@solidnative-dev/animation 0.0.0-stage → 0.1.0-alpha.0
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/LICENSE +21 -0
- package/README.md +337 -2
- package/dist/index.d.ts +300 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1604 -0
- package/dist/index.js.map +1 -0
- package/dist/native.d.ts +43 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +189 -0
- package/dist/native.js.map +1 -0
- package/dist/react-native.d.ts +21 -0
- package/dist/react-native.d.ts.map +1 -0
- package/dist/react-native.js +353 -0
- package/dist/react-native.js.map +1 -0
- package/dist/solid.d.ts +15 -0
- package/dist/solid.d.ts.map +1 -0
- package/dist/solid.js +60 -0
- package/dist/solid.js.map +1 -0
- package/package.json +52 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Solid Native contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,338 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@solidnative-dev/animation`
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This package defines the portable animation/worklet foundation and its native
|
|
4
|
+
UI-thread executors. The React Native 0.87 Fabric backends decode the same
|
|
5
|
+
bounded graph in C++, evaluate frames from Android `Choreographer` or iOS
|
|
6
|
+
`CADisplayLink`, and apply supported output channels directly to the owned
|
|
7
|
+
platform view.
|
|
8
|
+
|
|
9
|
+
The version-0 protocol represents numeric work as a bounded, transport-safe
|
|
10
|
+
graph rather than an arbitrary JavaScript closure. Inputs have explicit initial
|
|
11
|
+
values; output channels use constants, named inputs, arithmetic, absolute and
|
|
12
|
+
negated values, clamping, and linear interpolation. Parsing clones and deeply
|
|
13
|
+
freezes the graph while rejecting unsupported fields, duplicate or undeclared
|
|
14
|
+
identifiers, non-finite numbers, invalid ranges, more than 64 inputs or outputs,
|
|
15
|
+
more than 32 expression levels, and more than 512 expression nodes.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import {
|
|
19
|
+
createUIWorkletGraph,
|
|
20
|
+
createUIWorkletSession,
|
|
21
|
+
} from "@solidnative-dev/animation";
|
|
22
|
+
|
|
23
|
+
const graph = createUIWorkletGraph(
|
|
24
|
+
{ progress: 0 },
|
|
25
|
+
({ progress }, { interpolate }) => ({
|
|
26
|
+
opacity: interpolate(progress, [0, 1], [0.2, 1]),
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const session = createUIWorkletSession(host, graph);
|
|
31
|
+
session.update({ progress: 0.5 }, performance.now());
|
|
32
|
+
session.animate(
|
|
33
|
+
{ progress: 1 },
|
|
34
|
+
{ durationMilliseconds: 240, easing: "ease-in-out" },
|
|
35
|
+
performance.now(),
|
|
36
|
+
);
|
|
37
|
+
session.dispose();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The authoring callback runs once while the graph is defined; it never runs on
|
|
41
|
+
the UI thread and captures no application state. Its named input expressions
|
|
42
|
+
and `constant`, `add`, `subtract`, `multiply`, `divide`, `min`, `max`, `abs`,
|
|
43
|
+
`negate`, `clamp`, and `interpolate` helpers compile immediately to the same
|
|
44
|
+
bounded transport graph. Numeric outputs and operands are constant shorthand.
|
|
45
|
+
The explicit `protocolVersion`/array/AST form remains accepted for code
|
|
46
|
+
generators, native adapter fixtures, and persisted protocol data.
|
|
47
|
+
|
|
48
|
+
`UIWorkletHost` is the injected execution boundary. Installation receives only
|
|
49
|
+
the frozen graph; updates carry a complete positional input vector and a
|
|
50
|
+
monotonic timestamp; destruction releases the graph handle. Updates must be
|
|
51
|
+
atomic: a rejected input frame cannot partially publish values or output
|
|
52
|
+
channels. `createInMemoryUIWorkletHost` supplies executable reference semantics
|
|
53
|
+
and inspectable snapshots for deterministic tests. It runs in JavaScript and is
|
|
54
|
+
explicitly not evidence of UI-thread performance.
|
|
55
|
+
|
|
56
|
+
`@solidnative-dev/animation/solid` adds the ownership boundary:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { createSignal } from "solid-js";
|
|
60
|
+
import { createSolidUIWorklet } from "@solidnative-dev/animation/solid";
|
|
61
|
+
|
|
62
|
+
const [inputs, setInputs] = createSignal({ progress: 0 });
|
|
63
|
+
const session = createSolidUIWorklet(host, graph, inputs);
|
|
64
|
+
|
|
65
|
+
setInputs({ progress: 1 });
|
|
66
|
+
// The current Solid owner cancels `session` during cleanup.
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
This bridge is for coarse application-state synchronization. Gesture samples
|
|
70
|
+
and frame ticks should originate inside a native host so they do not round-trip
|
|
71
|
+
through the JavaScript thread. The owned helpers require an active Solid owner
|
|
72
|
+
and reject installation before allocating a native graph when none exists.
|
|
73
|
+
An input failure disposes the graph before reporting it, owner cleanup remains
|
|
74
|
+
idempotent even when the native destroy call throws, and synchronous or
|
|
75
|
+
asynchronously rejected diagnostic hooks cannot revive the session or escape as
|
|
76
|
+
background failures.
|
|
77
|
+
Native event handlers intentionally run outside reactive ownership; code that
|
|
78
|
+
installs an owned worklet from one must capture its component owner during
|
|
79
|
+
setup and explicitly re-enter it with Solid's `runWithOwner`.
|
|
80
|
+
|
|
81
|
+
Every session also accepts a pull-based reduced-motion policy. The accessor is
|
|
82
|
+
read when motion is requested, so it can be wired directly to the fine-grained
|
|
83
|
+
preference exposed by `@solidnative-dev/accessibility/solid` without making either
|
|
84
|
+
package depend on the other:
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
import { createNativeViewAnimation } from "@solidnative-dev/animation/native";
|
|
88
|
+
import { createAccessibilityPreferences } from "@solidnative-dev/accessibility/solid";
|
|
89
|
+
|
|
90
|
+
const preferences = createAccessibilityPreferences(accessibilityService, {
|
|
91
|
+
appState: platform,
|
|
92
|
+
});
|
|
93
|
+
const animation = createNativeViewAnimation(graph, {
|
|
94
|
+
reduceMotion: preferences.reduceMotionEnabled,
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
When the accessor returns `true`, timing, keyframe, and spring requests validate
|
|
99
|
+
normally but publish their final target immediately. Explicit decay is
|
|
100
|
+
suppressed at its current input vector, and a newly attached pan gesture keeps
|
|
101
|
+
direct touch tracking while omitting its optional release decay. `undefined`
|
|
102
|
+
is treated as no preference while the initial native query is loading. The
|
|
103
|
+
policy is intentionally pulled for each new request; an application that wants
|
|
104
|
+
to stop motion already in flight when its policy changes can call `cancel()`.
|
|
105
|
+
|
|
106
|
+
Hosts may implement the bounded timing extension used by `session.animate`.
|
|
107
|
+
Version 0 supports `linear`, `ease-in`, `ease-out`, and `ease-in-out` durations
|
|
108
|
+
up to 60 seconds. Solid publishes one complete target vector; the platform
|
|
109
|
+
display callback advances interpolation without JavaScript frame traffic. A
|
|
110
|
+
new immediate update cancels the timing, while a new timing continues from the
|
|
111
|
+
last evaluated native frame. Disposal remains the terminal cancellation
|
|
112
|
+
boundary. The deterministic host exposes `advanceFrame()` for exact reference
|
|
113
|
+
tests.
|
|
114
|
+
|
|
115
|
+
The independent `session.animateKeyframes` extension sends a complete bounded
|
|
116
|
+
timing sequence in one host call:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
session.animateKeyframes(
|
|
120
|
+
[
|
|
121
|
+
{
|
|
122
|
+
inputs: { progress: 0.5, offset: 24 },
|
|
123
|
+
timing: { durationMilliseconds: 120, easing: "ease-out" },
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
inputs: { progress: 1, offset: 0 },
|
|
127
|
+
timing: { durationMilliseconds: 180, easing: "ease-in-out" },
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
performance.now(),
|
|
131
|
+
);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
A sequence contains 1–32 stages and its combined duration cannot exceed 60
|
|
135
|
+
seconds. Named partial targets resolve cumulatively before crossing the host,
|
|
136
|
+
so every transported stage is a complete input vector. The host validates the
|
|
137
|
+
graph result at every stage endpoint before replacing an active driver. Display
|
|
138
|
+
callbacks evaluate elapsed time analytically and skip across completed stages,
|
|
139
|
+
which preserves the intended result when a callback is late and avoids a
|
|
140
|
+
JavaScript wakeup between stages. A replacement timing, keyframe sequence,
|
|
141
|
+
spring, or decay starts from the latest evaluated native vector.
|
|
142
|
+
|
|
143
|
+
After the first successfully evaluated timing frame, inspection includes
|
|
144
|
+
`timingFrameStatistics`. It reports frame and interval counts, first/last
|
|
145
|
+
display timestamps, global minimum/maximum/mean intervals, and nearest-rank
|
|
146
|
+
p50/p95/p99 intervals. Quantiles retain at most 8,192 interval samples; longer
|
|
147
|
+
runs keep exact aggregate counts and extrema while publishing the number of
|
|
148
|
+
samples omitted from quantiles. A new timing or keyframe sequence resets the
|
|
149
|
+
statistics, and an immediate update clears them. Keyframe statistics cover the
|
|
150
|
+
whole sequence. These values measure the platform display callback driving the
|
|
151
|
+
worklet, not compositor presentation.
|
|
152
|
+
|
|
153
|
+
Hosts may independently implement `session.cancel(timestamp)`. Cancellation
|
|
154
|
+
stops any active timing, keyframe sequence, spring, or decay and synchronously
|
|
155
|
+
returns the exact input vector from the last evaluated native frame. The
|
|
156
|
+
session validates that the result is complete and finite before replacing its
|
|
157
|
+
Solid-side mirror, so a later named partial animation resumes from what the user
|
|
158
|
+
actually saw instead of an earlier JavaScript target. A missing capability,
|
|
159
|
+
host exception, malformed vector, or stale timestamp fails closed without
|
|
160
|
+
advancing the mirror or its clock. Cancellation does not publish another frame,
|
|
161
|
+
discard cadence diagnostics, destroy the graph, or detach an owned pan gesture;
|
|
162
|
+
spring velocity and decay speed become zero while their last position/elapsed
|
|
163
|
+
diagnostics remain inspectable.
|
|
164
|
+
|
|
165
|
+
Hosts may independently implement `session.spring`. Its required definition
|
|
166
|
+
contains bounded mass, stiffness, damping, normalized initial velocity, rest
|
|
167
|
+
speed/displacement thresholds, and a hard duration cap:
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
session.spring(
|
|
171
|
+
{ progress: 1 },
|
|
172
|
+
{
|
|
173
|
+
mass: 1,
|
|
174
|
+
stiffness: 100,
|
|
175
|
+
damping: 10,
|
|
176
|
+
initialVelocity: 0,
|
|
177
|
+
restSpeedThreshold: 0.01,
|
|
178
|
+
restDisplacementThreshold: 0.001,
|
|
179
|
+
maximumDurationMilliseconds: 5_000,
|
|
180
|
+
},
|
|
181
|
+
performance.now(),
|
|
182
|
+
);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
The portable reference evaluates the closed-form damped harmonic oscillator,
|
|
186
|
+
including underdamped, critically damped, and overdamped regimes. Position and
|
|
187
|
+
velocity therefore depend on elapsed time rather than display-callback count;
|
|
188
|
+
position may overshoot the target. Velocity uses normalized input-vector
|
|
189
|
+
progress per second, so one spring advances the complete vector atomically.
|
|
190
|
+
Crossing both rest thresholds or the maximum duration snaps to the exact target.
|
|
191
|
+
A replacement driver starts from the latest evaluated host vector, while an
|
|
192
|
+
immediate update cancels the spring.
|
|
193
|
+
|
|
194
|
+
Hosts may independently implement `session.decay` for gesture-release and
|
|
195
|
+
other inertial motion. Velocities are named graph-input units per second;
|
|
196
|
+
unspecified inputs receive zero velocity and the host advances the complete
|
|
197
|
+
vector atomically:
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
session.decay(
|
|
201
|
+
{ offsetX: 1_200, offsetY: -240 },
|
|
202
|
+
{
|
|
203
|
+
deceleration: 2,
|
|
204
|
+
velocityThreshold: 1,
|
|
205
|
+
maximumDurationMilliseconds: 5_000,
|
|
206
|
+
},
|
|
207
|
+
performance.now(),
|
|
208
|
+
);
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
`deceleration` is exponential velocity loss per second. The analytical
|
|
212
|
+
reference derives one terminal time from the maximum absolute input velocity,
|
|
213
|
+
the threshold, and the hard duration cap. Every input therefore stops together
|
|
214
|
+
at a refresh-rate-independent endpoint. Inspection exposes elapsed display
|
|
215
|
+
time, maximum current speed, and bounded frame statistics. A replacement
|
|
216
|
+
driver begins at the latest evaluated host vector; immediate updates, timings,
|
|
217
|
+
springs, pan input, and owner disposal cancel the decay.
|
|
218
|
+
|
|
219
|
+
Hosts may also implement the native pan-input extension. Both axes name
|
|
220
|
+
declared graph inputs and have finite, strictly ascending bounds:
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
session.attachPanGesture({
|
|
224
|
+
xInput: "offsetX",
|
|
225
|
+
yInput: "offsetY",
|
|
226
|
+
minX: -120,
|
|
227
|
+
maxX: 120,
|
|
228
|
+
minY: -80,
|
|
229
|
+
maxY: 80,
|
|
230
|
+
releaseDecay: {
|
|
231
|
+
deceleration: 12,
|
|
232
|
+
velocityThreshold: 5,
|
|
233
|
+
maximumDurationMilliseconds: 1_000,
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Attachment transfers the session's complete input vector to the native host
|
|
239
|
+
until `session.detachPanGesture(timestamp)` succeeds. Each gesture begins from
|
|
240
|
+
the latest graph inputs, applies bounded
|
|
241
|
+
translation to the two selected inputs, evaluates every derived output, and
|
|
242
|
+
publishes the frame atomically. JavaScript `update`, `animate`, `spring`, and
|
|
243
|
+
`decay` calls then fail closed instead of overwriting native-owned state with a
|
|
244
|
+
stale mirror.
|
|
245
|
+
When `releaseDecay` is present, a successful gesture end transfers the native
|
|
246
|
+
recognizer's logical-unit velocity directly into the same analytical decay
|
|
247
|
+
driver. The selected x/y inputs receive velocity in units per second and every
|
|
248
|
+
other graph input receives zero. Pan bounds constrain the direct-touch phase;
|
|
249
|
+
inertial motion may continue beyond them. Before publishing the final pan frame,
|
|
250
|
+
the host validates both that frame and the decay's analytical terminal vector,
|
|
251
|
+
so a graph failure cannot expose a half-completed handoff. Cancellation never
|
|
252
|
+
starts inertia, and a new gesture begin interrupts an active release decay.
|
|
253
|
+
Detachment linearizes with any native sample, stops release decay, removes the
|
|
254
|
+
recognizer/listener, and returns the complete final vector. The session validates
|
|
255
|
+
that vector before clearing `nativeInputsOwned`, so subsequent Solid work resumes
|
|
256
|
+
from visible state; failures leave native ownership intact. Disposal remains the
|
|
257
|
+
terminal graph boundary. The in-memory host's
|
|
258
|
+
`dispatchPanGesture()` supplies deterministic begin/change/end/cancel reference
|
|
259
|
+
semantics, optional release velocities, and a gesture clock independent of
|
|
260
|
+
JavaScript update timestamps.
|
|
261
|
+
|
|
262
|
+
`@solidnative-dev/animation/native` is the application-facing path. It binds one
|
|
263
|
+
graph to a native element, waits for the renderer's platform mount
|
|
264
|
+
acknowledgement, creates the backend host, and owns native teardown with the
|
|
265
|
+
current Solid owner:
|
|
266
|
+
|
|
267
|
+
```tsx
|
|
268
|
+
import { createNativeViewAnimation } from "@solidnative-dev/animation/native";
|
|
269
|
+
|
|
270
|
+
const animation = createNativeViewAnimation(graph, {
|
|
271
|
+
inputs: () => ({ progress: progress() }),
|
|
272
|
+
onError: reportError,
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
return <View ref={animation.ref} />;
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
`animation.ready` resolves to `true` after installation, or `false` if its
|
|
279
|
+
owner ends first. After it resolves, the controller directly exposes `update`,
|
|
280
|
+
`animate`, `animateKeyframes`, `spring`, `decay`, `cancel`,
|
|
281
|
+
`attachPanGesture`, `detachPanGesture`, and `inspect`. An imperative call made
|
|
282
|
+
before readiness fails with a targeted error instead of racing an uncommitted
|
|
283
|
+
Fabric identity. The controller is single-target, cannot be rebound to another
|
|
284
|
+
element, reports asynchronous installation failures through `error`, `ready`,
|
|
285
|
+
and the optional `onError`, and is idempotently disposable.
|
|
286
|
+
|
|
287
|
+
`@solidnative-dev/animation/react-native` remains the lower-level adapter entry
|
|
288
|
+
for integration code that already owns a committed `NativeNode`. Its
|
|
289
|
+
`createNativeViewUIWorkletHost(node)` result can be paired with
|
|
290
|
+
`createSolidUIWorklet(host, graph, inputs)` when an application needs to own
|
|
291
|
+
mount sequencing itself.
|
|
292
|
+
|
|
293
|
+
The Android and iOS adapters accept `opacity`, `translateX`, `translateY`,
|
|
294
|
+
`scaleX`, `scaleY`, and numeric-degree `rotation`. Translation values are
|
|
295
|
+
logical display units: Android converts them to device pixels while UIKit uses
|
|
296
|
+
them as points.
|
|
297
|
+
All candidate input vectors are synchronously validated, then the native graph
|
|
298
|
+
is evaluated again on the UI frame. Outputs are installed together before the
|
|
299
|
+
frame is drawn. Unknown channels, stale/uncommitted node handles, non-finite
|
|
300
|
+
values, non-monotonic timestamps, graph limits, and surface leaks fail closed.
|
|
301
|
+
Deleting the target cancels native execution defensively; ordinary sessions
|
|
302
|
+
are disposed earlier with their Solid owner.
|
|
303
|
+
|
|
304
|
+
Each binding advertises `uiWorklets: true` only when install, update, destroy,
|
|
305
|
+
and inspection methods are all present. The checked-in Pixel and signed iPhone
|
|
306
|
+
Release proofs verify native decoding, platform display-callback/main-thread
|
|
307
|
+
delivery, real mounted Fabric view properties, frame sequence/timestamp
|
|
308
|
+
inspection, a real touchscreen drag delivered through Android's
|
|
309
|
+
`OnTouchListener` or UIKit's `UIPanGestureRecognizer` without a Hermes update
|
|
310
|
+
callback, and terminal owner/surface teardown. The current Pixel proof runs a
|
|
311
|
+
five-second timing gate and validates complete cadence statistics, executes a
|
|
312
|
+
three-leg native keyframe sequence without JavaScript stage handoffs, then
|
|
313
|
+
interrupts one native spring with another, observes underdamped overshoot, and
|
|
314
|
+
requires an exact endpoint with zero terminal velocity. It then interrupts one
|
|
315
|
+
analytical decay with another from the latest native vector, requires the exact
|
|
316
|
+
refresh-rate-independent endpoint and zero terminal speed, and hands that
|
|
317
|
+
endpoint to the real pan recognizer. Android instrumentation independently
|
|
318
|
+
samples the mounted `View` during both spring and decay. A Pixel 9a delivered
|
|
319
|
+
302 frames at 16.653 ms mean and 16.652 ms p50; an iPhone 17 Pro delivered 601
|
|
320
|
+
frames at 8.33478 ms mean and 8.33475 ms p50/p95. Neither run dropped an
|
|
321
|
+
interval sample. The Pixel proof additionally verifies a real drag handing its
|
|
322
|
+
native release velocity to decay and continuing beyond the direct-touch
|
|
323
|
+
endpoint without a Hermes callback. The iOS keyframe and release-handoff paths
|
|
324
|
+
are Release/ARM64 compile-verified and await the next physical-device rerun.
|
|
325
|
+
The Pixel proof also cancels a live timing, requires the mounted output and
|
|
326
|
+
native sequence to remain frozen with no queued frame, synchronizes the session
|
|
327
|
+
mirror, and resumes a named partial timing from that vector. The matching iOS
|
|
328
|
+
cancellation path is Release/ARM64 compile-verified and awaits a physical rerun.
|
|
329
|
+
The Pixel additionally detaches the real pan after inertia, verifies that the
|
|
330
|
+
gesture state disappears without moving the view, and publishes the first
|
|
331
|
+
post-detach Solid frame from the synchronized vector. The matching iOS detach
|
|
332
|
+
path is Release/ARM64 compile-verified pending a physical rerun.
|
|
333
|
+
The application-facing ref path is physically verified on the Pixel, including
|
|
334
|
+
mount sequencing, a named update, output inspection, and graph disposal; the
|
|
335
|
+
same entry and Hermes bundle compile for generic iOS Release/ARM64.
|
|
336
|
+
These are single-device correctness diagnostics, not general performance claims;
|
|
337
|
+
concurrent independently driven values and heterogeneous driver chaining remain
|
|
338
|
+
open.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
export declare const UI_WORKLET_PROTOCOL_VERSION: 0;
|
|
2
|
+
export declare const UI_WORKLET_MAX_INPUTS = 64;
|
|
3
|
+
export declare const UI_WORKLET_MAX_OUTPUTS = 64;
|
|
4
|
+
export declare const UI_WORKLET_MAX_EXPRESSION_DEPTH = 32;
|
|
5
|
+
export declare const UI_WORKLET_MAX_EXPRESSION_NODES = 512;
|
|
6
|
+
export declare const UI_WORKLET_MAX_TIMING_DURATION_MS = 60000;
|
|
7
|
+
export declare const UI_WORKLET_MAX_TIMING_KEYFRAMES = 32;
|
|
8
|
+
export declare const UI_WORKLET_MAX_FRAME_INTERVAL_SAMPLES = 8192;
|
|
9
|
+
export declare const UI_WORKLET_MIN_SPRING_MASS = 0.001;
|
|
10
|
+
export declare const UI_WORKLET_MAX_SPRING_MASS = 100;
|
|
11
|
+
export declare const UI_WORKLET_MIN_SPRING_STIFFNESS = 0.001;
|
|
12
|
+
export declare const UI_WORKLET_MAX_SPRING_STIFFNESS = 100000;
|
|
13
|
+
export declare const UI_WORKLET_MAX_SPRING_DAMPING = 10000;
|
|
14
|
+
export declare const UI_WORKLET_MAX_SPRING_INITIAL_VELOCITY = 100;
|
|
15
|
+
export declare const UI_WORKLET_MAX_SPRING_REST_SPEED = 100;
|
|
16
|
+
export declare const UI_WORKLET_MAX_SPRING_DURATION_MS = 60000;
|
|
17
|
+
export declare const UI_WORKLET_MIN_DECAY_DECELERATION = 0.001;
|
|
18
|
+
export declare const UI_WORKLET_MAX_DECAY_DECELERATION = 1000;
|
|
19
|
+
export declare const UI_WORKLET_MAX_DECAY_VELOCITY = 100000;
|
|
20
|
+
export declare const UI_WORKLET_MAX_DECAY_VELOCITY_THRESHOLD = 10000;
|
|
21
|
+
export declare const UI_WORKLET_MAX_DECAY_DURATION_MS = 60000;
|
|
22
|
+
export type UIWorkletTimingEasing = "linear" | "ease-in" | "ease-out" | "ease-in-out";
|
|
23
|
+
export interface UIWorkletTiming {
|
|
24
|
+
readonly durationMilliseconds: number;
|
|
25
|
+
readonly easing: UIWorkletTimingEasing;
|
|
26
|
+
}
|
|
27
|
+
/** One complete positional target in a host-level native timing sequence. */
|
|
28
|
+
export interface UIWorkletTimingKeyframe {
|
|
29
|
+
readonly inputs: readonly number[];
|
|
30
|
+
readonly timing: UIWorkletTiming;
|
|
31
|
+
}
|
|
32
|
+
/** One named partial target accepted by a UIWorkletSession. */
|
|
33
|
+
export interface UIWorkletNamedTimingKeyframe {
|
|
34
|
+
readonly inputs: Readonly<Record<string, number>>;
|
|
35
|
+
readonly timing: UIWorkletTiming;
|
|
36
|
+
}
|
|
37
|
+
export interface UIWorkletSpring {
|
|
38
|
+
readonly mass: number;
|
|
39
|
+
readonly stiffness: number;
|
|
40
|
+
readonly damping: number;
|
|
41
|
+
/** Normalized input-vector progress per second. */
|
|
42
|
+
readonly initialVelocity: number;
|
|
43
|
+
/** Normalized input-vector progress per second. */
|
|
44
|
+
readonly restSpeedThreshold: number;
|
|
45
|
+
readonly restDisplacementThreshold: number;
|
|
46
|
+
readonly maximumDurationMilliseconds: number;
|
|
47
|
+
}
|
|
48
|
+
export interface UIWorkletSpringSample {
|
|
49
|
+
/** Normalized input-vector progress; may overshoot zero or one. */
|
|
50
|
+
readonly position: number;
|
|
51
|
+
/** Normalized input-vector progress per second. */
|
|
52
|
+
readonly velocity: number;
|
|
53
|
+
readonly settled: boolean;
|
|
54
|
+
}
|
|
55
|
+
export interface UIWorkletDecay {
|
|
56
|
+
/** Exponential velocity loss per second. */
|
|
57
|
+
readonly deceleration: number;
|
|
58
|
+
/** Absolute input units per second. */
|
|
59
|
+
readonly velocityThreshold: number;
|
|
60
|
+
readonly maximumDurationMilliseconds: number;
|
|
61
|
+
}
|
|
62
|
+
export interface UIWorkletDecaySample {
|
|
63
|
+
/** Multiply each initial input velocity by this to get displacement. */
|
|
64
|
+
readonly displacementFactorSeconds: number;
|
|
65
|
+
/** Multiply each initial input velocity by this to get current velocity. */
|
|
66
|
+
readonly velocityFactor: number;
|
|
67
|
+
/** Maximum absolute input velocity in units per second. */
|
|
68
|
+
readonly speed: number;
|
|
69
|
+
readonly settled: boolean;
|
|
70
|
+
}
|
|
71
|
+
export interface UIWorkletFrameStatistics {
|
|
72
|
+
readonly frameCount: number;
|
|
73
|
+
readonly intervalCount: number;
|
|
74
|
+
readonly sampledIntervalCount: number;
|
|
75
|
+
readonly droppedIntervalSampleCount: number;
|
|
76
|
+
readonly firstFrameTimeMilliseconds: number;
|
|
77
|
+
readonly lastFrameTimeMilliseconds: number;
|
|
78
|
+
readonly minimumFrameIntervalMilliseconds: number;
|
|
79
|
+
readonly maximumFrameIntervalMilliseconds: number;
|
|
80
|
+
readonly meanFrameIntervalMilliseconds: number;
|
|
81
|
+
readonly p50FrameIntervalMilliseconds: number;
|
|
82
|
+
readonly p95FrameIntervalMilliseconds: number;
|
|
83
|
+
readonly p99FrameIntervalMilliseconds: number;
|
|
84
|
+
}
|
|
85
|
+
export interface UIWorkletPanGesture {
|
|
86
|
+
readonly xInput: string;
|
|
87
|
+
readonly yInput: string;
|
|
88
|
+
readonly minX: number;
|
|
89
|
+
readonly maxX: number;
|
|
90
|
+
readonly minY: number;
|
|
91
|
+
readonly maxY: number;
|
|
92
|
+
/** Optional native velocity handoff when the recognizer ends successfully. */
|
|
93
|
+
readonly releaseDecay?: UIWorkletDecay;
|
|
94
|
+
}
|
|
95
|
+
export type UIWorkletPanGesturePhase = "begin" | "change" | "end" | "cancel";
|
|
96
|
+
export type UIWorkletBinaryOperator = "add" | "subtract" | "multiply" | "divide" | "min" | "max";
|
|
97
|
+
export type UIWorkletExpression = {
|
|
98
|
+
readonly kind: "constant";
|
|
99
|
+
readonly value: number;
|
|
100
|
+
} | {
|
|
101
|
+
readonly kind: "input";
|
|
102
|
+
readonly name: string;
|
|
103
|
+
} | {
|
|
104
|
+
readonly kind: "binary";
|
|
105
|
+
readonly operator: UIWorkletBinaryOperator;
|
|
106
|
+
readonly left: UIWorkletExpression;
|
|
107
|
+
readonly right: UIWorkletExpression;
|
|
108
|
+
} | {
|
|
109
|
+
readonly kind: "abs";
|
|
110
|
+
readonly value: UIWorkletExpression;
|
|
111
|
+
} | {
|
|
112
|
+
readonly kind: "negate";
|
|
113
|
+
readonly value: UIWorkletExpression;
|
|
114
|
+
} | {
|
|
115
|
+
readonly kind: "clamp";
|
|
116
|
+
readonly value: UIWorkletExpression;
|
|
117
|
+
readonly min: number;
|
|
118
|
+
readonly max: number;
|
|
119
|
+
} | {
|
|
120
|
+
readonly kind: "interpolate";
|
|
121
|
+
readonly value: UIWorkletExpression;
|
|
122
|
+
readonly inputRange: readonly [number, number];
|
|
123
|
+
readonly outputRange: readonly [number, number];
|
|
124
|
+
readonly extrapolate: "clamp" | "extend";
|
|
125
|
+
};
|
|
126
|
+
/** A literal number is shorthand for a constant in the authoring API. */
|
|
127
|
+
export type UIWorkletOperand = UIWorkletExpression | number;
|
|
128
|
+
export type UIWorkletInputExpressions<TInputs extends Readonly<Record<string, number>>> = {
|
|
129
|
+
readonly [TName in keyof TInputs]: {
|
|
130
|
+
readonly kind: "input";
|
|
131
|
+
readonly name: TName & string;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
/** Typed expression helpers supplied to the concise graph-authoring callback. */
|
|
135
|
+
export interface UIWorkletExpressionBuilder {
|
|
136
|
+
constant(value: number): UIWorkletExpression;
|
|
137
|
+
add(left: UIWorkletOperand, right: UIWorkletOperand): UIWorkletExpression;
|
|
138
|
+
subtract(left: UIWorkletOperand, right: UIWorkletOperand): UIWorkletExpression;
|
|
139
|
+
multiply(left: UIWorkletOperand, right: UIWorkletOperand): UIWorkletExpression;
|
|
140
|
+
divide(left: UIWorkletOperand, right: UIWorkletOperand): UIWorkletExpression;
|
|
141
|
+
min(left: UIWorkletOperand, right: UIWorkletOperand): UIWorkletExpression;
|
|
142
|
+
max(left: UIWorkletOperand, right: UIWorkletOperand): UIWorkletExpression;
|
|
143
|
+
abs(value: UIWorkletOperand): UIWorkletExpression;
|
|
144
|
+
negate(value: UIWorkletOperand): UIWorkletExpression;
|
|
145
|
+
clamp(value: UIWorkletOperand, min: number, max: number): UIWorkletExpression;
|
|
146
|
+
interpolate(value: UIWorkletOperand, inputRange: readonly [number, number], outputRange: readonly [number, number], extrapolate?: "clamp" | "extend"): UIWorkletExpression;
|
|
147
|
+
}
|
|
148
|
+
export interface UIWorkletInput {
|
|
149
|
+
readonly name: string;
|
|
150
|
+
readonly initialValue: number;
|
|
151
|
+
}
|
|
152
|
+
export interface UIWorkletOutput {
|
|
153
|
+
readonly name: string;
|
|
154
|
+
readonly expression: UIWorkletExpression;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Transport-safe numeric graph intended for compilation by a native UI
|
|
158
|
+
* runtime. It deliberately contains no JavaScript closures or captured values.
|
|
159
|
+
*/
|
|
160
|
+
export interface UIWorkletGraph {
|
|
161
|
+
readonly protocolVersion: typeof UI_WORKLET_PROTOCOL_VERSION;
|
|
162
|
+
readonly inputs: readonly UIWorkletInput[];
|
|
163
|
+
readonly outputs: readonly UIWorkletOutput[];
|
|
164
|
+
}
|
|
165
|
+
export type UIWorkletHandle = number;
|
|
166
|
+
export interface UIWorkletHost {
|
|
167
|
+
readonly protocolVersion: typeof UI_WORKLET_PROTOCOL_VERSION;
|
|
168
|
+
installGraph(graph: UIWorkletGraph): UIWorkletHandle;
|
|
169
|
+
/** Must publish the complete input frame and its derived outputs atomically. */
|
|
170
|
+
updateGraphInputs(handle: UIWorkletHandle, inputs: readonly number[], timestamp: number): void;
|
|
171
|
+
/**
|
|
172
|
+
* Optional native/display-thread extension. A newer input publication or
|
|
173
|
+
* driver request interrupts active motion from its last evaluated frame.
|
|
174
|
+
*/
|
|
175
|
+
animateGraphInputs?(handle: UIWorkletHandle, inputs: readonly number[], timestamp: number, timing: UIWorkletTiming): void;
|
|
176
|
+
/** Optional finite sequence of complete native timing targets. */
|
|
177
|
+
animateGraphKeyframes?(handle: UIWorkletHandle, keyframes: readonly UIWorkletTimingKeyframe[], timestamp: number): void;
|
|
178
|
+
/** Optional native/display-thread analytical spring extension. */
|
|
179
|
+
springGraphInputs?(handle: UIWorkletHandle, inputs: readonly number[], timestamp: number, spring: UIWorkletSpring): void;
|
|
180
|
+
/** Optional native/display-thread analytical velocity-decay extension. */
|
|
181
|
+
decayGraphInputs?(handle: UIWorkletHandle, velocities: readonly number[], timestamp: number, decay: UIWorkletDecay): void;
|
|
182
|
+
/**
|
|
183
|
+
* Stops an active native driver and returns the exact frozen input vector.
|
|
184
|
+
* The returned vector lets the session resume partial updates without using
|
|
185
|
+
* a stale JavaScript-side target.
|
|
186
|
+
*/
|
|
187
|
+
cancelGraphAnimation?(handle: UIWorkletHandle, timestamp: number): readonly number[];
|
|
188
|
+
/**
|
|
189
|
+
* Optional native-input extension. Attachment transfers the graph input
|
|
190
|
+
* vector to the host until it is detached or the graph is destroyed.
|
|
191
|
+
*/
|
|
192
|
+
attachPanGesture?(handle: UIWorkletHandle, gesture: UIWorkletPanGesture): void;
|
|
193
|
+
/** Releases native pan ownership and returns the exact frozen input vector. */
|
|
194
|
+
detachPanGesture?(handle: UIWorkletHandle, timestamp: number): readonly number[];
|
|
195
|
+
destroyGraph(handle: UIWorkletHandle): void;
|
|
196
|
+
}
|
|
197
|
+
export interface UIWorkletSessionOptions {
|
|
198
|
+
/** Monotonic or epoch milliseconds used for JavaScript-originated updates. */
|
|
199
|
+
readonly clock?: () => number;
|
|
200
|
+
/**
|
|
201
|
+
* Pull-based system or application preference checked for every new motion
|
|
202
|
+
* request. `undefined` is treated as no preference while state is loading.
|
|
203
|
+
*/
|
|
204
|
+
readonly reduceMotion?: () => boolean | undefined;
|
|
205
|
+
}
|
|
206
|
+
export interface UIWorkletSession {
|
|
207
|
+
readonly graph: UIWorkletGraph;
|
|
208
|
+
readonly handle: UIWorkletHandle;
|
|
209
|
+
readonly disposed: boolean;
|
|
210
|
+
readonly nativeInputsOwned: boolean;
|
|
211
|
+
readonly inputs: Readonly<Record<string, number>>;
|
|
212
|
+
/** Atomically replaces the named subset of graph inputs. */
|
|
213
|
+
update(inputs: Readonly<Record<string, number>>, timestamp?: number): void;
|
|
214
|
+
/** Animates the named subset as one complete native input vector. */
|
|
215
|
+
animate(inputs: Readonly<Record<string, number>>, timing: UIWorkletTiming, timestamp?: number): void;
|
|
216
|
+
/** Runs finite timing targets without a JavaScript wakeup between stages. */
|
|
217
|
+
animateKeyframes(keyframes: readonly UIWorkletNamedTimingKeyframe[], timestamp?: number): void;
|
|
218
|
+
/** Springs the named subset as one complete native input vector. */
|
|
219
|
+
spring(inputs: Readonly<Record<string, number>>, spring: UIWorkletSpring, timestamp?: number): void;
|
|
220
|
+
/** Decays named per-input velocities as one complete native vector. */
|
|
221
|
+
decay(velocities: Readonly<Record<string, number>>, decay: UIWorkletDecay, timestamp?: number): void;
|
|
222
|
+
/** Stops native motion and synchronizes inputs to its last evaluated frame. */
|
|
223
|
+
cancel(timestamp?: number): void;
|
|
224
|
+
/** Transfers this session's input vector to one native pan until detached. */
|
|
225
|
+
attachPanGesture(gesture: UIWorkletPanGesture): void;
|
|
226
|
+
/** Releases native pan ownership and synchronizes its final input vector. */
|
|
227
|
+
detachPanGesture(timestamp?: number): void;
|
|
228
|
+
/** Idempotently releases the installed graph. */
|
|
229
|
+
dispose(): void;
|
|
230
|
+
}
|
|
231
|
+
export interface InMemoryUIWorkletSnapshot {
|
|
232
|
+
readonly handle: UIWorkletHandle;
|
|
233
|
+
readonly sequence: number;
|
|
234
|
+
readonly inputs: Readonly<Record<string, number>>;
|
|
235
|
+
readonly outputs: Readonly<Record<string, number>>;
|
|
236
|
+
readonly timestamp?: number;
|
|
237
|
+
readonly timingActive: boolean;
|
|
238
|
+
readonly timingProgress: number;
|
|
239
|
+
readonly timingFrameStatistics?: UIWorkletFrameStatistics;
|
|
240
|
+
readonly springActive?: boolean;
|
|
241
|
+
readonly springPosition?: number;
|
|
242
|
+
readonly springVelocity?: number;
|
|
243
|
+
readonly springFrameStatistics?: UIWorkletFrameStatistics;
|
|
244
|
+
readonly decayActive?: boolean;
|
|
245
|
+
readonly decayElapsedMilliseconds?: number;
|
|
246
|
+
readonly decaySpeed?: number;
|
|
247
|
+
readonly decayFrameStatistics?: UIWorkletFrameStatistics;
|
|
248
|
+
readonly gestureAttached?: boolean;
|
|
249
|
+
readonly gestureActive?: boolean;
|
|
250
|
+
readonly gestureSequence?: number;
|
|
251
|
+
readonly gestureTimestamp?: number;
|
|
252
|
+
}
|
|
253
|
+
export interface InMemoryUIWorkletHost extends UIWorkletHost {
|
|
254
|
+
readonly activeGraphCount: number;
|
|
255
|
+
/** Advances every active driver at one deterministic display timestamp. */
|
|
256
|
+
advanceFrame(frameTimeMilliseconds: number): void;
|
|
257
|
+
/** Delivers one deterministic native-clock pan sample. */
|
|
258
|
+
dispatchPanGesture(handle: UIWorkletHandle, phase: UIWorkletPanGesturePhase, translationX: number, translationY: number, timestamp: number, velocityX?: number, velocityY?: number): void;
|
|
259
|
+
snapshot(handle: UIWorkletHandle): InMemoryUIWorkletSnapshot;
|
|
260
|
+
}
|
|
261
|
+
/** Validates, clones, and deeply freezes an untrusted worklet graph. */
|
|
262
|
+
export declare function parseUIWorkletGraph(value: unknown): UIWorkletGraph;
|
|
263
|
+
/** Validates an explicit transport-level graph definition. */
|
|
264
|
+
export declare function createUIWorkletGraph(definition: UIWorkletGraph): UIWorkletGraph;
|
|
265
|
+
/**
|
|
266
|
+
* Builds a transport-safe graph from named initial inputs and typed numeric
|
|
267
|
+
* expressions. The callback executes once while the graph is defined; it is
|
|
268
|
+
* never serialized or run on the UI thread.
|
|
269
|
+
*/
|
|
270
|
+
export declare function createUIWorkletGraph<const TInputs extends Readonly<Record<string, number>>>(initialInputs: TInputs, defineOutputs: (inputs: UIWorkletInputExpressions<TInputs>, expression: UIWorkletExpressionBuilder) => Readonly<Record<string, UIWorkletOperand>>): UIWorkletGraph;
|
|
271
|
+
/** Validates and freezes one bounded native timing request. */
|
|
272
|
+
export declare function parseUIWorkletTiming(value: unknown): UIWorkletTiming;
|
|
273
|
+
/** Validates and freezes one bounded analytical native spring. */
|
|
274
|
+
export declare function parseUIWorkletSpring(value: unknown): UIWorkletSpring;
|
|
275
|
+
/** Validates and freezes one bounded analytical native velocity decay. */
|
|
276
|
+
export declare function parseUIWorkletDecay(value: unknown): UIWorkletDecay;
|
|
277
|
+
/** Validates and freezes one bounded native pan-to-input mapping. */
|
|
278
|
+
export declare function parseUIWorkletPanGesture(value: unknown, graphValue: UIWorkletGraph): UIWorkletPanGesture;
|
|
279
|
+
/** Reference easing semantics shared by deterministic and native hosts. */
|
|
280
|
+
export declare function evaluateUIWorkletTimingProgress(timingValue: UIWorkletTiming, elapsedMillisecondsValue: number): number;
|
|
281
|
+
/**
|
|
282
|
+
* Analytical damped-harmonic-oscillator reference. Its result depends on
|
|
283
|
+
* elapsed time rather than the number of display callbacks.
|
|
284
|
+
*/
|
|
285
|
+
export declare function evaluateUIWorkletSpring(springValue: UIWorkletSpring, elapsedMillisecondsValue: number): UIWorkletSpringSample;
|
|
286
|
+
/**
|
|
287
|
+
* Analytical exponential-decay reference for a complete velocity vector.
|
|
288
|
+
* `initialSpeedValue` is that vector's maximum absolute input velocity.
|
|
289
|
+
*/
|
|
290
|
+
export declare function evaluateUIWorkletDecay(decayValue: UIWorkletDecay, initialSpeedValue: number, elapsedMillisecondsValue: number): UIWorkletDecaySample;
|
|
291
|
+
/** Reference semantics used by native backends and deterministic tests. */
|
|
292
|
+
export declare function evaluateUIWorkletGraph(graphValue: UIWorkletGraph, inputValue: Readonly<Record<string, number>>): Readonly<Record<string, number>>;
|
|
293
|
+
/**
|
|
294
|
+
* Installs one validated graph and owns its input/cancellation boundary. This
|
|
295
|
+
* does not imply that the injected host executes on the UI thread.
|
|
296
|
+
*/
|
|
297
|
+
export declare function createUIWorkletSession(host: UIWorkletHost, graphValue: UIWorkletGraph, options?: UIWorkletSessionOptions): UIWorkletSession;
|
|
298
|
+
/** Deterministic reference host; it is intentionally not a UI-thread backend. */
|
|
299
|
+
export declare function createInMemoryUIWorkletHost(): InMemoryUIWorkletHost;
|
|
300
|
+
//# sourceMappingURL=index.d.ts.map
|