motion-dom 12.41.0 → 12.42.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.
@@ -11,10 +11,12 @@ class ViewTransitionBuilder {
11
11
  */
12
12
  this.resolveDefs = new Set();
13
13
  /**
14
- * Subjects opted out of the default crop (clip + object-fit: cover +
15
- * animated corner radii) via `.crop(false)`.
14
+ * Per-subject crop override: `true` forces the crop (clip + object-fit:
15
+ * cover + animated corner radii) on, `false` forces it off. A subject with
16
+ * no entry uses the default - crop only a genuine morph (a layer present in
17
+ * both snapshots), so a fade-only enter/exit isn't clipped to nothing.
16
18
  */
17
- this.noCrop = new Set();
19
+ this.cropOverride = new Map();
18
20
  /**
19
21
  * Subjects paired with a different new-snapshot target (the second `.add()`
20
22
  * argument), so two distinct elements share one name and morph into each
@@ -27,6 +29,14 @@ class ViewTransitionBuilder {
27
29
  * the opaque generated name.
28
30
  */
29
31
  this.classNames = new Map();
32
+ /**
33
+ * Subjects opted out of automatic group nesting via `.group(false)`. Their
34
+ * layer stays a flat top-level group (`view-transition-group: none`) instead
35
+ * of nesting under its DOM-ancestor layer - so it animates independently and
36
+ * escapes an ancestor's clip/transform (e.g. an element that lifts out of a
37
+ * card and flies across, which nesting would clip to the card).
38
+ */
39
+ this.flatGroups = new Set();
30
40
  this.notifyReady = noop;
31
41
  this.notifyReject = noop;
32
42
  this.readyPromise = new Promise((resolve, reject) => {
@@ -64,14 +74,37 @@ class ViewTransitionBuilder {
64
74
  return this;
65
75
  }
66
76
  /**
67
- * Morphs are clipped + `object-fit: cover` (and their corners animate)
68
- * by default. Call `.crop(false)` to opt this subject out and fall back
69
- * to the browser default (which overflows on aspect-ratio change).
77
+ * Control this subject's crop (clip + `object-fit: cover` + animated
78
+ * corners). By default a subject auto-crops only when it actually morphs -
79
+ * present in both snapshots (a survivor, or an `.add(a, b)` pair). A
80
+ * fade-only enter/exit has no second box to crop against, so it's left to
81
+ * the browser default; in particular the `overflow: clip` a crop adds would
82
+ * otherwise clip a mis-sized enter/exit layer to nothing.
83
+ *
84
+ * `.crop(false)` forces the crop off (e.g. a text morph, where
85
+ * `object-fit: cover` clips glyphs as the box grows); `.crop(true)` forces
86
+ * it on for a non-morph the default wouldn't otherwise crop.
70
87
  */
71
88
  crop(enabled = true) {
89
+ this.cropOverride.set(this.currentSubject, enabled);
90
+ return this;
91
+ }
92
+ /**
93
+ * By default a subject's layer nests under its nearest DOM-ancestor layer
94
+ * (`view-transition-group: contain`), so the ancestor's clip/transform/opacity
95
+ * apply to it through the transition - mirroring how the DOM actually paints,
96
+ * and letting a wrapper crop its child for the whole morph rather than only
97
+ * once the live DOM takes back over. (Needs a browser that supports nested
98
+ * view-transition groups; elsewhere it degrades to the flat default.)
99
+ *
100
+ * Call `.group(false)` to opt out: the layer stays flat and top-level, so it
101
+ * animates independently and escapes an ancestor's clip - e.g. an element
102
+ * that should lift out of a card and fly across, which nesting would clip.
103
+ */
104
+ group(enabled = true) {
72
105
  enabled
73
- ? this.noCrop.delete(this.currentSubject)
74
- : this.noCrop.add(this.currentSubject);
106
+ ? this.flatGroups.delete(this.currentSubject)
107
+ : this.flatGroups.add(this.currentSubject);
75
108
  return this;
76
109
  }
77
110
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/view/index.ts"],"sourcesContent":["import { noop } from \"motion-utils\"\nimport type { GroupAnimation } from \"../animation/GroupAnimation\"\nimport { AnimationOptions, DOMKeyframesDefinition } from \"../animation/types\"\nimport { addToQueue } from \"./queue\"\nimport {\n ViewTransitionOptions,\n ViewTransitionTarget,\n ViewTransitionTargetDefinition,\n} from \"./types\"\nimport \"./types.global\"\n\n// Re-export the public view-transition types so they flow out through\n// motion-dom -> framer-motion -> motion alongside `animateView`.\nexport type * from \"./types\"\n\nexport class ViewTransitionBuilder {\n private currentSubject: ViewTransitionTargetDefinition = \"root\"\n\n targets = new Map<ViewTransitionTargetDefinition, ViewTransitionTarget>()\n\n /**\n * Definitions that must be resolved to elements (and assigned a\n * `view-transition-name`) rather than treated as pre-named layers.\n */\n resolveDefs = new Set<ViewTransitionTargetDefinition>()\n\n /**\n * Subjects opted out of the default crop (clip + object-fit: cover +\n * animated corner radii) via `.crop(false)`.\n */\n noCrop = new Set<ViewTransitionTargetDefinition>()\n\n /**\n * Subjects paired with a different new-snapshot target (the second `.add()`\n * argument), so two distinct elements share one name and morph into each\n * other - a shared-element transition.\n */\n pairs = new Map<\n ViewTransitionTargetDefinition,\n ViewTransitionTargetDefinition\n >()\n\n /**\n * A `view-transition-class` to apply to each subject's resolved elements,\n * so authors can target the generated layers from CSS by class rather than\n * the opaque generated name.\n */\n classNames = new Map<ViewTransitionTargetDefinition, string>()\n\n update: () => void | Promise<void>\n\n options: ViewTransitionOptions\n\n notifyReady: (value: GroupAnimation) => void = noop\n\n notifyReject: (error: unknown) => void = noop\n\n private readyPromise = new Promise<GroupAnimation>((resolve, reject) => {\n this.notifyReady = resolve\n this.notifyReject = reject\n })\n\n constructor(\n update: () => void | Promise<void>,\n options: ViewTransitionOptions = {}\n ) {\n this.update = update\n this.options = {\n interrupt: \"wait\",\n ...options,\n }\n // Avoid an unhandled rejection when a failed transition has no\n // `.then(_, reject)` handler attached (e.g. fire-and-forget).\n this.readyPromise.catch(noop)\n addToQueue(this)\n }\n\n /**\n * Target elements resolved from a selector or Element, each assigned a\n * `view-transition-name` automatically.\n *\n * Passing a second target pairs them: the first is resolved in the old\n * snapshot and the second in the new, sharing one name so two *different*\n * elements morph into each other (e.g. `.add(card, \".modal\")`). Symmetric -\n * pass them the other way round to morph back.\n */\n add(\n subject: ViewTransitionTargetDefinition,\n newSubject?: ViewTransitionTargetDefinition\n ) {\n this.currentSubject = subject\n this.resolveDefs.add(subject)\n if (newSubject !== undefined) this.pairs.set(subject, newSubject)\n // Register the subject so it participates (and gets an automatic\n // layout/morph animation) even without an explicit enter/exit/layout.\n if (!this.targets.has(subject)) this.targets.set(subject, {})\n\n return this\n }\n\n /**\n * Morphs are clipped + `object-fit: cover` (and their corners animate)\n * by default. Call `.crop(false)` to opt this subject out and fall back\n * to the browser default (which overflows on aspect-ratio change).\n */\n crop(enabled = true) {\n enabled\n ? this.noCrop.delete(this.currentSubject)\n : this.noCrop.add(this.currentSubject)\n\n return this\n }\n\n /**\n * Tag this subject's generated layers with a `view-transition-class`, so\n * they can be targeted from CSS - `::view-transition-group(.name)`,\n * `::view-transition-old/new(.name)`, `::view-transition-image-pair(.name)`\n * - without the opaque generated `view-transition-name`. Because `.add()`\n * can match many elements, a shared class targets them all at once (and,\n * for a pair, both ends). The escape hatch for z-index / custom keyframes\n * on a morph layer.\n */\n class(name: string) {\n this.classNames.set(this.currentSubject, name)\n\n return this\n }\n\n /**\n * Set the transition for this subject's morph. The morph is enabled\n * automatically by `.add()`; this just customises its timing (duration,\n * easing, a `delay`/`stagger`, …). On the implicit `root` subject it also\n * opts the page into the transition (the root crossfade).\n */\n layout(options: AnimationOptions = {}) {\n this.updateTarget(\"layout\", {}, options)\n\n return this\n }\n\n enter(keyframes: DOMKeyframesDefinition, options?: AnimationOptions) {\n this.updateTarget(\"enter\", keyframes, options)\n\n return this\n }\n\n exit(keyframes: DOMKeyframesDefinition, options?: AnimationOptions) {\n this.updateTarget(\"exit\", keyframes, options)\n\n return this\n }\n\n /**\n * Animate the new view directly, whether the element is appearing or\n * persisting (unlike `.enter()`, which only fires for a pure newcomer).\n * Pair with `.old()` for a crossfade or slide-through.\n */\n new(keyframes: DOMKeyframesDefinition, options?: AnimationOptions) {\n this.updateTarget(\"new\", keyframes, options)\n\n return this\n }\n\n /**\n * Animate the old view directly, whether the element is leaving or\n * persisting (unlike `.exit()`, which only fires for a pure leaver).\n */\n old(keyframes: DOMKeyframesDefinition, options?: AnimationOptions) {\n this.updateTarget(\"old\", keyframes, options)\n\n return this\n }\n\n updateTarget(\n target: \"enter\" | \"exit\" | \"layout\" | \"new\" | \"old\",\n keyframes: DOMKeyframesDefinition,\n options: AnimationOptions = {}\n ) {\n const { currentSubject, targets } = this\n\n if (!targets.has(currentSubject)) {\n targets.set(currentSubject, {})\n }\n\n const targetData = targets.get(currentSubject)!\n\n targetData[target] = { keyframes, options }\n }\n\n then(resolve: () => void, reject?: () => void) {\n return this.readyPromise.then(resolve, reject)\n }\n}\n\nexport function animateView(\n update: () => void | Promise<void>,\n options: ViewTransitionOptions = {}\n) {\n return new ViewTransitionBuilder(update, options)\n}\n"],"names":[],"mappings":";;;MAea,qBAAqB,CAAA;IA+C9B,WAAA,CACI,MAAkC,EAClC,OAAA,GAAiC,EAAE,EAAA;QAhD/B,IAAA,CAAA,cAAc,GAAmC,MAAM;AAE/D,QAAA,IAAA,CAAA,OAAO,GAAG,IAAI,GAAG,EAAwD;AAEzE;;;AAGG;AACH,QAAA,IAAA,CAAA,WAAW,GAAG,IAAI,GAAG,EAAkC;AAEvD;;;AAGG;AACH,QAAA,IAAA,CAAA,MAAM,GAAG,IAAI,GAAG,EAAkC;AAElD;;;;AAIG;AACH,QAAA,IAAA,CAAA,KAAK,GAAG,IAAI,GAAG,EAGZ;AAEH;;;;AAIG;AACH,QAAA,IAAA,CAAA,UAAU,GAAG,IAAI,GAAG,EAA0C;QAM9D,IAAA,CAAA,WAAW,GAAoC,IAAI;QAEnD,IAAA,CAAA,YAAY,GAA6B,IAAI;QAErC,IAAA,CAAA,YAAY,GAAG,IAAI,OAAO,CAAiB,CAAC,OAAO,EAAE,MAAM,KAAI;AACnE,YAAA,IAAI,CAAC,WAAW,GAAG,OAAO;AAC1B,YAAA,IAAI,CAAC,YAAY,GAAG,MAAM;AAC9B,QAAA,CAAC,CAAC;AAME,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;QACpB,IAAI,CAAC,OAAO,GAAG;AACX,YAAA,SAAS,EAAE,MAAM;AACjB,YAAA,GAAG,OAAO;SACb;;;AAGD,QAAA,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC;QAC7B,UAAU,CAAC,IAAI,CAAC;IACpB;AAEA;;;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f;AAEA;;;;AAIG;IACH,GAAG,CAAC,SAAiC,EAAE,OAA0B,EAAA;QAC7D,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC;AAE5C,QAAA,OAAO,IAAI;IACf;AAEA;;;AAGG;IACH,GAAG,CAAC,SAAiC,EAAE,OAA0B,EAAA;QAC7D,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC;AAE5C,QAAA,OAAO,IAAI;IACf;AAEA,IAAA,YAAY,CACR,MAAmD,EACnD,SAAiC,EACjC,UAA4B,EAAE,EAAA;AAE9B,QAAA,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;QAExC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE;AAC9B,YAAA,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,EAAE,CAAC;QACnC;QAEA,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAE;QAE/C,UAAU,CAAC,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE;IAC/C;IAEA,IAAI,CAAC,OAAmB,EAAE,MAAmB,EAAA;QACzC,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;IAClD;AACH;SAEe,WAAW,CACvB,MAAkC,EAClC,UAAiC,EAAE,EAAA;AAEnC,IAAA,OAAO,IAAI,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC;AACrD;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/view/index.ts"],"sourcesContent":["import { noop } from \"motion-utils\"\nimport type { GroupAnimation } from \"../animation/GroupAnimation\"\nimport { AnimationOptions, DOMKeyframesDefinition } from \"../animation/types\"\nimport { addToQueue } from \"./queue\"\nimport {\n ViewTransitionOptions,\n ViewTransitionTarget,\n ViewTransitionTargetDefinition,\n} from \"./types\"\nimport \"./types.global\"\n\n// Re-export the public view-transition types so they flow out through\n// motion-dom -> framer-motion -> motion alongside `animateView`.\nexport type * from \"./types\"\n\nexport class ViewTransitionBuilder {\n private currentSubject: ViewTransitionTargetDefinition = \"root\"\n\n targets = new Map<ViewTransitionTargetDefinition, ViewTransitionTarget>()\n\n /**\n * Definitions that must be resolved to elements (and assigned a\n * `view-transition-name`) rather than treated as pre-named layers.\n */\n resolveDefs = new Set<ViewTransitionTargetDefinition>()\n\n /**\n * Per-subject crop override: `true` forces the crop (clip + object-fit:\n * cover + animated corner radii) on, `false` forces it off. A subject with\n * no entry uses the default - crop only a genuine morph (a layer present in\n * both snapshots), so a fade-only enter/exit isn't clipped to nothing.\n */\n cropOverride = new Map<ViewTransitionTargetDefinition, boolean>()\n\n /**\n * Subjects paired with a different new-snapshot target (the second `.add()`\n * argument), so two distinct elements share one name and morph into each\n * other - a shared-element transition.\n */\n pairs = new Map<\n ViewTransitionTargetDefinition,\n ViewTransitionTargetDefinition\n >()\n\n /**\n * A `view-transition-class` to apply to each subject's resolved elements,\n * so authors can target the generated layers from CSS by class rather than\n * the opaque generated name.\n */\n classNames = new Map<ViewTransitionTargetDefinition, string>()\n\n /**\n * Subjects opted out of automatic group nesting via `.group(false)`. Their\n * layer stays a flat top-level group (`view-transition-group: none`) instead\n * of nesting under its DOM-ancestor layer - so it animates independently and\n * escapes an ancestor's clip/transform (e.g. an element that lifts out of a\n * card and flies across, which nesting would clip to the card).\n */\n flatGroups = new Set<ViewTransitionTargetDefinition>()\n\n update: () => void | Promise<void>\n\n options: ViewTransitionOptions\n\n notifyReady: (value: GroupAnimation) => void = noop\n\n notifyReject: (error: unknown) => void = noop\n\n private readyPromise = new Promise<GroupAnimation>((resolve, reject) => {\n this.notifyReady = resolve\n this.notifyReject = reject\n })\n\n constructor(\n update: () => void | Promise<void>,\n options: ViewTransitionOptions = {}\n ) {\n this.update = update\n this.options = {\n interrupt: \"wait\",\n ...options,\n }\n // Avoid an unhandled rejection when a failed transition has no\n // `.then(_, reject)` handler attached (e.g. fire-and-forget).\n this.readyPromise.catch(noop)\n addToQueue(this)\n }\n\n /**\n * Target elements resolved from a selector or Element, each assigned a\n * `view-transition-name` automatically.\n *\n * Passing a second target pairs them: the first is resolved in the old\n * snapshot and the second in the new, sharing one name so two *different*\n * elements morph into each other (e.g. `.add(card, \".modal\")`). Symmetric -\n * pass them the other way round to morph back.\n */\n add(\n subject: ViewTransitionTargetDefinition,\n newSubject?: ViewTransitionTargetDefinition\n ) {\n this.currentSubject = subject\n this.resolveDefs.add(subject)\n if (newSubject !== undefined) this.pairs.set(subject, newSubject)\n // Register the subject so it participates (and gets an automatic\n // layout/morph animation) even without an explicit enter/exit/layout.\n if (!this.targets.has(subject)) this.targets.set(subject, {})\n\n return this\n }\n\n /**\n * Control this subject's crop (clip + `object-fit: cover` + animated\n * corners). By default a subject auto-crops only when it actually morphs -\n * present in both snapshots (a survivor, or an `.add(a, b)` pair). A\n * fade-only enter/exit has no second box to crop against, so it's left to\n * the browser default; in particular the `overflow: clip` a crop adds would\n * otherwise clip a mis-sized enter/exit layer to nothing.\n *\n * `.crop(false)` forces the crop off (e.g. a text morph, where\n * `object-fit: cover` clips glyphs as the box grows); `.crop(true)` forces\n * it on for a non-morph the default wouldn't otherwise crop.\n */\n crop(enabled = true) {\n this.cropOverride.set(this.currentSubject, enabled)\n\n return this\n }\n\n /**\n * By default a subject's layer nests under its nearest DOM-ancestor layer\n * (`view-transition-group: contain`), so the ancestor's clip/transform/opacity\n * apply to it through the transition - mirroring how the DOM actually paints,\n * and letting a wrapper crop its child for the whole morph rather than only\n * once the live DOM takes back over. (Needs a browser that supports nested\n * view-transition groups; elsewhere it degrades to the flat default.)\n *\n * Call `.group(false)` to opt out: the layer stays flat and top-level, so it\n * animates independently and escapes an ancestor's clip - e.g. an element\n * that should lift out of a card and fly across, which nesting would clip.\n */\n group(enabled = true) {\n enabled\n ? this.flatGroups.delete(this.currentSubject)\n : this.flatGroups.add(this.currentSubject)\n\n return this\n }\n\n /**\n * Tag this subject's generated layers with a `view-transition-class`, so\n * they can be targeted from CSS - `::view-transition-group(.name)`,\n * `::view-transition-old/new(.name)`, `::view-transition-image-pair(.name)`\n * - without the opaque generated `view-transition-name`. Because `.add()`\n * can match many elements, a shared class targets them all at once (and,\n * for a pair, both ends). The escape hatch for z-index / custom keyframes\n * on a morph layer.\n */\n class(name: string) {\n this.classNames.set(this.currentSubject, name)\n\n return this\n }\n\n /**\n * Set the transition for this subject's morph. The morph is enabled\n * automatically by `.add()`; this just customises its timing (duration,\n * easing, a `delay`/`stagger`, …). On the implicit `root` subject it also\n * opts the page into the transition (the root crossfade).\n */\n layout(options: AnimationOptions = {}) {\n this.updateTarget(\"layout\", {}, options)\n\n return this\n }\n\n enter(keyframes: DOMKeyframesDefinition, options?: AnimationOptions) {\n this.updateTarget(\"enter\", keyframes, options)\n\n return this\n }\n\n exit(keyframes: DOMKeyframesDefinition, options?: AnimationOptions) {\n this.updateTarget(\"exit\", keyframes, options)\n\n return this\n }\n\n /**\n * Animate the new view directly, whether the element is appearing or\n * persisting (unlike `.enter()`, which only fires for a pure newcomer).\n * Pair with `.old()` for a crossfade or slide-through.\n */\n new(keyframes: DOMKeyframesDefinition, options?: AnimationOptions) {\n this.updateTarget(\"new\", keyframes, options)\n\n return this\n }\n\n /**\n * Animate the old view directly, whether the element is leaving or\n * persisting (unlike `.exit()`, which only fires for a pure leaver).\n */\n old(keyframes: DOMKeyframesDefinition, options?: AnimationOptions) {\n this.updateTarget(\"old\", keyframes, options)\n\n return this\n }\n\n updateTarget(\n target: \"enter\" | \"exit\" | \"layout\" | \"new\" | \"old\",\n keyframes: DOMKeyframesDefinition,\n options: AnimationOptions = {}\n ) {\n const { currentSubject, targets } = this\n\n if (!targets.has(currentSubject)) {\n targets.set(currentSubject, {})\n }\n\n const targetData = targets.get(currentSubject)!\n\n targetData[target] = { keyframes, options }\n }\n\n then(resolve: () => void, reject?: () => void) {\n return this.readyPromise.then(resolve, reject)\n }\n}\n\nexport function animateView(\n update: () => void | Promise<void>,\n options: ViewTransitionOptions = {}\n) {\n return new ViewTransitionBuilder(update, options)\n}\n"],"names":[],"mappings":";;;MAea,qBAAqB,CAAA;IA0D9B,WAAA,CACI,MAAkC,EAClC,OAAA,GAAiC,EAAE,EAAA;QA3D/B,IAAA,CAAA,cAAc,GAAmC,MAAM;AAE/D,QAAA,IAAA,CAAA,OAAO,GAAG,IAAI,GAAG,EAAwD;AAEzE;;;AAGG;AACH,QAAA,IAAA,CAAA,WAAW,GAAG,IAAI,GAAG,EAAkC;AAEvD;;;;;AAKG;AACH,QAAA,IAAA,CAAA,YAAY,GAAG,IAAI,GAAG,EAA2C;AAEjE;;;;AAIG;AACH,QAAA,IAAA,CAAA,KAAK,GAAG,IAAI,GAAG,EAGZ;AAEH;;;;AAIG;AACH,QAAA,IAAA,CAAA,UAAU,GAAG,IAAI,GAAG,EAA0C;AAE9D;;;;;;AAMG;AACH,QAAA,IAAA,CAAA,UAAU,GAAG,IAAI,GAAG,EAAkC;QAMtD,IAAA,CAAA,WAAW,GAAoC,IAAI;QAEnD,IAAA,CAAA,YAAY,GAA6B,IAAI;QAErC,IAAA,CAAA,YAAY,GAAG,IAAI,OAAO,CAAiB,CAAC,OAAO,EAAE,MAAM,KAAI;AACnE,YAAA,IAAI,CAAC,WAAW,GAAG,OAAO;AAC1B,YAAA,IAAI,CAAC,YAAY,GAAG,MAAM;AAC9B,QAAA,CAAC,CAAC;AAME,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;QACpB,IAAI,CAAC,OAAO,GAAG;AACX,YAAA,SAAS,EAAE,MAAM;AACjB,YAAA,GAAG,OAAO;SACb;;;AAGD,QAAA,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC;QAC7B,UAAU,CAAC,IAAI,CAAC;IACpB;AAEA;;;;;;;;AAQG;IACH,GAAG,CACC,OAAuC,EACvC,UAA2C,EAAA;AAE3C,QAAA,IAAI,CAAC,cAAc,GAAG,OAAO;AAC7B,QAA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AAY,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC;AAE7C,QAAA,OAAO,IAAI;IACf;AAEA;;;;AAIG;IACH,GAAG,CAAC,SAAiC,EAAE,OAA0B,EAAA;QAC7D,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC;AAE5C,QAAA,OAAO,IAAI;IACf;AAEA;;;AAGG;IACH,GAAG,CAAC,SAAiC,EAAE,OAA0B,EAAA;QAC7D,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC;AAE5C,QAAA,OAAO,IAAI;IACf;AAEA,IAAA,YAAY,CACR,MAAmD,EACnD,SAAiC,EACjC,UAA4B,EAAE,EAAA;AAE9B,QAAA,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;QAExC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE;AAC9B,YAAA,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,EAAE,CAAC;QACnC;QAEA,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAE;QAE/C,UAAU,CAAC,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE;IAC/C;IAEA,IAAI,CAAC,OAAmB,EAAE,MAAmB,EAAA;QACzC,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;IAClD;AACH;SAEe,WAAW,CACvB,MAAkC,EAClC,UAAiC,EAAE,EAAA;AAEnC,IAAA,OAAO,IAAI,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC;AACrD;;;;"}
@@ -34,14 +34,14 @@ const ORIGIN_DEFAULTS = {
34
34
  new: { opacity: 0, scale: 0.85 },
35
35
  old: { opacity: 1, scale: 1 },
36
36
  };
