testing.js 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /**
  2. * @license Angular v5.2.11
  3. * (c) 2010-2018 Google, Inc. https://angular.io/
  4. * License: MIT
  5. */
  6. import { AUTO_STYLE, NoopAnimationPlayer } from '@angular/animations';
  7. /**
  8. * @fileoverview added by tsickle
  9. * @suppress {checkTypes} checked by tsc
  10. */
  11. /**
  12. * @param {?} players
  13. * @return {?}
  14. */
  15. /**
  16. * @param {?} driver
  17. * @param {?} normalizer
  18. * @param {?} element
  19. * @param {?} keyframes
  20. * @param {?=} preStyles
  21. * @param {?=} postStyles
  22. * @return {?}
  23. */
  24. /**
  25. * @param {?} player
  26. * @param {?} eventName
  27. * @param {?} event
  28. * @param {?} callback
  29. * @return {?}
  30. */
  31. /**
  32. * @param {?} e
  33. * @param {?=} phaseName
  34. * @param {?=} totalTime
  35. * @return {?}
  36. */
  37. /**
  38. * @param {?} element
  39. * @param {?} triggerName
  40. * @param {?} fromState
  41. * @param {?} toState
  42. * @param {?=} phaseName
  43. * @param {?=} totalTime
  44. * @return {?}
  45. */
  46. /**
  47. * @param {?} map
  48. * @param {?} key
  49. * @param {?} defaultValue
  50. * @return {?}
  51. */
  52. /**
  53. * @param {?} command
  54. * @return {?}
  55. */
  56. let _contains = (elm1, elm2) => false;
  57. let _matches = (element, selector) => false;
  58. let _query = (element, selector, multi) => {
  59. return [];
  60. };
  61. if (typeof Element != 'undefined') {
  62. // this is well supported in all browsers
  63. _contains = (elm1, elm2) => { return /** @type {?} */ (elm1.contains(elm2)); };
  64. if (Element.prototype.matches) {
  65. _matches = (element, selector) => element.matches(selector);
  66. }
  67. else {
  68. const /** @type {?} */ proto = /** @type {?} */ (Element.prototype);
  69. const /** @type {?} */ fn = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector ||
  70. proto.oMatchesSelector || proto.webkitMatchesSelector;
  71. if (fn) {
  72. _matches = (element, selector) => fn.apply(element, [selector]);
  73. }
  74. }
  75. _query = (element, selector, multi) => {
  76. let /** @type {?} */ results = [];
  77. if (multi) {
  78. results.push(...element.querySelectorAll(selector));
  79. }
  80. else {
  81. const /** @type {?} */ elm = element.querySelector(selector);
  82. if (elm) {
  83. results.push(elm);
  84. }
  85. }
  86. return results;
  87. };
  88. }
  89. /**
  90. * @param {?} prop
  91. * @return {?}
  92. */
  93. function containsVendorPrefix(prop) {
  94. // Webkit is the only real popular vendor prefix nowadays
  95. // cc: http://shouldiprefix.com/
  96. return prop.substring(1, 6) == 'ebkit'; // webkit or Webkit
  97. }
  98. let _CACHED_BODY = null;
  99. let _IS_WEBKIT = false;
  100. /**
  101. * @param {?} prop
  102. * @return {?}
  103. */
  104. function validateStyleProperty(prop) {
  105. if (!_CACHED_BODY) {
  106. _CACHED_BODY = getBodyNode() || {};
  107. _IS_WEBKIT = /** @type {?} */ ((_CACHED_BODY)).style ? ('WebkitAppearance' in /** @type {?} */ ((_CACHED_BODY)).style) : false;
  108. }
  109. let /** @type {?} */ result = true;
  110. if (/** @type {?} */ ((_CACHED_BODY)).style && !containsVendorPrefix(prop)) {
  111. result = prop in /** @type {?} */ ((_CACHED_BODY)).style;
  112. if (!result && _IS_WEBKIT) {
  113. const /** @type {?} */ camelProp = 'Webkit' + prop.charAt(0).toUpperCase() + prop.substr(1);
  114. result = camelProp in /** @type {?} */ ((_CACHED_BODY)).style;
  115. }
  116. }
  117. return result;
  118. }
  119. /**
  120. * @return {?}
  121. */
  122. function getBodyNode() {
  123. if (typeof document != 'undefined') {
  124. return document.body;
  125. }
  126. return null;
  127. }
  128. const matchesElement = _matches;
  129. const containsElement = _contains;
  130. const invokeQuery = _query;
  131. /**
  132. * @fileoverview added by tsickle
  133. * @suppress {checkTypes} checked by tsc
  134. */
  135. /**
  136. * @param {?} value
  137. * @return {?}
  138. */
  139. /**
  140. * @param {?} timings
  141. * @param {?} errors
  142. * @param {?=} allowNegativeValues
  143. * @return {?}
  144. */
  145. /**
  146. * @param {?} obj
  147. * @param {?=} destination
  148. * @return {?}
  149. */
  150. /**
  151. * @param {?} styles
  152. * @return {?}
  153. */
  154. /**
  155. * @param {?} styles
  156. * @param {?} readPrototype
  157. * @param {?=} destination
  158. * @return {?}
  159. */
  160. /**
  161. * @param {?} element
  162. * @param {?} styles
  163. * @return {?}
  164. */
  165. /**
  166. * @param {?} element
  167. * @param {?} styles
  168. * @return {?}
  169. */
  170. /**
  171. * @param {?} steps
  172. * @return {?}
  173. */
  174. /**
  175. * @param {?} value
  176. * @param {?} options
  177. * @param {?} errors
  178. * @return {?}
  179. */
  180. /**
  181. * @param {?} value
  182. * @return {?}
  183. */
  184. /**
  185. * @param {?} value
  186. * @param {?} params
  187. * @param {?} errors
  188. * @return {?}
  189. */
  190. /**
  191. * @param {?} iterator
  192. * @return {?}
  193. */
  194. /**
  195. * @param {?} source
  196. * @param {?} destination
  197. * @return {?}
  198. */
  199. /**
  200. * @param {?} input
  201. * @return {?}
  202. */
  203. /**
  204. * @param {?} duration
  205. * @param {?} delay
  206. * @return {?}
  207. */
  208. function allowPreviousPlayerStylesMerge(duration, delay) {
  209. return duration === 0 || delay === 0;
  210. }
  211. /**
  212. * @param {?} visitor
  213. * @param {?} node
  214. * @param {?} context
  215. * @return {?}
  216. */
  217. /**
  218. * @fileoverview added by tsickle
  219. * @suppress {checkTypes} checked by tsc
  220. */
  221. /**
  222. * \@experimental Animation support is experimental.
  223. */
  224. class MockAnimationDriver {
  225. /**
  226. * @param {?} prop
  227. * @return {?}
  228. */
  229. validateStyleProperty(prop) { return validateStyleProperty(prop); }
  230. /**
  231. * @param {?} element
  232. * @param {?} selector
  233. * @return {?}
  234. */
  235. matchesElement(element, selector) {
  236. return matchesElement(element, selector);
  237. }
  238. /**
  239. * @param {?} elm1
  240. * @param {?} elm2
  241. * @return {?}
  242. */
  243. containsElement(elm1, elm2) { return containsElement(elm1, elm2); }
  244. /**
  245. * @param {?} element
  246. * @param {?} selector
  247. * @param {?} multi
  248. * @return {?}
  249. */
  250. query(element, selector, multi) {
  251. return invokeQuery(element, selector, multi);
  252. }
  253. /**
  254. * @param {?} element
  255. * @param {?} prop
  256. * @param {?=} defaultValue
  257. * @return {?}
  258. */
  259. computeStyle(element, prop, defaultValue) {
  260. return defaultValue || '';
  261. }
  262. /**
  263. * @param {?} element
  264. * @param {?} keyframes
  265. * @param {?} duration
  266. * @param {?} delay
  267. * @param {?} easing
  268. * @param {?=} previousPlayers
  269. * @return {?}
  270. */
  271. animate(element, keyframes, duration, delay, easing, previousPlayers = []) {
  272. const /** @type {?} */ player = new MockAnimationPlayer(element, keyframes, duration, delay, easing, previousPlayers);
  273. MockAnimationDriver.log.push(/** @type {?} */ (player));
  274. return player;
  275. }
  276. }
  277. MockAnimationDriver.log = [];
  278. /**
  279. * \@experimental Animation support is experimental.
  280. */
  281. class MockAnimationPlayer extends NoopAnimationPlayer {
  282. /**
  283. * @param {?} element
  284. * @param {?} keyframes
  285. * @param {?} duration
  286. * @param {?} delay
  287. * @param {?} easing
  288. * @param {?} previousPlayers
  289. */
  290. constructor(element, keyframes, duration, delay, easing, previousPlayers) {
  291. super();
  292. this.element = element;
  293. this.keyframes = keyframes;
  294. this.duration = duration;
  295. this.delay = delay;
  296. this.easing = easing;
  297. this.previousPlayers = previousPlayers;
  298. this.__finished = false;
  299. this.__started = false;
  300. this.previousStyles = {};
  301. this._onInitFns = [];
  302. this.currentSnapshot = {};
  303. if (allowPreviousPlayerStylesMerge(duration, delay)) {
  304. previousPlayers.forEach(player => {
  305. if (player instanceof MockAnimationPlayer) {
  306. const /** @type {?} */ styles = player.currentSnapshot;
  307. Object.keys(styles).forEach(prop => this.previousStyles[prop] = styles[prop]);
  308. }
  309. });
  310. }
  311. this.totalTime = delay + duration;
  312. }
  313. /**
  314. * @param {?} fn
  315. * @return {?}
  316. */
  317. onInit(fn) { this._onInitFns.push(fn); }
  318. /**
  319. * @return {?}
  320. */
  321. init() {
  322. super.init();
  323. this._onInitFns.forEach(fn => fn());
  324. this._onInitFns = [];
  325. }
  326. /**
  327. * @return {?}
  328. */
  329. finish() {
  330. super.finish();
  331. this.__finished = true;
  332. }
  333. /**
  334. * @return {?}
  335. */
  336. destroy() {
  337. super.destroy();
  338. this.__finished = true;
  339. }
  340. /**
  341. * @return {?}
  342. */
  343. triggerMicrotask() { }
  344. /**
  345. * @return {?}
  346. */
  347. play() {
  348. super.play();
  349. this.__started = true;
  350. }
  351. /**
  352. * @return {?}
  353. */
  354. hasStarted() { return this.__started; }
  355. /**
  356. * @return {?}
  357. */
  358. beforeDestroy() {
  359. const /** @type {?} */ captures = {};
  360. Object.keys(this.previousStyles).forEach(prop => {
  361. captures[prop] = this.previousStyles[prop];
  362. });
  363. if (this.hasStarted()) {
  364. // when assembling the captured styles, it's important that
  365. // we build the keyframe styles in the following order:
  366. // {other styles within keyframes, ... previousStyles }
  367. this.keyframes.forEach(kf => {
  368. Object.keys(kf).forEach(prop => {
  369. if (prop != 'offset') {
  370. captures[prop] = this.__finished ? kf[prop] : AUTO_STYLE;
  371. }
  372. });
  373. });
  374. }
  375. this.currentSnapshot = captures;
  376. }
  377. }
  378. /**
  379. * @fileoverview added by tsickle
  380. * @suppress {checkTypes} checked by tsc
  381. */
  382. /**
  383. * @fileoverview added by tsickle
  384. * @suppress {checkTypes} checked by tsc
  385. */
  386. /**
  387. * @license
  388. * Copyright Google Inc. All Rights Reserved.
  389. *
  390. * Use of this source code is governed by an MIT-style license that can be
  391. * found in the LICENSE file at https://angular.io/license
  392. */
  393. /**
  394. * @module
  395. * @description
  396. * Entry point for all public APIs of this package.
  397. */
  398. /**
  399. * @fileoverview added by tsickle
  400. * @suppress {checkTypes} checked by tsc
  401. */
  402. /**
  403. * Generated bundle index. Do not edit.
  404. */
  405. export { MockAnimationDriver, MockAnimationPlayer };
  406. //# sourceMappingURL=testing.js.map