@loaders.gl/raster 5.0.0-beta.1 → 5.0.0-beta.11

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 (226) hide show
  1. package/README.md +9 -5
  2. package/THIRD-PARTY-NOTICES.md +1 -1
  3. package/dist/geotiff/advanced.cjs +153 -105
  4. package/dist/geotiff/advanced.cjs.map +4 -4
  5. package/dist/geotiff/advanced.d.ts +4 -3
  6. package/dist/geotiff/advanced.d.ts.map +1 -1
  7. package/dist/geotiff/advanced.js +3 -2
  8. package/dist/geotiff/advanced.js.map +1 -1
  9. package/dist/geotiff/geotiff-loader-types.d.ts +14 -3
  10. package/dist/geotiff/geotiff-loader-types.d.ts.map +1 -1
  11. package/dist/geotiff/geotiff-loader-types.js +12 -2
  12. package/dist/geotiff/geotiff-loader-types.js.map +1 -1
  13. package/dist/geotiff/geotiff-loader.d.ts +9 -8
  14. package/dist/geotiff/geotiff-loader.d.ts.map +1 -1
  15. package/dist/geotiff/geotiff-loader.js +2 -0
  16. package/dist/geotiff/geotiff-loader.js.map +1 -1
  17. package/dist/geotiff/geotiff-raster-loader-types.d.ts.map +1 -1
  18. package/dist/geotiff/geotiff-raster-loader-types.js +2 -2
  19. package/dist/geotiff/geotiff-raster-loader-types.js.map +1 -1
  20. package/dist/geotiff/geotiff-source-loader.d.ts +2 -34
  21. package/dist/geotiff/geotiff-source-loader.d.ts.map +1 -1
  22. package/dist/geotiff/geotiff-source-loader.js +14 -36
  23. package/dist/geotiff/geotiff-source-loader.js.map +1 -1
  24. package/dist/geotiff/lib/ome/load-ome-tiff.d.ts +1 -0
  25. package/dist/geotiff/lib/ome/load-ome-tiff.d.ts.map +1 -1
  26. package/dist/geotiff/lib/ome/load-ome-tiff.js +7 -1
  27. package/dist/geotiff/lib/ome/load-ome-tiff.js.map +1 -1
  28. package/dist/geotiff/lib/ome/omexml.d.ts.map +1 -1
  29. package/dist/geotiff/lib/ome/omexml.js +5 -4
  30. package/dist/geotiff/lib/ome/omexml.js.map +1 -1
  31. package/dist/geotiff/lib/tiff/tiff-gdal-metadata.d.ts.map +1 -1
  32. package/dist/geotiff/lib/tiff/tiff-gdal-metadata.js +6 -5
  33. package/dist/geotiff/lib/tiff/tiff-gdal-metadata.js.map +1 -1
  34. package/dist/geotiff/lib/tiff-pixel-source.d.ts.map +1 -1
  35. package/dist/geotiff/lib/tiff-pixel-source.js +2 -1
  36. package/dist/geotiff/lib/tiff-pixel-source.js.map +1 -1
  37. package/dist/geotiff/loaders.js +1 -1
  38. package/dist/geotiff/loaders.js.map +1 -1
  39. package/dist/geotiff/{ometiff-source-loader-types.d.ts → ometiff-loader-types.d.ts} +7 -7
  40. package/dist/geotiff/ometiff-loader-types.d.ts.map +1 -0
  41. package/dist/geotiff/{ometiff-source-loader-types.js → ometiff-loader-types.js} +6 -6
  42. package/dist/geotiff/ometiff-loader-types.js.map +1 -0
  43. package/dist/geotiff/{ometiff-source-loader.d.ts → ometiff-loader.d.ts} +6 -6
  44. package/dist/geotiff/ometiff-loader.d.ts.map +1 -0
  45. package/dist/geotiff/{ometiff-source-loader.js → ometiff-loader.js} +5 -5
  46. package/dist/geotiff/ometiff-loader.js.map +1 -0
  47. package/dist/geotiff-loader-types.d.ts +2 -0
  48. package/dist/geotiff-loader-types.d.ts.map +1 -0
  49. package/dist/geotiff-loader-types.js +2 -0
  50. package/dist/geotiff-loader-types.js.map +1 -0
  51. package/dist/geotiff-loader.d.ts +2 -0
  52. package/dist/geotiff-loader.d.ts.map +1 -0
  53. package/dist/geotiff-loader.js +2 -0
  54. package/dist/geotiff-loader.js.map +1 -0
  55. package/dist/geotiff-raster-loader-types.d.ts +2 -0
  56. package/dist/geotiff-raster-loader-types.d.ts.map +1 -0
  57. package/dist/geotiff-raster-loader-types.js +2 -0
  58. package/dist/geotiff-raster-loader-types.js.map +1 -0
  59. package/dist/geotiff-raster-loader.d.ts +2 -0
  60. package/dist/geotiff-raster-loader.d.ts.map +1 -0
  61. package/dist/geotiff-raster-loader.js +2 -0
  62. package/dist/geotiff-raster-loader.js.map +1 -0
  63. package/dist/geotiff-source-loader.d.ts +2 -0
  64. package/dist/geotiff-source-loader.d.ts.map +1 -0
  65. package/dist/geotiff-source-loader.js +2 -0
  66. package/dist/geotiff-source-loader.js.map +1 -0
  67. package/dist/index.cjs +37 -67
  68. package/dist/index.cjs.map +3 -3
  69. package/dist/index.d.ts +4 -10
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +1 -6
  72. package/dist/index.js.map +1 -1
  73. package/dist/lerc/lerc-loader-types.d.ts +1 -1
  74. package/dist/lerc/lerc-loader-types.js +2 -2
  75. package/dist/lerc/lerc-loader-types.js.map +1 -1
  76. package/dist/lerc-loader-types.d.ts +2 -0
  77. package/dist/lerc-loader-types.d.ts.map +1 -0
  78. package/dist/lerc-loader-types.js +2 -0
  79. package/dist/lerc-loader-types.js.map +1 -0
  80. package/dist/lerc-loader.d.ts +2 -0
  81. package/dist/lerc-loader.d.ts.map +1 -0
  82. package/dist/lerc-loader.js +2 -0
  83. package/dist/lerc-loader.js.map +1 -0
  84. package/dist/ometiff-loader-types.d.ts +2 -0
  85. package/dist/ometiff-loader-types.d.ts.map +1 -0
  86. package/dist/ometiff-loader-types.js +2 -0
  87. package/dist/ometiff-loader-types.js.map +1 -0
  88. package/dist/ometiff-loader.d.ts +2 -0
  89. package/dist/ometiff-loader.d.ts.map +1 -0
  90. package/dist/ometiff-loader.js +2 -0
  91. package/dist/ometiff-loader.js.map +1 -0
  92. package/dist/quantized-mesh-loader-types.d.ts +2 -0
  93. package/dist/quantized-mesh-loader-types.d.ts.map +1 -0
  94. package/dist/quantized-mesh-loader-types.js +2 -0
  95. package/dist/quantized-mesh-loader-types.js.map +1 -0
  96. package/dist/quantized-mesh-loader.d.ts +2 -0
  97. package/dist/quantized-mesh-loader.d.ts.map +1 -0
  98. package/dist/quantized-mesh-loader.js +2 -0
  99. package/dist/quantized-mesh-loader.js.map +1 -0
  100. package/dist/quantized-mesh-worker.js +1807 -1032
  101. package/dist/quantized-mesh-writer.d.ts +2 -0
  102. package/dist/quantized-mesh-writer.d.ts.map +1 -0
  103. package/dist/quantized-mesh-writer.js +2 -0
  104. package/dist/quantized-mesh-writer.js.map +1 -0
  105. package/dist/terrain/heightmap.cjs +2 -333
  106. package/dist/terrain/heightmap.cjs.map +4 -4
  107. package/dist/terrain/heightmap.d.ts +1 -5
  108. package/dist/terrain/heightmap.d.ts.map +1 -1
  109. package/dist/terrain/heightmap.js +0 -3
  110. package/dist/terrain/heightmap.js.map +1 -1
  111. package/dist/terrain/index.cjs +72 -610
  112. package/dist/terrain/index.cjs.map +4 -4
  113. package/dist/terrain/index.d.ts +3 -6
  114. package/dist/terrain/index.d.ts.map +1 -1
  115. package/dist/terrain/index.js +2 -5
  116. package/dist/terrain/index.js.map +1 -1
  117. package/dist/terrain/lib/helpers/skirt.d.ts +2 -9
  118. package/dist/terrain/lib/helpers/skirt.d.ts.map +1 -1
  119. package/dist/terrain/lib/helpers/skirt.js +30 -114
  120. package/dist/terrain/lib/helpers/skirt.js.map +1 -1
  121. package/dist/terrain/lib/parse-terrain.d.ts +2 -0
  122. package/dist/terrain/lib/parse-terrain.d.ts.map +1 -1
  123. package/dist/terrain/lib/parse-terrain.js +23 -38
  124. package/dist/terrain/lib/parse-terrain.js.map +1 -1
  125. package/dist/terrain/lib/terrain-contracts.d.ts +0 -15
  126. package/dist/terrain/lib/terrain-contracts.d.ts.map +1 -1
  127. package/dist/terrain/lib/utils/version.js +1 -1
  128. package/dist/terrain/lib/utils/version.js.map +1 -1
  129. package/dist/terrain/quantized-mesh-loader-types.d.ts +1 -1
  130. package/dist/terrain/quantized-mesh-loader-types.d.ts.map +1 -1
  131. package/dist/terrain/quantized-mesh-loader-types.js +4 -3
  132. package/dist/terrain/quantized-mesh-loader-types.js.map +1 -1
  133. package/dist/terrain/quantized-mesh-loader.d.ts.map +1 -1
  134. package/dist/terrain/quantized-mesh-loader.js +4 -4
  135. package/dist/terrain/quantized-mesh-loader.js.map +1 -1
  136. package/dist/terrain/quantized-mesh-writer.d.ts +5 -4
  137. package/dist/terrain/quantized-mesh-writer.d.ts.map +1 -1
  138. package/dist/terrain/quantized-mesh-writer.js +4 -4
  139. package/dist/terrain/quantized-mesh-writer.js.map +1 -1
  140. package/dist/terrain/terrain-loader-types.d.ts +3 -3
  141. package/dist/terrain/terrain-loader-types.d.ts.map +1 -1
  142. package/dist/terrain/terrain-loader-types.js +4 -2
  143. package/dist/terrain/terrain-loader-types.js.map +1 -1
  144. package/dist/terrain/terrain-loader.d.ts +3 -2
  145. package/dist/terrain/terrain-loader.d.ts.map +1 -1
  146. package/dist/terrain/terrain-loader.js +7 -7
  147. package/dist/terrain/terrain-loader.js.map +1 -1
  148. package/dist/terrain-loader-types.d.ts +2 -0
  149. package/dist/terrain-loader-types.d.ts.map +1 -0
  150. package/dist/terrain-loader-types.js +2 -0
  151. package/dist/terrain-loader-types.js.map +1 -0
  152. package/dist/terrain-loader.d.ts +2 -0
  153. package/dist/terrain-loader.d.ts.map +1 -0
  154. package/dist/terrain-loader.js +2 -0
  155. package/dist/terrain-loader.js.map +1 -0
  156. package/dist/terrain-worker.js +5511 -3271
  157. package/package.json +78 -67
  158. package/src/geotiff/advanced.ts +9 -4
  159. package/src/geotiff/geotiff-loader-types.ts +13 -4
  160. package/src/geotiff/geotiff-loader.ts +5 -8
  161. package/src/geotiff/geotiff-raster-loader-types.ts +1 -3
  162. package/src/geotiff/geotiff-source-loader.ts +19 -45
  163. package/src/geotiff/lib/ome/load-ome-tiff.ts +7 -1
  164. package/src/geotiff/lib/ome/omexml.ts +5 -4
  165. package/src/geotiff/lib/tiff/tiff-gdal-metadata.ts +6 -5
  166. package/src/geotiff/lib/tiff-pixel-source.ts +2 -1
  167. package/src/geotiff/{ometiff-source-loader-types.ts → ometiff-loader-types.ts} +6 -7
  168. package/src/geotiff/{ometiff-source-loader.ts → ometiff-loader.ts} +6 -8
  169. package/src/geotiff-loader-types.ts +1 -0
  170. package/src/geotiff-loader.ts +1 -0
  171. package/src/geotiff-raster-loader-types.ts +1 -0
  172. package/src/geotiff-raster-loader.ts +1 -0
  173. package/src/geotiff-source-loader.ts +1 -0
  174. package/src/index.ts +4 -15
  175. package/src/lerc/lerc-loader-types.ts +1 -1
  176. package/src/lerc-loader-types.ts +1 -0
  177. package/src/lerc-loader.ts +1 -0
  178. package/src/ometiff-loader-types.ts +1 -0
  179. package/src/ometiff-loader.ts +1 -0
  180. package/src/quantized-mesh-loader-types.ts +1 -0
  181. package/src/quantized-mesh-loader.ts +1 -0
  182. package/src/quantized-mesh-writer.ts +1 -0
  183. package/src/terrain/heightmap.ts +0 -10
  184. package/src/terrain/index.ts +2 -13
  185. package/src/terrain/lib/helpers/skirt.ts +41 -151
  186. package/src/terrain/lib/parse-terrain.ts +36 -40
  187. package/src/terrain/lib/terrain-contracts.ts +0 -19
  188. package/src/terrain/quantized-mesh-loader-types.ts +9 -7
  189. package/src/terrain/quantized-mesh-loader.ts +8 -7
  190. package/src/terrain/quantized-mesh-writer.ts +10 -9
  191. package/src/terrain/terrain-loader-types.ts +11 -9
  192. package/src/terrain/terrain-loader.ts +11 -10
  193. package/src/terrain-loader-types.ts +1 -0
  194. package/src/terrain-loader.ts +1 -0
  195. package/dist/geotiff/geotiff-source-loader-types.d.ts +0 -67
  196. package/dist/geotiff/geotiff-source-loader-types.d.ts.map +0 -1
  197. package/dist/geotiff/geotiff-source-loader-types.js +0 -43
  198. package/dist/geotiff/geotiff-source-loader-types.js.map +0 -1
  199. package/dist/geotiff/ometiff-source-loader-types.d.ts.map +0 -1
  200. package/dist/geotiff/ometiff-source-loader-types.js.map +0 -1
  201. package/dist/geotiff/ometiff-source-loader.d.ts.map +0 -1
  202. package/dist/geotiff/ometiff-source-loader.js.map +0 -1
  203. package/dist/terrain/lib/terrain-height-field.d.ts +0 -51
  204. package/dist/terrain/lib/terrain-height-field.d.ts.map +0 -1
  205. package/dist/terrain/lib/terrain-height-field.js +0 -260
  206. package/dist/terrain/lib/terrain-height-field.js.map +0 -1
  207. package/dist/terrain/lib/terrain-height-grid.d.ts +0 -14
  208. package/dist/terrain/lib/terrain-height-grid.d.ts.map +0 -1
  209. package/dist/terrain/lib/terrain-height-grid.js +0 -104
  210. package/dist/terrain/lib/terrain-height-grid.js.map +0 -1
  211. package/dist/terrain/lib/terrain-neighborhood.d.ts +0 -15
  212. package/dist/terrain/lib/terrain-neighborhood.d.ts.map +0 -1
  213. package/dist/terrain/lib/terrain-neighborhood.js +0 -58
  214. package/dist/terrain/lib/terrain-neighborhood.js.map +0 -1
  215. package/dist/terrain/libs/README.md +0 -10
  216. package/dist/terrain/libs/martini-LICENSE +0 -15
  217. package/dist/terrain/libs/martini.d.mts +0 -19
  218. package/dist/terrain/libs/martini.mjs +0 -164
  219. package/src/geotiff/geotiff-source-loader-types.ts +0 -55
  220. package/src/terrain/lib/terrain-height-field.ts +0 -355
  221. package/src/terrain/lib/terrain-height-grid.ts +0 -157
  222. package/src/terrain/lib/terrain-neighborhood.ts +0 -69
  223. package/src/terrain/libs/README.md +0 -10
  224. package/src/terrain/libs/martini-LICENSE +0 -15
  225. package/src/terrain/libs/martini.d.mts +0 -19
  226. package/src/terrain/libs/martini.mjs +0 -164
@@ -16,626 +16,101 @@
16
16
  };
17
17
 
18
18
  // ../core/src/worker-utils/lib/node/worker_threads-browser.ts
19
- var parentPort;
19
+ var worker_threads_browser_exports = {};
20
+ __export(worker_threads_browser_exports, {
21
+ NodeWorker: () => NodeWorker,
22
+ parentPort: () => parentPort2
23
+ });
24
+ var NodeWorker, parentPort2;
20
25
  var init_worker_threads_browser = __esm({
21
26
  "../core/src/worker-utils/lib/node/worker_threads-browser.ts"() {
22
27
  "use strict";
23
- parentPort = null;
28
+ NodeWorker = class {
29
+ /** Restores the native worker constructor when this browser shim is embedded in a Node bundle. */
30
+ constructor(...arguments_) {
31
+ const runtimeProcess = globalThis.process;
32
+ const WorkerConstructor = runtimeProcess?.getBuiltinModule?.("node:worker_threads").Worker;
33
+ if (WorkerConstructor) {
34
+ return new WorkerConstructor(...arguments_);
35
+ }
36
+ }
37
+ /** No-op browser fallback matching the native Worker API. */
38
+ terminate() {
39
+ }
40
+ };
41
+ parentPort2 = null;
24
42
  }
25
43
  });
26
44
 
