@loaders.gl/json 4.0.0-alpha.4 → 4.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/dist.min.js +2543 -0
  4. package/dist/geojson-loader.d.ts +16 -0
  5. package/dist/geojson-loader.d.ts.map +1 -0
  6. package/dist/geojson-loader.js +1 -1
  7. package/dist/geojson-worker.js +782 -181
  8. package/dist/index.d.ts +9 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +1 -0
  11. package/dist/index.js.map +1 -1
  12. package/dist/json-loader.d.ts +14 -0
  13. package/dist/json-loader.d.ts.map +1 -0
  14. package/dist/json-loader.js +1 -1
  15. package/dist/jsonl-loader.d.ts +1 -0
  16. package/dist/jsonl-loader.d.ts.map +1 -0
  17. package/dist/lib/clarinet/clarinet.d.ts +74 -0
  18. package/dist/lib/clarinet/clarinet.d.ts.map +1 -0
  19. package/dist/lib/jsonpath/jsonpath.d.ts +32 -0
  20. package/dist/lib/jsonpath/jsonpath.d.ts.map +1 -0
  21. package/dist/lib/parse-json-in-batches.d.ts +5 -0
  22. package/dist/lib/parse-json-in-batches.d.ts.map +1 -0
  23. package/dist/lib/parse-json-in-batches.js +18 -1
  24. package/dist/lib/parse-json-in-batches.js.map +1 -1
  25. package/dist/lib/parse-json.d.ts +3 -0
  26. package/dist/lib/parse-json.d.ts.map +1 -0
  27. package/dist/lib/parse-ndjson-in-batches.d.ts +4 -0
  28. package/dist/lib/parse-ndjson-in-batches.d.ts.map +1 -0
  29. package/dist/lib/parse-ndjson.d.ts +2 -0
  30. package/dist/lib/parse-ndjson.d.ts.map +1 -0
  31. package/dist/lib/parser/json-parser.d.ts +22 -0
  32. package/dist/lib/parser/json-parser.d.ts.map +1 -0
  33. package/dist/lib/parser/streaming-json-parser.d.ts +37 -0
  34. package/dist/lib/parser/streaming-json-parser.d.ts.map +1 -0
  35. package/dist/ndjson-loader.d.ts +22 -0
  36. package/dist/ndjson-loader.d.ts.map +1 -0
  37. package/dist/ndjson-loader.js +1 -1
  38. package/dist/workers/geojson-worker.d.ts +2 -0
  39. package/dist/workers/geojson-worker.d.ts.map +1 -0
  40. package/package.json +8 -8
  41. package/src/index.ts +2 -0
  42. package/src/lib/parse-json-in-batches.ts +23 -1
