@astryx-vue/core 0.16.5 → 0.18.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/AppShell/index.d.ts +1 -1
- package/dist/AvatarGroup/index.d.ts +1 -1
- package/dist/Banner/index.d.ts +1 -1
- package/dist/BottomSheet/index.d.ts +1 -1
- package/dist/Button/index.d.ts +1 -1
- package/dist/ButtonGroup/index.d.ts +1 -1
- package/dist/Calendar/index.d.ts +1 -1
- package/dist/Carousel/index.d.ts +1 -1
- package/dist/Chat/index.d.ts +1 -1
- package/dist/Chat/index.js +1 -1
- package/dist/CheckboxInput/index.d.ts +1 -1
- package/dist/CheckboxList/index.d.ts +1 -1
- package/dist/ClickableCard/index.d.ts +1 -1
- package/dist/Code/index.d.ts +1 -1
- package/dist/Code/index.js +1 -1
- package/dist/Collapsible/index.d.ts +1 -1
- package/dist/Collapsible/index.js +1 -1
- package/dist/{Collapsible-Dk9BQQbT.js → Collapsible-ExzU7vC0.js} +104 -40
- package/dist/CommandPalette/index.d.ts +1 -1
- package/dist/CommandPalette/index.js +1 -1
- package/dist/{CommandPalette-mNR6dV0B.js → CommandPalette-CECjNvGB.js} +1 -1
- package/dist/ComplexSelector/index.js +1 -1
- package/dist/{ComplexSelector-CR9XbpTa.js → ComplexSelector-Dmaag1wm.js} +5 -1
- package/dist/ContextMenu/index.d.ts +1 -1
- package/dist/DateInput/index.d.ts +1 -1
- package/dist/DateInput/index.js +1 -1
- package/dist/DateRangeInput/index.d.ts +1 -1
- package/dist/DateRangeInput/index.js +1 -1
- package/dist/DateTimeInput/index.d.ts +1 -1
- package/dist/DateTimeInput/index.js +1 -1
- package/dist/{DateTimeInput-ChGin5zS.js → DateTimeInput-Cfkuec_h.js} +1 -1
- package/dist/Dialog/index.d.ts +1 -1
- package/dist/Divider/index.d.ts +1 -1
- package/dist/Drawer/index.d.ts +1 -1
- package/dist/Field/index.d.ts +1 -1
- package/dist/FileInput/index.d.ts +1 -1
- package/dist/HoverCard/index.d.ts +1 -1
- package/dist/Indicator/index.d.ts +2 -2
- package/dist/InfoTip/index.d.ts +1 -1
- package/dist/InputGroup/index.d.ts +1 -1
- package/dist/InternationalizationProvider/index.d.ts +1 -1
- package/dist/InternationalizationProvider/index.js +1 -1
- package/dist/{InternationalizationProvider-7rA65NO7.js → InternationalizationProvider-Dr5GE6f0.js} +1 -1
- package/dist/Link/index.d.ts +1 -1
- package/dist/List/index.d.ts +1 -1
- package/dist/Markdown/index.js +1 -1
- package/dist/{Markdown-BNVd70jg.js → Markdown-DnnWjJGX.js} +1 -1
- package/dist/{MediaTheme-Bkj-_DFN.js → MediaTheme-DfcdEWx-.js} +2 -36
- package/dist/MoreMenu/index.d.ts +1 -1
- package/dist/MultiSelector/index.d.ts +1 -1
- package/dist/MultiSelector/index.js +1 -1
- package/dist/{MultiSelector-CXX1Hsty.js → MultiSelector-BK6nZweN.js} +26 -14
- package/dist/NavItem/index.d.ts +1 -1
- package/dist/NumberInput/index.d.ts +1 -1
- package/dist/OverflowList/index.d.ts +1 -1
- package/dist/Pagination/index.d.ts +1 -1
- package/dist/Pagination/index.js +1 -1
- package/dist/{Pagination-BvZFvwso.js → Pagination-DFQNX_Mb.js} +1 -1
- package/dist/Popover/index.d.ts +1 -1
- package/dist/PowerSearch/index.d.ts +1 -1
- package/dist/PowerSearch/index.js +1 -1
- package/dist/{PowerSearch-BiupstfT.js → PowerSearch-BAOqpQag.js} +10 -10
- package/dist/ProgressBar/index.d.ts +1 -1
- package/dist/Radio/index.d.ts +1 -1
- package/dist/RadioList/index.d.ts +1 -1
- package/dist/ScrollableArea/index.d.ts +1 -1
- package/dist/SegmentedControl/index.d.ts +1 -1
- package/dist/SelectableCard/index.d.ts +1 -1
- package/dist/Selector/index.d.ts +1 -1
- package/dist/Selector/index.js +1 -1
- package/dist/{Selector-DiSLNzl8.js → Selector-Bo7qkt1P.js} +157 -62
- package/dist/SideNav/index.d.ts +1 -1
- package/dist/Stepper/index.d.ts +1 -1
- package/dist/Switch/index.d.ts +1 -1
- package/dist/Table/index.d.ts +1 -1
- package/dist/Table/index.js +1 -1
- package/dist/{Table-BD8MugZo.js → Table-iemur_3E.js} +378 -7
- package/dist/TextArea/index.d.ts +1 -1
- package/dist/TextInput/index.d.ts +1 -1
- package/dist/Theme/index.d.ts +3 -3
- package/dist/Theme/index.js +3 -2
- package/dist/{Theme-8bDq2nud.js → Theme-1RJVaRgz.js} +329 -40
- package/dist/TimeInput/index.d.ts +1 -1
- package/dist/Timer/index.d.ts +1 -1
- package/dist/Timestamp/index.d.ts +1 -1
- package/dist/Toast/index.js +1 -1
- package/dist/{Toast-CzbqvHDN.js → Toast-D4Q6wvYu.js} +1 -1
- package/dist/ToggleButton/index.d.ts +1 -1
- package/dist/Tokenizer/index.d.ts +1 -1
- package/dist/Tokenizer/index.js +1 -1
- package/dist/{Tokenizer-mu0Sak58.js → Tokenizer-CsFiYUJ_.js} +171 -103
- package/dist/Toolbar/index.d.ts +1 -1
- package/dist/Tooltip/index.d.ts +1 -1
- package/dist/TopNav/index.d.ts +1 -1
- package/dist/TreeList/index.d.ts +1 -1
- package/dist/TreeList/index.js +1 -1
- package/dist/{TreeList-CNj4KnHH.js → TreeList-ugSF9DWj.js} +117 -2
- package/dist/Typeahead/index.d.ts +2 -1
- package/dist/Typeahead/index.js +2 -2
- package/dist/{Typeahead-Db8Tu27Z.js → Typeahead--kEp21ut.js} +159 -71
- package/dist/{useKeyboardHighlight-CGCf1O57.js → assertOptions-CK_gJ0d3.js} +12 -1
- package/dist/composables/index.d.ts +4 -3
- package/dist/composables/index.js +5 -5
- package/dist/composables-BgfubKnk.js +5437 -0
- package/dist/handle-BPXdHbkr.js +458 -0
- package/dist/{index-sXu15K4j.d.ts → index-B-3EGjfQ.d.ts} +2 -2
- package/dist/{index-TXcNH86P.d.ts → index-B1eCxBCY.d.ts} +1 -1
- package/dist/{index-9eluGe3a.d.ts → index-BBTU-TKb.d.ts} +1 -1
- package/dist/{index-CE74Qsbn.d.ts → index-BKpnfdq1.d.ts} +9 -9
- package/dist/{index-D_xBhUV5.d.ts → index-B_PKY-Wn.d.ts} +11 -11
- package/dist/{index-Bfm6mF-r.d.ts → index-BfoazhEu.d.ts} +1 -1
- package/dist/{index-BWzEt0gT.d.ts → index-BhxqUt3y.d.ts} +1 -1
- package/dist/{index-CJdOt5Cc.d.ts → index-BtqvPjAf.d.ts} +3 -3
- package/dist/{index-ChqMaV6N.d.ts → index-Bzi3A980.d.ts} +1 -1
- package/dist/{index-DBwEz4M9.d.ts → index-BzmcDJau.d.ts} +11 -11
- package/dist/{index-CQ1bsxLC.d.ts → index-C1qJlC65.d.ts} +1 -1
- package/dist/{index-CMLnSg3T.d.ts → index-C4S65SAW.d.ts} +8 -1
- package/dist/{index-D05JGsT3.d.ts → index-C8wfe0Mr.d.ts} +1 -1
- package/dist/{index-gmY3A_Iw.d.ts → index-C93nwgTW.d.ts} +1 -1
- package/dist/{index-BvWBeoa8.d.ts → index-CEjvYAUZ.d.ts} +1 -1
- package/dist/{index-B0R5CLPF.d.ts → index-CsYDrQ9R.d.ts} +1 -1
- package/dist/{index-C2cH8OLC.d.ts → index-D31bgBoy.d.ts} +1 -1
- package/dist/{index-BxWCX2pJ.d.ts → index-DFLPv9io.d.ts} +3 -3
- package/dist/index-DGXCnzOL.d.ts +69 -0
- package/dist/{index-BPf_jmME.d.ts → index-DMcf0QeR.d.ts} +3 -3
- package/dist/{index-SWw-WMTO.d.ts → index-DPhQZXYw.d.ts} +3 -3
- package/dist/{index-B-Jla56c.d.ts → index-DmAEpn5E.d.ts} +1 -1
- package/dist/{index-B0yaHi__.d.ts → index-DtZUOyCy.d.ts} +12 -5
- package/dist/{index-BQ3cm7mP.d.ts → index-FeZXsFO-.d.ts} +1 -1
- package/dist/{index-Byan7Dad.d.ts → index-GmoeIuhl.d.ts} +1 -1
- package/dist/{index-ygmRS6Np.d.ts → index-KcCNhdAw.d.ts} +1 -1
- package/dist/{index-BPHqOCfp.d.ts → index-PffxihMx.d.ts} +4 -4
- package/dist/{index-unAZVFGz.d.ts → index-Qdbssopn.d.ts} +2 -2
- package/dist/{index-LHvLg1Pv.d.ts → index-Y4H4X6Vy.d.ts} +88 -82
- package/dist/{index-Xc3q9f84.d.ts → index-YKCx03zD.d.ts} +2 -2
- package/dist/{index-BXDqyk2_.d.ts → index-gu5EvbE0.d.ts} +170 -2
- package/dist/{index-BFZxzCYu.d.ts → index-o00Upzjp.d.ts} +3 -3
- package/dist/{index-BEZ4ezJk.d.ts → index-ql9ApSTF.d.ts} +7 -0
- package/dist/index.d.ts +39 -37
- package/dist/index.js +31 -30
- package/dist/landing-Bs0aMIsR.js +2049 -0
- package/dist/{loadCatalog-DFyDz_4e.d.ts → loadCatalog-BJwcyX8i.d.ts} +2 -0
- package/dist/{loadCatalog-C3MSknfx.js → loadCatalog-C1kms5sO.js} +5 -1
- package/dist/locale/index.d.ts +2 -2
- package/dist/locale/index.js +3 -3
- package/dist/{locale-OCGw4bi6.js → locale-CHhsd9Mq.js} +1 -1
- package/dist/motionTokenDefaults-EFzpiAF5.js +38 -0
- package/dist/tokenName-0U-WEH09.js +36 -0
- package/dist/{typeahead-RkZw0Ktn.js → typeahead-BgfLP7vR.js} +2 -0
- package/dist/{index-DbFIQDoa.d.ts → types-C1ydeFiu.d.ts} +43 -65
- package/dist/{types-uWxXh1Jm.d.ts → types-fRasDCe4.d.ts} +47 -6
- package/dist/useAnimatedLayout-C0koWm4a.d.ts +56 -0
- package/dist/{useAsyncSource-Gk0VtE7_.js → useAsyncSource-7GTcK8ep.js} +31 -1
- package/dist/{useAsyncSource-aGzrvRkI.d.ts → useAsyncSource-DbG2FSuI.d.ts} +19 -2
- package/dist/{useCombobox-D374_pT8.js → useCombobox-DIR9yoEu.js} +150 -3
- package/dist/{useTypeaheadAnnouncement-CSikDlpK.js → useTypeaheadMenuConfig--4f7jR6G.js} +264 -20
- package/package.json +1 -1
- package/styles/motion.css +10 -0
- package/styles/selector.css +10 -0
- package/styles/table.css +19 -0
- package/dist/composables-CCsHfpCS.js +0 -1256
- package/dist/{Chat-PEkZTrQE.js → Chat-Wq7e98zS.js} +1 -1
- package/dist/{CodeBlock-9Lfec8C8.js → CodeBlock-CLVXVlB7.js} +1 -1
- package/dist/{DateInput-kXAc_r5m.js → DateInput-BitZfGEY.js} +1 -1
- package/dist/{DateRangeInput-DW7IzFQM.js → DateRangeInput-kxXBsUTU.js} +1 -1
|
@@ -0,0 +1,2049 @@
|
|
|
1
|
+
import { _ as sharedMap, b as sharedWeakSet, c as parseCssEasing, g as writePresentedResolve, h as registerPresentedOffset, i as reducedMotionCrossFade, l as parseMotionRoleValue, m as clearPresentedResolve, p as batchPresented, r as cubicBezier, t as areaOf, v as sharedState, x as themeReducesMotion, y as sharedWeakMap } from "./handle-BPXdHbkr.js";
|
|
2
|
+
import { n as easeDefaults, t as durationDefaults } from "./motionTokenDefaults-EFzpiAF5.js";
|
|
3
|
+
import { n as normalizeTokenName } from "./tokenName-0U-WEH09.js";
|
|
4
|
+
//#region src/motion/linearEasing.ts
|
|
5
|
+
/**
|
|
6
|
+
* @file linearEasing.ts
|
|
7
|
+
* @input A duration and the fraction of a move done at each time
|
|
8
|
+
* @output Exports `linearEasing`, that curve as CSS `linear()` easing text,
|
|
9
|
+
* and `sampleCount`, how many samples cover a duration at 60 per second
|
|
10
|
+
* @position Pure math under the motion helpers; no DOM, no React
|
|
11
|
+
*/
|
|
12
|
+
/** Samples per second of a sampled curve: one per frame at 60 Hz. */
|
|
13
|
+
const SAMPLES_PER_SECOND = 60;
|
|
14
|
+
/** How many samples cover `durationMs`, both ends included: at least 2. */
|
|
15
|
+
function sampleCount(durationMs) {
|
|
16
|
+
return Math.max(2, Math.ceil(durationMs / 1e3 * SAMPLES_PER_SECOND) + 1);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/motion/layout/glides.ts
|
|
20
|
+
/**
|
|
21
|
+
* @file glides.ts
|
|
22
|
+
* @position Internal to motion/layout; split from upstream motion/animatedLayout.ts
|
|
23
|
+
*/
|
|
24
|
+
/** Every animation this module started, so it can tell the app's apart. */
|
|
25
|
+
const ours = sharedWeakSet("motion/animated-layout/ours", 1);
|
|
26
|
+
const glides = sharedWeakMap("motion/animated-layout/glides", 1);
|
|
27
|
+
const TRANSFORM_PROPERTIES = [
|
|
28
|
+
"transform",
|
|
29
|
+
"translate",
|
|
30
|
+
"rotate",
|
|
31
|
+
"scale"
|
|
32
|
+
];
|
|
33
|
+
/** The numbers in a CSS value, units dropped. */
|
|
34
|
+
function numbersIn(value) {
|
|
35
|
+
return (value.match(/-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/gi) ?? []).map(Number);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Whether a transform value leaves the element where it is: nothing at all
|
|
39
|
+
* (a swipe's `translate3d(0, 0, 0)` at rest, a button's `scale(1)`, computed
|
|
40
|
+
* as `matrix(1, 0, 0, 1, 0, 0)`), or a scale in place (a pressed button's
|
|
41
|
+
* `scale(0.98)`). A glide's `translate` composes with either; a translation,
|
|
42
|
+
* rotation or skew of its own is the app moving the element.
|
|
43
|
+
*/
|
|
44
|
+
function staysInPlace(property, value) {
|
|
45
|
+
if (value === "none") return true;
|
|
46
|
+
if (property === "scale") return true;
|
|
47
|
+
if (value.includes("var(")) return false;
|
|
48
|
+
if (property === "translate") return numbersIn(value).every((n) => n === 0);
|
|
49
|
+
if (property === "rotate") {
|
|
50
|
+
const numbers = numbersIn(value);
|
|
51
|
+
return numbers.length > 0 && numbers[numbers.length - 1] === 0;
|
|
52
|
+
}
|
|
53
|
+
const functions = [...value.matchAll(/([a-z0-9]+)\(([^)]*)\)/gi)];
|
|
54
|
+
return functions.length > 0 && functions.every(([, name, args]) => {
|
|
55
|
+
const numbers = numbersIn(args);
|
|
56
|
+
const fn = name.toLowerCase();
|
|
57
|
+
if (fn === "matrix") return numbers.length === 6 && [
|
|
58
|
+
1,
|
|
59
|
+
2,
|
|
60
|
+
4,
|
|
61
|
+
5
|
|
62
|
+
].every((index) => numbers[index] === 0);
|
|
63
|
+
if (fn === "matrix3d") return numbers.length === 16 && numbers.every((n, index) => index % 5 === 0 || n === 0);
|
|
64
|
+
if (fn === "rotate3d") return numbers[3] === 0;
|
|
65
|
+
if (fn.startsWith("scale")) return true;
|
|
66
|
+
if (fn.startsWith("translate") || fn.startsWith("rotate") || fn.startsWith("skew")) return numbers.every((n) => n === 0);
|
|
67
|
+
return false;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Whether the app moves `element` itself: its own `transform`, `translate`
|
|
72
|
+
* or `rotate`, or a running animation of one this module did not start. A
|
|
73
|
+
* value that leaves it in place (nothing, or a scale) is not a move.
|
|
74
|
+
*/
|
|
75
|
+
function movedByApp(element) {
|
|
76
|
+
const style = element.ownerDocument.defaultView?.getComputedStyle(element);
|
|
77
|
+
if (style != null && TRANSFORM_PROPERTIES.some((property) => {
|
|
78
|
+
const value = style.getPropertyValue(property);
|
|
79
|
+
return value !== "" && value !== "none" && !staysInPlace(property, value);
|
|
80
|
+
})) return true;
|
|
81
|
+
if (typeof element.getAnimations !== "function") return false;
|
|
82
|
+
return element.getAnimations().some((animation) => {
|
|
83
|
+
if (ours.has(animation)) return false;
|
|
84
|
+
const effect = animation.effect;
|
|
85
|
+
if (!(effect instanceof KeyframeEffect)) return false;
|
|
86
|
+
return effect.getKeyframes().some((frame) => TRANSFORM_PROPERTIES.some((property) => property in frame && !staysInPlace(property, String(frame[property]))));
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const AT_REST = () => ({
|
|
90
|
+
x: 0,
|
|
91
|
+
y: 0
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* `curve` as the browser draws it from `sampleOver`'s keyframes: a straight
|
|
95
|
+
* line between each two. A new glide then starts where the old one shows.
|
|
96
|
+
*/
|
|
97
|
+
function drawnCurve(durationMs, curve) {
|
|
98
|
+
const count = sampleCount(durationMs);
|
|
99
|
+
const points = Array.from({ length: count }, (_, i) => curve(i / (count - 1) * durationMs));
|
|
100
|
+
return (t) => {
|
|
101
|
+
const at = Math.min(Math.max(t / durationMs, 0), 1) * (count - 1);
|
|
102
|
+
const i = Math.min(Math.floor(at), count - 2);
|
|
103
|
+
const f = at - i;
|
|
104
|
+
const a = points[i];
|
|
105
|
+
const b = points[i + 1];
|
|
106
|
+
return {
|
|
107
|
+
x: a.x + (b.x - a.x) * f,
|
|
108
|
+
y: a.y + (b.y - a.y) * f
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The glide `element` is playing now, if any. For an adopter that draws
|
|
114
|
+
* something with each moving element (a table row's divider): it finds what
|
|
115
|
+
* moves without reading the DOM.
|
|
116
|
+
*/
|
|
117
|
+
function glideOf(element) {
|
|
118
|
+
return glides.get(element)?.animation ?? null;
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/motion/layout/geometry.ts
|
|
122
|
+
/**
|
|
123
|
+
* @file geometry.ts
|
|
124
|
+
* @position Internal to motion/layout; split from upstream motion/animatedLayout.ts
|
|
125
|
+
*/
|
|
126
|
+
function intersects(a, b) {
|
|
127
|
+
return a.width > 0 && a.height > 0 && a.right > b.left && a.left < b.right && a.bottom > b.top && a.top < b.bottom;
|
|
128
|
+
}
|
|
129
|
+
/** The part of the area the person can see: its box within the viewport. */
|
|
130
|
+
/** Where the area's scrolled content starts, in client px. */
|
|
131
|
+
function originOf(area) {
|
|
132
|
+
const box = area.getBoundingClientRect();
|
|
133
|
+
return {
|
|
134
|
+
x: box.left - area.scrollLeft,
|
|
135
|
+
y: box.top - area.scrollTop
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function visibleRect(area) {
|
|
139
|
+
const box = area.getBoundingClientRect();
|
|
140
|
+
const view = area.ownerDocument.defaultView;
|
|
141
|
+
const width = view?.innerWidth ?? box.right;
|
|
142
|
+
const height = view?.innerHeight ?? box.bottom;
|
|
143
|
+
const left = Math.max(box.left, 0);
|
|
144
|
+
const top = Math.max(box.top, 0);
|
|
145
|
+
return new DOMRect(left, top, Math.max(0, Math.min(box.right, width) - left), Math.max(0, Math.min(box.bottom, height) - top));
|
|
146
|
+
}
|
|
147
|
+
/** The element's rendered scale against its layout size (a scaled ancestor). */
|
|
148
|
+
function scaleOf(element, rect, own = {
|
|
149
|
+
x: 1,
|
|
150
|
+
y: 1
|
|
151
|
+
}) {
|
|
152
|
+
const html = element;
|
|
153
|
+
const x = html.offsetWidth > 0 && rect.width > 0 ? rect.width / html.offsetWidth / own.x : 1;
|
|
154
|
+
const y = html.offsetHeight > 0 && rect.height > 0 ? rect.height / html.offsetHeight / own.y : 1;
|
|
155
|
+
return {
|
|
156
|
+
x: Math.abs(x - 1) < .01 ? 1 : x || 1,
|
|
157
|
+
y: Math.abs(y - 1) < .01 ? 1 : y || 1
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The scale an element's own `scale` and `transform` give it, on each axis
|
|
162
|
+
* (a follower that keeps one in place, `staysInPlace`). A glide's `translate`
|
|
163
|
+
* does not go through them: the individual transform properties apply
|
|
164
|
+
* `translate` first, in the parent's space.
|
|
165
|
+
*/
|
|
166
|
+
function ownScaleOf(element) {
|
|
167
|
+
const style = element.ownerDocument.defaultView?.getComputedStyle(element);
|
|
168
|
+
if (style == null) return {
|
|
169
|
+
x: 1,
|
|
170
|
+
y: 1
|
|
171
|
+
};
|
|
172
|
+
let x = 1;
|
|
173
|
+
let y = 1;
|
|
174
|
+
const scale = style.getPropertyValue("scale");
|
|
175
|
+
if (scale !== "" && scale !== "none") {
|
|
176
|
+
const [sx = 1, sy = sx] = numbersIn(scale);
|
|
177
|
+
x *= Math.abs(sx);
|
|
178
|
+
y *= Math.abs(sy);
|
|
179
|
+
}
|
|
180
|
+
const matrix = /^matrix(3d)?\(([^)]*)\)/.exec(style.getPropertyValue("transform"));
|
|
181
|
+
if (matrix != null) {
|
|
182
|
+
const m = numbersIn(matrix[2]);
|
|
183
|
+
const [a = 1, b = 0, c = 0, d = 1] = matrix[1] == null ? m : [
|
|
184
|
+
m[0],
|
|
185
|
+
m[1],
|
|
186
|
+
m[4],
|
|
187
|
+
m[5]
|
|
188
|
+
];
|
|
189
|
+
x *= Math.hypot(a, b);
|
|
190
|
+
y *= Math.hypot(c, d);
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
x: x || 1,
|
|
194
|
+
y: y || 1
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/motion/layout/presented.ts
|
|
199
|
+
/**
|
|
200
|
+
* @file presented.ts
|
|
201
|
+
* @position Internal to motion/layout; split from upstream motion/animatedLayout.ts
|
|
202
|
+
*/
|
|
203
|
+
/** The glide each element reports now, so that only its end clears it. */
|
|
204
|
+
const presentedGlides = sharedWeakMap("motion/animated-layout/presented-glides", 1);
|
|
205
|
+
const glideReports = sharedState("motion/animated-layout/glide-reports", 1, () => /* @__PURE__ */ new Set());
|
|
206
|
+
/** The reports of ended glides, removed together in a later task. */
|
|
207
|
+
const endedReports = sharedState("motion/animated-layout/ended-reports", 1, () => []);
|
|
208
|
+
/**
|
|
209
|
+
* Removes the reports of ended glides with one notice to the registry's
|
|
210
|
+
* watchers. A glide in a closed window or out of its document never ends, so
|
|
211
|
+
* its report goes here too.
|
|
212
|
+
*/
|
|
213
|
+
function removeEndedReports() {
|
|
214
|
+
if (endedReports.length === 0) return;
|
|
215
|
+
batchPresented(() => {
|
|
216
|
+
for (const report of endedReports.splice(0)) report.remove();
|
|
217
|
+
for (const report of [...glideReports]) {
|
|
218
|
+
const { element } = report;
|
|
219
|
+
if (!element.isConnected || element.ownerDocument.defaultView == null) report.remove();
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/** Each keyframe's `translate` in px at its offset, or null if one has none. */
|
|
224
|
+
function translatesOf(keyframes) {
|
|
225
|
+
const points = [];
|
|
226
|
+
for (const [index, frame] of keyframes.entries()) {
|
|
227
|
+
const match = /^([\d.e+-]+)px ([\d.e+-]+)px$/.exec(String(frame.translate ?? ""));
|
|
228
|
+
if (match == null) return null;
|
|
229
|
+
points.push({
|
|
230
|
+
at: frame.offset ?? index / Math.max(1, keyframes.length - 1),
|
|
231
|
+
x: Number(match[1]),
|
|
232
|
+
y: Number(match[2])
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
return points.length > 0 ? points : null;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Reports `element` to the presented hit-test registry while its `translate`
|
|
239
|
+
* glide runs. iOS WebKit hit-tests the element where the glide started. So
|
|
240
|
+
* the gesture host resolves it at touch-down and lands the touch on what is
|
|
241
|
+
* drawn. `scale` is its ancestors' scale. An inert element, such as a swap's
|
|
242
|
+
* copy or a closing element, takes no touch, so it is not reported.
|
|
243
|
+
*/
|
|
244
|
+
function presentGlide(element, animation, keyframes, options, scale) {
|
|
245
|
+
const view = element.ownerDocument.defaultView;
|
|
246
|
+
const durationMs = Number(options.duration);
|
|
247
|
+
const points = (options.easing ?? "linear") === "linear" && options.delay == null ? translatesOf(keyframes) : null;
|
|
248
|
+
if (view == null || points == null || !(durationMs > 0) || !("style" in element) || element.closest("[inert]") != null) return;
|
|
249
|
+
const styled = element;
|
|
250
|
+
const now = () => view.performance.now();
|
|
251
|
+
const drawnAt = (time) => {
|
|
252
|
+
const start = animation.startTime;
|
|
253
|
+
const progress = start == null ? 0 : Math.min(1, Math.max(0, (time - Number(start)) / durationMs));
|
|
254
|
+
let next = 1;
|
|
255
|
+
while (next < points.length - 1 && points[next].at < progress) next += 1;
|
|
256
|
+
const from = points[next - 1] ?? points[0];
|
|
257
|
+
const to = points[next] ?? from;
|
|
258
|
+
const span = to.at - from.at;
|
|
259
|
+
const part = span > 0 ? Math.min(1, Math.max(0, (progress - from.at) / span)) : 1;
|
|
260
|
+
return {
|
|
261
|
+
x: (from.x + (to.x - from.x) * part) * scale.x,
|
|
262
|
+
y: (from.y + (to.y - from.y) * part) * scale.y
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
let hitTested = drawnAt(now());
|
|
266
|
+
let isEnded = false;
|
|
267
|
+
let isRemoved = false;
|
|
268
|
+
const glide = {};
|
|
269
|
+
presentedGlides.set(element, glide);
|
|
270
|
+
const unregister = registerPresentedOffset(element, {
|
|
271
|
+
offset: (time = now()) => {
|
|
272
|
+
if (isEnded) return {
|
|
273
|
+
x: 0,
|
|
274
|
+
y: 0
|
|
275
|
+
};
|
|
276
|
+
const drawn = drawnAt(time);
|
|
277
|
+
return {
|
|
278
|
+
x: drawn.x - hitTested.x,
|
|
279
|
+
y: drawn.y - hitTested.y
|
|
280
|
+
};
|
|
281
|
+
},
|
|
282
|
+
resolve: () => {
|
|
283
|
+
if (!isEnded) {
|
|
284
|
+
writePresentedResolve(styled);
|
|
285
|
+
hitTested = drawnAt(now());
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
const report = {
|
|
290
|
+
element,
|
|
291
|
+
remove: () => {
|
|
292
|
+
if (isRemoved) return;
|
|
293
|
+
isRemoved = true;
|
|
294
|
+
glideReports.delete(report);
|
|
295
|
+
unregister();
|
|
296
|
+
if (presentedGlides.get(element) === glide) {
|
|
297
|
+
presentedGlides.delete(element);
|
|
298
|
+
clearPresentedResolve(styled);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
glideReports.add(report);
|
|
303
|
+
const end = () => {
|
|
304
|
+
if (isEnded) return;
|
|
305
|
+
isEnded = true;
|
|
306
|
+
endedReports.push(report);
|
|
307
|
+
setTimeout(removeEndedReports, 0);
|
|
308
|
+
};
|
|
309
|
+
animation.addEventListener?.("finish", end);
|
|
310
|
+
animation.addEventListener?.("cancel", end);
|
|
311
|
+
return () => {
|
|
312
|
+
if (!isEnded && presentedGlides.get(element) === glide) hitTested = drawnAt(now());
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/motion/layout/settle.ts
|
|
317
|
+
/** How near its end, px or percent, an animated value counts as there. */
|
|
318
|
+
const SETTLED_PX = .5;
|
|
319
|
+
/** How near its end an animated value with no unit, an opacity, counts. */
|
|
320
|
+
const SETTLED_RATIO = .005;
|
|
321
|
+
/** Keyframe members that time a keyframe rather than style it. */
|
|
322
|
+
const KEYFRAME_TIMING = /* @__PURE__ */ new Set([
|
|
323
|
+
"offset",
|
|
324
|
+
"computedOffset",
|
|
325
|
+
"easing",
|
|
326
|
+
"composite"
|
|
327
|
+
]);
|
|
328
|
+
/** Whether a CSS value is within the settle tolerance of `end`. */
|
|
329
|
+
function isNearEnd(value, end) {
|
|
330
|
+
const numbers = (text) => [...String(text ?? "").matchAll(/(-?\d*\.?\d+(?:e[+-]?\d+)?)([a-z%]*)/gi)];
|
|
331
|
+
const ats = numbers(value);
|
|
332
|
+
const ends = numbers(end);
|
|
333
|
+
return ats.length === ends.length && ats.every(([, at, unit], index) => {
|
|
334
|
+
const tolerance = ["px", "%"].includes(unit.toLowerCase()) ? SETTLED_PX : SETTLED_RATIO;
|
|
335
|
+
return Math.abs(Number(at) - Number(ends[index][1])) <= tolerance;
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* The offset from which linear `keyframes` stay near their last one, or null
|
|
340
|
+
* when only the last one is.
|
|
341
|
+
*/
|
|
342
|
+
function settledOffset(keyframes) {
|
|
343
|
+
const last = keyframes[keyframes.length - 1];
|
|
344
|
+
if (last == null) return null;
|
|
345
|
+
const styles = Object.keys(last).filter((key) => !KEYFRAME_TIMING.has(key));
|
|
346
|
+
let from = null;
|
|
347
|
+
for (let index = keyframes.length - 2; index >= 0; index -= 1) {
|
|
348
|
+
const frame = keyframes[index];
|
|
349
|
+
if (!styles.every((key) => isNearEnd(frame[key], last[key]))) break;
|
|
350
|
+
from = frame.offset ?? index / (keyframes.length - 1);
|
|
351
|
+
}
|
|
352
|
+
return from;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* When an animation's sampled linear frames come within reach of their end,
|
|
356
|
+
* ms, or null. An eased two-keyframe fade, the Reduce Motion one, has none:
|
|
357
|
+
* WebKit draws its end values at its end.
|
|
358
|
+
*/
|
|
359
|
+
function settleTime(keyframes, timing) {
|
|
360
|
+
const duration = Number(timing.duration);
|
|
361
|
+
const fraction = (timing.easing ?? "linear") === "linear" ? settledOffset(keyframes) : null;
|
|
362
|
+
return fraction == null || !(duration > 0) ? null : (timing.delay ?? 0) + fraction * duration;
|
|
363
|
+
}
|
|
364
|
+
/** Each window's motions that have not settled yet, read once a frame. */
|
|
365
|
+
const settling = sharedWeakMap("motion/animated-layout/settling", 1);
|
|
366
|
+
/**
|
|
367
|
+
* Reads `entry` in each frame until it is done or its element leaves its
|
|
368
|
+
* document. One frame loop per window runs while any motion waits. Returns
|
|
369
|
+
* the stop.
|
|
370
|
+
*/
|
|
371
|
+
function watchSettle(view, entry) {
|
|
372
|
+
if (typeof view.requestAnimationFrame !== "function") return () => {};
|
|
373
|
+
let waiting = settling.get(view);
|
|
374
|
+
if (waiting == null) {
|
|
375
|
+
const entries = /* @__PURE__ */ new Set();
|
|
376
|
+
waiting = entries;
|
|
377
|
+
settling.set(view, entries);
|
|
378
|
+
const frame = () => {
|
|
379
|
+
for (const next of entries) if (!next.element.isConnected || next.frame()) entries.delete(next);
|
|
380
|
+
if (entries.size === 0) {
|
|
381
|
+
settling.delete(view);
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
view.requestAnimationFrame(frame);
|
|
385
|
+
};
|
|
386
|
+
view.requestAnimationFrame(frame);
|
|
387
|
+
}
|
|
388
|
+
const entries = waiting;
|
|
389
|
+
entries.add(entry);
|
|
390
|
+
return () => {
|
|
391
|
+
entries.delete(entry);
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
/** Each running animation's retime, for a ride that replaces its frames. */
|
|
395
|
+
const settleRetimes = sharedWeakMap("motion/animated-layout/settle-retimes", 1);
|
|
396
|
+
/**
|
|
397
|
+
* WebKit can draw a compositor animation's last frame with the values it last
|
|
398
|
+
* resolved for the element (presentation.ts). Every frame of a long task over
|
|
399
|
+
* its end can show them too. It resolved them at the start or at a later
|
|
400
|
+
* style write. One resolve once the animation is drawn near its end makes that
|
|
401
|
+
* frame its end. `onResolve` hears it, for a reported glide's hit test.
|
|
402
|
+
* Review condition: re-measure on each WebKit release, and remove these
|
|
403
|
+
* resolves once WebKit draws an ended compositor animation at its final
|
|
404
|
+
* values.
|
|
405
|
+
*/
|
|
406
|
+
function settleAnimation(element, animation, keyframes, options, onResolve) {
|
|
407
|
+
const view = element.ownerDocument.defaultView;
|
|
408
|
+
if (view == null || !("style" in element)) return;
|
|
409
|
+
const styled = element;
|
|
410
|
+
let at = settleTime(keyframes, options);
|
|
411
|
+
let isWritten = false;
|
|
412
|
+
settleRetimes.set(animation, (next, durationMs) => {
|
|
413
|
+
at = settleTime(next, {
|
|
414
|
+
...options,
|
|
415
|
+
duration: durationMs
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
const stop = watchSettle(view, {
|
|
419
|
+
element,
|
|
420
|
+
frame: () => {
|
|
421
|
+
if (at == null) return true;
|
|
422
|
+
if (!(animation.currentTime != null ? Number(animation.currentTime) >= at : animation.startTime != null && view.performance.now() >= Number(animation.startTime) + at)) return false;
|
|
423
|
+
writePresentedResolve(styled);
|
|
424
|
+
isWritten = true;
|
|
425
|
+
onResolve?.();
|
|
426
|
+
return true;
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
const end = () => {
|
|
430
|
+
stop();
|
|
431
|
+
settleRetimes.delete(animation);
|
|
432
|
+
if (isWritten && onResolve == null) clearPresentedResolve(styled);
|
|
433
|
+
};
|
|
434
|
+
animation.addEventListener?.("finish", end);
|
|
435
|
+
animation.addEventListener?.("cancel", end);
|
|
436
|
+
}
|
|
437
|
+
/** Retimes `animation`'s settle after a ride replaced its frames. */
|
|
438
|
+
function retimeSettle(animation, keyframes, durationMs) {
|
|
439
|
+
settleRetimes.get(animation)?.(keyframes, durationMs);
|
|
440
|
+
}
|
|
441
|
+
/** Each indicator's settle, stopped when the next change retimes it. */
|
|
442
|
+
const transitionSettles = sharedWeakMap("motion/animated-layout/transition-settles", 1);
|
|
443
|
+
/**
|
|
444
|
+
* An indicator's CSS transition runs on the compositor too, so it resolves
|
|
445
|
+
* once as it settles. Its time is read from the page's clock from now, when
|
|
446
|
+
* the change starts it: reading the transition itself would flush style.
|
|
447
|
+
*/
|
|
448
|
+
function settleTransition(element, progress) {
|
|
449
|
+
transitionSettles.get(element)?.();
|
|
450
|
+
transitionSettles.delete(element);
|
|
451
|
+
const view = element.ownerDocument.defaultView;
|
|
452
|
+
const { durationMs } = progress;
|
|
453
|
+
const count = sampleCount(durationMs);
|
|
454
|
+
let settled = null;
|
|
455
|
+
for (let index = count - 2; index >= 0; index -= 1) {
|
|
456
|
+
const at = index / (count - 1) * durationMs;
|
|
457
|
+
if (Math.abs(progress.remaining(at)) > SETTLED_RATIO) break;
|
|
458
|
+
settled = at;
|
|
459
|
+
}
|
|
460
|
+
if (view == null || settled == null || !(durationMs > 0)) return;
|
|
461
|
+
const start = view.performance.now();
|
|
462
|
+
const settleAt = start + settled;
|
|
463
|
+
const endAt = start + durationMs;
|
|
464
|
+
let isWritten = false;
|
|
465
|
+
const clear = () => {
|
|
466
|
+
transitionSettles.delete(element);
|
|
467
|
+
if (isWritten) {
|
|
468
|
+
clearPresentedResolve(element);
|
|
469
|
+
isWritten = false;
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
const stop = watchSettle(view, {
|
|
473
|
+
element,
|
|
474
|
+
frame: () => {
|
|
475
|
+
const now = view.performance.now();
|
|
476
|
+
if (!isWritten && now >= settleAt) {
|
|
477
|
+
writePresentedResolve(element);
|
|
478
|
+
isWritten = true;
|
|
479
|
+
}
|
|
480
|
+
if (now < endAt) return false;
|
|
481
|
+
clear();
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
transitionSettles.set(element, () => {
|
|
486
|
+
stop();
|
|
487
|
+
clear();
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
//#endregion
|
|
491
|
+
//#region src/motion/layout/play.ts
|
|
492
|
+
/**
|
|
493
|
+
* @file play.ts
|
|
494
|
+
* @position Internal to motion/layout; split from upstream motion/animatedLayout.ts
|
|
495
|
+
*/
|
|
496
|
+
/**
|
|
497
|
+
* Play `keyframes` on `element`. Every option here (linear easing over sampled
|
|
498
|
+
* keyframes, replace composition) is one any Web Animations engine takes, so
|
|
499
|
+
* a failure means no Web Animations at all: the change then lands at once.
|
|
500
|
+
* `scale` is the element's ancestors' scale, for a `translate` glide.
|
|
501
|
+
*/
|
|
502
|
+
function safeAnimate(element, keyframes, options, change, scale = {
|
|
503
|
+
x: 1,
|
|
504
|
+
y: 1
|
|
505
|
+
}) {
|
|
506
|
+
if (typeof element.animate !== "function") return null;
|
|
507
|
+
let animation;
|
|
508
|
+
try {
|
|
509
|
+
animation = element.animate(keyframes, options);
|
|
510
|
+
} catch {
|
|
511
|
+
return null;
|
|
512
|
+
}
|
|
513
|
+
ours.add(animation);
|
|
514
|
+
const doc = element.ownerDocument;
|
|
515
|
+
const now = doc.timeline?.currentTime;
|
|
516
|
+
if (now != null) {
|
|
517
|
+
const start = change != null && change.frame === Number(now) ? change : startFor(doc, Number(now));
|
|
518
|
+
start.last = clockOf(doc);
|
|
519
|
+
animation.startTime = start.at;
|
|
520
|
+
if (start.at !== Number(now)) {
|
|
521
|
+
const fill = animation.effect?.getTiming().fill;
|
|
522
|
+
animation.effect?.updateTiming({ fill: fill === "forwards" || fill === "both" ? "both" : "backwards" });
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
const onResolve = options.pseudoElement == null ? presentGlide(element, animation, keyframes, options, scale) : void 0;
|
|
526
|
+
settleAnimation(element, animation, keyframes, options, onResolve);
|
|
527
|
+
return animation;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Each document's change start: an iframe or a Picture-in-Picture window
|
|
531
|
+
* keeps its own clock, with its own origin and frames.
|
|
532
|
+
*/
|
|
533
|
+
const changeStarts = sharedWeakMap("motion/animated-layout/change-starts", 1);
|
|
534
|
+
/** The clock of the document whose timeline a start is read on. */
|
|
535
|
+
function clockOf(doc) {
|
|
536
|
+
return (doc.defaultView?.performance ?? performance).now();
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* The start the current change's animations share. A change keeps one start
|
|
540
|
+
* from its first animation through the flush of its glides and the parts that
|
|
541
|
+
* ride them. That holds however long the work between them runs, such as the
|
|
542
|
+
* rest of a commit or a slow swap. The start holds while the timeline reads
|
|
543
|
+
* the same frame: through the task that made it and the microtasks after it.
|
|
544
|
+
* A change that begins after a block takes a start of its own (beginChange).
|
|
545
|
+
*/
|
|
546
|
+
function startFor(doc, frame) {
|
|
547
|
+
const now = clockOf(doc);
|
|
548
|
+
const held = changeStarts.get(doc);
|
|
549
|
+
if (held != null && held.frame === frame) {
|
|
550
|
+
held.last = now;
|
|
551
|
+
return held;
|
|
552
|
+
}
|
|
553
|
+
const start = {
|
|
554
|
+
frame,
|
|
555
|
+
at: now - frame <= 34 ? frame : now,
|
|
556
|
+
last: now
|
|
557
|
+
};
|
|
558
|
+
changeStarts.set(doc, start);
|
|
559
|
+
(doc.defaultView?.setTimeout ?? setTimeout)(() => {
|
|
560
|
+
if (changeStarts.get(doc) === start) changeStarts.delete(doc);
|
|
561
|
+
}, 0);
|
|
562
|
+
return start;
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* A change begins as its "before" is read. After a block since the last
|
|
566
|
+
* animation of the change before it, it takes a start of its own. So a change
|
|
567
|
+
* made after a block that follows an earlier layout motion still plays.
|
|
568
|
+
* Changes made together, with no block between them, share one start.
|
|
569
|
+
*/
|
|
570
|
+
function beginChange(doc) {
|
|
571
|
+
const held = changeStarts.get(doc);
|
|
572
|
+
if (held != null && clockOf(doc) - held.last > 34) changeStarts.delete(doc);
|
|
573
|
+
}
|
|
574
|
+
//#endregion
|
|
575
|
+
//#region src/Theme/tokenReferences.ts
|
|
576
|
+
/**
|
|
577
|
+
* @file tokenReferences.ts
|
|
578
|
+
* @input A flat map of token names to raw CSS values
|
|
579
|
+
* @output `resolveTokenReferences`, which follows `var(--name[, fallback])`
|
|
580
|
+
* references through the map
|
|
581
|
+
* @position Theme utility with no imports: themeMotion.ts resolves motion
|
|
582
|
+
* tokens written as references on it, and the motion foundation resolves
|
|
583
|
+
* the declared timing defaults on it. Pure; safe on the server.
|
|
584
|
+
*/
|
|
585
|
+
/**
|
|
586
|
+
* Call `visit` for each top-level character of a CSS value. A top-level
|
|
587
|
+
* character is outside parentheses and outside quoted strings. In a quoted
|
|
588
|
+
* string, a backslash escapes the next character. The scan stops when `visit`
|
|
589
|
+
* returns true.
|
|
590
|
+
*/
|
|
591
|
+
function scanTopLevel(input, visit) {
|
|
592
|
+
let depth = 0;
|
|
593
|
+
let quote = null;
|
|
594
|
+
let isEscaped = false;
|
|
595
|
+
for (let i = 0; i < input.length; i++) {
|
|
596
|
+
const char = input[i];
|
|
597
|
+
if (quote !== null) {
|
|
598
|
+
if (isEscaped) isEscaped = false;
|
|
599
|
+
else if (char === "\\") isEscaped = true;
|
|
600
|
+
else if (char === quote) quote = null;
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
if (char === "\"" || char === "'") {
|
|
604
|
+
quote = char;
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
if (char === "(") {
|
|
608
|
+
depth++;
|
|
609
|
+
continue;
|
|
610
|
+
}
|
|
611
|
+
if (char === ")") {
|
|
612
|
+
depth = Math.max(0, depth - 1);
|
|
613
|
+
continue;
|
|
614
|
+
}
|
|
615
|
+
if (depth === 0 && visit(i)) return;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Split the arguments of a CSS function body on the first top-level comma.
|
|
620
|
+
* Handles nested functions such as rgba(), color-mix(), var(), and quoted strings.
|
|
621
|
+
*/
|
|
622
|
+
function splitTopLevelComma(input) {
|
|
623
|
+
let split = null;
|
|
624
|
+
scanTopLevel(input, (i) => {
|
|
625
|
+
if (input[i] !== ",") return false;
|
|
626
|
+
split = [input.slice(0, i).trim(), input.slice(i + 1).trim()];
|
|
627
|
+
return true;
|
|
628
|
+
});
|
|
629
|
+
return split;
|
|
630
|
+
}
|
|
631
|
+
/** Index of the `)` matching the `(` at `openIndex`, or -1 when unbalanced. */
|
|
632
|
+
function findMatchingParen(input, openIndex) {
|
|
633
|
+
let depth = 0;
|
|
634
|
+
for (let i = openIndex; i < input.length; i++) {
|
|
635
|
+
const char = input[i];
|
|
636
|
+
if (char === "(") depth++;
|
|
637
|
+
else if (char === ")") {
|
|
638
|
+
depth--;
|
|
639
|
+
if (depth === 0) return i;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return -1;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Resolves every value in `raw` to a concrete one: each `var(--name[,
|
|
646
|
+
* fallback])` is replaced by `name`'s resolved value, or by its fallback when
|
|
647
|
+
* `raw` has no `name`, and is kept as written when neither exists or the
|
|
648
|
+
* references form a cycle.
|
|
649
|
+
*/
|
|
650
|
+
function resolveTokenReferences(raw) {
|
|
651
|
+
const cache = {};
|
|
652
|
+
const substitute = (expr, seen) => {
|
|
653
|
+
const start = expr.indexOf("var(");
|
|
654
|
+
if (start === -1) return expr;
|
|
655
|
+
const openIndex = start + 3;
|
|
656
|
+
const closeIndex = findMatchingParen(expr, openIndex);
|
|
657
|
+
if (closeIndex === -1) return expr;
|
|
658
|
+
const inner = expr.slice(openIndex + 1, closeIndex);
|
|
659
|
+
const commaSplit = splitTopLevelComma(inner);
|
|
660
|
+
const name = (commaSplit ? commaSplit[0] : inner).trim();
|
|
661
|
+
const fallback = commaSplit ? commaSplit[1] : null;
|
|
662
|
+
let replacement;
|
|
663
|
+
if (seen.has(name)) replacement = expr.slice(start, closeIndex + 1);
|
|
664
|
+
else if (name in raw) {
|
|
665
|
+
seen.add(name);
|
|
666
|
+
replacement = reference(name, seen);
|
|
667
|
+
seen.delete(name);
|
|
668
|
+
} else if (fallback !== null) replacement = substitute(fallback.trim(), seen);
|
|
669
|
+
else replacement = expr.slice(start, closeIndex + 1);
|
|
670
|
+
const rest = substitute(expr.slice(closeIndex + 1), seen);
|
|
671
|
+
return expr.slice(0, start) + replacement + rest;
|
|
672
|
+
};
|
|
673
|
+
const reference = (name, seen) => {
|
|
674
|
+
if (name in cache) return cache[name];
|
|
675
|
+
const value = raw[name];
|
|
676
|
+
if (value === void 0) return "";
|
|
677
|
+
const resolved = value.includes("var(") ? substitute(value, seen) : value;
|
|
678
|
+
cache[name] = resolved;
|
|
679
|
+
return resolved;
|
|
680
|
+
};
|
|
681
|
+
for (const name of Object.keys(raw)) reference(name, /* @__PURE__ */ new Set());
|
|
682
|
+
return cache;
|
|
683
|
+
}
|
|
684
|
+
//#endregion
|
|
685
|
+
//#region src/motion/themeTiming.ts
|
|
686
|
+
/**
|
|
687
|
+
* The value `@astryx-vue/themes` declares for each timing token, by its
|
|
688
|
+
* unprefixed name. A page without the stylesheet reads these.
|
|
689
|
+
*/
|
|
690
|
+
const declaredTimingTokens = {
|
|
691
|
+
...durationDefaults,
|
|
692
|
+
...easeDefaults
|
|
693
|
+
};
|
|
694
|
+
/**
|
|
695
|
+
* The eased progress from 0 to 1 over `seconds`, as a MotionCurve whose
|
|
696
|
+
* velocity is in progress per second. A curve of no length is at its end.
|
|
697
|
+
* With `jumps`, a jump in the easing, as in `steps()`, carries no speed. The
|
|
698
|
+
* gentler of the slopes just before and just after counts.
|
|
699
|
+
*/
|
|
700
|
+
function easedProgress(seconds, ease, { jumps = false } = {}) {
|
|
701
|
+
const at = (t) => seconds <= 0 || t >= seconds ? 1 : ease(Math.max(0, t) / seconds);
|
|
702
|
+
const step = Math.min(.001, seconds / 100);
|
|
703
|
+
return {
|
|
704
|
+
duration: seconds,
|
|
705
|
+
at,
|
|
706
|
+
velocity: (t) => {
|
|
707
|
+
if (seconds <= 0 || t >= seconds) return 0;
|
|
708
|
+
const before = Math.max(0, t - step);
|
|
709
|
+
const after = Math.min(seconds, t + step);
|
|
710
|
+
if (!jumps) return (at(after) - at(before)) / (after - before);
|
|
711
|
+
const here = at(t);
|
|
712
|
+
const slopes = [];
|
|
713
|
+
if (t > before) slopes.push((here - at(before)) / (t - before));
|
|
714
|
+
if (after > t) slopes.push((at(after) - here) / (after - t));
|
|
715
|
+
return slopes.reduce((a, b) => Math.abs(b) < Math.abs(a) ? b : a);
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
function firstDurationMs(style) {
|
|
720
|
+
return parseMotionRoleValue("duration", style.transitionDuration.split(",")[0] ?? "");
|
|
721
|
+
}
|
|
722
|
+
/** The first transition's easing in a computed style, as the style writes it. */
|
|
723
|
+
function firstEasingText(style) {
|
|
724
|
+
return style.transitionTimingFunction.split(/,(?![^(]*\))/)[0] ?? "";
|
|
725
|
+
}
|
|
726
|
+
/** The first transition's easing in a computed style. */
|
|
727
|
+
function firstEasing(style) {
|
|
728
|
+
return parseCssEasing(firstEasingText(style));
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* The easing `text` as the browser plays it. A paused animation with that
|
|
732
|
+
* easing gives its eased progress at each time it is set to. This reads an
|
|
733
|
+
* easing that is not a cubic Bézier, such as `linear()` or `steps()`. Null
|
|
734
|
+
* when the browser plays no such easing, or has no Web Animations.
|
|
735
|
+
*/
|
|
736
|
+
function browserEasing(doc, text) {
|
|
737
|
+
const view = doc.defaultView;
|
|
738
|
+
if (typeof view?.Animation !== "function" || typeof view.KeyframeEffect !== "function") return null;
|
|
739
|
+
let animation;
|
|
740
|
+
try {
|
|
741
|
+
animation = new view.Animation(new view.KeyframeEffect(null, null, {
|
|
742
|
+
duration: 1e3,
|
|
743
|
+
easing: text,
|
|
744
|
+
fill: "both"
|
|
745
|
+
}), null);
|
|
746
|
+
} catch {
|
|
747
|
+
return null;
|
|
748
|
+
}
|
|
749
|
+
return (x) => {
|
|
750
|
+
animation.currentTime = Math.min(1, Math.max(0, x)) * 1e3;
|
|
751
|
+
return animation.effect?.getComputedTiming().progress ?? 1;
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* The curve for a duration and an easing, or null if either cannot play. An
|
|
756
|
+
* easing that is not a cubic Bézier plays as the browser plays `easing`, and
|
|
757
|
+
* a jump in it carries no speed.
|
|
758
|
+
*/
|
|
759
|
+
function progressOf(doc, { ms, points }, easing) {
|
|
760
|
+
if (ms == null || ms <= 0) return null;
|
|
761
|
+
if (points != null) return easedProgress(ms / 1e3, cubicBezier(points));
|
|
762
|
+
const ease = browserEasing(doc, easing);
|
|
763
|
+
return ease == null ? null : easedProgress(ms / 1e3, ease, { jumps: true });
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* A duration and an easing written in CSS, resolved as a transition resolves
|
|
767
|
+
* them where `element` is. A plain time or easing parses as written. Other
|
|
768
|
+
* text, such as `calc()`, resolves on a hidden probe's transition. The
|
|
769
|
+
* duration is null when it is not a time of zero or more. The easing is null
|
|
770
|
+
* when it is not a cubic Bézier. A value left out gives null.
|
|
771
|
+
*/
|
|
772
|
+
function resolveTiming(element, { duration, easing }) {
|
|
773
|
+
const plainMs = duration == null ? null : parseMotionRoleValue("duration", duration);
|
|
774
|
+
const plainPoints = easing == null ? null : parseCssEasing(easing);
|
|
775
|
+
const doc = element.ownerDocument;
|
|
776
|
+
const view = doc.defaultView;
|
|
777
|
+
const needsMs = duration != null && plainMs == null;
|
|
778
|
+
const needsPoints = easing != null && plainPoints == null;
|
|
779
|
+
if (view == null || !needsMs && !needsPoints) return {
|
|
780
|
+
ms: plainMs,
|
|
781
|
+
points: plainPoints
|
|
782
|
+
};
|
|
783
|
+
const probe = doc.createElement("span");
|
|
784
|
+
probe.style.setProperty("display", "none", "important");
|
|
785
|
+
const takes = (property, value) => {
|
|
786
|
+
probe.style.setProperty(property, value, "important");
|
|
787
|
+
return probe.style.getPropertyValue(property) !== "";
|
|
788
|
+
};
|
|
789
|
+
const hasMs = needsMs && takes("transition-duration", duration);
|
|
790
|
+
const hasPoints = needsPoints && takes("transition-timing-function", easing);
|
|
791
|
+
(doc.body ?? doc.documentElement).append(probe);
|
|
792
|
+
try {
|
|
793
|
+
const style = view.getComputedStyle(probe);
|
|
794
|
+
return {
|
|
795
|
+
ms: hasMs ? firstDurationMs(style) : plainMs,
|
|
796
|
+
points: hasPoints ? firstEasing(style) : plainPoints
|
|
797
|
+
};
|
|
798
|
+
} finally {
|
|
799
|
+
probe.remove();
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* The value of `token` in `style`, which carries it with the `--astryx-`
|
|
804
|
+
* prefix. With none, it is the declared default, and the references in that
|
|
805
|
+
* default read their own tokens in `style` too.
|
|
806
|
+
*/
|
|
807
|
+
function tokenValue(style, token) {
|
|
808
|
+
const own = style.getPropertyValue(normalizeTokenName(token)).trim();
|
|
809
|
+
if (own !== "") return own;
|
|
810
|
+
const declared = {};
|
|
811
|
+
for (const [name, value] of Object.entries(declaredTimingTokens)) declared[name] = style.getPropertyValue(normalizeTokenName(name)).trim() || value;
|
|
812
|
+
return resolveTokenReferences(declared)[token] ?? "";
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* The text of a timing token where `element` is: its value there, or the
|
|
816
|
+
* default the theme declares, with that default's references read there too. It
|
|
817
|
+
* holds no reference, so another element that takes it plays the same timing.
|
|
818
|
+
*/
|
|
819
|
+
function readThemeTokenText(element, token) {
|
|
820
|
+
const style = element.ownerDocument.defaultView?.getComputedStyle(element);
|
|
821
|
+
return style == null ? null : tokenValue(style, token);
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* The eased progress from 0 to 1 that times a motion of `element`, as a
|
|
825
|
+
* MotionCurve whose velocity is in progress per second. With no tokens, it
|
|
826
|
+
* reads the element's own transition, where its stylesheet applies the
|
|
827
|
+
* theme's tokens. With tokens, it reads them as readThemeTokens does. Null
|
|
828
|
+
* when the duration is not a positive length or the browser plays no such
|
|
829
|
+
* easing: the caller decides what that motion does.
|
|
830
|
+
*/
|
|
831
|
+
function readThemeTiming(element, tokens) {
|
|
832
|
+
const doc = element.ownerDocument;
|
|
833
|
+
const style = doc.defaultView?.getComputedStyle(element);
|
|
834
|
+
if (style == null) return null;
|
|
835
|
+
if (tokens != null) {
|
|
836
|
+
const easing = tokenValue(style, tokens.easing);
|
|
837
|
+
return progressOf(doc, resolveTiming(element, {
|
|
838
|
+
duration: tokenValue(style, tokens.duration),
|
|
839
|
+
easing
|
|
840
|
+
}), easing);
|
|
841
|
+
}
|
|
842
|
+
const easing = firstEasingText(style);
|
|
843
|
+
return progressOf(doc, {
|
|
844
|
+
ms: firstDurationMs(style),
|
|
845
|
+
points: parseCssEasing(easing)
|
|
846
|
+
}, easing);
|
|
847
|
+
}
|
|
848
|
+
/** The touch cross-fade's cap (`design:reduced-motion` DR2). */
|
|
849
|
+
const CROSS_FADE_CAP_MS = 200;
|
|
850
|
+
function matches(element, query) {
|
|
851
|
+
const view = element.ownerDocument.defaultView;
|
|
852
|
+
return typeof view?.matchMedia === "function" && view.matchMedia(query).matches;
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* The theme's move curve over its medium duration where `area` is:
|
|
856
|
+
* one value for the glide, the changed element and the indicator. The tokens
|
|
857
|
+
* carry the theme's `character` and `tempo`. Null when the duration is zero
|
|
858
|
+
* or the browser plays no such easing, and then the change lands at once.
|
|
859
|
+
*/
|
|
860
|
+
function glideProgress(area) {
|
|
861
|
+
const curve = readThemeTiming(area, {
|
|
862
|
+
duration: "--duration-medium",
|
|
863
|
+
easing: "--ease-move"
|
|
864
|
+
});
|
|
865
|
+
const easing = readThemeTokenText(area, "--ease-move");
|
|
866
|
+
if (curve == null || easing == null) return null;
|
|
867
|
+
const durationMs = curve.duration * 1e3;
|
|
868
|
+
return {
|
|
869
|
+
durationMs,
|
|
870
|
+
easing,
|
|
871
|
+
remaining: (t) => t >= durationMs ? 0 : 1 - curve.at(t / 1e3)
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
const releaseGlides = sharedWeakMap("motion/animated-layout/release-glides", 1);
|
|
875
|
+
function releaseGlideFor(area) {
|
|
876
|
+
for (let at = area; at != null; at = at.parentElement) {
|
|
877
|
+
const progress = releaseGlides.get(at);
|
|
878
|
+
if (progress != null) return progress;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
/** The motion a change in `area` plays now. */
|
|
882
|
+
function layoutMotion(area) {
|
|
883
|
+
if (matches(area, "(prefers-reduced-motion: reduce)") || themeReducesMotion(area)) {
|
|
884
|
+
if (!matches(area, "(pointer: coarse)")) return { kind: "instant" };
|
|
885
|
+
const [x1, y1, x2, y2] = reducedMotionCrossFade.curve;
|
|
886
|
+
return {
|
|
887
|
+
kind: "fade",
|
|
888
|
+
durationMs: Math.min(CROSS_FADE_CAP_MS, reducedMotionCrossFade.durationMs),
|
|
889
|
+
easing: `cubic-bezier(${x1}, ${y1}, ${x2}, ${y2})`
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
const progress = releaseGlideFor(area) ?? glideProgress(area);
|
|
893
|
+
return progress == null ? { kind: "instant" } : {
|
|
894
|
+
kind: "glide",
|
|
895
|
+
progress
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
/** Linear keyframes over `durationMs`, one per frame, from `frame(t ms)`. */
|
|
899
|
+
function sampleOver(durationMs, frame) {
|
|
900
|
+
const count = sampleCount(durationMs);
|
|
901
|
+
const keyframes = [];
|
|
902
|
+
for (let i = 0; i < count; i++) {
|
|
903
|
+
const offset = i / (count - 1);
|
|
904
|
+
keyframes.push({
|
|
905
|
+
...frame(offset * durationMs),
|
|
906
|
+
offset
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
return keyframes;
|
|
910
|
+
}
|
|
911
|
+
/** Linear keyframes sampled from the move curve, one per frame. */
|
|
912
|
+
function sampleKeyframes(progress, frame) {
|
|
913
|
+
return sampleOver(progress.durationMs, (t) => frame(progress.remaining(t)));
|
|
914
|
+
}
|
|
915
|
+
function round(value) {
|
|
916
|
+
return Math.round(value * 1e3) / 1e3;
|
|
917
|
+
}
|
|
918
|
+
//#endregion
|
|
919
|
+
//#region src/motion/layout/walk.ts
|
|
920
|
+
/**
|
|
921
|
+
* Whether `element` takes part: in flow, rendered, not in the top layer.
|
|
922
|
+
* `display: contents` is handled by the caller.
|
|
923
|
+
*/
|
|
924
|
+
function takesPart(element, style) {
|
|
925
|
+
if (style.display === "none" || style.visibility === "hidden" || style.position === "absolute" || style.position === "fixed") return false;
|
|
926
|
+
try {
|
|
927
|
+
if (element.matches(":popover-open, :modal")) return false;
|
|
928
|
+
} catch {}
|
|
929
|
+
return true;
|
|
930
|
+
}
|
|
931
|
+
function bandFor(visible, reach) {
|
|
932
|
+
return {
|
|
933
|
+
start: visible.top - reach,
|
|
934
|
+
end: visible.bottom + reach
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
function partOf(element, cache) {
|
|
938
|
+
let part = cache.parts.get(element);
|
|
939
|
+
if (part === void 0) {
|
|
940
|
+
const style = element.ownerDocument.defaultView?.getComputedStyle(element);
|
|
941
|
+
part = style == null ? false : style.display === "contents" ? "contents" : takesPart(element, style);
|
|
942
|
+
cache.parts.set(element, part);
|
|
943
|
+
}
|
|
944
|
+
return part;
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Whether a container lays its children out across the block direction, so
|
|
948
|
+
* DOM order does not run down the page: multi-column, a wrapping column flex
|
|
949
|
+
* box, or a grid that flows by column. The band says nothing about where its
|
|
950
|
+
* later children sit, so a walk there runs through the level.
|
|
951
|
+
*/
|
|
952
|
+
function flowsAcross(container) {
|
|
953
|
+
if (container == null) return false;
|
|
954
|
+
const style = container.ownerDocument.defaultView?.getComputedStyle(container);
|
|
955
|
+
if (style == null) return false;
|
|
956
|
+
const count = style.getPropertyValue("column-count");
|
|
957
|
+
const width = style.getPropertyValue("column-width");
|
|
958
|
+
return count !== "" && count !== "auto" || width !== "" && width !== "auto" || style.display.includes("flex") && style.flexDirection.startsWith("column") && style.flexWrap.startsWith("wrap") || style.display.includes("grid") && style.getPropertyValue("grid-auto-flow").startsWith("column");
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* The box a sticky element sticks to: its nearest scrolling ancestor's, or
|
|
962
|
+
* the viewport.
|
|
963
|
+
*/
|
|
964
|
+
function scrollportOf(element) {
|
|
965
|
+
const view = element.ownerDocument.defaultView;
|
|
966
|
+
for (let node = element.parentElement; node != null && node !== element.ownerDocument.documentElement; node = node.parentElement) {
|
|
967
|
+
const overflow = view?.getComputedStyle(node).overflowY ?? "visible";
|
|
968
|
+
if (node === element.ownerDocument.body && view?.getComputedStyle(element.ownerDocument.documentElement).overflowY === "visible") continue;
|
|
969
|
+
if (overflow !== "visible" && overflow !== "clip") {
|
|
970
|
+
const box = node.getBoundingClientRect();
|
|
971
|
+
return {
|
|
972
|
+
start: box.top + node.clientTop,
|
|
973
|
+
end: box.top + node.clientTop + node.clientHeight
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
return {
|
|
978
|
+
start: 0,
|
|
979
|
+
end: view?.innerHeight ?? 0
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* Whether a sticky element is stuck: resting against its scrollport's edge
|
|
984
|
+
* at its inset. A stuck element takes its final place; an unstuck one is in
|
|
985
|
+
* flow.
|
|
986
|
+
*/
|
|
987
|
+
function isStuck(element, cache) {
|
|
988
|
+
const style = element.ownerDocument.defaultView?.getComputedStyle(element);
|
|
989
|
+
if (style?.position !== "sticky") return false;
|
|
990
|
+
const rect = rectOf(element, cache);
|
|
991
|
+
const edge = scrollportOf(element);
|
|
992
|
+
const top = Number.parseFloat(style.top);
|
|
993
|
+
const bottom = Number.parseFloat(style.bottom);
|
|
994
|
+
return Number.isFinite(top) && Math.abs(rect.top - (edge.start + top)) < 1 || Number.isFinite(bottom) && Math.abs(rect.bottom - (edge.end - bottom)) < 1;
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* `rect`, a box read before a change or after it (in the flush, once the
|
|
998
|
+
* glides the change retargets have stopped), with every running glide that
|
|
999
|
+
* carries the element put back on its glide's own clock: its own and those of
|
|
1000
|
+
* its ancestors inside `area`. A glide the change retargets is read on its
|
|
1001
|
+
* clock before the change and is gone after it; one the change leaves running
|
|
1002
|
+
* (a card inside an absolutely positioned panel, which the change takes no
|
|
1003
|
+
* ancestors from) is read on the same clock in both places, so it cancels out
|
|
1004
|
+
* of the move. A box read samples a running `translate`
|
|
1005
|
+
* wherever the engine evaluates it, and WebKit evaluates it at the moment of
|
|
1006
|
+
* the read, while a glide's offset, and the glide a change retargets it into,
|
|
1007
|
+
* run on the timeline's frame time: from the box alone, a change made `n` ms
|
|
1008
|
+
* into a frame started the new glide `n` ms of motion ahead of the one drawn
|
|
1009
|
+
* (up to about 3 px on a slow frame), and a row inside a gliding card took up
|
|
1010
|
+
* the card's difference. The box is read between two readings of every
|
|
1011
|
+
* carrier's applied `translate` that agree: WebKit samples a running
|
|
1012
|
+
* animation at the moment of each read, in steps of about a millisecond, so
|
|
1013
|
+
* a box read between two equal readings is of that same sample, while the
|
|
1014
|
+
* walk's earlier box read, or one read across a step, is of another. Taken
|
|
1015
|
+
* out of that
|
|
1016
|
+
* box (each scaled by its node's ancestors, as its glide is), the `translate`s
|
|
1017
|
+
* leave the element's place with no glide, and each glide's offset at its
|
|
1018
|
+
* current time goes back in. A glide replaces any `translate` of the app's
|
|
1019
|
+
* own while it runs, so each applied value is the glide's alone. Where the
|
|
1020
|
+
* engine reports no applied `translate` at all (an environment without
|
|
1021
|
+
* individual transform properties), the box is taken as it is.
|
|
1022
|
+
*/
|
|
1023
|
+
/**
|
|
1024
|
+
* How many times `onGlideClock` reads a box and the applied translates around
|
|
1025
|
+
* it to take all of them from one sample: it bounds the reads for one
|
|
1026
|
+
* consistent snapshot (WebKit's samples step about once a millisecond, and a
|
|
1027
|
+
* second reading lands inside one step), not a retry around a result.
|
|
1028
|
+
*/
|
|
1029
|
+
const SAMPLE_READS = 3;
|
|
1030
|
+
function onGlideClock(element, rect, area) {
|
|
1031
|
+
const carriers = [];
|
|
1032
|
+
for (let node = element; node != null && node !== area; node = node.parentElement) {
|
|
1033
|
+
const glide = glides.get(node);
|
|
1034
|
+
const time = Number(glide?.animation.currentTime);
|
|
1035
|
+
if (glide != null && Number.isFinite(time)) carriers.push({
|
|
1036
|
+
node,
|
|
1037
|
+
glide,
|
|
1038
|
+
time
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
if (carriers.length === 0) return rect;
|
|
1042
|
+
const view = element.ownerDocument.defaultView;
|
|
1043
|
+
const appliedNow = () => carriers.map(({ node }) => view?.getComputedStyle(node).translate);
|
|
1044
|
+
let applied = appliedNow();
|
|
1045
|
+
if (applied.some((translate) => translate == null || translate === "")) return rect;
|
|
1046
|
+
let box = element.getBoundingClientRect();
|
|
1047
|
+
for (let read = 0; read < SAMPLE_READS; read++) {
|
|
1048
|
+
const again = appliedNow();
|
|
1049
|
+
if (again.every((translate, index) => translate === applied[index])) break;
|
|
1050
|
+
applied = again;
|
|
1051
|
+
box = element.getBoundingClientRect();
|
|
1052
|
+
}
|
|
1053
|
+
let dx = 0;
|
|
1054
|
+
let dy = 0;
|
|
1055
|
+
carriers.forEach(({ node, glide, time }, index) => {
|
|
1056
|
+
const [appliedX = 0, appliedY = 0] = numbersIn(applied[index]);
|
|
1057
|
+
const offset = glide.offsetAt(Math.min(Math.max(0, time), glide.durationMs));
|
|
1058
|
+
const scale = scaleOf(node, node === element ? box : node.getBoundingClientRect(), ownScaleOf(node));
|
|
1059
|
+
dx += (offset.x - appliedX) * scale.x;
|
|
1060
|
+
dy += (offset.y - appliedY) * scale.y;
|
|
1061
|
+
});
|
|
1062
|
+
return new DOMRect(box.x + dx, box.y + dy, box.width, box.height);
|
|
1063
|
+
}
|
|
1064
|
+
function rectOf(element, cache) {
|
|
1065
|
+
let rect = cache.rects.get(element);
|
|
1066
|
+
if (rect === void 0) {
|
|
1067
|
+
rect = element.getBoundingClientRect();
|
|
1068
|
+
cache.rects.set(element, rect);
|
|
1069
|
+
}
|
|
1070
|
+
return rect;
|
|
1071
|
+
}
|
|
1072
|
+
/**
|
|
1073
|
+
* The elements a change can move, each with its rectangle before the change:
|
|
1074
|
+
* the changed element's ancestors up to the area (a centered column moves
|
|
1075
|
+
* the card around the change), and at each of their levels the siblings
|
|
1076
|
+
* after and before (a centered, end-aligned or space-between row, or
|
|
1077
|
+
* `order`, moves those too). A `display: contents` element has no box: its
|
|
1078
|
+
* children stand in its place, walked in the same direction. At each level
|
|
1079
|
+
* the walk stops at the first sibling outside `band`, so its cost grows with
|
|
1080
|
+
* depth plus the siblings near the visible part, never with the length of a
|
|
1081
|
+
* list; where the area opts out of scroll anchoring (`walksToBand`), the walk
|
|
1082
|
+
* after a change above the band goes on to the band, a cost that grows with
|
|
1083
|
+
* that distance. Inside a positioned, stuck sticky or top-layer ancestor only the
|
|
1084
|
+
* content after the change is taken.
|
|
1085
|
+
*/
|
|
1086
|
+
function collectCandidates(changed, area, band, cache, walksToBand, ancestors, befores) {
|
|
1087
|
+
const out = /* @__PURE__ */ new Map();
|
|
1088
|
+
/** Takes `element`; returns false once it lies outside the band. */
|
|
1089
|
+
/** The current level runs through its siblings, ignoring the band. */
|
|
1090
|
+
let runsThrough = false;
|
|
1091
|
+
const take = (element, isAfter) => {
|
|
1092
|
+
const part = partOf(element, cache);
|
|
1093
|
+
if (part === "contents") {
|
|
1094
|
+
for (let child = isAfter ? element.firstElementChild : element.lastElementChild; child != null; child = isAfter ? child.nextElementSibling : child.previousElementSibling) if (!take(child, isAfter)) return false;
|
|
1095
|
+
return true;
|
|
1096
|
+
}
|
|
1097
|
+
if (!part) return true;
|
|
1098
|
+
const rect = rectOf(element, cache);
|
|
1099
|
+
if (runsThrough) {
|
|
1100
|
+
out.set(element, rect);
|
|
1101
|
+
return true;
|
|
1102
|
+
}
|
|
1103
|
+
if (rect.top > band.end) return false;
|
|
1104
|
+
if (rect.bottom < band.start) return isAfter && walksToBand;
|
|
1105
|
+
out.set(element, rect);
|
|
1106
|
+
if (!isAfter) befores.add(element);
|
|
1107
|
+
return true;
|
|
1108
|
+
};
|
|
1109
|
+
const chain = [];
|
|
1110
|
+
for (let node = changed; node != null && node !== area; node = node.parentElement) chain.push(node);
|
|
1111
|
+
let positionedFrom = 0;
|
|
1112
|
+
for (let index = chain.length - 1; index > 0; index -= 1) if (partOf(chain[index], cache) === false || isStuck(chain[index], cache)) {
|
|
1113
|
+
positionedFrom = index;
|
|
1114
|
+
break;
|
|
1115
|
+
}
|
|
1116
|
+
for (const [level, node] of chain.entries()) {
|
|
1117
|
+
runsThrough = flowsAcross(node.parentElement);
|
|
1118
|
+
if (node !== changed && level > positionedFrom && partOf(node, cache) === true) {
|
|
1119
|
+
out.set(node, rectOf(node, cache));
|
|
1120
|
+
ancestors.add(node);
|
|
1121
|
+
}
|
|
1122
|
+
for (let sibling = node.nextElementSibling; sibling != null && take(sibling, true); sibling = sibling.nextElementSibling);
|
|
1123
|
+
if (level < positionedFrom) continue;
|
|
1124
|
+
for (let sibling = node.previousElementSibling; sibling != null && take(sibling, false); sibling = sibling.previousElementSibling);
|
|
1125
|
+
}
|
|
1126
|
+
return out;
|
|
1127
|
+
}
|
|
1128
|
+
//#endregion
|
|
1129
|
+
//#region src/motion/layout/batch.ts
|
|
1130
|
+
const batches = sharedMap("motion/animated-layout/batches", 1);
|
|
1131
|
+
function batchFor(area) {
|
|
1132
|
+
let batch = batches.get(area);
|
|
1133
|
+
if (batch == null) {
|
|
1134
|
+
const created = {
|
|
1135
|
+
area,
|
|
1136
|
+
changed: /* @__PURE__ */ new Set(),
|
|
1137
|
+
before: /* @__PURE__ */ new Map(),
|
|
1138
|
+
candidates: /* @__PURE__ */ new Map(),
|
|
1139
|
+
changedSize: 0,
|
|
1140
|
+
reach: 0,
|
|
1141
|
+
visible: null,
|
|
1142
|
+
walksToBand: null,
|
|
1143
|
+
ancestors: /* @__PURE__ */ new Set(),
|
|
1144
|
+
befores: /* @__PURE__ */ new Set(),
|
|
1145
|
+
originBefore: null,
|
|
1146
|
+
cache: {
|
|
1147
|
+
rects: /* @__PURE__ */ new Map(),
|
|
1148
|
+
parts: /* @__PURE__ */ new Map()
|
|
1149
|
+
},
|
|
1150
|
+
scheduled: false,
|
|
1151
|
+
beforeMove: [],
|
|
1152
|
+
start: null
|
|
1153
|
+
};
|
|
1154
|
+
batches.set(area, created);
|
|
1155
|
+
const view = area.ownerDocument.defaultView;
|
|
1156
|
+
const drop = () => {
|
|
1157
|
+
if (batches.get(area) === created && !created.scheduled) batches.delete(area);
|
|
1158
|
+
};
|
|
1159
|
+
if (typeof view?.requestAnimationFrame === "function") view.requestAnimationFrame(drop);
|
|
1160
|
+
else setTimeout(drop, 16);
|
|
1161
|
+
batch = created;
|
|
1162
|
+
}
|
|
1163
|
+
return batch;
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* The start `batch`'s change shares: taken by its first animation, from the
|
|
1167
|
+
* document's (startFor), and kept with the batch through its flush.
|
|
1168
|
+
*/
|
|
1169
|
+
function changeStartOf(batch) {
|
|
1170
|
+
const doc = batch.area.ownerDocument;
|
|
1171
|
+
const now = doc.timeline?.currentTime;
|
|
1172
|
+
if (now == null) return;
|
|
1173
|
+
if (batch.start == null || batch.start.frame !== Number(now)) batch.start = startFor(doc, Number(now));
|
|
1174
|
+
return batch.start;
|
|
1175
|
+
}
|
|
1176
|
+
function flush(batch) {
|
|
1177
|
+
batches.delete(batch.area);
|
|
1178
|
+
const notify = (candidates) => {
|
|
1179
|
+
for (const callback of batch.beforeMove) callback(candidates);
|
|
1180
|
+
};
|
|
1181
|
+
const followers = /* @__PURE__ */ new Set();
|
|
1182
|
+
for (const changed of batch.changed) for (const element of batch.candidates.get(changed) ?? []) if (element.isConnected) followers.add(element);
|
|
1183
|
+
if (followers.size === 0) {
|
|
1184
|
+
notify([]);
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
const motion = layoutMotion(batch.area);
|
|
1188
|
+
if (motion.kind === "instant") {
|
|
1189
|
+
notify([]);
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1192
|
+
const change = changeStartOf(batch);
|
|
1193
|
+
const visible = visibleRect(batch.area);
|
|
1194
|
+
const entries = [];
|
|
1195
|
+
for (const element of followers) {
|
|
1196
|
+
const before = batch.before.get(element);
|
|
1197
|
+
if (before == null || before.width === 0 && before.height === 0) continue;
|
|
1198
|
+
const running = glides.get(element);
|
|
1199
|
+
let carried = AT_REST;
|
|
1200
|
+
let carriedMs = 0;
|
|
1201
|
+
let held = AT_REST(0);
|
|
1202
|
+
if (running != null) {
|
|
1203
|
+
const time = Number(running.animation.currentTime);
|
|
1204
|
+
const elapsed = Number.isFinite(time) ? Math.max(0, time) : 0;
|
|
1205
|
+
if (elapsed < running.durationMs) held = running.offsetAt(elapsed);
|
|
1206
|
+
const { startTime } = running.animation;
|
|
1207
|
+
const shownAt = change != null && startTime != null ? Math.max(elapsed, change.at - Number(startTime)) : elapsed;
|
|
1208
|
+
if (shownAt < running.durationMs) {
|
|
1209
|
+
carried = (t) => running.offsetAt(shownAt + t);
|
|
1210
|
+
carriedMs = running.durationMs - shownAt;
|
|
1211
|
+
}
|
|
1212
|
+
running.animation.cancel();
|
|
1213
|
+
glides.delete(element);
|
|
1214
|
+
}
|
|
1215
|
+
entries.push({
|
|
1216
|
+
element,
|
|
1217
|
+
before,
|
|
1218
|
+
carried,
|
|
1219
|
+
carriedMs,
|
|
1220
|
+
held
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
const byElement = /* @__PURE__ */ new Map();
|
|
1224
|
+
const origin = originOf(batch.area);
|
|
1225
|
+
const scrolledX = origin.x - (batch.originBefore?.x ?? origin.x);
|
|
1226
|
+
const scrolledY = origin.y - (batch.originBefore?.y ?? origin.y);
|
|
1227
|
+
const nearer = (raw, shift) => Math.abs(raw + shift) < Math.abs(raw) ? raw + shift : raw;
|
|
1228
|
+
for (const entry of entries) {
|
|
1229
|
+
entry.after = onGlideClock(entry.element, entry.element.getBoundingClientRect(), batch.area);
|
|
1230
|
+
const container = entry.element.parentElement ?? entry.element;
|
|
1231
|
+
const rawX = container.ownerDocument.defaultView?.getComputedStyle(container).direction === "rtl" ? entry.before.right - entry.after.right : entry.before.left - entry.after.left;
|
|
1232
|
+
const rawY = entry.before.top - entry.after.top;
|
|
1233
|
+
const isAncestor = batch.ancestors.has(entry.element) || batch.befores.has(entry.element);
|
|
1234
|
+
entry.rawX = isAncestor ? nearer(rawX, scrolledX) : rawX;
|
|
1235
|
+
entry.rawY = isAncestor ? nearer(rawY, scrolledY) : rawY;
|
|
1236
|
+
byElement.set(entry.element, entry);
|
|
1237
|
+
}
|
|
1238
|
+
for (const entry of entries) {
|
|
1239
|
+
const after = entry.after;
|
|
1240
|
+
if (intersects(entry.before, visible) || intersects(after, visible)) {
|
|
1241
|
+
entry.isMovedByApp = movedByApp(entry.element);
|
|
1242
|
+
entry.scale = scaleOf(entry.element, after, ownScaleOf(entry.element));
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
notify(entries.map((entry) => entry.element));
|
|
1246
|
+
for (const entry of entries) {
|
|
1247
|
+
const { element, before, carried, carriedMs, held } = entry;
|
|
1248
|
+
const after = entry.after;
|
|
1249
|
+
let dx = entry.rawX ?? 0;
|
|
1250
|
+
let dy = entry.rawY ?? 0;
|
|
1251
|
+
for (let ancestor = element.parentElement; ancestor != null && ancestor !== batch.area; ancestor = ancestor.parentElement) {
|
|
1252
|
+
const moving = byElement.get(ancestor);
|
|
1253
|
+
if (moving != null) {
|
|
1254
|
+
dx -= moving.rawX ?? 0;
|
|
1255
|
+
dy -= moving.rawY ?? 0;
|
|
1256
|
+
break;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
if (Math.abs(dx) < .5 && Math.abs(dy) < .5) continue;
|
|
1260
|
+
if (!intersects(before, visible) && !intersects(after, visible)) continue;
|
|
1261
|
+
if (motion.kind === "fade") {
|
|
1262
|
+
safeAnimate(element, [{ opacity: 0 }, { opacity: 1 }], {
|
|
1263
|
+
duration: motion.durationMs,
|
|
1264
|
+
easing: motion.easing
|
|
1265
|
+
}, change);
|
|
1266
|
+
continue;
|
|
1267
|
+
}
|
|
1268
|
+
if (entry.isMovedByApp === true) continue;
|
|
1269
|
+
const scale = entry.scale ?? {
|
|
1270
|
+
x: 1,
|
|
1271
|
+
y: 1
|
|
1272
|
+
};
|
|
1273
|
+
const moveX = dx / scale.x - held.x;
|
|
1274
|
+
const moveY = dy / scale.y - held.y;
|
|
1275
|
+
const { progress } = motion;
|
|
1276
|
+
const durationMs = Math.max(progress.durationMs, carriedMs);
|
|
1277
|
+
const offsetAt = drawnCurve(durationMs, (t) => {
|
|
1278
|
+
const remaining = progress.remaining(t);
|
|
1279
|
+
const carry = carried(t);
|
|
1280
|
+
return {
|
|
1281
|
+
x: carry.x + moveX * remaining,
|
|
1282
|
+
y: carry.y + moveY * remaining
|
|
1283
|
+
};
|
|
1284
|
+
});
|
|
1285
|
+
const animation = safeAnimate(element, sampleOver(durationMs, (t) => {
|
|
1286
|
+
const offset = offsetAt(t);
|
|
1287
|
+
return { translate: `${offset.x}px ${offset.y}px` };
|
|
1288
|
+
}), {
|
|
1289
|
+
duration: durationMs,
|
|
1290
|
+
easing: "linear"
|
|
1291
|
+
}, change, scale);
|
|
1292
|
+
if (animation != null) {
|
|
1293
|
+
const glide = {
|
|
1294
|
+
animation,
|
|
1295
|
+
offsetAt,
|
|
1296
|
+
durationMs,
|
|
1297
|
+
shownBefore: {
|
|
1298
|
+
x: dx / scale.x,
|
|
1299
|
+
y: dy / scale.y
|
|
1300
|
+
},
|
|
1301
|
+
scale
|
|
1302
|
+
};
|
|
1303
|
+
glides.set(element, glide);
|
|
1304
|
+
animation.addEventListener?.("finish", () => {
|
|
1305
|
+
if (glides.get(element) === glide) glides.delete(element);
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
//#endregion
|
|
1311
|
+
//#region src/motion/layout/edge.ts
|
|
1312
|
+
/** Whether `element` lays its inline axis out right to left. */
|
|
1313
|
+
function isRtl(element) {
|
|
1314
|
+
return element.ownerDocument.defaultView?.getComputedStyle(element).direction === "rtl";
|
|
1315
|
+
}
|
|
1316
|
+
/**
|
|
1317
|
+
* The `clip-path` that hides `side` of an element from `edge`: `inset()`'s
|
|
1318
|
+
* sides are physical (top, right, bottom, left), so an inline edge is
|
|
1319
|
+
* mirrored right to left. `zero` is how the other three are written.
|
|
1320
|
+
*/
|
|
1321
|
+
function edgeClip(edge, side, zero, rtl) {
|
|
1322
|
+
const sides = [
|
|
1323
|
+
zero,
|
|
1324
|
+
zero,
|
|
1325
|
+
zero,
|
|
1326
|
+
zero
|
|
1327
|
+
];
|
|
1328
|
+
const index = edge === "block-start" ? 0 : edge === "block-end" ? 2 : edge === "inline-end" !== rtl ? 1 : 3;
|
|
1329
|
+
sides[index] = side;
|
|
1330
|
+
return `inset(${sides.join(" ")})`;
|
|
1331
|
+
}
|
|
1332
|
+
/** A hidden fraction of the element, as a percentage clip on `edge`. */
|
|
1333
|
+
function fractionClip(edge, hidden, rtl) {
|
|
1334
|
+
return edgeClip(edge, `${round(hidden * 100)}%`, "0", rtl);
|
|
1335
|
+
}
|
|
1336
|
+
/** A hidden length of the element, in its own px, as a clip on `edge`. */
|
|
1337
|
+
function pxClip(edge, hidden, rtl) {
|
|
1338
|
+
return edgeClip(edge, `${hidden}px`, "0px", rtl);
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* The element's size along `edge`'s axis, in its own px (a scaled ancestor
|
|
1342
|
+
* divided out), read from the layout the caller already laid out.
|
|
1343
|
+
*/
|
|
1344
|
+
function extentOf(element, edge) {
|
|
1345
|
+
const rect = element.getBoundingClientRect();
|
|
1346
|
+
const scale = scaleOf(element, rect);
|
|
1347
|
+
return edge.startsWith("inline") ? rect.width / scale.x : rect.height / scale.y;
|
|
1348
|
+
}
|
|
1349
|
+
/**
|
|
1350
|
+
* The parts that slide inside an element revealed or concealed from a block
|
|
1351
|
+
* edge by `extent` px. They are its child elements that the band can show:
|
|
1352
|
+
* the area's visible part plus one viewport, or `extent` if larger, above and
|
|
1353
|
+
* below. A part past the band cannot come into view while it moves, so it
|
|
1354
|
+
* stays. The walk stops at the first child below the band, so its cost grows
|
|
1355
|
+
* with the changed size, never with the length of a list. A translation
|
|
1356
|
+
* cannot move text on its own, so an element with text of its own keeps the
|
|
1357
|
+
* clip (null).
|
|
1358
|
+
*/
|
|
1359
|
+
function slidingParts(element, edge, area, extent) {
|
|
1360
|
+
if (!edge.startsWith("block") || !(extent > 0)) return null;
|
|
1361
|
+
const view = element.ownerDocument.defaultView;
|
|
1362
|
+
const style = view?.getComputedStyle(element);
|
|
1363
|
+
if (view == null || style == null || paintsOwnBox(style) || ["::before", "::after"].some((pseudo) => {
|
|
1364
|
+
const { content } = view.getComputedStyle(element, pseudo);
|
|
1365
|
+
return content !== "" && content !== "none" && content !== "normal";
|
|
1366
|
+
})) return null;
|
|
1367
|
+
const band = bandFor(visibleRect(area), Math.max(view.innerHeight, extent));
|
|
1368
|
+
const parts = [];
|
|
1369
|
+
const scales = [];
|
|
1370
|
+
for (let node = element.firstChild; node != null; node = node.nextSibling) {
|
|
1371
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
1372
|
+
if ((node.textContent ?? "").trim() !== "") return null;
|
|
1373
|
+
continue;
|
|
1374
|
+
}
|
|
1375
|
+
if (node.nodeType !== Node.ELEMENT_NODE) continue;
|
|
1376
|
+
const { display } = view.getComputedStyle(node);
|
|
1377
|
+
if (display === "inline" || display === "contents") return null;
|
|
1378
|
+
const box = node.getBoundingClientRect();
|
|
1379
|
+
if (box.top > band.end) break;
|
|
1380
|
+
if (box.bottom >= band.start) {
|
|
1381
|
+
if (glides.has(node)) return null;
|
|
1382
|
+
parts.push(node);
|
|
1383
|
+
scales.push(scaleOf(node, box, ownScaleOf(node)));
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
if (parts.length === 0) return null;
|
|
1387
|
+
const inner = (side) => (Number.parseFloat(style.getPropertyValue(`border-${side}-width`)) || 0) + (Number.parseFloat(style.getPropertyValue(`padding-${side}`)) || 0);
|
|
1388
|
+
return {
|
|
1389
|
+
parts,
|
|
1390
|
+
scales,
|
|
1391
|
+
clip: edge === "block-end" ? `inset(${inner("top")}px 0px 0px 0px)` : `inset(0px 0px ${inner("bottom")}px 0px)`
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Whether a style paints a box of its own: a fill, a border, a shadow, an
|
|
1396
|
+
* outline or a filter.
|
|
1397
|
+
*/
|
|
1398
|
+
function paintsOwnBox(style) {
|
|
1399
|
+
const isClear = (color) => color === "" || color === "transparent" || /^rgba\(.*,\s*0\)$/.test(color);
|
|
1400
|
+
return !isClear(style.backgroundColor) || style.backgroundImage !== "" && style.backgroundImage !== "none" || [
|
|
1401
|
+
"Top",
|
|
1402
|
+
"Right",
|
|
1403
|
+
"Bottom",
|
|
1404
|
+
"Left"
|
|
1405
|
+
].some((side) => style.getPropertyValue(`border-${side.toLowerCase()}-style`) !== "none" && Number.parseFloat(style.getPropertyValue(`border-${side.toLowerCase()}-width`)) > 0) || style.boxShadow !== "" && style.boxShadow !== "none" || style.borderImageSource !== "" && style.borderImageSource !== "none" || style.filter !== "" && style.filter !== "none" || style.outlineStyle !== "" && style.outlineStyle !== "none" && Number.parseFloat(style.outlineWidth) > 0;
|
|
1406
|
+
}
|
|
1407
|
+
/**
|
|
1408
|
+
* Where the parts sit when the element hides `hidden` px from `edge`. They
|
|
1409
|
+
* move that far towards it, so their far edge meets the content that rides
|
|
1410
|
+
* the same edge.
|
|
1411
|
+
*/
|
|
1412
|
+
function slideFrame(edge, hidden) {
|
|
1413
|
+
return { translate: `0px ${edge === "block-end" ? -hidden : hidden}px` };
|
|
1414
|
+
}
|
|
1415
|
+
/**
|
|
1416
|
+
* Clips `element` with `clip` while its parts slide, and returns what puts
|
|
1417
|
+
* its own `clip-path` back. The clip does not move, so it stays in step with
|
|
1418
|
+
* the parts and the content beside them on every engine.
|
|
1419
|
+
*/
|
|
1420
|
+
function holdSlideClip(element, clip) {
|
|
1421
|
+
const { style } = element;
|
|
1422
|
+
const value = style.getPropertyValue("clip-path");
|
|
1423
|
+
const priority = style.getPropertyPriority("clip-path");
|
|
1424
|
+
style.setProperty("clip-path", clip);
|
|
1425
|
+
return () => {
|
|
1426
|
+
if (value === "") style.removeProperty("clip-path");
|
|
1427
|
+
else style.setProperty("clip-path", value, priority);
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
/**
|
|
1431
|
+
* The last element before `element` in the area that takes part in layout:
|
|
1432
|
+
* its previous sibling, or its nearest ancestor's below the area (the mirror
|
|
1433
|
+
* of `nextInFlow`, for a start edge).
|
|
1434
|
+
*/
|
|
1435
|
+
function previousInFlow(element, area) {
|
|
1436
|
+
const view = element.ownerDocument.defaultView;
|
|
1437
|
+
const lastBox = (from) => {
|
|
1438
|
+
const style = view?.getComputedStyle(from);
|
|
1439
|
+
if (style == null) return from;
|
|
1440
|
+
if (style.display === "contents") {
|
|
1441
|
+
for (let child = from.lastElementChild; child != null; child = child.previousElementSibling) {
|
|
1442
|
+
const box = lastBox(child);
|
|
1443
|
+
if (box != null) return box;
|
|
1444
|
+
}
|
|
1445
|
+
return null;
|
|
1446
|
+
}
|
|
1447
|
+
return takesPart(from, style) ? from : null;
|
|
1448
|
+
};
|
|
1449
|
+
let node = element;
|
|
1450
|
+
while (node != null && node !== area) {
|
|
1451
|
+
for (let sibling = node.previousElementSibling; sibling != null; sibling = sibling.previousElementSibling) {
|
|
1452
|
+
const box = lastBox(sibling);
|
|
1453
|
+
if (box != null) return box;
|
|
1454
|
+
}
|
|
1455
|
+
node = node.parentElement;
|
|
1456
|
+
}
|
|
1457
|
+
return null;
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* The glide that moves `neighbour`: its own, or that of its nearest gliding
|
|
1461
|
+
* ancestor below the area that does not also hold `element` (one that holds
|
|
1462
|
+
* both moves the two together, so the edge does not ride it).
|
|
1463
|
+
*/
|
|
1464
|
+
function glideMoving(neighbour, element, area) {
|
|
1465
|
+
for (let node = neighbour; node != null && node !== area && !node.contains(element); node = node.parentElement) {
|
|
1466
|
+
const glide = glides.get(node);
|
|
1467
|
+
if (glide != null) return glide;
|
|
1468
|
+
}
|
|
1469
|
+
return null;
|
|
1470
|
+
}
|
|
1471
|
+
//#endregion
|
|
1472
|
+
//#region src/motion/layout/playChange.ts
|
|
1473
|
+
/** Each part's slide, by its motion: a stopped slide is no glide. */
|
|
1474
|
+
const slideTargets = sharedWeakMap("motion/animated-layout/slide-targets", 1);
|
|
1475
|
+
/**
|
|
1476
|
+
* The changed element's own animation, on the same motion as the content
|
|
1477
|
+
* after it (`spec:AST-105` FR4): content that appears reveals from its
|
|
1478
|
+
* block-end edge downward, or from the `edge` it is given (FR9), and its edge
|
|
1479
|
+
* rides the glide of the content on that side once it starts. A reveal that
|
|
1480
|
+
* reverses a running conceal (an adopter opens it again mid-exit, after
|
|
1481
|
+
* `releaseLayoutExit`) starts from what the element shows. Plays only with a
|
|
1482
|
+
* handle, inside its area and in the area's visible part. Returns the
|
|
1483
|
+
* entrance it started, or null when it played none.
|
|
1484
|
+
*/
|
|
1485
|
+
function playLayoutChange(handle, element, { edge = "block-end" } = {}) {
|
|
1486
|
+
if (handle == null) return null;
|
|
1487
|
+
const area = areaOf(handle, element);
|
|
1488
|
+
if (area == null) return null;
|
|
1489
|
+
if (!intersects(element.getBoundingClientRect(), visibleRect(area))) return null;
|
|
1490
|
+
const motion = layoutMotion(area);
|
|
1491
|
+
if (motion.kind === "instant") return null;
|
|
1492
|
+
const from = shownAtStart(element, 0);
|
|
1493
|
+
const batch = batches.get(area);
|
|
1494
|
+
const change = batch != null && [...batch.changed].some((changed) => changed === element || changed.contains(element)) ? changeStartOf(batch) : void 0;
|
|
1495
|
+
if (motion.kind === "fade") return safeAnimate(element, [{ opacity: from }, { opacity: 1 }], {
|
|
1496
|
+
duration: motion.durationMs,
|
|
1497
|
+
easing: motion.easing
|
|
1498
|
+
}, change);
|
|
1499
|
+
const { progress } = motion;
|
|
1500
|
+
const rtl = edge.startsWith("inline") && isRtl(element);
|
|
1501
|
+
const extent = edge.startsWith("block") ? extentOf(element, edge) : 0;
|
|
1502
|
+
const sliding = slidingParts(element, edge, area, extent);
|
|
1503
|
+
const partMotions = slideParts(sliding, progress, change, (remaining) => slideFrame(edge, (1 - from) * remaining * extent));
|
|
1504
|
+
const animation = safeAnimate(element, sampleKeyframes(progress, (remaining) => {
|
|
1505
|
+
const hidden = (1 - from) * remaining;
|
|
1506
|
+
return partMotions.length > 0 ? { opacity: 1 - hidden } : {
|
|
1507
|
+
opacity: 1 - hidden,
|
|
1508
|
+
clipPath: fractionClip(edge, hidden, rtl)
|
|
1509
|
+
};
|
|
1510
|
+
}), {
|
|
1511
|
+
duration: progress.durationMs,
|
|
1512
|
+
easing: "linear"
|
|
1513
|
+
}, change);
|
|
1514
|
+
if (animation == null) for (const part of partMotions) part.cancel();
|
|
1515
|
+
else rideEdge(element, area, edge, rtl, trackEdgeMotion(element, animation, (t) => 1 - (1 - from) * progress.remaining(t), partMotions, partMotions.length > 0 && sliding != null ? holdSlideClip(element, sliding.clip) : void 0), false);
|
|
1516
|
+
return animation;
|
|
1517
|
+
}
|
|
1518
|
+
/**
|
|
1519
|
+
* Plays each part's slide on the change's start, sampled like the glide.
|
|
1520
|
+
* `frame` turns the share of the motion still to come into a keyframe.
|
|
1521
|
+
*/
|
|
1522
|
+
function slideParts(sliding, progress, change, frame, fill) {
|
|
1523
|
+
const motions = [];
|
|
1524
|
+
for (const [index, part] of (sliding?.parts ?? []).entries()) {
|
|
1525
|
+
const motion = safeAnimate(part, sampleKeyframes(progress, frame), {
|
|
1526
|
+
duration: progress.durationMs,
|
|
1527
|
+
easing: "linear",
|
|
1528
|
+
fill
|
|
1529
|
+
}, change);
|
|
1530
|
+
if (motion != null) {
|
|
1531
|
+
motions.push(motion);
|
|
1532
|
+
const glide = {
|
|
1533
|
+
animation: motion,
|
|
1534
|
+
offsetAt: (t) => drawnOffset(motion, t),
|
|
1535
|
+
get durationMs() {
|
|
1536
|
+
return liveDuration(motion, progress.durationMs);
|
|
1537
|
+
},
|
|
1538
|
+
shownBefore: {
|
|
1539
|
+
x: 0,
|
|
1540
|
+
y: 0
|
|
1541
|
+
},
|
|
1542
|
+
scale: sliding?.scales[index] ?? {
|
|
1543
|
+
x: 1,
|
|
1544
|
+
y: 1
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
glides.set(part, glide);
|
|
1548
|
+
slideTargets.set(motion, part);
|
|
1549
|
+
motion.addEventListener?.("finish", () => {
|
|
1550
|
+
if (glides.get(part) === glide) glides.delete(part);
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
return motions;
|
|
1555
|
+
}
|
|
1556
|
+
/**
|
|
1557
|
+
* The offset `animation` draws `t` ms in, read off its keyframes, a straight
|
|
1558
|
+
* line between each two. A slide that rides another glide reads that glide's
|
|
1559
|
+
* frames, so this follows it.
|
|
1560
|
+
*/
|
|
1561
|
+
function drawnOffset(animation, t) {
|
|
1562
|
+
const effect = animation.effect;
|
|
1563
|
+
if (effect == null || typeof effect.getKeyframes !== "function") return {
|
|
1564
|
+
x: 0,
|
|
1565
|
+
y: 0
|
|
1566
|
+
};
|
|
1567
|
+
const frames = effect.getKeyframes();
|
|
1568
|
+
const duration = Number(effect.getTiming().duration);
|
|
1569
|
+
const at = duration > 0 ? Math.min(1, Math.max(0, t / duration)) : 1;
|
|
1570
|
+
const offsetOf = (frame) => {
|
|
1571
|
+
const [x = 0, y = 0] = numbersIn(String(frame?.translate ?? ""));
|
|
1572
|
+
return {
|
|
1573
|
+
x,
|
|
1574
|
+
y,
|
|
1575
|
+
offset: frame?.computedOffset ?? 0
|
|
1576
|
+
};
|
|
1577
|
+
};
|
|
1578
|
+
let from = offsetOf(frames[0]);
|
|
1579
|
+
let to = offsetOf(frames[frames.length - 1]);
|
|
1580
|
+
for (const frame of frames) {
|
|
1581
|
+
const point = offsetOf(frame);
|
|
1582
|
+
if (point.offset <= at) from = point;
|
|
1583
|
+
if (point.offset >= at) {
|
|
1584
|
+
to = point;
|
|
1585
|
+
break;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
const span = to.offset - from.offset;
|
|
1589
|
+
const k = span > 0 ? (at - from.offset) / span : 0;
|
|
1590
|
+
return {
|
|
1591
|
+
x: from.x + (to.x - from.x) * k,
|
|
1592
|
+
y: from.y + (to.y - from.y) * k
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
/** How many ms before `animation` started `glide` started: 0 in one change. */
|
|
1596
|
+
function startedBefore(glide, animation) {
|
|
1597
|
+
const shift = Number(animation.startTime) - Number(glide.animation.startTime);
|
|
1598
|
+
return Number.isFinite(shift) ? Math.max(0, shift) : 0;
|
|
1599
|
+
}
|
|
1600
|
+
/** `animation`'s length now, in ms, or `fallback` if it has none. */
|
|
1601
|
+
function liveDuration(animation, fallback) {
|
|
1602
|
+
const effect = animation.effect;
|
|
1603
|
+
const duration = Number(effect?.getTiming?.().duration);
|
|
1604
|
+
return duration > 0 ? duration : fallback;
|
|
1605
|
+
}
|
|
1606
|
+
/** Cancels a part's slide, and forgets it as the part's glide. */
|
|
1607
|
+
function stopGlideOf(animation) {
|
|
1608
|
+
const part = slideTargets.get(animation);
|
|
1609
|
+
if (part != null && glides.get(part)?.animation === animation) glides.delete(part);
|
|
1610
|
+
animation.cancel();
|
|
1611
|
+
}
|
|
1612
|
+
//#endregion
|
|
1613
|
+
//#region src/motion/layout/exit.ts
|
|
1614
|
+
/** The inline properties an exit sets, so a release removes exactly them. */
|
|
1615
|
+
const EXIT_PROPERTIES = [
|
|
1616
|
+
"margin-block-end",
|
|
1617
|
+
"margin-inline-end",
|
|
1618
|
+
"margin-block-start",
|
|
1619
|
+
"margin-inline-start",
|
|
1620
|
+
"pointer-events"
|
|
1621
|
+
];
|
|
1622
|
+
/**
|
|
1623
|
+
* The first element after `element` in the area that takes part in layout:
|
|
1624
|
+
* its next sibling, or its nearest ancestor's below the area. A wrapper's
|
|
1625
|
+
* edge is not used: a negative end margin can collapse through it.
|
|
1626
|
+
*/
|
|
1627
|
+
function nextInFlow(element, area) {
|
|
1628
|
+
const view = element.ownerDocument.defaultView;
|
|
1629
|
+
const firstBox = (from) => {
|
|
1630
|
+
const style = view?.getComputedStyle(from);
|
|
1631
|
+
if (style == null) return from;
|
|
1632
|
+
if (style.display === "contents") {
|
|
1633
|
+
for (let child = from.firstElementChild; child != null; child = child.nextElementSibling) {
|
|
1634
|
+
const box = firstBox(child);
|
|
1635
|
+
if (box != null) return box;
|
|
1636
|
+
}
|
|
1637
|
+
return null;
|
|
1638
|
+
}
|
|
1639
|
+
return takesPart(from, style) ? from : null;
|
|
1640
|
+
};
|
|
1641
|
+
let node = element;
|
|
1642
|
+
while (node != null && node !== area) {
|
|
1643
|
+
for (let sibling = node.nextElementSibling; sibling != null; sibling = sibling.nextElementSibling) {
|
|
1644
|
+
const box = firstBox(sibling);
|
|
1645
|
+
if (box != null) return box;
|
|
1646
|
+
}
|
|
1647
|
+
node = node.parentElement;
|
|
1648
|
+
}
|
|
1649
|
+
return null;
|
|
1650
|
+
}
|
|
1651
|
+
/**
|
|
1652
|
+
* An element's place: its block start, and its inline start (RTL read right
|
|
1653
|
+
* to left).
|
|
1654
|
+
*/
|
|
1655
|
+
function placeOf(element, rtl) {
|
|
1656
|
+
const rect = element.getBoundingClientRect();
|
|
1657
|
+
return {
|
|
1658
|
+
block: rect.top,
|
|
1659
|
+
inline: rtl ? -rect.right : rect.left
|
|
1660
|
+
};
|
|
1661
|
+
}
|
|
1662
|
+
/**
|
|
1663
|
+
* Keeps `element` where it is, in flow (so it scrolls and clips with its
|
|
1664
|
+
* container), while the content after it takes the place it takes once the
|
|
1665
|
+
* element is hidden: a negative end margin measured against that content,
|
|
1666
|
+
* so a gap or collapsing margins come out exact. Returns false, setting
|
|
1667
|
+
* nothing, when no margin reaches that place.
|
|
1668
|
+
*/
|
|
1669
|
+
function giveUpSpace(element, area, edge = "block-end") {
|
|
1670
|
+
const view = element.ownerDocument.defaultView;
|
|
1671
|
+
const parent = element.parentElement == null ? void 0 : view?.getComputedStyle(element.parentElement);
|
|
1672
|
+
const isRow = parent != null && parent.display.includes("flex") && parent.flexDirection.startsWith("row");
|
|
1673
|
+
const rtl = view?.getComputedStyle(element).direction === "rtl";
|
|
1674
|
+
const isStart = edge.endsWith("start");
|
|
1675
|
+
const property = edge === "block-end" ? isRow ? "margin-inline-end" : "margin-block-end" : `margin-${edge}`;
|
|
1676
|
+
const isInline = property.includes("inline");
|
|
1677
|
+
const size = isInline ? element.offsetWidth : element.offsetHeight;
|
|
1678
|
+
const next = nextInFlow(element, area);
|
|
1679
|
+
if (next == null && !isStart) {
|
|
1680
|
+
element.style.setProperty(property, `${-size}px`);
|
|
1681
|
+
return true;
|
|
1682
|
+
}
|
|
1683
|
+
const own = element.style.getPropertyValue(property);
|
|
1684
|
+
const ownPriority = element.style.getPropertyPriority(property);
|
|
1685
|
+
const axis = isInline ? "inline" : "block";
|
|
1686
|
+
const checked = [
|
|
1687
|
+
next,
|
|
1688
|
+
element.parentElement == null || element.parentElement === area ? null : nextInFlow(element.parentElement, area),
|
|
1689
|
+
isStart ? previousInFlow(element, area) : null,
|
|
1690
|
+
isStart ? element : null
|
|
1691
|
+
].filter((box) => box != null);
|
|
1692
|
+
if (checked.length === 0) return false;
|
|
1693
|
+
const scale = scaleOf(element, element.getBoundingClientRect());
|
|
1694
|
+
const position = element.style.getPropertyValue("position");
|
|
1695
|
+
const positionPriority = element.style.getPropertyPriority("position");
|
|
1696
|
+
const shown = isStart ? placeOf(element, rtl) : null;
|
|
1697
|
+
element.style.setProperty("position", "absolute", "important");
|
|
1698
|
+
const targets = checked.map((box) => box === element && shown != null ? shown : placeOf(box, rtl));
|
|
1699
|
+
const target = targets[0];
|
|
1700
|
+
if (position === "") element.style.removeProperty("position");
|
|
1701
|
+
else element.style.setProperty("position", position, positionPriority);
|
|
1702
|
+
const perPx = isRow ? scale.x : scale.y;
|
|
1703
|
+
element.style.setProperty(property, `${-size}px`);
|
|
1704
|
+
const guess = placeOf(checked[0], rtl)[axis];
|
|
1705
|
+
const correction = (target[axis] - guess) / perPx;
|
|
1706
|
+
element.style.setProperty(property, `${-size + correction}px`);
|
|
1707
|
+
if (checked.some((box, index) => {
|
|
1708
|
+
const landed = placeOf(box, rtl);
|
|
1709
|
+
return Math.abs(landed.block - targets[index].block) > 1 || Math.abs(landed.inline - targets[index].inline) > 1;
|
|
1710
|
+
})) {
|
|
1711
|
+
if (own === "") element.style.removeProperty(property);
|
|
1712
|
+
else element.style.setProperty(property, own, ownPriority);
|
|
1713
|
+
return false;
|
|
1714
|
+
}
|
|
1715
|
+
return true;
|
|
1716
|
+
}
|
|
1717
|
+
/** Exits holding an element back, so a release can stop one. */
|
|
1718
|
+
const exits = sharedWeakMap("motion/animated-layout/exits", 1);
|
|
1719
|
+
const replaced = sharedWeakMap("motion/animated-layout/replaced", 1);
|
|
1720
|
+
/**
|
|
1721
|
+
* The changed element's exit (`spec:AST-105` FR4): content that disappears
|
|
1722
|
+
* keeps its place on screen but gives up its space (a negative end margin
|
|
1723
|
+
* measured against the layout without it, so the content after it glides up
|
|
1724
|
+
* at once to exactly where it ends, and it still scrolls and clips with its
|
|
1725
|
+
* container), is inert (no focus, no pointer, nothing read), conceals upward
|
|
1726
|
+
* from its bottom edge on the same motion, and then `done` runs, when the
|
|
1727
|
+
* component hides or unmounts it. Under Reduce Motion with a coarse primary pointer it
|
|
1728
|
+
* fades instead. Call it in the layout effect of the commit that closes the
|
|
1729
|
+
* element, after the change's `animate()` reported it measured, in the same
|
|
1730
|
+
* task: the glide reads the layout once the element has given up its space.
|
|
1731
|
+
*
|
|
1732
|
+
* It conceals to its block-end edge by default, or to the `edge` it is given
|
|
1733
|
+
* (`spec:AST-105` FR9), and its edge rides the glide of the content on that
|
|
1734
|
+
* side once it starts; a conceal that reverses a running reveal (a close
|
|
1735
|
+
* while it opens) starts from what the element shows.
|
|
1736
|
+
*
|
|
1737
|
+
* Returns false, holding nothing, when the exit lands at once: no handle, a
|
|
1738
|
+
* close no change in the area measured, outside the area or its visible part,
|
|
1739
|
+
* Reduce Motion with a fine pointer, or a layout no end margin can free (a
|
|
1740
|
+
* grid track and its gap, a flex-row item that sets its row's height); in
|
|
1741
|
+
* that last case the content after it takes its final place at once too.
|
|
1742
|
+
* The component then hides the element itself.
|
|
1743
|
+
*/
|
|
1744
|
+
function holdLayoutExit(handle, element, done, { edge = "block-end" } = {}) {
|
|
1745
|
+
if (handle == null) return false;
|
|
1746
|
+
const area = areaOf(handle, element);
|
|
1747
|
+
if (area == null || !intersects(element.getBoundingClientRect(), visibleRect(area))) return false;
|
|
1748
|
+
const batch = batches.get(area);
|
|
1749
|
+
if (batch == null || ![...batch.changed].some((changed) => changed === element || changed.contains(element))) return false;
|
|
1750
|
+
const motion = layoutMotion(area);
|
|
1751
|
+
if (motion.kind === "instant") return false;
|
|
1752
|
+
releaseLayoutExit(element);
|
|
1753
|
+
const prior = {
|
|
1754
|
+
inert: element.hasAttribute("inert"),
|
|
1755
|
+
styles: EXIT_PROPERTIES.map((property) => [
|
|
1756
|
+
property,
|
|
1757
|
+
element.style.getPropertyValue(property),
|
|
1758
|
+
element.style.getPropertyPriority(property)
|
|
1759
|
+
])
|
|
1760
|
+
};
|
|
1761
|
+
if (!giveUpSpace(element, area, edge)) {
|
|
1762
|
+
for (const changed of [...batch.changed]) if (changed === element || changed.contains(element)) batch.changed.delete(changed);
|
|
1763
|
+
return false;
|
|
1764
|
+
}
|
|
1765
|
+
replaced.set(element, prior);
|
|
1766
|
+
element.setAttribute("inert", "");
|
|
1767
|
+
element.style.setProperty("pointer-events", "none");
|
|
1768
|
+
const from = shownAtStart(element, 1);
|
|
1769
|
+
const rtl = edge.startsWith("inline") && isRtl(element);
|
|
1770
|
+
const change = changeStartOf(batch);
|
|
1771
|
+
let animation;
|
|
1772
|
+
if (motion.kind === "fade") animation = safeAnimate(element, [{ opacity: from }, { opacity: 0 }], {
|
|
1773
|
+
duration: motion.durationMs,
|
|
1774
|
+
easing: motion.easing,
|
|
1775
|
+
fill: "forwards"
|
|
1776
|
+
}, change);
|
|
1777
|
+
else {
|
|
1778
|
+
const { progress } = motion;
|
|
1779
|
+
const extent = edge.startsWith("block") ? extentOf(element, edge) : 0;
|
|
1780
|
+
const sliding = slidingParts(element, edge, area, extent);
|
|
1781
|
+
const partMotions = slideParts(sliding, progress, change, (remaining) => slideFrame(edge, (1 - from * remaining) * extent), "forwards");
|
|
1782
|
+
animation = safeAnimate(element, sampleKeyframes(progress, (remaining) => {
|
|
1783
|
+
const shown = from * remaining;
|
|
1784
|
+
return partMotions.length > 0 ? { opacity: shown } : {
|
|
1785
|
+
opacity: shown,
|
|
1786
|
+
clipPath: fractionClip(edge, 1 - shown, rtl)
|
|
1787
|
+
};
|
|
1788
|
+
}), {
|
|
1789
|
+
duration: progress.durationMs,
|
|
1790
|
+
easing: "linear",
|
|
1791
|
+
fill: "forwards"
|
|
1792
|
+
}, change);
|
|
1793
|
+
if (animation == null) for (const part of partMotions) part.cancel();
|
|
1794
|
+
else rideEdge(element, area, edge, rtl, trackEdgeMotion(element, animation, (t) => from * progress.remaining(t), partMotions, partMotions.length > 0 && sliding != null ? holdSlideClip(element, sliding.clip) : void 0, true), true);
|
|
1795
|
+
}
|
|
1796
|
+
exits.set(element, animation);
|
|
1797
|
+
if (animation == null) {
|
|
1798
|
+
done();
|
|
1799
|
+
return true;
|
|
1800
|
+
}
|
|
1801
|
+
animation.addEventListener?.("finish", () => {
|
|
1802
|
+
if (exits.get(element) === animation) done();
|
|
1803
|
+
});
|
|
1804
|
+
return true;
|
|
1805
|
+
}
|
|
1806
|
+
/**
|
|
1807
|
+
* Puts an element `holdLayoutExit` held back: stops its exit and puts back
|
|
1808
|
+
* what the exit replaced (its `inert` and inline values as they were). Called
|
|
1809
|
+
* once the component has hidden the element, or when the element opens again
|
|
1810
|
+
* mid-exit.
|
|
1811
|
+
*/
|
|
1812
|
+
function releaseLayoutExit(element) {
|
|
1813
|
+
if (!exits.has(element)) return;
|
|
1814
|
+
const running = edgeMotions.get(element);
|
|
1815
|
+
if (running != null) {
|
|
1816
|
+
edgeMotions.delete(element);
|
|
1817
|
+
stoppedShown.set(element, {
|
|
1818
|
+
fraction: shownNow(running),
|
|
1819
|
+
at: timelineNow(element)
|
|
1820
|
+
});
|
|
1821
|
+
stopSlides(running);
|
|
1822
|
+
}
|
|
1823
|
+
const held = heldSlides.get(element);
|
|
1824
|
+
heldSlides.delete(element);
|
|
1825
|
+
if (held != null) stopSlides(held);
|
|
1826
|
+
exits.get(element)?.cancel();
|
|
1827
|
+
exits.delete(element);
|
|
1828
|
+
const prior = replaced.get(element);
|
|
1829
|
+
replaced.delete(element);
|
|
1830
|
+
if (prior?.inert !== true) element.removeAttribute("inert");
|
|
1831
|
+
for (const [property, value, priority] of prior?.styles ?? []) if (value === "") element.style.removeProperty(property);
|
|
1832
|
+
else element.style.setProperty(property, value, priority);
|
|
1833
|
+
}
|
|
1834
|
+
//#endregion
|
|
1835
|
+
//#region src/motion/layout/edgeRide.ts
|
|
1836
|
+
/** Each exit's motion, whose parts hold their slides until its release. */
|
|
1837
|
+
const heldSlides = sharedWeakMap("motion/animated-layout/held-slides", 1);
|
|
1838
|
+
/** Each element's running one-state reveal or conceal. */
|
|
1839
|
+
const edgeMotions = sharedWeakMap("motion/animated-layout/edge-motions", 1);
|
|
1840
|
+
/**
|
|
1841
|
+
* What a one-state motion an adopter stopped (`releaseLayoutExit`) showed,
|
|
1842
|
+
* and the timeline time it stopped at: a reveal started in the same frame,
|
|
1843
|
+
* the reversal that stopped it, starts there.
|
|
1844
|
+
*/
|
|
1845
|
+
const stoppedShown = sharedWeakMap("motion/animated-layout/stopped-shown", 1);
|
|
1846
|
+
function timelineNow(element) {
|
|
1847
|
+
return Number(element.ownerDocument.timeline?.currentTime ?? NaN);
|
|
1848
|
+
}
|
|
1849
|
+
/** What `motion` shows now, by its animation's own clock. */
|
|
1850
|
+
function shownNow(motion) {
|
|
1851
|
+
const time = Number(motion.animation.currentTime);
|
|
1852
|
+
return motion.shownAt(Number.isFinite(time) ? Math.max(0, time) : 0);
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* What `element` shows as a reveal or conceal starts: where the one-state
|
|
1856
|
+
* motion this one reverses had got to (it stops there), or `atRest`, all of
|
|
1857
|
+
* it for a conceal and nothing for a reveal.
|
|
1858
|
+
*/
|
|
1859
|
+
function shownAtStart(element, atRest) {
|
|
1860
|
+
const running = edgeMotions.get(element);
|
|
1861
|
+
if (running != null) {
|
|
1862
|
+
edgeMotions.delete(element);
|
|
1863
|
+
const fraction = shownNow(running);
|
|
1864
|
+
running.animation.cancel();
|
|
1865
|
+
stopSlides(running);
|
|
1866
|
+
return fraction;
|
|
1867
|
+
}
|
|
1868
|
+
const stopped = stoppedShown.get(element);
|
|
1869
|
+
stoppedShown.delete(element);
|
|
1870
|
+
if (stopped != null && stopped.at === timelineNow(element)) return stopped.fraction;
|
|
1871
|
+
return atRest;
|
|
1872
|
+
}
|
|
1873
|
+
/** Stops `motion`'s sliding parts and puts back the element's clip, once. */
|
|
1874
|
+
function stopSlides(motion) {
|
|
1875
|
+
motion.release();
|
|
1876
|
+
}
|
|
1877
|
+
/** Records `animation` as `element`'s running one-state motion. */
|
|
1878
|
+
function trackEdgeMotion(element, animation, shownAt, slides = [], release = () => {}, isHeldToRelease = false) {
|
|
1879
|
+
let isReleased = false;
|
|
1880
|
+
const motion = {
|
|
1881
|
+
animation,
|
|
1882
|
+
shownAt,
|
|
1883
|
+
slides,
|
|
1884
|
+
release: () => {
|
|
1885
|
+
if (!isReleased) {
|
|
1886
|
+
isReleased = true;
|
|
1887
|
+
for (const slide of slides) stopGlideOf(slide);
|
|
1888
|
+
release();
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
};
|
|
1892
|
+
edgeMotions.set(element, motion);
|
|
1893
|
+
if (isHeldToRelease) heldSlides.set(element, motion);
|
|
1894
|
+
animation.addEventListener?.("finish", () => {
|
|
1895
|
+
if (edgeMotions.get(element) === motion) {
|
|
1896
|
+
edgeMotions.delete(element);
|
|
1897
|
+
if (!isHeldToRelease) motion.release();
|
|
1898
|
+
}
|
|
1899
|
+
});
|
|
1900
|
+
return motion;
|
|
1901
|
+
}
|
|
1902
|
+
/**
|
|
1903
|
+
* After this commit's glides start (the batch flushes in a microtask queued
|
|
1904
|
+
* before this one), before the frame paints: once the content on `edge`'s
|
|
1905
|
+
* side glides, the moving edge rides that glide, frame by frame, so the two
|
|
1906
|
+
* never part, a reversal included (the glide carries its running motion).
|
|
1907
|
+
* `hiddenAt` turns that content's offset towards the edge's side into the
|
|
1908
|
+
* length the element hides; `frame` turns that length into a keyframe.
|
|
1909
|
+
* Without that glide (nothing on that side in the area, or nothing that
|
|
1910
|
+
* moves) the motion keeps its own curve. The animation is kept, its frames
|
|
1911
|
+
* replaced; `onRide` hears the ridden hidden length over time.
|
|
1912
|
+
*/
|
|
1913
|
+
function rideNeighbour(element, area, edge, rtl, animation, isCurrent, hiddenAt, frame, onRide) {
|
|
1914
|
+
const effect = animation.effect;
|
|
1915
|
+
if (effect == null || typeof effect.setKeyframes !== "function") return;
|
|
1916
|
+
queueMicrotask(() => {
|
|
1917
|
+
if (!isCurrent()) return;
|
|
1918
|
+
const isEnd = edge.endsWith("end");
|
|
1919
|
+
const neighbour = isEnd ? nextInFlow(element, area) : previousInFlow(element, area);
|
|
1920
|
+
const glide = neighbour == null ? null : glideMoving(neighbour, element, area);
|
|
1921
|
+
if (neighbour == null || glide == null) return;
|
|
1922
|
+
const own = glideMoving(element, neighbour, area);
|
|
1923
|
+
const glideAt = startedBefore(glide, animation);
|
|
1924
|
+
const ownAt = own == null ? 0 : startedBefore(own, animation);
|
|
1925
|
+
const durationMs = Math.max(glide.durationMs - glideAt, own == null ? 0 : own.durationMs - ownAt);
|
|
1926
|
+
const sign = isEnd ? 1 : -1;
|
|
1927
|
+
const hidden = (t) => {
|
|
1928
|
+
const offset = glide.offsetAt(glideAt + t);
|
|
1929
|
+
const moved = own?.offsetAt(ownAt + t) ?? {
|
|
1930
|
+
x: 0,
|
|
1931
|
+
y: 0
|
|
1932
|
+
};
|
|
1933
|
+
return hiddenAt(sign * (edge.startsWith("inline") ? (rtl ? -1 : 1) * (offset.x - moved.x) : offset.y - moved.y));
|
|
1934
|
+
};
|
|
1935
|
+
const frames = sampleOver(durationMs, (t) => frame(hidden(t)));
|
|
1936
|
+
effect.setKeyframes(frames);
|
|
1937
|
+
effect.updateTiming?.({ duration: durationMs });
|
|
1938
|
+
retimeSettle(animation, frames, durationMs);
|
|
1939
|
+
onRide(hidden, durationMs);
|
|
1940
|
+
});
|
|
1941
|
+
}
|
|
1942
|
+
/**
|
|
1943
|
+
* The one-state reveal or conceal rides the content on its edge's side: the
|
|
1944
|
+
* element shows what lies between its fixed edge and that content, a reveal
|
|
1945
|
+
* less by however far the content still is from its place towards it, a
|
|
1946
|
+
* conceal all of it less however far the content has come, fading with what
|
|
1947
|
+
* it hides.
|
|
1948
|
+
*/
|
|
1949
|
+
function rideEdge(element, area, edge, rtl, motion, isConceal) {
|
|
1950
|
+
const extent = extentOf(element, edge);
|
|
1951
|
+
if (!(extent > 0)) return;
|
|
1952
|
+
rideNeighbour(element, area, edge, rtl, motion.animation, () => edgeMotions.get(element) === motion, (towards) => Math.min(extent, Math.max(0, isConceal ? extent - towards : -towards)), (hidden) => motion.slides.length > 0 ? { opacity: 1 - hidden / extent } : {
|
|
1953
|
+
opacity: 1 - hidden / extent,
|
|
1954
|
+
clipPath: pxClip(edge, hidden, rtl)
|
|
1955
|
+
}, (hiddenAt, durationMs) => {
|
|
1956
|
+
motion.shownAt = (t) => 1 - hiddenAt(t) / extent;
|
|
1957
|
+
for (const slide of motion.slides) {
|
|
1958
|
+
const effect = slide.effect;
|
|
1959
|
+
const frames = sampleOver(durationMs, (t) => slideFrame(edge, hiddenAt(t)));
|
|
1960
|
+
effect?.setKeyframes?.(frames);
|
|
1961
|
+
effect?.updateTiming?.({ duration: durationMs });
|
|
1962
|
+
retimeSettle(slide, frames, durationMs);
|
|
1963
|
+
}
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1966
|
+
//#endregion
|
|
1967
|
+
//#region src/motion/layout/reportChange.ts
|
|
1968
|
+
function resolve(target) {
|
|
1969
|
+
return typeof target === "function" ? target() : target.current;
|
|
1970
|
+
}
|
|
1971
|
+
/**
|
|
1972
|
+
* Report a size change of `target` to the handle's area. Call
|
|
1973
|
+
* `measureBefore()` before the change commits and `animate()` after it; the
|
|
1974
|
+
* content after `target`, up to the area, glides from its old place.
|
|
1975
|
+
* Changes in one area in one frame move together. Without a handle, or
|
|
1976
|
+
* outside its container, nothing moves.
|
|
1977
|
+
*/
|
|
1978
|
+
function reportLayoutChange(handle, target) {
|
|
1979
|
+
return {
|
|
1980
|
+
measureBefore() {
|
|
1981
|
+
const element = resolve(target);
|
|
1982
|
+
if (element == null || handle == null) return;
|
|
1983
|
+
const area = areaOf(handle, element);
|
|
1984
|
+
if (area == null) return;
|
|
1985
|
+
beginChange(element.ownerDocument);
|
|
1986
|
+
const batch = batchFor(area);
|
|
1987
|
+
if (batch.changed.has(element)) return;
|
|
1988
|
+
batch.changed.add(element);
|
|
1989
|
+
batch.changedSize += rectOf(element, batch.cache).height;
|
|
1990
|
+
batch.visible ??= visibleRect(area);
|
|
1991
|
+
batch.originBefore ??= originOf(area);
|
|
1992
|
+
batch.walksToBand ??= area.ownerDocument.defaultView?.getComputedStyle(area).getPropertyValue("overflow-anchor") === "none";
|
|
1993
|
+
const needed = Math.max(batch.visible.height, batch.changedSize);
|
|
1994
|
+
const walks = needed > batch.reach ? [...batch.changed] : [element];
|
|
1995
|
+
if (needed > batch.reach) batch.reach = Math.max(needed, batch.reach * 2);
|
|
1996
|
+
const band = bandFor(batch.visible, batch.reach);
|
|
1997
|
+
for (const changed of walks) {
|
|
1998
|
+
const candidates = collectCandidates(changed, area, band, batch.cache, batch.walksToBand, batch.ancestors, batch.befores);
|
|
1999
|
+
for (const [candidate, rect] of candidates) if (!batch.before.has(candidate)) batch.before.set(candidate, onGlideClock(candidate, rect, area));
|
|
2000
|
+
batch.candidates.set(changed, [...candidates.keys()]);
|
|
2001
|
+
}
|
|
2002
|
+
},
|
|
2003
|
+
animate(beforeMove) {
|
|
2004
|
+
const element = resolve(target);
|
|
2005
|
+
if (element == null || handle == null) return false;
|
|
2006
|
+
const area = areaOf(handle, element);
|
|
2007
|
+
const batch = area == null ? void 0 : batches.get(area);
|
|
2008
|
+
if (batch == null || !batch.changed.has(element)) return false;
|
|
2009
|
+
if (beforeMove != null) batch.beforeMove.push(beforeMove);
|
|
2010
|
+
if (!batch.scheduled) {
|
|
2011
|
+
batch.scheduled = true;
|
|
2012
|
+
queueMicrotask(() => batchPresented(() => flush(batch)));
|
|
2013
|
+
}
|
|
2014
|
+
return true;
|
|
2015
|
+
}
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
//#endregion
|
|
2019
|
+
//#region src/motion/layout/landing.ts
|
|
2020
|
+
/**
|
|
2021
|
+
* A disclosure's indicator (its chevron) turns on the same motion as the
|
|
2022
|
+
* glide. Its CSS transition takes the theme's move curve and duration as the
|
|
2023
|
+
* glide reads them where the area is, and is immediate under Reduce Motion.
|
|
2024
|
+
* Without a handle the inline values are cleared, so the component's own
|
|
2025
|
+
* transition applies.
|
|
2026
|
+
*/
|
|
2027
|
+
function applyLayoutChangeTransition(handle, element) {
|
|
2028
|
+
if (element == null) return;
|
|
2029
|
+
const area = handle == null ? null : areaOf(handle, element);
|
|
2030
|
+
if (area == null) {
|
|
2031
|
+
transitionSettles.get(element)?.();
|
|
2032
|
+
element.style.removeProperty("transition-duration");
|
|
2033
|
+
element.style.removeProperty("transition-timing-function");
|
|
2034
|
+
return;
|
|
2035
|
+
}
|
|
2036
|
+
const motion = layoutMotion(area);
|
|
2037
|
+
if (motion.kind !== "glide") {
|
|
2038
|
+
transitionSettles.get(element)?.();
|
|
2039
|
+
element.style.setProperty("transition-duration", "0s");
|
|
2040
|
+
element.style.removeProperty("transition-timing-function");
|
|
2041
|
+
return;
|
|
2042
|
+
}
|
|
2043
|
+
const ms = Math.round(motion.progress.durationMs * 1e3) / 1e3;
|
|
2044
|
+
element.style.setProperty("transition-duration", `${ms}ms`);
|
|
2045
|
+
element.style.setProperty("transition-timing-function", motion.progress.easing);
|
|
2046
|
+
settleTransition(element, motion.progress);
|
|
2047
|
+
}
|
|
2048
|
+
//#endregion
|
|
2049
|
+
export { playLayoutChange as a, releaseLayoutExit as i, reportLayoutChange as n, glideOf as o, holdLayoutExit as r, applyLayoutChangeTransition as t };
|