@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.
Files changed (257) hide show
  1. package/README.md +2 -2
  2. package/dist/core/circle-math.d.ts.map +1 -1
  3. package/dist/core/easing.d.ts +8 -0
  4. package/dist/core/easing.d.ts.map +1 -1
  5. package/dist/core/easing.js +12 -4
  6. package/dist/core/easing.js.map +1 -1
  7. package/dist/core/gesture-math.d.ts.map +1 -1
  8. package/dist/core/gradient-text.d.ts +24 -0
  9. package/dist/core/gradient-text.d.ts.map +1 -0
  10. package/dist/core/gradient-text.js +30 -0
  11. package/dist/core/gradient-text.js.map +1 -0
  12. package/dist/core/inspection-plot.d.ts +11 -0
  13. package/dist/core/inspection-plot.d.ts.map +1 -0
  14. package/dist/core/inspection-plot.js +57 -0
  15. package/dist/core/inspection-plot.js.map +1 -0
  16. package/dist/core/motion-behaviors.d.ts +68 -0
  17. package/dist/core/motion-behaviors.d.ts.map +1 -0
  18. package/dist/core/motion-behaviors.js +276 -0
  19. package/dist/core/motion-behaviors.js.map +1 -0
  20. package/dist/core/numeric-map.js.map +1 -1
  21. package/dist/core/particle-motion.d.ts +8 -0
  22. package/dist/core/particle-motion.d.ts.map +1 -0
  23. package/dist/core/particle-motion.js +11 -0
  24. package/dist/core/particle-motion.js.map +1 -0
  25. package/dist/core/pointer.d.ts +1 -1
  26. package/dist/core/preset-recipe.d.ts +20 -0
  27. package/dist/core/preset-recipe.d.ts.map +1 -0
  28. package/dist/core/preset-recipe.js +79 -0
  29. package/dist/core/preset-recipe.js.map +1 -0
  30. package/dist/core/reorder.d.ts +5 -0
  31. package/dist/core/reorder.d.ts.map +1 -1
  32. package/dist/core/reorder.js +17 -0
  33. package/dist/core/reorder.js.map +1 -1
  34. package/dist/core/rig.d.ts +73 -0
  35. package/dist/core/rig.d.ts.map +1 -0
  36. package/dist/core/rig.js +99 -0
  37. package/dist/core/rig.js.map +1 -0
  38. package/dist/core/scroll-header.js.map +1 -1
  39. package/dist/core/sensor-kinds.d.ts +1 -1
  40. package/dist/core/sensor-kinds.d.ts.map +1 -1
  41. package/dist/core/sensor-replay.d.ts +10 -0
  42. package/dist/core/sensor-replay.d.ts.map +1 -0
  43. package/dist/core/sensor-replay.js +32 -0
  44. package/dist/core/sensor-replay.js.map +1 -0
  45. package/dist/gradient-text/index.d.ts +2 -10
  46. package/dist/gradient-text/index.d.ts.map +1 -1
  47. package/dist/gradient-text/index.js +2 -25
  48. package/dist/gradient-text/index.js.map +1 -1
  49. package/dist/gradient-text/native.d.ts +2 -8
  50. package/dist/gradient-text/native.d.ts.map +1 -1
  51. package/dist/gradient-text/native.js.map +1 -1
  52. package/dist/index.d.ts +2 -0
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +1 -0
  55. package/dist/index.js.map +1 -1
  56. package/dist/inspector/plot.d.ts +1 -3
  57. package/dist/inspector/plot.d.ts.map +1 -1
  58. package/dist/inspector/plot.js +1 -22
  59. package/dist/inspector/plot.js.map +1 -1
  60. package/dist/motion-behaviors.d.ts +5 -54
  61. package/dist/motion-behaviors.d.ts.map +1 -1
  62. package/dist/motion-behaviors.js +18 -267
  63. package/dist/motion-behaviors.js.map +1 -1
  64. package/dist/rig/index.d.ts +2 -27
  65. package/dist/rig/index.d.ts.map +1 -1
  66. package/dist/rig/index.js +5 -89
  67. package/dist/rig/index.js.map +1 -1
  68. package/dist/testing/sensors.d.ts +2 -9
  69. package/dist/testing/sensors.d.ts.map +1 -1
  70. package/dist/testing/sensors.js +3 -21
  71. package/dist/testing/sensors.js.map +1 -1
  72. package/dist/web/angular/index.d.ts +62 -0
  73. package/dist/web/angular/index.d.ts.map +1 -0
  74. package/dist/web/angular/index.js +190 -0
  75. package/dist/web/angular/index.js.map +1 -0
  76. package/dist/web/behaviors.d.ts +5 -0
  77. package/dist/web/behaviors.d.ts.map +1 -0
  78. package/dist/web/behaviors.js +2 -0
  79. package/dist/web/behaviors.js.map +1 -0
  80. package/dist/web/bottom-sheet.js.map +1 -1
  81. package/dist/web/compose.js.map +1 -1
  82. package/dist/web/curve.js.map +1 -1
  83. package/dist/web/decay.js.map +1 -1
  84. package/dist/web/diagnostics.d.ts +1 -1
  85. package/dist/web/diagnostics.d.ts.map +1 -1
  86. package/dist/web/diagnostics.js.map +1 -1
  87. package/dist/web/drag.d.ts +11 -11
  88. package/dist/web/drag.d.ts.map +1 -1
  89. package/dist/web/effect.d.ts +2 -1
  90. package/dist/web/effect.d.ts.map +1 -1
  91. package/dist/web/effect.js +11 -4
  92. package/dist/web/effect.js.map +1 -1
  93. package/dist/web/frameworks/binding.d.ts +39 -0
  94. package/dist/web/frameworks/binding.d.ts.map +1 -0
  95. package/dist/web/frameworks/binding.js +356 -0
  96. package/dist/web/frameworks/binding.js.map +1 -0
  97. package/dist/web/gestures.js.map +1 -1
  98. package/dist/web/gradient-css.d.ts +2 -0
  99. package/dist/web/gradient-css.d.ts.map +1 -0
  100. package/dist/web/gradient-css.js +5 -0
  101. package/dist/web/gradient-css.js.map +1 -0
  102. package/dist/web/gradient-text.d.ts +24 -0
  103. package/dist/web/gradient-text.d.ts.map +1 -0
  104. package/dist/web/gradient-text.js +179 -0
  105. package/dist/web/gradient-text.js.map +1 -0
  106. package/dist/web/gradient.d.ts.map +1 -1
  107. package/dist/web/gradient.js +2 -1
  108. package/dist/web/gradient.js.map +1 -1
  109. package/dist/web/image-surface.d.ts.map +1 -1
  110. package/dist/web/image-surface.js.map +1 -1
  111. package/dist/web/inspector.d.ts +24 -0
  112. package/dist/web/inspector.d.ts.map +1 -1
  113. package/dist/web/inspector.js +76 -5
  114. package/dist/web/inspector.js.map +1 -1
  115. package/dist/web/interaction.d.ts +4 -0
  116. package/dist/web/interaction.d.ts.map +1 -1
  117. package/dist/web/interaction.js.map +1 -1
  118. package/dist/web/keyboard.js.map +1 -1
  119. package/dist/web/layout.d.ts +75 -75
  120. package/dist/web/layout.d.ts.map +1 -1
  121. package/dist/web/layout.js.map +1 -1
  122. package/dist/web/particles.d.ts.map +1 -1
  123. package/dist/web/particles.js +5 -6
  124. package/dist/web/particles.js.map +1 -1
  125. package/dist/web/plan.d.ts +2 -0
  126. package/dist/web/plan.d.ts.map +1 -1
  127. package/dist/web/plan.js.map +1 -1
  128. package/dist/web/press.js.map +1 -1
  129. package/dist/web/progress.d.ts.map +1 -1
  130. package/dist/web/properties.d.ts +4 -4
  131. package/dist/web/properties.d.ts.map +1 -1
  132. package/dist/web/property.d.ts.map +1 -1
  133. package/dist/web/property.js.map +1 -1
  134. package/dist/web/public.d.ts +19 -3
  135. package/dist/web/public.d.ts.map +1 -1
  136. package/dist/web/public.js +9 -0
  137. package/dist/web/public.js.map +1 -1
  138. package/dist/web/react/index.d.ts +12 -0
  139. package/dist/web/react/index.d.ts.map +1 -0
  140. package/dist/web/react/index.js +119 -0
  141. package/dist/web/react/index.js.map +1 -0
  142. package/dist/web/reorder.d.ts.map +1 -1
  143. package/dist/web/reorder.js +23 -2
  144. package/dist/web/reorder.js.map +1 -1
  145. package/dist/web/rig.d.ts +43 -0
  146. package/dist/web/rig.d.ts.map +1 -0
  147. package/dist/web/rig.js +307 -0
  148. package/dist/web/rig.js.map +1 -0
  149. package/dist/web/runtime.d.ts +37 -25
  150. package/dist/web/runtime.d.ts.map +1 -1
  151. package/dist/web/runtime.js +111 -8
  152. package/dist/web/runtime.js.map +1 -1
  153. package/dist/web/scheduler.d.ts.map +1 -1
  154. package/dist/web/scheduler.js.map +1 -1
  155. package/dist/web/scope.d.ts +7 -1
  156. package/dist/web/scope.d.ts.map +1 -1
  157. package/dist/web/scope.js +16 -2
  158. package/dist/web/scope.js.map +1 -1
  159. package/dist/web/scroll-header.js.map +1 -1
  160. package/dist/web/scroll-range.d.ts.map +1 -1
  161. package/dist/web/scroll-range.js.map +1 -1
  162. package/dist/web/scroll.d.ts +1 -1
  163. package/dist/web/scroll.d.ts.map +1 -1
  164. package/dist/web/scroll.js.map +1 -1
  165. package/dist/web/sensor-replay-bridge.d.ts +16 -0
  166. package/dist/web/sensor-replay-bridge.d.ts.map +1 -0
  167. package/dist/web/sensor-replay-bridge.js +12 -0
  168. package/dist/web/sensor-replay-bridge.js.map +1 -0
  169. package/dist/web/sensor-replay.d.ts +22 -0
  170. package/dist/web/sensor-replay.d.ts.map +1 -0
  171. package/dist/web/sensor-replay.js +124 -0
  172. package/dist/web/sensor-replay.js.map +1 -0
  173. package/dist/web/sensors.d.ts +14 -5
  174. package/dist/web/sensors.d.ts.map +1 -1
  175. package/dist/web/sensors.js +159 -41
  176. package/dist/web/sensors.js.map +1 -1
  177. package/dist/web/shape.d.ts +2 -0
  178. package/dist/web/shape.d.ts.map +1 -1
  179. package/dist/web/shape.js +44 -12
  180. package/dist/web/shape.js.map +1 -1
  181. package/dist/web/shared-layout.js.map +1 -1
  182. package/dist/web/size.d.ts.map +1 -1
  183. package/dist/web/size.js.map +1 -1
  184. package/dist/web/solid/index.d.ts +16 -0
  185. package/dist/web/solid/index.d.ts.map +1 -0
  186. package/dist/web/solid/index.js +89 -0
  187. package/dist/web/solid/index.js.map +1 -0
  188. package/dist/web/spring-value.d.ts.map +1 -1
  189. package/dist/web/spring-value.js.map +1 -1
  190. package/dist/web/stroke.d.ts.map +1 -1
  191. package/dist/web/stroke.js.map +1 -1
  192. package/dist/web/style.d.ts.map +1 -1
  193. package/dist/web/style.js.map +1 -1
  194. package/dist/web/surface-effect.d.ts.map +1 -1
  195. package/dist/web/surface-effect.js.map +1 -1
  196. package/dist/web/svelte/index.d.ts +50 -0
  197. package/dist/web/svelte/index.d.ts.map +1 -0
  198. package/dist/web/svelte/index.js +68 -0
  199. package/dist/web/svelte/index.js.map +1 -0
  200. package/dist/web/testing.d.ts +1 -0
  201. package/dist/web/testing.d.ts.map +1 -1
  202. package/dist/web/testing.js +1 -0
  203. package/dist/web/testing.js.map +1 -1
  204. package/dist/web/timers.d.ts.map +1 -1
  205. package/dist/web/timers.js.map +1 -1
  206. package/dist/web/types.d.ts.map +1 -1
  207. package/dist/web/value-playback.d.ts +17 -17
  208. package/dist/web/value-playback.js.map +1 -1
  209. package/dist/web/value.d.ts.map +1 -1
  210. package/dist/web/value.js.map +1 -1
  211. package/dist/web/viewport.js.map +1 -1
  212. package/dist/web/vue/index.d.ts +12 -3
  213. package/dist/web/vue/index.d.ts.map +1 -1
  214. package/dist/web/vue/index.js +115 -35
  215. package/dist/web/vue/index.js.map +1 -1
  216. package/package.json +35 -6
  217. package/src/core/easing.ts +12 -4
  218. package/src/core/gradient-text.ts +56 -0
  219. package/src/core/inspection-plot.ts +74 -0
  220. package/src/core/motion-behaviors.ts +337 -0
  221. package/src/core/particle-motion.ts +20 -0
  222. package/src/core/preset-recipe.ts +111 -0
  223. package/src/core/reorder.ts +23 -0
  224. package/src/core/rig.ts +149 -0
  225. package/src/core/sensor-replay.ts +48 -0
  226. package/src/gradient-text/index.ts +7 -43
  227. package/src/gradient-text/native.ts +2 -7
  228. package/src/index.ts +6 -0
  229. package/src/inspector/plot.ts +1 -27
  230. package/src/motion-behaviors.ts +34 -316
  231. package/src/rig/index.ts +25 -124
  232. package/src/testing/sensors.ts +4 -36
  233. package/src/web/angular/index.ts +171 -0
  234. package/src/web/behaviors.ts +12 -0
  235. package/src/web/effect.ts +10 -5
  236. package/src/web/frameworks/binding.ts +408 -0
  237. package/src/web/gradient-css.ts +8 -0
  238. package/src/web/gradient-text.ts +234 -0
  239. package/src/web/gradient.ts +2 -1
  240. package/src/web/inspector.ts +80 -5
  241. package/src/web/interaction.ts +4 -0
  242. package/src/web/particles.ts +15 -9
  243. package/src/web/plan.ts +2 -0
  244. package/src/web/public.ts +51 -4
  245. package/src/web/react/index.ts +208 -0
  246. package/src/web/reorder.ts +21 -3
  247. package/src/web/rig.ts +377 -0
  248. package/src/web/runtime.ts +128 -11
  249. package/src/web/scope.ts +32 -4
  250. package/src/web/sensor-replay-bridge.ts +23 -0
  251. package/src/web/sensor-replay.ts +140 -0
  252. package/src/web/sensors.ts +179 -57
  253. package/src/web/shape.ts +42 -9
  254. package/src/web/solid/index.ts +102 -0
  255. package/src/web/svelte/index.ts +88 -0
  256. package/src/web/testing.ts +6 -0
  257. package/src/web/vue/index.ts +122 -31
