motion-dom 14.7.1 → 14.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/cjs/index.js +408 -168
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/animation/JSAnimation.mjs +7 -1
  4. package/dist/es/animation/JSAnimation.mjs.map +1 -1
  5. package/dist/es/animation/generators/keyframes.mjs +12 -3
  6. package/dist/es/animation/generators/keyframes.mjs.map +1 -1
  7. package/dist/es/animation/utils/is-transition-defined.mjs +1 -0
  8. package/dist/es/animation/utils/is-transition-defined.mjs.map +1 -1
  9. package/dist/es/animation/waapi/supports/waapi.mjs +3 -1
  10. package/dist/es/animation/waapi/supports/waapi.mjs.map +1 -1
  11. package/dist/es/animation/waapi/transforms/TransformAnimation.mjs +31 -35
  12. package/dist/es/animation/waapi/transforms/TransformAnimation.mjs.map +1 -1
  13. package/dist/es/animation/waapi/utils/needs-mixer.mjs +11 -0
  14. package/dist/es/animation/waapi/utils/needs-mixer.mjs.map +1 -0
  15. package/dist/es/effects/svg/index.mjs +14 -0
  16. package/dist/es/effects/svg/index.mjs.map +1 -1
  17. package/dist/es/gestures/drag/VisualElementDragControls.mjs +35 -19
  18. package/dist/es/gestures/drag/VisualElementDragControls.mjs.map +1 -1
  19. package/dist/es/gestures/drag/index.mjs +4 -3
  20. package/dist/es/gestures/drag/index.mjs.map +1 -1
  21. package/dist/es/gestures/drag/projection.mjs +85 -0
  22. package/dist/es/gestures/drag/projection.mjs.map +1 -0
  23. package/dist/es/index.mjs +1 -1
  24. package/dist/es/layout/LayoutAnimationBuilder.mjs +34 -51
  25. package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
  26. package/dist/es/layout/visual-element.mjs +48 -0
  27. package/dist/es/layout/visual-element.mjs.map +1 -0
  28. package/dist/es/projection/geometry/round.mjs +25 -0
  29. package/dist/es/projection/geometry/round.mjs.map +1 -0
  30. package/dist/es/projection/node/DocumentProjectionNode.mjs +2 -8
  31. package/dist/es/projection/node/DocumentProjectionNode.mjs.map +1 -1
  32. package/dist/es/projection/node/create-projection-node.mjs +68 -48
  33. package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
  34. package/dist/es/projection/utils/measure.mjs +5 -1
  35. package/dist/es/projection/utils/measure.mjs.map +1 -1
  36. package/dist/es/render/VisualElement.mjs +3 -2
  37. package/dist/es/render/VisualElement.mjs.map +1 -1
  38. package/dist/es/stats/buffer.mjs +1 -0
  39. package/dist/es/stats/buffer.mjs.map +1 -1
  40. package/dist/es/stats/index.mjs +31 -0
  41. package/dist/es/stats/index.mjs.map +1 -1
  42. package/dist/es/utils/interpolate.mjs +3 -2
  43. package/dist/es/utils/interpolate.mjs.map +1 -1
  44. package/dist/es/utils/is-ref-object.mjs +8 -0
  45. package/dist/es/utils/is-ref-object.mjs.map +1 -0
  46. package/dist/es/utils/transform.mjs.map +1 -1
  47. package/dist/es/value/index.mjs +10 -1
  48. package/dist/es/value/index.mjs.map +1 -1
  49. package/dist/index.d.ts +2048 -1931
  50. package/dist/motion-dom.dev.js +408 -168
  51. package/dist/motion-dom.js +1 -1
  52. package/dist/size-rollup-motion-value.js +1 -1
  53. package/dist/size-rollup-motion-value.js.map +1 -1
  54. package/dist/size-rollup-style-effect.js +1 -1
  55. package/dist/size-rollup-style-effect.js.map +1 -1
  56. package/package.json +2 -2
@@ -72,9 +72,15 @@ class JSAnimation extends WithPromise {
72
72
  generatorFactory !== keyframes) {
73
73
  invariant(keyframes$1.length <= 2, `Only two keyframes currently supported with spring and inertia animations. Trying to animate ${keyframes$1}`, "spring-two-frames");
74
74
  }
75
+ /**
76
+ * This runs again when a spring is flattened to attach it to a
77
+ * timeline, and the keyframes generator blends values itself.
78
+ */
79
+ this.mixKeyframes = undefined;
75
80
  if (generatorFactory !== keyframes &&
76
81
  typeof keyframes$1[0] !== "number") {
77
- this.mixKeyframes = pipe(percentToProgress, mix(keyframes$1[0], keyframes$1[1]));
82
+ this.mixKeyframes = pipe(percentToProgress, options.mixer?.(keyframes$1[0], keyframes$1[1]) ||
83
+ mix(keyframes$1[0], keyframes$1[1]));
78
84
  keyframes$1 = [0, 100];
79
85
  }
