motion-dom 14.3.0 → 14.3.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.
@@ -20,7 +20,7 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
20
20
  transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
21
21
  }
22
22
  if (latestTransform) {
23
- const { transformPerspective, rotate, pathRotation, rotateX, rotateY, skewX, skewY, } = latestTransform;
23
+ const { transformPerspective, rotate, pathRotation, rotateX, rotateY, rotateZ, skewX, skewY, } = latestTransform;
24
24
  if (transformPerspective)
25
25
  transform = `perspective(${transformPerspective}px) ${transform}`;
26
26
  if (rotate)
@@ -32,6 +32,8 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
32
32
  transform += `rotateX(${rotateX}deg) `;
33
33
  if (rotateY)
34
34
  transform += `rotateY(${rotateY}deg) `;
35
+ if (rotateZ)
36
+ transform += `rotateZ(${rotateZ}deg) `;
35
37
  if (skewX)
36
38
  transform += `skewX(${skewX}deg) `;
37
39
  if (skewY)
@@ -1 +1 @@
1
- {"version":3,"file":"transform.mjs","sources":["../../../../src/projection/styles/transform.ts"],"sourcesContent":["import type { Delta, Point } from \"motion-utils\"\nimport type { ResolvedValues } from \"../../node/types\"\n\nexport function buildProjectionTransform(\n delta: Delta,\n treeScale: Point,\n latestTransform?: ResolvedValues\n): string {\n let transform = \"\"\n\n /**\n * The translations we use to calculate are always relative to the viewport coordinate space.\n * But when we apply scales, we also scale the coordinate space of an element and its children.\n * For instance if we have a treeScale (the culmination of all parent scales) of 0.5 and we need\n * to move an element 100 pixels, we actually need to move it 200 in within that scaled space.\n */\n const xTranslate = delta.x.translate / treeScale.x\n const yTranslate = delta.y.translate / treeScale.y\n const zTranslate = latestTransform?.z || 0\n if (xTranslate || yTranslate || zTranslate) {\n transform = `translate3d(${xTranslate}px, ${yTranslate}px, ${zTranslate}px) `\n }\n\n /**\n * Apply scale correction for the tree transform.\n * This will apply scale to the screen-orientated axes.\n */\n if (treeScale.x !== 1 || treeScale.y !== 1) {\n transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `\n }\n\n if (latestTransform) {\n const {\n transformPerspective,\n rotate,\n pathRotation,\n rotateX,\n rotateY,\n skewX,\n skewY,\n } = latestTransform\n if (transformPerspective)\n transform = `perspective(${transformPerspective}px) ${transform}`\n if (rotate) transform += `rotate(${rotate}deg) `\n // Additive `rotate()` so user `rotate` isn't clobbered.\n if (pathRotation) transform += `rotate(${pathRotation}deg) `\n if (rotateX) transform += `rotateX(${rotateX}deg) `\n if (rotateY) transform += `rotateY(${rotateY}deg) `\n if (skewX) transform += `skewX(${skewX}deg) `\n if (skewY) transform += `skewY(${skewY}deg) `\n }\n\n /**\n * Apply scale to match the size of the element to the size we want it.\n * This will apply scale to the element-orientated axes.\n */\n const elementScaleX = delta.x.scale * treeScale.x\n const elementScaleY = delta.y.scale * treeScale.y\n if (elementScaleX !== 1 || elementScaleY !== 1) {\n transform += `scale(${elementScaleX}, ${elementScaleY})`\n }\n\n return transform || \"none\"\n}\n"],"names":[],"mappings":"SAGgB,wBAAwB,CACpC,KAAY,EACZ,SAAgB,EAChB,eAAgC,EAAA;IAEhC,IAAI,SAAS,GAAG,EAAE;AAElB;;;;;AAKG;IACH,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;IAClD,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;AAClD,IAAA,MAAM,UAAU,GAAG,eAAe,EAAE,CAAC,IAAI,CAAC;AAC1C,IAAA,IAAI,UAAU,IAAI,UAAU,IAAI,UAAU,EAAE;QACxC,SAAS,GAAG,eAAe,UAAU,CAAA,IAAA,EAAO,UAAU,CAAA,IAAA,EAAO,UAAU,MAAM;IACjF;AAEA;;;AAGG;AACH,IAAA,IAAI,SAAS,CAAC,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,CAAC,KAAK,CAAC,EAAE;AACxC,QAAA,SAAS,IAAI,CAAA,MAAA,EAAS,CAAC,GAAG,SAAS,CAAC,CAAC,CAAA,EAAA,EAAK,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI;IACjE;IAEA,IAAI,eAAe,EAAE;AACjB,QAAA,MAAM,EACF,oBAAoB,EACpB,MAAM,EACN,YAAY,EACZ,OAAO,EACP,OAAO,EACP,KAAK,EACL,KAAK,GACR,GAAG,eAAe;AACnB,QAAA,IAAI,oBAAoB;AACpB,YAAA,SAAS,GAAG,CAAA,YAAA,EAAe,oBAAoB,CAAA,IAAA,EAAO,SAAS,EAAE;AACrE,QAAA,IAAI,MAAM;AAAE,YAAA,SAAS,IAAI,CAAA,OAAA,EAAU,MAAM,CAAA,KAAA,CAAO;;AAEhD,QAAA,IAAI,YAAY;AAAE,YAAA,SAAS,IAAI,CAAA,OAAA,EAAU,YAAY,CAAA,KAAA,CAAO;AAC5D,QAAA,IAAI,OAAO;AAAE,YAAA,SAAS,IAAI,CAAA,QAAA,EAAW,OAAO,CAAA,KAAA,CAAO;AACnD,QAAA,IAAI,OAAO;AAAE,YAAA,SAAS,IAAI,CAAA,QAAA,EAAW,OAAO,CAAA,KAAA,CAAO;AACnD,QAAA,IAAI,KAAK;AAAE,YAAA,SAAS,IAAI,CAAA,MAAA,EAAS,KAAK,CAAA,KAAA,CAAO;AAC7C,QAAA,IAAI,KAAK;AAAE,YAAA,SAAS,IAAI,CAAA,MAAA,EAAS,KAAK,CAAA,KAAA,CAAO;IACjD;AAEA;;;AAGG;IACH,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IACjD,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IACjD,IAAI,aAAa,KAAK,CAAC,IAAI,aAAa,KAAK,CAAC,EAAE;AAC5C,QAAA,SAAS,IAAI,CAAA,MAAA,EAAS,aAAa,CAAA,EAAA,EAAK,aAAa,GAAG;IAC5D;IAEA,OAAO,SAAS,IAAI,MAAM;AAC9B;;;;"}
1
+ {"version":3,"file":"transform.mjs","sources":["../../../../src/projection/styles/transform.ts"],"sourcesContent":["import type { Delta, Point } from \"motion-utils\"\nimport type { ResolvedValues } from \"../../node/types\"\n\nexport function buildProjectionTransform(\n delta: Delta,\n treeScale: Point,\n latestTransform?: ResolvedValues\n): string {\n let transform = \"\"\n\n /**\n * The translations we use to calculate are always relative to the viewport coordinate space.\n * But when we apply scales, we also scale the coordinate space of an element and its children.\n * For instance if we have a treeScale (the culmination of all parent scales) of 0.5 and we need\n * to move an element 100 pixels, we actually need to move it 200 in within that scaled space.\n */\n const xTranslate = delta.x.translate / treeScale.x\n const yTranslate = delta.y.translate / treeScale.y\n const zTranslate = latestTransform?.z || 0\n if (xTranslate || yTranslate || zTranslate) {\n transform = `translate3d(${xTranslate}px, ${yTranslate}px, ${zTranslate}px) `\n }\n\n /**\n * Apply scale correction for the tree transform.\n * This will apply scale to the screen-orientated axes.\n */\n if (treeScale.x !== 1 || treeScale.y !== 1) {\n transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `\n }\n\n if (latestTransform) {\n const {\n transformPerspective,\n rotate,\n pathRotation,\n rotateX,\n rotateY,\n rotateZ,\n skewX,\n skewY,\n } = latestTransform\n if (transformPerspective)\n transform = `perspective(${transformPerspective}px) ${transform}`\n if (rotate) transform += `rotate(${rotate}deg) `\n // Additive `rotate()` so user `rotate` isn't clobbered.\n if (pathRotation) transform += `rotate(${pathRotation}deg) `\n if (rotateX) transform += `rotateX(${rotateX}deg) `\n if (rotateY) transform += `rotateY(${rotateY}deg) `\n if (rotateZ) transform += `rotateZ(${rotateZ}deg) `\n if (skewX) transform += `skewX(${skewX}deg) `\n if (skewY) transform += `skewY(${skewY}deg) `\n }\n\n /**\n * Apply scale to match the size of the element to the size we want it.\n * This will apply scale to the element-orientated axes.\n */\n const elementScaleX = delta.x.scale * treeScale.x\n const elementScaleY = delta.y.scale * treeScale.y\n if (elementScaleX !== 1 || elementScaleY !== 1) {\n transform += `scale(${elementScaleX}, ${elementScaleY})`\n }\n\n return transform || \"none\"\n}\n"],"names":[],"mappings":"SAGgB,wBAAwB,CACpC,KAAY,EACZ,SAAgB,EAChB,eAAgC,EAAA;IAEhC,IAAI,SAAS,GAAG,EAAE;AAElB;;;;;AAKG;IACH,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;IAClD,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;AAClD,IAAA,MAAM,UAAU,GAAG,eAAe,EAAE,CAAC,IAAI,CAAC;AAC1C,IAAA,IAAI,UAAU,IAAI,UAAU,IAAI,UAAU,EAAE;QACxC,SAAS,GAAG,eAAe,UAAU,CAAA,IAAA,EAAO,UAAU,CAAA,IAAA,EAAO,UAAU,MAAM;IACjF;AAEA;;;AAGG;AACH,IAAA,IAAI,SAAS,CAAC,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,CAAC,KAAK,CAAC,EAAE;AACxC,QAAA,SAAS,IAAI,CAAA,MAAA,EAAS,CAAC,GAAG,SAAS,CAAC,CAAC,CAAA,EAAA,EAAK,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI;IACjE;IAEA,IAAI,eAAe,EAAE;AACjB,QAAA,MAAM,EACF,oBAAoB,EACpB,MAAM,EACN,YAAY,EACZ,OAAO,EACP,OAAO,EACP,OAAO,EACP,KAAK,EACL,KAAK,GACR,GAAG,eAAe;AACnB,QAAA,IAAI,oBAAoB;AACpB,YAAA,SAAS,GAAG,CAAA,YAAA,EAAe,oBAAoB,CAAA,IAAA,EAAO,SAAS,EAAE;AACrE,QAAA,IAAI,MAAM;AAAE,YAAA,SAAS,IAAI,CAAA,OAAA,EAAU,MAAM,CAAA,KAAA,CAAO;;AAEhD,QAAA,IAAI,YAAY;AAAE,YAAA,SAAS,IAAI,CAAA,OAAA,EAAU,YAAY,CAAA,KAAA,CAAO;AAC5D,QAAA,IAAI,OAAO;AAAE,YAAA,SAAS,IAAI,CAAA,QAAA,EAAW,OAAO,CAAA,KAAA,CAAO;AACnD,QAAA,IAAI,OAAO;AAAE,YAAA,SAAS,IAAI,CAAA,QAAA,EAAW,OAAO,CAAA,KAAA,CAAO;AACnD,QAAA,IAAI,OAAO;AAAE,YAAA,SAAS,IAAI,CAAA,QAAA,EAAW,OAAO,CAAA,KAAA,CAAO;AACnD,QAAA,IAAI,KAAK;AAAE,YAAA,SAAS,IAAI,CAAA,MAAA,EAAS,KAAK,CAAA,KAAA,CAAO;AAC7C,QAAA,IAAI,KAAK;AAAE,YAAA,SAAS,IAAI,CAAA,MAAA,EAAS,KAAK,CAAA,KAAA,CAAO;IACjD;AAEA;;;AAGG;IACH,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IACjD,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IACjD,IAAI,aAAa,KAAK,CAAC,IAAI,aAAa,KAAK,CAAC,EAAE;AAC5C,QAAA,SAAS,IAAI,CAAA,MAAA,EAAS,aAAa,CAAA,EAAA,EAAK,aAAa,GAAG;IAC5D;IAEA,OAAO,SAAS,IAAI,MAAM;AAC9B;;;;"}
@@ -13,6 +13,7 @@ function hasTransform(values) {
13
13
  values.rotate ||
14
14
  values.rotateX ||
15
15
  values.rotateY ||
16
+ values.rotateZ ||
16
17
  values.skewX ||
17
18
  values.skewY);
18
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"has-transform.mjs","sources":["../../../../src/projection/utils/has-transform.ts"],"sourcesContent":["import { type AnyResolvedKeyframe } from \"../../animation/types\"\nimport { ResolvedValues } from \"../../render/types\"\n\nfunction isIdentityScale(scale: AnyResolvedKeyframe | undefined) {\n return scale === undefined || scale === 1\n}\n\nexport function hasScale({ scale, scaleX, scaleY }: ResolvedValues) {\n return (\n !isIdentityScale(scale) ||\n !isIdentityScale(scaleX) ||\n !isIdentityScale(scaleY)\n )\n}\n\nexport function hasTransform(values: ResolvedValues) {\n return (\n hasScale(values) ||\n has2DTranslate(values) ||\n values.z ||\n values.rotate ||\n values.rotateX ||\n values.rotateY ||\n values.skewX ||\n values.skewY\n )\n}\n\nexport function has2DTranslate(values: ResolvedValues) {\n return is2DTranslate(values.x) || is2DTranslate(values.y)\n}\n\nfunction is2DTranslate(value: AnyResolvedKeyframe | undefined) {\n return value && value !== \"0%\"\n}\n"],"names":[],"mappings":"AAGA,SAAS,eAAe,CAAC,KAAsC,EAAA;AAC3D,IAAA,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,CAAC;AAC7C;AAEM,SAAU,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAkB,EAAA;AAC9D,IAAA,QACI,CAAC,eAAe,CAAC,KAAK,CAAC;QACvB,CAAC,eAAe,CAAC,MAAM,CAAC;AACxB,QAAA,CAAC,eAAe,CAAC,MAAM,CAAC;AAEhC;AAEM,SAAU,YAAY,CAAC,MAAsB,EAAA;AAC/C,IAAA,QACI,QAAQ,CAAC,MAAM,CAAC;QAChB,cAAc,CAAC,MAAM,CAAC;AACtB,QAAA,MAAM,CAAC,CAAC;AACR,QAAA,MAAM,CAAC,MAAM;AACb,QAAA,MAAM,CAAC,OAAO;AACd,QAAA,MAAM,CAAC,OAAO;AACd,QAAA,MAAM,CAAC,KAAK;QACZ,MAAM,CAAC,KAAK;AAEpB;AAEM,SAAU,cAAc,CAAC,MAAsB,EAAA;AACjD,IAAA,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7D;AAEA,SAAS,aAAa,CAAC,KAAsC,EAAA;AACzD,IAAA,OAAO,KAAK,IAAI,KAAK,KAAK,IAAI;AAClC;;;;"}
1
+ {"version":3,"file":"has-transform.mjs","sources":["../../../../src/projection/utils/has-transform.ts"],"sourcesContent":["import { type AnyResolvedKeyframe } from \"../../animation/types\"\nimport { ResolvedValues } from \"../../render/types\"\n\nfunction isIdentityScale(scale: AnyResolvedKeyframe | undefined) {\n return scale === undefined || scale === 1\n}\n\nexport function hasScale({ scale, scaleX, scaleY }: ResolvedValues) {\n return (\n !isIdentityScale(scale) ||\n !isIdentityScale(scaleX) ||\n !isIdentityScale(scaleY)\n )\n}\n\nexport function hasTransform(values: ResolvedValues) {\n return (\n hasScale(values) ||\n has2DTranslate(values) ||\n values.z ||\n values.rotate ||\n values.rotateX ||\n values.rotateY ||\n values.rotateZ ||\n values.skewX ||\n values.skewY\n )\n}\n\nexport function has2DTranslate(values: ResolvedValues) {\n return is2DTranslate(values.x) || is2DTranslate(values.y)\n}\n\nfunction is2DTranslate(value: AnyResolvedKeyframe | undefined) {\n return value && value !== \"0%\"\n}\n"],"names":[],"mappings":"AAGA,SAAS,eAAe,CAAC,KAAsC,EAAA;AAC3D,IAAA,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,CAAC;AAC7C;AAEM,SAAU,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAkB,EAAA;AAC9D,IAAA,QACI,CAAC,eAAe,CAAC,KAAK,CAAC;QACvB,CAAC,eAAe,CAAC,MAAM,CAAC;AACxB,QAAA,CAAC,eAAe,CAAC,MAAM,CAAC;AAEhC;AAEM,SAAU,YAAY,CAAC,MAAsB,EAAA;AAC/C,IAAA,QACI,QAAQ,CAAC,MAAM,CAAC;QAChB,cAAc,CAAC,MAAM,CAAC;AACtB,QAAA,MAAM,CAAC,CAAC;AACR,QAAA,MAAM,CAAC,MAAM;AACb,QAAA,MAAM,CAAC,OAAO;AACd,QAAA,MAAM,CAAC,OAAO;AACd,QAAA,MAAM,CAAC,OAAO;AACd,QAAA,MAAM,CAAC,KAAK;QACZ,MAAM,CAAC,KAAK;AAEpB;AAEM,SAAU,cAAc,CAAC,MAAsB,EAAA;AACjD,IAAA,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7D;AAEA,SAAS,aAAa,CAAC,KAAsC,EAAA;AACzD,IAAA,OAAO,KAAK,IAAI,KAAK,KAAK,IAAI;AAClC;;;;"}
package/dist/index.d.ts CHANGED
@@ -1061,7 +1061,12 @@ interface MotionNodeOptions extends MotionNodeAnimationOptions, MotionNodeEventO
1061
1061
  interface PresenceContextProps {
1062
1062
  id: string;
1063
1063
  isPresent: boolean;
1064
- register: (id: string | number) => () => void;
1064
+ /**
1065
+ * Registers a child with this presence. Motion components also pass
1066
+ * their VisualElement, so `mode="popLayout"` can find the child's
1067
+ * element when the child can't be given a ref.
1068
+ */
1069
+ register: (id: string | number, node?: any) => () => void;
1065
1070
  onExitComplete?: (id: string | number) => void;
1066
1071
  initial?: false | VariantLabels;
1067
1072
  custom?: any;
@@ -2370,11 +2375,24 @@ interface PathInterpolator {
2370
2375
  }
2371
2376
  /**
2372
2377
  * Returned by a path factory such as `arc()` and passed to `transition.path`.
2373
- * Implements both the keyframe-animation hook (`animateVisualElement`) and
2374
- * the layout-projection hook (`interpolateProjection`).
2378
+ * Implements both the keyframe-animation hook (`animateValues`) and the
2379
+ * layout-projection hook (`interpolateProjection`).
2375
2380
  */
2376
2381
  interface MotionPath {
2377
- animateVisualElement(visualElement: VisualElement, target: TargetAndTransition, transition: Transition | undefined, delay: number, animations: AnimationPlaybackControlsWithThen[]): void;
2382
+ /**
2383
+ * Claim `x`/`y` from `target` (deleting them) and animate them, via
2384
+ * the motion values `getValue` returns, along the path. Called for
2385
+ * both VisualElements and elements animated by `animate()`.
2386
+ */
2387
+ animateValues?(getValue: (key: string) => MotionValue | undefined, target: {
2388
+ [key: string]: unknown;
2389
+ }, transition: Transition | undefined, delay: number, animations: AnimationPlaybackControlsWithThen[]): void;
2390
+ /**
2391
+ * @deprecated Implement `animateValues`, which also runs for elements
2392
+ * animated by `animate()`. Only called for VisualElements, and only
2393
+ * when `animateValues` isn't implemented.
2394
+ */
2395
+ animateVisualElement?(visualElement: VisualElement, target: TargetAndTransition, transition: Transition | undefined, delay: number, animations: AnimationPlaybackControlsWithThen[]): void;
2378
2396
  interpolateProjection(delta: Delta): PathInterpolator | undefined;
2379
2397
  }
2380
2398
  type DynamicOption<T> = (i: number, total: number) => T;
@@ -5145,6 +5163,10 @@ declare function createProjectionNode<I>({ attachResizeListener, defaultParent,
5145
5163
  prevTransformTemplateValue: string | undefined;
5146
5164
  preserveOpacity?: boolean | undefined;
5147
5165
  hasTreeAnimated: boolean;
5166
+ /**
5167
+ * Whether the layout animation "didUpdate" handler has been registered.
5168
+ */
5169
+ hasLayoutListener?: boolean | undefined;
5148
5170
  addEventListener(name: LayoutEvents, handler: any): VoidFunction;
5149
5171
  notifyListeners(name: LayoutEvents, ...args: any): void;
5150
5172
  hasListeners(name: LayoutEvents): boolean;
@@ -5152,6 +5174,12 @@ declare function createProjectionNode<I>({ attachResizeListener, defaultParent,
5152
5174
  * Lifecycles
5153
5175
  */
5154
5176
  mount(instance: I): void;
5177
+ /**
5178
+ * Only register the layout animation handler if this node requires
5179
+ * layout animation. This is called on mount, and again whenever options
5180
+ * change, as `layout` or `layoutId` may be enabled after mount.
5181
+ */
5182
+ addLayoutListener(): void;
5155
5183
  unmount(): void;
5156
5184
  blockUpdate(): void;
5157
5185
  unblockUpdate(): void;
@@ -5301,10 +5329,12 @@ declare const DocumentProjectionNode: {
5301
5329
  prevTransformTemplateValue: string | undefined;
5302
5330
  preserveOpacity?: boolean | undefined;
5303
5331
  hasTreeAnimated: boolean;
5332
+ hasLayoutListener?: boolean | undefined;
5304
5333
  addEventListener(name: LayoutEvents, handler: any): VoidFunction;
5305
5334
  notifyListeners(name: LayoutEvents, ...args: any): void;
5306
5335
  hasListeners(name: LayoutEvents): boolean;
5307
5336
  mount(instance: Window): void;
5337
+ addLayoutListener(): void;
5308
5338
  unmount(): void;
5309
5339
  blockUpdate(): void;
5310
5340
  unblockUpdate(): void;
@@ -5445,10 +5475,12 @@ declare const HTMLProjectionNode: {
5445
5475
  prevTransformTemplateValue: string | undefined;
5446
5476
  preserveOpacity?: boolean | undefined;
5447
5477
  hasTreeAnimated: boolean;
5478
+ hasLayoutListener?: boolean | undefined;
5448
5479
  addEventListener(name: LayoutEvents, handler: any): VoidFunction;
5449
5480
  notifyListeners(name: LayoutEvents, ...args: any): void;
5450
5481
  hasListeners(name: LayoutEvents): boolean;
5451
5482
  mount(instance: HTMLElement): void;
5483
+ addLayoutListener(): void;
5452
5484
  unmount(): void;
5453
5485
  blockUpdate(): void;
5454
5486
  unblockUpdate(): void;
@@ -3239,6 +3239,7 @@
3239
3239
  constructor(options) {
3240
3240
  const element = getOwner(options).current;
3241
3241
  const { driver = frameloopDriver } = options;
3242
+ let animation;
3242
3243
  /**
3243
3244
  * Before JSAnimation replaces the type with its generator.
3244
3245
  */
@@ -3268,11 +3269,12 @@
3268
3269
  stop: () => {
3269
3270
  js.stop();
3270
3271
  const group = getGroup(element);
3271
- group?.schedule(!group.isFinishing);
3272
+ group && !group.isFinishing && group.release(animation);
3272
3273
  },
3273
3274
  };
3274
3275
  };
3275
3276
  super(options);
3277
+ animation = this;
3276
3278
  this.canAccelerate = canAccelerate;
3277
3279
  /**
3278
3280
  * stop is bound in JSAnimation, so wrap it rather than override.
@@ -3428,8 +3430,14 @@
3428
3430
  }
3429
3431
  return super.time;
3430
3432
  }
3433
+ /**
3434
+ * A JS animation sets its motion value from a seek on its next tick.
3435
+ * This doesn't tick, so set it now, rather than leave it to be set
3436
+ * when this next stops.
3437
+ */
3431
3438
  set time(newTime) {
3432
3439
  super.time = newTime;
3440
+ this.isAccelerated() && this.sync();
3433
3441
  }
3434
3442
  /**
3435
3443
  * Scroll timelines set time every frame, so run these on the main
@@ -3457,6 +3465,7 @@
3457
3465
  let segments = [];
3458
3466
  let needsBuild = false;
3459
3467
  let isScheduled = false;
3468
+ let isEnded = false;
3460
3469
  let hasChurned = false;
3461
3470
  let lastChurn = -Infinity;
3462
3471
  const has = (key) => {
@@ -3573,8 +3582,19 @@
3573
3582
  for (const track of moving) {
3574
3583
  const values = at.map((t) => track.numberAt(t));
3575
3584
  const [first] = values;
3576
- const range = values[values.length - 1] - first;
3577
- const progress = values.map((value) => range ? (value - first) / range : value - first);
3585
+ const changes = values.map((value) => value - first);
3586
+ const end = changes[changes.length - 1];
3587
+ /**
3588
+ * A value that ends only a tiny way from where it started, as
3589
+ * a round trip does if it's built just after it starts, or
3590
+ * from a float residue, ends where it started. Dividing by
3591
+ * that tiny range would stretch the easing to values the
3592
+ * compositor can't render.
3593
+ */
3594
+ const range = changes.some((change) => Math.abs(change) * easingTolerance > Math.abs(end))
3595
+ ? 0
3596
+ : end;
3597
+ const progress = changes.map((change) => range ? change / range : change);
3578
3598
  /**
3579
3599
  * A value that doesn't change, like one still in its delay,
3580
3600
  * fits any easing. One that changes but ends where it started
@@ -3876,6 +3896,18 @@
3876
3896
  }
3877
3897
  return true;
3878
3898
  };
3899
+ /**
3900
+ * If no animations are left, write where they got to and cancel the
3901
+ * WAAPI animations. Returns whether the group ended.
3902
+ */
3903
+ const end = () => {
3904
+ if (tracks.size)
3905
+ return false;
3906
+ isEnded = true;
3907
+ transformGroups.delete(element);
3908
+ group.isJS || stop();
3909
+ return true;
3910
+ };
3879
3911
  const build = () => {
3880
3912
  const now = time.now();
3881
3913
  /**
@@ -3903,15 +3935,14 @@
3903
3935
  group.isFinishing = false;
3904
3936
  }
3905
3937
  isScheduled = false;
3938
+ if (isEnded)
3939
+ return;
3906
3940
  tracks.forEach(({ state }, track) => {
3907
3941
  if (state === "idle" || state === "finished")
3908
3942
  tracks.delete(track);
3909
3943
  });
3910
- if (!tracks.size) {
3911
- transformGroups.delete(element);
3912
- group.isJS || stop();
3944
+ if (end())
3913
3945
  return;
3914
- }
3915
3946
  for (const track of tracks) {
3916
3947
  if (!track.canAccelerate)
3917
3948
  return group.demote(true);
@@ -3943,6 +3974,8 @@
3943
3974
  isJS: false,
3944
3975
  isFinishing: false,
3945
3976
  schedule(build_, isChurn) {
3977
+ if (isEnded)
3978
+ return;
3946
3979
  needsBuild || (needsBuild = build_);
3947
3980
  hasChurned || (hasChurned = !!isChurn);
3948
3981
  /**
@@ -3957,6 +3990,21 @@
3957
3990
  : queueMicrotask(build);
3958
3991
  }
3959
3992
  },
3993
+ /**
3994
+ * End the group now, rather than when it next builds, so the
3995
+ * element's transform is the caller's again as soon as its last
3996
+ * animation is stopped.
3997
+ */
3998
+ release(track) {
3999
+ /**
4000
+ * Only drop the stopped animation. Others can be idle because
4001
+ * they're part way through play(), and are about to run.
4002
+ */
4003
+ const { state } = track;
4004
+ if (state === "idle" || state === "finished")
4005
+ tracks.delete(track);
4006
+ end() || group.schedule(true);
4007
+ },
3960
4008
  /**
3961
4009
  * An outside write. Rebuild once, but if it keeps happening, move
3962
4010
  * to the main thread.
@@ -3971,7 +4019,7 @@
3971
4019
  }
3972
4020
  },
3973
4021
  demote(canReturn) {
3974
- if (group.isJS)
4022
+ if (group.isJS || isEnded)
3975
4023
  return;
3976
4024
  /**
3977
4025
  * Unless only another animation is holding the group on the
@@ -4978,11 +5026,11 @@
4978
5026
  }
4979
5027
  return sample({ x: tx, y: ty }, { x: 0, y: 0 });
4980
5028
  },
4981
- animateVisualElement(visualElement, target, transition, delay, animations) {
5029
+ animateValues(getValue, target, transition, delay, animations) {
4982
5030
  if (!("x" in target || "y" in target))
4983
5031
  return;
4984
- const xValue = visualElement.getValue("x", visualElement.latestValues["x"] ?? 0);
4985
- const yValue = visualElement.getValue("y", visualElement.latestValues["y"] ?? 0);
5032
+ const xValue = getValue("x");
5033
+ const yValue = getValue("y");
4986
5034
  const xRaw = target.x;
4987
5035
  const yRaw = target.y;
4988
5036
  const xFrom = (Array.isArray(xRaw) && xRaw[0] != null
@@ -5005,7 +5053,7 @@
5005
5053
  // concurrent rotate animation composes and nothing accumulates
5006
5054
  // on interrupt.
5007
5055
  const pathRotationValue = interpolate(0).rotate !== undefined
5008
- ? visualElement.getValue("pathRotation", 0)
5056
+ ? getValue("pathRotation")
5009
5057
  : undefined;
5010
5058
  const pathTransition = {
5011
5059
  delay,
@@ -5215,7 +5263,9 @@
5215
5263
  const path = transition?.path;
5216
5264
  if (path) {
5217
5265
  // path mutates `target` to claim x/y; loop below skips them.
5218
- path.animateVisualElement(visualElement, target, transition, delay, animations);
5266
+ path.animateValues
5267
+ ? path.animateValues((key) => visualElement.getValue(key, visualElement.latestValues[key] ?? 0), target, transition, delay, animations)
5268
+ : path.animateVisualElement?.(visualElement, target, transition, delay, animations);
5219
5269
  }
5220
5270
  for (const key in target) {
5221
5271
  const value = visualElement.getValue(key, visualElement.latestValues[key] ?? null);
@@ -5674,8 +5724,16 @@
5674
5724
  */
5675
5725
  function animateValues(getValue, keyframes, transition = {}, element) {
5676
5726
  const animations = [];
5677
- const { velocity } = transition;
5727
+ const { velocity, path } = transition;
5678
5728
  const reduceMotion = transition.reduceMotion ?? element?.shouldReduceMotion;
5729
+ /**
5730
+ * Only elements have x/y to move along a path. path claims them by
5731
+ * deleting them, so hand it a copy.
5732
+ */
5733
+ if (path?.animateValues && element) {
5734
+ keyframes = { ...keyframes };
5735
+ path.animateValues(getValue, keyframes, transition, 0, animations);
5736
+ }
5679
5737
  for (const key in keyframes) {
5680
5738
  if (key === "transition" || key === "transitionEnd")
5681
5739
  continue;
@@ -6280,7 +6338,7 @@
6280
6338
  }
6281
6339
  }
6282
6340
  const addSVGValue = (element, state, key, value) => {
6283
- if (key.startsWith("path")) {
6341
+ if (key.startsWith("path") && !transformProps.has(key)) {
6284
6342
  return addSVGPathValue(element, state, key, value);
6285
6343
  }
6286
6344
  else if (key.startsWith("attr")) {
@@ -6381,6 +6439,7 @@
6381
6439
  values.rotate ||
6382
6440
  values.rotateX ||
6383
6441
  values.rotateY ||
6442
+ values.rotateZ ||
6384
6443
  values.skewX ||
6385
6444
  values.skewY);
6386
6445
  }
@@ -10166,7 +10225,7 @@
10166
10225
  transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
10167
10226
  }
10168
10227
  if (latestTransform) {
10169
- const { transformPerspective, rotate, pathRotation, rotateX, rotateY, skewX, skewY, } = latestTransform;
10228
+ const { transformPerspective, rotate, pathRotation, rotateX, rotateY, rotateZ, skewX, skewY, } = latestTransform;
10170
10229
  if (transformPerspective)
10171
10230
  transform = `perspective(${transformPerspective}px) ${transform}`;
10172
10231
  if (rotate)
@@ -10178,6 +10237,8 @@
10178
10237
  transform += `rotateX(${rotateX}deg) `;
10179
10238
  if (rotateY)
10180
10239
  transform += `rotateY(${rotateY}deg) `;
10240
+ if (rotateZ)
10241
+ transform += `rotateZ(${rotateZ}deg) `;
10181
10242
  if (skewX)
10182
10243
  transform += `skewX(${skewX}deg) `;
10183
10244
  if (skewY)
@@ -10196,6 +10257,15 @@
10196
10257
  }
10197
10258
 
10198
10259
  const numBorders = cornerRadiusProps.length;
10260
+ const mixedTransforms = [
10261
+ "rotate",
10262
+ "rotateX",
10263
+ "rotateY",
10264
+ "rotateZ",
10265
+ "skewX",
10266
+ "skewY",
10267
+ ];
10268
+ const numMixedTransforms = mixedTransforms.length;
10199
10269
  const isPx = (value) => typeof value === "number" || px.test(value);
10200
10270
  function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
10201
10271
  if (shouldCrossfadeOpacity) {
@@ -10230,10 +10300,14 @@
10230
10300
  }
10231
10301
  }
10232
10302
  /**
10233
- * Mix rotation
10303
+ * Mix rotation and skew. These can't be projected, so mix them every
10304
+ * frame rather than leaving them frozen at the animation-start snapshot.
10234
10305
  */
10235
- if (follow.rotate || lead.rotate) {
10236
- target.rotate = mixNumber$1(follow.rotate || 0, lead.rotate || 0, progress);
10306
+ for (let i = 0; i < numMixedTransforms; i++) {
10307
+ const key = mixedTransforms[i];
10308
+ if (follow[key] || lead[key]) {
10309
+ target[key] = mixNumber$1(follow[key] || 0, lead[key] || 0, progress);
10310
+ }
10237
10311
  }
10238
10312
  }
10239
10313
  function getRadius(values, radiusName) {
@@ -10683,82 +10757,92 @@
10683
10757
  if (layoutId) {
10684
10758
  this.root.registerSharedNode(layoutId, this);
10685
10759
  }
10686
- // Only register the handler if it requires layout animation
10687
- if (this.options.animate !== false &&
10688
- visualElement &&
10689
- (layoutId || layout)) {
10690
- this.addEventListener("didUpdate", ({ delta, hasLayoutChanged, hasRelativeLayoutChanged, layout: newLayout, }) => {
10691
- if (this.isAnimationBlocked) {
10692
- this.target = undefined;
10693
- this.relativeTarget = undefined;
10694
- return;
10760
+ this.addLayoutListener();
10761
+ }
10762
+ /**
10763
+ * Only register the layout animation handler if this node requires
10764
+ * layout animation. This is called on mount, and again whenever options
10765
+ * change, as `layout` or `layoutId` may be enabled after mount.
10766
+ */
10767
+ addLayoutListener() {
10768
+ const { layoutId, layout, visualElement, animate } = this.options;
10769
+ if (!this.instance ||
10770
+ this.hasLayoutListener ||
10771
+ animate === false ||
10772
+ !visualElement ||
10773
+ !(layoutId || layout))
10774
+ return;
10775
+ this.hasLayoutListener = true;
10776
+ this.addEventListener("didUpdate", ({ delta, hasLayoutChanged, hasRelativeLayoutChanged, layout: newLayout, }) => {
10777
+ if (this.isAnimationBlocked) {
10778
+ this.target = undefined;
10779
+ this.relativeTarget = undefined;
10780
+ return;
10781
+ }
10782
+ // TODO: Check here if an animation exists
10783
+ const layoutTransition = this.options.transition ||
10784
+ visualElement.getDefaultTransition() ||
10785
+ defaultLayoutTransition;
10786
+ const { onLayoutAnimationStart, onLayoutAnimationComplete, } = visualElement.getProps();
10787
+ /**
10788
+ * The target layout of the element might stay the same,
10789
+ * but its position relative to its parent has changed.
10790
+ */
10791
+ const hasTargetChanged = !this.targetLayout ||
10792
+ !boxEqualsRounded(this.targetLayout, newLayout);
10793
+ /*
10794
+ * Note: Disabled to fix relative animations always triggering new
10795
+ * layout animations. If this causes further issues, we can try
10796
+ * a different approach to detecting relative target changes.
10797
+ */
10798
+ // || hasRelativeLayoutChanged
10799
+ /**
10800
+ * If the layout hasn't seemed to have changed, it might be that the
10801
+ * element is visually in the same place in the document but its position
10802
+ * relative to its parent has indeed changed. So here we check for that.
10803
+ */
10804
+ const hasOnlyRelativeTargetChanged = !hasLayoutChanged && hasRelativeLayoutChanged;
10805
+ if (this.options.layoutRoot ||
10806
+ this.resumeFrom ||
10807
+ hasOnlyRelativeTargetChanged ||
10808
+ (hasLayoutChanged &&
10809
+ (hasTargetChanged || !this.currentAnimation))) {
10810
+ if (this.resumeFrom) {
10811
+ this.resumingFrom = this.resumeFrom;
10812
+ this.resumingFrom.resumingFrom = undefined;
10813
+ }
10814
+ const animationOptions = {
10815
+ ...getValueTransition(layoutTransition, "layout"),
10816
+ onPlay: onLayoutAnimationStart,
10817
+ onComplete: onLayoutAnimationComplete,
10818
+ };
10819
+ if (visualElement.shouldReduceMotion ||
10820
+ this.options.layoutRoot) {
10821
+ animationOptions.delay = 0;
10822
+ animationOptions.type = false;
10695
10823
  }
10696
- // TODO: Check here if an animation exists
10697
- const layoutTransition = this.options.transition ||
10698
- visualElement.getDefaultTransition() ||
10699
- defaultLayoutTransition;
10700
- const { onLayoutAnimationStart, onLayoutAnimationComplete, } = visualElement.getProps();
10824
+ this.startAnimation(animationOptions);
10701
10825
  /**
10702
- * The target layout of the element might stay the same,
10703
- * but its position relative to its parent has changed.
10704
- */
10705
- const hasTargetChanged = !this.targetLayout ||
10706
- !boxEqualsRounded(this.targetLayout, newLayout);
10707
- /*
10708
- * Note: Disabled to fix relative animations always triggering new
10709
- * layout animations. If this causes further issues, we can try
10710
- * a different approach to detecting relative target changes.
10826
+ * Set animation origin after starting animation to avoid layout jump
10827
+ * caused by stopping previous layout animation
10711
10828
  */
10712
- // || hasRelativeLayoutChanged
10829
+ this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged, animationOptions.path);
10830
+ }
10831
+ else {
10713
10832
  /**
10714
- * If the layout hasn't seemed to have changed, it might be that the
10715
- * element is visually in the same place in the document but its position
10716
- * relative to its parent has indeed changed. So here we check for that.
10833
+ * If the layout hasn't changed and we have an animation that hasn't started yet,
10834
+ * finish it immediately. Otherwise it will be animating from a location
10835
+ * that was probably never committed to screen and look like a jumpy box.
10717
10836
  */
10718
- const hasOnlyRelativeTargetChanged = !hasLayoutChanged && hasRelativeLayoutChanged;
10719
- if (this.options.layoutRoot ||
10720
- this.resumeFrom ||
10721
- hasOnlyRelativeTargetChanged ||
10722
- (hasLayoutChanged &&
10723
- (hasTargetChanged || !this.currentAnimation))) {
10724
- if (this.resumeFrom) {
10725
- this.resumingFrom = this.resumeFrom;
10726
- this.resumingFrom.resumingFrom = undefined;
10727
- }
10728
- const animationOptions = {
10729
- ...getValueTransition(layoutTransition, "layout"),
10730
- onPlay: onLayoutAnimationStart,
10731
- onComplete: onLayoutAnimationComplete,
10732
- };
10733
- if (visualElement.shouldReduceMotion ||
10734
- this.options.layoutRoot) {
10735
- animationOptions.delay = 0;
10736
- animationOptions.type = false;
10737
- }
10738
- this.startAnimation(animationOptions);
10739
- /**
10740
- * Set animation origin after starting animation to avoid layout jump
10741
- * caused by stopping previous layout animation
10742
- */
10743
- this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged, animationOptions
10744
- .path);
10837
+ if (!hasLayoutChanged) {
10838
+ finishAnimation(this);
10745
10839
  }
10746
- else {
10747
- /**
10748
- * If the layout hasn't changed and we have an animation that hasn't started yet,
10749
- * finish it immediately. Otherwise it will be animating from a location
10750
- * that was probably never committed to screen and look like a jumpy box.
10751
- */
10752
- if (!hasLayoutChanged) {
10753
- finishAnimation(this);
10754
- }
10755
- if (this.isLead() && this.options.onExitComplete) {
10756
- this.options.onExitComplete();
10757
- }
10840
+ if (this.isLead() && this.options.onExitComplete) {
10841
+ this.options.onExitComplete();
10758
10842
  }
10759
- this.targetLayout = newLayout;
10760
- });
10761
- }
10843
+ }
10844
+ this.targetLayout = newLayout;
10845
+ });
10762
10846
  }
10763
10847
  unmount() {
10764
10848
  this.options.layoutId && this.willUpdate();
@@ -10768,6 +10852,7 @@
10768
10852
  this.parent && this.parent.children.delete(this);
10769
10853
  this.instance = undefined;
10770
10854
  this.eventHandlers.clear();
10855
+ this.hasLayoutListener = false;
10771
10856
  cancelFrame(this.updateProjection);
10772
10857
  }
10773
10858
  // only on the root
@@ -10938,7 +11023,16 @@
10938
11023
  }
10939
11024
  clearAllSnapshots() {
10940
11025
  this.nodes.forEach(clearSnapshot);
10941
- this.sharedNodes.forEach(removeLeadSnapshots);
11026
+ /**
11027
+ * A stack's last member can unmount while a replacement with the
11028
+ * same layoutId mounts in the same commit, so the stack (and its
11029
+ * lead) must outlive the unmount for the replacement to resume
11030
+ * from it. By now that handoff has happened, so stacks that are
11031
+ * still empty only retain unmounted nodes and can be released.
11032
+ */
11033
+ this.sharedNodes.forEach((stack, layoutId) => stack.members.length
11034
+ ? stack.removeLeadSnapshot()
11035
+ : this.sharedNodes.delete(layoutId));
10942
11036
  }
10943
11037
  scheduleUpdateProjection() {
10944
11038
  if (!this.projectionUpdateScheduled) {
@@ -11162,6 +11256,7 @@
11162
11256
  ...options,
11163
11257
  crossfade: options.crossfade !== undefined ? options.crossfade : true,
11164
11258
  };
11259
+ this.addLayoutListener();
11165
11260
  }
11166
11261
  clearMeasurements() {
11167
11262
  this.scroll = undefined;
@@ -12091,9 +12186,6 @@
12091
12186
  function resetSkewAndRotation(node) {
12092
12187
  node.resetSkewAndRotation();
12093
12188
  }
12094
- function removeLeadSnapshots(stack) {
12095
- stack.removeLeadSnapshot();
12096
- }
12097
12189
  function mixAxisDeltaLinear(output, delta, p) {
12098
12190
  output.translate = mixNumber$1(delta.translate, 0, p);
12099
12191
  output.scale = mixNumber$1(delta.scale, 1, p);