motion-dom 12.40.0 → 12.41.0

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.
Files changed (45) hide show
  1. package/dist/cjs/index.js +1023 -458
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/animation/JSAnimation.mjs +0 -3
  4. package/dist/es/animation/JSAnimation.mjs.map +1 -1
  5. package/dist/es/animation/waapi/start-waapi-animation.mjs +1 -12
  6. package/dist/es/animation/waapi/start-waapi-animation.mjs.map +1 -1
  7. package/dist/es/events/add-dom-event.mjs +1 -1
  8. package/dist/es/events/add-dom-event.mjs.map +1 -1
  9. package/dist/es/frameloop/batcher.mjs +1 -1
  10. package/dist/es/frameloop/batcher.mjs.map +1 -1
  11. package/dist/es/frameloop/render-step.mjs +1 -12
  12. package/dist/es/frameloop/render-step.mjs.map +1 -1
  13. package/dist/es/gestures/press/index.mjs +11 -4
  14. package/dist/es/gestures/press/index.mjs.map +1 -1
  15. package/dist/es/index.mjs +0 -1
  16. package/dist/es/index.mjs.map +1 -1
  17. package/dist/es/layout/LayoutAnimationBuilder.mjs +299 -214
  18. package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
  19. package/dist/es/projection/node/create-projection-node.mjs +0 -6
  20. package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
  21. package/dist/es/stats/buffer.mjs.map +1 -1
  22. package/dist/es/stats/index.mjs +4 -93
  23. package/dist/es/stats/index.mjs.map +1 -1
  24. package/dist/es/view/index.mjs +90 -13
  25. package/dist/es/view/index.mjs.map +1 -1
  26. package/dist/es/view/queue.mjs +9 -3
  27. package/dist/es/view/queue.mjs.map +1 -1
  28. package/dist/es/view/start.mjs +484 -83
  29. package/dist/es/view/start.mjs.map +1 -1
  30. package/dist/es/view/utils/assign-names.mjs +118 -0
  31. package/dist/es/view/utils/assign-names.mjs.map +1 -0
  32. package/dist/es/view/utils/choose-layer-type.mjs +1 -3
  33. package/dist/es/view/utils/choose-layer-type.mjs.map +1 -1
  34. package/dist/es/view/utils/get-layer-info.mjs +3 -1
  35. package/dist/es/view/utils/get-layer-info.mjs.map +1 -1
  36. package/dist/es/view/utils/get-view-animations.mjs +6 -8
  37. package/dist/es/view/utils/get-view-animations.mjs.map +1 -1
  38. package/dist/index.d.ts +105 -52
  39. package/dist/motion-dom.dev.js +1023 -458
  40. package/dist/motion-dom.js +1 -1
  41. package/dist/size-rollup-motion-value.js.map +1 -1
  42. package/dist/size-rollup-style-effect.js.map +1 -1
  43. package/package.json +2 -2
  44. package/dist/es/stats/animation-count.mjs +0 -8
  45. package/dist/es/stats/animation-count.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"buffer.mjs","sources":["../../../src/stats/buffer.ts"],"sourcesContent":["import type { StatsRecording } from \"./types\"\n\nexport type InactiveStatsBuffer = {\n value: null\n addProjectionMetrics: null\n}\n\nexport type ActiveStatsBuffer = {\n value: StatsRecording\n addProjectionMetrics: (metrics: {\n nodes: number\n calculatedTargetDeltas: number\n calculatedProjections: number\n }) => void\n}\n\nexport const statsBuffer: InactiveStatsBuffer | ActiveStatsBuffer = {\n value: null,\n addProjectionMetrics: null,\n}\n"],"names":[],"mappings":"AAgBO,MAAM,WAAW,GAA4C;AAChE,IAAA,KAAK,EAAE,IAAI;AACX,IAAA,oBAAoB,EAAE,IAAI;;;;;"}
1
+ {"version":3,"file":"buffer.mjs","sources":["../../../src/stats/buffer.ts"],"sourcesContent":["import type { LayoutProjectionMetrics, StatsRecording } from \"./types\"\n\nexport type InactiveStatsBuffer = {\n value: null\n addProjectionMetrics: null\n}\n\nexport type ActiveStatsBuffer = {\n value: StatsRecording\n addProjectionMetrics: (metrics: LayoutProjectionMetrics) => void\n}\n\nexport const statsBuffer: InactiveStatsBuffer | ActiveStatsBuffer = {\n value: null,\n addProjectionMetrics: null,\n}\n"],"names":[],"mappings":"AAYO,MAAM,WAAW,GAA4C;AAChE,IAAA,KAAK,EAAE,IAAI;AACX,IAAA,oBAAoB,EAAE,IAAI;;;;;"}
@@ -1,117 +1,28 @@
1
- import { activeAnimations } from './animation-count.mjs';
2
1
  import { statsBuffer } from './buffer.mjs';
