@atom.io/spa 0.0.5 → 0.0.7
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/README.md +381 -10
- package/README.mdx +101 -5
- package/dist/astro-application.d.ts +1 -1
- package/dist/astro-client.d.ts +1 -1
- package/dist/astro-client.js +2 -2
- package/dist/astro-request-DRKvDjsO.js.map +1 -1
- package/dist/astro-resumability-client.d.ts +1 -1
- package/dist/astro-server.js +1 -1
- package/dist/{astro-shared-DHIpjNIG.d.ts → astro-shared-DZp1x8RQ.d.ts} +2 -2
- package/dist/{astro-shared-DHIpjNIG.d.ts.map → astro-shared-DZp1x8RQ.d.ts.map} +1 -1
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +1 -1
- package/dist/{capabilities-BCtBG-ni.d.ts → capabilities-DNcnGRv_.d.ts} +11 -5
- package/dist/capabilities-DNcnGRv_.d.ts.map +1 -0
- package/dist/{capabilities-BkQ2i0vV.js → capabilities-nOIitQ-_.js} +6 -4
- package/dist/capabilities-nOIitQ-_.js.map +1 -0
- package/dist/client.min.js +1 -1
- package/dist/{core-DjFJ0aIJ.js → core-B4rJ0xdc.js} +22 -12
- package/dist/core-B4rJ0xdc.js.map +1 -0
- package/dist/development/astro-client.js +2 -2
- package/dist/development/astro-request-DRKvDjsO.js.map +1 -1
- package/dist/development/astro-server.js +1 -1
- package/dist/development/astro.js +1 -1
- package/dist/development/{capabilities-BkQ2i0vV.js → capabilities-nOIitQ-_.js} +6 -4
- package/dist/development/capabilities-nOIitQ-_.js.map +1 -0
- package/dist/development/{core-DxPiKryn.js → core-BHA7I1nf.js} +24 -14
- package/dist/development/core-BHA7I1nf.js.map +1 -0
- package/dist/development/{dom-BytVV6Rp.js → dom-DQ0M3rLL.js} +11 -10
- package/dist/development/{dom-BytVV6Rp.js.map → dom-DQ0M3rLL.js.map} +1 -1
- package/dist/development/floating.js +148 -0
- package/dist/development/floating.js.map +1 -0
- package/dist/development/index.js +4 -4
- package/dist/development/jsx-runtime.js +2 -2
- package/dist/development/jsx-runtime.js.map +1 -1
- package/dist/development/konva.js +2 -2
- package/dist/development/motion.js +419 -25
- package/dist/development/motion.js.map +1 -1
- package/dist/development/renderer.js +2 -2
- package/dist/development/{server-renderer-CUQXh9oF.js → server-renderer-DCLoMdOX.js} +3 -3
- package/dist/development/{server-renderer-CUQXh9oF.js.map → server-renderer-DCLoMdOX.js.map} +1 -1
- package/dist/development/server.js +1 -1
- package/dist/{src-DWIqXCiz.js → development/src-DoQgCX-O.js} +2 -2
- package/dist/development/{src-WSHJxR9b.js.map → src-DoQgCX-O.js.map} +1 -1
- package/dist/development/three.js +87 -31
- package/dist/development/three.js.map +1 -1
- package/dist/development/{vite-CSHoxzXU.js → vite-Bmyb6P5w.js} +32 -7
- package/dist/development/vite-Bmyb6P5w.js.map +1 -0
- package/dist/development/vite.js +1 -1
- package/dist/{dom-B5OxgHkr.js → dom-D8g3roX9.js} +11 -10
- package/dist/{dom-B5OxgHkr.js.map → dom-D8g3roX9.js.map} +1 -1
- package/dist/floating.d.ts +16 -0
- package/dist/floating.d.ts.map +1 -0
- package/dist/floating.js +148 -0
- package/dist/floating.js.map +1 -0
- package/dist/{index-DufwkB6W.d.ts → index-BFnXIfOj.d.ts} +3 -3
- package/dist/{index-DufwkB6W.d.ts.map → index-BFnXIfOj.d.ts.map} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/{jsx-runtime-DMDVr7A5.d.ts → jsx-runtime-DQnpyT_g.d.ts} +2 -2
- package/dist/{jsx-runtime-DMDVr7A5.d.ts.map → jsx-runtime-DQnpyT_g.d.ts.map} +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js +2 -2
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/konva.d.ts +3 -3
- package/dist/konva.js +2 -2
- package/dist/motion.d.ts +39 -16
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +419 -25
- package/dist/motion.js.map +1 -1
- package/dist/renderer.d.ts +1 -1
- package/dist/renderer.js +2 -2
- package/dist/{server-renderer-DcU55e6s.js → server-renderer-D0rsFL_-.js} +3 -3
- package/dist/{server-renderer-DcU55e6s.js.map → server-renderer-D0rsFL_-.js.map} +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/size.json +12 -12
- package/dist/{development/src-WSHJxR9b.js → src-Bme1kz2b.js} +2 -2
- package/dist/{src-DWIqXCiz.js.map → src-Bme1kz2b.js.map} +1 -1
- package/dist/three.d.ts +27 -8
- package/dist/three.d.ts.map +1 -1
- package/dist/three.js +87 -31
- package/dist/three.js.map +1 -1
- package/dist/{vite-CSHoxzXU.js → vite-Bmyb6P5w.js} +32 -7
- package/dist/vite-Bmyb6P5w.js.map +1 -0
- package/dist/vite.js +1 -1
- package/package.json +18 -5
- package/src/astro-request.ts +1 -1
- package/src/capabilities.ts +11 -4
- package/src/compiler.ts +28 -9
- package/src/core.ts +26 -12
- package/src/dom.ts +12 -11
- package/src/floating.ts +234 -0
- package/src/index.ts +1 -0
- package/src/jsx-runtime.ts +4 -1
- package/src/motion-layout.ts +363 -0
- package/src/motion-transition.ts +92 -0
- package/src/motion-tween.ts +19 -2
- package/src/motion.ts +215 -77
- package/src/presence.ts +1 -1
- package/src/three-events.ts +14 -10
- package/src/three.ts +134 -39
- package/dist/capabilities-BCtBG-ni.d.ts.map +0 -1
- package/dist/capabilities-BkQ2i0vV.js.map +0 -1
- package/dist/core-DjFJ0aIJ.js.map +0 -1
- package/dist/development/capabilities-BkQ2i0vV.js.map +0 -1
- package/dist/development/core-DxPiKryn.js.map +0 -1
- package/dist/development/vite-CSHoxzXU.js.map +0 -1
- package/dist/vite-CSHoxzXU.js.map +0 -1
package/dist/motion.js
CHANGED
|
@@ -1,5 +1,310 @@
|
|
|
1
|
-
import { a as invalidate, i as fail, o as isPresent, p as untrack, r as dispose } from "./core-
|
|
2
|
-
import { animate, cancelFrame, frame, hover, keyframes, motionValue, press, readStyleValue, styleEffect } from "motion";
|
|
1
|
+
import { S as within, a as invalidate, i as fail, l as onMount, o as isPresent, p as untrack, r as dispose } from "./core-B4rJ0xdc.js";
|
|
2
|
+
import { acquireProjectionNode, animate, cancelFrame, frame, handOffElementState, hover, keyframes, motionValue, press, readStyleValue, styleEffect, visualElementStore } from "motion";
|
|
3
|
+
// src/motion-layout.ts
|
|
4
|
+
let serial = 0;
|
|
5
|
+
function createLayoutController(root, options) {
|
|
6
|
+
const prefix = serial++;
|
|
7
|
+
const entries = /* @__PURE__ */ new Set();
|
|
8
|
+
let dead = false;
|
|
9
|
+
let updating = false;
|
|
10
|
+
const preference = options.reducedMotion !== `never` && typeof matchMedia === `function` ? matchMedia(`(prefers-reduced-motion: reduce)`) : void 0;
|
|
11
|
+
const reduced = () => options.reducedMotion === `always` || options.reducedMotion !== `never` && Boolean(preference?.matches);
|
|
12
|
+
const report = (error) => {
|
|
13
|
+
try {
|
|
14
|
+
fail(root, error);
|
|
15
|
+
} catch (failure) {
|
|
16
|
+
root.error(failure);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const ordered = () => [...entries].filter((entry) => entry.mounted && !entry.dead && entry.element.isConnected).sort((a, b) => a.element.compareDocumentPosition(b.element) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
|
|
20
|
+
const release = (entry) => {
|
|
21
|
+
const detach = entry.release;
|
|
22
|
+
entry.release = void 0;
|
|
23
|
+
entry.node = void 0;
|
|
24
|
+
entry.refreshStyles = entry.captureStyles = void 0;
|
|
25
|
+
detach?.();
|
|
26
|
+
};
|
|
27
|
+
const configure = (entry) => {
|
|
28
|
+
const transition = entry.props.transition ?? options.layoutTransition ?? { duration: .3 };
|
|
29
|
+
for (const name of [
|
|
30
|
+
`duration`,
|
|
31
|
+
`delay`,
|
|
32
|
+
`stiffness`,
|
|
33
|
+
`damping`,
|
|
34
|
+
`mass`
|
|
35
|
+
]) {
|
|
36
|
+
const value = transition[name];
|
|
37
|
+
if (value !== void 0 && (!Number.isFinite(value) || value < 0 || [
|
|
38
|
+
`stiffness`,
|
|
39
|
+
`damping`,
|
|
40
|
+
`mass`
|
|
41
|
+
].includes(name) && value === 0)) throw new Error(`spa/motion: transitions must settle in finite time`);
|
|
42
|
+
}
|
|
43
|
+
entry.node.setOptions({
|
|
44
|
+
layoutScroll: entry.props.scroll ?? false,
|
|
45
|
+
animationType: typeof entry.props.animate === `string` ? entry.props.animate : `both`,
|
|
46
|
+
animate: entry.props.animate !== false && !reduced(),
|
|
47
|
+
transition: reduced() ? { duration: 0 } : transition
|
|
48
|
+
});
|
|
49
|
+
if (reduced()) entry.node.finishAnimation();
|
|
50
|
+
};
|
|
51
|
+
const prepare = (entry) => {
|
|
52
|
+
const { element, props } = entry;
|
|
53
|
+
const identity = JSON.stringify([
|
|
54
|
+
prefix,
|
|
55
|
+
props.group ?? ``,
|
|
56
|
+
props.id ?? null,
|
|
57
|
+
props.animate ?? true
|
|
58
|
+
]);
|
|
59
|
+
if (entry.node && entry.identity !== identity) release(entry);
|
|
60
|
+
if (!entry.node) {
|
|
61
|
+
const attrs = [`data-layout`, `data-layout-id`].map((name) => [name, element.getAttribute(name)]);
|
|
62
|
+
const styleNames = [
|
|
63
|
+
`transform`,
|
|
64
|
+
`transform-origin`,
|
|
65
|
+
`opacity`,
|
|
66
|
+
`visibility`,
|
|
67
|
+
`pointer-events`
|
|
68
|
+
];
|
|
69
|
+
const style = element.ownerDocument.createElement(`div`).style;
|
|
70
|
+
style.cssText = element.style.cssText;
|
|
71
|
+
const restore = (name) => {
|
|
72
|
+
const value = style.getPropertyValue(name);
|
|
73
|
+
if (value) element.style.setProperty(name, value, style.getPropertyPriority(name));
|
|
74
|
+
else element.style.removeProperty(name);
|
|
75
|
+
};
|
|
76
|
+
element.removeAttribute(`data-layout`);
|
|
77
|
+
element.removeAttribute(`data-layout-id`);
|
|
78
|
+
if (props.animate !== false) element.setAttribute(`data-layout`, typeof props.animate === `string` ? props.animate : `true`);
|
|
79
|
+
if (props.id !== void 0 && props.animate !== false) element.setAttribute(`data-layout-id`, JSON.stringify([
|
|
80
|
+
prefix,
|
|
81
|
+
props.group ?? ``,
|
|
82
|
+
props.id
|
|
83
|
+
]));
|
|
84
|
+
const [node, detach] = acquireProjectionNode(element);
|
|
85
|
+
entry.node = node;
|
|
86
|
+
entry.identity = identity;
|
|
87
|
+
const visual = node.options.visualElement;
|
|
88
|
+
const originalProps = visual.getProps();
|
|
89
|
+
const originalValues = { ...node.latestValues };
|
|
90
|
+
let opacity = `1`;
|
|
91
|
+
let visibility = ``;
|
|
92
|
+
let pointerEvents = ``;
|
|
93
|
+
let transform = ``;
|
|
94
|
+
const transformTemplate = (_, projected) => `${projected === `none` ? `` : projected} ${transform}`.trim();
|
|
95
|
+
entry.captureStyles = () => {
|
|
96
|
+
style.cssText = element.style.cssText;
|
|
97
|
+
};
|
|
98
|
+
entry.refreshStyles = () => {
|
|
99
|
+
const rendered = element.style.cssText;
|
|
100
|
+
for (const name of styleNames) restore(name);
|
|
101
|
+
try {
|
|
102
|
+
const authored = getComputedStyle(element);
|
|
103
|
+
opacity = authored.opacity || `1`;
|
|
104
|
+
visibility = authored.visibility;
|
|
105
|
+
pointerEvents = authored.pointerEvents;
|
|
106
|
+
transform = authored.transform;
|
|
107
|
+
if (!visual.values.has(`opacity`)) node.latestValues[`opacity`] = Number(opacity);
|
|
108
|
+
const origin = authored.transformOrigin.split(` `);
|
|
109
|
+
for (const [key, value] of [[`originX`, parseFloat(origin[0]) / (element.offsetWidth || 1)], [`originY`, parseFloat(origin[1]) / (element.offsetHeight || 1)]]) if (!visual.values.has(key) && Number.isFinite(value)) node.latestValues[key] = value;
|
|
110
|
+
} finally {
|
|
111
|
+
element.style.cssText = rendered;
|
|
112
|
+
}
|
|
113
|
+
const template = transform && transform !== `none` && !Object.keys(visual.latestValues).some((key) => /^(x|y|scale|rotate|skew)/.test(key)) ? transformTemplate : originalProps.transformTemplate;
|
|
114
|
+
if (visual.getProps().transformTemplate !== template) {
|
|
115
|
+
const next = { ...visual.getProps() };
|
|
116
|
+
if (template) next.transformTemplate = template;
|
|
117
|
+
else delete next.transformTemplate;
|
|
118
|
+
visual.update(next, null);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const applyProjectionStyles = node.applyProjectionStyles;
|
|
122
|
+
node.applyProjectionStyles = (targetStyle, styleProp) => {
|
|
123
|
+
applyProjectionStyles.call(node, targetStyle, {
|
|
124
|
+
...styleProp,
|
|
125
|
+
pointerEvents: styleProp?.[`pointerEvents`] ?? pointerEvents
|
|
126
|
+
});
|
|
127
|
+
if (!targetStyle.visibility) targetStyle.visibility = visibility;
|
|
128
|
+
if (!targetStyle.opacity) targetStyle.opacity = String(node.latestValues[`opacity`] ?? opacity);
|
|
129
|
+
};
|
|
130
|
+
entry.release = () => {
|
|
131
|
+
try {
|
|
132
|
+
if (node.isLead()) node.finishAnimation();
|
|
133
|
+
detach();
|
|
134
|
+
} finally {
|
|
135
|
+
node.applyProjectionStyles = applyProjectionStyles;
|
|
136
|
+
visual.projection = void 0;
|
|
137
|
+
for (const key of [
|
|
138
|
+
`opacity`,
|
|
139
|
+
`originX`,
|
|
140
|
+
`originY`
|
|
141
|
+
]) if (!visual.values.has(key)) {
|
|
142
|
+
if (originalValues[key] === void 0) Reflect.deleteProperty(node.latestValues, key);
|
|
143
|
+
else node.latestValues[key] = originalValues[key];
|
|
144
|
+
}
|
|
145
|
+
const retained = !root._dead && !entry.scope._dead && visual.values.size > 0;
|
|
146
|
+
if (!retained) {
|
|
147
|
+
visual.unmount();
|
|
148
|
+
visualElementStore.delete(element);
|
|
149
|
+
} else visual.update(originalProps, null);
|
|
150
|
+
for (const [name, value] of attrs) if (value === null) element.removeAttribute(name);
|
|
151
|
+
else element.setAttribute(name, value);
|
|
152
|
+
for (const name of styleNames) restore(name);
|
|
153
|
+
if (retained) visual.scheduleRender();
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
observer?.observe(element);
|
|
157
|
+
}
|
|
158
|
+
entry.refreshStyles();
|
|
159
|
+
configure(entry);
|
|
160
|
+
entry.size = `${element.offsetWidth}:${element.offsetHeight}`;
|
|
161
|
+
};
|
|
162
|
+
const commit = () => {
|
|
163
|
+
try {
|
|
164
|
+
if (dead) return;
|
|
165
|
+
for (const entry of ordered()) prepare(entry);
|
|
166
|
+
const roots = new Set([...entries].flatMap((entry) => entry.node ? [entry.node.root ?? entry.node] : []));
|
|
167
|
+
for (const projection of roots) projection.didUpdate();
|
|
168
|
+
for (const entry of entries) if (entry.dead) {
|
|
169
|
+
observer?.unobserve(entry.element);
|
|
170
|
+
release(entry);
|
|
171
|
+
entries.delete(entry);
|
|
172
|
+
}
|
|
173
|
+
} finally {
|
|
174
|
+
updating = false;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const observer = typeof ResizeObserver === `function` ? new ResizeObserver((changes) => {
|
|
178
|
+
if (dead || updating) return;
|
|
179
|
+
try {
|
|
180
|
+
for (const change of changes) {
|
|
181
|
+
const entry = [...entries].find((candidate) => candidate.element === change.target);
|
|
182
|
+
if (!entry?.node || entry.size === `${entry.element.offsetWidth}:${entry.element.offsetHeight}`) continue;
|
|
183
|
+
const previous = entry.node.layout;
|
|
184
|
+
entry.node.willUpdate();
|
|
185
|
+
if (previous) entry.node.snapshot = previous;
|
|
186
|
+
}
|
|
187
|
+
commit();
|
|
188
|
+
} catch (error) {
|
|
189
|
+
report(error);
|
|
190
|
+
}
|
|
191
|
+
}) : void 0;
|
|
192
|
+
const mediaChanged = () => {
|
|
193
|
+
try {
|
|
194
|
+
for (const entry of entries) if (entry.node) configure(entry);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
report(error);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
preference?.addEventListener(`change`, mediaChanged);
|
|
200
|
+
root._cleanups.add(() => {
|
|
201
|
+
dead = true;
|
|
202
|
+
observer?.disconnect();
|
|
203
|
+
preference?.removeEventListener(`change`, mediaChanged);
|
|
204
|
+
const errors = [];
|
|
205
|
+
for (const entry of entries) try {
|
|
206
|
+
release(entry);
|
|
207
|
+
} catch (error) {
|
|
208
|
+
errors.push(error);
|
|
209
|
+
}
|
|
210
|
+
entries.clear();
|
|
211
|
+
if (errors.length) throw new AggregateError(errors);
|
|
212
|
+
});
|
|
213
|
+
return {
|
|
214
|
+
commit,
|
|
215
|
+
beforeUpdate() {
|
|
216
|
+
updating = true;
|
|
217
|
+
for (const entry of ordered()) {
|
|
218
|
+
prepare(entry);
|
|
219
|
+
entry.node.willUpdate();
|
|
220
|
+
}
|
|
221
|
+
return commit;
|
|
222
|
+
},
|
|
223
|
+
attach(element, scope) {
|
|
224
|
+
const entry = {
|
|
225
|
+
element,
|
|
226
|
+
scope,
|
|
227
|
+
props: {},
|
|
228
|
+
mounted: false,
|
|
229
|
+
dead: false
|
|
230
|
+
};
|
|
231
|
+
entries.add(entry);
|
|
232
|
+
within(scope, () => {
|
|
233
|
+
onMount(() => {
|
|
234
|
+
entry.mounted = true;
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
return {
|
|
238
|
+
update(props, previousStyle) {
|
|
239
|
+
entry.props = props;
|
|
240
|
+
if (previousStyle !== void 0) entry.captureStyles?.();
|
|
241
|
+
},
|
|
242
|
+
exit() {
|
|
243
|
+
if (entry.node) entry.node.isPresent = false;
|
|
244
|
+
},
|
|
245
|
+
resume() {
|
|
246
|
+
if (entry.node) {
|
|
247
|
+
entry.node.isPresent = true;
|
|
248
|
+
entry.node.promote();
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
dispose() {
|
|
252
|
+
entry.dead = true;
|
|
253
|
+
if (!updating) {
|
|
254
|
+
observer?.unobserve(element);
|
|
255
|
+
release(entry);
|
|
256
|
+
entries.delete(entry);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
// src/motion-transition.ts
|
|
264
|
+
function finalFrame(value) {
|
|
265
|
+
return Array.isArray(value) ? value.at(-1) : value;
|
|
266
|
+
}
|
|
267
|
+
/** Property options override default options, which override top-level options. */
|
|
268
|
+
function propertyTransition(config, key, goal) {
|
|
269
|
+
const { default: fallback, properties, ...base } = config ?? {};
|
|
270
|
+
const transition = {
|
|
271
|
+
...base,
|
|
272
|
+
...fallback,
|
|
273
|
+
...properties?.[key]
|
|
274
|
+
};
|
|
275
|
+
const sequence = Array.isArray(goal);
|
|
276
|
+
if (sequence) {
|
|
277
|
+
if (goal.length < 2 || goal.some((value, index) => !(typeof value === `string` || typeof value === `number` && Number.isFinite(value) || index === 0 && value === null))) throw new Error(`spa/motion: keyframes require at least two scalar values; only the first may be null`);
|
|
278
|
+
if (transition.type === `spring` && goal.length > 2) throw new Error(`spa/motion: multi-keyframe sequences require a tween transition`);
|
|
279
|
+
transition.type ??= `tween`;
|
|
280
|
+
}
|
|
281
|
+
if (!sequence && !config) transition.type ??= `spring`;
|
|
282
|
+
const count = sequence ? goal.length : 2;
|
|
283
|
+
if (transition.times && (transition.times.length !== count || transition.times[0] !== 0 || transition.times.at(-1) !== 1 || transition.times.some((at, index, times) => !Number.isFinite(at) || at < 0 || at > 1 || index > 0 && at < times[index - 1]))) throw new Error(`spa/motion: times must match the keyframes and increase from 0 to 1`);
|
|
284
|
+
if (Array.isArray(transition.ease) && typeof transition.ease[0] !== `number` && transition.ease.length !== count - 1) throw new Error(`spa/motion: segment easing must match the keyframe intervals`);
|
|
285
|
+
for (const option of [
|
|
286
|
+
`duration`,
|
|
287
|
+
`delay`,
|
|
288
|
+
`visualDuration`,
|
|
289
|
+
`velocity`,
|
|
290
|
+
`bounce`,
|
|
291
|
+
`stiffness`,
|
|
292
|
+
`damping`,
|
|
293
|
+
`mass`,
|
|
294
|
+
`restDelta`,
|
|
295
|
+
`restSpeed`
|
|
296
|
+
]) {
|
|
297
|
+
const value = transition[option];
|
|
298
|
+
if (value !== void 0 && (!Number.isFinite(value) || option !== `velocity` && option !== `delay` && value < 0 || option === `bounce` && value >= 1 || [
|
|
299
|
+
`stiffness`,
|
|
300
|
+
`damping`,
|
|
301
|
+
`mass`,
|
|
302
|
+
`restDelta`,
|
|
303
|
+
`restSpeed`
|
|
304
|
+
].includes(option) && value === 0)) throw new Error(`spa/motion: animation requires a finite settling transition`);
|
|
305
|
+
}
|
|
306
|
+
return transition;
|
|
307
|
+
}
|
|
3
308
|
// src/motion-tween.ts
|
|
4
309
|
const trajectories = /* @__PURE__ */ new WeakMap();
|
|
5
310
|
const scalar = /^(-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)([a-z%]*)$/i;
|
|
@@ -7,6 +312,18 @@ const brake = (progress) => progress * (2 - progress);
|
|
|
7
312
|
const returnToTarget = (progress) => progress * progress * (3 - 2 * progress);
|
|
8
313
|
/** Retarget a moving tween without changing its position or velocity at the join. */
|
|
9
314
|
function animateTween(value, goal, transition, interrupted) {
|
|
315
|
+
if (Array.isArray(goal)) {
|
|
316
|
+
value.stop();
|
|
317
|
+
trajectories.delete(value);
|
|
318
|
+
let frames = goal.map((frame) => frame ?? value.get());
|
|
319
|
+
const units = frames.map((frame) => typeof frame === `number` ? `` : scalar.exec(frame)?.[2]);
|
|
320
|
+
const unit = units.find((suffix) => suffix);
|
|
321
|
+
if (unit && units.every((suffix) => suffix === `` || suffix === unit)) frames = frames.map((frame, index) => units[index] === `` ? `${frame}${unit}` : frame);
|
|
322
|
+
return animate(value, frames, {
|
|
323
|
+
...transition,
|
|
324
|
+
isSync: true
|
|
325
|
+
});
|
|
326
|
+
}
|
|
10
327
|
if (interrupted) value.stop();
|
|
11
328
|
const current = value.get();
|
|
12
329
|
const from = typeof current === `number` ? [
|
|
@@ -310,11 +627,17 @@ const allowed = /* @__PURE__ */ new Set([
|
|
|
310
627
|
`whileHover`,
|
|
311
628
|
`whileTap`
|
|
312
629
|
]);
|
|
630
|
+
const layoutKeys = {
|
|
631
|
+
layout: `animate`,
|
|
632
|
+
layoutId: `id`,
|
|
633
|
+
layoutGroup: `group`,
|
|
634
|
+
layoutScroll: `scroll`,
|
|
635
|
+
layoutTransition: `transition`
|
|
636
|
+
};
|
|
313
637
|
function equal(a, b) {
|
|
314
638
|
return Object.is(a, b) || Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((value, index) => Object.is(value, b[index]));
|
|
315
639
|
}
|
|
316
|
-
function
|
|
317
|
-
if (target.kind !== `dom` && (!target.read || !target.write)) throw new Error(`spa/motion: renderer ${target.kind} does not support motion`);
|
|
640
|
+
function attachValues(target, options) {
|
|
318
641
|
const element = target.kind === `dom` ? target.node : void 0;
|
|
319
642
|
const properties = /* @__PURE__ */ new Map();
|
|
320
643
|
const originalStyles = /* @__PURE__ */ new Map();
|
|
@@ -335,23 +658,28 @@ function attach(target, options) {
|
|
|
335
658
|
};
|
|
336
659
|
const bindStyles = () => {
|
|
337
660
|
styles?.();
|
|
338
|
-
if (element)
|
|
661
|
+
if (element) {
|
|
662
|
+
styles = styleEffect([element], Object.fromEntries([...properties].map(([key, property]) => [key, property.values[0]])));
|
|
663
|
+
const visual = visualElementStore.get(element);
|
|
664
|
+
if (visual) handOffElementState(element, visual);
|
|
665
|
+
}
|
|
339
666
|
};
|
|
340
667
|
const ensure = (key, goal, initial) => {
|
|
668
|
+
const vector = !element && Array.isArray(goal);
|
|
669
|
+
const sample = element ? finalFrame(goal) : goal;
|
|
341
670
|
const existing = properties.get(key);
|
|
342
671
|
if (existing) {
|
|
343
|
-
if (existing.values.length !== (
|
|
672
|
+
if (existing.values.length !== (vector ? goal.length : 1)) throw new Error(`spa/motion: cannot change the shape of ${key}`);
|
|
344
673
|
return existing;
|
|
345
674
|
}
|
|
346
|
-
const base = read(key,
|
|
347
|
-
const rest = !
|
|
348
|
-
let start = initial === false ?
|
|
349
|
-
if (!
|
|
350
|
-
if (
|
|
675
|
+
const base = read(key, sample);
|
|
676
|
+
const rest = !vector && Array.isArray(base) ? base[0] : base;
|
|
677
|
+
let start = initial === false ? sample : initial[key] ?? rest;
|
|
678
|
+
if (!vector && Array.isArray(start)) start = start[0];
|
|
679
|
+
if (vector && (!Array.isArray(start) || start.length !== goal.length)) throw new Error(`spa/motion: ${key} requires matching numeric tuples`);
|
|
351
680
|
const values = (Array.isArray(start) ? start : [start]).map((value) => motionValue(value));
|
|
352
681
|
const unsubscribers = [];
|
|
353
682
|
if (element) {
|
|
354
|
-
if (Array.isArray(goal)) throw new Error(`spa/motion: DOM targets must be scalar styles or transforms`);
|
|
355
683
|
const cssKey = transform.test(key) ? `transform` : key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
356
684
|
if (!originalStyles.has(cssKey)) originalStyles.set(cssKey, {
|
|
357
685
|
value: element.style.getPropertyValue(cssKey),
|
|
@@ -403,15 +731,15 @@ function attach(target, options) {
|
|
|
403
731
|
if (!had) added = true;
|
|
404
732
|
}
|
|
405
733
|
if (added) bindStyles();
|
|
406
|
-
const transition = props[`transition`] ?? { type: `spring` };
|
|
407
734
|
for (const [key, property] of properties) {
|
|
408
735
|
const goal = goals[key] ?? (initial === false ? void 0 : initial[key]) ?? property.rest;
|
|
409
736
|
if (!force && equal(property.target, goal)) continue;
|
|
410
737
|
property.target = Array.isArray(goal) ? [...goal] : goal;
|
|
411
|
-
const next = Array.isArray(goal) ? goal : [goal];
|
|
738
|
+
const next = !element && Array.isArray(goal) ? goal : [goal];
|
|
739
|
+
const transition = propertyTransition(props[`transition`], key, element ? goal : void 0);
|
|
412
740
|
if (next.length !== property.values.length) throw new Error(`spa/motion: cannot change the shape of ${key}`);
|
|
413
741
|
property.values.forEach((value, index) => {
|
|
414
|
-
if (reduced() || !started && initial === false) value.jump(next[index]);
|
|
742
|
+
if (reduced() || !started && initial === false) value.jump(finalFrame(next[index]));
|
|
415
743
|
else animateTween(value, next[index], transition, force || value.isAnimating());
|
|
416
744
|
});
|
|
417
745
|
}
|
|
@@ -468,9 +796,9 @@ function attach(target, options) {
|
|
|
468
796
|
};
|
|
469
797
|
const preferenceChanged = () => {
|
|
470
798
|
if (reduced()) for (const property of properties.values()) {
|
|
471
|
-
const goal = Array.isArray(property.target) ? property.target : [property.target];
|
|
799
|
+
const goal = !element && Array.isArray(property.target) ? property.target : [property.target];
|
|
472
800
|
property.values.forEach((value, i) => {
|
|
473
|
-
value.jump(goal[i]);
|
|
801
|
+
value.jump(finalFrame(goal[i]));
|
|
474
802
|
});
|
|
475
803
|
}
|
|
476
804
|
};
|
|
@@ -533,8 +861,9 @@ function attach(target, options) {
|
|
|
533
861
|
for (const [key, goal] of Object.entries(goals)) {
|
|
534
862
|
const property = properties.get(key);
|
|
535
863
|
property.target = Array.isArray(goal) ? [...goal] : goal;
|
|
536
|
-
const values = Array.isArray(goal) ? goal : [goal];
|
|
537
|
-
|
|
864
|
+
const values = !element && Array.isArray(goal) ? goal : [goal];
|
|
865
|
+
const resolved = propertyTransition(next[`transition`], key, element ? goal : void 0);
|
|
866
|
+
property.values.forEach((value, index) => controls.push(animateTween(value, values[index], resolved, moving.has(value))));
|
|
538
867
|
}
|
|
539
868
|
Promise.all(controls.map((control) => Promise.resolve(control))).then(settle, reject);
|
|
540
869
|
exitHandle = {
|
|
@@ -547,29 +876,32 @@ function attach(target, options) {
|
|
|
547
876
|
return exitHandle;
|
|
548
877
|
},
|
|
549
878
|
resume() {
|
|
550
|
-
if (dead) return;
|
|
551
879
|
exitHandle?.cancel();
|
|
552
880
|
exitHandle = void 0;
|
|
553
881
|
exiting = false;
|
|
554
882
|
installGestures();
|
|
555
883
|
refresh(true);
|
|
556
884
|
},
|
|
557
|
-
update(next) {
|
|
558
|
-
if (dead) return;
|
|
559
|
-
for (const key of Object.keys(next)) if (!allowed.has(key)) throw new Error(`spa/motion: unknown property motion:${key}`);
|
|
885
|
+
update(next, previousStyle) {
|
|
560
886
|
const gestureChange = !started || Boolean(next[`whileHover`]) !== Boolean(props[`whileHover`]) || Boolean(next[`whileTap`]) !== Boolean(props[`whileTap`]);
|
|
561
887
|
props = next;
|
|
562
888
|
if (gestureChange && !exiting) installGestures();
|
|
889
|
+
if (previousStyle !== void 0 && started && element) {
|
|
890
|
+
const snapshot = element.ownerDocument.createElement(`div`).style;
|
|
891
|
+
snapshot.cssText = previousStyle;
|
|
892
|
+
for (const key of originalStyles.keys()) element.style.setProperty(key, snapshot.getPropertyValue(key), snapshot.getPropertyPriority(key));
|
|
893
|
+
}
|
|
563
894
|
refresh();
|
|
564
895
|
},
|
|
565
896
|
dispose() {
|
|
566
|
-
if (dead) return;
|
|
567
897
|
dead = true;
|
|
568
898
|
clearGestures();
|
|
569
899
|
exitHandle?.cancel();
|
|
570
900
|
preference?.removeEventListener(`change`, mediaChanged);
|
|
571
901
|
styles?.();
|
|
902
|
+
const visual = element && visualElementStore.get(element);
|
|
572
903
|
for (const [key, property] of properties) {
|
|
904
|
+
if (visual?.values.get(key) === property.values[0]) visual.removeValue(key);
|
|
573
905
|
property.release();
|
|
574
906
|
if (!element) target.write(key, property.base);
|
|
575
907
|
}
|
|
@@ -581,10 +913,72 @@ function attach(target, options) {
|
|
|
581
913
|
}
|
|
582
914
|
/** Explicit, root-scoped motion:* integration. Importing it never registers globally. */
|
|
583
915
|
function motionCapability(options = {}) {
|
|
916
|
+
const layouts = /* @__PURE__ */ new WeakMap();
|
|
584
917
|
return {
|
|
585
918
|
namespace: `motion`,
|
|
586
919
|
presence: createPresence,
|
|
587
|
-
|
|
920
|
+
beforeUpdate(root) {
|
|
921
|
+
const layout = layouts.get(root);
|
|
922
|
+
return layout ? layout.beforeUpdate() : () => layouts.get(root)?.commit();
|
|
923
|
+
},
|
|
924
|
+
attach(target, scope) {
|
|
925
|
+
if (target.kind !== `dom` && (!target.read || !target.write)) throw new Error(`spa/motion: renderer ${target.kind} does not support motion`);
|
|
926
|
+
let values;
|
|
927
|
+
let layout;
|
|
928
|
+
let dead = false;
|
|
929
|
+
return {
|
|
930
|
+
update(next, previousStyle) {
|
|
931
|
+
if (dead) return;
|
|
932
|
+
const animated = {};
|
|
933
|
+
const projected = {};
|
|
934
|
+
for (const [key, value] of Object.entries(next)) if (Object.hasOwn(layoutKeys, key)) projected[layoutKeys[key]] = value;
|
|
935
|
+
else if (allowed.has(key)) animated[key] = value;
|
|
936
|
+
else throw new Error(`spa/motion: unknown property motion:${key}`);
|
|
937
|
+
if (Object.keys(projected).length) {
|
|
938
|
+
if (!layout) {
|
|
939
|
+
const element = target.node;
|
|
940
|
+
if (target.kind !== `dom` || element?.namespaceURI !== `http://www.w3.org/1999/xhtml` || !scope) throw new Error(`spa/motion: layout requires an owned HTML element`);
|
|
941
|
+
let controller = layouts.get(scope._root);
|
|
942
|
+
if (!controller) {
|
|
943
|
+
controller = createLayoutController(scope._root, options);
|
|
944
|
+
layouts.set(scope._root, controller);
|
|
945
|
+
}
|
|
946
|
+
layout = controller.attach(element, scope);
|
|
947
|
+
}
|
|
948
|
+
layout.update(projected, previousStyle);
|
|
949
|
+
} else {
|
|
950
|
+
layout?.dispose();
|
|
951
|
+
layout = void 0;
|
|
952
|
+
}
|
|
953
|
+
if (Object.keys(animated).length || values && !Object.keys(projected).length) {
|
|
954
|
+
values ??= attachValues(target, options);
|
|
955
|
+
values.update(animated, previousStyle);
|
|
956
|
+
} else {
|
|
957
|
+
values?.dispose();
|
|
958
|
+
values = void 0;
|
|
959
|
+
}
|
|
960
|
+
},
|
|
961
|
+
exit(next) {
|
|
962
|
+
if (dead) return void 0;
|
|
963
|
+
layout?.exit?.(next);
|
|
964
|
+
return values?.exit?.(next);
|
|
965
|
+
},
|
|
966
|
+
resume() {
|
|
967
|
+
if (dead) return;
|
|
968
|
+
layout?.resume?.();
|
|
969
|
+
values?.resume?.();
|
|
970
|
+
},
|
|
971
|
+
dispose() {
|
|
972
|
+
if (dead) return;
|
|
973
|
+
dead = true;
|
|
974
|
+
try {
|
|
975
|
+
values?.dispose();
|
|
976
|
+
} finally {
|
|
977
|
+
layout?.dispose();
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
};
|
|
981
|
+
},
|
|
588
982
|
scheduleFrame(callback) {
|
|
589
983
|
const run = ({ timestamp }) => {
|
|
590
984
|
callback(timestamp);
|