@loaders.gl/arrow 4.0.2 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/dist/arrow-loader.d.ts +6 -3
  2. package/dist/arrow-loader.d.ts.map +1 -1
  3. package/dist/arrow-loader.js +9 -1
  4. package/dist/arrow-loader.js.map +1 -1
  5. package/dist/arrow-worker.js +37 -537
  6. package/dist/arrow-writer.d.ts +2 -2
  7. package/dist/arrow-writer.d.ts.map +1 -1
  8. package/dist/arrow-writer.js.map +1 -1
  9. package/dist/dist.dev.js +1615 -246
  10. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts +31 -1
  11. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts.map +1 -1
  12. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js +133 -23
  13. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js.map +1 -1
  14. package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts +2 -1
  15. package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts.map +1 -1
  16. package/dist/geoarrow/convert-geoarrow-to-geojson.js +4 -0
  17. package/dist/geoarrow/convert-geoarrow-to-geojson.js.map +1 -1
  18. package/dist/geoarrow-loader.d.ts +19 -0
  19. package/dist/geoarrow-loader.d.ts.map +1 -0
  20. package/dist/geoarrow-loader.js +24 -0
  21. package/dist/geoarrow-loader.js.map +1 -0
  22. package/dist/geoarrow-writer.d.ts +9 -0
  23. package/dist/geoarrow-writer.d.ts.map +1 -0
  24. package/dist/geoarrow-writer.js +19 -0
  25. package/dist/geoarrow-writer.js.map +1 -0
  26. package/dist/index.cjs +508 -284
  27. package/dist/index.d.ts +9 -12
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +7 -13
  30. package/dist/index.js.map +1 -1
  31. package/dist/lib/arrow-table-batch.d.ts.map +1 -1
  32. package/dist/lib/arrow-table-batch.js.map +1 -1
  33. package/dist/lib/encode-arrow.d.ts.map +1 -1
  34. package/dist/lib/encode-arrow.js.map +1 -1
  35. package/dist/lib/encode-geoarrow.d.ts +15 -0
  36. package/dist/lib/encode-geoarrow.d.ts.map +1 -0
  37. package/dist/lib/encode-geoarrow.js +22 -0
  38. package/dist/lib/encode-geoarrow.js.map +1 -0
  39. package/dist/{lib → parsers}/parse-arrow-in-batches.d.ts +1 -1
  40. package/dist/parsers/parse-arrow-in-batches.d.ts.map +1 -0
  41. package/dist/parsers/parse-arrow-in-batches.js.map +1 -0
  42. package/dist/parsers/parse-arrow-sync.d.ts +6 -0
  43. package/dist/parsers/parse-arrow-sync.d.ts.map +1 -0
  44. package/dist/parsers/parse-arrow-sync.js +26 -0
  45. package/dist/parsers/parse-arrow-sync.js.map +1 -0
  46. package/dist/parsers/parse-geoarrow-in-batches.d.ts +6 -0
  47. package/dist/parsers/parse-geoarrow-in-batches.d.ts.map +1 -0
  48. package/dist/parsers/parse-geoarrow-in-batches.js +5 -0
  49. package/dist/parsers/parse-geoarrow-in-batches.js.map +1 -0
  50. package/dist/parsers/parse-geoarrow-sync.d.ts +6 -0
  51. package/dist/parsers/parse-geoarrow-sync.d.ts.map +1 -0
  52. package/dist/parsers/parse-geoarrow-sync.js +14 -0
  53. package/dist/parsers/parse-geoarrow-sync.js.map +1 -0
  54. package/dist/schema/convert-arrow-schema.d.ts.map +1 -1
  55. package/dist/schema/convert-arrow-schema.js +32 -5
  56. package/dist/schema/convert-arrow-schema.js.map +1 -1
  57. package/dist/tables/convert-arrow-to-columnar-table.d.ts +8 -0
  58. package/dist/tables/convert-arrow-to-columnar-table.d.ts.map +1 -0
  59. package/dist/tables/convert-arrow-to-columnar-table.js +14 -0
  60. package/dist/tables/convert-arrow-to-columnar-table.js.map +1 -0
  61. package/dist/tables/convert-arrow-to-geojson-table.d.ts +16 -0
  62. package/dist/tables/convert-arrow-to-geojson-table.d.ts.map +1 -0
  63. package/dist/tables/convert-arrow-to-geojson-table.js +33 -0
  64. package/dist/tables/convert-arrow-to-geojson-table.js.map +1 -0
  65. package/dist/tables/convert-columnar-to-row-table.d.ts +7 -0
  66. package/dist/tables/convert-columnar-to-row-table.d.ts.map +1 -0
  67. package/dist/tables/convert-columnar-to-row-table.js +18 -0
  68. package/dist/tables/convert-columnar-to-row-table.js.map +1 -0
  69. package/dist/triangulate-on-worker.d.ts +36 -0
  70. package/dist/triangulate-on-worker.d.ts.map +1 -0
  71. package/dist/triangulate-on-worker.js +14 -0
  72. package/dist/triangulate-on-worker.js.map +1 -0
  73. package/dist/triangulation-worker.js +880 -0
  74. package/dist/workers/arrow-worker.js +1 -1
  75. package/dist/workers/arrow-worker.js.map +1 -1
  76. package/dist/workers/triangulation-worker-node.d.ts +2 -0
  77. package/dist/workers/triangulation-worker-node.d.ts.map +1 -0
  78. package/dist/workers/triangulation-worker-node.js +2 -0
  79. package/dist/workers/triangulation-worker-node.js.map +1 -0
  80. package/dist/workers/triangulation-worker.d.ts +2 -0
  81. package/dist/workers/triangulation-worker.d.ts.map +1 -0
  82. package/dist/workers/triangulation-worker.js +24 -0
  83. package/dist/workers/triangulation-worker.js.map +1 -0
  84. package/package.json +9 -7
  85. package/src/arrow-loader.ts +25 -3
  86. package/src/arrow-writer.ts +2 -2
  87. package/src/geoarrow/convert-geoarrow-to-binary-geometry.ts +221 -30
  88. package/src/geoarrow/convert-geoarrow-to-geojson.ts +6 -2
  89. package/src/geoarrow-loader.ts +55 -0
  90. package/src/geoarrow-writer.ts +41 -0
  91. package/src/index.ts +30 -36
  92. package/src/lib/arrow-table-batch.ts +3 -0
  93. package/src/lib/encode-arrow.ts +3 -0
  94. package/src/lib/encode-geoarrow.ts +45 -0
  95. package/src/{lib → parsers}/parse-arrow-in-batches.ts +4 -2
  96. package/src/parsers/parse-arrow-sync.ts +38 -0
  97. package/src/parsers/parse-geoarrow-in-batches.ts +15 -0
  98. package/src/parsers/parse-geoarrow-sync.ts +22 -0
  99. package/src/schema/convert-arrow-schema.ts +32 -7
  100. package/src/tables/convert-arrow-to-columnar-table.ts +29 -0
  101. package/src/tables/convert-arrow-to-geojson-table.ts +54 -0
  102. package/src/tables/convert-columnar-to-row-table.ts +29 -0
  103. package/src/triangulate-on-worker.ts +47 -0
  104. package/src/workers/arrow-worker.ts +1 -1
  105. package/src/workers/triangulation-worker-node.ts +4 -0
  106. package/src/workers/triangulation-worker.ts +39 -0
  107. package/dist/lib/parse-arrow-in-batches.d.ts.map +0 -1
  108. package/dist/lib/parse-arrow-in-batches.js.map +0 -1
  109. package/dist/lib/parse-arrow-sync.d.ts +0 -5
  110. package/dist/lib/parse-arrow-sync.d.ts.map +0 -1
  111. package/dist/lib/parse-arrow-sync.js +0 -21
  112. package/dist/lib/parse-arrow-sync.js.map +0 -1
  113. package/dist/tables/convert-arrow-to-table.d.ts +0 -21
  114. package/dist/tables/convert-arrow-to-table.d.ts.map +0 -1
  115. package/dist/tables/convert-arrow-to-table.js +0 -37
  116. package/dist/tables/convert-arrow-to-table.js.map +0 -1
  117. package/src/lib/parse-arrow-sync.ts +0 -35
  118. package/src/tables/convert-arrow-to-table.ts +0 -68
  119. /package/dist/{lib → parsers}/parse-arrow-in-batches.js +0 -0
