@loaders.gl/scene 5.0.0-beta.4 → 5.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/DRACO-README.md +1 -1
  2. package/GLTF-README.md +1 -1
  3. package/OBJ-README.md +1 -1
  4. package/README.md +6 -1
  5. package/THIRD-PARTY-NOTICES.md +6 -0
  6. package/dist/dist.dev.js +2958 -750
  7. package/dist/dist.min.js +18 -18
  8. package/dist/draco/draco-javascript-loader-with-parser.d.ts +2 -2
  9. package/dist/draco/draco-loader-types.cjs +3 -3
  10. package/dist/draco/draco-loader-types.cjs.map +2 -2
  11. package/dist/draco/draco-loader-types.d.ts +1 -1
  12. package/dist/draco/draco-loader-types.d.ts.map +1 -1
  13. package/dist/draco/draco-loader-types.js +1 -1
  14. package/dist/draco/draco-loader-types.js.map +1 -1
  15. package/dist/draco/draco-loader.d.ts +2 -2
  16. package/dist/draco/draco-wasm-loader-with-parser.d.ts +2 -2
  17. package/dist/draco/draco3d-loader-with-parser.d.ts +2 -2
  18. package/dist/draco/lib/utils/version.cjs +1 -1
  19. package/dist/draco/lib/utils/version.js +1 -1
  20. package/dist/draco-worker-node.js +400 -113
  21. package/dist/draco-worker-node.js.map +4 -4
  22. package/dist/draco-worker.js +394 -113
  23. package/dist/draco-worker.js.map +4 -4
  24. package/dist/draco-writer-worker-node.cjs +654 -85
  25. package/dist/draco-writer-worker-node.cjs.map +4 -4
  26. package/dist/draco-writer-worker.js +624 -69
  27. package/dist/draco-writer-worker.js.map +4 -4
  28. package/dist/gltf/lib/extensions/KHR_gaussian_splatting.cjs +11 -4
  29. package/dist/gltf/lib/extensions/KHR_gaussian_splatting.cjs.map +2 -2
  30. package/dist/gltf/lib/extensions/KHR_gaussian_splatting.d.ts.map +1 -1
  31. package/dist/gltf/lib/extensions/KHR_gaussian_splatting.js +12 -2
  32. package/dist/gltf/lib/extensions/KHR_gaussian_splatting.js.map +1 -1
  33. package/dist/gltf/lib/parsers/parse-gltf.cjs.map +2 -2
  34. package/dist/gltf/lib/parsers/parse-gltf.d.ts +2 -0
  35. package/dist/gltf/lib/parsers/parse-gltf.d.ts.map +1 -1
  36. package/dist/gltf/lib/parsers/parse-gltf.js.map +1 -1
  37. package/dist/gltf/lib/types/gltf-additional-extension-schemas.cjs +22 -0
  38. package/dist/gltf/lib/types/gltf-additional-extension-schemas.cjs.map +2 -2
  39. package/dist/gltf/lib/types/gltf-additional-extension-schemas.d.ts +23 -0
  40. package/dist/gltf/lib/types/gltf-additional-extension-schemas.d.ts.map +1 -1
  41. package/dist/gltf/lib/types/gltf-additional-extension-schemas.js +22 -0
  42. package/dist/gltf/lib/types/gltf-additional-extension-schemas.js.map +1 -1
  43. package/dist/gltf/lib/types/gltf-extension-schemas.cjs +8 -0
  44. package/dist/gltf/lib/types/gltf-extension-schemas.cjs.map +2 -2
  45. package/dist/gltf/lib/types/gltf-extension-schemas.d.ts +27 -0
  46. package/dist/gltf/lib/types/gltf-extension-schemas.d.ts.map +1 -1
  47. package/dist/gltf/lib/types/gltf-extension-schemas.js +8 -1
  48. package/dist/gltf/lib/types/gltf-extension-schemas.js.map +1 -1
  49. package/dist/gltf/lib/types/gltf-json-schema.cjs.map +1 -1
  50. package/dist/gltf/lib/types/gltf-json-schema.d.ts +2 -2
  51. package/dist/gltf/lib/types/gltf-json-schema.d.ts.map +1 -1
  52. package/dist/gltf/lib/types/gltf-version-zod-schemas.d.ts +34 -0
  53. package/dist/gltf/lib/types/gltf-version-zod-schemas.d.ts.map +1 -1
  54. package/dist/gltf/lib/types/gltf-zod-schema.cjs +1 -1
  55. package/dist/gltf/lib/types/gltf-zod-schema.cjs.map +2 -2
  56. package/dist/gltf/lib/types/gltf-zod-schema.d.ts +51 -0
  57. package/dist/gltf/lib/types/gltf-zod-schema.d.ts.map +1 -1
  58. package/dist/gltf/lib/types/gltf-zod-schema.js +2 -2
  59. package/dist/gltf/lib/types/gltf-zod-schema.js.map +1 -1
  60. package/dist/gltf/lib/utils/version.cjs +1 -1
  61. package/dist/gltf/lib/utils/version.js +1 -1
  62. package/dist/index.cjs +4 -1
  63. package/dist/index.cjs.map +2 -2
  64. package/dist/index.d.ts +1 -0
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/index.js +2 -1
  67. package/dist/index.js.map +1 -1
  68. package/dist/mtl-loader-types.cjs +1 -1
  69. package/dist/obj/mtl-loader-types.cjs +1 -1
  70. package/dist/obj/mtl-loader-types.js +1 -1
  71. package/dist/obj/obj-loader-types.cjs +3 -3
  72. package/dist/obj/obj-loader-types.cjs.map +2 -2
  73. package/dist/obj/obj-loader-types.d.ts +1 -1
  74. package/dist/obj/obj-loader-types.d.ts.map +1 -1
  75. package/dist/obj/obj-loader-types.js +2 -2
  76. package/dist/obj/obj-loader-types.js.map +1 -1
  77. package/dist/obj/obj-loader.cjs +5 -5
  78. package/dist/obj/obj-loader.cjs.map +2 -2
  79. package/dist/obj/obj-loader.d.ts +1 -1
  80. package/dist/obj/obj-loader.d.ts.map +1 -1
  81. package/dist/obj/obj-loader.js +1 -1
  82. package/dist/obj/obj-loader.js.map +1 -1
  83. package/dist/obj/obj-writer.cjs +1 -1
  84. package/dist/obj/obj-writer.js +1 -1
  85. package/dist/obj-loader-types.cjs +3 -3
  86. package/dist/obj-loader-types.cjs.map +2 -2
  87. package/dist/obj-loader.cjs +5 -5
  88. package/dist/obj-loader.cjs.map +2 -2
  89. package/dist/obj-worker.js +568 -287
  90. package/dist/obj-writer.cjs +1 -1
  91. package/dist/stl/parse-stl.cjs +100 -0
  92. package/dist/stl/parse-stl.cjs.map +7 -0
  93. package/dist/stl/parse-stl.d.ts +4 -0
  94. package/dist/stl/parse-stl.d.ts.map +1 -0
  95. package/dist/stl/parse-stl.js +84 -0
  96. package/dist/stl/parse-stl.js.map +1 -0
  97. package/dist/stl-loader-types.cjs +58 -0
  98. package/dist/stl-loader-types.cjs.map +7 -0
  99. package/dist/stl-loader-types.d.ts +32 -0
  100. package/dist/stl-loader-types.d.ts.map +1 -0
  101. package/dist/stl-loader-types.js +25 -0
  102. package/dist/stl-loader-types.js.map +1 -0
  103. package/dist/stl-loader.cjs +38 -0
  104. package/dist/stl-loader.cjs.map +7 -0
  105. package/dist/stl-loader.d.ts +17 -0
  106. package/dist/stl-loader.d.ts.map +1 -0
  107. package/dist/stl-loader.js +13 -0
  108. package/dist/stl-loader.js.map +1 -0
  109. package/dist/usd/index.cjs.map +1 -1
  110. package/dist/usd/index.d.ts +1 -1
  111. package/dist/usd/index.d.ts.map +1 -1
  112. package/dist/usd/lib/parse-usd.cjs +42 -5
  113. package/dist/usd/lib/parse-usd.cjs.map +2 -2
  114. package/dist/usd/lib/parse-usd.d.ts.map +1 -1
  115. package/dist/usd/lib/parse-usd.js +53 -6
  116. package/dist/usd/lib/parse-usd.js.map +1 -1
  117. package/dist/usd/lib/parse-usdc.cjs +187 -0
  118. package/dist/usd/lib/parse-usdc.cjs.map +7 -0
  119. package/dist/usd/lib/parse-usdc.d.ts +4 -0
  120. package/dist/usd/lib/parse-usdc.d.ts.map +1 -0
  121. package/dist/usd/lib/parse-usdc.js +176 -0
  122. package/dist/usd/lib/parse-usdc.js.map +1 -0
  123. package/dist/usd/lib/parse-usdz.cjs +22 -0
  124. package/dist/usd/lib/parse-usdz.cjs.map +2 -2
  125. package/dist/usd/lib/parse-usdz.d.ts.map +1 -1
  126. package/dist/usd/lib/parse-usdz.js +26 -0
  127. package/dist/usd/lib/parse-usdz.js.map +1 -1
  128. package/dist/usd/lib/usd-types.cjs.map +1 -1
  129. package/dist/usd/lib/usd-types.d.ts +14 -1
  130. package/dist/usd/lib/usd-types.d.ts.map +1 -1
  131. package/dist/usd/lib/usd-types.js +1 -1
  132. package/dist/usd/lib/usd-types.js.map +1 -1
  133. package/dist/usd/libs/README.md +27 -0
  134. package/dist/usd/libs/THREE-LICENSE +21 -0
  135. package/dist/usd/libs/usdc-parser.d.ts +78 -0
  136. package/dist/usd/libs/usdc-parser.d.ts.map +1 -0
  137. package/dist/usd/libs/usdc-parser.js +1669 -0
  138. package/dist/usd/libs/usdc-parser.js.map +1 -0
  139. package/dist/usd/usd-loader-types.cjs +4 -4
  140. package/dist/usd/usd-loader-types.cjs.map +2 -2
  141. package/dist/usd/usd-loader-types.d.ts +7 -7
  142. package/dist/usd/usd-loader-types.d.ts.map +1 -1
  143. package/dist/usd/usd-loader-types.js +6 -6
  144. package/dist/usd/usd-loader-types.js.map +1 -1
  145. package/dist/usd/usd-loader.cjs.map +1 -1
  146. package/dist/usd/usd-loader.d.ts +4 -4
  147. package/dist/usd/usd-loader.d.ts.map +1 -1
  148. package/dist/usd/usd-loader.js +2 -2
  149. package/dist/usd/usd-loader.js.map +1 -1
  150. package/dist/usd-loader-types.cjs +4 -4
  151. package/dist/usd-loader-types.cjs.map +2 -2
  152. package/dist/usd-loader.cjs.map +1 -1
  153. package/package.json +14 -8
  154. package/src/draco/draco-loader-types.ts +1 -1
  155. package/src/gltf/lib/extensions/KHR_gaussian_splatting.ts +14 -4
  156. package/src/gltf/lib/parsers/parse-gltf.ts +2 -0
  157. package/src/gltf/lib/types/gltf-additional-extension-schemas.ts +32 -0
  158. package/src/gltf/lib/types/gltf-extension-schemas.ts +12 -0
  159. package/src/gltf/lib/types/gltf-json-schema.ts +2 -1
  160. package/src/gltf/lib/types/gltf-zod-schema.ts +2 -1
  161. package/src/index.ts +3 -1
  162. package/src/obj/obj-loader-types.ts +1 -1
  163. package/src/obj/obj-loader.ts +1 -1
  164. package/src/stl/parse-stl.ts +90 -0
  165. package/src/stl-loader-types.ts +28 -0
  166. package/src/stl-loader.ts +12 -0
  167. package/src/usd/index.ts +1 -0
  168. package/src/usd/lib/parse-usd.ts +68 -7
  169. package/src/usd/lib/parse-usdc.ts +188 -0
  170. package/src/usd/lib/parse-usdz.ts +28 -0
  171. package/src/usd/lib/usd-types.ts +16 -2
  172. package/src/usd/libs/README.md +27 -0
  173. package/src/usd/libs/THREE-LICENSE +21 -0
  174. package/src/usd/libs/usdc-parser.d.ts +18 -0
  175. package/src/usd/libs/usdc-parser.js +1669 -0
  176. package/src/usd/usd-loader-types.ts +5 -5
  177. package/src/usd/usd-loader.ts +2 -2