80
86
  const generator = generatorFactory(keyframes$1 === options.keyframes
@@ -1 +1 @@
1
- {"version":3,"file":"JSAnimation.mjs","sources":["../../../src/animation/JSAnimation.ts"],"sourcesContent":["import {\n clamp,\n invariant,\n millisecondsToSeconds,\n pipe,\n secondsToMilliseconds,\n} from \"motion-utils\"\nimport { time } from \"../frameloop/sync-time\"\nimport { mix } from \"../utils/mix\"\nimport { Mixer } from \"../utils/mix/types\"\nimport { frameloopDriver } from \"./drivers/frame\"\nimport { DriverControls } from \"./drivers/types\"\nimport { inertia } from \"./generators/inertia\"\nimport { keyframes as keyframesGenerator } from \"./generators/keyframes\"\nimport { calcGeneratorDuration } from \"./generators/utils/calc-duration\"\nimport { calcGeneratorVelocity } from \"./generators/utils/velocity\"\nimport { getFinalKeyframe } from \"./keyframes/get-final\"\nimport {\n AnimationPlaybackControlsWithThen,\n AnimationState,\n GeneratorFactory,\n KeyframeGenerator,\n TimelineWithFallback,\n ValueAnimationOptions,\n} from \"./types\"\nimport { replaceTransitionType } from \"./utils/replace-transition-type\"\nimport { resolveStartTime } from \"./utils/resolve-start-time\"\nimport { notifyAnimationStart } from \"./utils/notify-inspector\"\nimport { WithPromise } from \"./utils/WithPromise\"\n\nconst percentToProgress = (percent: number) => percent / 100\n\nexport const round = (value: number) => Math.round(value * 10000) / 10000\n\nexport class JSAnimation<T extends number | string>\n extends WithPromise\n implements AnimationPlaybackControlsWithThen\n{\n state: AnimationPlayState = \"idle\"\n\n startTime: number | null = null\n\n /**\n * The driver that's controlling the animation loop. Normally this is a requestAnimationFrame loop\n * but in tests we can pass in a synchronous loop.\n */\n protected driver?: DriverControls\n\n protected isStopped = false\n\n /**\n * The start time this animation picked for itself, until its first tick.\n */\n private pendingStartTime?: number\n\n private generator: KeyframeGenerator<T>\n\n private calculatedDuration: number\n\n protected resolvedDuration: number\n\n protected totalDuration: number\n\n protected options: ValueAnimationOptions<T>\n\n /**\n * The current time of the animation.\n */\n private currentTime: number = 0\n\n /**\n * The time at which the animation was paused.\n */\n protected holdTime: number | null = null\n\n /**\n * Playback speed as a factor. 0 would be stopped, -1 reverse and 2 double speed.\n */\n private playbackSpeed = 1\n\n /*\n * If our generator doesn't support mixing numbers, we need to replace keyframes with\n * [0, 100] and then make a function that maps that to the actual keyframes.\n *\n * 100 is chosen instead of 1 as it works nicer with spring animations.\n */\n private mixKeyframes: Mixer<T> | undefined\n\n private mirroredGenerator: KeyframeGenerator<T> | undefined\n\n /**\n * Reusable state object for the delay phase to avoid\n * allocating a new object every frame.\n */\n private delayState: AnimationState<T> = {\n done: false,\n value: undefined as unknown as T,\n }\n\n constructor(options: ValueAnimationOptions<T>) {\n super()\n\n this.options = options\n this.initAnimation()\n this.play()\n\n if (options.autoplay === false) this.pause()\n\n notifyAnimationStart(this, this.options)\n }\n\n initAnimation() {\n const { options } = this\n\n replaceTransitionType(options)\n\n const {\n type = keyframesGenerator,\n repeat = 0,\n repeatDelay = 0,\n repeatType,\n velocity = 0,\n } = options\n let { keyframes } = options\n\n const generatorFactory =\n (type as GeneratorFactory) || keyframesGenerator\n\n if (\n process.env.NODE_ENV !== \"production\" &&\n generatorFactory !== keyframesGenerator\n ) {\n invariant(\n keyframes.length <= 2,\n `Only two keyframes currently supported with spring and inertia animations. Trying to animate ${keyframes}`,\n \"spring-two-frames\"\n )\n }\n\n if (\n generatorFactory !== keyframesGenerator &&\n typeof keyframes[0] !== \"number\"\n ) {\n this.mixKeyframes = pipe(\n percentToProgress,\n mix(keyframes[0], keyframes[1])\n ) as (t: number) => T\n\n keyframes = [0 as T, 100 as T]\n }\n\n const generator = generatorFactory(\n keyframes === options.keyframes\n ? options\n : { ...options, keyframes }\n )\n\n /**\n * If we have a mirror repeat type we need to create a second generator that outputs the\n * mirrored (not reversed) animation and later ping pong between the two generators.\n */\n if (repeatType === \"mirror\") {\n this.mirroredGenerator = generatorFactory({\n ...options,\n keyframes: [...keyframes].reverse(),\n velocity: -velocity,\n })\n }\n\n /**\n * If duration is undefined and we have repeat options,\n * we need to calculate a duration from the generator.\n *\n * We set it to the generator itself to cache the duration.\n * Any timeline resolver will need to have already precalculated\n * the duration by this step.\n */\n if (generator.calculatedDuration === null) {\n generator.calculatedDuration = calcGeneratorDuration(generator)\n }\n\n const { calculatedDuration } = generator\n this.calculatedDuration = calculatedDuration\n this.resolvedDuration = calculatedDuration + repeatDelay\n this.totalDuration = this.resolvedDuration * (repeat + 1) - repeatDelay\n this.generator = generator\n }\n\n updateTime(timestamp: number) {\n // Rounding the time because floating point arithmetic is not always accurate, e.g. 3000.367 - 1000.367 =\n // 2000.0000000000002. This is a problem when we are comparing the currentTime with the duration, for\n // example.\n this.currentTime =\n this.holdTime ??\n Math.round(timestamp - this.startTime!) * this.playbackSpeed\n }\n\n tick(timestamp: number, sample = false) {\n const { generator, totalDuration, calculatedDuration } = this\n\n if (this.startTime === null) return generator.next(0)\n\n const {\n delay = 0,\n keyframes,\n type,\n onUpdate,\n finalKeyframe,\n } = this.options\n\n if (this.startTime === this.pendingStartTime) {\n this.startTime = resolveStartTime(this.startTime, timestamp)\n }\n this.pendingStartTime = undefined\n\n /**\n * requestAnimationFrame timestamps can come through as lower than\n * the startTime as set by performance.now(). Here we prevent this,\n * though in the future it could be possible to make setting startTime\n * a pending operation that gets resolved here.\n */\n if (this.speed > 0) {\n this.startTime = Math.min(this.startTime, timestamp)\n } else if (this.speed < 0) {\n this.startTime = Math.min(\n timestamp - totalDuration / this.speed,\n this.startTime\n )\n }\n\n if (sample) {\n this.currentTime = timestamp\n } else {\n this.updateTime(timestamp)\n }\n\n // Rebase on delay\n const timeWithoutDelay =\n this.currentTime - delay * (this.playbackSpeed >= 0 ? 1 : -1)\n const isInDelayPhase =\n this.playbackSpeed >= 0\n ? timeWithoutDelay < 0\n : timeWithoutDelay > totalDuration\n this.currentTime = Math.max(timeWithoutDelay, 0)\n\n // If this animation has finished, set the current time to the total duration.\n if (this.state === \"finished\" && this.holdTime === null) {\n this.currentTime = totalDuration\n }\n\n const state = this.generate(this.currentTime, isInDelayPhase)\n\n let { done } = state\n\n /**\n * A generator that takes longer than maxGeneratorDuration to finish\n * has an Infinity duration, so played forwards it finishes when it\n * says it's done.\n */\n if (!isInDelayPhase) {\n done =\n this.playbackSpeed >= 0\n ? calculatedDuration < Infinity\n ? this.currentTime >= totalDuration\n : done\n : this.currentTime <= 0\n }\n\n const isAnimationFinished =\n this.holdTime === null &&\n (this.state === \"finished\" || (this.state === \"running\" && done))\n\n // TODO: The exception for inertia could be cleaner here\n if (isAnimationFinished && type !== inertia) {\n state.value = getFinalKeyframe(\n keyframes,\n this.options,\n finalKeyframe,\n this.speed\n )\n }\n\n if (onUpdate) {\n onUpdate(state.value)\n }\n\n if (isAnimationFinished) {\n this.finish()\n }\n\n return state\n }\n\n /**\n * This animation's time, including delay, at a timestamp.\n */\n at(timestamp: number) {\n return (\n this.holdTime ??\n round((timestamp - this.startTime!) * this.playbackSpeed)\n )\n }\n\n /**\n * The value at a timestamp, without changing this animation's state.\n * If resolved, it ends at the last resolved keyframe, which is in the\n * same unit as the others, rather than at finalKeyframe.\n */\n sampleAt(timestamp: number, resolved?: boolean): T {\n const { options, totalDuration } = this\n const t = this.at(timestamp) - (options.delay || 0)\n\n return t >= totalDuration && options.type !== inertia\n ? getFinalKeyframe(\n options.keyframes,\n options,\n resolved ? undefined : options.finalKeyframe\n )\n : this.generate(Math.max(t, 0), t < 0).value\n }\n\n /**\n * The generator's state `currentTime` ms after the delay, without\n * changing the animation's own state.\n */\n protected generate(\n currentTime: number,\n isInDelayPhase: boolean\n ): AnimationState<T> {\n const {\n generator,\n totalDuration,\n mixKeyframes,\n mirroredGenerator,\n resolvedDuration,\n } = this\n const { keyframes, repeat, repeatType, repeatDelay } = this.options\n\n let elapsed = currentTime\n let frameGenerator = generator\n\n if (repeat) {\n /**\n * Get the current progress (0-1) of the animation. If t is >\n * than duration we'll get values like 2.5 (midway through the\n * third iteration)\n */\n const progress =\n Math.min(currentTime, totalDuration) / resolvedDuration\n\n /**\n * Get the current iteration (0 indexed). For instance the floor of\n * 2.5 is 2.\n */\n let currentIteration = Math.floor(progress)\n\n /**\n * Get the current progress of the iteration by taking the remainder\n * so 2.5 is 0.5 through iteration 2\n */\n let iterationProgress = progress % 1.0\n\n /**\n * If iteration progress is 1 we count that as the end\n * of the previous iteration.\n */\n if (!iterationProgress && progress >= 1) {\n iterationProgress = 1\n }\n\n iterationProgress === 1 && currentIteration--\n\n currentIteration = Math.min(currentIteration, repeat + 1)\n\n /**\n * Reverse progress if we're not running in \"normal\" direction\n */\n\n const isOddIteration = Boolean(currentIteration % 2)\n if (isOddIteration) {\n if (repeatType === \"reverse\") {\n iterationProgress = 1 - iterationProgress\n if (repeatDelay) {\n iterationProgress -= repeatDelay / resolvedDuration\n }\n } else if (repeatType === \"mirror\") {\n frameGenerator = mirroredGenerator!\n }\n }\n\n elapsed = clamp(0, 1, iterationProgress) * resolvedDuration\n }\n\n /**\n * If we're in negative time, set state as the initial keyframe.\n * This prevents delay: x, duration: 0 animations from finishing\n * instantly.\n */\n let state: AnimationState<T>\n if (isInDelayPhase) {\n this.delayState.value = keyframes[0]\n state = this.delayState\n } else {\n state = frameGenerator.next(elapsed)\n }\n\n if (mixKeyframes && !isInDelayPhase) {\n state.value = mixKeyframes(state.value as number)\n }\n\n return state\n }\n\n get duration() {\n return millisecondsToSeconds(this.calculatedDuration)\n }\n\n get iterationDuration() {\n return this.duration + millisecondsToSeconds(this.options.delay ?? 0)\n }\n\n get time() {\n return millisecondsToSeconds(this.currentTime)\n }\n\n set time(newTime: number) {\n newTime = secondsToMilliseconds(newTime)\n this.currentTime = newTime\n\n if (\n this.startTime === null ||\n this.holdTime !== null ||\n this.playbackSpeed === 0\n ) {\n this.holdTime = newTime\n } else if (this.driver) {\n this.startTime = this.driver.now() - newTime / this.playbackSpeed\n }\n\n if (this.driver) {\n this.driver.start(false)\n } else {\n this.startTime = 0\n this.state = \"paused\"\n this.holdTime = newTime\n this.tick(newTime)\n }\n }\n\n /**\n * Returns the generator's velocity at the current time in units/second.\n * Uses the analytical derivative when available (springs), avoiding\n * the MotionValue's frame-dependent velocity estimation.\n */\n getGeneratorVelocity(): number {\n return calcGeneratorVelocity(\n this.generator,\n this.currentTime,\n this.options.velocity\n )\n }\n\n get speed() {\n return this.playbackSpeed\n }\n\n set speed(newSpeed: number) {\n const hasChanged = this.playbackSpeed !== newSpeed\n\n if (hasChanged && this.driver) {\n this.updateTime(time.now())\n }\n\n this.playbackSpeed = newSpeed\n\n if (hasChanged && this.driver) {\n this.time = millisecondsToSeconds(this.currentTime)\n }\n }\n\n play() {\n if (this.isStopped) return\n\n const { driver = frameloopDriver, startTime } = this.options\n\n if (!this.driver) {\n this.driver = driver((timestamp) => this.tick(timestamp))\n }\n\n this.options.onPlay?.()\n\n const now = this.driver.now()\n\n if (this.state === \"finished\") {\n this.updateFinished()\n this.startTime = now\n } else if (this.holdTime !== null) {\n this.startTime = now - this.holdTime / (this.playbackSpeed || 1)\n } else if (!this.startTime) {\n this.startTime = startTime ?? (this.pendingStartTime = now)\n }\n\n if (this.state === \"finished\" && this.speed < 0) {\n this.startTime += this.calculatedDuration\n }\n\n this.holdTime = null\n\n /**\n * Set playState to running only after we've used it in\n * the previous logic.\n */\n this.state = \"running\"\n\n this.driver.start()\n }\n\n pause() {\n this.state = \"paused\"\n this.updateTime(time.now())\n this.holdTime = this.currentTime\n }\n\n /**\n * This method is bound to the instance to fix a pattern where\n * animation.stop is returned as a reference from a useEffect.\n */\n stop = () => {\n const { motionValue } = this.options\n if (motionValue && motionValue.updatedAt !== time.now()) {\n this.tick(time.now())\n }\n\n this.isStopped = true\n if (this.state === \"idle\") return\n this.teardown()\n this.options.onStop?.()\n }\n\n complete() {\n if (this.state !== \"running\") {\n this.play()\n }\n\n this.state = \"finished\"\n this.holdTime = null\n }\n\n finish() {\n this.notifyFinished()\n this.teardown()\n this.state = \"finished\"\n\n this.options.onComplete?.()\n }\n\n cancel() {\n this.holdTime = null\n this.startTime = 0\n this.tick(0)\n this.teardown()\n this.options.onCancel?.()\n }\n\n private teardown() {\n this.state = \"idle\"\n this.driver?.stop()\n this.driver = undefined\n this.startTime = this.holdTime = null\n }\n\n sample(sampleTime: number): AnimationState<T> {\n this.startTime = 0\n return this.tick(sampleTime, true)\n }\n\n attachTimeline(timeline: TimelineWithFallback): VoidFunction {\n if (this.options.allowFlatten) {\n this.options.type = \"keyframes\"\n this.options.ease = \"linear\"\n this.initAnimation()\n }\n\n this.driver?.stop()\n return timeline.observe(this)\n }\n}\n\n// Legacy function support\nexport function animateValue<T extends number | string>(\n options: ValueAnimationOptions<T>\n) {\n return new JSAnimation(options)\n}\n"],"names":["keyframesGenerator","keyframes"],"mappings":";;;;;;;;;;;;;;AA8BA,MAAM,iBAAiB,GAAG,CAAC,OAAe,KAAK,OAAO,GAAG,GAAG;AAErD,MAAM,KAAK,GAAG,CAAC,KAAa,KAAK,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG;AAE9D,MAAO,WACT,SAAQ,WAAW,CAAA;AAgEnB,IAAA,WAAA,CAAY,OAAiC,EAAA;AACzC,QAAA,KAAK,EAAE;QA9DX,IAAA,CAAA,KAAK,GAAuB,MAAM;QAElC,IAAA,CAAA,SAAS,GAAkB,IAAI;QAQrB,IAAA,CAAA,SAAS,GAAG,KAAK;AAiB3B;;AAEG;QACK,IAAA,CAAA,WAAW,GAAW,CAAC;AAE/B;;AAEG;QACO,IAAA,CAAA,QAAQ,GAAkB,IAAI;AAExC;;AAEG;QACK,IAAA,CAAA,aAAa,GAAG,CAAC;AAYzB;;;AAGG;AACK,QAAA,IAAA,CAAA,UAAU,GAAsB;AACpC,YAAA,IAAI,EAAE,KAAK;AACX,YAAA,KAAK,EAAE,SAAyB;SACnC;AA0aD;;;AAGG;QACH,IAAA,CAA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AI,CAAC,MAAM,EAAE,IAAI,EAAE;AACnB,QAAA,IAAI,CAAC,MAAM,GAAG,SAAS;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI;IACzC;AAEA,IAAA,MAAM,CAAC,UAAkB,EAAA;AACrB,QAAA,IAAI,CAAC,SAAS,GAAG,CAAC;QAClB,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC;IACtC;AAEA,IAAA,cAAc,CAAC,QAA8B,EAAA;AACzC,QAAA,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE;AAC3B,YAAA,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,WAAW;AAC/B,YAAA,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,QAAQ;YAC5B,IAAI,CAAC,aAAa,EAAE;QACxB;AAEA,QAAA,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE;AACnB,QAAA,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC;IACjC;AACH;AAED;AACM,SAAU,YAAY,CACxB,OAAiC,EAAA;AAEjC,IAAA,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC;AACnC;;;;"}
1
+ {"version":3,"file":"JSAnimation.mjs","sources":["../../../src/animation/JSAnimation.ts"],"sourcesContent":["import {\n clamp,\n invariant,\n millisecondsToSeconds,\n pipe,\n secondsToMilliseconds,\n} from \"motion-utils\"\nimport { time } from \"../frameloop/sync-time\"\nimport { mix } from \"../utils/mix\"\nimport { Mixer } from \"../utils/mix/types\"\nimport { frameloopDriver } from \"./drivers/frame\"\nimport { DriverControls } from \"./drivers/types\"\nimport { inertia } from \"./generators/inertia\"\nimport { keyframes as keyframesGenerator } from \"./generators/keyframes\"\nimport { calcGeneratorDuration } from \"./generators/utils/calc-duration\"\nimport { calcGeneratorVelocity } from \"./generators/utils/velocity\"\nimport { getFinalKeyframe } from \"./keyframes/get-final\"\nimport {\n AnimationPlaybackControlsWithThen,\n AnimationState,\n GeneratorFactory,\n KeyframeGenerator,\n TimelineWithFallback,\n ValueAnimationOptions,\n} from \"./types\"\nimport { replaceTransitionType } from \"./utils/replace-transition-type\"\nimport { resolveStartTime } from \"./utils/resolve-start-time\"\nimport { notifyAnimationStart } from \"./utils/notify-inspector\"\nimport { WithPromise } from \"./utils/WithPromise\"\n\nconst percentToProgress = (percent: number) => percent / 100\n\nexport const round = (value: number) => Math.round(value * 10000) / 10000\n\nexport class JSAnimation<T extends number | string>\n extends WithPromise\n implements AnimationPlaybackControlsWithThen\n{\n state: AnimationPlayState = \"idle\"\n\n startTime: number | null = null\n\n /**\n * The driver that's controlling the animation loop. Normally this is a requestAnimationFrame loop\n * but in tests we can pass in a synchronous loop.\n */\n protected driver?: DriverControls\n\n protected isStopped = false\n\n /**\n * The start time this animation picked for itself, until its first tick.\n */\n private pendingStartTime?: number\n\n private generator: KeyframeGenerator<T>\n\n private calculatedDuration: number\n\n protected resolvedDuration: number\n\n protected totalDuration: number\n\n protected options: ValueAnimationOptions<T>\n\n /**\n * The current time of the animation.\n */\n private currentTime: number = 0\n\n /**\n * The time at which the animation was paused.\n */\n protected holdTime: number | null = null\n\n /**\n * Playback speed as a factor. 0 would be stopped, -1 reverse and 2 double speed.\n */\n private playbackSpeed = 1\n\n /*\n * If our generator doesn't support mixing numbers, we need to replace keyframes with\n * [0, 100] and then make a function that maps that to the actual keyframes.\n *\n * 100 is chosen instead of 1 as it works nicer with spring animations.\n */\n private mixKeyframes: Mixer<T> | undefined\n\n private mirroredGenerator: KeyframeGenerator<T> | undefined\n\n /**\n * Reusable state object for the delay phase to avoid\n * allocating a new object every frame.\n */\n private delayState: AnimationState<T> = {\n done: false,\n value: undefined as unknown as T,\n }\n\n constructor(options: ValueAnimationOptions<T>) {\n super()\n\n this.options = options\n this.initAnimation()\n this.play()\n\n if (options.autoplay === false) this.pause()\n\n notifyAnimationStart(this, this.options)\n }\n\n initAnimation() {\n const { options } = this\n\n replaceTransitionType(options)\n\n const {\n type = keyframesGenerator,\n repeat = 0,\n repeatDelay = 0,\n repeatType,\n velocity = 0,\n } = options\n let { keyframes } = options\n\n const generatorFactory =\n (type as GeneratorFactory) || keyframesGenerator\n\n if (\n process.env.NODE_ENV !== \"production\" &&\n generatorFactory !== keyframesGenerator\n ) {\n invariant(\n keyframes.length <= 2,\n `Only two keyframes currently supported with spring and inertia animations. Trying to animate ${keyframes}`,\n \"spring-two-frames\"\n )\n }\n\n /**\n * This runs again when a spring is flattened to attach it to a\n * timeline, and the keyframes generator blends values itself.\n */\n this.mixKeyframes = undefined\n\n if (\n generatorFactory !== keyframesGenerator &&\n typeof keyframes[0] !== \"number\"\n ) {\n this.mixKeyframes = pipe(\n percentToProgress,\n options.mixer?.(keyframes[0], keyframes[1]) ||\n mix(keyframes[0], keyframes[1])\n ) as (t: number) => T\n\n keyframes = [0 as T, 100 as T]\n }\n\n const generator = generatorFactory(\n keyframes === options.keyframes\n ? options\n : { ...options, keyframes }\n )\n\n /**\n * If we have a mirror repeat type we need to create a second generator that outputs the\n * mirrored (not reversed) animation and later ping pong between the two generators.\n */\n if (repeatType === \"mirror\") {\n this.mirroredGenerator = generatorFactory({\n ...options,\n keyframes: [...keyframes].reverse(),\n velocity: -velocity,\n })\n }\n\n /**\n * If duration is undefined and we have repeat options,\n * we need to calculate a duration from the generator.\n *\n * We set it to the generator itself to cache the duration.\n * Any timeline resolver will need to have already precalculated\n * the duration by this step.\n */\n if (generator.calculatedDuration === null) {\n generator.calculatedDuration = calcGeneratorDuration(generator)\n }\n\n const { calculatedDuration } = generator\n this.calculatedDuration = calculatedDuration\n this.resolvedDuration = calculatedDuration + repeatDelay\n this.totalDuration = this.resolvedDuration * (repeat + 1) - repeatDelay\n this.generator = generator\n }\n\n updateTime(timestamp: number) {\n // Rounding the time because floating point arithmetic is not always accurate, e.g. 3000.367 - 1000.367 =\n // 2000.0000000000002. This is a problem when we are comparing the currentTime with the duration, for\n // example.\n this.currentTime =\n this.holdTime ??\n Math.round(timestamp - this.startTime!) * this.playbackSpeed\n }\n\n tick(timestamp: number, sample = false) {\n const { generator, totalDuration, calculatedDuration } = this\n\n if (this.startTime === null) return generator.next(0)\n\n const {\n delay = 0,\n keyframes,\n type,\n onUpdate,\n finalKeyframe,\n } = this.options\n\n if (this.startTime === this.pendingStartTime) {\n this.startTime = resolveStartTime(this.startTime, timestamp)\n }\n this.pendingStartTime = undefined\n\n /**\n * requestAnimationFrame timestamps can come through as lower than\n * the startTime as set by performance.now(). Here we prevent this,\n * though in the future it could be possible to make setting startTime\n * a pending operation that gets resolved here.\n */\n if (this.speed > 0) {\n this.startTime = Math.min(this.startTime, timestamp)\n } else if (this.speed < 0) {\n this.startTime = Math.min(\n timestamp - totalDuration / this.speed,\n this.startTime\n )\n }\n\n if (sample) {\n this.currentTime = timestamp\n } else {\n this.updateTime(timestamp)\n }\n\n // Rebase on delay\n const timeWithoutDelay =\n this.currentTime - delay * (this.playbackSpeed >= 0 ? 1 : -1)\n const isInDelayPhase =\n this.playbackSpeed >= 0\n ? timeWithoutDelay < 0\n : timeWithoutDelay > totalDuration\n this.currentTime = Math.max(timeWithoutDelay, 0)\n\n // If this animation has finished, set the current time to the total duration.\n if (this.state === \"finished\" && this.holdTime === null) {\n this.currentTime = totalDuration\n }\n\n const state = this.generate(this.currentTime, isInDelayPhase)\n\n let { done } = state\n\n /**\n * A generator that takes longer than maxGeneratorDuration to finish\n * has an Infinity duration, so played forwards it finishes when it\n * says it's done.\n */\n if (!isInDelayPhase) {\n done =\n this.playbackSpeed >= 0\n ? calculatedDuration < Infinity\n ? this.currentTime >= totalDuration\n : done\n : this.currentTime <= 0\n }\n\n const isAnimationFinished =\n this.holdTime === null &&\n (this.state === \"finished\" || (this.state === \"running\" && done))\n\n // TODO: The exception for inertia could be cleaner here\n if (isAnimationFinished && type !== inertia) {\n state.value = getFinalKeyframe(\n keyframes,\n this.options,\n finalKeyframe,\n this.speed\n )\n }\n\n if (onUpdate) {\n onUpdate(state.value)\n }\n\n if (isAnimationFinished) {\n this.finish()\n }\n\n return state\n }\n\n /**\n * This animation's time, including delay, at a timestamp.\n */\n at(timestamp: number) {\n return (\n this.holdTime ??\n round((timestamp - this.startTime!) * this.playbackSpeed)\n )\n }\n\n /**\n * The value at a timestamp, without changing this animation's state.\n * If resolved, it ends at the last resolved keyframe, which is in the\n * same unit as the others, rather than at finalKeyframe.\n */\n sampleAt(timestamp: number, resolved?: boolean): T {\n const { options, totalDuration } = this\n const t = this.at(timestamp) - (options.delay || 0)\n\n return t >= totalDuration && options.type !== inertia\n ? getFinalKeyframe(\n options.keyframes,\n options,\n resolved ? undefined : options.finalKeyframe\n )\n : this.generate(Math.max(t, 0), t < 0).value\n }\n\n /**\n * The generator's state `currentTime` ms after the delay, without\n * changing the animation's own state.\n */\n protected generate(\n currentTime: number,\n isInDelayPhase: boolean\n ): AnimationState<T> {\n const {\n generator,\n totalDuration,\n mixKeyframes,\n mirroredGenerator,\n resolvedDuration,\n } = this\n const { keyframes, repeat, repeatType, repeatDelay } = this.options\n\n let elapsed = currentTime\n let frameGenerator = generator\n\n if (repeat) {\n /**\n * Get the current progress (0-1) of the animation. If t is >\n * than duration we'll get values like 2.5 (midway through the\n * third iteration)\n */\n const progress =\n Math.min(currentTime, totalDuration) / resolvedDuration\n\n /**\n * Get the current iteration (0 indexed). For instance the floor of\n * 2.5 is 2.\n */\n let currentIteration = Math.floor(progress)\n\n /**\n * Get the current progress of the iteration by taking the remainder\n * so 2.5 is 0.5 through iteration 2\n */\n let iterationProgress = progress % 1.0\n\n /**\n * If iteration progress is 1 we count that as the end\n * of the previous iteration.\n */\n if (!iterationProgress && progress >= 1) {\n iterationProgress = 1\n }\n\n iterationProgress === 1 && currentIteration--\n\n currentIteration = Math.min(currentIteration, repeat + 1)\n\n /**\n * Reverse progress if we're not running in \"normal\" direction\n */\n\n const isOddIteration = Boolean(currentIteration % 2)\n if (isOddIteration) {\n if (repeatType === \"reverse\") {\n iterationProgress = 1 - iterationProgress\n if (repeatDelay) {\n iterationProgress -= repeatDelay / resolvedDuration\n }\n } else if (repeatType === \"mirror\") {\n frameGenerator = mirroredGenerator!\n }\n }\n\n elapsed = clamp(0, 1, iterationProgress) * resolvedDuration\n }\n\n /**\n * If we're in negative time, set state as the initial keyframe.\n * This prevents delay: x, duration: 0 animations from finishing\n * instantly.\n */\n let state: AnimationState<T>\n if (isInDelayPhase) {\n this.delayState.value = keyframes[0]\n state = this.delayState\n } else {\n state = frameGenerator.next(elapsed)\n }\n\n if (mixKeyframes && !isInDelayPhase) {\n state.value = mixKeyframes(state.value as number)\n }\n\n return state\n }\n\n get duration() {\n return millisecondsToSeconds(this.calculatedDuration)\n }\n\n get iterationDuration() {\n return this.duration + millisecondsToSeconds(this.options.delay ?? 0)\n }\n\n get time() {\n return millisecondsToSeconds(this.currentTime)\n }\n\n set time(newTime: number) {\n newTime = secondsToMilliseconds(newTime)\n this.currentTime = newTime\n\n if (\n this.startTime === null ||\n this.holdTime !== null ||\n this.playbackSpeed === 0\n ) {\n this.holdTime = newTime\n } else if (this.driver) {\n this.startTime = this.driver.now() - newTime / this.playbackSpeed\n }\n\n if (this.driver) {\n this.driver.start(false)\n } else {\n this.startTime = 0\n this.state = \"paused\"\n this.holdTime = newTime\n this.tick(newTime)\n }\n }\n\n /**\n * Returns the generator's velocity at the current time in units/second.\n * Uses the analytical derivative when available (springs), avoiding\n * the MotionValue's frame-dependent velocity estimation.\n */\n getGeneratorVelocity(): number {\n return calcGeneratorVelocity(\n this.generator,\n this.currentTime,\n this.options.velocity\n )\n }\n\n get speed() {\n return this.playbackSpeed\n }\n\n set speed(newSpeed: number) {\n const hasChanged = this.playbackSpeed !== newSpeed\n\n if (hasChanged && this.driver) {\n this.updateTime(time.now())\n }\n\n this.playbackSpeed = newSpeed\n\n if (hasChanged && this.driver) {\n this.time = millisecondsToSeconds(this.currentTime)\n }\n }\n\n play() {\n if (this.isStopped) return\n\n const { driver = frameloopDriver, startTime } = this.options\n\n if (!this.driver) {\n this.driver = driver((timestamp) => this.tick(timestamp))\n }\n\n this.options.onPlay?.()\n\n const now = this.driver.now()\n\n if (this.state === \"finished\") {\n this.updateFinished()\n this.startTime = now\n } else if (this.holdTime !== null) {\n this.startTime = now - this.holdTime / (this.playbackSpeed || 1)\n } else if (!this.startTime) {\n this.startTime = startTime ?? (this.pendingStartTime = now)\n }\n\n if (this.state === \"finished\" && this.speed < 0) {\n this.startTime += this.calculatedDuration\n }\n\n this.holdTime = null\n\n /**\n * Set playState to running only after we've used it in\n * the previous logic.\n */\n this.state = \"running\"\n\n this.driver.start()\n }\n\n pause() {\n this.state = \"paused\"\n this.updateTime(time.now())\n this.holdTime = this.currentTime\n }\n\n /**\n * This method is bound to the instance to fix a pattern where\n * animation.stop is returned as a reference from a useEffect.\n */\n stop = () => {\n const { motionValue } = this.options\n if (motionValue && motionValue.updatedAt !== time.now()) {\n this.tick(time.now())\n }\n\n this.isStopped = true\n if (this.state === \"idle\") return\n this.teardown()\n this.options.onStop?.()\n }\n\n complete() {\n if (this.state !== \"running\") {\n this.play()\n }\n\n this.state = \"finished\"\n this.holdTime = null\n }\n\n finish() {\n this.notifyFinished()\n this.teardown()\n this.state = \"finished\"\n\n this.options.onComplete?.()\n }\n\n cancel() {\n this.holdTime = null\n this.startTime = 0\n this.tick(0)\n this.teardown()\n this.options.onCancel?.()\n }\n\n private teardown() {\n this.state = \"idle\"\n this.driver?.stop()\n this.driver = undefined\n this.startTime = this.holdTime = null\n }\n\n sample(sampleTime: number): AnimationState<T> {\n this.startTime = 0\n return this.tick(sampleTime, true)\n }\n\n attachTimeline(timeline: TimelineWithFallback): VoidFunction {\n if (this.options.allowFlatten) {\n this.options.type = \"keyframes\"\n this.options.ease = \"linear\"\n this.initAnimation()\n }\n\n this.driver?.stop()\n return timeline.observe(this)\n }\n}\n\n// Legacy function support\nexport function animateValue<T extends number | string>(\n options: ValueAnimationOptions<T>\n) {\n return new JSAnimation(options)\n}\n"],"names":["keyframesGenerator","keyframes"],"mappings":";;;;;;;;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AI,CAAC,OAAO,CAAC,IAAI,GAAG,WAAW;AAC/B,YAAA,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,QAAQ;YAC5B,IAAI,CAAC,aAAa,EAAE;QACxB;AAEA,QAAA,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE;AACnB,QAAA,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC;IACjC;AACH;AAED;AACM,SAAU,YAAY,CACxB,OAAiC,EAAA;AAEjC,IAAA,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC;AACnC;;;;"}
@@ -7,7 +7,13 @@ import { convertOffsetToTimes } from '../keyframes/offsets/time.mjs';
7
7
  function defaultEasing(values, easing) {
8
8
  return values.map(() => easing || easeInOut).splice(0, values.length - 1);
9
9
  }
10
- function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "easeInOut", }) {
10
+ function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "easeInOut", mixer: transitionMixer, }) {
11
+ /**
12
+ * A mixer only blends values that aren't numbers. Numbers blend as
13
+ * usual, as they do in springs, and so do the progress animations
14
+ * behind layout and path animations, which take the same transition.
15
+ */
16
+ const customMixer = typeof keyframeValues[0] === "number" ? undefined : transitionMixer;
11
17
  /**
12
18
  * Easing functions can be externally defined as strings. Here we convert them
13
19
  * into actual functions.
@@ -24,9 +30,11 @@ function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "e
24
30
  value: keyframeValues[0],
25
31
  };
26
32
  /**
27
- * Fast setup path for two keyframes one easing.
33
+ * Fast setup path for two keyframes one easing. interpolate() handles
34
+ * a custom mixer, and falls back to the usual one where it declines.
28
35
  */
29
- if (keyframeValues.length === 2 &&
36
+ if (!customMixer &&
37
+ keyframeValues.length === 2 &&
30
38
  !Array.isArray(easingFunctions) &&
31
39
  (!times ||
32
40
  times.length !== 2 ||
@@ -59,6 +67,7 @@ function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "e
59
67
  ease: Array.isArray(easingFunctions)
60
68
  ? easingFunctions
61
69
  : defaultEasing(keyframeValues, easingFunctions),
70
+ mixer: customMixer,
62
71
  });
63
72
  return {
64
73
  calculatedDuration: duration,
@@ -1 +1 @@
1
- {"version":3,"file":"keyframes.mjs","sources":["../../../../src/animation/generators/keyframes.ts"],"sourcesContent":["import {\n clamp,\n easeInOut,\n easingDefinitionToFunction,\n EasingFunction,\n isEasingArray,\n MotionGlobalConfig,\n} from \"motion-utils\"\nimport { interpolate } from \"../../utils/interpolate\"\nimport { mix } from \"../../utils/mix\"\nimport { defaultOffset } from \"../keyframes/offsets/default\"\nimport { convertOffsetToTimes } from \"../keyframes/offsets/time\"\nimport {\n AnimationState,\n AnyResolvedKeyframe,\n KeyframeGenerator,\n ValueAnimationOptions,\n} from \"../types\"\n\nexport function defaultEasing(\n values: any[],\n easing?: EasingFunction\n): EasingFunction[] {\n return values.map(() => easing || easeInOut).splice(0, values.length - 1)\n}\n\nexport function keyframes<T extends AnyResolvedKeyframe>({\n duration = 300,\n keyframes: keyframeValues,\n times,\n ease = \"easeInOut\",\n}: ValueAnimationOptions<T>): KeyframeGenerator<T> {\n /**\n * Easing functions can be externally defined as strings. Here we convert them\n * into actual functions.\n */\n const easingFunctions = isEasingArray(ease)\n ? ease.map(easingDefinitionToFunction)\n : easingDefinitionToFunction(ease) || easeInOut\n\n /**\n * This is the Iterator-spec return value. We ensure it's mutable rather than using a generator\n * to reduce GC during animation.\n */\n const state: AnimationState<T> = {\n done: false,\n value: keyframeValues[0],\n }\n\n /**\n * Fast setup path for two keyframes one easing.\n */\n if (\n keyframeValues.length === 2 &&\n !Array.isArray(easingFunctions) &&\n (!times ||\n times.length !== 2 ||\n (times[0] === 0 && times[1] === 1))\n ) {\n const [origin, target] = keyframeValues\n const mixer =\n origin === target\n ? undefined\n : (MotionGlobalConfig.mix || mix)(origin, target)\n\n return {\n calculatedDuration: duration,\n next: (t: number) => {\n state.value = mixer\n ? mixer(\n easingFunctions(\n duration > 0 ? clamp(0, 1, t / duration) : 1\n )\n )\n : target\n state.done = t >= duration\n return state\n },\n }\n }\n\n /**\n * Create a times array based on the provided 0-1 offsets\n */\n const absoluteTimes = convertOffsetToTimes(\n // Only use the provided offsets if they're the correct length\n // TODO Maybe we should warn here if there's a length mismatch\n times && times.length === keyframeValues.length\n ? times\n : defaultOffset(keyframeValues),\n duration\n )\n\n const mapTimeToKeyframe = interpolate<T>(absoluteTimes, keyframeValues, {\n ease: Array.isArray(easingFunctions)\n ? easingFunctions\n : defaultEasing(keyframeValues, easingFunctions),\n })\n\n return {\n calculatedDuration: duration,\n next: (t: number) => {\n state.value = mapTimeToKeyframe(t)\n state.done = t >= duration\n return state\n },\n }\n}\n"],"names":[],"mappings":";;;;;;AAmBM,SAAU,aAAa,CACzB,MAAa,EACb,MAAuB,EAAA;IAEvB,OAAO,MAAM,CAAC,GAAG,CAAC,MAAM,MAAM,IAAI,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;AAC7E;SAEgB,SAAS,CAAgC,EACrD,QAAQ,GAAG,GAAG,EACd,SAAS,EAAE,cAAc,EACzB,KAAK,EACL,IAAI,GAAG,WAAW,GACK,EAAA;AACvB;;;AAGG;AACH,IAAA,MAAM,eAAe,GAAG,aAAa,CAAC,IAAI;AACtC,UAAE,IAAI,CAAC,GAAG,CAAC,0BAA0B;AACrC,UAAE,0BAA0B,CAAC,IAAI,CAAC,IAAI,SAAS;AAEnD;;;AAGG;AACH,IAAA,MAAM,KAAK,GAAsB;AAC7B,QAAA,IAAI,EAAE,KAAK;AACX,QAAA,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC;KAC3B;AAED;;AAEG;AACH,IAAA,IACI,cAAc,CAAC,MAAM,KAAK,CAAC;AAC3B,QAAA,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC;AAC/B,SAAC,CAAC,KAAK;YACH,KAAK,CAAC,MAAM,KAAK,CAAC;AAClB,aAAC,KAAK,CAAC,CAAC,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,KAAK;QAChB,CAAC;KACJ;AACL;;;;"}
1
+ {"version":3,"file":"keyframes.mjs","sources":["../../../../src/animation/generators/keyframes.ts"],"sourcesContent":["import {\n clamp,\n easeInOut,\n easingDefinitionToFunction,\n EasingFunction,\n isEasingArray,\n MotionGlobalConfig,\n} from \"motion-utils\"\nimport { interpolate } from \"../../utils/interpolate\"\nimport { mix } from \"../../utils/mix\"\nimport { defaultOffset } from \"../keyframes/offsets/default\"\nimport { convertOffsetToTimes } from \"../keyframes/offsets/time\"\nimport {\n AnimationState,\n AnyResolvedKeyframe,\n KeyframeGenerator,\n ValueAnimationOptions,\n} from \"../types\"\n\nexport function defaultEasing(\n values: any[],\n easing?: EasingFunction\n): EasingFunction[] {\n return values.map(() => easing || easeInOut).splice(0, values.length - 1)\n}\n\nexport function keyframes<T extends AnyResolvedKeyframe>({\n duration = 300,\n keyframes: keyframeValues,\n times,\n ease = \"easeInOut\",\n mixer: transitionMixer,\n}: ValueAnimationOptions<T>): KeyframeGenerator<T> {\n /**\n * A mixer only blends values that aren't numbers. Numbers blend as\n * usual, as they do in springs, and so do the progress animations\n * behind layout and path animations, which take the same transition.\n */\n const customMixer =\n typeof keyframeValues[0] === \"number\" ? undefined : transitionMixer\n\n /**\n * Easing functions can be externally defined as strings. Here we convert them\n * into actual functions.\n */\n const easingFunctions = isEasingArray(ease)\n ? ease.map(easingDefinitionToFunction)\n : easingDefinitionToFunction(ease) || easeInOut\n\n /**\n * This is the Iterator-spec return value. We ensure it's mutable rather than using a generator\n * to reduce GC during animation.\n */\n const state: AnimationState<T> = {\n done: false,\n value: keyframeValues[0],\n }\n\n /**\n * Fast setup path for two keyframes one easing. interpolate() handles\n * a custom mixer, and falls back to the usual one where it declines.\n */\n if (\n !customMixer &&\n keyframeValues.length === 2 &&\n !Array.isArray(easingFunctions) &&\n (!times ||\n times.length !== 2 ||\n (times[0] === 0 && times[1] === 1))\n ) {\n const [origin, target] = keyframeValues\n const mixer =\n origin === target\n ? undefined\n : (MotionGlobalConfig.mix || mix)(origin, target)\n\n return {\n calculatedDuration: duration,\n next: (t: number) => {\n state.value = mixer\n ? mixer(\n easingFunctions(\n duration > 0 ? clamp(0, 1, t / duration) : 1\n )\n )\n : target\n state.done = t >= duration\n return state\n },\n }\n }\n\n /**\n * Create a times array based on the provided 0-1 offsets\n */\n const absoluteTimes = convertOffsetToTimes(\n // Only use the provided offsets if they're the correct length\n // TODO Maybe we should warn here if there's a length mismatch\n times && times.length === keyframeValues.length\n ? times\n : defaultOffset(keyframeValues),\n duration\n )\n\n const mapTimeToKeyframe = interpolate<T>(absoluteTimes, keyframeValues, {\n ease: Array.isArray(easingFunctions)\n ? easingFunctions\n : defaultEasing(keyframeValues, easingFunctions),\n mixer: customMixer,\n })\n\n return {\n calculatedDuration: duration,\n next: (t: number) => {\n state.value = mapTimeToKeyframe(t)\n state.done = t >= duration\n return state\n },\n }\n}\n"],"names":[],"mappings":";;;;;;AAmBM,SAAU,aAAa,CACzB,MAAa,EACb,MAAuB,EAAA;IAEvB,OAAO,MAAM,CAAC,GAAG,CAAC,MAAM,MAAM,IAAI,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;AAC7E;AAEM,SAAU,SAAS,CAAgC,EACrD,QAAQ,GAAG,GAAG,EACd,SAAS,EAAE,cAAc,EACzB,KAAK,EACL,IAAI,GAAG,WAAW,EAClB,KAAK,EAAE,eAAe,GACC,EAAA;AACvB;;;;AAIG;AACH,IAAA,MAAM,WAAW,GACb,OAAO,cAAc,CAAC,CAAC,CAAC,KAAK,QAAQ,GAAG,SAAS,GAAG,eAAe;AAEvE;;;AAGG;AACH,IAAA,MAAM,eAAe,GAAG,aAAa,CAAC,IAAI;AACtC,UAAE,IAAI,CAAC,GAAG,CAAC,0BAA0B;AACrC,UAAE,0BAA0B,CAAC,IAAI,CAAC,IAAI,SAAS;AAEnD;;;AAGG;AACH,IAAA,MAAM,KAAK,GAAsB;AAC7B,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AC/B,cAAE;AACF,cAAE,aAAa,CAAC,cAAc,EAAE,eAAe,CAAC;AACpD,QAAA,KAAK,EAAE,WAAW;AACrB,KAAA,CAAC;IAEF,OAAO;AACH,QAAA,kBAAkB,EAAE,QAAQ;AAC5B,QAAA,IAAI,EAAE,CAAC,CAAS,KAAI;AAChB,YAAA,KAAK,CAAC,KAAK,GAAG,iBAAiB,CAAC,CAAC,CAAC;AAClC,YAAA,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,QAAQ;AAC1B,YAAA,OAAO,KAAK;QAChB,CAAC;KACJ;AACL;;;;"}
@@ -10,6 +10,7 @@ const orchestrationKeys = new Set([
10
10
  "from",
11
11
  "elapsed",
12
12
  "out",
13
+ "mixer",
13
14
  ]);
14
15
  /**
15
16
  * Decide whether a transition is defined on a given Transition.
@@ -1 +1 @@
1
- {"version":3,"file":"is-transition-defined.mjs","sources":["../../../../src/animation/utils/is-transition-defined.ts"],"sourcesContent":["import type { AnyResolvedKeyframe } from \"../types\"\nimport type { Transition } from \"../types\"\n\nconst orchestrationKeys = new Set([\n \"when\",\n \"delay\",\n \"delayChildren\",\n \"staggerChildren\",\n \"staggerDirection\",\n \"repeat\",\n \"repeatType\",\n \"repeatDelay\",\n \"from\",\n \"elapsed\",\n \"out\",\n])\n\n/**\n * Decide whether a transition is defined on a given Transition.\n * This filters out orchestration options and returns true\n * if any options are left.\n */\nexport function isTransitionDefined(\n transition: Transition & { elapsed?: number; from?: AnyResolvedKeyframe }\n) {\n for (const key in transition) {\n if (!orchestrationKeys.has(key)) return true\n }\n return false\n}\n"],"names":[],"mappings":"AAGA,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAC9B,MAAM;IACN,OAAO;IACP,eAAe;IACf,iBAAiB;IACjB,kBAAkB;IAClB,QAAQ;IACR,YAAY;IACZ,aAAa;IACb,MAAM;IACN,SAAS;IACT,KAAK;AACR,CAAA,CAAC;AAEF;;;;AAIG;AACG,SAAU,mBAAmB,CAC/B,UAAyE,EAAA;AAEzE,IAAA,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE;AAC1B,QAAA,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC;AAAE,YAAA,OAAO,IAAI;IAChD;AACA,IAAA,OAAO,KAAK;AAChB;;;;"}
1
+ {"version":3,"file":"is-transition-defined.mjs","sources":["../../../../src/animation/utils/is-transition-defined.ts"],"sourcesContent":["import type { AnyResolvedKeyframe } from \"../types\"\nimport type { Transition } from \"../types\"\n\nconst orchestrationKeys = new Set([\n \"when\",\n \"delay\",\n \"delayChildren\",\n \"staggerChildren\",\n \"staggerDirection\",\n \"repeat\",\n \"repeatType\",\n \"repeatDelay\",\n \"from\",\n \"elapsed\",\n \"out\",\n \"mixer\",\n])\n\n/**\n * Decide whether a transition is defined on a given Transition.\n * This filters out orchestration options and returns true\n * if any options are left.\n */\nexport function isTransitionDefined(\n transition: Transition & { elapsed?: number; from?: AnyResolvedKeyframe }\n) {\n for (const key in transition) {\n if (!orchestrationKeys.has(key)) return true\n }\n return false\n}\n"],"names":[],"mappings":"AAGA,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAC9B,MAAM;IACN,OAAO;IACP,eAAe;IACf,iBAAiB;IACjB,kBAAkB;IAClB,QAAQ;IACR,YAAY;IACZ,aAAa;IACb,MAAM;IACN,SAAS;IACT,KAAK;IACL,OAAO;AACV,CAAA,CAAC;AAEF;;;;AAIG;AACG,SAAU,mBAAmB,CAC/B,UAAyE,EAAA;AAEzE,IAAA,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE;AAC1B,QAAA,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC;AAAE,YAAA,OAAO,IAAI;IAChD;AACA,IAAA,OAAO,KAAK;AAChB;;;;"}
@@ -1,6 +1,7 @@
1
1
  import { MotionGlobalConfig } from 'motion-utils';
2
2
  import { acceleratedValues } from '../utils/accelerated-values.mjs';
3
3
  import { hasBrowserOnlyColors } from '../utils/is-browser-color.mjs';
4
+ import { needsMixer } from '../utils/needs-mixer.mjs';
4
5
 
5
6
  const colorProperties = new Set([
6
7
  "color",
@@ -61,7 +62,8 @@ function supportsBrowserAnimation(options) {
61
62
  !repeatDelay &&
62
63
  repeatType !== "mirror" &&
63
64
  damping !== 0 &&
64
- type !== "inertia");
65
+ type !== "inertia" &&
66
+ !needsMixer(options));
65
67
  }
66
68
 
67
69
  export { supportsBrowserAnimation, supportsWaapi };
@@ -1 +1 @@
1
- {"version":3,"file":"waapi.mjs","sources":["../../../../../src/animation/waapi/supports/waapi.ts"],"sourcesContent":["import { MotionGlobalConfig } from \"motion-utils\"\nimport {\n AnyResolvedKeyframe,\n ValueAnimationOptionsWithRenderContext,\n} from \"../../types\"\nimport { acceleratedValues } from \"../utils/accelerated-values\"\nimport { hasBrowserOnlyColors } from \"../utils/is-browser-color\"\n\nconst colorProperties = new Set([\n \"color\",\n \"backgroundColor\",\n \"outlineColor\",\n \"fill\",\n \"stroke\",\n \"borderColor\",\n \"borderTopColor\",\n \"borderRightColor\",\n \"borderBottomColor\",\n \"borderLeftColor\",\n])\n\n/**\n * WAAPI runs on the browser's clock, so on a manual clock every animation\n * runs in JS where processFrame can drive it. Set the flag before starting\n * animations: running WAAPI animations stay on the browser's clock.\n */\nexport const supportsWaapi = () =>\n !MotionGlobalConfig.useManualTiming &&\n Object.hasOwnProperty.call(Element.prototype, \"animate\")\n\nexport function supportsBrowserAnimation<T extends AnyResolvedKeyframe>(\n options: ValueAnimationOptionsWithRenderContext<T>\n) {\n const {\n motionValue,\n name,\n repeatDelay,\n repeatType,\n damping,\n type,\n keyframes,\n } = options\n\n /**\n * Most values can't be accelerated at all, so check the name before\n * looking at the element or its props.\n */\n if (\n !name ||\n !(acceleratedValues.has(name) || colorProperties.has(name))\n ) {\n return false\n }\n\n const subject = motionValue?.owner?.current\n\n /**\n * We use instanceof checks instead of isHTMLElement()/isSVGElement()\n * because we explicitly **don't** want elements in different timing\n * contexts (i.e. popups) to be accelerated, as it's not possible to sync\n * these animations properly with those driven from the main window\n * frameloop.\n */\n if (\n !(subject instanceof HTMLElement) &&\n !(subject instanceof SVGElement)\n ) {\n return false\n }\n\n const { onUpdate, transformTemplate } = motionValue!.owner!.getProps()\n\n return (\n supportsWaapi() &&\n /**\n * Force WAAPI for color properties with browser-only color formats\n * (oklch, oklab, lab, lch, etc.) that the JS animation path can't parse.\n */\n (acceleratedValues.has(name) ||\n (colorProperties.has(name) &&\n hasBrowserOnlyColors(keyframes))) &&\n (name !== \"transform\" || !transformTemplate) &&\n /**\n * If we're outputting values to onUpdate then we can't use WAAPI as there's\n * no way to read the value from WAAPI every frame.\n */\n !onUpdate &&\n !repeatDelay &&\n repeatType !== \"mirror\" &&\n damping !== 0 &&\n type !== \"inertia\"\n )\n}\n"],"names":[],"mappings":";;;;AAQA,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC5B,OAAO;IACP,iBAAiB;IACjB,cAAc;IACd,MAAM;IACN,QAAQ;IACR,aAAa;IACb,gBAAgB;IAChB,kBAAkB;IAClB,mBAAmB;IACnB,iBAAiB;AACpB,CAAA,CAAC;AAEF;;;;AAIG;AACI,MAAM,aAAa,GAAG,MACzB,CAAC,kBAAkB,CAAC,eAAe;IACnC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS;AAErD,SAAU,wBAAwB,CACpC,OAAkD,EAAA;AAElD,IAAA,MAAM,EACF,WAAW,EACX,IAAI,EACJ,WAAW,EACX,UAAU,EACV,OAAO,EACP,IAAI,EACJ,SAAS,GACZ,GAAG,OAAO;AAEX;;;AAGG;AACH,IAAA,IACI,CAAC,IAAI;AACL,QAAA,EAAE,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAC7D;AACE,QAAA,OAAO,KAAK;IAChB;AAEA,IAAA,MAAM,OAAO,GAAG,WAAW,EAAE,KAAK,EAAE,OAAO;AAE3C;;;;;;AAMG;AACH,IAAA,IACI,EAAE,OAAO,YAAY,WAAW,CAAC;AACjC,QAAA,EAAE,OAAO,YAAY,UAAU,CAAC,EAClC;AACE,QAAA,OAAO,KAAK;IAChB;AAEA,IAAA,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,WAAY,CAAC,KAAM,CAAC,QAAQ,EAAE;IAEtE,QACI,aAAa,EAAE;AACf;;;AAGG;AACH,SAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC;AACxB,aAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC;AACtB,gBAAA,oBAAoB,CAAC,SAAS,CAAC,CAAC,CAAC;AACzC,SAAC,IAAI,KAAK,WAAW,IAAI,CAAC,iBAAiB,CAAC;AAC5C;;;AAGG;AACH,QAAA,CAAC,QAAQ;AACT,QAAA,CAAC,WAAW;AACZ,QAAA,UAAU,KAAK,QAAQ;AACvB,QAAA,OAAO,KAAK,CAAC;QACb,IAAI,KAAK,SAAS;AAE1B;;;;"}
1
+ {"version":3,"file":"waapi.mjs","sources":["../../../../../src/animation/waapi/supports/waapi.ts"],"sourcesContent":["import { MotionGlobalConfig } from \"motion-utils\"\nimport {\n AnyResolvedKeyframe,\n ValueAnimationOptionsWithRenderContext,\n} from \"../../types\"\nimport { acceleratedValues } from \"../utils/accelerated-values\"\nimport { hasBrowserOnlyColors } from \"../utils/is-browser-color\"\nimport { needsMixer } from \"../utils/needs-mixer\"\n\nconst colorProperties = new Set([\n \"color\",\n \"backgroundColor\",\n \"outlineColor\",\n \"fill\",\n \"stroke\",\n \"borderColor\",\n \"borderTopColor\",\n \"borderRightColor\",\n \"borderBottomColor\",\n \"borderLeftColor\",\n])\n\n/**\n * WAAPI runs on the browser's clock, so on a manual clock every animation\n * runs in JS where processFrame can drive it. Set the flag before starting\n * animations: running WAAPI animations stay on the browser's clock.\n */\nexport const supportsWaapi = () =>\n !MotionGlobalConfig.useManualTiming &&\n Object.hasOwnProperty.call(Element.prototype, \"animate\")\n\nexport function supportsBrowserAnimation<T extends AnyResolvedKeyframe>(\n options: ValueAnimationOptionsWithRenderContext<T>\n) {\n const {\n motionValue,\n name,\n repeatDelay,\n repeatType,\n damping,\n type,\n keyframes,\n } = options\n\n /**\n * Most values can't be accelerated at all, so check the name before\n * looking at the element or its props.\n */\n if (\n !name ||\n !(acceleratedValues.has(name) || colorProperties.has(name))\n ) {\n return false\n }\n\n const subject = motionValue?.owner?.current\n\n /**\n * We use instanceof checks instead of isHTMLElement()/isSVGElement()\n * because we explicitly **don't** want elements in different timing\n * contexts (i.e. popups) to be accelerated, as it's not possible to sync\n * these animations properly with those driven from the main window\n * frameloop.\n */\n if (\n !(subject instanceof HTMLElement) &&\n !(subject instanceof SVGElement)\n ) {\n return false\n }\n\n const { onUpdate, transformTemplate } = motionValue!.owner!.getProps()\n\n return (\n supportsWaapi() &&\n /**\n * Force WAAPI for color properties with browser-only color formats\n * (oklch, oklab, lab, lch, etc.) that the JS animation path can't parse.\n */\n (acceleratedValues.has(name) ||\n (colorProperties.has(name) &&\n hasBrowserOnlyColors(keyframes))) &&\n (name !== \"transform\" || !transformTemplate) &&\n /**\n * If we're outputting values to onUpdate then we can't use WAAPI as there's\n * no way to read the value from WAAPI every frame.\n */\n !onUpdate &&\n !repeatDelay &&\n repeatType !== \"mirror\" &&\n damping !== 0 &&\n type !== \"inertia\" &&\n !needsMixer(options)\n )\n}\n"],"names":[],"mappings":";;;;;AASA,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC5B,OAAO;IACP,iBAAiB;IACjB,cAAc;IACd,MAAM;IACN,QAAQ;IACR,aAAa;IACb,gBAAgB;IAChB,kBAAkB;IAClB,mBAAmB;IACnB,iBAAiB;AACpB,CAAA,CAAC;AAEF;;;;AAIG;AACI,MAAM,aAAa,GAAG,MACzB,CAAC,kBAAkB,CAAC,eAAe;IACnC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS;AAErD,SAAU,wBAAwB,CACpC,OAAkD,EAAA;AAElD,IAAA,MAAM,EACF,WAAW,EACX,IAAI,EACJ,WAAW,EACX,UAAU,EACV,OAAO,EACP,IAAI,EACJ,SAAS,GACZ,GAAG,OAAO;AAEX;;;AAGG;AACH,IAAA,IACI,CAAC,IAAI;AACL,QAAA,EAAE,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAC7D;AACE,QAAA,OAAO,KAAK;IAChB;AAEA,IAAA,MAAM,OAAO,GAAG,WAAW,EAAE,KAAK,EAAE,OAAO;AAE3C;;;;;;AAMG;AACH,IAAA,IACI,EAAE,OAAO,YAAY,WAAW,CAAC;AACjC,QAAA,EAAE,OAAO,YAAY,UAAU,CAAC,EAClC;AACE,QAAA,OAAO,KAAK;IAChB;AAEA,IAAA,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,WAAY,CAAC,KAAM,CAAC,QAAQ,EAAE;IAEtE,QACI,aAAa,EAAE;AACf;;;AAGG;AACH,SAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC;AACxB,aAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC;AACtB,gBAAA,oBAAoB,CAAC,SAAS,CAAC,CAAC,CAAC;AACzC,SAAC,IAAI,KAAK,WAAW,IAAI,CAAC,iBAAiB,CAAC;AAC5C;;;AAGG;AACH,QAAA,CAAC,QAAQ;AACT,QAAA,CAAC,WAAW;AACZ,QAAA,UAAU,KAAK,QAAQ;AACvB,QAAA,OAAO,KAAK,CAAC;AACb,QAAA,IAAI,KAAK,SAAS;AAClB,QAAA,CAAC,UAAU,CAAC,OAAO,CAAC;AAE5B;;;;"}
@@ -13,6 +13,7 @@ import { sampleDelta } from '../../NativeAnimationExtended.mjs';
13
13
  import { cubicBezierAsString } from '../easing/cubic-bezier.mjs';
14
14
  import { supportedWaapiEasing } from '../easing/supported.mjs';
15
15
  import { supportsWaapi } from '../supports/waapi.mjs';
16
+ import { needsMixer } from '../utils/needs-mixer.mjs';
16
17
  import { supportsLinearEasing } from '../../../utils/supports/linear-easing.mjs';
17
18
  import { transformGroups } from './groups.mjs';
18
19
 
@@ -40,18 +41,21 @@ const churnWindow = 100;
40
41
  * Named easings that are the same cubic-bezier in JS and CSS.
41
42
  */
42
43
  const isNativeEasing = (ease) => /^(linear|ease(In|Out|InOut))$/.test(ease);
44
+ /**
45
+ * Whether two eased progresses match. False if either is NaN.
46
+ */
47
+ const isNear = (a, b) => Math.abs(a - b) <= easingTolerance;
43
48
  const byTime = (a, b) => a - b;
44
49
  /**
45
50
  * n + 1 evenly spaced timestamps, from one timestamp to another.
46
51
  */
47
- const spread = (from, to, n) => {
48
- const result = [];
49
- for (let i = 0; i <= n; i++)
50
- result.push(mixNumber(from, to, i / n));
51
- return result;
52
- };
52
+ const spread = (from, to, n) => defaultOffset(Array(n + 1)).map((p) => mixNumber(from, to, p));
53
53
  const getOwner = (options) => options.motionValue.owner;
54
54
  const getGroup = (element) => transformGroups.get(element);
55
+ /**
56
+ * Whether an animation has ended, so can leave its group.
57
+ */
58
+ const hasEnded = ({ state }) => state === "idle" || state === "finished";
55
59
  const read = (owner, key) => owner.latestValues ? owner.latestValues[key] : owner.getValue(key)?.get();
56
60
  /**
57
61
  * Whether this animation should join its element's transform group.
@@ -90,7 +94,12 @@ function canAccelerateTransform(options) {
90
94
  /**
91
95
  * Layout animations write transform every frame.
92
96
  */
93
- !owner.projection?.isProjecting());
97
+ !owner.projection?.isProjecting() &&
98
+ /**
99
+ * A mixer that blends these values makes them every frame. It's
100
+ * asked last, as it's user code.
101
+ */
102
+ !needsMixer(options));
94
103
  }
