@antv/g-web-animations-api
Advanced tools
Comparing version 1.0.16 to 1.0.17
@@ -13,3 +13,2 @@ import { FederatedEvent, ERROR_MSG_METHOD_NOT_IMPLEMENTED, propertyMetadataCache, runtime } from '@antv/g-lite'; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
@@ -23,10 +22,7 @@ if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
@@ -43,9 +39,6 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
*/ | ||
var AnimationEvent = /*#__PURE__*/function (_FederatedEvent) { | ||
_inheritsLoose(AnimationEvent, _FederatedEvent); | ||
function AnimationEvent(manager, target, currentTime, timelineTime) { | ||
var _this; | ||
_this = _FederatedEvent.call(this, manager) || this; | ||
@@ -55,8 +48,8 @@ _this.currentTime = void 0; | ||
_this.currentTime = currentTime; | ||
_this.timelineTime = timelineTime; // @ts-ignore | ||
_this.timelineTime = timelineTime; | ||
// @ts-ignore | ||
_this.target = target; | ||
_this.type = 'finish'; | ||
_this.bubbles = false; // @ts-ignore | ||
_this.bubbles = false; | ||
// @ts-ignore | ||
_this.currentTarget = target; | ||
@@ -70,3 +63,2 @@ _this.defaultPrevented = false; | ||
} | ||
return AnimationEvent; | ||
@@ -79,7 +71,5 @@ }(FederatedEvent); | ||
*/ | ||
var Animation = /*#__PURE__*/function () { | ||
function Animation(effect, timeline) { | ||
var _this$effect; | ||
this.effect = void 0; | ||
@@ -125,10 +115,6 @@ this.timeline = void 0; | ||
*/ | ||
var _proto = Animation.prototype; | ||
_proto.updatePromises = function updatePromises() { | ||
var oldPlayState = this.oldPlayState; | ||
var newPlayState = this.pending ? 'pending' : this.playState; | ||
if (this.readyPromise && newPlayState !== oldPlayState) { | ||
@@ -144,3 +130,2 @@ if (newPlayState === 'idle') { | ||
} | ||
if (this.finishedPromise && newPlayState !== oldPlayState) { | ||
@@ -156,11 +141,8 @@ if (newPlayState === 'idle') { | ||
} | ||
this.oldPlayState = newPlayState; | ||
return this.readyPromise || this.finishedPromise; | ||
}; | ||
_proto.play = function play() { | ||
this.updatePromises(); | ||
this._paused = false; | ||
if (this._isFinished || this._idle) { | ||
@@ -170,3 +152,2 @@ this.rewind(); | ||
} | ||
this._finishedFlag = false; | ||
@@ -176,17 +157,12 @@ this._idle = false; | ||
this.timeline.applyDirtiedAnimation(this); | ||
if (this.timeline.animations.indexOf(this) === -1) { | ||
this.timeline.animations.push(this); | ||
} | ||
this.updatePromises(); | ||
}; | ||
_proto.pause = function pause() { | ||
this.updatePromises(); | ||
if (this.currentTime) { | ||
this._holdTime = this.currentTime; | ||
} | ||
if (!this._isFinished && !this._paused && !this._idle) { | ||
@@ -198,3 +174,2 @@ this.currentTimePending = true; | ||
} | ||
this._startTime = null; | ||
@@ -204,3 +179,2 @@ this._paused = true; | ||
}; | ||
_proto.finish = function finish() { | ||
@@ -215,3 +189,2 @@ this.updatePromises(); | ||
}; | ||
_proto.cancel = function cancel() { | ||
@@ -226,9 +199,8 @@ this.updatePromises(); | ||
this._startTime = null; | ||
this.effect.update(null); // effects are invalid after cancellation as the animation state | ||
this.effect.update(null); | ||
// effects are invalid after cancellation as the animation state | ||
// needs to un-apply. | ||
this.timeline.applyDirtiedAnimation(this); | ||
this.updatePromises(); | ||
}; | ||
_proto.reverse = function reverse() { | ||
@@ -239,7 +211,5 @@ this.updatePromises(); | ||
this.play(); | ||
if (oldCurrentTime !== null) { | ||
this.currentTime = oldCurrentTime; | ||
} | ||
this.updatePromises(); | ||
@@ -249,19 +219,13 @@ } | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/updatePlaybackRate | ||
*/ | ||
; | ||
*/; | ||
_proto.updatePlaybackRate = function updatePlaybackRate(playbackRate) { | ||
this.playbackRate = playbackRate; | ||
}; | ||
_proto.targetAnimations = function targetAnimations() { | ||
var _this$effect2; | ||
var target = (_this$effect2 = this.effect) === null || _this$effect2 === void 0 ? void 0 : _this$effect2.target; | ||
return target.getAnimations(); | ||
}; | ||
_proto.markTarget = function markTarget() { | ||
var animations = this.targetAnimations(); | ||
if (animations.indexOf(this) === -1) { | ||
@@ -271,7 +235,5 @@ animations.push(this); | ||
}; | ||
_proto.unmarkTarget = function unmarkTarget() { | ||
var animations = this.targetAnimations(); | ||
var index = animations.indexOf(this); | ||
if (index !== -1) { | ||
@@ -281,3 +243,2 @@ animations.splice(index, 1); | ||
}; | ||
_proto.tick = function tick(timelineTime, isAnimationFrame) { | ||
@@ -293,3 +254,2 @@ if (!this._idle && !this._paused) { | ||
} | ||
if (isAnimationFrame) { | ||
@@ -300,3 +260,2 @@ this.currentTimePending = false; | ||
}; | ||
_proto.rewind = function rewind() { | ||
@@ -311,22 +270,20 @@ if (this.playbackRate >= 0) { | ||
}; | ||
_proto.persist = function persist() { | ||
throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED); | ||
} // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
; | ||
_proto.addEventListener = function addEventListener(type, listener, options) { | ||
throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED); | ||
} // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
; | ||
_proto.removeEventListener = function removeEventListener(type, listener, options) { | ||
throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED); | ||
} // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
; | ||
_proto.dispatchEvent = function dispatchEvent(event) { | ||
throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED); | ||
}; | ||
// replaceState: AnimationReplaceState; | ||
@@ -336,3 +293,2 @@ _proto.commitStyles = function commitStyles() { | ||
}; | ||
_proto.ensureAlive = function ensureAlive() { | ||
@@ -344,10 +300,7 @@ // If an animation is playing backwards and is not fill backwards/both | ||
var _this$effect3; | ||
this._inEffect = !!((_this$effect3 = this.effect) === null || _this$effect3 === void 0 ? void 0 : _this$effect3.update(-1)); | ||
} else { | ||
var _this$effect4; | ||
this._inEffect = !!((_this$effect4 = this.effect) === null || _this$effect4 === void 0 ? void 0 : _this$effect4.update(this.currentTime)); | ||
} | ||
if (!this._inTimeline && (this._inEffect || !this._finishedFlag)) { | ||
@@ -358,18 +311,13 @@ this._inTimeline = true; | ||
}; | ||
_proto.tickCurrentTime = function tickCurrentTime(newTime, ignoreLimit) { | ||
if (newTime !== this._currentTime) { | ||
this._currentTime = newTime; | ||
if (this._isFinished && !ignoreLimit) { | ||
this._currentTime = this._playbackRate > 0 ? this._totalDuration : 0; | ||
} | ||
this.ensureAlive(); | ||
} | ||
}; | ||
_proto.fireEvents = function fireEvents(baseTime) { | ||
var _this = this; | ||
if (this._isFinished) { | ||
@@ -385,3 +333,2 @@ if (!this._finishedFlag) { | ||
} | ||
this._finishedFlag = true; | ||
@@ -392,10 +339,7 @@ } | ||
var _event = new AnimationEvent(null, this, this.currentTime, baseTime); | ||
this.onframe(_event); | ||
} | ||
this._finishedFlag = false; | ||
} | ||
}; | ||
_createClass(Animation, [{ | ||
@@ -415,4 +359,4 @@ key: "pending", | ||
*/ | ||
// animation: InternalAnimation | null; | ||
/** | ||
@@ -435,3 +379,2 @@ * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/pending | ||
*/ | ||
}, { | ||
@@ -452,3 +395,2 @@ key: "ready", | ||
var _this2 = this; | ||
if (!this.readyPromise) { | ||
@@ -458,3 +400,2 @@ if (this.timeline.animationsWithPromises.indexOf(this) === -1) { | ||
} | ||
this.readyPromise = new Promise(function (resolve, reject) { | ||
@@ -464,3 +405,2 @@ _this2.resolveReadyPromise = function () { | ||
}; | ||
_this2.rejectReadyPromise = function () { | ||
@@ -470,3 +410,2 @@ reject(new Error()); | ||
}); | ||
if (!this.pending) { | ||
@@ -476,3 +415,2 @@ this.resolveReadyPromise(); | ||
} | ||
return this.readyPromise; | ||
@@ -495,3 +433,2 @@ } | ||
*/ | ||
}, { | ||
@@ -501,3 +438,2 @@ key: "finished", | ||
var _this3 = this; | ||
if (!this.finishedPromise) { | ||
@@ -507,3 +443,2 @@ if (this.timeline.animationsWithPromises.indexOf(this) === -1) { | ||
} | ||
this.finishedPromise = new Promise(function (resolve, reject) { | ||
@@ -513,3 +448,2 @@ _this3.resolveFinishedPromise = function () { | ||
}; | ||
_this3.rejectFinishedPromise = function () { | ||
@@ -519,3 +453,2 @@ reject(new Error()); | ||
}); | ||
if (this.playState === 'finished') { | ||
@@ -525,3 +458,2 @@ this.resolveFinishedPromise(); | ||
} | ||
return this.finishedPromise; | ||
@@ -532,3 +464,2 @@ } | ||
*/ | ||
}, { | ||
@@ -548,15 +479,10 @@ key: "currentTime", | ||
this.timeline.restart(); | ||
if (!this._paused && this._startTime !== null) { | ||
var _this$timeline; | ||
this._startTime = Number((_this$timeline = this.timeline) === null || _this$timeline === void 0 ? void 0 : _this$timeline.currentTime) - newTime / this.playbackRate; | ||
} | ||
this.currentTimePending = false; | ||
if (this._currentTime === newTime) { | ||
return; | ||
} | ||
if (this._idle) { | ||
@@ -566,3 +492,2 @@ this._idle = false; | ||
} | ||
this.tickCurrentTime(newTime, true); | ||
@@ -574,3 +499,2 @@ this.timeline.applyDirtiedAnimation(this); | ||
*/ | ||
}, { | ||
@@ -602,3 +526,2 @@ key: "startTime", | ||
} | ||
this.updatePromises(); | ||
@@ -608,3 +531,2 @@ var oldCurrentTime = this.currentTime; | ||
this.startTime = null; | ||
if (this.playState !== 'paused' && this.playState !== 'idle') { | ||
@@ -616,7 +538,5 @@ this._finishedFlag = false; | ||
} | ||
if (oldCurrentTime !== null) { | ||
this.currentTime = oldCurrentTime; | ||
} | ||
this.updatePromises(); | ||
@@ -640,3 +560,2 @@ } | ||
}]); | ||
return Animation; | ||
@@ -666,8 +585,8 @@ }(); | ||
return 3.0 * aA1; | ||
}; // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2. | ||
}; | ||
// Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2. | ||
var calcBezier = function calcBezier(aT, aA1, aA2) { | ||
return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT; | ||
}; // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2. | ||
}; | ||
// Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2. | ||
var getSlope = function getSlope(aT, aA1, aA2) { | ||
@@ -678,5 +597,4 @@ return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1); | ||
var currentX, | ||
currentT, | ||
i = 0; | ||
currentT, | ||
i = 0; | ||
do { | ||
@@ -687,3 +605,2 @@ currentT = aA + (aB - aA) / 2.0; | ||
} while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS); | ||
return currentT; | ||
@@ -698,3 +615,2 @@ }; | ||
} | ||
return aGuessT; | ||
@@ -706,10 +622,8 @@ }; | ||
return t; | ||
}; // Precompute samples table | ||
}; | ||
// Precompute samples table | ||
var sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize); | ||
for (var i = 0; i < kSplineTableSize; ++i) { | ||
sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2); | ||
} | ||
var getTForX = function getTForX(aX) { | ||
@@ -719,9 +633,7 @@ var intervalStart = 0.0; | ||
var lastSample = kSplineTableSize - 1; | ||
for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) { | ||
intervalStart += kSampleStepSize; | ||
} | ||
--currentSample; // Interpolate to provide an initial guess for t | ||
--currentSample; | ||
// Interpolate to provide an initial guess for t | ||
var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]); | ||
@@ -734,3 +646,2 @@ var guessForT = intervalStart + dist * kSampleStepSize; | ||
}; | ||
return function (t) { | ||
@@ -746,4 +657,4 @@ // Because JavaScript number are imprecise, we should guarantee the extremes are right. | ||
return "-" + letter.toLowerCase(); | ||
}); // Remove first dash | ||
}); | ||
// Remove first dash | ||
return str.charAt(0) === '-' ? str.substring(1) : str; | ||
@@ -754,44 +665,32 @@ }; | ||
*/ | ||
var Quad = function Quad(t) { | ||
return Math.pow(t, 2); | ||
}; | ||
var Cubic = function Cubic(t) { | ||
return Math.pow(t, 3); | ||
}; | ||
var Quart = function Quart(t) { | ||
return Math.pow(t, 4); | ||
}; | ||
var Quint = function Quint(t) { | ||
return Math.pow(t, 5); | ||
}; | ||
var Expo = function Expo(t) { | ||
return Math.pow(t, 6); | ||
}; | ||
var Sine = function Sine(t) { | ||
return 1 - Math.cos(t * Math.PI / 2); | ||
}; | ||
var Circ = function Circ(t) { | ||
return 1 - Math.sqrt(1 - t * t); | ||
}; | ||
var Back = function Back(t) { | ||
return t * t * (3 * t - 2); | ||
}; | ||
var Bounce = function Bounce(t) { | ||
var pow2, | ||
b = 4; | ||
b = 4; | ||
while (t < ((pow2 = Math.pow(2, --b)) - 1) / 11) {} | ||
return 1 / Math.pow(4, 3 - b) - 7.5625 * Math.pow((pow2 * 3 - 2) / 22 - t, 2); | ||
}; | ||
var Elastic = function Elastic(t, params) { | ||
@@ -801,8 +700,7 @@ if (params === void 0) { | ||
} | ||
var _params = params, | ||
_params$ = _params[0], | ||
amplitude = _params$ === void 0 ? 1 : _params$, | ||
_params$2 = _params[1], | ||
period = _params$2 === void 0 ? 0.5 : _params$2; | ||
_params$ = _params[0], | ||
amplitude = _params$ === void 0 ? 1 : _params$, | ||
_params$2 = _params[1], | ||
period = _params$2 === void 0 ? 0.5 : _params$2; | ||
var a = clamp(Number(amplitude), 1, 10); | ||
@@ -813,3 +711,2 @@ var p = clamp(Number(period), 0.1, 2); | ||
}; | ||
var Spring = function Spring(t, params, duration) { | ||
@@ -819,12 +716,11 @@ if (params === void 0) { | ||
} | ||
var _params2 = params, | ||
_params2$ = _params2[0], | ||
mass = _params2$ === void 0 ? 1 : _params2$, | ||
_params2$2 = _params2[1], | ||
stiffness = _params2$2 === void 0 ? 100 : _params2$2, | ||
_params2$3 = _params2[2], | ||
damping = _params2$3 === void 0 ? 10 : _params2$3, | ||
_params2$4 = _params2[3], | ||
velocity = _params2$4 === void 0 ? 0 : _params2$4; | ||
_params2$ = _params2[0], | ||
mass = _params2$ === void 0 ? 1 : _params2$, | ||
_params2$2 = _params2[1], | ||
stiffness = _params2$2 === void 0 ? 100 : _params2$2, | ||
_params2$3 = _params2[2], | ||
damping = _params2$3 === void 0 ? 10 : _params2$3, | ||
_params2$4 = _params2[3], | ||
velocity = _params2$4 === void 0 ? 0 : _params2$4; | ||
mass = clamp(mass, 0.1, 1000); | ||
@@ -840,3 +736,2 @@ stiffness = clamp(stiffness, 0.1, 1000); | ||
var progress = duration ? duration * t / 1000 : t; | ||
if (zeta < 1) { | ||
@@ -847,3 +742,2 @@ progress = Math.exp(-progress * zeta * w0) * (a * Math.cos(wd * progress) + b * Math.sin(wd * progress)); | ||
} | ||
if (t === 0 || t === 1) return t; | ||
@@ -856,3 +750,2 @@ return 1 - progress; | ||
// export const EasingDurationCache: Map<string | TypeEasingFunction, number> = new Map(); | ||
/** | ||
@@ -862,3 +755,2 @@ * The threshold for an infinite loop | ||
// const INTINITE_LOOP_LIMIT = 10000; | ||
/** Convert easing parameters to Array of numbers, e.g. "spring(2, 500)" to [2, 500] */ | ||
@@ -874,3 +766,2 @@ // export const parseEasingParameters = (str: string) => { | ||
// }; | ||
/** | ||
@@ -906,3 +797,2 @@ * The spring easing function will only look smooth at certain durations, with certain parameters. | ||
// }; | ||
/** | ||
@@ -912,4 +802,2 @@ These Easing Functions are based off of the Sozi Project's easing functions | ||
*/ | ||
var Steps = function Steps(t, params) { | ||
@@ -919,12 +807,10 @@ if (params === void 0) { | ||
} | ||
var _params3 = params, | ||
_params3$ = _params3[0], | ||
steps = _params3$ === void 0 ? 10 : _params3$, | ||
type = _params3[1]; | ||
_params3$ = _params3[0], | ||
steps = _params3$ === void 0 ? 10 : _params3$, | ||
type = _params3[1]; | ||
var trunc = type == 'start' ? Math.ceil : Math.floor; | ||
return trunc(clamp(t, 0, 1) * steps) / steps; | ||
}; // @ts-ignore | ||
}; | ||
// @ts-ignore | ||
var Bezier = function Bezier(t, params) { | ||
@@ -934,16 +820,12 @@ if (params === void 0) { | ||
} | ||
var _params4 = params, | ||
mX1 = _params4[0], | ||
mY1 = _params4[1], | ||
mX2 = _params4[2], | ||
mY2 = _params4[3]; | ||
mX1 = _params4[0], | ||
mY1 = _params4[1], | ||
mX2 = _params4[2], | ||
mY2 = _params4[3]; | ||
return bezier(mX1, mY1, mX2, mY2)(t); | ||
}; | ||
/** The default `ease-in` easing function */ | ||
var easein = bezier(0.42, 0.0, 1.0, 1.0); | ||
/** Converts easing functions to their `out`counter parts */ | ||
var EaseOut = function EaseOut(ease) { | ||
@@ -954,3 +836,2 @@ return function (t, params, duration) { | ||
} | ||
return 1 - ease(1 - t, params, duration); | ||
@@ -960,4 +841,2 @@ }; | ||
/** Converts easing functions to their `in-out` counter parts */ | ||
var EaseInOut = function EaseInOut(ease) { | ||
@@ -968,3 +847,2 @@ return function (t, params, duration) { | ||
} | ||
return t < 0.5 ? ease(t * 2, params, duration) / 2 : 1 - ease(t * -2 + 2, params, duration) / 2; | ||
@@ -974,4 +852,2 @@ }; | ||
/** Converts easing functions to their `out-in` counter parts */ | ||
var EaseOutIn = function EaseOutIn(ease) { | ||
@@ -982,7 +858,5 @@ return function (t, params, duration) { | ||
} | ||
return t < 0.5 ? (1 - ease(1 - t * 2, params, duration)) / 2 : (ease(t * 2 - 1, params, duration) + 1) / 2; | ||
}; | ||
}; | ||
var EasingFunctions = { | ||
@@ -1056,3 +930,2 @@ steps: Steps, | ||
*/ | ||
var complexEasingSyntax = function complexEasingSyntax(ease) { | ||
@@ -1064,7 +937,6 @@ return convertToDash(ease).replace(/^ease-/, '') // Remove the "ease-" keyword | ||
/** 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. */ | ||
var getEasingFunction = function getEasingFunction(ease) { | ||
return EasingFunctions[complexEasingSyntax(ease)] || EasingFunctions.linear; | ||
}; // /** | ||
}; | ||
// /** | ||
// * Allows you to register new easing functions | ||
@@ -1090,3 +962,2 @@ // */ | ||
var End = 0; | ||
function step(count, pos) { | ||
@@ -1097,3 +968,2 @@ return function (x) { | ||
} | ||
var stepSize = 1 / count; | ||
@@ -1104,3 +974,2 @@ x += pos * stepSize; | ||
} | ||
var numberString = '\\s*(-?\\d+\\.?\\d*|-?\\.\\d+)\\s*'; | ||
@@ -1112,3 +981,2 @@ var cubicBezierRe = new RegExp('cubic-bezier\\(' + numberString + ',' + numberString + ',' + numberString + ',' + numberString + '\\)'); | ||
var cubicData = cubicBezierRe.exec(normalizedEasing); | ||
if (cubicData) { | ||
@@ -1118,11 +986,7 @@ // @ts-ignore | ||
} | ||
var step1Data = step1Re.exec(normalizedEasing); | ||
if (step1Data) { | ||
return step(Number(step1Data[1]), End); | ||
} | ||
var step2Data = step2Re.exec(normalizedEasing); | ||
if (step2Data) { | ||
@@ -1136,3 +1000,2 @@ // @ts-ignore | ||
} | ||
return getEasingFunction(normalizedEasing); | ||
@@ -1144,18 +1007,14 @@ } | ||
} | ||
function repeatedDuration(timing) { | ||
var _timing$iterations; | ||
// https://drafts.csswg.org/web-animations/#calculating-the-active-duration | ||
if (timing.duration === 0 || timing.iterations === 0) { | ||
return 0; | ||
} // @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/duration#value | ||
} | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/duration#value | ||
// if (timing.duration === 'auto') { | ||
// timing.duration = 0; | ||
// } | ||
return (timing.duration === 'auto' ? 0 : Number(timing.duration)) * ((_timing$iterations = timing.iterations) !== null && _timing$iterations !== void 0 ? _timing$iterations : 1); | ||
} | ||
var PhaseNone = 0; | ||
@@ -1165,3 +1024,2 @@ var PhaseBefore = 1; | ||
var PhaseActive = 3; | ||
function calculatePhase(activeDuration, localTime, timing) { | ||
@@ -1172,16 +1030,11 @@ // https://drafts.csswg.org/web-animations/#animation-effect-phases-and-states | ||
} | ||
var endTime = timing.endTime; | ||
if (localTime < Math.min(timing.delay, endTime)) { | ||
return PhaseBefore; | ||
} | ||
if (localTime >= Math.min(timing.delay + activeDuration + timing.endDelay, endTime)) { | ||
return PhaseAfter; | ||
} | ||
return PhaseActive; | ||
} | ||
function calculateActiveTime(activeDuration, fillMode, localTime, phase, delay) { | ||
@@ -1193,10 +1046,7 @@ // https://drafts.csswg.org/web-animations/#calculating-the-active-time | ||
return null; | ||
case PhaseActive: | ||
return localTime - delay; | ||
case PhaseAfter: | ||
if (fillMode === 'forwards' || fillMode === 'both') return activeDuration; | ||
return null; | ||
case PhaseNone: | ||
@@ -1206,7 +1056,5 @@ return null; | ||
} | ||
function calculateOverallProgress(iterationDuration, phase, iterations, activeTime, iterationStart) { | ||
// https://drafts.csswg.org/web-animations/#calculating-the-overall-progress | ||
var overallProgress = iterationStart; | ||
if (iterationDuration === 0) { | ||
@@ -1219,17 +1067,12 @@ if (phase !== PhaseBefore) { | ||
} | ||
return overallProgress; | ||
} | ||
function calculateSimpleIterationProgress(overallProgress, iterationStart, phase, iterations, activeTime, iterationDuration) { | ||
// https://drafts.csswg.org/web-animations/#calculating-the-simple-iteration-progress | ||
var simpleIterationProgress = overallProgress === Infinity ? iterationStart % 1 : overallProgress % 1; | ||
if (simpleIterationProgress === 0 && phase === PhaseAfter && iterations !== 0 && (activeTime !== 0 || iterationDuration === 0)) { | ||
simpleIterationProgress = 1; | ||
} | ||
return simpleIterationProgress; | ||
} | ||
function calculateCurrentIteration(phase, iterations, simpleIterationProgress, overallProgress) { | ||
@@ -1240,23 +1083,16 @@ // https://drafts.csswg.org/web-animations/#calculating-the-current-iteration | ||
} | ||
if (simpleIterationProgress === 1) { | ||
return Math.floor(overallProgress) - 1; | ||
} | ||
return Math.floor(overallProgress); | ||
} | ||
function calculateDirectedProgress(playbackDirection, currentIteration, simpleIterationProgress) { | ||
// https://drafts.csswg.org/web-animations/#calculating-the-directed-progress | ||
var currentDirection = playbackDirection; | ||
if (playbackDirection !== 'normal' && playbackDirection !== 'reverse') { | ||
var d = currentIteration; | ||
if (playbackDirection === 'alternate-reverse') { | ||
d += 1; | ||
} | ||
currentDirection = 'normal'; | ||
if (d !== Infinity && d % 2 !== 0) { | ||
@@ -1266,10 +1102,7 @@ currentDirection = 'reverse'; | ||
} | ||
if (currentDirection === 'normal') { | ||
return simpleIterationProgress; | ||
} | ||
return 1 - simpleIterationProgress; | ||
} | ||
function calculateIterationProgress(activeDuration, localTime, timing) { | ||
@@ -1285,5 +1118,5 @@ var phase = calculatePhase(activeDuration, localTime, timing); | ||
timing.currentIteration = currentIteration; | ||
timing.progress = directedProgress; // https://drafts.csswg.org/web-animations/#calculating-the-transformed-progress | ||
timing.progress = directedProgress; | ||
// https://drafts.csswg.org/web-animations/#calculating-the-transformed-progress | ||
// https://drafts.csswg.org/web-animations/#calculating-the-iteration-progress | ||
return timing.easingFunction(directedProgress); | ||
@@ -1302,4 +1135,4 @@ } | ||
var localDuration = interpolation.endOffset - interpolation.startOffset; | ||
var scaledLocalTime = localDuration === 0 ? 0 : interpolation.easingFunction(offsetFraction / localDuration); // apply updated attribute | ||
var scaledLocalTime = localDuration === 0 ? 0 : interpolation.easingFunction(offsetFraction / localDuration); | ||
// apply updated attribute | ||
target.style[interpolation.property] = interpolation.interpolation(scaledLocalTime); | ||
@@ -1317,10 +1150,7 @@ }); | ||
} | ||
function isNotReservedWord(member) { | ||
return member !== 'offset' && member !== 'easing' && member !== 'composite' && member !== 'computedOffset'; | ||
} | ||
function makePropertySpecificKeyframeGroups(keyframes, timing) { | ||
var propertySpecificKeyframeGroups = {}; | ||
for (var i = 0; i < keyframes.length; i++) { | ||
@@ -1341,12 +1171,8 @@ for (var member in keyframes[i]) { | ||
} | ||
return propertySpecificKeyframeGroups; | ||
} | ||
function makeInterpolations(propertySpecificKeyframeGroups, target) { | ||
var interpolations = []; | ||
for (var groupName in propertySpecificKeyframeGroups) { | ||
var keyframes = propertySpecificKeyframeGroups[groupName]; | ||
for (var i = 0; i < keyframes.length - 1; i++) { | ||
@@ -1359,6 +1185,4 @@ var startIndex = i; | ||
var applyTo = endOffset; | ||
if (i === 0) { | ||
applyFrom = -Infinity; | ||
if (endOffset === 0) { | ||
@@ -1368,6 +1192,4 @@ endIndex = startIndex; | ||
} | ||
if (i === keyframes.length - 2) { | ||
applyTo = Infinity; | ||
if (startOffset === 1) { | ||
@@ -1377,3 +1199,2 @@ startIndex = endIndex; | ||
} | ||
interpolations.push({ | ||
@@ -1390,3 +1211,2 @@ applyFrom: applyFrom, | ||
} | ||
interpolations.sort(function (leftInterpolation, rightInterpolation) { | ||
@@ -1397,4 +1217,4 @@ return leftInterpolation.startOffset - rightInterpolation.startOffset; | ||
} | ||
var InterpolationFactory = function InterpolationFactory(from, to, // eslint-disable-next-line @typescript-eslint/ban-types | ||
var InterpolationFactory = function InterpolationFactory(from, to, | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
convertToString) { | ||
@@ -1405,9 +1225,6 @@ return function (f) { | ||
}; | ||
function propertyInterpolation(property, left, right, target) { | ||
var metadata = propertyMetadataCache[property]; | ||
if (metadata && metadata.syntax && metadata.int) { | ||
var propertyHandler = runtime.styleValueRegistry.getPropertySyntax(metadata.syntax); | ||
if (propertyHandler) { | ||
@@ -1417,3 +1234,4 @@ var computedLeft = runtime.styleValueRegistry.parseProperty(property, left, target); | ||
var usedLeft = runtime.styleValueRegistry.computeProperty(property, computedLeft, target); | ||
var usedRight = runtime.styleValueRegistry.computeProperty(property, computedRight, target); // use defaultValue | ||
var usedRight = runtime.styleValueRegistry.computeProperty(property, computedRight, target); | ||
// use defaultValue | ||
// const parsedDefaultLeft = parseDefaultValue(metadata, target, property, left); | ||
@@ -1444,5 +1262,3 @@ // const parsedDefaultRight = parseDefaultValue(metadata, target, property, right); | ||
// merger [left, right, n2string()] | ||
var interpolationArgs = propertyHandler.mixer(usedLeft, usedRight, target); | ||
if (interpolationArgs) { | ||
@@ -1458,5 +1274,4 @@ // @ts-ignore | ||
} | ||
} // eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
return InterpolationFactory(false, true, function (bool) { | ||
@@ -1469,4 +1284,2 @@ return bool ? right : left; | ||
*/ | ||
function interpolate(from, to, f) { | ||
@@ -1476,3 +1289,2 @@ if (typeof from === 'number' && typeof to === 'number') { | ||
} | ||
if (typeof from === 'boolean' && typeof to === 'boolean' || typeof from === 'string' && typeof to === 'string' // skip string, eg. path ['M', 10, 10] | ||
@@ -1482,3 +1294,2 @@ ) { | ||
} | ||
if (Array.isArray(from) && Array.isArray(to)) { | ||
@@ -1488,11 +1299,8 @@ // interpolate arrays/matrix | ||
var r = []; | ||
for (var i = 0; i < from.length; i++) { | ||
r.push(interpolate(from[i], to[i], f)); | ||
} | ||
return r; | ||
} | ||
} | ||
throw new Error('Mismatched interpolation arguments ' + from + ':' + to); | ||
@@ -1504,3 +1312,2 @@ } | ||
*/ | ||
var AnimationEffectTiming = /*#__PURE__*/function () { | ||
@@ -1525,3 +1332,2 @@ function AnimationEffectTiming() { | ||
} | ||
_createClass(AnimationEffectTiming, [{ | ||
@@ -1539,5 +1345,3 @@ key: "easing", | ||
*/ | ||
}]); | ||
return AnimationEffectTiming; | ||
@@ -1560,6 +1364,4 @@ }(); | ||
*/ | ||
function convertToArrayForm(effectInput) { | ||
var normalizedEffectInput = []; | ||
for (var property in effectInput) { | ||
@@ -1569,21 +1371,15 @@ // skip reserved props | ||
continue; | ||
} // @ts-ignore | ||
} | ||
// @ts-ignore | ||
var values = effectInput[property]; | ||
if (!Array.isArray(values)) { | ||
values = [values]; | ||
} | ||
var numKeyframes = values.length; | ||
for (var i = 0; i < numKeyframes; i++) { | ||
if (!normalizedEffectInput[i]) { | ||
var keyframe = {}; | ||
if ('offset' in effectInput) { | ||
keyframe.offset = Number(effectInput.offset); | ||
} | ||
if ('easing' in effectInput) { | ||
@@ -1593,3 +1389,2 @@ // @ts-ignore | ||
} | ||
if ('composite' in effectInput) { | ||
@@ -1599,6 +1394,4 @@ // @ts-ignore | ||
} | ||
normalizedEffectInput[i] = keyframe; | ||
} | ||
if (values[i] !== undefined && values[i] !== null) { | ||
@@ -1609,3 +1402,2 @@ normalizedEffectInput[i][property] = values[i]; | ||
} | ||
normalizedEffectInput.sort(function (a, b) { | ||
@@ -1616,3 +1408,2 @@ return (a.computedOffset || 0) - (b.computedOffset || 0); | ||
} | ||
function normalizeKeyframes(effectInput, timing) { | ||
@@ -1622,10 +1413,7 @@ if (effectInput === null) { | ||
} | ||
if (!Array.isArray(effectInput)) { | ||
effectInput = convertToArrayForm(effectInput); | ||
} | ||
var keyframes = effectInput.map(function (originalKeyframe) { | ||
var keyframe = {}; | ||
if (timing === null || timing === void 0 ? void 0 : timing.composite) { | ||
@@ -1636,6 +1424,4 @@ // This will be auto if the composite operation specified on the effect is being used. | ||
} | ||
for (var member in originalKeyframe) { | ||
var memberValue = originalKeyframe[member]; | ||
if (member === 'offset') { | ||
@@ -1654,12 +1440,9 @@ if (memberValue !== null) { | ||
} | ||
} else ; // assign to keyframe, no need to parse shorthand value | ||
} else ; | ||
// assign to keyframe, no need to parse shorthand value | ||
keyframe[member] = memberValue; | ||
} | ||
if (keyframe.offset === undefined) { | ||
keyframe.offset = null; | ||
} | ||
if (keyframe.easing === undefined) { | ||
@@ -1669,7 +1452,5 @@ // override with timing.easing | ||
} | ||
if (keyframe.composite === undefined) { | ||
keyframe.composite = 'auto'; | ||
} | ||
return keyframe; | ||
@@ -1679,6 +1460,4 @@ }); | ||
var previousOffset = -Infinity; | ||
for (var i = 0; i < keyframes.length; i++) { | ||
var offset = keyframes[i].offset; | ||
if (!isNil(offset)) { | ||
@@ -1688,3 +1467,2 @@ if (offset < previousOffset) { | ||
} | ||
previousOffset = offset; | ||
@@ -1695,25 +1473,17 @@ } else { | ||
} | ||
keyframes = keyframes.filter(function (keyframe) { | ||
return Number(keyframe.offset) >= 0 && Number(keyframe.offset) <= 1; | ||
}); | ||
function spaceKeyframes() { | ||
var _keyframes$offset; | ||
var length = keyframes.length; | ||
keyframes[length - 1].computedOffset = Number((_keyframes$offset = keyframes[length - 1].offset) !== null && _keyframes$offset !== void 0 ? _keyframes$offset : 1); | ||
if (length > 1) { | ||
var _keyframes$0$offset; | ||
keyframes[0].computedOffset = Number((_keyframes$0$offset = keyframes[0].offset) !== null && _keyframes$0$offset !== void 0 ? _keyframes$0$offset : 0); | ||
} | ||
var previousIndex = 0; | ||
var previousOffset = Number(keyframes[0].computedOffset); | ||
for (var _i = 1; _i < length; _i++) { | ||
var _offset = keyframes[_i].computedOffset; | ||
if (!isNil(_offset) && !isNil(previousOffset)) { | ||
@@ -1723,3 +1493,2 @@ for (var j = 1; j < _i - previousIndex; j++) { | ||
} | ||
previousIndex = _i; | ||
@@ -1730,3 +1499,2 @@ previousOffset = Number(_offset); | ||
} | ||
if (!everyFrameHasOffset) spaceKeyframes(); | ||
@@ -1740,3 +1508,2 @@ return keyframes; | ||
var timing = new AnimationEffectTiming(); | ||
if (forGroup) { | ||
@@ -1746,3 +1513,2 @@ timing.fill = 'both'; | ||
} | ||
if (typeof timingInput === 'number' && !isNaN(timingInput)) { | ||
@@ -1758,12 +1524,9 @@ timing.duration = timingInput; | ||
} | ||
if (property === 'fill' && fills.indexOf(timingInput[property]) === -1) { | ||
return; | ||
} | ||
if (property === 'direction' && directions.indexOf(timingInput[property]) === -1) { | ||
return; | ||
} // @ts-ignore | ||
} | ||
// @ts-ignore | ||
timing[property] = timingInput[property]; | ||
@@ -1773,3 +1536,2 @@ } | ||
} | ||
return timing; | ||
@@ -1779,3 +1541,2 @@ } | ||
var _timingInput; | ||
timingInput = numericTimingToObject((_timingInput = timingInput) !== null && _timingInput !== void 0 ? _timingInput : { | ||
@@ -1798,3 +1559,2 @@ duration: 'auto' | ||
} | ||
return timingInput; | ||
@@ -1815,8 +1575,7 @@ } | ||
*/ | ||
var KeyframeEffect = /*#__PURE__*/function () { | ||
// pseudoElement: string | null; | ||
function KeyframeEffect(target, effectInput, timingInput) { | ||
var _this = this; | ||
this.composite = 'replace'; | ||
@@ -1850,3 +1609,2 @@ this.iterationComposite = 'replace'; | ||
} | ||
return target.currentIteration || 0; | ||
@@ -1857,6 +1615,4 @@ } else if (prop === 'progress') { | ||
} | ||
return target.progress || 0; | ||
} | ||
return target[prop]; | ||
@@ -1869,9 +1625,6 @@ }, | ||
} | ||
var _proto = KeyframeEffect.prototype; | ||
_proto.applyInterpolations = function applyInterpolations() { | ||
this.interpolations(this.target, Number(this.timeFraction)); | ||
}; | ||
_proto.update = function update(localTime) { | ||
@@ -1881,11 +1634,8 @@ if (localTime === null) { | ||
} | ||
this.timeFraction = calculateIterationProgress(this.timing.activeDuration, localTime, this.timing); | ||
return this.timeFraction !== null; | ||
}; | ||
_proto.getKeyframes = function getKeyframes() { | ||
return this.normalizedKeyframes; | ||
}; | ||
_proto.setKeyframes = function setKeyframes(keyframes) { | ||
@@ -1896,5 +1646,3 @@ this.normalizedKeyframes = normalizeKeyframes(keyframes); | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEffect/getComputedTiming | ||
*/ | ||
; | ||
*/; | ||
_proto.getComputedTiming = function getComputedTiming() { | ||
@@ -1905,5 +1653,3 @@ return this.computedTiming; | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEffect/getTiming | ||
*/ | ||
; | ||
*/; | ||
_proto.getTiming = function getTiming() { | ||
@@ -1914,8 +1660,5 @@ return this.timing; | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEffect/updateTiming | ||
*/ | ||
; | ||
*/; | ||
_proto.updateTiming = function updateTiming(timing) { | ||
var _this2 = this; | ||
Object.keys(timing || {}).forEach(function (name) { | ||
@@ -1925,3 +1668,2 @@ _this2.timing = timing[name]; | ||
}; | ||
return KeyframeEffect; | ||
@@ -1936,3 +1678,2 @@ }(); | ||
*/ | ||
var AnimationTimeline = /*#__PURE__*/function () { | ||
@@ -1942,5 +1683,5 @@ /** | ||
*/ | ||
function AnimationTimeline(document) { | ||
var _this = this; | ||
this.document = void 0; | ||
@@ -1958,8 +1699,5 @@ this.animations = []; | ||
this.frameId = void 0; | ||
this.webAnimationsNextTick = function (t) { | ||
_this.currentTime = t; | ||
_this.discardAnimations(); | ||
if (_this.animations.length === 0) { | ||
@@ -1971,3 +1709,2 @@ _this.timelineTicking = false; | ||
}; | ||
this.processRafCallbacks = function (t) { | ||
@@ -1977,5 +1714,3 @@ var processing = _this.rafCallbacks; | ||
if (t < Number(_this.currentTime)) t = Number(_this.currentTime); | ||
_this.animations.sort(compareAnimations); | ||
_this.animations = _this.tick(t, true, _this.animations)[0]; | ||
@@ -1985,11 +1720,7 @@ processing.forEach(function (entry) { | ||
}); | ||
_this.applyPendingEffects(); | ||
}; | ||
this.document = document; | ||
} | ||
var _proto = AnimationTimeline.prototype; | ||
_proto.getAnimations = function getAnimations() { | ||
@@ -1999,7 +1730,5 @@ this.discardAnimations(); | ||
}; | ||
_proto.isTicking = function isTicking() { | ||
return this.inTick; | ||
}; | ||
_proto.play = function play(target, keyframes, options) { | ||
@@ -2014,3 +1743,4 @@ var effect = new KeyframeEffect(target, keyframes, options); | ||
return animation; | ||
} // RAF is supposed to be the last script to occur before frame rendering but not | ||
} | ||
// RAF is supposed to be the last script to occur before frame rendering but not | ||
// all browsers behave like this. This function is for synchonously updating an | ||
@@ -2020,19 +1750,15 @@ // animation's effects whenever its state is mutated by script to work around | ||
; | ||
_proto.applyDirtiedAnimation = function applyDirtiedAnimation(animation) { | ||
var _this2 = this; | ||
if (this.inTick) { | ||
return; | ||
} // update active animations in displayobject | ||
} | ||
// update active animations in displayobject | ||
animation.markTarget(); | ||
var animations = animation.targetAnimations(); | ||
animations.sort(compareAnimations); // clear inactive animations | ||
animations.sort(compareAnimations); | ||
// clear inactive animations | ||
var inactiveAnimations = this.tick(Number(this.currentTime), false, animations.slice())[1]; | ||
inactiveAnimations.forEach(function (animation) { | ||
var index = _this2.animations.indexOf(animation); | ||
if (index !== -1) { | ||
@@ -2044,3 +1770,2 @@ _this2.animations.splice(index, 1); | ||
}; | ||
_proto.restart = function restart() { | ||
@@ -2052,10 +1777,7 @@ if (!this.ticking) { | ||
} | ||
return this.hasRestartedThisFrame; | ||
}; | ||
_proto.destroy = function destroy() { | ||
this.document.defaultView.cancelAnimationFrame(this.frameId); | ||
}; | ||
_proto.applyPendingEffects = function applyPendingEffects() { | ||
@@ -2067,3 +1789,2 @@ this.pendingEffects.forEach(function (effect) { | ||
}; | ||
_proto.updateAnimationsPromises = function updateAnimationsPromises() { | ||
@@ -2074,3 +1795,2 @@ this.animationsWithPromises = this.animationsWithPromises.filter(function (animation) { | ||
}; | ||
_proto.discardAnimations = function discardAnimations() { | ||
@@ -2082,3 +1802,2 @@ this.updateAnimationsPromises(); | ||
}; | ||
_proto.restartWebAnimationsNextTick = function restartWebAnimationsNextTick() { | ||
@@ -2090,31 +1809,22 @@ if (!this.timelineTicking) { | ||
}; | ||
_proto.rAF = function rAF(f) { | ||
var id = this.rafId++; | ||
if (this.rafCallbacks.length === 0) { | ||
this.frameId = this.document.defaultView.requestAnimationFrame(this.processRafCallbacks); | ||
} | ||
this.rafCallbacks.push([id, f]); | ||
return id; | ||
}; | ||
_proto.requestAnimationFrame = function requestAnimationFrame(f) { | ||
var _this3 = this; | ||
return this.rAF(function (x) { | ||
_this3.updateAnimationsPromises(); | ||
f(x); | ||
_this3.updateAnimationsPromises(); | ||
}); | ||
}; | ||
_proto.tick = function tick(t, isAnimationFrame, updatingAnimations) { | ||
var _this4 = this, | ||
_this$pendingEffects, | ||
_this$pendingEffects2; | ||
_this$pendingEffects, | ||
_this$pendingEffects2; | ||
this.inTick = true; | ||
@@ -2130,3 +1840,2 @@ this.hasRestartedThisFrame = false; | ||
animation.tick(t, isAnimationFrame); | ||
if (!animation._inEffect) { | ||
@@ -2139,7 +1848,5 @@ newPendingClears.push(animation.effect); | ||
} | ||
if (animation._needsTick) _this4.ticking = true; | ||
var alive = animation._inEffect || animation._needsTick; | ||
animation._inTimeline = alive; | ||
if (alive) { | ||
@@ -2151,7 +1858,4 @@ activeAnimations.push(animation); | ||
}); | ||
(_this$pendingEffects = this.pendingEffects).push.apply(_this$pendingEffects, newPendingClears); | ||
(_this$pendingEffects2 = this.pendingEffects).push.apply(_this$pendingEffects2, newPendingEffects); | ||
if (this.ticking) this.requestAnimationFrame(function () {}); | ||
@@ -2161,3 +1865,2 @@ this.inTick = false; | ||
}; | ||
return AnimationTimeline; | ||
@@ -2164,0 +1867,0 @@ }(); |
@@ -17,3 +17,2 @@ 'use strict'; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
@@ -27,10 +26,7 @@ if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
@@ -47,9 +43,6 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
*/ | ||
var AnimationEvent = /*#__PURE__*/function (_FederatedEvent) { | ||
_inheritsLoose(AnimationEvent, _FederatedEvent); | ||
function AnimationEvent(manager, target, currentTime, timelineTime) { | ||
var _this; | ||
_this = _FederatedEvent.call(this, manager) || this; | ||
@@ -59,8 +52,8 @@ _this.currentTime = void 0; | ||
_this.currentTime = currentTime; | ||
_this.timelineTime = timelineTime; // @ts-ignore | ||
_this.timelineTime = timelineTime; | ||
// @ts-ignore | ||
_this.target = target; | ||
_this.type = 'finish'; | ||
_this.bubbles = false; // @ts-ignore | ||
_this.bubbles = false; | ||
// @ts-ignore | ||
_this.currentTarget = target; | ||
@@ -74,3 +67,2 @@ _this.defaultPrevented = false; | ||
} | ||
return AnimationEvent; | ||
@@ -83,7 +75,5 @@ }(gLite.FederatedEvent); | ||
*/ | ||
var Animation = /*#__PURE__*/function () { | ||
function Animation(effect, timeline) { | ||
var _this$effect; | ||
this.effect = void 0; | ||
@@ -129,10 +119,6 @@ this.timeline = void 0; | ||
*/ | ||
var _proto = Animation.prototype; | ||
_proto.updatePromises = function updatePromises() { | ||
var oldPlayState = this.oldPlayState; | ||
var newPlayState = this.pending ? 'pending' : this.playState; | ||
if (this.readyPromise && newPlayState !== oldPlayState) { | ||
@@ -148,3 +134,2 @@ if (newPlayState === 'idle') { | ||
} | ||
if (this.finishedPromise && newPlayState !== oldPlayState) { | ||
@@ -160,11 +145,8 @@ if (newPlayState === 'idle') { | ||
} | ||
this.oldPlayState = newPlayState; | ||
return this.readyPromise || this.finishedPromise; | ||
}; | ||
_proto.play = function play() { | ||
this.updatePromises(); | ||
this._paused = false; | ||
if (this._isFinished || this._idle) { | ||
@@ -174,3 +156,2 @@ this.rewind(); | ||
} | ||
this._finishedFlag = false; | ||
@@ -180,17 +161,12 @@ this._idle = false; | ||
this.timeline.applyDirtiedAnimation(this); | ||
if (this.timeline.animations.indexOf(this) === -1) { | ||
this.timeline.animations.push(this); | ||
} | ||
this.updatePromises(); | ||
}; | ||
_proto.pause = function pause() { | ||
this.updatePromises(); | ||
if (this.currentTime) { | ||
this._holdTime = this.currentTime; | ||
} | ||
if (!this._isFinished && !this._paused && !this._idle) { | ||
@@ -202,3 +178,2 @@ this.currentTimePending = true; | ||
} | ||
this._startTime = null; | ||
@@ -208,3 +183,2 @@ this._paused = true; | ||
}; | ||
_proto.finish = function finish() { | ||
@@ -219,3 +193,2 @@ this.updatePromises(); | ||
}; | ||
_proto.cancel = function cancel() { | ||
@@ -230,9 +203,8 @@ this.updatePromises(); | ||
this._startTime = null; | ||
this.effect.update(null); // effects are invalid after cancellation as the animation state | ||
this.effect.update(null); | ||
// effects are invalid after cancellation as the animation state | ||
// needs to un-apply. | ||
this.timeline.applyDirtiedAnimation(this); | ||
this.updatePromises(); | ||
}; | ||
_proto.reverse = function reverse() { | ||
@@ -243,7 +215,5 @@ this.updatePromises(); | ||
this.play(); | ||
if (oldCurrentTime !== null) { | ||
this.currentTime = oldCurrentTime; | ||
} | ||
this.updatePromises(); | ||
@@ -253,19 +223,13 @@ } | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/updatePlaybackRate | ||
*/ | ||
; | ||
*/; | ||
_proto.updatePlaybackRate = function updatePlaybackRate(playbackRate) { | ||
this.playbackRate = playbackRate; | ||
}; | ||
_proto.targetAnimations = function targetAnimations() { | ||
var _this$effect2; | ||
var target = (_this$effect2 = this.effect) === null || _this$effect2 === void 0 ? void 0 : _this$effect2.target; | ||
return target.getAnimations(); | ||
}; | ||
_proto.markTarget = function markTarget() { | ||
var animations = this.targetAnimations(); | ||
if (animations.indexOf(this) === -1) { | ||
@@ -275,7 +239,5 @@ animations.push(this); | ||
}; | ||
_proto.unmarkTarget = function unmarkTarget() { | ||
var animations = this.targetAnimations(); | ||
var index = animations.indexOf(this); | ||
if (index !== -1) { | ||
@@ -285,3 +247,2 @@ animations.splice(index, 1); | ||
}; | ||
_proto.tick = function tick(timelineTime, isAnimationFrame) { | ||
@@ -297,3 +258,2 @@ if (!this._idle && !this._paused) { | ||
} | ||
if (isAnimationFrame) { | ||
@@ -304,3 +264,2 @@ this.currentTimePending = false; | ||
}; | ||
_proto.rewind = function rewind() { | ||
@@ -315,22 +274,20 @@ if (this.playbackRate >= 0) { | ||
}; | ||
_proto.persist = function persist() { | ||
throw new Error(gLite.ERROR_MSG_METHOD_NOT_IMPLEMENTED); | ||
} // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
; | ||
_proto.addEventListener = function addEventListener(type, listener, options) { | ||
throw new Error(gLite.ERROR_MSG_METHOD_NOT_IMPLEMENTED); | ||
} // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
; | ||
_proto.removeEventListener = function removeEventListener(type, listener, options) { | ||
throw new Error(gLite.ERROR_MSG_METHOD_NOT_IMPLEMENTED); | ||
} // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
; | ||
_proto.dispatchEvent = function dispatchEvent(event) { | ||
throw new Error(gLite.ERROR_MSG_METHOD_NOT_IMPLEMENTED); | ||
}; | ||
// replaceState: AnimationReplaceState; | ||
@@ -340,3 +297,2 @@ _proto.commitStyles = function commitStyles() { | ||
}; | ||
_proto.ensureAlive = function ensureAlive() { | ||
@@ -348,10 +304,7 @@ // If an animation is playing backwards and is not fill backwards/both | ||
var _this$effect3; | ||
this._inEffect = !!((_this$effect3 = this.effect) === null || _this$effect3 === void 0 ? void 0 : _this$effect3.update(-1)); | ||
} else { | ||
var _this$effect4; | ||
this._inEffect = !!((_this$effect4 = this.effect) === null || _this$effect4 === void 0 ? void 0 : _this$effect4.update(this.currentTime)); | ||
} | ||
if (!this._inTimeline && (this._inEffect || !this._finishedFlag)) { | ||
@@ -362,18 +315,13 @@ this._inTimeline = true; | ||
}; | ||
_proto.tickCurrentTime = function tickCurrentTime(newTime, ignoreLimit) { | ||
if (newTime !== this._currentTime) { | ||
this._currentTime = newTime; | ||
if (this._isFinished && !ignoreLimit) { | ||
this._currentTime = this._playbackRate > 0 ? this._totalDuration : 0; | ||
} | ||
this.ensureAlive(); | ||
} | ||
}; | ||
_proto.fireEvents = function fireEvents(baseTime) { | ||
var _this = this; | ||
if (this._isFinished) { | ||
@@ -389,3 +337,2 @@ if (!this._finishedFlag) { | ||
} | ||
this._finishedFlag = true; | ||
@@ -396,10 +343,7 @@ } | ||
var _event = new AnimationEvent(null, this, this.currentTime, baseTime); | ||
this.onframe(_event); | ||
} | ||
this._finishedFlag = false; | ||
} | ||
}; | ||
_createClass(Animation, [{ | ||
@@ -419,4 +363,4 @@ key: "pending", | ||
*/ | ||
// animation: InternalAnimation | null; | ||
/** | ||
@@ -439,3 +383,2 @@ * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/pending | ||
*/ | ||
}, { | ||
@@ -456,3 +399,2 @@ key: "ready", | ||
var _this2 = this; | ||
if (!this.readyPromise) { | ||
@@ -462,3 +404,2 @@ if (this.timeline.animationsWithPromises.indexOf(this) === -1) { | ||
} | ||
this.readyPromise = new Promise(function (resolve, reject) { | ||
@@ -468,3 +409,2 @@ _this2.resolveReadyPromise = function () { | ||
}; | ||
_this2.rejectReadyPromise = function () { | ||
@@ -474,3 +414,2 @@ reject(new Error()); | ||
}); | ||
if (!this.pending) { | ||
@@ -480,3 +419,2 @@ this.resolveReadyPromise(); | ||
} | ||
return this.readyPromise; | ||
@@ -499,3 +437,2 @@ } | ||
*/ | ||
}, { | ||
@@ -505,3 +442,2 @@ key: "finished", | ||
var _this3 = this; | ||
if (!this.finishedPromise) { | ||
@@ -511,3 +447,2 @@ if (this.timeline.animationsWithPromises.indexOf(this) === -1) { | ||
} | ||
this.finishedPromise = new Promise(function (resolve, reject) { | ||
@@ -517,3 +452,2 @@ _this3.resolveFinishedPromise = function () { | ||
}; | ||
_this3.rejectFinishedPromise = function () { | ||
@@ -523,3 +457,2 @@ reject(new Error()); | ||
}); | ||
if (this.playState === 'finished') { | ||
@@ -529,3 +462,2 @@ this.resolveFinishedPromise(); | ||
} | ||
return this.finishedPromise; | ||
@@ -536,3 +468,2 @@ } | ||
*/ | ||
}, { | ||
@@ -552,15 +483,10 @@ key: "currentTime", | ||
this.timeline.restart(); | ||
if (!this._paused && this._startTime !== null) { | ||
var _this$timeline; | ||
this._startTime = Number((_this$timeline = this.timeline) === null || _this$timeline === void 0 ? void 0 : _this$timeline.currentTime) - newTime / this.playbackRate; | ||
} | ||
this.currentTimePending = false; | ||
if (this._currentTime === newTime) { | ||
return; | ||
} | ||
if (this._idle) { | ||
@@ -570,3 +496,2 @@ this._idle = false; | ||
} | ||
this.tickCurrentTime(newTime, true); | ||
@@ -578,3 +503,2 @@ this.timeline.applyDirtiedAnimation(this); | ||
*/ | ||
}, { | ||
@@ -606,3 +530,2 @@ key: "startTime", | ||
} | ||
this.updatePromises(); | ||
@@ -612,3 +535,2 @@ var oldCurrentTime = this.currentTime; | ||
this.startTime = null; | ||
if (this.playState !== 'paused' && this.playState !== 'idle') { | ||
@@ -620,7 +542,5 @@ this._finishedFlag = false; | ||
} | ||
if (oldCurrentTime !== null) { | ||
this.currentTime = oldCurrentTime; | ||
} | ||
this.updatePromises(); | ||
@@ -644,3 +564,2 @@ } | ||
}]); | ||
return Animation; | ||
@@ -670,8 +589,8 @@ }(); | ||
return 3.0 * aA1; | ||
}; // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2. | ||
}; | ||
// Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2. | ||
var calcBezier = function calcBezier(aT, aA1, aA2) { | ||
return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT; | ||
}; // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2. | ||
}; | ||
// Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2. | ||
var getSlope = function getSlope(aT, aA1, aA2) { | ||
@@ -682,5 +601,4 @@ return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1); | ||
var currentX, | ||
currentT, | ||
i = 0; | ||
currentT, | ||
i = 0; | ||
do { | ||
@@ -691,3 +609,2 @@ currentT = aA + (aB - aA) / 2.0; | ||
} while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS); | ||
return currentT; | ||
@@ -702,3 +619,2 @@ }; | ||
} | ||
return aGuessT; | ||
@@ -710,10 +626,8 @@ }; | ||
return t; | ||
}; // Precompute samples table | ||
}; | ||
// Precompute samples table | ||
var sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize); | ||
for (var i = 0; i < kSplineTableSize; ++i) { | ||
sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2); | ||
} | ||
var getTForX = function getTForX(aX) { | ||
@@ -723,9 +637,7 @@ var intervalStart = 0.0; | ||
var lastSample = kSplineTableSize - 1; | ||
for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) { | ||
intervalStart += kSampleStepSize; | ||
} | ||
--currentSample; // Interpolate to provide an initial guess for t | ||
--currentSample; | ||
// Interpolate to provide an initial guess for t | ||
var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]); | ||
@@ -738,3 +650,2 @@ var guessForT = intervalStart + dist * kSampleStepSize; | ||
}; | ||
return function (t) { | ||
@@ -750,4 +661,4 @@ // Because JavaScript number are imprecise, we should guarantee the extremes are right. | ||
return "-" + letter.toLowerCase(); | ||
}); // Remove first dash | ||
}); | ||
// Remove first dash | ||
return str.charAt(0) === '-' ? str.substring(1) : str; | ||
@@ -758,44 +669,32 @@ }; | ||
*/ | ||
var Quad = function Quad(t) { | ||
return Math.pow(t, 2); | ||
}; | ||
var Cubic = function Cubic(t) { | ||
return Math.pow(t, 3); | ||
}; | ||
var Quart = function Quart(t) { | ||
return Math.pow(t, 4); | ||
}; | ||
var Quint = function Quint(t) { | ||
return Math.pow(t, 5); | ||
}; | ||
var Expo = function Expo(t) { | ||
return Math.pow(t, 6); | ||
}; | ||
var Sine = function Sine(t) { | ||
return 1 - Math.cos(t * Math.PI / 2); | ||
}; | ||
var Circ = function Circ(t) { | ||
return 1 - Math.sqrt(1 - t * t); | ||
}; | ||
var Back = function Back(t) { | ||
return t * t * (3 * t - 2); | ||
}; | ||
var Bounce = function Bounce(t) { | ||
var pow2, | ||
b = 4; | ||
b = 4; | ||
while (t < ((pow2 = Math.pow(2, --b)) - 1) / 11) {} | ||
return 1 / Math.pow(4, 3 - b) - 7.5625 * Math.pow((pow2 * 3 - 2) / 22 - t, 2); | ||
}; | ||
var Elastic = function Elastic(t, params) { | ||
@@ -805,8 +704,7 @@ if (params === void 0) { | ||
} | ||
var _params = params, | ||
_params$ = _params[0], | ||
amplitude = _params$ === void 0 ? 1 : _params$, | ||
_params$2 = _params[1], | ||
period = _params$2 === void 0 ? 0.5 : _params$2; | ||
_params$ = _params[0], | ||
amplitude = _params$ === void 0 ? 1 : _params$, | ||
_params$2 = _params[1], | ||
period = _params$2 === void 0 ? 0.5 : _params$2; | ||
var a = util.clamp(Number(amplitude), 1, 10); | ||
@@ -817,3 +715,2 @@ var p = util.clamp(Number(period), 0.1, 2); | ||
}; | ||
var Spring = function Spring(t, params, duration) { | ||
@@ -823,12 +720,11 @@ if (params === void 0) { | ||
} | ||
var _params2 = params, | ||
_params2$ = _params2[0], | ||
mass = _params2$ === void 0 ? 1 : _params2$, | ||
_params2$2 = _params2[1], | ||
stiffness = _params2$2 === void 0 ? 100 : _params2$2, | ||
_params2$3 = _params2[2], | ||
damping = _params2$3 === void 0 ? 10 : _params2$3, | ||
_params2$4 = _params2[3], | ||
velocity = _params2$4 === void 0 ? 0 : _params2$4; | ||
_params2$ = _params2[0], | ||
mass = _params2$ === void 0 ? 1 : _params2$, | ||
_params2$2 = _params2[1], | ||
stiffness = _params2$2 === void 0 ? 100 : _params2$2, | ||
_params2$3 = _params2[2], | ||
damping = _params2$3 === void 0 ? 10 : _params2$3, | ||
_params2$4 = _params2[3], | ||
velocity = _params2$4 === void 0 ? 0 : _params2$4; | ||
mass = util.clamp(mass, 0.1, 1000); | ||
@@ -844,3 +740,2 @@ stiffness = util.clamp(stiffness, 0.1, 1000); | ||
var progress = duration ? duration * t / 1000 : t; | ||
if (zeta < 1) { | ||
@@ -851,3 +746,2 @@ progress = Math.exp(-progress * zeta * w0) * (a * Math.cos(wd * progress) + b * Math.sin(wd * progress)); | ||
} | ||
if (t === 0 || t === 1) return t; | ||
@@ -860,3 +754,2 @@ return 1 - progress; | ||
// export const EasingDurationCache: Map<string | TypeEasingFunction, number> = new Map(); | ||
/** | ||
@@ -866,3 +759,2 @@ * The threshold for an infinite loop | ||
// const INTINITE_LOOP_LIMIT = 10000; | ||
/** Convert easing parameters to Array of numbers, e.g. "spring(2, 500)" to [2, 500] */ | ||
@@ -878,3 +770,2 @@ // export const parseEasingParameters = (str: string) => { | ||
// }; | ||
/** | ||
@@ -910,3 +801,2 @@ * The spring easing function will only look smooth at certain durations, with certain parameters. | ||
// }; | ||
/** | ||
@@ -916,4 +806,2 @@ These Easing Functions are based off of the Sozi Project's easing functions | ||
*/ | ||
var Steps = function Steps(t, params) { | ||
@@ -923,12 +811,10 @@ if (params === void 0) { | ||
} | ||
var _params3 = params, | ||
_params3$ = _params3[0], | ||
steps = _params3$ === void 0 ? 10 : _params3$, | ||
type = _params3[1]; | ||
_params3$ = _params3[0], | ||
steps = _params3$ === void 0 ? 10 : _params3$, | ||
type = _params3[1]; | ||
var trunc = type == 'start' ? Math.ceil : Math.floor; | ||
return trunc(util.clamp(t, 0, 1) * steps) / steps; | ||
}; // @ts-ignore | ||
}; | ||
// @ts-ignore | ||
var Bezier = function Bezier(t, params) { | ||
@@ -938,16 +824,12 @@ if (params === void 0) { | ||
} | ||
var _params4 = params, | ||
mX1 = _params4[0], | ||
mY1 = _params4[1], | ||
mX2 = _params4[2], | ||
mY2 = _params4[3]; | ||
mX1 = _params4[0], | ||
mY1 = _params4[1], | ||
mX2 = _params4[2], | ||
mY2 = _params4[3]; | ||
return bezier(mX1, mY1, mX2, mY2)(t); | ||
}; | ||
/** The default `ease-in` easing function */ | ||
var easein = bezier(0.42, 0.0, 1.0, 1.0); | ||
/** Converts easing functions to their `out`counter parts */ | ||
var EaseOut = function EaseOut(ease) { | ||
@@ -958,3 +840,2 @@ return function (t, params, duration) { | ||
} | ||
return 1 - ease(1 - t, params, duration); | ||
@@ -964,4 +845,2 @@ }; | ||
/** Converts easing functions to their `in-out` counter parts */ | ||
var EaseInOut = function EaseInOut(ease) { | ||
@@ -972,3 +851,2 @@ return function (t, params, duration) { | ||
} | ||
return t < 0.5 ? ease(t * 2, params, duration) / 2 : 1 - ease(t * -2 + 2, params, duration) / 2; | ||
@@ -978,4 +856,2 @@ }; | ||
/** Converts easing functions to their `out-in` counter parts */ | ||
var EaseOutIn = function EaseOutIn(ease) { | ||
@@ -986,7 +862,5 @@ return function (t, params, duration) { | ||
} | ||
return t < 0.5 ? (1 - ease(1 - t * 2, params, duration)) / 2 : (ease(t * 2 - 1, params, duration) + 1) / 2; | ||
}; | ||
}; | ||
var EasingFunctions = { | ||
@@ -1060,3 +934,2 @@ steps: Steps, | ||
*/ | ||
var complexEasingSyntax = function complexEasingSyntax(ease) { | ||
@@ -1068,7 +941,6 @@ return convertToDash(ease).replace(/^ease-/, '') // Remove the "ease-" keyword | ||
/** 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. */ | ||
var getEasingFunction = function getEasingFunction(ease) { | ||
return EasingFunctions[complexEasingSyntax(ease)] || EasingFunctions.linear; | ||
}; // /** | ||
}; | ||
// /** | ||
// * Allows you to register new easing functions | ||
@@ -1094,3 +966,2 @@ // */ | ||
var End = 0; | ||
function step(count, pos) { | ||
@@ -1101,3 +972,2 @@ return function (x) { | ||
} | ||
var stepSize = 1 / count; | ||
@@ -1108,3 +978,2 @@ x += pos * stepSize; | ||
} | ||
var numberString = '\\s*(-?\\d+\\.?\\d*|-?\\.\\d+)\\s*'; | ||
@@ -1116,3 +985,2 @@ var cubicBezierRe = new RegExp('cubic-bezier\\(' + numberString + ',' + numberString + ',' + numberString + ',' + numberString + '\\)'); | ||
var cubicData = cubicBezierRe.exec(normalizedEasing); | ||
if (cubicData) { | ||
@@ -1122,11 +990,7 @@ // @ts-ignore | ||
} | ||
var step1Data = step1Re.exec(normalizedEasing); | ||
if (step1Data) { | ||
return step(Number(step1Data[1]), End); | ||
} | ||
var step2Data = step2Re.exec(normalizedEasing); | ||
if (step2Data) { | ||
@@ -1140,3 +1004,2 @@ // @ts-ignore | ||
} | ||
return getEasingFunction(normalizedEasing); | ||
@@ -1148,18 +1011,14 @@ } | ||
} | ||
function repeatedDuration(timing) { | ||
var _timing$iterations; | ||
// https://drafts.csswg.org/web-animations/#calculating-the-active-duration | ||
if (timing.duration === 0 || timing.iterations === 0) { | ||
return 0; | ||
} // @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/duration#value | ||
} | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/duration#value | ||
// if (timing.duration === 'auto') { | ||
// timing.duration = 0; | ||
// } | ||
return (timing.duration === 'auto' ? 0 : Number(timing.duration)) * ((_timing$iterations = timing.iterations) !== null && _timing$iterations !== void 0 ? _timing$iterations : 1); | ||
} | ||
var PhaseNone = 0; | ||
@@ -1169,3 +1028,2 @@ var PhaseBefore = 1; | ||
var PhaseActive = 3; | ||
function calculatePhase(activeDuration, localTime, timing) { | ||
@@ -1176,16 +1034,11 @@ // https://drafts.csswg.org/web-animations/#animation-effect-phases-and-states | ||
} | ||
var endTime = timing.endTime; | ||
if (localTime < Math.min(timing.delay, endTime)) { | ||
return PhaseBefore; | ||
} | ||
if (localTime >= Math.min(timing.delay + activeDuration + timing.endDelay, endTime)) { | ||
return PhaseAfter; | ||
} | ||
return PhaseActive; | ||
} | ||
function calculateActiveTime(activeDuration, fillMode, localTime, phase, delay) { | ||
@@ -1197,10 +1050,7 @@ // https://drafts.csswg.org/web-animations/#calculating-the-active-time | ||
return null; | ||
case PhaseActive: | ||
return localTime - delay; | ||
case PhaseAfter: | ||
if (fillMode === 'forwards' || fillMode === 'both') return activeDuration; | ||
return null; | ||
case PhaseNone: | ||
@@ -1210,7 +1060,5 @@ return null; | ||
} | ||
function calculateOverallProgress(iterationDuration, phase, iterations, activeTime, iterationStart) { | ||
// https://drafts.csswg.org/web-animations/#calculating-the-overall-progress | ||
var overallProgress = iterationStart; | ||
if (iterationDuration === 0) { | ||
@@ -1223,17 +1071,12 @@ if (phase !== PhaseBefore) { | ||
} | ||
return overallProgress; | ||
} | ||
function calculateSimpleIterationProgress(overallProgress, iterationStart, phase, iterations, activeTime, iterationDuration) { | ||
// https://drafts.csswg.org/web-animations/#calculating-the-simple-iteration-progress | ||
var simpleIterationProgress = overallProgress === Infinity ? iterationStart % 1 : overallProgress % 1; | ||
if (simpleIterationProgress === 0 && phase === PhaseAfter && iterations !== 0 && (activeTime !== 0 || iterationDuration === 0)) { | ||
simpleIterationProgress = 1; | ||
} | ||
return simpleIterationProgress; | ||
} | ||
function calculateCurrentIteration(phase, iterations, simpleIterationProgress, overallProgress) { | ||
@@ -1244,23 +1087,16 @@ // https://drafts.csswg.org/web-animations/#calculating-the-current-iteration | ||
} | ||
if (simpleIterationProgress === 1) { | ||
return Math.floor(overallProgress) - 1; | ||
} | ||
return Math.floor(overallProgress); | ||
} | ||
function calculateDirectedProgress(playbackDirection, currentIteration, simpleIterationProgress) { | ||
// https://drafts.csswg.org/web-animations/#calculating-the-directed-progress | ||
var currentDirection = playbackDirection; | ||
if (playbackDirection !== 'normal' && playbackDirection !== 'reverse') { | ||
var d = currentIteration; | ||
if (playbackDirection === 'alternate-reverse') { | ||
d += 1; | ||
} | ||
currentDirection = 'normal'; | ||
if (d !== Infinity && d % 2 !== 0) { | ||
@@ -1270,10 +1106,7 @@ currentDirection = 'reverse'; | ||
} | ||
if (currentDirection === 'normal') { | ||
return simpleIterationProgress; | ||
} | ||
return 1 - simpleIterationProgress; | ||
} | ||
function calculateIterationProgress(activeDuration, localTime, timing) { | ||
@@ -1289,5 +1122,5 @@ var phase = calculatePhase(activeDuration, localTime, timing); | ||
timing.currentIteration = currentIteration; | ||
timing.progress = directedProgress; // https://drafts.csswg.org/web-animations/#calculating-the-transformed-progress | ||
timing.progress = directedProgress; | ||
// https://drafts.csswg.org/web-animations/#calculating-the-transformed-progress | ||
// https://drafts.csswg.org/web-animations/#calculating-the-iteration-progress | ||
return timing.easingFunction(directedProgress); | ||
@@ -1306,4 +1139,4 @@ } | ||
var localDuration = interpolation.endOffset - interpolation.startOffset; | ||
var scaledLocalTime = localDuration === 0 ? 0 : interpolation.easingFunction(offsetFraction / localDuration); // apply updated attribute | ||
var scaledLocalTime = localDuration === 0 ? 0 : interpolation.easingFunction(offsetFraction / localDuration); | ||
// apply updated attribute | ||
target.style[interpolation.property] = interpolation.interpolation(scaledLocalTime); | ||
@@ -1321,10 +1154,7 @@ }); | ||
} | ||
function isNotReservedWord(member) { | ||
return member !== 'offset' && member !== 'easing' && member !== 'composite' && member !== 'computedOffset'; | ||
} | ||
function makePropertySpecificKeyframeGroups(keyframes, timing) { | ||
var propertySpecificKeyframeGroups = {}; | ||
for (var i = 0; i < keyframes.length; i++) { | ||
@@ -1345,12 +1175,8 @@ for (var member in keyframes[i]) { | ||
} | ||
return propertySpecificKeyframeGroups; | ||
} | ||
function makeInterpolations(propertySpecificKeyframeGroups, target) { | ||
var interpolations = []; | ||
for (var groupName in propertySpecificKeyframeGroups) { | ||
var keyframes = propertySpecificKeyframeGroups[groupName]; | ||
for (var i = 0; i < keyframes.length - 1; i++) { | ||
@@ -1363,6 +1189,4 @@ var startIndex = i; | ||
var applyTo = endOffset; | ||
if (i === 0) { | ||
applyFrom = -Infinity; | ||
if (endOffset === 0) { | ||
@@ -1372,6 +1196,4 @@ endIndex = startIndex; | ||
} | ||
if (i === keyframes.length - 2) { | ||
applyTo = Infinity; | ||
if (startOffset === 1) { | ||
@@ -1381,3 +1203,2 @@ startIndex = endIndex; | ||
} | ||
interpolations.push({ | ||
@@ -1394,3 +1215,2 @@ applyFrom: applyFrom, | ||
} | ||
interpolations.sort(function (leftInterpolation, rightInterpolation) { | ||
@@ -1401,4 +1221,4 @@ return leftInterpolation.startOffset - rightInterpolation.startOffset; | ||
} | ||
var InterpolationFactory = function InterpolationFactory(from, to, // eslint-disable-next-line @typescript-eslint/ban-types | ||
var InterpolationFactory = function InterpolationFactory(from, to, | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
convertToString) { | ||
@@ -1409,9 +1229,6 @@ return function (f) { | ||
}; | ||
function propertyInterpolation(property, left, right, target) { | ||
var metadata = gLite.propertyMetadataCache[property]; | ||
if (metadata && metadata.syntax && metadata.int) { | ||
var propertyHandler = gLite.runtime.styleValueRegistry.getPropertySyntax(metadata.syntax); | ||
if (propertyHandler) { | ||
@@ -1421,3 +1238,4 @@ var computedLeft = gLite.runtime.styleValueRegistry.parseProperty(property, left, target); | ||
var usedLeft = gLite.runtime.styleValueRegistry.computeProperty(property, computedLeft, target); | ||
var usedRight = gLite.runtime.styleValueRegistry.computeProperty(property, computedRight, target); // use defaultValue | ||
var usedRight = gLite.runtime.styleValueRegistry.computeProperty(property, computedRight, target); | ||
// use defaultValue | ||
// const parsedDefaultLeft = parseDefaultValue(metadata, target, property, left); | ||
@@ -1448,5 +1266,3 @@ // const parsedDefaultRight = parseDefaultValue(metadata, target, property, right); | ||
// merger [left, right, n2string()] | ||
var interpolationArgs = propertyHandler.mixer(usedLeft, usedRight, target); | ||
if (interpolationArgs) { | ||
@@ -1462,5 +1278,4 @@ // @ts-ignore | ||
} | ||
} // eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
return InterpolationFactory(false, true, function (bool) { | ||
@@ -1473,4 +1288,2 @@ return bool ? right : left; | ||
*/ | ||
function interpolate(from, to, f) { | ||
@@ -1480,3 +1293,2 @@ if (typeof from === 'number' && typeof to === 'number') { | ||
} | ||
if (typeof from === 'boolean' && typeof to === 'boolean' || typeof from === 'string' && typeof to === 'string' // skip string, eg. path ['M', 10, 10] | ||
@@ -1486,3 +1298,2 @@ ) { | ||
} | ||
if (Array.isArray(from) && Array.isArray(to)) { | ||
@@ -1492,11 +1303,8 @@ // interpolate arrays/matrix | ||
var r = []; | ||
for (var i = 0; i < from.length; i++) { | ||
r.push(interpolate(from[i], to[i], f)); | ||
} | ||
return r; | ||
} | ||
} | ||
throw new Error('Mismatched interpolation arguments ' + from + ':' + to); | ||
@@ -1508,3 +1316,2 @@ } | ||
*/ | ||
var AnimationEffectTiming = /*#__PURE__*/function () { | ||
@@ -1529,3 +1336,2 @@ function AnimationEffectTiming() { | ||
} | ||
_createClass(AnimationEffectTiming, [{ | ||
@@ -1543,5 +1349,3 @@ key: "easing", | ||
*/ | ||
}]); | ||
return AnimationEffectTiming; | ||
@@ -1564,6 +1368,4 @@ }(); | ||
*/ | ||
function convertToArrayForm(effectInput) { | ||
var normalizedEffectInput = []; | ||
for (var property in effectInput) { | ||
@@ -1573,21 +1375,15 @@ // skip reserved props | ||
continue; | ||
} // @ts-ignore | ||
} | ||
// @ts-ignore | ||
var values = effectInput[property]; | ||
if (!Array.isArray(values)) { | ||
values = [values]; | ||
} | ||
var numKeyframes = values.length; | ||
for (var i = 0; i < numKeyframes; i++) { | ||
if (!normalizedEffectInput[i]) { | ||
var keyframe = {}; | ||
if ('offset' in effectInput) { | ||
keyframe.offset = Number(effectInput.offset); | ||
} | ||
if ('easing' in effectInput) { | ||
@@ -1597,3 +1393,2 @@ // @ts-ignore | ||
} | ||
if ('composite' in effectInput) { | ||
@@ -1603,6 +1398,4 @@ // @ts-ignore | ||
} | ||
normalizedEffectInput[i] = keyframe; | ||
} | ||
if (values[i] !== undefined && values[i] !== null) { | ||
@@ -1613,3 +1406,2 @@ normalizedEffectInput[i][property] = values[i]; | ||
} | ||
normalizedEffectInput.sort(function (a, b) { | ||
@@ -1620,3 +1412,2 @@ return (a.computedOffset || 0) - (b.computedOffset || 0); | ||
} | ||
function normalizeKeyframes(effectInput, timing) { | ||
@@ -1626,10 +1417,7 @@ if (effectInput === null) { | ||
} | ||
if (!Array.isArray(effectInput)) { | ||
effectInput = convertToArrayForm(effectInput); | ||
} | ||
var keyframes = effectInput.map(function (originalKeyframe) { | ||
var keyframe = {}; | ||
if (timing === null || timing === void 0 ? void 0 : timing.composite) { | ||
@@ -1640,6 +1428,4 @@ // This will be auto if the composite operation specified on the effect is being used. | ||
} | ||
for (var member in originalKeyframe) { | ||
var memberValue = originalKeyframe[member]; | ||
if (member === 'offset') { | ||
@@ -1658,12 +1444,9 @@ if (memberValue !== null) { | ||
} | ||
} else ; // assign to keyframe, no need to parse shorthand value | ||
} else ; | ||
// assign to keyframe, no need to parse shorthand value | ||
keyframe[member] = memberValue; | ||
} | ||
if (keyframe.offset === undefined) { | ||
keyframe.offset = null; | ||
} | ||
if (keyframe.easing === undefined) { | ||
@@ -1673,7 +1456,5 @@ // override with timing.easing | ||
} | ||
if (keyframe.composite === undefined) { | ||
keyframe.composite = 'auto'; | ||
} | ||
return keyframe; | ||
@@ -1683,6 +1464,4 @@ }); | ||
var previousOffset = -Infinity; | ||
for (var i = 0; i < keyframes.length; i++) { | ||
var offset = keyframes[i].offset; | ||
if (!util.isNil(offset)) { | ||
@@ -1692,3 +1471,2 @@ if (offset < previousOffset) { | ||
} | ||
previousOffset = offset; | ||
@@ -1699,25 +1477,17 @@ } else { | ||
} | ||
keyframes = keyframes.filter(function (keyframe) { | ||
return Number(keyframe.offset) >= 0 && Number(keyframe.offset) <= 1; | ||
}); | ||
function spaceKeyframes() { | ||
var _keyframes$offset; | ||
var length = keyframes.length; | ||
keyframes[length - 1].computedOffset = Number((_keyframes$offset = keyframes[length - 1].offset) !== null && _keyframes$offset !== void 0 ? _keyframes$offset : 1); | ||
if (length > 1) { | ||
var _keyframes$0$offset; | ||
keyframes[0].computedOffset = Number((_keyframes$0$offset = keyframes[0].offset) !== null && _keyframes$0$offset !== void 0 ? _keyframes$0$offset : 0); | ||
} | ||
var previousIndex = 0; | ||
var previousOffset = Number(keyframes[0].computedOffset); | ||
for (var _i = 1; _i < length; _i++) { | ||
var _offset = keyframes[_i].computedOffset; | ||
if (!util.isNil(_offset) && !util.isNil(previousOffset)) { | ||
@@ -1727,3 +1497,2 @@ for (var j = 1; j < _i - previousIndex; j++) { | ||
} | ||
previousIndex = _i; | ||
@@ -1734,3 +1503,2 @@ previousOffset = Number(_offset); | ||
} | ||
if (!everyFrameHasOffset) spaceKeyframes(); | ||
@@ -1744,3 +1512,2 @@ return keyframes; | ||
var timing = new AnimationEffectTiming(); | ||
if (forGroup) { | ||
@@ -1750,3 +1517,2 @@ timing.fill = 'both'; | ||
} | ||
if (typeof timingInput === 'number' && !isNaN(timingInput)) { | ||
@@ -1762,12 +1528,9 @@ timing.duration = timingInput; | ||
} | ||
if (property === 'fill' && fills.indexOf(timingInput[property]) === -1) { | ||
return; | ||
} | ||
if (property === 'direction' && directions.indexOf(timingInput[property]) === -1) { | ||
return; | ||
} // @ts-ignore | ||
} | ||
// @ts-ignore | ||
timing[property] = timingInput[property]; | ||
@@ -1777,3 +1540,2 @@ } | ||
} | ||
return timing; | ||
@@ -1783,3 +1545,2 @@ } | ||
var _timingInput; | ||
timingInput = numericTimingToObject((_timingInput = timingInput) !== null && _timingInput !== void 0 ? _timingInput : { | ||
@@ -1802,3 +1563,2 @@ duration: 'auto' | ||
} | ||
return timingInput; | ||
@@ -1819,8 +1579,7 @@ } | ||
*/ | ||
var KeyframeEffect = /*#__PURE__*/function () { | ||
// pseudoElement: string | null; | ||
function KeyframeEffect(target, effectInput, timingInput) { | ||
var _this = this; | ||
this.composite = 'replace'; | ||
@@ -1854,3 +1613,2 @@ this.iterationComposite = 'replace'; | ||
} | ||
return target.currentIteration || 0; | ||
@@ -1861,6 +1619,4 @@ } else if (prop === 'progress') { | ||
} | ||
return target.progress || 0; | ||
} | ||
return target[prop]; | ||
@@ -1873,9 +1629,6 @@ }, | ||
} | ||
var _proto = KeyframeEffect.prototype; | ||
_proto.applyInterpolations = function applyInterpolations() { | ||
this.interpolations(this.target, Number(this.timeFraction)); | ||
}; | ||
_proto.update = function update(localTime) { | ||
@@ -1885,11 +1638,8 @@ if (localTime === null) { | ||
} | ||
this.timeFraction = calculateIterationProgress(this.timing.activeDuration, localTime, this.timing); | ||
return this.timeFraction !== null; | ||
}; | ||
_proto.getKeyframes = function getKeyframes() { | ||
return this.normalizedKeyframes; | ||
}; | ||
_proto.setKeyframes = function setKeyframes(keyframes) { | ||
@@ -1900,5 +1650,3 @@ this.normalizedKeyframes = normalizeKeyframes(keyframes); | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEffect/getComputedTiming | ||
*/ | ||
; | ||
*/; | ||
_proto.getComputedTiming = function getComputedTiming() { | ||
@@ -1909,5 +1657,3 @@ return this.computedTiming; | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEffect/getTiming | ||
*/ | ||
; | ||
*/; | ||
_proto.getTiming = function getTiming() { | ||
@@ -1918,8 +1664,5 @@ return this.timing; | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEffect/updateTiming | ||
*/ | ||
; | ||
*/; | ||
_proto.updateTiming = function updateTiming(timing) { | ||
var _this2 = this; | ||
Object.keys(timing || {}).forEach(function (name) { | ||
@@ -1929,3 +1672,2 @@ _this2.timing = timing[name]; | ||
}; | ||
return KeyframeEffect; | ||
@@ -1940,3 +1682,2 @@ }(); | ||
*/ | ||
var AnimationTimeline = /*#__PURE__*/function () { | ||
@@ -1946,5 +1687,5 @@ /** | ||
*/ | ||
function AnimationTimeline(document) { | ||
var _this = this; | ||
this.document = void 0; | ||
@@ -1962,8 +1703,5 @@ this.animations = []; | ||
this.frameId = void 0; | ||
this.webAnimationsNextTick = function (t) { | ||
_this.currentTime = t; | ||
_this.discardAnimations(); | ||
if (_this.animations.length === 0) { | ||
@@ -1975,3 +1713,2 @@ _this.timelineTicking = false; | ||
}; | ||
this.processRafCallbacks = function (t) { | ||
@@ -1981,5 +1718,3 @@ var processing = _this.rafCallbacks; | ||
if (t < Number(_this.currentTime)) t = Number(_this.currentTime); | ||
_this.animations.sort(compareAnimations); | ||
_this.animations = _this.tick(t, true, _this.animations)[0]; | ||
@@ -1989,11 +1724,7 @@ processing.forEach(function (entry) { | ||
}); | ||
_this.applyPendingEffects(); | ||
}; | ||
this.document = document; | ||
} | ||
var _proto = AnimationTimeline.prototype; | ||
_proto.getAnimations = function getAnimations() { | ||
@@ -2003,7 +1734,5 @@ this.discardAnimations(); | ||
}; | ||
_proto.isTicking = function isTicking() { | ||
return this.inTick; | ||
}; | ||
_proto.play = function play(target, keyframes, options) { | ||
@@ -2018,3 +1747,4 @@ var effect = new KeyframeEffect(target, keyframes, options); | ||
return animation; | ||
} // RAF is supposed to be the last script to occur before frame rendering but not | ||
} | ||
// RAF is supposed to be the last script to occur before frame rendering but not | ||
// all browsers behave like this. This function is for synchonously updating an | ||
@@ -2024,19 +1754,15 @@ // animation's effects whenever its state is mutated by script to work around | ||
; | ||
_proto.applyDirtiedAnimation = function applyDirtiedAnimation(animation) { | ||
var _this2 = this; | ||
if (this.inTick) { | ||
return; | ||
} // update active animations in displayobject | ||
} | ||
// update active animations in displayobject | ||
animation.markTarget(); | ||
var animations = animation.targetAnimations(); | ||
animations.sort(compareAnimations); // clear inactive animations | ||
animations.sort(compareAnimations); | ||
// clear inactive animations | ||
var inactiveAnimations = this.tick(Number(this.currentTime), false, animations.slice())[1]; | ||
inactiveAnimations.forEach(function (animation) { | ||
var index = _this2.animations.indexOf(animation); | ||
if (index !== -1) { | ||
@@ -2048,3 +1774,2 @@ _this2.animations.splice(index, 1); | ||
}; | ||
_proto.restart = function restart() { | ||
@@ -2056,10 +1781,7 @@ if (!this.ticking) { | ||
} | ||
return this.hasRestartedThisFrame; | ||
}; | ||
_proto.destroy = function destroy() { | ||
this.document.defaultView.cancelAnimationFrame(this.frameId); | ||
}; | ||
_proto.applyPendingEffects = function applyPendingEffects() { | ||
@@ -2071,3 +1793,2 @@ this.pendingEffects.forEach(function (effect) { | ||
}; | ||
_proto.updateAnimationsPromises = function updateAnimationsPromises() { | ||
@@ -2078,3 +1799,2 @@ this.animationsWithPromises = this.animationsWithPromises.filter(function (animation) { | ||
}; | ||
_proto.discardAnimations = function discardAnimations() { | ||
@@ -2086,3 +1806,2 @@ this.updateAnimationsPromises(); | ||
}; | ||
_proto.restartWebAnimationsNextTick = function restartWebAnimationsNextTick() { | ||
@@ -2094,31 +1813,22 @@ if (!this.timelineTicking) { | ||
}; | ||
_proto.rAF = function rAF(f) { | ||
var id = this.rafId++; | ||
if (this.rafCallbacks.length === 0) { | ||
this.frameId = this.document.defaultView.requestAnimationFrame(this.processRafCallbacks); | ||
} | ||
this.rafCallbacks.push([id, f]); | ||
return id; | ||
}; | ||
_proto.requestAnimationFrame = function requestAnimationFrame(f) { | ||
var _this3 = this; | ||
return this.rAF(function (x) { | ||
_this3.updateAnimationsPromises(); | ||
f(x); | ||
_this3.updateAnimationsPromises(); | ||
}); | ||
}; | ||
_proto.tick = function tick(t, isAnimationFrame, updatingAnimations) { | ||
var _this4 = this, | ||
_this$pendingEffects, | ||
_this$pendingEffects2; | ||
_this$pendingEffects, | ||
_this$pendingEffects2; | ||
this.inTick = true; | ||
@@ -2134,3 +1844,2 @@ this.hasRestartedThisFrame = false; | ||
animation.tick(t, isAnimationFrame); | ||
if (!animation._inEffect) { | ||
@@ -2143,7 +1852,5 @@ newPendingClears.push(animation.effect); | ||
} | ||
if (animation._needsTick) _this4.ticking = true; | ||
var alive = animation._inEffect || animation._needsTick; | ||
animation._inTimeline = alive; | ||
if (alive) { | ||
@@ -2155,7 +1862,4 @@ activeAnimations.push(animation); | ||
}); | ||
(_this$pendingEffects = this.pendingEffects).push.apply(_this$pendingEffects, newPendingClears); | ||
(_this$pendingEffects2 = this.pendingEffects).push.apply(_this$pendingEffects2, newPendingEffects); | ||
if (this.ticking) this.requestAnimationFrame(function () {}); | ||
@@ -2165,3 +1869,2 @@ this.inTick = false; | ||
}; | ||
return AnimationTimeline; | ||
@@ -2168,0 +1871,0 @@ }(); |
{ | ||
"name": "@antv/g-web-animations-api", | ||
"version": "1.0.16", | ||
"version": "1.0.17", | ||
"description": "A simple implementation of Web Animations API.", | ||
@@ -35,3 +35,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@antv/util": "^3.2.4" | ||
"@antv/util": "^3.3.1" | ||
}, | ||
@@ -44,3 +44,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "e7c23dd07f888b9e46a27a4f79ec80ed2db62fc7" | ||
"gitHead": "c92278756907344ff54ebc6f6a83630559ef36ff" | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5569
237044
Updated@antv/util@^3.3.1