@felipe-software/react-native-gpui 0.0.0-stage → 1.0.1

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 (72) hide show
  1. package/.reanimated-prebuilt/react-native-reanimated.mjs +29373 -0
  2. package/LICENSE +21 -0
  3. package/README.md +657 -2
  4. package/cli/bin.ts +379 -0
  5. package/cli/bundle.ts +32 -0
  6. package/cli/commands/do.ts +213 -0
  7. package/cli/commands/flow.ts +283 -0
  8. package/cli/commands/get.ts +584 -0
  9. package/cli/commands/shot.ts +312 -0
  10. package/cli/commands/trace.ts +293 -0
  11. package/cli/host.ts +714 -0
  12. package/cli/hotReload.ts +210 -0
  13. package/cli/run.ts +66 -0
  14. package/cli/selectors.ts +205 -0
  15. package/dist/Animated.d.ts +120 -0
  16. package/dist/ChatList.d.ts +28 -0
  17. package/dist/Dimensions.d.ts +31 -0
  18. package/dist/StyleSheet.d.ts +18 -0
  19. package/dist/Window.d.ts +33 -0
  20. package/dist/apis.d.ts +165 -0
  21. package/dist/app-state.d.ts +27 -0
  22. package/dist/chat-list-types.d.ts +136 -0
  23. package/dist/colors.d.ts +32 -0
  24. package/dist/commands.d.ts +230 -0
  25. package/dist/components.d.ts +419 -0
  26. package/dist/hotModules.d.ts +1 -0
  27. package/dist/index.d.ts +31 -0
  28. package/dist/index.development.js +14876 -0
  29. package/dist/index.js +12 -0
  30. package/dist/keyboard.d.ts +140 -0
  31. package/dist/native-menu.d.ts +7 -0
  32. package/dist/platform-driver.d.ts +32 -0
  33. package/dist/platform-services.d.ts +35 -0
  34. package/dist/portal.d.ts +43 -0
  35. package/dist/raf.d.ts +4 -0
  36. package/dist/reanimated/colors-processor-shim.d.ts +10 -0
  37. package/dist/reanimated/reanimated-host.d.ts +10 -0
  38. package/dist/reanimated/seam.d.ts +34 -0
  39. package/dist/reanimated/ui-entry.d.ts +2 -0
  40. package/dist/reanimated/worklet-channel.d.ts +10 -0
  41. package/dist/reanimated/worklet-runtime.d.ts +466 -0
  42. package/dist/reanimated/worklets.d.ts +199 -0
  43. package/dist/reconciler.d.ts +102 -0
  44. package/dist/refresh.d.ts +1 -0
  45. package/dist/render.d.ts +37 -0
  46. package/dist/runtime.d.ts +235 -0
  47. package/dist/surfaces.d.ts +51 -0
  48. package/dist/types.d.ts +276 -0
  49. package/dist/ui-runtime.js +42276 -0
  50. package/dist/window-context.d.ts +7 -0
  51. package/dist/window-host.d.ts +41 -0
  52. package/dist/wire-delta.d.ts +20 -0
  53. package/package.json +176 -5
  54. package/scripts/bundle-app.mjs +88 -0
  55. package/scripts/conformance-utils.mjs +293 -0
  56. package/scripts/hot-update-alias-plugin.mjs +88 -0
  57. package/scripts/native-package-exports-plugin.mjs +235 -0
  58. package/scripts/pixel.mjs +152 -0
  59. package/scripts/png.mjs +198 -0
  60. package/scripts/react-refresh-swc.mjs +35 -0
  61. package/scripts/reanimated-bun-plugin.mjs +188 -0
  62. package/scripts/service-binary.d.mts +27 -0
  63. package/scripts/service-binary.mjs +100 -0
  64. package/src/reanimated/colors-processor-shim.ts +119 -0
  65. package/src/reanimated/reanimated-host.ts +69 -0
  66. package/src/reanimated/rngpui-reanimated-prebuilt.d.ts +7 -0
  67. package/src/reanimated/seam.ts +566 -0
  68. package/src/reanimated/ui-entry.ts +80 -0
  69. package/src/reanimated/worklet-channel.ts +64 -0
  70. package/src/reanimated/worklet-runtime.ts +2569 -0
  71. package/src/reanimated/worklets.ts +1334 -0
  72. package/src/refresh.ts +33 -0
