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

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 +1847 -1011
  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 +74 -612
  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 +5 -5
  135. package/dist/terrain/quantized-mesh-loader.js.map +1 -1
  136. package/dist/terrain/quantized-mesh-writer.d.ts +4 -3
  137. package/dist/terrain/quantized-mesh-writer.d.ts.map +1 -1
  138. package/dist/terrain/quantized-mesh-writer.js +3 -3
  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 +8 -8
  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 +6558 -4257
  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 +9 -8
  190. package/src/terrain/quantized-mesh-writer.ts +12 -7
  191. package/src/terrain/terrain-loader-types.ts +11 -9
  192. package/src/terrain/terrain-loader.ts +12 -11
  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, edges } = options;
176
+ const maxVertices = options.maxVertices ?? 2e6, maxTriangles = options.maxTriangles ?? 4e6;
177
+ if (!Number.isFinite(height) || height <= 0 || !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] = 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,491 @@ 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/split-arrow-buffers.js
15224
+ function splitArrowBuffers(input, options = {}) {
15225
+ const retainedBuffers = /* @__PURE__ */ new Set();
15226
+ const visited = /* @__PURE__ */ new Set();
15227
+ for (const retained of options.retain ?? []) {
15228
+ const chunks = isArrowTable2(retained) ? retained.batches.map((batch) => batch.data) : isArrowVector2(retained) ? retained.data : [isArrowRecordBatch2(retained) ? retained.data : retained];
15229
+ for (const data of chunks)
15230
+ collectArrowBuffers(data, retainedBuffers, visited);
15231
+ }
15232
+ const context = { ...options, copies: /* @__PURE__ */ new WeakMap(), retainedBuffers };
15233
+ if (isArrowTable2(input)) {
15234
+ return splitArrowTableBuffersInternal(input, context);
15235
+ }
15236
+ if (isArrowRecordBatch2(input)) {
15237
+ return splitArrowRecordBatchBuffers(input, context);
15238
+ }
15239
+ if (isArrowVector2(input)) {
15240
+ return splitArrowVectorBuffers(input, context);
15241
+ }
15242
+ return splitArrowDataBuffers(input, context);
15243
+ }
15244
+ function isArrowTable2(input) {
15245
+ return "batches" in input;
15246
+ }
15247
+ function isArrowRecordBatch2(input) {
15248
+ return "schema" in input && "data" in input && !Array.isArray(input.data);
15249
+ }
15250
+ function isArrowVector2(input) {
15251
+ return "data" in input && Array.isArray(input.data);
15252
+ }
15253
+ function splitArrowTableBuffersInternal(arrowTable, options) {
15254
+ const recordBatches = arrowTable.batches.map((recordBatch) => splitArrowRecordBatchBuffers(recordBatch, options));
15255
+ return new Table(arrowTable.schema, recordBatches);
15256
+ }
15257
+ function splitArrowRecordBatchBuffers(recordBatch, options) {
15258
+ const data = splitArrowDataBuffers(recordBatch.data, options);
15259
+ return createRecordBatchWithMetadata(recordBatch.schema, data, getRecordBatchMetadata(recordBatch));
15260
+ }
15261
+ function splitArrowDataBuffers(data, options) {
15262
+ const children = data.children.map((childData) => splitArrowDataBuffers(childData, options));
15263
+ const dictionary = data.dictionary ? splitArrowVectorBuffers(data.dictionary, options) : void 0;
15264
+ const buffers = {
15265
+ [BufferType.OFFSET]: splitArrowBuffer(data.buffers[BufferType.OFFSET], options),
15266
+ [BufferType.DATA]: splitArrowBuffer(data.buffers[BufferType.DATA], options),
15267
+ [BufferType.VALIDITY]: splitArrowBuffer(data.buffers[BufferType.VALIDITY], options),
15268
+ [BufferType.TYPE]: splitArrowBuffer(data.buffers[BufferType.TYPE], options)
15269
+ };
15270
+ return createArrowData(
15271
+ data.type,
15272
+ data.offset,
15273
+ data.length,
15274
+ // @ts-expect-error _nullCount is protected. Reuse it to preserve lazy null-count state.
15275
+ data._nullCount,
15276
+ buffers,
15277
+ children,
15278
+ dictionary,
15279
+ getArrowVariadicBuffers(data).map((buffer) => splitArrowBuffer(buffer, options))
15280
+ );
15281
+ }
15282
+ function splitArrowVectorBuffers(vector, options) {
15283
+ return new Vector(vector.data.map((data) => splitArrowDataBuffers(data, options)));
15284
+ }
15285
+ function collectArrowBuffers(data, buffers, visited) {
15286
+ if (visited.has(data))
15287
+ return;
15288
+ visited.add(data);
15289
+ for (const view of [...Object.values(data.buffers), ...getArrowVariadicBuffers(data)]) {
15290
+ if (isArrowTypedArray(view))
15291
+ buffers.add(view.buffer);
15292
+ }
15293
+ for (const child of data.children)
15294
+ collectArrowBuffers(child, buffers, visited);
15295
+ for (const chunk of data.dictionary?.data ?? [])
15296
+ collectArrowBuffers(chunk, buffers, visited);
15297
+ }
15298
+ function splitArrowBuffer(array, options) {
15299
+ if (!isArrowTypedArray(array)) {
15300
+ return array;
15301
+ }
15302
+ const sliced = array.byteOffset !== 0 || array.byteLength !== array.buffer.byteLength;
15303
+ if (!options.retainedBuffers.has(array.buffer) && options.copy !== "all" && (options.copy === "none" || !sliced)) {
15304
+ return array;
15305
+ }
15306
+ let copy = options.copies.get(array);
15307
+ if (!copy) {
15308
+ copy = array instanceof Uint8Array ? new Uint8Array(array) : array.slice();
15309
+ options.copies.set(array, copy);
15310
+ }
15311
+ return copy;
15312
+ }
15313
+ function isArrowTypedArray(value) {
15314
+ return ArrayBuffer.isView(value) && !(value instanceof DataView);
15315
+ }
15316
+ var init_split_arrow_buffers = __esm({
15317
+ "../../node_modules/@math.gl/arrow/dist/arrow/split-arrow-buffers.js"() {
15318
+ init_Arrow_dom();
15319
+ init_arrow_record_batch();
15320
+ init_arrow_data();
15321
+ }
15322
+ });
15323
+
15324
+ // ../../node_modules/@math.gl/arrow/dist/arrow/take-arrow-rows.js
15325
+ var init_take_arrow_rows = __esm({
15326
+ "../../node_modules/@math.gl/arrow/dist/arrow/take-arrow-rows.js"() {
15327
+ init_arrow_data();
15328
+ init_split_arrow_buffers();
15329
+ }
15330
+ });
15331
+
15332
+ // ../../node_modules/@math.gl/arrow/dist/arrow/indexed-arrow-vector.js
15333
+ var init_indexed_arrow_vector = __esm({
15334
+ "../../node_modules/@math.gl/arrow/dist/arrow/indexed-arrow-vector.js"() {
15335
+ init_indexed_arrow_helpers();
15336
+ }
15337
+ });
15338
+
15339
+ // ../../node_modules/@math.gl/arrow/dist/arrow/indexed-arrow-table.js
15340
+ var init_indexed_arrow_table = __esm({
15341
+ "../../node_modules/@math.gl/arrow/dist/arrow/indexed-arrow-table.js"() {
15342
+ init_indexed_arrow_helpers();
15343
+ init_arrow_schema_utils();
15344
+ init_take_arrow_rows();
15345
+ init_indexed_arrow_vector();
15346
+ }
15347
+ });
15348
+
15349
+ // ../../node_modules/@math.gl/arrow/dist/arrow/mapped-arrow-table.js
15350
+ var init_mapped_arrow_table = __esm({
15351
+ "../../node_modules/@math.gl/arrow/dist/arrow/mapped-arrow-table.js"() {
15352
+ init_indexed_arrow_helpers();
15353
+ init_indexed_arrow_table();
15354
+ }
15355
+ });
15356
+
15357
+ // ../../node_modules/@math.gl/arrow/dist/arrow/rename-arrow-columns.js
15358
+ var init_rename_arrow_columns = __esm({
15359
+ "../../node_modules/@math.gl/arrow/dist/arrow/rename-arrow-columns.js"() {
15360
+ init_arrow_schema_utils();
15361
+ }
15362
+ });
15363
+
15364
+ // ../../node_modules/@math.gl/arrow/dist/arrow/arrow-table-transport.js
15365
+ function dehydrateArrowTable(arrowTable, options) {
15366
+ const splitTable = splitArrowBuffers(arrowTable, options);
15367
+ return {
15368
+ transport: "arrow-js",
15369
+ version: 1,
15370
+ schema: tableToIPC(new Table(splitTable.schema, [])),
15371
+ metadataVersion: splitTable.schema.metadataVersion,
15372
+ batches: splitTable.batches.map((batch) => {
15373
+ const metadata = getRecordBatchMetadata(batch);
15374
+ return {
15375
+ ...dehydrateArrowData(batch.data),
15376
+ ...metadata !== void 0 ? { metadata: [...metadata] } : {}
15377
+ };
15378
+ })
15379
+ };
15380
+ }
15381
+ function hydrateArrowTable(table) {
15382
+ if (table.transport !== "arrow-js" || table.version !== 1) {
15383
+ throw new Error("Unsupported Arrow column-buffer transport protocol.");
15384
+ }
15385
+ const decodedSchema = tableFromIPC(table.schema).schema;
15386
+ const schema = new Schema2(decodedSchema.fields, decodedSchema.metadata, decodedSchema.dictionaries, table.metadataVersion);
15387
+ const type = new Struct(schema.fields);
15388
+ const batches = table.batches.map((payload) => {
15389
+ const data = hydrateArrowData(payload, type);
15390
+ return createRecordBatchWithMetadata(schema, data, payload.metadata && new Map(payload.metadata));
15391
+ });
15392
+ return new Table(schema, batches);
15393
+ }
15394
+ function dehydrateArrowData(data) {
15395
+ return {
15396
+ offset: data.offset,
15397
+ length: data.length,
15398
+ nullCount: data.nullCount,
15399
+ buffers: {
15400
+ [BufferType.OFFSET]: data.buffers[BufferType.OFFSET],
15401
+ [BufferType.DATA]: data.buffers[BufferType.DATA],
15402
+ [BufferType.VALIDITY]: data.buffers[BufferType.VALIDITY],
15403
+ [BufferType.TYPE]: data.buffers[BufferType.TYPE]
15404
+ },
15405
+ children: data.children.map((child) => dehydrateArrowData(child)),
15406
+ variadicBuffers: getArrowVariadicBuffers(data),
15407
+ dictionary: data.dictionary?.data.map((chunk) => dehydrateArrowData(chunk))
15408
+ };
15409
+ }
15410
+ function hydrateArrowData(data, type) {
15411
+ const children = data.children.map((child, index) => hydrateArrowData(child, type.children[index].type));
15412
+ const dictionary = data.dictionary && DataType.isDictionary(type) ? new Vector(data.dictionary.map((chunk) => hydrateArrowData(chunk, type.dictionary))) : void 0;
15413
+ return createArrowData(type, data.offset, data.length, data.nullCount, data.buffers, children, dictionary, data.variadicBuffers);
15414
+ }
15415
+ function dehydrateArrowRecordBatch(batch, options) {
15416
+ return dehydrateArrowTable(new Table(batch.schema, [batch]), options);
15417
+ }
15418
+ function hydrateArrowRecordBatch(payload) {
15419
+ if (payload.batches.length !== 1) {
15420
+ throw new Error("Arrow record batch transport requires exactly one batch.");
15421
+ }
15422
+ return hydrateArrowTable(payload).batches[0];
15423
+ }
15424
+ var init_arrow_table_transport = __esm({
15425
+ "../../node_modules/@math.gl/arrow/dist/arrow/arrow-table-transport.js"() {
15426
+ init_Arrow_dom();
15427
+ init_arrow_record_batch();
15428
+ init_arrow_data();
15429
+ init_split_arrow_buffers();
15430
+ }
15431
+ });
15432
+
15433
+ // ../../node_modules/@math.gl/arrow/dist/arrow/arrow-column-utils.js
15434
+ var init_arrow_column_utils = __esm({
15435
+ "../../node_modules/@math.gl/arrow/dist/arrow/arrow-column-utils.js"() {
15436
+ }
15437
+ });
15438
+
15439
+ // ../../node_modules/@math.gl/arrow/dist/arrow/index.js
15440
+ var init_arrow = __esm({
15441
+ "../../node_modules/@math.gl/arrow/dist/arrow/index.js"() {
15442
+ init_indexed_arrow_table();
15443
+ init_indexed_arrow_vector();
15444
+ init_mapped_arrow_table();
15445
+ init_arrow_schema_utils();
15446
+ init_rename_arrow_columns();
15447
+ init_split_arrow_buffers();
15448
+ init_arrow_table_transport();
15449
+ init_arrow_column_utils();
15450
+ init_take_arrow_rows();
15451
+ init_arrow_record_batch();
15452
+ }
15453
+ });
15454
+
15455
+ // ../../node_modules/@math.gl/arrow/dist/index.js
15456
+ var init_dist2 = __esm({
15457
+ "../../node_modules/@math.gl/arrow/dist/index.js"() {
15458
+ init_arrow();
15459
+ }
15460
+ });
15461
+
15462
+ // ../core/src/arrow-worker-transport.ts
15463
+ function deserializeArrowWorkerTable(result) {
15464
+ if (isArrowWorkerEnvelope(result)) {
15465
+ return { ...result.metadata, shape: "arrow-table", data: hydrateWorkerTable(result) };
15466
+ }
15467
+ if (isLegacyArrowWorkerEnvelope(result)) {
15468
+ const { arrowBatchMetadata: _snapshots, data: _columns, ...metadata } = result;
15469
+ return { ...metadata, data: hydrateWorkerTable(result) };
15470
+ }
15471
+ throw new Error("Workers require Arrow column transport");
15472
+ }
15473
+ function serializeNativeArrowWorkerResult(result, options = { copy: "all" }) {
15474
+ const batch = result instanceof RecordBatch3;
15475
+ if (!batch && !(result instanceof Table)) {
15476
+ throw new Error("Workers require Arrow table output");
15477
+ }
15478
+ return {
15479
+ transport: batch ? "arrow-record-batch" : "arrow-table-columns",
15480
+ columns: batch ? { data: dehydrateArrowRecordBatch(result, options) } : serializeWorkerColumns(result, options)
15481
+ };
15482
+ }
15483
+ function deserializeNativeArrowWorkerResult(result) {
15484
+ const payload = result;
15485
+ if (payload?.transport !== "arrow-table-columns" && payload?.transport !== "arrow-record-batch" || !hasArrowWorkerColumns(payload.columns)) {
15486
+ throw new Error("Workers require Arrow column transport");
15487
+ }
15488
+ if (payload.transport === "arrow-record-batch" && !payload.columns.arrowBatchMetadata) {
15489
+ return hydrateArrowRecordBatch(payload.columns.data);
15490
+ }
15491
+ const data = hydrateWorkerTable(payload.columns);
15492
+ return payload.transport === "arrow-record-batch" ? data.batches[0] : data;
15493
+ }
15494
+ function serializeArrowWorkerResult(result, options) {
15495
+ const workerOptions = options;
15496
+ const bufferCopyMode = workerOptions?.core?.workerTransferBufferCopy ?? workerOptions?.workerTransferBufferCopy;
15497
+ if (result instanceof Table || result instanceof RecordBatch3) {
15498
+ return serializeNativeArrowWorkerResult(result, { copy: bufferCopyMode ?? "all" });
15499
+ }
15500
+ if (!isArrowTableWrapper(result)) {
15501
+ return result;
15502
+ }
15503
+ const { data, shape: _shape, ...metadata } = result;
15504
+ return {
15505
+ transport: "arrow-column-envelope",
15506
+ metadata: structuredClone(metadata),
15507
+ ...serializeWorkerColumns(data, bufferCopyMode ? { copy: bufferCopyMode } : void 0)
15508
+ };
15509
+ }
15510
+ function deserializeArrowWorkerResult(result) {
15511
+ const transport = result?.transport;
15512
+ if (transport === "arrow-table-columns" || transport === "arrow-record-batch") {
15513
+ return deserializeNativeArrowWorkerResult(result);
15514
+ }
15515
+ return isArrowWorkerEnvelope(result) || isLegacyArrowWorkerEnvelope(result) ? deserializeArrowWorkerTable(result) : result;
15516
+ }
15517
+ function isArrowTableWrapper(value) {
15518
+ const table = value;
15519
+ return Boolean(
15520
+ table && table.shape === "arrow-table" && table.data && typeof table.data === "object" && "batches" in table.data
15521
+ );
15522
+ }
15523
+ function hasArrowWorkerColumns(value) {
15524
+ const columns = value;
15525
+ return columns?.data?.transport === "arrow-js" && Array.isArray(columns.data.batches);
15526
+ }
15527
+ function isArrowWorkerEnvelope(value) {
15528
+ return value?.transport === "arrow-column-envelope" && hasArrowWorkerColumns(value);
15529
+ }
15530
+ function isLegacyArrowWorkerEnvelope(value) {
15531
+ return value?.shape === "arrow-table" && hasArrowWorkerColumns(value);
15532
+ }
15533
+ function serializeWorkerColumns(table, options) {
15534
+ return {
15535
+ arrowBatchMetadata: snapshotBatchMetadata(table),
15536
+ data: dehydrateWorkerTable(table, options)
15537
+ };
15538
+ }
15539
+ function dehydrateWorkerTable(table, options) {
15540
+ const payload = dehydrateArrowTable(table, options);
15541
+ if (table.numCols === 0) {
15542
+ for (const [index, batch] of table.batches.entries()) {
15543
+ payload.batches[index].length = batch.numRows;
15544
+ }
15545
+ }
15546
+ return payload;
15547
+ }
15548
+ function snapshotBatchMetadata(table) {
15549
+ return table.batches.map((batch) => ({
15550
+ schema: tableToIPC(new Table(batch.schema, [])),
15551
+ metadata: Array.from(batch.metadata)
15552
+ }));
15553
+ }
15554
+ function hydrateWorkerTable(result) {
15555
+ const { arrowBatchMetadata, data } = result;
15556
+ const table = hydrateArrowTable(data);
15557
+ const batches = table.batches.map((batch, index) => {
15558
+ const snapshot = arrowBatchMetadata?.[index];
15559
+ const restored = snapshot ? new RecordBatch3(
15560
+ tableFromIPC(snapshot.schema).schema,
15561
+ batch.data,
15562
+ new Map(snapshot.metadata)
15563
+ ) : batch;
15564
+ const rowCount = data.batches[index].length;
15565
+ if (restored.numCols === 0 && restored.numRows !== rowCount) {
15566
+ Object.defineProperty(restored, "data", {
15567
+ value: new Data(new Struct([]), 0, rowCount, 0, void 0, [])
15568
+ });
15569
+ }
15570
+ return restored;
15571
+ });
15572
+ return new Table(table.schema, batches);
15573
+ }
15574
+ var init_arrow_worker_transport = __esm({
15575
+ "../core/src/arrow-worker-transport.ts"() {
15576
+ "use strict";
15577
+ init_Arrow_dom();
15578
+ init_dist2();
15579
+ }
15580
+ });
15581
+
15582
+ // ../core/src/schema-utils/lib/schema/data-type.ts
15583
+ function getDataTypeFromValue(value, defaultNumberType = "float32") {
15584
+ if (value instanceof Date) {
15585
+ return "date-millisecond";
15586
+ }
15587
+ if (typeof value === "number") {
15588
+ return defaultNumberType;
15589
+ }
15590
+ if (typeof value === "boolean") {
15591
+ return "bool";
15592
+ }
15593
+ if (typeof value === "string") {
15594
+ return "utf8";
15595
+ }
15596
+ if (value === null || value === "undefined") {
15597
+ return "null";
15598
+ }
15599
+ return "null";
15600
+ }
15601
+ function getDataTypeFromArray(array) {
15602
+ let type = getDataTypeFromTypedArray(array);
15603
+ if (type !== "null") {
15604
+ return { type, nullable: false };
15605
+ }
15606
+ if (array.length > 0) {
15607
+ type = getDataTypeFromValue(array[0]);
15608
+ return { type, nullable: true };
15609
+ }
15610
+ return { type: "null", nullable: true };
15611
+ }
15612
+ function getDataTypeFromTypedArray(array) {
15613
+ if (typeof Float16Array !== "undefined" && array instanceof Float16Array) {
15614
+ return "float16";
15615
+ }
15616
+ switch (array.constructor) {
15617
+ case Int8Array:
15618
+ return "int8";
15619
+ case Uint8Array:
15620
+ case Uint8ClampedArray:
15621
+ return "uint8";
15622
+ case Int16Array:
15623
+ return "int16";
15624
+ case Uint16Array:
15625
+ return "uint16";
15626
+ case Int32Array:
15627
+ return "int32";
15628
+ case Uint32Array:
15629
+ return "uint32";
15630
+ case BigInt64Array:
15631
+ return "int64";
15632
+ case BigUint64Array:
15633
+ return "uint64";
15634
+ case Float32Array:
15635
+ return "float32";
15636
+ case Float64Array:
15637
+ return "float64";
15638
+ default:
15639
+ return "null";
15640
+ }
15641
+ }
15642
+ var init_data_type = __esm({
15643
+ "../core/src/schema-utils/lib/schema/data-type.ts"() {
15644
+ "use strict";
15645
+ }
15646
+ });
15647
+
15648
+ // ../core/src/schema-utils/lib/schema/convert-arrow-schema.ts
15649
+ function serializeArrowSchema(arrowSchema) {
15650
+ return {
15651
+ fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
15652
+ metadata: serializeArrowMetadata(arrowSchema.metadata)
15653
+ };
15654
+ }
15655
+ function serializeArrowMetadata(arrowMetadata) {
15621
15656
  return Object.fromEntries(arrowMetadata);
15622
15657
  }
