motion-dom 14.9.1 → 14.10.1
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 +729 -183
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/GroupAnimation.mjs +21 -15
- package/dist/es/animation/GroupAnimation.mjs.map +1 -1
- package/dist/es/animation/JSAnimation.mjs +6 -0
- package/dist/es/animation/JSAnimation.mjs.map +1 -1
- package/dist/es/animation/NativeAnimation.mjs +5 -0
- package/dist/es/animation/NativeAnimation.mjs.map +1 -1
- package/dist/es/animation/animate/effects.mjs +15 -4
- package/dist/es/animation/animate/effects.mjs.map +1 -1
- package/dist/es/animation/animate/single-value.mjs +1 -1
- package/dist/es/animation/animate/single-value.mjs.map +1 -1
- package/dist/es/animation/generators/keyframes.mjs +44 -16
- package/dist/es/animation/generators/keyframes.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs +8 -3
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs.map +1 -1
- package/dist/es/animation/keyframes/get-final.mjs +18 -4
- package/dist/es/animation/keyframes/get-final.mjs.map +1 -1
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs +347 -88
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs.map +1 -1
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +3 -3
- package/dist/es/gestures/drag/VisualElementDragControls.mjs.map +1 -1
- package/dist/es/gestures/drag/index.mjs +4 -1
- package/dist/es/gestures/drag/index.mjs.map +1 -1
- package/dist/es/gestures/pan/PanSession.mjs +6 -2
- package/dist/es/gestures/pan/PanSession.mjs.map +1 -1
- package/dist/es/gestures/press/index.mjs +179 -8
- package/dist/es/gestures/press/index.mjs.map +1 -1
- package/dist/es/gestures/press/utils/keyboard.mjs +1 -1
- package/dist/es/gestures/press/utils/keyboard.mjs.map +1 -1
- package/dist/es/projection/styles/transform.mjs +39 -17
- package/dist/es/projection/styles/transform.mjs.map +1 -1
- package/dist/es/value/index.mjs +24 -20
- package/dist/es/value/index.mjs.map +1 -1
- package/dist/es/value/types/utils/animatable-none.mjs +13 -1
- package/dist/es/value/types/utils/animatable-none.mjs.map +1 -1
- package/dist/index.d.ts +163 -13
- package/dist/motion-dom.dev.js +729 -183
- 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":"visual-element-target.mjs","sources":["../../../../src/animation/interfaces/visual-element-target.ts"],"sourcesContent":["import { frame } from \"../../frameloop\"\nimport { getValueTransition } from \"../utils/get-value-transition\"\nimport { resolveTransition } from \"../utils/resolve-transition\"\nimport { positionalKeys } from \"../../render/utils/keys-position\"\nimport { setTarget } from \"../../render/utils/setters\"\nimport { addValueToWillChange } from \"../../value/will-change/add-will-change\"\nimport { getOptimisedAppearId } from \"../optimized-appear/get-appear-id\"\nimport { animateMotionValue } from \"./motion-value\"\nimport type { MotionPath } from \"../types\"\nimport type { VisualElementAnimationOptions } from \"./types\"\nimport type { AnimationPlaybackControlsWithThen } from \"../types\"\nimport type { TargetAndTransition } from \"../../node/types\"\nimport type { AnimationTypeState } from \"../../render/utils/animation-state\"\nimport type { VisualElement } from \"../../render/VisualElement\"\n\nconst isBrowser = typeof window !== \"undefined\"\n\n/**\n * Decide whether we should block this animation. Previously, we achieved this\n * just by checking whether the key was listed in protectedKeys, but this\n * posed problems if an animation was triggered by afterChildren and protectedKeys\n * had been set to true in the meantime.\n */\nfunction shouldBlockAnimation(\n { protectedKeys, needsAnimating }: AnimationTypeState,\n key: string\n) {\n const shouldBlock = key in protectedKeys && !needsAnimating[key]\n\n needsAnimating[key] = false\n return shouldBlock\n}\n\nexport function animateTarget(\n visualElement: VisualElement,\n targetAndTransition: TargetAndTransition,\n { delay = 0, transitionOverride, type }: VisualElementAnimationOptions = {}\n): AnimationPlaybackControlsWithThen[] {\n let {\n transition,\n transitionEnd,\n ...target\n } = targetAndTransition\n\n const defaultTransition = visualElement.getDefaultTransition()\n transition = transition\n ? resolveTransition(transition, defaultTransition)\n : defaultTransition\n\n const reduceMotion = (transition as { reduceMotion?: boolean })?.reduceMotion\n const skipAnimations = transition?.skipAnimations\n\n if (transitionOverride) transition = transitionOverride\n\n const animations: AnimationPlaybackControlsWithThen[] = []\n\n const animationTypeState =\n type && visualElement.animationState?.getState()[type]\n\n const path = (transition as { path?: MotionPath } | undefined)?.path\n if (path) {\n // path mutates `target` to claim x/y; loop below skips them.\n path.animateValues\n ? path.animateValues(\n (key) =>\n visualElement.getValue(\n key,\n visualElement.latestValues[key] ?? 0\n ),\n target,\n transition,\n delay,\n animations\n )\n : path.animateVisualElement?.(\n visualElement,\n target,\n transition,\n delay,\n animations\n )\n }\n\n for (const key in target) {\n const value = visualElement.getValue(\n key,\n visualElement.latestValues[key] ?? null\n )\n const valueTarget = target[key as keyof typeof target]\n\n if (\n valueTarget === undefined ||\n (animationTypeState &&\n shouldBlockAnimation(animationTypeState, key))\n ) {\n continue\n }\n\n const valueTransition = {\n delay,\n ...getValueTransition(\n animationTypeState?.out[key] || transition || {},\n key\n ),\n }\n\n if (skipAnimations) valueTransition.skipAnimations = true\n\n /**\n * If the value is already at the defined target, skip the animation.\n * We still re-assert the value via frame.update to take precedence\n * over any stale transitionEnd callbacks from previous animations.\n */\n const currentValue = value.get()\n if (\n currentValue !== undefined &&\n !value.isAnimating() &&\n !Array.isArray(valueTarget) &&\n valueTarget === currentValue &&\n !valueTransition.velocity\n ) {\n frame.update(() => value.set(valueTarget as any))\n continue\n }\n\n /**\n * If this is the first time a value is being animated, check\n * to see if we're handling off from an existing animation.\n */\n let isHandoff = false\n if (isBrowser && window.MotionHandoffAnimation) {\n const appearId = getOptimisedAppearId(visualElement)\n\n if (appearId) {\n const startTime = window.MotionHandoffAnimation(\n appearId,\n key,\n frame\n )\n\n if (startTime !== null) {\n valueTransition.startTime = startTime\n isHandoff = true\n }\n }\n }\n\n addValueToWillChange(visualElement, key)\n\n const shouldReduceMotion =\n reduceMotion ?? visualElement.shouldReduceMotion\n\n value.
|
|
1
|
+
{"version":3,"file":"visual-element-target.mjs","sources":["../../../../src/animation/interfaces/visual-element-target.ts"],"sourcesContent":["import { frame } from \"../../frameloop\"\nimport { getValueTransition } from \"../utils/get-value-transition\"\nimport { resolveTransition } from \"../utils/resolve-transition\"\nimport { positionalKeys } from \"../../render/utils/keys-position\"\nimport { setTarget } from \"../../render/utils/setters\"\nimport { addValueToWillChange } from \"../../value/will-change/add-will-change\"\nimport { getOptimisedAppearId } from \"../optimized-appear/get-appear-id\"\nimport { animateMotionValue } from \"./motion-value\"\nimport type { MotionPath } from \"../types\"\nimport type { VisualElementAnimationOptions } from \"./types\"\nimport type { AnimationPlaybackControlsWithThen } from \"../types\"\nimport type { TargetAndTransition } from \"../../node/types\"\nimport type { AnimationTypeState } from \"../../render/utils/animation-state\"\nimport type { VisualElement } from \"../../render/VisualElement\"\n\nconst isBrowser = typeof window !== \"undefined\"\n\n/**\n * Decide whether we should block this animation. Previously, we achieved this\n * just by checking whether the key was listed in protectedKeys, but this\n * posed problems if an animation was triggered by afterChildren and protectedKeys\n * had been set to true in the meantime.\n */\nfunction shouldBlockAnimation(\n { protectedKeys, needsAnimating }: AnimationTypeState,\n key: string\n) {\n const shouldBlock = key in protectedKeys && !needsAnimating[key]\n\n needsAnimating[key] = false\n return shouldBlock\n}\n\nexport function animateTarget(\n visualElement: VisualElement,\n targetAndTransition: TargetAndTransition,\n { delay = 0, transitionOverride, type }: VisualElementAnimationOptions = {}\n): AnimationPlaybackControlsWithThen[] {\n let {\n transition,\n transitionEnd,\n ...target\n } = targetAndTransition\n\n const defaultTransition = visualElement.getDefaultTransition()\n transition = transition\n ? resolveTransition(transition, defaultTransition)\n : defaultTransition\n\n const reduceMotion = (transition as { reduceMotion?: boolean })?.reduceMotion\n const skipAnimations = transition?.skipAnimations\n\n if (transitionOverride) transition = transitionOverride\n\n const animations: AnimationPlaybackControlsWithThen[] = []\n\n const animationTypeState =\n type && visualElement.animationState?.getState()[type]\n\n const path = (transition as { path?: MotionPath } | undefined)?.path\n if (path) {\n // path mutates `target` to claim x/y; loop below skips them.\n path.animateValues\n ? path.animateValues(\n (key) =>\n visualElement.getValue(\n key,\n visualElement.latestValues[key] ?? 0\n ),\n target,\n transition,\n delay,\n animations\n )\n : path.animateVisualElement?.(\n visualElement,\n target,\n transition,\n delay,\n animations\n )\n }\n\n for (const key in target) {\n const value = visualElement.getValue(\n key,\n visualElement.latestValues[key] ?? null\n )\n const valueTarget = target[key as keyof typeof target]\n\n if (\n valueTarget === undefined ||\n (animationTypeState &&\n shouldBlockAnimation(animationTypeState, key))\n ) {\n continue\n }\n\n const valueTransition = {\n delay,\n ...getValueTransition(\n animationTypeState?.out[key] || transition || {},\n key\n ),\n }\n\n if (skipAnimations) valueTransition.skipAnimations = true\n\n /**\n * If the value is already at the defined target, skip the animation.\n * We still re-assert the value via frame.update to take precedence\n * over any stale transitionEnd callbacks from previous animations.\n */\n const currentValue = value.get()\n if (\n currentValue !== undefined &&\n !value.isAnimating() &&\n !Array.isArray(valueTarget) &&\n valueTarget === currentValue &&\n !valueTransition.velocity\n ) {\n frame.update(() => value.set(valueTarget as any))\n continue\n }\n\n /**\n * If this is the first time a value is being animated, check\n * to see if we're handling off from an existing animation.\n */\n let isHandoff = false\n if (isBrowser && window.MotionHandoffAnimation) {\n const appearId = getOptimisedAppearId(visualElement)\n\n if (appearId) {\n const startTime = window.MotionHandoffAnimation(\n appearId,\n key,\n frame\n )\n\n if (startTime !== null) {\n valueTransition.startTime = startTime\n isHandoff = true\n }\n }\n }\n\n addValueToWillChange(visualElement, key)\n\n const shouldReduceMotion =\n reduceMotion ?? visualElement.shouldReduceMotion\n\n value.run(\n animateMotionValue(\n key,\n value,\n valueTarget,\n shouldReduceMotion && positionalKeys.has(key)\n ? { type: false }\n : valueTransition,\n visualElement,\n isHandoff\n )\n )\n\n const animation = value.animation as\n | AnimationPlaybackControlsWithThen\n | undefined\n\n if (animation) {\n animations.push(animation)\n }\n }\n\n if (transitionEnd) {\n const applyTransitionEnd = () =>\n frame.update(() => {\n transitionEnd && setTarget(visualElement, transitionEnd)\n })\n\n if (animations.length) {\n Promise.all(animations).then(applyTransitionEnd)\n } else {\n applyTransitionEnd()\n }\n }\n\n return animations\n}\n"],"names":[],"mappings":";;;;;;;;;AAeA,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW;AAE/C;;;;;AAKG;AACH,SAAS,oBAAoB,CACzB,EAAE,aAAa,EAAE,cAAc,EAAsB,EACrD,GAAW,EAAA;IAEX,MAAM,WAAW,GAAG,GAAG,IAAI,aAAa,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;AAEhE,IAAA,cAAc,CAAC,GAAG,CAAC,GAAG,KAAK;AAC3B,IAAA,OAAO,WAAW;AACtB;SAEgB,aAAa,CACzB,aAA4B,EAC5B,mBAAwC,EACxC,EAAE,KAAK,GAAG,CAAC,EAAE,kBAAkB,EAAE,IAAI,KAAoC,EAAE,EAAA;IAE3E,IAAI,EACA,UAAU,EACV,aAAa,EACb,GAAG,MAAM,EACZ,GAAG,mBAAmB;AAEvB,IAAA,MAAM,iBAAiB,GAAG,aAAa,CAAC,oBAAoB,EAAE;AAC9D,IAAA,UAAU,GAAG;AACT,UAAE,iBAAiB,CAAC,UAAU,EAAE,iBAAiB;UAC/C,iBAAiB;AAEvB,IAAA,MAAM,YAAY,GAAI,UAAyC,EAAE,YAAY;AAC7E,IAAA,MAAM,cAAc,GAAG,UAAU,EAAE,cAAc;AAEjD,IAAA,IAAI,kBAAkB;QAAE,UAAU,GAAG,kBAAkB;IAEvD,MAAM,UAAU,GAAwC,EAAE;AAE1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UAAU,CAAC,MAAM,EAAE;YACnB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC;QACpD;aAAO;AACH,YAAA,kBAAkB,EAAE;QACxB;IACJ;AAEA,IAAA,OAAO,UAAU;AACrB;;;;"}
|
|
@@ -8,9 +8,14 @@ import { makeNoneKeyframesAnimatable } from './utils/make-none-animatable.mjs';
|
|
|
8
8
|
import { positionalValues, isNumOrPxType } from './utils/unit-conversion.mjs';
|
|
9
9
|
|
|
10
10
|
class DOMKeyframesResolver extends KeyframeResolver {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Passes isAsync to the base constructor rather than setting it as a
|
|
13
|
+
* class field, which would compile to a constructor that spreads
|
|
14
|
+
* `arguments` into super(). That spread is slow in the interpreter,
|
|
15
|
+
* and animate() constructs one resolver per value.
|
|
16
|
+
*/
|
|
17
|
+
constructor(unresolvedKeyframes, onComplete, name, motionValue, element) {
|
|
18
|
+
super(unresolvedKeyframes, onComplete, name, motionValue, element, true);
|
|
14
19
|
}
|
|
15
20
|
/**
|
|
16
21
|
* Keyframes that don't need reading from the DOM, or measuring,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOMKeyframesResolver.mjs","sources":["../../../../src/animation/keyframes/DOMKeyframesResolver.ts"],"sourcesContent":["import { positionalKeys } from \"../../render/utils/keys-position\"\nimport { findDimensionValueType } from \"../../value/types/dimensions\"\nimport { AnyResolvedKeyframe } from \"../types\"\nimport { getVariableValue } from \"../utils/css-variables-conversion\"\nimport {\n containsCSSVariable,\n isCSSVariableToken,\n} from \"../utils/is-css-variable\"\nimport { KeyframeResolver } from \"./KeyframesResolver\"\nimport { WithRender } from \"./types\"\nimport { isNone } from \"./utils/is-none\"\nimport { makeNoneKeyframesAnimatable } from \"./utils/make-none-animatable\"\nimport { isNumOrPxType, positionalValues } from \"./utils/unit-conversion\"\n\nexport class DOMKeyframesResolver<\n T extends AnyResolvedKeyframe\n> extends KeyframeResolver<T> {\n name: string\n element?: WithRender\n\n private measuredOrigin?: AnyResolvedKeyframe\n\n protected isAsync = true\n\n /**\n * Keyframes that don't need reading from the DOM, or measuring,\n * resolve straight away rather than in the frame loop's batched read.\n */\n scheduleResolve() {\n if (this.canReadNow()) {\n this.readKeyframes()\n if (!this.needsMeasurement) return this.complete()\n }\n\n super.scheduleResolve()\n }\n\n private canReadNow() {\n const { unresolvedKeyframes, element, motionValue } = this\n const origin = unresolvedKeyframes[0] ?? motionValue?.get()\n\n if (!element?.current || origin === undefined) return false\n\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n if (containsCSSVariable(i ? unresolvedKeyframes[i] : origin)) {\n return false\n }\n }\n\n return true\n }\n\n readKeyframes() {\n const { unresolvedKeyframes, element, name } = this\n\n if (!element?.current) return\n\n super.readKeyframes()\n\n /**\n * If any keyframe is a CSS variable, we need to find its value by sampling the element\n */\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n let keyframe = unresolvedKeyframes[i]\n\n if (typeof keyframe === \"string\") {\n keyframe = keyframe.trim()\n\n if (isCSSVariableToken(keyframe)) {\n const resolved = getVariableValue(keyframe, element.current)\n\n if (resolved !== undefined) {\n unresolvedKeyframes[i] = resolved as T\n }\n\n if (i === unresolvedKeyframes.length - 1) {\n this.finalKeyframe = keyframe as T\n }\n }\n }\n }\n\n /**\n * Resolve \"none\" values. We do this potentially twice - once before and once after measuring keyframes.\n * This could be seen as inefficient but it's a trade-off to avoid measurements in more situations, which\n * have a far bigger performance impact.\n */\n this.resolveNoneKeyframes()\n\n /**\n * Check to see if unit type has changed. If so schedule jobs that will\n * temporarily set styles to the destination keyframes.\n * Skip if we have more than two keyframes or this isn't a positional value.\n * TODO: We can throw if there are multiple keyframes and the value type changes.\n */\n if (!positionalKeys.has(name) || unresolvedKeyframes.length !== 2) {\n return\n }\n\n const [origin, target] = unresolvedKeyframes\n\n // Two numbers share a unit, so skip the value type search.\n if (typeof origin === \"number\" && typeof target === \"number\") return\n\n const originType = findDimensionValueType(origin)\n const targetType = findDimensionValueType(target)\n\n /**\n * If one keyframe contains embedded CSS variables (e.g. in calc()) and the other\n * doesn't, we need to measure to convert to pixels. This handles GitHub issue #3410.\n */\n const originHasVar = containsCSSVariable(origin)\n const targetHasVar = containsCSSVariable(target)\n\n if (originHasVar !== targetHasVar && positionalValues[name]) {\n this.needsMeasurement = true\n return\n }\n\n /**\n * Either we don't recognise these value types or we can animate between them.\n */\n if (originType === targetType) return\n\n /**\n * If both values are numbers or pixels, we can animate between them by\n * converting them to numbers.\n */\n if (isNumOrPxType(originType) && isNumOrPxType(targetType)) {\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n const value = unresolvedKeyframes[i]\n if (typeof value === \"string\") {\n unresolvedKeyframes[i] = parseFloat(value as string)\n }\n }\n } else if (positionalValues[name]) {\n /**\n * Else, the only way to resolve this is by measuring the element.\n */\n this.needsMeasurement = true\n }\n }\n\n resolveNoneKeyframes() {\n const { unresolvedKeyframes, name } = this\n\n const noneKeyframeIndexes: number[] = []\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n if (\n unresolvedKeyframes[i] === null ||\n isNone(unresolvedKeyframes[i])\n ) {\n noneKeyframeIndexes.push(i)\n }\n }\n\n if (noneKeyframeIndexes.length) {\n makeNoneKeyframesAnimatable(\n unresolvedKeyframes,\n noneKeyframeIndexes,\n name\n )\n }\n }\n\n private measure() {\n const { element, name } = this\n return positionalValues[name](\n window.getComputedStyle(element!.current!),\n () => element!.measureViewportBox()\n )\n }\n\n measureInitialState() {\n const { element, unresolvedKeyframes, name } = this\n\n if (!element?.current) return\n\n if (name === \"height\") this.suspendedScrollY = window.pageYOffset\n\n this.measuredOrigin = this.measure()\n\n unresolvedKeyframes[0] = this.measuredOrigin\n\n // Set final key frame to measure after next render\n const measureKeyframe =\n unresolvedKeyframes[unresolvedKeyframes.length - 1]\n\n if (measureKeyframe !== undefined) {\n this.motionValue?.jump(measureKeyframe as T, false)\n }\n }\n\n measureEndState() {\n const { element, unresolvedKeyframes } = this\n\n if (!element?.current) return\n\n this.motionValue?.jump(this.measuredOrigin as T, false)\n\n const finalKeyframeIndex = unresolvedKeyframes.length - 1\n const finalKeyframe = unresolvedKeyframes[finalKeyframeIndex]\n\n unresolvedKeyframes[finalKeyframeIndex] = this.measure() as any\n\n if (finalKeyframe !== null && this.finalKeyframe === undefined) {\n this.finalKeyframe = finalKeyframe as T\n }\n\n this.resolveNoneKeyframes()\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAcM,MAAO,oBAEX,SAAQ,gBAAmB,CAAA;AAF7B,IAAA,WAAA,GAAA;;QAQc,IAAA,CAAA,OAAO,GAAG,IAAI;IA6L5B;AA3LI;;;AAGG;IACH,eAAe,GAAA;AACX,QAAA,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE;YACnB,IAAI,CAAC,aAAa,EAAE;YACpB,IAAI,CAAC,IAAI,CAAC,gBAAgB;AAAE,gBAAA,OAAO,IAAI,CAAC,QAAQ,EAAE;QACtD;QAEA,KAAK,CAAC,eAAe,EAAE;IAC3B;IAEQ,UAAU,GAAA;QACd,MAAM,EAAE,mBAAmB,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI;QAC1D,MAAM,MAAM,GAAG,mBAAmB,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,GAAG,EAAE;AAE3D,QAAA,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,MAAM,KAAK,SAAS;AAAE,YAAA,OAAO,KAAK;AAE3D,QAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,mBAAmB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACjD,YAAA,IAAI,mBAAmB,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,EAAE;AAC1D,gBAAA,OAAO,KAAK;YAChB;QACJ;AAEA,QAAA,OAAO,IAAI;IACf;IAEA,aAAa,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,kBAAkB,CAAC,GAAG,IAAI,CAAC,OAAO,EAAS;QAE/D,IAAI,aAAa,KAAK,IAAI,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS,EAAE;AAC5D,YAAA,IAAI,CAAC,aAAa,GAAG,aAAkB;QAC3C;QAEA,IAAI,CAAC,oBAAoB,EAAE;IAC/B;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"DOMKeyframesResolver.mjs","sources":["../../../../src/animation/keyframes/DOMKeyframesResolver.ts"],"sourcesContent":["import { positionalKeys } from \"../../render/utils/keys-position\"\nimport { findDimensionValueType } from \"../../value/types/dimensions\"\nimport { AnyResolvedKeyframe } from \"../types\"\nimport { getVariableValue } from \"../utils/css-variables-conversion\"\nimport {\n containsCSSVariable,\n isCSSVariableToken,\n} from \"../utils/is-css-variable\"\nimport type { MotionValue } from \"../../value\"\nimport {\n KeyframeResolver,\n OnKeyframesResolved,\n UnresolvedKeyframes,\n} from \"./KeyframesResolver\"\nimport { WithRender } from \"./types\"\nimport { isNone } from \"./utils/is-none\"\nimport { makeNoneKeyframesAnimatable } from \"./utils/make-none-animatable\"\nimport { isNumOrPxType, positionalValues } from \"./utils/unit-conversion\"\n\nexport class DOMKeyframesResolver<\n T extends AnyResolvedKeyframe\n> extends KeyframeResolver<T> {\n name: string\n element?: WithRender\n\n private measuredOrigin?: AnyResolvedKeyframe\n\n /**\n * Passes isAsync to the base constructor rather than setting it as a\n * class field, which would compile to a constructor that spreads\n * `arguments` into super(). That spread is slow in the interpreter,\n * and animate() constructs one resolver per value.\n */\n constructor(\n unresolvedKeyframes: UnresolvedKeyframes<AnyResolvedKeyframe>,\n onComplete: OnKeyframesResolved<T>,\n name?: string,\n motionValue?: MotionValue<T>,\n element?: WithRender\n ) {\n super(unresolvedKeyframes, onComplete, name, motionValue, element, true)\n }\n\n /**\n * Keyframes that don't need reading from the DOM, or measuring,\n * resolve straight away rather than in the frame loop's batched read.\n */\n scheduleResolve() {\n if (this.canReadNow()) {\n this.readKeyframes()\n if (!this.needsMeasurement) return this.complete()\n }\n\n super.scheduleResolve()\n }\n\n private canReadNow() {\n const { unresolvedKeyframes, element, motionValue } = this\n const origin = unresolvedKeyframes[0] ?? motionValue?.get()\n\n if (!element?.current || origin === undefined) return false\n\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n if (containsCSSVariable(i ? unresolvedKeyframes[i] : origin)) {\n return false\n }\n }\n\n return true\n }\n\n readKeyframes() {\n const { unresolvedKeyframes, element, name } = this\n\n if (!element?.current) return\n\n super.readKeyframes()\n\n /**\n * If any keyframe is a CSS variable, we need to find its value by sampling the element\n */\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n let keyframe = unresolvedKeyframes[i]\n\n if (typeof keyframe === \"string\") {\n keyframe = keyframe.trim()\n\n if (isCSSVariableToken(keyframe)) {\n const resolved = getVariableValue(keyframe, element.current)\n\n if (resolved !== undefined) {\n unresolvedKeyframes[i] = resolved as T\n }\n\n if (i === unresolvedKeyframes.length - 1) {\n this.finalKeyframe = keyframe as T\n }\n }\n }\n }\n\n /**\n * Resolve \"none\" values. We do this potentially twice - once before and once after measuring keyframes.\n * This could be seen as inefficient but it's a trade-off to avoid measurements in more situations, which\n * have a far bigger performance impact.\n */\n this.resolveNoneKeyframes()\n\n /**\n * Check to see if unit type has changed. If so schedule jobs that will\n * temporarily set styles to the destination keyframes.\n * Skip if we have more than two keyframes or this isn't a positional value.\n * TODO: We can throw if there are multiple keyframes and the value type changes.\n */\n if (!positionalKeys.has(name) || unresolvedKeyframes.length !== 2) {\n return\n }\n\n const [origin, target] = unresolvedKeyframes\n\n // Two numbers share a unit, so skip the value type search.\n if (typeof origin === \"number\" && typeof target === \"number\") return\n\n const originType = findDimensionValueType(origin)\n const targetType = findDimensionValueType(target)\n\n /**\n * If one keyframe contains embedded CSS variables (e.g. in calc()) and the other\n * doesn't, we need to measure to convert to pixels. This handles GitHub issue #3410.\n */\n const originHasVar = containsCSSVariable(origin)\n const targetHasVar = containsCSSVariable(target)\n\n if (originHasVar !== targetHasVar && positionalValues[name]) {\n this.needsMeasurement = true\n return\n }\n\n /**\n * Either we don't recognise these value types or we can animate between them.\n */\n if (originType === targetType) return\n\n /**\n * If both values are numbers or pixels, we can animate between them by\n * converting them to numbers.\n */\n if (isNumOrPxType(originType) && isNumOrPxType(targetType)) {\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n const value = unresolvedKeyframes[i]\n if (typeof value === \"string\") {\n unresolvedKeyframes[i] = parseFloat(value as string)\n }\n }\n } else if (positionalValues[name]) {\n /**\n * Else, the only way to resolve this is by measuring the element.\n */\n this.needsMeasurement = true\n }\n }\n\n resolveNoneKeyframes() {\n const { unresolvedKeyframes, name } = this\n\n const noneKeyframeIndexes: number[] = []\n for (let i = 0; i < unresolvedKeyframes.length; i++) {\n if (\n unresolvedKeyframes[i] === null ||\n isNone(unresolvedKeyframes[i])\n ) {\n noneKeyframeIndexes.push(i)\n }\n }\n\n if (noneKeyframeIndexes.length) {\n makeNoneKeyframesAnimatable(\n unresolvedKeyframes,\n noneKeyframeIndexes,\n name\n )\n }\n }\n\n private measure() {\n const { element, name } = this\n return positionalValues[name](\n window.getComputedStyle(element!.current!),\n () => element!.measureViewportBox()\n )\n }\n\n measureInitialState() {\n const { element, unresolvedKeyframes, name } = this\n\n if (!element?.current) return\n\n if (name === \"height\") this.suspendedScrollY = window.pageYOffset\n\n this.measuredOrigin = this.measure()\n\n unresolvedKeyframes[0] = this.measuredOrigin\n\n // Set final key frame to measure after next render\n const measureKeyframe =\n unresolvedKeyframes[unresolvedKeyframes.length - 1]\n\n if (measureKeyframe !== undefined) {\n this.motionValue?.jump(measureKeyframe as T, false)\n }\n }\n\n measureEndState() {\n const { element, unresolvedKeyframes } = this\n\n if (!element?.current) return\n\n this.motionValue?.jump(this.measuredOrigin as T, false)\n\n const finalKeyframeIndex = unresolvedKeyframes.length - 1\n const finalKeyframe = unresolvedKeyframes[finalKeyframeIndex]\n\n unresolvedKeyframes[finalKeyframeIndex] = this.measure() as any\n\n if (finalKeyframe !== null && this.finalKeyframe === undefined) {\n this.finalKeyframe = finalKeyframe as T\n }\n\n this.resolveNoneKeyframes()\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAmBM,MAAO,oBAEX,SAAQ,gBAAmB,CAAA;AAMzB;;;;;AAKG;IACH,WAAA,CACI,mBAA6D,EAC7D,UAAkC,EAClC,IAAa,EACb,WAA4B,EAC5B,OAAoB,EAAA;AAEpB,QAAA,KAAK,CAAC,mBAAmB,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC;IAC5E;AAEA;;;AAGG;IACH,eAAe,GAAA;AACX,QAAA,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE;YACnB,IAAI,CAAC,aAAa,EAAE;YACpB,IAAI,CAAC,IAAI,CAAC,gBAAgB;AAAE,gBAAA,OAAO,IAAI,CAAC,QAAQ,EAAE;QACtD;QAEA,KAAK,CAAC,eAAe,EAAE;IAC3B;IAEQ,UAAU,GAAA;QACd,MAAM,EAAE,mBAAmB,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI;QAC1D,MAAM,MAAM,GAAG,mBAAmB,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,GAAG,EAAE;AAE3D,QAAA,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,MAAM,KAAK,SAAS;AAAE,YAAA,OAAO,KAAK;AAE3D,QAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,mBAAmB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACjD,YAAA,IAAI,mBAAmB,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,EAAE;AAC1D,gBAAA,OAAO,KAAK;YAChB;QACJ;AAEA,QAAA,OAAO,IAAI;IACf;IAEA,aAAa,GAAA;QACT,MAAM,EAAE,mBAAmB,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI;QAE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IAAI,IAAI,CAAC,aAAa,KAAK,SAAS,EAAE;AAC5D,YAAA,IAAI,CAAC,aAAa,GAAG,aAAkB;QAC3C;QAEA,IAAI,CAAC,oBAAoB,EAAE;IAC/B;AACH;;;;"}
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
const isNotNull = (value) => value !== null;
|
|
2
1
|
function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe, speed = 1) {
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The first and last keyframes that aren't null, and how many there
|
|
4
|
+
* are. Found in one pass rather than filtering into a new array, as
|
|
5
|
+
* this runs for every value of every animation.
|
|
6
|
+
*/
|
|
7
|
+
let first;
|
|
8
|
+
let last;
|
|
9
|
+
let numResolved = 0;
|
|
10
|
+
for (let i = 0; i < keyframes.length; i++) {
|
|
11
|
+
const keyframe = keyframes[i];
|
|
12
|
+
if (keyframe !== null) {
|
|
13
|
+
if (!numResolved++)
|
|
14
|
+
first = keyframe;
|
|
15
|
+
last = keyframe;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
4
18
|
const useFirstKeyframe = speed < 0 || (repeat && repeatType !== "loop" && repeat % 2 === 1);
|
|
5
|
-
const index = useFirstKeyframe ? 0 :
|
|
19
|
+
const index = useFirstKeyframe ? 0 : numResolved - 1;
|
|
6
20
|
return !index || finalKeyframe === undefined
|
|
7
|
-
?
|
|
21
|
+
? (index ? last : first)
|
|
8
22
|
: finalKeyframe;
|
|
9
23
|
}
|
|
10
24
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-final.mjs","sources":["../../../../src/animation/keyframes/get-final.ts"],"sourcesContent":["import { AnimationPlaybackOptions } from \"../types\"\n\
|
|
1
|
+
{"version":3,"file":"get-final.mjs","sources":["../../../../src/animation/keyframes/get-final.ts"],"sourcesContent":["import { AnimationPlaybackOptions } from \"../types\"\n\nexport function getFinalKeyframe<T>(\n keyframes: T[],\n { repeat, repeatType = \"loop\" }: AnimationPlaybackOptions,\n finalKeyframe?: T,\n speed: number = 1\n): T {\n /**\n * The first and last keyframes that aren't null, and how many there\n * are. Found in one pass rather than filtering into a new array, as\n * this runs for every value of every animation.\n */\n let first: T | undefined\n let last: T | undefined\n let numResolved = 0\n for (let i = 0; i < keyframes.length; i++) {\n const keyframe = keyframes[i]\n if (keyframe !== null) {\n if (!numResolved++) first = keyframe\n last = keyframe\n }\n }\n\n const useFirstKeyframe =\n speed < 0 || (repeat && repeatType !== \"loop\" && repeat % 2 === 1)\n const index = useFirstKeyframe ? 0 : numResolved - 1\n\n return !index || finalKeyframe === undefined\n ? ((index ? last : first) as T)\n : finalKeyframe\n}\n"],"names":[],"mappings":"SAEgB,gBAAgB,CAC5B,SAAc,EACd,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,EAA4B,EACzD,aAAiB,EACjB,QAAgB,CAAC,EAAA;AAEjB;;;;AAIG;AACH,IAAA,IAAI,KAAoB;AACxB,IAAA,IAAI,IAAmB;IACvB,IAAI,WAAW,GAAG,CAAC;AACnB,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACvC,QAAA,MAAM,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC;AAC7B,QAAA,IAAI,QAAQ,KAAK,IAAI,EAAE;YACnB,IAAI,CAAC,WAAW,EAAE;gBAAE,KAAK,GAAG,QAAQ;YACpC,IAAI,GAAG,QAAQ;QACnB;IACJ;AAEA,IAAA,MAAM,gBAAgB,GAClB,KAAK,GAAG,CAAC,KAAK,MAAM,IAAI,UAAU,KAAK,MAAM,IAAI,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC;AACtE,IAAA,MAAM,KAAK,GAAG,gBAAgB,GAAG,CAAC,GAAG,WAAW,GAAG,CAAC;AAEpD,IAAA,OAAO,CAAC,KAAK,IAAI,aAAa,KAAK;WAC3B,KAAK,GAAG,IAAI,GAAG,KAAK;UACtB,aAAa;AACvB;;;;"}
|