@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
|
@@ -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.4";
|
|
12
54
|
globalThis._loadersgl_ = globalThis._loadersgl_ || {};
|
|
13
55
|
globalThis._loadersgl_.version ||= version;
|
|
14
56
|
return version;
|
|
@@ -43,11 +85,11 @@
|
|
|
43
85
|
var nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
44
86
|
|
|
45
87
|
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/npm-tag.js
|
|
46
|
-
var
|
|
88
|
+
var NPM_TAG2 = "latest";
|
|
47
89
|
|
|
48
90
|
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/env-utils/version.js
|
|
49
91
|
function getVersion2() {
|
|
50
|
-
return false ?
|
|
92
|
+
return false ? NPM_TAG2 : "5.0.0-beta.4";
|
|
51
93
|
}
|
|
52
94
|
var VERSION2 = getVersion2();
|
|
53
95
|
|
|
@@ -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
255
|
// ../../node_modules/@math.gl/core/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) {
|
|
@@ -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);
|
|
@@ -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) {
|
|
@@ -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
|
}
|
|
@@ -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}`;
|
|
@@ -1469,8 +1537,62 @@
|
|
|
1469
1537
|
return bytes;
|
|
1470
1538
|
}
|
|
1471
1539
|
|
|
1540
|
+
// ../../node_modules/@math.gl/core/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
|
+
|
|
1472
1547
|
// ../../node_modules/@math.gl/core/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);
|
|
@@ -1721,7 +1843,7 @@
|
|
|
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,7 +2039,7 @@
|
|
|
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
|
}
|
|
@@ -1926,6 +2051,1159 @@
|
|
|
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
|
|
|
2054
|
+
// ../../node_modules/@math.gl/core/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));
|
|
2067
|
+
}
|
|
2068
|
+
return withSignal(promise, signal);
|
|
2069
|
+
}
|
|
2070
|
+
function isTaskCodeLoaded(task) {
|
|
2071
|
+
return !task.preload || loaded.has(task);
|
|
2072
|
+
}
|
|
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
|
+
});
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
// ../../node_modules/@math.gl/core/dist/tasks/task-runtime.js
|
|
2095
|
+
function assertPayload(value) {
|
|
2096
|
+
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) {
|
|
2097
|
+
throw new TypeError("Task payloads must be plain objects with named fields");
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
function clonePayload(value, ownership = "copy") {
|
|
2101
|
+
assertPayload(value);
|
|
2102
|
+
if (!["copy", "transfer", "share"].includes(ownership))
|
|
2103
|
+
throw new TypeError("Invalid input ownership");
|
|
2104
|
+
const transfer = getTransferList(value);
|
|
2105
|
+
if (ownership === "share" && transfer.length)
|
|
2106
|
+
throw new TypeError("Share requires shared storage");
|
|
2107
|
+
return structuredClone(value, {
|
|
2108
|
+
transfer: ownership === "transfer" ? transfer : []
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2111
|
+
function taskContext(state, context = {}) {
|
|
2112
|
+
const signal = context.signal ?? new AbortController().signal;
|
|
2113
|
+
return {
|
|
2114
|
+
state,
|
|
2115
|
+
signal,
|
|
2116
|
+
throwIfAborted: () => {
|
|
2117
|
+
signal.throwIfAborted();
|
|
2118
|
+
context.throwIfAborted?.();
|
|
2119
|
+
},
|
|
2120
|
+
reportProgress: (progress) => context.reportProgress?.({
|
|
2121
|
+
...progress,
|
|
2122
|
+
phase: progress.phase ?? "process",
|
|
2123
|
+
unit: progress.unit ?? "items"
|
|
2124
|
+
})
|
|
2125
|
+
};
|
|
2126
|
+
}
|
|
2127
|
+
var TaskRuntime = class {
|
|
2128
|
+
constructor(task) {
|
|
2129
|
+
this.task = task;
|
|
2130
|
+
this.initialized = false;
|
|
2131
|
+
}
|
|
2132
|
+
async initialize(input, context = {}) {
|
|
2133
|
+
if (this.initialized)
|
|
2134
|
+
throw new Error("Task is already initialized");
|
|
2135
|
+
assertPayload(input);
|
|
2136
|
+
await preloadTaskCode(this.task, context.signal);
|
|
2137
|
+
context.signal?.throwIfAborted();
|
|
2138
|
+
this.state = await this.task.initialize?.(input, taskContext(void 0, context));
|
|
2139
|
+
this.initialized = true;
|
|
2140
|
+
return {};
|
|
2141
|
+
}
|
|
2142
|
+
async destroy() {
|
|
2143
|
+
if (this.initialized) {
|
|
2144
|
+
this.initialized = false;
|
|
2145
|
+
const state = this.state;
|
|
2146
|
+
this.state = void 0;
|
|
2147
|
+
if (this.task.initialize)
|
|
2148
|
+
await this.task.destroy?.(state);
|
|
2149
|
+
}
|
|
2150
|
+
return {};
|
|
2151
|
+
}
|
|
2152
|
+
async process(input, options, context = {}) {
|
|
2153
|
+
if (!this.initialized)
|
|
2154
|
+
throw new Error("Task is not initialized");
|
|
2155
|
+
if (!this.task.process)
|
|
2156
|
+
throw new Error("Task has no atomic processor");
|
|
2157
|
+
assertPayload(input);
|
|
2158
|
+
const result = await this.task.process(input, options, taskContext(this.state, context));
|
|
2159
|
+
assertPayload(result);
|
|
2160
|
+
return result;
|
|
2161
|
+
}
|
|
2162
|
+
async *stream(inputs, options, context = {}) {
|
|
2163
|
+
if (!this.initialized)
|
|
2164
|
+
throw new Error("Task is not initialized");
|
|
2165
|
+
if (!this.task.processInBatches)
|
|
2166
|
+
throw new Error("Task has no streaming processor");
|
|
2167
|
+
for await (const output of this.task.processInBatches(inputs, options, taskContext(this.state, context))) {
|
|
2168
|
+
assertPayload(output);
|
|
2169
|
+
yield output;
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
};
|
|
2173
|
+
async function initializeTaskWorker(task) {
|
|
2174
|
+
if (!await WorkerBody.inWorkerThread())
|
|
2175
|
+
throw new Error("initializeTaskWorker must run inside a worker");
|
|
2176
|
+
if (installed)
|
|
2177
|
+
throw new Error("A task is already installed in this worker");
|
|
2178
|
+
installed = true;
|
|
2179
|
+
const runtime = new TaskRuntime(task);
|
|
2180
|
+
let streamOptions = {};
|
|
2181
|
+
return createWorker(async (request, _options, context) => {
|
|
2182
|
+
switch (request.operation) {
|
|
2183
|
+
case "initialize":
|
|
2184
|
+
return runtime.initialize(request.input, context);
|
|
2185
|
+
case "destroy":
|
|
2186
|
+
return runtime.destroy();
|
|
2187
|
+
case "stream-options":
|
|
2188
|
+
streamOptions = request.options;
|
|
2189
|
+
return {};
|
|
2190
|
+
case "process":
|
|
2191
|
+
return runtime.process(request.input, request.options, context);
|
|
2192
|
+
default:
|
|
2193
|
+
throw new Error("Unknown task operation");
|
|
2194
|
+
}
|
|
2195
|
+
}, async function* (inputs, _options, context) {
|
|
2196
|
+
async function* batches() {
|
|
2197
|
+
for await (const input of inputs) {
|
|
2198
|
+
assertPayload(input);
|
|
2199
|
+
yield input;
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
try {
|
|
2203
|
+
yield* runtime.stream(batches(), streamOptions, context);
|
|
2204
|
+
} finally {
|
|
2205
|
+
streamOptions = {};
|
|
2206
|
+
}
|
|
2207
|
+
}, () => preloadTaskCode(task));
|
|
2208
|
+
}
|
|
2209
|
+
var installed = false;
|
|
2210
|
+
function localContext(controls) {
|
|
2211
|
+
return {
|
|
2212
|
+
signal: controls.signal,
|
|
2213
|
+
reportProgress: (progress) => controls.onProgress?.(progress)
|
|
2214
|
+
};
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
// ../../node_modules/@math.gl/core/dist/tasks/task-sync.js
|
|
2218
|
+
function runTaskSync(task, input, request = {}) {
|
|
2219
|
+
if (!isTaskCodeLoaded(task))
|
|
2220
|
+
throw new Error("Preload task on the main thread before runTaskSync");
|
|
2221
|
+
if ("execution" in request)
|
|
2222
|
+
throw new TypeError("runTaskSync always runs on the calling thread");
|
|
2223
|
+
if (!task.process)
|
|
2224
|
+
throw new TypeError("Task has no atomic processor");
|
|
2225
|
+
for (const hook of [task.initialize, task.process, task.destroy]) {
|
|
2226
|
+
if (hook && Object.prototype.toString.call(hook) === "[object AsyncFunction]")
|
|
2227
|
+
throw new TypeError("runTaskSync requires synchronous lifecycle hooks");
|
|
2228
|
+
}
|
|
2229
|
+
if (request.outputOwnership && !["copy", "transfer"].includes(request.outputOwnership))
|
|
2230
|
+
throw new TypeError("Invalid output ownership");
|
|
2231
|
+
const context = taskContext(void 0, localContext(request));
|
|
2232
|
+
context.throwIfAborted();
|
|
2233
|
+
const options = request.options ?? {};
|
|
2234
|
+
if (request.inputOwnership === "transfer") {
|
|
2235
|
+
const metadata = new Set(getTransferList(options));
|
|
2236
|
+
if (getTransferList(input).some((buffer) => metadata.has(buffer)))
|
|
2237
|
+
throw new Error("Transferred input aliases reusable options; use inputOwnership: copy");
|
|
2238
|
+
}
|
|
2239
|
+
const copiedOptions = clonePayload(options);
|
|
2240
|
+
const initialization = clonePayload(request.initialization ?? {}, request.initializationOwnership);
|
|
2241
|
+
let initialized = false;
|
|
2242
|
+
let failure;
|
|
2243
|
+
let failed = false;
|
|
2244
|
+
let output;
|
|
2245
|
+
try {
|
|
2246
|
+
const state = task.initialize?.(initialization, context);
|
|
2247
|
+
if (isThenable(state)) {
|
|
2248
|
+
void Promise.resolve(state).then((value) => task.destroy?.(value)).catch(() => {
|
|
2249
|
+
});
|
|
2250
|
+
throw new TypeError("runTaskSync initialize returned a promise");
|
|
2251
|
+
}
|
|
2252
|
+
context.state = state;
|
|
2253
|
+
initialized = true;
|
|
2254
|
+
context.throwIfAborted();
|
|
2255
|
+
const copiedInput = clonePayload(input, request.inputOwnership);
|
|
2256
|
+
const result = task.process(copiedInput, copiedOptions, context);
|
|
2257
|
+
if (isThenable(result)) {
|
|
2258
|
+
initialized = false;
|
|
2259
|
+
void Promise.resolve(result).catch(() => {
|
|
2260
|
+
}).then(() => {
|
|
2261
|
+
if (task.initialize)
|
|
2262
|
+
return task.destroy?.(context.state);
|
|
2263
|
+
}).catch(() => {
|
|
2264
|
+
});
|
|
2265
|
+
throw new TypeError("runTaskSync process returned a promise");
|
|
2266
|
+
}
|
|
2267
|
+
assertPayload(result);
|
|
2268
|
+
context.throwIfAborted();
|
|
2269
|
+
output = clonePayload(result, request.outputOwnership ?? "transfer");
|
|
2270
|
+
} catch (error) {
|
|
2271
|
+
failed = true;
|
|
2272
|
+
failure = error;
|
|
2273
|
+
} finally {
|
|
2274
|
+
if (initialized && task.initialize) {
|
|
2275
|
+
try {
|
|
2276
|
+
const cleanup = task.destroy?.(context.state);
|
|
2277
|
+
if (isThenable(cleanup)) {
|
|
2278
|
+
void Promise.resolve(cleanup).catch(() => {
|
|
2279
|
+
});
|
|
2280
|
+
throw new TypeError("runTaskSync destroy returned a promise");
|
|
2281
|
+
}
|
|
2282
|
+
} catch (error) {
|
|
2283
|
+
if (failed)
|
|
2284
|
+
throw new AggregateError([failure, error], "Task processing and destruction failed");
|
|
2285
|
+
throw error;
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
if (failed)
|
|
2290
|
+
throw failure;
|
|
2291
|
+
return output;
|
|
2292
|
+
}
|
|
2293
|
+
function isThenable(value) {
|
|
2294
|
+
return Boolean(value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function");
|
|
2295
|
+
}
|
|
2296
|
+
|
|
2297
|
+
// ../../node_modules/@math.gl/core/dist/tasks/task-runner.js
|
|
2298
|
+
var InitializedTask = class {
|
|
2299
|
+
/** @internal Use TaskRunner.initializeTask. */
|
|
2300
|
+
constructor(task, release, controls) {
|
|
2301
|
+
this.task = task;
|
|
2302
|
+
this.release = release;
|
|
2303
|
+
this.tail = Promise.resolve();
|
|
2304
|
+
this.closed = false;
|
|
2305
|
+
this.streams = /* @__PURE__ */ new Set();
|
|
2306
|
+
this.invalid = false;
|
|
2307
|
+
this.controller = new AbortController();
|
|
2308
|
+
this.runtime = new TaskRuntime(task);
|
|
2309
|
+
const execution = controls.execution ?? "auto";
|
|
2310
|
+
if (!["auto", "main-thread", "worker"].includes(execution))
|
|
2311
|
+
throw new TypeError("Invalid execution mode");
|
|
2312
|
+
if (execution === "worker" && !task.worker)
|
|
2313
|
+
throw new Error("Task has no worker");
|
|
2314
|
+
if (execution !== "main-thread" && task.worker) {
|
|
2315
|
+
const target = task.worker;
|
|
2316
|
+
if (Boolean(target.url) === Boolean(target.create))
|
|
2317
|
+
throw new Error("Supply exactly one worker URL or factory");
|
|
2318
|
+
this.pool = new WorkerPool({
|
|
2319
|
+
name: task.id,
|
|
2320
|
+
url: target.url?.toString(),
|
|
2321
|
+
loadWorker: target.create,
|
|
2322
|
+
workerType: "module",
|
|
2323
|
+
maxConcurrency: 1,
|
|
2324
|
+
maxMobileConcurrency: 1
|
|
2325
|
+
});
|
|
2326
|
+
this.descriptor = {
|
|
2327
|
+
id: task.id,
|
|
2328
|
+
name: task.id,
|
|
2329
|
+
module: "core",
|
|
2330
|
+
version: "prototype",
|
|
2331
|
+
options: {},
|
|
2332
|
+
worker: target.url?.toString() ?? true,
|
|
2333
|
+
loadWorker: target.create,
|
|
2334
|
+
workerInBatches: target.capabilities.streaming
|
|
2335
|
+
};
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
/** @internal */
|
|
2339
|
+
async initialize(input, controls) {
|
|
2340
|
+
try {
|
|
2341
|
+
assertPayload(input);
|
|
2342
|
+
await this.enqueue(() => this.invoke("initialize", input, {}, controls));
|
|
2343
|
+
} catch (error) {
|
|
2344
|
+
await this.terminate(error);
|
|
2345
|
+
throw error;
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
runTask(input, ...args) {
|
|
2349
|
+
return this.enqueue(async () => {
|
|
2350
|
+
this.checkCapability("atomic");
|
|
2351
|
+
return this.invoke("process", input, args[0]?.options ?? {}, args[0]);
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
/** Independent calls sharing this instance, always serial and in input order. */
|
|
2355
|
+
async *runTasks(inputs, ...args) {
|
|
2356
|
+
yield* this.serialStream(async function* (self2) {
|
|
2357
|
+
self2.checkCapability("atomic");
|
|
2358
|
+
for await (const input of asAsync(inputs, self2.controls(args[0]).signal)) {
|
|
2359
|
+
yield await self2.invoke("process", input, args[0]?.options ?? {}, args[0]);
|
|
2360
|
+
}
|
|
2361
|
+
});
|
|
2362
|
+
}
|
|
2363
|
+
/** One processor invocation for the entire input iterable. */
|
|
2364
|
+
async *runTaskInBatches(inputs, ...args) {
|
|
2365
|
+
yield* this.serialStream(async function* (self2) {
|
|
2366
|
+
self2.checkCapability("streaming");
|
|
2367
|
+
const controls = self2.controls(args[0]);
|
|
2368
|
+
const options = clonePayload(args[0]?.options ?? {});
|
|
2369
|
+
async function* prepared() {
|
|
2370
|
+
for await (const input of asAsync(inputs, controls.signal)) {
|
|
2371
|
+
controls.signal?.throwIfAborted();
|
|
2372
|
+
assertNoTransferAlias(input, args[0]?.options ?? {}, controls.inputOwnership);
|
|
2373
|
+
yield clonePayload(input, controls.inputOwnership);
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
let completed = false;
|
|
2377
|
+
try {
|
|
2378
|
+
if (self2.pool) {
|
|
2379
|
+
await self2.invoke("stream-options", {}, options, controls);
|
|
2380
|
+
yield* processOnWorkerInBatches(self2.descriptor, prepared(), {
|
|
2381
|
+
...self2.workerOptions(controls),
|
|
2382
|
+
inputOwnership: "transfer",
|
|
2383
|
+
workerInBatches: true
|
|
2384
|
+
});
|
|
2385
|
+
} else {
|
|
2386
|
+
for await (const output of self2.runtime.stream(prepared(), options, localContext(controls))) {
|
|
2387
|
+
controls.signal?.throwIfAborted();
|
|
2388
|
+
yield clonePayload(output, controls.outputOwnership ?? "transfer");
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
completed = true;
|
|
2392
|
+
} catch (error) {
|
|
2393
|
+
if (self2.pool) {
|
|
2394
|
+
self2.invalid = true;
|
|
2395
|
+
await self2.pool.destroy(error);
|
|
2396
|
+
}
|
|
2397
|
+
throw error;
|
|
2398
|
+
} finally {
|
|
2399
|
+
if (self2.pool && !completed)
|
|
2400
|
+
self2.invalid = true;
|
|
2401
|
+
}
|
|
2402
|
+
});
|
|
2403
|
+
}
|
|
2404
|
+
/** Drain accepted work, invoke destroy, and release execution capacity. */
|
|
2405
|
+
close() {
|
|
2406
|
+
if (!this.closing) {
|
|
2407
|
+
this.closed = true;
|
|
2408
|
+
this.closing = (async () => {
|
|
2409
|
+
try {
|
|
2410
|
+
await this.tail;
|
|
2411
|
+
if (!this.invalid)
|
|
2412
|
+
await this.invoke("destroy", {}, {});
|
|
2413
|
+
} finally {
|
|
2414
|
+
try {
|
|
2415
|
+
await this.pool?.destroy();
|
|
2416
|
+
} finally {
|
|
2417
|
+
this.release();
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
})();
|
|
2421
|
+
}
|
|
2422
|
+
return this.closing;
|
|
2423
|
+
}
|
|
2424
|
+
/** Abort work. Local JavaScript must settle before its state can be destroyed. */
|
|
2425
|
+
async terminate(reason = new Error("Task terminated")) {
|
|
2426
|
+
this.controller.abort(reason);
|
|
2427
|
+
if (this.pool) {
|
|
2428
|
+
this.invalid = true;
|
|
2429
|
+
await this.pool.destroy(reason);
|
|
2430
|
+
}
|
|
2431
|
+
await Promise.allSettled([...this.streams].map((stop) => stop()));
|
|
2432
|
+
await this.close();
|
|
2433
|
+
}
|
|
2434
|
+
checkCapability(kind) {
|
|
2435
|
+
if (this.pool ? !this.task.worker?.capabilities[kind] : !(kind === "atomic" ? this.task.process : this.task.processInBatches)) {
|
|
2436
|
+
throw new Error(`Task has no ${kind} processor for this execution route`);
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
controls(controls = {}) {
|
|
2440
|
+
if (controls.outputOwnership && !["copy", "transfer"].includes(controls.outputOwnership))
|
|
2441
|
+
throw new TypeError("Invalid output ownership");
|
|
2442
|
+
return {
|
|
2443
|
+
...controls,
|
|
2444
|
+
signal: controls.signal ? AbortSignal.any([controls.signal, this.controller.signal]) : this.controller.signal
|
|
2445
|
+
};
|
|
2446
|
+
}
|
|
2447
|
+
workerOptions(controls) {
|
|
2448
|
+
return {
|
|
2449
|
+
workerPool: this.pool,
|
|
2450
|
+
workerType: "module",
|
|
2451
|
+
inputOwnership: controls.inputOwnership ?? "copy",
|
|
2452
|
+
outputOwnership: controls.outputOwnership ?? "transfer",
|
|
2453
|
+
signal: controls.signal,
|
|
2454
|
+
onProgress: controls.onProgress,
|
|
2455
|
+
cancellationMode: "terminate"
|
|
2456
|
+
};
|
|
2457
|
+
}
|
|
2458
|
+
async invoke(operation, input, options, controls = {}) {
|
|
2459
|
+
if (this.invalid)
|
|
2460
|
+
throw new Error("Initialized task is invalid; initialize a new instance");
|
|
2461
|
+
const prepared = operation === "destroy" ? {} : this.controls(controls);
|
|
2462
|
+
prepared.signal?.throwIfAborted();
|
|
2463
|
+
assertPayload(input);
|
|
2464
|
+
assertNoTransferAlias(input, options, prepared.inputOwnership);
|
|
2465
|
+
const copiedOptions = clonePayload(options);
|
|
2466
|
+
if (this.pool) {
|
|
2467
|
+
try {
|
|
2468
|
+
return await processOnWorker(this.descriptor, { operation, input: clonePayload(input, prepared.inputOwnership), options: copiedOptions }, this.workerOptions({ ...prepared, inputOwnership: "transfer" }));
|
|
2469
|
+
} catch (error) {
|
|
2470
|
+
this.invalid = true;
|
|
2471
|
+
await this.pool.destroy(error);
|
|
2472
|
+
throw error;
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
if (operation === "destroy")
|
|
2476
|
+
return this.runtime.destroy();
|
|
2477
|
+
const copied = clonePayload(input, prepared.inputOwnership);
|
|
2478
|
+
const context = localContext(prepared);
|
|
2479
|
+
if (operation === "initialize") {
|
|
2480
|
+
const result2 = await this.runtime.initialize(copied, context);
|
|
2481
|
+
prepared.signal?.throwIfAborted();
|
|
2482
|
+
return result2;
|
|
2483
|
+
}
|
|
2484
|
+
const result = await this.runtime.process(copied, copiedOptions, context);
|
|
2485
|
+
prepared.signal?.throwIfAborted();
|
|
2486
|
+
return clonePayload(result, prepared.outputOwnership ?? "transfer");
|
|
2487
|
+
}
|
|
2488
|
+
enqueue(operation) {
|
|
2489
|
+
if (this.closed)
|
|
2490
|
+
return Promise.reject(new Error("Initialized task is closed"));
|
|
2491
|
+
const result = this.tail.then(operation);
|
|
2492
|
+
this.tail = result.catch(() => {
|
|
2493
|
+
});
|
|
2494
|
+
return result;
|
|
2495
|
+
}
|
|
2496
|
+
async *serialStream(operation) {
|
|
2497
|
+
if (this.closed)
|
|
2498
|
+
throw new Error("Initialized task is closed");
|
|
2499
|
+
const before = this.tail;
|
|
2500
|
+
let release;
|
|
2501
|
+
this.tail = new Promise((resolve) => {
|
|
2502
|
+
release = resolve;
|
|
2503
|
+
});
|
|
2504
|
+
await before;
|
|
2505
|
+
if (this.controller.signal.aborted) {
|
|
2506
|
+
release();
|
|
2507
|
+
throw this.controller.signal.reason;
|
|
2508
|
+
}
|
|
2509
|
+
const iterator = operation(this)[Symbol.asyncIterator]();
|
|
2510
|
+
let stopping;
|
|
2511
|
+
const stop = () => {
|
|
2512
|
+
stopping ?? (stopping = (async () => {
|
|
2513
|
+
try {
|
|
2514
|
+
await iterator.return?.();
|
|
2515
|
+
} finally {
|
|
2516
|
+
this.streams.delete(stop);
|
|
2517
|
+
release();
|
|
2518
|
+
}
|
|
2519
|
+
})());
|
|
2520
|
+
return stopping;
|
|
2521
|
+
};
|
|
2522
|
+
this.streams.add(stop);
|
|
2523
|
+
try {
|
|
2524
|
+
while (true) {
|
|
2525
|
+
this.controller.signal.throwIfAborted();
|
|
2526
|
+
const next = await iterator.next();
|
|
2527
|
+
if (next.done)
|
|
2528
|
+
return;
|
|
2529
|
+
yield next.value;
|
|
2530
|
+
}
|
|
2531
|
+
} finally {
|
|
2532
|
+
await stop();
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
};
|
|
2536
|
+
var TaskRunner = class {
|
|
2537
|
+
constructor(options = {}) {
|
|
2538
|
+
this.active = /* @__PURE__ */ new Set();
|
|
2539
|
+
this.count = 0;
|
|
2540
|
+
this.waiters = [];
|
|
2541
|
+
this.closed = false;
|
|
2542
|
+
this.initializing = /* @__PURE__ */ new Set();
|
|
2543
|
+
this.iterations = /* @__PURE__ */ new Set();
|
|
2544
|
+
this.maxConcurrency = options.maxConcurrency ?? 1;
|
|
2545
|
+
if (!Number.isSafeInteger(this.maxConcurrency) || this.maxConcurrency < 1)
|
|
2546
|
+
throw new RangeError("maxConcurrency must be a positive safe integer");
|
|
2547
|
+
}
|
|
2548
|
+
/** Execute synchronous hooks immediately on the calling thread, without queueing. */
|
|
2549
|
+
runTaskSync(task, input, ...args) {
|
|
2550
|
+
if (this.closed)
|
|
2551
|
+
throw new Error("Task runner is closed");
|
|
2552
|
+
if (this.count >= this.maxConcurrency)
|
|
2553
|
+
throw new Error("Task runner has no synchronous capacity");
|
|
2554
|
+
this.count++;
|
|
2555
|
+
try {
|
|
2556
|
+
return runTaskSync(task, input, args[0]);
|
|
2557
|
+
} finally {
|
|
2558
|
+
const waiter = this.waiters.shift();
|
|
2559
|
+
if (waiter)
|
|
2560
|
+
waiter.resolve();
|
|
2561
|
+
else
|
|
2562
|
+
this.count--;
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
initializeTask(task, initialization, controls = {}) {
|
|
2566
|
+
const pending2 = this.open(task, initialization, controls);
|
|
2567
|
+
this.initializing.add(pending2);
|
|
2568
|
+
void pending2.then(() => this.initializing.delete(pending2), () => this.initializing.delete(pending2));
|
|
2569
|
+
return pending2;
|
|
2570
|
+
}
|
|
2571
|
+
async runTask(task, input, ...args) {
|
|
2572
|
+
const request = args[0] ?? {};
|
|
2573
|
+
const handle = await this.initializeTask(task, request.initialization ?? {}, {
|
|
2574
|
+
...request,
|
|
2575
|
+
inputOwnership: request.initializationOwnership ?? "copy"
|
|
2576
|
+
});
|
|
2577
|
+
return finish(handle, () => handle.runTask(input, request));
|
|
2578
|
+
}
|
|
2579
|
+
async *runTasks(task, inputs, ...args) {
|
|
2580
|
+
const request = args[0] ?? {};
|
|
2581
|
+
if (this.closed)
|
|
2582
|
+
throw new Error("Task runner is closed");
|
|
2583
|
+
if (request.initializationOwnership === "transfer")
|
|
2584
|
+
throw new TypeError("runTasks initialization is a reusable template; use copy or share");
|
|
2585
|
+
const concurrency = request.concurrency ?? 1;
|
|
2586
|
+
if (!Number.isSafeInteger(concurrency) || concurrency < 1 || concurrency > this.maxConcurrency)
|
|
2587
|
+
throw new RangeError("concurrency must be between 1 and maxConcurrency");
|
|
2588
|
+
const handles = [];
|
|
2589
|
+
const busy = /* @__PURE__ */ new Set();
|
|
2590
|
+
const pending2 = [];
|
|
2591
|
+
const controller = new AbortController();
|
|
2592
|
+
this.iterations.add(controller);
|
|
2593
|
+
const signal = request.signal ? AbortSignal.any([request.signal, controller.signal]) : controller.signal;
|
|
2594
|
+
const iterator = asAsync(inputs, signal)[Symbol.asyncIterator]();
|
|
2595
|
+
let finished = false;
|
|
2596
|
+
let reading;
|
|
2597
|
+
try {
|
|
2598
|
+
while (!finished || pending2.length) {
|
|
2599
|
+
signal.throwIfAborted();
|
|
2600
|
+
if (!finished && !reading && pending2.length < concurrency) {
|
|
2601
|
+
reading = iterator.next().then((next) => ({ kind: "input", next }));
|
|
2602
|
+
}
|
|
2603
|
+
const event = await Promise.race([
|
|
2604
|
+
...pending2.length ? [pending2[0]] : [],
|
|
2605
|
+
...reading ? [reading] : []
|
|
2606
|
+
]);
|
|
2607
|
+
if (event.kind === "result") {
|
|
2608
|
+
pending2.shift();
|
|
2609
|
+
busy.delete(event.handle);
|
|
2610
|
+
if (event.failed)
|
|
2611
|
+
throw event.error;
|
|
2612
|
+
yield event.value;
|
|
2613
|
+
continue;
|
|
2614
|
+
}
|
|
2615
|
+
reading = void 0;
|
|
2616
|
+
if (event.next.done) {
|
|
2617
|
+
finished = true;
|
|
2618
|
+
continue;
|
|
2619
|
+
}
|
|
2620
|
+
let handle = handles.find((candidate) => !busy.has(candidate));
|
|
2621
|
+
if (!handle && (handles.length === 0 || this.count < this.maxConcurrency)) {
|
|
2622
|
+
handle = await this.initializeTask(task, clonePayload(request.initialization ?? {}, request.initializationOwnership), {
|
|
2623
|
+
...request,
|
|
2624
|
+
signal,
|
|
2625
|
+
inputOwnership: request.initializationOwnership ?? "copy"
|
|
2626
|
+
});
|
|
2627
|
+
handles.push(handle);
|
|
2628
|
+
}
|
|
2629
|
+
if (!handle) {
|
|
2630
|
+
const result = await pending2.shift();
|
|
2631
|
+
busy.delete(result.handle);
|
|
2632
|
+
if (result.failed)
|
|
2633
|
+
throw result.error;
|
|
2634
|
+
yield result.value;
|
|
2635
|
+
handle = result.handle;
|
|
2636
|
+
}
|
|
2637
|
+
busy.add(handle);
|
|
2638
|
+
const current = handle;
|
|
2639
|
+
pending2.push(handle.runTask(event.next.value, { ...request, signal }).then((value) => ({ kind: "result", handle: current, value }), (error) => ({ kind: "result", handle: current, failed: true, error })));
|
|
2640
|
+
}
|
|
2641
|
+
} finally {
|
|
2642
|
+
this.iterations.delete(controller);
|
|
2643
|
+
controller.abort(new Error("Task iteration closed"));
|
|
2644
|
+
try {
|
|
2645
|
+
if (reading)
|
|
2646
|
+
await reading.catch(() => {
|
|
2647
|
+
});
|
|
2648
|
+
if (!finished)
|
|
2649
|
+
await iterator.return?.();
|
|
2650
|
+
} finally {
|
|
2651
|
+
await Promise.all(pending2);
|
|
2652
|
+
await Promise.all(handles.map((handle) => handle.close()));
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
async *runTaskInBatches(task, inputs, ...args) {
|
|
2657
|
+
const request = args[0] ?? {};
|
|
2658
|
+
const handle = await this.initializeTask(task, request.initialization ?? {}, {
|
|
2659
|
+
...request,
|
|
2660
|
+
inputOwnership: request.initializationOwnership ?? "copy"
|
|
2661
|
+
});
|
|
2662
|
+
try {
|
|
2663
|
+
yield* handle.runTaskInBatches(inputs, request);
|
|
2664
|
+
} finally {
|
|
2665
|
+
await handle.close();
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
/** Close owned handles and workers. Finish or return active iterators first. */
|
|
2669
|
+
close() {
|
|
2670
|
+
if (!this.closing) {
|
|
2671
|
+
this.closed = true;
|
|
2672
|
+
for (const waiter of this.waiters.splice(0))
|
|
2673
|
+
waiter.reject(new Error("Task runner is closed"));
|
|
2674
|
+
this.closing = (async () => {
|
|
2675
|
+
await Promise.allSettled(this.initializing);
|
|
2676
|
+
const results = await Promise.allSettled([...this.active].map((handle) => handle.close()));
|
|
2677
|
+
const failure = results.find((result) => result.status === "rejected");
|
|
2678
|
+
if (failure?.status === "rejected")
|
|
2679
|
+
throw failure.reason;
|
|
2680
|
+
})();
|
|
2681
|
+
}
|
|
2682
|
+
return this.closing;
|
|
2683
|
+
}
|
|
2684
|
+
async terminate(reason = new Error("Task runner terminated")) {
|
|
2685
|
+
for (const controller of this.iterations)
|
|
2686
|
+
controller.abort(reason);
|
|
2687
|
+
const closing = this.close();
|
|
2688
|
+
await Promise.allSettled([...this.active].map((handle) => handle.terminate(reason)));
|
|
2689
|
+
await closing;
|
|
2690
|
+
}
|
|
2691
|
+
async open(task, initialization, controls) {
|
|
2692
|
+
if (this.closed)
|
|
2693
|
+
throw new Error("Task runner is closed");
|
|
2694
|
+
controls.signal?.throwIfAborted();
|
|
2695
|
+
if (this.count >= this.maxConcurrency) {
|
|
2696
|
+
await new Promise((resolve, reject) => {
|
|
2697
|
+
const waiter = {
|
|
2698
|
+
resolve: () => {
|
|
2699
|
+
cleanup();
|
|
2700
|
+
resolve();
|
|
2701
|
+
},
|
|
2702
|
+
reject: (error) => {
|
|
2703
|
+
cleanup();
|
|
2704
|
+
reject(error);
|
|
2705
|
+
}
|
|
2706
|
+
};
|
|
2707
|
+
const abort = () => {
|
|
2708
|
+
this.waiters = this.waiters.filter((item) => item !== waiter);
|
|
2709
|
+
waiter.reject(controls.signal?.reason);
|
|
2710
|
+
};
|
|
2711
|
+
const cleanup = () => controls.signal?.removeEventListener("abort", abort);
|
|
2712
|
+
this.waiters.push(waiter);
|
|
2713
|
+
controls.signal?.addEventListener("abort", abort, { once: true });
|
|
2714
|
+
if (controls.signal?.aborted)
|
|
2715
|
+
abort();
|
|
2716
|
+
});
|
|
2717
|
+
} else
|
|
2718
|
+
this.count++;
|
|
2719
|
+
let handle;
|
|
2720
|
+
let released = false;
|
|
2721
|
+
const release = () => {
|
|
2722
|
+
if (released)
|
|
2723
|
+
return;
|
|
2724
|
+
released = true;
|
|
2725
|
+
if (handle)
|
|
2726
|
+
this.active.delete(handle);
|
|
2727
|
+
const waiter = this.waiters.shift();
|
|
2728
|
+
if (waiter)
|
|
2729
|
+
waiter.resolve();
|
|
2730
|
+
else
|
|
2731
|
+
this.count--;
|
|
2732
|
+
};
|
|
2733
|
+
try {
|
|
2734
|
+
if (this.closed)
|
|
2735
|
+
throw new Error("Task runner is closed");
|
|
2736
|
+
handle = new InitializedTask(task, release, controls);
|
|
2737
|
+
this.active.add(handle);
|
|
2738
|
+
await handle.initialize(initialization, controls);
|
|
2739
|
+
return handle;
|
|
2740
|
+
} catch (error) {
|
|
2741
|
+
release();
|
|
2742
|
+
throw error;
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
};
|
|
2746
|
+
async function finish(handle, operation) {
|
|
2747
|
+
let result;
|
|
2748
|
+
try {
|
|
2749
|
+
result = await operation();
|
|
2750
|
+
} catch (error) {
|
|
2751
|
+
try {
|
|
2752
|
+
await handle.close();
|
|
2753
|
+
} catch (cleanup) {
|
|
2754
|
+
throw new AggregateError([error, cleanup], "Task processing and destruction failed");
|
|
2755
|
+
}
|
|
2756
|
+
throw error;
|
|
2757
|
+
}
|
|
2758
|
+
await handle.close();
|
|
2759
|
+
return result;
|
|
2760
|
+
}
|
|
2761
|
+
async function* asAsync(inputs, signal) {
|
|
2762
|
+
const iterator = Symbol.asyncIterator in inputs ? inputs[Symbol.asyncIterator]() : inputs[Symbol.iterator]();
|
|
2763
|
+
let done = false;
|
|
2764
|
+
let blocked = false;
|
|
2765
|
+
try {
|
|
2766
|
+
while (true) {
|
|
2767
|
+
const next = await new Promise((resolve, reject) => {
|
|
2768
|
+
const cleanup = () => signal?.removeEventListener("abort", abort);
|
|
2769
|
+
const abort = () => {
|
|
2770
|
+
cleanup();
|
|
2771
|
+
reject(signal?.reason);
|
|
2772
|
+
};
|
|
2773
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
2774
|
+
if (signal?.aborted) {
|
|
2775
|
+
abort();
|
|
2776
|
+
return;
|
|
2777
|
+
}
|
|
2778
|
+
try {
|
|
2779
|
+
blocked = true;
|
|
2780
|
+
Promise.resolve(iterator.next()).then((value) => {
|
|
2781
|
+
blocked = false;
|
|
2782
|
+
cleanup();
|
|
2783
|
+
resolve(value);
|
|
2784
|
+
}, (error) => {
|
|
2785
|
+
blocked = false;
|
|
2786
|
+
cleanup();
|
|
2787
|
+
reject(error);
|
|
2788
|
+
});
|
|
2789
|
+
} catch (error) {
|
|
2790
|
+
blocked = false;
|
|
2791
|
+
cleanup();
|
|
2792
|
+
reject(error);
|
|
2793
|
+
}
|
|
2794
|
+
});
|
|
2795
|
+
if (next.done) {
|
|
2796
|
+
done = true;
|
|
2797
|
+
return;
|
|
2798
|
+
}
|
|
2799
|
+
yield next.value;
|
|
2800
|
+
}
|
|
2801
|
+
} finally {
|
|
2802
|
+
if (!done) {
|
|
2803
|
+
if (blocked) {
|
|
2804
|
+
try {
|
|
2805
|
+
void Promise.resolve(iterator.return?.()).catch(() => {
|
|
2806
|
+
});
|
|
2807
|
+
} catch {
|
|
2808
|
+
}
|
|
2809
|
+
} else {
|
|
2810
|
+
await iterator.return?.();
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2815
|
+
function assertNoTransferAlias(input, options, ownership) {
|
|
2816
|
+
if (ownership === "transfer") {
|
|
2817
|
+
const metadata = new Set(getTransferList(options));
|
|
2818
|
+
if (getTransferList(input).some((buffer) => metadata.has(buffer))) {
|
|
2819
|
+
throw new Error("Transferred input aliases reusable options; use inputOwnership: copy");
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
|
|
2824
|
+
// ../core/src/worker-utils/lib/worker-api/task-runtime.ts
|
|
2825
|
+
function normalizeTaskProgress(progress) {
|
|
2826
|
+
return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
|
|
2827
|
+
}
|
|
2828
|
+
async function isWorkerThread() {
|
|
2829
|
+
if (typeof self !== "undefined" && typeof document === "undefined" && typeof self.postMessage === "function")
|
|
2830
|
+
return true;
|
|
2831
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
2832
|
+
const { isMainThread } = await Promise.resolve().then(() => (init_worker_threads_browser(), worker_threads_browser_exports));
|
|
2833
|
+
return !isMainThread;
|
|
2834
|
+
}
|
|
2835
|
+
return false;
|
|
2836
|
+
}
|
|
2837
|
+
var initializeTaskWorker2 = initializeTaskWorker;
|
|
2838
|
+
|
|
2839
|
+
// ../core/src/worker-utils/lib/worker-api/get-worker-url.ts
|
|
2840
|
+
var warnedWorkerVersionFallbacks2 = /* @__PURE__ */ new Set();
|
|
2841
|
+
function getCustomWorkerURL2(worker, options = {}) {
|
|
2842
|
+
const workerFile = isBrowser ? worker.workerFile || `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
|
|
2843
|
+
let url = getConfiguredWorkerURL2(worker, options);
|
|
2844
|
+
const workerType = options._workerType || options?.core?._workerType;
|
|
2845
|
+
if (!url && workerType === "test") {
|
|
2846
|
+
if (isBrowser) {
|
|
2847
|
+
url = `modules/${worker.module}/dist/${workerFile}`;
|
|
2848
|
+
} else {
|
|
2849
|
+
const workerSourceDirectory = worker.module === "core" && worker.workerNode?.startsWith("worker-utils/") ? "worker-utils/workers" : "workers";
|
|
2850
|
+
const workerSourceNode = worker.workerSourceNode || `${workerSourceDirectory}/${worker.id}-worker-node.ts`;
|
|
2851
|
+
url = `modules/${worker.module}/src/${workerSourceNode}`;
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
return url || null;
|
|
2855
|
+
}
|
|
2856
|
+
function getConfiguredWorkerURL2(worker, options = {}) {
|
|
2857
|
+
const workerOptions = options[worker.id] || {};
|
|
2858
|
+
return workerOptions.workerUrl || (worker.id === "compression" ? options.workerUrl : null) || null;
|
|
2859
|
+
}
|
|
2860
|
+
function getWorkerURL2(worker, options = {}) {
|
|
2861
|
+
const customWorkerUrl = getCustomWorkerURL2(worker, options);
|
|
2862
|
+
const descriptorWorkerUrl = typeof worker.worker === "string" ? worker.worker : null;
|
|
2863
|
+
const url = customWorkerUrl || descriptorWorkerUrl || getDefaultWorkerURL2(worker, true);
|
|
2864
|
+
assert(url);
|
|
2865
|
+
return url;
|
|
2866
|
+
}
|
|
2867
|
+
function getDefaultWorkerURL2(worker, warn = false) {
|
|
2868
|
+
const workerFile = isBrowser ? worker.workerFile || `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
|
|
2869
|
+
let version = worker.version;
|
|
2870
|
+
if (version === "latest") {
|
|
2871
|
+
version = NPM_TAG;
|
|
2872
|
+
}
|
|
2873
|
+
const versionTag = version ? `@${version}` : "";
|
|
2874
|
+
const url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;
|
|
2875
|
+
if (warn) {
|
|
2876
|
+
warnIfUsingNpmTagFallback2(worker, url);
|
|
2877
|
+
}
|
|
2878
|
+
return url;
|
|
2879
|
+
}
|
|
2880
|
+
function warnIfUsingNpmTagFallback2(worker, url) {
|
|
2881
|
+
if (worker.version !== "latest") {
|
|
2882
|
+
return;
|
|
2883
|
+
}
|
|
2884
|
+
const workerId = `${worker.module}:${worker.id}`;
|
|
2885
|
+
if (warnedWorkerVersionFallbacks2.has(workerId)) {
|
|
2886
|
+
return;
|
|
2887
|
+
}
|
|
2888
|
+
warnedWorkerVersionFallbacks2.add(workerId);
|
|
2889
|
+
console.warn(
|
|
2890
|
+
`loaders.gl: ${worker.name} loader worker version is "latest" because __VERSION__ was not injected. Fetching ${url} from CDN.`
|
|
2891
|
+
);
|
|
2892
|
+
}
|
|
2893
|
+
|
|
2894
|
+
// ../core/src/worker-utils/lib/worker-utils/get-transfer-list.ts
|
|
2895
|
+
function getTransferList2(object, recursive = true, transfers) {
|
|
2896
|
+
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
2897
|
+
if (!object) {
|
|
2898
|
+
} else if (isTransferable2(object)) {
|
|
2899
|
+
transfersSet.add(object);
|
|
2900
|
+
} else if (isTransferable2(object.buffer)) {
|
|
2901
|
+
transfersSet.add(object.buffer);
|
|
2902
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
2903
|
+
} else if (recursive && typeof object === "object") {
|
|
2904
|
+
for (const key in object) {
|
|
2905
|
+
getTransferList2(object[key], recursive, transfersSet);
|
|
2906
|
+
}
|
|
2907
|
+
}
|
|
2908
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
2909
|
+
}
|
|
2910
|
+
function isTransferable2(object) {
|
|
2911
|
+
if (!object) {
|
|
2912
|
+
return false;
|
|
2913
|
+
}
|
|
2914
|
+
if (object instanceof ArrayBuffer) {
|
|
2915
|
+
return true;
|
|
2916
|
+
}
|
|
2917
|
+
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
2918
|
+
return true;
|
|
2919
|
+
}
|
|
2920
|
+
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
2921
|
+
return true;
|
|
2922
|
+
}
|
|
2923
|
+
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
2924
|
+
return true;
|
|
2925
|
+
}
|
|
2926
|
+
return false;
|
|
2927
|
+
}
|
|
2928
|
+
function getTransferListForWriter2(object) {
|
|
2929
|
+
if (object === null) {
|
|
2930
|
+
return {};
|
|
2931
|
+
}
|
|
2932
|
+
const clone = Object.assign({}, object);
|
|
2933
|
+
Object.keys(clone).forEach((key) => {
|
|
2934
|
+
if (object[key] !== null && typeof object[key] === "object" && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) {
|
|
2935
|
+
clone[key] = getTransferListForWriter2(object[key]);
|
|
2936
|
+
} else if (typeof clone[key] === "function" || clone[key] instanceof RegExp) {
|
|
2937
|
+
clone[key] = {};
|
|
2938
|
+
} else {
|
|
2939
|
+
clone[key] = object[key];
|
|
2940
|
+
}
|
|
2941
|
+
});
|
|
2942
|
+
return clone;
|
|
2943
|
+
}
|
|
2944
|
+
|
|
2945
|
+
// ../core/src/worker-utils/lib/worker-api/process-on-worker.ts
|
|
2946
|
+
var runners = /* @__PURE__ */ new WeakMap();
|
|
2947
|
+
var activeRunners = /* @__PURE__ */ new Set();
|
|
2948
|
+
var moduleWorkerUrls = /* @__PURE__ */ new Map();
|
|
2949
|
+
function canProcessOnWorker2(worker, options = {}) {
|
|
2950
|
+
const supported = isBrowser ? typeof Worker !== "undefined" : Boolean(options._nodeWorkers);
|
|
2951
|
+
return Boolean(
|
|
2952
|
+
supported && options.worker && (worker.worker || worker.loadWorker || getConfiguredWorkerURL2(worker, options))
|
|
2953
|
+
);
|
|
2954
|
+
}
|
|
2955
|
+
async function* processOnWorkerInBatches2(worker, input, options = {}, context = {}, jobContext = {}) {
|
|
2956
|
+
const taskInput = wrapInput(input);
|
|
2957
|
+
let session;
|
|
2958
|
+
try {
|
|
2959
|
+
session = await openSession(worker, options, context, jobContext);
|
|
2960
|
+
for await (const result of session.handle.runTaskInBatches(taskInput, {
|
|
2961
|
+
...getControls(options),
|
|
2962
|
+
options: getParserOptions(options)
|
|
2963
|
+
}))
|
|
2964
|
+
yield result.value;
|
|
2965
|
+
} finally {
|
|
2966
|
+
const closingInput = taskInput.return?.();
|
|
2967
|
+
void closingInput?.catch(() => {
|
|
2968
|
+
});
|
|
2969
|
+
await session?.close();
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
function getTask(worker, options) {
|
|
2973
|
+
if (options.source || options.core?.source)
|
|
2974
|
+
throw new Error(
|
|
2975
|
+
"Inline legacy worker source is unsupported; use a TaskRunner worker URL or factory"
|
|
2976
|
+
);
|
|
2977
|
+
const create = !getCustomWorkerURL2(worker, options) && isBrowser ? worker.loadWorker : void 0;
|
|
2978
|
+
const url = getWorkerURL2(worker, options);
|
|
2979
|
+
return {
|
|
2980
|
+
id: `${worker.module}:${worker.id}`,
|
|
2981
|
+
initialize: (state) => state,
|
|
2982
|
+
worker: {
|
|
2983
|
+
...create ? { create: () => create() ?? createModuleWorker(url) } : { url },
|
|
2984
|
+
capabilities: { atomic: true, streaming: true }
|
|
2985
|
+
}
|
|
2986
|
+
};
|
|
2987
|
+
}
|
|
2988
|
+
function getControls(options) {
|
|
2989
|
+
return {
|
|
2990
|
+
execution: "worker",
|
|
2991
|
+
signal: options.signal,
|
|
2992
|
+
inputOwnership: options.inputOwnership ?? "transfer",
|
|
2993
|
+
outputOwnership: options.outputOwnership ?? "transfer",
|
|
2994
|
+
onProgress: options.onProgress ? (progress) => options.onProgress?.(normalizeTaskProgress(progress)) : void 0
|
|
2995
|
+
};
|
|
2996
|
+
}
|
|
2997
|
+
function getParserOptions(options) {
|
|
2998
|
+
const { signal, onProgress, ...parserOptions } = options;
|
|
2999
|
+
return getTransferListForWriter2(parserOptions);
|
|
3000
|
+
}
|
|
3001
|
+
async function openSession(worker, options, context, jobContext) {
|
|
3002
|
+
options.signal?.throwIfAborted();
|
|
3003
|
+
const task = getTask(worker, options);
|
|
3004
|
+
let state = runners.get(worker);
|
|
3005
|
+
if (!state) {
|
|
3006
|
+
state = {
|
|
3007
|
+
runner: new TaskRunner({
|
|
3008
|
+
maxConcurrency: isMobile ? options.maxMobileConcurrency ?? 1 : options.maxConcurrency ?? 3
|
|
3009
|
+
}),
|
|
3010
|
+
requests: 0
|
|
3011
|
+
};
|
|
3012
|
+
runners.set(worker, state);
|
|
3013
|
+
}
|
|
3014
|
+
const runnerState = state;
|
|
3015
|
+
const channel = context.process ? new MessageChannel() : void 0;
|
|
3016
|
+
const callbackController = new AbortController();
|
|
3017
|
+
let channelClosed = false;
|
|
3018
|
+
const abortCallbacks = () => callbackController.abort(options.signal?.reason);
|
|
3019
|
+
options.signal?.addEventListener("abort", abortCallbacks, { once: true });
|
|
3020
|
+
const closeChannel = () => {
|
|
3021
|
+
channelClosed = true;
|
|
3022
|
+
options.signal?.removeEventListener("abort", abortCallbacks);
|
|
3023
|
+
callbackController.abort();
|
|
3024
|
+
channel?.port1.close();
|
|
3025
|
+
channel?.port2.close();
|
|
3026
|
+
};
|
|
3027
|
+
if (channel) {
|
|
3028
|
+
channel.port1.onmessage = async ({ data }) => {
|
|
3029
|
+
try {
|
|
3030
|
+
const value = await context.process(
|
|
3031
|
+
data.input,
|
|
3032
|
+
data.options,
|
|
3033
|
+
{
|
|
3034
|
+
signal: callbackController.signal,
|
|
3035
|
+
throwIfAborted: () => callbackController.signal.throwIfAborted()
|
|
3036
|
+
},
|
|
3037
|
+
data.context
|
|
3038
|
+
);
|
|
3039
|
+
if (!channelClosed && !callbackController.signal.aborted)
|
|
3040
|
+
channel.port1.postMessage({ identifier: data.identifier, value }, getTransferList2(value));
|
|
3041
|
+
} catch (error) {
|
|
3042
|
+
if (channelClosed || callbackController.signal.aborted) return;
|
|
3043
|
+
channel.port1.postMessage({
|
|
3044
|
+
identifier: data.identifier,
|
|
3045
|
+
error: {
|
|
3046
|
+
name: error instanceof Error ? error.name : "Error",
|
|
3047
|
+
message: error instanceof Error ? error.message : String(error)
|
|
3048
|
+
}
|
|
3049
|
+
});
|
|
3050
|
+
}
|
|
3051
|
+
};
|
|
3052
|
+
channel.port1.start();
|
|
3053
|
+
}
|
|
3054
|
+
runnerState.requests++;
|
|
3055
|
+
activeRunners.add(runnerState);
|
|
3056
|
+
let released = false;
|
|
3057
|
+
const releaseRunner = () => {
|
|
3058
|
+
if (released) return;
|
|
3059
|
+
released = true;
|
|
3060
|
+
runnerState.requests--;
|
|
3061
|
+
if (!runnerState.requests) activeRunners.delete(runnerState);
|
|
3062
|
+
};
|
|
3063
|
+
let handle;
|
|
3064
|
+
try {
|
|
3065
|
+
handle = await runnerState.runner.initializeTask(
|
|
3066
|
+
task,
|
|
3067
|
+
{
|
|
3068
|
+
context: structuredClone(jobContext),
|
|
3069
|
+
...channel ? { port: channel.port2 } : {}
|
|
3070
|
+
},
|
|
3071
|
+
// The callback port is setup state, independent of the caller's payload ownership.
|
|
3072
|
+
{ ...getControls(options), inputOwnership: "transfer" }
|
|
3073
|
+
);
|
|
3074
|
+
} catch (error) {
|
|
3075
|
+
releaseRunner();
|
|
3076
|
+
closeChannel();
|
|
3077
|
+
throw error;
|
|
3078
|
+
}
|
|
3079
|
+
return {
|
|
3080
|
+
handle,
|
|
3081
|
+
/** Releases the worker and callback channel on success, failure, and early stream return. */
|
|
3082
|
+
async close() {
|
|
3083
|
+
try {
|
|
3084
|
+
await handle.close();
|
|
3085
|
+
} finally {
|
|
3086
|
+
closeChannel();
|
|
3087
|
+
releaseRunner();
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
};
|
|
3091
|
+
}
|
|
3092
|
+
function wrapInput(input) {
|
|
3093
|
+
const iterator = Symbol.asyncIterator in input ? input[Symbol.asyncIterator]() : input[Symbol.iterator]();
|
|
3094
|
+
let inputClosed = false;
|
|
3095
|
+
return {
|
|
3096
|
+
[Symbol.asyncIterator]() {
|
|
3097
|
+
return this;
|
|
3098
|
+
},
|
|
3099
|
+
async next() {
|
|
3100
|
+
if (inputClosed) return { done: true, value: void 0 };
|
|
3101
|
+
const next = await iterator.next();
|
|
3102
|
+
if (next.done || inputClosed) {
|
|
3103
|
+
inputClosed = true;
|
|
3104
|
+
return { done: true, value: void 0 };
|
|
3105
|
+
}
|
|
3106
|
+
return { done: false, value: { value: next.value } };
|
|
3107
|
+
},
|
|
3108
|
+
async return() {
|
|
3109
|
+
if (!inputClosed) {
|
|
3110
|
+
inputClosed = true;
|
|
3111
|
+
await iterator.return?.();
|
|
3112
|
+
}
|
|
3113
|
+
return { done: true, value: void 0 };
|
|
3114
|
+
}
|
|
3115
|
+
};
|
|
3116
|
+
}
|
|
3117
|
+
function createModuleWorker(url) {
|
|
3118
|
+
const resolved = new URL(url, globalThis.document?.baseURI ?? globalThis.location.href);
|
|
3119
|
+
let workerUrl = resolved.href;
|
|
3120
|
+
if (/^https?:$/.test(resolved.protocol) && resolved.origin !== globalThis.location.origin) {
|
|
3121
|
+
let shimUrl = moduleWorkerUrls.get(resolved.href);
|
|
3122
|
+
if (!shimUrl) {
|
|
3123
|
+
shimUrl = URL.createObjectURL(
|
|
3124
|
+
new Blob([`import ${JSON.stringify(resolved.href)};`], { type: "application/javascript" })
|
|
3125
|
+
);
|
|
3126
|
+
moduleWorkerUrls.set(resolved.href, shimUrl);
|
|
3127
|
+
}
|
|
3128
|
+
workerUrl = shimUrl;
|
|
3129
|
+
}
|
|
3130
|
+
return new Worker(workerUrl, { type: "module" });
|
|
3131
|
+
}
|
|
3132
|
+
|
|
3133
|
+
// ../core/src/worker-utils/lib/worker-api/create-worker.ts
|
|
3134
|
+
async function createWorker2(process2, processInBatches) {
|
|
3135
|
+
if (!await isWorkerThread()) return;
|
|
3136
|
+
await initializeTaskWorker2(createWorkerTask(process2, processInBatches));
|
|
3137
|
+
}
|
|
3138
|
+
function createWorkerTask(process2, processInBatches) {
|
|
3139
|
+
return {
|
|
3140
|
+
id: "loaders.gl",
|
|
3141
|
+
initialize: (state) => state,
|
|
3142
|
+
destroy: (state) => state.port?.close(),
|
|
3143
|
+
process: async ({ value }, options, context) => {
|
|
3144
|
+
if (!process2) throw new Error("Worker does not support atomic processing");
|
|
3145
|
+
return { value: await process2(value, options, createContext(context), context.state.context) };
|
|
3146
|
+
},
|
|
3147
|
+
...processInBatches ? {
|
|
3148
|
+
processInBatches: async function* (inputs, options, context) {
|
|
3149
|
+
async function* values() {
|
|
3150
|
+
for await (const input of inputs) yield input.value;
|
|
3151
|
+
}
|
|
3152
|
+
for await (const value of processInBatches(
|
|
3153
|
+
values(),
|
|
3154
|
+
options,
|
|
3155
|
+
createContext(context),
|
|
3156
|
+
context.state.context
|
|
3157
|
+
)) {
|
|
3158
|
+
yield { value };
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
} : {}
|
|
3162
|
+
};
|
|
3163
|
+
}
|
|
3164
|
+
function createContext(context) {
|
|
3165
|
+
let requestIdentifier = 0;
|
|
3166
|
+
const port = context.state.port;
|
|
3167
|
+
return {
|
|
3168
|
+
signal: context.signal,
|
|
3169
|
+
throwIfAborted: () => context.throwIfAborted(),
|
|
3170
|
+
reportProgress: (progress) => context.reportProgress(normalizeTaskProgress(progress)),
|
|
3171
|
+
process: port ? (input, options = {}, jobContext = {}) => {
|
|
3172
|
+
context.throwIfAborted();
|
|
3173
|
+
const identifier = ++requestIdentifier;
|
|
3174
|
+
return new Promise((resolve, reject) => {
|
|
3175
|
+
const onMessage2 = (event) => {
|
|
3176
|
+
if (event.data.identifier !== identifier) return;
|
|
3177
|
+
cleanup();
|
|
3178
|
+
if (event.data.error) {
|
|
3179
|
+
const error = new Error(event.data.error.message);
|
|
3180
|
+
error.name = event.data.error.name;
|
|
3181
|
+
reject(error);
|
|
3182
|
+
} else resolve(event.data.value);
|
|
3183
|
+
};
|
|
3184
|
+
const onAbort = () => {
|
|
3185
|
+
cleanup();
|
|
3186
|
+
reject(context.signal.reason);
|
|
3187
|
+
};
|
|
3188
|
+
const cleanup = () => {
|
|
3189
|
+
port.removeEventListener("message", onMessage2);
|
|
3190
|
+
context.signal.removeEventListener("abort", onAbort);
|
|
3191
|
+
};
|
|
3192
|
+
port.addEventListener("message", onMessage2);
|
|
3193
|
+
context.signal.addEventListener("abort", onAbort, { once: true });
|
|
3194
|
+
port.start();
|
|
3195
|
+
try {
|
|
3196
|
+
const request = { identifier, input, options, context: jobContext };
|
|
3197
|
+
port.postMessage(request, getTransferList2(request));
|
|
3198
|
+
} catch (error) {
|
|
3199
|
+
cleanup();
|
|
3200
|
+
reject(error);
|
|
3201
|
+
}
|
|
3202
|
+
});
|
|
3203
|
+
} : void 0
|
|
3204
|
+
};
|
|
3205
|
+
}
|
|
3206
|
+
|
|
1929
3207
|
// ../core/src/worker-utils/lib/library-utils/library-utils.ts
|
|
1930
3208
|
var loadLibraryPromises = {};
|
|
1931
3209
|
function extractLoadLibraryOptions(options = {}) {
|
|
@@ -2128,15 +3406,15 @@
|
|
|
2128
3406
|
|
|
2129
3407
|
// ../core/src/loader-utils/lib/worker-loader-utils/encode-with-worker.ts
|
|
2130
3408
|
function canEncodeWithWorker(writer, options) {
|
|
2131
|
-
if (!WorkerFarm.isSupported()) {
|
|
2132
|
-
return false;
|
|
2133
|
-
}
|
|
2134
3409
|
const nodeWorkers = options?._nodeWorkers ?? options?.core?._nodeWorkers;
|
|
2135
3410
|
const useWorkers = options?.worker ?? options?.core?.worker;
|
|
2136
3411
|
if (!isBrowser3 && !nodeWorkers) {
|
|
2137
3412
|
return false;
|
|
2138
3413
|
}
|
|
2139
|
-
return
|
|
3414
|
+
return canProcessOnWorker2(
|
|
3415
|
+
{ ...writer, options: writer.options || {} },
|
|
3416
|
+
{ worker: Boolean(useWorkers), _nodeWorkers: Boolean(nodeWorkers) }
|
|
3417
|
+
);
|
|
2140
3418
|
}
|
|
2141
3419
|
|
|
2142
3420
|
// ../../node_modules/@math.gl/core/dist/types/float16.js
|
|
@@ -9497,11 +10775,11 @@ return true;`);
|
|
|
9497
10775
|
this._offsets = new OffsetsBufferBuilder(opts.type);
|
|
9498
10776
|
}
|
|
9499
10777
|
setValue(index, value) {
|
|
9500
|
-
const
|
|
9501
|
-
const current =
|
|
10778
|
+
const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
|
|
10779
|
+
const current = pending2.get(index);
|
|
9502
10780
|
current && (this._pendingLength -= current.length);
|
|
9503
10781
|
this._pendingLength += value instanceof MapRow ? value[kKeys].length : value.length;
|
|
9504
|
-
|
|
10782
|
+
pending2.set(index, value);
|
|
9505
10783
|
}
|
|
9506
10784
|
setValid(index, isValid) {
|
|
9507
10785
|
if (!super.setValid(index, isValid)) {
|
|
@@ -9524,12 +10802,12 @@ return true;`);
|
|
|
9524
10802
|
return super.finish();
|
|
9525
10803
|
}
|
|
9526
10804
|
_flush() {
|
|
9527
|
-
const
|
|
10805
|
+
const pending2 = this._pending;
|
|
9528
10806
|
const pendingLength = this._pendingLength;
|
|
9529
10807
|
this._pendingLength = 0;
|
|
9530
10808
|
this._pending = void 0;
|
|
9531
|
-
if (
|
|
9532
|
-
this._flushPending(
|
|
10809
|
+
if (pending2 && pending2.size > 0) {
|
|
10810
|
+
this._flushPending(pending2, pendingLength);
|
|
9533
10811
|
}
|
|
9534
10812
|
return this;
|
|
9535
10813
|
}
|
|
@@ -11939,11 +13217,11 @@ return true;`);
|
|
|
11939
13217
|
setValue(index, value) {
|
|
11940
13218
|
return super.setValue(index, toUint8Array(value));
|
|
11941
13219
|
}
|
|
11942
|
-
_flushPending(
|
|
13220
|
+
_flushPending(pending2, pendingLength) {
|
|
11943
13221
|
const offsets = this._offsets;
|
|
11944
13222
|
const data = this._values.reserve(pendingLength).buffer;
|
|
11945
13223
|
let offset = 0;
|
|
11946
|
-
for (const [index, value] of
|
|
13224
|
+
for (const [index, value] of pending2) {
|
|
11947
13225
|
if (value === void 0) {
|
|
11948
13226
|
offsets.set(index, 0);
|
|
11949
13227
|
} else {
|
|
@@ -11972,11 +13250,11 @@ return true;`);
|
|
|
11972
13250
|
setValue(index, value) {
|
|
11973
13251
|
return super.setValue(index, toUint8Array(value));
|
|
11974
13252
|
}
|
|
11975
|
-
_flushPending(
|
|
13253
|
+
_flushPending(pending2, pendingLength) {
|
|
11976
13254
|
const offsets = this._offsets;
|
|
11977
13255
|
const data = this._values.reserve(pendingLength).buffer;
|
|
11978
13256
|
let offset = 0;
|
|
11979
|
-
for (const [index, value] of
|
|
13257
|
+
for (const [index, value] of pending2) {
|
|
11980
13258
|
if (value === void 0) {
|
|
11981
13259
|
offsets.set(index, BigInt(0));
|
|
11982
13260
|
} else {
|
|
@@ -12207,10 +13485,10 @@ return true;`);
|
|
|
12207
13485
|
this.type = new List2(new Field2(name, child.type, true));
|
|
12208
13486
|
return this.numChildren - 1;
|
|
12209
13487
|
}
|
|
12210
|
-
_flushPending(
|
|
13488
|
+
_flushPending(pending2) {
|
|
12211
13489
|
const offsets = this._offsets;
|
|
12212
13490
|
const [child] = this.children;
|
|
12213
|
-
for (const [index, value] of
|
|
13491
|
+
for (const [index, value] of pending2) {
|
|
12214
13492
|
if (typeof value === "undefined") {
|
|
12215
13493
|
offsets.set(index, 0);
|
|
12216
13494
|
} else {
|
|
@@ -12239,10 +13517,10 @@ return true;`);
|
|
|
12239
13517
|
this.type = new LargeList2(new Field2(name, child.type, true));
|
|
12240
13518
|
return this.numChildren - 1;
|
|
12241
13519
|
}
|
|
12242
|
-
_flushPending(
|
|
13520
|
+
_flushPending(pending2) {
|
|
12243
13521
|
const offsets = this._offsets;
|
|
12244
13522
|
const [child] = this.children;
|
|
12245
|
-
for (const [index, value] of
|
|
13523
|
+
for (const [index, value] of pending2) {
|
|
12246
13524
|
if (typeof value === "undefined") {
|
|
12247
13525
|
offsets.set(index, BigInt(0));
|
|
12248
13526
|
} else {
|
|
@@ -12264,11 +13542,11 @@ return true;`);
|
|
|
12264
13542
|
}
|
|
12265
13543
|
setValue(index, value) {
|
|
12266
13544
|
const row = value instanceof Map ? value : new Map(Object.entries(value));
|
|
12267
|
-
const
|
|
12268
|
-
const current =
|
|
13545
|
+
const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
|
|
13546
|
+
const current = pending2.get(index);
|
|
12269
13547
|
current && (this._pendingLength -= current.size);
|
|
12270
13548
|
this._pendingLength += row.size;
|
|
12271
|
-
|
|
13549
|
+
pending2.set(index, row);
|
|
12272
13550
|
}
|
|
12273
13551
|
addChild(child, name = `${this.numChildren}`) {
|
|
12274
13552
|
if (this.numChildren > 0) {
|
|
@@ -12278,10 +13556,10 @@ return true;`);
|
|
|
12278
13556
|
this.type = new Map_(new Field2(name, child.type, true), this.type.keysSorted);
|
|
12279
13557
|
return this.numChildren - 1;
|
|
12280
13558
|
}
|
|
12281
|
-
_flushPending(
|
|
13559
|
+
_flushPending(pending2) {
|
|
12282
13560
|
const offsets = this._offsets;
|
|
12283
13561
|
const [child] = this.children;
|
|
12284
|
-
for (const [index, value] of
|
|
13562
|
+
for (const [index, value] of pending2) {
|
|
12285
13563
|
if (value === void 0) {
|
|
12286
13564
|
offsets.set(index, 0);
|
|
12287
13565
|
} else {
|
|
@@ -12444,7 +13722,7 @@ return true;`);
|
|
|
12444
13722
|
return super.setValue(index, encodeUtf8(value));
|
|
12445
13723
|
}
|
|
12446
13724
|
// @ts-ignore
|
|
12447
|
-
_flushPending(
|
|
13725
|
+
_flushPending(pending2, pendingLength) {
|
|
12448
13726
|
}
|
|
12449
13727
|
};
|
|
12450
13728
|
Utf8Builder.prototype._flushPending = BinaryBuilder.prototype._flushPending;
|
|
@@ -12466,7 +13744,7 @@ return true;`);
|
|
|
12466
13744
|
return super.setValue(index, encodeUtf8(value));
|
|
12467
13745
|
}
|
|
12468
13746
|
// @ts-ignore
|
|
12469
|
-
_flushPending(
|
|
13747
|
+
_flushPending(pending2, pendingLength) {
|
|
12470
13748
|
}
|
|
12471
13749
|
};
|
|
12472
13750
|
LargeUtf8Builder.prototype._flushPending = LargeBinaryBuilder.prototype._flushPending;
|
|
@@ -17198,7 +18476,7 @@ return true;`);
|
|
|
17198
18476
|
}
|
|
17199
18477
|
|
|
17200
18478
|
// src/draco/lib/utils/version.ts
|
|
17201
|
-
var VERSION3 = true ? "5.0.0-beta.
|
|
18479
|
+
var VERSION3 = true ? "5.0.0-beta.4" : "latest";
|
|
17202
18480
|
|
|
17203
18481
|
// src/draco/draco-format.ts
|
|
17204
18482
|
var DracoFormat = {
|
|
@@ -17265,7 +18543,7 @@ return true;`);
|
|
|
17265
18543
|
const normalizedData = normalizeDracoInputBatches(data);
|
|
17266
18544
|
if (canEncodeWithWorker(DracoWriterWorker, options)) {
|
|
17267
18545
|
const { onProgress: _onProgress, ...workerOptions } = options;
|
|
17268
|
-
return
|
|
18546
|
+
return processOnWorkerInBatches2(
|
|
17269
18547
|
DracoWriterWorker,
|
|
17270
18548
|
normalizedData,
|
|
17271
18549
|
workerOptions
|
|
@@ -17331,7 +18609,7 @@ return true;`);
|
|
|
17331
18609
|
}
|
|
17332
18610
|
|
|
17333
18611
|
// src/draco/workers/draco-writer-worker.ts
|
|
17334
|
-
|
|
18612
|
+
createWorker2(
|
|
17335
18613
|
async (input, options) => (await encodeDraco(input, options)).data,
|
|
17336
18614
|
encodeDracoInBatchesLocally
|
|
17337
18615
|
);
|