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.
- package/dist/cjs/index.js +1023 -458
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/JSAnimation.mjs +0 -3
- package/dist/es/animation/JSAnimation.mjs.map +1 -1
- package/dist/es/animation/waapi/start-waapi-animation.mjs +1 -12
- package/dist/es/animation/waapi/start-waapi-animation.mjs.map +1 -1
- package/dist/es/events/add-dom-event.mjs +1 -1
- package/dist/es/events/add-dom-event.mjs.map +1 -1
- package/dist/es/frameloop/batcher.mjs +1 -1
- package/dist/es/frameloop/batcher.mjs.map +1 -1
- package/dist/es/frameloop/render-step.mjs +1 -12
- package/dist/es/frameloop/render-step.mjs.map +1 -1
- package/dist/es/gestures/press/index.mjs +11 -4
- package/dist/es/gestures/press/index.mjs.map +1 -1
- package/dist/es/index.mjs +0 -1
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/layout/LayoutAnimationBuilder.mjs +299 -214
- package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +0 -6
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/stats/buffer.mjs.map +1 -1
- package/dist/es/stats/index.mjs +4 -93
- package/dist/es/stats/index.mjs.map +1 -1
- package/dist/es/view/index.mjs +90 -13
- package/dist/es/view/index.mjs.map +1 -1
- package/dist/es/view/queue.mjs +9 -3
- package/dist/es/view/queue.mjs.map +1 -1
- package/dist/es/view/start.mjs +484 -83
- package/dist/es/view/start.mjs.map +1 -1
- package/dist/es/view/utils/assign-names.mjs +118 -0
- package/dist/es/view/utils/assign-names.mjs.map +1 -0
- package/dist/es/view/utils/choose-layer-type.mjs +1 -3
- package/dist/es/view/utils/choose-layer-type.mjs.map +1 -1
- package/dist/es/view/utils/get-layer-info.mjs +3 -1
- package/dist/es/view/utils/get-layer-info.mjs.map +1 -1
- package/dist/es/view/utils/get-view-animations.mjs +6 -8
- package/dist/es/view/utils/get-view-animations.mjs.map +1 -1
- package/dist/index.d.ts +105 -52
- package/dist/motion-dom.dev.js +1023 -458
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-motion-value.js.map +1 -1
- package/dist/size-rollup-style-effect.js.map +1 -1
- package/package.json +2 -2
- package/dist/es/stats/animation-count.mjs +0 -8
- 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:
|
|
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;;;;;"}
|
package/dist/es/stats/index.mjs
CHANGED
|
@@ -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
|
|
84
|
-
|
|
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
|
-
|
|
108
|
-
const { layoutProjection } =
|
|
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 {
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/stats/index.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;;;;"}
|
package/dist/es/view/index.mjs
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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,
|
|
61
|
-
return new ViewTransitionBuilder(update,
|
|
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
|
|
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;Q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B,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;;;;"}
|
package/dist/es/view/queue.mjs
CHANGED
|
@@ -13,10 +13,16 @@ function next() {
|
|
|
13
13
|
function start(builder) {
|
|
14
14
|
removeItem(builders, builder);
|
|
15
15
|
current = builder;
|
|
16
|
-
startViewAnimation(builder)
|
|
16
|
+
startViewAnimation(builder)
|
|
17
|
+
.then((animation) => {
|
|
17
18
|
builder.notifyReady(animation);
|
|
18
|
-
animation.finished
|
|
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
|
|
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,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,OAA8B,EAAA;AACzC,IAAA,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