@@ -0,0 +1,234 @@
1
+ import {
2
+ resolveGradientText,
3
+ type GradientTextDefinition,
4
+ } from '../core/gradient-text.js'
5
+ import { createTrack } from '../core/track.js'
6
+ import { resolveTransition } from '../core/transition.js'
7
+ import {
8
+ EffectAnimation,
9
+ EffectStyles,
10
+ effectOptions,
11
+ effectOwnership,
12
+ effectTarget,
13
+ type EffectHost,
14
+ } from './effect.js'
15
+ import { parseColor } from './style.js'
16
+ import { linearGradientCSS } from './gradient-css.js'
17
+ import type { Transition } from './types.js'
18
+ import type { WebAnimation } from './public.js'
19
+
20
+ export interface WebGradientTextOptions extends GradientTextDefinition<string> {}
21
+ export interface WebGradientText {
22
+ readonly disposed: boolean
23
+ readonly suspended: boolean
24
+ play(transition?: Transition): WebAnimation
25
+ suspend(): void
26
+ resume(): void
27
+ stop(): void
28
+ refresh(): void
29
+ snapshot(): {
30
+ attached: boolean
31
+ playing: boolean
32
+ backend: 'css-text-clip' | 'plain-text'
33
+ }
34
+ dispose(): void
35
+ }
36
+ const owners = new WeakMap<HTMLElement, WebGradientText>()
37
+
38
+ /** Uses the original text node: no bitmap, cloned text, or extra accessible content. */
39
+ export function createGradientText(
40
+ target: HTMLElement,
41
+ options: WebGradientTextOptions,
42
+ host: EffectHost,
43
+ ): WebGradientText {
44
+ const view = effectTarget(target, host)
45
+ if (owners.has(target)) throw new Error('This text target already owns gradient text.')
46
+ effectOptions(options, ['colors', 'stops', 'angle', 'sheen'])
47
+ if (options.sheen) effectOptions(options.sheen, ['color', 'width', 'direction'])
48
+ if (
49
+ target.childElementCount ||
50
+ ['INPUT', 'TEXTAREA', 'SELECT', 'IMG', 'CANVAS'].includes(target.tagName)
51
+ )
52
+ throw new TypeError(
53
+ 'gradientText requires plain text in an HTMLElement without child elements.',
54
+ )
55
+ const { paint: definition, direction } = resolveGradientText(options, (color) => {
56
+ if (typeof color !== 'string')
57
+ throw new TypeError('Web text colors must be CSS strings.')
58
+ return parseColor(host.document, color)
59
+ })
60
+ const base = linearGradientCSS(
61
+ definition.angle + 90,
62
+ definition.colors,
63
+ definition.stops,
64
+ )
65
+ const forced = view.matchMedia('(forced-colors: active)')
66
+ const canClip =
67
+ view.CSS.supports('background-clip', 'text') ||
68
+ view.CSS.supports('-webkit-background-clip', 'text')
69
+ const styles = new EffectStyles(target)
70
+ const off: (() => void)[] = []
71
+ let ended = false,
72
+ held = false,
73
+ restart = false,
74
+ active: EffectAnimation | undefined
75
+ let band: number | undefined
76
+ const supported = () => canClip && !forced.matches
77
+ const valid = () =>
78
+ target.isConnected &&
79
+ target.ownerDocument === host.document &&
80
+ target.childElementCount === 0
81
+ const paint = () => {
82
+ if (ended) return
83
+ if (!styles.owns()) {
84
+ dispose()
85
+ throw new Error('Application replaced text gradient styles.')
86
+ }
87
+ if (!supported()) {
88
+ styles.restore()
89
+ return
90
+ }
91
+ let image = base
92
+ if (band !== undefined) {
93
+ const center = -definition.width + band * (1 + 2 * definition.width)
94
+ image = `${linearGradientCSS(90, [definition.sheen & 0xffffff, definition.sheen, definition.sheen & 0xffffff], [center - definition.width / 2, center, center + definition.width / 2])},${base}`
95
+ }
96
+ styles.set('background-image', image)
97
+ styles.set('background-clip', 'text')
98
+ styles.set('-webkit-background-clip', 'text')
99
+ styles.set('background-repeat', 'no-repeat')
100
+ styles.set('color', 'transparent')
101
+ styles.set('-webkit-text-fill-color', 'transparent')
102
+ }
103
+ const stop = () => {
104
+ const previous = active
105
+ active = undefined
106
+ previous?.stop()
107
+ restart = false
108
+ band = undefined
109
+ paint()
110
+ }
111
+ function dispose() {
112
+ if (ended) return
113
+ // Mark before stopping: rendering cancellation cannot rewrite external styles.
114
+ ended = true
115
+ active?.stop()
116
+ active = undefined
117
+ for (const release of off.splice(0).reverse()) release()
118
+ styles.restore()
119
+ owners.delete(target)
120
+ }
121
+ const refresh = () => {
122
+ if (ended) return
123
+ if (!valid() || !styles.owns()) {
124
+ dispose()
125
+ return
126
+ }
127
+ if (!supported()) stop()
128
+ paint()
129
+ }
130
+ const handle: WebGradientText = {
131
+ get disposed() {
132
+ return ended
133
+ },
134
+ get suspended() {
135
+ return held
136
+ },
137
+ play(transition = { duration: 1200, ease: 'linear' }) {
138
+ if (ended) throw new Error('Gradient text is disposed.')
139
+ if (!valid() || !styles.owns()) {
140
+ dispose()
141
+ throw new Error('Gradient text target is detached or replaced.')
142
+ }
143
+ const track = createTrack(
144
+ 'x',
145
+ direction === 'left' ? [1, 0] : [0, 1],
146
+ resolveTransition(transition, 'x', 2),
147
+ 0,
148
+ host.settings(),
149
+ )
150
+ stop()
151
+ const duration = supported() ? track.end : 0
152
+ const terminal = Number.isFinite(duration) ? duration : track.delay + track.duration
153
+ let animation: EffectAnimation | undefined
154
+ animation = new EffectAnimation(
155
+ host,
156
+ duration,
157
+ [],
158
+ (time) => {
159
+ band = track.valueAt(time)
160
+ paint()
161
+ },
162
+ () => {
163
+ band = undefined
164
+ paint()
165
+ if (active === animation) active = undefined
166
+ },
167
+ terminal,
168
+ )
169
+ active = animation
170
+ if (held) {
171
+ animation.pause()
172
+ restart = true
173
+ }
174
+ return animation
175
+ },
176
+ suspend() {
177
+ if (!ended && !held) {
178
+ held = true
179
+ restart = !!active && !active.paused
180
+ active?.pause()
181
+ }
182
+ },
183
+ resume() {
184
+ if (!ended && held) {
185
+ held = false
186
+ if (restart) active?.play()
187
+ restart = false
188
+ }
189
+ },
190
+ stop,
191
+ refresh,
192
+ snapshot: () => ({
193
+ attached: !ended && valid(),
194
+ playing: !!active && !active.paused && !ended,
195
+ backend: supported() ? 'css-text-clip' : 'plain-text',
196
+ }),
197
+ dispose,
198
+ }
199
+ try {
200
+ off.push(effectOwnership(target, 'gradient', host, dispose))
201
+ owners.set(target, handle)
202
+ paint()
203
+ const changed = () => refresh()
204
+ forced.addEventListener('change', changed)
205
+ off.push(() => forced.removeEventListener('change', changed))
206
+ off.push(
207
+ host.onReduced(() => {
208
+ if (host.reduced()) stop()
209
+ }),
210
+ )
211
+ off.push(
212
+ host.register(
213
+ target,
214
+ {
215
+ get disposed() {
216
+ return ended
217
+ },
218
+ get paused() {
219
+ return held
220
+ },
221
+ pause: handle.suspend,
222
+ play: handle.resume,
223
+ cancel: stop,
224
+ dispose,
225
+ },
226
+ refresh,
227
+ ),
228
+ )
229
+ return handle
230
+ } catch (error) {
231
+ dispose()
232
+ throw error
233
+ }
234
+ }
@@ -19,6 +19,7 @@ import {
19
19
  } from './effect.js'