95
104
  class TransformAnimation extends JSAnimation {
96
105
  constructor(options) {
@@ -447,9 +456,8 @@ function createGroup(owner) {
447
456
  let shared;
448
457
  let progressAt;
449
458
  for (const track of moving) {
450
- const values = at.map((t) => track.numberAt(t));
451
- const [first] = values;
452
- const changes = values.map((value) => value - first);
459
+ const first = track.numberAt(from);
460
+ const changes = at.map((t) => track.numberAt(t) - first);
453
461
  const end = changes[changes.length - 1];
454
462
  /**
455
463
  * A value that ends only a tiny way from where it started, as
@@ -463,25 +471,20 @@ function createGroup(owner) {
463
471
  : end;
464
472
  const progress = changes.map((change) => range ? change / range : change);
465
473
  /**
466
- * A value that doesn't change, like one still in its delay,
467
- * fits any easing. One that changes but ends where it started
468
- * fits none.
474
+ * The first value that moves sets the easing, and every other
475
+ * one must follow it. A value that doesn't change, like one
476
+ * still in its delay, fits any easing. One that changes but
477
+ * ends where it started fits none.
469
478
  */
470
- if (!range) {
471
- if (progress.some((p) => !(Math.abs(p) <= easingTolerance))) {
472
- return;
473
- }
474
- }
475
- else if (!shared) {
479
+ if (range && !shared) {
476
480
  shared = progress;
477
481
  progressAt = (t) => (track.numberAt(t) - first) / range;
478
482
  }
479
- else if (progress.some((p, i) => !(Math.abs(p - shared[i]) <= easingTolerance))) {
483
+ else if (progress.some((p, i) => !isNear(p, range && shared[i]))) {
480
484
  return;
481
485
  }
482
486
  }
483
- if (!shared ||
484
- shared.every((p, i) => Math.abs(p - position(at[i])) <= easingTolerance)) {
487
+ if (!shared || shared.every((p, i) => isNear(p, position(at[i])))) {
485
488
  return "linear";
486
489
  }
487
490
  /**
@@ -568,7 +571,7 @@ function createGroup(owner) {
568
571
  /**
569
572
  * A WAAPI animation of the composed transform between two timestamps.
570
573
  */
571
- const run = (moving, from, to, options = { fill: "both" }, settled, nativeEasing) => {
574
+ const run = (moving, from, to, nativeEasing, options = { fill: "both" }, settled) => {
572
575
  const bounds = moving.flatMap((track) => track.boundaries(from, to));
573
576
  const easing = nativeEasing || getEasing(moving, from, to, bounds);
574
577
  const times = easing ? [from, to] : sample(moving, from, to, bounds);
@@ -654,9 +657,7 @@ function createGroup(owner) {
654
657
  if (byKey.has(key))
655
658
  return true;
656
659
  const value = (statics[key] = read(owner, key));
657
- return (value !== undefined &&
658
- parseFloat(value) !==
659
- (key.startsWith("scale") ? 1 : 0));
660
+ return value !== undefined && !isDefaultTransform(key, value);
660
661
  });
661
662
  stop(false);
662
663
  /**
@@ -667,7 +668,7 @@ function createGroup(owner) {
667
668
  try {
668
669
  if (tween && tween[1] > now) {
669
670
  const [from, to, easing] = tween;
670
- add(run(moving, from, to, undefined, undefined, easing), from - now, to - from);
671
+ add(run(moving, from, to, easing), from - now, to - from);
671
672
  }
672
673
  else if (end > now) {
673
674
  add(run(moving, now, end), 0, end - now);
@@ -684,7 +685,7 @@ function createGroup(owner) {
684
685
  * seamlessly, and start it part way through.
685
686
  */
686
687
  const from = cycleStart + Math.floor((end - cycleStart) / cycle) * cycle;
687
- add(run(looping, from, from + cycle, {
688
+ add(run(looping, from, from + cycle, undefined, {
688
689
  iterations: Infinity,
689
690
  iterationStart: (end - from) / cycle,
690
691
  /**
@@ -823,10 +824,7 @@ function createGroup(owner) {
823
824
  isScheduled = false;
824
825
  if (isEnded)
825
826
  return;
826
- tracks.forEach(({ state }, track) => {
827
- if (state === "idle" || state === "finished")
828
- tracks.delete(track);
829
- });
827
+ tracks.forEach((track) => hasEnded(track) && tracks.delete(track));
830
828
  if (end())
831
829
  return;
832
830
  for (const track of tracks) {
@@ -886,9 +884,7 @@ function createGroup(owner) {
886
884
  * Only drop the stopped animation. Others can be idle because
887
885
  * they're part way through play(), and are about to run.
888
886
  */
889
- const { state } = track;
890
- if (state === "idle" || state === "finished")
891
- tracks.delete(track);
887
+ hasEnded(track) && tracks.delete(track);
892
888
  end() || group.schedule(true);
893
889
  },
894
890
  /**