@onlynative/inertia 0.0.1-alpha.7 → 0.0.1-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/gestureLayer/index.d.mts +119 -0
- package/dist/gestureLayer/index.d.ts +119 -0
- package/dist/gestureLayer/index.js +1745 -0
- package/dist/gestureLayer/index.js.map +1 -0
- package/dist/gestureLayer/index.mjs +1743 -0
- package/dist/gestureLayer/index.mjs.map +1 -0
- package/dist/index.d.mts +114 -74
- package/dist/index.d.ts +114 -74
- package/dist/index.js +279 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +279 -44
- package/dist/index.mjs.map +1 -1
- package/dist/motion/Image.d.mts +1 -1
- package/dist/motion/Image.d.ts +1 -1
- package/dist/motion/Image.js +178 -4
- package/dist/motion/Image.js.map +1 -1
- package/dist/motion/Image.mjs +180 -6
- package/dist/motion/Image.mjs.map +1 -1
- package/dist/motion/Pressable.d.mts +1 -1
- package/dist/motion/Pressable.d.ts +1 -1
- package/dist/motion/Pressable.js +178 -4
- package/dist/motion/Pressable.js.map +1 -1
- package/dist/motion/Pressable.mjs +180 -6
- package/dist/motion/Pressable.mjs.map +1 -1
- package/dist/motion/ScrollView.d.mts +1 -1
- package/dist/motion/ScrollView.d.ts +1 -1
- package/dist/motion/ScrollView.js +178 -4
- package/dist/motion/ScrollView.js.map +1 -1
- package/dist/motion/ScrollView.mjs +180 -6
- package/dist/motion/ScrollView.mjs.map +1 -1
- package/dist/motion/Text.d.mts +1 -1
- package/dist/motion/Text.d.ts +1 -1
- package/dist/motion/Text.js +178 -4
- package/dist/motion/Text.js.map +1 -1
- package/dist/motion/Text.mjs +180 -6
- package/dist/motion/Text.mjs.map +1 -1
- package/dist/motion/View.d.mts +1 -1
- package/dist/motion/View.d.ts +1 -1
- package/dist/motion/View.js +178 -4
- package/dist/motion/View.js.map +1 -1
- package/dist/motion/View.mjs +180 -6
- package/dist/motion/View.mjs.map +1 -1
- package/dist/touch/index.d.mts +146 -0
- package/dist/touch/index.d.ts +146 -0
- package/dist/touch/index.js +166 -0
- package/dist/touch/index.js.map +1 -0
- package/dist/touch/index.mjs +164 -0
- package/dist/touch/index.mjs.map +1 -0
- package/dist/{types-NmNeJjo1.d.mts → types-BwyvoH2V.d.mts} +24 -4
- package/dist/{types-NmNeJjo1.d.ts → types-BwyvoH2V.d.ts} +24 -4
- package/dist/useGesture-BPPp9LhV.d.ts +84 -0
- package/dist/useGesture-BnBF4OtT.d.mts +84 -0
- package/llms.txt +12 -3
- package/package.json +15 -1
- package/src/gestureLayer/index.ts +21 -0
- package/src/gestureLayer/useGestureLayer.ts +285 -0
- package/src/index.ts +7 -0
- package/src/layout/index.ts +15 -0
- package/src/layout/sharedRegistry.ts +108 -0
- package/src/layout/useSharedLayout.ts +289 -0
- package/src/motion/createMotionComponent.tsx +60 -4
- package/src/touch/index.ts +18 -0
- package/src/touch/useTouchDrag.ts +289 -0
- package/src/types.ts +23 -3
- package/src/values/index.ts +11 -0
- package/src/values/useBooleanSpring.ts +33 -0
- package/src/values/useColorTransition.ts +72 -0
- package/src/values/useShadow.ts +116 -0
|
@@ -0,0 +1,1743 @@
|
|
|
1
|
+
import { createContext, useEffect, useMemo, useCallback, useContext } from 'react';
|
|
2
|
+
import { useSharedValue, useAnimatedStyle, interpolateColor, useReducedMotion, withRepeat, withDelay, withDecay, withTiming, Easing, withSpring } from 'react-native-reanimated';
|
|
3
|
+
import { Platform, TurboModuleRegistry } from 'react-native';
|
|
4
|
+
|
|
5
|
+
var __typeError = (msg) => {
|
|
6
|
+
throw TypeError(msg);
|
|
7
|
+
};
|
|
8
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
+
}) : x)(function(x) {
|
|
11
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
+
});
|
|
14
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
15
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
16
|
+
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);
|
|
17
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
18
|
+
var DEFAULT_MOTION_CONFIG = {
|
|
19
|
+
reducedMotion: "user"
|
|
20
|
+
};
|
|
21
|
+
var MotionConfigContext = createContext(
|
|
22
|
+
DEFAULT_MOTION_CONFIG
|
|
23
|
+
);
|
|
24
|
+
function useMotionConfig() {
|
|
25
|
+
return useContext(MotionConfigContext);
|
|
26
|
+
}
|
|
27
|
+
function useShouldReduceMotion() {
|
|
28
|
+
const { reducedMotion } = useMotionConfig();
|
|
29
|
+
const osReduced = useReducedMotion();
|
|
30
|
+
if (reducedMotion === "never") return false;
|
|
31
|
+
if (reducedMotion === "always") return true;
|
|
32
|
+
return osReduced;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ../../node_modules/react-native-worklets/lib/module/logger.js
|
|
36
|
+
var PREFIX = "[Worklets]";
|
|
37
|
+
function formatMessage(message) {
|
|
38
|
+
return `${PREFIX} ${message}`;
|
|
39
|
+
}
|
|
40
|
+
var logger = {
|
|
41
|
+
warn(message) {
|
|
42
|
+
console.warn(formatMessage(message));
|
|
43
|
+
},
|
|
44
|
+
error(message) {
|
|
45
|
+
console.error(formatMessage(message));
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// ../../node_modules/react-native-worklets/lib/module/runtimeKind.js
|
|
50
|
+
var RuntimeKind = /* @__PURE__ */ (function(RuntimeKind2) {
|
|
51
|
+
RuntimeKind2[RuntimeKind2["ReactNative"] = 1] = "ReactNative";
|
|
52
|
+
RuntimeKind2[RuntimeKind2["UI"] = 2] = "UI";
|
|
53
|
+
RuntimeKind2[RuntimeKind2["Worker"] = 3] = "Worker";
|
|
54
|
+
return RuntimeKind2;
|
|
55
|
+
})({});
|
|
56
|
+
if (globalThis.__RUNTIME_KIND === void 0) {
|
|
57
|
+
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsError.js
|
|
61
|
+
function WorkletsErrorConstructor(message) {
|
|
62
|
+
"worklet";
|
|
63
|
+
const prefix = "[Worklets]";
|
|
64
|
+
const errorInstance = new Error(message ? `${prefix} ${message}` : prefix);
|
|
65
|
+
errorInstance.name = `WorkletsError`;
|
|
66
|
+
return errorInstance;
|
|
67
|
+
}
|
|
68
|
+
function registerWorkletsError() {
|
|
69
|
+
"worklet";
|
|
70
|
+
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
|
|
71
|
+
globalThis.WorkletsError = WorkletsErrorConstructor;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
var WorkletsError = WorkletsErrorConstructor;
|
|
75
|
+
|
|
76
|
+
// ../../node_modules/react-native-worklets/lib/module/bundleUnpacker.js
|
|
77
|
+
var handleCache = /* @__PURE__ */ new WeakMap();
|
|
78
|
+
function bundleValueUnpacker(objectToUnpack, category, remoteFunctionName) {
|
|
79
|
+
const workletHash = objectToUnpack.__workletHash;
|
|
80
|
+
if (workletHash !== void 0) {
|
|
81
|
+
return getWorklet(workletHash, objectToUnpack.__closure);
|
|
82
|
+
} else if (objectToUnpack.__init !== void 0) {
|
|
83
|
+
let value = handleCache.get(objectToUnpack);
|
|
84
|
+
if (value === void 0) {
|
|
85
|
+
value = objectToUnpack.__init();
|
|
86
|
+
handleCache.set(objectToUnpack, value);
|
|
87
|
+
}
|
|
88
|
+
return value;
|
|
89
|
+
} else if (category === "RemoteFunction") {
|
|
90
|
+
const remoteFunctionHolder = () => {
|
|
91
|
+
const label = remoteFunctionName ? `function \`${remoteFunctionName}\`` : "anonymous function";
|
|
92
|
+
throw new WorkletsError(`Tried to synchronously call a non-worklet ${label} on the UI thread.
|
|
93
|
+
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.`);
|
|
94
|
+
};
|
|
95
|
+
remoteFunctionHolder.__remoteFunction = objectToUnpack;
|
|
96
|
+
return remoteFunctionHolder;
|
|
97
|
+
} else {
|
|
98
|
+
throw new WorkletsError(`Data type in category "${category}" not recognized by value unpacker: "${globalThis._toString(objectToUnpack)}".`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function getWorklet(workletHash, closureVariables) {
|
|
102
|
+
let worklet;
|
|
103
|
+
if (__DEV__) {
|
|
104
|
+
try {
|
|
105
|
+
worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
|
|
106
|
+
} catch (_e) {
|
|
107
|
+
logger.error("Unable to resolve worklet with hash " + workletHash + ". Try reloading the app.");
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
|
|
111
|
+
}
|
|
112
|
+
return worklet;
|
|
113
|
+
}
|
|
114
|
+
var metroRequire = globalThis.__r;
|
|
115
|
+
function getWorkletFromMetroRequire(workletHash, closureVariables) {
|
|
116
|
+
const factory = metroRequire(workletHash).default;
|
|
117
|
+
return factory(closureVariables);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ../../node_modules/react-native-worklets/lib/module/callGuard.js
|
|
121
|
+
function callGuardDEV(fn, ...args) {
|
|
122
|
+
"worklet";
|
|
123
|
+
try {
|
|
124
|
+
return fn(...args);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (globalThis.__workletsModuleProxy) {
|
|
127
|
+
const {
|
|
128
|
+
message,
|
|
129
|
+
stack,
|
|
130
|
+
name,
|
|
131
|
+
jsEngine
|
|
132
|
+
} = error;
|
|
133
|
+
globalThis.__workletsModuleProxy.reportFatalErrorOnJS(message, stack ?? "", name ?? "WorkletsError", jsEngine ?? "Worklets");
|
|
134
|
+
} else {
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function setupCallGuard() {
|
|
140
|
+
"worklet";
|
|
141
|
+
if (!globalThis.__callGuardDEV) {
|
|
142
|
+
globalThis.__callGuardDEV = callGuardDEV;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ../../node_modules/react-native-worklets/lib/module/errors.js
|
|
147
|
+
var _workletStackDetails = /* @__PURE__ */ new Map();
|
|
148
|
+
function registerWorkletStackDetails(hash, stackDetails) {
|
|
149
|
+
_workletStackDetails.set(hash, stackDetails);
|
|
150
|
+
}
|
|
151
|
+
function getBundleOffset(error) {
|
|
152
|
+
const frame = error.stack?.split("\n")?.[0];
|
|
153
|
+
if (frame) {
|
|
154
|
+
const parsedFrame = /@([^@]+):(\d+):(\d+)/.exec(frame);
|
|
155
|
+
if (parsedFrame) {
|
|
156
|
+
const [, file, line, col] = parsedFrame;
|
|
157
|
+
return [file, Number(line), Number(col)];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return ["unknown", 0, 0];
|
|
161
|
+
}
|
|
162
|
+
function processStack(stack) {
|
|
163
|
+
if (stack === "" || stack === void 0) {
|
|
164
|
+
return void 0;
|
|
165
|
+
}
|
|
166
|
+
const workletStackEntries = stack.match(/worklet_(\d+):(\d+):(\d+)/g);
|
|
167
|
+
let result = stack;
|
|
168
|
+
workletStackEntries?.forEach((match) => {
|
|
169
|
+
const [, hash, origLine, origCol] = match.split(/:|_/).map(Number);
|
|
170
|
+
const errorDetails = _workletStackDetails.get(hash);
|
|
171
|
+
if (!errorDetails) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const [error, lineOffset, colOffset] = errorDetails;
|
|
175
|
+
const [bundleFile, bundleLine, bundleCol] = getBundleOffset(error);
|
|
176
|
+
const line = origLine + bundleLine + lineOffset;
|
|
177
|
+
const col = origCol + bundleCol + colOffset;
|
|
178
|
+
result = result.replace(match, `${bundleFile}:${line}:${col}`);
|
|
179
|
+
});
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
function reportFatalRemoteError({
|
|
183
|
+
message,
|
|
184
|
+
stack,
|
|
185
|
+
name,
|
|
186
|
+
jsEngine
|
|
187
|
+
}, force) {
|
|
188
|
+
const error = new WorkletsError();
|
|
189
|
+
error.message = message;
|
|
190
|
+
error.stack = processStack(stack);
|
|
191
|
+
error.name = name;
|
|
192
|
+
error.jsEngine = jsEngine;
|
|
193
|
+
if (force) {
|
|
194
|
+
throw error;
|
|
195
|
+
} else {
|
|
196
|
+
globalThis.ErrorUtils.reportFatalError(error);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function registerReportFatalRemoteError() {
|
|
200
|
+
globalThis.__reportFatalRemoteError = reportFatalRemoteError;
|
|
201
|
+
}
|
|
202
|
+
var IS_JEST = !!process.env.JEST_WORKER_ID;
|
|
203
|
+
var IS_WEB = Platform.OS === "web";
|
|
204
|
+
var IS_WINDOWS = Platform.OS === "windows";
|
|
205
|
+
var SHOULD_BE_USE_WEB = IS_JEST || IS_WEB || IS_WINDOWS;
|
|
206
|
+
|
|
207
|
+
// ../../node_modules/react-native-worklets/lib/module/PlatformChecker/index.js
|
|
208
|
+
var IS_JEST2 = false;
|
|
209
|
+
var SHOULD_BE_USE_WEB2 = false;
|
|
210
|
+
if (globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
211
|
+
IS_JEST2 = IS_JEST;
|
|
212
|
+
SHOULD_BE_USE_WEB2 = SHOULD_BE_USE_WEB;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/common/setImmediatePolyfill.js
|
|
216
|
+
function setupSetImmediate() {
|
|
217
|
+
"worklet";
|
|
218
|
+
const setImmediatePolyfill = (callback, ...args) => {
|
|
219
|
+
return setTimeout(callback, 0, ...args);
|
|
220
|
+
};
|
|
221
|
+
const clearImmediatePolyfill = (immediateHandle) => {
|
|
222
|
+
clearTimeout(immediateHandle);
|
|
223
|
+
};
|
|
224
|
+
globalThis.setImmediate = setImmediatePolyfill;
|
|
225
|
+
globalThis.clearImmediate = clearImmediatePolyfill;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/common/setIntervalPolyfill.js
|
|
229
|
+
function setupSetInterval() {
|
|
230
|
+
"worklet";
|
|
231
|
+
const intervalHandleToTimeoutHandle = /* @__PURE__ */ new Map();
|
|
232
|
+
const setIntervalPolyfill = (callback, delay = 0, ...args) => {
|
|
233
|
+
let intervalHandle = 0;
|
|
234
|
+
const repeatingCallback = () => {
|
|
235
|
+
const timeoutHandle = setTimeout(repeatingCallback, delay);
|
|
236
|
+
intervalHandleToTimeoutHandle.set(intervalHandle, timeoutHandle);
|
|
237
|
+
callback(...args);
|
|
238
|
+
};
|
|
239
|
+
intervalHandle = setTimeout(repeatingCallback, delay);
|
|
240
|
+
intervalHandleToTimeoutHandle.set(intervalHandle, intervalHandle);
|
|
241
|
+
return intervalHandle;
|
|
242
|
+
};
|
|
243
|
+
const clearIntervalPolyfill = (intervalHandle) => {
|
|
244
|
+
const timeoutHandle = intervalHandleToTimeoutHandle.get(intervalHandle);
|
|
245
|
+
clearTimeout(timeoutHandle);
|
|
246
|
+
intervalHandleToTimeoutHandle.delete(intervalHandle);
|
|
247
|
+
};
|
|
248
|
+
globalThis.setInterval = setIntervalPolyfill;
|
|
249
|
+
globalThis.clearInterval = clearIntervalPolyfill;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js
|
|
253
|
+
function mockedRequestAnimationFrame(callback) {
|
|
254
|
+
return setTimeout(() => callback(performance.now()), 0);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// ../../node_modules/react-native-worklets/lib/module/isSynchronizable.js
|
|
258
|
+
function isSynchronizable(value) {
|
|
259
|
+
return typeof value === "object" && value !== null && "__synchronizableRef" in value && value.__synchronizableRef === true;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ../../node_modules/react-native-worklets/lib/module/serializableMappingCache.js
|
|
263
|
+
var serializableMappingFlag = /* @__PURE__ */ Symbol("serializable flag");
|
|
264
|
+
var cache = SHOULD_BE_USE_WEB2 ? null : /* @__PURE__ */ new WeakMap();
|
|
265
|
+
var serializableMappingCache = SHOULD_BE_USE_WEB2 ? {
|
|
266
|
+
set() {
|
|
267
|
+
},
|
|
268
|
+
get() {
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
} : {
|
|
272
|
+
set(serializable, serializableRef) {
|
|
273
|
+
cache.set(serializable, serializableRef || serializableMappingFlag);
|
|
274
|
+
},
|
|
275
|
+
get: cache.get.bind(cache)
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// ../../node_modules/react-native-worklets/lib/module/utils/jsVersion.js
|
|
279
|
+
var jsVersion = "0.5.1";
|
|
280
|
+
|
|
281
|
+
// ../../node_modules/react-native-worklets/lib/module/workletFunction.js
|
|
282
|
+
function isWorkletFunction(value) {
|
|
283
|
+
"worklet";
|
|
284
|
+
return (
|
|
285
|
+
// `__workletHash` isn't extracted in Worklet Runtimes.
|
|
286
|
+
typeof value === "function" && !!value.__workletHash
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsModule/JSWorklets.js
|
|
291
|
+
function createJSWorkletsModule() {
|
|
292
|
+
return new JSWorklets();
|
|
293
|
+
}
|
|
294
|
+
var requestAnimationFrameImpl = IS_JEST2 || !globalThis.requestAnimationFrame ? mockedRequestAnimationFrame : globalThis.requestAnimationFrame;
|
|
295
|
+
var JSWorklets = class {
|
|
296
|
+
createSerializable() {
|
|
297
|
+
throw new WorkletsError("createSerializable should never be called in JSWorklets.");
|
|
298
|
+
}
|
|
299
|
+
createSerializableString() {
|
|
300
|
+
throw new WorkletsError("createSerializableString should never be called in JSWorklets.");
|
|
301
|
+
}
|
|
302
|
+
createSerializableNumber() {
|
|
303
|
+
throw new WorkletsError("createSerializableNumber should never be called in JSWorklets.");
|
|
304
|
+
}
|
|
305
|
+
createSerializableBoolean() {
|
|
306
|
+
throw new WorkletsError("createSerializableBoolean should never be called in JSWorklets.");
|
|
307
|
+
}
|
|
308
|
+
createSerializableBigInt() {
|
|
309
|
+
throw new WorkletsError("createSerializableBigInt should never be called in JSWorklets.");
|
|
310
|
+
}
|
|
311
|
+
createSerializableUndefined() {
|
|
312
|
+
throw new WorkletsError("createSerializableUndefined should never be called in JSWorklets.");
|
|
313
|
+
}
|
|
314
|
+
createSerializableNull() {
|
|
315
|
+
throw new WorkletsError("createSerializableNull should never be called in JSWorklets.");
|
|
316
|
+
}
|
|
317
|
+
createSerializableTurboModuleLike() {
|
|
318
|
+
throw new WorkletsError("createSerializableTurboModuleLike should never be called in JSWorklets.");
|
|
319
|
+
}
|
|
320
|
+
createSerializableObject() {
|
|
321
|
+
throw new WorkletsError("createSerializableObject should never be called in JSWorklets.");
|
|
322
|
+
}
|
|
323
|
+
createSerializableMap() {
|
|
324
|
+
throw new WorkletsError("createSerializableMap should never be called in JSWorklets.");
|
|
325
|
+
}
|
|
326
|
+
createSerializableSet() {
|
|
327
|
+
throw new WorkletsError("createSerializableSet should never be called in JSWorklets.");
|
|
328
|
+
}
|
|
329
|
+
createSerializableImport() {
|
|
330
|
+
throw new WorkletsError("createSerializableImport should never be called in JSWorklets.");
|
|
331
|
+
}
|
|
332
|
+
createSerializableHostObject() {
|
|
333
|
+
throw new WorkletsError("createSerializableHostObject should never be called in JSWorklets.");
|
|
334
|
+
}
|
|
335
|
+
createSerializableArray() {
|
|
336
|
+
throw new WorkletsError("createSerializableArray should never be called in JSWorklets.");
|
|
337
|
+
}
|
|
338
|
+
createSerializableInitializer() {
|
|
339
|
+
throw new WorkletsError("createSerializableInitializer should never be called in JSWorklets.");
|
|
340
|
+
}
|
|
341
|
+
createSerializableFunction() {
|
|
342
|
+
throw new WorkletsError("createSerializableFunction should never be called in JSWorklets.");
|
|
343
|
+
}
|
|
344
|
+
createSerializableWorklet() {
|
|
345
|
+
throw new WorkletsError("createSerializableWorklet should never be called in JSWorklets.");
|
|
346
|
+
}
|
|
347
|
+
scheduleOnUI(worklet) {
|
|
348
|
+
requestAnimationFrameImpl(worklet);
|
|
349
|
+
}
|
|
350
|
+
executeOnUIRuntimeSync() {
|
|
351
|
+
throw new WorkletsError("`executeOnUIRuntimeSync` is not available in JSWorklets.");
|
|
352
|
+
}
|
|
353
|
+
createWorkletRuntime() {
|
|
354
|
+
throw new WorkletsError("createWorkletRuntime is not available in JSWorklets.");
|
|
355
|
+
}
|
|
356
|
+
scheduleOnRuntime() {
|
|
357
|
+
throw new WorkletsError("scheduleOnRuntime is not available in JSWorklets.");
|
|
358
|
+
}
|
|
359
|
+
createSynchronizable() {
|
|
360
|
+
throw new WorkletsError("createSynchronizable should never be called in JSWorklets.");
|
|
361
|
+
}
|
|
362
|
+
synchronizableGetDirty() {
|
|
363
|
+
throw new WorkletsError("synchronizableGetDirty should never be called in JSWorklets.");
|
|
364
|
+
}
|
|
365
|
+
synchronizableGetBlocking() {
|
|
366
|
+
throw new WorkletsError("synchronizableGetBlocking should never be called in JSWorklets.");
|
|
367
|
+
}
|
|
368
|
+
synchronizableSetBlocking() {
|
|
369
|
+
throw new WorkletsError("synchronizableSetBlocking should never be called in JSWorklets.");
|
|
370
|
+
}
|
|
371
|
+
synchronizableLock() {
|
|
372
|
+
throw new WorkletsError("synchronizableLock should never be called in JSWorklets.");
|
|
373
|
+
}
|
|
374
|
+
synchronizableUnlock() {
|
|
375
|
+
throw new WorkletsError("synchronizableUnlock should never be called in JSWorklets.");
|
|
376
|
+
}
|
|
377
|
+
reportFatalErrorOnJS() {
|
|
378
|
+
throw new WorkletsError("reportFatalErrorOnJS should never be called in JSWorklets.");
|
|
379
|
+
}
|
|
380
|
+
getStaticFeatureFlag() {
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
setDynamicFeatureFlag() {
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
var NativeWorkletsModule_default = TurboModuleRegistry.get("WorkletsModule");
|
|
387
|
+
|
|
388
|
+
// ../../node_modules/react-native-worklets/lib/module/specs/index.js
|
|
389
|
+
var WorkletsTurboModule = globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative ? NativeWorkletsModule_default : (
|
|
390
|
+
// In Bundle Mode, on Worklet Runtimes `RNWorkletsTurboModule` isn't
|
|
391
|
+
// available and shouldn't be accessed. We return null here
|
|
392
|
+
// to keep the same codebase for the Bundle Mode and legacy behavior.
|
|
393
|
+
null
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
// ../../node_modules/react-native-worklets/lib/module/utils/checkCppVersion.js
|
|
397
|
+
function checkCppVersion() {
|
|
398
|
+
const cppVersion = global._WORKLETS_VERSION_CPP;
|
|
399
|
+
if (cppVersion === void 0) {
|
|
400
|
+
logger.warn(`Couldn't determine the version of the native part of Worklets.
|
|
401
|
+
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#couldnt-determine-the-version-of-the-native-part-of-worklets\` for more details.`);
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
const ok = matchVersion(jsVersion, cppVersion);
|
|
405
|
+
if (!ok) {
|
|
406
|
+
throw new WorkletsError(`Mismatch between JavaScript part and native part of Worklets (${jsVersion} vs ${cppVersion}).
|
|
407
|
+
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-part-and-native-part-of-worklets\` for more details.`);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
function matchVersion(version1, version2) {
|
|
411
|
+
if (version1.match(/^\d+\.\d+\.\d+$/) && version2.match(/^\d+\.\d+\.\d+$/)) {
|
|
412
|
+
const [major1, minor1] = version1.split(".");
|
|
413
|
+
const [major2, minor2] = version2.split(".");
|
|
414
|
+
return major1 === major2 && minor1 === minor2;
|
|
415
|
+
} else {
|
|
416
|
+
return version1 === version2;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsModule/NativeWorklets.js
|
|
421
|
+
function createNativeWorkletsModule() {
|
|
422
|
+
return new NativeWorklets();
|
|
423
|
+
}
|
|
424
|
+
var _workletsModuleProxy, _serializableUndefined, _serializableNull, _serializableTrue, _serializableFalse;
|
|
425
|
+
var NativeWorklets = class {
|
|
426
|
+
constructor() {
|
|
427
|
+
__privateAdd(this, _workletsModuleProxy);
|
|
428
|
+
__privateAdd(this, _serializableUndefined);
|
|
429
|
+
__privateAdd(this, _serializableNull);
|
|
430
|
+
__privateAdd(this, _serializableTrue);
|
|
431
|
+
__privateAdd(this, _serializableFalse);
|
|
432
|
+
globalThis._WORKLETS_VERSION_JS = jsVersion;
|
|
433
|
+
if (global.__workletsModuleProxy === void 0 && globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
434
|
+
WorkletsTurboModule?.installTurboModule();
|
|
435
|
+
}
|
|
436
|
+
if (global.__workletsModuleProxy === void 0) {
|
|
437
|
+
throw new WorkletsError(`Native part of Worklets doesn't seem to be initialized.
|
|
438
|
+
See https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#native-part-of-worklets-doesnt-seem-to-be-initialized for more details.`);
|
|
439
|
+
}
|
|
440
|
+
if (__DEV__) {
|
|
441
|
+
checkCppVersion();
|
|
442
|
+
}
|
|
443
|
+
__privateSet(this, _workletsModuleProxy, global.__workletsModuleProxy);
|
|
444
|
+
__privateSet(this, _serializableNull, __privateGet(this, _workletsModuleProxy).createSerializableNull());
|
|
445
|
+
__privateSet(this, _serializableUndefined, __privateGet(this, _workletsModuleProxy).createSerializableUndefined());
|
|
446
|
+
__privateSet(this, _serializableTrue, __privateGet(this, _workletsModuleProxy).createSerializableBoolean(true));
|
|
447
|
+
__privateSet(this, _serializableFalse, __privateGet(this, _workletsModuleProxy).createSerializableBoolean(false));
|
|
448
|
+
}
|
|
449
|
+
createSerializable(value, shouldPersistRemote, nativeStateSource) {
|
|
450
|
+
return __privateGet(this, _workletsModuleProxy).createSerializable(value, shouldPersistRemote, nativeStateSource);
|
|
451
|
+
}
|
|
452
|
+
createSerializableImport(from, to) {
|
|
453
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableImport(from, to);
|
|
454
|
+
}
|
|
455
|
+
createSerializableString(str) {
|
|
456
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableString(str);
|
|
457
|
+
}
|
|
458
|
+
createSerializableNumber(num) {
|
|
459
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableNumber(num);
|
|
460
|
+
}
|
|
461
|
+
createSerializableBoolean(bool) {
|
|
462
|
+
return bool ? __privateGet(this, _serializableTrue) : __privateGet(this, _serializableFalse);
|
|
463
|
+
}
|
|
464
|
+
createSerializableBigInt(bigInt) {
|
|
465
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableBigInt(bigInt);
|
|
466
|
+
}
|
|
467
|
+
createSerializableUndefined() {
|
|
468
|
+
return __privateGet(this, _serializableUndefined);
|
|
469
|
+
}
|
|
470
|
+
createSerializableNull() {
|
|
471
|
+
return __privateGet(this, _serializableNull);
|
|
472
|
+
}
|
|
473
|
+
createSerializableTurboModuleLike(props, proto) {
|
|
474
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableTurboModuleLike(props, proto);
|
|
475
|
+
}
|
|
476
|
+
createSerializableObject(obj, shouldRetainRemote, nativeStateSource) {
|
|
477
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableObject(obj, shouldRetainRemote, nativeStateSource);
|
|
478
|
+
}
|
|
479
|
+
createSerializableHostObject(obj) {
|
|
480
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableHostObject(obj);
|
|
481
|
+
}
|
|
482
|
+
createSerializableArray(array, shouldRetainRemote) {
|
|
483
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableArray(array, shouldRetainRemote);
|
|
484
|
+
}
|
|
485
|
+
createSerializableMap(keys, values) {
|
|
486
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableMap(keys, values);
|
|
487
|
+
}
|
|
488
|
+
createSerializableSet(values) {
|
|
489
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableSet(values);
|
|
490
|
+
}
|
|
491
|
+
createSerializableInitializer(obj) {
|
|
492
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableInitializer(obj);
|
|
493
|
+
}
|
|
494
|
+
createSerializableFunction(func) {
|
|
495
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableFunction(func);
|
|
496
|
+
}
|
|
497
|
+
createSerializableWorklet(worklet, shouldPersistRemote) {
|
|
498
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableWorklet(worklet, shouldPersistRemote);
|
|
499
|
+
}
|
|
500
|
+
scheduleOnUI(serializable) {
|
|
501
|
+
return __privateGet(this, _workletsModuleProxy).scheduleOnUI(serializable);
|
|
502
|
+
}
|
|
503
|
+
executeOnUIRuntimeSync(serializable) {
|
|
504
|
+
return __privateGet(this, _workletsModuleProxy).executeOnUIRuntimeSync(serializable);
|
|
505
|
+
}
|
|
506
|
+
createWorkletRuntime(name, initializer, useDefaultQueue, customQueue, enableEventLoop) {
|
|
507
|
+
return __privateGet(this, _workletsModuleProxy).createWorkletRuntime(name, initializer, useDefaultQueue, customQueue, enableEventLoop);
|
|
508
|
+
}
|
|
509
|
+
scheduleOnRuntime(workletRuntime, serializableWorklet) {
|
|
510
|
+
return __privateGet(this, _workletsModuleProxy).scheduleOnRuntime(workletRuntime, serializableWorklet);
|
|
511
|
+
}
|
|
512
|
+
createSynchronizable(value) {
|
|
513
|
+
return __privateGet(this, _workletsModuleProxy).createSynchronizable(value);
|
|
514
|
+
}
|
|
515
|
+
synchronizableGetDirty(synchronizableRef) {
|
|
516
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableGetDirty(synchronizableRef);
|
|
517
|
+
}
|
|
518
|
+
synchronizableGetBlocking(synchronizableRef) {
|
|
519
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableGetBlocking(synchronizableRef);
|
|
520
|
+
}
|
|
521
|
+
synchronizableSetBlocking(synchronizableRef, value) {
|
|
522
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableSetBlocking(synchronizableRef, value);
|
|
523
|
+
}
|
|
524
|
+
synchronizableLock(synchronizableRef) {
|
|
525
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableLock(synchronizableRef);
|
|
526
|
+
}
|
|
527
|
+
synchronizableUnlock(synchronizableRef) {
|
|
528
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableUnlock(synchronizableRef);
|
|
529
|
+
}
|
|
530
|
+
reportFatalErrorOnJS(message, stack, name, jsEngine) {
|
|
531
|
+
return __privateGet(this, _workletsModuleProxy).reportFatalErrorOnJS(message, stack, name, jsEngine);
|
|
532
|
+
}
|
|
533
|
+
getStaticFeatureFlag(name) {
|
|
534
|
+
return __privateGet(this, _workletsModuleProxy).getStaticFeatureFlag(name);
|
|
535
|
+
}
|
|
536
|
+
setDynamicFeatureFlag(name, value) {
|
|
537
|
+
__privateGet(this, _workletsModuleProxy).setDynamicFeatureFlag(name, value);
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
_workletsModuleProxy = new WeakMap();
|
|
541
|
+
_serializableUndefined = new WeakMap();
|
|
542
|
+
_serializableNull = new WeakMap();
|
|
543
|
+
_serializableTrue = new WeakMap();
|
|
544
|
+
_serializableFalse = new WeakMap();
|
|
545
|
+
|
|
546
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsModule/workletsModuleInstance.js
|
|
547
|
+
var WorkletsModule = SHOULD_BE_USE_WEB2 ? createJSWorkletsModule() : createNativeWorkletsModule();
|
|
548
|
+
|
|
549
|
+
// ../../node_modules/react-native-worklets/lib/module/serializable.js
|
|
550
|
+
var MAGIC_KEY = "REANIMATED_MAGIC_KEY";
|
|
551
|
+
function isHostObject(value) {
|
|
552
|
+
"worklet";
|
|
553
|
+
return MAGIC_KEY in value;
|
|
554
|
+
}
|
|
555
|
+
function isPlainJSObject(object) {
|
|
556
|
+
"worklet";
|
|
557
|
+
return Object.getPrototypeOf(object) === Object.prototype;
|
|
558
|
+
}
|
|
559
|
+
function isTurboModuleLike(object) {
|
|
560
|
+
return isHostObject(Object.getPrototypeOf(object));
|
|
561
|
+
}
|
|
562
|
+
function getFromCache(value) {
|
|
563
|
+
const cached = serializableMappingCache.get(value);
|
|
564
|
+
if (cached === serializableMappingFlag) {
|
|
565
|
+
return value;
|
|
566
|
+
}
|
|
567
|
+
return cached;
|
|
568
|
+
}
|
|
569
|
+
var INACCESSIBLE_OBJECT = {
|
|
570
|
+
__init: () => {
|
|
571
|
+
"worklet";
|
|
572
|
+
return new Proxy({}, {
|
|
573
|
+
get: (_, prop) => {
|
|
574
|
+
if (prop === "_isReanimatedSharedValue" || prop === "__remoteFunction") {
|
|
575
|
+
return false;
|
|
576
|
+
}
|
|
577
|
+
throw new WorkletsError(`Trying to access property \`${String(prop)}\` of an object which cannot be sent to the UI runtime.`);
|
|
578
|
+
},
|
|
579
|
+
set: () => {
|
|
580
|
+
throw new WorkletsError("Trying to write to an object which cannot be sent to the UI runtime.");
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
var VALID_ARRAY_VIEWS_NAMES = ["Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array", "DataView"];
|
|
586
|
+
var DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD = 30;
|
|
587
|
+
var processedObjectAtThresholdDepth;
|
|
588
|
+
function createSerializableWeb(value) {
|
|
589
|
+
return value;
|
|
590
|
+
}
|
|
591
|
+
function createSerializableNative(value, shouldPersistRemote = false, depth = 0) {
|
|
592
|
+
detectCyclicObject(value, depth);
|
|
593
|
+
const isObject = typeof value === "object";
|
|
594
|
+
const isFunction = typeof value === "function";
|
|
595
|
+
if (typeof value === "string") {
|
|
596
|
+
return cloneString(value);
|
|
597
|
+
}
|
|
598
|
+
if (typeof value === "number") {
|
|
599
|
+
return cloneNumber(value);
|
|
600
|
+
}
|
|
601
|
+
if (typeof value === "boolean") {
|
|
602
|
+
return cloneBoolean(value);
|
|
603
|
+
}
|
|
604
|
+
if (typeof value === "bigint") {
|
|
605
|
+
return cloneBigInt(value);
|
|
606
|
+
}
|
|
607
|
+
if (value === void 0) {
|
|
608
|
+
return cloneUndefined();
|
|
609
|
+
}
|
|
610
|
+
if (value === null) {
|
|
611
|
+
return cloneNull();
|
|
612
|
+
}
|
|
613
|
+
if (!isObject && !isFunction || value === null) {
|
|
614
|
+
return clonePrimitive(value, shouldPersistRemote);
|
|
615
|
+
}
|
|
616
|
+
const cached = getFromCache(value);
|
|
617
|
+
if (cached !== void 0) {
|
|
618
|
+
return cached;
|
|
619
|
+
}
|
|
620
|
+
if (Array.isArray(value)) {
|
|
621
|
+
return cloneArray(value, shouldPersistRemote, depth);
|
|
622
|
+
}
|
|
623
|
+
if (globalThis._WORKLETS_BUNDLE_MODE && isFunction && value.__bundleData) {
|
|
624
|
+
return cloneImport(value);
|
|
625
|
+
}
|
|
626
|
+
if (isFunction && !isWorkletFunction(value)) {
|
|
627
|
+
return cloneRemoteFunction(value);
|
|
628
|
+
}
|
|
629
|
+
if (isTurboModuleLike(value)) {
|
|
630
|
+
return cloneTurboModuleLike(value, shouldPersistRemote, depth);
|
|
631
|
+
}
|
|
632
|
+
if (isHostObject(value)) {
|
|
633
|
+
return cloneHostObject(value);
|
|
634
|
+
}
|
|
635
|
+
if (isPlainJSObject(value) && value.__init) {
|
|
636
|
+
return cloneInitializer(value, shouldPersistRemote, depth);
|
|
637
|
+
}
|
|
638
|
+
if (isPlainJSObject(value) && value.__workletContextObjectFactory) {
|
|
639
|
+
return cloneContextObject(value);
|
|
640
|
+
}
|
|
641
|
+
if ((isPlainJSObject(value) || isFunction) && isWorkletFunction(value)) {
|
|
642
|
+
return cloneWorklet(value, shouldPersistRemote, depth);
|
|
643
|
+
}
|
|
644
|
+
if (isSynchronizable(value)) {
|
|
645
|
+
return cloneSynchronizable(value);
|
|
646
|
+
}
|
|
647
|
+
if (isPlainJSObject(value) || isFunction) {
|
|
648
|
+
return clonePlainJSObject(value, shouldPersistRemote, depth);
|
|
649
|
+
}
|
|
650
|
+
if (value instanceof Set) {
|
|
651
|
+
return cloneSet(value);
|
|
652
|
+
}
|
|
653
|
+
if (value instanceof Map) {
|
|
654
|
+
return cloneMap(value);
|
|
655
|
+
}
|
|
656
|
+
if (value instanceof RegExp) {
|
|
657
|
+
return cloneRegExp(value);
|
|
658
|
+
}
|
|
659
|
+
if (value instanceof Error) {
|
|
660
|
+
return cloneError(value);
|
|
661
|
+
}
|
|
662
|
+
if (value instanceof ArrayBuffer) {
|
|
663
|
+
return cloneArrayBuffer(value, shouldPersistRemote);
|
|
664
|
+
}
|
|
665
|
+
if (ArrayBuffer.isView(value)) {
|
|
666
|
+
return cloneArrayBufferView(value);
|
|
667
|
+
}
|
|
668
|
+
return inaccessibleObject(value);
|
|
669
|
+
}
|
|
670
|
+
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
671
|
+
createSerializableNative.__bundleData = {
|
|
672
|
+
imported: "createSerializable",
|
|
673
|
+
// @ts-expect-error resolveWeak is defined by Metro
|
|
674
|
+
source: __require.resolveWeak("./index")
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
var createSerializable = SHOULD_BE_USE_WEB2 ? createSerializableWeb : createSerializableNative;
|
|
678
|
+
function detectCyclicObject(value, depth) {
|
|
679
|
+
if (depth >= DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
|
|
680
|
+
if (depth === DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
|
|
681
|
+
processedObjectAtThresholdDepth = value;
|
|
682
|
+
} else if (value === processedObjectAtThresholdDepth) {
|
|
683
|
+
throw new WorkletsError("Trying to convert a cyclic object to a serializable. This is not supported.");
|
|
684
|
+
}
|
|
685
|
+
} else {
|
|
686
|
+
processedObjectAtThresholdDepth = void 0;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
function clonePrimitive(value, shouldPersistRemote) {
|
|
690
|
+
return WorkletsModule.createSerializable(value, shouldPersistRemote);
|
|
691
|
+
}
|
|
692
|
+
function cloneString(value) {
|
|
693
|
+
return WorkletsModule.createSerializableString(value);
|
|
694
|
+
}
|
|
695
|
+
function cloneNumber(value) {
|
|
696
|
+
return WorkletsModule.createSerializableNumber(value);
|
|
697
|
+
}
|
|
698
|
+
function cloneBoolean(value) {
|
|
699
|
+
return WorkletsModule.createSerializableBoolean(value);
|
|
700
|
+
}
|
|
701
|
+
function cloneBigInt(value) {
|
|
702
|
+
return WorkletsModule.createSerializableBigInt(value);
|
|
703
|
+
}
|
|
704
|
+
function cloneUndefined() {
|
|
705
|
+
return WorkletsModule.createSerializableUndefined();
|
|
706
|
+
}
|
|
707
|
+
function cloneNull() {
|
|
708
|
+
return WorkletsModule.createSerializableNull();
|
|
709
|
+
}
|
|
710
|
+
function cloneObjectProperties(value, shouldPersistRemote, depth) {
|
|
711
|
+
const clonedProps = {};
|
|
712
|
+
for (const [key, element] of Object.entries(value)) {
|
|
713
|
+
if (key === "__initData" && clonedProps.__initData !== void 0) {
|
|
714
|
+
continue;
|
|
715
|
+
}
|
|
716
|
+
clonedProps[key] = createSerializable(element, shouldPersistRemote, depth + 1);
|
|
717
|
+
}
|
|
718
|
+
return clonedProps;
|
|
719
|
+
}
|
|
720
|
+
function cloneInitializer(value, shouldPersistRemote = false, depth = 0) {
|
|
721
|
+
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
|
|
722
|
+
return WorkletsModule.createSerializableInitializer(clonedProps);
|
|
723
|
+
}
|
|
724
|
+
function cloneArray(value, shouldPersistRemote, depth) {
|
|
725
|
+
const clonedElements = value.map((element) => createSerializable(element, shouldPersistRemote, depth + 1));
|
|
726
|
+
const clone = WorkletsModule.createSerializableArray(clonedElements, shouldPersistRemote);
|
|
727
|
+
serializableMappingCache.set(value, clone);
|
|
728
|
+
serializableMappingCache.set(clone);
|
|
729
|
+
freezeObjectInDev(value);
|
|
730
|
+
return clone;
|
|
731
|
+
}
|
|
732
|
+
function cloneRemoteFunction(value) {
|
|
733
|
+
const clone = WorkletsModule.createSerializableFunction(value);
|
|
734
|
+
serializableMappingCache.set(value, clone);
|
|
735
|
+
serializableMappingCache.set(clone);
|
|
736
|
+
freezeObjectInDev(value);
|
|
737
|
+
return clone;
|
|
738
|
+
}
|
|
739
|
+
function cloneHostObject(value) {
|
|
740
|
+
const clone = WorkletsModule.createSerializableHostObject(value);
|
|
741
|
+
serializableMappingCache.set(value, clone);
|
|
742
|
+
serializableMappingCache.set(clone);
|
|
743
|
+
return clone;
|
|
744
|
+
}
|
|
745
|
+
function cloneWorklet(value, shouldPersistRemote, depth) {
|
|
746
|
+
if (__DEV__) {
|
|
747
|
+
const babelVersion = value.__pluginVersion;
|
|
748
|
+
if (babelVersion !== void 0 && babelVersion !== jsVersion) {
|
|
749
|
+
throw new WorkletsError(`Mismatch between JavaScript code version and Worklets Babel plugin version (${jsVersion} vs. ${babelVersion}).
|
|
750
|
+
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-code-version-and-worklets-babel-plugin-version\` for more details.
|
|
751
|
+
Offending code was: \`${getWorkletCode(value)}\``);
|
|
752
|
+
}
|
|
753
|
+
registerWorkletStackDetails(value.__workletHash, value.__stackDetails);
|
|
754
|
+
}
|
|
755
|
+
if (value.__stackDetails) {
|
|
756
|
+
delete value.__stackDetails;
|
|
757
|
+
}
|
|
758
|
+
const clonedProps = cloneObjectProperties(value, true, depth);
|
|
759
|
+
clonedProps.__initData = createSerializable(value.__initData, true, depth + 1);
|
|
760
|
+
const clone = WorkletsModule.createSerializableWorklet(
|
|
761
|
+
clonedProps,
|
|
762
|
+
// TODO: Check after refactor if we can remove shouldPersistRemote parameter (imho it's redundant here since worklets are always persistent)
|
|
763
|
+
// retain all worklets
|
|
764
|
+
true
|
|
765
|
+
);
|
|
766
|
+
serializableMappingCache.set(value, clone);
|
|
767
|
+
serializableMappingCache.set(clone);
|
|
768
|
+
freezeObjectInDev(value);
|
|
769
|
+
return clone;
|
|
770
|
+
}
|
|
771
|
+
function cloneTurboModuleLike(value, shouldPersistRemote, depth) {
|
|
772
|
+
const proto = Object.getPrototypeOf(value);
|
|
773
|
+
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
|
|
774
|
+
const clone = WorkletsModule.createSerializableTurboModuleLike(clonedProps, proto);
|
|
775
|
+
return clone;
|
|
776
|
+
}
|
|
777
|
+
function cloneContextObject(value) {
|
|
778
|
+
const workletContextObjectFactory = value.__workletContextObjectFactory;
|
|
779
|
+
const handle = cloneInitializer({
|
|
780
|
+
__init: () => {
|
|
781
|
+
"worklet";
|
|
782
|
+
return workletContextObjectFactory();
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
serializableMappingCache.set(value, handle);
|
|
786
|
+
return handle;
|
|
787
|
+
}
|
|
788
|
+
function clonePlainJSObject(value, shouldPersistRemote, depth) {
|
|
789
|
+
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
|
|
790
|
+
const clone = WorkletsModule.createSerializableObject(clonedProps, shouldPersistRemote, value);
|
|
791
|
+
serializableMappingCache.set(value, clone);
|
|
792
|
+
serializableMappingCache.set(clone);
|
|
793
|
+
freezeObjectInDev(value);
|
|
794
|
+
return clone;
|
|
795
|
+
}
|
|
796
|
+
function cloneMap(value) {
|
|
797
|
+
const clonedKeys = [];
|
|
798
|
+
const clonedValues = [];
|
|
799
|
+
for (const [key, element] of value.entries()) {
|
|
800
|
+
clonedKeys.push(createSerializable(key));
|
|
801
|
+
clonedValues.push(createSerializable(element));
|
|
802
|
+
}
|
|
803
|
+
const clone = WorkletsModule.createSerializableMap(clonedKeys, clonedValues);
|
|
804
|
+
serializableMappingCache.set(value, clone);
|
|
805
|
+
serializableMappingCache.set(clone);
|
|
806
|
+
freezeObjectInDev(value);
|
|
807
|
+
return clone;
|
|
808
|
+
}
|
|
809
|
+
function cloneSet(value) {
|
|
810
|
+
const clonedElements = [];
|
|
811
|
+
for (const element of value) {
|
|
812
|
+
clonedElements.push(createSerializable(element));
|
|
813
|
+
}
|
|
814
|
+
const clone = WorkletsModule.createSerializableSet(clonedElements);
|
|
815
|
+
serializableMappingCache.set(value, clone);
|
|
816
|
+
serializableMappingCache.set(clone);
|
|
817
|
+
freezeObjectInDev(value);
|
|
818
|
+
return clone;
|
|
819
|
+
}
|
|
820
|
+
function cloneRegExp(value) {
|
|
821
|
+
const pattern = value.source;
|
|
822
|
+
const flags = value.flags;
|
|
823
|
+
const handle = cloneInitializer({
|
|
824
|
+
__init: () => {
|
|
825
|
+
"worklet";
|
|
826
|
+
return new RegExp(pattern, flags);
|
|
827
|
+
}
|
|
828
|
+
});
|
|
829
|
+
serializableMappingCache.set(value, handle);
|
|
830
|
+
return handle;
|
|
831
|
+
}
|
|
832
|
+
function cloneError(value) {
|
|
833
|
+
const {
|
|
834
|
+
name,
|
|
835
|
+
message,
|
|
836
|
+
stack
|
|
837
|
+
} = value;
|
|
838
|
+
const handle = cloneInitializer({
|
|
839
|
+
__init: () => {
|
|
840
|
+
"worklet";
|
|
841
|
+
const error = new Error();
|
|
842
|
+
error.name = name;
|
|
843
|
+
error.message = message;
|
|
844
|
+
error.stack = stack;
|
|
845
|
+
return error;
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
serializableMappingCache.set(value, handle);
|
|
849
|
+
return handle;
|
|
850
|
+
}
|
|
851
|
+
function cloneArrayBuffer(value, shouldPersistRemote) {
|
|
852
|
+
const clone = WorkletsModule.createSerializable(value, shouldPersistRemote, value);
|
|
853
|
+
serializableMappingCache.set(value, clone);
|
|
854
|
+
serializableMappingCache.set(clone);
|
|
855
|
+
return clone;
|
|
856
|
+
}
|
|
857
|
+
function cloneArrayBufferView(value) {
|
|
858
|
+
const buffer = value.buffer;
|
|
859
|
+
const typeName = value.constructor.name;
|
|
860
|
+
const handle = cloneInitializer({
|
|
861
|
+
__init: () => {
|
|
862
|
+
"worklet";
|
|
863
|
+
if (!VALID_ARRAY_VIEWS_NAMES.includes(typeName)) {
|
|
864
|
+
throw new WorkletsError(`Invalid array view name \`${typeName}\`.`);
|
|
865
|
+
}
|
|
866
|
+
const constructor = global[typeName];
|
|
867
|
+
if (constructor === void 0) {
|
|
868
|
+
throw new WorkletsError(`Constructor for \`${typeName}\` not found.`);
|
|
869
|
+
}
|
|
870
|
+
return new constructor(buffer);
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
serializableMappingCache.set(value, handle);
|
|
874
|
+
return handle;
|
|
875
|
+
}
|
|
876
|
+
function cloneSynchronizable(value) {
|
|
877
|
+
serializableMappingCache.set(value);
|
|
878
|
+
return value;
|
|
879
|
+
}
|
|
880
|
+
function cloneImport(value) {
|
|
881
|
+
const {
|
|
882
|
+
source,
|
|
883
|
+
imported
|
|
884
|
+
} = value.__bundleData;
|
|
885
|
+
const clone = WorkletsModule.createSerializableImport(source, imported);
|
|
886
|
+
serializableMappingCache.set(value, clone);
|
|
887
|
+
serializableMappingCache.set(clone);
|
|
888
|
+
return clone;
|
|
889
|
+
}
|
|
890
|
+
function inaccessibleObject(value) {
|
|
891
|
+
const clone = createSerializable(INACCESSIBLE_OBJECT);
|
|
892
|
+
serializableMappingCache.set(value, clone);
|
|
893
|
+
return clone;
|
|
894
|
+
}
|
|
895
|
+
var WORKLET_CODE_THRESHOLD = 255;
|
|
896
|
+
function getWorkletCode(value) {
|
|
897
|
+
const code = value?.__initData?.code;
|
|
898
|
+
if (!code) {
|
|
899
|
+
return "unknown";
|
|
900
|
+
}
|
|
901
|
+
if (code.length > WORKLET_CODE_THRESHOLD) {
|
|
902
|
+
return `${code.substring(0, WORKLET_CODE_THRESHOLD)}...`;
|
|
903
|
+
}
|
|
904
|
+
return code;
|
|
905
|
+
}
|
|
906
|
+
function isRemoteFunction(value) {
|
|
907
|
+
"worklet";
|
|
908
|
+
return !!value.__remoteFunction;
|
|
909
|
+
}
|
|
910
|
+
function freezeObjectInDev(value) {
|
|
911
|
+
if (!__DEV__) {
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
Object.entries(value).forEach(([key, element]) => {
|
|
915
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
916
|
+
if (!descriptor.configurable) {
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
Object.defineProperty(value, key, {
|
|
920
|
+
get() {
|
|
921
|
+
return element;
|
|
922
|
+
},
|
|
923
|
+
set() {
|
|
924
|
+
logger.warn(`Tried to modify key \`${key}\` of an object which has been already passed to a worklet. See
|
|
925
|
+
https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-modify-key-of-an-object-which-has-been-converted-to-a-serializable
|
|
926
|
+
for more details.`);
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
});
|
|
930
|
+
Object.preventExtensions(value);
|
|
931
|
+
}
|
|
932
|
+
function makeShareableCloneOnUIRecursiveLEGACY(value) {
|
|
933
|
+
"worklet";
|
|
934
|
+
if (SHOULD_BE_USE_WEB2) {
|
|
935
|
+
return value;
|
|
936
|
+
}
|
|
937
|
+
function cloneRecursive(value2) {
|
|
938
|
+
if (typeof value2 === "object" && value2 !== null || typeof value2 === "function") {
|
|
939
|
+
if (isHostObject(value2)) {
|
|
940
|
+
return global._createSerializableHostObject(value2);
|
|
941
|
+
}
|
|
942
|
+
if (isRemoteFunction(value2)) {
|
|
943
|
+
return value2.__remoteFunction;
|
|
944
|
+
}
|
|
945
|
+
if (Array.isArray(value2)) {
|
|
946
|
+
return global._createSerializableArray(value2.map(cloneRecursive));
|
|
947
|
+
}
|
|
948
|
+
if (value2.__synchronizableRef) {
|
|
949
|
+
return global._createSerializableSynchronizable(value2);
|
|
950
|
+
}
|
|
951
|
+
const toAdapt = {};
|
|
952
|
+
for (const [key, element] of Object.entries(value2)) {
|
|
953
|
+
toAdapt[key] = cloneRecursive(element);
|
|
954
|
+
}
|
|
955
|
+
return global._createSerializable(toAdapt, value2);
|
|
956
|
+
}
|
|
957
|
+
if (typeof value2 === "string") {
|
|
958
|
+
return global._createSerializableString(value2);
|
|
959
|
+
}
|
|
960
|
+
if (typeof value2 === "number") {
|
|
961
|
+
return global._createSerializableNumber(value2);
|
|
962
|
+
}
|
|
963
|
+
if (typeof value2 === "boolean") {
|
|
964
|
+
return global._createSerializableBoolean(value2);
|
|
965
|
+
}
|
|
966
|
+
if (typeof value2 === "bigint") {
|
|
967
|
+
return global._createSerializableBigInt(value2);
|
|
968
|
+
}
|
|
969
|
+
if (value2 === void 0) {
|
|
970
|
+
return global._createSerializableUndefined();
|
|
971
|
+
}
|
|
972
|
+
if (value2 === null) {
|
|
973
|
+
return global._createSerializableNull();
|
|
974
|
+
}
|
|
975
|
+
return global._createSerializable(value2, void 0);
|
|
976
|
+
}
|
|
977
|
+
return cloneRecursive(value);
|
|
978
|
+
}
|
|
979
|
+
var makeShareableCloneOnUIRecursive = globalThis._WORKLETS_BUNDLE_MODE ? createSerializable : makeShareableCloneOnUIRecursiveLEGACY;
|
|
980
|
+
|
|
981
|
+
// ../../node_modules/react-native-worklets/lib/module/threads.js
|
|
982
|
+
var runOnUIQueue = [];
|
|
983
|
+
function setupMicrotasks() {
|
|
984
|
+
"worklet";
|
|
985
|
+
let microtasksQueue = [];
|
|
986
|
+
let isExecutingMicrotasksQueue = false;
|
|
987
|
+
global.queueMicrotask = (callback) => {
|
|
988
|
+
microtasksQueue.push(callback);
|
|
989
|
+
};
|
|
990
|
+
global._microtaskQueueFinalizers = [];
|
|
991
|
+
global.__callMicrotasks = () => {
|
|
992
|
+
if (isExecutingMicrotasksQueue) {
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
995
|
+
try {
|
|
996
|
+
isExecutingMicrotasksQueue = true;
|
|
997
|
+
for (let index = 0; index < microtasksQueue.length; index += 1) {
|
|
998
|
+
microtasksQueue[index]();
|
|
999
|
+
}
|
|
1000
|
+
microtasksQueue = [];
|
|
1001
|
+
global._microtaskQueueFinalizers.forEach((finalizer) => finalizer());
|
|
1002
|
+
} finally {
|
|
1003
|
+
isExecutingMicrotasksQueue = false;
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
function callMicrotasksOnUIThread() {
|
|
1008
|
+
"worklet";
|
|
1009
|
+
global.__callMicrotasks();
|
|
1010
|
+
}
|
|
1011
|
+
var callMicrotasks = SHOULD_BE_USE_WEB2 ? () => {
|
|
1012
|
+
} : callMicrotasksOnUIThread;
|
|
1013
|
+
function runOnUI(worklet) {
|
|
1014
|
+
if (__DEV__ && !SHOULD_BE_USE_WEB2 && !isWorkletFunction(worklet) && !worklet.__bundleData) {
|
|
1015
|
+
throw new WorkletsError("`runOnUI` can only be used with worklets.");
|
|
1016
|
+
}
|
|
1017
|
+
return (...args) => {
|
|
1018
|
+
if (IS_JEST2) {
|
|
1019
|
+
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
|
1020
|
+
"worklet";
|
|
1021
|
+
worklet(...args);
|
|
1022
|
+
}));
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
if (__DEV__) {
|
|
1026
|
+
createSerializable(worklet);
|
|
1027
|
+
createSerializable(args);
|
|
1028
|
+
}
|
|
1029
|
+
enqueueUI(worklet, args);
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
if (__DEV__) {
|
|
1033
|
+
let runOnUIWorklet = function() {
|
|
1034
|
+
"worklet";
|
|
1035
|
+
throw new WorkletsError("`runOnUI` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.");
|
|
1036
|
+
};
|
|
1037
|
+
const serializableRunOnUIWorklet = createSerializable(runOnUIWorklet);
|
|
1038
|
+
serializableMappingCache.set(runOnUI, serializableRunOnUIWorklet);
|
|
1039
|
+
}
|
|
1040
|
+
function executeOnUIRuntimeSync(worklet) {
|
|
1041
|
+
return (...args) => {
|
|
1042
|
+
return WorkletsModule.executeOnUIRuntimeSync(createSerializable(() => {
|
|
1043
|
+
"worklet";
|
|
1044
|
+
const result = worklet(...args);
|
|
1045
|
+
return makeShareableCloneOnUIRecursive(result);
|
|
1046
|
+
}));
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
function runWorkletOnJS(worklet, ...args) {
|
|
1050
|
+
worklet(...args);
|
|
1051
|
+
}
|
|
1052
|
+
function runOnJS(fun) {
|
|
1053
|
+
"worklet";
|
|
1054
|
+
if (SHOULD_BE_USE_WEB2 || globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
1055
|
+
return (...args) => queueMicrotask(args.length ? () => fun(...args) : fun);
|
|
1056
|
+
}
|
|
1057
|
+
if (isWorkletFunction(fun)) {
|
|
1058
|
+
return (...args) => runOnJS(runWorkletOnJS)(fun, ...args);
|
|
1059
|
+
}
|
|
1060
|
+
if (fun.__remoteFunction) {
|
|
1061
|
+
fun = fun.__remoteFunction;
|
|
1062
|
+
}
|
|
1063
|
+
const scheduleOnJS = typeof fun === "function" ? global._scheduleHostFunctionOnJS : global._scheduleRemoteFunctionOnJS;
|
|
1064
|
+
return (...args) => {
|
|
1065
|
+
scheduleOnJS(fun, args.length > 0 ? makeShareableCloneOnUIRecursive(args) : void 0);
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
function runOnUIAsync(worklet) {
|
|
1069
|
+
if (__DEV__ && !SHOULD_BE_USE_WEB2 && !isWorkletFunction(worklet)) {
|
|
1070
|
+
throw new WorkletsError("`runOnUIAsync` can only be used with worklets.");
|
|
1071
|
+
}
|
|
1072
|
+
return (...args) => {
|
|
1073
|
+
return new Promise((resolve) => {
|
|
1074
|
+
if (IS_JEST2) {
|
|
1075
|
+
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
|
1076
|
+
"worklet";
|
|
1077
|
+
worklet(...args);
|
|
1078
|
+
}));
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
if (__DEV__) {
|
|
1082
|
+
createSerializable(worklet);
|
|
1083
|
+
createSerializable(args);
|
|
1084
|
+
}
|
|
1085
|
+
enqueueUI(worklet, args, resolve);
|
|
1086
|
+
});
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
if (__DEV__) {
|
|
1090
|
+
let runOnUIAsyncWorklet = function() {
|
|
1091
|
+
"worklet";
|
|
1092
|
+
throw new WorkletsError("`runOnUIAsync` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.");
|
|
1093
|
+
};
|
|
1094
|
+
const serializableRunOnUIAsyncWorklet = createSerializable(runOnUIAsyncWorklet);
|
|
1095
|
+
serializableMappingCache.set(runOnUIAsync, serializableRunOnUIAsyncWorklet);
|
|
1096
|
+
}
|
|
1097
|
+
function enqueueUI(worklet, args, resolve) {
|
|
1098
|
+
const job = [worklet, args, resolve];
|
|
1099
|
+
runOnUIQueue.push(job);
|
|
1100
|
+
if (runOnUIQueue.length === 1) {
|
|
1101
|
+
flushUIQueue();
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
function flushUIQueue() {
|
|
1105
|
+
queueMicrotask(() => {
|
|
1106
|
+
const queue = runOnUIQueue;
|
|
1107
|
+
runOnUIQueue = [];
|
|
1108
|
+
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
|
1109
|
+
"worklet";
|
|
1110
|
+
queue.forEach(([workletFunction, workletArgs, jobResolve]) => {
|
|
1111
|
+
const result = workletFunction(...workletArgs);
|
|
1112
|
+
if (jobResolve) {
|
|
1113
|
+
runOnJS(jobResolve)(result);
|
|
1114
|
+
}
|
|
1115
|
+
});
|
|
1116
|
+
callMicrotasks();
|
|
1117
|
+
}));
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/requestAnimationFrame.js
|
|
1122
|
+
function setupRequestAnimationFrame() {
|
|
1123
|
+
"worklet";
|
|
1124
|
+
const nativeRequestAnimationFrame = globalThis.requestAnimationFrame;
|
|
1125
|
+
let queuedCallbacks = [];
|
|
1126
|
+
let queuedCallbacksBegin = 0;
|
|
1127
|
+
let queuedCallbacksEnd = 0;
|
|
1128
|
+
let flushedCallbacks = queuedCallbacks;
|
|
1129
|
+
let flushedCallbacksBegin = 0;
|
|
1130
|
+
let flushedCallbacksEnd = 0;
|
|
1131
|
+
let flushRequested = false;
|
|
1132
|
+
globalThis.__flushAnimationFrame = (timestamp) => {
|
|
1133
|
+
flushedCallbacks = queuedCallbacks;
|
|
1134
|
+
queuedCallbacks = [];
|
|
1135
|
+
flushedCallbacksBegin = queuedCallbacksBegin;
|
|
1136
|
+
flushedCallbacksEnd = queuedCallbacksEnd;
|
|
1137
|
+
queuedCallbacksBegin = queuedCallbacksEnd;
|
|
1138
|
+
for (const callback of flushedCallbacks) {
|
|
1139
|
+
callback(timestamp);
|
|
1140
|
+
}
|
|
1141
|
+
flushedCallbacksBegin = flushedCallbacksEnd;
|
|
1142
|
+
callMicrotasks();
|
|
1143
|
+
};
|
|
1144
|
+
globalThis.requestAnimationFrame = (callback) => {
|
|
1145
|
+
const handle = queuedCallbacksEnd++;
|
|
1146
|
+
queuedCallbacks.push(callback);
|
|
1147
|
+
if (!flushRequested) {
|
|
1148
|
+
flushRequested = true;
|
|
1149
|
+
nativeRequestAnimationFrame((timestamp) => {
|
|
1150
|
+
flushRequested = false;
|
|
1151
|
+
globalThis.__frameTimestamp = timestamp;
|
|
1152
|
+
globalThis.__flushAnimationFrame(timestamp);
|
|
1153
|
+
globalThis.__frameTimestamp = void 0;
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1156
|
+
return handle;
|
|
1157
|
+
};
|
|
1158
|
+
globalThis.cancelAnimationFrame = (handle) => {
|
|
1159
|
+
if (handle < flushedCallbacksBegin || handle >= queuedCallbacksEnd) {
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
if (handle < flushedCallbacksEnd) {
|
|
1163
|
+
flushedCallbacks[handle - flushedCallbacksBegin] = () => {
|
|
1164
|
+
};
|
|
1165
|
+
} else {
|
|
1166
|
+
queuedCallbacks[handle - queuedCallbacksBegin] = () => {
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js
|
|
1173
|
+
function setupSetTimeout() {
|
|
1174
|
+
"worklet";
|
|
1175
|
+
const timeoutHandleToRafHandle = /* @__PURE__ */ new Map();
|
|
1176
|
+
const setTimeoutPolyfill = (callback, delay = 0, ...args) => {
|
|
1177
|
+
const start = performance.now();
|
|
1178
|
+
let timeoutHandle = 0;
|
|
1179
|
+
const rafCallback = () => {
|
|
1180
|
+
const now = performance.now();
|
|
1181
|
+
if (now - start >= delay) {
|
|
1182
|
+
callback(...args);
|
|
1183
|
+
timeoutHandleToRafHandle.delete(timeoutHandle);
|
|
1184
|
+
} else {
|
|
1185
|
+
const rafHandle = requestAnimationFrame(rafCallback);
|
|
1186
|
+
timeoutHandleToRafHandle.set(timeoutHandle, rafHandle);
|
|
1187
|
+
}
|
|
1188
|
+
};
|
|
1189
|
+
timeoutHandle = requestAnimationFrame(rafCallback);
|
|
1190
|
+
timeoutHandleToRafHandle.set(timeoutHandle, timeoutHandle);
|
|
1191
|
+
return timeoutHandle;
|
|
1192
|
+
};
|
|
1193
|
+
const clearTimeoutPolyfill = (timeoutHandle) => {
|
|
1194
|
+
const rafHandle = timeoutHandleToRafHandle.get(timeoutHandle);
|
|
1195
|
+
timeoutHandleToRafHandle.delete(timeoutHandle);
|
|
1196
|
+
cancelAnimationFrame(rafHandle);
|
|
1197
|
+
};
|
|
1198
|
+
globalThis.setTimeout = setTimeoutPolyfill;
|
|
1199
|
+
globalThis.clearTimeout = clearTimeoutPolyfill;
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
// ../../node_modules/react-native-worklets/lib/module/synchronizableUnpacker.js
|
|
1203
|
+
function __installUnpacker() {
|
|
1204
|
+
const serializer = !globalThis._WORKLET || globalThis._WORKLETS_BUNDLE_MODE ? (value, _) => createSerializable(value) : globalThis._createSerializable;
|
|
1205
|
+
function synchronizableUnpacker(synchronizableRef) {
|
|
1206
|
+
const synchronizable = synchronizableRef;
|
|
1207
|
+
const proxy = globalThis.__workletsModuleProxy;
|
|
1208
|
+
synchronizable.__synchronizableRef = true;
|
|
1209
|
+
synchronizable.getDirty = () => {
|
|
1210
|
+
return proxy.synchronizableGetDirty(synchronizable);
|
|
1211
|
+
};
|
|
1212
|
+
synchronizable.getBlocking = () => {
|
|
1213
|
+
return proxy.synchronizableGetBlocking(synchronizable);
|
|
1214
|
+
};
|
|
1215
|
+
synchronizable.setBlocking = (valueOrFunction) => {
|
|
1216
|
+
let newValue;
|
|
1217
|
+
if (typeof valueOrFunction === "function") {
|
|
1218
|
+
const func = valueOrFunction;
|
|
1219
|
+
synchronizable.lock();
|
|
1220
|
+
const prev = synchronizable.getBlocking();
|
|
1221
|
+
newValue = func(prev);
|
|
1222
|
+
proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, void 0));
|
|
1223
|
+
synchronizable.unlock();
|
|
1224
|
+
} else {
|
|
1225
|
+
const value = valueOrFunction;
|
|
1226
|
+
newValue = value;
|
|
1227
|
+
proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, void 0));
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
synchronizable.lock = () => {
|
|
1231
|
+
proxy.synchronizableLock(synchronizable);
|
|
1232
|
+
};
|
|
1233
|
+
synchronizable.unlock = () => {
|
|
1234
|
+
proxy.synchronizableUnlock(synchronizable);
|
|
1235
|
+
};
|
|
1236
|
+
return synchronizable;
|
|
1237
|
+
}
|
|
1238
|
+
globalThis.__synchronizableUnpacker = synchronizableUnpacker;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
// ../../node_modules/react-native-worklets/lib/module/initializers.js
|
|
1242
|
+
var capturableConsole;
|
|
1243
|
+
function getMemorySafeCapturableConsole() {
|
|
1244
|
+
if (capturableConsole) {
|
|
1245
|
+
return capturableConsole;
|
|
1246
|
+
}
|
|
1247
|
+
const consoleCopy = Object.fromEntries(Object.entries(console).map(([methodName, method]) => {
|
|
1248
|
+
const methodWrapper = function methodWrapper2(...args) {
|
|
1249
|
+
return method(...args);
|
|
1250
|
+
};
|
|
1251
|
+
if (method.name) {
|
|
1252
|
+
Object.defineProperty(methodWrapper, "name", {
|
|
1253
|
+
value: method.name,
|
|
1254
|
+
writable: false
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
return [methodName, methodWrapper];
|
|
1258
|
+
}));
|
|
1259
|
+
capturableConsole = consoleCopy;
|
|
1260
|
+
return consoleCopy;
|
|
1261
|
+
}
|
|
1262
|
+
function setupConsole(boundCapturableConsole) {
|
|
1263
|
+
"worklet";
|
|
1264
|
+
globalThis.console = {
|
|
1265
|
+
assert: runOnJS(boundCapturableConsole.assert),
|
|
1266
|
+
debug: runOnJS(boundCapturableConsole.debug),
|
|
1267
|
+
log: runOnJS(boundCapturableConsole.log),
|
|
1268
|
+
warn: runOnJS(boundCapturableConsole.warn),
|
|
1269
|
+
error: runOnJS(boundCapturableConsole.error),
|
|
1270
|
+
info: runOnJS(boundCapturableConsole.info)
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
var initialized = false;
|
|
1274
|
+
function init() {
|
|
1275
|
+
if (initialized) {
|
|
1276
|
+
return;
|
|
1277
|
+
}
|
|
1278
|
+
initialized = true;
|
|
1279
|
+
if (globalThis.__RUNTIME_KIND === void 0) {
|
|
1280
|
+
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
|
|
1281
|
+
}
|
|
1282
|
+
initializeRuntime();
|
|
1283
|
+
if (SHOULD_BE_USE_WEB2) {
|
|
1284
|
+
initializeRuntimeOnWeb();
|
|
1285
|
+
}
|
|
1286
|
+
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
|
|
1287
|
+
initializeWorkletRuntime();
|
|
1288
|
+
} else {
|
|
1289
|
+
initializeRNRuntime();
|
|
1290
|
+
if (!SHOULD_BE_USE_WEB2) {
|
|
1291
|
+
installRNBindingsOnUIRuntime();
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
function initializeRuntime() {
|
|
1296
|
+
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
1297
|
+
globalThis.__valueUnpacker = bundleValueUnpacker;
|
|
1298
|
+
}
|
|
1299
|
+
__installUnpacker();
|
|
1300
|
+
}
|
|
1301
|
+
function initializeRNRuntime() {
|
|
1302
|
+
if (__DEV__) {
|
|
1303
|
+
const testWorklet = () => {
|
|
1304
|
+
"worklet";
|
|
1305
|
+
};
|
|
1306
|
+
if (!isWorkletFunction(testWorklet)) {
|
|
1307
|
+
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.`);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
registerReportFatalRemoteError();
|
|
1311
|
+
}
|
|
1312
|
+
function initializeWorkletRuntime() {
|
|
1313
|
+
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
1314
|
+
setupCallGuard();
|
|
1315
|
+
if (__DEV__) {
|
|
1316
|
+
const Refresh = new Proxy({}, {
|
|
1317
|
+
get() {
|
|
1318
|
+
return () => {
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
globalThis.__r.Refresh = Refresh;
|
|
1323
|
+
const modules = __require.getModules();
|
|
1324
|
+
const ReactNativeModuleId = __require.resolveWeak("react-native");
|
|
1325
|
+
const factory = function(_global, _require, _importDefault, _importAll, module, _exports, _dependencyMap) {
|
|
1326
|
+
module.exports = new Proxy({}, {
|
|
1327
|
+
get: function get(_target, prop) {
|
|
1328
|
+
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.`);
|
|
1329
|
+
return {
|
|
1330
|
+
get() {
|
|
1331
|
+
return void 0;
|
|
1332
|
+
}
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
};
|
|
1337
|
+
const mod = {
|
|
1338
|
+
dependencyMap: [],
|
|
1339
|
+
factory,
|
|
1340
|
+
hasError: false,
|
|
1341
|
+
importedAll: {},
|
|
1342
|
+
importedDefault: {},
|
|
1343
|
+
isInitialized: false,
|
|
1344
|
+
publicModule: {
|
|
1345
|
+
exports: {}
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
modules.set(ReactNativeModuleId, mod);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
function initializeRuntimeOnWeb() {
|
|
1353
|
+
globalThis._WORKLET = false;
|
|
1354
|
+
globalThis._log = console.log;
|
|
1355
|
+
globalThis._getAnimationTimestamp = () => performance.now();
|
|
1356
|
+
if (IS_JEST2) {
|
|
1357
|
+
globalThis.requestAnimationFrame = mockedRequestAnimationFrame;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
function installRNBindingsOnUIRuntime() {
|
|
1361
|
+
if (!WorkletsModule) {
|
|
1362
|
+
throw new WorkletsError("Worklets are trying to initialize the UI runtime without a valid WorkletsModule");
|
|
1363
|
+
}
|
|
1364
|
+
const runtimeBoundCapturableConsole = getMemorySafeCapturableConsole();
|
|
1365
|
+
if (!globalThis._WORKLETS_BUNDLE_MODE) {
|
|
1366
|
+
executeOnUIRuntimeSync(setupCallGuard)();
|
|
1367
|
+
executeOnUIRuntimeSync(registerWorkletsError)();
|
|
1368
|
+
}
|
|
1369
|
+
executeOnUIRuntimeSync(() => {
|
|
1370
|
+
"worklet";
|
|
1371
|
+
setupConsole(runtimeBoundCapturableConsole);
|
|
1372
|
+
setupMicrotasks();
|
|
1373
|
+
setupRequestAnimationFrame();
|
|
1374
|
+
setupSetTimeout();
|
|
1375
|
+
setupSetImmediate();
|
|
1376
|
+
setupSetInterval();
|
|
1377
|
+
})();
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
// ../../node_modules/react-native-worklets/lib/module/workletRuntimeEntry.js
|
|
1381
|
+
function bundleModeInit() {
|
|
1382
|
+
if (SHOULD_BE_USE_WEB2) {
|
|
1383
|
+
return;
|
|
1384
|
+
}
|
|
1385
|
+
globalThis._WORKLETS_BUNDLE_MODE = true;
|
|
1386
|
+
const runtimeKind = globalThis.__RUNTIME_KIND;
|
|
1387
|
+
if (runtimeKind && runtimeKind !== RuntimeKind.ReactNative) {
|
|
1388
|
+
init();
|
|
1389
|
+
throw new WorkletsError("Worklets initialized successfully");
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
bundleModeInit();
|
|
1393
|
+
|
|
1394
|
+
// ../../node_modules/react-native-worklets/lib/module/featureFlags/index.js
|
|
1395
|
+
var DynamicFlags = {
|
|
1396
|
+
EXAMPLE_DYNAMIC_FLAG: true,
|
|
1397
|
+
init() {
|
|
1398
|
+
Object.keys(DynamicFlags).forEach((key) => {
|
|
1399
|
+
if (key !== "init" && key !== "setFlag") {
|
|
1400
|
+
WorkletsModule.setDynamicFeatureFlag(key, DynamicFlags[key]);
|
|
1401
|
+
}
|
|
1402
|
+
});
|
|
1403
|
+
},
|
|
1404
|
+
setFlag(name, value) {
|
|
1405
|
+
if (name in DynamicFlags) {
|
|
1406
|
+
DynamicFlags[name] = value;
|
|
1407
|
+
WorkletsModule.setDynamicFeatureFlag(name, value);
|
|
1408
|
+
} else {
|
|
1409
|
+
logger.warn(`The feature flag: '${name}' no longer exists, you can safely remove invocation of \`setDynamicFeatureFlag('${name}')\` from your code.`);
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
};
|
|
1413
|
+
DynamicFlags.init();
|
|
1414
|
+
|
|
1415
|
+
// ../../node_modules/react-native-worklets/lib/module/index.js
|
|
1416
|
+
init();
|
|
1417
|
+
if (globalThis._ALWAYS_FALSE) {
|
|
1418
|
+
bundleModeInit();
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
// src/transitions/easing.ts
|
|
1422
|
+
function ensureWorkletEasing(easing) {
|
|
1423
|
+
if (!easing) return void 0;
|
|
1424
|
+
const fn = isEasingFactory(easing) ? easing.factory() : easing;
|
|
1425
|
+
if (isWorkletFunction(fn)) return fn;
|
|
1426
|
+
const wrapped = (t) => {
|
|
1427
|
+
"worklet";
|
|
1428
|
+
return fn(t);
|
|
1429
|
+
};
|
|
1430
|
+
return wrapped;
|
|
1431
|
+
}
|
|
1432
|
+
function isEasingFactory(value) {
|
|
1433
|
+
return typeof value === "object" && value !== null && "factory" in value && typeof value.factory === "function";
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
// src/transitions/spring.ts
|
|
1437
|
+
var DEFAULT_SPRING = {
|
|
1438
|
+
tension: 170,
|
|
1439
|
+
friction: 26,
|
|
1440
|
+
mass: 1
|
|
1441
|
+
};
|
|
1442
|
+
function springToReanimated(t) {
|
|
1443
|
+
"worklet";
|
|
1444
|
+
return {
|
|
1445
|
+
stiffness: t.tension ?? DEFAULT_SPRING.tension,
|
|
1446
|
+
damping: t.friction ?? DEFAULT_SPRING.friction,
|
|
1447
|
+
mass: t.mass ?? DEFAULT_SPRING.mass,
|
|
1448
|
+
velocity: t.velocity,
|
|
1449
|
+
restSpeedThreshold: t.restSpeedThreshold,
|
|
1450
|
+
restDisplacementThreshold: t.restDisplacementThreshold
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
// src/transitions/resolve.ts
|
|
1455
|
+
var DEFAULT_TIMING_DURATION = 250;
|
|
1456
|
+
function buildSpring(cfg, toValue, cb) {
|
|
1457
|
+
return withSpring(toValue, springToReanimated(cfg), cb);
|
|
1458
|
+
}
|
|
1459
|
+
function buildTiming(cfg, toValue, cb) {
|
|
1460
|
+
return withTiming(
|
|
1461
|
+
toValue,
|
|
1462
|
+
{
|
|
1463
|
+
duration: cfg.duration ?? DEFAULT_TIMING_DURATION,
|
|
1464
|
+
easing: ensureWorkletEasing(cfg.easing) ?? Easing.inOut(Easing.ease)
|
|
1465
|
+
},
|
|
1466
|
+
cb
|
|
1467
|
+
);
|
|
1468
|
+
}
|
|
1469
|
+
function buildDecay(cfg, cb) {
|
|
1470
|
+
return withDecay(
|
|
1471
|
+
{
|
|
1472
|
+
velocity: cfg.velocity ?? 0,
|
|
1473
|
+
deceleration: cfg.deceleration,
|
|
1474
|
+
clamp: cfg.clamp
|
|
1475
|
+
},
|
|
1476
|
+
cb
|
|
1477
|
+
);
|
|
1478
|
+
}
|
|
1479
|
+
function buildOne(cfg, toValue, cb) {
|
|
1480
|
+
if (cfg.type === "no-animation") {
|
|
1481
|
+
return toValue;
|
|
1482
|
+
}
|
|
1483
|
+
if (cfg.type === "decay") return buildDecay(cfg, cb);
|
|
1484
|
+
if (cfg.type === "timing") return buildTiming(cfg, toValue, cb);
|
|
1485
|
+
return buildSpring(cfg, toValue, cb);
|
|
1486
|
+
}
|
|
1487
|
+
function applyRepeat(animation, repeat) {
|
|
1488
|
+
if (repeat === void 0) return animation;
|
|
1489
|
+
if (repeat === "infinite") {
|
|
1490
|
+
return withRepeat(animation, -1, true);
|
|
1491
|
+
}
|
|
1492
|
+
if (typeof repeat === "number") {
|
|
1493
|
+
return withRepeat(animation, repeat, true);
|
|
1494
|
+
}
|
|
1495
|
+
const count = repeat.count === "infinite" ? -1 : repeat.count;
|
|
1496
|
+
const alternate = repeat.alternate ?? true;
|
|
1497
|
+
return withRepeat(animation, count, alternate);
|
|
1498
|
+
}
|
|
1499
|
+
function applyDelay(animation, delay) {
|
|
1500
|
+
if (!delay || delay <= 0) return animation;
|
|
1501
|
+
return withDelay(delay, animation);
|
|
1502
|
+
}
|
|
1503
|
+
function resolveTransition(config, toValue, callback) {
|
|
1504
|
+
const cfg = config ?? { type: "spring" };
|
|
1505
|
+
const base = buildOne(cfg, toValue, callback);
|
|
1506
|
+
const repeated = applyRepeat(base, repeatOf(cfg));
|
|
1507
|
+
return applyDelay(repeated, delayOf(cfg));
|
|
1508
|
+
}
|
|
1509
|
+
function repeatOf(cfg) {
|
|
1510
|
+
if (cfg.type === "no-animation" || cfg.type === "decay") return void 0;
|
|
1511
|
+
return cfg.repeat;
|
|
1512
|
+
}
|
|
1513
|
+
function delayOf(cfg) {
|
|
1514
|
+
if (cfg.type === "no-animation") return void 0;
|
|
1515
|
+
return cfg.delay;
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
// src/transitions/keys.ts
|
|
1519
|
+
var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
1520
|
+
"type",
|
|
1521
|
+
"tension",
|
|
1522
|
+
"friction",
|
|
1523
|
+
"mass",
|
|
1524
|
+
"velocity",
|
|
1525
|
+
"restSpeedThreshold",
|
|
1526
|
+
"restDisplacementThreshold",
|
|
1527
|
+
"duration",
|
|
1528
|
+
"easing",
|
|
1529
|
+
"delay",
|
|
1530
|
+
"repeat",
|
|
1531
|
+
"deceleration",
|
|
1532
|
+
"clamp"
|
|
1533
|
+
]);
|
|
1534
|
+
function isTopLevelTransition(t) {
|
|
1535
|
+
if (t === null || typeof t !== "object") return false;
|
|
1536
|
+
const keys = Object.keys(t);
|
|
1537
|
+
if (keys.length === 0) return false;
|
|
1538
|
+
return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
|
|
1539
|
+
}
|
|
1540
|
+
var modality = "keyboard";
|
|
1541
|
+
var installed = false;
|
|
1542
|
+
function setKeyboard() {
|
|
1543
|
+
modality = "keyboard";
|
|
1544
|
+
}
|
|
1545
|
+
function setPointer() {
|
|
1546
|
+
modality = "pointer";
|
|
1547
|
+
}
|
|
1548
|
+
function ensureInstalled() {
|
|
1549
|
+
if (installed) return;
|
|
1550
|
+
if (Platform.OS !== "web") return;
|
|
1551
|
+
if (typeof document === "undefined") return;
|
|
1552
|
+
document.addEventListener("keydown", setKeyboard, true);
|
|
1553
|
+
document.addEventListener("mousedown", setPointer, true);
|
|
1554
|
+
document.addEventListener("pointerdown", setPointer, true);
|
|
1555
|
+
document.addEventListener("touchstart", setPointer, true);
|
|
1556
|
+
installed = true;
|
|
1557
|
+
}
|
|
1558
|
+
function isFocusVisible() {
|
|
1559
|
+
if (Platform.OS !== "web") return true;
|
|
1560
|
+
ensureInstalled();
|
|
1561
|
+
return modality === "keyboard";
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
// src/values/useGesture.ts
|
|
1565
|
+
function useGesture(transition) {
|
|
1566
|
+
const pressed = useSharedValue(0);
|
|
1567
|
+
const focused = useSharedValue(0);
|
|
1568
|
+
const focusVisible = useSharedValue(0);
|
|
1569
|
+
const hovered = useSharedValue(0);
|
|
1570
|
+
const shouldReduceMotion = useShouldReduceMotion();
|
|
1571
|
+
const setLayer = useCallback(
|
|
1572
|
+
(sv, layer, target) => {
|
|
1573
|
+
const cfg = shouldReduceMotion ? { type: "no-animation" } : layerTransition(layer, transition) ?? { type: "spring" };
|
|
1574
|
+
sv.value = resolveTransition(cfg, target);
|
|
1575
|
+
},
|
|
1576
|
+
// The transition is intentionally read on every call rather than cooked
|
|
1577
|
+
// into the dep array — a fresh literal each render would otherwise
|
|
1578
|
+
// rebuild the handler bag and break composing consumers that key off
|
|
1579
|
+
// handler identity. `transition` is read inside the callback closure;
|
|
1580
|
+
// shared values are stable so the only dep that matters is the reduce-
|
|
1581
|
+
// motion flag.
|
|
1582
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1583
|
+
[shouldReduceMotion]
|
|
1584
|
+
);
|
|
1585
|
+
const handlers = useMemo(
|
|
1586
|
+
() => ({
|
|
1587
|
+
onPressIn: () => setLayer(pressed, "pressed", 1),
|
|
1588
|
+
onPressOut: () => setLayer(pressed, "pressed", 0),
|
|
1589
|
+
onHoverIn: () => setLayer(hovered, "hovered", 1),
|
|
1590
|
+
onHoverOut: () => setLayer(hovered, "hovered", 0),
|
|
1591
|
+
onFocus: () => {
|
|
1592
|
+
setLayer(focused, "focused", 1);
|
|
1593
|
+
if (isFocusVisible()) setLayer(focusVisible, "focusVisible", 1);
|
|
1594
|
+
},
|
|
1595
|
+
onBlur: () => {
|
|
1596
|
+
setLayer(focused, "focused", 0);
|
|
1597
|
+
setLayer(focusVisible, "focusVisible", 0);
|
|
1598
|
+
}
|
|
1599
|
+
}),
|
|
1600
|
+
[setLayer, pressed, focused, focusVisible, hovered]
|
|
1601
|
+
);
|
|
1602
|
+
return { pressed, focused, focusVisible, hovered, handlers };
|
|
1603
|
+
}
|
|
1604
|
+
function layerTransition(layer, transition) {
|
|
1605
|
+
if (!transition) return void 0;
|
|
1606
|
+
if (isTopLevelTransition(transition)) return transition;
|
|
1607
|
+
return transition[layer];
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
// src/gestureLayer/useGestureLayer.ts
|
|
1611
|
+
function useGestureLayer(states, options = {}) {
|
|
1612
|
+
const { disabled: isDisabled = false, transition } = options;
|
|
1613
|
+
const shouldReduceMotion = useShouldReduceMotion();
|
|
1614
|
+
const gesture = useGesture(transition);
|
|
1615
|
+
const disabledProgress = useSharedValue(0);
|
|
1616
|
+
useEffect(() => {
|
|
1617
|
+
const target = isDisabled ? 1 : 0;
|
|
1618
|
+
const cfg = shouldReduceMotion ? { type: "no-animation" } : disabledTransition(transition) ?? { type: "spring" };
|
|
1619
|
+
disabledProgress.value = resolveTransition(cfg, target);
|
|
1620
|
+
}, [isDisabled, shouldReduceMotion, transition, disabledProgress]);
|
|
1621
|
+
const meta = useMemo(() => {
|
|
1622
|
+
const layers = {
|
|
1623
|
+
rest: states.rest,
|
|
1624
|
+
hovered: states.hovered,
|
|
1625
|
+
focused: states.focused,
|
|
1626
|
+
focusVisible: states.focusVisible,
|
|
1627
|
+
pressed: states.pressed,
|
|
1628
|
+
disabled: states.disabled
|
|
1629
|
+
};
|
|
1630
|
+
const sources = [
|
|
1631
|
+
layers.rest,
|
|
1632
|
+
layers.hovered,
|
|
1633
|
+
layers.focused,
|
|
1634
|
+
layers.focusVisible,
|
|
1635
|
+
layers.pressed,
|
|
1636
|
+
layers.disabled
|
|
1637
|
+
];
|
|
1638
|
+
const keySet = /* @__PURE__ */ new Set();
|
|
1639
|
+
for (const src of sources) {
|
|
1640
|
+
if (!src) continue;
|
|
1641
|
+
for (const k in src) if (src[k] !== void 0) keySet.add(k);
|
|
1642
|
+
}
|
|
1643
|
+
const keys = Array.from(keySet);
|
|
1644
|
+
const types = {};
|
|
1645
|
+
const restValues = {};
|
|
1646
|
+
for (const k of keys) {
|
|
1647
|
+
let firstDefined;
|
|
1648
|
+
for (const src of sources) {
|
|
1649
|
+
if (src && src[k] !== void 0) {
|
|
1650
|
+
firstDefined = src[k];
|
|
1651
|
+
break;
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
const isColor = typeof firstDefined === "string";
|
|
1655
|
+
types[k] = isColor ? "color" : "number";
|
|
1656
|
+
const restRaw = layers.rest ? layers.rest[k] : void 0;
|
|
1657
|
+
restValues[k] = restRaw !== void 0 ? restRaw : isColor ? "transparent" : 0;
|
|
1658
|
+
}
|
|
1659
|
+
return { layers, keys, types, restValues };
|
|
1660
|
+
}, [
|
|
1661
|
+
states.rest,
|
|
1662
|
+
states.hovered,
|
|
1663
|
+
states.focused,
|
|
1664
|
+
states.focusVisible,
|
|
1665
|
+
states.pressed,
|
|
1666
|
+
states.disabled
|
|
1667
|
+
]);
|
|
1668
|
+
const style = useAnimatedStyle(() => {
|
|
1669
|
+
const { layers, keys, types, restValues } = meta;
|
|
1670
|
+
const ph = gesture.hovered.value;
|
|
1671
|
+
const pf = gesture.focused.value;
|
|
1672
|
+
const pfv = gesture.focusVisible.value;
|
|
1673
|
+
const pp = gesture.pressed.value;
|
|
1674
|
+
const pd = disabledProgress.value;
|
|
1675
|
+
const hoveredLayer = layers.hovered;
|
|
1676
|
+
const focusedLayer = layers.focused;
|
|
1677
|
+
const focusVisibleLayer = layers.focusVisible;
|
|
1678
|
+
const pressedLayer = layers.pressed;
|
|
1679
|
+
const disabledLayer = layers.disabled;
|
|
1680
|
+
const out = {};
|
|
1681
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1682
|
+
const k = keys[i];
|
|
1683
|
+
const isColor = types[k] === "color";
|
|
1684
|
+
const rest = restValues[k];
|
|
1685
|
+
if (isColor) {
|
|
1686
|
+
let v = rest;
|
|
1687
|
+
if (hoveredLayer && ph > 0 && hoveredLayer[k] !== void 0) {
|
|
1688
|
+
v = interpolateColor(ph, [0, 1], [v, hoveredLayer[k]]);
|
|
1689
|
+
}
|
|
1690
|
+
if (focusedLayer && pf > 0 && focusedLayer[k] !== void 0) {
|
|
1691
|
+
v = interpolateColor(pf, [0, 1], [v, focusedLayer[k]]);
|
|
1692
|
+
}
|
|
1693
|
+
if (focusVisibleLayer && pfv > 0 && focusVisibleLayer[k] !== void 0) {
|
|
1694
|
+
v = interpolateColor(pfv, [0, 1], [v, focusVisibleLayer[k]]);
|
|
1695
|
+
}
|
|
1696
|
+
if (pressedLayer && pp > 0 && pressedLayer[k] !== void 0) {
|
|
1697
|
+
v = interpolateColor(pp, [0, 1], [v, pressedLayer[k]]);
|
|
1698
|
+
}
|
|
1699
|
+
if (disabledLayer && pd > 0 && disabledLayer[k] !== void 0) {
|
|
1700
|
+
v = interpolateColor(pd, [0, 1], [v, disabledLayer[k]]);
|
|
1701
|
+
}
|
|
1702
|
+
out[k] = v;
|
|
1703
|
+
} else {
|
|
1704
|
+
const base = rest;
|
|
1705
|
+
let m = base;
|
|
1706
|
+
if (hoveredLayer && ph > 0 && hoveredLayer[k] !== void 0) {
|
|
1707
|
+
const c = base + (hoveredLayer[k] - base) * ph;
|
|
1708
|
+
if (c > m) m = c;
|
|
1709
|
+
}
|
|
1710
|
+
if (focusedLayer && pf > 0 && focusedLayer[k] !== void 0) {
|
|
1711
|
+
const c = base + (focusedLayer[k] - base) * pf;
|
|
1712
|
+
if (c > m) m = c;
|
|
1713
|
+
}
|
|
1714
|
+
if (focusVisibleLayer && pfv > 0 && focusVisibleLayer[k] !== void 0) {
|
|
1715
|
+
const c = base + (focusVisibleLayer[k] - base) * pfv;
|
|
1716
|
+
if (c > m) m = c;
|
|
1717
|
+
}
|
|
1718
|
+
if (pressedLayer && pp > 0 && pressedLayer[k] !== void 0) {
|
|
1719
|
+
const c = base + (pressedLayer[k] - base) * pp;
|
|
1720
|
+
if (c > m) m = c;
|
|
1721
|
+
}
|
|
1722
|
+
if (disabledLayer && pd > 0 && disabledLayer[k] !== void 0) {
|
|
1723
|
+
m = m + (disabledLayer[k] - m) * pd;
|
|
1724
|
+
}
|
|
1725
|
+
out[k] = m;
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
return out;
|
|
1729
|
+
});
|
|
1730
|
+
return {
|
|
1731
|
+
style,
|
|
1732
|
+
handlers: gesture.handlers
|
|
1733
|
+
};
|
|
1734
|
+
}
|
|
1735
|
+
function disabledTransition(transition) {
|
|
1736
|
+
if (!transition) return void 0;
|
|
1737
|
+
if (isTopLevelTransition(transition)) return transition;
|
|
1738
|
+
return void 0;
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
export { useGestureLayer };
|
|
1742
|
+
//# sourceMappingURL=index.mjs.map
|
|
1743
|
+
//# sourceMappingURL=index.mjs.map
|