@@ -0,0 +1,466 @@
1
+ type WorkletBuiltinName = string;
2
+ export type ValueSpec = {
3
+ kind: 'sv';
4
+ id: number;
5
+ } | {
6
+ kind: 'svObject';
7
+ id: number;
8
+ } | {
9
+ kind: 'svDetached';
10
+ value: unknown;
11
+ } | {
12
+ kind: 'animation';
13
+ type: string;
14
+ args: ValueSpec[];
15
+ } | {
16
+ kind: 'plain';
17
+ value: unknown;
18
+ } | {
19
+ kind: 'builtin';
20
+ name: WorkletBuiltinName;
21
+ } | {
22
+ kind: 'fn';
23
+ code: string;
24
+ closureSpec: ClosureSpec;
25
+ hash: number;
26
+ closureId: number;
27
+ } | {
28
+ kind: 'initializer';
29
+ init: WorkletFunctionSpec;
30
+ } | {
31
+ kind: 'animatedRef';
32
+ viewTag: number;
33
+ } | {
34
+ kind: 'animatedRefSlot';
35
+ slotId: number;
36
+ } | {
37
+ kind: 'jsCallback';
38
+ id: number;
39
+ } | {
40
+ kind: 'undef';
41
+ } | {
42
+ kind: 'array';
43
+ items: ValueSpec[];
44
+ } | {
45
+ kind: 'object';
46
+ entries: Array<[string, ValueSpec]>;
47
+ } | {
48
+ kind: 'shareableRef';
49
+ id: number;
50
+ snapshot: Array<[string, ValueSpec]>;
51
+ };
52
+ export type ClosureSpec = Record<string, ValueSpec>;
53
+ type WorkletFunctionSpec = Extract<ValueSpec, {
54
+ kind: 'fn';
55
+ }>;
56
+ export declare function markWorkletBuiltin<T extends (...args: never[]) => unknown>(name: string, fn: T): T;
57
+ /**
58
+ * Register a worklet builtin by name. The integrator populates this from the
59
+ * UI-side upstream reanimated module so that closures captured on the React side
60
+ * (which serialize builtins as {kind:'builtin', name}) resolve to the real UI
61
+ * implementation on deserialization. See bindBuiltin's special cases.
62
+ *
63
+ * The value is usually a function (withSpring, scrollTo, …) but may be a namespace
64
+ * object exposed to worklet bodies by name (e.g. `Easing`), so the registry holds
65
+ * `unknown`. Functions also get the hidden name brand (for outbound serialization);
66
+ * non-functions just land in the registry for by-name resolution.
67
+ */
68
+ export declare function registerWorkletBuiltin(name: string, value: unknown): void;
69
+ export interface WorkletDispatchOptions {
70
+ awaitReply?: boolean;
71
+ eventTimestamp?: number;
72
+ }
73
+ export type WorkletMessage = {
74
+ type: 'runWorklet';
75
+ runId: number;
76
+ code: string;
77
+ hash: number;
78
+ closureId: number;
79
+ closureSpec: ClosureSpec;
80
+ argsSpec: ValueSpec[];
81
+ awaitReply: boolean;
82
+ eventTimestamp?: number;
83
+ } | {
84
+ type: 'workletReply';
85
+ runId: number;
86
+ ok: boolean;
87
+ returnValueSpec?: ValueSpec;
88
+ error?: string;
89
+ } | {
90
+ type: 'workletDone';
91
+ runId: number;
92
+ ok: boolean;
93
+ error?: string;
94
+ } | {
95
+ type: 'svUpdate';
96
+ svId: number;
97
+ value: number;
98
+ } | {
99
+ type: 'svUpdateBatch';
100
+ updates: Array<{
101
+ svId: number;
102
+ value: number;
103
+ }>;
104
+ objectUpdates?: Array<{
105
+ svId: number;
106
+ value: unknown;
107
+ }>;
108
+ } | {
109
+ type: 'svAlloc';
110
+ svId: number;
111
+ initial: number;
112
+ bool?: boolean;
113
+ } | {
114
+ type: 'svObjectAlloc';
115
+ svId: number;
116
+ initial: unknown;
117
+ } | {
118
+ type: 'svFree';
119
+ svId: number;
120
+ } | {
121
+ type: 'runJSCallback';
122
+ callbackId: number;
123
+ argsSpec: ValueSpec[];
124
+ };
125
+ export interface WorkletChannel {
126
+ send(msg: WorkletMessage): void;
127
+ hasPeer(): boolean;
128
+ }
129
+ export type WorkletRuntimeRole = 'react' | 'ui';
130
+ export declare class WorkletRuntime {
131
+ private channel;
132
+ private buffer;
133
+ private floats;
134
+ private capacity;
135
+ private listeners;
136
+ private lastSlotListenerValue;
137
+ private freeSlots;
138
+ private freedSet;
139
+ private freeObjectSlots;
140
+ private freedObjectSet;
141
+ private svProxyCache;
142
+ private svObjectProxyCache;
143
+ private boolSlots;
144
+ private nextId;
145
+ private nextObjectId;
146
+ private idStride;
147
+ private role;
148
+ private statPrimitiveAllocs;
149
+ private statObjectAllocs;
150
+ private statReusedAllocs;
151
+ private statFrees;
152
+ private exhaustionLoggedAt;
153
+ private exhaustionSuppressed;
154
+ private runIdCounter;
155
+ private pending;
156
+ private workletCache;
157
+ private materializedClosureCache;
158
+ private remoteWorkletCache;
159
+ private shareableCache;
160
+ private serializedWorklets;
161
+ private nextSerializedClosureId;
162
+ private jsCallbacks;
163
+ private jsCallbackByFn;
164
+ private nextJsCallbackId;
165
+ private animatedRefSlots;
166
+ private statRunJSCallbackSent;
167
+ private statRunJSCallbackReceived;
168
+ private statRunJSCallbackMissing;
169
+ private pendingRunWorklets;
170
+ private statRunWorkletSent;
171
+ private statRunWorkletDone;
172
+ private statRunWorkletFailed;
173
+ private statClosureCacheHits;
174
+ private statClosureCacheMisses;
175
+ private pendingPeerUpdates;
176
+ private peerFlushScheduled;
177
+ private statWriteRequests;
178
+ private statBatchesSent;
179
+ private objectSlots;
180
+ private objectListeners;
181
+ private pendingObjectUpdates;
182
+ constructor(opts: {
183
+ channel: WorkletChannel;
184
+ buffer: ArrayBuffer;
185
+ role: WorkletRuntimeRole;
186
+ });
187
+ /**
188
+ * Inbound channel entry point. The channel adapter calls this with each
189
+ * decoded message. Public so the adapter (worklet-channel.ts) can wire it.
190
+ */
191
+ onMessage(msg: WorkletMessage): void;
192
+ /**
193
+ * Allocate a slot, write the initial value, and announce to the peer.
194
+ * Returns the slot id. Slots 0..3 are reserved (header).
195
+ */
196
+ allocSharedValueSlot(initial: number, isBool?: boolean): number;
197
+ /**
198
+ * Reuse a reclaimed slot id if one is available, else advance the matching
199
+ * counter. Primitive and object ids live in DISJOINT ranges with their own
200
+ * counters + free-lists (see OBJECT_ID_BASE): primitive ids index the shared
201
+ * Float64 array so they are capacity-bounded; object ids are JS-Map-backed so
202
+ * their range is effectively unbounded. A freed id is fully reset by
203
+ * releaseSlotState() before it returns to its pool.
204
+ */
205
+ private allocSlotId;
206
+ /**
207
+ * Throttled exhaustion logging. A re-render storm can hit the exhausted
208
+ * allocator hundreds of thousands of times in a burst; building an Error+stack
209
+ * and console.error-ing each time is itself enough to OOM/crash the runtime.
210
+ * Throttle to one log per window with a suppressed-count.
211
+ */
212
+ private logExhaustion;
213
+ /** true if `id` belongs to the disjoint object-slot id range. */
214
+ private isObjectId;
215
+ /**
216
+ * Clear every per-id structure for `id` and return the cell to zero. Shared by
217
+ * freeSlot() (owner side) and the inbound 'svFree' handler (peer side); both
218
+ * need the mirror dropped, only the owner recycles.
219
+ */
220
+ private releaseSlotState;
221
+ /**
222
+ * Reclaim a SharedValue slot whose JS wrapper was garbage-collected. Mirrors
223
+ * reanimated's native Shareable lifetime: once the JS Mutable is collected
224
+ * nothing can reference the value (live mappers / useAnimatedStyle deps keep the
225
+ * wrapper alive), so the slot is safe to recycle. Idempotent. Owner-only — a
226
+ * runtime only frees ids it allocates (even=react / odd=ui); the parity guard
227
+ * keeps a stray call from poisoning the peer's id space.
228
+ */
229
+ freeSlot(id: number): void;
230
+ readSlot(id: number): number;
231
+ /**
232
+ * Write a value to a slot, fire local listeners, and notify the peer.
233
+ * skipNotify=true is used when a write came in via inbound svUpdate to avoid
234
+ * bouncing it back. peer notifications coalesce per microtask — see
235
+ * `enqueuePeerUpdate`.
236
+ */
237
+ writeSlot(id: number, value: unknown, skipNotify?: boolean): boolean;
238
+ /**
239
+ * Used by createShareable's local-write echo: updates the cell and notifies the
240
+ * peer, but skips fireLocal. Required because the local SharedValue's listeners
241
+ * already fired the upstream fan-out — we don't want subscribeSlot listeners to
242
+ * fire again and recurse back into upstream's `_value` setter.
243
+ */
244
+ syncToPeer(id: number, value: unknown): boolean;
245
+ /**
246
+ * Queue an svUpdate for the peer. Within a single JS turn, repeat writes to the
247
+ * same slot collapse to last-write-wins. Flush happens at microtask boundary as
248
+ * a single `svUpdateBatch` message.
249
+ */
250
+ private enqueuePeerUpdate;
251
+ /**
252
+ * Single microtask schedules both primitive and object pending updates so a
253
+ * mixed-write turn ships at most one combined batch message per microtask (not
254
+ * two — one per kind). Both sides decode `svUpdateBatch` with optional
255
+ * `objectUpdates` for backward compat.
256
+ */
257
+ private scheduleUnifiedFlush;
258
+ private flushPendingPeerUpdates;
259
+ /**
260
+ * Force-flush any pending svUpdate batch to the peer. Used by tests and callers
261
+ * that need a synchronous handoff. Normal callers should rely on the microtask
262
+ * flush.
263
+ */
264
+ flushPeerUpdates(): void;
265
+ /**
266
+ * Allocate an object SV slot, seed the local Map, and announce to the peer.
267
+ * Returns the slot id. Object SVs use the same react-even / ui-odd lane
268
+ * convention as primitive SVs, but in a disjoint high range so object churn
269
+ * never consumes primitive cells.
270
+ */
271
+ allocObjectSharedValueSlot(initial: unknown): number;
272
+ readObjectSlot(id: number): unknown;
273
+ /**
274
+ * Write an object value to a slot, fire local listeners, and queue a peer
275
+ * notification. skipNotify avoids bouncing inbound updates back. Identity
276
+ * comparison would be too expensive (deep equality); we always notify on write
277
+ * — callers that want dedup should compare before calling.
278
+ */
279
+ writeObjectSlot(id: number, value: unknown, skipNotify?: boolean): boolean;
280
+ /**
281
+ * Object-slot equivalent of syncToPeer: updates the local Map and notifies the
282
+ * peer, but skips fireObjectLocal. Used by createShareable to avoid recursing
283
+ * into upstream listener fan-out.
284
+ */
285
+ syncObjectToPeer(id: number, value: unknown): boolean;
286
+ subscribeObjectSlot(id: number, fn: (value: unknown) => void): () => void;
287
+ private fireObjectLocal;
288
+ private enqueueObjectUpdate;
289
+ /**
290
+ * Snapshot of the per-runtime svUpdate coalescing counters. Read by tests for
291
+ * empirical perf validation. ratio (writeRequests / batchesSent) is the average
292
+ * coalescing factor — higher is better.
293
+ */
294
+ getPeerStats(reset?: boolean): {
295
+ writeRequests: number;
296
+ batchesSent: number;
297
+ pendingRunWorklets: number;
298
+ runWorkletsSent: number;
299
+ runWorkletsDone: number;
300
+ runWorkletsFailed: number;
301
+ closureCacheHits: number;
302
+ closureCacheMisses: number;
303
+ };
304
+ getSlotStats(): {
305
+ role: WorkletRuntimeRole;
306
+ capacity: number;
307
+ nextId: number;
308
+ freeSlots: number;
309
+ freedSlots: number;
310
+ nextObjectId: number;
311
+ freeObjectSlots: number;
312
+ freedObjectSlots: number;
313
+ primitiveAllocs: number;
314
+ objectAllocs: number;
315
+ reusedAllocs: number;
316
+ frees: number;
317
+ listenerSlots: number;
318
+ objectListenerSlots: number;
319
+ objectSlots: number;
320
+ pendingPrimitiveUpdates: number;
321
+ pendingObjectUpdates: number;
322
+ runJSCallbackSent: number;
323
+ runJSCallbackReceived: number;
324
+ runJSCallbackMissing: number;
325
+ };
326
+ subscribeSlot(id: number, fn: (value: number) => void): () => void;
327
+ private fireLocal;
328
+ private fireLocalIfChanged;
329
+ /**
330
+ * Ship a worklet to the peer for execution. The fn must have been processed by
331
+ * react-native-worklets/plugin so it carries __initData, __closure,
332
+ * __workletHash. Returns a Promise that resolves with the worklet's return value
333
+ * (when awaitReply is true) or undefined for fire-and-forget.
334
+ */
335
+ dispatchWorklet(fn: WorkletFn, args: unknown[], opts?: WorkletDispatchOptions): Promise<unknown>;
336
+ /** returns true if a SharedValue with this id has a slot in the shared array */
337
+ hasSlot(id: number): boolean;
338
+ /**
339
+ * Register a React-local callback so it can be invoked by UI-side worklets via
340
+ * runOnJS. Returns a wrapper function that:
341
+ * - when called locally on react, just runs `fn` (so existing call sites that
342
+ * don't ship to ui still work)
343
+ * - when serialized via serializeValue, becomes a kind:'jsCallback' spec
344
+ * carrying the registration id
345
+ *
346
+ * Memoizes per source fn so the same `runOnJS(fn)` call returns a stable wrapper
347
+ * across renders, keeping the id space small.
348
+ */
349
+ registerJSCallback<T extends (...args: unknown[]) => unknown>(fn: T): T;
350
+ private serializeValueForDispatch;
351
+ private serializeClosureForDispatch;
352
+ private serializeWorkletFunctionForDispatch;
353
+ private serializeRegisteredJSCallback;
354
+ /**
355
+ * Send a `runJSCallback` to the peer. UI-side bindRemoteJSCallback uses this
356
+ * when a deserialized callback wrapper is invoked.
357
+ */
358
+ postJSCallback(id: number, args: unknown[]): void;
359
+ private handleRunWorklet;
360
+ /**
361
+ * Re-hydrate a closure spec into an object the worklet body can read via
362
+ * `this.__closure`. SV refs become live SharedValue proxies bound to this
363
+ * runtime's slot view; nested fn specs become callable worklets that themselves
364
+ * dispatch back to the peer.
365
+ */
366
+ deserializeClosure(spec: ClosureSpec): Record<string, unknown>;
367
+ private getMaterializedClosure;
368
+ deserializeValue(spec: ValueSpec): unknown;
369
+ /**
370
+ * Bind a peer-side js-callback id to a local function that ships args back
371
+ * across the channel. Used on the UI runtime for runOnJS-tagged callbacks
372
+ * captured in the closure.
373
+ */
374
+ private bindRemoteJSCallback;
375
+ private bindBuiltin;
376
+ /**
377
+ * A SharedValue proxy on the receiving side: reads/writes route through the slot,
378
+ * and sets fan out to listeners. the proxy intentionally matches the same minimal
379
+ * shape the worklet body expects (.value getter/setter, .get(), .set()) so
380
+ * worklets authored against the real SharedValue API run unmodified here.
381
+ */
382
+ private bindSharedValueProxy;
383
+ /**
384
+ * Object-SV equivalent of bindSharedValueProxy. Reads return the local Map entry;
385
+ * writes update local + queue a peer notification. Identity isn't preserved across
386
+ * runtimes (the value is structured-cloned across the channel), but each side's Map
387
+ * holds the latest snapshot so .value always returns the most recent post-flush
388
+ * state.
389
+ */
390
+ private bindObjectSharedValueProxy;
391
+ private bindRemoteAnimatedRefSlot;
392
+ private serializeAnimatedRefForDispatch;
393
+ /**
394
+ * Bind a remote worklet that lived in the original closure as a callable.
395
+ * Calling it dispatches back through this runtime to the peer where the worklet's
396
+ * home runtime can execute it. This is how runOnJS-from-ui round-trips: the
397
+ * closure had a runOnJS-wrapped worklet, we call it, we ship it back across the
398
+ * channel.
399
+ */
400
+ private bindRemoteWorklet;
401
+ }
402
+ export interface SharedValueProxy {
403
+ _id: number;
404
+ _isReanimatedSharedValue: true;
405
+ value: number | boolean;
406
+ _value: number | boolean;
407
+ _animation: unknown;
408
+ get(): number | boolean;
409
+ set(v: number | boolean | (() => number | boolean)): void;
410
+ modify(modifier: (value: number | boolean) => number | boolean, forceUpdate?: boolean): void;
411
+ addListener(id: number, fn: (value: number) => void): void;
412
+ removeListener(id: number): void;
413
+ setDirty(dirty: boolean): void;
414
+ }
415
+ export interface ObjectSharedValueProxy {
416
+ _id: number;
417
+ _isReanimatedSharedValue: true;
418
+ value: unknown;
419
+ get(): unknown;
420
+ set(v: unknown): void;
421
+ modify(modifier: (value: unknown) => unknown, forceUpdate?: boolean): void;
422
+ addListener(id: number, fn: (value: unknown) => void): void;
423
+ removeListener(id: number): void;
424
+ }
425
+ export interface WorkletFn {
426
+ __closure?: Record<string, unknown>;
427
+ __workletHash?: number;
428
+ __initData?: {
429
+ code?: string;
430
+ location?: string;
431
+ sourceMap?: string;
432
+ };
433
+ (...args: unknown[]): unknown;
434
+ }
435
+ export declare const SHAREABLE_ID_KEY: unique symbol;
436
+ export declare function serializeValue(value: unknown): ValueSpec;
437
+ export declare function serializeClosure(closure: Record<string, unknown>): ClosureSpec;
438
+ export declare function markObjectSV(target: object): void;
439
+ export declare function evalWorkletCode(code: string): (...args: unknown[]) => unknown;
440
+ export declare function createSharedValueBuffer(capacity?: number): ArrayBuffer;
441
+ export declare function setActiveWorkletRuntime(rt: WorkletRuntime): void;
442
+ export declare function getWorkletRuntime(): WorkletRuntime | null;
443
+ export declare function isWorkletRuntimeReady(): boolean;
444
+ /**
445
+ * Install (or return the existing) per-runtime WorkletRuntime singleton. Reads the
446
+ * shared-slot ArrayBuffer from `globalThis.__rngpui_svSlots` (installed by the rust
447
+ * host). The channel adapter (worklet-channel.ts) wires itself in via installChannel
448
+ * — this installs the runtime against a supplied channel. If no channel is supplied
449
+ * the caller is expected to follow up with installChannel(role, runtime).
450
+ *
451
+ * Returns null when the shared-slot buffer is absent (bun unit tests without the
452
+ * host bridge): callers then keep their local-only path.
453
+ */
454
+ export declare function installWorkletRuntime(opts: {
455
+ role: WorkletRuntimeRole;
456
+ channel: WorkletChannel;
457
+ buffer?: ArrayBuffer;
458
+ }): WorkletRuntime | null;
459
+ export declare const __WORKLET_RUNTIME_INTERNALS: {
460
+ SAB_HEADER_FLOATS: number;
461
+ SAB_MAGIC: number;
462
+ DEFAULT_CAPACITY: number;
463
+ OBJECT_ID_BASE: number;
464
+ SHARED_SLOTS_KEY: string;
465
+ };
466
+ export {};
@@ -0,0 +1,199 @@
1
+ import './seam';
2
+ import { type WorkletRuntime as WorkletRuntimeInstance } from './worklet-runtime';
3
+ export interface WorkletFunction {
4
+ __workletHash?: number;
5
+ __initData?: {
6
+ code?: string;
7
+ location?: string;
8
+ sourceMap?: string;
9
+ };
10
+ __closure?: Record<string, unknown>;
11
+ (...args: unknown[]): unknown;
12
+ }
13
+ export interface SerializableRef {
14
+ __init?: () => unknown;
15
+ }
16
+ export interface Synchronizable<T> {
17
+ getBlocking(): T;
18
+ setBlocking(value: T): void;
19
+ }
20
+ export interface IWorkletsModule {
21
+ makeShareableClone: (value: unknown) => unknown;
22
+ scheduleOnUI: (fn: () => void) => void;
23
+ executeOnUIRuntimeSync: <T extends (...args: unknown[]) => unknown>(fn: T) => T;
24
+ createWorkletRuntime: (name: string, initializer?: () => void) => unknown;
25
+ }
26
+ export type MakeShareableClone = (value: unknown) => unknown;
27
+ export type WorkletRuntime = unknown;
28
+ export declare enum RuntimeKind {
29
+ ReactNative = 1,
30
+ UI = 2,
31
+ Worker = 3
32
+ }
33
+ export declare function getUIRuntimeHolder(): object;
34
+ export declare function getUISchedulerHolder(): object;
35
+ export declare const UIRuntimeId = 1;
36
+ interface ShareableGuestBase<TValue = unknown> {
37
+ isHost: false;
38
+ __shareableRef: true;
39
+ getSync(): TValue;
40
+ setAsync(value: TValue | ((prev: TValue) => TValue)): void;
41
+ setSync(value: TValue | ((prev: TValue) => TValue)): void;
42
+ getAsync(): Promise<TValue>;
43
+ modify?(modifier: (value: TValue) => TValue, forceUpdate?: boolean): void;
44
+ }
45
+ interface ShareableConfig<H = unknown, G = unknown> {
46
+ hostDecorator?: (host: {
47
+ value: unknown;
48
+ }) => H;
49
+ guestDecorator?: (guest: ShareableGuestBase) => G;
50
+ initSynchronously?: boolean;
51
+ }
52
+ export declare function createShareable<TValue, THostDecorated = unknown, TGuestDecorated = unknown>(_hostRuntimeId: number, initial: TValue, config?: ShareableConfig<THostDecorated, TGuestDecorated>): unknown;
53
+ /**
54
+ * In real reanimated, runOnJS schedules `fn` on the JS runtime. On rngpui the React
55
+ * runtime IS the JS runtime, so the wrapper executes locally — the worklet runtime
56
+ * registers the wrapper so that when it's captured in a closure that later ships to
57
+ * the UI runtime, the UI-side proxy routes call-args back here. Without the runtime,
58
+ * identity.
59
+ */
60
+ export declare function runOnJS<T extends (...args: unknown[]) => unknown>(fn: T): T;
61
+ /**
62
+ * `runOnUI(fn)` returns a wrapper that schedules workletized functions on the UI
63
+ * runtime; the UI runtime itself runs them on its local microtask path.
64
+ */
65
+ export declare function runOnUI<T extends (...args: unknown[]) => unknown>(fn: T): T;
66
+ /**
67
+ * `runOnRuntime(runtime, fn)` is the explicit cross-runtime escape hatch. rngpui has
68
+ * one peer runtime (the UI runtime); this routes through the worklet runtime when
69
+ * available so callers that genuinely need off-thread execution still get it.
70
+ * Degrades to local execution when no peer is wired.
71
+ */
72
+ export declare function runOnRuntime<T extends (...args: unknown[]) => unknown>(_runtime: unknown, fn: T): T;
73
+ /** Real signature: scheduleOnRN(fn, ...args) — calls fn(...args) async. */
74
+ export declare function scheduleOnRN<T extends (...args: unknown[]) => unknown>(fn: T, ...args: unknown[]): void;
75
+ /**
76
+ * `scheduleOnUI(fn, ...args)` — real iOS schedules `fn` on the UI runtime. rngpui's
77
+ * UI runtime is the second JavaScriptCore runtime, so workletized callbacks dispatch there
78
+ * from the React runtime. plain callbacks (not serializable worklets) and the no-
79
+ * bridge path keep the local microtask behavior.
80
+ */
81
+ export declare function scheduleOnUI<T extends (...args: unknown[]) => unknown>(fn: T, ...args: unknown[]): void;
82
+ /**
83
+ * Invoke a GestureDetector lifecycle callback respecting RN's worklet / non-worklet
84
+ * runtime split. a callback that IS a worklet runs on the UI runtime — the same
85
+ * runtime as the `useAnimatedStyle` mapper and the `withTiming`/`withSpring` driver —
86
+ * so a shared value's `valueSetter` animation lifecycle stays coherent.
87
+ *
88
+ * the `gesture` carries RNGH's `runOnJS` flag. a callback is dispatched to the UI
89
+ * runtime ONLY when it is a worklet AND the gesture did not opt into `runOnJS(true)`.
90
+ * a `runOnJS(true)` gesture (e.g. tamagui's press gesture, whose onBegin/onEnd are
91
+ * babel-workletized yet mutate React state) must run on the React runtime. a
92
+ * non-worklet callback — and every callback when the bridge is absent — runs
93
+ * synchronously on the React runtime as before.
94
+ */
95
+ export declare function invokeGestureCallback(cb: ((...a: any[]) => unknown) | null | undefined, gesture: {
96
+ _runOnJS?: boolean;
97
+ } | null | undefined, ...args: unknown[]): void;
98
+ /**
99
+ * Sync UI execution is not feasible across runtimes (a blocking wait on the React
100
+ * runtime would freeze the bundle). Best-effort: identity. Upstream only uses
101
+ * executeOnUIRuntimeSync for init-time reads — apps that genuinely need synchronous
102
+ * UI-runtime semantics will see local/stale state, which is acceptable for those
103
+ * bootstrap reads.
104
+ */
105
+ export declare function executeOnUIRuntimeSync<T extends (...args: unknown[]) => unknown>(fn: T): T;
106
+ /** Sync runOnUI — runs LOCALLY on the React runtime. cross-runtime sync is impossible;
107
+ * upstream only uses this for init-time reads. set `this = fn` so the babel-emitted
108
+ * `this.__closure.X` and `this._recur` references inside worklet bodies resolve. */
109
+ export declare function runOnUISync<T extends (...args: unknown[]) => unknown>(fn: T, ...args: unknown[]): unknown;
110
+ export declare function runOnUIAsync<T extends (...args: unknown[]) => unknown>(fn: T, ...args: unknown[]): Promise<unknown>;
111
+ export declare function makeShareable<T>(value: T): T;
112
+ export declare function createSerializable(config: {
113
+ __init?: () => unknown;
114
+ }): unknown;
115
+ export declare function createSynchronizable<T>(initial: T): Synchronizable<T>;
116
+ export declare const serializableMappingCache: WeakMap<object, unknown>;
117
+ export declare function isWorkletFunction(fn: unknown): fn is WorkletFunction;
118
+ export declare function createWorkletRuntime(name: string, _initializer?: () => void): unknown;
119
+ export declare function callMicrotasks(): void;
120
+ export declare const WorkletsModule: IWorkletsModule;
121
+ export declare function useWorklet<T>(fn: T, _deps?: unknown[]): T;
122
+ export declare function createWorklet<T extends (...args: unknown[]) => unknown>(fn: T): T;
123
+ export declare class WorkletRuntimeClass {
124
+ name: string;
125
+ constructor(name?: string);
126
+ run<T>(fn: () => T): T;
127
+ destroy(): void;
128
+ }
129
+ export declare const Worklets: {
130
+ defaultContext: {
131
+ name: string;
132
+ };
133
+ createContext(name?: string): {
134
+ name: string;
135
+ };
136
+ createRuntime(name?: string, _initializer?: () => void): WorkletRuntimeClass;
137
+ createSharedValue<T>(initial: T): {
138
+ value: T;
139
+ };
140
+ };
141
+ export declare function currentContext(): {
142
+ name: string;
143
+ };
144
+ export declare const shareableMappingCache: WeakMap<object, unknown>;
145
+ export declare function makeShareableCloneRecursive(value: unknown): unknown;
146
+ export declare function makeShareableCloneOnUIRecursive(value: unknown): unknown;
147
+ export declare function isShareableRef(_value: unknown): boolean;
148
+ export declare const isSerializableRef: typeof isShareableRef;
149
+ export declare function getRuntimeKind(): RuntimeKind;
150
+ export declare function scheduleOnRuntime(_runtime: unknown, fn: WorkletFunction, ...args: unknown[]): void;
151
+ export declare function isRNRuntime(): boolean;
152
+ export declare function isUIRuntime(): boolean;
153
+ export declare function isWorkerRuntime(): boolean;
154
+ export declare function isWorkletRuntime(): boolean;
155
+ export declare function runOnRuntimeAsync<T extends (...args: unknown[]) => unknown>(runtime: unknown, fn: T): T;
156
+ export declare function runOnRuntimeSyncWithId<T extends (...args: unknown[]) => unknown>(_runtimeId: number, fn: T, ...args: unknown[]): unknown;
157
+ export declare function scheduleOnRuntimeWithId(_runtimeId: number, fn: WorkletFunction, ...args: unknown[]): void;
158
+ export declare function isShareable(value: unknown): boolean;
159
+ export declare function isSynchronizable(value: unknown): boolean;
160
+ export declare function registerCustomSerializable(klass: unknown, serializer: unknown): void;
161
+ export declare function getStaticFeatureFlag(_name: string): boolean;
162
+ export declare function getDynamicFeatureFlag(_name: string): boolean;
163
+ export declare function setDynamicFeatureFlag(_name: string, _value: boolean): void;
164
+ export declare function toggleSlowAnimationsOnUIRuntime(): boolean;
165
+ declare const _default: {
166
+ runOnJS: typeof runOnJS;
167
+ runOnUI: typeof runOnUI;
168
+ runOnRuntime: typeof runOnRuntime;
169
+ scheduleOnRN: typeof scheduleOnRN;
170
+ scheduleOnUI: typeof scheduleOnUI;
171
+ makeShareable: typeof makeShareable;
172
+ createSerializable: typeof createSerializable;
173
+ createSynchronizable: typeof createSynchronizable;
174
+ serializableMappingCache: WeakMap<object, unknown>;
175
+ isWorkletFunction: typeof isWorkletFunction;
176
+ executeOnUIRuntimeSync: typeof executeOnUIRuntimeSync;
177
+ createWorkletRuntime: typeof createWorkletRuntime;
178
+ callMicrotasks: typeof callMicrotasks;
179
+ WorkletsModule: IWorkletsModule;
180
+ RuntimeKind: typeof RuntimeKind;
181
+ useWorklet: typeof useWorklet;
182
+ createWorklet: typeof createWorklet;
183
+ WorkletRuntime: typeof WorkletRuntimeClass;
184
+ Worklets: {
185
+ defaultContext: {
186
+ name: string;
187
+ };
188
+ createContext(name?: string): {
189
+ name: string;
190
+ };
191
+ createRuntime(name?: string, _initializer?: () => void): WorkletRuntimeClass;
192
+ createSharedValue<T>(initial: T): {
193
+ value: T;
194
+ };
195
+ };
196
+ currentContext: typeof currentContext;
197
+ };
198
+ export default _default;
199
+ export type { WorkletRuntimeInstance };