@rafaelaugusto/jolt 0.1.0-rc.12 → 0.1.0-rc.13
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 +2 -2
- package/dist/core/circle-math.d.ts.map +1 -1
- package/dist/core/easing.d.ts +8 -0
- package/dist/core/easing.d.ts.map +1 -1
- package/dist/core/easing.js +12 -4
- package/dist/core/easing.js.map +1 -1
- package/dist/core/gesture-math.d.ts.map +1 -1
- package/dist/core/gradient-text.d.ts +24 -0
- package/dist/core/gradient-text.d.ts.map +1 -0
- package/dist/core/gradient-text.js +30 -0
- package/dist/core/gradient-text.js.map +1 -0
- package/dist/core/inspection-plot.d.ts +11 -0
- package/dist/core/inspection-plot.d.ts.map +1 -0
- package/dist/core/inspection-plot.js +57 -0
- package/dist/core/inspection-plot.js.map +1 -0
- package/dist/core/motion-behaviors.d.ts +68 -0
- package/dist/core/motion-behaviors.d.ts.map +1 -0
- package/dist/core/motion-behaviors.js +276 -0
- package/dist/core/motion-behaviors.js.map +1 -0
- package/dist/core/numeric-map.js.map +1 -1
- package/dist/core/particle-motion.d.ts +8 -0
- package/dist/core/particle-motion.d.ts.map +1 -0
- package/dist/core/particle-motion.js +11 -0
- package/dist/core/particle-motion.js.map +1 -0
- package/dist/core/pointer.d.ts +1 -1
- package/dist/core/preset-recipe.d.ts +20 -0
- package/dist/core/preset-recipe.d.ts.map +1 -0
- package/dist/core/preset-recipe.js +79 -0
- package/dist/core/preset-recipe.js.map +1 -0
- package/dist/core/reorder.d.ts +5 -0
- package/dist/core/reorder.d.ts.map +1 -1
- package/dist/core/reorder.js +17 -0
- package/dist/core/reorder.js.map +1 -1
- package/dist/core/rig.d.ts +73 -0
- package/dist/core/rig.d.ts.map +1 -0
- package/dist/core/rig.js +99 -0
- package/dist/core/rig.js.map +1 -0
- package/dist/core/scroll-header.js.map +1 -1
- package/dist/core/sensor-kinds.d.ts +1 -1
- package/dist/core/sensor-kinds.d.ts.map +1 -1
- package/dist/core/sensor-replay.d.ts +10 -0
- package/dist/core/sensor-replay.d.ts.map +1 -0
- package/dist/core/sensor-replay.js +32 -0
- package/dist/core/sensor-replay.js.map +1 -0
- package/dist/gradient-text/index.d.ts +2 -10
- package/dist/gradient-text/index.d.ts.map +1 -1
- package/dist/gradient-text/index.js +2 -25
- package/dist/gradient-text/index.js.map +1 -1
- package/dist/gradient-text/native.d.ts +2 -8
- package/dist/gradient-text/native.d.ts.map +1 -1
- package/dist/gradient-text/native.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/inspector/plot.d.ts +1 -3
- package/dist/inspector/plot.d.ts.map +1 -1
- package/dist/inspector/plot.js +1 -22
- package/dist/inspector/plot.js.map +1 -1
- package/dist/motion-behaviors.d.ts +5 -54
- package/dist/motion-behaviors.d.ts.map +1 -1
- package/dist/motion-behaviors.js +18 -267
- package/dist/motion-behaviors.js.map +1 -1
- package/dist/rig/index.d.ts +2 -27
- package/dist/rig/index.d.ts.map +1 -1
- package/dist/rig/index.js +5 -89
- package/dist/rig/index.js.map +1 -1
- package/dist/testing/sensors.d.ts +2 -9
- package/dist/testing/sensors.d.ts.map +1 -1
- package/dist/testing/sensors.js +3 -21
- package/dist/testing/sensors.js.map +1 -1
- package/dist/web/angular/index.d.ts +62 -0
- package/dist/web/angular/index.d.ts.map +1 -0
- package/dist/web/angular/index.js +190 -0
- package/dist/web/angular/index.js.map +1 -0
- package/dist/web/behaviors.d.ts +5 -0
- package/dist/web/behaviors.d.ts.map +1 -0
- package/dist/web/behaviors.js +2 -0
- package/dist/web/behaviors.js.map +1 -0
- package/dist/web/bottom-sheet.js.map +1 -1
- package/dist/web/compose.js.map +1 -1
- package/dist/web/curve.js.map +1 -1
- package/dist/web/decay.js.map +1 -1
- package/dist/web/diagnostics.d.ts +1 -1
- package/dist/web/diagnostics.d.ts.map +1 -1
- package/dist/web/diagnostics.js.map +1 -1
- package/dist/web/drag.d.ts +11 -11
- package/dist/web/drag.d.ts.map +1 -1
- package/dist/web/effect.d.ts +2 -1
- package/dist/web/effect.d.ts.map +1 -1
- package/dist/web/effect.js +11 -4
- package/dist/web/effect.js.map +1 -1
- package/dist/web/frameworks/binding.d.ts +39 -0
- package/dist/web/frameworks/binding.d.ts.map +1 -0
- package/dist/web/frameworks/binding.js +356 -0
- package/dist/web/frameworks/binding.js.map +1 -0
- package/dist/web/gestures.js.map +1 -1
- package/dist/web/gradient-css.d.ts +2 -0
- package/dist/web/gradient-css.d.ts.map +1 -0
- package/dist/web/gradient-css.js +5 -0
- package/dist/web/gradient-css.js.map +1 -0
- package/dist/web/gradient-text.d.ts +24 -0
- package/dist/web/gradient-text.d.ts.map +1 -0
- package/dist/web/gradient-text.js +179 -0
- package/dist/web/gradient-text.js.map +1 -0
- package/dist/web/gradient.d.ts.map +1 -1
- package/dist/web/gradient.js +2 -1
- package/dist/web/gradient.js.map +1 -1
- package/dist/web/image-surface.d.ts.map +1 -1
- package/dist/web/image-surface.js.map +1 -1
- package/dist/web/inspector.d.ts +24 -0
- package/dist/web/inspector.d.ts.map +1 -1
- package/dist/web/inspector.js +76 -5
- package/dist/web/inspector.js.map +1 -1
- package/dist/web/interaction.d.ts +4 -0
- package/dist/web/interaction.d.ts.map +1 -1
- package/dist/web/interaction.js.map +1 -1
- package/dist/web/keyboard.js.map +1 -1
- package/dist/web/layout.d.ts +75 -75
- package/dist/web/layout.d.ts.map +1 -1
- package/dist/web/layout.js.map +1 -1
- package/dist/web/particles.d.ts.map +1 -1
- package/dist/web/particles.js +5 -6
- package/dist/web/particles.js.map +1 -1
- package/dist/web/plan.d.ts +2 -0
- package/dist/web/plan.d.ts.map +1 -1
- package/dist/web/plan.js.map +1 -1
- package/dist/web/press.js.map +1 -1
- package/dist/web/progress.d.ts.map +1 -1
- package/dist/web/properties.d.ts +4 -4
- package/dist/web/properties.d.ts.map +1 -1
- package/dist/web/property.d.ts.map +1 -1
- package/dist/web/property.js.map +1 -1
- package/dist/web/public.d.ts +19 -3
- package/dist/web/public.d.ts.map +1 -1
- package/dist/web/public.js +9 -0
- package/dist/web/public.js.map +1 -1
- package/dist/web/react/index.d.ts +12 -0
- package/dist/web/react/index.d.ts.map +1 -0
- package/dist/web/react/index.js +119 -0
- package/dist/web/react/index.js.map +1 -0
- package/dist/web/reorder.d.ts.map +1 -1
- package/dist/web/reorder.js +23 -2
- package/dist/web/reorder.js.map +1 -1
- package/dist/web/rig.d.ts +43 -0
- package/dist/web/rig.d.ts.map +1 -0
- package/dist/web/rig.js +307 -0
- package/dist/web/rig.js.map +1 -0
- package/dist/web/runtime.d.ts +37 -25
- package/dist/web/runtime.d.ts.map +1 -1
- package/dist/web/runtime.js +111 -8
- package/dist/web/runtime.js.map +1 -1
- package/dist/web/scheduler.d.ts.map +1 -1
- package/dist/web/scheduler.js.map +1 -1
- package/dist/web/scope.d.ts +7 -1
- package/dist/web/scope.d.ts.map +1 -1
- package/dist/web/scope.js +16 -2
- package/dist/web/scope.js.map +1 -1
- package/dist/web/scroll-header.js.map +1 -1
- package/dist/web/scroll-range.d.ts.map +1 -1
- package/dist/web/scroll-range.js.map +1 -1
- package/dist/web/scroll.d.ts +1 -1
- package/dist/web/scroll.d.ts.map +1 -1
- package/dist/web/scroll.js.map +1 -1
- package/dist/web/sensor-replay-bridge.d.ts +16 -0
- package/dist/web/sensor-replay-bridge.d.ts.map +1 -0
- package/dist/web/sensor-replay-bridge.js +12 -0
- package/dist/web/sensor-replay-bridge.js.map +1 -0
- package/dist/web/sensor-replay.d.ts +22 -0
- package/dist/web/sensor-replay.d.ts.map +1 -0
- package/dist/web/sensor-replay.js +124 -0
- package/dist/web/sensor-replay.js.map +1 -0
- package/dist/web/sensors.d.ts +14 -5
- package/dist/web/sensors.d.ts.map +1 -1
- package/dist/web/sensors.js +159 -41
- package/dist/web/sensors.js.map +1 -1
- package/dist/web/shape.d.ts +2 -0
- package/dist/web/shape.d.ts.map +1 -1
- package/dist/web/shape.js +44 -12
- package/dist/web/shape.js.map +1 -1
- package/dist/web/shared-layout.js.map +1 -1
- package/dist/web/size.d.ts.map +1 -1
- package/dist/web/size.js.map +1 -1
- package/dist/web/solid/index.d.ts +16 -0
- package/dist/web/solid/index.d.ts.map +1 -0
- package/dist/web/solid/index.js +89 -0
- package/dist/web/solid/index.js.map +1 -0
- package/dist/web/spring-value.d.ts.map +1 -1
- package/dist/web/spring-value.js.map +1 -1
- package/dist/web/stroke.d.ts.map +1 -1
- package/dist/web/stroke.js.map +1 -1
- package/dist/web/style.d.ts.map +1 -1
- package/dist/web/style.js.map +1 -1
- package/dist/web/surface-effect.d.ts.map +1 -1
- package/dist/web/surface-effect.js.map +1 -1
- package/dist/web/svelte/index.d.ts +50 -0
- package/dist/web/svelte/index.d.ts.map +1 -0
- package/dist/web/svelte/index.js +68 -0
- package/dist/web/svelte/index.js.map +1 -0
- package/dist/web/testing.d.ts +1 -0
- package/dist/web/testing.d.ts.map +1 -1
- package/dist/web/testing.js +1 -0
- package/dist/web/testing.js.map +1 -1
- package/dist/web/timers.d.ts.map +1 -1
- package/dist/web/timers.js.map +1 -1
- package/dist/web/types.d.ts.map +1 -1
- package/dist/web/value-playback.d.ts +17 -17
- package/dist/web/value-playback.js.map +1 -1
- package/dist/web/value.d.ts.map +1 -1
- package/dist/web/value.js.map +1 -1
- package/dist/web/viewport.js.map +1 -1
- package/dist/web/vue/index.d.ts +12 -3
- package/dist/web/vue/index.d.ts.map +1 -1
- package/dist/web/vue/index.js +115 -35
- package/dist/web/vue/index.js.map +1 -1
- package/package.json +35 -6
- package/src/core/easing.ts +12 -4
- package/src/core/gradient-text.ts +56 -0
- package/src/core/inspection-plot.ts +74 -0
- package/src/core/motion-behaviors.ts +337 -0
- package/src/core/particle-motion.ts +20 -0
- package/src/core/preset-recipe.ts +111 -0
- package/src/core/reorder.ts +23 -0
- package/src/core/rig.ts +149 -0
- package/src/core/sensor-replay.ts +48 -0
- package/src/gradient-text/index.ts +7 -43
- package/src/gradient-text/native.ts +2 -7
- package/src/index.ts +6 -0
- package/src/inspector/plot.ts +1 -27
- package/src/motion-behaviors.ts +34 -316
- package/src/rig/index.ts +25 -124
- package/src/testing/sensors.ts +4 -36
- package/src/web/angular/index.ts +171 -0
- package/src/web/behaviors.ts +12 -0
- package/src/web/effect.ts +10 -5
- package/src/web/frameworks/binding.ts +408 -0
- package/src/web/gradient-css.ts +8 -0
- package/src/web/gradient-text.ts +234 -0
- package/src/web/gradient.ts +2 -1
- package/src/web/inspector.ts +80 -5
- package/src/web/interaction.ts +4 -0
- package/src/web/particles.ts +15 -9
- package/src/web/plan.ts +2 -0
- package/src/web/public.ts +51 -4
- package/src/web/react/index.ts +208 -0
- package/src/web/reorder.ts +21 -3
- package/src/web/rig.ts +377 -0
- package/src/web/runtime.ts +128 -11
- package/src/web/scope.ts +32 -4
- package/src/web/sensor-replay-bridge.ts +23 -0
- package/src/web/sensor-replay.ts +140 -0
- package/src/web/sensors.ts +179 -57
- package/src/web/shape.ts +42 -9
- package/src/web/solid/index.ts +102 -0
- package/src/web/svelte/index.ts +88 -0
- package/src/web/testing.ts +6 -0
- package/src/web/vue/index.ts +122 -31
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { useCallback, useEffect, useRef, useState, type RefObject } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
animateBinding,
|
|
5
|
+
presenceBinding,
|
|
6
|
+
type PresenceOptions,
|
|
7
|
+
motionBinding,
|
|
8
|
+
type MotionSetup,
|
|
9
|
+
pressBinding,
|
|
10
|
+
type AnimateValue,
|
|
11
|
+
type PressValue,
|
|
12
|
+
type BindingOptions,
|
|
13
|
+
} from '../frameworks/binding.js'
|
|
14
|
+
export type {
|
|
15
|
+
AnimateValue,
|
|
16
|
+
PressValue,
|
|
17
|
+
BindingOptions,
|
|
18
|
+
MotionSetup,
|
|
19
|
+
} from '../frameworks/binding.js'
|
|
20
|
+
|
|
21
|
+
/** DOM work starts after commit. React SSR never reads a ref or creates a runtime. */
|
|
22
|
+
export function useAnimate<T extends HTMLElement>(
|
|
23
|
+
ref: RefObject<T | null>,
|
|
24
|
+
value?: AnimateValue,
|
|
25
|
+
options: BindingOptions = {},
|
|
26
|
+
) {
|
|
27
|
+
const state = useRef<
|
|
28
|
+
| {
|
|
29
|
+
node: T
|
|
30
|
+
runtime: BindingOptions['runtime']
|
|
31
|
+
binding: ReturnType<typeof animateBinding>
|
|
32
|
+
}
|
|
33
|
+
| undefined
|
|
34
|
+
>(undefined)
|
|
35
|
+
const ensure = useCallback(() => {
|
|
36
|
+
const node = ref.current
|
|
37
|
+
const old = state.current
|
|
38
|
+
if (
|
|
39
|
+
old &&
|
|
40
|
+
(old.node !== node || old.runtime !== options.runtime || old.binding.disposed)
|
|
41
|
+
) {
|
|
42
|
+
old.binding.destroy()
|
|
43
|
+
state.current = undefined
|
|
44
|
+
}
|
|
45
|
+
if (node && !state.current)
|
|
46
|
+
state.current = {
|
|
47
|
+
node,
|
|
48
|
+
runtime: options.runtime,
|
|
49
|
+
binding: animateBinding(node, undefined, options),
|
|
50
|
+
}
|
|
51
|
+
return state.current?.binding
|
|
52
|
+
}, [ref, options.runtime])
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
ensure()?.update(value)
|
|
55
|
+
})
|
|
56
|
+
useEffect(
|
|
57
|
+
() => () => {
|
|
58
|
+
state.current?.binding.destroy()
|
|
59
|
+
state.current = undefined
|
|
60
|
+
},
|
|
61
|
+
[],
|
|
62
|
+
)
|
|
63
|
+
return useCallback(
|
|
64
|
+
(animation: AnimateValue) => {
|
|
65
|
+
const binding = state.current?.binding
|
|
66
|
+
if (!binding || state.current?.node !== ref.current || binding.disposed)
|
|
67
|
+
throw new Error('useAnimate requires a committed DOM ref.')
|
|
68
|
+
return binding.update(animation, true)
|
|
69
|
+
},
|
|
70
|
+
[ref],
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function usePress<T extends HTMLElement>(
|
|
75
|
+
ref: RefObject<T | null>,
|
|
76
|
+
value?: PressValue,
|
|
77
|
+
options: BindingOptions = {},
|
|
78
|
+
) {
|
|
79
|
+
const state = useRef<
|
|
80
|
+
| {
|
|
81
|
+
node: T
|
|
82
|
+
runtime: BindingOptions['runtime']
|
|
83
|
+
binding: ReturnType<typeof pressBinding>
|
|
84
|
+
}
|
|
85
|
+
| undefined
|
|
86
|
+
>(undefined)
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
const node = ref.current,
|
|
89
|
+
old = state.current
|
|
90
|
+
if (
|
|
91
|
+
old &&
|
|
92
|
+
(old.node !== node || old.runtime !== options.runtime || old.binding.disposed)
|
|
93
|
+
) {
|
|
94
|
+
old.binding.destroy()
|
|
95
|
+
state.current = undefined
|
|
96
|
+
}
|
|
97
|
+
if (node && !state.current)
|
|
98
|
+
state.current = {
|
|
99
|
+
node,
|
|
100
|
+
runtime: options.runtime,
|
|
101
|
+
binding: pressBinding(node, value, options),
|
|
102
|
+
}
|
|
103
|
+
else state.current?.binding.update(value)
|
|
104
|
+
})
|
|
105
|
+
useEffect(
|
|
106
|
+
() => () => {
|
|
107
|
+
state.current?.binding.destroy()
|
|
108
|
+
state.current = undefined
|
|
109
|
+
},
|
|
110
|
+
[],
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Own runtime resources for this committed DOM ref. Memoize setup to preserve the resource graph. */
|
|
115
|
+
export function useMotion<T extends HTMLElement>(
|
|
116
|
+
ref: RefObject<T | null>,
|
|
117
|
+
setup: MotionSetup,
|
|
118
|
+
options: BindingOptions = {},
|
|
119
|
+
) {
|
|
120
|
+
const state = useRef<
|
|
121
|
+
| {
|
|
122
|
+
node: T
|
|
123
|
+
runtime: BindingOptions['runtime']
|
|
124
|
+
binding: ReturnType<typeof motionBinding>
|
|
125
|
+
}
|
|
126
|
+
| undefined
|
|
127
|
+
>(undefined)
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
const node = ref.current,
|
|
130
|
+
old = state.current
|
|
131
|
+
if (
|
|
132
|
+
old &&
|
|
133
|
+
(old.node !== node || old.runtime !== options.runtime || old.binding.disposed)
|
|
134
|
+
) {
|
|
135
|
+
old.binding.destroy()
|
|
136
|
+
state.current = undefined
|
|
137
|
+
}
|
|
138
|
+
if (node && !state.current)
|
|
139
|
+
state.current = {
|
|
140
|
+
node,
|
|
141
|
+
runtime: options.runtime,
|
|
142
|
+
binding: motionBinding(node, setup, options),
|
|
143
|
+
}
|
|
144
|
+
else state.current?.binding.update(setup)
|
|
145
|
+
})
|
|
146
|
+
useEffect(
|
|
147
|
+
() => () => {
|
|
148
|
+
state.current?.binding.destroy()
|
|
149
|
+
state.current = undefined
|
|
150
|
+
},
|
|
151
|
+
[],
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export type { PresenceOptions } from '../frameworks/binding.js'
|
|
156
|
+
/** Render while the returned boolean is true; retain the same ref/key through an interrupted exit. */
|
|
157
|
+
export function usePresence<T extends HTMLElement>(
|
|
158
|
+
ref: RefObject<T | null>,
|
|
159
|
+
present: boolean,
|
|
160
|
+
options: PresenceOptions = {},
|
|
161
|
+
) {
|
|
162
|
+
const [retained, retain] = useState(present)
|
|
163
|
+
const latest = useRef(present)
|
|
164
|
+
const state = useRef<
|
|
165
|
+
| {
|
|
166
|
+
node: T
|
|
167
|
+
runtime: BindingOptions['runtime']
|
|
168
|
+
binding: ReturnType<typeof presenceBinding>
|
|
169
|
+
}
|
|
170
|
+
| undefined
|
|
171
|
+
>(undefined)
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
latest.current = present
|
|
174
|
+
if (present) retain(true)
|
|
175
|
+
const node = ref.current,
|
|
176
|
+
old = state.current
|
|
177
|
+
if (
|
|
178
|
+
old &&
|
|
179
|
+
(old.node !== node || old.runtime !== options.runtime || old.binding.disposed)
|
|
180
|
+
) {
|
|
181
|
+
old.binding.destroy()
|
|
182
|
+
state.current = undefined
|
|
183
|
+
}
|
|
184
|
+
if (node && !state.current)
|
|
185
|
+
state.current = {
|
|
186
|
+
node,
|
|
187
|
+
runtime: options.runtime,
|
|
188
|
+
binding: presenceBinding(
|
|
189
|
+
node,
|
|
190
|
+
present,
|
|
191
|
+
() => {
|
|
192
|
+
if (!latest.current) retain(false)
|
|
193
|
+
},
|
|
194
|
+
options,
|
|
195
|
+
),
|
|
196
|
+
}
|
|
197
|
+
else state.current?.binding.update(present, options)
|
|
198
|
+
if (!node && !present) retain(false)
|
|
199
|
+
})
|
|
200
|
+
useEffect(
|
|
201
|
+
() => () => {
|
|
202
|
+
state.current?.binding.destroy()
|
|
203
|
+
state.current = undefined
|
|
204
|
+
},
|
|
205
|
+
[],
|
|
206
|
+
)
|
|
207
|
+
return present || retained
|
|
208
|
+
}
|
package/src/web/reorder.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
itemKeys,
|
|
3
3
|
sameKeys,
|
|
4
4
|
moveAt,
|
|
5
|
+
reorderDestination,
|
|
5
6
|
type ReorderKey,
|
|
6
7
|
type ReorderMove,
|
|
7
8
|
} from '../core/reorder.js'
|
|
@@ -179,6 +180,9 @@ export function createReorder<K extends ReorderKey>(
|
|
|
179
180
|
throw new TypeError('Reorder rows need unique descendant elements.')
|
|
180
181
|
return items
|
|
181
182
|
}
|
|
183
|
+
// A completed FLIP retains row surfaces. Keep their measured geometry current
|
|
184
|
+
// while idle so later text/size changes do not invalidate the next drag.
|
|
185
|
+
const geometry = new Map<HTMLElement, { dispose(): void }>()
|
|
182
186
|
const cleanupPreview = () => {
|
|
183
187
|
const owned = preview,
|
|
184
188
|
restore = restoreDrag
|
|
@@ -296,6 +300,14 @@ export function createReorder<K extends ReorderKey>(
|
|
|
296
300
|
let binding: OwnedBinding
|
|
297
301
|
try {
|
|
298
302
|
binding = host.bindLayer(entry.target, { [axis]: value }, layer)
|
|
303
|
+
try {
|
|
304
|
+
const lease = host.geometry(entry.target)
|
|
305
|
+
geometry.get(entry.target)?.dispose()
|
|
306
|
+
geometry.set(entry.target, lease)
|
|
307
|
+
} catch (error) {
|
|
308
|
+
binding.dispose()
|
|
309
|
+
throw error
|
|
310
|
+
}
|
|
299
311
|
} catch (error) {
|
|
300
312
|
value.dispose()
|
|
301
313
|
throw error
|
|
@@ -387,9 +399,7 @@ export function createReorder<K extends ReorderKey>(
|
|
|
387
399
|
entry = preview[from]!
|
|
388
400
|
entry.value.set(delta)
|
|
389
401
|
const center = entry.start + delta + entry.size / 2
|
|
390
|
-
const index = preview
|
|
391
|
-
(row, i) => i !== from && center > row.start + row.size / 2,
|
|
392
|
-
).length
|
|
402
|
+
const index = reorderDestination(preview, from, center) ?? from
|
|
393
403
|
if (index !== to) {
|
|
394
404
|
reorderPreview(index)
|
|
395
405
|
announce(active, to, 'moved')
|
|
@@ -430,6 +440,12 @@ export function createReorder<K extends ReorderKey>(
|
|
|
430
440
|
}
|
|
431
441
|
})
|
|
432
442
|
for (const row of previous.values()) row.restore()
|
|
443
|
+
const retained = new Set(rows.map((row) => row.target))
|
|
444
|
+
for (const [target, lease] of geometry)
|
|
445
|
+
if (!retained.has(target)) {
|
|
446
|
+
lease.dispose()
|
|
447
|
+
geometry.delete(target)
|
|
448
|
+
}
|
|
433
449
|
observeRows()
|
|
434
450
|
}
|
|
435
451
|
events.on(container, 'pointerdown', (event: PointerEvent) => {
|
|
@@ -699,6 +715,8 @@ export function createReorder<K extends ReorderKey>(
|
|
|
699
715
|
layout = undefined
|
|
700
716
|
events.dispose()
|
|
701
717
|
resize.disconnect()
|
|
718
|
+
for (const lease of geometry.values()) lease.dispose()
|
|
719
|
+
geometry.clear()
|
|
702
720
|
for (const row of rows) row.restore()
|
|
703
721
|
rows = []
|
|
704
722
|
live.remove()
|
package/src/web/rig.ts
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import {
|
|
2
|
+
rigChannels,
|
|
3
|
+
resolveRigDefinition,
|
|
4
|
+
rigDestination,
|
|
5
|
+
type RigChannel,
|
|
6
|
+
type RigDefinition,
|
|
7
|
+
type RigPart,
|
|
8
|
+
type RigSocket,
|
|
9
|
+
type RigTransform,
|
|
10
|
+
} from '../core/rig.js'
|
|
11
|
+
import { EffectStyles, type Realm } from './effect.js'
|
|
12
|
+
import { borderBox } from './style.js'
|
|
13
|
+
import type { WebAnimation } from './public.js'
|
|
14
|
+
import type { WebMotionScope } from './scope.js'
|
|
15
|
+
import type { SpringName, Transition } from './types.js'
|
|
16
|
+
export type { RigDefinition, RigPart, RigSocket, RigTransform } from '../core/rig.js'
|
|
17
|
+
export interface WebRig {
|
|
18
|
+
readonly disposed: boolean
|
|
19
|
+
readonly paused: boolean
|
|
20
|
+
to(pose: string, transition?: Transition | SpringName): WebAnimation
|
|
21
|
+
blend(
|
|
22
|
+
poses: readonly { pose: string; weight: number }[],
|
|
23
|
+
transition?: Transition | SpringName,
|
|
24
|
+
): WebAnimation
|
|
25
|
+
attach(targets: Record<string, HTMLElement | null>): void
|
|
26
|
+
accessory(socket: string, target: HTMLElement | null): void
|
|
27
|
+
/** CSS pixels in the root part's parent's border-box coordinates. */
|
|
28
|
+
point(socket: string): { x: number; y: number }
|
|
29
|
+
refresh(): void
|
|
30
|
+
pause(): void
|
|
31
|
+
play(): void
|
|
32
|
+
stop(): void
|
|
33
|
+
dispose(): void
|
|
34
|
+
}
|
|
35
|
+
export interface RigHost {
|
|
36
|
+
document: Document
|
|
37
|
+
scope(): WebMotionScope
|
|
38
|
+
validate(target: HTMLElement): void
|
|
39
|
+
read(target: HTMLElement, key: RigChannel, model?: boolean): number
|
|
40
|
+
revision(target: HTMLElement, key: RigChannel): symbol | undefined
|
|
41
|
+
set(target: HTMLElement, values: RigTransform): void
|
|
42
|
+
refresh(target: HTMLElement): void
|
|
43
|
+
animate(
|
|
44
|
+
batch: readonly {
|
|
45
|
+
target: HTMLElement
|
|
46
|
+
values: RigTransform
|
|
47
|
+
rotation?: readonly [number, number]
|
|
48
|
+
}[],
|
|
49
|
+
transition: Transition | SpringName,
|
|
50
|
+
): WebAnimation
|
|
51
|
+
forget(): void
|
|
52
|
+
}
|
|
53
|
+
const owners = new WeakMap<HTMLElement, object>()
|
|
54
|
+
export function createRig(
|
|
55
|
+
definition: RigDefinition,
|
|
56
|
+
targets: Record<string, HTMLElement | null>,
|
|
57
|
+
host: RigHost,
|
|
58
|
+
): WebRig {
|
|
59
|
+
const { parts, used, sockets, select } = resolveRigDefinition(definition)
|
|
60
|
+
const view = host.document.defaultView as Realm,
|
|
61
|
+
identity = {}
|
|
62
|
+
const scope = host.scope()
|
|
63
|
+
type Binding = {
|
|
64
|
+
target: HTMLElement
|
|
65
|
+
original: RigTransform
|
|
66
|
+
rest: RigTransform
|
|
67
|
+
tokens: Map<RigChannel, symbol | undefined>
|
|
68
|
+
model: RigTransform
|
|
69
|
+
styles: EffectStyles
|
|
70
|
+
animation?: WebAnimation
|
|
71
|
+
}
|
|
72
|
+
const bound = new Map<string, Binding>(),
|
|
73
|
+
accessories = new Map<string, Binding>()
|
|
74
|
+
let ended = false,
|
|
75
|
+
held = false
|
|
76
|
+
const alive = () => {
|
|
77
|
+
if (ended) throw new Error('Rig is disposed.')
|
|
78
|
+
}
|
|
79
|
+
const geometry = (target: HTMLElement) => {
|
|
80
|
+
if (
|
|
81
|
+
!target.isConnected ||
|
|
82
|
+
target.ownerDocument !== host.document ||
|
|
83
|
+
!target.parentElement
|
|
84
|
+
)
|
|
85
|
+
throw new Error('Rig geometry requires connected parts in their runtime document.')
|
|
86
|
+
const css = view.getComputedStyle(target),
|
|
87
|
+
parent = target.parentElement
|
|
88
|
+
const matrix = new view.DOMMatrixReadOnly(
|
|
89
|
+
css.transform === 'none' ? undefined : css.transform,
|
|
90
|
+
)
|
|
91
|
+
const origin = css.transformOrigin.split(/\s+/).map(Number.parseFloat)
|
|
92
|
+
if (
|
|
93
|
+
!matrix.is2D ||
|
|
94
|
+
(origin[2] ?? 0) !== 0 ||
|
|
95
|
+
css.perspective !== 'none' ||
|
|
96
|
+
[css.translate, css.rotate, css.scale].some((v) => v !== 'none') ||
|
|
97
|
+
!['1', 'normal', ''].includes(css.getPropertyValue('zoom')) ||
|
|
98
|
+
target.offsetParent !== parent ||
|
|
99
|
+
!target.getClientRects().length
|
|
100
|
+
)
|
|
101
|
+
throw new Error(
|
|
102
|
+
'Rig geometry requires 2D boxes with their DOM parent as offsetParent, without CSS zoom or perspective.',
|
|
103
|
+
)
|
|
104
|
+
const size = borderBox(target, css)
|
|
105
|
+
return {
|
|
106
|
+
x: target.offsetLeft + parent.clientLeft - parent.scrollLeft,
|
|
107
|
+
y: target.offsetTop + parent.clientTop - parent.scrollTop,
|
|
108
|
+
width: size.width,
|
|
109
|
+
height: size.height,
|
|
110
|
+
origin: { x: origin[0]!, y: origin[1]! },
|
|
111
|
+
matrix,
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const remember = (binding: Binding, keys: Iterable<RigChannel>) => {
|
|
115
|
+
for (const key of keys) {
|
|
116
|
+
binding.tokens.set(key, host.revision(binding.target, key))
|
|
117
|
+
binding.model[key] = host.read(binding.target, key, true)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const release = (binding: Binding) => {
|
|
121
|
+
const restore: RigTransform = {}
|
|
122
|
+
if (binding.target.isConnected && binding.target.ownerDocument === host.document)
|
|
123
|
+
for (const [key, token] of binding.tokens)
|
|
124
|
+
if (
|
|
125
|
+
host.revision(binding.target, key) === token &&
|
|
126
|
+
host.read(binding.target, key, true) === binding.model[key]
|
|
127
|
+
)
|
|
128
|
+
restore[key] = binding.original[key]
|
|
129
|
+
try {
|
|
130
|
+
binding.animation?.stop()
|
|
131
|
+
if (Object.keys(restore).length) host.set(binding.target, restore)
|
|
132
|
+
} finally {
|
|
133
|
+
resize.unobserve(binding.target)
|
|
134
|
+
binding.styles.restore()
|
|
135
|
+
owners.delete(binding.target)
|
|
136
|
+
if (binding.target.isConnected) host.refresh(binding.target)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const bind = (target: HTMLElement, part: RigPart): Binding => {
|
|
140
|
+
const original = Object.fromEntries(
|
|
141
|
+
rigChannels.map((key) => [key, host.read(target, key, true)]),
|
|
142
|
+
) as RigTransform
|
|
143
|
+
const binding: Binding = {
|
|
144
|
+
target,
|
|
145
|
+
original,
|
|
146
|
+
rest: { ...original, ...part.rest },
|
|
147
|
+
tokens: new Map(),
|
|
148
|
+
model: {},
|
|
149
|
+
styles: new EffectStyles(target),
|
|
150
|
+
}
|
|
151
|
+
owners.set(target, identity)
|
|
152
|
+
try {
|
|
153
|
+
if (part.pivot) {
|
|
154
|
+
binding.styles.set(
|
|
155
|
+
'transform-origin',
|
|
156
|
+
`${part.pivot.x * 100}% ${part.pivot.y * 100}%`,
|
|
157
|
+
)
|
|
158
|
+
host.refresh(target)
|
|
159
|
+
}
|
|
160
|
+
resize.observe(target)
|
|
161
|
+
return binding
|
|
162
|
+
} catch (error) {
|
|
163
|
+
release(binding)
|
|
164
|
+
throw error
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const socket = (name: string) => {
|
|
168
|
+
const data = sockets.get(name)
|
|
169
|
+
if (!data) throw new TypeError(`Unknown rig socket "${name}".`)
|
|
170
|
+
return data
|
|
171
|
+
}
|
|
172
|
+
const localPoint = (data: RigSocket) => {
|
|
173
|
+
const target = bound.get(data.part)?.target
|
|
174
|
+
if (!target) throw new Error('Socket part is detached.')
|
|
175
|
+
const frame = geometry(target)
|
|
176
|
+
return {
|
|
177
|
+
x: data.x * (data.units === 'relative' ? frame.width : 1),
|
|
178
|
+
y: data.y * (data.units === 'relative' ? frame.height : 1),
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const refresh = () => {
|
|
182
|
+
if (ended) return
|
|
183
|
+
for (const [name, binding] of accessories) {
|
|
184
|
+
const data = socket(name),
|
|
185
|
+
parent = bound.get(data.part)?.target
|
|
186
|
+
if (
|
|
187
|
+
!parent ||
|
|
188
|
+
binding.target.parentElement !== parent ||
|
|
189
|
+
!binding.target.isConnected
|
|
190
|
+
)
|
|
191
|
+
continue
|
|
192
|
+
const frame = geometry(binding.target),
|
|
193
|
+
point = localPoint(data)
|
|
194
|
+
const values = {
|
|
195
|
+
x: point.x - frame.x - frame.origin.x,
|
|
196
|
+
y: point.y - frame.y - frame.origin.y,
|
|
197
|
+
}
|
|
198
|
+
if (values.x !== binding.model.x || values.y !== binding.model.y) {
|
|
199
|
+
host.set(binding.target, values)
|
|
200
|
+
remember(binding, ['x', 'y'])
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const resize = new view.ResizeObserver(() => {
|
|
205
|
+
try {
|
|
206
|
+
refresh()
|
|
207
|
+
} catch (error) {
|
|
208
|
+
view.reportError(error)
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
const rig: WebRig = {
|
|
212
|
+
get disposed() {
|
|
213
|
+
return ended
|
|
214
|
+
},
|
|
215
|
+
get paused() {
|
|
216
|
+
return held
|
|
217
|
+
},
|
|
218
|
+
to: (pose, transition) => rig.blend([{ pose, weight: 1 }], transition),
|
|
219
|
+
blend(layers, transition = 'smooth') {
|
|
220
|
+
alive()
|
|
221
|
+
if (held) throw new Error('Resume the rig before starting a pose.')
|
|
222
|
+
const selected = select(layers)
|
|
223
|
+
const batch = [...bound]
|
|
224
|
+
.map(([name, binding]) => {
|
|
225
|
+
geometry(binding.target)
|
|
226
|
+
const part = parts.get(name)!,
|
|
227
|
+
values: RigTransform = {}
|
|
228
|
+
for (const key of used.get(name)!)
|
|
229
|
+
values[key] = rigDestination(
|
|
230
|
+
part,
|
|
231
|
+
name,
|
|
232
|
+
key,
|
|
233
|
+
binding.rest[key]!,
|
|
234
|
+
host.read(binding.target, key),
|
|
235
|
+
selected,
|
|
236
|
+
)
|
|
237
|
+
return { target: binding.target, values, rotation: part.rotation }
|
|
238
|
+
})
|
|
239
|
+
.filter((item) => Object.keys(item.values).length > 0)
|
|
240
|
+
const animation = scope.add(host.animate(batch, transition))
|
|
241
|
+
for (const [name, binding] of bound) {
|
|
242
|
+
binding.animation = animation
|
|
243
|
+
remember(binding, used.get(name)!)
|
|
244
|
+
}
|
|
245
|
+
return animation
|
|
246
|
+
},
|
|
247
|
+
attach(replacements) {
|
|
248
|
+
alive()
|
|
249
|
+
const next = new Map([...bound].map(([name, binding]) => [name, binding.target]))
|
|
250
|
+
for (const [name, target] of Object.entries(replacements)) {
|
|
251
|
+
if (!parts.has(name)) throw new TypeError(`Unknown rig part "${name}".`)
|
|
252
|
+
if (target) next.set(name, target)
|
|
253
|
+
else next.delete(name)
|
|
254
|
+
}
|
|
255
|
+
if (new Set(next.values()).size !== next.size)
|
|
256
|
+
throw new Error('Rig parts must use distinct elements.')
|
|
257
|
+
for (const [name, target] of next) {
|
|
258
|
+
const owner = owners.get(target)
|
|
259
|
+
if (owner && (owner !== identity || bound.get(name)?.target !== target))
|
|
260
|
+
throw new Error('Rig target already has an owner.')
|
|
261
|
+
host.validate(target)
|
|
262
|
+
geometry(target)
|
|
263
|
+
const parent = parts.get(name)!.parent
|
|
264
|
+
if (parent && next.has(parent) && target.parentElement !== next.get(parent))
|
|
265
|
+
throw new Error('Rig parts must follow their declared DOM hierarchy.')
|
|
266
|
+
}
|
|
267
|
+
for (const [name, target] of Object.entries(replacements)) {
|
|
268
|
+
const old = bound.get(name)
|
|
269
|
+
if (old?.target === target) continue
|
|
270
|
+
for (const [key, data] of sockets)
|
|
271
|
+
if (data.part === name) rig.accessory(key, null)
|
|
272
|
+
if (old) {
|
|
273
|
+
bound.delete(name)
|
|
274
|
+
release(old)
|
|
275
|
+
}
|
|
276
|
+
if (!target) continue
|
|
277
|
+
const part = parts.get(name)!,
|
|
278
|
+
binding = bind(target, part)
|
|
279
|
+
bound.set(name, binding)
|
|
280
|
+
if (Object.keys(part.rest).length) {
|
|
281
|
+
host.set(target, part.rest)
|
|
282
|
+
remember(binding, Object.keys(part.rest) as RigChannel[])
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
refresh()
|
|
286
|
+
},
|
|
287
|
+
accessory(name, target) {
|
|
288
|
+
alive()
|
|
289
|
+
const data = socket(name),
|
|
290
|
+
old = accessories.get(name)
|
|
291
|
+
if (old?.target === target) return
|
|
292
|
+
if (target) {
|
|
293
|
+
if (owners.has(target) || target.parentElement !== bound.get(data.part)?.target)
|
|
294
|
+
throw new Error(
|
|
295
|
+
'An accessory must be an unowned direct child of its socket part.',
|
|
296
|
+
)
|
|
297
|
+
host.validate(target)
|
|
298
|
+
geometry(target)
|
|
299
|
+
}
|
|
300
|
+
if (old) {
|
|
301
|
+
accessories.delete(name)
|
|
302
|
+
release(old)
|
|
303
|
+
}
|
|
304
|
+
if (target) accessories.set(name, bind(target, {}))
|
|
305
|
+
refresh()
|
|
306
|
+
},
|
|
307
|
+
point(name) {
|
|
308
|
+
alive()
|
|
309
|
+
const data = socket(name)
|
|
310
|
+
let point = localPoint(data),
|
|
311
|
+
part: string | undefined = data.part
|
|
312
|
+
while (part !== undefined) {
|
|
313
|
+
const target = bound.get(part)?.target
|
|
314
|
+
if (!target) throw new Error('Socket ancestry is detached.')
|
|
315
|
+
const frame = geometry(target)
|
|
316
|
+
const transformed = frame.matrix.transformPoint({
|
|
317
|
+
x: point.x - frame.origin.x,
|
|
318
|
+
y: point.y - frame.origin.y,
|
|
319
|
+
})
|
|
320
|
+
point = {
|
|
321
|
+
x: frame.x + frame.origin.x + transformed.x,
|
|
322
|
+
y: frame.y + frame.origin.y + transformed.y,
|
|
323
|
+
}
|
|
324
|
+
part = parts.get(part)!.parent
|
|
325
|
+
}
|
|
326
|
+
return point
|
|
327
|
+
},
|
|
328
|
+
refresh,
|
|
329
|
+
pause() {
|
|
330
|
+
if (!ended) {
|
|
331
|
+
held = true
|
|
332
|
+
scope.suspend()
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
play() {
|
|
336
|
+
if (!ended) {
|
|
337
|
+
held = false
|
|
338
|
+
scope.resume()
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
stop() {
|
|
342
|
+
if (!ended) scope.reset()
|
|
343
|
+
},
|
|
344
|
+
dispose() {
|
|
345
|
+
if (ended) return
|
|
346
|
+
ended = true
|
|
347
|
+
const errors: unknown[] = []
|
|
348
|
+
try {
|
|
349
|
+
for (const binding of [...accessories.values(), ...bound.values()])
|
|
350
|
+
try {
|
|
351
|
+
release(binding)
|
|
352
|
+
} catch (error) {
|
|
353
|
+
errors.push(error)
|
|
354
|
+
}
|
|
355
|
+
} finally {
|
|
356
|
+
accessories.clear()
|
|
357
|
+
bound.clear()
|
|
358
|
+
resize.disconnect()
|
|
359
|
+
try {
|
|
360
|
+
scope.dispose()
|
|
361
|
+
} catch (error) {
|
|
362
|
+
errors.push(error)
|
|
363
|
+
} finally {
|
|
364
|
+
host.forget()
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (errors.length) throw new AggregateError(errors, 'Rig cleanup failed.')
|
|
368
|
+
},
|
|
369
|
+
}
|
|
370
|
+
try {
|
|
371
|
+
rig.attach(targets)
|
|
372
|
+
return rig
|
|
373
|
+
} catch (error) {
|
|
374
|
+
rig.dispose()
|
|
375
|
+
throw error
|
|
376
|
+
}
|
|
377
|
+
}
|