@loaders.gl/xml 3.3.0-alpha.8

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.
@@ -0,0 +1,1311 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+
3
+ const DEFAULT_SAX_EVENTS = {
4
+ ontext: () => {},
5
+ onprocessinginstruction: () => {},
6
+ onsgmldeclaration: () => {},
7
+ ondoctype: () => {},
8
+ oncomment: () => {},
9
+ onopentagstart: () => {},
10
+ onattribute: () => {},
11
+ onopentag: () => {},
12
+ onclosetag: () => {},
13
+ onopencdata: () => {},
14
+ oncdata: () => {},
15
+ onclosecdata: () => {},
16
+ onerror: () => {},
17
+ onend: () => {},
18
+ onready: () => {},
19
+ onscript: () => {},
20
+ onopennamespace: () => {},
21
+ onclosenamespace: () => {}
22
+ };
23
+ const DEFAULT_SAX_PARSER_OPTIONS = {
24
+ ...DEFAULT_SAX_EVENTS,
25
+ strict: false,
26
+ MAX_BUFFER_LENGTH: 64 * 1024,
27
+ lowercase: false,
28
+ lowercasetags: false,
29
+ noscript: false,
30
+ strictEntities: false,
31
+ xmlns: undefined,
32
+ position: undefined,
33
+ trim: undefined,
34
+ normalize: undefined
35
+ };
36
+ const EVENTS = ['text', 'processinginstruction', 'sgmldeclaration', 'doctype', 'comment', 'opentagstart', 'attribute', 'opentag', 'closetag', 'opencdata', 'cdata', 'closecdata', 'error', 'end', 'ready', 'script', 'opennamespace', 'closenamespace'];
37
+ const BUFFERS = ['comment', 'sgmlDecl', 'textNode', 'tagName', 'doctype', 'procInstName', 'procInstBody', 'entity', 'attribName', 'attribValue', 'cdata', 'script'];
38
+ const 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]/;
39
+ const 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-]/;
40
+ const 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]/;
41
+ const 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-]/;
42
+ export const ENTITIES = {
43
+ amp: '&',
44
+ gt: '>',
45
+ lt: '<',
46
+ quot: '"',
47
+ apos: "'",
48
+ AElig: 198,
49
+ Aacute: 193,
50
+ Acirc: 194,
51
+ Agrave: 192,
52
+ Aring: 197,
53
+ Atilde: 195,
54
+ Auml: 196,
55
+ Ccedil: 199,
56
+ ETH: 208,
57
+ Eacute: 201,
58
+ Ecirc: 202,
59
+ Egrave: 200,
60
+ Euml: 203,
61
+ Iacute: 205,
62
+ Icirc: 206,
63
+ Igrave: 204,
64
+ Iuml: 207,
65
+ Ntilde: 209,
66
+ Oacute: 211,
67
+ Ocirc: 212,
68
+ Ograve: 210,
69
+ Oslash: 216,
70
+ Otilde: 213,
71
+ Ouml: 214,
72
+ THORN: 222,
73
+ Uacute: 218,
74
+ Ucirc: 219,
75
+ Ugrave: 217,
76
+ Uuml: 220,
77
+ Yacute: 221,
78
+ aacute: 225,
79
+ acirc: 226,
80
+ aelig: 230,
81
+ agrave: 224,
82
+ aring: 229,
83
+ atilde: 227,
84
+ auml: 228,
85
+ ccedil: 231,
86
+ eacute: 233,
87
+ ecirc: 234,
88
+ egrave: 232,
89
+ eth: 240,
90
+ euml: 235,
91
+ iacute: 237,
92
+ icirc: 238,
93
+ igrave: 236,
94
+ iuml: 239,
95
+ ntilde: 241,
96
+ oacute: 243,
97
+ ocirc: 244,
98
+ ograve: 242,
99
+ oslash: 248,
100
+ otilde: 245,
101
+ ouml: 246,
102
+ szlig: 223,
103
+ thorn: 254,
104
+ uacute: 250,
105
+ ucirc: 251,
106
+ ugrave: 249,
107
+ uuml: 252,
108
+ yacute: 253,
109
+ yuml: 255,
110
+ copy: 169,
111
+ reg: 174,
112
+ nbsp: 160,
113
+ iexcl: 161,
114
+ cent: 162,
115
+ pound: 163,
116
+ curren: 164,
117
+ yen: 165,
118
+ brvbar: 166,
119
+ sect: 167,
120
+ uml: 168,
121
+ ordf: 170,
122
+ laquo: 171,
123
+ not: 172,
124
+ shy: 173,
125
+ macr: 175,
126
+ deg: 176,
127
+ plusmn: 177,
128
+ sup1: 185,
129
+ sup2: 178,
130
+ sup3: 179,
131
+ acute: 180,
132
+ micro: 181,
133
+ para: 182,
134
+ middot: 183,
135
+ cedil: 184,
136
+ ordm: 186,
137
+ raquo: 187,
138
+ frac14: 188,
139
+ frac12: 189,
140
+ frac34: 190,
141
+ iquest: 191,
142
+ times: 215,
143
+ divide: 247,
144
+ OElig: 338,
145
+ oelig: 339,
146
+ Scaron: 352,
147
+ scaron: 353,
148
+ Yuml: 376,
149
+ fnof: 402,
150
+ circ: 710,
151
+ tilde: 732,
152
+ Alpha: 913,
153
+ Beta: 914,
154
+ Gamma: 915,
155
+ Delta: 916,
156
+ Epsilon: 917,
157
+ Zeta: 918,
158
+ Eta: 919,
159
+ Theta: 920,
160
+ Iota: 921,
161
+ Kappa: 922,
162
+ Lambda: 923,
163
+ Mu: 924,
164
+ Nu: 925,
165
+ Xi: 926,
166
+ Omicron: 927,
167
+ Pi: 928,
168
+ Rho: 929,
169
+ Sigma: 931,
170
+ Tau: 932,
171
+ Upsilon: 933,
172
+ Phi: 934,
173
+ Chi: 935,
174
+ Psi: 936,
175
+ Omega: 937,
176
+ alpha: 945,
177
+ beta: 946,
178
+ gamma: 947,
179
+ delta: 948,
180
+ epsilon: 949,
181
+ zeta: 950,
182
+ eta: 951,
183
+ theta: 952,
184
+ iota: 953,
185
+ kappa: 954,
186
+ lambda: 955,
187
+ mu: 956,
188
+ nu: 957,
189
+ xi: 958,
190
+ omicron: 959,
191
+ pi: 960,
192
+ rho: 961,
193
+ sigmaf: 962,
194
+ sigma: 963,
195
+ tau: 964,
196
+ upsilon: 965,
197
+ phi: 966,
198
+ chi: 967,
199
+ psi: 968,
200
+ omega: 969,
201
+ thetasym: 977,
202
+ upsih: 978,
203
+ piv: 982,
204
+ ensp: 8194,
205
+ emsp: 8195,
206
+ thinsp: 8201,
207
+ zwnj: 8204,
208
+ zwj: 8205,
209
+ lrm: 8206,
210
+ rlm: 8207,
211
+ ndash: 8211,
212
+ mdash: 8212,
213
+ lsquo: 8216,
214
+ rsquo: 8217,
215
+ sbquo: 8218,
216
+ ldquo: 8220,
217
+ rdquo: 8221,
218
+ bdquo: 8222,
219
+ dagger: 8224,
220
+ Dagger: 8225,
221
+ bull: 8226,
222
+ hellip: 8230,
223
+ permil: 8240,
224
+ prime: 8242,
225
+ Prime: 8243,
226
+ lsaquo: 8249,
227
+ rsaquo: 8250,
228
+ oline: 8254,
229
+ frasl: 8260,
230
+ euro: 8364,
231
+ image: 8465,
232
+ weierp: 8472,
233
+ real: 8476,
234
+ trade: 8482,
235
+ alefsym: 8501,
236
+ larr: 8592,
237
+ uarr: 8593,
238
+ rarr: 8594,
239
+ darr: 8595,
240
+ harr: 8596,
241
+ crarr: 8629,
242
+ lArr: 8656,
243
+ uArr: 8657,
244
+ rArr: 8658,
245
+ dArr: 8659,
246
+ hArr: 8660,
247
+ forall: 8704,
248
+ part: 8706,
249
+ exist: 8707,
250
+ empty: 8709,
251
+ nabla: 8711,
252
+ isin: 8712,
253
+ notin: 8713,
254
+ ni: 8715,
255
+ prod: 8719,
256
+ sum: 8721,
257
+ minus: 8722,
258
+ lowast: 8727,
259
+ radic: 8730,
260
+ prop: 8733,
261
+ infin: 8734,
262
+ ang: 8736,
263
+ and: 8743,
264
+ or: 8744,
265
+ cap: 8745,
266
+ cup: 8746,
267
+ int: 8747,
268
+ there4: 8756,
269
+ sim: 8764,
270
+ cong: 8773,
271
+ asymp: 8776,
272
+ ne: 8800,
273
+ equiv: 8801,
274
+ le: 8804,
275
+ ge: 8805,
276
+ sub: 8834,
277
+ sup: 8835,
278
+ nsub: 8836,
279
+ sube: 8838,
280
+ supe: 8839,
281
+ oplus: 8853,
282
+ otimes: 8855,
283
+ perp: 8869,
284
+ sdot: 8901,
285
+ lceil: 8968,
286
+ rceil: 8969,
287
+ lfloor: 8970,
288
+ rfloor: 8971,
289
+ lang: 9001,
290
+ rang: 9002,
291
+ loz: 9674,
292
+ spades: 9824,
293
+ clubs: 9827,
294
+ hearts: 9829,
295
+ diams: 9830
296
+ };
297
+ Object.keys(ENTITIES).forEach(key => {
298
+ const e = ENTITIES[key];
299
+ ENTITIES[key] = typeof e === 'number' ? String.fromCharCode(e) : e;
300
+ });
301
+
302
+ class SAX {
303
+
304
+ constructor() {
305
+ _defineProperty(this, "EVENTS", EVENTS);
306
+ _defineProperty(this, "ENTITIES", {
307
+ ...ENTITIES
308
+ });
309
+ _defineProperty(this, "events", void 0);
310
+ _defineProperty(this, "XML_ENTITIES", {
311
+ amp: '&',
312
+ gt: '>',
313
+ lt: '<',
314
+ quot: '"',
315
+ apos: "'"
316
+ });
317
+ _defineProperty(this, "S", 0);
318
+ _defineProperty(this, "opt", void 0);
319
+ _defineProperty(this, "trackPosition", false);
320
+ _defineProperty(this, "column", 0);
321
+ _defineProperty(this, "line", 0);
322
+ _defineProperty(this, "c", '');
323
+ _defineProperty(this, "error", void 0);
324
+ _defineProperty(this, "q", '');
325
+ _defineProperty(this, "bufferCheckPosition", void 0);
326
+ _defineProperty(this, "closed", false);
327
+ _defineProperty(this, "tags", []);
328
+ _defineProperty(this, "looseCase", '');
329
+ _defineProperty(this, "closedRoot", false);
330
+ _defineProperty(this, "sawRoot", false);
331
+ _defineProperty(this, "strict", false);
332
+ _defineProperty(this, "tag", void 0);
333
+ _defineProperty(this, "strictEntities", void 0);
334
+ _defineProperty(this, "state", void 0);
335
+ _defineProperty(this, "noscript", false);
336
+ _defineProperty(this, "attribList", []);
337
+ _defineProperty(this, "ns", void 0);
338
+ _defineProperty(this, "position", 0);
339
+ _defineProperty(this, "STATE", {
340
+ BEGIN: this.S++,
341
+ BEGIN_WHITESPACE: this.S++,
342
+ TEXT: this.S++,
343
+ TEXT_ENTITY: this.S++,
344
+ OPEN_WAKA: this.S++,
345
+ SGML_DECL: this.S++,
346
+ SGML_DECL_QUOTED: this.S++,
347
+ DOCTYPE: this.S++,
348
+ DOCTYPE_QUOTED: this.S++,
349
+ DOCTYPE_DTD: this.S++,
350
+ DOCTYPE_DTD_QUOTED: this.S++,
351
+ COMMENT_STARTING: this.S++,
352
+ COMMENT: this.S++,
353
+ COMMENT_ENDING: this.S++,
354
+ COMMENT_ENDED: this.S++,
355
+ CDATA: this.S++,
356
+ CDATA_ENDING: this.S++,
357
+ CDATA_ENDING_2: this.S++,
358
+ PROC_INST: this.S++,
359
+ PROC_INST_BODY: this.S++,
360
+ PROC_INST_ENDING: this.S++,
361
+ OPEN_TAG: this.S++,
362
+ OPEN_TAG_SLASH: this.S++,
363
+ ATTRIB: this.S++,
364
+ ATTRIB_NAME: this.S++,
365
+ ATTRIB_NAME_SAW_WHITE: this.S++,
366
+ ATTRIB_VALUE: this.S++,
367
+ ATTRIB_VALUE_QUOTED: this.S++,
368
+ ATTRIB_VALUE_CLOSED: this.S++,
369
+ ATTRIB_VALUE_UNQUOTED: this.S++,
370
+ ATTRIB_VALUE_ENTITY_Q: this.S++,
371
+ ATTRIB_VALUE_ENTITY_U: this.S++,
372
+ CLOSE_TAG: this.S++,
373
+ CLOSE_TAG_SAW_WHITE: this.S++,
374
+ SCRIPT: this.S++,
375
+ SCRIPT_ENDING: this.S++
376
+ });
377
+ _defineProperty(this, "BUFFERS", BUFFERS);
378
+ _defineProperty(this, "CDATA", '[CDATA[');
379
+ _defineProperty(this, "DOCTYPE", 'DOCTYPE');
380
+ _defineProperty(this, "XML_NAMESPACE", 'http://www.w3.org/XML/1998/namespace');
381
+ _defineProperty(this, "XMLNS_NAMESPACE", 'http://www.w3.org/2000/xmlns/');
382
+ _defineProperty(this, "rootNS", {
383
+ xml: this.XML_NAMESPACE,
384
+ xmlns: this.XMLNS_NAMESPACE
385
+ });
386
+ _defineProperty(this, "comment", void 0);
387
+ _defineProperty(this, "sgmlDecl", void 0);
388
+ _defineProperty(this, "textNode", '');
389
+ _defineProperty(this, "tagName", void 0);
390
+ _defineProperty(this, "doctype", void 0);
391
+ _defineProperty(this, "procInstName", void 0);
392
+ _defineProperty(this, "procInstBody", void 0);
393
+ _defineProperty(this, "entity", '');
394
+ _defineProperty(this, "attribName", void 0);
395
+ _defineProperty(this, "attribValue", void 0);
396
+ _defineProperty(this, "cdata", '');
397
+ _defineProperty(this, "script", '');
398
+ _defineProperty(this, "startTagPosition", 0);
399
+ this.S = 0;
400
+ for (const s in this.STATE) {
401
+ if (this.STATE.hasOwnProperty(s)) {
402
+ this.STATE[this.STATE[s]] = s;
403
+ }
404
+ }
405
+
406
+ this.S = this.STATE;
407
+ }
408
+ static charAt(chunk, i) {
409
+ let result = '';
410
+ if (i < chunk.length) {
411
+ result = chunk.charAt(i);
412
+ }
413
+ return result;
414
+ }
415
+ static isWhitespace(c) {
416
+ return c === ' ' || c === '\n' || c === '\r' || c === '\t';
417
+ }
418
+ static isQuote(c) {
419
+ return c === '"' || c === "'";
420
+ }
421
+ static isAttribEnd(c) {
422
+ return c === '>' || SAX.isWhitespace(c);
423
+ }
424
+ static isMatch(regex, c) {
425
+ return regex.test(c);
426
+ }
427
+ static notMatch(regex, c) {
428
+ return !SAX.isMatch(regex, c);
429
+ }
430
+ static qname(name, attribute) {
431
+ const i = name.indexOf(':');
432
+ const qualName = i < 0 ? ['', name] : name.split(':');
433
+ let prefix = qualName[0];
434
+ let local = qualName[1];
435
+
436
+ if (attribute && name === 'xmlns') {
437
+ prefix = 'xmlns';
438
+ local = '';
439
+ }
440
+ return {
441
+ prefix,
442
+ local
443
+ };
444
+ }
445
+ write(chunk) {
446
+ if (this.error) {
447
+ throw this.error;
448
+ }
449
+ if (this.closed) {
450
+ return this.errorFunction('Cannot write after close. Assign an onready handler.');
451
+ }
452
+ if (chunk === null) {
453
+ return this.end();
454
+ }
455
+ if (typeof chunk === 'object') {
456
+ chunk = chunk.toString();
457
+ }
458
+ let i = 0;
459
+ let c;
460
+ while (true) {
461
+ c = SAX.charAt(chunk, i++);
462
+ this.c = c;
463
+ if (!c) {
464
+ break;
465
+ }
466
+ if (this.trackPosition) {
467
+ this.position++;
468
+ if (c === '\n') {
469
+ this.line++;
470
+ this.column = 0;
471
+ } else {
472
+ this.column++;
473
+ }
474
+ }
475
+ switch (this.state) {
476
+ case this.S.BEGIN:
477
+ this.state = this.S.BEGIN_WHITESPACE;
478
+ if (c === '\uFEFF') {
479
+ continue;
480
+ }
481
+ this.beginWhiteSpace(c);
482
+ continue;
483
+ case this.S.BEGIN_WHITESPACE:
484
+ this.beginWhiteSpace(c);
485
+ continue;
486
+ case this.S.TEXT:
487
+ if (this.sawRoot && !this.closedRoot) {
488
+ const starti = i - 1;
489
+ while (c && c !== '<' && c !== '&') {
490
+ c = SAX.charAt(chunk, i++);
491
+ if (c && this.trackPosition) {
492
+ this.position++;
493
+ if (c === '\n') {
494
+ this.line++;
495
+ this.column = 0;
496
+ } else {
497
+ this.column++;
498
+ }
499
+ }
500
+ }
501
+ this.textNode += chunk.substring(starti, i - 1);
502
+ }
503
+ if (c === '<' && !(this.sawRoot && this.closedRoot && !this.strict)) {
504
+ this.state = this.S.OPEN_WAKA;
505
+ this.startTagPosition = this.position;
506
+ } else {
507
+ if (!SAX.isWhitespace(c) && (!this.sawRoot || this.closedRoot)) {
508
+ this.strictFail('Text data outside of root node.');
509
+ }
510
+ if (c === '&') {
511
+ this.state = this.S.TEXT_ENTITY;
512
+ } else {
513
+ this.textNode += c;
514
+ }
515
+ }
516
+ continue;
517
+ case this.S.SCRIPT:
518
+ if (c === '<') {
519
+ this.state = this.S.SCRIPT_ENDING;
520
+ } else {
521
+ this.script += c;
522
+ }
523
+ continue;
524
+ case this.S.SCRIPT_ENDING:
525
+ if (c === '/') {
526
+ this.state = this.S.CLOSE_TAG;
527
+ } else {
528
+ this.script += "<".concat(c);
529
+ this.state = this.S.SCRIPT;
530
+ }
531
+ continue;
532
+ case this.S.OPEN_WAKA:
533
+ if (c === '!') {
534
+ this.state = this.S.SGML_DECL;
535
+ this.sgmlDecl = '';
536
+ } else if (SAX.isWhitespace(c)) {
537
+ } else if (SAX.isMatch(nameStart, c)) {
538
+ this.state = this.S.OPEN_TAG;
539
+ this.tagName = c;
540
+ } else if (c === '/') {
541
+ this.state = this.S.CLOSE_TAG;
542
+ this.tagName = '';
543
+ } else if (c === '?') {
544
+ this.state = this.S.PROC_INST;
545
+ this.procInstName = this.procInstBody = '';
546
+ } else {
547
+ this.strictFail('Unencoded <');
548
+ if (this.startTagPosition + 1 < this.position) {
549
+ const pad = this.position - this.startTagPosition;
550
+ c = new Array(pad).join(' ') + c;
551
+ }
552
+ this.textNode += "<".concat(c);
553
+ this.state = this.S.TEXT;
554
+ }
555
+ continue;
556
+ case this.S.SGML_DECL:
557
+ if ((this.sgmlDecl + c).toUpperCase() === this.CDATA) {
558
+ this.emitNode('onopencdata');
559
+ this.state = this.S.CDATA;
560
+ this.sgmlDecl = '';
561
+ this.cdata = '';
562
+ } else if (this.sgmlDecl + c === '--') {
563
+ this.state = this.S.COMMENT;
564
+ this.comment = '';
565
+ this.sgmlDecl = '';
566
+ } else if ((this.sgmlDecl + c).toUpperCase() === this.DOCTYPE) {
567
+ this.state = this.S.DOCTYPE;
568
+ if (this.doctype || this.sawRoot) {
569
+ this.strictFail('Inappropriately located doctype declaration');
570
+ }
571
+ this.doctype = '';
572
+ this.sgmlDecl = '';
573
+ } else if (c === '>') {
574
+ this.emitNode('onsgmldeclaration', this.sgmlDecl);
575
+ this.sgmlDecl = '';
576
+ this.state = this.S.TEXT;
577
+ } else if (SAX.isQuote(c)) {
578
+ this.state = this.S.SGML_DECL_QUOTED;
579
+ this.sgmlDecl += c;
580
+ } else {
581
+ this.sgmlDecl += c;
582
+ }
583
+ continue;
584
+ case this.S.SGML_DECL_QUOTED:
585
+ if (c === this.q) {
586
+ this.state = this.S.SGML_DECL;
587
+ this.q = '';
588
+ }
589
+ this.sgmlDecl += c;
590
+ continue;
591
+ case this.S.DOCTYPE:
592
+ if (c === '>') {
593
+ this.state = this.S.TEXT;
594
+ this.emitNode('ondoctype', this.doctype);
595
+ this.doctype = true;
596
+ } else {
597
+ this.doctype += c;
598
+ if (c === '[') {
599
+ this.state = this.S.DOCTYPE_DTD;
600
+ } else if (SAX.isQuote(c)) {
601
+ this.state = this.S.DOCTYPE_QUOTED;
602
+ this.q = c;
603
+ }
604
+ }
605
+ continue;
606
+ case this.S.DOCTYPE_QUOTED:
607
+ this.doctype += c;
608
+ if (c === this.q) {
609
+ this.q = '';
610
+ this.state = this.S.DOCTYPE;
611
+ }
612
+ continue;
613
+ case this.S.DOCTYPE_DTD:
614
+ this.doctype += c;
615
+ if (c === ']') {
616
+ this.state = this.S.DOCTYPE;
617
+ } else if (SAX.isQuote(c)) {
618
+ this.state = this.S.DOCTYPE_DTD_QUOTED;
619
+ this.q = c;
620
+ }
621
+ continue;
622
+ case this.S.DOCTYPE_DTD_QUOTED:
623
+ this.doctype += c;
624
+ if (c === this.q) {
625
+ this.state = this.S.DOCTYPE_DTD;
626
+ this.q = '';
627
+ }
628
+ continue;
629
+ case this.S.COMMENT:
630
+ if (c === '-') {
631
+ this.state = this.S.COMMENT_ENDING;
632
+ } else {
633
+ this.comment += c;
634
+ }
635
+ continue;
636
+ case this.S.COMMENT_ENDING:
637
+ if (c === '-') {
638
+ this.state = this.S.COMMENT_ENDED;
639
+ this.comment = this.textApplyOptions(this.comment);
640
+ if (this.comment) {
641
+ this.emitNode('oncomment', this.comment);
642
+ }
643
+ this.comment = '';
644
+ } else {
645
+ this.comment += "-".concat(c);
646
+ this.state = this.S.COMMENT;
647
+ }
648
+ continue;
649
+ case this.S.COMMENT_ENDED:
650
+ if (c !== '>') {
651
+ this.strictFail('Malformed comment');
652
+ this.comment += "--".concat(c);
653
+ this.state = this.S.COMMENT;
654
+ } else {
655
+ this.state = this.S.TEXT;
656
+ }
657
+ continue;
658
+ case this.S.CDATA:
659
+ if (c === ']') {
660
+ this.state = this.S.CDATA_ENDING;
661
+ } else {
662
+ this.cdata += c;
663
+ }
664
+ continue;
665
+ case this.S.CDATA_ENDING:
666
+ if (c === ']') {
667
+ this.state = this.S.CDATA_ENDING_2;
668
+ } else {
669
+ this.cdata += "]".concat(c);
670
+ this.state = this.S.CDATA;
671
+ }
672
+ continue;
673
+ case this.S.CDATA_ENDING_2:
674
+ if (c === '>') {
675
+ if (this.cdata) {
676
+ this.emitNode('oncdata', this.cdata);
677
+ }
678
+ this.emitNode('onclosecdata');
679
+ this.cdata = '';
680
+ this.state = this.S.TEXT;
681
+ } else if (c === ']') {
682
+ this.cdata += ']';
683
+ } else {
684
+ this.cdata += "]]".concat(c);
685
+ this.state = this.S.CDATA;
686
+ }
687
+ continue;
688
+ case this.S.PROC_INST:
689
+ if (c === '?') {
690
+ this.state = this.S.PROC_INST_ENDING;
691
+ } else if (SAX.isWhitespace(c)) {
692
+ this.state = this.S.PROC_INST_BODY;
693
+ } else {
694
+ this.procInstName += c;
695
+ }
696
+ continue;
697
+ case this.S.PROC_INST_BODY:
698
+ if (!this.procInstBody && SAX.isWhitespace(c)) {
699
+ continue;
700
+ } else if (c === '?') {
701
+ this.state = this.S.PROC_INST_ENDING;
702
+ } else {
703
+ this.procInstBody += c;
704
+ }
705
+ continue;
706
+ case this.S.PROC_INST_ENDING:
707
+ if (c === '>') {
708
+ this.emitNode('onprocessinginstruction', {
709
+ name: this.procInstName,
710
+ body: this.procInstBody
711
+ });
712
+ this.procInstName = this.procInstBody = '';
713
+ this.state = this.S.TEXT;
714
+ } else {
715
+ this.procInstBody += "?".concat(c);
716
+ this.state = this.S.PROC_INST_BODY;
717
+ }
718
+ continue;
719
+ case this.S.OPEN_TAG:
720
+ if (SAX.isMatch(nameBody, c)) {
721
+ this.tagName += c;
722
+ } else {
723
+ this.newTag();
724
+ if (c === '>') {
725
+ this.openTag();
726
+ } else if (c === '/') {
727
+ this.state = this.S.OPEN_TAG_SLASH;
728
+ } else {
729
+ if (!SAX.isWhitespace(c)) {
730
+ this.strictFail('Invalid character in tag name');
731
+ }
732
+ this.state = this.S.ATTRIB;
733
+ }
734
+ }
735
+ continue;
736
+ case this.S.OPEN_TAG_SLASH:
737
+ if (c === '>') {
738
+ this.openTag(true);
739
+ this.closeTag();
740
+ } else {
741
+ this.strictFail('Forward-slash in opening tag not followed by >');
742
+ this.state = this.S.ATTRIB;
743
+ }
744
+ continue;
745
+ case this.S.ATTRIB:
746
+ if (SAX.isWhitespace(c)) {
747
+ continue;
748
+ } else if (c === '>') {
749
+ this.openTag();
750
+ } else if (c === '/') {
751
+ this.state = this.S.OPEN_TAG_SLASH;
752
+ } else if (SAX.isMatch(nameStart, c)) {
753
+ this.attribName = c;
754
+ this.attribValue = '';
755
+ this.state = this.S.ATTRIB_NAME;
756
+ } else {
757
+ this.strictFail('Invalid attribute name');
758
+ }
759
+ continue;
760
+ case this.S.ATTRIB_NAME:
761
+ if (c === '=') {
762
+ this.state = this.S.ATTRIB_VALUE;
763
+ } else if (c === '>') {
764
+ this.strictFail('Attribute without value');
765
+ this.attribValue = this.attribName;
766
+ this.attrib();
767
+ this.openTag();
768
+ } else if (SAX.isWhitespace(c)) {
769
+ this.state = this.S.ATTRIB_NAME_SAW_WHITE;
770
+ } else if (SAX.isMatch(nameBody, c)) {
771
+ this.attribName += c;
772
+ } else {
773
+ this.strictFail('Invalid attribute name');
774
+ }
775
+ continue;
776
+ case this.S.ATTRIB_NAME_SAW_WHITE:
777
+ if (c === '=') {
778
+ this.state = this.S.ATTRIB_VALUE;
779
+ } else if (SAX.isWhitespace(c)) {
780
+ continue;
781
+ } else {
782
+ this.strictFail('Attribute without value');
783
+ this.tag.attributes[this.attribName] = '';
784
+ this.attribValue = '';
785
+ this.emitNode('onattribute', {
786
+ name: this.attribName,
787
+ value: ''
788
+ });
789
+ this.attribName = '';
790
+ if (c === '>') {
791
+ this.openTag();
792
+ } else if (SAX.isMatch(nameStart, c)) {
793
+ this.attribName = c;
794
+ this.state = this.S.ATTRIB_NAME;
795
+ } else {
796
+ this.strictFail('Invalid attribute name');
797
+ this.state = this.S.ATTRIB;
798
+ }
799
+ }
800
+ continue;
801
+ case this.S.ATTRIB_VALUE:
802
+ if (SAX.isWhitespace(c)) {
803
+ continue;
804
+ } else if (SAX.isQuote(c)) {
805
+ this.q = c;
806
+ this.state = this.S.ATTRIB_VALUE_QUOTED;
807
+ } else {
808
+ this.strictFail('Unquoted attribute value');
809
+ this.state = this.S.ATTRIB_VALUE_UNQUOTED;
810
+ this.attribValue = c;
811
+ }
812
+ continue;
813
+ case this.S.ATTRIB_VALUE_QUOTED:
814
+ if (c !== this.q) {
815
+ if (c === '&') {
816
+ this.state = this.S.ATTRIB_VALUE_ENTITY_Q;
817
+ } else {
818
+ this.attribValue += c;
819
+ }
820
+ continue;
821
+ }
822
+ this.attrib();
823
+ this.q = '';
824
+ this.state = this.S.ATTRIB_VALUE_CLOSED;
825
+ continue;
826
+ case this.S.ATTRIB_VALUE_CLOSED:
827
+ if (SAX.isWhitespace(c)) {
828
+ this.state = this.S.ATTRIB;
829
+ } else if (c === '>') {
830
+ this.openTag();
831
+ } else if (c === '/') {
832
+ this.state = this.S.OPEN_TAG_SLASH;
833
+ } else if (SAX.isMatch(nameStart, c)) {
834
+ this.strictFail('No whitespace between attributes');
835
+ this.attribName = c;
836
+ this.attribValue = '';
837
+ this.state = this.S.ATTRIB_NAME;
838
+ } else {
839
+ this.strictFail('Invalid attribute name');
840
+ }
841
+ continue;
842
+ case this.S.ATTRIB_VALUE_UNQUOTED:
843
+ if (!SAX.isAttribEnd(c)) {
844
+ if (c === '&') {
845
+ this.state = this.S.ATTRIB_VALUE_ENTITY_U;
846
+ } else {
847
+ this.attribValue += c;
848
+ }
849
+ continue;
850
+ }
851
+ this.attrib();
852
+ if (c === '>') {
853
+ this.openTag();
854
+ } else {
855
+ this.state = this.S.ATTRIB;
856
+ }
857
+ continue;
858
+ case this.S.CLOSE_TAG:
859
+ if (!this.tagName) {
860
+ if (SAX.isWhitespace(c)) {
861
+ continue;
862
+ } else if (SAX.notMatch(nameStart, c)) {
863
+ if (this.script) {
864
+ this.script += "</".concat(c);
865
+ this.state = this.S.SCRIPT;
866
+ } else {
867
+ this.strictFail('Invalid tagname in closing tag.');
868
+ }
869
+ } else {
870
+ this.tagName = c;
871
+ }
872
+ } else if (c === '>') {
873
+ this.closeTag();
874
+ } else if (SAX.isMatch(nameBody, c)) {
875
+ this.tagName += c;
876
+ } else if (this.script) {
877
+ this.script += "</".concat(this.tagName);
878
+ this.tagName = '';
879
+ this.state = this.S.SCRIPT;
880
+ } else {
881
+ if (!SAX.isWhitespace(c)) {
882
+ this.strictFail('Invalid tagname in closing tag');
883
+ }
884
+ this.state = this.S.CLOSE_TAG_SAW_WHITE;
885
+ }
886
+ continue;
887
+ case this.S.CLOSE_TAG_SAW_WHITE:
888
+ if (SAX.isWhitespace(c)) {
889
+ continue;
890
+ }
891
+ if (c === '>') {
892
+ this.closeTag();
893
+ } else {
894
+ this.strictFail('Invalid characters in closing tag');
895
+ }
896
+ continue;
897
+ case this.S.TEXT_ENTITY:
898
+ case this.S.ATTRIB_VALUE_ENTITY_Q:
899
+ case this.S.ATTRIB_VALUE_ENTITY_U:
900
+ let returnState;
901
+ let buffer;
902
+ switch (this.state) {
903
+ case this.S.TEXT_ENTITY:
904
+ returnState = this.S.TEXT;
905
+ buffer = 'textNode';
906
+ break;
907
+ case this.S.ATTRIB_VALUE_ENTITY_Q:
908
+ returnState = this.S.ATTRIB_VALUE_QUOTED;
909
+ buffer = 'attribValue';
910
+ break;
911
+ case this.S.ATTRIB_VALUE_ENTITY_U:
912
+ returnState = this.S.ATTRIB_VALUE_UNQUOTED;
913
+ buffer = 'attribValue';
914
+ break;
915
+ default:
916
+ throw new Error("Unknown state: ".concat(this.state));
917
+ }
918
+ if (c === ';') {
919
+ this[buffer] += this.parseEntity();
920
+ this.entity = '';
921
+ this.state = returnState;
922
+ } else if (SAX.isMatch(this.entity.length ? entityBody : entityStart, c)) {
923
+ this.entity += c;
924
+ } else {
925
+ this.strictFail('Invalid character in entity name');
926
+ this[buffer] += "&".concat(this.entity).concat(c);
927
+ this.entity = '';
928
+ this.state = returnState;
929
+ }
930
+ continue;
931
+ default:
932
+ throw new Error("Unknown state: ".concat(this.state));
933
+ }
934
+ }
935
+
936
+ if (this.position >= this.bufferCheckPosition) {
937
+ this.checkBufferLength();
938
+ }
939
+ return this;
940
+ }
941
+ emit(event, data) {
942
+ if (this.events.hasOwnProperty(event)) {
943
+ const eventName = event.replace(/^on/, '');
944
+ this.events[event](data, eventName, this);
945
+ }
946
+ }
947
+ clearBuffers() {
948
+ for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
949
+ this[this[i]] = '';
950
+ }
951
+ }
952
+ flushBuffers() {
953
+ this.closeText();
954
+ if (this.cdata !== '') {
955
+ this.emitNode('oncdata', this.cdata);
956
+ this.cdata = '';
957
+ }
958
+ if (this.script !== '') {
959
+ this.emitNode('onscript', this.script);
960
+ this.script = '';
961
+ }
962
+ }
963
+ end() {
964
+ if (this.sawRoot && !this.closedRoot) this.strictFail('Unclosed root tag');
965
+ if (this.state !== this.S.BEGIN && this.state !== this.S.BEGIN_WHITESPACE && this.state !== this.S.TEXT) {
966
+ this.errorFunction('Unexpected end');
967
+ }
968
+ this.closeText();
969
+ this.c = '';
970
+ this.closed = true;
971
+ this.emit('onend');
972
+ return new SAXParser(this.opt);
973
+ }
974
+ errorFunction(er) {
975
+ this.closeText();
976
+ if (this.trackPosition) {
977
+ er += "\nLine: ".concat(this.line, "\nColumn: ").concat(this.column, "\nChar: ").concat(this.c);
978
+ }
979
+ const error = new Error(er);
980
+ this.error = error;
981
+ this.emit('onerror', error);
982
+ return this;
983
+ }
984
+ attrib() {
985
+ if (!this.strict) {
986
+ this.attribName = this.attribName[this.looseCase]();
987
+ }
988
+ if (this.attribList.indexOf(this.attribName) !== -1 || this.tag.attributes.hasOwnProperty(this.attribName)) {
989
+ this.attribName = this.attribValue = '';
990
+ return;
991
+ }
992
+ if (this.opt.xmlns) {
993
+ const qn = SAX.qname(this.attribName, true);
994
+ const prefix = qn.prefix;
995
+ const local = qn.local;
996
+ if (prefix === 'xmlns') {
997
+ if (local === 'xml' && this.attribValue !== this.XML_NAMESPACE) {
998
+ this.strictFail("xml: prefix must be bound to ".concat(this.XML_NAMESPACE, "\n") + "Actual: ".concat(this.attribValue));
999
+ } else if (local === 'xmlns' && this.attribValue !== this.XMLNS_NAMESPACE) {
1000
+ this.strictFail("xmlns: prefix must be bound to ".concat(this.XMLNS_NAMESPACE, "\n") + "Actual: ".concat(this.attribValue));
1001
+ } else {
1002
+ const tag = this.tag;
1003
+ const parent = this.tags[this.tags.length - 1] || this;
1004
+ if (tag.ns === parent.ns) {
1005
+ tag.ns = Object.create(parent.ns);
1006
+ }
1007
+ tag.ns[local] = this.attribValue;
1008
+ }
1009
+ }
1010
+
1011
+ this.attribList.push([this.attribName, this.attribValue]);
1012
+ } else {
1013
+ this.tag.attributes[this.attribName] = this.attribValue;
1014
+ this.emitNode('onattribute', {
1015
+ name: this.attribName,
1016
+ value: this.attribValue
1017
+ });
1018
+ }
1019
+ this.attribName = this.attribValue = '';
1020
+ }
1021
+ newTag() {
1022
+ if (!this.strict) this.tagName = this.tagName[this.looseCase]();
1023
+ const parent = this.tags[this.tags.length - 1] || this;
1024
+ const tag = this.tag = {
1025
+ name: this.tagName,
1026
+ attributes: {}
1027
+ };
1028
+
1029
+ if (this.opt.xmlns) {
1030
+ tag.ns = parent.ns;
1031
+ }
1032
+ this.attribList.length = 0;
1033
+ this.emitNode('onopentagstart', tag);
1034
+ }
1035
+ parseEntity() {
1036
+ let entity = this.entity;
1037
+ const entityLC = entity.toLowerCase();
1038
+ let num = NaN;
1039
+ let numStr = '';
1040
+ if (this.ENTITIES[entity]) {
1041
+ return this.ENTITIES[entity];
1042
+ }
1043
+ if (this.ENTITIES[entityLC]) {
1044
+ return this.ENTITIES[entityLC];
1045
+ }
1046
+ entity = entityLC;
1047
+ if (entity.charAt(0) === '#') {
1048
+ if (entity.charAt(1) === 'x') {
1049
+ entity = entity.slice(2);
1050
+ num = parseInt(entity, 16);
1051
+ numStr = num.toString(16);
1052
+ } else {
1053
+ entity = entity.slice(1);
1054
+ num = parseInt(entity, 10);
1055
+ numStr = num.toString(10);
1056
+ }
1057
+ }
1058
+ entity = entity.replace(/^0+/, '');
1059
+ if (isNaN(num) || numStr.toLowerCase() !== entity) {
1060
+ this.strictFail('Invalid character entity');
1061
+ return "&".concat(this.entity, ";");
1062
+ }
1063
+ return String.fromCodePoint(num);
1064
+ }
1065
+ beginWhiteSpace(c) {
1066
+ if (c === '<') {
1067
+ this.state = this.S.OPEN_WAKA;
1068
+ this.startTagPosition = this.position;
1069
+ } else if (!SAX.isWhitespace(c)) {
1070
+ this.strictFail('Non-whitespace before first tag.');
1071
+ this.textNode = c;
1072
+ this.state = this.S.TEXT;
1073
+ } else {}
1074
+ }
1075
+ strictFail(message) {
1076
+ if (typeof this !== 'object' || !(this instanceof SAXParser)) {
1077
+ throw new Error('bad call to strictFail');
1078
+ }
1079
+ if (this.strict) {
1080
+ this.errorFunction(message);
1081
+ }
1082
+ }
1083
+ textApplyOptions(text) {
1084
+ if (this.opt.trim) text = text.trim();
1085
+ if (this.opt.normalize) text = text.replace(/\s+/g, ' ');
1086
+ return text;
1087
+ }
1088
+ emitNode(nodeType, data) {
1089
+ if (this.textNode) this.closeText();
1090
+ this.emit(nodeType, data);
1091
+ }
1092
+ closeText() {
1093
+ this.textNode = this.textApplyOptions(this.textNode);
1094
+ if (this.textNode !== undefined && this.textNode !== '' && this.textNode !== 'undefined') {
1095
+ this.emit('ontext', this.textNode);
1096
+ }
1097
+ this.textNode = '';
1098
+ }
1099
+ checkBufferLength() {
1100
+ const maxAllowed = Math.max(this.opt.MAX_BUFFER_LENGTH, 10);
1101
+ let maxActual = 0;
1102
+ for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
1103
+ var _this$this$BUFFERS$i;
1104
+ const len = ((_this$this$BUFFERS$i = this[this.BUFFERS[i]]) === null || _this$this$BUFFERS$i === void 0 ? void 0 : _this$this$BUFFERS$i.length) || 0;
1105
+ if (len > maxAllowed) {
1106
+ switch (this.BUFFERS[i]) {
1107
+ case 'textNode':
1108
+ this.closeText();
1109
+ break;
1110
+ case 'cdata':
1111
+ this.emitNode('oncdata', this.cdata);
1112
+ this.cdata = '';
1113
+ break;
1114
+ case 'script':
1115
+ this.emitNode('onscript', this.script);
1116
+ this.script = '';
1117
+ break;
1118
+ default:
1119
+ this.errorFunction("Max buffer length exceeded: ".concat(this.BUFFERS[i]));
1120
+ }
1121
+ }
1122
+ maxActual = Math.max(maxActual, len);
1123
+ }
1124
+ const m = this.opt.MAX_BUFFER_LENGTH - maxActual;
1125
+ this.bufferCheckPosition = m + this.position;
1126
+ }
1127
+ openTag(selfClosing) {
1128
+ if (this.opt.xmlns) {
1129
+ const tag = this.tag;
1130
+
1131
+ const qn = SAX.qname(this.tagName);
1132
+ tag.prefix = qn.prefix;
1133
+ tag.local = qn.local;
1134
+ tag.uri = tag.ns[qn.prefix] || '';
1135
+ if (tag.prefix && !tag.uri) {
1136
+ this.strictFail("Unbound namespace prefix: ".concat(JSON.stringify(this.tagName)));
1137
+ tag.uri = qn.prefix;
1138
+ }
1139
+ const parent = this.tags[this.tags.length - 1] || this;
1140
+ if (tag.ns && parent.ns !== tag.ns) {
1141
+ const that = this;
1142
+ Object.keys(tag.ns).forEach(p => {
1143
+ that.emitNode('onopennamespace', {
1144
+ prefix: p,
1145
+ uri: tag.ns[p]
1146
+ });
1147
+ });
1148
+ }
1149
+
1150
+ for (let i = 0, l = this.attribList.length; i < l; i++) {
1151
+ const nv = this.attribList[i];
1152
+ const name = nv[0];
1153
+ const value = nv[1];
1154
+ const qualName = SAX.qname(name, true);
1155
+ const prefix = qualName.prefix;
1156
+ const local = qualName.local;
1157
+ const uri = prefix === '' ? '' : tag.ns[prefix] || '';
1158
+ const a = {
1159
+ name,
1160
+ value,
1161
+ prefix,
1162
+ local,
1163
+ uri
1164
+ };
1165
+
1166
+ if (prefix && prefix !== 'xmlns' && !uri) {
1167
+ this.strictFail("Unbound namespace prefix: ".concat(JSON.stringify(prefix)));
1168
+ a.uri = prefix;
1169
+ }
1170
+ this.tag.attributes[name] = a;
1171
+ this.emitNode('onattribute', a);
1172
+ }
1173
+ this.attribList.length = 0;
1174
+ }
1175
+ this.tag.isSelfClosing = Boolean(selfClosing);
1176
+
1177
+ this.sawRoot = true;
1178
+ this.tags.push(this.tag);
1179
+ this.emitNode('onopentag', this.tag);
1180
+ if (!selfClosing) {
1181
+ if (!this.noscript && this.tagName.toLowerCase() === 'script') {
1182
+ this.state = this.S.SCRIPT;
1183
+ } else {
1184
+ this.state = this.S.TEXT;
1185
+ }
1186
+ this.tag = null;
1187
+ this.tagName = '';
1188
+ }
1189
+ this.attribName = this.attribValue = '';
1190
+ this.attribList.length = 0;
1191
+ }
1192
+ closeTag() {
1193
+ if (!this.tagName) {
1194
+ this.strictFail('Weird empty close tag.');
1195
+ this.textNode += '</>';
1196
+ this.state = this.S.TEXT;
1197
+ return;
1198
+ }
1199
+ if (this.script) {
1200
+ if (this.tagName !== 'script') {
1201
+ this.script += "</".concat(this.tagName, ">");
1202
+ this.tagName = '';
1203
+ this.state = this.S.SCRIPT;
1204
+ return;
1205
+ }
1206
+ this.emitNode('onscript', this.script);
1207
+ this.script = '';
1208
+ }
1209
+
1210
+ let t = this.tags.length;
1211
+ let tagName = this.tagName;
1212
+ if (!this.strict) {
1213
+ tagName = tagName[this.looseCase]();
1214
+ }
1215
+ while (t--) {
1216
+ const close = this.tags[t];
1217
+ if (close.name !== tagName) {
1218
+ this.strictFail('Unexpected close tag');
1219
+ } else {
1220
+ break;
1221
+ }
1222
+ }
1223
+
1224
+ if (t < 0) {
1225
+ this.strictFail("Unmatched closing tag: ".concat(this.tagName));
1226
+ this.textNode += "</".concat(this.tagName, ">");
1227
+ this.state = this.S.TEXT;
1228
+ return;
1229
+ }
1230
+ this.tagName = tagName;
1231
+ let s = this.tags.length;
1232
+ while (s-- > t) {
1233
+ const tag = this.tag = this.tags.pop();
1234
+ this.tagName = this.tag.name;
1235
+ this.emitNode('onclosetag', this.tagName);
1236
+ const x = {};
1237
+ for (const i in tag.ns) {
1238
+ if (tag.ns.hasOwnProperty(i)) {
1239
+ x[i] = tag.ns[i];
1240
+ }
1241
+ }
1242
+ const parent = this.tags[this.tags.length - 1] || this;
1243
+ if (this.opt.xmlns && tag.ns !== parent.ns) {
1244
+ const that = this;
1245
+ Object.keys(tag.ns).forEach(p => {
1246
+ const n = tag.ns[p];
1247
+ that.emitNode('onclosenamespace', {
1248
+ prefix: p,
1249
+ uri: n
1250
+ });
1251
+ });
1252
+ }
1253
+ }
1254
+ if (t === 0) this.closedRoot = true;
1255
+ this.tagName = this.attribValue = this.attribName = '';
1256
+ this.attribList.length = 0;
1257
+ this.state = this.S.TEXT;
1258
+ }
1259
+ }
1260
+
1261
+ export class SAXParser extends SAX {
1262
+ constructor(opt) {
1263
+ super();
1264
+ _defineProperty(this, "opt", DEFAULT_SAX_PARSER_OPTIONS);
1265
+ _defineProperty(this, "events", DEFAULT_SAX_EVENTS);
1266
+ this.clearBuffers();
1267
+ this.opt = opt = {
1268
+ ...this.opt,
1269
+ ...opt
1270
+ };
1271
+ this.events = {
1272
+ ...this.events,
1273
+ ...opt
1274
+ };
1275
+ this.q = this.c = '';
1276
+ this.opt.lowercase = this.opt.lowercase || this.opt.lowercasetags;
1277
+ this.bufferCheckPosition = this.opt.MAX_BUFFER_LENGTH;
1278
+ this.looseCase = this.opt.lowercase ? 'toLowerCase' : 'toUpperCase';
1279
+ this.tags = [];
1280
+ this.closed = this.closedRoot = this.sawRoot = false;
1281
+ this.tag = this.error = null;
1282
+ this.strict = Boolean(this.opt.strict);
1283
+ this.noscript = Boolean(this.opt.strict || this.opt.noscript);
1284
+ this.state = this.S.BEGIN;
1285
+ this.strictEntities = this.opt.strictEntities;
1286
+ this.ENTITIES = this.strictEntities ? Object.create(this.XML_ENTITIES) : Object.create(this.ENTITIES);
1287
+ this.attribList = [];
1288
+
1289
+ if (this.opt.xmlns) {
1290
+ this.ns = Object.create(this.rootNS);
1291
+ }
1292
+
1293
+ this.trackPosition = this.opt.position !== false;
1294
+ if (this.trackPosition) {
1295
+ this.position = this.line = this.column = 0;
1296
+ }
1297
+ this.emit('onready');
1298
+ }
1299
+ resume() {
1300
+ this.error = null;
1301
+ return this;
1302
+ }
1303
+ close() {
1304
+ return this.write(null);
1305
+ }
1306
+ flush() {
1307
+ this.flushBuffers();
1308
+ }
1309
+ }
1310
+ _defineProperty(SAXParser, "ENTITIES", ENTITIES);
1311
+ //# sourceMappingURL=sax.js.map