@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.
Files changed (151) hide show
  1. package/dist/dist.dev.js +3393 -407
  2. package/dist/dist.min.js +24 -16
  3. package/dist/draco/lib/utils/version.cjs +1 -1
  4. package/dist/draco/lib/utils/version.js +1 -1
  5. package/dist/draco-worker-node.js +415 -54
  6. package/dist/draco-worker-node.js.map +4 -4
  7. package/dist/draco-worker.js +390 -54
  8. package/dist/draco-worker.js.map +4 -4
  9. package/dist/draco-writer-worker-node.cjs +1401 -67
  10. package/dist/draco-writer-worker-node.cjs.map +4 -4
  11. package/dist/draco-writer-worker.js +1345 -67
  12. package/dist/draco-writer-worker.js.map +4 -4
  13. package/dist/gltf/gltf-loader-types.cjs.map +2 -2
  14. package/dist/gltf/gltf-loader-types.d.ts +6 -0
  15. package/dist/gltf/gltf-loader-types.d.ts.map +1 -1
  16. package/dist/gltf/gltf-loader-types.js.map +1 -1
  17. package/dist/gltf/index.cjs +2 -0
  18. package/dist/gltf/index.cjs.map +2 -2
  19. package/dist/gltf/index.d.ts +2 -2
  20. package/dist/gltf/index.d.ts.map +1 -1
  21. package/dist/gltf/index.js +1 -1
  22. package/dist/gltf/index.js.map +1 -1
  23. package/dist/gltf/lib/api/gltf-extensions.cjs +7 -2
  24. package/dist/gltf/lib/api/gltf-extensions.cjs.map +2 -2
  25. package/dist/gltf/lib/api/gltf-extensions.d.ts.map +1 -1
  26. package/dist/gltf/lib/api/gltf-extensions.js +7 -5
  27. package/dist/gltf/lib/api/gltf-extensions.js.map +1 -1
  28. package/dist/gltf/lib/extensions/EXT_texture_webp.cjs +1 -0
  29. package/dist/gltf/lib/extensions/EXT_texture_webp.cjs.map +2 -2
  30. package/dist/gltf/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
  31. package/dist/gltf/lib/extensions/EXT_texture_webp.js +3 -0
  32. package/dist/gltf/lib/extensions/EXT_texture_webp.js.map +1 -1
  33. package/dist/gltf/lib/extensions/KHR_accessor_float64.cjs +45 -0
  34. package/dist/gltf/lib/extensions/KHR_accessor_float64.cjs.map +7 -0
  35. package/dist/gltf/lib/extensions/KHR_accessor_float64.d.ts +6 -0
  36. package/dist/gltf/lib/extensions/KHR_accessor_float64.d.ts.map +1 -0
  37. package/dist/gltf/lib/extensions/KHR_accessor_float64.js +20 -0
  38. package/dist/gltf/lib/extensions/KHR_accessor_float64.js.map +1 -0
  39. package/dist/gltf/lib/extensions/KHR_gaussian_splatting.cjs +12 -3
  40. package/dist/gltf/lib/extensions/KHR_gaussian_splatting.cjs.map +2 -2
  41. package/dist/gltf/lib/extensions/KHR_gaussian_splatting.d.ts +2 -1
  42. package/dist/gltf/lib/extensions/KHR_gaussian_splatting.d.ts.map +1 -1
  43. package/dist/gltf/lib/extensions/KHR_gaussian_splatting.js +9 -3
  44. package/dist/gltf/lib/extensions/KHR_gaussian_splatting.js.map +1 -1
  45. package/dist/gltf/lib/extensions/MSFT_texture_dds.cjs +64 -0
  46. package/dist/gltf/lib/extensions/MSFT_texture_dds.cjs.map +7 -0
  47. package/dist/gltf/lib/extensions/MSFT_texture_dds.d.ts +12 -0
  48. package/dist/gltf/lib/extensions/MSFT_texture_dds.d.ts.map +1 -0
  49. package/dist/gltf/lib/extensions/MSFT_texture_dds.js +39 -0
  50. package/dist/gltf/lib/extensions/MSFT_texture_dds.js.map +1 -0
  51. package/dist/gltf/lib/extensions/utils/3d-tiles-utils.cjs +1 -1
  52. package/dist/gltf/lib/extensions/utils/3d-tiles-utils.cjs.map +2 -2
  53. package/dist/gltf/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -1
  54. package/dist/gltf/lib/extensions/utils/3d-tiles-utils.js +3 -1
  55. package/dist/gltf/lib/extensions/utils/3d-tiles-utils.js.map +1 -1
  56. package/dist/gltf/lib/parsers/parse-gltf.cjs +25 -0
  57. package/dist/gltf/lib/parsers/parse-gltf.cjs.map +2 -2
  58. package/dist/gltf/lib/parsers/parse-gltf.d.ts.map +1 -1
  59. package/dist/gltf/lib/parsers/parse-gltf.js +18 -0
  60. package/dist/gltf/lib/parsers/parse-gltf.js.map +1 -1
  61. package/dist/gltf/lib/types/gltf-ext-gaussian-splatting-schema.cjs.map +1 -1
  62. package/dist/gltf/lib/types/gltf-ext-gaussian-splatting-schema.d.ts +1 -1
  63. package/dist/gltf/lib/types/gltf-ext-gaussian-splatting-schema.d.ts.map +1 -1
  64. package/dist/gltf/lib/types/gltf-texture-procedurals.cjs +19 -0
  65. package/dist/gltf/lib/types/gltf-texture-procedurals.cjs.map +7 -0
  66. package/dist/gltf/lib/types/gltf-texture-procedurals.d.ts +45 -0
  67. package/dist/gltf/lib/types/gltf-texture-procedurals.d.ts.map +1 -0
  68. package/dist/gltf/lib/types/gltf-texture-procedurals.js +5 -0
  69. package/dist/gltf/lib/types/gltf-texture-procedurals.js.map +1 -0
  70. package/dist/gltf/lib/types/gltf-types.cjs.map +1 -1
  71. package/dist/gltf/lib/types/gltf-types.d.ts +7 -0
  72. package/dist/gltf/lib/types/gltf-types.d.ts.map +1 -1
  73. package/dist/gltf/lib/types/gltf-zod-schema.cjs +3 -0
  74. package/dist/gltf/lib/types/gltf-zod-schema.cjs.map +2 -2
  75. package/dist/gltf/lib/types/gltf-zod-schema.d.ts +5 -0
  76. package/dist/gltf/lib/types/gltf-zod-schema.d.ts.map +1 -1
  77. package/dist/gltf/lib/types/gltf-zod-schema.js +4 -0
  78. package/dist/gltf/lib/types/gltf-zod-schema.js.map +1 -1
  79. package/dist/gltf/lib/utils/version.cjs +1 -1
  80. package/dist/gltf/lib/utils/version.js +1 -1
  81. package/dist/gltf/schema.cjs +3 -0
  82. package/dist/gltf/schema.cjs.map +2 -2
  83. package/dist/gltf/schema.d.ts +1 -0
  84. package/dist/gltf/schema.d.ts.map +1 -1
  85. package/dist/gltf/schema.js +1 -0
  86. package/dist/gltf/schema.js.map +1 -1
  87. package/dist/gltf-loader-types.cjs.map +2 -2
  88. package/dist/index.cjs +3 -0
  89. package/dist/index.cjs.map +2 -2
  90. package/dist/index.d.ts +2 -0
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +1 -0
  93. package/dist/index.js.map +1 -1
  94. package/dist/materialx/parse-materialx.cjs +61 -0
  95. package/dist/materialx/parse-materialx.cjs.map +7 -0
  96. package/dist/materialx/parse-materialx.d.ts +23 -0
  97. package/dist/materialx/parse-materialx.d.ts.map +1 -0
  98. package/dist/materialx/parse-materialx.js +39 -0
  99. package/dist/materialx/parse-materialx.js.map +1 -0
  100. package/dist/materialx/procedural-graph.cjs +77 -0
  101. package/dist/materialx/procedural-graph.cjs.map +7 -0
  102. package/dist/materialx/procedural-graph.d.ts +40 -0
  103. package/dist/materialx/procedural-graph.d.ts.map +1 -0
  104. package/dist/materialx/procedural-graph.js +59 -0
  105. package/dist/materialx/procedural-graph.js.map +1 -0
  106. package/dist/materialx-loader-types.cjs +57 -0
  107. package/dist/materialx-loader-types.cjs.map +7 -0
  108. package/dist/materialx-loader-types.d.ts +34 -0
  109. package/dist/materialx-loader-types.d.ts.map +1 -0
  110. package/dist/materialx-loader-types.js +20 -0
  111. package/dist/materialx-loader-types.js.map +1 -0
  112. package/dist/materialx-loader.cjs +40 -0
  113. package/dist/materialx-loader.cjs.map +7 -0
  114. package/dist/materialx-loader.d.ts +19 -0
  115. package/dist/materialx-loader.d.ts.map +1 -0
  116. package/dist/materialx-loader.js +14 -0
  117. package/dist/materialx-loader.js.map +1 -0
  118. package/dist/mtl-loader-types.cjs +1 -1
  119. package/dist/obj/mtl-loader-types.cjs +1 -1
  120. package/dist/obj/mtl-loader-types.js +1 -1
  121. package/dist/obj/obj-loader-types.cjs +1 -1
  122. package/dist/obj/obj-loader-types.js +1 -1
  123. package/dist/obj/obj-writer.cjs +1 -1
  124. package/dist/obj/obj-writer.js +1 -1
  125. package/dist/obj-loader-types.cjs +1 -1
  126. package/dist/obj-worker.js +393 -57
  127. package/dist/obj-writer.cjs +1 -1
  128. package/dist/usd/usd-loader-types.cjs +1 -1
  129. package/dist/usd/usd-loader-types.js +1 -1
  130. package/dist/usd-loader-types.cjs +1 -1
  131. package/package.json +11 -5
  132. package/src/gltf/gltf-loader-types.ts +6 -0
  133. package/src/gltf/index.ts +4 -1
  134. package/src/gltf/lib/api/gltf-extensions.ts +7 -2
  135. package/src/gltf/lib/extensions/EXT_texture_webp.ts +3 -0
  136. package/src/gltf/lib/extensions/KHR_accessor_float64.ts +22 -0
  137. package/src/gltf/lib/extensions/KHR_gaussian_splatting.ts +17 -3
  138. package/src/gltf/lib/extensions/MSFT_texture_dds.ts +52 -0
  139. package/src/gltf/lib/extensions/utils/3d-tiles-utils.ts +5 -1
  140. package/src/gltf/lib/parsers/parse-gltf.ts +29 -0
  141. package/src/gltf/lib/types/gltf-ext-gaussian-splatting-schema.ts +1 -1
  142. package/src/gltf/lib/types/gltf-texture-procedurals.ts +67 -0
  143. package/src/gltf/lib/types/gltf-types.ts +8 -0
  144. package/src/gltf/lib/types/gltf-zod-schema.ts +5 -0
  145. package/src/gltf/schema.ts +1 -0
  146. package/src/index.ts +3 -0
  147. package/src/materialx/README.md +5 -0
  148. package/src/materialx/parse-materialx.ts +70 -0
  149. package/src/materialx/procedural-graph.ts +94 -0
  150. package/src/materialx-loader-types.ts +24 -0
  151. package/src/materialx-loader.ts +15 -0
