@onlynative/inertia 0.0.1-alpha.7 → 0.0.1-alpha.9

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/README.md +1 -1
  2. package/dist/gestureLayer/index.d.mts +119 -0
  3. package/dist/gestureLayer/index.d.ts +119 -0
  4. package/dist/gestureLayer/index.js +346 -0
  5. package/dist/gestureLayer/index.js.map +1 -0
  6. package/dist/gestureLayer/index.mjs +344 -0
  7. package/dist/gestureLayer/index.mjs.map +1 -0
  8. package/dist/index.d.mts +114 -74
  9. package/dist/index.d.ts +114 -74
  10. package/dist/index.js +388 -1542
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +388 -1545
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/motion/Image.d.mts +1 -1
  15. package/dist/motion/Image.d.ts +1 -1
  16. package/dist/motion/Image.js +244 -1462
  17. package/dist/motion/Image.js.map +1 -1
  18. package/dist/motion/Image.mjs +247 -1465
  19. package/dist/motion/Image.mjs.map +1 -1
  20. package/dist/motion/Pressable.d.mts +1 -1
  21. package/dist/motion/Pressable.d.ts +1 -1
  22. package/dist/motion/Pressable.js +244 -1462
  23. package/dist/motion/Pressable.js.map +1 -1
  24. package/dist/motion/Pressable.mjs +247 -1465
  25. package/dist/motion/Pressable.mjs.map +1 -1
  26. package/dist/motion/ScrollView.d.mts +1 -1
  27. package/dist/motion/ScrollView.d.ts +1 -1
  28. package/dist/motion/ScrollView.js +244 -1462
  29. package/dist/motion/ScrollView.js.map +1 -1
  30. package/dist/motion/ScrollView.mjs +247 -1465
  31. package/dist/motion/ScrollView.mjs.map +1 -1
  32. package/dist/motion/Text.d.mts +1 -1
  33. package/dist/motion/Text.d.ts +1 -1
  34. package/dist/motion/Text.js +244 -1462
  35. package/dist/motion/Text.js.map +1 -1
  36. package/dist/motion/Text.mjs +247 -1465
  37. package/dist/motion/Text.mjs.map +1 -1
  38. package/dist/motion/View.d.mts +1 -1
  39. package/dist/motion/View.d.ts +1 -1
  40. package/dist/motion/View.js +244 -1462
  41. package/dist/motion/View.js.map +1 -1
  42. package/dist/motion/View.mjs +247 -1465
  43. package/dist/motion/View.mjs.map +1 -1
  44. package/dist/touch/index.d.mts +146 -0
  45. package/dist/touch/index.d.ts +146 -0
  46. package/dist/touch/index.js +166 -0
  47. package/dist/touch/index.js.map +1 -0
  48. package/dist/touch/index.mjs +164 -0
  49. package/dist/touch/index.mjs.map +1 -0
  50. package/dist/{types-NmNeJjo1.d.mts → types-cU43dEmH.d.mts} +64 -17
  51. package/dist/{types-NmNeJjo1.d.ts → types-cU43dEmH.d.ts} +64 -17
  52. package/dist/useGesture-B7A_1DVg.d.ts +84 -0
  53. package/dist/useGesture-cimMrzC1.d.mts +84 -0
  54. package/jest-setup.js +4 -0
  55. package/llms.txt +12 -3
  56. package/package.json +22 -2
  57. package/src/__type-tests__/variants.test-d.tsx +67 -0
  58. package/src/gestureLayer/index.ts +21 -0
  59. package/src/gestureLayer/useGestureLayer.ts +285 -0
  60. package/src/index.ts +7 -0
  61. package/src/layout/index.ts +15 -0
  62. package/src/layout/sharedRegistry.ts +111 -0
  63. package/src/layout/useSharedLayout.ts +289 -0
  64. package/src/motion/createMotionComponent.tsx +123 -37
  65. package/src/motion/installCheck.ts +7 -11
  66. package/src/touch/index.ts +18 -0
  67. package/src/touch/useTouchDrag.ts +289 -0
  68. package/src/types.ts +79 -20
  69. package/src/values/index.ts +11 -0
  70. package/src/values/useBooleanSpring.ts +33 -0
  71. package/src/values/useColorTransition.ts +72 -0
  72. package/src/values/useShadow.ts +116 -0
package/dist/index.mjs CHANGED
@@ -1,1458 +1,59 @@
1
- import { Platform, TurboModuleRegistry, Image, Pressable, ScrollView, Text, View } from 'react-native';
2
- import { createContext, forwardRef, useRef, useState, useEffect, useMemo, useContext, Children, isValidElement, useCallback } from 'react';
3
- import Animated, { useSharedValue, useAnimatedStyle, interpolateColor, useReducedMotion, withSequence, LinearTransition, runOnJS as runOnJS$1, withRepeat, withDelay, withDecay, withTiming, Easing, withSpring, useAnimatedReaction, useDerivedValue, Extrapolation, useAnimatedScrollHandler, interpolate } from 'react-native-reanimated';
1
+ import { Image, Pressable, ScrollView, Text, View, Platform } from 'react-native';
2
+ import { createContext, forwardRef, useRef, useState, useEffect, useMemo, useContext, useCallback, Children, isValidElement } from 'react';
3
+ import Animated, { useSharedValue, useAnimatedStyle, interpolateColor, reanimatedVersion, useReducedMotion, withSequence, LinearTransition, runOnJS, withRepeat, withTiming, withSpring, withDelay, withDecay, Easing, useAnimatedReaction, useDerivedValue, Extrapolation, useAnimatedScrollHandler, interpolate } from 'react-native-reanimated';
4
4
  import { jsx, Fragment } from 'react/jsx-runtime';
5
+ import { isWorkletFunction } from 'react-native-worklets';
5
6
 
