@depup/react-native-worklets 0.12.2-depup.0 → 0.13.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +1 -2
- package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +1 -1
- package/Common/cpp/worklets/Compat/StableApi.cpp +24 -8
- package/Common/cpp/worklets/Compat/StableApi.h +1 -1
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +113 -50
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +10 -1
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +95 -37
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +57 -7
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxyInitializer.cpp +94 -0
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxyInitializer.h +58 -0
- package/Common/cpp/worklets/Networking/Networking.cpp +283 -0
- package/Common/cpp/worklets/Networking/Networking.h +51 -0
- package/Common/cpp/worklets/Networking/NetworkingBackend.h +47 -0
- package/Common/cpp/worklets/Networking/NetworkingInstaller.cpp +127 -0
- package/Common/cpp/worklets/Networking/NetworkingInstaller.h +19 -0
- package/Common/cpp/worklets/Networking/NetworkingTypes.h +33 -0
- package/Common/cpp/worklets/Networking/TextDecoding.cpp +189 -0
- package/Common/cpp/worklets/Networking/TextDecoding.h +29 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueue.h +28 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +9 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +6 -0
- package/Common/cpp/worklets/RunLoop/EventLoop.cpp +19 -4
- package/Common/cpp/worklets/RunLoop/EventLoop.h +3 -0
- package/Common/cpp/worklets/SharedItems/MemoryManager.cpp +1 -1
- package/Common/cpp/worklets/SharedItems/MemoryManager.h +2 -1
- package/Common/cpp/worklets/SharedItems/Serializable/CustomSerializable.cpp +37 -0
- package/Common/cpp/worklets/SharedItems/Serializable/CustomSerializable.h +33 -0
- package/Common/cpp/worklets/SharedItems/Serializable/RetainingSerializable.h +112 -0
- package/Common/cpp/worklets/SharedItems/Serializable/Serializable.cpp +129 -0
- package/Common/cpp/worklets/SharedItems/Serializable/Serializable.h +121 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableArray.cpp +38 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableArray.h +39 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableArrayBuffer.cpp +35 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableArrayBuffer.h +43 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableBigInt.cpp +23 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableBigInt.h +35 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableError.cpp +38 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableError.h +30 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostFunction.cpp +24 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostFunction.h +32 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostObject.cpp +19 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostObject.h +25 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableImport.cpp +29 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableImport.h +25 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableMap.cpp +44 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableMap.h +25 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableObject.cpp +80 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableObject.h +35 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableRegExp.cpp +22 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableRegExp.h +25 -0
- package/Common/cpp/worklets/SharedItems/{SerializableRemoteFunction.cpp → Serializable/SerializableRemoteFunction.cpp} +30 -2
- package/Common/cpp/worklets/SharedItems/{SerializableRemoteFunction.h → Serializable/SerializableRemoteFunction.h} +24 -10
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableScalar.cpp +46 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableScalar.h +41 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableSet.cpp +36 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableSet.h +23 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableString.cpp +19 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableString.h +22 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableTurboModuleLike.cpp +26 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableTurboModuleLike.h +33 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableWorklet.cpp +31 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableWorklet.h +23 -0
- package/Common/cpp/worklets/SharedItems/Serializable.h +21 -409
- package/Common/cpp/worklets/SharedItems/Shareable.cpp +1 -1
- package/Common/cpp/worklets/SharedItems/Shareable.h +1 -1
- package/Common/cpp/worklets/SharedItems/Synchronizable.h +43 -20
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.cpp +24 -26
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.h +5 -7
- package/Common/cpp/worklets/SharedItems/SynchronizableDynamic.cpp +36 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableDynamic.h +27 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableFixed.cpp +76 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableFixed.h +48 -0
- package/Common/cpp/worklets/Tools/ScriptBuffer.h +0 -5
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +16 -30
- package/Common/cpp/worklets/WorkletRuntime/RuntimeBindings.h +27 -30
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +4 -3
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +2 -1
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +79 -29
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +34 -19
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +13 -86
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +1 -7
- package/Package.swift +147 -0
- package/README.md +5 -5
- package/RNWorklets.podspec +1 -2
- package/android/CMakeLists.txt +7 -26
- package/android/build.gradle.kts +5 -31
- package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +46 -129
- package/android/src/main/cpp/worklets/android/WorkletsModule.h +21 -11
- package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +2 -4
- package/android/src/main/cpp/worklets/android/networking/AndroidNetworkingBackend.cpp +82 -0
- package/android/src/main/cpp/worklets/android/networking/AndroidNetworkingBackend.h +32 -0
- package/android/src/main/cpp/worklets/android/networking/JNetworkRequestListener.cpp +73 -0
- package/android/src/main/cpp/worklets/android/networking/JNetworkRequestListener.h +38 -0
- package/android/src/{no-networking → main/java}/com/swmansion/worklets/WorkletsModule.kt +39 -28
- package/android/src/main/java/com/swmansion/worklets/networking/NetworkRequestListener.kt +37 -0
- package/android/src/main/java/com/swmansion/worklets/networking/Networking.kt +244 -0
- package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameQueue.kt +3 -0
- package/apple/worklets/apple/AnimationFrameQueue.mm +9 -1
- package/apple/worklets/apple/AssertJavaScriptQueue.h +3 -2
- package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +4 -0
- package/apple/worklets/apple/IOSUIScheduler.mm +3 -0
- package/apple/worklets/apple/Networking/AppleNetworkingBackend.h +29 -0
- package/apple/worklets/apple/Networking/AppleNetworkingBackend.mm +93 -0
- package/apple/worklets/apple/Networking/WorkletsURLSessionDelegate.h +37 -0
- package/apple/worklets/apple/Networking/WorkletsURLSessionDelegate.mm +447 -0
- package/apple/worklets/apple/WorkletsModule.h +3 -2
- package/apple/worklets/apple/WorkletsModule.mm +82 -74
- package/bundleMode/index.js +10 -47
- package/bundleMode/polyfills/prepareBundleMode.js +16 -0
- package/changes.json +4 -4
- package/compatibility.json +4 -1
- package/lib/module/WorkletsModule/NativeWorklets.native.js +12 -9
- package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -1
- package/lib/module/debug/jsVersion.js +1 -1
- package/lib/module/featureFlags/staticFlags.json +0 -1
- package/lib/module/featureFlags/types.js +0 -1
- package/lib/module/featureFlags/types.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/initializers/initializers.native.js +5 -12
- package/lib/module/initializers/initializers.native.js.map +1 -1
- package/lib/module/memory/bundleUnpacker.native.js +2 -10
- package/lib/module/memory/bundleUnpacker.native.js.map +1 -1
- package/lib/module/memory/serializable.native.js +1 -29
- package/lib/module/memory/serializable.native.js.map +1 -1
- package/lib/module/memory/synchronizable.js +1 -1
- package/lib/module/memory/synchronizable.js.map +1 -1
- package/lib/module/memory/synchronizable.native.js +7 -3
- package/lib/module/memory/synchronizable.native.js.map +1 -1
- package/lib/module/memory/synchronizableUnpacker.native.js +7 -2
- package/lib/module/memory/synchronizableUnpacker.native.js.map +1 -1
- package/lib/module/memory/valueUnpacker.native.js +0 -8
- package/lib/module/memory/valueUnpacker.native.js.map +1 -1
- package/lib/module/mock.js +22 -1
- package/lib/module/mock.js.map +1 -1
- package/lib/module/networking/AbortController.js +43 -0
- package/lib/module/networking/AbortController.js.map +1 -0
- package/lib/module/networking/Blob.js +60 -0
- package/lib/module/networking/Blob.js.map +1 -0
- package/lib/module/networking/DOMException.js +35 -0
- package/lib/module/networking/DOMException.js.map +1 -0
- package/lib/module/networking/FileReader.js +83 -0
- package/lib/module/networking/FileReader.js.map +1 -0
- package/lib/module/networking/FormData.js +105 -0
- package/lib/module/networking/FormData.js.map +1 -0
- package/lib/module/networking/XMLHttpRequest.js +450 -0
- package/lib/module/networking/XMLHttpRequest.js.map +1 -0
- package/lib/module/networking/bytes.js +6 -0
- package/lib/module/networking/bytes.js.map +1 -0
- package/lib/module/networking/events.js +44 -0
- package/lib/module/networking/events.js.map +1 -0
- package/lib/module/networking/http.js +100 -0
- package/lib/module/networking/http.js.map +1 -0
- package/lib/module/networking/install.js +37 -0
- package/lib/module/networking/install.js.map +1 -0
- package/lib/module/networking/utf8.js +99 -0
- package/lib/module/networking/utf8.js.map +1 -0
- package/lib/module/privateGlobals.d.js +0 -1
- package/lib/module/privateGlobals.d.js.map +1 -1
- package/lib/module/runLoop/common/queueMicrotaskPolyfill.js +9 -0
- package/lib/module/runLoop/common/queueMicrotaskPolyfill.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +7 -3
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js.map +1 -1
- package/lib/module/runLoop/workletRuntime/index.js +1 -1
- package/lib/module/runLoop/workletRuntime/index.js.map +1 -1
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +1 -1
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js.map +1 -1
- package/lib/module/runLoop/workletRuntime/taskQueue.js +0 -13
- package/lib/module/runLoop/workletRuntime/taskQueue.js.map +1 -1
- package/lib/module/runtimes.native.js +8 -1
- package/lib/module/runtimes.native.js.map +1 -1
- package/lib/module/specs/NativeWorkletsModule.js.map +1 -1
- package/lib/module/threads.js +11 -0
- package/lib/module/threads.js.map +1 -1
- package/lib/module/threads.native.js +35 -42
- package/lib/module/threads.native.js.map +1 -1
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -1
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +6 -5
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -1
- package/lib/typescript/debug/jsVersion.d.ts +1 -1
- package/lib/typescript/featureFlags/types.d.ts +0 -1
- package/lib/typescript/featureFlags/types.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/memory/bundleUnpacker.native.d.ts.map +1 -1
- package/lib/typescript/memory/serializable.native.d.ts.map +1 -1
- package/lib/typescript/memory/synchronizable.d.ts +6 -2
- package/lib/typescript/memory/synchronizable.d.ts.map +1 -1
- package/lib/typescript/memory/synchronizable.native.d.ts +6 -2
- package/lib/typescript/memory/synchronizable.native.d.ts.map +1 -1
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts +1 -1
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts.map +1 -1
- package/lib/typescript/memory/types.d.ts +6 -0
- package/lib/typescript/memory/types.d.ts.map +1 -1
- package/lib/typescript/memory/valueUnpacker.native.d.ts.map +1 -1
- package/lib/typescript/networking/AbortController.d.ts +16 -0
- package/lib/typescript/networking/AbortController.d.ts.map +1 -0
- package/lib/typescript/networking/Blob.d.ts +16 -0
- package/lib/typescript/networking/Blob.d.ts.map +1 -0
- package/lib/typescript/networking/DOMException.d.ts +5 -0
- package/lib/typescript/networking/DOMException.d.ts.map +1 -0
- package/lib/typescript/networking/FileReader.d.ts +19 -0
- package/lib/typescript/networking/FileReader.d.ts.map +1 -0
- package/lib/typescript/networking/FormData.d.ts +30 -0
- package/lib/typescript/networking/FormData.d.ts.map +1 -0
- package/lib/typescript/networking/XMLHttpRequest.d.ts +77 -0
- package/lib/typescript/networking/XMLHttpRequest.d.ts.map +1 -0
- package/lib/typescript/networking/bytes.d.ts +2 -0
- package/lib/typescript/networking/bytes.d.ts.map +1 -0
- package/lib/typescript/networking/events.d.ts +18 -0
- package/lib/typescript/networking/events.d.ts.map +1 -0
- package/lib/typescript/networking/http.d.ts +14 -0
- package/lib/typescript/networking/http.d.ts.map +1 -0
- package/lib/typescript/networking/install.d.ts +2 -0
- package/lib/typescript/networking/install.d.ts.map +1 -0
- package/lib/typescript/networking/utf8.d.ts +4 -0
- package/lib/typescript/networking/utf8.d.ts.map +1 -0
- package/lib/typescript/runLoop/{workletRuntime/queueMicrotask.d.ts → common/queueMicrotaskPolyfill.d.ts} +1 -1
- package/lib/typescript/runLoop/common/queueMicrotaskPolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts.map +1 -1
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts +0 -2
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts.map +1 -1
- package/lib/typescript/runtimes.native.d.ts.map +1 -1
- package/lib/typescript/specs/NativeWorkletsModule.d.ts +1 -0
- package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -1
- package/lib/typescript/threads.d.ts +8 -0
- package/lib/typescript/threads.d.ts.map +1 -1
- package/lib/typescript/threads.native.d.ts +8 -1
- package/lib/typescript/threads.native.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +9 -5
- package/lib/typescript/types.d.ts.map +1 -1
- package/package.json +32 -18
- package/plugin/index.js +63 -93
- package/plugin-oxc/babel.d.ts +7 -0
- package/plugin-oxc/babel.js +200 -0
- package/plugin-oxc/index.d.ts +33 -0
- package/plugin-oxc/index.js +36 -0
- package/plugin-oxc/worklets-oxc-plugin.darwin-arm64.node +0 -0
- package/plugin-oxc/worklets-oxc-plugin.darwin-x64.node +0 -0
- package/plugin-oxc/worklets-oxc-plugin.linux-arm64.node +0 -0
- package/plugin-oxc/worklets-oxc-plugin.linux-x64.node +0 -0
- package/plugin-oxc/worklets-oxc-plugin.win32-arm64.node +0 -0
- package/plugin-oxc/worklets-oxc-plugin.win32-x64.node +0 -0
- package/react-native.config.js +5 -0
- package/scripts/worklets_utils.rb +0 -10
- package/src/WorkletsModule/NativeWorklets.native.ts +26 -9
- package/src/WorkletsModule/workletsModuleProxy.ts +15 -5
- package/src/debug/jsVersion.ts +1 -1
- package/src/featureFlags/staticFlags.json +0 -1
- package/src/featureFlags/types.ts +0 -1
- package/src/index.ts +3 -0
- package/src/initializers/initializers.native.ts +5 -13
- package/src/memory/bundleUnpacker.native.ts +6 -13
- package/src/memory/serializable.native.ts +1 -44
- package/src/memory/synchronizable.native.ts +38 -4
- package/src/memory/synchronizable.ts +22 -2
- package/src/memory/synchronizableUnpacker.native.ts +23 -4
- package/src/memory/types.ts +9 -0
- package/src/memory/valueUnpacker.native.ts +0 -8
- package/src/mock.ts +28 -1
- package/src/networking/AbortController.ts +57 -0
- package/src/networking/Blob.ts +74 -0
- package/src/networking/DOMException.ts +37 -0
- package/src/networking/FileReader.ts +99 -0
- package/src/networking/FormData.ts +135 -0
- package/src/networking/XMLHttpRequest.ts +557 -0
- package/src/networking/bytes.ts +8 -0
- package/src/networking/events.ts +61 -0
- package/src/networking/http.ts +173 -0
- package/src/networking/install.ts +38 -0
- package/src/networking/utf8.ts +122 -0
- package/src/privateGlobals.d.ts +20 -13
- package/src/runLoop/common/queueMicrotaskPolyfill.ts +12 -0
- package/src/runLoop/uiRuntime/requestAnimationFrame.ts +7 -4
- package/src/runLoop/workletRuntime/index.ts +1 -1
- package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +1 -1
- package/src/runLoop/workletRuntime/taskQueue.ts +0 -15
- package/src/runtimes.native.ts +10 -1
- package/src/specs/NativeWorkletsModule.ts +1 -0
- package/src/threads.native.ts +49 -54
- package/src/threads.ts +11 -0
- package/src/types.ts +9 -5
- package/Common/cpp/worklets/SharedItems/Serializable.cpp +0 -389
- package/Common/cpp/worklets/SharedItems/SerializableFactory.cpp +0 -172
- package/Common/cpp/worklets/SharedItems/SerializableFactory.h +0 -85
- package/Common/cpp/worklets/SharedItems/Synchronizable.cpp +0 -59
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.cpp +0 -51
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.h +0 -43
- package/android/src/networking/com/swmansion/worklets/WorkletRuntimeWrapper.kt +0 -27
- package/android/src/networking/com/swmansion/worklets/WorkletsHeaderUtil.kt +0 -30
- package/android/src/networking/com/swmansion/worklets/WorkletsModule.kt +0 -204
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworkEventUtil.kt +0 -272
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworking.kt +0 -1124
- package/android/src/networking/com/swmansion/worklets/WorkletsOkHttpCallUtil.kt +0 -40
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressListener.kt +0 -13
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressRequestBody.kt +0 -98
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressResponseBody.kt +0 -60
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressiveStringDecoder.kt +0 -87
- package/android/src/networking/com/swmansion/worklets/WorkletsRequestBodyUtil.kt +0 -181
- package/apple/worklets/apple/Networking/WorkletsNetworking.h +0 -25
- package/apple/worklets/apple/Networking/WorkletsNetworking.mm +0 -707
- package/bundleMode/shims/turboModuleRegistryShim.js +0 -47
- package/lib/module/bundleMode/network.native.js +0 -44
- package/lib/module/bundleMode/network.native.js.map +0 -1
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js +0 -11
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js.map +0 -1
- package/lib/typescript/bundleMode/network.native.d.ts +0 -7
- package/lib/typescript/bundleMode/network.native.d.ts.map +0 -1
- package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts.map +0 -1
- package/src/bundleMode/network.native.ts +0 -63
- package/src/runLoop/workletRuntime/queueMicrotask.ts +0 -13
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { toArrayBuffer } from './bytes';
|
|
4
|
+
import { stripUtf8Bom, utf8Decode, utf8Encode } from './utf8';
|
|
5
|
+
|
|
6
|
+
type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob;
|
|
7
|
+
|
|
8
|
+
export class Blob {
|
|
9
|
+
readonly type: string;
|
|
10
|
+
|
|
11
|
+
private bytes: Uint8Array;
|
|
12
|
+
|
|
13
|
+
constructor(parts: BlobPart[] = [], options: { type?: string } = {}) {
|
|
14
|
+
const chunks = parts.map(toUint8Array);
|
|
15
|
+
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
16
|
+
const bytes = new Uint8Array(totalLength);
|
|
17
|
+
let offset = 0;
|
|
18
|
+
for (const chunk of chunks) {
|
|
19
|
+
bytes.set(chunk, offset);
|
|
20
|
+
offset += chunk.length;
|
|
21
|
+
}
|
|
22
|
+
this.bytes = bytes;
|
|
23
|
+
this.type = String(options.type ?? '').toLowerCase();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get size(): number {
|
|
27
|
+
return this.bytes.byteLength;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get [Symbol.toStringTag]() {
|
|
31
|
+
return 'Blob';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
slice(start = 0, end = this.size, contentType = ''): Blob {
|
|
35
|
+
const size = this.size;
|
|
36
|
+
const relativeStart =
|
|
37
|
+
start < 0 ? Math.max(size + start, 0) : Math.min(start, size);
|
|
38
|
+
const relativeEnd = end < 0 ? Math.max(size + end, 0) : Math.min(end, size);
|
|
39
|
+
const span = Math.max(relativeEnd - relativeStart, 0);
|
|
40
|
+
const blob = new Blob([], { type: contentType });
|
|
41
|
+
blob.bytes = this.bytes.slice(relativeStart, relativeStart + span);
|
|
42
|
+
return blob;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
arrayBuffer(): Promise<ArrayBuffer> {
|
|
46
|
+
return Promise.resolve(toArrayBuffer(this.bytes));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
text(): Promise<string> {
|
|
50
|
+
return Promise.resolve(utf8Decode(stripUtf8Bom(this.bytes)));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
__getBytes(): Uint8Array {
|
|
54
|
+
return this.bytes;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function toUint8Array(part: BlobPart): Uint8Array {
|
|
59
|
+
if (typeof part === 'string') {
|
|
60
|
+
return utf8Encode(part);
|
|
61
|
+
}
|
|
62
|
+
if (part instanceof Blob) {
|
|
63
|
+
return part.__getBytes();
|
|
64
|
+
}
|
|
65
|
+
if (ArrayBuffer.isView(part)) {
|
|
66
|
+
return new Uint8Array(
|
|
67
|
+
part.buffer.slice(part.byteOffset, part.byteOffset + part.byteLength)
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
if (part instanceof ArrayBuffer) {
|
|
71
|
+
return new Uint8Array(part.slice(0));
|
|
72
|
+
}
|
|
73
|
+
return utf8Encode(String(part));
|
|
74
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const LEGACY_CODES: Record<string, number> = {
|
|
4
|
+
IndexSizeError: 1,
|
|
5
|
+
HierarchyRequestError: 3,
|
|
6
|
+
WrongDocumentError: 4,
|
|
7
|
+
InvalidCharacterError: 5,
|
|
8
|
+
NoModificationAllowedError: 7,
|
|
9
|
+
NotFoundError: 8,
|
|
10
|
+
NotSupportedError: 9,
|
|
11
|
+
InUseAttributeError: 10,
|
|
12
|
+
InvalidStateError: 11,
|
|
13
|
+
SyntaxError: 12,
|
|
14
|
+
InvalidModificationError: 13,
|
|
15
|
+
NamespaceError: 14,
|
|
16
|
+
InvalidAccessError: 15,
|
|
17
|
+
TypeMismatchError: 17,
|
|
18
|
+
SecurityError: 18,
|
|
19
|
+
NetworkError: 19,
|
|
20
|
+
AbortError: 20,
|
|
21
|
+
URLMismatchError: 21,
|
|
22
|
+
QuotaExceededError: 22,
|
|
23
|
+
TimeoutError: 23,
|
|
24
|
+
InvalidNodeTypeError: 24,
|
|
25
|
+
DataCloneError: 25,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export class DOMException extends Error {
|
|
29
|
+
readonly code: number;
|
|
30
|
+
|
|
31
|
+
constructor(message = '', name = 'Error') {
|
|
32
|
+
super(message);
|
|
33
|
+
Object.setPrototypeOf(this, DOMException.prototype);
|
|
34
|
+
this.name = name;
|
|
35
|
+
this.code = LEGACY_CODES[name] ?? 0;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import type { Blob } from './Blob';
|
|
4
|
+
import { toArrayBuffer } from './bytes';
|
|
5
|
+
import { utf8Decode } from './utf8';
|
|
6
|
+
|
|
7
|
+
const EMPTY = 0;
|
|
8
|
+
const LOADING = 1;
|
|
9
|
+
const DONE = 2;
|
|
10
|
+
|
|
11
|
+
const CHARSET_PARAMETER_PATTERN = /;\s*charset\s*=\s*("([^"]*)"|([^;\s]*))/i;
|
|
12
|
+
|
|
13
|
+
export class FileReader {
|
|
14
|
+
static readonly EMPTY = EMPTY;
|
|
15
|
+
static readonly LOADING = LOADING;
|
|
16
|
+
static readonly DONE = DONE;
|
|
17
|
+
|
|
18
|
+
readonly EMPTY = EMPTY;
|
|
19
|
+
readonly LOADING = LOADING;
|
|
20
|
+
readonly DONE = DONE;
|
|
21
|
+
|
|
22
|
+
readyState = EMPTY;
|
|
23
|
+
result: string | ArrayBuffer | null = null;
|
|
24
|
+
error: unknown = null;
|
|
25
|
+
|
|
26
|
+
onload: (() => void) | null = null;
|
|
27
|
+
onerror: (() => void) | null = null;
|
|
28
|
+
onloadend: (() => void) | null = null;
|
|
29
|
+
|
|
30
|
+
readAsArrayBuffer(blob: Blob) {
|
|
31
|
+
this.read(() => toArrayBuffer(readBytes(blob)));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
readAsText(blob: Blob, encoding?: string) {
|
|
35
|
+
this.read(() => {
|
|
36
|
+
const bytes = readBytes(blob);
|
|
37
|
+
const resolvedEncoding = encoding ?? extractCharset(blob.type);
|
|
38
|
+
const networking = globalThis.__workletsNetworking;
|
|
39
|
+
if (networking !== undefined) {
|
|
40
|
+
return networking.decodeText(toArrayBuffer(bytes), resolvedEncoding);
|
|
41
|
+
}
|
|
42
|
+
return utf8Decode(bytes);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private read(produceResult: () => string | ArrayBuffer) {
|
|
47
|
+
if (this.readyState === LOADING) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
"[Worklets] Failed to execute 'read' on 'FileReader': the object is already loading."
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
this.result = null;
|
|
53
|
+
this.error = null;
|
|
54
|
+
this.readyState = LOADING;
|
|
55
|
+
/**
|
|
56
|
+
* The File API fires read events from a task, not from a microtask, so
|
|
57
|
+
* `setTimeout` is used here rather than `queueMicrotask`. Reads are started
|
|
58
|
+
* from Promise continuations, which makes the distinction observable.
|
|
59
|
+
*/
|
|
60
|
+
setTimeout(() => {
|
|
61
|
+
let failed = false;
|
|
62
|
+
try {
|
|
63
|
+
this.result = produceResult();
|
|
64
|
+
} catch (error) {
|
|
65
|
+
this.error = error;
|
|
66
|
+
failed = true;
|
|
67
|
+
}
|
|
68
|
+
this.readyState = DONE;
|
|
69
|
+
invoke(failed ? this.onerror : this.onload);
|
|
70
|
+
invoke(this.onloadend);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function invoke(handler: (() => void) | null) {
|
|
76
|
+
try {
|
|
77
|
+
handler?.();
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error(error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function readBytes(blob: Blob): Uint8Array {
|
|
84
|
+
if (typeof blob?.__getBytes !== 'function') {
|
|
85
|
+
throw new Error(
|
|
86
|
+
'[Worklets] FileReader can only read a Blob created by the Worklets networking module.'
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return blob.__getBytes();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function extractCharset(mimeType: string): string | undefined {
|
|
93
|
+
const match = CHARSET_PARAMETER_PATTERN.exec(mimeType);
|
|
94
|
+
if (match === null) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
const charset = match[2] ?? match[3] ?? '';
|
|
98
|
+
return charset !== '' ? charset : undefined;
|
|
99
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { toArrayBuffer } from './bytes';
|
|
4
|
+
import { utf8Encode } from './utf8';
|
|
5
|
+
|
|
6
|
+
export class FormData {
|
|
7
|
+
private formEntries: Array<[string, string]> = [];
|
|
8
|
+
|
|
9
|
+
get [Symbol.toStringTag]() {
|
|
10
|
+
return 'FormData';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
append(name: string, value: unknown) {
|
|
14
|
+
if (value !== null && typeof value === 'object') {
|
|
15
|
+
throw new TypeError(
|
|
16
|
+
"[Worklets] Failed to execute 'append' on 'FormData': only string values are supported."
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
this.formEntries.push([String(name), String(value)]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
set(name: string, value: unknown) {
|
|
23
|
+
this.delete(name);
|
|
24
|
+
this.append(name, value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get(name: string): string | null {
|
|
28
|
+
const entry = this.formEntries.find(
|
|
29
|
+
([entryName]) => entryName === String(name)
|
|
30
|
+
);
|
|
31
|
+
return entry !== undefined ? entry[1] : null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getAll(name: string): string[] {
|
|
35
|
+
return this.formEntries
|
|
36
|
+
.filter(([entryName]) => entryName === String(name))
|
|
37
|
+
.map(([, value]) => value);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
has(name: string): boolean {
|
|
41
|
+
return this.formEntries.some(([entryName]) => entryName === String(name));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
delete(name: string) {
|
|
45
|
+
this.formEntries = this.formEntries.filter(
|
|
46
|
+
([entryName]) => entryName !== String(name)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
forEach(callback: (value: string, name: string, formData: FormData) => void) {
|
|
51
|
+
for (const [name, value] of this.formEntries) {
|
|
52
|
+
callback(value, name, this);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
*entries(): IterableIterator<[string, string]> {
|
|
57
|
+
for (const [name, value] of this.formEntries) {
|
|
58
|
+
yield [name, value];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
*keys(): IterableIterator<string> {
|
|
63
|
+
for (const [name] of this.formEntries) {
|
|
64
|
+
yield name;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
*values(): IterableIterator<string> {
|
|
69
|
+
for (const [, value] of this.formEntries) {
|
|
70
|
+
yield value;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
[Symbol.iterator]() {
|
|
75
|
+
return this.entries();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Mirrors React Native's non-standard `FormData.getParts`. Its presence makes
|
|
80
|
+
* libraries like Axios treat this object as a React Native `FormData` and
|
|
81
|
+
* leave the multipart encoding to `XMLHttpRequest`.
|
|
82
|
+
*/
|
|
83
|
+
getParts(): Array<{
|
|
84
|
+
string: string;
|
|
85
|
+
fieldName: string;
|
|
86
|
+
headers: Record<string, string>;
|
|
87
|
+
}> {
|
|
88
|
+
return this.formEntries.map(([name, value]) => ({
|
|
89
|
+
string: value,
|
|
90
|
+
fieldName: name,
|
|
91
|
+
headers: {
|
|
92
|
+
'content-disposition': `form-data; name="${escapeName(name)}"`,
|
|
93
|
+
},
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
__encodeMultipart(): { body: ArrayBuffer; contentType: string } {
|
|
98
|
+
const parts = this.formEntries.map(
|
|
99
|
+
([name, value]) =>
|
|
100
|
+
`content-disposition: form-data; name="${escapeName(name)}"\r\n\r\n${value}`
|
|
101
|
+
);
|
|
102
|
+
const boundary = pickBoundary(parts);
|
|
103
|
+
let encoded = '';
|
|
104
|
+
for (const part of parts) {
|
|
105
|
+
encoded += `--${boundary}\r\n${part}\r\n`;
|
|
106
|
+
}
|
|
107
|
+
encoded += `--${boundary}--\r\n`;
|
|
108
|
+
return {
|
|
109
|
+
body: toArrayBuffer(utf8Encode(encoded)),
|
|
110
|
+
contentType: `multipart/form-data; boundary=${boundary}`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Picks a boundary that appears in none of the parts. Entry values are written
|
|
117
|
+
* verbatim, so a value that contained the boundary could otherwise inject
|
|
118
|
+
* arbitrary parts into the request.
|
|
119
|
+
*/
|
|
120
|
+
function pickBoundary(parts: string[]): string {
|
|
121
|
+
for (;;) {
|
|
122
|
+
const boundary = `----WorkletsFormDataBoundary${randomToken()}${randomToken()}`;
|
|
123
|
+
if (!parts.some((part) => part.includes(boundary))) {
|
|
124
|
+
return boundary;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function randomToken(): string {
|
|
130
|
+
return Math.random().toString(36).slice(2).padEnd(11, '0');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function escapeName(name: string): string {
|
|
134
|
+
return name.replace(/\r/g, '%0D').replace(/\n/g, '%0A').replace(/"/g, '%22');
|
|
135
|
+
}
|