chore: update
This commit is contained in:
Generated
Vendored
+123
-1
@@ -1,4 +1,126 @@
|
||||
'use strict';
|
||||
|
||||
export const WorkletsModule = null;
|
||||
import { RuntimeKind } from "../runtimeKind.js";
|
||||
import { WorkletsTurboModule } from "../specs/index.js";
|
||||
import { checkCppVersion } from "../utils/checkCppVersion.js";
|
||||
import { jsVersion } from "../utils/jsVersion.js";
|
||||
import { WorkletsError } from "../WorkletsError.js";
|
||||
export function createNativeWorkletsModule() {
|
||||
return new NativeWorklets();
|
||||
}
|
||||
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__) {
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=NativeWorklets.js.map
|
||||
Generated
Vendored
+1
-1
File diff suppressed because one or more lines are too long
frontend-admin/node_modules/react-native-worklets/lib/module/WorkletsModule/NativeWorklets.native.js
Generated
Vendored
-130
@@ -1,130 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
File diff suppressed because one or more lines are too long
-30
@@ -1,30 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-12
@@ -1,12 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-27
@@ -1,27 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-30
@@ -1,30 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-69
@@ -1,69 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
'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
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
-2
@@ -1,2 +0,0 @@
|
||||
'use strict';
|
||||
//# sourceMappingURL=types.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["debug/types.ts"],"mappings":"AAAA,YAAY","ignoreList":[]}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
import { createSerializable, isSerializableRef, makeShareable, makeShareableCloneOnUIRecursive } from './memory/serializable';
|
||||
import { serializableMappingCache } from './memory/serializableMappingCache';
|
||||
import { createSerializable, isSerializableRef, makeShareable, makeShareableCloneOnUIRecursive } from "./serializable.js";
|
||||
import { serializableMappingCache } from "./serializableMappingCache.js";
|
||||
|
||||
/** @deprecated Use {@link SerializableRef} instead. */
|
||||
|
||||
|
||||
+1
-1
@@ -1 +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":[]}
|
||||
{"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,mBAAgB;AACvB,SAASC,wBAAwB,QAAQ,+BAA4B;;AAGrE;;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":[]}
|
||||
|
||||
Generated
Vendored
-12
@@ -1,12 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-51
@@ -1,51 +0,0 @@
|
||||
'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
|
||||
frontend-admin/node_modules/react-native-worklets/lib/module/featureFlags/featureFlags.native.js.map
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-12
@@ -1,12 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
+16
-16
@@ -1,26 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
import { init } from './initializers/initializers';
|
||||
import { bundleModeInit } from './initializers/workletRuntimeEntry';
|
||||
import "./publicGlobals.js";
|
||||
import { init } from "./initializers.js";
|
||||
import { bundleModeInit } from "./workletRuntimeEntry.js";
|
||||
init();
|
||||
|
||||
export { isShareableRef, makeShareable, makeShareableCloneOnUIRecursive, makeShareableCloneRecursive, shareableMappingCache } from "./deprecated.js";
|
||||
export { getStaticFeatureFlag, setDynamicFeatureFlag } from "./featureFlags/index.js";
|
||||
export { isSynchronizable } from "./isSynchronizable.js";
|
||||
export { getRuntimeKind, RuntimeKind } from "./runtimeKind.js";
|
||||
export { createWorkletRuntime, runOnRuntime } from "./runtimes.js";
|
||||
export { createSerializable, isSerializableRef } from "./serializable.js";
|
||||
export { serializableMappingCache } from "./serializableMappingCache.js";
|
||||
export { createSynchronizable } from "./synchronizable.js";
|
||||
export { callMicrotasks, executeOnUIRuntimeSync, runOnJS, runOnUI, runOnUIAsync, runOnUISync, scheduleOnRN, scheduleOnUI,
|
||||
// eslint-disable-next-line camelcase
|
||||
unstable_eventLoopTask } from "./threads.js";
|
||||
export { isWorkletFunction } from "./workletFunction.js";
|
||||
export { WorkletsModule } from "./WorkletsModule/index.js";
|
||||
// @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
|
||||
+1
-1
@@ -1 +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":[]}
|
||||
{"version":3,"names":["init","bundleModeInit","isShareableRef","makeShareable","makeShareableCloneOnUIRecursive","makeShareableCloneRecursive","shareableMappingCache","getStaticFeatureFlag","setDynamicFeatureFlag","isSynchronizable","getRuntimeKind","RuntimeKind","createWorkletRuntime","runOnRuntime","createSerializable","isSerializableRef","serializableMappingCache","createSynchronizable","callMicrotasks","executeOnUIRuntimeSync","runOnJS","runOnUI","runOnUIAsync","runOnUISync","scheduleOnRN","scheduleOnUI","unstable_eventLoopTask","isWorkletFunction","WorkletsModule","globalThis","_ALWAYS_FALSE"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,YAAY;;AAEZ,OAAO,oBAAiB;AAExB,SAASA,IAAI,QAAQ,mBAAgB;AACrC,SAASC,cAAc,QAAQ,0BAAuB;AAEtDD,IAAI,CAAC,CAAC;AAGN,SACEE,cAAc,EACdC,aAAa,EACbC,+BAA+B,EAC/BC,2BAA2B,EAC3BC,qBAAqB,QAChB,iBAAc;AACrB,SAASC,oBAAoB,EAAEC,qBAAqB,QAAQ,yBAAgB;AAC5E,SAASC,gBAAgB,QAAQ,uBAAoB;AACrD,SAASC,cAAc,EAAEC,WAAW,QAAQ,kBAAe;AAC3D,SAASC,oBAAoB,EAAEC,YAAY,QAAQ,eAAY;AAC/D,SAASC,kBAAkB,EAAEC,iBAAiB,QAAQ,mBAAgB;AACtE,SAASC,wBAAwB,QAAQ,+BAA4B;AAErE,SAASC,oBAAoB,QAAQ,qBAAkB;AACvD,SACEC,cAAc,EACdC,sBAAsB,EACtBC,OAAO,EACPC,OAAO,EACPC,YAAY,EACZC,WAAW,EACXC,YAAY,EACZC,YAAY;AACZ;AACAC,sBAAsB,QACjB,cAAW;AAClB,SAASC,iBAAiB,QAAQ,sBAAmB;AAErD,SAASC,cAAc,QAAQ,2BAAkB;AAQjD;AACA;AACA,IAAIC,UAAU,CAACC,aAAa,EAAE;EAC5B;EACA7B,cAAc,CAAC,CAAC;AAClB","ignoreList":[]}
|
||||
|
||||
Generated
Vendored
-21
@@ -1,21 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-198
@@ -1,198 +0,0 @@
|
||||
'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
|
||||
frontend-admin/node_modules/react-native-worklets/lib/module/initializers/initializers.native.js.map
Generated
Vendored
-1
File diff suppressed because one or more lines are too long
Generated
Vendored
-6
@@ -1,6 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
export function bundleModeInit() {
|
||||
// no-op
|
||||
}
|
||||
//# sourceMappingURL=workletRuntimeEntry.js.map
|
||||
frontend-admin/node_modules/react-native-worklets/lib/module/initializers/workletRuntimeEntry.js.map
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"names":["bundleModeInit"],"sourceRoot":"../../../src","sources":["initializers/workletRuntimeEntry.ts"],"mappings":"AAAA,YAAY;;AAEZ,OAAO,SAASA,cAAcA,CAAA,EAAG;EAC/B;AAAA","ignoreList":[]}
|
||||
Generated
Vendored
-37
@@ -1,37 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-47
@@ -1,47 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-18
@@ -1,18 +0,0 @@
|
||||
/* 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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-7
@@ -1,7 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
import { WorkletsError } from '../debug/WorkletsError';
|
||||
export function isSynchronizable(_value) {
|
||||
throw new WorkletsError('`isSynchronizable` is not supported on web.');
|
||||
}
|
||||
//# sourceMappingURL=isSynchronizable.js.map
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-8
@@ -1,8 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
export function isSynchronizable(value) {
|
||||
'worklet';
|
||||
|
||||
return typeof value === 'object' && value !== null && '__synchronizableRef' in value && value.__synchronizableRef === true;
|
||||
}
|
||||
//# sourceMappingURL=isSynchronizable.native.js.map
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-18
@@ -1,18 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-631
@@ -1,631 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
File diff suppressed because one or more lines are too long
Generated
Vendored
-11
@@ -1,11 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
export const serializableMappingCache = {
|
||||
set(_serializable, _serializableRef) {
|
||||
// NOOP
|
||||
},
|
||||
get(_key) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
//# sourceMappingURL=serializableMappingCache.js.map
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-29
@@ -1,29 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-7
@@ -1,7 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
import { WorkletsError } from '../debug/WorkletsError';
|
||||
export function createSynchronizable(_value) {
|
||||
throw new WorkletsError('`createSynchronizable` is not supported on web.');
|
||||
}
|
||||
//# sourceMappingURL=synchronizable.js.map
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-9
@@ -1,9 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
frontend-admin/node_modules/react-native-worklets/lib/module/memory/synchronizableUnpacker.native.js
Generated
Vendored
-42
@@ -1,42 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
'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
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["memory/types.ts"],"mappings":"AAAA,YAAY;;AAEZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
||||
Generated
Vendored
-61
@@ -1,61 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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
@@ -1,86 +0,0 @@
|
||||
'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
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"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":[]}
|
||||
Generated
Vendored
-4
@@ -1,4 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
export const IS_JEST = false;
|
||||
//# sourceMappingURL=platformChecker.native.js.map
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"names":["IS_JEST"],"sourceRoot":"../../src","sources":["platformChecker.native.ts"],"mappings":"AAAA,YAAY;;AAEZ,OAAO,MAAMA,OAAO,GAAG,KAAK","ignoreList":[]}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable reanimated/use-global-this */
|
||||
'use strict';
|
||||
|
||||
// This file works by accident - currently Builder Bob doesn't move `.d.ts` files to output types.
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"names":[],"sourceRoot":"../../src","sources":["privateGlobals.d.ts"],"mappings":"AAAA,YAAY;;AAEZ;AACA;AAAA","ignoreList":[]}
|
||||
{"version":3,"names":[],"sourceRoot":"../../src","sources":["privateGlobals.d.ts"],"mappings":"AAAA;AACA,YAAY;;AAEZ;AACA;AAAA","ignoreList":[]}
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
import { callMicrotasks } from '../../threads';
|
||||
import { callMicrotasks } from "../../threads.js";
|
||||
export function setupRequestAnimationFrame() {
|
||||
'worklet';
|
||||
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1 +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":[]}
|
||||
{"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,kBAAe;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":[]}
|
||||
|
||||
Generated
Vendored
+6
-6
@@ -1,11 +1,11 @@
|
||||
'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';
|
||||
import { setupSetImmediate } from "../common/setImmediatePolyfill.js";
|
||||
import { setupSetInterval } from "../common/setIntervalPolyfill.js";
|
||||
import { setupQueueMicrotask } from "./queueMicrotask.js";
|
||||
import { setupRequestAnimationFrame } from "./requestAnimationFramePolyfill.js";
|
||||
import { setupSetTimeout } from "./setTimeout.js";
|
||||
import { setupTaskQueue } from "./taskQueue.js";
|
||||
export function setupRunLoop(animationQueuePollingRate) {
|
||||
'worklet';
|
||||
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1 +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":[]}
|
||||
{"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,mCAAgC;AAClE,SAASC,gBAAgB,QAAQ,kCAA+B;AAChE,SAASC,mBAAmB,QAAQ,qBAAkB;AACtD,SAASC,0BAA0B,QAAQ,oCAAiC;AAC5E,SAASC,eAAe,QAAQ,iBAAc;AAC9C,SAASC,cAAc,QAAQ,gBAAa;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":[]}
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
import { pushMicrotask } from './taskQueue';
|
||||
import { pushMicrotask } from "./taskQueue.js";
|
||||
export function setupQueueMicrotask() {
|
||||
'worklet';
|
||||
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1 +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":[]}
|
||||
{"version":3,"names":["pushMicrotask","setupQueueMicrotask","globalThis","queueMicrotask","callback","args"],"sourceRoot":"../../../../src","sources":["runLoop/workletRuntime/queueMicrotask.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,aAAa,QAAQ,gBAAa;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":[]}
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
import { pushTask } from './taskQueue';
|
||||
import { pushTask } from "./taskQueue.js";
|
||||
export function setupSetTimeout() {
|
||||
'worklet';
|
||||
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1 +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":[]}
|
||||
{"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,gBAAa;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":[]}
|
||||
|
||||
-9
@@ -1,17 +1,8 @@
|
||||
'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;
|
||||
}({});
|
||||
|
||||
+1
-1
@@ -1 +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":[]}
|
||||
{"version":3,"names":["RuntimeKind","getRuntimeKind","globalThis","__RUNTIME_KIND","undefined","ReactNative"],"sourceRoot":"../../src","sources":["runtimeKind.ts"],"mappings":"AAAA,YAAY;;AAEZ,WAAYA,WAAW,0BAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,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":[]}
|
||||
|
||||
+95
-8
@@ -1,13 +1,100 @@
|
||||
'use strict';
|
||||
|
||||
import { WorkletsError } from './debug/WorkletsError';
|
||||
export function createWorkletRuntime() {
|
||||
throw new WorkletsError('`createWorkletRuntime` is not supported on web.');
|
||||
import { setupCallGuard } from "./callGuard.js";
|
||||
import { getMemorySafeCapturableConsole, setupConsole } from "./initializers.js";
|
||||
import { SHOULD_BE_USE_WEB } from "./PlatformChecker/index.js";
|
||||
import { setupRunLoop } from "./runLoop/workletRuntime/index.js";
|
||||
import { RuntimeKind } from "./runtimeKind.js";
|
||||
import { createSerializable, makeShareableCloneOnUIRecursive } from "./serializable.js";
|
||||
import { isWorkletFunction } from "./workletFunction.js";
|
||||
import { registerWorkletsError, WorkletsError } from "./WorkletsError.js";
|
||||
import { WorkletsModule } from "./WorkletsModule/index.js";
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
export function runOnRuntime() {
|
||||
throw new WorkletsError('`runOnRuntime` is not supported on web.');
|
||||
}
|
||||
export function scheduleOnRuntime() {
|
||||
throw new WorkletsError('`scheduleOnRuntime` is not supported on web.');
|
||||
|
||||
// @ts-expect-error Check `runOnUI` overload.
|
||||
|
||||
/** Schedule a worklet to execute on the background queue. */
|
||||
export function runOnRuntime(workletRuntime, worklet) {
|
||||
'worklet';
|
||||
|
||||
if (__DEV__ && !SHOULD_BE_USE_WEB && !isWorkletFunction(worklet)) {
|
||||
throw new WorkletsError('The function passed to `runOnRuntime` is not a worklet.');
|
||||
}
|
||||
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
|
||||
return (...args) => globalThis._scheduleOnRuntime(workletRuntime, makeShareableCloneOnUIRecursive(() => {
|
||||
'worklet';
|
||||
|
||||
worklet(...args);
|
||||
}));
|
||||
}
|
||||
return (...args) => WorkletsModule.scheduleOnRuntime(workletRuntime, createSerializable(() => {
|
||||
'worklet';
|
||||
|
||||
worklet(...args);
|
||||
globalThis.__flushMicrotasks();
|
||||
}));
|
||||
}
|
||||
|
||||
/** Configuration object for creating a worklet runtime. */
|
||||
//# sourceMappingURL=runtimes.js.map
|
||||
+1
-1
@@ -1 +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":[]}
|
||||
{"version":3,"names":["setupCallGuard","getMemorySafeCapturableConsole","setupConsole","SHOULD_BE_USE_WEB","setupRunLoop","RuntimeKind","createSerializable","makeShareableCloneOnUIRecursive","isWorkletFunction","registerWorkletsError","WorkletsError","WorkletsModule","createWorkletRuntime","nameOrConfig","initializer","runtimeBoundCapturableConsole","name","initializerFn","useDefaultQueue","customQueue","animationQueuePollingRate","enableEventLoop","Math","round","runOnRuntime","workletRuntime","worklet","__DEV__","globalThis","__RUNTIME_KIND","ReactNative","args","_scheduleOnRuntime","scheduleOnRuntime","__flushMicrotasks"],"sourceRoot":"../../src","sources":["runtimes.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,cAAc,QAAQ,gBAAa;AAC5C,SAASC,8BAA8B,EAAEC,YAAY,QAAQ,mBAAgB;AAC7E,SAASC,iBAAiB,QAAQ,4BAAmB;AACrD,SAASC,YAAY,QAAQ,mCAA0B;AACvD,SAASC,WAAW,QAAQ,kBAAe;AAC3C,SACEC,kBAAkB,EAClBC,+BAA+B,QAC1B,mBAAgB;AACvB,SAASC,iBAAiB,QAAQ,sBAAmB;AACrD,SAASC,qBAAqB,EAAEC,aAAa,QAAQ,oBAAiB;AACtE,SAASC,cAAc,QAAQ,2BAAkB;;AAGjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA,OAAO,SAASC,oBAAoBA,CAClCC,YAAoD,EACpDC,WAAuC,EACvB;EAChB,MAAMC,6BAA6B,GAAGd,8BAA8B,CAAC,CAAC;EAEtE,IAAIe,IAAY;EAChB,IAAIC,aAAuC;EAC3C,IAAIC,eAAe,GAAG,IAAI;EAC1B,IAAIC,WAA+B;EACnC,IAAIC,yBAAiC;EACrC,IAAIC,eAAe,GAAG,IAAI;EAC1B,IAAI,OAAOR,YAAY,KAAK,QAAQ,EAAE;IACpCG,IAAI,GAAGH,YAAY;IACnBI,aAAa,GAAGH,WAAW;EAC7B,CAAC,MAAM;IACL;IACAE,IAAI,GAAGH,YAAY,EAAEG,IAAI,IAAI,WAAW;IACxCC,aAAa,GAAGJ,YAAY,EAAEC,WAAW;IACzCI,eAAe,GAAGL,YAAY,EAAEK,eAAe,IAAI,IAAI;IACvDC,WAAW,GAAGN,YAAY,EAAEM,WAAW;IACvCC,yBAAyB,GAAGE,IAAI,CAACC,KAAK,CACpCV,YAAY,EAAEO,yBAAyB,IAAI,EAC7C,CAAC;IACDC,eAAe,GAAGR,YAAY,EAAEQ,eAAe,IAAI,IAAI;EACzD;EAEA,IAAIJ,aAAa,IAAI,CAACT,iBAAiB,CAACS,aAAa,CAAC,EAAE;IACtD,MAAM,IAAIP,aAAa,CACrB,oEACF,CAAC;EACH;EAEA,OAAOC,cAAc,CAACC,oBAAoB,CACxCI,IAAI,EACJV,kBAAkB,CAAC,MAAM;IACvB,SAAS;;IACTN,cAAc,CAAC,CAAC;IAChBS,qBAAqB,CAAC,CAAC;IACvBP,YAAY,CAACa,6BAA6B,CAAC;IAC3C,IAAIM,eAAe,EAAE;MACnBjB,YAAY,CAACgB,yBAAyB,CAAC;IACzC;IACAH,aAAa,GAAG,CAAC;EACnB,CAAC,CAAC,EACFC,eAAe,EACfC,WAAW,EACXE,eACF,CAAC;AACH;;AAEA;;AAKA;AACA,OAAO,SAASG,YAAYA,CAC1BC,cAA8B,EAC9BC,OAA2C,EAClB;EACzB,SAAS;;EACT,IAAIC,OAAO,IAAI,CAACxB,iBAAiB,IAAI,CAACK,iBAAiB,CAACkB,OAAO,CAAC,EAAE;IAChE,MAAM,IAAIhB,aAAa,CACrB,yDACF,CAAC;EACH;EACA,IAAIkB,UAAU,CAACC,cAAc,KAAKxB,WAAW,CAACyB,WAAW,EAAE;IACzD,OAAO,CAAC,GAAGC,IAAI,KACbH,UAAU,CAACI,kBAAkB,CAC3BP,cAAc,EACdlB,+BAA+B,CAAC,MAAM;MACpC,SAAS;;MACTmB,OAAO,CAAC,GAAGK,IAAI,CAAC;IAClB,CAAC,CACH,CAAC;EACL;EACA,OAAO,CAAC,GAAGA,IAAI,KACbpB,cAAc,CAACsB,iBAAiB,CAC9BR,cAAc,EACdnB,kBAAkB,CAAC,MAAM;IACvB,SAAS;;IACToB,OAAO,CAAC,GAAGK,IAAI,CAAC;IAChBH,UAAU,CAACM,iBAAiB,CAAC,CAAC;EAChC,CAAC,CACH,CAAC;AACL;;AAEA","ignoreList":[]}
|
||||
|
||||
-139
@@ -1,139 +0,0 @@
|
||||
'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
|
||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"names":["setupCallGuard","registerWorkletsError","WorkletsError","getMemorySafeCapturableConsole","setupConsole","createSerializable","makeShareableCloneOnUIRecursive","setupRunLoop","RuntimeKind","isWorkletFunction","WorkletsModule","createWorkletRuntime","nameOrConfig","initializer","runtimeBoundCapturableConsole","name","initializerFn","useDefaultQueue","customQueue","animationQueuePollingRate","enableEventLoop","Math","round","scheduleOnRuntime","workletRuntime","worklet","args","__DEV__","globalThis","__RUNTIME_KIND","ReactNative","_scheduleOnRuntime","__flushMicrotasks","runOnRuntime"],"sourceRoot":"../../src","sources":["runtimes.native.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,cAAc,QAAQ,aAAa;AAC5C,SAASC,qBAAqB,EAAEC,aAAa,QAAQ,uBAAuB;AAC5E,SACEC,8BAA8B,EAC9BC,YAAY,QACP,6BAA6B;AACpC,SACEC,kBAAkB,EAClBC,+BAA+B,QAC1B,uBAAuB;AAC9B,SAASC,YAAY,QAAQ,0BAA0B;AACvD,SAASC,WAAW,QAAQ,eAAe;AAM3C,SAASC,iBAAiB,QAAQ,mBAAmB;AACrD,SAASC,cAAc,QAAQ,iCAAiC;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA,OAAO,SAASC,oBAAoBA,CAClCC,YAAoD,EACpDC,WAAuC,EACvB;EAChB,MAAMC,6BAA6B,GAAGX,8BAA8B,CAAC,CAAC;EAEtE,IAAIY,IAAY;EAChB,IAAIC,aAAuC;EAC3C,IAAIC,eAAe,GAAG,IAAI;EAC1B,IAAIC,WAA+B;EACnC,IAAIC,yBAAiC;EACrC,IAAIC,eAAe,GAAG,IAAI;EAC1B,IAAI,OAAOR,YAAY,KAAK,QAAQ,EAAE;IACpCG,IAAI,GAAGH,YAAY;IACnBI,aAAa,GAAGH,WAAW;EAC7B,CAAC,MAAM;IACL;IACAE,IAAI,GAAGH,YAAY,EAAEG,IAAI,IAAI,WAAW;IACxCC,aAAa,GAAGJ,YAAY,EAAEC,WAAW;IACzCI,eAAe,GAAGL,YAAY,EAAEK,eAAe,IAAI,IAAI;IACvDC,WAAW,GAAGN,YAAY,EAAEM,WAAW;IACvCC,yBAAyB,GAAGE,IAAI,CAACC,KAAK,CACpCV,YAAY,EAAEO,yBAAyB,IAAI,EAC7C,CAAC;IACDC,eAAe,GAAGR,YAAY,EAAEQ,eAAe,IAAI,IAAI;EACzD;EAEA,IAAIJ,aAAa,IAAI,CAACP,iBAAiB,CAACO,aAAa,CAAC,EAAE;IACtD,MAAM,IAAId,aAAa,CACrB,oEACF,CAAC;EACH;EAEA,OAAOQ,cAAc,CAACC,oBAAoB,CACxCI,IAAI,EACJV,kBAAkB,CAAC,MAAM;IACvB,SAAS;;IACTL,cAAc,CAAC,CAAC;IAChBC,qBAAqB,CAAC,CAAC;IACvBG,YAAY,CAACU,6BAA6B,CAAC;IAC3C,IAAIM,eAAe,EAAE;MACnBb,YAAY,CAACY,yBAAyB,CAAC;IACzC;IACAH,aAAa,GAAG,CAAC;EACnB,CAAC,CAAC,EACFC,eAAe,EACfC,WAAW,EACXE,eACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,OAAO,SAASG,iBAAiBA,CAC/BC,cAA8B,EAC9BC,OAA2C,EAC3C,GAAGC,IAAU,EACP;EACN,SAAS;;EACT,IAAIC,OAAO,IAAI,CAAClB,iBAAiB,CAACgB,OAAO,CAAC,EAAE;IAC1C,MAAM,IAAIvB,aAAa,CACrB,8DACF,CAAC;EACH;EACA,IAAI0B,UAAU,CAACC,cAAc,KAAKrB,WAAW,CAACsB,WAAW,EAAE;IACzDF,UAAU,CAACG,kBAAkB,CAC3BP,cAAc,EACdlB,+BAA+B,CAAC,MAAM;MACpC,SAAS;;MACTmB,OAAO,CAAC,GAAGC,IAAI,CAAC;IAClB,CAAC,CACH,CAAC;EACH;EAEAhB,cAAc,CAACa,iBAAiB,CAC9BC,cAAc,EACdnB,kBAAkB,CAAC,MAAM;IACvB,SAAS;;IACToB,OAAO,CAAC,GAAGC,IAAI,CAAC;IAChBE,UAAU,CAACI,iBAAiB,CAAC,CAAC;EAChC,CAAC,CACH,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA,OAAO,SAASC,YAAYA,CAC1BT,cAA8B,EAC9BC,OAA2C,EAClB;EACzB,SAAS;;EACT,IAAIE,OAAO,IAAI,CAAClB,iBAAiB,CAACgB,OAAO,CAAC,EAAE;IAC1C,MAAM,IAAIvB,aAAa,CACrB,yDACF,CAAC;EACH;EACA,OAAO,CAAC,GAAGwB,IAAI,KAAKH,iBAAiB,CAACC,cAAc,EAAEC,OAAO,EAAE,GAAGC,IAAI,CAAC;AACzE","ignoreList":[]}
|
||||
Generated
Vendored
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"names":["TurboModuleRegistry","get"],"sourceRoot":"../../../src","sources":["specs/NativeWorkletsModule.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAA2BA,mBAAmB,QAAQ,cAAc;AAMpE,eAAeA,mBAAmB,CAACC,GAAG,CAAO,gBAAgB,CAAC","ignoreList":[]}
|
||||
{"version":3,"names":["TurboModuleRegistry","get"],"sourceRoot":"../../../src","sources":["specs/NativeWorkletsModule.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,mBAAmB,QAAQ,cAAc;AAMlD,eAAeA,mBAAmB,CAACC,GAAG,CAAO,gBAAgB,CAAC","ignoreList":[]}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
import { RuntimeKind } from '../runtimeKind';
|
||||
import RNWorkletsTurboModule from './NativeWorkletsModule';
|
||||
import { RuntimeKind } from "../runtimeKind.js";
|
||||
import RNWorkletsTurboModule from "./NativeWorkletsModule.js";
|
||||
export const WorkletsTurboModule = globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative ? RNWorkletsTurboModule :
|
||||
// In Bundle Mode, on Worklet Runtimes `RNWorkletsTurboModule` isn't
|
||||
// available and shouldn't be accessed. We return null here
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"names":["RuntimeKind","RNWorkletsTurboModule","WorkletsTurboModule","globalThis","__RUNTIME_KIND","ReactNative"],"sourceRoot":"../../../src","sources":["specs/index.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,WAAW,QAAQ,gBAAgB;AAE5C,OAAOC,qBAAqB,MAAM,wBAAwB;AAE1D,OAAO,MAAMC,mBAA4C,GACvDC,UAAU,CAACC,cAAc,KAAKJ,WAAW,CAACK,WAAW,GACjDJ,qBAAqB;AACrB;AACA;AACA;AACA,IAAI","ignoreList":[]}
|
||||
{"version":3,"names":["RuntimeKind","RNWorkletsTurboModule","WorkletsTurboModule","globalThis","__RUNTIME_KIND","ReactNative"],"sourceRoot":"../../../src","sources":["specs/index.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,WAAW,QAAQ,mBAAgB;AAE5C,OAAOC,qBAAqB,MAAM,2BAAwB;AAE1D,OAAO,MAAMC,mBAAgC,GAC3CC,UAAU,CAACC,cAAc,KAAKJ,WAAW,CAACK,WAAW,GACjDJ,qBAAqB;AACrB;AACA;AACA;AACA,IAAI","ignoreList":[]}
|
||||
|
||||
+314
-28
@@ -1,36 +1,311 @@
|
||||
'use strict';
|
||||
|
||||
import { WorkletsError } from './debug/WorkletsError';
|
||||
import { mockedRequestAnimationFrame } from './runLoop/uiRuntime/mockedRequestAnimationFrame';
|
||||
export function callMicrotasks() {
|
||||
// on web flushing is a noop as immediates are handled by the browser
|
||||
}
|
||||
export function scheduleOnUI(worklet, ...args) {
|
||||
enqueueUI(worklet, args);
|
||||
}
|
||||
export function runOnUI(worklet) {
|
||||
return (...args) => {
|
||||
scheduleOnUI(worklet, ...args);
|
||||
import { IS_JEST, SHOULD_BE_USE_WEB } from "./PlatformChecker/index.js";
|
||||
import { RuntimeKind } from "./runtimeKind.js";
|
||||
import { createSerializable, makeShareableCloneOnUIRecursive } from "./serializable.js";
|
||||
import { serializableMappingCache } from "./serializableMappingCache.js";
|
||||
import { isWorkletFunction } from "./workletFunction.js";
|
||||
import { WorkletsError } from "./WorkletsError.js";
|
||||
import { WorkletsModule } from "./WorkletsModule/index.js";
|
||||
let runOnUIQueue = [];
|
||||
export function setupMicrotasks() {
|
||||
'worklet';
|
||||
|
||||
let microtasksQueue = [];
|
||||
let isExecutingMicrotasksQueue = false;
|
||||
global.queueMicrotask = callback => {
|
||||
microtasksQueue.push(callback);
|
||||
};
|
||||
global._microtaskQueueFinalizers = [];
|
||||
global.__callMicrotasks = () => {
|
||||
if (isExecutingMicrotasksQueue) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
isExecutingMicrotasksQueue = true;
|
||||
for (let index = 0; index < microtasksQueue.length; index += 1) {
|
||||
// we use classic 'for' loop because the size of the currentTasks array may change while executing some of the callbacks due to queueMicrotask calls
|
||||
microtasksQueue[index]();
|
||||
}
|
||||
microtasksQueue = [];
|
||||
global._microtaskQueueFinalizers.forEach(finalizer => finalizer());
|
||||
} finally {
|
||||
isExecutingMicrotasksQueue = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
export function runOnUISync() {
|
||||
throw new WorkletsError('`runOnUISync` is not supported on web.');
|
||||
function callMicrotasksOnUIThread() {
|
||||
'worklet';
|
||||
|
||||
global.__callMicrotasks();
|
||||
}
|
||||
export function executeOnUIRuntimeSync() {
|
||||
throw new WorkletsError('`executeOnUIRuntimeSync` is not supported on web.');
|
||||
export const callMicrotasks = SHOULD_BE_USE_WEB ? () => {
|
||||
// on web flushing is a noop as immediates are handled by the browser
|
||||
} : callMicrotasksOnUIThread;
|
||||
|
||||
/**
|
||||
* Lets you schedule a function to be executed on the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime).
|
||||
*
|
||||
* - The callback executes asynchronously and doesn't return a value.
|
||||
* - Passed function and args are automatically
|
||||
* [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
|
||||
* and serialized.
|
||||
* - This function cannot be called from the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime)
|
||||
* or [Worker
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#worker-worklet-runtime---worker-runtime),
|
||||
* unless you have the [Bundle Mode](/docs/experimental/bundleMode) enabled.
|
||||
*
|
||||
* @param fun - A reference to a function you want to schedule on the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime).
|
||||
* @param args - Arguments to pass to the function.
|
||||
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/scheduleOnUI
|
||||
*/
|
||||
export function scheduleOnUI(worklet, ...args) {
|
||||
runOnUI(worklet)(...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets you asynchronously run
|
||||
* [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
|
||||
* functions on the [UI
|
||||
* thread](https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI/).
|
||||
*
|
||||
* This method does not schedule the work immediately but instead waits for
|
||||
* other worklets to be scheduled within the same JS loop. It uses
|
||||
* queueMicrotask to schedule all the worklets at once making sure they will run
|
||||
* within the same frame boundaries on the UI thread.
|
||||
*
|
||||
* @param fun - A reference to a function you want to execute on the [UI
|
||||
* thread](https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI/)
|
||||
* from the [JavaScript
|
||||
* thread](https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI/).
|
||||
* @returns A function that accepts arguments for the function passed as the
|
||||
* first argument.
|
||||
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI @deprecated Use `scheduleOnUI` instead.
|
||||
*/
|
||||
// @ts-expect-error This overload is correct since it's what user sees in his code
|
||||
// before it's transformed by Reanimated Babel plugin.
|
||||
|
||||
export function runOnUI(worklet) {
|
||||
if (__DEV__ && !SHOULD_BE_USE_WEB && !isWorkletFunction(worklet) && !worklet.__bundleData) {
|
||||
throw new WorkletsError('`runOnUI` can only be used with worklets.');
|
||||
}
|
||||
return (...args) => {
|
||||
if (IS_JEST) {
|
||||
// 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.
|
||||
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
||||
'worklet';
|
||||
|
||||
worklet(...args);
|
||||
}));
|
||||
return;
|
||||
}
|
||||
if (__DEV__) {
|
||||
// in DEV mode we call serializable conversion here because in case the object
|
||||
// can't be converted, we will get a meaningful stack-trace as opposed to the
|
||||
// situation when conversion is only done via microtask queue. This does not
|
||||
// make the app particularily less efficient as converted objects are cached
|
||||
// and for a given worklet the conversion only happens once.
|
||||
createSerializable(worklet);
|
||||
createSerializable(args);
|
||||
}
|
||||
enqueueUI(worklet, args);
|
||||
};
|
||||
}
|
||||
if (__DEV__) {
|
||||
function runOnUIWorklet() {
|
||||
'worklet';
|
||||
|
||||
throw new WorkletsError('`runOnUI` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.');
|
||||
}
|
||||
const serializableRunOnUIWorklet = createSerializable(runOnUIWorklet);
|
||||
serializableMappingCache.set(runOnUI, serializableRunOnUIWorklet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets you run a function synchronously on the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime)
|
||||
* from the [RN
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#react-native-runtime-rn-runtime).
|
||||
* Passed function and args are automatically
|
||||
* [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
|
||||
* and serialized.
|
||||
*
|
||||
* - This function cannot be called from the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime).
|
||||
* - This function cannot be called from a [Worker
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#worker-worklet-runtime---worker-runtime).
|
||||
*
|
||||
* @param fun - A reference to a function you want to execute on the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime).
|
||||
* @param args - Arguments to pass to the function.
|
||||
* @returns The return value of the function passed as the first argument.
|
||||
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUISync
|
||||
*/
|
||||
export function runOnUISync(worklet, ...args) {
|
||||
return executeOnUIRuntimeSync(worklet)(...args);
|
||||
}
|
||||
|
||||
// @ts-expect-error Check `executeOnUIRuntimeSync` overload above.
|
||||
|
||||
export function executeOnUIRuntimeSync(worklet) {
|
||||
return (...args) => {
|
||||
return WorkletsModule.executeOnUIRuntimeSync(createSerializable(() => {
|
||||
'worklet';
|
||||
|
||||
const result = worklet(...args);
|
||||
return makeShareableCloneOnUIRecursive(result);
|
||||
}));
|
||||
};
|
||||
}
|
||||
function runWorkletOnJS(worklet, ...args) {
|
||||
// remote function that calls a worklet synchronously on the JS runtime
|
||||
worklet(...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets you asynchronously run
|
||||
* non-[workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
|
||||
* functions that couldn't otherwise run on the [UI
|
||||
* thread](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-thread).
|
||||
* This applies to most external libraries as they don't have their functions
|
||||
* marked with "worklet"; directive.
|
||||
*
|
||||
* @param fun - A reference to a function you want to execute on the JavaScript
|
||||
* thread from the UI thread.
|
||||
* @returns A function that accepts arguments for the function passed as the
|
||||
* first argument.
|
||||
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnJS
|
||||
*/
|
||||
/** @deprecated Use `scheduleOnRN` instead. */
|
||||
export function runOnJS(fun) {
|
||||
return (...args) => scheduleOnRN(fun, ...args);
|
||||
'worklet';
|
||||
|
||||
if (SHOULD_BE_USE_WEB || globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
||||
// if we are already on the JS thread, we just schedule the worklet on the JS queue
|
||||
return (...args) => queueMicrotask(args.length ? () => fun(...args) : fun);
|
||||
}
|
||||
if (isWorkletFunction(fun)) {
|
||||
// If `fun` is a worklet, we schedule a call of a remote function `runWorkletOnJS`
|
||||
// and pass the worklet as a first argument followed by original arguments.
|
||||
|
||||
return (...args) => runOnJS(runWorkletOnJS)(fun, ...args);
|
||||
}
|
||||
if (fun.__remoteFunction) {
|
||||
// In development mode the function provided as `fun` throws an error message
|
||||
// such that when someone accidentally calls it directly on the UI runtime, they
|
||||
// see that they should use `runOnJS` instead. To facilitate that we put the
|
||||
// reference to the original remote function in the `__remoteFunction` property.
|
||||
fun = fun.__remoteFunction;
|
||||
}
|
||||
const scheduleOnJS = typeof fun === 'function' ? global._scheduleHostFunctionOnJS : global._scheduleRemoteFunctionOnJS;
|
||||
return (...args) => {
|
||||
scheduleOnJS(fun, args.length > 0 ? makeShareableCloneOnUIRecursive(args) : undefined);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets you schedule a function to be executed on the RN runtime from any
|
||||
* runtime. Check
|
||||
* {@link https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds}
|
||||
* for more information about the different runtime kinds.
|
||||
*
|
||||
* Scheduling function from the RN Runtime (we are already on RN Runtime) simply
|
||||
* uses `queueMicrotask`.
|
||||
*
|
||||
* When functions need to be scheduled from the UI Runtime, first function and
|
||||
* args are serialized and then the system passes the scheduling responsibility
|
||||
* to the JSScheduler. The JSScheduler then uses the RN CallInvoker to schedule
|
||||
* the function asynchronously on the JavaScript thread by calling
|
||||
* `jsCallInvoker_->invokeAsync()`.
|
||||
*
|
||||
* When called from a Worker Runtime, it uses the same JSScheduler mechanism.
|
||||
*
|
||||
* @param fun - A function you want to schedule on the RN runtime. A function
|
||||
* can be a worklet, a remote function or a regular function.
|
||||
* @param args - Arguments to pass to the function.
|
||||
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/scheduleOnRN
|
||||
*/
|
||||
export function scheduleOnRN(fun, ...args) {
|
||||
queueMicrotask(args.length ? () => fun(...args) : fun);
|
||||
'worklet';
|
||||
|
||||
runOnJS(fun)(...args);
|
||||
}
|
||||
export function runOnUIAsync(worklet, ...args) {
|
||||
return new Promise(resolve => {
|
||||
enqueueUI(worklet, args, resolve);
|
||||
});
|
||||
|
||||
/**
|
||||
* Lets you asynchronously run
|
||||
* [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
|
||||
* functions on the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime).
|
||||
*
|
||||
* This method does not schedule the work immediately but instead waits for
|
||||
* other worklets to be scheduled within the same JS loop. It uses
|
||||
* queueMicrotask to schedule all the worklets at once making sure they will run
|
||||
* within the same frame boundaries on the UI thread.
|
||||
*
|
||||
* @param fun - A reference to a function you want to execute on the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime).
|
||||
* from the [JavaScript
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#javascript-runtime).
|
||||
* @returns A promise that resolves to the return value of the function passed
|
||||
* as the first argument.
|
||||
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUIAsync
|
||||
*/
|
||||
export function runOnUIAsync(worklet) {
|
||||
if (__DEV__ && !SHOULD_BE_USE_WEB && !isWorkletFunction(worklet)) {
|
||||
throw new WorkletsError('`runOnUIAsync` can only be used with worklets.');
|
||||
}
|
||||
return (...args) => {
|
||||
return new Promise(resolve => {
|
||||
if (IS_JEST) {
|
||||
// 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.
|
||||
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
||||
'worklet';
|
||||
|
||||
worklet(...args);
|
||||
}));
|
||||
return;
|
||||
}
|
||||
if (__DEV__) {
|
||||
// in DEV mode we call serializable conversion here because in case the object
|
||||
// can't be converted, we will get a meaningful stack-trace as opposed to the
|
||||
// situation when conversion is only done via microtask queue. This does not
|
||||
// make the app particularily less efficient as converted objects are cached
|
||||
// and for a given worklet the conversion only happens once.
|
||||
createSerializable(worklet);
|
||||
createSerializable(args);
|
||||
}
|
||||
enqueueUI(worklet, args, resolve);
|
||||
});
|
||||
};
|
||||
}
|
||||
if (__DEV__) {
|
||||
function runOnUIAsyncWorklet() {
|
||||
'worklet';
|
||||
|
||||
throw new WorkletsError('`runOnUIAsync` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.');
|
||||
}
|
||||
const serializableRunOnUIAsyncWorklet = createSerializable(runOnUIAsyncWorklet);
|
||||
serializableMappingCache.set(runOnUIAsync, serializableRunOnUIAsyncWorklet);
|
||||
}
|
||||
let runOnUIQueue = [];
|
||||
function enqueueUI(worklet, args, resolve) {
|
||||
const job = [worklet, args, resolve];
|
||||
runOnUIQueue.push(job);
|
||||
@@ -42,20 +317,31 @@ function flushUIQueue() {
|
||||
queueMicrotask(() => {
|
||||
const queue = runOnUIQueue;
|
||||
runOnUIQueue = [];
|
||||
requestAnimationFrameImpl(() => {
|
||||
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
||||
'worklet';
|
||||
|
||||
queue.forEach(([workletFunction, workletArgs, jobResolve]) => {
|
||||
const result = workletFunction(...workletArgs);
|
||||
if (jobResolve) {
|
||||
jobResolve(result);
|
||||
runOnJS(jobResolve)(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
callMicrotasks();
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Added temporarily for integration with `react-native-audio-api`. Don't depend
|
||||
* on this API as it may change without notice.
|
||||
*/
|
||||
// eslint-disable-next-line camelcase
|
||||
export function unstable_eventLoopTask() {
|
||||
throw new WorkletsError('`unstable_eventLoopTask` is not supported on web.');
|
||||
export function unstable_eventLoopTask(worklet) {
|
||||
return (...args) => {
|
||||
'worklet';
|
||||
|
||||
worklet(...args);
|
||||
callMicrotasks();
|
||||
};
|
||||
}
|
||||
const requestAnimationFrameImpl = !globalThis.requestAnimationFrame ? mockedRequestAnimationFrame : globalThis.requestAnimationFrame;
|
||||
//# sourceMappingURL=threads.js.map
|
||||
+1
-1
File diff suppressed because one or more lines are too long
-319
@@ -1,319 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
import { WorkletsError } from './debug/WorkletsError';
|
||||
import { createSerializable, makeShareableCloneOnUIRecursive } from './memory/serializable';
|
||||
import { serializableMappingCache } from './memory/serializableMappingCache';
|
||||
import { RuntimeKind } from './runtimeKind';
|
||||
import { isWorkletFunction } from './workletFunction';
|
||||
import { WorkletsModule } from './WorkletsModule/NativeWorklets';
|
||||
let runOnUIQueue = [];
|
||||
export function setupMicrotasks() {
|
||||
'worklet';
|
||||
|
||||
let microtasksQueue = [];
|
||||
let isExecutingMicrotasksQueue = false;
|
||||
globalThis.queueMicrotask = callback => {
|
||||
microtasksQueue.push(callback);
|
||||
};
|
||||
globalThis._microtaskQueueFinalizers = [];
|
||||
globalThis.__callMicrotasks = () => {
|
||||
if (isExecutingMicrotasksQueue) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
isExecutingMicrotasksQueue = true;
|
||||
for (let index = 0; index < microtasksQueue.length; index += 1) {
|
||||
// we use classic 'for' loop because the size of the currentTasks array may change while executing some of the callbacks due to queueMicrotask calls
|
||||
microtasksQueue[index]();
|
||||
}
|
||||
microtasksQueue = [];
|
||||
globalThis._microtaskQueueFinalizers.forEach(finalizer => finalizer());
|
||||
} finally {
|
||||
isExecutingMicrotasksQueue = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
function callMicrotasksOnUIThread() {
|
||||
'worklet';
|
||||
|
||||
globalThis.__callMicrotasks();
|
||||
}
|
||||
export const callMicrotasks = callMicrotasksOnUIThread;
|
||||
|
||||
/**
|
||||
* Lets you schedule a function to be executed on the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
||||
*
|
||||
* - The callback executes asynchronously and doesn't return a value.
|
||||
* - Passed function and args are automatically
|
||||
* [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
|
||||
* and serialized.
|
||||
* - This function cannot be called from the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime)
|
||||
* or a [Worker
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime),
|
||||
* unless you have the [Bundle Mode](/docs/experimental/bundleMode) enabled.
|
||||
*
|
||||
* @param fun - A reference to a function you want to schedule on the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
||||
* @param args - Arguments to pass to the function.
|
||||
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/scheduleOnUI
|
||||
*/
|
||||
// @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 scheduleOnUI(worklet, ...args) {
|
||||
if (__DEV__ && !isWorkletFunction(worklet) && !worklet.__bundleData) {
|
||||
throw new WorkletsError('`scheduleOnUI` can only be used with worklets.');
|
||||
}
|
||||
if (__DEV__) {
|
||||
// in DEV mode we call serializable conversion here because in case the object
|
||||
// can't be converted, we will get a meaningful stack-trace as opposed to the
|
||||
// situation when conversion is only done via microtask queue. This does not
|
||||
// make the app particularily less efficient as converted objects are cached
|
||||
// and for a given worklet the conversion only happens once.
|
||||
createSerializable(worklet);
|
||||
createSerializable(args);
|
||||
}
|
||||
enqueueUI(worklet, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets you asynchronously run
|
||||
* [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
|
||||
* functions on the [UI
|
||||
* thread](https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI/).
|
||||
*
|
||||
* This method does not schedule the work immediately but instead waits for
|
||||
* other worklets to be scheduled within the same JS loop. It uses
|
||||
* queueMicrotask to schedule all the worklets at once making sure they will run
|
||||
* within the same frame boundaries on the UI thread.
|
||||
*
|
||||
* @param fun - A reference to a function you want to execute on the [UI
|
||||
* thread](https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI/)
|
||||
* from the [JavaScript
|
||||
* thread](https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI/).
|
||||
* @returns A function that accepts arguments for the function passed as the
|
||||
* first argument.
|
||||
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI @deprecated Use `scheduleOnUI` instead.
|
||||
*/
|
||||
// @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 runOnUI(worklet) {
|
||||
if (__DEV__ && !isWorkletFunction(worklet) && !worklet.__bundleData) {
|
||||
throw new WorkletsError('`runOnUI` can only be used with worklets.');
|
||||
}
|
||||
return (...args) => {
|
||||
scheduleOnUI(worklet, ...args);
|
||||
};
|
||||
}
|
||||
if (__DEV__) {
|
||||
function runOnUIWorklet() {
|
||||
'worklet';
|
||||
|
||||
throw new WorkletsError('`runOnUI` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.');
|
||||
}
|
||||
const serializableRunOnUIWorklet = createSerializable(runOnUIWorklet);
|
||||
serializableMappingCache.set(runOnUI, serializableRunOnUIWorklet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets you run a function synchronously on the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime)
|
||||
* from the [RN
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#rn-runtime).
|
||||
* Passed function and args are automatically
|
||||
* [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
|
||||
* and serialized.
|
||||
*
|
||||
* - This function cannot be called from the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
||||
* - This function cannot be called from a [Worker
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime).
|
||||
*
|
||||
* @param fun - A reference to a function you want to execute on the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
||||
* @param args - Arguments to pass to the function.
|
||||
* @returns The return value of the function passed as the first argument.
|
||||
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUISync
|
||||
*/
|
||||
// @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 runOnUISync(worklet, ...args) {
|
||||
return WorkletsModule.executeOnUIRuntimeSync(createSerializable(() => {
|
||||
'worklet';
|
||||
|
||||
const result = worklet(...args);
|
||||
return makeShareableCloneOnUIRecursive(result);
|
||||
}));
|
||||
}
|
||||
|
||||
// @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 executeOnUIRuntimeSync(worklet) {
|
||||
return (...args) => {
|
||||
return runOnUISync(worklet, ...args);
|
||||
};
|
||||
}
|
||||
function runWorkletOnJS(worklet, ...args) {
|
||||
// remote function that calls a worklet synchronously on the JS runtime
|
||||
worklet(...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets you schedule a function to be executed on the RN runtime from any
|
||||
* runtime. Check
|
||||
* {@link https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds}
|
||||
* for more information about the different runtime kinds.
|
||||
*
|
||||
* Scheduling function from the RN Runtime (we are already on RN Runtime) simply
|
||||
* uses `queueMicrotask`.
|
||||
*
|
||||
* When functions need to be scheduled from the UI Runtime, first function and
|
||||
* args are serialized and then the system passes the scheduling responsibility
|
||||
* to the JSScheduler. The JSScheduler then uses the RN CallInvoker to schedule
|
||||
* the function asynchronously on the JavaScript thread by calling
|
||||
* `jsCallInvoker_->invokeAsync()`.
|
||||
*
|
||||
* When called from a Worker Runtime, it uses the same JSScheduler mechanism.
|
||||
*
|
||||
* @param fun - A function you want to schedule on the RN runtime. A function
|
||||
* can be a worklet, a remote function or a regular function.
|
||||
* @param args - Arguments to pass to the function.
|
||||
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/scheduleOnRN
|
||||
*/
|
||||
export function scheduleOnRN(fun, ...args) {
|
||||
'worklet';
|
||||
|
||||
if (globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
||||
// if we are already on the JS thread, we just schedule the worklet on the JS queue
|
||||
queueMicrotask(args.length ? () => fun(...args) : fun);
|
||||
return;
|
||||
}
|
||||
if (isWorkletFunction(fun)) {
|
||||
// If `fun` is a worklet, we schedule a call of a remote function `runWorkletOnJS`
|
||||
// and pass the worklet as a first argument followed by original arguments.
|
||||
scheduleOnRN(runWorkletOnJS, fun, ...args);
|
||||
return;
|
||||
}
|
||||
if (fun.__remoteFunction) {
|
||||
// In development mode the function provided as `fun` throws an error message
|
||||
// such that when someone accidentally calls it directly on the UI runtime, they
|
||||
// see that they should use `runOnJS` instead. To facilitate that we put the
|
||||
// reference to the original remote function in the `__remoteFunction` property.
|
||||
fun = fun.__remoteFunction;
|
||||
}
|
||||
const scheduleOnRNImpl = typeof fun === 'function' ? globalThis._scheduleHostFunctionOnJS : globalThis._scheduleRemoteFunctionOnJS;
|
||||
scheduleOnRNImpl(fun, args.length > 0 ? makeShareableCloneOnUIRecursive(args) : undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets you asynchronously run
|
||||
* non-[workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
|
||||
* functions that couldn't otherwise run on the [UI
|
||||
* thread](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-thread).
|
||||
* This applies to most external libraries as they don't have their functions
|
||||
* marked with "worklet"; directive.
|
||||
*
|
||||
* @param fun - A reference to a function you want to execute on the JavaScript
|
||||
* thread from the UI thread.
|
||||
* @returns A function that accepts arguments for the function passed as the
|
||||
* first argument.
|
||||
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnJS
|
||||
*/
|
||||
/** @deprecated Use `scheduleOnRN` instead. */
|
||||
export function runOnJS(fun) {
|
||||
'worklet';
|
||||
|
||||
return (...args) => {
|
||||
scheduleOnRN(fun, ...args);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets you asynchronously run
|
||||
* [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
|
||||
* functions on the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
||||
*
|
||||
* This method does not schedule the work immediately but instead waits for
|
||||
* other worklets to be scheduled within the same JS loop. It uses
|
||||
* queueMicrotask to schedule all the worklets at once making sure they will run
|
||||
* within the same frame boundaries on the UI thread.
|
||||
*
|
||||
* @param fun - A reference to a function you want to execute on the [UI
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
||||
* from the [JavaScript
|
||||
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#javascript-runtime).
|
||||
* @returns A promise that resolves to the return value of the function passed
|
||||
* as the first argument.
|
||||
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUIAsync
|
||||
*/
|
||||
export function runOnUIAsync(worklet, ...args) {
|
||||
if (__DEV__ && !isWorkletFunction(worklet)) {
|
||||
throw new WorkletsError('`runOnUIAsync` can only be used with worklets.');
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
if (__DEV__) {
|
||||
// in DEV mode we call serializable conversion here because in case the object
|
||||
// can't be converted, we will get a meaningful stack-trace as opposed to the
|
||||
// situation when conversion is only done via microtask queue. This does not
|
||||
// make the app particularily less efficient as converted objects are cached
|
||||
// and for a given worklet the conversion only happens once.
|
||||
createSerializable(worklet);
|
||||
createSerializable(args);
|
||||
}
|
||||
enqueueUI(worklet, args, resolve);
|
||||
});
|
||||
}
|
||||
if (__DEV__) {
|
||||
function runOnUIAsyncWorklet() {
|
||||
'worklet';
|
||||
|
||||
throw new WorkletsError('`runOnUIAsync` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.');
|
||||
}
|
||||
const serializableRunOnUIAsyncWorklet = createSerializable(runOnUIAsyncWorklet);
|
||||
serializableMappingCache.set(runOnUIAsync, serializableRunOnUIAsyncWorklet);
|
||||
}
|
||||
function enqueueUI(worklet, args, resolve) {
|
||||
const job = [worklet, args, resolve];
|
||||
runOnUIQueue.push(job);
|
||||
if (runOnUIQueue.length === 1) {
|
||||
flushUIQueue();
|
||||
}
|
||||
}
|
||||
function flushUIQueue() {
|
||||
queueMicrotask(() => {
|
||||
const queue = runOnUIQueue;
|
||||
runOnUIQueue = [];
|
||||
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
||||
'worklet';
|
||||
|
||||
queue.forEach(([workletFunction, workletArgs, jobResolve]) => {
|
||||
const result = workletFunction(...workletArgs);
|
||||
if (jobResolve) {
|
||||
runOnJS(jobResolve)(result);
|
||||
}
|
||||
});
|
||||
callMicrotasks();
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Added temporarily for integration with `react-native-audio-api`. Don't depend
|
||||
* on this API as it may change without notice.
|
||||
*/
|
||||
// eslint-disable-next-line camelcase
|
||||
export function unstable_eventLoopTask(worklet) {
|
||||
return (...args) => {
|
||||
'worklet';
|
||||
|
||||
worklet(...args);
|
||||
callMicrotasks();
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=threads.native.js.map
|
||||
Generated
Vendored
-1
File diff suppressed because one or more lines are too long
-5
@@ -1,5 +0,0 @@
|
||||
/* eslint-disable reanimated/use-global-this */
|
||||
'use strict';
|
||||
|
||||
export {};
|
||||
//# sourceMappingURL=types.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"AAAA;AACA,YAAY;;AAAC","ignoreList":[]}
|
||||
+3
-2
@@ -2,8 +2,9 @@
|
||||
|
||||
/**
|
||||
* This function allows you to determine if a given function is a worklet. It
|
||||
* only works with Worklets Babel plugin enabled. Unless you are doing something
|
||||
* with internals of Worklets you shouldn't need to use this function.
|
||||
* only works with Reanimated Babel plugin enabled. Unless you are doing
|
||||
* something with internals of Reanimated you shouldn't need to use this
|
||||
* function.
|
||||
*
|
||||
* ### Note
|
||||
*
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"names":["isWorkletFunction","value","__workletHash"],"sourceRoot":"../../src","sources":["workletFunction.ts"],"mappings":"AAAA,YAAY;;AAIZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,iBAAiBA,CAG/BC,KAAc,EAA+C;EAC7D,SAAS;;EACT;EACA;EAEA;IACE;IACA,OAAOA,KAAK,KAAK,UAAU,IAC3B,CAAC,CAAEA,KAAK,CAAwCC;EAAa;AAEjE","ignoreList":[]}
|
||||
{"version":3,"names":["isWorkletFunction","value","__workletHash"],"sourceRoot":"../../src","sources":["workletFunction.ts"],"mappings":"AAAA,YAAY;;AAIZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,iBAAiBA,CAG/BC,KAAc,EAA+C;EAC7D,SAAS;;EACT;EACA;EAEA;IACE;IACA,OAAOA,KAAK,KAAK,UAAU,IAC3B,CAAC,CAAEA,KAAK,CAAwCC;EAAa;AAEjE","ignoreList":[]}
|
||||
|
||||
Generated
Vendored
+1
-2
@@ -1,4 +1,3 @@
|
||||
import type { IWorkletsModule } from './workletsModuleProxy';
|
||||
export type { IWorkletsModule, WorkletsModuleProxy, } from './workletsModuleProxy';
|
||||
export declare const WorkletsModule: IWorkletsModule;
|
||||
export declare function createNativeWorkletsModule(): IWorkletsModule;
|
||||
//# sourceMappingURL=NativeWorklets.d.ts.map
|
||||
Generated
Vendored
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"NativeWorklets.d.ts","sourceRoot":"","sources":["../../../src/WorkletsModule/NativeWorklets.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,YAAY,EACV,eAAe,EACf,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,cAAc,EAAE,eAAuB,CAAC"}
|
||||
{"version":3,"file":"NativeWorklets.d.ts","sourceRoot":"","sources":["../../../src/WorkletsModule/NativeWorklets.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B,wBAAgB,0BAA0B,IAAI,eAAe,CAE5D"}
|
||||
Generated
Vendored
-3
@@ -1,3 +0,0 @@
|
||||
import type { IWorkletsModule } from './workletsModuleProxy';
|
||||
export declare const WorkletsModule: IWorkletsModule;
|
||||
//# sourceMappingURL=NativeWorklets.native.d.ts.map
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user