a zip code crypto-currency system good for red ONLY

animation.js 40KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. (function (factory) {
  2. if (typeof module === "object" && typeof module.exports === "object") {
  3. var v = factory(require, exports);
  4. if (v !== undefined) module.exports = v;
  5. }
  6. else if (typeof define === "function" && define.amd) {
  7. define(["require", "exports", "../util/util"], factory);
  8. }
  9. })(function (require, exports) {
  10. "use strict";
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var util_1 = require("../util/util");
  13. /**
  14. * @hidden
  15. */
  16. var Animation = (function () {
  17. function Animation(plt, ele, opts) {
  18. this._dur = null;
  19. this._es = null;
  20. this._rvEs = null;
  21. this.hasChildren = false;
  22. this.isPlaying = false;
  23. this.hasCompleted = false;
  24. this.plt = plt;
  25. this.element(ele);
  26. this.opts = opts;
  27. }
  28. Animation.prototype.element = function (ele) {
  29. if (ele) {
  30. if (typeof ele === 'string') {
  31. ele = this.plt.doc().querySelectorAll(ele);
  32. for (var i = 0; i < ele.length; i++) {
  33. this._addEle(ele[i]);
  34. }
  35. }
  36. else if (ele.length) {
  37. for (var i = 0; i < ele.length; i++) {
  38. this._addEle(ele[i]);
  39. }
  40. }
  41. else {
  42. this._addEle(ele);
  43. }
  44. }
  45. return this;
  46. };
  47. /**
  48. * NO DOM
  49. */
  50. Animation.prototype._addEle = function (ele) {
  51. if (ele.nativeElement) {
  52. ele = ele.nativeElement;
  53. }
  54. if (ele.nodeType === 1) {
  55. this._eL = (this._e = this._e || []).push(ele);
  56. }
  57. };
  58. /**
  59. * Add a child animation to this animation.
  60. */
  61. Animation.prototype.add = function (childAnimation) {
  62. childAnimation.parent = this;
  63. this.hasChildren = true;
  64. this._cL = (this._c = this._c || []).push(childAnimation);
  65. return this;
  66. };
  67. /**
  68. * Get the duration of this animation. If this animation does
  69. * not have a duration, then it'll get the duration from its parent.
  70. */
  71. Animation.prototype.getDuration = function (opts) {
  72. if (opts && util_1.isDefined(opts.duration)) {
  73. return opts.duration;
  74. }
  75. else if (this._dur !== null) {
  76. return this._dur;
  77. }
  78. else if (this.parent) {
  79. return this.parent.getDuration();
  80. }
  81. return 0;
  82. };
  83. /**
  84. * Returns if the animation is a root one.
  85. */
  86. Animation.prototype.isRoot = function () {
  87. return !this.parent;
  88. };
  89. /**
  90. * Set the duration for this animation.
  91. */
  92. Animation.prototype.duration = function (milliseconds) {
  93. this._dur = milliseconds;
  94. return this;
  95. };
  96. /**
  97. * Get the easing of this animation. If this animation does
  98. * not have an easing, then it'll get the easing from its parent.
  99. */
  100. Animation.prototype.getEasing = function () {
  101. if (this._rv && this._rvEs) {
  102. return this._rvEs;
  103. }
  104. return this._es !== null ? this._es : (this.parent && this.parent.getEasing()) || null;
  105. };
  106. /**
  107. * Set the easing for this animation.
  108. */
  109. Animation.prototype.easing = function (name) {
  110. this._es = name;
  111. return this;
  112. };
  113. /**
  114. * Set the easing for this reversed animation.
  115. */
  116. Animation.prototype.easingReverse = function (name) {
  117. this._rvEs = name;
  118. return this;
  119. };
  120. /**
  121. * Add the "from" value for a specific property.
  122. */
  123. Animation.prototype.from = function (prop, val) {
  124. this._addProp('from', prop, val);
  125. return this;
  126. };
  127. /**
  128. * Add the "to" value for a specific property.
  129. */
  130. Animation.prototype.to = function (prop, val, clearProperyAfterTransition) {
  131. var fx = this._addProp('to', prop, val);
  132. if (clearProperyAfterTransition) {
  133. // if this effect is a transform then clear the transform effect
  134. // otherwise just clear the actual property
  135. this.afterClearStyles([fx.trans ? this.plt.Css.transform : prop]);
  136. }
  137. return this;
  138. };
  139. /**
  140. * Shortcut to add both the "from" and "to" for the same property.
  141. */
  142. Animation.prototype.fromTo = function (prop, fromVal, toVal, clearProperyAfterTransition) {
  143. return this.from(prop, fromVal).to(prop, toVal, clearProperyAfterTransition);
  144. };
  145. /**
  146. * @hidden
  147. * NO DOM
  148. */
  149. Animation.prototype._getProp = function (name) {
  150. if (this._fx) {
  151. return this._fx.find(function (prop) { return prop.name === name; });
  152. }
  153. else {
  154. this._fx = [];
  155. }
  156. return null;
  157. };
  158. Animation.prototype._addProp = function (state, prop, val) {
  159. var fxProp = this._getProp(prop);
  160. if (!fxProp) {
  161. // first time we've see this EffectProperty
  162. var shouldTrans = (ANIMATION_TRANSFORMS[prop] === 1);
  163. fxProp = {
  164. name: prop,
  165. trans: shouldTrans,
  166. // add the will-change property for transforms or opacity
  167. wc: (shouldTrans ? this.plt.Css.transform : prop)
  168. };
  169. this._fx.push(fxProp);
  170. }
  171. // add from/to EffectState to the EffectProperty
  172. var fxState = {
  173. val: val,
  174. num: null,
  175. unit: '',
  176. };
  177. fxProp[state] = fxState;
  178. if (typeof val === 'string' && val.indexOf(' ') < 0) {
  179. var r = val.match(ANIMATION_CSS_VALUE_REGEX);
  180. var num = parseFloat(r[1]);
  181. if (!isNaN(num)) {
  182. fxState.num = num;
  183. }
  184. fxState.unit = (r[0] !== r[2] ? r[2] : '');
  185. }
  186. else if (typeof val === 'number') {
  187. fxState.num = val;
  188. }
  189. return fxProp;
  190. };
  191. /**
  192. * Add CSS class to this animation's elements
  193. * before the animation begins.
  194. */
  195. Animation.prototype.beforeAddClass = function (className) {
  196. (this._bfAdd = this._bfAdd || []).push(className);
  197. return this;
  198. };
  199. /**
  200. * Remove CSS class from this animation's elements
  201. * before the animation begins.
  202. */
  203. Animation.prototype.beforeRemoveClass = function (className) {
  204. (this._bfRm = this._bfRm || []).push(className);
  205. return this;
  206. };
  207. /**
  208. * Set CSS inline styles to this animation's elements
  209. * before the animation begins.
  210. */
  211. Animation.prototype.beforeStyles = function (styles) {
  212. this._bfSty = styles;
  213. return this;
  214. };
  215. /**
  216. * Clear CSS inline styles from this animation's elements
  217. * before the animation begins.
  218. */
  219. Animation.prototype.beforeClearStyles = function (propertyNames) {
  220. this._bfSty = this._bfSty || {};
  221. for (var i = 0; i < propertyNames.length; i++) {
  222. this._bfSty[propertyNames[i]] = '';
  223. }
  224. return this;
  225. };
  226. /**
  227. * Add a function which contains DOM reads, which will run
  228. * before the animation begins.
  229. */
  230. Animation.prototype.beforeAddRead = function (domReadFn) {
  231. (this._rdFn = this._rdFn || []).push(domReadFn);
  232. return this;
  233. };
  234. /**
  235. * Add a function which contains DOM writes, which will run
  236. * before the animation begins.
  237. */
  238. Animation.prototype.beforeAddWrite = function (domWriteFn) {
  239. (this._wrFn = this._wrFn || []).push(domWriteFn);
  240. return this;
  241. };
  242. /**
  243. * Add CSS class to this animation's elements
  244. * after the animation finishes.
  245. */
  246. Animation.prototype.afterAddClass = function (className) {
  247. (this._afAdd = this._afAdd || []).push(className);
  248. return this;
  249. };
  250. /**
  251. * Remove CSS class from this animation's elements
  252. * after the animation finishes.
  253. */
  254. Animation.prototype.afterRemoveClass = function (className) {
  255. (this._afRm = this._afRm || []).push(className);
  256. return this;
  257. };
  258. /**
  259. * Set CSS inline styles to this animation's elements
  260. * after the animation finishes.
  261. */
  262. Animation.prototype.afterStyles = function (styles) {
  263. this._afSty = styles;
  264. return this;
  265. };
  266. /**
  267. * Clear CSS inline styles from this animation's elements
  268. * after the animation finishes.
  269. */
  270. Animation.prototype.afterClearStyles = function (propertyNames) {
  271. this._afSty = this._afSty || {};
  272. for (var i = 0; i < propertyNames.length; i++) {
  273. this._afSty[propertyNames[i]] = '';
  274. }
  275. return this;
  276. };
  277. /**
  278. * Play the animation.
  279. */
  280. Animation.prototype.play = function (opts) {
  281. var _this = this;
  282. // If the animation was already invalidated (it did finish), do nothing
  283. if (!this.plt) {
  284. return;
  285. }
  286. // this is the top level animation and is in full control
  287. // of when the async play() should actually kick off
  288. // if there is no duration then it'll set the TO property immediately
  289. // if there is a duration, then it'll stage all animations at the
  290. // FROM property and transition duration, wait a few frames, then
  291. // kick off the animation by setting the TO property for each animation
  292. this._isAsync = this._hasDuration(opts);
  293. // ensure all past transition end events have been cleared
  294. this._clearAsync();
  295. // recursively kicks off the correct progress step for each child animation
  296. // ******** DOM WRITE ****************
  297. this._playInit(opts);
  298. // doubling up RAFs since this animation was probably triggered
  299. // from an input event, and just having one RAF would have this code
  300. // run within the same frame as the triggering input event, and the
  301. // input event probably already did way too much work for one frame
  302. this.plt.raf(function () {
  303. _this.plt.raf(_this._playDomInspect.bind(_this, opts));
  304. });
  305. };
  306. Animation.prototype.syncPlay = function () {
  307. // If the animation was already invalidated (it did finish), do nothing
  308. if (!this.plt) {
  309. return;
  310. }
  311. var opts = { duration: 0 };
  312. this._isAsync = false;
  313. this._clearAsync();
  314. this._playInit(opts);
  315. this._playDomInspect(opts);
  316. };
  317. /**
  318. * @hidden
  319. * DOM WRITE
  320. * RECURSION
  321. */
  322. Animation.prototype._playInit = function (opts) {
  323. // always default that an animation does not tween
  324. // a tween requires that an Animation class has an element
  325. // and that it has at least one FROM/TO effect
  326. // and that the FROM/TO effect can tween numeric values
  327. this._twn = false;
  328. this.isPlaying = true;
  329. this.hasCompleted = false;
  330. this._hasDur = (this.getDuration(opts) > ANIMATION_DURATION_MIN);
  331. var children = this._c;
  332. for (var i = 0; i < this._cL; i++) {
  333. // ******** DOM WRITE ****************
  334. children[i]._playInit(opts);
  335. }
  336. if (this._hasDur) {
  337. // if there is a duration then we want to start at step 0
  338. // ******** DOM WRITE ****************
  339. this._progress(0);
  340. // add the will-change properties
  341. // ******** DOM WRITE ****************
  342. this._willChg(true);
  343. }
  344. };
  345. /**
  346. * @hidden
  347. * DOM WRITE
  348. * NO RECURSION
  349. * ROOT ANIMATION
  350. */
  351. Animation.prototype._playDomInspect = function (opts) {
  352. // fire off all the "before" function that have DOM READS in them
  353. // elements will be in the DOM, however visibily hidden
  354. // so we can read their dimensions if need be
  355. // ******** DOM READ ****************
  356. // ******** DOM WRITE ****************
  357. this._beforeAnimation();
  358. // for the root animation only
  359. // set the async TRANSITION END event
  360. // and run onFinishes when the transition ends
  361. var dur = this.getDuration(opts);
  362. if (this._isAsync) {
  363. this._asyncEnd(dur, true);
  364. }
  365. // ******** DOM WRITE ****************
  366. this._playProgress(opts);
  367. if (this._isAsync && this.plt) {
  368. // this animation has a duration so we need another RAF
  369. // for the CSS TRANSITION properties to kick in
  370. this.plt.raf(this._playToStep.bind(this, 1));
  371. }
  372. };
  373. /**
  374. * @hidden
  375. * DOM WRITE
  376. * RECURSION
  377. */
  378. Animation.prototype._playProgress = function (opts) {
  379. var children = this._c;
  380. for (var i = 0; i < this._cL; i++) {
  381. // ******** DOM WRITE ****************
  382. children[i]._playProgress(opts);
  383. }
  384. if (this._hasDur) {
  385. // set the CSS TRANSITION duration/easing
  386. // ******** DOM WRITE ****************
  387. this._setTrans(this.getDuration(opts), false);
  388. }
  389. else {
  390. // this animation does not have a duration, so it should not animate
  391. // just go straight to the TO properties and call it done
  392. // ******** DOM WRITE ****************
  393. this._progress(1);
  394. // since there was no animation, immediately run the after
  395. // ******** DOM WRITE ****************
  396. this._setAfterStyles();
  397. // this animation has no duration, so it has finished
  398. // other animations could still be running
  399. this._didFinish(true);
  400. }
  401. };
  402. /**
  403. * @hidden
  404. * DOM WRITE
  405. * RECURSION
  406. */
  407. Animation.prototype._playToStep = function (stepValue) {
  408. var children = this._c;
  409. for (var i = 0; i < this._cL; i++) {
  410. // ******** DOM WRITE ****************
  411. children[i]._playToStep(stepValue);
  412. }
  413. if (this._hasDur) {
  414. // browser had some time to render everything in place
  415. // and the transition duration/easing is set
  416. // now set the TO properties which will trigger the transition to begin
  417. // ******** DOM WRITE ****************
  418. this._progress(stepValue);
  419. }
  420. };
  421. /**
  422. * @hidden
  423. * DOM WRITE
  424. * NO RECURSION
  425. * ROOT ANIMATION
  426. */
  427. Animation.prototype._asyncEnd = function (dur, shouldComplete) {
  428. (void 0) /* assert */;
  429. (void 0) /* assert */;
  430. (void 0) /* assert */;
  431. var self = this;
  432. function onTransitionEnd() {
  433. // congrats! a successful transition completed!
  434. // ensure transition end events and timeouts have been cleared
  435. self._clearAsync();
  436. // ******** DOM WRITE ****************
  437. self._playEnd();
  438. // transition finished
  439. self._didFinishAll(shouldComplete, true, false);
  440. }
  441. function onTransitionFallback() {
  442. (void 0) /* console.debug */;
  443. // oh noz! the transition end event didn't fire in time!
  444. // instead the fallback timer when first
  445. // if all goes well this fallback should never fire
  446. // clear the other async end events from firing
  447. self._tm = undefined;
  448. self._clearAsync();
  449. // set the after styles
  450. // ******** DOM WRITE ****************
  451. self._playEnd(shouldComplete ? 1 : 0);
  452. // transition finished
  453. self._didFinishAll(shouldComplete, true, false);
  454. }
  455. // set the TRANSITION END event on one of the transition elements
  456. self._unrgTrns = this.plt.transitionEnd(self._transEl(), onTransitionEnd, false);
  457. // set a fallback timeout if the transition end event never fires, or is too slow
  458. // transition end fallback: (animation duration + XXms)
  459. self._tm = self.plt.timeout(onTransitionFallback, (dur + ANIMATION_TRANSITION_END_FALLBACK_PADDING_MS));
  460. };
  461. /**
  462. * @hidden
  463. * DOM WRITE
  464. * RECURSION
  465. */
  466. Animation.prototype._playEnd = function (stepValue) {
  467. var children = this._c;
  468. for (var i = 0; i < this._cL; i++) {
  469. // ******** DOM WRITE ****************
  470. children[i]._playEnd(stepValue);
  471. }
  472. if (this._hasDur) {
  473. if (util_1.isDefined(stepValue)) {
  474. // too late to have a smooth animation, just finish it
  475. // ******** DOM WRITE ****************
  476. this._setTrans(0, true);
  477. // ensure the ending progress step gets rendered
  478. // ******** DOM WRITE ****************
  479. this._progress(stepValue);
  480. }
  481. // set the after styles
  482. // ******** DOM WRITE ****************
  483. this._setAfterStyles();
  484. // remove the will-change properties
  485. // ******** DOM WRITE ****************
  486. this._willChg(false);
  487. }
  488. };
  489. /**
  490. * @hidden
  491. * NO DOM
  492. * RECURSION
  493. */
  494. Animation.prototype._hasDuration = function (opts) {
  495. if (this.getDuration(opts) > ANIMATION_DURATION_MIN) {
  496. return true;
  497. }
  498. var children = this._c;
  499. for (var i = 0; i < this._cL; i++) {
  500. if (children[i]._hasDuration(opts)) {
  501. return true;
  502. }
  503. }
  504. return false;
  505. };
  506. /**
  507. * @hidden
  508. * NO DOM
  509. * RECURSION
  510. */
  511. Animation.prototype._hasDomReads = function () {
  512. if (this._rdFn && this._rdFn.length) {
  513. return true;
  514. }
  515. var children = this._c;
  516. for (var i = 0; i < this._cL; i++) {
  517. if (children[i]._hasDomReads()) {
  518. return true;
  519. }
  520. }
  521. return false;
  522. };
  523. /**
  524. * Immediately stop at the end of the animation.
  525. */
  526. Animation.prototype.stop = function (stepValue) {
  527. if (stepValue === void 0) { stepValue = 1; }
  528. // ensure all past transition end events have been cleared
  529. this._clearAsync();
  530. this._hasDur = true;
  531. this._playEnd(stepValue);
  532. };
  533. /**
  534. * @hidden
  535. * NO DOM
  536. * NO RECURSION
  537. */
  538. Animation.prototype._clearAsync = function () {
  539. this._unrgTrns && this._unrgTrns();
  540. this._tm && clearTimeout(this._tm);
  541. this._tm = this._unrgTrns = undefined;
  542. };
  543. /**
  544. * @hidden
  545. * DOM WRITE
  546. * NO RECURSION
  547. */
  548. Animation.prototype._progress = function (stepValue) {
  549. // bread 'n butter
  550. var val;
  551. var effects = this._fx;
  552. var nuElements = this._eL;
  553. if (!effects || !nuElements) {
  554. return;
  555. }
  556. // flip the number if we're going in reverse
  557. if (this._rv) {
  558. stepValue = ((stepValue * -1) + 1);
  559. }
  560. var i, j;
  561. var finalTransform = '';
  562. var elements = this._e;
  563. for (i = 0; i < effects.length; i++) {
  564. var fx = effects[i];
  565. if (fx.from && fx.to) {
  566. var fromNum = fx.from.num;
  567. var toNum = fx.to.num;
  568. var tweenEffect = (fromNum !== toNum);
  569. (void 0) /* assert */;
  570. if (tweenEffect) {
  571. this._twn = true;
  572. }
  573. if (stepValue === 0) {
  574. // FROM
  575. val = fx.from.val;
  576. }
  577. else if (stepValue === 1) {
  578. // TO
  579. val = fx.to.val;
  580. }
  581. else if (tweenEffect) {
  582. // EVERYTHING IN BETWEEN
  583. var valNum = (((toNum - fromNum) * stepValue) + fromNum);
  584. var unit = fx.to.unit;
  585. if (unit === 'px') {
  586. valNum = Math.round(valNum);
  587. }
  588. val = valNum + unit;
  589. }
  590. if (val !== null) {
  591. var prop = fx.name;
  592. if (fx.trans) {
  593. finalTransform += prop + '(' + val + ') ';
  594. }
  595. else {
  596. for (j = 0; j < nuElements; j++) {
  597. // ******** DOM WRITE ****************
  598. elements[j].style[prop] = val;
  599. }
  600. }
  601. }
  602. }
  603. }
  604. // place all transforms on the same property
  605. if (finalTransform.length) {
  606. if (!this._rv && stepValue !== 1 || this._rv && stepValue !== 0) {
  607. finalTransform += 'translateZ(0px)';
  608. }
  609. var cssTransform = this.plt.Css.transform;
  610. for (i = 0; i < elements.length; i++) {
  611. // ******** DOM WRITE ****************
  612. elements[i].style[cssTransform] = finalTransform;
  613. }
  614. }
  615. };
  616. /**
  617. * @hidden
  618. * DOM WRITE
  619. * NO RECURSION
  620. */
  621. Animation.prototype._setTrans = function (dur, forcedLinearEasing) {
  622. // Transition is not enabled if there are not effects
  623. if (!this._fx) {
  624. return;
  625. }
  626. // set the TRANSITION properties inline on the element
  627. var elements = this._e;
  628. var easing = (forcedLinearEasing ? 'linear' : this.getEasing());
  629. var durString = dur + 'ms';
  630. var Css = this.plt.Css;
  631. var cssTransform = Css.transition;
  632. var cssTransitionDuration = Css.transitionDuration;
  633. var cssTransitionTimingFn = Css.transitionTimingFn;
  634. var eleStyle;
  635. for (var i = 0; i < this._eL; i++) {
  636. eleStyle = elements[i].style;
  637. if (dur > 0) {
  638. // ******** DOM WRITE ****************
  639. eleStyle[cssTransform] = '';
  640. eleStyle[cssTransitionDuration] = durString;
  641. // each animation can have a different easing
  642. if (easing) {
  643. // ******** DOM WRITE ****************
  644. eleStyle[cssTransitionTimingFn] = easing;
  645. }
  646. }
  647. else {
  648. eleStyle[cssTransform] = 'none';
  649. }
  650. }
  651. };
  652. /**
  653. * @hidden
  654. * DOM READ
  655. * DOM WRITE
  656. * RECURSION
  657. */
  658. Animation.prototype._beforeAnimation = function () {
  659. // fire off all the "before" function that have DOM READS in them
  660. // elements will be in the DOM, however visibily hidden
  661. // so we can read their dimensions if need be
  662. // ******** DOM READ ****************
  663. this._fireBeforeReadFunc();
  664. // ******** DOM READS ABOVE / DOM WRITES BELOW ****************
  665. // fire off all the "before" function that have DOM WRITES in them
  666. // ******** DOM WRITE ****************
  667. this._fireBeforeWriteFunc();
  668. // stage all of the before css classes and inline styles
  669. // ******** DOM WRITE ****************
  670. this._setBeforeStyles();
  671. };
  672. /**
  673. * @hidden
  674. * DOM WRITE
  675. * RECURSION
  676. */
  677. Animation.prototype._setBeforeStyles = function () {
  678. var i, j;
  679. var children = this._c;
  680. for (i = 0; i < this._cL; i++) {
  681. children[i]._setBeforeStyles();
  682. }
  683. // before the animations have started
  684. // only set before styles if animation is not reversed
  685. if (this._rv) {
  686. return;
  687. }
  688. var addClasses = this._bfAdd;
  689. var removeClasses = this._bfRm;
  690. var ele;
  691. var eleClassList;
  692. var prop;
  693. for (i = 0; i < this._eL; i++) {
  694. ele = this._e[i];
  695. eleClassList = ele.classList;
  696. // css classes to add before the animation
  697. if (addClasses) {
  698. for (j = 0; j < addClasses.length; j++) {
  699. // ******** DOM WRITE ****************
  700. eleClassList.add(addClasses[j]);
  701. }
  702. }
  703. // css classes to remove before the animation
  704. if (removeClasses) {
  705. for (j = 0; j < removeClasses.length; j++) {
  706. // ******** DOM WRITE ****************
  707. eleClassList.remove(removeClasses[j]);
  708. }
  709. }
  710. // inline styles to add before the animation
  711. if (this._bfSty) {
  712. for (prop in this._bfSty) {
  713. // ******** DOM WRITE ****************
  714. ele.style[prop] = this._bfSty[prop];
  715. }
  716. }
  717. }
  718. };
  719. /**
  720. * @hidden
  721. * DOM READ
  722. * RECURSION
  723. */
  724. Animation.prototype._fireBeforeReadFunc = function () {
  725. var children = this._c;
  726. for (var i = 0; i < this._cL; i++) {
  727. // ******** DOM READ ****************
  728. children[i]._fireBeforeReadFunc();
  729. }
  730. var readFunctions = this._rdFn;
  731. if (readFunctions) {
  732. for (var i = 0; i < readFunctions.length; i++) {
  733. // ******** DOM READ ****************
  734. readFunctions[i]();
  735. }
  736. }
  737. };
  738. /**
  739. * @hidden
  740. * DOM WRITE
  741. * RECURSION
  742. */
  743. Animation.prototype._fireBeforeWriteFunc = function () {
  744. var children = this._c;
  745. for (var i = 0; i < this._cL; i++) {
  746. // ******** DOM WRITE ****************
  747. children[i]._fireBeforeWriteFunc();
  748. }
  749. var writeFunctions = this._wrFn;
  750. if (this._wrFn) {
  751. for (var i = 0; i < writeFunctions.length; i++) {
  752. // ******** DOM WRITE ****************
  753. writeFunctions[i]();
  754. }
  755. }
  756. };
  757. /**
  758. * @hidden
  759. * DOM WRITE
  760. */
  761. Animation.prototype._setAfterStyles = function () {
  762. var i, j;
  763. var ele;
  764. var eleClassList;
  765. var elements = this._e;
  766. for (i = 0; i < this._eL; i++) {
  767. ele = elements[i];
  768. eleClassList = ele.classList;
  769. // remove the transition duration/easing
  770. // ******** DOM WRITE ****************
  771. ele.style[this.plt.Css.transitionDuration] = ele.style[this.plt.Css.transitionTimingFn] = '';
  772. if (this._rv) {
  773. // finished in reverse direction
  774. // css classes that were added before the animation should be removed
  775. if (this._bfAdd) {
  776. for (j = 0; j < this._bfAdd.length; j++) {
  777. // ******** DOM WRITE ****************
  778. eleClassList.remove(this._bfAdd[j]);
  779. }
  780. }
  781. // css classes that were removed before the animation should be added
  782. if (this._bfRm) {
  783. for (j = 0; j < this._bfRm.length; j++) {
  784. // ******** DOM WRITE ****************
  785. eleClassList.add(this._bfRm[j]);
  786. }
  787. }
  788. // inline styles that were added before the animation should be removed
  789. if (this._bfSty) {
  790. for (var prop in this._bfSty) {
  791. // ******** DOM WRITE ****************
  792. ele.style[prop] = '';
  793. }
  794. }
  795. }
  796. else {
  797. // finished in forward direction
  798. // css classes to add after the animation
  799. if (this._afAdd) {
  800. for (j = 0; j < this._afAdd.length; j++) {
  801. // ******** DOM WRITE ****************
  802. eleClassList.add(this._afAdd[j]);
  803. }
  804. }
  805. // css classes to remove after the animation
  806. if (this._afRm) {
  807. for (j = 0; j < this._afRm.length; j++) {
  808. // ******** DOM WRITE ****************
  809. eleClassList.remove(this._afRm[j]);
  810. }
  811. }
  812. // inline styles to add after the animation
  813. if (this._afSty) {
  814. for (var prop in this._afSty) {
  815. // ******** DOM WRITE ****************
  816. ele.style[prop] = this._afSty[prop];
  817. }
  818. }
  819. }
  820. }
  821. };
  822. /**
  823. * @hidden
  824. * DOM WRITE
  825. * NO RECURSION
  826. */
  827. Animation.prototype._willChg = function (addWillChange) {
  828. var wc;
  829. var effects = this._fx;
  830. var willChange;
  831. if (addWillChange && effects) {
  832. wc = [];
  833. for (var i = 0; i < effects.length; i++) {
  834. var propWC = effects[i].wc;
  835. if (propWC === 'webkitTransform') {
  836. wc.push('transform', '-webkit-transform');
  837. }
  838. else {
  839. wc.push(propWC);
  840. }
  841. }
  842. willChange = wc.join(',');
  843. }
  844. else {
  845. willChange = '';
  846. }
  847. for (var i = 0; i < this._eL; i++) {
  848. // ******** DOM WRITE ****************
  849. this._e[i].style.willChange = willChange;
  850. }
  851. };
  852. /**
  853. * Start the animation with a user controlled progress.
  854. */
  855. Animation.prototype.progressStart = function () {
  856. // ensure all past transition end events have been cleared
  857. this._clearAsync();
  858. // ******** DOM READ/WRITE ****************
  859. this._beforeAnimation();
  860. // ******** DOM WRITE ****************
  861. this._progressStart();
  862. };
  863. /**
  864. * @hidden
  865. * DOM WRITE
  866. * RECURSION
  867. */
  868. Animation.prototype._progressStart = function () {
  869. var children = this._c;
  870. for (var i = 0; i < this._cL; i++) {
  871. // ******** DOM WRITE ****************
  872. children[i]._progressStart();
  873. }
  874. // force no duration, linear easing
  875. // ******** DOM WRITE ****************
  876. this._setTrans(0, true);
  877. // ******** DOM WRITE ****************
  878. this._willChg(true);
  879. };
  880. /**
  881. * Set the progress step for this animation.
  882. * progressStep() is not debounced, so it should not be called faster than 60FPS.
  883. */
  884. Animation.prototype.progressStep = function (stepValue) {
  885. // only update if the last update was more than 16ms ago
  886. stepValue = Math.min(1, Math.max(0, stepValue));
  887. var children = this._c;
  888. for (var i = 0; i < this._cL; i++) {
  889. // ******** DOM WRITE ****************
  890. children[i].progressStep(stepValue);
  891. }
  892. if (this._rv) {
  893. // if the animation is going in reverse then
  894. // flip the step value: 0 becomes 1, 1 becomes 0
  895. stepValue = ((stepValue * -1) + 1);
  896. }
  897. // ******** DOM WRITE ****************
  898. this._progress(stepValue);
  899. };
  900. /**
  901. * End the progress animation.
  902. */
  903. Animation.prototype.progressEnd = function (shouldComplete, currentStepValue, dur) {
  904. if (dur === void 0) { dur = -1; }
  905. (void 0) /* console.debug */;
  906. if (this._rv) {
  907. // if the animation is going in reverse then
  908. // flip the step value: 0 becomes 1, 1 becomes 0
  909. currentStepValue = ((currentStepValue * -1) + 1);
  910. }
  911. var stepValue = shouldComplete ? 1 : 0;
  912. var diff = Math.abs(currentStepValue - stepValue);
  913. if (diff < 0.05) {
  914. dur = 0;
  915. }
  916. else if (dur < 0) {
  917. dur = this._dur;
  918. }
  919. this._isAsync = (dur > 30);
  920. this._progressEnd(shouldComplete, stepValue, dur, this._isAsync);
  921. if (this._isAsync) {
  922. // for the root animation only
  923. // set the async TRANSITION END event
  924. // and run onFinishes when the transition ends
  925. // ******** DOM WRITE ****************
  926. this._asyncEnd(dur, shouldComplete);
  927. // this animation has a duration so we need another RAF
  928. // for the CSS TRANSITION properties to kick in
  929. this.plt && this.plt.raf(this._playToStep.bind(this, stepValue));
  930. }
  931. };
  932. /**
  933. * @hidden
  934. * DOM WRITE
  935. * RECURSION
  936. */
  937. Animation.prototype._progressEnd = function (shouldComplete, stepValue, dur, isAsync) {
  938. var children = this._c;
  939. for (var i = 0; i < this._cL; i++) {
  940. // ******** DOM WRITE ****************
  941. children[i]._progressEnd(shouldComplete, stepValue, dur, isAsync);
  942. }
  943. if (!isAsync) {
  944. // stop immediately
  945. // set all the animations to their final position
  946. // ******** DOM WRITE ****************
  947. this._progress(stepValue);
  948. this._willChg(false);
  949. this._setAfterStyles();
  950. this._didFinish(shouldComplete);
  951. }
  952. else {
  953. // animate it back to it's ending position
  954. this.isPlaying = true;
  955. this.hasCompleted = false;
  956. this._hasDur = true;
  957. // ******** DOM WRITE ****************
  958. this._willChg(true);
  959. this._setTrans(dur, false);
  960. }
  961. };
  962. /**
  963. * Add a callback to fire when the animation has finished.
  964. */
  965. Animation.prototype.onFinish = function (callback, onceTimeCallback, clearOnFinishCallacks) {
  966. if (onceTimeCallback === void 0) { onceTimeCallback = false; }
  967. if (clearOnFinishCallacks === void 0) { clearOnFinishCallacks = false; }
  968. if (clearOnFinishCallacks) {
  969. this._fFn = this._fOneFn = undefined;
  970. }
  971. if (onceTimeCallback) {
  972. this._fOneFn = this._fOneFn || [];
  973. this._fOneFn.push(callback);
  974. }
  975. else {
  976. this._fFn = this._fFn || [];
  977. this._fFn.push(callback);
  978. }
  979. return this;
  980. };
  981. /**
  982. * @hidden
  983. * NO DOM
  984. * RECURSION
  985. */
  986. Animation.prototype._didFinishAll = function (hasCompleted, finishAsyncAnimations, finishNoDurationAnimations) {
  987. var children = this._c;
  988. for (var i = 0; i < this._cL; i++) {
  989. children[i]._didFinishAll(hasCompleted, finishAsyncAnimations, finishNoDurationAnimations);
  990. }
  991. if (finishAsyncAnimations && this._isAsync || finishNoDurationAnimations && !this._isAsync) {
  992. this._didFinish(hasCompleted);
  993. }
  994. };
  995. /**
  996. * @hidden
  997. * NO RECURSION
  998. */
  999. Animation.prototype._didFinish = function (hasCompleted) {
  1000. this.isPlaying = false;
  1001. this.hasCompleted = hasCompleted;
  1002. if (this._fFn) {
  1003. // run all finish callbacks
  1004. for (var i = 0; i < this._fFn.length; i++) {
  1005. this._fFn[i](this);
  1006. }
  1007. }
  1008. if (this._fOneFn) {
  1009. // run all "onetime" finish callbacks
  1010. for (var i = 0; i < this._fOneFn.length; i++) {
  1011. this._fOneFn[i](this);
  1012. }
  1013. this._fOneFn.length = 0;
  1014. }
  1015. };
  1016. /**
  1017. * Reverse the animation.
  1018. */
  1019. Animation.prototype.reverse = function (shouldReverse) {
  1020. if (shouldReverse === void 0) { shouldReverse = true; }
  1021. var children = this._c;
  1022. for (var i = 0; i < this._cL; i++) {
  1023. children[i].reverse(shouldReverse);
  1024. }
  1025. this._rv = shouldReverse;
  1026. return this;
  1027. };
  1028. /**
  1029. * Recursively destroy this animation and all child animations.
  1030. */
  1031. Animation.prototype.destroy = function () {
  1032. var children = this._c;
  1033. for (var i = 0; i < this._cL; i++) {
  1034. children[i].destroy();
  1035. }
  1036. this._clearAsync();
  1037. this.parent = this.plt = this._e = this._rdFn = this._wrFn = null;
  1038. if (this._c) {
  1039. this._c.length = this._cL = 0;
  1040. }
  1041. if (this._fFn) {
  1042. this._fFn.length = 0;
  1043. }
  1044. if (this._fOneFn) {
  1045. this._fOneFn.length = 0;
  1046. }
  1047. };
  1048. /**
  1049. * @hidden
  1050. * NO DOM
  1051. */
  1052. Animation.prototype._transEl = function () {
  1053. // get the lowest level element that has an Animation
  1054. var targetEl;
  1055. for (var i = 0; i < this._cL; i++) {
  1056. targetEl = this._c[i]._transEl();
  1057. if (targetEl) {
  1058. return targetEl;
  1059. }
  1060. }
  1061. return (this._twn && this._hasDur && this._eL ? this._e[0] : null);
  1062. };
  1063. return Animation;
  1064. }());
  1065. exports.Animation = Animation;
  1066. var ANIMATION_TRANSFORMS = {
  1067. 'translateX': 1,
  1068. 'translateY': 1,
  1069. 'translateZ': 1,
  1070. 'scale': 1,
  1071. 'scaleX': 1,
  1072. 'scaleY': 1,
  1073. 'scaleZ': 1,
  1074. 'rotate': 1,
  1075. 'rotateX': 1,
  1076. 'rotateY': 1,
  1077. 'rotateZ': 1,
  1078. 'skewX': 1,
  1079. 'skewY': 1,
  1080. 'perspective': 1
  1081. };
  1082. var ANIMATION_CSS_VALUE_REGEX = /(^-?\d*\.?\d*)(.*)/;
  1083. var ANIMATION_DURATION_MIN = 32;
  1084. var ANIMATION_TRANSITION_END_FALLBACK_PADDING_MS = 400;
  1085. });
  1086. //# sourceMappingURL=animation.js.map