@nika-js/onlymap 0.2.3 → 0.3.1

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 (62) hide show
  1. package/.vscode/onlymap.code-snippets +13 -0
  2. package/LICENSE.md +4 -0
  3. package/README.md +30 -7
  4. package/THIRD-PARTY-LICENSES.md +7874 -0
  5. package/dist/{Arrow.dom-7AXne1TU.js → Arrow.dom-BNjbQ9jb.js} +23 -23
  6. package/dist/LercDecode.es-CVmNpXBp.js +303 -0
  7. package/dist/assets/LercDecode.es-BJb2dZu5.js +305 -0
  8. package/dist/assets/__vite-browser-external-DDArsqdc.js +29 -0
  9. package/dist/assets/lerc-wasm.wasm +0 -0
  10. package/dist/assets/lzw-BY5a_5nb.js +83 -0
  11. package/dist/assets/worker-DtIrTJB7.js +305 -0
  12. package/dist/assets/zstd-QGAv3PMm.js +383 -0
  13. package/dist/{basemap-BdvB-SHy.js → basemap-BSb-g03Z.js} +5729 -5684
  14. package/dist/basemap-registry.d.ts +10 -0
  15. package/dist/basemap.d.ts +23 -0
  16. package/dist/color.d.ts +9 -0
  17. package/dist/{convert-arrow-schema-CvZ3cT5m.js → convert-arrow-schema-DrAihRf9.js} +31 -31
  18. package/dist/ctx.d.ts +3 -0
  19. package/dist/deck.d.ts +28 -0
  20. package/dist/deck.js +16 -0
  21. package/dist/elements/om-map.d.ts +29 -0
  22. package/dist/html-data.d.ts +2 -2
  23. package/dist/index-CIEkseeV.js +3108 -0
  24. package/dist/index-D67FynN5.js +594 -0
  25. package/dist/{index-CJOMgp8k.js → index-QSkZjzIL.js} +4 -4
  26. package/dist/index-WeMwLoaQ.js +1446 -0
  27. package/dist/{index-BxzDKZpu.js → index-lV5eG2Xt.js} +22439 -21347
  28. package/dist/index.d.ts +13 -0
  29. package/dist/ir-snapshot.d.ts +2 -0
  30. package/dist/ir.d.ts +10 -0
  31. package/dist/layer-registry.d.ts +15 -1
  32. package/dist/legend-spec.d.ts +66 -0
  33. package/dist/lerc-DJzRIT6z.js +30 -0
  34. package/dist/lerc-wasm.wasm +0 -0
  35. package/dist/lzw-BY5a_5nb.js +83 -0
  36. package/dist/mgrs-BY9bIvp4.js +799 -0
  37. package/dist/onlymapjs.css +1 -1
  38. package/dist/onlymapjs.js +55 -35
  39. package/dist/programmatic.d.ts +35 -0
  40. package/dist/raster-BKf1dx54.js +8843 -0
  41. package/dist/raster.d.ts +61 -0
  42. package/dist/react/om-layer.d.ts +2 -0
  43. package/dist/react.js +18 -16
  44. package/dist/{recordbatch-HRu0SMKp.js → recordbatch-Bpc0uxFn.js} +200 -200
  45. package/dist/runtime-core.d.ts +73 -1
  46. package/dist/scene-lighting.d.ts +83 -0
  47. package/dist/selection.d.ts +1 -1
  48. package/dist/snapshot.d.ts +14 -0
  49. package/dist/{table-accessors-DBjWgN0C.js → table-accessors-CYWTzpQI.js} +71 -76
  50. package/dist/terrain.d.ts +113 -0
  51. package/dist/version.d.ts +1 -1
  52. package/dist/zstd-jXobGRcq.js +14 -0
  53. package/docs/custom-layers.md +99 -0
  54. package/llms.txt +5 -5
  55. package/onlymapjs.html-data.json +163 -29
  56. package/package.json +35 -15
  57. package/skills/onlymapjs/SKILL.md +3 -1
  58. package/skills/onlymapjs/references/syntax.md +53 -3
  59. package/dist/index-BVQ0s1Zh.js +0 -1457
  60. package/dist/index-CvBHiOGD.js +0 -605
  61. package/dist/index-Vc8QfNEf.js +0 -3907
  62. package/dist/onlymapjs.umd.cjs +0 -8634