37
- const cornerProps = [
38
- "borderTopLeftRadius",
39
- "borderTopRightRadius",
40
- "borderBottomRightRadius",
41
- "borderBottomLeftRadius",
42
- ];
37
+ /**
38
+ * How much two box aspect ratios must differ before a morph is treated as
39
+ * aspect-changing (and so worth cropping). Matches the projection engine's
40
+ * `preserve-aspect` threshold, so small layout jitter doesn't trigger a crop.
41
+ */
42
+ const ASPECT_TOLERANCE = 0.2;
43
43
  function startViewAnimation(builder) {
44
- const { update, targets, resolveDefs, noCrop, pairs, classNames, options: defaultOptions, } = builder;
44
+ const { update, targets, resolveDefs, cropOverride, pairs, classNames, flatGroups, options: defaultOptions, } = builder;
45
45
  if (!document.startViewTransition) {
46
46
  // An async IIFE (not `new Promise(async …)`) so a throwing/rejecting
47
47
  // update rejects this promise rather than leaving it unsettled.
@@ -65,8 +65,21 @@ function startViewAnimation(builder) {
65
65
  * ever stripping an author's own inline `view-transition-name`.
66
66
  */
67
67
  const classed = [];
68
+ /**
69
+ * Elements we set a `view-transition-group` on (for nesting), tracked for
70
+ * cleanup. `clipChildren` collects the names of nested parents that clip in
71
+ * the live layout, so their `::view-transition-group-children` is clipped
72
+ * through the transition - not just once the live DOM takes back over.
73
+ */
74
+ const grouped = [];
75
+ const clipChildren = new Set();
68
76
  const layerTargets = new Map();
69
77
  const croppedNames = new Set();
78
+ /**
79
+ * Each layer's explicit `.crop(true | false)` override (by resolved name),
80
+ * so `finalizeCrop` can let an author's choice win over the morph default.
81
+ */
82
+ const cropForName = new Map();
70
83
  /**
71
84
  * Each layer's stagger position (index + total) within its subject, per
72
85
  * snapshot. Resolving against the snapshot the layer belongs to keeps
@@ -88,6 +101,18 @@ function startViewAnimation(builder) {
88
101
  const resolveLayers = (phase) => {
89
102
  targets.forEach((target, definition) => {
90
103
  const className = classNames.get(definition);
104
+ /**
105
+ * Nest each resolved layer under its DOM-ancestor layer by default
106
+ * (`contain`), so an ancestor's clip/transform/opacity reach it
107
+ * through the transition; `.group(false)` opts a subject out (`none`)
108
+ * to stay flat and escape. Skipped for root / pre-named layers, which
109
+ * aren't elements we resolve and style.
110
+ */
111
+ const group = definition === "root" || !resolveDefs.has(definition)
112
+ ? undefined
113
+ : flatGroups.has(definition)
114
+ ? "none"
115
+ : "contain";
91
116
  let names;
92
117
  if (definition === "root" || !resolveDefs.has(definition)) {
93
118
  names = [definition];
@@ -100,7 +125,7 @@ function startViewAnimation(builder) {
100
125
  */
101
126
  if (phase === "old") {
102
127
  pairFrom.set(definition, resolveElements(definition));
103
- names = assignViewTransitionNames(definition, nameRegistry, assigned, undefined, className, classed);
128
+ names = assignViewTransitionNames(definition, nameRegistry, assigned, undefined, className, classed, group, grouped, clipChildren);
104
129
  pairNames.set(definition, names);
105
130
  }
106
131
  else {
@@ -120,13 +145,16 @@ function startViewAnimation(builder) {
120
145
  */
121
146
  nameRegistry.delete(el);
122
147
  }
123
- names = assignViewTransitionNames(pairs.get(definition), nameRegistry, assigned, pairNames.get(definition), className, classed);
148
+ names = assignViewTransitionNames(pairs.get(definition), nameRegistry, assigned, pairNames.get(definition), className, classed, group, grouped, clipChildren);
124
149
  }
125
150
  }
126
151
  else {
127
- names = assignViewTransitionNames(definition, nameRegistry, assigned, undefined, className, classed);
152
+ names = assignViewTransitionNames(definition, nameRegistry, assigned, undefined, className, classed, group, grouped, clipChildren);
128
153
  }
129
- const cropped = definition !== "root" && !noCrop.has(definition);
154
+ // Record any explicit `.crop(true | false)` per resolved name; the
155
+ // crop set itself is computed later by `finalizeCrop` (it needs both
156
+ // snapshots to know which morphs change aspect ratio).
157
+ const override = cropOverride.get(definition);
130
158
  names.forEach((name, index) => {
131
159
  /**
132
160
  * If two subjects resolve to the same element, merge their
@@ -136,8 +164,8 @@ function startViewAnimation(builder) {
136
164
  layerTargets.set(name, existing && existing !== target
137
165
  ? { ...existing, ...target }
138
166
  : target);
139
- if (cropped)
140
- croppedNames.add(name);
167
+ if (override !== undefined)
168
+ cropForName.set(name, override);
141
169
  const stagger = layerStagger.get(name) ?? {};
142
170
  stagger[phase] = [index, names.length];
143
171
  layerStagger.set(name, stagger);
@@ -172,44 +200,62 @@ function startViewAnimation(builder) {
172
200
  return transition;
173
201
  };
174
202
  /**
175
- * Measured corner radii per cropped layer, so the clip can animate each
176
- * corner between the old and new elements. Per-corner (rather than the
177
- * shorthand) so mismatched/individual radii interpolate cleanly.
203
+ * Each layer's box size per snapshot, so `finalizeCrop` can tell whether a
204
+ * morph's aspect ratio changed (the only case worth cropping).
178
205
  */
179
- const cropRadii = new Map();
180
- const recordRadii = (style, name, phase) => {
181
- const corners = {};
182
- for (const corner of cornerProps)
183
- corners[corner] = style[corner];
184
- const entry = cropRadii.get(name) ?? {};
185
- entry[phase] = corners;
186
- cropRadii.set(name, entry);
187
- };
206
+ const cropBox = new Map();
207
+ const measureLayers = (phase) => nameRegistry.forEach((name, element) => {
208
+ const rect = element.getBoundingClientRect?.();
209
+ if (rect && rect.height) {
210
+ const entry = cropBox.get(name) ?? {};
211
+ entry[phase] = { width: rect.width, height: rect.height };
212
+ cropBox.set(name, entry);
213
+ }
214
+ });
188
215
  /**
189
- * Cropped layers all come from `.add()`, so their elements are in the
190
- * registry - read each one's corner radii directly. For a paired morph both
191
- * ends share a name; the new-snapshot element is registered last, so it
192
- * wins the `new` reading (and the old end the `old` reading).
216
+ * With both snapshots measured, settle which layers crop. The default crops
217
+ * only a morph whose aspect ratio *changes* between snapshots - the one case
218
+ * where `object-fit: cover` does real work. A same-aspect morph or a
219
+ * fade-only layer is left uncropped: its corners scale naturally (no flash
220
+ * from squaring, no `overflow: clip` eating its shadow) and a backdrop can't
221
+ * be clipped to nothing. An explicit `.crop(true | false)` overrides either
222
+ * way. Runs after both snapshots are measured, since aspect needs both.
193
223
  */
194
- const measureCrop = (phase) => {
195
- if (!croppedNames.size)
196
- return;
197
- nameRegistry.forEach((name, element) => {
198
- if (croppedNames.has(name)) {
199
- recordRadii(getComputedStyle(element), name, phase);
224
+ const finalizeCrop = () => {
225
+ croppedNames.clear();
226
+ for (const name of layerStagger.keys()) {
227
+ if (name === "root")
228
+ continue;
229
+ // An explicit `.crop(true | false)` wins; otherwise crop a morph
230
+ // whose aspect ratio changed.
231
+ if (cropForName.get(name) ?? aspectChanged(name)) {
232
+ croppedNames.add(name);
200
233
  }
201
- });
234
+ }
235
+ };
236
+ /**
237
+ * Whether a layer is a morph whose box aspect ratio changed between
238
+ * snapshots (beyond a small tolerance). Fade-only layers (one snapshot) are
239
+ * never "changed".
240
+ */
241
+ const aspectChanged = (name) => {
242
+ const box = cropBox.get(name);
243
+ if (!box?.old || !box?.new || !box.old.height || !box.new.height) {
244
+ return false;
245
+ }
246
+ return (Math.abs(box.old.width / box.old.height -
247
+ box.new.width / box.new.height) > ASPECT_TOLERANCE);
202
248
  };
203
249
  /**
204
250
  * Write the persistent view-transition CSS: suppress root capture when the
205
251
  * root has no animations of its own; force linear timing (baked into the
206
252
  * keyframes, so we can retime later via updateTiming); and clip +
207
253
  * object-fit: cover every cropped morph (the UA default overflows on
208
- * aspect-ratio change), with an animated border-radius added below.
254
+ * aspect-ratio change).
209
255
  *
210
256
  * `css.commit` replaces rather than appends, so we re-set the full rule set
211
- * each call - the second call (in the update callback) then picks up cropped
212
- * layers that only exist in the new snapshot.
257
+ * each call - the crop rules are only known after `finalizeCrop` runs in the
258
+ * update callback, so the second call writes them.
213
259
  */
214
260
  const commitViewCSS = () => {
215
261
  if (!hasTarget("root", targets)) {
@@ -220,33 +266,49 @@ function startViewAnimation(builder) {
220
266
  css.set(`::view-transition-group(${name})`, { overflow: "clip" });
221
267
  css.set(`::view-transition-old(${name}), ::view-transition-new(${name})`, { width: "100%", height: "100%", "object-fit": "cover" });
222
268
  });
269
+ /**
270
+ * Clip the nested children of any layer that clips in the live layout,
271
+ * so a wrapper crops its child for the whole morph (mirroring the DOM)
272
+ * rather than only at the live-DOM handoff. No-op on browsers without
273
+ * nested view-transition groups.
274
+ */
275
+ clipChildren.forEach((name) => {
276
+ css.set(`::view-transition-group-children(${name})`, {
277
+ overflow: "clip",
278
+ });
279
+ });
223
280
  css.commit(); // Write
224
281
  };
225
282
  const cleanup = () => {
226
- releaseViewTransitionNames(assigned, classed);
283
+ releaseViewTransitionNames(assigned, classed, grouped);
227
284
  css.remove(); // Write
228
285
  };
229
286
  const callback = async () => {
230
287
  await update();
231
288
  /**
232
289
  * Re-resolve so elements created by the update are named for the new
233
- * snapshot, then measure the cropped layers' new border-radius.
290
+ * snapshot, then measure them. With both snapshots measured we can
291
+ * settle the crop set (aspect-changing morphs + forced).
234
292
  */
235
- const croppedBefore = croppedNames.size;
236
293
  resolveLayers("new");
237
- measureCrop("new");
294
+ measureLayers("new");
295
+ finalizeCrop();
238
296
  /**
239
- * Re-commit the crop CSS only if the new snapshot introduced cropped
240
- * layers, so a layer that exists only in the new snapshot is clipped
241
- * too - without forcing a redundant style write on the common path.
297
+ * Re-commit the crop CSS unconditionally: `finalizeCrop` is computed
298
+ * here (after both snapshots are measured), so the clip rules must be
299
+ * (re)written to match the settled set.
242
300
  */
243
- if (croppedNames.size > croppedBefore)
244
- commitViewCSS();
301
+ commitViewCSS();
245
302
  };
246
303
  let transition;
247
304
  try {
248
305
  resolveLayers("old");
249
- measureCrop("old");
306
+ /**
307
+ * Measure the old snapshot against the optimistic crop set (the new
308
+ * snapshot doesn't exist yet, so aspect change can't be known here;
309
+ * `finalizeCrop` settles it post-update).
310
+ */
311
+ measureLayers("old");
250
312
  commitViewCSS();
251
313
  transition = document.startViewTransition(callback);
252
314
  }
@@ -421,6 +483,31 @@ function startViewAnimation(builder) {
421
483
  }
422
484
  continue;
423
485
  }
486
+ /**
487
+ * Drop the orphaned half of the default crossfade. The UA
488
+ * fades old out and new in as a *pair*; if the opposing half
489
+ * was explicitly overridden with something other than an
490
+ * opacity fade (a clip or transform reveal), this side's
491
+ * default opacity fade has no partner - left to run it would
492
+ * dissolve what should be a static backdrop (e.g.
493
+ * `.new({ clipPath })` should reveal over a still old view,
494
+ * not fade the old out around the growing clip). Cancel it -
495
+ * and its `plus-lighter` sibling on the same pseudo, which
496
+ * would otherwise flash bright where the two opaque layers
497
+ * overlap. A genuine crossfade (the opposing side also fading
498
+ * opacity) keeps both halves and is handled above.
499
+ */
500
+ const opposite = name.type === "old"
501
+ ? "new"
502
+ : name.type === "new"
503
+ ? "old"
504
+ : undefined;
505
+ if (opposite &&
506
+ explicitlyAnimated.has(`${name.layer}:${opposite}`) &&
507
+ !opacityAnimated.has(`${name.layer}:${opposite}`)) {
508
+ animation.cancel();
509
+ continue;
510
+ }
424
511
  /**
425
512
  * Otherwise retime the browser-generated animation to
426
513
  * Motion's timing. This auto-enables the layout (group)
@@ -475,38 +562,6 @@ function startViewAnimation(builder) {
475
562
  });
476
563
  animations.push(new NativeAnimationWrapper(animation));
477
564
  }
478
- /**
479
- * Animate each cropped layer's clip corners between the old and
480
- * new elements, so a cropped morph keeps rounded corners
481
- * (handling individual per-corner radii).
482
- */
483
- cropRadii.forEach((radii, name) => {
484
- if (!radii.old && !radii.new)
485
- return;
486
- const target = layerTargets.get(name);
487
- const [index, total] = staggerPosition(name, "group");
488
- const radiusOptions = resolveLayerTransition(target, "group", "layout", index === -1 ? 0 : index, total);
489
- radiusOptions.duration && (radiusOptions.duration = secondsToMilliseconds(radiusOptions.duration));
490
- radiusOptions.delay && (radiusOptions.delay = secondsToMilliseconds(radiusOptions.delay));
491
- for (const corner of cornerProps) {
492
- // `||` (not `??`) so an empty measurement (e.g. an
493
- // un-rendered element) falls back rather than producing
494
- // an invalid keyframe.
495
- const from = radii.old?.[corner] || radii.new?.[corner] || "0px";
496
- const to = radii.new?.[corner] || radii.old?.[corner] || "0px";
497
- // Skip square corners - nothing to round.
498
- if (parseFloat(from) === 0 && parseFloat(to) === 0) {
499
- continue;
500
- }
501
- animations.push(new NativeAnimation({
502
- ...radiusOptions,
503
- element: document.documentElement,
504
- name: corner,
505
- pseudoElement: `::view-transition-group(${name})`,
506
- keyframes: [from, to],
507
- }));
508
- }
509
- });
510
565
  resolve(new GroupAnimation(animations));
511
566
  })
512
567
  .catch(() =>