chore: add mobile app

This commit is contained in:
2026-02-07 22:33:02 +01:00
parent db34640acc
commit e89384ad4e
29327 changed files with 3886944 additions and 12 deletions
@@ -0,0 +1,4 @@
'use strict';
export const WorkletsModule = null;
//# sourceMappingURL=NativeWorklets.js.map
@@ -0,0 +1 @@
{"version":3,"names":["WorkletsModule"],"sourceRoot":"../../../src","sources":["WorkletsModule/NativeWorklets.ts"],"mappings":"AAAA,YAAY;;AASZ,OAAO,MAAMA,cAA+B,GAAG,IAAK","ignoreList":[]}
@@ -0,0 +1,130 @@
'use strict';
import { checkCppVersion } from '../debug/checkCppVersion';
import { jsVersion } from '../debug/jsVersion';
import { WorkletsError } from '../debug/WorkletsError';
import { RuntimeKind } from '../runtimeKind';
import { WorkletsTurboModule } from '../specs';
class NativeWorklets {
#workletsModuleProxy;
#serializableUndefined;
#serializableNull;
#serializableTrue;
#serializableFalse;
constructor() {
globalThis._WORKLETS_VERSION_JS = jsVersion;
if (global.__workletsModuleProxy === undefined && globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
WorkletsTurboModule?.installTurboModule();
}
if (global.__workletsModuleProxy === undefined) {
throw new WorkletsError(`Native part of Worklets doesn't seem to be initialized.
See https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#native-part-of-worklets-doesnt-seem-to-be-initialized for more details.`);
}
if (__DEV__ && globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
checkCppVersion();
}
this.#workletsModuleProxy = global.__workletsModuleProxy;
this.#serializableNull = this.#workletsModuleProxy.createSerializableNull();
this.#serializableUndefined = this.#workletsModuleProxy.createSerializableUndefined();
this.#serializableTrue = this.#workletsModuleProxy.createSerializableBoolean(true);
this.#serializableFalse = this.#workletsModuleProxy.createSerializableBoolean(false);
}
createSerializable(value, shouldPersistRemote, nativeStateSource) {
return this.#workletsModuleProxy.createSerializable(value, shouldPersistRemote, nativeStateSource);
}
createSerializableImport(from, to) {
return this.#workletsModuleProxy.createSerializableImport(from, to);
}
createSerializableString(str) {
return this.#workletsModuleProxy.createSerializableString(str);
}
createSerializableNumber(num) {
return this.#workletsModuleProxy.createSerializableNumber(num);
}
createSerializableBoolean(bool) {
return bool ? this.#serializableTrue : this.#serializableFalse;
}
createSerializableBigInt(bigInt) {
return this.#workletsModuleProxy.createSerializableBigInt(bigInt);
}
createSerializableUndefined() {
return this.#serializableUndefined;
}
createSerializableNull() {
return this.#serializableNull;
}
createSerializableTurboModuleLike(props, proto) {
return this.#workletsModuleProxy.createSerializableTurboModuleLike(props, proto);
}
createSerializableObject(obj, shouldRetainRemote, nativeStateSource) {
return this.#workletsModuleProxy.createSerializableObject(obj, shouldRetainRemote, nativeStateSource);
}
createSerializableHostObject(obj) {
return this.#workletsModuleProxy.createSerializableHostObject(obj);
}
createSerializableArray(array, shouldRetainRemote) {
return this.#workletsModuleProxy.createSerializableArray(array, shouldRetainRemote);
}
createSerializableMap(keys, values) {
return this.#workletsModuleProxy.createSerializableMap(keys, values);
}
createSerializableSet(values) {
return this.#workletsModuleProxy.createSerializableSet(values);
}
createSerializableInitializer(obj) {
return this.#workletsModuleProxy.createSerializableInitializer(obj);
}
createSerializableFunction(func) {
return this.#workletsModuleProxy.createSerializableFunction(func);
}
createSerializableWorklet(worklet, shouldPersistRemote) {
return this.#workletsModuleProxy.createSerializableWorklet(worklet, shouldPersistRemote);
}
createCustomSerializable(data, typeId) {
return this.#workletsModuleProxy.createCustomSerializable(data, typeId);
}
registerCustomSerializable(determine, pack, unpack, typeId) {
this.#workletsModuleProxy.registerCustomSerializable(determine, pack, unpack, typeId);
}
scheduleOnUI(serializable) {
return this.#workletsModuleProxy.scheduleOnUI(serializable);
}
executeOnUIRuntimeSync(serializable) {
return this.#workletsModuleProxy.executeOnUIRuntimeSync(serializable);
}
createWorkletRuntime(name, initializer, useDefaultQueue, customQueue, enableEventLoop) {
return this.#workletsModuleProxy.createWorkletRuntime(name, initializer, useDefaultQueue, customQueue, enableEventLoop);
}
scheduleOnRuntime(workletRuntime, serializableWorklet) {
return this.#workletsModuleProxy.scheduleOnRuntime(workletRuntime, serializableWorklet);
}
createSynchronizable(value) {
return this.#workletsModuleProxy.createSynchronizable(value);
}
synchronizableGetDirty(synchronizableRef) {
return this.#workletsModuleProxy.synchronizableGetDirty(synchronizableRef);
}
synchronizableGetBlocking(synchronizableRef) {
return this.#workletsModuleProxy.synchronizableGetBlocking(synchronizableRef);
}
synchronizableSetBlocking(synchronizableRef, value) {
return this.#workletsModuleProxy.synchronizableSetBlocking(synchronizableRef, value);
}
synchronizableLock(synchronizableRef) {
return this.#workletsModuleProxy.synchronizableLock(synchronizableRef);
}
synchronizableUnlock(synchronizableRef) {
return this.#workletsModuleProxy.synchronizableUnlock(synchronizableRef);
}
reportFatalErrorOnJS(message, stack, name, jsEngine) {
return this.#workletsModuleProxy.reportFatalErrorOnJS(message, stack, name, jsEngine);
}
getStaticFeatureFlag(name) {
return this.#workletsModuleProxy.getStaticFeatureFlag(name);
}
setDynamicFeatureFlag(name, value) {
this.#workletsModuleProxy.setDynamicFeatureFlag(name, value);
}
}
export const WorkletsModule = new NativeWorklets();
//# sourceMappingURL=NativeWorklets.native.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,4 @@
'use strict';
export {};
//# sourceMappingURL=workletsModuleProxy.js.map
@@ -0,0 +1 @@
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["WorkletsModule/workletsModuleProxy.ts"],"mappings":"AAAA,YAAY;;AAAC","ignoreList":[]}
@@ -0,0 +1,30 @@
'use strict';
/** Used only with debug builds. */
export function callGuardDEV(fn, ...args) {
'worklet';
try {
return fn(...args);
} catch (error) {
if (globalThis.__workletsModuleProxy) {
const {
message,
stack,
name,
jsEngine
} = error;
globalThis.__workletsModuleProxy.reportFatalErrorOnJS(message, stack ?? '', name ?? 'WorkletsError', jsEngine ?? 'Worklets');
} else {
throw error;
}
}
}
export function setupCallGuard() {
'worklet';
if (!globalThis.__callGuardDEV) {
globalThis.__callGuardDEV = callGuardDEV;
}
}
//# sourceMappingURL=callGuard.native.js.map
@@ -0,0 +1 @@
{"version":3,"names":["callGuardDEV","fn","args","error","globalThis","__workletsModuleProxy","message","stack","name","jsEngine","reportFatalErrorOnJS","setupCallGuard","__callGuardDEV"],"sourceRoot":"../../src","sources":["callGuard.native.ts"],"mappings":"AAAA,YAAY;;AAIZ;AACA,OAAO,SAASA,YAAYA,CAC1BC,EAAkC,EAClC,GAAGC,IAAU,EACO;EACpB,SAAS;;EACT,IAAI;IACF,OAAOD,EAAE,CAAC,GAAGC,IAAI,CAAC;EACpB,CAAC,CAAC,OAAOC,KAAK,EAAE;IACd,IAAIC,UAAU,CAACC,qBAAqB,EAAE;MACpC,MAAM;QAAEC,OAAO;QAAEC,KAAK;QAAEC,IAAI;QAAEC;MAAS,CAAC,GAAGN,KAAgB;MAC3DC,UAAU,CAACC,qBAAqB,CAACK,oBAAoB,CACnDJ,OAAO,EACPC,KAAK,IAAI,EAAE,EACXC,IAAI,IAAI,eAAe,EACvBC,QAAQ,IAAI,UACd,CAAC;IACH,CAAC,MAAM;MACL,MAAMN,KAAK;IACb;EACF;AACF;AAEA,OAAO,SAASQ,cAAcA,CAAA,EAAG;EAC/B,SAAS;;EACT,IAAI,CAACP,UAAU,CAACQ,cAAc,EAAE;IAC9BR,UAAU,CAACQ,cAAc,GAAGZ,YAAY;EAC1C;AACF","ignoreList":[]}
@@ -0,0 +1,12 @@
'use strict';
function WorkletsErrorConstructor(message) {
const prefix = '[Worklets]';
// eslint-disable-next-line reanimated/use-worklets-error
const errorInstance = new Error(message ? `${prefix} ${message}` : prefix);
errorInstance.name = `WorkletsError`;
return errorInstance;
}
export const WorkletsError = WorkletsErrorConstructor;
//# sourceMappingURL=WorkletsError.js.map
@@ -0,0 +1 @@
{"version":3,"names":["WorkletsErrorConstructor","message","prefix","errorInstance","Error","name","WorkletsError"],"sourceRoot":"../../../src","sources":["debug/WorkletsError.ts"],"mappings":"AAAA,YAAY;;AAOZ,SAASA,wBAAwBA,CAACC,OAAgB,EAAkB;EAClE,MAAMC,MAAM,GAAG,YAAY;;EAE3B;EACA,MAAMC,aAAa,GAAG,IAAIC,KAAK,CAACH,OAAO,GAAG,GAAGC,MAAM,IAAID,OAAO,EAAE,GAAGC,MAAM,CAAC;EAC1EC,aAAa,CAACE,IAAI,GAAG,eAAe;EACpC,OAAOF,aAAa;AACtB;AAEA,OAAO,MAAMG,aAAa,GACxBN,wBAAqD","ignoreList":[]}
@@ -0,0 +1,27 @@
'use strict';
import { RuntimeKind } from '../runtimeKind';
function WorkletsErrorConstructor(message) {
'worklet';
const prefix = '[Worklets]';
// eslint-disable-next-line reanimated/use-worklets-error
const errorInstance = new Error(message ? `${prefix} ${message}` : prefix);
errorInstance.name = `WorkletsError`;
return errorInstance;
}
/**
* Registers WorkletsError in the global scope. Register only for Worklet
* runtimes.
*/
export function registerWorkletsError() {
'worklet';
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
globalThis.WorkletsError = WorkletsErrorConstructor;
}
}
export const WorkletsError = WorkletsErrorConstructor;
//# sourceMappingURL=WorkletsError.native.js.map
@@ -0,0 +1 @@
{"version":3,"names":["RuntimeKind","WorkletsErrorConstructor","message","prefix","errorInstance","Error","name","registerWorkletsError","globalThis","__RUNTIME_KIND","ReactNative","WorkletsError"],"sourceRoot":"../../../src","sources":["debug/WorkletsError.native.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,WAAW,QAAQ,gBAAgB;AAM5C,SAASC,wBAAwBA,CAACC,OAAgB,EAAkB;EAClE,SAAS;;EACT,MAAMC,MAAM,GAAG,YAAY;;EAE3B;EACA,MAAMC,aAAa,GAAG,IAAIC,KAAK,CAACH,OAAO,GAAG,GAAGC,MAAM,IAAID,OAAO,EAAE,GAAGC,MAAM,CAAC;EAC1EC,aAAa,CAACE,IAAI,GAAG,eAAe;EACpC,OAAOF,aAAa;AACtB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASG,qBAAqBA,CAAA,EAAG;EACtC,SAAS;;EACT,IAAKC,UAAU,CAACC,cAAc,KAAqBT,WAAW,CAACU,WAAW,EAAE;IACzEF,UAAU,CAA6BG,aAAa,GACnDV,wBAAwB;EAC5B;AACF;AAEA,OAAO,MAAMU,aAAa,GACxBV,wBAAqD","ignoreList":[]}
@@ -0,0 +1,30 @@
'use strict';
import { jsVersion } from './jsVersion';
import { logger } from './logger';
import { WorkletsError } from './WorkletsError';
export function checkCppVersion() {
const cppVersion = global._WORKLETS_VERSION_CPP;
if (cppVersion === undefined) {
logger.warn(`Couldn't determine the version of the native part of Worklets.
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#couldnt-determine-the-version-of-the-native-part-of-worklets\` for more details.`);
return;
}
const ok = matchVersion(jsVersion, cppVersion);
if (!ok) {
throw new WorkletsError(`Mismatch between JavaScript part and native part of Worklets (${jsVersion} vs ${cppVersion}).
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-part-and-native-part-of-worklets\` for more details.`);
}
}
export function matchVersion(version1, version2) {
if (version1.match(/^\d+\.\d+\.\d+$/) && version2.match(/^\d+\.\d+\.\d+$/)) {
// x.y.z, compare only major and minor, skip patch
const [major1, minor1] = version1.split('.');
const [major2, minor2] = version2.split('.');
return major1 === major2 && minor1 === minor2;
} else {
// alpha, beta or rc, compare everything
return version1 === version2;
}
}
//# sourceMappingURL=checkCppVersion.js.map
@@ -0,0 +1 @@
{"version":3,"names":["jsVersion","logger","WorkletsError","checkCppVersion","cppVersion","global","_WORKLETS_VERSION_CPP","undefined","warn","ok","matchVersion","version1","version2","match","major1","minor1","split","major2","minor2"],"sourceRoot":"../../../src","sources":["debug/checkCppVersion.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,SAAS,QAAQ,aAAa;AACvC,SAASC,MAAM,QAAQ,UAAU;AACjC,SAASC,aAAa,QAAQ,iBAAiB;AAE/C,OAAO,SAASC,eAAeA,CAAA,EAAG;EAChC,MAAMC,UAAU,GAAGC,MAAM,CAACC,qBAAqB;EAC/C,IAAIF,UAAU,KAAKG,SAAS,EAAE;IAC5BN,MAAM,CAACO,IAAI,CACT;AACN,wKACI,CAAC;IACD;EACF;EACA,MAAMC,EAAE,GAAGC,YAAY,CAACV,SAAS,EAAEI,UAAU,CAAC;EAC9C,IAAI,CAACK,EAAE,EAAE;IACP,MAAM,IAAIP,aAAa,CACrB,iEAAiEF,SAAS,OAAOI,UAAU;AACjG,wKACI,CAAC;EACH;AACF;AAEA,OAAO,SAASM,YAAYA,CAACC,QAAgB,EAAEC,QAAgB,EAAE;EAC/D,IAAID,QAAQ,CAACE,KAAK,CAAC,iBAAiB,CAAC,IAAID,QAAQ,CAACC,KAAK,CAAC,iBAAiB,CAAC,EAAE;IAC1E;IACA,MAAM,CAACC,MAAM,EAAEC,MAAM,CAAC,GAAGJ,QAAQ,CAACK,KAAK,CAAC,GAAG,CAAC;IAC5C,MAAM,CAACC,MAAM,EAAEC,MAAM,CAAC,GAAGN,QAAQ,CAACI,KAAK,CAAC,GAAG,CAAC;IAC5C,OAAOF,MAAM,KAAKG,MAAM,IAAIF,MAAM,KAAKG,MAAM;EAC/C,CAAC,MAAM;IACL;IACA,OAAOP,QAAQ,KAAKC,QAAQ;EAC9B;AACF","ignoreList":[]}
@@ -0,0 +1,69 @@
'use strict';
import { WorkletsError } from './WorkletsError';
const _workletStackDetails = new Map();
export function registerWorkletStackDetails(hash, stackDetails) {
_workletStackDetails.set(hash, stackDetails);
}
function getBundleOffset(error) {
const frame = error.stack?.split('\n')?.[0];
if (frame) {
const parsedFrame = /@([^@]+):(\d+):(\d+)/.exec(frame);
if (parsedFrame) {
const [, file, line, col] = parsedFrame;
return [file, Number(line), Number(col)];
}
}
return ['unknown', 0, 0];
}
function processStack(stack) {
if (stack === '' || stack === undefined) {
return undefined;
}
const workletStackEntries = stack.match(/worklet_(\d+):(\d+):(\d+)/g);
let result = stack;
workletStackEntries?.forEach(match => {
const [, hash, origLine, origCol] = match.split(/:|_/).map(Number);
const errorDetails = _workletStackDetails.get(hash);
if (!errorDetails) {
return;
}
const [error, lineOffset, colOffset] = errorDetails;
const [bundleFile, bundleLine, bundleCol] = getBundleOffset(error);
const line = origLine + bundleLine + lineOffset;
const col = origCol + bundleCol + colOffset;
result = result.replace(match, `${bundleFile}:${line}:${col}`);
});
return result;
}
/**
* Remote error is an error coming from a Worklet Runtime that we bubble up to
* the RN Runtime.
*/
export function reportFatalRemoteError({
message,
stack,
name,
jsEngine
}, force) {
const error = new WorkletsError();
error.message = message;
error.stack = processStack(stack);
error.name = name;
error.jsEngine = jsEngine;
if (force) {
throw error;
} else {
// @ts-expect-error React Native's `ErrorUtils` are hidden from the global scope.
globalThis.ErrorUtils.reportFatalError(error);
}
}
/**
* Registers `reportFatalRemoteError` function in global scope to allow to
* invoke it from C++.
*/
export function registerReportFatalRemoteError() {
globalThis.__reportFatalRemoteError = reportFatalRemoteError;
}
//# sourceMappingURL=errors.native.js.map
@@ -0,0 +1 @@
{"version":3,"names":["WorkletsError","_workletStackDetails","Map","registerWorkletStackDetails","hash","stackDetails","set","getBundleOffset","error","frame","stack","split","parsedFrame","exec","file","line","col","Number","processStack","undefined","workletStackEntries","match","result","forEach","origLine","origCol","map","errorDetails","get","lineOffset","colOffset","bundleFile","bundleLine","bundleCol","replace","reportFatalRemoteError","message","name","jsEngine","force","globalThis","ErrorUtils","reportFatalError","registerReportFatalRemoteError","__reportFatalRemoteError"],"sourceRoot":"../../../src","sources":["debug/errors.native.ts"],"mappings":"AAAA,YAAY;;AAGZ,SAASA,aAAa,QAAQ,iBAAiB;AAE/C,MAAMC,oBAAoB,GAAG,IAAIC,GAAG,CAA8B,CAAC;AAEnE,OAAO,SAASC,2BAA2BA,CACzCC,IAAY,EACZC,YAAiC,EACjC;EACAJ,oBAAoB,CAACK,GAAG,CAACF,IAAI,EAAEC,YAAY,CAAC;AAC9C;AAEA,SAASE,eAAeA,CAACC,KAAY,EAA4B;EAC/D,MAAMC,KAAK,GAAGD,KAAK,CAACE,KAAK,EAAEC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;EAC3C,IAAIF,KAAK,EAAE;IACT,MAAMG,WAAW,GAAG,sBAAsB,CAACC,IAAI,CAACJ,KAAK,CAAC;IACtD,IAAIG,WAAW,EAAE;MACf,MAAM,GAAGE,IAAI,EAAEC,IAAI,EAAEC,GAAG,CAAC,GAAGJ,WAAW;MACvC,OAAO,CAACE,IAAI,EAAEG,MAAM,CAACF,IAAI,CAAC,EAAEE,MAAM,CAACD,GAAG,CAAC,CAAC;IAC1C;EACF;EACA,OAAO,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;AAC1B;AAEA,SAASE,YAAYA,CAACR,KAAc,EAAsB;EACxD,IAAIA,KAAK,KAAK,EAAE,IAAIA,KAAK,KAAKS,SAAS,EAAE;IACvC,OAAOA,SAAS;EAClB;EACA,MAAMC,mBAAmB,GAAGV,KAAK,CAACW,KAAK,CAAC,4BAA4B,CAAC;EACrE,IAAIC,MAAM,GAAGZ,KAAK;EAClBU,mBAAmB,EAAEG,OAAO,CAAEF,KAAK,IAAK;IACtC,MAAM,GAAGjB,IAAI,EAAEoB,QAAQ,EAAEC,OAAO,CAAC,GAAGJ,KAAK,CAACV,KAAK,CAAC,KAAK,CAAC,CAACe,GAAG,CAACT,MAAM,CAAC;IAClE,MAAMU,YAAY,GAAG1B,oBAAoB,CAAC2B,GAAG,CAACxB,IAAI,CAAC;IACnD,IAAI,CAACuB,YAAY,EAAE;MACjB;IACF;IACA,MAAM,CAACnB,KAAK,EAAEqB,UAAU,EAAEC,SAAS,CAAC,GAAGH,YAAY;IACnD,MAAM,CAACI,UAAU,EAAEC,UAAU,EAAEC,SAAS,CAAC,GAAG1B,eAAe,CAACC,KAAK,CAAC;IAClE,MAAMO,IAAI,GAAGS,QAAQ,GAAGQ,UAAU,GAAGH,UAAU;IAC/C,MAAMb,GAAG,GAAGS,OAAO,GAAGQ,SAAS,GAAGH,SAAS;IAE3CR,MAAM,GAAGA,MAAM,CAACY,OAAO,CAACb,KAAK,EAAE,GAAGU,UAAU,IAAIhB,IAAI,IAAIC,GAAG,EAAE,CAAC;EAChE,CAAC,CAAC;EACF,OAAOM,MAAM;AACf;AAMA;AACA;AACA;AACA;AACA,OAAO,SAASa,sBAAsBA,CACpC;EAAEC,OAAO;EAAE1B,KAAK;EAAE2B,IAAI;EAAEC;AAAkB,CAAC,EAC3CC,KAAc,EACR;EACN,MAAM/B,KAAK,GAAG,IAAIR,aAAa,CAAC,CAAY;EAC5CQ,KAAK,CAAC4B,OAAO,GAAGA,OAAO;EACvB5B,KAAK,CAACE,KAAK,GAAGQ,YAAY,CAACR,KAAK,CAAC;EACjCF,KAAK,CAAC6B,IAAI,GAAGA,IAAI;EACjB7B,KAAK,CAAC8B,QAAQ,GAAGA,QAAQ;EACzB,IAAIC,KAAK,EAAE;IACT,MAAM/B,KAAK;EACb,CAAC,MAAM;IACL;IACAgC,UAAU,CAACC,UAAU,CAACC,gBAAgB,CAAClC,KAAK,CAAC;EAC/C;AACF;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASmC,8BAA8BA,CAAA,EAAG;EAC/CH,UAAU,CAACI,wBAAwB,GAAGT,sBAAsB;AAC9D","ignoreList":[]}
@@ -0,0 +1,9 @@
'use strict';
/**
* We hardcode the version of Worklets here in order to compare it with the
* version used to build the native part of the library in runtime. Remember to
* keep this in sync with the version declared in `package.json`
*/
export const jsVersion = '0.7.2';
//# sourceMappingURL=jsVersion.js.map
@@ -0,0 +1 @@
{"version":3,"names":["jsVersion"],"sourceRoot":"../../../src","sources":["debug/jsVersion.ts"],"mappings":"AAAA,YAAY;;AAEZ;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,SAAS,GAAG,OAAO","ignoreList":[]}
@@ -0,0 +1,15 @@
'use strict';
const PREFIX = '[Worklets]';
function formatMessage(message) {
return `${PREFIX} ${message}`;
}
export const logger = {
warn(message) {
console.warn(formatMessage(message));
},
error(message) {
console.error(formatMessage(message));
}
};
//# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
{"version":3,"names":["PREFIX","formatMessage","message","logger","warn","console","error"],"sourceRoot":"../../../src","sources":["debug/logger.ts"],"mappings":"AAAA,YAAY;;AAEZ,MAAMA,MAAM,GAAG,YAAY;AAE3B,SAASC,aAAaA,CAACC,OAAe,EAAE;EACtC,OAAO,GAAGF,MAAM,IAAIE,OAAO,EAAE;AAC/B;AAEA,OAAO,MAAMC,MAAM,GAAG;EACpBC,IAAIA,CAACF,OAAe,EAAE;IACpBG,OAAO,CAACD,IAAI,CAACH,aAAa,CAACC,OAAO,CAAC,CAAC;EACtC,CAAC;EACDI,KAAKA,CAACJ,OAAe,EAAE;IACrBG,OAAO,CAACC,KAAK,CAACL,aAAa,CAACC,OAAO,CAAC,CAAC;EACvC;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
'use strict';
//# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["debug/types.ts"],"mappings":"AAAA,YAAY","ignoreList":[]}
@@ -0,0 +1,20 @@
'use strict';
import { createSerializable, isSerializableRef, makeShareable, makeShareableCloneOnUIRecursive } from './memory/serializable';
import { serializableMappingCache } from './memory/serializableMappingCache';
/** @deprecated Use {@link SerializableRef} instead. */
export { makeShareable, makeShareableCloneOnUIRecursive };
/** @deprecated It will be removed in the next major version. */
/** @deprecated Use {@link createSerializable} instead. */
export const makeShareableCloneRecursive = createSerializable;
/** @deprecated Use {@link isSerializableRef} instead. */
export const isShareableRef = isSerializableRef;
/** @deprecated Use {@link serializableMappingCache} instead. */
export const shareableMappingCache = serializableMappingCache;
//# sourceMappingURL=deprecated.js.map
@@ -0,0 +1 @@
{"version":3,"names":["createSerializable","isSerializableRef","makeShareable","makeShareableCloneOnUIRecursive","serializableMappingCache","makeShareableCloneRecursive","isShareableRef","shareableMappingCache"],"sourceRoot":"../../src","sources":["deprecated.ts"],"mappings":"AAAA,YAAY;;AAEZ,SACEA,kBAAkB,EAClBC,iBAAiB,EACjBC,aAAa,EACbC,+BAA+B,QAC1B,uBAAuB;AAC9B,SAASC,wBAAwB,QAAQ,mCAAmC;;AAG5E;;AAGA,SAASF,aAAa,EAAEC,+BAA+B;;AAEvD;;AAOA;AACA,OAAO,MAAME,2BAA+C,GAC1DL,kBAAkB;;AAEpB;AACA,OAAO,MAAMM,cAAc,GAAGL,iBAAiB;;AAE/C;AACA,OAAO,MAAMM,qBAAqB,GAAGH,wBAAwB","ignoreList":[]}
@@ -0,0 +1,12 @@
'use strict';
export function getStaticFeatureFlag(_name) {
return false;
}
export function setDynamicFeatureFlag(_name, _value) {
// no-op
}
export function getDynamicFeatureFlag(_name) {
return false;
}
//# sourceMappingURL=featureFlags.js.map
@@ -0,0 +1 @@
{"version":3,"names":["getStaticFeatureFlag","_name","setDynamicFeatureFlag","_value","getDynamicFeatureFlag"],"sourceRoot":"../../../src","sources":["featureFlags/featureFlags.ts"],"mappings":"AAAA,YAAY;;AAIZ,OAAO,SAASA,oBAAoBA,CAClCC,KAAqC,EAC5B;EACT,OAAO,KAAK;AACd;AAEA,OAAO,SAASC,qBAAqBA,CACnCD,KAAsB,EACtBE,MAAe,EACT;EACN;AAAA;AAGF,OAAO,SAASC,qBAAqBA,CAACH,KAAsB,EAAW;EACrE,OAAO,KAAK;AACd","ignoreList":[]}
@@ -0,0 +1,51 @@
'use strict';
import { logger } from '../debug/logger';
import { WorkletsModule } from '../WorkletsModule/NativeWorklets';
export const DynamicFlags = {
EXAMPLE_DYNAMIC_FLAG: true,
init() {
Object.keys(DynamicFlags).forEach(key => {
if (key !== 'init' && key !== 'setFlag' && key !== 'getFlag') {
WorkletsModule.setDynamicFeatureFlag(key, DynamicFlags[key]);
}
});
},
setFlag(name, value) {
if (name in DynamicFlags) {
DynamicFlags[name] = value;
WorkletsModule.setDynamicFeatureFlag(name, value);
} else {
logger.warn(`The feature flag: '${name}' no longer exists, you can safely remove invocation of \`setDynamicFeatureFlag('${name}')\` from your code.`);
}
},
getFlag(name) {
if (name in DynamicFlags) {
return DynamicFlags[name];
} else {
logger.warn(`The feature flag: '${name}' no longer exists, you can safely remove invocation of \`getDynamicFeatureFlag('${name}')\` from your code.`);
return false;
}
}
};
DynamicFlags.init();
// Public API function to update a feature flag
export function setDynamicFeatureFlag(name, value) {
DynamicFlags.setFlag(name, value);
}
// Public API function to read a feature flag
export function getDynamicFeatureFlag(name) {
return DynamicFlags.getFlag(name);
}
const staticFeatureFlags = {};
export function getStaticFeatureFlag(name) {
if (name in staticFeatureFlags) {
return staticFeatureFlags[name];
}
const featureFlagValue = WorkletsModule.getStaticFeatureFlag(name);
staticFeatureFlags[name] = featureFlagValue;
return featureFlagValue;
}
//# sourceMappingURL=featureFlags.native.js.map
@@ -0,0 +1 @@
{"version":3,"names":["logger","WorkletsModule","DynamicFlags","EXAMPLE_DYNAMIC_FLAG","init","Object","keys","forEach","key","setDynamicFeatureFlag","setFlag","name","value","warn","getFlag","getDynamicFeatureFlag","staticFeatureFlags","getStaticFeatureFlag","featureFlagValue"],"sourceRoot":"../../../src","sources":["featureFlags/featureFlags.native.ts"],"mappings":"AAAA,YAAY;;AACZ,SAASA,MAAM,QAAQ,iBAAiB;AACxC,SAASC,cAAc,QAAQ,kCAAkC;AAOjE,OAAO,MAAMC,YAA8B,GAAG;EAC5CC,oBAAoB,EAAE,IAAI;EAE1BC,IAAIA,CAAA,EAAG;IACLC,MAAM,CAACC,IAAI,CAACJ,YAAY,CAAC,CAACK,OAAO,CAAEC,GAAG,IAAK;MACzC,IAAIA,GAAG,KAAK,MAAM,IAAIA,GAAG,KAAK,SAAS,IAAIA,GAAG,KAAK,SAAS,EAAE;QAC5DP,cAAc,CAACQ,qBAAqB,CAClCD,GAAG,EACHN,YAAY,CAACM,GAAG,CAClB,CAAC;MACH;IACF,CAAC,CAAC;EACJ,CAAC;EACDE,OAAOA,CAACC,IAAI,EAAEC,KAAK,EAAE;IACnB,IAAID,IAAI,IAAIT,YAAY,EAAE;MACxBA,YAAY,CAACS,IAAI,CAAC,GAAGC,KAAK;MAC1BX,cAAc,CAACQ,qBAAqB,CAACE,IAAI,EAAEC,KAAK,CAAC;IACnD,CAAC,MAAM;MACLZ,MAAM,CAACa,IAAI,CACT,sBAAsBF,IAAI,oFAAoFA,IAAI,sBACpH,CAAC;IACH;EACF,CAAC;EACDG,OAAOA,CAACH,IAAI,EAAE;IACZ,IAAIA,IAAI,IAAIT,YAAY,EAAE;MACxB,OAAOA,YAAY,CAACS,IAAI,CAAC;IAC3B,CAAC,MAAM;MACLX,MAAM,CAACa,IAAI,CACT,sBAAsBF,IAAI,oFAAoFA,IAAI,sBACpH,CAAC;MACD,OAAO,KAAK;IACd;EACF;AACF,CAAC;AACDT,YAAY,CAACE,IAAI,CAAC,CAAC;;AAEnB;AACA,OAAO,SAASK,qBAAqBA,CACnCE,IAAqB,EACrBC,KAAc,EACR;EACNV,YAAY,CAACQ,OAAO,CAACC,IAAI,EAAEC,KAAK,CAAC;AACnC;;AAEA;AACA,OAAO,SAASG,qBAAqBA,CAACJ,IAAqB,EAAW;EACpE,OAAOT,YAAY,CAACY,OAAO,CAACH,IAAI,CAAC;AACnC;AAEA,MAAMK,kBAAqD,GAAG,CAAC,CAAC;AAEhE,OAAO,SAASC,oBAAoBA,CAClCN,IAAoC,EAC3B;EACT,IAAIA,IAAI,IAAIK,kBAAkB,EAAE;IAC9B,OAAOA,kBAAkB,CAACL,IAAI,CAAC;EACjC;EACA,MAAMO,gBAAgB,GAAGjB,cAAc,CAACgB,oBAAoB,CAACN,IAAI,CAAC;EAClEK,kBAAkB,CAACL,IAAI,CAAC,GAAGO,gBAAgB;EAC3C,OAAOA,gBAAgB;AACzB","ignoreList":[]}
@@ -0,0 +1,4 @@
{
"RUNTIME_TEST_FLAG": false,
"IOS_DYNAMIC_FRAMERATE_ENABLED": true
}
@@ -0,0 +1,12 @@
'use strict';
/**
* This constant is needed for typechecking and preserving static typechecks in
* generated .d.ts files. Without it, the static flags resolve to an object
* without specific keys.
*/
export const DefaultStaticFeatureFlags = {
RUNTIME_TEST_FLAG: false,
IOS_DYNAMIC_FRAMERATE_ENABLED: false
};
//# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
{"version":3,"names":["DefaultStaticFeatureFlags","RUNTIME_TEST_FLAG","IOS_DYNAMIC_FRAMERATE_ENABLED"],"sourceRoot":"../../../src","sources":["featureFlags/types.ts"],"mappings":"AAAA,YAAY;;AAgBZ;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,yBAAyB,GAAG;EACvCC,iBAAiB,EAAE,KAAK;EACxBC,6BAA6B,EAAE;AACjC,CAAkD","ignoreList":[]}
+26
View File
@@ -0,0 +1,26 @@
'use strict';
import { init } from './initializers/initializers';
import { bundleModeInit } from './initializers/workletRuntimeEntry';
init();
// @ts-expect-error We must trick the bundler to include
// the `workletRuntimeEntry` file the way it cannot optimize it out.
if (globalThis._ALWAYS_FALSE) {
// Bundle mode.
bundleModeInit();
}
export { isShareableRef, makeShareable, makeShareableCloneOnUIRecursive, makeShareableCloneRecursive, shareableMappingCache } from './deprecated';
export { getDynamicFeatureFlag, getStaticFeatureFlag, setDynamicFeatureFlag } from './featureFlags/featureFlags';
export { isSynchronizable } from './memory/isSynchronizable';
export { createSerializable, isSerializableRef, registerCustomSerializable } from './memory/serializable';
export { serializableMappingCache } from './memory/serializableMappingCache';
export { createSynchronizable } from './memory/synchronizable';
export { getRuntimeKind, RuntimeKind } from './runtimeKind';
export { createWorkletRuntime, runOnRuntime, scheduleOnRuntime } from './runtimes';
export { callMicrotasks, executeOnUIRuntimeSync, runOnJS, runOnUI, runOnUIAsync, runOnUISync, scheduleOnRN, scheduleOnUI,
// eslint-disable-next-line camelcase
unstable_eventLoopTask } from './threads';
export { isWorkletFunction } from './workletFunction';
export { WorkletsModule } from './WorkletsModule/NativeWorklets';
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"names":["init","bundleModeInit","globalThis","_ALWAYS_FALSE","isShareableRef","makeShareable","makeShareableCloneOnUIRecursive","makeShareableCloneRecursive","shareableMappingCache","getDynamicFeatureFlag","getStaticFeatureFlag","setDynamicFeatureFlag","isSynchronizable","createSerializable","isSerializableRef","registerCustomSerializable","serializableMappingCache","createSynchronizable","getRuntimeKind","RuntimeKind","createWorkletRuntime","runOnRuntime","scheduleOnRuntime","callMicrotasks","executeOnUIRuntimeSync","runOnJS","runOnUI","runOnUIAsync","runOnUISync","scheduleOnRN","scheduleOnUI","unstable_eventLoopTask","isWorkletFunction","WorkletsModule"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,IAAI,QAAQ,6BAA6B;AAClD,SAASC,cAAc,QAAQ,oCAAoC;AAEnED,IAAI,CAAC,CAAC;;AAEN;AACA;AACA,IAAIE,UAAU,CAACC,aAAa,EAAE;EAC5B;EACAF,cAAc,CAAC,CAAC;AAClB;AAEA,SACEG,cAAc,EACdC,aAAa,EAEbC,+BAA+B,EAC/BC,2BAA2B,EAC3BC,qBAAqB,QAEhB,cAAc;AACrB,SACEC,qBAAqB,EACrBC,oBAAoB,EACpBC,qBAAqB,QAChB,6BAA6B;AACpC,SAASC,gBAAgB,QAAQ,2BAA2B;AAC5D,SACEC,kBAAkB,EAClBC,iBAAiB,EACjBC,0BAA0B,QACrB,uBAAuB;AAC9B,SAASC,wBAAwB,QAAQ,mCAAmC;AAC5E,SAASC,oBAAoB,QAAQ,yBAAyB;AAO9D,SAASC,cAAc,EAAEC,WAAW,QAAQ,eAAe;AAC3D,SACEC,oBAAoB,EACpBC,YAAY,EACZC,iBAAiB,QACZ,YAAY;AACnB,SACEC,cAAc,EACdC,sBAAsB,EACtBC,OAAO,EACPC,OAAO,EACPC,YAAY,EACZC,WAAW,EACXC,YAAY,EACZC,YAAY;AACZ;AACAC,sBAAsB,QACjB,WAAW;AAMlB,SAASC,iBAAiB,QAAQ,mBAAmB;AACrD,SAASC,cAAc,QAAQ,iCAAiC","ignoreList":[]}
@@ -0,0 +1,21 @@
'use strict';
import { IS_JEST } from '../platformChecker';
import { mockedRequestAnimationFrame } from '../runLoop/uiRuntime/mockedRequestAnimationFrame';
import { RuntimeKind } from '../runtimeKind';
export function init() {
globalThis._WORKLET = false;
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
globalThis._log = console.log;
globalThis._getAnimationTimestamp = () => performance.now();
if (IS_JEST) {
// requestAnimationFrame react-native jest's setup is incorrect as it polyfills
// the method directly using setTimeout, therefore the callback doesn't get the
// expected timestamp as the only argument: https://github.com/facebook/react-native/blob/main/packages/react-native/jest/setup.js#L28
// We override this setup here to make sure that callbacks get the proper timestamps
// when executed. For non-jest environments we define requestAnimationFrame in setupRequestAnimationFrame
// @ts-ignore TypeScript uses Node definition for rAF, setTimeout, etc which returns a Timeout object rather than a number
globalThis.requestAnimationFrame = mockedRequestAnimationFrame;
}
}
//# sourceMappingURL=initializers.js.map
@@ -0,0 +1 @@
{"version":3,"names":["IS_JEST","mockedRequestAnimationFrame","RuntimeKind","init","globalThis","_WORKLET","__RUNTIME_KIND","ReactNative","_log","console","log","_getAnimationTimestamp","performance","now","requestAnimationFrame"],"sourceRoot":"../../../src","sources":["initializers/initializers.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,2BAA2B,QAAQ,kDAAkD;AAC9F,SAASC,WAAW,QAAQ,gBAAgB;AAE5C,OAAO,SAASC,IAAIA,CAAA,EAAG;EACrBC,UAAU,CAACC,QAAQ,GAAG,KAAK;EAC3BD,UAAU,CAACE,cAAc,GAAGJ,WAAW,CAACK,WAAW;EACnDH,UAAU,CAACI,IAAI,GAAGC,OAAO,CAACC,GAAG;EAC7BN,UAAU,CAACO,sBAAsB,GAAG,MAAMC,WAAW,CAACC,GAAG,CAAC,CAAC;EAC3D,IAAIb,OAAO,EAAE;IACX;IACA;IACA;IACA;IACA;IACA;IACAI,UAAU,CAACU,qBAAqB,GAAGb,2BAA2B;EAChE;AACF","ignoreList":[]}
@@ -0,0 +1,198 @@
'use strict';
import { setupCallGuard } from '../callGuard';
import { registerReportFatalRemoteError } from '../debug/errors';
import { registerWorkletsError, WorkletsError } from '../debug/WorkletsError';
import { bundleValueUnpacker } from '../memory/bundleUnpacker';
import { __installUnpacker as installCustomSerializableUnpacker } from '../memory/customSerializableUnpacker';
import { __installUnpacker as installSynchronizableUnpacker } from '../memory/synchronizableUnpacker';
import { setupSetImmediate } from '../runLoop/common/setImmediatePolyfill';
import { setupSetInterval } from '../runLoop/common/setIntervalPolyfill';
import { setupRequestAnimationFrame } from '../runLoop/uiRuntime/requestAnimationFrame';
import { setupSetTimeout } from '../runLoop/uiRuntime/setTimeoutPolyfill';
import { RuntimeKind } from '../runtimeKind';
import { runOnUISync, scheduleOnRN, setupMicrotasks } from '../threads';
import { isWorkletFunction } from '../workletFunction';
import { WorkletsModule } from '../WorkletsModule/NativeWorklets';
if (globalThis.__RUNTIME_KIND === undefined) {
// The only runtime that doesn't have `__RUNTIME_KIND` preconfigured
// is the RN Runtime. We must set it as soon as possible.
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
}
let capturableConsole;
/**
* Currently there seems to be a bug in the JSI layer which causes a crash when
* we try to copy some of the console methods, i.e. `clear` or `dirxml`.
*
* The crash happens only in React Native 0.75. It's not reproducible in neither
* 0.76 nor 0.74. It also happens only in the configuration of a debug app and
* production bundle.
*
* I haven't yet discovered what exactly causes the crash. It's tied to the
* console methods sometimes being `HostFunction`s. Therefore, as a workaround
* we don't copy the methods as they are in the original console object, we copy
* JavaScript wrappers instead.
*/
export function getMemorySafeCapturableConsole() {
if (capturableConsole) {
return capturableConsole;
}
const consoleCopy = Object.fromEntries(Object.entries(console).map(([methodName, method]) => {
const methodWrapper = function methodWrapper(...args) {
return method(...args);
};
if (method.name) {
/**
* Set the original method name as the wrapper name if available.
*
* It might be unnecessary but if we want to fully mimic the console
* object we should take into the account the fact some code might rely
* on the method name.
*/
Object.defineProperty(methodWrapper, 'name', {
value: method.name,
writable: false
});
}
return [methodName, methodWrapper];
}));
capturableConsole = consoleCopy;
return consoleCopy;
}
export function setupConsole(boundCapturableConsole) {
'worklet';
// @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
globalThis.console = {
assert: (...args) => scheduleOnRN(boundCapturableConsole.assert, ...args),
debug: (...args) => scheduleOnRN(boundCapturableConsole.debug, ...args),
log: (...args) => scheduleOnRN(boundCapturableConsole.log, ...args),
warn: (...args) => scheduleOnRN(boundCapturableConsole.warn, ...args),
error: (...args) => scheduleOnRN(boundCapturableConsole.error, ...args),
info: (...args) => scheduleOnRN(boundCapturableConsole.info, ...args)
};
}
let initialized = false;
export function init() {
if (initialized) {
return;
}
initialized = true;
initializeRuntime();
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
initializeWorkletRuntime();
} else {
initializeRNRuntime();
installRNBindingsOnUIRuntime();
}
}
/** A function that should be run on any kind of runtime. */
function initializeRuntime() {
if (globalThis._WORKLETS_BUNDLE_MODE) {
globalThis.__valueUnpacker = bundleValueUnpacker;
}
installSynchronizableUnpacker();
installCustomSerializableUnpacker();
}
/** A function that should be run only on React Native runtime. */
function initializeRNRuntime() {
if (__DEV__) {
const testWorklet = () => {
'worklet';
};
if (!isWorkletFunction(testWorklet)) {
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.`);
}
}
registerReportFatalRemoteError();
}
/** A function that should be run only on Worklet runtimes. */
function initializeWorkletRuntime() {
if (globalThis._WORKLETS_BUNDLE_MODE) {
setupCallGuard();
if (__DEV__) {
/*
* Temporary workaround for Metro bundler. We must implement a dummy
* Refresh module to prevent Metro from throwing irrelevant errors.
*/
const Refresh = new Proxy({}, {
get() {
return () => {};
}
});
globalThis.__r.Refresh = Refresh;
/* Gracefully handle unwanted imports from React Native. */
const modules = require.getModules();
const ReactNativeModuleId = require.resolveWeak('react-native');
const factory = function (_global, _require, _importDefault, _importAll, module, _exports, _dependencyMap) {
module.exports = new Proxy({}, {
get: function get(_target, prop) {
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.`);
return {
get() {
return undefined;
}
};
}
});
};
const mod = {
dependencyMap: [],
factory,
hasError: false,
importedAll: {},
importedDefault: {},
isInitialized: false,
publicModule: {
exports: {}
}
};
modules.set(ReactNativeModuleId, mod);
}
}
}
/**
* A function that should be run on the RN Runtime to configure the UI Runtime
* with callback bindings.
*/
function installRNBindingsOnUIRuntime() {
if (!WorkletsModule) {
throw new WorkletsError('Worklets are trying to initialize the UI runtime without a valid WorkletsModule');
}
const runtimeBoundCapturableConsole = getMemorySafeCapturableConsole();
if (!globalThis._WORKLETS_BUNDLE_MODE) {
/** In bundle mode Runtimes setup their callGuard themselves. */
runOnUISync(setupCallGuard);
/**
* Register WorkletsError in the UI runtime global scope. (we are using
* `executeOnUIRuntimeSync` here to make sure that the changes are applied
* before any async operations are executed on the UI runtime).
*
* There's no need to register the error in bundle mode.
*/
runOnUISync(registerWorkletsError);
}
runOnUISync(() => {
'worklet';
setupConsole(runtimeBoundCapturableConsole);
/**
* TODO: Move `setupMicrotasks` and `setupRequestAnimationFrame` to a
* separate function once we have a better way to distinguish between
* Worklet Runtimes.
*/
setupMicrotasks();
setupRequestAnimationFrame();
setupSetTimeout();
setupSetImmediate();
setupSetInterval();
});
}
//# sourceMappingURL=initializers.native.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,6 @@
'use strict';
export function bundleModeInit() {
// no-op
}
//# sourceMappingURL=workletRuntimeEntry.js.map
@@ -0,0 +1 @@
{"version":3,"names":["bundleModeInit"],"sourceRoot":"../../../src","sources":["initializers/workletRuntimeEntry.ts"],"mappings":"AAAA,YAAY;;AAEZ,OAAO,SAASA,cAAcA,CAAA,EAAG;EAC/B;AAAA","ignoreList":[]}
@@ -0,0 +1,37 @@
'use strict';
import { WorkletsError } from '../debug/WorkletsError';
import { RuntimeKind } from '../runtimeKind';
import { init } from './initializers';
/**
* This function is an entry point for Worklet Runtimes. We can use it to setup
* necessary tools, like the ValueUnpacker.
*
* We must throw an error at the end of this function to prevent the bundle to
* continue executing. This is because the next module to be ran would be the
* React Native one, and it would break the Worklet Runtime if initialized. The
* error is caught in C++ code.
*
* This function has no effect on the RN Runtime beside setting the
* `_WORKLETS_BUNDLE_MODE` flag.
*/
export function bundleModeInit() {
// Worklets Babel Plugin replaces `false` with `true` here
// when Bundle Mode is enabled.
globalThis._WORKLETS_BUNDLE_MODE = false;
if (!globalThis._WORKLETS_BUNDLE_MODE) {
return;
}
const runtimeKind = globalThis.__RUNTIME_KIND;
if (runtimeKind && runtimeKind !== RuntimeKind.ReactNative) {
/**
* We shouldn't call `init()` on RN Runtime here, as it would initialize our
* module before React Native has configured the RN Runtime.
*/
init();
throw new WorkletsError('Worklets initialized successfully');
}
}
bundleModeInit();
//# sourceMappingURL=workletRuntimeEntry.native.js.map
@@ -0,0 +1 @@
{"version":3,"names":["WorkletsError","RuntimeKind","init","bundleModeInit","globalThis","_WORKLETS_BUNDLE_MODE","runtimeKind","__RUNTIME_KIND","ReactNative"],"sourceRoot":"../../../src","sources":["initializers/workletRuntimeEntry.native.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,aAAa,QAAQ,wBAAwB;AACtD,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SAASC,IAAI,QAAQ,gBAAgB;;AAErC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAA,EAAG;EAC/B;EACA;EACAC,UAAU,CAACC,qBAAqB,GAAG,KAAK;EAExC,IAAI,CAACD,UAAU,CAACC,qBAAqB,EAAE;IACrC;EACF;EAEA,MAAMC,WAAW,GAAGF,UAAU,CAACG,cAAc;EAC7C,IAAID,WAAW,IAAIA,WAAW,KAAKL,WAAW,CAACO,WAAW,EAAE;IAC1D;AACJ;AACA;AACA;IACIN,IAAI,CAAC,CAAC;IACN,MAAM,IAAIF,aAAa,CAAC,mCAAmC,CAAC;EAC9D;AACF;AAEAG,cAAc,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,47 @@
'use strict';
import { logger } from '../debug/logger';
import { WorkletsError } from '../debug/WorkletsError';
const handleCache = new WeakMap();
export function bundleValueUnpacker(objectToUnpack, category, remoteFunctionName) {
const workletHash = objectToUnpack.__workletHash;
if (workletHash !== undefined) {
return getWorklet(workletHash, objectToUnpack.__closure);
} else if (objectToUnpack.__init !== undefined) {
let value = handleCache.get(objectToUnpack);
if (value === undefined) {
value = objectToUnpack.__init();
handleCache.set(objectToUnpack, value);
}
return value;
} else if (category === 'RemoteFunction') {
const remoteFunctionHolder = () => {
const label = remoteFunctionName ? `function \`${remoteFunctionName}\`` : 'anonymous function';
throw new WorkletsError(`Tried to synchronously call a non-worklet ${label} on the UI thread.
See https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#tried-to-synchronously-call-a-non-worklet-function-on-the-ui-thread for more details.`);
};
remoteFunctionHolder.__remoteFunction = objectToUnpack;
return remoteFunctionHolder;
} else {
throw new WorkletsError(`Data type in category "${category}" not recognized by value unpacker: "${globalThis._toString(objectToUnpack)}".`);
}
}
function getWorklet(workletHash, closureVariables) {
let worklet;
if (__DEV__) {
try {
worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
} catch (_e) {
logger.error('Unable to resolve worklet with hash ' + workletHash + '. Try reloading the app.');
}
} else {
worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
}
return worklet;
}
const metroRequire = globalThis.__r;
function getWorkletFromMetroRequire(workletHash, closureVariables) {
const factory = metroRequire(workletHash).default;
return factory(closureVariables);
}
//# sourceMappingURL=bundleUnpacker.native.js.map
@@ -0,0 +1 @@
{"version":3,"names":["logger","WorkletsError","handleCache","WeakMap","bundleValueUnpacker","objectToUnpack","category","remoteFunctionName","workletHash","__workletHash","undefined","getWorklet","__closure","__init","value","get","set","remoteFunctionHolder","label","__remoteFunction","globalThis","_toString","closureVariables","worklet","__DEV__","getWorkletFromMetroRequire","_e","error","metroRequire","__r","factory","default"],"sourceRoot":"../../../src","sources":["memory/bundleUnpacker.native.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,MAAM,QAAQ,iBAAiB;AACxC,SAASC,aAAa,QAAQ,wBAAwB;AAGtD,MAAMC,WAAW,GAAG,IAAIC,OAAO,CAA2B,CAAC;AAE3D,OAAO,SAASC,mBAAmBA,CACjCC,cAA8B,EAC9BC,QAAiB,EACjBC,kBAA2B,EAClB;EACT,MAAMC,WAAW,GAAGH,cAAc,CAACI,aAAa;EAChD,IAAID,WAAW,KAAKE,SAAS,EAAE;IAC7B,OAAOC,UAAU,CAACH,WAAW,EAAEH,cAAc,CAACO,SAAS,CAAC;EAC1D,CAAC,MAAM,IAAIP,cAAc,CAACQ,MAAM,KAAKH,SAAS,EAAE;IAC9C,IAAII,KAAK,GAAGZ,WAAW,CAACa,GAAG,CAACV,cAAc,CAAC;IAC3C,IAAIS,KAAK,KAAKJ,SAAS,EAAE;MACvBI,KAAK,GAAGT,cAAc,CAACQ,MAAM,CAAC,CAAC;MAC/BX,WAAW,CAACc,GAAG,CAACX,cAAc,EAAES,KAAK,CAAC;IACxC;IACA,OAAOA,KAAK;EACd,CAAC,MAAM,IAAIR,QAAQ,KAAK,gBAAgB,EAAE;IACxC,MAAMW,oBAAoB,GAAGA,CAAA,KAAM;MACjC,MAAMC,KAAK,GAAGX,kBAAkB,GAC5B,cAAcA,kBAAkB,IAAI,GACpC,oBAAoB;MACxB,MAAM,IAAIN,aAAa,CAAC,6CAA6CiB,KAAK;AAChF,uKAAuK,CAAC;IACpK,CAAC;IACDD,oBAAoB,CAACE,gBAAgB,GAAGd,cAAc;IACtD,OAAOY,oBAAoB;EAC7B,CAAC,MAAM;IACL,MAAM,IAAIhB,aAAa,CACrB,0BAA0BK,QAAQ,wCAAwCc,UAAU,CAACC,SAAS,CAC5FhB,cACF,CAAC,IACH,CAAC;EACH;AACF;AAEA,SAASM,UAAUA,CACjBH,WAAmB,EACnBc,gBAAyC,EACZ;EAC7B,IAAIC,OAAO;EACX,IAAIC,OAAO,EAAE;IACX,IAAI;MACFD,OAAO,GAAGE,0BAA0B,CAACjB,WAAW,EAAEc,gBAAgB,CAAC;IACrE,CAAC,CAAC,OAAOI,EAAE,EAAE;MACX1B,MAAM,CAAC2B,KAAK,CACV,sCAAsC,GACpCnB,WAAW,GACX,0BACJ,CAAC;IACH;EACF,CAAC,MAAM;IACLe,OAAO,GAAGE,0BAA0B,CAACjB,WAAW,EAAEc,gBAAgB,CAAC;EACrE;EACA,OAAOC,OAAO;AAChB;AAEA,MAAMK,YAAY,GAAGR,UAAU,CAACS,GAAG;AAEnC,SAASJ,0BAA0BA,CACjCjB,WAAmB,EACnBc,gBAAyC,EACxB;EACjB,MAAMQ,OAAO,GAAGF,YAAY,CAACpB,WAAW,CAAC,CAACuB,OAAyB;EACnE,OAAOD,OAAO,CAACR,gBAAgB,CAAC;AAClC","ignoreList":[]}
@@ -0,0 +1,18 @@
/* eslint-disable reanimated/use-worklets-error */
'use strict';
export function __installUnpacker() {
if (!globalThis.__customSerializationRegistry) {
globalThis.__customSerializationRegistry = [];
}
const registry = globalThis.__customSerializationRegistry;
function customSerializableUnpacker(value, typeId) {
const data = registry[typeId];
if (!data) {
throw new Error(`[Worklets] No custom serializable registered for type ID ${typeId}.`);
}
return data.unpack(value);
}
globalThis.__customSerializableUnpacker = customSerializableUnpacker;
}
//# sourceMappingURL=customSerializableUnpacker.native.js.map
@@ -0,0 +1 @@
{"version":3,"names":["__installUnpacker","globalThis","__customSerializationRegistry","registry","customSerializableUnpacker","value","typeId","data","Error","unpack","__customSerializableUnpacker"],"sourceRoot":"../../../src","sources":["memory/customSerializableUnpacker.native.ts"],"mappings":"AAAA;AACA,YAAY;;AAEZ,OAAO,SAASA,iBAAiBA,CAAA,EAAG;EAClC,IAAI,CAACC,UAAU,CAACC,6BAA6B,EAAE;IAC7CD,UAAU,CAACC,6BAA6B,GACtC,EAAqD;EACzD;EACA,MAAMC,QAAQ,GAAGF,UAAU,CAACC,6BAA6B;EAEzD,SAASE,0BAA0BA,CAASC,KAAa,EAAEC,MAAc,EAAE;IACzE,MAAMC,IAAI,GAAGJ,QAAQ,CAACG,MAAM,CAAC;IAC7B,IAAI,CAACC,IAAI,EAAE;MACT,MAAM,IAAIC,KAAK,CACb,4DAA4DF,MAAM,GACpE,CAAC;IACH;IAEA,OAAOC,IAAI,CAACE,MAAM,CAACJ,KAAe,CAAC;EACrC;EAEAJ,UAAU,CAACS,4BAA4B,GACrCN,0BAAwD;AAC5D","ignoreList":[]}
@@ -0,0 +1,7 @@
'use strict';
import { WorkletsError } from '../debug/WorkletsError';
export function isSynchronizable(_value) {
throw new WorkletsError('`isSynchronizable` is not supported on web.');
}
//# sourceMappingURL=isSynchronizable.js.map
@@ -0,0 +1 @@
{"version":3,"names":["WorkletsError","isSynchronizable","_value"],"sourceRoot":"../../../src","sources":["memory/isSynchronizable.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,aAAa,QAAQ,wBAAwB;AAGtD,OAAO,SAASC,gBAAgBA,CAC9BC,MAAe,EACmB;EAClC,MAAM,IAAIF,aAAa,CAAC,6CAA6C,CAAC;AACxE","ignoreList":[]}
@@ -0,0 +1,8 @@
'use strict';
export function isSynchronizable(value) {
'worklet';
return typeof value === 'object' && value !== null && '__synchronizableRef' in value && value.__synchronizableRef === true;
}
//# sourceMappingURL=isSynchronizable.native.js.map
@@ -0,0 +1 @@
{"version":3,"names":["isSynchronizable","value","__synchronizableRef"],"sourceRoot":"../../../src","sources":["memory/isSynchronizable.native.ts"],"mappings":"AAAA,YAAY;;AAIZ,OAAO,SAASA,gBAAgBA,CAC9BC,KAAc,EACmB;EACjC,SAAS;;EACT,OACE,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAK,IAAI,IACd,qBAAqB,IAAIA,KAAK,IAC9BA,KAAK,CAACC,mBAAmB,KAAK,IAAI;AAEtC","ignoreList":[]}
@@ -0,0 +1,18 @@
'use strict';
export function isSerializableRef(value) {
return true;
}
export function createSerializable(value) {
return value;
}
export function makeShareableCloneOnUIRecursive(value) {
return value;
}
export function makeShareable(value) {
return value;
}
export function registerCustomSerializable(_registrationData) {
// noop
}
//# sourceMappingURL=serializable.js.map
@@ -0,0 +1 @@
{"version":3,"names":["isSerializableRef","value","createSerializable","makeShareableCloneOnUIRecursive","makeShareable","registerCustomSerializable","_registrationData"],"sourceRoot":"../../../src","sources":["memory/serializable.ts"],"mappings":"AAAA,YAAY;;AAQZ,OAAO,SAASA,iBAAiBA,CAC/BC,KAAc,EACoB;EAClC,OAAO,IAAI;AACb;AAEA,OAAO,SAASC,kBAAkBA,CAChCD,KAAa,EACY;EACzB,OAAOA,KAAK;AACd;AAEA,OAAO,SAASE,+BAA+BA,CAC7CF,KAAa,EACgB;EAC7B,OAAOA,KAAK;AACd;AAEA,OAAO,SAASG,aAAaA,CAASH,KAAa,EAAU;EAC3D,OAAOA,KAAK;AACd;AAEA,OAAO,SAASI,0BAA0BA,CAGxCC,iBAAoD,EAAE;EACtD;AAAA","ignoreList":[]}
@@ -0,0 +1,631 @@
'use strict';
import { registerWorkletStackDetails } from '../debug/errors';
import { jsVersion } from '../debug/jsVersion';
import { logger } from '../debug/logger';
import { WorkletsError } from '../debug/WorkletsError';
import { getRuntimeKind, RuntimeKind } from '../runtimeKind';
import { isWorkletFunction } from '../workletFunction';
import { WorkletsModule } from '../WorkletsModule/NativeWorklets';
import { isSynchronizable } from './isSynchronizable';
import { serializableMappingCache, serializableMappingFlag } from './serializableMappingCache';
const MAGIC_KEY = 'REANIMATED_MAGIC_KEY';
function isHostObject(value) {
'worklet';
// We could use JSI to determine whether an object is a host object, however
// the below workaround works well and is way faster than an additional JSI call.
// We use the fact that host objects have broken implementation of `hasOwnProperty`
// and hence return true for all `in` checks regardless of the key we ask for.
return MAGIC_KEY in value;
}
export function isSerializableRef(value) {
'worklet';
return typeof value === 'object' && value !== null && '__serializableRef' in value && value.__serializableRef === true;
}
function isPlainJSObject(object) {
'worklet';
return Object.getPrototypeOf(object) === Object.prototype;
}
function isTurboModuleLike(object) {
return isHostObject(Object.getPrototypeOf(object));
}
function getFromCache(value) {
const cached = serializableMappingCache.get(value);
if (cached === serializableMappingFlag) {
// This means that `value` was already a clone and we should return it as is.
return value;
}
return cached;
}
// The below object is used as a replacement for objects that cannot be transferred
// as serializable values. In createSerializable we detect if an object is of
// a plain Object.prototype and only allow such objects to be transferred. This lets
// us avoid all sorts of react internals from leaking into the UI runtime. To make it
// possible to catch errors when someone actually tries to access such object on the UI
// runtime, we use the below Proxy object which is instantiated on the UI runtime and
// throws whenever someone tries to access its fields.
const INACCESSIBLE_OBJECT = {
__init: () => {
'worklet';
return new Proxy({}, {
get: (_, prop) => {
if (prop === '_isReanimatedSharedValue' || prop === '__remoteFunction' || prop === '__synchronizableRef') {
// not very happy about this check here, but we need to allow for
// "inaccessible" objects to be tested with isSerializableRef check
// as it is being used in the mappers when extracting inputs recursively
// as well as with isRemoteFunction when cloning objects recursively.
// Apparently we can't check if a key exists there as HostObjects always
// return true for such tests, so the only possibility for us is to
// actually access that key and see if it is set to true. We therefore
// need to allow for this key to be accessed here.
return false;
}
throw new WorkletsError(`Trying to access property \`${String(prop)}\` of an object which cannot be sent to the UI runtime.`);
},
set: () => {
throw new WorkletsError('Trying to write to an object which cannot be sent to the UI runtime.');
}
});
}
};
const VALID_ARRAY_VIEWS_NAMES = ['Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array', 'Float64Array', 'BigInt64Array', 'BigUint64Array', 'DataView'];
const DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD = 30;
// Below variable stores object that we process in createSerializable at the specified depth.
// We use it to check if later on the function reenters with the same object
let processedObjectAtThresholdDepth;
export function createSerializable(value, shouldPersistRemote = false, depth = 0) {
detectCyclicObject(value, depth);
const isObject = typeof value === 'object';
const isFunction = typeof value === 'function';
if (typeof value === 'string') {
return cloneString(value);
}
if (typeof value === 'number') {
return cloneNumber(value);
}
if (typeof value === 'boolean') {
return cloneBoolean(value);
}
if (typeof value === 'bigint') {
return cloneBigInt(value);
}
if (value === undefined) {
return cloneUndefined();
}
if (value === null) {
return cloneNull();
}
if (!isObject && !isFunction || value === null) {
return clonePrimitive(value, shouldPersistRemote);
}
const cached = getFromCache(value);
if (cached !== undefined) {
return cached;
}
if (Array.isArray(value)) {
return cloneArray(value, shouldPersistRemote, depth);
}
if (globalThis._WORKLETS_BUNDLE_MODE && isFunction && value.__bundleData) {
return cloneImport(value);
}
if (isFunction && !isWorkletFunction(value)) {
return cloneRemoteFunction(value);
}
// RN has introduced a new representation of TurboModules as a JS object whose prototype is the host object
// More details: https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp#L182
if (isTurboModuleLike(value)) {
return cloneTurboModuleLike(value, shouldPersistRemote, depth);
}
if (isHostObject(value)) {
return cloneHostObject(value);
}
if (isPlainJSObject(value) && value.__init) {
return cloneInitializer(value, shouldPersistRemote, depth);
}
if (isPlainJSObject(value) && value.__workletContextObjectFactory) {
return cloneContextObject(value);
}
if ((isPlainJSObject(value) || isFunction) && isWorkletFunction(value)) {
return cloneWorklet(value, shouldPersistRemote, depth);
}
if (isSynchronizable(value)) {
return cloneSynchronizable(value);
}
if (isPlainJSObject(value) || isFunction) {
return clonePlainJSObject(value, shouldPersistRemote, depth);
}
if (value instanceof Set) {
return cloneSet(value);
}
if (value instanceof Map) {
return cloneMap(value);
}
if (value instanceof RegExp) {
return cloneRegExp(value);
}
if (value instanceof Error) {
return cloneError(value);
}
if (value instanceof ArrayBuffer) {
return cloneArrayBuffer(value, shouldPersistRemote);
}
if (ArrayBuffer.isView(value)) {
// typed array (e.g. Int32Array, Uint8ClampedArray) or DataView
return cloneArrayBufferView(value);
}
for (let i = 0; i < customSerializationRegistry.length; i++) {
const {
determine,
pack
} = customSerializationRegistry[i];
if (determine(value)) {
return cloneCustom(value, pack, i);
}
}
return inaccessibleObject(value);
}
if (globalThis._WORKLETS_BUNDLE_MODE) {
// TODO: Do it programmatically.
createSerializable.__bundleData = {
imported: 'createSerializable',
source: require.resolveWeak('react-native-worklets')
};
}
if (!globalThis.__customSerializationRegistry) {
globalThis.__customSerializationRegistry = [];
}
const customSerializationRegistry = globalThis.__customSerializationRegistry;
/**
* `registerCustomSerializable` lets you register your own pre-serialization and
* post-deserialization logic. This is necessary for objects with prototypes
* different than just `Object.prototype` or some other built-in prototypes like
* `Map` etc. Worklets can't handle such objects by default to convert into
* [Serializables](https://docs.swmansion.com/react-native-worklets/docs/memory/serializable)
* hence you need to register them as **Custom Serializables**. This way you can
* tell Worklets how to transfer your custom data structures between different
* Runtimes without manually serializing and deserializing them every time.
*
* @param registrationData - The registration data for the custom serializable -
* {@link RegistrationData}
* @see https://docs.swmansion.com/react-native-worklets/docs/memory/registerCustomSerializable/
*/
export function registerCustomSerializable(registrationData) {
if (__DEV__ && getRuntimeKind() !== RuntimeKind.ReactNative) {
throw new WorkletsError('registerCustomSerializable can be used only on React Native runtime.');
}
const {
name,
determine,
pack,
unpack
} = registrationData;
if (__DEV__) {
verifyRegistrationData(determine, pack, unpack);
}
if (customSerializationRegistry.some(data => data.name === name)) {
if (__DEV__) {
console.warn(`Custom serializable with name "${name}" is already registered. Duplicate registration is ignored.`);
}
return;
}
customSerializationRegistry.push(registrationData);
WorkletsModule.registerCustomSerializable(createSerializable(determine), createSerializable(pack), createSerializable(unpack), customSerializationRegistry.length - 1);
}
function verifyRegistrationData(determine, pack, unpack) {
if (!isWorkletFunction(determine)) {
throw new WorkletsError('The "determine" function provided to registerCustomSerializable must be a worklet.');
}
if (!isWorkletFunction(pack)) {
throw new WorkletsError('The "pack" function provided to registerCustomSerializable must be a worklet.');
}
if (!isWorkletFunction(unpack)) {
throw new WorkletsError('The "unpack" function provided to registerCustomSerializable must be a worklet.');
}
}
function detectCyclicObject(value, depth) {
if (depth >= DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
// if we reach certain recursion depth we suspect that we are dealing with a cyclic object.
// this type of objects are not supported and cannot be transferred as serializable, so we
// implement a simple detection mechanism that remembers the value at a given depth and
// tests whether we try reenter this method later on with the same value. If that happens
// we throw an appropriate error.
if (depth === DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
processedObjectAtThresholdDepth = value;
} else if (value === processedObjectAtThresholdDepth) {
throw new WorkletsError('Trying to convert a cyclic object to a serializable. This is not supported.');
}
} else {
processedObjectAtThresholdDepth = undefined;
}
}
function clonePrimitive(value, shouldPersistRemote) {
return WorkletsModule.createSerializable(value, shouldPersistRemote);
}
function cloneString(value) {
return WorkletsModule.createSerializableString(value);
}
function cloneNumber(value) {
return WorkletsModule.createSerializableNumber(value);
}
function cloneBoolean(value) {
return WorkletsModule.createSerializableBoolean(value);
}
function cloneBigInt(value) {
return WorkletsModule.createSerializableBigInt(value);
}
function cloneUndefined() {
return WorkletsModule.createSerializableUndefined();
}
function cloneNull() {
return WorkletsModule.createSerializableNull();
}
function cloneObjectProperties(value, shouldPersistRemote, depth) {
const clonedProps = {};
for (const [key, element] of Object.entries(value)) {
// We don't need to clone __initData field as it contains long strings
// representing the worklet code, source map, and location, and we will
// serialize/deserialize it once.
if (key === '__initData' && clonedProps.__initData !== undefined) {
continue;
}
clonedProps[key] = createSerializable(element, shouldPersistRemote, depth + 1);
}
return clonedProps;
}
function cloneInitializer(value, shouldPersistRemote = false, depth = 0) {
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
return WorkletsModule.createSerializableInitializer(clonedProps);
}
function cloneArray(value, shouldPersistRemote, depth) {
const clonedElements = value.map(element => createSerializable(element, shouldPersistRemote, depth + 1));
const clone = WorkletsModule.createSerializableArray(clonedElements, shouldPersistRemote);
serializableMappingCache.set(value, clone);
serializableMappingCache.set(clone);
freezeObjectInDev(value);
return clone;
}
function cloneRemoteFunction(value) {
const clone = WorkletsModule.createSerializableFunction(value);
serializableMappingCache.set(value, clone);
serializableMappingCache.set(clone);
freezeObjectInDev(value);
return clone;
}
function cloneHostObject(value) {
// for host objects we pass the reference to the object as serializable and
// then recreate new host object wrapping the same instance on the UI thread.
// there is no point of iterating over keys as we do for regular objects.
const clone = WorkletsModule.createSerializableHostObject(value);
serializableMappingCache.set(value, clone);
serializableMappingCache.set(clone);
return clone;
}
function cloneWorklet(value, shouldPersistRemote, depth) {
if (__DEV__) {
const babelVersion = value.__pluginVersion;
if (babelVersion !== undefined && babelVersion !== jsVersion) {
throw new WorkletsError(`Mismatch between JavaScript code version and Worklets Babel plugin version (${jsVersion} vs. ${babelVersion}).
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-code-version-and-worklets-babel-plugin-version\` for more details.
Offending code was: \`${getWorkletCode(value)}\``);
}
registerWorkletStackDetails(value.__workletHash, value.__stackDetails);
}
if (value.__stackDetails) {
// `Error` type of value cannot be copied to the UI thread, so we
// remove it after we handled it in dev mode or delete it to ignore it in production mode.
// Not removing this would cause an infinite loop in production mode and it just
// seems more elegant to handle it this way.
delete value.__stackDetails;
}
const clonedProps = cloneObjectProperties(value, true, depth);
// to save on transferring static __initData field of worklet structure
// we request serializable value to persist its UI counterpart. This means
// that the __initData field that contains long strings representing the
// worklet code, source map, and location, will always be
// serialized/deserialized once.
clonedProps.__initData = createSerializable(value.__initData, true, depth + 1);
const clone = WorkletsModule.createSerializableWorklet(clonedProps,
// TODO: Check after refactor if we can remove shouldPersistRemote parameter (imho it's redundant here since worklets are always persistent)
// retain all worklets
true);
serializableMappingCache.set(value, clone);
serializableMappingCache.set(clone);
freezeObjectInDev(value);
return clone;
}
/**
* TurboModuleLike objects are JS objects that have a TurboModule as their
* prototype.
*/
function cloneTurboModuleLike(value, shouldPersistRemote, depth) {
const proto = Object.getPrototypeOf(value);
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
const clone = WorkletsModule.createSerializableTurboModuleLike(clonedProps, proto);
return clone;
}
function cloneContextObject(value) {
const workletContextObjectFactory = value.__workletContextObjectFactory;
const handle = cloneInitializer({
__init: () => {
'worklet';
return workletContextObjectFactory();
}
});
serializableMappingCache.set(value, handle);
return handle;
}
function clonePlainJSObject(value, shouldPersistRemote, depth) {
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
const clone = WorkletsModule.createSerializableObject(clonedProps, shouldPersistRemote, value);
serializableMappingCache.set(value, clone);
serializableMappingCache.set(clone);
freezeObjectInDev(value);
return clone;
}
function cloneMap(value) {
const clonedKeys = [];
const clonedValues = [];
for (const [key, element] of value.entries()) {
clonedKeys.push(createSerializable(key));
clonedValues.push(createSerializable(element));
}
const clone = WorkletsModule.createSerializableMap(clonedKeys, clonedValues);
serializableMappingCache.set(value, clone);
serializableMappingCache.set(clone);
freezeObjectInDev(value);
return clone;
}
function cloneSet(value) {
const clonedElements = [];
for (const element of value) {
clonedElements.push(createSerializable(element));
}
const clone = WorkletsModule.createSerializableSet(clonedElements);
serializableMappingCache.set(value, clone);
serializableMappingCache.set(clone);
freezeObjectInDev(value);
return clone;
}
function cloneRegExp(value) {
const pattern = value.source;
const flags = value.flags;
const handle = cloneInitializer({
__init: () => {
'worklet';
return new RegExp(pattern, flags);
}
});
serializableMappingCache.set(value, handle);
return handle;
}
function cloneError(value) {
const {
name,
message,
stack
} = value;
const handle = cloneInitializer({
__init: () => {
'worklet';
// eslint-disable-next-line reanimated/use-worklets-error
const error = new Error();
error.name = name;
error.message = message;
error.stack = stack;
return error;
}
});
serializableMappingCache.set(value, handle);
return handle;
}
function cloneArrayBuffer(value, shouldPersistRemote) {
const clone = WorkletsModule.createSerializable(value, shouldPersistRemote, value);
serializableMappingCache.set(value, clone);
serializableMappingCache.set(clone);
return clone;
}
function cloneArrayBufferView(value) {
const buffer = value.buffer;
const typeName = value.constructor.name;
const handle = cloneInitializer({
__init: () => {
'worklet';
if (!VALID_ARRAY_VIEWS_NAMES.includes(typeName)) {
throw new WorkletsError(`Invalid array view name \`${typeName}\`.`);
}
const constructor = global[typeName];
if (constructor === undefined) {
throw new WorkletsError(`Constructor for \`${typeName}\` not found.`);
}
return new constructor(buffer);
}
});
serializableMappingCache.set(value, handle);
return handle;
}
function cloneSynchronizable(value) {
serializableMappingCache.set(value);
return value;
}
function cloneImport(value) {
const {
source,
imported
} = value.__bundleData;
const clone = WorkletsModule.createSerializableImport(source, imported);
serializableMappingCache.set(value, clone);
serializableMappingCache.set(clone);
return clone;
}
function cloneCustom(data, pack, typeId) {
const packedData = pack(data);
const serialized = createSerializable(packedData);
return WorkletsModule.createCustomSerializable(serialized, typeId);
}
function inaccessibleObject(value) {
// This is reached for object types that are not of plain Object.prototype.
// We don't support such objects from being transferred as serializables to
// the UI runtime and hence we replace them with "inaccessible object"
// which is implemented as a Proxy object that throws on any attempt
// of accessing its fields. We argue that such objects can sometimes leak
// as attributes of objects being captured by worklets but should never
// be used on the UI runtime regardless. If they are being accessed, the user
// will get an appropriate error message.
const clone = createSerializable(INACCESSIBLE_OBJECT);
serializableMappingCache.set(value, clone);
return clone;
}
const WORKLET_CODE_THRESHOLD = 255;
function getWorkletCode(value) {
const code = value?.__initData?.code;
if (!code) {
return 'unknown';
}
if (code.length > WORKLET_CODE_THRESHOLD) {
return `${code.substring(0, WORKLET_CODE_THRESHOLD)}...`;
}
return code;
}
function isRemoteFunction(value) {
'worklet';
return !!value.__remoteFunction;
}
/**
* We freeze
*
* - Arrays,
* - Remote functions,
* - Plain JS objects,
*
* That are transformed to a serializable with a meaningful warning. This should
* help detect issues when someone modifies data after it's been converted.
* Meaning that they may be doing a faulty assumption in their code expecting
* that the updates are going to automatically propagate to the object sent to
* the UI thread. If the user really wants some objects to be mutable they
* should use shared values instead.
*/
function freezeObjectInDev(value) {
if (!__DEV__ || globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
return;
}
Object.entries(value).forEach(([key, element]) => {
const descriptor = Object.getOwnPropertyDescriptor(value, key);
if (!descriptor.configurable) {
return;
}
Object.defineProperty(value, key, {
get() {
return element;
},
set() {
logger.warn(`Tried to modify key \`${key}\` of an object which has been already passed to a worklet. See
https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-modify-key-of-an-object-which-has-been-converted-to-a-serializable
for more details.`);
}
});
});
Object.preventExtensions(value);
}
function makeShareableCloneOnUIRecursiveLEGACY(value) {
'worklet';
// eslint-disable-next-line @typescript-eslint/no-shadow
function cloneRecursive(value) {
if (typeof value === 'object' && value !== null || typeof value === 'function') {
if (isHostObject(value)) {
// We call `_createSerializableClone` to wrap the provided HostObject
// inside SerializableJSRef.
return global._createSerializableHostObject(value);
}
if (isRemoteFunction(value)) {
// RemoteFunctions are created by us therefore they are
// a Serializable out of the box and there is no need to
// call `_createSerializableClone`.
return value.__remoteFunction;
}
if (Array.isArray(value)) {
return global._createSerializableArray(value.map(cloneRecursive));
}
if (value.__synchronizableRef) {
return global._createSerializableSynchronizable(value);
}
if (Object.getPrototypeOf(value) !== Object.prototype) {
const length = globalThis.__customSerializationRegistry.length;
for (let i = 0; i < length; i++) {
const {
determine,
pack
} = globalThis.__customSerializationRegistry[i];
if (determine(value)) {
const packedData = pack(value);
return globalThis.__workletsModuleProxy?.createCustomSerializable(cloneRecursive(packedData), i);
}
}
}
const toAdapt = {};
for (const [key, element] of Object.entries(value)) {
toAdapt[key] = cloneRecursive(element);
}
return global._createSerializable(toAdapt, value);
}
if (typeof value === 'string') {
return global._createSerializableString(value);
}
if (typeof value === 'number') {
return global._createSerializableNumber(value);
}
if (typeof value === 'boolean') {
return global._createSerializableBoolean(value);
}
if (typeof value === 'bigint') {
return global._createSerializableBigInt(value);
}
if (value === undefined) {
return global._createSerializableUndefined();
}
if (value === null) {
return global._createSerializableNull();
}
return global._createSerializable(value, undefined);
}
return cloneRecursive(value);
}
/** @deprecated This function is no longer supported. */
export const makeShareableCloneOnUIRecursive = globalThis._WORKLETS_BUNDLE_MODE ? createSerializable : makeShareableCloneOnUIRecursiveLEGACY;
/**
* This function creates a value on UI with persistent state - changes to it on
* the UI thread will be seen by all worklets. Use it when you want to create a
* value that is read and written only on the UI thread.
*
* @deprecated This function is no longer supported.
*/
export function makeShareable(value) {
if (serializableMappingCache.get(value)) {
return value;
}
const handle = createSerializable({
__init: () => {
'worklet';
return value;
}
});
serializableMappingCache.set(value, handle);
return value;
}
//# sourceMappingURL=serializable.native.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
'use strict';
export const serializableMappingCache = {
set(_serializable, _serializableRef) {
// NOOP
},
get(_key) {
return null;
}
};
//# sourceMappingURL=serializableMappingCache.js.map
@@ -0,0 +1 @@
{"version":3,"names":["serializableMappingCache","set","_serializable","_serializableRef","get","_key"],"sourceRoot":"../../../src","sources":["memory/serializableMappingCache.ts"],"mappings":"AAAA,YAAY;;AAIZ,OAAO,MAAMA,wBAAwB,GAAG;EACtCC,GAAGA,CAACC,aAAqB,EAAEC,gBAAkC,EAAQ;IACnE;EAAA,CACD;EACDC,GAAGA,CAACC,IAAY,EAAqC;IACnD,OAAO,IAAI;EACb;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,29 @@
'use strict';
/**
* This symbol is used to represent a mapping from the value to itself.
*
* It's used to prevent converting a serializable that's already converted - for
* example a Shared Value that's in worklet's closure.
*/
export const serializableMappingFlag = Symbol('serializable flag');
/*
During a fast refresh, React holds the same instance of a Mutable
(that's guaranteed by `useRef`) but `serializableCache` gets regenerated and thus
becoming empty. This happens when editing the file that contains the definition of this cache.
Because of it, `createSerializable` can't find given mapping
in `serializableCache` for the Mutable and tries to clone it as if it was a regular JS object.
During cloning we use `Object.entries` to iterate over the keys which throws an error on accessing `_value`.
For convenience we moved this cache to a separate file so it doesn't scare us with red squiggles.
*/
const cache = new WeakMap();
export const serializableMappingCache = {
set(serializable, serializableRef) {
cache.set(serializable, serializableRef || serializableMappingFlag);
},
get: cache.get.bind(cache)
};
//# sourceMappingURL=serializableMappingCache.native.js.map
@@ -0,0 +1 @@
{"version":3,"names":["serializableMappingFlag","Symbol","cache","WeakMap","serializableMappingCache","set","serializable","serializableRef","get","bind"],"sourceRoot":"../../../src","sources":["memory/serializableMappingCache.native.ts"],"mappings":"AAAA,YAAY;;AAIZ;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,uBAAuB,GAAGC,MAAM,CAAC,mBAAmB,CAAC;;AAElE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMC,KAAK,GAAG,IAAIC,OAAO,CAAmC,CAAC;AAE7D,OAAO,MAAMC,wBAAwB,GAAG;EACtCC,GAAGA,CAACC,YAAoB,EAAEC,eAAiC,EAAQ;IACjEL,KAAK,CAACG,GAAG,CAACC,YAAY,EAAEC,eAAe,IAAIP,uBAAuB,CAAC;EACrE,CAAC;EACDQ,GAAG,EAAEN,KAAK,CAACM,GAAG,CAACC,IAAI,CAACP,KAAK;AAC3B,CAAC","ignoreList":[]}
@@ -0,0 +1,7 @@
'use strict';
import { WorkletsError } from '../debug/WorkletsError';
export function createSynchronizable(_value) {
throw new WorkletsError('`createSynchronizable` is not supported on web.');
}
//# sourceMappingURL=synchronizable.js.map
@@ -0,0 +1 @@
{"version":3,"names":["WorkletsError","createSynchronizable","_value"],"sourceRoot":"../../../src","sources":["memory/synchronizable.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,aAAa,QAAQ,wBAAwB;AAGtD,OAAO,SAASC,oBAAoBA,CAClCC,MAAc,EACU;EACxB,MAAM,IAAIF,aAAa,CAAC,iDAAiD,CAAC;AAC5E","ignoreList":[]}
@@ -0,0 +1,9 @@
'use strict';
import { WorkletsModule } from '../WorkletsModule/NativeWorklets';
import { createSerializable } from './serializable';
export function createSynchronizable(initialValue) {
const synchronizableRef = WorkletsModule.createSynchronizable(createSerializable(initialValue));
return globalThis.__synchronizableUnpacker(synchronizableRef);
}
//# sourceMappingURL=synchronizable.native.js.map
@@ -0,0 +1 @@
{"version":3,"names":["WorkletsModule","createSerializable","createSynchronizable","initialValue","synchronizableRef","globalThis","__synchronizableUnpacker"],"sourceRoot":"../../../src","sources":["memory/synchronizable.native.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,cAAc,QAAQ,kCAAkC;AACjE,SAASC,kBAAkB,QAAQ,gBAAgB;AAGnD,OAAO,SAASC,oBAAoBA,CAClCC,YAAoB,EACI;EACxB,MAAMC,iBAAiB,GAAGJ,cAAc,CAACE,oBAAoB,CAC3DD,kBAAkB,CAACE,YAAY,CACjC,CAAC;EAED,OAAOE,UAAU,CAACC,wBAAwB,CACxCF,iBACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,42 @@
'use strict';
import { createSerializable } from './serializable';
export function __installUnpacker() {
// TODO: Add cache for synchronizables.
const serializer = !globalThis._WORKLET || globalThis._WORKLETS_BUNDLE_MODE ? (value, _) => createSerializable(value) : globalThis._createSerializable;
function synchronizableUnpacker(synchronizableRef) {
const synchronizable = synchronizableRef;
const proxy = globalThis.__workletsModuleProxy;
synchronizable.__synchronizableRef = true;
synchronizable.getDirty = () => {
return proxy.synchronizableGetDirty(synchronizable);
};
synchronizable.getBlocking = () => {
return proxy.synchronizableGetBlocking(synchronizable);
};
synchronizable.setBlocking = valueOrFunction => {
let newValue;
if (typeof valueOrFunction === 'function') {
const func = valueOrFunction;
synchronizable.lock();
const prev = synchronizable.getBlocking();
newValue = func(prev);
proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, undefined));
synchronizable.unlock();
} else {
const value = valueOrFunction;
newValue = value;
proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, undefined));
}
};
synchronizable.lock = () => {
proxy.synchronizableLock(synchronizable);
};
synchronizable.unlock = () => {
proxy.synchronizableUnlock(synchronizable);
};
return synchronizable;
}
globalThis.__synchronizableUnpacker = synchronizableUnpacker;
}
//# sourceMappingURL=synchronizableUnpacker.native.js.map
@@ -0,0 +1 @@
{"version":3,"names":["createSerializable","__installUnpacker","serializer","globalThis","_WORKLET","_WORKLETS_BUNDLE_MODE","value","_","_createSerializable","synchronizableUnpacker","synchronizableRef","synchronizable","proxy","__workletsModuleProxy","__synchronizableRef","getDirty","synchronizableGetDirty","getBlocking","synchronizableGetBlocking","setBlocking","valueOrFunction","newValue","func","lock","prev","synchronizableSetBlocking","undefined","unlock","synchronizableLock","synchronizableUnlock","__synchronizableUnpacker"],"sourceRoot":"../../../src","sources":["memory/synchronizableUnpacker.native.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,kBAAkB,QAAQ,gBAAgB;AAGnD,OAAO,SAASC,iBAAiBA,CAAA,EAAG;EAClC;EACA,MAAMC,UAAU,GACd,CAACC,UAAU,CAACC,QAAQ,IAAID,UAAU,CAACE,qBAAqB,GACpD,CAACC,KAAc,EAAEC,CAAU,KAAKP,kBAAkB,CAACM,KAAK,CAAC,GACzDH,UAAU,CAACK,mBAAmB;EAEpC,SAASC,sBAAsBA,CAC7BC,iBAA4C,EACpB;IACxB,MAAMC,cAAc,GAClBD,iBAAsD;IACxD,MAAME,KAAK,GAAGT,UAAU,CAACU,qBAAsB;IAE/CF,cAAc,CAACG,mBAAmB,GAAG,IAAI;IACzCH,cAAc,CAACI,QAAQ,GAAG,MAAM;MAC9B,OAAOH,KAAK,CAACI,sBAAsB,CAACL,cAAc,CAAC;IACrD,CAAC;IACDA,cAAc,CAACM,WAAW,GAAG,MAAM;MACjC,OAAOL,KAAK,CAACM,yBAAyB,CAACP,cAAc,CAAC;IACxD,CAAC;IACDA,cAAc,CAACQ,WAAW,GACxBC,eAAoD,IACjD;MACH,IAAIC,QAAgB;MACpB,IAAI,OAAOD,eAAe,KAAK,UAAU,EAAE;QACzC,MAAME,IAAI,GAAGF,eAA2C;QACxDT,cAAc,CAACY,IAAI,CAAC,CAAC;QACrB,MAAMC,IAAI,GAAGb,cAAc,CAACM,WAAW,CAAC,CAAC;QACzCI,QAAQ,GAAGC,IAAI,CAACE,IAAI,CAAC;QAErBZ,KAAK,CAACa,yBAAyB,CAC7Bd,cAAc,EACdT,UAAU,CAACmB,QAAQ,EAAEK,SAAS,CAChC,CAAC;QAEDf,cAAc,CAACgB,MAAM,CAAC,CAAC;MACzB,CAAC,MAAM;QACL,MAAMrB,KAAK,GAAGc,eAAe;QAC7BC,QAAQ,GAAGf,KAAK;QAChBM,KAAK,CAACa,yBAAyB,CAC7Bd,cAAc,EACdT,UAAU,CAACmB,QAAQ,EAAEK,SAAS,CAChC,CAAC;MACH;IACF,CAAC;IACDf,cAAc,CAACY,IAAI,GAAG,MAAM;MAC1BX,KAAK,CAACgB,kBAAkB,CAACjB,cAAc,CAAC;IAC1C,CAAC;IACDA,cAAc,CAACgB,MAAM,GAAG,MAAM;MAC5Bf,KAAK,CAACiB,oBAAoB,CAAClB,cAAc,CAAC;IAC5C,CAAC;IAED,OAAOA,cAAc;EACvB;EAEAR,UAAU,CAAC2B,wBAAwB,GAAGrB,sBAAsB;AAC9D","ignoreList":[]}
@@ -0,0 +1,12 @@
'use strict';
/**
* The below type is used for HostObjects returned by the JSI API that don't
* have any accessible fields or methods but can carry data that is accessed
* from the c++ side. We add a field to the type to make it possible for
* typescript to recognize which JSI methods accept those types as arguments and
* to be able to correctly type check other methods that may use them. However,
* this field is not actually defined nor should be used for anything else as
* assigning any data to those objects will throw an error.
*/
//# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["memory/types.ts"],"mappings":"AAAA,YAAY;;AAEZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -0,0 +1,61 @@
'use strict';
function __installUnpacker() {
const workletsCache = new Map();
const handleCache = new WeakMap();
function valueUnpacker(objectToUnpack, category, remoteFunctionName) {
// eslint-disable-next-line strict
'use strict';
const workletHash = objectToUnpack.__workletHash;
if (workletHash !== undefined) {
let workletFun = workletsCache.get(workletHash);
if (workletFun === undefined) {
const initData = objectToUnpack.__initData;
if (globalThis.evalWithSourceMap) {
// if the runtime (hermes only for now) supports loading source maps
// we want to use the proper filename for the location as it guarantees
// that debugger understands and loads the source code of the file where
// the worklet is defined.
workletFun = globalThis.evalWithSourceMap('(' + initData.code + '\n)', initData.location, initData.sourceMap);
} else if (globalThis.evalWithSourceUrl) {
// if the runtime doesn't support loading source maps, in dev mode we
// can pass source url when evaluating the worklet. Now, instead of using
// the actual file location we use worklet hash, as it the allows us to
// properly symbolicate traces (see errors.ts for details)
workletFun = globalThis.evalWithSourceUrl('(' + initData.code + '\n)', `worklet_${workletHash}`);
} else {
// in release we use the regular eval to save on JSI calls
// eslint-disable-next-line no-eval
workletFun = eval('(' + initData.code + '\n)');
}
workletsCache.set(workletHash, workletFun);
}
const functionInstance = workletFun.bind(objectToUnpack);
objectToUnpack._recur = functionInstance;
return functionInstance;
} else if (objectToUnpack.__init !== undefined) {
let value = handleCache.get(objectToUnpack);
if (value === undefined) {
value = objectToUnpack.__init();
handleCache.set(objectToUnpack, value);
}
return value;
} else if (category === 'RemoteFunction') {
const fun = () => {
const label = remoteFunctionName ? `function \`${remoteFunctionName}\`` : 'anonymous function';
// eslint-disable-next-line reanimated/use-worklets-error
throw new Error(`[Worklets] Tried to synchronously call a non-worklet ${label} on the UI thread.
See https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#tried-to-synchronously-call-a-non-worklet-function-on-the-ui-thread for more details.`);
};
fun.__remoteFunction = objectToUnpack;
return fun;
} else {
// eslint-disable-next-line reanimated/use-worklets-error
throw new Error(`[Worklets] Data type in category "${category}" not recognized by value unpacker: "${globalThis._toString(objectToUnpack)}".`);
}
}
globalThis.__valueUnpacker = valueUnpacker;
}
export {};
//# sourceMappingURL=valueUnpacker.native.js.map
@@ -0,0 +1 @@
{"version":3,"names":["__installUnpacker","workletsCache","Map","handleCache","WeakMap","valueUnpacker","objectToUnpack","category","remoteFunctionName","workletHash","__workletHash","undefined","workletFun","get","initData","__initData","globalThis","evalWithSourceMap","code","location","sourceMap","evalWithSourceUrl","eval","set","functionInstance","bind","_recur","__init","value","fun","label","Error","__remoteFunction","_toString","__valueUnpacker"],"sourceRoot":"../../../src","sources":["memory/valueUnpacker.native.ts"],"mappings":"AAAA,YAAY;;AAaZ,SAASA,iBAAiBA,CAAA,EAAG;EAC3B,MAAMC,aAAa,GAAG,IAAIC,GAAG,CAAwB,CAAC;EACtD,MAAMC,WAAW,GAAG,IAAIC,OAAO,CAAkB,CAAC;EAElD,SAASC,aAAaA,CACpBC,cAA8B,EAC9BC,QAAiB,EACjBC,kBAA2B,EAClB;IACT;IACA,YAAY;;IACZ,MAAMC,WAAW,GAAGH,cAAc,CAACI,aAAa;IAChD,IAAID,WAAW,KAAKE,SAAS,EAAE;MAC7B,IAAIC,UAAU,GAAGX,aAAa,CAACY,GAAG,CAACJ,WAAW,CAAC;MAC/C,IAAIG,UAAU,KAAKD,SAAS,EAAE;QAC5B,MAAMG,QAAQ,GAAGR,cAAc,CAACS,UAAU;QAC1C,IAAIC,UAAU,CAACC,iBAAiB,EAAE;UAChC;UACA;UACA;UACA;UACAL,UAAU,GAAGI,UAAU,CAACC,iBAAiB,CACvC,GAAG,GAAGH,QAAQ,CAAEI,IAAI,GAAG,KAAK,EAC5BJ,QAAQ,CAAEK,QAAQ,EAClBL,QAAQ,CAAEM,SACZ,CAAC;QACH,CAAC,MAAM,IAAIJ,UAAU,CAACK,iBAAiB,EAAE;UACvC;UACA;UACA;UACA;UACAT,UAAU,GAAGI,UAAU,CAACK,iBAAiB,CACvC,GAAG,GAAGP,QAAQ,CAAEI,IAAI,GAAG,KAAK,EAC5B,WAAWT,WAAW,EACxB,CAAC;QACH,CAAC,MAAM;UACL;UACA;UACAG,UAAU,GAAGU,IAAI,CAAC,GAAG,GAAGR,QAAQ,CAAEI,IAAI,GAAG,KAAK,CAAC;QACjD;QACAjB,aAAa,CAACsB,GAAG,CAACd,WAAW,EAAEG,UAAW,CAAC;MAC7C;MACA,MAAMY,gBAAgB,GAAGZ,UAAU,CAAEa,IAAI,CAACnB,cAAc,CAAC;MACzDA,cAAc,CAACoB,MAAM,GAAGF,gBAAgB;MACxC,OAAOA,gBAAgB;IACzB,CAAC,MAAM,IAAIlB,cAAc,CAACqB,MAAM,KAAKhB,SAAS,EAAE;MAC9C,IAAIiB,KAAK,GAAGzB,WAAW,CAACU,GAAG,CAACP,cAAc,CAAC;MAC3C,IAAIsB,KAAK,KAAKjB,SAAS,EAAE;QACvBiB,KAAK,GAAGtB,cAAc,CAACqB,MAAM,CAAC,CAAC;QAC/BxB,WAAW,CAACoB,GAAG,CAACjB,cAAc,EAAEsB,KAAK,CAAC;MACxC;MACA,OAAOA,KAAK;IACd,CAAC,MAAM,IAAIrB,QAAQ,KAAK,gBAAgB,EAAE;MACxC,MAAMsB,GAAG,GAAGA,CAAA,KAAM;QAChB,MAAMC,KAAK,GAAGtB,kBAAkB,GAC5B,cAAcA,kBAAkB,IAAI,GACpC,oBAAoB;QACxB;QACA,MAAM,IAAIuB,KAAK,CAAC,wDAAwDD,KAAK;AACrF,uKAAuK,CAAC;MAClK,CAAC;MACDD,GAAG,CAACG,gBAAgB,GAAG1B,cAAc;MACrC,OAAOuB,GAAG;IACZ,CAAC,MAAM;MACL;MACA,MAAM,IAAIE,KAAK,CACb,qCAAqCxB,QAAQ,wCAAwCS,UAAU,CAACiB,SAAS,CACvG3B,cACF,CAAC,IACH,CAAC;IACH;EACF;EAEAU,UAAU,CAACkB,eAAe,GAAG7B,aAA8B;AAC7D;AAAC","ignoreList":[]}
+86
View File
@@ -0,0 +1,86 @@
'use strict';
import { mockedRequestAnimationFrame } from './runLoop/uiRuntime/mockedRequestAnimationFrame';
import { RuntimeKind } from './runtimeKind';
import { isWorkletFunction } from './workletFunction';
const NOOP = () => {};
const NOOP_FACTORY = () => NOOP;
const ID = value => value;
const IMMEDIATE_CALLBACK_INVOCATION = callback => callback();
globalThis._WORKLET = false;
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
globalThis._log = console.log;
globalThis._getAnimationTimestamp = () => performance.now();
// requestAnimationFrame react-native jest's setup is incorrect as it polyfills
// the method directly using setTimeout, therefore the callback doesn't get the
// expected timestamp as the only argument: https://github.com/facebook/react-native/blob/main/packages/react-native/jest/setup.js#L28
// We override this setup here to make sure that callbacks get the proper timestamps
// when executed. For non-jest environments we define requestAnimationFrame in setupRequestAnimationFrame
// @ts-ignore TypeScript uses Node definition for rAF, setTimeout, etc which returns a Timeout object rather than a number
globalThis.requestAnimationFrame = mockedRequestAnimationFrame;
const WorkletAPI = {
isShareableRef: () => true,
makeShareable: ID,
makeShareableCloneOnUIRecursive: ID,
makeShareableCloneRecursive: ID,
shareableMappingCache: new Map(),
getStaticFeatureFlag: () => false,
setDynamicFeatureFlag: NOOP,
isSynchronizable: () => false,
getRuntimeKind: () => RuntimeKind.ReactNative,
RuntimeKind: RuntimeKind,
createWorkletRuntime: NOOP_FACTORY,
runOnRuntime: ID,
scheduleOnRuntime: IMMEDIATE_CALLBACK_INVOCATION,
createSerializable: ID,
isSerializableRef: ID,
serializableMappingCache: new Map(),
createSynchronizable: ID,
callMicrotasks: NOOP,
executeOnUIRuntimeSync: ID,
runOnJS(fun) {
return (...args) => queueMicrotask(args.length ? () => fun(...args) : fun);
},
runOnUI(worklet) {
return (...args) => {
// Mocking time in Jest is tricky as both requestAnimationFrame and queueMicrotask
// callbacks run on the same queue and can be interleaved. There is no way
// to flush particular queue in Jest and the only control over mocked timers
// is by using jest.advanceTimersByTime() method which advances all types
// of timers including immediate and animation callbacks. Ideally we'd like
// to have some way here to schedule work along with React updates, but
// that's not possible, and hence in Jest environment instead of using scheduling
// mechanism we just schedule the work ommiting the queue. This is ok for the
// uses that we currently have but may not be ok for future tests that we write.
mockedRequestAnimationFrame(() => {
worklet(...args);
});
};
},
runOnUIAsync(worklet) {
return (...args) => {
return new Promise(resolve => {
mockedRequestAnimationFrame(() => {
const result = worklet(...args);
resolve(result);
});
});
};
},
runOnUISync: IMMEDIATE_CALLBACK_INVOCATION,
scheduleOnRN(fun, ...args) {
WorkletAPI.runOnJS(fun)(...args);
},
scheduleOnUI(worklet, ...args) {
WorkletAPI.runOnUI(worklet)(...args);
},
// eslint-disable-next-line camelcase
unstable_eventLoopTask: NOOP_FACTORY,
isWorkletFunction: isWorkletFunction,
WorkletsModule: {}
};
module.exports = {
__esModule: true,
...WorkletAPI
};
//# sourceMappingURL=mock.js.map
@@ -0,0 +1 @@
{"version":3,"names":["mockedRequestAnimationFrame","RuntimeKind","isWorkletFunction","NOOP","NOOP_FACTORY","ID","value","IMMEDIATE_CALLBACK_INVOCATION","callback","globalThis","_WORKLET","__RUNTIME_KIND","ReactNative","_log","console","log","_getAnimationTimestamp","performance","now","requestAnimationFrame","WorkletAPI","isShareableRef","makeShareable","makeShareableCloneOnUIRecursive","makeShareableCloneRecursive","shareableMappingCache","Map","getStaticFeatureFlag","setDynamicFeatureFlag","isSynchronizable","getRuntimeKind","createWorkletRuntime","runOnRuntime","scheduleOnRuntime","createSerializable","isSerializableRef","serializableMappingCache","createSynchronizable","callMicrotasks","executeOnUIRuntimeSync","runOnJS","fun","args","queueMicrotask","length","runOnUI","worklet","runOnUIAsync","Promise","resolve","result","runOnUISync","scheduleOnRN","scheduleOnUI","unstable_eventLoopTask","WorkletsModule","module","exports","__esModule"],"sourceRoot":"../../src","sources":["mock.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,2BAA2B,QAAQ,iDAAiD;AAC7F,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,iBAAiB,QAAQ,mBAAmB;AAErD,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AACrB,MAAMC,YAAY,GAAGA,CAAA,KAAMD,IAAI;AAC/B,MAAME,EAAE,GAAYC,KAAa,IAAKA,KAAK;AAC3C,MAAMC,6BAA6B,GAAeC,QAAyB,IACzEA,QAAQ,CAAC,CAAC;AAEZC,UAAU,CAACC,QAAQ,GAAG,KAAK;AAC3BD,UAAU,CAACE,cAAc,GAAGV,WAAW,CAACW,WAAW;AACnDH,UAAU,CAACI,IAAI,GAAGC,OAAO,CAACC,GAAG;AAC7BN,UAAU,CAACO,sBAAsB,GAAG,MAAMC,WAAW,CAACC,GAAG,CAAC,CAAC;AAC3D;AACA;AACA;AACA;AACA;AACA;AACAT,UAAU,CAACU,qBAAqB,GAAGnB,2BAA2B;AAE9D,MAAMoB,UAAU,GAAG;EACjBC,cAAc,EAAEA,CAAA,KAAM,IAAI;EAC1BC,aAAa,EAAEjB,EAAE;EACjBkB,+BAA+B,EAAElB,EAAE;EACnCmB,2BAA2B,EAAEnB,EAAE;EAC/BoB,qBAAqB,EAAE,IAAIC,GAAG,CAAC,CAAC;EAChCC,oBAAoB,EAAEA,CAAA,KAAM,KAAK;EACjCC,qBAAqB,EAAEzB,IAAI;EAC3B0B,gBAAgB,EAAEA,CAAA,KAAM,KAAK;EAC7BC,cAAc,EAAEA,CAAA,KAAM7B,WAAW,CAACW,WAAW;EAC7CX,WAAW,EAAEA,WAAW;EACxB8B,oBAAoB,EAAE3B,YAAY;EAClC4B,YAAY,EAAE3B,EAAE;EAChB4B,iBAAiB,EAAE1B,6BAA6B;EAChD2B,kBAAkB,EAAE7B,EAAE;EACtB8B,iBAAiB,EAAE9B,EAAE;EACrB+B,wBAAwB,EAAE,IAAIV,GAAG,CAAC,CAAC;EACnCW,oBAAoB,EAAEhC,EAAE;EACxBiC,cAAc,EAAEnC,IAAI;EACpBoC,sBAAsB,EAAElC,EAAE;EAC1BmC,OAAOA,CACLC,GAAmC,EACV;IACzB,OAAO,CAAC,GAAGC,IAAI,KACbC,cAAc,CACZD,IAAI,CAACE,MAAM,GACP,MAAOH,GAAG,CAAoC,GAAGC,IAAI,CAAC,GACrDD,GACP,CAAC;EACL,CAAC;EACDI,OAAOA,CACLC,OAAuC,EACd;IACzB,OAAO,CAAC,GAAGJ,IAAI,KAAK;MAClB;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA1C,2BAA2B,CAAC,MAAM;QAChC8C,OAAO,CAAC,GAAGJ,IAAI,CAAC;MAClB,CAAC,CAAC;IACJ,CAAC;EACH,CAAC;EACDK,YAAYA,CACVD,OAAuC,EACE;IACzC,OAAO,CAAC,GAAGJ,IAAU,KAAK;MACxB,OAAO,IAAIM,OAAO,CAAeC,OAAO,IAAK;QAC3CjD,2BAA2B,CAAC,MAAM;UAChC,MAAMkD,MAAM,GAAGJ,OAAO,CAAC,GAAGJ,IAAI,CAAC;UAC/BO,OAAO,CAACC,MAAM,CAAC;QACjB,CAAC,CAAC;MACJ,CAAC,CAAC;IACJ,CAAC;EACH,CAAC;EACDC,WAAW,EAAE5C,6BAA6B;EAC1C6C,YAAYA,CACVX,GAAmC,EACnC,GAAGC,IAAU,EACP;IACNtB,UAAU,CAACoB,OAAO,CAACC,GAAG,CAAC,CAAC,GAAGC,IAAI,CAAC;EAClC,CAAC;EACDW,YAAYA,CACVP,OAAuC,EACvC,GAAGJ,IAAU,EACP;IACNtB,UAAU,CAACyB,OAAO,CAACC,OAAO,CAAC,CAAC,GAAGJ,IAAI,CAAC;EACtC,CAAC;EACD;EACAY,sBAAsB,EAAElD,YAAY;EACpCF,iBAAiB,EAAEA,iBAAiB;EACpCqD,cAAc,EAAE,CAAC;AACnB,CAAC;AAEDC,MAAM,CAACC,OAAO,GAAG;EACfC,UAAU,EAAE,IAAI;EAChB,GAAGtC;AACL,CAAC","ignoreList":[]}
@@ -0,0 +1,8 @@
'use strict';
import { Platform } from 'react-native';
export const IS_JEST = !!process.env.JEST_WORKER_ID;
export const IS_WEB = Platform.OS === 'web';
export const IS_WINDOWS = Platform.OS === 'windows';
export const SHOULD_BE_USE_WEB = IS_JEST || IS_WEB || IS_WINDOWS;
//# sourceMappingURL=platformChecker.js.map
@@ -0,0 +1 @@
{"version":3,"names":["Platform","IS_JEST","process","env","JEST_WORKER_ID","IS_WEB","OS","IS_WINDOWS","SHOULD_BE_USE_WEB"],"sourceRoot":"../../src","sources":["platformChecker.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,QAAQ,QAAQ,cAAc;AAEvC,OAAO,MAAMC,OAAgB,GAAG,CAAC,CAACC,OAAO,CAACC,GAAG,CAACC,cAAc;AAC5D,OAAO,MAAMC,MAAe,GAAGL,QAAQ,CAACM,EAAE,KAAK,KAAK;AACpD,OAAO,MAAMC,UAAmB,GAAGP,QAAQ,CAACM,EAAE,KAAK,SAAS;AAC5D,OAAO,MAAME,iBAA0B,GAAGP,OAAO,IAAII,MAAM,IAAIE,UAAU","ignoreList":[]}
@@ -0,0 +1,4 @@
'use strict';
export const IS_JEST = false;
//# sourceMappingURL=platformChecker.native.js.map
@@ -0,0 +1 @@
{"version":3,"names":["IS_JEST"],"sourceRoot":"../../src","sources":["platformChecker.native.ts"],"mappings":"AAAA,YAAY;;AAEZ,OAAO,MAAMA,OAAO,GAAG,KAAK","ignoreList":[]}
@@ -0,0 +1,6 @@
'use strict';
// This file works by accident - currently Builder Bob doesn't move `.d.ts` files to output types.
// If it ever breaks, we should address it so we'd not pollute the user's global namespace.
export {};
//# sourceMappingURL=privateGlobals.d.js.map
@@ -0,0 +1 @@
{"version":3,"names":[],"sourceRoot":"../../src","sources":["privateGlobals.d.ts"],"mappings":"AAAA,YAAY;;AAEZ;AACA;AAAA","ignoreList":[]}
@@ -0,0 +1,15 @@
'use strict';
export function setupSetImmediate() {
'worklet';
const setImmediatePolyfill = (callback, ...args) => {
return setTimeout(callback, 0, ...args);
};
const clearImmediatePolyfill = immediateHandle => {
clearTimeout(immediateHandle);
};
globalThis.setImmediate = setImmediatePolyfill;
globalThis.clearImmediate = clearImmediatePolyfill;
}
//# sourceMappingURL=setImmediatePolyfill.js.map
@@ -0,0 +1 @@
{"version":3,"names":["setupSetImmediate","setImmediatePolyfill","callback","args","setTimeout","clearImmediatePolyfill","immediateHandle","clearTimeout","globalThis","setImmediate","clearImmediate"],"sourceRoot":"../../../../src","sources":["runLoop/common/setImmediatePolyfill.ts"],"mappings":"AAAA,YAAY;;AAEZ,OAAO,SAASA,iBAAiBA,CAAA,EAAG;EAClC,SAAS;;EAET,MAAMC,oBAAoB,GAAGA,CAC3BC,QAAsC,EACtC,GAAGC,IAAe,KACf;IACH,OAAOC,UAAU,CAACF,QAAQ,EAAE,CAAC,EAAE,GAAGC,IAAI,CAAC;EACzC,CAAC;EAED,MAAME,sBAAsB,GAAIC,eAAuB,IAAK;IAC1DC,YAAY,CAACD,eAAe,CAAC;EAC/B,CAAC;EAEDE,UAAU,CAACC,YAAY,GACrBR,oBAAsD;EACxDO,UAAU,CAACE,cAAc,GAAGL,sBAA+C;AAC7E","ignoreList":[]}
@@ -0,0 +1,26 @@
'use strict';
export function setupSetInterval() {
'worklet';
const intervalHandleToTimeoutHandle = new Map();
const setIntervalPolyfill = (callback, delay = 0, ...args) => {
let intervalHandle = 0;
const repeatingCallback = () => {
const timeoutHandle = setTimeout(repeatingCallback, delay);
intervalHandleToTimeoutHandle.set(intervalHandle, timeoutHandle);
callback(...args);
};
intervalHandle = setTimeout(repeatingCallback, delay);
intervalHandleToTimeoutHandle.set(intervalHandle, intervalHandle);
return intervalHandle;
};
const clearIntervalPolyfill = intervalHandle => {
const timeoutHandle = intervalHandleToTimeoutHandle.get(intervalHandle);
clearTimeout(timeoutHandle);
intervalHandleToTimeoutHandle.delete(intervalHandle);
};
globalThis.setInterval = setIntervalPolyfill;
globalThis.clearInterval = clearIntervalPolyfill;
}
//# sourceMappingURL=setIntervalPolyfill.js.map
@@ -0,0 +1 @@
{"version":3,"names":["setupSetInterval","intervalHandleToTimeoutHandle","Map","setIntervalPolyfill","callback","delay","args","intervalHandle","repeatingCallback","timeoutHandle","setTimeout","set","clearIntervalPolyfill","get","clearTimeout","delete","globalThis","setInterval","clearInterval"],"sourceRoot":"../../../../src","sources":["runLoop/common/setIntervalPolyfill.ts"],"mappings":"AAAA,YAAY;;AAEZ,OAAO,SAASA,gBAAgBA,CAAA,EAAG;EACjC,SAAS;;EAET,MAAMC,6BAAkD,GAAG,IAAIC,GAAG,CAAC,CAAC;EAEpE,MAAMC,mBAAmB,GAAGA,CAC1BC,QAAsC,EACtCC,KAAa,GAAG,CAAC,EACjB,GAAGC,IAAe,KACf;IACH,IAAIC,cAAc,GAAG,CAAC;IAEtB,MAAMC,iBAAiB,GAAGA,CAAA,KAAM;MAC9B,MAAMC,aAAa,GAAGC,UAAU,CAC9BF,iBAAiB,EACjBH,KACF,CAAsB;MACtBJ,6BAA6B,CAACU,GAAG,CAACJ,cAAc,EAAEE,aAAa,CAAC;MAChEL,QAAQ,CAAC,GAAGE,IAAI,CAAC;IACnB,CAAC;IAEDC,cAAc,GAAGG,UAAU,CAACF,iBAAiB,EAAEH,KAAK,CAAsB;IAC1EJ,6BAA6B,CAACU,GAAG,CAACJ,cAAc,EAAEA,cAAc,CAAC;IAEjE,OAAOA,cAAc;EACvB,CAAC;EAED,MAAMK,qBAAqB,GAAIL,cAAsB,IAAK;IACxD,MAAME,aAAa,GAAGR,6BAA6B,CAACY,GAAG,CAACN,cAAc,CAAC;IACvEO,YAAY,CAACL,aAAa,CAAC;IAC3BR,6BAA6B,CAACc,MAAM,CAACR,cAAc,CAAC;EACtD,CAAC;EAEDS,UAAU,CAACC,WAAW,GAAGd,mBAAyC;EAClEa,UAAU,CAACE,aAAa,GAAGN,qBAA6C;AAC1E","ignoreList":[]}
@@ -0,0 +1,10 @@
'use strict';
/**
* This is Jest implementation of `requestAnimationFrame` that is required by
* React Native for test purposes.
*/
export function mockedRequestAnimationFrame(callback) {
return setTimeout(() => callback(performance.now()), 0);
}
//# sourceMappingURL=mockedRequestAnimationFrame.js.map
@@ -0,0 +1 @@
{"version":3,"names":["mockedRequestAnimationFrame","callback","setTimeout","performance","now"],"sourceRoot":"../../../../src","sources":["runLoop/uiRuntime/mockedRequestAnimationFrame.ts"],"mappings":"AAAA,YAAY;;AAEZ;AACA;AACA;AACA;AACA,OAAO,SAASA,2BAA2BA,CACzCC,QAAqC,EACN;EAC/B,OAAOC,UAAU,CAAC,MAAMD,QAAQ,CAACE,WAAW,CAACC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACzD","ignoreList":[]}
@@ -0,0 +1,52 @@
'use strict';
import { callMicrotasks } from '../../threads';
export function setupRequestAnimationFrame() {
'worklet';
const nativeRequestAnimationFrame = globalThis.requestAnimationFrame;
let queuedCallbacks = [];
let queuedCallbacksBegin = 0;
let queuedCallbacksEnd = 0;
let flushedCallbacks = queuedCallbacks;
let flushedCallbacksBegin = 0;
let flushedCallbacksEnd = 0;
let flushRequested = false;
globalThis.__flushAnimationFrame = timestamp => {
flushedCallbacks = queuedCallbacks;
queuedCallbacks = [];
flushedCallbacksBegin = queuedCallbacksBegin;
flushedCallbacksEnd = queuedCallbacksEnd;
queuedCallbacksBegin = queuedCallbacksEnd;
for (const callback of flushedCallbacks) {
callback(timestamp);
}
flushedCallbacksBegin = flushedCallbacksEnd;
callMicrotasks();
};
globalThis.requestAnimationFrame = callback => {
const handle = queuedCallbacksEnd++;
queuedCallbacks.push(callback);
if (!flushRequested) {
flushRequested = true;
nativeRequestAnimationFrame(timestamp => {
flushRequested = false;
globalThis.__frameTimestamp = timestamp;
globalThis.__flushAnimationFrame(timestamp);
globalThis.__frameTimestamp = undefined;
});
}
return handle;
};
globalThis.cancelAnimationFrame = handle => {
if (handle < flushedCallbacksBegin || handle >= queuedCallbacksEnd) {
return;
}
if (handle < flushedCallbacksEnd) {
flushedCallbacks[handle - flushedCallbacksBegin] = () => {};
} else {
queuedCallbacks[handle - queuedCallbacksBegin] = () => {};
}
};
}
//# sourceMappingURL=requestAnimationFrame.js.map
@@ -0,0 +1 @@
{"version":3,"names":["callMicrotasks","setupRequestAnimationFrame","nativeRequestAnimationFrame","globalThis","requestAnimationFrame","queuedCallbacks","queuedCallbacksBegin","queuedCallbacksEnd","flushedCallbacks","flushedCallbacksBegin","flushedCallbacksEnd","flushRequested","__flushAnimationFrame","timestamp","callback","handle","push","__frameTimestamp","undefined","cancelAnimationFrame"],"sourceRoot":"../../../../src","sources":["runLoop/uiRuntime/requestAnimationFrame.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,cAAc,QAAQ,eAAe;AAE9C,OAAO,SAASC,0BAA0BA,CAAA,EAAG;EAC3C,SAAS;;EACT,MAAMC,2BAA2B,GAAGC,UAAU,CAACC,qBAAqB;EAEpE,IAAIC,eAAgD,GAAG,EAAE;EACzD,IAAIC,oBAAoB,GAAG,CAAC;EAC5B,IAAIC,kBAAkB,GAAG,CAAC;EAE1B,IAAIC,gBAAgB,GAAGH,eAAe;EACtC,IAAII,qBAAqB,GAAG,CAAC;EAC7B,IAAIC,mBAAmB,GAAG,CAAC;EAE3B,IAAIC,cAAc,GAAG,KAAK;EAE1BR,UAAU,CAACS,qBAAqB,GAAIC,SAAiB,IAAK;IACxDL,gBAAgB,GAAGH,eAAe;IAClCA,eAAe,GAAG,EAAE;IAEpBI,qBAAqB,GAAGH,oBAAoB;IAC5CI,mBAAmB,GAAGH,kBAAkB;IACxCD,oBAAoB,GAAGC,kBAAkB;IAEzC,KAAK,MAAMO,QAAQ,IAAIN,gBAAgB,EAAE;MACvCM,QAAQ,CAACD,SAAS,CAAC;IACrB;IAEAJ,qBAAqB,GAAGC,mBAAmB;IAE3CV,cAAc,CAAC,CAAC;EAClB,CAAC;EAEDG,UAAU,CAACC,qBAAqB,GAC9BU,QAAqC,IAC1B;IACX,MAAMC,MAAM,GAAGR,kBAAkB,EAAE;IAEnCF,eAAe,CAACW,IAAI,CAACF,QAAQ,CAAC;IAC9B,IAAI,CAACH,cAAc,EAAE;MACnBA,cAAc,GAAG,IAAI;MAErBT,2BAA2B,CAAEW,SAAS,IAAK;QACzCF,cAAc,GAAG,KAAK;QACtBR,UAAU,CAACc,gBAAgB,GAAGJ,SAAS;QACvCV,UAAU,CAACS,qBAAqB,CAACC,SAAS,CAAC;QAC3CV,UAAU,CAACc,gBAAgB,GAAGC,SAAS;MACzC,CAAC,CAAC;IACJ;IACA,OAAOH,MAAM;EACf,CAAC;EAEDZ,UAAU,CAACgB,oBAAoB,GAAIJ,MAAc,IAAK;IACpD,IAAIA,MAAM,GAAGN,qBAAqB,IAAIM,MAAM,IAAIR,kBAAkB,EAAE;MAClE;IACF;IAEA,IAAIQ,MAAM,GAAGL,mBAAmB,EAAE;MAChCF,gBAAgB,CAACO,MAAM,GAAGN,qBAAqB,CAAC,GAAG,MAAM,CAAC,CAAC;IAC7D,CAAC,MAAM;MACLJ,eAAe,CAACU,MAAM,GAAGT,oBAAoB,CAAC,GAAG,MAAM,CAAC,CAAC;IAC3D;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,32 @@
'use strict';
export function setupSetTimeout() {
'worklet';
const timeoutHandleToRafHandle = new Map();
const setTimeoutPolyfill = (callback, delay = 0, ...args) => {
const start = performance.now();
let timeoutHandle = 0;
const rafCallback = () => {
const now = performance.now();
if (now - start >= delay) {
callback(...args);
timeoutHandleToRafHandle.delete(timeoutHandle);
} else {
const rafHandle = requestAnimationFrame(rafCallback);
timeoutHandleToRafHandle.set(timeoutHandle, rafHandle);
}
};
timeoutHandle = requestAnimationFrame(rafCallback);
timeoutHandleToRafHandle.set(timeoutHandle, timeoutHandle);
return timeoutHandle;
};
const clearTimeoutPolyfill = timeoutHandle => {
const rafHandle = timeoutHandleToRafHandle.get(timeoutHandle);
timeoutHandleToRafHandle.delete(timeoutHandle);
cancelAnimationFrame(rafHandle);
};
globalThis.setTimeout = setTimeoutPolyfill;
globalThis.clearTimeout = clearTimeoutPolyfill;
}
//# sourceMappingURL=setTimeoutPolyfill.js.map
@@ -0,0 +1 @@
{"version":3,"names":["setupSetTimeout","timeoutHandleToRafHandle","Map","setTimeoutPolyfill","callback","delay","args","start","performance","now","timeoutHandle","rafCallback","delete","rafHandle","requestAnimationFrame","set","clearTimeoutPolyfill","get","cancelAnimationFrame","globalThis","setTimeout","clearTimeout"],"sourceRoot":"../../../../src","sources":["runLoop/uiRuntime/setTimeoutPolyfill.ts"],"mappings":"AAAA,YAAY;;AAEZ,OAAO,SAASA,eAAeA,CAAA,EAAG;EAChC,SAAS;;EAET,MAAMC,wBAA6C,GAAG,IAAIC,GAAG,CAAC,CAAC;EAE/D,MAAMC,kBAAkB,GAAGA,CACzBC,QAAsC,EACtCC,KAAa,GAAG,CAAC,EACjB,GAAGC,IAAe,KACf;IACH,MAAMC,KAAK,GAAGC,WAAW,CAACC,GAAG,CAAC,CAAC;IAC/B,IAAIC,aAAa,GAAG,CAAC;IAErB,MAAMC,WAAW,GAAGA,CAAA,KAAM;MACxB,MAAMF,GAAG,GAAGD,WAAW,CAACC,GAAG,CAAC,CAAC;MAC7B,IAAIA,GAAG,GAAGF,KAAK,IAAIF,KAAK,EAAE;QACxBD,QAAQ,CAAC,GAAGE,IAAI,CAAC;QACjBL,wBAAwB,CAACW,MAAM,CAACF,aAAa,CAAC;MAChD,CAAC,MAAM;QACL,MAAMG,SAAS,GAAGC,qBAAqB,CAACH,WAAW,CAAC;QACpDV,wBAAwB,CAACc,GAAG,CAACL,aAAa,EAAEG,SAAS,CAAC;MACxD;IACF,CAAC;IAEDH,aAAa,GAAGI,qBAAqB,CAACH,WAAW,CAAC;IAClDV,wBAAwB,CAACc,GAAG,CAACL,aAAa,EAAEA,aAAa,CAAC;IAC1D,OAAOA,aAAa;EACtB,CAAC;EAED,MAAMM,oBAAoB,GAAIN,aAAqB,IAAK;IACtD,MAAMG,SAAS,GAAGZ,wBAAwB,CAACgB,GAAG,CAACP,aAAa,CAAC;IAC7DT,wBAAwB,CAACW,MAAM,CAACF,aAAa,CAAC;IAC9CQ,oBAAoB,CAACL,SAAU,CAAC;EAClC,CAAC;EAEDM,UAAU,CAACC,UAAU,GAAGjB,kBAAuC;EAC/DgB,UAAU,CAACE,YAAY,GAAGL,oBAA2C;AACvE","ignoreList":[]}
@@ -0,0 +1,19 @@
'use strict';
import { setupSetImmediate } from '../common/setImmediatePolyfill';
import { setupSetInterval } from '../common/setIntervalPolyfill';
import { setupQueueMicrotask } from './queueMicrotask';
import { setupRequestAnimationFrame } from './requestAnimationFramePolyfill';
import { setupSetTimeout } from './setTimeout';
import { setupTaskQueue } from './taskQueue';
export function setupRunLoop(animationQueuePollingRate) {
'worklet';
setupTaskQueue();
setupQueueMicrotask();
setupSetTimeout();
setupRequestAnimationFrame(animationQueuePollingRate);
setupSetImmediate();
setupSetInterval();
}
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"names":["setupSetImmediate","setupSetInterval","setupQueueMicrotask","setupRequestAnimationFrame","setupSetTimeout","setupTaskQueue","setupRunLoop","animationQueuePollingRate"],"sourceRoot":"../../../../src","sources":["runLoop/workletRuntime/index.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,iBAAiB,QAAQ,gCAAgC;AAClE,SAASC,gBAAgB,QAAQ,+BAA+B;AAChE,SAASC,mBAAmB,QAAQ,kBAAkB;AACtD,SAASC,0BAA0B,QAAQ,iCAAiC;AAC5E,SAASC,eAAe,QAAQ,cAAc;AAC9C,SAASC,cAAc,QAAQ,aAAa;AAE5C,OAAO,SAASC,YAAYA,CAACC,yBAAiC,EAAE;EAC9D,SAAS;;EACTF,cAAc,CAAC,CAAC;EAChBH,mBAAmB,CAAC,CAAC;EACrBE,eAAe,CAAC,CAAC;EACjBD,0BAA0B,CAACI,yBAAyB,CAAC;EACrDP,iBAAiB,CAAC,CAAC;EACnBC,gBAAgB,CAAC,CAAC;AACpB","ignoreList":[]}
@@ -0,0 +1,11 @@
'use strict';
import { pushMicrotask } from './taskQueue';
export function setupQueueMicrotask() {
'worklet';
globalThis.queueMicrotask = function (callback, ...args) {
pushMicrotask(() => callback(...args));
};
}
//# sourceMappingURL=queueMicrotask.js.map
@@ -0,0 +1 @@
{"version":3,"names":["pushMicrotask","setupQueueMicrotask","globalThis","queueMicrotask","callback","args"],"sourceRoot":"../../../../src","sources":["runLoop/workletRuntime/queueMicrotask.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,aAAa,QAAQ,aAAa;AAE3C,OAAO,SAASC,mBAAmBA,CAAA,EAAG;EACpC,SAAS;;EACTC,UAAU,CAACC,cAAc,GAAG,UAC1BC,QAAsC,EACtC,GAAGC,IAAe,EAClB;IACAL,aAAa,CAAC,MAAMI,QAAQ,CAAC,GAAGC,IAAI,CAAC,CAAC;EACxC,CAA0B;AAC5B","ignoreList":[]}
@@ -0,0 +1,48 @@
'use strict';
export function setupRequestAnimationFrame(animationQueuePollingRate) {
'worklet';
const timeoutInterval = animationQueuePollingRate;
let queuedCallbacks = [];
let queuedCallbacksBegin = 0;
let queuedCallbacksEnd = 0;
let flushedCallbacks = queuedCallbacks;
let flushedCallbacksBegin = 0;
let flushedCallbacksEnd = 0;
let flushRequested = false;
function flushAnimationFrame() {
flushRequested = false;
const timestamp = performance.now();
flushedCallbacks = queuedCallbacks;
queuedCallbacks = [];
flushedCallbacksBegin = queuedCallbacksBegin;
flushedCallbacksEnd = queuedCallbacksEnd;
queuedCallbacksBegin = queuedCallbacksEnd;
for (const callback of flushedCallbacks) {
callback(timestamp);
globalThis.__flushMicrotasks();
}
flushedCallbacksBegin = flushedCallbacksEnd;
}
globalThis.requestAnimationFrame = callback => {
const handle = queuedCallbacksEnd++;
queuedCallbacks.push(callback);
if (!flushRequested) {
flushRequested = true;
setTimeout(flushAnimationFrame, timeoutInterval);
}
return handle;
};
globalThis.cancelAnimationFrame = handle => {
if (handle < flushedCallbacksBegin || handle >= queuedCallbacksEnd) {
return;
}
if (handle < flushedCallbacksEnd) {
flushedCallbacks[handle - flushedCallbacksBegin] = () => {};
} else {
queuedCallbacks[handle - queuedCallbacksBegin] = () => {};
}
};
}
//# sourceMappingURL=requestAnimationFramePolyfill.js.map
@@ -0,0 +1 @@
{"version":3,"names":["setupRequestAnimationFrame","animationQueuePollingRate","timeoutInterval","queuedCallbacks","queuedCallbacksBegin","queuedCallbacksEnd","flushedCallbacks","flushedCallbacksBegin","flushedCallbacksEnd","flushRequested","flushAnimationFrame","timestamp","performance","now","callback","globalThis","__flushMicrotasks","requestAnimationFrame","handle","push","setTimeout","cancelAnimationFrame"],"sourceRoot":"../../../../src","sources":["runLoop/workletRuntime/requestAnimationFramePolyfill.ts"],"mappings":"AAAA,YAAY;;AAEZ,OAAO,SAASA,0BAA0BA,CAACC,yBAAiC,EAAE;EAC5E,SAAS;;EACT,MAAMC,eAAe,GAAGD,yBAAyB;EAEjD,IAAIE,eAAgD,GAAG,EAAE;EACzD,IAAIC,oBAAoB,GAAG,CAAC;EAC5B,IAAIC,kBAAkB,GAAG,CAAC;EAE1B,IAAIC,gBAAgB,GAAGH,eAAe;EACtC,IAAII,qBAAqB,GAAG,CAAC;EAC7B,IAAIC,mBAAmB,GAAG,CAAC;EAE3B,IAAIC,cAAc,GAAG,KAAK;EAE1B,SAASC,mBAAmBA,CAAA,EAAG;IAC7BD,cAAc,GAAG,KAAK;IACtB,MAAME,SAAS,GAAGC,WAAW,CAACC,GAAG,CAAC,CAAC;IAEnCP,gBAAgB,GAAGH,eAAe;IAClCA,eAAe,GAAG,EAAE;IAEpBI,qBAAqB,GAAGH,oBAAoB;IAC5CI,mBAAmB,GAAGH,kBAAkB;IACxCD,oBAAoB,GAAGC,kBAAkB;IAEzC,KAAK,MAAMS,QAAQ,IAAIR,gBAAgB,EAAE;MACvCQ,QAAQ,CAACH,SAAS,CAAC;MACnBI,UAAU,CAACC,iBAAiB,CAAC,CAAC;IAChC;IAEAT,qBAAqB,GAAGC,mBAAmB;EAC7C;EAEAO,UAAU,CAACE,qBAAqB,GAC9BH,QAAqC,IAC1B;IACX,MAAMI,MAAM,GAAGb,kBAAkB,EAAE;IAEnCF,eAAe,CAACgB,IAAI,CAACL,QAAQ,CAAC;IAC9B,IAAI,CAACL,cAAc,EAAE;MACnBA,cAAc,GAAG,IAAI;MAErBW,UAAU,CAACV,mBAAmB,EAAER,eAAe,CAAC;IAClD;IACA,OAAOgB,MAAM;EACf,CAAC;EAEDH,UAAU,CAACM,oBAAoB,GAAIH,MAAc,IAAK;IACpD,IAAIA,MAAM,GAAGX,qBAAqB,IAAIW,MAAM,IAAIb,kBAAkB,EAAE;MAClE;IACF;IAEA,IAAIa,MAAM,GAAGV,mBAAmB,EAAE;MAChCF,gBAAgB,CAACY,MAAM,GAAGX,qBAAqB,CAAC,GAAG,MAAM,CAAC,CAAC;IAC7D,CAAC,MAAM;MACLJ,eAAe,CAACe,MAAM,GAAGd,oBAAoB,CAAC,GAAG,MAAM,CAAC,CAAC;IAC3D;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,28 @@
'use strict';
import { pushTask } from './taskQueue';
export function setupSetTimeout() {
'worklet';
const pendingHandlers = new Set();
let ID = 0;
const setTimeoutPolyfill = (callback, delay = 0, ...args) => {
const handlerId = ID++;
const timeoutCallback = () => {
if (!pendingHandlers.has(handlerId)) {
return;
}
callback(...args);
pendingHandlers.delete(handlerId);
};
pendingHandlers.add(handlerId);
pushTask(timeoutCallback, handlerId, delay);
return handlerId;
};
const clearTimeoutPolyfill = timeoutHandle => {
pendingHandlers.delete(timeoutHandle);
};
globalThis.setTimeout = setTimeoutPolyfill;
globalThis.clearTimeout = clearTimeoutPolyfill;
}
//# sourceMappingURL=setTimeout.js.map
@@ -0,0 +1 @@
{"version":3,"names":["pushTask","setupSetTimeout","pendingHandlers","Set","ID","setTimeoutPolyfill","callback","delay","args","handlerId","timeoutCallback","has","delete","add","clearTimeoutPolyfill","timeoutHandle","globalThis","setTimeout","clearTimeout"],"sourceRoot":"../../../../src","sources":["runLoop/workletRuntime/setTimeout.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,QAAQ,QAAQ,aAAa;AAEtC,OAAO,SAASC,eAAeA,CAAA,EAAG;EAChC,SAAS;;EAET,MAAMC,eAA4B,GAAG,IAAIC,GAAG,CAAC,CAAC;EAC9C,IAAIC,EAAE,GAAG,CAAC;EAEV,MAAMC,kBAAkB,GAAGA,CACzBC,QAAsC,EACtCC,KAAa,GAAG,CAAC,EACjB,GAAGC,IAAe,KACf;IACH,MAAMC,SAAS,GAAGL,EAAE,EAAE;IAEtB,MAAMM,eAAe,GAAGA,CAAA,KAAM;MAC5B,IAAI,CAACR,eAAe,CAACS,GAAG,CAACF,SAAS,CAAC,EAAE;QACnC;MACF;MACAH,QAAQ,CAAC,GAAGE,IAAI,CAAC;MACjBN,eAAe,CAACU,MAAM,CAACH,SAAS,CAAC;IACnC,CAAC;IAEDP,eAAe,CAACW,GAAG,CAACJ,SAAS,CAAC;IAC9BT,QAAQ,CAACU,eAAe,EAAED,SAAS,EAAEF,KAAK,CAAC;IAC3C,OAAOE,SAAS;EAClB,CAAC;EAED,MAAMK,oBAAoB,GAAIC,aAAqB,IAAK;IACtDb,eAAe,CAACU,MAAM,CAACG,aAAa,CAAC;EACvC,CAAC;EAEDC,UAAU,CAACC,UAAU,GAAGZ,kBAAuC;EAC/DW,UAAU,CAACE,YAAY,GAAGJ,oBAA2C;AACvE","ignoreList":[]}
@@ -0,0 +1,37 @@
'use strict';
export function setupTaskQueue() {
'worklet';
const queue = {
microtasks: [],
timeoutCallbacks: new Map()
};
globalThis._taskQueue = queue;
globalThis.__runTimeoutCallback = function (handlerId) {
const task = queue.timeoutCallbacks.get(handlerId);
task?.();
queue.timeoutCallbacks.delete(handlerId);
globalThis.__flushMicrotasks();
};
globalThis.__flushMicrotasks = function () {
for (let i = 0; i < queue.microtasks.length; i++) {
queue.microtasks[i]();
}
queue.microtasks = [];
};
}
export function pushMicrotask(callback) {
'worklet';
const queue = globalThis._taskQueue;
queue.microtasks.push(callback);
}
export function pushTask(callback, handlerId, delay) {
'worklet';
const queue = globalThis._taskQueue;
queue.timeoutCallbacks.set(handlerId, callback);
globalThis._scheduleTimeoutCallback(delay, handlerId);
}
//# sourceMappingURL=taskQueue.js.map
@@ -0,0 +1 @@
{"version":3,"names":["setupTaskQueue","queue","microtasks","timeoutCallbacks","Map","globalThis","_taskQueue","__runTimeoutCallback","handlerId","task","get","delete","__flushMicrotasks","i","length","pushMicrotask","callback","push","pushTask","delay","set","_scheduleTimeoutCallback"],"sourceRoot":"../../../../src","sources":["runLoop/workletRuntime/taskQueue.ts"],"mappings":"AAAA,YAAY;;AASZ,OAAO,SAASA,cAAcA,CAAA,EAAG;EAC/B,SAAS;;EACT,MAAMC,KAAY,GAAG;IACnBC,UAAU,EAAE,EAAE;IACdC,gBAAgB,EAAE,IAAIC,GAAG,CAAC;EAC5B,CAAC;EACDC,UAAU,CAACC,UAAU,GAAGL,KAAK;EAE7BI,UAAU,CAACE,oBAAoB,GAAG,UAAUC,SAAiB,EAAE;IAC7D,MAAMC,IAAI,GAAGR,KAAK,CAACE,gBAAgB,CAACO,GAAG,CAACF,SAAS,CAAC;IAClDC,IAAI,GAAG,CAAC;IACRR,KAAK,CAACE,gBAAgB,CAACQ,MAAM,CAACH,SAAS,CAAC;IACxCH,UAAU,CAACO,iBAAiB,CAAC,CAAC;EAChC,CAAC;EAEDP,UAAU,CAACO,iBAAiB,GAAG,YAAY;IACzC,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGZ,KAAK,CAACC,UAAU,CAACY,MAAM,EAAED,CAAC,EAAE,EAAE;MAChDZ,KAAK,CAACC,UAAU,CAACW,CAAC,CAAC,CAAC,CAAC;IACvB;IACAZ,KAAK,CAACC,UAAU,GAAG,EAAE;EACvB,CAAC;AACH;AAEA,OAAO,SAASa,aAAaA,CAACC,QAAkB,EAAE;EAChD,SAAS;;EACT,MAAMf,KAAK,GAAGI,UAAU,CAACC,UAAU;EACnCL,KAAK,CAACC,UAAU,CAACe,IAAI,CAACD,QAAQ,CAAC;AACjC;AAEA,OAAO,SAASE,QAAQA,CAACF,QAAkB,EAAER,SAAiB,EAAEW,KAAa,EAAE;EAC7E,SAAS;;EACT,MAAMlB,KAAK,GAAGI,UAAU,CAACC,UAAU;EACnCL,KAAK,CAACE,gBAAgB,CAACiB,GAAG,CAACZ,SAAS,EAAEQ,QAAQ,CAAC;EAC/CX,UAAU,CAACgB,wBAAwB,CAACF,KAAK,EAAEX,SAAS,CAAC;AACvD","ignoreList":[]}
@@ -0,0 +1,39 @@
'use strict';
export let RuntimeKind = /*#__PURE__*/function (RuntimeKind) {
/**
* The React Native runtime, which is the main runtime for React Native where
* React exists and where components are rendered.
*/
RuntimeKind[RuntimeKind["ReactNative"] = 1] = "ReactNative";
/**
* The UI runtime, which is a special runtime that executes on the UI thread,
* mostly used for animations and gestures.
*/
RuntimeKind[RuntimeKind["UI"] = 2] = "UI";
/** Additional runtime created on-demand by the user. */
RuntimeKind[RuntimeKind["Worker"] = 3] = "Worker";
return RuntimeKind;
}({});
/**
* Programmatic way to check the current runtime kind. It's useful when you need
* specific implementations for different runtimes created by Worklets.
*
* For more optimized calls you can check the value of
* `globalThis.__RUNTIME_KIND` directly.
*
* @returns The kind of the current runtime.
*/
export function getRuntimeKind() {
'worklet';
return globalThis.__RUNTIME_KIND;
}
if (globalThis.__RUNTIME_KIND === undefined) {
// In Jest environments eager imports make this file to evaluate before
// `initializers.ts` file, therefore we have to set the RuntimeKind here,
// just to be safe.
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
}
//# sourceMappingURL=runtimeKind.js.map
@@ -0,0 +1 @@
{"version":3,"names":["RuntimeKind","getRuntimeKind","globalThis","__RUNTIME_KIND","undefined","ReactNative"],"sourceRoot":"../../src","sources":["runtimeKind.ts"],"mappings":"AAAA,YAAY;;AAEZ,WAAYA,WAAW,0BAAXA,WAAW;EACrB;AACF;AACA;AACA;EAJYA,WAAW,CAAXA,WAAW;EAMrB;AACF;AACA;AACA;EATYA,WAAW,CAAXA,WAAW;EAWrB;EAXUA,WAAW,CAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA;;AAevB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAA,EAAgB;EAC5C,SAAS;;EACT,OAAOC,UAAU,CAACC,cAAc;AAClC;AAEA,IAAID,UAAU,CAACC,cAAc,KAAKC,SAAS,EAAE;EAC3C;EACA;EACA;EACAF,UAAU,CAACC,cAAc,GAAGH,WAAW,CAACK,WAAW;AACrD","ignoreList":[]}
@@ -0,0 +1,13 @@
'use strict';
import { WorkletsError } from './debug/WorkletsError';
export function createWorkletRuntime() {
throw new WorkletsError('`createWorkletRuntime` is not supported on web.');
}
export function runOnRuntime() {
throw new WorkletsError('`runOnRuntime` is not supported on web.');
}
export function scheduleOnRuntime() {
throw new WorkletsError('`scheduleOnRuntime` is not supported on web.');
}
//# sourceMappingURL=runtimes.js.map
@@ -0,0 +1 @@
{"version":3,"names":["WorkletsError","createWorkletRuntime","runOnRuntime","scheduleOnRuntime"],"sourceRoot":"../../src","sources":["runtimes.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,aAAa,QAAQ,uBAAuB;AAgBrD,OAAO,SAASC,oBAAoBA,CAAA,EAAU;EAC5C,MAAM,IAAID,aAAa,CAAC,iDAAiD,CAAC;AAC5E;AAOA,OAAO,SAASE,YAAYA,CAAA,EAAU;EACpC,MAAM,IAAIF,aAAa,CAAC,yCAAyC,CAAC;AACpE;AAQA,OAAO,SAASG,iBAAiBA,CAAA,EAAU;EACzC,MAAM,IAAIH,aAAa,CAAC,8CAA8C,CAAC;AACzE","ignoreList":[]}
@@ -0,0 +1,139 @@
'use strict';
import { setupCallGuard } from './callGuard';
import { registerWorkletsError, WorkletsError } from './debug/WorkletsError';
import { getMemorySafeCapturableConsole, setupConsole } from './initializers/initializers';
import { createSerializable, makeShareableCloneOnUIRecursive } from './memory/serializable';
import { setupRunLoop } from './runLoop/workletRuntime';
import { RuntimeKind } from './runtimeKind';
import { isWorkletFunction } from './workletFunction';
import { WorkletsModule } from './WorkletsModule/NativeWorklets';
/**
* Lets you create a new JS runtime which can be used to run worklets possibly
* on different threads than JS or UI thread.
*
* @param config - Runtime configuration object - {@link WorkletRuntimeConfig}.
* @returns WorkletRuntime which is a
* `jsi::HostObject<worklets::WorkletRuntime>` - {@link WorkletRuntime}
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/createWorkletRuntime/
*/
// @ts-expect-error Public API overload.
/**
* @deprecated Please use the new config object signature instead:
* `createWorkletRuntime({ name, initializer })`
*
* Lets you create a new JS runtime which can be used to run worklets possibly
* on different threads than JS or UI thread.
* @param name - A name used to identify the runtime which will appear in
* devices list in Chrome DevTools.
* @param initializer - An optional worklet that will be run synchronously on
* the same thread immediately after the runtime is created.
* @returns WorkletRuntime which is a
* `jsi::HostObject<worklets::WorkletRuntime>` - {@link WorkletRuntime}
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/createWorkletRuntime/
*/
export function createWorkletRuntime(nameOrConfig, initializer) {
const runtimeBoundCapturableConsole = getMemorySafeCapturableConsole();
let name;
let initializerFn;
let useDefaultQueue = true;
let customQueue;
let animationQueuePollingRate;
let enableEventLoop = true;
if (typeof nameOrConfig === 'string') {
name = nameOrConfig;
initializerFn = initializer;
} else {
// TODO: Make anonymous name globally unique.
name = nameOrConfig?.name ?? 'anonymous';
initializerFn = nameOrConfig?.initializer;
useDefaultQueue = nameOrConfig?.useDefaultQueue ?? true;
customQueue = nameOrConfig?.customQueue;
animationQueuePollingRate = Math.round(nameOrConfig?.animationQueuePollingRate ?? 16);
enableEventLoop = nameOrConfig?.enableEventLoop ?? true;
}
if (initializerFn && !isWorkletFunction(initializerFn)) {
throw new WorkletsError('The initializer passed to `createWorkletRuntime` is not a worklet.');
}
return WorkletsModule.createWorkletRuntime(name, createSerializable(() => {
'worklet';
setupCallGuard();
registerWorkletsError();
setupConsole(runtimeBoundCapturableConsole);
if (enableEventLoop) {
setupRunLoop(animationQueuePollingRate);
}
initializerFn?.();
}), useDefaultQueue, customQueue, enableEventLoop);
}
/**
* Lets you asynchronously run a
* [worklet](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#worklet)
* on a [Worker
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime).
*
* Check
* {@link https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds}
* for more information about the different runtime kinds.
*
* - The worklet is scheduled on the Worker Runtime's [Async
* Queue](https://github.com/software-mansion/react-native-reanimated/blob/main/packages/react-native-worklets/Common/cpp/worklets/RunLoop/AsyncQueue.h)
* - The function cannot be scheduled on the Worker Runtime from [UI
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime)
* or another [Worker
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime),
* unless the [Bundle
* Mode](https://docs.swmansion.com/react-native-worklets/docs/experimental/bundleMode)
* is enabled.
*
* @param workletRuntime - The runtime to schedule the worklet on.
* @param worklet - The worklet to schedule.
* @param args - The arguments to pass to the worklet.
* @returns The return value of the worklet.
*/
// @ts-expect-error This overload is correct since it's what user sees in their code
// before it's transformed by Worklets Babel plugin.
export function scheduleOnRuntime(workletRuntime, worklet, ...args) {
'worklet';
if (__DEV__ && !isWorkletFunction(worklet)) {
throw new WorkletsError('The function passed to `scheduleOnRuntime` is not a worklet.');
}
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
globalThis._scheduleOnRuntime(workletRuntime, makeShareableCloneOnUIRecursive(() => {
'worklet';
worklet(...args);
}));
}
WorkletsModule.scheduleOnRuntime(workletRuntime, createSerializable(() => {
'worklet';
worklet(...args);
globalThis.__flushMicrotasks();
}));
}
/**
* @deprecated Use `scheduleOnRuntime` instead.
*
* Schedule a worklet to execute on the background queue.
*/
// @ts-expect-error This overload is correct since it's what user sees in their code
// before it's transformed by Worklets Babel plugin.
export function runOnRuntime(workletRuntime, worklet) {
'worklet';
if (__DEV__ && !isWorkletFunction(worklet)) {
throw new WorkletsError('The function passed to `runOnRuntime` is not a worklet.');
}
return (...args) => scheduleOnRuntime(workletRuntime, worklet, ...args);
}
//# sourceMappingURL=runtimes.native.js.map

Some files were not shown because too many files have changed in this diff Show More