react-native-worklets 0.8.2 → 0.8.3
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/lib/module/WorkletsModule/NativeWorklets.js +4 -0
- package/lib/module/WorkletsModule/NativeWorklets.js.map +1 -0
- package/lib/module/WorkletsModule/NativeWorklets.native.js +152 -0
- package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -0
- package/lib/module/WorkletsModule/workletsModuleProxy.js +4 -0
- package/lib/module/WorkletsModule/workletsModuleProxy.js.map +1 -0
- package/lib/module/bundleMode/metroOverrides.native.js +115 -0
- package/lib/module/bundleMode/metroOverrides.native.js.map +1 -0
- package/lib/module/bundleMode/network.native.js +41 -0
- package/lib/module/bundleMode/network.native.js.map +1 -0
- package/lib/module/callGuard.native.js +30 -0
- package/lib/module/callGuard.native.js.map +1 -0
- package/lib/module/debug/WorkletsError.js +12 -0
- package/lib/module/debug/WorkletsError.js.map +1 -0
- package/lib/module/debug/WorkletsError.native.js +27 -0
- package/lib/module/debug/WorkletsError.native.js.map +1 -0
- package/lib/module/debug/checkCppVersion.js +30 -0
- package/lib/module/debug/checkCppVersion.js.map +1 -0
- package/lib/module/debug/errors.native.js +69 -0
- package/lib/module/debug/errors.native.js.map +1 -0
- package/lib/module/debug/jsVersion.js +9 -0
- package/lib/module/debug/jsVersion.js.map +1 -0
- package/lib/module/debug/logger.js +15 -0
- package/lib/module/debug/logger.js.map +1 -0
- package/lib/module/debug/types.js +2 -0
- package/lib/module/debug/types.js.map +1 -0
- package/lib/module/deprecated.js +27 -0
- package/lib/module/deprecated.js.map +1 -0
- package/lib/module/featureFlags/featureFlags.js +12 -0
- package/lib/module/featureFlags/featureFlags.js.map +1 -0
- package/lib/module/featureFlags/featureFlags.native.js +51 -0
- package/lib/module/featureFlags/featureFlags.native.js.map +1 -0
- package/lib/module/featureFlags/staticFlags.json +5 -0
- package/lib/module/featureFlags/types.js +13 -0
- package/lib/module/featureFlags/types.js.map +1 -0
- package/lib/module/guardImplementation.native.js +17 -0
- package/lib/module/guardImplementation.native.js.map +1 -0
- package/lib/module/index.js +28 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/initializers/initializers.js +24 -0
- package/lib/module/initializers/initializers.js.map +1 -0
- package/lib/module/initializers/initializers.native.js +174 -0
- package/lib/module/initializers/initializers.native.js.map +1 -0
- package/lib/module/initializers/workletRuntimeEntry.js +6 -0
- package/lib/module/initializers/workletRuntimeEntry.js.map +1 -0
- package/lib/module/initializers/workletRuntimeEntry.native.js +37 -0
- package/lib/module/initializers/workletRuntimeEntry.native.js.map +1 -0
- package/lib/module/memory/bundleUnpacker.native.js +47 -0
- package/lib/module/memory/bundleUnpacker.native.js.map +1 -0
- package/lib/module/memory/customSerializableUnpacker.native.js +18 -0
- package/lib/module/memory/customSerializableUnpacker.native.js.map +1 -0
- package/lib/module/memory/isShareable.js +8 -0
- package/lib/module/memory/isShareable.js.map +1 -0
- package/lib/module/memory/isSynchronizable.js +8 -0
- package/lib/module/memory/isSynchronizable.js.map +1 -0
- package/lib/module/memory/serializable.js +18 -0
- package/lib/module/memory/serializable.js.map +1 -0
- package/lib/module/memory/serializable.native.js +642 -0
- package/lib/module/memory/serializable.native.js.map +1 -0
- package/lib/module/memory/serializableMappingCache.js +11 -0
- package/lib/module/memory/serializableMappingCache.js.map +1 -0
- package/lib/module/memory/serializableMappingCache.native.js +29 -0
- package/lib/module/memory/serializableMappingCache.native.js.map +1 -0
- package/lib/module/memory/shareable.js +28 -0
- package/lib/module/memory/shareable.js.map +1 -0
- package/lib/module/memory/shareable.native.js +53 -0
- package/lib/module/memory/shareable.native.js.map +1 -0
- package/lib/module/memory/shareableGuestUnpacker.native.js +96 -0
- package/lib/module/memory/shareableGuestUnpacker.native.js.map +1 -0
- package/lib/module/memory/shareableHostUnpacker.native.js +18 -0
- package/lib/module/memory/shareableHostUnpacker.native.js.map +1 -0
- package/lib/module/memory/synchronizable.js +7 -0
- package/lib/module/memory/synchronizable.js.map +1 -0
- package/lib/module/memory/synchronizable.native.js +9 -0
- package/lib/module/memory/synchronizable.native.js.map +1 -0
- package/lib/module/memory/synchronizableUnpacker.native.js +42 -0
- package/lib/module/memory/synchronizableUnpacker.native.js.map +1 -0
- package/lib/module/memory/types.js +12 -0
- package/lib/module/memory/types.js.map +1 -0
- package/lib/module/memory/valueUnpacker.native.js +61 -0
- package/lib/module/memory/valueUnpacker.native.js.map +1 -0
- package/lib/module/mock.js +85 -0
- package/lib/module/mock.js.map +1 -0
- package/lib/module/platformChecker.js +8 -0
- package/lib/module/platformChecker.js.map +1 -0
- package/lib/module/platformChecker.native.js +4 -0
- package/lib/module/platformChecker.native.js.map +1 -0
- package/lib/module/privateGlobals.d.js +6 -0
- package/lib/module/privateGlobals.d.js.map +1 -0
- package/lib/module/runLoop/common/setImmediatePolyfill.js +15 -0
- package/lib/module/runLoop/common/setImmediatePolyfill.js.map +1 -0
- package/lib/module/runLoop/common/setIntervalPolyfill.js +26 -0
- package/lib/module/runLoop/common/setIntervalPolyfill.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js +10 -0
- package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +63 -0
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js +32 -0
- package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/index.js +19 -0
- package/lib/module/runLoop/workletRuntime/index.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js +11 -0
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +48 -0
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/setTimeout.js +28 -0
- package/lib/module/runLoop/workletRuntime/setTimeout.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/taskQueue.js +37 -0
- package/lib/module/runLoop/workletRuntime/taskQueue.js.map +1 -0
- package/lib/module/runtimeKind.js +92 -0
- package/lib/module/runtimeKind.js.map +1 -0
- package/lib/module/runtimes.js +33 -0
- package/lib/module/runtimes.js.map +1 -0
- package/lib/module/runtimes.native.js +331 -0
- package/lib/module/runtimes.native.js.map +1 -0
- package/lib/module/specs/NativeWorkletsModule.js +5 -0
- package/lib/module/specs/NativeWorkletsModule.js.map +1 -0
- package/lib/module/specs/index.js +10 -0
- package/lib/module/specs/index.js.map +1 -0
- package/lib/module/threads.js +61 -0
- package/lib/module/threads.js.map +1 -0
- package/lib/module/threads.native.js +290 -0
- package/lib/module/threads.native.js.map +1 -0
- package/lib/module/types.js +5 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/workletFunction.js +36 -0
- package/lib/module/workletFunction.js.map +1 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.d.ts +4 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.d.ts.map +1 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts +3 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -0
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +45 -0
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -0
- package/lib/typescript/bundleMode/metroOverrides.native.d.ts +28 -0
- package/lib/typescript/bundleMode/metroOverrides.native.d.ts.map +1 -0
- package/lib/typescript/bundleMode/network.native.d.ts +7 -0
- package/lib/typescript/bundleMode/network.native.d.ts.map +1 -0
- package/lib/typescript/callGuard.native.d.ts +4 -0
- package/lib/typescript/callGuard.native.d.ts.map +1 -0
- package/lib/typescript/debug/WorkletsError.d.ts +3 -0
- package/lib/typescript/debug/WorkletsError.d.ts.map +1 -0
- package/lib/typescript/debug/WorkletsError.native.d.ts +8 -0
- package/lib/typescript/debug/WorkletsError.native.d.ts.map +1 -0
- package/lib/typescript/debug/checkCppVersion.d.ts +3 -0
- package/lib/typescript/debug/checkCppVersion.d.ts.map +1 -0
- package/lib/typescript/debug/errors.native.d.ts +16 -0
- package/lib/typescript/debug/errors.native.d.ts.map +1 -0
- package/lib/typescript/debug/jsVersion.d.ts +7 -0
- package/lib/typescript/debug/jsVersion.d.ts.map +1 -0
- package/lib/typescript/debug/logger.d.ts +5 -0
- package/lib/typescript/debug/logger.d.ts.map +1 -0
- package/lib/typescript/debug/types.d.ts +9 -0
- package/lib/typescript/debug/types.d.ts.map +1 -0
- package/lib/typescript/deprecated.d.ts +19 -0
- package/lib/typescript/deprecated.d.ts.map +1 -0
- package/lib/typescript/featureFlags/featureFlags.d.ts +5 -0
- package/lib/typescript/featureFlags/featureFlags.d.ts.map +1 -0
- package/lib/typescript/featureFlags/featureFlags.native.d.ts +6 -0
- package/lib/typescript/featureFlags/featureFlags.native.d.ts.map +1 -0
- package/lib/typescript/featureFlags/types.d.ts +21 -0
- package/lib/typescript/featureFlags/types.d.ts.map +1 -0
- package/lib/typescript/guardImplementation.native.d.ts +2 -0
- package/lib/typescript/guardImplementation.native.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +17 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/initializers/initializers.d.ts +2 -0
- package/lib/typescript/initializers/initializers.d.ts.map +1 -0
- package/lib/typescript/initializers/initializers.native.d.ts +18 -0
- package/lib/typescript/initializers/initializers.native.d.ts.map +1 -0
- package/lib/typescript/initializers/workletRuntimeEntry.d.ts +2 -0
- package/lib/typescript/initializers/workletRuntimeEntry.d.ts.map +1 -0
- package/lib/typescript/initializers/workletRuntimeEntry.native.d.ts +14 -0
- package/lib/typescript/initializers/workletRuntimeEntry.native.d.ts.map +1 -0
- package/lib/typescript/memory/bundleUnpacker.native.d.ts +7 -0
- package/lib/typescript/memory/bundleUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/customSerializableUnpacker.native.d.ts +3 -0
- package/lib/typescript/memory/customSerializableUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/isShareable.d.ts +3 -0
- package/lib/typescript/memory/isShareable.d.ts.map +1 -0
- package/lib/typescript/memory/isSynchronizable.d.ts +3 -0
- package/lib/typescript/memory/isSynchronizable.d.ts.map +1 -0
- package/lib/typescript/memory/serializable.d.ts +7 -0
- package/lib/typescript/memory/serializable.d.ts.map +1 -0
- package/lib/typescript/memory/serializable.native.d.ts +37 -0
- package/lib/typescript/memory/serializable.native.d.ts.map +1 -0
- package/lib/typescript/memory/serializableMappingCache.d.ts +6 -0
- package/lib/typescript/memory/serializableMappingCache.d.ts.map +1 -0
- package/lib/typescript/memory/serializableMappingCache.native.d.ts +13 -0
- package/lib/typescript/memory/serializableMappingCache.native.d.ts.map +1 -0
- package/lib/typescript/memory/shareable.d.ts +23 -0
- package/lib/typescript/memory/shareable.d.ts.map +1 -0
- package/lib/typescript/memory/shareable.native.d.ts +23 -0
- package/lib/typescript/memory/shareable.native.d.ts.map +1 -0
- package/lib/typescript/memory/shareableGuestUnpacker.native.d.ts +4 -0
- package/lib/typescript/memory/shareableGuestUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/shareableHostUnpacker.native.d.ts +4 -0
- package/lib/typescript/memory/shareableHostUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/synchronizable.d.ts +3 -0
- package/lib/typescript/memory/synchronizable.d.ts.map +1 -0
- package/lib/typescript/memory/synchronizable.native.d.ts +3 -0
- package/lib/typescript/memory/synchronizable.native.d.ts.map +1 -0
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts +4 -0
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/types.d.ts +132 -0
- package/lib/typescript/memory/types.d.ts.map +1 -0
- package/lib/typescript/memory/valueUnpacker.native.d.ts +6 -0
- package/lib/typescript/memory/valueUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/mock.d.ts +2 -0
- package/lib/typescript/mock.d.ts.map +1 -0
- package/lib/typescript/platformChecker.d.ts +5 -0
- package/lib/typescript/platformChecker.d.ts.map +1 -0
- package/lib/typescript/platformChecker.native.d.ts +2 -0
- package/lib/typescript/platformChecker.native.d.ts.map +1 -0
- package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts +6 -0
- package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts +2 -0
- package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/index.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/index.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts +10 -0
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts.map +1 -0
- package/lib/typescript/runtimeKind.d.ts +56 -0
- package/lib/typescript/runtimeKind.d.ts.map +1 -0
- package/lib/typescript/runtimes.d.ts +14 -0
- package/lib/typescript/runtimes.d.ts.map +1 -0
- package/lib/typescript/runtimes.native.d.ts +137 -0
- package/lib/typescript/runtimes.native.d.ts.map +1 -0
- package/lib/typescript/specs/NativeWorkletsModule.d.ts +7 -0
- package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -0
- package/lib/typescript/specs/index.d.ts +3 -0
- package/lib/typescript/specs/index.d.ts.map +1 -0
- package/lib/typescript/threads.d.ts +8 -0
- package/lib/typescript/threads.d.ts.map +1 -0
- package/lib/typescript/threads.native.d.ts +132 -0
- package/lib/typescript/threads.native.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +127 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/workletFunction.d.ts +26 -0
- package/lib/typescript/workletFunction.d.ts.map +1 -0
- package/package.json +2 -1
- package/src/debug/jsVersion.ts +1 -1
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { setupCallGuard } from './callGuard';
|
|
4
|
+
import { registerWorkletsError, WorkletsError } from './debug/WorkletsError';
|
|
5
|
+
import { addGuardImplementation } from './guardImplementation';
|
|
6
|
+
import { getMemorySafeCapturableConsole, setupConsole, setupSerializer } from './initializers/initializers';
|
|
7
|
+
import { createSerializable, makeShareableCloneOnUIRecursive } from './memory/serializable';
|
|
8
|
+
import { serializableMappingCache } from './memory/serializableMappingCache';
|
|
9
|
+
import { setupRunLoop } from './runLoop/workletRuntime';
|
|
10
|
+
import { RuntimeKind } from './runtimeKind';
|
|
11
|
+
import { scheduleOnRN } from './threads';
|
|
12
|
+
import { isWorkletFunction } from './workletFunction';
|
|
13
|
+
import { WorkletsModule } from './WorkletsModule/NativeWorklets';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The ID of the [UI Worklet
|
|
17
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
|
18
|
+
*/
|
|
19
|
+
export const UIRuntimeId = RuntimeKind.UI;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Lets you create a new JS runtime which can be used to run worklets possibly
|
|
23
|
+
* on different threads than JS or UI thread.
|
|
24
|
+
*
|
|
25
|
+
* @param config - Runtime configuration object - {@link WorkletRuntimeConfig}.
|
|
26
|
+
* @returns WorkletRuntime which is a
|
|
27
|
+
* `jsi::HostObject<worklets::WorkletRuntime>` - {@link WorkletRuntime}
|
|
28
|
+
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/createWorkletRuntime/
|
|
29
|
+
*/
|
|
30
|
+
// @ts-expect-error Public API overload.
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated Please use the new config object signature instead:
|
|
34
|
+
* `createWorkletRuntime({ name, initializer })`
|
|
35
|
+
*
|
|
36
|
+
* Lets you create a new JS runtime which can be used to run worklets possibly
|
|
37
|
+
* on different threads than JS or UI thread.
|
|
38
|
+
* @param name - A name used to identify the runtime which will appear in
|
|
39
|
+
* devices list in Chrome DevTools.
|
|
40
|
+
* @param initializer - An optional worklet that will be run synchronously on
|
|
41
|
+
* the same thread immediately after the runtime is created.
|
|
42
|
+
* @returns WorkletRuntime which is a
|
|
43
|
+
* `jsi::HostObject<worklets::WorkletRuntime>` - {@link WorkletRuntime}
|
|
44
|
+
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/createWorkletRuntime/
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
export function createWorkletRuntime(nameOrConfig, initializer) {
|
|
48
|
+
const runtimeBoundCapturableConsole = getMemorySafeCapturableConsole();
|
|
49
|
+
let name;
|
|
50
|
+
let initializerFn;
|
|
51
|
+
let useDefaultQueue = true;
|
|
52
|
+
let customQueue;
|
|
53
|
+
let animationQueuePollingRate;
|
|
54
|
+
let enableEventLoop = true;
|
|
55
|
+
if (typeof nameOrConfig === 'string') {
|
|
56
|
+
name = nameOrConfig;
|
|
57
|
+
initializerFn = initializer;
|
|
58
|
+
} else {
|
|
59
|
+
// TODO: Make anonymous name globally unique.
|
|
60
|
+
name = nameOrConfig?.name ?? 'anonymous';
|
|
61
|
+
initializerFn = nameOrConfig?.initializer;
|
|
62
|
+
useDefaultQueue = nameOrConfig?.useDefaultQueue ?? true;
|
|
63
|
+
customQueue = nameOrConfig?.customQueue;
|
|
64
|
+
animationQueuePollingRate = Math.round(nameOrConfig?.animationQueuePollingRate ?? 16);
|
|
65
|
+
enableEventLoop = nameOrConfig?.enableEventLoop ?? true;
|
|
66
|
+
}
|
|
67
|
+
if (initializerFn && !isWorkletFunction(initializerFn)) {
|
|
68
|
+
throw new WorkletsError('The initializer passed to `createWorkletRuntime` is not a worklet.');
|
|
69
|
+
}
|
|
70
|
+
return WorkletsModule.createWorkletRuntime(name, createSerializable(() => {
|
|
71
|
+
'worklet';
|
|
72
|
+
|
|
73
|
+
setupCallGuard();
|
|
74
|
+
setupSerializer();
|
|
75
|
+
registerWorkletsError();
|
|
76
|
+
setupConsole(runtimeBoundCapturableConsole);
|
|
77
|
+
if (enableEventLoop) {
|
|
78
|
+
setupRunLoop(animationQueuePollingRate);
|
|
79
|
+
}
|
|
80
|
+
initializerFn?.();
|
|
81
|
+
}), useDefaultQueue, customQueue, enableEventLoop);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Lets you asynchronously run a
|
|
86
|
+
* [worklet](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#worklet)
|
|
87
|
+
* on a [Worker
|
|
88
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime).
|
|
89
|
+
*
|
|
90
|
+
* Check
|
|
91
|
+
* {@link https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds}
|
|
92
|
+
* for more information about the different runtime kinds.
|
|
93
|
+
*
|
|
94
|
+
* - The worklet is scheduled on the Worker Runtime's [Async
|
|
95
|
+
* Queue](https://github.com/software-mansion/react-native-reanimated/blob/main/packages/react-native-worklets/Common/cpp/worklets/RunLoop/AsyncQueue.h)
|
|
96
|
+
*
|
|
97
|
+
* @param workletRuntime - The runtime to schedule the worklet on.
|
|
98
|
+
* @param worklet - The worklet to schedule.
|
|
99
|
+
* @param args - The arguments to pass to the worklet.
|
|
100
|
+
* @returns The return value of the worklet.
|
|
101
|
+
*/
|
|
102
|
+
// @ts-expect-error This overload is correct since it's what user sees in their code
|
|
103
|
+
// before it's transformed by Worklets Babel plugin.
|
|
104
|
+
|
|
105
|
+
export function scheduleOnRuntime(workletRuntime, worklet, ...args) {
|
|
106
|
+
if (__DEV__ && !isWorkletFunction(worklet)) {
|
|
107
|
+
throw new WorkletsError('The function passed to `scheduleOnRuntime` is not a worklet.');
|
|
108
|
+
}
|
|
109
|
+
WorkletsModule.scheduleOnRuntime(workletRuntime, createSerializable(() => {
|
|
110
|
+
'worklet';
|
|
111
|
+
|
|
112
|
+
worklet(...args);
|
|
113
|
+
globalThis.__flushMicrotasks?.();
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
if (!globalThis._WORKLETS_BUNDLE_MODE_ENABLED) {
|
|
117
|
+
function scheduleOnRuntimeWorklet(workletRuntime, worklet, ...args) {
|
|
118
|
+
'worklet';
|
|
119
|
+
|
|
120
|
+
if (__DEV__ && !isWorkletFunction(worklet)) {
|
|
121
|
+
throw new WorkletsError('The function passed to `scheduleOnRuntime` is not a worklet.');
|
|
122
|
+
}
|
|
123
|
+
globalThis.__workletsModuleProxy.scheduleOnRuntime(workletRuntime, globalThis.__serializer(() => {
|
|
124
|
+
'worklet';
|
|
125
|
+
|
|
126
|
+
worklet(...args);
|
|
127
|
+
globalThis.__flushMicrotasks?.();
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
serializableMappingCache.set(scheduleOnRuntime, createSerializable(scheduleOnRuntimeWorklet));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Lets you asynchronously run a
|
|
135
|
+
* [worklet](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#worklet)
|
|
136
|
+
* on a [Worker
|
|
137
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime)
|
|
138
|
+
* identified by the runtime's id.
|
|
139
|
+
*
|
|
140
|
+
* Check
|
|
141
|
+
* {@link https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds}
|
|
142
|
+
* for more information about the different runtime kinds.
|
|
143
|
+
*
|
|
144
|
+
* - The worklet is scheduled on the Worker Runtime's [Async
|
|
145
|
+
* Queue](https://github.com/software-mansion/react-native-reanimated/blob/main/packages/react-native-worklets/Common/cpp/worklets/RunLoop/AsyncQueue.h)
|
|
146
|
+
*
|
|
147
|
+
* @param runtimeId - The id of the runtime to schedule the worklet on.
|
|
148
|
+
* @param worklet - The worklet to schedule.
|
|
149
|
+
* @param args - The arguments to pass to the worklet.
|
|
150
|
+
* @returns The return value of the worklet.
|
|
151
|
+
*/
|
|
152
|
+
// @ts-expect-error This overload is correct since it's what user sees in their code
|
|
153
|
+
// before it's transformed by Worklets Babel plugin.
|
|
154
|
+
|
|
155
|
+
export function scheduleOnRuntimeWithId(runtimeId, worklet, ...args) {
|
|
156
|
+
if (__DEV__ && !isWorkletFunction(worklet)) {
|
|
157
|
+
throw new WorkletsError('The function passed to `scheduleOnRuntimeWithId` is not a worklet.');
|
|
158
|
+
}
|
|
159
|
+
WorkletsModule.scheduleOnRuntimeWithId(runtimeId, createSerializable(() => {
|
|
160
|
+
'worklet';
|
|
161
|
+
|
|
162
|
+
worklet(...args);
|
|
163
|
+
globalThis.__flushMicrotasks?.();
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
if (!globalThis._WORKLETS_BUNDLE_MODE_ENABLED) {
|
|
167
|
+
function scheduleOnRuntimeWithIdWorklet(runtimeId, worklet, ...args) {
|
|
168
|
+
'worklet';
|
|
169
|
+
|
|
170
|
+
if (__DEV__ && !isWorkletFunction(worklet)) {
|
|
171
|
+
throw new WorkletsError('The function passed to `scheduleOnRuntimeWithId` is not a worklet.');
|
|
172
|
+
}
|
|
173
|
+
globalThis.__workletsModuleProxy.scheduleOnRuntimeWithId(runtimeId, globalThis.__serializer(() => {
|
|
174
|
+
'worklet';
|
|
175
|
+
|
|
176
|
+
worklet(...args);
|
|
177
|
+
globalThis.__flushMicrotasks?.();
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
serializableMappingCache.set(scheduleOnRuntimeWithId, createSerializable(scheduleOnRuntimeWithIdWorklet));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @deprecated Use `scheduleOnRuntime` instead.
|
|
185
|
+
*
|
|
186
|
+
* Schedule a worklet to execute on the background queue.
|
|
187
|
+
*/
|
|
188
|
+
// @ts-expect-error This overload is correct since it's what user sees in their code
|
|
189
|
+
// before it's transformed by Worklets Babel plugin.
|
|
190
|
+
|
|
191
|
+
export function runOnRuntime(workletRuntime, worklet) {
|
|
192
|
+
'worklet';
|
|
193
|
+
|
|
194
|
+
if (__DEV__ && !isWorkletFunction(worklet)) {
|
|
195
|
+
throw new WorkletsError('The function passed to `runOnRuntime` is not a worklet.');
|
|
196
|
+
}
|
|
197
|
+
return (...args) => scheduleOnRuntime(workletRuntime, worklet, ...args);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Lets you run a function synchronously on a [Worker
|
|
201
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime).
|
|
202
|
+
*
|
|
203
|
+
* - This function cannot be called from the [UI
|
|
204
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
|
205
|
+
* or another [Worker
|
|
206
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime),
|
|
207
|
+
* unless the [Bundle
|
|
208
|
+
* Mode](https://docs.swmansion.com/react-native-worklets/docs/bundleMode/) is
|
|
209
|
+
* enabled.
|
|
210
|
+
*
|
|
211
|
+
* @param workletRuntime - The runtime to run the worklet on.
|
|
212
|
+
* @param worklet - The worklet to run.
|
|
213
|
+
* @param args - The arguments to pass to the worklet.
|
|
214
|
+
* @returns The return value of the worklet.
|
|
215
|
+
*/
|
|
216
|
+
export function runOnRuntimeSync(workletRuntime, worklet, ...args) {
|
|
217
|
+
if (__DEV__ && !isWorkletFunction(worklet)) {
|
|
218
|
+
throw new WorkletsError('The function passed to `runOnRuntimeSync` is not a worklet.');
|
|
219
|
+
}
|
|
220
|
+
return WorkletsModule.runOnRuntimeSync(workletRuntime, createSerializable(() => {
|
|
221
|
+
'worklet';
|
|
222
|
+
|
|
223
|
+
const result = worklet(...args);
|
|
224
|
+
return makeShareableCloneOnUIRecursive(result);
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Lets you run a function synchronously on a [Worklet
|
|
230
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worklet-runtime)
|
|
231
|
+
* identified by the runtime's id.
|
|
232
|
+
*
|
|
233
|
+
* - This function cannot be called from the [UI
|
|
234
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime)
|
|
235
|
+
* or a [Worker
|
|
236
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime),
|
|
237
|
+
* unless the [Bundle
|
|
238
|
+
* Mode](https://docs.swmansion.com/react-native-worklets/docs/bundleMode/) is
|
|
239
|
+
* enabled.
|
|
240
|
+
* - You can target the UI Runtime with this function by passing
|
|
241
|
+
* {@link UIRuntimeId} as the `runtimeId` argument.
|
|
242
|
+
*
|
|
243
|
+
* @param runtimeId - The id of the runtime to run the worklet on.
|
|
244
|
+
* @param worklet - The worklet to run.
|
|
245
|
+
* @param args - The arguments to pass to the worklet.
|
|
246
|
+
* @returns The return value of the worklet.
|
|
247
|
+
*/
|
|
248
|
+
// @ts-expect-error This overload is correct since it's what user sees in their code
|
|
249
|
+
// before it's transformed by Worklets Babel plugin.
|
|
250
|
+
|
|
251
|
+
export function runOnRuntimeSyncWithId(runtimeId, worklet, ...args) {
|
|
252
|
+
if (__DEV__ && !isWorkletFunction(worklet)) {
|
|
253
|
+
throw new WorkletsError('The function passed to `runOnRuntimeSyncWithId` is not a worklet.');
|
|
254
|
+
}
|
|
255
|
+
return WorkletsModule.runOnRuntimeSyncWithId(runtimeId, createSerializable(() => {
|
|
256
|
+
'worklet';
|
|
257
|
+
|
|
258
|
+
const result = worklet(...args);
|
|
259
|
+
return makeShareableCloneOnUIRecursive(result);
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Lets you asynchronously run a
|
|
265
|
+
* [worklet](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#worklet)
|
|
266
|
+
* on a [Worker
|
|
267
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime)
|
|
268
|
+
* and get the result via a Promise.
|
|
269
|
+
*
|
|
270
|
+
* - The worklet is scheduled on the Worker Runtime's Async Queue
|
|
271
|
+
* - Returns a Promise that resolves with the worklet's return value
|
|
272
|
+
* - This function can only be called from the [RN
|
|
273
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#rn-runtime).
|
|
274
|
+
*
|
|
275
|
+
* @param workletRuntime - The runtime to run the worklet on.
|
|
276
|
+
* @param worklet - The worklet to run.
|
|
277
|
+
* @param args - The arguments to pass to the worklet.
|
|
278
|
+
* @returns A Promise that resolves to the return value of the worklet.
|
|
279
|
+
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnRuntimeAsync
|
|
280
|
+
*/
|
|
281
|
+
// @ts-expect-error This overload is correct since it's what user sees in their code
|
|
282
|
+
// before it's transformed by Worklets Babel plugin.
|
|
283
|
+
|
|
284
|
+
export function runOnRuntimeAsync(workletRuntime, worklet, ...args) {
|
|
285
|
+
if (__DEV__) {
|
|
286
|
+
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
|
|
287
|
+
throw new WorkletsError('`runOnRuntimeAsync` can only be called on the RN Runtime.');
|
|
288
|
+
}
|
|
289
|
+
if (!isWorkletFunction(worklet)) {
|
|
290
|
+
throw new WorkletsError('The function passed to `runOnRuntimeAsync` is not a worklet.');
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return new Promise((resolve, reject) => {
|
|
294
|
+
if (__DEV__) {
|
|
295
|
+
// in DEV mode we call serializable conversion here because in case the object
|
|
296
|
+
// can't be converted, we will get a meaningful stack-trace as opposed to the
|
|
297
|
+
// situation when conversion is only done via microtask queue. This does not
|
|
298
|
+
// make the app particularily less efficient as converted objects are cached
|
|
299
|
+
// and for a given worklet the conversion only happens once.
|
|
300
|
+
createSerializable(worklet);
|
|
301
|
+
createSerializable(args);
|
|
302
|
+
}
|
|
303
|
+
WorkletsModule.scheduleOnRuntime(workletRuntime, createSerializable(() => {
|
|
304
|
+
'worklet';
|
|
305
|
+
|
|
306
|
+
try {
|
|
307
|
+
const result = worklet(...args);
|
|
308
|
+
scheduleOnRN(resolve, result);
|
|
309
|
+
} catch (error) {
|
|
310
|
+
scheduleOnRN(reject, error);
|
|
311
|
+
}
|
|
312
|
+
globalThis.__flushMicrotasks?.();
|
|
313
|
+
}));
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
if (__DEV__ && !globalThis._WORKLETS_BUNDLE_MODE_ENABLED) {
|
|
317
|
+
/**
|
|
318
|
+
* QoL guards to give a meaningful error message when the user tries to call
|
|
319
|
+
* these functions on Worklet Runtimes outside of the Bundle Mode.
|
|
320
|
+
*/
|
|
321
|
+
addGuardImplementation(runOnRuntimeAsync);
|
|
322
|
+
addGuardImplementation(runOnRuntimeSync);
|
|
323
|
+
addGuardImplementation(runOnRuntimeSyncWithId);
|
|
324
|
+
}
|
|
325
|
+
export function getUIRuntimeHolder() {
|
|
326
|
+
return WorkletsModule.getUIRuntimeHolder();
|
|
327
|
+
}
|
|
328
|
+
export function getUISchedulerHolder() {
|
|
329
|
+
return WorkletsModule.getUISchedulerHolder();
|
|
330
|
+
}
|
|
331
|
+
//# sourceMappingURL=runtimes.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["setupCallGuard","registerWorkletsError","WorkletsError","addGuardImplementation","getMemorySafeCapturableConsole","setupConsole","setupSerializer","createSerializable","makeShareableCloneOnUIRecursive","serializableMappingCache","setupRunLoop","RuntimeKind","scheduleOnRN","isWorkletFunction","WorkletsModule","UIRuntimeId","UI","createWorkletRuntime","nameOrConfig","initializer","runtimeBoundCapturableConsole","name","initializerFn","useDefaultQueue","customQueue","animationQueuePollingRate","enableEventLoop","Math","round","scheduleOnRuntime","workletRuntime","worklet","args","__DEV__","globalThis","__flushMicrotasks","_WORKLETS_BUNDLE_MODE_ENABLED","scheduleOnRuntimeWorklet","__workletsModuleProxy","__serializer","set","scheduleOnRuntimeWithId","runtimeId","scheduleOnRuntimeWithIdWorklet","runOnRuntime","runOnRuntimeSync","result","runOnRuntimeSyncWithId","runOnRuntimeAsync","__RUNTIME_KIND","ReactNative","Promise","resolve","reject","error","getUIRuntimeHolder","getUISchedulerHolder"],"sourceRoot":"../../src","sources":["runtimes.native.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,cAAc,QAAQ,aAAa;AAC5C,SAASC,qBAAqB,EAAEC,aAAa,QAAQ,uBAAuB;AAC5E,SAASC,sBAAsB,QAAQ,uBAAuB;AAC9D,SACEC,8BAA8B,EAC9BC,YAAY,EACZC,eAAe,QACV,6BAA6B;AACpC,SACEC,kBAAkB,EAClBC,+BAA+B,QAC1B,uBAAuB;AAC9B,SAASC,wBAAwB,QAAQ,mCAAmC;AAC5E,SAASC,YAAY,QAAQ,0BAA0B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AAsB,CAAC;AAChD;AAEA,OAAO,SAASQ,kBAAkBA,CAAA,EAAW;EAC3C,OAAOzC,cAAc,CAACyC,kBAAkB,CAAC,CAAC;AAC5C;AAEA,OAAO,SAASC,oBAAoBA,CAAA,EAAW;EAC7C,OAAO1C,cAAc,CAAC0C,oBAAoB,CAAC,CAAC;AAC9C","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","get"],"sourceRoot":"../../../src","sources":["specs/NativeWorkletsModule.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAA2BA,mBAAmB,QAAQ,cAAc;AAMpE,eAAeA,mBAAmB,CAACC,GAAG,CAAO,gBAAgB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { RuntimeKind } from '../runtimeKind';
|
|
4
|
+
import RNWorkletsTurboModule from './NativeWorkletsModule';
|
|
5
|
+
export const WorkletsTurboModule = globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative ? RNWorkletsTurboModule :
|
|
6
|
+
// In Bundle Mode, on Worklet Runtimes `RNWorkletsTurboModule` isn't
|
|
7
|
+
// available and shouldn't be accessed. We return null here
|
|
8
|
+
// to keep the same codebase for the Bundle Mode and legacy behavior.
|
|
9
|
+
null;
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["RuntimeKind","RNWorkletsTurboModule","WorkletsTurboModule","globalThis","__RUNTIME_KIND","ReactNative"],"sourceRoot":"../../../src","sources":["specs/index.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,WAAW,QAAQ,gBAAgB;AAE5C,OAAOC,qBAAqB,MAAM,wBAAwB;AAE1D,OAAO,MAAMC,mBAA4C,GACvDC,UAAU,CAACC,cAAc,KAAKJ,WAAW,CAACK,WAAW,GACjDJ,qBAAqB;AACrB;AACA;AACA;AACA,IAAI","ignoreList":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { WorkletsError } from './debug/WorkletsError';
|
|
4
|
+
import { IS_JEST } from './platformChecker';
|
|
5
|
+
import { mockedRequestAnimationFrame } from './runLoop/uiRuntime/mockedRequestAnimationFrame';
|
|
6
|
+
export function scheduleOnUI(worklet, ...args) {
|
|
7
|
+
enqueueUI(worklet, args);
|
|
8
|
+
}
|
|
9
|
+
export function runOnUI(worklet) {
|
|
10
|
+
return (...args) => {
|
|
11
|
+
scheduleOnUI(worklet, ...args);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function runOnUISync() {
|
|
15
|
+
throw new WorkletsError('`runOnUISync` is not supported on web.');
|
|
16
|
+
}
|
|
17
|
+
export function executeOnUIRuntimeSync() {
|
|
18
|
+
throw new WorkletsError('`executeOnUIRuntimeSync` is not supported on web.');
|
|
19
|
+
}
|
|
20
|
+
export function runOnJS(fun) {
|
|
21
|
+
return (...args) => scheduleOnRN(fun, ...args);
|
|
22
|
+
}
|
|
23
|
+
export function scheduleOnRN(fun, ...args) {
|
|
24
|
+
queueMicrotask(args.length ? () => fun(...args) : fun);
|
|
25
|
+
}
|
|
26
|
+
export function runOnUIAsync(worklet, ...args) {
|
|
27
|
+
return new Promise(resolve => {
|
|
28
|
+
enqueueUI(worklet, args, resolve);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
let runOnUIQueue = [];
|
|
32
|
+
function enqueueUI(worklet, args, resolve) {
|
|
33
|
+
if (IS_JEST) {
|
|
34
|
+
mockedRequestAnimationFrame(() => {
|
|
35
|
+
const result = worklet(...args);
|
|
36
|
+
resolve?.(result);
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
const job = [worklet, args, resolve];
|
|
40
|
+
runOnUIQueue.push(job);
|
|
41
|
+
if (runOnUIQueue.length === 1) {
|
|
42
|
+
flushUIQueue();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function flushUIQueue() {
|
|
47
|
+
queueMicrotask(() => {
|
|
48
|
+
const queue = runOnUIQueue;
|
|
49
|
+
runOnUIQueue = [];
|
|
50
|
+
requestAnimationFrameImpl(() => {
|
|
51
|
+
queue.forEach(([workletFunction, workletArgs, jobResolve]) => {
|
|
52
|
+
const result = workletFunction(...workletArgs);
|
|
53
|
+
if (jobResolve) {
|
|
54
|
+
jobResolve(result);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const requestAnimationFrameImpl = !globalThis.requestAnimationFrame ? mockedRequestAnimationFrame : globalThis.requestAnimationFrame;
|
|
61
|
+
//# sourceMappingURL=threads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["WorkletsError","IS_JEST","mockedRequestAnimationFrame","scheduleOnUI","worklet","args","enqueueUI","runOnUI","runOnUISync","executeOnUIRuntimeSync","runOnJS","fun","scheduleOnRN","queueMicrotask","length","runOnUIAsync","Promise","resolve","runOnUIQueue","result","job","push","flushUIQueue","queue","requestAnimationFrameImpl","forEach","workletFunction","workletArgs","jobResolve","globalThis","requestAnimationFrame"],"sourceRoot":"../../src","sources":["threads.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,aAAa,QAAQ,uBAAuB;AACrD,SAASC,OAAO,QAAQ,mBAAmB;AAC3C,SAASC,2BAA2B,QAAQ,iDAAiD;AAE7F,OAAO,SAASC,YAAYA,CAC1BC,OAAuC,EACvC,GAAGC,IAAU,EACP;EACNC,SAAS,CAACF,OAAO,EAAEC,IAAI,CAAC;AAC1B;AAEA,OAAO,SAASE,OAAOA,CACrBH,OAAuC,EACd;EACzB,OAAO,CAAC,GAAGC,IAAI,KAAK;IAClBF,YAAY,CAACC,OAAO,EAAE,GAAGC,IAAI,CAAC;EAChC,CAAC;AACH;AAOA,OAAO,SAASG,WAAWA,CAAA,EAAU;EACnC,MAAM,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