@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
|
@@ -1,14 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(() => {
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __esm = (fn, res, err) => function __init() {
|
|
6
|
+
if (err) throw err[0];
|
|
7
|
+
try {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
} catch (e) {
|
|
10
|
+
throw err = [e], e;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
4
13
|
var __export = (target, all) => {
|
|
5
14
|
for (var name in all)
|
|
6
15
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
16
|
};
|
|
8
17
|
|
|
18
|
+
// ../core/src/worker-utils/lib/node/worker_threads-browser.ts
|
|
19
|
+
var worker_threads_browser_exports = {};
|
|
20
|
+
__export(worker_threads_browser_exports, {
|
|
21
|
+
NodeWorker: () => NodeWorker2,
|
|
22
|
+
parentPort: () => parentPort2
|
|
23
|
+
});
|
|
24
|
+
var NodeWorker2, parentPort2;
|
|
25
|
+
var init_worker_threads_browser = __esm({
|
|
26
|
+
"../core/src/worker-utils/lib/node/worker_threads-browser.ts"() {
|
|
27
|
+
"use strict";
|
|
28
|
+
NodeWorker2 = class {
|
|
29
|
+
/** Restores the native worker constructor when this browser shim is embedded in a Node bundle. */
|
|
30
|
+
constructor(...arguments_) {
|
|
31
|
+
const runtimeProcess = globalThis.process;
|
|
32
|
+
const WorkerConstructor = runtimeProcess?.getBuiltinModule?.("node:worker_threads").Worker;
|
|
33
|
+
if (WorkerConstructor) {
|
|
34
|
+
return new WorkerConstructor(...arguments_);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** No-op browser fallback matching the native Worker API. */
|
|
38
|
+
terminate() {
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
parentPort2 = null;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// ../core/src/constants/index.ts
|
|
46
|
+
var LOADERS_GL_FIXTURE_BRANCH = "master";
|
|
47
|
+
var LOADERS_GL_RAW_FIXTURE_URL = `https://raw.githubusercontent.com/visgl/loaders.gl/${LOADERS_GL_FIXTURE_BRANCH}/`;
|
|
48
|
+
var LOADERS_GL_REDIRECTING_FIXTURE_URL = `https://github.com/visgl/loaders.gl/raw/${LOADERS_GL_FIXTURE_BRANCH}/`;
|
|
49
|
+
var NPM_TAG = "beta";
|
|
50
|
+
|
|
9
51
|
// ../core/src/worker-utils/lib/env-utils/version.ts
|
|
10
52
|
function getVersion() {
|
|
11
|
-
const version = false ? NPM_TAG : "5.0.0-beta.
|
|
53
|
+
const version = false ? NPM_TAG : "5.0.0-beta.5";
|
|
12
54
|
globalThis._loadersgl_ = globalThis._loadersgl_ || {};
|
|
13
55
|
globalThis._loadersgl_.version ||= version;
|
|
14
56
|
return version;
|
|
@@ -42,23 +84,23 @@
|
|
|
42
84
|
var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
43
85
|
var nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
44
86
|
|
|
45
|
-
// ../../node_modules/@math.gl/
|
|
46
|
-
var
|
|
87
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/npm-tag.js
|
|
88
|
+
var NPM_TAG2 = "latest";
|
|
47
89
|
|
|
48
|
-
// ../../node_modules/@math.gl/
|
|
90
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/env-utils/version.js
|
|
49
91
|
function getVersion2() {
|
|
50
|
-
return false ?
|
|
92
|
+
return false ? NPM_TAG2 : "5.0.0-beta.5";
|
|
51
93
|
}
|
|
52
94
|
var VERSION2 = getVersion2();
|
|
53
95
|
|
|
54
|
-
// ../../node_modules/@math.gl/
|
|
96
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/env-utils/assert.js
|
|
55
97
|
function assert2(condition, message) {
|
|
56
98
|
if (!condition) {
|
|
57
99
|
throw new Error(message || "loaders.gl assertion failed.");
|
|
58
100
|
}
|
|
59
101
|
}
|
|
60
102
|
|
|
61
|
-
// ../../node_modules/@math.gl/
|
|
103
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/env-utils/globals.js
|
|
62
104
|
var globals2 = {
|
|
63
105
|
self: typeof self !== "undefined" && self,
|
|
64
106
|
window: typeof window !== "undefined" && window,
|
|
@@ -77,7 +119,7 @@
|
|
|
77
119
|
var matches2 = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
78
120
|
var nodeVersion2 = matches2 && parseFloat(matches2[1]) || 0;
|
|
79
121
|
|
|
80
|
-
// ../../node_modules/@math.gl/
|
|
122
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-job.js
|
|
81
123
|
var WorkerJob = class {
|
|
82
124
|
constructor(jobName, workerThread) {
|
|
83
125
|
this.isRunning = true;
|
|
@@ -194,7 +236,7 @@
|
|
|
194
236
|
return error;
|
|
195
237
|
}
|
|
196
238
|
|
|
197
|
-
// ../../node_modules/@math.gl/
|
|
239
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/node/worker_threads-browser.js
|
|
198
240
|
var NodeWorker = class {
|
|
199
241
|
/** Restores the native worker constructor when this browser shim is embedded in a Node bundle. */
|
|
200
242
|
constructor(...arguments_) {
|
|
@@ -208,14 +250,23 @@
|
|
|
208
250
|
terminate() {
|
|
209
251
|
}
|
|
210
252
|
};
|
|
211
|
-
var parentPort = null;
|
|
253
|
+
var parentPort = globalThis.process?.getBuiltinModule?.("node:worker_threads")?.parentPort ?? null;
|
|
212
254
|
|
|
213
|
-
// ../../node_modules/@math.gl/
|
|
255
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-utils/get-loadable-worker-url.js
|
|
214
256
|
var workerURLCache = /* @__PURE__ */ new Map();
|
|
215
257
|
function getLoadableWorkerURL(props) {
|
|
216
258
|
assert2(props.source && !props.url || !props.source && props.url);
|
|
217
|
-
if (props.url && props.workerType === "module")
|
|
259
|
+
if (props.url && props.workerType === "module") {
|
|
260
|
+
const baseUrl = globalThis.document?.baseURI ?? globalThis.location?.href;
|
|
261
|
+
if (!baseUrl)
|
|
262
|
+
return props.url;
|
|
263
|
+
const resolved = new URL(props.url, baseUrl);
|
|
264
|
+
const origin = globalThis.location?.origin;
|
|
265
|
+
if (/^https?:$/.test(resolved.protocol) && resolved.origin !== origin) {
|
|
266
|
+
return getLoadableWorkerURLFromSource(`import ${JSON.stringify(resolved.href)};`);
|
|
267
|
+
}
|
|
218
268
|
return props.url;
|
|
269
|
+
}
|
|
219
270
|
let workerURL = workerURLCache.get(props.source || props.url);
|
|
220
271
|
if (!workerURL) {
|
|
221
272
|
if (props.url) {
|
|
@@ -250,7 +301,7 @@
|
|
|
250
301
|
}`;
|
|
251
302
|
}
|
|
252
303
|
|
|
253
|
-
// ../../node_modules/@math.gl/
|
|
304
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-utils/get-transfer-list.js
|
|
254
305
|
function getTransferList(object, recursive = true, transfers) {
|
|
255
306
|
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
256
307
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -263,6 +314,9 @@
|
|
|
263
314
|
else if (ArrayBuffer.isView(value)) {
|
|
264
315
|
if (isTransferable(value.buffer))
|
|
265
316
|
transfersSet.add(value.buffer);
|
|
317
|
+
} else if (recursive && typeof MessageChannel !== "undefined" && value instanceof MessageChannel) {
|
|
318
|
+
visit(value.port1);
|
|
319
|
+
visit(value.port2);
|
|
266
320
|
} else if (recursive && value instanceof Map) {
|
|
267
321
|
for (const [key, item] of value) {
|
|
268
322
|
visit(key);
|
|
@@ -331,7 +385,7 @@
|
|
|
331
385
|
return object === null ? {} : clone(object);
|
|
332
386
|
}
|
|
333
387
|
|
|
334
|
-
// ../../node_modules/@math.gl/
|
|
388
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-thread.js
|
|
335
389
|
var NOOP = () => {
|
|
336
390
|
};
|
|
337
391
|
var WorkerThread = class {
|
|
@@ -367,7 +421,7 @@
|
|
|
367
421
|
if (this.terminated)
|
|
368
422
|
return this.termination ?? Promise.resolve();
|
|
369
423
|
this.terminated = true;
|
|
370
|
-
this.termination = Promise.resolve(this.worker.terminate()).then(() => void 0);
|
|
424
|
+
this.termination = Promise.resolve(this.worker.terminate()).then(() => void 0).finally(() => this.releaseModuleWorkerURL());
|
|
371
425
|
void this.termination.catch(() => void 0);
|
|
372
426
|
return this.termination;
|
|
373
427
|
}
|
|
@@ -417,9 +471,9 @@
|
|
|
417
471
|
_createBrowserWorker() {
|
|
418
472
|
if (this.loadWorker) {
|
|
419
473
|
try {
|
|
420
|
-
const
|
|
421
|
-
if (
|
|
422
|
-
return this._initializeBrowserWorker(
|
|
474
|
+
const worker = this.loadWorker();
|
|
475
|
+
if (worker) {
|
|
476
|
+
return this._initializeBrowserWorker(worker);
|
|
423
477
|
}
|
|
424
478
|
} catch (error) {
|
|
425
479
|
if (!this.source && !this.url && !this.getUrl) {
|
|
@@ -433,8 +487,22 @@
|
|
|
433
487
|
url,
|
|
434
488
|
workerType: this.workerType
|
|
435
489
|
});
|
|
436
|
-
|
|
437
|
-
|
|
490
|
+
if (this.workerType === "module" && url && this._loadableURL !== url && this._loadableURL.startsWith("blob:"))
|
|
491
|
+
this.ownedModuleWorkerURL = this._loadableURL;
|
|
492
|
+
try {
|
|
493
|
+
const worker = new Worker(this._loadableURL, { name: this.name, type: this.workerType });
|
|
494
|
+
return this._initializeBrowserWorker(worker);
|
|
495
|
+
} catch (error) {
|
|
496
|
+
this.releaseModuleWorkerURL();
|
|
497
|
+
throw error;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
/** Releases only the module shim owned by this worker, never caller-owned blob URLs. */
|
|
501
|
+
releaseModuleWorkerURL() {
|
|
502
|
+
if (this.ownedModuleWorkerURL) {
|
|
503
|
+
URL.revokeObjectURL(this.ownedModuleWorkerURL);
|
|
504
|
+
this.ownedModuleWorkerURL = void 0;
|
|
505
|
+
}
|
|
438
506
|
}
|
|
439
507
|
/** Attaches protocol handlers to a browser worker. */
|
|
440
508
|
_initializeBrowserWorker(worker) {
|
|
@@ -498,7 +566,7 @@
|
|
|
498
566
|
}
|
|
499
567
|
};
|
|
500
568
|
|
|
501
|
-
// ../../node_modules/@math.gl/
|
|
569
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-pool.js
|
|
502
570
|
var WorkerPool = class {
|
|
503
571
|
/** Snapshot; byte figures describe input buffers, not total heap memory. */
|
|
504
572
|
get stats() {
|
|
@@ -1024,7 +1092,7 @@
|
|
|
1024
1092
|
}
|
|
1025
1093
|
};
|
|
1026
1094
|
|
|
1027
|
-
// ../../node_modules/@math.gl/
|
|
1095
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-farm.js
|
|
1028
1096
|
var DEFAULT_PROPS = {
|
|
1029
1097
|
maxQueuedJobs: Infinity,
|
|
1030
1098
|
maxPendingAdmissions: 128,
|
|
@@ -1145,7 +1213,7 @@
|
|
|
1145
1213
|
return loadWorkerId;
|
|
1146
1214
|
}
|
|
1147
1215
|
|
|
1148
|
-
// ../../node_modules/@math.gl/
|
|
1216
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-body.js
|
|
1149
1217
|
async function getParentPort() {
|
|
1150
1218
|
return parentPort;
|
|
1151
1219
|
}
|
|
@@ -1161,16 +1229,16 @@
|
|
|
1161
1229
|
*/
|
|
1162
1230
|
static set onmessage(onMessage2) {
|
|
1163
1231
|
async function handleMessage(message) {
|
|
1164
|
-
const
|
|
1165
|
-
const { type, payload } =
|
|
1232
|
+
const parentPort3 = await getParentPort();
|
|
1233
|
+
const { type, payload } = parentPort3 ? message : message.data;
|
|
1166
1234
|
onMessage2(type, payload);
|
|
1167
1235
|
}
|
|
1168
|
-
getParentPort().then((
|
|
1169
|
-
if (
|
|
1170
|
-
|
|
1236
|
+
getParentPort().then((parentPort3) => {
|
|
1237
|
+
if (parentPort3) {
|
|
1238
|
+
parentPort3.on("message", (message) => {
|
|
1171
1239
|
handleMessage(message);
|
|
1172
1240
|
});
|
|
1173
|
-
|
|
1241
|
+
parentPort3.on("exit", () => console.debug("Node worker closing"));
|
|
1174
1242
|
} else {
|
|
1175
1243
|
globalThis.onmessage = handleMessage;
|
|
1176
1244
|
}
|
|
@@ -1188,9 +1256,9 @@
|
|
|
1188
1256
|
};
|
|
1189
1257
|
onMessageWrapperMap.set(onMessage2, onMessageWrapper);
|
|
1190
1258
|
}
|
|
1191
|
-
const
|
|
1192
|
-
if (
|
|
1193
|
-
|
|
1259
|
+
const parentPort3 = await getParentPort();
|
|
1260
|
+
if (parentPort3) {
|
|
1261
|
+
parentPort3.on("message", onMessageWrapper);
|
|
1194
1262
|
} else {
|
|
1195
1263
|
globalThis.addEventListener("message", onMessageWrapper);
|
|
1196
1264
|
}
|
|
@@ -1201,9 +1269,9 @@
|
|
|
1201
1269
|
if (!onMessageWrapper) {
|
|
1202
1270
|
return;
|
|
1203
1271
|
}
|
|
1204
|
-
const
|
|
1205
|
-
if (
|
|
1206
|
-
|
|
1272
|
+
const parentPort3 = await getParentPort();
|
|
1273
|
+
if (parentPort3) {
|
|
1274
|
+
parentPort3.off("message", onMessageWrapper);
|
|
1207
1275
|
} else {
|
|
1208
1276
|
globalThis.removeEventListener("message", onMessageWrapper);
|
|
1209
1277
|
}
|
|
@@ -1213,12 +1281,12 @@
|
|
|
1213
1281
|
* @param type
|
|
1214
1282
|
* @param payload
|
|
1215
1283
|
*/
|
|
1216
|
-
static async postMessage(type, payload) {
|
|
1284
|
+
static async postMessage(type, payload, copy = false) {
|
|
1217
1285
|
const data = { source: "loaders.gl", type, payload };
|
|
1218
|
-
const transferList = getTransferList(payload);
|
|
1219
|
-
const
|
|
1220
|
-
if (
|
|
1221
|
-
|
|
1286
|
+
const transferList = copy ? [] : getTransferList(payload);
|
|
1287
|
+
const parentPort3 = await getParentPort();
|
|
1288
|
+
if (parentPort3) {
|
|
1289
|
+
parentPort3.postMessage(data, transferList);
|
|
1222
1290
|
} else {
|
|
1223
1291
|
globalThis.postMessage(data, transferList);
|
|
1224
1292
|
}
|
|
@@ -1232,7 +1300,7 @@
|
|
|
1232
1300
|
return messageData && typeof messageData.source === "string" && messageData.source.startsWith("loaders.gl") ? messageData : null;
|
|
1233
1301
|
}
|
|
1234
1302
|
|
|
1235
|
-
// ../../node_modules/@math.gl/
|
|
1303
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/async-queue/async-queue.js
|
|
1236
1304
|
var AsyncQueue = class {
|
|
1237
1305
|
constructor() {
|
|
1238
1306
|
this._values = [];
|
|
@@ -1299,7 +1367,7 @@
|
|
|
1299
1367
|
}
|
|
1300
1368
|
};
|
|
1301
1369
|
|
|
1302
|
-
// ../../node_modules/@math.gl/
|
|
1370
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/get-worker-url.js
|
|
1303
1371
|
var warnedWorkerVersionFallbacks = /* @__PURE__ */ new Set();
|
|
1304
1372
|
function getWorkerName(worker) {
|
|
1305
1373
|
const warning = worker.version !== VERSION2 ? ` (worker-utils@${VERSION2})` : "";
|
|
@@ -1313,7 +1381,7 @@
|
|
|
1313
1381
|
if (isBrowser2) {
|
|
1314
1382
|
url = `modules/${worker.module}/dist/${workerFile}`;
|
|
1315
1383
|
} else {
|
|
1316
|
-
const workerSourceDirectory = worker.module === "
|
|
1384
|
+
const workerSourceDirectory = worker.module === "tasks" && worker.workerNode?.startsWith("worker-utils/") ? "worker-utils/workers" : "workers";
|
|
1317
1385
|
const workerSourceNode = worker.workerSourceNode || `${workerSourceDirectory}/${worker.id}-worker-node.ts`;
|
|
1318
1386
|
url = `modules/${worker.module}/src/${workerSourceNode}`;
|
|
1319
1387
|
}
|
|
@@ -1335,7 +1403,7 @@
|
|
|
1335
1403
|
const workerFile = isBrowser2 ? worker.workerFile || `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
|
|
1336
1404
|
let version = worker.version;
|
|
1337
1405
|
if (version === "latest") {
|
|
1338
|
-
version =
|
|
1406
|
+
version = NPM_TAG2;
|
|
1339
1407
|
}
|
|
1340
1408
|
const versionTag = version ? `@${version}` : "";
|
|
1341
1409
|
const packageName = worker.packageName || `@loaders.gl/${worker.module}`;
|
|
@@ -1357,7 +1425,7 @@
|
|
|
1357
1425
|
console.warn(`loaders.gl: ${worker.name} loader worker version is "latest" because __VERSION__ was not injected. Fetching ${url} from CDN.`);
|
|
1358
1426
|
}
|
|
1359
1427
|
|
|
1360
|
-
// ../../node_modules/@math.gl/
|
|
1428
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/shared-state.js
|
|
1361
1429
|
function getWorkerCapabilities() {
|
|
1362
1430
|
const isolated = typeof globalThis.crossOriginIsolated === "boolean" ? globalThis.crossOriginIsolated : void 0;
|
|
1363
1431
|
const capabilities = {
|
|
@@ -1440,7 +1508,7 @@
|
|
|
1440
1508
|
return options;
|
|
1441
1509
|
}
|
|
1442
1510
|
|
|
1443
|
-
// ../../node_modules/@math.gl/
|
|
1511
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-utils/get-input-byte-length.js
|
|
1444
1512
|
function getInputByteLength(input) {
|
|
1445
1513
|
const seen = /* @__PURE__ */ new Set();
|
|
1446
1514
|
let bytes = 0;
|
|
@@ -1469,8 +1537,62 @@
|
|
|
1469
1537
|
return bytes;
|
|
1470
1538
|
}
|
|
1471
1539
|
|
|
1472
|
-
// ../../node_modules/@math.gl/
|
|
1540
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/validate-output-ownership.js
|
|
1541
|
+
function validateOutputOwnership(ownership) {
|
|
1542
|
+
if (ownership !== void 0 && ownership !== "copy" && ownership !== "transfer") {
|
|
1543
|
+
throw new Error("Invalid worker output ownership");
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/process-on-worker.js
|
|
1548
|
+
async function processOnWorker(worker, data, options = {}, context = {}, jobContext = {}) {
|
|
1549
|
+
validateOutputOwnership(options.outputOwnership);
|
|
1550
|
+
if (options.inputOwnership !== void 0 && !["copy", "transfer", "share"].includes(options.inputOwnership))
|
|
1551
|
+
throw new Error("Invalid worker input ownership");
|
|
1552
|
+
options = prepareSharedState(options);
|
|
1553
|
+
throwIfAborted(options.signal);
|
|
1554
|
+
validateSharedInput(options, [data, serializableOptions(options), jobContext]);
|
|
1555
|
+
const name = getWorkerName(worker);
|
|
1556
|
+
const workerPool = options.workerPool ?? WorkerFarm.getWorkerFarm(options).getWorkerPool(getWorkerPoolTarget(worker, options, name));
|
|
1557
|
+
const jobName = options.jobName || worker.name;
|
|
1558
|
+
const job = await workerPool.startJob(
|
|
1559
|
+
jobName,
|
|
1560
|
+
// eslint-disable-next-line
|
|
1561
|
+
onMessage.bind(null, context, options),
|
|
1562
|
+
void 0,
|
|
1563
|
+
options.signal,
|
|
1564
|
+
{
|
|
1565
|
+
inputBytes: getInputByteLength([data, budgetOptions(options), jobContext]),
|
|
1566
|
+
priority: options.priority,
|
|
1567
|
+
admission: options.admission,
|
|
1568
|
+
sharedState: options.sharedState ? new SharedWorkerState(options.sharedState) : void 0,
|
|
1569
|
+
cancellationMode: options.cancellationMode,
|
|
1570
|
+
cancellationTimeout: options.cancellationTimeout
|
|
1571
|
+
}
|
|
1572
|
+
);
|
|
1573
|
+
try {
|
|
1574
|
+
if (options.signal?.aborted && !job.isCancelled)
|
|
1575
|
+
job.abort(getAbortReason(options.signal));
|
|
1576
|
+
const workerOptions = serializableOptions(options);
|
|
1577
|
+
const transferableOptions = getTransferListForWriter(workerOptions);
|
|
1578
|
+
const transferableContext = getTransferListForWriter(jobContext);
|
|
1579
|
+
if (job.isRunning) {
|
|
1580
|
+
job.postMessage("process", {
|
|
1581
|
+
input: data,
|
|
1582
|
+
options: transferableOptions,
|
|
1583
|
+
context: transferableContext
|
|
1584
|
+
}, options.inputOwnership === "copy" || options.inputOwnership === "share" ? [] : void 0);
|
|
1585
|
+
}
|
|
1586
|
+
const result = await job.result;
|
|
1587
|
+
return result.result;
|
|
1588
|
+
} catch (error) {
|
|
1589
|
+
if (!job.isCancelled)
|
|
1590
|
+
job.abort(error);
|
|
1591
|
+
throw error;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1473
1594
|
function processOnWorkerInBatches(worker, input, options = {}, context = {}, jobContext = {}) {
|
|
1595
|
+
validateOutputOwnership(options.outputOwnership);
|
|
1474
1596
|
if (options.inputOwnership !== void 0 && !["copy", "transfer", "share"].includes(options.inputOwnership))
|
|
1475
1597
|
throw new Error("Invalid worker input ownership");
|
|
1476
1598
|
return processOnWorkerInBatchesIterator(worker, input, options, context, jobContext);
|
|
@@ -1716,12 +1838,12 @@
|
|
|
1716
1838
|
return inputOptions;
|
|
1717
1839
|
}
|
|
1718
1840
|
|
|
1719
|
-
// ../../node_modules/@math.gl/
|
|
1841
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/create-worker.js
|
|
1720
1842
|
var requestId = 0;
|
|
1721
1843
|
var activeController = null;
|
|
1722
1844
|
var activeInputBatches = null;
|
|
1723
1845
|
var activeOutputAcknowledgements = null;
|
|
1724
|
-
async function createWorker(process2, processInBatches) {
|
|
1846
|
+
async function createWorker(process2, processInBatches, preload) {
|
|
1725
1847
|
if (!await WorkerBody.inWorkerThread()) {
|
|
1726
1848
|
return;
|
|
1727
1849
|
}
|
|
@@ -1762,10 +1884,12 @@
|
|
|
1762
1884
|
}
|
|
1763
1885
|
switch (type) {
|
|
1764
1886
|
case "preload":
|
|
1887
|
+
await preload?.();
|
|
1765
1888
|
WorkerBody.postMessage("done", {});
|
|
1766
1889
|
break;
|
|
1767
1890
|
case "process":
|
|
1768
1891
|
throwIfAborted3();
|
|
1892
|
+
validateOutputOwnership(payload.options?.["outputOwnership"]);
|
|
1769
1893
|
if (!process2) {
|
|
1770
1894
|
throw new Error("Worker does not support atomic processing");
|
|
1771
1895
|
}
|
|
@@ -1775,10 +1899,11 @@
|
|
|
1775
1899
|
await WorkerBody.postMessage("done", {
|
|
1776
1900
|
result,
|
|
1777
1901
|
executionMs: performance.now() - startedAt
|
|
1778
|
-
});
|
|
1902
|
+
}, payload.options?.["outputOwnership"] === "copy");
|
|
1779
1903
|
break;
|
|
1780
1904
|
case "process-in-batches":
|
|
1781
1905
|
throwIfAborted3();
|
|
1906
|
+
validateOutputOwnership(payload.options?.["outputOwnership"]);
|
|
1782
1907
|
if (!processInBatches) {
|
|
1783
1908
|
throw new Error("Worker does not support batched processing");
|
|
1784
1909
|
}
|
|
@@ -1790,7 +1915,7 @@
|
|
|
1790
1915
|
const resultIterator = processInBatches(createDemandDrivenIterator(inputBatches), payload.options || {}, jobContext, payload.context || {});
|
|
1791
1916
|
for await (const batch of resultIterator) {
|
|
1792
1917
|
throwIfAborted3();
|
|
1793
|
-
await WorkerBody.postMessage("output-batch", { result: batch });
|
|
1918
|
+
await WorkerBody.postMessage("output-batch", { result: batch }, payload.options?.["outputOwnership"] === "copy");
|
|
1794
1919
|
await outputAcknowledgements.next();
|
|
1795
1920
|
}
|
|
1796
1921
|
throwIfAborted3();
|
|
@@ -1888,14 +2013,14 @@
|
|
|
1888
2013
|
});
|
|
1889
2014
|
}
|
|
1890
2015
|
function createProgressReporter() {
|
|
1891
|
-
let
|
|
2016
|
+
let pending2;
|
|
1892
2017
|
let finished = false;
|
|
1893
2018
|
let scheduled = false;
|
|
1894
2019
|
const flush = () => {
|
|
1895
2020
|
scheduled = false;
|
|
1896
|
-
if (
|
|
1897
|
-
WorkerBody.postMessage("progress", { progress:
|
|
1898
|
-
|
|
2021
|
+
if (pending2) {
|
|
2022
|
+
WorkerBody.postMessage("progress", { progress: pending2 });
|
|
2023
|
+
pending2 = void 0;
|
|
1899
2024
|
}
|
|
1900
2025
|
};
|
|
1901
2026
|
return {
|
|
@@ -1903,9 +2028,9 @@
|
|
|
1903
2028
|
report(progress) {
|
|
1904
2029
|
if (finished)
|
|
1905
2030
|
return;
|
|
1906
|
-
if (
|
|
2031
|
+
if (pending2 && pending2.phase !== progress.phase)
|
|
1907
2032
|
flush();
|
|
1908
|
-
|
|
2033
|
+
pending2 = { ...progress };
|
|
1909
2034
|
if (!scheduled) {
|
|
1910
2035
|
scheduled = true;
|
|
1911
2036
|
setTimeout(flush, 0);
|
|
@@ -1914,173 +2039,1881 @@
|
|
|
1914
2039
|
/** Flushes final progress and suppresses reports from stale callbacks. */
|
|
1915
2040
|
finish(discard = false) {
|
|
1916
2041
|
if (discard)
|
|
1917
|
-
|
|
2042
|
+
pending2 = void 0;
|
|
1918
2043
|
flush();
|
|
1919
2044
|
finished = true;
|
|
1920
2045
|
}
|
|
1921
2046
|
};
|
|
1922
2047
|
}
|
|
1923
2048
|
|
|
1924
|
-
// ../../node_modules/@math.gl/
|
|
2049
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/index.js
|
|
1925
2050
|
var import_meta = {};
|
|
1926
2051
|
var path = typeof __filename === "string" ? __filename.replace(/\\/g, "/") : "";
|
|
1927
2052
|
var moduleUrl = path ? `file://${path.startsWith("/") ? "" : "/"}${encodeURI(path).replace(/#/g, "%23").replace(/\?/g, "%3F")}` : import_meta.url;
|
|
1928
2053
|
|
|
1929
|
-
//
|
|
1930
|
-
var
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
if (typeof cdn === "string" || cdn === null) {
|
|
1943
|
-
return cdn;
|
|
1944
|
-
}
|
|
1945
|
-
if (typeof coreCDN === "string" || coreCDN === null) {
|
|
1946
|
-
return coreCDN;
|
|
2054
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-preload.js
|
|
2055
|
+
var pending = /* @__PURE__ */ new WeakMap();
|
|
2056
|
+
var loaded = /* @__PURE__ */ new WeakSet();
|
|
2057
|
+
function preloadTaskCode(task, signal) {
|
|
2058
|
+
if (!task.preload)
|
|
2059
|
+
return Promise.resolve();
|
|
2060
|
+
let promise = pending.get(task);
|
|
2061
|
+
if (!promise) {
|
|
2062
|
+
promise = Promise.resolve().then(() => task.preload()).then(() => {
|
|
2063
|
+
loaded.add(task);
|
|
2064
|
+
});
|
|
2065
|
+
pending.set(task, promise);
|
|
2066
|
+
void promise.catch(() => pending.delete(task));
|
|
1947
2067
|
}
|
|
1948
|
-
return
|
|
2068
|
+
return withSignal(promise, signal);
|
|
1949
2069
|
}
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
if (moduleName) {
|
|
1953
|
-
const requestedLibraryName = libraryName || libraryUrl;
|
|
1954
|
-
const injectedLibrary = options.modules?.[requestedLibraryName];
|
|
1955
|
-
if (injectedLibrary !== void 0 && typeof injectedLibrary !== "string") {
|
|
1956
|
-
return injectedLibrary;
|
|
1957
|
-
}
|
|
1958
|
-
libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName);
|
|
1959
|
-
const hasLibraryOverride = typeof injectedLibrary === "string";
|
|
1960
|
-
moduleLibraryUrl = moduleLibraryName && (!hasLibraryOverride || typeof options.modules?.[moduleLibraryName] === "string") ? getLibraryUrl(moduleLibraryName, moduleName, options, moduleLibraryName) : libraryUrl;
|
|
1961
|
-
}
|
|
1962
|
-
const cacheKey = getLibraryCacheKey(libraryUrl, moduleLibraryUrl, isWorker);
|
|
1963
|
-
loadLibraryPromises[cacheKey] = // eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
1964
|
-
loadLibraryPromises[cacheKey] || loadLibraryFromFile(libraryUrl, moduleLibraryUrl);
|
|
1965
|
-
return await loadLibraryPromises[cacheKey];
|
|
2070
|
+
function isTaskCodeLoaded(task) {
|
|
2071
|
+
return !task.preload || loaded.has(task);
|
|
1966
2072
|
}
|
|
1967
|
-
function
|
|
1968
|
-
|
|
2073
|
+
function withSignal(operation, signal) {
|
|
2074
|
+
if (!signal)
|
|
2075
|
+
return operation;
|
|
2076
|
+
return new Promise((resolve, reject) => {
|
|
2077
|
+
const abort = () => {
|
|
2078
|
+
signal.removeEventListener("abort", abort);
|
|
2079
|
+
reject(signal.reason);
|
|
2080
|
+
};
|
|
2081
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
2082
|
+
if (signal.aborted)
|
|
2083
|
+
abort();
|
|
2084
|
+
operation.then((value) => {
|
|
2085
|
+
signal.removeEventListener("abort", abort);
|
|
2086
|
+
resolve(value);
|
|
2087
|
+
}, (error) => {
|
|
2088
|
+
signal.removeEventListener("abort", abort);
|
|
2089
|
+
reject(error);
|
|
2090
|
+
});
|
|
2091
|
+
});
|
|
1969
2092
|
}
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
2093
|
+
|
|
2094
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-channel.js
|
|
2095
|
+
var TaskRequestError = class extends Error {
|
|
2096
|
+
};
|
|
2097
|
+
var TaskChannel = class {
|
|
2098
|
+
constructor(options) {
|
|
2099
|
+
this.options = options;
|
|
2100
|
+
this.nextId = 1;
|
|
2101
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
2102
|
+
this.incoming = /* @__PURE__ */ new Map();
|
|
2103
|
+
}
|
|
2104
|
+
/** Send a request without serializing other in-flight requests. */
|
|
2105
|
+
request(operation, value, signal, transfer = []) {
|
|
2106
|
+
if (this.failure)
|
|
2107
|
+
return Promise.reject(this.failure.reason);
|
|
2108
|
+
if (signal?.aborted)
|
|
2109
|
+
return Promise.reject(signal.reason);
|
|
2110
|
+
const id = this.nextId++;
|
|
2111
|
+
return new Promise((resolve, reject) => {
|
|
2112
|
+
const abort = () => {
|
|
2113
|
+
const pending2 = this.pending.get(id);
|
|
2114
|
+
if (!pending2)
|
|
2115
|
+
return;
|
|
2116
|
+
this.pending.delete(id);
|
|
2117
|
+
pending2.cleanup();
|
|
2118
|
+
reject(signal?.reason);
|
|
2119
|
+
this.send({ source: "math.gl/tasks", kind: "cancel", id });
|
|
2120
|
+
};
|
|
2121
|
+
this.pending.set(id, {
|
|
2122
|
+
resolve,
|
|
2123
|
+
reject,
|
|
2124
|
+
cleanup: () => signal?.removeEventListener("abort", abort)
|
|
2125
|
+
});
|
|
2126
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
2127
|
+
this.send({ source: "math.gl/tasks", kind: "request", id, operation, value }, transfer);
|
|
2128
|
+
});
|
|
1981
2129
|
}
|
|
1982
|
-
|
|
1983
|
-
|
|
2130
|
+
/** Send a one-way notification. */
|
|
2131
|
+
emit(operation, value, transfer = []) {
|
|
2132
|
+
if (this.failure)
|
|
2133
|
+
throw this.failure.reason;
|
|
2134
|
+
this.send({ source: "math.gl/tasks", kind: "event", id: 0, operation, value }, transfer);
|
|
1984
2135
|
}
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
2136
|
+
/** Dispatch a transport message; unrelated protocols are ignored. */
|
|
2137
|
+
receive(message) {
|
|
2138
|
+
if (this.failure || message?.source !== "math.gl/tasks")
|
|
2139
|
+
return;
|
|
2140
|
+
if (message.kind === "failure") {
|
|
2141
|
+
const reason = new Error(message.error?.message ?? "Task channel failed");
|
|
2142
|
+
this.close(reason);
|
|
2143
|
+
this.options.onFailure?.(reason);
|
|
2144
|
+
} else if (message.kind === "result" || message.kind === "error") {
|
|
2145
|
+
const pending2 = this.pending.get(message.id);
|
|
2146
|
+
if (!pending2)
|
|
2147
|
+
return;
|
|
2148
|
+
this.pending.delete(message.id);
|
|
2149
|
+
pending2.cleanup();
|
|
2150
|
+
if (message.kind === "result")
|
|
2151
|
+
pending2.resolve(message.value);
|
|
2152
|
+
else {
|
|
2153
|
+
const error = new TaskRequestError(message.error?.message ?? "Task request failed");
|
|
2154
|
+
error.name = message.error?.name ?? "Error";
|
|
2155
|
+
pending2.reject(error);
|
|
2156
|
+
}
|
|
2157
|
+
} else if (message.kind === "cancel") {
|
|
2158
|
+
this.incoming.get(message.id)?.abort(new DOMException("Task request cancelled", "AbortError"));
|
|
2159
|
+
} else if (message.kind === "event") {
|
|
2160
|
+
try {
|
|
2161
|
+
this.options.handleEvent?.(message.operation, message.value);
|
|
2162
|
+
} catch (error) {
|
|
2163
|
+
this.fail(error);
|
|
2164
|
+
}
|
|
2165
|
+
} else if (message.kind === "request") {
|
|
2166
|
+
if (this.incoming.has(message.id)) {
|
|
2167
|
+
this.fail(new Error("Duplicate task request identifier"));
|
|
2168
|
+
return;
|
|
2169
|
+
}
|
|
2170
|
+
const controller = new AbortController();
|
|
2171
|
+
this.incoming.set(message.id, controller);
|
|
2172
|
+
void Promise.resolve().then(() => {
|
|
2173
|
+
controller.signal.throwIfAborted();
|
|
2174
|
+
return this.options.handleRequest(message.operation, message.value, controller.signal);
|
|
2175
|
+
}).then((value) => {
|
|
2176
|
+
if (!controller.signal.aborted && !this.failure) {
|
|
2177
|
+
this.send({ source: "math.gl/tasks", kind: "result", id: message.id, value }, this.options.getResultTransferList?.(value, message.value));
|
|
2178
|
+
}
|
|
2179
|
+
}).catch((reason) => {
|
|
2180
|
+
if (!controller.signal.aborted && !this.failure) {
|
|
2181
|
+
this.send({
|
|
2182
|
+
source: "math.gl/tasks",
|
|
2183
|
+
kind: "error",
|
|
2184
|
+
id: message.id,
|
|
2185
|
+
error: {
|
|
2186
|
+
name: reason instanceof Error ? reason.name : "Error",
|
|
2187
|
+
message: reason instanceof Error ? reason.message : String(reason)
|
|
2188
|
+
}
|
|
2189
|
+
});
|
|
2190
|
+
}
|
|
2191
|
+
}).finally(() => this.incoming.delete(message.id));
|
|
1988
2192
|
}
|
|
1989
|
-
assert(options.CDN.startsWith("http"));
|
|
1990
|
-
return `${options.CDN}/${moduleName}@${VERSION}/dist/libs/${libraryName}`;
|
|
1991
|
-
}
|
|
1992
|
-
if (isWorker) {
|
|
1993
|
-
return libraryName.endsWith(".mjs") ? `./libs/${libraryName}` : `../src/libs/${libraryName}`;
|
|
1994
|
-
}
|
|
1995
|
-
return `modules/${moduleName}/src/libs/${libraryName}`;
|
|
1996
|
-
}
|
|
1997
|
-
async function loadLibraryFromFile(libraryUrl, moduleLibraryUrl) {
|
|
1998
|
-
if (libraryUrl.endsWith("wasm")) {
|
|
1999
|
-
return await loadAsArrayBuffer(libraryUrl);
|
|
2000
2193
|
}
|
|
2001
|
-
|
|
2002
|
-
|
|
2194
|
+
/** Reject all outstanding calls with a common cause and abort incoming callbacks. */
|
|
2195
|
+
close(reason = new Error("Task channel closed")) {
|
|
2196
|
+
if (this.failure)
|
|
2197
|
+
return;
|
|
2198
|
+
this.failure = { reason };
|
|
2199
|
+
for (const pending2 of this.pending.values()) {
|
|
2200
|
+
pending2.cleanup();
|
|
2201
|
+
pending2.reject(reason);
|
|
2202
|
+
}
|
|
2203
|
+
this.pending.clear();
|
|
2204
|
+
for (const controller of this.incoming.values())
|
|
2205
|
+
controller.abort(reason);
|
|
2206
|
+
this.incoming.clear();
|
|
2207
|
+
}
|
|
2208
|
+
send(message, transfer = []) {
|
|
2209
|
+
if (this.failure)
|
|
2210
|
+
return;
|
|
2003
2211
|
try {
|
|
2004
|
-
|
|
2005
|
-
if (result || !libraryUrl.includes("/dist/libs/")) {
|
|
2006
|
-
return result;
|
|
2007
|
-
}
|
|
2008
|
-
return await requireFromFile?.(libraryUrl.replace("/dist/libs/", "/src/libs/"));
|
|
2212
|
+
this.options.send(message, transfer);
|
|
2009
2213
|
} catch (error) {
|
|
2010
|
-
|
|
2011
|
-
try {
|
|
2012
|
-
return await requireFromFile?.(libraryUrl.replace("/dist/libs/", "/src/libs/"));
|
|
2013
|
-
} catch {
|
|
2014
|
-
}
|
|
2015
|
-
}
|
|
2016
|
-
console.error(error);
|
|
2017
|
-
return null;
|
|
2214
|
+
this.fail(error);
|
|
2018
2215
|
}
|
|
2019
2216
|
}
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2217
|
+
/** Invalidate the channel and notify the peer when the transport still works. */
|
|
2218
|
+
fail(reason) {
|
|
2219
|
+
if (this.failure)
|
|
2220
|
+
return;
|
|
2221
|
+
this.close(reason);
|
|
2222
|
+
try {
|
|
2223
|
+
this.options.send({
|
|
2224
|
+
source: "math.gl/tasks",
|
|
2225
|
+
kind: "failure",
|
|
2226
|
+
id: 0,
|
|
2227
|
+
error: {
|
|
2228
|
+
name: reason instanceof Error ? reason.name : "Error",
|
|
2229
|
+
message: reason instanceof Error ? reason.message : String(reason)
|
|
2230
|
+
}
|
|
2231
|
+
}, []);
|
|
2232
|
+
} catch {
|
|
2233
|
+
}
|
|
2234
|
+
this.options.onFailure?.(reason);
|
|
2036
2235
|
}
|
|
2037
|
-
|
|
2236
|
+
};
|
|
2237
|
+
|
|
2238
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-runtime.js
|
|
2239
|
+
function assertPayload(value) {
|
|
2240
|
+
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) {
|
|
2241
|
+
throw new TypeError("Task payloads must be plain objects with named fields");
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
function clonePayload(value, ownership = "copy") {
|
|
2245
|
+
assertPayload(value);
|
|
2246
|
+
if (!["copy", "transfer", "share"].includes(ownership))
|
|
2247
|
+
throw new TypeError("Invalid input ownership");
|
|
2248
|
+
const transfer = getTransferList(value);
|
|
2249
|
+
if (ownership === "share" && transfer.length)
|
|
2250
|
+
throw new TypeError("Share requires shared storage");
|
|
2251
|
+
return structuredClone(value, {
|
|
2252
|
+
transfer: ownership === "transfer" ? transfer : []
|
|
2253
|
+
});
|
|
2038
2254
|
}
|
|
2039
|
-
function
|
|
2040
|
-
const
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2255
|
+
function taskContext(state, context = {}) {
|
|
2256
|
+
const signal = context.signal ?? new AbortController().signal;
|
|
2257
|
+
return {
|
|
2258
|
+
state,
|
|
2259
|
+
signal,
|
|
2260
|
+
requestHost: async (operation, payload, controls) => {
|
|
2261
|
+
signal.throwIfAborted();
|
|
2262
|
+
if (!context.requestHost)
|
|
2263
|
+
throw new Error("No host request handler configured");
|
|
2264
|
+
return context.requestHost(operation, payload, controls);
|
|
2265
|
+
},
|
|
2266
|
+
emitHost: (operation, payload) => {
|
|
2267
|
+
signal.throwIfAborted();
|
|
2268
|
+
context.emitHost?.(operation, payload);
|
|
2269
|
+
},
|
|
2270
|
+
throwIfAborted: () => {
|
|
2271
|
+
signal.throwIfAborted();
|
|
2272
|
+
context.throwIfAborted?.();
|
|
2273
|
+
},
|
|
2274
|
+
reportProgress: (progress) => context.reportProgress?.({
|
|
2275
|
+
...progress,
|
|
2276
|
+
phase: progress.phase ?? "process",
|
|
2277
|
+
unit: progress.unit ?? "items"
|
|
2278
|
+
})
|
|
2279
|
+
};
|
|
2049
2280
|
}
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2281
|
+
var TaskRuntime = class {
|
|
2282
|
+
constructor(task) {
|
|
2283
|
+
this.task = task;
|
|
2284
|
+
this.initialized = false;
|
|
2285
|
+
}
|
|
2286
|
+
async initialize(input, context = {}) {
|
|
2287
|
+
if (this.initialized)
|
|
2288
|
+
throw new Error("Task is already initialized");
|
|
2289
|
+
assertPayload(input);
|
|
2290
|
+
await preloadTaskCode(this.task, context.signal);
|
|
2291
|
+
context.signal?.throwIfAborted();
|
|
2292
|
+
this.state = await this.task.initialize?.(input, taskContext(void 0, context));
|
|
2293
|
+
this.initialized = true;
|
|
2294
|
+
return {};
|
|
2055
2295
|
}
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2296
|
+
async destroy() {
|
|
2297
|
+
if (this.initialized) {
|
|
2298
|
+
this.initialized = false;
|
|
2299
|
+
const state = this.state;
|
|
2300
|
+
this.state = void 0;
|
|
2301
|
+
if (this.task.initialize)
|
|
2302
|
+
await this.task.destroy?.(state);
|
|
2061
2303
|
}
|
|
2062
|
-
|
|
2304
|
+
return {};
|
|
2063
2305
|
}
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2306
|
+
async process(input, options, context = {}) {
|
|
2307
|
+
if (!this.initialized)
|
|
2308
|
+
throw new Error("Task is not initialized");
|
|
2309
|
+
if (!this.task.process)
|
|
2310
|
+
throw new Error("Task has no atomic processor");
|
|
2311
|
+
assertPayload(input);
|
|
2312
|
+
const result = await this.task.process(input, options, taskContext(this.state, context));
|
|
2313
|
+
assertPayload(result);
|
|
2314
|
+
return result;
|
|
2070
2315
|
}
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
if (
|
|
2075
|
-
|
|
2316
|
+
async *stream(inputs, options, context = {}) {
|
|
2317
|
+
if (!this.initialized)
|
|
2318
|
+
throw new Error("Task is not initialized");
|
|
2319
|
+
if (!this.task.processInBatches)
|
|
2320
|
+
throw new Error("Task has no streaming processor");
|
|
2321
|
+
for await (const output of this.task.processInBatches(inputs, options, taskContext(this.state, context))) {
|
|
2322
|
+
assertPayload(output);
|
|
2323
|
+
yield output;
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
};
|
|
2327
|
+
async function initializeTaskWorker(task) {
|
|
2328
|
+
if (!await WorkerBody.inWorkerThread())
|
|
2329
|
+
throw new Error("initializeTaskWorker must run inside a worker");
|
|
2330
|
+
if (installed)
|
|
2331
|
+
throw new Error("A task is already installed in this worker");
|
|
2332
|
+
installed = true;
|
|
2333
|
+
const runtime = new TaskRuntime(task);
|
|
2334
|
+
let channelStream;
|
|
2335
|
+
const channel = new TaskChannel({
|
|
2336
|
+
getResultTransferList: (value, request) => request.outputOwnership === "transfer" ? getTransferList(value) : [],
|
|
2337
|
+
send: (message, transfer) => {
|
|
2338
|
+
const snapshot = structuredClone(message, { transfer });
|
|
2339
|
+
void WorkerBody.postMessage("task-channel", snapshot).catch((reason) => channel.fail(reason));
|
|
2340
|
+
},
|
|
2341
|
+
handleRequest: async (operation, value, signal) => {
|
|
2342
|
+
const request = value;
|
|
2343
|
+
const context = {
|
|
2344
|
+
signal,
|
|
2345
|
+
reportProgress: (progress) => channel.emit("task:progress", { id: request.progressId, progress }),
|
|
2346
|
+
requestHost: (operation2, payload, controls = {}) => {
|
|
2347
|
+
const request2 = {
|
|
2348
|
+
operation: operation2,
|
|
2349
|
+
payload: clonePayload(payload, controls.inputOwnership),
|
|
2350
|
+
outputOwnership: controls.outputOwnership ?? "copy"
|
|
2351
|
+
};
|
|
2352
|
+
return channel.request("task:host-request", request2, signal, getTransferList(request2));
|
|
2353
|
+
},
|
|
2354
|
+
emitHost: (operation2, payload) => channel.emit("task:host-event", { operation: operation2, payload, id: request.progressId })
|
|
2355
|
+
};
|
|
2356
|
+
switch (operation) {
|
|
2357
|
+
case "initialize":
|
|
2358
|
+
return runtime.initialize(request.input, context);
|
|
2359
|
+
case "process":
|
|
2360
|
+
return runtime.process(request.input, request.options, context);
|
|
2361
|
+
case "stream-open": {
|
|
2362
|
+
if (channelStream)
|
|
2363
|
+
throw new Error("A task stream is already open");
|
|
2364
|
+
async function* inputs() {
|
|
2365
|
+
while (true) {
|
|
2366
|
+
const result = await channel.request("task:next-input", { outputOwnership: "transfer" }, signal);
|
|
2367
|
+
if (result.done)
|
|
2368
|
+
return;
|
|
2369
|
+
yield result.value;
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
channelStream = runtime.stream(inputs(), request.options, context)[Symbol.asyncIterator]();
|
|
2373
|
+
return {};
|
|
2374
|
+
}
|
|
2375
|
+
case "stream-next":
|
|
2376
|
+
if (!channelStream)
|
|
2377
|
+
throw new Error("No active task stream");
|
|
2378
|
+
return channelStream.next();
|
|
2379
|
+
case "stream-close":
|
|
2380
|
+
try {
|
|
2381
|
+
await channelStream?.return?.();
|
|
2382
|
+
} finally {
|
|
2383
|
+
channelStream = void 0;
|
|
2384
|
+
}
|
|
2385
|
+
return {};
|
|
2386
|
+
case "destroy":
|
|
2387
|
+
return runtime.destroy();
|
|
2388
|
+
default:
|
|
2389
|
+
throw new Error("Unknown task channel operation");
|
|
2390
|
+
}
|
|
2076
2391
|
}
|
|
2077
|
-
|
|
2078
|
-
|
|
2392
|
+
});
|
|
2393
|
+
await WorkerBody.addEventListener((type, payload) => {
|
|
2394
|
+
if (type === "task-channel")
|
|
2395
|
+
channel.receive(payload);
|
|
2396
|
+
});
|
|
2397
|
+
let streamOptions = {};
|
|
2398
|
+
return createWorker(async (request, _options, context) => {
|
|
2399
|
+
switch (request.operation) {
|
|
2400
|
+
case "initialize":
|
|
2401
|
+
return runtime.initialize(request.input, context);
|
|
2402
|
+
case "destroy":
|
|
2403
|
+
return runtime.destroy();
|
|
2404
|
+
case "stream-options":
|
|
2405
|
+
streamOptions = request.options;
|
|
2406
|
+
return {};
|
|
2407
|
+
case "process":
|
|
2408
|
+
return runtime.process(request.input, request.options, context);
|
|
2409
|
+
default:
|
|
2410
|
+
throw new Error("Unknown task operation");
|
|
2411
|
+
}
|
|
2412
|
+
}, async function* (inputs, _options, context) {
|
|
2413
|
+
async function* batches() {
|
|
2414
|
+
for await (const input of inputs) {
|
|
2415
|
+
assertPayload(input);
|
|
2416
|
+
yield input;
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
try {
|
|
2420
|
+
yield* runtime.stream(batches(), streamOptions, context);
|
|
2421
|
+
} finally {
|
|
2422
|
+
streamOptions = {};
|
|
2423
|
+
}
|
|
2424
|
+
}, () => preloadTaskCode(task));
|
|
2425
|
+
}
|
|
2426
|
+
var installed = false;
|
|
2427
|
+
function localContext(controls) {
|
|
2428
|
+
return {
|
|
2429
|
+
signal: controls.signal,
|
|
2430
|
+
reportProgress: (progress) => controls.onProgress?.(progress)
|
|
2431
|
+
};
|
|
2079
2432
|
}
|
|
2080
2433
|
|
|
2081
|
-
//
|
|
2082
|
-
|
|
2083
|
-
|
|
2434
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-sync.js
|
|
2435
|
+
function runTaskSync(task, input, request = {}) {
|
|
2436
|
+
if (!isTaskCodeLoaded(task))
|
|
2437
|
+
throw new Error("Preload task on the main thread before runTaskSync");
|
|
2438
|
+
if ("execution" in request)
|
|
2439
|
+
throw new TypeError("runTaskSync always runs on the calling thread");
|
|
2440
|
+
if (!task.process)
|
|
2441
|
+
throw new TypeError("Task has no atomic processor");
|
|
2442
|
+
for (const hook of [task.initialize, task.process, task.destroy]) {
|
|
2443
|
+
if (hook && Object.prototype.toString.call(hook) === "[object AsyncFunction]")
|
|
2444
|
+
throw new TypeError("runTaskSync requires synchronous lifecycle hooks");
|
|
2445
|
+
}
|
|
2446
|
+
if (request.outputOwnership && !["copy", "transfer"].includes(request.outputOwnership))
|
|
2447
|
+
throw new TypeError("Invalid output ownership");
|
|
2448
|
+
const context = taskContext(void 0, localContext(request));
|
|
2449
|
+
context.throwIfAborted();
|
|
2450
|
+
const options = request.options ?? {};
|
|
2451
|
+
if (request.inputOwnership === "transfer") {
|
|
2452
|
+
const metadata = new Set(getTransferList(options));
|
|
2453
|
+
if (getTransferList(input).some((buffer) => metadata.has(buffer)))
|
|
2454
|
+
throw new Error("Transferred input aliases reusable options; use inputOwnership: copy");
|
|
2455
|
+
}
|
|
2456
|
+
const copiedOptions = clonePayload(options);
|
|
2457
|
+
const initialization = clonePayload(request.initialization ?? {}, request.initializationOwnership);
|
|
2458
|
+
let initialized = false;
|
|
2459
|
+
let failure;
|
|
2460
|
+
let failed = false;
|
|
2461
|
+
let output;
|
|
2462
|
+
try {
|
|
2463
|
+
const state = task.initialize?.(initialization, context);
|
|
2464
|
+
if (isThenable(state)) {
|
|
2465
|
+
void Promise.resolve(state).then((value) => task.destroy?.(value)).catch(() => {
|
|
2466
|
+
});
|
|
2467
|
+
throw new TypeError("runTaskSync initialize returned a promise");
|
|
2468
|
+
}
|
|
2469
|
+
context.state = state;
|
|
2470
|
+
initialized = true;
|
|
2471
|
+
context.throwIfAborted();
|
|
2472
|
+
const copiedInput = clonePayload(input, request.inputOwnership);
|
|
2473
|
+
const result = task.process(copiedInput, copiedOptions, context);
|
|
2474
|
+
if (isThenable(result)) {
|
|
2475
|
+
initialized = false;
|
|
2476
|
+
void Promise.resolve(result).catch(() => {
|
|
2477
|
+
}).then(() => {
|
|
2478
|
+
if (task.initialize)
|
|
2479
|
+
return task.destroy?.(context.state);
|
|
2480
|
+
}).catch(() => {
|
|
2481
|
+
});
|
|
2482
|
+
throw new TypeError("runTaskSync process returned a promise");
|
|
2483
|
+
}
|
|
2484
|
+
assertPayload(result);
|
|
2485
|
+
context.throwIfAborted();
|
|
2486
|
+
output = clonePayload(result, request.outputOwnership ?? "transfer");
|
|
2487
|
+
} catch (error) {
|
|
2488
|
+
failed = true;
|
|
2489
|
+
failure = error;
|
|
2490
|
+
} finally {
|
|
2491
|
+
if (initialized && task.initialize) {
|
|
2492
|
+
try {
|
|
2493
|
+
const cleanup = task.destroy?.(context.state);
|
|
2494
|
+
if (isThenable(cleanup)) {
|
|
2495
|
+
void Promise.resolve(cleanup).catch(() => {
|
|
2496
|
+
});
|
|
2497
|
+
throw new TypeError("runTaskSync destroy returned a promise");
|
|
2498
|
+
}
|
|
2499
|
+
} catch (error) {
|
|
2500
|
+
if (failed)
|
|
2501
|
+
throw new AggregateError([failure, error], "Task processing and destruction failed");
|
|
2502
|
+
throw error;
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
if (failed)
|
|
2507
|
+
throw failure;
|
|
2508
|
+
return output;
|
|
2509
|
+
}
|
|
2510
|
+
function isThenable(value) {
|
|
2511
|
+
return Boolean(value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function");
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-operation-queue.js
|
|
2515
|
+
var TaskOperationQueue = class {
|
|
2516
|
+
constructor(maxConcurrency) {
|
|
2517
|
+
this.maxConcurrency = maxConcurrency;
|
|
2518
|
+
this.pending = [];
|
|
2519
|
+
this.active = 0;
|
|
2520
|
+
this.exclusive = false;
|
|
2521
|
+
this.closed = false;
|
|
2522
|
+
this.idleWaiters = /* @__PURE__ */ new Set();
|
|
2523
|
+
if (!Number.isSafeInteger(maxConcurrency) || maxConcurrency < 1) {
|
|
2524
|
+
throw new RangeError("maxConcurrency must be a positive safe integer");
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
/** Queue an operation; aborting before it starts removes it without running it. */
|
|
2528
|
+
run(mode, operation, signal) {
|
|
2529
|
+
if (this.closed)
|
|
2530
|
+
return Promise.reject(new Error("Task operation queue is closed"));
|
|
2531
|
+
if (mode !== "parallel" && mode !== "exclusive")
|
|
2532
|
+
return Promise.reject(new TypeError("Invalid operation mode"));
|
|
2533
|
+
if (signal?.aborted)
|
|
2534
|
+
return Promise.reject(signal.reason);
|
|
2535
|
+
return new Promise((resolve, reject) => {
|
|
2536
|
+
const onAbort = () => {
|
|
2537
|
+
const index = this.pending.indexOf(entry);
|
|
2538
|
+
if (index >= 0) {
|
|
2539
|
+
this.pending.splice(index, 1);
|
|
2540
|
+
entry.cancel(signal?.reason);
|
|
2541
|
+
this.pump();
|
|
2542
|
+
}
|
|
2543
|
+
};
|
|
2544
|
+
const entry = {
|
|
2545
|
+
mode,
|
|
2546
|
+
cancel: (reason) => {
|
|
2547
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2548
|
+
reject(reason);
|
|
2549
|
+
},
|
|
2550
|
+
start: () => {
|
|
2551
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2552
|
+
this.active++;
|
|
2553
|
+
if (mode === "exclusive")
|
|
2554
|
+
this.exclusive = true;
|
|
2555
|
+
void Promise.resolve().then(() => {
|
|
2556
|
+
signal?.throwIfAborted();
|
|
2557
|
+
return operation();
|
|
2558
|
+
}).then(resolve, reject).finally(() => {
|
|
2559
|
+
this.active--;
|
|
2560
|
+
if (mode === "exclusive")
|
|
2561
|
+
this.exclusive = false;
|
|
2562
|
+
this.pump();
|
|
2563
|
+
});
|
|
2564
|
+
}
|
|
2565
|
+
};
|
|
2566
|
+
this.pending.push(entry);
|
|
2567
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
2568
|
+
if (signal?.aborted)
|
|
2569
|
+
onAbort();
|
|
2570
|
+
else
|
|
2571
|
+
this.pump();
|
|
2572
|
+
});
|
|
2573
|
+
}
|
|
2574
|
+
/** Reject queued calls with one cause while allowing active operations to settle. */
|
|
2575
|
+
cancelPending(reason) {
|
|
2576
|
+
this.closed = true;
|
|
2577
|
+
for (const entry of this.pending.splice(0))
|
|
2578
|
+
entry.cancel(reason);
|
|
2579
|
+
this.pump();
|
|
2580
|
+
}
|
|
2581
|
+
/** Stop accepting new work; accepted operations continue to completion. */
|
|
2582
|
+
close() {
|
|
2583
|
+
this.closed = true;
|
|
2584
|
+
return this.whenIdle();
|
|
2585
|
+
}
|
|
2586
|
+
/** Wait until the queue has no running or waiting operations. */
|
|
2587
|
+
whenIdle() {
|
|
2588
|
+
if (!this.active && !this.pending.length)
|
|
2589
|
+
return Promise.resolve();
|
|
2590
|
+
return new Promise((resolve) => this.idleWaiters.add(resolve));
|
|
2591
|
+
}
|
|
2592
|
+
pump() {
|
|
2593
|
+
while (!this.exclusive && this.pending.length && this.active < this.maxConcurrency) {
|
|
2594
|
+
const entry = this.pending[0];
|
|
2595
|
+
if (entry.mode === "exclusive" && this.active)
|
|
2596
|
+
break;
|
|
2597
|
+
this.pending.shift();
|
|
2598
|
+
entry.start();
|
|
2599
|
+
if (entry.mode === "exclusive")
|
|
2600
|
+
break;
|
|
2601
|
+
}
|
|
2602
|
+
if (!this.active && !this.pending.length) {
|
|
2603
|
+
for (const resolve of this.idleWaiters)
|
|
2604
|
+
resolve();
|
|
2605
|
+
this.idleWaiters.clear();
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
};
|
|
2609
|
+
|
|
2610
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-worker-channel.js
|
|
2611
|
+
var TaskWorkerChannel = class {
|
|
2612
|
+
constructor(name, target, options) {
|
|
2613
|
+
this.thread = new WorkerThread({
|
|
2614
|
+
name,
|
|
2615
|
+
url: target.url?.toString(),
|
|
2616
|
+
loadWorker: target.create,
|
|
2617
|
+
workerType: "module"
|
|
2618
|
+
});
|
|
2619
|
+
this.channel = new TaskChannel({
|
|
2620
|
+
...options,
|
|
2621
|
+
send: (message, transfer) => this.thread.postMessage({ source: "loaders.gl/tasks", type: "task-channel", payload: message }, transfer)
|
|
2622
|
+
});
|
|
2623
|
+
this.thread.onMessage = (message) => {
|
|
2624
|
+
if (message?.type === "task-channel")
|
|
2625
|
+
this.channel.receive(message.payload);
|
|
2626
|
+
};
|
|
2627
|
+
this.thread.onError = (reason) => {
|
|
2628
|
+
this.channel.close(reason);
|
|
2629
|
+
options.onFailure?.(reason);
|
|
2630
|
+
};
|
|
2631
|
+
}
|
|
2632
|
+
/** Settle pending calls and terminate the worker without replacing its state. */
|
|
2633
|
+
async destroy(reason) {
|
|
2634
|
+
this.channel.close(reason);
|
|
2635
|
+
await this.thread.destroy();
|
|
2636
|
+
}
|
|
2637
|
+
};
|
|
2638
|
+
|
|
2639
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-runner.js
|
|
2640
|
+
var InitializedTask = class {
|
|
2641
|
+
/** @internal Use TaskRunner.initializeTask. */
|
|
2642
|
+
constructor(task, release, initializationControls) {
|
|
2643
|
+
this.task = task;
|
|
2644
|
+
this.release = release;
|
|
2645
|
+
this.initializationControls = initializationControls;
|
|
2646
|
+
this.nextProgressId = 1;
|
|
2647
|
+
this.progressCallbacks = /* @__PURE__ */ new Map();
|
|
2648
|
+
this.callbackFailures = /* @__PURE__ */ new Map();
|
|
2649
|
+
this.closed = false;
|
|
2650
|
+
this.finalized = false;
|
|
2651
|
+
this.streams = /* @__PURE__ */ new Set();
|
|
2652
|
+
this.invalid = false;
|
|
2653
|
+
this.controller = new AbortController();
|
|
2654
|
+
const controls = initializationControls;
|
|
2655
|
+
this.runtime = new TaskRuntime(task);
|
|
2656
|
+
const concurrency = controls.operationConcurrency ?? 1;
|
|
2657
|
+
const maximum = task.concurrency?.maxConcurrency ?? 1;
|
|
2658
|
+
if (!Number.isSafeInteger(maximum) || maximum < 1 || !Number.isSafeInteger(concurrency) || concurrency < 1 || concurrency > maximum) {
|
|
2659
|
+
throw new RangeError("Task concurrency must be between 1 and the task maximum");
|
|
2660
|
+
}
|
|
2661
|
+
this.operationQueue = new TaskOperationQueue(concurrency);
|
|
2662
|
+
this.concurrent = concurrency > 1;
|
|
2663
|
+
const execution = controls.execution ?? "auto";
|
|
2664
|
+
if (!["auto", "main-thread", "worker"].includes(execution))
|
|
2665
|
+
throw new TypeError("Invalid execution mode");
|
|
2666
|
+
if (execution === "worker" && !task.worker)
|
|
2667
|
+
throw new Error("Task has no worker");
|
|
2668
|
+
if (execution !== "main-thread" && task.worker) {
|
|
2669
|
+
const target = task.worker;
|
|
2670
|
+
if (Boolean(target.url) === Boolean(target.create))
|
|
2671
|
+
throw new Error("Supply exactly one worker URL or factory");
|
|
2672
|
+
if (this.concurrent || controls.onRequest || controls.onEvent) {
|
|
2673
|
+
this.workerChannel = new TaskWorkerChannel(task.id, target, {
|
|
2674
|
+
handleRequest: async (operation, payload, signal) => {
|
|
2675
|
+
if (operation === "task:next-input") {
|
|
2676
|
+
if (!this.channelInputs)
|
|
2677
|
+
throw new Error("No active task stream");
|
|
2678
|
+
return this.channelInputs.next();
|
|
2679
|
+
}
|
|
2680
|
+
if (!controls.onRequest)
|
|
2681
|
+
throw new Error("No host request handler configured");
|
|
2682
|
+
const request = payload;
|
|
2683
|
+
if (operation !== "task:host-request")
|
|
2684
|
+
throw new Error("Unknown host request");
|
|
2685
|
+
return controls.onRequest(request.operation, request.payload, signal);
|
|
2686
|
+
},
|
|
2687
|
+
getResultTransferList: (value, request) => request.outputOwnership === "transfer" ? getTransferList(value) : [],
|
|
2688
|
+
handleEvent: (operation, payload) => {
|
|
2689
|
+
const { id } = payload;
|
|
2690
|
+
try {
|
|
2691
|
+
if (operation === "task:progress") {
|
|
2692
|
+
const event = payload;
|
|
2693
|
+
(this.progressCallbacks.get(event.id) ?? this.streamProgress)?.(event.progress);
|
|
2694
|
+
} else if (operation === "task:host-event") {
|
|
2695
|
+
const event = payload;
|
|
2696
|
+
controls.onEvent?.(event.operation, event.payload);
|
|
2697
|
+
}
|
|
2698
|
+
} catch (reason) {
|
|
2699
|
+
if (this.progressCallbacks.has(id) || this.streamProgressId === id) {
|
|
2700
|
+
if (!this.callbackFailures.has(id))
|
|
2701
|
+
this.callbackFailures.set(id, { reason });
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
},
|
|
2705
|
+
onFailure: (reason) => {
|
|
2706
|
+
this.invalid = true;
|
|
2707
|
+
this.operationQueue.cancelPending(reason);
|
|
2708
|
+
this.controller.abort(reason);
|
|
2709
|
+
}
|
|
2710
|
+
});
|
|
2711
|
+
return;
|
|
2712
|
+
}
|
|
2713
|
+
this.pool = new WorkerPool({
|
|
2714
|
+
name: task.id,
|
|
2715
|
+
url: target.url?.toString(),
|
|
2716
|
+
loadWorker: target.create,
|
|
2717
|
+
workerType: "module",
|
|
2718
|
+
maxConcurrency: 1,
|
|
2719
|
+
maxMobileConcurrency: 1
|
|
2720
|
+
});
|
|
2721
|
+
this.descriptor = {
|
|
2722
|
+
id: task.id,
|
|
2723
|
+
name: task.id,
|
|
2724
|
+
module: "tasks",
|
|
2725
|
+
version: "prototype",
|
|
2726
|
+
options: {},
|
|
2727
|
+
worker: target.url?.toString() ?? true,
|
|
2728
|
+
loadWorker: target.create,
|
|
2729
|
+
workerInBatches: target.capabilities.streaming
|
|
2730
|
+
};
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
/** @internal */
|
|
2734
|
+
async initialize(input, controls) {
|
|
2735
|
+
try {
|
|
2736
|
+
assertPayload(input);
|
|
2737
|
+
await this.enqueue(() => this.invoke("initialize", input, {}, controls));
|
|
2738
|
+
} catch (error) {
|
|
2739
|
+
await this.terminate(error);
|
|
2740
|
+
throw error;
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
runTask(input, ...args) {
|
|
2744
|
+
if (this.invalid)
|
|
2745
|
+
return Promise.reject(new Error("Initialized task is invalid; initialize a new instance"));
|
|
2746
|
+
if (this.closed)
|
|
2747
|
+
return Promise.reject(new Error("Initialized task is closed"));
|
|
2748
|
+
const timeout = args[0]?.timeout;
|
|
2749
|
+
if (timeout !== void 0 && (!Number.isSafeInteger(timeout) || timeout < 0 || timeout > 4294967295)) {
|
|
2750
|
+
return Promise.reject(new RangeError("Invalid task timeout"));
|
|
2751
|
+
}
|
|
2752
|
+
const deadline = timeout === void 0 ? void 0 : AbortSignal.timeout(timeout);
|
|
2753
|
+
const signal = deadline && args[0]?.signal ? AbortSignal.any([deadline, args[0].signal]) : deadline ?? args[0]?.signal;
|
|
2754
|
+
const controls = { ...args[0], signal };
|
|
2755
|
+
const mode = this.task.concurrency?.getSchedulingMode?.(input) ?? "exclusive";
|
|
2756
|
+
return this.operationQueue.run(mode, async () => {
|
|
2757
|
+
signal?.throwIfAborted();
|
|
2758
|
+
this.checkCapability("atomic");
|
|
2759
|
+
const invalidate = () => {
|
|
2760
|
+
if (this.concurrent) {
|
|
2761
|
+
this.invalid = true;
|
|
2762
|
+
this.operationQueue.cancelPending(signal?.reason);
|
|
2763
|
+
this.controller.abort(signal?.reason);
|
|
2764
|
+
}
|
|
2765
|
+
};
|
|
2766
|
+
signal?.addEventListener("abort", invalidate, { once: true });
|
|
2767
|
+
try {
|
|
2768
|
+
return await this.invoke("process", input, args[0]?.options ?? {}, controls);
|
|
2769
|
+
} finally {
|
|
2770
|
+
signal?.removeEventListener("abort", invalidate);
|
|
2771
|
+
}
|
|
2772
|
+
}, signal);
|
|
2773
|
+
}
|
|
2774
|
+
/** Independent calls sharing this instance, always serial and in input order. */
|
|
2775
|
+
runTasks(inputs, ...args) {
|
|
2776
|
+
return this.serialStream(async function* (self2) {
|
|
2777
|
+
self2.checkCapability("atomic");
|
|
2778
|
+
for await (const input of asAsync(inputs, self2.controls(args[0]).signal)) {
|
|
2779
|
+
yield await self2.invoke("process", input, args[0]?.options ?? {}, args[0]);
|
|
2780
|
+
}
|
|
2781
|
+
}, args[0]?.signal);
|
|
2782
|
+
}
|
|
2783
|
+
/** One processor invocation for the entire input iterable. */
|
|
2784
|
+
runTaskInBatches(inputs, ...args) {
|
|
2785
|
+
return this.serialStream(async function* (self2) {
|
|
2786
|
+
self2.checkCapability("streaming");
|
|
2787
|
+
const controls = self2.controls(args[0]);
|
|
2788
|
+
const options = clonePayload(args[0]?.options ?? {});
|
|
2789
|
+
async function* prepared() {
|
|
2790
|
+
for await (const input of asAsync(inputs, controls.signal)) {
|
|
2791
|
+
controls.signal?.throwIfAborted();
|
|
2792
|
+
assertNoTransferAlias(input, args[0]?.options ?? {}, controls.inputOwnership);
|
|
2793
|
+
yield clonePayload(input, controls.inputOwnership);
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
let completed = false;
|
|
2797
|
+
try {
|
|
2798
|
+
if (self2.workerChannel) {
|
|
2799
|
+
self2.channelInputs = prepared()[Symbol.asyncIterator]();
|
|
2800
|
+
self2.streamProgress = controls.onProgress;
|
|
2801
|
+
try {
|
|
2802
|
+
await self2.invoke("stream-open", {}, options, controls);
|
|
2803
|
+
while (true) {
|
|
2804
|
+
const result = await self2.invoke("stream-next", {}, {}, controls);
|
|
2805
|
+
if (result.done)
|
|
2806
|
+
break;
|
|
2807
|
+
yield result.value;
|
|
2808
|
+
}
|
|
2809
|
+
} finally {
|
|
2810
|
+
try {
|
|
2811
|
+
if (!self2.invalid)
|
|
2812
|
+
await self2.invoke("stream-close", {}, {}, controls);
|
|
2813
|
+
} finally {
|
|
2814
|
+
await self2.channelInputs.return?.();
|
|
2815
|
+
self2.channelInputs = void 0;
|
|
2816
|
+
self2.streamProgress = void 0;
|
|
2817
|
+
if (self2.streamProgressId !== void 0)
|
|
2818
|
+
self2.callbackFailures.delete(self2.streamProgressId);
|
|
2819
|
+
self2.streamProgressId = void 0;
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
} else if (self2.pool) {
|
|
2823
|
+
await self2.invoke("stream-options", {}, options, controls);
|
|
2824
|
+
yield* processOnWorkerInBatches(self2.descriptor, prepared(), {
|
|
2825
|
+
...self2.workerOptions(controls),
|
|
2826
|
+
inputOwnership: "transfer",
|
|
2827
|
+
workerInBatches: true
|
|
2828
|
+
});
|
|
2829
|
+
} else {
|
|
2830
|
+
for await (const output of self2.runtime.stream(prepared(), options, self2.runtimeContext(controls))) {
|
|
2831
|
+
controls.signal?.throwIfAborted();
|
|
2832
|
+
yield clonePayload(output, controls.outputOwnership ?? "transfer");
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
completed = true;
|
|
2836
|
+
} catch (error) {
|
|
2837
|
+
if (self2.workerChannel) {
|
|
2838
|
+
self2.invalid = true;
|
|
2839
|
+
self2.operationQueue.cancelPending(error);
|
|
2840
|
+
self2.controller.abort(error);
|
|
2841
|
+
await self2.workerChannel.destroy(error);
|
|
2842
|
+
}
|
|
2843
|
+
if (self2.pool) {
|
|
2844
|
+
self2.invalid = true;
|
|
2845
|
+
await self2.pool.destroy(error);
|
|
2846
|
+
}
|
|
2847
|
+
throw error;
|
|
2848
|
+
} finally {
|
|
2849
|
+
if (self2.pool && !completed)
|
|
2850
|
+
self2.invalid = true;
|
|
2851
|
+
if (self2.workerChannel && !completed && !self2.invalid) {
|
|
2852
|
+
const reason = new Error("Worker stream ended before completion");
|
|
2853
|
+
self2.invalid = true;
|
|
2854
|
+
self2.operationQueue.cancelPending(reason);
|
|
2855
|
+
self2.controller.abort(reason);
|
|
2856
|
+
await self2.workerChannel.destroy(reason);
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
}, args[0]?.signal);
|
|
2860
|
+
}
|
|
2861
|
+
/** Lifecycle status of this initialized task. */
|
|
2862
|
+
get state() {
|
|
2863
|
+
if (this.invalid)
|
|
2864
|
+
return "invalid";
|
|
2865
|
+
if (this.finalized)
|
|
2866
|
+
return "closed";
|
|
2867
|
+
return this.closed ? "closing" : "ready";
|
|
2868
|
+
}
|
|
2869
|
+
/** Drain accepted work, invoke destroy, and release execution capacity. */
|
|
2870
|
+
close() {
|
|
2871
|
+
if (!this.closing) {
|
|
2872
|
+
this.closed = true;
|
|
2873
|
+
this.closing = (async () => {
|
|
2874
|
+
try {
|
|
2875
|
+
await this.operationQueue.close();
|
|
2876
|
+
if (!this.invalid)
|
|
2877
|
+
await this.invoke("destroy", {}, {});
|
|
2878
|
+
else if (!this.pool && !this.workerChannel)
|
|
2879
|
+
await this.runtime.destroy();
|
|
2880
|
+
} finally {
|
|
2881
|
+
try {
|
|
2882
|
+
await this.pool?.destroy();
|
|
2883
|
+
await this.workerChannel?.destroy();
|
|
2884
|
+
} finally {
|
|
2885
|
+
this.finalized = true;
|
|
2886
|
+
this.release();
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
})();
|
|
2890
|
+
}
|
|
2891
|
+
return this.closing;
|
|
2892
|
+
}
|
|
2893
|
+
/** Abort work. Local JavaScript must settle before its state can be destroyed. */
|
|
2894
|
+
async terminate(reason = new Error("Task terminated")) {
|
|
2895
|
+
this.operationQueue.cancelPending(reason);
|
|
2896
|
+
this.controller.abort(reason);
|
|
2897
|
+
if (this.workerChannel) {
|
|
2898
|
+
this.invalid = true;
|
|
2899
|
+
await this.workerChannel.destroy(reason);
|
|
2900
|
+
}
|
|
2901
|
+
if (this.pool) {
|
|
2902
|
+
this.invalid = true;
|
|
2903
|
+
await this.pool.destroy(reason);
|
|
2904
|
+
}
|
|
2905
|
+
await Promise.allSettled([...this.streams].map((stop) => stop()));
|
|
2906
|
+
await this.close();
|
|
2907
|
+
}
|
|
2908
|
+
checkCapability(kind) {
|
|
2909
|
+
if (this.pool || this.workerChannel ? !this.task.worker?.capabilities[kind] : !(kind === "atomic" ? this.task.process : this.task.processInBatches)) {
|
|
2910
|
+
throw new Error(`Task has no ${kind} processor for this execution route`);
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2913
|
+
controls(controls = {}) {
|
|
2914
|
+
if (controls.outputOwnership && !["copy", "transfer"].includes(controls.outputOwnership))
|
|
2915
|
+
throw new TypeError("Invalid output ownership");
|
|
2916
|
+
return {
|
|
2917
|
+
...controls,
|
|
2918
|
+
signal: controls.signal ? AbortSignal.any([controls.signal, this.controller.signal]) : this.controller.signal
|
|
2919
|
+
};
|
|
2920
|
+
}
|
|
2921
|
+
workerOptions(controls) {
|
|
2922
|
+
return {
|
|
2923
|
+
workerPool: this.pool,
|
|
2924
|
+
workerType: "module",
|
|
2925
|
+
inputOwnership: controls.inputOwnership ?? "copy",
|
|
2926
|
+
outputOwnership: controls.outputOwnership ?? "transfer",
|
|
2927
|
+
signal: controls.signal,
|
|
2928
|
+
onProgress: controls.onProgress,
|
|
2929
|
+
cancellationMode: "terminate"
|
|
2930
|
+
};
|
|
2931
|
+
}
|
|
2932
|
+
async invoke(operation, input, options, controls = {}) {
|
|
2933
|
+
if (this.invalid)
|
|
2934
|
+
throw new Error("Initialized task is invalid; initialize a new instance");
|
|
2935
|
+
const prepared = operation === "destroy" ? {} : this.controls(controls);
|
|
2936
|
+
prepared.signal?.throwIfAborted();
|
|
2937
|
+
assertPayload(input);
|
|
2938
|
+
assertNoTransferAlias(input, options, prepared.inputOwnership);
|
|
2939
|
+
const copiedOptions = clonePayload(options);
|
|
2940
|
+
if (this.workerChannel) {
|
|
2941
|
+
const progressId = this.nextProgressId++;
|
|
2942
|
+
const request = {
|
|
2943
|
+
input: clonePayload(input, prepared.inputOwnership),
|
|
2944
|
+
options: copiedOptions,
|
|
2945
|
+
outputOwnership: prepared.outputOwnership ?? "transfer",
|
|
2946
|
+
progressId
|
|
2947
|
+
};
|
|
2948
|
+
if (operation === "stream-open")
|
|
2949
|
+
this.streamProgressId = progressId;
|
|
2950
|
+
this.progressCallbacks.set(progressId, prepared.onProgress);
|
|
2951
|
+
let callbackFailure;
|
|
2952
|
+
try {
|
|
2953
|
+
const result2 = await this.workerChannel.channel.request(operation, request, prepared.signal, getTransferList(request));
|
|
2954
|
+
callbackFailure = this.callbackFailures.get(progressId) ?? (operation.startsWith("stream-") && this.streamProgressId !== void 0 ? this.callbackFailures.get(this.streamProgressId) : void 0);
|
|
2955
|
+
if (callbackFailure)
|
|
2956
|
+
throw callbackFailure.reason;
|
|
2957
|
+
return result2;
|
|
2958
|
+
} catch (reason) {
|
|
2959
|
+
if (operation === "process" && !prepared.signal?.aborted && (reason instanceof TaskRequestError || callbackFailure))
|
|
2960
|
+
throw reason;
|
|
2961
|
+
this.invalid = true;
|
|
2962
|
+
this.operationQueue.cancelPending(reason);
|
|
2963
|
+
this.controller.abort(reason);
|
|
2964
|
+
await this.workerChannel.destroy(reason);
|
|
2965
|
+
throw reason;
|
|
2966
|
+
} finally {
|
|
2967
|
+
this.progressCallbacks.delete(progressId);
|
|
2968
|
+
if (this.streamProgressId !== progressId)
|
|
2969
|
+
this.callbackFailures.delete(progressId);
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
if (this.pool) {
|
|
2973
|
+
try {
|
|
2974
|
+
return await processOnWorker(this.descriptor, { operation, input: clonePayload(input, prepared.inputOwnership), options: copiedOptions }, this.workerOptions({ ...prepared, inputOwnership: "transfer" }));
|
|
2975
|
+
} catch (error) {
|
|
2976
|
+
this.invalid = true;
|
|
2977
|
+
await this.pool.destroy(error);
|
|
2978
|
+
throw error;
|
|
2979
|
+
}
|
|
2980
|
+
}
|
|
2981
|
+
if (operation === "destroy")
|
|
2982
|
+
return this.runtime.destroy();
|
|
2983
|
+
const copied = clonePayload(input, prepared.inputOwnership);
|
|
2984
|
+
const context = this.runtimeContext(prepared);
|
|
2985
|
+
if (operation === "initialize") {
|
|
2986
|
+
const result2 = await this.runtime.initialize(copied, context);
|
|
2987
|
+
prepared.signal?.throwIfAborted();
|
|
2988
|
+
return result2;
|
|
2989
|
+
}
|
|
2990
|
+
const result = await this.runtime.process(copied, copiedOptions, context);
|
|
2991
|
+
prepared.signal?.throwIfAborted();
|
|
2992
|
+
return clonePayload(result, prepared.outputOwnership ?? "transfer");
|
|
2993
|
+
}
|
|
2994
|
+
runtimeContext(prepared) {
|
|
2995
|
+
return {
|
|
2996
|
+
...localContext(prepared),
|
|
2997
|
+
requestHost: async (operation, payload, controls = {}) => {
|
|
2998
|
+
const signal = prepared.signal ?? this.controller.signal;
|
|
2999
|
+
signal.throwIfAborted();
|
|
3000
|
+
const handler = this.initializationControls.onRequest;
|
|
3001
|
+
if (!handler)
|
|
3002
|
+
throw new Error("No host request handler configured");
|
|
3003
|
+
const result = await handler(operation, clonePayload(payload, controls.inputOwnership), signal);
|
|
3004
|
+
signal.throwIfAborted();
|
|
3005
|
+
return structuredClone(result, {
|
|
3006
|
+
transfer: controls.outputOwnership === "transfer" ? getTransferList(result) : []
|
|
3007
|
+
});
|
|
3008
|
+
},
|
|
3009
|
+
emitHost: (operation, payload) => this.initializationControls.onEvent?.(operation, structuredClone(payload))
|
|
3010
|
+
};
|
|
3011
|
+
}
|
|
3012
|
+
enqueue(operation) {
|
|
3013
|
+
if (this.closed)
|
|
3014
|
+
return Promise.reject(new Error("Initialized task is closed"));
|
|
3015
|
+
return this.operationQueue.run("exclusive", operation);
|
|
3016
|
+
}
|
|
3017
|
+
serialStream(operation, signal) {
|
|
3018
|
+
const waiting = new AbortController();
|
|
3019
|
+
const queueSignal = AbortSignal.any([waiting.signal, this.controller.signal, signal].filter((value) => Boolean(value)));
|
|
3020
|
+
let started = false;
|
|
3021
|
+
const iterator = this.acquireStream(operation, queueSignal, () => {
|
|
3022
|
+
started = true;
|
|
3023
|
+
});
|
|
3024
|
+
const cancelWaiting = () => {
|
|
3025
|
+
if (!started)
|
|
3026
|
+
waiting.abort(new Error("Stream returned before execution"));
|
|
3027
|
+
};
|
|
3028
|
+
return {
|
|
3029
|
+
[Symbol.asyncIterator]() {
|
|
3030
|
+
return this;
|
|
3031
|
+
},
|
|
3032
|
+
next: () => iterator.next(),
|
|
3033
|
+
return: async () => {
|
|
3034
|
+
cancelWaiting();
|
|
3035
|
+
return iterator.return(void 0);
|
|
3036
|
+
},
|
|
3037
|
+
throw: async (reason) => {
|
|
3038
|
+
cancelWaiting();
|
|
3039
|
+
return iterator.throw(reason);
|
|
3040
|
+
}
|
|
3041
|
+
};
|
|
3042
|
+
}
|
|
3043
|
+
async *acquireStream(operation, signal, onStart) {
|
|
3044
|
+
if (this.closed)
|
|
3045
|
+
throw new Error("Initialized task is closed");
|
|
3046
|
+
let acquire;
|
|
3047
|
+
const acquired = new Promise((resolve) => {
|
|
3048
|
+
acquire = resolve;
|
|
3049
|
+
});
|
|
3050
|
+
let release;
|
|
3051
|
+
const held = new Promise((resolve) => {
|
|
3052
|
+
release = resolve;
|
|
3053
|
+
});
|
|
3054
|
+
const lease = this.operationQueue.run("exclusive", async () => {
|
|
3055
|
+
acquire();
|
|
3056
|
+
await held;
|
|
3057
|
+
}, signal);
|
|
3058
|
+
await Promise.race([acquired, lease]);
|
|
3059
|
+
if (signal.aborted) {
|
|
3060
|
+
release();
|
|
3061
|
+
throw signal.reason;
|
|
3062
|
+
}
|
|
3063
|
+
onStart();
|
|
3064
|
+
const iterator = operation(this)[Symbol.asyncIterator]();
|
|
3065
|
+
let stopping;
|
|
3066
|
+
const stop = () => {
|
|
3067
|
+
stopping ?? (stopping = (async () => {
|
|
3068
|
+
try {
|
|
3069
|
+
await iterator.return?.();
|
|
3070
|
+
} finally {
|
|
3071
|
+
this.streams.delete(stop);
|
|
3072
|
+
release();
|
|
3073
|
+
}
|
|
3074
|
+
})());
|
|
3075
|
+
return stopping;
|
|
3076
|
+
};
|
|
3077
|
+
this.streams.add(stop);
|
|
3078
|
+
try {
|
|
3079
|
+
while (true) {
|
|
3080
|
+
this.controller.signal.throwIfAborted();
|
|
3081
|
+
const next = await iterator.next();
|
|
3082
|
+
if (next.done)
|
|
3083
|
+
return;
|
|
3084
|
+
yield next.value;
|
|
3085
|
+
}
|
|
3086
|
+
} finally {
|
|
3087
|
+
await stop();
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
};
|
|
3091
|
+
var TaskRunner = class {
|
|
3092
|
+
constructor(options = {}) {
|
|
3093
|
+
this.active = /* @__PURE__ */ new Set();
|
|
3094
|
+
this.count = 0;
|
|
3095
|
+
this.waiters = [];
|
|
3096
|
+
this.closed = false;
|
|
3097
|
+
this.initializing = /* @__PURE__ */ new Set();
|
|
3098
|
+
this.iterations = /* @__PURE__ */ new Set();
|
|
3099
|
+
this.maxConcurrency = options.maxConcurrency ?? 1;
|
|
3100
|
+
if (!Number.isSafeInteger(this.maxConcurrency) || this.maxConcurrency < 1)
|
|
3101
|
+
throw new RangeError("maxConcurrency must be a positive safe integer");
|
|
3102
|
+
}
|
|
3103
|
+
/** Execute synchronous hooks immediately on the calling thread, without queueing. */
|
|
3104
|
+
runTaskSync(task, input, ...args) {
|
|
3105
|
+
if (this.closed)
|
|
3106
|
+
throw new Error("Task runner is closed");
|
|
3107
|
+
if (this.count >= this.maxConcurrency)
|
|
3108
|
+
throw new Error("Task runner has no synchronous capacity");
|
|
3109
|
+
this.count++;
|
|
3110
|
+
try {
|
|
3111
|
+
return runTaskSync(task, input, args[0]);
|
|
3112
|
+
} finally {
|
|
3113
|
+
const waiter = this.waiters.shift();
|
|
3114
|
+
if (waiter)
|
|
3115
|
+
waiter.resolve();
|
|
3116
|
+
else
|
|
3117
|
+
this.count--;
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
initializeTask(task, initialization, controls = {}) {
|
|
3121
|
+
const pending2 = this.open(task, initialization, controls);
|
|
3122
|
+
this.initializing.add(pending2);
|
|
3123
|
+
void pending2.then(() => this.initializing.delete(pending2), () => this.initializing.delete(pending2));
|
|
3124
|
+
return pending2;
|
|
3125
|
+
}
|
|
3126
|
+
async runTask(task, input, ...args) {
|
|
3127
|
+
const request = args[0] ?? {};
|
|
3128
|
+
const handle = await this.initializeTask(task, request.initialization ?? {}, {
|
|
3129
|
+
...request,
|
|
3130
|
+
inputOwnership: request.initializationOwnership ?? "copy"
|
|
3131
|
+
});
|
|
3132
|
+
return finish(handle, () => handle.runTask(input, request));
|
|
3133
|
+
}
|
|
3134
|
+
async *runTasks(task, inputs, ...args) {
|
|
3135
|
+
const request = args[0] ?? {};
|
|
3136
|
+
if (this.closed)
|
|
3137
|
+
throw new Error("Task runner is closed");
|
|
3138
|
+
if (request.initializationOwnership === "transfer")
|
|
3139
|
+
throw new TypeError("runTasks initialization is a reusable template; use copy or share");
|
|
3140
|
+
const concurrency = request.concurrency ?? 1;
|
|
3141
|
+
if (!Number.isSafeInteger(concurrency) || concurrency < 1 || concurrency > this.maxConcurrency)
|
|
3142
|
+
throw new RangeError("concurrency must be between 1 and maxConcurrency");
|
|
3143
|
+
const handles = [];
|
|
3144
|
+
const busy = /* @__PURE__ */ new Set();
|
|
3145
|
+
const pending2 = [];
|
|
3146
|
+
const controller = new AbortController();
|
|
3147
|
+
this.iterations.add(controller);
|
|
3148
|
+
const signal = request.signal ? AbortSignal.any([request.signal, controller.signal]) : controller.signal;
|
|
3149
|
+
const iterator = asAsync(inputs, signal)[Symbol.asyncIterator]();
|
|
3150
|
+
let finished = false;
|
|
3151
|
+
let reading;
|
|
3152
|
+
try {
|
|
3153
|
+
while (!finished || pending2.length) {
|
|
3154
|
+
signal.throwIfAborted();
|
|
3155
|
+
if (!finished && !reading && pending2.length < concurrency) {
|
|
3156
|
+
reading = iterator.next().then((next) => ({ kind: "input", next }));
|
|
3157
|
+
}
|
|
3158
|
+
const event = await Promise.race([
|
|
3159
|
+
...pending2.length ? [pending2[0]] : [],
|
|
3160
|
+
...reading ? [reading] : []
|
|
3161
|
+
]);
|
|
3162
|
+
if (event.kind === "result") {
|
|
3163
|
+
pending2.shift();
|
|
3164
|
+
busy.delete(event.handle);
|
|
3165
|
+
if (event.failed)
|
|
3166
|
+
throw event.error;
|
|
3167
|
+
yield event.value;
|
|
3168
|
+
continue;
|
|
3169
|
+
}
|
|
3170
|
+
reading = void 0;
|
|
3171
|
+
if (event.next.done) {
|
|
3172
|
+
finished = true;
|
|
3173
|
+
continue;
|
|
3174
|
+
}
|
|
3175
|
+
let handle = handles.find((candidate) => !busy.has(candidate));
|
|
3176
|
+
if (!handle && (handles.length === 0 || this.count < this.maxConcurrency)) {
|
|
3177
|
+
handle = await this.initializeTask(task, clonePayload(request.initialization ?? {}, request.initializationOwnership), {
|
|
3178
|
+
...request,
|
|
3179
|
+
signal,
|
|
3180
|
+
inputOwnership: request.initializationOwnership ?? "copy"
|
|
3181
|
+
});
|
|
3182
|
+
handles.push(handle);
|
|
3183
|
+
}
|
|
3184
|
+
if (!handle) {
|
|
3185
|
+
const result = await pending2.shift();
|
|
3186
|
+
busy.delete(result.handle);
|
|
3187
|
+
if (result.failed)
|
|
3188
|
+
throw result.error;
|
|
3189
|
+
yield result.value;
|
|
3190
|
+
handle = result.handle;
|
|
3191
|
+
}
|
|
3192
|
+
busy.add(handle);
|
|
3193
|
+
const current = handle;
|
|
3194
|
+
pending2.push(handle.runTask(event.next.value, { ...request, signal }).then((value) => ({ kind: "result", handle: current, value }), (error) => ({ kind: "result", handle: current, failed: true, error })));
|
|
3195
|
+
}
|
|
3196
|
+
} finally {
|
|
3197
|
+
this.iterations.delete(controller);
|
|
3198
|
+
controller.abort(new Error("Task iteration closed"));
|
|
3199
|
+
try {
|
|
3200
|
+
if (reading)
|
|
3201
|
+
await reading.catch(() => {
|
|
3202
|
+
});
|
|
3203
|
+
if (!finished)
|
|
3204
|
+
await iterator.return?.();
|
|
3205
|
+
} finally {
|
|
3206
|
+
await Promise.all(pending2);
|
|
3207
|
+
await Promise.all(handles.map((handle) => handle.close()));
|
|
3208
|
+
}
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
async *runTaskInBatches(task, inputs, ...args) {
|
|
3212
|
+
const request = args[0] ?? {};
|
|
3213
|
+
const handle = await this.initializeTask(task, request.initialization ?? {}, {
|
|
3214
|
+
...request,
|
|
3215
|
+
inputOwnership: request.initializationOwnership ?? "copy"
|
|
3216
|
+
});
|
|
3217
|
+
try {
|
|
3218
|
+
yield* handle.runTaskInBatches(inputs, request);
|
|
3219
|
+
} finally {
|
|
3220
|
+
await handle.close();
|
|
3221
|
+
}
|
|
3222
|
+
}
|
|
3223
|
+
/** Close owned handles and workers. Finish or return active iterators first. */
|
|
3224
|
+
close() {
|
|
3225
|
+
if (!this.closing) {
|
|
3226
|
+
this.closed = true;
|
|
3227
|
+
for (const waiter of this.waiters.splice(0))
|
|
3228
|
+
waiter.reject(new Error("Task runner is closed"));
|
|
3229
|
+
this.closing = (async () => {
|
|
3230
|
+
await Promise.allSettled(this.initializing);
|
|
3231
|
+
const results = await Promise.allSettled([...this.active].map((handle) => handle.close()));
|
|
3232
|
+
const failure = results.find((result) => result.status === "rejected");
|
|
3233
|
+
if (failure?.status === "rejected")
|
|
3234
|
+
throw failure.reason;
|
|
3235
|
+
})();
|
|
3236
|
+
}
|
|
3237
|
+
return this.closing;
|
|
3238
|
+
}
|
|
3239
|
+
async terminate(reason = new Error("Task runner terminated")) {
|
|
3240
|
+
for (const controller of this.iterations)
|
|
3241
|
+
controller.abort(reason);
|
|
3242
|
+
const closing = this.close();
|
|
3243
|
+
await Promise.allSettled([...this.active].map((handle) => handle.terminate(reason)));
|
|
3244
|
+
await closing;
|
|
3245
|
+
}
|
|
3246
|
+
async open(task, initialization, controls) {
|
|
3247
|
+
if (this.closed)
|
|
3248
|
+
throw new Error("Task runner is closed");
|
|
3249
|
+
controls.signal?.throwIfAborted();
|
|
3250
|
+
if (this.count >= this.maxConcurrency) {
|
|
3251
|
+
await new Promise((resolve, reject) => {
|
|
3252
|
+
const waiter = {
|
|
3253
|
+
resolve: () => {
|
|
3254
|
+
cleanup();
|
|
3255
|
+
resolve();
|
|
3256
|
+
},
|
|
3257
|
+
reject: (error) => {
|
|
3258
|
+
cleanup();
|
|
3259
|
+
reject(error);
|
|
3260
|
+
}
|
|
3261
|
+
};
|
|
3262
|
+
const abort = () => {
|
|
3263
|
+
this.waiters = this.waiters.filter((item) => item !== waiter);
|
|
3264
|
+
waiter.reject(controls.signal?.reason);
|
|
3265
|
+
};
|
|
3266
|
+
const cleanup = () => controls.signal?.removeEventListener("abort", abort);
|
|
3267
|
+
this.waiters.push(waiter);
|
|
3268
|
+
controls.signal?.addEventListener("abort", abort, { once: true });
|
|
3269
|
+
if (controls.signal?.aborted)
|
|
3270
|
+
abort();
|
|
3271
|
+
});
|
|
3272
|
+
} else
|
|
3273
|
+
this.count++;
|
|
3274
|
+
let handle;
|
|
3275
|
+
let released = false;
|
|
3276
|
+
const release = () => {
|
|
3277
|
+
if (released)
|
|
3278
|
+
return;
|
|
3279
|
+
released = true;
|
|
3280
|
+
if (handle)
|
|
3281
|
+
this.active.delete(handle);
|
|
3282
|
+
const waiter = this.waiters.shift();
|
|
3283
|
+
if (waiter)
|
|
3284
|
+
waiter.resolve();
|
|
3285
|
+
else
|
|
3286
|
+
this.count--;
|
|
3287
|
+
};
|
|
3288
|
+
try {
|
|
3289
|
+
if (this.closed)
|
|
3290
|
+
throw new Error("Task runner is closed");
|
|
3291
|
+
handle = new InitializedTask(task, release, controls);
|
|
3292
|
+
this.active.add(handle);
|
|
3293
|
+
await handle.initialize(initialization, controls);
|
|
3294
|
+
return handle;
|
|
3295
|
+
} catch (error) {
|
|
3296
|
+
release();
|
|
3297
|
+
throw error;
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
};
|
|
3301
|
+
async function finish(handle, operation) {
|
|
3302
|
+
let result;
|
|
3303
|
+
try {
|
|
3304
|
+
result = await operation();
|
|
3305
|
+
} catch (error) {
|
|
3306
|
+
try {
|
|
3307
|
+
await handle.close();
|
|
3308
|
+
} catch (cleanup) {
|
|
3309
|
+
throw new AggregateError([error, cleanup], "Task processing and destruction failed");
|
|
3310
|
+
}
|
|
3311
|
+
throw error;
|
|
3312
|
+
}
|
|
3313
|
+
await handle.close();
|
|
3314
|
+
return result;
|
|
3315
|
+
}
|
|
3316
|
+
async function* asAsync(inputs, signal) {
|
|
3317
|
+
const iterator = Symbol.asyncIterator in inputs ? inputs[Symbol.asyncIterator]() : inputs[Symbol.iterator]();
|
|
3318
|
+
let done = false;
|
|
3319
|
+
let blocked = false;
|
|
3320
|
+
try {
|
|
3321
|
+
while (true) {
|
|
3322
|
+
const next = await new Promise((resolve, reject) => {
|
|
3323
|
+
const cleanup = () => signal?.removeEventListener("abort", abort);
|
|
3324
|
+
const abort = () => {
|
|
3325
|
+
cleanup();
|
|
3326
|
+
reject(signal?.reason);
|
|
3327
|
+
};
|
|
3328
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
3329
|
+
if (signal?.aborted) {
|
|
3330
|
+
abort();
|
|
3331
|
+
return;
|
|
3332
|
+
}
|
|
3333
|
+
try {
|
|
3334
|
+
blocked = true;
|
|
3335
|
+
Promise.resolve(iterator.next()).then((value) => {
|
|
3336
|
+
blocked = false;
|
|
3337
|
+
cleanup();
|
|
3338
|
+
resolve(value);
|
|
3339
|
+
}, (error) => {
|
|
3340
|
+
blocked = false;
|
|
3341
|
+
cleanup();
|
|
3342
|
+
reject(error);
|
|
3343
|
+
});
|
|
3344
|
+
} catch (error) {
|
|
3345
|
+
blocked = false;
|
|
3346
|
+
cleanup();
|
|
3347
|
+
reject(error);
|
|
3348
|
+
}
|
|
3349
|
+
});
|
|
3350
|
+
if (next.done) {
|
|
3351
|
+
done = true;
|
|
3352
|
+
return;
|
|
3353
|
+
}
|
|
3354
|
+
yield next.value;
|
|
3355
|
+
}
|
|
3356
|
+
} finally {
|
|
3357
|
+
if (!done) {
|
|
3358
|
+
if (blocked) {
|
|
3359
|
+
try {
|
|
3360
|
+
void Promise.resolve(iterator.return?.()).catch(() => {
|
|
3361
|
+
});
|
|
3362
|
+
} catch {
|
|
3363
|
+
}
|
|
3364
|
+
} else {
|
|
3365
|
+
await iterator.return?.();
|
|
3366
|
+
}
|
|
3367
|
+
}
|
|
3368
|
+
}
|
|
3369
|
+
}
|
|
3370
|
+
function assertNoTransferAlias(input, options, ownership) {
|
|
3371
|
+
if (ownership === "transfer") {
|
|
3372
|
+
const metadata = new Set(getTransferList(options));
|
|
3373
|
+
if (getTransferList(input).some((buffer) => metadata.has(buffer))) {
|
|
3374
|
+
throw new Error("Transferred input aliases reusable options; use inputOwnership: copy");
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
|
|
3379
|
+
// ../core/src/worker-utils/lib/worker-api/get-worker-url.ts
|
|
3380
|
+
var warnedWorkerVersionFallbacks2 = /* @__PURE__ */ new Set();
|
|
3381
|
+
function getCustomWorkerURL2(worker, options = {}) {
|
|
3382
|
+
const workerFile = isBrowser ? worker.workerFile || `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
|
|
3383
|
+
let url = getConfiguredWorkerURL2(worker, options);
|
|
3384
|
+
const workerType = options._workerType || options?.core?._workerType;
|
|
3385
|
+
if (!url && workerType === "test") {
|
|
3386
|
+
if (isBrowser) {
|
|
3387
|
+
url = `modules/${worker.module}/dist/${workerFile}`;
|
|
3388
|
+
} else {
|
|
3389
|
+
const workerSourceDirectory = worker.module === "core" && worker.workerNode?.startsWith("worker-utils/") ? "worker-utils/workers" : "workers";
|
|
3390
|
+
const workerSourceNode = worker.workerSourceNode || `${workerSourceDirectory}/${worker.id}-worker-node.ts`;
|
|
3391
|
+
url = `modules/${worker.module}/src/${workerSourceNode}`;
|
|
3392
|
+
}
|
|
3393
|
+
}
|
|
3394
|
+
return url || null;
|
|
3395
|
+
}
|
|
3396
|
+
function getConfiguredWorkerURL2(worker, options = {}) {
|
|
3397
|
+
const workerOptions = options[worker.id] || {};
|
|
3398
|
+
return workerOptions.workerUrl || (worker.id === "compression" ? options.workerUrl : null) || null;
|
|
3399
|
+
}
|
|
3400
|
+
function getWorkerURL2(worker, options = {}) {
|
|
3401
|
+
const customWorkerUrl = getCustomWorkerURL2(worker, options);
|
|
3402
|
+
const descriptorWorkerUrl = typeof worker.worker === "string" ? worker.worker : null;
|
|
3403
|
+
const url = customWorkerUrl || descriptorWorkerUrl || getDefaultWorkerURL2(worker, true);
|
|
3404
|
+
assert(url);
|
|
3405
|
+
return url;
|
|
3406
|
+
}
|
|
3407
|
+
function getDefaultWorkerURL2(worker, warn = false) {
|
|
3408
|
+
const workerFile = isBrowser ? worker.workerFile || `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
|
|
3409
|
+
let version = worker.version;
|
|
3410
|
+
if (version === "latest") {
|
|
3411
|
+
version = NPM_TAG;
|
|
3412
|
+
}
|
|
3413
|
+
const versionTag = version ? `@${version}` : "";
|
|
3414
|
+
const url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;
|
|
3415
|
+
if (warn) {
|
|
3416
|
+
warnIfUsingNpmTagFallback2(worker, url);
|
|
3417
|
+
}
|
|
3418
|
+
return url;
|
|
3419
|
+
}
|
|
3420
|
+
function warnIfUsingNpmTagFallback2(worker, url) {
|
|
3421
|
+
if (worker.version !== "latest") {
|
|
3422
|
+
return;
|
|
3423
|
+
}
|
|
3424
|
+
const workerId = `${worker.module}:${worker.id}`;
|
|
3425
|
+
if (warnedWorkerVersionFallbacks2.has(workerId)) {
|
|
3426
|
+
return;
|
|
3427
|
+
}
|
|
3428
|
+
warnedWorkerVersionFallbacks2.add(workerId);
|
|
3429
|
+
console.warn(
|
|
3430
|
+
`loaders.gl: ${worker.name} loader worker version is "latest" because __VERSION__ was not injected. Fetching ${url} from CDN.`
|
|
3431
|
+
);
|
|
3432
|
+
}
|
|
3433
|
+
|
|
3434
|
+
// ../core/src/worker-utils/lib/worker-api/task-runtime.ts
|
|
3435
|
+
function normalizeTaskProgress(progress) {
|
|
3436
|
+
return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
|
|
3437
|
+
}
|
|
3438
|
+
async function isWorkerThread() {
|
|
3439
|
+
if (typeof self !== "undefined" && typeof document === "undefined" && typeof self.postMessage === "function")
|
|
3440
|
+
return true;
|
|
3441
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
3442
|
+
const { isMainThread } = await Promise.resolve().then(() => (init_worker_threads_browser(), worker_threads_browser_exports));
|
|
3443
|
+
return !isMainThread;
|
|
3444
|
+
}
|
|
3445
|
+
return false;
|
|
3446
|
+
}
|
|
3447
|
+
var initializeTaskWorker2 = initializeTaskWorker;
|
|
3448
|
+
|
|
3449
|
+
// ../core/src/worker-utils/lib/worker-utils/get-transfer-list.ts
|
|
3450
|
+
function getTransferList2(object, recursive = true, transfers) {
|
|
3451
|
+
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
3452
|
+
if (!object) {
|
|
3453
|
+
} else if (isTransferable2(object)) {
|
|
3454
|
+
transfersSet.add(object);
|
|
3455
|
+
} else if (isTransferable2(object.buffer)) {
|
|
3456
|
+
transfersSet.add(object.buffer);
|
|
3457
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
3458
|
+
} else if (recursive && typeof object === "object") {
|
|
3459
|
+
for (const key in object) {
|
|
3460
|
+
getTransferList2(object[key], recursive, transfersSet);
|
|
3461
|
+
}
|
|
3462
|
+
}
|
|
3463
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
3464
|
+
}
|
|
3465
|
+
function isTransferable2(object) {
|
|
3466
|
+
if (!object) {
|
|
3467
|
+
return false;
|
|
3468
|
+
}
|
|
3469
|
+
if (object instanceof ArrayBuffer) {
|
|
3470
|
+
return true;
|
|
3471
|
+
}
|
|
3472
|
+
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
3473
|
+
return true;
|
|
3474
|
+
}
|
|
3475
|
+
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
3476
|
+
return true;
|
|
3477
|
+
}
|
|
3478
|
+
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
3479
|
+
return true;
|
|
3480
|
+
}
|
|
3481
|
+
return false;
|
|
3482
|
+
}
|
|
3483
|
+
function getTransferListForWriter2(object) {
|
|
3484
|
+
if (object === null) {
|
|
3485
|
+
return {};
|
|
3486
|
+
}
|
|
3487
|
+
const clone = Object.assign({}, object);
|
|
3488
|
+
Object.keys(clone).forEach((key) => {
|
|
3489
|
+
if (object[key] !== null && typeof object[key] === "object" && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) {
|
|
3490
|
+
clone[key] = getTransferListForWriter2(object[key]);
|
|
3491
|
+
} else if (typeof clone[key] === "function" || clone[key] instanceof RegExp) {
|
|
3492
|
+
clone[key] = {};
|
|
3493
|
+
} else {
|
|
3494
|
+
clone[key] = object[key];
|
|
3495
|
+
}
|
|
3496
|
+
});
|
|
3497
|
+
return clone;
|
|
3498
|
+
}
|
|
3499
|
+
|
|
3500
|
+
// ../core/src/worker-utils/lib/worker-api/process-on-worker.ts
|
|
3501
|
+
var runners = /* @__PURE__ */ new WeakMap();
|
|
3502
|
+
var activeRunners = /* @__PURE__ */ new Set();
|
|
3503
|
+
var moduleWorkerUrls = /* @__PURE__ */ new Map();
|
|
3504
|
+
function canProcessOnWorker2(worker, options = {}) {
|
|
3505
|
+
const supported = isBrowser ? typeof Worker !== "undefined" : Boolean(options._nodeWorkers);
|
|
3506
|
+
return Boolean(
|
|
3507
|
+
supported && options.worker && (worker.worker || worker.loadWorker || getConfiguredWorkerURL2(worker, options))
|
|
3508
|
+
);
|
|
3509
|
+
}
|
|
3510
|
+
async function* processOnWorkerInBatches2(worker, input, options = {}, context = {}, jobContext = {}) {
|
|
3511
|
+
const taskInput = wrapInput(input);
|
|
3512
|
+
let session;
|
|
3513
|
+
try {
|
|
3514
|
+
session = await openSession(worker, options, context, jobContext);
|
|
3515
|
+
for await (const result of session.handle.runTaskInBatches(taskInput, {
|
|
3516
|
+
...getControls(options),
|
|
3517
|
+
options: getParserOptions(options)
|
|
3518
|
+
}))
|
|
3519
|
+
yield result.value;
|
|
3520
|
+
} finally {
|
|
3521
|
+
const closingInput = taskInput.return?.();
|
|
3522
|
+
void closingInput?.catch(() => {
|
|
3523
|
+
});
|
|
3524
|
+
await session?.close();
|
|
3525
|
+
}
|
|
3526
|
+
}
|
|
3527
|
+
function getTask(worker, options) {
|
|
3528
|
+
if (options.source || options.core?.source)
|
|
3529
|
+
throw new Error(
|
|
3530
|
+
"Inline legacy worker source is unsupported; use a TaskRunner worker URL or factory"
|
|
3531
|
+
);
|
|
3532
|
+
const create = !getCustomWorkerURL2(worker, options) && isBrowser ? worker.loadWorker : void 0;
|
|
3533
|
+
const url = getWorkerURL2(worker, options);
|
|
3534
|
+
return {
|
|
3535
|
+
id: `${worker.module}:${worker.id}`,
|
|
3536
|
+
initialize: (state) => state,
|
|
3537
|
+
worker: {
|
|
3538
|
+
...create ? { create: () => create() ?? createModuleWorker(url) } : { url },
|
|
3539
|
+
capabilities: { atomic: true, streaming: true }
|
|
3540
|
+
}
|
|
3541
|
+
};
|
|
3542
|
+
}
|
|
3543
|
+
function getControls(options) {
|
|
3544
|
+
return {
|
|
3545
|
+
execution: "worker",
|
|
3546
|
+
signal: options.signal,
|
|
3547
|
+
inputOwnership: options.inputOwnership ?? "transfer",
|
|
3548
|
+
outputOwnership: options.outputOwnership ?? "transfer",
|
|
3549
|
+
onProgress: options.onProgress ? (progress) => options.onProgress?.(normalizeTaskProgress(progress)) : void 0
|
|
3550
|
+
};
|
|
3551
|
+
}
|
|
3552
|
+
function getParserOptions(options) {
|
|
3553
|
+
const { signal, onProgress, ...parserOptions } = options;
|
|
3554
|
+
return getTransferListForWriter2(parserOptions);
|
|
3555
|
+
}
|
|
3556
|
+
async function openSession(worker, options, context, jobContext) {
|
|
3557
|
+
options.signal?.throwIfAborted();
|
|
3558
|
+
const task = getTask(worker, options);
|
|
3559
|
+
let state = runners.get(worker);
|
|
3560
|
+
if (!state) {
|
|
3561
|
+
state = {
|
|
3562
|
+
runner: new TaskRunner({
|
|
3563
|
+
maxConcurrency: isMobile ? options.maxMobileConcurrency ?? 1 : options.maxConcurrency ?? 3
|
|
3564
|
+
}),
|
|
3565
|
+
requests: 0
|
|
3566
|
+
};
|
|
3567
|
+
runners.set(worker, state);
|
|
3568
|
+
}
|
|
3569
|
+
const runnerState = state;
|
|
3570
|
+
const channel = context.process ? new MessageChannel() : void 0;
|
|
3571
|
+
const callbackController = new AbortController();
|
|
3572
|
+
let channelClosed = false;
|
|
3573
|
+
const abortCallbacks = () => callbackController.abort(options.signal?.reason);
|
|
3574
|
+
options.signal?.addEventListener("abort", abortCallbacks, { once: true });
|
|
3575
|
+
const closeChannel = () => {
|
|
3576
|
+
channelClosed = true;
|
|
3577
|
+
options.signal?.removeEventListener("abort", abortCallbacks);
|
|
3578
|
+
callbackController.abort();
|
|
3579
|
+
channel?.port1.close();
|
|
3580
|
+
channel?.port2.close();
|
|
3581
|
+
};
|
|
3582
|
+
if (channel) {
|
|
3583
|
+
channel.port1.onmessage = async ({ data }) => {
|
|
3584
|
+
try {
|
|
3585
|
+
const value = await context.process(
|
|
3586
|
+
data.input,
|
|
3587
|
+
data.options,
|
|
3588
|
+
{
|
|
3589
|
+
signal: callbackController.signal,
|
|
3590
|
+
throwIfAborted: () => callbackController.signal.throwIfAborted()
|
|
3591
|
+
},
|
|
3592
|
+
data.context
|
|
3593
|
+
);
|
|
3594
|
+
if (!channelClosed && !callbackController.signal.aborted)
|
|
3595
|
+
channel.port1.postMessage({ identifier: data.identifier, value }, getTransferList2(value));
|
|
3596
|
+
} catch (error) {
|
|
3597
|
+
if (channelClosed || callbackController.signal.aborted) return;
|
|
3598
|
+
channel.port1.postMessage({
|
|
3599
|
+
identifier: data.identifier,
|
|
3600
|
+
error: {
|
|
3601
|
+
name: error instanceof Error ? error.name : "Error",
|
|
3602
|
+
message: error instanceof Error ? error.message : String(error)
|
|
3603
|
+
}
|
|
3604
|
+
});
|
|
3605
|
+
}
|
|
3606
|
+
};
|
|
3607
|
+
channel.port1.start();
|
|
3608
|
+
}
|
|
3609
|
+
runnerState.requests++;
|
|
3610
|
+
activeRunners.add(runnerState);
|
|
3611
|
+
let released = false;
|
|
3612
|
+
const releaseRunner = () => {
|
|
3613
|
+
if (released) return;
|
|
3614
|
+
released = true;
|
|
3615
|
+
runnerState.requests--;
|
|
3616
|
+
if (!runnerState.requests) activeRunners.delete(runnerState);
|
|
3617
|
+
};
|
|
3618
|
+
let handle;
|
|
3619
|
+
try {
|
|
3620
|
+
handle = await runnerState.runner.initializeTask(
|
|
3621
|
+
task,
|
|
3622
|
+
{
|
|
3623
|
+
context: structuredClone(jobContext),
|
|
3624
|
+
...channel ? { port: channel.port2 } : {}
|
|
3625
|
+
},
|
|
3626
|
+
// The callback port is setup state, independent of the caller's payload ownership.
|
|
3627
|
+
{ ...getControls(options), inputOwnership: "transfer" }
|
|
3628
|
+
);
|
|
3629
|
+
} catch (error) {
|
|
3630
|
+
releaseRunner();
|
|
3631
|
+
closeChannel();
|
|
3632
|
+
throw error;
|
|
3633
|
+
}
|
|
3634
|
+
return {
|
|
3635
|
+
handle,
|
|
3636
|
+
/** Releases the worker and callback channel on success, failure, and early stream return. */
|
|
3637
|
+
async close() {
|
|
3638
|
+
try {
|
|
3639
|
+
await handle.close();
|
|
3640
|
+
} finally {
|
|
3641
|
+
closeChannel();
|
|
3642
|
+
releaseRunner();
|
|
3643
|
+
}
|
|
3644
|
+
}
|
|
3645
|
+
};
|
|
3646
|
+
}
|
|
3647
|
+
function wrapInput(input) {
|
|
3648
|
+
const iterator = Symbol.asyncIterator in input ? input[Symbol.asyncIterator]() : input[Symbol.iterator]();
|
|
3649
|
+
let inputClosed = false;
|
|
3650
|
+
return {
|
|
3651
|
+
[Symbol.asyncIterator]() {
|
|
3652
|
+
return this;
|
|
3653
|
+
},
|
|
3654
|
+
async next() {
|
|
3655
|
+
if (inputClosed) return { done: true, value: void 0 };
|
|
3656
|
+
const next = await iterator.next();
|
|
3657
|
+
if (next.done || inputClosed) {
|
|
3658
|
+
inputClosed = true;
|
|
3659
|
+
return { done: true, value: void 0 };
|
|
3660
|
+
}
|
|
3661
|
+
return { done: false, value: { value: next.value } };
|
|
3662
|
+
},
|
|
3663
|
+
async return() {
|
|
3664
|
+
if (!inputClosed) {
|
|
3665
|
+
inputClosed = true;
|
|
3666
|
+
await iterator.return?.();
|
|
3667
|
+
}
|
|
3668
|
+
return { done: true, value: void 0 };
|
|
3669
|
+
}
|
|
3670
|
+
};
|
|
3671
|
+
}
|
|
3672
|
+
function createModuleWorker(url) {
|
|
3673
|
+
const resolved = new URL(url, globalThis.document?.baseURI ?? globalThis.location.href);
|
|
3674
|
+
let workerUrl = resolved.href;
|
|
3675
|
+
if (/^https?:$/.test(resolved.protocol) && resolved.origin !== globalThis.location.origin) {
|
|
3676
|
+
let shimUrl = moduleWorkerUrls.get(resolved.href);
|
|
3677
|
+
if (!shimUrl) {
|
|
3678
|
+
shimUrl = URL.createObjectURL(
|
|
3679
|
+
new Blob([`import ${JSON.stringify(resolved.href)};`], { type: "application/javascript" })
|
|
3680
|
+
);
|
|
3681
|
+
moduleWorkerUrls.set(resolved.href, shimUrl);
|
|
3682
|
+
}
|
|
3683
|
+
workerUrl = shimUrl;
|
|
3684
|
+
}
|
|
3685
|
+
return new Worker(workerUrl, { type: "module" });
|
|
3686
|
+
}
|
|
3687
|
+
|
|
3688
|
+
// ../core/src/worker-utils/lib/worker-api/create-worker.ts
|
|
3689
|
+
async function createWorker2(process2, processInBatches) {
|
|
3690
|
+
if (!await isWorkerThread()) return;
|
|
3691
|
+
await initializeTaskWorker2(createWorkerTask(process2, processInBatches));
|
|
3692
|
+
}
|
|
3693
|
+
function createWorkerTask(process2, processInBatches) {
|
|
3694
|
+
return {
|
|
3695
|
+
id: "loaders.gl",
|
|
3696
|
+
initialize: (state) => state,
|
|
3697
|
+
destroy: (state) => state.port?.close(),
|
|
3698
|
+
process: async ({ value }, options, context) => {
|
|
3699
|
+
if (!process2) throw new Error("Worker does not support atomic processing");
|
|
3700
|
+
return { value: await process2(value, options, createContext(context), context.state.context) };
|
|
3701
|
+
},
|
|
3702
|
+
...processInBatches ? {
|
|
3703
|
+
processInBatches: async function* (inputs, options, context) {
|
|
3704
|
+
async function* values() {
|
|
3705
|
+
for await (const input of inputs) yield input.value;
|
|
3706
|
+
}
|
|
3707
|
+
for await (const value of processInBatches(
|
|
3708
|
+
values(),
|
|
3709
|
+
options,
|
|
3710
|
+
createContext(context),
|
|
3711
|
+
context.state.context
|
|
3712
|
+
)) {
|
|
3713
|
+
yield { value };
|
|
3714
|
+
}
|
|
3715
|
+
}
|
|
3716
|
+
} : {}
|
|
3717
|
+
};
|
|
3718
|
+
}
|
|
3719
|
+
function createContext(context) {
|
|
3720
|
+
let requestIdentifier = 0;
|
|
3721
|
+
const port = context.state.port;
|
|
3722
|
+
return {
|
|
3723
|
+
signal: context.signal,
|
|
3724
|
+
throwIfAborted: () => context.throwIfAborted(),
|
|
3725
|
+
reportProgress: (progress) => context.reportProgress(normalizeTaskProgress(progress)),
|
|
3726
|
+
process: port ? (input, options = {}, jobContext = {}) => {
|
|
3727
|
+
context.throwIfAborted();
|
|
3728
|
+
const identifier = ++requestIdentifier;
|
|
3729
|
+
return new Promise((resolve, reject) => {
|
|
3730
|
+
const onMessage2 = (event) => {
|
|
3731
|
+
if (event.data.identifier !== identifier) return;
|
|
3732
|
+
cleanup();
|
|
3733
|
+
if (event.data.error) {
|
|
3734
|
+
const error = new Error(event.data.error.message);
|
|
3735
|
+
error.name = event.data.error.name;
|
|
3736
|
+
reject(error);
|
|
3737
|
+
} else resolve(event.data.value);
|
|
3738
|
+
};
|
|
3739
|
+
const onAbort = () => {
|
|
3740
|
+
cleanup();
|
|
3741
|
+
reject(context.signal.reason);
|
|
3742
|
+
};
|
|
3743
|
+
const cleanup = () => {
|
|
3744
|
+
port.removeEventListener("message", onMessage2);
|
|
3745
|
+
context.signal.removeEventListener("abort", onAbort);
|
|
3746
|
+
};
|
|
3747
|
+
port.addEventListener("message", onMessage2);
|
|
3748
|
+
context.signal.addEventListener("abort", onAbort, { once: true });
|
|
3749
|
+
port.start();
|
|
3750
|
+
try {
|
|
3751
|
+
const request = { identifier, input, options, context: jobContext };
|
|
3752
|
+
port.postMessage(request, getTransferList2(request));
|
|
3753
|
+
} catch (error) {
|
|
3754
|
+
cleanup();
|
|
3755
|
+
reject(error);
|
|
3756
|
+
}
|
|
3757
|
+
});
|
|
3758
|
+
} : void 0
|
|
3759
|
+
};
|
|
3760
|
+
}
|
|
3761
|
+
|
|
3762
|
+
// ../core/src/worker-utils/lib/library-utils/library-utils.ts
|
|
3763
|
+
var loadLibraryPromises = {};
|
|
3764
|
+
function extractLoadLibraryOptions(options = {}) {
|
|
3765
|
+
const useLocalLibraries = options.useLocalLibraries ?? options.core?.useLocalLibraries;
|
|
3766
|
+
const CDN = getCDNOption(options.CDN, options.core?.CDN);
|
|
3767
|
+
const modules = options.modules;
|
|
3768
|
+
return {
|
|
3769
|
+
...useLocalLibraries !== void 0 ? { useLocalLibraries } : {},
|
|
3770
|
+
...CDN !== void 0 ? { CDN } : {},
|
|
3771
|
+
...modules !== void 0 ? { modules } : {}
|
|
3772
|
+
};
|
|
3773
|
+
}
|
|
3774
|
+
function getCDNOption(cdn, coreCDN) {
|
|
3775
|
+
if (typeof cdn === "string" || cdn === null) {
|
|
3776
|
+
return cdn;
|
|
3777
|
+
}
|
|
3778
|
+
if (typeof coreCDN === "string" || coreCDN === null) {
|
|
3779
|
+
return coreCDN;
|
|
3780
|
+
}
|
|
3781
|
+
return void 0;
|
|
3782
|
+
}
|
|
3783
|
+
async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null, moduleLibraryName = null) {
|
|
3784
|
+
let moduleLibraryUrl = libraryUrl;
|
|
3785
|
+
if (moduleName) {
|
|
3786
|
+
const requestedLibraryName = libraryName || libraryUrl;
|
|
3787
|
+
const injectedLibrary = options.modules?.[requestedLibraryName];
|
|
3788
|
+
if (injectedLibrary !== void 0 && typeof injectedLibrary !== "string") {
|
|
3789
|
+
return injectedLibrary;
|
|
3790
|
+
}
|
|
3791
|
+
libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName);
|
|
3792
|
+
const hasLibraryOverride = typeof injectedLibrary === "string";
|
|
3793
|
+
moduleLibraryUrl = moduleLibraryName && (!hasLibraryOverride || typeof options.modules?.[moduleLibraryName] === "string") ? getLibraryUrl(moduleLibraryName, moduleName, options, moduleLibraryName) : libraryUrl;
|
|
3794
|
+
}
|
|
3795
|
+
const cacheKey = getLibraryCacheKey(libraryUrl, moduleLibraryUrl, isWorker);
|
|
3796
|
+
loadLibraryPromises[cacheKey] = // eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
3797
|
+
loadLibraryPromises[cacheKey] || loadLibraryFromFile(libraryUrl, moduleLibraryUrl);
|
|
3798
|
+
return await loadLibraryPromises[cacheKey];
|
|
3799
|
+
}
|
|
3800
|
+
function getLibraryCacheKey(libraryUrl, moduleLibraryUrl, worker) {
|
|
3801
|
+
return worker ? JSON.stringify([libraryUrl, moduleLibraryUrl]) : libraryUrl;
|
|
3802
|
+
}
|
|
3803
|
+
function getLibraryUrl(library, moduleName, options = {}, libraryName = null) {
|
|
3804
|
+
if (options?.core) {
|
|
3805
|
+
throw new Error("loadLibrary: options.core must be pre-normalized");
|
|
3806
|
+
}
|
|
3807
|
+
libraryName = libraryName || library;
|
|
3808
|
+
const modules = options.modules || {};
|
|
3809
|
+
if (typeof modules[libraryName] === "string") {
|
|
3810
|
+
return modules[libraryName];
|
|
3811
|
+
}
|
|
3812
|
+
if (!options.useLocalLibraries && library.startsWith("http")) {
|
|
3813
|
+
return library;
|
|
3814
|
+
}
|
|
3815
|
+
if (!isBrowser) {
|
|
3816
|
+
return `modules/${moduleName}/dist/libs/${libraryName}`;
|
|
3817
|
+
}
|
|
3818
|
+
if (options.CDN) {
|
|
3819
|
+
if (typeof options.CDN !== "string") {
|
|
3820
|
+
throw new Error("loadLibrary: options.CDN must be a string or null");
|
|
3821
|
+
}
|
|
3822
|
+
assert(options.CDN.startsWith("http"));
|
|
3823
|
+
return `${options.CDN}/${moduleName}@${VERSION}/dist/libs/${libraryName}`;
|
|
3824
|
+
}
|
|
3825
|
+
if (isWorker) {
|
|
3826
|
+
return libraryName.endsWith(".mjs") ? `./libs/${libraryName}` : `../src/libs/${libraryName}`;
|
|
3827
|
+
}
|
|
3828
|
+
return `modules/${moduleName}/src/libs/${libraryName}`;
|
|
3829
|
+
}
|
|
3830
|
+
async function loadLibraryFromFile(libraryUrl, moduleLibraryUrl) {
|
|
3831
|
+
if (libraryUrl.endsWith("wasm")) {
|
|
3832
|
+
return await loadAsArrayBuffer(libraryUrl);
|
|
3833
|
+
}
|
|
3834
|
+
if (!isBrowser) {
|
|
3835
|
+
const { requireFromFile } = globalThis.loaders || {};
|
|
3836
|
+
try {
|
|
3837
|
+
const result = await requireFromFile?.(libraryUrl);
|
|
3838
|
+
if (result || !libraryUrl.includes("/dist/libs/")) {
|
|
3839
|
+
return result;
|
|
3840
|
+
}
|
|
3841
|
+
return await requireFromFile?.(libraryUrl.replace("/dist/libs/", "/src/libs/"));
|
|
3842
|
+
} catch (error) {
|
|
3843
|
+
if (libraryUrl.includes("/dist/libs/")) {
|
|
3844
|
+
try {
|
|
3845
|
+
return await requireFromFile?.(libraryUrl.replace("/dist/libs/", "/src/libs/"));
|
|
3846
|
+
} catch {
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3849
|
+
console.error(error);
|
|
3850
|
+
return null;
|
|
3851
|
+
}
|
|
3852
|
+
}
|
|
3853
|
+
if (isWorker) {
|
|
3854
|
+
return loadLibraryInWorker(libraryUrl, moduleLibraryUrl);
|
|
3855
|
+
}
|
|
3856
|
+
const scriptSource = await loadAsText(libraryUrl);
|
|
3857
|
+
return loadLibraryFromString(scriptSource, libraryUrl);
|
|
3858
|
+
}
|
|
3859
|
+
async function loadLibraryInWorker(libraryUrl, moduleLibraryUrl = libraryUrl) {
|
|
3860
|
+
try {
|
|
3861
|
+
importScripts();
|
|
3862
|
+
} catch {
|
|
3863
|
+
const moduleUrl2 = new URL(moduleLibraryUrl, globalThis.location.href).href;
|
|
3864
|
+
const library = await import(
|
|
3865
|
+
/* @vite-ignore */
|
|
3866
|
+
moduleUrl2
|
|
3867
|
+
);
|
|
3868
|
+
return library.default ?? library;
|
|
3869
|
+
}
|
|
3870
|
+
return importScripts(libraryUrl);
|
|
3871
|
+
}
|
|
3872
|
+
function loadLibraryFromString(scriptSource, id) {
|
|
3873
|
+
const script = document.createElement("script");
|
|
3874
|
+
script.id = id;
|
|
3875
|
+
try {
|
|
3876
|
+
script.appendChild(document.createTextNode(scriptSource));
|
|
3877
|
+
} catch (_e2) {
|
|
3878
|
+
script.text = scriptSource;
|
|
3879
|
+
}
|
|
3880
|
+
document.body.appendChild(script);
|
|
3881
|
+
return null;
|
|
3882
|
+
}
|
|
3883
|
+
async function loadAsArrayBuffer(url) {
|
|
3884
|
+
const { readFileAsArrayBuffer } = globalThis.loaders || {};
|
|
3885
|
+
if (isBrowser || !readFileAsArrayBuffer || url.startsWith("http")) {
|
|
3886
|
+
const response = await fetch(url);
|
|
3887
|
+
return await response.arrayBuffer();
|
|
3888
|
+
}
|
|
3889
|
+
try {
|
|
3890
|
+
return await readFileAsArrayBuffer(url);
|
|
3891
|
+
} catch {
|
|
3892
|
+
if (url.includes("/dist/libs/")) {
|
|
3893
|
+
return await readFileAsArrayBuffer(url.replace("/dist/libs/", "/src/libs/"));
|
|
3894
|
+
}
|
|
3895
|
+
throw new Error(`Failed to load ArrayBuffer from ${url}`);
|
|
3896
|
+
}
|
|
3897
|
+
}
|
|
3898
|
+
async function loadAsText(url) {
|
|
3899
|
+
const { readFileAsText } = globalThis.loaders || {};
|
|
3900
|
+
if (isBrowser || !readFileAsText || url.startsWith("http")) {
|
|
3901
|
+
const response = await fetch(url);
|
|
3902
|
+
return await response.text();
|
|
3903
|
+
}
|
|
3904
|
+
try {
|
|
3905
|
+
return await readFileAsText(url);
|
|
3906
|
+
} catch {
|
|
3907
|
+
if (url.includes("/dist/libs/")) {
|
|
3908
|
+
return await readFileAsText(url.replace("/dist/libs/", "/src/libs/"));
|
|
3909
|
+
}
|
|
3910
|
+
throw new Error(`Failed to load text from ${url}`);
|
|
3911
|
+
}
|
|
3912
|
+
}
|
|
3913
|
+
|
|
3914
|
+
// ../core/src/loader-utils/lib/env-utils/globals.ts
|
|
3915
|
+
var globals3 = {
|
|
3916
|
+
self: typeof self !== "undefined" && self,
|
|
2084
3917
|
window: typeof window !== "undefined" && window,
|
|
2085
3918
|
global: typeof global !== "undefined" && global,
|
|
2086
3919
|
document: typeof document !== "undefined" && document
|
|
@@ -2128,15 +3961,15 @@
|
|
|
2128
3961
|
|
|
2129
3962
|
// ../core/src/loader-utils/lib/worker-loader-utils/encode-with-worker.ts
|
|
2130
3963
|
function canEncodeWithWorker(writer, options) {
|
|
2131
|
-
if (!WorkerFarm.isSupported()) {
|
|
2132
|
-
return false;
|
|
2133
|
-
}
|
|
2134
3964
|
const nodeWorkers = options?._nodeWorkers ?? options?.core?._nodeWorkers;
|
|
2135
3965
|
const useWorkers = options?.worker ?? options?.core?.worker;
|
|
2136
3966
|
if (!isBrowser3 && !nodeWorkers) {
|
|
2137
3967
|
return false;
|
|
2138
3968
|
}
|
|
2139
|
-
return
|
|
3969
|
+
return canProcessOnWorker2(
|
|
3970
|
+
{ ...writer, options: writer.options || {} },
|
|
3971
|
+
{ worker: Boolean(useWorkers), _nodeWorkers: Boolean(nodeWorkers) }
|
|
3972
|
+
);
|
|
2140
3973
|
}
|
|
2141
3974
|
|
|
2142
3975
|
// ../../node_modules/@math.gl/core/dist/types/float16.js
|
|
@@ -9497,11 +11330,11 @@ return true;`);
|
|
|
9497
11330
|
this._offsets = new OffsetsBufferBuilder(opts.type);
|
|
9498
11331
|
}
|
|
9499
11332
|
setValue(index, value) {
|
|
9500
|
-
const
|
|
9501
|
-
const current =
|
|
11333
|
+
const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
|
|
11334
|
+
const current = pending2.get(index);
|
|
9502
11335
|
current && (this._pendingLength -= current.length);
|
|
9503
11336
|
this._pendingLength += value instanceof MapRow ? value[kKeys].length : value.length;
|
|
9504
|
-
|
|
11337
|
+
pending2.set(index, value);
|
|
9505
11338
|
}
|
|
9506
11339
|
setValid(index, isValid) {
|
|
9507
11340
|
if (!super.setValid(index, isValid)) {
|
|
@@ -9524,12 +11357,12 @@ return true;`);
|
|
|
9524
11357
|
return super.finish();
|
|
9525
11358
|
}
|
|
9526
11359
|
_flush() {
|
|
9527
|
-
const
|
|
11360
|
+
const pending2 = this._pending;
|
|
9528
11361
|
const pendingLength = this._pendingLength;
|
|
9529
11362
|
this._pendingLength = 0;
|
|
9530
11363
|
this._pending = void 0;
|
|
9531
|
-
if (
|
|
9532
|
-
this._flushPending(
|
|
11364
|
+
if (pending2 && pending2.size > 0) {
|
|
11365
|
+
this._flushPending(pending2, pendingLength);
|
|
9533
11366
|
}
|
|
9534
11367
|
return this;
|
|
9535
11368
|
}
|
|
@@ -11939,11 +13772,11 @@ return true;`);
|
|
|
11939
13772
|
setValue(index, value) {
|
|
11940
13773
|
return super.setValue(index, toUint8Array(value));
|
|
11941
13774
|
}
|
|
11942
|
-
_flushPending(
|
|
13775
|
+
_flushPending(pending2, pendingLength) {
|
|
11943
13776
|
const offsets = this._offsets;
|
|
11944
13777
|
const data = this._values.reserve(pendingLength).buffer;
|
|
11945
13778
|
let offset = 0;
|
|
11946
|
-
for (const [index, value] of
|
|
13779
|
+
for (const [index, value] of pending2) {
|
|
11947
13780
|
if (value === void 0) {
|
|
11948
13781
|
offsets.set(index, 0);
|
|
11949
13782
|
} else {
|
|
@@ -11972,11 +13805,11 @@ return true;`);
|
|
|
11972
13805
|
setValue(index, value) {
|
|
11973
13806
|
return super.setValue(index, toUint8Array(value));
|
|
11974
13807
|
}
|
|
11975
|
-
_flushPending(
|
|
13808
|
+
_flushPending(pending2, pendingLength) {
|
|
11976
13809
|
const offsets = this._offsets;
|
|
11977
13810
|
const data = this._values.reserve(pendingLength).buffer;
|
|
11978
13811
|
let offset = 0;
|
|
11979
|
-
for (const [index, value] of
|
|
13812
|
+
for (const [index, value] of pending2) {
|
|
11980
13813
|
if (value === void 0) {
|
|
11981
13814
|
offsets.set(index, BigInt(0));
|
|
11982
13815
|
} else {
|
|
@@ -12207,10 +14040,10 @@ return true;`);
|
|
|
12207
14040
|
this.type = new List2(new Field2(name, child.type, true));
|
|
12208
14041
|
return this.numChildren - 1;
|
|
12209
14042
|
}
|
|
12210
|
-
_flushPending(
|
|
14043
|
+
_flushPending(pending2) {
|
|
12211
14044
|
const offsets = this._offsets;
|
|
12212
14045
|
const [child] = this.children;
|
|
12213
|
-
for (const [index, value] of
|
|
14046
|
+
for (const [index, value] of pending2) {
|
|
12214
14047
|
if (typeof value === "undefined") {
|
|
12215
14048
|
offsets.set(index, 0);
|
|
12216
14049
|
} else {
|
|
@@ -12239,10 +14072,10 @@ return true;`);
|
|
|
12239
14072
|
this.type = new LargeList2(new Field2(name, child.type, true));
|
|
12240
14073
|
return this.numChildren - 1;
|
|
12241
14074
|
}
|
|
12242
|
-
_flushPending(
|
|
14075
|
+
_flushPending(pending2) {
|
|
12243
14076
|
const offsets = this._offsets;
|
|
12244
14077
|
const [child] = this.children;
|
|
12245
|
-
for (const [index, value] of
|
|
14078
|
+
for (const [index, value] of pending2) {
|
|
12246
14079
|
if (typeof value === "undefined") {
|
|
12247
14080
|
offsets.set(index, BigInt(0));
|
|
12248
14081
|
} else {
|
|
@@ -12264,11 +14097,11 @@ return true;`);
|
|
|
12264
14097
|
}
|
|
12265
14098
|
setValue(index, value) {
|
|
12266
14099
|
const row = value instanceof Map ? value : new Map(Object.entries(value));
|
|
12267
|
-
const
|
|
12268
|
-
const current =
|
|
14100
|
+
const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
|
|
14101
|
+
const current = pending2.get(index);
|
|
12269
14102
|
current && (this._pendingLength -= current.size);
|
|
12270
14103
|
this._pendingLength += row.size;
|
|
12271
|
-
|
|
14104
|
+
pending2.set(index, row);
|
|
12272
14105
|
}
|
|
12273
14106
|
addChild(child, name = `${this.numChildren}`) {
|
|
12274
14107
|
if (this.numChildren > 0) {
|
|
@@ -12278,10 +14111,10 @@ return true;`);
|
|
|
12278
14111
|
this.type = new Map_(new Field2(name, child.type, true), this.type.keysSorted);
|
|
12279
14112
|
return this.numChildren - 1;
|
|
12280
14113
|
}
|
|
12281
|
-
_flushPending(
|
|
14114
|
+
_flushPending(pending2) {
|
|
12282
14115
|
const offsets = this._offsets;
|
|
12283
14116
|
const [child] = this.children;
|
|
12284
|
-
for (const [index, value] of
|
|
14117
|
+
for (const [index, value] of pending2) {
|
|
12285
14118
|
if (value === void 0) {
|
|
12286
14119
|
offsets.set(index, 0);
|
|
12287
14120
|
} else {
|
|
@@ -12444,7 +14277,7 @@ return true;`);
|
|
|
12444
14277
|
return super.setValue(index, encodeUtf8(value));
|
|
12445
14278
|
}
|
|
12446
14279
|
// @ts-ignore
|
|
12447
|
-
_flushPending(
|
|
14280
|
+
_flushPending(pending2, pendingLength) {
|
|
12448
14281
|
}
|
|
12449
14282
|
};
|
|
12450
14283
|
Utf8Builder.prototype._flushPending = BinaryBuilder.prototype._flushPending;
|
|
@@ -12466,7 +14299,7 @@ return true;`);
|
|
|
12466
14299
|
return super.setValue(index, encodeUtf8(value));
|
|
12467
14300
|
}
|
|
12468
14301
|
// @ts-ignore
|
|
12469
|
-
_flushPending(
|
|
14302
|
+
_flushPending(pending2, pendingLength) {
|
|
12470
14303
|
}
|
|
12471
14304
|
};
|
|
12472
14305
|
LargeUtf8Builder.prototype._flushPending = LargeBinaryBuilder.prototype._flushPending;
|
|
@@ -17198,7 +19031,7 @@ return true;`);
|
|
|
17198
19031
|
}
|
|
17199
19032
|
|
|
17200
19033
|
// src/draco/lib/utils/version.ts
|
|
17201
|
-
var VERSION3 = true ? "5.0.0-beta.
|
|
19034
|
+
var VERSION3 = true ? "5.0.0-beta.5" : "latest";
|
|
17202
19035
|
|
|
17203
19036
|
// src/draco/draco-format.ts
|
|
17204
19037
|
var DracoFormat = {
|
|
@@ -17265,7 +19098,7 @@ return true;`);
|
|
|
17265
19098
|
const normalizedData = normalizeDracoInputBatches(data);
|
|
17266
19099
|
if (canEncodeWithWorker(DracoWriterWorker, options)) {
|
|
17267
19100
|
const { onProgress: _onProgress, ...workerOptions } = options;
|
|
17268
|
-
return
|
|
19101
|
+
return processOnWorkerInBatches2(
|
|
17269
19102
|
DracoWriterWorker,
|
|
17270
19103
|
normalizedData,
|
|
17271
19104
|
workerOptions
|
|
@@ -17331,7 +19164,7 @@ return true;`);
|
|
|
17331
19164
|
}
|
|
17332
19165
|
|
|
17333
19166
|
// src/draco/workers/draco-writer-worker.ts
|
|
17334
|
-
|
|
19167
|
+
createWorker2(
|
|
17335
19168
|
async (input, options) => (await encodeDraco(input, options)).data,
|
|
17336
19169
|
encodeDracoInBatchesLocally
|
|
17337
19170
|
);
|