3
- import { frame, cancelFrame, frameData } from '../frameloop/frame.mjs';
4
2
 
5
- function record() {
6
- const { value } = statsBuffer;
7
- if (value === null) {
8
- cancelFrame(record);
9
- return;
10
- }
11
- value.frameloop.rate.push(frameData.delta);
12
- value.animations.mainThread.push(activeAnimations.mainThread);
13
- value.animations.waapi.push(activeAnimations.waapi);
14
- value.animations.layout.push(activeAnimations.layout);
15
- }
16
- function mean(values) {
17
- return values.reduce((acc, value) => acc + value, 0) / values.length;
18
- }
19
- function summarise(values, calcAverage = mean) {
20
- if (values.length === 0) {
21
- return {
22
- min: 0,
23
- max: 0,
24
- avg: 0,
25
- };
26
- }
27
- return {
28
- min: Math.min(...values),
29
- max: Math.max(...values),
30
- avg: calcAverage(values),
31
- };
32
- }
33
- const msToFps = (ms) => Math.round(1000 / ms);
34
3
  function clearStatsBuffer() {
35
4
  statsBuffer.value = null;
36
5
  statsBuffer.addProjectionMetrics = null;
37
6
  }
38
- function reportStats() {
39
- const { value } = statsBuffer;
40
- if (!value) {
41
- throw new Error("Stats are not being measured");
42
- }
43
- clearStatsBuffer();
44
- cancelFrame(record);
45
- const summary = {
46
- frameloop: {
47
- setup: summarise(value.frameloop.setup),
48
- rate: summarise(value.frameloop.rate),
49
- read: summarise(value.frameloop.read),
50
- resolveKeyframes: summarise(value.frameloop.resolveKeyframes),
51
- preUpdate: summarise(value.frameloop.preUpdate),
52
- update: summarise(value.frameloop.update),
53
- preRender: summarise(value.frameloop.preRender),
54
- render: summarise(value.frameloop.render),
55
- postRender: summarise(value.frameloop.postRender),
56
- },
57
- animations: {
58
- mainThread: summarise(value.animations.mainThread),
59
- waapi: summarise(value.animations.waapi),
60
- layout: summarise(value.animations.layout),
61
- },
62
- layoutProjection: {
63
- nodes: summarise(value.layoutProjection.nodes),
64
- calculatedTargetDeltas: summarise(value.layoutProjection.calculatedTargetDeltas),
65
- calculatedProjections: summarise(value.layoutProjection.calculatedProjections),
66
- },
67
- };
68
- /**
69
- * Convert the rate to FPS
70
- */
71
- const { rate } = summary.frameloop;
72
- rate.min = msToFps(rate.min);
73
- rate.max = msToFps(rate.max);
74
- rate.avg = msToFps(rate.avg);
75
- [rate.min, rate.max] = [rate.max, rate.min];
76
- return summary;
77
- }
78
7
  function recordStats() {
79
8
  if (statsBuffer.value) {
80
9
  clearStatsBuffer();
81
10
  throw new Error("Stats are already being measured");
82
11
  }
83
- const newStatsBuffer = statsBuffer;
84
- newStatsBuffer.value = {
85
- frameloop: {
86
- setup: [],
87
- rate: [],
88
- read: [],
89
- resolveKeyframes: [],
90
- preUpdate: [],
91
- update: [],
92
- preRender: [],
93
- render: [],
94
- postRender: [],
95
- },
96
- animations: {
97
- mainThread: [],
98
- waapi: [],
99
- layout: [],
100
- },
12
+ const buffer = statsBuffer;
13
+ buffer.value = {
101
14
  layoutProjection: {
102
15
  nodes: [],
103
16
  calculatedTargetDeltas: [],
104
17
  calculatedProjections: [],
105
18
  },
106
19
  };
107
- newStatsBuffer.addProjectionMetrics = (metrics) => {
108
- const { layoutProjection } = newStatsBuffer.value;
20
+ buffer.addProjectionMetrics = (metrics) => {
21
+ const { layoutProjection } = buffer.value;
109
22
  layoutProjection.nodes.push(metrics.nodes);
110
23
  layoutProjection.calculatedTargetDeltas.push(metrics.calculatedTargetDeltas);
111
24
  layoutProjection.calculatedProjections.push(metrics.calculatedProjections);
112
25
  };
113
- frame.postRender(record, true);
114
- return reportStats;
115
26
  }
116
27
 
117
28
  export { recordStats };
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/stats/index.ts"],"sourcesContent":["import { cancelFrame, frame, frameData } from \"../frameloop\"\nimport { activeAnimations } from \"./animation-count\"\nimport { ActiveStatsBuffer, statsBuffer } from \"./buffer\"\nimport { StatsSummary, Summary } from \"./types\"\n\nfunction record() {\n const { value } = statsBuffer\n\n if (value === null) {\n cancelFrame(record)\n return\n }\n\n value.frameloop.rate.push(frameData.delta)\n value.animations.mainThread.push(activeAnimations.mainThread)\n value.animations.waapi.push(activeAnimations.waapi)\n value.animations.layout.push(activeAnimations.layout)\n}\n\nfunction mean(values: number[]) {\n return values.reduce((acc, value) => acc + value, 0) / values.length\n}\n\nfunction summarise(\n values: number[],\n calcAverage: (allValues: number[]) => number = mean\n): Summary {\n if (values.length === 0) {\n return {\n min: 0,\n max: 0,\n avg: 0,\n }\n }\n\n return {\n min: Math.min(...values),\n max: Math.max(...values),\n avg: calcAverage(values),\n }\n}\n\nconst msToFps = (ms: number) => Math.round(1000 / ms)\n\nfunction clearStatsBuffer() {\n statsBuffer.value = null\n statsBuffer.addProjectionMetrics = null\n}\n\nfunction reportStats(): StatsSummary {\n const { value } = statsBuffer\n\n if (!value) {\n throw new Error(\"Stats are not being measured\")\n }\n\n clearStatsBuffer()\n cancelFrame(record)\n\n const summary = {\n frameloop: {\n setup: summarise(value.frameloop.setup),\n rate: summarise(value.frameloop.rate),\n read: summarise(value.frameloop.read),\n resolveKeyframes: summarise(value.frameloop.resolveKeyframes),\n preUpdate: summarise(value.frameloop.preUpdate),\n update: summarise(value.frameloop.update),\n preRender: summarise(value.frameloop.preRender),\n render: summarise(value.frameloop.render),\n postRender: summarise(value.frameloop.postRender),\n },\n animations: {\n mainThread: summarise(value.animations.mainThread),\n waapi: summarise(value.animations.waapi),\n layout: summarise(value.animations.layout),\n },\n layoutProjection: {\n nodes: summarise(value.layoutProjection.nodes),\n calculatedTargetDeltas: summarise(\n value.layoutProjection.calculatedTargetDeltas\n ),\n calculatedProjections: summarise(\n value.layoutProjection.calculatedProjections\n ),\n },\n }\n\n /**\n * Convert the rate to FPS\n */\n const { rate } = summary.frameloop\n rate.min = msToFps(rate.min)\n rate.max = msToFps(rate.max)\n rate.avg = msToFps(rate.avg)\n // Swap these as the min and max are inverted when converted to FPS\n ;[rate.min, rate.max] = [rate.max, rate.min]\n\n return summary\n}\n\nexport function recordStats() {\n if (statsBuffer.value) {\n clearStatsBuffer()\n throw new Error(\"Stats are already being measured\")\n }\n\n const newStatsBuffer = statsBuffer as unknown as ActiveStatsBuffer\n\n newStatsBuffer.value = {\n frameloop: {\n setup: [],\n rate: [],\n read: [],\n resolveKeyframes: [],\n preUpdate: [],\n update: [],\n preRender: [],\n render: [],\n postRender: [],\n },\n animations: {\n mainThread: [],\n waapi: [],\n layout: [],\n },\n layoutProjection: {\n nodes: [],\n calculatedTargetDeltas: [],\n calculatedProjections: [],\n },\n }\n\n newStatsBuffer.addProjectionMetrics = (metrics) => {\n const { layoutProjection } = newStatsBuffer.value\n layoutProjection.nodes.push(metrics.nodes)\n layoutProjection.calculatedTargetDeltas.push(\n metrics.calculatedTargetDeltas\n )\n layoutProjection.calculatedProjections.push(\n metrics.calculatedProjections\n )\n }\n\n frame.postRender(record, true)\n\n return reportStats\n}\n"],"names":[],"mappings":";;;;AAKA,SAAS,MAAM,GAAA;AACX,IAAA,MAAM,EAAE,KAAK,EAAE,GAAG,WAAW;AAE7B,IAAA,IAAI,KAAK,KAAK,IAAI,EAAE;QAChB,WAAW,CAAC,MAAM,CAAC;QACnB;IACJ;IAEA,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;IAC1C,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC;IAC7D,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC;IACnD,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;AACzD;AAEA,SAAS,IAAI,CAAC,MAAgB,EAAA;IAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,KAAK,GAAG,GAAG,KAAK,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM;AACxE;A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ts"],"sourcesContent":["import { ActiveStatsBuffer, statsBuffer } from \"./buffer\"\n\nfunction clearStatsBuffer() {\n statsBuffer.value = null\n statsBuffer.addProjectionMetrics = null\n}\n\nexport function recordStats() {\n if (statsBuffer.value) {\n clearStatsBuffer()\n throw new Error(\"Stats are already being measured\")\n }\n\n const buffer = statsBuffer as unknown as ActiveStatsBuffer\n\n buffer.value = {\n layoutProjection: {\n nodes: [],\n calculatedTargetDeltas: [],\n calculatedProjections: [],\n },\n }\n\n buffer.addProjectionMetrics = (metrics) => {\n const { layoutProjection } = buffer.value\n layoutProjection.nodes.push(metrics.nodes)\n layoutProjection.calculatedTargetDeltas.push(\n metrics.calculatedTargetDeltas\n )\n layoutProjection.calculatedProjections.push(\n metrics.calculatedProjections\n )\n }\n}\n"],"names":[],"mappings":";;AAEA,SAAS,gBAAgB,GAAA;AACrB,IAAA,WAAW,CAAC,KAAK,GAAG,IAAI;AACxB,IAAA,WAAW,CAAC,oBAAoB,GAAG,IAAI;AAC3C;SAEgB,WAAW,GAAA;AACvB,IAAA,IAAI,WAAW,CAAC,KAAK,EAAE;AACnB,QAAA,gBAAgB,EAAE;AAClB,QAAA,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC;IACvD;IAEA,MAAM,MAAM,GAAG,WAA2C;IAE1D,MAAM,CAAC,KAAK,GAAG;AACX,QAAA,gBAAgB,EAAE;AACd,YAAA,KAAK,EAAE,EAAE;AACT,YAAA,sBAAsB,EAAE,EAAE;AAC1B,YAAA,qBAAqB,EAAE,EAAE;AAC5B,SAAA;KACJ;AAED,IAAA,MAAM,CAAC,oBAAoB,GAAG,CAAC,OAAO,KAAI;AACtC,QAAA,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC,KAAK;QACzC,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QAC1C,gBAAgB,CAAC,sBAAsB,CAAC,IAAI,CACxC,OAAO,CAAC,sBAAsB,CACjC;QACD,gBAAgB,CAAC,qBAAqB,CAAC,IAAI,CACvC,OAAO,CAAC,qBAAqB,CAChC;AACL,IAAA,CAAC;AACL;;;;"}
@@ -5,31 +5,96 @@ class ViewTransitionBuilder {
5
5
  constructor(update, options = {}) {
6
6
  this.currentSubject = "root";
7
7
  this.targets = new Map();
8
+ /**
9
+ * Definitions that must be resolved to elements (and assigned a
10
+ * `view-transition-name`) rather than treated as pre-named layers.
11
+ */
12
+ this.resolveDefs = new Set();
13
+ /**
14
+ * Subjects opted out of the default crop (clip + object-fit: cover +
15
+ * animated corner radii) via `.crop(false)`.
16
+ */
17
+ this.noCrop = new Set();
18
+ /**
19
+ * Subjects paired with a different new-snapshot target (the second `.add()`
20
+ * argument), so two distinct elements share one name and morph into each
21
+ * other - a shared-element transition.
22
+ */
23
+ this.pairs = new Map();
24
+ /**
25
+ * A `view-transition-class` to apply to each subject's resolved elements,
26
+ * so authors can target the generated layers from CSS by class rather than
27
+ * the opaque generated name.
28
+ */
29
+ this.classNames = new Map();
8
30
  this.notifyReady = noop;
9
- this.readyPromise = new Promise((resolve) => {
31
+ this.notifyReject = noop;
32
+ this.readyPromise = new Promise((resolve, reject) => {
10
33
  this.notifyReady = resolve;
34
+ this.notifyReject = reject;
11
35
  });
12
36
  this.update = update;
13
37
  this.options = {
14
38
  interrupt: "wait",
15
39
  ...options,
16
40
  };
41
+ // Avoid an unhandled rejection when a failed transition has no
42
+ // `.then(_, reject)` handler attached (e.g. fire-and-forget).
43
+ this.readyPromise.catch(noop);
17
44
  addToQueue(this);
18
45
  }
19
- get(subject) {
46
+ /**
47
+ * Target elements resolved from a selector or Element, each assigned a
48
+ * `view-transition-name` automatically.
49
+ *
50
+ * Passing a second target pairs them: the first is resolved in the old
51
+ * snapshot and the second in the new, sharing one name so two *different*
52
+ * elements morph into each other (e.g. `.add(card, ".modal")`). Symmetric -
53
+ * pass them the other way round to morph back.
54
+ */
55
+ add(subject, newSubject) {
20
56
  this.currentSubject = subject;
57
+ this.resolveDefs.add(subject);
58
+ if (newSubject !== undefined)
59
+ this.pairs.set(subject, newSubject);
60
+ // Register the subject so it participates (and gets an automatic
61
+ // layout/morph animation) even without an explicit enter/exit/layout.
62
+ if (!this.targets.has(subject))
63
+ this.targets.set(subject, {});
21
64
  return this;
22
65
  }
23
- layout(keyframes, options) {
24
- this.updateTarget("layout", keyframes, options);
66
+ /**
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).
70
+ */
71
+ crop(enabled = true) {
72
+ enabled
73
+ ? this.noCrop.delete(this.currentSubject)
74
+ : this.noCrop.add(this.currentSubject);
25
75
  return this;
26
76
  }
27
- new(keyframes, options) {
28
- this.updateTarget("new", keyframes, options);
77
+ /**
78
+ * Tag this subject's generated layers with a `view-transition-class`, so
79
+ * they can be targeted from CSS - `::view-transition-group(.name)`,
80
+ * `::view-transition-old/new(.name)`, `::view-transition-image-pair(.name)`
81
+ * - without the opaque generated `view-transition-name`. Because `.add()`
82
+ * can match many elements, a shared class targets them all at once (and,
83
+ * for a pair, both ends). The escape hatch for z-index / custom keyframes
84
+ * on a morph layer.
85
+ */
86
+ class(name) {
87
+ this.classNames.set(this.currentSubject, name);
29
88
  return this;
30
89
  }
31
- old(keyframes, options) {
32
- this.updateTarget("old", keyframes, options);
90
+ /**
91
+ * Set the transition for this subject's morph. The morph is enabled
92
+ * automatically by `.add()`; this just customises its timing (duration,
93
+ * easing, a `delay`/`stagger`, …). On the implicit `root` subject it also
94
+ * opts the page into the transition (the root crossfade).
95
+ */
96
+ layout(options = {}) {
97
+ this.updateTarget("layout", {}, options);
33
98
  return this;
34
99
  }
35
100
  enter(keyframes, options) {
@@ -40,9 +105,21 @@ class ViewTransitionBuilder {
40
105
  this.updateTarget("exit", keyframes, options);
41
106
  return this;
42
107
  }
43
- crossfade(options) {
44
- this.updateTarget("enter", { opacity: 1 }, options);
45
- this.updateTarget("exit", { opacity: 0 }, options);
108
+ /**
109
+ * Animate the new view directly, whether the element is appearing or
110
+ * persisting (unlike `.enter()`, which only fires for a pure newcomer).
111
+ * Pair with `.old()` for a crossfade or slide-through.
112
+ */
113
+ new(keyframes, options) {
114
+ this.updateTarget("new", keyframes, options);
115
+ return this;
116
+ }
117
+ /**
118
+ * Animate the old view directly, whether the element is leaving or
119
+ * persisting (unlike `.exit()`, which only fires for a pure leaver).
120
+ */
121
+ old(keyframes, options) {
122
+ this.updateTarget("old", keyframes, options);
46
123
  return this;
47
124
  }
48
125
  updateTarget(target, keyframes, options = {}) {
@@ -57,8 +134,8 @@ class ViewTransitionBuilder {
57
134
  return this.readyPromise.then(resolve, reject);
58
135
  }
59
136
  }
60
- function animateView(update, defaultOptions = {}) {
61
- return new ViewTransitionBuilder(update, defaultOptions);
137
+ function animateView(update, options = {}) {
138
+ return new ViewTransitionBuilder(update, options);
62
139
  }
63
140
 
64
141
  export { ViewTransitionBuilder, animateView };
@@ -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\nexport class ViewTransitionBuilder {\n private currentSubject: ViewTransitionTargetDefinition = \"root\"\n\n targets = new Map<ViewTransitionTargetDefinition, ViewTransitionTarget>()\n\n update: () => void | Promise<void>\n\n options: ViewTransitionOptions\n\n notifyReady: (value: GroupAnimation) => void = noop\n\n private readyPromise = new Promise<GroupAnimation>((resolve) => {\n this.notifyReady = resolve\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 addToQueue(this)\n }\n\n get(subject: ViewTransitionTargetDefinition) {\n this.currentSubject = subject\n\n return this\n }\n\n layout(keyframes: DOMKeyframesDefinition, options?: AnimationOptions) {\n this.updateTarget(\"layout\", keyframes, options)\n\n return this\n }\n\n new(keyframes: DOMKeyframesDefinition, options?: AnimationOptions) {\n this.updateTarget(\"new\", keyframes, options)\n\n return this\n }\n\n old(keyframes: DOMKeyframesDefinition, options?: AnimationOptions) {\n this.updateTarget(\"old\", keyframes, 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 crossfade(options?: AnimationOptions) {\n this.updateTarget(\"enter\", { opacity: 1 }, options)\n this.updateTarget(\"exit\", { opacity: 0 }, 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 defaultOptions: ViewTransitionOptions = {}\n) {\n return new ViewTransitionBuilder(update, defaultOptions)\n}\n"],"names":[],"mappings":";;;MAWa,qBAAqB,CAAA;IAe9B,WAAA,CACI,MAAkC,EAClC,OAAA,GAAiC,EAAE,EAAA;QAhB/B,IAAA,CAAA,cAAc,GAAmC,MAAM;AAE/D,QAAA,IAAA,CAAA,OAAO,GAAG,IAAI,GAAG,EAAwD;QAMzE,IAAA,CAAA,WAAW,GAAoC,IAAI;AAE3C,QAAA,IAAA,CAAA,YAAY,GAAG,IAAI,OAAO,CAAiB,CAAC,OAAO,KAAI;A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EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC;AAElD,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,iBAAwC,EAAE,EAAA;AAE1C,IAAA,OAAO,IAAI,qBAAqB,CAAC,MAAM,EAAE,cAAc,CAAC;AAC5D;;;;"}
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;;;;;;;;AAQG;IACH,GAAG,CACC,OAAuC,EACvC,UAA2C,EAA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0B,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;;;;"}
@@ -13,10 +13,16 @@ function next() {
13
13
  function start(builder) {
14
14
  removeItem(builders, builder);
15
15
  current = builder;
16
- startViewAnimation(builder).then((animation) => {
16
+ startViewAnimation(builder)
17
+ .then((animation) => {
17
18
  builder.notifyReady(animation);
18
- animation.finished.finally(next);
19
- });
19
+ return animation.finished;
20
+ })
21
+ // A genuinely failed transition (a throwing update) rejects the
22
+ // builder; a skipped/interrupted one resolves with no animations (see
23
+ // start.ts). Either way, advance the queue - else later transitions hang.
24
+ .catch((error) => builder.notifyReject(error))
25
+ .finally(next);
20
26
  }
21
27
  function processQueue() {
22
28
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"queue.mjs","sources":["../../../src/view/queue.ts"],"sourcesContent":["import { removeItem } from \"motion-utils\"\nimport type { ViewTransitionBuilder } from \".\"\nimport { microtask } from \"../frameloop/microtask\"\nimport { startViewAnimation } from \"./start\"\n\nlet builders: ViewTransitionBuilder[] = []\n\nlet current: ViewTransitionBuilder | null = null\n\nfunction next() {\n current = null\n const [nextBuilder] = builders\n if (nextBuilder) start(nextBuilder)\n}\n\nfunction start(builder: ViewTransitionBuilder) {\n removeItem(builders, builder)\n current = builder\n startViewAnimation(builder).then((animation) => {\n builder.notifyReady(animation)\n animation.finished.finally(next)\n })\n}\n\nfunction processQueue() {\n /**\n * Iterate backwards over the builders array. We can ignore the\n * \"wait\" animations. If we have an interrupting animation in the\n * queue then we need to batch all preceeding animations into it.\n * Currently this only batches the update functions but will also\n * need to batch the targets.\n */\n for (let i = builders.length - 1; i >= 0; i--) {\n const builder = builders[i]\n const { interrupt } = builder.options\n\n if (interrupt === \"immediate\") {\n const batchedUpdates = builders.slice(0, i + 1).map((b) => b.update)\n const remaining = builders.slice(i + 1)\n\n builder.update = () => {\n batchedUpdates.forEach((update) => update())\n }\n\n // Put the current builder at the front, followed by any \"wait\" builders\n builders = [builder, ...remaining]\n\n break\n }\n }\n\n if (!current || builders[0]?.options.interrupt === \"immediate\") {\n next()\n }\n}\n\nexport function addToQueue(builder: ViewTransitionBuilder) {\n builders.push(builder)\n microtask.render(processQueue)\n}\n"],"names":[],"mappings":";;;;AAKA,IAAI,QAAQ,GAA4B,EAAE;AAE1C,IAAI,OAAO,GAAiC,IAAI;AAEhD,SAAS,IAAI,GAAA;IACT,OAAO,GAAG,IAAI;AACd,IAAA,MAAM,CAAC,WAAW,CAAC,GAAG,QAAQ;AAC9B,IAAA,IAAI,WAAW;QAAE,KAAK,CAAC,WAAW,CAAC;AACvC;AAEA,SAAS,KAAK,CAAC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,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;AACtB,IAAA,SAAS,CAAC,MAAM,CAAC,YAAY,CAAC;AAClC;;;;"}
1
+ {"version":3,"file":"queue.mjs","sources":["../../../src/view/queue.ts"],"sourcesContent":["import { removeItem } from \"motion-utils\"\nimport type { ViewTransitionBuilder } from \".\"\nimport { microtask } from \"../frameloop/microtask\"\nimport { startViewAnimation } from \"./start\"\n\nlet builders: ViewTransitionBuilder[] = []\n\nlet current: ViewTransitionBuilder | null = null\n\nfunction next() {\n current = null\n const [nextBuilder] = builders\n if (nextBuilder) start(nextBuilder)\n}\n\nfunction start(builder: ViewTransitionBuilder) {\n removeItem(builders, builder)\n current = builder\n startViewAnimation(builder)\n .then((animation) => {\n builder.notifyReady(animation)\n return animation.finished\n })\n // A genuinely failed transition (a throwing update) rejects the\n // builder; a skipped/interrupted one resolves with no animations (see\n // start.ts). Either way, advance the queue - else later transitions hang.\n .catch((error) => builder.notifyReject(error))\n .finally(next)\n}\n\nfunction processQueue() {\n /**\n * Iterate backwards over the builders array. We can ignore the\n * \"wait\" animations. If we have an interrupting animation in the\n * queue then we need to batch all preceeding animations into it.\n * Currently this only batches the update functions but will also\n * need to batch the targets.\n */\n for (let i = builders.length - 1; i >= 0; i--) {\n const builder = builders[i]\n const { interrupt } = builder.options\n\n if (interrupt === \"immediate\") {\n const batchedUpdates = builders.slice(0, i + 1).map((b) => b.update)\n const remaining = builders.slice(i + 1)\n\n builder.update = () => {\n batchedUpdates.forEach((update) => update())\n }\n\n // Put the current builder at the front, followed by any \"wait\" builders\n builders = [builder, ...remaining]\n\n break\n }\n }\n\n if (!current || builders[0]?.options.interrupt === \"immediate\") {\n next()\n }\n}\n\nexport function addToQueue(builder: ViewTransitionBuilder) {\n builders.push(builder)\n microtask.render(processQueue)\n}\n"],"names":[],"mappings":";;;;AAKA,IAAI,QAAQ,GAA4B,EAAE;AAE1C,IAAI,OAAO,GAAiC,IAAI;AAEhD,SAAS,IAAI,GAAA;IACT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