motion-dom 14.0.0 → 14.1.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.
@@ -1,9 +1,16 @@
1
1
  import { buildHTMLStyles } from '../../html/utils/build-styles.mjs';
2
2
  import { buildSVGPath } from './path.mjs';
3
3
 
4
+ /**
5
+ * Values rendered via style rather than as attributes. This must include
6
+ * every value WAAPI can accelerate, as WAAPI writes its final value to
7
+ * style, which would otherwise override later attribute writes.
8
+ */
4
9
  const cssStyleProperties = [
5
10
  "transform",
6
11
  "opacity",
12
+ "clipPath",
13
+ "filter",
7
14
  "offsetDistance",
8
15
  "offsetPath",
9
16
  "offsetRotate",
@@ -1 +1 @@
1
- {"version":3,"file":"build-attrs.mjs","sources":["../../../../../src/render/svg/utils/build-attrs.ts"],"sourcesContent":["import type { MotionNodeOptions } from \"../../../node/types\"\nimport { buildHTMLStyles } from \"../../html/utils/build-styles\"\nimport { ResolvedValues } from \"../../types\"\nimport { SVGRenderState } from \"../types\"\nimport { buildSVGPath } from \"./path\"\n\nexport const cssStyleProperties = [\n \"transform\",\n \"opacity\",\n \"offsetDistance\",\n \"offsetPath\",\n \"offsetRotate\",\n \"offsetAnchor\",\n]\n\n/**\n * Build SVG visual attributes, like cx and style.transform\n */\nexport function buildSVGAttrs(\n state: SVGRenderState,\n {\n attrX,\n attrY,\n attrScale,\n pathLength,\n pathSpacing = 1,\n pathOffset = 0,\n // This is object creation, which we try to avoid per-frame.\n ...latest\n }: ResolvedValues,\n isSVGTag: boolean,\n transformTemplate?: MotionNodeOptions[\"transformTemplate\"],\n styleProp?: Record<string, any>\n) {\n buildHTMLStyles(state, latest, transformTemplate)\n\n /**\n * For svg tags we just want to make sure viewBox is animatable and treat all the styles\n * as normal HTML tags.\n */\n if (isSVGTag) {\n if (state.style.viewBox) {\n state.attrs.viewBox = state.style.viewBox\n }\n return\n }\n\n state.attrs = state.style\n state.style = {}\n const { attrs, style } = state\n\n for (const key of cssStyleProperties) {\n if (attrs[key] !== undefined) {\n style[key] = attrs[key]\n delete attrs[key]\n }\n }\n\n if (style.transform || attrs.transformOrigin) {\n style.transformOrigin = attrs.transformOrigin ?? \"50% 50%\"\n delete attrs.transformOrigin\n }\n\n if (style.transform) {\n /**\n * SVG's element transform-origin uses its own median as a reference.\n * Therefore, transformBox becomes a fill-box\n */\n style.transformBox = (styleProp?.transformBox as string) ?? \"fill-box\"\n delete attrs.transformBox\n }\n\n // Render attrX/attrY/attrScale as attributes\n if (attrX !== undefined) attrs.x = attrX\n if (attrY !== undefined) attrs.y = attrY\n if (attrScale !== undefined) attrs.scale = attrScale\n\n // Build SVG path if one has been defined\n if (pathLength !== undefined) {\n buildSVGPath(\n attrs,\n pathLength as number,\n pathSpacing as number,\n pathOffset as number,\n false\n )\n }\n}\n"],"names":[],"mappings":";;;AAMO,MAAM,kBAAkB,GAAG;IAC9B,WAAW;IACX,SAAS;IACT,gBAAgB;IAChB,YAAY;IACZ,cAAc;IACd,cAAc;;AAGlB;;AAEG;AACG,SAAU,aAAa,CACzB,KAAqB,EACrB,EACI,KAAK,EACL,KAAK,EACL,SAAS,EACT,UAAU,EACV,WAAW,GAAG,CAAC,EACf,UAAU,GAAG,CAAC;AACd;AACA,GAAG,MAAM,EACI,EACjB,QAAiB,EACjB,iBAA0D,EAC1D,SAA+B,EAAA;AAE/B,IAAA,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,iBAAiB,CAAC;AAEjD;;;AAGG;IACH,IAAI,QAAQ,EAAE;AACV,QAAA,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE;YACrB,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO;QAC7C;QACA;IACJ;AAEA,IAAA,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK;AACzB,IAAA,KAAK,CAAC,KAAK,GAAG,EAAE;AAChB,IAAA,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,KAAK;AAE9B,IAAA,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE;AAClC,QAAA,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE;YAC1B,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC;AACvB,YAAA,OAAO,KAAK,CAAC,GAAG,CAAC;QACrB;IACJ;IAEA,IAAI,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,eAAe,EAAE;QAC1C,KAAK,CAAC,eAAe,GAAG,KAAK,CAAC,eAAe,IAAI,SAAS;QAC1D,OAAO,KAAK,CAAC,eAAe;IAChC;AAEA,IAAA,IAAI,KAAK,CAAC,SAAS,EAAE;AACjB;;;AAGG;QACH,KAAK,CAAC,YAAY,GAAI,SAAS,EAAE,YAAuB,IAAI,UAAU;QACtE,OAAO,KAAK,CAAC,YAAY;IAC7B;;IAGA,IAAI,KAAK,KAAK,SAAS;AAAE,QAAA,KAAK,CAAC,CAAC,GAAG,KAAK;IACxC,IAAI,KAAK,KAAK,SAAS;AAAE,QAAA,KAAK,CAAC,CAAC,GAAG,KAAK;IACxC,IAAI,SAAS,KAAK,SAAS;AAAE,QAAA,KAAK,CAAC,KAAK,GAAG,SAAS;;AAGpD,IAAA,IAAI,UAAU,KAAK,SAAS,EAAE;QAC1B,YAAY,CACR,KAAK,EACL,UAAoB,EACpB,WAAqB,EACrB,UAAoB,EACpB,KAAK,CACR;IACL;AACJ;;;;"}
1
+ {"version":3,"file":"build-attrs.mjs","sources":["../../../../../src/render/svg/utils/build-attrs.ts"],"sourcesContent":["import type { MotionNodeOptions } from \"../../../node/types\"\nimport { buildHTMLStyles } from \"../../html/utils/build-styles\"\nimport { ResolvedValues } from \"../../types\"\nimport { SVGRenderState } from \"../types\"\nimport { buildSVGPath } from \"./path\"\n\n/**\n * Values rendered via style rather than as attributes. This must include\n * every value WAAPI can accelerate, as WAAPI writes its final value to\n * style, which would otherwise override later attribute writes.\n */\nexport const cssStyleProperties = [\n \"transform\",\n \"opacity\",\n \"clipPath\",\n \"filter\",\n \"offsetDistance\",\n \"offsetPath\",\n \"offsetRotate\",\n \"offsetAnchor\",\n]\n\n/**\n * Build SVG visual attributes, like cx and style.transform\n */\nexport function buildSVGAttrs(\n state: SVGRenderState,\n {\n attrX,\n attrY,\n attrScale,\n pathLength,\n pathSpacing = 1,\n pathOffset = 0,\n // This is object creation, which we try to avoid per-frame.\n ...latest\n }: ResolvedValues,\n isSVGTag: boolean,\n transformTemplate?: MotionNodeOptions[\"transformTemplate\"],\n styleProp?: Record<string, any>\n) {\n buildHTMLStyles(state, latest, transformTemplate)\n\n /**\n * For svg tags we just want to make sure viewBox is animatable and treat all the styles\n * as normal HTML tags.\n */\n if (isSVGTag) {\n if (state.style.viewBox) {\n state.attrs.viewBox = state.style.viewBox\n }\n return\n }\n\n state.attrs = state.style\n state.style = {}\n const { attrs, style } = state\n\n for (const key of cssStyleProperties) {\n if (attrs[key] !== undefined) {\n style[key] = attrs[key]\n delete attrs[key]\n }\n }\n\n if (style.transform || attrs.transformOrigin) {\n style.transformOrigin = attrs.transformOrigin ?? \"50% 50%\"\n delete attrs.transformOrigin\n }\n\n if (style.transform) {\n /**\n * SVG's element transform-origin uses its own median as a reference.\n * Therefore, transformBox becomes a fill-box\n */\n style.transformBox = (styleProp?.transformBox as string) ?? \"fill-box\"\n delete attrs.transformBox\n }\n\n // Render attrX/attrY/attrScale as attributes\n if (attrX !== undefined) attrs.x = attrX\n if (attrY !== undefined) attrs.y = attrY\n if (attrScale !== undefined) attrs.scale = attrScale\n\n // Build SVG path if one has been defined\n if (pathLength !== undefined) {\n buildSVGPath(\n attrs,\n pathLength as number,\n pathSpacing as number,\n pathOffset as number,\n false\n )\n }\n}\n"],"names":[],"mappings":";;;AAMA;;;;AAIG;AACI,MAAM,kBAAkB,GAAG;IAC9B,WAAW;IACX,SAAS;IACT,UAAU;IACV,QAAQ;IACR,gBAAgB;IAChB,YAAY;IACZ,cAAc;IACd,cAAc;;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ACxC,IAAI,KAAK,KAAK,SAAS;AAAE,QAAA,KAAK,CAAC,CAAC,GAAG,KAAK;IACxC,IAAI,SAAS,KAAK,SAAS;AAAE,QAAA,KAAK,CAAC,KAAK,GAAG,SAAS;;AAGpD,IAAA,IAAI,UAAU,KAAK,SAAS,EAAE;QAC1B,YAAY,CACR,KAAK,EACL,UAAoB,EACpB,WAAqB,EACrB,UAAoB,EACpB,KAAK,CACR;IACL;AACJ;;;;"}
@@ -195,6 +195,21 @@ function createAnimationState(visualElement) {
195
195
  : visualElement.initialValues[key] === undefined
196
196
  ? visualElement.baseTarget[key]
197
197
  : undefined) ?? null;
198
+ /**
199
+ * If it stays where it is, that's now its base. Otherwise a
200
+ * later removal (like a gesture ending) would also stay,
201
+ * leaving the value stuck. Stop first so accelerated
202
+ * animations sync the value they reached. In practice initial
203
+ * only changes like this with Fast Refresh, so this is
204
+ * dev-only (#3787).
205
+ */
206
+ if (process.env.NODE_ENV !== "production" &&
207
+ fallbackAnimation[key] === null &&
208
+ visualElement.initialValues[key] !== undefined) {
209
+ delete visualElement.initialValues[key];
210
+ motionValue?.stop();
211
+ visualElement.baseTarget[key] = motionValue?.get();
212
+ }
198
213
  });