15623
15658
  function deserializeArrowMetadata(metadata) {
@@ -16039,261 +16074,19 @@ return true;`);
16039
16074
  }
16040
16075
  });
16041
16076
 
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)
16075
- );
16076
- }
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;
16077
+ // ../core/src/lib/loader-utils/native-arrow.ts
16078
+ function isNativeArrowTable(value) {
16169
16079
  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
16080
+ 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"
16207
16081
  );
16208
16082
  }
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"() {
16083
+ var init_native_arrow = __esm({
16084
+ "../core/src/lib/loader-utils/native-arrow.ts"() {
16292
16085
  "use strict";
16293
16086
  }
16294
16087
  });
16295
16088
 
16296
- // ../core/src/schema-utils/lib/mesh/mesh-utils.ts
16089
+ // ../core/src/schema-utils/lib/mesh/get-mesh-bounding-box.ts
16297
16090
  function getMeshBoundingBox(attributes) {
16298
16091
  const positionAttribute = attributes?.POSITION;
16299
16092
  if (!positionAttribute || !("value" in positionAttribute) || !positionAttribute.value.length) {
@@ -16323,9 +16116,17 @@ return true;`);
16323
16116
  [maxX, maxY, maxZ]
16324
16117
  ];
16325
16118
  }
16119
+ var init_get_mesh_bounding_box = __esm({
16120
+ "../core/src/schema-utils/lib/mesh/get-mesh-bounding-box.ts"() {
16121
+ "use strict";
16122
+ }
16123
+ });
16124
+
16125
+ // ../core/src/schema-utils/lib/mesh/mesh-utils.ts
16326
16126
  var init_mesh_utils = __esm({
16327
16127
  "../core/src/schema-utils/lib/mesh/mesh-utils.ts"() {
16328
16128
  "use strict";
16129
+ init_get_mesh_bounding_box();
16329
16130
  }
16330
16131
  });
