@onlynative/inertia 0.0.1-alpha.2 → 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 +44 -3
- package/dist/index.d.mts +259 -3
- package/dist/index.d.ts +259 -3
- package/dist/index.js +1866 -161
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1864 -165
- 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 +1696 -146
- package/dist/motion/Image.js.map +1 -1
- package/dist/motion/Image.mjs +1698 -148
- 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 +1696 -146
- package/dist/motion/Pressable.js.map +1 -1
- package/dist/motion/Pressable.mjs +1698 -148
- 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 +1696 -146
- package/dist/motion/ScrollView.js.map +1 -1
- package/dist/motion/ScrollView.mjs +1698 -148
- 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 +1696 -146
- package/dist/motion/Text.js.map +1 -1
- package/dist/motion/Text.mjs +1698 -148
- 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 +1696 -146
- package/dist/motion/View.js.map +1 -1
- package/dist/motion/View.mjs +1698 -148
- package/dist/motion/View.mjs.map +1 -1
- package/dist/{types-DeZZzE_e.d.mts → types-CjztO3RW.d.mts} +89 -20
- package/dist/{types-DeZZzE_e.d.ts → types-CjztO3RW.d.ts} +89 -20
- package/llms.txt +54 -6
- 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 +292 -153
- package/src/motion/installCheck.ts +69 -0
- 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 +96 -18
- 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/motion/Text.js
CHANGED
|
@@ -9,7 +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
|
-
|
|
12
|
+
var __typeError = (msg) => {
|
|
13
|
+
throw TypeError(msg);
|
|
14
|
+
};
|
|
15
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
16
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
17
|
+
}) : x)(function(x) {
|
|
18
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
19
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
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);
|
|
13
25
|
var DEFAULT_MOTION_CONFIG = {
|
|
14
26
|
reducedMotion: "user"
|
|
15
27
|
};
|
|
@@ -19,43 +31,1427 @@ var MotionConfigContext = react.createContext(
|
|
|
19
31
|
function useMotionConfig() {
|
|
20
32
|
return react.useContext(MotionConfigContext);
|
|
21
33
|
}
|
|
22
|
-
function useShouldReduceMotion() {
|
|
23
|
-
const { reducedMotion } = useMotionConfig();
|
|
24
|
-
const osReduced = Animated.useReducedMotion();
|
|
25
|
-
if (reducedMotion === "never") return false;
|
|
26
|
-
if (reducedMotion === "always") return true;
|
|
27
|
-
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
|
+
var modality = "keyboard";
|
|
42
|
+
var installed = false;
|
|
43
|
+
function setKeyboard() {
|
|
44
|
+
modality = "keyboard";
|
|
45
|
+
}
|
|
46
|
+
function setPointer() {
|
|
47
|
+
modality = "pointer";
|
|
48
|
+
}
|
|
49
|
+
function ensureInstalled() {
|
|
50
|
+
if (installed) return;
|
|
51
|
+
if (reactNative.Platform.OS !== "web") return;
|
|
52
|
+
if (typeof document === "undefined") return;
|
|
53
|
+
document.addEventListener("keydown", setKeyboard, true);
|
|
54
|
+
document.addEventListener("mousedown", setPointer, true);
|
|
55
|
+
document.addEventListener("pointerdown", setPointer, true);
|
|
56
|
+
document.addEventListener("touchstart", setPointer, true);
|
|
57
|
+
installed = true;
|
|
58
|
+
}
|
|
59
|
+
function isFocusVisible() {
|
|
60
|
+
if (reactNative.Platform.OS !== "web") return true;
|
|
61
|
+
ensureInstalled();
|
|
62
|
+
return modality === "keyboard";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ../../node_modules/react-native-worklets/lib/module/logger.js
|
|
66
|
+
var PREFIX = "[Worklets]";
|
|
67
|
+
function formatMessage(message) {
|
|
68
|
+
return `${PREFIX} ${message}`;
|
|
69
|
+
}
|
|
70
|
+
var logger = {
|
|
71
|
+
warn(message) {
|
|
72
|
+
console.warn(formatMessage(message));
|
|
73
|
+
},
|
|
74
|
+
error(message) {
|
|
75
|
+
console.error(formatMessage(message));
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// ../../node_modules/react-native-worklets/lib/module/runtimeKind.js
|
|
80
|
+
var RuntimeKind = /* @__PURE__ */ (function(RuntimeKind2) {
|
|
81
|
+
RuntimeKind2[RuntimeKind2["ReactNative"] = 1] = "ReactNative";
|
|
82
|
+
RuntimeKind2[RuntimeKind2["UI"] = 2] = "UI";
|
|
83
|
+
RuntimeKind2[RuntimeKind2["Worker"] = 3] = "Worker";
|
|
84
|
+
return RuntimeKind2;
|
|
85
|
+
})({});
|
|
86
|
+
if (globalThis.__RUNTIME_KIND === void 0) {
|
|
87
|
+
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsError.js
|
|
91
|
+
function WorkletsErrorConstructor(message) {
|
|
92
|
+
"worklet";
|
|
93
|
+
const prefix = "[Worklets]";
|
|
94
|
+
const errorInstance = new Error(message ? `${prefix} ${message}` : prefix);
|
|
95
|
+
errorInstance.name = `WorkletsError`;
|
|
96
|
+
return errorInstance;
|
|
97
|
+
}
|
|
98
|
+
function registerWorkletsError() {
|
|
99
|
+
"worklet";
|
|
100
|
+
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
|
|
101
|
+
globalThis.WorkletsError = WorkletsErrorConstructor;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
var WorkletsError = WorkletsErrorConstructor;
|
|
105
|
+
|
|
106
|
+
// ../../node_modules/react-native-worklets/lib/module/bundleUnpacker.js
|
|
107
|
+
var handleCache = /* @__PURE__ */ new WeakMap();
|
|
108
|
+
function bundleValueUnpacker(objectToUnpack, category, remoteFunctionName) {
|
|
109
|
+
const workletHash = objectToUnpack.__workletHash;
|
|
110
|
+
if (workletHash !== void 0) {
|
|
111
|
+
return getWorklet(workletHash, objectToUnpack.__closure);
|
|
112
|
+
} else if (objectToUnpack.__init !== void 0) {
|
|
113
|
+
let value = handleCache.get(objectToUnpack);
|
|
114
|
+
if (value === void 0) {
|
|
115
|
+
value = objectToUnpack.__init();
|
|
116
|
+
handleCache.set(objectToUnpack, value);
|
|
117
|
+
}
|
|
118
|
+
return value;
|
|
119
|
+
} else if (category === "RemoteFunction") {
|
|
120
|
+
const remoteFunctionHolder = () => {
|
|
121
|
+
const label = remoteFunctionName ? `function \`${remoteFunctionName}\`` : "anonymous function";
|
|
122
|
+
throw new WorkletsError(`Tried to synchronously call a non-worklet ${label} on the UI thread.
|
|
123
|
+
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.`);
|
|
124
|
+
};
|
|
125
|
+
remoteFunctionHolder.__remoteFunction = objectToUnpack;
|
|
126
|
+
return remoteFunctionHolder;
|
|
127
|
+
} else {
|
|
128
|
+
throw new WorkletsError(`Data type in category "${category}" not recognized by value unpacker: "${globalThis._toString(objectToUnpack)}".`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function getWorklet(workletHash, closureVariables) {
|
|
132
|
+
let worklet;
|
|
133
|
+
if (__DEV__) {
|
|
134
|
+
try {
|
|
135
|
+
worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
|
|
136
|
+
} catch (_e) {
|
|
137
|
+
logger.error("Unable to resolve worklet with hash " + workletHash + ". Try reloading the app.");
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
|
|
141
|
+
}
|
|
142
|
+
return worklet;
|
|
143
|
+
}
|
|
144
|
+
var metroRequire = globalThis.__r;
|
|
145
|
+
function getWorkletFromMetroRequire(workletHash, closureVariables) {
|
|
146
|
+
const factory = metroRequire(workletHash).default;
|
|
147
|
+
return factory(closureVariables);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// ../../node_modules/react-native-worklets/lib/module/callGuard.js
|
|
151
|
+
function callGuardDEV(fn, ...args) {
|
|
152
|
+
"worklet";
|
|
153
|
+
try {
|
|
154
|
+
return fn(...args);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (globalThis.__workletsModuleProxy) {
|
|
157
|
+
const {
|
|
158
|
+
message,
|
|
159
|
+
stack,
|
|
160
|
+
name,
|
|
161
|
+
jsEngine
|
|
162
|
+
} = error;
|
|
163
|
+
globalThis.__workletsModuleProxy.reportFatalErrorOnJS(message, stack ?? "", name ?? "WorkletsError", jsEngine ?? "Worklets");
|
|
164
|
+
} else {
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function setupCallGuard() {
|
|
170
|
+
"worklet";
|
|
171
|
+
if (!globalThis.__callGuardDEV) {
|
|
172
|
+
globalThis.__callGuardDEV = callGuardDEV;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ../../node_modules/react-native-worklets/lib/module/errors.js
|
|
177
|
+
var _workletStackDetails = /* @__PURE__ */ new Map();
|
|
178
|
+
function registerWorkletStackDetails(hash, stackDetails) {
|
|
179
|
+
_workletStackDetails.set(hash, stackDetails);
|
|
180
|
+
}
|
|
181
|
+
function getBundleOffset(error) {
|
|
182
|
+
const frame = error.stack?.split("\n")?.[0];
|
|
183
|
+
if (frame) {
|
|
184
|
+
const parsedFrame = /@([^@]+):(\d+):(\d+)/.exec(frame);
|
|
185
|
+
if (parsedFrame) {
|
|
186
|
+
const [, file, line, col] = parsedFrame;
|
|
187
|
+
return [file, Number(line), Number(col)];
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return ["unknown", 0, 0];
|
|
191
|
+
}
|
|
192
|
+
function processStack(stack) {
|
|
193
|
+
if (stack === "" || stack === void 0) {
|
|
194
|
+
return void 0;
|
|
195
|
+
}
|
|
196
|
+
const workletStackEntries = stack.match(/worklet_(\d+):(\d+):(\d+)/g);
|
|
197
|
+
let result = stack;
|
|
198
|
+
workletStackEntries?.forEach((match) => {
|
|
199
|
+
const [, hash, origLine, origCol] = match.split(/:|_/).map(Number);
|
|
200
|
+
const errorDetails = _workletStackDetails.get(hash);
|
|
201
|
+
if (!errorDetails) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const [error, lineOffset, colOffset] = errorDetails;
|
|
205
|
+
const [bundleFile, bundleLine, bundleCol] = getBundleOffset(error);
|
|
206
|
+
const line = origLine + bundleLine + lineOffset;
|
|
207
|
+
const col = origCol + bundleCol + colOffset;
|
|
208
|
+
result = result.replace(match, `${bundleFile}:${line}:${col}`);
|
|
209
|
+
});
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
function reportFatalRemoteError({
|
|
213
|
+
message,
|
|
214
|
+
stack,
|
|
215
|
+
name,
|
|
216
|
+
jsEngine
|
|
217
|
+
}, force) {
|
|
218
|
+
const error = new WorkletsError();
|
|
219
|
+
error.message = message;
|
|
220
|
+
error.stack = processStack(stack);
|
|
221
|
+
error.name = name;
|
|
222
|
+
error.jsEngine = jsEngine;
|
|
223
|
+
if (force) {
|
|
224
|
+
throw error;
|
|
225
|
+
} else {
|
|
226
|
+
globalThis.ErrorUtils.reportFatalError(error);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function registerReportFatalRemoteError() {
|
|
230
|
+
globalThis.__reportFatalRemoteError = reportFatalRemoteError;
|
|
231
|
+
}
|
|
232
|
+
var IS_JEST = !!process.env.JEST_WORKER_ID;
|
|
233
|
+
var IS_WEB = reactNative.Platform.OS === "web";
|
|
234
|
+
var IS_WINDOWS = reactNative.Platform.OS === "windows";
|
|
235
|
+
var SHOULD_BE_USE_WEB = IS_JEST || IS_WEB || IS_WINDOWS;
|
|
236
|
+
|
|
237
|
+
// ../../node_modules/react-native-worklets/lib/module/PlatformChecker/index.js
|
|
238
|
+
var IS_JEST2 = false;
|
|
239
|
+
var SHOULD_BE_USE_WEB2 = false;
|
|
240
|
+
if (globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
241
|
+
IS_JEST2 = IS_JEST;
|
|
242
|
+
SHOULD_BE_USE_WEB2 = SHOULD_BE_USE_WEB;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/common/setImmediatePolyfill.js
|
|
246
|
+
function setupSetImmediate() {
|
|
247
|
+
"worklet";
|
|
248
|
+
const setImmediatePolyfill = (callback, ...args) => {
|
|
249
|
+
return setTimeout(callback, 0, ...args);
|
|
250
|
+
};
|
|
251
|
+
const clearImmediatePolyfill = (immediateHandle) => {
|
|
252
|
+
clearTimeout(immediateHandle);
|
|
253
|
+
};
|
|
254
|
+
globalThis.setImmediate = setImmediatePolyfill;
|
|
255
|
+
globalThis.clearImmediate = clearImmediatePolyfill;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/common/setIntervalPolyfill.js
|
|
259
|
+
function setupSetInterval() {
|
|
260
|
+
"worklet";
|
|
261
|
+
const intervalHandleToTimeoutHandle = /* @__PURE__ */ new Map();
|
|
262
|
+
const setIntervalPolyfill = (callback, delay = 0, ...args) => {
|
|
263
|
+
let intervalHandle = 0;
|
|
264
|
+
const repeatingCallback = () => {
|
|
265
|
+
const timeoutHandle = setTimeout(repeatingCallback, delay);
|
|
266
|
+
intervalHandleToTimeoutHandle.set(intervalHandle, timeoutHandle);
|
|
267
|
+
callback(...args);
|
|
268
|
+
};
|
|
269
|
+
intervalHandle = setTimeout(repeatingCallback, delay);
|
|
270
|
+
intervalHandleToTimeoutHandle.set(intervalHandle, intervalHandle);
|
|
271
|
+
return intervalHandle;
|
|
272
|
+
};
|
|
273
|
+
const clearIntervalPolyfill = (intervalHandle) => {
|
|
274
|
+
const timeoutHandle = intervalHandleToTimeoutHandle.get(intervalHandle);
|
|
275
|
+
clearTimeout(timeoutHandle);
|
|
276
|
+
intervalHandleToTimeoutHandle.delete(intervalHandle);
|
|
277
|
+
};
|
|
278
|
+
globalThis.setInterval = setIntervalPolyfill;
|
|
279
|
+
globalThis.clearInterval = clearIntervalPolyfill;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js
|
|
283
|
+
function mockedRequestAnimationFrame(callback) {
|
|
284
|
+
return setTimeout(() => callback(performance.now()), 0);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// ../../node_modules/react-native-worklets/lib/module/isSynchronizable.js
|
|
288
|
+
function isSynchronizable(value) {
|
|
289
|
+
return typeof value === "object" && value !== null && "__synchronizableRef" in value && value.__synchronizableRef === true;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// ../../node_modules/react-native-worklets/lib/module/serializableMappingCache.js
|
|
293
|
+
var serializableMappingFlag = /* @__PURE__ */ Symbol("serializable flag");
|
|
294
|
+
var cache = SHOULD_BE_USE_WEB2 ? null : /* @__PURE__ */ new WeakMap();
|
|
295
|
+
var serializableMappingCache = SHOULD_BE_USE_WEB2 ? {
|
|
296
|
+
set() {
|
|
297
|
+
},
|
|
298
|
+
get() {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
} : {
|
|
302
|
+
set(serializable, serializableRef) {
|
|
303
|
+
cache.set(serializable, serializableRef || serializableMappingFlag);
|
|
304
|
+
},
|
|
305
|
+
get: cache.get.bind(cache)
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// ../../node_modules/react-native-worklets/lib/module/utils/jsVersion.js
|
|
309
|
+
var jsVersion = "0.5.1";
|
|
310
|
+
|
|
311
|
+
// ../../node_modules/react-native-worklets/lib/module/workletFunction.js
|
|
312
|
+
function isWorkletFunction(value) {
|
|
313
|
+
"worklet";
|
|
314
|
+
return (
|
|
315
|
+
// `__workletHash` isn't extracted in Worklet Runtimes.
|
|
316
|
+
typeof value === "function" && !!value.__workletHash
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsModule/JSWorklets.js
|
|
321
|
+
function createJSWorkletsModule() {
|
|
322
|
+
return new JSWorklets();
|
|
323
|
+
}
|
|
324
|
+
var requestAnimationFrameImpl = IS_JEST2 || !globalThis.requestAnimationFrame ? mockedRequestAnimationFrame : globalThis.requestAnimationFrame;
|
|
325
|
+
var JSWorklets = class {
|
|
326
|
+
createSerializable() {
|
|
327
|
+
throw new WorkletsError("createSerializable should never be called in JSWorklets.");
|
|
328
|
+
}
|
|
329
|
+
createSerializableString() {
|
|
330
|
+
throw new WorkletsError("createSerializableString should never be called in JSWorklets.");
|
|
331
|
+
}
|
|
332
|
+
createSerializableNumber() {
|
|
333
|
+
throw new WorkletsError("createSerializableNumber should never be called in JSWorklets.");
|
|
334
|
+
}
|
|
335
|
+
createSerializableBoolean() {
|
|
336
|
+
throw new WorkletsError("createSerializableBoolean should never be called in JSWorklets.");
|
|
337
|
+
}
|
|
338
|
+
createSerializableBigInt() {
|
|
339
|
+
throw new WorkletsError("createSerializableBigInt should never be called in JSWorklets.");
|
|
340
|
+
}
|
|
341
|
+
createSerializableUndefined() {
|
|
342
|
+
throw new WorkletsError("createSerializableUndefined should never be called in JSWorklets.");
|
|
343
|
+
}
|
|
344
|
+
createSerializableNull() {
|
|
345
|
+
throw new WorkletsError("createSerializableNull should never be called in JSWorklets.");
|
|
346
|
+
}
|
|
347
|
+
createSerializableTurboModuleLike() {
|
|
348
|
+
throw new WorkletsError("createSerializableTurboModuleLike should never be called in JSWorklets.");
|
|
349
|
+
}
|
|
350
|
+
createSerializableObject() {
|
|
351
|
+
throw new WorkletsError("createSerializableObject should never be called in JSWorklets.");
|
|
352
|
+
}
|
|
353
|
+
createSerializableMap() {
|
|
354
|
+
throw new WorkletsError("createSerializableMap should never be called in JSWorklets.");
|
|
355
|
+
}
|
|
356
|
+
createSerializableSet() {
|
|
357
|
+
throw new WorkletsError("createSerializableSet should never be called in JSWorklets.");
|
|
358
|
+
}
|
|
359
|
+
createSerializableImport() {
|
|
360
|
+
throw new WorkletsError("createSerializableImport should never be called in JSWorklets.");
|
|
361
|
+
}
|
|
362
|
+
createSerializableHostObject() {
|
|
363
|
+
throw new WorkletsError("createSerializableHostObject should never be called in JSWorklets.");
|
|
364
|
+
}
|
|
365
|
+
createSerializableArray() {
|
|
366
|
+
throw new WorkletsError("createSerializableArray should never be called in JSWorklets.");
|
|
367
|
+
}
|
|
368
|
+
createSerializableInitializer() {
|
|
369
|
+
throw new WorkletsError("createSerializableInitializer should never be called in JSWorklets.");
|
|
370
|
+
}
|
|
371
|
+
createSerializableFunction() {
|
|
372
|
+
throw new WorkletsError("createSerializableFunction should never be called in JSWorklets.");
|
|
373
|
+
}
|
|
374
|
+
createSerializableWorklet() {
|
|
375
|
+
throw new WorkletsError("createSerializableWorklet should never be called in JSWorklets.");
|
|
376
|
+
}
|
|
377
|
+
scheduleOnUI(worklet) {
|
|
378
|
+
requestAnimationFrameImpl(worklet);
|
|
379
|
+
}
|
|
380
|
+
executeOnUIRuntimeSync() {
|
|
381
|
+
throw new WorkletsError("`executeOnUIRuntimeSync` is not available in JSWorklets.");
|
|
382
|
+
}
|
|
383
|
+
createWorkletRuntime() {
|
|
384
|
+
throw new WorkletsError("createWorkletRuntime is not available in JSWorklets.");
|
|
385
|
+
}
|
|
386
|
+
scheduleOnRuntime() {
|
|
387
|
+
throw new WorkletsError("scheduleOnRuntime is not available in JSWorklets.");
|
|
388
|
+
}
|
|
389
|
+
createSynchronizable() {
|
|
390
|
+
throw new WorkletsError("createSynchronizable should never be called in JSWorklets.");
|
|
391
|
+
}
|
|
392
|
+
synchronizableGetDirty() {
|
|
393
|
+
throw new WorkletsError("synchronizableGetDirty should never be called in JSWorklets.");
|
|
394
|
+
}
|
|
395
|
+
synchronizableGetBlocking() {
|
|
396
|
+
throw new WorkletsError("synchronizableGetBlocking should never be called in JSWorklets.");
|
|
397
|
+
}
|
|
398
|
+
synchronizableSetBlocking() {
|
|
399
|
+
throw new WorkletsError("synchronizableSetBlocking should never be called in JSWorklets.");
|
|
400
|
+
}
|
|
401
|
+
synchronizableLock() {
|
|
402
|
+
throw new WorkletsError("synchronizableLock should never be called in JSWorklets.");
|
|
403
|
+
}
|
|
404
|
+
synchronizableUnlock() {
|
|
405
|
+
throw new WorkletsError("synchronizableUnlock should never be called in JSWorklets.");
|
|
406
|
+
}
|
|
407
|
+
reportFatalErrorOnJS() {
|
|
408
|
+
throw new WorkletsError("reportFatalErrorOnJS should never be called in JSWorklets.");
|
|
409
|
+
}
|
|
410
|
+
getStaticFeatureFlag() {
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
setDynamicFeatureFlag() {
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
var NativeWorkletsModule_default = reactNative.TurboModuleRegistry.get("WorkletsModule");
|
|
417
|
+
|
|
418
|
+
// ../../node_modules/react-native-worklets/lib/module/specs/index.js
|
|
419
|
+
var WorkletsTurboModule = globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative ? NativeWorkletsModule_default : (
|
|
420
|
+
// In Bundle Mode, on Worklet Runtimes `RNWorkletsTurboModule` isn't
|
|
421
|
+
// available and shouldn't be accessed. We return null here
|
|
422
|
+
// to keep the same codebase for the Bundle Mode and legacy behavior.
|
|
423
|
+
null
|
|
424
|
+
);
|
|
425
|
+
|
|
426
|
+
// ../../node_modules/react-native-worklets/lib/module/utils/checkCppVersion.js
|
|
427
|
+
function checkCppVersion() {
|
|
428
|
+
const cppVersion = global._WORKLETS_VERSION_CPP;
|
|
429
|
+
if (cppVersion === void 0) {
|
|
430
|
+
logger.warn(`Couldn't determine the version of the native part of Worklets.
|
|
431
|
+
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#couldnt-determine-the-version-of-the-native-part-of-worklets\` for more details.`);
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
const ok = matchVersion(jsVersion, cppVersion);
|
|
435
|
+
if (!ok) {
|
|
436
|
+
throw new WorkletsError(`Mismatch between JavaScript part and native part of Worklets (${jsVersion} vs ${cppVersion}).
|
|
437
|
+
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-part-and-native-part-of-worklets\` for more details.`);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
function matchVersion(version1, version2) {
|
|
441
|
+
if (version1.match(/^\d+\.\d+\.\d+$/) && version2.match(/^\d+\.\d+\.\d+$/)) {
|
|
442
|
+
const [major1, minor1] = version1.split(".");
|
|
443
|
+
const [major2, minor2] = version2.split(".");
|
|
444
|
+
return major1 === major2 && minor1 === minor2;
|
|
445
|
+
} else {
|
|
446
|
+
return version1 === version2;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsModule/NativeWorklets.js
|
|
451
|
+
function createNativeWorkletsModule() {
|
|
452
|
+
return new NativeWorklets();
|
|
453
|
+
}
|
|
454
|
+
var _workletsModuleProxy, _serializableUndefined, _serializableNull, _serializableTrue, _serializableFalse;
|
|
455
|
+
var NativeWorklets = class {
|
|
456
|
+
constructor() {
|
|
457
|
+
__privateAdd(this, _workletsModuleProxy);
|
|
458
|
+
__privateAdd(this, _serializableUndefined);
|
|
459
|
+
__privateAdd(this, _serializableNull);
|
|
460
|
+
__privateAdd(this, _serializableTrue);
|
|
461
|
+
__privateAdd(this, _serializableFalse);
|
|
462
|
+
globalThis._WORKLETS_VERSION_JS = jsVersion;
|
|
463
|
+
if (global.__workletsModuleProxy === void 0 && globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
464
|
+
WorkletsTurboModule?.installTurboModule();
|
|
465
|
+
}
|
|
466
|
+
if (global.__workletsModuleProxy === void 0) {
|
|
467
|
+
throw new WorkletsError(`Native part of Worklets doesn't seem to be initialized.
|
|
468
|
+
See https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#native-part-of-worklets-doesnt-seem-to-be-initialized for more details.`);
|
|
469
|
+
}
|
|
470
|
+
if (__DEV__) {
|
|
471
|
+
checkCppVersion();
|
|
472
|
+
}
|
|
473
|
+
__privateSet(this, _workletsModuleProxy, global.__workletsModuleProxy);
|
|
474
|
+
__privateSet(this, _serializableNull, __privateGet(this, _workletsModuleProxy).createSerializableNull());
|
|
475
|
+
__privateSet(this, _serializableUndefined, __privateGet(this, _workletsModuleProxy).createSerializableUndefined());
|
|
476
|
+
__privateSet(this, _serializableTrue, __privateGet(this, _workletsModuleProxy).createSerializableBoolean(true));
|
|
477
|
+
__privateSet(this, _serializableFalse, __privateGet(this, _workletsModuleProxy).createSerializableBoolean(false));
|
|
478
|
+
}
|
|
479
|
+
createSerializable(value, shouldPersistRemote, nativeStateSource) {
|
|
480
|
+
return __privateGet(this, _workletsModuleProxy).createSerializable(value, shouldPersistRemote, nativeStateSource);
|
|
481
|
+
}
|
|
482
|
+
createSerializableImport(from, to) {
|
|
483
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableImport(from, to);
|
|
484
|
+
}
|
|
485
|
+
createSerializableString(str) {
|
|
486
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableString(str);
|
|
487
|
+
}
|
|
488
|
+
createSerializableNumber(num) {
|
|
489
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableNumber(num);
|
|
490
|
+
}
|
|
491
|
+
createSerializableBoolean(bool) {
|
|
492
|
+
return bool ? __privateGet(this, _serializableTrue) : __privateGet(this, _serializableFalse);
|
|
493
|
+
}
|
|
494
|
+
createSerializableBigInt(bigInt) {
|
|
495
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableBigInt(bigInt);
|
|
496
|
+
}
|
|
497
|
+
createSerializableUndefined() {
|
|
498
|
+
return __privateGet(this, _serializableUndefined);
|
|
499
|
+
}
|
|
500
|
+
createSerializableNull() {
|
|
501
|
+
return __privateGet(this, _serializableNull);
|
|
502
|
+
}
|
|
503
|
+
createSerializableTurboModuleLike(props, proto) {
|
|
504
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableTurboModuleLike(props, proto);
|
|
505
|
+
}
|
|
506
|
+
createSerializableObject(obj, shouldRetainRemote, nativeStateSource) {
|
|
507
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableObject(obj, shouldRetainRemote, nativeStateSource);
|
|
508
|
+
}
|
|
509
|
+
createSerializableHostObject(obj) {
|
|
510
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableHostObject(obj);
|
|
511
|
+
}
|
|
512
|
+
createSerializableArray(array, shouldRetainRemote) {
|
|
513
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableArray(array, shouldRetainRemote);
|
|
514
|
+
}
|
|
515
|
+
createSerializableMap(keys, values) {
|
|
516
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableMap(keys, values);
|
|
517
|
+
}
|
|
518
|
+
createSerializableSet(values) {
|
|
519
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableSet(values);
|
|
520
|
+
}
|
|
521
|
+
createSerializableInitializer(obj) {
|
|
522
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableInitializer(obj);
|
|
523
|
+
}
|
|
524
|
+
createSerializableFunction(func) {
|
|
525
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableFunction(func);
|
|
526
|
+
}
|
|
527
|
+
createSerializableWorklet(worklet, shouldPersistRemote) {
|
|
528
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableWorklet(worklet, shouldPersistRemote);
|
|
529
|
+
}
|
|
530
|
+
scheduleOnUI(serializable) {
|
|
531
|
+
return __privateGet(this, _workletsModuleProxy).scheduleOnUI(serializable);
|
|
532
|
+
}
|
|
533
|
+
executeOnUIRuntimeSync(serializable) {
|
|
534
|
+
return __privateGet(this, _workletsModuleProxy).executeOnUIRuntimeSync(serializable);
|
|
535
|
+
}
|
|
536
|
+
createWorkletRuntime(name, initializer, useDefaultQueue, customQueue, enableEventLoop) {
|
|
537
|
+
return __privateGet(this, _workletsModuleProxy).createWorkletRuntime(name, initializer, useDefaultQueue, customQueue, enableEventLoop);
|
|
538
|
+
}
|
|
539
|
+
scheduleOnRuntime(workletRuntime, serializableWorklet) {
|
|
540
|
+
return __privateGet(this, _workletsModuleProxy).scheduleOnRuntime(workletRuntime, serializableWorklet);
|
|
541
|
+
}
|
|
542
|
+
createSynchronizable(value) {
|
|
543
|
+
return __privateGet(this, _workletsModuleProxy).createSynchronizable(value);
|
|
544
|
+
}
|
|
545
|
+
synchronizableGetDirty(synchronizableRef) {
|
|
546
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableGetDirty(synchronizableRef);
|
|
547
|
+
}
|
|
548
|
+
synchronizableGetBlocking(synchronizableRef) {
|
|
549
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableGetBlocking(synchronizableRef);
|
|
550
|
+
}
|
|
551
|
+
synchronizableSetBlocking(synchronizableRef, value) {
|
|
552
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableSetBlocking(synchronizableRef, value);
|
|
553
|
+
}
|
|
554
|
+
synchronizableLock(synchronizableRef) {
|
|
555
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableLock(synchronizableRef);
|
|
556
|
+
}
|
|
557
|
+
synchronizableUnlock(synchronizableRef) {
|
|
558
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableUnlock(synchronizableRef);
|
|
559
|
+
}
|
|
560
|
+
reportFatalErrorOnJS(message, stack, name, jsEngine) {
|
|
561
|
+
return __privateGet(this, _workletsModuleProxy).reportFatalErrorOnJS(message, stack, name, jsEngine);
|
|
562
|
+
}
|
|
563
|
+
getStaticFeatureFlag(name) {
|
|
564
|
+
return __privateGet(this, _workletsModuleProxy).getStaticFeatureFlag(name);
|
|
565
|
+
}
|
|
566
|
+
setDynamicFeatureFlag(name, value) {
|
|
567
|
+
__privateGet(this, _workletsModuleProxy).setDynamicFeatureFlag(name, value);
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
_workletsModuleProxy = new WeakMap();
|
|
571
|
+
_serializableUndefined = new WeakMap();
|
|
572
|
+
_serializableNull = new WeakMap();
|
|
573
|
+
_serializableTrue = new WeakMap();
|
|
574
|
+
_serializableFalse = new WeakMap();
|
|
575
|
+
|
|
576
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsModule/workletsModuleInstance.js
|
|
577
|
+
var WorkletsModule = SHOULD_BE_USE_WEB2 ? createJSWorkletsModule() : createNativeWorkletsModule();
|
|
578
|
+
|
|
579
|
+
// ../../node_modules/react-native-worklets/lib/module/serializable.js
|
|
580
|
+
var MAGIC_KEY = "REANIMATED_MAGIC_KEY";
|
|
581
|
+
function isHostObject(value) {
|
|
582
|
+
"worklet";
|
|
583
|
+
return MAGIC_KEY in value;
|
|
584
|
+
}
|
|
585
|
+
function isPlainJSObject(object) {
|
|
586
|
+
"worklet";
|
|
587
|
+
return Object.getPrototypeOf(object) === Object.prototype;
|
|
588
|
+
}
|
|
589
|
+
function isTurboModuleLike(object) {
|
|
590
|
+
return isHostObject(Object.getPrototypeOf(object));
|
|
591
|
+
}
|
|
592
|
+
function getFromCache(value) {
|
|
593
|
+
const cached = serializableMappingCache.get(value);
|
|
594
|
+
if (cached === serializableMappingFlag) {
|
|
595
|
+
return value;
|
|
596
|
+
}
|
|
597
|
+
return cached;
|
|
598
|
+
}
|
|
599
|
+
var INACCESSIBLE_OBJECT = {
|
|
600
|
+
__init: () => {
|
|
601
|
+
"worklet";
|
|
602
|
+
return new Proxy({}, {
|
|
603
|
+
get: (_, prop) => {
|
|
604
|
+
if (prop === "_isReanimatedSharedValue" || prop === "__remoteFunction") {
|
|
605
|
+
return false;
|
|
606
|
+
}
|
|
607
|
+
throw new WorkletsError(`Trying to access property \`${String(prop)}\` of an object which cannot be sent to the UI runtime.`);
|
|
608
|
+
},
|
|
609
|
+
set: () => {
|
|
610
|
+
throw new WorkletsError("Trying to write to an object which cannot be sent to the UI runtime.");
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
var VALID_ARRAY_VIEWS_NAMES = ["Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array", "DataView"];
|
|
616
|
+
var DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD = 30;
|
|
617
|
+
var processedObjectAtThresholdDepth;
|
|
618
|
+
function createSerializableWeb(value) {
|
|
619
|
+
return value;
|
|
620
|
+
}
|
|
621
|
+
function createSerializableNative(value, shouldPersistRemote = false, depth = 0) {
|
|
622
|
+
detectCyclicObject(value, depth);
|
|
623
|
+
const isObject = typeof value === "object";
|
|
624
|
+
const isFunction = typeof value === "function";
|
|
625
|
+
if (typeof value === "string") {
|
|
626
|
+
return cloneString(value);
|
|
627
|
+
}
|
|
628
|
+
if (typeof value === "number") {
|
|
629
|
+
return cloneNumber(value);
|
|
630
|
+
}
|
|
631
|
+
if (typeof value === "boolean") {
|
|
632
|
+
return cloneBoolean(value);
|
|
633
|
+
}
|
|
634
|
+
if (typeof value === "bigint") {
|
|
635
|
+
return cloneBigInt(value);
|
|
636
|
+
}
|
|
637
|
+
if (value === void 0) {
|
|
638
|
+
return cloneUndefined();
|
|
639
|
+
}
|
|
640
|
+
if (value === null) {
|
|
641
|
+
return cloneNull();
|
|
642
|
+
}
|
|
643
|
+
if (!isObject && !isFunction || value === null) {
|
|
644
|
+
return clonePrimitive(value, shouldPersistRemote);
|
|
645
|
+
}
|
|
646
|
+
const cached = getFromCache(value);
|
|
647
|
+
if (cached !== void 0) {
|
|
648
|
+
return cached;
|
|
649
|
+
}
|
|
650
|
+
if (Array.isArray(value)) {
|
|
651
|
+
return cloneArray(value, shouldPersistRemote, depth);
|
|
652
|
+
}
|
|
653
|
+
if (globalThis._WORKLETS_BUNDLE_MODE && isFunction && value.__bundleData) {
|
|
654
|
+
return cloneImport(value);
|
|
655
|
+
}
|
|
656
|
+
if (isFunction && !isWorkletFunction(value)) {
|
|
657
|
+
return cloneRemoteFunction(value);
|
|
658
|
+
}
|
|
659
|
+
if (isTurboModuleLike(value)) {
|
|
660
|
+
return cloneTurboModuleLike(value, shouldPersistRemote, depth);
|
|
661
|
+
}
|
|
662
|
+
if (isHostObject(value)) {
|
|
663
|
+
return cloneHostObject(value);
|
|
664
|
+
}
|
|
665
|
+
if (isPlainJSObject(value) && value.__init) {
|
|
666
|
+
return cloneInitializer(value, shouldPersistRemote, depth);
|
|
667
|
+
}
|
|
668
|
+
if (isPlainJSObject(value) && value.__workletContextObjectFactory) {
|
|
669
|
+
return cloneContextObject(value);
|
|
670
|
+
}
|
|
671
|
+
if ((isPlainJSObject(value) || isFunction) && isWorkletFunction(value)) {
|
|
672
|
+
return cloneWorklet(value, shouldPersistRemote, depth);
|
|
673
|
+
}
|
|
674
|
+
if (isSynchronizable(value)) {
|
|
675
|
+
return cloneSynchronizable(value);
|
|
676
|
+
}
|
|
677
|
+
if (isPlainJSObject(value) || isFunction) {
|
|
678
|
+
return clonePlainJSObject(value, shouldPersistRemote, depth);
|
|
679
|
+
}
|
|
680
|
+
if (value instanceof Set) {
|
|
681
|
+
return cloneSet(value);
|
|
682
|
+
}
|
|
683
|
+
if (value instanceof Map) {
|
|
684
|
+
return cloneMap(value);
|
|
685
|
+
}
|
|
686
|
+
if (value instanceof RegExp) {
|
|
687
|
+
return cloneRegExp(value);
|
|
688
|
+
}
|
|
689
|
+
if (value instanceof Error) {
|
|
690
|
+
return cloneError(value);
|
|
691
|
+
}
|
|
692
|
+
if (value instanceof ArrayBuffer) {
|
|
693
|
+
return cloneArrayBuffer(value, shouldPersistRemote);
|
|
694
|
+
}
|
|
695
|
+
if (ArrayBuffer.isView(value)) {
|
|
696
|
+
return cloneArrayBufferView(value);
|
|
697
|
+
}
|
|
698
|
+
return inaccessibleObject(value);
|
|
699
|
+
}
|
|
700
|
+
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
701
|
+
createSerializableNative.__bundleData = {
|
|
702
|
+
imported: "createSerializable",
|
|
703
|
+
// @ts-expect-error resolveWeak is defined by Metro
|
|
704
|
+
source: __require.resolveWeak("./index")
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
var createSerializable = SHOULD_BE_USE_WEB2 ? createSerializableWeb : createSerializableNative;
|
|
708
|
+
function detectCyclicObject(value, depth) {
|
|
709
|
+
if (depth >= DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
|
|
710
|
+
if (depth === DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
|
|
711
|
+
processedObjectAtThresholdDepth = value;
|
|
712
|
+
} else if (value === processedObjectAtThresholdDepth) {
|
|
713
|
+
throw new WorkletsError("Trying to convert a cyclic object to a serializable. This is not supported.");
|
|
714
|
+
}
|
|
715
|
+
} else {
|
|
716
|
+
processedObjectAtThresholdDepth = void 0;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
function clonePrimitive(value, shouldPersistRemote) {
|
|
720
|
+
return WorkletsModule.createSerializable(value, shouldPersistRemote);
|
|
721
|
+
}
|
|
722
|
+
function cloneString(value) {
|
|
723
|
+
return WorkletsModule.createSerializableString(value);
|
|
724
|
+
}
|
|
725
|
+
function cloneNumber(value) {
|
|
726
|
+
return WorkletsModule.createSerializableNumber(value);
|
|
727
|
+
}
|
|
728
|
+
function cloneBoolean(value) {
|
|
729
|
+
return WorkletsModule.createSerializableBoolean(value);
|
|
730
|
+
}
|
|
731
|
+
function cloneBigInt(value) {
|
|
732
|
+
return WorkletsModule.createSerializableBigInt(value);
|
|
733
|
+
}
|
|
734
|
+
function cloneUndefined() {
|
|
735
|
+
return WorkletsModule.createSerializableUndefined();
|
|
736
|
+
}
|
|
737
|
+
function cloneNull() {
|
|
738
|
+
return WorkletsModule.createSerializableNull();
|
|
739
|
+
}
|
|
740
|
+
function cloneObjectProperties(value, shouldPersistRemote, depth) {
|
|
741
|
+
const clonedProps = {};
|
|
742
|
+
for (const [key, element] of Object.entries(value)) {
|
|
743
|
+
if (key === "__initData" && clonedProps.__initData !== void 0) {
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
clonedProps[key] = createSerializable(element, shouldPersistRemote, depth + 1);
|
|
747
|
+
}
|
|
748
|
+
return clonedProps;
|
|
749
|
+
}
|
|
750
|
+
function cloneInitializer(value, shouldPersistRemote = false, depth = 0) {
|
|
751
|
+
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
|
|
752
|
+
return WorkletsModule.createSerializableInitializer(clonedProps);
|
|
753
|
+
}
|
|
754
|
+
function cloneArray(value, shouldPersistRemote, depth) {
|
|
755
|
+
const clonedElements = value.map((element) => createSerializable(element, shouldPersistRemote, depth + 1));
|
|
756
|
+
const clone = WorkletsModule.createSerializableArray(clonedElements, shouldPersistRemote);
|
|
757
|
+
serializableMappingCache.set(value, clone);
|
|
758
|
+
serializableMappingCache.set(clone);
|
|
759
|
+
freezeObjectInDev(value);
|
|
760
|
+
return clone;
|
|
761
|
+
}
|
|
762
|
+
function cloneRemoteFunction(value) {
|
|
763
|
+
const clone = WorkletsModule.createSerializableFunction(value);
|
|
764
|
+
serializableMappingCache.set(value, clone);
|
|
765
|
+
serializableMappingCache.set(clone);
|
|
766
|
+
freezeObjectInDev(value);
|
|
767
|
+
return clone;
|
|
768
|
+
}
|
|
769
|
+
function cloneHostObject(value) {
|
|
770
|
+
const clone = WorkletsModule.createSerializableHostObject(value);
|
|
771
|
+
serializableMappingCache.set(value, clone);
|
|
772
|
+
serializableMappingCache.set(clone);
|
|
773
|
+
return clone;
|
|
774
|
+
}
|
|
775
|
+
function cloneWorklet(value, shouldPersistRemote, depth) {
|
|
776
|
+
if (__DEV__) {
|
|
777
|
+
const babelVersion = value.__pluginVersion;
|
|
778
|
+
if (babelVersion !== void 0 && babelVersion !== jsVersion) {
|
|
779
|
+
throw new WorkletsError(`Mismatch between JavaScript code version and Worklets Babel plugin version (${jsVersion} vs. ${babelVersion}).
|
|
780
|
+
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-code-version-and-worklets-babel-plugin-version\` for more details.
|
|
781
|
+
Offending code was: \`${getWorkletCode(value)}\``);
|
|
782
|
+
}
|
|
783
|
+
registerWorkletStackDetails(value.__workletHash, value.__stackDetails);
|
|
784
|
+
}
|
|
785
|
+
if (value.__stackDetails) {
|
|
786
|
+
delete value.__stackDetails;
|
|
787
|
+
}
|
|
788
|
+
const clonedProps = cloneObjectProperties(value, true, depth);
|
|
789
|
+
clonedProps.__initData = createSerializable(value.__initData, true, depth + 1);
|
|
790
|
+
const clone = WorkletsModule.createSerializableWorklet(
|
|
791
|
+
clonedProps,
|
|
792
|
+
// TODO: Check after refactor if we can remove shouldPersistRemote parameter (imho it's redundant here since worklets are always persistent)
|
|
793
|
+
// retain all worklets
|
|
794
|
+
true
|
|
795
|
+
);
|
|
796
|
+
serializableMappingCache.set(value, clone);
|
|
797
|
+
serializableMappingCache.set(clone);
|
|
798
|
+
freezeObjectInDev(value);
|
|
799
|
+
return clone;
|
|
800
|
+
}
|
|
801
|
+
function cloneTurboModuleLike(value, shouldPersistRemote, depth) {
|
|
802
|
+
const proto = Object.getPrototypeOf(value);
|
|
803
|
+
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
|
|
804
|
+
const clone = WorkletsModule.createSerializableTurboModuleLike(clonedProps, proto);
|
|
805
|
+
return clone;
|
|
806
|
+
}
|
|
807
|
+
function cloneContextObject(value) {
|
|
808
|
+
const workletContextObjectFactory = value.__workletContextObjectFactory;
|
|
809
|
+
const handle = cloneInitializer({
|
|
810
|
+
__init: () => {
|
|
811
|
+
"worklet";
|
|
812
|
+
return workletContextObjectFactory();
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
serializableMappingCache.set(value, handle);
|
|
816
|
+
return handle;
|
|
817
|
+
}
|
|
818
|
+
function clonePlainJSObject(value, shouldPersistRemote, depth) {
|
|
819
|
+
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
|
|
820
|
+
const clone = WorkletsModule.createSerializableObject(clonedProps, shouldPersistRemote, value);
|
|
821
|
+
serializableMappingCache.set(value, clone);
|
|
822
|
+
serializableMappingCache.set(clone);
|
|
823
|
+
freezeObjectInDev(value);
|
|
824
|
+
return clone;
|
|
825
|
+
}
|
|
826
|
+
function cloneMap(value) {
|
|
827
|
+
const clonedKeys = [];
|
|
828
|
+
const clonedValues = [];
|
|
829
|
+
for (const [key, element] of value.entries()) {
|
|
830
|
+
clonedKeys.push(createSerializable(key));
|
|
831
|
+
clonedValues.push(createSerializable(element));
|
|
832
|
+
}
|
|
833
|
+
const clone = WorkletsModule.createSerializableMap(clonedKeys, clonedValues);
|
|
834
|
+
serializableMappingCache.set(value, clone);
|
|
835
|
+
serializableMappingCache.set(clone);
|
|
836
|
+
freezeObjectInDev(value);
|
|
837
|
+
return clone;
|
|
838
|
+
}
|
|
839
|
+
function cloneSet(value) {
|
|
840
|
+
const clonedElements = [];
|
|
841
|
+
for (const element of value) {
|
|
842
|
+
clonedElements.push(createSerializable(element));
|
|
843
|
+
}
|
|
844
|
+
const clone = WorkletsModule.createSerializableSet(clonedElements);
|
|
845
|
+
serializableMappingCache.set(value, clone);
|
|
846
|
+
serializableMappingCache.set(clone);
|
|
847
|
+
freezeObjectInDev(value);
|
|
848
|
+
return clone;
|
|
849
|
+
}
|
|
850
|
+
function cloneRegExp(value) {
|
|
851
|
+
const pattern = value.source;
|
|
852
|
+
const flags = value.flags;
|
|
853
|
+
const handle = cloneInitializer({
|
|
854
|
+
__init: () => {
|
|
855
|
+
"worklet";
|
|
856
|
+
return new RegExp(pattern, flags);
|
|
857
|
+
}
|
|
858
|
+
});
|
|
859
|
+
serializableMappingCache.set(value, handle);
|
|
860
|
+
return handle;
|
|
861
|
+
}
|
|
862
|
+
function cloneError(value) {
|
|
863
|
+
const {
|
|
864
|
+
name,
|
|
865
|
+
message,
|
|
866
|
+
stack
|
|
867
|
+
} = value;
|
|
868
|
+
const handle = cloneInitializer({
|
|
869
|
+
__init: () => {
|
|
870
|
+
"worklet";
|
|
871
|
+
const error = new Error();
|
|
872
|
+
error.name = name;
|
|
873
|
+
error.message = message;
|
|
874
|
+
error.stack = stack;
|
|
875
|
+
return error;
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
serializableMappingCache.set(value, handle);
|
|
879
|
+
return handle;
|
|
880
|
+
}
|
|
881
|
+
function cloneArrayBuffer(value, shouldPersistRemote) {
|
|
882
|
+
const clone = WorkletsModule.createSerializable(value, shouldPersistRemote, value);
|
|
883
|
+
serializableMappingCache.set(value, clone);
|
|
884
|
+
serializableMappingCache.set(clone);
|
|
885
|
+
return clone;
|
|
886
|
+
}
|
|
887
|
+
function cloneArrayBufferView(value) {
|
|
888
|
+
const buffer = value.buffer;
|
|
889
|
+
const typeName = value.constructor.name;
|
|
890
|
+
const handle = cloneInitializer({
|
|
891
|
+
__init: () => {
|
|
892
|
+
"worklet";
|
|
893
|
+
if (!VALID_ARRAY_VIEWS_NAMES.includes(typeName)) {
|
|
894
|
+
throw new WorkletsError(`Invalid array view name \`${typeName}\`.`);
|
|
895
|
+
}
|
|
896
|
+
const constructor = global[typeName];
|
|
897
|
+
if (constructor === void 0) {
|
|
898
|
+
throw new WorkletsError(`Constructor for \`${typeName}\` not found.`);
|
|
899
|
+
}
|
|
900
|
+
return new constructor(buffer);
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
serializableMappingCache.set(value, handle);
|
|
904
|
+
return handle;
|
|
905
|
+
}
|
|
906
|
+
function cloneSynchronizable(value) {
|
|
907
|
+
serializableMappingCache.set(value);
|
|
908
|
+
return value;
|
|
909
|
+
}
|
|
910
|
+
function cloneImport(value) {
|
|
911
|
+
const {
|
|
912
|
+
source,
|
|
913
|
+
imported
|
|
914
|
+
} = value.__bundleData;
|
|
915
|
+
const clone = WorkletsModule.createSerializableImport(source, imported);
|
|
916
|
+
serializableMappingCache.set(value, clone);
|
|
917
|
+
serializableMappingCache.set(clone);
|
|
918
|
+
return clone;
|
|
919
|
+
}
|
|
920
|
+
function inaccessibleObject(value) {
|
|
921
|
+
const clone = createSerializable(INACCESSIBLE_OBJECT);
|
|
922
|
+
serializableMappingCache.set(value, clone);
|
|
923
|
+
return clone;
|
|
924
|
+
}
|
|
925
|
+
var WORKLET_CODE_THRESHOLD = 255;
|
|
926
|
+
function getWorkletCode(value) {
|
|
927
|
+
const code = value?.__initData?.code;
|
|
928
|
+
if (!code) {
|
|
929
|
+
return "unknown";
|
|
930
|
+
}
|
|
931
|
+
if (code.length > WORKLET_CODE_THRESHOLD) {
|
|
932
|
+
return `${code.substring(0, WORKLET_CODE_THRESHOLD)}...`;
|
|
933
|
+
}
|
|
934
|
+
return code;
|
|
935
|
+
}
|
|
936
|
+
function isRemoteFunction(value) {
|
|
937
|
+
"worklet";
|
|
938
|
+
return !!value.__remoteFunction;
|
|
939
|
+
}
|
|
940
|
+
function freezeObjectInDev(value) {
|
|
941
|
+
if (!__DEV__) {
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
Object.entries(value).forEach(([key, element]) => {
|
|
945
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
946
|
+
if (!descriptor.configurable) {
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
Object.defineProperty(value, key, {
|
|
950
|
+
get() {
|
|
951
|
+
return element;
|
|
952
|
+
},
|
|
953
|
+
set() {
|
|
954
|
+
logger.warn(`Tried to modify key \`${key}\` of an object which has been already passed to a worklet. See
|
|
955
|
+
https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-modify-key-of-an-object-which-has-been-converted-to-a-serializable
|
|
956
|
+
for more details.`);
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
});
|
|
960
|
+
Object.preventExtensions(value);
|
|
961
|
+
}
|
|
962
|
+
function makeShareableCloneOnUIRecursiveLEGACY(value) {
|
|
963
|
+
"worklet";
|
|
964
|
+
if (SHOULD_BE_USE_WEB2) {
|
|
965
|
+
return value;
|
|
966
|
+
}
|
|
967
|
+
function cloneRecursive(value2) {
|
|
968
|
+
if (typeof value2 === "object" && value2 !== null || typeof value2 === "function") {
|
|
969
|
+
if (isHostObject(value2)) {
|
|
970
|
+
return global._createSerializableHostObject(value2);
|
|
971
|
+
}
|
|
972
|
+
if (isRemoteFunction(value2)) {
|
|
973
|
+
return value2.__remoteFunction;
|
|
974
|
+
}
|
|
975
|
+
if (Array.isArray(value2)) {
|
|
976
|
+
return global._createSerializableArray(value2.map(cloneRecursive));
|
|
977
|
+
}
|
|
978
|
+
if (value2.__synchronizableRef) {
|
|
979
|
+
return global._createSerializableSynchronizable(value2);
|
|
980
|
+
}
|
|
981
|
+
const toAdapt = {};
|
|
982
|
+
for (const [key, element] of Object.entries(value2)) {
|
|
983
|
+
toAdapt[key] = cloneRecursive(element);
|
|
984
|
+
}
|
|
985
|
+
return global._createSerializable(toAdapt, value2);
|
|
986
|
+
}
|
|
987
|
+
if (typeof value2 === "string") {
|
|
988
|
+
return global._createSerializableString(value2);
|
|
989
|
+
}
|
|
990
|
+
if (typeof value2 === "number") {
|
|
991
|
+
return global._createSerializableNumber(value2);
|
|
992
|
+
}
|
|
993
|
+
if (typeof value2 === "boolean") {
|
|
994
|
+
return global._createSerializableBoolean(value2);
|
|
995
|
+
}
|
|
996
|
+
if (typeof value2 === "bigint") {
|
|
997
|
+
return global._createSerializableBigInt(value2);
|
|
998
|
+
}
|
|
999
|
+
if (value2 === void 0) {
|
|
1000
|
+
return global._createSerializableUndefined();
|
|
1001
|
+
}
|
|
1002
|
+
if (value2 === null) {
|
|
1003
|
+
return global._createSerializableNull();
|
|
1004
|
+
}
|
|
1005
|
+
return global._createSerializable(value2, void 0);
|
|
1006
|
+
}
|
|
1007
|
+
return cloneRecursive(value);
|
|
1008
|
+
}
|
|
1009
|
+
var makeShareableCloneOnUIRecursive = globalThis._WORKLETS_BUNDLE_MODE ? createSerializable : makeShareableCloneOnUIRecursiveLEGACY;
|
|
1010
|
+
|
|
1011
|
+
// ../../node_modules/react-native-worklets/lib/module/threads.js
|
|
1012
|
+
var runOnUIQueue = [];
|
|
1013
|
+
function setupMicrotasks() {
|
|
1014
|
+
"worklet";
|
|
1015
|
+
let microtasksQueue = [];
|
|
1016
|
+
let isExecutingMicrotasksQueue = false;
|
|
1017
|
+
global.queueMicrotask = (callback) => {
|
|
1018
|
+
microtasksQueue.push(callback);
|
|
1019
|
+
};
|
|
1020
|
+
global._microtaskQueueFinalizers = [];
|
|
1021
|
+
global.__callMicrotasks = () => {
|
|
1022
|
+
if (isExecutingMicrotasksQueue) {
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
try {
|
|
1026
|
+
isExecutingMicrotasksQueue = true;
|
|
1027
|
+
for (let index = 0; index < microtasksQueue.length; index += 1) {
|
|
1028
|
+
microtasksQueue[index]();
|
|
1029
|
+
}
|
|
1030
|
+
microtasksQueue = [];
|
|
1031
|
+
global._microtaskQueueFinalizers.forEach((finalizer) => finalizer());
|
|
1032
|
+
} finally {
|
|
1033
|
+
isExecutingMicrotasksQueue = false;
|
|
1034
|
+
}
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
function callMicrotasksOnUIThread() {
|
|
1038
|
+
"worklet";
|
|
1039
|
+
global.__callMicrotasks();
|
|
1040
|
+
}
|
|
1041
|
+
var callMicrotasks = SHOULD_BE_USE_WEB2 ? () => {
|
|
1042
|
+
} : callMicrotasksOnUIThread;
|
|
1043
|
+
function runOnUI(worklet) {
|
|
1044
|
+
if (__DEV__ && !SHOULD_BE_USE_WEB2 && !isWorkletFunction(worklet) && !worklet.__bundleData) {
|
|
1045
|
+
throw new WorkletsError("`runOnUI` can only be used with worklets.");
|
|
1046
|
+
}
|
|
1047
|
+
return (...args) => {
|
|
1048
|
+
if (IS_JEST2) {
|
|
1049
|
+
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
|
1050
|
+
"worklet";
|
|
1051
|
+
worklet(...args);
|
|
1052
|
+
}));
|
|
1053
|
+
return;
|
|
1054
|
+
}
|
|
1055
|
+
if (__DEV__) {
|
|
1056
|
+
createSerializable(worklet);
|
|
1057
|
+
createSerializable(args);
|
|
1058
|
+
}
|
|
1059
|
+
enqueueUI(worklet, args);
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
1062
|
+
if (__DEV__) {
|
|
1063
|
+
let runOnUIWorklet = function() {
|
|
1064
|
+
"worklet";
|
|
1065
|
+
throw new WorkletsError("`runOnUI` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.");
|
|
1066
|
+
};
|
|
1067
|
+
const serializableRunOnUIWorklet = createSerializable(runOnUIWorklet);
|
|
1068
|
+
serializableMappingCache.set(runOnUI, serializableRunOnUIWorklet);
|
|
1069
|
+
}
|
|
1070
|
+
function executeOnUIRuntimeSync(worklet) {
|
|
1071
|
+
return (...args) => {
|
|
1072
|
+
return WorkletsModule.executeOnUIRuntimeSync(createSerializable(() => {
|
|
1073
|
+
"worklet";
|
|
1074
|
+
const result = worklet(...args);
|
|
1075
|
+
return makeShareableCloneOnUIRecursive(result);
|
|
1076
|
+
}));
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
function runWorkletOnJS(worklet, ...args) {
|
|
1080
|
+
worklet(...args);
|
|
1081
|
+
}
|
|
1082
|
+
function runOnJS(fun) {
|
|
1083
|
+
"worklet";
|
|
1084
|
+
if (SHOULD_BE_USE_WEB2 || globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
1085
|
+
return (...args) => queueMicrotask(args.length ? () => fun(...args) : fun);
|
|
1086
|
+
}
|
|
1087
|
+
if (isWorkletFunction(fun)) {
|
|
1088
|
+
return (...args) => runOnJS(runWorkletOnJS)(fun, ...args);
|
|
1089
|
+
}
|
|
1090
|
+
if (fun.__remoteFunction) {
|
|
1091
|
+
fun = fun.__remoteFunction;
|
|
1092
|
+
}
|
|
1093
|
+
const scheduleOnJS = typeof fun === "function" ? global._scheduleHostFunctionOnJS : global._scheduleRemoteFunctionOnJS;
|
|
1094
|
+
return (...args) => {
|
|
1095
|
+
scheduleOnJS(fun, args.length > 0 ? makeShareableCloneOnUIRecursive(args) : void 0);
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
function runOnUIAsync(worklet) {
|
|
1099
|
+
if (__DEV__ && !SHOULD_BE_USE_WEB2 && !isWorkletFunction(worklet)) {
|
|
1100
|
+
throw new WorkletsError("`runOnUIAsync` can only be used with worklets.");
|
|
1101
|
+
}
|
|
1102
|
+
return (...args) => {
|
|
1103
|
+
return new Promise((resolve) => {
|
|
1104
|
+
if (IS_JEST2) {
|
|
1105
|
+
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
|
1106
|
+
"worklet";
|
|
1107
|
+
worklet(...args);
|
|
1108
|
+
}));
|
|
1109
|
+
return;
|
|
1110
|
+
}
|
|
1111
|
+
if (__DEV__) {
|
|
1112
|
+
createSerializable(worklet);
|
|
1113
|
+
createSerializable(args);
|
|
1114
|
+
}
|
|
1115
|
+
enqueueUI(worklet, args, resolve);
|
|
1116
|
+
});
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
if (__DEV__) {
|
|
1120
|
+
let runOnUIAsyncWorklet = function() {
|
|
1121
|
+
"worklet";
|
|
1122
|
+
throw new WorkletsError("`runOnUIAsync` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.");
|
|
1123
|
+
};
|
|
1124
|
+
const serializableRunOnUIAsyncWorklet = createSerializable(runOnUIAsyncWorklet);
|
|
1125
|
+
serializableMappingCache.set(runOnUIAsync, serializableRunOnUIAsyncWorklet);
|
|
28
1126
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
1127
|
+
function enqueueUI(worklet, args, resolve) {
|
|
1128
|
+
const job = [worklet, args, resolve];
|
|
1129
|
+
runOnUIQueue.push(job);
|
|
1130
|
+
if (runOnUIQueue.length === 1) {
|
|
1131
|
+
flushUIQueue();
|
|
1132
|
+
}
|
|
33
1133
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
1134
|
+
function flushUIQueue() {
|
|
1135
|
+
queueMicrotask(() => {
|
|
1136
|
+
const queue = runOnUIQueue;
|
|
1137
|
+
runOnUIQueue = [];
|
|
1138
|
+
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
|
1139
|
+
"worklet";
|
|
1140
|
+
queue.forEach(([workletFunction, workletArgs, jobResolve]) => {
|
|
1141
|
+
const result = workletFunction(...workletArgs);
|
|
1142
|
+
if (jobResolve) {
|
|
1143
|
+
runOnJS(jobResolve)(result);
|
|
1144
|
+
}
|
|
1145
|
+
});
|
|
1146
|
+
callMicrotasks();
|
|
1147
|
+
}));
|
|
1148
|
+
});
|
|
36
1149
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
1150
|
+
|
|
1151
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/requestAnimationFrame.js
|
|
1152
|
+
function setupRequestAnimationFrame() {
|
|
1153
|
+
"worklet";
|
|
1154
|
+
const nativeRequestAnimationFrame = globalThis.requestAnimationFrame;
|
|
1155
|
+
let queuedCallbacks = [];
|
|
1156
|
+
let queuedCallbacksBegin = 0;
|
|
1157
|
+
let queuedCallbacksEnd = 0;
|
|
1158
|
+
let flushedCallbacks = queuedCallbacks;
|
|
1159
|
+
let flushedCallbacksBegin = 0;
|
|
1160
|
+
let flushedCallbacksEnd = 0;
|
|
1161
|
+
let flushRequested = false;
|
|
1162
|
+
globalThis.__flushAnimationFrame = (timestamp) => {
|
|
1163
|
+
flushedCallbacks = queuedCallbacks;
|
|
1164
|
+
queuedCallbacks = [];
|
|
1165
|
+
flushedCallbacksBegin = queuedCallbacksBegin;
|
|
1166
|
+
flushedCallbacksEnd = queuedCallbacksEnd;
|
|
1167
|
+
queuedCallbacksBegin = queuedCallbacksEnd;
|
|
1168
|
+
for (const callback of flushedCallbacks) {
|
|
1169
|
+
callback(timestamp);
|
|
1170
|
+
}
|
|
1171
|
+
flushedCallbacksBegin = flushedCallbacksEnd;
|
|
1172
|
+
callMicrotasks();
|
|
1173
|
+
};
|
|
1174
|
+
globalThis.requestAnimationFrame = (callback) => {
|
|
1175
|
+
const handle = queuedCallbacksEnd++;
|
|
1176
|
+
queuedCallbacks.push(callback);
|
|
1177
|
+
if (!flushRequested) {
|
|
1178
|
+
flushRequested = true;
|
|
1179
|
+
nativeRequestAnimationFrame((timestamp) => {
|
|
1180
|
+
flushRequested = false;
|
|
1181
|
+
globalThis.__frameTimestamp = timestamp;
|
|
1182
|
+
globalThis.__flushAnimationFrame(timestamp);
|
|
1183
|
+
globalThis.__frameTimestamp = void 0;
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
return handle;
|
|
1187
|
+
};
|
|
1188
|
+
globalThis.cancelAnimationFrame = (handle) => {
|
|
1189
|
+
if (handle < flushedCallbacksBegin || handle >= queuedCallbacksEnd) {
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1192
|
+
if (handle < flushedCallbacksEnd) {
|
|
1193
|
+
flushedCallbacks[handle - flushedCallbacksBegin] = () => {
|
|
1194
|
+
};
|
|
1195
|
+
} else {
|
|
1196
|
+
queuedCallbacks[handle - queuedCallbacksBegin] = () => {
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
46
1200
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
1201
|
+
|
|
1202
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js
|
|
1203
|
+
function setupSetTimeout() {
|
|
1204
|
+
"worklet";
|
|
1205
|
+
const timeoutHandleToRafHandle = /* @__PURE__ */ new Map();
|
|
1206
|
+
const setTimeoutPolyfill = (callback, delay = 0, ...args) => {
|
|
1207
|
+
const start = performance.now();
|
|
1208
|
+
let timeoutHandle = 0;
|
|
1209
|
+
const rafCallback = () => {
|
|
1210
|
+
const now = performance.now();
|
|
1211
|
+
if (now - start >= delay) {
|
|
1212
|
+
callback(...args);
|
|
1213
|
+
timeoutHandleToRafHandle.delete(timeoutHandle);
|
|
1214
|
+
} else {
|
|
1215
|
+
const rafHandle = requestAnimationFrame(rafCallback);
|
|
1216
|
+
timeoutHandleToRafHandle.set(timeoutHandle, rafHandle);
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
timeoutHandle = requestAnimationFrame(rafCallback);
|
|
1220
|
+
timeoutHandleToRafHandle.set(timeoutHandle, timeoutHandle);
|
|
1221
|
+
return timeoutHandle;
|
|
1222
|
+
};
|
|
1223
|
+
const clearTimeoutPolyfill = (timeoutHandle) => {
|
|
1224
|
+
const rafHandle = timeoutHandleToRafHandle.get(timeoutHandle);
|
|
1225
|
+
timeoutHandleToRafHandle.delete(timeoutHandle);
|
|
1226
|
+
cancelAnimationFrame(rafHandle);
|
|
1227
|
+
};
|
|
1228
|
+
globalThis.setTimeout = setTimeoutPolyfill;
|
|
1229
|
+
globalThis.clearTimeout = clearTimeoutPolyfill;
|
|
51
1230
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
1231
|
+
|
|
1232
|
+
// ../../node_modules/react-native-worklets/lib/module/synchronizableUnpacker.js
|
|
1233
|
+
function __installUnpacker() {
|
|
1234
|
+
const serializer = !globalThis._WORKLET || globalThis._WORKLETS_BUNDLE_MODE ? (value, _) => createSerializable(value) : globalThis._createSerializable;
|
|
1235
|
+
function synchronizableUnpacker(synchronizableRef) {
|
|
1236
|
+
const synchronizable = synchronizableRef;
|
|
1237
|
+
const proxy = globalThis.__workletsModuleProxy;
|
|
1238
|
+
synchronizable.__synchronizableRef = true;
|
|
1239
|
+
synchronizable.getDirty = () => {
|
|
1240
|
+
return proxy.synchronizableGetDirty(synchronizable);
|
|
1241
|
+
};
|
|
1242
|
+
synchronizable.getBlocking = () => {
|
|
1243
|
+
return proxy.synchronizableGetBlocking(synchronizable);
|
|
1244
|
+
};
|
|
1245
|
+
synchronizable.setBlocking = (valueOrFunction) => {
|
|
1246
|
+
let newValue;
|
|
1247
|
+
if (typeof valueOrFunction === "function") {
|
|
1248
|
+
const func = valueOrFunction;
|
|
1249
|
+
synchronizable.lock();
|
|
1250
|
+
const prev = synchronizable.getBlocking();
|
|
1251
|
+
newValue = func(prev);
|
|
1252
|
+
proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, void 0));
|
|
1253
|
+
synchronizable.unlock();
|
|
1254
|
+
} else {
|
|
1255
|
+
const value = valueOrFunction;
|
|
1256
|
+
newValue = value;
|
|
1257
|
+
proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, void 0));
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
1260
|
+
synchronizable.lock = () => {
|
|
1261
|
+
proxy.synchronizableLock(synchronizable);
|
|
1262
|
+
};
|
|
1263
|
+
synchronizable.unlock = () => {
|
|
1264
|
+
proxy.synchronizableUnlock(synchronizable);
|
|
1265
|
+
};
|
|
1266
|
+
return synchronizable;
|
|
1267
|
+
}
|
|
1268
|
+
globalThis.__synchronizableUnpacker = synchronizableUnpacker;
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
// ../../node_modules/react-native-worklets/lib/module/initializers.js
|
|
1272
|
+
var capturableConsole;
|
|
1273
|
+
function getMemorySafeCapturableConsole() {
|
|
1274
|
+
if (capturableConsole) {
|
|
1275
|
+
return capturableConsole;
|
|
1276
|
+
}
|
|
1277
|
+
const consoleCopy = Object.fromEntries(Object.entries(console).map(([methodName, method]) => {
|
|
1278
|
+
const methodWrapper = function methodWrapper2(...args) {
|
|
1279
|
+
return method(...args);
|
|
1280
|
+
};
|
|
1281
|
+
if (method.name) {
|
|
1282
|
+
Object.defineProperty(methodWrapper, "name", {
|
|
1283
|
+
value: method.name,
|
|
1284
|
+
writable: false
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
return [methodName, methodWrapper];
|
|
1288
|
+
}));
|
|
1289
|
+
capturableConsole = consoleCopy;
|
|
1290
|
+
return consoleCopy;
|
|
1291
|
+
}
|
|
1292
|
+
function setupConsole(boundCapturableConsole) {
|
|
1293
|
+
"worklet";
|
|
1294
|
+
globalThis.console = {
|
|
1295
|
+
assert: runOnJS(boundCapturableConsole.assert),
|
|
1296
|
+
debug: runOnJS(boundCapturableConsole.debug),
|
|
1297
|
+
log: runOnJS(boundCapturableConsole.log),
|
|
1298
|
+
warn: runOnJS(boundCapturableConsole.warn),
|
|
1299
|
+
error: runOnJS(boundCapturableConsole.error),
|
|
1300
|
+
info: runOnJS(boundCapturableConsole.info)
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
var initialized = false;
|
|
1304
|
+
function init() {
|
|
1305
|
+
if (initialized) {
|
|
1306
|
+
return;
|
|
1307
|
+
}
|
|
1308
|
+
initialized = true;
|
|
1309
|
+
if (globalThis.__RUNTIME_KIND === void 0) {
|
|
1310
|
+
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
|
|
1311
|
+
}
|
|
1312
|
+
initializeRuntime();
|
|
1313
|
+
if (SHOULD_BE_USE_WEB2) {
|
|
1314
|
+
initializeRuntimeOnWeb();
|
|
1315
|
+
}
|
|
1316
|
+
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
|
|
1317
|
+
initializeWorkletRuntime();
|
|
1318
|
+
} else {
|
|
1319
|
+
initializeRNRuntime();
|
|
1320
|
+
if (!SHOULD_BE_USE_WEB2) {
|
|
1321
|
+
installRNBindingsOnUIRuntime();
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
function initializeRuntime() {
|
|
1326
|
+
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
1327
|
+
globalThis.__valueUnpacker = bundleValueUnpacker;
|
|
1328
|
+
}
|
|
1329
|
+
__installUnpacker();
|
|
1330
|
+
}
|
|
1331
|
+
function initializeRNRuntime() {
|
|
1332
|
+
if (__DEV__) {
|
|
1333
|
+
const testWorklet = () => {
|
|
1334
|
+
"worklet";
|
|
1335
|
+
};
|
|
1336
|
+
if (!isWorkletFunction(testWorklet)) {
|
|
1337
|
+
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.`);
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
registerReportFatalRemoteError();
|
|
1341
|
+
}
|
|
1342
|
+
function initializeWorkletRuntime() {
|
|
1343
|
+
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
1344
|
+
setupCallGuard();
|
|
1345
|
+
if (__DEV__) {
|
|
1346
|
+
const Refresh = new Proxy({}, {
|
|
1347
|
+
get() {
|
|
1348
|
+
return () => {
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
});
|
|
1352
|
+
globalThis.__r.Refresh = Refresh;
|
|
1353
|
+
const modules = __require.getModules();
|
|
1354
|
+
const ReactNativeModuleId = __require.resolveWeak("react-native");
|
|
1355
|
+
const factory = function(_global, _require, _importDefault, _importAll, module, _exports, _dependencyMap) {
|
|
1356
|
+
module.exports = new Proxy({}, {
|
|
1357
|
+
get: function get(_target, prop) {
|
|
1358
|
+
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.`);
|
|
1359
|
+
return {
|
|
1360
|
+
get() {
|
|
1361
|
+
return void 0;
|
|
1362
|
+
}
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
});
|
|
1366
|
+
};
|
|
1367
|
+
const mod = {
|
|
1368
|
+
dependencyMap: [],
|
|
1369
|
+
factory,
|
|
1370
|
+
hasError: false,
|
|
1371
|
+
importedAll: {},
|
|
1372
|
+
importedDefault: {},
|
|
1373
|
+
isInitialized: false,
|
|
1374
|
+
publicModule: {
|
|
1375
|
+
exports: {}
|
|
1376
|
+
}
|
|
1377
|
+
};
|
|
1378
|
+
modules.set(ReactNativeModuleId, mod);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
function initializeRuntimeOnWeb() {
|
|
1383
|
+
globalThis._WORKLET = false;
|
|
1384
|
+
globalThis._log = console.log;
|
|
1385
|
+
globalThis._getAnimationTimestamp = () => performance.now();
|
|
1386
|
+
if (IS_JEST2) {
|
|
1387
|
+
globalThis.requestAnimationFrame = mockedRequestAnimationFrame;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
function installRNBindingsOnUIRuntime() {
|
|
1391
|
+
if (!WorkletsModule) {
|
|
1392
|
+
throw new WorkletsError("Worklets are trying to initialize the UI runtime without a valid WorkletsModule");
|
|
1393
|
+
}
|
|
1394
|
+
const runtimeBoundCapturableConsole = getMemorySafeCapturableConsole();
|
|
1395
|
+
if (!globalThis._WORKLETS_BUNDLE_MODE) {
|
|
1396
|
+
executeOnUIRuntimeSync(setupCallGuard)();
|
|
1397
|
+
executeOnUIRuntimeSync(registerWorkletsError)();
|
|
1398
|
+
}
|
|
1399
|
+
executeOnUIRuntimeSync(() => {
|
|
1400
|
+
"worklet";
|
|
1401
|
+
setupConsole(runtimeBoundCapturableConsole);
|
|
1402
|
+
setupMicrotasks();
|
|
1403
|
+
setupRequestAnimationFrame();
|
|
1404
|
+
setupSetTimeout();
|
|
1405
|
+
setupSetImmediate();
|
|
1406
|
+
setupSetInterval();
|
|
1407
|
+
})();
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
// ../../node_modules/react-native-worklets/lib/module/workletRuntimeEntry.js
|
|
1411
|
+
function bundleModeInit() {
|
|
1412
|
+
if (SHOULD_BE_USE_WEB2) {
|
|
1413
|
+
return;
|
|
1414
|
+
}
|
|
1415
|
+
globalThis._WORKLETS_BUNDLE_MODE = true;
|
|
1416
|
+
const runtimeKind = globalThis.__RUNTIME_KIND;
|
|
1417
|
+
if (runtimeKind && runtimeKind !== RuntimeKind.ReactNative) {
|
|
1418
|
+
init();
|
|
1419
|
+
throw new WorkletsError("Worklets initialized successfully");
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
bundleModeInit();
|
|
1423
|
+
|
|
1424
|
+
// ../../node_modules/react-native-worklets/lib/module/featureFlags/index.js
|
|
1425
|
+
var DynamicFlags = {
|
|
1426
|
+
EXAMPLE_DYNAMIC_FLAG: true,
|
|
1427
|
+
init() {
|
|
1428
|
+
Object.keys(DynamicFlags).forEach((key) => {
|
|
1429
|
+
if (key !== "init" && key !== "setFlag") {
|
|
1430
|
+
WorkletsModule.setDynamicFeatureFlag(key, DynamicFlags[key]);
|
|
1431
|
+
}
|
|
1432
|
+
});
|
|
1433
|
+
},
|
|
1434
|
+
setFlag(name, value) {
|
|
1435
|
+
if (name in DynamicFlags) {
|
|
1436
|
+
DynamicFlags[name] = value;
|
|
1437
|
+
WorkletsModule.setDynamicFeatureFlag(name, value);
|
|
1438
|
+
} else {
|
|
1439
|
+
logger.warn(`The feature flag: '${name}' no longer exists, you can safely remove invocation of \`setDynamicFeatureFlag('${name}')\` from your code.`);
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1443
|
+
DynamicFlags.init();
|
|
1444
|
+
|
|
1445
|
+
// ../../node_modules/react-native-worklets/lib/module/index.js
|
|
1446
|
+
init();
|
|
1447
|
+
if (globalThis._ALWAYS_FALSE) {
|
|
1448
|
+
bundleModeInit();
|
|
55
1449
|
}
|
|
1450
|
+
|
|
1451
|
+
// src/transitions/easing.ts
|
|
56
1452
|
function ensureWorkletEasing(easing) {
|
|
57
1453
|
if (!easing) return void 0;
|
|
58
|
-
if (
|
|
1454
|
+
if (isWorkletFunction(easing)) return easing;
|
|
59
1455
|
const wrapped = (t) => {
|
|
60
1456
|
"worklet";
|
|
61
1457
|
return easing(t);
|
|
@@ -63,13 +1459,12 @@ function ensureWorkletEasing(easing) {
|
|
|
63
1459
|
return wrapped;
|
|
64
1460
|
}
|
|
65
1461
|
|
|
66
|
-
// src/transitions/
|
|
1462
|
+
// src/transitions/spring.ts
|
|
67
1463
|
var DEFAULT_SPRING = {
|
|
68
1464
|
tension: 170,
|
|
69
1465
|
friction: 26,
|
|
70
1466
|
mass: 1
|
|
71
1467
|
};
|
|
72
|
-
var DEFAULT_TIMING_DURATION = 250;
|
|
73
1468
|
function springToReanimated(t) {
|
|
74
1469
|
return {
|
|
75
1470
|
stiffness: t.tension ?? DEFAULT_SPRING.tension,
|
|
@@ -80,6 +1475,33 @@ function springToReanimated(t) {
|
|
|
80
1475
|
restDisplacementThreshold: t.restDisplacementThreshold
|
|
81
1476
|
};
|
|
82
1477
|
}
|
|
1478
|
+
|
|
1479
|
+
// src/layout/resolveLayout.ts
|
|
1480
|
+
function resolveLayoutTransition(layout) {
|
|
1481
|
+
if (!layout) return void 0;
|
|
1482
|
+
const cfg = layout === true ? { type: "spring" } : layout;
|
|
1483
|
+
if (cfg.type === "no-animation") return void 0;
|
|
1484
|
+
if (cfg.type === "timing") {
|
|
1485
|
+
let builder2 = Animated.LinearTransition.duration(cfg.duration ?? 300);
|
|
1486
|
+
const easing = ensureWorkletEasing(cfg.easing);
|
|
1487
|
+
if (easing) builder2 = builder2.easing(easing);
|
|
1488
|
+
if (cfg.delay) builder2 = builder2.delay(cfg.delay);
|
|
1489
|
+
return builder2;
|
|
1490
|
+
}
|
|
1491
|
+
const spring = cfg.type === "decay" ? { type: "spring" } : cfg;
|
|
1492
|
+
const { stiffness, damping, mass } = springToReanimated({
|
|
1493
|
+
...DEFAULT_SPRING,
|
|
1494
|
+
...spring
|
|
1495
|
+
});
|
|
1496
|
+
let builder = Animated.LinearTransition.springify().stiffness(stiffness).damping(damping).mass(mass);
|
|
1497
|
+
if ("delay" in spring && spring.delay) builder = builder.delay(spring.delay);
|
|
1498
|
+
return builder;
|
|
1499
|
+
}
|
|
1500
|
+
var PresenceContext = react.createContext(null);
|
|
1501
|
+
function usePresence() {
|
|
1502
|
+
return react.useContext(PresenceContext);
|
|
1503
|
+
}
|
|
1504
|
+
var DEFAULT_TIMING_DURATION = 250;
|
|
83
1505
|
function buildSpring(cfg, toValue, cb) {
|
|
84
1506
|
return Animated.withSpring(toValue, springToReanimated(cfg), cb);
|
|
85
1507
|
}
|
|
@@ -184,14 +1606,96 @@ function mergeTransition(base, override) {
|
|
|
184
1606
|
}
|
|
185
1607
|
return { ...base ?? { type: "spring" }, ...override };
|
|
186
1608
|
}
|
|
1609
|
+
|
|
1610
|
+
// src/transitions/keys.ts
|
|
1611
|
+
var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
1612
|
+
"type",
|
|
1613
|
+
"tension",
|
|
1614
|
+
"friction",
|
|
1615
|
+
"mass",
|
|
1616
|
+
"velocity",
|
|
1617
|
+
"restSpeedThreshold",
|
|
1618
|
+
"restDisplacementThreshold",
|
|
1619
|
+
"duration",
|
|
1620
|
+
"easing",
|
|
1621
|
+
"delay",
|
|
1622
|
+
"repeat",
|
|
1623
|
+
"deceleration",
|
|
1624
|
+
"clamp"
|
|
1625
|
+
]);
|
|
1626
|
+
function isTopLevelTransition(t) {
|
|
1627
|
+
if (t === null || typeof t !== "object") return false;
|
|
1628
|
+
const keys = Object.keys(t);
|
|
1629
|
+
if (keys.length === 0) return false;
|
|
1630
|
+
return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
// src/transitions/sig.ts
|
|
1634
|
+
function stableSig(value) {
|
|
1635
|
+
if (value === void 0) return "";
|
|
1636
|
+
try {
|
|
1637
|
+
return stableStringify(value);
|
|
1638
|
+
} catch {
|
|
1639
|
+
return String(value);
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
function stableStringify(v) {
|
|
1643
|
+
if (v === null || typeof v !== "object") {
|
|
1644
|
+
if (typeof v === "function" || v === void 0) return "null";
|
|
1645
|
+
return JSON.stringify(v);
|
|
1646
|
+
}
|
|
1647
|
+
if (Array.isArray(v)) {
|
|
1648
|
+
return "[" + v.map(stableStringify).join(",") + "]";
|
|
1649
|
+
}
|
|
1650
|
+
const obj = v;
|
|
1651
|
+
const keys = Object.keys(obj).sort();
|
|
1652
|
+
return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
// src/motion/installCheck.ts
|
|
1656
|
+
var alreadyChecked = false;
|
|
1657
|
+
function ensureReanimatedInstalled() {
|
|
1658
|
+
if (!__DEV__ || alreadyChecked) return;
|
|
1659
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV === "test") {
|
|
1660
|
+
return;
|
|
1661
|
+
}
|
|
1662
|
+
alreadyChecked = true;
|
|
1663
|
+
let version;
|
|
1664
|
+
try {
|
|
1665
|
+
const pkg = __require("react-native-reanimated/package.json");
|
|
1666
|
+
version = pkg.version;
|
|
1667
|
+
} catch {
|
|
1668
|
+
}
|
|
1669
|
+
if (version) {
|
|
1670
|
+
const major = parseInt(version.split(".")[0] ?? "0", 10);
|
|
1671
|
+
if (major < 4) {
|
|
1672
|
+
console.error(
|
|
1673
|
+
`[inertia] react-native-reanimated v${version} is installed, but @onlynative/inertia requires v4.0.0 or later. Upgrade with \`pnpm add react-native-reanimated@^4\` (or your package manager's equivalent).`
|
|
1674
|
+
);
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
const probe = function probe2() {
|
|
1679
|
+
"worklet";
|
|
1680
|
+
return 0;
|
|
1681
|
+
};
|
|
1682
|
+
if (typeof probe.__workletHash !== "number") {
|
|
1683
|
+
console.error(
|
|
1684
|
+
`[inertia] The Reanimated worklets babel plugin is not configured. Add \`'react-native-worklets/plugin'\` as the LAST entry in the \`plugins\` array of your \`babel.config.js\`, then restart Metro with a fresh cache: \`npx expo start -c\` or \`npx react-native start --reset-cache\`.`
|
|
1685
|
+
);
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
187
1688
|
var TRANSFORM_KEYS = [
|
|
188
1689
|
"translateX",
|
|
189
1690
|
"translateY",
|
|
190
1691
|
"scale",
|
|
191
1692
|
"scaleX",
|
|
192
1693
|
"scaleY",
|
|
193
|
-
"rotate"
|
|
1694
|
+
"rotate",
|
|
1695
|
+
"rotateX",
|
|
1696
|
+
"rotateY"
|
|
194
1697
|
];
|
|
1698
|
+
var ROTATION_KEYS = /* @__PURE__ */ new Set(["rotate", "rotateX", "rotateY"]);
|
|
195
1699
|
var NUMERIC_TOP_LEVEL_KEYS = [
|
|
196
1700
|
"opacity",
|
|
197
1701
|
"width",
|
|
@@ -210,6 +1714,14 @@ var ALL_KEYS = [
|
|
|
210
1714
|
...COLOR_KEYS
|
|
211
1715
|
];
|
|
212
1716
|
var TRANSFORM_KEY_SET = new Set(TRANSFORM_KEYS);
|
|
1717
|
+
var COLOR_KEY_SET = new Set(COLOR_KEYS);
|
|
1718
|
+
var GESTURE_LAYER_NAMES = [
|
|
1719
|
+
"hovered",
|
|
1720
|
+
"focused",
|
|
1721
|
+
"focusVisible",
|
|
1722
|
+
"pressed"
|
|
1723
|
+
];
|
|
1724
|
+
var GESTURE_LAYER_NAME_SET = new Set(GESTURE_LAYER_NAMES);
|
|
213
1725
|
var EXITING_POINTER_EVENTS_STYLE = { pointerEvents: "none" };
|
|
214
1726
|
var DEFAULT_RESTING = {
|
|
215
1727
|
translateX: 0,
|
|
@@ -218,6 +1730,8 @@ var DEFAULT_RESTING = {
|
|
|
218
1730
|
scaleX: 1,
|
|
219
1731
|
scaleY: 1,
|
|
220
1732
|
rotate: 0,
|
|
1733
|
+
rotateX: 0,
|
|
1734
|
+
rotateY: 0,
|
|
221
1735
|
opacity: 1,
|
|
222
1736
|
width: 0,
|
|
223
1737
|
height: 0,
|
|
@@ -231,34 +1745,21 @@ var DEFAULT_RESTING = {
|
|
|
231
1745
|
color: "transparent",
|
|
232
1746
|
tintColor: "transparent"
|
|
233
1747
|
};
|
|
234
|
-
var TRANSITION_KEYS = /* @__PURE__ */ new Set([
|
|
235
|
-
"type",
|
|
236
|
-
"tension",
|
|
237
|
-
"friction",
|
|
238
|
-
"mass",
|
|
239
|
-
"velocity",
|
|
240
|
-
"restSpeedThreshold",
|
|
241
|
-
"restDisplacementThreshold",
|
|
242
|
-
"duration",
|
|
243
|
-
"easing",
|
|
244
|
-
"delay",
|
|
245
|
-
"repeat",
|
|
246
|
-
"deceleration",
|
|
247
|
-
"clamp"
|
|
248
|
-
]);
|
|
249
|
-
function isTopLevelTransition(t) {
|
|
250
|
-
if (t === null || typeof t !== "object") return false;
|
|
251
|
-
const keys = Object.keys(t);
|
|
252
|
-
if (keys.length === 0) return false;
|
|
253
|
-
return keys.every((k) => TRANSITION_KEYS.has(k));
|
|
254
|
-
}
|
|
255
1748
|
function transitionFor(prop, transition) {
|
|
256
1749
|
if (!transition) return void 0;
|
|
257
1750
|
if (isTopLevelTransition(transition)) return transition;
|
|
1751
|
+
if (GESTURE_LAYER_NAME_SET.has(prop)) return void 0;
|
|
258
1752
|
return transition[prop];
|
|
259
1753
|
}
|
|
1754
|
+
function gestureLayerTransitionFor(layer, transition) {
|
|
1755
|
+
if (!transition) return void 0;
|
|
1756
|
+
if (isTopLevelTransition(transition)) return transition;
|
|
1757
|
+
return transition[layer];
|
|
1758
|
+
}
|
|
260
1759
|
function createMotionComponent(Component) {
|
|
1760
|
+
ensureReanimatedInstalled();
|
|
261
1761
|
const AnimatedComponent = Animated__default.default.createAnimatedComponent(
|
|
1762
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
262
1763
|
Component
|
|
263
1764
|
);
|
|
264
1765
|
const Motion = react.forwardRef(function Motion2(props, ref) {
|
|
@@ -270,6 +1771,7 @@ function createMotionComponent(Component) {
|
|
|
270
1771
|
variants,
|
|
271
1772
|
controller,
|
|
272
1773
|
gesture,
|
|
1774
|
+
layout,
|
|
273
1775
|
onAnimationEnd,
|
|
274
1776
|
style,
|
|
275
1777
|
...rest
|
|
@@ -337,13 +1839,19 @@ function createMotionComponent(Component) {
|
|
|
337
1839
|
}
|
|
338
1840
|
return initialRecord?.[key] ?? restValue(animateRecord[key]) ?? DEFAULT_RESTING[key];
|
|
339
1841
|
});
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
1842
|
+
const pressedProgress = Animated.useSharedValue(0);
|
|
1843
|
+
const focusedProgress = Animated.useSharedValue(0);
|
|
1844
|
+
const focusVisibleProgress = Animated.useSharedValue(0);
|
|
1845
|
+
const hoveredProgress = Animated.useSharedValue(0);
|
|
1846
|
+
const gestureSV = Animated.useSharedValue(
|
|
1847
|
+
resolveGestureLayers(gesture)
|
|
1848
|
+
);
|
|
1849
|
+
const gestureTargetsSig = stableSig(gesture);
|
|
1850
|
+
react.useEffect(() => {
|
|
1851
|
+
gestureSV.value = resolveGestureLayers(gesture);
|
|
1852
|
+
}, [gestureTargetsSig]);
|
|
1853
|
+
const baseRecord = isExiting && exitRecord ? { ...animateRecord, ...exitRecord } : animateRecord;
|
|
1854
|
+
const baseSig = stableSig(baseRecord) + (isExiting ? "|exit" : "") + (shouldReduceMotion ? "|rm" : "");
|
|
347
1855
|
const transitionSig = stableSig(transition);
|
|
348
1856
|
const safeToRemoveRef = react.useRef(void 0);
|
|
349
1857
|
safeToRemoveRef.current = presence?.safeToRemove;
|
|
@@ -364,13 +1872,13 @@ function createMotionComponent(Component) {
|
|
|
364
1872
|
};
|
|
365
1873
|
let transformPending = 0;
|
|
366
1874
|
for (const k of ALL_KEYS) {
|
|
367
|
-
if (TRANSFORM_KEY_SET.has(k) &&
|
|
1875
|
+
if (TRANSFORM_KEY_SET.has(k) && baseRecord[k] !== void 0) {
|
|
368
1876
|
transformPending++;
|
|
369
1877
|
}
|
|
370
1878
|
}
|
|
371
1879
|
const transformGroup = transformPending > 0 ? { remaining: transformPending } : void 0;
|
|
372
1880
|
for (const key of ALL_KEYS) {
|
|
373
|
-
const target =
|
|
1881
|
+
const target = baseRecord[key];
|
|
374
1882
|
if (target === void 0) continue;
|
|
375
1883
|
const cfg = shouldReduceMotion ? { type: "no-animation" } : transitionFor(key, transition);
|
|
376
1884
|
if (isExiting) pending++;
|
|
@@ -395,17 +1903,79 @@ function createMotionComponent(Component) {
|
|
|
395
1903
|
if (isExiting && pending === 0) {
|
|
396
1904
|
safeToRemoveRef.current?.();
|
|
397
1905
|
}
|
|
398
|
-
}, [
|
|
1906
|
+
}, [baseSig, transitionSig]);
|
|
1907
|
+
useGestureLayerProgress(
|
|
1908
|
+
pressedProgress,
|
|
1909
|
+
pressed,
|
|
1910
|
+
gesture?.pressed != null,
|
|
1911
|
+
"pressed",
|
|
1912
|
+
transition,
|
|
1913
|
+
isExiting,
|
|
1914
|
+
shouldReduceMotion
|
|
1915
|
+
);
|
|
1916
|
+
useGestureLayerProgress(
|
|
1917
|
+
focusedProgress,
|
|
1918
|
+
focused,
|
|
1919
|
+
gesture?.focused != null,
|
|
1920
|
+
"focused",
|
|
1921
|
+
transition,
|
|
1922
|
+
isExiting,
|
|
1923
|
+
shouldReduceMotion
|
|
1924
|
+
);
|
|
1925
|
+
useGestureLayerProgress(
|
|
1926
|
+
focusVisibleProgress,
|
|
1927
|
+
focusVisible,
|
|
1928
|
+
gesture?.focusVisible != null,
|
|
1929
|
+
"focusVisible",
|
|
1930
|
+
transition,
|
|
1931
|
+
isExiting,
|
|
1932
|
+
shouldReduceMotion
|
|
1933
|
+
);
|
|
1934
|
+
useGestureLayerProgress(
|
|
1935
|
+
hoveredProgress,
|
|
1936
|
+
hovered,
|
|
1937
|
+
gesture?.hovered != null,
|
|
1938
|
+
"hovered",
|
|
1939
|
+
transition,
|
|
1940
|
+
isExiting,
|
|
1941
|
+
shouldReduceMotion
|
|
1942
|
+
);
|
|
399
1943
|
const animatedStyle = Animated.useAnimatedStyle(() => {
|
|
400
1944
|
const activeKeys = activeKeysRef.current;
|
|
401
1945
|
const hasTransform = hasTransformRef.current;
|
|
402
1946
|
const out = {};
|
|
403
1947
|
const transform = [];
|
|
1948
|
+
const ph = hoveredProgress.value;
|
|
1949
|
+
const pf = focusedProgress.value;
|
|
1950
|
+
const pfv = focusVisibleProgress.value;
|
|
1951
|
+
const pp = pressedProgress.value;
|
|
1952
|
+
const layers = gestureSV.value;
|
|
1953
|
+
const hoveredLayer = layers ? layers.hovered : null;
|
|
1954
|
+
const focusedLayer = layers ? layers.focused : null;
|
|
1955
|
+
const focusVisibleLayer = layers ? layers.focusVisible : null;
|
|
1956
|
+
const pressedLayer = layers ? layers.pressed : null;
|
|
404
1957
|
for (const key of activeKeys) {
|
|
405
|
-
|
|
1958
|
+
let v = sharedValues[key].value;
|
|
1959
|
+
const isColor = COLOR_KEY_SET.has(key);
|
|
1960
|
+
if (hoveredLayer && ph > 0 && hoveredLayer[key] !== void 0) {
|
|
1961
|
+
const t = hoveredLayer[key];
|
|
1962
|
+
v = isColor ? Animated.interpolateColor(ph, [0, 1], [v, t]) : v + (t - v) * ph;
|
|
1963
|
+
}
|
|
1964
|
+
if (focusedLayer && pf > 0 && focusedLayer[key] !== void 0) {
|
|
1965
|
+
const t = focusedLayer[key];
|
|
1966
|
+
v = isColor ? Animated.interpolateColor(pf, [0, 1], [v, t]) : v + (t - v) * pf;
|
|
1967
|
+
}
|
|
1968
|
+
if (focusVisibleLayer && pfv > 0 && focusVisibleLayer[key] !== void 0) {
|
|
1969
|
+
const t = focusVisibleLayer[key];
|
|
1970
|
+
v = isColor ? Animated.interpolateColor(pfv, [0, 1], [v, t]) : v + (t - v) * pfv;
|
|
1971
|
+
}
|
|
1972
|
+
if (pressedLayer && pp > 0 && pressedLayer[key] !== void 0) {
|
|
1973
|
+
const t = pressedLayer[key];
|
|
1974
|
+
v = isColor ? Animated.interpolateColor(pp, [0, 1], [v, t]) : v + (t - v) * pp;
|
|
1975
|
+
}
|
|
406
1976
|
if (TRANSFORM_KEY_SET.has(key)) {
|
|
407
1977
|
transform.push(
|
|
408
|
-
key
|
|
1978
|
+
ROTATION_KEYS.has(key) ? { [key]: `${v}deg` } : { [key]: v }
|
|
409
1979
|
);
|
|
410
1980
|
} else {
|
|
411
1981
|
out[key] = v;
|
|
@@ -426,12 +1996,19 @@ function createMotionComponent(Component) {
|
|
|
426
1996
|
setFocusVisible,
|
|
427
1997
|
setHovered
|
|
428
1998
|
);
|
|
1999
|
+
const layoutSig = stableSig(layout);
|
|
2000
|
+
const layoutTransition = react.useMemo(
|
|
2001
|
+
() => shouldReduceMotion ? void 0 : resolveLayoutTransition(layout),
|
|
2002
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2003
|
+
[layoutSig, shouldReduceMotion]
|
|
2004
|
+
);
|
|
429
2005
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
430
2006
|
AnimatedComponent,
|
|
431
2007
|
{
|
|
432
2008
|
ref,
|
|
433
2009
|
...rest,
|
|
434
2010
|
...gestureHandlers,
|
|
2011
|
+
layout: layoutTransition,
|
|
435
2012
|
style: mergedStyle
|
|
436
2013
|
}
|
|
437
2014
|
);
|
|
@@ -439,23 +2016,25 @@ function createMotionComponent(Component) {
|
|
|
439
2016
|
Motion.displayName = `Motion(${Component.displayName ?? Component.name ?? "Component"})`;
|
|
440
2017
|
return Motion;
|
|
441
2018
|
}
|
|
442
|
-
function useAnimatableSharedValues(
|
|
443
|
-
const translateX = Animated.useSharedValue(
|
|
444
|
-
const translateY = Animated.useSharedValue(
|
|
445
|
-
const scale = Animated.useSharedValue(
|
|
446
|
-
const scaleX = Animated.useSharedValue(
|
|
447
|
-
const scaleY = Animated.useSharedValue(
|
|
448
|
-
const rotate = Animated.useSharedValue(
|
|
449
|
-
const
|
|
450
|
-
const
|
|
451
|
-
const
|
|
452
|
-
const
|
|
2019
|
+
function useAnimatableSharedValues(init2) {
|
|
2020
|
+
const translateX = Animated.useSharedValue(init2("translateX"));
|
|
2021
|
+
const translateY = Animated.useSharedValue(init2("translateY"));
|
|
2022
|
+
const scale = Animated.useSharedValue(init2("scale"));
|
|
2023
|
+
const scaleX = Animated.useSharedValue(init2("scaleX"));
|
|
2024
|
+
const scaleY = Animated.useSharedValue(init2("scaleY"));
|
|
2025
|
+
const rotate = Animated.useSharedValue(init2("rotate"));
|
|
2026
|
+
const rotateX = Animated.useSharedValue(init2("rotateX"));
|
|
2027
|
+
const rotateY = Animated.useSharedValue(init2("rotateY"));
|
|
2028
|
+
const opacity = Animated.useSharedValue(init2("opacity"));
|
|
2029
|
+
const width = Animated.useSharedValue(init2("width"));
|
|
2030
|
+
const height = Animated.useSharedValue(init2("height"));
|
|
2031
|
+
const borderRadius = Animated.useSharedValue(init2("borderRadius"));
|
|
453
2032
|
const backgroundColor = Animated.useSharedValue(
|
|
454
|
-
|
|
2033
|
+
init2("backgroundColor")
|
|
455
2034
|
);
|
|
456
|
-
const borderColor = Animated.useSharedValue(
|
|
457
|
-
const color = Animated.useSharedValue(
|
|
458
|
-
const tintColor = Animated.useSharedValue(
|
|
2035
|
+
const borderColor = Animated.useSharedValue(init2("borderColor"));
|
|
2036
|
+
const color = Animated.useSharedValue(init2("color"));
|
|
2037
|
+
const tintColor = Animated.useSharedValue(init2("tintColor"));
|
|
459
2038
|
const ref = react.useRef(null);
|
|
460
2039
|
if (ref.current === null) {
|
|
461
2040
|
ref.current = {
|
|
@@ -465,6 +2044,8 @@ function useAnimatableSharedValues(init) {
|
|
|
465
2044
|
scaleX,
|
|
466
2045
|
scaleY,
|
|
467
2046
|
rotate,
|
|
2047
|
+
rotateX,
|
|
2048
|
+
rotateY,
|
|
468
2049
|
opacity,
|
|
469
2050
|
width,
|
|
470
2051
|
height,
|
|
@@ -601,72 +2182,41 @@ function restValue(v) {
|
|
|
601
2182
|
}
|
|
602
2183
|
return void 0;
|
|
603
2184
|
}
|
|
604
|
-
function
|
|
605
|
-
if (
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
return "[" + v.map(stableStringify).join(",") + "]";
|
|
2185
|
+
function resolveGestureLayers(gesture) {
|
|
2186
|
+
if (!gesture) return null;
|
|
2187
|
+
const out = {};
|
|
2188
|
+
for (const layer of GESTURE_LAYER_NAMES) {
|
|
2189
|
+
const subState = gesture[layer];
|
|
2190
|
+
if (!subState) continue;
|
|
2191
|
+
const resolved = {};
|
|
2192
|
+
for (const key of ALL_KEYS) {
|
|
2193
|
+
const raw = subState[key];
|
|
2194
|
+
if (raw === void 0) continue;
|
|
2195
|
+
const t = targetEndValue(raw);
|
|
2196
|
+
if (t !== void 0) resolved[key] = t;
|
|
2197
|
+
}
|
|
2198
|
+
out[layer] = resolved;
|
|
619
2199
|
}
|
|
620
|
-
|
|
621
|
-
const keys = Object.keys(obj).sort();
|
|
622
|
-
return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
|
|
2200
|
+
return out;
|
|
623
2201
|
}
|
|
624
|
-
function
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
gesture.focused,
|
|
632
|
-
gesture.focusVisible,
|
|
633
|
-
gesture.pressed
|
|
634
|
-
];
|
|
635
|
-
for (const sub of subStates) {
|
|
636
|
-
if (!sub) continue;
|
|
637
|
-
for (const k of ALL_KEYS) {
|
|
638
|
-
if (k in sub && !(k in merged)) {
|
|
639
|
-
merged[k] = DEFAULT_RESTING[k];
|
|
640
|
-
}
|
|
2202
|
+
function useGestureLayerProgress(progress, active, declared, layer, transition, isExiting, shouldReduceMotion) {
|
|
2203
|
+
const layerCfgSig = stableSig(gestureLayerTransitionFor(layer, transition));
|
|
2204
|
+
react.useEffect(() => {
|
|
2205
|
+
if (!declared) return;
|
|
2206
|
+
if (isExiting) {
|
|
2207
|
+
progress.value = 0;
|
|
2208
|
+
return;
|
|
641
2209
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
gesture.hovered
|
|
647
|
-
);
|
|
648
|
-
}
|
|
649
|
-
if (active.focused && gesture.focused) {
|
|
650
|
-
Object.assign(
|
|
651
|
-
merged,
|
|
652
|
-
gesture.focused
|
|
653
|
-
);
|
|
654
|
-
}
|
|
655
|
-
if (active.focusVisible && gesture.focusVisible) {
|
|
656
|
-
Object.assign(
|
|
657
|
-
merged,
|
|
658
|
-
gesture.focusVisible
|
|
659
|
-
);
|
|
660
|
-
}
|
|
661
|
-
if (active.pressed && gesture.pressed) {
|
|
662
|
-
Object.assign(
|
|
663
|
-
merged,
|
|
664
|
-
gesture.pressed
|
|
665
|
-
);
|
|
666
|
-
}
|
|
667
|
-
return merged;
|
|
2210
|
+
const target = active ? 1 : 0;
|
|
2211
|
+
const cfg = shouldReduceMotion ? { type: "no-animation" } : gestureLayerTransitionFor(layer, transition) ?? { type: "spring" };
|
|
2212
|
+
progress.value = resolveTransition(cfg, target);
|
|
2213
|
+
}, [active, declared, isExiting, shouldReduceMotion, layerCfgSig]);
|
|
668
2214
|
}
|
|
669
2215
|
function useGestureHandlers(gesture, rest, setPressed, setFocused, setFocusVisible, setHovered) {
|
|
2216
|
+
const hasPressed = gesture?.pressed ? 1 : 0;
|
|
2217
|
+
const hasFocused = gesture?.focused ? 1 : 0;
|
|
2218
|
+
const hasFocusVisible = gesture?.focusVisible ? 1 : 0;
|
|
2219
|
+
const hasHovered = gesture?.hovered ? 1 : 0;
|
|
670
2220
|
return react.useMemo(() => {
|
|
671
2221
|
if (!gesture) return {};
|
|
672
2222
|
const handlers = {};
|
|
@@ -699,10 +2249,10 @@ function useGestureHandlers(gesture, rest, setPressed, setFocused, setFocusVisib
|
|
|
699
2249
|
}
|
|
700
2250
|
return handlers;
|
|
701
2251
|
}, [
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
2252
|
+
hasPressed,
|
|
2253
|
+
hasFocused,
|
|
2254
|
+
hasFocusVisible,
|
|
2255
|
+
hasHovered,
|
|
706
2256
|
rest.onTouchStart,
|
|
707
2257
|
rest.onTouchEnd,
|
|
708
2258
|
rest.onTouchCancel,
|