199
214
  animations.push({ animation: fallbackAnimation });
200
215
  }
@@ -1 +1 @@
1
- {"version":3,"file":"animation-state.mjs","sources":["../../../../src/render/utils/animation-state.ts"],"sourcesContent":["import type {\n AnimationDefinition,\n TargetAndTransition,\n VariantLabels,\n} from \"../../node/types\"\nimport type { AnimationType } from \"../types\"\nimport type { VisualElementAnimationOptions } from \"../../animation/interfaces/types\"\nimport { animateVisualElement } from \"../../animation/interfaces/visual-element\"\nimport { calcChildStagger } from \"../../animation/utils/calc-child-stagger\"\nimport { isMotionValue } from \"../../value/utils/is-motion-value\"\nimport { isAnimationControls } from \"./is-animation-controls\"\nimport { isVariantLabel } from \"./is-variant-label\"\nimport { getTypeCustom, resolveVariant } from \"./resolve-dynamic-variants\"\nimport { shallowCompare } from \"./shallow-compare\"\nimport { variantPriorityOrder } from \"./variant-props\"\n\nexport type { VisualElementAnimationOptions }\n\nexport interface AnimationState {\n animateChanges: (type?: AnimationType) => Promise<any>\n setActive: (\n type: AnimationType,\n isActive: boolean,\n options?: VisualElementAnimationOptions\n ) => Promise<any>\n setAnimateFunction: (fn: any) => void\n getState: () => { [key: string]: AnimationTypeState }\n reset: () => void\n}\n\ninterface DefinitionAndOptions {\n animation: AnimationDefinition\n options?: VisualElementAnimationOptions\n}\n\nexport type AnimationList = string[] | TargetAndTransition[]\n\n/**\n * Type for the animate function that can be injected.\n * This allows the animation implementation to be provided by the framework layer.\n */\nexport type AnimateFunction = (animations: DefinitionAndOptions[]) => Promise<any>\n\nconst reversePriorityOrder = [...variantPriorityOrder].reverse()\n\n/**\n * Diffs the element's animation props (one layer per AnimationType, highest\n * priority wins each value) against the previous call and starts animations\n * for what changed.\n *\n * Uses `any` type for visualElement to avoid circular dependencies. It reads\n * props, parent, presenceContext, variantChildren, enteringChildren,\n * manuallyAnimateOnMount, blockInitialAnimation, getValue(),\n * getBaseTargetFromProps(), baseTarget and initialValues.\n */\nexport function createAnimationState(visualElement: any): AnimationState {\n let animate: AnimateFunction = (animations) =>\n Promise.all(\n animations.map(({ animation, options }) =>\n animateVisualElement(visualElement, animation, options)\n )\n )\n let state = createState()\n let isInitialRender = true\n\n /**\n * After a reset (StrictMode, Suspense, AnimatePresence re-entry) the next\n * animateChanges() mounts again, but initial={false} no longer applies.\n */\n let wasReset = false\n\n function animateChanges(changedActiveType?: AnimationType) {\n const { props, parent, manuallyAnimateOnMount } = visualElement\n const isMounting = isInitialRender || wasReset\n const animations: DefinitionAndOptions[] = []\n\n /**\n * Values removed from a type. A lower-priority type that defines\n * them animates them back, otherwise they fall back to a base target.\n */\n const removedKeys = new Set<string>()\n\n /**\n * Values claimed by active, higher-priority types.\n */\n let encounteredKeys: { [key: string]: any } = {}\n\n /**\n * Once a type has been deactivated, lower-priority variant labels\n * re-animate so variant children animate back too.\n */\n let removedVariantIndex = Infinity\n\n /**\n * Variant labels are inherited from the closest variant-controlling\n * ancestor, unless an element on the way has inherit={false}.\n */\n let source = visualElement\n do source = source.props.inherit !== false && source.parent\n while (source && !source.isControllingVariants)\n\n reversePriorityOrder.forEach((type, i) => {\n const typeState = state[type]\n const ownProp = props[type]\n const inheritedProp = source && source.props[type]\n const prop =\n ownProp !== undefined\n ? ownProp\n : isVariantLabel(inheritedProp) || inheritedProp === false\n ? inheritedProp\n : undefined\n const propIsVariant = isVariantLabel(prop)\n const activeDelta =\n type === changedActiveType ? typeState.isActive : null\n\n if (activeDelta === false) removedVariantIndex = i\n\n /**\n * Inherited labels are animated by the parent through\n * variantChildren, unless this element mounted after its parent.\n */\n const isInherited =\n propIsVariant &&\n ownProp === undefined &&\n !(isMounting && manuallyAnimateOnMount)\n\n typeState.protectedKeys = { ...encounteredKeys }\n\n if (\n (!typeState.isActive && activeDelta === null) ||\n (!prop && !typeState.prevProp) ||\n isAnimationControls(prop) ||\n typeof prop === \"boolean\"\n ) {\n return\n }\n\n /**\n * Don't re-resolve a running exit: a changed custom would start\n * new value animations that stop the originals, leaving the exit\n * promise unresolved and the element stuck in the DOM.\n */\n if (type === \"exit\" && typeState.isActive && activeDelta !== true) {\n encounteredKeys = {\n ...encounteredKeys,\n ...typeState.prevResolvedValues,\n }\n return\n }\n\n const variantDidChange = checkVariantsDidChange(\n typeState.prevProp,\n prop\n )\n let shouldAnimateType =\n variantDidChange ||\n (propIsVariant &&\n ((activeDelta && !isInherited) || i > removedVariantIndex))\n let handledRemovedValues = false\n const definitionList = Array.isArray(prop) ? prop : [prop]\n let resolvedValues: { [key: string]: any } = {}\n\n if (activeDelta !== false) {\n for (const definition of definitionList) {\n const { transition, transitionEnd, ...target } =\n resolveVariant(\n visualElement,\n definition,\n getTypeCustom(visualElement, type)\n ) || {}\n resolvedValues = {\n ...resolvedValues,\n ...target,\n ...transitionEnd,\n }\n }\n }\n\n const { prevResolvedValues } = typeState\n\n for (const key in { ...prevResolvedValues, ...resolvedValues }) {\n if (key in encounteredKeys) continue\n\n const next = resolvedValues[key]\n const prev = prevResolvedValues[key]\n\n /**\n * Keyframes compare by value, but replay whenever the\n * variant label changed.\n */\n const valueHasChanged =\n Array.isArray(next) && Array.isArray(prev)\n ? !shallowCompare(next, prev) || variantDidChange\n : next !== prev\n\n if (\n valueHasChanged &&\n (next === undefined || next === null)\n ) {\n removedKeys.add(key)\n } else if (\n valueHasChanged ||\n (next !== undefined && removedKeys.has(key))\n ) {\n shouldAnimateType = true\n if (removedKeys.delete(key)) handledRemovedValues = true\n typeState.needsAnimating[key] = true\n\n const motionValue = visualElement.getValue(key)\n if (motionValue) motionValue.liveStyle = false\n } else {\n typeState.protectedKeys[key] = true\n }\n }\n\n typeState.prevProp = prop\n typeState.prevResolvedValues = resolvedValues\n\n if (typeState.isActive) {\n encounteredKeys = { ...encounteredKeys, ...resolvedValues }\n }\n\n if (\n shouldAnimateType &&\n (!(isInherited && variantDidChange) || handledRemovedValues)\n ) {\n for (const animation of definitionList) {\n const options: VisualElementAnimationOptions = { type }\n\n /**\n * Elements that mount into an already-mounted parent\n * animate themselves, staggered by the parent variant's\n * delayChildren.\n */\n if (\n typeof animation === \"string\" &&\n isMounting &&\n manuallyAnimateOnMount &&\n parent?.enteringChildren\n ) {\n const delayChildren = resolveVariant(parent, animation)\n ?.transition?.delayChildren\n\n options.delay = calcChildStagger(\n parent.enteringChildren,\n visualElement,\n delayChildren\n )\n }\n\n animations.push({ animation, options })\n }\n }\n })\n\n /**\n * Removed values that no lower-priority type defines animate back to\n * initial, then style, then the value as first read. If initial no\n * longer defines a value it once did, it stays where it is.\n */\n if (removedKeys.size) {\n const { initial } = props\n const fallbackAnimation: { [key: string]: any } = {}\n const resolvedInitial =\n typeof initial !== \"boolean\" &&\n resolveVariant(\n visualElement,\n Array.isArray(initial) ? initial[0] : initial,\n visualElement.presenceContext?.custom\n )\n\n if (resolvedInitial && resolvedInitial.transition) {\n fallbackAnimation.transition = resolvedInitial.transition\n }\n\n removedKeys.forEach((key) => {\n const motionValue = visualElement.getValue(key)\n if (motionValue) motionValue.liveStyle = true\n\n const fromInitial =\n resolvedInitial && !Array.isArray(initial)\n ? (resolvedInitial as any)[key]\n : undefined\n const fromProps = visualElement.getBaseTargetFromProps(\n props,\n key\n )\n\n fallbackAnimation[key] =\n (fromInitial !== undefined\n ? fromInitial\n : fromProps !== undefined && !isMotionValue(fromProps)\n ? fromProps\n : visualElement.initialValues[key] === undefined\n ? visualElement.baseTarget[key]\n : undefined) ?? null\n })\n\n animations.push({ animation: fallbackAnimation })\n }\n\n const blockAnimation =\n (isMounting && visualElement.blockInitialAnimation) ||\n (isInitialRender &&\n !manuallyAnimateOnMount &&\n (props.initial === false || props.initial === props.animate))\n\n isInitialRender = wasReset = false\n\n return !blockAnimation && animations.length\n ? animate(animations)\n : Promise.resolve()\n }\n\n /**\n * Change whether a certain animation type is active.\n */\n function setActive(type: AnimationType, isActive: boolean) {\n if (state[type].isActive === isActive) return Promise.resolve()\n\n visualElement.variantChildren?.forEach((child: any) =>\n child.animationState?.setActive(type, isActive)\n )\n\n state[type].isActive = isActive\n\n const animations = animateChanges(type)\n\n for (const key in state) {\n state[key as AnimationType].protectedKeys = {}\n }\n\n return animations\n }\n\n return {\n animateChanges,\n setActive,\n /**\n * Allows tests to inject a mocked animate function.\n * @internal\n */\n setAnimateFunction: (makeAnimator) => {\n animate = makeAnimator(visualElement)\n },\n getState: () => state,\n reset: () => {\n state = createState()\n wasReset = true\n },\n }\n}\n\nexport function checkVariantsDidChange(prev: any, next: any) {\n if (typeof next === \"string\") {\n return next !== prev\n } else if (Array.isArray(next)) {\n return !shallowCompare(next, prev)\n }\n\n return false\n}\n\nexport interface AnimationTypeState {\n isActive: boolean\n protectedKeys: { [key: string]: true }\n needsAnimating: { [key: string]: boolean }\n prevResolvedValues: { [key: string]: any }\n prevProp?: VariantLabels | TargetAndTransition\n}\n\nfunction createState() {\n const state = {} as { [K in AnimationType]: AnimationTypeState }\n\n for (const type of variantPriorityOrder) {\n state[type] = {\n isActive: type === \"animate\",\n protectedKeys: {},\n needsAnimating: {},\n prevResolvedValues: {},\n }\n }\n\n return state\n}\n"],"names":[],"mappings":";;;;;;;;;AA2CA,MAAM,oBAAoB,GAAG,CAAC,GAAG,oBAAoB,CAAC,CAAC,OAAO,EAAE;AAEhE;;;;;;;;;AASG;AACG,SAAU,oBAAoB,CAAC,aAAkB,EAAA;AACnD,IAAA,IAAI,OAAO,GAAoB,CAAC,UAAU,KACtC,OAAO,CAAC,GAAG,CACP,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,KAClC,oBAAoB,CAAC,aAAa,EAAE,SAAS,EAAE,OAAO,CAAC,CAC1D,CACJ;AACL,IAAA,IAAI,KAAK,GAAG,WAAW,EAAE;IACzB,IAAI,eAAe,GAAG,IAAI;AAE1B;;;AAGG;IACH,IAAI,QAAQ,GAAG,KAAK;IAEpB,SAAS,cAAc,CAAC,iBAAiC,EAAA;QACrD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,sBAAsB,EAAE,GAAG,aAAa;AAC/D,QAAA,MAAM,UAAU,GAAG,eAAe,IAAI,QAAQ;QAC9C,MAAM,UAAU,GAA2B,EAAE;AAE7C;;;AAGG;AACH,QAAA,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU;AAErC;;AAEG;QACH,IAAI,eAAe,GAA2B,EAAE;AAEhD;;;AAGG;QACH,IAAI,mBAAmB,GAAG,QAAQ;AAElC;;;AAGG;QACH,IAAI,MAAM,GAAG,aAAa;AAC1B,QAAA;AAAG,YAAA,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,KAAK,KAAK,IAAI,MAAM,CAAC,MAAM;AACpD,eAAA,MAAM,IAAI,CAAC,MAAM,CAAC,qBAAqB;QAE9C,oBAAoB,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,KAAI;AACrC,YAAA,MAAM,SAAS,GAAG,KAAK,CA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;YACrB,QAAQ,GAAG,IAAI;QACnB,CAAC;KACJ;AACL;AAEM,SAAU,sBAAsB,CAAC,IAAS,EAAE,IAAS,EAAA;AACvD,IAAA,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC1B,OAAO,IAAI,KAAK,IAAI;IACxB;AAAO,SAAA,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;AAC5B,QAAA,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC;IACtC;AAEA,IAAA,OAAO,KAAK;AAChB;AAUA,SAAS,WAAW,GAAA;IAChB,MAAM,KAAK,GAAG,EAAkD;AAEhE,IAAA,KAAK,MAAM,IAAI,IAAI,oBAAoB,EAAE;QACrC,KAAK,CAAC,IAAI,CAAC,GAAG;YACV,QAAQ,EAAE,IAAI,KAAK,SAAS;AAC5B,YAAA,aAAa,EAAE,EAAE;AACjB,YAAA,cAAc,EAAE,EAAE;AAClB,YAAA,kBAAkB,EAAE,EAAE;SACzB;IACL;AAEA,IAAA,OAAO,KAAK;AAChB;;;;"}
1
+ {"version":3,"file":"animation-state.mjs","sources":["../../../../src/render/utils/animation-state.ts"],"sourcesContent":["import type {\n AnimationDefinition,\n TargetAndTransition,\n VariantLabels,\n} from \"../../node/types\"\nimport type { AnimationType } from \"../types\"\nimport type { VisualElementAnimationOptions } from \"../../animation/interfaces/types\"\nimport { animateVisualElement } from \"../../animation/interfaces/visual-element\"\nimport { calcChildStagger } from \"../../animation/utils/calc-child-stagger\"\nimport { isMotionValue } from \"../../value/utils/is-motion-value\"\nimport { isAnimationControls } from \"./is-animation-controls\"\nimport { isVariantLabel } from \"./is-variant-label\"\nimport { getTypeCustom, resolveVariant } from \"./resolve-dynamic-variants\"\nimport { shallowCompare } from \"./shallow-compare\"\nimport { variantPriorityOrder } from \"./variant-props\"\n\nexport type { VisualElementAnimationOptions }\n\nexport interface AnimationState {\n animateChanges: (type?: AnimationType) => Promise<any>\n setActive: (\n type: AnimationType,\n isActive: boolean,\n options?: VisualElementAnimationOptions\n ) => Promise<any>\n setAnimateFunction: (fn: any) => void\n getState: () => { [key: string]: AnimationTypeState }\n reset: () => void\n}\n\ninterface DefinitionAndOptions {\n animation: AnimationDefinition\n options?: VisualElementAnimationOptions\n}\n\nexport type AnimationList = string[] | TargetAndTransition[]\n\n/**\n * Type for the animate function that can be injected.\n * This allows the animation implementation to be provided by the framework layer.\n */\nexport type AnimateFunction = (animations: DefinitionAndOptions[]) => Promise<any>\n\nconst reversePriorityOrder = [...variantPriorityOrder].reverse()\n\n/**\n * Diffs the element's animation props (one layer per AnimationType, highest\n * priority wins each value) against the previous call and starts animations\n * for what changed.\n *\n * Uses `any` type for visualElement to avoid circular dependencies. It reads\n * props, parent, presenceContext, variantChildren, enteringChildren,\n * manuallyAnimateOnMount, blockInitialAnimation, getValue(),\n * getBaseTargetFromProps(), baseTarget and initialValues.\n */\nexport function createAnimationState(visualElement: any): AnimationState {\n let animate: AnimateFunction = (animations) =>\n Promise.all(\n animations.map(({ animation, options }) =>\n animateVisualElement(visualElement, animation, options)\n )\n )\n let state = createState()\n let isInitialRender = true\n\n /**\n * After a reset (StrictMode, Suspense, AnimatePresence re-entry) the next\n * animateChanges() mounts again, but initial={false} no longer applies.\n */\n let wasReset = false\n\n function animateChanges(changedActiveType?: AnimationType) {\n const { props, parent, manuallyAnimateOnMount } = visualElement\n const isMounting = isInitialRender || wasReset\n const animations: DefinitionAndOptions[] = []\n\n /**\n * Values removed from a type. A lower-priority type that defines\n * them animates them back, otherwise they fall back to a base target.\n */\n const removedKeys = new Set<string>()\n\n /**\n * Values claimed by active, higher-priority types.\n */\n let encounteredKeys: { [key: string]: any } = {}\n\n /**\n * Once a type has been deactivated, lower-priority variant labels\n * re-animate so variant children animate back too.\n */\n let removedVariantIndex = Infinity\n\n /**\n * Variant labels are inherited from the closest variant-controlling\n * ancestor, unless an element on the way has inherit={false}.\n */\n let source = visualElement\n do source = source.props.inherit !== false && source.parent\n while (source && !source.isControllingVariants)\n\n reversePriorityOrder.forEach((type, i) => {\n const typeState = state[type]\n const ownProp = props[type]\n const inheritedProp = source && source.props[type]\n const prop =\n ownProp !== undefined\n ? ownProp\n : isVariantLabel(inheritedProp) || inheritedProp === false\n ? inheritedProp\n : undefined\n const propIsVariant = isVariantLabel(prop)\n const activeDelta =\n type === changedActiveType ? typeState.isActive : null\n\n if (activeDelta === false) removedVariantIndex = i\n\n /**\n * Inherited labels are animated by the parent through\n * variantChildren, unless this element mounted after its parent.\n */\n const isInherited =\n propIsVariant &&\n ownProp === undefined &&\n !(isMounting && manuallyAnimateOnMount)\n\n typeState.protectedKeys = { ...encounteredKeys }\n\n if (\n (!typeState.isActive && activeDelta === null) ||\n (!prop && !typeState.prevProp) ||\n isAnimationControls(prop) ||\n typeof prop === \"boolean\"\n ) {\n return\n }\n\n /**\n * Don't re-resolve a running exit: a changed custom would start\n * new value animations that stop the originals, leaving the exit\n * promise unresolved and the element stuck in the DOM.\n */\n if (type === \"exit\" && typeState.isActive && activeDelta !== true) {\n encounteredKeys = {\n ...encounteredKeys,\n ...typeState.prevResolvedValues,\n }\n return\n }\n\n const variantDidChange = checkVariantsDidChange(\n typeState.prevProp,\n prop\n )\n let shouldAnimateType =\n variantDidChange ||\n (propIsVariant &&\n ((activeDelta && !isInherited) || i > removedVariantIndex))\n let handledRemovedValues = false\n const definitionList = Array.isArray(prop) ? prop : [prop]\n let resolvedValues: { [key: string]: any } = {}\n\n if (activeDelta !== false) {\n for (const definition of definitionList) {\n const { transition, transitionEnd, ...target } =\n resolveVariant(\n visualElement,\n definition,\n getTypeCustom(visualElement, type)\n ) || {}\n resolvedValues = {\n ...resolvedValues,\n ...target,\n ...transitionEnd,\n }\n }\n }\n\n const { prevResolvedValues } = typeState\n\n for (const key in { ...prevResolvedValues, ...resolvedValues }) {\n if (key in encounteredKeys) continue\n\n const next = resolvedValues[key]\n const prev = prevResolvedValues[key]\n\n /**\n * Keyframes compare by value, but replay whenever the\n * variant label changed.\n */\n const valueHasChanged =\n Array.isArray(next) && Array.isArray(prev)\n ? !shallowCompare(next, prev) || variantDidChange\n : next !== prev\n\n if (\n valueHasChanged &&\n (next === undefined || next === null)\n ) {\n removedKeys.add(key)\n } else if (\n valueHasChanged ||\n (next !== undefined && removedKeys.has(key))\n ) {\n shouldAnimateType = true\n if (removedKeys.delete(key)) handledRemovedValues = true\n typeState.needsAnimating[key] = true\n\n const motionValue = visualElement.getValue(key)\n if (motionValue) motionValue.liveStyle = false\n } else {\n typeState.protectedKeys[key] = true\n }\n }\n\n typeState.prevProp = prop\n typeState.prevResolvedValues = resolvedValues\n\n if (typeState.isActive) {\n encounteredKeys = { ...encounteredKeys, ...resolvedValues }\n }\n\n if (\n shouldAnimateType &&\n (!(isInherited && variantDidChange) || handledRemovedValues)\n ) {\n for (const animation of definitionList) {\n const options: VisualElementAnimationOptions = { type }\n\n /**\n * Elements that mount into an already-mounted parent\n * animate themselves, staggered by the parent variant's\n * delayChildren.\n */\n if (\n typeof animation === \"string\" &&\n isMounting &&\n manuallyAnimateOnMount &&\n parent?.enteringChildren\n ) {\n const delayChildren = resolveVariant(parent, animation)\n ?.transition?.delayChildren\n\n options.delay = calcChildStagger(\n parent.enteringChildren,\n visualElement,\n delayChildren\n )\n }\n\n animations.push({ animation, options })\n }\n }\n })\n\n /**\n * Removed values that no lower-priority type defines animate back to\n * initial, then style, then the value as first read. If initial no\n * longer defines a value it once did, it stays where it is.\n */\n if (removedKeys.size) {\n const { initial } = props\n const fallbackAnimation: { [key: string]: any } = {}\n const resolvedInitial =\n typeof initial !== \"boolean\" &&\n resolveVariant(\n visualElement,\n Array.isArray(initial) ? initial[0] : initial,\n visualElement.presenceContext?.custom\n )\n\n if (resolvedInitial && resolvedInitial.transition) {\n fallbackAnimation.transition = resolvedInitial.transition\n }\n\n removedKeys.forEach((key) => {\n const motionValue = visualElement.getValue(key)\n if (motionValue) motionValue.liveStyle = true\n\n const fromInitial =\n resolvedInitial && !Array.isArray(initial)\n ? (resolvedInitial as any)[key]\n : undefined\n const fromProps = visualElement.getBaseTargetFromProps(\n props,\n key\n )\n\n fallbackAnimation[key] =\n (fromInitial !== undefined\n ? fromInitial\n : fromProps !== undefined && !isMotionValue(fromProps)\n ? fromProps\n : visualElement.initialValues[key] === undefined\n ? visualElement.baseTarget[key]\n : undefined) ?? null\n\n /**\n * If it stays where it is, that's now its base. Otherwise a\n * later removal (like a gesture ending) would also stay,\n * leaving the value stuck. Stop first so accelerated\n * animations sync the value they reached. In practice initial\n * only changes like this with Fast Refresh, so this is\n * dev-only (#3787).\n */\n if (\n process.env.NODE_ENV !== \"production\" &&\n fallbackAnimation[key] === null &&\n visualElement.initialValues[key] !== undefined\n ) {\n delete visualElement.initialValues[key]\n motionValue?.stop()\n visualElement.baseTarget[key] = motionValue?.get()\n }\n })\n\n animations.push({ animation: fallbackAnimation })\n }\n\n const blockAnimation =\n (isMounting && visualElement.blockInitialAnimation) ||\n (isInitialRender &&\n !manuallyAnimateOnMount &&\n (props.initial === false || props.initial === props.animate))\n\n isInitialRender = wasReset = false\n\n return !blockAnimation && animations.length\n ? animate(animations)\n : Promise.resolve()\n }\n\n /**\n * Change whether a certain animation type is active.\n */\n function setActive(type: AnimationType, isActive: boolean) {\n if (state[type].isActive === isActive) return Promise.resolve()\n\n visualElement.variantChildren?.forEach((child: any) =>\n child.animationState?.setActive(type, isActive)\n )\n\n state[type].isActive = isActive\n\n const animations = animateChanges(type)\n\n for (const key in state) {\n state[key as AnimationType].protectedKeys = {}\n }\n\n return animations\n }\n\n return {\n animateChanges,\n setActive,\n /**\n * Allows tests to inject a mocked animate function.\n * @internal\n */\n setAnimateFunction: (makeAnimator) => {\n animate = makeAnimator(visualElement)\n },\n getState: () => state,\n reset: () => {\n state = createState()\n wasReset = true\n },\n }\n}\n\nexport function checkVariantsDidChange(prev: any, next: any) {\n if (typeof next === \"string\") {\n return next !== prev\n } else if (Array.isArray(next)) {\n return !shallowCompare(next, prev)\n }\n\n return false\n}\n\nexport interface AnimationTypeState {\n isActive: boolean\n protectedKeys: { [key: string]: true }\n needsAnimating: { [key: string]: boolean }\n prevResolvedValues: { [key: string]: any }\n prevProp?: VariantLabels | TargetAndTransition\n}\n\nfunction createState() {\n const state = {} as { [K in AnimationType]: AnimationTypeState }\n\n for (const type of variantPriorityOrder) {\n state[type] = {\n isActive: type === \"animate\",\n protectedKeys: {},\n needsAnimating: {},\n prevResolvedValues: {},\n }\n }\n\n return state\n}\n"],"names":[],"mappings":";;;;;;;;;AA2CA,MAAM,oBAAoB,GAAG,CAAC,GAAG,oBAAoB,CAAC,CAAC,OAAO,EAAE;AAEhE;;;;;;;;;AASG;AACG,SAAU,oBAAoB,CAAC,aAAkB,EAAA;AACnD,IAAA,IAAI,OAAO,GAAoB,CAAC,UAAU,KACtC,OAAO,CAAC,GAAG,CACP,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,KAClC,oBAAoB,CAAC,aAAa,EAAE,SAAS,EAAE,OAAO,CAAC,CAC1D,CACJ;AACL,IAAA,IAAI,KAAK,GAAG,WAAW,EAAE;IACzB,IAAI,eAAe,GAAG,IAAI;AAE1B;;;AAGG;IACH,IAAI,QAAQ,GAAG,KAAK;IAEpB,SAAS,cAAc,CAAC,iBAAiC,EAAA;QACrD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,sBAAsB,EAAE,GAAG,aAAa;AAC/D,QAAA,MAAM,UAAU,GAAG,eAAe,IAAI,QAAQ;QAC9C,MAAM,UAAU,GAA2B,EAAE;AAE7C;;;AAGG;AACH,QAAA,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU;AAErC;;AAEG;QACH,IAAI,eAAe,GAA2B,EAAE;AAEhD;;;AAGG;QACH,IAAI,mBAAmB,GAAG,QAAQ;AAElC;;;AAGG;QACH,IAAI,MAAM,GAAG,aAAa;AAC1B,QAAA;AAAG,YAAA,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,KAAK,KAAK,IAAI,MA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 @@ declare class JSAnimation<T extends number | string> extends WithPromise impleme
2803
2803
  */
2804
2804
  private driver?;
2805
2805
  private isStopped;
2806
+ /**
2807
+ * The start time this animation picked for itself, until its first tick.
2808
+ */
2809
+ private pendingStartTime?;
2806
2810
  private generator;
2807
2811
  private calculatedDuration;
2808
2812
  private resolvedDuration;
@@ -4709,6 +4713,8 @@ interface IProjectionNode<I = unknown> {
4709
4713
  options: ProjectionNodeOptions;
4710
4714
  setOptions(options: ProjectionNodeOptions): void;
4711
4715
  layout?: Measurements;
4716
+ dragSnapshot?: Measurements;
4717
+ dragAncestor?: IProjectionNode;
4712
4718
  snapshot?: Measurements;
4713
4719
  target?: Box;
4714
4720
  relativeTarget?: Box;
@@ -4769,7 +4775,6 @@ interface IProjectionNode<I = unknown> {
4769
4775
  currentAnimation?: JSAnimation<number>;
4770
4776
  isTreeAnimating?: boolean;
4771
4777
  isAnimationBlocked?: boolean;
4772
- isTreeAnimationBlocked: () => boolean;
4773
4778
  setAnimationOrigin(delta: Delta, hasOnlyRelativeTargetChanged?: boolean, pathFn?: MotionPath): void;
4774
4779
  startAnimation(transition: ValueTransition): void;
4775
4780
  finishAnimation(): void;
@@ -4904,6 +4909,15 @@ declare function createProjectionNode<I>({ attachResizeListener, defaultParent,
4904
4909
  * captured with all parent scrolls and projection transforms unset.
4905
4910
  */
4906
4911
  layout: Measurements | undefined;
4912
+ /**
4913
+ * A measurement taken just before the current update of a dragged node
4914
+ * without a snapshot (one without `layout`).
4915
+ */
4916
+ dragSnapshot: Measurements | undefined;
4917
+ /**
4918
+ * The nearest dragged ancestor, recorded in willUpdate.
4919
+ */
4920
+ dragAncestor: IProjectionNode | undefined;
4907
4921
  /**
4908
4922
  * The layout used to calculate the previous layout animation. We use this to compare
4909
4923
  * layouts between renders and decide whether we need to trigger a new layout animation
@@ -5072,7 +5086,6 @@ declare function createProjectionNode<I>({ attachResizeListener, defaultParent,
5072
5086
  blockUpdate(): void;
5073
5087
  unblockUpdate(): void;
5074
5088
  isUpdateBlocked(): boolean;
5075
- isTreeAnimationBlocked(): boolean;
5076
5089
  startUpdate(): void;
5077
5090
  getTransformTemplate(): TransformTemplate | undefined;
5078
5091
  willUpdate(shouldNotifyListeners?: boolean): void;
@@ -5180,6 +5193,8 @@ declare const DocumentProjectionNode: {
5180
5193
  options: ProjectionNodeOptions;
5181
5194
  snapshot: Measurements | undefined;
5182
5195
  layout: Measurements | undefined;
5196
+ dragSnapshot: Measurements | undefined;
5197
+ dragAncestor: IProjectionNode<unknown> | undefined;
5183
5198
  targetLayout?: motion_utils.Box | undefined;
5184
5199
  layoutCorrected: motion_utils.Box;
5185
5200
  targetDelta?: motion_utils.Delta | undefined;
@@ -5224,7 +5239,6 @@ declare const DocumentProjectionNode: {
5224
5239
  blockUpdate(): void;
5225
5240
  unblockUpdate(): void;
5226
5241
  isUpdateBlocked(): boolean;
5227
- isTreeAnimationBlocked(): boolean;
5228
5242
  startUpdate(): void;
5229
5243
  getTransformTemplate(): TransformTemplate | undefined;
5230
5244
  willUpdate(shouldNotifyListeners?: boolean): void;
@@ -5323,6 +5337,8 @@ declare const HTMLProjectionNode: {
5323
5337
  options: ProjectionNodeOptions;
5324
5338
  snapshot: Measurements | undefined;
5325
5339
  layout: Measurements | undefined;
5340
+ dragSnapshot: Measurements | undefined;
5341
+ dragAncestor: IProjectionNode<unknown> | undefined;
5326
5342
  targetLayout?: motion_utils.Box | undefined;
5327
5343
  layoutCorrected: motion_utils.Box;
5328
5344
  targetDelta?: motion_utils.Delta | undefined;
@@ -5367,7 +5383,6 @@ declare const HTMLProjectionNode: {
5367
5383
  blockUpdate(): void;
5368
5384
  unblockUpdate(): void;
5369
5385
  isUpdateBlocked(): boolean;
5370
- isTreeAnimationBlocked(): boolean;
5371
5386
  startUpdate(): void;
5372
5387
  getTransformTemplate(): TransformTemplate | undefined;
5373
5388
  willUpdate(shouldNotifyListeners?: boolean): void;
@@ -5539,6 +5554,18 @@ declare function parseAnimateLayoutArgs(scopeOrUpdateDom: ElementOrSelector | ((
5539
5554
  defaultOptions?: AnimationOptions;
5540
5555
  };
5541
5556
 
5557
+ /**
5558
+ * Animate layout changes made within `updateDom` on elements tagged
5559
+ * with `data-layout` or `data-layout-id`.
5560
+ *
5561
+ * ```
5562
+ * animateLayout(() => {
5563
+ * element.style.justifyContent = "flex-end"
5564
+ * })
5565
+ * ```
5566
+ */
5567
+ declare function animateLayout(scopeOrUpdateDom: ElementOrSelector | (() => void), updateDomOrOptions?: (() => void) | AnimationOptions, options?: AnimationOptions): LayoutAnimationBuilder;
5568
+
5542
5569
  /**
5543
5570
  * @deprecated
5544
5571
  *
@@ -5552,4 +5579,4 @@ declare const sync: Batcher;
5552
5579
  */
5553
5580
  declare const cancelSync: Record<string, (process: Process) => void>;
5554
5581
 
5555
- export { type AccelerateConfig, type AcceptedAnimations, type ActiveStatsBuffer, type AddEffectValue, type AnimateEffect, type AnimationDefinition, type AnimationGeneratorName, type AnimationGeneratorType, type AnimationList, type AnimationOptions, type AnimationOrchestrationOptions, type AnimationPlaybackControls, type AnimationPlaybackControlsWithThen, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState$1 as AnimationState, type AnimationType, type AnimationTypeState, type AnyResolvedKeyframe, type ArcOptions, AsyncMotionValueAnimation, type Batcher, type CSSStyleDeclarationWithTransform, type CSSVariableName, type CSSVariableToken, type CancelProcess, type Color, type ComplexValueInfo, type ComplexValues, type DOMKeyframesDefinition, DOMKeyframesResolver, type DOMValueAnimationOptions, DOMVisualElement, type DOMVisualElementOptions, type DecayOptions, type DelayedFunction, DocumentProjectionNode, type DragElastic, type DragHandler, type DraggableProps, type DurationSpringOptions, type DynamicOption, type Effect, type EffectKeyframes, type EffectOptions, type EffectRead, type EffectTest, type EffectTransition, type ElementOrSelector, type EventInfo, type EventOptions, Feature, type FeatureClass, FlatTree, type FollowValueOptions, type FrameData, type GeneratorFactory, type GeneratorFactoryFunction, GroupAnimation, GroupAnimationWithThen, type GroupedAnimations, type HSLA, HTMLProjectionNode, type HTMLRenderState, HTMLVisualElement, type HandoffFunction, type IProjectionNode, type InactiveStatsBuffer, type InertiaOptions, type InitialPromotionConfig, type InterpolateOptions, JSAnimation, type KeyframeGenerator, type KeyframeOptions, KeyframeResolver, LayoutAnimationBuilder, type LayoutEvents, type LayoutLifecycles, type LayoutProjectionMetrics, type LayoutProjectionStats, type LayoutUpdateData, type LayoutUpdateHandler, type LegacyAnimationControls, type MapInputRange, type Measurements, type Mixer, type MixerFactory, type MotionConfigContextProps, type MotionNodeAdvancedOptions, type MotionNodeAnimationOptions, type MotionNodeDragHandlers, type MotionNodeDraggableOptions, type MotionNodeEventOptions, type MotionNodeFocusHandlers, type MotionNodeHoverHandlers, type MotionNodeLayoutOptions, type MotionNodeOptions, type MotionNodePanHandlers, type MotionNodeTapHandlers, type MotionNodeViewportOptions, type MotionPath, type MotionStyle, MotionValue, type MotionValueAnimation, type MotionValueEventCallbacks, type MotionValueOptions, MotionValueState, type MultiTransformer, NativeAnimation, NativeAnimationExtended, type NativeAnimationOptions, type NativeAnimationOptionsExtended, NativeAnimationWrapper, type NodeGroup, NodeStack, type NumberMap, ObjectVisualElement, type OnHoverEndEvent, type OnHoverStartEvent, type OnKeyframesResolved, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PanHandler, type PanInfo, type PassiveEffect, type PathInterpolator, type PathState, type Phase, type Point2D, type PointerEventOptions, type PresenceContextProps, type PressGestureInfo, type Process, type ProgressTimeline, type ProjectionEventName, type ProjectionNodeConfig, type ProjectionNodeOptions, type PropagateOptions, type RGBA, type ReducedMotionConfig, type RepeatType, type ResolvedConstraints, type ResolvedElastic, type ResolvedKeyframes, type ResolvedValueKeyframe, type ResolvedValues$1 as ResolvedValues, type SVGAttributes, type SVGForcedAttrKeyframesDefinition, type SVGForcedAttrProperties, type SVGForcedAttrTransitions, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGRenderState, type SVGTransitions, SVGVisualElement, type ScaleCorrectionNode, type ScaleCorrector, type ScaleCorrectorDefinition, type ScaleCorrectorMap, type Schedule, type ScrapeMotionValuesFromProps, type ScrollMeasurements, type SelectorCache, type SingleTransformer, type Spring, type SpringOptions, type StaggerOptions, type StaggerOrigin, type StartAnimation, type StatsRecording, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleSubject, type StyleTransitions, type Subscriber, type TapHandlers, type TapInfo, type Target, type TargetAndTransition, type TargetResolver, type TimelineWithFallback, type TransformInputRange, type TransformOptions, type TransformOrigin, type TransformProperties, type TransformTemplate, type Transformer, type Transition, type TransitionWithValueOverrides, type Tween, type UnresolvedKeyframes, type UnresolvedValueKeyframe, type UseRenderState, type ValueAnimationOptions, type ValueAnimationOptionsWithRenderContext, type ValueAnimationTransition, type ValueAnimationWithDynamicDelay, type ValueIndexes, type ValueKeyframe, type ValueKeyframesDefinition, type ValueTransformer, type ValueTransition, type ValueType, type ValueTypeMap, type VariableKeyframesDefinition, type VariableTransitions, type Variant, type VariantLabels, type Variants, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type ViewTransitionTargetDefinition, type ViewportEventHandler, type ViewportOptions, VisualElement, type VisualElementAnimationOptions, type VisualElementEventCallbacks, type VisualElementOptions, type VisualState, type WillChange, type WithAppearProps, type WithDepth, type WithQuerySelectorAll, acceleratedValues, addAttrValue, addDomEvent, addEffect, addSVGValue, addScaleCorrector, addStyleValue, addValueToWillChange, alpha, analyseComplexValue, animateEffectSubject, animateElement, animateMotionValue, animateSingleValue, animateTarget, animateValue, animateValues, animateVariant, animateView, animateVisualElement, animationMapKey, applyAxisDelta, applyBoxDelta, applyGeneratorOptions, applyPointDelta, applyPxDefaults, applyTreeDeltas, arc, aspectRatio, attachFollow, attachSpring, attrEffect, axisDeltaEquals, axisEquals, axisEqualsRounded, boxEquals, boxEqualsRounded, buildHTMLStyles, buildProjectionTransform, buildSVGAttrs, buildSVGPath, buildTransform, calcAxisDelta, calcBoxDelta, calcChildStagger, calcGeneratorDuration, calcLength, calcRelativeAxis, calcRelativeAxisPosition, calcRelativeBox, calcRelativePosition, camelCaseAttributes, camelToDash, cancelFrame, cancelMicrotask, cancelSync, checkVariantsDidChange, cleanDirtyNodes, collectMotionValues, color, compareByDepth, complex, containsCSSVariable, convertBoundingBoxToBox, convertBoxToBoundingBox, convertOffsetToTimes, copyAxisDeltaInto, copyAxisInto, copyBoxInto, correctBorderRadius, correctBoxShadow, createAnimationState, createAxis, createAxisDelta, createBox, createDelta, createEffect, createGeneratorEasing, createProjectionNode, createRenderBatcher, cubicBezierAsString, defaultEasing, defaultOffset, defaultTransformValue, defaultValueTypes, degrees, delay, delayInSeconds, dimensionValueTypes, eachAxis, fillOffset, fillWildcards, findDimensionValueType, findEffect, findValueType, flushKeyframeResolvers, followValue, frame, frameData, frameSteps, generateLinearEasing, getAnimatableNone, getAnimationMap, getComputedStyle, getDefaultTransition, getDefaultValueType, getFeatureDefinitions, getFinalKeyframe, getMixer, getOptimisedAppearId, getOriginIndex, getValueAsType, getValueTransition, getVariableValue, getVariantContext, getViewAnimationLayerInfo, getViewAnimations, globalProjectionState, handOffElementState, has2DTranslate, hasComplexValues, hasReducedMotionListener, hasScale, hasTransform, hex, hover, hsla, hslaToRgba, inertia, initPrefersReducedMotion, interpolate, invisibleValues, isAnimationControls, isCSSVariableName, isCSSVariableToken, isControllingVariants, isDeltaZero, isDragActive, isDragging, isElementKeyboardAccessible, isElementTextInput, isForcedMotionValue, isGenerator, isHTMLElement, isKeyframesTarget, isMotionValue, isNear, isNodeOrChild, isPrimaryPointer, isSVGElement, isSVGSVGElement, isSVGTag, isTransitionDefined, isVariantLabel, isVariantNode, isWaapiSupportedEasing, isWillChangeMotionValue, keyframes, makeAnimationInstant, mapEasingToNativeEasing, mapValue, maxGeneratorDuration, measurePageBox, measureViewportBox, microtask, mix, mixArray, mixColor, mixComplex, mixImmediate, mixLinearColor, mixNumber, mixObject, mixValues, mixVisibility, motionValue, nodeGroup, number, numberValueTypes, optimizedAppearDataAttribute, optimizedAppearDataId, originProps, parseAnimateLayoutArgs, parseCSSVariable, parseValueFromTransform, percent, pixelsToPercent, positionalKeys, prefersReducedMotion, press, progressPercentage, propEffect, propagateDirtyNodes, px, readSVGValue, readStyleValue, readTransformValue, recordStats, removeAxisDelta, removeAxisTransforms, removeBoxTransforms, removeEffect, removePointDelta, renderHTML, renderSVG, resize, resolveElements, resolveMotionValue, resolveTransition, resolveVariant, resolveVariantFromProps, rgbUnit, rgba, rootProjectionNode, scale, scaleCorrectors, scalePoint, scrapeMotionValuesFromProps$1 as scrapeHTMLMotionValuesFromProps, scrapeMotionValuesFromProps as scrapeSVGMotionValuesFromProps, setDragLock, setFeatureDefinitions, setStyle, setTarget, spring, springValue, stagger, startWaapiAnimation, statsBuffer, styleEffect, styleSubjectEffect, supportedWaapiEasing, supportsBrowserAnimation, supportsFlags, supportsLinearEasing, supportsPartialKeyframes, supportsScrollTimeline, supportsViewTimeline, svgEffect, svgSubjectEffect, sync, testValueType, time, transform, transformAxis, transformBox, transformBoxPoints, transformPropOrder, transformProps, transformValue, transformValueTypes, translateAxis, updateMotionValuesFromProps, variantPriorityOrder, variantProps, vh, visualElementStore, vw };
5582
+ export { type AccelerateConfig, type AcceptedAnimations, type ActiveStatsBuffer, type AddEffectValue, type AnimateEffect, type AnimationDefinition, type AnimationGeneratorName, type AnimationGeneratorType, type AnimationList, type AnimationOptions, type AnimationOrchestrationOptions, type AnimationPlaybackControls, type AnimationPlaybackControlsWithThen, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState$1 as AnimationState, type AnimationType, type AnimationTypeState, type AnyResolvedKeyframe, type ArcOptions, AsyncMotionValueAnimation, type Batcher, type CSSStyleDeclarationWithTransform, type CSSVariableName, type CSSVariableToken, type CancelProcess, type Color, type ComplexValueInfo, type ComplexValues, type DOMKeyframesDefinition, DOMKeyframesResolver, type DOMValueAnimationOptions, DOMVisualElement, type DOMVisualElementOptions, type DecayOptions, type DelayedFunction, DocumentProjectionNode, type DragElastic, type DragHandler, type DraggableProps, type DurationSpringOptions, type DynamicOption, type Effect, type EffectKeyframes, type EffectOptions, type EffectRead, type EffectTest, type EffectTransition, type ElementOrSelector, type EventInfo, type EventOptions, Feature, type FeatureClass, FlatTree, type FollowValueOptions, type FrameData, type GeneratorFactory, type GeneratorFactoryFunction, GroupAnimation, GroupAnimationWithThen, type GroupedAnimations, type HSLA, HTMLProjectionNode, type HTMLRenderState, HTMLVisualElement, type HandoffFunction, type IProjectionNode, type InactiveStatsBuffer, type InertiaOptions, type InitialPromotionConfig, type InterpolateOptions, JSAnimation, type KeyframeGenerator, type KeyframeOptions, KeyframeResolver, LayoutAnimationBuilder, type LayoutEvents, type LayoutLifecycles, type LayoutProjectionMetrics, type LayoutProjectionStats, type LayoutUpdateData, type LayoutUpdateHandler, type LegacyAnimationControls, type MapInputRange, type Measurements, type Mixer, type MixerFactory, type MotionConfigContextProps, type MotionNodeAdvancedOptions, type MotionNodeAnimationOptions, type MotionNodeDragHandlers, type MotionNodeDraggableOptions, type MotionNodeEventOptions, type MotionNodeFocusHandlers, type MotionNodeHoverHandlers, type MotionNodeLayoutOptions, type MotionNodeOptions, type MotionNodePanHandlers, type MotionNodeTapHandlers, type MotionNodeViewportOptions, type MotionPath, type MotionStyle, MotionValue, type MotionValueAnimation, type MotionValueEventCallbacks, type MotionValueOptions, MotionValueState, type MultiTransformer, NativeAnimation, NativeAnimationExtended, type NativeAnimationOptions, type NativeAnimationOptionsExtended, NativeAnimationWrapper, type NodeGroup, NodeStack, type NumberMap, ObjectVisualElement, type OnHoverEndEvent, type OnHoverStartEvent, type OnKeyframesResolved, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PanHandler, type PanInfo, type PassiveEffect, type PathInterpolator, type PathState, type Phase, type Point2D, type PointerEventOptions, type PresenceContextProps, type PressGestureInfo, type Process, type ProgressTimeline, type ProjectionEventName, type ProjectionNodeConfig, type ProjectionNodeOptions, type PropagateOptions, type RGBA, type ReducedMotionConfig, type RepeatType, type ResolvedConstraints, type ResolvedElastic, type ResolvedKeyframes, type ResolvedValueKeyframe, type ResolvedValues$1 as ResolvedValues, type SVGAttributes, type SVGForcedAttrKeyframesDefinition, type SVGForcedAttrProperties, type SVGForcedAttrTransitions, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGRenderState, type SVGTransitions, SVGVisualElement, type ScaleCorrectionNode, type ScaleCorrector, type ScaleCorrectorDefinition, type ScaleCorrectorMap, type Schedule, type ScrapeMotionValuesFromProps, type ScrollMeasurements, type SelectorCache, type SingleTransformer, type Spring, type SpringOptions, type StaggerOptions, type StaggerOrigin, type StartAnimation, type StatsRecording, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleSubject, type StyleTransitions, type Subscriber, type TapHandlers, type TapInfo, type Target, type TargetAndTransition, type TargetResolver, type TimelineWithFallback, type TransformInputRange, type TransformOptions, type TransformOrigin, type TransformProperties, type TransformTemplate, type Transformer, type Transition, type TransitionWithValueOverrides, type Tween, type UnresolvedKeyframes, type UnresolvedValueKeyframe, type UseRenderState, type ValueAnimationOptions, type ValueAnimationOptionsWithRenderContext, type ValueAnimationTransition, type ValueAnimationWithDynamicDelay, type ValueIndexes, type ValueKeyframe, type ValueKeyframesDefinition, type ValueTransformer, type ValueTransition, type ValueType, type ValueTypeMap, type VariableKeyframesDefinition, type VariableTransitions, type Variant, type VariantLabels, type Variants, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type ViewTransitionTargetDefinition, type ViewportEventHandler, type ViewportOptions, VisualElement, type VisualElementAnimationOptions, type VisualElementEventCallbacks, type VisualElementOptions, type VisualState, type WillChange, type WithAppearProps, type WithDepth, type WithQuerySelectorAll, acceleratedValues, addAttrValue, addDomEvent, addEffect, addSVGValue, addScaleCorrector, addStyleValue, addValueToWillChange, alpha, analyseComplexValue, animateEffectSubject, animateElement, animateLayout, animateMotionValue, animateSingleValue, animateTarget, animateValue, animateValues, animateVariant, animateView, animateVisualElement, animationMapKey, applyAxisDelta, applyBoxDelta, applyGeneratorOptions, applyPointDelta, applyPxDefaults, applyTreeDeltas, arc, aspectRatio, attachFollow, attachSpring, attrEffect, axisDeltaEquals, axisEquals, axisEqualsRounded, boxEquals, boxEqualsRounded, buildHTMLStyles, buildProjectionTransform, buildSVGAttrs, buildSVGPath, buildTransform, calcAxisDelta, calcBoxDelta, calcChildStagger, calcGeneratorDuration, calcLength, calcRelativeAxis, calcRelativeAxisPosition, calcRelativeBox, calcRelativePosition, camelCaseAttributes, camelToDash, cancelFrame, cancelMicrotask, cancelSync, checkVariantsDidChange, cleanDirtyNodes, collectMotionValues, color, compareByDepth, complex, containsCSSVariable, convertBoundingBoxToBox, convertBoxToBoundingBox, convertOffsetToTimes, copyAxisDeltaInto, copyAxisInto, copyBoxInto, correctBorderRadius, correctBoxShadow, createAnimationState, createAxis, createAxisDelta, createBox, createDelta, createEffect, createGeneratorEasing, createProjectionNode, createRenderBatcher, cubicBezierAsString, defaultEasing, defaultOffset, defaultTransformValue, defaultValueTypes, degrees, delay, delayInSeconds, dimensionValueTypes, eachAxis, fillOffset, fillWildcards, findDimensionValueType, findEffect, findValueType, flushKeyframeResolvers, followValue, frame, frameData, frameSteps, generateLinearEasing, getAnimatableNone, getAnimationMap, getComputedStyle, getDefaultTransition, getDefaultValueType, getFeatureDefinitions, getFinalKeyframe, getMixer, getOptimisedAppearId, getOriginIndex, getValueAsType, getValueTransition, getVariableValue, getVariantContext, getViewAnimationLayerInfo, getViewAnimations, globalProjectionState, handOffElementState, has2DTranslate, hasComplexValues, hasReducedMotionListener, hasScale, hasTransform, hex, hover, hsla, hslaToRgba, inertia, initPrefersReducedMotion, interpolate, invisibleValues, isAnimationControls, isCSSVariableName, isCSSVariableToken, isControllingVariants, isDeltaZero, isDragActive, isDragging, isElementKeyboardAccessible, isElementTextInput, isForcedMotionValue, isGenerator, isHTMLElement, isKeyframesTarget, isMotionValue, isNear, isNodeOrChild, isPrimaryPointer, isSVGElement, isSVGSVGElement, isSVGTag, isTransitionDefined, isVariantLabel, isVariantNode, isWaapiSupportedEasing, isWillChangeMotionValue, keyframes, makeAnimationInstant, mapEasingToNativeEasing, mapValue, maxGeneratorDuration, measurePageBox, measureViewportBox, microtask, mix, mixArray, mixColor, mixComplex, mixImmediate, mixLinearColor, mixNumber, mixObject, mixValues, mixVisibility, motionValue, nodeGroup, number, numberValueTypes, optimizedAppearDataAttribute, optimizedAppearDataId, originProps, parseAnimateLayoutArgs, parseCSSVariable, parseValueFromTransform, percent, pixelsToPercent, positionalKeys, prefersReducedMotion, press, progressPercentage, propEffect, propagateDirtyNodes, px, readSVGValue, readStyleValue, readTransformValue, recordStats, removeAxisDelta, removeAxisTransforms, removeBoxTransforms, removeEffect, removePointDelta, renderHTML, renderSVG, resize, resolveElements, resolveMotionValue, resolveTransition, resolveVariant, resolveVariantFromProps, rgbUnit, rgba, rootProjectionNode, scale, scaleCorrectors, scalePoint, scrapeMotionValuesFromProps$1 as scrapeHTMLMotionValuesFromProps, scrapeMotionValuesFromProps as scrapeSVGMotionValuesFromProps, setDragLock, setFeatureDefinitions, setStyle, setTarget, spring, springValue, stagger, startWaapiAnimation, statsBuffer, styleEffect, styleSubjectEffect, supportedWaapiEasing, supportsBrowserAnimation, supportsFlags, supportsLinearEasing, supportsPartialKeyframes, supportsScrollTimeline, supportsViewTimeline, svgEffect, svgSubjectEffect, sync, testValueType, time, transform, transformAxis, transformBox, transformBoxPoints, transformPropOrder, transformProps, transformValue, transformValueTypes, translateAxis, updateMotionValuesFromProps, variantPriorityOrder, variantProps, vh, visualElementStore, vw };
@@ -805,7 +805,20 @@
805
805
  * Create a progress => progress easing function from a generator.
806
806
  */
807
807
  function createGeneratorEasing(options, scale = 100, createGenerator) {
808
- const generator = createGenerator({ ...options, keyframes: [0, scale] });
808
+ /**
809
+ * The easing is generated over 0 - scale, but velocity is in the
810
+ * value's own units, so scale it to match. Otherwise an interrupted
811
+ * spring hands off the wrong speed, or direction. Keyframes with
812
+ * units (colours, filters, mixed units) give NaN, which is falsy,
813
+ * so their velocity passes through unscaled.
814
+ */
815
+ const { keyframes: k, velocity: v } = options;
816
+ const delta = k && k[k.length - 1] - k[0];
817
+ const generator = createGenerator({
818
+ ...options,
819
+ velocity: v && delta ? (v * scale) / delta : v,
820
+ keyframes: [0, scale],
821
+ });
809
822
  const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
810
823
  return {
811
824
  type: "keyframes",
@@ -1489,6 +1502,19 @@
1489
1502
  }
1490
1503
  }
1491
1504
 
1505
+ /**
1506
+ * If an animation's keyframes resolve, or its first frame renders, more than
1507
+ * this long after its start time, it starts from then instead. While we prefer
1508
+ * to "start" an animation as soon as it's triggered, this avoids a visual jump
1509
+ * into it after main thread work.
1510
+ *
1511
+ * Manual timing steps frames by however long it likes, so never lags.
1512
+ */
1513
+ const MAX_START_DELAY = 40;
1514
+ const resolveStartTime = (startTime, now) => now - startTime > MAX_START_DELAY && !motionUtils.MotionGlobalConfig.useManualTiming
1515
+ ? now
1516
+ : startTime;
1517
+
1492
1518
  function baseRecord(kind, animation) {
1493
1519
  return {
1494
1520
  kind,
@@ -1684,6 +1710,10 @@
1684
1710
  if (this.startTime === null)
1685
1711
  return generator.next(0);
1686
1712
  const { delay = 0, keyframes, repeat, repeatType, repeatDelay, type, onUpdate, finalKeyframe, } = this.options;
1713
+ if (this.startTime === this.pendingStartTime) {
1714
+ this.startTime = resolveStartTime(this.startTime, timestamp);
1715
+ }
1716
+ this.pendingStartTime = undefined;
1687
1717
  /**
1688
1718
  * requestAnimationFrame timestamps can come through as lower than
1689
1719
  * the startTime as set by performance.now(). Here we prevent this,
@@ -1868,10 +1898,10 @@
1868
1898
  this.startTime = now;
1869
1899
  }
1870
1900
  else if (this.holdTime !== null) {
1871
- this.startTime = now - this.holdTime;
1901
+ this.startTime = now - this.holdTime / (this.playbackSpeed || 1);
1872
1902
  }
1873
1903
  else if (!this.startTime) {
1874
- this.startTime = startTime ?? now;
1904
+ this.startTime = startTime ?? (this.pendingStartTime = now);
1875
1905
  }
1876
1906
  if (this.state === "finished" && this.speed < 0) {
1877
1907
  this.startTime += this.calculatedDuration;
@@ -2991,15 +3021,6 @@
2991
3021
  type !== "inertia");
2992
3022
  }
2993
3023
 
2994
- /**
2995
- * Maximum time allowed between an animation being created and it being
2996
- * resolved for us to use the latter as the start time.
2997
- *
2998
- * This is to ensure that while we prefer to "start" an animation as soon
2999
- * as it's triggered, we also want to avoid a visual jump if there's a big delay
3000
- * between these two moments.
3001
- */
3002
- const MAX_RESOLVE_DELAY = 40;
3003
3024
  class AsyncMotionValueAnimation extends WithPromise {
3004
3025
  constructor(options) {
3005
3026
  super();
@@ -3048,31 +3069,7 @@
3048
3069
  makeAnimationInstant(options);
3049
3070
  options.repeat = 0;
3050
3071
  }
3051
- /**
3052
- * Resolve startTime for the animation.
3053
- *
3054
- * This method uses the createdAt and resolvedAt to calculate the
3055
- * animation startTime. *Ideally*, we would use the createdAt time as t=0
3056
- * as the following frame would then be the first frame of the animation in
3057
- * progress, which would feel snappier.
3058
- *
3059
- * However, if there's a delay (main thread work) between the creation of
3060
- * the animation and the first committed frame, we prefer to use resolvedAt
3061
- * to avoid a sudden jump into the animation.
3062
- */
3063
- const startTime = sync
3064
- ? !this.resolvedAt
3065
- ? this.createdAt
3066
- : this.resolvedAt - this.createdAt > MAX_RESOLVE_DELAY
3067
- ? this.resolvedAt
3068
- : this.createdAt
3069
- : undefined;
3070
3072
  const { onComplete } = options;
3071
- /**
3072
- * A startTime passed in options (an optimised appear handoff syncing
3073
- * to its WAAPI animation) takes precedence over the derived one.
3074
- */
3075
- options.startTime ?? (options.startTime = startTime);
3076
3073
  options.finalKeyframe = finalKeyframe;
3077
3074
  options.keyframes = keyframes;
3078
3075
  /**
@@ -3093,6 +3090,24 @@
3093
3090
  * values may not be valid CSS and would trigger browser warnings.
3094
3091
  */
3095
3092
  const useWaapi = canAnimateValue && !isHandoff && supportsBrowserAnimation(options);
3093
+ /**
3094
+ * Resolve startTime for the animation. A startTime passed in options
3095
+ * (an optimised appear handoff syncing to its WAAPI animation) takes
3096
+ * precedence.
3097
+ *
3098
+ * *Ideally*, we would use the createdAt time as t=0 as the following
3099
+ * frame would then be the first frame of the animation in progress,
3100
+ * which would feel snappier. If keyframes resolved on a later frame,
3101
+ * and long after creation, we start from then instead.
3102
+ *
3103
+ * If they resolved immediately, a JSAnimation picks its own start
3104
+ * time and resolves it the same way on its first frame, so every
3105
+ * animation started in that moment stays in sync. WAAPI has no frame
3106
+ * of ours to do that on.
3107
+ */
3108
+ if (sync && (useWaapi || this.resolvedAt !== this.createdAt)) {
3109
+ options.startTime ?? (options.startTime = resolveStartTime(this.createdAt, this.resolvedAt));
3110
+ }
3096
3111
  let animation;
3097
3112
  if (useWaapi) {
3098
3113
  /**
@@ -5192,9 +5207,16 @@
5192
5207
  attrs[keys.array] = `${length} ${spacing}`;
5193
5208
  }
5194
5209
 
5210
+ /**
5211
+ * Values rendered via style rather than as attributes. This must include
5212
+ * every value WAAPI can accelerate, as WAAPI writes its final value to
5213
+ * style, which would otherwise override later attribute writes.
5214
+ */
5195
5215
  const cssStyleProperties = [
5196
5216
  "transform",
5197
5217
  "opacity",
5218
+ "clipPath",
5219
+ "filter",
5198
5220
  "offsetDistance",
5199
5221
  "offsetPath",
5200
5222
  "offsetRotate",
@@ -6208,6 +6230,10 @@
6208
6230
  tick(timestamp) {
6209
6231
  const { options, hasNextTarget: retargeted } = this;
6210
6232
  const { delay = 0, onUpdate, onPlay } = options;
6233
+ // Retargets happen on a tick, so only the first start can lag
6234
+ if (!this.started) {
6235
+ this.startTime = resolveStartTime(this.startTime, timestamp);
6236
+ }
6211
6237
  const elapsed = Math.round(timestamp - this.startTime) - delay;
6212
6238
  const t = (this.currentTime = Math.max(0, elapsed));
6213
6239
  const state = this.generator.next(t);
@@ -8764,6 +8790,20 @@
8764
8790
  : visualElement.initialValues[key] === undefined
8765
8791
  ? visualElement.baseTarget[key]
8766
8792
  : undefined) ?? null;
8793
+ /**
8794
+ * If it stays where it is, that's now its base. Otherwise a
8795
+ * later removal (like a gesture ending) would also stay,
8796
+ * leaving the value stuck. Stop first so accelerated
8797
+ * animations sync the value they reached. In practice initial
8798
+ * only changes like this with Fast Refresh, so this is
8799
+ * dev-only (#3787).
8800
+ */
8801
+ if (fallbackAnimation[key] === null &&
8802
+ visualElement.initialValues[key] !== undefined) {
8803
+ delete visualElement.initialValues[key];
8804
+ motionValue?.stop();
8805
+ visualElement.baseTarget[key] = motionValue?.get();
8806
+ }
8767
8807
  });
8768
8808
  animations.push({ animation: fallbackAnimation });
8769
8809
  }
@@ -9635,7 +9675,7 @@
9635
9675
  visualElement &&
9636
9676
  (layoutId || layout)) {
9637
9677
  this.addEventListener("didUpdate", ({ delta, hasLayoutChanged, hasRelativeLayoutChanged, layout: newLayout, }) => {
9638
- if (this.isTreeAnimationBlocked()) {
9678
+ if (this.isAnimationBlocked) {
9639
9679
  this.target = undefined;
9640
9680
  this.relativeTarget = undefined;
9641
9681
  return;
@@ -9727,11 +9767,6 @@
9727
9767
  isUpdateBlocked() {
9728
9768
  return this.updateManuallyBlocked || this.updateBlockedByResize;
9729
9769
  }
9730
- isTreeAnimationBlocked() {
9731
- return (this.isAnimationBlocked ||
9732
- (this.parent && this.parent.isTreeAnimationBlocked()) ||
9733
- false);
9734
- }
9735
9770
  // Note: currently only running on root node
9736
9771
  startUpdate() {
9737
9772
  if (this.isUpdateBlocked())
@@ -9785,6 +9820,14 @@
9785
9820
  if (node.options.layoutRoot) {
9786
9821
  node.willUpdate(false);
9787
9822
  }
9823
+ /**
9824
+ * Measure the nearest dragged ancestor before the DOM
9825
+ * changes, so this node can follow its layout change.
9826
+ */
9827
+ if (node.isAnimationBlocked) {
9828
+ node.dragSnapshot || (node.dragSnapshot = node.measure());
9829
+ this.dragAncestor = node;
9830
+ }
9788
9831
  }
9789
9832
  const { layoutId, layout } = this.options;
9790
9833
  if (layoutId === undefined && !layout)
@@ -10792,7 +10835,11 @@
10792
10835
  }
10793
10836
  }
10794
10837
  clearSnapshot() {
10795
- this.resumeFrom = this.snapshot = undefined;
10838
+ this.resumeFrom =
10839
+ this.snapshot =
10840
+ this.dragSnapshot =
10841
+ this.dragAncestor =
10842
+ undefined;
10796
10843
  }
10797
10844
  // Only run on root
10798
10845
  resetTree() {
@@ -10802,8 +10849,13 @@
10802
10849
  }
10803
10850
  };
10804
10851
  }
10852
+ /**
10853
+ * Nodes are depth-ordered, so a dragged ancestor's layout is updated before
10854
+ * its descendants'.
10855
+ */
10805
10856
  function updateLayout(node) {
10806
10857
  node.updateLayout();
10858
+ followDraggedAncestor(node);
10807
10859
  }
10808
10860
  function notifyLayoutUpdate(node) {
10809
10861
  const snapshot = node.resumeFrom?.snapshot || node.snapshot;
@@ -10952,6 +11004,19 @@
10952
11004
  function clearIsLayoutDirty(node) {
10953
11005
  node.isLayoutDirty = false;
10954
11006
  }
11007
+ /**
11008
+ * A dragged node doesn't layout animate, so it jumps to its new layout. Shift
11009
+ * its descendants' snapshots by the same amount, so they only animate layout
11010
+ * changes relative to it, rather than lagging behind.
11011
+ */
11012
+ function followDraggedAncestor(node) {
11013
+ const { snapshot, dragAncestor } = node;
11014
+ const to = dragAncestor?.layout;
11015
+ if (!snapshot || !to || node.resumeFrom || node.isAnimationBlocked)
11016
+ return;
11017
+ const from = dragAncestor.dragSnapshot;
11018
+ eachAxis((axis) => translateAxis(snapshot.layoutBox[axis], to.layoutBox[axis].min - from.layoutBox[axis].min));
11019
+ }
10955
11020
  /**
10956
11021
  * When a node is animation-blocked (e.g. during drag) and its component
10957
11022
  * didn't re-render (memoized), willUpdate() is never called so there's
@@ -10960,7 +11025,7 @@
10960
11025
  */
10961
11026
  function ensureDraggedNodesSnapshotted(node) {
10962
11027
  if (node.isAnimationBlocked && node.layout && !node.isLayoutDirty) {
10963
- node.snapshot = node.layout;
11028
+ node.snapshot = node.dragSnapshot || node.layout;
10964
11029
  node.isLayoutDirty = true;
10965
11030
  }
10966
11031
  }
@@ -11461,6 +11526,21 @@
11461
11526
  };
11462
11527
  }
11463
11528
 
11529
+ /**
11530
+ * Animate layout changes made within `updateDom` on elements tagged
11531
+ * with `data-layout` or `data-layout-id`.
11532
+ *
11533
+ * ```
11534
+ * animateLayout(() => {
11535
+ * element.style.justifyContent = "flex-end"
11536
+ * })
11537
+ * ```
11538
+ */
11539
+ function animateLayout(scopeOrUpdateDom, updateDomOrOptions, options) {
11540
+ const { scope, updateDom, defaultOptions } = parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options);
11541
+ return new LayoutAnimationBuilder(scope, updateDom, defaultOptions);
11542
+ }
11543
+
11464
11544
  /**
11465
11545
  * @deprecated
11466
11546
  *
@@ -11512,6 +11592,7 @@
11512
11592
  exports.analyseComplexValue = analyseComplexValue;
11513
11593
  exports.animateEffectSubject = animateEffectSubject;
11514
11594
  exports.animateElement = animateElement;
11595
+ exports.animateLayout = animateLayout;
11515
11596
  exports.animateMotionValue = animateMotionValue;
11516
11597
  exports.animateSingleValue = animateSingleValue;
11517
11598
  exports.animateTarget = animateTarget;