@amazon-devices/react-native-worklets 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/Common/cpp/worklets/Registries/EventHandlerRegistry.h +5 -3
  2. package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +5 -6
  3. package/Common/cpp/worklets/RunLoop/EventLoop.cpp +6 -6
  4. package/Common/cpp/worklets/SharedItems/Serializable.h +9 -8
  5. package/Common/cpp/worklets/Tools/JSISerializer.h +4 -4
  6. package/Common/cpp/worklets/Tools/JSScheduler.h +5 -3
  7. package/Common/cpp/worklets/Tools/SingleInstanceChecker.h +3 -2
  8. package/Common/cpp/worklets/Tools/UIScheduler.h +4 -4
  9. package/Common/cpp/worklets/Tools/VersionUtils.h +1 -4
  10. package/Common/cpp/worklets/Tools/WorkletsSystraceSection.h +0 -25
  11. package/SystemModules/amzn__react-native-worklets-1.private.modules.txt +57 -33
  12. package/kepler-compatibility.json +3 -1
  13. package/lib/module/index.js +0 -25
  14. package/oss-attribution/attribution.txt +2262 -0
  15. package/oss-attribution/licenseInfos.json +585 -0
  16. package/package.json +1 -153
  17. package/src/index.ts +0 -52
  18. package/SystemBundles/cc12deac6e91c435b76698c8445aed85612f2f88e733218d14f88a35d06fb0f4.bundle +0 -10512
  19. package/SystemBundles/cc12deac6e91c435b76698c8445aed85612f2f88e733218d14f88a35d06fb0f4.map +0 -3771
  20. package/bundleMode/index.js +0 -59
  21. package/lib/module/PlatformChecker/PlatformChecker.js +0 -8
  22. package/lib/module/PlatformChecker/index.js +0 -18
  23. package/lib/module/WorkletsError.js +0 -29
  24. package/lib/module/WorkletsModule/JSWorklets.js +0 -111
  25. package/lib/module/WorkletsModule/NativeWorklets.js +0 -126
  26. package/lib/module/WorkletsModule/index.js +0 -4
  27. package/lib/module/WorkletsModule/workletsModuleInstance.js +0 -7
  28. package/lib/module/WorkletsModule/workletsModuleInstance.web.js +0 -5
  29. package/lib/module/WorkletsModule/workletsModuleProxy.js +0 -4
  30. package/lib/module/bundleUnpacker.js +0 -47
  31. package/lib/module/callGuard.js +0 -30
  32. package/lib/module/deprecated.js +0 -20
  33. package/lib/module/errors.js +0 -69
  34. package/lib/module/featureFlags/index.js +0 -48
  35. package/lib/module/initializers.js +0 -221
  36. package/lib/module/isSynchronizable.js +0 -6
  37. package/lib/module/logger.js +0 -15
  38. package/lib/module/privateGlobals.d.js +0 -7
  39. package/lib/module/publicGlobals.js +0 -6
  40. package/lib/module/runLoop/common/setImmediatePolyfill.js +0 -15
  41. package/lib/module/runLoop/common/setIntervalPolyfill.js +0 -26
  42. package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js +0 -10
  43. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +0 -52
  44. package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js +0 -32
  45. package/lib/module/runLoop/workletRuntime/index.js +0 -19
  46. package/lib/module/runLoop/workletRuntime/queueMicrotask.js +0 -11
  47. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +0 -48
  48. package/lib/module/runLoop/workletRuntime/setTimeout.js +0 -28
  49. package/lib/module/runLoop/workletRuntime/taskQueue.js +0 -37
  50. package/lib/module/runtimeKind.js +0 -39
  51. package/lib/module/runtimes.js +0 -100
  52. package/lib/module/serializable.js +0 -568
  53. package/lib/module/serializableMappingCache.js +0 -37
  54. package/lib/module/specs/NativeWorkletsModule.js +0 -5
  55. package/lib/module/specs/NativeWorkletsModule.kepler.js +0 -7
  56. package/lib/module/specs/index.js +0 -10
  57. package/lib/module/synchronizable.js +0 -9
  58. package/lib/module/synchronizableUnpacker.js +0 -42
  59. package/lib/module/threads.js +0 -347
  60. package/lib/module/utils/checkCppVersion.js +0 -30
  61. package/lib/module/utils/jsVersion.js +0 -9
  62. package/lib/module/valueUnpacker.js +0 -60
  63. package/lib/module/workletFunction.js +0 -37
  64. package/lib/module/workletRuntimeEntry.js +0 -32
  65. package/lib/module/workletTypes.js +0 -12
  66. package/scripts/validate-react-native-version.js +0 -43
  67. package/src/PlatformChecker/PlatformChecker.ts +0 -7
  68. package/src/PlatformChecker/index.ts +0 -30
  69. package/src/WorkletsError.ts +0 -36
  70. package/src/WorkletsModule/JSWorklets.ts +0 -200
  71. package/src/WorkletsModule/NativeWorklets.ts +0 -256
  72. package/src/WorkletsModule/index.ts +0 -7
  73. package/src/WorkletsModule/workletsModuleInstance.ts +0 -9
  74. package/src/WorkletsModule/workletsModuleInstance.web.ts +0 -5
  75. package/src/WorkletsModule/workletsModuleProxy.ts +0 -126
  76. package/src/bundleUnpacker.ts +0 -75
  77. package/src/callGuard.ts +0 -33
  78. package/src/deprecated.ts +0 -32
  79. package/src/errors.ts +0 -80
  80. package/src/featureFlags/index.ts +0 -72
  81. package/src/initializers.ts +0 -262
  82. package/src/isSynchronizable.ts +0 -13
  83. package/src/logger.ts +0 -16
  84. package/src/publicGlobals.ts +0 -39
  85. package/src/runLoop/common/setImmediatePolyfill.ts +0 -20
  86. package/src/runLoop/common/setIntervalPolyfill.ts +0 -38
  87. package/src/runLoop/uiRuntime/mockedRequestAnimationFrame.ts +0 -11
  88. package/src/runLoop/uiRuntime/requestAnimationFrame.ts +0 -66
  89. package/src/runLoop/uiRuntime/setTimeoutPolyfill.ts +0 -40
  90. package/src/runLoop/workletRuntime/index.ts +0 -18
  91. package/src/runLoop/workletRuntime/queueMicrotask.ts +0 -13
  92. package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +0 -61
  93. package/src/runLoop/workletRuntime/setTimeout.ts +0 -37
  94. package/src/runLoop/workletRuntime/taskQueue.ts +0 -44
  95. package/src/runtimeKind.ts +0 -37
  96. package/src/runtimes.ts +0 -193
  97. package/src/serializable.ts +0 -801
  98. package/src/serializableMappingCache.ts +0 -42
  99. package/src/specs/NativeWorkletsModule.kepler.ts +0 -11
  100. package/src/specs/NativeWorkletsModule.ts +0 -9
  101. package/src/specs/index.ts +0 -13
  102. package/src/synchronizable.ts +0 -32
  103. package/src/synchronizableUnpacker.ts +0 -67
  104. package/src/threads.ts +0 -452
  105. package/src/utils/checkCppVersion.ts +0 -34
  106. package/src/utils/jsVersion.ts +0 -7
  107. package/src/valueUnpacker.ts +0 -90
  108. package/src/workletFunction.ts +0 -42
  109. package/src/workletRuntimeEntry.ts +0 -35
  110. package/src/workletTypes.ts +0 -81