16331
16132
 
@@ -16478,31 +16279,7 @@ return true;`);
16478
16279
  });
16479
16280
 
16480
16281
  // ../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) {
16282
+ function convertMeshToArrowTableWrapper(mesh, batchSize) {
16506
16283
  return makeMeshArrowTable(mesh.attributes, {
16507
16284
  schema: mesh.schema,
16508
16285
  topology: mesh.topology,
@@ -16663,6 +16440,7 @@ return true;`);
16663
16440
 
16664
16441
  // ../core/src/schema-utils/lib/mesh/convert-table-to-mesh.ts
16665
16442
  function convertTableToMesh(table) {
16443
+ if (isNativeArrowTable(table)) return convertArrowTableToMesh(table);
16666
16444
  switch (table.shape) {
16667
16445
  // case 'columnar-table':
16668
16446
  // return convertColumnarTableToMesh(table);
@@ -16673,8 +16451,10 @@ return true;`);
16673
16451
  }
16674
16452
  }
16675
16453
  function convertArrowTableToMesh(table) {
16676
- const arrowTable = table.data;
16454
+ const arrowTable = isNativeArrowTable(table) ? table : table.data;
16677
16455
  const schema = serializeArrowSchema(arrowTable.schema);
16456
+ const localBounds = arrowTable.batches.length === 1 ? arrowTable.batches[0].metadata.get("boundingBox") : void 0;
16457
+ if (localBounds) schema.metadata = { ...schema.metadata, boundingBox: localBounds };
16678
16458
  const fields = schema.fields;
16679
16459
  const attributes = {};
16680
16460
  const columns = [];
@@ -16829,6 +16609,7 @@ return true;`);
16829
16609
  init_Arrow_dom();
16830
16610
  init_arrow_fixed_size_list_utils();
16831
16611
  init_convert_arrow_schema();
16612
+ init_native_arrow();
16832
16613
  init_mesh_utils();
16833
16614
  }
16834
16615
  });
@@ -17136,106 +16917,52 @@ return true;`);
17136
16917
 
17137
16918
  // src/terrain/lib/helpers/skirt.ts
17138
16919
  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
- });
16920
+ const positions = attributes.POSITION.value;
16921
+ const sourceIndices = Array.isArray(triangles) ? Uint32Array.from(triangles) : triangles;
16922
+ const edges = outsideIndices ? getBoundaryEdges(outsideIndices, positions) : void 0;
16923
+ const skirt = createTerrainSkirt(
16924
+ { positions, indices: sourceIndices },
16925
+ { height: skirtHeight, edges }
16926
+ );
16927
+ const textureCoordinates = attributes.TEXCOORD_0.value;
16928
+ const outputTextureCoordinates = new textureCoordinates.constructor(
16929
+ skirt.positions.length / 3 * 2
16930
+ );
16931
+ outputTextureCoordinates.set(textureCoordinates);
16932
+ for (let i = 0; i < skirt.sourceVertexIndices.length; i++) {
16933
+ const source = skirt.sourceVertexIndices[i];
16934
+ outputTextureCoordinates.set(
16935
+ textureCoordinates.subarray(source * 2, source * 2 + 2),
16936
+ (skirt.skirtVertexOffset + i) * 2
16937
+ );
17154
16938
  }
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);
16939
+ attributes.POSITION.value = skirt.positions;
16940
+ attributes.TEXCOORD_0.value = outputTextureCoordinates;
17158
16941
  return {
17159
16942
  attributes,
17160
- triangles: resultTriangles
16943
+ triangles: Array.isArray(triangles) ? Array.from(skirt.indices) : skirt.indices
17161
16944
  };
17162
16945
  }
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]);
16946
+ function getBoundaryEdges(indices, positions) {
16947
+ indices.westIndices.sort((a, b) => positions[3 * a + 1] - positions[3 * b + 1]);
16948
+ indices.eastIndices.sort((a, b) => positions[3 * b + 1] - positions[3 * a + 1]);
16949
+ indices.southIndices.sort((a, b) => positions[3 * b] - positions[3 * a]);
16950
+ indices.northIndices.sort((a, b) => positions[3 * a] - positions[3 * b]);
17188
16951
  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
- }
16952
+ for (const side of [
16953
+ indices.westIndices,
16954
+ indices.northIndices,
16955
+ indices.eastIndices,
16956
+ indices.southIndices
16957
+ ]) {
16958
+ for (let i = 1; i < side.length; i++) edges.push(side[i - 1], side[i]);
17194
16959
  }
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;
16960
+ return Uint32Array.from(edges);
17234
16961
  }
17235
16962
  var init_skirt = __esm({
17236
16963
  "src/terrain/lib/helpers/skirt.ts"() {
17237
16964
  "use strict";
17238
- init_loader_utils();
16965
+ init_terrain();
17239
16966
  }
17240
16967
  });
17241
16968
 
@@ -17333,7 +17060,7 @@ return true;`);
17333
17060
  var init_version = __esm({
17334
17061
  "src/terrain/lib/utils/version.ts"() {
17335
17062
  "use strict";
17336
- VERSION = true ? "5.0.0-beta.1" : "latest";
17063
+ VERSION = true ? "5.0.0-beta.10" : "latest";
17337
17064
  }
17338
17065
  });