@@ -0,0 +1,880 @@
1
+ "use strict";
2
+ (() => {
3
+ // ../worker-utils/src/lib/node/worker_threads-browser.ts
4
+ var parentPort = null;
5
+
6
+ // ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
7
+ function getTransferList(object, recursive = true, transfers) {
8
+ const transfersSet = transfers || /* @__PURE__ */ new Set();
9
+ if (!object) {
10
+ } else if (isTransferable(object)) {
11
+ transfersSet.add(object);
12
+ } else if (isTransferable(object.buffer)) {
13
+ transfersSet.add(object.buffer);
14
+ } else if (ArrayBuffer.isView(object)) {
15
+ } else if (recursive && typeof object === "object") {
16
+ for (const key in object) {
17
+ getTransferList(object[key], recursive, transfersSet);
18
+ }
19
+ }
20
+ return transfers === void 0 ? Array.from(transfersSet) : [];
21
+ }
22
+ function isTransferable(object) {
23
+ if (!object) {
24
+ return false;
25
+ }
26
+ if (object instanceof ArrayBuffer) {
27
+ return true;
28
+ }
29
+ if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
30
+ return true;
31
+ }
32
+ if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
33
+ return true;
34
+ }
35
+ if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
36
+ return true;
37
+ }
38
+ return false;
39
+ }
40
+
41
+ // ../worker-utils/src/lib/worker-farm/worker-body.ts
42
+ async function getParentPort() {
43
+ return parentPort;
44
+ }
45
+ var onMessageWrapperMap = /* @__PURE__ */ new Map();
46
+ var WorkerBody = class {
47
+ /** Check that we are actually in a worker thread */
48
+ static async inWorkerThread() {
49
+ return typeof self !== "undefined" || Boolean(await getParentPort());
50
+ }
51
+ /*
52
+ * (type: WorkerMessageType, payload: WorkerMessagePayload) => any
53
+ */
54
+ static set onmessage(onMessage) {
55
+ async function handleMessage(message) {
56
+ const parentPort2 = await getParentPort();
57
+ const { type, payload } = parentPort2 ? message : message.data;
58
+ onMessage(type, payload);
59
+ }
60
+ getParentPort().then((parentPort2) => {
61
+ if (parentPort2) {
62
+ parentPort2.on("message", handleMessage);
63
+ parentPort2.on("exit", () => console.debug("Node worker closing"));
64
+ } else {
65
+ globalThis.onmessage = handleMessage;
66
+ }
67
+ });
68
+ }
69
+ static async addEventListener(onMessage) {
70
+ let onMessageWrapper = onMessageWrapperMap.get(onMessage);
71
+ if (!onMessageWrapper) {
72
+ onMessageWrapper = async (message) => {
73
+ if (!isKnownMessage(message)) {
74
+ return;
75
+ }
76
+ const parentPort3 = await getParentPort();
77
+ const { type, payload } = parentPort3 ? message : message.data;
78
+ onMessage(type, payload);
79
+ };
80
+ }
81
+ const parentPort2 = await getParentPort();
82
+ if (parentPort2) {
83
+ console.error("not implemented");
84
+ } else {
85
+ globalThis.addEventListener("message", onMessageWrapper);
86
+ }
87
+ }
88
+ static async removeEventListener(onMessage) {
89
+ const onMessageWrapper = onMessageWrapperMap.get(onMessage);
90
+ onMessageWrapperMap.delete(onMessage);
91
+ const parentPort2 = await getParentPort();
92
+ if (parentPort2) {
93
+ console.error("not implemented");
94
+ } else {
95
+ globalThis.removeEventListener("message", onMessageWrapper);
96
+ }
97
+ }
98
+ /**
99
+ * Send a message from a worker to creating thread (main thread)
100
+ * @param type
101
+ * @param payload
102
+ */
103
+ static async postMessage(type, payload) {
104
+ const data = { source: "loaders.gl", type, payload };
105
+ const transferList = getTransferList(payload);
106
+ const parentPort2 = await getParentPort();
107
+ if (parentPort2) {
108
+ parentPort2.postMessage(data, transferList);
109
+ } else {
110
+ globalThis.postMessage(data, transferList);
111
+ }
112
+ }
113
+ };
114
+ function isKnownMessage(message) {
115
+ const { type, data } = message;
116
+ return type === "message" && data && typeof data.source === "string" && data.source.startsWith("loaders.gl");
117
+ }
118
+
119
+ // ../worker-utils/src/lib/async-queue/async-queue.ts
120
+ var AsyncQueue = class {
121
+ constructor() {
122
+ this._values = [];
123
+ this._settlers = [];
124
+ this._closed = false;
125
+ }
126
+ /** Return an async iterator for this queue */
127
+ [Symbol.asyncIterator]() {
128
+ return this;
129
+ }
130
+ /** Push a new value - the async iterator will yield a promise resolved to this value */
131
+ push(value) {
132
+ return this.enqueue(value);
133
+ }
134
+ /**
135
+ * Push a new value - the async iterator will yield a promise resolved to this value
136
+ * Add an error - the async iterator will yield a promise rejected with this value
137
+ */
138
+ enqueue(value) {
139
+ if (this._closed) {
140
+ throw new Error("Closed");
141
+ }
142
+ if (this._settlers.length > 0) {
143
+ if (this._values.length > 0) {
144
+ throw new Error("Illegal internal state");
145
+ }
146
+ const settler = this._settlers.shift();
147
+ if (value instanceof Error) {
148
+ settler.reject(value);
149
+ } else {
150
+ settler.resolve({ value });
151
+ }
152
+ } else {
153
+ this._values.push(value);
154
+ }
155
+ }
156
+ /** Indicate that we not waiting for more values - The async iterator will be done */
157
+ close() {
158
+ while (this._settlers.length > 0) {
159
+ const settler = this._settlers.shift();
160
+ settler.resolve({ done: true });
161
+ }
162
+ this._closed = true;
163
+ }
164
+ // ITERATOR IMPLEMENTATION
165
+ /** @returns a Promise for an IteratorResult */
166
+ next() {
167
+ if (this._values.length > 0) {
168
+ const value = this._values.shift();
169
+ if (value instanceof Error) {
170
+ return Promise.reject(value);
171
+ }
172
+ return Promise.resolve({ done: false, value });
173
+ }
174
+ if (this._closed) {
175
+ if (this._settlers.length > 0) {
176
+ throw new Error("Illegal internal state");
177
+ }
178
+ return Promise.resolve({ done: true, value: void 0 });
179
+ }
180
+ return new Promise((resolve, reject) => {
181
+ this._settlers.push({ resolve, reject });
182
+ });
183
+ }
184
+ };
185
+
186
+ // ../worker-utils/src/lib/worker-api/create-worker.ts
187
+ var requestId = 0;
188
+ var inputBatches;
189
+ var options;
190
+ async function createWorker(process, processInBatches) {
191
+ if (!await WorkerBody.inWorkerThread()) {
192
+ return;
193
+ }
194
+ const context = {
195
+ process: processOnMainThread
196
+ };
197
+ WorkerBody.onmessage = async (type, payload) => {
198
+ try {
199
+ switch (type) {
200
+ case "process":
201
+ if (!process) {
202
+ throw new Error("Worker does not support atomic processing");
203
+ }
204
+ const result = await process(payload.input, payload.options || {}, context);
205
+ WorkerBody.postMessage("done", { result });
206
+ break;
207
+ case "process-in-batches":
208
+ if (!processInBatches) {
209
+ throw new Error("Worker does not support batched processing");
210
+ }
211
+ inputBatches = new AsyncQueue();
212
+ options = payload.options || {};
213
+ const resultIterator = processInBatches(inputBatches, options, context);
214
+ for await (const batch of resultIterator) {
215
+ WorkerBody.postMessage("output-batch", { result: batch });
216
+ }
217
+ WorkerBody.postMessage("done", {});
218
+ break;
219
+ case "input-batch":
220
+ inputBatches.push(payload.input);
221
+ break;
222
+ case "input-done":
223
+ inputBatches.close();
224
+ break;
225
+ default:
226
+ }
227
+ } catch (error) {
228
+ const message = error instanceof Error ? error.message : "";
229
+ WorkerBody.postMessage("error", { error: message });
230
+ }
231
+ };
232
+ }
233
+ function processOnMainThread(arrayBuffer, options2 = {}) {
234
+ return new Promise((resolve, reject) => {
235
+ const id = requestId++;
236
+ const onMessage = (type, payload2) => {
237
+ if (payload2.id !== id) {
238
+ return;
239
+ }
240
+ switch (type) {
241
+ case "done":
242
+ WorkerBody.removeEventListener(onMessage);
243
+ resolve(payload2.result);
244
+ break;
245
+ case "error":
246
+ WorkerBody.removeEventListener(onMessage);
247
+ reject(payload2.error);
248
+ break;
249
+ default:
250
+ }
251
+ };
252
+ WorkerBody.addEventListener(onMessage);
253
+ const payload = { id, input: arrayBuffer, options: options2 };
254
+ WorkerBody.postMessage("process", payload);
255
+ });
256
+ }
257
+
258
+ // ../../node_modules/@babel/runtime/helpers/esm/typeof.js
259
+ function _typeof(obj) {
260
+ "@babel/helpers - typeof";
261
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
262
+ return typeof obj2;
263
+ } : function(obj2) {
264
+ return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
265
+ }, _typeof(obj);
266
+ }
267
+
268
+ // ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
269
+ function _toPrimitive(input, hint) {
270
+ if (_typeof(input) !== "object" || input === null)
271
+ return input;
272
+ var prim = input[Symbol.toPrimitive];
273
+ if (prim !== void 0) {
274
+ var res = prim.call(input, hint || "default");
275
+ if (_typeof(res) !== "object")
276
+ return res;
277
+ throw new TypeError("@@toPrimitive must return a primitive value.");
278
+ }
279
+ return (hint === "string" ? String : Number)(input);
280
+ }
281
+
282
+ // ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
283
+ function _toPropertyKey(arg) {
284
+ var key = _toPrimitive(arg, "string");
285
+ return _typeof(key) === "symbol" ? key : String(key);
286
+ }
287
+
288
+ // ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
289
+ function _defineProperty(obj, key, value) {
290
+ key = _toPropertyKey(key);
291
+ if (key in obj) {
292
+ Object.defineProperty(obj, key, {
293
+ value,
294
+ enumerable: true,
295
+ configurable: true,
296
+ writable: true
297
+ });
298
+ } else {
299
+ obj[key] = value;
300
+ }
301
+ return obj;
302
+ }
303
+
304
+ // ../../node_modules/@math.gl/polygon/dist/polygon-utils.js
305
+ var DimIndex = {
306
+ x: 0,
307
+ y: 1,
308
+ z: 2
309
+ };
310
+ function getPolygonSignedArea(points, options2 = {}) {
311
+ const {
312
+ start = 0,
313
+ end = points.length,
314
+ plane = "xy"
315
+ } = options2;
316
+ const dim = options2.size || 2;
317
+ let area2 = 0;
318
+ const i0 = DimIndex[plane[0]];
319
+ const i1 = DimIndex[plane[1]];
320
+ for (let i = start, j = end - dim; i < end; i += dim) {
321
+ area2 += (points[i + i0] - points[j + i0]) * (points[i + i1] + points[j + i1]);
322
+ j = i;
323
+ }
324
+ return area2 / 2;
325
+ }
326
+
327
+ // ../../node_modules/@math.gl/polygon/dist/earcut.js
328
+ function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
329
+ const hasHoles = holeIndices && holeIndices.length;
330
+ const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
331
+ let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0], plane);
332
+ const triangles = [];
333
+ if (!outerNode || outerNode.next === outerNode.prev)
334
+ return triangles;
335
+ let invSize;
336
+ let maxX;
337
+ let maxY;
338
+ let minX;
339
+ let minY;
340
+ let x;
341
+ let y;
342
+ if (hasHoles)
343
+ outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
344
+ if (positions.length > 80 * dim) {
345
+ minX = maxX = positions[0];
346
+ minY = maxY = positions[1];
347
+ for (let i = dim; i < outerLen; i += dim) {
348
+ x = positions[i];
349
+ y = positions[i + 1];
350
+ if (x < minX)
351
+ minX = x;
352
+ if (y < minY)
353
+ minY = y;
354
+ if (x > maxX)
355
+ maxX = x;
356
+ if (y > maxY)
357
+ maxY = y;
358
+ }
359
+ invSize = Math.max(maxX - minX, maxY - minY);
360
+ invSize = invSize !== 0 ? 32767 / invSize : 0;
361
+ }
362
+ earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);
363
+ return triangles;
364
+ }
365
+ function linkedList(data, start, end, dim, clockwise, area2, plane) {
366
+ let i;
367
+ let last;
368
+ if (area2 === void 0) {
369
+ area2 = getPolygonSignedArea(data, {
370
+ start,
371
+ end,
372
+ size: dim,
373
+ plane
374
+ });
375
+ }
376
+ let i0 = DimIndex[plane[0]];
377
+ let i1 = DimIndex[plane[1]];
378
+ if (clockwise === area2 < 0) {
379
+ for (i = start; i < end; i += dim)
380
+ last = insertNode(i, data[i + i0], data[i + i1], last);
381
+ } else {
382
+ for (i = end - dim; i >= start; i -= dim)
383
+ last = insertNode(i, data[i + i0], data[i + i1], last);
384
+ }
385
+ if (last && equals(last, last.next)) {
386
+ removeNode(last);
387
+ last = last.next;
388
+ }
389
+ return last;
390
+ }
391
+ function filterPoints(start, end) {
392
+ if (!start)
393
+ return start;
394
+ if (!end)
395
+ end = start;
396
+ let p = start;
397
+ let again;
398
+ do {
399
+ again = false;
400
+ if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
401
+ removeNode(p);
402
+ p = end = p.prev;
403
+ if (p === p.next)
404
+ break;
405
+ again = true;
406
+ } else {
407
+ p = p.next;
408
+ }
409
+ } while (again || p !== end);
410
+ return end;
411
+ }
412
+ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
413
+ if (!ear)
414
+ return;
415
+ if (!pass && invSize)
416
+ indexCurve(ear, minX, minY, invSize);
417
+ let stop = ear;
418
+ let prev;
419
+ let next;
420
+ while (ear.prev !== ear.next) {
421
+ prev = ear.prev;
422
+ next = ear.next;
423
+ if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
424
+ triangles.push(prev.i / dim | 0);
425
+ triangles.push(ear.i / dim | 0);
426
+ triangles.push(next.i / dim | 0);
427
+ removeNode(ear);
428
+ ear = next.next;
429
+ stop = next.next;
430
+ continue;
431
+ }
432
+ ear = next;
433
+ if (ear === stop) {
434
+ if (!pass) {
435
+ earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
436
+ } else if (pass === 1) {
437
+ ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
438
+ earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
439
+ } else if (pass === 2) {
440
+ splitEarcut(ear, triangles, dim, minX, minY, invSize);
441
+ }
442
+ break;
443
+ }
444
+ }
445
+ }
446
+ function isEar(ear) {
447
+ const a = ear.prev;
448
+ const b = ear;
449
+ const c = ear.next;
450
+ if (area(a, b, c) >= 0)
451
+ return false;
452
+ const ax = a.x;
453
+ const bx = b.x;
454
+ const cx = c.x;
455
+ const ay = a.y;
456
+ const by = b.y;
457
+ const cy = c.y;
458
+ const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx;
459
+ const y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy;
460
+ const x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx;
461
+ const y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
462
+ let p = c.next;
463
+ while (p !== a) {
464
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
465
+ return false;
466
+ p = p.next;
467
+ }
468
+ return true;
469
+ }
470
+ function isEarHashed(ear, minX, minY, invSize) {
471
+ const a = ear.prev;
472
+ const b = ear;
473
+ const c = ear.next;
474
+ if (area(a, b, c) >= 0)
475
+ return false;
476
+ const ax = a.x;
477
+ const bx = b.x;
478
+ const cx = c.x;
479
+ const ay = a.y;
480
+ const by = b.y;
481
+ const cy = c.y;
482
+ const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx;
483
+ const y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy;
484
+ const x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx;
485
+ const y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
486
+ const minZ = zOrder(x0, y0, minX, minY, invSize);
487
+ const maxZ = zOrder(x1, y1, minX, minY, invSize);
488
+ let p = ear.prevZ;
489
+ let n = ear.nextZ;
490
+ while (p && p.z >= minZ && n && n.z <= maxZ) {
491
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
492
+ return false;
493
+ p = p.prevZ;
494
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
495
+ return false;
496
+ n = n.nextZ;
497
+ }
498
+ while (p && p.z >= minZ) {
499
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
500
+ return false;
501
+ p = p.prevZ;
502
+ }
503
+ while (n && n.z <= maxZ) {
504
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
505
+ return false;
506
+ n = n.nextZ;
507
+ }
508
+ return true;
509
+ }
510
+ function cureLocalIntersections(start, triangles, dim) {
511
+ let p = start;
512
+ do {
513
+ const a = p.prev;
514
+ const b = p.next.next;
515
+ if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
516
+ triangles.push(a.i / dim | 0);
517
+ triangles.push(p.i / dim | 0);
518
+ triangles.push(b.i / dim | 0);
519
+ removeNode(p);
520
+ removeNode(p.next);
521
+ p = start = b;
522
+ }
523
+ p = p.next;
524
+ } while (p !== start);
525
+ return filterPoints(p);
526
+ }
527
+ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
528
+ let a = start;
529
+ do {
530
+ let b = a.next.next;
531
+ while (b !== a.prev) {
532
+ if (a.i !== b.i && isValidDiagonal(a, b)) {
533
+ let c = splitPolygon(a, b);
534
+ a = filterPoints(a, a.next);
535
+ c = filterPoints(c, c.next);
536
+ earcutLinked(a, triangles, dim, minX, minY, invSize, 0);
537
+ earcutLinked(c, triangles, dim, minX, minY, invSize, 0);
538
+ return;
539
+ }
540
+ b = b.next;
541
+ }
542
+ a = a.next;
543
+ } while (a !== start);
544
+ }
545
+ function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
546
+ const queue = [];
547
+ let i;
548
+ let len;
549
+ let start;
550
+ let end;
551
+ let list;
552
+ for (i = 0, len = holeIndices.length; i < len; i++) {
553
+ start = holeIndices[i] * dim;
554
+ end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
555
+ list = linkedList(data, start, end, dim, false, areas && areas[i + 1], plane);
556
+ if (list === list.next)
557
+ list.steiner = true;
558
+ queue.push(getLeftmost(list));
559
+ }
560
+ queue.sort(compareX);
561
+ for (i = 0; i < queue.length; i++) {
562
+ outerNode = eliminateHole(queue[i], outerNode);
563
+ }
564
+ return outerNode;
565
+ }
566
+ function compareX(a, b) {
567
+ return a.x - b.x;
568
+ }
569
+ function eliminateHole(hole, outerNode) {
570
+ const bridge = findHoleBridge(hole, outerNode);
571
+ if (!bridge) {
572
+ return outerNode;
573
+ }
574
+ const bridgeReverse = splitPolygon(bridge, hole);
575
+ filterPoints(bridgeReverse, bridgeReverse.next);
576
+ return filterPoints(bridge, bridge.next);
577
+ }
578
+ function findHoleBridge(hole, outerNode) {
579
+ let p = outerNode;
580
+ const hx = hole.x;
581
+ const hy = hole.y;
582
+ let qx = -Infinity;
583
+ let m;
584
+ do {
585
+ if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
586
+ const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
587
+ if (x <= hx && x > qx) {
588
+ qx = x;
589
+ m = p.x < p.next.x ? p : p.next;
590
+ if (x === hx)
591
+ return m;
592
+ }
593
+ }
594
+ p = p.next;
595
+ } while (p !== outerNode);
596
+ if (!m)
597
+ return null;
598
+ const stop = m;
599
+ const mx = m.x;
600
+ const my = m.y;
601
+ let tanMin = Infinity;
602
+ let tan;
603
+ p = m;
604
+ do {
605
+ if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
606
+ tan = Math.abs(hy - p.y) / (hx - p.x);
607
+ if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
608
+ m = p;
609
+ tanMin = tan;
610
+ }
611
+ }
612
+ p = p.next;
613
+ } while (p !== stop);
614
+ return m;
615
+ }
616
+ function sectorContainsSector(m, p) {
617
+ return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
618
+ }
619
+ function indexCurve(start, minX, minY, invSize) {
620
+ let p = start;
621
+ do {
622
+ if (p.z === 0)
623
+ p.z = zOrder(p.x, p.y, minX, minY, invSize);
624
+ p.prevZ = p.prev;
625
+ p.nextZ = p.next;
626
+ p = p.next;
627
+ } while (p !== start);
628
+ p.prevZ.nextZ = null;
629
+ p.prevZ = null;
630
+ sortLinked(p);
631
+ }
632
+ function sortLinked(list) {
633
+ let e;
634
+ let i;
635
+ let inSize = 1;
636
+ let numMerges;
637
+ let p;
638
+ let pSize;
639
+ let q;
640
+ let qSize;
641
+ let tail;
642
+ do {
643
+ p = list;
644
+ list = null;
645
+ tail = null;
646
+ numMerges = 0;
647
+ while (p) {
648
+ numMerges++;
649
+ q = p;
650
+ pSize = 0;
651
+ for (i = 0; i < inSize; i++) {
652
+ pSize++;
653
+ q = q.nextZ;
654
+ if (!q)
655
+ break;
656
+ }
657
+ qSize = inSize;
658
+ while (pSize > 0 || qSize > 0 && q) {
659
+ if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
660
+ e = p;
661
+ p = p.nextZ;
662
+ pSize--;
663
+ } else {
664
+ e = q;
665
+ q = q.nextZ;
666
+ qSize--;
667
+ }
668
+ if (tail)
669
+ tail.nextZ = e;
670
+ else
671
+ list = e;
672
+ e.prevZ = tail;
673
+ tail = e;
674
+ }
675
+ p = q;
676
+ }
677
+ tail.nextZ = null;
678
+ inSize *= 2;
679
+ } while (numMerges > 1);
680
+ return list;
681
+ }
682
+ function zOrder(x, y, minX, minY, invSize) {
683
+ x = (x - minX) * invSize | 0;
684
+ y = (y - minY) * invSize | 0;
685
+ x = (x | x << 8) & 16711935;
686
+ x = (x | x << 4) & 252645135;
687
+ x = (x | x << 2) & 858993459;
688
+ x = (x | x << 1) & 1431655765;
689
+ y = (y | y << 8) & 16711935;
690
+ y = (y | y << 4) & 252645135;
691
+ y = (y | y << 2) & 858993459;
692
+ y = (y | y << 1) & 1431655765;
693
+ return x | y << 1;
694
+ }
695
+ function getLeftmost(start) {
696
+ let p = start;
697
+ let leftmost = start;
698
+ do {
699
+ if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
700
+ leftmost = p;
701
+ p = p.next;
702
+ } while (p !== start);
703
+ return leftmost;
704
+ }
705
+ function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
706
+ return (cx - px) * (ay - py) >= (ax - px) * (cy - py) && (ax - px) * (by - py) >= (bx - px) * (ay - py) && (bx - px) * (cy - py) >= (cx - px) * (by - py);
707
+ }
708
+ function isValidDiagonal(a, b) {
709
+ return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && (area(a.prev, a, b.prev) || area(a, b.prev, b)) || equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0);
710
+ }
711
+ function area(p, q, r) {
712
+ return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
713
+ }
714
+ function equals(p1, p2) {
715
+ return p1.x === p2.x && p1.y === p2.y;
716
+ }
717
+ function intersects(p1, q1, p2, q2) {
718
+ const o1 = sign(area(p1, q1, p2));
719
+ const o2 = sign(area(p1, q1, q2));
720
+ const o3 = sign(area(p2, q2, p1));
721
+ const o4 = sign(area(p2, q2, q1));
722
+ if (o1 !== o2 && o3 !== o4)
723
+ return true;
724
+ if (o1 === 0 && onSegment(p1, p2, q1))
725
+ return true;
726
+ if (o2 === 0 && onSegment(p1, q2, q1))
727
+ return true;
728
+ if (o3 === 0 && onSegment(p2, p1, q2))
729
+ return true;
730
+ if (o4 === 0 && onSegment(p2, q1, q2))
731
+ return true;
732
+ return false;
733
+ }
734
+ function onSegment(p, q, r) {
735
+ return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
736
+ }
737
+ function sign(num) {
738
+ return num > 0 ? 1 : num < 0 ? -1 : 0;
739
+ }
740
+ function intersectsPolygon(a, b) {
741
+ let p = a;
742
+ do {
743
+ if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b))
744
+ return true;
745
+ p = p.next;
746
+ } while (p !== a);
747
+ return false;
748
+ }
749
+ function locallyInside(a, b) {
750
+ return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
751
+ }
752
+ function middleInside(a, b) {
753
+ let p = a;
754
+ let inside = false;
755
+ const px = (a.x + b.x) / 2;
756
+ const py = (a.y + b.y) / 2;
757
+ do {
758
+ if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)
759
+ inside = !inside;
760
+ p = p.next;
761
+ } while (p !== a);
762
+ return inside;
763
+ }
764
+ function splitPolygon(a, b) {
765
+ const a2 = new Vertex(a.i, a.x, a.y);
766
+ const b2 = new Vertex(b.i, b.x, b.y);
767
+ const an = a.next;
768
+ const bp = b.prev;
769
+ a.next = b;
770
+ b.prev = a;
771
+ a2.next = an;
772
+ an.prev = a2;
773
+ b2.next = a2;
774
+ a2.prev = b2;
775
+ bp.next = b2;
776
+ b2.prev = bp;
777
+ return b2;
778
+ }
779
+ function insertNode(i, x, y, last) {
780
+ const p = new Vertex(i, x, y);
781
+ if (!last) {
782
+ p.prev = p;
783
+ p.next = p;
784
+ } else {
785
+ p.next = last.next;
786
+ p.prev = last;
787
+ last.next.prev = p;
788
+ last.next = p;
789
+ }
790
+ return p;
791
+ }
792
+ function removeNode(p) {
793
+ p.next.prev = p.prev;
794
+ p.prev.next = p.next;
795
+ if (p.prevZ)
796
+ p.prevZ.nextZ = p.nextZ;
797
+ if (p.nextZ)
798
+ p.nextZ.prevZ = p.prevZ;
799
+ }
800
+ var Vertex = class {
801
+ constructor(i, x, y) {
802
+ _defineProperty(this, "i", void 0);
803
+ _defineProperty(this, "x", void 0);
804
+ _defineProperty(this, "y", void 0);
805
+ _defineProperty(this, "prev", null);
806
+ _defineProperty(this, "next", null);
807
+ _defineProperty(this, "z", 0);
808
+ _defineProperty(this, "prevZ", null);
809
+ _defineProperty(this, "nextZ", null);
810
+ _defineProperty(this, "steiner", false);
811
+ this.i = i;
812
+ this.x = x;
813
+ this.y = y;
814
+ }
815
+ };
816
+
817
+ // src/geoarrow/convert-geoarrow-to-binary-geometry.ts
818
+ var BINARY_GEOMETRY_TEMPLATE = {
819
+ globalFeatureIds: { value: new Uint32Array(0), size: 1 },
820
+ positions: { value: new Float32Array(0), size: 2 },
821
+ properties: [],
822
+ numericProps: {},
823
+ featureIds: { value: new Uint32Array(0), size: 1 }
824
+ };
825
+ function getTriangleIndices(polygonIndices, primitivePolygonIndices, flatCoordinateArray, nDim) {
826
+ let primitiveIndex = 0;
827
+ const triangles = [];
828
+ for (let i = 0; i < polygonIndices.length - 1; i++) {
829
+ const startIdx = polygonIndices[i];
830
+ const endIdx = polygonIndices[i + 1];
831
+ const slicedFlatCoords = flatCoordinateArray.subarray(startIdx * nDim, endIdx * nDim);
832
+ const holeIndices = [];
833
+ while (primitivePolygonIndices[primitiveIndex] < endIdx) {
834
+ if (primitivePolygonIndices[primitiveIndex] > startIdx) {
835
+ holeIndices.push(primitivePolygonIndices[primitiveIndex] - startIdx);
836
+ }
837
+ primitiveIndex++;
838
+ }
839
+ const triangleIndices = earcut(
840
+ slicedFlatCoords,
841
+ holeIndices.length > 0 ? holeIndices : void 0,
842
+ nDim
843
+ );
844
+ for (let j = 0; j < triangleIndices.length; j++) {
845
+ triangles.push(triangleIndices[j] + startIdx);
846
+ }
847
+ }
848
+ const trianglesUint32 = new Uint32Array(triangles.length);
849
+ for (let i = 0; i < triangles.length; i++) {
850
+ trianglesUint32[i] = triangles[i];
851
+ }
852
+ return trianglesUint32;
853
+ }
854
+
855
+ // src/workers/triangulation-worker.ts
856
+ createWorker(async (data, options2 = {}) => {
857
+ const input = data;
858
+ const operation = input?.operation;
859
+ switch (operation) {
860
+ case "test":
861
+ return input;
862
+ case "triangulate":
863
+ return triangulateBatch(data);
864
+ default:
865
+ throw new Error(
866
+ `TriangulationWorker: Unsupported operation ${operation}. Expected 'triangulate'`
867
+ );
868
+ }
869
+ });
870
+ function triangulateBatch(data) {
871
+ console.error("TriangulationWorker: tessellating batch", data);
872
+ const triangleIndices = getTriangleIndices(
873
+ data.polygonIndices,
874
+ data.primitivePolygonIndices,
875
+ data.flatCoordinateArray,
876
+ data.nDim
877
+ );
878
+ return { ...data, triangleIndices };
879
+ }
880
+ })();