@onlynative/inertia 0.0.1-alpha.3 → 0.0.1-alpha.4
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 +19 -5
- package/dist/index.d.mts +259 -3
- package/dist/index.d.ts +259 -3
- package/dist/index.js +1711 -118
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1709 -122
- 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 +1502 -64
- package/dist/motion/Image.js.map +1 -1
- package/dist/motion/Image.mjs +1504 -66
- 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 +1502 -64
- package/dist/motion/Pressable.js.map +1 -1
- package/dist/motion/Pressable.mjs +1504 -66
- 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 +1502 -64
- package/dist/motion/ScrollView.js.map +1 -1
- package/dist/motion/ScrollView.mjs +1504 -66
- 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 +1502 -64
- package/dist/motion/Text.js.map +1 -1
- package/dist/motion/Text.mjs +1504 -66
- 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 +1502 -64
- package/dist/motion/View.js.map +1 -1
- package/dist/motion/View.mjs +1504 -66
- package/dist/motion/View.mjs.map +1 -1
- package/dist/{types-DAhX3fC2.d.mts → types-CjztO3RW.d.mts} +49 -4
- package/dist/{types-DAhX3fC2.d.ts → types-CjztO3RW.d.ts} +49 -4
- package/llms.txt +29 -4
- package/package.json +1 -1
- package/src/__type-tests__/animate.test-d.tsx +88 -0
- package/src/index.ts +16 -1
- package/src/layout/index.ts +1 -0
- package/src/layout/resolveLayout.ts +54 -0
- package/src/motion/createMotionComponent.tsx +38 -60
- package/src/transitions/easing.ts +3 -1
- package/src/transitions/index.ts +3 -0
- package/src/transitions/keys.ts +32 -0
- package/src/transitions/resolve.ts +1 -24
- package/src/transitions/sig.ts +40 -0
- package/src/transitions/spring.ts +41 -0
- package/src/types.ts +52 -2
- package/src/values/index.ts +14 -0
- package/src/values/useAnimation.ts +69 -0
- package/src/values/useGesture.ts +144 -0
- package/src/values/useMotionValue.ts +33 -0
- package/src/values/useScroll.ts +72 -0
- package/src/values/useSpring.ts +93 -0
- package/src/values/useTransform.ts +132 -0
package/dist/index.js
CHANGED
|
@@ -9,12 +9,19 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
9
9
|
|
|
10
10
|
var Animated__default = /*#__PURE__*/_interopDefault(Animated);
|
|
11
11
|
|
|
12
|
+
var __typeError = (msg) => {
|
|
13
|
+
throw TypeError(msg);
|
|
14
|
+
};
|
|
12
15
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
13
16
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
14
17
|
}) : x)(function(x) {
|
|
15
18
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
16
19
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
17
20
|
});
|
|
21
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
22
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
23
|
+
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);
|
|
24
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
18
25
|
var DEFAULT_MOTION_CONFIG = {
|
|
19
26
|
reducedMotion: "user"
|
|
20
27
|
};
|
|
@@ -24,45 +31,1481 @@ var MotionConfigContext = react.createContext(
|
|
|
24
31
|
function useMotionConfig() {
|
|
25
32
|
return react.useContext(MotionConfigContext);
|
|
26
33
|
}
|
|
27
|
-
function useShouldReduceMotion() {
|
|
28
|
-
const { reducedMotion } = useMotionConfig();
|
|
29
|
-
const osReduced = Animated.useReducedMotion();
|
|
30
|
-
if (reducedMotion === "never") return false;
|
|
31
|
-
if (reducedMotion === "always") return true;
|
|
32
|
-
return osReduced;
|
|
34
|
+
function useShouldReduceMotion() {
|
|
35
|
+
const { reducedMotion } = useMotionConfig();
|
|
36
|
+
const osReduced = Animated.useReducedMotion();
|
|
37
|
+
if (reducedMotion === "never") return false;
|
|
38
|
+
if (reducedMotion === "always") return true;
|
|
39
|
+
return osReduced;
|
|
40
|
+
}
|
|
41
|
+
function MotionConfig({
|
|
42
|
+
reducedMotion = "user",
|
|
43
|
+
children
|
|
44
|
+
}) {
|
|
45
|
+
const value = react.useMemo(
|
|
46
|
+
() => ({ reducedMotion }),
|
|
47
|
+
[reducedMotion]
|
|
48
|
+
);
|
|
49
|
+
return /* @__PURE__ */ jsxRuntime.jsx(MotionConfigContext.Provider, { value, children });
|
|
50
|
+
}
|
|
51
|
+
var modality = "keyboard";
|
|
52
|
+
var installed = false;
|
|
53
|
+
function setKeyboard() {
|
|
54
|
+
modality = "keyboard";
|
|
55
|
+
}
|
|
56
|
+
function setPointer() {
|
|
57
|
+
modality = "pointer";
|
|
58
|
+
}
|
|
59
|
+
function ensureInstalled() {
|
|
60
|
+
if (installed) return;
|
|
61
|
+
if (reactNative.Platform.OS !== "web") return;
|
|
62
|
+
if (typeof document === "undefined") return;
|
|
63
|
+
document.addEventListener("keydown", setKeyboard, true);
|
|
64
|
+
document.addEventListener("mousedown", setPointer, true);
|
|
65
|
+
document.addEventListener("pointerdown", setPointer, true);
|
|
66
|
+
document.addEventListener("touchstart", setPointer, true);
|
|
67
|
+
installed = true;
|
|
68
|
+
}
|
|
69
|
+
function isFocusVisible() {
|
|
70
|
+
if (reactNative.Platform.OS !== "web") return true;
|
|
71
|
+
ensureInstalled();
|
|
72
|
+
return modality === "keyboard";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ../../node_modules/react-native-worklets/lib/module/logger.js
|
|
76
|
+
var PREFIX = "[Worklets]";
|
|
77
|
+
function formatMessage(message) {
|
|
78
|
+
return `${PREFIX} ${message}`;
|
|
79
|
+
}
|
|
80
|
+
var logger = {
|
|
81
|
+
warn(message) {
|
|
82
|
+
console.warn(formatMessage(message));
|
|
83
|
+
},
|
|
84
|
+
error(message) {
|
|
85
|
+
console.error(formatMessage(message));
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// ../../node_modules/react-native-worklets/lib/module/runtimeKind.js
|
|
90
|
+
var RuntimeKind = /* @__PURE__ */ (function(RuntimeKind2) {
|
|
91
|
+
RuntimeKind2[RuntimeKind2["ReactNative"] = 1] = "ReactNative";
|
|
92
|
+
RuntimeKind2[RuntimeKind2["UI"] = 2] = "UI";
|
|
93
|
+
RuntimeKind2[RuntimeKind2["Worker"] = 3] = "Worker";
|
|
94
|
+
return RuntimeKind2;
|
|
95
|
+
})({});
|
|
96
|
+
if (globalThis.__RUNTIME_KIND === void 0) {
|
|
97
|
+
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsError.js
|
|
101
|
+
function WorkletsErrorConstructor(message) {
|
|
102
|
+
"worklet";
|
|
103
|
+
const prefix = "[Worklets]";
|
|
104
|
+
const errorInstance = new Error(message ? `${prefix} ${message}` : prefix);
|
|
105
|
+
errorInstance.name = `WorkletsError`;
|
|
106
|
+
return errorInstance;
|
|
107
|
+
}
|
|
108
|
+
function registerWorkletsError() {
|
|
109
|
+
"worklet";
|
|
110
|
+
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
|
|
111
|
+
globalThis.WorkletsError = WorkletsErrorConstructor;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
var WorkletsError = WorkletsErrorConstructor;
|
|
115
|
+
|
|
116
|
+
// ../../node_modules/react-native-worklets/lib/module/bundleUnpacker.js
|
|
117
|
+
var handleCache = /* @__PURE__ */ new WeakMap();
|
|
118
|
+
function bundleValueUnpacker(objectToUnpack, category, remoteFunctionName) {
|
|
119
|
+
const workletHash = objectToUnpack.__workletHash;
|
|
120
|
+
if (workletHash !== void 0) {
|
|
121
|
+
return getWorklet(workletHash, objectToUnpack.__closure);
|
|
122
|
+
} else if (objectToUnpack.__init !== void 0) {
|
|
123
|
+
let value = handleCache.get(objectToUnpack);
|
|
124
|
+
if (value === void 0) {
|
|
125
|
+
value = objectToUnpack.__init();
|
|
126
|
+
handleCache.set(objectToUnpack, value);
|
|
127
|
+
}
|
|
128
|
+
return value;
|
|
129
|
+
} else if (category === "RemoteFunction") {
|
|
130
|
+
const remoteFunctionHolder = () => {
|
|
131
|
+
const label = remoteFunctionName ? `function \`${remoteFunctionName}\`` : "anonymous function";
|
|
132
|
+
throw new WorkletsError(`Tried to synchronously call a non-worklet ${label} on the UI thread.
|
|
133
|
+
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.`);
|
|
134
|
+
};
|
|
135
|
+
remoteFunctionHolder.__remoteFunction = objectToUnpack;
|
|
136
|
+
return remoteFunctionHolder;
|
|
137
|
+
} else {
|
|
138
|
+
throw new WorkletsError(`Data type in category "${category}" not recognized by value unpacker: "${globalThis._toString(objectToUnpack)}".`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function getWorklet(workletHash, closureVariables) {
|
|
142
|
+
let worklet;
|
|
143
|
+
if (__DEV__) {
|
|
144
|
+
try {
|
|
145
|
+
worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
|
|
146
|
+
} catch (_e) {
|
|
147
|
+
logger.error("Unable to resolve worklet with hash " + workletHash + ". Try reloading the app.");
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
|
|
151
|
+
}
|
|
152
|
+
return worklet;
|
|
153
|
+
}
|
|
154
|
+
var metroRequire = globalThis.__r;
|
|
155
|
+
function getWorkletFromMetroRequire(workletHash, closureVariables) {
|
|
156
|
+
const factory = metroRequire(workletHash).default;
|
|
157
|
+
return factory(closureVariables);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// ../../node_modules/react-native-worklets/lib/module/callGuard.js
|
|
161
|
+
function callGuardDEV(fn, ...args) {
|
|
162
|
+
"worklet";
|
|
163
|
+
try {
|
|
164
|
+
return fn(...args);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (globalThis.__workletsModuleProxy) {
|
|
167
|
+
const {
|
|
168
|
+
message,
|
|
169
|
+
stack,
|
|
170
|
+
name,
|
|
171
|
+
jsEngine
|
|
172
|
+
} = error;
|
|
173
|
+
globalThis.__workletsModuleProxy.reportFatalErrorOnJS(message, stack ?? "", name ?? "WorkletsError", jsEngine ?? "Worklets");
|
|
174
|
+
} else {
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function setupCallGuard() {
|
|
180
|
+
"worklet";
|
|
181
|
+
if (!globalThis.__callGuardDEV) {
|
|
182
|
+
globalThis.__callGuardDEV = callGuardDEV;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ../../node_modules/react-native-worklets/lib/module/errors.js
|
|
187
|
+
var _workletStackDetails = /* @__PURE__ */ new Map();
|
|
188
|
+
function registerWorkletStackDetails(hash, stackDetails) {
|
|
189
|
+
_workletStackDetails.set(hash, stackDetails);
|
|
190
|
+
}
|
|
191
|
+
function getBundleOffset(error) {
|
|
192
|
+
const frame = error.stack?.split("\n")?.[0];
|
|
193
|
+
if (frame) {
|
|
194
|
+
const parsedFrame = /@([^@]+):(\d+):(\d+)/.exec(frame);
|
|
195
|
+
if (parsedFrame) {
|
|
196
|
+
const [, file, line, col] = parsedFrame;
|
|
197
|
+
return [file, Number(line), Number(col)];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return ["unknown", 0, 0];
|
|
201
|
+
}
|
|
202
|
+
function processStack(stack) {
|
|
203
|
+
if (stack === "" || stack === void 0) {
|
|
204
|
+
return void 0;
|
|
205
|
+
}
|
|
206
|
+
const workletStackEntries = stack.match(/worklet_(\d+):(\d+):(\d+)/g);
|
|
207
|
+
let result = stack;
|
|
208
|
+
workletStackEntries?.forEach((match) => {
|
|
209
|
+
const [, hash, origLine, origCol] = match.split(/:|_/).map(Number);
|
|
210
|
+
const errorDetails = _workletStackDetails.get(hash);
|
|
211
|
+
if (!errorDetails) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const [error, lineOffset, colOffset] = errorDetails;
|
|
215
|
+
const [bundleFile, bundleLine, bundleCol] = getBundleOffset(error);
|
|
216
|
+
const line = origLine + bundleLine + lineOffset;
|
|
217
|
+
const col = origCol + bundleCol + colOffset;
|
|
218
|
+
result = result.replace(match, `${bundleFile}:${line}:${col}`);
|
|
219
|
+
});
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
function reportFatalRemoteError({
|
|
223
|
+
message,
|
|
224
|
+
stack,
|
|
225
|
+
name,
|
|
226
|
+
jsEngine
|
|
227
|
+
}, force) {
|
|
228
|
+
const error = new WorkletsError();
|
|
229
|
+
error.message = message;
|
|
230
|
+
error.stack = processStack(stack);
|
|
231
|
+
error.name = name;
|
|
232
|
+
error.jsEngine = jsEngine;
|
|
233
|
+
if (force) {
|
|
234
|
+
throw error;
|
|
235
|
+
} else {
|
|
236
|
+
globalThis.ErrorUtils.reportFatalError(error);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function registerReportFatalRemoteError() {
|
|
240
|
+
globalThis.__reportFatalRemoteError = reportFatalRemoteError;
|
|
241
|
+
}
|
|
242
|
+
var IS_JEST = !!process.env.JEST_WORKER_ID;
|
|
243
|
+
var IS_WEB = reactNative.Platform.OS === "web";
|
|
244
|
+
var IS_WINDOWS = reactNative.Platform.OS === "windows";
|
|
245
|
+
var SHOULD_BE_USE_WEB = IS_JEST || IS_WEB || IS_WINDOWS;
|
|
246
|
+
|
|
247
|
+
// ../../node_modules/react-native-worklets/lib/module/PlatformChecker/index.js
|
|
248
|
+
var IS_JEST2 = false;
|
|
249
|
+
var SHOULD_BE_USE_WEB2 = false;
|
|
250
|
+
if (globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
251
|
+
IS_JEST2 = IS_JEST;
|
|
252
|
+
SHOULD_BE_USE_WEB2 = SHOULD_BE_USE_WEB;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/common/setImmediatePolyfill.js
|
|
256
|
+
function setupSetImmediate() {
|
|
257
|
+
"worklet";
|
|
258
|
+
const setImmediatePolyfill = (callback, ...args) => {
|
|
259
|
+
return setTimeout(callback, 0, ...args);
|
|
260
|
+
};
|
|
261
|
+
const clearImmediatePolyfill = (immediateHandle) => {
|
|
262
|
+
clearTimeout(immediateHandle);
|
|
263
|
+
};
|
|
264
|
+
globalThis.setImmediate = setImmediatePolyfill;
|
|
265
|
+
globalThis.clearImmediate = clearImmediatePolyfill;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/common/setIntervalPolyfill.js
|
|
269
|
+
function setupSetInterval() {
|
|
270
|
+
"worklet";
|
|
271
|
+
const intervalHandleToTimeoutHandle = /* @__PURE__ */ new Map();
|
|
272
|
+
const setIntervalPolyfill = (callback, delay = 0, ...args) => {
|
|
273
|
+
let intervalHandle = 0;
|
|
274
|
+
const repeatingCallback = () => {
|
|
275
|
+
const timeoutHandle = setTimeout(repeatingCallback, delay);
|
|
276
|
+
intervalHandleToTimeoutHandle.set(intervalHandle, timeoutHandle);
|
|
277
|
+
callback(...args);
|
|
278
|
+
};
|
|
279
|
+
intervalHandle = setTimeout(repeatingCallback, delay);
|
|
280
|
+
intervalHandleToTimeoutHandle.set(intervalHandle, intervalHandle);
|
|
281
|
+
return intervalHandle;
|
|
282
|
+
};
|
|
283
|
+
const clearIntervalPolyfill = (intervalHandle) => {
|
|
284
|
+
const timeoutHandle = intervalHandleToTimeoutHandle.get(intervalHandle);
|
|
285
|
+
clearTimeout(timeoutHandle);
|
|
286
|
+
intervalHandleToTimeoutHandle.delete(intervalHandle);
|
|
287
|
+
};
|
|
288
|
+
globalThis.setInterval = setIntervalPolyfill;
|
|
289
|
+
globalThis.clearInterval = clearIntervalPolyfill;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js
|
|
293
|
+
function mockedRequestAnimationFrame(callback) {
|
|
294
|
+
return setTimeout(() => callback(performance.now()), 0);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// ../../node_modules/react-native-worklets/lib/module/isSynchronizable.js
|
|
298
|
+
function isSynchronizable(value) {
|
|
299
|
+
return typeof value === "object" && value !== null && "__synchronizableRef" in value && value.__synchronizableRef === true;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ../../node_modules/react-native-worklets/lib/module/serializableMappingCache.js
|
|
303
|
+
var serializableMappingFlag = /* @__PURE__ */ Symbol("serializable flag");
|
|
304
|
+
var cache = SHOULD_BE_USE_WEB2 ? null : /* @__PURE__ */ new WeakMap();
|
|
305
|
+
var serializableMappingCache = SHOULD_BE_USE_WEB2 ? {
|
|
306
|
+
set() {
|
|
307
|
+
},
|
|
308
|
+
get() {
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
} : {
|
|
312
|
+
set(serializable, serializableRef) {
|
|
313
|
+
cache.set(serializable, serializableRef || serializableMappingFlag);
|
|
314
|
+
},
|
|
315
|
+
get: cache.get.bind(cache)
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
// ../../node_modules/react-native-worklets/lib/module/utils/jsVersion.js
|
|
319
|
+
var jsVersion = "0.5.1";
|
|
320
|
+
|
|
321
|
+
// ../../node_modules/react-native-worklets/lib/module/workletFunction.js
|
|
322
|
+
function isWorkletFunction(value) {
|
|
323
|
+
"worklet";
|
|
324
|
+
return (
|
|
325
|
+
// `__workletHash` isn't extracted in Worklet Runtimes.
|
|
326
|
+
typeof value === "function" && !!value.__workletHash
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsModule/JSWorklets.js
|
|
331
|
+
function createJSWorkletsModule() {
|
|
332
|
+
return new JSWorklets();
|
|
333
|
+
}
|
|
334
|
+
var requestAnimationFrameImpl = IS_JEST2 || !globalThis.requestAnimationFrame ? mockedRequestAnimationFrame : globalThis.requestAnimationFrame;
|
|
335
|
+
var JSWorklets = class {
|
|
336
|
+
createSerializable() {
|
|
337
|
+
throw new WorkletsError("createSerializable should never be called in JSWorklets.");
|
|
338
|
+
}
|
|
339
|
+
createSerializableString() {
|
|
340
|
+
throw new WorkletsError("createSerializableString should never be called in JSWorklets.");
|
|
341
|
+
}
|
|
342
|
+
createSerializableNumber() {
|
|
343
|
+
throw new WorkletsError("createSerializableNumber should never be called in JSWorklets.");
|
|
344
|
+
}
|
|
345
|
+
createSerializableBoolean() {
|
|
346
|
+
throw new WorkletsError("createSerializableBoolean should never be called in JSWorklets.");
|
|
347
|
+
}
|
|
348
|
+
createSerializableBigInt() {
|
|
349
|
+
throw new WorkletsError("createSerializableBigInt should never be called in JSWorklets.");
|
|
350
|
+
}
|
|
351
|
+
createSerializableUndefined() {
|
|
352
|
+
throw new WorkletsError("createSerializableUndefined should never be called in JSWorklets.");
|
|
353
|
+
}
|
|
354
|
+
createSerializableNull() {
|
|
355
|
+
throw new WorkletsError("createSerializableNull should never be called in JSWorklets.");
|
|
356
|
+
}
|
|
357
|
+
createSerializableTurboModuleLike() {
|
|
358
|
+
throw new WorkletsError("createSerializableTurboModuleLike should never be called in JSWorklets.");
|
|
359
|
+
}
|
|
360
|
+
createSerializableObject() {
|
|
361
|
+
throw new WorkletsError("createSerializableObject should never be called in JSWorklets.");
|
|
362
|
+
}
|
|
363
|
+
createSerializableMap() {
|
|
364
|
+
throw new WorkletsError("createSerializableMap should never be called in JSWorklets.");
|
|
365
|
+
}
|
|
366
|
+
createSerializableSet() {
|
|
367
|
+
throw new WorkletsError("createSerializableSet should never be called in JSWorklets.");
|
|
368
|
+
}
|
|
369
|
+
createSerializableImport() {
|
|
370
|
+
throw new WorkletsError("createSerializableImport should never be called in JSWorklets.");
|
|
371
|
+
}
|
|
372
|
+
createSerializableHostObject() {
|
|
373
|
+
throw new WorkletsError("createSerializableHostObject should never be called in JSWorklets.");
|
|
374
|
+
}
|
|
375
|
+
createSerializableArray() {
|
|
376
|
+
throw new WorkletsError("createSerializableArray should never be called in JSWorklets.");
|
|
377
|
+
}
|
|
378
|
+
createSerializableInitializer() {
|
|
379
|
+
throw new WorkletsError("createSerializableInitializer should never be called in JSWorklets.");
|
|
380
|
+
}
|
|
381
|
+
createSerializableFunction() {
|
|
382
|
+
throw new WorkletsError("createSerializableFunction should never be called in JSWorklets.");
|
|
383
|
+
}
|
|
384
|
+
createSerializableWorklet() {
|
|
385
|
+
throw new WorkletsError("createSerializableWorklet should never be called in JSWorklets.");
|
|
386
|
+
}
|
|
387
|
+
scheduleOnUI(worklet) {
|
|
388
|
+
requestAnimationFrameImpl(worklet);
|
|
389
|
+
}
|
|
390
|
+
executeOnUIRuntimeSync() {
|
|
391
|
+
throw new WorkletsError("`executeOnUIRuntimeSync` is not available in JSWorklets.");
|
|
392
|
+
}
|
|
393
|
+
createWorkletRuntime() {
|
|
394
|
+
throw new WorkletsError("createWorkletRuntime is not available in JSWorklets.");
|
|
395
|
+
}
|
|
396
|
+
scheduleOnRuntime() {
|
|
397
|
+
throw new WorkletsError("scheduleOnRuntime is not available in JSWorklets.");
|
|
398
|
+
}
|
|
399
|
+
createSynchronizable() {
|
|
400
|
+
throw new WorkletsError("createSynchronizable should never be called in JSWorklets.");
|
|
401
|
+
}
|
|
402
|
+
synchronizableGetDirty() {
|
|
403
|
+
throw new WorkletsError("synchronizableGetDirty should never be called in JSWorklets.");
|
|
404
|
+
}
|
|
405
|
+
synchronizableGetBlocking() {
|
|
406
|
+
throw new WorkletsError("synchronizableGetBlocking should never be called in JSWorklets.");
|
|
407
|
+
}
|
|
408
|
+
synchronizableSetBlocking() {
|
|
409
|
+
throw new WorkletsError("synchronizableSetBlocking should never be called in JSWorklets.");
|
|
410
|
+
}
|
|
411
|
+
synchronizableLock() {
|
|
412
|
+
throw new WorkletsError("synchronizableLock should never be called in JSWorklets.");
|
|
413
|
+
}
|
|
414
|
+
synchronizableUnlock() {
|
|
415
|
+
throw new WorkletsError("synchronizableUnlock should never be called in JSWorklets.");
|
|
416
|
+
}
|
|
417
|
+
reportFatalErrorOnJS() {
|
|
418
|
+
throw new WorkletsError("reportFatalErrorOnJS should never be called in JSWorklets.");
|
|
419
|
+
}
|
|
420
|
+
getStaticFeatureFlag() {
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
setDynamicFeatureFlag() {
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
var NativeWorkletsModule_default = reactNative.TurboModuleRegistry.get("WorkletsModule");
|
|
427
|
+
|
|
428
|
+
// ../../node_modules/react-native-worklets/lib/module/specs/index.js
|
|
429
|
+
var WorkletsTurboModule = globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative ? NativeWorkletsModule_default : (
|
|
430
|
+
// In Bundle Mode, on Worklet Runtimes `RNWorkletsTurboModule` isn't
|
|
431
|
+
// available and shouldn't be accessed. We return null here
|
|
432
|
+
// to keep the same codebase for the Bundle Mode and legacy behavior.
|
|
433
|
+
null
|
|
434
|
+
);
|
|
435
|
+
|
|
436
|
+
// ../../node_modules/react-native-worklets/lib/module/utils/checkCppVersion.js
|
|
437
|
+
function checkCppVersion() {
|
|
438
|
+
const cppVersion = global._WORKLETS_VERSION_CPP;
|
|
439
|
+
if (cppVersion === void 0) {
|
|
440
|
+
logger.warn(`Couldn't determine the version of the native part of Worklets.
|
|
441
|
+
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#couldnt-determine-the-version-of-the-native-part-of-worklets\` for more details.`);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
const ok = matchVersion(jsVersion, cppVersion);
|
|
445
|
+
if (!ok) {
|
|
446
|
+
throw new WorkletsError(`Mismatch between JavaScript part and native part of Worklets (${jsVersion} vs ${cppVersion}).
|
|
447
|
+
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-part-and-native-part-of-worklets\` for more details.`);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
function matchVersion(version1, version2) {
|
|
451
|
+
if (version1.match(/^\d+\.\d+\.\d+$/) && version2.match(/^\d+\.\d+\.\d+$/)) {
|
|
452
|
+
const [major1, minor1] = version1.split(".");
|
|
453
|
+
const [major2, minor2] = version2.split(".");
|
|
454
|
+
return major1 === major2 && minor1 === minor2;
|
|
455
|
+
} else {
|
|
456
|
+
return version1 === version2;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsModule/NativeWorklets.js
|
|
461
|
+
function createNativeWorkletsModule() {
|
|
462
|
+
return new NativeWorklets();
|
|
463
|
+
}
|
|
464
|
+
var _workletsModuleProxy, _serializableUndefined, _serializableNull, _serializableTrue, _serializableFalse;
|
|
465
|
+
var NativeWorklets = class {
|
|
466
|
+
constructor() {
|
|
467
|
+
__privateAdd(this, _workletsModuleProxy);
|
|
468
|
+
__privateAdd(this, _serializableUndefined);
|
|
469
|
+
__privateAdd(this, _serializableNull);
|
|
470
|
+
__privateAdd(this, _serializableTrue);
|
|
471
|
+
__privateAdd(this, _serializableFalse);
|
|
472
|
+
globalThis._WORKLETS_VERSION_JS = jsVersion;
|
|
473
|
+
if (global.__workletsModuleProxy === void 0 && globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
474
|
+
WorkletsTurboModule?.installTurboModule();
|
|
475
|
+
}
|
|
476
|
+
if (global.__workletsModuleProxy === void 0) {
|
|
477
|
+
throw new WorkletsError(`Native part of Worklets doesn't seem to be initialized.
|
|
478
|
+
See https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#native-part-of-worklets-doesnt-seem-to-be-initialized for more details.`);
|
|
479
|
+
}
|
|
480
|
+
if (__DEV__) {
|
|
481
|
+
checkCppVersion();
|
|
482
|
+
}
|
|
483
|
+
__privateSet(this, _workletsModuleProxy, global.__workletsModuleProxy);
|
|
484
|
+
__privateSet(this, _serializableNull, __privateGet(this, _workletsModuleProxy).createSerializableNull());
|
|
485
|
+
__privateSet(this, _serializableUndefined, __privateGet(this, _workletsModuleProxy).createSerializableUndefined());
|
|
486
|
+
__privateSet(this, _serializableTrue, __privateGet(this, _workletsModuleProxy).createSerializableBoolean(true));
|
|
487
|
+
__privateSet(this, _serializableFalse, __privateGet(this, _workletsModuleProxy).createSerializableBoolean(false));
|
|
488
|
+
}
|
|
489
|
+
createSerializable(value, shouldPersistRemote, nativeStateSource) {
|
|
490
|
+
return __privateGet(this, _workletsModuleProxy).createSerializable(value, shouldPersistRemote, nativeStateSource);
|
|
491
|
+
}
|
|
492
|
+
createSerializableImport(from, to) {
|
|
493
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableImport(from, to);
|
|
494
|
+
}
|
|
495
|
+
createSerializableString(str) {
|
|
496
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableString(str);
|
|
497
|
+
}
|
|
498
|
+
createSerializableNumber(num) {
|
|
499
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableNumber(num);
|
|
500
|
+
}
|
|
501
|
+
createSerializableBoolean(bool) {
|
|
502
|
+
return bool ? __privateGet(this, _serializableTrue) : __privateGet(this, _serializableFalse);
|
|
503
|
+
}
|
|
504
|
+
createSerializableBigInt(bigInt) {
|
|
505
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableBigInt(bigInt);
|
|
506
|
+
}
|
|
507
|
+
createSerializableUndefined() {
|
|
508
|
+
return __privateGet(this, _serializableUndefined);
|
|
509
|
+
}
|
|
510
|
+
createSerializableNull() {
|
|
511
|
+
return __privateGet(this, _serializableNull);
|
|
512
|
+
}
|
|
513
|
+
createSerializableTurboModuleLike(props, proto) {
|
|
514
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableTurboModuleLike(props, proto);
|
|
515
|
+
}
|
|
516
|
+
createSerializableObject(obj, shouldRetainRemote, nativeStateSource) {
|
|
517
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableObject(obj, shouldRetainRemote, nativeStateSource);
|
|
518
|
+
}
|
|
519
|
+
createSerializableHostObject(obj) {
|
|
520
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableHostObject(obj);
|
|
521
|
+
}
|
|
522
|
+
createSerializableArray(array, shouldRetainRemote) {
|
|
523
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableArray(array, shouldRetainRemote);
|
|
524
|
+
}
|
|
525
|
+
createSerializableMap(keys, values) {
|
|
526
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableMap(keys, values);
|
|
527
|
+
}
|
|
528
|
+
createSerializableSet(values) {
|
|
529
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableSet(values);
|
|
530
|
+
}
|
|
531
|
+
createSerializableInitializer(obj) {
|
|
532
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableInitializer(obj);
|
|
533
|
+
}
|
|
534
|
+
createSerializableFunction(func) {
|
|
535
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableFunction(func);
|
|
536
|
+
}
|
|
537
|
+
createSerializableWorklet(worklet, shouldPersistRemote) {
|
|
538
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableWorklet(worklet, shouldPersistRemote);
|
|
539
|
+
}
|
|
540
|
+
scheduleOnUI(serializable) {
|
|
541
|
+
return __privateGet(this, _workletsModuleProxy).scheduleOnUI(serializable);
|
|
542
|
+
}
|
|
543
|
+
executeOnUIRuntimeSync(serializable) {
|
|
544
|
+
return __privateGet(this, _workletsModuleProxy).executeOnUIRuntimeSync(serializable);
|
|
545
|
+
}
|
|
546
|
+
createWorkletRuntime(name, initializer, useDefaultQueue, customQueue, enableEventLoop) {
|
|
547
|
+
return __privateGet(this, _workletsModuleProxy).createWorkletRuntime(name, initializer, useDefaultQueue, customQueue, enableEventLoop);
|
|
548
|
+
}
|
|
549
|
+
scheduleOnRuntime(workletRuntime, serializableWorklet) {
|
|
550
|
+
return __privateGet(this, _workletsModuleProxy).scheduleOnRuntime(workletRuntime, serializableWorklet);
|
|
551
|
+
}
|
|
552
|
+
createSynchronizable(value) {
|
|
553
|
+
return __privateGet(this, _workletsModuleProxy).createSynchronizable(value);
|
|
554
|
+
}
|
|
555
|
+
synchronizableGetDirty(synchronizableRef) {
|
|
556
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableGetDirty(synchronizableRef);
|
|
557
|
+
}
|
|
558
|
+
synchronizableGetBlocking(synchronizableRef) {
|
|
559
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableGetBlocking(synchronizableRef);
|
|
560
|
+
}
|
|
561
|
+
synchronizableSetBlocking(synchronizableRef, value) {
|
|
562
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableSetBlocking(synchronizableRef, value);
|
|
563
|
+
}
|
|
564
|
+
synchronizableLock(synchronizableRef) {
|
|
565
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableLock(synchronizableRef);
|
|
566
|
+
}
|
|
567
|
+
synchronizableUnlock(synchronizableRef) {
|
|
568
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableUnlock(synchronizableRef);
|
|
569
|
+
}
|
|
570
|
+
reportFatalErrorOnJS(message, stack, name, jsEngine) {
|
|
571
|
+
return __privateGet(this, _workletsModuleProxy).reportFatalErrorOnJS(message, stack, name, jsEngine);
|
|
572
|
+
}
|
|
573
|
+
getStaticFeatureFlag(name) {
|
|
574
|
+
return __privateGet(this, _workletsModuleProxy).getStaticFeatureFlag(name);
|
|
575
|
+
}
|
|
576
|
+
setDynamicFeatureFlag(name, value) {
|
|
577
|
+
__privateGet(this, _workletsModuleProxy).setDynamicFeatureFlag(name, value);
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
_workletsModuleProxy = new WeakMap();
|
|
581
|
+
_serializableUndefined = new WeakMap();
|
|
582
|
+
_serializableNull = new WeakMap();
|
|
583
|
+
_serializableTrue = new WeakMap();
|
|
584
|
+
_serializableFalse = new WeakMap();
|
|
585
|
+
|
|
586
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsModule/workletsModuleInstance.js
|
|
587
|
+
var WorkletsModule = SHOULD_BE_USE_WEB2 ? createJSWorkletsModule() : createNativeWorkletsModule();
|
|
588
|
+
|
|
589
|
+
// ../../node_modules/react-native-worklets/lib/module/serializable.js
|
|
590
|
+
var MAGIC_KEY = "REANIMATED_MAGIC_KEY";
|
|
591
|
+
function isHostObject(value) {
|
|
592
|
+
"worklet";
|
|
593
|
+
return MAGIC_KEY in value;
|
|
594
|
+
}
|
|
595
|
+
function isPlainJSObject(object) {
|
|
596
|
+
"worklet";
|
|
597
|
+
return Object.getPrototypeOf(object) === Object.prototype;
|
|
598
|
+
}
|
|
599
|
+
function isTurboModuleLike(object) {
|
|
600
|
+
return isHostObject(Object.getPrototypeOf(object));
|
|
601
|
+
}
|
|
602
|
+
function getFromCache(value) {
|
|
603
|
+
const cached = serializableMappingCache.get(value);
|
|
604
|
+
if (cached === serializableMappingFlag) {
|
|
605
|
+
return value;
|
|
606
|
+
}
|
|
607
|
+
return cached;
|
|
608
|
+
}
|
|
609
|
+
var INACCESSIBLE_OBJECT = {
|
|
610
|
+
__init: () => {
|
|
611
|
+
"worklet";
|
|
612
|
+
return new Proxy({}, {
|
|
613
|
+
get: (_, prop) => {
|
|
614
|
+
if (prop === "_isReanimatedSharedValue" || prop === "__remoteFunction") {
|
|
615
|
+
return false;
|
|
616
|
+
}
|
|
617
|
+
throw new WorkletsError(`Trying to access property \`${String(prop)}\` of an object which cannot be sent to the UI runtime.`);
|
|
618
|
+
},
|
|
619
|
+
set: () => {
|
|
620
|
+
throw new WorkletsError("Trying to write to an object which cannot be sent to the UI runtime.");
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
var VALID_ARRAY_VIEWS_NAMES = ["Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array", "DataView"];
|
|
626
|
+
var DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD = 30;
|
|
627
|
+
var processedObjectAtThresholdDepth;
|
|
628
|
+
function createSerializableWeb(value) {
|
|
629
|
+
return value;
|
|
630
|
+
}
|
|
631
|
+
function createSerializableNative(value, shouldPersistRemote = false, depth = 0) {
|
|
632
|
+
detectCyclicObject(value, depth);
|
|
633
|
+
const isObject = typeof value === "object";
|
|
634
|
+
const isFunction = typeof value === "function";
|
|
635
|
+
if (typeof value === "string") {
|
|
636
|
+
return cloneString(value);
|
|
637
|
+
}
|
|
638
|
+
if (typeof value === "number") {
|
|
639
|
+
return cloneNumber(value);
|
|
640
|
+
}
|
|
641
|
+
if (typeof value === "boolean") {
|
|
642
|
+
return cloneBoolean(value);
|
|
643
|
+
}
|
|
644
|
+
if (typeof value === "bigint") {
|
|
645
|
+
return cloneBigInt(value);
|
|
646
|
+
}
|
|
647
|
+
if (value === void 0) {
|
|
648
|
+
return cloneUndefined();
|
|
649
|
+
}
|
|
650
|
+
if (value === null) {
|
|
651
|
+
return cloneNull();
|
|
652
|
+
}
|
|
653
|
+
if (!isObject && !isFunction || value === null) {
|
|
654
|
+
return clonePrimitive(value, shouldPersistRemote);
|
|
655
|
+
}
|
|
656
|
+
const cached = getFromCache(value);
|
|
657
|
+
if (cached !== void 0) {
|
|
658
|
+
return cached;
|
|
659
|
+
}
|
|
660
|
+
if (Array.isArray(value)) {
|
|
661
|
+
return cloneArray(value, shouldPersistRemote, depth);
|
|
662
|
+
}
|
|
663
|
+
if (globalThis._WORKLETS_BUNDLE_MODE && isFunction && value.__bundleData) {
|
|
664
|
+
return cloneImport(value);
|
|
665
|
+
}
|
|
666
|
+
if (isFunction && !isWorkletFunction(value)) {
|
|
667
|
+
return cloneRemoteFunction(value);
|
|
668
|
+
}
|
|
669
|
+
if (isTurboModuleLike(value)) {
|
|
670
|
+
return cloneTurboModuleLike(value, shouldPersistRemote, depth);
|
|
671
|
+
}
|
|
672
|
+
if (isHostObject(value)) {
|
|
673
|
+
return cloneHostObject(value);
|
|
674
|
+
}
|
|
675
|
+
if (isPlainJSObject(value) && value.__init) {
|
|
676
|
+
return cloneInitializer(value, shouldPersistRemote, depth);
|
|
677
|
+
}
|
|
678
|
+
if (isPlainJSObject(value) && value.__workletContextObjectFactory) {
|
|
679
|
+
return cloneContextObject(value);
|
|
680
|
+
}
|
|
681
|
+
if ((isPlainJSObject(value) || isFunction) && isWorkletFunction(value)) {
|
|
682
|
+
return cloneWorklet(value, shouldPersistRemote, depth);
|
|
683
|
+
}
|
|
684
|
+
if (isSynchronizable(value)) {
|
|
685
|
+
return cloneSynchronizable(value);
|
|
686
|
+
}
|
|
687
|
+
if (isPlainJSObject(value) || isFunction) {
|
|
688
|
+
return clonePlainJSObject(value, shouldPersistRemote, depth);
|
|
689
|
+
}
|
|
690
|
+
if (value instanceof Set) {
|
|
691
|
+
return cloneSet(value);
|
|
692
|
+
}
|
|
693
|
+
if (value instanceof Map) {
|
|
694
|
+
return cloneMap(value);
|
|
695
|
+
}
|
|
696
|
+
if (value instanceof RegExp) {
|
|
697
|
+
return cloneRegExp(value);
|
|
698
|
+
}
|
|
699
|
+
if (value instanceof Error) {
|
|
700
|
+
return cloneError(value);
|
|
701
|
+
}
|
|
702
|
+
if (value instanceof ArrayBuffer) {
|
|
703
|
+
return cloneArrayBuffer(value, shouldPersistRemote);
|
|
704
|
+
}
|
|
705
|
+
if (ArrayBuffer.isView(value)) {
|
|
706
|
+
return cloneArrayBufferView(value);
|
|
707
|
+
}
|
|
708
|
+
return inaccessibleObject(value);
|
|
709
|
+
}
|
|
710
|
+
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
711
|
+
createSerializableNative.__bundleData = {
|
|
712
|
+
imported: "createSerializable",
|
|
713
|
+
// @ts-expect-error resolveWeak is defined by Metro
|
|
714
|
+
source: __require.resolveWeak("./index")
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
var createSerializable = SHOULD_BE_USE_WEB2 ? createSerializableWeb : createSerializableNative;
|
|
718
|
+
function detectCyclicObject(value, depth) {
|
|
719
|
+
if (depth >= DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
|
|
720
|
+
if (depth === DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
|
|
721
|
+
processedObjectAtThresholdDepth = value;
|
|
722
|
+
} else if (value === processedObjectAtThresholdDepth) {
|
|
723
|
+
throw new WorkletsError("Trying to convert a cyclic object to a serializable. This is not supported.");
|
|
724
|
+
}
|
|
725
|
+
} else {
|
|
726
|
+
processedObjectAtThresholdDepth = void 0;
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
function clonePrimitive(value, shouldPersistRemote) {
|
|
730
|
+
return WorkletsModule.createSerializable(value, shouldPersistRemote);
|
|
731
|
+
}
|
|
732
|
+
function cloneString(value) {
|
|
733
|
+
return WorkletsModule.createSerializableString(value);
|
|
734
|
+
}
|
|
735
|
+
function cloneNumber(value) {
|
|
736
|
+
return WorkletsModule.createSerializableNumber(value);
|
|
737
|
+
}
|
|
738
|
+
function cloneBoolean(value) {
|
|
739
|
+
return WorkletsModule.createSerializableBoolean(value);
|
|
740
|
+
}
|
|
741
|
+
function cloneBigInt(value) {
|
|
742
|
+
return WorkletsModule.createSerializableBigInt(value);
|
|
743
|
+
}
|
|
744
|
+
function cloneUndefined() {
|
|
745
|
+
return WorkletsModule.createSerializableUndefined();
|
|
746
|
+
}
|
|
747
|
+
function cloneNull() {
|
|
748
|
+
return WorkletsModule.createSerializableNull();
|
|
749
|
+
}
|
|
750
|
+
function cloneObjectProperties(value, shouldPersistRemote, depth) {
|
|
751
|
+
const clonedProps = {};
|
|
752
|
+
for (const [key, element] of Object.entries(value)) {
|
|
753
|
+
if (key === "__initData" && clonedProps.__initData !== void 0) {
|
|
754
|
+
continue;
|
|
755
|
+
}
|
|
756
|
+
clonedProps[key] = createSerializable(element, shouldPersistRemote, depth + 1);
|
|
757
|
+
}
|
|
758
|
+
return clonedProps;
|
|
759
|
+
}
|
|
760
|
+
function cloneInitializer(value, shouldPersistRemote = false, depth = 0) {
|
|
761
|
+
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
|
|
762
|
+
return WorkletsModule.createSerializableInitializer(clonedProps);
|
|
763
|
+
}
|
|
764
|
+
function cloneArray(value, shouldPersistRemote, depth) {
|
|
765
|
+
const clonedElements = value.map((element) => createSerializable(element, shouldPersistRemote, depth + 1));
|
|
766
|
+
const clone = WorkletsModule.createSerializableArray(clonedElements, shouldPersistRemote);
|
|
767
|
+
serializableMappingCache.set(value, clone);
|
|
768
|
+
serializableMappingCache.set(clone);
|
|
769
|
+
freezeObjectInDev(value);
|
|
770
|
+
return clone;
|
|
771
|
+
}
|
|
772
|
+
function cloneRemoteFunction(value) {
|
|
773
|
+
const clone = WorkletsModule.createSerializableFunction(value);
|
|
774
|
+
serializableMappingCache.set(value, clone);
|
|
775
|
+
serializableMappingCache.set(clone);
|
|
776
|
+
freezeObjectInDev(value);
|
|
777
|
+
return clone;
|
|
778
|
+
}
|
|
779
|
+
function cloneHostObject(value) {
|
|
780
|
+
const clone = WorkletsModule.createSerializableHostObject(value);
|
|
781
|
+
serializableMappingCache.set(value, clone);
|
|
782
|
+
serializableMappingCache.set(clone);
|
|
783
|
+
return clone;
|
|
784
|
+
}
|
|
785
|
+
function cloneWorklet(value, shouldPersistRemote, depth) {
|
|
786
|
+
if (__DEV__) {
|
|
787
|
+
const babelVersion = value.__pluginVersion;
|
|
788
|
+
if (babelVersion !== void 0 && babelVersion !== jsVersion) {
|
|
789
|
+
throw new WorkletsError(`Mismatch between JavaScript code version and Worklets Babel plugin version (${jsVersion} vs. ${babelVersion}).
|
|
790
|
+
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-code-version-and-worklets-babel-plugin-version\` for more details.
|
|
791
|
+
Offending code was: \`${getWorkletCode(value)}\``);
|
|
792
|
+
}
|
|
793
|
+
registerWorkletStackDetails(value.__workletHash, value.__stackDetails);
|
|
794
|
+
}
|
|
795
|
+
if (value.__stackDetails) {
|
|
796
|
+
delete value.__stackDetails;
|
|
797
|
+
}
|
|
798
|
+
const clonedProps = cloneObjectProperties(value, true, depth);
|
|
799
|
+
clonedProps.__initData = createSerializable(value.__initData, true, depth + 1);
|
|
800
|
+
const clone = WorkletsModule.createSerializableWorklet(
|
|
801
|
+
clonedProps,
|
|
802
|
+
// TODO: Check after refactor if we can remove shouldPersistRemote parameter (imho it's redundant here since worklets are always persistent)
|
|
803
|
+
// retain all worklets
|
|
804
|
+
true
|
|
805
|
+
);
|
|
806
|
+
serializableMappingCache.set(value, clone);
|
|
807
|
+
serializableMappingCache.set(clone);
|
|
808
|
+
freezeObjectInDev(value);
|
|
809
|
+
return clone;
|
|
810
|
+
}
|
|
811
|
+
function cloneTurboModuleLike(value, shouldPersistRemote, depth) {
|
|
812
|
+
const proto = Object.getPrototypeOf(value);
|
|
813
|
+
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
|
|
814
|
+
const clone = WorkletsModule.createSerializableTurboModuleLike(clonedProps, proto);
|
|
815
|
+
return clone;
|
|
816
|
+
}
|
|
817
|
+
function cloneContextObject(value) {
|
|
818
|
+
const workletContextObjectFactory = value.__workletContextObjectFactory;
|
|
819
|
+
const handle = cloneInitializer({
|
|
820
|
+
__init: () => {
|
|
821
|
+
"worklet";
|
|
822
|
+
return workletContextObjectFactory();
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
serializableMappingCache.set(value, handle);
|
|
826
|
+
return handle;
|
|
827
|
+
}
|
|
828
|
+
function clonePlainJSObject(value, shouldPersistRemote, depth) {
|
|
829
|
+
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
|
|
830
|
+
const clone = WorkletsModule.createSerializableObject(clonedProps, shouldPersistRemote, value);
|
|
831
|
+
serializableMappingCache.set(value, clone);
|
|
832
|
+
serializableMappingCache.set(clone);
|
|
833
|
+
freezeObjectInDev(value);
|
|
834
|
+
return clone;
|
|
835
|
+
}
|
|
836
|
+
function cloneMap(value) {
|
|
837
|
+
const clonedKeys = [];
|
|
838
|
+
const clonedValues = [];
|
|
839
|
+
for (const [key, element] of value.entries()) {
|
|
840
|
+
clonedKeys.push(createSerializable(key));
|
|
841
|
+
clonedValues.push(createSerializable(element));
|
|
842
|
+
}
|
|
843
|
+
const clone = WorkletsModule.createSerializableMap(clonedKeys, clonedValues);
|
|
844
|
+
serializableMappingCache.set(value, clone);
|
|
845
|
+
serializableMappingCache.set(clone);
|
|
846
|
+
freezeObjectInDev(value);
|
|
847
|
+
return clone;
|
|
848
|
+
}
|
|
849
|
+
function cloneSet(value) {
|
|
850
|
+
const clonedElements = [];
|
|
851
|
+
for (const element of value) {
|
|
852
|
+
clonedElements.push(createSerializable(element));
|
|
853
|
+
}
|
|
854
|
+
const clone = WorkletsModule.createSerializableSet(clonedElements);
|
|
855
|
+
serializableMappingCache.set(value, clone);
|
|
856
|
+
serializableMappingCache.set(clone);
|
|
857
|
+
freezeObjectInDev(value);
|
|
858
|
+
return clone;
|
|
859
|
+
}
|
|
860
|
+
function cloneRegExp(value) {
|
|
861
|
+
const pattern = value.source;
|
|
862
|
+
const flags = value.flags;
|
|
863
|
+
const handle = cloneInitializer({
|
|
864
|
+
__init: () => {
|
|
865
|
+
"worklet";
|
|
866
|
+
return new RegExp(pattern, flags);
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
serializableMappingCache.set(value, handle);
|
|
870
|
+
return handle;
|
|
871
|
+
}
|
|
872
|
+
function cloneError(value) {
|
|
873
|
+
const {
|
|
874
|
+
name,
|
|
875
|
+
message,
|
|
876
|
+
stack
|
|
877
|
+
} = value;
|
|
878
|
+
const handle = cloneInitializer({
|
|
879
|
+
__init: () => {
|
|
880
|
+
"worklet";
|
|
881
|
+
const error = new Error();
|
|
882
|
+
error.name = name;
|
|
883
|
+
error.message = message;
|
|
884
|
+
error.stack = stack;
|
|
885
|
+
return error;
|
|
886
|
+
}
|
|
887
|
+
});
|
|
888
|
+
serializableMappingCache.set(value, handle);
|
|
889
|
+
return handle;
|
|
890
|
+
}
|
|
891
|
+
function cloneArrayBuffer(value, shouldPersistRemote) {
|
|
892
|
+
const clone = WorkletsModule.createSerializable(value, shouldPersistRemote, value);
|
|
893
|
+
serializableMappingCache.set(value, clone);
|
|
894
|
+
serializableMappingCache.set(clone);
|
|
895
|
+
return clone;
|
|
896
|
+
}
|
|
897
|
+
function cloneArrayBufferView(value) {
|
|
898
|
+
const buffer = value.buffer;
|
|
899
|
+
const typeName = value.constructor.name;
|
|
900
|
+
const handle = cloneInitializer({
|
|
901
|
+
__init: () => {
|
|
902
|
+
"worklet";
|
|
903
|
+
if (!VALID_ARRAY_VIEWS_NAMES.includes(typeName)) {
|
|
904
|
+
throw new WorkletsError(`Invalid array view name \`${typeName}\`.`);
|
|
905
|
+
}
|
|
906
|
+
const constructor = global[typeName];
|
|
907
|
+
if (constructor === void 0) {
|
|
908
|
+
throw new WorkletsError(`Constructor for \`${typeName}\` not found.`);
|
|
909
|
+
}
|
|
910
|
+
return new constructor(buffer);
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
serializableMappingCache.set(value, handle);
|
|
914
|
+
return handle;
|
|
915
|
+
}
|
|
916
|
+
function cloneSynchronizable(value) {
|
|
917
|
+
serializableMappingCache.set(value);
|
|
918
|
+
return value;
|
|
919
|
+
}
|
|
920
|
+
function cloneImport(value) {
|
|
921
|
+
const {
|
|
922
|
+
source,
|
|
923
|
+
imported
|
|
924
|
+
} = value.__bundleData;
|
|
925
|
+
const clone = WorkletsModule.createSerializableImport(source, imported);
|
|
926
|
+
serializableMappingCache.set(value, clone);
|
|
927
|
+
serializableMappingCache.set(clone);
|
|
928
|
+
return clone;
|
|
929
|
+
}
|
|
930
|
+
function inaccessibleObject(value) {
|
|
931
|
+
const clone = createSerializable(INACCESSIBLE_OBJECT);
|
|
932
|
+
serializableMappingCache.set(value, clone);
|
|
933
|
+
return clone;
|
|
934
|
+
}
|
|
935
|
+
var WORKLET_CODE_THRESHOLD = 255;
|
|
936
|
+
function getWorkletCode(value) {
|
|
937
|
+
const code = value?.__initData?.code;
|
|
938
|
+
if (!code) {
|
|
939
|
+
return "unknown";
|
|
940
|
+
}
|
|
941
|
+
if (code.length > WORKLET_CODE_THRESHOLD) {
|
|
942
|
+
return `${code.substring(0, WORKLET_CODE_THRESHOLD)}...`;
|
|
943
|
+
}
|
|
944
|
+
return code;
|
|
945
|
+
}
|
|
946
|
+
function isRemoteFunction(value) {
|
|
947
|
+
"worklet";
|
|
948
|
+
return !!value.__remoteFunction;
|
|
949
|
+
}
|
|
950
|
+
function freezeObjectInDev(value) {
|
|
951
|
+
if (!__DEV__) {
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
Object.entries(value).forEach(([key, element]) => {
|
|
955
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
956
|
+
if (!descriptor.configurable) {
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
959
|
+
Object.defineProperty(value, key, {
|
|
960
|
+
get() {
|
|
961
|
+
return element;
|
|
962
|
+
},
|
|
963
|
+
set() {
|
|
964
|
+
logger.warn(`Tried to modify key \`${key}\` of an object which has been already passed to a worklet. See
|
|
965
|
+
https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-modify-key-of-an-object-which-has-been-converted-to-a-serializable
|
|
966
|
+
for more details.`);
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
});
|
|
970
|
+
Object.preventExtensions(value);
|
|
971
|
+
}
|
|
972
|
+
function makeShareableCloneOnUIRecursiveLEGACY(value) {
|
|
973
|
+
"worklet";
|
|
974
|
+
if (SHOULD_BE_USE_WEB2) {
|
|
975
|
+
return value;
|
|
976
|
+
}
|
|
977
|
+
function cloneRecursive(value2) {
|
|
978
|
+
if (typeof value2 === "object" && value2 !== null || typeof value2 === "function") {
|
|
979
|
+
if (isHostObject(value2)) {
|
|
980
|
+
return global._createSerializableHostObject(value2);
|
|
981
|
+
}
|
|
982
|
+
if (isRemoteFunction(value2)) {
|
|
983
|
+
return value2.__remoteFunction;
|
|
984
|
+
}
|
|
985
|
+
if (Array.isArray(value2)) {
|
|
986
|
+
return global._createSerializableArray(value2.map(cloneRecursive));
|
|
987
|
+
}
|
|
988
|
+
if (value2.__synchronizableRef) {
|
|
989
|
+
return global._createSerializableSynchronizable(value2);
|
|
990
|
+
}
|
|
991
|
+
const toAdapt = {};
|
|
992
|
+
for (const [key, element] of Object.entries(value2)) {
|
|
993
|
+
toAdapt[key] = cloneRecursive(element);
|
|
994
|
+
}
|
|
995
|
+
return global._createSerializable(toAdapt, value2);
|
|
996
|
+
}
|
|
997
|
+
if (typeof value2 === "string") {
|
|
998
|
+
return global._createSerializableString(value2);
|
|
999
|
+
}
|
|
1000
|
+
if (typeof value2 === "number") {
|
|
1001
|
+
return global._createSerializableNumber(value2);
|
|
1002
|
+
}
|
|
1003
|
+
if (typeof value2 === "boolean") {
|
|
1004
|
+
return global._createSerializableBoolean(value2);
|
|
1005
|
+
}
|
|
1006
|
+
if (typeof value2 === "bigint") {
|
|
1007
|
+
return global._createSerializableBigInt(value2);
|
|
1008
|
+
}
|
|
1009
|
+
if (value2 === void 0) {
|
|
1010
|
+
return global._createSerializableUndefined();
|
|
1011
|
+
}
|
|
1012
|
+
if (value2 === null) {
|
|
1013
|
+
return global._createSerializableNull();
|
|
1014
|
+
}
|
|
1015
|
+
return global._createSerializable(value2, void 0);
|
|
1016
|
+
}
|
|
1017
|
+
return cloneRecursive(value);
|
|
1018
|
+
}
|
|
1019
|
+
var makeShareableCloneOnUIRecursive = globalThis._WORKLETS_BUNDLE_MODE ? createSerializable : makeShareableCloneOnUIRecursiveLEGACY;
|
|
1020
|
+
|
|
1021
|
+
// ../../node_modules/react-native-worklets/lib/module/threads.js
|
|
1022
|
+
var runOnUIQueue = [];
|
|
1023
|
+
function setupMicrotasks() {
|
|
1024
|
+
"worklet";
|
|
1025
|
+
let microtasksQueue = [];
|
|
1026
|
+
let isExecutingMicrotasksQueue = false;
|
|
1027
|
+
global.queueMicrotask = (callback) => {
|
|
1028
|
+
microtasksQueue.push(callback);
|
|
1029
|
+
};
|
|
1030
|
+
global._microtaskQueueFinalizers = [];
|
|
1031
|
+
global.__callMicrotasks = () => {
|
|
1032
|
+
if (isExecutingMicrotasksQueue) {
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
try {
|
|
1036
|
+
isExecutingMicrotasksQueue = true;
|
|
1037
|
+
for (let index = 0; index < microtasksQueue.length; index += 1) {
|
|
1038
|
+
microtasksQueue[index]();
|
|
1039
|
+
}
|
|
1040
|
+
microtasksQueue = [];
|
|
1041
|
+
global._microtaskQueueFinalizers.forEach((finalizer) => finalizer());
|
|
1042
|
+
} finally {
|
|
1043
|
+
isExecutingMicrotasksQueue = false;
|
|
1044
|
+
}
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
function callMicrotasksOnUIThread() {
|
|
1048
|
+
"worklet";
|
|
1049
|
+
global.__callMicrotasks();
|
|
1050
|
+
}
|
|
1051
|
+
var callMicrotasks = SHOULD_BE_USE_WEB2 ? () => {
|
|
1052
|
+
} : callMicrotasksOnUIThread;
|
|
1053
|
+
function runOnUI(worklet) {
|
|
1054
|
+
if (__DEV__ && !SHOULD_BE_USE_WEB2 && !isWorkletFunction(worklet) && !worklet.__bundleData) {
|
|
1055
|
+
throw new WorkletsError("`runOnUI` can only be used with worklets.");
|
|
1056
|
+
}
|
|
1057
|
+
return (...args) => {
|
|
1058
|
+
if (IS_JEST2) {
|
|
1059
|
+
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
|
1060
|
+
"worklet";
|
|
1061
|
+
worklet(...args);
|
|
1062
|
+
}));
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
if (__DEV__) {
|
|
1066
|
+
createSerializable(worklet);
|
|
1067
|
+
createSerializable(args);
|
|
1068
|
+
}
|
|
1069
|
+
enqueueUI(worklet, args);
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
if (__DEV__) {
|
|
1073
|
+
let runOnUIWorklet = function() {
|
|
1074
|
+
"worklet";
|
|
1075
|
+
throw new WorkletsError("`runOnUI` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.");
|
|
1076
|
+
};
|
|
1077
|
+
const serializableRunOnUIWorklet = createSerializable(runOnUIWorklet);
|
|
1078
|
+
serializableMappingCache.set(runOnUI, serializableRunOnUIWorklet);
|
|
1079
|
+
}
|
|
1080
|
+
function executeOnUIRuntimeSync(worklet) {
|
|
1081
|
+
return (...args) => {
|
|
1082
|
+
return WorkletsModule.executeOnUIRuntimeSync(createSerializable(() => {
|
|
1083
|
+
"worklet";
|
|
1084
|
+
const result = worklet(...args);
|
|
1085
|
+
return makeShareableCloneOnUIRecursive(result);
|
|
1086
|
+
}));
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
function runWorkletOnJS(worklet, ...args) {
|
|
1090
|
+
worklet(...args);
|
|
1091
|
+
}
|
|
1092
|
+
function runOnJS(fun) {
|
|
1093
|
+
"worklet";
|
|
1094
|
+
if (SHOULD_BE_USE_WEB2 || globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
1095
|
+
return (...args) => queueMicrotask(args.length ? () => fun(...args) : fun);
|
|
1096
|
+
}
|
|
1097
|
+
if (isWorkletFunction(fun)) {
|
|
1098
|
+
return (...args) => runOnJS(runWorkletOnJS)(fun, ...args);
|
|
1099
|
+
}
|
|
1100
|
+
if (fun.__remoteFunction) {
|
|
1101
|
+
fun = fun.__remoteFunction;
|
|
1102
|
+
}
|
|
1103
|
+
const scheduleOnJS = typeof fun === "function" ? global._scheduleHostFunctionOnJS : global._scheduleRemoteFunctionOnJS;
|
|
1104
|
+
return (...args) => {
|
|
1105
|
+
scheduleOnJS(fun, args.length > 0 ? makeShareableCloneOnUIRecursive(args) : void 0);
|
|
1106
|
+
};
|
|
1107
|
+
}
|
|
1108
|
+
function runOnUIAsync(worklet) {
|
|
1109
|
+
if (__DEV__ && !SHOULD_BE_USE_WEB2 && !isWorkletFunction(worklet)) {
|
|
1110
|
+
throw new WorkletsError("`runOnUIAsync` can only be used with worklets.");
|
|
1111
|
+
}
|
|
1112
|
+
return (...args) => {
|
|
1113
|
+
return new Promise((resolve) => {
|
|
1114
|
+
if (IS_JEST2) {
|
|
1115
|
+
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
|
1116
|
+
"worklet";
|
|
1117
|
+
worklet(...args);
|
|
1118
|
+
}));
|
|
1119
|
+
return;
|
|
1120
|
+
}
|
|
1121
|
+
if (__DEV__) {
|
|
1122
|
+
createSerializable(worklet);
|
|
1123
|
+
createSerializable(args);
|
|
1124
|
+
}
|
|
1125
|
+
enqueueUI(worklet, args, resolve);
|
|
1126
|
+
});
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
if (__DEV__) {
|
|
1130
|
+
let runOnUIAsyncWorklet = function() {
|
|
1131
|
+
"worklet";
|
|
1132
|
+
throw new WorkletsError("`runOnUIAsync` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.");
|
|
1133
|
+
};
|
|
1134
|
+
const serializableRunOnUIAsyncWorklet = createSerializable(runOnUIAsyncWorklet);
|
|
1135
|
+
serializableMappingCache.set(runOnUIAsync, serializableRunOnUIAsyncWorklet);
|
|
1136
|
+
}
|
|
1137
|
+
function enqueueUI(worklet, args, resolve) {
|
|
1138
|
+
const job = [worklet, args, resolve];
|
|
1139
|
+
runOnUIQueue.push(job);
|
|
1140
|
+
if (runOnUIQueue.length === 1) {
|
|
1141
|
+
flushUIQueue();
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
function flushUIQueue() {
|
|
1145
|
+
queueMicrotask(() => {
|
|
1146
|
+
const queue = runOnUIQueue;
|
|
1147
|
+
runOnUIQueue = [];
|
|
1148
|
+
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
|
1149
|
+
"worklet";
|
|
1150
|
+
queue.forEach(([workletFunction, workletArgs, jobResolve]) => {
|
|
1151
|
+
const result = workletFunction(...workletArgs);
|
|
1152
|
+
if (jobResolve) {
|
|
1153
|
+
runOnJS(jobResolve)(result);
|
|
1154
|
+
}
|
|
1155
|
+
});
|
|
1156
|
+
callMicrotasks();
|
|
1157
|
+
}));
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/requestAnimationFrame.js
|
|
1162
|
+
function setupRequestAnimationFrame() {
|
|
1163
|
+
"worklet";
|
|
1164
|
+
const nativeRequestAnimationFrame = globalThis.requestAnimationFrame;
|
|
1165
|
+
let queuedCallbacks = [];
|
|
1166
|
+
let queuedCallbacksBegin = 0;
|
|
1167
|
+
let queuedCallbacksEnd = 0;
|
|
1168
|
+
let flushedCallbacks = queuedCallbacks;
|
|
1169
|
+
let flushedCallbacksBegin = 0;
|
|
1170
|
+
let flushedCallbacksEnd = 0;
|
|
1171
|
+
let flushRequested = false;
|
|
1172
|
+
globalThis.__flushAnimationFrame = (timestamp) => {
|
|
1173
|
+
flushedCallbacks = queuedCallbacks;
|
|
1174
|
+
queuedCallbacks = [];
|
|
1175
|
+
flushedCallbacksBegin = queuedCallbacksBegin;
|
|
1176
|
+
flushedCallbacksEnd = queuedCallbacksEnd;
|
|
1177
|
+
queuedCallbacksBegin = queuedCallbacksEnd;
|
|
1178
|
+
for (const callback of flushedCallbacks) {
|
|
1179
|
+
callback(timestamp);
|
|
1180
|
+
}
|
|
1181
|
+
flushedCallbacksBegin = flushedCallbacksEnd;
|
|
1182
|
+
callMicrotasks();
|
|
1183
|
+
};
|
|
1184
|
+
globalThis.requestAnimationFrame = (callback) => {
|
|
1185
|
+
const handle = queuedCallbacksEnd++;
|
|
1186
|
+
queuedCallbacks.push(callback);
|
|
1187
|
+
if (!flushRequested) {
|
|
1188
|
+
flushRequested = true;
|
|
1189
|
+
nativeRequestAnimationFrame((timestamp) => {
|
|
1190
|
+
flushRequested = false;
|
|
1191
|
+
globalThis.__frameTimestamp = timestamp;
|
|
1192
|
+
globalThis.__flushAnimationFrame(timestamp);
|
|
1193
|
+
globalThis.__frameTimestamp = void 0;
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
return handle;
|
|
1197
|
+
};
|
|
1198
|
+
globalThis.cancelAnimationFrame = (handle) => {
|
|
1199
|
+
if (handle < flushedCallbacksBegin || handle >= queuedCallbacksEnd) {
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1202
|
+
if (handle < flushedCallbacksEnd) {
|
|
1203
|
+
flushedCallbacks[handle - flushedCallbacksBegin] = () => {
|
|
1204
|
+
};
|
|
1205
|
+
} else {
|
|
1206
|
+
queuedCallbacks[handle - queuedCallbacksBegin] = () => {
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js
|
|
1213
|
+
function setupSetTimeout() {
|
|
1214
|
+
"worklet";
|
|
1215
|
+
const timeoutHandleToRafHandle = /* @__PURE__ */ new Map();
|
|
1216
|
+
const setTimeoutPolyfill = (callback, delay = 0, ...args) => {
|
|
1217
|
+
const start = performance.now();
|
|
1218
|
+
let timeoutHandle = 0;
|
|
1219
|
+
const rafCallback = () => {
|
|
1220
|
+
const now = performance.now();
|
|
1221
|
+
if (now - start >= delay) {
|
|
1222
|
+
callback(...args);
|
|
1223
|
+
timeoutHandleToRafHandle.delete(timeoutHandle);
|
|
1224
|
+
} else {
|
|
1225
|
+
const rafHandle = requestAnimationFrame(rafCallback);
|
|
1226
|
+
timeoutHandleToRafHandle.set(timeoutHandle, rafHandle);
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
timeoutHandle = requestAnimationFrame(rafCallback);
|
|
1230
|
+
timeoutHandleToRafHandle.set(timeoutHandle, timeoutHandle);
|
|
1231
|
+
return timeoutHandle;
|
|
1232
|
+
};
|
|
1233
|
+
const clearTimeoutPolyfill = (timeoutHandle) => {
|
|
1234
|
+
const rafHandle = timeoutHandleToRafHandle.get(timeoutHandle);
|
|
1235
|
+
timeoutHandleToRafHandle.delete(timeoutHandle);
|
|
1236
|
+
cancelAnimationFrame(rafHandle);
|
|
1237
|
+
};
|
|
1238
|
+
globalThis.setTimeout = setTimeoutPolyfill;
|
|
1239
|
+
globalThis.clearTimeout = clearTimeoutPolyfill;
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
// ../../node_modules/react-native-worklets/lib/module/synchronizableUnpacker.js
|
|
1243
|
+
function __installUnpacker() {
|
|
1244
|
+
const serializer = !globalThis._WORKLET || globalThis._WORKLETS_BUNDLE_MODE ? (value, _) => createSerializable(value) : globalThis._createSerializable;
|
|
1245
|
+
function synchronizableUnpacker(synchronizableRef) {
|
|
1246
|
+
const synchronizable = synchronizableRef;
|
|
1247
|
+
const proxy = globalThis.__workletsModuleProxy;
|
|
1248
|
+
synchronizable.__synchronizableRef = true;
|
|
1249
|
+
synchronizable.getDirty = () => {
|
|
1250
|
+
return proxy.synchronizableGetDirty(synchronizable);
|
|
1251
|
+
};
|
|
1252
|
+
synchronizable.getBlocking = () => {
|
|
1253
|
+
return proxy.synchronizableGetBlocking(synchronizable);
|
|
1254
|
+
};
|
|
1255
|
+
synchronizable.setBlocking = (valueOrFunction) => {
|
|
1256
|
+
let newValue;
|
|
1257
|
+
if (typeof valueOrFunction === "function") {
|
|
1258
|
+
const func = valueOrFunction;
|
|
1259
|
+
synchronizable.lock();
|
|
1260
|
+
const prev = synchronizable.getBlocking();
|
|
1261
|
+
newValue = func(prev);
|
|
1262
|
+
proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, void 0));
|
|
1263
|
+
synchronizable.unlock();
|
|
1264
|
+
} else {
|
|
1265
|
+
const value = valueOrFunction;
|
|
1266
|
+
newValue = value;
|
|
1267
|
+
proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, void 0));
|
|
1268
|
+
}
|
|
1269
|
+
};
|
|
1270
|
+
synchronizable.lock = () => {
|
|
1271
|
+
proxy.synchronizableLock(synchronizable);
|
|
1272
|
+
};
|
|
1273
|
+
synchronizable.unlock = () => {
|
|
1274
|
+
proxy.synchronizableUnlock(synchronizable);
|
|
1275
|
+
};
|
|
1276
|
+
return synchronizable;
|
|
1277
|
+
}
|
|
1278
|
+
globalThis.__synchronizableUnpacker = synchronizableUnpacker;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
// ../../node_modules/react-native-worklets/lib/module/initializers.js
|
|
1282
|
+
var capturableConsole;
|
|
1283
|
+
function getMemorySafeCapturableConsole() {
|
|
1284
|
+
if (capturableConsole) {
|
|
1285
|
+
return capturableConsole;
|
|
1286
|
+
}
|
|
1287
|
+
const consoleCopy = Object.fromEntries(Object.entries(console).map(([methodName, method]) => {
|
|
1288
|
+
const methodWrapper = function methodWrapper2(...args) {
|
|
1289
|
+
return method(...args);
|
|
1290
|
+
};
|
|
1291
|
+
if (method.name) {
|
|
1292
|
+
Object.defineProperty(methodWrapper, "name", {
|
|
1293
|
+
value: method.name,
|
|
1294
|
+
writable: false
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
return [methodName, methodWrapper];
|
|
1298
|
+
}));
|
|
1299
|
+
capturableConsole = consoleCopy;
|
|
1300
|
+
return consoleCopy;
|
|
33
1301
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
1302
|
+
function setupConsole(boundCapturableConsole) {
|
|
1303
|
+
"worklet";
|
|
1304
|
+
globalThis.console = {
|
|
1305
|
+
assert: runOnJS(boundCapturableConsole.assert),
|
|
1306
|
+
debug: runOnJS(boundCapturableConsole.debug),
|
|
1307
|
+
log: runOnJS(boundCapturableConsole.log),
|
|
1308
|
+
warn: runOnJS(boundCapturableConsole.warn),
|
|
1309
|
+
error: runOnJS(boundCapturableConsole.error),
|
|
1310
|
+
info: runOnJS(boundCapturableConsole.info)
|
|
1311
|
+
};
|
|
43
1312
|
}
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1313
|
+
var initialized = false;
|
|
1314
|
+
function init() {
|
|
1315
|
+
if (initialized) {
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
initialized = true;
|
|
1319
|
+
if (globalThis.__RUNTIME_KIND === void 0) {
|
|
1320
|
+
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
|
|
1321
|
+
}
|
|
1322
|
+
initializeRuntime();
|
|
1323
|
+
if (SHOULD_BE_USE_WEB2) {
|
|
1324
|
+
initializeRuntimeOnWeb();
|
|
1325
|
+
}
|
|
1326
|
+
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
|
|
1327
|
+
initializeWorkletRuntime();
|
|
1328
|
+
} else {
|
|
1329
|
+
initializeRNRuntime();
|
|
1330
|
+
if (!SHOULD_BE_USE_WEB2) {
|
|
1331
|
+
installRNBindingsOnUIRuntime();
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
48
1334
|
}
|
|
49
|
-
function
|
|
50
|
-
|
|
1335
|
+
function initializeRuntime() {
|
|
1336
|
+
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
1337
|
+
globalThis.__valueUnpacker = bundleValueUnpacker;
|
|
1338
|
+
}
|
|
1339
|
+
__installUnpacker();
|
|
51
1340
|
}
|
|
52
|
-
function
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
1341
|
+
function initializeRNRuntime() {
|
|
1342
|
+
if (__DEV__) {
|
|
1343
|
+
const testWorklet = () => {
|
|
1344
|
+
"worklet";
|
|
1345
|
+
};
|
|
1346
|
+
if (!isWorkletFunction(testWorklet)) {
|
|
1347
|
+
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.`);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
registerReportFatalRemoteError();
|
|
61
1351
|
}
|
|
62
|
-
function
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
1352
|
+
function initializeWorkletRuntime() {
|
|
1353
|
+
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
1354
|
+
setupCallGuard();
|
|
1355
|
+
if (__DEV__) {
|
|
1356
|
+
const Refresh = new Proxy({}, {
|
|
1357
|
+
get() {
|
|
1358
|
+
return () => {
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
});
|
|
1362
|
+
globalThis.__r.Refresh = Refresh;
|
|
1363
|
+
const modules = __require.getModules();
|
|
1364
|
+
const ReactNativeModuleId = __require.resolveWeak("react-native");
|
|
1365
|
+
const factory = function(_global, _require, _importDefault, _importAll, module, _exports, _dependencyMap) {
|
|
1366
|
+
module.exports = new Proxy({}, {
|
|
1367
|
+
get: function get(_target, prop) {
|
|
1368
|
+
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.`);
|
|
1369
|
+
return {
|
|
1370
|
+
get() {
|
|
1371
|
+
return void 0;
|
|
1372
|
+
}
|
|
1373
|
+
};
|
|
1374
|
+
}
|
|
1375
|
+
});
|
|
1376
|
+
};
|
|
1377
|
+
const mod = {
|
|
1378
|
+
dependencyMap: [],
|
|
1379
|
+
factory,
|
|
1380
|
+
hasError: false,
|
|
1381
|
+
importedAll: {},
|
|
1382
|
+
importedDefault: {},
|
|
1383
|
+
isInitialized: false,
|
|
1384
|
+
publicModule: {
|
|
1385
|
+
exports: {}
|
|
1386
|
+
}
|
|
1387
|
+
};
|
|
1388
|
+
modules.set(ReactNativeModuleId, mod);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
function initializeRuntimeOnWeb() {
|
|
1393
|
+
globalThis._WORKLET = false;
|
|
1394
|
+
globalThis._log = console.log;
|
|
1395
|
+
globalThis._getAnimationTimestamp = () => performance.now();
|
|
1396
|
+
if (IS_JEST2) {
|
|
1397
|
+
globalThis.requestAnimationFrame = mockedRequestAnimationFrame;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
function installRNBindingsOnUIRuntime() {
|
|
1401
|
+
if (!WorkletsModule) {
|
|
1402
|
+
throw new WorkletsError("Worklets are trying to initialize the UI runtime without a valid WorkletsModule");
|
|
1403
|
+
}
|
|
1404
|
+
const runtimeBoundCapturableConsole = getMemorySafeCapturableConsole();
|
|
1405
|
+
if (!globalThis._WORKLETS_BUNDLE_MODE) {
|
|
1406
|
+
executeOnUIRuntimeSync(setupCallGuard)();
|
|
1407
|
+
executeOnUIRuntimeSync(registerWorkletsError)();
|
|
1408
|
+
}
|
|
1409
|
+
executeOnUIRuntimeSync(() => {
|
|
1410
|
+
"worklet";
|
|
1411
|
+
setupConsole(runtimeBoundCapturableConsole);
|
|
1412
|
+
setupMicrotasks();
|
|
1413
|
+
setupRequestAnimationFrame();
|
|
1414
|
+
setupSetTimeout();
|
|
1415
|
+
setupSetImmediate();
|
|
1416
|
+
setupSetInterval();
|
|
1417
|
+
})();
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
// ../../node_modules/react-native-worklets/lib/module/workletRuntimeEntry.js
|
|
1421
|
+
function bundleModeInit() {
|
|
1422
|
+
if (SHOULD_BE_USE_WEB2) {
|
|
1423
|
+
return;
|
|
1424
|
+
}
|
|
1425
|
+
globalThis._WORKLETS_BUNDLE_MODE = true;
|
|
1426
|
+
const runtimeKind = globalThis.__RUNTIME_KIND;
|
|
1427
|
+
if (runtimeKind && runtimeKind !== RuntimeKind.ReactNative) {
|
|
1428
|
+
init();
|
|
1429
|
+
throw new WorkletsError("Worklets initialized successfully");
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
bundleModeInit();
|
|
1433
|
+
|
|
1434
|
+
// ../../node_modules/react-native-worklets/lib/module/featureFlags/index.js
|
|
1435
|
+
var DynamicFlags = {
|
|
1436
|
+
EXAMPLE_DYNAMIC_FLAG: true,
|
|
1437
|
+
init() {
|
|
1438
|
+
Object.keys(DynamicFlags).forEach((key) => {
|
|
1439
|
+
if (key !== "init" && key !== "setFlag") {
|
|
1440
|
+
WorkletsModule.setDynamicFeatureFlag(key, DynamicFlags[key]);
|
|
1441
|
+
}
|
|
1442
|
+
});
|
|
1443
|
+
},
|
|
1444
|
+
setFlag(name, value) {
|
|
1445
|
+
if (name in DynamicFlags) {
|
|
1446
|
+
DynamicFlags[name] = value;
|
|
1447
|
+
WorkletsModule.setDynamicFeatureFlag(name, value);
|
|
1448
|
+
} else {
|
|
1449
|
+
logger.warn(`The feature flag: '${name}' no longer exists, you can safely remove invocation of \`setDynamicFeatureFlag('${name}')\` from your code.`);
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
DynamicFlags.init();
|
|
1454
|
+
|
|
1455
|
+
// ../../node_modules/react-native-worklets/lib/module/index.js
|
|
1456
|
+
init();
|
|
1457
|
+
if (globalThis._ALWAYS_FALSE) {
|
|
1458
|
+
bundleModeInit();
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
// src/transitions/easing.ts
|
|
1462
|
+
function ensureWorkletEasing(easing) {
|
|
1463
|
+
if (!easing) return void 0;
|
|
1464
|
+
if (isWorkletFunction(easing)) return easing;
|
|
1465
|
+
const wrapped = (t) => {
|
|
1466
|
+
"worklet";
|
|
1467
|
+
return easing(t);
|
|
1468
|
+
};
|
|
1469
|
+
return wrapped;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
// src/transitions/spring.ts
|
|
1473
|
+
var DEFAULT_SPRING = {
|
|
1474
|
+
tension: 170,
|
|
1475
|
+
friction: 26,
|
|
1476
|
+
mass: 1
|
|
1477
|
+
};
|
|
1478
|
+
function springToReanimated(t) {
|
|
1479
|
+
return {
|
|
1480
|
+
stiffness: t.tension ?? DEFAULT_SPRING.tension,
|
|
1481
|
+
damping: t.friction ?? DEFAULT_SPRING.friction,
|
|
1482
|
+
mass: t.mass ?? DEFAULT_SPRING.mass,
|
|
1483
|
+
velocity: t.velocity,
|
|
1484
|
+
restSpeedThreshold: t.restSpeedThreshold,
|
|
1485
|
+
restDisplacementThreshold: t.restDisplacementThreshold
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
// src/layout/resolveLayout.ts
|
|
1490
|
+
function resolveLayoutTransition(layout) {
|
|
1491
|
+
if (!layout) return void 0;
|
|
1492
|
+
const cfg = layout === true ? { type: "spring" } : layout;
|
|
1493
|
+
if (cfg.type === "no-animation") return void 0;
|
|
1494
|
+
if (cfg.type === "timing") {
|
|
1495
|
+
let builder2 = Animated.LinearTransition.duration(cfg.duration ?? 300);
|
|
1496
|
+
const easing = ensureWorkletEasing(cfg.easing);
|
|
1497
|
+
if (easing) builder2 = builder2.easing(easing);
|
|
1498
|
+
if (cfg.delay) builder2 = builder2.delay(cfg.delay);
|
|
1499
|
+
return builder2;
|
|
1500
|
+
}
|
|
1501
|
+
const spring = cfg.type === "decay" ? { type: "spring" } : cfg;
|
|
1502
|
+
const { stiffness, damping, mass } = springToReanimated({
|
|
1503
|
+
...DEFAULT_SPRING,
|
|
1504
|
+
...spring
|
|
1505
|
+
});
|
|
1506
|
+
let builder = Animated.LinearTransition.springify().stiffness(stiffness).damping(damping).mass(mass);
|
|
1507
|
+
if ("delay" in spring && spring.delay) builder = builder.delay(spring.delay);
|
|
1508
|
+
return builder;
|
|
66
1509
|
}
|
|
67
1510
|
var PresenceContext = react.createContext(null);
|
|
68
1511
|
function usePresence() {
|
|
@@ -159,33 +1602,7 @@ function PresenceItem({
|
|
|
159
1602
|
);
|
|
160
1603
|
return /* @__PURE__ */ jsxRuntime.jsx(PresenceContext.Provider, { value, children });
|
|
161
1604
|
}
|
|
162
|
-
function ensureWorkletEasing(easing) {
|
|
163
|
-
if (!easing) return void 0;
|
|
164
|
-
if (Animated.isWorkletFunction(easing)) return easing;
|
|
165
|
-
const wrapped = (t) => {
|
|
166
|
-
"worklet";
|
|
167
|
-
return easing(t);
|
|
168
|
-
};
|
|
169
|
-
return wrapped;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// src/transitions/resolve.ts
|
|
173
|
-
var DEFAULT_SPRING = {
|
|
174
|
-
tension: 170,
|
|
175
|
-
friction: 26,
|
|
176
|
-
mass: 1
|
|
177
|
-
};
|
|
178
1605
|
var DEFAULT_TIMING_DURATION = 250;
|
|
179
|
-
function springToReanimated(t) {
|
|
180
|
-
return {
|
|
181
|
-
stiffness: t.tension ?? DEFAULT_SPRING.tension,
|
|
182
|
-
damping: t.friction ?? DEFAULT_SPRING.friction,
|
|
183
|
-
mass: t.mass ?? DEFAULT_SPRING.mass,
|
|
184
|
-
velocity: t.velocity,
|
|
185
|
-
restSpeedThreshold: t.restSpeedThreshold,
|
|
186
|
-
restDisplacementThreshold: t.restDisplacementThreshold
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
1606
|
function buildSpring(cfg, toValue, cb) {
|
|
190
1607
|
return Animated.withSpring(toValue, springToReanimated(cfg), cb);
|
|
191
1608
|
}
|
|
@@ -291,6 +1708,51 @@ function mergeTransition(base, override) {
|
|
|
291
1708
|
return { ...base ?? { type: "spring" }, ...override };
|
|
292
1709
|
}
|
|
293
1710
|
|
|
1711
|
+
// src/transitions/keys.ts
|
|
1712
|
+
var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
1713
|
+
"type",
|
|
1714
|
+
"tension",
|
|
1715
|
+
"friction",
|
|
1716
|
+
"mass",
|
|
1717
|
+
"velocity",
|
|
1718
|
+
"restSpeedThreshold",
|
|
1719
|
+
"restDisplacementThreshold",
|
|
1720
|
+
"duration",
|
|
1721
|
+
"easing",
|
|
1722
|
+
"delay",
|
|
1723
|
+
"repeat",
|
|
1724
|
+
"deceleration",
|
|
1725
|
+
"clamp"
|
|
1726
|
+
]);
|
|
1727
|
+
function isTopLevelTransition(t) {
|
|
1728
|
+
if (t === null || typeof t !== "object") return false;
|
|
1729
|
+
const keys = Object.keys(t);
|
|
1730
|
+
if (keys.length === 0) return false;
|
|
1731
|
+
return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
// src/transitions/sig.ts
|
|
1735
|
+
function stableSig(value) {
|
|
1736
|
+
if (value === void 0) return "";
|
|
1737
|
+
try {
|
|
1738
|
+
return stableStringify(value);
|
|
1739
|
+
} catch {
|
|
1740
|
+
return String(value);
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
function stableStringify(v) {
|
|
1744
|
+
if (v === null || typeof v !== "object") {
|
|
1745
|
+
if (typeof v === "function" || v === void 0) return "null";
|
|
1746
|
+
return JSON.stringify(v);
|
|
1747
|
+
}
|
|
1748
|
+
if (Array.isArray(v)) {
|
|
1749
|
+
return "[" + v.map(stableStringify).join(",") + "]";
|
|
1750
|
+
}
|
|
1751
|
+
const obj = v;
|
|
1752
|
+
const keys = Object.keys(obj).sort();
|
|
1753
|
+
return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
|
|
1754
|
+
}
|
|
1755
|
+
|
|
294
1756
|
// src/motion/installCheck.ts
|
|
295
1757
|
var alreadyChecked = false;
|
|
296
1758
|
function ensureReanimatedInstalled() {
|
|
@@ -330,8 +1792,11 @@ var TRANSFORM_KEYS = [
|
|
|
330
1792
|
"scale",
|
|
331
1793
|
"scaleX",
|
|
332
1794
|
"scaleY",
|
|
333
|
-
"rotate"
|
|
1795
|
+
"rotate",
|
|
1796
|
+
"rotateX",
|
|
1797
|
+
"rotateY"
|
|
334
1798
|
];
|
|
1799
|
+
var ROTATION_KEYS = /* @__PURE__ */ new Set(["rotate", "rotateX", "rotateY"]);
|
|
335
1800
|
var NUMERIC_TOP_LEVEL_KEYS = [
|
|
336
1801
|
"opacity",
|
|
337
1802
|
"width",
|
|
@@ -366,6 +1831,8 @@ var DEFAULT_RESTING = {
|
|
|
366
1831
|
scaleX: 1,
|
|
367
1832
|
scaleY: 1,
|
|
368
1833
|
rotate: 0,
|
|
1834
|
+
rotateX: 0,
|
|
1835
|
+
rotateY: 0,
|
|
369
1836
|
opacity: 1,
|
|
370
1837
|
width: 0,
|
|
371
1838
|
height: 0,
|
|
@@ -379,27 +1846,6 @@ var DEFAULT_RESTING = {
|
|
|
379
1846
|
color: "transparent",
|
|
380
1847
|
tintColor: "transparent"
|
|
381
1848
|
};
|
|
382
|
-
var TRANSITION_KEYS = /* @__PURE__ */ new Set([
|
|
383
|
-
"type",
|
|
384
|
-
"tension",
|
|
385
|
-
"friction",
|
|
386
|
-
"mass",
|
|
387
|
-
"velocity",
|
|
388
|
-
"restSpeedThreshold",
|
|
389
|
-
"restDisplacementThreshold",
|
|
390
|
-
"duration",
|
|
391
|
-
"easing",
|
|
392
|
-
"delay",
|
|
393
|
-
"repeat",
|
|
394
|
-
"deceleration",
|
|
395
|
-
"clamp"
|
|
396
|
-
]);
|
|
397
|
-
function isTopLevelTransition(t) {
|
|
398
|
-
if (t === null || typeof t !== "object") return false;
|
|
399
|
-
const keys = Object.keys(t);
|
|
400
|
-
if (keys.length === 0) return false;
|
|
401
|
-
return keys.every((k) => TRANSITION_KEYS.has(k));
|
|
402
|
-
}
|
|
403
1849
|
function transitionFor(prop, transition) {
|
|
404
1850
|
if (!transition) return void 0;
|
|
405
1851
|
if (isTopLevelTransition(transition)) return transition;
|
|
@@ -426,6 +1872,7 @@ function createMotionComponent(Component) {
|
|
|
426
1872
|
variants,
|
|
427
1873
|
controller,
|
|
428
1874
|
gesture,
|
|
1875
|
+
layout,
|
|
429
1876
|
onAnimationEnd,
|
|
430
1877
|
style,
|
|
431
1878
|
...rest
|
|
@@ -629,7 +2076,7 @@ function createMotionComponent(Component) {
|
|
|
629
2076
|
}
|
|
630
2077
|
if (TRANSFORM_KEY_SET.has(key)) {
|
|
631
2078
|
transform.push(
|
|
632
|
-
key
|
|
2079
|
+
ROTATION_KEYS.has(key) ? { [key]: `${v}deg` } : { [key]: v }
|
|
633
2080
|
);
|
|
634
2081
|
} else {
|
|
635
2082
|
out[key] = v;
|
|
@@ -650,12 +2097,19 @@ function createMotionComponent(Component) {
|
|
|
650
2097
|
setFocusVisible,
|
|
651
2098
|
setHovered
|
|
652
2099
|
);
|
|
2100
|
+
const layoutSig = stableSig(layout);
|
|
2101
|
+
const layoutTransition = react.useMemo(
|
|
2102
|
+
() => shouldReduceMotion ? void 0 : resolveLayoutTransition(layout),
|
|
2103
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2104
|
+
[layoutSig, shouldReduceMotion]
|
|
2105
|
+
);
|
|
653
2106
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
654
2107
|
AnimatedComponent,
|
|
655
2108
|
{
|
|
656
2109
|
ref,
|
|
657
2110
|
...rest,
|
|
658
2111
|
...gestureHandlers,
|
|
2112
|
+
layout: layoutTransition,
|
|
659
2113
|
style: mergedStyle
|
|
660
2114
|
}
|
|
661
2115
|
);
|
|
@@ -663,23 +2117,25 @@ function createMotionComponent(Component) {
|
|
|
663
2117
|
Motion2.displayName = `Motion(${Component.displayName ?? Component.name ?? "Component"})`;
|
|
664
2118
|
return Motion2;
|
|
665
2119
|
}
|
|
666
|
-
function useAnimatableSharedValues(
|
|
667
|
-
const translateX = Animated.useSharedValue(
|
|
668
|
-
const translateY = Animated.useSharedValue(
|
|
669
|
-
const scale = Animated.useSharedValue(
|
|
670
|
-
const scaleX = Animated.useSharedValue(
|
|
671
|
-
const scaleY = Animated.useSharedValue(
|
|
672
|
-
const rotate = Animated.useSharedValue(
|
|
673
|
-
const
|
|
674
|
-
const
|
|
675
|
-
const
|
|
676
|
-
const
|
|
2120
|
+
function useAnimatableSharedValues(init2) {
|
|
2121
|
+
const translateX = Animated.useSharedValue(init2("translateX"));
|
|
2122
|
+
const translateY = Animated.useSharedValue(init2("translateY"));
|
|
2123
|
+
const scale = Animated.useSharedValue(init2("scale"));
|
|
2124
|
+
const scaleX = Animated.useSharedValue(init2("scaleX"));
|
|
2125
|
+
const scaleY = Animated.useSharedValue(init2("scaleY"));
|
|
2126
|
+
const rotate = Animated.useSharedValue(init2("rotate"));
|
|
2127
|
+
const rotateX = Animated.useSharedValue(init2("rotateX"));
|
|
2128
|
+
const rotateY = Animated.useSharedValue(init2("rotateY"));
|
|
2129
|
+
const opacity = Animated.useSharedValue(init2("opacity"));
|
|
2130
|
+
const width = Animated.useSharedValue(init2("width"));
|
|
2131
|
+
const height = Animated.useSharedValue(init2("height"));
|
|
2132
|
+
const borderRadius = Animated.useSharedValue(init2("borderRadius"));
|
|
677
2133
|
const backgroundColor = Animated.useSharedValue(
|
|
678
|
-
|
|
2134
|
+
init2("backgroundColor")
|
|
679
2135
|
);
|
|
680
|
-
const borderColor = Animated.useSharedValue(
|
|
681
|
-
const color = Animated.useSharedValue(
|
|
682
|
-
const tintColor = Animated.useSharedValue(
|
|
2136
|
+
const borderColor = Animated.useSharedValue(init2("borderColor"));
|
|
2137
|
+
const color = Animated.useSharedValue(init2("color"));
|
|
2138
|
+
const tintColor = Animated.useSharedValue(init2("tintColor"));
|
|
683
2139
|
const ref = react.useRef(null);
|
|
684
2140
|
if (ref.current === null) {
|
|
685
2141
|
ref.current = {
|
|
@@ -689,6 +2145,8 @@ function useAnimatableSharedValues(init) {
|
|
|
689
2145
|
scaleX,
|
|
690
2146
|
scaleY,
|
|
691
2147
|
rotate,
|
|
2148
|
+
rotateX,
|
|
2149
|
+
rotateY,
|
|
692
2150
|
opacity,
|
|
693
2151
|
width,
|
|
694
2152
|
height,
|
|
@@ -825,26 +2283,6 @@ function restValue(v) {
|
|
|
825
2283
|
}
|
|
826
2284
|
return void 0;
|
|
827
2285
|
}
|
|
828
|
-
function stableSig(value) {
|
|
829
|
-
if (value === void 0) return "";
|
|
830
|
-
try {
|
|
831
|
-
return stableStringify(value);
|
|
832
|
-
} catch {
|
|
833
|
-
return String(value);
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
function stableStringify(v) {
|
|
837
|
-
if (v === null || typeof v !== "object") {
|
|
838
|
-
if (typeof v === "function" || v === void 0) return "null";
|
|
839
|
-
return JSON.stringify(v);
|
|
840
|
-
}
|
|
841
|
-
if (Array.isArray(v)) {
|
|
842
|
-
return "[" + v.map(stableStringify).join(",") + "]";
|
|
843
|
-
}
|
|
844
|
-
const obj = v;
|
|
845
|
-
const keys = Object.keys(obj).sort();
|
|
846
|
-
return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
|
|
847
|
-
}
|
|
848
2286
|
function resolveGestureLayers(gesture) {
|
|
849
2287
|
if (!gesture) return null;
|
|
850
2288
|
const out = {};
|
|
@@ -950,6 +2388,155 @@ var Motion = {
|
|
|
950
2388
|
Pressable: MotionPressable,
|
|
951
2389
|
ScrollView: MotionScrollView
|
|
952
2390
|
};
|
|
2391
|
+
function useAnimation(target, transition) {
|
|
2392
|
+
const output = Animated.useSharedValue(target);
|
|
2393
|
+
const shouldReduceMotion = useShouldReduceMotion();
|
|
2394
|
+
const cfgSig = stableSig(transition);
|
|
2395
|
+
react.useEffect(() => {
|
|
2396
|
+
const cfg = shouldReduceMotion ? { type: "no-animation" } : transition ?? { type: "spring" };
|
|
2397
|
+
output.value = resolveTransition(cfg, target);
|
|
2398
|
+
}, [target, cfgSig, shouldReduceMotion]);
|
|
2399
|
+
return output;
|
|
2400
|
+
}
|
|
2401
|
+
function useGesture(transition) {
|
|
2402
|
+
const pressed = Animated.useSharedValue(0);
|
|
2403
|
+
const focused = Animated.useSharedValue(0);
|
|
2404
|
+
const focusVisible = Animated.useSharedValue(0);
|
|
2405
|
+
const hovered = Animated.useSharedValue(0);
|
|
2406
|
+
const shouldReduceMotion = useShouldReduceMotion();
|
|
2407
|
+
const setLayer = react.useCallback(
|
|
2408
|
+
(sv, layer, target) => {
|
|
2409
|
+
const cfg = shouldReduceMotion ? { type: "no-animation" } : layerTransition(layer, transition) ?? { type: "spring" };
|
|
2410
|
+
sv.value = resolveTransition(cfg, target);
|
|
2411
|
+
},
|
|
2412
|
+
// The transition is intentionally read on every call rather than cooked
|
|
2413
|
+
// into the dep array — a fresh literal each render would otherwise
|
|
2414
|
+
// rebuild the handler bag and break composing consumers that key off
|
|
2415
|
+
// handler identity. `transition` is read inside the callback closure;
|
|
2416
|
+
// shared values are stable so the only dep that matters is the reduce-
|
|
2417
|
+
// motion flag.
|
|
2418
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2419
|
+
[shouldReduceMotion]
|
|
2420
|
+
);
|
|
2421
|
+
const handlers = react.useMemo(
|
|
2422
|
+
() => ({
|
|
2423
|
+
onPressIn: () => setLayer(pressed, "pressed", 1),
|
|
2424
|
+
onPressOut: () => setLayer(pressed, "pressed", 0),
|
|
2425
|
+
onHoverIn: () => setLayer(hovered, "hovered", 1),
|
|
2426
|
+
onHoverOut: () => setLayer(hovered, "hovered", 0),
|
|
2427
|
+
onFocus: () => {
|
|
2428
|
+
setLayer(focused, "focused", 1);
|
|
2429
|
+
if (isFocusVisible()) setLayer(focusVisible, "focusVisible", 1);
|
|
2430
|
+
},
|
|
2431
|
+
onBlur: () => {
|
|
2432
|
+
setLayer(focused, "focused", 0);
|
|
2433
|
+
setLayer(focusVisible, "focusVisible", 0);
|
|
2434
|
+
}
|
|
2435
|
+
}),
|
|
2436
|
+
[setLayer, pressed, focused, focusVisible, hovered]
|
|
2437
|
+
);
|
|
2438
|
+
return { pressed, focused, focusVisible, hovered, handlers };
|
|
2439
|
+
}
|
|
2440
|
+
function layerTransition(layer, transition) {
|
|
2441
|
+
if (!transition) return void 0;
|
|
2442
|
+
if (isTopLevelTransition(transition)) return transition;
|
|
2443
|
+
return transition[layer];
|
|
2444
|
+
}
|
|
2445
|
+
function useMotionValue(initial) {
|
|
2446
|
+
return Animated.useSharedValue(initial);
|
|
2447
|
+
}
|
|
2448
|
+
function useSpring(target, config) {
|
|
2449
|
+
const reanimConfig = react.useMemo(
|
|
2450
|
+
() => springToReanimated(config ?? {}),
|
|
2451
|
+
[
|
|
2452
|
+
config?.tension,
|
|
2453
|
+
config?.friction,
|
|
2454
|
+
config?.mass,
|
|
2455
|
+
config?.velocity,
|
|
2456
|
+
config?.restSpeedThreshold,
|
|
2457
|
+
config?.restDisplacementThreshold
|
|
2458
|
+
]
|
|
2459
|
+
);
|
|
2460
|
+
const isSharedTarget = isSharedValue(target);
|
|
2461
|
+
const initial = isSharedTarget ? target.value : target;
|
|
2462
|
+
const output = Animated.useSharedValue(initial);
|
|
2463
|
+
react.useEffect(() => {
|
|
2464
|
+
if (isSharedTarget) return;
|
|
2465
|
+
output.value = Animated.withSpring(target, reanimConfig);
|
|
2466
|
+
}, [isSharedTarget, target, reanimConfig]);
|
|
2467
|
+
Animated.useAnimatedReaction(
|
|
2468
|
+
() => {
|
|
2469
|
+
"worklet";
|
|
2470
|
+
if (!isSharedTarget) return null;
|
|
2471
|
+
return target.value;
|
|
2472
|
+
},
|
|
2473
|
+
(next, prev) => {
|
|
2474
|
+
"worklet";
|
|
2475
|
+
if (next === null || next === prev) return;
|
|
2476
|
+
output.value = Animated.withSpring(next, reanimConfig);
|
|
2477
|
+
},
|
|
2478
|
+
[isSharedTarget, reanimConfig]
|
|
2479
|
+
);
|
|
2480
|
+
return output;
|
|
2481
|
+
}
|
|
2482
|
+
function isSharedValue(v) {
|
|
2483
|
+
return typeof v === "object" && v !== null && "value" in v;
|
|
2484
|
+
}
|
|
2485
|
+
function useTransform(arg1, inputRange, outputRange, options) {
|
|
2486
|
+
let producer;
|
|
2487
|
+
if (typeof arg1 === "function") {
|
|
2488
|
+
const userFn = arg1;
|
|
2489
|
+
producer = isWorkletFunction(userFn) ? userFn : () => {
|
|
2490
|
+
"worklet";
|
|
2491
|
+
return userFn();
|
|
2492
|
+
};
|
|
2493
|
+
} else {
|
|
2494
|
+
const source = arg1;
|
|
2495
|
+
const input = inputRange;
|
|
2496
|
+
const output = outputRange;
|
|
2497
|
+
const isColor = output.length > 0 && typeof output[0] === "string";
|
|
2498
|
+
const extrapolateLeft = mapExtrapolation(options?.extrapolateLeft);
|
|
2499
|
+
const extrapolateRight = mapExtrapolation(options?.extrapolateRight);
|
|
2500
|
+
producer = isColor ? () => {
|
|
2501
|
+
"worklet";
|
|
2502
|
+
return Animated.interpolateColor(
|
|
2503
|
+
source.value,
|
|
2504
|
+
input,
|
|
2505
|
+
output
|
|
2506
|
+
);
|
|
2507
|
+
} : () => {
|
|
2508
|
+
"worklet";
|
|
2509
|
+
return Animated.interpolate(
|
|
2510
|
+
source.value,
|
|
2511
|
+
input,
|
|
2512
|
+
output,
|
|
2513
|
+
{ extrapolateLeft, extrapolateRight }
|
|
2514
|
+
);
|
|
2515
|
+
};
|
|
2516
|
+
}
|
|
2517
|
+
return Animated.useDerivedValue(producer);
|
|
2518
|
+
}
|
|
2519
|
+
function mapExtrapolation(mode) {
|
|
2520
|
+
if (mode === "identity") return Animated.Extrapolation.IDENTITY;
|
|
2521
|
+
if (mode === "extend") return Animated.Extrapolation.EXTEND;
|
|
2522
|
+
return Animated.Extrapolation.CLAMP;
|
|
2523
|
+
}
|
|
2524
|
+
function useScroll() {
|
|
2525
|
+
const scrollX = Animated.useSharedValue(0);
|
|
2526
|
+
const scrollY = Animated.useSharedValue(0);
|
|
2527
|
+
const handler = Animated.useAnimatedScrollHandler({
|
|
2528
|
+
onScroll: (event) => {
|
|
2529
|
+
"worklet";
|
|
2530
|
+
scrollX.value = event.contentOffset.x;
|
|
2531
|
+
scrollY.value = event.contentOffset.y;
|
|
2532
|
+
}
|
|
2533
|
+
});
|
|
2534
|
+
return {
|
|
2535
|
+
scrollX,
|
|
2536
|
+
scrollY,
|
|
2537
|
+
onScroll: handler
|
|
2538
|
+
};
|
|
2539
|
+
}
|
|
953
2540
|
function useVariants(variants, initial) {
|
|
954
2541
|
const variantsRef = react.useRef(variants);
|
|
955
2542
|
return react.useMemo(() => {
|
|
@@ -995,9 +2582,15 @@ exports.createMotionComponent = createMotionComponent;
|
|
|
995
2582
|
exports.ensureWorkletEasing = ensureWorkletEasing;
|
|
996
2583
|
exports.resolveAnimatableValue = resolveAnimatableValue;
|
|
997
2584
|
exports.resolveTransition = resolveTransition;
|
|
2585
|
+
exports.useAnimation = useAnimation;
|
|
2586
|
+
exports.useGesture = useGesture;
|
|
998
2587
|
exports.useMotionConfig = useMotionConfig;
|
|
2588
|
+
exports.useMotionValue = useMotionValue;
|
|
999
2589
|
exports.usePresence = usePresence;
|
|
2590
|
+
exports.useScroll = useScroll;
|
|
1000
2591
|
exports.useShouldReduceMotion = useShouldReduceMotion;
|
|
2592
|
+
exports.useSpring = useSpring;
|
|
2593
|
+
exports.useTransform = useTransform;
|
|
1001
2594
|
exports.useVariants = useVariants;
|
|
1002
2595
|
//# sourceMappingURL=index.js.map
|
|
1003
2596
|
//# sourceMappingURL=index.js.map
|