@loaders.gl/scene 5.0.0-beta.2 → 5.0.0-beta.5
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/DRACO-README.md +1 -1
- package/GLTF-README.md +1 -1
- package/OBJ-README.md +1 -1
- package/README.md +6 -1
- package/THIRD-PARTY-NOTICES.md +6 -0
- package/dist/dist.dev.js +6557 -1363
- package/dist/dist.min.js +24 -16
- package/dist/draco/draco-javascript-loader-with-parser.d.ts +2 -2
- package/dist/draco/draco-loader-types.cjs +3 -3
- package/dist/draco/draco-loader-types.cjs.map +2 -2
- package/dist/draco/draco-loader-types.d.ts +1 -1
- package/dist/draco/draco-loader-types.d.ts.map +1 -1
- package/dist/draco/draco-loader-types.js +1 -1
- package/dist/draco/draco-loader-types.js.map +1 -1
- package/dist/draco/draco-loader.d.ts +2 -2
- package/dist/draco/draco-wasm-loader-with-parser.d.ts +2 -2
- package/dist/draco/draco3d-loader-with-parser.d.ts +2 -2
- package/dist/draco/lib/utils/version.cjs +1 -1
- package/dist/draco/lib/utils/version.js +1 -1
- package/dist/draco-worker-node.js +806 -158
- package/dist/draco-worker-node.js.map +4 -4
- package/dist/draco-worker.js +775 -158
- package/dist/draco-worker.js.map +4 -4
- package/dist/draco-writer-worker-node.cjs +2122 -219
- package/dist/draco-writer-worker-node.cjs.map +4 -4
- package/dist/draco-writer-worker.js +2053 -220
- package/dist/draco-writer-worker.js.map +4 -4
- package/dist/gltf/gltf-loader-types.cjs.map +2 -2
- package/dist/gltf/gltf-loader-types.d.ts +6 -0
- package/dist/gltf/gltf-loader-types.d.ts.map +1 -1
- package/dist/gltf/gltf-loader-types.js.map +1 -1
- package/dist/gltf/index.cjs +2 -0
- package/dist/gltf/index.cjs.map +2 -2
- package/dist/gltf/index.d.ts +2 -2
- package/dist/gltf/index.d.ts.map +1 -1
- package/dist/gltf/index.js +1 -1
- package/dist/gltf/index.js.map +1 -1
- package/dist/gltf/lib/api/gltf-extensions.cjs +7 -2
- package/dist/gltf/lib/api/gltf-extensions.cjs.map +2 -2
- package/dist/gltf/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/gltf/lib/api/gltf-extensions.js +7 -5
- package/dist/gltf/lib/api/gltf-extensions.js.map +1 -1
- package/dist/gltf/lib/extensions/EXT_texture_webp.cjs +1 -0
- package/dist/gltf/lib/extensions/EXT_texture_webp.cjs.map +2 -2
- package/dist/gltf/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/gltf/lib/extensions/EXT_texture_webp.js +3 -0
- package/dist/gltf/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/gltf/lib/extensions/KHR_accessor_float64.cjs +45 -0
- package/dist/gltf/lib/extensions/KHR_accessor_float64.cjs.map +7 -0
- package/dist/gltf/lib/extensions/KHR_accessor_float64.d.ts +6 -0
- package/dist/gltf/lib/extensions/KHR_accessor_float64.d.ts.map +1 -0
- package/dist/gltf/lib/extensions/KHR_accessor_float64.js +20 -0
- package/dist/gltf/lib/extensions/KHR_accessor_float64.js.map +1 -0
- package/dist/gltf/lib/extensions/KHR_gaussian_splatting.cjs +23 -7
- package/dist/gltf/lib/extensions/KHR_gaussian_splatting.cjs.map +2 -2
- package/dist/gltf/lib/extensions/KHR_gaussian_splatting.d.ts +2 -1
- package/dist/gltf/lib/extensions/KHR_gaussian_splatting.d.ts.map +1 -1
- package/dist/gltf/lib/extensions/KHR_gaussian_splatting.js +21 -5
- package/dist/gltf/lib/extensions/KHR_gaussian_splatting.js.map +1 -1
- package/dist/gltf/lib/extensions/MSFT_texture_dds.cjs +64 -0
- package/dist/gltf/lib/extensions/MSFT_texture_dds.cjs.map +7 -0
- package/dist/gltf/lib/extensions/MSFT_texture_dds.d.ts +12 -0
- package/dist/gltf/lib/extensions/MSFT_texture_dds.d.ts.map +1 -0
- package/dist/gltf/lib/extensions/MSFT_texture_dds.js +39 -0
- package/dist/gltf/lib/extensions/MSFT_texture_dds.js.map +1 -0
- package/dist/gltf/lib/extensions/utils/3d-tiles-utils.cjs +1 -1
- package/dist/gltf/lib/extensions/utils/3d-tiles-utils.cjs.map +2 -2
- package/dist/gltf/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -1
- package/dist/gltf/lib/extensions/utils/3d-tiles-utils.js +3 -1
- package/dist/gltf/lib/extensions/utils/3d-tiles-utils.js.map +1 -1
- package/dist/gltf/lib/parsers/parse-gltf.cjs +25 -0
- package/dist/gltf/lib/parsers/parse-gltf.cjs.map +2 -2
- package/dist/gltf/lib/parsers/parse-gltf.d.ts +2 -0
- package/dist/gltf/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/gltf/lib/parsers/parse-gltf.js +18 -0
- package/dist/gltf/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/gltf/lib/types/gltf-additional-extension-schemas.cjs +22 -0
- package/dist/gltf/lib/types/gltf-additional-extension-schemas.cjs.map +2 -2
- package/dist/gltf/lib/types/gltf-additional-extension-schemas.d.ts +23 -0
- package/dist/gltf/lib/types/gltf-additional-extension-schemas.d.ts.map +1 -1
- package/dist/gltf/lib/types/gltf-additional-extension-schemas.js +22 -0
- package/dist/gltf/lib/types/gltf-additional-extension-schemas.js.map +1 -1
- package/dist/gltf/lib/types/gltf-ext-gaussian-splatting-schema.cjs.map +1 -1
- package/dist/gltf/lib/types/gltf-ext-gaussian-splatting-schema.d.ts +1 -1
- package/dist/gltf/lib/types/gltf-ext-gaussian-splatting-schema.d.ts.map +1 -1
- package/dist/gltf/lib/types/gltf-extension-schemas.cjs +8 -0
- package/dist/gltf/lib/types/gltf-extension-schemas.cjs.map +2 -2
- package/dist/gltf/lib/types/gltf-extension-schemas.d.ts +27 -0
- package/dist/gltf/lib/types/gltf-extension-schemas.d.ts.map +1 -1
- package/dist/gltf/lib/types/gltf-extension-schemas.js +8 -1
- package/dist/gltf/lib/types/gltf-extension-schemas.js.map +1 -1
- package/dist/gltf/lib/types/gltf-json-schema.cjs.map +1 -1
- package/dist/gltf/lib/types/gltf-json-schema.d.ts +2 -2
- package/dist/gltf/lib/types/gltf-json-schema.d.ts.map +1 -1
- package/dist/gltf/lib/types/gltf-texture-procedurals.cjs +19 -0
- package/dist/gltf/lib/types/gltf-texture-procedurals.cjs.map +7 -0
- package/dist/gltf/lib/types/gltf-texture-procedurals.d.ts +45 -0
- package/dist/gltf/lib/types/gltf-texture-procedurals.d.ts.map +1 -0
- package/dist/gltf/lib/types/gltf-texture-procedurals.js +5 -0
- package/dist/gltf/lib/types/gltf-texture-procedurals.js.map +1 -0
- package/dist/gltf/lib/types/gltf-types.cjs.map +1 -1
- package/dist/gltf/lib/types/gltf-types.d.ts +7 -0
- package/dist/gltf/lib/types/gltf-types.d.ts.map +1 -1
- package/dist/gltf/lib/types/gltf-version-zod-schemas.d.ts +34 -0
- package/dist/gltf/lib/types/gltf-version-zod-schemas.d.ts.map +1 -1
- package/dist/gltf/lib/types/gltf-zod-schema.cjs +4 -1
- package/dist/gltf/lib/types/gltf-zod-schema.cjs.map +2 -2
- package/dist/gltf/lib/types/gltf-zod-schema.d.ts +56 -0
- package/dist/gltf/lib/types/gltf-zod-schema.d.ts.map +1 -1
- package/dist/gltf/lib/types/gltf-zod-schema.js +6 -2
- package/dist/gltf/lib/types/gltf-zod-schema.js.map +1 -1
- package/dist/gltf/lib/utils/version.cjs +1 -1
- package/dist/gltf/lib/utils/version.js +1 -1
- package/dist/gltf/schema.cjs +3 -0
- package/dist/gltf/schema.cjs.map +2 -2
- package/dist/gltf/schema.d.ts +1 -0
- package/dist/gltf/schema.d.ts.map +1 -1
- package/dist/gltf/schema.js +1 -0
- package/dist/gltf/schema.js.map +1 -1
- package/dist/gltf-loader-types.cjs.map +2 -2
- package/dist/index.cjs +7 -1
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/materialx/parse-materialx.cjs +61 -0
- package/dist/materialx/parse-materialx.cjs.map +7 -0
- package/dist/materialx/parse-materialx.d.ts +23 -0
- package/dist/materialx/parse-materialx.d.ts.map +1 -0
- package/dist/materialx/parse-materialx.js +39 -0
- package/dist/materialx/parse-materialx.js.map +1 -0
- package/dist/materialx/procedural-graph.cjs +77 -0
- package/dist/materialx/procedural-graph.cjs.map +7 -0
- package/dist/materialx/procedural-graph.d.ts +40 -0
- package/dist/materialx/procedural-graph.d.ts.map +1 -0
- package/dist/materialx/procedural-graph.js +59 -0
- package/dist/materialx/procedural-graph.js.map +1 -0
- package/dist/materialx-loader-types.cjs +57 -0
- package/dist/materialx-loader-types.cjs.map +7 -0
- package/dist/materialx-loader-types.d.ts +34 -0
- package/dist/materialx-loader-types.d.ts.map +1 -0
- package/dist/materialx-loader-types.js +20 -0
- package/dist/materialx-loader-types.js.map +1 -0
- package/dist/materialx-loader.cjs +40 -0
- package/dist/materialx-loader.cjs.map +7 -0
- package/dist/materialx-loader.d.ts +19 -0
- package/dist/materialx-loader.d.ts.map +1 -0
- package/dist/materialx-loader.js +14 -0
- package/dist/materialx-loader.js.map +1 -0
- package/dist/mtl-loader-types.cjs +1 -1
- package/dist/obj/mtl-loader-types.cjs +1 -1
- package/dist/obj/mtl-loader-types.js +1 -1
- package/dist/obj/obj-loader-types.cjs +3 -3
- package/dist/obj/obj-loader-types.cjs.map +2 -2
- package/dist/obj/obj-loader-types.d.ts +1 -1
- package/dist/obj/obj-loader-types.d.ts.map +1 -1
- package/dist/obj/obj-loader-types.js +2 -2
- package/dist/obj/obj-loader-types.js.map +1 -1
- package/dist/obj/obj-loader.cjs +5 -5
- package/dist/obj/obj-loader.cjs.map +2 -2
- package/dist/obj/obj-loader.d.ts +1 -1
- package/dist/obj/obj-loader.d.ts.map +1 -1
- package/dist/obj/obj-loader.js +1 -1
- package/dist/obj/obj-loader.js.map +1 -1
- package/dist/obj/obj-writer.cjs +1 -1
- package/dist/obj/obj-writer.js +1 -1
- package/dist/obj-loader-types.cjs +3 -3
- package/dist/obj-loader-types.cjs.map +2 -2
- package/dist/obj-loader.cjs +5 -5
- package/dist/obj-loader.cjs.map +2 -2
- package/dist/obj-worker.js +985 -368
- package/dist/obj-writer.cjs +1 -1
- package/dist/stl/parse-stl.cjs +100 -0
- package/dist/stl/parse-stl.cjs.map +7 -0
- package/dist/stl/parse-stl.d.ts +4 -0
- package/dist/stl/parse-stl.d.ts.map +1 -0
- package/dist/stl/parse-stl.js +84 -0
- package/dist/stl/parse-stl.js.map +1 -0
- package/dist/stl-loader-types.cjs +58 -0
- package/dist/stl-loader-types.cjs.map +7 -0
- package/dist/stl-loader-types.d.ts +32 -0
- package/dist/stl-loader-types.d.ts.map +1 -0
- package/dist/stl-loader-types.js +25 -0
- package/dist/stl-loader-types.js.map +1 -0
- package/dist/stl-loader.cjs +38 -0
- package/dist/stl-loader.cjs.map +7 -0
- package/dist/stl-loader.d.ts +17 -0
- package/dist/stl-loader.d.ts.map +1 -0
- package/dist/stl-loader.js +13 -0
- package/dist/stl-loader.js.map +1 -0
- package/dist/usd/index.cjs.map +1 -1
- package/dist/usd/index.d.ts +1 -1
- package/dist/usd/index.d.ts.map +1 -1
- package/dist/usd/lib/parse-usd.cjs +42 -5
- package/dist/usd/lib/parse-usd.cjs.map +2 -2
- package/dist/usd/lib/parse-usd.d.ts.map +1 -1
- package/dist/usd/lib/parse-usd.js +53 -6
- package/dist/usd/lib/parse-usd.js.map +1 -1
- package/dist/usd/lib/parse-usdc.cjs +187 -0
- package/dist/usd/lib/parse-usdc.cjs.map +7 -0
- package/dist/usd/lib/parse-usdc.d.ts +4 -0
- package/dist/usd/lib/parse-usdc.d.ts.map +1 -0
- package/dist/usd/lib/parse-usdc.js +176 -0
- package/dist/usd/lib/parse-usdc.js.map +1 -0
- package/dist/usd/lib/parse-usdz.cjs +22 -0
- package/dist/usd/lib/parse-usdz.cjs.map +2 -2
- package/dist/usd/lib/parse-usdz.d.ts.map +1 -1
- package/dist/usd/lib/parse-usdz.js +26 -0
- package/dist/usd/lib/parse-usdz.js.map +1 -1
- package/dist/usd/lib/usd-types.cjs.map +1 -1
- package/dist/usd/lib/usd-types.d.ts +14 -1
- package/dist/usd/lib/usd-types.d.ts.map +1 -1
- package/dist/usd/lib/usd-types.js +1 -1
- package/dist/usd/lib/usd-types.js.map +1 -1
- package/dist/usd/libs/README.md +27 -0
- package/dist/usd/libs/THREE-LICENSE +21 -0
- package/dist/usd/libs/usdc-parser.d.ts +78 -0
- package/dist/usd/libs/usdc-parser.d.ts.map +1 -0
- package/dist/usd/libs/usdc-parser.js +1669 -0
- package/dist/usd/libs/usdc-parser.js.map +1 -0
- package/dist/usd/usd-loader-types.cjs +4 -4
- package/dist/usd/usd-loader-types.cjs.map +2 -2
- package/dist/usd/usd-loader-types.d.ts +7 -7
- package/dist/usd/usd-loader-types.d.ts.map +1 -1
- package/dist/usd/usd-loader-types.js +6 -6
- package/dist/usd/usd-loader-types.js.map +1 -1
- package/dist/usd/usd-loader.cjs.map +1 -1
- package/dist/usd/usd-loader.d.ts +4 -4
- package/dist/usd/usd-loader.d.ts.map +1 -1
- package/dist/usd/usd-loader.js +2 -2
- package/dist/usd/usd-loader.js.map +1 -1
- package/dist/usd-loader-types.cjs +4 -4
- package/dist/usd-loader-types.cjs.map +2 -2
- package/dist/usd-loader.cjs.map +1 -1
- package/package.json +19 -7
- package/src/draco/draco-loader-types.ts +1 -1
- package/src/gltf/gltf-loader-types.ts +6 -0
- package/src/gltf/index.ts +4 -1
- package/src/gltf/lib/api/gltf-extensions.ts +7 -2
- package/src/gltf/lib/extensions/EXT_texture_webp.ts +3 -0
- package/src/gltf/lib/extensions/KHR_accessor_float64.ts +22 -0
- package/src/gltf/lib/extensions/KHR_gaussian_splatting.ts +31 -7
- package/src/gltf/lib/extensions/MSFT_texture_dds.ts +52 -0
- package/src/gltf/lib/extensions/utils/3d-tiles-utils.ts +5 -1
- package/src/gltf/lib/parsers/parse-gltf.ts +31 -0
- package/src/gltf/lib/types/gltf-additional-extension-schemas.ts +32 -0
- package/src/gltf/lib/types/gltf-ext-gaussian-splatting-schema.ts +1 -1
- package/src/gltf/lib/types/gltf-extension-schemas.ts +12 -0
- package/src/gltf/lib/types/gltf-json-schema.ts +2 -1
- package/src/gltf/lib/types/gltf-texture-procedurals.ts +67 -0
- package/src/gltf/lib/types/gltf-types.ts +8 -0
- package/src/gltf/lib/types/gltf-zod-schema.ts +7 -1
- package/src/gltf/schema.ts +1 -0
- package/src/index.ts +6 -1
- package/src/materialx/README.md +5 -0
- package/src/materialx/parse-materialx.ts +70 -0
- package/src/materialx/procedural-graph.ts +94 -0
- package/src/materialx-loader-types.ts +24 -0
- package/src/materialx-loader.ts +15 -0
- package/src/obj/obj-loader-types.ts +1 -1
- package/src/obj/obj-loader.ts +1 -1
- package/src/stl/parse-stl.ts +90 -0
- package/src/stl-loader-types.ts +28 -0
- package/src/stl-loader.ts +12 -0
- package/src/usd/index.ts +1 -0
- package/src/usd/lib/parse-usd.ts +68 -7
- package/src/usd/lib/parse-usdc.ts +188 -0
- package/src/usd/lib/parse-usdz.ts +28 -0
- package/src/usd/lib/usd-types.ts +16 -2
- package/src/usd/libs/README.md +27 -0
- package/src/usd/libs/THREE-LICENSE +21 -0
- package/src/usd/libs/usdc-parser.d.ts +18 -0
- package/src/usd/libs/usdc-parser.js +1669 -0
- package/src/usd/usd-loader-types.ts +5 -5
- package/src/usd/usd-loader.ts +2 -2
|
@@ -7580,6 +7580,48 @@ var init_dist = __esm({
|
|
|
7580
7580
|
}
|
|
7581
7581
|
});
|
|
7582
7582
|
|
|
7583
|
+
// ../core/src/worker-utils/lib/node/worker_threads.ts
|
|
7584
|
+
var worker_threads_exports = {};
|
|
7585
|
+
__export(worker_threads_exports, {
|
|
7586
|
+
BroadcastChannel: () => import_worker_threads4.BroadcastChannel,
|
|
7587
|
+
MessageChannel: () => import_worker_threads4.MessageChannel,
|
|
7588
|
+
MessagePort: () => import_worker_threads4.MessagePort,
|
|
7589
|
+
NodeWorker: () => NodeWorker2,
|
|
7590
|
+
SHARE_ENV: () => import_worker_threads4.SHARE_ENV,
|
|
7591
|
+
Worker: () => import_worker_threads4.Worker,
|
|
7592
|
+
getEnvironmentData: () => import_worker_threads4.getEnvironmentData,
|
|
7593
|
+
isInternalThread: () => isInternalThread2,
|
|
7594
|
+
isMainThread: () => import_worker_threads4.isMainThread,
|
|
7595
|
+
isMarkedAsUntransferable: () => import_worker_threads4.isMarkedAsUntransferable,
|
|
7596
|
+
locks: () => locks2,
|
|
7597
|
+
markAsUncloneable: () => import_worker_threads4.markAsUncloneable,
|
|
7598
|
+
markAsUntransferable: () => import_worker_threads4.markAsUntransferable,
|
|
7599
|
+
moveMessagePortToContext: () => import_worker_threads4.moveMessagePortToContext,
|
|
7600
|
+
parentPort: () => parentPort2,
|
|
7601
|
+
postMessageToThread: () => import_worker_threads4.postMessageToThread,
|
|
7602
|
+
receiveMessageOnPort: () => import_worker_threads4.receiveMessageOnPort,
|
|
7603
|
+
resourceLimits: () => import_worker_threads4.resourceLimits,
|
|
7604
|
+
setEnvironmentData: () => import_worker_threads4.setEnvironmentData,
|
|
7605
|
+
structuredClone: () => structuredClone3,
|
|
7606
|
+
threadId: () => import_worker_threads4.threadId,
|
|
7607
|
+
threadName: () => threadName2,
|
|
7608
|
+
workerData: () => import_worker_threads4.workerData
|
|
7609
|
+
});
|
|
7610
|
+
var WorkerThreads, import_worker_threads4, parentPort2, NodeWorker2, isInternalThread2, threadName2, locks2, structuredClone3;
|
|
7611
|
+
var init_worker_threads = __esm({
|
|
7612
|
+
"../core/src/worker-utils/lib/node/worker_threads.ts"() {
|
|
7613
|
+
"use strict";
|
|
7614
|
+
WorkerThreads = __toESM(require("worker_threads"), 1);
|
|
7615
|
+
import_worker_threads4 = require("worker_threads");
|
|
7616
|
+
parentPort2 = WorkerThreads == null ? void 0 : WorkerThreads.parentPort;
|
|
7617
|
+
NodeWorker2 = WorkerThreads.Worker;
|
|
7618
|
+
isInternalThread2 = WorkerThreads.isInternalThread;
|
|
7619
|
+
threadName2 = WorkerThreads.threadName;
|
|
7620
|
+
locks2 = WorkerThreads.locks;
|
|
7621
|
+
structuredClone3 = WorkerThreads.structuredClone;
|
|
7622
|
+
}
|
|
7623
|
+
});
|
|
7624
|
+
|
|
7583
7625
|
// ../../node_modules/flatbuffers/js/constants.js
|
|
7584
7626
|
var require_constants2 = __commonJS({
|
|
7585
7627
|
"../../node_modules/flatbuffers/js/constants.js"(exports2) {
|
|
@@ -10594,9 +10636,15 @@ globalThis.loaders.readFileAsText = readFileAsText;
|
|
|
10594
10636
|
globalThis.loaders.requireFromFile = requireFromFile;
|
|
10595
10637
|
globalThis.loaders.requireFromString = requireFromString;
|
|
10596
10638
|
|
|
10639
|
+
// ../core/src/constants/index.ts
|
|
10640
|
+
var LOADERS_GL_FIXTURE_BRANCH = "master";
|
|
10641
|
+
var LOADERS_GL_RAW_FIXTURE_URL = `https://raw.githubusercontent.com/visgl/loaders.gl/${LOADERS_GL_FIXTURE_BRANCH}/`;
|
|
10642
|
+
var LOADERS_GL_REDIRECTING_FIXTURE_URL = `https://github.com/visgl/loaders.gl/raw/${LOADERS_GL_FIXTURE_BRANCH}/`;
|
|
10643
|
+
var NPM_TAG = "beta";
|
|
10644
|
+
|
|
10597
10645
|
// ../core/src/worker-utils/lib/env-utils/version.ts
|
|
10598
10646
|
function getVersion() {
|
|
10599
|
-
const version2 = false ? NPM_TAG : "5.0.0-beta.
|
|
10647
|
+
const version2 = false ? NPM_TAG : "5.0.0-beta.5";
|
|
10600
10648
|
globalThis._loadersgl_ = globalThis._loadersgl_ || {};
|
|
10601
10649
|
globalThis._loadersgl_.version ||= version2;
|
|
10602
10650
|
return version2;
|
|
@@ -10630,23 +10678,23 @@ var isMobile = typeof window !== "undefined" && typeof window.orientation !== "u
|
|
|
10630
10678
|
var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
10631
10679
|
var nodeVersion2 = matches && parseFloat(matches[1]) || 0;
|
|
10632
10680
|
|
|
10633
|
-
// ../../node_modules/@math.gl/
|
|
10634
|
-
var
|
|
10681
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/npm-tag.js
|
|
10682
|
+
var NPM_TAG2 = "latest";
|
|
10635
10683
|
|
|
10636
|
-
// ../../node_modules/@math.gl/
|
|
10684
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/env-utils/version.js
|
|
10637
10685
|
function getVersion2() {
|
|
10638
|
-
return false ?
|
|
10686
|
+
return false ? NPM_TAG2 : "5.0.0-beta.5";
|
|
10639
10687
|
}
|
|
10640
10688
|
var VERSION2 = getVersion2();
|
|
10641
10689
|
|
|
10642
|
-
// ../../node_modules/@math.gl/
|
|
10690
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/env-utils/assert.js
|
|
10643
10691
|
function assert2(condition, message) {
|
|
10644
10692
|
if (!condition) {
|
|
10645
10693
|
throw new Error(message || "loaders.gl assertion failed.");
|
|
10646
10694
|
}
|
|
10647
10695
|
}
|
|
10648
10696
|
|
|
10649
|
-
// ../../node_modules/@math.gl/
|
|
10697
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/env-utils/globals.js
|
|
10650
10698
|
var globals2 = {
|
|
10651
10699
|
self: typeof self !== "undefined" && self,
|
|
10652
10700
|
window: typeof window !== "undefined" && window,
|
|
@@ -10665,7 +10713,7 @@ var isMobile2 = typeof window !== "undefined" && typeof window.orientation !== "
|
|
|
10665
10713
|
var matches2 = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
10666
10714
|
var nodeVersion3 = matches2 && parseFloat(matches2[1]) || 0;
|
|
10667
10715
|
|
|
10668
|
-
// ../../node_modules/@math.gl/
|
|
10716
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-job.js
|
|
10669
10717
|
var WorkerJob = class {
|
|
10670
10718
|
constructor(jobName, workerThread) {
|
|
10671
10719
|
this.isRunning = true;
|
|
@@ -10785,17 +10833,27 @@ function createAbortError(message) {
|
|
|
10785
10833
|
return error;
|
|
10786
10834
|
}
|
|
10787
10835
|
|
|
10788
|
-
// ../../node_modules/@math.gl/
|
|
10836
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/node/worker_threads.js
|
|
10789
10837
|
var import_worker_threads = require("worker_threads");
|
|
10790
10838
|
var parentPort = import_worker_threads.parentPort;
|
|
10791
10839
|
var NodeWorker = import_worker_threads.Worker;
|
|
10792
10840
|
|
|
10793
|
-
// ../../node_modules/@math.gl/
|
|
10841
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-utils/get-loadable-worker-url.js
|
|
10794
10842
|
var workerURLCache = /* @__PURE__ */ new Map();
|
|
10795
10843
|
function getLoadableWorkerURL(props) {
|
|
10844
|
+
var _a5, _b2, _c2;
|
|
10796
10845
|
assert2(props.source && !props.url || !props.source && props.url);
|
|
10797
|
-
if (props.url && props.workerType === "module")
|
|
10846
|
+
if (props.url && props.workerType === "module") {
|
|
10847
|
+
const baseUrl = ((_a5 = globalThis.document) == null ? void 0 : _a5.baseURI) ?? ((_b2 = globalThis.location) == null ? void 0 : _b2.href);
|
|
10848
|
+
if (!baseUrl)
|
|
10849
|
+
return props.url;
|
|
10850
|
+
const resolved = new URL(props.url, baseUrl);
|
|
10851
|
+
const origin = (_c2 = globalThis.location) == null ? void 0 : _c2.origin;
|
|
10852
|
+
if (/^https?:$/.test(resolved.protocol) && resolved.origin !== origin) {
|
|
10853
|
+
return getLoadableWorkerURLFromSource(`import ${JSON.stringify(resolved.href)};`);
|
|
10854
|
+
}
|
|
10798
10855
|
return props.url;
|
|
10856
|
+
}
|
|
10799
10857
|
let workerURL = workerURLCache.get(props.source || props.url);
|
|
10800
10858
|
if (!workerURL) {
|
|
10801
10859
|
if (props.url) {
|
|
@@ -10830,7 +10888,7 @@ function buildScriptSource(workerUrl) {
|
|
|
10830
10888
|
}`;
|
|
10831
10889
|
}
|
|
10832
10890
|
|
|
10833
|
-
// ../../node_modules/@math.gl/
|
|
10891
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-utils/get-transfer-list.js
|
|
10834
10892
|
function getTransferList(object2, recursive = true, transfers) {
|
|
10835
10893
|
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
10836
10894
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -10843,6 +10901,9 @@ function getTransferList(object2, recursive = true, transfers) {
|
|
|
10843
10901
|
else if (ArrayBuffer.isView(value)) {
|
|
10844
10902
|
if (isTransferable(value.buffer))
|
|
10845
10903
|
transfersSet.add(value.buffer);
|
|
10904
|
+
} else if (recursive && typeof MessageChannel !== "undefined" && value instanceof MessageChannel) {
|
|
10905
|
+
visit(value.port1);
|
|
10906
|
+
visit(value.port2);
|
|
10846
10907
|
} else if (recursive && value instanceof Map) {
|
|
10847
10908
|
for (const [key, item] of value) {
|
|
10848
10909
|
visit(key);
|
|
@@ -10911,7 +10972,7 @@ function getTransferListForWriter(object2) {
|
|
|
10911
10972
|
return object2 === null ? {} : clone2(object2);
|
|
10912
10973
|
}
|
|
10913
10974
|
|
|
10914
|
-
// ../../node_modules/@math.gl/
|
|
10975
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-thread.js
|
|
10915
10976
|
var NOOP = () => {
|
|
10916
10977
|
};
|
|
10917
10978
|
var WorkerThread = class {
|
|
@@ -10947,7 +11008,7 @@ var WorkerThread = class {
|
|
|
10947
11008
|
if (this.terminated)
|
|
10948
11009
|
return this.termination ?? Promise.resolve();
|
|
10949
11010
|
this.terminated = true;
|
|
10950
|
-
this.termination = Promise.resolve(this.worker.terminate()).then(() => void 0);
|
|
11011
|
+
this.termination = Promise.resolve(this.worker.terminate()).then(() => void 0).finally(() => this.releaseModuleWorkerURL());
|
|
10951
11012
|
void this.termination.catch(() => void 0);
|
|
10952
11013
|
return this.termination;
|
|
10953
11014
|
}
|
|
@@ -10998,9 +11059,9 @@ var WorkerThread = class {
|
|
|
10998
11059
|
var _a5;
|
|
10999
11060
|
if (this.loadWorker) {
|
|
11000
11061
|
try {
|
|
11001
|
-
const
|
|
11002
|
-
if (
|
|
11003
|
-
return this._initializeBrowserWorker(
|
|
11062
|
+
const worker = this.loadWorker();
|
|
11063
|
+
if (worker) {
|
|
11064
|
+
return this._initializeBrowserWorker(worker);
|
|
11004
11065
|
}
|
|
11005
11066
|
} catch (error) {
|
|
11006
11067
|
if (!this.source && !this.url && !this.getUrl) {
|
|
@@ -11014,8 +11075,22 @@ var WorkerThread = class {
|
|
|
11014
11075
|
url,
|
|
11015
11076
|
workerType: this.workerType
|
|
11016
11077
|
});
|
|
11017
|
-
|
|
11018
|
-
|
|
11078
|
+
if (this.workerType === "module" && url && this._loadableURL !== url && this._loadableURL.startsWith("blob:"))
|
|
11079
|
+
this.ownedModuleWorkerURL = this._loadableURL;
|
|
11080
|
+
try {
|
|
11081
|
+
const worker = new Worker(this._loadableURL, { name: this.name, type: this.workerType });
|
|
11082
|
+
return this._initializeBrowserWorker(worker);
|
|
11083
|
+
} catch (error) {
|
|
11084
|
+
this.releaseModuleWorkerURL();
|
|
11085
|
+
throw error;
|
|
11086
|
+
}
|
|
11087
|
+
}
|
|
11088
|
+
/** Releases only the module shim owned by this worker, never caller-owned blob URLs. */
|
|
11089
|
+
releaseModuleWorkerURL() {
|
|
11090
|
+
if (this.ownedModuleWorkerURL) {
|
|
11091
|
+
URL.revokeObjectURL(this.ownedModuleWorkerURL);
|
|
11092
|
+
this.ownedModuleWorkerURL = void 0;
|
|
11093
|
+
}
|
|
11019
11094
|
}
|
|
11020
11095
|
/** Attaches protocol handlers to a browser worker. */
|
|
11021
11096
|
_initializeBrowserWorker(worker) {
|
|
@@ -11079,7 +11154,7 @@ var WorkerThread = class {
|
|
|
11079
11154
|
}
|
|
11080
11155
|
};
|
|
11081
11156
|
|
|
11082
|
-
// ../../node_modules/@math.gl/
|
|
11157
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-pool.js
|
|
11083
11158
|
var WorkerPool = class {
|
|
11084
11159
|
/** Snapshot; byte figures describe input buffers, not total heap memory. */
|
|
11085
11160
|
get stats() {
|
|
@@ -11609,7 +11684,7 @@ var WorkerPool = class {
|
|
|
11609
11684
|
}
|
|
11610
11685
|
};
|
|
11611
11686
|
|
|
11612
|
-
// ../../node_modules/@math.gl/
|
|
11687
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-farm.js
|
|
11613
11688
|
var DEFAULT_PROPS = {
|
|
11614
11689
|
maxQueuedJobs: Infinity,
|
|
11615
11690
|
maxPendingAdmissions: 128,
|
|
@@ -11730,7 +11805,7 @@ function getLoadWorkerId(loadWorker) {
|
|
|
11730
11805
|
return loadWorkerId;
|
|
11731
11806
|
}
|
|
11732
11807
|
|
|
11733
|
-
// ../../node_modules/@math.gl/
|
|
11808
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-body.js
|
|
11734
11809
|
async function getParentPort() {
|
|
11735
11810
|
return parentPort;
|
|
11736
11811
|
}
|
|
@@ -11746,16 +11821,16 @@ var WorkerBody = class {
|
|
|
11746
11821
|
*/
|
|
11747
11822
|
static set onmessage(onMessage2) {
|
|
11748
11823
|
async function handleMessage(message) {
|
|
11749
|
-
const
|
|
11750
|
-
const { type, payload } =
|
|
11824
|
+
const parentPort3 = await getParentPort();
|
|
11825
|
+
const { type, payload } = parentPort3 ? message : message.data;
|
|
11751
11826
|
onMessage2(type, payload);
|
|
11752
11827
|
}
|
|
11753
|
-
getParentPort().then((
|
|
11754
|
-
if (
|
|
11755
|
-
|
|
11828
|
+
getParentPort().then((parentPort3) => {
|
|
11829
|
+
if (parentPort3) {
|
|
11830
|
+
parentPort3.on("message", (message) => {
|
|
11756
11831
|
handleMessage(message);
|
|
11757
11832
|
});
|
|
11758
|
-
|
|
11833
|
+
parentPort3.on("exit", () => console.debug("Node worker closing"));
|
|
11759
11834
|
} else {
|
|
11760
11835
|
globalThis.onmessage = handleMessage;
|
|
11761
11836
|
}
|
|
@@ -11773,9 +11848,9 @@ var WorkerBody = class {
|
|
|
11773
11848
|
};
|
|
11774
11849
|
onMessageWrapperMap.set(onMessage2, onMessageWrapper);
|
|
11775
11850
|
}
|
|
11776
|
-
const
|
|
11777
|
-
if (
|
|
11778
|
-
|
|
11851
|
+
const parentPort3 = await getParentPort();
|
|
11852
|
+
if (parentPort3) {
|
|
11853
|
+
parentPort3.on("message", onMessageWrapper);
|
|
11779
11854
|
} else {
|
|
11780
11855
|
globalThis.addEventListener("message", onMessageWrapper);
|
|
11781
11856
|
}
|
|
@@ -11786,9 +11861,9 @@ var WorkerBody = class {
|
|
|
11786
11861
|
if (!onMessageWrapper) {
|
|
11787
11862
|
return;
|
|
11788
11863
|
}
|
|
11789
|
-
const
|
|
11790
|
-
if (
|
|
11791
|
-
|
|
11864
|
+
const parentPort3 = await getParentPort();
|
|
11865
|
+
if (parentPort3) {
|
|
11866
|
+
parentPort3.off("message", onMessageWrapper);
|
|
11792
11867
|
} else {
|
|
11793
11868
|
globalThis.removeEventListener("message", onMessageWrapper);
|
|
11794
11869
|
}
|
|
@@ -11798,12 +11873,12 @@ var WorkerBody = class {
|
|
|
11798
11873
|
* @param type
|
|
11799
11874
|
* @param payload
|
|
11800
11875
|
*/
|
|
11801
|
-
static async postMessage(type, payload) {
|
|
11876
|
+
static async postMessage(type, payload, copy = false) {
|
|
11802
11877
|
const data = { source: "loaders.gl", type, payload };
|
|
11803
|
-
const transferList = getTransferList(payload);
|
|
11804
|
-
const
|
|
11805
|
-
if (
|
|
11806
|
-
|
|
11878
|
+
const transferList = copy ? [] : getTransferList(payload);
|
|
11879
|
+
const parentPort3 = await getParentPort();
|
|
11880
|
+
if (parentPort3) {
|
|
11881
|
+
parentPort3.postMessage(data, transferList);
|
|
11807
11882
|
} else {
|
|
11808
11883
|
globalThis.postMessage(data, transferList);
|
|
11809
11884
|
}
|
|
@@ -11817,7 +11892,7 @@ function getWorkerMessageData(message) {
|
|
|
11817
11892
|
return messageData && typeof messageData.source === "string" && messageData.source.startsWith("loaders.gl") ? messageData : null;
|
|
11818
11893
|
}
|
|
11819
11894
|
|
|
11820
|
-
// ../../node_modules/@math.gl/
|
|
11895
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/async-queue/async-queue.js
|
|
11821
11896
|
var AsyncQueue = class {
|
|
11822
11897
|
constructor() {
|
|
11823
11898
|
this._values = [];
|
|
@@ -11884,7 +11959,7 @@ var AsyncQueue = class {
|
|
|
11884
11959
|
}
|
|
11885
11960
|
};
|
|
11886
11961
|
|
|
11887
|
-
// ../../node_modules/@math.gl/
|
|
11962
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/get-worker-url.js
|
|
11888
11963
|
var warnedWorkerVersionFallbacks = /* @__PURE__ */ new Set();
|
|
11889
11964
|
function getWorkerName(worker) {
|
|
11890
11965
|
const warning = worker.version !== VERSION2 ? ` (worker-utils@${VERSION2})` : "";
|
|
@@ -11899,7 +11974,7 @@ function getCustomWorkerURL(worker, options = {}) {
|
|
|
11899
11974
|
if (isBrowser3) {
|
|
11900
11975
|
url = `modules/${worker.module}/dist/${workerFile}`;
|
|
11901
11976
|
} else {
|
|
11902
|
-
const workerSourceDirectory = worker.module === "
|
|
11977
|
+
const workerSourceDirectory = worker.module === "tasks" && ((_b2 = worker.workerNode) == null ? void 0 : _b2.startsWith("worker-utils/")) ? "worker-utils/workers" : "workers";
|
|
11903
11978
|
const workerSourceNode = worker.workerSourceNode || `${workerSourceDirectory}/${worker.id}-worker-node.ts`;
|
|
11904
11979
|
url = `modules/${worker.module}/src/${workerSourceNode}`;
|
|
11905
11980
|
}
|
|
@@ -11921,7 +11996,7 @@ function getDefaultWorkerURL(worker, warn = false) {
|
|
|
11921
11996
|
const workerFile = isBrowser3 ? worker.workerFile || `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
|
|
11922
11997
|
let version2 = worker.version;
|
|
11923
11998
|
if (version2 === "latest") {
|
|
11924
|
-
version2 =
|
|
11999
|
+
version2 = NPM_TAG2;
|
|
11925
12000
|
}
|
|
11926
12001
|
const versionTag = version2 ? `@${version2}` : "";
|
|
11927
12002
|
const packageName = worker.packageName || `@loaders.gl/${worker.module}`;
|
|
@@ -11943,7 +12018,7 @@ function warnIfUsingNpmTagFallback(worker, url) {
|
|
|
11943
12018
|
console.warn(`loaders.gl: ${worker.name} loader worker version is "latest" because __VERSION__ was not injected. Fetching ${url} from CDN.`);
|
|
11944
12019
|
}
|
|
11945
12020
|
|
|
11946
|
-
// ../../node_modules/@math.gl/
|
|
12021
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/shared-state.js
|
|
11947
12022
|
function getWorkerCapabilities() {
|
|
11948
12023
|
const isolated = typeof globalThis.crossOriginIsolated === "boolean" ? globalThis.crossOriginIsolated : void 0;
|
|
11949
12024
|
const capabilities = {
|
|
@@ -12026,7 +12101,7 @@ function prepareSharedState(options) {
|
|
|
12026
12101
|
return options;
|
|
12027
12102
|
}
|
|
12028
12103
|
|
|
12029
|
-
// ../../node_modules/@math.gl/
|
|
12104
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-utils/get-input-byte-length.js
|
|
12030
12105
|
function getInputByteLength(input) {
|
|
12031
12106
|
const seen = /* @__PURE__ */ new Set();
|
|
12032
12107
|
let bytes = 0;
|
|
@@ -12055,8 +12130,63 @@ function getInputByteLength(input) {
|
|
|
12055
12130
|
return bytes;
|
|
12056
12131
|
}
|
|
12057
12132
|
|
|
12058
|
-
// ../../node_modules/@math.gl/
|
|
12133
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/validate-output-ownership.js
|
|
12134
|
+
function validateOutputOwnership(ownership) {
|
|
12135
|
+
if (ownership !== void 0 && ownership !== "copy" && ownership !== "transfer") {
|
|
12136
|
+
throw new Error("Invalid worker output ownership");
|
|
12137
|
+
}
|
|
12138
|
+
}
|
|
12139
|
+
|
|
12140
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/process-on-worker.js
|
|
12141
|
+
async function processOnWorker(worker, data, options = {}, context = {}, jobContext = {}) {
|
|
12142
|
+
var _a5;
|
|
12143
|
+
validateOutputOwnership(options.outputOwnership);
|
|
12144
|
+
if (options.inputOwnership !== void 0 && !["copy", "transfer", "share"].includes(options.inputOwnership))
|
|
12145
|
+
throw new Error("Invalid worker input ownership");
|
|
12146
|
+
options = prepareSharedState(options);
|
|
12147
|
+
throwIfAborted(options.signal);
|
|
12148
|
+
validateSharedInput(options, [data, serializableOptions(options), jobContext]);
|
|
12149
|
+
const name = getWorkerName(worker);
|
|
12150
|
+
const workerPool = options.workerPool ?? WorkerFarm.getWorkerFarm(options).getWorkerPool(getWorkerPoolTarget(worker, options, name));
|
|
12151
|
+
const jobName = options.jobName || worker.name;
|
|
12152
|
+
const job = await workerPool.startJob(
|
|
12153
|
+
jobName,
|
|
12154
|
+
// eslint-disable-next-line
|
|
12155
|
+
onMessage.bind(null, context, options),
|
|
12156
|
+
void 0,
|
|
12157
|
+
options.signal,
|
|
12158
|
+
{
|
|
12159
|
+
inputBytes: getInputByteLength([data, budgetOptions(options), jobContext]),
|
|
12160
|
+
priority: options.priority,
|
|
12161
|
+
admission: options.admission,
|
|
12162
|
+
sharedState: options.sharedState ? new SharedWorkerState(options.sharedState) : void 0,
|
|
12163
|
+
cancellationMode: options.cancellationMode,
|
|
12164
|
+
cancellationTimeout: options.cancellationTimeout
|
|
12165
|
+
}
|
|
12166
|
+
);
|
|
12167
|
+
try {
|
|
12168
|
+
if (((_a5 = options.signal) == null ? void 0 : _a5.aborted) && !job.isCancelled)
|
|
12169
|
+
job.abort(getAbortReason(options.signal));
|
|
12170
|
+
const workerOptions = serializableOptions(options);
|
|
12171
|
+
const transferableOptions = getTransferListForWriter(workerOptions);
|
|
12172
|
+
const transferableContext = getTransferListForWriter(jobContext);
|
|
12173
|
+
if (job.isRunning) {
|
|
12174
|
+
job.postMessage("process", {
|
|
12175
|
+
input: data,
|
|
12176
|
+
options: transferableOptions,
|
|
12177
|
+
context: transferableContext
|
|
12178
|
+
}, options.inputOwnership === "copy" || options.inputOwnership === "share" ? [] : void 0);
|
|
12179
|
+
}
|
|
12180
|
+
const result = await job.result;
|
|
12181
|
+
return result.result;
|
|
12182
|
+
} catch (error) {
|
|
12183
|
+
if (!job.isCancelled)
|
|
12184
|
+
job.abort(error);
|
|
12185
|
+
throw error;
|
|
12186
|
+
}
|
|
12187
|
+
}
|
|
12059
12188
|
function processOnWorkerInBatches(worker, input, options = {}, context = {}, jobContext = {}) {
|
|
12189
|
+
validateOutputOwnership(options.outputOwnership);
|
|
12060
12190
|
if (options.inputOwnership !== void 0 && !["copy", "transfer", "share"].includes(options.inputOwnership))
|
|
12061
12191
|
throw new Error("Invalid worker input ownership");
|
|
12062
12192
|
return processOnWorkerInBatchesIterator(worker, input, options, context, jobContext);
|
|
@@ -12304,12 +12434,12 @@ function budgetOptions(options) {
|
|
|
12304
12434
|
return inputOptions;
|
|
12305
12435
|
}
|
|
12306
12436
|
|
|
12307
|
-
// ../../node_modules/@math.gl/
|
|
12437
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/create-worker.js
|
|
12308
12438
|
var requestId = 0;
|
|
12309
12439
|
var activeController = null;
|
|
12310
12440
|
var activeInputBatches = null;
|
|
12311
12441
|
var activeOutputAcknowledgements = null;
|
|
12312
|
-
async function createWorker(process2, processInBatches) {
|
|
12442
|
+
async function createWorker(process2, processInBatches, preload) {
|
|
12313
12443
|
if (!await WorkerBody.inWorkerThread()) {
|
|
12314
12444
|
return;
|
|
12315
12445
|
}
|
|
@@ -12317,7 +12447,7 @@ async function createWorker(process2, processInBatches) {
|
|
|
12317
12447
|
process: processOnMainThread
|
|
12318
12448
|
};
|
|
12319
12449
|
WorkerBody.onmessage = async (type, payload) => {
|
|
12320
|
-
var _a5;
|
|
12450
|
+
var _a5, _b2, _c2, _d2, _e2;
|
|
12321
12451
|
if (type === "cancel") {
|
|
12322
12452
|
activeController == null ? void 0 : activeController.abort();
|
|
12323
12453
|
activeInputBatches == null ? void 0 : activeInputBatches.close();
|
|
@@ -12351,10 +12481,12 @@ async function createWorker(process2, processInBatches) {
|
|
|
12351
12481
|
}
|
|
12352
12482
|
switch (type) {
|
|
12353
12483
|
case "preload":
|
|
12484
|
+
await (preload == null ? void 0 : preload());
|
|
12354
12485
|
WorkerBody.postMessage("done", {});
|
|
12355
12486
|
break;
|
|
12356
12487
|
case "process":
|
|
12357
12488
|
throwIfAborted3();
|
|
12489
|
+
validateOutputOwnership((_b2 = payload.options) == null ? void 0 : _b2["outputOwnership"]);
|
|
12358
12490
|
if (!process2) {
|
|
12359
12491
|
throw new Error("Worker does not support atomic processing");
|
|
12360
12492
|
}
|
|
@@ -12364,10 +12496,11 @@ async function createWorker(process2, processInBatches) {
|
|
|
12364
12496
|
await WorkerBody.postMessage("done", {
|
|
12365
12497
|
result,
|
|
12366
12498
|
executionMs: performance.now() - startedAt
|
|
12367
|
-
});
|
|
12499
|
+
}, ((_c2 = payload.options) == null ? void 0 : _c2["outputOwnership"]) === "copy");
|
|
12368
12500
|
break;
|
|
12369
12501
|
case "process-in-batches":
|
|
12370
12502
|
throwIfAborted3();
|
|
12503
|
+
validateOutputOwnership((_d2 = payload.options) == null ? void 0 : _d2["outputOwnership"]);
|
|
12371
12504
|
if (!processInBatches) {
|
|
12372
12505
|
throw new Error("Worker does not support batched processing");
|
|
12373
12506
|
}
|
|
@@ -12379,7 +12512,7 @@ async function createWorker(process2, processInBatches) {
|
|
|
12379
12512
|
const resultIterator = processInBatches(createDemandDrivenIterator(inputBatches), payload.options || {}, jobContext, payload.context || {});
|
|
12380
12513
|
for await (const batch of resultIterator) {
|
|
12381
12514
|
throwIfAborted3();
|
|
12382
|
-
await WorkerBody.postMessage("output-batch", { result: batch });
|
|
12515
|
+
await WorkerBody.postMessage("output-batch", { result: batch }, ((_e2 = payload.options) == null ? void 0 : _e2["outputOwnership"]) === "copy");
|
|
12383
12516
|
await outputAcknowledgements.next();
|
|
12384
12517
|
}
|
|
12385
12518
|
throwIfAborted3();
|
|
@@ -12477,14 +12610,14 @@ function processOnMainThread(arrayBuffer2, options = {}, jobContext = {}) {
|
|
|
12477
12610
|
});
|
|
12478
12611
|
}
|
|
12479
12612
|
function createProgressReporter() {
|
|
12480
|
-
let
|
|
12613
|
+
let pending2;
|
|
12481
12614
|
let finished2 = false;
|
|
12482
12615
|
let scheduled = false;
|
|
12483
12616
|
const flush = () => {
|
|
12484
12617
|
scheduled = false;
|
|
12485
|
-
if (
|
|
12486
|
-
WorkerBody.postMessage("progress", { progress:
|
|
12487
|
-
|
|
12618
|
+
if (pending2) {
|
|
12619
|
+
WorkerBody.postMessage("progress", { progress: pending2 });
|
|
12620
|
+
pending2 = void 0;
|
|
12488
12621
|
}
|
|
12489
12622
|
};
|
|
12490
12623
|
return {
|
|
@@ -12492,9 +12625,9 @@ function createProgressReporter() {
|
|
|
12492
12625
|
report(progress) {
|
|
12493
12626
|
if (finished2)
|
|
12494
12627
|
return;
|
|
12495
|
-
if (
|
|
12628
|
+
if (pending2 && pending2.phase !== progress.phase)
|
|
12496
12629
|
flush();
|
|
12497
|
-
|
|
12630
|
+
pending2 = { ...progress };
|
|
12498
12631
|
if (!scheduled) {
|
|
12499
12632
|
scheduled = true;
|
|
12500
12633
|
setTimeout(flush, 0);
|
|
@@ -12503,172 +12636,1942 @@ function createProgressReporter() {
|
|
|
12503
12636
|
/** Flushes final progress and suppresses reports from stale callbacks. */
|
|
12504
12637
|
finish(discard = false) {
|
|
12505
12638
|
if (discard)
|
|
12506
|
-
|
|
12639
|
+
pending2 = void 0;
|
|
12507
12640
|
flush();
|
|
12508
12641
|
finished2 = true;
|
|
12509
12642
|
}
|
|
12510
12643
|
};
|
|
12511
12644
|
}
|
|
12512
12645
|
|
|
12513
|
-
// ../../node_modules/@math.gl/
|
|
12646
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/index.js
|
|
12514
12647
|
var import_meta3 = {};
|
|
12515
12648
|
var path3 = typeof __filename === "string" ? __filename.replace(/\\/g, "/") : "";
|
|
12516
12649
|
var moduleUrl = path3 ? `file://${path3.startsWith("/") ? "" : "/"}${encodeURI(path3).replace(/#/g, "%23").replace(/\?/g, "%3F")}` : import_meta3.url;
|
|
12517
12650
|
|
|
12518
|
-
//
|
|
12519
|
-
var
|
|
12520
|
-
|
|
12521
|
-
|
|
12522
|
-
|
|
12523
|
-
|
|
12524
|
-
|
|
12525
|
-
|
|
12526
|
-
|
|
12527
|
-
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
|
|
12531
|
-
function getCDNOption(cdn, coreCDN) {
|
|
12532
|
-
if (typeof cdn === "string" || cdn === null) {
|
|
12533
|
-
return cdn;
|
|
12534
|
-
}
|
|
12535
|
-
if (typeof coreCDN === "string" || coreCDN === null) {
|
|
12536
|
-
return coreCDN;
|
|
12651
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-preload.js
|
|
12652
|
+
var pending = /* @__PURE__ */ new WeakMap();
|
|
12653
|
+
var loaded = /* @__PURE__ */ new WeakSet();
|
|
12654
|
+
function preloadTaskCode(task, signal) {
|
|
12655
|
+
if (!task.preload)
|
|
12656
|
+
return Promise.resolve();
|
|
12657
|
+
let promise = pending.get(task);
|
|
12658
|
+
if (!promise) {
|
|
12659
|
+
promise = Promise.resolve().then(() => task.preload()).then(() => {
|
|
12660
|
+
loaded.add(task);
|
|
12661
|
+
});
|
|
12662
|
+
pending.set(task, promise);
|
|
12663
|
+
void promise.catch(() => pending.delete(task));
|
|
12537
12664
|
}
|
|
12538
|
-
return
|
|
12665
|
+
return withSignal(promise, signal);
|
|
12539
12666
|
}
|
|
12540
|
-
|
|
12541
|
-
|
|
12542
|
-
let moduleLibraryUrl = libraryUrl;
|
|
12543
|
-
if (moduleName) {
|
|
12544
|
-
const requestedLibraryName = libraryName || libraryUrl;
|
|
12545
|
-
const injectedLibrary = (_a5 = options.modules) == null ? void 0 : _a5[requestedLibraryName];
|
|
12546
|
-
if (injectedLibrary !== void 0 && typeof injectedLibrary !== "string") {
|
|
12547
|
-
return injectedLibrary;
|
|
12548
|
-
}
|
|
12549
|
-
libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName);
|
|
12550
|
-
const hasLibraryOverride = typeof injectedLibrary === "string";
|
|
12551
|
-
moduleLibraryUrl = moduleLibraryName && (!hasLibraryOverride || typeof ((_b2 = options.modules) == null ? void 0 : _b2[moduleLibraryName]) === "string") ? getLibraryUrl(moduleLibraryName, moduleName, options, moduleLibraryName) : libraryUrl;
|
|
12552
|
-
}
|
|
12553
|
-
const cacheKey = getLibraryCacheKey(libraryUrl, moduleLibraryUrl, isWorker);
|
|
12554
|
-
loadLibraryPromises[cacheKey] = // eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
12555
|
-
loadLibraryPromises[cacheKey] || loadLibraryFromFile(libraryUrl, moduleLibraryUrl);
|
|
12556
|
-
return await loadLibraryPromises[cacheKey];
|
|
12667
|
+
function isTaskCodeLoaded(task) {
|
|
12668
|
+
return !task.preload || loaded.has(task);
|
|
12557
12669
|
}
|
|
12558
|
-
function
|
|
12559
|
-
|
|
12670
|
+
function withSignal(operation, signal) {
|
|
12671
|
+
if (!signal)
|
|
12672
|
+
return operation;
|
|
12673
|
+
return new Promise((resolve, reject) => {
|
|
12674
|
+
const abort = () => {
|
|
12675
|
+
signal.removeEventListener("abort", abort);
|
|
12676
|
+
reject(signal.reason);
|
|
12677
|
+
};
|
|
12678
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
12679
|
+
if (signal.aborted)
|
|
12680
|
+
abort();
|
|
12681
|
+
operation.then((value) => {
|
|
12682
|
+
signal.removeEventListener("abort", abort);
|
|
12683
|
+
resolve(value);
|
|
12684
|
+
}, (error) => {
|
|
12685
|
+
signal.removeEventListener("abort", abort);
|
|
12686
|
+
reject(error);
|
|
12687
|
+
});
|
|
12688
|
+
});
|
|
12560
12689
|
}
|
|
12561
|
-
|
|
12562
|
-
|
|
12563
|
-
|
|
12564
|
-
|
|
12565
|
-
|
|
12566
|
-
|
|
12567
|
-
|
|
12568
|
-
|
|
12569
|
-
|
|
12570
|
-
|
|
12571
|
-
|
|
12690
|
+
|
|
12691
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-channel.js
|
|
12692
|
+
var TaskRequestError = class extends Error {
|
|
12693
|
+
};
|
|
12694
|
+
var TaskChannel = class {
|
|
12695
|
+
constructor(options) {
|
|
12696
|
+
this.options = options;
|
|
12697
|
+
this.nextId = 1;
|
|
12698
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
12699
|
+
this.incoming = /* @__PURE__ */ new Map();
|
|
12700
|
+
}
|
|
12701
|
+
/** Send a request without serializing other in-flight requests. */
|
|
12702
|
+
request(operation, value, signal, transfer = []) {
|
|
12703
|
+
if (this.failure)
|
|
12704
|
+
return Promise.reject(this.failure.reason);
|
|
12705
|
+
if (signal == null ? void 0 : signal.aborted)
|
|
12706
|
+
return Promise.reject(signal.reason);
|
|
12707
|
+
const id = this.nextId++;
|
|
12708
|
+
return new Promise((resolve, reject) => {
|
|
12709
|
+
const abort = () => {
|
|
12710
|
+
const pending2 = this.pending.get(id);
|
|
12711
|
+
if (!pending2)
|
|
12712
|
+
return;
|
|
12713
|
+
this.pending.delete(id);
|
|
12714
|
+
pending2.cleanup();
|
|
12715
|
+
reject(signal == null ? void 0 : signal.reason);
|
|
12716
|
+
this.send({ source: "math.gl/tasks", kind: "cancel", id });
|
|
12717
|
+
};
|
|
12718
|
+
this.pending.set(id, {
|
|
12719
|
+
resolve,
|
|
12720
|
+
reject,
|
|
12721
|
+
cleanup: () => signal == null ? void 0 : signal.removeEventListener("abort", abort)
|
|
12722
|
+
});
|
|
12723
|
+
signal == null ? void 0 : signal.addEventListener("abort", abort, { once: true });
|
|
12724
|
+
this.send({ source: "math.gl/tasks", kind: "request", id, operation, value }, transfer);
|
|
12725
|
+
});
|
|
12572
12726
|
}
|
|
12573
|
-
|
|
12574
|
-
|
|
12727
|
+
/** Send a one-way notification. */
|
|
12728
|
+
emit(operation, value, transfer = []) {
|
|
12729
|
+
if (this.failure)
|
|
12730
|
+
throw this.failure.reason;
|
|
12731
|
+
this.send({ source: "math.gl/tasks", kind: "event", id: 0, operation, value }, transfer);
|
|
12575
12732
|
}
|
|
12576
|
-
|
|
12577
|
-
|
|
12578
|
-
|
|
12733
|
+
/** Dispatch a transport message; unrelated protocols are ignored. */
|
|
12734
|
+
receive(message) {
|
|
12735
|
+
var _a5, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
12736
|
+
if (this.failure || (message == null ? void 0 : message.source) !== "math.gl/tasks")
|
|
12737
|
+
return;
|
|
12738
|
+
if (message.kind === "failure") {
|
|
12739
|
+
const reason = new Error(((_a5 = message.error) == null ? void 0 : _a5.message) ?? "Task channel failed");
|
|
12740
|
+
this.close(reason);
|
|
12741
|
+
(_c2 = (_b2 = this.options).onFailure) == null ? void 0 : _c2.call(_b2, reason);
|
|
12742
|
+
} else if (message.kind === "result" || message.kind === "error") {
|
|
12743
|
+
const pending2 = this.pending.get(message.id);
|
|
12744
|
+
if (!pending2)
|
|
12745
|
+
return;
|
|
12746
|
+
this.pending.delete(message.id);
|
|
12747
|
+
pending2.cleanup();
|
|
12748
|
+
if (message.kind === "result")
|
|
12749
|
+
pending2.resolve(message.value);
|
|
12750
|
+
else {
|
|
12751
|
+
const error = new TaskRequestError(((_d2 = message.error) == null ? void 0 : _d2.message) ?? "Task request failed");
|
|
12752
|
+
error.name = ((_e2 = message.error) == null ? void 0 : _e2.name) ?? "Error";
|
|
12753
|
+
pending2.reject(error);
|
|
12754
|
+
}
|
|
12755
|
+
} else if (message.kind === "cancel") {
|
|
12756
|
+
(_f2 = this.incoming.get(message.id)) == null ? void 0 : _f2.abort(new DOMException("Task request cancelled", "AbortError"));
|
|
12757
|
+
} else if (message.kind === "event") {
|
|
12758
|
+
try {
|
|
12759
|
+
(_h2 = (_g2 = this.options).handleEvent) == null ? void 0 : _h2.call(_g2, message.operation, message.value);
|
|
12760
|
+
} catch (error) {
|
|
12761
|
+
this.fail(error);
|
|
12762
|
+
}
|
|
12763
|
+
} else if (message.kind === "request") {
|
|
12764
|
+
if (this.incoming.has(message.id)) {
|
|
12765
|
+
this.fail(new Error("Duplicate task request identifier"));
|
|
12766
|
+
return;
|
|
12767
|
+
}
|
|
12768
|
+
const controller = new AbortController();
|
|
12769
|
+
this.incoming.set(message.id, controller);
|
|
12770
|
+
void Promise.resolve().then(() => {
|
|
12771
|
+
controller.signal.throwIfAborted();
|
|
12772
|
+
return this.options.handleRequest(message.operation, message.value, controller.signal);
|
|
12773
|
+
}).then((value) => {
|
|
12774
|
+
var _a6, _b3;
|
|
12775
|
+
if (!controller.signal.aborted && !this.failure) {
|
|
12776
|
+
this.send({ source: "math.gl/tasks", kind: "result", id: message.id, value }, (_b3 = (_a6 = this.options).getResultTransferList) == null ? void 0 : _b3.call(_a6, value, message.value));
|
|
12777
|
+
}
|
|
12778
|
+
}).catch((reason) => {
|
|
12779
|
+
if (!controller.signal.aborted && !this.failure) {
|
|
12780
|
+
this.send({
|
|
12781
|
+
source: "math.gl/tasks",
|
|
12782
|
+
kind: "error",
|
|
12783
|
+
id: message.id,
|
|
12784
|
+
error: {
|
|
12785
|
+
name: reason instanceof Error ? reason.name : "Error",
|
|
12786
|
+
message: reason instanceof Error ? reason.message : String(reason)
|
|
12787
|
+
}
|
|
12788
|
+
});
|
|
12789
|
+
}
|
|
12790
|
+
}).finally(() => this.incoming.delete(message.id));
|
|
12579
12791
|
}
|
|
12580
|
-
assert(options.CDN.startsWith("http"));
|
|
12581
|
-
return `${options.CDN}/${moduleName}@${VERSION}/dist/libs/${libraryName}`;
|
|
12582
|
-
}
|
|
12583
|
-
if (isWorker) {
|
|
12584
|
-
return libraryName.endsWith(".mjs") ? `./libs/${libraryName}` : `../src/libs/${libraryName}`;
|
|
12585
12792
|
}
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
|
|
12590
|
-
|
|
12591
|
-
|
|
12592
|
-
|
|
12593
|
-
|
|
12793
|
+
/** Reject all outstanding calls with a common cause and abort incoming callbacks. */
|
|
12794
|
+
close(reason = new Error("Task channel closed")) {
|
|
12795
|
+
if (this.failure)
|
|
12796
|
+
return;
|
|
12797
|
+
this.failure = { reason };
|
|
12798
|
+
for (const pending2 of this.pending.values()) {
|
|
12799
|
+
pending2.cleanup();
|
|
12800
|
+
pending2.reject(reason);
|
|
12801
|
+
}
|
|
12802
|
+
this.pending.clear();
|
|
12803
|
+
for (const controller of this.incoming.values())
|
|
12804
|
+
controller.abort(reason);
|
|
12805
|
+
this.incoming.clear();
|
|
12806
|
+
}
|
|
12807
|
+
send(message, transfer = []) {
|
|
12808
|
+
if (this.failure)
|
|
12809
|
+
return;
|
|
12594
12810
|
try {
|
|
12595
|
-
|
|
12596
|
-
if (result || !libraryUrl.includes("/dist/libs/")) {
|
|
12597
|
-
return result;
|
|
12598
|
-
}
|
|
12599
|
-
return await (requireFromFile2 == null ? void 0 : requireFromFile2(libraryUrl.replace("/dist/libs/", "/src/libs/")));
|
|
12811
|
+
this.options.send(message, transfer);
|
|
12600
12812
|
} catch (error) {
|
|
12601
|
-
|
|
12602
|
-
try {
|
|
12603
|
-
return await (requireFromFile2 == null ? void 0 : requireFromFile2(libraryUrl.replace("/dist/libs/", "/src/libs/")));
|
|
12604
|
-
} catch {
|
|
12605
|
-
}
|
|
12606
|
-
}
|
|
12607
|
-
console.error(error);
|
|
12608
|
-
return null;
|
|
12813
|
+
this.fail(error);
|
|
12609
12814
|
}
|
|
12610
12815
|
}
|
|
12611
|
-
|
|
12612
|
-
|
|
12816
|
+
/** Invalidate the channel and notify the peer when the transport still works. */
|
|
12817
|
+
fail(reason) {
|
|
12818
|
+
var _a5, _b2;
|
|
12819
|
+
if (this.failure)
|
|
12820
|
+
return;
|
|
12821
|
+
this.close(reason);
|
|
12822
|
+
try {
|
|
12823
|
+
this.options.send({
|
|
12824
|
+
source: "math.gl/tasks",
|
|
12825
|
+
kind: "failure",
|
|
12826
|
+
id: 0,
|
|
12827
|
+
error: {
|
|
12828
|
+
name: reason instanceof Error ? reason.name : "Error",
|
|
12829
|
+
message: reason instanceof Error ? reason.message : String(reason)
|
|
12830
|
+
}
|
|
12831
|
+
}, []);
|
|
12832
|
+
} catch {
|
|
12833
|
+
}
|
|
12834
|
+
(_b2 = (_a5 = this.options).onFailure) == null ? void 0 : _b2.call(_a5, reason);
|
|
12613
12835
|
}
|
|
12614
|
-
|
|
12615
|
-
|
|
12616
|
-
|
|
12617
|
-
|
|
12618
|
-
|
|
12619
|
-
|
|
12620
|
-
} catch {
|
|
12621
|
-
const moduleUrl2 = new URL(moduleLibraryUrl, globalThis.location.href).href;
|
|
12622
|
-
const library = await import(
|
|
12623
|
-
/* @vite-ignore */
|
|
12624
|
-
moduleUrl2
|
|
12625
|
-
);
|
|
12626
|
-
return library.default ?? library;
|
|
12836
|
+
};
|
|
12837
|
+
|
|
12838
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-runtime.js
|
|
12839
|
+
function assertPayload(value) {
|
|
12840
|
+
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) {
|
|
12841
|
+
throw new TypeError("Task payloads must be plain objects with named fields");
|
|
12627
12842
|
}
|
|
12628
|
-
return importScripts(libraryUrl);
|
|
12629
12843
|
}
|
|
12630
|
-
function
|
|
12631
|
-
|
|
12632
|
-
|
|
12633
|
-
|
|
12634
|
-
|
|
12635
|
-
|
|
12636
|
-
|
|
12637
|
-
|
|
12638
|
-
|
|
12639
|
-
|
|
12844
|
+
function clonePayload(value, ownership = "copy") {
|
|
12845
|
+
assertPayload(value);
|
|
12846
|
+
if (!["copy", "transfer", "share"].includes(ownership))
|
|
12847
|
+
throw new TypeError("Invalid input ownership");
|
|
12848
|
+
const transfer = getTransferList(value);
|
|
12849
|
+
if (ownership === "share" && transfer.length)
|
|
12850
|
+
throw new TypeError("Share requires shared storage");
|
|
12851
|
+
return structuredClone(value, {
|
|
12852
|
+
transfer: ownership === "transfer" ? transfer : []
|
|
12853
|
+
});
|
|
12640
12854
|
}
|
|
12641
|
-
|
|
12642
|
-
const
|
|
12643
|
-
|
|
12644
|
-
|
|
12645
|
-
|
|
12646
|
-
|
|
12647
|
-
|
|
12648
|
-
|
|
12649
|
-
|
|
12650
|
-
|
|
12651
|
-
|
|
12855
|
+
function taskContext(state, context = {}) {
|
|
12856
|
+
const signal = context.signal ?? new AbortController().signal;
|
|
12857
|
+
return {
|
|
12858
|
+
state,
|
|
12859
|
+
signal,
|
|
12860
|
+
requestHost: async (operation, payload, controls) => {
|
|
12861
|
+
signal.throwIfAborted();
|
|
12862
|
+
if (!context.requestHost)
|
|
12863
|
+
throw new Error("No host request handler configured");
|
|
12864
|
+
return context.requestHost(operation, payload, controls);
|
|
12865
|
+
},
|
|
12866
|
+
emitHost: (operation, payload) => {
|
|
12867
|
+
var _a5;
|
|
12868
|
+
signal.throwIfAborted();
|
|
12869
|
+
(_a5 = context.emitHost) == null ? void 0 : _a5.call(context, operation, payload);
|
|
12870
|
+
},
|
|
12871
|
+
throwIfAborted: () => {
|
|
12872
|
+
var _a5;
|
|
12873
|
+
signal.throwIfAborted();
|
|
12874
|
+
(_a5 = context.throwIfAborted) == null ? void 0 : _a5.call(context);
|
|
12875
|
+
},
|
|
12876
|
+
reportProgress: (progress) => {
|
|
12877
|
+
var _a5;
|
|
12878
|
+
return (_a5 = context.reportProgress) == null ? void 0 : _a5.call(context, {
|
|
12879
|
+
...progress,
|
|
12880
|
+
phase: progress.phase ?? "process",
|
|
12881
|
+
unit: progress.unit ?? "items"
|
|
12882
|
+
});
|
|
12652
12883
|
}
|
|
12653
|
-
|
|
12654
|
-
}
|
|
12884
|
+
};
|
|
12655
12885
|
}
|
|
12656
|
-
|
|
12657
|
-
|
|
12658
|
-
|
|
12659
|
-
|
|
12660
|
-
|
|
12886
|
+
var TaskRuntime = class {
|
|
12887
|
+
constructor(task) {
|
|
12888
|
+
this.task = task;
|
|
12889
|
+
this.initialized = false;
|
|
12890
|
+
}
|
|
12891
|
+
async initialize(input, context = {}) {
|
|
12892
|
+
var _a5, _b2, _c2;
|
|
12893
|
+
if (this.initialized)
|
|
12894
|
+
throw new Error("Task is already initialized");
|
|
12895
|
+
assertPayload(input);
|
|
12896
|
+
await preloadTaskCode(this.task, context.signal);
|
|
12897
|
+
(_a5 = context.signal) == null ? void 0 : _a5.throwIfAborted();
|
|
12898
|
+
this.state = await ((_c2 = (_b2 = this.task).initialize) == null ? void 0 : _c2.call(_b2, input, taskContext(void 0, context)));
|
|
12899
|
+
this.initialized = true;
|
|
12900
|
+
return {};
|
|
12661
12901
|
}
|
|
12662
|
-
|
|
12663
|
-
|
|
12664
|
-
|
|
12665
|
-
|
|
12666
|
-
|
|
12902
|
+
async destroy() {
|
|
12903
|
+
var _a5, _b2;
|
|
12904
|
+
if (this.initialized) {
|
|
12905
|
+
this.initialized = false;
|
|
12906
|
+
const state = this.state;
|
|
12907
|
+
this.state = void 0;
|
|
12908
|
+
if (this.task.initialize)
|
|
12909
|
+
await ((_b2 = (_a5 = this.task).destroy) == null ? void 0 : _b2.call(_a5, state));
|
|
12667
12910
|
}
|
|
12668
|
-
|
|
12911
|
+
return {};
|
|
12912
|
+
}
|
|
12913
|
+
async process(input, options, context = {}) {
|
|
12914
|
+
if (!this.initialized)
|
|
12915
|
+
throw new Error("Task is not initialized");
|
|
12916
|
+
if (!this.task.process)
|
|
12917
|
+
throw new Error("Task has no atomic processor");
|
|
12918
|
+
assertPayload(input);
|
|
12919
|
+
const result = await this.task.process(input, options, taskContext(this.state, context));
|
|
12920
|
+
assertPayload(result);
|
|
12921
|
+
return result;
|
|
12669
12922
|
}
|
|
12923
|
+
async *stream(inputs, options, context = {}) {
|
|
12924
|
+
if (!this.initialized)
|
|
12925
|
+
throw new Error("Task is not initialized");
|
|
12926
|
+
if (!this.task.processInBatches)
|
|
12927
|
+
throw new Error("Task has no streaming processor");
|
|
12928
|
+
for await (const output of this.task.processInBatches(inputs, options, taskContext(this.state, context))) {
|
|
12929
|
+
assertPayload(output);
|
|
12930
|
+
yield output;
|
|
12931
|
+
}
|
|
12932
|
+
}
|
|
12933
|
+
};
|
|
12934
|
+
async function initializeTaskWorker(task) {
|
|
12935
|
+
if (!await WorkerBody.inWorkerThread())
|
|
12936
|
+
throw new Error("initializeTaskWorker must run inside a worker");
|
|
12937
|
+
if (installed)
|
|
12938
|
+
throw new Error("A task is already installed in this worker");
|
|
12939
|
+
installed = true;
|
|
12940
|
+
const runtime = new TaskRuntime(task);
|
|
12941
|
+
let channelStream;
|
|
12942
|
+
const channel = new TaskChannel({
|
|
12943
|
+
getResultTransferList: (value, request) => request.outputOwnership === "transfer" ? getTransferList(value) : [],
|
|
12944
|
+
send: (message, transfer) => {
|
|
12945
|
+
const snapshot = structuredClone(message, { transfer });
|
|
12946
|
+
void WorkerBody.postMessage("task-channel", snapshot).catch((reason) => channel.fail(reason));
|
|
12947
|
+
},
|
|
12948
|
+
handleRequest: async (operation, value, signal) => {
|
|
12949
|
+
var _a5;
|
|
12950
|
+
const request = value;
|
|
12951
|
+
const context = {
|
|
12952
|
+
signal,
|
|
12953
|
+
reportProgress: (progress) => channel.emit("task:progress", { id: request.progressId, progress }),
|
|
12954
|
+
requestHost: (operation2, payload, controls = {}) => {
|
|
12955
|
+
const request2 = {
|
|
12956
|
+
operation: operation2,
|
|
12957
|
+
payload: clonePayload(payload, controls.inputOwnership),
|
|
12958
|
+
outputOwnership: controls.outputOwnership ?? "copy"
|
|
12959
|
+
};
|
|
12960
|
+
return channel.request("task:host-request", request2, signal, getTransferList(request2));
|
|
12961
|
+
},
|
|
12962
|
+
emitHost: (operation2, payload) => channel.emit("task:host-event", { operation: operation2, payload, id: request.progressId })
|
|
12963
|
+
};
|
|
12964
|
+
switch (operation) {
|
|
12965
|
+
case "initialize":
|
|
12966
|
+
return runtime.initialize(request.input, context);
|
|
12967
|
+
case "process":
|
|
12968
|
+
return runtime.process(request.input, request.options, context);
|
|
12969
|
+
case "stream-open": {
|
|
12970
|
+
if (channelStream)
|
|
12971
|
+
throw new Error("A task stream is already open");
|
|
12972
|
+
async function* inputs() {
|
|
12973
|
+
while (true) {
|
|
12974
|
+
const result = await channel.request("task:next-input", { outputOwnership: "transfer" }, signal);
|
|
12975
|
+
if (result.done)
|
|
12976
|
+
return;
|
|
12977
|
+
yield result.value;
|
|
12978
|
+
}
|
|
12979
|
+
}
|
|
12980
|
+
channelStream = runtime.stream(inputs(), request.options, context)[Symbol.asyncIterator]();
|
|
12981
|
+
return {};
|
|
12982
|
+
}
|
|
12983
|
+
case "stream-next":
|
|
12984
|
+
if (!channelStream)
|
|
12985
|
+
throw new Error("No active task stream");
|
|
12986
|
+
return channelStream.next();
|
|
12987
|
+
case "stream-close":
|
|
12988
|
+
try {
|
|
12989
|
+
await ((_a5 = channelStream == null ? void 0 : channelStream.return) == null ? void 0 : _a5.call(channelStream));
|
|
12990
|
+
} finally {
|
|
12991
|
+
channelStream = void 0;
|
|
12992
|
+
}
|
|
12993
|
+
return {};
|
|
12994
|
+
case "destroy":
|
|
12995
|
+
return runtime.destroy();
|
|
12996
|
+
default:
|
|
12997
|
+
throw new Error("Unknown task channel operation");
|
|
12998
|
+
}
|
|
12999
|
+
}
|
|
13000
|
+
});
|
|
13001
|
+
await WorkerBody.addEventListener((type, payload) => {
|
|
13002
|
+
if (type === "task-channel")
|
|
13003
|
+
channel.receive(payload);
|
|
13004
|
+
});
|
|
13005
|
+
let streamOptions = {};
|
|
13006
|
+
return createWorker(async (request, _options, context) => {
|
|
13007
|
+
switch (request.operation) {
|
|
13008
|
+
case "initialize":
|
|
13009
|
+
return runtime.initialize(request.input, context);
|
|
13010
|
+
case "destroy":
|
|
13011
|
+
return runtime.destroy();
|
|
13012
|
+
case "stream-options":
|
|
13013
|
+
streamOptions = request.options;
|
|
13014
|
+
return {};
|
|
13015
|
+
case "process":
|
|
13016
|
+
return runtime.process(request.input, request.options, context);
|
|
13017
|
+
default:
|
|
13018
|
+
throw new Error("Unknown task operation");
|
|
13019
|
+
}
|
|
13020
|
+
}, async function* (inputs, _options, context) {
|
|
13021
|
+
async function* batches() {
|
|
13022
|
+
for await (const input of inputs) {
|
|
13023
|
+
assertPayload(input);
|
|
13024
|
+
yield input;
|
|
13025
|
+
}
|
|
13026
|
+
}
|
|
13027
|
+
try {
|
|
13028
|
+
yield* runtime.stream(batches(), streamOptions, context);
|
|
13029
|
+
} finally {
|
|
13030
|
+
streamOptions = {};
|
|
13031
|
+
}
|
|
13032
|
+
}, () => preloadTaskCode(task));
|
|
12670
13033
|
}
|
|
12671
|
-
|
|
13034
|
+
var installed = false;
|
|
13035
|
+
function localContext(controls) {
|
|
13036
|
+
return {
|
|
13037
|
+
signal: controls.signal,
|
|
13038
|
+
reportProgress: (progress) => {
|
|
13039
|
+
var _a5;
|
|
13040
|
+
return (_a5 = controls.onProgress) == null ? void 0 : _a5.call(controls, progress);
|
|
13041
|
+
}
|
|
13042
|
+
};
|
|
13043
|
+
}
|
|
13044
|
+
|
|
13045
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-sync.js
|
|
13046
|
+
function runTaskSync(task, input, request = {}) {
|
|
13047
|
+
var _a5, _b2;
|
|
13048
|
+
if (!isTaskCodeLoaded(task))
|
|
13049
|
+
throw new Error("Preload task on the main thread before runTaskSync");
|
|
13050
|
+
if ("execution" in request)
|
|
13051
|
+
throw new TypeError("runTaskSync always runs on the calling thread");
|
|
13052
|
+
if (!task.process)
|
|
13053
|
+
throw new TypeError("Task has no atomic processor");
|
|
13054
|
+
for (const hook of [task.initialize, task.process, task.destroy]) {
|
|
13055
|
+
if (hook && Object.prototype.toString.call(hook) === "[object AsyncFunction]")
|
|
13056
|
+
throw new TypeError("runTaskSync requires synchronous lifecycle hooks");
|
|
13057
|
+
}
|
|
13058
|
+
if (request.outputOwnership && !["copy", "transfer"].includes(request.outputOwnership))
|
|
13059
|
+
throw new TypeError("Invalid output ownership");
|
|
13060
|
+
const context = taskContext(void 0, localContext(request));
|
|
13061
|
+
context.throwIfAborted();
|
|
13062
|
+
const options = request.options ?? {};
|
|
13063
|
+
if (request.inputOwnership === "transfer") {
|
|
13064
|
+
const metadata2 = new Set(getTransferList(options));
|
|
13065
|
+
if (getTransferList(input).some((buffer2) => metadata2.has(buffer2)))
|
|
13066
|
+
throw new Error("Transferred input aliases reusable options; use inputOwnership: copy");
|
|
13067
|
+
}
|
|
13068
|
+
const copiedOptions = clonePayload(options);
|
|
13069
|
+
const initialization = clonePayload(request.initialization ?? {}, request.initializationOwnership);
|
|
13070
|
+
let initialized = false;
|
|
13071
|
+
let failure;
|
|
13072
|
+
let failed = false;
|
|
13073
|
+
let output;
|
|
13074
|
+
try {
|
|
13075
|
+
const state = (_a5 = task.initialize) == null ? void 0 : _a5.call(task, initialization, context);
|
|
13076
|
+
if (isThenable(state)) {
|
|
13077
|
+
void Promise.resolve(state).then((value) => {
|
|
13078
|
+
var _a6;
|
|
13079
|
+
return (_a6 = task.destroy) == null ? void 0 : _a6.call(task, value);
|
|
13080
|
+
}).catch(() => {
|
|
13081
|
+
});
|
|
13082
|
+
throw new TypeError("runTaskSync initialize returned a promise");
|
|
13083
|
+
}
|
|
13084
|
+
context.state = state;
|
|
13085
|
+
initialized = true;
|
|
13086
|
+
context.throwIfAborted();
|
|
13087
|
+
const copiedInput = clonePayload(input, request.inputOwnership);
|
|
13088
|
+
const result = task.process(copiedInput, copiedOptions, context);
|
|
13089
|
+
if (isThenable(result)) {
|
|
13090
|
+
initialized = false;
|
|
13091
|
+
void Promise.resolve(result).catch(() => {
|
|
13092
|
+
}).then(() => {
|
|
13093
|
+
var _a6;
|
|
13094
|
+
if (task.initialize)
|
|
13095
|
+
return (_a6 = task.destroy) == null ? void 0 : _a6.call(task, context.state);
|
|
13096
|
+
}).catch(() => {
|
|
13097
|
+
});
|
|
13098
|
+
throw new TypeError("runTaskSync process returned a promise");
|
|
13099
|
+
}
|
|
13100
|
+
assertPayload(result);
|
|
13101
|
+
context.throwIfAborted();
|
|
13102
|
+
output = clonePayload(result, request.outputOwnership ?? "transfer");
|
|
13103
|
+
} catch (error) {
|
|
13104
|
+
failed = true;
|
|
13105
|
+
failure = error;
|
|
13106
|
+
} finally {
|
|
13107
|
+
if (initialized && task.initialize) {
|
|
13108
|
+
try {
|
|
13109
|
+
const cleanup = (_b2 = task.destroy) == null ? void 0 : _b2.call(task, context.state);
|
|
13110
|
+
if (isThenable(cleanup)) {
|
|
13111
|
+
void Promise.resolve(cleanup).catch(() => {
|
|
13112
|
+
});
|
|
13113
|
+
throw new TypeError("runTaskSync destroy returned a promise");
|
|
13114
|
+
}
|
|
13115
|
+
} catch (error) {
|
|
13116
|
+
if (failed)
|
|
13117
|
+
throw new AggregateError([failure, error], "Task processing and destruction failed");
|
|
13118
|
+
throw error;
|
|
13119
|
+
}
|
|
13120
|
+
}
|
|
13121
|
+
}
|
|
13122
|
+
if (failed)
|
|
13123
|
+
throw failure;
|
|
13124
|
+
return output;
|
|
13125
|
+
}
|
|
13126
|
+
function isThenable(value) {
|
|
13127
|
+
return Boolean(value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function");
|
|
13128
|
+
}
|
|
13129
|
+
|
|
13130
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-operation-queue.js
|
|
13131
|
+
var TaskOperationQueue = class {
|
|
13132
|
+
constructor(maxConcurrency) {
|
|
13133
|
+
this.maxConcurrency = maxConcurrency;
|
|
13134
|
+
this.pending = [];
|
|
13135
|
+
this.active = 0;
|
|
13136
|
+
this.exclusive = false;
|
|
13137
|
+
this.closed = false;
|
|
13138
|
+
this.idleWaiters = /* @__PURE__ */ new Set();
|
|
13139
|
+
if (!Number.isSafeInteger(maxConcurrency) || maxConcurrency < 1) {
|
|
13140
|
+
throw new RangeError("maxConcurrency must be a positive safe integer");
|
|
13141
|
+
}
|
|
13142
|
+
}
|
|
13143
|
+
/** Queue an operation; aborting before it starts removes it without running it. */
|
|
13144
|
+
run(mode, operation, signal) {
|
|
13145
|
+
if (this.closed)
|
|
13146
|
+
return Promise.reject(new Error("Task operation queue is closed"));
|
|
13147
|
+
if (mode !== "parallel" && mode !== "exclusive")
|
|
13148
|
+
return Promise.reject(new TypeError("Invalid operation mode"));
|
|
13149
|
+
if (signal == null ? void 0 : signal.aborted)
|
|
13150
|
+
return Promise.reject(signal.reason);
|
|
13151
|
+
return new Promise((resolve, reject) => {
|
|
13152
|
+
const onAbort = () => {
|
|
13153
|
+
const index2 = this.pending.indexOf(entry);
|
|
13154
|
+
if (index2 >= 0) {
|
|
13155
|
+
this.pending.splice(index2, 1);
|
|
13156
|
+
entry.cancel(signal == null ? void 0 : signal.reason);
|
|
13157
|
+
this.pump();
|
|
13158
|
+
}
|
|
13159
|
+
};
|
|
13160
|
+
const entry = {
|
|
13161
|
+
mode,
|
|
13162
|
+
cancel: (reason) => {
|
|
13163
|
+
signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
|
|
13164
|
+
reject(reason);
|
|
13165
|
+
},
|
|
13166
|
+
start: () => {
|
|
13167
|
+
signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
|
|
13168
|
+
this.active++;
|
|
13169
|
+
if (mode === "exclusive")
|
|
13170
|
+
this.exclusive = true;
|
|
13171
|
+
void Promise.resolve().then(() => {
|
|
13172
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
13173
|
+
return operation();
|
|
13174
|
+
}).then(resolve, reject).finally(() => {
|
|
13175
|
+
this.active--;
|
|
13176
|
+
if (mode === "exclusive")
|
|
13177
|
+
this.exclusive = false;
|
|
13178
|
+
this.pump();
|
|
13179
|
+
});
|
|
13180
|
+
}
|
|
13181
|
+
};
|
|
13182
|
+
this.pending.push(entry);
|
|
13183
|
+
signal == null ? void 0 : signal.addEventListener("abort", onAbort, { once: true });
|
|
13184
|
+
if (signal == null ? void 0 : signal.aborted)
|
|
13185
|
+
onAbort();
|
|
13186
|
+
else
|
|
13187
|
+
this.pump();
|
|
13188
|
+
});
|
|
13189
|
+
}
|
|
13190
|
+
/** Reject queued calls with one cause while allowing active operations to settle. */
|
|
13191
|
+
cancelPending(reason) {
|
|
13192
|
+
this.closed = true;
|
|
13193
|
+
for (const entry of this.pending.splice(0))
|
|
13194
|
+
entry.cancel(reason);
|
|
13195
|
+
this.pump();
|
|
13196
|
+
}
|
|
13197
|
+
/** Stop accepting new work; accepted operations continue to completion. */
|
|
13198
|
+
close() {
|
|
13199
|
+
this.closed = true;
|
|
13200
|
+
return this.whenIdle();
|
|
13201
|
+
}
|
|
13202
|
+
/** Wait until the queue has no running or waiting operations. */
|
|
13203
|
+
whenIdle() {
|
|
13204
|
+
if (!this.active && !this.pending.length)
|
|
13205
|
+
return Promise.resolve();
|
|
13206
|
+
return new Promise((resolve) => this.idleWaiters.add(resolve));
|
|
13207
|
+
}
|
|
13208
|
+
pump() {
|
|
13209
|
+
while (!this.exclusive && this.pending.length && this.active < this.maxConcurrency) {
|
|
13210
|
+
const entry = this.pending[0];
|
|
13211
|
+
if (entry.mode === "exclusive" && this.active)
|
|
13212
|
+
break;
|
|
13213
|
+
this.pending.shift();
|
|
13214
|
+
entry.start();
|
|
13215
|
+
if (entry.mode === "exclusive")
|
|
13216
|
+
break;
|
|
13217
|
+
}
|
|
13218
|
+
if (!this.active && !this.pending.length) {
|
|
13219
|
+
for (const resolve of this.idleWaiters)
|
|
13220
|
+
resolve();
|
|
13221
|
+
this.idleWaiters.clear();
|
|
13222
|
+
}
|
|
13223
|
+
}
|
|
13224
|
+
};
|
|
13225
|
+
|
|
13226
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-worker-channel.js
|
|
13227
|
+
var TaskWorkerChannel = class {
|
|
13228
|
+
constructor(name, target, options) {
|
|
13229
|
+
var _a5;
|
|
13230
|
+
this.thread = new WorkerThread({
|
|
13231
|
+
name,
|
|
13232
|
+
url: (_a5 = target.url) == null ? void 0 : _a5.toString(),
|
|
13233
|
+
loadWorker: target.create,
|
|
13234
|
+
workerType: "module"
|
|
13235
|
+
});
|
|
13236
|
+
this.channel = new TaskChannel({
|
|
13237
|
+
...options,
|
|
13238
|
+
send: (message, transfer) => this.thread.postMessage({ source: "loaders.gl/tasks", type: "task-channel", payload: message }, transfer)
|
|
13239
|
+
});
|
|
13240
|
+
this.thread.onMessage = (message) => {
|
|
13241
|
+
if ((message == null ? void 0 : message.type) === "task-channel")
|
|
13242
|
+
this.channel.receive(message.payload);
|
|
13243
|
+
};
|
|
13244
|
+
this.thread.onError = (reason) => {
|
|
13245
|
+
var _a6;
|
|
13246
|
+
this.channel.close(reason);
|
|
13247
|
+
(_a6 = options.onFailure) == null ? void 0 : _a6.call(options, reason);
|
|
13248
|
+
};
|
|
13249
|
+
}
|
|
13250
|
+
/** Settle pending calls and terminate the worker without replacing its state. */
|
|
13251
|
+
async destroy(reason) {
|
|
13252
|
+
this.channel.close(reason);
|
|
13253
|
+
await this.thread.destroy();
|
|
13254
|
+
}
|
|
13255
|
+
};
|
|
13256
|
+
|
|
13257
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-runner.js
|
|
13258
|
+
var InitializedTask = class {
|
|
13259
|
+
/** @internal Use TaskRunner.initializeTask. */
|
|
13260
|
+
constructor(task, release, initializationControls) {
|
|
13261
|
+
var _a5, _b2, _c2;
|
|
13262
|
+
this.task = task;
|
|
13263
|
+
this.release = release;
|
|
13264
|
+
this.initializationControls = initializationControls;
|
|
13265
|
+
this.nextProgressId = 1;
|
|
13266
|
+
this.progressCallbacks = /* @__PURE__ */ new Map();
|
|
13267
|
+
this.callbackFailures = /* @__PURE__ */ new Map();
|
|
13268
|
+
this.closed = false;
|
|
13269
|
+
this.finalized = false;
|
|
13270
|
+
this.streams = /* @__PURE__ */ new Set();
|
|
13271
|
+
this.invalid = false;
|
|
13272
|
+
this.controller = new AbortController();
|
|
13273
|
+
const controls = initializationControls;
|
|
13274
|
+
this.runtime = new TaskRuntime(task);
|
|
13275
|
+
const concurrency2 = controls.operationConcurrency ?? 1;
|
|
13276
|
+
const maximum = ((_a5 = task.concurrency) == null ? void 0 : _a5.maxConcurrency) ?? 1;
|
|
13277
|
+
if (!Number.isSafeInteger(maximum) || maximum < 1 || !Number.isSafeInteger(concurrency2) || concurrency2 < 1 || concurrency2 > maximum) {
|
|
13278
|
+
throw new RangeError("Task concurrency must be between 1 and the task maximum");
|
|
13279
|
+
}
|
|
13280
|
+
this.operationQueue = new TaskOperationQueue(concurrency2);
|
|
13281
|
+
this.concurrent = concurrency2 > 1;
|
|
13282
|
+
const execution = controls.execution ?? "auto";
|
|
13283
|
+
if (!["auto", "main-thread", "worker"].includes(execution))
|
|
13284
|
+
throw new TypeError("Invalid execution mode");
|
|
13285
|
+
if (execution === "worker" && !task.worker)
|
|
13286
|
+
throw new Error("Task has no worker");
|
|
13287
|
+
if (execution !== "main-thread" && task.worker) {
|
|
13288
|
+
const target = task.worker;
|
|
13289
|
+
if (Boolean(target.url) === Boolean(target.create))
|
|
13290
|
+
throw new Error("Supply exactly one worker URL or factory");
|
|
13291
|
+
if (this.concurrent || controls.onRequest || controls.onEvent) {
|
|
13292
|
+
this.workerChannel = new TaskWorkerChannel(task.id, target, {
|
|
13293
|
+
handleRequest: async (operation, payload, signal) => {
|
|
13294
|
+
if (operation === "task:next-input") {
|
|
13295
|
+
if (!this.channelInputs)
|
|
13296
|
+
throw new Error("No active task stream");
|
|
13297
|
+
return this.channelInputs.next();
|
|
13298
|
+
}
|
|
13299
|
+
if (!controls.onRequest)
|
|
13300
|
+
throw new Error("No host request handler configured");
|
|
13301
|
+
const request = payload;
|
|
13302
|
+
if (operation !== "task:host-request")
|
|
13303
|
+
throw new Error("Unknown host request");
|
|
13304
|
+
return controls.onRequest(request.operation, request.payload, signal);
|
|
13305
|
+
},
|
|
13306
|
+
getResultTransferList: (value, request) => request.outputOwnership === "transfer" ? getTransferList(value) : [],
|
|
13307
|
+
handleEvent: (operation, payload) => {
|
|
13308
|
+
var _a6, _b3;
|
|
13309
|
+
const { id } = payload;
|
|
13310
|
+
try {
|
|
13311
|
+
if (operation === "task:progress") {
|
|
13312
|
+
const event = payload;
|
|
13313
|
+
(_a6 = this.progressCallbacks.get(event.id) ?? this.streamProgress) == null ? void 0 : _a6(event.progress);
|
|
13314
|
+
} else if (operation === "task:host-event") {
|
|
13315
|
+
const event = payload;
|
|
13316
|
+
(_b3 = controls.onEvent) == null ? void 0 : _b3.call(controls, event.operation, event.payload);
|
|
13317
|
+
}
|
|
13318
|
+
} catch (reason) {
|
|
13319
|
+
if (this.progressCallbacks.has(id) || this.streamProgressId === id) {
|
|
13320
|
+
if (!this.callbackFailures.has(id))
|
|
13321
|
+
this.callbackFailures.set(id, { reason });
|
|
13322
|
+
}
|
|
13323
|
+
}
|
|
13324
|
+
},
|
|
13325
|
+
onFailure: (reason) => {
|
|
13326
|
+
this.invalid = true;
|
|
13327
|
+
this.operationQueue.cancelPending(reason);
|
|
13328
|
+
this.controller.abort(reason);
|
|
13329
|
+
}
|
|
13330
|
+
});
|
|
13331
|
+
return;
|
|
13332
|
+
}
|
|
13333
|
+
this.pool = new WorkerPool({
|
|
13334
|
+
name: task.id,
|
|
13335
|
+
url: (_b2 = target.url) == null ? void 0 : _b2.toString(),
|
|
13336
|
+
loadWorker: target.create,
|
|
13337
|
+
workerType: "module",
|
|
13338
|
+
maxConcurrency: 1,
|
|
13339
|
+
maxMobileConcurrency: 1
|
|
13340
|
+
});
|
|
13341
|
+
this.descriptor = {
|
|
13342
|
+
id: task.id,
|
|
13343
|
+
name: task.id,
|
|
13344
|
+
module: "tasks",
|
|
13345
|
+
version: "prototype",
|
|
13346
|
+
options: {},
|
|
13347
|
+
worker: ((_c2 = target.url) == null ? void 0 : _c2.toString()) ?? true,
|
|
13348
|
+
loadWorker: target.create,
|
|
13349
|
+
workerInBatches: target.capabilities.streaming
|
|
13350
|
+
};
|
|
13351
|
+
}
|
|
13352
|
+
}
|
|
13353
|
+
/** @internal */
|
|
13354
|
+
async initialize(input, controls) {
|
|
13355
|
+
try {
|
|
13356
|
+
assertPayload(input);
|
|
13357
|
+
await this.enqueue(() => this.invoke("initialize", input, {}, controls));
|
|
13358
|
+
} catch (error) {
|
|
13359
|
+
await this.terminate(error);
|
|
13360
|
+
throw error;
|
|
13361
|
+
}
|
|
13362
|
+
}
|
|
13363
|
+
runTask(input, ...args) {
|
|
13364
|
+
var _a5, _b2, _c2, _d2, _e2;
|
|
13365
|
+
if (this.invalid)
|
|
13366
|
+
return Promise.reject(new Error("Initialized task is invalid; initialize a new instance"));
|
|
13367
|
+
if (this.closed)
|
|
13368
|
+
return Promise.reject(new Error("Initialized task is closed"));
|
|
13369
|
+
const timeout2 = (_a5 = args[0]) == null ? void 0 : _a5.timeout;
|
|
13370
|
+
if (timeout2 !== void 0 && (!Number.isSafeInteger(timeout2) || timeout2 < 0 || timeout2 > 4294967295)) {
|
|
13371
|
+
return Promise.reject(new RangeError("Invalid task timeout"));
|
|
13372
|
+
}
|
|
13373
|
+
const deadline = timeout2 === void 0 ? void 0 : AbortSignal.timeout(timeout2);
|
|
13374
|
+
const signal = deadline && ((_b2 = args[0]) == null ? void 0 : _b2.signal) ? AbortSignal.any([deadline, args[0].signal]) : deadline ?? ((_c2 = args[0]) == null ? void 0 : _c2.signal);
|
|
13375
|
+
const controls = { ...args[0], signal };
|
|
13376
|
+
const mode = ((_e2 = (_d2 = this.task.concurrency) == null ? void 0 : _d2.getSchedulingMode) == null ? void 0 : _e2.call(_d2, input)) ?? "exclusive";
|
|
13377
|
+
return this.operationQueue.run(mode, async () => {
|
|
13378
|
+
var _a6;
|
|
13379
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
13380
|
+
this.checkCapability("atomic");
|
|
13381
|
+
const invalidate = () => {
|
|
13382
|
+
if (this.concurrent) {
|
|
13383
|
+
this.invalid = true;
|
|
13384
|
+
this.operationQueue.cancelPending(signal == null ? void 0 : signal.reason);
|
|
13385
|
+
this.controller.abort(signal == null ? void 0 : signal.reason);
|
|
13386
|
+
}
|
|
13387
|
+
};
|
|
13388
|
+
signal == null ? void 0 : signal.addEventListener("abort", invalidate, { once: true });
|
|
13389
|
+
try {
|
|
13390
|
+
return await this.invoke("process", input, ((_a6 = args[0]) == null ? void 0 : _a6.options) ?? {}, controls);
|
|
13391
|
+
} finally {
|
|
13392
|
+
signal == null ? void 0 : signal.removeEventListener("abort", invalidate);
|
|
13393
|
+
}
|
|
13394
|
+
}, signal);
|
|
13395
|
+
}
|
|
13396
|
+
/** Independent calls sharing this instance, always serial and in input order. */
|
|
13397
|
+
runTasks(inputs, ...args) {
|
|
13398
|
+
var _a5;
|
|
13399
|
+
return this.serialStream(async function* (self2) {
|
|
13400
|
+
var _a6;
|
|
13401
|
+
self2.checkCapability("atomic");
|
|
13402
|
+
for await (const input of asAsync(inputs, self2.controls(args[0]).signal)) {
|
|
13403
|
+
yield await self2.invoke("process", input, ((_a6 = args[0]) == null ? void 0 : _a6.options) ?? {}, args[0]);
|
|
13404
|
+
}
|
|
13405
|
+
}, (_a5 = args[0]) == null ? void 0 : _a5.signal);
|
|
13406
|
+
}
|
|
13407
|
+
/** One processor invocation for the entire input iterable. */
|
|
13408
|
+
runTaskInBatches(inputs, ...args) {
|
|
13409
|
+
var _a5;
|
|
13410
|
+
return this.serialStream(async function* (self2) {
|
|
13411
|
+
var _a6, _b2, _c2, _d2;
|
|
13412
|
+
self2.checkCapability("streaming");
|
|
13413
|
+
const controls = self2.controls(args[0]);
|
|
13414
|
+
const options = clonePayload(((_a6 = args[0]) == null ? void 0 : _a6.options) ?? {});
|
|
13415
|
+
async function* prepared() {
|
|
13416
|
+
var _a7, _b3;
|
|
13417
|
+
for await (const input of asAsync(inputs, controls.signal)) {
|
|
13418
|
+
(_a7 = controls.signal) == null ? void 0 : _a7.throwIfAborted();
|
|
13419
|
+
assertNoTransferAlias(input, ((_b3 = args[0]) == null ? void 0 : _b3.options) ?? {}, controls.inputOwnership);
|
|
13420
|
+
yield clonePayload(input, controls.inputOwnership);
|
|
13421
|
+
}
|
|
13422
|
+
}
|
|
13423
|
+
let completed = false;
|
|
13424
|
+
try {
|
|
13425
|
+
if (self2.workerChannel) {
|
|
13426
|
+
self2.channelInputs = prepared()[Symbol.asyncIterator]();
|
|
13427
|
+
self2.streamProgress = controls.onProgress;
|
|
13428
|
+
try {
|
|
13429
|
+
await self2.invoke("stream-open", {}, options, controls);
|
|
13430
|
+
while (true) {
|
|
13431
|
+
const result = await self2.invoke("stream-next", {}, {}, controls);
|
|
13432
|
+
if (result.done)
|
|
13433
|
+
break;
|
|
13434
|
+
yield result.value;
|
|
13435
|
+
}
|
|
13436
|
+
} finally {
|
|
13437
|
+
try {
|
|
13438
|
+
if (!self2.invalid)
|
|
13439
|
+
await self2.invoke("stream-close", {}, {}, controls);
|
|
13440
|
+
} finally {
|
|
13441
|
+
await ((_c2 = (_b2 = self2.channelInputs).return) == null ? void 0 : _c2.call(_b2));
|
|
13442
|
+
self2.channelInputs = void 0;
|
|
13443
|
+
self2.streamProgress = void 0;
|
|
13444
|
+
if (self2.streamProgressId !== void 0)
|
|
13445
|
+
self2.callbackFailures.delete(self2.streamProgressId);
|
|
13446
|
+
self2.streamProgressId = void 0;
|
|
13447
|
+
}
|
|
13448
|
+
}
|
|
13449
|
+
} else if (self2.pool) {
|
|
13450
|
+
await self2.invoke("stream-options", {}, options, controls);
|
|
13451
|
+
yield* processOnWorkerInBatches(self2.descriptor, prepared(), {
|
|
13452
|
+
...self2.workerOptions(controls),
|
|
13453
|
+
inputOwnership: "transfer",
|
|
13454
|
+
workerInBatches: true
|
|
13455
|
+
});
|
|
13456
|
+
} else {
|
|
13457
|
+
for await (const output of self2.runtime.stream(prepared(), options, self2.runtimeContext(controls))) {
|
|
13458
|
+
(_d2 = controls.signal) == null ? void 0 : _d2.throwIfAborted();
|
|
13459
|
+
yield clonePayload(output, controls.outputOwnership ?? "transfer");
|
|
13460
|
+
}
|
|
13461
|
+
}
|
|
13462
|
+
completed = true;
|
|
13463
|
+
} catch (error) {
|
|
13464
|
+
if (self2.workerChannel) {
|
|
13465
|
+
self2.invalid = true;
|
|
13466
|
+
self2.operationQueue.cancelPending(error);
|
|
13467
|
+
self2.controller.abort(error);
|
|
13468
|
+
await self2.workerChannel.destroy(error);
|
|
13469
|
+
}
|
|
13470
|
+
if (self2.pool) {
|
|
13471
|
+
self2.invalid = true;
|
|
13472
|
+
await self2.pool.destroy(error);
|
|
13473
|
+
}
|
|
13474
|
+
throw error;
|
|
13475
|
+
} finally {
|
|
13476
|
+
if (self2.pool && !completed)
|
|
13477
|
+
self2.invalid = true;
|
|
13478
|
+
if (self2.workerChannel && !completed && !self2.invalid) {
|
|
13479
|
+
const reason = new Error("Worker stream ended before completion");
|
|
13480
|
+
self2.invalid = true;
|
|
13481
|
+
self2.operationQueue.cancelPending(reason);
|
|
13482
|
+
self2.controller.abort(reason);
|
|
13483
|
+
await self2.workerChannel.destroy(reason);
|
|
13484
|
+
}
|
|
13485
|
+
}
|
|
13486
|
+
}, (_a5 = args[0]) == null ? void 0 : _a5.signal);
|
|
13487
|
+
}
|
|
13488
|
+
/** Lifecycle status of this initialized task. */
|
|
13489
|
+
get state() {
|
|
13490
|
+
if (this.invalid)
|
|
13491
|
+
return "invalid";
|
|
13492
|
+
if (this.finalized)
|
|
13493
|
+
return "closed";
|
|
13494
|
+
return this.closed ? "closing" : "ready";
|
|
13495
|
+
}
|
|
13496
|
+
/** Drain accepted work, invoke destroy, and release execution capacity. */
|
|
13497
|
+
close() {
|
|
13498
|
+
if (!this.closing) {
|
|
13499
|
+
this.closed = true;
|
|
13500
|
+
this.closing = (async () => {
|
|
13501
|
+
var _a5, _b2;
|
|
13502
|
+
try {
|
|
13503
|
+
await this.operationQueue.close();
|
|
13504
|
+
if (!this.invalid)
|
|
13505
|
+
await this.invoke("destroy", {}, {});
|
|
13506
|
+
else if (!this.pool && !this.workerChannel)
|
|
13507
|
+
await this.runtime.destroy();
|
|
13508
|
+
} finally {
|
|
13509
|
+
try {
|
|
13510
|
+
await ((_a5 = this.pool) == null ? void 0 : _a5.destroy());
|
|
13511
|
+
await ((_b2 = this.workerChannel) == null ? void 0 : _b2.destroy());
|
|
13512
|
+
} finally {
|
|
13513
|
+
this.finalized = true;
|
|
13514
|
+
this.release();
|
|
13515
|
+
}
|
|
13516
|
+
}
|
|
13517
|
+
})();
|
|
13518
|
+
}
|
|
13519
|
+
return this.closing;
|
|
13520
|
+
}
|
|
13521
|
+
/** Abort work. Local JavaScript must settle before its state can be destroyed. */
|
|
13522
|
+
async terminate(reason = new Error("Task terminated")) {
|
|
13523
|
+
this.operationQueue.cancelPending(reason);
|
|
13524
|
+
this.controller.abort(reason);
|
|
13525
|
+
if (this.workerChannel) {
|
|
13526
|
+
this.invalid = true;
|
|
13527
|
+
await this.workerChannel.destroy(reason);
|
|
13528
|
+
}
|
|
13529
|
+
if (this.pool) {
|
|
13530
|
+
this.invalid = true;
|
|
13531
|
+
await this.pool.destroy(reason);
|
|
13532
|
+
}
|
|
13533
|
+
await Promise.allSettled([...this.streams].map((stop) => stop()));
|
|
13534
|
+
await this.close();
|
|
13535
|
+
}
|
|
13536
|
+
checkCapability(kind) {
|
|
13537
|
+
var _a5;
|
|
13538
|
+
if (this.pool || this.workerChannel ? !((_a5 = this.task.worker) == null ? void 0 : _a5.capabilities[kind]) : !(kind === "atomic" ? this.task.process : this.task.processInBatches)) {
|
|
13539
|
+
throw new Error(`Task has no ${kind} processor for this execution route`);
|
|
13540
|
+
}
|
|
13541
|
+
}
|
|
13542
|
+
controls(controls = {}) {
|
|
13543
|
+
if (controls.outputOwnership && !["copy", "transfer"].includes(controls.outputOwnership))
|
|
13544
|
+
throw new TypeError("Invalid output ownership");
|
|
13545
|
+
return {
|
|
13546
|
+
...controls,
|
|
13547
|
+
signal: controls.signal ? AbortSignal.any([controls.signal, this.controller.signal]) : this.controller.signal
|
|
13548
|
+
};
|
|
13549
|
+
}
|
|
13550
|
+
workerOptions(controls) {
|
|
13551
|
+
return {
|
|
13552
|
+
workerPool: this.pool,
|
|
13553
|
+
workerType: "module",
|
|
13554
|
+
inputOwnership: controls.inputOwnership ?? "copy",
|
|
13555
|
+
outputOwnership: controls.outputOwnership ?? "transfer",
|
|
13556
|
+
signal: controls.signal,
|
|
13557
|
+
onProgress: controls.onProgress,
|
|
13558
|
+
cancellationMode: "terminate"
|
|
13559
|
+
};
|
|
13560
|
+
}
|
|
13561
|
+
async invoke(operation, input, options, controls = {}) {
|
|
13562
|
+
var _a5, _b2, _c2, _d2;
|
|
13563
|
+
if (this.invalid)
|
|
13564
|
+
throw new Error("Initialized task is invalid; initialize a new instance");
|
|
13565
|
+
const prepared = operation === "destroy" ? {} : this.controls(controls);
|
|
13566
|
+
(_a5 = prepared.signal) == null ? void 0 : _a5.throwIfAborted();
|
|
13567
|
+
assertPayload(input);
|
|
13568
|
+
assertNoTransferAlias(input, options, prepared.inputOwnership);
|
|
13569
|
+
const copiedOptions = clonePayload(options);
|
|
13570
|
+
if (this.workerChannel) {
|
|
13571
|
+
const progressId = this.nextProgressId++;
|
|
13572
|
+
const request = {
|
|
13573
|
+
input: clonePayload(input, prepared.inputOwnership),
|
|
13574
|
+
options: copiedOptions,
|
|
13575
|
+
outputOwnership: prepared.outputOwnership ?? "transfer",
|
|
13576
|
+
progressId
|
|
13577
|
+
};
|
|
13578
|
+
if (operation === "stream-open")
|
|
13579
|
+
this.streamProgressId = progressId;
|
|
13580
|
+
this.progressCallbacks.set(progressId, prepared.onProgress);
|
|
13581
|
+
let callbackFailure;
|
|
13582
|
+
try {
|
|
13583
|
+
const result2 = await this.workerChannel.channel.request(operation, request, prepared.signal, getTransferList(request));
|
|
13584
|
+
callbackFailure = this.callbackFailures.get(progressId) ?? (operation.startsWith("stream-") && this.streamProgressId !== void 0 ? this.callbackFailures.get(this.streamProgressId) : void 0);
|
|
13585
|
+
if (callbackFailure)
|
|
13586
|
+
throw callbackFailure.reason;
|
|
13587
|
+
return result2;
|
|
13588
|
+
} catch (reason) {
|
|
13589
|
+
if (operation === "process" && !((_b2 = prepared.signal) == null ? void 0 : _b2.aborted) && (reason instanceof TaskRequestError || callbackFailure))
|
|
13590
|
+
throw reason;
|
|
13591
|
+
this.invalid = true;
|
|
13592
|
+
this.operationQueue.cancelPending(reason);
|
|
13593
|
+
this.controller.abort(reason);
|
|
13594
|
+
await this.workerChannel.destroy(reason);
|
|
13595
|
+
throw reason;
|
|
13596
|
+
} finally {
|
|
13597
|
+
this.progressCallbacks.delete(progressId);
|
|
13598
|
+
if (this.streamProgressId !== progressId)
|
|
13599
|
+
this.callbackFailures.delete(progressId);
|
|
13600
|
+
}
|
|
13601
|
+
}
|
|
13602
|
+
if (this.pool) {
|
|
13603
|
+
try {
|
|
13604
|
+
return await processOnWorker(this.descriptor, { operation, input: clonePayload(input, prepared.inputOwnership), options: copiedOptions }, this.workerOptions({ ...prepared, inputOwnership: "transfer" }));
|
|
13605
|
+
} catch (error) {
|
|
13606
|
+
this.invalid = true;
|
|
13607
|
+
await this.pool.destroy(error);
|
|
13608
|
+
throw error;
|
|
13609
|
+
}
|
|
13610
|
+
}
|
|
13611
|
+
if (operation === "destroy")
|
|
13612
|
+
return this.runtime.destroy();
|
|
13613
|
+
const copied = clonePayload(input, prepared.inputOwnership);
|
|
13614
|
+
const context = this.runtimeContext(prepared);
|
|
13615
|
+
if (operation === "initialize") {
|
|
13616
|
+
const result2 = await this.runtime.initialize(copied, context);
|
|
13617
|
+
(_c2 = prepared.signal) == null ? void 0 : _c2.throwIfAborted();
|
|
13618
|
+
return result2;
|
|
13619
|
+
}
|
|
13620
|
+
const result = await this.runtime.process(copied, copiedOptions, context);
|
|
13621
|
+
(_d2 = prepared.signal) == null ? void 0 : _d2.throwIfAborted();
|
|
13622
|
+
return clonePayload(result, prepared.outputOwnership ?? "transfer");
|
|
13623
|
+
}
|
|
13624
|
+
runtimeContext(prepared) {
|
|
13625
|
+
return {
|
|
13626
|
+
...localContext(prepared),
|
|
13627
|
+
requestHost: async (operation, payload, controls = {}) => {
|
|
13628
|
+
const signal = prepared.signal ?? this.controller.signal;
|
|
13629
|
+
signal.throwIfAborted();
|
|
13630
|
+
const handler = this.initializationControls.onRequest;
|
|
13631
|
+
if (!handler)
|
|
13632
|
+
throw new Error("No host request handler configured");
|
|
13633
|
+
const result = await handler(operation, clonePayload(payload, controls.inputOwnership), signal);
|
|
13634
|
+
signal.throwIfAborted();
|
|
13635
|
+
return structuredClone(result, {
|
|
13636
|
+
transfer: controls.outputOwnership === "transfer" ? getTransferList(result) : []
|
|
13637
|
+
});
|
|
13638
|
+
},
|
|
13639
|
+
emitHost: (operation, payload) => {
|
|
13640
|
+
var _a5, _b2;
|
|
13641
|
+
return (_b2 = (_a5 = this.initializationControls).onEvent) == null ? void 0 : _b2.call(_a5, operation, structuredClone(payload));
|
|
13642
|
+
}
|
|
13643
|
+
};
|
|
13644
|
+
}
|
|
13645
|
+
enqueue(operation) {
|
|
13646
|
+
if (this.closed)
|
|
13647
|
+
return Promise.reject(new Error("Initialized task is closed"));
|
|
13648
|
+
return this.operationQueue.run("exclusive", operation);
|
|
13649
|
+
}
|
|
13650
|
+
serialStream(operation, signal) {
|
|
13651
|
+
const waiting = new AbortController();
|
|
13652
|
+
const queueSignal = AbortSignal.any([waiting.signal, this.controller.signal, signal].filter((value) => Boolean(value)));
|
|
13653
|
+
let started = false;
|
|
13654
|
+
const iterator = this.acquireStream(operation, queueSignal, () => {
|
|
13655
|
+
started = true;
|
|
13656
|
+
});
|
|
13657
|
+
const cancelWaiting = () => {
|
|
13658
|
+
if (!started)
|
|
13659
|
+
waiting.abort(new Error("Stream returned before execution"));
|
|
13660
|
+
};
|
|
13661
|
+
return {
|
|
13662
|
+
[Symbol.asyncIterator]() {
|
|
13663
|
+
return this;
|
|
13664
|
+
},
|
|
13665
|
+
next: () => iterator.next(),
|
|
13666
|
+
return: async () => {
|
|
13667
|
+
cancelWaiting();
|
|
13668
|
+
return iterator.return(void 0);
|
|
13669
|
+
},
|
|
13670
|
+
throw: async (reason) => {
|
|
13671
|
+
cancelWaiting();
|
|
13672
|
+
return iterator.throw(reason);
|
|
13673
|
+
}
|
|
13674
|
+
};
|
|
13675
|
+
}
|
|
13676
|
+
async *acquireStream(operation, signal, onStart) {
|
|
13677
|
+
if (this.closed)
|
|
13678
|
+
throw new Error("Initialized task is closed");
|
|
13679
|
+
let acquire;
|
|
13680
|
+
const acquired = new Promise((resolve) => {
|
|
13681
|
+
acquire = resolve;
|
|
13682
|
+
});
|
|
13683
|
+
let release;
|
|
13684
|
+
const held = new Promise((resolve) => {
|
|
13685
|
+
release = resolve;
|
|
13686
|
+
});
|
|
13687
|
+
const lease = this.operationQueue.run("exclusive", async () => {
|
|
13688
|
+
acquire();
|
|
13689
|
+
await held;
|
|
13690
|
+
}, signal);
|
|
13691
|
+
await Promise.race([acquired, lease]);
|
|
13692
|
+
if (signal.aborted) {
|
|
13693
|
+
release();
|
|
13694
|
+
throw signal.reason;
|
|
13695
|
+
}
|
|
13696
|
+
onStart();
|
|
13697
|
+
const iterator = operation(this)[Symbol.asyncIterator]();
|
|
13698
|
+
let stopping;
|
|
13699
|
+
const stop = () => {
|
|
13700
|
+
stopping ?? (stopping = (async () => {
|
|
13701
|
+
var _a5;
|
|
13702
|
+
try {
|
|
13703
|
+
await ((_a5 = iterator.return) == null ? void 0 : _a5.call(iterator));
|
|
13704
|
+
} finally {
|
|
13705
|
+
this.streams.delete(stop);
|
|
13706
|
+
release();
|
|
13707
|
+
}
|
|
13708
|
+
})());
|
|
13709
|
+
return stopping;
|
|
13710
|
+
};
|
|
13711
|
+
this.streams.add(stop);
|
|
13712
|
+
try {
|
|
13713
|
+
while (true) {
|
|
13714
|
+
this.controller.signal.throwIfAborted();
|
|
13715
|
+
const next = await iterator.next();
|
|
13716
|
+
if (next.done)
|
|
13717
|
+
return;
|
|
13718
|
+
yield next.value;
|
|
13719
|
+
}
|
|
13720
|
+
} finally {
|
|
13721
|
+
await stop();
|
|
13722
|
+
}
|
|
13723
|
+
}
|
|
13724
|
+
};
|
|
13725
|
+
var TaskRunner = class {
|
|
13726
|
+
constructor(options = {}) {
|
|
13727
|
+
this.active = /* @__PURE__ */ new Set();
|
|
13728
|
+
this.count = 0;
|
|
13729
|
+
this.waiters = [];
|
|
13730
|
+
this.closed = false;
|
|
13731
|
+
this.initializing = /* @__PURE__ */ new Set();
|
|
13732
|
+
this.iterations = /* @__PURE__ */ new Set();
|
|
13733
|
+
this.maxConcurrency = options.maxConcurrency ?? 1;
|
|
13734
|
+
if (!Number.isSafeInteger(this.maxConcurrency) || this.maxConcurrency < 1)
|
|
13735
|
+
throw new RangeError("maxConcurrency must be a positive safe integer");
|
|
13736
|
+
}
|
|
13737
|
+
/** Execute synchronous hooks immediately on the calling thread, without queueing. */
|
|
13738
|
+
runTaskSync(task, input, ...args) {
|
|
13739
|
+
if (this.closed)
|
|
13740
|
+
throw new Error("Task runner is closed");
|
|
13741
|
+
if (this.count >= this.maxConcurrency)
|
|
13742
|
+
throw new Error("Task runner has no synchronous capacity");
|
|
13743
|
+
this.count++;
|
|
13744
|
+
try {
|
|
13745
|
+
return runTaskSync(task, input, args[0]);
|
|
13746
|
+
} finally {
|
|
13747
|
+
const waiter = this.waiters.shift();
|
|
13748
|
+
if (waiter)
|
|
13749
|
+
waiter.resolve();
|
|
13750
|
+
else
|
|
13751
|
+
this.count--;
|
|
13752
|
+
}
|
|
13753
|
+
}
|
|
13754
|
+
initializeTask(task, initialization, controls = {}) {
|
|
13755
|
+
const pending2 = this.open(task, initialization, controls);
|
|
13756
|
+
this.initializing.add(pending2);
|
|
13757
|
+
void pending2.then(() => this.initializing.delete(pending2), () => this.initializing.delete(pending2));
|
|
13758
|
+
return pending2;
|
|
13759
|
+
}
|
|
13760
|
+
async runTask(task, input, ...args) {
|
|
13761
|
+
const request = args[0] ?? {};
|
|
13762
|
+
const handle = await this.initializeTask(task, request.initialization ?? {}, {
|
|
13763
|
+
...request,
|
|
13764
|
+
inputOwnership: request.initializationOwnership ?? "copy"
|
|
13765
|
+
});
|
|
13766
|
+
return finish(handle, () => handle.runTask(input, request));
|
|
13767
|
+
}
|
|
13768
|
+
async *runTasks(task, inputs, ...args) {
|
|
13769
|
+
var _a5;
|
|
13770
|
+
const request = args[0] ?? {};
|
|
13771
|
+
if (this.closed)
|
|
13772
|
+
throw new Error("Task runner is closed");
|
|
13773
|
+
if (request.initializationOwnership === "transfer")
|
|
13774
|
+
throw new TypeError("runTasks initialization is a reusable template; use copy or share");
|
|
13775
|
+
const concurrency2 = request.concurrency ?? 1;
|
|
13776
|
+
if (!Number.isSafeInteger(concurrency2) || concurrency2 < 1 || concurrency2 > this.maxConcurrency)
|
|
13777
|
+
throw new RangeError("concurrency must be between 1 and maxConcurrency");
|
|
13778
|
+
const handles = [];
|
|
13779
|
+
const busy = /* @__PURE__ */ new Set();
|
|
13780
|
+
const pending2 = [];
|
|
13781
|
+
const controller = new AbortController();
|
|
13782
|
+
this.iterations.add(controller);
|
|
13783
|
+
const signal = request.signal ? AbortSignal.any([request.signal, controller.signal]) : controller.signal;
|
|
13784
|
+
const iterator = asAsync(inputs, signal)[Symbol.asyncIterator]();
|
|
13785
|
+
let finished2 = false;
|
|
13786
|
+
let reading;
|
|
13787
|
+
try {
|
|
13788
|
+
while (!finished2 || pending2.length) {
|
|
13789
|
+
signal.throwIfAborted();
|
|
13790
|
+
if (!finished2 && !reading && pending2.length < concurrency2) {
|
|
13791
|
+
reading = iterator.next().then((next) => ({ kind: "input", next }));
|
|
13792
|
+
}
|
|
13793
|
+
const event = await Promise.race([
|
|
13794
|
+
...pending2.length ? [pending2[0]] : [],
|
|
13795
|
+
...reading ? [reading] : []
|
|
13796
|
+
]);
|
|
13797
|
+
if (event.kind === "result") {
|
|
13798
|
+
pending2.shift();
|
|
13799
|
+
busy.delete(event.handle);
|
|
13800
|
+
if (event.failed)
|
|
13801
|
+
throw event.error;
|
|
13802
|
+
yield event.value;
|
|
13803
|
+
continue;
|
|
13804
|
+
}
|
|
13805
|
+
reading = void 0;
|
|
13806
|
+
if (event.next.done) {
|
|
13807
|
+
finished2 = true;
|
|
13808
|
+
continue;
|
|
13809
|
+
}
|
|
13810
|
+
let handle = handles.find((candidate) => !busy.has(candidate));
|
|
13811
|
+
if (!handle && (handles.length === 0 || this.count < this.maxConcurrency)) {
|
|
13812
|
+
handle = await this.initializeTask(task, clonePayload(request.initialization ?? {}, request.initializationOwnership), {
|
|
13813
|
+
...request,
|
|
13814
|
+
signal,
|
|
13815
|
+
inputOwnership: request.initializationOwnership ?? "copy"
|
|
13816
|
+
});
|
|
13817
|
+
handles.push(handle);
|
|
13818
|
+
}
|
|
13819
|
+
if (!handle) {
|
|
13820
|
+
const result = await pending2.shift();
|
|
13821
|
+
busy.delete(result.handle);
|
|
13822
|
+
if (result.failed)
|
|
13823
|
+
throw result.error;
|
|
13824
|
+
yield result.value;
|
|
13825
|
+
handle = result.handle;
|
|
13826
|
+
}
|
|
13827
|
+
busy.add(handle);
|
|
13828
|
+
const current = handle;
|
|
13829
|
+
pending2.push(handle.runTask(event.next.value, { ...request, signal }).then((value) => ({ kind: "result", handle: current, value }), (error) => ({ kind: "result", handle: current, failed: true, error })));
|
|
13830
|
+
}
|
|
13831
|
+
} finally {
|
|
13832
|
+
this.iterations.delete(controller);
|
|
13833
|
+
controller.abort(new Error("Task iteration closed"));
|
|
13834
|
+
try {
|
|
13835
|
+
if (reading)
|
|
13836
|
+
await reading.catch(() => {
|
|
13837
|
+
});
|
|
13838
|
+
if (!finished2)
|
|
13839
|
+
await ((_a5 = iterator.return) == null ? void 0 : _a5.call(iterator));
|
|
13840
|
+
} finally {
|
|
13841
|
+
await Promise.all(pending2);
|
|
13842
|
+
await Promise.all(handles.map((handle) => handle.close()));
|
|
13843
|
+
}
|
|
13844
|
+
}
|
|
13845
|
+
}
|
|
13846
|
+
async *runTaskInBatches(task, inputs, ...args) {
|
|
13847
|
+
const request = args[0] ?? {};
|
|
13848
|
+
const handle = await this.initializeTask(task, request.initialization ?? {}, {
|
|
13849
|
+
...request,
|
|
13850
|
+
inputOwnership: request.initializationOwnership ?? "copy"
|
|
13851
|
+
});
|
|
13852
|
+
try {
|
|
13853
|
+
yield* handle.runTaskInBatches(inputs, request);
|
|
13854
|
+
} finally {
|
|
13855
|
+
await handle.close();
|
|
13856
|
+
}
|
|
13857
|
+
}
|
|
13858
|
+
/** Close owned handles and workers. Finish or return active iterators first. */
|
|
13859
|
+
close() {
|
|
13860
|
+
if (!this.closing) {
|
|
13861
|
+
this.closed = true;
|
|
13862
|
+
for (const waiter of this.waiters.splice(0))
|
|
13863
|
+
waiter.reject(new Error("Task runner is closed"));
|
|
13864
|
+
this.closing = (async () => {
|
|
13865
|
+
await Promise.allSettled(this.initializing);
|
|
13866
|
+
const results = await Promise.allSettled([...this.active].map((handle) => handle.close()));
|
|
13867
|
+
const failure = results.find((result) => result.status === "rejected");
|
|
13868
|
+
if ((failure == null ? void 0 : failure.status) === "rejected")
|
|
13869
|
+
throw failure.reason;
|
|
13870
|
+
})();
|
|
13871
|
+
}
|
|
13872
|
+
return this.closing;
|
|
13873
|
+
}
|
|
13874
|
+
async terminate(reason = new Error("Task runner terminated")) {
|
|
13875
|
+
for (const controller of this.iterations)
|
|
13876
|
+
controller.abort(reason);
|
|
13877
|
+
const closing = this.close();
|
|
13878
|
+
await Promise.allSettled([...this.active].map((handle) => handle.terminate(reason)));
|
|
13879
|
+
await closing;
|
|
13880
|
+
}
|
|
13881
|
+
async open(task, initialization, controls) {
|
|
13882
|
+
var _a5;
|
|
13883
|
+
if (this.closed)
|
|
13884
|
+
throw new Error("Task runner is closed");
|
|
13885
|
+
(_a5 = controls.signal) == null ? void 0 : _a5.throwIfAborted();
|
|
13886
|
+
if (this.count >= this.maxConcurrency) {
|
|
13887
|
+
await new Promise((resolve, reject) => {
|
|
13888
|
+
var _a6, _b2;
|
|
13889
|
+
const waiter = {
|
|
13890
|
+
resolve: () => {
|
|
13891
|
+
cleanup();
|
|
13892
|
+
resolve();
|
|
13893
|
+
},
|
|
13894
|
+
reject: (error) => {
|
|
13895
|
+
cleanup();
|
|
13896
|
+
reject(error);
|
|
13897
|
+
}
|
|
13898
|
+
};
|
|
13899
|
+
const abort = () => {
|
|
13900
|
+
var _a7;
|
|
13901
|
+
this.waiters = this.waiters.filter((item) => item !== waiter);
|
|
13902
|
+
waiter.reject((_a7 = controls.signal) == null ? void 0 : _a7.reason);
|
|
13903
|
+
};
|
|
13904
|
+
const cleanup = () => {
|
|
13905
|
+
var _a7;
|
|
13906
|
+
return (_a7 = controls.signal) == null ? void 0 : _a7.removeEventListener("abort", abort);
|
|
13907
|
+
};
|
|
13908
|
+
this.waiters.push(waiter);
|
|
13909
|
+
(_a6 = controls.signal) == null ? void 0 : _a6.addEventListener("abort", abort, { once: true });
|
|
13910
|
+
if ((_b2 = controls.signal) == null ? void 0 : _b2.aborted)
|
|
13911
|
+
abort();
|
|
13912
|
+
});
|
|
13913
|
+
} else
|
|
13914
|
+
this.count++;
|
|
13915
|
+
let handle;
|
|
13916
|
+
let released = false;
|
|
13917
|
+
const release = () => {
|
|
13918
|
+
if (released)
|
|
13919
|
+
return;
|
|
13920
|
+
released = true;
|
|
13921
|
+
if (handle)
|
|
13922
|
+
this.active.delete(handle);
|
|
13923
|
+
const waiter = this.waiters.shift();
|
|
13924
|
+
if (waiter)
|
|
13925
|
+
waiter.resolve();
|
|
13926
|
+
else
|
|
13927
|
+
this.count--;
|
|
13928
|
+
};
|
|
13929
|
+
try {
|
|
13930
|
+
if (this.closed)
|
|
13931
|
+
throw new Error("Task runner is closed");
|
|
13932
|
+
handle = new InitializedTask(task, release, controls);
|
|
13933
|
+
this.active.add(handle);
|
|
13934
|
+
await handle.initialize(initialization, controls);
|
|
13935
|
+
return handle;
|
|
13936
|
+
} catch (error) {
|
|
13937
|
+
release();
|
|
13938
|
+
throw error;
|
|
13939
|
+
}
|
|
13940
|
+
}
|
|
13941
|
+
};
|
|
13942
|
+
async function finish(handle, operation) {
|
|
13943
|
+
let result;
|
|
13944
|
+
try {
|
|
13945
|
+
result = await operation();
|
|
13946
|
+
} catch (error) {
|
|
13947
|
+
try {
|
|
13948
|
+
await handle.close();
|
|
13949
|
+
} catch (cleanup) {
|
|
13950
|
+
throw new AggregateError([error, cleanup], "Task processing and destruction failed");
|
|
13951
|
+
}
|
|
13952
|
+
throw error;
|
|
13953
|
+
}
|
|
13954
|
+
await handle.close();
|
|
13955
|
+
return result;
|
|
13956
|
+
}
|
|
13957
|
+
async function* asAsync(inputs, signal) {
|
|
13958
|
+
var _a5, _b2;
|
|
13959
|
+
const iterator = Symbol.asyncIterator in inputs ? inputs[Symbol.asyncIterator]() : inputs[Symbol.iterator]();
|
|
13960
|
+
let done = false;
|
|
13961
|
+
let blocked = false;
|
|
13962
|
+
try {
|
|
13963
|
+
while (true) {
|
|
13964
|
+
const next = await new Promise((resolve, reject) => {
|
|
13965
|
+
const cleanup = () => signal == null ? void 0 : signal.removeEventListener("abort", abort);
|
|
13966
|
+
const abort = () => {
|
|
13967
|
+
cleanup();
|
|
13968
|
+
reject(signal == null ? void 0 : signal.reason);
|
|
13969
|
+
};
|
|
13970
|
+
signal == null ? void 0 : signal.addEventListener("abort", abort, { once: true });
|
|
13971
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
13972
|
+
abort();
|
|
13973
|
+
return;
|
|
13974
|
+
}
|
|
13975
|
+
try {
|
|
13976
|
+
blocked = true;
|
|
13977
|
+
Promise.resolve(iterator.next()).then((value) => {
|
|
13978
|
+
blocked = false;
|
|
13979
|
+
cleanup();
|
|
13980
|
+
resolve(value);
|
|
13981
|
+
}, (error) => {
|
|
13982
|
+
blocked = false;
|
|
13983
|
+
cleanup();
|
|
13984
|
+
reject(error);
|
|
13985
|
+
});
|
|
13986
|
+
} catch (error) {
|
|
13987
|
+
blocked = false;
|
|
13988
|
+
cleanup();
|
|
13989
|
+
reject(error);
|
|
13990
|
+
}
|
|
13991
|
+
});
|
|
13992
|
+
if (next.done) {
|
|
13993
|
+
done = true;
|
|
13994
|
+
return;
|
|
13995
|
+
}
|
|
13996
|
+
yield next.value;
|
|
13997
|
+
}
|
|
13998
|
+
} finally {
|
|
13999
|
+
if (!done) {
|
|
14000
|
+
if (blocked) {
|
|
14001
|
+
try {
|
|
14002
|
+
void Promise.resolve((_a5 = iterator.return) == null ? void 0 : _a5.call(iterator)).catch(() => {
|
|
14003
|
+
});
|
|
14004
|
+
} catch {
|
|
14005
|
+
}
|
|
14006
|
+
} else {
|
|
14007
|
+
await ((_b2 = iterator.return) == null ? void 0 : _b2.call(iterator));
|
|
14008
|
+
}
|
|
14009
|
+
}
|
|
14010
|
+
}
|
|
14011
|
+
}
|
|
14012
|
+
function assertNoTransferAlias(input, options, ownership) {
|
|
14013
|
+
if (ownership === "transfer") {
|
|
14014
|
+
const metadata2 = new Set(getTransferList(options));
|
|
14015
|
+
if (getTransferList(input).some((buffer2) => metadata2.has(buffer2))) {
|
|
14016
|
+
throw new Error("Transferred input aliases reusable options; use inputOwnership: copy");
|
|
14017
|
+
}
|
|
14018
|
+
}
|
|
14019
|
+
}
|
|
14020
|
+
|
|
14021
|
+
// ../core/src/worker-utils/lib/worker-api/get-worker-url.ts
|
|
14022
|
+
var warnedWorkerVersionFallbacks2 = /* @__PURE__ */ new Set();
|
|
14023
|
+
function getCustomWorkerURL2(worker, options = {}) {
|
|
14024
|
+
var _a5, _b2;
|
|
14025
|
+
const workerFile = isBrowser2 ? worker.workerFile || `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
|
|
14026
|
+
let url = getConfiguredWorkerURL2(worker, options);
|
|
14027
|
+
const workerType = options._workerType || ((_a5 = options == null ? void 0 : options.core) == null ? void 0 : _a5._workerType);
|
|
14028
|
+
if (!url && workerType === "test") {
|
|
14029
|
+
if (isBrowser2) {
|
|
14030
|
+
url = `modules/${worker.module}/dist/${workerFile}`;
|
|
14031
|
+
} else {
|
|
14032
|
+
const workerSourceDirectory = worker.module === "core" && ((_b2 = worker.workerNode) == null ? void 0 : _b2.startsWith("worker-utils/")) ? "worker-utils/workers" : "workers";
|
|
14033
|
+
const workerSourceNode = worker.workerSourceNode || `${workerSourceDirectory}/${worker.id}-worker-node.ts`;
|
|
14034
|
+
url = `modules/${worker.module}/src/${workerSourceNode}`;
|
|
14035
|
+
}
|
|
14036
|
+
}
|
|
14037
|
+
return url || null;
|
|
14038
|
+
}
|
|
14039
|
+
function getConfiguredWorkerURL2(worker, options = {}) {
|
|
14040
|
+
const workerOptions = options[worker.id] || {};
|
|
14041
|
+
return workerOptions.workerUrl || (worker.id === "compression" ? options.workerUrl : null) || null;
|
|
14042
|
+
}
|
|
14043
|
+
function getWorkerURL2(worker, options = {}) {
|
|
14044
|
+
const customWorkerUrl = getCustomWorkerURL2(worker, options);
|
|
14045
|
+
const descriptorWorkerUrl = typeof worker.worker === "string" ? worker.worker : null;
|
|
14046
|
+
const url = customWorkerUrl || descriptorWorkerUrl || getDefaultWorkerURL2(worker, true);
|
|
14047
|
+
assert(url);
|
|
14048
|
+
return url;
|
|
14049
|
+
}
|
|
14050
|
+
function getDefaultWorkerURL2(worker, warn = false) {
|
|
14051
|
+
const workerFile = isBrowser2 ? worker.workerFile || `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
|
|
14052
|
+
let version2 = worker.version;
|
|
14053
|
+
if (version2 === "latest") {
|
|
14054
|
+
version2 = NPM_TAG;
|
|
14055
|
+
}
|
|
14056
|
+
const versionTag = version2 ? `@${version2}` : "";
|
|
14057
|
+
const url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;
|
|
14058
|
+
if (warn) {
|
|
14059
|
+
warnIfUsingNpmTagFallback2(worker, url);
|
|
14060
|
+
}
|
|
14061
|
+
return url;
|
|
14062
|
+
}
|
|
14063
|
+
function warnIfUsingNpmTagFallback2(worker, url) {
|
|
14064
|
+
if (worker.version !== "latest") {
|
|
14065
|
+
return;
|
|
14066
|
+
}
|
|
14067
|
+
const workerId = `${worker.module}:${worker.id}`;
|
|
14068
|
+
if (warnedWorkerVersionFallbacks2.has(workerId)) {
|
|
14069
|
+
return;
|
|
14070
|
+
}
|
|
14071
|
+
warnedWorkerVersionFallbacks2.add(workerId);
|
|
14072
|
+
console.warn(
|
|
14073
|
+
`loaders.gl: ${worker.name} loader worker version is "latest" because __VERSION__ was not injected. Fetching ${url} from CDN.`
|
|
14074
|
+
);
|
|
14075
|
+
}
|
|
14076
|
+
|
|
14077
|
+
// ../core/src/worker-utils/lib/worker-api/task-runtime.ts
|
|
14078
|
+
function normalizeTaskProgress(progress) {
|
|
14079
|
+
return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
|
|
14080
|
+
}
|
|
14081
|
+
async function isWorkerThread() {
|
|
14082
|
+
var _a5;
|
|
14083
|
+
if (typeof self !== "undefined" && typeof document === "undefined" && typeof self.postMessage === "function")
|
|
14084
|
+
return true;
|
|
14085
|
+
if (typeof process !== "undefined" && ((_a5 = process.versions) == null ? void 0 : _a5.node)) {
|
|
14086
|
+
const { isMainThread: isMainThread2 } = await Promise.resolve().then(() => (init_worker_threads(), worker_threads_exports));
|
|
14087
|
+
return !isMainThread2;
|
|
14088
|
+
}
|
|
14089
|
+
return false;
|
|
14090
|
+
}
|
|
14091
|
+
var initializeTaskWorker2 = initializeTaskWorker;
|
|
14092
|
+
|
|
14093
|
+
// ../core/src/worker-utils/lib/worker-utils/get-transfer-list.ts
|
|
14094
|
+
function getTransferList2(object2, recursive = true, transfers) {
|
|
14095
|
+
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
14096
|
+
if (!object2) {
|
|
14097
|
+
} else if (isTransferable2(object2)) {
|
|
14098
|
+
transfersSet.add(object2);
|
|
14099
|
+
} else if (isTransferable2(object2.buffer)) {
|
|
14100
|
+
transfersSet.add(object2.buffer);
|
|
14101
|
+
} else if (ArrayBuffer.isView(object2)) {
|
|
14102
|
+
} else if (recursive && typeof object2 === "object") {
|
|
14103
|
+
for (const key in object2) {
|
|
14104
|
+
getTransferList2(object2[key], recursive, transfersSet);
|
|
14105
|
+
}
|
|
14106
|
+
}
|
|
14107
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
14108
|
+
}
|
|
14109
|
+
function isTransferable2(object2) {
|
|
14110
|
+
if (!object2) {
|
|
14111
|
+
return false;
|
|
14112
|
+
}
|
|
14113
|
+
if (object2 instanceof ArrayBuffer) {
|
|
14114
|
+
return true;
|
|
14115
|
+
}
|
|
14116
|
+
if (typeof MessagePort !== "undefined" && object2 instanceof MessagePort) {
|
|
14117
|
+
return true;
|
|
14118
|
+
}
|
|
14119
|
+
if (typeof ImageBitmap !== "undefined" && object2 instanceof ImageBitmap) {
|
|
14120
|
+
return true;
|
|
14121
|
+
}
|
|
14122
|
+
if (typeof OffscreenCanvas !== "undefined" && object2 instanceof OffscreenCanvas) {
|
|
14123
|
+
return true;
|
|
14124
|
+
}
|
|
14125
|
+
return false;
|
|
14126
|
+
}
|
|
14127
|
+
function getTransferListForWriter2(object2) {
|
|
14128
|
+
if (object2 === null) {
|
|
14129
|
+
return {};
|
|
14130
|
+
}
|
|
14131
|
+
const clone2 = Object.assign({}, object2);
|
|
14132
|
+
Object.keys(clone2).forEach((key) => {
|
|
14133
|
+
if (object2[key] !== null && typeof object2[key] === "object" && !ArrayBuffer.isView(object2[key]) && !(object2[key] instanceof Array)) {
|
|
14134
|
+
clone2[key] = getTransferListForWriter2(object2[key]);
|
|
14135
|
+
} else if (typeof clone2[key] === "function" || clone2[key] instanceof RegExp) {
|
|
14136
|
+
clone2[key] = {};
|
|
14137
|
+
} else {
|
|
14138
|
+
clone2[key] = object2[key];
|
|
14139
|
+
}
|
|
14140
|
+
});
|
|
14141
|
+
return clone2;
|
|
14142
|
+
}
|
|
14143
|
+
|
|
14144
|
+
// ../core/src/worker-utils/lib/worker-api/process-on-worker.ts
|
|
14145
|
+
var runners = /* @__PURE__ */ new WeakMap();
|
|
14146
|
+
var activeRunners = /* @__PURE__ */ new Set();
|
|
14147
|
+
var moduleWorkerUrls = /* @__PURE__ */ new Map();
|
|
14148
|
+
function canProcessOnWorker2(worker, options = {}) {
|
|
14149
|
+
const supported = isBrowser2 ? typeof Worker !== "undefined" : Boolean(options._nodeWorkers);
|
|
14150
|
+
return Boolean(
|
|
14151
|
+
supported && options.worker && (worker.worker || worker.loadWorker || getConfiguredWorkerURL2(worker, options))
|
|
14152
|
+
);
|
|
14153
|
+
}
|
|
14154
|
+
async function* processOnWorkerInBatches2(worker, input, options = {}, context = {}, jobContext = {}) {
|
|
14155
|
+
var _a5;
|
|
14156
|
+
const taskInput = wrapInput(input);
|
|
14157
|
+
let session;
|
|
14158
|
+
try {
|
|
14159
|
+
session = await openSession(worker, options, context, jobContext);
|
|
14160
|
+
for await (const result of session.handle.runTaskInBatches(taskInput, {
|
|
14161
|
+
...getControls(options),
|
|
14162
|
+
options: getParserOptions(options)
|
|
14163
|
+
}))
|
|
14164
|
+
yield result.value;
|
|
14165
|
+
} finally {
|
|
14166
|
+
const closingInput = (_a5 = taskInput.return) == null ? void 0 : _a5.call(taskInput);
|
|
14167
|
+
void (closingInput == null ? void 0 : closingInput.catch(() => {
|
|
14168
|
+
}));
|
|
14169
|
+
await (session == null ? void 0 : session.close());
|
|
14170
|
+
}
|
|
14171
|
+
}
|
|
14172
|
+
function getTask(worker, options) {
|
|
14173
|
+
var _a5;
|
|
14174
|
+
if (options.source || ((_a5 = options.core) == null ? void 0 : _a5.source))
|
|
14175
|
+
throw new Error(
|
|
14176
|
+
"Inline legacy worker source is unsupported; use a TaskRunner worker URL or factory"
|
|
14177
|
+
);
|
|
14178
|
+
const create = !getCustomWorkerURL2(worker, options) && isBrowser2 ? worker.loadWorker : void 0;
|
|
14179
|
+
const url = getWorkerURL2(worker, options);
|
|
14180
|
+
return {
|
|
14181
|
+
id: `${worker.module}:${worker.id}`,
|
|
14182
|
+
initialize: (state) => state,
|
|
14183
|
+
worker: {
|
|
14184
|
+
...create ? { create: () => create() ?? createModuleWorker(url) } : { url },
|
|
14185
|
+
capabilities: { atomic: true, streaming: true }
|
|
14186
|
+
}
|
|
14187
|
+
};
|
|
14188
|
+
}
|
|
14189
|
+
function getControls(options) {
|
|
14190
|
+
return {
|
|
14191
|
+
execution: "worker",
|
|
14192
|
+
signal: options.signal,
|
|
14193
|
+
inputOwnership: options.inputOwnership ?? "transfer",
|
|
14194
|
+
outputOwnership: options.outputOwnership ?? "transfer",
|
|
14195
|
+
onProgress: options.onProgress ? (progress) => {
|
|
14196
|
+
var _a5;
|
|
14197
|
+
return (_a5 = options.onProgress) == null ? void 0 : _a5.call(options, normalizeTaskProgress(progress));
|
|
14198
|
+
} : void 0
|
|
14199
|
+
};
|
|
14200
|
+
}
|
|
14201
|
+
function getParserOptions(options) {
|
|
14202
|
+
const { signal, onProgress, ...parserOptions } = options;
|
|
14203
|
+
return getTransferListForWriter2(parserOptions);
|
|
14204
|
+
}
|
|
14205
|
+
async function openSession(worker, options, context, jobContext) {
|
|
14206
|
+
var _a5, _b2;
|
|
14207
|
+
(_a5 = options.signal) == null ? void 0 : _a5.throwIfAborted();
|
|
14208
|
+
const task = getTask(worker, options);
|
|
14209
|
+
let state = runners.get(worker);
|
|
14210
|
+
if (!state) {
|
|
14211
|
+
state = {
|
|
14212
|
+
runner: new TaskRunner({
|
|
14213
|
+
maxConcurrency: isMobile ? options.maxMobileConcurrency ?? 1 : options.maxConcurrency ?? 3
|
|
14214
|
+
}),
|
|
14215
|
+
requests: 0
|
|
14216
|
+
};
|
|
14217
|
+
runners.set(worker, state);
|
|
14218
|
+
}
|
|
14219
|
+
const runnerState = state;
|
|
14220
|
+
const channel = context.process ? new MessageChannel() : void 0;
|
|
14221
|
+
const callbackController = new AbortController();
|
|
14222
|
+
let channelClosed = false;
|
|
14223
|
+
const abortCallbacks = () => {
|
|
14224
|
+
var _a6;
|
|
14225
|
+
return callbackController.abort((_a6 = options.signal) == null ? void 0 : _a6.reason);
|
|
14226
|
+
};
|
|
14227
|
+
(_b2 = options.signal) == null ? void 0 : _b2.addEventListener("abort", abortCallbacks, { once: true });
|
|
14228
|
+
const closeChannel = () => {
|
|
14229
|
+
var _a6;
|
|
14230
|
+
channelClosed = true;
|
|
14231
|
+
(_a6 = options.signal) == null ? void 0 : _a6.removeEventListener("abort", abortCallbacks);
|
|
14232
|
+
callbackController.abort();
|
|
14233
|
+
channel == null ? void 0 : channel.port1.close();
|
|
14234
|
+
channel == null ? void 0 : channel.port2.close();
|
|
14235
|
+
};
|
|
14236
|
+
if (channel) {
|
|
14237
|
+
channel.port1.onmessage = async ({ data }) => {
|
|
14238
|
+
try {
|
|
14239
|
+
const value = await context.process(
|
|
14240
|
+
data.input,
|
|
14241
|
+
data.options,
|
|
14242
|
+
{
|
|
14243
|
+
signal: callbackController.signal,
|
|
14244
|
+
throwIfAborted: () => callbackController.signal.throwIfAborted()
|
|
14245
|
+
},
|
|
14246
|
+
data.context
|
|
14247
|
+
);
|
|
14248
|
+
if (!channelClosed && !callbackController.signal.aborted)
|
|
14249
|
+
channel.port1.postMessage({ identifier: data.identifier, value }, getTransferList2(value));
|
|
14250
|
+
} catch (error) {
|
|
14251
|
+
if (channelClosed || callbackController.signal.aborted) return;
|
|
14252
|
+
channel.port1.postMessage({
|
|
14253
|
+
identifier: data.identifier,
|
|
14254
|
+
error: {
|
|
14255
|
+
name: error instanceof Error ? error.name : "Error",
|
|
14256
|
+
message: error instanceof Error ? error.message : String(error)
|
|
14257
|
+
}
|
|
14258
|
+
});
|
|
14259
|
+
}
|
|
14260
|
+
};
|
|
14261
|
+
channel.port1.start();
|
|
14262
|
+
}
|
|
14263
|
+
runnerState.requests++;
|
|
14264
|
+
activeRunners.add(runnerState);
|
|
14265
|
+
let released = false;
|
|
14266
|
+
const releaseRunner = () => {
|
|
14267
|
+
if (released) return;
|
|
14268
|
+
released = true;
|
|
14269
|
+
runnerState.requests--;
|
|
14270
|
+
if (!runnerState.requests) activeRunners.delete(runnerState);
|
|
14271
|
+
};
|
|
14272
|
+
let handle;
|
|
14273
|
+
try {
|
|
14274
|
+
handle = await runnerState.runner.initializeTask(
|
|
14275
|
+
task,
|
|
14276
|
+
{
|
|
14277
|
+
context: structuredClone(jobContext),
|
|
14278
|
+
...channel ? { port: channel.port2 } : {}
|
|
14279
|
+
},
|
|
14280
|
+
// The callback port is setup state, independent of the caller's payload ownership.
|
|
14281
|
+
{ ...getControls(options), inputOwnership: "transfer" }
|
|
14282
|
+
);
|
|
14283
|
+
} catch (error) {
|
|
14284
|
+
releaseRunner();
|
|
14285
|
+
closeChannel();
|
|
14286
|
+
throw error;
|
|
14287
|
+
}
|
|
14288
|
+
return {
|
|
14289
|
+
handle,
|
|
14290
|
+
/** Releases the worker and callback channel on success, failure, and early stream return. */
|
|
14291
|
+
async close() {
|
|
14292
|
+
try {
|
|
14293
|
+
await handle.close();
|
|
14294
|
+
} finally {
|
|
14295
|
+
closeChannel();
|
|
14296
|
+
releaseRunner();
|
|
14297
|
+
}
|
|
14298
|
+
}
|
|
14299
|
+
};
|
|
14300
|
+
}
|
|
14301
|
+
function wrapInput(input) {
|
|
14302
|
+
const iterator = Symbol.asyncIterator in input ? input[Symbol.asyncIterator]() : input[Symbol.iterator]();
|
|
14303
|
+
let inputClosed = false;
|
|
14304
|
+
return {
|
|
14305
|
+
[Symbol.asyncIterator]() {
|
|
14306
|
+
return this;
|
|
14307
|
+
},
|
|
14308
|
+
async next() {
|
|
14309
|
+
if (inputClosed) return { done: true, value: void 0 };
|
|
14310
|
+
const next = await iterator.next();
|
|
14311
|
+
if (next.done || inputClosed) {
|
|
14312
|
+
inputClosed = true;
|
|
14313
|
+
return { done: true, value: void 0 };
|
|
14314
|
+
}
|
|
14315
|
+
return { done: false, value: { value: next.value } };
|
|
14316
|
+
},
|
|
14317
|
+
async return() {
|
|
14318
|
+
var _a5;
|
|
14319
|
+
if (!inputClosed) {
|
|
14320
|
+
inputClosed = true;
|
|
14321
|
+
await ((_a5 = iterator.return) == null ? void 0 : _a5.call(iterator));
|
|
14322
|
+
}
|
|
14323
|
+
return { done: true, value: void 0 };
|
|
14324
|
+
}
|
|
14325
|
+
};
|
|
14326
|
+
}
|
|
14327
|
+
function createModuleWorker(url) {
|
|
14328
|
+
var _a5;
|
|
14329
|
+
const resolved = new URL(url, ((_a5 = globalThis.document) == null ? void 0 : _a5.baseURI) ?? globalThis.location.href);
|
|
14330
|
+
let workerUrl = resolved.href;
|
|
14331
|
+
if (/^https?:$/.test(resolved.protocol) && resolved.origin !== globalThis.location.origin) {
|
|
14332
|
+
let shimUrl = moduleWorkerUrls.get(resolved.href);
|
|
14333
|
+
if (!shimUrl) {
|
|
14334
|
+
shimUrl = URL.createObjectURL(
|
|
14335
|
+
new Blob([`import ${JSON.stringify(resolved.href)};`], { type: "application/javascript" })
|
|
14336
|
+
);
|
|
14337
|
+
moduleWorkerUrls.set(resolved.href, shimUrl);
|
|
14338
|
+
}
|
|
14339
|
+
workerUrl = shimUrl;
|
|
14340
|
+
}
|
|
14341
|
+
return new Worker(workerUrl, { type: "module" });
|
|
14342
|
+
}
|
|
14343
|
+
|
|
14344
|
+
// ../core/src/worker-utils/lib/worker-api/create-worker.ts
|
|
14345
|
+
async function createWorker2(process2, processInBatches) {
|
|
14346
|
+
if (!await isWorkerThread()) return;
|
|
14347
|
+
await initializeTaskWorker2(createWorkerTask(process2, processInBatches));
|
|
14348
|
+
}
|
|
14349
|
+
function createWorkerTask(process2, processInBatches) {
|
|
14350
|
+
return {
|
|
14351
|
+
id: "loaders.gl",
|
|
14352
|
+
initialize: (state) => state,
|
|
14353
|
+
destroy: (state) => {
|
|
14354
|
+
var _a5;
|
|
14355
|
+
return (_a5 = state.port) == null ? void 0 : _a5.close();
|
|
14356
|
+
},
|
|
14357
|
+
process: async ({ value }, options, context) => {
|
|
14358
|
+
if (!process2) throw new Error("Worker does not support atomic processing");
|
|
14359
|
+
return { value: await process2(value, options, createContext(context), context.state.context) };
|
|
14360
|
+
},
|
|
14361
|
+
...processInBatches ? {
|
|
14362
|
+
processInBatches: async function* (inputs, options, context) {
|
|
14363
|
+
async function* values() {
|
|
14364
|
+
for await (const input of inputs) yield input.value;
|
|
14365
|
+
}
|
|
14366
|
+
for await (const value of processInBatches(
|
|
14367
|
+
values(),
|
|
14368
|
+
options,
|
|
14369
|
+
createContext(context),
|
|
14370
|
+
context.state.context
|
|
14371
|
+
)) {
|
|
14372
|
+
yield { value };
|
|
14373
|
+
}
|
|
14374
|
+
}
|
|
14375
|
+
} : {}
|
|
14376
|
+
};
|
|
14377
|
+
}
|
|
14378
|
+
function createContext(context) {
|
|
14379
|
+
let requestIdentifier = 0;
|
|
14380
|
+
const port = context.state.port;
|
|
14381
|
+
return {
|
|
14382
|
+
signal: context.signal,
|
|
14383
|
+
throwIfAborted: () => context.throwIfAborted(),
|
|
14384
|
+
reportProgress: (progress) => context.reportProgress(normalizeTaskProgress(progress)),
|
|
14385
|
+
process: port ? (input, options = {}, jobContext = {}) => {
|
|
14386
|
+
context.throwIfAborted();
|
|
14387
|
+
const identifier = ++requestIdentifier;
|
|
14388
|
+
return new Promise((resolve, reject) => {
|
|
14389
|
+
const onMessage2 = (event) => {
|
|
14390
|
+
if (event.data.identifier !== identifier) return;
|
|
14391
|
+
cleanup();
|
|
14392
|
+
if (event.data.error) {
|
|
14393
|
+
const error = new Error(event.data.error.message);
|
|
14394
|
+
error.name = event.data.error.name;
|
|
14395
|
+
reject(error);
|
|
14396
|
+
} else resolve(event.data.value);
|
|
14397
|
+
};
|
|
14398
|
+
const onAbort = () => {
|
|
14399
|
+
cleanup();
|
|
14400
|
+
reject(context.signal.reason);
|
|
14401
|
+
};
|
|
14402
|
+
const cleanup = () => {
|
|
14403
|
+
port.removeEventListener("message", onMessage2);
|
|
14404
|
+
context.signal.removeEventListener("abort", onAbort);
|
|
14405
|
+
};
|
|
14406
|
+
port.addEventListener("message", onMessage2);
|
|
14407
|
+
context.signal.addEventListener("abort", onAbort, { once: true });
|
|
14408
|
+
port.start();
|
|
14409
|
+
try {
|
|
14410
|
+
const request = { identifier, input, options, context: jobContext };
|
|
14411
|
+
port.postMessage(request, getTransferList2(request));
|
|
14412
|
+
} catch (error) {
|
|
14413
|
+
cleanup();
|
|
14414
|
+
reject(error);
|
|
14415
|
+
}
|
|
14416
|
+
});
|
|
14417
|
+
} : void 0
|
|
14418
|
+
};
|
|
14419
|
+
}
|
|
14420
|
+
|
|
14421
|
+
// ../core/src/worker-utils/lib/library-utils/library-utils.ts
|
|
14422
|
+
var loadLibraryPromises = {};
|
|
14423
|
+
function extractLoadLibraryOptions(options = {}) {
|
|
14424
|
+
var _a5, _b2;
|
|
14425
|
+
const useLocalLibraries = options.useLocalLibraries ?? ((_a5 = options.core) == null ? void 0 : _a5.useLocalLibraries);
|
|
14426
|
+
const CDN = getCDNOption(options.CDN, (_b2 = options.core) == null ? void 0 : _b2.CDN);
|
|
14427
|
+
const modules = options.modules;
|
|
14428
|
+
return {
|
|
14429
|
+
...useLocalLibraries !== void 0 ? { useLocalLibraries } : {},
|
|
14430
|
+
...CDN !== void 0 ? { CDN } : {},
|
|
14431
|
+
...modules !== void 0 ? { modules } : {}
|
|
14432
|
+
};
|
|
14433
|
+
}
|
|
14434
|
+
function getCDNOption(cdn, coreCDN) {
|
|
14435
|
+
if (typeof cdn === "string" || cdn === null) {
|
|
14436
|
+
return cdn;
|
|
14437
|
+
}
|
|
14438
|
+
if (typeof coreCDN === "string" || coreCDN === null) {
|
|
14439
|
+
return coreCDN;
|
|
14440
|
+
}
|
|
14441
|
+
return void 0;
|
|
14442
|
+
}
|
|
14443
|
+
async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null, moduleLibraryName = null) {
|
|
14444
|
+
var _a5, _b2;
|
|
14445
|
+
let moduleLibraryUrl = libraryUrl;
|
|
14446
|
+
if (moduleName) {
|
|
14447
|
+
const requestedLibraryName = libraryName || libraryUrl;
|
|
14448
|
+
const injectedLibrary = (_a5 = options.modules) == null ? void 0 : _a5[requestedLibraryName];
|
|
14449
|
+
if (injectedLibrary !== void 0 && typeof injectedLibrary !== "string") {
|
|
14450
|
+
return injectedLibrary;
|
|
14451
|
+
}
|
|
14452
|
+
libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName);
|
|
14453
|
+
const hasLibraryOverride = typeof injectedLibrary === "string";
|
|
14454
|
+
moduleLibraryUrl = moduleLibraryName && (!hasLibraryOverride || typeof ((_b2 = options.modules) == null ? void 0 : _b2[moduleLibraryName]) === "string") ? getLibraryUrl(moduleLibraryName, moduleName, options, moduleLibraryName) : libraryUrl;
|
|
14455
|
+
}
|
|
14456
|
+
const cacheKey = getLibraryCacheKey(libraryUrl, moduleLibraryUrl, isWorker);
|
|
14457
|
+
loadLibraryPromises[cacheKey] = // eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
14458
|
+
loadLibraryPromises[cacheKey] || loadLibraryFromFile(libraryUrl, moduleLibraryUrl);
|
|
14459
|
+
return await loadLibraryPromises[cacheKey];
|
|
14460
|
+
}
|
|
14461
|
+
function getLibraryCacheKey(libraryUrl, moduleLibraryUrl, worker) {
|
|
14462
|
+
return worker ? JSON.stringify([libraryUrl, moduleLibraryUrl]) : libraryUrl;
|
|
14463
|
+
}
|
|
14464
|
+
function getLibraryUrl(library, moduleName, options = {}, libraryName = null) {
|
|
14465
|
+
if (options == null ? void 0 : options.core) {
|
|
14466
|
+
throw new Error("loadLibrary: options.core must be pre-normalized");
|
|
14467
|
+
}
|
|
14468
|
+
libraryName = libraryName || library;
|
|
14469
|
+
const modules = options.modules || {};
|
|
14470
|
+
if (typeof modules[libraryName] === "string") {
|
|
14471
|
+
return modules[libraryName];
|
|
14472
|
+
}
|
|
14473
|
+
if (!options.useLocalLibraries && library.startsWith("http")) {
|
|
14474
|
+
return library;
|
|
14475
|
+
}
|
|
14476
|
+
if (!isBrowser2) {
|
|
14477
|
+
return `modules/${moduleName}/dist/libs/${libraryName}`;
|
|
14478
|
+
}
|
|
14479
|
+
if (options.CDN) {
|
|
14480
|
+
if (typeof options.CDN !== "string") {
|
|
14481
|
+
throw new Error("loadLibrary: options.CDN must be a string or null");
|
|
14482
|
+
}
|
|
14483
|
+
assert(options.CDN.startsWith("http"));
|
|
14484
|
+
return `${options.CDN}/${moduleName}@${VERSION}/dist/libs/${libraryName}`;
|
|
14485
|
+
}
|
|
14486
|
+
if (isWorker) {
|
|
14487
|
+
return libraryName.endsWith(".mjs") ? `./libs/${libraryName}` : `../src/libs/${libraryName}`;
|
|
14488
|
+
}
|
|
14489
|
+
return `modules/${moduleName}/src/libs/${libraryName}`;
|
|
14490
|
+
}
|
|
14491
|
+
async function loadLibraryFromFile(libraryUrl, moduleLibraryUrl) {
|
|
14492
|
+
if (libraryUrl.endsWith("wasm")) {
|
|
14493
|
+
return await loadAsArrayBuffer(libraryUrl);
|
|
14494
|
+
}
|
|
14495
|
+
if (!isBrowser2) {
|
|
14496
|
+
const { requireFromFile: requireFromFile2 } = globalThis.loaders || {};
|
|
14497
|
+
try {
|
|
14498
|
+
const result = await (requireFromFile2 == null ? void 0 : requireFromFile2(libraryUrl));
|
|
14499
|
+
if (result || !libraryUrl.includes("/dist/libs/")) {
|
|
14500
|
+
return result;
|
|
14501
|
+
}
|
|
14502
|
+
return await (requireFromFile2 == null ? void 0 : requireFromFile2(libraryUrl.replace("/dist/libs/", "/src/libs/")));
|
|
14503
|
+
} catch (error) {
|
|
14504
|
+
if (libraryUrl.includes("/dist/libs/")) {
|
|
14505
|
+
try {
|
|
14506
|
+
return await (requireFromFile2 == null ? void 0 : requireFromFile2(libraryUrl.replace("/dist/libs/", "/src/libs/")));
|
|
14507
|
+
} catch {
|
|
14508
|
+
}
|
|
14509
|
+
}
|
|
14510
|
+
console.error(error);
|
|
14511
|
+
return null;
|
|
14512
|
+
}
|
|
14513
|
+
}
|
|
14514
|
+
if (isWorker) {
|
|
14515
|
+
return loadLibraryInWorker(libraryUrl, moduleLibraryUrl);
|
|
14516
|
+
}
|
|
14517
|
+
const scriptSource = await loadAsText(libraryUrl);
|
|
14518
|
+
return loadLibraryFromString(scriptSource, libraryUrl);
|
|
14519
|
+
}
|
|
14520
|
+
async function loadLibraryInWorker(libraryUrl, moduleLibraryUrl = libraryUrl) {
|
|
14521
|
+
try {
|
|
14522
|
+
importScripts();
|
|
14523
|
+
} catch {
|
|
14524
|
+
const moduleUrl2 = new URL(moduleLibraryUrl, globalThis.location.href).href;
|
|
14525
|
+
const library = await import(
|
|
14526
|
+
/* @vite-ignore */
|
|
14527
|
+
moduleUrl2
|
|
14528
|
+
);
|
|
14529
|
+
return library.default ?? library;
|
|
14530
|
+
}
|
|
14531
|
+
return importScripts(libraryUrl);
|
|
14532
|
+
}
|
|
14533
|
+
function loadLibraryFromString(scriptSource, id) {
|
|
14534
|
+
const script = document.createElement("script");
|
|
14535
|
+
script.id = id;
|
|
14536
|
+
try {
|
|
14537
|
+
script.appendChild(document.createTextNode(scriptSource));
|
|
14538
|
+
} catch (_e2) {
|
|
14539
|
+
script.text = scriptSource;
|
|
14540
|
+
}
|
|
14541
|
+
document.body.appendChild(script);
|
|
14542
|
+
return null;
|
|
14543
|
+
}
|
|
14544
|
+
async function loadAsArrayBuffer(url) {
|
|
14545
|
+
const { readFileAsArrayBuffer: readFileAsArrayBuffer2 } = globalThis.loaders || {};
|
|
14546
|
+
if (isBrowser2 || !readFileAsArrayBuffer2 || url.startsWith("http")) {
|
|
14547
|
+
const response = await fetch(url);
|
|
14548
|
+
return await response.arrayBuffer();
|
|
14549
|
+
}
|
|
14550
|
+
try {
|
|
14551
|
+
return await readFileAsArrayBuffer2(url);
|
|
14552
|
+
} catch {
|
|
14553
|
+
if (url.includes("/dist/libs/")) {
|
|
14554
|
+
return await readFileAsArrayBuffer2(url.replace("/dist/libs/", "/src/libs/"));
|
|
14555
|
+
}
|
|
14556
|
+
throw new Error(`Failed to load ArrayBuffer from ${url}`);
|
|
14557
|
+
}
|
|
14558
|
+
}
|
|
14559
|
+
async function loadAsText(url) {
|
|
14560
|
+
const { readFileAsText: readFileAsText2 } = globalThis.loaders || {};
|
|
14561
|
+
if (isBrowser2 || !readFileAsText2 || url.startsWith("http")) {
|
|
14562
|
+
const response = await fetch(url);
|
|
14563
|
+
return await response.text();
|
|
14564
|
+
}
|
|
14565
|
+
try {
|
|
14566
|
+
return await readFileAsText2(url);
|
|
14567
|
+
} catch {
|
|
14568
|
+
if (url.includes("/dist/libs/")) {
|
|
14569
|
+
return await readFileAsText2(url.replace("/dist/libs/", "/src/libs/"));
|
|
14570
|
+
}
|
|
14571
|
+
throw new Error(`Failed to load text from ${url}`);
|
|
14572
|
+
}
|
|
14573
|
+
}
|
|
14574
|
+
|
|
12672
14575
|
// ../core/src/loader-utils/lib/env-utils/globals.ts
|
|
12673
14576
|
var globals3 = {
|
|
12674
14577
|
self: typeof self !== "undefined" && self,
|
|
@@ -12720,15 +14623,15 @@ function initializeWasmModule(initialize, extractExports) {
|
|
|
12720
14623
|
// ../core/src/loader-utils/lib/worker-loader-utils/encode-with-worker.ts
|
|
12721
14624
|
function canEncodeWithWorker(writer, options) {
|
|
12722
14625
|
var _a5, _b2;
|
|
12723
|
-
if (!WorkerFarm.isSupported()) {
|
|
12724
|
-
return false;
|
|
12725
|
-
}
|
|
12726
14626
|
const nodeWorkers = (options == null ? void 0 : options._nodeWorkers) ?? ((_a5 = options == null ? void 0 : options.core) == null ? void 0 : _a5._nodeWorkers);
|
|
12727
14627
|
const useWorkers = (options == null ? void 0 : options.worker) ?? ((_b2 = options == null ? void 0 : options.core) == null ? void 0 : _b2.worker);
|
|
12728
14628
|
if (!isBrowser4 && !nodeWorkers) {
|
|
12729
14629
|
return false;
|
|
12730
14630
|
}
|
|
12731
|
-
return
|
|
14631
|
+
return canProcessOnWorker2(
|
|
14632
|
+
{ ...writer, options: writer.options || {} },
|
|
14633
|
+
{ worker: Boolean(useWorkers), _nodeWorkers: Boolean(nodeWorkers) }
|
|
14634
|
+
);
|
|
12732
14635
|
}
|
|
12733
14636
|
|
|
12734
14637
|
// ../../node_modules/@math.gl/core/dist/types/float16.js
|
|
@@ -19371,11 +21274,11 @@ var VariableWidthBuilder = class extends Builder {
|
|
|
19371
21274
|
this._offsets = new OffsetsBufferBuilder(opts.type);
|
|
19372
21275
|
}
|
|
19373
21276
|
setValue(index2, value) {
|
|
19374
|
-
const
|
|
19375
|
-
const current =
|
|
21277
|
+
const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
|
|
21278
|
+
const current = pending2.get(index2);
|
|
19376
21279
|
current && (this._pendingLength -= current.length);
|
|
19377
21280
|
this._pendingLength += value instanceof MapRow ? value[kKeys].length : value.length;
|
|
19378
|
-
|
|
21281
|
+
pending2.set(index2, value);
|
|
19379
21282
|
}
|
|
19380
21283
|
setValid(index2, isValid) {
|
|
19381
21284
|
if (!super.setValid(index2, isValid)) {
|
|
@@ -19398,12 +21301,12 @@ var VariableWidthBuilder = class extends Builder {
|
|
|
19398
21301
|
return super.finish();
|
|
19399
21302
|
}
|
|
19400
21303
|
_flush() {
|
|
19401
|
-
const
|
|
21304
|
+
const pending2 = this._pending;
|
|
19402
21305
|
const pendingLength = this._pendingLength;
|
|
19403
21306
|
this._pendingLength = 0;
|
|
19404
21307
|
this._pending = void 0;
|
|
19405
|
-
if (
|
|
19406
|
-
this._flushPending(
|
|
21308
|
+
if (pending2 && pending2.size > 0) {
|
|
21309
|
+
this._flushPending(pending2, pendingLength);
|
|
19407
21310
|
}
|
|
19408
21311
|
return this;
|
|
19409
21312
|
}
|
|
@@ -21821,11 +23724,11 @@ var BinaryBuilder = class extends VariableWidthBuilder {
|
|
|
21821
23724
|
setValue(index2, value) {
|
|
21822
23725
|
return super.setValue(index2, toUint8Array2(value));
|
|
21823
23726
|
}
|
|
21824
|
-
_flushPending(
|
|
23727
|
+
_flushPending(pending2, pendingLength) {
|
|
21825
23728
|
const offsets = this._offsets;
|
|
21826
23729
|
const data = this._values.reserve(pendingLength).buffer;
|
|
21827
23730
|
let offset = 0;
|
|
21828
|
-
for (const [index2, value] of
|
|
23731
|
+
for (const [index2, value] of pending2) {
|
|
21829
23732
|
if (value === void 0) {
|
|
21830
23733
|
offsets.set(index2, 0);
|
|
21831
23734
|
} else {
|
|
@@ -21854,11 +23757,11 @@ var LargeBinaryBuilder = class extends VariableWidthBuilder {
|
|
|
21854
23757
|
setValue(index2, value) {
|
|
21855
23758
|
return super.setValue(index2, toUint8Array2(value));
|
|
21856
23759
|
}
|
|
21857
|
-
_flushPending(
|
|
23760
|
+
_flushPending(pending2, pendingLength) {
|
|
21858
23761
|
const offsets = this._offsets;
|
|
21859
23762
|
const data = this._values.reserve(pendingLength).buffer;
|
|
21860
23763
|
let offset = 0;
|
|
21861
|
-
for (const [index2, value] of
|
|
23764
|
+
for (const [index2, value] of pending2) {
|
|
21862
23765
|
if (value === void 0) {
|
|
21863
23766
|
offsets.set(index2, BigInt(0));
|
|
21864
23767
|
} else {
|
|
@@ -22089,10 +23992,10 @@ var ListBuilder = class extends VariableWidthBuilder {
|
|
|
22089
23992
|
this.type = new List2(new Field2(name, child.type, true));
|
|
22090
23993
|
return this.numChildren - 1;
|
|
22091
23994
|
}
|
|
22092
|
-
_flushPending(
|
|
23995
|
+
_flushPending(pending2) {
|
|
22093
23996
|
const offsets = this._offsets;
|
|
22094
23997
|
const [child] = this.children;
|
|
22095
|
-
for (const [index2, value] of
|
|
23998
|
+
for (const [index2, value] of pending2) {
|
|
22096
23999
|
if (typeof value === "undefined") {
|
|
22097
24000
|
offsets.set(index2, 0);
|
|
22098
24001
|
} else {
|
|
@@ -22121,10 +24024,10 @@ var LargeListBuilder = class extends VariableWidthBuilder {
|
|
|
22121
24024
|
this.type = new LargeList2(new Field2(name, child.type, true));
|
|
22122
24025
|
return this.numChildren - 1;
|
|
22123
24026
|
}
|
|
22124
|
-
_flushPending(
|
|
24027
|
+
_flushPending(pending2) {
|
|
22125
24028
|
const offsets = this._offsets;
|
|
22126
24029
|
const [child] = this.children;
|
|
22127
|
-
for (const [index2, value] of
|
|
24030
|
+
for (const [index2, value] of pending2) {
|
|
22128
24031
|
if (typeof value === "undefined") {
|
|
22129
24032
|
offsets.set(index2, BigInt(0));
|
|
22130
24033
|
} else {
|
|
@@ -22146,11 +24049,11 @@ var MapBuilder = class extends VariableWidthBuilder {
|
|
|
22146
24049
|
}
|
|
22147
24050
|
setValue(index2, value) {
|
|
22148
24051
|
const row = value instanceof Map ? value : new Map(Object.entries(value));
|
|
22149
|
-
const
|
|
22150
|
-
const current =
|
|
24052
|
+
const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
|
|
24053
|
+
const current = pending2.get(index2);
|
|
22151
24054
|
current && (this._pendingLength -= current.size);
|
|
22152
24055
|
this._pendingLength += row.size;
|
|
22153
|
-
|
|
24056
|
+
pending2.set(index2, row);
|
|
22154
24057
|
}
|
|
22155
24058
|
addChild(child, name = `${this.numChildren}`) {
|
|
22156
24059
|
if (this.numChildren > 0) {
|
|
@@ -22160,10 +24063,10 @@ var MapBuilder = class extends VariableWidthBuilder {
|
|
|
22160
24063
|
this.type = new Map_(new Field2(name, child.type, true), this.type.keysSorted);
|
|
22161
24064
|
return this.numChildren - 1;
|
|
22162
24065
|
}
|
|
22163
|
-
_flushPending(
|
|
24066
|
+
_flushPending(pending2) {
|
|
22164
24067
|
const offsets = this._offsets;
|
|
22165
24068
|
const [child] = this.children;
|
|
22166
|
-
for (const [index2, value] of
|
|
24069
|
+
for (const [index2, value] of pending2) {
|
|
22167
24070
|
if (value === void 0) {
|
|
22168
24071
|
offsets.set(index2, 0);
|
|
22169
24072
|
} else {
|
|
@@ -22326,7 +24229,7 @@ var Utf8Builder = class extends VariableWidthBuilder {
|
|
|
22326
24229
|
return super.setValue(index2, encodeUtf8(value));
|
|
22327
24230
|
}
|
|
22328
24231
|
// @ts-ignore
|
|
22329
|
-
_flushPending(
|
|
24232
|
+
_flushPending(pending2, pendingLength) {
|
|
22330
24233
|
}
|
|
22331
24234
|
};
|
|
22332
24235
|
Utf8Builder.prototype._flushPending = BinaryBuilder.prototype._flushPending;
|
|
@@ -22348,7 +24251,7 @@ var LargeUtf8Builder = class extends VariableWidthBuilder {
|
|
|
22348
24251
|
return super.setValue(index2, encodeUtf8(value));
|
|
22349
24252
|
}
|
|
22350
24253
|
// @ts-ignore
|
|
22351
|
-
_flushPending(
|
|
24254
|
+
_flushPending(pending2, pendingLength) {
|
|
22352
24255
|
}
|
|
22353
24256
|
};
|
|
22354
24257
|
LargeUtf8Builder.prototype._flushPending = LargeBinaryBuilder.prototype._flushPending;
|
|
@@ -27361,7 +29264,7 @@ function getLibraryCacheKey2(type, options) {
|
|
|
27361
29264
|
}
|
|
27362
29265
|
|
|
27363
29266
|
// src/draco/lib/utils/version.ts
|
|
27364
|
-
var VERSION3 = true ? "5.0.0-beta.
|
|
29267
|
+
var VERSION3 = true ? "5.0.0-beta.5" : "latest";
|
|
27365
29268
|
|
|
27366
29269
|
// src/draco/draco-format.ts
|
|
27367
29270
|
var DracoFormat = {
|
|
@@ -27428,7 +29331,7 @@ function encodeDracoInBatches(data, options = {}) {
|
|
|
27428
29331
|
const normalizedData = normalizeDracoInputBatches(data);
|
|
27429
29332
|
if (canEncodeWithWorker(DracoWriterWorker, options)) {
|
|
27430
29333
|
const { onProgress: _onProgress, ...workerOptions } = options;
|
|
27431
|
-
return
|
|
29334
|
+
return processOnWorkerInBatches2(
|
|
27432
29335
|
DracoWriterWorker,
|
|
27433
29336
|
normalizedData,
|
|
27434
29337
|
workerOptions
|
|
@@ -27494,7 +29397,7 @@ function isDracoBuilderMesh(data) {
|
|
|
27494
29397
|
}
|
|
27495
29398
|
|
|
27496
29399
|
// src/draco/workers/draco-writer-worker-node.ts
|
|
27497
|
-
|
|
29400
|
+
createWorker2(
|
|
27498
29401
|
async (input, options) => (await encodeDraco(input, options)).data,
|
|
27499
29402
|
encodeDracoInBatchesLocally
|
|
27500
29403
|
);
|