@@ -10644,7 +10644,7 @@ var NPM_TAG = "beta";
10644
10644
 
10645
10645
  // ../core/src/worker-utils/lib/env-utils/version.ts
10646
10646
  function getVersion() {
10647
- const version2 = false ? NPM_TAG : "5.0.0-beta.4";
10647
+ const version2 = false ? NPM_TAG : "5.0.0-beta.5";
10648
10648
  globalThis._loadersgl_ = globalThis._loadersgl_ || {};
10649
10649
  globalThis._loadersgl_.version ||= version2;
10650
10650
  return version2;
@@ -10678,23 +10678,23 @@ var isMobile = typeof window !== "undefined" && typeof window.orientation !== "u
10678
10678
  var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
10679
10679
  var nodeVersion2 = matches && parseFloat(matches[1]) || 0;
10680
10680
 
10681
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/npm-tag.js
10681
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/npm-tag.js
10682
10682
  var NPM_TAG2 = "latest";
10683
10683
 
10684
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/env-utils/version.js
10684
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/env-utils/version.js
10685
10685
  function getVersion2() {
10686
- return false ? NPM_TAG2 : "5.0.0-beta.4";
10686
+ return false ? NPM_TAG2 : "5.0.0-beta.5";
10687
10687
  }
10688
10688
  var VERSION2 = getVersion2();
10689
10689
 
10690
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/env-utils/assert.js
10690
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/env-utils/assert.js
10691
10691
  function assert2(condition, message) {
10692
10692
  if (!condition) {
10693
10693
  throw new Error(message || "loaders.gl assertion failed.");
10694
10694
  }
10695
10695
  }
10696
10696
 
10697
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/env-utils/globals.js
10697
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/env-utils/globals.js
10698
10698
  var globals2 = {
10699
10699
  self: typeof self !== "undefined" && self,
10700
10700
  window: typeof window !== "undefined" && window,
@@ -10713,7 +10713,7 @@ var isMobile2 = typeof window !== "undefined" && typeof window.orientation !== "
10713
10713
  var matches2 = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
10714
10714
  var nodeVersion3 = matches2 && parseFloat(matches2[1]) || 0;
10715
10715
 
10716
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-farm/worker-job.js
10716
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-job.js
10717
10717
  var WorkerJob = class {
10718
10718
  constructor(jobName, workerThread) {
10719
10719
  this.isRunning = true;
@@ -10833,12 +10833,12 @@ function createAbortError(message) {
10833
10833
  return error;
10834
10834
  }
10835
10835
 
10836
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/node/worker_threads.js
10836
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/node/worker_threads.js
10837
10837
  var import_worker_threads = require("worker_threads");
10838
10838
  var parentPort = import_worker_threads.parentPort;
10839
10839
  var NodeWorker = import_worker_threads.Worker;
10840
10840
 
10841
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-utils/get-loadable-worker-url.js
10841
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-utils/get-loadable-worker-url.js
10842
10842
  var workerURLCache = /* @__PURE__ */ new Map();
10843
10843
  function getLoadableWorkerURL(props) {
10844
10844
  var _a5, _b2, _c2;
@@ -10888,7 +10888,7 @@ function buildScriptSource(workerUrl) {
10888
10888
  }`;
10889
10889
  }
10890
10890
 
10891
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-utils/get-transfer-list.js
10891
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-utils/get-transfer-list.js
10892
10892
  function getTransferList(object2, recursive = true, transfers) {
10893
10893
  const transfersSet = transfers || /* @__PURE__ */ new Set();
10894
10894
  const seen = /* @__PURE__ */ new Set();
@@ -10972,7 +10972,7 @@ function getTransferListForWriter(object2) {
10972
10972
  return object2 === null ? {} : clone2(object2);
10973
10973
  }
10974
10974
 
10975
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-farm/worker-thread.js
10975
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-thread.js
10976
10976
  var NOOP = () => {
10977
10977
  };
10978
10978
  var WorkerThread = class {
@@ -11154,7 +11154,7 @@ var WorkerThread = class {
11154
11154
  }
11155
11155
  };
11156
11156
 
11157
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-farm/worker-pool.js
11157
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-pool.js
11158
11158
  var WorkerPool = class {
11159
11159
  /** Snapshot; byte figures describe input buffers, not total heap memory. */
11160
11160
  get stats() {
@@ -11684,7 +11684,7 @@ var WorkerPool = class {
11684
11684
  }
11685
11685
  };
11686
11686
 
11687
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-farm/worker-farm.js
11687
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-farm.js
11688
11688
  var DEFAULT_PROPS = {
11689
11689
  maxQueuedJobs: Infinity,
11690
11690
  maxPendingAdmissions: 128,
@@ -11805,7 +11805,7 @@ function getLoadWorkerId(loadWorker) {
11805
11805
  return loadWorkerId;
11806
11806
  }
11807
11807
 
11808
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-farm/worker-body.js
11808
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-body.js
11809
11809
  async function getParentPort() {
11810
11810
  return parentPort;
11811
11811
  }
@@ -11892,7 +11892,7 @@ function getWorkerMessageData(message) {
11892
11892
  return messageData && typeof messageData.source === "string" && messageData.source.startsWith("loaders.gl") ? messageData : null;
11893
11893
  }
11894
11894
 
11895
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/async-queue/async-queue.js
11895
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/async-queue/async-queue.js
11896
11896
  var AsyncQueue = class {
11897
11897
  constructor() {
11898
11898
  this._values = [];
@@ -11959,7 +11959,7 @@ var AsyncQueue = class {
11959
11959
  }
11960
11960
  };
11961
11961
 
11962
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/get-worker-url.js
11962
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/get-worker-url.js
11963
11963
  var warnedWorkerVersionFallbacks = /* @__PURE__ */ new Set();
11964
11964
  function getWorkerName(worker) {
11965
11965
  const warning = worker.version !== VERSION2 ? ` (worker-utils@${VERSION2})` : "";
@@ -11974,7 +11974,7 @@ function getCustomWorkerURL(worker, options = {}) {
11974
11974
  if (isBrowser3) {
11975
11975
  url = `modules/${worker.module}/dist/${workerFile}`;
11976
11976
  } else {
11977
- const workerSourceDirectory = worker.module === "core" && ((_b2 = worker.workerNode) == null ? void 0 : _b2.startsWith("worker-utils/")) ? "worker-utils/workers" : "workers";
11977
+ const workerSourceDirectory = worker.module === "tasks" && ((_b2 = worker.workerNode) == null ? void 0 : _b2.startsWith("worker-utils/")) ? "worker-utils/workers" : "workers";
11978
11978
  const workerSourceNode = worker.workerSourceNode || `${workerSourceDirectory}/${worker.id}-worker-node.ts`;
11979
11979
  url = `modules/${worker.module}/src/${workerSourceNode}`;
11980
11980
  }
@@ -12018,7 +12018,7 @@ function warnIfUsingNpmTagFallback(worker, url) {
12018
12018
  console.warn(`loaders.gl: ${worker.name} loader worker version is "latest" because __VERSION__ was not injected. Fetching ${url} from CDN.`);
12019
12019
  }
12020
12020
 
12021
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/shared-state.js
12021
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/shared-state.js
12022
12022
  function getWorkerCapabilities() {
12023
12023
  const isolated = typeof globalThis.crossOriginIsolated === "boolean" ? globalThis.crossOriginIsolated : void 0;
12024
12024
  const capabilities = {
@@ -12101,7 +12101,7 @@ function prepareSharedState(options) {
12101
12101
  return options;
12102
12102
  }
12103
12103
 
12104
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-utils/get-input-byte-length.js
12104
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-utils/get-input-byte-length.js
12105
12105
  function getInputByteLength(input) {
12106
12106
  const seen = /* @__PURE__ */ new Set();
12107
12107
  let bytes = 0;
@@ -12130,14 +12130,14 @@ function getInputByteLength(input) {
12130
12130
  return bytes;
12131
12131
  }
12132
12132
 
12133
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/validate-output-ownership.js
12133
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/validate-output-ownership.js
12134
12134
  function validateOutputOwnership(ownership) {
12135
12135
  if (ownership !== void 0 && ownership !== "copy" && ownership !== "transfer") {
12136
12136
  throw new Error("Invalid worker output ownership");
12137
12137
  }
12138
12138
  }
12139
12139
 
12140
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/process-on-worker.js
12140
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/process-on-worker.js
12141
12141
  async function processOnWorker(worker, data, options = {}, context = {}, jobContext = {}) {
12142
12142
  var _a5;
12143
12143
  validateOutputOwnership(options.outputOwnership);
@@ -12434,7 +12434,7 @@ function budgetOptions(options) {
12434
12434
  return inputOptions;
12435
12435
  }
12436
12436
 
12437
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/create-worker.js
12437
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/create-worker.js
12438
12438
  var requestId = 0;
12439
12439
  var activeController = null;
12440
12440
  var activeInputBatches = null;
@@ -12643,12 +12643,12 @@ function createProgressReporter() {
12643
12643
  };
12644
12644
  }
12645
12645
 
12646
- // ../../node_modules/@math.gl/core/dist/worker-utils/index.js
12646
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/index.js
12647
12647
  var import_meta3 = {};
12648
12648
  var path3 = typeof __filename === "string" ? __filename.replace(/\\/g, "/") : "";
12649
12649
  var moduleUrl = path3 ? `file://${path3.startsWith("/") ? "" : "/"}${encodeURI(path3).replace(/#/g, "%23").replace(/\?/g, "%3F")}` : import_meta3.url;
12650
12650
 
12651
- // ../../node_modules/@math.gl/core/dist/tasks/task-preload.js
12651
+ // ../../node_modules/@math.gl/tasks/dist/tasks/task-preload.js
12652
12652
  var pending = /* @__PURE__ */ new WeakMap();
12653
12653
  var loaded = /* @__PURE__ */ new WeakSet();
12654
12654
  function preloadTaskCode(task, signal) {
@@ -12688,7 +12688,154 @@ function withSignal(operation, signal) {
12688
12688
  });
12689
12689
  }
12690
12690
 
12691
- // ../../node_modules/@math.gl/core/dist/tasks/task-runtime.js
12691
+ // ../../node_modules/@math.gl/tasks/dist/tasks/task-channel.js
12692
+ var TaskRequestError = class extends Error {
12693
+ };
12694
+ var TaskChannel = class {
12695
+ constructor(options) {
12696
+ this.options = options;
12697
+ this.nextId = 1;
12698
+ this.pending = /* @__PURE__ */ new Map();
12699
+ this.incoming = /* @__PURE__ */ new Map();
12700
+ }
12701
+ /** Send a request without serializing other in-flight requests. */
12702
+ request(operation, value, signal, transfer = []) {
12703
+ if (this.failure)
12704
+ return Promise.reject(this.failure.reason);
12705
+ if (signal == null ? void 0 : signal.aborted)
12706
+ return Promise.reject(signal.reason);
12707
+ const id = this.nextId++;
12708
+ return new Promise((resolve, reject) => {
12709
+ const abort = () => {
12710
+ const pending2 = this.pending.get(id);
12711
+ if (!pending2)
12712
+ return;
12713
+ this.pending.delete(id);
12714
+ pending2.cleanup();
12715
+ reject(signal == null ? void 0 : signal.reason);
12716
+ this.send({ source: "math.gl/tasks", kind: "cancel", id });
12717
+ };
12718
+ this.pending.set(id, {
12719
+ resolve,
12720
+ reject,
12721
+ cleanup: () => signal == null ? void 0 : signal.removeEventListener("abort", abort)
12722
+ });
12723
+ signal == null ? void 0 : signal.addEventListener("abort", abort, { once: true });
12724
+ this.send({ source: "math.gl/tasks", kind: "request", id, operation, value }, transfer);
12725
+ });
12726
+ }
12727
+ /** Send a one-way notification. */
12728
+ emit(operation, value, transfer = []) {
12729
+ if (this.failure)
12730
+ throw this.failure.reason;
12731
+ this.send({ source: "math.gl/tasks", kind: "event", id: 0, operation, value }, transfer);
12732
+ }
12733
+ /** Dispatch a transport message; unrelated protocols are ignored. */
12734
+ receive(message) {
12735
+ var _a5, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
12736
+ if (this.failure || (message == null ? void 0 : message.source) !== "math.gl/tasks")
12737
+ return;
12738
+ if (message.kind === "failure") {
12739
+ const reason = new Error(((_a5 = message.error) == null ? void 0 : _a5.message) ?? "Task channel failed");
12740
+ this.close(reason);
12741
+ (_c2 = (_b2 = this.options).onFailure) == null ? void 0 : _c2.call(_b2, reason);
12742
+ } else if (message.kind === "result" || message.kind === "error") {
12743
+ const pending2 = this.pending.get(message.id);
12744
+ if (!pending2)
12745
+ return;
12746
+ this.pending.delete(message.id);
12747
+ pending2.cleanup();
12748
+ if (message.kind === "result")
12749
+ pending2.resolve(message.value);
12750
+ else {
12751
+ const error = new TaskRequestError(((_d2 = message.error) == null ? void 0 : _d2.message) ?? "Task request failed");
12752
+ error.name = ((_e2 = message.error) == null ? void 0 : _e2.name) ?? "Error";
12753
+ pending2.reject(error);
12754
+ }
12755
+ } else if (message.kind === "cancel") {
12756
+ (_f2 = this.incoming.get(message.id)) == null ? void 0 : _f2.abort(new DOMException("Task request cancelled", "AbortError"));
12757
+ } else if (message.kind === "event") {
12758
+ try {
12759
+ (_h2 = (_g2 = this.options).handleEvent) == null ? void 0 : _h2.call(_g2, message.operation, message.value);
12760
+ } catch (error) {
12761
+ this.fail(error);
12762
+ }
12763
+ } else if (message.kind === "request") {
12764
+ if (this.incoming.has(message.id)) {
12765
+ this.fail(new Error("Duplicate task request identifier"));
12766
+ return;
12767
+ }
12768
+ const controller = new AbortController();
12769
+ this.incoming.set(message.id, controller);
12770
+ void Promise.resolve().then(() => {
12771
+ controller.signal.throwIfAborted();
12772
+ return this.options.handleRequest(message.operation, message.value, controller.signal);
12773
+ }).then((value) => {
12774
+ var _a6, _b3;
12775
+ if (!controller.signal.aborted && !this.failure) {
12776
+ this.send({ source: "math.gl/tasks", kind: "result", id: message.id, value }, (_b3 = (_a6 = this.options).getResultTransferList) == null ? void 0 : _b3.call(_a6, value, message.value));
12777
+ }
12778
+ }).catch((reason) => {
12779
+ if (!controller.signal.aborted && !this.failure) {
12780
+ this.send({
12781
+ source: "math.gl/tasks",
12782
+ kind: "error",
12783
+ id: message.id,
12784
+ error: {
12785
+ name: reason instanceof Error ? reason.name : "Error",
12786
+ message: reason instanceof Error ? reason.message : String(reason)
12787
+ }
12788
+ });
12789
+ }
12790
+ }).finally(() => this.incoming.delete(message.id));
12791
+ }
12792
+ }
12793
+ /** Reject all outstanding calls with a common cause and abort incoming callbacks. */
12794
+ close(reason = new Error("Task channel closed")) {
12795
+ if (this.failure)
12796
+ return;
12797
+ this.failure = { reason };
12798
+ for (const pending2 of this.pending.values()) {
12799
+ pending2.cleanup();
12800
+ pending2.reject(reason);
12801
+ }
12802
+ this.pending.clear();
12803
+ for (const controller of this.incoming.values())
12804
+ controller.abort(reason);
12805
+ this.incoming.clear();
12806
+ }
12807
+ send(message, transfer = []) {
12808
+ if (this.failure)
12809
+ return;
12810
+ try {
12811
+ this.options.send(message, transfer);
12812
+ } catch (error) {
12813
+ this.fail(error);
12814
+ }
12815
+ }
12816
+ /** Invalidate the channel and notify the peer when the transport still works. */
12817
+ fail(reason) {
12818
+ var _a5, _b2;
12819
+ if (this.failure)
12820
+ return;
12821
+ this.close(reason);
12822
+ try {
12823
+ this.options.send({
12824
+ source: "math.gl/tasks",
12825
+ kind: "failure",
12826
+ id: 0,
12827
+ error: {
12828
+ name: reason instanceof Error ? reason.name : "Error",
12829
+ message: reason instanceof Error ? reason.message : String(reason)
12830
+ }
12831
+ }, []);
12832
+ } catch {
12833
+ }
12834
+ (_b2 = (_a5 = this.options).onFailure) == null ? void 0 : _b2.call(_a5, reason);
12835
+ }
12836
+ };
12837
+
12838
+ // ../../node_modules/@math.gl/tasks/dist/tasks/task-runtime.js
12692
12839
  function assertPayload(value) {
12693
12840
  if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) {
12694
12841
  throw new TypeError("Task payloads must be plain objects with named fields");
@@ -12710,6 +12857,17 @@ function taskContext(state, context = {}) {
12710
12857
  return {
12711
12858
  state,
12712
12859
  signal,
12860
+ requestHost: async (operation, payload, controls) => {
12861
+ signal.throwIfAborted();
12862
+ if (!context.requestHost)
12863
+ throw new Error("No host request handler configured");
12864
+ return context.requestHost(operation, payload, controls);
12865
+ },
12866
+ emitHost: (operation, payload) => {
12867
+ var _a5;
12868
+ signal.throwIfAborted();
12869
+ (_a5 = context.emitHost) == null ? void 0 : _a5.call(context, operation, payload);
12870
+ },
12713
12871
  throwIfAborted: () => {
12714
12872
  var _a5;
12715
12873
  signal.throwIfAborted();
@@ -12780,6 +12938,70 @@ async function initializeTaskWorker(task) {
12780
12938
  throw new Error("A task is already installed in this worker");
12781
12939
  installed = true;
12782
12940
  const runtime = new TaskRuntime(task);
12941
+ let channelStream;
12942
+ const channel = new TaskChannel({
12943
+ getResultTransferList: (value, request) => request.outputOwnership === "transfer" ? getTransferList(value) : [],
12944
+ send: (message, transfer) => {
12945
+ const snapshot = structuredClone(message, { transfer });
12946
+ void WorkerBody.postMessage("task-channel", snapshot).catch((reason) => channel.fail(reason));
12947
+ },
12948
+ handleRequest: async (operation, value, signal) => {
12949
+ var _a5;
12950
+ const request = value;
12951
+ const context = {
12952
+ signal,
12953
+ reportProgress: (progress) => channel.emit("task:progress", { id: request.progressId, progress }),
12954
+ requestHost: (operation2, payload, controls = {}) => {
12955
+ const request2 = {
12956
+ operation: operation2,
12957
+ payload: clonePayload(payload, controls.inputOwnership),
12958
+ outputOwnership: controls.outputOwnership ?? "copy"
12959
+ };
12960
+ return channel.request("task:host-request", request2, signal, getTransferList(request2));
12961
+ },
12962
+ emitHost: (operation2, payload) => channel.emit("task:host-event", { operation: operation2, payload, id: request.progressId })
12963
+ };
12964
+ switch (operation) {
12965
+ case "initialize":
12966
+ return runtime.initialize(request.input, context);
12967
+ case "process":
12968
+ return runtime.process(request.input, request.options, context);
12969
+ case "stream-open": {
12970
+ if (channelStream)
12971
+ throw new Error("A task stream is already open");
12972
+ async function* inputs() {
12973
+ while (true) {
12974
+ const result = await channel.request("task:next-input", { outputOwnership: "transfer" }, signal);
12975
+ if (result.done)
12976
+ return;
12977
+ yield result.value;
12978
+ }
12979
+ }
12980
+ channelStream = runtime.stream(inputs(), request.options, context)[Symbol.asyncIterator]();
12981
+ return {};
12982
+ }
12983
+ case "stream-next":
12984
+ if (!channelStream)
12985
+ throw new Error("No active task stream");
12986
+ return channelStream.next();
12987
+ case "stream-close":
12988
+ try {
12989
+ await ((_a5 = channelStream == null ? void 0 : channelStream.return) == null ? void 0 : _a5.call(channelStream));
12990
+ } finally {
12991
+ channelStream = void 0;
12992
+ }
12993
+ return {};
12994
+ case "destroy":
12995
+ return runtime.destroy();
12996
+ default:
12997
+ throw new Error("Unknown task channel operation");
12998
+ }
12999
+ }
13000
+ });
13001
+ await WorkerBody.addEventListener((type, payload) => {
13002
+ if (type === "task-channel")
13003
+ channel.receive(payload);
13004
+ });
12783
13005
  let streamOptions = {};
12784
13006
  return createWorker(async (request, _options, context) => {
12785
13007
  switch (request.operation) {
@@ -12820,7 +13042,7 @@ function localContext(controls) {
12820
13042
  };
12821
13043
  }
12822
13044
 
12823
- // ../../node_modules/@math.gl/core/dist/tasks/task-sync.js
13045
+ // ../../node_modules/@math.gl/tasks/dist/tasks/task-sync.js
12824
13046
  function runTaskSync(task, input, request = {}) {
12825
13047
  var _a5, _b2;
12826
13048
  if (!isTaskCodeLoaded(task))
@@ -12905,19 +13127,158 @@ function isThenable(value) {
12905
13127
  return Boolean(value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function");
12906
13128
  }
12907
13129
 
12908
- // ../../node_modules/@math.gl/core/dist/tasks/task-runner.js
13130
+ // ../../node_modules/@math.gl/tasks/dist/tasks/task-operation-queue.js
13131
+ var TaskOperationQueue = class {
13132
+ constructor(maxConcurrency) {
13133
+ this.maxConcurrency = maxConcurrency;
13134
+ this.pending = [];
13135
+ this.active = 0;
13136
+ this.exclusive = false;
13137
+ this.closed = false;
13138
+ this.idleWaiters = /* @__PURE__ */ new Set();
13139
+ if (!Number.isSafeInteger(maxConcurrency) || maxConcurrency < 1) {
13140
+ throw new RangeError("maxConcurrency must be a positive safe integer");
13141
+ }
13142
+ }
13143
+ /** Queue an operation; aborting before it starts removes it without running it. */
13144
+ run(mode, operation, signal) {
13145
+ if (this.closed)
13146
+ return Promise.reject(new Error("Task operation queue is closed"));
13147
+ if (mode !== "parallel" && mode !== "exclusive")
13148
+ return Promise.reject(new TypeError("Invalid operation mode"));
13149
+ if (signal == null ? void 0 : signal.aborted)
13150
+ return Promise.reject(signal.reason);
13151
+ return new Promise((resolve, reject) => {
13152
+ const onAbort = () => {
13153
+ const index2 = this.pending.indexOf(entry);
13154
+ if (index2 >= 0) {
13155
+ this.pending.splice(index2, 1);
13156
+ entry.cancel(signal == null ? void 0 : signal.reason);
13157
+ this.pump();
13158
+ }
13159
+ };
13160
+ const entry = {
13161
+ mode,
13162
+ cancel: (reason) => {
13163
+ signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
13164
+ reject(reason);
13165
+ },
13166
+ start: () => {
13167
+ signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
13168
+ this.active++;
13169
+ if (mode === "exclusive")
13170
+ this.exclusive = true;
13171
+ void Promise.resolve().then(() => {
13172
+ signal == null ? void 0 : signal.throwIfAborted();
13173
+ return operation();
13174
+ }).then(resolve, reject).finally(() => {
13175
+ this.active--;
13176
+ if (mode === "exclusive")
13177
+ this.exclusive = false;
13178
+ this.pump();
13179
+ });
13180
+ }
13181
+ };
13182
+ this.pending.push(entry);
13183
+ signal == null ? void 0 : signal.addEventListener("abort", onAbort, { once: true });
13184
+ if (signal == null ? void 0 : signal.aborted)
13185
+ onAbort();
13186
+ else
13187
+ this.pump();
13188
+ });
13189
+ }
13190
+ /** Reject queued calls with one cause while allowing active operations to settle. */
13191
+ cancelPending(reason) {
13192
+ this.closed = true;
13193
+ for (const entry of this.pending.splice(0))
13194
+ entry.cancel(reason);
13195
+ this.pump();
13196
+ }
13197
+ /** Stop accepting new work; accepted operations continue to completion. */
13198
+ close() {
13199
+ this.closed = true;
13200
+ return this.whenIdle();
13201
+ }
13202
+ /** Wait until the queue has no running or waiting operations. */
13203
+ whenIdle() {
13204
+ if (!this.active && !this.pending.length)
13205
+ return Promise.resolve();
13206
+ return new Promise((resolve) => this.idleWaiters.add(resolve));
13207
+ }
13208
+ pump() {
13209
+ while (!this.exclusive && this.pending.length && this.active < this.maxConcurrency) {
13210
+ const entry = this.pending[0];
13211
+ if (entry.mode === "exclusive" && this.active)
13212
+ break;
13213
+ this.pending.shift();
13214
+ entry.start();
13215
+ if (entry.mode === "exclusive")
13216
+ break;
13217
+ }
13218
+ if (!this.active && !this.pending.length) {
13219
+ for (const resolve of this.idleWaiters)
13220
+ resolve();
13221
+ this.idleWaiters.clear();
13222
+ }
13223
+ }
13224
+ };
13225
+
13226
+ // ../../node_modules/@math.gl/tasks/dist/tasks/task-worker-channel.js
13227
+ var TaskWorkerChannel = class {
13228
+ constructor(name, target, options) {
13229
+ var _a5;
13230
+ this.thread = new WorkerThread({
13231
+ name,
13232
+ url: (_a5 = target.url) == null ? void 0 : _a5.toString(),
13233
+ loadWorker: target.create,
13234
+ workerType: "module"
13235
+ });
13236
+ this.channel = new TaskChannel({
13237
+ ...options,
13238
+ send: (message, transfer) => this.thread.postMessage({ source: "loaders.gl/tasks", type: "task-channel", payload: message }, transfer)
13239
+ });
13240
+ this.thread.onMessage = (message) => {
13241
+ if ((message == null ? void 0 : message.type) === "task-channel")
13242
+ this.channel.receive(message.payload);
13243
+ };
13244
+ this.thread.onError = (reason) => {
13245
+ var _a6;
13246
+ this.channel.close(reason);
13247
+ (_a6 = options.onFailure) == null ? void 0 : _a6.call(options, reason);
13248
+ };
13249
+ }
13250
+ /** Settle pending calls and terminate the worker without replacing its state. */
13251
+ async destroy(reason) {
13252
+ this.channel.close(reason);
13253
+ await this.thread.destroy();
13254
+ }
13255
+ };
13256
+
13257
+ // ../../node_modules/@math.gl/tasks/dist/tasks/task-runner.js
12909
13258
  var InitializedTask = class {
12910
13259
  /** @internal Use TaskRunner.initializeTask. */
12911
- constructor(task, release, controls) {
12912
- var _a5, _b2;
13260
+ constructor(task, release, initializationControls) {
13261
+ var _a5, _b2, _c2;
12913
13262
  this.task = task;
12914
13263
  this.release = release;
12915
- this.tail = Promise.resolve();
13264
+ this.initializationControls = initializationControls;
13265
+ this.nextProgressId = 1;
13266
+ this.progressCallbacks = /* @__PURE__ */ new Map();
13267
+ this.callbackFailures = /* @__PURE__ */ new Map();
12916
13268
  this.closed = false;
13269
+ this.finalized = false;
12917
13270
  this.streams = /* @__PURE__ */ new Set();
12918
13271
  this.invalid = false;
12919
13272
  this.controller = new AbortController();
13273
+ const controls = initializationControls;
12920
13274
  this.runtime = new TaskRuntime(task);
13275
+ const concurrency2 = controls.operationConcurrency ?? 1;
13276
+ const maximum = ((_a5 = task.concurrency) == null ? void 0 : _a5.maxConcurrency) ?? 1;
13277
+ if (!Number.isSafeInteger(maximum) || maximum < 1 || !Number.isSafeInteger(concurrency2) || concurrency2 < 1 || concurrency2 > maximum) {
13278
+ throw new RangeError("Task concurrency must be between 1 and the task maximum");
13279
+ }
13280
+ this.operationQueue = new TaskOperationQueue(concurrency2);
13281
+ this.concurrent = concurrency2 > 1;
12921
13282
  const execution = controls.execution ?? "auto";
12922
13283
  if (!["auto", "main-thread", "worker"].includes(execution))
12923
13284
  throw new TypeError("Invalid execution mode");
@@ -12927,9 +13288,51 @@ var InitializedTask = class {
12927
13288
  const target = task.worker;
12928
13289
  if (Boolean(target.url) === Boolean(target.create))
12929
13290
  throw new Error("Supply exactly one worker URL or factory");
13291
+ if (this.concurrent || controls.onRequest || controls.onEvent) {
13292
+ this.workerChannel = new TaskWorkerChannel(task.id, target, {
13293
+ handleRequest: async (operation, payload, signal) => {
13294
+ if (operation === "task:next-input") {
13295
+ if (!this.channelInputs)
13296
+ throw new Error("No active task stream");
13297
+ return this.channelInputs.next();
13298
+ }
13299
+ if (!controls.onRequest)
13300
+ throw new Error("No host request handler configured");
13301
+ const request = payload;
13302
+ if (operation !== "task:host-request")
13303
+ throw new Error("Unknown host request");
13304
+ return controls.onRequest(request.operation, request.payload, signal);
13305
+ },
13306
+ getResultTransferList: (value, request) => request.outputOwnership === "transfer" ? getTransferList(value) : [],
13307
+ handleEvent: (operation, payload) => {
13308
+ var _a6, _b3;
13309
+ const { id } = payload;
13310
+ try {
13311
+ if (operation === "task:progress") {
13312
+ const event = payload;
13313
+ (_a6 = this.progressCallbacks.get(event.id) ?? this.streamProgress) == null ? void 0 : _a6(event.progress);
13314
+ } else if (operation === "task:host-event") {
13315
+ const event = payload;
13316
+ (_b3 = controls.onEvent) == null ? void 0 : _b3.call(controls, event.operation, event.payload);
13317
+ }
13318
+ } catch (reason) {
13319
+ if (this.progressCallbacks.has(id) || this.streamProgressId === id) {
13320
+ if (!this.callbackFailures.has(id))
13321
+ this.callbackFailures.set(id, { reason });
13322
+ }
13323
+ }
13324
+ },
13325
+ onFailure: (reason) => {
13326
+ this.invalid = true;
13327
+ this.operationQueue.cancelPending(reason);
13328
+ this.controller.abort(reason);
13329
+ }
13330
+ });
13331
+ return;
13332
+ }
12930
13333
  this.pool = new WorkerPool({
12931
13334
  name: task.id,
12932
- url: (_a5 = target.url) == null ? void 0 : _a5.toString(),
13335
+ url: (_b2 = target.url) == null ? void 0 : _b2.toString(),
12933
13336
  loadWorker: target.create,
12934
13337
  workerType: "module",
12935
13338
  maxConcurrency: 1,
@@ -12938,10 +13341,10 @@ var InitializedTask = class {
12938
13341
  this.descriptor = {
12939
13342
  id: task.id,
12940
13343
  name: task.id,
12941
- module: "core",
13344
+ module: "tasks",
12942
13345
  version: "prototype",
12943
13346
  options: {},
12944
- worker: ((_b2 = target.url) == null ? void 0 : _b2.toString()) ?? true,
13347
+ worker: ((_c2 = target.url) == null ? void 0 : _c2.toString()) ?? true,
12945
13348
  loadWorker: target.create,
12946
13349
  workerInBatches: target.capabilities.streaming
12947
13350
  };
@@ -12958,40 +13361,92 @@ var InitializedTask = class {
12958
13361
  }
12959
13362
  }
12960
13363
  runTask(input, ...args) {
12961
- return this.enqueue(async () => {
12962
- var _a5;
13364
+ var _a5, _b2, _c2, _d2, _e2;
13365
+ if (this.invalid)
13366
+ return Promise.reject(new Error("Initialized task is invalid; initialize a new instance"));
13367
+ if (this.closed)
13368
+ return Promise.reject(new Error("Initialized task is closed"));
13369
+ const timeout2 = (_a5 = args[0]) == null ? void 0 : _a5.timeout;
13370
+ if (timeout2 !== void 0 && (!Number.isSafeInteger(timeout2) || timeout2 < 0 || timeout2 > 4294967295)) {
13371
+ return Promise.reject(new RangeError("Invalid task timeout"));
13372
+ }
13373
+ const deadline = timeout2 === void 0 ? void 0 : AbortSignal.timeout(timeout2);
13374
+ const signal = deadline && ((_b2 = args[0]) == null ? void 0 : _b2.signal) ? AbortSignal.any([deadline, args[0].signal]) : deadline ?? ((_c2 = args[0]) == null ? void 0 : _c2.signal);
13375
+ const controls = { ...args[0], signal };
13376
+ const mode = ((_e2 = (_d2 = this.task.concurrency) == null ? void 0 : _d2.getSchedulingMode) == null ? void 0 : _e2.call(_d2, input)) ?? "exclusive";
13377
+ return this.operationQueue.run(mode, async () => {
13378
+ var _a6;
13379
+ signal == null ? void 0 : signal.throwIfAborted();
12963
13380
  this.checkCapability("atomic");
12964
- return this.invoke("process", input, ((_a5 = args[0]) == null ? void 0 : _a5.options) ?? {}, args[0]);
12965
- });
13381
+ const invalidate = () => {
13382
+ if (this.concurrent) {
13383
+ this.invalid = true;
13384
+ this.operationQueue.cancelPending(signal == null ? void 0 : signal.reason);
13385
+ this.controller.abort(signal == null ? void 0 : signal.reason);
13386
+ }
13387
+ };
13388
+ signal == null ? void 0 : signal.addEventListener("abort", invalidate, { once: true });
13389
+ try {
13390
+ return await this.invoke("process", input, ((_a6 = args[0]) == null ? void 0 : _a6.options) ?? {}, controls);
13391
+ } finally {
13392
+ signal == null ? void 0 : signal.removeEventListener("abort", invalidate);
13393
+ }
13394
+ }, signal);
12966
13395
  }
12967
13396
  /** Independent calls sharing this instance, always serial and in input order. */
12968
- async *runTasks(inputs, ...args) {
12969
- yield* this.serialStream(async function* (self2) {
12970
- var _a5;
13397
+ runTasks(inputs, ...args) {
13398
+ var _a5;
13399
+ return this.serialStream(async function* (self2) {
13400
+ var _a6;
12971
13401
  self2.checkCapability("atomic");
12972
13402
  for await (const input of asAsync(inputs, self2.controls(args[0]).signal)) {
12973
- yield await self2.invoke("process", input, ((_a5 = args[0]) == null ? void 0 : _a5.options) ?? {}, args[0]);
13403
+ yield await self2.invoke("process", input, ((_a6 = args[0]) == null ? void 0 : _a6.options) ?? {}, args[0]);
12974
13404
  }
12975
- });
13405
+ }, (_a5 = args[0]) == null ? void 0 : _a5.signal);
12976
13406
  }
12977
13407
  /** One processor invocation for the entire input iterable. */
12978
- async *runTaskInBatches(inputs, ...args) {
12979
- yield* this.serialStream(async function* (self2) {
12980
- var _a5, _b2;
13408
+ runTaskInBatches(inputs, ...args) {
13409
+ var _a5;
13410
+ return this.serialStream(async function* (self2) {
13411
+ var _a6, _b2, _c2, _d2;
12981
13412
  self2.checkCapability("streaming");
12982
13413
  const controls = self2.controls(args[0]);
12983
- const options = clonePayload(((_a5 = args[0]) == null ? void 0 : _a5.options) ?? {});
13414
+ const options = clonePayload(((_a6 = args[0]) == null ? void 0 : _a6.options) ?? {});
12984
13415
  async function* prepared() {
12985
- var _a6, _b3;
13416
+ var _a7, _b3;
12986
13417
  for await (const input of asAsync(inputs, controls.signal)) {
12987
- (_a6 = controls.signal) == null ? void 0 : _a6.throwIfAborted();
13418
+ (_a7 = controls.signal) == null ? void 0 : _a7.throwIfAborted();
12988
13419
  assertNoTransferAlias(input, ((_b3 = args[0]) == null ? void 0 : _b3.options) ?? {}, controls.inputOwnership);
12989
13420
  yield clonePayload(input, controls.inputOwnership);
12990
13421
  }
12991
13422
  }
12992
13423
  let completed = false;
12993
13424
  try {
12994
- if (self2.pool) {
13425
+ if (self2.workerChannel) {
13426
+ self2.channelInputs = prepared()[Symbol.asyncIterator]();
13427
+ self2.streamProgress = controls.onProgress;
13428
+ try {
13429
+ await self2.invoke("stream-open", {}, options, controls);
13430
+ while (true) {
13431
+ const result = await self2.invoke("stream-next", {}, {}, controls);
13432
+ if (result.done)
13433
+ break;
13434
+ yield result.value;
13435
+ }
13436
+ } finally {
13437
+ try {
13438
+ if (!self2.invalid)
13439
+ await self2.invoke("stream-close", {}, {}, controls);
13440
+ } finally {
13441
+ await ((_c2 = (_b2 = self2.channelInputs).return) == null ? void 0 : _c2.call(_b2));
13442
+ self2.channelInputs = void 0;
13443
+ self2.streamProgress = void 0;
13444
+ if (self2.streamProgressId !== void 0)
13445
+ self2.callbackFailures.delete(self2.streamProgressId);
13446
+ self2.streamProgressId = void 0;
13447
+ }
13448
+ }
13449
+ } else if (self2.pool) {
12995
13450
  await self2.invoke("stream-options", {}, options, controls);
12996
13451
  yield* processOnWorkerInBatches(self2.descriptor, prepared(), {
12997
13452
  ...self2.workerOptions(controls),
@@ -12999,13 +13454,19 @@ var InitializedTask = class {
12999
13454
  workerInBatches: true
13000
13455
  });
13001
13456
  } else {
13002
- for await (const output of self2.runtime.stream(prepared(), options, localContext(controls))) {
13003
- (_b2 = controls.signal) == null ? void 0 : _b2.throwIfAborted();
13457
+ for await (const output of self2.runtime.stream(prepared(), options, self2.runtimeContext(controls))) {
13458
+ (_d2 = controls.signal) == null ? void 0 : _d2.throwIfAborted();
13004
13459
  yield clonePayload(output, controls.outputOwnership ?? "transfer");
13005
13460
  }
13006
13461
  }
13007
13462
  completed = true;
13008
13463
  } catch (error) {
13464
+ if (self2.workerChannel) {
13465
+ self2.invalid = true;
13466
+ self2.operationQueue.cancelPending(error);
13467
+ self2.controller.abort(error);
13468
+ await self2.workerChannel.destroy(error);
13469
+ }
13009
13470
  if (self2.pool) {
13010
13471
  self2.invalid = true;
13011
13472
  await self2.pool.destroy(error);
@@ -13014,23 +13475,42 @@ var InitializedTask = class {
13014
13475
  } finally {
13015
13476
  if (self2.pool && !completed)
13016
13477
  self2.invalid = true;
13478
+ if (self2.workerChannel && !completed && !self2.invalid) {
13479
+ const reason = new Error("Worker stream ended before completion");
13480
+ self2.invalid = true;
13481
+ self2.operationQueue.cancelPending(reason);
13482
+ self2.controller.abort(reason);
13483
+ await self2.workerChannel.destroy(reason);
13484
+ }
13017
13485
  }
13018
- });
13486
+ }, (_a5 = args[0]) == null ? void 0 : _a5.signal);
13487
+ }
13488
+ /** Lifecycle status of this initialized task. */
13489
+ get state() {
13490
+ if (this.invalid)
13491
+ return "invalid";
13492
+ if (this.finalized)
13493
+ return "closed";
13494
+ return this.closed ? "closing" : "ready";
13019
13495
  }
13020
13496
  /** Drain accepted work, invoke destroy, and release execution capacity. */
13021
13497
  close() {
13022
13498
  if (!this.closing) {
13023
13499
  this.closed = true;
13024
13500
  this.closing = (async () => {
13025
- var _a5;
13501
+ var _a5, _b2;
13026
13502
  try {
13027
- await this.tail;
13503
+ await this.operationQueue.close();
13028
13504
  if (!this.invalid)
13029
13505
  await this.invoke("destroy", {}, {});
13506
+ else if (!this.pool && !this.workerChannel)
13507
+ await this.runtime.destroy();
13030
13508
  } finally {
13031
13509
  try {
13032
13510
  await ((_a5 = this.pool) == null ? void 0 : _a5.destroy());
13511
+ await ((_b2 = this.workerChannel) == null ? void 0 : _b2.destroy());
13033
13512
  } finally {
13513
+ this.finalized = true;
13034
13514
  this.release();
13035
13515
  }
13036
13516
  }
@@ -13040,7 +13520,12 @@ var InitializedTask = class {
13040
13520
  }
13041
13521
  /** Abort work. Local JavaScript must settle before its state can be destroyed. */
13042
13522
  async terminate(reason = new Error("Task terminated")) {
13523
+ this.operationQueue.cancelPending(reason);
13043
13524
  this.controller.abort(reason);
13525
+ if (this.workerChannel) {
13526
+ this.invalid = true;
13527
+ await this.workerChannel.destroy(reason);
13528
+ }
13044
13529
  if (this.pool) {
13045
13530
  this.invalid = true;
13046
13531
  await this.pool.destroy(reason);
@@ -13050,7 +13535,7 @@ var InitializedTask = class {
13050
13535
  }
13051
13536
  checkCapability(kind) {
13052
13537
  var _a5;
13053
- if (this.pool ? !((_a5 = this.task.worker) == null ? void 0 : _a5.capabilities[kind]) : !(kind === "atomic" ? this.task.process : this.task.processInBatches)) {
13538
+ if (this.pool || this.workerChannel ? !((_a5 = this.task.worker) == null ? void 0 : _a5.capabilities[kind]) : !(kind === "atomic" ? this.task.process : this.task.processInBatches)) {
13054
13539
  throw new Error(`Task has no ${kind} processor for this execution route`);
13055
13540
  }
13056
13541
  }
@@ -13074,7 +13559,7 @@ var InitializedTask = class {
13074
13559
  };
13075
13560
  }
13076
13561
  async invoke(operation, input, options, controls = {}) {
13077
- var _a5, _b2, _c2;
13562
+ var _a5, _b2, _c2, _d2;
13078
13563
  if (this.invalid)
13079
13564
  throw new Error("Initialized task is invalid; initialize a new instance");
13080
13565
  const prepared = operation === "destroy" ? {} : this.controls(controls);
@@ -13082,6 +13567,38 @@ var InitializedTask = class {
13082
13567
  assertPayload(input);
13083
13568
  assertNoTransferAlias(input, options, prepared.inputOwnership);
13084
13569
  const copiedOptions = clonePayload(options);
13570
+ if (this.workerChannel) {
13571
+ const progressId = this.nextProgressId++;
13572
+ const request = {
13573
+ input: clonePayload(input, prepared.inputOwnership),
13574
+ options: copiedOptions,
13575
+ outputOwnership: prepared.outputOwnership ?? "transfer",
13576
+ progressId
13577
+ };
13578
+ if (operation === "stream-open")
13579
+ this.streamProgressId = progressId;
13580
+ this.progressCallbacks.set(progressId, prepared.onProgress);
13581
+ let callbackFailure;
13582
+ try {
13583
+ const result2 = await this.workerChannel.channel.request(operation, request, prepared.signal, getTransferList(request));
13584
+ callbackFailure = this.callbackFailures.get(progressId) ?? (operation.startsWith("stream-") && this.streamProgressId !== void 0 ? this.callbackFailures.get(this.streamProgressId) : void 0);
13585
+ if (callbackFailure)
13586
+ throw callbackFailure.reason;
13587
+ return result2;
13588
+ } catch (reason) {
13589
+ if (operation === "process" && !((_b2 = prepared.signal) == null ? void 0 : _b2.aborted) && (reason instanceof TaskRequestError || callbackFailure))
13590
+ throw reason;
13591
+ this.invalid = true;
13592
+ this.operationQueue.cancelPending(reason);
13593
+ this.controller.abort(reason);
13594
+ await this.workerChannel.destroy(reason);
13595
+ throw reason;
13596
+ } finally {
13597
+ this.progressCallbacks.delete(progressId);
13598
+ if (this.streamProgressId !== progressId)
13599
+ this.callbackFailures.delete(progressId);
13600
+ }
13601
+ }
13085
13602
  if (this.pool) {
13086
13603
  try {
13087
13604
  return await processOnWorker(this.descriptor, { operation, input: clonePayload(input, prepared.inputOwnership), options: copiedOptions }, this.workerOptions({ ...prepared, inputOwnership: "transfer" }));
@@ -13094,37 +13611,89 @@ var InitializedTask = class {
13094
13611
  if (operation === "destroy")
13095
13612
  return this.runtime.destroy();
13096
13613
  const copied = clonePayload(input, prepared.inputOwnership);
13097
- const context = localContext(prepared);
13614
+ const context = this.runtimeContext(prepared);
13098
13615
  if (operation === "initialize") {
13099
13616
  const result2 = await this.runtime.initialize(copied, context);
13100
- (_b2 = prepared.signal) == null ? void 0 : _b2.throwIfAborted();
13617
+ (_c2 = prepared.signal) == null ? void 0 : _c2.throwIfAborted();
13101
13618
  return result2;
13102
13619
  }
13103
13620
  const result = await this.runtime.process(copied, copiedOptions, context);
13104
- (_c2 = prepared.signal) == null ? void 0 : _c2.throwIfAborted();
13621
+ (_d2 = prepared.signal) == null ? void 0 : _d2.throwIfAborted();
13105
13622
  return clonePayload(result, prepared.outputOwnership ?? "transfer");
13106
13623
  }
13624
+ runtimeContext(prepared) {
13625
+ return {
13626
+ ...localContext(prepared),
13627
+ requestHost: async (operation, payload, controls = {}) => {
13628
+ const signal = prepared.signal ?? this.controller.signal;
13629
+ signal.throwIfAborted();
13630
+ const handler = this.initializationControls.onRequest;
13631
+ if (!handler)
13632
+ throw new Error("No host request handler configured");
13633
+ const result = await handler(operation, clonePayload(payload, controls.inputOwnership), signal);
13634
+ signal.throwIfAborted();
13635
+ return structuredClone(result, {
13636
+ transfer: controls.outputOwnership === "transfer" ? getTransferList(result) : []
13637
+ });
13638
+ },
13639
+ emitHost: (operation, payload) => {
13640
+ var _a5, _b2;
13641
+ return (_b2 = (_a5 = this.initializationControls).onEvent) == null ? void 0 : _b2.call(_a5, operation, structuredClone(payload));
13642
+ }
13643
+ };
13644
+ }
13107
13645
  enqueue(operation) {
13108
13646
  if (this.closed)
13109
13647
  return Promise.reject(new Error("Initialized task is closed"));
13110
- const result = this.tail.then(operation);
13111
- this.tail = result.catch(() => {
13648
+ return this.operationQueue.run("exclusive", operation);
13649
+ }
13650
+ serialStream(operation, signal) {
13651
+ const waiting = new AbortController();
13652
+ const queueSignal = AbortSignal.any([waiting.signal, this.controller.signal, signal].filter((value) => Boolean(value)));
13653
+ let started = false;
13654
+ const iterator = this.acquireStream(operation, queueSignal, () => {
13655
+ started = true;
13112
13656
  });
13113
- return result;
13657
+ const cancelWaiting = () => {
13658
+ if (!started)
13659
+ waiting.abort(new Error("Stream returned before execution"));
13660
+ };
13661
+ return {
13662
+ [Symbol.asyncIterator]() {
13663
+ return this;
13664
+ },
13665
+ next: () => iterator.next(),
13666
+ return: async () => {
13667
+ cancelWaiting();
13668
+ return iterator.return(void 0);
13669
+ },
13670
+ throw: async (reason) => {
13671
+ cancelWaiting();
13672
+ return iterator.throw(reason);
13673
+ }
13674
+ };
13114
13675
  }
13115
- async *serialStream(operation) {
13676
+ async *acquireStream(operation, signal, onStart) {
13116
13677
  if (this.closed)
13117
13678
  throw new Error("Initialized task is closed");
13118
- const before = this.tail;
13679
+ let acquire;
13680
+ const acquired = new Promise((resolve) => {
13681
+ acquire = resolve;
13682
+ });
13119
13683
  let release;
13120
- this.tail = new Promise((resolve) => {
13684
+ const held = new Promise((resolve) => {
13121
13685
  release = resolve;
13122
13686
  });
13123
- await before;
13124
- if (this.controller.signal.aborted) {
13687
+ const lease = this.operationQueue.run("exclusive", async () => {
13688
+ acquire();
13689
+ await held;
13690
+ }, signal);
13691
+ await Promise.race([acquired, lease]);
13692
+ if (signal.aborted) {
13125
13693
  release();
13126
- throw this.controller.signal.reason;
13694
+ throw signal.reason;
13127
13695
  }
13696
+ onStart();
13128
13697
  const iterator = operation(this)[Symbol.asyncIterator]();
13129
13698
  let stopping;
13130
13699
  const stop = () => {
@@ -13449,22 +14018,6 @@ function assertNoTransferAlias(input, options, ownership) {
13449
14018
  }
13450
14019
  }
13451
14020
 
13452
- // ../core/src/worker-utils/lib/worker-api/task-runtime.ts
13453
- function normalizeTaskProgress(progress) {
13454
- return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
13455
- }
13456
- async function isWorkerThread() {
13457
- var _a5;
13458
- if (typeof self !== "undefined" && typeof document === "undefined" && typeof self.postMessage === "function")
13459
- return true;
13460
- if (typeof process !== "undefined" && ((_a5 = process.versions) == null ? void 0 : _a5.node)) {
13461
- const { isMainThread: isMainThread2 } = await Promise.resolve().then(() => (init_worker_threads(), worker_threads_exports));
13462
- return !isMainThread2;
13463
- }
13464
- return false;
13465
- }
13466
- var initializeTaskWorker2 = initializeTaskWorker;
13467
-
13468
14021
  // ../core/src/worker-utils/lib/worker-api/get-worker-url.ts
13469
14022
  var warnedWorkerVersionFallbacks2 = /* @__PURE__ */ new Set();
13470
14023
  function getCustomWorkerURL2(worker, options = {}) {
@@ -13521,6 +14074,22 @@ function warnIfUsingNpmTagFallback2(worker, url) {
13521
14074
  );
13522
14075
  }
13523
14076
 
14077
+ // ../core/src/worker-utils/lib/worker-api/task-runtime.ts
14078
+ function normalizeTaskProgress(progress) {
14079
+ return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
14080
+ }
14081
+ async function isWorkerThread() {
14082
+ var _a5;
14083
+ if (typeof self !== "undefined" && typeof document === "undefined" && typeof self.postMessage === "function")
14084
+ return true;
14085
+ if (typeof process !== "undefined" && ((_a5 = process.versions) == null ? void 0 : _a5.node)) {
14086
+ const { isMainThread: isMainThread2 } = await Promise.resolve().then(() => (init_worker_threads(), worker_threads_exports));
14087
+ return !isMainThread2;
14088
+ }
14089
+ return false;
14090
+ }
14091
+ var initializeTaskWorker2 = initializeTaskWorker;
14092
+
13524
14093
  // ../core/src/worker-utils/lib/worker-utils/get-transfer-list.ts
13525
14094
  function getTransferList2(object2, recursive = true, transfers) {
13526
14095
  const transfersSet = transfers || /* @__PURE__ */ new Set();
@@ -28695,7 +29264,7 @@ function getLibraryCacheKey2(type, options) {
28695
29264
  }
28696
29265
 
28697
29266
  // src/draco/lib/utils/version.ts
28698
- var VERSION3 = true ? "5.0.0-beta.4" : "latest";
29267
+ var VERSION3 = true ? "5.0.0-beta.5" : "latest";
28699
29268
 
28700
29269
  // src/draco/draco-format.ts
28701
29270
  var DracoFormat = {