@@ -0,0 +1,2543 @@
1
+ (() => {
2
+ var __defProp = Object.defineProperty;
3
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
4
+ var __esm = (fn, res) => function __init() {
5
+ return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
6
+ };
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __export = (target, all) => {
11
+ __markAsModule(target);
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+
16
+ // src/lib/parse-json.ts
17
+ function parseJSONSync(jsonText, options) {
18
+ try {
19
+ const json = JSON.parse(jsonText);
20
+ if (options.json?.table) {
21
+ return getFirstArray(json) || json;
22
+ }
23
+ return json;
24
+ } catch (error) {
25
+ throw new Error("JSONLoader: failed to parse JSON");
26
+ }
27
+ }
28
+ function getFirstArray(json) {
29
+ if (Array.isArray(json)) {
30
+ return json;
31
+ }
32
+ if (json && typeof json === "object") {
33
+ for (const value of Object.values(json)) {
34
+ const array = getFirstArray(value);
35
+ if (array) {
36
+ return array;
37
+ }
38
+ }
39
+ }
40
+ return null;
41
+ }
42
+ var init_parse_json = __esm({
43
+ "src/lib/parse-json.ts"() {
44
+ }
45
+ });
46
+
47
+ // ../schema/src/lib/batches/base-table-batch-aggregator.ts
48
+ var DEFAULT_ROW_COUNT, RowTableBatchAggregator;
49
+ var init_base_table_batch_aggregator = __esm({
50
+ "../schema/src/lib/batches/base-table-batch-aggregator.ts"() {
51
+ DEFAULT_ROW_COUNT = 100;
52
+ RowTableBatchAggregator = class {
53
+ constructor(schema, options) {
54
+ this.length = 0;
55
+ this.rows = null;
56
+ this.cursor = 0;
57
+ this._headers = [];
58
+ this.options = options;
59
+ this.schema = schema;
60
+ if (!Array.isArray(schema)) {
61
+ this._headers = [];
62
+ for (const key in schema) {
63
+ this._headers[schema[key].index] = schema[key].name;
64
+ }
65
+ }
66
+ }
67
+ rowCount() {
68
+ return this.length;
69
+ }
70
+ addArrayRow(row, cursor) {
71
+ if (Number.isFinite(cursor)) {
72
+ this.cursor = cursor;
73
+ }
74
+ this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
75
+ this.rows[this.length] = row;
76
+ this.length++;
77
+ }
78
+ addObjectRow(row, cursor) {
79
+ if (Number.isFinite(cursor)) {
80
+ this.cursor = cursor;
81
+ }
82
+ this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
83
+ this.rows[this.length] = row;
84
+ this.length++;
85
+ }
86
+ getBatch() {
87
+ let rows = this.rows;
88
+ if (!rows) {
89
+ return null;
90
+ }
91
+ rows = rows.slice(0, this.length);
92
+ this.rows = null;
93
+ const batch = {
94
+ shape: this.options.shape,
95
+ batchType: "data",
96
+ data: rows,
97
+ length: this.length,
98
+ schema: this.schema,
99
+ cursor: this.cursor
100
+ };
101
+ return batch;
102
+ }
103
+ };
104
+ }
105
+ });
106
+
107
+ // ../schema/src/lib/utils/row-utils.ts
108
+ function convertToObjectRow(arrayRow, headers) {
109
+ if (!arrayRow) {
110
+ throw new Error("null row");
111
+ }
112
+ if (!headers) {
113
+ throw new Error("no headers");
114
+ }
115
+ const objectRow = {};
116
+ for (let i = 0; i < headers.length; i++) {
117
+ objectRow[headers[i]] = arrayRow[i];
118
+ }
119
+ return objectRow;
120
+ }
121
+ function convertToArrayRow(objectRow, headers) {
122
+ if (!objectRow) {
123
+ throw new Error("null row");
124
+ }
125
+ if (!headers) {
126
+ throw new Error("no headers");
127
+ }
128
+ const arrayRow = new Array(headers.length);
129
+ for (let i = 0; i < headers.length; i++) {
130
+ arrayRow[i] = objectRow[headers[i]];
131
+ }
132
+ return arrayRow;
133
+ }
134
+ var init_row_utils = __esm({
135
+ "../schema/src/lib/utils/row-utils.ts"() {
136
+ }
137
+ });
138
+
139
+ // ../schema/src/lib/batches/row-table-batch-aggregator.ts
140
+ var DEFAULT_ROW_COUNT2, RowTableBatchAggregator2;
141
+ var init_row_table_batch_aggregator = __esm({
142
+ "../schema/src/lib/batches/row-table-batch-aggregator.ts"() {
143
+ init_row_utils();
144
+ DEFAULT_ROW_COUNT2 = 100;
145
+ RowTableBatchAggregator2 = class {
146
+ constructor(schema, options) {
147
+ this.length = 0;
148
+ this.objectRows = null;
149
+ this.arrayRows = null;
150
+ this.cursor = 0;
151
+ this._headers = [];
152
+ this.options = options;
153
+ this.schema = schema;
154
+ if (!Array.isArray(schema)) {
155
+ this._headers = [];
156
+ for (const key in schema) {
157
+ this._headers[schema[key].index] = schema[key].name;
158
+ }
159
+ }
160
+ }
161
+ rowCount() {
162
+ return this.length;
163
+ }
164
+ addArrayRow(row, cursor) {
165
+ if (Number.isFinite(cursor)) {
166
+ this.cursor = cursor;
167
+ }
168
+ switch (this.options.shape) {
169
+ case "object-row-table":
170
+ const rowObject = convertToObjectRow(row, this._headers);
171
+ this.addObjectRow(rowObject, cursor);
172
+ break;
173
+ case "array-row-table":
174
+ this.arrayRows = this.arrayRows || new Array(DEFAULT_ROW_COUNT2);
175
+ this.arrayRows[this.length] = row;
176
+ this.length++;
177
+ break;
178
+ }
179
+ }
180
+ addObjectRow(row, cursor) {
181
+ if (Number.isFinite(cursor)) {
182
+ this.cursor = cursor;
183
+ }
184
+ switch (this.options.shape) {
185
+ case "array-row-table":
186
+ const rowArray = convertToArrayRow(row, this._headers);
187
+ this.addArrayRow(rowArray, cursor);
188
+ break;
189
+ case "object-row-table":
190
+ this.objectRows = this.objectRows || new Array(DEFAULT_ROW_COUNT2);
191
+ this.objectRows[this.length] = row;
192
+ this.length++;
193
+ break;
194
+ }
195
+ }
196
+ getBatch() {
197
+ let rows = this.arrayRows || this.objectRows;
198
+ if (!rows) {
199
+ return null;
200
+ }
201
+ rows = rows.slice(0, this.length);
202
+ this.arrayRows = null;
203
+ this.objectRows = null;
204
+ return {
205
+ shape: this.options.shape,
206
+ batchType: "data",
207
+ data: rows,
208
+ length: this.length,
209
+ schema: this.schema,
210
+ cursor: this.cursor
211
+ };
212
+ }
213
+ };
214
+ }
215
+ });
216
+
217
+ // ../schema/src/lib/batches/columnar-table-batch-aggregator.ts
218
+ var DEFAULT_ROW_COUNT3, ColumnarTableBatchAggregator;
219
+ var init_columnar_table_batch_aggregator = __esm({
220
+ "../schema/src/lib/batches/columnar-table-batch-aggregator.ts"() {
221
+ DEFAULT_ROW_COUNT3 = 100;
222
+ ColumnarTableBatchAggregator = class {
223
+ constructor(schema, options) {
224
+ this.length = 0;
225
+ this.allocated = 0;
226
+ this.columns = {};
227
+ this.schema = schema;
228
+ this._reallocateColumns();
229
+ }
230
+ rowCount() {
231
+ return this.length;
232
+ }
233
+ addArrayRow(row) {
234
+ this._reallocateColumns();
235
+ let i = 0;
236
+ for (const fieldName in this.columns) {
237
+ this.columns[fieldName][this.length] = row[i++];
238
+ }
239
+ this.length++;
240
+ }
241
+ addObjectRow(row) {
242
+ this._reallocateColumns();
243
+ for (const fieldName in row) {
244
+ this.columns[fieldName][this.length] = row[fieldName];
245
+ }
246
+ this.length++;
247
+ }
248
+ getBatch() {
249
+ this._pruneColumns();
250
+ const columns = Array.isArray(this.schema) ? this.columns : {};
251
+ if (!Array.isArray(this.schema)) {
252
+ for (const fieldName in this.schema) {
253
+ const field = this.schema[fieldName];
254
+ columns[field.name] = this.columns[field.index];
255
+ }
256
+ }
257
+ this.columns = {};
258
+ const batch = {
259
+ shape: "columnar-table",
260
+ batchType: "data",
261
+ data: columns,
262
+ schema: this.schema,
263
+ length: this.length
264
+ };
265
+ return batch;
266
+ }
267
+ _reallocateColumns() {
268
+ if (this.length < this.allocated) {
269
+ return;
270
+ }
271
+ this.allocated = this.allocated > 0 ? this.allocated *= 2 : DEFAULT_ROW_COUNT3;
272
+ this.columns = {};
273
+ for (const fieldName in this.schema) {
274
+ const field = this.schema[fieldName];
275
+ const ArrayType = field.type || Float32Array;
276
+ const oldColumn = this.columns[field.index];
277
+ if (oldColumn && ArrayBuffer.isView(oldColumn)) {
278
+ const typedArray = new ArrayType(this.allocated);
279
+ typedArray.set(oldColumn);
280
+ this.columns[field.index] = typedArray;
281
+ } else if (oldColumn) {
282
+ oldColumn.length = this.allocated;
283
+ this.columns[field.index] = oldColumn;
284
+ } else {
285
+ this.columns[field.index] = new ArrayType(this.allocated);
286
+ }
287
+ }
288
+ }
289
+ _pruneColumns() {
290
+ for (const [columnName, column] of Object.entries(this.columns)) {
291
+ this.columns[columnName] = column.slice(0, this.length);
292
+ }
293
+ }
294
+ };
295
+ }
296
+ });
297
+
298
+ // ../schema/src/lib/batches/table-batch-builder.ts
299
+ var DEFAULT_OPTIONS, ERR_MESSAGE, TableBatchBuilder;
300
+ var init_table_batch_builder = __esm({
301
+ "../schema/src/lib/batches/table-batch-builder.ts"() {
302
+ init_base_table_batch_aggregator();
303
+ init_row_table_batch_aggregator();
304
+ init_columnar_table_batch_aggregator();
305
+ DEFAULT_OPTIONS = {
306
+ shape: "array-row-table",
307
+ batchSize: "auto",
308
+ batchDebounceMs: 0,
309
+ limit: 0,
310
+ _limitMB: 0
311
+ };
312
+ ERR_MESSAGE = "TableBatchBuilder";
313
+ TableBatchBuilder = class {
314
+ constructor(schema, options) {
315
+ this.aggregator = null;
316
+ this.batchCount = 0;
317
+ this.bytesUsed = 0;
318
+ this.isChunkComplete = false;
319
+ this.lastBatchEmittedMs = Date.now();
320
+ this.totalLength = 0;
321
+ this.totalBytes = 0;
322
+ this.rowBytes = 0;
323
+ this.schema = schema;
324
+ this.options = { ...DEFAULT_OPTIONS, ...options };
325
+ }
326
+ limitReached() {
327
+ if (Boolean(this.options?.limit) && this.totalLength >= this.options.limit) {
328
+ return true;
329
+ }
330
+ if (Boolean(this.options?._limitMB) && this.totalBytes / 1e6 >= this.options._limitMB) {
331
+ return true;
332
+ }
333
+ return false;
334
+ }
335
+ addRow(row) {
336
+ if (this.limitReached()) {
337
+ return;
338
+ }
339
+ this.totalLength++;
340
+ this.rowBytes = this.rowBytes || this._estimateRowMB(row);
341
+ this.totalBytes += this.rowBytes;
342
+ if (Array.isArray(row)) {
343
+ this.addArrayRow(row);
344
+ } else {
345
+ this.addObjectRow(row);
346
+ }
347
+ }
348
+ addArrayRow(row) {
349
+ if (!this.aggregator) {
350
+ const TableBatchType = this._getTableBatchType();
351
+ this.aggregator = new TableBatchType(this.schema, this.options);
352
+ }
353
+ this.aggregator.addArrayRow(row);
354
+ }
355
+ addObjectRow(row) {
356
+ if (!this.aggregator) {
357
+ const TableBatchType = this._getTableBatchType();
358
+ this.aggregator = new TableBatchType(this.schema, this.options);
359
+ }
360
+ this.aggregator.addObjectRow(row);
361
+ }
362
+ chunkComplete(chunk) {
363
+ if (chunk instanceof ArrayBuffer) {
364
+ this.bytesUsed += chunk.byteLength;
365
+ }
366
+ if (typeof chunk === "string") {
367
+ this.bytesUsed += chunk.length;
368
+ }
369
+ this.isChunkComplete = true;
370
+ }
371
+ getFullBatch(options) {
372
+ return this._isFull() ? this._getBatch(options) : null;
373
+ }
374
+ getFinalBatch(options) {
375
+ return this._getBatch(options);
376
+ }
377
+ _estimateRowMB(row) {
378
+ return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
379
+ }
380
+ _isFull() {
381
+ if (!this.aggregator || this.aggregator.rowCount() === 0) {
382
+ return false;
383
+ }
384
+ if (this.options.batchSize === "auto") {
385
+ if (!this.isChunkComplete) {
386
+ return false;
387
+ }
388
+ } else if (this.options.batchSize > this.aggregator.rowCount()) {
389
+ return false;
390
+ }
391
+ if (this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs) {
392
+ return false;
393
+ }
394
+ this.isChunkComplete = false;
395
+ this.lastBatchEmittedMs = Date.now();
396
+ return true;
397
+ }
398
+ _getBatch(options) {
399
+ if (!this.aggregator) {
400
+ return null;
401
+ }
402
+ if (options?.bytesUsed) {
403
+ this.bytesUsed = options.bytesUsed;
404
+ }
405
+ const normalizedBatch = this.aggregator.getBatch();
406
+ normalizedBatch.count = this.batchCount;
407
+ normalizedBatch.bytesUsed = this.bytesUsed;
408
+ Object.assign(normalizedBatch, options);
409
+ this.batchCount++;
410
+ this.aggregator = null;
411
+ return normalizedBatch;
412
+ }
413
+ _getTableBatchType() {
414
+ switch (this.options.shape) {
415
+ case "row-table":
416
+ return RowTableBatchAggregator;
417
+ case "array-row-table":
418
+ case "object-row-table":
419
+ return RowTableBatchAggregator2;
420
+ case "columnar-table":
421
+ return ColumnarTableBatchAggregator;
422
+ case "arrow-table":
423
+ if (!TableBatchBuilder.ArrowBatch) {
424
+ throw new Error(ERR_MESSAGE);
425
+ }
426
+ return TableBatchBuilder.ArrowBatch;
427
+ default:
428
+ throw new Error(ERR_MESSAGE);
429
+ }
430
+ }
431
+ };
432
+ }
433
+ });
434
+
435
+ // ../schema/src/index.ts
436
+ var init_src = __esm({
437
+ "../schema/src/index.ts"() {
438
+ init_table_batch_builder();
439
+ }
440
+ });
441
+
442
+ // ../loader-utils/src/lib/env-utils/assert.ts
443
+ function assert(condition, message) {
444
+ if (!condition) {
445
+ throw new Error(message || "loader assertion failed.");
446
+ }
447
+ }
448
+ var init_assert = __esm({
449
+ "../loader-utils/src/lib/env-utils/assert.ts"() {
450
+ }
451
+ });
452
+
453
+ // ../loader-utils/src/lib/iterators/text-iterators.ts
454
+ async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
455
+ const textDecoder = new TextDecoder(void 0, options);
456
+ for await (const arrayBuffer of arrayBufferIterator) {
457
+ yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
458
+ }
459
+ }
460
+ async function* makeLineIterator(textIterator) {
461
+ let previous = "";
462
+ for await (const textChunk of textIterator) {
463
+ previous += textChunk;
464
+ let eolIndex;
465
+ while ((eolIndex = previous.indexOf("\n")) >= 0) {
466
+ const line = previous.slice(0, eolIndex + 1);
467
+ previous = previous.slice(eolIndex + 1);
468
+ yield line;
469
+ }
470
+ }
471
+ if (previous.length > 0) {
472
+ yield previous;
473
+ }
474
+ }
475
+ async function* makeNumberedLineIterator(lineIterator) {
476
+ let counter = 1;
477
+ for await (const line of lineIterator) {
478
+ yield { counter, line };
479
+ counter++;
480
+ }
481
+ }
482
+ var init_text_iterators = __esm({
483
+ "../loader-utils/src/lib/iterators/text-iterators.ts"() {
484
+ }
485
+ });
486
+
487
+ // ../loader-utils/src/index.ts
488
+ var init_src2 = __esm({
489
+ "../loader-utils/src/index.ts"() {
490
+ init_assert();
491
+ init_text_iterators();
492
+ }
493
+ });
494
+
495
+ // src/lib/clarinet/clarinet.ts
496
+ function isWhitespace(c) {
497
+ return c === Char.carriageReturn || c === Char.lineFeed || c === Char.space || c === Char.tab;
498
+ }
499
+ function checkBufferLength(parser) {
500
+ const maxAllowed = Math.max(MAX_BUFFER_LENGTH, 10);
501
+ let maxActual = 0;
502
+ for (const buffer of ["textNode", "numberNode"]) {
503
+ const len = parser[buffer] === void 0 ? 0 : parser[buffer].length;
504
+ if (len > maxAllowed) {
505
+ switch (buffer) {
506
+ case "text":
507
+ break;
508
+ default:
509
+ parser._error(`Max buffer length exceeded: ${buffer}`);
510
+ }
511
+ }
512
+ maxActual = Math.max(maxActual, len);
513
+ }
514
+ parser.bufferCheckPosition = MAX_BUFFER_LENGTH - maxActual + parser.position;
515
+ }
516
+ var MAX_BUFFER_LENGTH, STATE, Char, stringTokenPattern, DEFAULT_OPTIONS2, ClarinetParser;
517
+ var init_clarinet = __esm({
518
+ "src/lib/clarinet/clarinet.ts"() {
519
+ MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;
520
+ (function(STATE2) {
521
+ STATE2[STATE2["BEGIN"] = 0] = "BEGIN";
522
+ STATE2[STATE2["VALUE"] = 1] = "VALUE";
523
+ STATE2[STATE2["OPEN_OBJECT"] = 2] = "OPEN_OBJECT";
524
+ STATE2[STATE2["CLOSE_OBJECT"] = 3] = "CLOSE_OBJECT";
525
+ STATE2[STATE2["OPEN_ARRAY"] = 4] = "OPEN_ARRAY";
526
+ STATE2[STATE2["CLOSE_ARRAY"] = 5] = "CLOSE_ARRAY";
527
+ STATE2[STATE2["TEXT_ESCAPE"] = 6] = "TEXT_ESCAPE";
528
+ STATE2[STATE2["STRING"] = 7] = "STRING";
529
+ STATE2[STATE2["BACKSLASH"] = 8] = "BACKSLASH";
530
+ STATE2[STATE2["END"] = 9] = "END";
531
+ STATE2[STATE2["OPEN_KEY"] = 10] = "OPEN_KEY";
532
+ STATE2[STATE2["CLOSE_KEY"] = 11] = "CLOSE_KEY";
533
+ STATE2[STATE2["TRUE"] = 12] = "TRUE";
534
+ STATE2[STATE2["TRUE2"] = 13] = "TRUE2";
535
+ STATE2[STATE2["TRUE3"] = 14] = "TRUE3";
536
+ STATE2[STATE2["FALSE"] = 15] = "FALSE";
537
+ STATE2[STATE2["FALSE2"] = 16] = "FALSE2";
538
+ STATE2[STATE2["FALSE3"] = 17] = "FALSE3";
539
+ STATE2[STATE2["FALSE4"] = 18] = "FALSE4";
540
+ STATE2[STATE2["NULL"] = 19] = "NULL";
541
+ STATE2[STATE2["NULL2"] = 20] = "NULL2";
542
+ STATE2[STATE2["NULL3"] = 21] = "NULL3";
543
+ STATE2[STATE2["NUMBER_DECIMAL_POINT"] = 22] = "NUMBER_DECIMAL_POINT";
544
+ STATE2[STATE2["NUMBER_DIGIT"] = 23] = "NUMBER_DIGIT";
545
+ })(STATE || (STATE = {}));
546
+ Char = {
547
+ tab: 9,
548
+ lineFeed: 10,
549
+ carriageReturn: 13,
550
+ space: 32,
551
+ doubleQuote: 34,
552
+ plus: 43,
553
+ comma: 44,
554
+ minus: 45,
555
+ period: 46,
556
+ _0: 48,
557
+ _9: 57,
558
+ colon: 58,
559
+ E: 69,
560
+ openBracket: 91,
561
+ backslash: 92,
562
+ closeBracket: 93,
563
+ a: 97,
564
+ b: 98,
565
+ e: 101,
566
+ f: 102,
567
+ l: 108,
568
+ n: 110,
569
+ r: 114,
570
+ s: 115,
571
+ t: 116,
572
+ u: 117,
573
+ openBrace: 123,
574
+ closeBrace: 125
575
+ };
576
+ stringTokenPattern = /[\\"\n]/g;
577
+ DEFAULT_OPTIONS2 = {
578
+ onready: () => {
579
+ },
580
+ onopenobject: () => {
581
+ },
582
+ onkey: () => {
583
+ },
584
+ oncloseobject: () => {
585
+ },
586
+ onopenarray: () => {
587
+ },
588
+ onclosearray: () => {
589
+ },
590
+ onvalue: () => {
591
+ },
592
+ onerror: () => {
593
+ },
594
+ onend: () => {
595
+ },
596
+ onchunkparsed: () => {
597
+ }
598
+ };
599
+ ClarinetParser = class {
600
+ constructor(options = {}) {
601
+ this.options = DEFAULT_OPTIONS2;
602
+ this.bufferCheckPosition = MAX_BUFFER_LENGTH;
603
+ this.q = "";
604
+ this.c = "";
605
+ this.p = "";
606
+ this.closed = false;
607
+ this.closedRoot = false;
608
+ this.sawRoot = false;
609
+ this.error = null;
610
+ this.state = 0;
611
+ this.stack = [];
612
+ this.position = 0;
613
+ this.column = 0;
614
+ this.line = 1;
615
+ this.slashed = false;
616
+ this.unicodeI = 0;
617
+ this.unicodeS = null;
618
+ this.depth = 0;
619
+ this.options = { ...DEFAULT_OPTIONS2, ...options };
620
+ this.textNode = void 0;
621
+ this.numberNode = "";
622
+ this.emit("onready");
623
+ }
624
+ end() {
625
+ if (this.state !== 1 || this.depth !== 0)
626
+ this._error("Unexpected end");
627
+ this._closeValue();
628
+ this.c = "";
629
+ this.closed = true;
630
+ this.emit("onend");
631
+ return this;
632
+ }
633
+ resume() {
634
+ this.error = null;
635
+ return this;
636
+ }
637
+ close() {
638
+ return this.write(null);
639
+ }
640
+ emit(event, data) {
641
+ this.options[event]?.(data, this);
642
+ }
643
+ emitNode(event, data) {
644
+ this._closeValue();
645
+ this.emit(event, data);
646
+ }
647
+ write(chunk) {
648
+ if (this.error) {
649
+ throw this.error;
650
+ }
651
+ if (this.closed) {
652
+ return this._error("Cannot write after close. Assign an onready handler.");
653
+ }
654
+ if (chunk === null) {
655
+ return this.end();
656
+ }
657
+ let i = 0;
658
+ let c = chunk.charCodeAt(0);
659
+ let p = this.p;
660
+ while (c) {
661
+ p = c;
662
+ this.c = c = chunk.charCodeAt(i++);
663
+ if (p !== c) {
664
+ this.p = p;
665
+ } else {
666
+ p = this.p;
667
+ }
668
+ if (!c)
669
+ break;
670
+ this.position++;
671
+ if (c === Char.lineFeed) {
672
+ this.line++;
673
+ this.column = 0;
674
+ } else
675
+ this.column++;
676
+ switch (this.state) {
677
+ case 0:
678
+ if (c === Char.openBrace)
679
+ this.state = 2;
680
+ else if (c === Char.openBracket)
681
+ this.state = 4;
682
+ else if (!isWhitespace(c)) {
683
+ this._error("Non-whitespace before {[.");
684
+ }
685
+ continue;
686
+ case 10:
687
+ case 2:
688
+ if (isWhitespace(c))
689
+ continue;
690
+ if (this.state === 10)
691
+ this.stack.push(11);
692
+ else if (c === Char.closeBrace) {
693
+ this.emit("onopenobject");
694
+ this.depth++;
695
+ this.emit("oncloseobject");
696
+ this.depth--;
697
+ this.state = this.stack.pop() || 1;
698
+ continue;
699
+ } else
700
+ this.stack.push(3);
701
+ if (c === Char.doubleQuote)
702
+ this.state = 7;
703
+ else
704
+ this._error('Malformed object key should start with "');
705
+ continue;
706
+ case 11:
707
+ case 3:
708
+ if (isWhitespace(c))
709
+ continue;
710
+ if (c === Char.colon) {
711
+ if (this.state === 3) {
712
+ this.stack.push(3);
713
+ this._closeValue("onopenobject");
714
+ this.depth++;
715
+ } else
716
+ this._closeValue("onkey");
717
+ this.state = 1;
718
+ } else if (c === Char.closeBrace) {
719
+ this.emitNode("oncloseobject");
720
+ this.depth--;
721
+ this.state = this.stack.pop() || 1;
722
+ } else if (c === Char.comma) {
723
+ if (this.state === 3)
724
+ this.stack.push(3);
725
+ this._closeValue();
726
+ this.state = 10;
727
+ } else
728
+ this._error("Bad object");
729
+ continue;
730
+ case 4:
731
+ case 1:
732
+ if (isWhitespace(c))
733
+ continue;
734
+ if (this.state === 4) {
735
+ this.emit("onopenarray");
736
+ this.depth++;
737
+ this.state = 1;
738
+ if (c === Char.closeBracket) {
739
+ this.emit("onclosearray");
740
+ this.depth--;
741
+ this.state = this.stack.pop() || 1;
742
+ continue;
743
+ } else {
744
+ this.stack.push(5);
745
+ }
746
+ }
747
+ if (c === Char.doubleQuote)
748
+ this.state = 7;
749
+ else if (c === Char.openBrace)
750
+ this.state = 2;
751
+ else if (c === Char.openBracket)
752
+ this.state = 4;
753
+ else if (c === Char.t)
754
+ this.state = 12;
755
+ else if (c === Char.f)
756
+ this.state = 15;
757
+ else if (c === Char.n)
758
+ this.state = 19;
759
+ else if (c === Char.minus) {
760
+ this.numberNode += "-";
761
+ } else if (Char._0 <= c && c <= Char._9) {
762
+ this.numberNode += String.fromCharCode(c);
763
+ this.state = 23;
764
+ } else
765
+ this._error("Bad value");
766
+ continue;
767
+ case 5:
768
+ if (c === Char.comma) {
769
+ this.stack.push(5);
770
+ this._closeValue("onvalue");
771
+ this.state = 1;
772
+ } else if (c === Char.closeBracket) {
773
+ this.emitNode("onclosearray");
774
+ this.depth--;
775
+ this.state = this.stack.pop() || 1;
776
+ } else if (isWhitespace(c))
777
+ continue;
778
+ else
779
+ this._error("Bad array");
780
+ continue;
781
+ case 7:
782
+ if (this.textNode === void 0) {
783
+ this.textNode = "";
784
+ }
785
+ let starti = i - 1;
786
+ let slashed = this.slashed;
787
+ let unicodeI = this.unicodeI;
788
+ STRING_BIGLOOP:
789
+ while (true) {
790
+ while (unicodeI > 0) {
791
+ this.unicodeS += String.fromCharCode(c);
792
+ c = chunk.charCodeAt(i++);
793
+ this.position++;
794
+ if (unicodeI === 4) {
795
+ this.textNode += String.fromCharCode(parseInt(this.unicodeS, 16));
796
+ unicodeI = 0;
797
+ starti = i - 1;
798
+ } else {
799
+ unicodeI++;
800
+ }
801
+ if (!c)
802
+ break STRING_BIGLOOP;
803
+ }
804
+ if (c === Char.doubleQuote && !slashed) {
805
+ this.state = this.stack.pop() || 1;
806
+ this.textNode += chunk.substring(starti, i - 1);
807
+ this.position += i - 1 - starti;
808
+ break;
809
+ }
810
+ if (c === Char.backslash && !slashed) {
811
+ slashed = true;
812
+ this.textNode += chunk.substring(starti, i - 1);
813
+ this.position += i - 1 - starti;
814
+ c = chunk.charCodeAt(i++);
815
+ this.position++;
816
+ if (!c)
817
+ break;
818
+ }
819
+ if (slashed) {
820
+ slashed = false;
821
+ if (c === Char.n) {
822
+ this.textNode += "\n";
823
+ } else if (c === Char.r) {
824
+ this.textNode += "\r";
825
+ } else if (c === Char.t) {
826
+ this.textNode += " ";
827
+ } else if (c === Char.f) {
828
+ this.textNode += "\f";
829
+ } else if (c === Char.b) {
830
+ this.textNode += "\b";
831
+ } else if (c === Char.u) {
832
+ unicodeI = 1;
833
+ this.unicodeS = "";
834
+ } else {
835
+ this.textNode += String.fromCharCode(c);
836
+ }
837
+ c = chunk.charCodeAt(i++);
838
+ this.position++;
839
+ starti = i - 1;
840
+ if (!c)
841
+ break;
842
+ else
843
+ continue;
844
+ }
845
+ stringTokenPattern.lastIndex = i;
846
+ const reResult = stringTokenPattern.exec(chunk);
847
+ if (reResult === null) {
848
+ i = chunk.length + 1;
849
+ this.textNode += chunk.substring(starti, i - 1);
850
+ this.position += i - 1 - starti;
851
+ break;
852
+ }
853
+ i = reResult.index + 1;
854
+ c = chunk.charCodeAt(reResult.index);
855
+ if (!c) {
856
+ this.textNode += chunk.substring(starti, i - 1);
857
+ this.position += i - 1 - starti;
858
+ break;
859
+ }
860
+ }
861
+ this.slashed = slashed;
862
+ this.unicodeI = unicodeI;
863
+ continue;
864
+ case 12:
865
+ if (c === Char.r)
866
+ this.state = 13;
867
+ else
868
+ this._error(`Invalid true started with t${c}`);
869
+ continue;
870
+ case 13:
871
+ if (c === Char.u)
872
+ this.state = 14;
873
+ else
874
+ this._error(`Invalid true started with tr${c}`);
875
+ continue;
876
+ case 14:
877
+ if (c === Char.e) {
878
+ this.emit("onvalue", true);
879
+ this.state = this.stack.pop() || 1;
880
+ } else
881
+ this._error(`Invalid true started with tru${c}`);
882
+ continue;
883
+ case 15:
884
+ if (c === Char.a)
885
+ this.state = 16;
886
+ else
887
+ this._error(`Invalid false started with f${c}`);
888
+ continue;
889
+ case 16:
890
+ if (c === Char.l)
891
+ this.state = 17;
892
+ else
893
+ this._error(`Invalid false started with fa${c}`);
894
+ continue;
895
+ case 17:
896
+ if (c === Char.s)
897
+ this.state = 18;
898
+ else
899
+ this._error(`Invalid false started with fal${c}`);
900
+ continue;
901
+ case 18:
902
+ if (c === Char.e) {
903
+ this.emit("onvalue", false);
904
+ this.state = this.stack.pop() || 1;
905
+ } else
906
+ this._error(`Invalid false started with fals${c}`);
907
+ continue;
908
+ case 19:
909
+ if (c === Char.u)
910
+ this.state = 20;
911
+ else
912
+ this._error(`Invalid null started with n${c}`);
913
+ continue;
914
+ case 20:
915
+ if (c === Char.l)
916
+ this.state = 21;
917
+ else
918
+ this._error(`Invalid null started with nu${c}`);
919
+ continue;
920
+ case 21:
921
+ if (c === Char.l) {
922
+ this.emit("onvalue", null);
923
+ this.state = this.stack.pop() || 1;
924
+ } else
925
+ this._error(`Invalid null started with nul${c}`);
926
+ continue;
927
+ case 22:
928
+ if (c === Char.period) {
929
+ this.numberNode += ".";
930
+ this.state = 23;
931
+ } else
932
+ this._error("Leading zero not followed by .");
933
+ continue;
934
+ case 23:
935
+ if (Char._0 <= c && c <= Char._9)
936
+ this.numberNode += String.fromCharCode(c);
937
+ else if (c === Char.period) {
938
+ if (this.numberNode.indexOf(".") !== -1)
939
+ this._error("Invalid number has two dots");
940
+ this.numberNode += ".";
941
+ } else if (c === Char.e || c === Char.E) {
942
+ if (this.numberNode.indexOf("e") !== -1 || this.numberNode.indexOf("E") !== -1)
943
+ this._error("Invalid number has two exponential");
944
+ this.numberNode += "e";
945
+ } else if (c === Char.plus || c === Char.minus) {
946
+ if (!(p === Char.e || p === Char.E))
947
+ this._error("Invalid symbol in number");
948
+ this.numberNode += String.fromCharCode(c);
949
+ } else {
950
+ this._closeNumber();
951
+ i--;
952
+ this.state = this.stack.pop() || 1;
953
+ }
954
+ continue;
955
+ default:
956
+ this._error(`Unknown state: ${this.state}`);
957
+ }
958
+ }
959
+ if (this.position >= this.bufferCheckPosition) {
960
+ checkBufferLength(this);
961
+ }
962
+ this.emit("onchunkparsed");
963
+ return this;
964
+ }
965
+ _closeValue(event = "onvalue") {
966
+ if (this.textNode !== void 0) {
967
+ this.emit(event, this.textNode);
968
+ }
969
+ this.textNode = void 0;
970
+ }
971
+ _closeNumber() {
972
+ if (this.numberNode)
973
+ this.emit("onvalue", parseFloat(this.numberNode));
974
+ this.numberNode = "";
975
+ }
976
+ _error(message = "") {
977
+ this._closeValue();
978
+ message += `
979
+ Line: ${this.line}
980
+ Column: ${this.column}
981
+ Char: ${this.c}`;
982
+ const error = new Error(message);
983
+ this.error = error;
984
+ this.emit("onerror", error);
985
+ }
986
+ };
987
+ }
988
+ });
989
+
990
+ // src/lib/jsonpath/jsonpath.ts
991
+ var JSONPath;
992
+ var init_jsonpath = __esm({
993
+ "src/lib/jsonpath/jsonpath.ts"() {
994
+ JSONPath = class {
995
+ constructor(path = null) {
996
+ this.path = ["$"];
997
+ if (path instanceof JSONPath) {
998
+ this.path = [...path.path];
999
+ return;
1000
+ }
1001
+ if (Array.isArray(path)) {
1002
+ this.path.push(...path);
1003
+ return;
1004
+ }
1005
+ if (typeof path === "string") {
1006
+ this.path = path.split(".");
1007
+ if (this.path[0] !== "$") {
1008
+ throw new Error("JSONPaths must start with $");
1009
+ }
1010
+ }
1011
+ }
1012
+ clone() {
1013
+ return new JSONPath(this);
1014
+ }
1015
+ toString() {
1016
+ return this.path.join(".");
1017
+ }
1018
+ push(name) {
1019
+ this.path.push(name);
1020
+ }
1021
+ pop() {
1022
+ return this.path.pop();
1023
+ }
1024
+ set(name) {
1025
+ this.path[this.path.length - 1] = name;
1026
+ }
1027
+ equals(other) {
1028
+ if (!this || !other || this.path.length !== other.path.length) {
1029
+ return false;
1030
+ }
1031
+ for (let i = 0; i < this.path.length; ++i) {
1032
+ if (this.path[i] !== other.path[i]) {
1033
+ return false;
1034
+ }
1035
+ }
1036
+ return true;
1037
+ }
1038
+ setFieldAtPath(object, value) {
1039
+ const path = [...this.path];
1040
+ path.shift();
1041
+ const field = path.pop();
1042
+ for (const component of path) {
1043
+ object = object[component];
1044
+ }
1045
+ object[field] = value;
1046
+ }
1047
+ getFieldAtPath(object) {
1048
+ const path = [...this.path];
1049
+ path.shift();
1050
+ const field = path.pop();
1051
+ for (const component of path) {
1052
+ object = object[component];
1053
+ }
1054
+ return object[field];
1055
+ }
1056
+ };
1057
+ }
1058
+ });
1059
+
1060
+ // src/lib/parser/json-parser.ts
1061
+ var JSONParser;
1062
+ var init_json_parser = __esm({
1063
+ "src/lib/parser/json-parser.ts"() {
1064
+ init_clarinet();
1065
+ init_jsonpath();
1066
+ JSONParser = class {
1067
+ constructor(options) {
1068
+ this.result = void 0;
1069
+ this.previousStates = [];
1070
+ this.currentState = Object.freeze({ container: [], key: null });
1071
+ this.jsonpath = new JSONPath();
1072
+ this.reset();
1073
+ this.parser = new ClarinetParser({
1074
+ onready: () => {
1075
+ this.jsonpath = new JSONPath();
1076
+ this.previousStates.length = 0;
1077
+ this.currentState.container.length = 0;
1078
+ },
1079
+ onopenobject: (name) => {
1080
+ this._openObject({});
1081
+ if (typeof name !== "undefined") {
1082
+ this.parser.emit("onkey", name);
1083
+ }
1084
+ },
1085
+ onkey: (name) => {
1086
+ this.jsonpath.set(name);
1087
+ this.currentState.key = name;
1088
+ },
1089
+ oncloseobject: () => {
1090
+ this._closeObject();
1091
+ },
1092
+ onopenarray: () => {
1093
+ this._openArray();
1094
+ },
1095
+ onclosearray: () => {
1096
+ this._closeArray();
1097
+ },
1098
+ onvalue: (value) => {
1099
+ this._pushOrSet(value);
1100
+ },
1101
+ onerror: (error) => {
1102
+ throw error;
1103
+ },
1104
+ onend: () => {
1105
+ this.result = this.currentState.container.pop();
1106
+ },
1107
+ ...options
1108
+ });
1109
+ }
1110
+ reset() {
1111
+ this.result = void 0;
1112
+ this.previousStates = [];
1113
+ this.currentState = Object.freeze({ container: [], key: null });
1114
+ this.jsonpath = new JSONPath();
1115
+ }
1116
+ write(chunk) {
1117
+ this.parser.write(chunk);
1118
+ }
1119
+ close() {
1120
+ this.parser.close();
1121
+ }
1122
+ _pushOrSet(value) {
1123
+ const { container, key } = this.currentState;
1124
+ if (key !== null) {
1125
+ container[key] = value;
1126
+ this.currentState.key = null;
1127
+ } else {
1128
+ container.push(value);
1129
+ }
1130
+ }
1131
+ _openArray(newContainer = []) {
1132
+ this.jsonpath.push(null);
1133
+ this._pushOrSet(newContainer);
1134
+ this.previousStates.push(this.currentState);
1135
+ this.currentState = { container: newContainer, isArray: true, key: null };
1136
+ }
1137
+ _closeArray() {
1138
+ this.jsonpath.pop();
1139
+ this.currentState = this.previousStates.pop();
1140
+ }
1141
+ _openObject(newContainer = {}) {
1142
+ this.jsonpath.push(null);
1143
+ this._pushOrSet(newContainer);
1144
+ this.previousStates.push(this.currentState);
1145
+ this.currentState = { container: newContainer, isArray: false, key: null };
1146
+ }
1147
+ _closeObject() {
1148
+ this.jsonpath.pop();
1149
+ this.currentState = this.previousStates.pop();
1150
+ }
1151
+ };
1152
+ }
1153
+ });
1154
+
1155
+ // src/lib/parser/streaming-json-parser.ts
1156
+ var StreamingJSONParser;
1157
+ var init_streaming_json_parser = __esm({
1158
+ "src/lib/parser/streaming-json-parser.ts"() {
1159
+ init_json_parser();
1160
+ init_jsonpath();
1161
+ StreamingJSONParser = class extends JSONParser {
1162
+ constructor(options = {}) {
1163
+ super({
1164
+ onopenarray: () => {
1165
+ if (!this.streamingArray) {
1166
+ if (this._matchJSONPath()) {
1167
+ this.streamingJsonPath = this.getJsonPath().clone();
1168
+ this.streamingArray = [];
1169
+ this._openArray(this.streamingArray);
1170
+ return;
1171
+ }
1172
+ }
1173
+ this._openArray();
1174
+ },
1175
+ onopenobject: (name) => {
1176
+ if (!this.topLevelObject) {
1177
+ this.topLevelObject = {};
1178
+ this._openObject(this.topLevelObject);
1179
+ } else {
1180
+ this._openObject({});
1181
+ }
1182
+ if (typeof name !== "undefined") {
1183
+ this.parser.emit("onkey", name);
1184
+ }
1185
+ }
1186
+ });
1187
+ this.streamingJsonPath = null;
1188
+ this.streamingArray = null;
1189
+ this.topLevelObject = null;
1190
+ const jsonpaths = options.jsonpaths || [];
1191
+ this.jsonPaths = jsonpaths.map((jsonpath) => new JSONPath(jsonpath));
1192
+ }
1193
+ write(chunk) {
1194
+ super.write(chunk);
1195
+ let array = [];
1196
+ if (this.streamingArray) {
1197
+ array = [...this.streamingArray];
1198
+ this.streamingArray.length = 0;
1199
+ }
1200
+ return array;
1201
+ }
1202
+ getPartialResult() {
1203
+ return this.topLevelObject;
1204
+ }
1205
+ getStreamingJsonPath() {
1206
+ return this.streamingJsonPath;
1207
+ }
1208
+ getStreamingJsonPathAsString() {
1209
+ return this.streamingJsonPath && this.streamingJsonPath.toString();
1210
+ }
1211
+ getJsonPath() {
1212
+ return this.jsonpath;
1213
+ }
1214
+ _matchJSONPath() {
1215
+ const currentPath = this.getJsonPath();
1216
+ if (this.jsonPaths.length === 0) {
1217
+ return true;
1218
+ }
1219
+ for (const jsonPath of this.jsonPaths) {
1220
+ if (jsonPath.equals(currentPath)) {
1221
+ return true;
1222
+ }
1223
+ }
1224
+ return false;
1225
+ }
1226
+ };
1227
+ }
1228
+ });
1229
+
1230
+ // src/lib/parse-json-in-batches.ts
1231
+ async function* parseJSONInBatches(binaryAsyncIterator, options) {
1232
+ const asyncIterator = makeTextDecoderIterator(binaryAsyncIterator);
1233
+ const { metadata } = options;
1234
+ const { jsonpaths } = options.json || {};
1235
+ let isFirstChunk = true;
1236
+ const schema = null;
1237
+ const shape = options?.json?.shape || "row-table";
1238
+ const tableBatchBuilder = new TableBatchBuilder(schema, {
1239
+ ...options,
1240
+ shape
1241
+ });
1242
+ const parser = new StreamingJSONParser({ jsonpaths });
1243
+ for await (const chunk of asyncIterator) {
1244
+ const rows = parser.write(chunk);
1245
+ const jsonpath2 = rows.length > 0 && parser.getStreamingJsonPathAsString();
1246
+ if (rows.length > 0 && isFirstChunk) {
1247
+ if (metadata) {
1248
+ const initialBatch = {
1249
+ shape,
1250
+ batchType: "partial-result",
1251
+ data: [],
1252
+ length: 0,
1253
+ bytesUsed: 0,
1254
+ container: parser.getPartialResult(),
1255
+ jsonpath: jsonpath2
1256
+ };
1257
+ yield initialBatch;
1258
+ }
1259
+ isFirstChunk = false;
1260
+ }
1261
+ for (const row of rows) {
1262
+ tableBatchBuilder.addRow(row);
1263
+ const batch3 = tableBatchBuilder.getFullBatch({ jsonpath: jsonpath2 });
1264
+ if (batch3) {
1265
+ yield batch3;
1266
+ }
1267
+ }
1268
+ tableBatchBuilder.chunkComplete(chunk);
1269
+ const batch2 = tableBatchBuilder.getFullBatch({ jsonpath: jsonpath2 });
1270
+ if (batch2) {
1271
+ yield batch2;
1272
+ }
1273
+ }
1274
+ const jsonpath = parser.getStreamingJsonPathAsString();
1275
+ const batch = tableBatchBuilder.getFinalBatch({ jsonpath });
1276
+ if (batch) {
1277
+ yield batch;
1278
+ }
1279
+ if (metadata) {
1280
+ const finalBatch = {
1281
+ shape,
1282
+ batchType: "final-result",
1283
+ container: parser.getPartialResult(),
1284
+ jsonpath: parser.getStreamingJsonPathAsString(),
1285
+ data: [],
1286
+ length: 0
1287
+ };
1288
+ yield finalBatch;
1289
+ }
1290
+ }
1291
+ function rebuildJsonObject(batch, data) {
1292
+ assert(batch.batchType === "final-result");
1293
+ if (batch.jsonpath === "$") {
1294
+ return data;
1295
+ }
1296
+ if (batch.jsonpath && batch.jsonpath.length > 1) {
1297
+ const topLevelObject = batch.container;
1298
+ const streamingPath = new JSONPath(batch.jsonpath);
1299
+ streamingPath.setFieldAtPath(topLevelObject, data);
1300
+ return topLevelObject;
1301
+ }
1302
+ return batch.container;
1303
+ }
1304
+ var init_parse_json_in_batches = __esm({
1305
+ "src/lib/parse-json-in-batches.ts"() {
1306
+ init_src();
1307
+ init_src2();
1308
+ init_streaming_json_parser();
1309
+ init_jsonpath();
1310
+ }
1311
+ });
1312
+
1313
+ // src/json-loader.ts
1314
+ async function parse(arrayBuffer, options) {
1315
+ return parseTextSync(new TextDecoder().decode(arrayBuffer), options);
1316
+ }
1317
+ function parseTextSync(text, options) {
1318
+ const jsonOptions = { ...options, json: { ...DEFAULT_JSON_LOADER_OPTIONS.json, ...options?.json } };
1319
+ return parseJSONSync(text, jsonOptions);
1320
+ }
1321
+ function parseInBatches(asyncIterator, options) {
1322
+ const jsonOptions = { ...options, json: { ...DEFAULT_JSON_LOADER_OPTIONS.json, ...options?.json } };
1323
+ return parseJSONInBatches(asyncIterator, jsonOptions);
1324
+ }
1325
+ var VERSION, DEFAULT_JSON_LOADER_OPTIONS, JSONLoader;
1326
+ var init_json_loader = __esm({
1327
+ "src/json-loader.ts"() {
1328
+ init_parse_json();
1329
+ init_parse_json_in_batches();
1330
+ VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1331
+ DEFAULT_JSON_LOADER_OPTIONS = {
1332
+ json: {
1333
+ shape: "row-table",
1334
+ table: false,
1335
+ jsonpaths: []
1336
+ }
1337
+ };
1338
+ JSONLoader = {
1339
+ name: "JSON",
1340
+ id: "json",
1341
+ module: "json",
1342
+ version: VERSION,
1343
+ extensions: ["json", "geojson"],
1344
+ mimeTypes: ["application/json"],
1345
+ category: "table",
1346
+ text: true,
1347
+ parse,
1348
+ parseTextSync,
1349
+ parseInBatches,
1350
+ options: DEFAULT_JSON_LOADER_OPTIONS
1351
+ };
1352
+ }
1353
+ });
1354
+
1355
+ // src/lib/parse-ndjson.ts
1356
+ function parseNDJSONSync(ndjsonText) {
1357
+ const lines = ndjsonText.trim().split("\n");
1358
+ return lines.map((line, counter) => {
1359
+ try {
1360
+ return JSON.parse(line);
1361
+ } catch (error) {
1362
+ throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter + 1}`);
1363
+ }
1364
+ });
1365
+ }
1366
+ var init_parse_ndjson = __esm({
1367
+ "src/lib/parse-ndjson.ts"() {
1368
+ }
1369
+ });
1370
+
1371
+ // src/lib/parse-ndjson-in-batches.ts
1372
+ async function* parseNDJSONInBatches(binaryAsyncIterator, options) {
1373
+ const textIterator = makeTextDecoderIterator(binaryAsyncIterator);
1374
+ const lineIterator = makeLineIterator(textIterator);
1375
+ const numberedLineIterator = makeNumberedLineIterator(lineIterator);
1376
+ const schema = null;
1377
+ const shape = "row-table";
1378
+ const tableBatchBuilder = new TableBatchBuilder(schema, {
1379
+ ...options,
1380
+ shape
1381
+ });
1382
+ for await (const { counter, line } of numberedLineIterator) {
1383
+ try {
1384
+ const row = JSON.parse(line);
1385
+ tableBatchBuilder.addRow(row);
1386
+ tableBatchBuilder.chunkComplete(line);
1387
+ const batch2 = tableBatchBuilder.getFullBatch();
1388
+ if (batch2) {
1389
+ yield batch2;
1390
+ }
1391
+ } catch (error) {
1392
+ throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter}`);
1393
+ }
1394
+ }
1395
+ const batch = tableBatchBuilder.getFinalBatch();
1396
+ if (batch) {
1397
+ yield batch;
1398
+ }
1399
+ }
1400
+ var init_parse_ndjson_in_batches = __esm({
1401
+ "src/lib/parse-ndjson-in-batches.ts"() {
1402
+ init_src();
1403
+ init_src2();
1404
+ }
1405
+ });
1406
+
1407
+ // src/ndjson-loader.ts
1408
+ async function parse2(arrayBuffer) {
1409
+ return parseTextSync2(new TextDecoder().decode(arrayBuffer));
1410
+ }
1411
+ function parseTextSync2(text) {
1412
+ return parseNDJSONSync(text);
1413
+ }
1414
+ function parseInBatches2(asyncIterator, options) {
1415
+ return parseNDJSONInBatches(asyncIterator, options);
1416
+ }
1417
+ var VERSION2, NDJSONLoader;
1418
+ var init_ndjson_loader = __esm({
1419
+ "src/ndjson-loader.ts"() {
1420
+ init_parse_ndjson();
1421
+ init_parse_ndjson_in_batches();
1422
+ VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1423
+ NDJSONLoader = {
1424
+ name: "NDJSON",
1425
+ id: "ndjson",
1426
+ module: "json",
1427
+ version: VERSION2,
1428
+ extensions: ["ndjson"],
1429
+ mimeTypes: ["application/x-ndjson"],
1430
+ category: "table",
1431
+ text: true,
1432
+ parse: parse2,
1433
+ parseTextSync: parseTextSync2,
1434
+ parseInBatches: parseInBatches2,
1435
+ options: {}
1436
+ };
1437
+ }
1438
+ });
1439
+
1440
+ // ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
1441
+ function getPolygonSignedArea(points, options = {}) {
1442
+ const {
1443
+ start = 0,
1444
+ end = points.length
1445
+ } = options;
1446
+ const dim = options.size || 2;
1447
+ let area2 = 0;
1448
+ for (let i = start, j = end - dim; i < end; i += dim) {
1449
+ area2 += (points[i] - points[j]) * (points[i + 1] + points[j + 1]);
1450
+ j = i;
1451
+ }
1452
+ return area2 / 2;
1453
+ }
1454
+ var init_polygon_utils = __esm({
1455
+ "../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js"() {
1456
+ }
1457
+ });
1458
+
1459
+ // ../../node_modules/@math.gl/polygon/dist/esm/polygon.js
1460
+ var init_polygon = __esm({
1461
+ "../../node_modules/@math.gl/polygon/dist/esm/polygon.js"() {
1462
+ init_polygon_utils();
1463
+ }
1464
+ });
1465
+
1466
+ // ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
1467
+ function earcut(data, holeIndices, dim, areas) {
1468
+ dim = dim || 2;
1469
+ const hasHoles = holeIndices && holeIndices.length;
1470
+ const outerLen = hasHoles ? holeIndices[0] * dim : data.length;
1471
+ let outerNode = linkedList(data, 0, outerLen, dim, true, areas && areas[0]);
1472
+ const triangles = [];
1473
+ if (!outerNode || outerNode.next === outerNode.prev)
1474
+ return triangles;
1475
+ let invSize;
1476
+ let maxX;
1477
+ let maxY;
1478
+ let minX;
1479
+ let minY;
1480
+ let x;
1481
+ let y;
1482
+ if (hasHoles)
1483
+ outerNode = eliminateHoles(data, holeIndices, outerNode, dim, areas);
1484
+ if (data.length > 80 * dim) {
1485
+ minX = maxX = data[0];
1486
+ minY = maxY = data[1];
1487
+ for (let i = dim; i < outerLen; i += dim) {
1488
+ x = data[i];
1489
+ y = data[i + 1];
1490
+ if (x < minX)
1491
+ minX = x;
1492
+ if (y < minY)
1493
+ minY = y;
1494
+ if (x > maxX)
1495
+ maxX = x;
1496
+ if (y > maxY)
1497
+ maxY = y;
1498
+ }
1499
+ invSize = Math.max(maxX - minX, maxY - minY);
1500
+ invSize = invSize !== 0 ? 1 / invSize : 0;
1501
+ }
1502
+ earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
1503
+ return triangles;
1504
+ }
1505
+ function linkedList(data, start, end, dim, clockwise, area2) {
1506
+ let i;
1507
+ let last;
1508
+ if (area2 === void 0) {
1509
+ area2 = getPolygonSignedArea(data, {
1510
+ start,
1511
+ end,
1512
+ size: dim
1513
+ });
1514
+ }
1515
+ if (clockwise === area2 < 0) {
1516
+ for (i = start; i < end; i += dim)
1517
+ last = insertNode(i, data[i], data[i + 1], last);
1518
+ } else {
1519
+ for (i = end - dim; i >= start; i -= dim)
1520
+ last = insertNode(i, data[i], data[i + 1], last);
1521
+ }
1522
+ if (last && equals(last, last.next)) {
1523
+ removeNode(last);
1524
+ last = last.next;
1525
+ }
1526
+ return last;
1527
+ }
1528
+ function filterPoints(start, end) {
1529
+ if (!start)
1530
+ return start;
1531
+ if (!end)
1532
+ end = start;
1533
+ let p = start;
1534
+ let again;
1535
+ do {
1536
+ again = false;
1537
+ if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
1538
+ removeNode(p);
1539
+ p = end = p.prev;
1540
+ if (p === p.next)
1541
+ break;
1542
+ again = true;
1543
+ } else {
1544
+ p = p.next;
1545
+ }
1546
+ } while (again || p !== end);
1547
+ return end;
1548
+ }
1549
+ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
1550
+ if (!ear)
1551
+ return;
1552
+ if (!pass && invSize)
1553
+ indexCurve(ear, minX, minY, invSize);
1554
+ let stop = ear;
1555
+ let prev;
1556
+ let next;
1557
+ while (ear.prev !== ear.next) {
1558
+ prev = ear.prev;
1559
+ next = ear.next;
1560
+ if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
1561
+ triangles.push(prev.i / dim);
1562
+ triangles.push(ear.i / dim);
1563
+ triangles.push(next.i / dim);
1564
+ removeNode(ear);
1565
+ ear = next.next;
1566
+ stop = next.next;
1567
+ continue;
1568
+ }
1569
+ ear = next;
1570
+ if (ear === stop) {
1571
+ if (!pass) {
1572
+ earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
1573
+ } else if (pass === 1) {
1574
+ ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
1575
+ earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
1576
+ } else if (pass === 2) {
1577
+ splitEarcut(ear, triangles, dim, minX, minY, invSize);
1578
+ }
1579
+ break;
1580
+ }
1581
+ }
1582
+ }
1583
+ function isEar(ear) {
1584
+ const a = ear.prev;
1585
+ const b = ear;
1586
+ const c = ear.next;
1587
+ if (area(a, b, c) >= 0)
1588
+ return false;
1589
+ let p = ear.next.next;
1590
+ while (p !== ear.prev) {
1591
+ if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
1592
+ return false;
1593
+ p = p.next;
1594
+ }
1595
+ return true;
1596
+ }
1597
+ function isEarHashed(ear, minX, minY, invSize) {
1598
+ const a = ear.prev;
1599
+ const b = ear;
1600
+ const c = ear.next;
1601
+ if (area(a, b, c) >= 0)
1602
+ return false;
1603
+ const minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x;
1604
+ const minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y;
1605
+ const maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x;
1606
+ const maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
1607
+ const minZ = zOrder(minTX, minTY, minX, minY, invSize);
1608
+ const maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
1609
+ let p = ear.prevZ;
1610
+ let n = ear.nextZ;
1611
+ while (p && p.z >= minZ && n && n.z <= maxZ) {
1612
+ if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
1613
+ return false;
1614
+ p = p.prevZ;
1615
+ if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
1616
+ return false;
1617
+ n = n.nextZ;
1618
+ }
1619
+ while (p && p.z >= minZ) {
1620
+ if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
1621
+ return false;
1622
+ p = p.prevZ;
1623
+ }
1624
+ while (n && n.z <= maxZ) {
1625
+ if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
1626
+ return false;
1627
+ n = n.nextZ;
1628
+ }
1629
+ return true;
1630
+ }
1631
+ function cureLocalIntersections(start, triangles, dim) {
1632
+ let p = start;
1633
+ do {
1634
+ const a = p.prev;
1635
+ const b = p.next.next;
1636
+ if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
1637
+ triangles.push(a.i / dim);
1638
+ triangles.push(p.i / dim);
1639
+ triangles.push(b.i / dim);
1640
+ removeNode(p);
1641
+ removeNode(p.next);
1642
+ p = start = b;
1643
+ }
1644
+ p = p.next;
1645
+ } while (p !== start);
1646
+ return filterPoints(p);
1647
+ }
1648
+ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
1649
+ let a = start;
1650
+ do {
1651
+ let b = a.next.next;
1652
+ while (b !== a.prev) {
1653
+ if (a.i !== b.i && isValidDiagonal(a, b)) {
1654
+ let c = splitPolygon(a, b);
1655
+ a = filterPoints(a, a.next);
1656
+ c = filterPoints(c, c.next);
1657
+ earcutLinked(a, triangles, dim, minX, minY, invSize);
1658
+ earcutLinked(c, triangles, dim, minX, minY, invSize);
1659
+ return;
1660
+ }
1661
+ b = b.next;
1662
+ }
1663
+ a = a.next;
1664
+ } while (a !== start);
1665
+ }
1666
+ function eliminateHoles(data, holeIndices, outerNode, dim, areas) {
1667
+ const queue = [];
1668
+ let i;
1669
+ let len;
1670
+ let start;
1671
+ let end;
1672
+ let list;
1673
+ for (i = 0, len = holeIndices.length; i < len; i++) {
1674
+ start = holeIndices[i] * dim;
1675
+ end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
1676
+ list = linkedList(data, start, end, dim, false, areas && areas[i + 1]);
1677
+ if (list === list.next)
1678
+ list.steiner = true;
1679
+ queue.push(getLeftmost(list));
1680
+ }
1681
+ queue.sort(compareX);
1682
+ for (i = 0; i < queue.length; i++) {
1683
+ eliminateHole(queue[i], outerNode);
1684
+ outerNode = filterPoints(outerNode, outerNode.next);
1685
+ }
1686
+ return outerNode;
1687
+ }
1688
+ function compareX(a, b) {
1689
+ return a.x - b.x;
1690
+ }
1691
+ function eliminateHole(hole, outerNode) {
1692
+ outerNode = findHoleBridge(hole, outerNode);
1693
+ if (outerNode) {
1694
+ const b = splitPolygon(outerNode, hole);
1695
+ filterPoints(outerNode, outerNode.next);
1696
+ filterPoints(b, b.next);
1697
+ }
1698
+ }
1699
+ function findHoleBridge(hole, outerNode) {
1700
+ let p = outerNode;
1701
+ const hx = hole.x;
1702
+ const hy = hole.y;
1703
+ let qx = -Infinity;
1704
+ let m;
1705
+ do {
1706
+ if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
1707
+ const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
1708
+ if (x <= hx && x > qx) {
1709
+ qx = x;
1710
+ if (x === hx) {
1711
+ if (hy === p.y)
1712
+ return p;
1713
+ if (hy === p.next.y)
1714
+ return p.next;
1715
+ }
1716
+ m = p.x < p.next.x ? p : p.next;
1717
+ }
1718
+ }
1719
+ p = p.next;
1720
+ } while (p !== outerNode);
1721
+ if (!m)
1722
+ return null;
1723
+ if (hx === qx)
1724
+ return m;
1725
+ const stop = m;
1726
+ const mx = m.x;
1727
+ const my = m.y;
1728
+ let tanMin = Infinity;
1729
+ let tan;
1730
+ p = m;
1731
+ do {
1732
+ 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)) {
1733
+ tan = Math.abs(hy - p.y) / (hx - p.x);
1734
+ if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
1735
+ m = p;
1736
+ tanMin = tan;
1737
+ }
1738
+ }
1739
+ p = p.next;
1740
+ } while (p !== stop);
1741
+ return m;
1742
+ }
1743
+ function sectorContainsSector(m, p) {
1744
+ return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
1745
+ }
1746
+ function indexCurve(start, minX, minY, invSize) {
1747
+ let p = start;
1748
+ do {
1749
+ if (p.z === null)
1750
+ p.z = zOrder(p.x, p.y, minX, minY, invSize);
1751
+ p.prevZ = p.prev;
1752
+ p.nextZ = p.next;
1753
+ p = p.next;
1754
+ } while (p !== start);
1755
+ p.prevZ.nextZ = null;
1756
+ p.prevZ = null;
1757
+ sortLinked(p);
1758
+ }
1759
+ function sortLinked(list) {
1760
+ let e;
1761
+ let i;
1762
+ let inSize = 1;
1763
+ let numMerges;
1764
+ let p;
1765
+ let pSize;
1766
+ let q;
1767
+ let qSize;
1768
+ let tail;
1769
+ do {
1770
+ p = list;
1771
+ list = null;
1772
+ tail = null;
1773
+ numMerges = 0;
1774
+ while (p) {
1775
+ numMerges++;
1776
+ q = p;
1777
+ pSize = 0;
1778
+ for (i = 0; i < inSize; i++) {
1779
+ pSize++;
1780
+ q = q.nextZ;
1781
+ if (!q)
1782
+ break;
1783
+ }
1784
+ qSize = inSize;
1785
+ while (pSize > 0 || qSize > 0 && q) {
1786
+ if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
1787
+ e = p;
1788
+ p = p.nextZ;
1789
+ pSize--;
1790
+ } else {
1791
+ e = q;
1792
+ q = q.nextZ;
1793
+ qSize--;
1794
+ }
1795
+ if (tail)
1796
+ tail.nextZ = e;
1797
+ else
1798
+ list = e;
1799
+ e.prevZ = tail;
1800
+ tail = e;
1801
+ }
1802
+ p = q;
1803
+ }
1804
+ tail.nextZ = null;
1805
+ inSize *= 2;
1806
+ } while (numMerges > 1);
1807
+ return list;
1808
+ }
1809
+ function zOrder(x, y, minX, minY, invSize) {
1810
+ x = 32767 * (x - minX) * invSize;
1811
+ y = 32767 * (y - minY) * invSize;
1812
+ x = (x | x << 8) & 16711935;
1813
+ x = (x | x << 4) & 252645135;
1814
+ x = (x | x << 2) & 858993459;
1815
+ x = (x | x << 1) & 1431655765;
1816
+ y = (y | y << 8) & 16711935;
1817
+ y = (y | y << 4) & 252645135;
1818
+ y = (y | y << 2) & 858993459;
1819
+ y = (y | y << 1) & 1431655765;
1820
+ return x | y << 1;
1821
+ }
1822
+ function getLeftmost(start) {
1823
+ let p = start;
1824
+ let leftmost = start;
1825
+ do {
1826
+ if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
1827
+ leftmost = p;
1828
+ p = p.next;
1829
+ } while (p !== start);
1830
+ return leftmost;
1831
+ }
1832
+ function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
1833
+ return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
1834
+ }
1835
+ function isValidDiagonal(a, b) {
1836
+ 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);
1837
+ }
1838
+ function area(p, q, r) {
1839
+ return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
1840
+ }
1841
+ function equals(p1, p2) {
1842
+ return p1.x === p2.x && p1.y === p2.y;
1843
+ }
1844
+ function intersects(p1, q1, p2, q2) {
1845
+ const o1 = sign(area(p1, q1, p2));
1846
+ const o2 = sign(area(p1, q1, q2));
1847
+ const o3 = sign(area(p2, q2, p1));
1848
+ const o4 = sign(area(p2, q2, q1));
1849
+ if (o1 !== o2 && o3 !== o4)
1850
+ return true;
1851
+ if (o1 === 0 && onSegment(p1, p2, q1))
1852
+ return true;
1853
+ if (o2 === 0 && onSegment(p1, q2, q1))
1854
+ return true;
1855
+ if (o3 === 0 && onSegment(p2, p1, q2))
1856
+ return true;
1857
+ if (o4 === 0 && onSegment(p2, q1, q2))
1858
+ return true;
1859
+ return false;
1860
+ }
1861
+ function onSegment(p, q, r) {
1862
+ 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);
1863
+ }
1864
+ function sign(num) {
1865
+ return num > 0 ? 1 : num < 0 ? -1 : 0;
1866
+ }
1867
+ function intersectsPolygon(a, b) {
1868
+ let p = a;
1869
+ do {
1870
+ 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))
1871
+ return true;
1872
+ p = p.next;
1873
+ } while (p !== a);
1874
+ return false;
1875
+ }
1876
+ function locallyInside(a, b) {
1877
+ 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;
1878
+ }
1879
+ function middleInside(a, b) {
1880
+ let p = a;
1881
+ let inside = false;
1882
+ const px = (a.x + b.x) / 2;
1883
+ const py = (a.y + b.y) / 2;
1884
+ do {
1885
+ 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)
1886
+ inside = !inside;
1887
+ p = p.next;
1888
+ } while (p !== a);
1889
+ return inside;
1890
+ }
1891
+ function splitPolygon(a, b) {
1892
+ const a2 = new Node(a.i, a.x, a.y);
1893
+ const b2 = new Node(b.i, b.x, b.y);
1894
+ const an = a.next;
1895
+ const bp = b.prev;
1896
+ a.next = b;
1897
+ b.prev = a;
1898
+ a2.next = an;
1899
+ an.prev = a2;
1900
+ b2.next = a2;
1901
+ a2.prev = b2;
1902
+ bp.next = b2;
1903
+ b2.prev = bp;
1904
+ return b2;
1905
+ }
1906
+ function insertNode(i, x, y, last) {
1907
+ const p = new Node(i, x, y);
1908
+ if (!last) {
1909
+ p.prev = p;
1910
+ p.next = p;
1911
+ } else {
1912
+ p.next = last.next;
1913
+ p.prev = last;
1914
+ last.next.prev = p;
1915
+ last.next = p;
1916
+ }
1917
+ return p;
1918
+ }
1919
+ function removeNode(p) {
1920
+ p.next.prev = p.prev;
1921
+ p.prev.next = p.next;
1922
+ if (p.prevZ)
1923
+ p.prevZ.nextZ = p.nextZ;
1924
+ if (p.nextZ)
1925
+ p.nextZ.prevZ = p.prevZ;
1926
+ }
1927
+ function Node(i, x, y) {
1928
+ this.i = i;
1929
+ this.x = x;
1930
+ this.y = y;
1931
+ this.prev = null;
1932
+ this.next = null;
1933
+ this.z = null;
1934
+ this.prevZ = null;
1935
+ this.nextZ = null;
1936
+ this.steiner = false;
1937
+ }
1938
+ var init_earcut = __esm({
1939
+ "../../node_modules/@math.gl/polygon/dist/esm/earcut.js"() {
1940
+ init_polygon_utils();
1941
+ }
1942
+ });
1943
+
1944
+ // ../../node_modules/@math.gl/polygon/dist/esm/utils.js
1945
+ var init_utils = __esm({
1946
+ "../../node_modules/@math.gl/polygon/dist/esm/utils.js"() {
1947
+ }
1948
+ });
1949
+
1950
+ // ../../node_modules/@math.gl/polygon/dist/esm/lineclip.js
1951
+ var init_lineclip = __esm({
1952
+ "../../node_modules/@math.gl/polygon/dist/esm/lineclip.js"() {
1953
+ init_utils();
1954
+ }
1955
+ });
1956
+
1957
+ // ../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js
1958
+ var init_cut_by_grid = __esm({
1959
+ "../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js"() {
1960
+ init_lineclip();
1961
+ init_utils();
1962
+ }
1963
+ });
1964
+
1965
+ // ../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js
1966
+ var init_cut_by_mercator_bounds = __esm({
1967
+ "../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js"() {
1968
+ init_cut_by_grid();
1969
+ init_utils();
1970
+ }
1971
+ });
1972
+
1973
+ // ../../node_modules/@math.gl/polygon/dist/esm/index.js
1974
+ var init_esm = __esm({
1975
+ "../../node_modules/@math.gl/polygon/dist/esm/index.js"() {
1976
+ init_polygon();
1977
+ init_polygon_utils();
1978
+ init_earcut();
1979
+ init_lineclip();
1980
+ init_cut_by_grid();
1981
+ init_cut_by_mercator_bounds();
1982
+ init_polygon();
1983
+ }
1984
+ });
1985
+
1986
+ // ../gis/src/lib/flat-geojson-to-binary.ts
1987
+ function flatGeojsonToBinary(features, geometryInfo, options) {
1988
+ const propArrayTypes = extractNumericPropTypes(features);
1989
+ const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
1990
+ return fillArrays(features, {
1991
+ propArrayTypes,
1992
+ ...geometryInfo
1993
+ }, {
1994
+ numericPropKeys: options && options.numericPropKeys || numericPropKeys,
1995
+ PositionDataType: options ? options.PositionDataType : Float32Array
1996
+ });
1997
+ }
1998
+ function extractNumericPropTypes(features) {
1999
+ const propArrayTypes = {};
2000
+ for (const feature of features) {
2001
+ if (feature.properties) {
2002
+ for (const key in feature.properties) {
2003
+ const val = feature.properties[key];
2004
+ propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
2005
+ }
2006
+ }
2007
+ }
2008
+ return propArrayTypes;
2009
+ }
2010
+ function fillArrays(features, geometryInfo, options) {
2011
+ const {
2012
+ pointPositionsCount,
2013
+ pointFeaturesCount,
2014
+ linePositionsCount,
2015
+ linePathsCount,
2016
+ lineFeaturesCount,
2017
+ polygonPositionsCount,
2018
+ polygonObjectsCount,
2019
+ polygonRingsCount,
2020
+ polygonFeaturesCount,
2021
+ propArrayTypes,
2022
+ coordLength
2023
+ } = geometryInfo;
2024
+ const { numericPropKeys = [], PositionDataType = Float32Array } = options;
2025
+ const hasGlobalId = features[0] && "id" in features[0];
2026
+ const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
2027
+ const points = {
2028
+ type: "Point",
2029
+ positions: new PositionDataType(pointPositionsCount * coordLength),
2030
+ globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
2031
+ featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
2032
+ numericProps: {},
2033
+ properties: [],
2034
+ fields: []
2035
+ };
2036
+ const lines = {
2037
+ type: "LineString",
2038
+ pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
2039
+ positions: new PositionDataType(linePositionsCount * coordLength),
2040
+ globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
2041
+ featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
2042
+ numericProps: {},
2043
+ properties: [],
2044
+ fields: []
2045
+ };
2046
+ const polygons = {
2047
+ type: "Polygon",
2048
+ polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
2049
+ primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
2050
+ positions: new PositionDataType(polygonPositionsCount * coordLength),
2051
+ triangles: [],
2052
+ globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
2053
+ featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
2054
+ numericProps: {},
2055
+ properties: [],
2056
+ fields: []
2057
+ };
2058
+ for (const object of [points, lines, polygons]) {
2059
+ for (const propName of numericPropKeys) {
2060
+ const T = propArrayTypes[propName];
2061
+ object.numericProps[propName] = new T(object.positions.length / coordLength);
2062
+ }
2063
+ }
2064
+ lines.pathIndices[linePathsCount] = linePositionsCount;
2065
+ polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
2066
+ polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
2067
+ const indexMap = {
2068
+ pointPosition: 0,
2069
+ pointFeature: 0,
2070
+ linePosition: 0,
2071
+ linePath: 0,
2072
+ lineFeature: 0,
2073
+ polygonPosition: 0,
2074
+ polygonObject: 0,
2075
+ polygonRing: 0,
2076
+ polygonFeature: 0,
2077
+ feature: 0
2078
+ };
2079
+ for (const feature of features) {
2080
+ const geometry = feature.geometry;
2081
+ const properties = feature.properties || {};
2082
+ switch (geometry.type) {
2083
+ case "Point":
2084
+ handlePoint(geometry, points, indexMap, coordLength, properties);
2085
+ points.properties.push(keepStringProperties(properties, numericPropKeys));
2086
+ if (hasGlobalId) {
2087
+ points.fields.push({ id: feature.id });
2088
+ }
2089
+ indexMap.pointFeature++;
2090
+ break;
2091
+ case "LineString":
2092
+ handleLineString(geometry, lines, indexMap, coordLength, properties);
2093
+ lines.properties.push(keepStringProperties(properties, numericPropKeys));
2094
+ if (hasGlobalId) {
2095
+ lines.fields.push({ id: feature.id });
2096
+ }
2097
+ indexMap.lineFeature++;
2098
+ break;
2099
+ case "Polygon":
2100
+ handlePolygon(geometry, polygons, indexMap, coordLength, properties);
2101
+ polygons.properties.push(keepStringProperties(properties, numericPropKeys));
2102
+ if (hasGlobalId) {
2103
+ polygons.fields.push({ id: feature.id });
2104
+ }
2105
+ indexMap.polygonFeature++;
2106
+ break;
2107
+ default:
2108
+ throw new Error("Invalid geometry type");
2109
+ }
2110
+ indexMap.feature++;
2111
+ }
2112
+ return makeAccessorObjects(points, lines, polygons, coordLength);
2113
+ }
2114
+ function handlePoint(geometry, points, indexMap, coordLength, properties) {
2115
+ points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
2116
+ const nPositions = geometry.data.length / coordLength;
2117
+ fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
2118
+ points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
2119
+ points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
2120
+ indexMap.pointPosition += nPositions;
2121
+ }
2122
+ function handleLineString(geometry, lines, indexMap, coordLength, properties) {
2123
+ lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
2124
+ const nPositions = geometry.data.length / coordLength;
2125
+ fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
2126
+ lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
2127
+ lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
2128
+ for (let i = 0, il = geometry.indices.length; i < il; ++i) {
2129
+ const start = geometry.indices[i];
2130
+ const end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
2131
+ lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
2132
+ indexMap.linePosition += (end - start) / coordLength;
2133
+ }
2134
+ }
2135
+ function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
2136
+ polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
2137
+ const nPositions = geometry.data.length / coordLength;
2138
+ fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
2139
+ polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
2140
+ polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
2141
+ for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
2142
+ const startPosition = indexMap.polygonPosition;
2143
+ polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
2144
+ const areas = geometry.areas[l];
2145
+ const indices = geometry.indices[l];
2146
+ const nextIndices = geometry.indices[l + 1];
2147
+ for (let i = 0, il = indices.length; i < il; ++i) {
2148
+ const start = indices[i];
2149
+ const end = i === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i + 1];
2150
+ polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
2151
+ indexMap.polygonPosition += (end - start) / coordLength;
2152
+ }
2153
+ const endPosition = indexMap.polygonPosition;
2154
+ triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
2155
+ }
2156
+ }
2157
+ function triangulatePolygon(polygons, areas, indices, {
2158
+ startPosition,
2159
+ endPosition,
2160
+ coordLength
2161
+ }) {
2162
+ const start = startPosition * coordLength;
2163
+ const end = endPosition * coordLength;
2164
+ const polygonPositions = polygons.positions.subarray(start, end);
2165
+ const offset = indices[0];
2166
+ const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
2167
+ const triangles = earcut(polygonPositions, holes, coordLength, areas);
2168
+ for (let t = 0, tl = triangles.length; t < tl; ++t) {
2169
+ polygons.triangles.push(startPosition + triangles[t]);
2170
+ }
2171
+ }
2172
+ function wrapProps(obj, size) {
2173
+ const returnObj = {};
2174
+ for (const key in obj) {
2175
+ returnObj[key] = { value: obj[key], size };
2176
+ }
2177
+ return returnObj;
2178
+ }
2179
+ function makeAccessorObjects(points, lines, polygons, coordLength) {
2180
+ return {
2181
+ points: {
2182
+ ...points,
2183
+ positions: { value: points.positions, size: coordLength },
2184
+ globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
2185
+ featureIds: { value: points.featureIds, size: 1 },
2186
+ numericProps: wrapProps(points.numericProps, 1)
2187
+ },
2188
+ lines: {
2189
+ ...lines,
2190
+ positions: { value: lines.positions, size: coordLength },
2191
+ pathIndices: { value: lines.pathIndices, size: 1 },
2192
+ globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
2193
+ featureIds: { value: lines.featureIds, size: 1 },
2194
+ numericProps: wrapProps(lines.numericProps, 1)
2195
+ },
2196
+ polygons: {
2197
+ ...polygons,
2198
+ positions: { value: polygons.positions, size: coordLength },
2199
+ polygonIndices: { value: polygons.polygonIndices, size: 1 },
2200
+ primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
2201
+ triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
2202
+ globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
2203
+ featureIds: { value: polygons.featureIds, size: 1 },
2204
+ numericProps: wrapProps(polygons.numericProps, 1)
2205
+ }
2206
+ };
2207
+ }
2208
+ function fillNumericProperties(object, properties, index, length) {
2209
+ for (const numericPropName in object.numericProps) {
2210
+ if (numericPropName in properties) {
2211
+ const value = properties[numericPropName];
2212
+ object.numericProps[numericPropName].fill(value, index, index + length);
2213
+ }
2214
+ }
2215
+ }
2216
+ function keepStringProperties(properties, numericKeys) {
2217
+ const props = {};
2218
+ for (const key in properties) {
2219
+ if (!numericKeys.includes(key)) {
2220
+ props[key] = properties[key];
2221
+ }
2222
+ }
2223
+ return props;
2224
+ }
2225
+ function deduceArrayType(x, constructor) {
2226
+ if (constructor === Array || !Number.isFinite(x)) {
2227
+ return Array;
2228
+ }
2229
+ return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
2230
+ }
2231
+ var init_flat_geojson_to_binary = __esm({
2232
+ "../gis/src/lib/flat-geojson-to-binary.ts"() {
2233
+ init_esm();
2234
+ }
2235
+ });
2236
+
2237
+ // ../gis/src/lib/extract-geometry-info.ts
2238
+ function extractGeometryInfo(features) {
2239
+ let pointPositionsCount = 0;
2240
+ let pointFeaturesCount = 0;
2241
+ let linePositionsCount = 0;
2242
+ let linePathsCount = 0;
2243
+ let lineFeaturesCount = 0;
2244
+ let polygonPositionsCount = 0;
2245
+ let polygonObjectsCount = 0;
2246
+ let polygonRingsCount = 0;
2247
+ let polygonFeaturesCount = 0;
2248
+ const coordLengths = new Set();
2249
+ for (const feature of features) {
2250
+ const geometry = feature.geometry;
2251
+ switch (geometry.type) {
2252
+ case "Point":
2253
+ pointFeaturesCount++;
2254
+ pointPositionsCount++;
2255
+ coordLengths.add(geometry.coordinates.length);
2256
+ break;
2257
+ case "MultiPoint":
2258
+ pointFeaturesCount++;
2259
+ pointPositionsCount += geometry.coordinates.length;
2260
+ for (const point of geometry.coordinates) {
2261
+ coordLengths.add(point.length);
2262
+ }
2263
+ break;
2264
+ case "LineString":
2265
+ lineFeaturesCount++;
2266
+ linePositionsCount += geometry.coordinates.length;
2267
+ linePathsCount++;
2268
+ for (const coord of geometry.coordinates) {
2269
+ coordLengths.add(coord.length);
2270
+ }
2271
+ break;
2272
+ case "MultiLineString":
2273
+ lineFeaturesCount++;
2274
+ for (const line of geometry.coordinates) {
2275
+ linePositionsCount += line.length;
2276
+ linePathsCount++;
2277
+ for (const coord of line) {
2278
+ coordLengths.add(coord.length);
2279
+ }
2280
+ }
2281
+ break;
2282
+ case "Polygon":
2283
+ polygonFeaturesCount++;
2284
+ polygonObjectsCount++;
2285
+ polygonRingsCount += geometry.coordinates.length;
2286
+ const flattened = geometry.coordinates.flat();
2287
+ polygonPositionsCount += flattened.length;
2288
+ for (const coord of flattened) {
2289
+ coordLengths.add(coord.length);
2290
+ }
2291
+ break;
2292
+ case "MultiPolygon":
2293
+ polygonFeaturesCount++;
2294
+ for (const polygon of geometry.coordinates) {
2295
+ polygonObjectsCount++;
2296
+ polygonRingsCount += polygon.length;
2297
+ const flattened2 = polygon.flat();
2298
+ polygonPositionsCount += flattened2.length;
2299
+ for (const coord of flattened2) {
2300
+ coordLengths.add(coord.length);
2301
+ }
2302
+ }
2303
+ break;
2304
+ default:
2305
+ throw new Error(`Unsupported geometry type: ${geometry.type}`);
2306
+ }
2307
+ }
2308
+ return {
2309
+ coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
2310
+ pointPositionsCount,
2311
+ pointFeaturesCount,
2312
+ linePositionsCount,
2313
+ linePathsCount,
2314
+ lineFeaturesCount,
2315
+ polygonPositionsCount,
2316
+ polygonObjectsCount,
2317
+ polygonRingsCount,
2318
+ polygonFeaturesCount
2319
+ };
2320
+ }
2321
+ var init_extract_geometry_info = __esm({
2322
+ "../gis/src/lib/extract-geometry-info.ts"() {
2323
+ }
2324
+ });
2325
+
2326
+ // ../gis/src/lib/geojson-to-flat-geojson.ts
2327
+ function geojsonToFlatGeojson(features, options = { coordLength: 2, fixRingWinding: true }) {
2328
+ return features.map((feature) => flattenFeature(feature, options));
2329
+ }
2330
+ function flattenPoint(coordinates, data, indices, options) {
2331
+ indices.push(data.length);
2332
+ data.push(...coordinates);
2333
+ for (let i = coordinates.length; i < options.coordLength; i++) {
2334
+ data.push(0);
2335
+ }
2336
+ }
2337
+ function flattenLineString(coordinates, data, indices, options) {
2338
+ indices.push(data.length);
2339
+ for (const c of coordinates) {
2340
+ data.push(...c);
2341
+ for (let i = c.length; i < options.coordLength; i++) {
2342
+ data.push(0);
2343
+ }
2344
+ }
2345
+ }
2346
+ function flattenPolygon(coordinates, data, indices, areas, options) {
2347
+ let count = 0;
2348
+ const ringAreas = [];
2349
+ const polygons = [];
2350
+ for (const lineString of coordinates) {
2351
+ const lineString2d = lineString.map((p) => p.slice(0, 2));
2352
+ let area2 = getPolygonSignedArea(lineString2d.flat());
2353
+ const ccw = area2 < 0;
2354
+ if (options.fixRingWinding && (count === 0 && !ccw || count > 0 && ccw)) {
2355
+ lineString.reverse();
2356
+ area2 = -area2;
2357
+ }
2358
+ ringAreas.push(area2);
2359
+ flattenLineString(lineString, data, polygons, options);
2360
+ count++;
2361
+ }
2362
+ if (count > 0) {
2363
+ areas.push(ringAreas);
2364
+ indices.push(polygons);
2365
+ }
2366
+ }
2367
+ function flattenFeature(feature, options) {
2368
+ const { geometry } = feature;
2369
+ if (geometry.type === "GeometryCollection") {
2370
+ throw new Error("GeometryCollection type not supported");
2371
+ }
2372
+ const data = [];
2373
+ const indices = [];
2374
+ let areas;
2375
+ let type;
2376
+ switch (geometry.type) {
2377
+ case "Point":
2378
+ type = "Point";
2379
+ flattenPoint(geometry.coordinates, data, indices, options);
2380
+ break;
2381
+ case "MultiPoint":
2382
+ type = "Point";
2383
+ geometry.coordinates.map((c) => flattenPoint(c, data, indices, options));
2384
+ break;
2385
+ case "LineString":
2386
+ type = "LineString";
2387
+ flattenLineString(geometry.coordinates, data, indices, options);
2388
+ break;
2389
+ case "MultiLineString":
2390
+ type = "LineString";
2391
+ geometry.coordinates.map((c) => flattenLineString(c, data, indices, options));
2392
+ break;
2393
+ case "Polygon":
2394
+ type = "Polygon";
2395
+ areas = [];
2396
+ flattenPolygon(geometry.coordinates, data, indices, areas, options);
2397
+ break;
2398
+ case "MultiPolygon":
2399
+ type = "Polygon";
2400
+ areas = [];
2401
+ geometry.coordinates.map((c) => flattenPolygon(c, data, indices, areas, options));
2402
+ break;
2403
+ default:
2404
+ throw new Error(`Unknown type: ${type}`);
2405
+ }
2406
+ return { ...feature, geometry: { type, indices, data, areas } };
2407
+ }
2408
+ var init_geojson_to_flat_geojson = __esm({
2409
+ "../gis/src/lib/geojson-to-flat-geojson.ts"() {
2410
+ init_esm();
2411
+ }
2412
+ });
2413
+
2414
+ // ../gis/src/lib/geojson-to-binary.ts
2415
+ function geojsonToBinary(features, options = { fixRingWinding: true }) {
2416
+ const geometryInfo = extractGeometryInfo(features);
2417
+ const coordLength = geometryInfo.coordLength;
2418
+ const { fixRingWinding } = options;
2419
+ const flatFeatures = geojsonToFlatGeojson(features, { coordLength, fixRingWinding });
2420
+ return flatGeojsonToBinary(flatFeatures, geometryInfo, {
2421
+ numericPropKeys: options.numericPropKeys,
2422
+ PositionDataType: options.PositionDataType || Float32Array
2423
+ });
2424
+ }
2425
+ var init_geojson_to_binary = __esm({
2426
+ "../gis/src/lib/geojson-to-binary.ts"() {
2427
+ init_extract_geometry_info();
2428
+ init_geojson_to_flat_geojson();
2429
+ init_flat_geojson_to_binary();
2430
+ }
2431
+ });
2432
+
2433
+ // ../gis/src/index.ts
2434
+ var init_src3 = __esm({
2435
+ "../gis/src/index.ts"() {
2436
+ init_geojson_to_binary();
2437
+ }
2438
+ });
2439
+
2440
+ // src/geojson-loader.ts
2441
+ async function parse3(arrayBuffer, options) {
2442
+ return parseTextSync3(new TextDecoder().decode(arrayBuffer), options);
2443
+ }
2444
+ function parseTextSync3(text, options) {
2445
+ options = { ...DEFAULT_GEOJSON_LOADER_OPTIONS, ...options };
2446
+ options.json = { ...DEFAULT_GEOJSON_LOADER_OPTIONS.geojson, ...options.geojson };
2447
+ options.gis = options.gis || {};
2448
+ const json = parseJSONSync(text, options);
2449
+ switch (options.gis.format) {
2450
+ case "binary":
2451
+ return geojsonToBinary(json);
2452
+ default:
2453
+ return json;
2454
+ }
2455
+ }
2456
+ function parseInBatches3(asyncIterator, options) {
2457
+ options = { ...DEFAULT_GEOJSON_LOADER_OPTIONS, ...options };
2458
+ options.json = { ...DEFAULT_GEOJSON_LOADER_OPTIONS.geojson, ...options.geojson };
2459
+ const geojsonIterator = parseJSONInBatches(asyncIterator, options);
2460
+ switch (options.gis.format) {
2461
+ case "binary":
2462
+ return makeBinaryGeometryIterator(geojsonIterator);
2463
+ default:
2464
+ return geojsonIterator;
2465
+ }
2466
+ }
2467
+ async function* makeBinaryGeometryIterator(geojsonIterator) {
2468
+ for await (const batch of geojsonIterator) {
2469
+ batch.data = geojsonToBinary(batch.data);
2470
+ yield batch;
2471
+ }
2472
+ }
2473
+ var VERSION3, DEFAULT_GEOJSON_LOADER_OPTIONS, GeoJSONWorkerLoader, GeoJSONLoader;
2474
+ var init_geojson_loader = __esm({
2475
+ "src/geojson-loader.ts"() {
2476
+ init_src3();
2477
+ init_parse_json();
2478
+ init_parse_json_in_batches();
2479
+ VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2480
+ DEFAULT_GEOJSON_LOADER_OPTIONS = {
2481
+ geojson: {
2482
+ shape: "object-row-table"
2483
+ },
2484
+ json: {
2485
+ jsonpaths: ["$", "$.features"]
2486
+ },
2487
+ gis: {
2488
+ format: "geojson"
2489
+ }
2490
+ };
2491
+ GeoJSONWorkerLoader = {
2492
+ name: "GeoJSON",
2493
+ id: "geojson",
2494
+ module: "geojson",
2495
+ version: VERSION3,
2496
+ worker: true,
2497
+ extensions: ["geojson"],
2498
+ mimeTypes: ["application/geo+json"],
2499
+ category: "geometry",
2500
+ text: true,
2501
+ options: DEFAULT_GEOJSON_LOADER_OPTIONS
2502
+ };
2503
+ GeoJSONLoader = {
2504
+ ...GeoJSONWorkerLoader,
2505
+ parse: parse3,
2506
+ parseTextSync: parseTextSync3,
2507
+ parseInBatches: parseInBatches3
2508
+ };
2509
+ }
2510
+ });
2511
+
2512
+ // src/index.ts
2513
+ var src_exports = {};
2514
+ __export(src_exports, {
2515
+ JSONLoader: () => JSONLoader,
2516
+ NDJSONLoader: () => NDJSONLoader,
2517
+ _ClarinetParser: () => ClarinetParser,
2518
+ _GeoJSONLoader: () => GeoJSONLoader,
2519
+ _GeoJSONWorkerLoader: () => GeoJSONWorkerLoader,
2520
+ _JSONPath: () => JSONPath,
2521
+ _rebuildJsonObject: () => rebuildJsonObject
2522
+ });
2523
+ var init_src4 = __esm({
2524
+ "src/index.ts"() {
2525
+ init_json_loader();
2526
+ init_ndjson_loader();
2527
+ init_geojson_loader();
2528
+ init_jsonpath();
2529
+ init_clarinet();
2530
+ init_parse_json_in_batches();
2531
+ }
2532
+ });
2533
+
2534
+ // src/bundle.ts
2535
+ var require_bundle = __commonJS({
2536
+ "src/bundle.ts"(exports, module) {
2537
+ var moduleExports = (init_src4(), src_exports);
2538
+ globalThis.loaders = globalThis.loaders || {};
2539
+ module.exports = Object.assign(globalThis.loaders, moduleExports);
2540
+ }
2541
+ });
2542
+ require_bundle();
2543
+ })();