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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +4 -2
  2. package/THIRD-PARTY-NOTICES.md +1 -1
  3. package/dist/dot-loader-types.cjs +60 -0
  4. package/dist/dot-loader-types.cjs.map +7 -0
  5. package/dist/dot-loader-types.d.ts +4 -2
  6. package/dist/dot-loader-types.d.ts.map +1 -1
  7. package/dist/dot-loader-types.js +3 -2
  8. package/dist/dot-loader-types.js.map +1 -1
  9. package/dist/dot-loader.cjs +15 -295
  10. package/dist/dot-loader.cjs.map +2 -2
  11. package/dist/dot-loader.d.ts +2 -1
  12. package/dist/dot-loader.d.ts.map +1 -1
  13. package/dist/dot-loader.js +3 -3
  14. package/dist/dot-loader.js.map +1 -1
  15. package/dist/gexf-loader-types.cjs +60 -0
  16. package/dist/gexf-loader-types.cjs.map +7 -0
  17. package/dist/gexf-loader-types.d.ts +4 -2
  18. package/dist/gexf-loader-types.d.ts.map +1 -1
  19. package/dist/gexf-loader-types.js +3 -2
  20. package/dist/gexf-loader-types.js.map +1 -1
  21. package/dist/gexf-loader.cjs +1652 -287
  22. package/dist/gexf-loader.cjs.map +3 -3
  23. package/dist/gexf-loader.d.ts +2 -1
  24. package/dist/gexf-loader.d.ts.map +1 -1
  25. package/dist/gexf-loader.js +3 -3
  26. package/dist/gexf-loader.js.map +1 -1
  27. package/dist/graph-types.d.ts +3 -2
  28. package/dist/graph-types.d.ts.map +1 -1
  29. package/dist/graphml-loader-types.cjs +60 -0
  30. package/dist/graphml-loader-types.cjs.map +7 -0
  31. package/dist/graphml-loader-types.d.ts +4 -2
  32. package/dist/graphml-loader-types.d.ts.map +1 -1
  33. package/dist/graphml-loader-types.js +3 -2
  34. package/dist/graphml-loader-types.js.map +1 -1
  35. package/dist/graphml-loader.cjs +1633 -280
  36. package/dist/graphml-loader.cjs.map +3 -3
  37. package/dist/graphml-loader.d.ts +2 -1
  38. package/dist/graphml-loader.d.ts.map +1 -1
  39. package/dist/graphml-loader.js +3 -3
  40. package/dist/graphml-loader.js.map +1 -1
  41. package/dist/index.cjs +36 -1930
  42. package/dist/index.cjs.map +4 -3
  43. package/dist/lib/build-graph-tables.d.ts.map +1 -1
  44. package/dist/lib/build-graph-tables.js +2 -4
  45. package/dist/lib/build-graph-tables.js.map +1 -1
  46. package/dist/lib/parse-gexf.d.ts.map +1 -1
  47. package/dist/lib/parse-gexf.js +10 -8
  48. package/dist/lib/parse-gexf.js.map +1 -1
  49. package/dist/lib/parse-graphml.js +4 -4
  50. package/dist/lib/parse-graphml.js.map +1 -1
  51. package/package.json +9 -7
  52. package/src/dot-loader-types.ts +2 -1
  53. package/src/dot-loader.ts +3 -3
  54. package/src/gexf-loader-types.ts +2 -1
  55. package/src/gexf-loader.ts +3 -3
  56. package/src/graph-types.ts +3 -2
  57. package/src/graphml-loader-types.ts +2 -1
  58. package/src/graphml-loader.ts +3 -3
  59. package/src/lib/build-graph-tables.ts +5 -7
  60. package/src/lib/parse-gexf.ts +10 -8
  61. package/src/lib/parse-graphml.ts +5 -5
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __esm = (fn, res, err) => function __init() {
9
7
  if (err) throw err[0];
@@ -25,14 +23,6 @@ var __copyProps = (to, from, except, desc) => {
25
23
  }
26
24
  return to;
27
25
  };
28
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
- // If the importer is in node compatibility mode or this is not an ESM
30
- // file that has been converted to a CommonJS file using a Babel-
31
- // compatible transform (i.e. "__esModule" has not been set), then set
32
- // "default" to the CommonJS "module.exports" for node compatibility.
33
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
- mod
35
- ));
36
26
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
27
 
38
28
  // src/graphml-loader-types.ts
@@ -54,279 +44,1645 @@ var init_graphml_loader_types = __esm({
54
44
  mimeTypes: ["application/graphml+xml"],
55
45
  text: true,
56
46
  worker: false,
47
+ supportsNativeArrow: true,
57
48
  dataType: null,
58
49
  batchType: null,
59
- options: { graphml: { shape: "arrow-table" } },
50
+ options: { graphml: { shape: "arrow" } },
60
51
  preload
61
52
  };
62
53
  }
63
54
  });
64
55
 
