index.umd.js 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@antv/g-lite')) :
  3. typeof define === 'function' && define.amd ? define(['exports', '@antv/g-lite'], factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.G = global.G || {}, global.G.WebAnimationsAPI = {}), global.window.G));
  5. }(this, (function (exports, gLite) { 'use strict';
  6. function _defineProperties(target, props) {
  7. for (var i = 0; i < props.length; i++) {
  8. var descriptor = props[i];
  9. descriptor.enumerable = descriptor.enumerable || false;
  10. descriptor.configurable = true;
  11. if ("value" in descriptor) descriptor.writable = true;
  12. Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
  13. }
  14. }
  15. function _createClass(Constructor, protoProps, staticProps) {
  16. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  17. if (staticProps) _defineProperties(Constructor, staticProps);
  18. Object.defineProperty(Constructor, "prototype", {
  19. writable: false
  20. });
  21. return Constructor;
  22. }
  23. function _inheritsLoose(subClass, superClass) {
  24. subClass.prototype = Object.create(superClass.prototype);
  25. subClass.prototype.constructor = subClass;
  26. _setPrototypeOf(subClass, superClass);
  27. }
  28. function _setPrototypeOf(o, p) {
  29. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
  30. o.__proto__ = p;
  31. return o;
  32. };
  33. return _setPrototypeOf(o, p);
  34. }
  35. function _toPrimitive(input, hint) {
  36. if (typeof input !== "object" || input === null) return input;
  37. var prim = input[Symbol.toPrimitive];
  38. if (prim !== undefined) {
  39. var res = prim.call(input, hint || "default");
  40. if (typeof res !== "object") return res;
  41. throw new TypeError("@@toPrimitive must return a primitive value.");
  42. }
  43. return (hint === "string" ? String : Number)(input);
  44. }
  45. function _toPropertyKey(arg) {
  46. var key = _toPrimitive(arg, "string");
  47. return typeof key === "symbol" ? key : String(key);
  48. }
  49. /**
  50. * @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationPlaybackEvent
  51. */
  52. var AnimationEvent = /*#__PURE__*/function (_FederatedEvent) {
  53. _inheritsLoose(AnimationEvent, _FederatedEvent);
  54. function AnimationEvent(manager, target, currentTime, timelineTime) {
  55. var _this;
  56. _this = _FederatedEvent.call(this, manager) || this;
  57. _this.currentTime = void 0;
  58. _this.timelineTime = void 0;
  59. _this.currentTime = currentTime;
  60. _this.timelineTime = timelineTime;
  61. // @ts-ignore
  62. _this.target = target;
  63. _this.type = 'finish';
  64. _this.bubbles = false;
  65. // @ts-ignore
  66. _this.currentTarget = target;
  67. _this.defaultPrevented = false;
  68. _this.eventPhase = _this.AT_TARGET;
  69. _this.timeStamp = Date.now();
  70. _this.currentTime = currentTime;
  71. _this.timelineTime = timelineTime;
  72. return _this;
  73. }
  74. return AnimationEvent;
  75. }(gLite.FederatedEvent);
  76. var sequenceNumber = 0;
  77. /**
  78. * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/Animation
  79. */
  80. var Animation = /*#__PURE__*/function () {
  81. function Animation(effect, timeline) {
  82. var _this$effect;
  83. /**
  84. * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/effect
  85. */
  86. this.effect = void 0;
  87. /**
  88. * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/timeline
  89. */
  90. this.timeline = void 0;
  91. /**
  92. * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/id
  93. */
  94. this.id = void 0;
  95. this.currentTimePending = false;
  96. /**
  97. * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/playState
  98. */
  99. // playState: AnimationPlayState;
  100. this._idle = true;
  101. this._paused = false;
  102. this._finishedFlag = true;
  103. /**
  104. * record previos state
  105. */
  106. this.oldPlayState = void 0;
  107. this._holdTime = void 0;
  108. this.readyPromise = void 0;
  109. this.finishedPromise = void 0;
  110. // eslint-disable-next-line @typescript-eslint/ban-types
  111. this.resolveReadyPromise = void 0;
  112. // eslint-disable-next-line @typescript-eslint/ban-types
  113. this.rejectReadyPromise = void 0;
  114. // eslint-disable-next-line @typescript-eslint/ban-types
  115. this.resolveFinishedPromise = void 0;
  116. // eslint-disable-next-line @typescript-eslint/ban-types
  117. this.rejectFinishedPromise = void 0;
  118. /**
  119. * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/onfinish
  120. */
  121. this.onfinish = void 0;
  122. /**
  123. * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/oncancel
  124. */
  125. this.oncancel = void 0;
  126. /**
  127. * get called after each frame when running
  128. */
  129. this.onframe = void 0;
  130. /**
  131. * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/currentTime
  132. */
  133. this._currentTime = 0;
  134. /**
  135. * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/startTime
  136. */
  137. this._startTime = void 0;
  138. this._playbackRate = 1;
  139. this._totalDuration = void 0;
  140. this._inEffect = void 0;
  141. this._inTimeline = true;
  142. this.onremove = void 0;
  143. this.effect = effect;
  144. effect.animation = this;
  145. this.timeline = timeline;
  146. this.id = "" + sequenceNumber++;
  147. this._inEffect = !!this.effect.update(0);
  148. this._totalDuration = Number((_this$effect = this.effect) === null || _this$effect === void 0 ? void 0 : _this$effect.getComputedTiming().endTime);
  149. this._holdTime = 0;
  150. this._paused = false;
  151. this.oldPlayState = 'idle';
  152. this.updatePromises();
  153. }
  154. /**
  155. * state machine,
  156. * resolve/reject ready/finished Promise according to current state
  157. */
  158. var _proto = Animation.prototype;
  159. _proto.updatePromises = function updatePromises() {
  160. var oldPlayState = this.oldPlayState;
  161. var newPlayState = this.pending ? 'pending' : this.playState;
  162. if (this.readyPromise && newPlayState !== oldPlayState) {
  163. if (newPlayState === 'idle') {
  164. this.rejectReadyPromise();
  165. this.readyPromise = undefined;
  166. } else if (oldPlayState === 'pending') {
  167. this.resolveReadyPromise();
  168. } else if (newPlayState === 'pending') {
  169. this.readyPromise = undefined;
  170. }
  171. }
  172. if (this.finishedPromise && newPlayState !== oldPlayState) {
  173. if (newPlayState === 'idle') {
  174. this.rejectFinishedPromise();
  175. this.finishedPromise = undefined;
  176. } else if (newPlayState === 'finished') {
  177. this.resolveFinishedPromise();
  178. } else if (oldPlayState === 'finished') {
  179. this.finishedPromise = undefined;
  180. }
  181. }
  182. this.oldPlayState = newPlayState;
  183. return this.readyPromise || this.finishedPromise;
  184. };
  185. _proto.play = function play() {
  186. this.updatePromises();
  187. this._paused = false;
  188. if (this._isFinished || this._idle) {
  189. this.rewind();
  190. this._startTime = null;
  191. }
  192. this._finishedFlag = false;
  193. this._idle = false;
  194. this.ensureAlive();
  195. this.timeline.applyDirtiedAnimation(this);
  196. if (this.timeline.animations.indexOf(this) === -1) {
  197. this.timeline.animations.push(this);
  198. }
  199. this.updatePromises();
  200. };
  201. _proto.pause = function pause() {
  202. this.updatePromises();
  203. if (this.currentTime) {
  204. this._holdTime = this.currentTime;
  205. }
  206. if (!this._isFinished && !this._paused && !this._idle) {
  207. this.currentTimePending = true;
  208. } else if (this._idle) {
  209. this.rewind();
  210. this._idle = false;
  211. }
  212. this._startTime = null;
  213. this._paused = true;
  214. this.updatePromises();
  215. };
  216. _proto.finish = function finish() {
  217. this.updatePromises();
  218. if (this._idle) return;
  219. this.currentTime = this._playbackRate > 0 ? this._totalDuration : 0;
  220. this._startTime = this._totalDuration - this.currentTime;
  221. this.currentTimePending = false;
  222. this.timeline.applyDirtiedAnimation(this);
  223. this.updatePromises();
  224. };
  225. _proto.cancel = function cancel() {
  226. var _this = this;
  227. this.updatePromises();
  228. if (!this._inEffect) return;
  229. this._inEffect = false;
  230. this._idle = true;
  231. this._paused = false;
  232. this._finishedFlag = true;
  233. this._currentTime = 0;
  234. this._startTime = null;
  235. this.effect.update(null);
  236. // effects are invalid after cancellation as the animation state
  237. // needs to un-apply.
  238. this.timeline.applyDirtiedAnimation(this);
  239. this.updatePromises();
  240. /**
  241. * 1. Reject the current finished promise with a DOMException named "AbortError".
  242. * 2. Let current finished promise be a new promise
  243. * @see https://w3c.github.io/csswg-drafts/web-animations-1/#canceling-an-animation-section
  244. */
  245. // if (this.finishedPromise) {
  246. // this.rejectFinishedPromise();
  247. // this.finishedPromise = undefined;
  248. // }
  249. if (this.oncancel) {
  250. var event = new AnimationEvent(null, this, this.currentTime, null);
  251. setTimeout(function () {
  252. _this.oncancel(event);
  253. });
  254. }
  255. };
  256. _proto.reverse = function reverse() {
  257. this.updatePromises();
  258. var oldCurrentTime = this.currentTime;
  259. this.playbackRate *= -1;
  260. this.play();
  261. if (oldCurrentTime !== null) {
  262. this.currentTime = oldCurrentTime;
  263. }
  264. this.updatePromises();
  265. }
  266. /**
  267. * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/updatePlaybackRate
  268. */;
  269. _proto.updatePlaybackRate = function updatePlaybackRate(playbackRate) {
  270. this.playbackRate = playbackRate;
  271. };
  272. _proto.targetAnimations = function targetAnimations() {
  273. var _this$effect2;
  274. var target = (_this$effect2 = this.effect) === null || _this$effect2 === void 0 ? void 0 : _this$effect2.target;
  275. return target.getAnimations();
  276. };
  277. _proto.markTarget = function markTarget() {
  278. var animations = this.targetAnimations();
  279. if (animations.indexOf(this) === -1) {
  280. animations.push(this);
  281. }
  282. };
  283. _proto.unmarkTarget = function unmarkTarget() {
  284. var animations = this.targetAnimations();
  285. var index = animations.indexOf(this);
  286. if (index !== -1) {
  287. animations.splice(index, 1);
  288. }
  289. };
  290. _proto.tick = function tick(timelineTime, isAnimationFrame) {
  291. if (!this._idle && !this._paused) {
  292. if (this._startTime === null) {
  293. if (isAnimationFrame) {
  294. this.startTime = timelineTime - this._currentTime / this.playbackRate;
  295. }
  296. } else if (!this._isFinished) {
  297. this.tickCurrentTime((timelineTime - this._startTime) * this.playbackRate);
  298. }
  299. }
  300. if (isAnimationFrame) {
  301. this.currentTimePending = false;
  302. this.fireEvents(timelineTime);
  303. }
  304. };
  305. _proto.rewind = function rewind() {
  306. if (this.playbackRate >= 0) {
  307. this.currentTime = 0;
  308. } else if (this._totalDuration < Infinity) {
  309. this.currentTime = this._totalDuration;
  310. } else {
  311. throw new Error('Unable to rewind negative playback rate animation with infinite duration');
  312. }
  313. };
  314. _proto.persist = function persist() {
  315. throw new Error(gLite.ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  316. };
  317. _proto.addEventListener = function addEventListener(type, listener, options) {
  318. throw new Error(gLite.ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  319. };
  320. _proto.removeEventListener = function removeEventListener(type, listener, options) {
  321. throw new Error(gLite.ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  322. };
  323. _proto.dispatchEvent = function dispatchEvent(event) {
  324. throw new Error(gLite.ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  325. };
  326. // replaceState: AnimationReplaceState;
  327. _proto.commitStyles = function commitStyles() {
  328. throw new Error(gLite.ERROR_MSG_METHOD_NOT_IMPLEMENTED);
  329. };
  330. _proto.ensureAlive = function ensureAlive() {
  331. // If an animation is playing backwards and is not fill backwards/both
  332. // then it should go out of effect when it reaches the start of its
  333. // active interval (currentTime === 0).
  334. if (this.playbackRate < 0 && this.currentTime === 0) {
  335. var _this$effect3;
  336. this._inEffect = !!((_this$effect3 = this.effect) === null || _this$effect3 === void 0 ? void 0 : _this$effect3.update(-1));
  337. } else {
  338. var _this$effect4;
  339. this._inEffect = !!((_this$effect4 = this.effect) === null || _this$effect4 === void 0 ? void 0 : _this$effect4.update(this.currentTime));
  340. }
  341. if (!this._inTimeline && (this._inEffect || !this._finishedFlag)) {
  342. this._inTimeline = true;
  343. this.timeline.animations.push(this);
  344. }
  345. };
  346. _proto.tickCurrentTime = function tickCurrentTime(newTime, ignoreLimit) {
  347. if (newTime !== this._currentTime) {
  348. this._currentTime = newTime;
  349. if (this._isFinished && !ignoreLimit) {
  350. this._currentTime = this._playbackRate > 0 ? this._totalDuration : 0;
  351. }
  352. this.ensureAlive();
  353. }
  354. };
  355. _proto.fireEvents = function fireEvents(baseTime) {
  356. var _this2 = this;
  357. if (this._isFinished) {
  358. if (!this._finishedFlag) {
  359. if (this.onfinish) {
  360. var event = new AnimationEvent(null, this, this.currentTime, baseTime);
  361. setTimeout(function () {
  362. if (_this2.onfinish) {
  363. _this2.onfinish(event);
  364. }
  365. });
  366. }
  367. this._finishedFlag = true;
  368. }
  369. } else {
  370. if (this.onframe && this.playState === 'running') {
  371. var _event = new AnimationEvent(null, this, this.currentTime, baseTime);
  372. this.onframe(_event);
  373. }
  374. this._finishedFlag = false;
  375. }
  376. };
  377. _createClass(Animation, [{
  378. key: "pending",
  379. get:
  380. // animation: InternalAnimation | null;
  381. /**
  382. * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/pending
  383. */
  384. function get() {
  385. return this._startTime === null && !this._paused && this.playbackRate !== 0 || this.currentTimePending;
  386. }
  387. }, {
  388. key: "playState",
  389. get: function get() {
  390. if (this._idle) return 'idle';
  391. if (this._isFinished) return 'finished';
  392. if (this._paused) return 'paused';
  393. return 'running';
  394. }
  395. }, {
  396. key: "ready",
  397. get:
  398. /**
  399. * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/ready
  400. * @example
  401. animation.pause();
  402. animation.ready.then(function() {
  403. // Displays 'running'
  404. alert(animation.playState);
  405. });
  406. animation.play();
  407. */
  408. function get() {
  409. var _this3 = this;
  410. if (!this.readyPromise) {
  411. if (this.timeline.animationsWithPromises.indexOf(this) === -1) {
  412. this.timeline.animationsWithPromises.push(this);
  413. }
  414. this.readyPromise = new Promise(function (resolve, reject) {
  415. _this3.resolveReadyPromise = function () {
  416. resolve(_this3);
  417. };
  418. _this3.rejectReadyPromise = function () {
  419. reject(new Error());
  420. };
  421. });
  422. if (!this.pending) {
  423. this.resolveReadyPromise();
  424. }
  425. }
  426. return this.readyPromise;
  427. }
  428. /**
  429. * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/finished
  430. * @example
  431. Promise.all(
  432. elem.getAnimations().map(
  433. function(animation) {
  434. return animation.finished
  435. }
  436. )
  437. ).then(
  438. function() {
  439. return elem.remove();
  440. }
  441. );
  442. */
  443. }, {
  444. key: "finished",
  445. get: function get() {
  446. var _this4 = this;
  447. if (!this.finishedPromise) {
  448. if (this.timeline.animationsWithPromises.indexOf(this) === -1) {
  449. this.timeline.animationsWithPromises.push(this);
  450. }
  451. this.finishedPromise = new Promise(function (resolve, reject) {
  452. _this4.resolveFinishedPromise = function () {
  453. resolve(_this4);
  454. };
  455. _this4.rejectFinishedPromise = function () {
  456. reject(new Error());
  457. };
  458. });
  459. if (this.playState === 'finished') {
  460. this.resolveFinishedPromise();
  461. }
  462. }
  463. return this.finishedPromise;
  464. }
  465. }, {
  466. key: "currentTime",
  467. get: function get() {
  468. this.updatePromises();
  469. return this._idle || this.currentTimePending ? null : this._currentTime;
  470. },
  471. set: function set(newTime) {
  472. newTime = Number(newTime);
  473. if (isNaN(newTime)) return;
  474. this.timeline.restart();
  475. if (!this._paused && this._startTime !== null) {
  476. var _this$timeline;
  477. this._startTime = Number((_this$timeline = this.timeline) === null || _this$timeline === void 0 ? void 0 : _this$timeline.currentTime) - newTime / this.playbackRate;
  478. }
  479. this.currentTimePending = false;
  480. if (this._currentTime === newTime) {
  481. return;
  482. }
  483. if (this._idle) {
  484. this._idle = false;
  485. this._paused = true;
  486. }
  487. this.tickCurrentTime(newTime, true);
  488. this.timeline.applyDirtiedAnimation(this);
  489. }
  490. }, {
  491. key: "startTime",
  492. get: function get() {
  493. return this._startTime;
  494. },
  495. set: function set(newTime) {
  496. if (newTime !== null) {
  497. this.updatePromises();
  498. newTime = Number(newTime);
  499. if (isNaN(newTime)) return;
  500. if (this._paused || this._idle) return;
  501. this._startTime = newTime;
  502. this.tickCurrentTime((Number(this.timeline.currentTime) - this._startTime) * this.playbackRate);
  503. this.timeline.applyDirtiedAnimation(this);
  504. this.updatePromises();
  505. }
  506. }
  507. }, {
  508. key: "playbackRate",
  509. get: function get() {
  510. return this._playbackRate;
  511. },
  512. set: function set(value) {
  513. if (value === this._playbackRate) {
  514. return;
  515. }
  516. this.updatePromises();
  517. var oldCurrentTime = this.currentTime;
  518. this._playbackRate = value;
  519. this.startTime = null;
  520. if (this.playState !== 'paused' && this.playState !== 'idle') {
  521. this._finishedFlag = false;
  522. this._idle = false;
  523. this.ensureAlive();
  524. this.timeline.applyDirtiedAnimation(this);
  525. }
  526. if (oldCurrentTime !== null) {
  527. this.currentTime = oldCurrentTime;
  528. }
  529. this.updatePromises();
  530. }
  531. }, {
  532. key: "_isFinished",
  533. get: function get() {
  534. return !this._idle && (this._playbackRate > 0 && Number(this._currentTime) >= this._totalDuration || this._playbackRate < 0 && Number(this._currentTime) <= 0);
  535. }
  536. }, {
  537. key: "totalDuration",
  538. get: function get() {
  539. return this._totalDuration;
  540. }
  541. }, {
  542. key: "_needsTick",
  543. get: function get() {
  544. return this.pending || this.playState === 'running' || !this._finishedFlag;
  545. }
  546. }]);
  547. return Animation;
  548. }();
  549. /**
  550. * https://github.com/gre/bezier-easing
  551. * BezierEasing - use bezier curve for transition easing function
  552. * by Gaëtan Renaudeau 2014 - 2015 – MIT License
  553. */
  554. // These values are established by empiricism with tests (tradeoff: performance VS precision)
  555. var NEWTON_ITERATIONS = 4;
  556. var NEWTON_MIN_SLOPE = 0.001;
  557. var SUBDIVISION_PRECISION = 0.0000001;
  558. var SUBDIVISION_MAX_ITERATIONS = 10;
  559. var kSplineTableSize = 11;
  560. var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
  561. var float32ArraySupported = typeof Float32Array === 'function';
  562. var A = function A(aA1, aA2) {
  563. return 1.0 - 3.0 * aA2 + 3.0 * aA1;
  564. };
  565. var B = function B(aA1, aA2) {
  566. return 3.0 * aA2 - 6.0 * aA1;
  567. };
  568. var C = function C(aA1) {
  569. return 3.0 * aA1;
  570. };
  571. // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
  572. var calcBezier = function calcBezier(aT, aA1, aA2) {
  573. return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
  574. };
  575. // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
  576. var getSlope = function getSlope(aT, aA1, aA2) {
  577. return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
  578. };
  579. var binarySubdivide = function binarySubdivide(aX, aA, aB, mX1, mX2) {
  580. var currentX,
  581. currentT,
  582. i = 0;
  583. do {
  584. currentT = aA + (aB - aA) / 2.0;
  585. currentX = calcBezier(currentT, mX1, mX2) - aX;
  586. if (currentX > 0.0) aB = currentT;else aA = currentT;
  587. } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
  588. return currentT;
  589. };
  590. var newtonRaphsonIterate = function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
  591. for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
  592. var currentSlope = getSlope(aGuessT, mX1, mX2);
  593. if (currentSlope === 0.0) return aGuessT;
  594. var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
  595. aGuessT -= currentX / currentSlope;
  596. }
  597. return aGuessT;
  598. };
  599. var bezier = function bezier(mX1, mY1, mX2, mY2) {
  600. if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) throw new Error('bezier x values must be in [0, 1] range');
  601. if (mX1 === mY1 && mX2 === mY2) return function (t) {
  602. return t;
  603. };
  604. // Precompute samples table
  605. var sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
  606. for (var i = 0; i < kSplineTableSize; ++i) {
  607. sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
  608. }
  609. var getTForX = function getTForX(aX) {
  610. var intervalStart = 0.0;
  611. var currentSample = 1;
  612. var lastSample = kSplineTableSize - 1;
  613. for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) intervalStart += kSampleStepSize;
  614. --currentSample;
  615. // Interpolate to provide an initial guess for t
  616. var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);
  617. var guessForT = intervalStart + dist * kSampleStepSize;
  618. var initialSlope = getSlope(guessForT, mX1, mX2);
  619. if (initialSlope >= NEWTON_MIN_SLOPE) return newtonRaphsonIterate(aX, guessForT, mX1, mX2);else if (initialSlope === 0.0) return guessForT;else {
  620. return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
  621. }
  622. };
  623. return function (t) {
  624. // Because JavaScript number are imprecise, we should guarantee the extremes are right.
  625. if (t === 0 || t === 1) return t;
  626. return calcBezier(getTForX(t), mY1, mY2);
  627. };
  628. };
  629. // isFinite,
  630. var isNil = function (value) {
  631. /**
  632. * isNil(null) => true
  633. * isNil() => true
  634. */
  635. return value === null || value === undefined;
  636. };
  637. var toString = {}.toString;
  638. var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
  639. var clamp = function (a, min, max) {
  640. if (a < min) {
  641. return min;
  642. }
  643. else if (a > max) {
  644. return max;
  645. }
  646. return a;
  647. };
  648. /**
  649. * 判断是否数字
  650. * @return {Boolean} 是否数字
  651. */
  652. var isNumber = function (value) {
  653. return isType(value, 'Number');
  654. };
  655. var convertToDash = function convertToDash(str) {
  656. str = str.replace(/([A-Z])/g, function (letter) {
  657. return "-" + letter.toLowerCase();
  658. });
  659. // Remove first dash
  660. return str.charAt(0) === '-' ? str.substring(1) : str;
  661. };
  662. /**
  663. Easing Functions from anime.js, they are tried and true, so, its better to use them instead of other alternatives
  664. */
  665. var Quad = function Quad(t) {
  666. return Math.pow(t, 2);
  667. };
  668. var Cubic = function Cubic(t) {
  669. return Math.pow(t, 3);
  670. };
  671. var Quart = function Quart(t) {
  672. return Math.pow(t, 4);
  673. };
  674. var Quint = function Quint(t) {
  675. return Math.pow(t, 5);
  676. };
  677. var Expo = function Expo(t) {
  678. return Math.pow(t, 6);
  679. };
  680. var Sine = function Sine(t) {
  681. return 1 - Math.cos(t * Math.PI / 2);
  682. };
  683. var Circ = function Circ(t) {
  684. return 1 - Math.sqrt(1 - t * t);
  685. };
  686. var Back = function Back(t) {
  687. return t * t * (3 * t - 2);
  688. };
  689. var Bounce = function Bounce(t) {
  690. var pow2,
  691. b = 4;
  692. while (t < ((pow2 = Math.pow(2, --b)) - 1) / 11) {}
  693. return 1 / Math.pow(4, 3 - b) - 7.5625 * Math.pow((pow2 * 3 - 2) / 22 - t, 2);
  694. };
  695. var Elastic = function Elastic(t, params) {
  696. if (params === void 0) {
  697. params = [];
  698. }
  699. var _params = params,
  700. _params$ = _params[0],
  701. amplitude = _params$ === void 0 ? 1 : _params$,
  702. _params$2 = _params[1],
  703. period = _params$2 === void 0 ? 0.5 : _params$2;
  704. var a = clamp(Number(amplitude), 1, 10);
  705. var p = clamp(Number(period), 0.1, 2);
  706. if (t === 0 || t === 1) return t;
  707. return -a * Math.pow(2, 10 * (t - 1)) * Math.sin((t - 1 - p / (Math.PI * 2) * Math.asin(1 / a)) * (Math.PI * 2) / p);
  708. };
  709. var Spring = function Spring(t, params, duration) {
  710. if (params === void 0) {
  711. params = [];
  712. }
  713. var _params2 = params,
  714. _params2$ = _params2[0],
  715. mass = _params2$ === void 0 ? 1 : _params2$,
  716. _params2$2 = _params2[1],
  717. stiffness = _params2$2 === void 0 ? 100 : _params2$2,
  718. _params2$3 = _params2[2],
  719. damping = _params2$3 === void 0 ? 10 : _params2$3,
  720. _params2$4 = _params2[3],
  721. velocity = _params2$4 === void 0 ? 0 : _params2$4;
  722. mass = clamp(mass, 0.1, 1000);
  723. stiffness = clamp(stiffness, 0.1, 1000);
  724. damping = clamp(damping, 0.1, 1000);
  725. velocity = clamp(velocity, 0.1, 1000);
  726. var w0 = Math.sqrt(stiffness / mass);
  727. var zeta = damping / (2 * Math.sqrt(stiffness * mass));
  728. var wd = zeta < 1 ? w0 * Math.sqrt(1 - zeta * zeta) : 0;
  729. var a = 1;
  730. var b = zeta < 1 ? (zeta * w0 + -velocity) / wd : -velocity + w0;
  731. var progress = duration ? duration * t / 1000 : t;
  732. if (zeta < 1) {
  733. progress = Math.exp(-progress * zeta * w0) * (a * Math.cos(wd * progress) + b * Math.sin(wd * progress));
  734. } else {
  735. progress = (a + b * progress) * Math.exp(-progress * w0);
  736. }
  737. if (t === 0 || t === 1) return t;
  738. return 1 - progress;
  739. };
  740. /**
  741. * Cache the durations at set easing parameters
  742. */
  743. // export const EasingDurationCache: Map<string | TypeEasingFunction, number> = new Map();
  744. /**
  745. * The threshold for an infinite loop
  746. */
  747. // const INTINITE_LOOP_LIMIT = 10000;
  748. /** Convert easing parameters to Array of numbers, e.g. "spring(2, 500)" to [2, 500] */
  749. // export const parseEasingParameters = (str: string) => {
  750. // const match = /(\(|\s)([^)]+)\)?/.exec(str);
  751. // return match
  752. // ? match[2].split(',').map((value) => {
  753. // const num = parseFloat(value);
  754. // return !Number.isNaN(num) ? num : value.trim();
  755. // })
  756. // : [];
  757. // };
  758. /**
  759. * The spring easing function will only look smooth at certain durations, with certain parameters.
  760. * This functions returns the optimal duration to create a smooth springy animation based on physics
  761. *
  762. * Note: it can also be used to determine the optimal duration of other types of easing function, but be careful of 'in-'
  763. * easing functions, because of the nature of the function it can sometimes create an infinite loop, I suggest only using
  764. * `getEasingDuration` for `spring`, specifically 'out-spring' and 'spring'
  765. */
  766. // export const getEasingDuration = (easing: string | TypeEasingFunction = 'spring') => {
  767. // if (EasingDurationCache.has(easing)) return EasingDurationCache.get(easing);
  768. // // eslint-disable-next-line @typescript-eslint/no-use-before-define
  769. // const easingFunction = typeof easing == 'function' ? easing : getEasingFunction(easing as string);
  770. // const params = typeof easing == 'function' ? [] : parseEasingParameters(easing);
  771. // const frame = 1 / 6;
  772. // let elapsed = 0;
  773. // let rest = 0;
  774. // let count = 0;
  775. // while (++count < INTINITE_LOOP_LIMIT) {
  776. // elapsed += frame;
  777. // if (easingFunction(elapsed, params, undefined) === 1) {
  778. // rest++;
  779. // if (rest >= 16) break;
  780. // } else {
  781. // rest = 0;
  782. // }
  783. // }
  784. // const duration = elapsed * frame * 1000;
  785. // EasingDurationCache.set(easing, duration);
  786. // return duration;
  787. // };
  788. /**
  789. These Easing Functions are based off of the Sozi Project's easing functions
  790. https://github.com/sozi-projects/Sozi/blob/d72e44ebd580dc7579d1e177406ad41e632f961d/src/js/player/Timing.js
  791. */
  792. var Steps = function Steps(t, params) {
  793. if (params === void 0) {
  794. params = [];
  795. }
  796. var _params3 = params,
  797. _params3$ = _params3[0],
  798. steps = _params3$ === void 0 ? 10 : _params3$,
  799. type = _params3[1];
  800. var trunc = type == 'start' ? Math.ceil : Math.floor;
  801. return trunc(clamp(t, 0, 1) * steps) / steps;
  802. };
  803. // @ts-ignore
  804. var Bezier = function Bezier(t, params) {
  805. if (params === void 0) {
  806. params = [];
  807. }
  808. var _params4 = params,
  809. mX1 = _params4[0],
  810. mY1 = _params4[1],
  811. mX2 = _params4[2],
  812. mY2 = _params4[3];
  813. return bezier(mX1, mY1, mX2, mY2)(t);
  814. };
  815. /** The default `ease-in` easing function */
  816. var easein = bezier(0.42, 0.0, 1.0, 1.0);
  817. /** Converts easing functions to their `out`counter parts */
  818. var EaseOut = function EaseOut(ease) {
  819. return function (t, params, duration) {
  820. if (params === void 0) {
  821. params = [];
  822. }
  823. return 1 - ease(1 - t, params, duration);
  824. };
  825. };
  826. /** Converts easing functions to their `in-out` counter parts */
  827. var EaseInOut = function EaseInOut(ease) {
  828. return function (t, params, duration) {
  829. if (params === void 0) {
  830. params = [];
  831. }
  832. return t < 0.5 ? ease(t * 2, params, duration) / 2 : 1 - ease(t * -2 + 2, params, duration) / 2;
  833. };
  834. };
  835. /** Converts easing functions to their `out-in` counter parts */
  836. var EaseOutIn = function EaseOutIn(ease) {
  837. return function (t, params, duration) {
  838. if (params === void 0) {
  839. params = [];
  840. }
  841. return t < 0.5 ? (1 - ease(1 - t * 2, params, duration)) / 2 : (ease(t * 2 - 1, params, duration) + 1) / 2;
  842. };
  843. };
  844. var EasingFunctions = {
  845. steps: Steps,
  846. 'step-start': function stepStart(t) {
  847. return Steps(t, [1, 'start']);
  848. },
  849. 'step-end': function stepEnd(t) {
  850. return Steps(t, [1, 'end']);
  851. },
  852. linear: function linear(t) {
  853. return t;
  854. },
  855. 'cubic-bezier': Bezier,
  856. ease: function ease(t) {
  857. return Bezier(t, [0.25, 0.1, 0.25, 1.0]);
  858. },
  859. in: easein,
  860. out: EaseOut(easein),
  861. 'in-out': EaseInOut(easein),
  862. 'out-in': EaseOutIn(easein),
  863. 'in-quad': Quad,
  864. 'out-quad': EaseOut(Quad),
  865. 'in-out-quad': EaseInOut(Quad),
  866. 'out-in-quad': EaseOutIn(Quad),
  867. 'in-cubic': Cubic,
  868. 'out-cubic': EaseOut(Cubic),
  869. 'in-out-cubic': EaseInOut(Cubic),
  870. 'out-in-cubic': EaseOutIn(Cubic),
  871. 'in-quart': Quart,
  872. 'out-quart': EaseOut(Quart),
  873. 'in-out-quart': EaseInOut(Quart),
  874. 'out-in-quart': EaseOutIn(Quart),
  875. 'in-quint': Quint,
  876. 'out-quint': EaseOut(Quint),
  877. 'in-out-quint': EaseInOut(Quint),
  878. 'out-in-quint': EaseOutIn(Quint),
  879. 'in-expo': Expo,
  880. 'out-expo': EaseOut(Expo),
  881. 'in-out-expo': EaseInOut(Expo),
  882. 'out-in-expo': EaseOutIn(Expo),
  883. 'in-sine': Sine,
  884. 'out-sine': EaseOut(Sine),
  885. 'in-out-sine': EaseInOut(Sine),
  886. 'out-in-sine': EaseOutIn(Sine),
  887. 'in-circ': Circ,
  888. 'out-circ': EaseOut(Circ),
  889. 'in-out-circ': EaseInOut(Circ),
  890. 'out-in-circ': EaseOutIn(Circ),
  891. 'in-back': Back,
  892. 'out-back': EaseOut(Back),
  893. 'in-out-back': EaseInOut(Back),
  894. 'out-in-back': EaseOutIn(Back),
  895. 'in-bounce': Bounce,
  896. 'out-bounce': EaseOut(Bounce),
  897. 'in-out-bounce': EaseInOut(Bounce),
  898. 'out-in-bounce': EaseOutIn(Bounce),
  899. 'in-elastic': Elastic,
  900. 'out-elastic': EaseOut(Elastic),
  901. 'in-out-elastic': EaseInOut(Elastic),
  902. 'out-in-elastic': EaseOutIn(Elastic),
  903. spring: Spring,
  904. 'spring-in': Spring,
  905. 'spring-out': EaseOut(Spring),
  906. 'spring-in-out': EaseInOut(Spring),
  907. 'spring-out-in': EaseOutIn(Spring)
  908. };
  909. /**
  910. * Convert string easing to their proper form
  911. */
  912. var complexEasingSyntax = function complexEasingSyntax(ease) {
  913. return convertToDash(ease).replace(/^ease-/, '') // Remove the "ease-" keyword
  914. .replace(/(\(|\s).+/, '') // Remove the function brackets and parameters
  915. .toLowerCase().trim();
  916. };
  917. /** Re-maps a number from one range to another. Numbers outside the range are not clamped to 0 and 1, because out-of-range values are often intentional and useful. */
  918. var getEasingFunction = function getEasingFunction(ease) {
  919. return EasingFunctions[complexEasingSyntax(ease)] || EasingFunctions.linear;
  920. };
  921. // /**
  922. // * Allows you to register new easing functions
  923. // */
  924. // export const registerEasingFunction = (key: string, fn: TypeEasingFunction) => {
  925. // Object.assign(EasingFunctions, {
  926. // [key]: fn,
  927. // });
  928. // };
  929. // /**
  930. // * Allows you to register multiple new easing functions
  931. // */
  932. // export const registerEasingFunctions = (...obj: typeof EasingFunctions[]) => {
  933. // Object.assign(EasingFunctions, ...obj);
  934. // };
  935. var linear = function linear(x) {
  936. return x;
  937. };
  938. var Start = 1;
  939. var Middle = 0.5;
  940. var End = 0;
  941. function step(count, pos) {
  942. return function (x) {
  943. if (x >= 1) {
  944. return 1;
  945. }
  946. var stepSize = 1 / count;
  947. x += pos * stepSize;
  948. return x - x % stepSize;
  949. };
  950. }
  951. var numberString = '\\s*(-?\\d+\\.?\\d*|-?\\.\\d+)\\s*';
  952. var cubicBezierRe = new RegExp('cubic-bezier\\(' + numberString + ',' + numberString + ',' + numberString + ',' + numberString + '\\)');
  953. var step1Re = /steps\(\s*(\d+)\s*\)/;
  954. var step2Re = /steps\(\s*(\d+)\s*,\s*(start|middle|end)\s*\)/;
  955. function parseEasingFunction(normalizedEasing) {
  956. var cubicData = cubicBezierRe.exec(normalizedEasing);
  957. if (cubicData) {
  958. // @ts-ignore
  959. return bezier.apply(void 0, cubicData.slice(1).map(Number));
  960. }
  961. var step1Data = step1Re.exec(normalizedEasing);
  962. if (step1Data) {
  963. return step(Number(step1Data[1]), End);
  964. }
  965. var step2Data = step2Re.exec(normalizedEasing);
  966. if (step2Data) {
  967. // @ts-ignore
  968. return step(Number(step2Data[1]), {
  969. start: Start,
  970. middle: Middle,
  971. end: End
  972. }[step2Data[2]]);
  973. }
  974. return getEasingFunction(normalizedEasing);
  975. }
  976. function calculateActiveDuration(timing) {
  977. // @ts-ignore
  978. return Math.abs(repeatedDuration(timing) / (timing.playbackRate || 1));
  979. }
  980. function repeatedDuration(timing) {
  981. var _timing$iterations;
  982. // https://drafts.csswg.org/web-animations/#calculating-the-active-duration
  983. if (timing.duration === 0 || timing.iterations === 0) {
  984. return 0;
  985. }
  986. // @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/duration#value
  987. // if (timing.duration === 'auto') {
  988. // timing.duration = 0;
  989. // }
  990. return (timing.duration === 'auto' ? 0 : Number(timing.duration)) * ((_timing$iterations = timing.iterations) !== null && _timing$iterations !== void 0 ? _timing$iterations : 1);
  991. }
  992. var PhaseNone = 0;
  993. var PhaseBefore = 1;
  994. var PhaseAfter = 2;
  995. var PhaseActive = 3;
  996. function calculatePhase(activeDuration, localTime, timing) {
  997. // https://drafts.csswg.org/web-animations/#animation-effect-phases-and-states
  998. if (localTime === null) {
  999. return PhaseNone;
  1000. }
  1001. var endTime = timing.endTime;
  1002. if (localTime < Math.min(timing.delay, endTime)) {
  1003. return PhaseBefore;
  1004. }
  1005. if (localTime >= Math.min(timing.delay + activeDuration + timing.endDelay, endTime)) {
  1006. return PhaseAfter;
  1007. }
  1008. return PhaseActive;
  1009. }
  1010. function calculateActiveTime(activeDuration, fillMode, localTime, phase, delay) {
  1011. // https://drafts.csswg.org/web-animations/#calculating-the-active-time
  1012. switch (phase) {
  1013. case PhaseBefore:
  1014. if (fillMode === 'backwards' || fillMode === 'both') return 0;
  1015. return null;
  1016. case PhaseActive:
  1017. return localTime - delay;
  1018. case PhaseAfter:
  1019. if (fillMode === 'forwards' || fillMode === 'both') return activeDuration;
  1020. return null;
  1021. case PhaseNone:
  1022. return null;
  1023. }
  1024. }
  1025. function calculateOverallProgress(iterationDuration, phase, iterations, activeTime, iterationStart) {
  1026. // https://drafts.csswg.org/web-animations/#calculating-the-overall-progress
  1027. var overallProgress = iterationStart;
  1028. if (iterationDuration === 0) {
  1029. if (phase !== PhaseBefore) {
  1030. overallProgress += iterations;
  1031. }
  1032. } else {
  1033. overallProgress += activeTime / iterationDuration;
  1034. }
  1035. return overallProgress;
  1036. }
  1037. function calculateSimpleIterationProgress(overallProgress, iterationStart, phase, iterations, activeTime, iterationDuration) {
  1038. // https://drafts.csswg.org/web-animations/#calculating-the-simple-iteration-progress
  1039. var simpleIterationProgress = overallProgress === Infinity ? iterationStart % 1 : overallProgress % 1;
  1040. if (simpleIterationProgress === 0 && phase === PhaseAfter && iterations !== 0 && (activeTime !== 0 || iterationDuration === 0)) {
  1041. simpleIterationProgress = 1;
  1042. }
  1043. return simpleIterationProgress;
  1044. }
  1045. function calculateCurrentIteration(phase, iterations, simpleIterationProgress, overallProgress) {
  1046. // https://drafts.csswg.org/web-animations/#calculating-the-current-iteration
  1047. if (phase === PhaseAfter && iterations === Infinity) {
  1048. return Infinity;
  1049. }
  1050. if (simpleIterationProgress === 1) {
  1051. return Math.floor(overallProgress) - 1;
  1052. }
  1053. return Math.floor(overallProgress);
  1054. }
  1055. function calculateDirectedProgress(playbackDirection, currentIteration, simpleIterationProgress) {
  1056. // https://drafts.csswg.org/web-animations/#calculating-the-directed-progress
  1057. var currentDirection = playbackDirection;
  1058. if (playbackDirection !== 'normal' && playbackDirection !== 'reverse') {
  1059. var d = currentIteration;
  1060. if (playbackDirection === 'alternate-reverse') {
  1061. d += 1;
  1062. }
  1063. currentDirection = 'normal';
  1064. if (d !== Infinity && d % 2 !== 0) {
  1065. currentDirection = 'reverse';
  1066. }
  1067. }
  1068. if (currentDirection === 'normal') {
  1069. return simpleIterationProgress;
  1070. }
  1071. return 1 - simpleIterationProgress;
  1072. }
  1073. function calculateIterationProgress(activeDuration, localTime, timing) {
  1074. var phase = calculatePhase(activeDuration, localTime, timing);
  1075. var activeTime = calculateActiveTime(activeDuration, timing.fill, localTime, phase, timing.delay);
  1076. if (activeTime === null) return null;
  1077. var duration = timing.duration === 'auto' ? 0 : timing.duration;
  1078. var overallProgress = calculateOverallProgress(duration, phase, timing.iterations, activeTime, timing.iterationStart);
  1079. var simpleIterationProgress = calculateSimpleIterationProgress(overallProgress, timing.iterationStart, phase, timing.iterations, activeTime, duration);
  1080. var currentIteration = calculateCurrentIteration(phase, timing.iterations, simpleIterationProgress, overallProgress);
  1081. var directedProgress = calculateDirectedProgress(timing.direction, currentIteration, simpleIterationProgress);
  1082. timing.currentIteration = currentIteration;
  1083. timing.progress = directedProgress;
  1084. // https://drafts.csswg.org/web-animations/#calculating-the-transformed-progress
  1085. // https://drafts.csswg.org/web-animations/#calculating-the-iteration-progress
  1086. return timing.easingFunction(directedProgress);
  1087. }
  1088. function convertEffectInput(keyframes, timing, target) {
  1089. var propertySpecificKeyframeGroups = makePropertySpecificKeyframeGroups(keyframes, timing);
  1090. var interpolations = makeInterpolations(propertySpecificKeyframeGroups, target);
  1091. return function (target, fraction) {
  1092. if (fraction !== null) {
  1093. interpolations.filter(function (interpolation) {
  1094. return fraction >= interpolation.applyFrom && fraction < interpolation.applyTo;
  1095. }).forEach(function (interpolation) {
  1096. var offsetFraction = fraction - interpolation.startOffset;
  1097. var localDuration = interpolation.endOffset - interpolation.startOffset;
  1098. var scaledLocalTime = localDuration === 0 ? 0 : interpolation.easingFunction(offsetFraction / localDuration);
  1099. // apply updated attribute
  1100. target.setAttribute(interpolation.property, interpolation.interpolation(scaledLocalTime));
  1101. // if (interpolation.property === 'visibility') {
  1102. // console.log(
  1103. // scaledLocalTime,
  1104. // interpolation.interpolation(scaledLocalTime),
  1105. // );
  1106. // }
  1107. });
  1108. } else {
  1109. for (var property in propertySpecificKeyframeGroups) if (isNotReservedWord(property)) {
  1110. // clear attribute
  1111. target.setAttribute(property, null);
  1112. }
  1113. }
  1114. };
  1115. }
  1116. function isNotReservedWord(member) {
  1117. return member !== 'offset' && member !== 'easing' && member !== 'composite' && member !== 'computedOffset';
  1118. }
  1119. function makePropertySpecificKeyframeGroups(keyframes, timing) {
  1120. var propertySpecificKeyframeGroups = {};
  1121. for (var i = 0; i < keyframes.length; i++) {
  1122. for (var member in keyframes[i]) {
  1123. if (isNotReservedWord(member)) {
  1124. var propertySpecificKeyframe = {
  1125. offset: keyframes[i].offset,
  1126. computedOffset: keyframes[i].computedOffset,
  1127. easing: keyframes[i].easing,
  1128. easingFunction: parseEasingFunction(keyframes[i].easing) || timing.easingFunction,
  1129. value: keyframes[i][member]
  1130. };
  1131. propertySpecificKeyframeGroups[member] = propertySpecificKeyframeGroups[member] || [];
  1132. propertySpecificKeyframeGroups[member].push(propertySpecificKeyframe);
  1133. }
  1134. }
  1135. }
  1136. return propertySpecificKeyframeGroups;
  1137. }
  1138. function makeInterpolations(propertySpecificKeyframeGroups, target) {
  1139. var interpolations = [];
  1140. for (var groupName in propertySpecificKeyframeGroups) {
  1141. var keyframes = propertySpecificKeyframeGroups[groupName];
  1142. for (var i = 0; i < keyframes.length - 1; i++) {
  1143. var startIndex = i;
  1144. var endIndex = i + 1;
  1145. var startOffset = keyframes[startIndex].computedOffset;
  1146. var endOffset = keyframes[endIndex].computedOffset;
  1147. var applyFrom = startOffset;
  1148. var applyTo = endOffset;
  1149. if (i === 0) {
  1150. applyFrom = -Infinity;
  1151. if (endOffset === 0) {
  1152. endIndex = startIndex;
  1153. }
  1154. }
  1155. if (i === keyframes.length - 2) {
  1156. applyTo = Infinity;
  1157. if (startOffset === 1) {
  1158. startIndex = endIndex;
  1159. }
  1160. }
  1161. interpolations.push({
  1162. applyFrom: applyFrom,
  1163. applyTo: applyTo,
  1164. startOffset: keyframes[startIndex].computedOffset,
  1165. endOffset: keyframes[endIndex].computedOffset,
  1166. easingFunction: keyframes[startIndex].easingFunction,
  1167. property: groupName,
  1168. interpolation: propertyInterpolation(groupName, keyframes[startIndex].value, keyframes[endIndex].value, target)
  1169. });
  1170. }
  1171. }
  1172. interpolations.sort(function (leftInterpolation, rightInterpolation) {
  1173. return leftInterpolation.startOffset - rightInterpolation.startOffset;
  1174. });
  1175. return interpolations;
  1176. }
  1177. var InterpolationFactory = function InterpolationFactory(from, to,
  1178. // eslint-disable-next-line @typescript-eslint/ban-types
  1179. convertToString) {
  1180. return function (f) {
  1181. var interpolated = interpolate(from, to, f);
  1182. return !gLite.runtime.enableCSSParsing && isNumber(interpolated) ? interpolated : convertToString(interpolated);
  1183. };
  1184. };
  1185. function propertyInterpolation(property, left, right, target) {
  1186. var metadata = gLite.propertyMetadataCache[property];
  1187. // discrete step
  1188. // if (property === 'visibility') {
  1189. // return function (t: number) {
  1190. // if (t === 0) return left;
  1191. // if (t === 1) return right;
  1192. // debugger;
  1193. // return t < 0.5 ? left : right;
  1194. // };
  1195. // }
  1196. if (metadata && metadata.syntax && metadata.int) {
  1197. var propertyHandler = gLite.runtime.styleValueRegistry.getPropertySyntax(metadata.syntax);
  1198. if (propertyHandler) {
  1199. var usedLeft;
  1200. var usedRight;
  1201. if (gLite.runtime.enableCSSParsing) {
  1202. var computedLeft = gLite.runtime.styleValueRegistry.parseProperty(property, left, target);
  1203. var computedRight = gLite.runtime.styleValueRegistry.parseProperty(property, right, target);
  1204. usedLeft = gLite.runtime.styleValueRegistry.computeProperty(property, computedLeft, target);
  1205. usedRight = gLite.runtime.styleValueRegistry.computeProperty(property, computedRight, target);
  1206. } else {
  1207. var parser = propertyHandler.parserWithCSSDisabled;
  1208. usedLeft = parser ? parser(left, target) : left;
  1209. usedRight = parser ? parser(right, target) : right;
  1210. }
  1211. // merger [left, right, n2string()]
  1212. var interpolationArgs = propertyHandler.mixer(usedLeft, usedRight, target);
  1213. if (interpolationArgs) {
  1214. var interp = InterpolationFactory.apply(void 0, interpolationArgs);
  1215. return function (t) {
  1216. if (t === 0) return left;
  1217. if (t === 1) return right;
  1218. return interp(t);
  1219. };
  1220. }
  1221. }
  1222. }
  1223. // eslint-disable-next-line @typescript-eslint/no-use-before-define
  1224. return InterpolationFactory(false, true, function (bool) {
  1225. return bool ? right : left;
  1226. });
  1227. }
  1228. /**
  1229. * interpolate with number, boolean, number[], boolean[]
  1230. */
  1231. function interpolate(from, to, f) {
  1232. if (typeof from === 'number' && typeof to === 'number') {
  1233. return from * (1 - f) + to * f;
  1234. }
  1235. if (typeof from === 'boolean' && typeof to === 'boolean' || typeof from === 'string' && typeof to === 'string' // skip string, eg. path ['M', 10, 10]
  1236. ) {
  1237. return f < 0.5 ? from : to;
  1238. }
  1239. if (Array.isArray(from) && Array.isArray(to)) {
  1240. // interpolate arrays/matrix
  1241. var fromLength = from.length;
  1242. var toLength = to.length;
  1243. var length = Math.max(fromLength, toLength);
  1244. var r = [];
  1245. for (var i = 0; i < length; i++) {
  1246. r.push(interpolate(from[i < fromLength ? i : fromLength - 1], to[i < toLength ? i : toLength - 1], f));
  1247. }
  1248. return r;
  1249. }
  1250. throw new Error('Mismatched interpolation arguments ' + from + ':' + to);
  1251. }
  1252. /**
  1253. * @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming
  1254. */
  1255. var AnimationEffectTiming = /*#__PURE__*/function () {
  1256. function AnimationEffectTiming() {
  1257. /**
  1258. * @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/delay
  1259. */
  1260. this.delay = 0;
  1261. /**
  1262. * @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/direction
  1263. */
  1264. this.direction = 'normal';
  1265. /**
  1266. * @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/duration
  1267. */
  1268. this.duration = 'auto';
  1269. /**
  1270. * @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/easing
  1271. */
  1272. this._easing = 'linear';
  1273. this.easingFunction = linear;
  1274. /**
  1275. * @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/endDelay
  1276. */
  1277. this.endDelay = 0;
  1278. /**
  1279. * @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/fill
  1280. */
  1281. this.fill = 'auto';
  1282. /**
  1283. * @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/iterationStart
  1284. */
  1285. this.iterationStart = 0;
  1286. /**
  1287. * @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/iterations
  1288. */
  1289. this.iterations = 1;
  1290. /**
  1291. * @deprecated
  1292. */
  1293. this.playbackRate = void 0;
  1294. /**
  1295. * ref to effect
  1296. */
  1297. this.effect = void 0;
  1298. this.composite = void 0;
  1299. /**
  1300. * ComputedEffectTiming
  1301. * @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEffect/getComputedTiming
  1302. */
  1303. this.activeDuration = void 0;
  1304. this.endTime = void 0;
  1305. this.currentIteration = null;
  1306. this.progress = null;
  1307. }
  1308. _createClass(AnimationEffectTiming, [{
  1309. key: "easing",
  1310. get: function get() {
  1311. return this._easing;
  1312. },
  1313. set: function set(value) {
  1314. this.easingFunction = parseEasingFunction(value);
  1315. this._easing = value;
  1316. }
  1317. }]);
  1318. return AnimationEffectTiming;
  1319. }();
  1320. /**
  1321. * @example
  1322. {
  1323. translateY: [200, 300],
  1324. scale: [1, 10],
  1325. }
  1326. * groups' length can be different, the following config should generate 3 frames:
  1327. @example
  1328. {
  1329. translateY: [200, 300, 400],
  1330. scale: [1, 10],
  1331. }
  1332. */
  1333. function convertToArrayForm(effectInput) {
  1334. var normalizedEffectInput = [];
  1335. for (var property in effectInput) {
  1336. // skip reserved props
  1337. if (property in ['easing', 'offset', 'composite']) {
  1338. continue;
  1339. }
  1340. // @ts-ignore
  1341. var values = effectInput[property];
  1342. if (!Array.isArray(values)) {
  1343. values = [values];
  1344. }
  1345. var numKeyframes = values.length;
  1346. for (var i = 0; i < numKeyframes; i++) {
  1347. if (!normalizedEffectInput[i]) {
  1348. var keyframe = {};
  1349. if ('offset' in effectInput) {
  1350. keyframe.offset = Number(effectInput.offset);
  1351. }
  1352. if ('easing' in effectInput) {
  1353. // @ts-ignore
  1354. keyframe.easing = effectInput.easing;
  1355. }
  1356. if ('composite' in effectInput) {
  1357. // @ts-ignore
  1358. keyframe.composite = effectInput.composite;
  1359. }
  1360. normalizedEffectInput[i] = keyframe;
  1361. }
  1362. if (values[i] !== undefined && values[i] !== null) {
  1363. normalizedEffectInput[i][property] = values[i];
  1364. }
  1365. }
  1366. }
  1367. normalizedEffectInput.sort(function (a, b) {
  1368. return (a.computedOffset || 0) - (b.computedOffset || 0);
  1369. });
  1370. return normalizedEffectInput;
  1371. }
  1372. function normalizeKeyframes(effectInput, timing) {
  1373. if (effectInput === null) {
  1374. return [];
  1375. }
  1376. if (!Array.isArray(effectInput)) {
  1377. effectInput = convertToArrayForm(effectInput);
  1378. }
  1379. var keyframes = effectInput.map(function (originalKeyframe) {
  1380. var keyframe = {};
  1381. if (timing === null || timing === void 0 ? void 0 : timing.composite) {
  1382. // This will be auto if the composite operation specified on the effect is being used.
  1383. // @see https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Keyframe_Formats
  1384. keyframe.composite = 'auto';
  1385. }
  1386. for (var member in originalKeyframe) {
  1387. var memberValue = originalKeyframe[member];
  1388. if (member === 'offset') {
  1389. if (memberValue !== null) {
  1390. memberValue = Number(memberValue);
  1391. if (!isFinite(memberValue)) throw new Error('Keyframe offsets must be numbers.');
  1392. if (memberValue < 0 || memberValue > 1) throw new Error('Keyframe offsets must be between 0 and 1.');
  1393. keyframe.computedOffset = memberValue;
  1394. }
  1395. } else if (member === 'composite') {
  1396. // TODO: Support add & accumulate in KeyframeEffect.composite
  1397. // @see https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/composite
  1398. if (['replace', 'add', 'accumulate', 'auto'].indexOf(memberValue) === -1) {
  1399. throw new Error(memberValue + " compositing is not supported");
  1400. }
  1401. } else ;
  1402. // assign to keyframe, no need to parse shorthand value
  1403. keyframe[member] = memberValue;
  1404. }
  1405. if (keyframe.offset === undefined) {
  1406. keyframe.offset = null;
  1407. }
  1408. if (keyframe.easing === undefined) {
  1409. // override with timing.easing
  1410. keyframe.easing = (timing === null || timing === void 0 ? void 0 : timing.easing) || 'linear';
  1411. }
  1412. if (keyframe.composite === undefined) {
  1413. keyframe.composite = 'auto';
  1414. }
  1415. return keyframe;
  1416. });
  1417. var everyFrameHasOffset = true;
  1418. var previousOffset = -Infinity;
  1419. for (var i = 0; i < keyframes.length; i++) {
  1420. var offset = keyframes[i].offset;
  1421. if (!isNil(offset)) {
  1422. if (offset < previousOffset) {
  1423. throw new TypeError('Keyframes are not loosely sorted by offset. Sort or specify offsets.');
  1424. }
  1425. previousOffset = offset;
  1426. } else {
  1427. everyFrameHasOffset = false;
  1428. }
  1429. }
  1430. keyframes = keyframes.filter(function (keyframe) {
  1431. return Number(keyframe.offset) >= 0 && Number(keyframe.offset) <= 1;
  1432. });
  1433. function spaceKeyframes() {
  1434. var _keyframes$offset;
  1435. var length = keyframes.length;
  1436. keyframes[length - 1].computedOffset = Number((_keyframes$offset = keyframes[length - 1].offset) !== null && _keyframes$offset !== void 0 ? _keyframes$offset : 1);
  1437. if (length > 1) {
  1438. var _keyframes$0$offset;
  1439. keyframes[0].computedOffset = Number((_keyframes$0$offset = keyframes[0].offset) !== null && _keyframes$0$offset !== void 0 ? _keyframes$0$offset : 0);
  1440. }
  1441. var previousIndex = 0;
  1442. var previousOffset = Number(keyframes[0].computedOffset);
  1443. for (var _i = 1; _i < length; _i++) {
  1444. var _offset = keyframes[_i].computedOffset;
  1445. if (!isNil(_offset) && !isNil(previousOffset)) {
  1446. for (var j = 1; j < _i - previousIndex; j++) keyframes[previousIndex + j].computedOffset = previousOffset + (Number(_offset) - previousOffset) * j / (_i - previousIndex);
  1447. previousIndex = _i;
  1448. previousOffset = Number(_offset);
  1449. }
  1450. }
  1451. }
  1452. if (!everyFrameHasOffset) spaceKeyframes();
  1453. return keyframes;
  1454. }
  1455. var fills = 'backwards|forwards|both|none'.split('|');
  1456. var directions = 'reverse|alternate|alternate-reverse'.split('|');
  1457. function makeTiming(timingInput, forGroup) {
  1458. var timing = new AnimationEffectTiming();
  1459. if (forGroup) {
  1460. timing.fill = 'both';
  1461. timing.duration = 'auto';
  1462. }
  1463. if (typeof timingInput === 'number' && !isNaN(timingInput)) {
  1464. timing.duration = timingInput;
  1465. } else if (timingInput !== undefined) {
  1466. Object.keys(timingInput).forEach(function (property) {
  1467. if (timingInput[property] !== undefined && timingInput[property] !== null && timingInput[property] !== 'auto') {
  1468. if (typeof timing[property] === 'number' || property === 'duration') {
  1469. if (typeof timingInput[property] !== 'number' || isNaN(timingInput[property])) {
  1470. return;
  1471. }
  1472. }
  1473. if (property === 'fill' && fills.indexOf(timingInput[property]) === -1) {
  1474. return;
  1475. }
  1476. if (property === 'direction' && directions.indexOf(timingInput[property]) === -1) {
  1477. return;
  1478. }
  1479. // @ts-ignore
  1480. timing[property] = timingInput[property];
  1481. }
  1482. });
  1483. }
  1484. return timing;
  1485. }
  1486. function normalizeTimingInput(timingInput, forGroup) {
  1487. var _timingInput;
  1488. timingInput = numericTimingToObject((_timingInput = timingInput) !== null && _timingInput !== void 0 ? _timingInput : {
  1489. duration: 'auto'
  1490. });
  1491. return makeTiming(timingInput, forGroup);
  1492. }
  1493. function numericTimingToObject(timingInput) {
  1494. if (typeof timingInput === 'number') {
  1495. if (isNaN(timingInput)) {
  1496. timingInput = {
  1497. duration: 'auto'
  1498. };
  1499. } else {
  1500. timingInput = {
  1501. duration: timingInput
  1502. };
  1503. }
  1504. }
  1505. return timingInput;
  1506. }
  1507. /**
  1508. * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect
  1509. * @example
  1510. const circleDownKeyframes = new KeyframeEffect(
  1511. circle, // element to animate
  1512. [
  1513. { transform: 'translateY(0)' }, // keyframe
  1514. { transform: 'translateY(100)' } // keyframe
  1515. ],
  1516. { duration: 3000, fill: 'forwards' } // keyframe options
  1517. );
  1518. *
  1519. */
  1520. var KeyframeEffect = /*#__PURE__*/function () {
  1521. function KeyframeEffect(target, effectInput, timingInput) {
  1522. var _this = this;
  1523. this.composite = 'replace';
  1524. this.iterationComposite = 'replace';
  1525. // pseudoElement: string | null;
  1526. this.target = void 0;
  1527. this.animation = void 0;
  1528. this.timing = void 0;
  1529. this.computedTiming = void 0;
  1530. this.normalizedKeyframes = void 0;
  1531. this.timeFraction = void 0;
  1532. this.interpolations = void 0;
  1533. this.target = target;
  1534. this.timing = normalizeTimingInput(timingInput, false);
  1535. this.timing.effect = this;
  1536. this.timing.activeDuration = calculateActiveDuration(this.timing);
  1537. this.timing.endTime = Math.max(0, this.timing.delay + this.timing.activeDuration + this.timing.endDelay);
  1538. this.normalizedKeyframes = normalizeKeyframes(effectInput, this.timing);
  1539. this.interpolations = convertEffectInput(this.normalizedKeyframes, this.timing, this.target);
  1540. // 不支持 proxy 时降级成 this.timing
  1541. var Proxy = gLite.runtime.globalThis.Proxy;
  1542. this.computedTiming = Proxy ? new Proxy(this.timing, {
  1543. get: function get(target, prop) {
  1544. if (prop === 'duration') {
  1545. return target.duration === 'auto' ? 0 : target.duration;
  1546. } else if (prop === 'fill') {
  1547. return target.fill === 'auto' ? 'none' : target.fill;
  1548. } else if (prop === 'localTime') {
  1549. return _this.animation && _this.animation.currentTime || null;
  1550. } else if (prop === 'currentIteration') {
  1551. if (!_this.animation || _this.animation.playState !== 'running') {
  1552. return null;
  1553. }
  1554. return target.currentIteration || 0;
  1555. } else if (prop === 'progress') {
  1556. if (!_this.animation || _this.animation.playState !== 'running') {
  1557. return null;
  1558. }
  1559. return target.progress || 0;
  1560. }
  1561. return target[prop];
  1562. },
  1563. set: function set() {
  1564. return true;
  1565. }
  1566. }) : this.timing;
  1567. }
  1568. var _proto = KeyframeEffect.prototype;
  1569. _proto.applyInterpolations = function applyInterpolations() {
  1570. this.interpolations(this.target, Number(this.timeFraction));
  1571. };
  1572. _proto.update = function update(localTime) {
  1573. if (localTime === null) {
  1574. return false;
  1575. }
  1576. this.timeFraction = calculateIterationProgress(this.timing.activeDuration, localTime, this.timing);
  1577. return this.timeFraction !== null;
  1578. };
  1579. _proto.getKeyframes = function getKeyframes() {
  1580. return this.normalizedKeyframes;
  1581. };
  1582. _proto.setKeyframes = function setKeyframes(keyframes) {
  1583. this.normalizedKeyframes = normalizeKeyframes(keyframes);
  1584. }
  1585. /**
  1586. * @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEffect/getComputedTiming
  1587. */;
  1588. _proto.getComputedTiming = function getComputedTiming() {
  1589. return this.computedTiming;
  1590. }
  1591. /**
  1592. * @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEffect/getTiming
  1593. */;
  1594. _proto.getTiming = function getTiming() {
  1595. return this.timing;
  1596. }
  1597. /**
  1598. * @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEffect/updateTiming
  1599. */;
  1600. _proto.updateTiming = function updateTiming(timing) {
  1601. var _this2 = this;
  1602. Object.keys(timing || {}).forEach(function (name) {
  1603. _this2.timing[name] = timing[name];
  1604. });
  1605. };
  1606. return KeyframeEffect;
  1607. }();
  1608. function compareAnimations(leftAnimation, rightAnimation) {
  1609. return Number(leftAnimation.id) - Number(rightAnimation.id);
  1610. }
  1611. /**
  1612. * @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/web-animations-js/index.d.ts
  1613. */
  1614. var AnimationTimeline = /*#__PURE__*/function () {
  1615. function AnimationTimeline(document) {
  1616. var _this = this;
  1617. this.document = void 0;
  1618. /**
  1619. * all active animations
  1620. */
  1621. this.animations = [];
  1622. this.ticking = false;
  1623. this.timelineTicking = false;
  1624. this.hasRestartedThisFrame = false;
  1625. this.animationsWithPromises = [];
  1626. this.inTick = false;
  1627. this.pendingEffects = [];
  1628. this.currentTime = null;
  1629. this.rafId = 0;
  1630. this.rafCallbacks = [];
  1631. this.frameId = void 0;
  1632. this.webAnimationsNextTick = function (t) {
  1633. _this.currentTime = t;
  1634. _this.discardAnimations();
  1635. if (_this.animations.length === 0) {
  1636. _this.timelineTicking = false;
  1637. } else {
  1638. _this.requestAnimationFrame(_this.webAnimationsNextTick);
  1639. }
  1640. };
  1641. this.processRafCallbacks = function (t) {
  1642. var processing = _this.rafCallbacks;
  1643. _this.rafCallbacks = [];
  1644. if (t < Number(_this.currentTime)) t = Number(_this.currentTime);
  1645. _this.animations.sort(compareAnimations);
  1646. _this.animations = _this.tick(t, true, _this.animations)[0];
  1647. processing.forEach(function (entry) {
  1648. entry[1](t);
  1649. });
  1650. _this.applyPendingEffects();
  1651. };
  1652. this.document = document;
  1653. }
  1654. var _proto = AnimationTimeline.prototype;
  1655. _proto.getAnimations = function getAnimations() {
  1656. this.discardAnimations();
  1657. return this.animations.slice();
  1658. };
  1659. _proto.isTicking = function isTicking() {
  1660. return this.inTick;
  1661. };
  1662. _proto.play = function play(target, keyframes, options) {
  1663. var effect = new KeyframeEffect(target, keyframes, options);
  1664. var animation = new Animation(effect, this);
  1665. this.animations.push(animation);
  1666. this.restartWebAnimationsNextTick();
  1667. animation.updatePromises();
  1668. animation.play();
  1669. animation.updatePromises();
  1670. return animation;
  1671. }
  1672. // RAF is supposed to be the last script to occur before frame rendering but not
  1673. // all browsers behave like this. This function is for synchonously updating an
  1674. // animation's effects whenever its state is mutated by script to work around
  1675. // incorrect script execution ordering by the browser.
  1676. ;
  1677. _proto.applyDirtiedAnimation = function applyDirtiedAnimation(animation) {
  1678. var _this2 = this;
  1679. if (this.inTick) {
  1680. return;
  1681. }
  1682. // update active animations in displayobject
  1683. animation.markTarget();
  1684. var animations = animation.targetAnimations();
  1685. animations.sort(compareAnimations);
  1686. // clear inactive animations
  1687. var inactiveAnimations = this.tick(Number(this.currentTime), false, animations.slice())[1];
  1688. inactiveAnimations.forEach(function (animation) {
  1689. var index = _this2.animations.indexOf(animation);
  1690. if (index !== -1) {
  1691. _this2.animations.splice(index, 1);
  1692. }
  1693. });
  1694. this.applyPendingEffects();
  1695. };
  1696. _proto.restart = function restart() {
  1697. if (!this.ticking) {
  1698. this.ticking = true;
  1699. this.requestAnimationFrame(function () {});
  1700. this.hasRestartedThisFrame = true;
  1701. }
  1702. return this.hasRestartedThisFrame;
  1703. };
  1704. _proto.destroy = function destroy() {
  1705. this.document.defaultView.cancelAnimationFrame(this.frameId);
  1706. };
  1707. _proto.applyPendingEffects = function applyPendingEffects() {
  1708. this.pendingEffects.forEach(function (effect) {
  1709. effect === null || effect === void 0 ? void 0 : effect.applyInterpolations();
  1710. });
  1711. this.pendingEffects = [];
  1712. };
  1713. _proto.updateAnimationsPromises = function updateAnimationsPromises() {
  1714. this.animationsWithPromises = this.animationsWithPromises.filter(function (animation) {
  1715. return animation.updatePromises();
  1716. });
  1717. };
  1718. _proto.discardAnimations = function discardAnimations() {
  1719. this.updateAnimationsPromises();
  1720. this.animations = this.animations.filter(function (animation) {
  1721. return animation.playState !== 'finished' && animation.playState !== 'idle';
  1722. });
  1723. };
  1724. _proto.restartWebAnimationsNextTick = function restartWebAnimationsNextTick() {
  1725. if (!this.timelineTicking) {
  1726. this.timelineTicking = true;
  1727. this.requestAnimationFrame(this.webAnimationsNextTick);
  1728. }
  1729. };
  1730. _proto.rAF = function rAF(f) {
  1731. var id = this.rafId++;
  1732. if (this.rafCallbacks.length === 0) {
  1733. this.frameId = this.document.defaultView.requestAnimationFrame(this.processRafCallbacks);
  1734. }
  1735. this.rafCallbacks.push([id, f]);
  1736. return id;
  1737. };
  1738. _proto.requestAnimationFrame = function requestAnimationFrame(f) {
  1739. var _this3 = this;
  1740. return this.rAF(function (x) {
  1741. _this3.updateAnimationsPromises();
  1742. f(x);
  1743. _this3.updateAnimationsPromises();
  1744. });
  1745. };
  1746. _proto.tick = function tick(t, isAnimationFrame, updatingAnimations) {
  1747. var _this4 = this,
  1748. _this$pendingEffects,
  1749. _this$pendingEffects2;
  1750. this.inTick = true;
  1751. this.hasRestartedThisFrame = false;
  1752. this.currentTime = t;
  1753. this.ticking = false;
  1754. var newPendingClears = [];
  1755. var newPendingEffects = [];
  1756. var activeAnimations = [];
  1757. var inactiveAnimations = [];
  1758. updatingAnimations.forEach(function (animation) {
  1759. animation.tick(t, isAnimationFrame);
  1760. if (!animation._inEffect) {
  1761. newPendingClears.push(animation.effect);
  1762. animation.unmarkTarget();
  1763. } else {
  1764. newPendingEffects.push(animation.effect);
  1765. animation.markTarget();
  1766. }
  1767. if (animation._needsTick) _this4.ticking = true;
  1768. var alive = animation._inEffect || animation._needsTick;
  1769. animation._inTimeline = alive;
  1770. if (alive) {
  1771. activeAnimations.push(animation);
  1772. } else {
  1773. inactiveAnimations.push(animation);
  1774. }
  1775. });
  1776. (_this$pendingEffects = this.pendingEffects).push.apply(_this$pendingEffects, newPendingClears);
  1777. (_this$pendingEffects2 = this.pendingEffects).push.apply(_this$pendingEffects2, newPendingEffects);
  1778. if (this.ticking) this.requestAnimationFrame(function () {});
  1779. this.inTick = false;
  1780. return [activeAnimations, inactiveAnimations];
  1781. };
  1782. return AnimationTimeline;
  1783. }();
  1784. gLite.runtime.EasingFunction = parseEasingFunction;
  1785. gLite.runtime.AnimationTimeline = AnimationTimeline;
  1786. exports.Animation = Animation;
  1787. exports.AnimationEvent = AnimationEvent;
  1788. exports.AnimationTimeline = AnimationTimeline;
  1789. exports.KeyframeEffect = KeyframeEffect;
  1790. exports.compareAnimations = compareAnimations;
  1791. exports.makeTiming = makeTiming;
  1792. exports.normalizeKeyframes = normalizeKeyframes;
  1793. exports.normalizeTimingInput = normalizeTimingInput;
  1794. exports.numericTimingToObject = numericTimingToObject;
  1795. Object.defineProperty(exports, '__esModule', { value: true });
  1796. })));