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

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