65
- // ../core/src/schema-utils/lib/schema/convert-arrow-schema.ts
66
- function convertArrowToSchema(arrowSchema) {
67
- return serializeArrowSchema(arrowSchema);
56
+ // ../documents/src/lib/xml-utils/uncapitalize.ts
57
+ function uncapitalize(str) {
58
+ return typeof str === "string" ? str.charAt(0).toLowerCase() + str.slice(1) : str;
68
59
  }
69
- function serializeArrowSchema(arrowSchema) {
70
- return {
71
- fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
72
- metadata: serializeArrowMetadata(arrowSchema.metadata)
73
- };
74
- }
75
- function serializeArrowMetadata(arrowMetadata) {
76
- return Object.fromEntries(arrowMetadata);
77
- }
78
- function serializeArrowField(field) {
79
- return {
80
- name: field.name,
81
- type: serializeArrowType(field.type),
82
- nullable: field.nullable,
83
- metadata: serializeArrowMetadata(field.metadata)
84
- };
85
- }
86
- function serializeArrowType(arrowType) {
87
- if (isArrowViewType(arrowType, "BinaryView")) {
88
- return "binary-view";
60
+ function uncapitalizeKeys(object) {
61
+ if (Array.isArray(object)) {
62
+ return object.map((element) => uncapitalizeKeys(element));
63
+ }
64
+ if (object && typeof object === "object") {
65
+ const newObject = {};
66
+ for (const [key, value] of Object.entries(object)) {
67
+ Object.defineProperty(newObject, uncapitalize(key), {
68
+ value: uncapitalizeKeys(value),
69
+ enumerable: true,
70
+ configurable: true,
71
+ writable: true
72
+ });
73
+ }
74
+ return newObject;
89
75
  }
90
- if (isArrowViewType(arrowType, "Utf8View")) {
91
- return "utf8-view";
76
+ return object;
77
+ }
78
+ var init_uncapitalize = __esm({
79
+ "../documents/src/lib/xml-utils/uncapitalize.ts"() {
80
+ "use strict";
92
81
  }
93
- if (isOptionalArrowType(arrowType, "LargeList")) {
94
- const largeListType = arrowType;
95
- return {
96
- type: "large-list",
97
- children: [serializeArrowField(largeListType.valueField)]
82
+ });
83
+
84
+ // ../documents/src/sax-ts/sax.ts
85
+ var DEFAULT_SAX_EVENTS, DEFAULT_SAX_PARSER_OPTIONS, EVENTS, BUFFERS, nameStart, nameBody, entityStart, entityBody, ENTITIES, SAX, SAXParser;
86
+ var init_sax = __esm({
87
+ "../documents/src/sax-ts/sax.ts"() {
88
+ "use strict";
89
+ DEFAULT_SAX_EVENTS = {
90
+ ontext: () => {
91
+ },
92
+ onprocessinginstruction: () => {
93
+ },
94
+ onsgmldeclaration: () => {
95
+ },
96
+ ondoctype: () => {
97
+ },
98
+ oncomment: () => {
99
+ },
100
+ onopentagstart: () => {
101
+ },
102
+ onattribute: () => {
103
+ },
104
+ onopentag: () => {
105
+ },
106
+ onclosetag: () => {
107
+ },
108
+ onopencdata: () => {
109
+ },
110
+ oncdata: () => {
111
+ },
112
+ onclosecdata: () => {
113
+ },
114
+ onerror: () => {
115
+ },
116
+ onend: () => {
117
+ },
118
+ onready: () => {
119
+ },
120
+ onscript: () => {
121
+ },
122
+ onopennamespace: () => {
123
+ },
124
+ onclosenamespace: () => {
125
+ }
98
126
  };
99
- }
100
- switch (arrowType.constructor) {
101
- case arrow.Null:
102
- return "null";
103
- case arrow.Binary:
104
- return "binary";
105
- case arrow.FixedSizeBinary:
106
- return {
107
- type: "fixed-size-binary",
108
- byteWidth: arrowType.byteWidth
127
+ DEFAULT_SAX_PARSER_OPTIONS = {
128
+ ...DEFAULT_SAX_EVENTS,
129
+ strict: false,
130
+ MAX_BUFFER_LENGTH: 64 * 1024,
131
+ lowercase: false,
132
+ lowercasetags: false,
133
+ noscript: false,
134
+ strictEntities: false,
135
+ preserveCase: false,
136
+ caseInsensitiveTags: false,
137
+ processEntities: true,
138
+ xmlns: void 0,
139
+ position: void 0,
140
+ trim: void 0,
141
+ normalize: void 0
142
+ };
143
+ EVENTS = [
144
+ "text",
145
+ "processinginstruction",
146
+ "sgmldeclaration",
147
+ "doctype",
148
+ "comment",
149
+ "opentagstart",
150
+ "attribute",
151
+ "opentag",
152
+ "closetag",
153
+ "opencdata",
154
+ "cdata",
155
+ "closecdata",
156
+ "error",
157
+ "end",
158
+ "ready",
159
+ "script",
160
+ "opennamespace",
161
+ "closenamespace"
162
+ ];
163
+ BUFFERS = [
164
+ "comment",
165
+ "sgmlDecl",
166
+ "textNode",
167
+ "tagName",
168
+ "doctype",
169
+ "procInstName",
170
+ "procInstBody",
171
+ "entity",
172
+ "attribName",
173
+ "attribValue",
174
+ "cdata",
175
+ "script"
176
+ ];
177
+ nameStart = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;
178
+ nameBody = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/;
179
+ entityStart = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;
180
+ entityBody = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/;
181
+ ENTITIES = {
182
+ amp: "&",
183
+ gt: ">",
184
+ lt: "<",
185
+ quot: '"',
186
+ apos: "'",
187
+ AElig: 198,
188
+ Aacute: 193,
189
+ Acirc: 194,
190
+ Agrave: 192,
191
+ Aring: 197,
192
+ Atilde: 195,
193
+ Auml: 196,
194
+ Ccedil: 199,
195
+ ETH: 208,
196
+ Eacute: 201,
197
+ Ecirc: 202,
198
+ Egrave: 200,
199
+ Euml: 203,
200
+ Iacute: 205,
201
+ Icirc: 206,
202
+ Igrave: 204,
203
+ Iuml: 207,
204
+ Ntilde: 209,
205
+ Oacute: 211,
206
+ Ocirc: 212,
207
+ Ograve: 210,
208
+ Oslash: 216,
209
+ Otilde: 213,
210
+ Ouml: 214,
211
+ THORN: 222,
212
+ Uacute: 218,
213
+ Ucirc: 219,
214
+ Ugrave: 217,
215
+ Uuml: 220,
216
+ Yacute: 221,
217
+ aacute: 225,
218
+ acirc: 226,
219
+ aelig: 230,
220
+ agrave: 224,
221
+ aring: 229,
222
+ atilde: 227,
223
+ auml: 228,
224
+ ccedil: 231,
225
+ eacute: 233,
226
+ ecirc: 234,
227
+ egrave: 232,
228
+ eth: 240,
229
+ euml: 235,
230
+ iacute: 237,
231
+ icirc: 238,
232
+ igrave: 236,
233
+ iuml: 239,
234
+ ntilde: 241,
235
+ oacute: 243,
236
+ ocirc: 244,
237
+ ograve: 242,
238
+ oslash: 248,
239
+ otilde: 245,
240
+ ouml: 246,
241
+ szlig: 223,
242
+ thorn: 254,
243
+ uacute: 250,
244
+ ucirc: 251,
245
+ ugrave: 249,
246
+ uuml: 252,
247
+ yacute: 253,
248
+ yuml: 255,
249
+ copy: 169,
250
+ reg: 174,
251
+ nbsp: 160,
252
+ iexcl: 161,
253
+ cent: 162,
254
+ pound: 163,
255
+ curren: 164,
256
+ yen: 165,
257
+ brvbar: 166,
258
+ sect: 167,
259
+ uml: 168,
260
+ ordf: 170,
261
+ laquo: 171,
262
+ not: 172,
263
+ shy: 173,
264
+ macr: 175,
265
+ deg: 176,
266
+ plusmn: 177,
267
+ sup1: 185,
268
+ sup2: 178,
269
+ sup3: 179,
270
+ acute: 180,
271
+ micro: 181,
272
+ para: 182,
273
+ middot: 183,
274
+ cedil: 184,
275
+ ordm: 186,
276
+ raquo: 187,
277
+ frac14: 188,
278
+ frac12: 189,
279
+ frac34: 190,
280
+ iquest: 191,
281
+ times: 215,
282
+ divide: 247,
283
+ OElig: 338,
284
+ oelig: 339,
285
+ Scaron: 352,
286
+ scaron: 353,
287
+ Yuml: 376,
288
+ fnof: 402,
289
+ circ: 710,
290
+ tilde: 732,
291
+ Alpha: 913,
292
+ Beta: 914,
293
+ Gamma: 915,
294
+ Delta: 916,
295
+ Epsilon: 917,
296
+ Zeta: 918,
297
+ Eta: 919,
298
+ Theta: 920,
299
+ Iota: 921,
300
+ Kappa: 922,
301
+ Lambda: 923,
302
+ Mu: 924,
303
+ Nu: 925,
304
+ Xi: 926,
305
+ Omicron: 927,
306
+ Pi: 928,
307
+ Rho: 929,
308
+ Sigma: 931,
309
+ Tau: 932,
310
+ Upsilon: 933,
311
+ Phi: 934,
312
+ Chi: 935,
313
+ Psi: 936,
314
+ Omega: 937,
315
+ alpha: 945,
316
+ beta: 946,
317
+ gamma: 947,
318
+ delta: 948,
319
+ epsilon: 949,
320
+ zeta: 950,
321
+ eta: 951,
322
+ theta: 952,
323
+ iota: 953,
324
+ kappa: 954,
325
+ lambda: 955,
326
+ mu: 956,
327
+ nu: 957,
328
+ xi: 958,
329
+ omicron: 959,
330
+ pi: 960,
331
+ rho: 961,
332
+ sigmaf: 962,
333
+ sigma: 963,
334
+ tau: 964,
335
+ upsilon: 965,
336
+ phi: 966,
337
+ chi: 967,
338
+ psi: 968,
339
+ omega: 969,
340
+ thetasym: 977,
341
+ upsih: 978,
342
+ piv: 982,
343
+ ensp: 8194,
344
+ emsp: 8195,
345
+ thinsp: 8201,
346
+ zwnj: 8204,
347
+ zwj: 8205,
348
+ lrm: 8206,
349
+ rlm: 8207,
350
+ ndash: 8211,
351
+ mdash: 8212,
352
+ lsquo: 8216,
353
+ rsquo: 8217,
354
+ sbquo: 8218,
355
+ ldquo: 8220,
356
+ rdquo: 8221,
357
+ bdquo: 8222,
358
+ dagger: 8224,
359
+ Dagger: 8225,
360
+ bull: 8226,
361
+ hellip: 8230,
362
+ permil: 8240,
363
+ prime: 8242,
364
+ Prime: 8243,
365
+ lsaquo: 8249,
366
+ rsaquo: 8250,
367
+ oline: 8254,
368
+ frasl: 8260,
369
+ euro: 8364,
370
+ image: 8465,
371
+ weierp: 8472,
372
+ real: 8476,
373
+ trade: 8482,
374
+ alefsym: 8501,
375
+ larr: 8592,
376
+ uarr: 8593,
377
+ rarr: 8594,
378
+ darr: 8595,
379
+ harr: 8596,
380
+ crarr: 8629,
381
+ lArr: 8656,
382
+ uArr: 8657,
383
+ rArr: 8658,
384
+ dArr: 8659,
385
+ hArr: 8660,
386
+ forall: 8704,
387
+ part: 8706,
388
+ exist: 8707,
389
+ empty: 8709,
390
+ nabla: 8711,
391
+ isin: 8712,
392
+ notin: 8713,
393
+ ni: 8715,
394
+ prod: 8719,
395
+ sum: 8721,
396
+ minus: 8722,
397
+ lowast: 8727,
398
+ radic: 8730,
399
+ prop: 8733,
400
+ infin: 8734,
401
+ ang: 8736,
402
+ and: 8743,
403
+ or: 8744,
404
+ cap: 8745,
405
+ cup: 8746,
406
+ int: 8747,
407
+ there4: 8756,
408
+ sim: 8764,
409
+ cong: 8773,
410
+ asymp: 8776,
411
+ ne: 8800,
412
+ equiv: 8801,
413
+ le: 8804,
414
+ ge: 8805,
415
+ sub: 8834,
416
+ sup: 8835,
417
+ nsub: 8836,
418
+ sube: 8838,
419
+ supe: 8839,
420
+ oplus: 8853,
421
+ otimes: 8855,
422
+ perp: 8869,
423
+ sdot: 8901,
424
+ lceil: 8968,
425
+ rceil: 8969,
426
+ lfloor: 8970,
427
+ rfloor: 8971,
428
+ lang: 9001,
429
+ rang: 9002,
430
+ loz: 9674,
431
+ spades: 9824,
432
+ clubs: 9827,
433
+ hearts: 9829,
434
+ diams: 9830
435
+ };
436
+ Object.keys(ENTITIES).forEach((key) => {
437
+ const e = ENTITIES[key];
438
+ ENTITIES[key] = typeof e === "number" ? String.fromCharCode(e) : e;
439
+ });
440
+ SAX = class _SAX {
441
+ EVENTS = EVENTS;
442
+ ENTITIES = {
443
+ // TODO: make it readonly, needed for entity-mega test
444
+ // amp, gt, lt, quot and apos are resolved to strings instead of numerical
445
+ // codes, IDK why
446
+ ...ENTITIES
109
447
  };
110
- case arrow.Bool:
111
- return "bool";
112
- case arrow.Int:
113
- const intType = arrowType;
114
- return `${intType.isSigned ? "" : "u"}int${intType.bitWidth}`;
115
- case arrow.Int8:
116
- return "int8";
117
- case arrow.Int16:
118
- return "int16";
119
- case arrow.Int32:
120
- return "int32";
121
- case arrow.Int64:
122
- return "int64";
123
- case arrow.Uint8:
124
- return "uint8";
125
- case arrow.Uint16:
126
- return "uint16";
127
- case arrow.Uint32:
128
- return "uint32";
129
- case arrow.Uint64:
130
- return "uint64";
131
- case arrow.Float:
132
- const precision = arrowType.precision;
133
- switch (precision) {
134
- case arrow.Precision.HALF:
135
- return "float16";
136
- case arrow.Precision.SINGLE:
137
- return "float32";
138
- case arrow.Precision.DOUBLE:
139
- return "float64";
140
- default:
141
- return "float16";
142
- }
143
- case arrow.Float16:
144
- return "float16";
145
- case arrow.Float32:
146
- return "float32";
147
- case arrow.Float64:
148
- return "float64";
149
- case arrow.Utf8:
150
- return "utf8";
151
- case arrow.Decimal:
152
- const decimal = arrowType;
153
- return {
154
- type: "decimal",
155
- bitWidth: decimal.bitWidth,
156
- precision: decimal.precision,
157
- scale: decimal.scale
448
+ XML_ENTITIES = {
449
+ amp: "&",
450
+ gt: ">",
451
+ lt: "<",
452
+ quot: '"',
453
+ apos: "'"
454
+ };
455
+ S = 0;
456
+ opt;
457
+ trackPosition = false;
458
+ column = 0;
459
+ line = 0;
460
+ c = "";
461
+ error;
462
+ q = "";
463
+ bufferCheckPosition;
464
+ closed = false;
465
+ tags = [];
466
+ looseCase = "";
467
+ closedRoot = false;
468
+ sawRoot = false;
469
+ strict = false;
470
+ tag;
471
+ strictEntities;
472
+ state;
473
+ noscript = false;
474
+ attribList = [];
475
+ ns;
476
+ position = 0;
477
+ STATE = {
478
+ BEGIN: this.S++,
479
+ // leading byte order mark or whitespace
480
+ BEGIN_WHITESPACE: this.S++,
481
+ // leading whitespace
482
+ TEXT: this.S++,
483
+ // general stuff
484
+ TEXT_ENTITY: this.S++,
485
+ // &amp and such.
486
+ OPEN_WAKA: this.S++,
487
+ // <
488
+ SGML_DECL: this.S++,
489
+ // <!BLARG
490
+ SGML_DECL_QUOTED: this.S++,
491
+ // <!BLARG foo "bar
492
+ DOCTYPE: this.S++,
493
+ // <!DOCTYPE
494
+ DOCTYPE_QUOTED: this.S++,
495
+ // <!DOCTYPE "//blah
496
+ DOCTYPE_DTD: this.S++,
497
+ // <!DOCTYPE "//blah" [ ...
498
+ DOCTYPE_DTD_QUOTED: this.S++,
499
+ // <!DOCTYPE "//blah" [ "foo
500
+ COMMENT_STARTING: this.S++,
501
+ // <!-
502
+ COMMENT: this.S++,
503
+ // <!--
504
+ COMMENT_ENDING: this.S++,
505
+ // <!-- blah -
506
+ COMMENT_ENDED: this.S++,
507
+ // <!-- blah --
508
+ CDATA: this.S++,
509
+ // <![CDATA[ something
510
+ CDATA_ENDING: this.S++,
511
+ // ]
512
+ CDATA_ENDING_2: this.S++,
513
+ // ]]
514
+ PROC_INST: this.S++,
515
+ // <?hi
516
+ PROC_INST_BODY: this.S++,
517
+ // <?hi there
518
+ PROC_INST_ENDING: this.S++,
519
+ // <?hi "there" ?
520
+ OPEN_TAG: this.S++,
521
+ // <strong
522
+ OPEN_TAG_SLASH: this.S++,
523
+ // <strong /
524
+ ATTRIB: this.S++,
525
+ // <a
526
+ ATTRIB_NAME: this.S++,
527
+ // <a foo
528
+ ATTRIB_NAME_SAW_WHITE: this.S++,
529
+ // <a foo _
530
+ ATTRIB_VALUE: this.S++,
531
+ // <a foo=
532
+ ATTRIB_VALUE_QUOTED: this.S++,
533
+ // <a foo="bar
534
+ ATTRIB_VALUE_CLOSED: this.S++,
535
+ // <a foo="bar"
536
+ ATTRIB_VALUE_UNQUOTED: this.S++,
537
+ // <a foo=bar
538
+ ATTRIB_VALUE_ENTITY_Q: this.S++,
539
+ // <foo bar="&quot;"
540
+ ATTRIB_VALUE_ENTITY_U: this.S++,
541
+ // <foo bar=&quot
542
+ CLOSE_TAG: this.S++,
543
+ // </a
544
+ CLOSE_TAG_SAW_WHITE: this.S++,
545
+ // </a >
546
+ SCRIPT: this.S++,
547
+ // <script> ...
548
+ SCRIPT_ENDING: this.S++
549
+ // <script> ... <
550
+ };
551
+ BUFFERS = BUFFERS;
552
+ // private parser: (strict: boolean, opt: any) => SAXParser;
553
+ CDATA = "[CDATA[";
554
+ DOCTYPE = "DOCTYPE";
555
+ XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
556
+ XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
557
+ rootNS = {
558
+ xml: this.XML_NAMESPACE,
559
+ xmlns: this.XMLNS_NAMESPACE
158
560
  };
159
- case arrow.Date_:
160
- const dateUnit = arrowType.unit;
161
- return dateUnit === arrow.DateUnit.DAY ? "date-day" : "date-millisecond";
162
- case arrow.DateDay:
163
- return "date-day";
164
- case arrow.DateMillisecond:
165
- return "date-millisecond";
166
- case arrow.Time:
167
- const timeUnit = arrowType.unit;
168
- switch (timeUnit) {
169
- case arrow.TimeUnit.SECOND:
170
- return "time-second";
171
- case arrow.TimeUnit.MILLISECOND:
172
- return "time-millisecond";
173
- case arrow.TimeUnit.MICROSECOND:
174
- return "time-microsecond";
175
- case arrow.TimeUnit.NANOSECOND:
176
- return "time-nanosecond";
177
- default:
178
- return "time-second";
561
+ comment;
562
+ sgmlDecl;
563
+ textNode = "";
564
+ tagName;
565
+ doctype;
566
+ procInstName;
567
+ procInstBody;
568
+ entity = "";
569
+ attribName;
570
+ attribValue;
571
+ cdata = "";
572
+ script = "";
573
+ startTagPosition = 0;
574
+ constructor() {
575
+ this.S = 0;
576
+ for (const s in this.STATE) {
577
+ if (this.STATE.hasOwnProperty(s)) {
578
+ this.STATE[this.STATE[s]] = s;
579
+ }
580
+ }
581
+ this.S = this.STATE;
179
582
  }
180
- case arrow.TimeMillisecond:
181
- return "time-millisecond";
182
- case arrow.TimeSecond:
183
- return "time-second";
184
- case arrow.TimeMicrosecond:
185
- return "time-microsecond";
186
- case arrow.TimeNanosecond:
187
- return "time-nanosecond";
188
- case arrow.Timestamp:
189
- const timeStampUnit = arrowType.unit;
190
- switch (timeStampUnit) {
191
- case arrow.TimeUnit.SECOND:
192
- return "timestamp-second";
193
- case arrow.TimeUnit.MILLISECOND:
194
- return "timestamp-millisecond";
195
- case arrow.TimeUnit.MICROSECOND:
196
- return "timestamp-microsecond";
197
- case arrow.TimeUnit.NANOSECOND:
198
- return "timestamp-nanosecond";
199
- default:
200
- return "timestamp-second";
583
+ static charAt(chunk, i) {
584
+ let result = "";
585
+ if (i < chunk.length) {
586
+ result = chunk.charAt(i);
587
+ }
588
+ return result;
201
589
  }
202
- case arrow.TimestampSecond:
203
- return "timestamp-second";
204
- case arrow.TimestampMillisecond:
205
- return "timestamp-millisecond";
206
- case arrow.TimestampMicrosecond:
207
- return "timestamp-microsecond";
208
- case arrow.TimestampNanosecond:
209
- return "timestamp-nanosecond";
210
- case arrow.Interval:
211
- const intervalUnit = arrowType.unit;
212
- switch (intervalUnit) {
213
- case arrow.IntervalUnit.DAY_TIME:
214
- return "interval-daytime";
215
- case arrow.IntervalUnit.YEAR_MONTH:
216
- return "interval-yearmonth";
217
- default:
218
- return "interval-daytime";
590
+ static isWhitespace(c) {
591
+ return c === " " || c === "\n" || c === "\r" || c === " ";
219
592
  }
220
- case arrow.IntervalDayTime:
221
- return "interval-daytime";
222
- case arrow.IntervalYearMonth:
223
- return "interval-yearmonth";
224
- case arrow.Map_:
225
- const mapType = arrowType;
226
- return {
227
- type: "map",
228
- keysSorted: mapType.keysSorted,
229
- children: mapType.children.map((arrowField) => serializeArrowField(arrowField))
230
- };
231
- case arrow.List:
232
- const listType = arrowType;
233
- const listField = listType.valueField;
234
- return {
235
- type: "list",
236
- children: [serializeArrowField(listField)]
237
- };
238
- case arrow.FixedSizeList:
239
- const fixedSizeList = arrowType;
240
- return {
241
- type: "fixed-size-list",
242
- listSize: fixedSizeList.listSize,
243
- children: [serializeArrowField(fixedSizeList.children[0])]
244
- };
245
- case arrow.Struct:
246
- const structType = arrowType;
247
- return {
248
- type: "struct",
249
- children: structType.children.map((arrowField) => serializeArrowField(arrowField))
250
- };
251
- case arrow.SparseUnion:
252
- case arrow.DenseUnion:
253
- const unionType = arrowType;
254
- return {
255
- type: unionType instanceof arrow.DenseUnion ? "dense-union" : "sparse-union",
256
- typeIds: unionType.typeIds,
257
- children: unionType.children.map((arrowField) => serializeArrowField(arrowField)),
258
- typeIdToChildIndex: { ...unionType.typeIdToChildIndex }
259
- };
260
- case arrow.Dictionary:
261
- const dictionaryType = arrowType;
262
- return {
263
- type: "dictionary",
264
- id: dictionaryType.id,
265
- indices: serializeArrowDictionaryKeyType(dictionaryType.indices),
266
- dictionary: serializeArrowType(dictionaryType.dictionary),
267
- isOrdered: dictionaryType.isOrdered
268
- };
269
- default:
270
- throw new Error(`arrow type not supported: ${arrowType.constructor.name}`);
593
+ static isQuote(c) {
594
+ return c === '"' || c === "'";
595
+ }
596
+ static isAttribEnd(c) {
597
+ return c === ">" || _SAX.isWhitespace(c);
598
+ }
599
+ static isMatch(regex, c) {
600
+ return regex.test(c);
601
+ }
602
+ static notMatch(regex, c) {
603
+ return !_SAX.isMatch(regex, c);
604
+ }
605
+ static qname(name, attribute) {
606
+ const i = name.indexOf(":");
607
+ const qualName = i < 0 ? ["", name] : name.split(":");
608
+ let prefix = qualName[0];
609
+ let local = qualName[1];
610
+ if (attribute && name === "xmlns") {
611
+ prefix = "xmlns";
612
+ local = "";
613
+ }
614
+ return { prefix, local };
615
+ }
616
+ write(chunk) {
617
+ if (this.error) {
618
+ throw this.error;
619
+ }
620
+ if (this.closed) {
621
+ return this.errorFunction("Cannot write after close. Assign an onready handler.");
622
+ }
623
+ if (chunk === null) {
624
+ return this.end();
625
+ }
626
+ if (typeof chunk === "object") {
627
+ chunk = chunk.toString();
628
+ }
629
+ let i = 0;
630
+ let c;
631
+ while (true) {
632
+ c = _SAX.charAt(chunk, i++);
633
+ this.c = c;
634
+ if (!c) {
635
+ break;
636
+ }
637
+ if (this.trackPosition) {
638
+ this.position++;
639
+ if (c === "\n") {
640
+ this.line++;
641
+ this.column = 0;
642
+ } else {
643
+ this.column++;
644
+ }
645
+ }
646
+ switch (this.state) {
647
+ case this.S.BEGIN:
648
+ this.state = this.S.BEGIN_WHITESPACE;
649
+ if (c === "\uFEFF") {
650
+ continue;
651
+ }
652
+ this.beginWhiteSpace(c);
653
+ continue;
654
+ case this.S.BEGIN_WHITESPACE:
655
+ this.beginWhiteSpace(c);
656
+ continue;
657
+ case this.S.TEXT:
658
+ if (this.sawRoot && !this.closedRoot) {
659
+ const starti = i - 1;
660
+ while (c && c !== "<" && c !== "&") {
661
+ c = _SAX.charAt(chunk, i++);
662
+ if (c && this.trackPosition) {
663
+ this.position++;
664
+ if (c === "\n") {
665
+ this.line++;
666
+ this.column = 0;
667
+ } else {
668
+ this.column++;
669
+ }
670
+ }
671
+ }
672
+ this.textNode += chunk.substring(starti, i - 1);
673
+ }
674
+ if (c === "<" && !(this.sawRoot && this.closedRoot && !this.strict)) {
675
+ this.state = this.S.OPEN_WAKA;
676
+ this.startTagPosition = this.position;
677
+ } else {
678
+ if (!_SAX.isWhitespace(c) && (!this.sawRoot || this.closedRoot)) {
679
+ this.strictFail("Text data outside of root node.");
680
+ }
681
+ if (c === "&") {
682
+ this.state = this.S.TEXT_ENTITY;
683
+ } else {
684
+ this.textNode += c;
685
+ }
686
+ }
687
+ continue;
688
+ case this.S.SCRIPT:
689
+ if (c === "<") {
690
+ this.state = this.S.SCRIPT_ENDING;
691
+ } else {
692
+ this.script += c;
693
+ }
694
+ continue;
695
+ case this.S.SCRIPT_ENDING:
696
+ if (c === "/") {
697
+ this.state = this.S.CLOSE_TAG;
698
+ } else {
699
+ this.script += `<${c}`;
700
+ this.state = this.S.SCRIPT;
701
+ }
702
+ continue;
703
+ case this.S.OPEN_WAKA:
704
+ if (c === "!") {
705
+ this.state = this.S.SGML_DECL;
706
+ this.sgmlDecl = "";
707
+ } else if (_SAX.isWhitespace(c)) {
708
+ } else if (_SAX.isMatch(nameStart, c)) {
709
+ this.state = this.S.OPEN_TAG;
710
+ this.tagName = c;
711
+ } else if (c === "/") {
712
+ this.state = this.S.CLOSE_TAG;
713
+ this.tagName = "";
714
+ } else if (c === "?") {
715
+ this.state = this.S.PROC_INST;
716
+ this.procInstName = this.procInstBody = "";
717
+ } else {
718
+ this.strictFail("Unencoded <");
719
+ if (this.startTagPosition + 1 < this.position) {
720
+ const pad = this.position - this.startTagPosition;
721
+ c = new Array(pad).join(" ") + c;
722
+ }
723
+ this.textNode += `<${c}`;
724
+ this.state = this.S.TEXT;
725
+ }
726
+ continue;
727
+ case this.S.SGML_DECL:
728
+ if ((this.sgmlDecl + c).toUpperCase() === this.CDATA) {
729
+ this.emitNode("onopencdata");
730
+ this.state = this.S.CDATA;
731
+ this.sgmlDecl = "";
732
+ this.cdata = "";
733
+ } else if (this.sgmlDecl + c === "--") {
734
+ this.state = this.S.COMMENT;
735
+ this.comment = "";
736
+ this.sgmlDecl = "";
737
+ } else if ((this.sgmlDecl + c).toUpperCase() === this.DOCTYPE) {
738
+ this.state = this.S.DOCTYPE;
739
+ if (this.doctype || this.sawRoot) {
740
+ this.strictFail("Inappropriately located doctype declaration");
741
+ }
742
+ this.doctype = "";
743
+ this.sgmlDecl = "";
744
+ } else if (c === ">") {
745
+ this.emitNode("onsgmldeclaration", this.sgmlDecl);
746
+ this.sgmlDecl = "";
747
+ this.state = this.S.TEXT;
748
+ } else if (_SAX.isQuote(c)) {
749
+ this.state = this.S.SGML_DECL_QUOTED;
750
+ this.sgmlDecl += c;
751
+ } else {
752
+ this.sgmlDecl += c;
753
+ }
754
+ continue;
755
+ case this.S.SGML_DECL_QUOTED:
756
+ if (c === this.q) {
757
+ this.state = this.S.SGML_DECL;
758
+ this.q = "";
759
+ }
760
+ this.sgmlDecl += c;
761
+ continue;
762
+ case this.S.DOCTYPE:
763
+ if (c === ">") {
764
+ this.state = this.S.TEXT;
765
+ this.emitNode("ondoctype", this.doctype);
766
+ this.doctype = true;
767
+ } else {
768
+ this.doctype += c;
769
+ if (c === "[") {
770
+ this.state = this.S.DOCTYPE_DTD;
771
+ } else if (_SAX.isQuote(c)) {
772
+ this.state = this.S.DOCTYPE_QUOTED;
773
+ this.q = c;
774
+ }
775
+ }
776
+ continue;
777
+ case this.S.DOCTYPE_QUOTED:
778
+ this.doctype += c;
779
+ if (c === this.q) {
780
+ this.q = "";
781
+ this.state = this.S.DOCTYPE;
782
+ }
783
+ continue;
784
+ case this.S.DOCTYPE_DTD:
785
+ this.doctype += c;
786
+ if (c === "]") {
787
+ this.state = this.S.DOCTYPE;
788
+ } else if (_SAX.isQuote(c)) {
789
+ this.state = this.S.DOCTYPE_DTD_QUOTED;
790
+ this.q = c;
791
+ }
792
+ continue;
793
+ case this.S.DOCTYPE_DTD_QUOTED:
794
+ this.doctype += c;
795
+ if (c === this.q) {
796
+ this.state = this.S.DOCTYPE_DTD;
797
+ this.q = "";
798
+ }
799
+ continue;
800
+ case this.S.COMMENT:
801
+ if (c === "-") {
802
+ this.state = this.S.COMMENT_ENDING;
803
+ } else {
804
+ this.comment += c;
805
+ }
806
+ continue;
807
+ case this.S.COMMENT_ENDING:
808
+ if (c === "-") {
809
+ this.state = this.S.COMMENT_ENDED;
810
+ this.comment = this.textApplyOptions(this.comment);
811
+ if (this.comment) {
812
+ this.emitNode("oncomment", this.comment);
813
+ }
814
+ this.comment = "";
815
+ } else {
816
+ this.comment += `-${c}`;
817
+ this.state = this.S.COMMENT;
818
+ }
819
+ continue;
820
+ case this.S.COMMENT_ENDED:
821
+ if (c !== ">") {
822
+ this.strictFail("Malformed comment");
823
+ this.comment += `--${c}`;
824
+ this.state = this.S.COMMENT;
825
+ } else {
826
+ this.state = this.S.TEXT;
827
+ }
828
+ continue;
829
+ case this.S.CDATA:
830
+ if (c === "]") {
831
+ this.state = this.S.CDATA_ENDING;
832
+ } else {
833
+ this.cdata += c;
834
+ }
835
+ continue;
836
+ case this.S.CDATA_ENDING:
837
+ if (c === "]") {
838
+ this.state = this.S.CDATA_ENDING_2;
839
+ } else {
840
+ this.cdata += `]${c}`;
841
+ this.state = this.S.CDATA;
842
+ }
843
+ continue;
844
+ case this.S.CDATA_ENDING_2:
845
+ if (c === ">") {
846
+ if (this.cdata) {
847
+ this.emitNode("oncdata", this.cdata);
848
+ }
849
+ this.emitNode("onclosecdata");
850
+ this.cdata = "";
851
+ this.state = this.S.TEXT;
852
+ } else if (c === "]") {
853
+ this.cdata += "]";
854
+ } else {
855
+ this.cdata += `]]${c}`;
856
+ this.state = this.S.CDATA;
857
+ }
858
+ continue;
859
+ case this.S.PROC_INST:
860
+ if (c === "?") {
861
+ this.state = this.S.PROC_INST_ENDING;
862
+ } else if (_SAX.isWhitespace(c)) {
863
+ this.state = this.S.PROC_INST_BODY;
864
+ } else {
865
+ this.procInstName += c;
866
+ }
867
+ continue;
868
+ case this.S.PROC_INST_BODY:
869
+ if (!this.procInstBody && _SAX.isWhitespace(c)) {
870
+ continue;
871
+ } else if (c === "?") {
872
+ this.state = this.S.PROC_INST_ENDING;
873
+ } else {
874
+ this.procInstBody += c;
875
+ }
876
+ continue;
877
+ case this.S.PROC_INST_ENDING:
878
+ if (c === ">") {
879
+ this.emitNode("onprocessinginstruction", {
880
+ name: this.procInstName,
881
+ body: this.procInstBody
882
+ });
883
+ this.procInstName = this.procInstBody = "";
884
+ this.state = this.S.TEXT;
885
+ } else {
886
+ this.procInstBody += `?${c}`;
887
+ this.state = this.S.PROC_INST_BODY;
888
+ }
889
+ continue;
890
+ case this.S.OPEN_TAG:
891
+ if (_SAX.isMatch(nameBody, c)) {
892
+ this.tagName += c;
893
+ } else {
894
+ this.newTag();
895
+ if (c === ">") {
896
+ this.openTag();
897
+ } else if (c === "/") {
898
+ this.state = this.S.OPEN_TAG_SLASH;
899
+ } else {
900
+ if (!_SAX.isWhitespace(c)) {
901
+ this.strictFail("Invalid character in tag name");
902
+ }
903
+ this.state = this.S.ATTRIB;
904
+ }
905
+ }
906
+ continue;
907
+ case this.S.OPEN_TAG_SLASH:
908
+ if (c === ">") {
909
+ this.openTag(true);
910
+ this.closeTag();
911
+ } else {
912
+ this.strictFail("Forward-slash in opening tag not followed by >");
913
+ this.state = this.S.ATTRIB;
914
+ }
915
+ continue;
916
+ case this.S.ATTRIB:
917
+ if (_SAX.isWhitespace(c)) {
918
+ continue;
919
+ } else if (c === ">") {
920
+ this.openTag();
921
+ } else if (c === "/") {
922
+ this.state = this.S.OPEN_TAG_SLASH;
923
+ } else if (_SAX.isMatch(nameStart, c)) {
924
+ this.attribName = c;
925
+ this.attribValue = "";
926
+ this.state = this.S.ATTRIB_NAME;
927
+ } else {
928
+ this.strictFail("Invalid attribute name");
929
+ }
930
+ continue;
931
+ case this.S.ATTRIB_NAME:
932
+ if (c === "=") {
933
+ this.state = this.S.ATTRIB_VALUE;
934
+ } else if (c === ">") {
935
+ this.strictFail("Attribute without value");
936
+ this.attribValue = this.attribName;
937
+ this.attrib();
938
+ this.openTag();
939
+ } else if (_SAX.isWhitespace(c)) {
940
+ this.state = this.S.ATTRIB_NAME_SAW_WHITE;
941
+ } else if (_SAX.isMatch(nameBody, c)) {
942
+ this.attribName += c;
943
+ } else {
944
+ this.strictFail("Invalid attribute name");
945
+ }
946
+ continue;
947
+ case this.S.ATTRIB_NAME_SAW_WHITE:
948
+ if (c === "=") {
949
+ this.state = this.S.ATTRIB_VALUE;
950
+ } else if (_SAX.isWhitespace(c)) {
951
+ continue;
952
+ } else {
953
+ this.strictFail("Attribute without value");
954
+ Object.defineProperty(this.tag.attributes, this.attribName, {
955
+ value: "",
956
+ enumerable: true,
957
+ configurable: true,
958
+ writable: true
959
+ });
960
+ this.attribValue = "";
961
+ this.emitNode("onattribute", {
962
+ name: this.attribName,
963
+ value: ""
964
+ });
965
+ this.attribName = "";
966
+ if (c === ">") {
967
+ this.openTag();
968
+ } else if (_SAX.isMatch(nameStart, c)) {
969
+ this.attribName = c;
970
+ this.state = this.S.ATTRIB_NAME;
971
+ } else {
972
+ this.strictFail("Invalid attribute name");
973
+ this.state = this.S.ATTRIB;
974
+ }
975
+ }
976
+ continue;
977
+ case this.S.ATTRIB_VALUE:
978
+ if (_SAX.isWhitespace(c)) {
979
+ continue;
980
+ } else if (_SAX.isQuote(c)) {
981
+ this.q = c;
982
+ this.state = this.S.ATTRIB_VALUE_QUOTED;
983
+ } else {
984
+ this.strictFail("Unquoted attribute value");
985
+ this.state = this.S.ATTRIB_VALUE_UNQUOTED;
986
+ this.attribValue = c;
987
+ }
988
+ continue;
989
+ case this.S.ATTRIB_VALUE_QUOTED:
990
+ if (c !== this.q) {
991
+ if (c === "&") {
992
+ this.state = this.S.ATTRIB_VALUE_ENTITY_Q;
993
+ } else {
994
+ this.attribValue += c;
995
+ }
996
+ continue;
997
+ }
998
+ this.attrib();
999
+ this.q = "";
1000
+ this.state = this.S.ATTRIB_VALUE_CLOSED;
1001
+ continue;
1002
+ case this.S.ATTRIB_VALUE_CLOSED:
1003
+ if (_SAX.isWhitespace(c)) {
1004
+ this.state = this.S.ATTRIB;
1005
+ } else if (c === ">") {
1006
+ this.openTag();
1007
+ } else if (c === "/") {
1008
+ this.state = this.S.OPEN_TAG_SLASH;
1009
+ } else if (_SAX.isMatch(nameStart, c)) {
1010
+ this.strictFail("No whitespace between attributes");
1011
+ this.attribName = c;
1012
+ this.attribValue = "";
1013
+ this.state = this.S.ATTRIB_NAME;
1014
+ } else {
1015
+ this.strictFail("Invalid attribute name");
1016
+ }
1017
+ continue;
1018
+ case this.S.ATTRIB_VALUE_UNQUOTED:
1019
+ if (!_SAX.isAttribEnd(c)) {
1020
+ if (c === "&") {
1021
+ this.state = this.S.ATTRIB_VALUE_ENTITY_U;
1022
+ } else {
1023
+ this.attribValue += c;
1024
+ }
1025
+ continue;
1026
+ }
1027
+ this.attrib();
1028
+ if (c === ">") {
1029
+ this.openTag();
1030
+ } else {
1031
+ this.state = this.S.ATTRIB;
1032
+ }
1033
+ continue;
1034
+ case this.S.CLOSE_TAG:
1035
+ if (!this.tagName) {
1036
+ if (_SAX.isWhitespace(c)) {
1037
+ continue;
1038
+ } else if (_SAX.notMatch(nameStart, c)) {
1039
+ if (this.script) {
1040
+ this.script += `</${c}`;
1041
+ this.state = this.S.SCRIPT;
1042
+ } else {
1043
+ this.strictFail("Invalid tagname in closing tag.");
1044
+ }
1045
+ } else {
1046
+ this.tagName = c;
1047
+ }
1048
+ } else if (c === ">") {
1049
+ this.closeTag();
1050
+ } else if (_SAX.isMatch(nameBody, c)) {
1051
+ this.tagName += c;
1052
+ } else if (this.script) {
1053
+ this.script += `</${this.tagName}`;
1054
+ this.tagName = "";
1055
+ this.state = this.S.SCRIPT;
1056
+ } else {
1057
+ if (!_SAX.isWhitespace(c)) {
1058
+ this.strictFail("Invalid tagname in closing tag");
1059
+ }
1060
+ this.state = this.S.CLOSE_TAG_SAW_WHITE;
1061
+ }
1062
+ continue;
1063
+ case this.S.CLOSE_TAG_SAW_WHITE:
1064
+ if (_SAX.isWhitespace(c)) {
1065
+ continue;
1066
+ }
1067
+ if (c === ">") {
1068
+ this.closeTag();
1069
+ } else {
1070
+ this.strictFail("Invalid characters in closing tag");
1071
+ }
1072
+ continue;
1073
+ case this.S.TEXT_ENTITY:
1074
+ case this.S.ATTRIB_VALUE_ENTITY_Q:
1075
+ case this.S.ATTRIB_VALUE_ENTITY_U:
1076
+ let returnState;
1077
+ let buffer;
1078
+ switch (this.state) {
1079
+ case this.S.TEXT_ENTITY:
1080
+ returnState = this.S.TEXT;
1081
+ buffer = "textNode";
1082
+ break;
1083
+ case this.S.ATTRIB_VALUE_ENTITY_Q:
1084
+ returnState = this.S.ATTRIB_VALUE_QUOTED;
1085
+ buffer = "attribValue";
1086
+ break;
1087
+ case this.S.ATTRIB_VALUE_ENTITY_U:
1088
+ returnState = this.S.ATTRIB_VALUE_UNQUOTED;
1089
+ buffer = "attribValue";
1090
+ break;
1091
+ default:
1092
+ throw new Error(`Unknown state: ${this.state}`);
1093
+ }
1094
+ if (c === ";") {
1095
+ this[buffer] += this.parseEntity();
1096
+ this.entity = "";
1097
+ this.state = returnState;
1098
+ } else if (_SAX.isMatch(this.entity.length ? entityBody : entityStart, c)) {
1099
+ this.entity += c;
1100
+ } else {
1101
+ this.strictFail("Invalid character in entity name");
1102
+ this[buffer] += `&${this.entity}${c}`;
1103
+ this.entity = "";
1104
+ this.state = returnState;
1105
+ }
1106
+ continue;
1107
+ default:
1108
+ throw new Error(`Unknown state: ${this.state}`);
1109
+ }
1110
+ }
1111
+ if (this.position >= this.bufferCheckPosition) {
1112
+ this.checkBufferLength();
1113
+ }
1114
+ return this;
1115
+ }
1116
+ emit(event, data) {
1117
+ if (this.events.hasOwnProperty(event)) {
1118
+ const eventName = event.replace(/^on/, "");
1119
+ this.events[event](data, eventName, this);
1120
+ }
1121
+ }
1122
+ clearBuffers() {
1123
+ for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
1124
+ this[this[i]] = "";
1125
+ }
1126
+ }
1127
+ flushBuffers() {
1128
+ this.closeText();
1129
+ if (this.cdata !== "") {
1130
+ this.emitNode("oncdata", this.cdata);
1131
+ this.cdata = "";
1132
+ }
1133
+ if (this.script !== "") {
1134
+ this.emitNode("onscript", this.script);
1135
+ this.script = "";
1136
+ }
1137
+ }
1138
+ end() {
1139
+ if (this.sawRoot && !this.closedRoot) this.strictFail("Unclosed root tag");
1140
+ if (this.strict && this.state !== this.S.BEGIN && this.state !== this.S.BEGIN_WHITESPACE && this.state !== this.S.TEXT) {
1141
+ this.errorFunction("Unexpected end");
1142
+ }
1143
+ this.closeText();
1144
+ this.c = "";
1145
+ this.closed = true;
1146
+ this.emit("onend");
1147
+ return new SAXParser(this.opt);
1148
+ }
1149
+ errorFunction(er) {
1150
+ this.closeText();
1151
+ if (this.trackPosition) {
1152
+ er += `
1153
+ Line: ${this.line}
1154
+ Column: ${this.column}
1155
+ Char: ${this.c}`;
1156
+ }
1157
+ const error = new Error(er);
1158
+ this.error = error;
1159
+ this.emit("onerror", error);
1160
+ return this;
1161
+ }
1162
+ attrib() {
1163
+ if (!this.strict && !this.opt.preserveCase) {
1164
+ this.attribName = this.attribName[this.looseCase]();
1165
+ }
1166
+ if (this.attribList.indexOf(this.attribName) !== -1 || Object.hasOwn(this.tag.attributes, this.attribName)) {
1167
+ this.strictFail("Duplicate attribute");
1168
+ this.attribName = this.attribValue = "";
1169
+ return;
1170
+ }
1171
+ if (this.opt.xmlns) {
1172
+ const qn = _SAX.qname(this.attribName, true);
1173
+ const prefix = qn.prefix;
1174
+ const local = qn.local;
1175
+ if (prefix === "xmlns") {
1176
+ if (local === "xml" && this.attribValue !== this.XML_NAMESPACE) {
1177
+ this.strictFail(
1178
+ `xml: prefix must be bound to ${this.XML_NAMESPACE}
1179
+ Actual: ${this.attribValue}`
1180
+ );
1181
+ } else if (local === "xmlns" && this.attribValue !== this.XMLNS_NAMESPACE) {
1182
+ this.strictFail(
1183
+ `xmlns: prefix must be bound to ${this.XMLNS_NAMESPACE}
1184
+ Actual: ${this.attribValue}`
1185
+ );
1186
+ } else {
1187
+ const tag = this.tag;
1188
+ const parent = this.tags[this.tags.length - 1] || this;
1189
+ if (tag.ns === parent.ns) {
1190
+ tag.ns = Object.create(parent.ns);
1191
+ }
1192
+ tag.ns[local] = this.attribValue;
1193
+ }
1194
+ }
1195
+ this.attribList.push([this.attribName, this.attribValue]);
1196
+ } else {
1197
+ Object.defineProperty(this.tag.attributes, this.attribName, {
1198
+ value: this.attribValue,
1199
+ enumerable: true,
1200
+ configurable: true,
1201
+ writable: true
1202
+ });
1203
+ this.emitNode("onattribute", {
1204
+ name: this.attribName,
1205
+ value: this.attribValue
1206
+ });
1207
+ }
1208
+ this.attribName = this.attribValue = "";
1209
+ }
1210
+ newTag() {
1211
+ if (!this.strict && !this.opt.preserveCase) this.tagName = this.tagName[this.looseCase]();
1212
+ const parent = this.tags[this.tags.length - 1] || this;
1213
+ const tag = { name: this.tagName, attributes: {} };
1214
+ this.tag = tag;
1215
+ if (this.opt.xmlns) {
1216
+ tag.ns = parent.ns;
1217
+ }
1218
+ this.attribList.length = 0;
1219
+ this.emitNode("onopentagstart", tag);
1220
+ }
1221
+ /** Validates an entity before optionally preserving its authored spelling. */
1222
+ parseEntity() {
1223
+ const decoded = this.decodeEntity();
1224
+ return this.opt.processEntities === false ? `&${this.entity};` : decoded;
1225
+ }
1226
+ /** Decodes predefined, configured, or numeric entities without resolving document types. */
1227
+ decodeEntity() {
1228
+ let entity = this.entity;
1229
+ const entityLC = entity.toLowerCase();
1230
+ let num = NaN;
1231
+ let numStr = "";
1232
+ if (typeof this.ENTITIES[entity] === "string" || typeof this.ENTITIES[entity] === "number") {
1233
+ return this.ENTITIES[entity];
1234
+ }
1235
+ if (typeof this.ENTITIES[entityLC] === "string" || typeof this.ENTITIES[entityLC] === "number") {
1236
+ return this.ENTITIES[entityLC];
1237
+ }
1238
+ entity = entityLC;
1239
+ if (entity.charAt(0) === "#") {
1240
+ if (entity.charAt(1) === "x") {
1241
+ entity = entity.slice(2);
1242
+ num = parseInt(entity, 16);
1243
+ numStr = num.toString(16);
1244
+ } else {
1245
+ entity = entity.slice(1);
1246
+ num = parseInt(entity, 10);
1247
+ numStr = num.toString(10);
1248
+ }
1249
+ }
1250
+ entity = entity.replace(/^0+/, "");
1251
+ if (Number.isNaN(num) || numStr.toLowerCase() !== entity) {
1252
+ this.strictFail("Invalid character entity");
1253
+ return `&${this.entity};`;
1254
+ }
1255
+ if (num < 0 || num > 1114111 || num >= 55296 && num <= 57343 || num < 32 && ![9, 10, 13].includes(num) || num === 65534 || num === 65535) {
1256
+ this.strictFail("Invalid character entity");
1257
+ return `&${this.entity};`;
1258
+ }
1259
+ return String.fromCodePoint(num);
1260
+ }
1261
+ beginWhiteSpace(c) {
1262
+ if (c === "<") {
1263
+ this.state = this.S.OPEN_WAKA;
1264
+ this.startTagPosition = this.position;
1265
+ } else if (!_SAX.isWhitespace(c)) {
1266
+ this.strictFail("Non-whitespace before first tag.");
1267
+ this.textNode = c;
1268
+ this.state = this.S.TEXT;
1269
+ } else {
1270
+ }
1271
+ }
1272
+ strictFail(message) {
1273
+ if (typeof this !== "object" || !(this instanceof SAXParser)) {
1274
+ throw new Error("bad call to strictFail");
1275
+ }
1276
+ if (this.strict) {
1277
+ this.errorFunction(message);
1278
+ }
1279
+ }
1280
+ textApplyOptions(text) {
1281
+ if (this.opt.trim) text = text.trim();
1282
+ if (this.opt.normalize) text = text.replace(/\s+/g, " ");
1283
+ return text;
1284
+ }
1285
+ emitNode(nodeType, data) {
1286
+ if (this.textNode) this.closeText();
1287
+ this.emit(nodeType, data);
1288
+ }
1289
+ closeText() {
1290
+ this.textNode = this.textApplyOptions(this.textNode);
1291
+ if (this.textNode !== void 0 && this.textNode !== "" && this.textNode !== "undefined") {
1292
+ this.emit("ontext", this.textNode);
1293
+ }
1294
+ this.textNode = "";
1295
+ }
1296
+ checkBufferLength() {
1297
+ var _a;
1298
+ const maxAllowed = Math.max(this.opt.MAX_BUFFER_LENGTH, 10);
1299
+ let maxActual = 0;
1300
+ for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
1301
+ const len = ((_a = this[this.BUFFERS[i]]) == null ? void 0 : _a.length) || 0;
1302
+ if (len > maxAllowed) {
1303
+ switch (this.BUFFERS[i]) {
1304
+ case "textNode":
1305
+ this.closeText();
1306
+ break;
1307
+ case "cdata":
1308
+ this.emitNode("oncdata", this.cdata);
1309
+ this.cdata = "";
1310
+ break;
1311
+ case "script":
1312
+ this.emitNode("onscript", this.script);
1313
+ this.script = "";
1314
+ break;
1315
+ default:
1316
+ this.errorFunction(`Max buffer length exceeded: ${this.BUFFERS[i]}`);
1317
+ }
1318
+ }
1319
+ maxActual = Math.max(maxActual, len);
1320
+ }
1321
+ const m = this.opt.MAX_BUFFER_LENGTH - maxActual;
1322
+ this.bufferCheckPosition = m + this.position;
1323
+ }
1324
+ openTag(selfClosing) {
1325
+ if (this.opt.xmlns) {
1326
+ const tag = this.tag;
1327
+ const qn = _SAX.qname(this.tagName);
1328
+ tag.prefix = qn.prefix;
1329
+ tag.local = qn.local;
1330
+ tag.uri = tag.ns[qn.prefix] || "";
1331
+ if (tag.prefix && !tag.uri) {
1332
+ this.strictFail(`Unbound namespace prefix: ${JSON.stringify(this.tagName)}`);
1333
+ tag.uri = qn.prefix;
1334
+ }
1335
+ const parent = this.tags[this.tags.length - 1] || this;
1336
+ if (tag.ns && parent.ns !== tag.ns) {
1337
+ const that = this;
1338
+ Object.keys(tag.ns).forEach((p) => {
1339
+ that.emitNode("onopennamespace", {
1340
+ prefix: p,
1341
+ uri: tag.ns[p]
1342
+ });
1343
+ });
1344
+ }
1345
+ for (let i = 0, l = this.attribList.length; i < l; i++) {
1346
+ const nv = this.attribList[i];
1347
+ const name = nv[0];
1348
+ const value = nv[1];
1349
+ const qualName = _SAX.qname(name, true);
1350
+ const prefix = qualName.prefix;
1351
+ const local = qualName.local;
1352
+ const uri = prefix === "" ? "" : tag.ns[prefix] || "";
1353
+ const a = {
1354
+ name,
1355
+ value,
1356
+ prefix,
1357
+ local,
1358
+ uri
1359
+ };
1360
+ if (prefix && prefix !== "xmlns" && !uri) {
1361
+ this.strictFail(`Unbound namespace prefix: ${JSON.stringify(prefix)}`);
1362
+ a.uri = prefix;
1363
+ }
1364
+ Object.defineProperty(this.tag.attributes, name, {
1365
+ value: a,
1366
+ enumerable: true,
1367
+ configurable: true,
1368
+ writable: true
1369
+ });
1370
+ this.emitNode("onattribute", a);
1371
+ }
1372
+ this.attribList.length = 0;
1373
+ }
1374
+ this.tag.isSelfClosing = Boolean(selfClosing);
1375
+ this.sawRoot = true;
1376
+ this.tags.push(this.tag);
1377
+ this.emitNode("onopentag", this.tag);
1378
+ if (!selfClosing) {
1379
+ if (!this.noscript && this.tagName.toLowerCase() === "script") {
1380
+ this.state = this.S.SCRIPT;
1381
+ } else {
1382
+ this.state = this.S.TEXT;
1383
+ }
1384
+ this.tag = null;
1385
+ this.tagName = "";
1386
+ }
1387
+ this.attribName = this.attribValue = "";
1388
+ this.attribList.length = 0;
1389
+ }
1390
+ closeTag() {
1391
+ if (!this.tagName) {
1392
+ this.strictFail("Weird empty close tag.");
1393
+ this.textNode += "</>";
1394
+ this.state = this.S.TEXT;
1395
+ return;
1396
+ }
1397
+ const caseInsensitiveTags = !this.strict && (this.opt.caseInsensitiveTags || !this.opt.preserveCase);
1398
+ if (this.script) {
1399
+ const normalizedScriptCloseTag = caseInsensitiveTags ? this.tagName.toLowerCase() : this.tagName;
1400
+ if (normalizedScriptCloseTag !== "script") {
1401
+ this.script += `</${this.tagName}>`;
1402
+ this.tagName = "";
1403
+ this.state = this.S.SCRIPT;
1404
+ return;
1405
+ }
1406
+ this.emitNode("onscript", this.script);
1407
+ this.script = "";
1408
+ }
1409
+ let t = this.tags.length;
1410
+ let tagName = this.tagName;
1411
+ const normalizedTagName = caseInsensitiveTags ? tagName.toLowerCase() : tagName;
1412
+ while (t--) {
1413
+ const close = this.tags[t];
1414
+ const normalizedOpenTagName = caseInsensitiveTags ? close.name.toLowerCase() : close.name;
1415
+ if (normalizedOpenTagName !== normalizedTagName) {
1416
+ this.strictFail("Unexpected close tag");
1417
+ } else {
1418
+ break;
1419
+ }
1420
+ }
1421
+ if (t < 0) {
1422
+ this.strictFail(`Unmatched closing tag: ${this.tagName}`);
1423
+ this.textNode += `</${this.tagName}>`;
1424
+ this.state = this.S.TEXT;
1425
+ return;
1426
+ }
1427
+ this.tagName = tagName;
1428
+ let s = this.tags.length;
1429
+ while (s-- > t) {
1430
+ const tag = this.tags.pop();
1431
+ this.tag = tag;
1432
+ this.tagName = this.tag.name;
1433
+ this.emitNode("onclosetag", this.tagName);
1434
+ const x = {};
1435
+ for (const i in tag.ns) {
1436
+ if (tag.ns.hasOwnProperty(i)) {
1437
+ x[i] = tag.ns[i];
1438
+ }
1439
+ }
1440
+ const parent = this.tags[this.tags.length - 1] || this;
1441
+ if (this.opt.xmlns && tag.ns !== parent.ns) {
1442
+ const that = this;
1443
+ Object.keys(tag.ns).forEach((p) => {
1444
+ const n = tag.ns[p];
1445
+ that.emitNode("onclosenamespace", { prefix: p, uri: n });
1446
+ });
1447
+ }
1448
+ }
1449
+ if (t === 0) this.closedRoot = true;
1450
+ this.tagName = this.attribValue = this.attribName = "";
1451
+ this.attribList.length = 0;
1452
+ this.state = this.S.TEXT;
1453
+ }
1454
+ };
1455
+ SAXParser = class extends SAX {
1456
+ static ENTITIES = ENTITIES;
1457
+ opt = DEFAULT_SAX_PARSER_OPTIONS;
1458
+ events = DEFAULT_SAX_EVENTS;
1459
+ constructor(opt) {
1460
+ super();
1461
+ this.clearBuffers();
1462
+ this.opt = opt = { ...this.opt, ...opt };
1463
+ this.events = { ...this.events, ...opt };
1464
+ this.q = this.c = "";
1465
+ this.opt.lowercase = this.opt.lowercase || this.opt.lowercasetags;
1466
+ this.bufferCheckPosition = this.opt.MAX_BUFFER_LENGTH;
1467
+ this.looseCase = this.opt.lowercase ? "toLowerCase" : "toUpperCase";
1468
+ this.tags = [];
1469
+ this.closed = this.closedRoot = this.sawRoot = false;
1470
+ this.tag = this.error = null;
1471
+ this.strict = Boolean(this.opt.strict);
1472
+ this.noscript = Boolean(this.opt.strict || this.opt.noscript);
1473
+ this.state = this.S.BEGIN;
1474
+ this.strictEntities = this.opt.strictEntities;
1475
+ this.ENTITIES = this.strictEntities ? Object.create(this.XML_ENTITIES) : Object.create(this.ENTITIES);
1476
+ this.attribList = [];
1477
+ if (this.opt.xmlns) {
1478
+ this.ns = Object.create(this.rootNS);
1479
+ }
1480
+ this.trackPosition = this.opt.position !== false;
1481
+ if (this.trackPosition) {
1482
+ this.position = this.line = this.column = 0;
1483
+ }
1484
+ this.emit("onready");
1485
+ }
1486
+ resume() {
1487
+ this.error = null;
1488
+ return this;
1489
+ }
1490
+ close() {
1491
+ return this.write(null);
1492
+ }
1493
+ flush() {
1494
+ this.flushBuffers();
1495
+ }
1496
+ };
271
1497
  }
1498
+ });
1499
+
1500
+ // ../documents/src/lib/parsers/parse-xml-internal.ts
1501
+ function setXMLField(object, name, value) {
1502
+ Object.defineProperty(object, name, {
1503
+ value,
1504
+ enumerable: true,
1505
+ configurable: true,
1506
+ writable: true
1507
+ });
272
1508
  }
273
- function getOptionalArrowConstructor(typeName) {
274
- return arrow[typeName];
275
- }
276
- function isArrowViewType(arrowType, viewTypeName) {
277
- const constructor = getOptionalArrowConstructor(viewTypeName);
278
- if (constructor && arrowType instanceof constructor) {
279
- return true;
1509
+ function parseXMLInternal(text, options = {}) {
1510
+ if (options.strict !== false && /[^\u0009\u000a\u000d\u0020-\ud7ff\ue000-\ufffd\u{10000}-\u{10ffff}]/u.test(text)) {
1511
+ throw new Error("XML: invalid XML character");
1512
+ }
1513
+ const maximumDepth = options.maxDepth ?? 256;
1514
+ if (!Number.isSafeInteger(maximumDepth) || maximumDepth < 1 || maximumDepth > 4096) {
1515
+ throw new Error("XML: maxDepth must be an integer between 1 and 4096");
1516
+ }
1517
+ const state = new InternalXMLParserState(options, maximumDepth);
1518
+ const parser = new SAXParser({
1519
+ strict: options.strict !== false,
1520
+ strictEntities: !options.htmlEntities,
1521
+ preserveCase: true,
1522
+ caseInsensitiveTags: options.strict === false,
1523
+ processEntities: options.processEntities !== false,
1524
+ onopentag: (tag) => state.openElement(tag.name, tag.attributes || {}),
1525
+ ontext: (value) => state.addText(value),
1526
+ oncdata: (value) => state.addText(value),
1527
+ onscript: (value) => state.addText(value),
1528
+ onclosetag: () => state.closeElement(),
1529
+ onerror: (error) => {
1530
+ throw error;
1531
+ }
1532
+ });
1533
+ parser.write(text).close();
1534
+ if (options.strict === false) {
1535
+ while (state.stack.length) state.closeElement();
280
1536
  }
281
- const guards = arrow.DataType;
282
- const guard = viewTypeName === "BinaryView" ? guards.isBinaryView : guards.isUtf8View;
283
- return Boolean(guard == null ? void 0 : guard(arrowType));
284
- }
285
- function isOptionalArrowType(arrowType, typeName) {
286
- const constructor = getOptionalArrowConstructor(typeName);
287
- return Boolean(constructor && arrowType instanceof constructor);
1537
+ if (state.result === void 0) throw new Error("XML: document requires a root element");
1538
+ return state.result;
288
1539
  }
289
- function serializeArrowDictionaryKeyType(arrowType) {
290
- if (arrowType instanceof arrow.Int) {
291
- const prefix = arrowType.isSigned ? "int" : "uint";
292
- const keyType = `${prefix}${arrowType.bitWidth}`;
293
- if (isSchemaDictionaryKeyType(keyType)) {
294
- return keyType;
295
- }
1540
+ var InternalXMLParserState;
1541
+ var init_parse_xml_internal = __esm({
1542
+ "../documents/src/lib/parsers/parse-xml-internal.ts"() {
1543
+ "use strict";
1544
+ init_sax();
1545
+ InternalXMLParserState = class {
1546
+ /** Initializes conversion options and the element nesting budget. */
1547
+ constructor(options, maximumDepth) {
1548
+ this.options = options;
1549
+ this.maximumDepth = maximumDepth;
1550
+ }
1551
+ options;
1552
+ maximumDepth;
1553
+ /** Open element stack. */
1554
+ stack = [];
1555
+ /** Parsed root document. */
1556
+ result;
1557
+ /** Starts an element, rejecting multiple roots and excessive nesting. */
1558
+ openElement(name, attributes) {
1559
+ if (this.stack.length >= this.maximumDepth)
1560
+ throw new Error("XML: maximum nesting depth exceeded");
1561
+ if (!this.stack.length && this.result !== void 0 && this.options.strict !== false) {
1562
+ throw new Error("XML: document requires a single root element");
1563
+ }
1564
+ const elementName = this.normalizeName(name);
1565
+ const parent = this.stack[this.stack.length - 1];
1566
+ this.stack.push({
1567
+ name: elementName,
1568
+ path: parent ? `${parent.path}.${elementName}` : elementName,
1569
+ attributes: this.normalizeAttributes(attributes),
1570
+ children: {},
1571
+ orderedChildren: [],
1572
+ text: ""
1573
+ });
1574
+ }
1575
+ /** Accumulates text without losing whitespace between text and CDATA chunks. */
1576
+ addText(text) {
1577
+ const current = this.stack[this.stack.length - 1];
1578
+ if (current) current.text += text;
1579
+ }
1580
+ /** Finishes an element and attaches it to its parent or the document root. */
1581
+ closeElement() {
1582
+ const node = this.stack.pop();
1583
+ if (!node) return;
1584
+ const value = this.finalizeElement(node);
1585
+ const parent = this.stack[this.stack.length - 1];
1586
+ if (this.options.preserveOrder) {
1587
+ if (parent) parent.orderedChildren.push(value);
1588
+ else this.result = value;
1589
+ return;
1590
+ }
1591
+ if (parent) this.addChild(parent.children, node.name, node.path, value);
1592
+ else {
1593
+ if (this.result === void 0) this.result = {};
1594
+ this.addChild(this.result, node.name, node.path, value);
1595
+ }
1596
+ }
1597
+ /** Converts a completed element, keeping grouping and coercion independent. */
1598
+ finalizeElement(node) {
1599
+ const text = this.options.trimValues === false ? node.text : node.text.trim();
1600
+ if (this.options.preserveOrder) {
1601
+ return { name: node.name, attributes: node.attributes, children: node.orderedChildren, text };
1602
+ }
1603
+ const hasAttributes = Object.keys(node.attributes).length > 0;
1604
+ if (!hasAttributes && !Object.keys(node.children).length) {
1605
+ return this.parseValue(text, this.options.parseTagValue !== false);
1606
+ }
1607
+ const object = node.children;
1608
+ if (text)
1609
+ setXMLField(
1610
+ object,
1611
+ this.options.textNodeName ?? "value",
1612
+ this.parseValue(text, this.options.parseTagValue !== false)
1613
+ );
1614
+ if (hasAttributes && this.options.attributesGroupName) {
1615
+ setXMLField(object, this.options.attributesGroupName, node.attributes);
1616
+ } else {
1617
+ for (const [name, value] of Object.entries(node.attributes)) setXMLField(object, name, value);
1618
+ }
1619
+ return object;
1620
+ }
1621
+ /** Appends an element while preserving repeated and explicitly array-valued fields. */
1622
+ addChild(object, name, path, value) {
1623
+ var _a;
1624
+ if (!Object.hasOwn(object, name)) {
1625
+ setXMLField(object, name, ((_a = this.options.arrayPaths) == null ? void 0 : _a.includes(path)) ? [value] : value);
1626
+ } else {
1627
+ const existing = object[name];
1628
+ if (Array.isArray(existing)) existing.push(value);
1629
+ else setXMLField(object, name, [existing, value]);
1630
+ }
1631
+ }
1632
+ /** Applies namespace, prefix, grouping and scalar options to attributes. */
1633
+ normalizeAttributes(attributes) {
1634
+ const normalized = {};
1635
+ if (this.options.ignoreAttributes) return normalized;
1636
+ for (const [name, value] of Object.entries(attributes)) {
1637
+ if (this.options.removeNSPrefix && (name === "xmlns" || name.startsWith("xmlns:"))) continue;
1638
+ const text = this.options.trimValues === false ? value : value.trim();
1639
+ setXMLField(
1640
+ normalized,
1641
+ (this.options.attributeNamePrefix ?? "") + this.normalizeName(name),
1642
+ this.parseValue(text, this.options.parseAttributeValue === true)
1643
+ );
1644
+ }
1645
+ return normalized;
1646
+ }
1647
+ /** Removes a namespace prefix only when requested. */
1648
+ normalizeName(name) {
1649
+ return this.options.removeNSPrefix ? name.slice(name.indexOf(":") + 1) : name;
1650
+ }
1651
+ /** Coerces only finite numeric values and lowercase XML boolean literals. */
1652
+ parseValue(value, convert) {
1653
+ if (!convert) return value;
1654
+ if (value === "true" || value === "false") return value === "true";
1655
+ if (value !== "" && value.trim() !== "" && Number.isFinite(Number(value))) return Number(value);
1656
+ return value;
1657
+ }
1658
+ };
1659
+ }
1660
+ });
1661
+
1662
+ // ../documents/src/lib/parsers/parse-xml.ts
1663
+ function parseXMLSync(text, options = {}) {
1664
+ if (Object.hasOwn(options, "_fastXML") || Object.hasOwn(options, "_sax")) {
1665
+ throw new Error("XML: backend-specific options were removed; use native XML options");
296
1666
  }
297
- switch (arrowType.constructor) {
298
- case arrow.Int8:
299
- return "int8";
300
- case arrow.Int16:
301
- return "int16";
302
- case arrow.Int32:
303
- return "int32";
304
- case arrow.Uint8:
305
- return "uint8";
306
- case arrow.Uint16:
307
- return "uint16";
308
- case arrow.Uint32:
309
- return "uint32";
310
- default:
311
- throw new Error(`arrow dictionary index type not supported: ${arrowType.constructor.name}`);
1667
+ if (options._parser && !["internal", "sax"].includes(options._parser)) {
1668
+ throw new Error("XML: unsupported parser backend; use the native documents parser");
312
1669
  }
1670
+ const parsed = parseXMLInternal(text, options);
1671
+ return options.uncapitalizeKeys ? uncapitalizeKeys(parsed) : parsed;
313
1672
  }
314
- function isSchemaDictionaryKeyType(keyType) {
315
- return ["int8", "int16", "int32", "uint8", "uint16", "uint32"].includes(keyType);
316
- }
317
- var arrow;
318
- var init_convert_arrow_schema = __esm({
319
- "../core/src/schema-utils/lib/schema/convert-arrow-schema.ts"() {
1673
+ var init_parse_xml = __esm({
1674
+ "../documents/src/lib/parsers/parse-xml.ts"() {
320
1675
  "use strict";
321
- arrow = __toESM(require("apache-arrow"), 1);
1676
+ init_uncapitalize();
1677
+ init_parse_xml_internal();
322
1678
  }
323
1679
  });
324
1680
 
325
- // ../core/src/schema-utils/index.ts
326
- var init_schema_utils = __esm({
327
- "../core/src/schema-utils/index.ts"() {
1681
+ // ../documents/src/xml-parser.ts
1682
+ var init_xml_parser = __esm({
1683
+ "../documents/src/xml-parser.ts"() {
328
1684
  "use strict";
329
- init_convert_arrow_schema();
1685
+ init_parse_xml();
330
1686
  }
331
1687
  });
332
1688
 
@@ -335,7 +1691,7 @@ function buildGraphTables(nodes, edges, shape, declarations) {
335
1691
  if (shape === "plain-graph-data") {
336
1692
  return { shape, nodes: Array.from(nodes), edges: Array.from(edges) };
337
1693
  }
338
- if (shape !== "arrow-table" && shape !== "object-row-table") {
1694
+ if (shape !== "arrow" && shape !== "object-row-table") {
339
1695
  throw new Error(`Unsupported graph shape: ${shape}`);
340
1696
  }
341
1697
  const nodeTable = buildGraphTable(nodes, false, shape, declarations == null ? void 0 : declarations.nodes);
@@ -375,8 +1731,7 @@ function buildGraphTable(records, isEdge, shape, declarations) {
375
1731
  type
376
1732
  );
377
1733
  }
378
- const data = new import_apache_arrow.Table(vectors);
379
- return { shape, schema: convertArrowToSchema(data.schema), data };
1734
+ return new import_apache_arrow.Table(vectors);
380
1735
  }
381
1736
  function inferAttributeType(values, declarations) {
382
1737
  const names = new Set(declarations == null ? void 0 : declarations.keys());
@@ -471,14 +1826,13 @@ var init_build_graph_tables = __esm({
471
1826
  "src/lib/build-graph-tables.ts"() {
472
1827
  "use strict";
473
1828
  import_apache_arrow = require("apache-arrow");
474
- init_schema_utils();
475
1829
  }
476
1830
  });
477
1831
 
478
1832
  // src/lib/parse-graphml.ts
479
1833
  function parseGraphML(graphml, shape = "plain-graph-data") {
480
1834
  const xmlText = decodeGraphML(graphml);
481
- const document = graphmlParser.parse(xmlText);
1835
+ const document = parseXMLSync(xmlText, GRAPHML_XML_OPTIONS);
482
1836
  const graphmlRoot = getGraphMLRoot(document);
483
1837
  if (!graphmlRoot) {
484
1838
  throw new Error("GraphML document does not contain a <graphml> element.");
@@ -758,15 +2112,15 @@ function parseBoolean(value) {
758
2112
  }
759
2113
  return Boolean(normalized);
760
2114
  }
761
- var import_fast_xml_parser, XML_ATTRIBUTE_PREFIX, XML_TEXT_KEY, graphmlParser;
2115
+ var XML_ATTRIBUTE_PREFIX, XML_TEXT_KEY, GRAPHML_XML_OPTIONS;
762
2116
  var init_parse_graphml = __esm({
763
2117
  "src/lib/parse-graphml.ts"() {
764
2118
  "use strict";
765
- import_fast_xml_parser = require("fast-xml-parser");
2119
+ init_xml_parser();
766
2120
  init_build_graph_tables();
767
2121
  XML_ATTRIBUTE_PREFIX = "@_";
768
2122
  XML_TEXT_KEY = "#text";
769
- graphmlParser = new import_fast_xml_parser.XMLParser({
2123
+ GRAPHML_XML_OPTIONS = {
770
2124
  ignoreAttributes: false,
771
2125
  attributeNamePrefix: XML_ATTRIBUTE_PREFIX,
772
2126
  textNodeName: XML_TEXT_KEY,
@@ -774,7 +2128,7 @@ var init_parse_graphml = __esm({
774
2128
  parseAttributeValue: false,
775
2129
  parseTagValue: false,
776
2130
  removeNSPrefix: true
777
- });
2131
+ };
778
2132
  }
779
2133
  });
780
2134
 
@@ -793,15 +2147,15 @@ var init_graphml_loader = __esm({
793
2147
  ...GraphMLLoader,
794
2148
  parse: async (data, options) => {
795
2149
  var _a;
796
- return parseGraphML(data, ((_a = options == null ? void 0 : options.graphml) == null ? void 0 : _a.shape) ?? "arrow-table");
2150
+ return parseGraphML(data, ((_a = options == null ? void 0 : options.graphml) == null ? void 0 : _a.shape) ?? "arrow");
797
2151
  },
798
2152
  parseSync: (data, options) => {
799
2153
  var _a;
800
- return parseGraphML(data, ((_a = options == null ? void 0 : options.graphml) == null ? void 0 : _a.shape) ?? "arrow-table");
2154
+ return parseGraphML(data, ((_a = options == null ? void 0 : options.graphml) == null ? void 0 : _a.shape) ?? "arrow");
801
2155
  },
802
2156
  parseTextSync: (data, options) => {
803
2157
  var _a;
804
- return parseGraphML(data, ((_a = options == null ? void 0 : options.graphml) == null ? void 0 : _a.shape) ?? "arrow-table");
2158
+ return parseGraphML(data, ((_a = options == null ? void 0 : options.graphml) == null ? void 0 : _a.shape) ?? "arrow");
805
2159
  }
806
2160
  };
807
2161
  }
@@ -815,7 +2169,7 @@ __export(graphml_loader_exports2, {
815
2169
  module.exports = __toCommonJS(graphml_loader_exports2);
816
2170
 
817
2171
  // dist/graphml-loader-types.js
818
- var VERSION2 = true ? "5.0.0-beta.1" : "latest";
2172
+ var VERSION2 = true ? "5.0.0-beta.10" : "latest";
819
2173
  async function preload2() {
820
2174
  const { GraphMLLoaderWithParser: GraphMLLoaderWithParser3 } = await Promise.resolve().then(() => (init_graphml_loader(), graphml_loader_exports));
821
2175
  return GraphMLLoaderWithParser3;
@@ -829,23 +2183,23 @@ var GraphMLLoader2 = {
829
2183
  mimeTypes: ["application/graphml+xml"],
830
2184
  text: true,
831
2185
  worker: false,
2186
+ supportsNativeArrow: true,
832
2187
  dataType: null,
833
2188
  batchType: null,
834
- options: { graphml: { shape: "arrow-table" } },
2189
+ options: { graphml: { shape: "arrow" } },
835
2190
  preload: preload2
836
2191
  };
837
2192
 
838
2193
  // dist/lib/parse-graphml.js
839
- var import_fast_xml_parser2 = require("fast-xml-parser");
2194
+ init_xml_parser();
840
2195
 
841
2196
  // dist/lib/build-graph-tables.js
842
2197
  var import_apache_arrow2 = require("apache-arrow");
843
- init_schema_utils();
844
2198
  function buildGraphTables2(nodes, edges, shape, declarations) {
845
2199
  if (shape === "plain-graph-data") {
846
2200
  return { shape, nodes: Array.from(nodes), edges: Array.from(edges) };
847
2201
  }
848
- if (shape !== "arrow-table" && shape !== "object-row-table") {
2202
+ if (shape !== "arrow" && shape !== "object-row-table") {
849
2203
  throw new Error(`Unsupported graph shape: ${shape}`);
850
2204
  }
851
2205
  const nodeTable = buildGraphTable2(nodes, false, shape, declarations == null ? void 0 : declarations.nodes);
@@ -878,8 +2232,7 @@ function buildGraphTable2(records, isEdge, shape, declarations) {
878
2232
  const type = name === "attributes" ? inferAttributeType2(values, declarations) : name === "directed" ? new import_apache_arrow2.Bool() : new import_apache_arrow2.Utf8();
879
2233
  vectors[name] = (0, import_apache_arrow2.vectorFromArray)(values.map((value) => normalizeValue2(value, type)), type);
880
2234
  }
881
- const data = new import_apache_arrow2.Table(vectors);
882
- return { shape, schema: convertArrowToSchema(data.schema), data };
2235
+ return new import_apache_arrow2.Table(vectors);
883
2236
  }
884
2237
  function inferAttributeType2(values, declarations) {
885
2238
  const names = new Set(declarations == null ? void 0 : declarations.keys());
@@ -960,7 +2313,7 @@ function normalizeValue2(value, type) {
960
2313
  // dist/lib/parse-graphml.js
961
2314
  var XML_ATTRIBUTE_PREFIX2 = "@_";
962
2315
  var XML_TEXT_KEY2 = "#text";
963
- var graphmlParser2 = new import_fast_xml_parser2.XMLParser({
2316
+ var GRAPHML_XML_OPTIONS2 = {
964
2317
  ignoreAttributes: false,
965
2318
  attributeNamePrefix: XML_ATTRIBUTE_PREFIX2,
966
2319
  textNodeName: XML_TEXT_KEY2,
@@ -968,10 +2321,10 @@ var graphmlParser2 = new import_fast_xml_parser2.XMLParser({
968
2321
  parseAttributeValue: false,
969
2322
  parseTagValue: false,
970
2323
  removeNSPrefix: true
971
- });
2324
+ };
972
2325
  function parseGraphML2(graphml, shape = "plain-graph-data") {
973
2326
  const xmlText = decodeGraphML2(graphml);
974
- const document = graphmlParser2.parse(xmlText);
2327
+ const document = parseXMLSync(xmlText, GRAPHML_XML_OPTIONS2);
975
2328
  const graphmlRoot = getGraphMLRoot2(document);
976
2329
  if (!graphmlRoot) {
977
2330
  throw new Error("GraphML document does not contain a <graphml> element.");
@@ -1246,15 +2599,15 @@ var GraphMLLoaderWithParser2 = {
1246
2599
  ...GraphMLLoader2,
1247
2600
  parse: async (data, options) => {
1248
2601
  var _a;
1249
- return parseGraphML2(data, ((_a = options == null ? void 0 : options.graphml) == null ? void 0 : _a.shape) ?? "arrow-table");
2602
+ return parseGraphML2(data, ((_a = options == null ? void 0 : options.graphml) == null ? void 0 : _a.shape) ?? "arrow");
1250
2603
  },
1251
2604
  parseSync: (data, options) => {
1252
2605
  var _a;
1253
- return parseGraphML2(data, ((_a = options == null ? void 0 : options.graphml) == null ? void 0 : _a.shape) ?? "arrow-table");
2606
+ return parseGraphML2(data, ((_a = options == null ? void 0 : options.graphml) == null ? void 0 : _a.shape) ?? "arrow");
1254
2607
  },
1255
2608
  parseTextSync: (data, options) => {
1256
2609
  var _a;
1257
- return parseGraphML2(data, ((_a = options == null ? void 0 : options.graphml) == null ? void 0 : _a.shape) ?? "arrow-table");
2610
+ return parseGraphML2(data, ((_a = options == null ? void 0 : options.graphml) == null ? void 0 : _a.shape) ?? "arrow");
1258
2611
  }
1259
2612
  };
1260
2613
  //# sourceMappingURL=graphml-loader.cjs.map