@@ -52,7 +52,7 @@
52
52
 
53
53
  // ../core/src/worker-utils/lib/env-utils/version.ts
54
54
  function getVersion() {
55
- const version = false ? NPM_TAG : "5.0.0-beta.2";
55
+ const version = false ? NPM_TAG : "5.0.0-beta.4";
56
56
  globalThis._loadersgl_ = globalThis._loadersgl_ || {};
57
57
  globalThis._loadersgl_.version ||= version;
58
58
  return version;
@@ -105,7 +105,7 @@
105
105
  var parentPort;
106
106
  var init_worker_threads_browser = __esm({
107
107
  "../../node_modules/@math.gl/core/dist/worker-utils/lib/node/worker_threads-browser.js"() {
108
- parentPort = null;
108
+ parentPort = globalThis.process?.getBuiltinModule?.("node:worker_threads")?.parentPort ?? null;
109
109
  }
110
110
  });
111
111
 
@@ -122,6 +122,9 @@
122
122
  else if (ArrayBuffer.isView(value)) {
123
123
  if (isTransferable(value.buffer))
124
124
  transfersSet.add(value.buffer);
125
+ } else if (recursive && typeof MessageChannel !== "undefined" && value instanceof MessageChannel) {
126
+ visit(value.port1);
127
+ visit(value.port2);
125
128
  } else if (recursive && value instanceof Map) {
126
129
  for (const [key, item] of value) {
127
130
  visit(key);
@@ -189,16 +192,16 @@
189
192
  */
190
193
  static set onmessage(onMessage) {
191
194
  async function handleMessage(message) {
192
- const parentPort2 = await getParentPort();
193
- const { type, payload } = parentPort2 ? message : message.data;
195
+ const parentPort3 = await getParentPort();
196
+ const { type, payload } = parentPort3 ? message : message.data;
194
197
  onMessage(type, payload);
195
198
  }
196
- getParentPort().then((parentPort2) => {
197
- if (parentPort2) {
198
- parentPort2.on("message", (message) => {
199
+ getParentPort().then((parentPort3) => {
200
+ if (parentPort3) {
201
+ parentPort3.on("message", (message) => {
199
202
  handleMessage(message);
200
203
  });
201
- parentPort2.on("exit", () => console.debug("Node worker closing"));
204
+ parentPort3.on("exit", () => console.debug("Node worker closing"));
202
205
  } else {
203
206
  globalThis.onmessage = handleMessage;
204
207
  }
@@ -216,9 +219,9 @@
216
219
  };
217
220
  onMessageWrapperMap.set(onMessage, onMessageWrapper);
218
221
  }
219
- const parentPort2 = await getParentPort();
220
- if (parentPort2) {
221
- parentPort2.on("message", onMessageWrapper);
222
+ const parentPort3 = await getParentPort();
223
+ if (parentPort3) {
224
+ parentPort3.on("message", onMessageWrapper);
222
225
  } else {
223
226
  globalThis.addEventListener("message", onMessageWrapper);
224
227
  }
@@ -229,9 +232,9 @@
229
232
  if (!onMessageWrapper) {
230
233
  return;
231
234
  }
232
- const parentPort2 = await getParentPort();
233
- if (parentPort2) {
234
- parentPort2.off("message", onMessageWrapper);
235
+ const parentPort3 = await getParentPort();
236
+ if (parentPort3) {
237
+ parentPort3.off("message", onMessageWrapper);
235
238
  } else {
236
239
  globalThis.removeEventListener("message", onMessageWrapper);
237
240
  }
@@ -241,12 +244,12 @@
241
244
  * @param type
242
245
  * @param payload
243
246
  */
244
- static async postMessage(type, payload) {
247
+ static async postMessage(type, payload, copy = false) {
245
248
  const data = { source: "loaders.gl", type, payload };
246
- const transferList = getTransferList(payload);
247
- const parentPort2 = await getParentPort();
248
- if (parentPort2) {
249
- parentPort2.postMessage(data, transferList);
249
+ const transferList = copy ? [] : getTransferList(payload);
250
+ const parentPort3 = await getParentPort();
251
+ if (parentPort3) {
252
+ parentPort3.postMessage(data, transferList);
250
253
  } else {
251
254
  globalThis.postMessage(data, transferList);
252
255
  }
@@ -371,8 +374,19 @@
371
374
  }
372
375
  });
373
376
 
377
+ // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/validate-output-ownership.js
378
+ function validateOutputOwnership(ownership) {
379
+ if (ownership !== void 0 && ownership !== "copy" && ownership !== "transfer") {
380
+ throw new Error("Invalid worker output ownership");
381
+ }
382
+ }
383
+ var init_validate_output_ownership = __esm({
384
+ "../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/validate-output-ownership.js"() {
385
+ }
386
+ });
387
+
374
388
  // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/create-worker.js
375
- async function createWorker(process2, processInBatches) {
389
+ async function createWorker(process2, processInBatches, preload2) {
376
390
  if (!await WorkerBody.inWorkerThread()) {
377
391
  return;
378
392
  }
@@ -413,10 +427,12 @@
413
427
  }
414
428
  switch (type) {
415
429
  case "preload":
430
+ await preload2?.();
416
431
  WorkerBody.postMessage("done", {});
417
432
  break;
418
433
  case "process":
419
434
  throwIfAborted();
435
+ validateOutputOwnership(payload.options?.["outputOwnership"]);
420
436
  if (!process2) {
421
437
  throw new Error("Worker does not support atomic processing");
422
438
  }
@@ -426,10 +442,11 @@
426
442
  await WorkerBody.postMessage("done", {
427
443
  result,
428
444
  executionMs: performance.now() - startedAt
429
- });
445
+ }, payload.options?.["outputOwnership"] === "copy");
430
446
  break;
431
447
  case "process-in-batches":
432
448
  throwIfAborted();
449
+ validateOutputOwnership(payload.options?.["outputOwnership"]);
433
450
  if (!processInBatches) {
434
451
  throw new Error("Worker does not support batched processing");
435
452
  }
@@ -441,7 +458,7 @@
441
458
  const resultIterator = processInBatches(createDemandDrivenIterator(inputBatches), payload.options || {}, jobContext, payload.context || {});
442
459
  for await (const batch of resultIterator) {
443
460
  throwIfAborted();
444
- await WorkerBody.postMessage("output-batch", { result: batch });
461
+ await WorkerBody.postMessage("output-batch", { result: batch }, payload.options?.["outputOwnership"] === "copy");
445
462
  await outputAcknowledgements.next();
446
463
  }
447
464
  throwIfAborted();
@@ -539,14 +556,14 @@
539
556
  });
540
557
  }
541
558
  function createProgressReporter() {
542
- let pending;
559
+ let pending2;
543
560
  let finished = false;
544
561
  let scheduled = false;
545
562
  const flush = () => {
546
563
  scheduled = false;
547
- if (pending) {
548
- WorkerBody.postMessage("progress", { progress: pending });
549
- pending = void 0;
564
+ if (pending2) {
565
+ WorkerBody.postMessage("progress", { progress: pending2 });
566
+ pending2 = void 0;
550
567
  }
551
568
  };
552
569
  return {
@@ -554,9 +571,9 @@
554
571
  report(progress) {
555
572
  if (finished)
556
573
  return;
557
- if (pending && pending.phase !== progress.phase)
574
+ if (pending2 && pending2.phase !== progress.phase)
558
575
  flush();
559
- pending = { ...progress };
576
+ pending2 = { ...progress };
560
577
  if (!scheduled) {
561
578
  scheduled = true;
562
579
  setTimeout(flush, 0);
@@ -565,7 +582,7 @@
565
582
  /** Flushes final progress and suppresses reports from stale callbacks. */
566
583
  finish(discard = false) {
567
584
  if (discard)
568
- pending = void 0;
585
+ pending2 = void 0;
569
586
  flush();
570
587
  finished = true;
571
588
  }
@@ -577,6 +594,7 @@
577
594
  init_shared_state();
578
595
  init_async_queue();
579
596
  init_worker_body();
597
+ init_validate_output_ownership();
580
598
  requestId = 0;
581
599
  activeController = null;
582
600
  activeInputBatches = null;
@@ -588,6 +606,7 @@
588
606
  var import_meta, path, moduleUrl;
589
607
  var init_worker_utils = __esm({
590
608
  "../../node_modules/@math.gl/core/dist/worker-utils/index.js"() {
609
+ init_worker_body();
591
610
  init_create_worker();
592
611
  import_meta = {};
593
612
  path = typeof __filename === "string" ? __filename.replace(/\\/g, "/") : "";
@@ -595,18 +614,335 @@
595
614
  }
596
615
  });
597
616
 
617
+ // ../../node_modules/@math.gl/core/dist/tasks/task-preload.js
618
+ function preloadTaskCode(task, signal) {
619
+ if (!task.preload)
620
+ return Promise.resolve();
621
+ let promise = pending.get(task);
622
+ if (!promise) {
623
+ promise = Promise.resolve().then(() => task.preload()).then(() => {
624
+ loaded.add(task);
625
+ });
626
+ pending.set(task, promise);
627
+ void promise.catch(() => pending.delete(task));
628
+ }
629
+ return withSignal(promise, signal);
630
+ }
631
+ function withSignal(operation, signal) {
632
+ if (!signal)
633
+ return operation;
634
+ return new Promise((resolve, reject) => {
635
+ const abort = () => {
636
+ signal.removeEventListener("abort", abort);
637
+ reject(signal.reason);
638
+ };
639
+ signal.addEventListener("abort", abort, { once: true });
640
+ if (signal.aborted)
641
+ abort();
642
+ operation.then((value) => {
643
+ signal.removeEventListener("abort", abort);
644
+ resolve(value);
645
+ }, (error) => {
646
+ signal.removeEventListener("abort", abort);
647
+ reject(error);
648
+ });
649
+ });
650
+ }
651
+ var pending, loaded;
652
+ var init_task_preload = __esm({
653
+ "../../node_modules/@math.gl/core/dist/tasks/task-preload.js"() {
654
+ pending = /* @__PURE__ */ new WeakMap();
655
+ loaded = /* @__PURE__ */ new WeakSet();
656
+ }
657
+ });
658
+
659
+ // ../../node_modules/@math.gl/core/dist/tasks/task-runtime.js
660
+ function assertPayload(value) {
661
+ if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) {
662
+ throw new TypeError("Task payloads must be plain objects with named fields");
663
+ }
664
+ }
665
+ function taskContext(state, context = {}) {
666
+ const signal = context.signal ?? new AbortController().signal;
667
+ return {
668
+ state,
669
+ signal,
670
+ throwIfAborted: () => {
671
+ signal.throwIfAborted();
672
+ context.throwIfAborted?.();
673
+ },
674
+ reportProgress: (progress) => context.reportProgress?.({
675
+ ...progress,
676
+ phase: progress.phase ?? "process",
677
+ unit: progress.unit ?? "items"
678
+ })
679
+ };
680
+ }
681
+ async function initializeTaskWorker(task) {
682
+ if (!await WorkerBody.inWorkerThread())
683
+ throw new Error("initializeTaskWorker must run inside a worker");
684
+ if (installed)
685
+ throw new Error("A task is already installed in this worker");
686
+ installed = true;
687
+ const runtime = new TaskRuntime(task);
688
+ let streamOptions = {};
689
+ return createWorker(async (request, _options, context) => {
690
+ switch (request.operation) {
691
+ case "initialize":
692
+ return runtime.initialize(request.input, context);
693
+ case "destroy":
694
+ return runtime.destroy();
695
+ case "stream-options":
696
+ streamOptions = request.options;
697
+ return {};
698
+ case "process":
699
+ return runtime.process(request.input, request.options, context);
700
+ default:
701
+ throw new Error("Unknown task operation");
702
+ }
703
+ }, async function* (inputs, _options, context) {
704
+ async function* batches() {
705
+ for await (const input of inputs) {
706
+ assertPayload(input);
707
+ yield input;
708
+ }
709
+ }
710
+ try {
711
+ yield* runtime.stream(batches(), streamOptions, context);
712
+ } finally {
713
+ streamOptions = {};
714
+ }
715
+ }, () => preloadTaskCode(task));
716
+ }
717
+ var TaskRuntime, installed;
718
+ var init_task_runtime = __esm({
719
+ "../../node_modules/@math.gl/core/dist/tasks/task-runtime.js"() {
720
+ init_worker_utils();
721
+ init_task_preload();
722
+ TaskRuntime = class {
723
+ constructor(task) {
724
+ this.task = task;
725
+ this.initialized = false;
726
+ }
727
+ async initialize(input, context = {}) {
728
+ if (this.initialized)
729
+ throw new Error("Task is already initialized");
730
+ assertPayload(input);
731
+ await preloadTaskCode(this.task, context.signal);
732
+ context.signal?.throwIfAborted();
733
+ this.state = await this.task.initialize?.(input, taskContext(void 0, context));
734
+ this.initialized = true;
735
+ return {};
736
+ }
737
+ async destroy() {
738
+ if (this.initialized) {
739
+ this.initialized = false;
740
+ const state = this.state;
741
+ this.state = void 0;
742
+ if (this.task.initialize)
743
+ await this.task.destroy?.(state);
744
+ }
745
+ return {};
746
+ }
747
+ async process(input, options, context = {}) {
748
+ if (!this.initialized)
749
+ throw new Error("Task is not initialized");
750
+ if (!this.task.process)
751
+ throw new Error("Task has no atomic processor");
752
+ assertPayload(input);
753
+ const result = await this.task.process(input, options, taskContext(this.state, context));
754
+ assertPayload(result);
755
+ return result;
756
+ }
757
+ async *stream(inputs, options, context = {}) {
758
+ if (!this.initialized)
759
+ throw new Error("Task is not initialized");
760
+ if (!this.task.processInBatches)
761
+ throw new Error("Task has no streaming processor");
762
+ for await (const output of this.task.processInBatches(inputs, options, taskContext(this.state, context))) {
763
+ assertPayload(output);
764
+ yield output;
765
+ }
766
+ }
767
+ };
768
+ installed = false;
769
+ }
770
+ });
771
+
598
772
  // ../../node_modules/@math.gl/core/dist/tasks/index.js
599
773
  var init_tasks = __esm({
600
774
  "../../node_modules/@math.gl/core/dist/tasks/index.js"() {
601
- init_worker_utils();
775
+ init_task_runtime();
776
+ }
777
+ });
778
+
779
+ // ../core/src/worker-utils/lib/node/worker_threads-browser.ts
780
+ var worker_threads_browser_exports = {};
781
+ __export(worker_threads_browser_exports, {
782
+ NodeWorker: () => NodeWorker,
783
+ parentPort: () => parentPort2
784
+ });
785
+ var NodeWorker, parentPort2;
786
+ var init_worker_threads_browser2 = __esm({
787
+ "../core/src/worker-utils/lib/node/worker_threads-browser.ts"() {
788
+ "use strict";
789
+ NodeWorker = class {
790
+ /** Restores the native worker constructor when this browser shim is embedded in a Node bundle. */
791
+ constructor(...arguments_) {
792
+ const runtimeProcess = globalThis.process;
793
+ const WorkerConstructor = runtimeProcess?.getBuiltinModule?.("node:worker_threads").Worker;
794
+ if (WorkerConstructor) {
795
+ return new WorkerConstructor(...arguments_);
796
+ }
797
+ }
798
+ /** No-op browser fallback matching the native Worker API. */
799
+ terminate() {
800
+ }
801
+ };
802
+ parentPort2 = null;
803
+ }
804
+ });
805
+
806
+ // ../core/src/worker-utils/lib/worker-api/task-runtime.ts
807
+ function normalizeTaskProgress(progress) {
808
+ return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
809
+ }
810
+ async function isWorkerThread() {
811
+ if (typeof self !== "undefined" && typeof document === "undefined" && typeof self.postMessage === "function")
812
+ return true;
813
+ if (typeof process !== "undefined" && process.versions?.node) {
814
+ const { isMainThread } = await Promise.resolve().then(() => (init_worker_threads_browser2(), worker_threads_browser_exports));
815
+ return !isMainThread;
816
+ }
817
+ return false;
818
+ }
819
+ var initializeTaskWorker2;
820
+ var init_task_runtime2 = __esm({
821
+ "../core/src/worker-utils/lib/worker-api/task-runtime.ts"() {
822
+ "use strict";
823
+ init_tasks();
824
+ initializeTaskWorker2 = initializeTaskWorker;
825
+ }
826
+ });
827
+
828
+ // ../core/src/worker-utils/lib/worker-utils/get-transfer-list.ts
829
+ function getTransferList2(object, recursive = true, transfers) {
830
+ const transfersSet = transfers || /* @__PURE__ */ new Set();
831
+ if (!object) {
832
+ } else if (isTransferable2(object)) {
833
+ transfersSet.add(object);
834
+ } else if (isTransferable2(object.buffer)) {
835
+ transfersSet.add(object.buffer);
836
+ } else if (ArrayBuffer.isView(object)) {
837
+ } else if (recursive && typeof object === "object") {
838
+ for (const key in object) {
839
+ getTransferList2(object[key], recursive, transfersSet);
840
+ }
841
+ }
842
+ return transfers === void 0 ? Array.from(transfersSet) : [];
843
+ }
844
+ function isTransferable2(object) {
845
+ if (!object) {
846
+ return false;
847
+ }
848
+ if (object instanceof ArrayBuffer) {
849
+ return true;
850
+ }
851
+ if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
852
+ return true;
853
+ }
854
+ if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
855
+ return true;
856
+ }
857
+ if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
858
+ return true;
859
+ }
860
+ return false;
861
+ }
862
+ var init_get_transfer_list2 = __esm({
863
+ "../core/src/worker-utils/lib/worker-utils/get-transfer-list.ts"() {
864
+ "use strict";
602
865
  }
603
866
  });
604
867
 
605
868
  // ../core/src/worker-utils/lib/worker-api/create-worker.ts
869
+ async function createWorker2(process2, processInBatches) {
870
+ if (!await isWorkerThread()) return;
871
+ await initializeTaskWorker2(createWorkerTask(process2, processInBatches));
872
+ }
873
+ function createWorkerTask(process2, processInBatches) {
874
+ return {
875
+ id: "loaders.gl",
876
+ initialize: (state) => state,
877
+ destroy: (state) => state.port?.close(),
878
+ process: async ({ value }, options, context) => {
879
+ if (!process2) throw new Error("Worker does not support atomic processing");
880
+ return { value: await process2(value, options, createContext(context), context.state.context) };
881
+ },
882
+ ...processInBatches ? {
883
+ processInBatches: async function* (inputs, options, context) {
884
+ async function* values() {
885
+ for await (const input of inputs) yield input.value;
886
+ }
887
+ for await (const value of processInBatches(
888
+ values(),
889
+ options,
890
+ createContext(context),
891
+ context.state.context
892
+ )) {
893
+ yield { value };
894
+ }
895
+ }
896
+ } : {}
897
+ };
898
+ }
899
+ function createContext(context) {
900
+ let requestIdentifier = 0;
901
+ const port = context.state.port;
902
+ return {
903
+ signal: context.signal,
904
+ throwIfAborted: () => context.throwIfAborted(),
905
+ reportProgress: (progress) => context.reportProgress(normalizeTaskProgress(progress)),
906
+ process: port ? (input, options = {}, jobContext = {}) => {
907
+ context.throwIfAborted();
908
+ const identifier = ++requestIdentifier;
909
+ return new Promise((resolve, reject) => {
910
+ const onMessage = (event) => {
911
+ if (event.data.identifier !== identifier) return;
912
+ cleanup();
913
+ if (event.data.error) {
914
+ const error = new Error(event.data.error.message);
915
+ error.name = event.data.error.name;
916
+ reject(error);
917
+ } else resolve(event.data.value);
918
+ };
919
+ const onAbort = () => {
920
+ cleanup();
921
+ reject(context.signal.reason);
922
+ };
923
+ const cleanup = () => {
924
+ port.removeEventListener("message", onMessage);
925
+ context.signal.removeEventListener("abort", onAbort);
926
+ };
927
+ port.addEventListener("message", onMessage);
928
+ context.signal.addEventListener("abort", onAbort, { once: true });
929
+ port.start();
930
+ try {
931
+ const request = { identifier, input, options, context: jobContext };
932
+ port.postMessage(request, getTransferList2(request));
933
+ } catch (error) {
934
+ cleanup();
935
+ reject(error);
936
+ }
937
+ });
938
+ } : void 0
939
+ };
940
+ }
606
941
  var init_create_worker2 = __esm({
607
942
  "../core/src/worker-utils/lib/worker-api/create-worker.ts"() {
608
943
  "use strict";
609
- init_tasks();
944
+ init_task_runtime2();
945
+ init_get_transfer_list2();
610
946
  }
611
947
  });
612
948
 
@@ -783,7 +1119,7 @@
783
1119
 
784
1120
  // ../core/src/loader-utils/lib/worker-loader-utils/create-loader-worker.ts
785
1121
  async function createLoaderWorker(loader, selectLoader = () => loader) {
786
- await createWorker(
1122
+ await createWorker2(
787
1123
  (input, options, workerContext, loaderContext) => processLoaderWorkerData(
788
1124
  selectLoader(options || {}),
789
1125
  input,
@@ -8775,11 +9111,11 @@ return true;`);
8775
9111
  this._offsets = new OffsetsBufferBuilder(opts.type);
8776
9112
  }
8777
9113
  setValue(index, value) {
8778
- const pending = this._pending || (this._pending = /* @__PURE__ */ new Map());
8779
- const current = pending.get(index);
9114
+ const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
9115
+ const current = pending2.get(index);
8780
9116
  current && (this._pendingLength -= current.length);
8781
9117
  this._pendingLength += value instanceof MapRow ? value[kKeys].length : value.length;
8782
- pending.set(index, value);
9118
+ pending2.set(index, value);
8783
9119
  }
8784
9120
  setValid(index, isValid) {
8785
9121
  if (!super.setValid(index, isValid)) {
@@ -8802,12 +9138,12 @@ return true;`);
8802
9138
  return super.finish();
8803
9139
  }
8804
9140
  _flush() {
8805
- const pending = this._pending;
9141
+ const pending2 = this._pending;
8806
9142
  const pendingLength = this._pendingLength;
8807
9143
  this._pendingLength = 0;
8808
9144
  this._pending = void 0;
8809
- if (pending && pending.size > 0) {
8810
- this._flushPending(pending, pendingLength);
9145
+ if (pending2 && pending2.size > 0) {
9146
+ this._flushPending(pending2, pendingLength);
8811
9147
  }
8812
9148
  return this;
8813
9149
  }
@@ -11393,11 +11729,11 @@ return true;`);
11393
11729
  setValue(index, value) {
11394
11730
  return super.setValue(index, toUint8Array(value));
11395
11731
  }
11396
- _flushPending(pending, pendingLength) {
11732
+ _flushPending(pending2, pendingLength) {
11397
11733
  const offsets = this._offsets;
11398
11734
  const data = this._values.reserve(pendingLength).buffer;
11399
11735
  let offset = 0;
11400
- for (const [index, value] of pending) {
11736
+ for (const [index, value] of pending2) {
11401
11737
  if (value === void 0) {
11402
11738
  offsets.set(index, 0);
11403
11739
  } else {
@@ -11434,11 +11770,11 @@ return true;`);
11434
11770
  setValue(index, value) {
11435
11771
  return super.setValue(index, toUint8Array(value));
11436
11772
  }
11437
- _flushPending(pending, pendingLength) {
11773
+ _flushPending(pending2, pendingLength) {
11438
11774
  const offsets = this._offsets;
11439
11775
  const data = this._values.reserve(pendingLength).buffer;
11440
11776
  let offset = 0;
11441
- for (const [index, value] of pending) {
11777
+ for (const [index, value] of pending2) {
11442
11778
  if (value === void 0) {
11443
11779
  offsets.set(index, BigInt(0));
11444
11780
  } else {
@@ -11749,10 +12085,10 @@ return true;`);
11749
12085
  this.type = new List2(new Field2(name, child.type, true));
11750
12086
  return this.numChildren - 1;
11751
12087
  }
11752
- _flushPending(pending) {
12088
+ _flushPending(pending2) {
11753
12089
  const offsets = this._offsets;
11754
12090
  const [child] = this.children;
11755
- for (const [index, value] of pending) {
12091
+ for (const [index, value] of pending2) {
11756
12092
  if (typeof value === "undefined") {
11757
12093
  offsets.set(index, 0);
11758
12094
  } else {
@@ -11791,10 +12127,10 @@ return true;`);
11791
12127
  this.type = new LargeList2(new Field2(name, child.type, true));
11792
12128
  return this.numChildren - 1;
11793
12129
  }
11794
- _flushPending(pending) {
12130
+ _flushPending(pending2) {
11795
12131
  const offsets = this._offsets;
11796
12132
  const [child] = this.children;
11797
- for (const [index, value] of pending) {
12133
+ for (const [index, value] of pending2) {
11798
12134
  if (typeof value === "undefined") {
11799
12135
  offsets.set(index, BigInt(0));
11800
12136
  } else {
@@ -11824,11 +12160,11 @@ return true;`);
11824
12160
  }
11825
12161
  setValue(index, value) {
11826
12162
  const row = value instanceof Map ? value : new Map(Object.entries(value));
11827
- const pending = this._pending || (this._pending = /* @__PURE__ */ new Map());
11828
- const current = pending.get(index);
12163
+ const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
12164
+ const current = pending2.get(index);
11829
12165
  current && (this._pendingLength -= current.size);
11830
12166
  this._pendingLength += row.size;
11831
- pending.set(index, row);
12167
+ pending2.set(index, row);
11832
12168
  }
11833
12169
  addChild(child, name = `${this.numChildren}`) {
11834
12170
  if (this.numChildren > 0) {
@@ -11838,10 +12174,10 @@ return true;`);
11838
12174
  this.type = new Map_(new Field2(name, child.type, true), this.type.keysSorted);
11839
12175
  return this.numChildren - 1;
11840
12176
  }
11841
- _flushPending(pending) {
12177
+ _flushPending(pending2) {
11842
12178
  const offsets = this._offsets;
11843
12179
  const [child] = this.children;
11844
- for (const [index, value] of pending) {
12180
+ for (const [index, value] of pending2) {
11845
12181
  if (value === void 0) {
11846
12182
  offsets.set(index, 0);
11847
12183
  } else {
@@ -12050,7 +12386,7 @@ return true;`);
12050
12386
  return super.setValue(index, encodeUtf8(value));
12051
12387
  }
12052
12388
  // @ts-ignore
12053
- _flushPending(pending, pendingLength) {
12389
+ _flushPending(pending2, pendingLength) {
12054
12390
  }
12055
12391
  };
12056
12392
  Utf8Builder.prototype._flushPending = BinaryBuilder.prototype._flushPending;
@@ -12081,7 +12417,7 @@ return true;`);
12081
12417
  return super.setValue(index, encodeUtf8(value));
12082
12418
  }
12083
12419
  // @ts-ignore
12084
- _flushPending(pending, pendingLength) {
12420
+ _flushPending(pending2, pendingLength) {
12085
12421
  }
12086
12422
  };
12087
12423
  LargeUtf8Builder.prototype._flushPending = LargeBinaryBuilder.prototype._flushPending;
@@ -17910,7 +18246,7 @@ return true;`);
17910
18246
  var init_version2 = __esm({
17911
18247
  "src/draco/lib/utils/version.ts"() {
17912
18248
  "use strict";
17913
- VERSION2 = true ? "5.0.0-beta.2" : "latest";
18249
+ VERSION2 = true ? "5.0.0-beta.4" : "latest";
17914
18250
  }
17915
18251
  });
17916
18252