@cognitap/radiant 0.0.5 → 0.0.6
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/CHANGELOG.md +17 -0
- package/README.md +8 -0
- package/dist/library/Button.d.ts +3 -1
- package/dist/library/Button.d.ts.map +1 -1
- package/dist/library/Button.js +43 -2
- package/dist/library/Button.js.map +1 -1
- package/dist/library/Collapsible.d.ts +2 -1
- package/dist/library/Collapsible.d.ts.map +1 -1
- package/dist/library/Collapsible.js +5 -2
- package/dist/library/Collapsible.js.map +1 -1
- package/dist/library/Dialog.d.ts +2 -1
- package/dist/library/Dialog.d.ts.map +1 -1
- package/dist/library/Dialog.js +5 -2
- package/dist/library/Dialog.js.map +1 -1
- package/dist/library/ThemeScope.d.ts.map +1 -1
- package/dist/library/ThemeScope.js +10 -9
- package/dist/library/ThemeScope.js.map +1 -1
- package/dist/library/index.d.ts +3 -1
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +1 -0
- package/dist/library/index.js.map +1 -1
- package/dist/library/motion/MotionLink.d.ts +7 -0
- package/dist/library/motion/MotionLink.d.ts.map +1 -0
- package/dist/library/motion/MotionLink.js +45 -0
- package/dist/library/motion/MotionLink.js.map +1 -0
- package/dist/library/motion/browser.d.ts +5 -0
- package/dist/library/motion/browser.d.ts.map +1 -0
- package/dist/library/motion/browser.js +35 -0
- package/dist/library/motion/browser.js.map +1 -0
- package/dist/library/motion/config.d.ts +26 -0
- package/dist/library/motion/config.d.ts.map +1 -0
- package/dist/library/motion/config.js +58 -0
- package/dist/library/motion/config.js.map +1 -0
- package/dist/library/motion/context.d.ts +2 -0
- package/dist/library/motion/context.d.ts.map +1 -0
- package/dist/library/motion/context.js +5 -0
- package/dist/library/motion/context.js.map +1 -0
- package/dist/library/motion/drag.d.ts +20 -0
- package/dist/library/motion/drag.d.ts.map +1 -0
- package/dist/library/motion/drag.js +138 -0
- package/dist/library/motion/drag.js.map +1 -0
- package/dist/library/motion/dragBrowser.d.ts +4 -0
- package/dist/library/motion/dragBrowser.d.ts.map +1 -0
- package/dist/library/motion/dragBrowser.js +156 -0
- package/dist/library/motion/dragBrowser.js.map +1 -0
- package/dist/library/motion/follow.d.ts +9 -0
- package/dist/library/motion/follow.d.ts.map +1 -0
- package/dist/library/motion/follow.js +26 -0
- package/dist/library/motion/follow.js.map +1 -0
- package/dist/library/motion/host.d.ts +27 -0
- package/dist/library/motion/host.d.ts.map +1 -0
- package/dist/library/motion/host.js +62 -0
- package/dist/library/motion/host.js.map +1 -0
- package/dist/library/motion/index.d.ts +16 -0
- package/dist/library/motion/index.d.ts.map +1 -0
- package/dist/library/motion/index.js +9 -0
- package/dist/library/motion/index.js.map +1 -0
- package/dist/library/motion/layout.d.ts +20 -0
- package/dist/library/motion/layout.d.ts.map +1 -0
- package/dist/library/motion/layout.js +67 -0
- package/dist/library/motion/layout.js.map +1 -0
- package/dist/library/motion/layoutDom.d.ts +17 -0
- package/dist/library/motion/layoutDom.d.ts.map +1 -0
- package/dist/library/motion/layoutDom.js +272 -0
- package/dist/library/motion/layoutDom.js.map +1 -0
- package/dist/library/motion/press.d.ts +5 -0
- package/dist/library/motion/press.d.ts.map +1 -0
- package/dist/library/motion/press.js +72 -0
- package/dist/library/motion/press.js.map +1 -0
- package/dist/library/motion/pressPolicy.d.ts +5 -0
- package/dist/library/motion/pressPolicy.d.ts.map +1 -0
- package/dist/library/motion/pressPolicy.js +8 -0
- package/dist/library/motion/pressPolicy.js.map +1 -0
- package/dist/library/motion/react.d.ts +35 -0
- package/dist/library/motion/react.d.ts.map +1 -0
- package/dist/library/motion/react.js +224 -0
- package/dist/library/motion/react.js.map +1 -0
- package/dist/library/motion/runtime.d.ts +22 -0
- package/dist/library/motion/runtime.d.ts.map +1 -0
- package/dist/library/motion/runtime.js +117 -0
- package/dist/library/motion/runtime.js.map +1 -0
- package/dist/library/motion/transitions.d.ts +5 -0
- package/dist/library/motion/transitions.d.ts.map +1 -0
- package/dist/library/motion/transitions.js +211 -0
- package/dist/library/motion/transitions.js.map +1 -0
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/defineTheme.d.ts +3 -0
- package/dist/library/themes/defineTheme.d.ts.map +1 -1
- package/dist/library/themes/defineTheme.js +4 -2
- package/dist/library/themes/defineTheme.js.map +1 -1
- package/dist/library/themes/index.d.ts +1 -1
- package/dist/library/themes/index.d.ts.map +1 -1
- package/dist/library/themes/index.js.map +1 -1
- package/dist/library/themes/themeDocument.d.ts.map +1 -1
- package/dist/library/themes/themeDocument.js +11 -5
- package/dist/library/themes/themeDocument.js.map +1 -1
- package/dist/library/themes/themeDocumentTypes.d.ts +5 -1
- package/dist/library/themes/themeDocumentTypes.d.ts.map +1 -1
- package/dist/library/themes/themeDocumentTypes.js.map +1 -1
- package/docs/motion.md +434 -0
- package/docs/system.md +26 -0
- package/package.json +14 -3
- package/src/Button.tsx +49 -1
- package/src/Collapsible.tsx +13 -1
- package/src/Dialog.tsx +10 -1
- package/src/ThemeScope.tsx +21 -17
- package/src/index.ts +9 -0
- package/src/motion/MotionLink.tsx +64 -0
- package/src/motion/browser.ts +45 -0
- package/src/motion/config.ts +79 -0
- package/src/motion/context.ts +4 -0
- package/src/motion/drag.ts +151 -0
- package/src/motion/dragBrowser.ts +159 -0
- package/src/motion/follow.ts +28 -0
- package/src/motion/host.ts +88 -0
- package/src/motion/index.ts +28 -0
- package/src/motion/layout.ts +78 -0
- package/src/motion/layoutDom.ts +293 -0
- package/src/motion/press.ts +77 -0
- package/src/motion/pressPolicy.ts +12 -0
- package/src/motion/react.ts +272 -0
- package/src/motion/runtime.ts +122 -0
- package/src/motion/transitions.ts +206 -0
- package/src/themes/defineTheme.ts +10 -2
- package/src/themes/index.ts +1 -0
- package/src/themes/themeDocument.ts +14 -6
- package/src/themes/themeDocumentTypes.ts +12 -5
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { createSpring } from './runtime.js';
|
|
2
|
+
import { bindSpringStyle } from './browser.js';
|
|
3
|
+
import { resolveMotion } from './config.js';
|
|
4
|
+
export function bindDisclosureMotion(host, initial) {
|
|
5
|
+
const node = host;
|
|
6
|
+
let profile = initial;
|
|
7
|
+
const query = node.ownerDocument.defaultView.matchMedia('(prefers-reduced-motion: reduce)');
|
|
8
|
+
const contents = () => Array.from(node.children).filter((child) => child instanceof HTMLElement && child.tagName !== 'SUMMARY');
|
|
9
|
+
const measure = () => contents().reduce((sum, child) => sum + child.getBoundingClientRect().height, 0);
|
|
10
|
+
const previous = node.style.getPropertyValue('--_rad-spring-details-height');
|
|
11
|
+
const spring = createSpring(node.open ? measure() : 0, resolveMotion(profile, 'disclosure', query.matches));
|
|
12
|
+
const saved = new Map();
|
|
13
|
+
const render = (value) => node.style.setProperty('--_rad-spring-details-height', `${Math.max(0, value)}px`);
|
|
14
|
+
const off = spring.subscribe(render);
|
|
15
|
+
render(spring.get());
|
|
16
|
+
function sync() {
|
|
17
|
+
for (const child of contents()) {
|
|
18
|
+
if (!node.open) {
|
|
19
|
+
if (!saved.has(child))
|
|
20
|
+
saved.set(child, { inert: child.inert, hidden: child.getAttribute('aria-hidden') });
|
|
21
|
+
child.inert = true;
|
|
22
|
+
child.setAttribute('aria-hidden', 'true');
|
|
23
|
+
}
|
|
24
|
+
else
|
|
25
|
+
restore(child);
|
|
26
|
+
}
|
|
27
|
+
spring.to(node.open ? measure() : 0);
|
|
28
|
+
}
|
|
29
|
+
function restore(child) {
|
|
30
|
+
const prior = saved.get(child);
|
|
31
|
+
if (!prior)
|
|
32
|
+
return;
|
|
33
|
+
child.inert = prior.inert;
|
|
34
|
+
if (prior.hidden === null)
|
|
35
|
+
child.removeAttribute('aria-hidden');
|
|
36
|
+
else
|
|
37
|
+
child.setAttribute('aria-hidden', prior.hidden);
|
|
38
|
+
saved.delete(child);
|
|
39
|
+
}
|
|
40
|
+
const observer = new MutationObserver(sync);
|
|
41
|
+
observer.observe(node, { attributes: true, attributeFilter: ['open'], childList: true });
|
|
42
|
+
const resize = new ResizeObserver(sync);
|
|
43
|
+
contents().forEach(child => resize.observe(child));
|
|
44
|
+
function update(next) {
|
|
45
|
+
profile = next;
|
|
46
|
+
spring.configure(resolveMotion(profile, 'disclosure', query.matches));
|
|
47
|
+
sync();
|
|
48
|
+
}
|
|
49
|
+
const preference = () => update(profile);
|
|
50
|
+
query.addEventListener('change', preference);
|
|
51
|
+
sync();
|
|
52
|
+
return {
|
|
53
|
+
update,
|
|
54
|
+
destroy() {
|
|
55
|
+
observer.disconnect();
|
|
56
|
+
resize.disconnect();
|
|
57
|
+
query.removeEventListener('change', preference);
|
|
58
|
+
off();
|
|
59
|
+
spring.destroy();
|
|
60
|
+
for (const child of saved.keys())
|
|
61
|
+
restore(child);
|
|
62
|
+
if (previous)
|
|
63
|
+
node.style.setProperty('--_rad-spring-details-height', previous);
|
|
64
|
+
else
|
|
65
|
+
node.style.removeProperty('--_rad-spring-details-height');
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function bindDialogMotion(host, initial) {
|
|
70
|
+
const node = host;
|
|
71
|
+
let profile = initial;
|
|
72
|
+
const query = node.ownerDocument.defaultView.matchMedia('(prefers-reduced-motion: reduce)');
|
|
73
|
+
let open = node.open;
|
|
74
|
+
const geometry = () => ({
|
|
75
|
+
left: node.offsetLeft,
|
|
76
|
+
top: node.offsetTop,
|
|
77
|
+
width: node.offsetWidth,
|
|
78
|
+
height: node.offsetHeight,
|
|
79
|
+
variables: Array.from(getComputedStyle(node))
|
|
80
|
+
.filter(key => key.startsWith('--'))
|
|
81
|
+
.map(key => [key, getComputedStyle(node).getPropertyValue(key)])
|
|
82
|
+
});
|
|
83
|
+
let bounds = node.open ? geometry() : null;
|
|
84
|
+
let ghost = null;
|
|
85
|
+
const spring = createSpring(open ? 1 : 0.94, {
|
|
86
|
+
...resolveMotion(profile, 'dialog', query.matches),
|
|
87
|
+
reducedValue: open ? 1 : 0.94
|
|
88
|
+
});
|
|
89
|
+
const unbind = bindSpringStyle(node, spring, 'scale');
|
|
90
|
+
function clear() {
|
|
91
|
+
ghost?.remove();
|
|
92
|
+
ghost = null;
|
|
93
|
+
}
|
|
94
|
+
function snapshot() {
|
|
95
|
+
clear();
|
|
96
|
+
if (!bounds || bounds.width === 0)
|
|
97
|
+
return;
|
|
98
|
+
if (node.parentElement?.closest('dialog[open]') ||
|
|
99
|
+
Array.from(node.querySelectorAll('*')).some(child => child.localName.includes('-') ||
|
|
100
|
+
/^(script|style|link|iframe|object|embed|canvas|video|audio)$/.test(child.localName)))
|
|
101
|
+
return;
|
|
102
|
+
const copy = node.cloneNode(true);
|
|
103
|
+
ghost = node.ownerDocument.createElement('div');
|
|
104
|
+
for (const attribute of copy.attributes)
|
|
105
|
+
ghost.setAttribute(attribute.name, attribute.value);
|
|
106
|
+
while (copy.firstChild)
|
|
107
|
+
ghost.append(copy.firstChild);
|
|
108
|
+
ghost.setAttribute('open', '');
|
|
109
|
+
ghost.removeAttribute('data-slot');
|
|
110
|
+
ghost.setAttribute('role', 'presentation');
|
|
111
|
+
ghost.setAttribute('data-state', 'open');
|
|
112
|
+
ghost.inert = true;
|
|
113
|
+
ghost.setAttribute('aria-hidden', 'true');
|
|
114
|
+
ghost.setAttribute('data-rad-motion-exit', '');
|
|
115
|
+
for (const child of [ghost, ...ghost.querySelectorAll('*')]) {
|
|
116
|
+
for (const attribute of Array.from(child.attributes))
|
|
117
|
+
if (attribute.name.toLowerCase().startsWith('on'))
|
|
118
|
+
child.removeAttribute(attribute.name);
|
|
119
|
+
for (const attribute of ['id', 'name', 'form', 'autofocus'])
|
|
120
|
+
child.removeAttribute(attribute);
|
|
121
|
+
if (child instanceof HTMLInputElement ||
|
|
122
|
+
child instanceof HTMLButtonElement ||
|
|
123
|
+
child instanceof HTMLSelectElement ||
|
|
124
|
+
child instanceof HTMLTextAreaElement)
|
|
125
|
+
child.disabled = true;
|
|
126
|
+
}
|
|
127
|
+
for (const [key, value] of bounds.variables)
|
|
128
|
+
ghost.style.setProperty(key, value);
|
|
129
|
+
ghost.style.font = getComputedStyle(node).font;
|
|
130
|
+
ghost.style.colorScheme = getComputedStyle(node).colorScheme;
|
|
131
|
+
Object.assign(ghost.style, {
|
|
132
|
+
position: 'fixed',
|
|
133
|
+
margin: '0px',
|
|
134
|
+
left: `${bounds.left}px`,
|
|
135
|
+
top: `${bounds.top}px`,
|
|
136
|
+
width: `${bounds.width}px`,
|
|
137
|
+
height: `${bounds.height}px`,
|
|
138
|
+
maxHeight: 'none',
|
|
139
|
+
pointerEvents: 'none',
|
|
140
|
+
zIndex: '2147483647',
|
|
141
|
+
transition: 'none'
|
|
142
|
+
});
|
|
143
|
+
node.ownerDocument.body.append(ghost);
|
|
144
|
+
}
|
|
145
|
+
const off = spring.subscribe(value => {
|
|
146
|
+
if (ghost) {
|
|
147
|
+
ghost.style.scale = String(Math.max(0, value));
|
|
148
|
+
ghost.style.opacity = String(Math.max(0, Math.min(1, (value - 0.94) / 0.06)));
|
|
149
|
+
if (!node.open && Math.abs(value - 0.94) < 0.0001)
|
|
150
|
+
clear();
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
function sync() {
|
|
154
|
+
if (node.open === open)
|
|
155
|
+
return;
|
|
156
|
+
open = node.open;
|
|
157
|
+
const enabled = resolveMotion(profile, 'dialog', query.matches).enabled;
|
|
158
|
+
if (open) {
|
|
159
|
+
clear();
|
|
160
|
+
bounds = geometry();
|
|
161
|
+
spring.configure({ reducedValue: 1 });
|
|
162
|
+
spring.to(1);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
if (enabled)
|
|
166
|
+
snapshot();
|
|
167
|
+
spring.configure({ reducedValue: 0.94 });
|
|
168
|
+
spring.to(0.94);
|
|
169
|
+
if (!enabled)
|
|
170
|
+
clear();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const beforeToggle = () => {
|
|
174
|
+
if (node.open)
|
|
175
|
+
bounds = geometry();
|
|
176
|
+
};
|
|
177
|
+
node.addEventListener('beforetoggle', beforeToggle);
|
|
178
|
+
const observer = new MutationObserver(sync);
|
|
179
|
+
observer.observe(node, { attributes: true, attributeFilter: ['open'] });
|
|
180
|
+
const resize = new ResizeObserver(() => {
|
|
181
|
+
if (node.open)
|
|
182
|
+
bounds = geometry();
|
|
183
|
+
});
|
|
184
|
+
resize.observe(node);
|
|
185
|
+
function update(next) {
|
|
186
|
+
profile = next;
|
|
187
|
+
spring.configure({
|
|
188
|
+
...resolveMotion(profile, 'dialog', query.matches),
|
|
189
|
+
reducedValue: node.open ? 1 : 0.94
|
|
190
|
+
});
|
|
191
|
+
if (!resolveMotion(profile, 'dialog', query.matches).enabled)
|
|
192
|
+
clear();
|
|
193
|
+
sync();
|
|
194
|
+
}
|
|
195
|
+
const preference = () => update(profile);
|
|
196
|
+
query.addEventListener('change', preference);
|
|
197
|
+
return {
|
|
198
|
+
update,
|
|
199
|
+
destroy() {
|
|
200
|
+
observer.disconnect();
|
|
201
|
+
resize.disconnect();
|
|
202
|
+
query.removeEventListener('change', preference);
|
|
203
|
+
off();
|
|
204
|
+
spring.destroy();
|
|
205
|
+
unbind();
|
|
206
|
+
node.removeEventListener('beforetoggle', beforeToggle);
|
|
207
|
+
clear();
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=transitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transitions.js","sourceRoot":"","sources":["../../../src/motion/transitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAsB,MAAM,aAAa,CAAA;AAG/D,MAAM,UAAU,oBAAoB,CAAC,IAAiB,EAAE,OAAsB;IAC5E,MAAM,IAAI,GAAG,IAA0B,CAAA;IACvC,IAAI,OAAO,GAAG,OAAO,CAAA;IACrB,MAAM,KAAK,GAAG,IAAI,CAAC,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AAA;YAC/C,GAAG,EAAE,CAAA;YACL,MAAM,CAAC,OAAO,EAAE,CAAA;YAChB,MAAM,EAAE,CAAA;YACR,IAAI,CAAC,mBAAmB,CAAC,cAAc,EAAE,YAAY,CAAC,CAAA;YACtD,KAAK,EAAE,CAAA;QACT,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import { createSpring } from './runtime.js'\nimport { bindSpringStyle } from './browser.js'\nimport { resolveMotion, type MotionProfile } from './config.js'\nimport type { MotionHostBinding } from './host.js'\n\nexport function bindDisclosureMotion(host: HTMLElement, initial: MotionProfile): MotionHostBinding {\n const node = host as HTMLDetailsElement\n let profile = initial\n const query = node.ownerDocument.defaultView!.matchMedia('(prefers-reduced-motion: reduce)')\n const contents = () =>\n Array.from(node.children).filter(\n (child): child is HTMLElement => child instanceof HTMLElement && child.tagName !== 'SUMMARY'\n )\n const measure = () =>\n contents().reduce((sum, child) => sum + child.getBoundingClientRect().height, 0)\n const previous = node.style.getPropertyValue('--_rad-spring-details-height')\n const spring = createSpring(\n node.open ? measure() : 0,\n resolveMotion(profile, 'disclosure', query.matches)\n )\n const saved = new Map<HTMLElement, { inert: boolean; hidden: string | null }>()\n const render = (value: number) =>\n node.style.setProperty('--_rad-spring-details-height', `${Math.max(0, value)}px`)\n const off = spring.subscribe(render)\n render(spring.get())\n function sync() {\n for (const child of contents()) {\n if (!node.open) {\n if (!saved.has(child))\n saved.set(child, { inert: child.inert, hidden: child.getAttribute('aria-hidden') })\n child.inert = true\n child.setAttribute('aria-hidden', 'true')\n } else restore(child)\n }\n spring.to(node.open ? measure() : 0)\n }\n function restore(child: HTMLElement) {\n const prior = saved.get(child)\n if (!prior) return\n child.inert = prior.inert\n if (prior.hidden === null) child.removeAttribute('aria-hidden')\n else child.setAttribute('aria-hidden', prior.hidden)\n saved.delete(child)\n }\n const observer = new MutationObserver(sync)\n observer.observe(node, { attributes: true, attributeFilter: ['open'], childList: true })\n const resize = new ResizeObserver(sync)\n contents().forEach(child => resize.observe(child))\n function update(next: MotionProfile) {\n profile = next\n spring.configure(resolveMotion(profile, 'disclosure', query.matches))\n sync()\n }\n const preference = () => update(profile)\n query.addEventListener('change', preference)\n sync()\n return {\n update,\n destroy() {\n observer.disconnect()\n resize.disconnect()\n query.removeEventListener('change', preference)\n off()\n spring.destroy()\n for (const child of saved.keys()) restore(child)\n if (previous) node.style.setProperty('--_rad-spring-details-height', previous)\n else node.style.removeProperty('--_rad-spring-details-height')\n }\n }\n}\n\nexport function bindDialogMotion(host: HTMLElement, initial: MotionProfile): MotionHostBinding {\n const node = host as HTMLDialogElement\n let profile = initial\n const query = node.ownerDocument.defaultView!.matchMedia('(prefers-reduced-motion: reduce)')\n let open = node.open\n const geometry = () => ({\n left: node.offsetLeft,\n top: node.offsetTop,\n width: node.offsetWidth,\n height: node.offsetHeight,\n variables: Array.from(getComputedStyle(node))\n .filter(key => key.startsWith('--'))\n .map(key => [key, getComputedStyle(node).getPropertyValue(key)])\n })\n let bounds = node.open ? geometry() : null\n let ghost: HTMLDivElement | null = null\n const spring = createSpring(open ? 1 : 0.94, {\n ...resolveMotion(profile, 'dialog', query.matches),\n reducedValue: open ? 1 : 0.94\n })\n const unbind = bindSpringStyle(node, spring, 'scale')\n function clear() {\n ghost?.remove()\n ghost = null\n }\n function snapshot() {\n clear()\n if (!bounds || bounds.width === 0) return\n if (\n node.parentElement?.closest('dialog[open]') ||\n Array.from(node.querySelectorAll('*')).some(\n child =>\n child.localName.includes('-') ||\n /^(script|style|link|iframe|object|embed|canvas|video|audio)$/.test(child.localName)\n )\n )\n return\n const copy = node.cloneNode(true) as HTMLDialogElement\n ghost = node.ownerDocument.createElement('div')\n for (const attribute of copy.attributes) ghost.setAttribute(attribute.name, attribute.value)\n while (copy.firstChild) ghost.append(copy.firstChild)\n ghost.setAttribute('open', '')\n ghost.removeAttribute('data-slot')\n ghost.setAttribute('role', 'presentation')\n ghost.setAttribute('data-state', 'open')\n ghost.inert = true\n ghost.setAttribute('aria-hidden', 'true')\n ghost.setAttribute('data-rad-motion-exit', '')\n for (const child of [ghost, ...ghost.querySelectorAll('*')]) {\n for (const attribute of Array.from(child.attributes))\n if (attribute.name.toLowerCase().startsWith('on')) child.removeAttribute(attribute.name)\n for (const attribute of ['id', 'name', 'form', 'autofocus']) child.removeAttribute(attribute)\n if (\n child instanceof HTMLInputElement ||\n child instanceof HTMLButtonElement ||\n child instanceof HTMLSelectElement ||\n child instanceof HTMLTextAreaElement\n )\n child.disabled = true\n }\n for (const [key, value] of bounds.variables) ghost.style.setProperty(key, value)\n ghost.style.font = getComputedStyle(node).font\n ghost.style.colorScheme = getComputedStyle(node).colorScheme\n Object.assign(ghost.style, {\n position: 'fixed',\n margin: '0px',\n left: `${bounds.left}px`,\n top: `${bounds.top}px`,\n width: `${bounds.width}px`,\n height: `${bounds.height}px`,\n maxHeight: 'none',\n pointerEvents: 'none',\n zIndex: '2147483647',\n transition: 'none'\n })\n node.ownerDocument.body.append(ghost)\n }\n const off = spring.subscribe(value => {\n if (ghost) {\n ghost.style.scale = String(Math.max(0, value))\n ghost.style.opacity = String(Math.max(0, Math.min(1, (value - 0.94) / 0.06)))\n if (!node.open && Math.abs(value - 0.94) < 0.0001) clear()\n }\n })\n function sync() {\n if (node.open === open) return\n open = node.open\n const enabled = resolveMotion(profile, 'dialog', query.matches).enabled\n if (open) {\n clear()\n bounds = geometry()\n spring.configure({ reducedValue: 1 })\n spring.to(1)\n } else {\n if (enabled) snapshot()\n spring.configure({ reducedValue: 0.94 })\n spring.to(0.94)\n if (!enabled) clear()\n }\n }\n const beforeToggle = () => {\n if (node.open) bounds = geometry()\n }\n node.addEventListener('beforetoggle', beforeToggle)\n const observer = new MutationObserver(sync)\n observer.observe(node, { attributes: true, attributeFilter: ['open'] })\n const resize = new ResizeObserver(() => {\n if (node.open) bounds = geometry()\n })\n resize.observe(node)\n function update(next: MotionProfile) {\n profile = next\n spring.configure({\n ...resolveMotion(profile, 'dialog', query.matches),\n reducedValue: node.open ? 1 : 0.94\n })\n if (!resolveMotion(profile, 'dialog', query.matches).enabled) clear()\n sync()\n }\n const preference = () => update(profile)\n query.addEventListener('change', preference)\n return {\n update,\n destroy() {\n observer.disconnect()\n resize.disconnect()\n query.removeEventListener('change', preference)\n off()\n spring.destroy()\n unbind()\n node.removeEventListener('beforetoggle', beforeToggle)\n clear()\n }\n }\n}\n"]}
|