motion-dom 14.11.1 → 14.13.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.
- package/dist/cjs/index.js +296 -22
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/JSAnimation.mjs +12 -2
- package/dist/es/animation/JSAnimation.mjs.map +1 -1
- package/dist/es/animation/generators/spring.mjs +12 -12
- package/dist/es/animation/generators/spring.mjs.map +1 -1
- package/dist/es/gestures/pinch/index.mjs +2 -3
- package/dist/es/gestures/pinch/index.mjs.map +1 -1
- package/dist/es/index.mjs +1 -1
- package/dist/es/projection/animation/layout-velocity.mjs +28 -0
- package/dist/es/projection/animation/layout-velocity.mjs.map +1 -0
- package/dist/es/projection/node/create-projection-node.mjs +251 -7
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/index.d.ts +78 -6
- package/dist/motion-dom.dev.js +296 -22
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-pinch.js +1 -1
- package/dist/size-rollup-pinch.js.map +1 -1
- package/package.json +2 -2
|
@@ -46,8 +46,18 @@ class JSAnimation extends WithPromise {
|
|
|
46
46
|
*/
|
|
47
47
|
this.stop = () => {
|
|
48
48
|
const { motionValue } = this.options;
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
const now = time.now();
|
|
50
|
+
if (motionValue && motionValue.updatedAt !== now) {
|
|
51
|
+
/**
|
|
52
|
+
* Catch the value up to now, but measure its velocity from the
|
|
53
|
+
* previous frame: marking it as updated now keeps the value's
|
|
54
|
+
* previous-frame sample. This tick is usually less than a frame
|
|
55
|
+
* after the last, and the animation's time is rounded to whole
|
|
56
|
+
* milliseconds, so measured from the last frame alone the
|
|
57
|
+
* velocity an interrupting animation inherits could read as 0,
|
|
58
|
+
* or a multiple of the real one.
|
|
59
|
+
*/
|
|
60
|
+
this.tick((motionValue.updatedAt = now));
|
|
51
61
|
}
|
|
52
62
|
this.isStopped = true;
|
|
53
63
|
if (this.state === "idle")
|
|
@@ -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 /**\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 /**\n * Seeking out of \"finished\" leaves the animation paused, so play()\n * won't renew finished. Renew it here.\n */\n if (this.state === \"finished\") this.updateFinished()\n\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,K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,GAAA;AACF,QAAA,IAAI,CAAC,QAAQ,GAAG,IAAI;AACpB,QAAA,IAAI,CAAC,SAAS,GAAG,CAAC;AAClB,QAAA,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACZ,IAAI,CAAC,QAAQ,EAAE;AACf,QAAA,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI;IAC7B;IAEQ,QAAQ,GAAA;AACZ,QAAA,IAAI,CAAC,KAAK,GAAG,MAAM;AACnB,QAAA,IAAI,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 /**\n * Seeking out of \"finished\" leaves the animation paused, so play()\n * won't renew finished. Renew it here.\n */\n if (this.state === \"finished\") this.updateFinished()\n\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 const now = time.now()\n if (motionValue && motionValue.updatedAt !== now) {\n /**\n * Catch the value up to now, but measure its velocity from the\n * previous frame: marking it as updated now keeps the value's\n * previous-frame sample. This tick is usually less than a frame\n * after the last, and the animation's time is rounded to whole\n * milliseconds, so measured from the last frame alone the\n * velocity an interrupting animation inherits could read as 0,\n * or a multiple of the real one.\n */\n this.tick((motionValue.updatedAt = 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,SA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generateLinearEasing } from '../waapi/utils/linear.mjs';
|
|
3
3
|
import { calcGeneratorDuration, maxGeneratorDuration } from './utils/calc-duration.mjs';
|
|
4
4
|
import { createGeneratorEasing } from './utils/create-generator-easing.mjs';
|
|
@@ -66,9 +66,9 @@ function approximateRoot(envelope, derivative, initialGuess) {
|
|
|
66
66
|
*/
|
|
67
67
|
const safeMin = 0.001;
|
|
68
68
|
/**
|
|
69
|
-
* Assumes zero initial velocity and the default mass:
|
|
70
|
-
*
|
|
71
|
-
* NaN physics when the root search doesn't converge.
|
|
69
|
+
* Assumes zero initial velocity and the default mass: duration springs start
|
|
70
|
+
* from rest so they end exactly at their duration. Only resolves without
|
|
71
|
+
* valid physics. Returns NaN physics when the root search doesn't converge.
|
|
72
72
|
*/
|
|
73
73
|
function findSpring({ duration = defaultDuration, bounce = defaultBounce, }) {
|
|
74
74
|
let envelope;
|
|
@@ -146,7 +146,7 @@ function resolvePhysics(value, canBeZero) {
|
|
|
146
146
|
if (isValidPhysics(value, canBeZero))
|
|
147
147
|
return value;
|
|
148
148
|
if (process.env.NODE_ENV !== "production") {
|
|
149
|
-
warning(value === undefined, "Spring stiffness and mass must be positive, damping 0 or greater", "spring-invalid-physics");
|
|
149
|
+
warning(value === undefined || value === "auto", "Spring stiffness and mass must be positive, damping 0 or greater", "spring-invalid-physics");
|
|
150
150
|
}
|
|
151
151
|
return undefined;
|
|
152
152
|
}
|
|
@@ -214,11 +214,12 @@ function springGenerator(optionsOrVisualDuration = defaultVisualDuration, bounce
|
|
|
214
214
|
const state = { done: false, value: origin };
|
|
215
215
|
const { stiffness, damping, mass, duration, isResolvedFromDuration, isTimeDefined, } = getSpringOptions({ ...options });
|
|
216
216
|
/**
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
217
|
+
* A duration spring must end exactly at its duration, and it's settled
|
|
218
|
+
* from rest by then. Inherited velocity could leave it still moving, so
|
|
219
|
+
* it starts from rest. Every other spring, visualDuration included, ends
|
|
220
|
+
* when it comes to rest, so inherits velocity as its initial condition.
|
|
220
221
|
*/
|
|
221
|
-
const inheritVelocity = (velocity) =>
|
|
222
|
+
const inheritVelocity = (velocity) => isResolvedFromDuration ? 0 : -millisecondsToSeconds(velocity);
|
|
222
223
|
const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass));
|
|
223
224
|
const undampedAngularFreq = millisecondsToSeconds(Math.sqrt(stiffness / mass));
|
|
224
225
|
const decay = dampingRatio * undampedAngularFreq;
|
|
@@ -232,7 +233,7 @@ function springGenerator(optionsOrVisualDuration = defaultVisualDuration, bounce
|
|
|
232
233
|
const s = {
|
|
233
234
|
target,
|
|
234
235
|
delta: target - origin,
|
|
235
|
-
velocity: inheritVelocity(options.velocity
|
|
236
|
+
velocity: inheritVelocity(options.velocity) || 0,
|
|
236
237
|
restSpeed: 0,
|
|
237
238
|
restDelta: 0,
|
|
238
239
|
};
|
|
@@ -379,7 +380,6 @@ function springGenerator(optionsOrVisualDuration = defaultVisualDuration, bounce
|
|
|
379
380
|
const easing = generateLinearEasing((progress) => generator.next(easingDuration * progress).value, easingDuration, 30);
|
|
380
381
|
return easingDuration + "ms " + easing;
|
|
381
382
|
},
|
|
382
|
-
toTransition: () => { },
|
|
383
383
|
};
|
|
384
384
|
return generator;
|
|
385
385
|
}
|
|
@@ -393,5 +393,5 @@ const spring = /* @__PURE__ */ Object.assign(springGenerator, {
|
|
|
393
393
|
},
|
|
394
394
|
});
|
|
395
395
|
|
|
396
|
-
export { spring };
|
|
396
|
+
export { getSpringOptions, spring };
|
|
397
397
|
//# sourceMappingURL=spring.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spring.mjs","sources":["../../../../src/animation/generators/spring.ts"],"sourcesContent":["import {\n clamp,\n millisecondsToSeconds,\n secondsToMilliseconds,\n warning,\n} from \"motion-utils\"\nimport {\n AnimationState,\n KeyframeGenerator,\n SpringOptions,\n Transition,\n ValueAnimationOptions,\n} from \"../types\"\nimport { generateLinearEasing } from \"../waapi/utils/linear\"\nimport {\n calcGeneratorDuration,\n maxGeneratorDuration,\n} from \"./utils/calc-duration\"\nimport { createGeneratorEasing } from \"./utils/create-generator-easing\"\n\n// Default spring physics\nconst defaultStiffness = 100\nconst defaultDamping = 10\nconst defaultMass = 1.0\n\n// Default duration/bounce-based options\nconst defaultDuration = 800 // in ms\nconst defaultBounce = 0.3\nconst defaultVisualDuration = 0.3 // in seconds\n\n// Rest thresholds\nconst restSpeedGranular = 0.01\nconst restSpeedDefault = 2\nconst restDeltaGranular = 0.005\nconst restDeltaDefault = 0.5\n\n// Limits\nconst minDuration = 0.01 // in seconds\nconst maxDuration = 10.0 // in seconds\nconst minDamping = 0.05\n\n/**\n * Maps bounce to a damping ratio as SwiftUI does: 0 is critically damped, and\n * it approaches undamped towards 1 and infinitely overdamped towards -1. Both\n * ends are limited so the spring still moves and settles.\n */\nconst bounceToDampingRatio = (bounce: number) =>\n bounce < 0\n ? 1 / Math.max(1 + bounce, minDamping)\n : Math.max(1 - bounce, minDamping)\n\n/**\n * Scales an overdamped spring's undamped frequency so that, at its defining\n * time, it has as far left to go as the critically damped spring that's\n * criticalFreqTime radians in by then. A negative bounce then changes the\n * shape of the curve, not when it arrives. 1 at a damping ratio of 1, so\n * there's no jump at a bounce of 0.\n *\n * Solved by Newton on the remaining distance (times fast - slow), which is\n * convex from criticalFreqTime onwards. criticalFreqTime is always below the\n * answer, so it converges from below without overshooting.\n */\nfunction overdampedFreqScale(dampingRatio: number, criticalFreqTime: number) {\n if (!(dampingRatio > 1)) return 1\n\n const root = Math.sqrt(dampingRatio * dampingRatio - 1)\n const slow = dampingRatio - root\n const fast = dampingRatio + root\n const target =\n 2 * root * Math.exp(-criticalFreqTime) * (1 + criticalFreqTime)\n\n return (\n approximateRoot(\n (freqTime) =>\n fast * Math.exp(-slow * freqTime) -\n slow * Math.exp(-fast * freqTime) -\n target,\n (freqTime) =>\n Math.exp(-fast * freqTime) - Math.exp(-slow * freqTime),\n criticalFreqTime\n ) / criticalFreqTime\n )\n}\n\nfunction calcAngularFreq(undampedFreq: number, dampingRatio: number) {\n return undampedFreq * Math.sqrt(1 - dampingRatio * dampingRatio)\n}\n\nconst rootIterations = 12\nfunction approximateRoot(\n envelope: (num: number) => number,\n derivative: (num: number) => number,\n initialGuess: number\n): number {\n let result = initialGuess\n for (let i = 1; i < rootIterations; i++) {\n result = result - envelope(result) / derivative(result)\n }\n return result\n}\n\n/**\n * This is ported from the Framer implementation of duration-based spring resolution.\n */\nconst safeMin = 0.001\n\n/**\n * Assumes zero initial velocity and the default mass: time-defined springs\n * ignore inherited velocity and only resolve without valid physics. Returns\n * NaN physics when the root search doesn't converge.\n */\nfunction findSpring({\n duration = defaultDuration,\n bounce = defaultBounce,\n}: SpringOptions) {\n let envelope: (num: number) => number\n let derivative: (num: number) => number\n\n process.env.NODE_ENV !== \"production\" &&\n warning(\n duration <= secondsToMilliseconds(maxDuration),\n \"Spring duration must be 10 seconds or less\",\n \"spring-duration-limit\"\n )\n\n const dampingRatio = bounceToDampingRatio(bounce)\n\n duration = clamp(minDuration, maxDuration, millisecondsToSeconds(duration))\n\n if (dampingRatio < 1) {\n /**\n * Underdamped spring\n */\n envelope = (undampedFreq) => {\n const exponentialDecay = undampedFreq * dampingRatio\n const delta = exponentialDecay * duration\n const b = calcAngularFreq(undampedFreq, dampingRatio)\n const c = Math.exp(-delta)\n return safeMin - (exponentialDecay / b) * c\n }\n\n derivative = (undampedFreq) => {\n const exponentialDecay = undampedFreq * dampingRatio\n const delta = exponentialDecay * duration\n const e =\n dampingRatio *\n dampingRatio *\n undampedFreq *\n undampedFreq *\n duration\n const f = Math.exp(-delta)\n const g = calcAngularFreq(undampedFreq * undampedFreq, dampingRatio)\n const factor = -envelope(undampedFreq) + safeMin > 0 ? -1 : 1\n return (factor * -e * f) / g\n }\n } else {\n /**\n * Critically-damped spring. Overdamped springs reuse this root,\n * scaled below.\n */\n envelope = (undampedFreq) => {\n const a = Math.exp(-undampedFreq * duration)\n const b = undampedFreq * duration + 1\n return -safeMin + a * b\n }\n\n derivative = (undampedFreq) => {\n const a = Math.exp(-undampedFreq * duration)\n const b = -undampedFreq * (duration * duration)\n return a * b\n }\n }\n\n const initialGuess = 5 / duration\n const criticalFreq = approximateRoot(envelope, derivative, initialGuess)\n const undampedFreq =\n criticalFreq *\n overdampedFreqScale(dampingRatio, criticalFreq * duration)\n const stiffness = undampedFreq * undampedFreq\n\n return {\n stiffness,\n damping: dampingRatio * 2 * Math.sqrt(stiffness),\n duration: secondsToMilliseconds(duration),\n }\n}\n\n/**\n * Spring physics must be finite. stiffness and mass are also divisors so must\n * be positive, whereas a damping of 0 is a valid, perpetually oscillating\n * spring. Relational rather than Number.isFinite so numeric strings still\n * coerce.\n */\nconst isValidPhysics = (value: number | undefined, canBeZero?: boolean) =>\n (canBeZero ? value! >= 0 : value! > 0) && value! < Infinity\n\n/**\n * Returns value if it's usable spring physics, otherwise undefined so callers\n * fall back to the default. An explicit `undefined`, e.g. from a forwarded\n * optional prop, must fall back too. Invalid physics would otherwise resolve\n * to NaN spring values that never report done.\n */\nfunction resolvePhysics(value: number | undefined, canBeZero?: boolean) {\n if (isValidPhysics(value, canBeZero)) return value\n\n if (process.env.NODE_ENV !== \"production\") {\n warning(\n value === undefined,\n \"Spring stiffness and mass must be positive, damping 0 or greater\",\n \"spring-invalid-physics\"\n )\n }\n\n return undefined\n}\n\nfunction getSpringOptions(options: SpringOptions) {\n /**\n * Resolve physics before choosing between physics- and duration-based\n * resolution, so an invalid stiffness doesn't also silently discard a\n * valid duration/bounce.\n */\n const validStiffness = resolvePhysics(options.stiffness)\n const validDamping = resolvePhysics(options.damping, true)\n const validMass = resolvePhysics(options.mass)\n\n const springOptions = {\n ...options,\n stiffness: validStiffness ?? defaultStiffness,\n damping: validDamping ?? defaultDamping,\n mass: validMass ?? defaultMass,\n isResolvedFromDuration: false,\n // stiffness/damping/mass overrides duration/bounce\n isTimeDefined:\n (validStiffness ?? validDamping ?? validMass) === undefined &&\n (options.duration !== undefined || options.bounce !== undefined),\n }\n\n if (springOptions.isTimeDefined) {\n if (options.visualDuration) {\n const dampingRatio = bounceToDampingRatio(options.bounce || 0)\n const root =\n ((2 * Math.PI) / (options.visualDuration * 1.2)) *\n overdampedFreqScale(dampingRatio, (2 * Math.PI) / 1.2)\n springOptions.stiffness = root * root\n springOptions.damping =\n 2 * dampingRatio * Math.sqrt(springOptions.stiffness)\n } else {\n Object.assign(springOptions, findSpring(springOptions))\n springOptions.isResolvedFromDuration = true\n }\n\n /**\n * Time options can degenerate: a NaN bounce gives a NaN damping, an\n * infinite visualDuration a 0 stiffness, and findSpring NaN for both\n * when it doesn't converge. Replace the two together, so the\n * relationship duration resolution establishes between them is never\n * left half-overwritten.\n */\n if (\n !isValidPhysics(springOptions.stiffness) ||\n !isValidPhysics(springOptions.damping, true)\n ) {\n springOptions.stiffness = defaultStiffness\n springOptions.damping = defaultDamping\n }\n }\n\n return springOptions\n}\n\nfunction springGenerator(\n optionsOrVisualDuration:\n | ValueAnimationOptions<number>\n | number = defaultVisualDuration,\n bounce = defaultBounce\n): KeyframeGenerator<number> {\n const options =\n typeof optionsOrVisualDuration !== \"object\"\n ? ({\n visualDuration: optionsOrVisualDuration,\n keyframes: [0, 1],\n bounce,\n } as ValueAnimationOptions<number>)\n : optionsOrVisualDuration\n\n const origin = options.keyframes[0]\n const target = options.keyframes[options.keyframes.length - 1]\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<number> = { done: false, value: origin }\n\n const {\n stiffness,\n damping,\n mass,\n duration,\n isResolvedFromDuration,\n isTimeDefined,\n } = getSpringOptions({ ...options })\n\n /**\n * Time-defined springs ignore inherited velocity. Velocity from\n * interrupted animations causes massive oscillation on small-range\n * animations.\n */\n const inheritVelocity = (velocity: number) =>\n isTimeDefined ? 0 : -millisecondsToSeconds(velocity)\n\n const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass))\n const undampedAngularFreq = millisecondsToSeconds(\n Math.sqrt(stiffness / mass)\n )\n const decay = dampingRatio * undampedAngularFreq\n\n /**\n * Everything that changes when the spring is retargeted: written by\n * retarget() and update(), read by the resolvers. Grouped on one object,\n * like the coefficients (c) below. Writing doubles to object fields\n * measured marginally faster than to captured let variables in optimised\n * code; neither allocates, so this is a grouping choice, not a GC one.\n */\n const s = {\n target,\n delta: target - origin,\n velocity: inheritVelocity(options.velocity || 0) || 0,\n restSpeed: 0,\n restDelta: 0,\n }\n\n /**\n * If we're working on a granular scale, use smaller defaults for determining\n * when the spring is finished.\n *\n * These defaults have been selected empirically based on what strikes a good\n * ratio between feeling good and finishing as soon as changes are imperceptible.\n */\n const setRestThresholds = () => {\n const isGranularScale = Math.abs(s.delta) < 5\n s.restSpeed =\n options.restSpeed ||\n (isGranularScale ? restSpeedGranular : restSpeedDefault)\n s.restDelta =\n options.restDelta ||\n (isGranularScale ? restDeltaGranular : restDeltaDefault)\n }\n setRestThresholds()\n\n let resolveSpring: (v: number) => number\n let resolveVelocity: (t: number) => number\n\n /**\n * Derives the coefficients that depend on origin, target and initial\n * velocity. Called once now and again whenever the spring is retargeted.\n */\n let update: VoidFunction\n\n if (dampingRatio < 1) {\n const angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio)\n\n /**\n * A is the position coefficient, sinC/cosC the coefficients of the\n * analytical derivative (px/ms). The exp/sin/cos terms depend only\n * on t, so they're memoized by t independently of the target: a\n * spring retargeted every frame samples the same t each frame and\n * skips the transcendentals entirely.\n */\n const c = { A: 0, sinC: 0, cosC: 0, t: -1, env: 0, sin: 0, cos: 0 }\n\n update = () => {\n c.A = (s.velocity + decay * s.delta) / angularFreq\n c.sinC = decay * c.A + s.delta * angularFreq\n c.cosC = decay * s.delta - c.A * angularFreq\n }\n\n const sample = (t: number) => {\n if (t !== c.t) {\n c.t = t\n c.env = Math.exp(-decay * t)\n c.sin = Math.sin(angularFreq * t)\n c.cos = Math.cos(angularFreq * t)\n }\n }\n\n // Underdamped spring\n resolveSpring = (t: number) => {\n sample(t)\n return s.target - c.env * (c.A * c.sin + s.delta * c.cos)\n }\n\n resolveVelocity = (t: number) => {\n sample(t)\n return c.env * (c.sinC * c.sin + c.cosC * c.cos)\n }\n } else if (dampingRatio === 1) {\n // Critically damped spring\n resolveSpring = (t: number) =>\n s.target -\n Math.exp(-undampedAngularFreq * t) *\n (s.delta + (s.velocity + undampedAngularFreq * s.delta) * t)\n\n // Analytical derivative of critically damped spring (px/ms)\n const c = { C: 0 }\n update = () => {\n c.C = s.velocity + undampedAngularFreq * s.delta\n }\n resolveVelocity = (t: number) =>\n Math.exp(-undampedAngularFreq * t) *\n (undampedAngularFreq * c.C * t - s.velocity)\n } else {\n /**\n * Overdamped spring: the sum of a slow and a fast decaying\n * exponential, so no term can overflow however heavily it's damped.\n */\n const dampedAngularFreq =\n undampedAngularFreq * Math.sqrt(dampingRatio * dampingRatio - 1)\n const slow = decay - dampedAngularFreq\n const fast = decay + dampedAngularFreq\n\n /**\n * Physics-defined springs keep a non-physical limit: once\n * dampedAngularFreq * t passes 300, both terms decay at the damping\n * rate. Heavily overdamped drag springs (dragElastic: 0,\n * dragTransition) rely on this to settle almost at once rather than\n * creep at stiffness / damping. It only applies when reached within\n * 300ms (a dampedAngularFreq of 1 rad/ms), so it reads as a stiff\n * spring snapping into place: any later and it cuts off a slow spring\n * that's visibly still moving (#1207). Negative bounce needs the\n * exact curve, so time-defined springs are exempt.\n */\n const limit =\n dampedAngularFreq < 1 || isTimeDefined\n ? Infinity\n : 300 / dampedAngularFreq\n const decayAt = (rate: number, t: number) =>\n Math.exp(t > limit ? (decay - rate) * limit - decay * t : -rate * t)\n\n const c = { S: 0, F: 0 }\n update = () => {\n const P = (s.velocity + decay * s.delta) / dampedAngularFreq\n c.S = (s.delta + P) / 2\n c.F = (s.delta - P) / 2\n }\n\n resolveSpring = (t: number) =>\n s.target - c.S * decayAt(slow, t) - c.F * decayAt(fast, t)\n\n // Analytical derivative of overdamped spring (px/ms)\n resolveVelocity = (t: number) =>\n slow * c.S * decayAt(slow, t) + fast * c.F * decayAt(fast, t)\n }\n\n update()\n\n const calculatedDuration = isResolvedFromDuration ? duration || null : null\n\n const generator = {\n calculatedDuration,\n /**\n * Aim the spring at a new target from its current position and\n * velocity, reusing the resolved physics and closures.\n */\n retarget: (keyframes: number[], newVelocity: number) => {\n s.target = keyframes[keyframes.length - 1]\n s.delta = s.target - keyframes[0]\n s.velocity = inheritVelocity(newVelocity)\n // Default thresholds depend on the scale of the new delta\n if (!(options.restSpeed && options.restDelta)) setRestThresholds()\n // Invalidate any duration lazily cached by JSAnimation\n generator.calculatedDuration = calculatedDuration\n state.done = false\n update()\n },\n velocity: (t: number) => secondsToMilliseconds(resolveVelocity(t)),\n next: (t: number) => {\n const current = resolveSpring(t)\n\n if (!isResolvedFromDuration) {\n const currentVelocity = secondsToMilliseconds(\n resolveVelocity(t)\n )\n state.done =\n Math.abs(currentVelocity) <= s.restSpeed &&\n Math.abs(s.target - current) <= s.restDelta\n } else {\n state.done = t >= duration!\n }\n\n state.value = state.done ? s.target : current\n\n return state\n },\n toString: () => {\n const easingDuration = Math.min(\n calcGeneratorDuration(generator),\n maxGeneratorDuration\n )\n\n const easing = generateLinearEasing(\n (progress: number) =>\n generator.next(easingDuration * progress).value,\n easingDuration,\n 30\n )\n\n return easingDuration + \"ms \" + easing\n },\n toTransition: () => {},\n }\n\n return generator\n}\n\nconst spring = /* @__PURE__ */ Object.assign(springGenerator, {\n applyToOptions: (options: Transition) => {\n const generatorOptions = createGeneratorEasing(\n options as any,\n 100,\n springGenerator\n )\n\n options.ease = generatorOptions.ease\n options.duration = secondsToMilliseconds(generatorOptions.duration)\n options.type = \"keyframes\"\n return options\n },\n})\n\nexport { spring }\n"],"names":[],"mappings":";;;;;AAoBA;AACA,MAAM,gBAAgB,GAAG,GAAG;AAC5B,MAAM,cAAc,GAAG,EAAE;AACzB,MAAM,WAAW,GAAG,GAAG;AAEvB;AACA,MAAM,eAAe,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AI;QACpC,MAAM,gBAAgB,GAAG,qBAAqB,CAC1C,OAAc,EACd,GAAG,EACH,eAAe,CAClB;AAED,QAAA,OAAO,CAAC,IAAI,GAAG,gBAAgB,CAAC,IAAI;QACpC,OAAO,CAAC,QAAQ,GAAG,qBAAqB,CAAC,gBAAgB,CAAC,QAAQ,CAAC;AACnE,QAAA,OAAO,CAAC,IAAI,GAAG,WAAW;AAC1B,QAAA,OAAO,OAAO;IAClB,CAAC;AACJ,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"spring.mjs","sources":["../../../../src/animation/generators/spring.ts"],"sourcesContent":["import {\n clamp,\n millisecondsToSeconds,\n secondsToMilliseconds,\n warning,\n} from \"motion-utils\"\nimport {\n AnimationState,\n KeyframeGenerator,\n SpringOptions,\n Transition,\n ValueAnimationOptions,\n} from \"../types\"\nimport { generateLinearEasing } from \"../waapi/utils/linear\"\nimport {\n calcGeneratorDuration,\n maxGeneratorDuration,\n} from \"./utils/calc-duration\"\nimport { createGeneratorEasing } from \"./utils/create-generator-easing\"\n\n// Default spring physics\nconst defaultStiffness = 100\nconst defaultDamping = 10\nconst defaultMass = 1.0\n\n// Default duration/bounce-based options\nconst defaultDuration = 800 // in ms\nconst defaultBounce = 0.3\nconst defaultVisualDuration = 0.3 // in seconds\n\n// Rest thresholds\nconst restSpeedGranular = 0.01\nconst restSpeedDefault = 2\nconst restDeltaGranular = 0.005\nconst restDeltaDefault = 0.5\n\n// Limits\nconst minDuration = 0.01 // in seconds\nconst maxDuration = 10.0 // in seconds\nconst minDamping = 0.05\n\n/**\n * Maps bounce to a damping ratio as SwiftUI does: 0 is critically damped, and\n * it approaches undamped towards 1 and infinitely overdamped towards -1. Both\n * ends are limited so the spring still moves and settles.\n */\nconst bounceToDampingRatio = (bounce: number) =>\n bounce < 0\n ? 1 / Math.max(1 + bounce, minDamping)\n : Math.max(1 - bounce, minDamping)\n\n/**\n * Scales an overdamped spring's undamped frequency so that, at its defining\n * time, it has as far left to go as the critically damped spring that's\n * criticalFreqTime radians in by then. A negative bounce then changes the\n * shape of the curve, not when it arrives. 1 at a damping ratio of 1, so\n * there's no jump at a bounce of 0.\n *\n * Solved by Newton on the remaining distance (times fast - slow), which is\n * convex from criticalFreqTime onwards. criticalFreqTime is always below the\n * answer, so it converges from below without overshooting.\n */\nfunction overdampedFreqScale(dampingRatio: number, criticalFreqTime: number) {\n if (!(dampingRatio > 1)) return 1\n\n const root = Math.sqrt(dampingRatio * dampingRatio - 1)\n const slow = dampingRatio - root\n const fast = dampingRatio + root\n const target =\n 2 * root * Math.exp(-criticalFreqTime) * (1 + criticalFreqTime)\n\n return (\n approximateRoot(\n (freqTime) =>\n fast * Math.exp(-slow * freqTime) -\n slow * Math.exp(-fast * freqTime) -\n target,\n (freqTime) =>\n Math.exp(-fast * freqTime) - Math.exp(-slow * freqTime),\n criticalFreqTime\n ) / criticalFreqTime\n )\n}\n\nfunction calcAngularFreq(undampedFreq: number, dampingRatio: number) {\n return undampedFreq * Math.sqrt(1 - dampingRatio * dampingRatio)\n}\n\nconst rootIterations = 12\nfunction approximateRoot(\n envelope: (num: number) => number,\n derivative: (num: number) => number,\n initialGuess: number\n): number {\n let result = initialGuess\n for (let i = 1; i < rootIterations; i++) {\n result = result - envelope(result) / derivative(result)\n }\n return result\n}\n\n/**\n * This is ported from the Framer implementation of duration-based spring resolution.\n */\nconst safeMin = 0.001\n\n/**\n * Assumes zero initial velocity and the default mass: duration springs start\n * from rest so they end exactly at their duration. Only resolves without\n * valid physics. Returns NaN physics when the root search doesn't converge.\n */\nfunction findSpring({\n duration = defaultDuration,\n bounce = defaultBounce,\n}: SpringOptions) {\n let envelope: (num: number) => number\n let derivative: (num: number) => number\n\n process.env.NODE_ENV !== \"production\" &&\n warning(\n duration <= secondsToMilliseconds(maxDuration),\n \"Spring duration must be 10 seconds or less\",\n \"spring-duration-limit\"\n )\n\n const dampingRatio = bounceToDampingRatio(bounce)\n\n duration = clamp(minDuration, maxDuration, millisecondsToSeconds(duration))\n\n if (dampingRatio < 1) {\n /**\n * Underdamped spring\n */\n envelope = (undampedFreq) => {\n const exponentialDecay = undampedFreq * dampingRatio\n const delta = exponentialDecay * duration\n const b = calcAngularFreq(undampedFreq, dampingRatio)\n const c = Math.exp(-delta)\n return safeMin - (exponentialDecay / b) * c\n }\n\n derivative = (undampedFreq) => {\n const exponentialDecay = undampedFreq * dampingRatio\n const delta = exponentialDecay * duration\n const e =\n dampingRatio *\n dampingRatio *\n undampedFreq *\n undampedFreq *\n duration\n const f = Math.exp(-delta)\n const g = calcAngularFreq(undampedFreq * undampedFreq, dampingRatio)\n const factor = -envelope(undampedFreq) + safeMin > 0 ? -1 : 1\n return (factor * -e * f) / g\n }\n } else {\n /**\n * Critically-damped spring. Overdamped springs reuse this root,\n * scaled below.\n */\n envelope = (undampedFreq) => {\n const a = Math.exp(-undampedFreq * duration)\n const b = undampedFreq * duration + 1\n return -safeMin + a * b\n }\n\n derivative = (undampedFreq) => {\n const a = Math.exp(-undampedFreq * duration)\n const b = -undampedFreq * (duration * duration)\n return a * b\n }\n }\n\n const initialGuess = 5 / duration\n const criticalFreq = approximateRoot(envelope, derivative, initialGuess)\n const undampedFreq =\n criticalFreq *\n overdampedFreqScale(dampingRatio, criticalFreq * duration)\n const stiffness = undampedFreq * undampedFreq\n\n return {\n stiffness,\n damping: dampingRatio * 2 * Math.sqrt(stiffness),\n duration: secondsToMilliseconds(duration),\n }\n}\n\n/**\n * Spring physics must be finite. stiffness and mass are also divisors so must\n * be positive, whereas a damping of 0 is a valid, perpetually oscillating\n * spring. Relational rather than Number.isFinite so numeric strings still\n * coerce.\n */\nconst isValidPhysics = (value: number | undefined, canBeZero?: boolean) =>\n (canBeZero ? value! >= 0 : value! > 0) && value! < Infinity\n\n/**\n * Returns value if it's usable spring physics, otherwise undefined so callers\n * fall back to the default. An explicit `undefined`, e.g. from a forwarded\n * optional prop, must fall back too. Invalid physics would otherwise resolve\n * to NaN spring values that never report done.\n */\nfunction resolvePhysics(value: number | undefined, canBeZero?: boolean) {\n if (isValidPhysics(value, canBeZero)) return value\n\n if (process.env.NODE_ENV !== \"production\") {\n warning(\n value === undefined || (value as unknown) === \"auto\",\n \"Spring stiffness and mass must be positive, damping 0 or greater\",\n \"spring-invalid-physics\"\n )\n }\n\n return undefined\n}\n\nexport function getSpringOptions(options: SpringOptions) {\n /**\n * Resolve physics before choosing between physics- and duration-based\n * resolution, so an invalid stiffness doesn't also silently discard a\n * valid duration/bounce.\n */\n const validStiffness = resolvePhysics(options.stiffness)\n const validDamping = resolvePhysics(options.damping, true)\n const validMass = resolvePhysics(options.mass as number)\n\n const springOptions = {\n ...options,\n stiffness: validStiffness ?? defaultStiffness,\n damping: validDamping ?? defaultDamping,\n mass: validMass ?? defaultMass,\n isResolvedFromDuration: false,\n // stiffness/damping/mass overrides duration/bounce\n isTimeDefined:\n (validStiffness ?? validDamping ?? validMass) === undefined &&\n (options.duration !== undefined || options.bounce !== undefined),\n }\n\n if (springOptions.isTimeDefined) {\n if (options.visualDuration) {\n const dampingRatio = bounceToDampingRatio(options.bounce || 0)\n const root =\n ((2 * Math.PI) / (options.visualDuration * 1.2)) *\n overdampedFreqScale(dampingRatio, (2 * Math.PI) / 1.2)\n springOptions.stiffness = root * root\n springOptions.damping =\n 2 * dampingRatio * Math.sqrt(springOptions.stiffness)\n } else {\n Object.assign(springOptions, findSpring(springOptions))\n springOptions.isResolvedFromDuration = true\n }\n\n /**\n * Time options can degenerate: a NaN bounce gives a NaN damping, an\n * infinite visualDuration a 0 stiffness, and findSpring NaN for both\n * when it doesn't converge. Replace the two together, so the\n * relationship duration resolution establishes between them is never\n * left half-overwritten.\n */\n if (\n !isValidPhysics(springOptions.stiffness) ||\n !isValidPhysics(springOptions.damping, true)\n ) {\n springOptions.stiffness = defaultStiffness\n springOptions.damping = defaultDamping\n }\n }\n\n return springOptions\n}\n\nfunction springGenerator(\n optionsOrVisualDuration:\n | ValueAnimationOptions<number>\n | number = defaultVisualDuration,\n bounce = defaultBounce\n): KeyframeGenerator<number> {\n const options =\n typeof optionsOrVisualDuration !== \"object\"\n ? ({\n visualDuration: optionsOrVisualDuration,\n keyframes: [0, 1],\n bounce,\n } as ValueAnimationOptions<number>)\n : optionsOrVisualDuration\n\n const origin = options.keyframes[0]\n const target = options.keyframes[options.keyframes.length - 1]\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<number> = { done: false, value: origin }\n\n const {\n stiffness,\n damping,\n mass,\n duration,\n isResolvedFromDuration,\n isTimeDefined,\n } = getSpringOptions({ ...options })\n\n /**\n * A duration spring must end exactly at its duration, and it's settled\n * from rest by then. Inherited velocity could leave it still moving, so\n * it starts from rest. Every other spring, visualDuration included, ends\n * when it comes to rest, so inherits velocity as its initial condition.\n */\n const inheritVelocity = (velocity: number) =>\n isResolvedFromDuration ? 0 : -millisecondsToSeconds(velocity)\n\n const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass))\n const undampedAngularFreq = millisecondsToSeconds(\n Math.sqrt(stiffness / mass)\n )\n const decay = dampingRatio * undampedAngularFreq\n\n /**\n * Everything that changes when the spring is retargeted: written by\n * retarget() and update(), read by the resolvers. Grouped on one object,\n * like the coefficients (c) below. Writing doubles to object fields\n * measured marginally faster than to captured let variables in optimised\n * code; neither allocates, so this is a grouping choice, not a GC one.\n */\n const s = {\n target,\n delta: target - origin,\n velocity: inheritVelocity(options.velocity!) || 0,\n restSpeed: 0,\n restDelta: 0,\n }\n\n /**\n * If we're working on a granular scale, use smaller defaults for determining\n * when the spring is finished.\n *\n * These defaults have been selected empirically based on what strikes a good\n * ratio between feeling good and finishing as soon as changes are imperceptible.\n */\n const setRestThresholds = () => {\n const isGranularScale = Math.abs(s.delta) < 5\n s.restSpeed =\n options.restSpeed ||\n (isGranularScale ? restSpeedGranular : restSpeedDefault)\n s.restDelta =\n options.restDelta ||\n (isGranularScale ? restDeltaGranular : restDeltaDefault)\n }\n setRestThresholds()\n\n let resolveSpring: (v: number) => number\n let resolveVelocity: (t: number) => number\n\n /**\n * Derives the coefficients that depend on origin, target and initial\n * velocity. Called once now and again whenever the spring is retargeted.\n */\n let update: VoidFunction\n\n if (dampingRatio < 1) {\n const angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio)\n\n /**\n * A is the position coefficient, sinC/cosC the coefficients of the\n * analytical derivative (px/ms). The exp/sin/cos terms depend only\n * on t, so they're memoized by t independently of the target: a\n * spring retargeted every frame samples the same t each frame and\n * skips the transcendentals entirely.\n */\n const c = { A: 0, sinC: 0, cosC: 0, t: -1, env: 0, sin: 0, cos: 0 }\n\n update = () => {\n c.A = (s.velocity + decay * s.delta) / angularFreq\n c.sinC = decay * c.A + s.delta * angularFreq\n c.cosC = decay * s.delta - c.A * angularFreq\n }\n\n const sample = (t: number) => {\n if (t !== c.t) {\n c.t = t\n c.env = Math.exp(-decay * t)\n c.sin = Math.sin(angularFreq * t)\n c.cos = Math.cos(angularFreq * t)\n }\n }\n\n // Underdamped spring\n resolveSpring = (t: number) => {\n sample(t)\n return s.target - c.env * (c.A * c.sin + s.delta * c.cos)\n }\n\n resolveVelocity = (t: number) => {\n sample(t)\n return c.env * (c.sinC * c.sin + c.cosC * c.cos)\n }\n } else if (dampingRatio === 1) {\n // Critically damped spring\n resolveSpring = (t: number) =>\n s.target -\n Math.exp(-undampedAngularFreq * t) *\n (s.delta + (s.velocity + undampedAngularFreq * s.delta) * t)\n\n // Analytical derivative of critically damped spring (px/ms)\n const c = { C: 0 }\n update = () => {\n c.C = s.velocity + undampedAngularFreq * s.delta\n }\n resolveVelocity = (t: number) =>\n Math.exp(-undampedAngularFreq * t) *\n (undampedAngularFreq * c.C * t - s.velocity)\n } else {\n /**\n * Overdamped spring: the sum of a slow and a fast decaying\n * exponential, so no term can overflow however heavily it's damped.\n */\n const dampedAngularFreq =\n undampedAngularFreq * Math.sqrt(dampingRatio * dampingRatio - 1)\n const slow = decay - dampedAngularFreq\n const fast = decay + dampedAngularFreq\n\n /**\n * Physics-defined springs keep a non-physical limit: once\n * dampedAngularFreq * t passes 300, both terms decay at the damping\n * rate. Heavily overdamped drag springs (dragElastic: 0,\n * dragTransition) rely on this to settle almost at once rather than\n * creep at stiffness / damping. It only applies when reached within\n * 300ms (a dampedAngularFreq of 1 rad/ms), so it reads as a stiff\n * spring snapping into place: any later and it cuts off a slow spring\n * that's visibly still moving (#1207). Negative bounce needs the\n * exact curve, so time-defined springs are exempt.\n */\n const limit =\n dampedAngularFreq < 1 || isTimeDefined\n ? Infinity\n : 300 / dampedAngularFreq\n const decayAt = (rate: number, t: number) =>\n Math.exp(t > limit ? (decay - rate) * limit - decay * t : -rate * t)\n\n const c = { S: 0, F: 0 }\n update = () => {\n const P = (s.velocity + decay * s.delta) / dampedAngularFreq\n c.S = (s.delta + P) / 2\n c.F = (s.delta - P) / 2\n }\n\n resolveSpring = (t: number) =>\n s.target - c.S * decayAt(slow, t) - c.F * decayAt(fast, t)\n\n // Analytical derivative of overdamped spring (px/ms)\n resolveVelocity = (t: number) =>\n slow * c.S * decayAt(slow, t) + fast * c.F * decayAt(fast, t)\n }\n\n update()\n\n const calculatedDuration = isResolvedFromDuration ? duration || null : null\n\n const generator = {\n calculatedDuration,\n /**\n * Aim the spring at a new target from its current position and\n * velocity, reusing the resolved physics and closures.\n */\n retarget: (keyframes: number[], newVelocity: number) => {\n s.target = keyframes[keyframes.length - 1]\n s.delta = s.target - keyframes[0]\n s.velocity = inheritVelocity(newVelocity)\n // Default thresholds depend on the scale of the new delta\n if (!(options.restSpeed && options.restDelta)) setRestThresholds()\n // Invalidate any duration lazily cached by JSAnimation\n generator.calculatedDuration = calculatedDuration\n state.done = false\n update()\n },\n velocity: (t: number) => secondsToMilliseconds(resolveVelocity(t)),\n next: (t: number) => {\n const current = resolveSpring(t)\n\n if (!isResolvedFromDuration) {\n const currentVelocity = secondsToMilliseconds(\n resolveVelocity(t)\n )\n state.done =\n Math.abs(currentVelocity) <= s.restSpeed &&\n Math.abs(s.target - current) <= s.restDelta\n } else {\n state.done = t >= duration!\n }\n\n state.value = state.done ? s.target : current\n\n return state\n },\n toString: () => {\n const easingDuration = Math.min(\n calcGeneratorDuration(generator),\n maxGeneratorDuration\n )\n\n const easing = generateLinearEasing(\n (progress: number) =>\n generator.next(easingDuration * progress).value,\n easingDuration,\n 30\n )\n\n return easingDuration + \"ms \" + easing\n },\n }\n\n return generator\n}\n\nconst spring = /* @__PURE__ */ Object.assign(springGenerator, {\n applyToOptions: (options: Transition) => {\n const generatorOptions = createGeneratorEasing(\n options as any,\n 100,\n springGenerator\n )\n\n options.ease = generatorOptions.ease\n options.duration = secondsToMilliseconds(generatorOptions.duration)\n options.type = \"keyframes\"\n return options\n },\n})\n\nexport { spring }\n"],"names":[],"mappings":";;;;;AAoBA;AACA,MAAM,gBAAgB,GAAG,GAAG;AAC5B,MAAM,cAAc,GAAG,EAAE;AACzB,MAAM,WAAW,GAAG,GAAG;AAEvB;AACA,MAAM,eAAe,GAAG,GAAG,CAAA;AAC3B,MAAM,aAAa,GAAG,GAAG;AACzB,MAAM,qBAAqB,GAAG,GAAG,CAAA;AAEjC;AACA,MAAM,iBAAiB,GAAG,IAAI;AAC9B,MAAM,gBAAgB,GAAG,CAAC;AAC1B,MAAM,iBAAiB,GAAG,KAAK;AAC/B,MAAM,gBAAgB,GAAG,GAAG;AAE5B;AACA,MAAM,WAAW,GAAG,IAAI,CAAA;AACxB,MAAM,WAAW,GAAG,IAAI,CAAA;AACxB,MAAM,UAAU,GAAG,IAAI;AAEvB;;;;AAIG;AACH,MAAM,oBAAoB,GAAG,CAAC,MAAc,KACxC,MAAM,GAAG;AACL,MAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,UAAU;MACnC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,UAAU,CAAC;AAE1C;;;;;;;;;;AAUG;AACH,SAAS,mBAAmB,CAAC,YAAoB,EAAE,gBAAwB,EAAA;AACvE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CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,MAAM,GAAG,OAAO;AAE7C,YAAA,OAAO,KAAK;QAChB,CAAC;QACD,QAAQ,EAAE,MAAK;AACX,YAAA,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAC3B,qBAAqB,CAAC,SAAS,CAAC,EAChC,oBAAoB,CACvB;YAED,MAAM,MAAM,GAAG,oBAAoB,CAC/B,CAAC,QAAgB,KACb,SAAS,CAAC,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC,CAAC,KAAK,EACnD,cAAc,EACd,EAAE,CACL;AAED,YAAA,OAAO,cAAc,GAAG,KAAK,GAAG,MAAM;QAC1C,CAAC;KACJ;AAED,IAAA,OAAO,SAAS;AACpB;AAEA,MAAM,MAAM,mBAAmB,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE;AAC1D,IAAA,cAAc,EAAE,CAAC,OAAmB,KAAI;QACpC,MAAM,gBAAgB,GAAG,qBAAqB,CAC1C,OAAc,EACd,GAAG,EACH,eAAe,CAClB;AAED,QAAA,OAAO,CAAC,IAAI,GAAG,gBAAgB,CAAC,IAAI;QACpC,OAAO,CAAC,QAAQ,GAAG,qBAAqB,CAAC,gBAAgB,CAAC,QAAQ,CAAC;AACnE,QAAA,OAAO,CAAC,IAAI,GAAG,WAAW;AAC1B,QAAA,OAAO,OAAO;IAClB,CAAC;AACJ,CAAA;;;;"}
|
|
@@ -232,15 +232,14 @@ function addPinchListeners(element, getValues, getEnabledOptions, onPinchStart)
|
|
|
232
232
|
* step and the focal point stays in place.
|
|
233
233
|
*/
|
|
234
234
|
const tick = () => {
|
|
235
|
-
if (dragControls()?.isDragging)
|
|
236
|
-
return stopSnap();
|
|
237
235
|
const { value: p, done } = generator.next(time.now() - startTime);
|
|
238
236
|
if (done)
|
|
239
237
|
stopSnap();
|
|
240
238
|
const [k, r, fx, fy] = at(p);
|
|
241
239
|
scaleOption !== false && scale.set(k);
|
|
242
240
|
rotateOption !== false && rotate.set(r);
|
|
243
|
-
|
|
241
|
+
// A drag that starts mid-snap owns x/y from then on.
|
|
242
|
+
if (moves && !dragControls()?.isDragging) {
|
|
244
243
|
x.set(snapToOrigin ? mixNumber(x0, 0, p) : fx);
|
|
245
244
|
y.set(snapToOrigin ? mixNumber(y0, 0, p) : fy);
|
|
246
245
|
}
|