@@ -0,0 +1,1446 @@
1
+ import { ae as Be, af as le, ag as ce, ah as De, ai as Oe, aj as ke } from "./index-lV5eG2Xt.js";
2
+ import { y as ve, a as he, z as G, R as J, A as ue, C as Fe, F as je, n as xe, S as Ie, E as Ne } from "./recordbatch-Bpc0uxFn.js";
3
+ import { g as V, a as fe, b as Le, c as Ue, d as Me, e as qe, m as Ve } from "./table-accessors-CYWTzpQI.js";
4
+ import { c as $e } from "./convert-arrow-schema-DrAihRf9.js";
5
+ function de(t) {
6
+ switch (t.shape) {
7
+ case "array-row-table":
8
+ case "object-row-table":
9
+ return Pe(t.data);
10
+ case "geojson-table":
11
+ return ze(t.features);
12
+ case "columnar-table":
13
+ return He(t.data);
14
+ case "arrow-table":
15
+ default:
16
+ throw new Error("Deduce schema");
17
+ }
18
+ }
19
+ function He(t) {
20
+ const e = [];
21
+ for (const [r, s] of Object.entries(t)) {
22
+ const n = Qe(s, r);
23
+ e.push(n);
24
+ }
25
+ return { fields: e, metadata: {} };
26
+ }
27
+ function Pe(t) {
28
+ if (!t.length)
29
+ throw new Error("deduce from empty table");
30
+ const e = [], r = t[0];
31
+ for (const [s, n] of Object.entries(r))
32
+ e.push(me(n, s));
33
+ return { fields: e, metadata: {} };
34
+ }
35
+ function ze(t) {
36
+ if (!t.length)
37
+ throw new Error("deduce from empty table");
38
+ const e = [], r = t[0].properties || {};
39
+ for (const [s, n] of Object.entries(r))
40
+ e.push(me(n, s));
41
+ return { fields: e, metadata: {} };
42
+ }
43
+ function Qe(t, e) {
44
+ if (ArrayBuffer.isView(t)) {
45
+ const r = Be(t);
46
+ return {
47
+ name: e,
48
+ type: r.type || "null",
49
+ nullable: r.nullable
50
+ // metadata: {}
51
+ };
52
+ }
53
+ if (Array.isArray(t) && t.length > 0) {
54
+ const r = t[0], s = le(r);
55
+ return {
56
+ name: e,
57
+ type: s,
58
+ nullable: !0
59
+ // metadata: {},
60
+ };
61
+ }
62
+ throw new Error("empty table");
63
+ }
64
+ function me(t, e) {
65
+ const r = le(t);
66
+ return {
67
+ name: e,
68
+ type: r,
69
+ nullable: !0
70
+ // metadata: {}
71
+ };
72
+ }
73
+ function Je(t, e) {
74
+ const r = ce(t.type, t.nullable);
75
+ return new r(e);
76
+ }
77
+ function* We(t, e) {
78
+ const r = $e(t.schema), s = V(t), n = fe(t), a = s, c = r?.fields.map((o) => ve(o)), h = new he(r.fields);
79
+ let f = 0;
80
+ for (let o = 0; o < s; o++)
81
+ for (let u = 0; u < n; ++u) {
82
+ const i = Le(t, o, u);
83
+ if (c[u].append(i), f++, f >= a) {
84
+ const g = c.map((l) => l.flush()), w = new G(h, 0, f, 0, void 0, g);
85
+ yield new J(r, w), f = 0;
86
+ }
87
+ }
88
+ if (f > 0) {
89
+ const o = c.map((i) => i.flush()), u = new G(h, 0, f, 0, void 0, o);
90
+ yield new J(r, u), f = 0;
91
+ }
92
+ c.map((o) => o.finish());
93
+ }
94
+ function Ze(t, e) {
95
+ switch (t.shape) {
96
+ case "arrow-table":
97
+ return t.data;
98
+ case "columnar-table":
99
+ // TODO - optimized implementation is possible
100
+ // return convertColumnarTableToArrow(table, options);
101
+ // fall through
102
+ default:
103
+ const r = We(t);
104
+ return new ue(r);
105
+ }
106
+ }
107
+ function L(t, e) {
108
+ switch (e) {
109
+ case "object-row-table":
110
+ return Ge(t);
111
+ case "array-row-table":
112
+ return Ye(t);
113
+ case "columnar-table":
114
+ return Ke(t);
115
+ case "arrow-table":
116
+ return Xe(t);
117
+ default:
118
+ throw new Error(e);
119
+ }
120
+ }
121
+ function Ke(t) {
122
+ const e = t.schema || de(t), r = t.schema?.fields || [];
123
+ if (t.shape === "columnar-table")
124
+ return { ...t, schema: e };
125
+ const s = V(t), n = {};
126
+ for (const a of r) {
127
+ const c = Je(a, s);
128
+ n[a.name] = c;
129
+ for (let h = 0; h < s; h++)
130
+ c[h] = Ue(t, h, a.name);
131
+ }
132
+ return {
133
+ shape: "columnar-table",
134
+ schema: e,
135
+ data: n
136
+ };
137
+ }
138
+ function Ye(t) {
139
+ if (t.shape === "array-row-table")
140
+ return t;
141
+ const e = V(t), r = new Array(e);
142
+ for (let s = 0; s < e; s++)
143
+ r[s] = Me(t, s);
144
+ return {
145
+ shape: "array-row-table",
146
+ schema: t.schema,
147
+ data: r
148
+ };
149
+ }
150
+ function Ge(t) {
151
+ if (t.shape === "object-row-table")
152
+ return t;
153
+ const e = V(t), r = new Array(e);
154
+ for (let s = 0; s < e; s++)
155
+ r[s] = qe(t, s);
156
+ return {
157
+ shape: "object-row-table",
158
+ schema: t.schema,
159
+ data: r
160
+ };
161
+ }
162
+ function Xe(t) {
163
+ const e = Ze(t);
164
+ return {
165
+ shape: "arrow-table",
166
+ schema: t.schema,
167
+ data: e
168
+ };
169
+ }
170
+ function pe(t, e) {
171
+ if (!t)
172
+ throw new Error("null row");
173
+ const r = {};
174
+ if (e)
175
+ for (let s = 0; s < e.length; s++)
176
+ r[e[s]] = t[s];
177
+ else
178
+ for (let s = 0; s < t.length; s++) {
179
+ const n = `column-${s}`;
180
+ r[n] = t[s];
181
+ }
182
+ return r;
183
+ }
184
+ function ge(t, e) {
185
+ if (!t)
186
+ throw new Error("null row");
187
+ if (e) {
188
+ const r = new Array(e.length);
189
+ for (let s = 0; s < e.length; s++)
190
+ r[s] = t[e[s]];
191
+ return r;
192
+ }
193
+ return Object.values(t);
194
+ }
195
+ function et(t) {
196
+ const e = [];
197
+ for (let r = 0; r < t.length; r++) {
198
+ const s = `column-${r}`;
199
+ e.push(s);
200
+ }
201
+ return e;
202
+ }
203
+ function tt(t) {
204
+ return Object.keys(t);
205
+ }
206
+ function M(t, e) {
207
+ switch (e) {
208
+ case "object-row-table":
209
+ return { ...t, ...L(t, "object-row-table") };
210
+ case "array-row-table":
211
+ return { ...t, ...L(t, "array-row-table") };
212
+ case "columnar-table":
213
+ return { ...t, ...L(t, "columnar-table") };
214
+ case "arrow-table":
215
+ return { ...t, ...L(t, "arrow-table") };
216
+ default:
217
+ throw new Error(e);
218
+ }
219
+ }
220
+ async function* rt(t, e) {
221
+ for await (const r of t)
222
+ switch (e) {
223
+ case "object-row-table":
224
+ yield M(r, "object-row-table");
225
+ break;
226
+ case "array-row-table":
227
+ yield M(r, "array-row-table");
228
+ break;
229
+ case "columnar-table":
230
+ yield M(r, "columnar-table");
231
+ break;
232
+ case "arrow-table":
233
+ yield M(r, "arrow-table");
234
+ break;
235
+ default:
236
+ throw new Error(e);
237
+ }
238
+ }
239
+ const X = 100;
240
+ class st {
241
+ schema;
242
+ options;
243
+ shape;
244
+ length = 0;
245
+ rows = null;
246
+ cursor = 0;
247
+ _headers = [];
248
+ constructor(e, r) {
249
+ if (this.options = r, this.schema = e, !Array.isArray(e)) {
250
+ this._headers = [];
251
+ for (const s in e)
252
+ this._headers[e[s].index] = e[s].name;
253
+ }
254
+ }
255
+ rowCount() {
256
+ return this.length;
257
+ }
258
+ addArrayRow(e, r) {
259
+ Number.isFinite(r) && (this.cursor = r), this.shape = "array-row-table", this.rows = this.rows || new Array(X), this.rows[this.length] = e, this.length++;
260
+ }
261
+ addObjectRow(e, r) {
262
+ Number.isFinite(r) && (this.cursor = r), this.shape = "object-row-table", this.rows = this.rows || new Array(X), this.rows[this.length] = e, this.length++;
263
+ }
264
+ getBatch() {
265
+ let e = this.rows;
266
+ return e ? (e = e.slice(0, this.length), this.rows = null, {
267
+ shape: this.shape || "array-row-table",
268
+ batchType: "data",
269
+ data: e,
270
+ length: this.length,
271
+ schema: this.schema,
272
+ cursor: this.cursor
273
+ }) : null;
274
+ }
275
+ }
276
+ const ee = 100;
277
+ class nt {
278
+ schema;
279
+ options;
280
+ length = 0;
281
+ objectRows = null;
282
+ arrayRows = null;
283
+ cursor = 0;
284
+ _headers = null;
285
+ constructor(e, r) {
286
+ if (this.options = r, this.schema = e, e) {
287
+ this._headers = [];
288
+ for (let s = 0; s < e.fields.length; s++)
289
+ this._headers[s] = e.fields[s].name;
290
+ }
291
+ }
292
+ rowCount() {
293
+ return this.length;
294
+ }
295
+ addArrayRow(e, r) {
296
+ switch (Number.isFinite(r) && (this.cursor = r), this._headers ||= et(e), this.options.shape) {
297
+ case "object-row-table":
298
+ const s = pe(e, this._headers);
299
+ this.addObjectRow(s, r);
300
+ break;
301
+ case "array-row-table":
302
+ this.arrayRows = this.arrayRows || new Array(ee), this.arrayRows[this.length] = e, this.length++;
303
+ break;
304
+ }
305
+ }
306
+ addObjectRow(e, r) {
307
+ switch (Number.isFinite(r) && (this.cursor = r), this._headers ||= tt(e), this.options.shape) {
308
+ case "array-row-table":
309
+ const s = ge(e, this._headers);
310
+ this.addArrayRow(s, r);
311
+ break;
312
+ case "object-row-table":
313
+ this.objectRows = this.objectRows || new Array(ee), this.objectRows[this.length] = e, this.length++;
314
+ break;
315
+ }
316
+ }
317
+ getBatch() {
318
+ let e = this.arrayRows || this.objectRows;
319
+ return e ? (e = e.slice(0, this.length), this.arrayRows = null, this.objectRows = null, {
320
+ shape: this.options.shape,
321
+ batchType: "data",
322
+ data: e,
323
+ length: this.length,
324
+ // @ts-expect-error we should infer a schema
325
+ schema: this.schema,
326
+ cursor: this.cursor
327
+ }) : null;
328
+ }
329
+ }
330
+ const it = 100;
331
+ class we {
332
+ schema;
333
+ length = 0;
334
+ allocated = 0;
335
+ columns = {};
336
+ constructor(e, r) {
337
+ this.schema = e, this._reallocateColumns();
338
+ }
339
+ rowCount() {
340
+ return this.length;
341
+ }
342
+ addArrayRow(e) {
343
+ this._reallocateColumns();
344
+ let r = 0;
345
+ for (const s in this.columns)
346
+ this.columns[s][this.length] = e[r++];
347
+ this.length++;
348
+ }
349
+ addObjectRow(e) {
350
+ this._reallocateColumns();
351
+ for (const r in e)
352
+ this.columns[r][this.length] = e[r];
353
+ this.length++;
354
+ }
355
+ getBatch() {
356
+ return this._pruneColumns(), {
357
+ shape: "columnar-table",
358
+ batchType: "data",
359
+ data: this.columns,
360
+ schema: this.schema,
361
+ length: this.length
362
+ };
363
+ }
364
+ // HELPERS
365
+ _reallocateColumns() {
366
+ if (!(this.length < this.allocated)) {
367
+ this.allocated = this.allocated > 0 ? this.allocated *= 2 : it, this.columns = {};
368
+ for (const e of this.schema.fields) {
369
+ const r = ce(e.type, e.nullable), s = this.columns[e.name];
370
+ if (!s)
371
+ this.columns[e.name] = new r(this.allocated);
372
+ else if (Array.isArray(s))
373
+ s.length = this.allocated;
374
+ else if (De(s)) {
375
+ const n = new r(this.allocated);
376
+ n.set(s), this.columns[e.name] = n;
377
+ } else
378
+ throw new Error("Invalid column type");
379
+ }
380
+ }
381
+ }
382
+ _pruneColumns() {
383
+ for (const [e, r] of Object.entries(this.columns))
384
+ this.columns[e] = r.slice(0, this.length);
385
+ }
386
+ }
387
+ class at extends we {
388
+ arrowSchema;
389
+ constructor(e, r) {
390
+ super(e, r), this.arrowSchema = null;
391
+ }
392
+ getBatch() {
393
+ const e = super.getBatch();
394
+ if (e) {
395
+ this.arrowSchema = this.arrowSchema || ot(e.schema);
396
+ const r = lt(this.arrowSchema, e.data), s = new J(this.arrowSchema, Fe({
397
+ type: new he(this.arrowSchema.fields),
398
+ children: r.map(({ data: n }) => n[0])
399
+ }));
400
+ return {
401
+ shape: "arrow-table",
402
+ batchType: "data",
403
+ data: new ue([s]),
404
+ length: e.length
405
+ };
406
+ }
407
+ return null;
408
+ }
409
+ }
410
+ function ot(t) {
411
+ const e = [];
412
+ for (const r in t) {
413
+ const s = t[r];
414
+ if (s.type === Float32Array) {
415
+ const n = /* @__PURE__ */ new Map(), a = new je(s.name, new xe(), s.nullable, n);
416
+ e.push(a);
417
+ }
418
+ }
419
+ if (e.length === 0)
420
+ throw new Error("No arrow convertible fields");
421
+ return new Ie(e);
422
+ }
423
+ function lt(t, e) {
424
+ const r = [];
425
+ for (const s of t.fields) {
426
+ const n = e[s.name];
427
+ if (n instanceof Float32Array) {
428
+ const a = Ne(n);
429
+ r.push(a);
430
+ }
431
+ }
432
+ if (t.fields.length !== r.length)
433
+ throw new Error("Some columns not arrow convertible");
434
+ return r;
435
+ }
436
+ const ct = {
437
+ shape: void 0,
438
+ batchSize: "auto",
439
+ batchDebounceMs: 0,
440
+ limit: 0,
441
+ _limitMB: 0
442
+ };
443
+ class ht {
444
+ schema;
445
+ options;
446
+ aggregator = null;
447
+ batchCount = 0;
448
+ bytesUsed = 0;
449
+ isChunkComplete = !1;
450
+ lastBatchEmittedMs = Date.now();
451
+ totalLength = 0;
452
+ totalBytes = 0;
453
+ rowBytes = 0;
454
+ static ArrowBatch;
455
+ constructor(e, r) {
456
+ this.schema = e, this.options = { ...ct, ...r };
457
+ }
458
+ limitReached() {
459
+ return !!(this.options?.limit && this.totalLength >= this.options.limit || this.options?._limitMB && this.totalBytes / 1e6 >= this.options._limitMB);
460
+ }
461
+ /** @deprecated Use addArrayRow or addObjectRow */
462
+ addRow(e) {
463
+ this.limitReached() || (this.totalLength++, this.rowBytes = this.rowBytes || this._estimateRowMB(e), this.totalBytes += this.rowBytes, Array.isArray(e) ? this.addArrayRow(e) : this.addObjectRow(e));
464
+ }
465
+ /** Add one row to the batch */
466
+ addArrayRow(e) {
467
+ if (!this.aggregator) {
468
+ const r = this._getTableBatchType();
469
+ this.aggregator = new r(this.schema, this.options);
470
+ }
471
+ this.aggregator.addArrayRow(e);
472
+ }
473
+ /** Add one row to the batch */
474
+ addObjectRow(e) {
475
+ if (!this.aggregator) {
476
+ const r = this._getTableBatchType();
477
+ this.aggregator = new r(this.schema, this.options);
478
+ }
479
+ this.aggregator.addObjectRow(e);
480
+ }
481
+ /** Mark an incoming raw memory chunk has completed */
482
+ chunkComplete(e) {
483
+ e instanceof ArrayBuffer && (this.bytesUsed += e.byteLength), typeof e == "string" && (this.bytesUsed += e.length), this.isChunkComplete = !0;
484
+ }
485
+ getFullBatch(e) {
486
+ return this._isFull() ? this._getBatch(e) : null;
487
+ }
488
+ getFinalBatch(e) {
489
+ return this._getBatch(e);
490
+ }
491
+ // INTERNAL
492
+ _estimateRowMB(e) {
493
+ return Array.isArray(e) ? e.length * 8 : Object.keys(e).length * 8;
494
+ }
495
+ _isFull() {
496
+ if (!this.aggregator || this.aggregator.rowCount() === 0)
497
+ return !1;
498
+ if (this.options.batchSize === "auto") {
499
+ if (!this.isChunkComplete)
500
+ return !1;
501
+ } else if (this.options.batchSize > this.aggregator.rowCount())
502
+ return !1;
503
+ return this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs ? !1 : (this.isChunkComplete = !1, this.lastBatchEmittedMs = Date.now(), !0);
504
+ }
505
+ /**
506
+ * bytesUsed can be set via chunkComplete or via getBatch*
507
+ */
508
+ _getBatch(e) {
509
+ if (!this.aggregator)
510
+ return null;
511
+ e?.bytesUsed && (this.bytesUsed = e.bytesUsed);
512
+ const r = this.aggregator.getBatch();
513
+ return r.count = this.batchCount, r.bytesUsed = this.bytesUsed, Object.assign(r, e), this.batchCount++, this.aggregator = null, r;
514
+ }
515
+ _getTableBatchType() {
516
+ switch (this.options.shape) {
517
+ case "array-row-table":
518
+ case "object-row-table":
519
+ return nt;
520
+ case "columnar-table":
521
+ return we;
522
+ case "arrow-table":
523
+ return at;
524
+ default:
525
+ return st;
526
+ }
527
+ }
528
+ }
529
+ class te extends Array {
530
+ enqueue(e) {
531
+ return this.push(e);
532
+ }
533
+ dequeue() {
534
+ return this.shift();
535
+ }
536
+ }
537
+ class ut {
538
+ _values;
539
+ _settlers;
540
+ _closed;
541
+ constructor() {
542
+ this._values = new te(), this._settlers = new te(), this._closed = !1;
543
+ }
544
+ close() {
545
+ for (; this._settlers.length > 0; )
546
+ this._settlers.dequeue().resolve({ done: !0 });
547
+ this._closed = !0;
548
+ }
549
+ [Symbol.asyncIterator]() {
550
+ return this;
551
+ }
552
+ enqueue(e) {
553
+ if (this._closed)
554
+ throw new Error("Closed");
555
+ if (this._settlers.length > 0) {
556
+ if (this._values.length > 0)
557
+ throw new Error("Illegal internal state");
558
+ const r = this._settlers.dequeue();
559
+ e instanceof Error ? r.reject(e) : r.resolve({ value: e });
560
+ } else
561
+ this._values.enqueue(e);
562
+ }
563
+ /**
564
+ * @returns a Promise for an IteratorResult
565
+ */
566
+ next() {
567
+ if (this._values.length > 0) {
568
+ const e = this._values.dequeue();
569
+ return e instanceof Error ? Promise.reject(e) : Promise.resolve({ value: e });
570
+ }
571
+ if (this._closed) {
572
+ if (this._settlers.length > 0)
573
+ throw new Error("Illegal internal state");
574
+ return Promise.resolve({ done: !0 });
575
+ }
576
+ return new Promise((e, r) => {
577
+ this._settlers.enqueue({ resolve: e, reject: r });
578
+ });
579
+ }
580
+ }
581
+ const re = "\uFEFF", F = {
582
+ RECORD_SEP: "",
583
+ UNIT_SEP: "",
584
+ BYTE_ORDER_MARK: re,
585
+ BAD_DELIMITERS: ["\r", `
586
+ `, '"', re],
587
+ WORKERS_SUPPORTED: !1,
588
+ // !IS_WORKER && !!globalThis.Worker
589
+ NODE_STREAM_INPUT: 1,
590
+ // Configurable chunk sizes for local and remote files, respectively
591
+ LocalChunkSize: 1024 * 1024 * 10,
592
+ // 10 M,
593
+ RemoteChunkSize: 1024 * 1024 * 5,
594
+ // 5 M,
595
+ DefaultDelimiter: ","
596
+ // Used if not specified and detection fail,
597
+ };
598
+ function ft(t, e = {}, r = dt) {
599
+ return new r(e).stream(t);
600
+ }
601
+ let ye = class {
602
+ _handle;
603
+ _config;
604
+ _finished = !1;
605
+ _completed = !1;
606
+ _input = null;
607
+ _baseIndex = 0;
608
+ _partialLine = "";
609
+ _rowCount = 0;
610
+ _start = 0;
611
+ isFirstChunk = !0;
612
+ _completeResults = {
613
+ data: [],
614
+ errors: [],
615
+ meta: {}
616
+ };
617
+ constructor(e) {
618
+ const r = { ...e };
619
+ r.dynamicTypingFunction && (r.dynamicTyping = {}), r.chunkSize = parseInt(r.chunkSize), !e.step && !e.chunk && (r.chunkSize = null), this._handle = new be(r), this._handle.streamer = this, this._config = r;
620
+ }
621
+ // eslint-disable-next-line complexity, max-statements
622
+ parseChunk(e, r) {
623
+ if (this.isFirstChunk && j(this._config.beforeFirstChunk)) {
624
+ const h = this._config.beforeFirstChunk(e);
625
+ h !== void 0 && (e = h);
626
+ }
627
+ this.isFirstChunk = !1;
628
+ const s = this._partialLine + e;
629
+ this._partialLine = "";
630
+ let n = this._handle.parse(s, this._baseIndex, !this._finished);
631
+ if (this._handle.paused() || this._handle.aborted())
632
+ return;
633
+ const a = n.meta.cursor;
634
+ this._finished || (this._partialLine = s.substring(a - this._baseIndex), this._baseIndex = a), n && n.data && (this._rowCount += n.data.length);
635
+ const c = this._finished || this._config.preview && this._rowCount >= this._config.preview;
636
+ if (j(this._config.chunk) && !r) {
637
+ if (this._config.chunk(n, this._handle), this._handle.paused() || this._handle.aborted())
638
+ return;
639
+ n = void 0, this._completeResults = void 0;
640
+ }
641
+ return !this._config.step && !this._config.chunk && (this._completeResults.data = this._completeResults.data.concat(n.data), this._completeResults.errors = this._completeResults.errors.concat(n.errors), this._completeResults.meta = n.meta), !this._completed && c && j(this._config.complete) && (!n || !n.meta.aborted) && (this._config.complete(this._completeResults, this._input), this._completed = !0), n;
642
+ }
643
+ _sendError(e) {
644
+ j(this._config.error) && this._config.error(e);
645
+ }
646
+ };
647
+ class dt extends ye {
648
+ remaining;
649
+ constructor(e = {}) {
650
+ super(e);
651
+ }
652
+ stream(e) {
653
+ return this.remaining = e, this._nextChunk();
654
+ }
655
+ _nextChunk() {
656
+ if (this._finished)
657
+ return;
658
+ const e = this._config.chunkSize, r = e ? this.remaining.substr(0, e) : this.remaining;
659
+ return this.remaining = e ? this.remaining.substr(e) : "", this._finished = !this.remaining, this.parseChunk(r);
660
+ }
661
+ }
662
+ const mt = /^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i, pt = /(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/;
663
+ class be {
664
+ _config;
665
+ /** Number of times step was called (number of rows parsed) */
666
+ _stepCounter = 0;
667
+ /** Number of rows that have been parsed so far */
668
+ _rowCounter = 0;
669
+ /** The input being parsed */
670
+ _input;
671
+ /** The core parser being used */
672
+ _parser;
673
+ /** Whether we are paused or not */
674
+ _paused = !1;
675
+ /** Whether the parser has aborted or not */
676
+ _aborted = !1;
677
+ /** Temporary state between delimiter detection and processing results */
678
+ _delimiterError = !1;
679
+ /** Fields are from the header row of the input, if there is one */
680
+ _fields = [];
681
+ /** The last results returned from the parser */
682
+ _results = {
683
+ data: [],
684
+ errors: [],
685
+ meta: {}
686
+ };
687
+ constructor(e) {
688
+ if (j(e.step)) {
689
+ const r = e.step;
690
+ e.step = (s) => {
691
+ if (this._results = s, this.needsHeaderRow())
692
+ this.processResults();
693
+ else {
694
+ if (this.processResults(), !this._results.data || this._results.data.length === 0)
695
+ return;
696
+ this._stepCounter += s.data.length, e.preview && this._stepCounter > e.preview ? this._parser.abort() : r(this._results, this);
697
+ }
698
+ };
699
+ }
700
+ this._config = e;
701
+ }
702
+ /**
703
+ * Parses input. Most users won't need, and shouldn't mess with, the baseIndex
704
+ * and ignoreLastRow parameters. They are used by streamers (wrapper functions)
705
+ * when an input comes in multiple chunks, like from a file.
706
+ */
707
+ parse(e, r, s) {
708
+ const n = this._config.quoteChar || '"';
709
+ if (this._config.newline || (this._config.newline = gt(e, n)), this._delimiterError = !1, this._config.delimiter)
710
+ j(this._config.delimiter) && (this._config.delimiter = this._config.delimiter(e), this._results.meta.delimiter = this._config.delimiter);
711
+ else {
712
+ const c = this.guessDelimiter(e, this._config.newline, this._config.skipEmptyLines, this._config.comments, this._config.delimitersToGuess);
713
+ c.successful ? this._config.delimiter = c.bestDelimiter : (this._delimiterError = !0, this._config.delimiter = F.DefaultDelimiter), this._results.meta.delimiter = this._config.delimiter;
714
+ }
715
+ const a = _e(this._config);
716
+ return this._config.preview && this._config.header && a.preview++, this._input = e, this._parser = new W(a), this._results = this._parser.parse(this._input, r, s), this.processResults(), this._paused ? { meta: { paused: !0 } } : this._results || { meta: { paused: !1 } };
717
+ }
718
+ paused() {
719
+ return this._paused;
720
+ }
721
+ pause() {
722
+ this._paused = !0, this._parser.abort(), this._input = this._input.substr(this._parser.getCharIndex());
723
+ }
724
+ resume() {
725
+ this._paused = !1, this.streamer.parseChunk(this._input, !0);
726
+ }
727
+ aborted() {
728
+ return this._aborted;
729
+ }
730
+ abort() {
731
+ this._aborted = !0, this._parser.abort(), this._results.meta.aborted = !0, j(this._config.complete) && this._config.complete(this._results), this._input = "";
732
+ }
733
+ testEmptyLine(e) {
734
+ return this._config.skipEmptyLines === "greedy" ? e.join("").trim() === "" : e.length === 1 && e[0].length === 0;
735
+ }
736
+ processResults() {
737
+ if (this._results && this._delimiterError && (this.addError("Delimiter", "UndetectableDelimiter", `Unable to auto-detect delimiting character; defaulted to '${F.DefaultDelimiter}'`), this._delimiterError = !1), this._config.skipEmptyLines)
738
+ for (let e = 0; e < this._results.data.length; e++)
739
+ this.testEmptyLine(this._results.data[e]) && this._results.data.splice(e--, 1);
740
+ return this.needsHeaderRow() && this.fillHeaderFields(), this.applyHeaderAndDynamicTypingAndTransformation();
741
+ }
742
+ needsHeaderRow() {
743
+ return this._config.header && this._fields.length === 0;
744
+ }
745
+ fillHeaderFields() {
746
+ if (!this._results)
747
+ return;
748
+ const e = (r) => {
749
+ j(this._config.transformHeader) && (r = this._config.transformHeader(r)), this._fields.push(r);
750
+ };
751
+ if (Array.isArray(this._results.data[0])) {
752
+ for (let r = 0; this.needsHeaderRow() && r < this._results.data.length; r++)
753
+ this._results.data[r].forEach(e);
754
+ this._results.data.splice(0, 1);
755
+ } else
756
+ this._results.data.forEach(e);
757
+ }
758
+ shouldApplyDynamicTyping(e) {
759
+ return this._config.dynamicTypingFunction && this._config.dynamicTyping?.[e] === void 0 && (this._config.dynamicTyping[e] = this._config.dynamicTypingFunction(e)), (this._config.dynamicTyping?.[e] || this._config.dynamicTyping) === !0;
760
+ }
761
+ parseDynamic(e, r) {
762
+ return this.shouldApplyDynamicTyping(e) ? r === "true" || r === "TRUE" ? !0 : r === "false" || r === "FALSE" ? !1 : mt.test(r) ? parseFloat(r) : pt.test(r) ? new Date(r) : r === "" ? null : r : r;
763
+ }
764
+ applyHeaderAndDynamicTypingAndTransformation() {
765
+ if (!this._results || !this._results.data || !this._config.header && !this._config.dynamicTyping && !this._config.transform)
766
+ return this._results;
767
+ let e = 1;
768
+ return !this._results.data[0] || Array.isArray(this._results.data[0]) ? (this._results.data = this._results.data.map(this.processRow.bind(this)), e = this._results.data.length) : this._results.data = this.processRow(this._results.data, 0), this._config.header && this._results.meta && (this._results.meta.fields = this._fields), this._rowCounter += e, this._results;
769
+ }
770
+ processRow(e, r) {
771
+ const s = this._config.header ? {} : [];
772
+ let n;
773
+ for (n = 0; n < e.length; n++) {
774
+ let a = n, c = e[n];
775
+ this._config.header && (a = n >= this._fields.length ? "__parsed_extra" : this._fields[n]), this._config.transform && (c = this._config.transform(c, a)), c = this.parseDynamic(a, c), a === "__parsed_extra" ? (s[a] = s[a] || [], s[a].push(c)) : s[a] = c;
776
+ }
777
+ return this._config.header && (n > this._fields.length ? this.addError("FieldMismatch", "TooManyFields", `Too many fields: expected ${this._fields.length} fields but parsed ${n}`, this._rowCounter + r) : n < this._fields.length && this.addError("FieldMismatch", "TooFewFields", `Too few fields: expected ${this._fields.length} fields but parsed ${n}`, this._rowCounter + r)), s;
778
+ }
779
+ // eslint-disable-next-line complexity, max-statements
780
+ guessDelimiter(e, r, s, n, a) {
781
+ let c, h, f;
782
+ a = a || [",", " ", "|", ";", F.RECORD_SEP, F.UNIT_SEP];
783
+ for (let o = 0; o < a.length; o++) {
784
+ const u = a[o];
785
+ let i = 0, d = 0, g = 0;
786
+ f = void 0;
787
+ const w = new W({
788
+ comments: n,
789
+ delimiter: u,
790
+ newline: r,
791
+ preview: 10
792
+ }).parse(e);
793
+ for (let l = 0; l < w.data.length; l++) {
794
+ if (s && this.testEmptyLine(w.data[l])) {
795
+ g++;
796
+ continue;
797
+ }
798
+ const m = w.data[l].length;
799
+ if (i += m, typeof f > "u") {
800
+ f = 0;
801
+ continue;
802
+ } else m > 1 && (d += Math.abs(m - f), f = m);
803
+ }
804
+ w.data.length > 0 && (i /= w.data.length - g), (typeof h > "u" || d > h) && i > 1.99 && (h = d, c = u);
805
+ }
806
+ return this._config.delimiter = c, {
807
+ successful: !!c,
808
+ bestDelimiter: c
809
+ };
810
+ }
811
+ addError(e, r, s, n) {
812
+ this._results.errors.push({
813
+ type: e,
814
+ code: r,
815
+ message: s,
816
+ row: n
817
+ });
818
+ }
819
+ }
820
+ function gt(t, e) {
821
+ t = t.substr(0, 1024 * 1024);
822
+ const r = new RegExp(`${q(e)}([^]*?)${q(e)}`, "gm");
823
+ t = t.replace(r, "");
824
+ const s = t.split("\r"), n = t.split(`
825
+ `), a = n.length > 1 && n[0].length < s[0].length;
826
+ if (s.length === 1 || a)
827
+ return `
828
+ `;
829
+ let c = 0;
830
+ for (let h = 0; h < s.length; h++)
831
+ s[h][0] === `
832
+ ` && c++;
833
+ return c >= s.length / 2 ? `\r
834
+ ` : "\r";
835
+ }
836
+ function q(t) {
837
+ return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
838
+ }
839
+ function W(t = {}) {
840
+ let e = t.delimiter, r = t.newline, s = t.comments;
841
+ const n = t.step, a = t.preview, c = t.fastMode;
842
+ let h;
843
+ t.quoteChar === void 0 ? h = '"' : h = t.quoteChar;
844
+ let f = h;
845
+ if (t.escapeChar !== void 0 && (f = t.escapeChar), (typeof e != "string" || F.BAD_DELIMITERS.indexOf(e) > -1) && (e = ","), s === e)
846
+ throw new Error("Comment character same as delimiter");
847
+ s === !0 ? s = "#" : (typeof s != "string" || F.BAD_DELIMITERS.indexOf(s) > -1) && (s = !1), r !== `
848
+ ` && r !== "\r" && r !== `\r
849
+ ` && (r = `
850
+ `);
851
+ let o = 0, u = !1;
852
+ this.parse = function(i, d, g) {
853
+ if (typeof i != "string")
854
+ throw new Error("Input must be a string");
855
+ const w = i.length, l = e.length, m = r.length, C = s.length, T = j(n);
856
+ o = 0;
857
+ let y = [], v = [], p = [], k = 0;
858
+ if (!i)
859
+ return S();
860
+ if (c || c !== !1 && i.indexOf(h) === -1) {
861
+ const R = i.split(r);
862
+ for (let D = 0; D < R.length; D++) {
863
+ const O = R[D];
864
+ if (o += O.length, D !== R.length - 1)
865
+ o += r.length;
866
+ else if (g)
867
+ return S();
868
+ if (!(s && O.substr(0, C) === s)) {
869
+ if (T) {
870
+ if (y = [], x(O.split(e)), I(), u)
871
+ return S();
872
+ } else
873
+ x(O.split(e));
874
+ if (a && D >= a)
875
+ return y = y.slice(0, a), S(!0);
876
+ }
877
+ }
878
+ return S();
879
+ }
880
+ let A = i.indexOf(e, o), _ = i.indexOf(r, o);
881
+ const B = new RegExp(q(f) + q(h), "g");
882
+ let b;
883
+ for (; ; ) {
884
+ if (i[o] === h) {
885
+ for (b = o, o++; ; ) {
886
+ if (b = i.indexOf(h, b + 1), b === -1)
887
+ return g || v.push({
888
+ type: "Quotes",
889
+ code: "MissingQuotes",
890
+ message: "Quoted field unterminated",
891
+ row: y.length,
892
+ // row has yet to be inserted
893
+ index: o
894
+ }), H();
895
+ if (b === w - 1) {
896
+ const Ee = i.substring(o, b).replace(B, h);
897
+ return H(Ee);
898
+ }
899
+ if (h === f && i[b + 1] === f) {
900
+ b++;
901
+ continue;
902
+ }
903
+ if (h !== f && b !== 0 && i[b - 1] === f)
904
+ continue;
905
+ const R = _ === -1 ? A : Math.min(A, _), D = K(R);
906
+ if (i[b + 1 + D] === e) {
907
+ if (p.push(i.substring(o, b).replace(B, h)), o = b + 1 + D + l, A = i.indexOf(e, o), _ = i.indexOf(r, o), T && (I(), u))
908
+ return S();
909
+ if (a && y.length >= a)
910
+ return S(!0);
911
+ break;
912
+ }
913
+ const O = K(_);
914
+ if (i.substr(b + 1 + O, m) === r) {
915
+ if (p.push(i.substring(o, b).replace(B, h)), Y(b + 1 + O + m), A = i.indexOf(e, o), T && (I(), u))
916
+ return S();
917
+ if (a && y.length >= a)
918
+ return S(!0);
919
+ break;
920
+ }
921
+ v.push({
922
+ type: "Quotes",
923
+ code: "InvalidQuotes",
924
+ message: "Trailing quote on quoted field is malformed",
925
+ row: y.length,
926
+ // row has yet to be inserted
927
+ index: o
928
+ }), b++;
929
+ }
930
+ if (T && (I(), u))
931
+ return S();
932
+ if (a && y.length >= a)
933
+ return S(!0);
934
+ continue;
935
+ }
936
+ if (s && p.length === 0 && i.substr(o, C) === s) {
937
+ if (_ === -1)
938
+ return S();
939
+ o = _ + m, _ = i.indexOf(r, o), A = i.indexOf(e, o);
940
+ continue;
941
+ }
942
+ if (A !== -1 && (A < _ || _ === -1)) {
943
+ p.push(i.substring(o, A)), o = A + l, A = i.indexOf(e, o);
944
+ continue;
945
+ }
946
+ if (_ !== -1) {
947
+ if (p.push(i.substring(o, _)), Y(_ + m), T && (I(), u))
948
+ return S();
949
+ if (a && y.length >= a)
950
+ return S(!0);
951
+ continue;
952
+ }
953
+ break;
954
+ }
955
+ return H();
956
+ function x(R) {
957
+ y.push(R), k = o;
958
+ }
959
+ function K(R) {
960
+ let D = 0;
961
+ if (R !== -1) {
962
+ const O = i.substring(b + 1, R);
963
+ O && O.trim() === "" && (D = O.length);
964
+ }
965
+ return D;
966
+ }
967
+ function H(R) {
968
+ return g || (typeof R > "u" && (R = i.substr(o)), p.push(R), o = w, x(p), T && I()), S();
969
+ }
970
+ function Y(R) {
971
+ o = R, x(p), p = [], _ = i.indexOf(r, o);
972
+ }
973
+ function S(R, D) {
974
+ return {
975
+ data: D || !1 ? y[0] : y,
976
+ errors: v,
977
+ meta: {
978
+ delimiter: e,
979
+ linebreak: r,
980
+ aborted: u,
981
+ truncated: !!R,
982
+ cursor: k + (d || 0)
983
+ }
984
+ };
985
+ }
986
+ function I() {
987
+ n(S(void 0, !0)), y = [], v = [];
988
+ }
989
+ }, this.abort = function() {
990
+ u = !0;
991
+ }, this.getCharIndex = function() {
992
+ return o;
993
+ };
994
+ }
995
+ function _e(t) {
996
+ if (typeof t != "object" || t === null)
997
+ return t;
998
+ const e = Array.isArray(t) ? [] : {};
999
+ for (const r in t)
1000
+ e[r] = _e(t[r]);
1001
+ return e;
1002
+ }
1003
+ function j(t) {
1004
+ return typeof t == "function";
1005
+ }
1006
+ function wt(t, e = {}) {
1007
+ let r = !1, s = !0, n = ",", a = `\r
1008
+ `, c = '"', h = c + c, f = !1, o = null;
1009
+ i();
1010
+ const u = new RegExp(yt(c), "g");
1011
+ if (typeof t == "string" && (t = JSON.parse(t)), Array.isArray(t)) {
1012
+ if (!t.length || Array.isArray(t[0]))
1013
+ return d(null, t, f);
1014
+ if (typeof t[0] == "object")
1015
+ return d(o || Object.keys(t[0]), t, f);
1016
+ } else if (typeof t == "object")
1017
+ return typeof t.data == "string" && (t.data = JSON.parse(t.data)), Array.isArray(t.data) && (t.fields || (t.fields = t.meta && t.meta.fields), t.fields || (t.fields = Array.isArray(t.data[0]) ? t.fields : Object.keys(t.data[0])), !Array.isArray(t.data[0]) && typeof t.data[0] != "object" && (t.data = [t.data])), d(t.fields || [], t.data || [], f);
1018
+ throw new Error("Unable to serialize unrecognized input");
1019
+ function i() {
1020
+ if (typeof e == "object") {
1021
+ if (typeof e.delimiter == "string" && !F.BAD_DELIMITERS.filter(function(l) {
1022
+ return e.delimiter?.indexOf(l) !== -1;
1023
+ }).length && (n = e.delimiter), (typeof e.quotes == "boolean" || Array.isArray(e.quotes)) && (r = e.quotes), (typeof e.skipEmptyLines == "boolean" || e.skipEmptyLines === "greedy") && (f = e.skipEmptyLines), typeof e.newline == "string" && (a = e.newline), typeof e.quoteChar == "string" && (c = e.quoteChar), typeof e.header == "boolean" && (s = e.header), Array.isArray(e.columns)) {
1024
+ if (e.columns.length === 0)
1025
+ throw new Error("Option columns is empty");
1026
+ o = e.columns;
1027
+ }
1028
+ e.escapeChar !== void 0 && (h = e.escapeChar + c);
1029
+ }
1030
+ }
1031
+ function d(l, m, C) {
1032
+ let T = "";
1033
+ typeof l == "string" && (l = JSON.parse(l)), typeof m == "string" && (m = JSON.parse(m));
1034
+ const y = Array.isArray(l) && l.length > 0, v = !Array.isArray(m[0]);
1035
+ if (y && s) {
1036
+ for (let p = 0; p < l.length; p++)
1037
+ p > 0 && (T += n), T += g(l[p], p);
1038
+ m.length > 0 && (T += a);
1039
+ }
1040
+ for (let p = 0; p < m.length; p++) {
1041
+ const k = y ? l.length : m[p].length;
1042
+ let A = !1;
1043
+ const _ = y ? Object.keys(m[p]).length === 0 : m[p].length === 0;
1044
+ if (C && !y && (A = C === "greedy" ? m[p].join("").trim() === "" : m[p].length === 1 && m[p][0].length === 0), C === "greedy" && y) {
1045
+ const B = [];
1046
+ for (let b = 0; b < k; b++) {
1047
+ const x = v ? l[b] : b;
1048
+ B.push(m[p][x]);
1049
+ }
1050
+ A = B.join("").trim() === "";
1051
+ }
1052
+ if (!A) {
1053
+ for (let B = 0; B < k; B++) {
1054
+ B > 0 && !_ && (T += n);
1055
+ const b = y && v ? l[B] : B;
1056
+ T += g(m[p][b], B);
1057
+ }
1058
+ p < m.length - 1 && (!C || k > 0 && !_) && (T += a);
1059
+ }
1060
+ }
1061
+ return T;
1062
+ }
1063
+ function g(l, m) {
1064
+ return typeof l > "u" || l === null ? "" : l.constructor === Date ? JSON.stringify(l).slice(1, 25) : (l = l.toString().replace(u, h), typeof r == "boolean" && r || Array.isArray(r) && r[m] || w(l, F.BAD_DELIMITERS) || l.indexOf(n) > -1 || l.charAt(0) === " " || l.charAt(l.length - 1) === " " ? c + l + c : l);
1065
+ }
1066
+ function w(l, m) {
1067
+ for (let C = 0; C < m.length; C++)
1068
+ if (l.indexOf(m[C]) > -1)
1069
+ return !0;
1070
+ return !1;
1071
+ }
1072
+ }
1073
+ function yt(t) {
1074
+ return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1075
+ }
1076
+ const $ = {
1077
+ ...F,
1078
+ parse: ft,
1079
+ unparse: wt,
1080
+ ChunkStreamer: ye,
1081
+ // Exposed for testing and development only
1082
+ Parser: W,
1083
+ ParserHandle: be
1084
+ }, { ChunkStreamer: bt } = $;
1085
+ class _t extends bt {
1086
+ textDecoder = new TextDecoder(this._config.encoding);
1087
+ constructor(e = {}) {
1088
+ super(e);
1089
+ }
1090
+ // Implement ChunkStreamer base class methods
1091
+ // this.pause = function() {
1092
+ // ChunkStreamer.prototype.pause.apply(this, arguments);
1093
+ // };
1094
+ // this.resume = function() {
1095
+ // ChunkStreamer.prototype.resume.apply(this, arguments);
1096
+ // this._input.resume();
1097
+ // };
1098
+ async stream(e) {
1099
+ this._input = e;
1100
+ try {
1101
+ for await (const r of e)
1102
+ this.parseChunk(this.getStringChunk(r));
1103
+ this._finished = !0, this.parseChunk("");
1104
+ } catch (r) {
1105
+ this._sendError(r);
1106
+ }
1107
+ }
1108
+ _nextChunk() {
1109
+ }
1110
+ // HELPER METHODS
1111
+ getStringChunk(e) {
1112
+ return typeof e == "string" ? e : this.textDecoder.decode(e, { stream: !0 });
1113
+ }
1114
+ }
1115
+ const Ce = {
1116
+ id: "csv",
1117
+ module: "csv",
1118
+ name: "CSV",
1119
+ extensions: ["csv", "tsv", "dsv"],
1120
+ mimeTypes: ["text/csv", "text/tab-separated-values", "text/dsv"],
1121
+ category: "table"
1122
+ }, Ct = "4.4.3", Z = "object-row-table", U = {
1123
+ ...Ce,
1124
+ dataType: null,
1125
+ batchType: null,
1126
+ version: Ct,
1127
+ parse: async (t, e) => se(new TextDecoder().decode(t), e),
1128
+ parseText: (t, e) => se(t, e),
1129
+ parseInBatches: At,
1130
+ // @ts-ignore
1131
+ // testText: null,
1132
+ options: {
1133
+ csv: {
1134
+ shape: Z,
1135
+ // 'object-row-table'
1136
+ optimizeMemoryUsage: !1,
1137
+ // CSV options
1138
+ header: "auto",
1139
+ columnPrefix: "column",
1140
+ // delimiter: auto
1141
+ // newline: auto
1142
+ quoteChar: '"',
1143
+ escapeChar: '"',
1144
+ dynamicTyping: !0,
1145
+ comments: !1,
1146
+ skipEmptyLines: !0,
1147
+ // transform: null?
1148
+ delimitersToGuess: [",", " ", "|", ";"]
1149
+ // fastMode: auto
1150
+ }
1151
+ }
1152
+ };
1153
+ async function se(t, e) {
1154
+ const r = { ...U.options.csv, ...e?.csv }, s = Tt(t), a = r.header === "auto" ? Ae(s) : !!r.header, c = {
1155
+ // dynamicTyping: true,
1156
+ ...r,
1157
+ header: a,
1158
+ download: !1,
1159
+ // We handle loading, no need for papaparse to do it for us
1160
+ transformHeader: a ? Te() : void 0,
1161
+ error: (d) => {
1162
+ throw new Error(d);
1163
+ }
1164
+ }, h = $.parse(t, c), f = h.data, o = h.meta.fields || Re(r.columnPrefix, s.length), u = r.shape || Z;
1165
+ let i;
1166
+ switch (u) {
1167
+ case "object-row-table":
1168
+ i = {
1169
+ shape: "object-row-table",
1170
+ data: f.map((d) => Array.isArray(d) ? pe(d, o) : d)
1171
+ };
1172
+ break;
1173
+ case "array-row-table":
1174
+ i = {
1175
+ shape: "array-row-table",
1176
+ data: f.map((d) => Array.isArray(d) ? d : ge(d, o))
1177
+ };
1178
+ break;
1179
+ default:
1180
+ throw new Error(u);
1181
+ }
1182
+ return i.schema = de(i), i;
1183
+ }
1184
+ function At(t, e) {
1185
+ e = { ...e }, e?.core?.batchSize === "auto" && (e.core.batchSize = 4e3);
1186
+ const r = { ...U.options.csv, ...e?.csv }, s = new ut();
1187
+ let n = !0, a = null, c = null, h = null;
1188
+ const f = {
1189
+ // dynamicTyping: true, // Convert numbers and boolean values in rows from strings,
1190
+ ...r,
1191
+ header: !1,
1192
+ // Unfortunately, header detection is not automatic and does not infer shapes
1193
+ download: !1,
1194
+ // We handle loading, no need for papaparse to do it for us
1195
+ // chunkSize is set to 5MB explicitly (same as Papaparse default) due to a bug where the
1196
+ // streaming parser gets stuck if skipEmptyLines and a step callback are both supplied.
1197
+ // See https://github.com/mholt/PapaParse/issues/465
1198
+ chunkSize: 1024 * 1024 * 5,
1199
+ // skipEmptyLines is set to a boolean value if supplied. Greedy is set to true
1200
+ // skipEmptyLines is handled manually given two bugs where the streaming parser gets stuck if
1201
+ // both of the skipEmptyLines and step callback options are provided:
1202
+ // - true doesn't work unless chunkSize is set: https://github.com/mholt/PapaParse/issues/465
1203
+ // - greedy doesn't work: https://github.com/mholt/PapaParse/issues/825
1204
+ skipEmptyLines: !1,
1205
+ // step is called on every row
1206
+ // eslint-disable-next-line complexity, max-statements
1207
+ step(o) {
1208
+ let u = o.data;
1209
+ if (r.skipEmptyLines && u.flat().join("").trim() === "")
1210
+ return;
1211
+ const i = o.meta.cursor;
1212
+ if (n && !a && (r.header === "auto" ? Ae(u) : !!r.header)) {
1213
+ a = u.map(Te());
1214
+ return;
1215
+ }
1216
+ n && (n = !1, a || (a = Re(r.columnPrefix, u.length)), h = Rt(u, a)), r.optimizeMemoryUsage && (u = JSON.parse(JSON.stringify(u)));
1217
+ const d = e?.shape || r.shape || Z;
1218
+ c = c || new ht(
1219
+ // @ts-expect-error TODO this is not a proper schema
1220
+ h,
1221
+ {
1222
+ shape: d,
1223
+ ...e?.core || {}
1224
+ }
1225
+ );
1226
+ try {
1227
+ c.addRow(u);
1228
+ const g = c && c.getFullBatch({ bytesUsed: i });
1229
+ g && s.enqueue(g);
1230
+ } catch (g) {
1231
+ s.enqueue(g);
1232
+ }
1233
+ },
1234
+ // complete is called when all rows have been read
1235
+ complete(o) {
1236
+ try {
1237
+ const u = o.meta.cursor, i = c && c.getFinalBatch({ bytesUsed: u });
1238
+ i && s.enqueue(i);
1239
+ } catch (u) {
1240
+ s.enqueue(u);
1241
+ }
1242
+ s.close();
1243
+ }
1244
+ };
1245
+ return $.parse(Oe(t), f, _t), s;
1246
+ }
1247
+ function Ae(t) {
1248
+ return t && t.every((e) => typeof e == "string");
1249
+ }
1250
+ function Tt(t) {
1251
+ return $.parse(t, {
1252
+ dynamicTyping: !0,
1253
+ preview: 1
1254
+ }).data[0];
1255
+ }
1256
+ function Te() {
1257
+ const t = /* @__PURE__ */ new Set();
1258
+ return (e) => {
1259
+ let r = e, s = 1;
1260
+ for (; t.has(r); )
1261
+ r = `${e}.${s}`, s++;
1262
+ return t.add(r), r;
1263
+ };
1264
+ }
1265
+ function Re(t, e = 0) {
1266
+ const r = [];
1267
+ for (let s = 0; s < e; s++)
1268
+ r.push(`${t}${s + 1}`);
1269
+ return r;
1270
+ }
1271
+ function Rt(t, e) {
1272
+ const r = [];
1273
+ for (let s = 0; s < t.length; s++) {
1274
+ const n = e && e[s] || s, a = t[s];
1275
+ switch (typeof a) {
1276
+ case "number":
1277
+ r.push({ name: String(n), type: "float64", nullable: !0 });
1278
+ break;
1279
+ case "boolean":
1280
+ r.push({ name: String(n), type: "bool", nullable: !0 });
1281
+ break;
1282
+ case "string":
1283
+ r.push({ name: String(n), type: "utf8", nullable: !0 });
1284
+ break;
1285
+ default:
1286
+ ke.warn(`CSV: Unknown column type: ${typeof a}`)(), r.push({ name: String(n), type: "utf8", nullable: !0 });
1287
+ }
1288
+ }
1289
+ return {
1290
+ fields: r,
1291
+ metadata: {
1292
+ "loaders.gl#format": "csv",
1293
+ "loaders.gl#loader": "CSVLoader"
1294
+ }
1295
+ };
1296
+ }
1297
+ var ne = {}, P = {}, z = 34, N = 10, Q = 13;
1298
+ function Se(t) {
1299
+ return new Function("d", "return {" + t.map(function(e, r) {
1300
+ return JSON.stringify(e) + ": d[" + r + '] || ""';
1301
+ }).join(",") + "}");
1302
+ }
1303
+ function St(t, e) {
1304
+ var r = Se(t);
1305
+ return function(s, n) {
1306
+ return e(r(s), n, t);
1307
+ };
1308
+ }
1309
+ function ie(t) {
1310
+ var e = /* @__PURE__ */ Object.create(null), r = [];
1311
+ return t.forEach(function(s) {
1312
+ for (var n in s)
1313
+ n in e || r.push(e[n] = n);
1314
+ }), r;
1315
+ }
1316
+ function E(t, e) {
1317
+ var r = t + "", s = r.length;
1318
+ return s < e ? new Array(e - s + 1).join(0) + r : r;
1319
+ }
1320
+ function Et(t) {
1321
+ return t < 0 ? "-" + E(-t, 6) : t > 9999 ? "+" + E(t, 6) : E(t, 4);
1322
+ }
1323
+ function Bt(t) {
1324
+ var e = t.getUTCHours(), r = t.getUTCMinutes(), s = t.getUTCSeconds(), n = t.getUTCMilliseconds();
1325
+ return isNaN(t) ? "Invalid Date" : Et(t.getUTCFullYear()) + "-" + E(t.getUTCMonth() + 1, 2) + "-" + E(t.getUTCDate(), 2) + (n ? "T" + E(e, 2) + ":" + E(r, 2) + ":" + E(s, 2) + "." + E(n, 3) + "Z" : s ? "T" + E(e, 2) + ":" + E(r, 2) + ":" + E(s, 2) + "Z" : r || e ? "T" + E(e, 2) + ":" + E(r, 2) + "Z" : "");
1326
+ }
1327
+ function Dt(t) {
1328
+ var e = new RegExp('["' + t + `
1329
+ \r]`), r = t.charCodeAt(0);
1330
+ function s(i, d) {
1331
+ var g, w, l = n(i, function(m, C) {
1332
+ if (g) return g(m, C - 1);
1333
+ w = m, g = d ? St(m, d) : Se(m);
1334
+ });
1335
+ return l.columns = w || [], l;
1336
+ }
1337
+ function n(i, d) {
1338
+ var g = [], w = i.length, l = 0, m = 0, C, T = w <= 0, y = !1;
1339
+ i.charCodeAt(w - 1) === N && --w, i.charCodeAt(w - 1) === Q && --w;
1340
+ function v() {
1341
+ if (T) return P;
1342
+ if (y) return y = !1, ne;
1343
+ var k, A = l, _;
1344
+ if (i.charCodeAt(A) === z) {
1345
+ for (; l++ < w && i.charCodeAt(l) !== z || i.charCodeAt(++l) === z; ) ;
1346
+ return (k = l) >= w ? T = !0 : (_ = i.charCodeAt(l++)) === N ? y = !0 : _ === Q && (y = !0, i.charCodeAt(l) === N && ++l), i.slice(A + 1, k - 1).replace(/""/g, '"');
1347
+ }
1348
+ for (; l < w; ) {
1349
+ if ((_ = i.charCodeAt(k = l++)) === N) y = !0;
1350
+ else if (_ === Q)
1351
+ y = !0, i.charCodeAt(l) === N && ++l;
1352
+ else if (_ !== r) continue;
1353
+ return i.slice(A, k);
1354
+ }
1355
+ return T = !0, i.slice(A, w);
1356
+ }
1357
+ for (; (C = v()) !== P; ) {
1358
+ for (var p = []; C !== ne && C !== P; ) p.push(C), C = v();
1359
+ d && (p = d(p, m++)) == null || g.push(p);
1360
+ }
1361
+ return g;
1362
+ }
1363
+ function a(i, d) {
1364
+ return i.map(function(g) {
1365
+ return d.map(function(w) {
1366
+ return u(g[w]);
1367
+ }).join(t);
1368
+ });
1369
+ }
1370
+ function c(i, d) {
1371
+ return d == null && (d = ie(i)), [d.map(u).join(t)].concat(a(i, d)).join(`
1372
+ `);
1373
+ }
1374
+ function h(i, d) {
1375
+ return d == null && (d = ie(i)), a(i, d).join(`
1376
+ `);
1377
+ }
1378
+ function f(i) {
1379
+ return i.map(o).join(`
1380
+ `);
1381
+ }
1382
+ function o(i) {
1383
+ return i.map(u).join(t);
1384
+ }
1385
+ function u(i) {
1386
+ return i == null ? "" : i instanceof Date ? Bt(i) : e.test(i += "") ? '"' + i.replace(/"/g, '""') + '"' : i;
1387
+ }
1388
+ return {
1389
+ parse: s,
1390
+ parseRows: n,
1391
+ format: c,
1392
+ formatBody: h,
1393
+ formatRows: f,
1394
+ formatRow: o,
1395
+ formatValue: u
1396
+ };
1397
+ }
1398
+ var Ot = Dt(","), kt = Ot.formatRows;
1399
+ function ae(t, e = { csv: { useDisplayNames: !0 } }) {
1400
+ const r = e.useDisplayNames || e.csv?.useDisplayNames, a = [(t.schema?.fields || []).map((h) => {
1401
+ const f = h.metadata?.displayName;
1402
+ return r && typeof f == "string" ? f : h.name;
1403
+ })];
1404
+ for (const h of Ve(t)) {
1405
+ const f = [];
1406
+ for (let o = 0; o < fe(t); ++o) {
1407
+ const u = h[o];
1408
+ f[o] = vt(u);
1409
+ }
1410
+ a.push(f);
1411
+ }
1412
+ const c = a.map((h) => h.map((f) => f === null ? "" : f));
1413
+ return kt(c);
1414
+ }
1415
+ const vt = (t) => t == null ? null : t instanceof Date ? t.toISOString() : typeof t == "object" ? JSON.stringify(t) : String(t), Ut = {
1416
+ ...Ce,
1417
+ version: "latest",
1418
+ options: {
1419
+ csv: {
1420
+ useDisplayNames: !1
1421
+ }
1422
+ },
1423
+ text: !0,
1424
+ encode: async (t, e) => new TextEncoder().encode(ae(t, e)).buffer,
1425
+ encodeTextSync: (t, e) => ae(t, e)
1426
+ }, Mt = {
1427
+ ...U,
1428
+ dataType: null,
1429
+ batchType: null,
1430
+ parse: async (t, e) => oe(new TextDecoder().decode(t), e),
1431
+ parseText: (t, e) => oe(t, e),
1432
+ parseInBatches: Ft
1433
+ };
1434
+ async function oe(t, e) {
1435
+ const r = await U.parseText(t, e);
1436
+ return L(r, "arrow-table");
1437
+ }
1438
+ function Ft(t, e) {
1439
+ const r = U.parseInBatches(t, e);
1440
+ return rt(r, "arrow-table");
1441
+ }
1442
+ export {
1443
+ Mt as CSVArrowLoader,
1444
+ U as CSVLoader,
1445
+ Ut as CSVWriter
1446
+ };