@loaders.gl/scene 5.0.0-beta.2 → 5.0.0-beta.4
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/dist/dist.dev.js +3393 -407
- package/dist/dist.min.js +24 -16
- package/dist/draco/lib/utils/version.cjs +1 -1
- package/dist/draco/lib/utils/version.js +1 -1
- package/dist/draco-worker-node.js +415 -54
- package/dist/draco-worker-node.js.map +4 -4
- package/dist/draco-worker.js +390 -54
- package/dist/draco-worker.js.map +4 -4
- package/dist/draco-writer-worker-node.cjs +1401 -67
- package/dist/draco-writer-worker-node.cjs.map +4 -4
- package/dist/draco-writer-worker.js +1345 -67
- 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 +12 -3
- 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 +9 -3
- 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.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-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-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-zod-schema.cjs +3 -0
- package/dist/gltf/lib/types/gltf-zod-schema.cjs.map +2 -2
- package/dist/gltf/lib/types/gltf-zod-schema.d.ts +5 -0
- package/dist/gltf/lib/types/gltf-zod-schema.d.ts.map +1 -1
- package/dist/gltf/lib/types/gltf-zod-schema.js +4 -0
- 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 +3 -0
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- 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 +1 -1
- package/dist/obj/obj-loader-types.js +1 -1
- package/dist/obj/obj-writer.cjs +1 -1
- package/dist/obj/obj-writer.js +1 -1
- package/dist/obj-loader-types.cjs +1 -1
- package/dist/obj-worker.js +393 -57
- package/dist/obj-writer.cjs +1 -1
- package/dist/usd/usd-loader-types.cjs +1 -1
- package/dist/usd/usd-loader-types.js +1 -1
- package/dist/usd-loader-types.cjs +1 -1
- package/package.json +11 -5
- 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 +17 -3
- 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 +29 -0
- package/src/gltf/lib/types/gltf-ext-gaussian-splatting-schema.ts +1 -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 +5 -0
- package/src/gltf/schema.ts +1 -0
- package/src/index.ts +3 -0
- 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
|
@@ -7580,6 +7580,48 @@ var init_dist = __esm({
|
|
|
7580
7580
|
}
|
|
7581
7581
|
});
|
|
7582
7582
|
|
|
7583
|
+
// ../core/src/worker-utils/lib/node/worker_threads.ts
|
|
7584
|
+
var worker_threads_exports = {};
|
|
7585
|
+
__export(worker_threads_exports, {
|
|
7586
|
+
BroadcastChannel: () => import_worker_threads4.BroadcastChannel,
|
|
7587
|
+
MessageChannel: () => import_worker_threads4.MessageChannel,
|
|
7588
|
+
MessagePort: () => import_worker_threads4.MessagePort,
|
|
7589
|
+
NodeWorker: () => NodeWorker2,
|
|
7590
|
+
SHARE_ENV: () => import_worker_threads4.SHARE_ENV,
|
|
7591
|
+
Worker: () => import_worker_threads4.Worker,
|
|
7592
|
+
getEnvironmentData: () => import_worker_threads4.getEnvironmentData,
|
|
7593
|
+
isInternalThread: () => isInternalThread2,
|
|
7594
|
+
isMainThread: () => import_worker_threads4.isMainThread,
|
|
7595
|
+
isMarkedAsUntransferable: () => import_worker_threads4.isMarkedAsUntransferable,
|
|
7596
|
+
locks: () => locks2,
|
|
7597
|
+
markAsUncloneable: () => import_worker_threads4.markAsUncloneable,
|
|
7598
|
+
markAsUntransferable: () => import_worker_threads4.markAsUntransferable,
|
|
7599
|
+
moveMessagePortToContext: () => import_worker_threads4.moveMessagePortToContext,
|
|
7600
|
+
parentPort: () => parentPort2,
|
|
7601
|
+
postMessageToThread: () => import_worker_threads4.postMessageToThread,
|
|
7602
|
+
receiveMessageOnPort: () => import_worker_threads4.receiveMessageOnPort,
|
|
7603
|
+
resourceLimits: () => import_worker_threads4.resourceLimits,
|
|
7604
|
+
setEnvironmentData: () => import_worker_threads4.setEnvironmentData,
|
|
7605
|
+
structuredClone: () => structuredClone3,
|
|
7606
|
+
threadId: () => import_worker_threads4.threadId,
|
|
7607
|
+
threadName: () => threadName2,
|
|
7608
|
+
workerData: () => import_worker_threads4.workerData
|
|
7609
|
+
});
|
|
7610
|
+
var WorkerThreads, import_worker_threads4, parentPort2, NodeWorker2, isInternalThread2, threadName2, locks2, structuredClone3;
|
|
7611
|
+
var init_worker_threads = __esm({
|
|
7612
|
+
"../core/src/worker-utils/lib/node/worker_threads.ts"() {
|
|
7613
|
+
"use strict";
|
|
7614
|
+
WorkerThreads = __toESM(require("worker_threads"), 1);
|
|
7615
|
+
import_worker_threads4 = require("worker_threads");
|
|
7616
|
+
parentPort2 = WorkerThreads == null ? void 0 : WorkerThreads.parentPort;
|
|
7617
|
+
NodeWorker2 = WorkerThreads.Worker;
|
|
7618
|
+
isInternalThread2 = WorkerThreads.isInternalThread;
|
|
7619
|
+
threadName2 = WorkerThreads.threadName;
|
|
7620
|
+
locks2 = WorkerThreads.locks;
|
|
7621
|
+
structuredClone3 = WorkerThreads.structuredClone;
|
|
7622
|
+
}
|
|
7623
|
+
});
|
|
7624
|
+
|
|
7583
7625
|
// ../../node_modules/flatbuffers/js/constants.js
|
|
7584
7626
|
var require_constants2 = __commonJS({
|
|
7585
7627
|
"../../node_modules/flatbuffers/js/constants.js"(exports2) {
|
|
@@ -10594,9 +10636,15 @@ globalThis.loaders.readFileAsText = readFileAsText;
|
|
|
10594
10636
|
globalThis.loaders.requireFromFile = requireFromFile;
|
|
10595
10637
|
globalThis.loaders.requireFromString = requireFromString;
|
|
10596
10638
|
|
|
10639
|
+
// ../core/src/constants/index.ts
|
|
10640
|
+
var LOADERS_GL_FIXTURE_BRANCH = "master";
|
|
10641
|
+
var LOADERS_GL_RAW_FIXTURE_URL = `https://raw.githubusercontent.com/visgl/loaders.gl/${LOADERS_GL_FIXTURE_BRANCH}/`;
|
|
10642
|
+
var LOADERS_GL_REDIRECTING_FIXTURE_URL = `https://github.com/visgl/loaders.gl/raw/${LOADERS_GL_FIXTURE_BRANCH}/`;
|
|
10643
|
+
var NPM_TAG = "beta";
|
|
10644
|
+
|
|
10597
10645
|
// ../core/src/worker-utils/lib/env-utils/version.ts
|
|
10598
10646
|
function getVersion() {
|
|
10599
|
-
const version2 = false ? NPM_TAG : "5.0.0-beta.
|
|
10647
|
+
const version2 = false ? NPM_TAG : "5.0.0-beta.4";
|
|
10600
10648
|
globalThis._loadersgl_ = globalThis._loadersgl_ || {};
|
|
10601
10649
|
globalThis._loadersgl_.version ||= version2;
|
|
10602
10650
|
return version2;
|
|
@@ -10631,11 +10679,11 @@ var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.e
|
|
|
10631
10679
|
var nodeVersion2 = matches && parseFloat(matches[1]) || 0;
|
|
10632
10680
|
|
|
10633
10681
|
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/npm-tag.js
|
|
10634
|
-
var
|
|
10682
|
+
var NPM_TAG2 = "latest";
|
|
10635
10683
|
|
|
10636
10684
|
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/env-utils/version.js
|
|
10637
10685
|
function getVersion2() {
|
|
10638
|
-
return false ?
|
|
10686
|
+
return false ? NPM_TAG2 : "5.0.0-beta.4";
|
|
10639
10687
|
}
|
|
10640
10688
|
var VERSION2 = getVersion2();
|
|
10641
10689
|
|
|
@@ -10793,9 +10841,19 @@ var NodeWorker = import_worker_threads.Worker;
|
|
|
10793
10841
|
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-utils/get-loadable-worker-url.js
|
|
10794
10842
|
var workerURLCache = /* @__PURE__ */ new Map();
|
|
10795
10843
|
function getLoadableWorkerURL(props) {
|
|
10844
|
+
var _a5, _b2, _c2;
|
|
10796
10845
|
assert2(props.source && !props.url || !props.source && props.url);
|
|
10797
|
-
if (props.url && props.workerType === "module")
|
|
10846
|
+
if (props.url && props.workerType === "module") {
|
|
10847
|
+
const baseUrl = ((_a5 = globalThis.document) == null ? void 0 : _a5.baseURI) ?? ((_b2 = globalThis.location) == null ? void 0 : _b2.href);
|
|
10848
|
+
if (!baseUrl)
|
|
10849
|
+
return props.url;
|
|
10850
|
+
const resolved = new URL(props.url, baseUrl);
|
|
10851
|
+
const origin = (_c2 = globalThis.location) == null ? void 0 : _c2.origin;
|
|
10852
|
+
if (/^https?:$/.test(resolved.protocol) && resolved.origin !== origin) {
|
|
10853
|
+
return getLoadableWorkerURLFromSource(`import ${JSON.stringify(resolved.href)};`);
|
|
10854
|
+
}
|
|
10798
10855
|
return props.url;
|
|
10856
|
+
}
|
|
10799
10857
|
let workerURL = workerURLCache.get(props.source || props.url);
|
|
10800
10858
|
if (!workerURL) {
|
|
10801
10859
|
if (props.url) {
|
|
@@ -10843,6 +10901,9 @@ function getTransferList(object2, recursive = true, transfers) {
|
|
|
10843
10901
|
else if (ArrayBuffer.isView(value)) {
|
|
10844
10902
|
if (isTransferable(value.buffer))
|
|
10845
10903
|
transfersSet.add(value.buffer);
|
|
10904
|
+
} else if (recursive && typeof MessageChannel !== "undefined" && value instanceof MessageChannel) {
|
|
10905
|
+
visit(value.port1);
|
|
10906
|
+
visit(value.port2);
|
|
10846
10907
|
} else if (recursive && value instanceof Map) {
|
|
10847
10908
|
for (const [key, item] of value) {
|
|
10848
10909
|
visit(key);
|
|
@@ -10947,7 +11008,7 @@ var WorkerThread = class {
|
|
|
10947
11008
|
if (this.terminated)
|
|
10948
11009
|
return this.termination ?? Promise.resolve();
|
|
10949
11010
|
this.terminated = true;
|
|
10950
|
-
this.termination = Promise.resolve(this.worker.terminate()).then(() => void 0);
|
|
11011
|
+
this.termination = Promise.resolve(this.worker.terminate()).then(() => void 0).finally(() => this.releaseModuleWorkerURL());
|
|
10951
11012
|
void this.termination.catch(() => void 0);
|
|
10952
11013
|
return this.termination;
|
|
10953
11014
|
}
|
|
@@ -10998,9 +11059,9 @@ var WorkerThread = class {
|
|
|
10998
11059
|
var _a5;
|
|
10999
11060
|
if (this.loadWorker) {
|
|
11000
11061
|
try {
|
|
11001
|
-
const
|
|
11002
|
-
if (
|
|
11003
|
-
return this._initializeBrowserWorker(
|
|
11062
|
+
const worker = this.loadWorker();
|
|
11063
|
+
if (worker) {
|
|
11064
|
+
return this._initializeBrowserWorker(worker);
|
|
11004
11065
|
}
|
|
11005
11066
|
} catch (error) {
|
|
11006
11067
|
if (!this.source && !this.url && !this.getUrl) {
|
|
@@ -11014,8 +11075,22 @@ var WorkerThread = class {
|
|
|
11014
11075
|
url,
|
|
11015
11076
|
workerType: this.workerType
|
|
11016
11077
|
});
|
|
11017
|
-
|
|
11018
|
-
|
|
11078
|
+
if (this.workerType === "module" && url && this._loadableURL !== url && this._loadableURL.startsWith("blob:"))
|
|
11079
|
+
this.ownedModuleWorkerURL = this._loadableURL;
|
|
11080
|
+
try {
|
|
11081
|
+
const worker = new Worker(this._loadableURL, { name: this.name, type: this.workerType });
|
|
11082
|
+
return this._initializeBrowserWorker(worker);
|
|
11083
|
+
} catch (error) {
|
|
11084
|
+
this.releaseModuleWorkerURL();
|
|
11085
|
+
throw error;
|
|
11086
|
+
}
|
|
11087
|
+
}
|
|
11088
|
+
/** Releases only the module shim owned by this worker, never caller-owned blob URLs. */
|
|
11089
|
+
releaseModuleWorkerURL() {
|
|
11090
|
+
if (this.ownedModuleWorkerURL) {
|
|
11091
|
+
URL.revokeObjectURL(this.ownedModuleWorkerURL);
|
|
11092
|
+
this.ownedModuleWorkerURL = void 0;
|
|
11093
|
+
}
|
|
11019
11094
|
}
|
|
11020
11095
|
/** Attaches protocol handlers to a browser worker. */
|
|
11021
11096
|
_initializeBrowserWorker(worker) {
|
|
@@ -11746,16 +11821,16 @@ var WorkerBody = class {
|
|
|
11746
11821
|
*/
|
|
11747
11822
|
static set onmessage(onMessage2) {
|
|
11748
11823
|
async function handleMessage(message) {
|
|
11749
|
-
const
|
|
11750
|
-
const { type, payload } =
|
|
11824
|
+
const parentPort3 = await getParentPort();
|
|
11825
|
+
const { type, payload } = parentPort3 ? message : message.data;
|
|
11751
11826
|
onMessage2(type, payload);
|
|
11752
11827
|
}
|
|
11753
|
-
getParentPort().then((
|
|
11754
|
-
if (
|
|
11755
|
-
|
|
11828
|
+
getParentPort().then((parentPort3) => {
|
|
11829
|
+
if (parentPort3) {
|
|
11830
|
+
parentPort3.on("message", (message) => {
|
|
11756
11831
|
handleMessage(message);
|
|
11757
11832
|
});
|
|
11758
|
-
|
|
11833
|
+
parentPort3.on("exit", () => console.debug("Node worker closing"));
|
|
11759
11834
|
} else {
|
|
11760
11835
|
globalThis.onmessage = handleMessage;
|
|
11761
11836
|
}
|
|
@@ -11773,9 +11848,9 @@ var WorkerBody = class {
|
|
|
11773
11848
|
};
|
|
11774
11849
|
onMessageWrapperMap.set(onMessage2, onMessageWrapper);
|
|
11775
11850
|
}
|
|
11776
|
-
const
|
|
11777
|
-
if (
|
|
11778
|
-
|
|
11851
|
+
const parentPort3 = await getParentPort();
|
|
11852
|
+
if (parentPort3) {
|
|
11853
|
+
parentPort3.on("message", onMessageWrapper);
|
|
11779
11854
|
} else {
|
|
11780
11855
|
globalThis.addEventListener("message", onMessageWrapper);
|
|
11781
11856
|
}
|
|
@@ -11786,9 +11861,9 @@ var WorkerBody = class {
|
|
|
11786
11861
|
if (!onMessageWrapper) {
|
|
11787
11862
|
return;
|
|
11788
11863
|
}
|
|
11789
|
-
const
|
|
11790
|
-
if (
|
|
11791
|
-
|
|
11864
|
+
const parentPort3 = await getParentPort();
|
|
11865
|
+
if (parentPort3) {
|
|
11866
|
+
parentPort3.off("message", onMessageWrapper);
|
|
11792
11867
|
} else {
|
|
11793
11868
|
globalThis.removeEventListener("message", onMessageWrapper);
|
|
11794
11869
|
}
|
|
@@ -11798,12 +11873,12 @@ var WorkerBody = class {
|
|
|
11798
11873
|
* @param type
|
|
11799
11874
|
* @param payload
|
|
11800
11875
|
*/
|
|
11801
|
-
static async postMessage(type, payload) {
|
|
11876
|
+
static async postMessage(type, payload, copy = false) {
|
|
11802
11877
|
const data = { source: "loaders.gl", type, payload };
|
|
11803
|
-
const transferList = getTransferList(payload);
|
|
11804
|
-
const
|
|
11805
|
-
if (
|
|
11806
|
-
|
|
11878
|
+
const transferList = copy ? [] : getTransferList(payload);
|
|
11879
|
+
const parentPort3 = await getParentPort();
|
|
11880
|
+
if (parentPort3) {
|
|
11881
|
+
parentPort3.postMessage(data, transferList);
|
|
11807
11882
|
} else {
|
|
11808
11883
|
globalThis.postMessage(data, transferList);
|
|
11809
11884
|
}
|
|
@@ -11921,7 +11996,7 @@ function getDefaultWorkerURL(worker, warn = false) {
|
|
|
11921
11996
|
const workerFile = isBrowser3 ? worker.workerFile || `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
|
|
11922
11997
|
let version2 = worker.version;
|
|
11923
11998
|
if (version2 === "latest") {
|
|
11924
|
-
version2 =
|
|
11999
|
+
version2 = NPM_TAG2;
|
|
11925
12000
|
}
|
|
11926
12001
|
const versionTag = version2 ? `@${version2}` : "";
|
|
11927
12002
|
const packageName = worker.packageName || `@loaders.gl/${worker.module}`;
|
|
@@ -12055,8 +12130,63 @@ function getInputByteLength(input) {
|
|
|
12055
12130
|
return bytes;
|
|
12056
12131
|
}
|
|
12057
12132
|
|
|
12133
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/validate-output-ownership.js
|
|
12134
|
+
function validateOutputOwnership(ownership) {
|
|
12135
|
+
if (ownership !== void 0 && ownership !== "copy" && ownership !== "transfer") {
|
|
12136
|
+
throw new Error("Invalid worker output ownership");
|
|
12137
|
+
}
|
|
12138
|
+
}
|
|
12139
|
+
|
|
12058
12140
|
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/process-on-worker.js
|
|
12141
|
+
async function processOnWorker(worker, data, options = {}, context = {}, jobContext = {}) {
|
|
12142
|
+
var _a5;
|
|
12143
|
+
validateOutputOwnership(options.outputOwnership);
|
|
12144
|
+
if (options.inputOwnership !== void 0 && !["copy", "transfer", "share"].includes(options.inputOwnership))
|
|
12145
|
+
throw new Error("Invalid worker input ownership");
|
|
12146
|
+
options = prepareSharedState(options);
|
|
12147
|
+
throwIfAborted(options.signal);
|
|
12148
|
+
validateSharedInput(options, [data, serializableOptions(options), jobContext]);
|
|
12149
|
+
const name = getWorkerName(worker);
|
|
12150
|
+
const workerPool = options.workerPool ?? WorkerFarm.getWorkerFarm(options).getWorkerPool(getWorkerPoolTarget(worker, options, name));
|
|
12151
|
+
const jobName = options.jobName || worker.name;
|
|
12152
|
+
const job = await workerPool.startJob(
|
|
12153
|
+
jobName,
|
|
12154
|
+
// eslint-disable-next-line
|
|
12155
|
+
onMessage.bind(null, context, options),
|
|
12156
|
+
void 0,
|
|
12157
|
+
options.signal,
|
|
12158
|
+
{
|
|
12159
|
+
inputBytes: getInputByteLength([data, budgetOptions(options), jobContext]),
|
|
12160
|
+
priority: options.priority,
|
|
12161
|
+
admission: options.admission,
|
|
12162
|
+
sharedState: options.sharedState ? new SharedWorkerState(options.sharedState) : void 0,
|
|
12163
|
+
cancellationMode: options.cancellationMode,
|
|
12164
|
+
cancellationTimeout: options.cancellationTimeout
|
|
12165
|
+
}
|
|
12166
|
+
);
|
|
12167
|
+
try {
|
|
12168
|
+
if (((_a5 = options.signal) == null ? void 0 : _a5.aborted) && !job.isCancelled)
|
|
12169
|
+
job.abort(getAbortReason(options.signal));
|
|
12170
|
+
const workerOptions = serializableOptions(options);
|
|
12171
|
+
const transferableOptions = getTransferListForWriter(workerOptions);
|
|
12172
|
+
const transferableContext = getTransferListForWriter(jobContext);
|
|
12173
|
+
if (job.isRunning) {
|
|
12174
|
+
job.postMessage("process", {
|
|
12175
|
+
input: data,
|
|
12176
|
+
options: transferableOptions,
|
|
12177
|
+
context: transferableContext
|
|
12178
|
+
}, options.inputOwnership === "copy" || options.inputOwnership === "share" ? [] : void 0);
|
|
12179
|
+
}
|
|
12180
|
+
const result = await job.result;
|
|
12181
|
+
return result.result;
|
|
12182
|
+
} catch (error) {
|
|
12183
|
+
if (!job.isCancelled)
|
|
12184
|
+
job.abort(error);
|
|
12185
|
+
throw error;
|
|
12186
|
+
}
|
|
12187
|
+
}
|
|
12059
12188
|
function processOnWorkerInBatches(worker, input, options = {}, context = {}, jobContext = {}) {
|
|
12189
|
+
validateOutputOwnership(options.outputOwnership);
|
|
12060
12190
|
if (options.inputOwnership !== void 0 && !["copy", "transfer", "share"].includes(options.inputOwnership))
|
|
12061
12191
|
throw new Error("Invalid worker input ownership");
|
|
12062
12192
|
return processOnWorkerInBatchesIterator(worker, input, options, context, jobContext);
|
|
@@ -12309,7 +12439,7 @@ var requestId = 0;
|
|
|
12309
12439
|
var activeController = null;
|
|
12310
12440
|
var activeInputBatches = null;
|
|
12311
12441
|
var activeOutputAcknowledgements = null;
|
|
12312
|
-
async function createWorker(process2, processInBatches) {
|
|
12442
|
+
async function createWorker(process2, processInBatches, preload) {
|
|
12313
12443
|
if (!await WorkerBody.inWorkerThread()) {
|
|
12314
12444
|
return;
|
|
12315
12445
|
}
|
|
@@ -12317,7 +12447,7 @@ async function createWorker(process2, processInBatches) {
|
|
|
12317
12447
|
process: processOnMainThread
|
|
12318
12448
|
};
|
|
12319
12449
|
WorkerBody.onmessage = async (type, payload) => {
|
|
12320
|
-
var _a5;
|
|
12450
|
+
var _a5, _b2, _c2, _d2, _e2;
|
|
12321
12451
|
if (type === "cancel") {
|
|
12322
12452
|
activeController == null ? void 0 : activeController.abort();
|
|
12323
12453
|
activeInputBatches == null ? void 0 : activeInputBatches.close();
|
|
@@ -12351,10 +12481,12 @@ async function createWorker(process2, processInBatches) {
|
|
|
12351
12481
|
}
|
|
12352
12482
|
switch (type) {
|
|
12353
12483
|
case "preload":
|
|
12484
|
+
await (preload == null ? void 0 : preload());
|
|
12354
12485
|
WorkerBody.postMessage("done", {});
|
|
12355
12486
|
break;
|
|
12356
12487
|
case "process":
|
|
12357
12488
|
throwIfAborted3();
|
|
12489
|
+
validateOutputOwnership((_b2 = payload.options) == null ? void 0 : _b2["outputOwnership"]);
|
|
12358
12490
|
if (!process2) {
|
|
12359
12491
|
throw new Error("Worker does not support atomic processing");
|
|
12360
12492
|
}
|
|
@@ -12364,10 +12496,11 @@ async function createWorker(process2, processInBatches) {
|
|
|
12364
12496
|
await WorkerBody.postMessage("done", {
|
|
12365
12497
|
result,
|
|
12366
12498
|
executionMs: performance.now() - startedAt
|
|
12367
|
-
});
|
|
12499
|
+
}, ((_c2 = payload.options) == null ? void 0 : _c2["outputOwnership"]) === "copy");
|
|
12368
12500
|
break;
|
|
12369
12501
|
case "process-in-batches":
|
|
12370
12502
|
throwIfAborted3();
|
|
12503
|
+
validateOutputOwnership((_d2 = payload.options) == null ? void 0 : _d2["outputOwnership"]);
|
|
12371
12504
|
if (!processInBatches) {
|
|
12372
12505
|
throw new Error("Worker does not support batched processing");
|
|
12373
12506
|
}
|
|
@@ -12379,7 +12512,7 @@ async function createWorker(process2, processInBatches) {
|
|
|
12379
12512
|
const resultIterator = processInBatches(createDemandDrivenIterator(inputBatches), payload.options || {}, jobContext, payload.context || {});
|
|
12380
12513
|
for await (const batch of resultIterator) {
|
|
12381
12514
|
throwIfAborted3();
|
|
12382
|
-
await WorkerBody.postMessage("output-batch", { result: batch });
|
|
12515
|
+
await WorkerBody.postMessage("output-batch", { result: batch }, ((_e2 = payload.options) == null ? void 0 : _e2["outputOwnership"]) === "copy");
|
|
12383
12516
|
await outputAcknowledgements.next();
|
|
12384
12517
|
}
|
|
12385
12518
|
throwIfAborted3();
|
|
@@ -12477,14 +12610,14 @@ function processOnMainThread(arrayBuffer2, options = {}, jobContext = {}) {
|
|
|
12477
12610
|
});
|
|
12478
12611
|
}
|
|
12479
12612
|
function createProgressReporter() {
|
|
12480
|
-
let
|
|
12613
|
+
let pending2;
|
|
12481
12614
|
let finished2 = false;
|
|
12482
12615
|
let scheduled = false;
|
|
12483
12616
|
const flush = () => {
|
|
12484
12617
|
scheduled = false;
|
|
12485
|
-
if (
|
|
12486
|
-
WorkerBody.postMessage("progress", { progress:
|
|
12487
|
-
|
|
12618
|
+
if (pending2) {
|
|
12619
|
+
WorkerBody.postMessage("progress", { progress: pending2 });
|
|
12620
|
+
pending2 = void 0;
|
|
12488
12621
|
}
|
|
12489
12622
|
};
|
|
12490
12623
|
return {
|
|
@@ -12492,9 +12625,9 @@ function createProgressReporter() {
|
|
|
12492
12625
|
report(progress) {
|
|
12493
12626
|
if (finished2)
|
|
12494
12627
|
return;
|
|
12495
|
-
if (
|
|
12628
|
+
if (pending2 && pending2.phase !== progress.phase)
|
|
12496
12629
|
flush();
|
|
12497
|
-
|
|
12630
|
+
pending2 = { ...progress };
|
|
12498
12631
|
if (!scheduled) {
|
|
12499
12632
|
scheduled = true;
|
|
12500
12633
|
setTimeout(flush, 0);
|
|
@@ -12503,7 +12636,7 @@ function createProgressReporter() {
|
|
|
12503
12636
|
/** Flushes final progress and suppresses reports from stale callbacks. */
|
|
12504
12637
|
finish(discard = false) {
|
|
12505
12638
|
if (discard)
|
|
12506
|
-
|
|
12639
|
+
pending2 = void 0;
|
|
12507
12640
|
flush();
|
|
12508
12641
|
finished2 = true;
|
|
12509
12642
|
}
|
|
@@ -12515,6 +12648,1207 @@ var import_meta3 = {};
|
|
|
12515
12648
|
var path3 = typeof __filename === "string" ? __filename.replace(/\\/g, "/") : "";
|
|
12516
12649
|
var moduleUrl = path3 ? `file://${path3.startsWith("/") ? "" : "/"}${encodeURI(path3).replace(/#/g, "%23").replace(/\?/g, "%3F")}` : import_meta3.url;
|
|
12517
12650
|
|
|
12651
|
+
// ../../node_modules/@math.gl/core/dist/tasks/task-preload.js
|
|
12652
|
+
var pending = /* @__PURE__ */ new WeakMap();
|
|
12653
|
+
var loaded = /* @__PURE__ */ new WeakSet();
|
|
12654
|
+
function preloadTaskCode(task, signal) {
|
|
12655
|
+
if (!task.preload)
|
|
12656
|
+
return Promise.resolve();
|
|
12657
|
+
let promise = pending.get(task);
|
|
12658
|
+
if (!promise) {
|
|
12659
|
+
promise = Promise.resolve().then(() => task.preload()).then(() => {
|
|
12660
|
+
loaded.add(task);
|
|
12661
|
+
});
|
|
12662
|
+
pending.set(task, promise);
|
|
12663
|
+
void promise.catch(() => pending.delete(task));
|
|
12664
|
+
}
|
|
12665
|
+
return withSignal(promise, signal);
|
|
12666
|
+
}
|
|
12667
|
+
function isTaskCodeLoaded(task) {
|
|
12668
|
+
return !task.preload || loaded.has(task);
|
|
12669
|
+
}
|
|
12670
|
+
function withSignal(operation, signal) {
|
|
12671
|
+
if (!signal)
|
|
12672
|
+
return operation;
|
|
12673
|
+
return new Promise((resolve, reject) => {
|
|
12674
|
+
const abort = () => {
|
|
12675
|
+
signal.removeEventListener("abort", abort);
|
|
12676
|
+
reject(signal.reason);
|
|
12677
|
+
};
|
|
12678
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
12679
|
+
if (signal.aborted)
|
|
12680
|
+
abort();
|
|
12681
|
+
operation.then((value) => {
|
|
12682
|
+
signal.removeEventListener("abort", abort);
|
|
12683
|
+
resolve(value);
|
|
12684
|
+
}, (error) => {
|
|
12685
|
+
signal.removeEventListener("abort", abort);
|
|
12686
|
+
reject(error);
|
|
12687
|
+
});
|
|
12688
|
+
});
|
|
12689
|
+
}
|
|
12690
|
+
|
|
12691
|
+
// ../../node_modules/@math.gl/core/dist/tasks/task-runtime.js
|
|
12692
|
+
function assertPayload(value) {
|
|
12693
|
+
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) {
|
|
12694
|
+
throw new TypeError("Task payloads must be plain objects with named fields");
|
|
12695
|
+
}
|
|
12696
|
+
}
|
|
12697
|
+
function clonePayload(value, ownership = "copy") {
|
|
12698
|
+
assertPayload(value);
|
|
12699
|
+
if (!["copy", "transfer", "share"].includes(ownership))
|
|
12700
|
+
throw new TypeError("Invalid input ownership");
|
|
12701
|
+
const transfer = getTransferList(value);
|
|
12702
|
+
if (ownership === "share" && transfer.length)
|
|
12703
|
+
throw new TypeError("Share requires shared storage");
|
|
12704
|
+
return structuredClone(value, {
|
|
12705
|
+
transfer: ownership === "transfer" ? transfer : []
|
|
12706
|
+
});
|
|
12707
|
+
}
|
|
12708
|
+
function taskContext(state, context = {}) {
|
|
12709
|
+
const signal = context.signal ?? new AbortController().signal;
|
|
12710
|
+
return {
|
|
12711
|
+
state,
|
|
12712
|
+
signal,
|
|
12713
|
+
throwIfAborted: () => {
|
|
12714
|
+
var _a5;
|
|
12715
|
+
signal.throwIfAborted();
|
|
12716
|
+
(_a5 = context.throwIfAborted) == null ? void 0 : _a5.call(context);
|
|
12717
|
+
},
|
|
12718
|
+
reportProgress: (progress) => {
|
|
12719
|
+
var _a5;
|
|
12720
|
+
return (_a5 = context.reportProgress) == null ? void 0 : _a5.call(context, {
|
|
12721
|
+
...progress,
|
|
12722
|
+
phase: progress.phase ?? "process",
|
|
12723
|
+
unit: progress.unit ?? "items"
|
|
12724
|
+
});
|
|
12725
|
+
}
|
|
12726
|
+
};
|
|
12727
|
+
}
|
|
12728
|
+
var TaskRuntime = class {
|
|
12729
|
+
constructor(task) {
|
|
12730
|
+
this.task = task;
|
|
12731
|
+
this.initialized = false;
|
|
12732
|
+
}
|
|
12733
|
+
async initialize(input, context = {}) {
|
|
12734
|
+
var _a5, _b2, _c2;
|
|
12735
|
+
if (this.initialized)
|
|
12736
|
+
throw new Error("Task is already initialized");
|
|
12737
|
+
assertPayload(input);
|
|
12738
|
+
await preloadTaskCode(this.task, context.signal);
|
|
12739
|
+
(_a5 = context.signal) == null ? void 0 : _a5.throwIfAborted();
|
|
12740
|
+
this.state = await ((_c2 = (_b2 = this.task).initialize) == null ? void 0 : _c2.call(_b2, input, taskContext(void 0, context)));
|
|
12741
|
+
this.initialized = true;
|
|
12742
|
+
return {};
|
|
12743
|
+
}
|
|
12744
|
+
async destroy() {
|
|
12745
|
+
var _a5, _b2;
|
|
12746
|
+
if (this.initialized) {
|
|
12747
|
+
this.initialized = false;
|
|
12748
|
+
const state = this.state;
|
|
12749
|
+
this.state = void 0;
|
|
12750
|
+
if (this.task.initialize)
|
|
12751
|
+
await ((_b2 = (_a5 = this.task).destroy) == null ? void 0 : _b2.call(_a5, state));
|
|
12752
|
+
}
|
|
12753
|
+
return {};
|
|
12754
|
+
}
|
|
12755
|
+
async process(input, options, context = {}) {
|
|
12756
|
+
if (!this.initialized)
|
|
12757
|
+
throw new Error("Task is not initialized");
|
|
12758
|
+
if (!this.task.process)
|
|
12759
|
+
throw new Error("Task has no atomic processor");
|
|
12760
|
+
assertPayload(input);
|
|
12761
|
+
const result = await this.task.process(input, options, taskContext(this.state, context));
|
|
12762
|
+
assertPayload(result);
|
|
12763
|
+
return result;
|
|
12764
|
+
}
|
|
12765
|
+
async *stream(inputs, options, context = {}) {
|
|
12766
|
+
if (!this.initialized)
|
|
12767
|
+
throw new Error("Task is not initialized");
|
|
12768
|
+
if (!this.task.processInBatches)
|
|
12769
|
+
throw new Error("Task has no streaming processor");
|
|
12770
|
+
for await (const output of this.task.processInBatches(inputs, options, taskContext(this.state, context))) {
|
|
12771
|
+
assertPayload(output);
|
|
12772
|
+
yield output;
|
|
12773
|
+
}
|
|
12774
|
+
}
|
|
12775
|
+
};
|
|
12776
|
+
async function initializeTaskWorker(task) {
|
|
12777
|
+
if (!await WorkerBody.inWorkerThread())
|
|
12778
|
+
throw new Error("initializeTaskWorker must run inside a worker");
|
|
12779
|
+
if (installed)
|
|
12780
|
+
throw new Error("A task is already installed in this worker");
|
|
12781
|
+
installed = true;
|
|
12782
|
+
const runtime = new TaskRuntime(task);
|
|
12783
|
+
let streamOptions = {};
|
|
12784
|
+
return createWorker(async (request, _options, context) => {
|
|
12785
|
+
switch (request.operation) {
|
|
12786
|
+
case "initialize":
|
|
12787
|
+
return runtime.initialize(request.input, context);
|
|
12788
|
+
case "destroy":
|
|
12789
|
+
return runtime.destroy();
|
|
12790
|
+
case "stream-options":
|
|
12791
|
+
streamOptions = request.options;
|
|
12792
|
+
return {};
|
|
12793
|
+
case "process":
|
|
12794
|
+
return runtime.process(request.input, request.options, context);
|
|
12795
|
+
default:
|
|
12796
|
+
throw new Error("Unknown task operation");
|
|
12797
|
+
}
|
|
12798
|
+
}, async function* (inputs, _options, context) {
|
|
12799
|
+
async function* batches() {
|
|
12800
|
+
for await (const input of inputs) {
|
|
12801
|
+
assertPayload(input);
|
|
12802
|
+
yield input;
|
|
12803
|
+
}
|
|
12804
|
+
}
|
|
12805
|
+
try {
|
|
12806
|
+
yield* runtime.stream(batches(), streamOptions, context);
|
|
12807
|
+
} finally {
|
|
12808
|
+
streamOptions = {};
|
|
12809
|
+
}
|
|
12810
|
+
}, () => preloadTaskCode(task));
|
|
12811
|
+
}
|
|
12812
|
+
var installed = false;
|
|
12813
|
+
function localContext(controls) {
|
|
12814
|
+
return {
|
|
12815
|
+
signal: controls.signal,
|
|
12816
|
+
reportProgress: (progress) => {
|
|
12817
|
+
var _a5;
|
|
12818
|
+
return (_a5 = controls.onProgress) == null ? void 0 : _a5.call(controls, progress);
|
|
12819
|
+
}
|
|
12820
|
+
};
|
|
12821
|
+
}
|
|
12822
|
+
|
|
12823
|
+
// ../../node_modules/@math.gl/core/dist/tasks/task-sync.js
|
|
12824
|
+
function runTaskSync(task, input, request = {}) {
|
|
12825
|
+
var _a5, _b2;
|
|
12826
|
+
if (!isTaskCodeLoaded(task))
|
|
12827
|
+
throw new Error("Preload task on the main thread before runTaskSync");
|
|
12828
|
+
if ("execution" in request)
|
|
12829
|
+
throw new TypeError("runTaskSync always runs on the calling thread");
|
|
12830
|
+
if (!task.process)
|
|
12831
|
+
throw new TypeError("Task has no atomic processor");
|
|
12832
|
+
for (const hook of [task.initialize, task.process, task.destroy]) {
|
|
12833
|
+
if (hook && Object.prototype.toString.call(hook) === "[object AsyncFunction]")
|
|
12834
|
+
throw new TypeError("runTaskSync requires synchronous lifecycle hooks");
|
|
12835
|
+
}
|
|
12836
|
+
if (request.outputOwnership && !["copy", "transfer"].includes(request.outputOwnership))
|
|
12837
|
+
throw new TypeError("Invalid output ownership");
|
|
12838
|
+
const context = taskContext(void 0, localContext(request));
|
|
12839
|
+
context.throwIfAborted();
|
|
12840
|
+
const options = request.options ?? {};
|
|
12841
|
+
if (request.inputOwnership === "transfer") {
|
|
12842
|
+
const metadata2 = new Set(getTransferList(options));
|
|
12843
|
+
if (getTransferList(input).some((buffer2) => metadata2.has(buffer2)))
|
|
12844
|
+
throw new Error("Transferred input aliases reusable options; use inputOwnership: copy");
|
|
12845
|
+
}
|
|
12846
|
+
const copiedOptions = clonePayload(options);
|
|
12847
|
+
const initialization = clonePayload(request.initialization ?? {}, request.initializationOwnership);
|
|
12848
|
+
let initialized = false;
|
|
12849
|
+
let failure;
|
|
12850
|
+
let failed = false;
|
|
12851
|
+
let output;
|
|
12852
|
+
try {
|
|
12853
|
+
const state = (_a5 = task.initialize) == null ? void 0 : _a5.call(task, initialization, context);
|
|
12854
|
+
if (isThenable(state)) {
|
|
12855
|
+
void Promise.resolve(state).then((value) => {
|
|
12856
|
+
var _a6;
|
|
12857
|
+
return (_a6 = task.destroy) == null ? void 0 : _a6.call(task, value);
|
|
12858
|
+
}).catch(() => {
|
|
12859
|
+
});
|
|
12860
|
+
throw new TypeError("runTaskSync initialize returned a promise");
|
|
12861
|
+
}
|
|
12862
|
+
context.state = state;
|
|
12863
|
+
initialized = true;
|
|
12864
|
+
context.throwIfAborted();
|
|
12865
|
+
const copiedInput = clonePayload(input, request.inputOwnership);
|
|
12866
|
+
const result = task.process(copiedInput, copiedOptions, context);
|
|
12867
|
+
if (isThenable(result)) {
|
|
12868
|
+
initialized = false;
|
|
12869
|
+
void Promise.resolve(result).catch(() => {
|
|
12870
|
+
}).then(() => {
|
|
12871
|
+
var _a6;
|
|
12872
|
+
if (task.initialize)
|
|
12873
|
+
return (_a6 = task.destroy) == null ? void 0 : _a6.call(task, context.state);
|
|
12874
|
+
}).catch(() => {
|
|
12875
|
+
});
|
|
12876
|
+
throw new TypeError("runTaskSync process returned a promise");
|
|
12877
|
+
}
|
|
12878
|
+
assertPayload(result);
|
|
12879
|
+
context.throwIfAborted();
|
|
12880
|
+
output = clonePayload(result, request.outputOwnership ?? "transfer");
|
|
12881
|
+
} catch (error) {
|
|
12882
|
+
failed = true;
|
|
12883
|
+
failure = error;
|
|
12884
|
+
} finally {
|
|
12885
|
+
if (initialized && task.initialize) {
|
|
12886
|
+
try {
|
|
12887
|
+
const cleanup = (_b2 = task.destroy) == null ? void 0 : _b2.call(task, context.state);
|
|
12888
|
+
if (isThenable(cleanup)) {
|
|
12889
|
+
void Promise.resolve(cleanup).catch(() => {
|
|
12890
|
+
});
|
|
12891
|
+
throw new TypeError("runTaskSync destroy returned a promise");
|
|
12892
|
+
}
|
|
12893
|
+
} catch (error) {
|
|
12894
|
+
if (failed)
|
|
12895
|
+
throw new AggregateError([failure, error], "Task processing and destruction failed");
|
|
12896
|
+
throw error;
|
|
12897
|
+
}
|
|
12898
|
+
}
|
|
12899
|
+
}
|
|
12900
|
+
if (failed)
|
|
12901
|
+
throw failure;
|
|
12902
|
+
return output;
|
|
12903
|
+
}
|
|
12904
|
+
function isThenable(value) {
|
|
12905
|
+
return Boolean(value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function");
|
|
12906
|
+
}
|
|
12907
|
+
|
|
12908
|
+
// ../../node_modules/@math.gl/core/dist/tasks/task-runner.js
|
|
12909
|
+
var InitializedTask = class {
|
|
12910
|
+
/** @internal Use TaskRunner.initializeTask. */
|
|
12911
|
+
constructor(task, release, controls) {
|
|
12912
|
+
var _a5, _b2;
|
|
12913
|
+
this.task = task;
|
|
12914
|
+
this.release = release;
|
|
12915
|
+
this.tail = Promise.resolve();
|
|
12916
|
+
this.closed = false;
|
|
12917
|
+
this.streams = /* @__PURE__ */ new Set();
|
|
12918
|
+
this.invalid = false;
|
|
12919
|
+
this.controller = new AbortController();
|
|
12920
|
+
this.runtime = new TaskRuntime(task);
|
|
12921
|
+
const execution = controls.execution ?? "auto";
|
|
12922
|
+
if (!["auto", "main-thread", "worker"].includes(execution))
|
|
12923
|
+
throw new TypeError("Invalid execution mode");
|
|
12924
|
+
if (execution === "worker" && !task.worker)
|
|
12925
|
+
throw new Error("Task has no worker");
|
|
12926
|
+
if (execution !== "main-thread" && task.worker) {
|
|
12927
|
+
const target = task.worker;
|
|
12928
|
+
if (Boolean(target.url) === Boolean(target.create))
|
|
12929
|
+
throw new Error("Supply exactly one worker URL or factory");
|
|
12930
|
+
this.pool = new WorkerPool({
|
|
12931
|
+
name: task.id,
|
|
12932
|
+
url: (_a5 = target.url) == null ? void 0 : _a5.toString(),
|
|
12933
|
+
loadWorker: target.create,
|
|
12934
|
+
workerType: "module",
|
|
12935
|
+
maxConcurrency: 1,
|
|
12936
|
+
maxMobileConcurrency: 1
|
|
12937
|
+
});
|
|
12938
|
+
this.descriptor = {
|
|
12939
|
+
id: task.id,
|
|
12940
|
+
name: task.id,
|
|
12941
|
+
module: "core",
|
|
12942
|
+
version: "prototype",
|
|
12943
|
+
options: {},
|
|
12944
|
+
worker: ((_b2 = target.url) == null ? void 0 : _b2.toString()) ?? true,
|
|
12945
|
+
loadWorker: target.create,
|
|
12946
|
+
workerInBatches: target.capabilities.streaming
|
|
12947
|
+
};
|
|
12948
|
+
}
|
|
12949
|
+
}
|
|
12950
|
+
/** @internal */
|
|
12951
|
+
async initialize(input, controls) {
|
|
12952
|
+
try {
|
|
12953
|
+
assertPayload(input);
|
|
12954
|
+
await this.enqueue(() => this.invoke("initialize", input, {}, controls));
|
|
12955
|
+
} catch (error) {
|
|
12956
|
+
await this.terminate(error);
|
|
12957
|
+
throw error;
|
|
12958
|
+
}
|
|
12959
|
+
}
|
|
12960
|
+
runTask(input, ...args) {
|
|
12961
|
+
return this.enqueue(async () => {
|
|
12962
|
+
var _a5;
|
|
12963
|
+
this.checkCapability("atomic");
|
|
12964
|
+
return this.invoke("process", input, ((_a5 = args[0]) == null ? void 0 : _a5.options) ?? {}, args[0]);
|
|
12965
|
+
});
|
|
12966
|
+
}
|
|
12967
|
+
/** Independent calls sharing this instance, always serial and in input order. */
|
|
12968
|
+
async *runTasks(inputs, ...args) {
|
|
12969
|
+
yield* this.serialStream(async function* (self2) {
|
|
12970
|
+
var _a5;
|
|
12971
|
+
self2.checkCapability("atomic");
|
|
12972
|
+
for await (const input of asAsync(inputs, self2.controls(args[0]).signal)) {
|
|
12973
|
+
yield await self2.invoke("process", input, ((_a5 = args[0]) == null ? void 0 : _a5.options) ?? {}, args[0]);
|
|
12974
|
+
}
|
|
12975
|
+
});
|
|
12976
|
+
}
|
|
12977
|
+
/** One processor invocation for the entire input iterable. */
|
|
12978
|
+
async *runTaskInBatches(inputs, ...args) {
|
|
12979
|
+
yield* this.serialStream(async function* (self2) {
|
|
12980
|
+
var _a5, _b2;
|
|
12981
|
+
self2.checkCapability("streaming");
|
|
12982
|
+
const controls = self2.controls(args[0]);
|
|
12983
|
+
const options = clonePayload(((_a5 = args[0]) == null ? void 0 : _a5.options) ?? {});
|
|
12984
|
+
async function* prepared() {
|
|
12985
|
+
var _a6, _b3;
|
|
12986
|
+
for await (const input of asAsync(inputs, controls.signal)) {
|
|
12987
|
+
(_a6 = controls.signal) == null ? void 0 : _a6.throwIfAborted();
|
|
12988
|
+
assertNoTransferAlias(input, ((_b3 = args[0]) == null ? void 0 : _b3.options) ?? {}, controls.inputOwnership);
|
|
12989
|
+
yield clonePayload(input, controls.inputOwnership);
|
|
12990
|
+
}
|
|
12991
|
+
}
|
|
12992
|
+
let completed = false;
|
|
12993
|
+
try {
|
|
12994
|
+
if (self2.pool) {
|
|
12995
|
+
await self2.invoke("stream-options", {}, options, controls);
|
|
12996
|
+
yield* processOnWorkerInBatches(self2.descriptor, prepared(), {
|
|
12997
|
+
...self2.workerOptions(controls),
|
|
12998
|
+
inputOwnership: "transfer",
|
|
12999
|
+
workerInBatches: true
|
|
13000
|
+
});
|
|
13001
|
+
} else {
|
|
13002
|
+
for await (const output of self2.runtime.stream(prepared(), options, localContext(controls))) {
|
|
13003
|
+
(_b2 = controls.signal) == null ? void 0 : _b2.throwIfAborted();
|
|
13004
|
+
yield clonePayload(output, controls.outputOwnership ?? "transfer");
|
|
13005
|
+
}
|
|
13006
|
+
}
|
|
13007
|
+
completed = true;
|
|
13008
|
+
} catch (error) {
|
|
13009
|
+
if (self2.pool) {
|
|
13010
|
+
self2.invalid = true;
|
|
13011
|
+
await self2.pool.destroy(error);
|
|
13012
|
+
}
|
|
13013
|
+
throw error;
|
|
13014
|
+
} finally {
|
|
13015
|
+
if (self2.pool && !completed)
|
|
13016
|
+
self2.invalid = true;
|
|
13017
|
+
}
|
|
13018
|
+
});
|
|
13019
|
+
}
|
|
13020
|
+
/** Drain accepted work, invoke destroy, and release execution capacity. */
|
|
13021
|
+
close() {
|
|
13022
|
+
if (!this.closing) {
|
|
13023
|
+
this.closed = true;
|
|
13024
|
+
this.closing = (async () => {
|
|
13025
|
+
var _a5;
|
|
13026
|
+
try {
|
|
13027
|
+
await this.tail;
|
|
13028
|
+
if (!this.invalid)
|
|
13029
|
+
await this.invoke("destroy", {}, {});
|
|
13030
|
+
} finally {
|
|
13031
|
+
try {
|
|
13032
|
+
await ((_a5 = this.pool) == null ? void 0 : _a5.destroy());
|
|
13033
|
+
} finally {
|
|
13034
|
+
this.release();
|
|
13035
|
+
}
|
|
13036
|
+
}
|
|
13037
|
+
})();
|
|
13038
|
+
}
|
|
13039
|
+
return this.closing;
|
|
13040
|
+
}
|
|
13041
|
+
/** Abort work. Local JavaScript must settle before its state can be destroyed. */
|
|
13042
|
+
async terminate(reason = new Error("Task terminated")) {
|
|
13043
|
+
this.controller.abort(reason);
|
|
13044
|
+
if (this.pool) {
|
|
13045
|
+
this.invalid = true;
|
|
13046
|
+
await this.pool.destroy(reason);
|
|
13047
|
+
}
|
|
13048
|
+
await Promise.allSettled([...this.streams].map((stop) => stop()));
|
|
13049
|
+
await this.close();
|
|
13050
|
+
}
|
|
13051
|
+
checkCapability(kind) {
|
|
13052
|
+
var _a5;
|
|
13053
|
+
if (this.pool ? !((_a5 = this.task.worker) == null ? void 0 : _a5.capabilities[kind]) : !(kind === "atomic" ? this.task.process : this.task.processInBatches)) {
|
|
13054
|
+
throw new Error(`Task has no ${kind} processor for this execution route`);
|
|
13055
|
+
}
|
|
13056
|
+
}
|
|
13057
|
+
controls(controls = {}) {
|
|
13058
|
+
if (controls.outputOwnership && !["copy", "transfer"].includes(controls.outputOwnership))
|
|
13059
|
+
throw new TypeError("Invalid output ownership");
|
|
13060
|
+
return {
|
|
13061
|
+
...controls,
|
|
13062
|
+
signal: controls.signal ? AbortSignal.any([controls.signal, this.controller.signal]) : this.controller.signal
|
|
13063
|
+
};
|
|
13064
|
+
}
|
|
13065
|
+
workerOptions(controls) {
|
|
13066
|
+
return {
|
|
13067
|
+
workerPool: this.pool,
|
|
13068
|
+
workerType: "module",
|
|
13069
|
+
inputOwnership: controls.inputOwnership ?? "copy",
|
|
13070
|
+
outputOwnership: controls.outputOwnership ?? "transfer",
|
|
13071
|
+
signal: controls.signal,
|
|
13072
|
+
onProgress: controls.onProgress,
|
|
13073
|
+
cancellationMode: "terminate"
|
|
13074
|
+
};
|
|
13075
|
+
}
|
|
13076
|
+
async invoke(operation, input, options, controls = {}) {
|
|
13077
|
+
var _a5, _b2, _c2;
|
|
13078
|
+
if (this.invalid)
|
|
13079
|
+
throw new Error("Initialized task is invalid; initialize a new instance");
|
|
13080
|
+
const prepared = operation === "destroy" ? {} : this.controls(controls);
|
|
13081
|
+
(_a5 = prepared.signal) == null ? void 0 : _a5.throwIfAborted();
|
|
13082
|
+
assertPayload(input);
|
|
13083
|
+
assertNoTransferAlias(input, options, prepared.inputOwnership);
|
|
13084
|
+
const copiedOptions = clonePayload(options);
|
|
13085
|
+
if (this.pool) {
|
|
13086
|
+
try {
|
|
13087
|
+
return await processOnWorker(this.descriptor, { operation, input: clonePayload(input, prepared.inputOwnership), options: copiedOptions }, this.workerOptions({ ...prepared, inputOwnership: "transfer" }));
|
|
13088
|
+
} catch (error) {
|
|
13089
|
+
this.invalid = true;
|
|
13090
|
+
await this.pool.destroy(error);
|
|
13091
|
+
throw error;
|
|
13092
|
+
}
|
|
13093
|
+
}
|
|
13094
|
+
if (operation === "destroy")
|
|
13095
|
+
return this.runtime.destroy();
|
|
13096
|
+
const copied = clonePayload(input, prepared.inputOwnership);
|
|
13097
|
+
const context = localContext(prepared);
|
|
13098
|
+
if (operation === "initialize") {
|
|
13099
|
+
const result2 = await this.runtime.initialize(copied, context);
|
|
13100
|
+
(_b2 = prepared.signal) == null ? void 0 : _b2.throwIfAborted();
|
|
13101
|
+
return result2;
|
|
13102
|
+
}
|
|
13103
|
+
const result = await this.runtime.process(copied, copiedOptions, context);
|
|
13104
|
+
(_c2 = prepared.signal) == null ? void 0 : _c2.throwIfAborted();
|
|
13105
|
+
return clonePayload(result, prepared.outputOwnership ?? "transfer");
|
|
13106
|
+
}
|
|
13107
|
+
enqueue(operation) {
|
|
13108
|
+
if (this.closed)
|
|
13109
|
+
return Promise.reject(new Error("Initialized task is closed"));
|
|
13110
|
+
const result = this.tail.then(operation);
|
|
13111
|
+
this.tail = result.catch(() => {
|
|
13112
|
+
});
|
|
13113
|
+
return result;
|
|
13114
|
+
}
|
|
13115
|
+
async *serialStream(operation) {
|
|
13116
|
+
if (this.closed)
|
|
13117
|
+
throw new Error("Initialized task is closed");
|
|
13118
|
+
const before = this.tail;
|
|
13119
|
+
let release;
|
|
13120
|
+
this.tail = new Promise((resolve) => {
|
|
13121
|
+
release = resolve;
|
|
13122
|
+
});
|
|
13123
|
+
await before;
|
|
13124
|
+
if (this.controller.signal.aborted) {
|
|
13125
|
+
release();
|
|
13126
|
+
throw this.controller.signal.reason;
|
|
13127
|
+
}
|
|
13128
|
+
const iterator = operation(this)[Symbol.asyncIterator]();
|
|
13129
|
+
let stopping;
|
|
13130
|
+
const stop = () => {
|
|
13131
|
+
stopping ?? (stopping = (async () => {
|
|
13132
|
+
var _a5;
|
|
13133
|
+
try {
|
|
13134
|
+
await ((_a5 = iterator.return) == null ? void 0 : _a5.call(iterator));
|
|
13135
|
+
} finally {
|
|
13136
|
+
this.streams.delete(stop);
|
|
13137
|
+
release();
|
|
13138
|
+
}
|
|
13139
|
+
})());
|
|
13140
|
+
return stopping;
|
|
13141
|
+
};
|
|
13142
|
+
this.streams.add(stop);
|
|
13143
|
+
try {
|
|
13144
|
+
while (true) {
|
|
13145
|
+
this.controller.signal.throwIfAborted();
|
|
13146
|
+
const next = await iterator.next();
|
|
13147
|
+
if (next.done)
|
|
13148
|
+
return;
|
|
13149
|
+
yield next.value;
|
|
13150
|
+
}
|
|
13151
|
+
} finally {
|
|
13152
|
+
await stop();
|
|
13153
|
+
}
|
|
13154
|
+
}
|
|
13155
|
+
};
|
|
13156
|
+
var TaskRunner = class {
|
|
13157
|
+
constructor(options = {}) {
|
|
13158
|
+
this.active = /* @__PURE__ */ new Set();
|
|
13159
|
+
this.count = 0;
|
|
13160
|
+
this.waiters = [];
|
|
13161
|
+
this.closed = false;
|
|
13162
|
+
this.initializing = /* @__PURE__ */ new Set();
|
|
13163
|
+
this.iterations = /* @__PURE__ */ new Set();
|
|
13164
|
+
this.maxConcurrency = options.maxConcurrency ?? 1;
|
|
13165
|
+
if (!Number.isSafeInteger(this.maxConcurrency) || this.maxConcurrency < 1)
|
|
13166
|
+
throw new RangeError("maxConcurrency must be a positive safe integer");
|
|
13167
|
+
}
|
|
13168
|
+
/** Execute synchronous hooks immediately on the calling thread, without queueing. */
|
|
13169
|
+
runTaskSync(task, input, ...args) {
|
|
13170
|
+
if (this.closed)
|
|
13171
|
+
throw new Error("Task runner is closed");
|
|
13172
|
+
if (this.count >= this.maxConcurrency)
|
|
13173
|
+
throw new Error("Task runner has no synchronous capacity");
|
|
13174
|
+
this.count++;
|
|
13175
|
+
try {
|
|
13176
|
+
return runTaskSync(task, input, args[0]);
|
|
13177
|
+
} finally {
|
|
13178
|
+
const waiter = this.waiters.shift();
|
|
13179
|
+
if (waiter)
|
|
13180
|
+
waiter.resolve();
|
|
13181
|
+
else
|
|
13182
|
+
this.count--;
|
|
13183
|
+
}
|
|
13184
|
+
}
|
|
13185
|
+
initializeTask(task, initialization, controls = {}) {
|
|
13186
|
+
const pending2 = this.open(task, initialization, controls);
|
|
13187
|
+
this.initializing.add(pending2);
|
|
13188
|
+
void pending2.then(() => this.initializing.delete(pending2), () => this.initializing.delete(pending2));
|
|
13189
|
+
return pending2;
|
|
13190
|
+
}
|
|
13191
|
+
async runTask(task, input, ...args) {
|
|
13192
|
+
const request = args[0] ?? {};
|
|
13193
|
+
const handle = await this.initializeTask(task, request.initialization ?? {}, {
|
|
13194
|
+
...request,
|
|
13195
|
+
inputOwnership: request.initializationOwnership ?? "copy"
|
|
13196
|
+
});
|
|
13197
|
+
return finish(handle, () => handle.runTask(input, request));
|
|
13198
|
+
}
|
|
13199
|
+
async *runTasks(task, inputs, ...args) {
|
|
13200
|
+
var _a5;
|
|
13201
|
+
const request = args[0] ?? {};
|
|
13202
|
+
if (this.closed)
|
|
13203
|
+
throw new Error("Task runner is closed");
|
|
13204
|
+
if (request.initializationOwnership === "transfer")
|
|
13205
|
+
throw new TypeError("runTasks initialization is a reusable template; use copy or share");
|
|
13206
|
+
const concurrency2 = request.concurrency ?? 1;
|
|
13207
|
+
if (!Number.isSafeInteger(concurrency2) || concurrency2 < 1 || concurrency2 > this.maxConcurrency)
|
|
13208
|
+
throw new RangeError("concurrency must be between 1 and maxConcurrency");
|
|
13209
|
+
const handles = [];
|
|
13210
|
+
const busy = /* @__PURE__ */ new Set();
|
|
13211
|
+
const pending2 = [];
|
|
13212
|
+
const controller = new AbortController();
|
|
13213
|
+
this.iterations.add(controller);
|
|
13214
|
+
const signal = request.signal ? AbortSignal.any([request.signal, controller.signal]) : controller.signal;
|
|
13215
|
+
const iterator = asAsync(inputs, signal)[Symbol.asyncIterator]();
|
|
13216
|
+
let finished2 = false;
|
|
13217
|
+
let reading;
|
|
13218
|
+
try {
|
|
13219
|
+
while (!finished2 || pending2.length) {
|
|
13220
|
+
signal.throwIfAborted();
|
|
13221
|
+
if (!finished2 && !reading && pending2.length < concurrency2) {
|
|
13222
|
+
reading = iterator.next().then((next) => ({ kind: "input", next }));
|
|
13223
|
+
}
|
|
13224
|
+
const event = await Promise.race([
|
|
13225
|
+
...pending2.length ? [pending2[0]] : [],
|
|
13226
|
+
...reading ? [reading] : []
|
|
13227
|
+
]);
|
|
13228
|
+
if (event.kind === "result") {
|
|
13229
|
+
pending2.shift();
|
|
13230
|
+
busy.delete(event.handle);
|
|
13231
|
+
if (event.failed)
|
|
13232
|
+
throw event.error;
|
|
13233
|
+
yield event.value;
|
|
13234
|
+
continue;
|
|
13235
|
+
}
|
|
13236
|
+
reading = void 0;
|
|
13237
|
+
if (event.next.done) {
|
|
13238
|
+
finished2 = true;
|
|
13239
|
+
continue;
|
|
13240
|
+
}
|
|
13241
|
+
let handle = handles.find((candidate) => !busy.has(candidate));
|
|
13242
|
+
if (!handle && (handles.length === 0 || this.count < this.maxConcurrency)) {
|
|
13243
|
+
handle = await this.initializeTask(task, clonePayload(request.initialization ?? {}, request.initializationOwnership), {
|
|
13244
|
+
...request,
|
|
13245
|
+
signal,
|
|
13246
|
+
inputOwnership: request.initializationOwnership ?? "copy"
|
|
13247
|
+
});
|
|
13248
|
+
handles.push(handle);
|
|
13249
|
+
}
|
|
13250
|
+
if (!handle) {
|
|
13251
|
+
const result = await pending2.shift();
|
|
13252
|
+
busy.delete(result.handle);
|
|
13253
|
+
if (result.failed)
|
|
13254
|
+
throw result.error;
|
|
13255
|
+
yield result.value;
|
|
13256
|
+
handle = result.handle;
|
|
13257
|
+
}
|
|
13258
|
+
busy.add(handle);
|
|
13259
|
+
const current = handle;
|
|
13260
|
+
pending2.push(handle.runTask(event.next.value, { ...request, signal }).then((value) => ({ kind: "result", handle: current, value }), (error) => ({ kind: "result", handle: current, failed: true, error })));
|
|
13261
|
+
}
|
|
13262
|
+
} finally {
|
|
13263
|
+
this.iterations.delete(controller);
|
|
13264
|
+
controller.abort(new Error("Task iteration closed"));
|
|
13265
|
+
try {
|
|
13266
|
+
if (reading)
|
|
13267
|
+
await reading.catch(() => {
|
|
13268
|
+
});
|
|
13269
|
+
if (!finished2)
|
|
13270
|
+
await ((_a5 = iterator.return) == null ? void 0 : _a5.call(iterator));
|
|
13271
|
+
} finally {
|
|
13272
|
+
await Promise.all(pending2);
|
|
13273
|
+
await Promise.all(handles.map((handle) => handle.close()));
|
|
13274
|
+
}
|
|
13275
|
+
}
|
|
13276
|
+
}
|
|
13277
|
+
async *runTaskInBatches(task, inputs, ...args) {
|
|
13278
|
+
const request = args[0] ?? {};
|
|
13279
|
+
const handle = await this.initializeTask(task, request.initialization ?? {}, {
|
|
13280
|
+
...request,
|
|
13281
|
+
inputOwnership: request.initializationOwnership ?? "copy"
|
|
13282
|
+
});
|
|
13283
|
+
try {
|
|
13284
|
+
yield* handle.runTaskInBatches(inputs, request);
|
|
13285
|
+
} finally {
|
|
13286
|
+
await handle.close();
|
|
13287
|
+
}
|
|
13288
|
+
}
|
|
13289
|
+
/** Close owned handles and workers. Finish or return active iterators first. */
|
|
13290
|
+
close() {
|
|
13291
|
+
if (!this.closing) {
|
|
13292
|
+
this.closed = true;
|
|
13293
|
+
for (const waiter of this.waiters.splice(0))
|
|
13294
|
+
waiter.reject(new Error("Task runner is closed"));
|
|
13295
|
+
this.closing = (async () => {
|
|
13296
|
+
await Promise.allSettled(this.initializing);
|
|
13297
|
+
const results = await Promise.allSettled([...this.active].map((handle) => handle.close()));
|
|
13298
|
+
const failure = results.find((result) => result.status === "rejected");
|
|
13299
|
+
if ((failure == null ? void 0 : failure.status) === "rejected")
|
|
13300
|
+
throw failure.reason;
|
|
13301
|
+
})();
|
|
13302
|
+
}
|
|
13303
|
+
return this.closing;
|
|
13304
|
+
}
|
|
13305
|
+
async terminate(reason = new Error("Task runner terminated")) {
|
|
13306
|
+
for (const controller of this.iterations)
|
|
13307
|
+
controller.abort(reason);
|
|
13308
|
+
const closing = this.close();
|
|
13309
|
+
await Promise.allSettled([...this.active].map((handle) => handle.terminate(reason)));
|
|
13310
|
+
await closing;
|
|
13311
|
+
}
|
|
13312
|
+
async open(task, initialization, controls) {
|
|
13313
|
+
var _a5;
|
|
13314
|
+
if (this.closed)
|
|
13315
|
+
throw new Error("Task runner is closed");
|
|
13316
|
+
(_a5 = controls.signal) == null ? void 0 : _a5.throwIfAborted();
|
|
13317
|
+
if (this.count >= this.maxConcurrency) {
|
|
13318
|
+
await new Promise((resolve, reject) => {
|
|
13319
|
+
var _a6, _b2;
|
|
13320
|
+
const waiter = {
|
|
13321
|
+
resolve: () => {
|
|
13322
|
+
cleanup();
|
|
13323
|
+
resolve();
|
|
13324
|
+
},
|
|
13325
|
+
reject: (error) => {
|
|
13326
|
+
cleanup();
|
|
13327
|
+
reject(error);
|
|
13328
|
+
}
|
|
13329
|
+
};
|
|
13330
|
+
const abort = () => {
|
|
13331
|
+
var _a7;
|
|
13332
|
+
this.waiters = this.waiters.filter((item) => item !== waiter);
|
|
13333
|
+
waiter.reject((_a7 = controls.signal) == null ? void 0 : _a7.reason);
|
|
13334
|
+
};
|
|
13335
|
+
const cleanup = () => {
|
|
13336
|
+
var _a7;
|
|
13337
|
+
return (_a7 = controls.signal) == null ? void 0 : _a7.removeEventListener("abort", abort);
|
|
13338
|
+
};
|
|
13339
|
+
this.waiters.push(waiter);
|
|
13340
|
+
(_a6 = controls.signal) == null ? void 0 : _a6.addEventListener("abort", abort, { once: true });
|
|
13341
|
+
if ((_b2 = controls.signal) == null ? void 0 : _b2.aborted)
|
|
13342
|
+
abort();
|
|
13343
|
+
});
|
|
13344
|
+
} else
|
|
13345
|
+
this.count++;
|
|
13346
|
+
let handle;
|
|
13347
|
+
let released = false;
|
|
13348
|
+
const release = () => {
|
|
13349
|
+
if (released)
|
|
13350
|
+
return;
|
|
13351
|
+
released = true;
|
|
13352
|
+
if (handle)
|
|
13353
|
+
this.active.delete(handle);
|
|
13354
|
+
const waiter = this.waiters.shift();
|
|
13355
|
+
if (waiter)
|
|
13356
|
+
waiter.resolve();
|
|
13357
|
+
else
|
|
13358
|
+
this.count--;
|
|
13359
|
+
};
|
|
13360
|
+
try {
|
|
13361
|
+
if (this.closed)
|
|
13362
|
+
throw new Error("Task runner is closed");
|
|
13363
|
+
handle = new InitializedTask(task, release, controls);
|
|
13364
|
+
this.active.add(handle);
|
|
13365
|
+
await handle.initialize(initialization, controls);
|
|
13366
|
+
return handle;
|
|
13367
|
+
} catch (error) {
|
|
13368
|
+
release();
|
|
13369
|
+
throw error;
|
|
13370
|
+
}
|
|
13371
|
+
}
|
|
13372
|
+
};
|
|
13373
|
+
async function finish(handle, operation) {
|
|
13374
|
+
let result;
|
|
13375
|
+
try {
|
|
13376
|
+
result = await operation();
|
|
13377
|
+
} catch (error) {
|
|
13378
|
+
try {
|
|
13379
|
+
await handle.close();
|
|
13380
|
+
} catch (cleanup) {
|
|
13381
|
+
throw new AggregateError([error, cleanup], "Task processing and destruction failed");
|
|
13382
|
+
}
|
|
13383
|
+
throw error;
|
|
13384
|
+
}
|
|
13385
|
+
await handle.close();
|
|
13386
|
+
return result;
|
|
13387
|
+
}
|
|
13388
|
+
async function* asAsync(inputs, signal) {
|
|
13389
|
+
var _a5, _b2;
|
|
13390
|
+
const iterator = Symbol.asyncIterator in inputs ? inputs[Symbol.asyncIterator]() : inputs[Symbol.iterator]();
|
|
13391
|
+
let done = false;
|
|
13392
|
+
let blocked = false;
|
|
13393
|
+
try {
|
|
13394
|
+
while (true) {
|
|
13395
|
+
const next = await new Promise((resolve, reject) => {
|
|
13396
|
+
const cleanup = () => signal == null ? void 0 : signal.removeEventListener("abort", abort);
|
|
13397
|
+
const abort = () => {
|
|
13398
|
+
cleanup();
|
|
13399
|
+
reject(signal == null ? void 0 : signal.reason);
|
|
13400
|
+
};
|
|
13401
|
+
signal == null ? void 0 : signal.addEventListener("abort", abort, { once: true });
|
|
13402
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
13403
|
+
abort();
|
|
13404
|
+
return;
|
|
13405
|
+
}
|
|
13406
|
+
try {
|
|
13407
|
+
blocked = true;
|
|
13408
|
+
Promise.resolve(iterator.next()).then((value) => {
|
|
13409
|
+
blocked = false;
|
|
13410
|
+
cleanup();
|
|
13411
|
+
resolve(value);
|
|
13412
|
+
}, (error) => {
|
|
13413
|
+
blocked = false;
|
|
13414
|
+
cleanup();
|
|
13415
|
+
reject(error);
|
|
13416
|
+
});
|
|
13417
|
+
} catch (error) {
|
|
13418
|
+
blocked = false;
|
|
13419
|
+
cleanup();
|
|
13420
|
+
reject(error);
|
|
13421
|
+
}
|
|
13422
|
+
});
|
|
13423
|
+
if (next.done) {
|
|
13424
|
+
done = true;
|
|
13425
|
+
return;
|
|
13426
|
+
}
|
|
13427
|
+
yield next.value;
|
|
13428
|
+
}
|
|
13429
|
+
} finally {
|
|
13430
|
+
if (!done) {
|
|
13431
|
+
if (blocked) {
|
|
13432
|
+
try {
|
|
13433
|
+
void Promise.resolve((_a5 = iterator.return) == null ? void 0 : _a5.call(iterator)).catch(() => {
|
|
13434
|
+
});
|
|
13435
|
+
} catch {
|
|
13436
|
+
}
|
|
13437
|
+
} else {
|
|
13438
|
+
await ((_b2 = iterator.return) == null ? void 0 : _b2.call(iterator));
|
|
13439
|
+
}
|
|
13440
|
+
}
|
|
13441
|
+
}
|
|
13442
|
+
}
|
|
13443
|
+
function assertNoTransferAlias(input, options, ownership) {
|
|
13444
|
+
if (ownership === "transfer") {
|
|
13445
|
+
const metadata2 = new Set(getTransferList(options));
|
|
13446
|
+
if (getTransferList(input).some((buffer2) => metadata2.has(buffer2))) {
|
|
13447
|
+
throw new Error("Transferred input aliases reusable options; use inputOwnership: copy");
|
|
13448
|
+
}
|
|
13449
|
+
}
|
|
13450
|
+
}
|
|
13451
|
+
|
|
13452
|
+
// ../core/src/worker-utils/lib/worker-api/task-runtime.ts
|
|
13453
|
+
function normalizeTaskProgress(progress) {
|
|
13454
|
+
return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
|
|
13455
|
+
}
|
|
13456
|
+
async function isWorkerThread() {
|
|
13457
|
+
var _a5;
|
|
13458
|
+
if (typeof self !== "undefined" && typeof document === "undefined" && typeof self.postMessage === "function")
|
|
13459
|
+
return true;
|
|
13460
|
+
if (typeof process !== "undefined" && ((_a5 = process.versions) == null ? void 0 : _a5.node)) {
|
|
13461
|
+
const { isMainThread: isMainThread2 } = await Promise.resolve().then(() => (init_worker_threads(), worker_threads_exports));
|
|
13462
|
+
return !isMainThread2;
|
|
13463
|
+
}
|
|
13464
|
+
return false;
|
|
13465
|
+
}
|
|
13466
|
+
var initializeTaskWorker2 = initializeTaskWorker;
|
|
13467
|
+
|
|
13468
|
+
// ../core/src/worker-utils/lib/worker-api/get-worker-url.ts
|
|
13469
|
+
var warnedWorkerVersionFallbacks2 = /* @__PURE__ */ new Set();
|
|
13470
|
+
function getCustomWorkerURL2(worker, options = {}) {
|
|
13471
|
+
var _a5, _b2;
|
|
13472
|
+
const workerFile = isBrowser2 ? worker.workerFile || `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
|
|
13473
|
+
let url = getConfiguredWorkerURL2(worker, options);
|
|
13474
|
+
const workerType = options._workerType || ((_a5 = options == null ? void 0 : options.core) == null ? void 0 : _a5._workerType);
|
|
13475
|
+
if (!url && workerType === "test") {
|
|
13476
|
+
if (isBrowser2) {
|
|
13477
|
+
url = `modules/${worker.module}/dist/${workerFile}`;
|
|
13478
|
+
} else {
|
|
13479
|
+
const workerSourceDirectory = worker.module === "core" && ((_b2 = worker.workerNode) == null ? void 0 : _b2.startsWith("worker-utils/")) ? "worker-utils/workers" : "workers";
|
|
13480
|
+
const workerSourceNode = worker.workerSourceNode || `${workerSourceDirectory}/${worker.id}-worker-node.ts`;
|
|
13481
|
+
url = `modules/${worker.module}/src/${workerSourceNode}`;
|
|
13482
|
+
}
|
|
13483
|
+
}
|
|
13484
|
+
return url || null;
|
|
13485
|
+
}
|
|
13486
|
+
function getConfiguredWorkerURL2(worker, options = {}) {
|
|
13487
|
+
const workerOptions = options[worker.id] || {};
|
|
13488
|
+
return workerOptions.workerUrl || (worker.id === "compression" ? options.workerUrl : null) || null;
|
|
13489
|
+
}
|
|
13490
|
+
function getWorkerURL2(worker, options = {}) {
|
|
13491
|
+
const customWorkerUrl = getCustomWorkerURL2(worker, options);
|
|
13492
|
+
const descriptorWorkerUrl = typeof worker.worker === "string" ? worker.worker : null;
|
|
13493
|
+
const url = customWorkerUrl || descriptorWorkerUrl || getDefaultWorkerURL2(worker, true);
|
|
13494
|
+
assert(url);
|
|
13495
|
+
return url;
|
|
13496
|
+
}
|
|
13497
|
+
function getDefaultWorkerURL2(worker, warn = false) {
|
|
13498
|
+
const workerFile = isBrowser2 ? worker.workerFile || `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
|
|
13499
|
+
let version2 = worker.version;
|
|
13500
|
+
if (version2 === "latest") {
|
|
13501
|
+
version2 = NPM_TAG;
|
|
13502
|
+
}
|
|
13503
|
+
const versionTag = version2 ? `@${version2}` : "";
|
|
13504
|
+
const url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;
|
|
13505
|
+
if (warn) {
|
|
13506
|
+
warnIfUsingNpmTagFallback2(worker, url);
|
|
13507
|
+
}
|
|
13508
|
+
return url;
|
|
13509
|
+
}
|
|
13510
|
+
function warnIfUsingNpmTagFallback2(worker, url) {
|
|
13511
|
+
if (worker.version !== "latest") {
|
|
13512
|
+
return;
|
|
13513
|
+
}
|
|
13514
|
+
const workerId = `${worker.module}:${worker.id}`;
|
|
13515
|
+
if (warnedWorkerVersionFallbacks2.has(workerId)) {
|
|
13516
|
+
return;
|
|
13517
|
+
}
|
|
13518
|
+
warnedWorkerVersionFallbacks2.add(workerId);
|
|
13519
|
+
console.warn(
|
|
13520
|
+
`loaders.gl: ${worker.name} loader worker version is "latest" because __VERSION__ was not injected. Fetching ${url} from CDN.`
|
|
13521
|
+
);
|
|
13522
|
+
}
|
|
13523
|
+
|
|
13524
|
+
// ../core/src/worker-utils/lib/worker-utils/get-transfer-list.ts
|
|
13525
|
+
function getTransferList2(object2, recursive = true, transfers) {
|
|
13526
|
+
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
13527
|
+
if (!object2) {
|
|
13528
|
+
} else if (isTransferable2(object2)) {
|
|
13529
|
+
transfersSet.add(object2);
|
|
13530
|
+
} else if (isTransferable2(object2.buffer)) {
|
|
13531
|
+
transfersSet.add(object2.buffer);
|
|
13532
|
+
} else if (ArrayBuffer.isView(object2)) {
|
|
13533
|
+
} else if (recursive && typeof object2 === "object") {
|
|
13534
|
+
for (const key in object2) {
|
|
13535
|
+
getTransferList2(object2[key], recursive, transfersSet);
|
|
13536
|
+
}
|
|
13537
|
+
}
|
|
13538
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
13539
|
+
}
|
|
13540
|
+
function isTransferable2(object2) {
|
|
13541
|
+
if (!object2) {
|
|
13542
|
+
return false;
|
|
13543
|
+
}
|
|
13544
|
+
if (object2 instanceof ArrayBuffer) {
|
|
13545
|
+
return true;
|
|
13546
|
+
}
|
|
13547
|
+
if (typeof MessagePort !== "undefined" && object2 instanceof MessagePort) {
|
|
13548
|
+
return true;
|
|
13549
|
+
}
|
|
13550
|
+
if (typeof ImageBitmap !== "undefined" && object2 instanceof ImageBitmap) {
|
|
13551
|
+
return true;
|
|
13552
|
+
}
|
|
13553
|
+
if (typeof OffscreenCanvas !== "undefined" && object2 instanceof OffscreenCanvas) {
|
|
13554
|
+
return true;
|
|
13555
|
+
}
|
|
13556
|
+
return false;
|
|
13557
|
+
}
|
|
13558
|
+
function getTransferListForWriter2(object2) {
|
|
13559
|
+
if (object2 === null) {
|
|
13560
|
+
return {};
|
|
13561
|
+
}
|
|
13562
|
+
const clone2 = Object.assign({}, object2);
|
|
13563
|
+
Object.keys(clone2).forEach((key) => {
|
|
13564
|
+
if (object2[key] !== null && typeof object2[key] === "object" && !ArrayBuffer.isView(object2[key]) && !(object2[key] instanceof Array)) {
|
|
13565
|
+
clone2[key] = getTransferListForWriter2(object2[key]);
|
|
13566
|
+
} else if (typeof clone2[key] === "function" || clone2[key] instanceof RegExp) {
|
|
13567
|
+
clone2[key] = {};
|
|
13568
|
+
} else {
|
|
13569
|
+
clone2[key] = object2[key];
|
|
13570
|
+
}
|
|
13571
|
+
});
|
|
13572
|
+
return clone2;
|
|
13573
|
+
}
|
|
13574
|
+
|
|
13575
|
+
// ../core/src/worker-utils/lib/worker-api/process-on-worker.ts
|
|
13576
|
+
var runners = /* @__PURE__ */ new WeakMap();
|
|
13577
|
+
var activeRunners = /* @__PURE__ */ new Set();
|
|
13578
|
+
var moduleWorkerUrls = /* @__PURE__ */ new Map();
|
|
13579
|
+
function canProcessOnWorker2(worker, options = {}) {
|
|
13580
|
+
const supported = isBrowser2 ? typeof Worker !== "undefined" : Boolean(options._nodeWorkers);
|
|
13581
|
+
return Boolean(
|
|
13582
|
+
supported && options.worker && (worker.worker || worker.loadWorker || getConfiguredWorkerURL2(worker, options))
|
|
13583
|
+
);
|
|
13584
|
+
}
|
|
13585
|
+
async function* processOnWorkerInBatches2(worker, input, options = {}, context = {}, jobContext = {}) {
|
|
13586
|
+
var _a5;
|
|
13587
|
+
const taskInput = wrapInput(input);
|
|
13588
|
+
let session;
|
|
13589
|
+
try {
|
|
13590
|
+
session = await openSession(worker, options, context, jobContext);
|
|
13591
|
+
for await (const result of session.handle.runTaskInBatches(taskInput, {
|
|
13592
|
+
...getControls(options),
|
|
13593
|
+
options: getParserOptions(options)
|
|
13594
|
+
}))
|
|
13595
|
+
yield result.value;
|
|
13596
|
+
} finally {
|
|
13597
|
+
const closingInput = (_a5 = taskInput.return) == null ? void 0 : _a5.call(taskInput);
|
|
13598
|
+
void (closingInput == null ? void 0 : closingInput.catch(() => {
|
|
13599
|
+
}));
|
|
13600
|
+
await (session == null ? void 0 : session.close());
|
|
13601
|
+
}
|
|
13602
|
+
}
|
|
13603
|
+
function getTask(worker, options) {
|
|
13604
|
+
var _a5;
|
|
13605
|
+
if (options.source || ((_a5 = options.core) == null ? void 0 : _a5.source))
|
|
13606
|
+
throw new Error(
|
|
13607
|
+
"Inline legacy worker source is unsupported; use a TaskRunner worker URL or factory"
|
|
13608
|
+
);
|
|
13609
|
+
const create = !getCustomWorkerURL2(worker, options) && isBrowser2 ? worker.loadWorker : void 0;
|
|
13610
|
+
const url = getWorkerURL2(worker, options);
|
|
13611
|
+
return {
|
|
13612
|
+
id: `${worker.module}:${worker.id}`,
|
|
13613
|
+
initialize: (state) => state,
|
|
13614
|
+
worker: {
|
|
13615
|
+
...create ? { create: () => create() ?? createModuleWorker(url) } : { url },
|
|
13616
|
+
capabilities: { atomic: true, streaming: true }
|
|
13617
|
+
}
|
|
13618
|
+
};
|
|
13619
|
+
}
|
|
13620
|
+
function getControls(options) {
|
|
13621
|
+
return {
|
|
13622
|
+
execution: "worker",
|
|
13623
|
+
signal: options.signal,
|
|
13624
|
+
inputOwnership: options.inputOwnership ?? "transfer",
|
|
13625
|
+
outputOwnership: options.outputOwnership ?? "transfer",
|
|
13626
|
+
onProgress: options.onProgress ? (progress) => {
|
|
13627
|
+
var _a5;
|
|
13628
|
+
return (_a5 = options.onProgress) == null ? void 0 : _a5.call(options, normalizeTaskProgress(progress));
|
|
13629
|
+
} : void 0
|
|
13630
|
+
};
|
|
13631
|
+
}
|
|
13632
|
+
function getParserOptions(options) {
|
|
13633
|
+
const { signal, onProgress, ...parserOptions } = options;
|
|
13634
|
+
return getTransferListForWriter2(parserOptions);
|
|
13635
|
+
}
|
|
13636
|
+
async function openSession(worker, options, context, jobContext) {
|
|
13637
|
+
var _a5, _b2;
|
|
13638
|
+
(_a5 = options.signal) == null ? void 0 : _a5.throwIfAborted();
|
|
13639
|
+
const task = getTask(worker, options);
|
|
13640
|
+
let state = runners.get(worker);
|
|
13641
|
+
if (!state) {
|
|
13642
|
+
state = {
|
|
13643
|
+
runner: new TaskRunner({
|
|
13644
|
+
maxConcurrency: isMobile ? options.maxMobileConcurrency ?? 1 : options.maxConcurrency ?? 3
|
|
13645
|
+
}),
|
|
13646
|
+
requests: 0
|
|
13647
|
+
};
|
|
13648
|
+
runners.set(worker, state);
|
|
13649
|
+
}
|
|
13650
|
+
const runnerState = state;
|
|
13651
|
+
const channel = context.process ? new MessageChannel() : void 0;
|
|
13652
|
+
const callbackController = new AbortController();
|
|
13653
|
+
let channelClosed = false;
|
|
13654
|
+
const abortCallbacks = () => {
|
|
13655
|
+
var _a6;
|
|
13656
|
+
return callbackController.abort((_a6 = options.signal) == null ? void 0 : _a6.reason);
|
|
13657
|
+
};
|
|
13658
|
+
(_b2 = options.signal) == null ? void 0 : _b2.addEventListener("abort", abortCallbacks, { once: true });
|
|
13659
|
+
const closeChannel = () => {
|
|
13660
|
+
var _a6;
|
|
13661
|
+
channelClosed = true;
|
|
13662
|
+
(_a6 = options.signal) == null ? void 0 : _a6.removeEventListener("abort", abortCallbacks);
|
|
13663
|
+
callbackController.abort();
|
|
13664
|
+
channel == null ? void 0 : channel.port1.close();
|
|
13665
|
+
channel == null ? void 0 : channel.port2.close();
|
|
13666
|
+
};
|
|
13667
|
+
if (channel) {
|
|
13668
|
+
channel.port1.onmessage = async ({ data }) => {
|
|
13669
|
+
try {
|
|
13670
|
+
const value = await context.process(
|
|
13671
|
+
data.input,
|
|
13672
|
+
data.options,
|
|
13673
|
+
{
|
|
13674
|
+
signal: callbackController.signal,
|
|
13675
|
+
throwIfAborted: () => callbackController.signal.throwIfAborted()
|
|
13676
|
+
},
|
|
13677
|
+
data.context
|
|
13678
|
+
);
|
|
13679
|
+
if (!channelClosed && !callbackController.signal.aborted)
|
|
13680
|
+
channel.port1.postMessage({ identifier: data.identifier, value }, getTransferList2(value));
|
|
13681
|
+
} catch (error) {
|
|
13682
|
+
if (channelClosed || callbackController.signal.aborted) return;
|
|
13683
|
+
channel.port1.postMessage({
|
|
13684
|
+
identifier: data.identifier,
|
|
13685
|
+
error: {
|
|
13686
|
+
name: error instanceof Error ? error.name : "Error",
|
|
13687
|
+
message: error instanceof Error ? error.message : String(error)
|
|
13688
|
+
}
|
|
13689
|
+
});
|
|
13690
|
+
}
|
|
13691
|
+
};
|
|
13692
|
+
channel.port1.start();
|
|
13693
|
+
}
|
|
13694
|
+
runnerState.requests++;
|
|
13695
|
+
activeRunners.add(runnerState);
|
|
13696
|
+
let released = false;
|
|
13697
|
+
const releaseRunner = () => {
|
|
13698
|
+
if (released) return;
|
|
13699
|
+
released = true;
|
|
13700
|
+
runnerState.requests--;
|
|
13701
|
+
if (!runnerState.requests) activeRunners.delete(runnerState);
|
|
13702
|
+
};
|
|
13703
|
+
let handle;
|
|
13704
|
+
try {
|
|
13705
|
+
handle = await runnerState.runner.initializeTask(
|
|
13706
|
+
task,
|
|
13707
|
+
{
|
|
13708
|
+
context: structuredClone(jobContext),
|
|
13709
|
+
...channel ? { port: channel.port2 } : {}
|
|
13710
|
+
},
|
|
13711
|
+
// The callback port is setup state, independent of the caller's payload ownership.
|
|
13712
|
+
{ ...getControls(options), inputOwnership: "transfer" }
|
|
13713
|
+
);
|
|
13714
|
+
} catch (error) {
|
|
13715
|
+
releaseRunner();
|
|
13716
|
+
closeChannel();
|
|
13717
|
+
throw error;
|
|
13718
|
+
}
|
|
13719
|
+
return {
|
|
13720
|
+
handle,
|
|
13721
|
+
/** Releases the worker and callback channel on success, failure, and early stream return. */
|
|
13722
|
+
async close() {
|
|
13723
|
+
try {
|
|
13724
|
+
await handle.close();
|
|
13725
|
+
} finally {
|
|
13726
|
+
closeChannel();
|
|
13727
|
+
releaseRunner();
|
|
13728
|
+
}
|
|
13729
|
+
}
|
|
13730
|
+
};
|
|
13731
|
+
}
|
|
13732
|
+
function wrapInput(input) {
|
|
13733
|
+
const iterator = Symbol.asyncIterator in input ? input[Symbol.asyncIterator]() : input[Symbol.iterator]();
|
|
13734
|
+
let inputClosed = false;
|
|
13735
|
+
return {
|
|
13736
|
+
[Symbol.asyncIterator]() {
|
|
13737
|
+
return this;
|
|
13738
|
+
},
|
|
13739
|
+
async next() {
|
|
13740
|
+
if (inputClosed) return { done: true, value: void 0 };
|
|
13741
|
+
const next = await iterator.next();
|
|
13742
|
+
if (next.done || inputClosed) {
|
|
13743
|
+
inputClosed = true;
|
|
13744
|
+
return { done: true, value: void 0 };
|
|
13745
|
+
}
|
|
13746
|
+
return { done: false, value: { value: next.value } };
|
|
13747
|
+
},
|
|
13748
|
+
async return() {
|
|
13749
|
+
var _a5;
|
|
13750
|
+
if (!inputClosed) {
|
|
13751
|
+
inputClosed = true;
|
|
13752
|
+
await ((_a5 = iterator.return) == null ? void 0 : _a5.call(iterator));
|
|
13753
|
+
}
|
|
13754
|
+
return { done: true, value: void 0 };
|
|
13755
|
+
}
|
|
13756
|
+
};
|
|
13757
|
+
}
|
|
13758
|
+
function createModuleWorker(url) {
|
|
13759
|
+
var _a5;
|
|
13760
|
+
const resolved = new URL(url, ((_a5 = globalThis.document) == null ? void 0 : _a5.baseURI) ?? globalThis.location.href);
|
|
13761
|
+
let workerUrl = resolved.href;
|
|
13762
|
+
if (/^https?:$/.test(resolved.protocol) && resolved.origin !== globalThis.location.origin) {
|
|
13763
|
+
let shimUrl = moduleWorkerUrls.get(resolved.href);
|
|
13764
|
+
if (!shimUrl) {
|
|
13765
|
+
shimUrl = URL.createObjectURL(
|
|
13766
|
+
new Blob([`import ${JSON.stringify(resolved.href)};`], { type: "application/javascript" })
|
|
13767
|
+
);
|
|
13768
|
+
moduleWorkerUrls.set(resolved.href, shimUrl);
|
|
13769
|
+
}
|
|
13770
|
+
workerUrl = shimUrl;
|
|
13771
|
+
}
|
|
13772
|
+
return new Worker(workerUrl, { type: "module" });
|
|
13773
|
+
}
|
|
13774
|
+
|
|
13775
|
+
// ../core/src/worker-utils/lib/worker-api/create-worker.ts
|
|
13776
|
+
async function createWorker2(process2, processInBatches) {
|
|
13777
|
+
if (!await isWorkerThread()) return;
|
|
13778
|
+
await initializeTaskWorker2(createWorkerTask(process2, processInBatches));
|
|
13779
|
+
}
|
|
13780
|
+
function createWorkerTask(process2, processInBatches) {
|
|
13781
|
+
return {
|
|
13782
|
+
id: "loaders.gl",
|
|
13783
|
+
initialize: (state) => state,
|
|
13784
|
+
destroy: (state) => {
|
|
13785
|
+
var _a5;
|
|
13786
|
+
return (_a5 = state.port) == null ? void 0 : _a5.close();
|
|
13787
|
+
},
|
|
13788
|
+
process: async ({ value }, options, context) => {
|
|
13789
|
+
if (!process2) throw new Error("Worker does not support atomic processing");
|
|
13790
|
+
return { value: await process2(value, options, createContext(context), context.state.context) };
|
|
13791
|
+
},
|
|
13792
|
+
...processInBatches ? {
|
|
13793
|
+
processInBatches: async function* (inputs, options, context) {
|
|
13794
|
+
async function* values() {
|
|
13795
|
+
for await (const input of inputs) yield input.value;
|
|
13796
|
+
}
|
|
13797
|
+
for await (const value of processInBatches(
|
|
13798
|
+
values(),
|
|
13799
|
+
options,
|
|
13800
|
+
createContext(context),
|
|
13801
|
+
context.state.context
|
|
13802
|
+
)) {
|
|
13803
|
+
yield { value };
|
|
13804
|
+
}
|
|
13805
|
+
}
|
|
13806
|
+
} : {}
|
|
13807
|
+
};
|
|
13808
|
+
}
|
|
13809
|
+
function createContext(context) {
|
|
13810
|
+
let requestIdentifier = 0;
|
|
13811
|
+
const port = context.state.port;
|
|
13812
|
+
return {
|
|
13813
|
+
signal: context.signal,
|
|
13814
|
+
throwIfAborted: () => context.throwIfAborted(),
|
|
13815
|
+
reportProgress: (progress) => context.reportProgress(normalizeTaskProgress(progress)),
|
|
13816
|
+
process: port ? (input, options = {}, jobContext = {}) => {
|
|
13817
|
+
context.throwIfAborted();
|
|
13818
|
+
const identifier = ++requestIdentifier;
|
|
13819
|
+
return new Promise((resolve, reject) => {
|
|
13820
|
+
const onMessage2 = (event) => {
|
|
13821
|
+
if (event.data.identifier !== identifier) return;
|
|
13822
|
+
cleanup();
|
|
13823
|
+
if (event.data.error) {
|
|
13824
|
+
const error = new Error(event.data.error.message);
|
|
13825
|
+
error.name = event.data.error.name;
|
|
13826
|
+
reject(error);
|
|
13827
|
+
} else resolve(event.data.value);
|
|
13828
|
+
};
|
|
13829
|
+
const onAbort = () => {
|
|
13830
|
+
cleanup();
|
|
13831
|
+
reject(context.signal.reason);
|
|
13832
|
+
};
|
|
13833
|
+
const cleanup = () => {
|
|
13834
|
+
port.removeEventListener("message", onMessage2);
|
|
13835
|
+
context.signal.removeEventListener("abort", onAbort);
|
|
13836
|
+
};
|
|
13837
|
+
port.addEventListener("message", onMessage2);
|
|
13838
|
+
context.signal.addEventListener("abort", onAbort, { once: true });
|
|
13839
|
+
port.start();
|
|
13840
|
+
try {
|
|
13841
|
+
const request = { identifier, input, options, context: jobContext };
|
|
13842
|
+
port.postMessage(request, getTransferList2(request));
|
|
13843
|
+
} catch (error) {
|
|
13844
|
+
cleanup();
|
|
13845
|
+
reject(error);
|
|
13846
|
+
}
|
|
13847
|
+
});
|
|
13848
|
+
} : void 0
|
|
13849
|
+
};
|
|
13850
|
+
}
|
|
13851
|
+
|
|
12518
13852
|
// ../core/src/worker-utils/lib/library-utils/library-utils.ts
|
|
12519
13853
|
var loadLibraryPromises = {};
|
|
12520
13854
|
function extractLoadLibraryOptions(options = {}) {
|
|
@@ -12720,15 +14054,15 @@ function initializeWasmModule(initialize, extractExports) {
|
|
|
12720
14054
|
// ../core/src/loader-utils/lib/worker-loader-utils/encode-with-worker.ts
|
|
12721
14055
|
function canEncodeWithWorker(writer, options) {
|
|
12722
14056
|
var _a5, _b2;
|
|
12723
|
-
if (!WorkerFarm.isSupported()) {
|
|
12724
|
-
return false;
|
|
12725
|
-
}
|
|
12726
14057
|
const nodeWorkers = (options == null ? void 0 : options._nodeWorkers) ?? ((_a5 = options == null ? void 0 : options.core) == null ? void 0 : _a5._nodeWorkers);
|
|
12727
14058
|
const useWorkers = (options == null ? void 0 : options.worker) ?? ((_b2 = options == null ? void 0 : options.core) == null ? void 0 : _b2.worker);
|
|
12728
14059
|
if (!isBrowser4 && !nodeWorkers) {
|
|
12729
14060
|
return false;
|
|
12730
14061
|
}
|
|
12731
|
-
return
|
|
14062
|
+
return canProcessOnWorker2(
|
|
14063
|
+
{ ...writer, options: writer.options || {} },
|
|
14064
|
+
{ worker: Boolean(useWorkers), _nodeWorkers: Boolean(nodeWorkers) }
|
|
14065
|
+
);
|
|
12732
14066
|
}
|
|
12733
14067
|
|
|
12734
14068
|
// ../../node_modules/@math.gl/core/dist/types/float16.js
|
|
@@ -19371,11 +20705,11 @@ var VariableWidthBuilder = class extends Builder {
|
|
|
19371
20705
|
this._offsets = new OffsetsBufferBuilder(opts.type);
|
|
19372
20706
|
}
|
|
19373
20707
|
setValue(index2, value) {
|
|
19374
|
-
const
|
|
19375
|
-
const current =
|
|
20708
|
+
const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
|
|
20709
|
+
const current = pending2.get(index2);
|
|
19376
20710
|
current && (this._pendingLength -= current.length);
|
|
19377
20711
|
this._pendingLength += value instanceof MapRow ? value[kKeys].length : value.length;
|
|
19378
|
-
|
|
20712
|
+
pending2.set(index2, value);
|
|
19379
20713
|
}
|
|
19380
20714
|
setValid(index2, isValid) {
|
|
19381
20715
|
if (!super.setValid(index2, isValid)) {
|
|
@@ -19398,12 +20732,12 @@ var VariableWidthBuilder = class extends Builder {
|
|
|
19398
20732
|
return super.finish();
|
|
19399
20733
|
}
|
|
19400
20734
|
_flush() {
|
|
19401
|
-
const
|
|
20735
|
+
const pending2 = this._pending;
|
|
19402
20736
|
const pendingLength = this._pendingLength;
|
|
19403
20737
|
this._pendingLength = 0;
|
|
19404
20738
|
this._pending = void 0;
|
|
19405
|
-
if (
|
|
19406
|
-
this._flushPending(
|
|
20739
|
+
if (pending2 && pending2.size > 0) {
|
|
20740
|
+
this._flushPending(pending2, pendingLength);
|
|
19407
20741
|
}
|
|
19408
20742
|
return this;
|
|
19409
20743
|
}
|
|
@@ -21821,11 +23155,11 @@ var BinaryBuilder = class extends VariableWidthBuilder {
|
|
|
21821
23155
|
setValue(index2, value) {
|
|
21822
23156
|
return super.setValue(index2, toUint8Array2(value));
|
|
21823
23157
|
}
|
|
21824
|
-
_flushPending(
|
|
23158
|
+
_flushPending(pending2, pendingLength) {
|
|
21825
23159
|
const offsets = this._offsets;
|
|
21826
23160
|
const data = this._values.reserve(pendingLength).buffer;
|
|
21827
23161
|
let offset = 0;
|
|
21828
|
-
for (const [index2, value] of
|
|
23162
|
+
for (const [index2, value] of pending2) {
|
|
21829
23163
|
if (value === void 0) {
|
|
21830
23164
|
offsets.set(index2, 0);
|
|
21831
23165
|
} else {
|
|
@@ -21854,11 +23188,11 @@ var LargeBinaryBuilder = class extends VariableWidthBuilder {
|
|
|
21854
23188
|
setValue(index2, value) {
|
|
21855
23189
|
return super.setValue(index2, toUint8Array2(value));
|
|
21856
23190
|
}
|
|
21857
|
-
_flushPending(
|
|
23191
|
+
_flushPending(pending2, pendingLength) {
|
|
21858
23192
|
const offsets = this._offsets;
|
|
21859
23193
|
const data = this._values.reserve(pendingLength).buffer;
|
|
21860
23194
|
let offset = 0;
|
|
21861
|
-
for (const [index2, value] of
|
|
23195
|
+
for (const [index2, value] of pending2) {
|
|
21862
23196
|
if (value === void 0) {
|
|
21863
23197
|
offsets.set(index2, BigInt(0));
|
|
21864
23198
|
} else {
|
|
@@ -22089,10 +23423,10 @@ var ListBuilder = class extends VariableWidthBuilder {
|
|
|
22089
23423
|
this.type = new List2(new Field2(name, child.type, true));
|
|
22090
23424
|
return this.numChildren - 1;
|
|
22091
23425
|
}
|
|
22092
|
-
_flushPending(
|
|
23426
|
+
_flushPending(pending2) {
|
|
22093
23427
|
const offsets = this._offsets;
|
|
22094
23428
|
const [child] = this.children;
|
|
22095
|
-
for (const [index2, value] of
|
|
23429
|
+
for (const [index2, value] of pending2) {
|
|
22096
23430
|
if (typeof value === "undefined") {
|
|
22097
23431
|
offsets.set(index2, 0);
|
|
22098
23432
|
} else {
|
|
@@ -22121,10 +23455,10 @@ var LargeListBuilder = class extends VariableWidthBuilder {
|
|
|
22121
23455
|
this.type = new LargeList2(new Field2(name, child.type, true));
|
|
22122
23456
|
return this.numChildren - 1;
|
|
22123
23457
|
}
|
|
22124
|
-
_flushPending(
|
|
23458
|
+
_flushPending(pending2) {
|
|
22125
23459
|
const offsets = this._offsets;
|
|
22126
23460
|
const [child] = this.children;
|
|
22127
|
-
for (const [index2, value] of
|
|
23461
|
+
for (const [index2, value] of pending2) {
|
|
22128
23462
|
if (typeof value === "undefined") {
|
|
22129
23463
|
offsets.set(index2, BigInt(0));
|
|
22130
23464
|
} else {
|
|
@@ -22146,11 +23480,11 @@ var MapBuilder = class extends VariableWidthBuilder {
|
|
|
22146
23480
|
}
|
|
22147
23481
|
setValue(index2, value) {
|
|
22148
23482
|
const row = value instanceof Map ? value : new Map(Object.entries(value));
|
|
22149
|
-
const
|
|
22150
|
-
const current =
|
|
23483
|
+
const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
|
|
23484
|
+
const current = pending2.get(index2);
|
|
22151
23485
|
current && (this._pendingLength -= current.size);
|
|
22152
23486
|
this._pendingLength += row.size;
|
|
22153
|
-
|
|
23487
|
+
pending2.set(index2, row);
|
|
22154
23488
|
}
|
|
22155
23489
|
addChild(child, name = `${this.numChildren}`) {
|
|
22156
23490
|
if (this.numChildren > 0) {
|
|
@@ -22160,10 +23494,10 @@ var MapBuilder = class extends VariableWidthBuilder {
|
|
|
22160
23494
|
this.type = new Map_(new Field2(name, child.type, true), this.type.keysSorted);
|
|
22161
23495
|
return this.numChildren - 1;
|
|
22162
23496
|
}
|
|
22163
|
-
_flushPending(
|
|
23497
|
+
_flushPending(pending2) {
|
|
22164
23498
|
const offsets = this._offsets;
|
|
22165
23499
|
const [child] = this.children;
|
|
22166
|
-
for (const [index2, value] of
|
|
23500
|
+
for (const [index2, value] of pending2) {
|
|
22167
23501
|
if (value === void 0) {
|
|
22168
23502
|
offsets.set(index2, 0);
|
|
22169
23503
|
} else {
|
|
@@ -22326,7 +23660,7 @@ var Utf8Builder = class extends VariableWidthBuilder {
|
|
|
22326
23660
|
return super.setValue(index2, encodeUtf8(value));
|
|
22327
23661
|
}
|
|
22328
23662
|
// @ts-ignore
|
|
22329
|
-
_flushPending(
|
|
23663
|
+
_flushPending(pending2, pendingLength) {
|
|
22330
23664
|
}
|
|
22331
23665
|
};
|
|
22332
23666
|
Utf8Builder.prototype._flushPending = BinaryBuilder.prototype._flushPending;
|
|
@@ -22348,7 +23682,7 @@ var LargeUtf8Builder = class extends VariableWidthBuilder {
|
|
|
22348
23682
|
return super.setValue(index2, encodeUtf8(value));
|
|
22349
23683
|
}
|
|
22350
23684
|
// @ts-ignore
|
|
22351
|
-
_flushPending(
|
|
23685
|
+
_flushPending(pending2, pendingLength) {
|
|
22352
23686
|
}
|
|
22353
23687
|
};
|
|
22354
23688
|
LargeUtf8Builder.prototype._flushPending = LargeBinaryBuilder.prototype._flushPending;
|
|
@@ -27361,7 +28695,7 @@ function getLibraryCacheKey2(type, options) {
|
|
|
27361
28695
|
}
|
|
27362
28696
|
|
|
27363
28697
|
// src/draco/lib/utils/version.ts
|
|
27364
|
-
var VERSION3 = true ? "5.0.0-beta.
|
|
28698
|
+
var VERSION3 = true ? "5.0.0-beta.4" : "latest";
|
|
27365
28699
|
|
|
27366
28700
|
// src/draco/draco-format.ts
|
|
27367
28701
|
var DracoFormat = {
|
|
@@ -27428,7 +28762,7 @@ function encodeDracoInBatches(data, options = {}) {
|
|
|
27428
28762
|
const normalizedData = normalizeDracoInputBatches(data);
|
|
27429
28763
|
if (canEncodeWithWorker(DracoWriterWorker, options)) {
|
|
27430
28764
|
const { onProgress: _onProgress, ...workerOptions } = options;
|
|
27431
|
-
return
|
|
28765
|
+
return processOnWorkerInBatches2(
|
|
27432
28766
|
DracoWriterWorker,
|
|
27433
28767
|
normalizedData,
|
|
27434
28768
|
workerOptions
|
|
@@ -27494,7 +28828,7 @@ function isDracoBuilderMesh(data) {
|
|
|
27494
28828
|
}
|
|
27495
28829
|
|
|
27496
28830
|
// src/draco/workers/draco-writer-worker-node.ts
|
|
27497
|
-
|
|
28831
|
+
createWorker2(
|
|
27498
28832
|
async (input, options) => (await encodeDraco(input, options)).data,
|
|
27499
28833
|
encodeDracoInBatchesLocally
|
|
27500
28834
|
);
|