6
- var __typeError = (msg) => {
7
- throw TypeError(msg);
8
- };
9
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
- }) : x)(function(x) {
12
- if (typeof require !== "undefined") return require.apply(this, arguments);
13
- throw Error('Dynamic require of "' + x + '" is not supported');
14
- });
15
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
16
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
17
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
18
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
19
- var DEFAULT_MOTION_CONFIG = {
20
- reducedMotion: "user"
21
- };
22
- var MotionConfigContext = createContext(
23
- DEFAULT_MOTION_CONFIG
24
- );
25
- function useMotionConfig() {
26
- return useContext(MotionConfigContext);
27
- }
28
- function useShouldReduceMotion() {
29
- const { reducedMotion } = useMotionConfig();
30
- const osReduced = useReducedMotion();
31
- if (reducedMotion === "never") return false;
32
- if (reducedMotion === "always") return true;
33
- return osReduced;
34
- }
35
- function MotionConfig({
36
- reducedMotion = "user",
37
- children
38
- }) {
39
- const value = useMemo(
40
- () => ({ reducedMotion }),
41
- [reducedMotion]
42
- );
43
- return /* @__PURE__ */ jsx(MotionConfigContext.Provider, { value, children });
44
- }
45
- var modality = "keyboard";
46
- var installed = false;
47
- function setKeyboard() {
48
- modality = "keyboard";
49
- }
50
- function setPointer() {
51
- modality = "pointer";
52
- }
53
- function ensureInstalled() {
54
- if (installed) return;
55
- if (Platform.OS !== "web") return;
56
- if (typeof document === "undefined") return;
57
- document.addEventListener("keydown", setKeyboard, true);
58
- document.addEventListener("mousedown", setPointer, true);
59
- document.addEventListener("pointerdown", setPointer, true);
60
- document.addEventListener("touchstart", setPointer, true);
61
- installed = true;
62
- }
63
- function isFocusVisible() {
64
- if (Platform.OS !== "web") return true;
65
- ensureInstalled();
66
- return modality === "keyboard";
67
- }
68
-
69
- // ../../node_modules/react-native-worklets/lib/module/logger.js
70
- var PREFIX = "[Worklets]";
71
- function formatMessage(message) {
72
- return `${PREFIX} ${message}`;
73
- }
74
- var logger = {
75
- warn(message) {
76
- console.warn(formatMessage(message));
77
- },
78
- error(message) {
79
- console.error(formatMessage(message));
80
- }
81
- };
82
-
83
- // ../../node_modules/react-native-worklets/lib/module/runtimeKind.js
84
- var RuntimeKind = /* @__PURE__ */ (function(RuntimeKind2) {
85
- RuntimeKind2[RuntimeKind2["ReactNative"] = 1] = "ReactNative";
86
- RuntimeKind2[RuntimeKind2["UI"] = 2] = "UI";
87
- RuntimeKind2[RuntimeKind2["Worker"] = 3] = "Worker";
88
- return RuntimeKind2;
89
- })({});
90
- if (globalThis.__RUNTIME_KIND === void 0) {
91
- globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
92
- }
93
-
94
- // ../../node_modules/react-native-worklets/lib/module/WorkletsError.js
95
- function WorkletsErrorConstructor(message) {
96
- "worklet";
97
- const prefix = "[Worklets]";
98
- const errorInstance = new Error(message ? `${prefix} ${message}` : prefix);
99
- errorInstance.name = `WorkletsError`;
100
- return errorInstance;
101
- }
102
- function registerWorkletsError() {
103
- "worklet";
104
- if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
105
- globalThis.WorkletsError = WorkletsErrorConstructor;
106
- }
107
- }
108
- var WorkletsError = WorkletsErrorConstructor;
109
-
110
- // ../../node_modules/react-native-worklets/lib/module/bundleUnpacker.js
111
- var handleCache = /* @__PURE__ */ new WeakMap();
112
- function bundleValueUnpacker(objectToUnpack, category, remoteFunctionName) {
113
- const workletHash = objectToUnpack.__workletHash;
114
- if (workletHash !== void 0) {
115
- return getWorklet(workletHash, objectToUnpack.__closure);
116
- } else if (objectToUnpack.__init !== void 0) {
117
- let value = handleCache.get(objectToUnpack);
118
- if (value === void 0) {
119
- value = objectToUnpack.__init();
120
- handleCache.set(objectToUnpack, value);
121
- }
122
- return value;
123
- } else if (category === "RemoteFunction") {
124
- const remoteFunctionHolder = () => {
125
- const label = remoteFunctionName ? `function \`${remoteFunctionName}\`` : "anonymous function";
126
- throw new WorkletsError(`Tried to synchronously call a non-worklet ${label} on the UI thread.
127
- See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-synchronously-call-a-non-worklet-function-on-the-ui-thread for more details.`);
128
- };
129
- remoteFunctionHolder.__remoteFunction = objectToUnpack;
130
- return remoteFunctionHolder;
131
- } else {
132
- throw new WorkletsError(`Data type in category "${category}" not recognized by value unpacker: "${globalThis._toString(objectToUnpack)}".`);
133
- }
134
- }
135
- function getWorklet(workletHash, closureVariables) {
136
- let worklet;
137
- if (__DEV__) {
138
- try {
139
- worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
140
- } catch (_e) {
141
- logger.error("Unable to resolve worklet with hash " + workletHash + ". Try reloading the app.");
142
- }
143
- } else {
144
- worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
145
- }
146
- return worklet;
147
- }
148
- var metroRequire = globalThis.__r;
149
- function getWorkletFromMetroRequire(workletHash, closureVariables) {
150
- const factory = metroRequire(workletHash).default;
151
- return factory(closureVariables);
152
- }
153
-
154
- // ../../node_modules/react-native-worklets/lib/module/callGuard.js
155
- function callGuardDEV(fn, ...args) {
156
- "worklet";
157
- try {
158
- return fn(...args);
159
- } catch (error) {
160
- if (globalThis.__workletsModuleProxy) {
161
- const {
162
- message,
163
- stack,
164
- name,
165
- jsEngine
166
- } = error;
167
- globalThis.__workletsModuleProxy.reportFatalErrorOnJS(message, stack ?? "", name ?? "WorkletsError", jsEngine ?? "Worklets");
168
- } else {
169
- throw error;
170
- }
171
- }
172
- }
173
- function setupCallGuard() {
174
- "worklet";
175
- if (!globalThis.__callGuardDEV) {
176
- globalThis.__callGuardDEV = callGuardDEV;
177
- }
178
- }
179
-
180
- // ../../node_modules/react-native-worklets/lib/module/errors.js
181
- var _workletStackDetails = /* @__PURE__ */ new Map();
182
- function registerWorkletStackDetails(hash, stackDetails) {
183
- _workletStackDetails.set(hash, stackDetails);
184
- }
185
- function getBundleOffset(error) {
186
- const frame = error.stack?.split("\n")?.[0];
187
- if (frame) {
188
- const parsedFrame = /@([^@]+):(\d+):(\d+)/.exec(frame);
189
- if (parsedFrame) {
190
- const [, file, line, col] = parsedFrame;
191
- return [file, Number(line), Number(col)];
192
- }
193
- }
194
- return ["unknown", 0, 0];
195
- }
196
- function processStack(stack) {
197
- if (stack === "" || stack === void 0) {
198
- return void 0;
199
- }
200
- const workletStackEntries = stack.match(/worklet_(\d+):(\d+):(\d+)/g);
201
- let result = stack;
202
- workletStackEntries?.forEach((match) => {
203
- const [, hash, origLine, origCol] = match.split(/:|_/).map(Number);
204
- const errorDetails = _workletStackDetails.get(hash);
205
- if (!errorDetails) {
206
- return;
207
- }
208
- const [error, lineOffset, colOffset] = errorDetails;
209
- const [bundleFile, bundleLine, bundleCol] = getBundleOffset(error);
210
- const line = origLine + bundleLine + lineOffset;
211
- const col = origCol + bundleCol + colOffset;
212
- result = result.replace(match, `${bundleFile}:${line}:${col}`);
213
- });
214
- return result;
215
- }
216
- function reportFatalRemoteError({
217
- message,
218
- stack,
219
- name,
220
- jsEngine
221
- }, force) {
222
- const error = new WorkletsError();
223
- error.message = message;
224
- error.stack = processStack(stack);
225
- error.name = name;
226
- error.jsEngine = jsEngine;
227
- if (force) {
228
- throw error;
229
- } else {
230
- globalThis.ErrorUtils.reportFatalError(error);
231
- }
232
- }
233
- function registerReportFatalRemoteError() {
234
- globalThis.__reportFatalRemoteError = reportFatalRemoteError;
235
- }
236
- var IS_JEST = !!process.env.JEST_WORKER_ID;
237
- var IS_WEB = Platform.OS === "web";
238
- var IS_WINDOWS = Platform.OS === "windows";
239
- var SHOULD_BE_USE_WEB = IS_JEST || IS_WEB || IS_WINDOWS;
240
-
241
- // ../../node_modules/react-native-worklets/lib/module/PlatformChecker/index.js
242
- var IS_JEST2 = false;
243
- var SHOULD_BE_USE_WEB2 = false;
244
- if (globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
245
- IS_JEST2 = IS_JEST;
246
- SHOULD_BE_USE_WEB2 = SHOULD_BE_USE_WEB;
247
- }
248
-
249
- // ../../node_modules/react-native-worklets/lib/module/runLoop/common/setImmediatePolyfill.js
250
- function setupSetImmediate() {
251
- "worklet";
252
- const setImmediatePolyfill = (callback, ...args) => {
253
- return setTimeout(callback, 0, ...args);
254
- };
255
- const clearImmediatePolyfill = (immediateHandle) => {
256
- clearTimeout(immediateHandle);
257
- };
258
- globalThis.setImmediate = setImmediatePolyfill;
259
- globalThis.clearImmediate = clearImmediatePolyfill;
260
- }
261
-
262
- // ../../node_modules/react-native-worklets/lib/module/runLoop/common/setIntervalPolyfill.js
263
- function setupSetInterval() {
264
- "worklet";
265
- const intervalHandleToTimeoutHandle = /* @__PURE__ */ new Map();
266
- const setIntervalPolyfill = (callback, delay = 0, ...args) => {
267
- let intervalHandle = 0;
268
- const repeatingCallback = () => {
269
- const timeoutHandle = setTimeout(repeatingCallback, delay);
270
- intervalHandleToTimeoutHandle.set(intervalHandle, timeoutHandle);
271
- callback(...args);
272
- };
273
- intervalHandle = setTimeout(repeatingCallback, delay);
274
- intervalHandleToTimeoutHandle.set(intervalHandle, intervalHandle);
275
- return intervalHandle;
276
- };
277
- const clearIntervalPolyfill = (intervalHandle) => {
278
- const timeoutHandle = intervalHandleToTimeoutHandle.get(intervalHandle);
279
- clearTimeout(timeoutHandle);
280
- intervalHandleToTimeoutHandle.delete(intervalHandle);
281
- };
282
- globalThis.setInterval = setIntervalPolyfill;
283
- globalThis.clearInterval = clearIntervalPolyfill;
284
- }
285
-
286
- // ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js
287
- function mockedRequestAnimationFrame(callback) {
288
- return setTimeout(() => callback(performance.now()), 0);
289
- }
290
-
291
- // ../../node_modules/react-native-worklets/lib/module/isSynchronizable.js
292
- function isSynchronizable(value) {
293
- return typeof value === "object" && value !== null && "__synchronizableRef" in value && value.__synchronizableRef === true;
294
- }
295
-
296
- // ../../node_modules/react-native-worklets/lib/module/serializableMappingCache.js
297
- var serializableMappingFlag = /* @__PURE__ */ Symbol("serializable flag");
298
- var cache = SHOULD_BE_USE_WEB2 ? null : /* @__PURE__ */ new WeakMap();
299
- var serializableMappingCache = SHOULD_BE_USE_WEB2 ? {
300
- set() {
301
- },
302
- get() {
303
- return null;
304
- }
305
- } : {
306
- set(serializable, serializableRef) {
307
- cache.set(serializable, serializableRef || serializableMappingFlag);
308
- },
309
- get: cache.get.bind(cache)
310
- };
311
-
312
- // ../../node_modules/react-native-worklets/lib/module/utils/jsVersion.js
313
- var jsVersion = "0.5.1";
314
-
315
- // ../../node_modules/react-native-worklets/lib/module/workletFunction.js
316
- function isWorkletFunction(value) {
317
- "worklet";
318
- return (
319
- // `__workletHash` isn't extracted in Worklet Runtimes.
320
- typeof value === "function" && !!value.__workletHash
321
- );
322
- }
323
-
324
- // ../../node_modules/react-native-worklets/lib/module/WorkletsModule/JSWorklets.js
325
- function createJSWorkletsModule() {
326
- return new JSWorklets();
327
- }
328
- var requestAnimationFrameImpl = IS_JEST2 || !globalThis.requestAnimationFrame ? mockedRequestAnimationFrame : globalThis.requestAnimationFrame;
329
- var JSWorklets = class {
330
- createSerializable() {
331
- throw new WorkletsError("createSerializable should never be called in JSWorklets.");
332
- }
333
- createSerializableString() {
334
- throw new WorkletsError("createSerializableString should never be called in JSWorklets.");
335
- }
336
- createSerializableNumber() {
337
- throw new WorkletsError("createSerializableNumber should never be called in JSWorklets.");
338
- }
339
- createSerializableBoolean() {
340
- throw new WorkletsError("createSerializableBoolean should never be called in JSWorklets.");
341
- }
342
- createSerializableBigInt() {
343
- throw new WorkletsError("createSerializableBigInt should never be called in JSWorklets.");
344
- }
345
- createSerializableUndefined() {
346
- throw new WorkletsError("createSerializableUndefined should never be called in JSWorklets.");
347
- }
348
- createSerializableNull() {
349
- throw new WorkletsError("createSerializableNull should never be called in JSWorklets.");
350
- }
351
- createSerializableTurboModuleLike() {
352
- throw new WorkletsError("createSerializableTurboModuleLike should never be called in JSWorklets.");
353
- }
354
- createSerializableObject() {
355
- throw new WorkletsError("createSerializableObject should never be called in JSWorklets.");
356
- }
357
- createSerializableMap() {
358
- throw new WorkletsError("createSerializableMap should never be called in JSWorklets.");
359
- }
360
- createSerializableSet() {
361
- throw new WorkletsError("createSerializableSet should never be called in JSWorklets.");
362
- }
363
- createSerializableImport() {
364
- throw new WorkletsError("createSerializableImport should never be called in JSWorklets.");
365
- }
366
- createSerializableHostObject() {
367
- throw new WorkletsError("createSerializableHostObject should never be called in JSWorklets.");
368
- }
369
- createSerializableArray() {
370
- throw new WorkletsError("createSerializableArray should never be called in JSWorklets.");
371
- }
372
- createSerializableInitializer() {
373
- throw new WorkletsError("createSerializableInitializer should never be called in JSWorklets.");
374
- }
375
- createSerializableFunction() {
376
- throw new WorkletsError("createSerializableFunction should never be called in JSWorklets.");
377
- }
378
- createSerializableWorklet() {
379
- throw new WorkletsError("createSerializableWorklet should never be called in JSWorklets.");
380
- }
381
- scheduleOnUI(worklet) {
382
- requestAnimationFrameImpl(worklet);
383
- }
384
- executeOnUIRuntimeSync() {
385
- throw new WorkletsError("`executeOnUIRuntimeSync` is not available in JSWorklets.");
386
- }
387
- createWorkletRuntime() {
388
- throw new WorkletsError("createWorkletRuntime is not available in JSWorklets.");
389
- }
390
- scheduleOnRuntime() {
391
- throw new WorkletsError("scheduleOnRuntime is not available in JSWorklets.");
392
- }
393
- createSynchronizable() {
394
- throw new WorkletsError("createSynchronizable should never be called in JSWorklets.");
395
- }
396
- synchronizableGetDirty() {
397
- throw new WorkletsError("synchronizableGetDirty should never be called in JSWorklets.");
398
- }
399
- synchronizableGetBlocking() {
400
- throw new WorkletsError("synchronizableGetBlocking should never be called in JSWorklets.");
401
- }
402
- synchronizableSetBlocking() {
403
- throw new WorkletsError("synchronizableSetBlocking should never be called in JSWorklets.");
404
- }
405
- synchronizableLock() {
406
- throw new WorkletsError("synchronizableLock should never be called in JSWorklets.");
407
- }
408
- synchronizableUnlock() {
409
- throw new WorkletsError("synchronizableUnlock should never be called in JSWorklets.");
410
- }
411
- reportFatalErrorOnJS() {
412
- throw new WorkletsError("reportFatalErrorOnJS should never be called in JSWorklets.");
413
- }
414
- getStaticFeatureFlag() {
415
- return false;
416
- }
417
- setDynamicFeatureFlag() {
418
- }
419
- };
420
- var NativeWorkletsModule_default = TurboModuleRegistry.get("WorkletsModule");
421
-
422
- // ../../node_modules/react-native-worklets/lib/module/specs/index.js
423
- var WorkletsTurboModule = globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative ? NativeWorkletsModule_default : (
424
- // In Bundle Mode, on Worklet Runtimes `RNWorkletsTurboModule` isn't
425
- // available and shouldn't be accessed. We return null here
426
- // to keep the same codebase for the Bundle Mode and legacy behavior.
427
- null
428
- );
429
-
430
- // ../../node_modules/react-native-worklets/lib/module/utils/checkCppVersion.js
431
- function checkCppVersion() {
432
- const cppVersion = global._WORKLETS_VERSION_CPP;
433
- if (cppVersion === void 0) {
434
- logger.warn(`Couldn't determine the version of the native part of Worklets.
435
- See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#couldnt-determine-the-version-of-the-native-part-of-worklets\` for more details.`);
436
- return;
437
- }
438
- const ok = matchVersion(jsVersion, cppVersion);
439
- if (!ok) {
440
- throw new WorkletsError(`Mismatch between JavaScript part and native part of Worklets (${jsVersion} vs ${cppVersion}).
441
- See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-part-and-native-part-of-worklets\` for more details.`);
442
- }
443
- }
444
- function matchVersion(version1, version2) {
445
- if (version1.match(/^\d+\.\d+\.\d+$/) && version2.match(/^\d+\.\d+\.\d+$/)) {
446
- const [major1, minor1] = version1.split(".");
447
- const [major2, minor2] = version2.split(".");
448
- return major1 === major2 && minor1 === minor2;
449
- } else {
450
- return version1 === version2;
451
- }
452
- }
453
-
454
- // ../../node_modules/react-native-worklets/lib/module/WorkletsModule/NativeWorklets.js
455
- function createNativeWorkletsModule() {
456
- return new NativeWorklets();
457
- }
458
- var _workletsModuleProxy, _serializableUndefined, _serializableNull, _serializableTrue, _serializableFalse;
459
- var NativeWorklets = class {
460
- constructor() {
461
- __privateAdd(this, _workletsModuleProxy);
462
- __privateAdd(this, _serializableUndefined);
463
- __privateAdd(this, _serializableNull);
464
- __privateAdd(this, _serializableTrue);
465
- __privateAdd(this, _serializableFalse);
466
- globalThis._WORKLETS_VERSION_JS = jsVersion;
467
- if (global.__workletsModuleProxy === void 0 && globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
468
- WorkletsTurboModule?.installTurboModule();
469
- }
470
- if (global.__workletsModuleProxy === void 0) {
471
- throw new WorkletsError(`Native part of Worklets doesn't seem to be initialized.
472
- See https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#native-part-of-worklets-doesnt-seem-to-be-initialized for more details.`);
473
- }
474
- if (__DEV__) {
475
- checkCppVersion();
476
- }
477
- __privateSet(this, _workletsModuleProxy, global.__workletsModuleProxy);
478
- __privateSet(this, _serializableNull, __privateGet(this, _workletsModuleProxy).createSerializableNull());
479
- __privateSet(this, _serializableUndefined, __privateGet(this, _workletsModuleProxy).createSerializableUndefined());
480
- __privateSet(this, _serializableTrue, __privateGet(this, _workletsModuleProxy).createSerializableBoolean(true));
481
- __privateSet(this, _serializableFalse, __privateGet(this, _workletsModuleProxy).createSerializableBoolean(false));
482
- }
483
- createSerializable(value, shouldPersistRemote, nativeStateSource) {
484
- return __privateGet(this, _workletsModuleProxy).createSerializable(value, shouldPersistRemote, nativeStateSource);
485
- }
486
- createSerializableImport(from, to) {
487
- return __privateGet(this, _workletsModuleProxy).createSerializableImport(from, to);
488
- }
489
- createSerializableString(str) {
490
- return __privateGet(this, _workletsModuleProxy).createSerializableString(str);
491
- }
492
- createSerializableNumber(num) {
493
- return __privateGet(this, _workletsModuleProxy).createSerializableNumber(num);
494
- }
495
- createSerializableBoolean(bool) {
496
- return bool ? __privateGet(this, _serializableTrue) : __privateGet(this, _serializableFalse);
497
- }
498
- createSerializableBigInt(bigInt) {
499
- return __privateGet(this, _workletsModuleProxy).createSerializableBigInt(bigInt);
500
- }
501
- createSerializableUndefined() {
502
- return __privateGet(this, _serializableUndefined);
503
- }
504
- createSerializableNull() {
505
- return __privateGet(this, _serializableNull);
506
- }
507
- createSerializableTurboModuleLike(props, proto) {
508
- return __privateGet(this, _workletsModuleProxy).createSerializableTurboModuleLike(props, proto);
509
- }
510
- createSerializableObject(obj, shouldRetainRemote, nativeStateSource) {
511
- return __privateGet(this, _workletsModuleProxy).createSerializableObject(obj, shouldRetainRemote, nativeStateSource);
512
- }
513
- createSerializableHostObject(obj) {
514
- return __privateGet(this, _workletsModuleProxy).createSerializableHostObject(obj);
515
- }
516
- createSerializableArray(array, shouldRetainRemote) {
517
- return __privateGet(this, _workletsModuleProxy).createSerializableArray(array, shouldRetainRemote);
518
- }
519
- createSerializableMap(keys, values) {
520
- return __privateGet(this, _workletsModuleProxy).createSerializableMap(keys, values);
521
- }
522
- createSerializableSet(values) {
523
- return __privateGet(this, _workletsModuleProxy).createSerializableSet(values);
524
- }
525
- createSerializableInitializer(obj) {
526
- return __privateGet(this, _workletsModuleProxy).createSerializableInitializer(obj);
527
- }
528
- createSerializableFunction(func) {
529
- return __privateGet(this, _workletsModuleProxy).createSerializableFunction(func);
530
- }
531
- createSerializableWorklet(worklet, shouldPersistRemote) {
532
- return __privateGet(this, _workletsModuleProxy).createSerializableWorklet(worklet, shouldPersistRemote);
533
- }
534
- scheduleOnUI(serializable) {
535
- return __privateGet(this, _workletsModuleProxy).scheduleOnUI(serializable);
536
- }
537
- executeOnUIRuntimeSync(serializable) {
538
- return __privateGet(this, _workletsModuleProxy).executeOnUIRuntimeSync(serializable);
539
- }
540
- createWorkletRuntime(name, initializer, useDefaultQueue, customQueue, enableEventLoop) {
541
- return __privateGet(this, _workletsModuleProxy).createWorkletRuntime(name, initializer, useDefaultQueue, customQueue, enableEventLoop);
542
- }
543
- scheduleOnRuntime(workletRuntime, serializableWorklet) {
544
- return __privateGet(this, _workletsModuleProxy).scheduleOnRuntime(workletRuntime, serializableWorklet);
545
- }
546
- createSynchronizable(value) {
547
- return __privateGet(this, _workletsModuleProxy).createSynchronizable(value);
548
- }
549
- synchronizableGetDirty(synchronizableRef) {
550
- return __privateGet(this, _workletsModuleProxy).synchronizableGetDirty(synchronizableRef);
551
- }
552
- synchronizableGetBlocking(synchronizableRef) {
553
- return __privateGet(this, _workletsModuleProxy).synchronizableGetBlocking(synchronizableRef);
554
- }
555
- synchronizableSetBlocking(synchronizableRef, value) {
556
- return __privateGet(this, _workletsModuleProxy).synchronizableSetBlocking(synchronizableRef, value);
557
- }
558
- synchronizableLock(synchronizableRef) {
559
- return __privateGet(this, _workletsModuleProxy).synchronizableLock(synchronizableRef);
560
- }
561
- synchronizableUnlock(synchronizableRef) {
562
- return __privateGet(this, _workletsModuleProxy).synchronizableUnlock(synchronizableRef);
563
- }
564
- reportFatalErrorOnJS(message, stack, name, jsEngine) {
565
- return __privateGet(this, _workletsModuleProxy).reportFatalErrorOnJS(message, stack, name, jsEngine);
566
- }
567
- getStaticFeatureFlag(name) {
568
- return __privateGet(this, _workletsModuleProxy).getStaticFeatureFlag(name);
569
- }
570
- setDynamicFeatureFlag(name, value) {
571
- __privateGet(this, _workletsModuleProxy).setDynamicFeatureFlag(name, value);
572
- }
573
- };
574
- _workletsModuleProxy = new WeakMap();
575
- _serializableUndefined = new WeakMap();
576
- _serializableNull = new WeakMap();
577
- _serializableTrue = new WeakMap();
578
- _serializableFalse = new WeakMap();
579
-
580
- // ../../node_modules/react-native-worklets/lib/module/WorkletsModule/workletsModuleInstance.js
581
- var WorkletsModule = SHOULD_BE_USE_WEB2 ? createJSWorkletsModule() : createNativeWorkletsModule();
582
-
583
- // ../../node_modules/react-native-worklets/lib/module/serializable.js
584
- var MAGIC_KEY = "REANIMATED_MAGIC_KEY";
585
- function isHostObject(value) {
586
- "worklet";
587
- return MAGIC_KEY in value;
588
- }
589
- function isPlainJSObject(object) {
590
- "worklet";
591
- return Object.getPrototypeOf(object) === Object.prototype;
592
- }
593
- function isTurboModuleLike(object) {
594
- return isHostObject(Object.getPrototypeOf(object));
595
- }
596
- function getFromCache(value) {
597
- const cached = serializableMappingCache.get(value);
598
- if (cached === serializableMappingFlag) {
599
- return value;
600
- }
601
- return cached;
602
- }
603
- var INACCESSIBLE_OBJECT = {
604
- __init: () => {
605
- "worklet";
606
- return new Proxy({}, {
607
- get: (_, prop) => {
608
- if (prop === "_isReanimatedSharedValue" || prop === "__remoteFunction") {
609
- return false;
610
- }
611
- throw new WorkletsError(`Trying to access property \`${String(prop)}\` of an object which cannot be sent to the UI runtime.`);
612
- },
613
- set: () => {
614
- throw new WorkletsError("Trying to write to an object which cannot be sent to the UI runtime.");
615
- }
616
- });
617
- }
618
- };
619
- var VALID_ARRAY_VIEWS_NAMES = ["Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array", "DataView"];
620
- var DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD = 30;
621
- var processedObjectAtThresholdDepth;
622
- function createSerializableWeb(value) {
623
- return value;
624
- }
625
- function createSerializableNative(value, shouldPersistRemote = false, depth = 0) {
626
- detectCyclicObject(value, depth);
627
- const isObject = typeof value === "object";
628
- const isFunction = typeof value === "function";
629
- if (typeof value === "string") {
630
- return cloneString(value);
631
- }
632
- if (typeof value === "number") {
633
- return cloneNumber(value);
634
- }
635
- if (typeof value === "boolean") {
636
- return cloneBoolean(value);
637
- }
638
- if (typeof value === "bigint") {
639
- return cloneBigInt(value);
640
- }
641
- if (value === void 0) {
642
- return cloneUndefined();
643
- }
644
- if (value === null) {
645
- return cloneNull();
646
- }
647
- if (!isObject && !isFunction || value === null) {
648
- return clonePrimitive(value, shouldPersistRemote);
649
- }
650
- const cached = getFromCache(value);
651
- if (cached !== void 0) {
652
- return cached;
653
- }
654
- if (Array.isArray(value)) {
655
- return cloneArray(value, shouldPersistRemote, depth);
656
- }
657
- if (globalThis._WORKLETS_BUNDLE_MODE && isFunction && value.__bundleData) {
658
- return cloneImport(value);
659
- }
660
- if (isFunction && !isWorkletFunction(value)) {
661
- return cloneRemoteFunction(value);
662
- }
663
- if (isTurboModuleLike(value)) {
664
- return cloneTurboModuleLike(value, shouldPersistRemote, depth);
665
- }
666
- if (isHostObject(value)) {
667
- return cloneHostObject(value);
668
- }
669
- if (isPlainJSObject(value) && value.__init) {
670
- return cloneInitializer(value, shouldPersistRemote, depth);
671
- }
672
- if (isPlainJSObject(value) && value.__workletContextObjectFactory) {
673
- return cloneContextObject(value);
674
- }
675
- if ((isPlainJSObject(value) || isFunction) && isWorkletFunction(value)) {
676
- return cloneWorklet(value, shouldPersistRemote, depth);
677
- }
678
- if (isSynchronizable(value)) {
679
- return cloneSynchronizable(value);
680
- }
681
- if (isPlainJSObject(value) || isFunction) {
682
- return clonePlainJSObject(value, shouldPersistRemote, depth);
683
- }
684
- if (value instanceof Set) {
685
- return cloneSet(value);
686
- }
687
- if (value instanceof Map) {
688
- return cloneMap(value);
689
- }
690
- if (value instanceof RegExp) {
691
- return cloneRegExp(value);
692
- }
693
- if (value instanceof Error) {
694
- return cloneError(value);
695
- }
696
- if (value instanceof ArrayBuffer) {
697
- return cloneArrayBuffer(value, shouldPersistRemote);
698
- }
699
- if (ArrayBuffer.isView(value)) {
700
- return cloneArrayBufferView(value);
701
- }
702
- return inaccessibleObject(value);
703
- }
704
- if (globalThis._WORKLETS_BUNDLE_MODE) {
705
- createSerializableNative.__bundleData = {
706
- imported: "createSerializable",
707
- // @ts-expect-error resolveWeak is defined by Metro
708
- source: __require.resolveWeak("./index")
709
- };
710
- }
711
- var createSerializable = SHOULD_BE_USE_WEB2 ? createSerializableWeb : createSerializableNative;
712
- function detectCyclicObject(value, depth) {
713
- if (depth >= DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
714
- if (depth === DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
715
- processedObjectAtThresholdDepth = value;
716
- } else if (value === processedObjectAtThresholdDepth) {
717
- throw new WorkletsError("Trying to convert a cyclic object to a serializable. This is not supported.");
718
- }
719
- } else {
720
- processedObjectAtThresholdDepth = void 0;
721
- }
722
- }
723
- function clonePrimitive(value, shouldPersistRemote) {
724
- return WorkletsModule.createSerializable(value, shouldPersistRemote);
725
- }
726
- function cloneString(value) {
727
- return WorkletsModule.createSerializableString(value);
728
- }
729
- function cloneNumber(value) {
730
- return WorkletsModule.createSerializableNumber(value);
731
- }
732
- function cloneBoolean(value) {
733
- return WorkletsModule.createSerializableBoolean(value);
734
- }
735
- function cloneBigInt(value) {
736
- return WorkletsModule.createSerializableBigInt(value);
737
- }
738
- function cloneUndefined() {
739
- return WorkletsModule.createSerializableUndefined();
740
- }
741
- function cloneNull() {
742
- return WorkletsModule.createSerializableNull();
743
- }
744
- function cloneObjectProperties(value, shouldPersistRemote, depth) {
745
- const clonedProps = {};
746
- for (const [key, element] of Object.entries(value)) {
747
- if (key === "__initData" && clonedProps.__initData !== void 0) {
748
- continue;
749
- }
750
- clonedProps[key] = createSerializable(element, shouldPersistRemote, depth + 1);
751
- }
752
- return clonedProps;
753
- }
754
- function cloneInitializer(value, shouldPersistRemote = false, depth = 0) {
755
- const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
756
- return WorkletsModule.createSerializableInitializer(clonedProps);
757
- }
758
- function cloneArray(value, shouldPersistRemote, depth) {
759
- const clonedElements = value.map((element) => createSerializable(element, shouldPersistRemote, depth + 1));
760
- const clone = WorkletsModule.createSerializableArray(clonedElements, shouldPersistRemote);
761
- serializableMappingCache.set(value, clone);
762
- serializableMappingCache.set(clone);
763
- freezeObjectInDev(value);
764
- return clone;
765
- }
766
- function cloneRemoteFunction(value) {
767
- const clone = WorkletsModule.createSerializableFunction(value);
768
- serializableMappingCache.set(value, clone);
769
- serializableMappingCache.set(clone);
770
- freezeObjectInDev(value);
771
- return clone;
772
- }
773
- function cloneHostObject(value) {
774
- const clone = WorkletsModule.createSerializableHostObject(value);
775
- serializableMappingCache.set(value, clone);
776
- serializableMappingCache.set(clone);
777
- return clone;
778
- }
779
- function cloneWorklet(value, shouldPersistRemote, depth) {
780
- if (__DEV__) {
781
- const babelVersion = value.__pluginVersion;
782
- if (babelVersion !== void 0 && babelVersion !== jsVersion) {
783
- throw new WorkletsError(`Mismatch between JavaScript code version and Worklets Babel plugin version (${jsVersion} vs. ${babelVersion}).
784
- See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-code-version-and-worklets-babel-plugin-version\` for more details.
785
- Offending code was: \`${getWorkletCode(value)}\``);
786
- }
787
- registerWorkletStackDetails(value.__workletHash, value.__stackDetails);
788
- }
789
- if (value.__stackDetails) {
790
- delete value.__stackDetails;
791
- }
792
- const clonedProps = cloneObjectProperties(value, true, depth);
793
- clonedProps.__initData = createSerializable(value.__initData, true, depth + 1);
794
- const clone = WorkletsModule.createSerializableWorklet(
795
- clonedProps,
796
- // TODO: Check after refactor if we can remove shouldPersistRemote parameter (imho it's redundant here since worklets are always persistent)
797
- // retain all worklets
798
- true
799
- );
800
- serializableMappingCache.set(value, clone);
801
- serializableMappingCache.set(clone);
802
- freezeObjectInDev(value);
803
- return clone;
804
- }
805
- function cloneTurboModuleLike(value, shouldPersistRemote, depth) {
806
- const proto = Object.getPrototypeOf(value);
807
- const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
808
- const clone = WorkletsModule.createSerializableTurboModuleLike(clonedProps, proto);
809
- return clone;
810
- }
811
- function cloneContextObject(value) {
812
- const workletContextObjectFactory = value.__workletContextObjectFactory;
813
- const handle = cloneInitializer({
814
- __init: () => {
815
- "worklet";
816
- return workletContextObjectFactory();
817
- }
818
- });
819
- serializableMappingCache.set(value, handle);
820
- return handle;
821
- }
822
- function clonePlainJSObject(value, shouldPersistRemote, depth) {
823
- const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
824
- const clone = WorkletsModule.createSerializableObject(clonedProps, shouldPersistRemote, value);
825
- serializableMappingCache.set(value, clone);
826
- serializableMappingCache.set(clone);
827
- freezeObjectInDev(value);
828
- return clone;
829
- }
830
- function cloneMap(value) {
831
- const clonedKeys = [];
832
- const clonedValues = [];
833
- for (const [key, element] of value.entries()) {
834
- clonedKeys.push(createSerializable(key));
835
- clonedValues.push(createSerializable(element));
836
- }
837
- const clone = WorkletsModule.createSerializableMap(clonedKeys, clonedValues);
838
- serializableMappingCache.set(value, clone);
839
- serializableMappingCache.set(clone);
840
- freezeObjectInDev(value);
841
- return clone;
842
- }
843
- function cloneSet(value) {
844
- const clonedElements = [];
845
- for (const element of value) {
846
- clonedElements.push(createSerializable(element));
847
- }
848
- const clone = WorkletsModule.createSerializableSet(clonedElements);
849
- serializableMappingCache.set(value, clone);
850
- serializableMappingCache.set(clone);
851
- freezeObjectInDev(value);
852
- return clone;
853
- }
854
- function cloneRegExp(value) {
855
- const pattern = value.source;
856
- const flags = value.flags;
857
- const handle = cloneInitializer({
858
- __init: () => {
859
- "worklet";
860
- return new RegExp(pattern, flags);
861
- }
862
- });
863
- serializableMappingCache.set(value, handle);
864
- return handle;
865
- }
866
- function cloneError(value) {
867
- const {
868
- name,
869
- message,
870
- stack
871
- } = value;
872
- const handle = cloneInitializer({
873
- __init: () => {
874
- "worklet";
875
- const error = new Error();
876
- error.name = name;
877
- error.message = message;
878
- error.stack = stack;
879
- return error;
880
- }
881
- });
882
- serializableMappingCache.set(value, handle);
883
- return handle;
884
- }
885
- function cloneArrayBuffer(value, shouldPersistRemote) {
886
- const clone = WorkletsModule.createSerializable(value, shouldPersistRemote, value);
887
- serializableMappingCache.set(value, clone);
888
- serializableMappingCache.set(clone);
889
- return clone;
890
- }
891
- function cloneArrayBufferView(value) {
892
- const buffer = value.buffer;
893
- const typeName = value.constructor.name;
894
- const handle = cloneInitializer({
895
- __init: () => {
896
- "worklet";
897
- if (!VALID_ARRAY_VIEWS_NAMES.includes(typeName)) {
898
- throw new WorkletsError(`Invalid array view name \`${typeName}\`.`);
899
- }
900
- const constructor = global[typeName];
901
- if (constructor === void 0) {
902
- throw new WorkletsError(`Constructor for \`${typeName}\` not found.`);
903
- }
904
- return new constructor(buffer);
905
- }
906
- });
907
- serializableMappingCache.set(value, handle);
908
- return handle;
909
- }
910
- function cloneSynchronizable(value) {
911
- serializableMappingCache.set(value);
912
- return value;
913
- }
914
- function cloneImport(value) {
915
- const {
916
- source,
917
- imported
918
- } = value.__bundleData;
919
- const clone = WorkletsModule.createSerializableImport(source, imported);
920
- serializableMappingCache.set(value, clone);
921
- serializableMappingCache.set(clone);
922
- return clone;
923
- }
924
- function inaccessibleObject(value) {
925
- const clone = createSerializable(INACCESSIBLE_OBJECT);
926
- serializableMappingCache.set(value, clone);
927
- return clone;
928
- }
929
- var WORKLET_CODE_THRESHOLD = 255;
930
- function getWorkletCode(value) {
931
- const code = value?.__initData?.code;
932
- if (!code) {
933
- return "unknown";
934
- }
935
- if (code.length > WORKLET_CODE_THRESHOLD) {
936
- return `${code.substring(0, WORKLET_CODE_THRESHOLD)}...`;
937
- }
938
- return code;
939
- }
940
- function isRemoteFunction(value) {
941
- "worklet";
942
- return !!value.__remoteFunction;
943
- }
944
- function freezeObjectInDev(value) {
945
- if (!__DEV__) {
946
- return;
947
- }
948
- Object.entries(value).forEach(([key, element]) => {
949
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
950
- if (!descriptor.configurable) {
951
- return;
952
- }
953
- Object.defineProperty(value, key, {
954
- get() {
955
- return element;
956
- },
957
- set() {
958
- logger.warn(`Tried to modify key \`${key}\` of an object which has been already passed to a worklet. See
959
- https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-modify-key-of-an-object-which-has-been-converted-to-a-serializable
960
- for more details.`);
961
- }
962
- });
963
- });
964
- Object.preventExtensions(value);
965
- }
966
- function makeShareableCloneOnUIRecursiveLEGACY(value) {
967
- "worklet";
968
- if (SHOULD_BE_USE_WEB2) {
969
- return value;
970
- }
971
- function cloneRecursive(value2) {
972
- if (typeof value2 === "object" && value2 !== null || typeof value2 === "function") {
973
- if (isHostObject(value2)) {
974
- return global._createSerializableHostObject(value2);
975
- }
976
- if (isRemoteFunction(value2)) {
977
- return value2.__remoteFunction;
978
- }
979
- if (Array.isArray(value2)) {
980
- return global._createSerializableArray(value2.map(cloneRecursive));
981
- }
982
- if (value2.__synchronizableRef) {
983
- return global._createSerializableSynchronizable(value2);
984
- }
985
- const toAdapt = {};
986
- for (const [key, element] of Object.entries(value2)) {
987
- toAdapt[key] = cloneRecursive(element);
988
- }
989
- return global._createSerializable(toAdapt, value2);
990
- }
991
- if (typeof value2 === "string") {
992
- return global._createSerializableString(value2);
993
- }
994
- if (typeof value2 === "number") {
995
- return global._createSerializableNumber(value2);
996
- }
997
- if (typeof value2 === "boolean") {
998
- return global._createSerializableBoolean(value2);
999
- }
1000
- if (typeof value2 === "bigint") {
1001
- return global._createSerializableBigInt(value2);
1002
- }
1003
- if (value2 === void 0) {
1004
- return global._createSerializableUndefined();
1005
- }
1006
- if (value2 === null) {
1007
- return global._createSerializableNull();
1008
- }
1009
- return global._createSerializable(value2, void 0);
1010
- }
1011
- return cloneRecursive(value);
1012
- }
1013
- var makeShareableCloneOnUIRecursive = globalThis._WORKLETS_BUNDLE_MODE ? createSerializable : makeShareableCloneOnUIRecursiveLEGACY;
1014
-
1015
- // ../../node_modules/react-native-worklets/lib/module/threads.js
1016
- var runOnUIQueue = [];
1017
- function setupMicrotasks() {
1018
- "worklet";
1019
- let microtasksQueue = [];
1020
- let isExecutingMicrotasksQueue = false;
1021
- global.queueMicrotask = (callback) => {
1022
- microtasksQueue.push(callback);
1023
- };
1024
- global._microtaskQueueFinalizers = [];
1025
- global.__callMicrotasks = () => {
1026
- if (isExecutingMicrotasksQueue) {
1027
- return;
1028
- }
1029
- try {
1030
- isExecutingMicrotasksQueue = true;
1031
- for (let index = 0; index < microtasksQueue.length; index += 1) {
1032
- microtasksQueue[index]();
1033
- }
1034
- microtasksQueue = [];
1035
- global._microtaskQueueFinalizers.forEach((finalizer) => finalizer());
1036
- } finally {
1037
- isExecutingMicrotasksQueue = false;
1038
- }
1039
- };
1040
- }
1041
- function callMicrotasksOnUIThread() {
1042
- "worklet";
1043
- global.__callMicrotasks();
1044
- }
1045
- var callMicrotasks = SHOULD_BE_USE_WEB2 ? () => {
1046
- } : callMicrotasksOnUIThread;
1047
- function runOnUI(worklet) {
1048
- if (__DEV__ && !SHOULD_BE_USE_WEB2 && !isWorkletFunction(worklet) && !worklet.__bundleData) {
1049
- throw new WorkletsError("`runOnUI` can only be used with worklets.");
1050
- }
1051
- return (...args) => {
1052
- if (IS_JEST2) {
1053
- WorkletsModule.scheduleOnUI(createSerializable(() => {
1054
- "worklet";
1055
- worklet(...args);
1056
- }));
1057
- return;
1058
- }
1059
- if (__DEV__) {
1060
- createSerializable(worklet);
1061
- createSerializable(args);
1062
- }
1063
- enqueueUI(worklet, args);
1064
- };
1065
- }
1066
- if (__DEV__) {
1067
- let runOnUIWorklet = function() {
1068
- "worklet";
1069
- throw new WorkletsError("`runOnUI` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.");
1070
- };
1071
- const serializableRunOnUIWorklet = createSerializable(runOnUIWorklet);
1072
- serializableMappingCache.set(runOnUI, serializableRunOnUIWorklet);
1073
- }
1074
- function executeOnUIRuntimeSync(worklet) {
1075
- return (...args) => {
1076
- return WorkletsModule.executeOnUIRuntimeSync(createSerializable(() => {
1077
- "worklet";
1078
- const result = worklet(...args);
1079
- return makeShareableCloneOnUIRecursive(result);
1080
- }));
1081
- };
1082
- }
1083
- function runWorkletOnJS(worklet, ...args) {
1084
- worklet(...args);
1085
- }
1086
- function runOnJS(fun) {
1087
- "worklet";
1088
- if (SHOULD_BE_USE_WEB2 || globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
1089
- return (...args) => queueMicrotask(args.length ? () => fun(...args) : fun);
1090
- }
1091
- if (isWorkletFunction(fun)) {
1092
- return (...args) => runOnJS(runWorkletOnJS)(fun, ...args);
1093
- }
1094
- if (fun.__remoteFunction) {
1095
- fun = fun.__remoteFunction;
1096
- }
1097
- const scheduleOnJS = typeof fun === "function" ? global._scheduleHostFunctionOnJS : global._scheduleRemoteFunctionOnJS;
1098
- return (...args) => {
1099
- scheduleOnJS(fun, args.length > 0 ? makeShareableCloneOnUIRecursive(args) : void 0);
1100
- };
1101
- }
1102
- function runOnUIAsync(worklet) {
1103
- if (__DEV__ && !SHOULD_BE_USE_WEB2 && !isWorkletFunction(worklet)) {
1104
- throw new WorkletsError("`runOnUIAsync` can only be used with worklets.");
1105
- }
1106
- return (...args) => {
1107
- return new Promise((resolve) => {
1108
- if (IS_JEST2) {
1109
- WorkletsModule.scheduleOnUI(createSerializable(() => {
1110
- "worklet";
1111
- worklet(...args);
1112
- }));
1113
- return;
1114
- }
1115
- if (__DEV__) {
1116
- createSerializable(worklet);
1117
- createSerializable(args);
1118
- }
1119
- enqueueUI(worklet, args, resolve);
1120
- });
1121
- };
1122
- }
1123
- if (__DEV__) {
1124
- let runOnUIAsyncWorklet = function() {
1125
- "worklet";
1126
- throw new WorkletsError("`runOnUIAsync` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.");
1127
- };
1128
- const serializableRunOnUIAsyncWorklet = createSerializable(runOnUIAsyncWorklet);
1129
- serializableMappingCache.set(runOnUIAsync, serializableRunOnUIAsyncWorklet);
1130
- }
1131
- function enqueueUI(worklet, args, resolve) {
1132
- const job = [worklet, args, resolve];
1133
- runOnUIQueue.push(job);
1134
- if (runOnUIQueue.length === 1) {
1135
- flushUIQueue();
1136
- }
1137
- }
1138
- function flushUIQueue() {
1139
- queueMicrotask(() => {
1140
- const queue = runOnUIQueue;
1141
- runOnUIQueue = [];
1142
- WorkletsModule.scheduleOnUI(createSerializable(() => {
1143
- "worklet";
1144
- queue.forEach(([workletFunction, workletArgs, jobResolve]) => {
1145
- const result = workletFunction(...workletArgs);
1146
- if (jobResolve) {
1147
- runOnJS(jobResolve)(result);
1148
- }
1149
- });
1150
- callMicrotasks();
1151
- }));
1152
- });
1153
- }
1154
-
1155
- // ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/requestAnimationFrame.js
1156
- function setupRequestAnimationFrame() {
1157
- "worklet";
1158
- const nativeRequestAnimationFrame = globalThis.requestAnimationFrame;
1159
- let queuedCallbacks = [];
1160
- let queuedCallbacksBegin = 0;
1161
- let queuedCallbacksEnd = 0;
1162
- let flushedCallbacks = queuedCallbacks;
1163
- let flushedCallbacksBegin = 0;
1164
- let flushedCallbacksEnd = 0;
1165
- let flushRequested = false;
1166
- globalThis.__flushAnimationFrame = (timestamp) => {
1167
- flushedCallbacks = queuedCallbacks;
1168
- queuedCallbacks = [];
1169
- flushedCallbacksBegin = queuedCallbacksBegin;
1170
- flushedCallbacksEnd = queuedCallbacksEnd;
1171
- queuedCallbacksBegin = queuedCallbacksEnd;
1172
- for (const callback of flushedCallbacks) {
1173
- callback(timestamp);
1174
- }
1175
- flushedCallbacksBegin = flushedCallbacksEnd;
1176
- callMicrotasks();
1177
- };
1178
- globalThis.requestAnimationFrame = (callback) => {
1179
- const handle = queuedCallbacksEnd++;
1180
- queuedCallbacks.push(callback);
1181
- if (!flushRequested) {
1182
- flushRequested = true;
1183
- nativeRequestAnimationFrame((timestamp) => {
1184
- flushRequested = false;
1185
- globalThis.__frameTimestamp = timestamp;
1186
- globalThis.__flushAnimationFrame(timestamp);
1187
- globalThis.__frameTimestamp = void 0;
1188
- });
1189
- }
1190
- return handle;
1191
- };
1192
- globalThis.cancelAnimationFrame = (handle) => {
1193
- if (handle < flushedCallbacksBegin || handle >= queuedCallbacksEnd) {
1194
- return;
1195
- }
1196
- if (handle < flushedCallbacksEnd) {
1197
- flushedCallbacks[handle - flushedCallbacksBegin] = () => {
1198
- };
1199
- } else {
1200
- queuedCallbacks[handle - queuedCallbacksBegin] = () => {
1201
- };
1202
- }
1203
- };
1204
- }
1205
-
1206
- // ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js
1207
- function setupSetTimeout() {
1208
- "worklet";
1209
- const timeoutHandleToRafHandle = /* @__PURE__ */ new Map();
1210
- const setTimeoutPolyfill = (callback, delay = 0, ...args) => {
1211
- const start = performance.now();
1212
- let timeoutHandle = 0;
1213
- const rafCallback = () => {
1214
- const now = performance.now();
1215
- if (now - start >= delay) {
1216
- callback(...args);
1217
- timeoutHandleToRafHandle.delete(timeoutHandle);
1218
- } else {
1219
- const rafHandle = requestAnimationFrame(rafCallback);
1220
- timeoutHandleToRafHandle.set(timeoutHandle, rafHandle);
1221
- }
1222
- };
1223
- timeoutHandle = requestAnimationFrame(rafCallback);
1224
- timeoutHandleToRafHandle.set(timeoutHandle, timeoutHandle);
1225
- return timeoutHandle;
1226
- };
1227
- const clearTimeoutPolyfill = (timeoutHandle) => {
1228
- const rafHandle = timeoutHandleToRafHandle.get(timeoutHandle);
1229
- timeoutHandleToRafHandle.delete(timeoutHandle);
1230
- cancelAnimationFrame(rafHandle);
1231
- };
1232
- globalThis.setTimeout = setTimeoutPolyfill;
1233
- globalThis.clearTimeout = clearTimeoutPolyfill;
1234
- }
1235
-
1236
- // ../../node_modules/react-native-worklets/lib/module/synchronizableUnpacker.js
1237
- function __installUnpacker() {
1238
- const serializer = !globalThis._WORKLET || globalThis._WORKLETS_BUNDLE_MODE ? (value, _) => createSerializable(value) : globalThis._createSerializable;
1239
- function synchronizableUnpacker(synchronizableRef) {
1240
- const synchronizable = synchronizableRef;
1241
- const proxy = globalThis.__workletsModuleProxy;
1242
- synchronizable.__synchronizableRef = true;
1243
- synchronizable.getDirty = () => {
1244
- return proxy.synchronizableGetDirty(synchronizable);
1245
- };
1246
- synchronizable.getBlocking = () => {
1247
- return proxy.synchronizableGetBlocking(synchronizable);
1248
- };
1249
- synchronizable.setBlocking = (valueOrFunction) => {
1250
- let newValue;
1251
- if (typeof valueOrFunction === "function") {
1252
- const func = valueOrFunction;
1253
- synchronizable.lock();
1254
- const prev = synchronizable.getBlocking();
1255
- newValue = func(prev);
1256
- proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, void 0));
1257
- synchronizable.unlock();
1258
- } else {
1259
- const value = valueOrFunction;
1260
- newValue = value;
1261
- proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, void 0));
1262
- }
1263
- };
1264
- synchronizable.lock = () => {
1265
- proxy.synchronizableLock(synchronizable);
1266
- };
1267
- synchronizable.unlock = () => {
1268
- proxy.synchronizableUnlock(synchronizable);
1269
- };
1270
- return synchronizable;
1271
- }
1272
- globalThis.__synchronizableUnpacker = synchronizableUnpacker;
1273
- }
1274
-
1275
- // ../../node_modules/react-native-worklets/lib/module/initializers.js
1276
- var capturableConsole;
1277
- function getMemorySafeCapturableConsole() {
1278
- if (capturableConsole) {
1279
- return capturableConsole;
1280
- }
1281
- const consoleCopy = Object.fromEntries(Object.entries(console).map(([methodName, method]) => {
1282
- const methodWrapper = function methodWrapper2(...args) {
1283
- return method(...args);
1284
- };
1285
- if (method.name) {
1286
- Object.defineProperty(methodWrapper, "name", {
1287
- value: method.name,
1288
- writable: false
1289
- });
1290
- }
1291
- return [methodName, methodWrapper];
1292
- }));
1293
- capturableConsole = consoleCopy;
1294
- return consoleCopy;
1295
- }
1296
- function setupConsole(boundCapturableConsole) {
1297
- "worklet";
1298
- globalThis.console = {
1299
- assert: runOnJS(boundCapturableConsole.assert),
1300
- debug: runOnJS(boundCapturableConsole.debug),
1301
- log: runOnJS(boundCapturableConsole.log),
1302
- warn: runOnJS(boundCapturableConsole.warn),
1303
- error: runOnJS(boundCapturableConsole.error),
1304
- info: runOnJS(boundCapturableConsole.info)
1305
- };
1306
- }
1307
- var initialized = false;
1308
- function init() {
1309
- if (initialized) {
1310
- return;
1311
- }
1312
- initialized = true;
1313
- if (globalThis.__RUNTIME_KIND === void 0) {
1314
- globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
1315
- }
1316
- initializeRuntime();
1317
- if (SHOULD_BE_USE_WEB2) {
1318
- initializeRuntimeOnWeb();
1319
- }
1320
- if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
1321
- initializeWorkletRuntime();
1322
- } else {
1323
- initializeRNRuntime();
1324
- if (!SHOULD_BE_USE_WEB2) {
1325
- installRNBindingsOnUIRuntime();
1326
- }
1327
- }
1328
- }
1329
- function initializeRuntime() {
1330
- if (globalThis._WORKLETS_BUNDLE_MODE) {
1331
- globalThis.__valueUnpacker = bundleValueUnpacker;
1332
- }
1333
- __installUnpacker();
7
+ // src/motion/Image.tsx
8
+ var DEFAULT_MOTION_CONFIG = {
9
+ reducedMotion: "user"
10
+ };
11
+ var MotionConfigContext = createContext(
12
+ DEFAULT_MOTION_CONFIG
13
+ );
14
+ function useMotionConfig() {
15
+ return useContext(MotionConfigContext);
1334
16
  }
1335
- function initializeRNRuntime() {
1336
- if (__DEV__) {
1337
- const testWorklet = () => {
1338
- "worklet";
1339
- };
1340
- if (!isWorkletFunction(testWorklet)) {
1341
- throw new WorkletsError(`Failed to create a worklet. See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#failed-to-create-a-worklet for more details.`);
1342
- }
1343
- }
1344
- registerReportFatalRemoteError();
17
+ function useShouldReduceMotion() {
18
+ const { reducedMotion } = useMotionConfig();
19
+ const osReduced = useReducedMotion();
20
+ if (reducedMotion === "never") return false;
21
+ if (reducedMotion === "always") return true;
22
+ return osReduced;
1345
23
  }
1346
- function initializeWorkletRuntime() {
1347
- if (globalThis._WORKLETS_BUNDLE_MODE) {
1348
- setupCallGuard();
1349
- if (__DEV__) {
1350
- const Refresh = new Proxy({}, {
1351
- get() {
1352
- return () => {
1353
- };
1354
- }
1355
- });
1356
- globalThis.__r.Refresh = Refresh;
1357
- const modules = __require.getModules();
1358
- const ReactNativeModuleId = __require.resolveWeak("react-native");
1359
- const factory = function(_global, _require, _importDefault, _importAll, module, _exports, _dependencyMap) {
1360
- module.exports = new Proxy({}, {
1361
- get: function get(_target, prop) {
1362
- globalThis.console.warn(`You tried to import '${String(prop)}' from 'react-native' module on a Worklet Runtime. Using 'react-native' module on a Worklet Runtime is not allowed.`);
1363
- return {
1364
- get() {
1365
- return void 0;
1366
- }
1367
- };
1368
- }
1369
- });
1370
- };
1371
- const mod = {
1372
- dependencyMap: [],
1373
- factory,
1374
- hasError: false,
1375
- importedAll: {},
1376
- importedDefault: {},
1377
- isInitialized: false,
1378
- publicModule: {
1379
- exports: {}
1380
- }
1381
- };
1382
- modules.set(ReactNativeModuleId, mod);
1383
- }
1384
- }
24
+ function MotionConfig({
25
+ reducedMotion = "user",
26
+ children
27
+ }) {
28
+ const value = useMemo(
29
+ () => ({ reducedMotion }),
30
+ [reducedMotion]
31
+ );
32
+ return /* @__PURE__ */ jsx(MotionConfigContext.Provider, { value, children });
1385
33
  }
1386
- function initializeRuntimeOnWeb() {
1387
- globalThis._WORKLET = false;
1388
- globalThis._log = console.log;
1389
- globalThis._getAnimationTimestamp = () => performance.now();
1390
- if (IS_JEST2) {
1391
- globalThis.requestAnimationFrame = mockedRequestAnimationFrame;
1392
- }
34
+ var modality = "keyboard";
35
+ var installed = false;
36
+ function setKeyboard() {
37
+ modality = "keyboard";
1393
38
  }
1394
- function installRNBindingsOnUIRuntime() {
1395
- if (!WorkletsModule) {
1396
- throw new WorkletsError("Worklets are trying to initialize the UI runtime without a valid WorkletsModule");
1397
- }
1398
- const runtimeBoundCapturableConsole = getMemorySafeCapturableConsole();
1399
- if (!globalThis._WORKLETS_BUNDLE_MODE) {
1400
- executeOnUIRuntimeSync(setupCallGuard)();
1401
- executeOnUIRuntimeSync(registerWorkletsError)();
1402
- }
1403
- executeOnUIRuntimeSync(() => {
1404
- "worklet";
1405
- setupConsole(runtimeBoundCapturableConsole);
1406
- setupMicrotasks();
1407
- setupRequestAnimationFrame();
1408
- setupSetTimeout();
1409
- setupSetImmediate();
1410
- setupSetInterval();
1411
- })();
39
+ function setPointer() {
40
+ modality = "pointer";
1412
41
  }
1413
-
1414
- // ../../node_modules/react-native-worklets/lib/module/workletRuntimeEntry.js
1415
- function bundleModeInit() {
1416
- if (SHOULD_BE_USE_WEB2) {
1417
- return;
1418
- }
1419
- globalThis._WORKLETS_BUNDLE_MODE = true;
1420
- const runtimeKind = globalThis.__RUNTIME_KIND;
1421
- if (runtimeKind && runtimeKind !== RuntimeKind.ReactNative) {
1422
- init();
1423
- throw new WorkletsError("Worklets initialized successfully");
1424
- }
42
+ function ensureInstalled() {
43
+ if (installed) return;
44
+ if (Platform.OS !== "web") return;
45
+ if (typeof document === "undefined") return;
46
+ document.addEventListener("keydown", setKeyboard, true);
47
+ document.addEventListener("mousedown", setPointer, true);
48
+ document.addEventListener("pointerdown", setPointer, true);
49
+ document.addEventListener("touchstart", setPointer, true);
50
+ installed = true;
1425
51
  }
1426
- bundleModeInit();
1427
-
1428
- // ../../node_modules/react-native-worklets/lib/module/featureFlags/index.js
1429
- var DynamicFlags = {
1430
- EXAMPLE_DYNAMIC_FLAG: true,
1431
- init() {
1432
- Object.keys(DynamicFlags).forEach((key) => {
1433
- if (key !== "init" && key !== "setFlag") {
1434
- WorkletsModule.setDynamicFeatureFlag(key, DynamicFlags[key]);
1435
- }
1436
- });
1437
- },
1438
- setFlag(name, value) {
1439
- if (name in DynamicFlags) {
1440
- DynamicFlags[name] = value;
1441
- WorkletsModule.setDynamicFeatureFlag(name, value);
1442
- } else {
1443
- logger.warn(`The feature flag: '${name}' no longer exists, you can safely remove invocation of \`setDynamicFeatureFlag('${name}')\` from your code.`);
1444
- }
1445
- }
1446
- };
1447
- DynamicFlags.init();
1448
-
1449
- // ../../node_modules/react-native-worklets/lib/module/index.js
1450
- init();
1451
- if (globalThis._ALWAYS_FALSE) {
1452
- bundleModeInit();
52
+ function isFocusVisible() {
53
+ if (Platform.OS !== "web") return true;
54
+ ensureInstalled();
55
+ return modality === "keyboard";
1453
56
  }
1454
-
1455
- // src/transitions/easing.ts
1456
57
  function ensureWorkletEasing(easing) {
1457
58
  if (!easing) return void 0;
1458
59
  const fn = isEasingFactory(easing) ? easing.factory() : easing;
@@ -1506,6 +107,157 @@ function resolveLayoutTransition(layout) {
1506
107
  if ("delay" in spring && spring.delay) builder = builder.delay(spring.delay);
1507
108
  return builder;
1508
109
  }
110
+
111
+ // src/layout/sharedRegistry.ts
112
+ var REGISTRY = /* @__PURE__ */ new Map();
113
+ var SHARED_LAYOUT_TTL_MS = 1e3;
114
+ var now = () => Date.now();
115
+ function registerLayout(id, rect) {
116
+ REGISTRY.set(id, { rect, expiresAt: now() + SHARED_LAYOUT_TTL_MS });
117
+ }
118
+ function releaseLayout(id, rect) {
119
+ REGISTRY.set(id, { rect, expiresAt: now() + SHARED_LAYOUT_TTL_MS });
120
+ }
121
+ function consumeLayout(id) {
122
+ const entry = REGISTRY.get(id);
123
+ if (!entry) return void 0;
124
+ REGISTRY.delete(id);
125
+ if (entry.expiresAt < now()) return void 0;
126
+ return entry.rect;
127
+ }
128
+ function useSharedLayout(options) {
129
+ const { layoutId, userRef, transition, shouldReduceMotion, userOnLayout } = options;
130
+ const dx = useSharedValue(0);
131
+ const dy = useSharedValue(0);
132
+ const sx = useSharedValue(1);
133
+ const sy = useSharedValue(1);
134
+ const lastRectRef = useRef(null);
135
+ const consumedRef = useRef(false);
136
+ const transitionRef = useRef(transition);
137
+ transitionRef.current = transition;
138
+ const reducedMotionRef = useRef(shouldReduceMotion);
139
+ reducedMotionRef.current = shouldReduceMotion;
140
+ const setRef = useCallback(
141
+ (node) => {
142
+ if (typeof userRef === "function") userRef(node);
143
+ else if (userRef) userRef.current = node;
144
+ },
145
+ [userRef]
146
+ );
147
+ const onLayout = useCallback(
148
+ (event) => {
149
+ userOnLayout?.(event);
150
+ if (!layoutId) return;
151
+ const { x, y, width, height } = event.nativeEvent.layout;
152
+ const rect = { x, y, width, height };
153
+ lastRectRef.current = rect;
154
+ let source;
155
+ if (!consumedRef.current) {
156
+ consumedRef.current = true;
157
+ source = consumeLayout(layoutId);
158
+ }
159
+ registerLayout(layoutId, rect);
160
+ if (source) {
161
+ applyFlip({
162
+ source,
163
+ target: rect,
164
+ dx,
165
+ dy,
166
+ sx,
167
+ sy,
168
+ transition: transitionRef.current,
169
+ shouldReduceMotion: reducedMotionRef.current
170
+ });
171
+ }
172
+ },
173
+ // dx/dy/sx/sy are stable refs from useSharedValue, but eslint's
174
+ // exhaustive-deps would flag them — including them is harmless and
175
+ // silences the warning.
176
+ [layoutId, userOnLayout, dx, dy, sx, sy]
177
+ );
178
+ useEffect(() => {
179
+ consumedRef.current = false;
180
+ }, [layoutId]);
181
+ useEffect(() => {
182
+ return () => {
183
+ if (!layoutId) return;
184
+ const rect = lastRectRef.current;
185
+ if (!rect) return;
186
+ releaseLayout(layoutId, rect);
187
+ };
188
+ }, [layoutId]);
189
+ return useMemo(
190
+ () => ({
191
+ flip: { dx, dy, sx, sy },
192
+ setRef,
193
+ onLayout
194
+ }),
195
+ [dx, dy, sx, sy, setRef, onLayout]
196
+ );
197
+ }
198
+ function applyFlip(args) {
199
+ const { source, target, dx, dy, sx, sy, transition, shouldReduceMotion } = args;
200
+ const sourceCenterX = source.x + source.width / 2;
201
+ const sourceCenterY = source.y + source.height / 2;
202
+ const targetCenterX = target.x + target.width / 2;
203
+ const targetCenterY = target.y + target.height / 2;
204
+ const deltaX = sourceCenterX - targetCenterX;
205
+ const deltaY = sourceCenterY - targetCenterY;
206
+ const scaleX = target.width > 0 ? source.width / target.width : 1;
207
+ const scaleY = target.height > 0 ? source.height / target.height : 1;
208
+ if (shouldReduceMotion) {
209
+ dx.value = 0;
210
+ dy.value = 0;
211
+ sx.value = 1;
212
+ sy.value = 1;
213
+ return;
214
+ }
215
+ if (transition?.type === "no-animation") {
216
+ dx.value = 0;
217
+ dy.value = 0;
218
+ sx.value = 1;
219
+ sy.value = 1;
220
+ return;
221
+ }
222
+ if (transition?.type === "timing") {
223
+ const duration = transition.duration ?? 300;
224
+ dx.value = withSequence(
225
+ withTiming(deltaX, { duration: 0 }),
226
+ withTiming(0, { duration })
227
+ );
228
+ dy.value = withSequence(
229
+ withTiming(deltaY, { duration: 0 }),
230
+ withTiming(0, { duration })
231
+ );
232
+ sx.value = withSequence(
233
+ withTiming(scaleX, { duration: 0 }),
234
+ withTiming(1, { duration })
235
+ );
236
+ sy.value = withSequence(
237
+ withTiming(scaleY, { duration: 0 }),
238
+ withTiming(1, { duration })
239
+ );
240
+ return;
241
+ }
242
+ const springCfg = transition?.type === "spring" ? { ...DEFAULT_SPRING, ...transition } : { ...DEFAULT_SPRING };
243
+ const springParams = springToReanimated(springCfg);
244
+ dx.value = withSequence(
245
+ withTiming(deltaX, { duration: 0 }),
246
+ withSpring(0, springParams)
247
+ );
248
+ dy.value = withSequence(
249
+ withTiming(deltaY, { duration: 0 }),
250
+ withSpring(0, springParams)
251
+ );
252
+ sx.value = withSequence(
253
+ withTiming(scaleX, { duration: 0 }),
254
+ withSpring(1, springParams)
255
+ );
256
+ sy.value = withSequence(
257
+ withTiming(scaleY, { duration: 0 }),
258
+ withSpring(1, springParams)
259
+ );
260
+ }
1509
261
  var PresenceContext = createContext(null);
1510
262
  function usePresence() {
1511
263
  return useContext(PresenceContext);
@@ -1773,8 +525,6 @@ function stableStringify(v) {
1773
525
  const keys = Object.keys(obj).sort();
1774
526
  return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
1775
527
  }
1776
-
1777
- // src/motion/installCheck.ts
1778
528
  var alreadyChecked = false;
1779
529
  function ensureReanimatedInstalled() {
1780
530
  if (!__DEV__ || alreadyChecked) return;
@@ -1782,12 +532,7 @@ function ensureReanimatedInstalled() {
1782
532
  return;
1783
533
  }
1784
534
  alreadyChecked = true;
1785
- let version;
1786
- try {
1787
- const pkg = __require("react-native-reanimated/package.json");
1788
- version = pkg.version;
1789
- } catch {
1790
- }
535
+ const version = reanimatedVersion;
1791
536
  if (version) {
1792
537
  const major = parseInt(version.split(".")[0] ?? "0", 10);
1793
538
  if (major < 4) {
@@ -1907,10 +652,17 @@ function createMotionComponent(Component) {
1907
652
  controller,
1908
653
  gesture,
1909
654
  layout,
655
+ layoutId,
1910
656
  onAnimationEnd,
1911
657
  style,
658
+ onLayout: userOnLayout,
1912
659
  ...rest
1913
660
  } = props;
661
+ if (__DEV__ && typeof style === "function") {
662
+ throw new Error(
663
+ "[inertia] `style` must be a style object or array of style objects, not a function. The function-form `style={(state) => ...}` Pressable API is not supported \u2014 use `gesture.pressed` (or `gesture.focused`, etc.) to drive state-dependent styling instead."
664
+ );
665
+ }
1914
666
  const presence = usePresence();
1915
667
  const isExiting = presence !== null && presence.isPresent === false;
1916
668
  const shouldReduceMotion = useShouldReduceMotion();
@@ -1929,37 +681,51 @@ function createMotionComponent(Component) {
1929
681
  const [focused, setFocused] = useState(false);
1930
682
  const [focusVisible, setFocusVisible] = useState(false);
1931
683
  const [hovered, setHovered] = useState(false);
1932
- const activeKeysRef = useRef(null);
1933
- if (activeKeysRef.current === null) {
1934
- const touched = /* @__PURE__ */ new Set();
1935
- collectTouchedKeys(touched, animateRecord);
1936
- if (initialRecord) collectTouchedKeys(touched, initialRecord);
1937
- if (variants) {
1938
- for (const variant of Object.values(variants)) {
1939
- if (!variant) continue;
1940
- collectTouchedKeys(touched, variant);
1941
- }
684
+ const touched = /* @__PURE__ */ new Set();
685
+ collectTouchedKeys(touched, animateRecord);
686
+ if (initialRecord) collectTouchedKeys(touched, initialRecord);
687
+ if (variants) {
688
+ for (const variant of Object.values(variants)) {
689
+ if (!variant) continue;
690
+ collectTouchedKeys(touched, variant);
1942
691
  }
1943
- if (gesture) {
1944
- for (const subState of [
1945
- gesture.pressed,
1946
- gesture.focused,
1947
- gesture.focusVisible,
1948
- gesture.hovered
1949
- ]) {
1950
- if (!subState) continue;
1951
- collectTouchedKeys(touched, subState);
692
+ }
693
+ if (gesture) {
694
+ for (const subState of [
695
+ gesture.pressed,
696
+ gesture.focused,
697
+ gesture.focusVisible,
698
+ gesture.hovered
699
+ ]) {
700
+ if (!subState) continue;
701
+ collectTouchedKeys(touched, subState);
702
+ }
703
+ }
704
+ if (exitRecord) collectTouchedKeys(touched, exitRecord);
705
+ const activeKeysRef = useRef(null);
706
+ const hasTransformRef = useRef(false);
707
+ const hasShadowOffsetRef = useRef(false);
708
+ const prevActive = activeKeysRef.current;
709
+ let grew = prevActive === null;
710
+ if (!grew && prevActive) {
711
+ for (const k of touched) {
712
+ if (!prevActive.includes(k)) {
713
+ grew = true;
714
+ break;
1952
715
  }
1953
716
  }
1954
- if (exitRecord) collectTouchedKeys(touched, exitRecord);
1955
- activeKeysRef.current = ALL_KEYS.filter((k) => touched.has(k));
1956
717
  }
1957
- const hasTransformRef = useRef(
1958
- activeKeysRef.current.some((k) => TRANSFORM_KEY_SET.has(k))
1959
- );
1960
- const hasShadowOffsetRef = useRef(
1961
- activeKeysRef.current.some((k) => SHADOW_OFFSET_KEY_SET.has(k))
1962
- );
718
+ if (grew) {
719
+ const merged = new Set(prevActive ?? []);
720
+ for (const k of touched) merged.add(k);
721
+ activeKeysRef.current = ALL_KEYS.filter((k) => merged.has(k));
722
+ hasTransformRef.current = activeKeysRef.current.some(
723
+ (k) => TRANSFORM_KEY_SET.has(k)
724
+ );
725
+ hasShadowOffsetRef.current = activeKeysRef.current.some(
726
+ (k) => SHADOW_OFFSET_KEY_SET.has(k)
727
+ );
728
+ }
1963
729
  const sharedValues = useAnimatableSharedValues((key) => {
1964
730
  if (SHADOW_OFFSET_KEY_SET.has(key)) {
1965
731
  const axis = shadowOffsetAxisFor(key);
@@ -2084,6 +850,15 @@ function createMotionComponent(Component) {
2084
850
  isExiting,
2085
851
  shouldReduceMotion
2086
852
  );
853
+ const sharedLayout = useSharedLayout({
854
+ layoutId,
855
+ userRef: ref,
856
+ transition: isTopLevelTransition(transition) ? transition : void 0,
857
+ shouldReduceMotion,
858
+ userOnLayout
859
+ });
860
+ const flip = sharedLayout.flip;
861
+ const hasLayoutId = layoutId !== void 0;
2087
862
  const animatedStyle = useAnimatedStyle(() => {
2088
863
  const activeKeys = activeKeysRef.current;
2089
864
  const hasTransform = hasTransformRef.current;
@@ -2132,7 +907,13 @@ function createMotionComponent(Component) {
2132
907
  out[key] = v;
2133
908
  }
2134
909
  }
2135
- if (hasTransform) out.transform = transform;
910
+ if (hasLayoutId) {
911
+ transform.push({ translateX: flip.dx.value });
912
+ transform.push({ translateY: flip.dy.value });
913
+ transform.push({ scaleX: flip.sx.value });
914
+ transform.push({ scaleY: flip.sy.value });
915
+ }
916
+ if (hasTransform || hasLayoutId) out.transform = transform;
2136
917
  if (hasShadowOffset) {
2137
918
  out.shadowOffset = { width: shadowOffsetW, height: shadowOffsetH };
2138
919
  }
@@ -2159,9 +940,10 @@ function createMotionComponent(Component) {
2159
940
  return /* @__PURE__ */ jsx(
2160
941
  AnimatedComponent,
2161
942
  {
2162
- ref,
943
+ ref: sharedLayout.setRef,
2163
944
  ...rest,
2164
945
  ...gestureHandlers,
946
+ onLayout: sharedLayout.onLayout,
2165
947
  layout: layoutTransition,
2166
948
  style: mergedStyle
2167
949
  }
@@ -2170,34 +952,34 @@ function createMotionComponent(Component) {
2170
952
  Motion2.displayName = `Motion(${Component.displayName ?? Component.name ?? "Component"})`;
2171
953
  return Motion2;
2172
954
  }
2173
- function useAnimatableSharedValues(init2) {
2174
- const translateX = useSharedValue(init2("translateX"));
2175
- const translateY = useSharedValue(init2("translateY"));
2176
- const scale = useSharedValue(init2("scale"));
2177
- const scaleX = useSharedValue(init2("scaleX"));
2178
- const scaleY = useSharedValue(init2("scaleY"));
2179
- const rotate = useSharedValue(init2("rotate"));
2180
- const rotateX = useSharedValue(init2("rotateX"));
2181
- const rotateY = useSharedValue(init2("rotateY"));
2182
- const opacity = useSharedValue(init2("opacity"));
2183
- const width = useSharedValue(init2("width"));
2184
- const height = useSharedValue(init2("height"));
2185
- const borderRadius = useSharedValue(init2("borderRadius"));
2186
- const shadowOpacity = useSharedValue(init2("shadowOpacity"));
2187
- const shadowRadius = useSharedValue(init2("shadowRadius"));
2188
- const elevation = useSharedValue(init2("elevation"));
955
+ function useAnimatableSharedValues(init) {
956
+ const translateX = useSharedValue(init("translateX"));
957
+ const translateY = useSharedValue(init("translateY"));
958
+ const scale = useSharedValue(init("scale"));
959
+ const scaleX = useSharedValue(init("scaleX"));
960
+ const scaleY = useSharedValue(init("scaleY"));
961
+ const rotate = useSharedValue(init("rotate"));
962
+ const rotateX = useSharedValue(init("rotateX"));
963
+ const rotateY = useSharedValue(init("rotateY"));
964
+ const opacity = useSharedValue(init("opacity"));
965
+ const width = useSharedValue(init("width"));
966
+ const height = useSharedValue(init("height"));
967
+ const borderRadius = useSharedValue(init("borderRadius"));
968
+ const shadowOpacity = useSharedValue(init("shadowOpacity"));
969
+ const shadowRadius = useSharedValue(init("shadowRadius"));
970
+ const elevation = useSharedValue(init("elevation"));
2189
971
  const backgroundColor = useSharedValue(
2190
- init2("backgroundColor")
972
+ init("backgroundColor")
2191
973
  );
2192
- const borderColor = useSharedValue(init2("borderColor"));
2193
- const color = useSharedValue(init2("color"));
2194
- const tintColor = useSharedValue(init2("tintColor"));
2195
- const shadowColor = useSharedValue(init2("shadowColor"));
974
+ const borderColor = useSharedValue(init("borderColor"));
975
+ const color = useSharedValue(init("color"));
976
+ const tintColor = useSharedValue(init("tintColor"));
977
+ const shadowColor = useSharedValue(init("shadowColor"));
2196
978
  const shadowOffsetWidth = useSharedValue(
2197
- init2("shadowOffsetWidth")
979
+ init("shadowOffsetWidth")
2198
980
  );
2199
981
  const shadowOffsetHeight = useSharedValue(
2200
- init2("shadowOffsetHeight")
982
+ init("shadowOffsetHeight")
2201
983
  );
2202
984
  const ref = useRef(null);
2203
985
  if (ref.current === null) {
@@ -2286,7 +1068,7 @@ function makeKeyCallbackFactory(key, sharedValue, target, onAnimationEndRef, met
2286
1068
  return (rawPhase, step) => {
2287
1069
  const cb = (finished) => {
2288
1070
  "worklet";
2289
- runOnJS$1(dispatch)(rawPhase, step, !!finished, sharedValue.value);
1071
+ runOnJS(dispatch)(rawPhase, step, !!finished, sharedValue.value);
2290
1072
  };
2291
1073
  return cb;
2292
1074
  };
@@ -2490,6 +1272,57 @@ function useAnimation(target, transition) {
2490
1272
  }, [target, cfgSig, shouldReduceMotion]);
2491
1273
  return output;
2492
1274
  }
1275
+ function useSpring(target, config) {
1276
+ const reanimConfig = useMemo(
1277
+ () => springToReanimated(config ?? {}),
1278
+ [
1279
+ config?.tension,
1280
+ config?.friction,
1281
+ config?.mass,
1282
+ config?.velocity,
1283
+ config?.restSpeedThreshold,
1284
+ config?.restDisplacementThreshold
1285
+ ]
1286
+ );
1287
+ const isSharedTarget = isSharedValue(target);
1288
+ const initial = isSharedTarget ? target.value : target;
1289
+ const output = useSharedValue(initial);
1290
+ useEffect(() => {
1291
+ if (isSharedTarget) return;
1292
+ output.value = withSpring(target, reanimConfig);
1293
+ }, [isSharedTarget, target, reanimConfig]);
1294
+ useAnimatedReaction(
1295
+ () => {
1296
+ "worklet";
1297
+ if (!isSharedTarget) return null;
1298
+ return target.value;
1299
+ },
1300
+ (next, prev) => {
1301
+ "worklet";
1302
+ if (next === null || next === prev) return;
1303
+ output.value = withSpring(next, reanimConfig);
1304
+ },
1305
+ [isSharedTarget, reanimConfig]
1306
+ );
1307
+ return output;
1308
+ }
1309
+ function isSharedValue(v) {
1310
+ return typeof v === "object" && v !== null && "value" in v;
1311
+ }
1312
+
1313
+ // src/values/useBooleanSpring.ts
1314
+ function useBooleanSpring(active, springConfig) {
1315
+ return useSpring(active ? 1 : 0, springConfig);
1316
+ }
1317
+ function useColorTransition(progress, range, options) {
1318
+ const key = options?.key ?? "backgroundColor";
1319
+ const from = range[0];
1320
+ const to = range[1];
1321
+ return useAnimatedStyle(() => {
1322
+ "worklet";
1323
+ return { [key]: interpolateColor(progress.value, [0, 1], [from, to]) };
1324
+ });
1325
+ }
2493
1326
  function useGesture(transition) {
2494
1327
  const pressed = useSharedValue(0);
2495
1328
  const focused = useSharedValue(0);
@@ -2537,43 +1370,6 @@ function layerTransition(layer, transition) {
2537
1370
  function useMotionValue(initial) {
2538
1371
  return useSharedValue(initial);
2539
1372
  }
2540
- function useSpring(target, config) {
2541
- const reanimConfig = useMemo(
2542
- () => springToReanimated(config ?? {}),
2543
- [
2544
- config?.tension,
2545
- config?.friction,
2546
- config?.mass,
2547
- config?.velocity,
2548
- config?.restSpeedThreshold,
2549
- config?.restDisplacementThreshold
2550
- ]
2551
- );
2552
- const isSharedTarget = isSharedValue(target);
2553
- const initial = isSharedTarget ? target.value : target;
2554
- const output = useSharedValue(initial);
2555
- useEffect(() => {
2556
- if (isSharedTarget) return;
2557
- output.value = withSpring(target, reanimConfig);
2558
- }, [isSharedTarget, target, reanimConfig]);
2559
- useAnimatedReaction(
2560
- () => {
2561
- "worklet";
2562
- if (!isSharedTarget) return null;
2563
- return target.value;
2564
- },
2565
- (next, prev) => {
2566
- "worklet";
2567
- if (next === null || next === prev) return;
2568
- output.value = withSpring(next, reanimConfig);
2569
- },
2570
- [isSharedTarget, reanimConfig]
2571
- );
2572
- return output;
2573
- }
2574
- function isSharedValue(v) {
2575
- return typeof v === "object" && v !== null && "value" in v;
2576
- }
2577
1373
  function useTransform(arg1, inputRange, outputRange, options) {
2578
1374
  let producer;
2579
1375
  if (typeof arg1 === "function") {
@@ -2629,6 +1425,53 @@ function useScroll() {
2629
1425
  onScroll: handler
2630
1426
  };
2631
1427
  }
1428
+ function useShadow({
1429
+ from,
1430
+ to,
1431
+ progress
1432
+ }) {
1433
+ const hasOpacity = from.shadowOpacity !== void 0 || to.shadowOpacity !== void 0;
1434
+ const hasRadius = from.shadowRadius !== void 0 || to.shadowRadius !== void 0;
1435
+ const hasElevation = from.elevation !== void 0 || to.elevation !== void 0;
1436
+ const hasColor = from.shadowColor !== void 0 || to.shadowColor !== void 0;
1437
+ const hasOffset = from.shadowOffset !== void 0 || to.shadowOffset !== void 0;
1438
+ const opacityFrom = from.shadowOpacity ?? 0;
1439
+ const opacityTo = to.shadowOpacity ?? 0;
1440
+ const radiusFrom = from.shadowRadius ?? 0;
1441
+ const radiusTo = to.shadowRadius ?? 0;
1442
+ const elevationFrom = from.elevation ?? 0;
1443
+ const elevationTo = to.elevation ?? 0;
1444
+ const colorFrom = from.shadowColor ?? "transparent";
1445
+ const colorTo = to.shadowColor ?? "transparent";
1446
+ const offsetWFrom = from.shadowOffset?.width ?? 0;
1447
+ const offsetWTo = to.shadowOffset?.width ?? 0;
1448
+ const offsetHFrom = from.shadowOffset?.height ?? 0;
1449
+ const offsetHTo = to.shadowOffset?.height ?? 0;
1450
+ return useAnimatedStyle(() => {
1451
+ "worklet";
1452
+ const t = progress.value;
1453
+ const out = {};
1454
+ if (hasOpacity) {
1455
+ out.shadowOpacity = interpolate(t, [0, 1], [opacityFrom, opacityTo]);
1456
+ }
1457
+ if (hasRadius) {
1458
+ out.shadowRadius = interpolate(t, [0, 1], [radiusFrom, radiusTo]);
1459
+ }
1460
+ if (hasElevation) {
1461
+ out.elevation = interpolate(t, [0, 1], [elevationFrom, elevationTo]);
1462
+ }
1463
+ if (hasColor) {
1464
+ out.shadowColor = interpolateColor(t, [0, 1], [colorFrom, colorTo]);
1465
+ }
1466
+ if (hasOffset) {
1467
+ out.shadowOffset = {
1468
+ width: interpolate(t, [0, 1], [offsetWFrom, offsetWTo]),
1469
+ height: interpolate(t, [0, 1], [offsetHFrom, offsetHTo])
1470
+ };
1471
+ }
1472
+ return out;
1473
+ });
1474
+ }
2632
1475
  function useVariants(variants, initial) {
2633
1476
  const variantsRef = useRef(variants);
2634
1477
  return useMemo(() => {
@@ -2662,6 +1505,6 @@ function useVariants(variants, initial) {
2662
1505
  }, []);
2663
1506
  }
2664
1507
 
2665
- export { Motion, MotionConfig, MotionImage, MotionPressable, MotionScrollView, MotionText, MotionView, Presence, buildReleaseAnimation, createMotionComponent, ensureWorkletEasing, resolveAnimatableValue, resolveTransition, useAnimation, useGesture, useMotionConfig, useMotionValue, usePresence, useScroll, useShouldReduceMotion, useSpring, useTransform, useVariants };
1508
+ export { Motion, MotionConfig, MotionImage, MotionPressable, MotionScrollView, MotionText, MotionView, Presence, buildReleaseAnimation, createMotionComponent, ensureWorkletEasing, resolveAnimatableValue, resolveTransition, useAnimation, useBooleanSpring, useColorTransition, useGesture, useMotionConfig, useMotionValue, usePresence, useScroll, useShadow, useShouldReduceMotion, useSpring, useTransform, useVariants };
2666
1509
  //# sourceMappingURL=index.mjs.map
2667
1510
  //# sourceMappingURL=index.mjs.map