@amazon-devices/react-native-worklets 1.0.1 → 1.0.2
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/kepler-compatibility.json +2 -1
- package/lib/module/index.js +0 -25
- package/package.json +1 -1
- package/src/index.ts +0 -52
- package/bundleMode/index.js +0 -59
- package/lib/module/PlatformChecker/PlatformChecker.js +0 -8
- package/lib/module/PlatformChecker/index.js +0 -18
- package/lib/module/WorkletsError.js +0 -29
- package/lib/module/WorkletsModule/JSWorklets.js +0 -111
- package/lib/module/WorkletsModule/NativeWorklets.js +0 -126
- package/lib/module/WorkletsModule/index.js +0 -4
- package/lib/module/WorkletsModule/workletsModuleInstance.js +0 -7
- package/lib/module/WorkletsModule/workletsModuleInstance.web.js +0 -5
- package/lib/module/WorkletsModule/workletsModuleProxy.js +0 -4
- package/lib/module/bundleUnpacker.js +0 -47
- package/lib/module/callGuard.js +0 -30
- package/lib/module/deprecated.js +0 -20
- package/lib/module/errors.js +0 -69
- package/lib/module/featureFlags/index.js +0 -48
- package/lib/module/initializers.js +0 -221
- package/lib/module/isSynchronizable.js +0 -6
- package/lib/module/logger.js +0 -15
- package/lib/module/privateGlobals.d.js +0 -7
- package/lib/module/publicGlobals.js +0 -6
- package/lib/module/runLoop/common/setImmediatePolyfill.js +0 -15
- package/lib/module/runLoop/common/setIntervalPolyfill.js +0 -26
- package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js +0 -10
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +0 -52
- package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js +0 -32
- package/lib/module/runLoop/workletRuntime/index.js +0 -19
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js +0 -11
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +0 -48
- package/lib/module/runLoop/workletRuntime/setTimeout.js +0 -28
- package/lib/module/runLoop/workletRuntime/taskQueue.js +0 -37
- package/lib/module/runtimeKind.js +0 -39
- package/lib/module/runtimes.js +0 -100
- package/lib/module/serializable.js +0 -568
- package/lib/module/serializableMappingCache.js +0 -37
- package/lib/module/specs/NativeWorkletsModule.js +0 -5
- package/lib/module/specs/NativeWorkletsModule.kepler.js +0 -7
- package/lib/module/specs/index.js +0 -10
- package/lib/module/synchronizable.js +0 -9
- package/lib/module/synchronizableUnpacker.js +0 -42
- package/lib/module/threads.js +0 -347
- package/lib/module/utils/checkCppVersion.js +0 -30
- package/lib/module/utils/jsVersion.js +0 -9
- package/lib/module/valueUnpacker.js +0 -60
- package/lib/module/workletFunction.js +0 -37
- package/lib/module/workletRuntimeEntry.js +0 -32
- package/lib/module/workletTypes.js +0 -12
- package/scripts/validate-react-native-version.js +0 -43
- package/src/PlatformChecker/PlatformChecker.ts +0 -7
- package/src/PlatformChecker/index.ts +0 -30
- package/src/WorkletsError.ts +0 -36
- package/src/WorkletsModule/JSWorklets.ts +0 -200
- package/src/WorkletsModule/NativeWorklets.ts +0 -256
- package/src/WorkletsModule/index.ts +0 -7
- package/src/WorkletsModule/workletsModuleInstance.ts +0 -9
- package/src/WorkletsModule/workletsModuleInstance.web.ts +0 -5
- package/src/WorkletsModule/workletsModuleProxy.ts +0 -126
- package/src/bundleUnpacker.ts +0 -75
- package/src/callGuard.ts +0 -33
- package/src/deprecated.ts +0 -32
- package/src/errors.ts +0 -80
- package/src/featureFlags/index.ts +0 -72
- package/src/initializers.ts +0 -262
- package/src/isSynchronizable.ts +0 -13
- package/src/logger.ts +0 -16
- package/src/publicGlobals.ts +0 -39
- package/src/runLoop/common/setImmediatePolyfill.ts +0 -20
- package/src/runLoop/common/setIntervalPolyfill.ts +0 -38
- package/src/runLoop/uiRuntime/mockedRequestAnimationFrame.ts +0 -11
- package/src/runLoop/uiRuntime/requestAnimationFrame.ts +0 -66
- package/src/runLoop/uiRuntime/setTimeoutPolyfill.ts +0 -40
- package/src/runLoop/workletRuntime/index.ts +0 -18
- package/src/runLoop/workletRuntime/queueMicrotask.ts +0 -13
- package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +0 -61
- package/src/runLoop/workletRuntime/setTimeout.ts +0 -37
- package/src/runLoop/workletRuntime/taskQueue.ts +0 -44
- package/src/runtimeKind.ts +0 -37
- package/src/runtimes.ts +0 -193
- package/src/serializable.ts +0 -801
- package/src/serializableMappingCache.ts +0 -42
- package/src/specs/NativeWorkletsModule.kepler.ts +0 -11
- package/src/specs/NativeWorkletsModule.ts +0 -9
- package/src/specs/index.ts +0 -13
- package/src/synchronizable.ts +0 -32
- package/src/synchronizableUnpacker.ts +0 -67
- package/src/threads.ts +0 -452
- package/src/utils/checkCppVersion.ts +0 -34
- package/src/utils/jsVersion.ts +0 -7
- package/src/valueUnpacker.ts +0 -90
- package/src/workletFunction.ts +0 -42
- package/src/workletRuntimeEntry.ts +0 -35
- package/src/workletTypes.ts +0 -81
package/lib/module/errors.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { WorkletsError } from './WorkletsError';
|
|
4
|
-
const _workletStackDetails = new Map();
|
|
5
|
-
export function registerWorkletStackDetails(hash, stackDetails) {
|
|
6
|
-
_workletStackDetails.set(hash, stackDetails);
|
|
7
|
-
}
|
|
8
|
-
function getBundleOffset(error) {
|
|
9
|
-
const frame = error.stack?.split('\n')?.[0];
|
|
10
|
-
if (frame) {
|
|
11
|
-
const parsedFrame = /@([^@]+):(\d+):(\d+)/.exec(frame);
|
|
12
|
-
if (parsedFrame) {
|
|
13
|
-
const [, file, line, col] = parsedFrame;
|
|
14
|
-
return [file, Number(line), Number(col)];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return ['unknown', 0, 0];
|
|
18
|
-
}
|
|
19
|
-
function processStack(stack) {
|
|
20
|
-
if (stack === '' || stack === undefined) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
const workletStackEntries = stack.match(/worklet_(\d+):(\d+):(\d+)/g);
|
|
24
|
-
let result = stack;
|
|
25
|
-
workletStackEntries?.forEach(match => {
|
|
26
|
-
const [, hash, origLine, origCol] = match.split(/:|_/).map(Number);
|
|
27
|
-
const errorDetails = _workletStackDetails.get(hash);
|
|
28
|
-
if (!errorDetails) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const [error, lineOffset, colOffset] = errorDetails;
|
|
32
|
-
const [bundleFile, bundleLine, bundleCol] = getBundleOffset(error);
|
|
33
|
-
const line = origLine + bundleLine + lineOffset;
|
|
34
|
-
const col = origCol + bundleCol + colOffset;
|
|
35
|
-
result = result.replace(match, `${bundleFile}:${line}:${col}`);
|
|
36
|
-
});
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Remote error is an error coming from a Worklet Runtime that we bubble up to
|
|
41
|
-
* the RN Runtime.
|
|
42
|
-
*/
|
|
43
|
-
export function reportFatalRemoteError({
|
|
44
|
-
message,
|
|
45
|
-
stack,
|
|
46
|
-
name,
|
|
47
|
-
jsEngine
|
|
48
|
-
}, force) {
|
|
49
|
-
const error = new WorkletsError();
|
|
50
|
-
error.message = message;
|
|
51
|
-
error.stack = processStack(stack);
|
|
52
|
-
error.name = name;
|
|
53
|
-
error.jsEngine = jsEngine;
|
|
54
|
-
if (force) {
|
|
55
|
-
throw error;
|
|
56
|
-
} else {
|
|
57
|
-
// @ts-expect-error React Native's `ErrorUtils` are hidden from the global scope.
|
|
58
|
-
globalThis.ErrorUtils.reportFatalError(error);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Registers `reportFatalRemoteError` function in global scope to allow to
|
|
64
|
-
* invoke it from C++.
|
|
65
|
-
*/
|
|
66
|
-
export function registerReportFatalRemoteError() {
|
|
67
|
-
globalThis.__reportFatalRemoteError = reportFatalRemoteError;
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=errors.js.map
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { logger } from '../logger';
|
|
4
|
-
import { WorkletsModule } from '../WorkletsModule';
|
|
5
|
-
export const DynamicFlags = {
|
|
6
|
-
EXAMPLE_DYNAMIC_FLAG: true,
|
|
7
|
-
init() {
|
|
8
|
-
Object.keys(DynamicFlags).forEach(key => {
|
|
9
|
-
if (key !== 'init' && key !== 'setFlag') {
|
|
10
|
-
WorkletsModule.setDynamicFeatureFlag(key, DynamicFlags[key]);
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
},
|
|
14
|
-
setFlag(name, value) {
|
|
15
|
-
if (name in DynamicFlags) {
|
|
16
|
-
DynamicFlags[name] = value;
|
|
17
|
-
WorkletsModule.setDynamicFeatureFlag(name, value);
|
|
18
|
-
} else {
|
|
19
|
-
logger.warn(`The feature flag: '${name}' no longer exists, you can safely remove invocation of \`setDynamicFeatureFlag('${name}')\` from your code.`);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
DynamicFlags.init();
|
|
24
|
-
// Public API function to update a feature flag
|
|
25
|
-
export function setDynamicFeatureFlag(name, value) {
|
|
26
|
-
DynamicFlags.setFlag(name, value);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* This constant is needed for typechecking and preserving static typechecks in
|
|
31
|
-
* generated .d.ts files. Without it, the static flags resolve to an object
|
|
32
|
-
* without specific keys.
|
|
33
|
-
*/
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
35
|
-
const DefaultStaticFeatureFlags = {
|
|
36
|
-
RUNTIME_TEST_FLAG: false,
|
|
37
|
-
IOS_DYNAMIC_FRAMERATE_ENABLED: false
|
|
38
|
-
};
|
|
39
|
-
const staticFeatureFlags = {};
|
|
40
|
-
export function getStaticFeatureFlag(name) {
|
|
41
|
-
if (name in staticFeatureFlags) {
|
|
42
|
-
return staticFeatureFlags[name];
|
|
43
|
-
}
|
|
44
|
-
const featureFlagValue = WorkletsModule.getStaticFeatureFlag(name);
|
|
45
|
-
staticFeatureFlags[name] = featureFlagValue;
|
|
46
|
-
return featureFlagValue;
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { bundleValueUnpacker } from './bundleUnpacker';
|
|
4
|
-
import { setupCallGuard } from './callGuard';
|
|
5
|
-
import { registerReportFatalRemoteError } from './errors';
|
|
6
|
-
import { IS_JEST, SHOULD_BE_USE_WEB } from './PlatformChecker';
|
|
7
|
-
import { setupSetImmediate } from './runLoop/common/setImmediatePolyfill';
|
|
8
|
-
import { setupSetInterval } from './runLoop/common/setIntervalPolyfill';
|
|
9
|
-
import { mockedRequestAnimationFrame } from './runLoop/uiRuntime/mockedRequestAnimationFrame';
|
|
10
|
-
import { setupRequestAnimationFrame } from './runLoop/uiRuntime/requestAnimationFrame';
|
|
11
|
-
import { setupSetTimeout } from './runLoop/uiRuntime/setTimeoutPolyfill';
|
|
12
|
-
import { RuntimeKind } from './runtimeKind';
|
|
13
|
-
import { __installUnpacker as installSynchronizableUnpacker } from './synchronizableUnpacker';
|
|
14
|
-
import { executeOnUIRuntimeSync, runOnJS, setupMicrotasks } from './threads';
|
|
15
|
-
import { isWorkletFunction } from './workletFunction';
|
|
16
|
-
import { registerWorkletsError, WorkletsError } from './WorkletsError';
|
|
17
|
-
import { WorkletsModule } from './WorkletsModule';
|
|
18
|
-
let capturableConsole;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Currently there seems to be a bug in the JSI layer which causes a crash when
|
|
22
|
-
* we try to copy some of the console methods, i.e. `clear` or `dirxml`.
|
|
23
|
-
*
|
|
24
|
-
* The crash happens only in React Native 0.75. It's not reproducible in neither
|
|
25
|
-
* 0.76 nor 0.74. It also happens only in the configuration of a debug app and
|
|
26
|
-
* production bundle.
|
|
27
|
-
*
|
|
28
|
-
* I haven't yet discovered what exactly causes the crash. It's tied to the
|
|
29
|
-
* console methods sometimes being `HostFunction`s. Therefore, as a workaround
|
|
30
|
-
* we don't copy the methods as they are in the original console object, we copy
|
|
31
|
-
* JavaScript wrappers instead.
|
|
32
|
-
*/
|
|
33
|
-
export function getMemorySafeCapturableConsole() {
|
|
34
|
-
if (capturableConsole) {
|
|
35
|
-
return capturableConsole;
|
|
36
|
-
}
|
|
37
|
-
const consoleCopy = Object.fromEntries(Object.entries(console).map(([methodName, method]) => {
|
|
38
|
-
const methodWrapper = function methodWrapper(...args) {
|
|
39
|
-
return method(...args);
|
|
40
|
-
};
|
|
41
|
-
if (method.name) {
|
|
42
|
-
/**
|
|
43
|
-
* Set the original method name as the wrapper name if available.
|
|
44
|
-
*
|
|
45
|
-
* It might be unnecessary but if we want to fully mimic the console
|
|
46
|
-
* object we should take into the account the fact some code might rely
|
|
47
|
-
* on the method name.
|
|
48
|
-
*/
|
|
49
|
-
Object.defineProperty(methodWrapper, 'name', {
|
|
50
|
-
value: method.name,
|
|
51
|
-
writable: false
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return [methodName, methodWrapper];
|
|
55
|
-
}));
|
|
56
|
-
capturableConsole = consoleCopy;
|
|
57
|
-
return consoleCopy;
|
|
58
|
-
}
|
|
59
|
-
export function setupConsole(boundCapturableConsole) {
|
|
60
|
-
'worklet';
|
|
61
|
-
|
|
62
|
-
// @ts-ignore TypeScript doesn't like that there are missing methods in console object, but we don't provide all the methods for the UI runtime console version
|
|
63
|
-
globalThis.console = {
|
|
64
|
-
assert: runOnJS(boundCapturableConsole.assert),
|
|
65
|
-
debug: runOnJS(boundCapturableConsole.debug),
|
|
66
|
-
log: runOnJS(boundCapturableConsole.log),
|
|
67
|
-
warn: runOnJS(boundCapturableConsole.warn),
|
|
68
|
-
error: runOnJS(boundCapturableConsole.error),
|
|
69
|
-
info: runOnJS(boundCapturableConsole.info)
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
let initialized = false;
|
|
73
|
-
export function init() {
|
|
74
|
-
if (initialized) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
initialized = true;
|
|
78
|
-
if (globalThis.__RUNTIME_KIND === undefined) {
|
|
79
|
-
// The only runtime that doesn't have `__RUNTIME_KIND` preconfigured
|
|
80
|
-
// is the RN Runtime. We must set it as soon as possible.
|
|
81
|
-
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
|
|
82
|
-
}
|
|
83
|
-
initializeRuntime();
|
|
84
|
-
if (SHOULD_BE_USE_WEB) {
|
|
85
|
-
initializeRuntimeOnWeb();
|
|
86
|
-
}
|
|
87
|
-
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
|
|
88
|
-
initializeWorkletRuntime();
|
|
89
|
-
} else {
|
|
90
|
-
initializeRNRuntime();
|
|
91
|
-
if (!SHOULD_BE_USE_WEB) {
|
|
92
|
-
installRNBindingsOnUIRuntime();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** A function that should be run on any kind of runtime. */
|
|
98
|
-
function initializeRuntime() {
|
|
99
|
-
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
100
|
-
globalThis.__valueUnpacker = bundleValueUnpacker;
|
|
101
|
-
}
|
|
102
|
-
installSynchronizableUnpacker();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/** A function that should be run only on React Native runtime. */
|
|
106
|
-
function initializeRNRuntime() {
|
|
107
|
-
if (__DEV__) {
|
|
108
|
-
const testWorklet = () => {
|
|
109
|
-
'worklet';
|
|
110
|
-
};
|
|
111
|
-
if (!isWorkletFunction(testWorklet)) {
|
|
112
|
-
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.`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
registerReportFatalRemoteError();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** A function that should be run only on Worklet runtimes. */
|
|
119
|
-
function initializeWorkletRuntime() {
|
|
120
|
-
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
121
|
-
setupCallGuard();
|
|
122
|
-
if (__DEV__) {
|
|
123
|
-
/*
|
|
124
|
-
* Temporary workaround for Metro bundler. We must implement a dummy
|
|
125
|
-
* Refresh module to prevent Metro from throwing irrelevant errors.
|
|
126
|
-
*/
|
|
127
|
-
const Refresh = new Proxy({}, {
|
|
128
|
-
get() {
|
|
129
|
-
return () => {};
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
globalThis.__r.Refresh = Refresh;
|
|
133
|
-
|
|
134
|
-
/* Gracefully handle unwanted imports from React Native. */
|
|
135
|
-
// @ts-expect-error type not exposed by Metro
|
|
136
|
-
const modules = require.getModules();
|
|
137
|
-
// @ts-expect-error type not exposed by Metro
|
|
138
|
-
const ReactNativeModuleId = require.resolveWeak('react-native');
|
|
139
|
-
const factory = function (_global, _require, _importDefault, _importAll, module, _exports, _dependencyMap) {
|
|
140
|
-
module.exports = new Proxy({}, {
|
|
141
|
-
get: function get(_target, prop) {
|
|
142
|
-
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.`);
|
|
143
|
-
return {
|
|
144
|
-
get() {
|
|
145
|
-
return undefined;
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
const mod = {
|
|
152
|
-
dependencyMap: [],
|
|
153
|
-
factory,
|
|
154
|
-
hasError: false,
|
|
155
|
-
importedAll: {},
|
|
156
|
-
importedDefault: {},
|
|
157
|
-
isInitialized: false,
|
|
158
|
-
publicModule: {
|
|
159
|
-
exports: {}
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
modules.set(ReactNativeModuleId, mod);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/** A function that should be run only on RN Runtime in web implementation. */
|
|
168
|
-
function initializeRuntimeOnWeb() {
|
|
169
|
-
globalThis._WORKLET = false;
|
|
170
|
-
globalThis._log = console.log;
|
|
171
|
-
globalThis._getAnimationTimestamp = () => performance.now();
|
|
172
|
-
if (IS_JEST) {
|
|
173
|
-
// requestAnimationFrame react-native jest's setup is incorrect as it polyfills
|
|
174
|
-
// the method directly using setTimeout, therefore the callback doesn't get the
|
|
175
|
-
// expected timestamp as the only argument: https://github.com/facebook/react-native/blob/main/packages/react-native/jest/setup.js#L28
|
|
176
|
-
// We override this setup here to make sure that callbacks get the proper timestamps
|
|
177
|
-
// when executed. For non-jest environments we define requestAnimationFrame in setupRequestAnimationFrame
|
|
178
|
-
// @ts-ignore TypeScript uses Node definition for rAF, setTimeout, etc which returns a Timeout object rather than a number
|
|
179
|
-
globalThis.requestAnimationFrame = mockedRequestAnimationFrame;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* A function that should be run on the RN Runtime to configure the UI Runtime
|
|
185
|
-
* with callback bindings.
|
|
186
|
-
*/
|
|
187
|
-
function installRNBindingsOnUIRuntime() {
|
|
188
|
-
if (!WorkletsModule) {
|
|
189
|
-
throw new WorkletsError('Worklets are trying to initialize the UI runtime without a valid WorkletsModule');
|
|
190
|
-
}
|
|
191
|
-
const runtimeBoundCapturableConsole = getMemorySafeCapturableConsole();
|
|
192
|
-
if (!globalThis._WORKLETS_BUNDLE_MODE) {
|
|
193
|
-
/** In bundle mode Runtimes setup their callGuard themselves. */
|
|
194
|
-
executeOnUIRuntimeSync(setupCallGuard)();
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Register WorkletsError in the UI runtime global scope. (we are using
|
|
198
|
-
* `executeOnUIRuntimeSync` here to make sure that the changes are applied
|
|
199
|
-
* before any async operations are executed on the UI runtime).
|
|
200
|
-
*
|
|
201
|
-
* There's no need to register the error in bundle mode.
|
|
202
|
-
*/
|
|
203
|
-
executeOnUIRuntimeSync(registerWorkletsError)();
|
|
204
|
-
}
|
|
205
|
-
executeOnUIRuntimeSync(() => {
|
|
206
|
-
'worklet';
|
|
207
|
-
|
|
208
|
-
setupConsole(runtimeBoundCapturableConsole);
|
|
209
|
-
/**
|
|
210
|
-
* TODO: Move `setupMicrotasks` and `setupRequestAnimationFrame` to a
|
|
211
|
-
* separate function once we have a better way to distinguish between
|
|
212
|
-
* Worklet Runtimes.
|
|
213
|
-
*/
|
|
214
|
-
setupMicrotasks();
|
|
215
|
-
setupRequestAnimationFrame();
|
|
216
|
-
setupSetTimeout();
|
|
217
|
-
setupSetImmediate();
|
|
218
|
-
setupSetInterval();
|
|
219
|
-
})();
|
|
220
|
-
}
|
|
221
|
-
//# sourceMappingURL=initializers.js.map
|
package/lib/module/logger.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const PREFIX = '[Worklets]';
|
|
4
|
-
function formatMessage(message) {
|
|
5
|
-
return `${PREFIX} ${message}`;
|
|
6
|
-
}
|
|
7
|
-
export const logger = {
|
|
8
|
-
warn(message) {
|
|
9
|
-
console.warn(formatMessage(message));
|
|
10
|
-
},
|
|
11
|
-
error(message) {
|
|
12
|
-
console.error(formatMessage(message));
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=logger.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/* eslint-disable reanimated/use-global-this */
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
// This file works by accident - currently Builder Bob doesn't move `.d.ts` files to output types.
|
|
5
|
-
// If it ever breaks, we should address it so we'd not pollute the user's global namespace.
|
|
6
|
-
export {};
|
|
7
|
-
//# sourceMappingURL=privateGlobals.d.js.map
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
export function setupSetImmediate() {
|
|
4
|
-
'worklet';
|
|
5
|
-
|
|
6
|
-
const setImmediatePolyfill = (callback, ...args) => {
|
|
7
|
-
return setTimeout(callback, 0, ...args);
|
|
8
|
-
};
|
|
9
|
-
const clearImmediatePolyfill = immediateHandle => {
|
|
10
|
-
clearTimeout(immediateHandle);
|
|
11
|
-
};
|
|
12
|
-
globalThis.setImmediate = setImmediatePolyfill;
|
|
13
|
-
globalThis.clearImmediate = clearImmediatePolyfill;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=setImmediatePolyfill.js.map
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
export function setupSetInterval() {
|
|
4
|
-
'worklet';
|
|
5
|
-
|
|
6
|
-
const intervalHandleToTimeoutHandle = new Map();
|
|
7
|
-
const setIntervalPolyfill = (callback, delay = 0, ...args) => {
|
|
8
|
-
let intervalHandle = 0;
|
|
9
|
-
const repeatingCallback = () => {
|
|
10
|
-
const timeoutHandle = setTimeout(repeatingCallback, delay);
|
|
11
|
-
intervalHandleToTimeoutHandle.set(intervalHandle, timeoutHandle);
|
|
12
|
-
callback(...args);
|
|
13
|
-
};
|
|
14
|
-
intervalHandle = setTimeout(repeatingCallback, delay);
|
|
15
|
-
intervalHandleToTimeoutHandle.set(intervalHandle, intervalHandle);
|
|
16
|
-
return intervalHandle;
|
|
17
|
-
};
|
|
18
|
-
const clearIntervalPolyfill = intervalHandle => {
|
|
19
|
-
const timeoutHandle = intervalHandleToTimeoutHandle.get(intervalHandle);
|
|
20
|
-
clearTimeout(timeoutHandle);
|
|
21
|
-
intervalHandleToTimeoutHandle.delete(intervalHandle);
|
|
22
|
-
};
|
|
23
|
-
globalThis.setInterval = setIntervalPolyfill;
|
|
24
|
-
globalThis.clearInterval = clearIntervalPolyfill;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=setIntervalPolyfill.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This is Jest implementation of `requestAnimationFrame` that is required by
|
|
5
|
-
* React Native for test purposes.
|
|
6
|
-
*/
|
|
7
|
-
export function mockedRequestAnimationFrame(callback) {
|
|
8
|
-
return setTimeout(() => callback(performance.now()), 0);
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=mockedRequestAnimationFrame.js.map
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { callMicrotasks } from '../../threads';
|
|
4
|
-
export function setupRequestAnimationFrame() {
|
|
5
|
-
'worklet';
|
|
6
|
-
|
|
7
|
-
const nativeRequestAnimationFrame = globalThis.requestAnimationFrame;
|
|
8
|
-
let queuedCallbacks = [];
|
|
9
|
-
let queuedCallbacksBegin = 0;
|
|
10
|
-
let queuedCallbacksEnd = 0;
|
|
11
|
-
let flushedCallbacks = queuedCallbacks;
|
|
12
|
-
let flushedCallbacksBegin = 0;
|
|
13
|
-
let flushedCallbacksEnd = 0;
|
|
14
|
-
let flushRequested = false;
|
|
15
|
-
globalThis.__flushAnimationFrame = timestamp => {
|
|
16
|
-
flushedCallbacks = queuedCallbacks;
|
|
17
|
-
queuedCallbacks = [];
|
|
18
|
-
flushedCallbacksBegin = queuedCallbacksBegin;
|
|
19
|
-
flushedCallbacksEnd = queuedCallbacksEnd;
|
|
20
|
-
queuedCallbacksBegin = queuedCallbacksEnd;
|
|
21
|
-
for (const callback of flushedCallbacks) {
|
|
22
|
-
callback(timestamp);
|
|
23
|
-
}
|
|
24
|
-
flushedCallbacksBegin = flushedCallbacksEnd;
|
|
25
|
-
callMicrotasks();
|
|
26
|
-
};
|
|
27
|
-
globalThis.requestAnimationFrame = callback => {
|
|
28
|
-
const handle = queuedCallbacksEnd++;
|
|
29
|
-
queuedCallbacks.push(callback);
|
|
30
|
-
if (!flushRequested) {
|
|
31
|
-
flushRequested = true;
|
|
32
|
-
nativeRequestAnimationFrame(timestamp => {
|
|
33
|
-
flushRequested = false;
|
|
34
|
-
globalThis.__frameTimestamp = timestamp;
|
|
35
|
-
globalThis.__flushAnimationFrame(timestamp);
|
|
36
|
-
globalThis.__frameTimestamp = undefined;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return handle;
|
|
40
|
-
};
|
|
41
|
-
globalThis.cancelAnimationFrame = handle => {
|
|
42
|
-
if (handle < flushedCallbacksBegin || handle >= queuedCallbacksEnd) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (handle < flushedCallbacksEnd) {
|
|
46
|
-
flushedCallbacks[handle - flushedCallbacksBegin] = () => {};
|
|
47
|
-
} else {
|
|
48
|
-
queuedCallbacks[handle - queuedCallbacksBegin] = () => {};
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=requestAnimationFrame.js.map
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
export function setupSetTimeout() {
|
|
4
|
-
'worklet';
|
|
5
|
-
|
|
6
|
-
const timeoutHandleToRafHandle = new Map();
|
|
7
|
-
const setTimeoutPolyfill = (callback, delay = 0, ...args) => {
|
|
8
|
-
const start = performance.now();
|
|
9
|
-
let timeoutHandle = 0;
|
|
10
|
-
const rafCallback = () => {
|
|
11
|
-
const now = performance.now();
|
|
12
|
-
if (now - start >= delay) {
|
|
13
|
-
callback(...args);
|
|
14
|
-
timeoutHandleToRafHandle.delete(timeoutHandle);
|
|
15
|
-
} else {
|
|
16
|
-
const rafHandle = requestAnimationFrame(rafCallback);
|
|
17
|
-
timeoutHandleToRafHandle.set(timeoutHandle, rafHandle);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
timeoutHandle = requestAnimationFrame(rafCallback);
|
|
21
|
-
timeoutHandleToRafHandle.set(timeoutHandle, timeoutHandle);
|
|
22
|
-
return timeoutHandle;
|
|
23
|
-
};
|
|
24
|
-
const clearTimeoutPolyfill = timeoutHandle => {
|
|
25
|
-
const rafHandle = timeoutHandleToRafHandle.get(timeoutHandle);
|
|
26
|
-
timeoutHandleToRafHandle.delete(timeoutHandle);
|
|
27
|
-
cancelAnimationFrame(rafHandle);
|
|
28
|
-
};
|
|
29
|
-
globalThis.setTimeout = setTimeoutPolyfill;
|
|
30
|
-
globalThis.clearTimeout = clearTimeoutPolyfill;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=setTimeoutPolyfill.js.map
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { setupSetImmediate } from '../common/setImmediatePolyfill';
|
|
4
|
-
import { setupSetInterval } from '../common/setIntervalPolyfill';
|
|
5
|
-
import { setupQueueMicrotask } from './queueMicrotask';
|
|
6
|
-
import { setupRequestAnimationFrame } from './requestAnimationFramePolyfill';
|
|
7
|
-
import { setupSetTimeout } from './setTimeout';
|
|
8
|
-
import { setupTaskQueue } from './taskQueue';
|
|
9
|
-
export function setupRunLoop(animationQueuePollingRate) {
|
|
10
|
-
'worklet';
|
|
11
|
-
|
|
12
|
-
setupTaskQueue();
|
|
13
|
-
setupQueueMicrotask();
|
|
14
|
-
setupSetTimeout();
|
|
15
|
-
setupRequestAnimationFrame(animationQueuePollingRate);
|
|
16
|
-
setupSetImmediate();
|
|
17
|
-
setupSetInterval();
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { pushMicrotask } from './taskQueue';
|
|
4
|
-
export function setupQueueMicrotask() {
|
|
5
|
-
'worklet';
|
|
6
|
-
|
|
7
|
-
globalThis.queueMicrotask = function (callback, ...args) {
|
|
8
|
-
pushMicrotask(() => callback(...args));
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=queueMicrotask.js.map
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
export function setupRequestAnimationFrame(animationQueuePollingRate) {
|
|
4
|
-
'worklet';
|
|
5
|
-
|
|
6
|
-
const timeoutInterval = animationQueuePollingRate;
|
|
7
|
-
let queuedCallbacks = [];
|
|
8
|
-
let queuedCallbacksBegin = 0;
|
|
9
|
-
let queuedCallbacksEnd = 0;
|
|
10
|
-
let flushedCallbacks = queuedCallbacks;
|
|
11
|
-
let flushedCallbacksBegin = 0;
|
|
12
|
-
let flushedCallbacksEnd = 0;
|
|
13
|
-
let flushRequested = false;
|
|
14
|
-
function flushAnimationFrame() {
|
|
15
|
-
flushRequested = false;
|
|
16
|
-
const timestamp = performance.now();
|
|
17
|
-
flushedCallbacks = queuedCallbacks;
|
|
18
|
-
queuedCallbacks = [];
|
|
19
|
-
flushedCallbacksBegin = queuedCallbacksBegin;
|
|
20
|
-
flushedCallbacksEnd = queuedCallbacksEnd;
|
|
21
|
-
queuedCallbacksBegin = queuedCallbacksEnd;
|
|
22
|
-
for (const callback of flushedCallbacks) {
|
|
23
|
-
callback(timestamp);
|
|
24
|
-
globalThis.__flushMicrotasks();
|
|
25
|
-
}
|
|
26
|
-
flushedCallbacksBegin = flushedCallbacksEnd;
|
|
27
|
-
}
|
|
28
|
-
globalThis.requestAnimationFrame = callback => {
|
|
29
|
-
const handle = queuedCallbacksEnd++;
|
|
30
|
-
queuedCallbacks.push(callback);
|
|
31
|
-
if (!flushRequested) {
|
|
32
|
-
flushRequested = true;
|
|
33
|
-
setTimeout(flushAnimationFrame, timeoutInterval);
|
|
34
|
-
}
|
|
35
|
-
return handle;
|
|
36
|
-
};
|
|
37
|
-
globalThis.cancelAnimationFrame = handle => {
|
|
38
|
-
if (handle < flushedCallbacksBegin || handle >= queuedCallbacksEnd) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (handle < flushedCallbacksEnd) {
|
|
42
|
-
flushedCallbacks[handle - flushedCallbacksBegin] = () => {};
|
|
43
|
-
} else {
|
|
44
|
-
queuedCallbacks[handle - queuedCallbacksBegin] = () => {};
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=requestAnimationFramePolyfill.js.map
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { pushTask } from './taskQueue';
|
|
4
|
-
export function setupSetTimeout() {
|
|
5
|
-
'worklet';
|
|
6
|
-
|
|
7
|
-
const pendingHandlers = new Set();
|
|
8
|
-
let ID = 0;
|
|
9
|
-
const setTimeoutPolyfill = (callback, delay = 0, ...args) => {
|
|
10
|
-
const handlerId = ID++;
|
|
11
|
-
const timeoutCallback = () => {
|
|
12
|
-
if (!pendingHandlers.has(handlerId)) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
callback(...args);
|
|
16
|
-
pendingHandlers.delete(handlerId);
|
|
17
|
-
};
|
|
18
|
-
pendingHandlers.add(handlerId);
|
|
19
|
-
pushTask(timeoutCallback, handlerId, delay);
|
|
20
|
-
return handlerId;
|
|
21
|
-
};
|
|
22
|
-
const clearTimeoutPolyfill = timeoutHandle => {
|
|
23
|
-
pendingHandlers.delete(timeoutHandle);
|
|
24
|
-
};
|
|
25
|
-
globalThis.setTimeout = setTimeoutPolyfill;
|
|
26
|
-
globalThis.clearTimeout = clearTimeoutPolyfill;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=setTimeout.js.map
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
export function setupTaskQueue() {
|
|
4
|
-
'worklet';
|
|
5
|
-
|
|
6
|
-
const queue = {
|
|
7
|
-
microtasks: [],
|
|
8
|
-
timeoutCallbacks: new Map()
|
|
9
|
-
};
|
|
10
|
-
globalThis._taskQueue = queue;
|
|
11
|
-
globalThis.__runTimeoutCallback = function (handlerId) {
|
|
12
|
-
const task = queue.timeoutCallbacks.get(handlerId);
|
|
13
|
-
task?.();
|
|
14
|
-
queue.timeoutCallbacks.delete(handlerId);
|
|
15
|
-
globalThis.__flushMicrotasks();
|
|
16
|
-
};
|
|
17
|
-
globalThis.__flushMicrotasks = function () {
|
|
18
|
-
for (let i = 0; i < queue.microtasks.length; i++) {
|
|
19
|
-
queue.microtasks[i]();
|
|
20
|
-
}
|
|
21
|
-
queue.microtasks = [];
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export function pushMicrotask(callback) {
|
|
25
|
-
'worklet';
|
|
26
|
-
|
|
27
|
-
const queue = globalThis._taskQueue;
|
|
28
|
-
queue.microtasks.push(callback);
|
|
29
|
-
}
|
|
30
|
-
export function pushTask(callback, handlerId, delay) {
|
|
31
|
-
'worklet';
|
|
32
|
-
|
|
33
|
-
const queue = globalThis._taskQueue;
|
|
34
|
-
queue.timeoutCallbacks.set(handlerId, callback);
|
|
35
|
-
globalThis._scheduleTimeoutCallback(delay, handlerId);
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=taskQueue.js.map
|