17339
17066
 
@@ -17355,6 +17082,18 @@ return true;`);
17355
17082
  }
17356
17083
  });
17357
17084
 
17085
+ // src/quantized-mesh-loader.ts
17086
+ var quantized_mesh_loader_exports = {};
17087
+ __export(quantized_mesh_loader_exports, {
17088
+ QuantizedMeshLoaderWithParser: () => QuantizedMeshLoaderWithParser
17089
+ });
17090
+ var init_quantized_mesh_loader = __esm({
17091
+ "src/quantized-mesh-loader.ts"() {
17092
+ "use strict";
17093
+ init_quantized_mesh_loader2();
17094
+ }
17095
+ });
17096
+
17358
17097
  // src/terrain/quantized-mesh-loader-types.ts
17359
17098
  var QuantizedMeshLoader;
17360
17099
  var init_quantized_mesh_loader_types = __esm({
@@ -17363,6 +17102,8 @@ return true;`);
17363
17102
  init_version();
17364
17103
  init_terrain_format();
17365
17104
  QuantizedMeshLoader = {
17105
+ defaultShape: "arrow",
17106
+ supportsNativeArrow: true,
17366
17107
  dataType: null,
17367
17108
  batchType: null,
17368
17109
  ...QuantizedMeshFormat,
@@ -17372,7 +17113,7 @@ return true;`);
17372
17113
  preload: async () => (await Promise.resolve().then(() => (init_quantized_mesh_loader(), quantized_mesh_loader_exports))).QuantizedMeshLoaderWithParser,
17373
17114
  options: {
17374
17115
  "quantized-mesh": {
17375
- shape: "arrow-table",
17116
+ shape: "arrow",
17376
17117
  bounds: [0, 0, 1, 1],
17377
17118
  skirtHeight: null
17378
17119
  }
@@ -17382,15 +17123,11 @@ return true;`);
17382
17123
  });
17383
17124
 
17384
17125
  // src/terrain/quantized-mesh-loader.ts
17385
- var quantized_mesh_loader_exports = {};
17386
- __export(quantized_mesh_loader_exports, {
17387
- QuantizedMeshLoaderWithParser: () => QuantizedMeshLoaderWithParser
17388
- });
17389
17126
  function parseQuantizedMeshInRequestedShape(arrayBuffer, options) {
17390
17127
  const mesh = parseQuantizedMesh(arrayBuffer, options?.["quantized-mesh"]);
17391
- const table = convertMeshToTable(mesh, "arrow-table");
17392
- if (options?.["quantized-mesh"]?.shape === "arrow-table") {
17393
- return table;
17128
+ const table = convertMeshToArrowTableWrapper(mesh);
17129
+ if (options?.["quantized-mesh"]?.shape === "arrow") {
17130
+ return table.data;
17394
17131
  }
17395
17132
  return {
17396
17133
  ...convertTableToMesh(table),
@@ -17399,10 +17136,10 @@ return true;`);
17399
17136
  };
17400
17137
  }
17401
17138
  var _QuantizedMeshLoaderPreload, QuantizedMeshLoaderMetadataWithoutPreload, QuantizedMeshLoaderWithParser;
17402
- var init_quantized_mesh_loader = __esm({
17139
+ var init_quantized_mesh_loader2 = __esm({
17403
17140
  "src/terrain/quantized-mesh-loader.ts"() {
17404
17141
  "use strict";
17405
- init_arrow_transport();
17142
+ init_arrow_worker_transport();
17406
17143
  init_schema_utils();
17407
17144
  init_parse_quantized_mesh();
17408
17145
  init_quantized_mesh_loader_types();
@@ -17417,8 +17154,1107 @@ return true;`);
17417
17154
  }
17418
17155
  });
17419
17156
 
