motion-dom 12.34.2 → 12.34.5
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 +60 -92
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/AsyncMotionValueAnimation.mjs.map +1 -1
- package/dist/es/animation/GroupAnimation.mjs.map +1 -1
- package/dist/es/animation/GroupAnimationWithThen.mjs.map +1 -1
- package/dist/es/animation/JSAnimation.mjs.map +1 -1
- package/dist/es/animation/NativeAnimation.mjs +8 -7
- package/dist/es/animation/NativeAnimation.mjs.map +1 -1
- package/dist/es/animation/NativeAnimationExtended.mjs.map +1 -1
- package/dist/es/animation/NativeAnimationWrapper.mjs.map +1 -1
- package/dist/es/animation/animate/single-value.mjs.map +1 -1
- package/dist/es/animation/drivers/frame.mjs +1 -1
- package/dist/es/animation/drivers/frame.mjs.map +1 -1
- package/dist/es/animation/generators/inertia.mjs.map +1 -1
- package/dist/es/animation/generators/keyframes.mjs.map +1 -1
- package/dist/es/animation/generators/spring/defaults.mjs.map +1 -1
- package/dist/es/animation/generators/spring/find.mjs.map +1 -1
- package/dist/es/animation/generators/spring/index.mjs +7 -2
- package/dist/es/animation/generators/spring/index.mjs.map +1 -1
- package/dist/es/animation/generators/utils/calc-duration.mjs.map +1 -1
- package/dist/es/animation/generators/utils/create-generator-easing.mjs.map +1 -1
- package/dist/es/animation/generators/utils/is-generator.mjs.map +1 -1
- package/dist/es/animation/generators/utils/velocity.mjs.map +1 -1
- package/dist/es/animation/interfaces/motion-value.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element-variant.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element.mjs.map +1 -1
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs.map +1 -1
- package/dist/es/animation/keyframes/KeyframesResolver.mjs.map +1 -1
- package/dist/es/animation/keyframes/get-final.mjs.map +1 -1
- package/dist/es/animation/keyframes/offsets/default.mjs.map +1 -1
- package/dist/es/animation/keyframes/offsets/fill.mjs.map +1 -1
- package/dist/es/animation/keyframes/offsets/time.mjs.map +1 -1
- package/dist/es/animation/keyframes/utils/apply-px-defaults.mjs.map +1 -1
- package/dist/es/animation/keyframes/utils/fill-wildcards.mjs.map +1 -1
- package/dist/es/animation/keyframes/utils/is-none.mjs.map +1 -1
- package/dist/es/animation/keyframes/utils/make-none-animatable.mjs.map +1 -1
- package/dist/es/animation/keyframes/utils/unit-conversion.mjs.map +1 -1
- package/dist/es/animation/optimized-appear/data-id.mjs.map +1 -1
- package/dist/es/animation/optimized-appear/get-appear-id.mjs.map +1 -1
- package/dist/es/animation/utils/WithPromise.mjs.map +1 -1
- package/dist/es/animation/utils/active-animations.mjs.map +1 -1
- package/dist/es/animation/utils/calc-child-stagger.mjs.map +1 -1
- package/dist/es/animation/utils/can-animate.mjs.map +1 -1
- package/dist/es/animation/utils/css-variables-conversion.mjs.map +1 -1
- package/dist/es/animation/utils/default-transitions.mjs.map +1 -1
- package/dist/es/animation/utils/get-final-keyframe.mjs.map +1 -1
- package/dist/es/animation/utils/get-value-transition.mjs.map +1 -1
- package/dist/es/animation/utils/is-animatable.mjs.map +1 -1
- package/dist/es/animation/utils/is-css-variable.mjs.map +1 -1
- package/dist/es/animation/utils/is-transition-defined.mjs.map +1 -1
- package/dist/es/animation/utils/make-animation-instant.mjs.map +1 -1
- package/dist/es/animation/utils/replace-transition-type.mjs.map +1 -1
- package/dist/es/animation/utils/resolve-transition.mjs.map +1 -1
- package/dist/es/animation/waapi/easing/cubic-bezier.mjs.map +1 -1
- package/dist/es/animation/waapi/easing/is-supported.mjs.map +1 -1
- package/dist/es/animation/waapi/easing/map-easing.mjs.map +1 -1
- package/dist/es/animation/waapi/easing/supported.mjs.map +1 -1
- package/dist/es/animation/waapi/start-waapi-animation.mjs.map +1 -1
- package/dist/es/animation/waapi/supports/partial-keyframes.mjs.map +1 -1
- package/dist/es/animation/waapi/supports/waapi.mjs.map +1 -1
- package/dist/es/animation/waapi/utils/accelerated-values.mjs.map +1 -1
- package/dist/es/animation/waapi/utils/apply-generator.mjs.map +1 -1
- package/dist/es/animation/waapi/utils/linear.mjs.map +1 -1
- package/dist/es/animation/waapi/utils/px-values.mjs.map +1 -1
- package/dist/es/animation/waapi/utils/unsupported-easing.mjs +1 -1
- package/dist/es/animation/waapi/utils/unsupported-easing.mjs.map +1 -1
- package/dist/es/effects/MotionValueState.mjs.map +1 -1
- package/dist/es/effects/attr/index.mjs.map +1 -1
- package/dist/es/effects/prop/index.mjs.map +1 -1
- package/dist/es/effects/style/index.mjs.map +1 -1
- package/dist/es/effects/style/transform.mjs.map +1 -1
- package/dist/es/effects/svg/index.mjs.map +1 -1
- package/dist/es/effects/utils/create-dom-effect.mjs.map +1 -1
- package/dist/es/effects/utils/create-effect.mjs.map +1 -1
- package/dist/es/events/add-dom-event.mjs.map +1 -1
- package/dist/es/frameloop/batcher.mjs.map +1 -1
- package/dist/es/frameloop/frame.mjs.map +1 -1
- package/dist/es/frameloop/index-legacy.mjs.map +1 -1
- package/dist/es/frameloop/microtask.mjs.map +1 -1
- package/dist/es/frameloop/order.mjs.map +1 -1
- package/dist/es/frameloop/render-step.mjs.map +1 -1
- package/dist/es/frameloop/sync-time.mjs.map +1 -1
- package/dist/es/gestures/drag/state/is-active.mjs.map +1 -1
- package/dist/es/gestures/drag/state/set-active.mjs.map +1 -1
- package/dist/es/gestures/hover.mjs.map +1 -1
- package/dist/es/gestures/press/index.mjs.map +1 -1
- package/dist/es/gestures/press/utils/is-keyboard-accessible.mjs.map +1 -1
- package/dist/es/gestures/press/utils/keyboard.mjs.map +1 -1
- package/dist/es/gestures/press/utils/state.mjs.map +1 -1
- package/dist/es/gestures/utils/is-node-or-child.mjs.map +1 -1
- package/dist/es/gestures/utils/is-primary-pointer.mjs.map +1 -1
- package/dist/es/gestures/utils/setup.mjs.map +1 -1
- package/dist/es/index.mjs +1 -1
- package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
- package/dist/es/projection/animation/mix-values.mjs.map +1 -1
- package/dist/es/projection/geometry/conversion.mjs.map +1 -1
- package/dist/es/projection/geometry/copy.mjs.map +1 -1
- package/dist/es/projection/geometry/delta-apply.mjs.map +1 -1
- package/dist/es/projection/geometry/delta-calc.mjs.map +1 -1
- package/dist/es/projection/geometry/delta-remove.mjs.map +1 -1
- package/dist/es/projection/geometry/models.mjs.map +1 -1
- package/dist/es/projection/geometry/utils.mjs.map +1 -1
- package/dist/es/projection/node/HTMLProjectionNode.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +1 -1
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/projection/node/group.mjs.map +1 -1
- package/dist/es/projection/node/state.mjs.map +1 -1
- package/dist/es/projection/shared/stack.mjs +32 -75
- package/dist/es/projection/shared/stack.mjs.map +1 -1
- package/dist/es/projection/styles/scale-border-radius.mjs.map +1 -1
- package/dist/es/projection/styles/scale-box-shadow.mjs.map +1 -1
- package/dist/es/projection/styles/scale-correction.mjs.map +1 -1
- package/dist/es/projection/styles/transform.mjs.map +1 -1
- package/dist/es/projection/utils/compare-by-depth.mjs.map +1 -1
- package/dist/es/projection/utils/each-axis.mjs.map +1 -1
- package/dist/es/projection/utils/flat-tree.mjs.map +1 -1
- package/dist/es/projection/utils/has-transform.mjs.map +1 -1
- package/dist/es/projection/utils/measure.mjs.map +1 -1
- package/dist/es/render/Feature.mjs.map +1 -1
- package/dist/es/render/VisualElement.mjs.map +1 -1
- package/dist/es/render/dom/DOMVisualElement.mjs.map +1 -1
- package/dist/es/render/dom/parse-transform.mjs.map +1 -1
- package/dist/es/render/dom/style-computed.mjs.map +1 -1
- package/dist/es/render/dom/style-set.mjs.map +1 -1
- package/dist/es/render/dom/utils/camel-to-dash.mjs.map +1 -1
- package/dist/es/render/html/HTMLVisualElement.mjs.map +1 -1
- package/dist/es/render/html/utils/build-styles.mjs.map +1 -1
- package/dist/es/render/html/utils/build-transform.mjs.map +1 -1
- package/dist/es/render/html/utils/render.mjs.map +1 -1
- package/dist/es/render/html/utils/scrape-motion-values.mjs.map +1 -1
- package/dist/es/render/object/ObjectVisualElement.mjs.map +1 -1
- package/dist/es/render/store.mjs.map +1 -1
- package/dist/es/render/svg/SVGVisualElement.mjs.map +1 -1
- package/dist/es/render/svg/utils/build-attrs.mjs.map +1 -1
- package/dist/es/render/svg/utils/camel-case-attrs.mjs.map +1 -1
- package/dist/es/render/svg/utils/path.mjs.map +1 -1
- package/dist/es/render/svg/utils/render.mjs.map +1 -1
- package/dist/es/render/svg/utils/scrape-motion-values.mjs.map +1 -1
- package/dist/es/render/utils/animation-state.mjs +14 -9
- package/dist/es/render/utils/animation-state.mjs.map +1 -1
- package/dist/es/render/utils/get-variant-context.mjs.map +1 -1
- package/dist/es/render/utils/is-animation-controls.mjs.map +1 -1
- package/dist/es/render/utils/is-controlling-variants.mjs.map +1 -1
- package/dist/es/render/utils/is-forced-motion-value.mjs.map +1 -1
- package/dist/es/render/utils/is-keyframes-target.mjs.map +1 -1
- package/dist/es/render/utils/is-variant-label.mjs.map +1 -1
- package/dist/es/render/utils/keys-position.mjs.map +1 -1
- package/dist/es/render/utils/keys-transform.mjs.map +1 -1
- package/dist/es/render/utils/motion-values.mjs.map +1 -1
- package/dist/es/render/utils/reduced-motion/index.mjs.map +1 -1
- package/dist/es/render/utils/reduced-motion/state.mjs.map +1 -1
- package/dist/es/render/utils/resolve-dynamic-variants.mjs.map +1 -1
- package/dist/es/render/utils/resolve-variants.mjs.map +1 -1
- package/dist/es/render/utils/setters.mjs.map +1 -1
- package/dist/es/render/utils/shallow-compare.mjs.map +1 -1
- package/dist/es/render/utils/variant-props.mjs.map +1 -1
- package/dist/es/resize/handle-element.mjs.map +1 -1
- package/dist/es/resize/handle-window.mjs.map +1 -1
- package/dist/es/resize/index.mjs.map +1 -1
- package/dist/es/scroll/observe.mjs.map +1 -1
- package/dist/es/stats/animation-count.mjs.map +1 -1
- package/dist/es/stats/buffer.mjs.map +1 -1
- package/dist/es/stats/index.mjs.map +1 -1
- package/dist/es/utils/delay.mjs.map +1 -1
- package/dist/es/utils/interpolate.mjs.map +1 -1
- package/dist/es/utils/is-html-element.mjs.map +1 -1
- package/dist/es/utils/is-svg-element.mjs.map +1 -1
- package/dist/es/utils/is-svg-svg-element.mjs.map +1 -1
- package/dist/es/utils/mix/color.mjs.map +1 -1
- package/dist/es/utils/mix/complex.mjs.map +1 -1
- package/dist/es/utils/mix/immediate.mjs.map +1 -1
- package/dist/es/utils/mix/index.mjs.map +1 -1
- package/dist/es/utils/mix/number.mjs.map +1 -1
- package/dist/es/utils/mix/visibility.mjs.map +1 -1
- package/dist/es/utils/resolve-elements.mjs.map +1 -1
- package/dist/es/utils/stagger.mjs.map +1 -1
- package/dist/es/utils/supports/linear-easing.mjs.map +1 -1
- package/dist/es/utils/supports/memo.mjs.map +1 -1
- package/dist/es/utils/supports/scroll-timeline.mjs.map +1 -1
- package/dist/es/utils/transform.mjs.map +1 -1
- package/dist/es/value/follow-value.mjs.map +1 -1
- package/dist/es/value/index.mjs.map +1 -1
- package/dist/es/value/map-value.mjs.map +1 -1
- package/dist/es/value/spring-value.mjs +1 -1
- package/dist/es/value/spring-value.mjs.map +1 -1
- package/dist/es/value/subscribe-value.mjs.map +1 -1
- package/dist/es/value/transform-value.mjs.map +1 -1
- package/dist/es/value/types/auto.mjs.map +1 -1
- package/dist/es/value/types/color/hex.mjs.map +1 -1
- package/dist/es/value/types/color/hsla-to-rgba.mjs.map +1 -1
- package/dist/es/value/types/color/hsla.mjs +1 -1
- package/dist/es/value/types/color/hsla.mjs.map +1 -1
- package/dist/es/value/types/color/index.mjs.map +1 -1
- package/dist/es/value/types/color/rgba.mjs +1 -1
- package/dist/es/value/types/color/rgba.mjs.map +1 -1
- package/dist/es/value/types/color/utils.mjs.map +1 -1
- package/dist/es/value/types/complex/filter.mjs.map +1 -1
- package/dist/es/value/types/complex/index.mjs.map +1 -1
- package/dist/es/value/types/complex/mask.mjs.map +1 -1
- package/dist/es/value/types/dimensions.mjs.map +1 -1
- package/dist/es/value/types/int.mjs.map +1 -1
- package/dist/es/value/types/maps/defaults.mjs.map +1 -1
- package/dist/es/value/types/maps/number.mjs.map +1 -1
- package/dist/es/value/types/maps/transform.mjs +2 -2
- package/dist/es/value/types/maps/transform.mjs.map +1 -1
- package/dist/es/value/types/numbers/index.mjs.map +1 -1
- package/dist/es/value/types/numbers/units.mjs.map +1 -1
- package/dist/es/value/types/utils/animatable-none.mjs.map +1 -1
- package/dist/es/value/types/utils/find.mjs.map +1 -1
- package/dist/es/value/types/utils/get-as-type.mjs.map +1 -1
- package/dist/es/value/types/utils/is-nullish.mjs.map +1 -1
- package/dist/es/value/types/utils/sanitize.mjs.map +1 -1
- package/dist/es/value/utils/is-motion-value.mjs.map +1 -1
- package/dist/es/value/utils/resolve-motion-value.mjs.map +1 -1
- package/dist/es/value/will-change/add-will-change.mjs.map +1 -1
- package/dist/es/value/will-change/is.mjs.map +1 -1
- package/dist/es/view/index.mjs.map +1 -1
- package/dist/es/view/queue.mjs.map +1 -1
- package/dist/es/view/start.mjs.map +1 -1
- package/dist/es/view/utils/choose-layer-type.mjs.map +1 -1
- package/dist/es/view/utils/css.mjs.map +1 -1
- package/dist/es/view/utils/get-layer-info.mjs.map +1 -1
- package/dist/es/view/utils/get-view-animations.mjs.map +1 -1
- package/dist/es/view/utils/has-target.mjs.map +1 -1
- package/dist/index.d.ts +0 -4
- package/dist/motion-dom.dev.js +60 -92
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-motion-value.js +1 -1
- package/dist/size-rollup-motion-value.js.map +1 -1
- package/dist/size-rollup-style-effect.js +1 -1
- package/dist/size-rollup-style-effect.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncMotionValueAnimation.mjs","sources":["../../../src/animation/AsyncMotionValueAnimation.ts"],"sourcesContent":["import { MotionGlobalConfig, noop } from \"motion-utils\"\nimport { time } from \"../frameloop/sync-time\"\nimport { JSAnimation } from \"./JSAnimation\"\nimport { getFinalKeyframe } from \"./keyframes/get-final\"\nimport {\n KeyframeResolver as DefaultKeyframeResolver,\n flushKeyframeResolvers,\n ResolvedKeyframes,\n} from \"./keyframes/KeyframesResolver\"\nimport { NativeAnimationExtended } from \"./NativeAnimationExtended\"\nimport {\n AnimationPlaybackControls,\n AnyResolvedKeyframe,\n TimelineWithFallback,\n ValueAnimationOptions,\n} from \"./types\"\nimport { canAnimate } from \"./utils/can-animate\"\nimport { makeAnimationInstant } from \"./utils/make-animation-instant\"\nimport { WithPromise } from \"./utils/WithPromise\"\nimport { supportsBrowserAnimation } from \"./waapi/supports/waapi\"\n\n/**\n * Maximum time allowed between an animation being created and it being\n * resolved for us to use the latter as the start time.\n *\n * This is to ensure that while we prefer to \"start\" an animation as soon\n * as it's triggered, we also want to avoid a visual jump if there's a big delay\n * between these two moments.\n */\nconst MAX_RESOLVE_DELAY = 40\n\ntype OptionsWithoutKeyframes<T extends AnyResolvedKeyframe> = Omit<\n ValueAnimationOptions<T>,\n \"keyframes\"\n>\n\nexport class AsyncMotionValueAnimation<T extends AnyResolvedKeyframe>\n extends WithPromise\n implements AnimationPlaybackControls\n{\n private createdAt: number\n\n private resolvedAt: number | undefined\n\n private _animation: AnimationPlaybackControls | undefined\n\n private pendingTimeline: TimelineWithFallback | undefined\n\n private keyframeResolver: DefaultKeyframeResolver | undefined\n\n private stopTimeline: VoidFunction | undefined\n\n constructor({\n autoplay = true,\n delay = 0,\n type = \"keyframes\",\n repeat = 0,\n repeatDelay = 0,\n repeatType = \"loop\",\n keyframes,\n name,\n motionValue,\n element,\n ...options\n }: ValueAnimationOptions<T>) {\n super()\n\n this.createdAt = time.now()\n\n const optionsWithDefaults: OptionsWithoutKeyframes<T> = {\n autoplay,\n delay,\n type,\n repeat,\n repeatDelay,\n repeatType,\n name,\n motionValue,\n element,\n ...options,\n }\n\n const KeyframeResolver =\n element?.KeyframeResolver || DefaultKeyframeResolver\n\n this.keyframeResolver = new KeyframeResolver(\n keyframes,\n (\n resolvedKeyframes: ResolvedKeyframes<T>,\n finalKeyframe: T,\n forced: boolean\n ) =>\n this.onKeyframesResolved(\n resolvedKeyframes,\n finalKeyframe,\n optionsWithDefaults,\n !forced\n ),\n name,\n motionValue,\n element\n )\n this.keyframeResolver?.scheduleResolve()\n }\n\n onKeyframesResolved(\n keyframes: ResolvedKeyframes<T>,\n finalKeyframe: T,\n options: OptionsWithoutKeyframes<T>,\n sync: boolean\n ) {\n this.keyframeResolver = undefined\n\n const { name, type, velocity, delay, isHandoff, onUpdate } = options\n this.resolvedAt = time.now()\n\n /**\n * If we can't animate this value with the resolved keyframes\n * then we should complete it immediately.\n */\n if (!canAnimate(keyframes, name, type, velocity)) {\n if (MotionGlobalConfig.instantAnimations || !delay) {\n onUpdate?.(getFinalKeyframe(keyframes, options, finalKeyframe))\n }\n\n keyframes[0] = keyframes[keyframes.length - 1]\n\n makeAnimationInstant(options)\n options.repeat = 0\n }\n\n /**\n * Resolve startTime for the animation.\n *\n * This method uses the createdAt and resolvedAt to calculate the\n * animation startTime. *Ideally*, we would use the createdAt time as t=0\n * as the following frame would then be the first frame of the animation in\n * progress, which would feel snappier.\n *\n * However, if there's a delay (main thread work) between the creation of\n * the animation and the first committed frame, we prefer to use resolvedAt\n * to avoid a sudden jump into the animation.\n */\n const startTime = sync\n ? !this.resolvedAt\n ? this.createdAt\n : this.resolvedAt - this.createdAt > MAX_RESOLVE_DELAY\n ? this.resolvedAt\n : this.createdAt\n : undefined\n\n const resolvedOptions = {\n startTime,\n finalKeyframe,\n ...options,\n keyframes,\n }\n\n /**\n * Animate via WAAPI if possible. If this is a handoff animation, the optimised animation will be running via\n * WAAPI. Therefore, this animation must be JS to ensure it runs \"under\" the\n * optimised animation.\n */\n const useWaapi = !isHandoff && supportsBrowserAnimation(resolvedOptions)\n const element = resolvedOptions.motionValue?.owner?.current\n\n const animation = useWaapi\n ? new NativeAnimationExtended({\n ...resolvedOptions,\n element,\n } as any)\n : new JSAnimation(resolvedOptions)\n\n animation.finished.then(() => {\n this.notifyFinished()\n }).catch(noop)\n\n if (this.pendingTimeline) {\n this.stopTimeline = animation.attachTimeline(this.pendingTimeline)\n this.pendingTimeline = undefined\n }\n\n this._animation = animation\n }\n\n get finished() {\n if (!this._animation) {\n return this._finished\n } else {\n return this.animation.finished\n }\n }\n\n then(onResolve: VoidFunction, _onReject?: VoidFunction) {\n return this.finished.finally(onResolve).then(() => {})\n }\n\n get animation(): AnimationPlaybackControls {\n if (!this._animation) {\n this.keyframeResolver?.resume()\n flushKeyframeResolvers()\n }\n\n return this._animation!\n }\n\n get duration() {\n return this.animation.duration\n }\n\n get iterationDuration() {\n return this.animation.iterationDuration\n }\n\n get time() {\n return this.animation.time\n }\n\n set time(newTime: number) {\n this.animation.time = newTime\n }\n\n get speed() {\n return this.animation.speed\n }\n\n get state() {\n return this.animation.state\n }\n\n set speed(newSpeed: number) {\n this.animation.speed = newSpeed\n }\n\n get startTime() {\n return this.animation.startTime\n }\n\n attachTimeline(timeline: TimelineWithFallback) {\n if (this._animation) {\n this.stopTimeline = this.animation.attachTimeline(timeline)\n } else {\n this.pendingTimeline = timeline\n }\n\n return () => this.stop()\n }\n\n play() {\n this.animation.play()\n }\n\n pause() {\n this.animation.pause()\n }\n\n complete() {\n this.animation.complete()\n }\n\n cancel() {\n if (this._animation) {\n this.animation.cancel()\n }\n\n this.keyframeResolver?.cancel()\n }\n\n /**\n * Bound to support return animation.stop pattern\n */\n stop = () => {\n if (this._animation) {\n this._animation.stop()\n this.stopTimeline?.()\n }\n\n this.keyframeResolver?.cancel()\n }\n}\n"],"names":["KeyframeResolver","DefaultKeyframeResolver"],"mappings":";;;;;;;;;;;AAqBA;;;;;;;AAOG;AACH,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAOtB,MAAO,yBACT,SAAQ,WAAW,CAAA;AAenB,IAAA,WAAA,CAAY,EACR,Q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CAAA;KAClC;AAaJ;;;;"}
|
|
1
|
+
{"version":3,"file":"AsyncMotionValueAnimation.mjs","sources":["../../../src/animation/AsyncMotionValueAnimation.ts"],"sourcesContent":["import { MotionGlobalConfig, noop } from \"motion-utils\"\nimport { time } from \"../frameloop/sync-time\"\nimport { JSAnimation } from \"./JSAnimation\"\nimport { getFinalKeyframe } from \"./keyframes/get-final\"\nimport {\n KeyframeResolver as DefaultKeyframeResolver,\n flushKeyframeResolvers,\n ResolvedKeyframes,\n} from \"./keyframes/KeyframesResolver\"\nimport { NativeAnimationExtended } from \"./NativeAnimationExtended\"\nimport {\n AnimationPlaybackControls,\n AnyResolvedKeyframe,\n TimelineWithFallback,\n ValueAnimationOptions,\n} from \"./types\"\nimport { canAnimate } from \"./utils/can-animate\"\nimport { makeAnimationInstant } from \"./utils/make-animation-instant\"\nimport { WithPromise } from \"./utils/WithPromise\"\nimport { supportsBrowserAnimation } from \"./waapi/supports/waapi\"\n\n/**\n * Maximum time allowed between an animation being created and it being\n * resolved for us to use the latter as the start time.\n *\n * This is to ensure that while we prefer to \"start\" an animation as soon\n * as it's triggered, we also want to avoid a visual jump if there's a big delay\n * between these two moments.\n */\nconst MAX_RESOLVE_DELAY = 40\n\ntype OptionsWithoutKeyframes<T extends AnyResolvedKeyframe> = Omit<\n ValueAnimationOptions<T>,\n \"keyframes\"\n>\n\nexport class AsyncMotionValueAnimation<T extends AnyResolvedKeyframe>\n extends WithPromise\n implements AnimationPlaybackControls\n{\n private createdAt: number\n\n private resolvedAt: number | undefined\n\n private _animation: AnimationPlaybackControls | undefined\n\n private pendingTimeline: TimelineWithFallback | undefined\n\n private keyframeResolver: DefaultKeyframeResolver | undefined\n\n private stopTimeline: VoidFunction | undefined\n\n constructor({\n autoplay = true,\n delay = 0,\n type = \"keyframes\",\n repeat = 0,\n repeatDelay = 0,\n repeatType = \"loop\",\n keyframes,\n name,\n motionValue,\n element,\n ...options\n }: ValueAnimationOptions<T>) {\n super()\n\n this.createdAt = time.now()\n\n const optionsWithDefaults: OptionsWithoutKeyframes<T> = {\n autoplay,\n delay,\n type,\n repeat,\n repeatDelay,\n repeatType,\n name,\n motionValue,\n element,\n ...options,\n }\n\n const KeyframeResolver =\n element?.KeyframeResolver || DefaultKeyframeResolver\n\n this.keyframeResolver = new KeyframeResolver(\n keyframes,\n (\n resolvedKeyframes: ResolvedKeyframes<T>,\n finalKeyframe: T,\n forced: boolean\n ) =>\n this.onKeyframesResolved(\n resolvedKeyframes,\n finalKeyframe,\n optionsWithDefaults,\n !forced\n ),\n name,\n motionValue,\n element\n )\n this.keyframeResolver?.scheduleResolve()\n }\n\n onKeyframesResolved(\n keyframes: ResolvedKeyframes<T>,\n finalKeyframe: T,\n options: OptionsWithoutKeyframes<T>,\n sync: boolean\n ) {\n this.keyframeResolver = undefined\n\n const { name, type, velocity, delay, isHandoff, onUpdate } = options\n this.resolvedAt = time.now()\n\n /**\n * If we can't animate this value with the resolved keyframes\n * then we should complete it immediately.\n */\n if (!canAnimate(keyframes, name, type, velocity)) {\n if (MotionGlobalConfig.instantAnimations || !delay) {\n onUpdate?.(getFinalKeyframe(keyframes, options, finalKeyframe))\n }\n\n keyframes[0] = keyframes[keyframes.length - 1]\n\n makeAnimationInstant(options)\n options.repeat = 0\n }\n\n /**\n * Resolve startTime for the animation.\n *\n * This method uses the createdAt and resolvedAt to calculate the\n * animation startTime. *Ideally*, we would use the createdAt time as t=0\n * as the following frame would then be the first frame of the animation in\n * progress, which would feel snappier.\n *\n * However, if there's a delay (main thread work) between the creation of\n * the animation and the first committed frame, we prefer to use resolvedAt\n * to avoid a sudden jump into the animation.\n */\n const startTime = sync\n ? !this.resolvedAt\n ? this.createdAt\n : this.resolvedAt - this.createdAt > MAX_RESOLVE_DELAY\n ? this.resolvedAt\n : this.createdAt\n : undefined\n\n const resolvedOptions = {\n startTime,\n finalKeyframe,\n ...options,\n keyframes,\n }\n\n /**\n * Animate via WAAPI if possible. If this is a handoff animation, the optimised animation will be running via\n * WAAPI. Therefore, this animation must be JS to ensure it runs \"under\" the\n * optimised animation.\n */\n const useWaapi = !isHandoff && supportsBrowserAnimation(resolvedOptions)\n const element = resolvedOptions.motionValue?.owner?.current\n\n const animation = useWaapi\n ? new NativeAnimationExtended({\n ...resolvedOptions,\n element,\n } as any)\n : new JSAnimation(resolvedOptions)\n\n animation.finished.then(() => {\n this.notifyFinished()\n }).catch(noop)\n\n if (this.pendingTimeline) {\n this.stopTimeline = animation.attachTimeline(this.pendingTimeline)\n this.pendingTimeline = undefined\n }\n\n this._animation = animation\n }\n\n get finished() {\n if (!this._animation) {\n return this._finished\n } else {\n return this.animation.finished\n }\n }\n\n then(onResolve: VoidFunction, _onReject?: VoidFunction) {\n return this.finished.finally(onResolve).then(() => {})\n }\n\n get animation(): AnimationPlaybackControls {\n if (!this._animation) {\n this.keyframeResolver?.resume()\n flushKeyframeResolvers()\n }\n\n return this._animation!\n }\n\n get duration() {\n return this.animation.duration\n }\n\n get iterationDuration() {\n return this.animation.iterationDuration\n }\n\n get time() {\n return this.animation.time\n }\n\n set time(newTime: number) {\n this.animation.time = newTime\n }\n\n get speed() {\n return this.animation.speed\n }\n\n get state() {\n return this.animation.state\n }\n\n set speed(newSpeed: number) {\n this.animation.speed = newSpeed\n }\n\n get startTime() {\n return this.animation.startTime\n }\n\n attachTimeline(timeline: TimelineWithFallback) {\n if (this._animation) {\n this.stopTimeline = this.animation.attachTimeline(timeline)\n } else {\n this.pendingTimeline = timeline\n }\n\n return () => this.stop()\n }\n\n play() {\n this.animation.play()\n }\n\n pause() {\n this.animation.pause()\n }\n\n complete() {\n this.animation.complete()\n }\n\n cancel() {\n if (this._animation) {\n this.animation.cancel()\n }\n\n this.keyframeResolver?.cancel()\n }\n\n /**\n * Bound to support return animation.stop pattern\n */\n stop = () => {\n if (this._animation) {\n this._animation.stop()\n this.stopTimeline?.()\n }\n\n this.keyframeResolver?.cancel()\n }\n}\n"],"names":["KeyframeResolver","DefaultKeyframeResolver"],"mappings":";;;;;;;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AA,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,OAAO;IACjC;AAEA,IAAA,IAAI,KAAK,GAAA;AACL,QAAA,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK;IAC/B;AAEA,IAAA,IAAI,KAAK,GAAA;AACL,QAAA,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK;IAC/B;IAEA,IAAI,KAAK,CAAC,QAAgB,EAAA;AACtB,QAAA,IAAI,CAAC,SAAS,CAAC,KAAK,GAAG,QAAQ;IACnC;AAEA,IAAA,IAAI,SAAS,GAAA;AACT,QAAA,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS;IACnC;AAEA,IAAA,cAAc,CAAC,QAA8B,EAAA;AACzC,QAAA,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,QAAQ,CAAC;QAC/D;aAAO;AACH,YAAA,IAAI,CAAC,eAAe,GAAG,QAAQ;QACnC;AAEA,QAAA,OAAO,MAAM,IAAI,CAAC,IAAI,EAAE;IAC5B;IAEA,IAAI,GAAA;AACA,QAAA,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE;IACzB;IAEA,KAAK,GAAA;AACD,QAAA,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE;IAC1B;IAEA,QAAQ,GAAA;AACJ,QAAA,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;IAC7B;IAEA,MAAM,GAAA;AACF,QAAA,IAAI,IAAI,CAAC,UAAU,EAAE;AACjB,YAAA,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE;QAC3B;AAEA,QAAA,IAAI,CAAC,gBAAgB,EAAE,MAAM,EAAE;IACnC;AAaH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupAnimation.mjs","sources":["../../../src/animation/GroupAnimation.ts"],"sourcesContent":["import { AnimationPlaybackControls, TimelineWithFallback } from \"./types\"\n\ntype PropNames =\n | \"time\"\n | \"speed\"\n | \"duration\"\n | \"attachTimeline\"\n | \"startTime\"\n | \"state\"\n\nexport type AcceptedAnimations = AnimationPlaybackControls\n\nexport type GroupedAnimations = AcceptedAnimations[]\n\nexport class GroupAnimation implements AnimationPlaybackControls {\n animations: GroupedAnimations\n\n constructor(animations: Array<AcceptedAnimations | undefined>) {\n this.animations = animations.filter(Boolean) as GroupedAnimations\n }\n\n get finished() {\n return Promise.all(\n this.animations.map((animation) => animation.finished)\n )\n }\n\n /**\n * TODO: Filter out cancelled or stopped animations before returning\n */\n private getAll(propName: PropNames) {\n return this.animations[0][propName] as any\n }\n\n private setAll(propName: PropNames, newValue: any) {\n for (let i = 0; i < this.animations.length; i++) {\n ;(this.animations[i][propName] as any) = newValue\n }\n }\n\n attachTimeline(timeline: TimelineWithFallback) {\n const subscriptions = this.animations.map((animation) =>\n animation.attachTimeline(timeline)\n )\n\n return () => {\n subscriptions.forEach((cancel, i) => {\n cancel && cancel()\n this.animations[i].stop()\n })\n }\n }\n\n get time() {\n return this.getAll(\"time\")\n }\n\n set time(time: number) {\n this.setAll(\"time\", time)\n }\n\n get speed() {\n return this.getAll(\"speed\")\n }\n\n set speed(speed: number) {\n this.setAll(\"speed\", speed)\n }\n\n get state() {\n return this.getAll(\"state\")\n }\n\n get startTime() {\n return this.getAll(\"startTime\")\n }\n\n get duration() {\n return getMax(this.animations, \"duration\")\n }\n\n get iterationDuration() {\n return getMax(this.animations, \"iterationDuration\")\n }\n\n private runAll(\n methodName: keyof Omit<\n AnimationPlaybackControls,\n PropNames | \"then\" | \"finished\" | \"iterationDuration\"\n >\n ) {\n this.animations.forEach((controls) => controls[methodName]())\n }\n\n play() {\n this.runAll(\"play\")\n }\n\n pause() {\n this.runAll(\"pause\")\n }\n\n // Bound to accomadate common `return animation.stop` pattern\n stop = () => this.runAll(\"stop\")\n\n cancel() {\n this.runAll(\"cancel\")\n }\n\n complete() {\n this.runAll(\"complete\")\n }\n}\n\nfunction getMax(\n animations: GroupedAnimations,\n propName: \"iterationDuration\" | \"duration\"\n): number {\n let max = 0\n\n for (let i = 0; i < animations.length; i++) {\n const value = animations[i][propName]\n if (value !== null && value > max) {\n max = value\n }\n }\n return max\n}\n"],"names":[],"mappings":"MAca,cAAc,CAAA;AAGvB,IAAA,WAAA,CAAY,UAAiD,EAAA;;QAsF7D,
|
|
1
|
+
{"version":3,"file":"GroupAnimation.mjs","sources":["../../../src/animation/GroupAnimation.ts"],"sourcesContent":["import { AnimationPlaybackControls, TimelineWithFallback } from \"./types\"\n\ntype PropNames =\n | \"time\"\n | \"speed\"\n | \"duration\"\n | \"attachTimeline\"\n | \"startTime\"\n | \"state\"\n\nexport type AcceptedAnimations = AnimationPlaybackControls\n\nexport type GroupedAnimations = AcceptedAnimations[]\n\nexport class GroupAnimation implements AnimationPlaybackControls {\n animations: GroupedAnimations\n\n constructor(animations: Array<AcceptedAnimations | undefined>) {\n this.animations = animations.filter(Boolean) as GroupedAnimations\n }\n\n get finished() {\n return Promise.all(\n this.animations.map((animation) => animation.finished)\n )\n }\n\n /**\n * TODO: Filter out cancelled or stopped animations before returning\n */\n private getAll(propName: PropNames) {\n return this.animations[0][propName] as any\n }\n\n private setAll(propName: PropNames, newValue: any) {\n for (let i = 0; i < this.animations.length; i++) {\n ;(this.animations[i][propName] as any) = newValue\n }\n }\n\n attachTimeline(timeline: TimelineWithFallback) {\n const subscriptions = this.animations.map((animation) =>\n animation.attachTimeline(timeline)\n )\n\n return () => {\n subscriptions.forEach((cancel, i) => {\n cancel && cancel()\n this.animations[i].stop()\n })\n }\n }\n\n get time() {\n return this.getAll(\"time\")\n }\n\n set time(time: number) {\n this.setAll(\"time\", time)\n }\n\n get speed() {\n return this.getAll(\"speed\")\n }\n\n set speed(speed: number) {\n this.setAll(\"speed\", speed)\n }\n\n get state() {\n return this.getAll(\"state\")\n }\n\n get startTime() {\n return this.getAll(\"startTime\")\n }\n\n get duration() {\n return getMax(this.animations, \"duration\")\n }\n\n get iterationDuration() {\n return getMax(this.animations, \"iterationDuration\")\n }\n\n private runAll(\n methodName: keyof Omit<\n AnimationPlaybackControls,\n PropNames | \"then\" | \"finished\" | \"iterationDuration\"\n >\n ) {\n this.animations.forEach((controls) => controls[methodName]())\n }\n\n play() {\n this.runAll(\"play\")\n }\n\n pause() {\n this.runAll(\"pause\")\n }\n\n // Bound to accomadate common `return animation.stop` pattern\n stop = () => this.runAll(\"stop\")\n\n cancel() {\n this.runAll(\"cancel\")\n }\n\n complete() {\n this.runAll(\"complete\")\n }\n}\n\nfunction getMax(\n animations: GroupedAnimations,\n propName: \"iterationDuration\" | \"duration\"\n): number {\n let max = 0\n\n for (let i = 0; i < animations.length; i++) {\n const value = animations[i][propName]\n if (value !== null && value > max) {\n max = value\n }\n }\n return max\n}\n"],"names":[],"mappings":"MAca,cAAc,CAAA;AAGvB,IAAA,WAAA,CAAY,UAAiD,EAAA;;QAsF7D,IAAA,CAAA,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QArF5B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,OAAO,CAAsB;IACrE;AAEA,IAAA,IAAI,QAAQ,GAAA;QACR,OAAO,OAAO,CAAC,GAAG,CACd,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,QAAQ,CAAC,CACzD;IACL;AAEA;;AAEG;AACK,IAAA,MAAM,CAAC,QAAmB,EAAA;QAC9B,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAQ;IAC9C;IAEQ,MAAM,CAAC,QAAmB,EAAE,QAAa,EAAA;AAC7C,QAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC3C,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAS,GAAG,QAAQ;QACrD;IACJ;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AC,QAAQ,KAAK,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;IACjE;IAEA,IAAI,GAAA;AACA,QAAA,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IACvB;IAEA,KAAK,GAAA;AACD,QAAA,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IACxB;IAKA,MAAM,GAAA;AACF,QAAA,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;IACzB;IAEA,QAAQ,GAAA;AACJ,QAAA,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;IAC3B;AACH;AAED,SAAS,MAAM,CACX,UAA6B,EAC7B,QAA0C,EAAA;IAE1C,IAAI,GAAG,GAAG,CAAC;AAEX,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACxC,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QACrC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,GAAG,GAAG,EAAE;YAC/B,GAAG,GAAG,KAAK;QACf;IACJ;AACA,IAAA,OAAO,GAAG;AACd;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupAnimationWithThen.mjs","sources":["../../../src/animation/GroupAnimationWithThen.ts"],"sourcesContent":["import { GroupAnimation } from \"./GroupAnimation\"\nimport { AnimationPlaybackControlsWithThen } from \"./types\"\n\nexport class GroupAnimationWithThen\n extends GroupAnimation\n implements AnimationPlaybackControlsWithThen\n{\n then(onResolve: VoidFunction, _onReject?: VoidFunction) {\n return this.finished.finally(onResolve).then(() => {})\n }\n}\n"],"names":[],"mappings":";;AAGM,MAAO,sBACT,SAAQ,cAAc,CAAA;IAGtB,IAAI,CAAC,SAAuB,EAAE,SAAwB,EAAA;AAClD,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"GroupAnimationWithThen.mjs","sources":["../../../src/animation/GroupAnimationWithThen.ts"],"sourcesContent":["import { GroupAnimation } from \"./GroupAnimation\"\nimport { AnimationPlaybackControlsWithThen } from \"./types\"\n\nexport class GroupAnimationWithThen\n extends GroupAnimation\n implements AnimationPlaybackControlsWithThen\n{\n then(onResolve: VoidFunction, _onReject?: VoidFunction) {\n return this.finished.finally(onResolve).then(() => {})\n }\n}\n"],"names":[],"mappings":";;AAGM,MAAO,sBACT,SAAQ,cAAc,CAAA;IAGtB,IAAI,CAAC,SAAuB,EAAE,SAAwB,EAAA;AAClD,QAAA,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,MAAK,EAAE,CAAC,CAAC;IAC1D;AACH;;;;"}
|
|
@@ -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 { activeAnimations } from \"../stats/animation-count\"\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 { 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 { WithPromise } from \"./utils/WithPromise\"\n\nconst percentToProgress = (percent: number) => percent / 100\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 private driver?: DriverControls\n\n private isStopped = false\n\n private generator: KeyframeGenerator<T>\n\n private calculatedDuration: number\n\n private resolvedDuration: number\n\n private totalDuration: number\n\n private 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 private 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 constructor(options: ValueAnimationOptions<T>) {\n super()\n activeAnimations.mainThread++\n\n this.options = options\n this.initAnimation()\n this.play()\n\n if (options.autoplay === false) this.pause()\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({ ...options, keyframes })\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 const animationTime =\n Math.round(timestamp - this.startTime!) * this.playbackSpeed\n\n // Update currentTime\n if (this.holdTime !== null) {\n this.currentTime = this.holdTime\n } else {\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 = animationTime\n }\n }\n\n tick(timestamp: number, sample = false) {\n const {\n generator,\n totalDuration,\n mixKeyframes,\n mirroredGenerator,\n resolvedDuration,\n calculatedDuration,\n } = this\n\n if (this.startTime === null) return generator.next(0)\n\n const {\n delay = 0,\n keyframes,\n repeat,\n repeatType,\n repeatDelay,\n type,\n onUpdate,\n finalKeyframe,\n } = this.options\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 let elapsed = this.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(this.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 const state = isInDelayPhase\n ? { done: false, value: keyframes[0] }\n : frameGenerator.next(elapsed)\n\n if (mixKeyframes) {\n state.value = mixKeyframes(state.value as number)\n }\n\n let { done } = state\n\n if (!isInDelayPhase && calculatedDuration !== null) {\n done =\n this.playbackSpeed >= 0\n ? this.currentTime >= totalDuration\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 * Allows the returned animation to be awaited or promise-chained. Currently\n * resolves when the animation finishes at all but in a future update could/should\n * reject if its cancels.\n */\n then(resolve: VoidFunction, reject?: VoidFunction) {\n return this.finished.then(resolve, reject)\n }\n\n get duration() {\n return millisecondsToSeconds(this.calculatedDuration)\n }\n\n get iterationDuration() {\n const { delay = 0 } = this.options || {}\n return this.duration + millisecondsToSeconds(delay)\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 this.driver?.start(false)\n }\n\n get speed() {\n return this.playbackSpeed\n }\n\n set speed(newSpeed: number) {\n this.updateTime(time.now())\n const hasChanged = this.playbackSpeed !== newSpeed\n this.playbackSpeed = newSpeed\n\n if (hasChanged) {\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\n } else if (!this.startTime) {\n this.startTime = startTime ?? 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.stopDriver()\n this.startTime = this.holdTime = null\n activeAnimations.mainThread--\n }\n\n private stopDriver() {\n if (!this.driver) return\n this.driver.stop()\n this.driver = undefined\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":";;;;;;;;;;;;AA4BA,MAAM,iBAAiB,GAAG,CAAC,OAAe,KAAK,OAAO,GAAG,GAAG,CAAA;AAEtD,MAAO,WACT,SAAQ,WAAW,CAAA;AAkDnB,IAAA,WAAA,CAAY,OAAiC,EAAA;AACzC,QAAA,KAAK,EAAE,CAAA;QAhDX,IAAK,CAAA,KAAA,GAAuB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AC5B,IAAI,CAAC,aAAa,EAAE,CAAA;SACvB;AAED,QAAA,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAA;AACnB,QAAA,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;KAChC;AACJ,CAAA;AAED;AACM,SAAU,YAAY,CACxB,OAAiC,EAAA;AAEjC,IAAA,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAA;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 { activeAnimations } from \"../stats/animation-count\"\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 { 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 { WithPromise } from \"./utils/WithPromise\"\n\nconst percentToProgress = (percent: number) => percent / 100\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 private driver?: DriverControls\n\n private isStopped = false\n\n private generator: KeyframeGenerator<T>\n\n private calculatedDuration: number\n\n private resolvedDuration: number\n\n private totalDuration: number\n\n private 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 private 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 constructor(options: ValueAnimationOptions<T>) {\n super()\n activeAnimations.mainThread++\n\n this.options = options\n this.initAnimation()\n this.play()\n\n if (options.autoplay === false) this.pause()\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({ ...options, keyframes })\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 const animationTime =\n Math.round(timestamp - this.startTime!) * this.playbackSpeed\n\n // Update currentTime\n if (this.holdTime !== null) {\n this.currentTime = this.holdTime\n } else {\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 = animationTime\n }\n }\n\n tick(timestamp: number, sample = false) {\n const {\n generator,\n totalDuration,\n mixKeyframes,\n mirroredGenerator,\n resolvedDuration,\n calculatedDuration,\n } = this\n\n if (this.startTime === null) return generator.next(0)\n\n const {\n delay = 0,\n keyframes,\n repeat,\n repeatType,\n repeatDelay,\n type,\n onUpdate,\n finalKeyframe,\n } = this.options\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 let elapsed = this.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(this.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 const state = isInDelayPhase\n ? { done: false, value: keyframes[0] }\n : frameGenerator.next(elapsed)\n\n if (mixKeyframes) {\n state.value = mixKeyframes(state.value as number)\n }\n\n let { done } = state\n\n if (!isInDelayPhase && calculatedDuration !== null) {\n done =\n this.playbackSpeed >= 0\n ? this.currentTime >= totalDuration\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 * Allows the returned animation to be awaited or promise-chained. Currently\n * resolves when the animation finishes at all but in a future update could/should\n * reject if its cancels.\n */\n then(resolve: VoidFunction, reject?: VoidFunction) {\n return this.finished.then(resolve, reject)\n }\n\n get duration() {\n return millisecondsToSeconds(this.calculatedDuration)\n }\n\n get iterationDuration() {\n const { delay = 0 } = this.options || {}\n return this.duration + millisecondsToSeconds(delay)\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 this.driver?.start(false)\n }\n\n get speed() {\n return this.playbackSpeed\n }\n\n set speed(newSpeed: number) {\n this.updateTime(time.now())\n const hasChanged = this.playbackSpeed !== newSpeed\n this.playbackSpeed = newSpeed\n\n if (hasChanged) {\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\n } else if (!this.startTime) {\n this.startTime = startTime ?? 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.stopDriver()\n this.startTime = this.holdTime = null\n activeAnimations.mainThread--\n }\n\n private stopDriver() {\n if (!this.driver) return\n this.driver.stop()\n this.driver = undefined\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":";;;;;;;;;;;;AA4BA,MAAM,iBAAiB,GAAG,CAAC,OAAe,KAAK,OAAO,GAAG,GAAG;AAEtD,MAAO,WACT,SAAQ,WAAW,CAAA;AAkDnB,IAAA,WAAA,CAAY,OAAiC,EAAA;AACzC,QAAA,KAAK,EAAE;QAhDX,IAAA,CAAA,KAAK,GAAuB,MAAM;QAElC,IAAA,CAAA,SAAS,GAAkB,IAAI;QAQvB,IAAA,CAAA,SAAS,GAAG,KAAK;AAYzB;;AAEG;QACK,IAAA,CAAA,WAAW,GAAW,CAAC;AAE/B;;AAEG;QACK,IAAA,CAAA,QAAQ,GAAkB,IAAI;AAEtC;;AAEG;QACK,IAAA,CAAA,aAAa,GAAG,CAAC;AA+WzB;;;AAGG;QACH,IAAA,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U,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;;;;"}
|
|
@@ -39,13 +39,14 @@ class NativeAnimation extends WithPromise {
|
|
|
39
39
|
if (this.updateMotionValue) {
|
|
40
40
|
this.updateMotionValue(keyframe);
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
/**
|
|
43
|
+
* If we can, we want to commit the final style as set by the user,
|
|
44
|
+
* rather than the computed keyframe value supplied by the animation.
|
|
45
|
+
* We always do this, even when a motion value is present, to prevent
|
|
46
|
+
* a visual flash in Firefox where the WAAPI animation's fill is removed
|
|
47
|
+
* during cancel() before the scheduled render can apply the correct value.
|
|
48
|
+
*/
|
|
49
|
+
setStyle(element, name, keyframe);
|
|
49
50
|
this.animation.cancel();
|
|
50
51
|
}
|
|
51
52
|
onComplete?.();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeAnimation.mjs","sources":["../../../src/animation/NativeAnimation.ts"],"sourcesContent":["import {\n invariant,\n millisecondsToSeconds,\n noop,\n secondsToMilliseconds,\n} from \"motion-utils\"\nimport { setStyle } from \"../render/dom/style-set\"\nimport { supportsScrollTimeline } from \"../utils/supports/scroll-timeline\"\nimport { getFinalKeyframe } from \"./keyframes/get-final\"\nimport {\n AnimationPlaybackControlsWithThen,\n AnyResolvedKeyframe,\n DOMValueAnimationOptions,\n TimelineWithFallback,\n} from \"./types\"\nimport { WithPromise } from \"./utils/WithPromise\"\nimport { startWaapiAnimation } from \"./waapi/start-waapi-animation\"\nimport { applyGeneratorOptions } from \"./waapi/utils/apply-generator\"\n\nexport interface NativeAnimationOptions<V extends AnyResolvedKeyframe = number>\n extends DOMValueAnimationOptions<V> {\n pseudoElement?: string\n startTime?: number\n}\n\n/**\n * NativeAnimation implements AnimationPlaybackControls for the browser's Web Animations API.\n */\nexport class NativeAnimation<T extends AnyResolvedKeyframe>\n extends WithPromise\n implements AnimationPlaybackControlsWithThen\n{\n /**\n * The interfaced Web Animation API animation\n */\n protected animation: Animation\n\n protected finishedTime: number | null = null\n\n protected options: NativeAnimationOptions\n\n private allowFlatten: boolean\n\n private isStopped = false\n\n private isPseudoElement: boolean\n\n /**\n * Tracks a manually-set start time that takes precedence over WAAPI's\n * dynamic startTime. This is cleared when play() or time setter is called,\n * allowing WAAPI to take over timing.\n */\n protected manualStartTime: number | null = null\n\n constructor(options?: NativeAnimationOptions) {\n super()\n\n if (!options) return\n\n const {\n element,\n name,\n keyframes,\n pseudoElement,\n allowFlatten = false,\n finalKeyframe,\n onComplete,\n } = options as any\n\n this.isPseudoElement = Boolean(pseudoElement)\n\n this.allowFlatten = allowFlatten\n this.options = options\n\n invariant(\n typeof options.type !== \"string\",\n `Mini animate() doesn't support \"type\" as a string.`,\n \"mini-spring\"\n )\n\n const transition = applyGeneratorOptions(options)\n\n this.animation = startWaapiAnimation(\n element,\n name,\n keyframes,\n transition,\n pseudoElement\n )\n\n if (transition.autoplay === false) {\n this.animation.pause()\n }\n\n this.animation.onfinish = () => {\n this.finishedTime = this.time\n\n if (!pseudoElement) {\n const keyframe = getFinalKeyframe(\n keyframes as any,\n this.options as any,\n finalKeyframe,\n this.speed\n )\n if (this.updateMotionValue) {\n this.updateMotionValue(keyframe)\n } else {\n /**\n * If we can, we want to commit the final style as set by the user,\n * rather than the computed keyframe value supplied by the animation.\n */\n setStyle(element, name, keyframe)\n }\n\n this.animation.cancel()\n }\n\n onComplete?.()\n this.notifyFinished()\n }\n }\n\n updateMotionValue?(value?: T): void\n\n play() {\n if (this.isStopped) return\n\n this.manualStartTime = null\n this.animation.play()\n\n if (this.state === \"finished\") {\n this.updateFinished()\n }\n }\n\n pause() {\n this.animation.pause()\n }\n\n complete() {\n this.animation.finish?.()\n }\n\n cancel() {\n try {\n this.animation.cancel()\n } catch (e) {}\n }\n\n stop() {\n if (this.isStopped) return\n this.isStopped = true\n const { state } = this\n\n if (state === \"idle\" || state === \"finished\") {\n return\n }\n\n if (this.updateMotionValue) {\n this.updateMotionValue()\n } else {\n this.commitStyles()\n }\n\n if (!this.isPseudoElement) this.cancel()\n }\n\n /**\n * WAAPI doesn't natively have any interruption capabilities.\n *\n * In this method, we commit styles back to the DOM before cancelling\n * the animation.\n *\n * This is designed to be overridden by NativeAnimationExtended, which\n * will create a renderless JS animation and sample it twice to calculate\n * its current value, \"previous\" value, and therefore allow\n * Motion to also correctly calculate velocity for any subsequent animation\n * while deferring the commit until the next animation frame.\n */\n protected commitStyles() {\n const element = this.options?.element\n if (!this.isPseudoElement && element?.isConnected) {\n this.animation.commitStyles?.()\n }\n }\n\n get duration() {\n const duration =\n this.animation.effect?.getComputedTiming?.().duration || 0\n\n return millisecondsToSeconds(Number(duration))\n }\n\n get iterationDuration() {\n const { delay = 0 } = this.options || {}\n return this.duration + millisecondsToSeconds(delay)\n }\n\n get time() {\n return millisecondsToSeconds(Number(this.animation.currentTime) || 0)\n }\n\n set time(newTime: number) {\n this.manualStartTime = null\n this.finishedTime = null\n this.animation.currentTime = secondsToMilliseconds(newTime)\n }\n\n /**\n * The playback speed of the animation.\n * 1 = normal speed, 2 = double speed, 0.5 = half speed.\n */\n get speed() {\n return this.animation.playbackRate\n }\n\n set speed(newSpeed: number) {\n // Allow backwards playback after finishing\n if (newSpeed < 0) this.finishedTime = null\n\n this.animation.playbackRate = newSpeed\n }\n\n get state() {\n return this.finishedTime !== null\n ? \"finished\"\n : this.animation.playState\n }\n\n get startTime() {\n return this.manualStartTime ?? Number(this.animation.startTime)\n }\n\n set startTime(newStartTime: number) {\n this.manualStartTime = this.animation.startTime = newStartTime\n }\n\n /**\n * Attaches a timeline to the animation, for instance the `ScrollTimeline`.\n */\n attachTimeline({ timeline, observe }: TimelineWithFallback): VoidFunction {\n if (this.allowFlatten) {\n this.animation.effect?.updateTiming({ easing: \"linear\" })\n }\n\n this.animation.onfinish = null\n\n if (timeline && supportsScrollTimeline()) {\n this.animation.timeline = timeline as any\n\n return noop<void>\n } else {\n return observe(this)\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;AAyBA;;AAEG;AACG,MAAO,eACT,SAAQ,WAAW,CAAA;AAyBnB,IAAA,WAAA,CAAY,OAAgC,EAAA;AACxC,QAAA,KAAK,EAAE,CAAA;QAlBD,IAAY,CAAA,YAAA,GAAkB,IAAI,CAAA;QAMpC,IAAS,CAAA,SAAA,GAAG,KAAK,CAAA;AAIzB;;;;AAIG;QACO,IAAe,CAAA,eAAA,GAAkB,IAAI,CAAA;AAK3C,QAAA,IAAI,CAAC,OAAO;YAAE,OAAM;AAEpB,QAAA,MAAM,EACF,OAAO,EACP,IAAI,EACJ,SAAS,EACT,aAAa,EACb,YAAY,GAAG,KAAK,EACpB,aAAa,EACb,UAAU,GACb,GAAG,OAAc,CAAA;AAElB,QAAA,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;AAE7C,QAAA,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;AAChC,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;AAEtB,QAAA,SAAS,CACL,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,EAChC,CAAoD,kDAAA,CAAA,EACpD,aAAa,CAChB,CAAA;AAED,QAAA,MAAM,U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AAC,YAAY,EAAE;AACnB,YAAA,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAA;SAC5D;AAED,QAAA,IAAI,CAAC,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAA;AAE9B,QAAA,IAAI,QAAQ,IAAI,sBAAsB,EAAE,EAAE;AACtC,YAAA,IAAI,CAAC,SAAS,CAAC,QAAQ,GAAG,QAAe,CAAA;AAEzC,YAAA,OAAO,IAAU,CAAA;SACpB;aAAM;AACH,YAAA,OAAO,OAAO,CAAC,IAAI,CAAC,CAAA;SACvB;KACJ;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"NativeAnimation.mjs","sources":["../../../src/animation/NativeAnimation.ts"],"sourcesContent":["import {\n invariant,\n millisecondsToSeconds,\n noop,\n secondsToMilliseconds,\n} from \"motion-utils\"\nimport { setStyle } from \"../render/dom/style-set\"\nimport { supportsScrollTimeline } from \"../utils/supports/scroll-timeline\"\nimport { getFinalKeyframe } from \"./keyframes/get-final\"\nimport {\n AnimationPlaybackControlsWithThen,\n AnyResolvedKeyframe,\n DOMValueAnimationOptions,\n TimelineWithFallback,\n} from \"./types\"\nimport { WithPromise } from \"./utils/WithPromise\"\nimport { startWaapiAnimation } from \"./waapi/start-waapi-animation\"\nimport { applyGeneratorOptions } from \"./waapi/utils/apply-generator\"\n\nexport interface NativeAnimationOptions<V extends AnyResolvedKeyframe = number>\n extends DOMValueAnimationOptions<V> {\n pseudoElement?: string\n startTime?: number\n}\n\n/**\n * NativeAnimation implements AnimationPlaybackControls for the browser's Web Animations API.\n */\nexport class NativeAnimation<T extends AnyResolvedKeyframe>\n extends WithPromise\n implements AnimationPlaybackControlsWithThen\n{\n /**\n * The interfaced Web Animation API animation\n */\n protected animation: Animation\n\n protected finishedTime: number | null = null\n\n protected options: NativeAnimationOptions\n\n private allowFlatten: boolean\n\n private isStopped = false\n\n private isPseudoElement: boolean\n\n /**\n * Tracks a manually-set start time that takes precedence over WAAPI's\n * dynamic startTime. This is cleared when play() or time setter is called,\n * allowing WAAPI to take over timing.\n */\n protected manualStartTime: number | null = null\n\n constructor(options?: NativeAnimationOptions) {\n super()\n\n if (!options) return\n\n const {\n element,\n name,\n keyframes,\n pseudoElement,\n allowFlatten = false,\n finalKeyframe,\n onComplete,\n } = options as any\n\n this.isPseudoElement = Boolean(pseudoElement)\n\n this.allowFlatten = allowFlatten\n this.options = options\n\n invariant(\n typeof options.type !== \"string\",\n `Mini animate() doesn't support \"type\" as a string.`,\n \"mini-spring\"\n )\n\n const transition = applyGeneratorOptions(options)\n\n this.animation = startWaapiAnimation(\n element,\n name,\n keyframes,\n transition,\n pseudoElement\n )\n\n if (transition.autoplay === false) {\n this.animation.pause()\n }\n\n this.animation.onfinish = () => {\n this.finishedTime = this.time\n\n if (!pseudoElement) {\n const keyframe = getFinalKeyframe(\n keyframes as any,\n this.options as any,\n finalKeyframe,\n this.speed\n )\n if (this.updateMotionValue) {\n this.updateMotionValue(keyframe)\n }\n\n /**\n * If we can, we want to commit the final style as set by the user,\n * rather than the computed keyframe value supplied by the animation.\n * We always do this, even when a motion value is present, to prevent\n * a visual flash in Firefox where the WAAPI animation's fill is removed\n * during cancel() before the scheduled render can apply the correct value.\n */\n setStyle(element, name, keyframe)\n\n this.animation.cancel()\n }\n\n onComplete?.()\n this.notifyFinished()\n }\n }\n\n updateMotionValue?(value?: T): void\n\n play() {\n if (this.isStopped) return\n\n this.manualStartTime = null\n this.animation.play()\n\n if (this.state === \"finished\") {\n this.updateFinished()\n }\n }\n\n pause() {\n this.animation.pause()\n }\n\n complete() {\n this.animation.finish?.()\n }\n\n cancel() {\n try {\n this.animation.cancel()\n } catch (e) {}\n }\n\n stop() {\n if (this.isStopped) return\n this.isStopped = true\n const { state } = this\n\n if (state === \"idle\" || state === \"finished\") {\n return\n }\n\n if (this.updateMotionValue) {\n this.updateMotionValue()\n } else {\n this.commitStyles()\n }\n\n if (!this.isPseudoElement) this.cancel()\n }\n\n /**\n * WAAPI doesn't natively have any interruption capabilities.\n *\n * In this method, we commit styles back to the DOM before cancelling\n * the animation.\n *\n * This is designed to be overridden by NativeAnimationExtended, which\n * will create a renderless JS animation and sample it twice to calculate\n * its current value, \"previous\" value, and therefore allow\n * Motion to also correctly calculate velocity for any subsequent animation\n * while deferring the commit until the next animation frame.\n */\n protected commitStyles() {\n const element = this.options?.element\n if (!this.isPseudoElement && element?.isConnected) {\n this.animation.commitStyles?.()\n }\n }\n\n get duration() {\n const duration =\n this.animation.effect?.getComputedTiming?.().duration || 0\n\n return millisecondsToSeconds(Number(duration))\n }\n\n get iterationDuration() {\n const { delay = 0 } = this.options || {}\n return this.duration + millisecondsToSeconds(delay)\n }\n\n get time() {\n return millisecondsToSeconds(Number(this.animation.currentTime) || 0)\n }\n\n set time(newTime: number) {\n this.manualStartTime = null\n this.finishedTime = null\n this.animation.currentTime = secondsToMilliseconds(newTime)\n }\n\n /**\n * The playback speed of the animation.\n * 1 = normal speed, 2 = double speed, 0.5 = half speed.\n */\n get speed() {\n return this.animation.playbackRate\n }\n\n set speed(newSpeed: number) {\n // Allow backwards playback after finishing\n if (newSpeed < 0) this.finishedTime = null\n\n this.animation.playbackRate = newSpeed\n }\n\n get state() {\n return this.finishedTime !== null\n ? \"finished\"\n : this.animation.playState\n }\n\n get startTime() {\n return this.manualStartTime ?? Number(this.animation.startTime)\n }\n\n set startTime(newStartTime: number) {\n this.manualStartTime = this.animation.startTime = newStartTime\n }\n\n /**\n * Attaches a timeline to the animation, for instance the `ScrollTimeline`.\n */\n attachTimeline({ timeline, observe }: TimelineWithFallback): VoidFunction {\n if (this.allowFlatten) {\n this.animation.effect?.updateTiming({ easing: \"linear\" })\n }\n\n this.animation.onfinish = null\n\n if (timeline && supportsScrollTimeline()) {\n this.animation.timeline = timeline as any\n\n return noop<void>\n } else {\n return observe(this)\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;AAyBA;;AAEG;AACG,MAAO,eACT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Y,KAAK;AACzB,cAAE;AACF,cAAE,IAAI,CAAC,SAAS,CAAC,SAAS;IAClC;AAEA,IAAA,IAAI,SAAS,GAAA;AACT,QAAA,OAAO,IAAI,CAAC,eAAe,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;IACnE;IAEA,IAAI,SAAS,CAAC,YAAoB,EAAA;QAC9B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,GAAG,YAAY;IAClE;AAEA;;AAEG;AACH,IAAA,cAAc,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAwB,EAAA;AACtD,QAAA,IAAI,IAAI,CAAC,YAAY,EAAE;AACnB,YAAA,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;QAC7D;AAEA,QAAA,IAAI,CAAC,SAAS,CAAC,QAAQ,GAAG,IAAI;AAE9B,QAAA,IAAI,QAAQ,IAAI,sBAAsB,EAAE,EAAE;AACtC,YAAA,IAAI,CAAC,SAAS,CAAC,QAAQ,GAAG,QAAe;AAEzC,YAAA,OAAO,IAAU;QACrB;aAAO;AACH,YAAA,OAAO,OAAO,CAAC,IAAI,CAAC;QACxB;IACJ;AACH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeAnimationExtended.mjs","sources":["../../../src/animation/NativeAnimationExtended.ts"],"sourcesContent":["import { clamp } from \"motion-utils\"\nimport { time } from \"../frameloop/sync-time\"\nimport { JSAnimation } from \"./JSAnimation\"\nimport { NativeAnimation, NativeAnimationOptions } from \"./NativeAnimation\"\nimport { AnyResolvedKeyframe, ValueAnimationOptions } from \"./types\"\nimport { replaceTransitionType } from \"./utils/replace-transition-type\"\nimport { replaceStringEasing } from \"./waapi/utils/unsupported-easing\"\n\nexport type NativeAnimationOptionsExtended<T extends AnyResolvedKeyframe> =\n NativeAnimationOptions & ValueAnimationOptions<T> & NativeAnimationOptions\n\n/**\n * 10ms is chosen here as it strikes a balance between smooth\n * results (more than one keyframe per frame at 60fps) and\n * keyframe quantity.\n */\nconst sampleDelta = 10 //ms\n\nexport class NativeAnimationExtended<\n T extends AnyResolvedKeyframe\n> extends NativeAnimation<T> {\n options: NativeAnimationOptionsExtended<T>\n\n constructor(options: NativeAnimationOptionsExtended<T>) {\n /**\n * The base NativeAnimation function only supports a subset\n * of Motion easings, and WAAPI also only supports some\n * easing functions via string/cubic-bezier definitions.\n *\n * This function replaces those unsupported easing functions\n * with a JS easing function. This will later get compiled\n * to a linear() easing function.\n */\n replaceStringEasing(options)\n\n /**\n * Ensure we replace the transition type with a generator function\n * before passing to WAAPI.\n *\n * TODO: Does this have a better home? It could be shared with\n * JSAnimation.\n */\n replaceTransitionType(options)\n\n super(options)\n\n if (options.startTime !== undefined) {\n this.startTime = options.startTime\n }\n\n this.options = options\n }\n\n /**\n * WAAPI doesn't natively have any interruption capabilities.\n *\n * Rather than read committed styles back out of the DOM, we can\n * create a renderless JS animation and sample it twice to calculate\n * its current value, \"previous\" value, and therefore allow\n * Motion to calculate velocity for any subsequent animation.\n */\n updateMotionValue(value?: T) {\n const { motionValue, onUpdate, onComplete, element, ...options } =\n this.options\n\n if (!motionValue) return\n\n if (value !== undefined) {\n motionValue.set(value)\n return\n }\n\n const sampleAnimation = new JSAnimation({\n ...options,\n autoplay: false,\n })\n\n /**\n * Use wall-clock elapsed time for sampling.\n * Under CPU load, WAAPI's currentTime may not reflect actual\n * elapsed time, causing incorrect sampling and visual jumps.\n */\n const sampleTime = Math.max(sampleDelta, time.now() - this.startTime)\n const delta = clamp(0, sampleDelta, sampleTime - sampleDelta)\n\n motionValue.setWithVelocity(\n sampleAnimation.sample(Math.max(0, sampleTime - delta)).value,\n sampleAnimation.sample(sampleTime).value,\n delta\n )\n\n sampleAnimation.stop()\n }\n}\n"],"names":[],"mappings":";;;;;;;AAWA;;;;AAIG;AACH,MAAM,WAAW,GAAG,EAAE,CAAA;AAEhB,MAAO,uBAEX,SAAQ,eAAkB,CAAA;AAGxB,IAAA,WAAA,CAAY,OAA0C,EAAA;AAClD;;;;;;;;AAQG;QACH,mBAAmB,CAAC,OAAO,CAAC
|
|
1
|
+
{"version":3,"file":"NativeAnimationExtended.mjs","sources":["../../../src/animation/NativeAnimationExtended.ts"],"sourcesContent":["import { clamp } from \"motion-utils\"\nimport { time } from \"../frameloop/sync-time\"\nimport { JSAnimation } from \"./JSAnimation\"\nimport { NativeAnimation, NativeAnimationOptions } from \"./NativeAnimation\"\nimport { AnyResolvedKeyframe, ValueAnimationOptions } from \"./types\"\nimport { replaceTransitionType } from \"./utils/replace-transition-type\"\nimport { replaceStringEasing } from \"./waapi/utils/unsupported-easing\"\n\nexport type NativeAnimationOptionsExtended<T extends AnyResolvedKeyframe> =\n NativeAnimationOptions & ValueAnimationOptions<T> & NativeAnimationOptions\n\n/**\n * 10ms is chosen here as it strikes a balance between smooth\n * results (more than one keyframe per frame at 60fps) and\n * keyframe quantity.\n */\nconst sampleDelta = 10 //ms\n\nexport class NativeAnimationExtended<\n T extends AnyResolvedKeyframe\n> extends NativeAnimation<T> {\n options: NativeAnimationOptionsExtended<T>\n\n constructor(options: NativeAnimationOptionsExtended<T>) {\n /**\n * The base NativeAnimation function only supports a subset\n * of Motion easings, and WAAPI also only supports some\n * easing functions via string/cubic-bezier definitions.\n *\n * This function replaces those unsupported easing functions\n * with a JS easing function. This will later get compiled\n * to a linear() easing function.\n */\n replaceStringEasing(options)\n\n /**\n * Ensure we replace the transition type with a generator function\n * before passing to WAAPI.\n *\n * TODO: Does this have a better home? It could be shared with\n * JSAnimation.\n */\n replaceTransitionType(options)\n\n super(options)\n\n if (options.startTime !== undefined) {\n this.startTime = options.startTime\n }\n\n this.options = options\n }\n\n /**\n * WAAPI doesn't natively have any interruption capabilities.\n *\n * Rather than read committed styles back out of the DOM, we can\n * create a renderless JS animation and sample it twice to calculate\n * its current value, \"previous\" value, and therefore allow\n * Motion to calculate velocity for any subsequent animation.\n */\n updateMotionValue(value?: T) {\n const { motionValue, onUpdate, onComplete, element, ...options } =\n this.options\n\n if (!motionValue) return\n\n if (value !== undefined) {\n motionValue.set(value)\n return\n }\n\n const sampleAnimation = new JSAnimation({\n ...options,\n autoplay: false,\n })\n\n /**\n * Use wall-clock elapsed time for sampling.\n * Under CPU load, WAAPI's currentTime may not reflect actual\n * elapsed time, causing incorrect sampling and visual jumps.\n */\n const sampleTime = Math.max(sampleDelta, time.now() - this.startTime)\n const delta = clamp(0, sampleDelta, sampleTime - sampleDelta)\n\n motionValue.setWithVelocity(\n sampleAnimation.sample(Math.max(0, sampleTime - delta)).value,\n sampleAnimation.sample(sampleTime).value,\n delta\n )\n\n sampleAnimation.stop()\n }\n}\n"],"names":[],"mappings":";;;;;;;AAWA;;;;AAIG;AACH,MAAM,WAAW,GAAG,EAAE,CAAA;AAEhB,MAAO,uBAEX,SAAQ,eAAkB,CAAA;AAGxB,IAAA,WAAA,CAAY,OAA0C,EAAA;AAClD;;;;;;;;AAQG;QACH,mBAAmB,CAAC,OAAO,CAAC;AAE5B;;;;;;AAMG;QACH,qBAAqB,CAAC,OAAO,CAAC;QAE9B,KAAK,CAAC,OAAO,CAAC;AAEd,QAAA,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE;AACjC,YAAA,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS;QACtC;AAEA,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;IAC1B;AAEA;;;;;;;AAOG;AACH,IAAA,iBAAiB,CAAC,KAAS,EAAA;AACvB,QAAA,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,GAC5D,IAAI,CAAC,OAAO;AAEhB,QAAA,IAAI,CAAC,WAAW;YAAE;AAElB,QAAA,IAAI,KAAK,KAAK,SAAS,EAAE;AACrB,YAAA,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC;YACtB;QACJ;AAEA,QAAA,MAAM,eAAe,GAAG,IAAI,WAAW,CAAC;AACpC,YAAA,GAAG,OAAO;AACV,YAAA,QAAQ,EAAE,KAAK;AAClB,SAAA,CAAC;AAEF;;;;AAIG;AACH,QAAA,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;AACrE,QAAA,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,EAAE,WAAW,EAAE,UAAU,GAAG,WAAW,CAAC;AAE7D,QAAA,WAAW,CAAC,eAAe,CACvB,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,EAC7D,eAAe,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,EACxC,KAAK,CACR;QAED,eAAe,CAAC,IAAI,EAAE;IAC1B;AACH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeAnimationWrapper.mjs","sources":["../../../src/animation/NativeAnimationWrapper.ts"],"sourcesContent":["import { NativeAnimation } from \"./NativeAnimation\"\nimport { AnyResolvedKeyframe } from \"./types\"\n\nexport class NativeAnimationWrapper<\n T extends AnyResolvedKeyframe\n> extends NativeAnimation<T> {\n constructor(animation: Animation) {\n super()\n\n this.animation = animation\n animation.onfinish = () => {\n this.finishedTime = this.time\n this.notifyFinished()\n }\n }\n}\n"],"names":[],"mappings":";;AAGM,MAAO,sBAEX,SAAQ,eAAkB,CAAA;AACxB,IAAA,WAAA,CAAY,SAAoB,EAAA;AAC5B,QAAA,KAAK,EAAE
|
|
1
|
+
{"version":3,"file":"NativeAnimationWrapper.mjs","sources":["../../../src/animation/NativeAnimationWrapper.ts"],"sourcesContent":["import { NativeAnimation } from \"./NativeAnimation\"\nimport { AnyResolvedKeyframe } from \"./types\"\n\nexport class NativeAnimationWrapper<\n T extends AnyResolvedKeyframe\n> extends NativeAnimation<T> {\n constructor(animation: Animation) {\n super()\n\n this.animation = animation\n animation.onfinish = () => {\n this.finishedTime = this.time\n this.notifyFinished()\n }\n }\n}\n"],"names":[],"mappings":";;AAGM,MAAO,sBAEX,SAAQ,eAAkB,CAAA;AACxB,IAAA,WAAA,CAAY,SAAoB,EAAA;AAC5B,QAAA,KAAK,EAAE;AAEP,QAAA,IAAI,CAAC,SAAS,GAAG,SAAS;AAC1B,QAAA,SAAS,CAAC,QAAQ,GAAG,MAAK;AACtB,YAAA,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,IAAI;YAC7B,IAAI,CAAC,cAAc,EAAE;AACzB,QAAA,CAAC;IACL;AACH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"single-value.mjs","sources":["../../../../src/animation/animate/single-value.ts"],"sourcesContent":["import { animateMotionValue } from \"../interfaces/motion-value\"\nimport type {\n AnimationPlaybackControlsWithThen,\n AnyResolvedKeyframe,\n UnresolvedValueKeyframe,\n ValueAnimationTransition,\n} from \"../types\"\nimport {\n motionValue as createMotionValue,\n MotionValue,\n} from \"../../value\"\nimport { isMotionValue } from \"../../value/utils/is-motion-value\"\n\nexport function animateSingleValue<V extends AnyResolvedKeyframe>(\n value: MotionValue<V> | V,\n keyframes: V | UnresolvedValueKeyframe<V>[],\n options?: ValueAnimationTransition\n): AnimationPlaybackControlsWithThen {\n const motionValue = isMotionValue(value) ? value : createMotionValue(value)\n\n motionValue.start(animateMotionValue(\"\", motionValue, keyframes, options))\n\n return motionValue.animation!\n}\n"],"names":["motionValue","createMotionValue"],"mappings":";;;;SAagB,kBAAkB,CAC9B,KAAyB,EACzB,SAA2C,EAC3C,OAAkC,EAAA;AAElC,IAAA,MAAMA,aAAW,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,KAAK,GAAGC,WAAiB,CAAC,KAAK,CAAC
|
|
1
|
+
{"version":3,"file":"single-value.mjs","sources":["../../../../src/animation/animate/single-value.ts"],"sourcesContent":["import { animateMotionValue } from \"../interfaces/motion-value\"\nimport type {\n AnimationPlaybackControlsWithThen,\n AnyResolvedKeyframe,\n UnresolvedValueKeyframe,\n ValueAnimationTransition,\n} from \"../types\"\nimport {\n motionValue as createMotionValue,\n MotionValue,\n} from \"../../value\"\nimport { isMotionValue } from \"../../value/utils/is-motion-value\"\n\nexport function animateSingleValue<V extends AnyResolvedKeyframe>(\n value: MotionValue<V> | V,\n keyframes: V | UnresolvedValueKeyframe<V>[],\n options?: ValueAnimationTransition\n): AnimationPlaybackControlsWithThen {\n const motionValue = isMotionValue(value) ? value : createMotionValue(value)\n\n motionValue.start(animateMotionValue(\"\", motionValue, keyframes, options))\n\n return motionValue.animation!\n}\n"],"names":["motionValue","createMotionValue"],"mappings":";;;;SAagB,kBAAkB,CAC9B,KAAyB,EACzB,SAA2C,EAC3C,OAAkC,EAAA;AAElC,IAAA,MAAMA,aAAW,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,KAAK,GAAGC,WAAiB,CAAC,KAAK,CAAC;AAE3E,IAAAD,aAAW,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE,EAAEA,aAAW,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAE1E,OAAOA,aAAW,CAAC,SAAU;AACjC;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { time } from '../../frameloop/sync-time.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { frameData, cancelFrame, frame } from '../../frameloop/frame.mjs';
|
|
3
3
|
|
|
4
4
|
const frameloopDriver = (update) => {
|
|
5
5
|
const passTimestamp = ({ timestamp }) => update(timestamp);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frame.mjs","sources":["../../../../src/animation/drivers/frame.ts"],"sourcesContent":["import { cancelFrame, frame, frameData } from \"../../frameloop\"\nimport { time } from \"../../frameloop/sync-time\"\nimport { FrameData } from \"../../frameloop/types\"\nimport { Driver } from \"./types\"\n\nexport const frameloopDriver: Driver = (update) => {\n const passTimestamp = ({ timestamp }: FrameData) => update(timestamp)\n\n return {\n start: (keepAlive = true) => frame.update(passTimestamp, keepAlive),\n stop: () => cancelFrame(passTimestamp),\n /**\n * If we're processing this frame we can use the\n * framelocked timestamp to keep things in sync.\n */\n now: () => (frameData.isProcessing ? frameData.timestamp : time.now()),\n }\n}\n"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"frame.mjs","sources":["../../../../src/animation/drivers/frame.ts"],"sourcesContent":["import { cancelFrame, frame, frameData } from \"../../frameloop\"\nimport { time } from \"../../frameloop/sync-time\"\nimport { FrameData } from \"../../frameloop/types\"\nimport { Driver } from \"./types\"\n\nexport const frameloopDriver: Driver = (update) => {\n const passTimestamp = ({ timestamp }: FrameData) => update(timestamp)\n\n return {\n start: (keepAlive = true) => frame.update(passTimestamp, keepAlive),\n stop: () => cancelFrame(passTimestamp),\n /**\n * If we're processing this frame we can use the\n * framelocked timestamp to keep things in sync.\n */\n now: () => (frameData.isProcessing ? frameData.timestamp : time.now()),\n }\n}\n"],"names":[],"mappings":";;;AAKO,MAAM,eAAe,GAAW,CAAC,MAAM,KAAI;AAC9C,IAAA,MAAM,aAAa,GAAG,CAAC,EAAE,SAAS,EAAa,KAAK,MAAM,CAAC,SAAS,CAAC;IAErE,OAAO;AACH,QAAA,KAAK,EAAE,CAAC,SAAS,GAAG,IAAI,KAAK,KAAK,CAAC,MAAM,CAAC,aAAa,EAAE,SAAS,CAAC;AACnE,QAAA,IAAI,EAAE,MAAM,WAAW,CAAC,aAAa,CAAC;AACtC;;;AAGG;QACH,GAAG,EAAE,OAAO,SAAS,CAAC,YAAY,GAAG,SAAS,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;KACzE;AACL;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inertia.mjs","sources":["../../../../src/animation/generators/inertia.ts"],"sourcesContent":["import {\n AnimationState,\n KeyframeGenerator,\n ValueAnimationOptions,\n} from \"../types\"\nimport { spring as createSpring } from \"./spring\"\nimport { calcGeneratorVelocity } from \"./utils/velocity\"\n\nexport function inertia({\n keyframes,\n velocity = 0.0,\n power = 0.8,\n timeConstant = 325,\n bounceDamping = 10,\n bounceStiffness = 500,\n modifyTarget,\n min,\n max,\n restDelta = 0.5,\n restSpeed,\n}: ValueAnimationOptions<number>): KeyframeGenerator<number> {\n const origin = keyframes[0]\n\n const state: AnimationState<number> = {\n done: false,\n value: origin,\n }\n\n const isOutOfBounds = (v: number) =>\n (min !== undefined && v < min) || (max !== undefined && v > max)\n\n const nearestBoundary = (v: number) => {\n if (min === undefined) return max\n if (max === undefined) return min\n\n return Math.abs(min - v) < Math.abs(max - v) ? min : max\n }\n\n let amplitude = power * velocity\n const ideal = origin + amplitude\n const target = modifyTarget === undefined ? ideal : modifyTarget(ideal)\n\n /**\n * If the target has changed we need to re-calculate the amplitude, otherwise\n * the animation will start from the wrong position.\n */\n if (target !== ideal) amplitude = target - origin\n\n const calcDelta = (t: number) => -amplitude * Math.exp(-t / timeConstant)\n\n const calcLatest = (t: number) => target + calcDelta(t)\n\n const applyFriction = (t: number) => {\n const delta = calcDelta(t)\n const latest = calcLatest(t)\n state.done = Math.abs(delta) <= restDelta\n state.value = state.done ? target : latest\n }\n\n /**\n * Ideally this would resolve for t in a stateless way, we could\n * do that by always precalculating the animation but as we know\n * this will be done anyway we can assume that spring will\n * be discovered during that.\n */\n let timeReachedBoundary: number | undefined\n let spring: KeyframeGenerator<number> | undefined\n\n const checkCatchBoundary = (t: number) => {\n if (!isOutOfBounds(state.value)) return\n\n timeReachedBoundary = t\n\n spring = createSpring({\n keyframes: [state.value, nearestBoundary(state.value)!],\n velocity: calcGeneratorVelocity(calcLatest, t, state.value), // TODO: This should be passing * 1000\n damping: bounceDamping,\n stiffness: bounceStiffness,\n restDelta,\n restSpeed,\n })\n }\n\n checkCatchBoundary(0)\n\n return {\n calculatedDuration: null,\n next: (t: number) => {\n /**\n * We need to resolve the friction to figure out if we need a\n * spring but we don't want to do this twice per frame. So here\n * we flag if we updated for this frame and later if we did\n * we can skip doing it again.\n */\n let hasUpdatedFrame = false\n if (!spring && timeReachedBoundary === undefined) {\n hasUpdatedFrame = true\n applyFriction(t)\n checkCatchBoundary(t)\n }\n\n /**\n * If we have a spring and the provided t is beyond the moment the friction\n * animation crossed the min/max boundary, use the spring.\n */\n if (timeReachedBoundary !== undefined && t >= timeReachedBoundary) {\n return spring!.next(t - timeReachedBoundary)\n } else {\n !hasUpdatedFrame && applyFriction(t)\n return state\n }\n },\n }\n}\n"],"names":["spring","createSpring"],"mappings":";;;SAQgB,OAAO,CAAC,EACpB,SAAS,EACT,QAAQ,GAAG,GAAG,EACd,KAAK,GAAG,GAAG,EACX,YAAY,GAAG,GAAG,EAClB,aAAa,GAAG,EAAE,EAClB,eAAe,GAAG,GAAG,EACrB,YAAY,EACZ,GAAG,EACH,GAAG,EACH,SAAS,GAAG,GAAG,EACf,SAAS,GACmB,EAAA;AAC5B,IAAA,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC
|
|
1
|
+
{"version":3,"file":"inertia.mjs","sources":["../../../../src/animation/generators/inertia.ts"],"sourcesContent":["import {\n AnimationState,\n KeyframeGenerator,\n ValueAnimationOptions,\n} from \"../types\"\nimport { spring as createSpring } from \"./spring\"\nimport { calcGeneratorVelocity } from \"./utils/velocity\"\n\nexport function inertia({\n keyframes,\n velocity = 0.0,\n power = 0.8,\n timeConstant = 325,\n bounceDamping = 10,\n bounceStiffness = 500,\n modifyTarget,\n min,\n max,\n restDelta = 0.5,\n restSpeed,\n}: ValueAnimationOptions<number>): KeyframeGenerator<number> {\n const origin = keyframes[0]\n\n const state: AnimationState<number> = {\n done: false,\n value: origin,\n }\n\n const isOutOfBounds = (v: number) =>\n (min !== undefined && v < min) || (max !== undefined && v > max)\n\n const nearestBoundary = (v: number) => {\n if (min === undefined) return max\n if (max === undefined) return min\n\n return Math.abs(min - v) < Math.abs(max - v) ? min : max\n }\n\n let amplitude = power * velocity\n const ideal = origin + amplitude\n const target = modifyTarget === undefined ? ideal : modifyTarget(ideal)\n\n /**\n * If the target has changed we need to re-calculate the amplitude, otherwise\n * the animation will start from the wrong position.\n */\n if (target !== ideal) amplitude = target - origin\n\n const calcDelta = (t: number) => -amplitude * Math.exp(-t / timeConstant)\n\n const calcLatest = (t: number) => target + calcDelta(t)\n\n const applyFriction = (t: number) => {\n const delta = calcDelta(t)\n const latest = calcLatest(t)\n state.done = Math.abs(delta) <= restDelta\n state.value = state.done ? target : latest\n }\n\n /**\n * Ideally this would resolve for t in a stateless way, we could\n * do that by always precalculating the animation but as we know\n * this will be done anyway we can assume that spring will\n * be discovered during that.\n */\n let timeReachedBoundary: number | undefined\n let spring: KeyframeGenerator<number> | undefined\n\n const checkCatchBoundary = (t: number) => {\n if (!isOutOfBounds(state.value)) return\n\n timeReachedBoundary = t\n\n spring = createSpring({\n keyframes: [state.value, nearestBoundary(state.value)!],\n velocity: calcGeneratorVelocity(calcLatest, t, state.value), // TODO: This should be passing * 1000\n damping: bounceDamping,\n stiffness: bounceStiffness,\n restDelta,\n restSpeed,\n })\n }\n\n checkCatchBoundary(0)\n\n return {\n calculatedDuration: null,\n next: (t: number) => {\n /**\n * We need to resolve the friction to figure out if we need a\n * spring but we don't want to do this twice per frame. So here\n * we flag if we updated for this frame and later if we did\n * we can skip doing it again.\n */\n let hasUpdatedFrame = false\n if (!spring && timeReachedBoundary === undefined) {\n hasUpdatedFrame = true\n applyFriction(t)\n checkCatchBoundary(t)\n }\n\n /**\n * If we have a spring and the provided t is beyond the moment the friction\n * animation crossed the min/max boundary, use the spring.\n */\n if (timeReachedBoundary !== undefined && t >= timeReachedBoundary) {\n return spring!.next(t - timeReachedBoundary)\n } else {\n !hasUpdatedFrame && applyFriction(t)\n return state\n }\n },\n }\n}\n"],"names":["spring","createSpring"],"mappings":";;;SAQgB,OAAO,CAAC,EACpB,SAAS,EACT,QAAQ,GAAG,GAAG,EACd,KAAK,GAAG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AAEA;;;AAGG;YACH,IAAI,mBAAmB,KAAK,SAAS,IAAI,CAAC,IAAI,mBAAmB,EAAE;gBAC/D,OAAOA,QAAO,CAAC,IAAI,CAAC,CAAC,GAAG,mBAAmB,CAAC;YAChD;iBAAO;AACH,gBAAA,CAAC,eAAe,IAAI,aAAa,CAAC,CAAC,CAAC;AACpC,gBAAA,OAAO,KAAK;YAChB;QACJ,CAAC;KACJ;AACL;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyframes.mjs","sources":["../../../../src/animation/generators/keyframes.ts"],"sourcesContent":["import {\n easeInOut,\n easingDefinitionToFunction,\n EasingFunction,\n isEasingArray,\n} from \"motion-utils\"\nimport { interpolate } from \"../../utils/interpolate\"\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)\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 * 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":";;;;;
|
|
1
|
+
{"version":3,"file":"keyframes.mjs","sources":["../../../../src/animation/generators/keyframes.ts"],"sourcesContent":["import {\n easeInOut,\n easingDefinitionToFunction,\n EasingFunction,\n isEasingArray,\n} from \"motion-utils\"\nimport { interpolate } from \"../../utils/interpolate\"\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)\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 * 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":";;;;;AAgBM,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;AAEtC;;;AAGG;AACH,IAAA,MAAM,KAAK,GAAsB;AAC7B,QAAA,IAAI,EAAE,KAAK;AACX,QAAA,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC;KAC3B;AAED;;AAEG;IACH,MAAM,aAAa,GAAG,oBAAoB;;;AAGtC,IAAA,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,cAAc,CAAC;AACrC,UAAE;UACA,aAAa,CAAC,cAAc,CAAC,EACnC,QAAQ,CACX;AAED,IAAA,MAAM,iBAAiB,GAAG,WAAW,CAAI,aAAa,EAAE,cAAc,EAAE;AACpE,QAAA,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,eAAe;AAC/B,cAAE;AACF,cAAE,aAAa,CAAC,cAAc,EAAE,eAAe,CAAC;AACvD,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;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.mjs","sources":["../../../../../src/animation/generators/spring/defaults.ts"],"sourcesContent":["export const springDefaults = {\n // Default spring physics\n stiffness: 100,\n damping: 10,\n mass: 1.0,\n velocity: 0.0,\n\n // Default duration/bounce-based options\n duration: 800, // in ms\n bounce: 0.3,\n visualDuration: 0.3, // in seconds\n\n // Rest thresholds\n restSpeed: {\n granular: 0.01,\n default: 2,\n },\n restDelta: {\n granular: 0.005,\n default: 0.5,\n },\n\n // Limits\n minDuration: 0.01, // in seconds\n maxDuration: 10.0, // in seconds\n minDamping: 0.05,\n maxDamping: 1,\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"defaults.mjs","sources":["../../../../../src/animation/generators/spring/defaults.ts"],"sourcesContent":["export const springDefaults = {\n // Default spring physics\n stiffness: 100,\n damping: 10,\n mass: 1.0,\n velocity: 0.0,\n\n // Default duration/bounce-based options\n duration: 800, // in ms\n bounce: 0.3,\n visualDuration: 0.3, // in seconds\n\n // Rest thresholds\n restSpeed: {\n granular: 0.01,\n default: 2,\n },\n restDelta: {\n granular: 0.005,\n default: 0.5,\n },\n\n // Limits\n minDuration: 0.01, // in seconds\n maxDuration: 10.0, // in seconds\n minDamping: 0.05,\n maxDamping: 1,\n}\n"],"names":[],"mappings":"AAAO,MAAM,cAAc,GAAG;;AAE1B,IAAA,SAAS,EAAE,GAAG;AACd,IAAA,OAAO,EAAE,EAAE;AACX,IAAA,IAAI,EAAE,GAAG;AACT,IAAA,QAAQ,EAAE,GAAG;;IAGb,QAAQ,EAAE,GAAG;AACb,IAAA,MAAM,EAAE,GAAG;IACX,cAAc,EAAE,GAAG;;AAGnB,IAAA,SAAS,EAAE;AACP,QAAA,QAAQ,EAAE,IAAI;AACd,QAAA,OAAO,EAAE,CAAC;AACb,KAAA;AACD,IAAA,SAAS,EAAE;AACP,QAAA,QAAQ,EAAE,KAAK;AACf,QAAA,OAAO,EAAE,GAAG;AACf,KAAA;;IAGD,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;AACjB,IAAA,UAAU,EAAE,IAAI;AAChB,IAAA,UAAU,EAAE,CAAC;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find.mjs","sources":["../../../../../src/animation/generators/spring/find.ts"],"sourcesContent":["import {\n clamp,\n millisecondsToSeconds,\n secondsToMilliseconds,\n warning,\n} from \"motion-utils\"\nimport { SpringOptions } from \"../../types\"\nimport { springDefaults } from \"./defaults\"\n\n/**\n * This is ported from the Framer implementation of duration-based spring resolution.\n */\n\ntype Resolver = (num: number) => number\n\nconst safeMin = 0.001\n\nexport function findSpring({\n duration = springDefaults.duration,\n bounce = springDefaults.bounce,\n velocity = springDefaults.velocity,\n mass = springDefaults.mass,\n}: SpringOptions) {\n let envelope: Resolver\n let derivative: Resolver\n\n warning(\n duration <= secondsToMilliseconds(springDefaults.maxDuration),\n \"Spring duration must be 10 seconds or less\",\n \"spring-duration-limit\"\n )\n\n let dampingRatio = 1 - bounce\n\n /**\n * Restrict dampingRatio and duration to within acceptable ranges.\n */\n dampingRatio = clamp(\n springDefaults.minDamping,\n springDefaults.maxDamping,\n dampingRatio\n )\n duration = clamp(\n springDefaults.minDuration,\n springDefaults.maxDuration,\n millisecondsToSeconds(duration)\n )\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 a = exponentialDecay - velocity\n const b = calcAngularFreq(undampedFreq, dampingRatio)\n const c = Math.exp(-delta)\n return safeMin - (a / b) * c\n }\n\n derivative = (undampedFreq) => {\n const exponentialDecay = undampedFreq * dampingRatio\n const delta = exponentialDecay * duration\n const d = delta * velocity + velocity\n const e =\n Math.pow(dampingRatio, 2) * Math.pow(undampedFreq, 2) * duration\n const f = Math.exp(-delta)\n const g = calcAngularFreq(Math.pow(undampedFreq, 2), dampingRatio)\n const factor = -envelope(undampedFreq) + safeMin > 0 ? -1 : 1\n return (factor * ((d - e) * f)) / g\n }\n } else {\n /**\n * Critically-damped spring\n */\n envelope = (undampedFreq) => {\n const a = Math.exp(-undampedFreq * duration)\n const b = (undampedFreq - velocity) * duration + 1\n return -safeMin + a * b\n }\n\n derivative = (undampedFreq) => {\n const a = Math.exp(-undampedFreq * duration)\n const b = (velocity - undampedFreq) * (duration * duration)\n return a * b\n }\n }\n\n const initialGuess = 5 / duration\n const undampedFreq = approximateRoot(envelope, derivative, initialGuess)\n\n duration = secondsToMilliseconds(duration)\n if (isNaN(undampedFreq)) {\n return {\n stiffness: springDefaults.stiffness,\n damping: springDefaults.damping,\n duration,\n }\n } else {\n const stiffness = Math.pow(undampedFreq, 2) * mass\n return {\n stiffness,\n damping: dampingRatio * 2 * Math.sqrt(mass * stiffness),\n duration,\n }\n }\n}\n\nconst rootIterations = 12\nfunction approximateRoot(\n envelope: Resolver,\n derivative: Resolver,\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\nexport function calcAngularFreq(undampedFreq: number, dampingRatio: number) {\n return undampedFreq * Math.sqrt(1 - dampingRatio * dampingRatio)\n}\n"],"names":[],"mappings":";;;AAeA,MAAM,OAAO,GAAG,KAAK
|
|
1
|
+
{"version":3,"file":"find.mjs","sources":["../../../../../src/animation/generators/spring/find.ts"],"sourcesContent":["import {\n clamp,\n millisecondsToSeconds,\n secondsToMilliseconds,\n warning,\n} from \"motion-utils\"\nimport { SpringOptions } from \"../../types\"\nimport { springDefaults } from \"./defaults\"\n\n/**\n * This is ported from the Framer implementation of duration-based spring resolution.\n */\n\ntype Resolver = (num: number) => number\n\nconst safeMin = 0.001\n\nexport function findSpring({\n duration = springDefaults.duration,\n bounce = springDefaults.bounce,\n velocity = springDefaults.velocity,\n mass = springDefaults.mass,\n}: SpringOptions) {\n let envelope: Resolver\n let derivative: Resolver\n\n warning(\n duration <= secondsToMilliseconds(springDefaults.maxDuration),\n \"Spring duration must be 10 seconds or less\",\n \"spring-duration-limit\"\n )\n\n let dampingRatio = 1 - bounce\n\n /**\n * Restrict dampingRatio and duration to within acceptable ranges.\n */\n dampingRatio = clamp(\n springDefaults.minDamping,\n springDefaults.maxDamping,\n dampingRatio\n )\n duration = clamp(\n springDefaults.minDuration,\n springDefaults.maxDuration,\n millisecondsToSeconds(duration)\n )\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 a = exponentialDecay - velocity\n const b = calcAngularFreq(undampedFreq, dampingRatio)\n const c = Math.exp(-delta)\n return safeMin - (a / b) * c\n }\n\n derivative = (undampedFreq) => {\n const exponentialDecay = undampedFreq * dampingRatio\n const delta = exponentialDecay * duration\n const d = delta * velocity + velocity\n const e =\n Math.pow(dampingRatio, 2) * Math.pow(undampedFreq, 2) * duration\n const f = Math.exp(-delta)\n const g = calcAngularFreq(Math.pow(undampedFreq, 2), dampingRatio)\n const factor = -envelope(undampedFreq) + safeMin > 0 ? -1 : 1\n return (factor * ((d - e) * f)) / g\n }\n } else {\n /**\n * Critically-damped spring\n */\n envelope = (undampedFreq) => {\n const a = Math.exp(-undampedFreq * duration)\n const b = (undampedFreq - velocity) * duration + 1\n return -safeMin + a * b\n }\n\n derivative = (undampedFreq) => {\n const a = Math.exp(-undampedFreq * duration)\n const b = (velocity - undampedFreq) * (duration * duration)\n return a * b\n }\n }\n\n const initialGuess = 5 / duration\n const undampedFreq = approximateRoot(envelope, derivative, initialGuess)\n\n duration = secondsToMilliseconds(duration)\n if (isNaN(undampedFreq)) {\n return {\n stiffness: springDefaults.stiffness,\n damping: springDefaults.damping,\n duration,\n }\n } else {\n const stiffness = Math.pow(undampedFreq, 2) * mass\n return {\n stiffness,\n damping: dampingRatio * 2 * Math.sqrt(mass * stiffness),\n duration,\n }\n }\n}\n\nconst rootIterations = 12\nfunction approximateRoot(\n envelope: Resolver,\n derivative: Resolver,\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\nexport function calcAngularFreq(undampedFreq: number, dampingRatio: number) {\n return undampedFreq * Math.sqrt(1 - dampingRatio * dampingRatio)\n}\n"],"names":[],"mappings":";;;AAeA,MAAM,OAAO,GAAG,KAAK;AAEf,SAAU,UAAU,CAAC,EACvB,QAAQ,GAAG,cAAc,CAAC,QAAQ,EAClC,MAAM,GAAG,cAAc,CAAC,MAAM,EAC9B,QAAQ,GAAG,cAAc,CAAC,QAAQ,EAClC,IAAI,GAAG,cAAc,CAAC,IAAI,GACd,EAAA;AACZ,IAAA,IAAI,QAAkB;AACtB,IAAA,IAAI,UAAoB;AAExB,IAAA,OAAO,CACH,QAAQ,IAAI,qBAAqB,CAAC,cAAc,CAAC,WAAW,CAAC,EAC7D,4CAA4C,EAC5C,uBAAuB,CAC1B;AAED,IAAA,IAAI,YAAY,GAAG,CAAC,GAAG,MAAM;AAE7B;;AAEG;AACH,IAAA,YAAY,GAAG,KAAK,CAChB,cAAc,CAAC,UAAU,EACzB,cAAc,CAAC,UAAU,EACzB,YAAY,CACf;AACD,IAAA,QAAQ,GAAG,KAAK,CACZ,cAAc,CAAC,WAAW,EAC1B,cAAc,CAAC,WAAW,EAC1B,qBAAqB,CAAC,QAAQ,CAAC,CAClC;AAED,IAAA,IAAI,YAAY,GAAG,CAAC,EAAE;AAClB;;AAEG;AACH,QAAA,QAAQ,GAAG,CAAC,YAAY,KAAI;AACxB,YAAA,MAAM,gBAAgB,GAAG,YAAY,GAAG,YAAY;AACpD,YAAA,MAAM,KAAK,GAAG,gBAAgB,GAAG,QAAQ;AACzC,YAAA,MAAM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Ae,CAAC,YAAoB,EAAE,YAAoB,EAAA;AACtE,IAAA,OAAO,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,YAAY,GAAG,YAAY,CAAC;AACpE;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { millisecondsToSeconds,
|
|
1
|
+
import { millisecondsToSeconds, clamp, secondsToMilliseconds } from 'motion-utils';
|
|
2
2
|
import { 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';
|
|
@@ -23,6 +23,11 @@ function getSpringOptions(options) {
|
|
|
23
23
|
// stiffness/damping/mass overrides duration/bounce
|
|
24
24
|
if (!isSpringType(options, physicsKeys) &&
|
|
25
25
|
isSpringType(options, durationKeys)) {
|
|
26
|
+
// Time-defined springs should ignore inherited velocity.
|
|
27
|
+
// Velocity from interrupted animations can cause findSpring()
|
|
28
|
+
// to compute wildly different spring parameters, leading to
|
|
29
|
+
// massive oscillation on small-range animations.
|
|
30
|
+
springOptions.velocity = 0;
|
|
26
31
|
if (options.visualDuration) {
|
|
27
32
|
const visualDuration = options.visualDuration;
|
|
28
33
|
const root = (2 * Math.PI) / (visualDuration * 1.2);
|
|
@@ -38,7 +43,7 @@ function getSpringOptions(options) {
|
|
|
38
43
|
};
|
|
39
44
|
}
|
|
40
45
|
else {
|
|
41
|
-
const derived = findSpring(options);
|
|
46
|
+
const derived = findSpring({ ...options, velocity: 0 });
|
|
42
47
|
springOptions = {
|
|
43
48
|
...springOptions,
|
|
44
49
|
...derived,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../../src/animation/generators/spring/index.ts"],"sourcesContent":["import {\n clamp,\n millisecondsToSeconds,\n secondsToMilliseconds,\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\"\nimport { calcGeneratorVelocity } from \"../utils/velocity\"\nimport { springDefaults } from \"./defaults\"\nimport { calcAngularFreq, findSpring } from \"./find\"\n\nconst durationKeys = [\"duration\", \"bounce\"]\nconst physicsKeys = [\"stiffness\", \"damping\", \"mass\"]\n\nfunction isSpringType(options: SpringOptions, keys: string[]) {\n return keys.some((key) => (options as any)[key] !== undefined)\n}\n\nfunction getSpringOptions(options: SpringOptions) {\n let springOptions = {\n velocity: springDefaults.velocity,\n stiffness: springDefaults.stiffness,\n damping: springDefaults.damping,\n mass: springDefaults.mass,\n isResolvedFromDuration: false,\n ...options,\n }\n // stiffness/damping/mass overrides duration/bounce\n if (\n !isSpringType(options, physicsKeys) &&\n isSpringType(options, durationKeys)\n ) {\n if (options.visualDuration) {\n const visualDuration = options.visualDuration\n const root = (2 * Math.PI) / (visualDuration * 1.2)\n const stiffness = root * root\n const damping =\n 2 *\n clamp(0.05, 1, 1 - (options.bounce || 0)) *\n Math.sqrt(stiffness)\n\n springOptions = {\n ...springOptions,\n mass: springDefaults.mass,\n stiffness,\n damping,\n }\n } else {\n const derived = findSpring(options)\n\n springOptions = {\n ...springOptions,\n ...derived,\n mass: springDefaults.mass,\n }\n springOptions.isResolvedFromDuration = true\n }\n }\n\n return springOptions\n}\n\nfunction spring(\n optionsOrVisualDuration:\n | ValueAnimationOptions<number>\n | number = springDefaults.visualDuration,\n bounce = springDefaults.bounce\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 let { restSpeed, restDelta } = options\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 velocity,\n isResolvedFromDuration,\n } = getSpringOptions({\n ...options,\n velocity: -millisecondsToSeconds(options.velocity || 0),\n })\n\n const initialVelocity = velocity || 0.0\n const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass))\n\n const initialDelta = target - origin\n const undampedAngularFreq = millisecondsToSeconds(\n Math.sqrt(stiffness / mass)\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 emprically based on what strikes a good\n * ratio between feeling good and finishing as soon as changes are imperceptible.\n */\n const isGranularScale = Math.abs(initialDelta) < 5\n restSpeed ||= isGranularScale\n ? springDefaults.restSpeed.granular\n : springDefaults.restSpeed.default\n restDelta ||= isGranularScale\n ? springDefaults.restDelta.granular\n : springDefaults.restDelta.default\n\n let resolveSpring: (v: number) => number\n if (dampingRatio < 1) {\n const angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio)\n\n // Underdamped spring\n resolveSpring = (t: number) => {\n const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t)\n\n return (\n target -\n envelope *\n (((initialVelocity +\n dampingRatio * undampedAngularFreq * initialDelta) /\n angularFreq) *\n Math.sin(angularFreq * t) +\n initialDelta * Math.cos(angularFreq * t))\n )\n }\n } else if (dampingRatio === 1) {\n // Critically damped spring\n resolveSpring = (t: number) =>\n target -\n Math.exp(-undampedAngularFreq * t) *\n (initialDelta +\n (initialVelocity + undampedAngularFreq * initialDelta) * t)\n } else {\n // Overdamped spring\n const dampedAngularFreq =\n undampedAngularFreq * Math.sqrt(dampingRatio * dampingRatio - 1)\n\n resolveSpring = (t: number) => {\n const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t)\n\n // When performing sinh or cosh values can hit Infinity so we cap them here\n const freqForT = Math.min(dampedAngularFreq * t, 300)\n\n return (\n target -\n (envelope *\n ((initialVelocity +\n dampingRatio * undampedAngularFreq * initialDelta) *\n Math.sinh(freqForT) +\n dampedAngularFreq *\n initialDelta *\n Math.cosh(freqForT))) /\n dampedAngularFreq\n )\n }\n }\n\n const generator = {\n calculatedDuration: isResolvedFromDuration ? duration || null : null,\n next: (t: number) => {\n const current = resolveSpring(t)\n\n if (!isResolvedFromDuration) {\n let currentVelocity = t === 0 ? initialVelocity : 0.0\n\n /**\n * We only need to calculate velocity for under-damped springs\n * as over- and critically-damped springs can't overshoot, so\n * checking only for displacement is enough.\n */\n if (dampingRatio < 1) {\n currentVelocity =\n t === 0\n ? secondsToMilliseconds(initialVelocity)\n : calcGeneratorVelocity(resolveSpring, t, current)\n }\n\n const isBelowVelocityThreshold =\n Math.abs(currentVelocity) <= restSpeed!\n const isBelowDisplacementThreshold =\n Math.abs(target - current) <= restDelta!\n\n state.done =\n isBelowVelocityThreshold && isBelowDisplacementThreshold\n } else {\n state.done = t >= duration!\n }\n\n state.value = state.done ? target : current\n\n return state\n },\n toString: () => {\n const calculatedDuration = Math.min(\n calcGeneratorDuration(generator),\n maxGeneratorDuration\n )\n\n const easing = generateLinearEasing(\n (progress: number) =>\n generator.next(calculatedDuration * progress).value,\n calculatedDuration,\n 30\n )\n\n return calculatedDuration + \"ms \" + easing\n },\n toTransition: () => {},\n }\n\n return generator\n}\n\nspring.applyToOptions = (options: Transition) => {\n const generatorOptions = createGeneratorEasing(options as any, 100, spring)\n\n options.ease = generatorOptions.ease\n options.duration = secondsToMilliseconds(generatorOptions.duration)\n options.type = \"keyframes\"\n return options\n}\n\nexport { spring }\n"],"names":[],"mappings":";;;;;;;;AAsBA,MAAM,YAAY,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;AAC3C,MAAM,WAAW,GAAG,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,CAAC,CAAA;AAEpD,SAAS,YAAY,CAAC,OAAsB,EAAE,IAAc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AC,CAAA;AACnE,IAAA,OAAO,CAAC,IAAI,GAAG,WAAW,CAAA;AAC1B,IAAA,OAAO,OAAO,CAAA;AAClB,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../../src/animation/generators/spring/index.ts"],"sourcesContent":["import {\n clamp,\n millisecondsToSeconds,\n secondsToMilliseconds,\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\"\nimport { calcGeneratorVelocity } from \"../utils/velocity\"\nimport { springDefaults } from \"./defaults\"\nimport { calcAngularFreq, findSpring } from \"./find\"\n\nconst durationKeys = [\"duration\", \"bounce\"]\nconst physicsKeys = [\"stiffness\", \"damping\", \"mass\"]\n\nfunction isSpringType(options: SpringOptions, keys: string[]) {\n return keys.some((key) => (options as any)[key] !== undefined)\n}\n\nfunction getSpringOptions(options: SpringOptions) {\n let springOptions = {\n velocity: springDefaults.velocity,\n stiffness: springDefaults.stiffness,\n damping: springDefaults.damping,\n mass: springDefaults.mass,\n isResolvedFromDuration: false,\n ...options,\n }\n // stiffness/damping/mass overrides duration/bounce\n if (\n !isSpringType(options, physicsKeys) &&\n isSpringType(options, durationKeys)\n ) {\n // Time-defined springs should ignore inherited velocity.\n // Velocity from interrupted animations can cause findSpring()\n // to compute wildly different spring parameters, leading to\n // massive oscillation on small-range animations.\n springOptions.velocity = 0\n\n if (options.visualDuration) {\n const visualDuration = options.visualDuration\n const root = (2 * Math.PI) / (visualDuration * 1.2)\n const stiffness = root * root\n const damping =\n 2 *\n clamp(0.05, 1, 1 - (options.bounce || 0)) *\n Math.sqrt(stiffness)\n\n springOptions = {\n ...springOptions,\n mass: springDefaults.mass,\n stiffness,\n damping,\n }\n } else {\n const derived = findSpring({ ...options, velocity: 0 })\n\n springOptions = {\n ...springOptions,\n ...derived,\n mass: springDefaults.mass,\n }\n springOptions.isResolvedFromDuration = true\n }\n }\n\n return springOptions\n}\n\nfunction spring(\n optionsOrVisualDuration:\n | ValueAnimationOptions<number>\n | number = springDefaults.visualDuration,\n bounce = springDefaults.bounce\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 let { restSpeed, restDelta } = options\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 velocity,\n isResolvedFromDuration,\n } = getSpringOptions({\n ...options,\n velocity: -millisecondsToSeconds(options.velocity || 0),\n })\n\n const initialVelocity = velocity || 0.0\n const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass))\n\n const initialDelta = target - origin\n const undampedAngularFreq = millisecondsToSeconds(\n Math.sqrt(stiffness / mass)\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 emprically based on what strikes a good\n * ratio between feeling good and finishing as soon as changes are imperceptible.\n */\n const isGranularScale = Math.abs(initialDelta) < 5\n restSpeed ||= isGranularScale\n ? springDefaults.restSpeed.granular\n : springDefaults.restSpeed.default\n restDelta ||= isGranularScale\n ? springDefaults.restDelta.granular\n : springDefaults.restDelta.default\n\n let resolveSpring: (v: number) => number\n if (dampingRatio < 1) {\n const angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio)\n\n // Underdamped spring\n resolveSpring = (t: number) => {\n const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t)\n\n return (\n target -\n envelope *\n (((initialVelocity +\n dampingRatio * undampedAngularFreq * initialDelta) /\n angularFreq) *\n Math.sin(angularFreq * t) +\n initialDelta * Math.cos(angularFreq * t))\n )\n }\n } else if (dampingRatio === 1) {\n // Critically damped spring\n resolveSpring = (t: number) =>\n target -\n Math.exp(-undampedAngularFreq * t) *\n (initialDelta +\n (initialVelocity + undampedAngularFreq * initialDelta) * t)\n } else {\n // Overdamped spring\n const dampedAngularFreq =\n undampedAngularFreq * Math.sqrt(dampingRatio * dampingRatio - 1)\n\n resolveSpring = (t: number) => {\n const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t)\n\n // When performing sinh or cosh values can hit Infinity so we cap them here\n const freqForT = Math.min(dampedAngularFreq * t, 300)\n\n return (\n target -\n (envelope *\n ((initialVelocity +\n dampingRatio * undampedAngularFreq * initialDelta) *\n Math.sinh(freqForT) +\n dampedAngularFreq *\n initialDelta *\n Math.cosh(freqForT))) /\n dampedAngularFreq\n )\n }\n }\n\n const generator = {\n calculatedDuration: isResolvedFromDuration ? duration || null : null,\n next: (t: number) => {\n const current = resolveSpring(t)\n\n if (!isResolvedFromDuration) {\n let currentVelocity = t === 0 ? initialVelocity : 0.0\n\n /**\n * We only need to calculate velocity for under-damped springs\n * as over- and critically-damped springs can't overshoot, so\n * checking only for displacement is enough.\n */\n if (dampingRatio < 1) {\n currentVelocity =\n t === 0\n ? secondsToMilliseconds(initialVelocity)\n : calcGeneratorVelocity(resolveSpring, t, current)\n }\n\n const isBelowVelocityThreshold =\n Math.abs(currentVelocity) <= restSpeed!\n const isBelowDisplacementThreshold =\n Math.abs(target - current) <= restDelta!\n\n state.done =\n isBelowVelocityThreshold && isBelowDisplacementThreshold\n } else {\n state.done = t >= duration!\n }\n\n state.value = state.done ? target : current\n\n return state\n },\n toString: () => {\n const calculatedDuration = Math.min(\n calcGeneratorDuration(generator),\n maxGeneratorDuration\n )\n\n const easing = generateLinearEasing(\n (progress: number) =>\n generator.next(calculatedDuration * progress).value,\n calculatedDuration,\n 30\n )\n\n return calculatedDuration + \"ms \" + easing\n },\n toTransition: () => {},\n }\n\n return generator\n}\n\nspring.applyToOptions = (options: Transition) => {\n const generatorOptions = createGeneratorEasing(options as any, 100, spring)\n\n options.ease = generatorOptions.ease\n options.duration = secondsToMilliseconds(generatorOptions.duration)\n options.type = \"keyframes\"\n return options\n}\n\nexport { spring }\n"],"names":[],"mappings":";;;;;;;;AAsBA,MAAM,YAAY,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC;AAC3C,MAAM,WAAW,GAAG,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,CAAC;AAEpD,SAAS,YAAY,CAAC,OAAsB,EAAE,IAAc,EAAA;AACxD,IAAA,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,KAAM,OAAe,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC;AAClE;AAEA,SAAS,gBAAgB,CAAC,OAAsB,EAAA;AAC5C,IAAA,IAAI,aAAa,GAAG;QAChB,QAAQ,EAAE,cAAc,CAAC,QAAQ;QACjC,SAAS,EAAE,cAAc,CAAC,SAAS;QACnC,OAAO,EAAE,cAAc,CAAC,OAAO;QAC/B,IAAI,EAAE,cAAc,CAAC,IAAI;AACzB,QAAA,sBAAsB,EAAE,KAAK;AAC7B,QAAA,GAAG,OAAO;KACb;;AAED,IAAA,IACI,CAAC,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC;AACnC,QAAA,YAAY,CAAC,OAAO,EAAE,YAAY,CAAC,EACrC;;;;;AAKE,QAAA,aAAa,CAAC,QAAQ,GAAG,CAAC;AAE1B,QAAA,IAAI,OAAO,CAAC,cAAc,EAAE;AACxB,YAAA,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc;AAC7C,YAAA,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,KAAK,cAAc,GAAG,GAAG,CAAC;AACnD,YAAA,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI;YAC7B,MAAM,OAAO,GACT,CAAC;AACD,gBAAA,KA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