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
package/dist/motion-dom.dev.js
CHANGED
|
@@ -15,12 +15,7 @@
|
|
|
15
15
|
"postRender", // Compute
|
|
16
16
|
];
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
value: null,
|
|
20
|
-
addProjectionMetrics: null,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
function createRenderStep(runNextFrame, stepName) {
|
|
18
|
+
function createRenderStep(runNextFrame) {
|
|
24
19
|
/**
|
|
25
20
|
* We create and reuse two queues, one to queue jobs for the current frame
|
|
26
21
|
* and one for the next. We reuse to avoid triggering GC after x frames.
|
|
@@ -42,13 +37,11 @@
|
|
|
42
37
|
timestamp: 0.0,
|
|
43
38
|
isProcessing: false,
|
|
44
39
|
};
|
|
45
|
-
let numCalls = 0;
|
|
46
40
|
function triggerCallback(callback) {
|
|
47
41
|
if (toKeepAlive.has(callback)) {
|
|
48
42
|
step.schedule(callback);
|
|
49
43
|
runNextFrame();
|
|
50
44
|
}
|
|
51
|
-
numCalls++;
|
|
52
45
|
callback(latestFrameData);
|
|
53
46
|
}
|
|
54
47
|
const step = {
|
|
@@ -91,13 +84,6 @@
|
|
|
91
84
|
nextFrame = prevFrame;
|
|
92
85
|
// Execute this frame
|
|
93
86
|
thisFrame.forEach(triggerCallback);
|
|
94
|
-
/**
|
|
95
|
-
* If we're recording stats then
|
|
96
|
-
*/
|
|
97
|
-
if (stepName && statsBuffer.value) {
|
|
98
|
-
statsBuffer.value.frameloop[stepName].push(numCalls);
|
|
99
|
-
}
|
|
100
|
-
numCalls = 0;
|
|
101
87
|
// Clear the frame so no callbacks remain. This is to avoid
|
|
102
88
|
// memory leaks should this render step not run for a while.
|
|
103
89
|
thisFrame.clear();
|
|
@@ -122,7 +108,7 @@
|
|
|
122
108
|
};
|
|
123
109
|
const flagRunNextFrame = () => (runNextFrame = true);
|
|
124
110
|
const steps = stepsOrder.reduce((acc, key) => {
|
|
125
|
-
acc[key] = createRenderStep(flagRunNextFrame
|
|
111
|
+
acc[key] = createRenderStep(flagRunNextFrame);
|
|
126
112
|
return acc;
|
|
127
113
|
}, {});
|
|
128
114
|
const { setup, read, resolveKeyframes, preUpdate, update, preRender, render, postRender, } = steps;
|
|
@@ -207,12 +193,6 @@
|
|
|
207
193
|
},
|
|
208
194
|
};
|
|
209
195
|
|
|
210
|
-
const activeAnimations = {
|
|
211
|
-
layout: 0,
|
|
212
|
-
mainThread: 0,
|
|
213
|
-
waapi: 0,
|
|
214
|
-
};
|
|
215
|
-
|
|
216
196
|
const checkStringStartsWith = (token) => (key) => typeof key === "string" && key.startsWith(token);
|
|
217
197
|
const isCSSVariableName =
|
|
218
198
|
/*@__PURE__*/ checkStringStartsWith("--");
|
|
@@ -1414,7 +1394,6 @@
|
|
|
1414
1394
|
this.teardown();
|
|
1415
1395
|
this.options.onStop?.();
|
|
1416
1396
|
};
|
|
1417
|
-
activeAnimations.mainThread++;
|
|
1418
1397
|
this.options = options;
|
|
1419
1398
|
this.initAnimation();
|
|
1420
1399
|
this.play();
|
|
@@ -1719,7 +1698,6 @@
|
|
|
1719
1698
|
this.state = "idle";
|
|
1720
1699
|
this.stopDriver();
|
|
1721
1700
|
this.startTime = this.holdTime = null;
|
|
1722
|
-
activeAnimations.mainThread--;
|
|
1723
1701
|
}
|
|
1724
1702
|
stopDriver() {
|
|
1725
1703
|
if (!this.driver)
|
|
@@ -2131,9 +2109,6 @@
|
|
|
2131
2109
|
*/
|
|
2132
2110
|
if (Array.isArray(easing))
|
|
2133
2111
|
keyframeOptions.easing = easing;
|
|
2134
|
-
if (statsBuffer.value) {
|
|
2135
|
-
activeAnimations.waapi++;
|
|
2136
|
-
}
|
|
2137
2112
|
const options = {
|
|
2138
2113
|
delay,
|
|
2139
2114
|
duration,
|
|
@@ -2144,13 +2119,7 @@
|
|
|
2144
2119
|
};
|
|
2145
2120
|
if (pseudoElement)
|
|
2146
2121
|
options.pseudoElement = pseudoElement;
|
|
2147
|
-
|
|
2148
|
-
if (statsBuffer.value) {
|
|
2149
|
-
animation.finished.finally(() => {
|
|
2150
|
-
activeAnimations.waapi--;
|
|
2151
|
-
});
|
|
2152
|
-
}
|
|
2153
|
-
return animation;
|
|
2122
|
+
return element.animate(keyframeOptions, options);
|
|
2154
2123
|
}
|
|
2155
2124
|
|
|
2156
2125
|
function isGenerator(type) {
|
|
@@ -4860,9 +4829,16 @@
|
|
|
4860
4829
|
claimedPointerDownEvents.add(startEvent);
|
|
4861
4830
|
}
|
|
4862
4831
|
const onPressEnd = onPressStart(target, startEvent);
|
|
4832
|
+
/**
|
|
4833
|
+
* End listeners run in the capture phase so a descendant calling
|
|
4834
|
+
* stopPropagation() in its own pointerup handler can't prevent the
|
|
4835
|
+
* press gesture from ending. This also keeps the gesture-end
|
|
4836
|
+
* ordering consistent with the drag gesture. See #2794.
|
|
4837
|
+
*/
|
|
4838
|
+
const endEventOptions = { ...eventOptions, capture: true };
|
|
4863
4839
|
const onPointerEnd = (endEvent, success) => {
|
|
4864
|
-
window.removeEventListener("pointerup", onPointerUp);
|
|
4865
|
-
window.removeEventListener("pointercancel", onPointerCancel);
|
|
4840
|
+
window.removeEventListener("pointerup", onPointerUp, endEventOptions);
|
|
4841
|
+
window.removeEventListener("pointercancel", onPointerCancel, endEventOptions);
|
|
4866
4842
|
if (isPressing.has(target)) {
|
|
4867
4843
|
isPressing.delete(target);
|
|
4868
4844
|
}
|
|
@@ -4882,8 +4858,8 @@
|
|
|
4882
4858
|
const onPointerCancel = (cancelEvent) => {
|
|
4883
4859
|
onPointerEnd(cancelEvent, false);
|
|
4884
4860
|
};
|
|
4885
|
-
window.addEventListener("pointerup", onPointerUp,
|
|
4886
|
-
window.addEventListener("pointercancel", onPointerCancel,
|
|
4861
|
+
window.addEventListener("pointerup", onPointerUp, endEventOptions);
|
|
4862
|
+
window.addEventListener("pointercancel", onPointerCancel, endEventOptions);
|
|
4887
4863
|
};
|
|
4888
4864
|
targets.forEach((target) => {
|
|
4889
4865
|
const pointerDownTarget = options.useGlobalTarget ? window : target;
|
|
@@ -5022,116 +4998,34 @@
|
|
|
5022
4998
|
return () => cancelFrame(onFrame);
|
|
5023
4999
|
}
|
|
5024
5000
|
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
}
|
|
5031
|
-
value.frameloop.rate.push(frameData.delta);
|
|
5032
|
-
value.animations.mainThread.push(activeAnimations.mainThread);
|
|
5033
|
-
value.animations.waapi.push(activeAnimations.waapi);
|
|
5034
|
-
value.animations.layout.push(activeAnimations.layout);
|
|
5035
|
-
}
|
|
5036
|
-
function mean(values) {
|
|
5037
|
-
return values.reduce((acc, value) => acc + value, 0) / values.length;
|
|
5038
|
-
}
|
|
5039
|
-
function summarise(values, calcAverage = mean) {
|
|
5040
|
-
if (values.length === 0) {
|
|
5041
|
-
return {
|
|
5042
|
-
min: 0,
|
|
5043
|
-
max: 0,
|
|
5044
|
-
avg: 0,
|
|
5045
|
-
};
|
|
5046
|
-
}
|
|
5047
|
-
return {
|
|
5048
|
-
min: Math.min(...values),
|
|
5049
|
-
max: Math.max(...values),
|
|
5050
|
-
avg: calcAverage(values),
|
|
5051
|
-
};
|
|
5052
|
-
}
|
|
5053
|
-
const msToFps = (ms) => Math.round(1000 / ms);
|
|
5001
|
+
const statsBuffer = {
|
|
5002
|
+
value: null,
|
|
5003
|
+
addProjectionMetrics: null,
|
|
5004
|
+
};
|
|
5005
|
+
|
|
5054
5006
|
function clearStatsBuffer() {
|
|
5055
5007
|
statsBuffer.value = null;
|
|
5056
5008
|
statsBuffer.addProjectionMetrics = null;
|
|
5057
5009
|
}
|
|
5058
|
-
function reportStats() {
|
|
5059
|
-
const { value } = statsBuffer;
|
|
5060
|
-
if (!value) {
|
|
5061
|
-
throw new Error("Stats are not being measured");
|
|
5062
|
-
}
|
|
5063
|
-
clearStatsBuffer();
|
|
5064
|
-
cancelFrame(record);
|
|
5065
|
-
const summary = {
|
|
5066
|
-
frameloop: {
|
|
5067
|
-
setup: summarise(value.frameloop.setup),
|
|
5068
|
-
rate: summarise(value.frameloop.rate),
|
|
5069
|
-
read: summarise(value.frameloop.read),
|
|
5070
|
-
resolveKeyframes: summarise(value.frameloop.resolveKeyframes),
|
|
5071
|
-
preUpdate: summarise(value.frameloop.preUpdate),
|
|
5072
|
-
update: summarise(value.frameloop.update),
|
|
5073
|
-
preRender: summarise(value.frameloop.preRender),
|
|
5074
|
-
render: summarise(value.frameloop.render),
|
|
5075
|
-
postRender: summarise(value.frameloop.postRender),
|
|
5076
|
-
},
|
|
5077
|
-
animations: {
|
|
5078
|
-
mainThread: summarise(value.animations.mainThread),
|
|
5079
|
-
waapi: summarise(value.animations.waapi),
|
|
5080
|
-
layout: summarise(value.animations.layout),
|
|
5081
|
-
},
|
|
5082
|
-
layoutProjection: {
|
|
5083
|
-
nodes: summarise(value.layoutProjection.nodes),
|
|
5084
|
-
calculatedTargetDeltas: summarise(value.layoutProjection.calculatedTargetDeltas),
|
|
5085
|
-
calculatedProjections: summarise(value.layoutProjection.calculatedProjections),
|
|
5086
|
-
},
|
|
5087
|
-
};
|
|
5088
|
-
/**
|
|
5089
|
-
* Convert the rate to FPS
|
|
5090
|
-
*/
|
|
5091
|
-
const { rate } = summary.frameloop;
|
|
5092
|
-
rate.min = msToFps(rate.min);
|
|
5093
|
-
rate.max = msToFps(rate.max);
|
|
5094
|
-
rate.avg = msToFps(rate.avg);
|
|
5095
|
-
[rate.min, rate.max] = [rate.max, rate.min];
|
|
5096
|
-
return summary;
|
|
5097
|
-
}
|
|
5098
5010
|
function recordStats() {
|
|
5099
5011
|
if (statsBuffer.value) {
|
|
5100
5012
|
clearStatsBuffer();
|
|
5101
5013
|
throw new Error("Stats are already being measured");
|
|
5102
5014
|
}
|
|
5103
|
-
const
|
|
5104
|
-
|
|
5105
|
-
frameloop: {
|
|
5106
|
-
setup: [],
|
|
5107
|
-
rate: [],
|
|
5108
|
-
read: [],
|
|
5109
|
-
resolveKeyframes: [],
|
|
5110
|
-
preUpdate: [],
|
|
5111
|
-
update: [],
|
|
5112
|
-
preRender: [],
|
|
5113
|
-
render: [],
|
|
5114
|
-
postRender: [],
|
|
5115
|
-
},
|
|
5116
|
-
animations: {
|
|
5117
|
-
mainThread: [],
|
|
5118
|
-
waapi: [],
|
|
5119
|
-
layout: [],
|
|
5120
|
-
},
|
|
5015
|
+
const buffer = statsBuffer;
|
|
5016
|
+
buffer.value = {
|
|
5121
5017
|
layoutProjection: {
|
|
5122
5018
|
nodes: [],
|
|
5123
5019
|
calculatedTargetDeltas: [],
|
|
5124
5020
|
calculatedProjections: [],
|
|
5125
5021
|
},
|
|
5126
5022
|
};
|
|
5127
|
-
|
|
5128
|
-
const { layoutProjection } =
|
|
5023
|
+
buffer.addProjectionMetrics = (metrics) => {
|
|
5024
|
+
const { layoutProjection } = buffer.value;
|
|
5129
5025
|
layoutProjection.nodes.push(metrics.nodes);
|
|
5130
5026
|
layoutProjection.calculatedTargetDeltas.push(metrics.calculatedTargetDeltas);
|
|
5131
5027
|
layoutProjection.calculatedProjections.push(metrics.calculatedProjections);
|
|
5132
5028
|
};
|
|
5133
|
-
frame.postRender(record, true);
|
|
5134
|
-
return reportStats;
|
|
5135
5029
|
}
|
|
5136
5030
|
|
|
5137
5031
|
/**
|
|
@@ -5417,14 +5311,126 @@
|
|
|
5417
5311
|
*/
|
|
5418
5312
|
const findValueType = (v) => valueTypes.find(testValueType(v));
|
|
5419
5313
|
|
|
5314
|
+
let nameCount = 0;
|
|
5315
|
+
/**
|
|
5316
|
+
* Generated names live in their own namespace so we can tell a name we own
|
|
5317
|
+
* (and must clean up) from an author-defined one - and so a stale generated
|
|
5318
|
+
* name left behind by an interrupted transition is re-owned, not mistaken for
|
|
5319
|
+
* the author's and leaked.
|
|
5320
|
+
*/
|
|
5321
|
+
const generatedName = () => `motion-view-${nameCount++}`;
|
|
5322
|
+
const isGeneratedName = (name) => name.startsWith("motion-view-");
|
|
5323
|
+
/**
|
|
5324
|
+
* Tag a captured element with a `view-transition-class` so authors can target
|
|
5325
|
+
* its generated layer from CSS (e.g. `::view-transition-group(.hero)`) without
|
|
5326
|
+
* the opaque generated name. Tracked in `classed` - separate from the generated
|
|
5327
|
+
* names in `assigned` - so cleanup removes the class without ever stripping an
|
|
5328
|
+
* author's own inline `view-transition-name`.
|
|
5329
|
+
*/
|
|
5330
|
+
function tagClass(element, className, classed) {
|
|
5331
|
+
if (!className)
|
|
5332
|
+
return;
|
|
5333
|
+
element.style?.setProperty("view-transition-class", className);
|
|
5334
|
+
classed.push(element);
|
|
5335
|
+
}
|
|
5336
|
+
/**
|
|
5337
|
+
* Resolve a selector/Element to elements and ensure each one carries a
|
|
5338
|
+
* `view-transition-name` we can target from script.
|
|
5339
|
+
*
|
|
5340
|
+
* Author-defined names are reused as-is. Elements that are unnamed (or use
|
|
5341
|
+
* the browser's `auto`/`match-element`, whose generated name is not exposed
|
|
5342
|
+
* to script) are given a unique generated name, set inline so it's captured,
|
|
5343
|
+
* and tracked in `assigned` for later cleanup.
|
|
5344
|
+
*
|
|
5345
|
+
* `registry` maps each Element to its name so the same element keeps its name
|
|
5346
|
+
* across both captures (before and after the update), which is what allows a
|
|
5347
|
+
* persistent element to animate as a single `group` layer.
|
|
5348
|
+
*/
|
|
5349
|
+
function assignViewTransitionNames(definition, registry, assigned, forcedNames, className, classed = []) {
|
|
5350
|
+
const elements = resolveElements(definition);
|
|
5351
|
+
/**
|
|
5352
|
+
* The new end of a paired morph: give each element the matching name from
|
|
5353
|
+
* the old end (by index) so the two share one layer and morph. If the new
|
|
5354
|
+
* end resolves to *more* elements than the old end named, the extras have no
|
|
5355
|
+
* counterpart - give them a fresh name so they animate as newcomers rather
|
|
5356
|
+
* than being silently left unnamed. We return the names actually assigned
|
|
5357
|
+
* (sized to the resolved elements), not the raw `forcedNames`, so stagger
|
|
5358
|
+
* totals and the layer set stay in step with what's on the page.
|
|
5359
|
+
*/
|
|
5360
|
+
if (forcedNames) {
|
|
5361
|
+
return elements.map((element, i) => {
|
|
5362
|
+
const existing = registry.get(element);
|
|
5363
|
+
if (existing)
|
|
5364
|
+
return existing;
|
|
5365
|
+
const name = forcedNames[i] ?? generatedName();
|
|
5366
|
+
element.style?.setProperty("view-transition-name", name);
|
|
5367
|
+
assigned.push(element);
|
|
5368
|
+
registry.set(element, name);
|
|
5369
|
+
tagClass(element, className, classed);
|
|
5370
|
+
return name;
|
|
5371
|
+
});
|
|
5372
|
+
}
|
|
5373
|
+
/**
|
|
5374
|
+
* Read every current name up front, before assigning any. Interleaving the
|
|
5375
|
+
* reads with the inline `setProperty` writes below would dirty styles
|
|
5376
|
+
* between reads and force a style recalc per element; batching the reads
|
|
5377
|
+
* keeps it to one. Elements already in the registry keep their name and
|
|
5378
|
+
* need no read.
|
|
5379
|
+
*/
|
|
5380
|
+
const currentNames = elements.map((element) => registry.has(element)
|
|
5381
|
+
? undefined
|
|
5382
|
+
: getComputedStyle(element).getPropertyValue("view-transition-name"));
|
|
5383
|
+
return elements.map((element, i) => {
|
|
5384
|
+
const existing = registry.get(element);
|
|
5385
|
+
if (existing)
|
|
5386
|
+
return existing;
|
|
5387
|
+
const current = currentNames[i];
|
|
5388
|
+
let name;
|
|
5389
|
+
if (current &&
|
|
5390
|
+
current !== "none" &&
|
|
5391
|
+
current !== "auto" &&
|
|
5392
|
+
current !== "match-element" &&
|
|
5393
|
+
!isGeneratedName(current)) {
|
|
5394
|
+
/**
|
|
5395
|
+
* The author already named this layer - target it as-is and leave
|
|
5396
|
+
* it to them to clean up. `auto`/`match-element` are overridden
|
|
5397
|
+
* because their generated name is not exposed to script, and a
|
|
5398
|
+
* stale `motion-view-*` (e.g. left by an interrupted transition) is
|
|
5399
|
+
* re-owned rather than adopted as an author name and leaked.
|
|
5400
|
+
*/
|
|
5401
|
+
name = current;
|
|
5402
|
+
}
|
|
5403
|
+
else {
|
|
5404
|
+
name = generatedName();
|
|
5405
|
+
element.style?.setProperty("view-transition-name", name);
|
|
5406
|
+
assigned.push(element);
|
|
5407
|
+
}
|
|
5408
|
+
registry.set(element, name);
|
|
5409
|
+
tagClass(element, className, classed);
|
|
5410
|
+
return name;
|
|
5411
|
+
});
|
|
5412
|
+
}
|
|
5413
|
+
/**
|
|
5414
|
+
* Remove the `view-transition-name`s we generated and the
|
|
5415
|
+
* `view-transition-class`es we applied. Author-defined names are never touched
|
|
5416
|
+
* (they're not in `assigned`). Safe to call more than once (e.g. on both a
|
|
5417
|
+
* finished and an interrupted transition).
|
|
5418
|
+
*/
|
|
5419
|
+
function releaseViewTransitionNames(assigned, classed = []) {
|
|
5420
|
+
for (const element of assigned) {
|
|
5421
|
+
element.style?.removeProperty("view-transition-name");
|
|
5422
|
+
}
|
|
5423
|
+
for (const element of classed) {
|
|
5424
|
+
element.style?.removeProperty("view-transition-class");
|
|
5425
|
+
}
|
|
5426
|
+
}
|
|
5427
|
+
|
|
5420
5428
|
function chooseLayerType(valueName) {
|
|
5421
5429
|
if (valueName === "layout")
|
|
5422
5430
|
return "group";
|
|
5423
5431
|
if (valueName === "enter" || valueName === "new")
|
|
5424
5432
|
return "new";
|
|
5425
|
-
|
|
5426
|
-
return "old";
|
|
5427
|
-
return "group";
|
|
5433
|
+
return "old";
|
|
5428
5434
|
}
|
|
5429
5435
|
|
|
5430
5436
|
let pendingRules = {};
|
|
@@ -5459,21 +5465,21 @@
|
|
|
5459
5465
|
};
|
|
5460
5466
|
|
|
5461
5467
|
function getViewAnimationLayerInfo(pseudoElement) {
|
|
5462
|
-
const match = pseudoElement.match(
|
|
5468
|
+
const match = pseudoElement.match(
|
|
5469
|
+
// `group-children` (nested transitions) before `group` so it wins.
|
|
5470
|
+
/::view-transition-(old|new|group-children|group|image-pair)\((.*?)\)/);
|
|
5463
5471
|
if (!match)
|
|
5464
5472
|
return null;
|
|
5465
5473
|
return { layer: match[2], type: match[1] };
|
|
5466
5474
|
}
|
|
5467
5475
|
|
|
5468
|
-
function filterViewAnimations(animation) {
|
|
5469
|
-
const { effect } = animation;
|
|
5470
|
-
if (!effect)
|
|
5471
|
-
return false;
|
|
5472
|
-
return (effect.target === document.documentElement &&
|
|
5473
|
-
effect.pseudoElement?.startsWith("::view-transition"));
|
|
5474
|
-
}
|
|
5475
5476
|
function getViewAnimations() {
|
|
5476
|
-
return document.getAnimations().filter(
|
|
5477
|
+
return document.getAnimations().filter((animation) => {
|
|
5478
|
+
const { effect } = animation;
|
|
5479
|
+
return (!!effect &&
|
|
5480
|
+
effect.target === document.documentElement &&
|
|
5481
|
+
effect.pseudoElement?.startsWith("::view-transition"));
|
|
5482
|
+
});
|
|
5477
5483
|
}
|
|
5478
5484
|
|
|
5479
5485
|
function hasTarget(target, targets) {
|
|
@@ -5481,87 +5487,370 @@
|
|
|
5481
5487
|
}
|
|
5482
5488
|
|
|
5483
5489
|
const definitionNames = ["layout", "enter", "exit", "new", "old"];
|
|
5490
|
+
/**
|
|
5491
|
+
* The `ViewTransitionTarget` buckets driving each generated layer type, in
|
|
5492
|
+
* priority order - the inverse of `chooseLayerType`. The new view is driven by
|
|
5493
|
+
* `new`/`enter`, the old by `old`/`exit`. `group-children`/`image-pair` have no
|
|
5494
|
+
* bucket; they follow the default layout timing.
|
|
5495
|
+
*/
|
|
5496
|
+
const typeBuckets = {
|
|
5497
|
+
group: ["layout"],
|
|
5498
|
+
new: ["new", "enter"],
|
|
5499
|
+
old: ["old", "exit"],
|
|
5500
|
+
};
|
|
5501
|
+
/**
|
|
5502
|
+
* Default "absent" origin for a single-value keyframe, by pseudo type, so e.g.
|
|
5503
|
+
* `enter({ scale: 1 })` grows in from 0.85 and `exit({ opacity: 0 })` fades
|
|
5504
|
+
* from 1. `enter` prefers the matching `exit` value over these (see below).
|
|
5505
|
+
*/
|
|
5506
|
+
const ORIGIN_DEFAULTS = {
|
|
5507
|
+
new: { opacity: 0, scale: 0.85 },
|
|
5508
|
+
old: { opacity: 1, scale: 1 },
|
|
5509
|
+
};
|
|
5510
|
+
const cornerProps = [
|
|
5511
|
+
"borderTopLeftRadius",
|
|
5512
|
+
"borderTopRightRadius",
|
|
5513
|
+
"borderBottomRightRadius",
|
|
5514
|
+
"borderBottomLeftRadius",
|
|
5515
|
+
];
|
|
5484
5516
|
function startViewAnimation(builder) {
|
|
5485
|
-
const { update, targets, options: defaultOptions } = builder;
|
|
5517
|
+
const { update, targets, resolveDefs, noCrop, pairs, classNames, options: defaultOptions, } = builder;
|
|
5486
5518
|
if (!document.startViewTransition) {
|
|
5487
|
-
|
|
5519
|
+
// An async IIFE (not `new Promise(async …)`) so a throwing/rejecting
|
|
5520
|
+
// update rejects this promise rather than leaving it unsettled.
|
|
5521
|
+
return (async () => {
|
|
5488
5522
|
await update();
|
|
5489
|
-
|
|
5490
|
-
});
|
|
5523
|
+
return new GroupAnimation([]);
|
|
5524
|
+
})();
|
|
5491
5525
|
}
|
|
5492
|
-
// TODO: Go over existing targets and ensure they all have ids
|
|
5493
5526
|
/**
|
|
5494
|
-
*
|
|
5495
|
-
*
|
|
5527
|
+
* Resolve any selector/Element targets to layer names, assigning a
|
|
5528
|
+
* `view-transition-name` to each element as we go. We run this before the
|
|
5529
|
+
* update (so the elements are captured in the old snapshot) and again
|
|
5530
|
+
* after it (for the new snapshot). An element present in both keeps the
|
|
5531
|
+
* same name and animates as a single `group` layer.
|
|
5532
|
+
*/
|
|
5533
|
+
const nameRegistry = new Map();
|
|
5534
|
+
const assigned = [];
|
|
5535
|
+
/**
|
|
5536
|
+
* Elements we tagged with a `view-transition-class` (via `.class()`),
|
|
5537
|
+
* tracked separately from `assigned` so cleanup removes the class without
|
|
5538
|
+
* ever stripping an author's own inline `view-transition-name`.
|
|
5496
5539
|
*/
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5540
|
+
const classed = [];
|
|
5541
|
+
const layerTargets = new Map();
|
|
5542
|
+
const croppedNames = new Set();
|
|
5543
|
+
/**
|
|
5544
|
+
* Each layer's stagger position (index + total) within its subject, per
|
|
5545
|
+
* snapshot. Resolving against the snapshot the layer belongs to keeps
|
|
5546
|
+
* stagger correct when `update()` replaces the matched elements, and lets
|
|
5547
|
+
* us skip a layer that's absent from a snapshot (e.g. an exited element
|
|
5548
|
+
* has no `new` pseudo-element).
|
|
5549
|
+
*/
|
|
5550
|
+
const layerStagger = new Map();
|
|
5551
|
+
/**
|
|
5552
|
+
* Names allocated for a paired subject in the old snapshot, replayed onto
|
|
5553
|
+
* its new-snapshot target so both ends share a layer and morph.
|
|
5554
|
+
*/
|
|
5555
|
+
const pairNames = new Map();
|
|
5556
|
+
/**
|
|
5557
|
+
* The old (`from`) elements of each paired subject, so their names can be
|
|
5558
|
+
* transferred off before the new (`to`) elements inherit them.
|
|
5559
|
+
*/
|
|
5560
|
+
const pairFrom = new Map();
|
|
5561
|
+
const resolveLayers = (phase) => {
|
|
5562
|
+
targets.forEach((target, definition) => {
|
|
5563
|
+
const className = classNames.get(definition);
|
|
5564
|
+
let names;
|
|
5565
|
+
if (definition === "root" || !resolveDefs.has(definition)) {
|
|
5566
|
+
names = [definition];
|
|
5567
|
+
}
|
|
5568
|
+
else if (pairs.has(definition)) {
|
|
5569
|
+
/**
|
|
5570
|
+
* Paired morph: name the old target in the old snapshot, then
|
|
5571
|
+
* force the same name(s) onto the new target in the new one, so
|
|
5572
|
+
* two different elements morph as a single layer.
|
|
5573
|
+
*/
|
|
5574
|
+
if (phase === "old") {
|
|
5575
|
+
pairFrom.set(definition, resolveElements(definition));
|
|
5576
|
+
names = assignViewTransitionNames(definition, nameRegistry, assigned, undefined, className, classed);
|
|
5577
|
+
pairNames.set(definition, names);
|
|
5578
|
+
}
|
|
5579
|
+
else {
|
|
5580
|
+
/**
|
|
5581
|
+
* Transfer the name(s) off the `from` elements before the
|
|
5582
|
+
* `to` elements inherit them. A `from` that survives into
|
|
5583
|
+
* the new snapshot (e.g. hidden with `visibility: hidden`
|
|
5584
|
+
* rather than removed) would otherwise keep the name and
|
|
5585
|
+
* collide - "duplicate view-transition-name".
|
|
5586
|
+
*/
|
|
5587
|
+
for (const el of pairFrom.get(definition) ?? []) {
|
|
5588
|
+
el.style?.removeProperty("view-transition-name");
|
|
5589
|
+
/**
|
|
5590
|
+
* Drop the old end from the registry too, so the new
|
|
5591
|
+
* end alone supplies this name's `new` crop radii - we
|
|
5592
|
+
* neither re-measure nor get ordered by a stale element.
|
|
5593
|
+
*/
|
|
5594
|
+
nameRegistry.delete(el);
|
|
5595
|
+
}
|
|
5596
|
+
names = assignViewTransitionNames(pairs.get(definition), nameRegistry, assigned, pairNames.get(definition), className, classed);
|
|
5597
|
+
}
|
|
5598
|
+
}
|
|
5599
|
+
else {
|
|
5600
|
+
names = assignViewTransitionNames(definition, nameRegistry, assigned, undefined, className, classed);
|
|
5601
|
+
}
|
|
5602
|
+
const cropped = definition !== "root" && !noCrop.has(definition);
|
|
5603
|
+
names.forEach((name, index) => {
|
|
5604
|
+
/**
|
|
5605
|
+
* If two subjects resolve to the same element, merge their
|
|
5606
|
+
* definitions so neither subject's animations are dropped.
|
|
5607
|
+
*/
|
|
5608
|
+
const existing = layerTargets.get(name);
|
|
5609
|
+
layerTargets.set(name, existing && existing !== target
|
|
5610
|
+
? { ...existing, ...target }
|
|
5611
|
+
: target);
|
|
5612
|
+
if (cropped)
|
|
5613
|
+
croppedNames.add(name);
|
|
5614
|
+
const stagger = layerStagger.get(name) ?? {};
|
|
5615
|
+
stagger[phase] = [index, names.length];
|
|
5616
|
+
layerStagger.set(name, stagger);
|
|
5617
|
+
});
|
|
5500
5618
|
});
|
|
5501
|
-
}
|
|
5619
|
+
};
|
|
5620
|
+
/**
|
|
5621
|
+
* The stagger index/total for a layer, resolved against the snapshot it
|
|
5622
|
+
* belongs to. Returns index -1 when the layer is absent from that snapshot
|
|
5623
|
+
* so the caller can skip a pseudo-element that doesn't exist.
|
|
5624
|
+
*/
|
|
5625
|
+
const staggerPosition = (name, type) => {
|
|
5626
|
+
const stagger = layerStagger.get(name);
|
|
5627
|
+
const position = type === "old"
|
|
5628
|
+
? stagger?.old
|
|
5629
|
+
: type === "new"
|
|
5630
|
+
? stagger?.new
|
|
5631
|
+
: // group / group-children / image-pair persist across both.
|
|
5632
|
+
stagger?.new ?? stagger?.old;
|
|
5633
|
+
return position ?? [-1, 1];
|
|
5634
|
+
};
|
|
5635
|
+
/**
|
|
5636
|
+
* Merge default + per-layer transition options for a generated layer and
|
|
5637
|
+
* resolve any stagger/delay function against this element's position. Used
|
|
5638
|
+
* by both the morph-retiming and crop corner-radius passes.
|
|
5639
|
+
*/
|
|
5640
|
+
const resolveLayerTransition = (target, type, transitionName, index, total) => {
|
|
5641
|
+
const transition = mergeTransition(getValueTransition(defaultOptions, transitionName), getValueTransition((layerOptions(target, type) ?? {}), transitionName));
|
|
5642
|
+
if (typeof transition.delay === "function") {
|
|
5643
|
+
transition.delay = transition.delay(index, total);
|
|
5644
|
+
}
|
|
5645
|
+
return transition;
|
|
5646
|
+
};
|
|
5647
|
+
/**
|
|
5648
|
+
* Measured corner radii per cropped layer, so the clip can animate each
|
|
5649
|
+
* corner between the old and new elements. Per-corner (rather than the
|
|
5650
|
+
* shorthand) so mismatched/individual radii interpolate cleanly.
|
|
5651
|
+
*/
|
|
5652
|
+
const cropRadii = new Map();
|
|
5653
|
+
const recordRadii = (style, name, phase) => {
|
|
5654
|
+
const corners = {};
|
|
5655
|
+
for (const corner of cornerProps)
|
|
5656
|
+
corners[corner] = style[corner];
|
|
5657
|
+
const entry = cropRadii.get(name) ?? {};
|
|
5658
|
+
entry[phase] = corners;
|
|
5659
|
+
cropRadii.set(name, entry);
|
|
5660
|
+
};
|
|
5661
|
+
/**
|
|
5662
|
+
* Cropped layers all come from `.add()`, so their elements are in the
|
|
5663
|
+
* registry - read each one's corner radii directly. For a paired morph both
|
|
5664
|
+
* ends share a name; the new-snapshot element is registered last, so it
|
|
5665
|
+
* wins the `new` reading (and the old end the `old` reading).
|
|
5666
|
+
*/
|
|
5667
|
+
const measureCrop = (phase) => {
|
|
5668
|
+
if (!croppedNames.size)
|
|
5669
|
+
return;
|
|
5670
|
+
nameRegistry.forEach((name, element) => {
|
|
5671
|
+
if (croppedNames.has(name)) {
|
|
5672
|
+
recordRadii(getComputedStyle(element), name, phase);
|
|
5673
|
+
}
|
|
5674
|
+
});
|
|
5675
|
+
};
|
|
5502
5676
|
/**
|
|
5503
|
-
*
|
|
5504
|
-
*
|
|
5505
|
-
*
|
|
5677
|
+
* Write the persistent view-transition CSS: suppress root capture when the
|
|
5678
|
+
* root has no animations of its own; force linear timing (baked into the
|
|
5679
|
+
* keyframes, so we can retime later via updateTiming); and clip +
|
|
5680
|
+
* object-fit: cover every cropped morph (the UA default overflows on
|
|
5681
|
+
* aspect-ratio change), with an animated border-radius added below.
|
|
5506
5682
|
*
|
|
5507
|
-
*
|
|
5683
|
+
* `css.commit` replaces rather than appends, so we re-set the full rule set
|
|
5684
|
+
* each call - the second call (in the update callback) then picks up cropped
|
|
5685
|
+
* layers that only exist in the new snapshot.
|
|
5508
5686
|
*/
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5687
|
+
const commitViewCSS = () => {
|
|
5688
|
+
if (!hasTarget("root", targets)) {
|
|
5689
|
+
css.set(":root", { "view-transition-name": "none" });
|
|
5690
|
+
}
|
|
5691
|
+
css.set("::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*)", { "animation-timing-function": "linear !important" });
|
|
5692
|
+
croppedNames.forEach((name) => {
|
|
5693
|
+
css.set(`::view-transition-group(${name})`, { overflow: "clip" });
|
|
5694
|
+
css.set(`::view-transition-old(${name}), ::view-transition-new(${name})`, { width: "100%", height: "100%", "object-fit": "cover" });
|
|
5695
|
+
});
|
|
5696
|
+
css.commit(); // Write
|
|
5697
|
+
};
|
|
5698
|
+
const cleanup = () => {
|
|
5699
|
+
releaseViewTransitionNames(assigned, classed);
|
|
5516
5700
|
css.remove(); // Write
|
|
5517
|
-
}
|
|
5518
|
-
|
|
5519
|
-
|
|
5701
|
+
};
|
|
5702
|
+
const callback = async () => {
|
|
5703
|
+
await update();
|
|
5704
|
+
/**
|
|
5705
|
+
* Re-resolve so elements created by the update are named for the new
|
|
5706
|
+
* snapshot, then measure the cropped layers' new border-radius.
|
|
5707
|
+
*/
|
|
5708
|
+
const croppedBefore = croppedNames.size;
|
|
5709
|
+
resolveLayers("new");
|
|
5710
|
+
measureCrop("new");
|
|
5711
|
+
/**
|
|
5712
|
+
* Re-commit the crop CSS only if the new snapshot introduced cropped
|
|
5713
|
+
* layers, so a layer that exists only in the new snapshot is clipped
|
|
5714
|
+
* too - without forcing a redundant style write on the common path.
|
|
5715
|
+
*/
|
|
5716
|
+
if (croppedNames.size > croppedBefore)
|
|
5717
|
+
commitViewCSS();
|
|
5718
|
+
};
|
|
5719
|
+
let transition;
|
|
5720
|
+
try {
|
|
5721
|
+
resolveLayers("old");
|
|
5722
|
+
measureCrop("old");
|
|
5723
|
+
commitViewCSS();
|
|
5724
|
+
transition = document.startViewTransition(callback);
|
|
5725
|
+
}
|
|
5726
|
+
catch (error) {
|
|
5727
|
+
/**
|
|
5728
|
+
* The prelude writes inline names before the transition exists. If it
|
|
5729
|
+
* throws (e.g. startViewTransition rejects in a bad UA state), release
|
|
5730
|
+
* them so we neither leak DOM state nor stall the queue on a promise
|
|
5731
|
+
* that never settles - hand back a rejection it can advance past.
|
|
5732
|
+
*/
|
|
5733
|
+
cleanup();
|
|
5734
|
+
return Promise.reject(error);
|
|
5735
|
+
}
|
|
5736
|
+
transition.finished.finally(cleanup);
|
|
5737
|
+
return new Promise((resolve, reject) => {
|
|
5738
|
+
transition.ready
|
|
5739
|
+
.then(() => {
|
|
5520
5740
|
const generatedViewAnimations = getViewAnimations();
|
|
5521
5741
|
const animations = [];
|
|
5522
5742
|
/**
|
|
5523
5743
|
* Create animations for each of our explicitly-defined subjects.
|
|
5744
|
+
* `opacityAnimated` additionally tracks which `${name}:${type}`
|
|
5745
|
+
* we faded, so we can keep the UA `plus-lighter` blend only for a
|
|
5746
|
+
* genuine opacity crossfade (both sides fading) and drop it for a
|
|
5747
|
+
* slide/transform, where additive compositing would flash bright.
|
|
5524
5748
|
*/
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5749
|
+
const explicitlyAnimated = new Set();
|
|
5750
|
+
const opacityAnimated = new Set();
|
|
5751
|
+
layerTargets.forEach((target, name) => {
|
|
5752
|
+
const stagger = layerStagger.get(name);
|
|
5753
|
+
/**
|
|
5754
|
+
* Presence: `enter` only fires for a pure newcomer (a new
|
|
5755
|
+
* view with no old), `exit` only for a pure leaver. A
|
|
5756
|
+
* survivor (both) gets neither - it just morphs.
|
|
5757
|
+
*/
|
|
5758
|
+
const enterApplies = !!stagger?.new && !stagger?.old;
|
|
5759
|
+
const exitApplies = !!stagger?.old && !stagger?.new;
|
|
5528
5760
|
for (const key of definitionNames) {
|
|
5529
|
-
if (!
|
|
5761
|
+
if (!target[key])
|
|
5762
|
+
continue;
|
|
5763
|
+
if (key === "enter" && !enterApplies)
|
|
5764
|
+
continue;
|
|
5765
|
+
if (key === "exit" && !exitApplies)
|
|
5766
|
+
continue;
|
|
5767
|
+
const type = chooseLayerType(key);
|
|
5768
|
+
const [index, total] = staggerPosition(name, type);
|
|
5769
|
+
// Skip a layer absent from its snapshot.
|
|
5770
|
+
if (index === -1)
|
|
5530
5771
|
continue;
|
|
5531
|
-
const { keyframes, options } =
|
|
5772
|
+
const { keyframes, options } = target[key];
|
|
5532
5773
|
for (let [valueName, valueKeyframes] of Object.entries(keyframes)) {
|
|
5533
|
-
|
|
5774
|
+
// Skip only missing values - `0` (e.g. opacity: 0)
|
|
5775
|
+
// is valid and must reach the from-value inference.
|
|
5776
|
+
if (valueKeyframes == null)
|
|
5534
5777
|
continue;
|
|
5535
|
-
const valueOptions = {
|
|
5536
|
-
...getValueTransition(defaultOptions, valueName),
|
|
5537
|
-
...getValueTransition(options, valueName),
|
|
5538
|
-
};
|
|
5539
|
-
const type = chooseLayerType(key);
|
|
5540
5778
|
/**
|
|
5541
|
-
*
|
|
5542
|
-
*
|
|
5779
|
+
* The view path hands keyframes straight to WAAPI,
|
|
5780
|
+
* so Motion's `x`/`y` shorthands (compiled to
|
|
5781
|
+
* `transform` only via the value pipeline) have no
|
|
5782
|
+
* effect. Warn and skip - use `transform`/`translate`.
|
|
5783
|
+
*/
|
|
5784
|
+
if (valueName === "x" || valueName === "y") {
|
|
5785
|
+
motionUtils.warnOnce(false, `animateView() animates view-transition layers with CSS properties; the "${valueName}" shorthand has no effect - use transform, e.g. { transform: "translateX(40px)" }.`);
|
|
5786
|
+
continue;
|
|
5787
|
+
}
|
|
5788
|
+
/**
|
|
5789
|
+
* enter/exit win over new/old on a shared property -
|
|
5790
|
+
* skip it here when the gated bucket also defines it.
|
|
5791
|
+
*/
|
|
5792
|
+
if (key === "new" &&
|
|
5793
|
+
enterApplies &&
|
|
5794
|
+
target.enter?.keyframes[valueName] != null) {
|
|
5795
|
+
continue;
|
|
5796
|
+
}
|
|
5797
|
+
if (key === "old" &&
|
|
5798
|
+
exitApplies &&
|
|
5799
|
+
target.exit?.keyframes[valueName] != null) {
|
|
5800
|
+
continue;
|
|
5801
|
+
}
|
|
5802
|
+
const valueOptions = mergeTransition(getValueTransition(defaultOptions, valueName), getValueTransition(options, valueName));
|
|
5803
|
+
/**
|
|
5804
|
+
* Infer an origin for a single-value keyframe. An
|
|
5805
|
+
* `enter` mirrors the matching `exit` value (a
|
|
5806
|
+
* defined exit reverses into the enter for free);
|
|
5807
|
+
* otherwise the per-type default (opacity 0/1, scale
|
|
5808
|
+
* 0.85). No default -> left as-is (animates from the
|
|
5809
|
+
* live value).
|
|
5810
|
+
*
|
|
5811
|
+
* `new`/`old` fire for survivors too, where only the
|
|
5812
|
+
* opacity crossfade default applies - a transform
|
|
5813
|
+
* default like scale 0.85 would pop a persisting
|
|
5814
|
+
* element, so gate it on the layer actually
|
|
5815
|
+
* entering/leaving.
|
|
5543
5816
|
*/
|
|
5544
|
-
if (
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5817
|
+
if (!Array.isArray(valueKeyframes)) {
|
|
5818
|
+
const exitValue = key === "enter"
|
|
5819
|
+
? target.exit?.keyframes[valueName]
|
|
5820
|
+
: undefined;
|
|
5821
|
+
const allowDefault = valueName === "opacity" ||
|
|
5822
|
+
(type === "new" ? enterApplies : exitApplies);
|
|
5823
|
+
const from = exitValue != null
|
|
5824
|
+
? Array.isArray(exitValue)
|
|
5825
|
+
? exitValue[exitValue.length - 1]
|
|
5826
|
+
: exitValue
|
|
5827
|
+
: allowDefault
|
|
5828
|
+
? ORIGIN_DEFAULTS[type]?.[valueName]
|
|
5829
|
+
: undefined;
|
|
5830
|
+
if (from !== undefined) {
|
|
5831
|
+
valueKeyframes = [from, valueKeyframes];
|
|
5832
|
+
}
|
|
5548
5833
|
}
|
|
5549
5834
|
/**
|
|
5550
|
-
* Resolve stagger function if provided
|
|
5835
|
+
* Resolve stagger function if provided, per element
|
|
5836
|
+
* across this subject's resolved layers.
|
|
5551
5837
|
*/
|
|
5552
5838
|
if (typeof valueOptions.delay === "function") {
|
|
5553
|
-
valueOptions.delay = valueOptions.delay(
|
|
5839
|
+
valueOptions.delay = valueOptions.delay(index, total);
|
|
5554
5840
|
}
|
|
5555
5841
|
valueOptions.duration && (valueOptions.duration = motionUtils.secondsToMilliseconds(valueOptions.duration));
|
|
5556
5842
|
valueOptions.delay && (valueOptions.delay = motionUtils.secondsToMilliseconds(valueOptions.delay));
|
|
5557
|
-
|
|
5843
|
+
animations.push(new NativeAnimation({
|
|
5558
5844
|
...valueOptions,
|
|
5559
5845
|
element: document.documentElement,
|
|
5560
5846
|
name: valueName,
|
|
5561
|
-
pseudoElement: `::view-transition-${type}(${
|
|
5847
|
+
pseudoElement: `::view-transition-${type}(${name})`,
|
|
5562
5848
|
keyframes: valueKeyframes,
|
|
5563
|
-
});
|
|
5564
|
-
|
|
5849
|
+
}));
|
|
5850
|
+
explicitlyAnimated.add(`${name}:${type}`);
|
|
5851
|
+
if (valueName === "opacity") {
|
|
5852
|
+
opacityAnimated.add(`${name}:${type}`);
|
|
5853
|
+
}
|
|
5565
5854
|
}
|
|
5566
5855
|
}
|
|
5567
5856
|
});
|
|
@@ -5580,45 +5869,161 @@
|
|
|
5580
5869
|
const name = getViewAnimationLayerInfo(pseudoElement);
|
|
5581
5870
|
if (!name)
|
|
5582
5871
|
continue;
|
|
5583
|
-
const targetDefinition =
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
}
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
effect
|
|
5608
|
-
.getKeyframes()
|
|
5609
|
-
.some((keyframe) => keyframe.mixBlendMode)) {
|
|
5610
|
-
animations.push(new NativeAnimationWrapper(animation));
|
|
5611
|
-
}
|
|
5612
|
-
else {
|
|
5613
|
-
animation.cancel();
|
|
5872
|
+
const targetDefinition = layerTargets.get(name.layer);
|
|
5873
|
+
/**
|
|
5874
|
+
* We built our own animation for this layer, so drop the
|
|
5875
|
+
* browser-generated fade we're replacing. The UA
|
|
5876
|
+
* `plus-lighter` blend is a *separate* generated animation on
|
|
5877
|
+
* the same pseudo (it sets `mix-blend-mode` in its keyframes):
|
|
5878
|
+
* keep it *only* for a true opacity crossfade - both sides
|
|
5879
|
+
* fading - so a symmetric crossfade composites without
|
|
5880
|
+
* darkening, but a slide/transform (where both layers stay
|
|
5881
|
+
* opaque and overlap) doesn't flash bright from the addition.
|
|
5882
|
+
*/
|
|
5883
|
+
if (explicitlyAnimated.has(`${name.layer}:${name.type}`)) {
|
|
5884
|
+
const isCrossfade = opacityAnimated.has(`${name.layer}:new`) &&
|
|
5885
|
+
opacityAnimated.has(`${name.layer}:old`);
|
|
5886
|
+
if (isCrossfade &&
|
|
5887
|
+
effect
|
|
5888
|
+
.getKeyframes()
|
|
5889
|
+
.some((keyframe) => keyframe.mixBlendMode)) {
|
|
5890
|
+
animations.push(new NativeAnimationWrapper(animation));
|
|
5891
|
+
}
|
|
5892
|
+
else {
|
|
5893
|
+
animation.cancel();
|
|
5894
|
+
}
|
|
5895
|
+
continue;
|
|
5614
5896
|
}
|
|
5897
|
+
/**
|
|
5898
|
+
* Otherwise retime the browser-generated animation to
|
|
5899
|
+
* Motion's timing. This auto-enables the layout (group)
|
|
5900
|
+
* morph for any resolved/named target, and applies the
|
|
5901
|
+
* default timing to old/new layers we haven't explicitly
|
|
5902
|
+
* overridden.
|
|
5903
|
+
*
|
|
5904
|
+
* group + group-children both follow the layout timing so
|
|
5905
|
+
* the nesting container stays in sync with the morph.
|
|
5906
|
+
*/
|
|
5907
|
+
/**
|
|
5908
|
+
* A survivor's old + new are the two halves of one
|
|
5909
|
+
* `plus-lighter` crossfade. They must share identical timing
|
|
5910
|
+
* (so their opacities stay mirrored and sum to 1 - else the
|
|
5911
|
+
* additive blend flashes bright wherever both are partly
|
|
5912
|
+
* visible) and fade linearly (the bounce belongs on the
|
|
5913
|
+
* group's geometry, not the opacity). So time them as the
|
|
5914
|
+
* group, rather than via their own - potentially staggered,
|
|
5915
|
+
* or enter/exit-derived - old/new options.
|
|
5916
|
+
*/
|
|
5917
|
+
const stagger = layerStagger.get(name.layer);
|
|
5918
|
+
const isMorphCrossfade = (name.type === "old" || name.type === "new") &&
|
|
5919
|
+
!!stagger?.old &&
|
|
5920
|
+
!!stagger?.new;
|
|
5921
|
+
const timingType = name.type.startsWith("group") || isMorphCrossfade
|
|
5922
|
+
? "group"
|
|
5923
|
+
: name.type;
|
|
5924
|
+
const [index, total] = staggerPosition(name.layer, timingType);
|
|
5925
|
+
const transitionName = timingType === "group" ? "layout" : "";
|
|
5926
|
+
let animationTransition = resolveLayerTransition(targetDefinition, timingType, transitionName, index === -1 ? 0 : index, total);
|
|
5927
|
+
/**
|
|
5928
|
+
* The crossfade should resolve at the spring's *perceptual*
|
|
5929
|
+
* (visual) duration - the geometry can keep bouncing, but the
|
|
5930
|
+
* opacity shouldn't drag through the settle. So capture
|
|
5931
|
+
* `visualDuration` before `applyGeneratorOptions` replaces it
|
|
5932
|
+
* with the full overshoot duration, and use it for the fade.
|
|
5933
|
+
*/
|
|
5934
|
+
const visualDuration = animationTransition.visualDuration;
|
|
5935
|
+
animationTransition.duration && (animationTransition.duration = motionUtils.secondsToMilliseconds(animationTransition.duration));
|
|
5936
|
+
animationTransition =
|
|
5937
|
+
applyGeneratorOptions(animationTransition);
|
|
5938
|
+
const duration = isMorphCrossfade && visualDuration !== undefined
|
|
5939
|
+
? motionUtils.secondsToMilliseconds(visualDuration)
|
|
5940
|
+
: animationTransition.duration;
|
|
5941
|
+
const easing = isMorphCrossfade
|
|
5942
|
+
? "linear"
|
|
5943
|
+
: mapEasingToNativeEasing(animationTransition.ease, animationTransition.duration);
|
|
5944
|
+
effect.updateTiming({
|
|
5945
|
+
delay: motionUtils.secondsToMilliseconds(animationTransition.delay ?? 0),
|
|
5946
|
+
duration,
|
|
5947
|
+
easing,
|
|
5948
|
+
});
|
|
5949
|
+
animations.push(new NativeAnimationWrapper(animation));
|
|
5615
5950
|
}
|
|
5951
|
+
/**
|
|
5952
|
+
* Animate each cropped layer's clip corners between the old and
|
|
5953
|
+
* new elements, so a cropped morph keeps rounded corners
|
|
5954
|
+
* (handling individual per-corner radii).
|
|
5955
|
+
*/
|
|
5956
|
+
cropRadii.forEach((radii, name) => {
|
|
5957
|
+
if (!radii.old && !radii.new)
|
|
5958
|
+
return;
|
|
5959
|
+
const target = layerTargets.get(name);
|
|
5960
|
+
const [index, total] = staggerPosition(name, "group");
|
|
5961
|
+
const radiusOptions = resolveLayerTransition(target, "group", "layout", index === -1 ? 0 : index, total);
|
|
5962
|
+
radiusOptions.duration && (radiusOptions.duration = motionUtils.secondsToMilliseconds(radiusOptions.duration));
|
|
5963
|
+
radiusOptions.delay && (radiusOptions.delay = motionUtils.secondsToMilliseconds(radiusOptions.delay));
|
|
5964
|
+
for (const corner of cornerProps) {
|
|
5965
|
+
// `||` (not `??`) so an empty measurement (e.g. an
|
|
5966
|
+
// un-rendered element) falls back rather than producing
|
|
5967
|
+
// an invalid keyframe.
|
|
5968
|
+
const from = radii.old?.[corner] || radii.new?.[corner] || "0px";
|
|
5969
|
+
const to = radii.new?.[corner] || radii.old?.[corner] || "0px";
|
|
5970
|
+
// Skip square corners - nothing to round.
|
|
5971
|
+
if (parseFloat(from) === 0 && parseFloat(to) === 0) {
|
|
5972
|
+
continue;
|
|
5973
|
+
}
|
|
5974
|
+
animations.push(new NativeAnimation({
|
|
5975
|
+
...radiusOptions,
|
|
5976
|
+
element: document.documentElement,
|
|
5977
|
+
name: corner,
|
|
5978
|
+
pseudoElement: `::view-transition-group(${name})`,
|
|
5979
|
+
keyframes: [from, to],
|
|
5980
|
+
}));
|
|
5981
|
+
}
|
|
5982
|
+
});
|
|
5616
5983
|
resolve(new GroupAnimation(animations));
|
|
5617
|
-
})
|
|
5984
|
+
})
|
|
5985
|
+
.catch(() =>
|
|
5986
|
+
/**
|
|
5987
|
+
* `ready` rejects when the transition is skipped - no visual
|
|
5988
|
+
* change, or superseded by an interrupting transition. The DOM
|
|
5989
|
+
* update still applied, so settle with no animations rather than
|
|
5990
|
+
* surfacing it as an error to an awaiting caller. A genuine
|
|
5991
|
+
* failure in `update()` rejects `updateCallbackDone` (already
|
|
5992
|
+
* settled by now), so propagate that instead.
|
|
5993
|
+
*/
|
|
5994
|
+
transition.updateCallbackDone.then(() => resolve(new GroupAnimation([])), reject));
|
|
5618
5995
|
});
|
|
5619
5996
|
}
|
|
5620
|
-
|
|
5621
|
-
|
|
5997
|
+
/**
|
|
5998
|
+
* The options that should time a given generated layer type, so a retimed
|
|
5999
|
+
* group/old/new picks up any per-target transition the user provided. Checks
|
|
6000
|
+
* the type's buckets in priority order (e.g. `new` before `enter`).
|
|
6001
|
+
*/
|
|
6002
|
+
function layerOptions(target, type) {
|
|
6003
|
+
for (const bucket of typeBuckets[type] ?? []) {
|
|
6004
|
+
const options = target?.[bucket]?.options;
|
|
6005
|
+
if (options)
|
|
6006
|
+
return options;
|
|
6007
|
+
}
|
|
6008
|
+
}
|
|
6009
|
+
/**
|
|
6010
|
+
* Merge a base transition (e.g. the default `options`) with a per-layer/value
|
|
6011
|
+
* override. An explicit `duration` on the override must win over an inherited
|
|
6012
|
+
* generator's own timing: a spring prefers `visualDuration`, and
|
|
6013
|
+
* `spring.applyToOptions` overwrites `duration` with the computed settle time -
|
|
6014
|
+
* so without this the override is silently discarded. Dropping the inherited
|
|
6015
|
+
* `type`/`visualDuration` makes the layer a plain tween of that duration, unless
|
|
6016
|
+
* it asked for its own generator `type`/`visualDuration`.
|
|
6017
|
+
*/
|
|
6018
|
+
function mergeTransition(base, override) {
|
|
6019
|
+
const merged = { ...base, ...override };
|
|
6020
|
+
if (override.duration !== undefined) {
|
|
6021
|
+
if (override.visualDuration === undefined)
|
|
6022
|
+
delete merged.visualDuration;
|
|
6023
|
+
if (override.type === undefined)
|
|
6024
|
+
delete merged.type;
|
|
6025
|
+
}
|
|
6026
|
+
return merged;
|
|
5622
6027
|
}
|
|
5623
6028
|
|
|
5624
6029
|
let builders = [];
|
|
@@ -5632,10 +6037,16 @@
|
|
|
5632
6037
|
function start(builder) {
|
|
5633
6038
|
motionUtils.removeItem(builders, builder);
|
|
5634
6039
|
current = builder;
|
|
5635
|
-
startViewAnimation(builder)
|
|
6040
|
+
startViewAnimation(builder)
|
|
6041
|
+
.then((animation) => {
|
|
5636
6042
|
builder.notifyReady(animation);
|
|
5637
|
-
animation.finished
|
|
5638
|
-
})
|
|
6043
|
+
return animation.finished;
|
|
6044
|
+
})
|
|
6045
|
+
// A genuinely failed transition (a throwing update) rejects the
|
|
6046
|
+
// builder; a skipped/interrupted one resolves with no animations (see
|
|
6047
|
+
// start.ts). Either way, advance the queue - else later transitions hang.
|
|
6048
|
+
.catch((error) => builder.notifyReject(error))
|
|
6049
|
+
.finally(next);
|
|
5639
6050
|
}
|
|
5640
6051
|
function processQueue() {
|
|
5641
6052
|
/**
|
|
@@ -5672,31 +6083,96 @@
|
|
|
5672
6083
|
constructor(update, options = {}) {
|
|
5673
6084
|
this.currentSubject = "root";
|
|
5674
6085
|
this.targets = new Map();
|
|
6086
|
+
/**
|
|
6087
|
+
* Definitions that must be resolved to elements (and assigned a
|
|
6088
|
+
* `view-transition-name`) rather than treated as pre-named layers.
|
|
6089
|
+
*/
|
|
6090
|
+
this.resolveDefs = new Set();
|
|
6091
|
+
/**
|
|
6092
|
+
* Subjects opted out of the default crop (clip + object-fit: cover +
|
|
6093
|
+
* animated corner radii) via `.crop(false)`.
|
|
6094
|
+
*/
|
|
6095
|
+
this.noCrop = new Set();
|
|
6096
|
+
/**
|
|
6097
|
+
* Subjects paired with a different new-snapshot target (the second `.add()`
|
|
6098
|
+
* argument), so two distinct elements share one name and morph into each
|
|
6099
|
+
* other - a shared-element transition.
|
|
6100
|
+
*/
|
|
6101
|
+
this.pairs = new Map();
|
|
6102
|
+
/**
|
|
6103
|
+
* A `view-transition-class` to apply to each subject's resolved elements,
|
|
6104
|
+
* so authors can target the generated layers from CSS by class rather than
|
|
6105
|
+
* the opaque generated name.
|
|
6106
|
+
*/
|
|
6107
|
+
this.classNames = new Map();
|
|
5675
6108
|
this.notifyReady = motionUtils.noop;
|
|
5676
|
-
this.
|
|
6109
|
+
this.notifyReject = motionUtils.noop;
|
|
6110
|
+
this.readyPromise = new Promise((resolve, reject) => {
|
|
5677
6111
|
this.notifyReady = resolve;
|
|
6112
|
+
this.notifyReject = reject;
|
|
5678
6113
|
});
|
|
5679
6114
|
this.update = update;
|
|
5680
6115
|
this.options = {
|
|
5681
6116
|
interrupt: "wait",
|
|
5682
6117
|
...options,
|
|
5683
6118
|
};
|
|
6119
|
+
// Avoid an unhandled rejection when a failed transition has no
|
|
6120
|
+
// `.then(_, reject)` handler attached (e.g. fire-and-forget).
|
|
6121
|
+
this.readyPromise.catch(motionUtils.noop);
|
|
5684
6122
|
addToQueue(this);
|
|
5685
6123
|
}
|
|
5686
|
-
|
|
6124
|
+
/**
|
|
6125
|
+
* Target elements resolved from a selector or Element, each assigned a
|
|
6126
|
+
* `view-transition-name` automatically.
|
|
6127
|
+
*
|
|
6128
|
+
* Passing a second target pairs them: the first is resolved in the old
|
|
6129
|
+
* snapshot and the second in the new, sharing one name so two *different*
|
|
6130
|
+
* elements morph into each other (e.g. `.add(card, ".modal")`). Symmetric -
|
|
6131
|
+
* pass them the other way round to morph back.
|
|
6132
|
+
*/
|
|
6133
|
+
add(subject, newSubject) {
|
|
5687
6134
|
this.currentSubject = subject;
|
|
6135
|
+
this.resolveDefs.add(subject);
|
|
6136
|
+
if (newSubject !== undefined)
|
|
6137
|
+
this.pairs.set(subject, newSubject);
|
|
6138
|
+
// Register the subject so it participates (and gets an automatic
|
|
6139
|
+
// layout/morph animation) even without an explicit enter/exit/layout.
|
|
6140
|
+
if (!this.targets.has(subject))
|
|
6141
|
+
this.targets.set(subject, {});
|
|
5688
6142
|
return this;
|
|
5689
6143
|
}
|
|
5690
|
-
|
|
5691
|
-
|
|
6144
|
+
/**
|
|
6145
|
+
* Morphs are clipped + `object-fit: cover` (and their corners animate)
|
|
6146
|
+
* by default. Call `.crop(false)` to opt this subject out and fall back
|
|
6147
|
+
* to the browser default (which overflows on aspect-ratio change).
|
|
6148
|
+
*/
|
|
6149
|
+
crop(enabled = true) {
|
|
6150
|
+
enabled
|
|
6151
|
+
? this.noCrop.delete(this.currentSubject)
|
|
6152
|
+
: this.noCrop.add(this.currentSubject);
|
|
5692
6153
|
return this;
|
|
5693
6154
|
}
|
|
5694
|
-
|
|
5695
|
-
|
|
6155
|
+
/**
|
|
6156
|
+
* Tag this subject's generated layers with a `view-transition-class`, so
|
|
6157
|
+
* they can be targeted from CSS - `::view-transition-group(.name)`,
|
|
6158
|
+
* `::view-transition-old/new(.name)`, `::view-transition-image-pair(.name)`
|
|
6159
|
+
* - without the opaque generated `view-transition-name`. Because `.add()`
|
|
6160
|
+
* can match many elements, a shared class targets them all at once (and,
|
|
6161
|
+
* for a pair, both ends). The escape hatch for z-index / custom keyframes
|
|
6162
|
+
* on a morph layer.
|
|
6163
|
+
*/
|
|
6164
|
+
class(name) {
|
|
6165
|
+
this.classNames.set(this.currentSubject, name);
|
|
5696
6166
|
return this;
|
|
5697
6167
|
}
|
|
5698
|
-
|
|
5699
|
-
|
|
6168
|
+
/**
|
|
6169
|
+
* Set the transition for this subject's morph. The morph is enabled
|
|
6170
|
+
* automatically by `.add()`; this just customises its timing (duration,
|
|
6171
|
+
* easing, a `delay`/`stagger`, …). On the implicit `root` subject it also
|
|
6172
|
+
* opts the page into the transition (the root crossfade).
|
|
6173
|
+
*/
|
|
6174
|
+
layout(options = {}) {
|
|
6175
|
+
this.updateTarget("layout", {}, options);
|
|
5700
6176
|
return this;
|
|
5701
6177
|
}
|
|
5702
6178
|
enter(keyframes, options) {
|
|
@@ -5707,9 +6183,21 @@
|
|
|
5707
6183
|
this.updateTarget("exit", keyframes, options);
|
|
5708
6184
|
return this;
|
|
5709
6185
|
}
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
6186
|
+
/**
|
|
6187
|
+
* Animate the new view directly, whether the element is appearing or
|
|
6188
|
+
* persisting (unlike `.enter()`, which only fires for a pure newcomer).
|
|
6189
|
+
* Pair with `.old()` for a crossfade or slide-through.
|
|
6190
|
+
*/
|
|
6191
|
+
new(keyframes, options) {
|
|
6192
|
+
this.updateTarget("new", keyframes, options);
|
|
6193
|
+
return this;
|
|
6194
|
+
}
|
|
6195
|
+
/**
|
|
6196
|
+
* Animate the old view directly, whether the element is leaving or
|
|
6197
|
+
* persisting (unlike `.exit()`, which only fires for a pure leaver).
|
|
6198
|
+
*/
|
|
6199
|
+
old(keyframes, options) {
|
|
6200
|
+
this.updateTarget("old", keyframes, options);
|
|
5713
6201
|
return this;
|
|
5714
6202
|
}
|
|
5715
6203
|
updateTarget(target, keyframes, options = {}) {
|
|
@@ -5724,8 +6212,8 @@
|
|
|
5724
6212
|
return this.readyPromise.then(resolve, reject);
|
|
5725
6213
|
}
|
|
5726
6214
|
}
|
|
5727
|
-
function animateView(update,
|
|
5728
|
-
return new ViewTransitionBuilder(update,
|
|
6215
|
+
function animateView(update, options = {}) {
|
|
6216
|
+
return new ViewTransitionBuilder(update, options);
|
|
5729
6217
|
}
|
|
5730
6218
|
|
|
5731
6219
|
const createAxisDelta = () => ({
|
|
@@ -7845,7 +8333,7 @@
|
|
|
7845
8333
|
|
|
7846
8334
|
function addDomEvent(target, eventName, handler, options = { passive: true }) {
|
|
7847
8335
|
target.addEventListener(eventName, handler, options);
|
|
7848
|
-
return () => target.removeEventListener(eventName, handler);
|
|
8336
|
+
return () => target.removeEventListener(eventName, handler, options);
|
|
7849
8337
|
}
|
|
7850
8338
|
|
|
7851
8339
|
const compareByDepth = (a, b) => a.depth - b.depth;
|
|
@@ -9115,7 +9603,6 @@
|
|
|
9115
9603
|
*/
|
|
9116
9604
|
this.pendingAnimation = frame.update(() => {
|
|
9117
9605
|
globalProjectionState.hasAnimatedSinceResize = true;
|
|
9118
|
-
activeAnimations.layout++;
|
|
9119
9606
|
this.motionValue || (this.motionValue = motionValue(0));
|
|
9120
9607
|
this.motionValue.jump(0, false);
|
|
9121
9608
|
this.currentAnimation = animateSingleValue(this.motionValue, [0, 1000], {
|
|
@@ -9126,11 +9613,7 @@
|
|
|
9126
9613
|
this.mixTargetDelta(latest);
|
|
9127
9614
|
options.onUpdate && options.onUpdate(latest);
|
|
9128
9615
|
},
|
|
9129
|
-
onStop: () => {
|
|
9130
|
-
activeAnimations.layout--;
|
|
9131
|
-
},
|
|
9132
9616
|
onComplete: () => {
|
|
9133
|
-
activeAnimations.layout--;
|
|
9134
9617
|
options.onComplete && options.onComplete();
|
|
9135
9618
|
this.completeAnimation();
|
|
9136
9619
|
},
|
|
@@ -9719,39 +10202,221 @@
|
|
|
9719
10202
|
checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
|
|
9720
10203
|
});
|
|
9721
10204
|
|
|
9722
|
-
const layoutSelector = "[data-layout],
|
|
9723
|
-
|
|
9724
|
-
|
|
9725
|
-
|
|
9726
|
-
|
|
9727
|
-
|
|
9728
|
-
|
|
9729
|
-
|
|
9730
|
-
|
|
9731
|
-
|
|
10205
|
+
const layoutSelector = "[data-layout],[data-layout-id]";
|
|
10206
|
+
/**
|
|
10207
|
+
* All imperatively-created projection nodes live in one persistent tree,
|
|
10208
|
+
* shared across animateLayout() calls (and with any React-created nodes,
|
|
10209
|
+
* via the singleton document root). Keyed by element for reuse.
|
|
10210
|
+
*/
|
|
10211
|
+
const layoutNodes = new WeakMap();
|
|
10212
|
+
/**
|
|
10213
|
+
* Builders created within the same synchronous tick are flushed together
|
|
10214
|
+
* as a single "commit": every node is snapshotted before any updateDom
|
|
10215
|
+
* runs, mirroring React batching renders from different parts of the tree.
|
|
10216
|
+
*/
|
|
10217
|
+
let pendingBuilders;
|
|
10218
|
+
function collectLayoutElements(scope) {
|
|
10219
|
+
const elements = [];
|
|
10220
|
+
if (scope instanceof HTMLElement && scope.matches(layoutSelector)) {
|
|
10221
|
+
elements.push(scope);
|
|
10222
|
+
}
|
|
10223
|
+
scope.querySelectorAll(layoutSelector).forEach((element) => {
|
|
10224
|
+
if (element instanceof HTMLElement)
|
|
10225
|
+
elements.push(element);
|
|
10226
|
+
});
|
|
10227
|
+
return elements;
|
|
10228
|
+
}
|
|
10229
|
+
/**
|
|
10230
|
+
* Process any work scheduled on the frameloop now. A previous animation
|
|
10231
|
+
* may have been seeked while paused (controls.time = x) without a frame
|
|
10232
|
+
* having rendered it - we must materialise that state into the DOM
|
|
10233
|
+
* before taking snapshots.
|
|
10234
|
+
*/
|
|
10235
|
+
function flushPendingFrame() {
|
|
10236
|
+
if (frameData.isProcessing)
|
|
10237
|
+
return;
|
|
10238
|
+
const now = time.now();
|
|
10239
|
+
frameData.delta = motionUtils.clamp(0, 1000 / 60, now - frameData.timestamp);
|
|
10240
|
+
frameData.timestamp = now;
|
|
10241
|
+
frameData.isProcessing = true;
|
|
10242
|
+
frameSteps.update.process(frameData);
|
|
10243
|
+
frameSteps.preRender.process(frameData);
|
|
10244
|
+
frameSteps.render.process(frameData);
|
|
10245
|
+
frameData.isProcessing = false;
|
|
10246
|
+
}
|
|
10247
|
+
function getProjectionParent(element) {
|
|
10248
|
+
let ancestor = element.parentElement;
|
|
10249
|
+
while (ancestor) {
|
|
10250
|
+
const node = layoutNodes.get(ancestor);
|
|
10251
|
+
if (node && node.instance)
|
|
10252
|
+
return node;
|
|
10253
|
+
ancestor = ancestor.parentElement;
|
|
10254
|
+
}
|
|
10255
|
+
return undefined;
|
|
10256
|
+
}
|
|
10257
|
+
function createVisualElement() {
|
|
10258
|
+
return new HTMLVisualElement({
|
|
10259
|
+
props: {},
|
|
10260
|
+
presenceContext: null,
|
|
10261
|
+
visualState: {
|
|
10262
|
+
latestValues: {},
|
|
10263
|
+
renderState: {
|
|
10264
|
+
transform: {},
|
|
10265
|
+
transformOrigin: {},
|
|
10266
|
+
style: {},
|
|
10267
|
+
vars: {},
|
|
10268
|
+
},
|
|
10269
|
+
},
|
|
10270
|
+
}, { allowProjection: true });
|
|
10271
|
+
}
|
|
10272
|
+
function readNodeOptions(element, transition) {
|
|
10273
|
+
const layoutAttr = element.getAttribute("data-layout");
|
|
10274
|
+
const layoutId = element.getAttribute("data-layout-id") ?? undefined;
|
|
9732
10275
|
return {
|
|
9733
|
-
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
|
|
9737
|
-
|
|
10276
|
+
layoutId,
|
|
10277
|
+
layout: layoutAttr !== null ? true : undefined,
|
|
10278
|
+
animationType: (!layoutAttr || layoutAttr === "true"
|
|
10279
|
+
? "both"
|
|
10280
|
+
: layoutAttr),
|
|
10281
|
+
transition,
|
|
9738
10282
|
};
|
|
9739
10283
|
}
|
|
10284
|
+
function prepareNode(element, transition) {
|
|
10285
|
+
let node = layoutNodes.get(element);
|
|
10286
|
+
if (!node) {
|
|
10287
|
+
let visualElement = visualElementStore.get(element);
|
|
10288
|
+
if (!visualElement)
|
|
10289
|
+
visualElement = createVisualElement();
|
|
10290
|
+
/**
|
|
10291
|
+
* A first-time element may carry a projection transform in its
|
|
10292
|
+
* inline style (e.g. it was cloned from an element mid-animation).
|
|
10293
|
+
* That transform isn't tracked in latestValues so the engine can't
|
|
10294
|
+
* reset it before measuring - clear it now so the first layout
|
|
10295
|
+
* measurement isn't inflated.
|
|
10296
|
+
*/
|
|
10297
|
+
if (element.style.transform &&
|
|
10298
|
+
!hasTransform(visualElement.latestValues)) {
|
|
10299
|
+
element.style.transform = "";
|
|
10300
|
+
}
|
|
10301
|
+
node = new HTMLProjectionNode(visualElement.latestValues, getProjectionParent(element));
|
|
10302
|
+
visualElement.projection = node;
|
|
10303
|
+
node.setOptions({
|
|
10304
|
+
...readNodeOptions(element, transition),
|
|
10305
|
+
visualElement,
|
|
10306
|
+
});
|
|
10307
|
+
node.mount(element);
|
|
10308
|
+
layoutNodes.set(element, node);
|
|
10309
|
+
}
|
|
10310
|
+
else {
|
|
10311
|
+
node.setOptions(readNodeOptions(element, transition));
|
|
10312
|
+
}
|
|
10313
|
+
node.isPresent = true;
|
|
10314
|
+
if (node.options.onExitComplete) {
|
|
10315
|
+
node.setOptions({ onExitComplete: undefined });
|
|
10316
|
+
}
|
|
10317
|
+
return node;
|
|
10318
|
+
}
|
|
10319
|
+
function sortDocumentOrder(elements) {
|
|
10320
|
+
return [...elements].sort((a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
|
|
10321
|
+
}
|
|
10322
|
+
function dropNode(element, node) {
|
|
10323
|
+
node.setOptions({ onExitComplete: undefined });
|
|
10324
|
+
/**
|
|
10325
|
+
* Stop any lingering animation so it can't leak into future updates.
|
|
10326
|
+
* A follow node can share its currentAnimation with a surviving lead
|
|
10327
|
+
* (via resumingFrom), in which case it isn't ours to stop.
|
|
10328
|
+
*/
|
|
10329
|
+
const stack = node.getStack();
|
|
10330
|
+
if (!stack || node.isLead())
|
|
10331
|
+
node.currentAnimation?.stop();
|
|
10332
|
+
node.unmount();
|
|
10333
|
+
layoutNodes.delete(element);
|
|
10334
|
+
}
|
|
10335
|
+
function flushPendingBuilders() {
|
|
10336
|
+
const builders = pendingBuilders;
|
|
10337
|
+
pendingBuilders = undefined;
|
|
10338
|
+
flushPendingFrame();
|
|
10339
|
+
/**
|
|
10340
|
+
* Discover and mount every node across all builders before snapshotting
|
|
10341
|
+
* any of them. Mounting during an active update flags isLayoutDirty,
|
|
10342
|
+
* which would make that node's own willUpdate skip its snapshot.
|
|
10343
|
+
* Document order guarantees ancestors mount before descendants, even
|
|
10344
|
+
* when they're discovered by different builders.
|
|
10345
|
+
*/
|
|
10346
|
+
const targets = new Map();
|
|
10347
|
+
for (const builder of builders) {
|
|
10348
|
+
for (const element of builder.collectTargets()) {
|
|
10349
|
+
const owners = targets.get(element);
|
|
10350
|
+
owners ? owners.push(builder) : targets.set(element, [builder]);
|
|
10351
|
+
}
|
|
10352
|
+
}
|
|
10353
|
+
const union = new Map();
|
|
10354
|
+
for (const element of sortDocumentOrder(targets.keys())) {
|
|
10355
|
+
const owners = targets.get(element);
|
|
10356
|
+
const node = prepareNode(element, owners[owners.length - 1].transitionFor(element));
|
|
10357
|
+
for (const owner of owners)
|
|
10358
|
+
owner.adopt(element, node);
|
|
10359
|
+
union.set(element, node);
|
|
10360
|
+
}
|
|
10361
|
+
union.forEach((node) => {
|
|
10362
|
+
node.isLayoutDirty = false;
|
|
10363
|
+
node.willUpdate();
|
|
10364
|
+
});
|
|
10365
|
+
const updatePromises = [];
|
|
10366
|
+
for (const builder of builders) {
|
|
10367
|
+
const result = builder.runUpdate();
|
|
10368
|
+
if (result)
|
|
10369
|
+
updatePromises.push(result);
|
|
10370
|
+
}
|
|
10371
|
+
const commit = () => {
|
|
10372
|
+
/**
|
|
10373
|
+
* Process all additions before any removals so that, even across
|
|
10374
|
+
* builders, a removed member knows whether a replacement with the
|
|
10375
|
+
* same layoutId was added in this commit.
|
|
10376
|
+
*/
|
|
10377
|
+
const newMemberIds = new Set();
|
|
10378
|
+
for (const builder of builders) {
|
|
10379
|
+
builder.reconcileAdditions(newMemberIds);
|
|
10380
|
+
}
|
|
10381
|
+
for (const builder of builders) {
|
|
10382
|
+
builder.reconcileRemovals(newMemberIds);
|
|
10383
|
+
}
|
|
10384
|
+
let root;
|
|
10385
|
+
union.forEach((node) => (root || (root = node.root)));
|
|
10386
|
+
for (const builder of builders)
|
|
10387
|
+
root || (root = builder.getRoot());
|
|
10388
|
+
root?.didUpdate();
|
|
10389
|
+
/**
|
|
10390
|
+
* The root flushes the update on a microtask, synchronously
|
|
10391
|
+
* processing the frame that creates the layout animations. Collect
|
|
10392
|
+
* them in a later microtask step of the same pass.
|
|
10393
|
+
*/
|
|
10394
|
+
microtask.render(() => {
|
|
10395
|
+
for (const builder of builders)
|
|
10396
|
+
builder.finalize();
|
|
10397
|
+
});
|
|
10398
|
+
};
|
|
10399
|
+
updatePromises.length ? Promise.all(updatePromises).then(commit) : commit();
|
|
10400
|
+
}
|
|
9740
10401
|
class LayoutAnimationBuilder {
|
|
9741
10402
|
constructor(scope, updateDom, defaultOptions) {
|
|
9742
|
-
this.sharedTransitions = new Map();
|
|
9743
|
-
this.notifyReady = noop;
|
|
9744
|
-
this.rejectReady = noop;
|
|
9745
10403
|
this.scope = scope;
|
|
9746
10404
|
this.updateDom = updateDom;
|
|
9747
10405
|
this.defaultOptions = defaultOptions;
|
|
10406
|
+
this.sharedTransitions = new Map();
|
|
10407
|
+
this.notifyReady = () => { };
|
|
10408
|
+
this.rejectReady = () => { };
|
|
10409
|
+
this.tracked = new Map();
|
|
10410
|
+
this.restorePoints = new Map();
|
|
9748
10411
|
this.readyPromise = new Promise((resolve, reject) => {
|
|
9749
10412
|
this.notifyReady = resolve;
|
|
9750
10413
|
this.rejectReady = reject;
|
|
9751
10414
|
});
|
|
9752
|
-
|
|
9753
|
-
|
|
9754
|
-
|
|
10415
|
+
if (!pendingBuilders) {
|
|
10416
|
+
pendingBuilders = [];
|
|
10417
|
+
queueMicrotask(flushPendingBuilders);
|
|
10418
|
+
}
|
|
10419
|
+
pendingBuilders.push(this);
|
|
9755
10420
|
}
|
|
9756
10421
|
shared(id, transition) {
|
|
9757
10422
|
this.sharedTransitions.set(id, transition);
|
|
@@ -9760,114 +10425,107 @@
|
|
|
9760
10425
|
then(resolve, reject) {
|
|
9761
10426
|
return this.readyPromise.then(resolve, reject);
|
|
9762
10427
|
}
|
|
9763
|
-
|
|
9764
|
-
const
|
|
9765
|
-
|
|
9766
|
-
|
|
9767
|
-
|
|
9768
|
-
|
|
9769
|
-
|
|
9770
|
-
|
|
9771
|
-
|
|
9772
|
-
|
|
9773
|
-
}
|
|
9774
|
-
else if (projection.snapshot) {
|
|
9775
|
-
projection.snapshot = undefined;
|
|
9776
|
-
}
|
|
9777
|
-
}
|
|
9778
|
-
else if (projection.snapshot &&
|
|
9779
|
-
(projection.currentAnimation || projection.isProjecting())) {
|
|
9780
|
-
projection.snapshot = undefined;
|
|
9781
|
-
}
|
|
9782
|
-
projection.isPresent = true;
|
|
9783
|
-
projection.willUpdate();
|
|
10428
|
+
transitionFor(element) {
|
|
10429
|
+
const layoutId = element.getAttribute("data-layout-id");
|
|
10430
|
+
return ((layoutId && this.sharedTransitions.get(layoutId)) ||
|
|
10431
|
+
this.defaultOptions);
|
|
10432
|
+
}
|
|
10433
|
+
adopt(element, node) {
|
|
10434
|
+
this.tracked.set(element, node);
|
|
10435
|
+
this.restorePoints.set(element, {
|
|
10436
|
+
parent: element.parentElement,
|
|
10437
|
+
next: element.nextSibling,
|
|
9784
10438
|
});
|
|
9785
|
-
|
|
9786
|
-
|
|
9787
|
-
|
|
9788
|
-
|
|
9789
|
-
|
|
9790
|
-
|
|
9791
|
-
const
|
|
9792
|
-
|
|
9793
|
-
|
|
9794
|
-
|
|
9795
|
-
|
|
9796
|
-
return;
|
|
9797
|
-
const currentTransform = instance.style.transform;
|
|
9798
|
-
const resumeFromTransform = resumeFromInstance.style.transform;
|
|
9799
|
-
if (currentTransform &&
|
|
9800
|
-
resumeFromTransform &&
|
|
9801
|
-
currentTransform === resumeFromTransform) {
|
|
9802
|
-
instance.style.transform = "";
|
|
9803
|
-
instance.style.transformOrigin = "";
|
|
10439
|
+
}
|
|
10440
|
+
collectTargets() {
|
|
10441
|
+
return collectLayoutElements(this.scope);
|
|
10442
|
+
}
|
|
10443
|
+
runUpdate() {
|
|
10444
|
+
try {
|
|
10445
|
+
const result = this.updateDom();
|
|
10446
|
+
if (result && typeof result.then === "function") {
|
|
10447
|
+
return result.then(undefined, (error) => {
|
|
10448
|
+
this.updateError = error;
|
|
10449
|
+
});
|
|
9804
10450
|
}
|
|
9805
|
-
}
|
|
9806
|
-
|
|
9807
|
-
|
|
9808
|
-
}
|
|
9809
|
-
|
|
9810
|
-
root?.didUpdate();
|
|
9811
|
-
await new Promise((resolve) => {
|
|
9812
|
-
frame.postRender(() => resolve());
|
|
9813
|
-
});
|
|
9814
|
-
const animations = collectAnimations(afterRecords);
|
|
9815
|
-
const animation = new GroupAnimation(animations);
|
|
9816
|
-
return animation;
|
|
10451
|
+
}
|
|
10452
|
+
catch (error) {
|
|
10453
|
+
this.updateError = error;
|
|
10454
|
+
}
|
|
10455
|
+
return undefined;
|
|
9817
10456
|
}
|
|
9818
|
-
|
|
9819
|
-
const
|
|
9820
|
-
|
|
9821
|
-
|
|
9822
|
-
const
|
|
9823
|
-
|
|
9824
|
-
|
|
9825
|
-
? this.sharedTransitions.get(layoutId)
|
|
9826
|
-
: undefined;
|
|
9827
|
-
const transition = override || this.defaultOptions;
|
|
9828
|
-
const record = getOrCreateRecord(element, parentRecord?.projection, {
|
|
9829
|
-
layout,
|
|
9830
|
-
layoutId,
|
|
9831
|
-
animationType: typeof layout === "string" ? layout : "both",
|
|
9832
|
-
transition: transition,
|
|
9833
|
-
});
|
|
9834
|
-
recordMap.set(element, record);
|
|
9835
|
-
records.push(record);
|
|
10457
|
+
reconcileAdditions(newMemberIds) {
|
|
10458
|
+
for (const element of collectLayoutElements(this.scope)) {
|
|
10459
|
+
if (this.tracked.has(element))
|
|
10460
|
+
continue;
|
|
10461
|
+
const node = prepareNode(element, this.transitionFor(element));
|
|
10462
|
+
this.adopt(element, node);
|
|
10463
|
+
node.options.layoutId && newMemberIds.add(node.options.layoutId);
|
|
9836
10464
|
}
|
|
9837
|
-
return records;
|
|
9838
10465
|
}
|
|
9839
|
-
|
|
9840
|
-
|
|
9841
|
-
|
|
9842
|
-
if (afterElementsSet.has(record.element))
|
|
10466
|
+
reconcileRemovals(newMemberIds) {
|
|
10467
|
+
this.tracked.forEach((node, element) => {
|
|
10468
|
+
if (element.isConnected)
|
|
9843
10469
|
return;
|
|
9844
|
-
|
|
9845
|
-
|
|
9846
|
-
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
|
-
|
|
9850
|
-
|
|
9851
|
-
|
|
10470
|
+
const restore = this.restorePoints.get(element);
|
|
10471
|
+
this.restorePoints.delete(element);
|
|
10472
|
+
const { layoutId } = node.options;
|
|
10473
|
+
const stack = node.getStack();
|
|
10474
|
+
const hasSurvivor = stack &&
|
|
10475
|
+
stack.members.some((member) => member !== node &&
|
|
10476
|
+
member.instance
|
|
10477
|
+
?.isConnected);
|
|
10478
|
+
/**
|
|
10479
|
+
* A removed lead with a surviving stack member - and no
|
|
10480
|
+
* replacement member added this commit - runs an exit
|
|
10481
|
+
* crossfade: restore the element to its old position in the
|
|
10482
|
+
* DOM, relegate it and let the survivor take over. It's
|
|
10483
|
+
* removed again once the animation completes.
|
|
10484
|
+
*/
|
|
10485
|
+
if (layoutId &&
|
|
10486
|
+
node.isLead() &&
|
|
10487
|
+
hasSurvivor &&
|
|
10488
|
+
!newMemberIds.has(layoutId)) {
|
|
10489
|
+
if (restore && restore.parent.isConnected) {
|
|
10490
|
+
restore.parent.insertBefore(element, restore.next && restore.next.parentNode === restore.parent
|
|
10491
|
+
? restore.next
|
|
10492
|
+
: null);
|
|
10493
|
+
node.isPresent = false;
|
|
10494
|
+
node.setOptions({
|
|
10495
|
+
onExitComplete: () => {
|
|
10496
|
+
element.remove();
|
|
10497
|
+
dropNode(element, node);
|
|
10498
|
+
},
|
|
10499
|
+
});
|
|
10500
|
+
if (node.relegate())
|
|
10501
|
+
return;
|
|
10502
|
+
element.remove();
|
|
10503
|
+
}
|
|
10504
|
+
}
|
|
10505
|
+
dropNode(element, node);
|
|
10506
|
+
this.tracked.delete(element);
|
|
9852
10507
|
});
|
|
9853
|
-
|
|
9854
|
-
|
|
9855
|
-
|
|
9856
|
-
|
|
9857
|
-
|
|
9858
|
-
|
|
9859
|
-
|
|
9860
|
-
|
|
9861
|
-
|
|
9862
|
-
|
|
9863
|
-
|
|
9864
|
-
|
|
10508
|
+
}
|
|
10509
|
+
getRoot() {
|
|
10510
|
+
let root;
|
|
10511
|
+
this.tracked.forEach((node) => (root || (root = node.root)));
|
|
10512
|
+
return root;
|
|
10513
|
+
}
|
|
10514
|
+
finalize() {
|
|
10515
|
+
if (this.updateError) {
|
|
10516
|
+
this.rejectReady(this.updateError);
|
|
10517
|
+
return;
|
|
10518
|
+
}
|
|
10519
|
+
const animations = new Set();
|
|
10520
|
+
this.tracked.forEach((node) => {
|
|
10521
|
+
if (node.instance && node.currentAnimation) {
|
|
10522
|
+
animations.add(node.currentAnimation);
|
|
9865
10523
|
}
|
|
9866
10524
|
});
|
|
10525
|
+
this.notifyReady(new GroupAnimation([...animations]));
|
|
9867
10526
|
}
|
|
9868
10527
|
}
|
|
9869
10528
|
function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
9870
|
-
// animateLayout(updateDom)
|
|
9871
10529
|
if (typeof scopeOrUpdateDom === "function") {
|
|
9872
10530
|
return {
|
|
9873
10531
|
scope: document,
|
|
@@ -9875,107 +10533,15 @@
|
|
|
9875
10533
|
defaultOptions: updateDomOrOptions,
|
|
9876
10534
|
};
|
|
9877
10535
|
}
|
|
9878
|
-
|
|
9879
|
-
|
|
9880
|
-
|
|
10536
|
+
const scope = scopeOrUpdateDom instanceof Document
|
|
10537
|
+
? scopeOrUpdateDom
|
|
10538
|
+
: resolveElements(scopeOrUpdateDom)[0] ?? document;
|
|
9881
10539
|
return {
|
|
9882
10540
|
scope,
|
|
9883
10541
|
updateDom: updateDomOrOptions,
|
|
9884
10542
|
defaultOptions: options,
|
|
9885
10543
|
};
|
|
9886
10544
|
}
|
|
9887
|
-
function collectLayoutElements(scope) {
|
|
9888
|
-
const elements = Array.from(scope.querySelectorAll(layoutSelector));
|
|
9889
|
-
if (scope instanceof Element && scope.matches(layoutSelector)) {
|
|
9890
|
-
if (!elements.includes(scope)) {
|
|
9891
|
-
elements.unshift(scope);
|
|
9892
|
-
}
|
|
9893
|
-
}
|
|
9894
|
-
return elements;
|
|
9895
|
-
}
|
|
9896
|
-
function readLayoutAttributes(element) {
|
|
9897
|
-
const layoutId = element.getAttribute("data-layout-id") || undefined;
|
|
9898
|
-
const rawLayout = element.getAttribute("data-layout");
|
|
9899
|
-
let layout;
|
|
9900
|
-
if (rawLayout === "" || rawLayout === "true") {
|
|
9901
|
-
layout = true;
|
|
9902
|
-
}
|
|
9903
|
-
else if (rawLayout) {
|
|
9904
|
-
layout = rawLayout;
|
|
9905
|
-
}
|
|
9906
|
-
return {
|
|
9907
|
-
layout,
|
|
9908
|
-
layoutId,
|
|
9909
|
-
};
|
|
9910
|
-
}
|
|
9911
|
-
function createVisualState() {
|
|
9912
|
-
return {
|
|
9913
|
-
latestValues: {},
|
|
9914
|
-
renderState: {
|
|
9915
|
-
transform: {},
|
|
9916
|
-
transformOrigin: {},
|
|
9917
|
-
style: {},
|
|
9918
|
-
vars: {},
|
|
9919
|
-
},
|
|
9920
|
-
};
|
|
9921
|
-
}
|
|
9922
|
-
function getOrCreateRecord(element, parentProjection, projectionOptions) {
|
|
9923
|
-
const existing = visualElementStore.get(element);
|
|
9924
|
-
const visualElement = existing ??
|
|
9925
|
-
new HTMLVisualElement({
|
|
9926
|
-
props: {},
|
|
9927
|
-
presenceContext: null,
|
|
9928
|
-
visualState: createVisualState(),
|
|
9929
|
-
}, { allowProjection: true });
|
|
9930
|
-
if (!existing || !visualElement.projection) {
|
|
9931
|
-
visualElement.projection = new HTMLProjectionNode(visualElement.latestValues, parentProjection);
|
|
9932
|
-
}
|
|
9933
|
-
visualElement.projection.setOptions({
|
|
9934
|
-
...projectionOptions,
|
|
9935
|
-
visualElement,
|
|
9936
|
-
});
|
|
9937
|
-
if (!visualElement.current) {
|
|
9938
|
-
visualElement.mount(element);
|
|
9939
|
-
}
|
|
9940
|
-
else if (!visualElement.projection.instance) {
|
|
9941
|
-
// Mount projection if VisualElement is already mounted but projection isn't
|
|
9942
|
-
// This happens when animate() was called before animateLayout()
|
|
9943
|
-
visualElement.projection.mount(element);
|
|
9944
|
-
}
|
|
9945
|
-
if (!existing) {
|
|
9946
|
-
visualElementStore.set(element, visualElement);
|
|
9947
|
-
}
|
|
9948
|
-
return {
|
|
9949
|
-
element,
|
|
9950
|
-
visualElement,
|
|
9951
|
-
projection: visualElement.projection,
|
|
9952
|
-
};
|
|
9953
|
-
}
|
|
9954
|
-
function findParentRecord(element, recordMap, scope) {
|
|
9955
|
-
let parent = element.parentElement;
|
|
9956
|
-
while (parent) {
|
|
9957
|
-
const record = recordMap.get(parent);
|
|
9958
|
-
if (record)
|
|
9959
|
-
return record;
|
|
9960
|
-
if (parent === scope)
|
|
9961
|
-
break;
|
|
9962
|
-
parent = parent.parentElement;
|
|
9963
|
-
}
|
|
9964
|
-
return undefined;
|
|
9965
|
-
}
|
|
9966
|
-
function getProjectionRoot(afterRecords, beforeRecords) {
|
|
9967
|
-
const record = afterRecords[0] || beforeRecords[0];
|
|
9968
|
-
return record?.projection.root;
|
|
9969
|
-
}
|
|
9970
|
-
function collectAnimations(afterRecords) {
|
|
9971
|
-
const animations = new Set();
|
|
9972
|
-
afterRecords.forEach((record) => {
|
|
9973
|
-
const animation = record.projection.currentAnimation;
|
|
9974
|
-
if (animation)
|
|
9975
|
-
animations.add(animation);
|
|
9976
|
-
});
|
|
9977
|
-
return Array.from(animations);
|
|
9978
|
-
}
|
|
9979
10545
|
|
|
9980
10546
|
/**
|
|
9981
10547
|
* @deprecated
|
|
@@ -10016,7 +10582,6 @@
|
|
|
10016
10582
|
exports.ViewTransitionBuilder = ViewTransitionBuilder;
|
|
10017
10583
|
exports.VisualElement = VisualElement;
|
|
10018
10584
|
exports.acceleratedValues = acceleratedValues;
|
|
10019
|
-
exports.activeAnimations = activeAnimations;
|
|
10020
10585
|
exports.addAttrValue = addAttrValue;
|
|
10021
10586
|
exports.addDomEvent = addDomEvent;
|
|
10022
10587
|
exports.addScaleCorrector = addScaleCorrector;
|