17157
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/node/worker_threads-browser.js
17158
+ var parentPort = globalThis.process?.getBuiltinModule?.("node:worker_threads")?.parentPort ?? null;
17159
+
17160
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-utils/get-transfer-list.js
17161
+ function getTransferList(object, recursive = true, transfers) {
17162
+ const transfersSet = transfers || /* @__PURE__ */ new Set();
17163
+ const seen = /* @__PURE__ */ new Set();
17164
+ function visit(value) {
17165
+ if (!value || typeof value !== "object" || seen.has(value))
17166
+ return;
17167
+ seen.add(value);
17168
+ if (isTransferable(value))
17169
+ transfersSet.add(value);
17170
+ else if (ArrayBuffer.isView(value)) {
17171
+ if (isTransferable(value.buffer))
17172
+ transfersSet.add(value.buffer);
17173
+ } else if (recursive && typeof MessageChannel !== "undefined" && value instanceof MessageChannel) {
17174
+ visit(value.port1);
17175
+ visit(value.port2);
17176
+ } else if (recursive && value instanceof Map) {
17177
+ for (const [key, item] of value) {
17178
+ visit(key);
17179
+ visit(item);
17180
+ }
17181
+ } else if (recursive && value instanceof Set) {
17182
+ for (const item of value)
17183
+ visit(item);
17184
+ } else if (recursive) {
17185
+ for (const key of Object.keys(value))
17186
+ visit(value[key]);
17187
+ }
17188
+ }
17189
+ visit(object);
17190
+ return transfers === void 0 ? Array.from(transfersSet) : [];
17191
+ }
17192
+ function isTransferable(object) {
17193
+ if (!object) {
17194
+ return false;
17195
+ }
17196
+ if (object instanceof ArrayBuffer) {
17197
+ return true;
17198
+ }
17199
+ if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
17200
+ return true;
17201
+ }
17202
+ if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
17203
+ return true;
17204
+ }
17205
+ if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
17206
+ return true;
17207
+ }
17208
+ return false;
17209
+ }
17210
+
17211
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-body.js
17212
+ async function getParentPort() {
17213
+ return parentPort;
17214
+ }
17215
+ var onMessageWrapperMap = /* @__PURE__ */ new Map();
17216
+ var WorkerBody = class {
17217
+ /** Check that we are actually in a worker thread */
17218
+ static async inWorkerThread() {
17219
+ const workerGlobalScope = globalThis.WorkerGlobalScope;
17220
+ return typeof workerGlobalScope === "function" && globalThis instanceof workerGlobalScope || Boolean(await getParentPort());
17221
+ }
17222
+ /*
17223
+ * (type: WorkerMessageType, payload: WorkerMessagePayload) => any
17224
+ */
17225
+ static set onmessage(onMessage) {
17226
+ async function handleMessage(message) {
17227
+ const parentPort3 = await getParentPort();
17228
+ const { type, payload } = parentPort3 ? message : message.data;
17229
+ onMessage(type, payload);
17230
+ }
17231
+ getParentPort().then((parentPort3) => {
17232
+ if (parentPort3) {
17233
+ parentPort3.on("message", (message) => {
17234
+ handleMessage(message);
17235
+ });
17236
+ parentPort3.on("exit", () => console.debug("Node worker closing"));
17237
+ } else {
17238
+ globalThis.onmessage = handleMessage;
17239
+ }
17240
+ });
17241
+ }
17242
+ static async addEventListener(onMessage) {
17243
+ let onMessageWrapper = onMessageWrapperMap.get(onMessage);
17244
+ if (!onMessageWrapper) {
17245
+ onMessageWrapper = (message) => {
17246
+ const messageData = getWorkerMessageData(message);
17247
+ if (!messageData) {
17248
+ return;
17249
+ }
17250
+ onMessage(messageData.type, messageData.payload);
17251
+ };
17252
+ onMessageWrapperMap.set(onMessage, onMessageWrapper);
17253
+ }
17254
+ const parentPort3 = await getParentPort();
17255
+ if (parentPort3) {
17256
+ parentPort3.on("message", onMessageWrapper);
17257
+ } else {
17258
+ globalThis.addEventListener("message", onMessageWrapper);
17259
+ }
17260
+ }
17261
+ static async removeEventListener(onMessage) {
17262
+ const onMessageWrapper = onMessageWrapperMap.get(onMessage);
17263
+ onMessageWrapperMap.delete(onMessage);
17264
+ if (!onMessageWrapper) {
17265
+ return;
17266
+ }
17267
+ const parentPort3 = await getParentPort();
17268
+ if (parentPort3) {
17269
+ parentPort3.off("message", onMessageWrapper);
17270
+ } else {
17271
+ globalThis.removeEventListener("message", onMessageWrapper);
17272
+ }
17273
+ }
17274
+ /**
17275
+ * Send a message from a worker to creating thread (main thread)
17276
+ * @param type
17277
+ * @param payload
17278
+ */
17279
+ static async postMessage(type, payload, copy = false) {
17280
+ const data = { source: "loaders.gl", type, payload };
17281
+ const transferList = copy ? [] : getTransferList(payload);
17282
+ const parentPort3 = await getParentPort();
17283
+ if (parentPort3) {
17284
+ parentPort3.postMessage(data, transferList);
17285
+ } else {
17286
+ globalThis.postMessage(data, transferList);
17287
+ }
17288
+ }
17289
+ };
17290
+ function getWorkerMessageData(message) {
17291
+ if (!message || typeof message !== "object") {
17292
+ return null;
17293
+ }
17294
+ const messageData = "data" in message && message.type === "message" ? message.data : message;
17295
+ return messageData && typeof messageData.source === "string" && messageData.source.startsWith("loaders.gl") ? messageData : null;
17296
+ }
17297
+
17298
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/async-queue/async-queue.js
17299
+ var AsyncQueue = class {
17300
+ constructor() {
17301
+ this._values = [];
17302
+ this._settlers = [];
17303
+ this._closed = false;
17304
+ }
17305
+ /** Return an async iterator for this queue */
17306
+ [Symbol.asyncIterator]() {
17307
+ return this;
17308
+ }
17309
+ /** Push a new value - the async iterator will yield a promise resolved to this value */
17310
+ push(value) {
17311
+ return this.enqueue(value);
17312
+ }
17313
+ /**
17314
+ * Push a new value - the async iterator will yield a promise resolved to this value
17315
+ * Add an error - the async iterator will yield a promise rejected with this value
17316
+ */
17317
+ enqueue(value) {
17318
+ if (this._closed) {
17319
+ throw new Error("Closed");
17320
+ }
17321
+ if (this._settlers.length > 0) {
17322
+ if (this._values.length > 0) {
17323
+ throw new Error("Illegal internal state");
17324
+ }
17325
+ const settler = this._settlers.shift();
17326
+ if (value instanceof Error) {
17327
+ settler.reject(value);
17328
+ } else {
17329
+ settler.resolve({ value });
17330
+ }
17331
+ } else {
17332
+ this._values.push(value);
17333
+ }
17334
+ }
17335
+ /** Indicate that we not waiting for more values - The async iterator will be done */
17336
+ close() {
17337
+ while (this._settlers.length > 0) {
17338
+ const settler = this._settlers.shift();
17339
+ settler.resolve({ done: true });
17340
+ }
17341
+ this._closed = true;
17342
+ }
17343
+ // ITERATOR IMPLEMENTATION
17344
+ /** @returns a Promise for an IteratorResult */
17345
+ next() {
17346
+ if (this._values.length > 0) {
17347
+ const value = this._values.shift();
17348
+ if (value instanceof Error) {
17349
+ return Promise.reject(value);
17350
+ }
17351
+ return Promise.resolve({ done: false, value });
17352
+ }
17353
+ if (this._closed) {
17354
+ if (this._settlers.length > 0) {
17355
+ throw new Error("Illegal internal state");
17356
+ }
17357
+ return Promise.resolve({ done: true, value: void 0 });
17358
+ }
17359
+ return new Promise((resolve, reject) => {
17360
+ this._settlers.push({ resolve, reject });
17361
+ });
17362
+ }
17363
+ };
17364
+
17365
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/shared-state.js
17366
+ var SharedWorkerState = class {
17367
+ constructor(buffer) {
17368
+ if (typeof SharedArrayBuffer === "undefined" || !(buffer instanceof SharedArrayBuffer) || buffer.byteLength !== 16)
17369
+ throw new Error("Expected a 16-byte shared worker control buffer");
17370
+ this.buffer = buffer;
17371
+ this.values = new Int32Array(buffer);
17372
+ }
17373
+ get snapshot() {
17374
+ return {
17375
+ cancelled: Atomics.load(this.values, 0) !== 0,
17376
+ completed: Atomics.load(this.values, 1),
17377
+ total: Atomics.load(this.values, 2),
17378
+ revision: Atomics.load(this.values, 3)
17379
+ };
17380
+ }
17381
+ cancel() {
17382
+ Atomics.store(this.values, 0, 1);
17383
+ Atomics.add(this.values, 3, 1);
17384
+ Atomics.notify(this.values, 0);
17385
+ }
17386
+ throwIfCancelled() {
17387
+ if (Atomics.load(this.values, 0) !== 0) {
17388
+ const error = new Error("Shared worker task was cancelled");
17389
+ error.name = "AbortError";
17390
+ throw error;
17391
+ }
17392
+ }
17393
+ /** Integer counters for application-defined work; messages still carry phase names and units. */
17394
+ setProgress(completed, total = -1) {
17395
+ if (!Number.isInteger(completed) || completed < 0 || completed > 2147483647 || !Number.isInteger(total) || total < -1 || total > 2147483647) {
17396
+ throw new RangeError("Shared progress requires nonnegative int32 counts (or total -1)");
17397
+ }
17398
+ Atomics.store(this.values, 1, completed);
17399
+ Atomics.store(this.values, 2, total);
17400
+ Atomics.add(this.values, 3, 1);
17401
+ }
17402
+ };
17403
+
17404
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/validate-output-ownership.js
17405
+ function validateOutputOwnership(ownership) {
17406
+ if (ownership !== void 0 && ownership !== "copy" && ownership !== "transfer") {
17407
+ throw new Error("Invalid worker output ownership");
17408
+ }
17409
+ }
17410
+
17411
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/create-worker.js
17412
+ var requestId = 0;
17413
+ var activeController = null;
17414
+ var activeInputBatches = null;
17415
+ var activeOutputAcknowledgements = null;
17416
+ async function createWorker(process2, processInBatches, preload) {
17417
+ if (!await WorkerBody.inWorkerThread()) {
17418
+ return;
17419
+ }
17420
+ const context = {
17421
+ process: processOnMainThread
17422
+ };
17423
+ WorkerBody.onmessage = async (type, payload) => {
17424
+ if (type === "cancel") {
17425
+ activeController?.abort();
17426
+ activeInputBatches?.close();
17427
+ activeOutputAcknowledgements?.close();
17428
+ return;
17429
+ }
17430
+ const controller = type === "process" || type === "process-in-batches" ? new AbortController() : void 0;
17431
+ if (controller)
17432
+ activeController = controller;
17433
+ const startedAt = performance.now();
17434
+ const reporter = type === "process" || type === "process-in-batches" ? createProgressReporter() : void 0;
17435
+ let sharedState;
17436
+ const throwIfAborted = () => {
17437
+ controller?.signal.throwIfAborted();
17438
+ sharedState?.throwIfCancelled();
17439
+ };
17440
+ const jobContext = {
17441
+ ...context,
17442
+ signal: controller?.signal,
17443
+ sharedState,
17444
+ throwIfAborted,
17445
+ reportProgress: (progress) => {
17446
+ if (!controller?.signal.aborted && !sharedState?.snapshot.cancelled)
17447
+ reporter?.report(progress);
17448
+ }
17449
+ };
17450
+ try {
17451
+ if (controller && payload.options?.["sharedState"]) {
17452
+ sharedState = new SharedWorkerState(payload.options["sharedState"]);
17453
+ jobContext.sharedState = sharedState;
17454
+ }
17455
+ switch (type) {
17456
+ case "preload":
17457
+ await preload?.();
17458
+ WorkerBody.postMessage("done", {});
17459
+ break;
17460
+ case "process":
17461
+ throwIfAborted();
17462
+ validateOutputOwnership(payload.options?.["outputOwnership"]);
17463
+ if (!process2) {
17464
+ throw new Error("Worker does not support atomic processing");
17465
+ }
17466
+ const result = await process2(payload.input, payload.options || {}, jobContext, payload.context || {});
17467
+ throwIfAborted();
17468
+ reporter?.finish();
17469
+ await WorkerBody.postMessage("done", {
17470
+ result,
17471
+ executionMs: performance.now() - startedAt
17472
+ }, payload.options?.["outputOwnership"] === "copy");
17473
+ break;
17474
+ case "process-in-batches":
17475
+ throwIfAborted();
17476
+ validateOutputOwnership(payload.options?.["outputOwnership"]);
17477
+ if (!processInBatches) {
17478
+ throw new Error("Worker does not support batched processing");
17479
+ }
17480
+ const inputBatches = new AsyncQueue();
17481
+ const outputAcknowledgements = new AsyncQueue();
17482
+ activeInputBatches = inputBatches;
17483
+ activeOutputAcknowledgements = outputAcknowledgements;
17484
+ try {
17485
+ const resultIterator = processInBatches(createDemandDrivenIterator(inputBatches), payload.options || {}, jobContext, payload.context || {});
17486
+ for await (const batch of resultIterator) {
17487
+ throwIfAborted();
17488
+ await WorkerBody.postMessage("output-batch", { result: batch }, payload.options?.["outputOwnership"] === "copy");
17489
+ await outputAcknowledgements.next();
17490
+ }
17491
+ throwIfAborted();
17492
+ reporter?.finish();
17493
+ await WorkerBody.postMessage("done", { executionMs: performance.now() - startedAt });
17494
+ } finally {
17495
+ activeInputBatches = null;
17496
+ activeOutputAcknowledgements = null;
17497
+ }
17498
+ break;
17499
+ case "input-batch":
17500
+ if (!activeInputBatches) {
17501
+ throw new Error("Worker has no active batched processing session");
17502
+ }
17503
+ activeInputBatches.push(payload.input);
17504
+ break;
17505
+ case "input-done":
17506
+ if (!activeInputBatches) {
17507
+ throw new Error("Worker has no active batched processing session");
17508
+ }
17509
+ activeInputBatches.close();
17510
+ break;
17511
+ case "output-ack":
17512
+ if (!activeOutputAcknowledgements) {
17513
+ throw new Error("Worker has no active batched processing session");
17514
+ }
17515
+ activeOutputAcknowledgements.push(void 0);
17516
+ break;
17517
+ default:
17518
+ }
17519
+ } catch (error) {
17520
+ reporter?.finish(controller?.signal.aborted || sharedState?.snapshot.cancelled);
17521
+ const message = error instanceof Error ? error.message : "";
17522
+ await WorkerBody.postMessage("error", {
17523
+ error: message,
17524
+ errorName: error instanceof Error ? error.name : "Error"
17525
+ });
17526
+ } finally {
17527
+ if (controller && activeController === controller)
17528
+ activeController = null;
17529
+ }
17530
+ };
17531
+ await WorkerBody.postMessage("ready", {});
17532
+ }
17533
+ async function* createDemandDrivenIterator(inputBatches) {
17534
+ while (true) {
17535
+ await WorkerBody.postMessage("input-request", {});
17536
+ const nextBatch = await inputBatches.next();
17537
+ if (nextBatch.done) {
17538
+ return;
17539
+ }
17540
+ yield nextBatch.value;
17541
+ }
17542
+ }
17543
+ function processOnMainThread(arrayBuffer, options = {}, jobContext = {}) {
17544
+ const signal = activeController?.signal;
17545
+ signal?.throwIfAborted();
17546
+ return new Promise((resolve, reject) => {
17547
+ const id = requestId++;
17548
+ const cleanup = () => {
17549
+ signal?.removeEventListener("abort", abort);
17550
+ void WorkerBody.removeEventListener(onMessage);
17551
+ };
17552
+ const abort = () => {
17553
+ cleanup();
17554
+ reject(signal?.reason);
17555
+ };
17556
+ const onMessage = (type, payload) => {
17557
+ if (payload.id !== id)
17558
+ return;
17559
+ if (type === "done") {
17560
+ cleanup();
17561
+ resolve(payload.result);
17562
+ } else if (type === "error") {
17563
+ cleanup();
17564
+ reject(payload.error);
17565
+ }
17566
+ };
17567
+ void WorkerBody.addEventListener(onMessage).then(async () => {
17568
+ if (signal?.aborted) {
17569
+ abort();
17570
+ return;
17571
+ }
17572
+ signal?.addEventListener("abort", abort, { once: true });
17573
+ await WorkerBody.postMessage("process", {
17574
+ id,
17575
+ input: arrayBuffer,
17576
+ options,
17577
+ context: jobContext
17578
+ });
17579
+ }).catch((error) => {
17580
+ cleanup();
17581
+ reject(error);
17582
+ });
17583
+ });
17584
+ }
17585
+ function createProgressReporter() {
17586
+ let pending2;
17587
+ let finished = false;
17588
+ let scheduled = false;
17589
+ const flush = () => {
17590
+ scheduled = false;
17591
+ if (pending2) {
17592
+ WorkerBody.postMessage("progress", { progress: pending2 });
17593
+ pending2 = void 0;
17594
+ }
17595
+ };
17596
+ return {
17597
+ /** Records progress while retaining phase transitions. */
17598
+ report(progress) {
17599
+ if (finished)
17600
+ return;
17601
+ if (pending2 && pending2.phase !== progress.phase)
17602
+ flush();
17603
+ pending2 = { ...progress };
17604
+ if (!scheduled) {
17605
+ scheduled = true;
17606
+ setTimeout(flush, 0);
17607
+ }
17608
+ },
17609
+ /** Flushes final progress and suppresses reports from stale callbacks. */
17610
+ finish(discard = false) {
17611
+ if (discard)
17612
+ pending2 = void 0;
17613
+ flush();
17614
+ finished = true;
17615
+ }
17616
+ };
17617
+ }
17618
+
17619
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/index.js
17620
+ var import_meta = {};
17621
+ var path = typeof __filename === "string" ? __filename.replace(/\\/g, "/") : "";
17622
+ var moduleUrl = path ? `file://${path.startsWith("/") ? "" : "/"}${encodeURI(path).replace(/#/g, "%23").replace(/\?/g, "%3F")}` : import_meta.url;
17623
+
17624
+ // ../../node_modules/@math.gl/tasks/dist/tasks/task-preload.js
17625
+ var pending = /* @__PURE__ */ new WeakMap();
17626
+ var loaded = /* @__PURE__ */ new WeakSet();
17627
+ function preloadTaskCode(task, signal) {
17628
+ if (!task.preload)
17629
+ return Promise.resolve();
17630
+ let promise = pending.get(task);
17631
+ if (!promise) {
17632
+ promise = Promise.resolve().then(() => task.preload()).then(() => {
17633
+ loaded.add(task);
17634
+ });
17635
+ pending.set(task, promise);
17636
+ void promise.catch(() => pending.delete(task));
17637
+ }
17638
+ return withSignal(promise, signal);
17639
+ }
17640
+ function withSignal(operation, signal) {
17641
+ if (!signal)
17642
+ return operation;
17643
+ return new Promise((resolve, reject) => {
17644
+ const abort = () => {
17645
+ signal.removeEventListener("abort", abort);
17646
+ reject(signal.reason);
17647
+ };
17648
+ signal.addEventListener("abort", abort, { once: true });
17649
+ if (signal.aborted)
17650
+ abort();
17651
+ operation.then((value) => {
17652
+ signal.removeEventListener("abort", abort);
17653
+ resolve(value);
17654
+ }, (error) => {
17655
+ signal.removeEventListener("abort", abort);
17656
+ reject(error);
17657
+ });
17658
+ });
17659
+ }
17660
+
17661
+ // ../../node_modules/@math.gl/tasks/dist/tasks/task-channel.js
17662
+ var TaskRequestError = class extends Error {
17663
+ };
17664
+ var TaskChannel = class {
17665
+ constructor(options) {
17666
+ this.options = options;
17667
+ this.nextId = 1;
17668
+ this.pending = /* @__PURE__ */ new Map();
17669
+ this.incoming = /* @__PURE__ */ new Map();
17670
+ }
17671
+ /** Send a request without serializing other in-flight requests. */
17672
+ request(operation, value, signal, transfer = []) {
17673
+ if (this.failure)
17674
+ return Promise.reject(this.failure.reason);
17675
+ if (signal?.aborted)
17676
+ return Promise.reject(signal.reason);
17677
+ const id = this.nextId++;
17678
+ return new Promise((resolve, reject) => {
17679
+ const abort = () => {
17680
+ const pending2 = this.pending.get(id);
17681
+ if (!pending2)
17682
+ return;
17683
+ this.pending.delete(id);
17684
+ pending2.cleanup();
17685
+ reject(signal?.reason);
17686
+ this.send({ source: "math.gl/tasks", kind: "cancel", id });
17687
+ };
17688
+ this.pending.set(id, {
17689
+ resolve,
17690
+ reject,
17691
+ cleanup: () => signal?.removeEventListener("abort", abort)
17692
+ });
17693
+ signal?.addEventListener("abort", abort, { once: true });
17694
+ this.send({ source: "math.gl/tasks", kind: "request", id, operation, value }, transfer);
17695
+ });
17696
+ }
17697
+ /** Send a one-way notification. */
17698
+ emit(operation, value, transfer = []) {
17699
+ if (this.failure)
17700
+ throw this.failure.reason;
17701
+ this.send({ source: "math.gl/tasks", kind: "event", id: 0, operation, value }, transfer);
17702
+ }
17703
+ /** Dispatch a transport message; unrelated protocols are ignored. */
17704
+ receive(message) {
17705
+ if (this.failure || message?.source !== "math.gl/tasks")
17706
+ return;
17707
+ if (message.kind === "failure") {
17708
+ const reason = new Error(message.error?.message ?? "Task channel failed");
17709
+ this.close(reason);
17710
+ this.options.onFailure?.(reason);
17711
+ } else if (message.kind === "result" || message.kind === "error") {
17712
+ const pending2 = this.pending.get(message.id);
17713
+ if (!pending2)
17714
+ return;
17715
+ this.pending.delete(message.id);
17716
+ pending2.cleanup();
17717
+ if (message.kind === "result")
17718
+ pending2.resolve(message.value);
17719
+ else {
17720
+ const error = new TaskRequestError(message.error?.message ?? "Task request failed");
17721
+ error.name = message.error?.name ?? "Error";
17722
+ pending2.reject(error);
17723
+ }
17724
+ } else if (message.kind === "cancel") {
17725
+ this.incoming.get(message.id)?.abort(new DOMException("Task request cancelled", "AbortError"));
17726
+ } else if (message.kind === "event") {
17727
+ try {
17728
+ this.options.handleEvent?.(message.operation, message.value);
17729
+ } catch (error) {
17730
+ this.fail(error);
17731
+ }
17732
+ } else if (message.kind === "request") {
17733
+ if (this.incoming.has(message.id)) {
17734
+ this.fail(new Error("Duplicate task request identifier"));
17735
+ return;
17736
+ }
17737
+ const controller = new AbortController();
17738
+ this.incoming.set(message.id, controller);
17739
+ void Promise.resolve().then(() => {
17740
+ controller.signal.throwIfAborted();
17741
+ return this.options.handleRequest(message.operation, message.value, controller.signal);
17742
+ }).then((value) => {
17743
+ if (!controller.signal.aborted && !this.failure) {
17744
+ this.send({ source: "math.gl/tasks", kind: "result", id: message.id, value }, this.options.getResultTransferList?.(value, message.value));
17745
+ }
17746
+ }).catch((reason) => {
17747
+ if (!controller.signal.aborted && !this.failure) {
17748
+ this.send({
17749
+ source: "math.gl/tasks",
17750
+ kind: "error",
17751
+ id: message.id,
17752
+ error: {
17753
+ name: reason instanceof Error ? reason.name : "Error",
17754
+ message: reason instanceof Error ? reason.message : String(reason)
17755
+ }
17756
+ });
17757
+ }
17758
+ }).finally(() => this.incoming.delete(message.id));
17759
+ }
17760
+ }
17761
+ /** Reject all outstanding calls with a common cause and abort incoming callbacks. */
17762
+ close(reason = new Error("Task channel closed")) {
17763
+ if (this.failure)
17764
+ return;
17765
+ this.failure = { reason };
17766
+ for (const pending2 of this.pending.values()) {
17767
+ pending2.cleanup();
17768
+ pending2.reject(reason);
17769
+ }
17770
+ this.pending.clear();
17771
+ for (const controller of this.incoming.values())
17772
+ controller.abort(reason);
17773
+ this.incoming.clear();
17774
+ }
17775
+ send(message, transfer = []) {
17776
+ if (this.failure)
17777
+ return;
17778
+ try {
17779
+ this.options.send(message, transfer);
17780
+ } catch (error) {
17781
+ this.fail(error);
17782
+ }
17783
+ }
17784
+ /** Invalidate the channel and notify the peer when the transport still works. */
17785
+ fail(reason) {
17786
+ if (this.failure)
17787
+ return;
17788
+ this.close(reason);
17789
+ try {
17790
+ this.options.send({
17791
+ source: "math.gl/tasks",
17792
+ kind: "failure",
17793
+ id: 0,
17794
+ error: {
17795
+ name: reason instanceof Error ? reason.name : "Error",
17796
+ message: reason instanceof Error ? reason.message : String(reason)
17797
+ }
17798
+ }, []);
17799
+ } catch {
17800
+ }
17801
+ this.options.onFailure?.(reason);
17802
+ }
17803
+ };
17804
+
17805
+ // ../../node_modules/@math.gl/tasks/dist/tasks/task-runtime.js
17806
+ function assertPayload(value) {
17807
+ if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) {
17808
+ throw new TypeError("Task payloads must be plain objects with named fields");
17809
+ }
17810
+ }
17811
+ function clonePayload(value, ownership = "copy") {
17812
+ assertPayload(value);
17813
+ if (!["copy", "transfer", "share"].includes(ownership))
17814
+ throw new TypeError("Invalid input ownership");
17815
+ const transfer = getTransferList(value);
17816
+ if (ownership === "share" && transfer.length)
17817
+ throw new TypeError("Share requires shared storage");
17818
+ return structuredClone(value, {
17819
+ transfer: ownership === "transfer" ? transfer : []
17820
+ });
17821
+ }
17822
+ function taskContext(state, context = {}) {
17823
+ const signal = context.signal ?? new AbortController().signal;
17824
+ return {
17825
+ state,
17826
+ signal,
17827
+ requestHost: async (operation, payload, controls) => {
17828
+ signal.throwIfAborted();
17829
+ if (!context.requestHost)
17830
+ throw new Error("No host request handler configured");
17831
+ return context.requestHost(operation, payload, controls);
17832
+ },
17833
+ emitHost: (operation, payload) => {
17834
+ signal.throwIfAborted();
17835
+ context.emitHost?.(operation, payload);
17836
+ },
17837
+ throwIfAborted: () => {
17838
+ signal.throwIfAborted();
17839
+ context.throwIfAborted?.();
17840
+ },
17841
+ reportProgress: (progress) => context.reportProgress?.({
17842
+ ...progress,
17843
+ phase: progress.phase ?? "process",
17844
+ unit: progress.unit ?? "items"
17845
+ })
17846
+ };
17847
+ }
17848
+ var TaskRuntime = class {
17849
+ constructor(task) {
17850
+ this.task = task;
17851
+ this.initialized = false;
17852
+ }
17853
+ async initialize(input, context = {}) {
17854
+ if (this.initialized)
17855
+ throw new Error("Task is already initialized");
17856
+ assertPayload(input);
17857
+ await preloadTaskCode(this.task, context.signal);
17858
+ context.signal?.throwIfAborted();
17859
+ this.state = await this.task.initialize?.(input, taskContext(void 0, context));
17860
+ this.initialized = true;
17861
+ return {};
17862
+ }
17863
+ async destroy() {
17864
+ if (this.initialized) {
17865
+ this.initialized = false;
17866
+ const state = this.state;
17867
+ this.state = void 0;
17868
+ if (this.task.initialize)
17869
+ await this.task.destroy?.(state);
17870
+ }
17871
+ return {};
17872
+ }
17873
+ async process(input, options, context = {}) {
17874
+ if (!this.initialized)
17875
+ throw new Error("Task is not initialized");
17876
+ if (!this.task.process)
17877
+ throw new Error("Task has no atomic processor");
17878
+ assertPayload(input);
17879
+ const result = await this.task.process(input, options, taskContext(this.state, context));
17880
+ assertPayload(result);
17881
+ return result;
17882
+ }
17883
+ async *stream(inputs, options, context = {}) {
17884
+ if (!this.initialized)
17885
+ throw new Error("Task is not initialized");
17886
+ if (!this.task.processInBatches)
17887
+ throw new Error("Task has no streaming processor");
17888
+ for await (const output of this.task.processInBatches(inputs, options, taskContext(this.state, context))) {
17889
+ assertPayload(output);
17890
+ yield output;
17891
+ }
17892
+ }
17893
+ };
17894
+ async function initializeTaskWorker(task) {
17895
+ if (!await WorkerBody.inWorkerThread())
17896
+ throw new Error("initializeTaskWorker must run inside a worker");
17897
+ if (installed)
17898
+ throw new Error("A task is already installed in this worker");
17899
+ installed = true;
17900
+ const runtime = new TaskRuntime(task);
17901
+ let channelStream;
17902
+ const channel = new TaskChannel({
17903
+ getResultTransferList: (value, request) => request.outputOwnership === "transfer" ? getTransferList(value) : [],
17904
+ send: (message, transfer) => {
17905
+ const snapshot = structuredClone(message, { transfer });
17906
+ void WorkerBody.postMessage("task-channel", snapshot).catch((reason) => channel.fail(reason));
17907
+ },
17908
+ handleRequest: async (operation, value, signal) => {
17909
+ const request = value;
17910
+ const context = {
17911
+ signal,
17912
+ reportProgress: (progress) => channel.emit("task:progress", { id: request.progressId, progress }),
17913
+ requestHost: (operation2, payload, controls = {}) => {
17914
+ const request2 = {
17915
+ operation: operation2,
17916
+ payload: clonePayload(payload, controls.inputOwnership),
17917
+ outputOwnership: controls.outputOwnership ?? "copy"
17918
+ };
17919
+ return channel.request("task:host-request", request2, signal, getTransferList(request2));
17920
+ },
17921
+ emitHost: (operation2, payload) => channel.emit("task:host-event", { operation: operation2, payload, id: request.progressId })
17922
+ };
17923
+ switch (operation) {
17924
+ case "initialize":
17925
+ return runtime.initialize(request.input, context);
17926
+ case "process":
17927
+ return runtime.process(request.input, request.options, context);
17928
+ case "stream-open": {
17929
+ if (channelStream)
17930
+ throw new Error("A task stream is already open");
17931
+ async function* inputs() {
17932
+ while (true) {
17933
+ const result = await channel.request("task:next-input", { outputOwnership: "transfer" }, signal);
17934
+ if (result.done)
17935
+ return;
17936
+ yield result.value;
17937
+ }
17938
+ }
17939
+ channelStream = runtime.stream(inputs(), request.options, context)[Symbol.asyncIterator]();
17940
+ return {};
17941
+ }
17942
+ case "stream-next":
17943
+ if (!channelStream)
17944
+ throw new Error("No active task stream");
17945
+ return channelStream.next();
17946
+ case "stream-close":
17947
+ try {
17948
+ await channelStream?.return?.();
17949
+ } finally {
17950
+ channelStream = void 0;
17951
+ }
17952
+ return {};
17953
+ case "destroy":
17954
+ return runtime.destroy();
17955
+ default:
17956
+ throw new Error("Unknown task channel operation");
17957
+ }
17958
+ }
17959
+ });
17960
+ await WorkerBody.addEventListener((type, payload) => {
17961
+ if (type === "task-channel")
17962
+ channel.receive(payload);
17963
+ });
17964
+ let streamOptions = {};
17965
+ return createWorker(async (request, _options, context) => {
17966
+ switch (request.operation) {
17967
+ case "initialize":
17968
+ return runtime.initialize(request.input, context);
17969
+ case "destroy":
17970
+ return runtime.destroy();
17971
+ case "stream-options":
17972
+ streamOptions = request.options;
17973
+ return {};
17974
+ case "process":
17975
+ return runtime.process(request.input, request.options, context);
17976
+ default:
17977
+ throw new Error("Unknown task operation");
17978
+ }
17979
+ }, async function* (inputs, _options, context) {
17980
+ async function* batches() {
17981
+ for await (const input of inputs) {
17982
+ assertPayload(input);
17983
+ yield input;
17984
+ }
17985
+ }
17986
+ try {
17987
+ yield* runtime.stream(batches(), streamOptions, context);
17988
+ } finally {
17989
+ streamOptions = {};
17990
+ }
17991
+ }, () => preloadTaskCode(task));
17992
+ }
17993
+ var installed = false;
17994
+
17995
+ // ../core/src/worker-utils/lib/worker-api/task-runtime.ts
17996
+ function normalizeTaskProgress(progress) {
17997
+ return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
17998
+ }
17999
+ async function isWorkerThread() {
18000
+ if (typeof self !== "undefined" && typeof document === "undefined" && typeof self.postMessage === "function")
18001
+ return true;
18002
+ if (typeof process !== "undefined" && process.versions?.node) {
18003
+ const { isMainThread } = await Promise.resolve().then(() => (init_worker_threads_browser(), worker_threads_browser_exports));
18004
+ return !isMainThread;
18005
+ }
18006
+ return false;
18007
+ }
18008
+ var initializeTaskWorker2 = initializeTaskWorker;
18009
+
18010
+ // ../core/src/worker-utils/lib/worker-utils/get-transfer-list.ts
18011
+ function getTransferList2(object, recursive = true, transfers) {
18012
+ const transfersSet = transfers || /* @__PURE__ */ new Set();
18013
+ if (!object) {
18014
+ } else if (isTransferable2(object)) {
18015
+ transfersSet.add(object);
18016
+ } else if (isTransferable2(object.buffer)) {
18017
+ transfersSet.add(object.buffer);
18018
+ } else if (ArrayBuffer.isView(object)) {
18019
+ } else if (recursive && typeof object === "object") {
18020
+ for (const key in object) {
18021
+ getTransferList2(object[key], recursive, transfersSet);
18022
+ }
18023
+ }
18024
+ return transfers === void 0 ? Array.from(transfersSet) : [];
18025
+ }
18026
+ function isTransferable2(object) {
18027
+ if (!object) {
18028
+ return false;
18029
+ }
18030
+ if (object instanceof ArrayBuffer) {
18031
+ return true;
18032
+ }
18033
+ if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
18034
+ return true;
18035
+ }
18036
+ if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
18037
+ return true;
18038
+ }
18039
+ if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
18040
+ return true;
18041
+ }
18042
+ return false;
18043
+ }
18044
+
18045
+ // ../core/src/worker-utils/lib/worker-api/create-worker.ts
18046
+ async function createWorker2(process2, processInBatches) {
18047
+ if (!await isWorkerThread()) return;
18048
+ await initializeTaskWorker2(createWorkerTask(process2, processInBatches));
18049
+ }
18050
+ function createWorkerTask(process2, processInBatches) {
18051
+ return {
18052
+ id: "loaders.gl",
18053
+ initialize: (state) => state,
18054
+ destroy: (state) => state.port?.close(),
18055
+ process: async ({ value }, options, context) => {
18056
+ if (!process2) throw new Error("Worker does not support atomic processing");
18057
+ return { value: await process2(value, options, createContext(context), context.state.context) };
18058
+ },
18059
+ ...processInBatches ? {
18060
+ processInBatches: async function* (inputs, options, context) {
18061
+ async function* values() {
18062
+ for await (const input of inputs) yield input.value;
18063
+ }
18064
+ for await (const value of processInBatches(
18065
+ values(),
18066
+ options,
18067
+ createContext(context),
18068
+ context.state.context
18069
+ )) {
18070
+ yield { value };
18071
+ }
18072
+ }
18073
+ } : {}
18074
+ };
18075
+ }
18076
+ function createContext(context) {
18077
+ let requestIdentifier = 0;
18078
+ const port = context.state.port;
18079
+ return {
18080
+ signal: context.signal,
18081
+ throwIfAborted: () => context.throwIfAborted(),
18082
+ reportProgress: (progress) => context.reportProgress(normalizeTaskProgress(progress)),
18083
+ process: port ? (input, options = {}, jobContext = {}) => {
18084
+ context.throwIfAborted();
18085
+ const identifier = ++requestIdentifier;
18086
+ return new Promise((resolve, reject) => {
18087
+ const onMessage = (event) => {
18088
+ if (event.data.identifier !== identifier) return;
18089
+ cleanup();
18090
+ if (event.data.error) {
18091
+ const error = new Error(event.data.error.message);
18092
+ error.name = event.data.error.name;
18093
+ reject(error);
18094
+ } else resolve(event.data.value);
18095
+ };
18096
+ const onAbort = () => {
18097
+ cleanup();
18098
+ reject(context.signal.reason);
18099
+ };
18100
+ const cleanup = () => {
18101
+ port.removeEventListener("message", onMessage);
18102
+ context.signal.removeEventListener("abort", onAbort);
18103
+ };
18104
+ port.addEventListener("message", onMessage);
18105
+ context.signal.addEventListener("abort", onAbort, { once: true });
18106
+ port.start();
18107
+ try {
18108
+ const request = { identifier, input, options, context: jobContext };
18109
+ port.postMessage(request, getTransferList2(request));
18110
+ } catch (error) {
18111
+ cleanup();
18112
+ reject(error);
18113
+ }
18114
+ });
18115
+ } : void 0
18116
+ };
18117
+ }
18118
+
18119
+ // ../core/src/loader-utils/lib/worker-loader-utils/create-loader-worker.ts
18120
+ async function createLoaderWorker(loader, selectLoader = () => loader) {
18121
+ await createWorker2(
18122
+ (input, options, workerContext, loaderContext) => processLoaderWorkerData(
18123
+ selectLoader(options || {}),
18124
+ input,
18125
+ options,
18126
+ workerContext,
18127
+ loaderContext
18128
+ ),
18129
+ (inputIterator, options, workerContext, loaderContext) => processLoaderWorkerBatches(
18130
+ selectLoader(options || {}),
18131
+ inputIterator,
18132
+ options,
18133
+ workerContext,
18134
+ loaderContext
18135
+ )
18136
+ );
18137
+ }
18138
+ async function processLoaderWorkerData(loader, input, options = {}, workerContext, loaderContext = {}) {
18139
+ const result = await parseData({
18140
+ loader,
18141
+ arrayBuffer: input,
18142
+ options,
18143
+ context: {
18144
+ ...loaderContext,
18145
+ reportProgress: workerContext?.reportProgress,
18146
+ coreApi: createWorkerCoreApi(),
18147
+ _parse: createParseOnMainThread(workerContext?.process)
18148
+ }
18149
+ });
18150
+ return loader.serializeWorkerResult ? loader.serializeWorkerResult(result, options, loaderContext) : result;
18151
+ }
18152
+ async function* processLoaderWorkerBatches(loader, inputIterator, options = {}, workerContext, loaderContext = {}) {
18153
+ if (!loader.parseInBatches) {
18154
+ throw new Error(`${loader.id} loader does not support batched parsing`);
18155
+ }
18156
+ const parserOptions = getWorkerLoaderOptions(loader, options);
18157
+ const resultIterator = loader.parseInBatches(inputIterator, parserOptions, {
18158
+ ...loaderContext,
18159
+ reportProgress: workerContext?.reportProgress,
18160
+ coreApi: createWorkerCoreApi(),
18161
+ _parse: createParseOnMainThread(workerContext?.process)
18162
+ });
18163
+ for await (const batch of resultIterator) {
18164
+ yield loader.serializeWorkerBatch ? loader.serializeWorkerBatch(batch, options, loaderContext) : batch;
18165
+ }
18166
+ }
18167
+ function createWorkerCoreApi() {
18168
+ const unavailable = (methodName) => () => {
18169
+ throw new Error(`context.coreApi.${methodName} is unavailable inside worker loaders.`);
18170
+ };
18171
+ return {
18172
+ fetchFile: async (urlOrData, fetchOptions) => await fetch(urlOrData, fetchOptions),
18173
+ parseSync: unavailable("parseSync"),
18174
+ parse: unavailable("parse"),
18175
+ parseFile: unavailable("parseFile"),
18176
+ parseInBatches: unavailable("parseInBatches"),
18177
+ load: unavailable("load"),
18178
+ loadInBatches: unavailable("loadInBatches")
18179
+ };
18180
+ }
18181
+ function createParseOnMainThread(processOnMainThread2) {
18182
+ return (arrayBuffer, loaders, options, context) => {
18183
+ if (!processOnMainThread2) {
18184
+ throw new Error("Worker not set up to parse on main thread");
18185
+ }
18186
+ const parseArguments = getMainThreadParseArguments(loaders, options, context);
18187
+ return processOnMainThread2(arrayBuffer, parseArguments.options, {
18188
+ ...parseArguments.context,
18189
+ ...Array.isArray(loaders) || loaders && isLoaderObject(loaders) ? {
18190
+ _loaderIsArray: Array.isArray(loaders),
18191
+ _loaderIds: (Array.isArray(loaders) ? loaders : [loaders]).map((loader) => loader.id)
18192
+ } : {}
18193
+ });
18194
+ };
18195
+ }
18196
+ function getMainThreadParseArguments(loaders, options, context) {
18197
+ if (options) {
18198
+ return { options, context: getSerializableLoaderContext(context) };
18199
+ }
18200
+ if (Array.isArray(loaders) || loaders && isLoaderObject(loaders)) {
18201
+ return { options: void 0, context: getSerializableLoaderContext(context) };
18202
+ }
18203
+ if (loaders && !Array.isArray(loaders)) {
18204
+ return { options: loaders };
18205
+ }
18206
+ return { options: void 0, context: getSerializableLoaderContext(context) };
18207
+ }
18208
+ function isLoaderObject(value) {
18209
+ return "id" in value && "extensions" in value;
18210
+ }
18211
+ function getSerializableLoaderContext(context) {
18212
+ if (!context) {
18213
+ return void 0;
18214
+ }
18215
+ const {
18216
+ fetch: fetch2,
18217
+ loaders,
18218
+ coreApi,
18219
+ signal,
18220
+ reportProgress,
18221
+ _parse,
18222
+ _parseSync,
18223
+ _parseInBatches,
18224
+ ...serializableContext
18225
+ } = context;
18226
+ return JSON.parse(JSON.stringify(serializableContext));
18227
+ }
18228
+ async function parseData({
18229
+ loader,
18230
+ arrayBuffer,
18231
+ options,
18232
+ context
18233
+ }) {
18234
+ let data;
18235
+ let parser;
18236
+ if (loader.parse || loader.parseSync) {
18237
+ data = arrayBuffer;
18238
+ parser = loader.parse || loader.parseSync;
18239
+ } else if (loader.parseTextSync) {
18240
+ const textDecoder = new TextDecoder();
18241
+ data = textDecoder.decode(arrayBuffer);
18242
+ parser = loader.parseTextSync;
18243
+ } else {
18244
+ throw new Error(`Could not load data with ${loader.name} loader`);
18245
+ }
18246
+ options = getWorkerLoaderOptions(loader, options);
18247
+ return await parser(data, { ...options }, context, loader);
18248
+ }
18249
+ function getWorkerLoaderOptions(loader, options) {
18250
+ return {
18251
+ ...options,
18252
+ modules: { ...loader.options?.modules, ...options.modules },
18253
+ core: { ...options.core, worker: false }
18254
+ };
18255
+ }
18256
+
17420
18257
  // src/terrain/workers/quantized-mesh-worker.ts
17421
- init_loader_utils();
17422
- init_quantized_mesh_loader();
18258
+ init_quantized_mesh_loader2();
17423
18259
  createLoaderWorker(QuantizedMeshLoaderWithParser);
17424
18260
  })();