20
20
  import { valuePlan, valueTrack } from './value-playback.js'
21
21
  import { colorCSS } from './properties.js'
22
+ import { linearGradientCSS } from './gradient-css.js'
22
23
  import { parseColor } from './style.js'
23
24
  import type { NumericValue, WebReadableValue, WebColorValue } from './value.js'
24
25
  import type { WebAnimation } from './public.js'
@@ -252,7 +253,7 @@ class Gradient implements WebGradient {
252
253
  const center = `${frame.x * 100}% ${frame.y * 100}%`
253
254
  const image =
254
255
  this.type === 'linear'
255
- ? `linear-gradient(${frame.angle}deg,${stops})`
256
+ ? linearGradientCSS(frame.angle, frame.colors, frame.stops)
256
257
  : this.type === 'conic'
257
258
  ? `conic-gradient(from ${frame.angle}deg at ${center},${stops})`
258
259
  : `radial-gradient(circle ${Math.max(0.001, Math.min(this.target.clientWidth, this.target.clientHeight) * frame.radius)}px at ${center},${stops})`
@@ -2,6 +2,14 @@ import { createAdapterInspector } from '../core/adapter-inspection.js'
2
2
  import { playbackSource, type PlaybackAnimation } from '../core/playback.js'
3
3
  import { inspectorSpring, type InspectorSpring } from '../core/inspector-spring.js'
4
4
  import type { WebRuntime, WebDiagnostics } from './public.js'
5
+ import {
6
+ inspectorPlot,
7
+ validatePlotSample,
8
+ type PlotSample,
9
+ type PlotEvent,
10
+ } from '../core/inspection-plot.js'
11
+ export { inspectorPlot } from '../core/inspection-plot.js'
12
+ export type { PlotSample, PlotEvent } from '../core/inspection-plot.js'
5
13
  export { inspectorSpring } from '../core/inspector-spring.js'
6
14
  export type { InspectorSpring } from '../core/inspector-spring.js'
7
15
  export type {
@@ -43,6 +51,12 @@ export function createMotionInspector(
43
51
  runtime.diagnostics({ development: true, maxEvents: options.capacity })
44
52
  const surfaces = new Map<string, WeakRef<HTMLElement>>()
45
53
  const animations = new Map<string, WeakRef<PlaybackAnimation>>()
54
+ const capacity = options.capacity ?? 256
55
+ const history: (PlotSample & {
56
+ id: string
57
+ property: 'x' | 'y' | 'opacity'
58
+ source: 'computed-style' | 'unavailable'
59
+ })[] = []
46
60
  let disposed = false
47
61
  const validID = (id: string) => {
48
62
  if (disposed) throw new Error('Web inspector is disposed.')
@@ -53,21 +67,79 @@ export function createMotionInspector(
53
67
  }
54
68
  return {
55
69
  adapters,
70
+ /** Explicit pull sampling; no timer, animation-frame loop or inferred GPU observation. */
71
+ sample(
72
+ id: string,
73
+ property: 'x' | 'y' | 'opacity',
74
+ expected: number | null,
75
+ event?: PlotEvent,
76
+ ) {
77
+ if (disposed) throw new Error('Web inspector is disposed.')
78
+ if (!surfaces.has(id)) throw new TypeError('Watch a target before sampling.')
79
+ if (!['x', 'y', 'opacity'].includes(property))
80
+ throw new TypeError('Sample x, y or opacity.')
81
+ const at = document.defaultView!.performance.now()
82
+ validatePlotSample({ at, expected, observed: null, event })
83
+ const target = surfaces.get(id)?.deref()
84
+ let observed: number | null = null
85
+ if (target?.isConnected && target.ownerDocument === document) {
86
+ const style = document.defaultView!.getComputedStyle(target)
87
+ if (property === 'opacity') observed = Number(style.opacity)
88
+ else {
89
+ const matrix = new (
90
+ document.defaultView as Window & typeof globalThis
91
+ ).DOMMatrixReadOnly(style.transform === 'none' ? undefined : style.transform)
92
+ if (matrix.is2D) observed = property === 'x' ? matrix.m41 : matrix.m42
93
+ }
94
+ if (!Number.isFinite(observed)) observed = null
95
+ }
96
+ const sample = {
97
+ id,
98
+ property,
99
+ at,
100
+ expected,
101
+ observed,
102
+ source:
103
+ observed === null ? ('unavailable' as const) : ('computed-style' as const),
104
+ ...(event ? { event } : {}),
105
+ }
106
+ history.push(sample)
107
+ if (history.length > capacity) history.shift()
108
+ return { ...sample }
109
+ },
110
+ samples(id: string, property: 'x' | 'y' | 'opacity') {
111
+ if (disposed) throw new Error('Web inspector is disposed.')
112
+ return history
113
+ .filter((s) => s.id === id && s.property === property)
114
+ .map((s) => ({ ...s }))
115
+ },
116
+ plot(id: string, property: 'x' | 'y' | 'opacity') {
117
+ if (disposed) throw new Error('Web inspector is disposed.')
118
+ return inspectorPlot(history.filter((s) => s.id === id && s.property === property))
119
+ },
120
+ clearSamples() {
121
+ if (disposed) throw new Error('Web inspector is disposed.')
122
+ history.length = 0
123
+ },
56
124
  watch(target: HTMLElement, id: string) {
57
125
  validID(id)
58
126
  if (!target?.isConnected || target.ownerDocument !== document)
59
127
  throw new TypeError('Watch a mounted surface in this runtime document.')
60
- surfaces.set(id, new WeakRef(target))
128
+ for (let i = history.length - 1; i >= 0; i--)
129
+ if (history[i]!.id === id) history.splice(i, 1)
130
+ const ref = new WeakRef(target)
131
+ surfaces.set(id, ref)
61
132
  return () => {
62
- surfaces.delete(id)
133
+ if (surfaces.get(id) === ref) surfaces.delete(id)
63
134
  }
64
135
  },
65
136
  track(animation: PlaybackAnimation, id: string) {
66
137
  validID(id)
67
138
  playbackSource(animation)
68
- animations.set(id, new WeakRef(animation))
139
+ const ref = new WeakRef(animation)
140
+ animations.set(id, ref)
69
141
  return () => {
70
- animations.delete(id)
142
+ if (animations.get(id) === ref) animations.delete(id)
71
143
  }
72
144
  },
73
145
  control(id: string, command: 'pause' | 'play' | 'seek' | 'stop', progress?: number) {
@@ -94,6 +166,7 @@ export function createMotionInspector(
94
166
  return settings
95
167
  },
96
168
  read() {
169
+ if (disposed) throw new Error('Web inspector is disposed.')
97
170
  const targets: {
98
171
  id: string
99
172
  target: number
@@ -102,10 +175,11 @@ export function createMotionInspector(
102
175
  }[] = []
103
176
  for (const [id, ref] of surfaces) {
104
177
  const target = ref.deref()
105
- if (!target?.isConnected || target.ownerDocument !== document) {
178
+ if (!target || target.ownerDocument !== document) {
106
179
  surfaces.delete(id)
107
180
  continue
108
181
  }
182
+ if (!target.isConnected) continue
109
183
  const style = document.defaultView!.getComputedStyle(target)
110
184
  targets.push({
111
185
  id,
@@ -155,6 +229,7 @@ export function createMotionInspector(
155
229
  disposed = true
156
230
  surfaces.clear()
157
231
  animations.clear()
232
+ history.length = 0
158
233
  adapters.dispose()
159
234
  if (!options.diagnostics) diagnostics.dispose()
160
235
  },
@@ -7,6 +7,8 @@ export interface OwnedBinding extends WebBinding {
7
7
  owns(): boolean
8
8
  }
9
9
  export interface WebInteraction {
10
+ /** An explicitly retained renderer may pause through temporary DOM removal. */
11
+ retainDetached?(): boolean
10
12
  readonly disposed: boolean
11
13
  readonly paused: boolean
12
14
  pause(): void
@@ -32,6 +34,8 @@ export interface InteractionHost extends Pick<
32
34
  values: import('./value.js').WebBindings,
33
35
  layer: string,
34
36
  ): OwnedBinding
37
+ /** Retain size/origin tracking across idle periods between interactions. */
38
+ geometry(target: HTMLElement): WebBinding
35
39
  layer(name: string): string
36
40
  scheduler: FrameScheduler
37
41
  error(error: unknown): void
@@ -1,3 +1,4 @@
1
+ import { sampleParticle } from '../core/particle-motion.js'
1
2
  import {
2
3
  decorativeLayer,
3
4
  effectOptions,
@@ -292,16 +293,21 @@ function start(
292
293
  })
293
294
  }
294
295
  for (const p of population) {
295
- const age = Math.max(0, time - p.born) / 1000
296
- context.save()
297
- context.translate(
298
- p.x + p.vx * age,
299
- p.y + p.vy * age + (options.gravity * age * age) / 2,
296
+ const sample = sampleParticle(
297
+ p.x,
298
+ p.y,
299
+ p.vx,
300
+ p.vy,
301
+ options.gravity,
302
+ p.spin,
303
+ options.lifetime,
304
+ time - p.born,
305
+ options.fadeOut,
300
306
  )
301
- context.rotate(p.spin * age)
302
- context.globalAlpha = options.fadeOut
303
- ? Math.max(0, 1 - (age * 1000) / options.lifetime)
304
- : 1
307
+ context.save()
308
+ context.translate(sample.x, sample.y)
309
+ context.rotate(sample.rotation)
310
+ context.globalAlpha = sample.opacity
305
311
  context.fillStyle = context.strokeStyle = p.color
306
312
  const size = options.size
307
313
  if (options.shape === 'rectangle')
package/src/web/plan.ts CHANGED
@@ -28,6 +28,8 @@ import {
28
28
  } from './properties.js'
29
29
 
30
30
  export interface Plan {
31
+ /** Internal rig constraint; applied to every sample before WAAPI compilation. */
32
+ range?: readonly [number, number]
31
33
  property: Property
32
34
  path?: MotionPath
33
35
  frames: (Scalar | null)[]
package/src/web/public.ts CHANGED
@@ -1,3 +1,28 @@
1
+ export type { WebRig, RigDefinition, RigPart, RigSocket, RigTransform } from './rig.js'
2
+ export type { WebGradientText, WebGradientTextOptions } from './gradient-text.js'
3
+ import type {
4
+ WebMotionBehavior,
5
+ MotionBehaviorsOptions,
6
+ MotionBehaviors,
7
+ } from './behaviors.js'
8
+ export { cubicBezier } from '../core/easing.js'
9
+ export { origamiSpring, springs } from '../core/transition.js'
10
+ export { presets } from '../core/presets.js'
11
+ export { createPreset } from '../core/preset-recipe.js'
12
+ export type {
13
+ PortablePresetName,
14
+ PresetParameters,
15
+ PresetRecipe,
16
+ } from '../core/preset-recipe.js'
17
+ export type {
18
+ WebBehaviorContext,
19
+ WebMotionBehavior,
20
+ BehaviorRun,
21
+ BehaviorResult,
22
+ BehaviorStatus,
23
+ MotionBehaviorsOptions,
24
+ MotionBehaviors,
25
+ } from './behaviors.js'
1
26
  import type {
2
27
  TimelineCue,
3
28
  TimelineCueOptions,
@@ -35,6 +60,7 @@ export type {
35
60
  WebSensor,
36
61
  WebRotationSensor,
37
62
  WebGravitySensor,
63
+ WebVectorSensor,
38
64
  } from './sensors.js'
39
65
  export type { Haptic, HapticStyle, HapticOptions, WebHapticResult } from './haptics.js'
40
66
  export type {
@@ -288,6 +314,22 @@ export interface WebAnimation extends PlaybackAnimation {
288
314
 
289
315
  /** Experimental DOM context; platform/framework adapters are not public APIs. */
290
316
  export interface WebRuntime {
317
+ rig2d(
318
+ definition: import('./rig.js').RigDefinition,
319
+ targets?: Record<string, HTMLElement | null>,
320
+ ): import('./rig.js').WebRig
321
+ gradientText(
322
+ target: HTMLElement,
323
+ options: import('./gradient-text.js').WebGradientTextOptions,
324
+ ): import('./gradient-text.js').WebGradientText
325
+ /** Effective preference for this document/runtime, including configure overrides. */
326
+ reducedMotion(): boolean
327
+ /** Observe effective changes; read reducedMotion() for the initial value. */
328
+ onReducedMotion(listener: (reduced: boolean) => void): () => void
329
+ motionBehaviors<const D extends Record<string, WebMotionBehavior>>(
330
+ definitions: D,
331
+ options?: MotionBehaviorsOptions<Extract<keyof D, string>>,
332
+ ): MotionBehaviors<Extract<keyof D, string>>
291
333
  interactiveNavigation(
292
334
  target: HTMLElement,
293
335
  options: import('./interactive-navigation.js').WebInteractiveNavigationOptions,
@@ -304,14 +346,14 @@ export interface WebRuntime {
304
346
  kind: 'rotation',
305
347
  options?: import('./sensors.js').WebSensorOptions,
306
348
  ): import('./sensors.js').WebRotationSensor
307
- sensor(
308
- kind: 'gravity',
349
+ sensor<K extends import('../core/sensor-kinds.js').VectorSensorKind>(
350
+ kind: K,
309
351
  options?: import('./sensors.js').WebSensorOptions,
310
- ): import('./sensors.js').WebGravitySensor
352
+ ): import('./sensors.js').WebVectorSensor<K>
311
353
  sensor(
312
354
  kind: import('./sensors.js').WebSensorKind,
313
355
  options?: import('./sensors.js').WebSensorOptions,
314
- ): import('./sensors.js').WebRotationSensor | import('./sensors.js').WebGravitySensor
356
+ ): import('./sensors.js').WebRotationSensor | import('./sensors.js').WebVectorSensor
315
357
 
316
358
  haptic(
317
359
  style: import('./haptics.js').HapticStyle,
@@ -495,9 +537,12 @@ export function createWebRuntime(
495
537
  // Keep diagnostics, ownership internals and driver implementation off the
496
538
  // package API, including at runtime rather than only in the declarations.
497
539
  return {
540
+ reducedMotion: runtime.reducedMotion.bind(runtime),
541
+ onReducedMotion: runtime.onReducedMotion.bind(runtime),
498
542
  interactiveNavigation: runtime.interactiveNavigation.bind(runtime),
499
543
  sharedNavigationEntry: runtime.sharedNavigationEntry.bind(runtime),
500
544
  glass: runtime.glass.bind(runtime),
545
+ motionBehaviors: runtime.motionBehaviors.bind(runtime),
501
546
  sensor: runtime.sensor.bind(runtime) as WebRuntime['sensor'],
502
547
  haptic: runtime.haptic.bind(runtime),
503
548
  onKeyboard: runtime.onKeyboard.bind(runtime),
@@ -515,6 +560,8 @@ export function createWebRuntime(
515
560
  liquid: runtime.liquid.bind(runtime),
516
561
  imageEffect: runtime.imageEffect.bind(runtime),
517
562
  gradient: runtime.gradient.bind(runtime),
563
+ gradientText: runtime.gradientText.bind(runtime),
564
+ rig2d: runtime.rig2d.bind(runtime),
518
565
  reveal: runtime.reveal.bind(runtime),
519
566
  conceal: runtime.conceal.bind(runtime),
520
567
  animateText: runtime.animateText.bind(runtime),