@@ -1,90 +0,0 @@
1
- 'use strict';
2
- import type { ValueUnpacker, WorkletFunction } from './workletTypes';
3
-
4
- declare global {
5
- var evalWithSourceMap:
6
- | ((js: string, sourceURL: string, sourceMap: string) => () => unknown)
7
- | undefined;
8
- var evalWithSourceUrl:
9
- | ((js: string, sourceURL: string) => () => unknown)
10
- | undefined;
11
- }
12
-
13
- function __installUnpacker() {
14
- const workletsCache = new Map<number, () => unknown>();
15
- const handleCache = new WeakMap<object, unknown>();
16
-
17
- function valueUnpacker(
18
- objectToUnpack: ObjectToUnpack,
19
- category?: string,
20
- remoteFunctionName?: string
21
- ): unknown {
22
- 'use strict';
23
- const workletHash = objectToUnpack.__workletHash;
24
- if (workletHash !== undefined) {
25
- let workletFun = workletsCache.get(workletHash);
26
- if (workletFun === undefined) {
27
- const initData = objectToUnpack.__initData;
28
- if (globalThis.evalWithSourceMap) {
29
- // if the runtime (hermes only for now) supports loading source maps
30
- // we want to use the proper filename for the location as it guarantees
31
- // that debugger understands and loads the source code of the file where
32
- // the worklet is defined.
33
- workletFun = globalThis.evalWithSourceMap(
34
- '(' + initData!.code + '\n)',
35
- initData!.location!,
36
- initData!.sourceMap!
37
- );
38
- } else if (globalThis.evalWithSourceUrl) {
39
- // if the runtime doesn't support loading source maps, in dev mode we
40
- // can pass source url when evaluating the worklet. Now, instead of using
41
- // the actual file location we use worklet hash, as it the allows us to
42
- // properly symbolicate traces (see errors.ts for details)
43
- workletFun = globalThis.evalWithSourceUrl(
44
- '(' + initData!.code + '\n)',
45
- `worklet_${workletHash}`
46
- );
47
- } else {
48
- // in release we use the regular eval to save on JSI calls
49
- // eslint-disable-next-line no-eval
50
- workletFun = eval('(' + initData!.code + '\n)');
51
- }
52
- workletsCache.set(workletHash, workletFun!);
53
- }
54
- const functionInstance = workletFun!.bind(objectToUnpack);
55
- objectToUnpack._recur = functionInstance;
56
- return functionInstance;
57
- } else if (objectToUnpack.__init !== undefined) {
58
- let value = handleCache.get(objectToUnpack);
59
- if (value === undefined) {
60
- value = objectToUnpack.__init();
61
- handleCache.set(objectToUnpack, value);
62
- }
63
- return value;
64
- } else if (category === 'RemoteFunction') {
65
- const fun = () => {
66
- const label = remoteFunctionName
67
- ? `function \`${remoteFunctionName}\``
68
- : 'anonymous function';
69
- // eslint-disable-next-line reanimated/use-worklets-error
70
- throw new Error(`[Worklets] Tried to synchronously call a non-worklet ${label} on the UI thread.
71
- See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-synchronously-call-a-non-worklet-function-on-the-ui-thread for more details.`);
72
- };
73
- fun.__remoteFunction = objectToUnpack;
74
- return fun;
75
- } else {
76
- // eslint-disable-next-line reanimated/use-worklets-error
77
- throw new Error(
78
- `[Worklets] Data type in category "${category}" not recognized by value unpacker: "${globalThis._toString(
79
- objectToUnpack
80
- )}".`
81
- );
82
- }
83
- }
84
-
85
- globalThis.__valueUnpacker = valueUnpacker as ValueUnpacker;
86
- }
87
-
88
- interface ObjectToUnpack extends WorkletFunction {
89
- _recur: unknown;
90
- }
@@ -1,42 +0,0 @@
1
- 'use strict';
2
-
3
- import type { WorkletFunction } from './workletTypes';
4
-
5
- /**
6
- * This function allows you to determine if a given function is a worklet. It
7
- * only works with Reanimated Babel plugin enabled. Unless you are doing
8
- * something with internals of Reanimated you shouldn't need to use this
9
- * function.
10
- *
11
- * ### Note
12
- *
13
- * Do not call it before the worklet is declared, as it will always return false
14
- * then. E.g.:
15
- *
16
- * ```ts
17
- * isWorkletFunction(myWorklet); // Will always return false.
18
- *
19
- * function myWorklet() {
20
- * 'worklet';
21
- * }
22
- * ```
23
- *
24
- * ### Maintainer note
25
- *
26
- * This function is supposed to be used only in the React Runtime. It always
27
- * returns `false` in Worklet Runtimes.
28
- */
29
- export function isWorkletFunction<
30
- Args extends unknown[] = unknown[],
31
- ReturnValue = unknown,
32
- >(value: unknown): value is WorkletFunction<Args, ReturnValue> {
33
- 'worklet';
34
- // Since host objects always return true for `in` operator, we have to use dot notation to check if the property exists.
35
- // See https://github.com/facebook/hermes/blob/340726ef8cf666a7cce75bc60b02fa56b3e54560/lib/VM/JSObject.cpp#L1276.
36
-
37
- return (
38
- // `__workletHash` isn't extracted in Worklet Runtimes.
39
- typeof value === 'function' &&
40
- !!(value as unknown as Record<string, unknown>).__workletHash
41
- );
42
- }
@@ -1,35 +0,0 @@
1
- 'use strict';
2
-
3
- import { init } from './initializers';
4
- import { SHOULD_BE_USE_WEB } from './PlatformChecker';
5
- import { RuntimeKind } from './runtimeKind';
6
- import { WorkletsError } from './WorkletsError';
7
-
8
- /**
9
- * This function is an entry point for Worklet Runtimes. We can use it to setup
10
- * necessary tools, like the ValueUnpacker.
11
- *
12
- * We must throw an error at the end of this function to prevent the bundle to
13
- * continue executing. This is because the next module to be ran would be the
14
- * React Native one, and it would break the Worklet Runtime if initialized. The
15
- * error is caught in C++ code.
16
- *
17
- * This function has no effect on the RN Runtime beside setting the
18
- * `_WORKLETS_BUNDLE_MODE` flag.
19
- */
20
- export function bundleModeInit() {
21
- globalThis._WORKLETS_BUNDLE_MODE = true;
22
- if (
23
- !SHOULD_BE_USE_WEB &&
24
- globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative
25
- ) {
26
- /**
27
- * We shouldn't call `init()` on RN Runtime here, as it would initialize our
28
- * module before React Native has configured the RN Runtime.
29
- */
30
- init();
31
- throw new WorkletsError('Worklets initialized successfully');
32
- }
33
- }
34
-
35
- bundleModeInit();
@@ -1,81 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * The below type is used for HostObjects returned by the JSI API that don't
5
- * have any accessible fields or methods but can carry data that is accessed
6
- * from the c++ side. We add a field to the type to make it possible for
7
- * typescript to recognize which JSI methods accept those types as arguments and
8
- * to be able to correctly type check other methods that may use them. However,
9
- * this field is not actually defined nor should be used for anything else as
10
- * assigning any data to those objects will throw an error.
11
- */
12
- export type SerializableRef<T = unknown> = {
13
- __serializableRef: true;
14
- __nativeStateSerializableJSRef: T;
15
- };
16
-
17
- // In case of objects with depth or arrays of objects or arrays of arrays etc.
18
- // we add this utility type that makes it a `SharaebleRef` of the outermost type.
19
- export type FlatSerializableRef<T> =
20
- T extends SerializableRef<infer U> ? SerializableRef<U> : SerializableRef<T>;
21
-
22
- export type WorkletRuntime = {
23
- __hostObjectWorkletRuntime: never;
24
- readonly name: string;
25
- };
26
-
27
- export type WorkletStackDetails = [
28
- error: Error,
29
- lineOffset: number,
30
- columnOffset: number,
31
- ];
32
-
33
- export type WorkletClosure = Record<string, unknown>;
34
-
35
- interface WorkletInitData {
36
- code: string;
37
- /** Only in dev builds. */
38
- location?: string;
39
- /** Only in dev builds. */
40
- sourceMap?: string;
41
- }
42
-
43
- interface WorkletProps {
44
- __closure: WorkletClosure;
45
- __workletHash: number;
46
- /** Only in Legacy Bundling. */
47
- __initData?: WorkletInitData;
48
- /** Only for Handles. */
49
- __init?: () => unknown;
50
- /** `__stackDetails` is removed after parsing. */
51
- __stackDetails?: WorkletStackDetails;
52
- /** Only in dev builds. */
53
- __pluginVersion?: string;
54
- }
55
-
56
- export type WorkletFunction<
57
- TArgs extends unknown[] = unknown[],
58
- TReturn = unknown,
59
- > = ((...args: TArgs) => TReturn) & WorkletProps;
60
-
61
- export interface WorkletFactory<
62
- TArgs extends unknown[] = unknown[],
63
- TReturn = unknown,
64
- TClosureVariables extends Record<string, unknown> = Record<string, unknown>,
65
- > {
66
- (closureVariables: TClosureVariables): WorkletFunction<TArgs, TReturn>;
67
- }
68
-
69
- export type ValueUnpacker = WorkletFunction<
70
- [objectToUnpack: unknown, category?: string],
71
- unknown
72
- >;
73
-
74
- export interface WorkletImport {
75
- __bundleData: {
76
- /** Name of the module which is the source of the import. */
77
- source: string;
78
- /** The name of the imported value. */
79
- imported: string;
80
- };
81
- }