@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/src/motion.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { animate, MotionValue
|
|
1
|
+
import type { animate, MotionValue } from "motion"
|
|
2
2
|
import {
|
|
3
3
|
cancelFrame,
|
|
4
4
|
frame,
|
|
5
|
+
handOffElementState,
|
|
5
6
|
hover,
|
|
6
7
|
motionValue,
|
|
7
8
|
press,
|
|
8
9
|
readStyleValue,
|
|
9
10
|
styleEffect,
|
|
11
|
+
visualElementStore,
|
|
10
12
|
} from "motion"
|
|
11
13
|
|
|
12
14
|
import type {
|
|
@@ -14,10 +16,65 @@ import type {
|
|
|
14
16
|
CapabilityBinding,
|
|
15
17
|
CapabilityTarget,
|
|
16
18
|
} from "./capabilities.ts"
|
|
19
|
+
import type { Root } from "./core.ts"
|
|
20
|
+
import { createLayoutController } from "./motion-layout.ts"
|
|
21
|
+
import { finalFrame, propertyTransition } from "./motion-transition.ts"
|
|
17
22
|
import { animateTween } from "./motion-tween.ts"
|
|
18
23
|
import type { ExitHandle } from "./presence.ts"
|
|
19
24
|
import { createPresence } from "./presence.ts"
|
|
20
25
|
|
|
26
|
+
export type MotionKeyframes = readonly [
|
|
27
|
+
MotionScalar | null,
|
|
28
|
+
MotionScalar,
|
|
29
|
+
...MotionScalar[],
|
|
30
|
+
]
|
|
31
|
+
export type MotionEasing =
|
|
32
|
+
| `linear`
|
|
33
|
+
| `easeIn`
|
|
34
|
+
| `easeOut`
|
|
35
|
+
| `easeInOut`
|
|
36
|
+
| `circIn`
|
|
37
|
+
| `circOut`
|
|
38
|
+
| `circInOut`
|
|
39
|
+
| `backIn`
|
|
40
|
+
| `backOut`
|
|
41
|
+
| `backInOut`
|
|
42
|
+
| readonly [number, number, number, number]
|
|
43
|
+
/** Public options remain independent of optional Motion peer declarations. */
|
|
44
|
+
export interface MotionValueTransition {
|
|
45
|
+
type?: `spring` | `tween`
|
|
46
|
+
stiffness?: number
|
|
47
|
+
damping?: number
|
|
48
|
+
mass?: number
|
|
49
|
+
velocity?: number
|
|
50
|
+
restSpeed?: number
|
|
51
|
+
restDelta?: number
|
|
52
|
+
bounce?: number
|
|
53
|
+
visualDuration?: number
|
|
54
|
+
duration?: number
|
|
55
|
+
delay?: number
|
|
56
|
+
times?: readonly number[]
|
|
57
|
+
ease?: MotionEasing | readonly MotionEasing[]
|
|
58
|
+
}
|
|
59
|
+
export interface MotionTransition extends MotionValueTransition {
|
|
60
|
+
default?: MotionValueTransition
|
|
61
|
+
properties?: Readonly<Record<string, MotionValueTransition>>
|
|
62
|
+
}
|
|
63
|
+
export interface MotionLayoutTransition {
|
|
64
|
+
type?: `spring` | `tween`
|
|
65
|
+
duration?: number
|
|
66
|
+
delay?: number
|
|
67
|
+
ease?:
|
|
68
|
+
| `linear`
|
|
69
|
+
| `easeIn`
|
|
70
|
+
| `easeOut`
|
|
71
|
+
| `easeInOut`
|
|
72
|
+
| readonly [number, number, number, number]
|
|
73
|
+
stiffness?: number
|
|
74
|
+
damping?: number
|
|
75
|
+
mass?: number
|
|
76
|
+
}
|
|
77
|
+
|
|
21
78
|
export type MotionScalar = number | string
|
|
22
79
|
export type MotionDOMTarget = Partial<
|
|
23
80
|
Record<
|
|
@@ -35,7 +92,7 @@ export type MotionDOMTarget = Partial<
|
|
|
35
92
|
| `skewX`
|
|
36
93
|
| `skewY`
|
|
37
94
|
| `--${string}`,
|
|
38
|
-
MotionScalar
|
|
95
|
+
MotionScalar | MotionKeyframes
|
|
39
96
|
>
|
|
40
97
|
>
|
|
41
98
|
export interface MotionThreeTarget {
|
|
@@ -51,34 +108,19 @@ export type MotionTarget<Kind extends string> = Kind extends `dom`
|
|
|
51
108
|
: Kind extends `three`
|
|
52
109
|
? MotionThreeTarget
|
|
53
110
|
: Record<string, MotionScalar>
|
|
54
|
-
/** Supported transition options; keep public declarations independent of optional peer types. */
|
|
55
|
-
export interface MotionTransition {
|
|
56
|
-
type?: `spring` | `tween`
|
|
57
|
-
stiffness?: number
|
|
58
|
-
damping?: number
|
|
59
|
-
mass?: number
|
|
60
|
-
velocity?: number
|
|
61
|
-
restSpeed?: number
|
|
62
|
-
restDelta?: number
|
|
63
|
-
bounce?: number
|
|
64
|
-
visualDuration?: number
|
|
65
|
-
duration?: number
|
|
66
|
-
delay?: number
|
|
67
|
-
ease?:
|
|
68
|
-
| `linear`
|
|
69
|
-
| `easeIn`
|
|
70
|
-
| `easeOut`
|
|
71
|
-
| `easeInOut`
|
|
72
|
-
| `circIn`
|
|
73
|
-
| `circOut`
|
|
74
|
-
| `circInOut`
|
|
75
|
-
| `backIn`
|
|
76
|
-
| `backOut`
|
|
77
|
-
| `backInOut`
|
|
78
|
-
| readonly [number, number, number, number]
|
|
79
|
-
}
|
|
80
111
|
export interface MotionAttributes<Kind extends string = `dom`> {
|
|
81
|
-
[`motion:
|
|
112
|
+
[`motion:layout`]?: Kind extends `dom` ? boolean | `position` | `size` : never
|
|
113
|
+
[`motion:layoutId`]?: Kind extends `dom` ? string | number : never
|
|
114
|
+
[`motion:layoutGroup`]?: Kind extends `dom` ? string | number : never
|
|
115
|
+
[`motion:layoutScroll`]?: Kind extends `dom` ? boolean : never
|
|
116
|
+
[`motion:layoutTransition`]?: Kind extends `dom`
|
|
117
|
+
? MotionLayoutTransition
|
|
118
|
+
: never
|
|
119
|
+
[`motion:initial`]?:
|
|
120
|
+
| (Kind extends `dom`
|
|
121
|
+
? Partial<Record<keyof MotionDOMTarget, MotionScalar>>
|
|
122
|
+
: MotionTarget<Kind>)
|
|
123
|
+
| false
|
|
82
124
|
[`motion:animate`]?: MotionTarget<Kind>
|
|
83
125
|
[`motion:exit`]?: MotionTarget<Kind>
|
|
84
126
|
[`motion:transition`]?: MotionTransition
|
|
@@ -97,13 +139,16 @@ declare module "@atom.io/spa/jsx-runtime" {
|
|
|
97
139
|
export interface MotionCapabilityOptions {
|
|
98
140
|
/** Respect the user's reduced-motion preference by default. */
|
|
99
141
|
reducedMotion?: `user` | `always` | `never`
|
|
142
|
+
/** Default transition for layout projection; animated properties use motion:transition. */
|
|
143
|
+
layoutTransition?: MotionLayoutTransition
|
|
100
144
|
}
|
|
101
|
-
type
|
|
145
|
+
type TargetValue = MotionScalar | readonly (MotionScalar | null)[]
|
|
146
|
+
type TargetValues = Record<string, TargetValue>
|
|
102
147
|
interface AnimatedProperty {
|
|
103
148
|
values: MotionValue<MotionScalar>[]
|
|
104
|
-
base:
|
|
105
|
-
rest:
|
|
106
|
-
target:
|
|
149
|
+
base: TargetValue
|
|
150
|
+
rest: TargetValue
|
|
151
|
+
target: TargetValue
|
|
107
152
|
release(): void
|
|
108
153
|
}
|
|
109
154
|
const transform =
|
|
@@ -116,6 +161,13 @@ const allowed = new Set([
|
|
|
116
161
|
`whileHover`,
|
|
117
162
|
`whileTap`,
|
|
118
163
|
])
|
|
164
|
+
const layoutKeys = {
|
|
165
|
+
layout: `animate`,
|
|
166
|
+
layoutId: `id`,
|
|
167
|
+
layoutGroup: `group`,
|
|
168
|
+
layoutScroll: `scroll`,
|
|
169
|
+
layoutTransition: `transition`,
|
|
170
|
+
} as const
|
|
119
171
|
function equal(a: unknown, b: unknown): boolean {
|
|
120
172
|
return (
|
|
121
173
|
Object.is(a, b) ||
|
|
@@ -126,14 +178,10 @@ function equal(a: unknown, b: unknown): boolean {
|
|
|
126
178
|
)
|
|
127
179
|
}
|
|
128
180
|
|
|
129
|
-
function
|
|
181
|
+
function attachValues(
|
|
130
182
|
target: CapabilityTarget,
|
|
131
183
|
options: MotionCapabilityOptions,
|
|
132
184
|
): CapabilityBinding {
|
|
133
|
-
if (target.kind !== `dom` && (!target.read || !target.write))
|
|
134
|
-
throw new Error(
|
|
135
|
-
`spa/motion: renderer ${target.kind} does not support motion`,
|
|
136
|
-
)
|
|
137
185
|
const element =
|
|
138
186
|
target.kind === `dom` ? (target.node as HTMLElement | SVGElement) : undefined
|
|
139
187
|
const properties = new Map<string, AnimatedProperty>()
|
|
@@ -166,43 +214,42 @@ function attach(
|
|
|
166
214
|
}
|
|
167
215
|
const bindStyles = () => {
|
|
168
216
|
styles?.()
|
|
169
|
-
if (element)
|
|
217
|
+
if (element) {
|
|
170
218
|
styles = styleEffect(
|
|
171
219
|
[element],
|
|
172
220
|
Object.fromEntries(
|
|
173
221
|
[...properties].map(([key, property]) => [key, property.values[0]]),
|
|
174
222
|
) as any,
|
|
175
223
|
)
|
|
224
|
+
// Layout projection and late-added/gesture values must render together.
|
|
225
|
+
const visual = visualElementStore.get(element)
|
|
226
|
+
if (visual) handOffElementState(element, visual)
|
|
227
|
+
}
|
|
176
228
|
}
|
|
177
229
|
const ensure = (
|
|
178
230
|
key: string,
|
|
179
|
-
goal:
|
|
231
|
+
goal: TargetValue,
|
|
180
232
|
initial: TargetValues | false,
|
|
181
233
|
): AnimatedProperty => {
|
|
234
|
+
const vector = !element && Array.isArray(goal)
|
|
235
|
+
const sample = element ? finalFrame(goal) : goal
|
|
182
236
|
const existing = properties.get(key)
|
|
183
237
|
if (existing) {
|
|
184
|
-
if (existing.values.length !== (
|
|
238
|
+
if (existing.values.length !== (vector ? goal.length : 1))
|
|
185
239
|
throw new Error(`spa/motion: cannot change the shape of ${key}`)
|
|
186
240
|
return existing
|
|
187
241
|
}
|
|
188
|
-
const base = read(key,
|
|
189
|
-
const rest = !
|
|
190
|
-
let start = initial === false ?
|
|
191
|
-
if (!
|
|
192
|
-
if (
|
|
193
|
-
Array.isArray(goal) &&
|
|
194
|
-
(!Array.isArray(start) || start.length !== goal.length)
|
|
195
|
-
)
|
|
242
|
+
const base = read(key, sample) as TargetValue
|
|
243
|
+
const rest = !vector && Array.isArray(base) ? base[0]! : base
|
|
244
|
+
let start = initial === false ? sample : (initial[key] ?? rest)
|
|
245
|
+
if (!vector && Array.isArray(start)) start = start[0]!
|
|
246
|
+
if (vector && (!Array.isArray(start) || start.length !== goal.length))
|
|
196
247
|
throw new Error(`spa/motion: ${key} requires matching numeric tuples`)
|
|
197
248
|
const values = (Array.isArray(start) ? start : [start]).map((value) =>
|
|
198
249
|
motionValue(value),
|
|
199
250
|
) as MotionValue<MotionScalar>[]
|
|
200
251
|
const unsubscribers: (() => void)[] = []
|
|
201
252
|
if (element) {
|
|
202
|
-
if (Array.isArray(goal))
|
|
203
|
-
throw new Error(
|
|
204
|
-
`spa/motion: DOM targets must be scalar styles or transforms`,
|
|
205
|
-
)
|
|
206
253
|
const cssKey = transform.test(key)
|
|
207
254
|
? `transform`
|
|
208
255
|
: key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)
|
|
@@ -266,9 +313,6 @@ function attach(
|
|
|
266
313
|
if (!had) added = true
|
|
267
314
|
}
|
|
268
315
|
if (added) bindStyles()
|
|
269
|
-
const transition = (props[`transition`] ?? {
|
|
270
|
-
type: `spring`,
|
|
271
|
-
}) as ValueAnimationTransition
|
|
272
316
|
for (const [key, property] of properties) {
|
|
273
317
|
const goal =
|
|
274
318
|
goals[key] ??
|
|
@@ -276,11 +320,17 @@ function attach(
|
|
|
276
320
|
property.rest
|
|
277
321
|
if (!force && equal(property.target, goal)) continue
|
|
278
322
|
property.target = Array.isArray(goal) ? [...goal] : goal
|
|
279
|
-
const next = Array.isArray(goal) ? goal : [goal]
|
|
323
|
+
const next = !element && Array.isArray(goal) ? goal : [goal]
|
|
324
|
+
const transition = propertyTransition(
|
|
325
|
+
props[`transition`] as MotionTransition | undefined,
|
|
326
|
+
key,
|
|
327
|
+
element ? goal : undefined,
|
|
328
|
+
)
|
|
280
329
|
if (next.length !== property.values.length)
|
|
281
330
|
throw new Error(`spa/motion: cannot change the shape of ${key}`)
|
|
282
331
|
property.values.forEach((value, index) => {
|
|
283
|
-
if (reduced() || (!started && initial === false))
|
|
332
|
+
if (reduced() || (!started && initial === false))
|
|
333
|
+
value.jump(finalFrame(next[index]))
|
|
284
334
|
else
|
|
285
335
|
animateTween(
|
|
286
336
|
value,
|
|
@@ -354,11 +404,12 @@ function attach(
|
|
|
354
404
|
const preferenceChanged = () => {
|
|
355
405
|
if (reduced()) {
|
|
356
406
|
for (const property of properties.values()) {
|
|
357
|
-
const goal =
|
|
358
|
-
|
|
359
|
-
|
|
407
|
+
const goal =
|
|
408
|
+
!element && Array.isArray(property.target)
|
|
409
|
+
? property.target
|
|
410
|
+
: [property.target]
|
|
360
411
|
property.values.forEach((value, i) => {
|
|
361
|
-
value.jump(goal[i])
|
|
412
|
+
value.jump(finalFrame(goal[i]))
|
|
362
413
|
})
|
|
363
414
|
}
|
|
364
415
|
}
|
|
@@ -431,15 +482,15 @@ function attach(
|
|
|
431
482
|
for (const [key, goal] of Object.entries(goals)) {
|
|
432
483
|
const property = properties.get(key)!
|
|
433
484
|
property.target = Array.isArray(goal) ? [...goal] : goal
|
|
434
|
-
const values = Array.isArray(goal) ? goal : [goal]
|
|
485
|
+
const values = !element && Array.isArray(goal) ? goal : [goal]
|
|
486
|
+
const resolved = propertyTransition(
|
|
487
|
+
next[`transition`] as MotionTransition | undefined,
|
|
488
|
+
key,
|
|
489
|
+
element ? goal : undefined,
|
|
490
|
+
)
|
|
435
491
|
property.values.forEach((value, index) =>
|
|
436
492
|
controls.push(
|
|
437
|
-
animateTween(
|
|
438
|
-
value,
|
|
439
|
-
values[index],
|
|
440
|
-
transition as ValueAnimationTransition,
|
|
441
|
-
moving.has(value),
|
|
442
|
-
),
|
|
493
|
+
animateTween(value, values[index], resolved, moving.has(value)),
|
|
443
494
|
),
|
|
444
495
|
)
|
|
445
496
|
}
|
|
@@ -457,34 +508,42 @@ function attach(
|
|
|
457
508
|
return exitHandle
|
|
458
509
|
},
|
|
459
510
|
resume() {
|
|
460
|
-
if (dead) return
|
|
461
511
|
exitHandle?.cancel()
|
|
462
512
|
exitHandle = undefined
|
|
463
513
|
exiting = false
|
|
464
514
|
installGestures()
|
|
465
515
|
refresh(true)
|
|
466
516
|
},
|
|
467
|
-
update(next) {
|
|
468
|
-
if (dead) return
|
|
469
|
-
for (const key of Object.keys(next))
|
|
470
|
-
if (!allowed.has(key))
|
|
471
|
-
throw new Error(`spa/motion: unknown property motion:${key}`)
|
|
517
|
+
update(next, previousStyle) {
|
|
472
518
|
const gestureChange =
|
|
473
519
|
!started ||
|
|
474
520
|
Boolean(next[`whileHover`]) !== Boolean(props[`whileHover`]) ||
|
|
475
521
|
Boolean(next[`whileTap`]) !== Boolean(props[`whileTap`])
|
|
476
522
|
props = next
|
|
477
523
|
if (gestureChange && !exiting) installGestures()
|
|
524
|
+
if (previousStyle !== undefined && started && element) {
|
|
525
|
+
const snapshot = element.ownerDocument.createElement(`div`).style
|
|
526
|
+
snapshot.cssText = previousStyle
|
|
527
|
+
for (const key of originalStyles.keys())
|
|
528
|
+
element.style.setProperty(
|
|
529
|
+
key,
|
|
530
|
+
snapshot.getPropertyValue(key),
|
|
531
|
+
snapshot.getPropertyPriority(key),
|
|
532
|
+
)
|
|
533
|
+
}
|
|
478
534
|
refresh()
|
|
479
535
|
},
|
|
480
536
|
dispose() {
|
|
481
|
-
if (dead) return
|
|
482
537
|
dead = true
|
|
483
538
|
clearGestures()
|
|
484
539
|
exitHandle?.cancel()
|
|
485
540
|
preference?.removeEventListener(`change`, mediaChanged)
|
|
486
541
|
styles?.()
|
|
542
|
+
const visual = element && visualElementStore.get(element)
|
|
487
543
|
for (const [key, property] of properties) {
|
|
544
|
+
// Projection can retain this renderer after the binding is gone.
|
|
545
|
+
if (visual?.values.get(key) === property.values[0])
|
|
546
|
+
visual.removeValue(key)
|
|
488
547
|
property.release()
|
|
489
548
|
if (!element) target.write!(key, property.base)
|
|
490
549
|
}
|
|
@@ -502,10 +561,89 @@ function attach(
|
|
|
502
561
|
export function motionCapability(
|
|
503
562
|
options: MotionCapabilityOptions = {},
|
|
504
563
|
): Capability {
|
|
564
|
+
const layouts = new WeakMap<Root, ReturnType<typeof createLayoutController>>()
|
|
505
565
|
return {
|
|
506
566
|
namespace: `motion`,
|
|
507
567
|
presence: createPresence,
|
|
508
|
-
|
|
568
|
+
beforeUpdate(root) {
|
|
569
|
+
const layout = layouts.get(root)
|
|
570
|
+
// A layout binding can first appear during the upcoming DOM writes.
|
|
571
|
+
return layout ? layout.beforeUpdate() : () => layouts.get(root)?.commit()
|
|
572
|
+
},
|
|
573
|
+
attach(target, scope) {
|
|
574
|
+
if (target.kind !== `dom` && (!target.read || !target.write))
|
|
575
|
+
throw new Error(
|
|
576
|
+
`spa/motion: renderer ${target.kind} does not support motion`,
|
|
577
|
+
)
|
|
578
|
+
let values: CapabilityBinding | undefined
|
|
579
|
+
let layout: CapabilityBinding | undefined
|
|
580
|
+
let dead = false
|
|
581
|
+
return {
|
|
582
|
+
update(next, previousStyle) {
|
|
583
|
+
if (dead) return
|
|
584
|
+
const animated: Record<string, unknown> = {}
|
|
585
|
+
const projected: Record<string, unknown> = {}
|
|
586
|
+
for (const [key, value] of Object.entries(next)) {
|
|
587
|
+
if (Object.hasOwn(layoutKeys, key))
|
|
588
|
+
projected[layoutKeys[key as keyof typeof layoutKeys]] = value
|
|
589
|
+
else if (allowed.has(key)) animated[key] = value
|
|
590
|
+
else throw new Error(`spa/motion: unknown property motion:${key}`)
|
|
591
|
+
}
|
|
592
|
+
if (Object.keys(projected).length) {
|
|
593
|
+
if (!layout) {
|
|
594
|
+
const element = target.node as HTMLElement
|
|
595
|
+
if (
|
|
596
|
+
target.kind !== `dom` ||
|
|
597
|
+
element?.namespaceURI !== `http://www.w3.org/1999/xhtml` ||
|
|
598
|
+
!scope
|
|
599
|
+
)
|
|
600
|
+
throw new Error(
|
|
601
|
+
`spa/motion: layout requires an owned HTML element`,
|
|
602
|
+
)
|
|
603
|
+
let controller = layouts.get(scope._root)
|
|
604
|
+
if (!controller) {
|
|
605
|
+
controller = createLayoutController(scope._root, options)
|
|
606
|
+
layouts.set(scope._root, controller)
|
|
607
|
+
}
|
|
608
|
+
layout = controller.attach(element, scope)
|
|
609
|
+
}
|
|
610
|
+
layout.update(projected, previousStyle)
|
|
611
|
+
} else {
|
|
612
|
+
layout?.dispose()
|
|
613
|
+
layout = undefined
|
|
614
|
+
}
|
|
615
|
+
if (
|
|
616
|
+
Object.keys(animated).length ||
|
|
617
|
+
(values && !Object.keys(projected).length)
|
|
618
|
+
) {
|
|
619
|
+
values ??= attachValues(target, options)
|
|
620
|
+
values.update(animated, previousStyle)
|
|
621
|
+
} else {
|
|
622
|
+
values?.dispose()
|
|
623
|
+
values = undefined
|
|
624
|
+
}
|
|
625
|
+
},
|
|
626
|
+
exit(next) {
|
|
627
|
+
if (dead) return undefined
|
|
628
|
+
layout?.exit?.(next)
|
|
629
|
+
return values?.exit?.(next)
|
|
630
|
+
},
|
|
631
|
+
resume() {
|
|
632
|
+
if (dead) return
|
|
633
|
+
layout?.resume?.()
|
|
634
|
+
values?.resume?.()
|
|
635
|
+
},
|
|
636
|
+
dispose() {
|
|
637
|
+
if (dead) return
|
|
638
|
+
dead = true
|
|
639
|
+
try {
|
|
640
|
+
values?.dispose()
|
|
641
|
+
} finally {
|
|
642
|
+
layout?.dispose()
|
|
643
|
+
}
|
|
644
|
+
},
|
|
645
|
+
}
|
|
646
|
+
},
|
|
509
647
|
scheduleFrame(callback) {
|
|
510
648
|
const run = ({ timestamp }: { timestamp: number }) => {
|
|
511
649
|
callback(timestamp)
|
package/src/presence.ts
CHANGED
package/src/three-events.ts
CHANGED
|
@@ -268,16 +268,20 @@ export function createThreeEvents(
|
|
|
268
268
|
if (event.type === `pointerup`) {
|
|
269
269
|
const down = pressed.get(event.pointerId)
|
|
270
270
|
pressed.delete(event.pointerId)
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
dispatch(`
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
271
|
+
try {
|
|
272
|
+
// Capture may belong to an ancestor of the original hit.
|
|
273
|
+
if (down && !capture && down.node !== hit?.node)
|
|
274
|
+
dispatch(`pointercancel`, down, event)
|
|
275
|
+
if (delivery) dispatch(`pointerup`, delivery, event)
|
|
276
|
+
if (down && down.node === hit?.node && event.button === 0)
|
|
277
|
+
dispatch(`click`, hit, event)
|
|
278
|
+
} finally {
|
|
279
|
+
captures.delete(event.pointerId)
|
|
280
|
+
nativeCapture(event.pointerId)
|
|
281
|
+
if (event.pointerType === `touch`) {
|
|
282
|
+
hover(event)
|
|
283
|
+
last.delete(event.pointerId)
|
|
284
|
+
}
|
|
281
285
|
}
|
|
282
286
|
} else if (delivery) dispatch(event.type, delivery, event)
|
|
283
287
|
} catch (error) {
|