27
- // ../core/src/worker-utils/lib/worker-utils/get-transfer-list.ts
28
- function getTransferList(object, recursive = true, transfers) {
29
- const transfersSet = transfers || /* @__PURE__ */ new Set();
30
- if (!object) {
31
- } else if (isTransferable(object)) {
32
- transfersSet.add(object);
33
- } else if (isTransferable(object.buffer)) {
34
- transfersSet.add(object.buffer);
35
- } else if (ArrayBuffer.isView(object)) {
36
- } else if (recursive && typeof object === "object") {
37
- for (const key in object) {
38
- getTransferList(object[key], recursive, transfersSet);
39
- }
40
- }
41
- return transfers === void 0 ? Array.from(transfersSet) : [];
42
- }
43
- function isTransferable(object) {
44
- if (!object) {
45
- return false;
46
- }
47
- if (object instanceof ArrayBuffer) {
48
- return true;
49
- }
50
- if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
51
- return true;
52
- }
53
- if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
54
- return true;
45
+ // ../../node_modules/@math.gl/core/dist/lib/math-utils.js
46
+ var PI_OVER_TWO, PI_OVER_FOUR, PI_OVER_SIX, TWO_PI;
47
+ var init_math_utils = __esm({
48
+ "../../node_modules/@math.gl/core/dist/lib/math-utils.js"() {
49
+ PI_OVER_TWO = Math.PI / 2;
50
+ PI_OVER_FOUR = Math.PI / 4;
51
+ PI_OVER_SIX = Math.PI / 6;
52
+ TWO_PI = Math.PI * 2;
55
53
  }
56
- if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
57
- return true;
54
+ });
55
+
56
+ // ../../node_modules/@math.gl/core/dist/gl-matrix/vec2.js
57
+ var init_vec2 = __esm({
58
+ "../../node_modules/@math.gl/core/dist/gl-matrix/vec2.js"() {
58
59
  }
59
- return false;
60
- }
61
- var init_get_transfer_list = __esm({
62
- "../core/src/worker-utils/lib/worker-utils/get-transfer-list.ts"() {
63
- "use strict";
60
+ });
61
+
62
+ // ../../node_modules/@math.gl/core/dist/gl-matrix/vec3.js
63
+ var init_vec3 = __esm({
64
+ "../../node_modules/@math.gl/core/dist/gl-matrix/vec3.js"() {
64
65
  }
65
66
  });
66
67
 
67
- // ../core/src/worker-utils/lib/worker-farm/worker-body.ts
68
- async function getParentPort() {
69
- return parentPort;
70
- }
71
- function getWorkerMessageData(message) {
72
- if (!message || typeof message !== "object") {
73
- return null;
68
+ // ../../node_modules/@math.gl/core/dist/gl-matrix/mat3.js
69
+ var init_mat3 = __esm({
70
+ "../../node_modules/@math.gl/core/dist/gl-matrix/mat3.js"() {
74
71
  }
75
- const messageData = "data" in message && message.type === "message" ? message.data : message;
76
- return messageData && typeof messageData.source === "string" && messageData.source.startsWith("loaders.gl") ? messageData : null;
77
- }
78
- var onMessageWrapperMap, WorkerBody;
79
- var init_worker_body = __esm({
80
- "../core/src/worker-utils/lib/worker-farm/worker-body.ts"() {
81
- "use strict";
82
- init_get_transfer_list();
83
- init_worker_threads_browser();
84
- onMessageWrapperMap = /* @__PURE__ */ new Map();
85
- WorkerBody = class {
86
- /** Check that we are actually in a worker thread */
87
- static async inWorkerThread() {
88
- return typeof self !== "undefined" || Boolean(await getParentPort());
89
- }
90
- /*
91
- * (type: WorkerMessageType, payload: WorkerMessagePayload) => any
92
- */
93
- static set onmessage(onMessage) {
94
- async function handleMessage(message) {
95
- const parentPort2 = await getParentPort();
96
- const { type, payload } = parentPort2 ? message : message.data;
97
- onMessage(type, payload);
98
- }
99
- getParentPort().then((parentPort2) => {
100
- if (parentPort2) {
101
- parentPort2.on("message", (message) => {
102
- handleMessage(message);
103
- });
104
- parentPort2.on("exit", () => console.debug("Node worker closing"));
105
- } else {
106
- globalThis.onmessage = handleMessage;
107
- }
108
- });
109
- }
110
- static async addEventListener(onMessage) {
111
- let onMessageWrapper = onMessageWrapperMap.get(onMessage);
112
- if (!onMessageWrapper) {
113
- onMessageWrapper = (message) => {
114
- const messageData = getWorkerMessageData(message);
115
- if (!messageData) {
116
- return;
117
- }
118
- onMessage(messageData.type, messageData.payload);
119
- };
120
- onMessageWrapperMap.set(onMessage, onMessageWrapper);
121
- }
122
- const parentPort2 = await getParentPort();
123
- if (parentPort2) {
124
- parentPort2.on("message", onMessageWrapper);
125
- } else {
126
- globalThis.addEventListener("message", onMessageWrapper);
127
- }
128
- }
129
- static async removeEventListener(onMessage) {
130
- const onMessageWrapper = onMessageWrapperMap.get(onMessage);
131
- onMessageWrapperMap.delete(onMessage);
132
- if (!onMessageWrapper) {
133
- return;
134
- }
135
- const parentPort2 = await getParentPort();
136
- if (parentPort2) {
137
- parentPort2.off("message", onMessageWrapper);
138
- } else {
139
- globalThis.removeEventListener("message", onMessageWrapper);
140
- }
141
- }
142
- /**
143
- * Send a message from a worker to creating thread (main thread)
144
- * @param type
145
- * @param payload
146
- */
147
- static async postMessage(type, payload) {
148
- const data = { source: "loaders.gl", type, payload };
149
- const transferList = getTransferList(payload);
150
- const parentPort2 = await getParentPort();
151
- if (parentPort2) {
152
- parentPort2.postMessage(data, transferList);
153
- } else {
154
- globalThis.postMessage(data, transferList);
155
- }
156
- }
157
- };
72
+ });
73
+
74
+ // ../../node_modules/@math.gl/core/dist/gl-matrix/mat4.js
75
+ var init_mat4 = __esm({
76
+ "../../node_modules/@math.gl/core/dist/gl-matrix/mat4.js"() {
158
77
  }
159
78
  });
160
79
 
161
- // ../core/src/worker-utils/lib/async-queue/async-queue.ts
162
- var AsyncQueue;
163
- var init_async_queue = __esm({
164
- "../core/src/worker-utils/lib/async-queue/async-queue.ts"() {
165
- "use strict";
166
- AsyncQueue = class {
167
- _values;
168
- _settlers;
169
- _closed;
170
- constructor() {
171
- this._values = [];
172
- this._settlers = [];
173
- this._closed = false;
174
- }
175
- /** Return an async iterator for this queue */
176
- [Symbol.asyncIterator]() {
177
- return this;
178
- }
179
- /** Push a new value - the async iterator will yield a promise resolved to this value */
180
- push(value) {
181
- return this.enqueue(value);
182
- }
183
- /**
184
- * Push a new value - the async iterator will yield a promise resolved to this value
185
- * Add an error - the async iterator will yield a promise rejected with this value
186
- */
187
- enqueue(value) {
188
- if (this._closed) {
189
- throw new Error("Closed");
190
- }
191
- if (this._settlers.length > 0) {
192
- if (this._values.length > 0) {
193
- throw new Error("Illegal internal state");
194
- }
195
- const settler = this._settlers.shift();
196
- if (value instanceof Error) {
197
- settler.reject(value);
198
- } else {
199
- settler.resolve({ value });
200
- }
201
- } else {
202
- this._values.push(value);
203
- }
204
- }
205
- /** Indicate that we not waiting for more values - The async iterator will be done */
206
- close() {
207
- while (this._settlers.length > 0) {
208
- const settler = this._settlers.shift();
209
- settler.resolve({ done: true });
210
- }
211
- this._closed = true;
212
- }
213
- // ITERATOR IMPLEMENTATION
214
- /** @returns a Promise for an IteratorResult */
215
- next() {
216
- if (this._values.length > 0) {
217
- const value = this._values.shift();
218
- if (value instanceof Error) {
219
- return Promise.reject(value);
220
- }
221
- return Promise.resolve({ done: false, value });
222
- }
223
- if (this._closed) {
224
- if (this._settlers.length > 0) {
225
- throw new Error("Illegal internal state");
226
- }
227
- return Promise.resolve({ done: true, value: void 0 });
228
- }
229
- return new Promise((resolve, reject) => {
230
- this._settlers.push({ resolve, reject });
231
- });
232
- }
233
- };
80
+ // ../../node_modules/@math.gl/core/dist/gl-matrix/vec4.js
81
+ var init_vec4 = __esm({
82
+ "../../node_modules/@math.gl/core/dist/gl-matrix/vec4.js"() {
234
83
  }
235
84
  });
236
85
 
237
- // ../core/src/worker-utils/lib/worker-api/create-worker.ts
238
- async function createWorker(process, processInBatches) {
239
- if (!await WorkerBody.inWorkerThread()) {
240
- return;
86
+ // ../../node_modules/@math.gl/core/dist/gl-matrix/quat.js
87
+ var init_quat = __esm({
88
+ "../../node_modules/@math.gl/core/dist/gl-matrix/quat.js"() {
241
89
  }
242
- const context = {
243
- process: processOnMainThread
244
- };
245
- WorkerBody.onmessage = async (type, payload) => {
246
- const reporter = type === "process" || type === "process-in-batches" ? createProgressReporter() : void 0;
247
- const jobContext = { ...context, reportProgress: reporter?.report };
248
- try {
249
- switch (type) {
250
- case "preload":
251
- WorkerBody.postMessage("done", {});
252
- break;
253
- case "process":
254
- if (!process) {
255
- throw new Error("Worker does not support atomic processing");
256
- }
257
- const result = await process(
258
- payload.input,
259
- payload.options || {},
260
- jobContext,
261
- payload.context || {}
262
- );
263
- reporter?.finish();
264
- WorkerBody.postMessage("done", { result });
265
- break;
266
- case "process-in-batches":
267
- if (!processInBatches) {
268
- throw new Error("Worker does not support batched processing");
269
- }
270
- const inputBatches = new AsyncQueue();
271
- const outputAcknowledgements = new AsyncQueue();
272
- activeInputBatches = inputBatches;
273
- activeOutputAcknowledgements = outputAcknowledgements;
274
- try {
275
- const resultIterator = processInBatches(
276
- createDemandDrivenIterator(inputBatches),
277
- payload.options || {},
278
- jobContext,
279
- payload.context || {}
280
- );
281
- for await (const batch of resultIterator) {
282
- await WorkerBody.postMessage("output-batch", { result: batch });
283
- await outputAcknowledgements.next();
284
- }
285
- reporter?.finish();
286
- await WorkerBody.postMessage("done", {});
287
- } finally {
288
- activeInputBatches = null;
289
- activeOutputAcknowledgements = null;
290
- }
291
- break;
292
- case "input-batch":
293
- if (!activeInputBatches) {
294
- throw new Error("Worker has no active batched processing session");
295
- }
296
- activeInputBatches.push(payload.input);
297
- break;
298
- case "input-done":
299
- if (!activeInputBatches) {
300
- throw new Error("Worker has no active batched processing session");
301
- }
302
- activeInputBatches.close();
303
- break;
304
- case "output-ack":
305
- if (!activeOutputAcknowledgements) {
306
- throw new Error("Worker has no active batched processing session");
307
- }
308
- activeOutputAcknowledgements.push(void 0);
309
- break;
310
- default:
311
- }
312
- } catch (error) {
313
- reporter?.finish();
314
- const message = error instanceof Error ? error.message : "";
315
- WorkerBody.postMessage("error", { error: message });
316
- }
317
- };
90
+ });
91
+
92
+ // ../../node_modules/@math.gl/core/dist/types/float16.js
93
+ function getFloat16ArrayConstructor() {
94
+ return NativeFloat16ArrayConstructor ?? Uint16Array;
318
95
  }
319
- async function* createDemandDrivenIterator(inputBatches) {
320
- while (true) {
321
- await WorkerBody.postMessage("input-request", {});
322
- const nextBatch = await inputBatches.next();
323
- if (nextBatch.done) {
324
- return;
325
- }
326
- yield nextBatch.value;
96
+ var NativeFloat16ArrayConstructor;
97
+ var init_float16 = __esm({
98
+ "../../node_modules/@math.gl/core/dist/types/float16.js"() {
99
+ NativeFloat16ArrayConstructor = globalThis.Float16Array;
327
100
  }
328
- }
329
- function processOnMainThread(arrayBuffer, options = {}, jobContext = {}) {
330
- return new Promise((resolve, reject) => {
331
- const id = requestId++;
332
- const onMessage = (type, payload2) => {
333
- if (payload2.id !== id) {
334
- return;
335
- }
336
- switch (type) {
337
- case "done":
338
- WorkerBody.removeEventListener(onMessage);
339
- resolve(payload2.result);
340
- break;
341
- case "error":
342
- WorkerBody.removeEventListener(onMessage);
343
- reject(payload2.error);
344
- break;
345
- default:
346
- }
347
- };
348
- WorkerBody.addEventListener(onMessage);
349
- const payload = { id, input: arrayBuffer, options, context: jobContext };
350
- WorkerBody.postMessage("process", payload);
351
- });
352
- }
353
- function createProgressReporter() {
354
- let pending;
355
- let finished = false;
356
- let scheduled = false;
357
- const flush = () => {
358
- scheduled = false;
359
- if (pending) {
360
- WorkerBody.postMessage("progress", { progress: pending });
361
- pending = void 0;
362
- }
363
- };
364
- return {
365
- /** Records progress while retaining phase transitions. */
366
- report(progress) {
367
- if (finished) return;
368
- if (pending && pending.phase !== progress.phase) flush();
369
- pending = { ...progress };
370
- if (!scheduled) {
371
- scheduled = true;
372
- setTimeout(flush, 0);
373
- }
374
- },
375
- /** Flushes final progress and suppresses reports from stale callbacks. */
376
- finish() {
377
- flush();
378
- finished = true;
379
- }
380
- };
381
- }
382
- var requestId, activeInputBatches, activeOutputAcknowledgements;
383
- var init_create_worker = __esm({
384
- "../core/src/worker-utils/lib/worker-api/create-worker.ts"() {
385
- "use strict";
386
- init_async_queue();
387
- init_worker_body();
388
- requestId = 0;
389
- activeInputBatches = null;
390
- activeOutputAcknowledgements = null;
101
+ });
102
+
103
+ // ../../node_modules/@math.gl/core/dist/types/index.js
104
+ var init_types = __esm({
105
+ "../../node_modules/@math.gl/core/dist/types/index.js"() {
106
+ init_float16();
391
107
  }
392
108
  });
393
109
 
394
- // ../core/src/worker-utils/index.ts
395
- var init_worker_utils = __esm({
396
- "../core/src/worker-utils/index.ts"() {
397
- "use strict";
398
- init_create_worker();
399
- }
400
- });
401
-
402
- // ../core/src/loader-utils/lib/worker-loader-utils/create-loader-worker.ts
403
- async function createLoaderWorker(loader, selectLoader = () => loader) {
404
- await createWorker(
405
- (input, options, workerContext, loaderContext) => processLoaderWorkerData(
406
- selectLoader(options || {}),
407
- input,
408
- options,
409
- workerContext,
410
- loaderContext
411
- ),
412
- (inputIterator, options, workerContext, loaderContext) => processLoaderWorkerBatches(
413
- selectLoader(options || {}),
414
- inputIterator,
415
- options,
416
- workerContext,
417
- loaderContext
418
- )
419
- );
420
- }
421
- async function processLoaderWorkerData(loader, input, options = {}, workerContext, loaderContext = {}) {
422
- const result = await parseData({
423
- loader,
424
- arrayBuffer: input,
425
- options,
426
- context: {
427
- ...loaderContext,
428
- reportProgress: workerContext?.reportProgress,
429
- coreApi: createWorkerCoreApi(),
430
- _parse: createParseOnMainThread(workerContext?.process)
431
- }
432
- });
433
- return loader.serializeWorkerResult ? loader.serializeWorkerResult(result, options, loaderContext) : result;
434
- }
435
- async function* processLoaderWorkerBatches(loader, inputIterator, options = {}, workerContext, loaderContext = {}) {
436
- if (!loader.parseInBatches) {
437
- throw new Error(`${loader.id} loader does not support batched parsing`);
438
- }
439
- const parserOptions = getWorkerLoaderOptions(loader, options);
440
- const resultIterator = loader.parseInBatches(inputIterator, parserOptions, {
441
- ...loaderContext,
442
- reportProgress: workerContext?.reportProgress,
443
- coreApi: createWorkerCoreApi(),
444
- _parse: createParseOnMainThread(workerContext?.process)
445
- });
446
- for await (const batch of resultIterator) {
447
- yield loader.serializeWorkerBatch ? loader.serializeWorkerBatch(batch, options, loaderContext) : batch;
448
- }
449
- }
450
- function createWorkerCoreApi() {
451
- const unavailable = (methodName) => () => {
452
- throw new Error(`context.coreApi.${methodName} is unavailable inside worker loaders.`);
453
- };
454
- return {
455
- fetchFile: async (urlOrData, fetchOptions) => await fetch(urlOrData, fetchOptions),
456
- parseSync: unavailable("parseSync"),
457
- parse: unavailable("parse"),
458
- parseFile: unavailable("parseFile"),
459
- parseInBatches: unavailable("parseInBatches"),
460
- load: unavailable("load"),
461
- loadInBatches: unavailable("loadInBatches")
462
- };
463
- }
464
- function createParseOnMainThread(processOnMainThread2) {
465
- return (arrayBuffer, loaders, options, context) => {
466
- if (!processOnMainThread2) {
467
- throw new Error("Worker not set up to parse on main thread");
468
- }
469
- const parseArguments = getMainThreadParseArguments(loaders, options, context);
470
- return processOnMainThread2(arrayBuffer, parseArguments.options, {
471
- ...parseArguments.context,
472
- ...Array.isArray(loaders) || loaders && isLoaderObject(loaders) ? {
473
- _loaderIsArray: Array.isArray(loaders),
474
- _loaderIds: (Array.isArray(loaders) ? loaders : [loaders]).map((loader) => loader.id)
475
- } : {}
476
- });
477
- };
478
- }
479
- function getMainThreadParseArguments(loaders, options, context) {
480
- if (options) {
481
- return { options, context: getSerializableLoaderContext(context) };
482
- }
483
- if (Array.isArray(loaders) || loaders && isLoaderObject(loaders)) {
484
- return { options: void 0, context: getSerializableLoaderContext(context) };
485
- }
486
- if (loaders && !Array.isArray(loaders)) {
487
- return { options: loaders };
488
- }
489
- return { options: void 0, context: getSerializableLoaderContext(context) };
490
- }
491
- function isLoaderObject(value) {
492
- return "id" in value && "extensions" in value;
493
- }
494
- function getSerializableLoaderContext(context) {
495
- if (!context) {
496
- return void 0;
497
- }
498
- const {
499
- fetch: fetch2,
500
- loaders,
501
- coreApi,
502
- signal,
503
- reportProgress,
504
- _parse,
505
- _parseSync,
506
- _parseInBatches,
507
- ...serializableContext
508
- } = context;
509
- return JSON.parse(JSON.stringify(serializableContext));
510
- }
511
- async function parseData({
512
- loader,
513
- arrayBuffer,
514
- options,
515
- context
516
- }) {
517
- let data;
518
- let parser;
519
- if (loader.parse || loader.parseSync) {
520
- data = arrayBuffer;
521
- parser = loader.parse || loader.parseSync;
522
- } else if (loader.parseTextSync) {
523
- const textDecoder = new TextDecoder();
524
- data = textDecoder.decode(arrayBuffer);
525
- parser = loader.parseTextSync;
526
- } else {
527
- throw new Error(`Could not load data with ${loader.name} loader`);
528
- }
529
- options = getWorkerLoaderOptions(loader, options);
530
- return await parser(data, { ...options }, context, loader);
531
- }
532
- function getWorkerLoaderOptions(loader, options) {
533
- return {
534
- ...options,
535
- modules: { ...loader.options?.modules, ...options.modules },
536
- core: { ...options.core, worker: false }
537
- };
538
- }
539
- var init_create_loader_worker = __esm({
540
- "../core/src/loader-utils/lib/worker-loader-utils/create-loader-worker.ts"() {
541
- "use strict";
542
- init_worker_utils();
543
- }
544
- });
545
-
546
- // ../core/src/loader-utils/lib/binary-utils/array-buffer-utils.ts
547
- function concatenateTypedArrays(...typedArrays) {
548
- const arrays = typedArrays;
549
- const TypedArrayConstructor = arrays && arrays.length > 1 && arrays[0].constructor || null;
550
- if (!TypedArrayConstructor) {
551
- throw new Error(
552
- '"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types'
553
- );
554
- }
555
- const sumLength = arrays.reduce((acc, value) => acc + value.length, 0);
556
- const result = new TypedArrayConstructor(sumLength);
557
- let offset = 0;
558
- for (const array of arrays) {
559
- result.set(array, offset);
560
- offset += array.length;
561
- }
562
- return result;
563
- }
564
- var init_array_buffer_utils = __esm({
565
- "../core/src/loader-utils/lib/binary-utils/array-buffer-utils.ts"() {
566
- "use strict";
567
- }
568
- });
569
-
570
- // ../../node_modules/@math.gl/core/dist/lib/math-utils.js
571
- var PI_OVER_TWO, PI_OVER_FOUR, PI_OVER_SIX, TWO_PI;
572
- var init_math_utils = __esm({
573
- "../../node_modules/@math.gl/core/dist/lib/math-utils.js"() {
574
- PI_OVER_TWO = Math.PI / 2;
575
- PI_OVER_FOUR = Math.PI / 4;
576
- PI_OVER_SIX = Math.PI / 6;
577
- TWO_PI = Math.PI * 2;
578
- }
579
- });
580
-
581
- // ../../node_modules/@math.gl/core/dist/gl-matrix/vec2.js
582
- var init_vec2 = __esm({
583
- "../../node_modules/@math.gl/core/dist/gl-matrix/vec2.js"() {
584
- }
585
- });
586
-
587
- // ../../node_modules/@math.gl/core/dist/gl-matrix/vec3.js
588
- var init_vec3 = __esm({
589
- "../../node_modules/@math.gl/core/dist/gl-matrix/vec3.js"() {
590
- }
591
- });
592
-
593
- // ../../node_modules/@math.gl/core/dist/gl-matrix/mat3.js
594
- var init_mat3 = __esm({
595
- "../../node_modules/@math.gl/core/dist/gl-matrix/mat3.js"() {
596
- }
597
- });
598
-
599
- // ../../node_modules/@math.gl/core/dist/gl-matrix/mat4.js
600
- var init_mat4 = __esm({
601
- "../../node_modules/@math.gl/core/dist/gl-matrix/mat4.js"() {
602
- }
603
- });
604
-
605
- // ../../node_modules/@math.gl/core/dist/gl-matrix/vec4.js
606
- var init_vec4 = __esm({
607
- "../../node_modules/@math.gl/core/dist/gl-matrix/vec4.js"() {
608
- }
609
- });
610
-
611
- // ../../node_modules/@math.gl/core/dist/gl-matrix/quat.js
612
- var init_quat = __esm({
613
- "../../node_modules/@math.gl/core/dist/gl-matrix/quat.js"() {
614
- }
615
- });
616
-
617
- // ../../node_modules/@math.gl/core/dist/types/float16.js
618
- function getFloat16ArrayConstructor() {
619
- return NativeFloat16ArrayConstructor ?? Uint16Array;
620
- }
621
- var NativeFloat16ArrayConstructor;
622
- var init_float16 = __esm({
623
- "../../node_modules/@math.gl/core/dist/types/float16.js"() {
624
- NativeFloat16ArrayConstructor = globalThis.Float16Array;
625
- }
626
- });
627
-
628
- // ../../node_modules/@math.gl/core/dist/types/index.js
629
- var init_types = __esm({
630
- "../../node_modules/@math.gl/core/dist/types/index.js"() {
631
- init_float16();
632
- }
633
- });
634
-
635
- // ../../node_modules/@math.gl/core/dist/types.js
636
- var init_types2 = __esm({
637
- "../../node_modules/@math.gl/core/dist/types.js"() {
638
- init_types();
110
+ // ../../node_modules/@math.gl/core/dist/types.js
111
+ var init_types2 = __esm({
112
+ "../../node_modules/@math.gl/core/dist/types.js"() {
113
+ init_types();
639
114
  }
640
115
  });
641
116
 
@@ -695,12 +170,101 @@
695
170
  }
696
171
  });
697
172
 
698
- // ../core/src/loader-utils/index.ts
699
- var init_loader_utils = __esm({
700
- "../core/src/loader-utils/index.ts"() {
701
- "use strict";
702
- init_create_loader_worker();
703
- init_array_buffer_utils();
173
+ // ../../node_modules/@math.gl/geospatial/dist/terrain/mesh-skirts.js
174
+ function createTerrainSkirt(mesh, options) {
175
+ const { positions, indices } = mesh, { height, baseZ, edges } = options;
176
+ const maxVertices = options.maxVertices ?? 2e6, maxTriangles = options.maxTriangles ?? 4e6;
177
+ if ((baseZ === void 0 ? !(Number.isFinite(height) && height > 0) : height !== void 0 || !Number.isFinite(baseZ)) || !Number.isSafeInteger(maxVertices) || maxVertices < 0 || maxVertices > 4294967295 || !Number.isSafeInteger(maxTriangles) || maxTriangles < 0 || maxTriangles > 4294967295)
178
+ throw new Error("Invalid terrain skirt height or capacity");
179
+ if (!(positions instanceof Float32Array || positions instanceof Float64Array) || positions.length < 3 || positions.length % 3 || !positions.every(Number.isFinite) || !(indices instanceof Uint16Array || indices instanceof Uint32Array) || indices.length % 3 || positions.length / 3 > maxVertices || indices.length / 3 > maxTriangles)
180
+ throw new Error("Invalid terrain skirt mesh or capacity");
181
+ if (edges !== void 0 && (!(edges instanceof Uint16Array || edges instanceof Uint32Array) || edges.length % 2))
182
+ throw new Error("Invalid terrain skirt edge pairs");
183
+ const vertexCount = positions.length / 3, triangleCount = indices.length / 3;
184
+ const boundary = /* @__PURE__ */ new Map();
185
+ for (let i = 0; i < indices.length; i += 3) {
186
+ const ids = [indices[i], indices[i + 1], indices[i + 2]];
187
+ if (ids.some((id) => id >= vertexCount))
188
+ throw new Error("Terrain skirt index out of range");
189
+ const [a, b, c] = ids.map((id) => id * 3);
190
+ const area = (positions[b] - positions[a]) * (positions[c + 1] - positions[a + 1]) - (positions[b + 1] - positions[a + 1]) * (positions[c] - positions[a]);
191
+ if (!Number.isFinite(area) || area <= 0)
192
+ throw new Error("Terrain skirt requires upward nondegenerate XY triangles");
193
+ for (let j = 0; j < 3; j++) {
194
+ const u = ids[j], v = ids[(j + 1) % 3], key = edgeKey(u, v), prior = boundary.get(key);
195
+ if (!prior)
196
+ boundary.set(key, { a: u, b: v, count: 1 });
197
+ else {
198
+ if (prior.count !== 1 || prior.a !== v || prior.b !== u)
199
+ throw new Error("Terrain skirt mesh has nonmanifold or inconsistent edges");
200
+ prior.count++;
201
+ }
202
+ }
203
+ }
204
+ let selected;
205
+ if (edges) {
206
+ selected = [];
207
+ const used = /* @__PURE__ */ new Set();
208
+ for (let i = 0; i < edges.length; i += 2) {
209
+ const key = edgeKey(edges[i], edges[i + 1]), edge = boundary.get(key);
210
+ if (!edge || edge.count !== 1 || used.has(key))
211
+ throw new Error("Terrain skirt selection must contain unique boundary edges");
212
+ used.add(key);
213
+ selected.push(edge);
214
+ }
215
+ } else
216
+ selected = [...boundary.values()].filter((edge) => edge.count === 1);
217
+ const outputVertices = vertexCount + selected.length * 2, outputTriangles = triangleCount + selected.length * 2;
218
+ if (!Number.isSafeInteger(outputVertices) || outputVertices > maxVertices || outputVertices > 4294967295 || !Number.isSafeInteger(outputTriangles) || outputTriangles > maxTriangles)
219
+ throw new Error("Terrain skirt output capacity exceeded");
220
+ const resultPositions = positions instanceof Float32Array ? new Float32Array(outputVertices * 3) : new Float64Array(outputVertices * 3);
221
+ resultPositions.set(positions);
222
+ const resultIndices = indices instanceof Uint16Array && outputVertices <= 65536 ? new Uint16Array(outputTriangles * 3) : new Uint32Array(outputTriangles * 3);
223
+ resultIndices.set(indices);
224
+ const sourceVertexIndices = new Uint32Array(selected.length * 2), triangleValidity = new Uint8Array(outputTriangles);
225
+ triangleValidity.fill(1, 0, triangleCount);
226
+ for (let i = 0; i < selected.length; i++) {
227
+ const { a, b } = selected[i], lowerA = vertexCount + 2 * i, lowerB = lowerA + 1;
228
+ for (const [source, target] of [
229
+ [a, lowerA],
230
+ [b, lowerB]
231
+ ]) {
232
+ resultPositions.set(positions.subarray(3 * source, 3 * source + 3), 3 * target);
233
+ resultPositions[3 * target + 2] = baseZ ?? positions[3 * source + 2] - height;
234
+ if (!Number.isFinite(resultPositions[3 * target + 2]) || resultPositions[3 * target + 2] >= positions[3 * source + 2])
235
+ throw new Error("Terrain skirt height cannot be represented in position precision");
236
+ sourceVertexIndices[target - vertexCount] = source;
237
+ }
238
+ resultIndices.set([a, lowerB, b, lowerB, a, lowerA], indices.length + i * 6);
239
+ }
240
+ const min = [Infinity, Infinity, Infinity], max = [-Infinity, -Infinity, -Infinity];
241
+ for (let i = 0; i < resultPositions.length; i++) {
242
+ const axis = i % 3;
243
+ min[axis] = Math.min(min[axis], resultPositions[i]);
244
+ max[axis] = Math.max(max[axis], resultPositions[i]);
245
+ }
246
+ return {
247
+ positions: resultPositions,
248
+ indices: resultIndices,
249
+ sourceVertexIndices,
250
+ skirtVertexOffset: vertexCount,
251
+ skirtTriangleOffset: triangleCount,
252
+ triangleValidity,
253
+ bounds: [min, max]
254
+ };
255
+ }
256
+ function edgeKey(a, b) {
257
+ return a < b ? `${a},${b}` : `${b},${a}`;
258
+ }
259
+ var init_mesh_skirts = __esm({
260
+ "../../node_modules/@math.gl/geospatial/dist/terrain/mesh-skirts.js"() {
261
+ }
262
+ });
263
+
264
+ // ../../node_modules/@math.gl/geospatial/dist/terrain/index.js
265
+ var init_terrain = __esm({
266
+ "../../node_modules/@math.gl/geospatial/dist/terrain/index.js"() {
267
+ init_mesh_skirts();
704
268
  }
705
269
  });
706
270
 
@@ -8354,11 +7918,11 @@ return true;`);
8354
7918
  this._offsets = new OffsetsBufferBuilder(opts.type);
8355
7919
  }
8356
7920
  setValue(index, value) {
8357
- const pending = this._pending || (this._pending = /* @__PURE__ */ new Map());
8358
- const current = pending.get(index);
7921
+ const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
7922
+ const current = pending2.get(index);
8359
7923
  current && (this._pendingLength -= current.length);
8360
7924
  this._pendingLength += value instanceof MapRow ? value[kKeys].length : value.length;
8361
- pending.set(index, value);
7925
+ pending2.set(index, value);
8362
7926
  }
8363
7927
  setValid(index, isValid) {
8364
7928
  if (!super.setValid(index, isValid)) {
@@ -8381,12 +7945,12 @@ return true;`);
8381
7945
  return super.finish();
8382
7946
  }
8383
7947
  _flush() {
8384
- const pending = this._pending;
7948
+ const pending2 = this._pending;
8385
7949
  const pendingLength = this._pendingLength;
8386
7950
  this._pendingLength = 0;
8387
7951
  this._pending = void 0;
8388
- if (pending && pending.size > 0) {
8389
- this._flushPending(pending, pendingLength);
7952
+ if (pending2 && pending2.size > 0) {
7953
+ this._flushPending(pending2, pendingLength);
8390
7954
  }
8391
7955
  return this;
8392
7956
  }
@@ -10972,11 +10536,11 @@ return true;`);
10972
10536
  setValue(index, value) {
10973
10537
  return super.setValue(index, toUint8Array(value));
10974
10538
  }
10975
- _flushPending(pending, pendingLength) {
10539
+ _flushPending(pending2, pendingLength) {
10976
10540
  const offsets = this._offsets;
10977
10541
  const data = this._values.reserve(pendingLength).buffer;
10978
10542
  let offset = 0;
10979
- for (const [index, value] of pending) {
10543
+ for (const [index, value] of pending2) {
10980
10544
  if (value === void 0) {
10981
10545
  offsets.set(index, 0);
10982
10546
  } else {
@@ -11013,11 +10577,11 @@ return true;`);
11013
10577
  setValue(index, value) {
11014
10578
  return super.setValue(index, toUint8Array(value));
11015
10579
  }
11016
- _flushPending(pending, pendingLength) {
10580
+ _flushPending(pending2, pendingLength) {
11017
10581
  const offsets = this._offsets;
11018
10582
  const data = this._values.reserve(pendingLength).buffer;
11019
10583
  let offset = 0;
11020
- for (const [index, value] of pending) {
10584
+ for (const [index, value] of pending2) {
11021
10585
  if (value === void 0) {
11022
10586
  offsets.set(index, BigInt(0));
11023
10587
  } else {
@@ -11328,10 +10892,10 @@ return true;`);
11328
10892
  this.type = new List2(new Field2(name, child.type, true));
11329
10893
  return this.numChildren - 1;
11330
10894
  }
11331
- _flushPending(pending) {
10895
+ _flushPending(pending2) {
11332
10896
  const offsets = this._offsets;
11333
10897
  const [child] = this.children;
11334
- for (const [index, value] of pending) {
10898
+ for (const [index, value] of pending2) {
11335
10899
  if (typeof value === "undefined") {
11336
10900
  offsets.set(index, 0);
11337
10901
  } else {
@@ -11370,10 +10934,10 @@ return true;`);
11370
10934
  this.type = new LargeList2(new Field2(name, child.type, true));
11371
10935
  return this.numChildren - 1;
11372
10936
  }
11373
- _flushPending(pending) {
10937
+ _flushPending(pending2) {
11374
10938
  const offsets = this._offsets;
11375
10939
  const [child] = this.children;
11376
- for (const [index, value] of pending) {
10940
+ for (const [index, value] of pending2) {
11377
10941
  if (typeof value === "undefined") {
11378
10942
  offsets.set(index, BigInt(0));
11379
10943
  } else {
@@ -11403,11 +10967,11 @@ return true;`);
11403
10967
  }
11404
10968
  setValue(index, value) {
11405
10969
  const row = value instanceof Map ? value : new Map(Object.entries(value));
11406
- const pending = this._pending || (this._pending = /* @__PURE__ */ new Map());
11407
- const current = pending.get(index);
10970
+ const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
10971
+ const current = pending2.get(index);
11408
10972
  current && (this._pendingLength -= current.size);
11409
10973
  this._pendingLength += row.size;
11410
- pending.set(index, row);
10974
+ pending2.set(index, row);
11411
10975
  }
11412
10976
  addChild(child, name = `${this.numChildren}`) {
11413
10977
  if (this.numChildren > 0) {
@@ -11417,10 +10981,10 @@ return true;`);
11417
10981
  this.type = new Map_(new Field2(name, child.type, true), this.type.keysSorted);
11418
10982
  return this.numChildren - 1;
11419
10983
  }
11420
- _flushPending(pending) {
10984
+ _flushPending(pending2) {
11421
10985
  const offsets = this._offsets;
11422
10986
  const [child] = this.children;
11423
- for (const [index, value] of pending) {
10987
+ for (const [index, value] of pending2) {
11424
10988
  if (value === void 0) {
11425
10989
  offsets.set(index, 0);
11426
10990
  } else {
@@ -11629,7 +11193,7 @@ return true;`);
11629
11193
  return super.setValue(index, encodeUtf8(value));
11630
11194
  }
11631
11195
  // @ts-ignore
11632
- _flushPending(pending, pendingLength) {
11196
+ _flushPending(pending2, pendingLength) {
11633
11197
  }
11634
11198
  };
11635
11199
  Utf8Builder.prototype._flushPending = BinaryBuilder.prototype._flushPending;
@@ -11660,7 +11224,7 @@ return true;`);
11660
11224
  return super.setValue(index, encodeUtf8(value));
11661
11225
  }
11662
11226
  // @ts-ignore
11663
- _flushPending(pending, pendingLength) {
11227
+ _flushPending(pending2, pendingLength) {
11664
11228
  }
11665
11229
  };
11666
11230
  LargeUtf8Builder.prototype._flushPending = LargeBinaryBuilder.prototype._flushPending;
@@ -15604,20 +15168,441 @@ return true;`);
15604
15168
  }
15605
15169
  });
15606
15170
 
15607
- // ../core/src/schema-utils/lib/schema/convert-arrow-schema.ts
15608
- function serializeArrowSchema(arrowSchema) {
15609
- return {
15610
- fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
15611
- metadata: serializeArrowMetadata(arrowSchema.metadata)
15612
- };
15171
+ // ../../node_modules/@math.gl/arrow/dist/arrow/indexed-arrow-helpers.js
15172
+ var init_indexed_arrow_helpers = __esm({
15173
+ "../../node_modules/@math.gl/arrow/dist/arrow/indexed-arrow-helpers.js"() {
15174
+ }
15175
+ });
15176
+
15177
+ // ../../node_modules/@math.gl/arrow/dist/arrow/arrow-schema-utils.js
15178
+ var init_arrow_schema_utils = __esm({
15179
+ "../../node_modules/@math.gl/arrow/dist/arrow/arrow-schema-utils.js"() {
15180
+ }
15181
+ });
15182
+
15183
+ // ../../node_modules/@math.gl/arrow/dist/arrow/arrow-data.js
15184
+ function getArrowVariadicBuffers(data) {
15185
+ return data.variadicBuffers ?? [];
15186
+ }
15187
+ function createArrowData(type, offset, length, nullCount, buffers, children, dictionary, variadicBuffers) {
15188
+ return Reflect.construct(Data, [
15189
+ type,
15190
+ offset,
15191
+ length,
15192
+ nullCount,
15193
+ buffers,
15194
+ children,
15195
+ dictionary,
15196
+ variadicBuffers
15197
+ ]);
15613
15198
  }
15614
- function deserializeArrowSchema(schema, options) {
15615
- return new Schema2(
15616
- schema.fields.map((field) => deserializeArrowField(field, options)),
15617
- deserializeArrowMetadata(schema.metadata)
15618
- );
15199
+ var init_arrow_data = __esm({
15200
+ "../../node_modules/@math.gl/arrow/dist/arrow/arrow-data.js"() {
15201
+ init_Arrow_dom();
15202
+ }
15203
+ });
15204
+
15205
+ // ../../node_modules/@math.gl/arrow/dist/arrow/arrow-record-batch.js
15206
+ function getRecordBatchMetadata(batch) {
15207
+ return batch.metadata;
15619
15208
  }
15620
- function serializeArrowMetadata(arrowMetadata) {
15209
+ function createRecordBatchWithMetadata(schema, data, metadata) {
15210
+ if ("metadata" in RecordBatch3.prototype) {
15211
+ const MetadataRecordBatch = RecordBatch3;
15212
+ return Object.assign(new MetadataRecordBatch(schema, data, metadata), { data });
15213
+ }
15214
+ const batch = Object.assign(new RecordBatch3(schema, data), { data });
15215
+ return metadata === void 0 ? batch : Object.assign(batch, { metadata });
15216
+ }
15217
+ var init_arrow_record_batch = __esm({
15218
+ "../../node_modules/@math.gl/arrow/dist/arrow/arrow-record-batch.js"() {
15219
+ init_Arrow_dom();
15220
+ }
15221
+ });
15222
+
15223
+ // ../../node_modules/@math.gl/arrow/dist/arrow/arrow-column-utils.js
15224
+ function isArrowTable2(value) {
15225
+ const table = value;
15226
+ return Boolean(table && Number.isInteger(table.numRows) && Array.isArray(table.batches) && Array.isArray(table.schema?.fields) && typeof table.get === "function" && typeof table.getChild === "function");
15227
+ }
15228
+ function isArrowRecordBatch2(value) {
15229
+ const batch = value;
15230
+ return Boolean(batch && Number.isInteger(batch.numRows) && Array.isArray(batch.schema?.fields) && Array.isArray(batch.data?.children) && typeof batch.get === "function" && typeof batch.getChild === "function");
15231
+ }
15232
+ var init_arrow_column_utils = __esm({
15233
+ "../../node_modules/@math.gl/arrow/dist/arrow/arrow-column-utils.js"() {
15234
+ }
15235
+ });
15236
+
15237
+ // ../../node_modules/@math.gl/arrow/dist/arrow/split-arrow-buffers.js
15238
+ function splitArrowBuffers(input, options = {}) {
15239
+ const retainedBuffers = /* @__PURE__ */ new Set();
15240
+ const visited = /* @__PURE__ */ new Set();
15241
+ for (const retained of options.retain ?? []) {
15242
+ const chunks = isArrowTable2(retained) ? retained.batches.map((batch) => batch.data) : isArrowVector2(retained) ? retained.data : [isArrowRecordBatch2(retained) ? retained.data : retained];
15243
+ for (const data of chunks)
15244
+ collectArrowBuffers(data, retainedBuffers, visited);
15245
+ }
15246
+ const context = { ...options, copies: /* @__PURE__ */ new WeakMap(), retainedBuffers };
15247
+ if (isArrowTable2(input)) {
15248
+ return splitArrowTableBuffersInternal(input, context);
15249
+ }
15250
+ if (isArrowRecordBatch2(input)) {
15251
+ return splitArrowRecordBatchBuffers(input, context);
15252
+ }
15253
+ if (isArrowVector2(input)) {
15254
+ return splitArrowVectorBuffers(input, context);
15255
+ }
15256
+ return splitArrowDataBuffers(input, context);
15257
+ }
15258
+ function isArrowVector2(input) {
15259
+ return "data" in input && Array.isArray(input.data);
15260
+ }
15261
+ function splitArrowTableBuffersInternal(arrowTable, options) {
15262
+ const recordBatches = arrowTable.batches.map((recordBatch) => splitArrowRecordBatchBuffers(recordBatch, options));
15263
+ return new Table(arrowTable.schema, recordBatches);
15264
+ }
15265
+ function splitArrowRecordBatchBuffers(recordBatch, options) {
15266
+ const data = splitArrowDataBuffers(recordBatch.data, options);
15267
+ return createRecordBatchWithMetadata(recordBatch.schema, data, getRecordBatchMetadata(recordBatch));
15268
+ }
15269
+ function splitArrowDataBuffers(data, options) {
15270
+ const children = data.children.map((childData) => splitArrowDataBuffers(childData, options));
15271
+ const dictionary = data.dictionary ? splitArrowVectorBuffers(data.dictionary, options) : void 0;
15272
+ const buffers = {
15273
+ [BufferType.OFFSET]: splitArrowBuffer(data.buffers[BufferType.OFFSET], options),
15274
+ [BufferType.DATA]: splitArrowBuffer(data.buffers[BufferType.DATA], options),
15275
+ [BufferType.VALIDITY]: splitArrowBuffer(data.buffers[BufferType.VALIDITY], options),
15276
+ [BufferType.TYPE]: splitArrowBuffer(data.buffers[BufferType.TYPE], options)
15277
+ };
15278
+ return createArrowData(
15279
+ data.type,
15280
+ data.offset,
15281
+ data.length,
15282
+ // @ts-expect-error _nullCount is protected. Reuse it to preserve lazy null-count state.
15283
+ data._nullCount,
15284
+ buffers,
15285
+ children,
15286
+ dictionary,
15287
+ getArrowVariadicBuffers(data).map((buffer) => splitArrowBuffer(buffer, options))
15288
+ );
15289
+ }
15290
+ function splitArrowVectorBuffers(vector, options) {
15291
+ return new Vector(vector.data.map((data) => splitArrowDataBuffers(data, options)));
15292
+ }
15293
+ function collectArrowBuffers(data, buffers, visited) {
15294
+ if (visited.has(data))
15295
+ return;
15296
+ visited.add(data);
15297
+ for (const view of [...Object.values(data.buffers), ...getArrowVariadicBuffers(data)]) {
15298
+ if (isArrowTypedArray(view))
15299
+ buffers.add(view.buffer);
15300
+ }
15301
+ for (const child of data.children)
15302
+ collectArrowBuffers(child, buffers, visited);
15303
+ for (const chunk of data.dictionary?.data ?? [])
15304
+ collectArrowBuffers(chunk, buffers, visited);
15305
+ }
15306
+ function splitArrowBuffer(array, options) {
15307
+ if (!isArrowTypedArray(array)) {
15308
+ return array;
15309
+ }
15310
+ const sliced = array.byteOffset !== 0 || array.byteLength !== array.buffer.byteLength;
15311
+ if (!options.retainedBuffers.has(array.buffer) && options.copy !== "all" && (options.copy === "none" || !sliced)) {
15312
+ return array;
15313
+ }
15314
+ let copy = options.copies.get(array);
15315
+ if (!copy) {
15316
+ copy = array instanceof Uint8Array ? new Uint8Array(array) : array.slice();
15317
+ options.copies.set(array, copy);
15318
+ }
15319
+ return copy;
15320
+ }
15321
+ function isArrowTypedArray(value) {
15322
+ return ArrayBuffer.isView(value) && !(value instanceof DataView);
15323
+ }
15324
+ var init_split_arrow_buffers = __esm({
15325
+ "../../node_modules/@math.gl/arrow/dist/arrow/split-arrow-buffers.js"() {
15326
+ init_Arrow_dom();
15327
+ init_arrow_record_batch();
15328
+ init_arrow_data();
15329
+ init_arrow_column_utils();
15330
+ }
15331
+ });
15332
+
15333
+ // ../../node_modules/@math.gl/arrow/dist/arrow/take-arrow-rows.js
15334
+ var init_take_arrow_rows = __esm({
15335
+ "../../node_modules/@math.gl/arrow/dist/arrow/take-arrow-rows.js"() {
15336
+ init_arrow_data();
15337
+ init_split_arrow_buffers();
15338
+ }
15339
+ });
15340
+
15341
+ // ../../node_modules/@math.gl/arrow/dist/arrow/indexed-arrow-vector.js
15342
+ var init_indexed_arrow_vector = __esm({
15343
+ "../../node_modules/@math.gl/arrow/dist/arrow/indexed-arrow-vector.js"() {
15344
+ init_indexed_arrow_helpers();
15345
+ }
15346
+ });
15347
+
15348
+ // ../../node_modules/@math.gl/arrow/dist/arrow/indexed-arrow-table.js
15349
+ var init_indexed_arrow_table = __esm({
15350
+ "../../node_modules/@math.gl/arrow/dist/arrow/indexed-arrow-table.js"() {
15351
+ init_indexed_arrow_helpers();
15352
+ init_arrow_schema_utils();
15353
+ init_take_arrow_rows();
15354
+ init_indexed_arrow_vector();
15355
+ }
15356
+ });
15357
+
15358
+ // ../../node_modules/@math.gl/arrow/dist/arrow/mapped-arrow-table.js
15359
+ var init_mapped_arrow_table = __esm({
15360
+ "../../node_modules/@math.gl/arrow/dist/arrow/mapped-arrow-table.js"() {
15361
+ init_indexed_arrow_helpers();
15362
+ init_indexed_arrow_table();
15363
+ }
15364
+ });
15365
+
15366
+ // ../../node_modules/@math.gl/arrow/dist/arrow/rename-arrow-columns.js
15367
+ var init_rename_arrow_columns = __esm({
15368
+ "../../node_modules/@math.gl/arrow/dist/arrow/rename-arrow-columns.js"() {
15369
+ init_arrow_schema_utils();
15370
+ }
15371
+ });
15372
+
15373
+ // ../../node_modules/@math.gl/arrow/dist/arrow/arrow-table-transport.js
15374
+ function dehydrateArrowTable(arrowTable, options) {
15375
+ const splitTable = splitArrowBuffers(arrowTable, options);
15376
+ return {
15377
+ transport: "arrow-js",
15378
+ version: 1,
15379
+ schema: tableToIPC(new Table(splitTable.schema, [])),
15380
+ metadataVersion: splitTable.schema.metadataVersion,
15381
+ batches: splitTable.batches.map((batch) => {
15382
+ const metadata = getRecordBatchMetadata(batch);
15383
+ return {
15384
+ ...dehydrateArrowData(batch.data),
15385
+ ...metadata !== void 0 ? { metadata: [...metadata] } : {}
15386
+ };
15387
+ })
15388
+ };
15389
+ }
15390
+ function hydrateArrowTable(table) {
15391
+ if (table.transport !== "arrow-js" || table.version !== 1) {
15392
+ throw new Error("Unsupported Arrow column-buffer transport protocol.");
15393
+ }
15394
+ const decodedSchema = tableFromIPC(table.schema).schema;
15395
+ const schema = new Schema2(decodedSchema.fields, decodedSchema.metadata, decodedSchema.dictionaries, table.metadataVersion);
15396
+ const type = new Struct(schema.fields);
15397
+ const batches = table.batches.map((payload) => {
15398
+ const data = hydrateArrowData(payload, type);
15399
+ return createRecordBatchWithMetadata(schema, data, payload.metadata && new Map(payload.metadata));
15400
+ });
15401
+ return new Table(schema, batches);
15402
+ }
15403
+ function dehydrateArrowData(data) {
15404
+ return {
15405
+ offset: data.offset,
15406
+ length: data.length,
15407
+ nullCount: data.nullCount,
15408
+ buffers: {
15409
+ [BufferType.OFFSET]: data.buffers[BufferType.OFFSET],
15410
+ [BufferType.DATA]: data.buffers[BufferType.DATA],
15411
+ [BufferType.VALIDITY]: data.buffers[BufferType.VALIDITY],
15412
+ [BufferType.TYPE]: data.buffers[BufferType.TYPE]
15413
+ },
15414
+ children: data.children.map((child) => dehydrateArrowData(child)),
15415
+ variadicBuffers: getArrowVariadicBuffers(data),
15416
+ dictionary: data.dictionary?.data.map((chunk) => dehydrateArrowData(chunk))
15417
+ };
15418
+ }
15419
+ function hydrateArrowData(data, type) {
15420
+ const children = data.children.map((child, index) => hydrateArrowData(child, type.children[index].type));
15421
+ const dictionary = data.dictionary && DataType.isDictionary(type) ? new Vector(data.dictionary.map((chunk) => hydrateArrowData(chunk, type.dictionary))) : void 0;
15422
+ return createArrowData(type, data.offset, data.length, data.nullCount, data.buffers, children, dictionary, data.variadicBuffers);
15423
+ }
15424
+ function dehydrateArrowRecordBatch(batch, options) {
15425
+ return dehydrateArrowTable(new Table(batch.schema, [batch]), options);
15426
+ }
15427
+ function hydrateArrowRecordBatch(payload) {
15428
+ if (payload.batches.length !== 1) {
15429
+ throw new Error("Arrow record batch transport requires exactly one batch.");
15430
+ }
15431
+ return hydrateArrowTable(payload).batches[0];
15432
+ }
15433
+ var init_arrow_table_transport = __esm({
15434
+ "../../node_modules/@math.gl/arrow/dist/arrow/arrow-table-transport.js"() {
15435
+ init_Arrow_dom();
15436
+ init_arrow_record_batch();
15437
+ init_arrow_data();
15438
+ init_split_arrow_buffers();
15439
+ }
15440
+ });
15441
+
15442
+ // ../../node_modules/@math.gl/arrow/dist/arrow/index.js
15443
+ var init_arrow = __esm({
15444
+ "../../node_modules/@math.gl/arrow/dist/arrow/index.js"() {
15445
+ init_indexed_arrow_table();
15446
+ init_indexed_arrow_vector();
15447
+ init_mapped_arrow_table();
15448
+ init_arrow_schema_utils();
15449
+ init_rename_arrow_columns();
15450
+ init_split_arrow_buffers();
15451
+ init_arrow_table_transport();
15452
+ init_arrow_column_utils();
15453
+ init_take_arrow_rows();
15454
+ init_arrow_record_batch();
15455
+ }
15456
+ });
15457
+
15458
+ // ../../node_modules/@math.gl/arrow/dist/index.js
15459
+ var init_dist2 = __esm({
15460
+ "../../node_modules/@math.gl/arrow/dist/index.js"() {
15461
+ init_arrow();
15462
+ }
15463
+ });
15464
+
15465
+ // ../core/src/arrow-worker-transport.ts
15466
+ function serializeNativeArrowWorkerResult(result, options = { copy: "all" }) {
15467
+ const batch = result instanceof RecordBatch3;
15468
+ if (!batch && !(result instanceof Table)) {
15469
+ throw new Error("Workers require Arrow table output");
15470
+ }
15471
+ return {
15472
+ transport: batch ? "arrow-record-batch" : "arrow-table-columns",
15473
+ columns: batch ? { data: dehydrateArrowRecordBatch(result, options) } : serializeWorkerColumns(result, options)
15474
+ };
15475
+ }
15476
+ function deserializeNativeArrowWorkerResult(result) {
15477
+ const payload = result;
15478
+ if (payload?.transport !== "arrow-table-columns" && payload?.transport !== "arrow-record-batch" || !hasArrowWorkerColumns(payload.columns)) {
15479
+ throw new Error("Workers require Arrow column transport");
15480
+ }
15481
+ if (payload.transport === "arrow-record-batch" && !payload.columns.arrowBatchMetadata) {
15482
+ return hydrateArrowRecordBatch(payload.columns.data);
15483
+ }
15484
+ const data = hydrateWorkerTable(payload.columns);
15485
+ return payload.transport === "arrow-record-batch" ? data.batches[0] : data;
15486
+ }
15487
+ function serializeArrowWorkerResult(result, options) {
15488
+ const workerOptions = options;
15489
+ const copy = workerOptions?.core?.workerTransferBufferCopy ?? workerOptions?.workerTransferBufferCopy;
15490
+ return result instanceof Table || result instanceof RecordBatch3 ? serializeNativeArrowWorkerResult(result, { copy: copy ?? "all" }) : result;
15491
+ }
15492
+ function deserializeArrowWorkerResult(result) {
15493
+ const transport = result?.transport;
15494
+ return transport === "arrow-table-columns" || transport === "arrow-record-batch" ? deserializeNativeArrowWorkerResult(result) : result;
15495
+ }
15496
+ function hasArrowWorkerColumns(value) {
15497
+ const columns = value;
15498
+ return columns?.data?.transport === "arrow-js" && Array.isArray(columns.data.batches);
15499
+ }
15500
+ function serializeWorkerColumns(table, options) {
15501
+ return {
15502
+ arrowBatchMetadata: snapshotBatchMetadata(table),
15503
+ data: dehydrateArrowTable(table, options)
15504
+ };
15505
+ }
15506
+ function snapshotBatchMetadata(table) {
15507
+ return table.batches.map((batch) => ({
15508
+ schema: tableToIPC(new Table(batch.schema, []))
15509
+ }));
15510
+ }
15511
+ function hydrateWorkerTable(result) {
15512
+ const { arrowBatchMetadata, data } = result;
15513
+ const table = hydrateArrowTable(data);
15514
+ const batches = table.batches.map((batch, index) => {
15515
+ const snapshot = arrowBatchMetadata?.[index];
15516
+ return snapshot ? createRecordBatchWithMetadata(
15517
+ tableFromIPC(snapshot.schema).schema,
15518
+ batch.data,
15519
+ snapshot.metadata ? new Map(snapshot.metadata) : getRecordBatchMetadata(batch)
15520
+ ) : batch;
15521
+ });
15522
+ return new Table(table.schema, batches);
15523
+ }
15524
+ var init_arrow_worker_transport = __esm({
15525
+ "../core/src/arrow-worker-transport.ts"() {
15526
+ "use strict";
15527
+ init_Arrow_dom();
15528
+ init_dist2();
15529
+ }
15530
+ });
15531
+
15532
+ // ../core/src/schema-utils/lib/schema/data-type.ts
15533
+ function getDataTypeFromValue(value, defaultNumberType = "float32") {
15534
+ if (value instanceof Date) {
15535
+ return "date-millisecond";
15536
+ }
15537
+ if (typeof value === "number") {
15538
+ return defaultNumberType;
15539
+ }
15540
+ if (typeof value === "boolean") {
15541
+ return "bool";
15542
+ }
15543
+ if (typeof value === "string") {
15544
+ return "utf8";
15545
+ }
15546
+ if (value === null || value === "undefined") {
15547
+ return "null";
15548
+ }
15549
+ return "null";
15550
+ }
15551
+ function getDataTypeFromArray(array) {
15552
+ let type = getDataTypeFromTypedArray(array);
15553
+ if (type !== "null") {
15554
+ return { type, nullable: false };
15555
+ }
15556
+ if (array.length > 0) {
15557
+ type = getDataTypeFromValue(array[0]);
15558
+ return { type, nullable: true };
15559
+ }
15560
+ return { type: "null", nullable: true };
15561
+ }
15562
+ function getDataTypeFromTypedArray(array) {
15563
+ if (typeof Float16Array !== "undefined" && array instanceof Float16Array) {
15564
+ return "float16";
15565
+ }
15566
+ switch (array.constructor) {
15567
+ case Int8Array:
15568
+ return "int8";
15569
+ case Uint8Array:
15570
+ case Uint8ClampedArray:
15571
+ return "uint8";
15572
+ case Int16Array:
15573
+ return "int16";
15574
+ case Uint16Array:
15575
+ return "uint16";
15576
+ case Int32Array:
15577
+ return "int32";
15578
+ case Uint32Array:
15579
+ return "uint32";
15580
+ case BigInt64Array:
15581
+ return "int64";
15582
+ case BigUint64Array:
15583
+ return "uint64";
15584
+ case Float32Array:
15585
+ return "float32";
15586
+ case Float64Array:
15587
+ return "float64";
15588
+ default:
15589
+ return "null";
15590
+ }
15591
+ }
15592
+ var init_data_type = __esm({
15593
+ "../core/src/schema-utils/lib/schema/data-type.ts"() {
15594
+ "use strict";
15595
+ }
15596
+ });
15597
+
15598
+ // ../core/src/schema-utils/lib/schema/convert-arrow-schema.ts
15599
+ function serializeArrowSchema(arrowSchema) {
15600
+ return {
15601
+ fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
15602
+ metadata: serializeArrowMetadata(arrowSchema.metadata)
15603
+ };
15604
+ }
15605
+ function serializeArrowMetadata(arrowMetadata) {
15621
15606
  return Object.fromEntries(arrowMetadata);
15622
15607
  }
15623
15608
  function deserializeArrowMetadata(metadata) {
@@ -16039,261 +16024,19 @@ return true;`);
16039
16024
  }
16040
16025
  });
16041
16026
 
16042
- // ../core/src/schema-utils/lib/arrow/split-arrow-buffers.ts
16043
- function splitArrowBuffers(input, options = {}) {
16044
- const context = { ...options, copies: /* @__PURE__ */ new WeakMap() };
16045
- if (isArrowTable2(input)) {
16046
- return splitArrowTableBuffersInternal(input, context);
16047
- }
16048
- if (isArrowRecordBatch2(input)) {
16049
- return splitArrowRecordBatchBuffers(input, context);
16050
- }
16051
- if (isArrowVector2(input)) {
16052
- return splitArrowVectorBuffers(input, context);
16053
- }
16054
- return splitArrowDataBuffers(input, context);
16055
- }
16056
- function isArrowTable2(input) {
16057
- return "batches" in input;
16058
- }
16059
- function isArrowRecordBatch2(input) {
16060
- return "schema" in input && "data" in input && !Array.isArray(input.data);
16061
- }
16062
- function isArrowVector2(input) {
16063
- return "data" in input && Array.isArray(input.data);
16064
- }
16065
- function splitArrowTableBuffersInternal(table, options) {
16066
- const recordBatches = table.batches.map(
16067
- (recordBatch) => splitArrowRecordBatchBuffers(recordBatch, options)
16068
- );
16069
- return new Table(table.schema, recordBatches);
16070
- }
16071
- function splitArrowRecordBatchBuffers(recordBatch, options) {
16072
- return new RecordBatch3(
16073
- recordBatch.schema,
16074
- splitArrowDataBuffers(recordBatch.data, options)
16027
+ // ../core/src/lib/loader-utils/native-arrow.ts
16028
+ function isArrowTable3(value) {
16029
+ return Boolean(
16030
+ value && typeof value === "object" && "schema" in value && "batches" in value && Array.isArray(value.batches) && "numRows" in value && typeof value.numRows === "number" && "getChildAt" in value && typeof value.getChildAt === "function"
16075
16031
  );
16076
16032
  }
16077
- function splitArrowDataBuffers(data, options) {
16078
- const children = data.children.map((childData) => splitArrowDataBuffers(childData, options));
16079
- const dictionary = data.dictionary ? splitArrowVectorBuffers(data.dictionary, options) : void 0;
16080
- const buffers = {
16081
- [BufferType.OFFSET]: splitArrowBuffer(data.buffers[BufferType.OFFSET], options),
16082
- [BufferType.DATA]: splitArrowBuffer(data.buffers[BufferType.DATA], options),
16083
- [BufferType.VALIDITY]: splitArrowBuffer(data.buffers[BufferType.VALIDITY], options),
16084
- [BufferType.TYPE]: splitArrowBuffer(data.buffers[BufferType.TYPE], options)
16085
- };
16086
- return new Data(
16087
- data.type,
16088
- data.offset,
16089
- data.length,
16090
- // @ts-expect-error _nullCount is protected. Reuse it to preserve lazy null-count state.
16091
- data._nullCount,
16092
- buffers,
16093
- children,
16094
- dictionary
16095
- );
16096
- }
16097
- function splitArrowVectorBuffers(vector, options) {
16098
- return new Vector(vector.data.map((data) => splitArrowDataBuffers(data, options)));
16099
- }
16100
- function splitArrowBuffer(array, options) {
16101
- if (!isArrowTypedArray(array)) {
16102
- return array;
16103
- }
16104
- if (options.copy === "none") {
16105
- return array;
16106
- }
16107
- if (options.copy !== "all" && array.byteOffset === 0 && array.byteLength === array.buffer.byteLength) {
16108
- return array;
16109
- }
16110
- let copy = options.copies.get(array);
16111
- if (!copy) {
16112
- copy = array.slice();
16113
- options.copies.set(array, copy);
16114
- }
16115
- return copy;
16116
- }
16117
- function isArrowTypedArray(value) {
16118
- return ArrayBuffer.isView(value) && !(value instanceof DataView);
16119
- }
16120
- var init_split_arrow_buffers = __esm({
16121
- "../core/src/schema-utils/lib/arrow/split-arrow-buffers.ts"() {
16122
- "use strict";
16123
- init_Arrow_dom();
16124
- }
16125
- });
16126
-
16127
- // ../core/src/schema-utils/lib/arrow/arrow-table-transport.ts
16128
- function dehydrateArrowTable(table, options) {
16129
- const splitTable = splitArrowBuffers(table, options);
16130
- return {
16131
- shape: "arrow-table",
16132
- transport: "arrow-js",
16133
- schema: serializeArrowSchema(splitTable.schema),
16134
- batches: splitTable.batches.map((recordBatch) => dehydrateArrowRecordBatch(recordBatch))
16135
- };
16136
- }
16137
- function hydrateArrowTable(table) {
16138
- const schema = deserializeArrowSchema(table.schema);
16139
- const recordBatches = table.batches.map(
16140
- (recordBatch) => new RecordBatch3(schema, hydrateArrowData(recordBatch.data))
16141
- );
16142
- return new Table(schema, recordBatches);
16143
- }
16144
- function serializeArrowWorkerResult(result, options) {
16145
- if (!isArrowTableWrapper(result)) {
16146
- return result;
16147
- }
16148
- const workerOptions = options;
16149
- const bufferCopyMode = workerOptions?.core?.workerTransferBufferCopy ?? workerOptions?.workerTransferBufferCopy;
16150
- return {
16151
- ...result,
16152
- data: dehydrateArrowTable(result.data, bufferCopyMode ? { copy: bufferCopyMode } : void 0)
16153
- };
16154
- }
16155
- function deserializeArrowWorkerResult(result) {
16156
- if (!isDehydratedArrowTableWrapper(result)) {
16157
- return result;
16158
- }
16159
- return { ...result, data: hydrateArrowTable(result.data) };
16160
- }
16161
- function isArrowTableWrapper(value) {
16162
- const table = value;
16163
- return Boolean(
16164
- table && table.shape === "arrow-table" && table.data && typeof table.data === "object" && "batches" in table.data
16165
- );
16166
- }
16167
- function isDehydratedArrowTableWrapper(value) {
16168
- const table = value;
16169
- return Boolean(
16170
- table && table.shape === "arrow-table" && table.data && table.data.transport === "arrow-js" && Array.isArray(table.data.batches)
16171
- );
16172
- }
16173
- function dehydrateArrowRecordBatch(recordBatch) {
16174
- return { data: dehydrateArrowData(recordBatch.data) };
16175
- }
16176
- function dehydrateArrowData(data) {
16177
- return {
16178
- type: serializeArrowType(data.type),
16179
- offset: data.offset,
16180
- length: data.length,
16181
- // @ts-expect-error _nullCount is protected. Preserve the Arrow lazy null-count state.
16182
- nullCount: data._nullCount,
16183
- buffers: {
16184
- [BufferType.OFFSET]: data.buffers[BufferType.OFFSET],
16185
- [BufferType.DATA]: data.buffers[BufferType.DATA],
16186
- [BufferType.VALIDITY]: data.buffers[BufferType.VALIDITY],
16187
- [BufferType.TYPE]: data.buffers[BufferType.TYPE]
16188
- },
16189
- children: data.children.map((childData) => dehydrateArrowData(childData)),
16190
- dictionary: data.dictionary ? dehydrateArrowVector(data.dictionary) : void 0
16191
- };
16192
- }
16193
- function dehydrateArrowVector(vector) {
16194
- return { data: vector.data.map((data) => dehydrateArrowData(data)) };
16195
- }
16196
- function hydrateArrowData(data) {
16197
- const children = data.children.map((childData) => hydrateArrowData(childData));
16198
- const dictionary = data.dictionary ? hydrateArrowVector(data.dictionary) : void 0;
16199
- return new Data(
16200
- deserializeArrowType(data.type),
16201
- data.offset,
16202
- data.length,
16203
- data.nullCount,
16204
- data.buffers,
16205
- children,
16206
- dictionary
16207
- );
16208
- }
16209
- function hydrateArrowVector(vector) {
16210
- return new Vector(vector.data.map((data) => hydrateArrowData(data)));
16211
- }
16212
- var init_arrow_table_transport = __esm({
16213
- "../core/src/schema-utils/lib/arrow/arrow-table-transport.ts"() {
16214
- "use strict";
16215
- init_Arrow_dom();
16216
- init_convert_arrow_schema();
16217
- init_split_arrow_buffers();
16218
- }
16219
- });
16220
-
16221
- // ../core/src/schema-utils/arrow-transport.ts
16222
- var init_arrow_transport = __esm({
16223
- "../core/src/schema-utils/arrow-transport.ts"() {
16224
- "use strict";
16225
- init_arrow_table_transport();
16226
- init_split_arrow_buffers();
16227
- }
16228
- });
16229
-
16230
- // ../core/src/schema-utils/lib/schema/data-type.ts
16231
- function getDataTypeFromValue(value, defaultNumberType = "float32") {
16232
- if (value instanceof Date) {
16233
- return "date-millisecond";
16234
- }
16235
- if (typeof value === "number") {
16236
- return defaultNumberType;
16237
- }
16238
- if (typeof value === "boolean") {
16239
- return "bool";
16240
- }
16241
- if (typeof value === "string") {
16242
- return "utf8";
16243
- }
16244
- if (value === null || value === "undefined") {
16245
- return "null";
16246
- }
16247
- return "null";
16248
- }
16249
- function getDataTypeFromArray(array) {
16250
- let type = getDataTypeFromTypedArray(array);
16251
- if (type !== "null") {
16252
- return { type, nullable: false };
16253
- }
16254
- if (array.length > 0) {
16255
- type = getDataTypeFromValue(array[0]);
16256
- return { type, nullable: true };
16257
- }
16258
- return { type: "null", nullable: true };
16259
- }
16260
- function getDataTypeFromTypedArray(array) {
16261
- if (typeof Float16Array !== "undefined" && array instanceof Float16Array) {
16262
- return "float16";
16263
- }
16264
- switch (array.constructor) {
16265
- case Int8Array:
16266
- return "int8";
16267
- case Uint8Array:
16268
- case Uint8ClampedArray:
16269
- return "uint8";
16270
- case Int16Array:
16271
- return "int16";
16272
- case Uint16Array:
16273
- return "uint16";
16274
- case Int32Array:
16275
- return "int32";
16276
- case Uint32Array:
16277
- return "uint32";
16278
- case BigInt64Array:
16279
- return "int64";
16280
- case BigUint64Array:
16281
- return "uint64";
16282
- case Float32Array:
16283
- return "float32";
16284
- case Float64Array:
16285
- return "float64";
16286
- default:
16287
- return "null";
16288
- }
16289
- }
16290
- var init_data_type = __esm({
16291
- "../core/src/schema-utils/lib/schema/data-type.ts"() {
16033
+ var init_native_arrow = __esm({
16034
+ "../core/src/lib/loader-utils/native-arrow.ts"() {
16292
16035
  "use strict";
16293
16036
  }
16294
16037
  });
16295
16038
 
16296
- // ../core/src/schema-utils/lib/mesh/mesh-utils.ts
16039
+ // ../core/src/schema-utils/lib/mesh/get-mesh-bounding-box.ts
16297
16040
  function getMeshBoundingBox(attributes) {
16298
16041
  const positionAttribute = attributes?.POSITION;
16299
16042
  if (!positionAttribute || !("value" in positionAttribute) || !positionAttribute.value.length) {
@@ -16323,9 +16066,17 @@ return true;`);
16323
16066
  [maxX, maxY, maxZ]
16324
16067
  ];
16325
16068
  }
16069
+ var init_get_mesh_bounding_box = __esm({
16070
+ "../core/src/schema-utils/lib/mesh/get-mesh-bounding-box.ts"() {
16071
+ "use strict";
16072
+ }
16073
+ });
16074
+
16075
+ // ../core/src/schema-utils/lib/mesh/mesh-utils.ts
16326
16076
  var init_mesh_utils = __esm({
16327
16077
  "../core/src/schema-utils/lib/mesh/mesh-utils.ts"() {
16328
16078
  "use strict";
16079
+ init_get_mesh_bounding_box();
16329
16080
  }
16330
16081
  });
16331
16082
 
@@ -16478,31 +16229,7 @@ return true;`);
16478
16229
  });
16479
16230
 
16480
16231
  // ../core/src/schema-utils/lib/mesh/convert-mesh-to-table.ts
16481
- function convertMeshToTable(mesh, shape) {
16482
- switch (shape) {
16483
- case "columnar-table":
16484
- return convertMeshToColumnarTable(mesh);
16485
- case "arrow-table":
16486
- return convertMeshToArrowTable(mesh);
16487
- default:
16488
- throw new Error(shape);
16489
- }
16490
- }
16491
- function convertMeshToColumnarTable(mesh) {
16492
- const columns = {};
16493
- const hasIndices = hasMeshIndices(mesh);
16494
- for (const [columnName, attribute] of Object.entries(mesh.attributes)) {
16495
- columns[columnName] = attribute.value;
16496
- }
16497
- return {
16498
- shape: "columnar-table",
16499
- schema: mesh.schema,
16500
- data: columns,
16501
- topology: mesh.topology,
16502
- indices: hasIndices ? mesh.indices : void 0
16503
- };
16504
- }
16505
- function convertMeshToArrowTable(mesh, batchSize) {
16232
+ function convertMeshToArrowTable(mesh) {
16506
16233
  return makeMeshArrowTable(mesh.attributes, {
16507
16234
  schema: mesh.schema,
16508
16235
  topology: mesh.topology,
@@ -16523,22 +16250,14 @@ return true;`);
16523
16250
  fields.push(
16524
16251
  getAttributeArrowField(options.schema, attributeName, column, attribute.componentType)
16525
16252
  );
16526
- if (attributeName === "POSITION" && options.indices?.value?.length) {
16253
+ if (attributeName === attributeNames[0] && options.indices?.value?.length) {
16527
16254
  const indicesField = indexedMeshArrowSchema.fields.find((field) => field.name === "indices");
16528
16255
  columns.indices = getIndicesVector(options.indices.value, column.length, indicesField.type);
16529
16256
  fields.push(indicesField);
16530
16257
  }
16531
16258
  }
16532
16259
  const arrowSchema = new Schema2(fields, getMeshArrowMetadata(options));
16533
- const table = columns[attributeNames[0]]?.length === 0 ? new Table(arrowSchema) : new Table(arrowSchema, columns);
16534
- const schema = serializeArrowSchema(table.schema);
16535
- return {
16536
- shape: "arrow-table",
16537
- schema,
16538
- data: table,
16539
- topology: options.topology || "point-list",
16540
- indices: options.indices
16541
- };
16260
+ return columns[attributeNames[0]]?.length === 0 ? new Table(arrowSchema) : new Table(arrowSchema, columns);
16542
16261
  }
16543
16262
  function getAttributeArrowVector(value, size, componentType) {
16544
16263
  if (componentType === "float16") {
@@ -16663,18 +16382,13 @@ return true;`);
16663
16382
 
16664
16383
  // ../core/src/schema-utils/lib/mesh/convert-table-to-mesh.ts
16665
16384
  function convertTableToMesh(table) {
16666
- switch (table.shape) {
16667
- // case 'columnar-table':
16668
- // return convertColumnarTableToMesh(table);
16669
- case "arrow-table":
16670
- return convertArrowTableToMesh(table);
16671
- default:
16672
- throw new Error(table.shape);
16673
- }
16385
+ if (isArrowTable3(table)) return convertArrowTableToMesh(table);
16386
+ throw new Error(table.shape);
16674
16387
  }
16675
- function convertArrowTableToMesh(table) {
16676
- const arrowTable = table.data;
16388
+ function convertArrowTableToMesh(arrowTable) {
16677
16389
  const schema = serializeArrowSchema(arrowTable.schema);
16390
+ const localBounds = arrowTable.batches.length === 1 ? arrowTable.batches[0].metadata.get("boundingBox") : void 0;
16391
+ if (localBounds) schema.metadata = { ...schema.metadata, boundingBox: localBounds };
16678
16392
  const fields = schema.fields;
16679
16393
  const attributes = {};
16680
16394
  const columns = [];
@@ -16775,13 +16489,18 @@ return true;`);
16775
16489
  if (!(attributeData.type instanceof FixedSizeList2)) {
16776
16490
  return attributeData.toArray();
16777
16491
  }
16778
- const values = attributeData.data[0].children[0].values;
16492
+ if (attributeData.length === 0) {
16493
+ const EmptyStorage = attributeData.type.valueType.ArrayType;
16494
+ return new EmptyStorage(0);
16495
+ }
16496
+ const values = attributeData.data.find((chunk) => chunk.length > 0).children[0].values;
16779
16497
  const TypedArrayConstructor = values.constructor;
16780
16498
  const typedArray = new TypedArrayConstructor(attributeData.length * size);
16781
16499
  let targetOffset = 0;
16782
16500
  for (const data of attributeData.data) {
16783
- const child = data.children[0];
16784
16501
  const sourceLength = data.length * size;
16502
+ if (sourceLength === 0) continue;
16503
+ const child = data.children[0];
16785
16504
  const sourceOffset = child.offset || data.offset * size;
16786
16505
  const sourceStart = sourceOffset + sourceLength <= child.values.length ? sourceOffset : 0;
16787
16506
  const source = child.values.subarray(sourceStart, sourceStart + sourceLength);
@@ -16829,6 +16548,7 @@ return true;`);
16829
16548
  init_Arrow_dom();
16830
16549
  init_arrow_fixed_size_list_utils();
16831
16550
  init_convert_arrow_schema();
16551
+ init_native_arrow();
16832
16552
  init_mesh_utils();
16833
16553
  }
16834
16554
  });
@@ -17136,106 +16856,52 @@ return true;`);
17136
16856
 
17137
16857
  // src/terrain/lib/helpers/skirt.ts
17138
16858
  function addSkirt(attributes, triangles, skirtHeight, outsideIndices) {
17139
- const outsideEdges = outsideIndices ? getOutsideEdgesFromIndices(outsideIndices, attributes.POSITION.value) : getOutsideEdgesFromTriangles(triangles);
17140
- const newPosition = new attributes.POSITION.value.constructor(outsideEdges.length * 6);
17141
- const newTexcoord0 = new attributes.TEXCOORD_0.value.constructor(outsideEdges.length * 4);
17142
- const newTriangles = new triangles.constructor(outsideEdges.length * 6);
17143
- for (let i = 0; i < outsideEdges.length; i++) {
17144
- const edge = outsideEdges[i];
17145
- updateAttributesForNewEdge({
17146
- edge,
17147
- edgeIndex: i,
17148
- attributes,
17149
- skirtHeight,
17150
- newPosition,
17151
- newTexcoord0,
17152
- newTriangles
17153
- });
16859
+ const positions = attributes.POSITION.value;
16860
+ const sourceIndices = Array.isArray(triangles) ? Uint32Array.from(triangles) : triangles;
16861
+ const edges = outsideIndices ? getBoundaryEdges(outsideIndices, positions) : void 0;
16862
+ const skirt = createTerrainSkirt(
16863
+ { positions, indices: sourceIndices },
16864
+ { height: skirtHeight, edges }
16865
+ );
16866
+ const textureCoordinates = attributes.TEXCOORD_0.value;
16867
+ const outputTextureCoordinates = new textureCoordinates.constructor(
16868
+ skirt.positions.length / 3 * 2
16869
+ );
16870
+ outputTextureCoordinates.set(textureCoordinates);
16871
+ for (let i = 0; i < skirt.sourceVertexIndices.length; i++) {
16872
+ const source = skirt.sourceVertexIndices[i];
16873
+ outputTextureCoordinates.set(
16874
+ textureCoordinates.subarray(source * 2, source * 2 + 2),
16875
+ (skirt.skirtVertexOffset + i) * 2
16876
+ );
17154
16877
  }
17155
- attributes.POSITION.value = concatenateTypedArrays(attributes.POSITION.value, newPosition);
17156
- attributes.TEXCOORD_0.value = concatenateTypedArrays(attributes.TEXCOORD_0.value, newTexcoord0);
17157
- const resultTriangles = triangles instanceof Array ? triangles.concat(newTriangles) : concatenateTypedArrays(triangles, newTriangles);
16878
+ attributes.POSITION.value = skirt.positions;
16879
+ attributes.TEXCOORD_0.value = outputTextureCoordinates;
17158
16880
  return {
17159
16881
  attributes,
17160
- triangles: resultTriangles
16882
+ triangles: Array.isArray(triangles) ? Array.from(skirt.indices) : skirt.indices
17161
16883
  };
17162
16884
  }
17163
- function getOutsideEdgesFromTriangles(triangles) {
17164
- const edges = [];
17165
- for (let i = 0; i < triangles.length; i += 3) {
17166
- edges.push([triangles[i], triangles[i + 1]]);
17167
- edges.push([triangles[i + 1], triangles[i + 2]]);
17168
- edges.push([triangles[i + 2], triangles[i]]);
17169
- }
17170
- edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));
17171
- const outsideEdges = [];
17172
- let index = 0;
17173
- while (index < edges.length) {
17174
- if (edges[index][0] === edges[index + 1]?.[1] && edges[index][1] === edges[index + 1]?.[0]) {
17175
- index += 2;
17176
- } else {
17177
- outsideEdges.push(edges[index]);
17178
- index++;
17179
- }
17180
- }
17181
- return outsideEdges;
17182
- }
17183
- function getOutsideEdgesFromIndices(indices, position) {
17184
- indices.westIndices.sort((a, b) => position[3 * a + 1] - position[3 * b + 1]);
17185
- indices.eastIndices.sort((a, b) => position[3 * b + 1] - position[3 * a + 1]);
17186
- indices.southIndices.sort((a, b) => position[3 * b] - position[3 * a]);
17187
- indices.northIndices.sort((a, b) => position[3 * a] - position[3 * b]);
16885
+ function getBoundaryEdges(indices, positions) {
16886
+ indices.westIndices.sort((a, b) => positions[3 * a + 1] - positions[3 * b + 1]);
16887
+ indices.eastIndices.sort((a, b) => positions[3 * b + 1] - positions[3 * a + 1]);
16888
+ indices.southIndices.sort((a, b) => positions[3 * b] - positions[3 * a]);
16889
+ indices.northIndices.sort((a, b) => positions[3 * a] - positions[3 * b]);
17188
16890
  const edges = [];
17189
- for (const index in indices) {
17190
- const indexGroup = indices[index];
17191
- for (let i = 0; i < indexGroup.length - 1; i++) {
17192
- edges.push([indexGroup[i], indexGroup[i + 1]]);
17193
- }
16891
+ for (const side of [
16892
+ indices.westIndices,
16893
+ indices.northIndices,
16894
+ indices.eastIndices,
16895
+ indices.southIndices
16896
+ ]) {
16897
+ for (let i = 1; i < side.length; i++) edges.push(side[i - 1], side[i]);
17194
16898
  }
17195
- return edges;
17196
- }
17197
- function updateAttributesForNewEdge({
17198
- edge,
17199
- edgeIndex,
17200
- attributes,
17201
- skirtHeight,
17202
- newPosition,
17203
- newTexcoord0,
17204
- newTriangles
17205
- }) {
17206
- const positionsLength = attributes.POSITION.value.length;
17207
- const vertex1Offset = edgeIndex * 2;
17208
- const vertex2Offset = edgeIndex * 2 + 1;
17209
- newPosition.set(
17210
- attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3),
17211
- vertex1Offset * 3
17212
- );
17213
- newPosition[vertex1Offset * 3 + 2] = newPosition[vertex1Offset * 3 + 2] - skirtHeight;
17214
- newPosition.set(
17215
- attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3),
17216
- vertex2Offset * 3
17217
- );
17218
- newPosition[vertex2Offset * 3 + 2] = newPosition[vertex2Offset * 3 + 2] - skirtHeight;
17219
- newTexcoord0.set(
17220
- attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2),
17221
- vertex1Offset * 2
17222
- );
17223
- newTexcoord0.set(
17224
- attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2),
17225
- vertex2Offset * 2
17226
- );
17227
- const triangle1Offset = edgeIndex * 2 * 3;
17228
- newTriangles[triangle1Offset] = edge[0];
17229
- newTriangles[triangle1Offset + 1] = positionsLength / 3 + vertex2Offset;
17230
- newTriangles[triangle1Offset + 2] = edge[1];
17231
- newTriangles[triangle1Offset + 3] = positionsLength / 3 + vertex2Offset;
17232
- newTriangles[triangle1Offset + 4] = edge[0];
17233
- newTriangles[triangle1Offset + 5] = positionsLength / 3 + vertex1Offset;
16899
+ return Uint32Array.from(edges);
17234
16900
  }
17235
16901
  var init_skirt = __esm({
17236
16902
  "src/terrain/lib/helpers/skirt.ts"() {
17237
16903
  "use strict";
17238
- init_loader_utils();
16904
+ init_terrain();
17239
16905
  }
17240
16906
  });
17241
16907
 
@@ -17333,7 +16999,7 @@ return true;`);
17333
16999
  var init_version = __esm({
17334
17000
  "src/terrain/lib/utils/version.ts"() {
17335
17001
  "use strict";
17336
- VERSION = true ? "5.0.0-beta.1" : "latest";
17002
+ VERSION = true ? "5.0.0-beta.11" : "latest";
17337
17003
  }
17338
17004
  });
17339
17005
 
@@ -17355,6 +17021,18 @@ return true;`);
17355
17021
  }
17356
17022
  });
17357
17023
 
17024
+ // src/quantized-mesh-loader.ts
17025
+ var quantized_mesh_loader_exports = {};
17026
+ __export(quantized_mesh_loader_exports, {
17027
+ QuantizedMeshLoaderWithParser: () => QuantizedMeshLoaderWithParser
17028
+ });
17029
+ var init_quantized_mesh_loader = __esm({
17030
+ "src/quantized-mesh-loader.ts"() {
17031
+ "use strict";
17032
+ init_quantized_mesh_loader2();
17033
+ }
17034
+ });
17035
+
17358
17036
  // src/terrain/quantized-mesh-loader-types.ts
17359
17037
  var QuantizedMeshLoader;
17360
17038
  var init_quantized_mesh_loader_types = __esm({
@@ -17363,6 +17041,8 @@ return true;`);
17363
17041
  init_version();
17364
17042
  init_terrain_format();
17365
17043
  QuantizedMeshLoader = {
17044
+ defaultShape: "arrow",
17045
+ supportsNativeArrow: true,
17366
17046
  dataType: null,
17367
17047
  batchType: null,
17368
17048
  ...QuantizedMeshFormat,
@@ -17372,7 +17052,7 @@ return true;`);
17372
17052
  preload: async () => (await Promise.resolve().then(() => (init_quantized_mesh_loader(), quantized_mesh_loader_exports))).QuantizedMeshLoaderWithParser,
17373
17053
  options: {
17374
17054
  "quantized-mesh": {
17375
- shape: "arrow-table",
17055
+ shape: "arrow",
17376
17056
  bounds: [0, 0, 1, 1],
17377
17057
  skirtHeight: null
17378
17058
  }
@@ -17382,14 +17062,10 @@ return true;`);
17382
17062
  });
17383
17063
 
17384
17064
  // src/terrain/quantized-mesh-loader.ts
17385
- var quantized_mesh_loader_exports = {};
17386
- __export(quantized_mesh_loader_exports, {
17387
- QuantizedMeshLoaderWithParser: () => QuantizedMeshLoaderWithParser
17388
- });
17389
17065
  function parseQuantizedMeshInRequestedShape(arrayBuffer, options) {
17390
17066
  const mesh = parseQuantizedMesh(arrayBuffer, options?.["quantized-mesh"]);
17391
- const table = convertMeshToTable(mesh, "arrow-table");
17392
- if (options?.["quantized-mesh"]?.shape === "arrow-table") {
17067
+ const table = convertMeshToArrowTable(mesh);
17068
+ if (options?.["quantized-mesh"]?.shape === "arrow") {
17393
17069
  return table;
17394
17070
  }
17395
17071
  return {
@@ -17399,10 +17075,10 @@ return true;`);
17399
17075
  };
17400
17076
  }
17401
17077
  var _QuantizedMeshLoaderPreload, QuantizedMeshLoaderMetadataWithoutPreload, QuantizedMeshLoaderWithParser;
17402
- var init_quantized_mesh_loader = __esm({
17078
+ var init_quantized_mesh_loader2 = __esm({
17403
17079
  "src/terrain/quantized-mesh-loader.ts"() {
17404
17080
  "use strict";
17405
- init_arrow_transport();
17081
+ init_arrow_worker_transport();
17406
17082
  init_schema_utils();
17407
17083
  init_parse_quantized_mesh();
17408
17084
  init_quantized_mesh_loader_types();
@@ -17417,8 +17093,1107 @@ return true;`);
17417
17093
  }
17418
17094
  });
17419
17095
 
17096
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/node/worker_threads-browser.js
17097
+ var parentPort = globalThis.process?.getBuiltinModule?.("node:worker_threads")?.parentPort ?? null;
17098
+
17099
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-utils/get-transfer-list.js
17100
+ function getTransferList(object, recursive = true, transfers) {
17101
+ const transfersSet = transfers || /* @__PURE__ */ new Set();
17102
+ const seen = /* @__PURE__ */ new Set();
17103
+ function visit(value) {
17104
+ if (!value || typeof value !== "object" || seen.has(value))
17105
+ return;
17106
+ seen.add(value);
17107
+ if (isTransferable(value))
17108
+ transfersSet.add(value);
17109
+ else if (ArrayBuffer.isView(value)) {
17110
+ if (isTransferable(value.buffer))
17111
+ transfersSet.add(value.buffer);
17112
+ } else if (recursive && typeof MessageChannel !== "undefined" && value instanceof MessageChannel) {
17113
+ visit(value.port1);
17114
+ visit(value.port2);
17115
+ } else if (recursive && value instanceof Map) {
17116
+ for (const [key, item] of value) {
17117
+ visit(key);
17118
+ visit(item);
17119
+ }
17120
+ } else if (recursive && value instanceof Set) {
17121
+ for (const item of value)
17122
+ visit(item);
17123
+ } else if (recursive) {
17124
+ for (const key of Object.keys(value))
17125
+ visit(value[key]);
17126
+ }
17127
+ }
17128
+ visit(object);
17129
+ return transfers === void 0 ? Array.from(transfersSet) : [];
17130
+ }
17131
+ function isTransferable(object) {
17132
+ if (!object) {
17133
+ return false;
17134
+ }
17135
+ if (object instanceof ArrayBuffer) {
17136
+ return true;
17137
+ }
17138
+ if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
17139
+ return true;
17140
+ }
17141
+ if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
17142
+ return true;
17143
+ }
17144
+ if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
17145
+ return true;
17146
+ }
17147
+ return false;
17148
+ }
17149
+
17150
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-body.js
17151
+ async function getParentPort() {
17152
+ return parentPort;
17153
+ }
17154
+ var onMessageWrapperMap = /* @__PURE__ */ new Map();
17155
+ var WorkerBody = class {
17156
+ /** Check that we are actually in a worker thread */
17157
+ static async inWorkerThread() {
17158
+ const workerGlobalScope = globalThis.WorkerGlobalScope;
17159
+ return typeof workerGlobalScope === "function" && globalThis instanceof workerGlobalScope || Boolean(await getParentPort());
17160
+ }
17161
+ /*
17162
+ * (type: WorkerMessageType, payload: WorkerMessagePayload) => any
17163
+ */
17164
+ static set onmessage(onMessage) {
17165
+ async function handleMessage(message) {
17166
+ const parentPort3 = await getParentPort();
17167
+ const { type, payload } = parentPort3 ? message : message.data;
17168
+ onMessage(type, payload);
17169
+ }
17170
+ getParentPort().then((parentPort3) => {
17171
+ if (parentPort3) {
17172
+ parentPort3.on("message", (message) => {
17173
+ handleMessage(message);
17174
+ });
17175
+ parentPort3.on("exit", () => console.debug("Node worker closing"));
17176
+ } else {
17177
+ globalThis.onmessage = handleMessage;
17178
+ }
17179
+ });
17180
+ }
17181
+ static async addEventListener(onMessage) {
17182
+ let onMessageWrapper = onMessageWrapperMap.get(onMessage);
17183
+ if (!onMessageWrapper) {
17184
+ onMessageWrapper = (message) => {
17185
+ const messageData = getWorkerMessageData(message);
17186
+ if (!messageData) {
17187
+ return;
17188
+ }
17189
+ onMessage(messageData.type, messageData.payload);
17190
+ };
17191
+ onMessageWrapperMap.set(onMessage, onMessageWrapper);
17192
+ }
17193
+ const parentPort3 = await getParentPort();
17194
+ if (parentPort3) {
17195
+ parentPort3.on("message", onMessageWrapper);
17196
+ } else {
17197
+ globalThis.addEventListener("message", onMessageWrapper);
17198
+ }
17199
+ }
17200
+ static async removeEventListener(onMessage) {
17201
+ const onMessageWrapper = onMessageWrapperMap.get(onMessage);
17202
+ onMessageWrapperMap.delete(onMessage);
17203
+ if (!onMessageWrapper) {
17204
+ return;
17205
+ }
17206
+ const parentPort3 = await getParentPort();
17207
+ if (parentPort3) {
17208
+ parentPort3.off("message", onMessageWrapper);
17209
+ } else {
17210
+ globalThis.removeEventListener("message", onMessageWrapper);
17211
+ }
17212
+ }
17213
+ /**
17214
+ * Send a message from a worker to creating thread (main thread)
17215
+ * @param type
17216
+ * @param payload
17217
+ */
17218
+ static async postMessage(type, payload, copy = false) {
17219
+ const data = { source: "loaders.gl", type, payload };
17220
+ const transferList = copy ? [] : getTransferList(payload);
17221
+ const parentPort3 = await getParentPort();
17222
+ if (parentPort3) {
17223
+ parentPort3.postMessage(data, transferList);
17224
+ } else {
17225
+ globalThis.postMessage(data, transferList);
17226
+ }
17227
+ }
17228
+ };
17229
+ function getWorkerMessageData(message) {
17230
+ if (!message || typeof message !== "object") {
17231
+ return null;
17232
+ }
17233
+ const messageData = "data" in message && message.type === "message" ? message.data : message;
17234
+ return messageData && typeof messageData.source === "string" && messageData.source.startsWith("loaders.gl") ? messageData : null;
17235
+ }
17236
+
17237
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/async-queue/async-queue.js
17238
+ var AsyncQueue = class {
17239
+ constructor() {
17240
+ this._values = [];
17241
+ this._settlers = [];
17242
+ this._closed = false;
17243
+ }
17244
+ /** Return an async iterator for this queue */
17245
+ [Symbol.asyncIterator]() {
17246
+ return this;
17247
+ }
17248
+ /** Push a new value - the async iterator will yield a promise resolved to this value */
17249
+ push(value) {
17250
+ return this.enqueue(value);
17251
+ }
17252
+ /**
17253
+ * Push a new value - the async iterator will yield a promise resolved to this value
17254
+ * Add an error - the async iterator will yield a promise rejected with this value
17255
+ */
17256
+ enqueue(value) {
17257
+ if (this._closed) {
17258
+ throw new Error("Closed");
17259
+ }
17260
+ if (this._settlers.length > 0) {
17261
+ if (this._values.length > 0) {
17262
+ throw new Error("Illegal internal state");
17263
+ }
17264
+ const settler = this._settlers.shift();
17265
+ if (value instanceof Error) {
17266
+ settler.reject(value);
17267
+ } else {
17268
+ settler.resolve({ value });
17269
+ }
17270
+ } else {
17271
+ this._values.push(value);
17272
+ }
17273
+ }
17274
+ /** Indicate that we not waiting for more values - The async iterator will be done */
17275
+ close() {
17276
+ while (this._settlers.length > 0) {
17277
+ const settler = this._settlers.shift();
17278
+ settler.resolve({ done: true });
17279
+ }
17280
+ this._closed = true;
17281
+ }
17282
+ // ITERATOR IMPLEMENTATION
17283
+ /** @returns a Promise for an IteratorResult */
17284
+ next() {
17285
+ if (this._values.length > 0) {
17286
+ const value = this._values.shift();
17287
+ if (value instanceof Error) {
17288
+ return Promise.reject(value);
17289
+ }
17290
+ return Promise.resolve({ done: false, value });
17291
+ }
17292
+ if (this._closed) {
17293
+ if (this._settlers.length > 0) {
17294
+ throw new Error("Illegal internal state");
17295
+ }
17296
+ return Promise.resolve({ done: true, value: void 0 });
17297
+ }
17298
+ return new Promise((resolve, reject) => {
17299
+ this._settlers.push({ resolve, reject });
17300
+ });
17301
+ }
17302
+ };
17303
+
17304
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/shared-state.js
17305
+ var SharedWorkerState = class {
17306
+ constructor(buffer) {
17307
+ if (typeof SharedArrayBuffer === "undefined" || !(buffer instanceof SharedArrayBuffer) || buffer.byteLength !== 16)
17308
+ throw new Error("Expected a 16-byte shared worker control buffer");
17309
+ this.buffer = buffer;
17310
+ this.values = new Int32Array(buffer);
17311
+ }
17312
+ get snapshot() {
17313
+ return {
17314
+ cancelled: Atomics.load(this.values, 0) !== 0,
17315
+ completed: Atomics.load(this.values, 1),
17316
+ total: Atomics.load(this.values, 2),
17317
+ revision: Atomics.load(this.values, 3)
17318
+ };
17319
+ }
17320
+ cancel() {
17321
+ Atomics.store(this.values, 0, 1);
17322
+ Atomics.add(this.values, 3, 1);
17323
+ Atomics.notify(this.values, 0);
17324
+ }
17325
+ throwIfCancelled() {
17326
+ if (Atomics.load(this.values, 0) !== 0) {
17327
+ const error = new Error("Shared worker task was cancelled");
17328
+ error.name = "AbortError";
17329
+ throw error;
17330
+ }
17331
+ }
17332
+ /** Integer counters for application-defined work; messages still carry phase names and units. */
17333
+ setProgress(completed, total = -1) {
17334
+ if (!Number.isInteger(completed) || completed < 0 || completed > 2147483647 || !Number.isInteger(total) || total < -1 || total > 2147483647) {
17335
+ throw new RangeError("Shared progress requires nonnegative int32 counts (or total -1)");
17336
+ }
17337
+ Atomics.store(this.values, 1, completed);
17338
+ Atomics.store(this.values, 2, total);
17339
+ Atomics.add(this.values, 3, 1);
17340
+ }
17341
+ };
17342
+
17343
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/validate-output-ownership.js
17344
+ function validateOutputOwnership(ownership) {
17345
+ if (ownership !== void 0 && ownership !== "copy" && ownership !== "transfer") {
17346
+ throw new Error("Invalid worker output ownership");
17347
+ }
17348
+ }
17349
+
17350
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/create-worker.js
17351
+ var requestId = 0;
17352
+ var activeController = null;
17353
+ var activeInputBatches = null;
17354
+ var activeOutputAcknowledgements = null;
17355
+ async function createWorker(process2, processInBatches, preload) {
17356
+ if (!await WorkerBody.inWorkerThread()) {
17357
+ return;
17358
+ }
17359
+ const context = {
17360
+ process: processOnMainThread
17361
+ };
17362
+ WorkerBody.onmessage = async (type, payload) => {
17363
+ if (type === "cancel") {
17364
+ activeController?.abort();
17365
+ activeInputBatches?.close();
17366
+ activeOutputAcknowledgements?.close();
17367
+ return;
17368
+ }
17369
+ const controller = type === "process" || type === "process-in-batches" ? new AbortController() : void 0;
17370
+ if (controller)
17371
+ activeController = controller;
17372
+ const startedAt = performance.now();
17373
+ const reporter = type === "process" || type === "process-in-batches" ? createProgressReporter() : void 0;
17374
+ let sharedState;
17375
+ const throwIfAborted = () => {
17376
+ controller?.signal.throwIfAborted();
17377
+ sharedState?.throwIfCancelled();
17378
+ };
17379
+ const jobContext = {
17380
+ ...context,
17381
+ signal: controller?.signal,
17382
+ sharedState,
17383
+ throwIfAborted,
17384
+ reportProgress: (progress) => {
17385
+ if (!controller?.signal.aborted && !sharedState?.snapshot.cancelled)
17386
+ reporter?.report(progress);
17387
+ }
17388
+ };
17389
+ try {
17390
+ if (controller && payload.options?.["sharedState"]) {
17391
+ sharedState = new SharedWorkerState(payload.options["sharedState"]);
17392
+ jobContext.sharedState = sharedState;
17393
+ }
17394
+ switch (type) {
17395
+ case "preload":
17396
+ await preload?.();
17397
+ WorkerBody.postMessage("done", {});
17398
+ break;
17399
+ case "process":
17400
+ throwIfAborted();
17401
+ validateOutputOwnership(payload.options?.["outputOwnership"]);
17402
+ if (!process2) {
17403
+ throw new Error("Worker does not support atomic processing");
17404
+ }
17405
+ const result = await process2(payload.input, payload.options || {}, jobContext, payload.context || {});
17406
+ throwIfAborted();
17407
+ reporter?.finish();
17408
+ await WorkerBody.postMessage("done", {
17409
+ result,
17410
+ executionMs: performance.now() - startedAt
17411
+ }, payload.options?.["outputOwnership"] === "copy");
17412
+ break;
17413
+ case "process-in-batches":
17414
+ throwIfAborted();
17415
+ validateOutputOwnership(payload.options?.["outputOwnership"]);
17416
+ if (!processInBatches) {
17417
+ throw new Error("Worker does not support batched processing");
17418
+ }
17419
+ const inputBatches = new AsyncQueue();
17420
+ const outputAcknowledgements = new AsyncQueue();
17421
+ activeInputBatches = inputBatches;
17422
+ activeOutputAcknowledgements = outputAcknowledgements;
17423
+ try {
17424
+ const resultIterator = processInBatches(createDemandDrivenIterator(inputBatches), payload.options || {}, jobContext, payload.context || {});
17425
+ for await (const batch of resultIterator) {
17426
+ throwIfAborted();
17427
+ await WorkerBody.postMessage("output-batch", { result: batch }, payload.options?.["outputOwnership"] === "copy");
17428
+ await outputAcknowledgements.next();
17429
+ }
17430
+ throwIfAborted();
17431
+ reporter?.finish();
17432
+ await WorkerBody.postMessage("done", { executionMs: performance.now() - startedAt });
17433
+ } finally {
17434
+ activeInputBatches = null;
17435
+ activeOutputAcknowledgements = null;
17436
+ }
17437
+ break;
17438
+ case "input-batch":
17439
+ if (!activeInputBatches) {
17440
+ throw new Error("Worker has no active batched processing session");
17441
+ }
17442
+ activeInputBatches.push(payload.input);
17443
+ break;
17444
+ case "input-done":
17445
+ if (!activeInputBatches) {
17446
+ throw new Error("Worker has no active batched processing session");
17447
+ }
17448
+ activeInputBatches.close();
17449
+ break;
17450
+ case "output-ack":
17451
+ if (!activeOutputAcknowledgements) {
17452
+ throw new Error("Worker has no active batched processing session");
17453
+ }
17454
+ activeOutputAcknowledgements.push(void 0);
17455
+ break;
17456
+ default:
17457
+ }
17458
+ } catch (error) {
17459
+ reporter?.finish(controller?.signal.aborted || sharedState?.snapshot.cancelled);
17460
+ const message = error instanceof Error ? error.message : "";
17461
+ await WorkerBody.postMessage("error", {
17462
+ error: message,
17463
+ errorName: error instanceof Error ? error.name : "Error"
17464
+ });
17465
+ } finally {
17466
+ if (controller && activeController === controller)
17467
+ activeController = null;
17468
+ }
17469
+ };
17470
+ await WorkerBody.postMessage("ready", {});
17471
+ }
17472
+ async function* createDemandDrivenIterator(inputBatches) {
17473
+ while (true) {
17474
+ await WorkerBody.postMessage("input-request", {});
17475
+ const nextBatch = await inputBatches.next();
17476
+ if (nextBatch.done) {
17477
+ return;
17478
+ }
17479
+ yield nextBatch.value;
17480
+ }
17481
+ }
17482
+ function processOnMainThread(arrayBuffer, options = {}, jobContext = {}) {
17483
+ const signal = activeController?.signal;
17484
+ signal?.throwIfAborted();
17485
+ return new Promise((resolve, reject) => {
17486
+ const id = requestId++;
17487
+ const cleanup = () => {
17488
+ signal?.removeEventListener("abort", abort);
17489
+ void WorkerBody.removeEventListener(onMessage);
17490
+ };
17491
+ const abort = () => {
17492
+ cleanup();
17493
+ reject(signal?.reason);
17494
+ };
17495
+ const onMessage = (type, payload) => {
17496
+ if (payload.id !== id)
17497
+ return;
17498
+ if (type === "done") {
17499
+ cleanup();
17500
+ resolve(payload.result);
17501
+ } else if (type === "error") {
17502
+ cleanup();
17503
+ reject(payload.error);
17504
+ }
17505
+ };
17506
+ void WorkerBody.addEventListener(onMessage).then(async () => {
17507
+ if (signal?.aborted) {
17508
+ abort();
17509
+ return;
17510
+ }
17511
+ signal?.addEventListener("abort", abort, { once: true });
17512
+ await WorkerBody.postMessage("process", {
17513
+ id,
17514
+ input: arrayBuffer,
17515
+ options,
17516
+ context: jobContext
17517
+ });
17518
+ }).catch((error) => {
17519
+ cleanup();
17520
+ reject(error);
17521
+ });
17522
+ });
17523
+ }
17524
+ function createProgressReporter() {
17525
+ let pending2;
17526
+ let finished = false;
17527
+ let scheduled = false;
17528
+ const flush = () => {
17529
+ scheduled = false;
17530
+ if (pending2) {
17531
+ WorkerBody.postMessage("progress", { progress: pending2 });
17532
+ pending2 = void 0;
17533
+ }
17534
+ };
17535
+ return {
17536
+ /** Records progress while retaining phase transitions. */
17537
+ report(progress) {
17538
+ if (finished)
17539
+ return;
17540
+ if (pending2 && pending2.phase !== progress.phase)
17541
+ flush();
17542
+ pending2 = { ...progress };
17543
+ if (!scheduled) {
17544
+ scheduled = true;
17545
+ setTimeout(flush, 0);
17546
+ }
17547
+ },
17548
+ /** Flushes final progress and suppresses reports from stale callbacks. */
17549
+ finish(discard = false) {
17550
+ if (discard)
17551
+ pending2 = void 0;
17552
+ flush();
17553
+ finished = true;
17554
+ }
17555
+ };
17556
+ }
17557
+
17558
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/index.js
17559
+ var import_meta = {};
17560
+ var path = typeof __filename === "string" ? __filename.replace(/\\/g, "/") : "";
17561
+ var moduleUrl = path ? `file://${path.startsWith("/") ? "" : "/"}${encodeURI(path).replace(/#/g, "%23").replace(/\?/g, "%3F")}` : import_meta.url;
17562
+
17563
+ // ../../node_modules/@math.gl/tasks/dist/tasks/task-preload.js
17564
+ var pending = /* @__PURE__ */ new WeakMap();
17565
+ var loaded = /* @__PURE__ */ new WeakSet();
17566
+ function preloadTaskCode(task, signal) {
17567
+ if (!task.preload)
17568
+ return Promise.resolve();
17569
+ let promise = pending.get(task);
17570
+ if (!promise) {
17571
+ promise = Promise.resolve().then(() => task.preload()).then(() => {
17572
+ loaded.add(task);
17573
+ });
17574
+ pending.set(task, promise);
17575
+ void promise.catch(() => pending.delete(task));
17576
+ }
17577
+ return withSignal(promise, signal);
17578
+ }
17579
+ function withSignal(operation, signal) {
17580
+ if (!signal)
17581
+ return operation;
17582
+ return new Promise((resolve, reject) => {
17583
+ const abort = () => {
17584
+ signal.removeEventListener("abort", abort);
17585
+ reject(signal.reason);
17586
+ };
17587
+ signal.addEventListener("abort", abort, { once: true });
17588
+ if (signal.aborted)
17589
+ abort();
17590
+ operation.then((value) => {
17591
+ signal.removeEventListener("abort", abort);
17592
+ resolve(value);
17593
+ }, (error) => {
17594
+ signal.removeEventListener("abort", abort);
17595
+ reject(error);
17596
+ });
17597
+ });
17598
+ }
17599
+
17600
+ // ../../node_modules/@math.gl/tasks/dist/tasks/task-channel.js
17601
+ var TaskRequestError = class extends Error {
17602
+ };
17603
+ var TaskChannel = class {
17604
+ constructor(options) {
17605
+ this.options = options;
17606
+ this.nextId = 1;
17607
+ this.pending = /* @__PURE__ */ new Map();
17608
+ this.incoming = /* @__PURE__ */ new Map();
17609
+ }
17610
+ /** Send a request without serializing other in-flight requests. */
17611
+ request(operation, value, signal, transfer = []) {
17612
+ if (this.failure)
17613
+ return Promise.reject(this.failure.reason);
17614
+ if (signal?.aborted)
17615
+ return Promise.reject(signal.reason);
17616
+ const id = this.nextId++;
17617
+ return new Promise((resolve, reject) => {
17618
+ const abort = () => {
17619
+ const pending2 = this.pending.get(id);
17620
+ if (!pending2)
17621
+ return;
17622
+ this.pending.delete(id);
17623
+ pending2.cleanup();
17624
+ reject(signal?.reason);
17625
+ this.send({ source: "math.gl/tasks", kind: "cancel", id });
17626
+ };
17627
+ this.pending.set(id, {
17628
+ resolve,
17629
+ reject,
17630
+ cleanup: () => signal?.removeEventListener("abort", abort)
17631
+ });
17632
+ signal?.addEventListener("abort", abort, { once: true });
17633
+ this.send({ source: "math.gl/tasks", kind: "request", id, operation, value }, transfer);
17634
+ });
17635
+ }
17636
+ /** Send a one-way notification. */
17637
+ emit(operation, value, transfer = []) {
17638
+ if (this.failure)
17639
+ throw this.failure.reason;
17640
+ this.send({ source: "math.gl/tasks", kind: "event", id: 0, operation, value }, transfer);
17641
+ }
17642
+ /** Dispatch a transport message; unrelated protocols are ignored. */
17643
+ receive(message) {
17644
+ if (this.failure || message?.source !== "math.gl/tasks")
17645
+ return;
17646
+ if (message.kind === "failure") {
17647
+ const reason = new Error(message.error?.message ?? "Task channel failed");
17648
+ this.close(reason);
17649
+ this.options.onFailure?.(reason);
17650
+ } else if (message.kind === "result" || message.kind === "error") {
17651
+ const pending2 = this.pending.get(message.id);
17652
+ if (!pending2)
17653
+ return;
17654
+ this.pending.delete(message.id);
17655
+ pending2.cleanup();
17656
+ if (message.kind === "result")
17657
+ pending2.resolve(message.value);
17658
+ else {
17659
+ const error = new TaskRequestError(message.error?.message ?? "Task request failed");
17660
+ error.name = message.error?.name ?? "Error";
17661
+ pending2.reject(error);
17662
+ }
17663
+ } else if (message.kind === "cancel") {
17664
+ this.incoming.get(message.id)?.abort(new DOMException("Task request cancelled", "AbortError"));
17665
+ } else if (message.kind === "event") {
17666
+ try {
17667
+ this.options.handleEvent?.(message.operation, message.value);
17668
+ } catch (error) {
17669
+ this.fail(error);
17670
+ }
17671
+ } else if (message.kind === "request") {
17672
+ if (this.incoming.has(message.id)) {
17673
+ this.fail(new Error("Duplicate task request identifier"));
17674
+ return;
17675
+ }
17676
+ const controller = new AbortController();
17677
+ this.incoming.set(message.id, controller);
17678
+ void Promise.resolve().then(() => {
17679
+ controller.signal.throwIfAborted();
17680
+ return this.options.handleRequest(message.operation, message.value, controller.signal);
17681
+ }).then((value) => {
17682
+ if (!controller.signal.aborted && !this.failure) {
17683
+ this.send({ source: "math.gl/tasks", kind: "result", id: message.id, value }, this.options.getResultTransferList?.(value, message.value));
17684
+ }
17685
+ }).catch((reason) => {
17686
+ if (!controller.signal.aborted && !this.failure) {
17687
+ this.send({
17688
+ source: "math.gl/tasks",
17689
+ kind: "error",
17690
+ id: message.id,
17691
+ error: {
17692
+ name: reason instanceof Error ? reason.name : "Error",
17693
+ message: reason instanceof Error ? reason.message : String(reason)
17694
+ }
17695
+ });
17696
+ }
17697
+ }).finally(() => this.incoming.delete(message.id));
17698
+ }
17699
+ }
17700
+ /** Reject all outstanding calls with a common cause and abort incoming callbacks. */
17701
+ close(reason = new Error("Task channel closed")) {
17702
+ if (this.failure)
17703
+ return;
17704
+ this.failure = { reason };
17705
+ for (const pending2 of this.pending.values()) {
17706
+ pending2.cleanup();
17707
+ pending2.reject(reason);
17708
+ }
17709
+ this.pending.clear();
17710
+ for (const controller of this.incoming.values())
17711
+ controller.abort(reason);
17712
+ this.incoming.clear();
17713
+ }
17714
+ send(message, transfer = []) {
17715
+ if (this.failure)
17716
+ return;
17717
+ try {
17718
+ this.options.send(message, transfer);
17719
+ } catch (error) {
17720
+ this.fail(error);
17721
+ }
17722
+ }
17723
+ /** Invalidate the channel and notify the peer when the transport still works. */
17724
+ fail(reason) {
17725
+ if (this.failure)
17726
+ return;
17727
+ this.close(reason);
17728
+ try {
17729
+ this.options.send({
17730
+ source: "math.gl/tasks",
17731
+ kind: "failure",
17732
+ id: 0,
17733
+ error: {
17734
+ name: reason instanceof Error ? reason.name : "Error",
17735
+ message: reason instanceof Error ? reason.message : String(reason)
17736
+ }
17737
+ }, []);
17738
+ } catch {
17739
+ }
17740
+ this.options.onFailure?.(reason);
17741
+ }
17742
+ };
17743
+
17744
+ // ../../node_modules/@math.gl/tasks/dist/tasks/task-runtime.js
17745
+ function assertPayload(value) {
17746
+ if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) {
17747
+ throw new TypeError("Task payloads must be plain objects with named fields");
17748
+ }
17749
+ }
17750
+ function clonePayload(value, ownership = "copy") {
17751
+ assertPayload(value);
17752
+ if (!["copy", "transfer", "share"].includes(ownership))
17753
+ throw new TypeError("Invalid input ownership");
17754
+ const transfer = getTransferList(value);
17755
+ if (ownership === "share" && transfer.length)
17756
+ throw new TypeError("Share requires shared storage");
17757
+ return structuredClone(value, {
17758
+ transfer: ownership === "transfer" ? transfer : []
17759
+ });
17760
+ }
17761
+ function taskContext(state, context = {}) {
17762
+ const signal = context.signal ?? new AbortController().signal;
17763
+ return {
17764
+ state,
17765
+ signal,
17766
+ requestHost: async (operation, payload, controls) => {
17767
+ signal.throwIfAborted();
17768
+ if (!context.requestHost)
17769
+ throw new Error("No host request handler configured");
17770
+ return context.requestHost(operation, payload, controls);
17771
+ },
17772
+ emitHost: (operation, payload) => {
17773
+ signal.throwIfAborted();
17774
+ context.emitHost?.(operation, payload);
17775
+ },
17776
+ throwIfAborted: () => {
17777
+ signal.throwIfAborted();
17778
+ context.throwIfAborted?.();
17779
+ },
17780
+ reportProgress: (progress) => context.reportProgress?.({
17781
+ ...progress,
17782
+ phase: progress.phase ?? "process",
17783
+ unit: progress.unit ?? "items"
17784
+ })
17785
+ };
17786
+ }
17787
+ var TaskRuntime = class {
17788
+ constructor(task) {
17789
+ this.task = task;
17790
+ this.initialized = false;
17791
+ }
17792
+ async initialize(input, context = {}) {
17793
+ if (this.initialized)
17794
+ throw new Error("Task is already initialized");
17795
+ assertPayload(input);
17796
+ await preloadTaskCode(this.task, context.signal);
17797
+ context.signal?.throwIfAborted();
17798
+ this.state = await this.task.initialize?.(input, taskContext(void 0, context));
17799
+ this.initialized = true;
17800
+ return {};
17801
+ }
17802
+ async destroy() {
17803
+ if (this.initialized) {
17804
+ this.initialized = false;
17805
+ const state = this.state;
17806
+ this.state = void 0;
17807
+ if (this.task.initialize)
17808
+ await this.task.destroy?.(state);
17809
+ }
17810
+ return {};
17811
+ }
17812
+ async process(input, options, context = {}) {
17813
+ if (!this.initialized)
17814
+ throw new Error("Task is not initialized");
17815
+ if (!this.task.process)
17816
+ throw new Error("Task has no atomic processor");
17817
+ assertPayload(input);
17818
+ const result = await this.task.process(input, options, taskContext(this.state, context));
17819
+ assertPayload(result);
17820
+ return result;
17821
+ }
17822
+ async *stream(inputs, options, context = {}) {
17823
+ if (!this.initialized)
17824
+ throw new Error("Task is not initialized");
17825
+ if (!this.task.processInBatches)
17826
+ throw new Error("Task has no streaming processor");
17827
+ for await (const output of this.task.processInBatches(inputs, options, taskContext(this.state, context))) {
17828
+ assertPayload(output);
17829
+ yield output;
17830
+ }
17831
+ }
17832
+ };
17833
+ async function initializeTaskWorker(task) {
17834
+ if (!await WorkerBody.inWorkerThread())
17835
+ throw new Error("initializeTaskWorker must run inside a worker");
17836
+ if (installed)
17837
+ throw new Error("A task is already installed in this worker");
17838
+ installed = true;
17839
+ const runtime = new TaskRuntime(task);
17840
+ let channelStream;
17841
+ const channel = new TaskChannel({
17842
+ getResultTransferList: (value, request) => request.outputOwnership === "transfer" ? getTransferList(value) : [],
17843
+ send: (message, transfer) => {
17844
+ const snapshot = structuredClone(message, { transfer });
17845
+ void WorkerBody.postMessage("task-channel", snapshot).catch((reason) => channel.fail(reason));
17846
+ },
17847
+ handleRequest: async (operation, value, signal) => {
17848
+ const request = value;
17849
+ const context = {
17850
+ signal,
17851
+ reportProgress: (progress) => channel.emit("task:progress", { id: request.progressId, progress }),
17852
+ requestHost: (operation2, payload, controls = {}) => {
17853
+ const request2 = {
17854
+ operation: operation2,
17855
+ payload: clonePayload(payload, controls.inputOwnership),
17856
+ outputOwnership: controls.outputOwnership ?? "copy"
17857
+ };
17858
+ return channel.request("task:host-request", request2, signal, getTransferList(request2));
17859
+ },
17860
+ emitHost: (operation2, payload) => channel.emit("task:host-event", { operation: operation2, payload, id: request.progressId })
17861
+ };
17862
+ switch (operation) {
17863
+ case "initialize":
17864
+ return runtime.initialize(request.input, context);
17865
+ case "process":
17866
+ return runtime.process(request.input, request.options, context);
17867
+ case "stream-open": {
17868
+ if (channelStream)
17869
+ throw new Error("A task stream is already open");
17870
+ async function* inputs() {
17871
+ while (true) {
17872
+ const result = await channel.request("task:next-input", { outputOwnership: "transfer" }, signal);
17873
+ if (result.done)
17874
+ return;
17875
+ yield result.value;
17876
+ }
17877
+ }
17878
+ channelStream = runtime.stream(inputs(), request.options, context)[Symbol.asyncIterator]();
17879
+ return {};
17880
+ }
17881
+ case "stream-next":
17882
+ if (!channelStream)
17883
+ throw new Error("No active task stream");
17884
+ return channelStream.next();
17885
+ case "stream-close":
17886
+ try {
17887
+ await channelStream?.return?.();
17888
+ } finally {
17889
+ channelStream = void 0;
17890
+ }
17891
+ return {};
17892
+ case "destroy":
17893
+ return runtime.destroy();
17894
+ default:
17895
+ throw new Error("Unknown task channel operation");
17896
+ }
17897
+ }
17898
+ });
17899
+ await WorkerBody.addEventListener((type, payload) => {
17900
+ if (type === "task-channel")
17901
+ channel.receive(payload);
17902
+ });
17903
+ let streamOptions = {};
17904
+ return createWorker(async (request, _options, context) => {
17905
+ switch (request.operation) {
17906
+ case "initialize":
17907
+ return runtime.initialize(request.input, context);
17908
+ case "destroy":
17909
+ return runtime.destroy();
17910
+ case "stream-options":
17911
+ streamOptions = request.options;
17912
+ return {};
17913
+ case "process":
17914
+ return runtime.process(request.input, request.options, context);
17915
+ default:
17916
+ throw new Error("Unknown task operation");
17917
+ }
17918
+ }, async function* (inputs, _options, context) {
17919
+ async function* batches() {
17920
+ for await (const input of inputs) {
17921
+ assertPayload(input);
17922
+ yield input;
17923
+ }
17924
+ }
17925
+ try {
17926
+ yield* runtime.stream(batches(), streamOptions, context);
17927
+ } finally {
17928
+ streamOptions = {};
17929
+ }
17930
+ }, () => preloadTaskCode(task));
17931
+ }
17932
+ var installed = false;
17933
+
17934
+ // ../core/src/worker-utils/lib/worker-api/task-runtime.ts
17935
+ function normalizeTaskProgress(progress) {
17936
+ return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
17937
+ }
17938
+ async function isWorkerThread() {
17939
+ if (typeof self !== "undefined" && typeof document === "undefined" && typeof self.postMessage === "function")
17940
+ return true;
17941
+ if (typeof process !== "undefined" && process.versions?.node) {
17942
+ const { isMainThread } = await Promise.resolve().then(() => (init_worker_threads_browser(), worker_threads_browser_exports));
17943
+ return !isMainThread;
17944
+ }
17945
+ return false;
17946
+ }
17947
+ var initializeTaskWorker2 = initializeTaskWorker;
17948
+
17949
+ // ../core/src/worker-utils/lib/worker-utils/get-transfer-list.ts
17950
+ function getTransferList2(object, recursive = true, transfers) {
17951
+ const transfersSet = transfers || /* @__PURE__ */ new Set();
17952
+ if (!object) {
17953
+ } else if (isTransferable2(object)) {
17954
+ transfersSet.add(object);
17955
+ } else if (isTransferable2(object.buffer)) {
17956
+ transfersSet.add(object.buffer);
17957
+ } else if (ArrayBuffer.isView(object)) {
17958
+ } else if (recursive && typeof object === "object") {
17959
+ for (const key in object) {
17960
+ getTransferList2(object[key], recursive, transfersSet);
17961
+ }
17962
+ }
17963
+ return transfers === void 0 ? Array.from(transfersSet) : [];
17964
+ }
17965
+ function isTransferable2(object) {
17966
+ if (!object) {
17967
+ return false;
17968
+ }
17969
+ if (object instanceof ArrayBuffer) {
17970
+ return true;
17971
+ }
17972
+ if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
17973
+ return true;
17974
+ }
17975
+ if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
17976
+ return true;
17977
+ }
17978
+ if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
17979
+ return true;
17980
+ }
17981
+ return false;
17982
+ }
17983
+
17984
+ // ../core/src/worker-utils/lib/worker-api/create-worker.ts
17985
+ async function createWorker2(process2, processInBatches) {
17986
+ if (!await isWorkerThread()) return;
17987
+ await initializeTaskWorker2(createWorkerTask(process2, processInBatches));
17988
+ }
17989
+ function createWorkerTask(process2, processInBatches) {
17990
+ return {
17991
+ id: "loaders.gl",
17992
+ initialize: (state) => state,
17993
+ destroy: (state) => state.port?.close(),
17994
+ process: async ({ value }, options, context) => {
17995
+ if (!process2) throw new Error("Worker does not support atomic processing");
17996
+ return { value: await process2(value, options, createContext(context), context.state.context) };
17997
+ },
17998
+ ...processInBatches ? {
17999
+ processInBatches: async function* (inputs, options, context) {
18000
+ async function* values() {
18001
+ for await (const input of inputs) yield input.value;
18002
+ }
18003
+ for await (const value of processInBatches(
18004
+ values(),
18005
+ options,
18006
+ createContext(context),
18007
+ context.state.context
18008
+ )) {
18009
+ yield { value };
18010
+ }
18011
+ }
18012
+ } : {}
18013
+ };
18014
+ }
18015
+ function createContext(context) {
18016
+ let requestIdentifier = 0;
18017
+ const port = context.state.port;
18018
+ return {
18019
+ signal: context.signal,
18020
+ throwIfAborted: () => context.throwIfAborted(),
18021
+ reportProgress: (progress) => context.reportProgress(normalizeTaskProgress(progress)),
18022
+ process: port ? (input, options = {}, jobContext = {}) => {
18023
+ context.throwIfAborted();
18024
+ const identifier = ++requestIdentifier;
18025
+ return new Promise((resolve, reject) => {
18026
+ const onMessage = (event) => {
18027
+ if (event.data.identifier !== identifier) return;
18028
+ cleanup();
18029
+ if (event.data.error) {
18030
+ const error = new Error(event.data.error.message);
18031
+ error.name = event.data.error.name;
18032
+ reject(error);
18033
+ } else resolve(event.data.value);
18034
+ };
18035
+ const onAbort = () => {
18036
+ cleanup();
18037
+ reject(context.signal.reason);
18038
+ };
18039
+ const cleanup = () => {
18040
+ port.removeEventListener("message", onMessage);
18041
+ context.signal.removeEventListener("abort", onAbort);
18042
+ };
18043
+ port.addEventListener("message", onMessage);
18044
+ context.signal.addEventListener("abort", onAbort, { once: true });
18045
+ port.start();
18046
+ try {
18047
+ const request = { identifier, input, options, context: jobContext };
18048
+ port.postMessage(request, getTransferList2(request));
18049
+ } catch (error) {
18050
+ cleanup();
18051
+ reject(error);
18052
+ }
18053
+ });
18054
+ } : void 0
18055
+ };
18056
+ }
18057
+
18058
+ // ../core/src/loader-utils/lib/worker-loader-utils/create-loader-worker.ts
18059
+ async function createLoaderWorker(loader, selectLoader = () => loader) {
18060
+ await createWorker2(
18061
+ (input, options, workerContext, loaderContext) => processLoaderWorkerData(
18062
+ selectLoader(options || {}),
18063
+ input,
18064
+ options,
18065
+ workerContext,
18066
+ loaderContext
18067
+ ),
18068
+ (inputIterator, options, workerContext, loaderContext) => processLoaderWorkerBatches(
18069
+ selectLoader(options || {}),
18070
+ inputIterator,
18071
+ options,
18072
+ workerContext,
18073
+ loaderContext
18074
+ )
18075
+ );
18076
+ }
18077
+ async function processLoaderWorkerData(loader, input, options = {}, workerContext, loaderContext = {}) {
18078
+ const result = await parseData({
18079
+ loader,
18080
+ arrayBuffer: input,
18081
+ options,
18082
+ context: {
18083
+ ...loaderContext,
18084
+ reportProgress: workerContext?.reportProgress,
18085
+ coreApi: createWorkerCoreApi(),
18086
+ _parse: createParseOnMainThread(workerContext?.process)
18087
+ }
18088
+ });
18089
+ return loader.serializeWorkerResult ? loader.serializeWorkerResult(result, options, loaderContext) : result;
18090
+ }
18091
+ async function* processLoaderWorkerBatches(loader, inputIterator, options = {}, workerContext, loaderContext = {}) {
18092
+ if (!loader.parseInBatches) {
18093
+ throw new Error(`${loader.id} loader does not support batched parsing`);
18094
+ }
18095
+ const parserOptions = getWorkerLoaderOptions(loader, options);
18096
+ const resultIterator = loader.parseInBatches(inputIterator, parserOptions, {
18097
+ ...loaderContext,
18098
+ reportProgress: workerContext?.reportProgress,
18099
+ coreApi: createWorkerCoreApi(),
18100
+ _parse: createParseOnMainThread(workerContext?.process)
18101
+ });
18102
+ for await (const batch of resultIterator) {
18103
+ yield loader.serializeWorkerBatch ? loader.serializeWorkerBatch(batch, options, loaderContext) : batch;
18104
+ }
18105
+ }
18106
+ function createWorkerCoreApi() {
18107
+ const unavailable = (methodName) => () => {
18108
+ throw new Error(`context.coreApi.${methodName} is unavailable inside worker loaders.`);
18109
+ };
18110
+ return {
18111
+ fetchFile: async (urlOrData, fetchOptions) => await fetch(urlOrData, fetchOptions),
18112
+ parseSync: unavailable("parseSync"),
18113
+ parse: unavailable("parse"),
18114
+ parseFile: unavailable("parseFile"),
18115
+ parseInBatches: unavailable("parseInBatches"),
18116
+ load: unavailable("load"),
18117
+ loadInBatches: unavailable("loadInBatches")
18118
+ };
18119
+ }
18120
+ function createParseOnMainThread(processOnMainThread2) {
18121
+ return (arrayBuffer, loaders, options, context) => {
18122
+ if (!processOnMainThread2) {
18123
+ throw new Error("Worker not set up to parse on main thread");
18124
+ }
18125
+ const parseArguments = getMainThreadParseArguments(loaders, options, context);
18126
+ return processOnMainThread2(arrayBuffer, parseArguments.options, {
18127
+ ...parseArguments.context,
18128
+ ...Array.isArray(loaders) || loaders && isLoaderObject(loaders) ? {
18129
+ _loaderIsArray: Array.isArray(loaders),
18130
+ _loaderIds: (Array.isArray(loaders) ? loaders : [loaders]).map((loader) => loader.id)
18131
+ } : {}
18132
+ });
18133
+ };
18134
+ }
18135
+ function getMainThreadParseArguments(loaders, options, context) {
18136
+ if (options) {
18137
+ return { options, context: getSerializableLoaderContext(context) };
18138
+ }
18139
+ if (Array.isArray(loaders) || loaders && isLoaderObject(loaders)) {
18140
+ return { options: void 0, context: getSerializableLoaderContext(context) };
18141
+ }
18142
+ if (loaders && !Array.isArray(loaders)) {
18143
+ return { options: loaders };
18144
+ }
18145
+ return { options: void 0, context: getSerializableLoaderContext(context) };
18146
+ }
18147
+ function isLoaderObject(value) {
18148
+ return "id" in value && "extensions" in value;
18149
+ }
18150
+ function getSerializableLoaderContext(context) {
18151
+ if (!context) {
18152
+ return void 0;
18153
+ }
18154
+ const {
18155
+ fetch: fetch2,
18156
+ loaders,
18157
+ coreApi,
18158
+ signal,
18159
+ reportProgress,
18160
+ _parse,
18161
+ _parseSync,
18162
+ _parseInBatches,
18163
+ ...serializableContext
18164
+ } = context;
18165
+ return JSON.parse(JSON.stringify(serializableContext));
18166
+ }
18167
+ async function parseData({
18168
+ loader,
18169
+ arrayBuffer,
18170
+ options,
18171
+ context
18172
+ }) {
18173
+ let data;
18174
+ let parser;
18175
+ if (loader.parse || loader.parseSync) {
18176
+ data = arrayBuffer;
18177
+ parser = loader.parse || loader.parseSync;
18178
+ } else if (loader.parseTextSync) {
18179
+ const textDecoder = new TextDecoder();
18180
+ data = textDecoder.decode(arrayBuffer);
18181
+ parser = loader.parseTextSync;
18182
+ } else {
18183
+ throw new Error(`Could not load data with ${loader.name} loader`);
18184
+ }
18185
+ options = getWorkerLoaderOptions(loader, options);
18186
+ return await parser(data, { ...options }, context, loader);
18187
+ }
18188
+ function getWorkerLoaderOptions(loader, options) {
18189
+ return {
18190
+ ...options,
18191
+ modules: { ...loader.options?.modules, ...options.modules },
18192
+ core: { ...options.core, worker: false }
18193
+ };
18194
+ }
18195
+
17420
18196
  // src/terrain/workers/quantized-mesh-worker.ts
17421
- init_loader_utils();
17422
- init_quantized_mesh_loader();
18197
+ init_quantized_mesh_loader2();
17423
18198
  createLoaderWorker(QuantizedMeshLoaderWithParser);
17424
18199
  })();