@loaders.gl/xml 4.0.0-beta.2 → 4.0.0-beta.3

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 (51) hide show
  1. package/dist/{dist.min.js → dist.dev.js} +2154 -2055
  2. package/dist/{esm/html-loader.js → html-loader.js} +1 -1
  3. package/dist/html-loader.js.map +1 -0
  4. package/dist/index.cjs +1530 -0
  5. package/dist/index.js +6 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/{esm/lib → lib}/parsers/parse-xml.js +2 -2
  8. package/dist/lib/parsers/parse-xml.js.map +1 -0
  9. package/dist/{esm/lib → lib}/parsers/streaming-xml-parser.js +6 -7
  10. package/dist/lib/parsers/streaming-xml-parser.js.map +1 -0
  11. package/dist/lib/xml-utils/uncapitalize.js.map +1 -0
  12. package/dist/lib/xml-utils/xml-utils.js.map +1 -0
  13. package/dist/{esm/sax-ts → sax-ts}/sax.js +75 -76
  14. package/dist/sax-ts/sax.js.map +1 -0
  15. package/dist/{esm/xml-loader.js → xml-loader.js} +2 -2
  16. package/dist/xml-loader.js.map +1 -0
  17. package/package.json +16 -8
  18. package/dist/bundle.d.ts +0 -2
  19. package/dist/bundle.d.ts.map +0 -1
  20. package/dist/es5/bundle.js +0 -6
  21. package/dist/es5/bundle.js.map +0 -1
  22. package/dist/es5/html-loader.js +0 -58
  23. package/dist/es5/html-loader.js.map +0 -1
  24. package/dist/es5/index.js +0 -53
  25. package/dist/es5/index.js.map +0 -1
  26. package/dist/es5/lib/parsers/parse-xml.js +0 -53
  27. package/dist/es5/lib/parsers/parse-xml.js.map +0 -1
  28. package/dist/es5/lib/parsers/streaming-xml-parser.js +0 -134
  29. package/dist/es5/lib/parsers/streaming-xml-parser.js.map +0 -1
  30. package/dist/es5/lib/xml-utils/uncapitalize.js +0 -32
  31. package/dist/es5/lib/xml-utils/uncapitalize.js.map +0 -1
  32. package/dist/es5/lib/xml-utils/xml-utils.js +0 -23
  33. package/dist/es5/lib/xml-utils/xml-utils.js.map +0 -1
  34. package/dist/es5/sax-ts/sax.js +0 -1372
  35. package/dist/es5/sax-ts/sax.js.map +0 -1
  36. package/dist/es5/xml-loader.js +0 -58
  37. package/dist/es5/xml-loader.js.map +0 -1
  38. package/dist/esm/bundle.js +0 -4
  39. package/dist/esm/bundle.js.map +0 -1
  40. package/dist/esm/html-loader.js.map +0 -1
  41. package/dist/esm/index.js +0 -6
  42. package/dist/esm/index.js.map +0 -1
  43. package/dist/esm/lib/parsers/parse-xml.js.map +0 -1
  44. package/dist/esm/lib/parsers/streaming-xml-parser.js.map +0 -1
  45. package/dist/esm/lib/xml-utils/uncapitalize.js.map +0 -1
  46. package/dist/esm/lib/xml-utils/xml-utils.js.map +0 -1
  47. package/dist/esm/sax-ts/sax.js.map +0 -1
  48. package/dist/esm/xml-loader.js.map +0 -1
  49. package/src/bundle.ts +0 -4
  50. /package/dist/{esm/lib → lib}/xml-utils/uncapitalize.js +0 -0
  51. /package/dist/{esm/lib → lib}/xml-utils/xml-utils.js +0 -0
@@ -1,1934 +1,620 @@
1
- (() => {
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if (typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if (typeof define === 'function' && define.amd) define([], factory);
5
+ else if (typeof exports === 'object') exports['loader'] = factory();
6
+ else root['loader'] = factory();})(globalThis, function () {
7
+ "use strict";
8
+ var __exports__ = (() => {
2
9
  var __create = Object.create;
3
10
  var __defProp = Object.defineProperty;
4
11
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
12
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
13
  var __getProtoOf = Object.getPrototypeOf;
7
14
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
9
- var __esm = (fn, res) => function __init() {
10
- return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
11
- };
15
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
16
  var __commonJS = (cb, mod) => function __require() {
13
- return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
14
18
  };
15
19
  var __export = (target, all) => {
16
- __markAsModule(target);
17
20
  for (var name in all)
18
21
  __defProp(target, name, { get: all[name], enumerable: true });
19
22
  };
20
- var __reExport = (target, module, desc) => {
21
- if (module && typeof module === "object" || typeof module === "function") {
22
- for (let key of __getOwnPropNames(module))
23
- if (!__hasOwnProp.call(target, key) && key !== "default")
24
- __defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
23
+ var __copyProps = (to, from, except, desc) => {
24
+ if (from && typeof from === "object" || typeof from === "function") {
25
+ for (let key of __getOwnPropNames(from))
26
+ if (!__hasOwnProp.call(to, key) && key !== except)
27
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
28
  }
26
- return target;
29
+ return to;
27
30
  };
28
- var __toModule = (module) => {
29
- return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
31
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
32
+ // If the importer is in node compatibility mode or this is not an ESM
33
+ // file that has been converted to a CommonJS file using a Babel-
34
+ // compatible transform (i.e. "__esModule" has not been set), then set
35
+ // "default" to the CommonJS "module.exports" for node compatibility.
36
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
+ mod
38
+ ));
39
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
+ var __publicField = (obj, key, value) => {
41
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
42
+ return value;
30
43
  };
31
44
 
32
- // src/sax-ts/sax.ts
33
- var DEFAULT_SAX_EVENTS, DEFAULT_SAX_PARSER_OPTIONS, EVENTS, BUFFERS, nameStart, nameBody, entityStart, entityBody, ENTITIES, SAX, SAXParser;
34
- var init_sax = __esm({
35
- "src/sax-ts/sax.ts"() {
36
- DEFAULT_SAX_EVENTS = {
37
- ontext: () => {
38
- },
39
- onprocessinginstruction: () => {
40
- },
41
- onsgmldeclaration: () => {
42
- },
43
- ondoctype: () => {
44
- },
45
- oncomment: () => {
46
- },
47
- onopentagstart: () => {
48
- },
49
- onattribute: () => {
50
- },
51
- onopentag: () => {
52
- },
53
- onclosetag: () => {
54
- },
55
- onopencdata: () => {
56
- },
57
- oncdata: () => {
58
- },
59
- onclosecdata: () => {
60
- },
61
- onerror: () => {
62
- },
63
- onend: () => {
64
- },
65
- onready: () => {
66
- },
67
- onscript: () => {
68
- },
69
- onopennamespace: () => {
70
- },
71
- onclosenamespace: () => {
45
+ // ../../node_modules/fast-xml-parser/src/util.js
46
+ var require_util = __commonJS({
47
+ "../../node_modules/fast-xml-parser/src/util.js"(exports) {
48
+ "use strict";
49
+ var nameStartChar = ":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";
50
+ var nameChar = nameStartChar + "\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
51
+ var nameRegexp = "[" + nameStartChar + "][" + nameChar + "]*";
52
+ var regexName = new RegExp("^" + nameRegexp + "$");
53
+ var getAllMatches = function(string, regex) {
54
+ const matches = [];
55
+ let match = regex.exec(string);
56
+ while (match) {
57
+ const allmatches = [];
58
+ allmatches.startIndex = regex.lastIndex - match[0].length;
59
+ const len = match.length;
60
+ for (let index = 0; index < len; index++) {
61
+ allmatches.push(match[index]);
62
+ }
63
+ matches.push(allmatches);
64
+ match = regex.exec(string);
72
65
  }
66
+ return matches;
73
67
  };
74
- DEFAULT_SAX_PARSER_OPTIONS = {
75
- ...DEFAULT_SAX_EVENTS,
76
- strict: false,
77
- MAX_BUFFER_LENGTH: 64 * 1024,
78
- lowercase: false,
79
- lowercasetags: false,
80
- noscript: false,
81
- strictEntities: false,
82
- xmlns: void 0,
83
- position: void 0,
84
- trim: void 0,
85
- normalize: void 0
68
+ var isName = function(string) {
69
+ const match = regexName.exec(string);
70
+ return !(match === null || typeof match === "undefined");
86
71
  };
87
- EVENTS = [
88
- "text",
89
- "processinginstruction",
90
- "sgmldeclaration",
91
- "doctype",
92
- "comment",
93
- "opentagstart",
94
- "attribute",
95
- "opentag",
96
- "closetag",
97
- "opencdata",
98
- "cdata",
99
- "closecdata",
100
- "error",
101
- "end",
102
- "ready",
103
- "script",
104
- "opennamespace",
105
- "closenamespace"
106
- ];
107
- BUFFERS = [
108
- "comment",
109
- "sgmlDecl",
110
- "textNode",
111
- "tagName",
112
- "doctype",
113
- "procInstName",
114
- "procInstBody",
115
- "entity",
116
- "attribName",
117
- "attribValue",
118
- "cdata",
119
- "script"
120
- ];
121
- 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]/;
122
- 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-]/;
123
- 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]/;
124
- 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-]/;
125
- ENTITIES = {
126
- amp: "&",
127
- gt: ">",
128
- lt: "<",
129
- quot: '"',
130
- apos: "'",
131
- AElig: 198,
132
- Aacute: 193,
133
- Acirc: 194,
134
- Agrave: 192,
135
- Aring: 197,
136
- Atilde: 195,
137
- Auml: 196,
138
- Ccedil: 199,
139
- ETH: 208,
140
- Eacute: 201,
141
- Ecirc: 202,
142
- Egrave: 200,
143
- Euml: 203,
144
- Iacute: 205,
145
- Icirc: 206,
146
- Igrave: 204,
147
- Iuml: 207,
148
- Ntilde: 209,
149
- Oacute: 211,
150
- Ocirc: 212,
151
- Ograve: 210,
152
- Oslash: 216,
153
- Otilde: 213,
154
- Ouml: 214,
155
- THORN: 222,
156
- Uacute: 218,
157
- Ucirc: 219,
158
- Ugrave: 217,
159
- Uuml: 220,
160
- Yacute: 221,
161
- aacute: 225,
162
- acirc: 226,
163
- aelig: 230,
164
- agrave: 224,
165
- aring: 229,
166
- atilde: 227,
167
- auml: 228,
168
- ccedil: 231,
169
- eacute: 233,
170
- ecirc: 234,
171
- egrave: 232,
172
- eth: 240,
173
- euml: 235,
174
- iacute: 237,
175
- icirc: 238,
176
- igrave: 236,
177
- iuml: 239,
178
- ntilde: 241,
179
- oacute: 243,
180
- ocirc: 244,
181
- ograve: 242,
182
- oslash: 248,
183
- otilde: 245,
184
- ouml: 246,
185
- szlig: 223,
186
- thorn: 254,
187
- uacute: 250,
188
- ucirc: 251,
189
- ugrave: 249,
190
- uuml: 252,
191
- yacute: 253,
192
- yuml: 255,
193
- copy: 169,
194
- reg: 174,
195
- nbsp: 160,
196
- iexcl: 161,
197
- cent: 162,
198
- pound: 163,
199
- curren: 164,
200
- yen: 165,
201
- brvbar: 166,
202
- sect: 167,
203
- uml: 168,
204
- ordf: 170,
205
- laquo: 171,
206
- not: 172,
207
- shy: 173,
208
- macr: 175,
209
- deg: 176,
210
- plusmn: 177,
211
- sup1: 185,
212
- sup2: 178,
213
- sup3: 179,
214
- acute: 180,
215
- micro: 181,
216
- para: 182,
217
- middot: 183,
218
- cedil: 184,
219
- ordm: 186,
220
- raquo: 187,
221
- frac14: 188,
222
- frac12: 189,
223
- frac34: 190,
224
- iquest: 191,
225
- times: 215,
226
- divide: 247,
227
- OElig: 338,
228
- oelig: 339,
229
- Scaron: 352,
230
- scaron: 353,
231
- Yuml: 376,
232
- fnof: 402,
233
- circ: 710,
234
- tilde: 732,
235
- Alpha: 913,
236
- Beta: 914,
237
- Gamma: 915,
238
- Delta: 916,
239
- Epsilon: 917,
240
- Zeta: 918,
241
- Eta: 919,
242
- Theta: 920,
243
- Iota: 921,
244
- Kappa: 922,
245
- Lambda: 923,
246
- Mu: 924,
247
- Nu: 925,
248
- Xi: 926,
249
- Omicron: 927,
250
- Pi: 928,
251
- Rho: 929,
252
- Sigma: 931,
253
- Tau: 932,
254
- Upsilon: 933,
255
- Phi: 934,
256
- Chi: 935,
257
- Psi: 936,
258
- Omega: 937,
259
- alpha: 945,
260
- beta: 946,
261
- gamma: 947,
262
- delta: 948,
263
- epsilon: 949,
264
- zeta: 950,
265
- eta: 951,
266
- theta: 952,
267
- iota: 953,
268
- kappa: 954,
269
- lambda: 955,
270
- mu: 956,
271
- nu: 957,
272
- xi: 958,
273
- omicron: 959,
274
- pi: 960,
275
- rho: 961,
276
- sigmaf: 962,
277
- sigma: 963,
278
- tau: 964,
279
- upsilon: 965,
280
- phi: 966,
281
- chi: 967,
282
- psi: 968,
283
- omega: 969,
284
- thetasym: 977,
285
- upsih: 978,
286
- piv: 982,
287
- ensp: 8194,
288
- emsp: 8195,
289
- thinsp: 8201,
290
- zwnj: 8204,
291
- zwj: 8205,
292
- lrm: 8206,
293
- rlm: 8207,
294
- ndash: 8211,
295
- mdash: 8212,
296
- lsquo: 8216,
297
- rsquo: 8217,
298
- sbquo: 8218,
299
- ldquo: 8220,
300
- rdquo: 8221,
301
- bdquo: 8222,
302
- dagger: 8224,
303
- Dagger: 8225,
304
- bull: 8226,
305
- hellip: 8230,
306
- permil: 8240,
307
- prime: 8242,
308
- Prime: 8243,
309
- lsaquo: 8249,
310
- rsaquo: 8250,
311
- oline: 8254,
312
- frasl: 8260,
313
- euro: 8364,
314
- image: 8465,
315
- weierp: 8472,
316
- real: 8476,
317
- trade: 8482,
318
- alefsym: 8501,
319
- larr: 8592,
320
- uarr: 8593,
321
- rarr: 8594,
322
- darr: 8595,
323
- harr: 8596,
324
- crarr: 8629,
325
- lArr: 8656,
326
- uArr: 8657,
327
- rArr: 8658,
328
- dArr: 8659,
329
- hArr: 8660,
330
- forall: 8704,
331
- part: 8706,
332
- exist: 8707,
333
- empty: 8709,
334
- nabla: 8711,
335
- isin: 8712,
336
- notin: 8713,
337
- ni: 8715,
338
- prod: 8719,
339
- sum: 8721,
340
- minus: 8722,
341
- lowast: 8727,
342
- radic: 8730,
343
- prop: 8733,
344
- infin: 8734,
345
- ang: 8736,
346
- and: 8743,
347
- or: 8744,
348
- cap: 8745,
349
- cup: 8746,
350
- int: 8747,
351
- there4: 8756,
352
- sim: 8764,
353
- cong: 8773,
354
- asymp: 8776,
355
- ne: 8800,
356
- equiv: 8801,
357
- le: 8804,
358
- ge: 8805,
359
- sub: 8834,
360
- sup: 8835,
361
- nsub: 8836,
362
- sube: 8838,
363
- supe: 8839,
364
- oplus: 8853,
365
- otimes: 8855,
366
- perp: 8869,
367
- sdot: 8901,
368
- lceil: 8968,
369
- rceil: 8969,
370
- lfloor: 8970,
371
- rfloor: 8971,
372
- lang: 9001,
373
- rang: 9002,
374
- loz: 9674,
375
- spades: 9824,
376
- clubs: 9827,
377
- hearts: 9829,
378
- diams: 9830
72
+ exports.isExist = function(v) {
73
+ return typeof v !== "undefined";
379
74
  };
380
- Object.keys(ENTITIES).forEach((key) => {
381
- const e = ENTITIES[key];
382
- ENTITIES[key] = typeof e === "number" ? String.fromCharCode(e) : e;
383
- });
384
- SAX = class {
385
- constructor() {
386
- this.EVENTS = EVENTS;
387
- this.ENTITIES = {
388
- ...ENTITIES
389
- };
390
- this.XML_ENTITIES = {
391
- amp: "&",
392
- gt: ">",
393
- lt: "<",
394
- quot: '"',
395
- apos: "'"
396
- };
397
- this.S = 0;
398
- this.trackPosition = false;
399
- this.column = 0;
400
- this.line = 0;
401
- this.c = "";
402
- this.q = "";
403
- this.closed = false;
404
- this.tags = [];
405
- this.looseCase = "";
406
- this.closedRoot = false;
407
- this.sawRoot = false;
408
- this.strict = false;
409
- this.noscript = false;
410
- this.attribList = [];
411
- this.position = 0;
412
- this.STATE = {
413
- BEGIN: this.S++,
414
- BEGIN_WHITESPACE: this.S++,
415
- TEXT: this.S++,
416
- TEXT_ENTITY: this.S++,
417
- OPEN_WAKA: this.S++,
418
- SGML_DECL: this.S++,
419
- SGML_DECL_QUOTED: this.S++,
420
- DOCTYPE: this.S++,
421
- DOCTYPE_QUOTED: this.S++,
422
- DOCTYPE_DTD: this.S++,
423
- DOCTYPE_DTD_QUOTED: this.S++,
424
- COMMENT_STARTING: this.S++,
425
- COMMENT: this.S++,
426
- COMMENT_ENDING: this.S++,
427
- COMMENT_ENDED: this.S++,
428
- CDATA: this.S++,
429
- CDATA_ENDING: this.S++,
430
- CDATA_ENDING_2: this.S++,
431
- PROC_INST: this.S++,
432
- PROC_INST_BODY: this.S++,
433
- PROC_INST_ENDING: this.S++,
434
- OPEN_TAG: this.S++,
435
- OPEN_TAG_SLASH: this.S++,
436
- ATTRIB: this.S++,
437
- ATTRIB_NAME: this.S++,
438
- ATTRIB_NAME_SAW_WHITE: this.S++,
439
- ATTRIB_VALUE: this.S++,
440
- ATTRIB_VALUE_QUOTED: this.S++,
441
- ATTRIB_VALUE_CLOSED: this.S++,
442
- ATTRIB_VALUE_UNQUOTED: this.S++,
443
- ATTRIB_VALUE_ENTITY_Q: this.S++,
444
- ATTRIB_VALUE_ENTITY_U: this.S++,
445
- CLOSE_TAG: this.S++,
446
- CLOSE_TAG_SAW_WHITE: this.S++,
447
- SCRIPT: this.S++,
448
- SCRIPT_ENDING: this.S++
449
- };
450
- this.BUFFERS = BUFFERS;
451
- this.CDATA = "[CDATA[";
452
- this.DOCTYPE = "DOCTYPE";
453
- this.XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
454
- this.XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
455
- this.rootNS = {
456
- xml: this.XML_NAMESPACE,
457
- xmlns: this.XMLNS_NAMESPACE
458
- };
459
- this.textNode = "";
460
- this.entity = "";
461
- this.cdata = "";
462
- this.script = "";
463
- this.startTagPosition = 0;
464
- this.S = 0;
465
- for (const s in this.STATE) {
466
- if (this.STATE.hasOwnProperty(s)) {
467
- this.STATE[this.STATE[s]] = s;
75
+ exports.isEmptyObject = function(obj) {
76
+ return Object.keys(obj).length === 0;
77
+ };
78
+ exports.merge = function(target, a, arrayMode) {
79
+ if (a) {
80
+ const keys = Object.keys(a);
81
+ const len = keys.length;
82
+ for (let i = 0; i < len; i++) {
83
+ if (arrayMode === "strict") {
84
+ target[keys[i]] = [a[keys[i]]];
85
+ } else {
86
+ target[keys[i]] = a[keys[i]];
468
87
  }
469
88
  }
470
- this.S = this.STATE;
471
- }
472
- static charAt(chunk, i) {
473
- let result = "";
474
- if (i < chunk.length) {
475
- result = chunk.charAt(i);
476
- }
477
- return result;
478
89
  }
479
- static isWhitespace(c) {
480
- return c === " " || c === "\n" || c === "\r" || c === " ";
481
- }
482
- static isQuote(c) {
483
- return c === '"' || c === "'";
484
- }
485
- static isAttribEnd(c) {
486
- return c === ">" || SAX.isWhitespace(c);
487
- }
488
- static isMatch(regex, c) {
489
- return regex.test(c);
490
- }
491
- static notMatch(regex, c) {
492
- return !SAX.isMatch(regex, c);
90
+ };
91
+ exports.getValue = function(v) {
92
+ if (exports.isExist(v)) {
93
+ return v;
94
+ } else {
95
+ return "";
493
96
  }
494
- static qname(name, attribute) {
495
- const i = name.indexOf(":");
496
- const qualName = i < 0 ? ["", name] : name.split(":");
497
- let prefix = qualName[0];
498
- let local = qualName[1];
499
- if (attribute && name === "xmlns") {
500
- prefix = "xmlns";
501
- local = "";
502
- }
503
- return { prefix, local };
97
+ };
98
+ exports.isName = isName;
99
+ exports.getAllMatches = getAllMatches;
100
+ exports.nameRegexp = nameRegexp;
101
+ }
102
+ });
103
+
104
+ // ../../node_modules/fast-xml-parser/src/validator.js
105
+ var require_validator = __commonJS({
106
+ "../../node_modules/fast-xml-parser/src/validator.js"(exports) {
107
+ "use strict";
108
+ var util = require_util();
109
+ var defaultOptions = {
110
+ allowBooleanAttributes: false,
111
+ //A tag can have attributes without any value
112
+ unpairedTags: []
113
+ };
114
+ exports.validate = function(xmlData, options) {
115
+ options = Object.assign({}, defaultOptions, options);
116
+ const tags = [];
117
+ let tagFound = false;
118
+ let reachedRoot = false;
119
+ if (xmlData[0] === "\uFEFF") {
120
+ xmlData = xmlData.substr(1);
504
121
  }
505
- write(chunk) {
506
- if (this.error) {
507
- throw this.error;
508
- }
509
- if (this.closed) {
510
- return this.errorFunction("Cannot write after close. Assign an onready handler.");
511
- }
512
- if (chunk === null) {
513
- return this.end();
514
- }
515
- if (typeof chunk === "object") {
516
- chunk = chunk.toString();
517
- }
518
- let i = 0;
519
- let c;
520
- while (true) {
521
- c = SAX.charAt(chunk, i++);
522
- this.c = c;
523
- if (!c) {
524
- break;
525
- }
526
- if (this.trackPosition) {
527
- this.position++;
528
- if (c === "\n") {
529
- this.line++;
530
- this.column = 0;
531
- } else {
532
- this.column++;
122
+ for (let i = 0; i < xmlData.length; i++) {
123
+ if (xmlData[i] === "<" && xmlData[i + 1] === "?") {
124
+ i += 2;
125
+ i = readPI(xmlData, i);
126
+ if (i.err)
127
+ return i;
128
+ } else if (xmlData[i] === "<") {
129
+ let tagStartPos = i;
130
+ i++;
131
+ if (xmlData[i] === "!") {
132
+ i = readCommentAndCDATA(xmlData, i);
133
+ continue;
134
+ } else {
135
+ let closingTag = false;
136
+ if (xmlData[i] === "/") {
137
+ closingTag = true;
138
+ i++;
533
139
  }
534
- }
535
- switch (this.state) {
536
- case this.S.BEGIN:
537
- this.state = this.S.BEGIN_WHITESPACE;
538
- if (c === "\uFEFF") {
539
- continue;
540
- }
541
- this.beginWhiteSpace(c);
542
- continue;
543
- case this.S.BEGIN_WHITESPACE:
544
- this.beginWhiteSpace(c);
545
- continue;
546
- case this.S.TEXT:
547
- if (this.sawRoot && !this.closedRoot) {
548
- const starti = i - 1;
549
- while (c && c !== "<" && c !== "&") {
550
- c = SAX.charAt(chunk, i++);
551
- if (c && this.trackPosition) {
552
- this.position++;
553
- if (c === "\n") {
554
- this.line++;
555
- this.column = 0;
556
- } else {
557
- this.column++;
558
- }
559
- }
560
- }
561
- this.textNode += chunk.substring(starti, i - 1);
562
- }
563
- if (c === "<" && !(this.sawRoot && this.closedRoot && !this.strict)) {
564
- this.state = this.S.OPEN_WAKA;
565
- this.startTagPosition = this.position;
566
- } else {
567
- if (!SAX.isWhitespace(c) && (!this.sawRoot || this.closedRoot)) {
568
- this.strictFail("Text data outside of root node.");
569
- }
570
- if (c === "&") {
571
- this.state = this.S.TEXT_ENTITY;
572
- } else {
573
- this.textNode += c;
574
- }
575
- }
576
- continue;
577
- case this.S.SCRIPT:
578
- if (c === "<") {
579
- this.state = this.S.SCRIPT_ENDING;
580
- } else {
581
- this.script += c;
582
- }
583
- continue;
584
- case this.S.SCRIPT_ENDING:
585
- if (c === "/") {
586
- this.state = this.S.CLOSE_TAG;
587
- } else {
588
- this.script += `<${c}`;
589
- this.state = this.S.SCRIPT;
590
- }
591
- continue;
592
- case this.S.OPEN_WAKA:
593
- if (c === "!") {
594
- this.state = this.S.SGML_DECL;
595
- this.sgmlDecl = "";
596
- } else if (SAX.isWhitespace(c)) {
597
- } else if (SAX.isMatch(nameStart, c)) {
598
- this.state = this.S.OPEN_TAG;
599
- this.tagName = c;
600
- } else if (c === "/") {
601
- this.state = this.S.CLOSE_TAG;
602
- this.tagName = "";
603
- } else if (c === "?") {
604
- this.state = this.S.PROC_INST;
605
- this.procInstName = this.procInstBody = "";
606
- } else {
607
- this.strictFail("Unencoded <");
608
- if (this.startTagPosition + 1 < this.position) {
609
- const pad = this.position - this.startTagPosition;
610
- c = new Array(pad).join(" ") + c;
611
- }
612
- this.textNode += `<${c}`;
613
- this.state = this.S.TEXT;
614
- }
615
- continue;
616
- case this.S.SGML_DECL:
617
- if ((this.sgmlDecl + c).toUpperCase() === this.CDATA) {
618
- this.emitNode("onopencdata");
619
- this.state = this.S.CDATA;
620
- this.sgmlDecl = "";
621
- this.cdata = "";
622
- } else if (this.sgmlDecl + c === "--") {
623
- this.state = this.S.COMMENT;
624
- this.comment = "";
625
- this.sgmlDecl = "";
626
- } else if ((this.sgmlDecl + c).toUpperCase() === this.DOCTYPE) {
627
- this.state = this.S.DOCTYPE;
628
- if (this.doctype || this.sawRoot) {
629
- this.strictFail("Inappropriately located doctype declaration");
630
- }
631
- this.doctype = "";
632
- this.sgmlDecl = "";
633
- } else if (c === ">") {
634
- this.emitNode("onsgmldeclaration", this.sgmlDecl);
635
- this.sgmlDecl = "";
636
- this.state = this.S.TEXT;
637
- } else if (SAX.isQuote(c)) {
638
- this.state = this.S.SGML_DECL_QUOTED;
639
- this.sgmlDecl += c;
140
+ let tagName = "";
141
+ for (; i < xmlData.length && xmlData[i] !== ">" && xmlData[i] !== " " && xmlData[i] !== " " && xmlData[i] !== "\n" && xmlData[i] !== "\r"; i++) {
142
+ tagName += xmlData[i];
143
+ }
144
+ tagName = tagName.trim();
145
+ if (tagName[tagName.length - 1] === "/") {
146
+ tagName = tagName.substring(0, tagName.length - 1);
147
+ i--;
148
+ }
149
+ if (!validateTagName(tagName)) {
150
+ let msg;
151
+ if (tagName.trim().length === 0) {
152
+ msg = "Invalid space after '<'.";
640
153
  } else {
641
- this.sgmlDecl += c;
642
- }
643
- continue;
644
- case this.S.SGML_DECL_QUOTED:
645
- if (c === this.q) {
646
- this.state = this.S.SGML_DECL;
647
- this.q = "";
154
+ msg = "Tag '" + tagName + "' is an invalid name.";
648
155
  }
649
- this.sgmlDecl += c;
650
- continue;
651
- case this.S.DOCTYPE:
652
- if (c === ">") {
653
- this.state = this.S.TEXT;
654
- this.emitNode("ondoctype", this.doctype);
655
- this.doctype = true;
156
+ return getErrorObject("InvalidTag", msg, getLineNumberForPosition(xmlData, i));
157
+ }
158
+ const result = readAttributeStr(xmlData, i);
159
+ if (result === false) {
160
+ return getErrorObject("InvalidAttr", "Attributes for '" + tagName + "' have open quote.", getLineNumberForPosition(xmlData, i));
161
+ }
162
+ let attrStr = result.value;
163
+ i = result.index;
164
+ if (attrStr[attrStr.length - 1] === "/") {
165
+ const attrStrStart = i - attrStr.length;
166
+ attrStr = attrStr.substring(0, attrStr.length - 1);
167
+ const isValid = validateAttributeString(attrStr, options);
168
+ if (isValid === true) {
169
+ tagFound = true;
656
170
  } else {
657
- this.doctype += c;
658
- if (c === "[") {
659
- this.state = this.S.DOCTYPE_DTD;
660
- } else if (SAX.isQuote(c)) {
661
- this.state = this.S.DOCTYPE_QUOTED;
662
- this.q = c;
663
- }
664
- }
665
- continue;
666
- case this.S.DOCTYPE_QUOTED:
667
- this.doctype += c;
668
- if (c === this.q) {
669
- this.q = "";
670
- this.state = this.S.DOCTYPE;
671
- }
672
- continue;
673
- case this.S.DOCTYPE_DTD:
674
- this.doctype += c;
675
- if (c === "]") {
676
- this.state = this.S.DOCTYPE;
677
- } else if (SAX.isQuote(c)) {
678
- this.state = this.S.DOCTYPE_DTD_QUOTED;
679
- this.q = c;
680
- }
681
- continue;
682
- case this.S.DOCTYPE_DTD_QUOTED:
683
- this.doctype += c;
684
- if (c === this.q) {
685
- this.state = this.S.DOCTYPE_DTD;
686
- this.q = "";
171
+ return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line));
687
172
  }
688
- continue;
689
- case this.S.COMMENT:
690
- if (c === "-") {
691
- this.state = this.S.COMMENT_ENDING;
173
+ } else if (closingTag) {
174
+ if (!result.tagClosed) {
175
+ return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
176
+ } else if (attrStr.trim().length > 0) {
177
+ return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
692
178
  } else {
693
- this.comment += c;
694
- }
695
- continue;
696
- case this.S.COMMENT_ENDING:
697
- if (c === "-") {
698
- this.state = this.S.COMMENT_ENDED;
699
- this.comment = this.textApplyOptions(this.comment);
700
- if (this.comment) {
701
- this.emitNode("oncomment", this.comment);
179
+ const otg = tags.pop();
180
+ if (tagName !== otg.tagName) {
181
+ let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
182
+ return getErrorObject("InvalidTag", "Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.", getLineNumberForPosition(xmlData, tagStartPos));
702
183
  }
703
- this.comment = "";
704
- } else {
705
- this.comment += `-${c}`;
706
- this.state = this.S.COMMENT;
707
- }
708
- continue;
709
- case this.S.COMMENT_ENDED:
710
- if (c !== ">") {
711
- this.strictFail("Malformed comment");
712
- this.comment += `--${c}`;
713
- this.state = this.S.COMMENT;
714
- } else {
715
- this.state = this.S.TEXT;
716
- }
717
- continue;
718
- case this.S.CDATA:
719
- if (c === "]") {
720
- this.state = this.S.CDATA_ENDING;
721
- } else {
722
- this.cdata += c;
723
- }
724
- continue;
725
- case this.S.CDATA_ENDING:
726
- if (c === "]") {
727
- this.state = this.S.CDATA_ENDING_2;
728
- } else {
729
- this.cdata += `]${c}`;
730
- this.state = this.S.CDATA;
731
- }
732
- continue;
733
- case this.S.CDATA_ENDING_2:
734
- if (c === ">") {
735
- if (this.cdata) {
736
- this.emitNode("oncdata", this.cdata);
184
+ if (tags.length == 0) {
185
+ reachedRoot = true;
737
186
  }
738
- this.emitNode("onclosecdata");
739
- this.cdata = "";
740
- this.state = this.S.TEXT;
741
- } else if (c === "]") {
742
- this.cdata += "]";
743
- } else {
744
- this.cdata += `]]${c}`;
745
- this.state = this.S.CDATA;
746
187
  }
747
- continue;
748
- case this.S.PROC_INST:
749
- if (c === "?") {
750
- this.state = this.S.PROC_INST_ENDING;
751
- } else if (SAX.isWhitespace(c)) {
752
- this.state = this.S.PROC_INST_BODY;
753
- } else {
754
- this.procInstName += c;
188
+ } else {
189
+ const isValid = validateAttributeString(attrStr, options);
190
+ if (isValid !== true) {
191
+ return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
755
192
  }
756
- continue;
757
- case this.S.PROC_INST_BODY:
758
- if (!this.procInstBody && SAX.isWhitespace(c)) {
759
- continue;
760
- } else if (c === "?") {
761
- this.state = this.S.PROC_INST_ENDING;
193
+ if (reachedRoot === true) {
194
+ return getErrorObject("InvalidXml", "Multiple possible root nodes found.", getLineNumberForPosition(xmlData, i));
195
+ } else if (options.unpairedTags.indexOf(tagName) !== -1) {
762
196
  } else {
763
- this.procInstBody += c;
764
- }
765
- continue;
766
- case this.S.PROC_INST_ENDING:
767
- if (c === ">") {
768
- this.emitNode("onprocessinginstruction", {
769
- name: this.procInstName,
770
- body: this.procInstBody
197
+ tags.push({
198
+ tagName,
199
+ tagStartPos
771
200
  });
772
- this.procInstName = this.procInstBody = "";
773
- this.state = this.S.TEXT;
774
- } else {
775
- this.procInstBody += `?${c}`;
776
- this.state = this.S.PROC_INST_BODY;
777
201
  }
778
- continue;
779
- case this.S.OPEN_TAG:
780
- if (SAX.isMatch(nameBody, c)) {
781
- this.tagName += c;
782
- } else {
783
- this.newTag();
784
- if (c === ">") {
785
- this.openTag();
786
- } else if (c === "/") {
787
- this.state = this.S.OPEN_TAG_SLASH;
202
+ tagFound = true;
203
+ }
204
+ for (i++; i < xmlData.length; i++) {
205
+ if (xmlData[i] === "<") {
206
+ if (xmlData[i + 1] === "!") {
207
+ i++;
208
+ i = readCommentAndCDATA(xmlData, i);
209
+ continue;
210
+ } else if (xmlData[i + 1] === "?") {
211
+ i = readPI(xmlData, ++i);
212
+ if (i.err)
213
+ return i;
788
214
  } else {
789
- if (!SAX.isWhitespace(c)) {
790
- this.strictFail("Invalid character in tag name");
791
- }
792
- this.state = this.S.ATTRIB;
215
+ break;
793
216
  }
794
- }
795
- continue;
796
- case this.S.OPEN_TAG_SLASH:
797
- if (c === ">") {
798
- this.openTag(true);
799
- this.closeTag();
800
- } else {
801
- this.strictFail("Forward-slash in opening tag not followed by >");
802
- this.state = this.S.ATTRIB;
803
- }
804
- continue;
805
- case this.S.ATTRIB:
806
- if (SAX.isWhitespace(c)) {
807
- continue;
808
- } else if (c === ">") {
809
- this.openTag();
810
- } else if (c === "/") {
811
- this.state = this.S.OPEN_TAG_SLASH;
812
- } else if (SAX.isMatch(nameStart, c)) {
813
- this.attribName = c;
814
- this.attribValue = "";
815
- this.state = this.S.ATTRIB_NAME;
217
+ } else if (xmlData[i] === "&") {
218
+ const afterAmp = validateAmpersand(xmlData, i);
219
+ if (afterAmp == -1)
220
+ return getErrorObject("InvalidChar", "char '&' is not expected.", getLineNumberForPosition(xmlData, i));
221
+ i = afterAmp;
816
222
  } else {
817
- this.strictFail("Invalid attribute name");
223
+ if (reachedRoot === true && !isWhiteSpace(xmlData[i])) {
224
+ return getErrorObject("InvalidXml", "Extra text at the end", getLineNumberForPosition(xmlData, i));
225
+ }
818
226
  }
819
- continue;
820
- case this.S.ATTRIB_NAME:
821
- if (c === "=") {
822
- this.state = this.S.ATTRIB_VALUE;
823
- } else if (c === ">") {
824
- this.strictFail("Attribute without value");
825
- this.attribValue = this.attribName;
826
- this.attrib();
827
- this.openTag();
828
- } else if (SAX.isWhitespace(c)) {
829
- this.state = this.S.ATTRIB_NAME_SAW_WHITE;
830
- } else if (SAX.isMatch(nameBody, c)) {
831
- this.attribName += c;
832
- } else {
833
- this.strictFail("Invalid attribute name");
834
- }
835
- continue;
836
- case this.S.ATTRIB_NAME_SAW_WHITE:
837
- if (c === "=") {
838
- this.state = this.S.ATTRIB_VALUE;
839
- } else if (SAX.isWhitespace(c)) {
840
- continue;
841
- } else {
842
- this.strictFail("Attribute without value");
843
- this.tag.attributes[this.attribName] = "";
844
- this.attribValue = "";
845
- this.emitNode("onattribute", {
846
- name: this.attribName,
847
- value: ""
848
- });
849
- this.attribName = "";
850
- if (c === ">") {
851
- this.openTag();
852
- } else if (SAX.isMatch(nameStart, c)) {
853
- this.attribName = c;
854
- this.state = this.S.ATTRIB_NAME;
855
- } else {
856
- this.strictFail("Invalid attribute name");
857
- this.state = this.S.ATTRIB;
858
- }
859
- }
860
- continue;
861
- case this.S.ATTRIB_VALUE:
862
- if (SAX.isWhitespace(c)) {
863
- continue;
864
- } else if (SAX.isQuote(c)) {
865
- this.q = c;
866
- this.state = this.S.ATTRIB_VALUE_QUOTED;
867
- } else {
868
- this.strictFail("Unquoted attribute value");
869
- this.state = this.S.ATTRIB_VALUE_UNQUOTED;
870
- this.attribValue = c;
871
- }
872
- continue;
873
- case this.S.ATTRIB_VALUE_QUOTED:
874
- if (c !== this.q) {
875
- if (c === "&") {
876
- this.state = this.S.ATTRIB_VALUE_ENTITY_Q;
877
- } else {
878
- this.attribValue += c;
879
- }
880
- continue;
881
- }
882
- this.attrib();
883
- this.q = "";
884
- this.state = this.S.ATTRIB_VALUE_CLOSED;
885
- continue;
886
- case this.S.ATTRIB_VALUE_CLOSED:
887
- if (SAX.isWhitespace(c)) {
888
- this.state = this.S.ATTRIB;
889
- } else if (c === ">") {
890
- this.openTag();
891
- } else if (c === "/") {
892
- this.state = this.S.OPEN_TAG_SLASH;
893
- } else if (SAX.isMatch(nameStart, c)) {
894
- this.strictFail("No whitespace between attributes");
895
- this.attribName = c;
896
- this.attribValue = "";
897
- this.state = this.S.ATTRIB_NAME;
898
- } else {
899
- this.strictFail("Invalid attribute name");
900
- }
901
- continue;
902
- case this.S.ATTRIB_VALUE_UNQUOTED:
903
- if (!SAX.isAttribEnd(c)) {
904
- if (c === "&") {
905
- this.state = this.S.ATTRIB_VALUE_ENTITY_U;
906
- } else {
907
- this.attribValue += c;
908
- }
909
- continue;
910
- }
911
- this.attrib();
912
- if (c === ">") {
913
- this.openTag();
914
- } else {
915
- this.state = this.S.ATTRIB;
916
- }
917
- continue;
918
- case this.S.CLOSE_TAG:
919
- if (!this.tagName) {
920
- if (SAX.isWhitespace(c)) {
921
- continue;
922
- } else if (SAX.notMatch(nameStart, c)) {
923
- if (this.script) {
924
- this.script += `</${c}`;
925
- this.state = this.S.SCRIPT;
926
- } else {
927
- this.strictFail("Invalid tagname in closing tag.");
928
- }
929
- } else {
930
- this.tagName = c;
931
- }
932
- } else if (c === ">") {
933
- this.closeTag();
934
- } else if (SAX.isMatch(nameBody, c)) {
935
- this.tagName += c;
936
- } else if (this.script) {
937
- this.script += `</${this.tagName}`;
938
- this.tagName = "";
939
- this.state = this.S.SCRIPT;
940
- } else {
941
- if (!SAX.isWhitespace(c)) {
942
- this.strictFail("Invalid tagname in closing tag");
943
- }
944
- this.state = this.S.CLOSE_TAG_SAW_WHITE;
945
- }
946
- continue;
947
- case this.S.CLOSE_TAG_SAW_WHITE:
948
- if (SAX.isWhitespace(c)) {
949
- continue;
950
- }
951
- if (c === ">") {
952
- this.closeTag();
953
- } else {
954
- this.strictFail("Invalid characters in closing tag");
955
- }
956
- continue;
957
- case this.S.TEXT_ENTITY:
958
- case this.S.ATTRIB_VALUE_ENTITY_Q:
959
- case this.S.ATTRIB_VALUE_ENTITY_U:
960
- let returnState;
961
- let buffer;
962
- switch (this.state) {
963
- case this.S.TEXT_ENTITY:
964
- returnState = this.S.TEXT;
965
- buffer = "textNode";
966
- break;
967
- case this.S.ATTRIB_VALUE_ENTITY_Q:
968
- returnState = this.S.ATTRIB_VALUE_QUOTED;
969
- buffer = "attribValue";
970
- break;
971
- case this.S.ATTRIB_VALUE_ENTITY_U:
972
- returnState = this.S.ATTRIB_VALUE_UNQUOTED;
973
- buffer = "attribValue";
974
- break;
975
- default:
976
- throw new Error(`Unknown state: ${this.state}`);
977
- }
978
- if (c === ";") {
979
- this[buffer] += this.parseEntity();
980
- this.entity = "";
981
- this.state = returnState;
982
- } else if (SAX.isMatch(this.entity.length ? entityBody : entityStart, c)) {
983
- this.entity += c;
984
- } else {
985
- this.strictFail("Invalid character in entity name");
986
- this[buffer] += `&${this.entity}${c}`;
987
- this.entity = "";
988
- this.state = returnState;
989
- }
990
- continue;
991
- default:
992
- throw new Error(`Unknown state: ${this.state}`);
993
- }
994
- }
995
- if (this.position >= this.bufferCheckPosition) {
996
- this.checkBufferLength();
997
- }
998
- return this;
999
- }
1000
- emit(event, data) {
1001
- if (this.events.hasOwnProperty(event)) {
1002
- const eventName = event.replace(/^on/, "");
1003
- this.events[event](data, eventName, this);
1004
- }
1005
- }
1006
- clearBuffers() {
1007
- for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
1008
- this[this[i]] = "";
1009
- }
1010
- }
1011
- flushBuffers() {
1012
- this.closeText();
1013
- if (this.cdata !== "") {
1014
- this.emitNode("oncdata", this.cdata);
1015
- this.cdata = "";
1016
- }
1017
- if (this.script !== "") {
1018
- this.emitNode("onscript", this.script);
1019
- this.script = "";
1020
- }
1021
- }
1022
- end() {
1023
- if (this.sawRoot && !this.closedRoot)
1024
- this.strictFail("Unclosed root tag");
1025
- if (this.state !== this.S.BEGIN && this.state !== this.S.BEGIN_WHITESPACE && this.state !== this.S.TEXT) {
1026
- this.errorFunction("Unexpected end");
1027
- }
1028
- this.closeText();
1029
- this.c = "";
1030
- this.closed = true;
1031
- this.emit("onend");
1032
- return new SAXParser(this.opt);
1033
- }
1034
- errorFunction(er) {
1035
- this.closeText();
1036
- if (this.trackPosition) {
1037
- er += `
1038
- Line: ${this.line}
1039
- Column: ${this.column}
1040
- Char: ${this.c}`;
1041
- }
1042
- const error = new Error(er);
1043
- this.error = error;
1044
- this.emit("onerror", error);
1045
- return this;
1046
- }
1047
- attrib() {
1048
- if (!this.strict) {
1049
- this.attribName = this.attribName[this.looseCase]();
1050
- }
1051
- if (this.attribList.indexOf(this.attribName) !== -1 || this.tag.attributes.hasOwnProperty(this.attribName)) {
1052
- this.attribName = this.attribValue = "";
1053
- return;
1054
- }
1055
- if (this.opt.xmlns) {
1056
- const qn = SAX.qname(this.attribName, true);
1057
- const prefix = qn.prefix;
1058
- const local = qn.local;
1059
- if (prefix === "xmlns") {
1060
- if (local === "xml" && this.attribValue !== this.XML_NAMESPACE) {
1061
- this.strictFail(`xml: prefix must be bound to ${this.XML_NAMESPACE}
1062
- Actual: ${this.attribValue}`);
1063
- } else if (local === "xmlns" && this.attribValue !== this.XMLNS_NAMESPACE) {
1064
- this.strictFail(`xmlns: prefix must be bound to ${this.XMLNS_NAMESPACE}
1065
- Actual: ${this.attribValue}`);
1066
- } else {
1067
- const tag = this.tag;
1068
- const parent = this.tags[this.tags.length - 1] || this;
1069
- if (tag.ns === parent.ns) {
1070
- tag.ns = Object.create(parent.ns);
1071
- }
1072
- tag.ns[local] = this.attribValue;
227
+ }
228
+ if (xmlData[i] === "<") {
229
+ i--;
1073
230
  }
1074
231
  }
1075
- this.attribList.push([this.attribName, this.attribValue]);
1076
232
  } else {
1077
- this.tag.attributes[this.attribName] = this.attribValue;
1078
- this.emitNode("onattribute", {
1079
- name: this.attribName,
1080
- value: this.attribValue
1081
- });
1082
- }
1083
- this.attribName = this.attribValue = "";
1084
- }
1085
- newTag() {
1086
- if (!this.strict)
1087
- this.tagName = this.tagName[this.looseCase]();
1088
- const parent = this.tags[this.tags.length - 1] || this;
1089
- const tag = this.tag = { name: this.tagName, attributes: {} };
1090
- if (this.opt.xmlns) {
1091
- tag.ns = parent.ns;
1092
- }
1093
- this.attribList.length = 0;
1094
- this.emitNode("onopentagstart", tag);
1095
- }
1096
- parseEntity() {
1097
- let entity = this.entity;
1098
- const entityLC = entity.toLowerCase();
1099
- let num = NaN;
1100
- let numStr = "";
1101
- if (this.ENTITIES[entity]) {
1102
- return this.ENTITIES[entity];
1103
- }
1104
- if (this.ENTITIES[entityLC]) {
1105
- return this.ENTITIES[entityLC];
1106
- }
1107
- entity = entityLC;
1108
- if (entity.charAt(0) === "#") {
1109
- if (entity.charAt(1) === "x") {
1110
- entity = entity.slice(2);
1111
- num = parseInt(entity, 16);
1112
- numStr = num.toString(16);
1113
- } else {
1114
- entity = entity.slice(1);
1115
- num = parseInt(entity, 10);
1116
- numStr = num.toString(10);
233
+ if (isWhiteSpace(xmlData[i])) {
234
+ continue;
1117
235
  }
1118
- }
1119
- entity = entity.replace(/^0+/, "");
1120
- if (isNaN(num) || numStr.toLowerCase() !== entity) {
1121
- this.strictFail("Invalid character entity");
1122
- return `&${this.entity};`;
1123
- }
1124
- return String.fromCodePoint(num);
1125
- }
1126
- beginWhiteSpace(c) {
1127
- if (c === "<") {
1128
- this.state = this.S.OPEN_WAKA;
1129
- this.startTagPosition = this.position;
1130
- } else if (!SAX.isWhitespace(c)) {
1131
- this.strictFail("Non-whitespace before first tag.");
1132
- this.textNode = c;
1133
- this.state = this.S.TEXT;
1134
- } else {
236
+ return getErrorObject("InvalidChar", "char '" + xmlData[i] + "' is not expected.", getLineNumberForPosition(xmlData, i));
1135
237
  }
1136
238
  }
1137
- strictFail(message) {
1138
- if (typeof this !== "object" || !(this instanceof SAXParser)) {
1139
- throw new Error("bad call to strictFail");
1140
- }
1141
- if (this.strict) {
1142
- this.errorFunction(message);
1143
- }
239
+ if (!tagFound) {
240
+ return getErrorObject("InvalidXml", "Start tag expected.", 1);
241
+ } else if (tags.length == 1) {
242
+ return getErrorObject("InvalidTag", "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
243
+ } else if (tags.length > 0) {
244
+ return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t) => t.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", {
245
+ line: 1,
246
+ col: 1
247
+ });
1144
248
  }
1145
- textApplyOptions(text) {
1146
- if (this.opt.trim)
1147
- text = text.trim();
1148
- if (this.opt.normalize)
1149
- text = text.replace(/\s+/g, " ");
1150
- return text;
1151
- }
1152
- emitNode(nodeType, data) {
1153
- if (this.textNode)
1154
- this.closeText();
1155
- this.emit(nodeType, data);
1156
- }
1157
- closeText() {
1158
- this.textNode = this.textApplyOptions(this.textNode);
1159
- if (this.textNode !== void 0 && this.textNode !== "" && this.textNode !== "undefined") {
1160
- this.emit("ontext", this.textNode);
1161
- }
1162
- this.textNode = "";
1163
- }
1164
- checkBufferLength() {
1165
- const maxAllowed = Math.max(this.opt.MAX_BUFFER_LENGTH, 10);
1166
- let maxActual = 0;
1167
- for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
1168
- const len = this[this.BUFFERS[i]]?.length || 0;
1169
- if (len > maxAllowed) {
1170
- switch (this.BUFFERS[i]) {
1171
- case "textNode":
1172
- this.closeText();
1173
- break;
1174
- case "cdata":
1175
- this.emitNode("oncdata", this.cdata);
1176
- this.cdata = "";
1177
- break;
1178
- case "script":
1179
- this.emitNode("onscript", this.script);
1180
- this.script = "";
1181
- break;
1182
- default:
1183
- this.errorFunction(`Max buffer length exceeded: ${this.BUFFERS[i]}`);
1184
- }
249
+ return true;
250
+ };
251
+ function isWhiteSpace(char) {
252
+ return char === " " || char === " " || char === "\n" || char === "\r";
253
+ }
254
+ function readPI(xmlData, i) {
255
+ const start = i;
256
+ for (; i < xmlData.length; i++) {
257
+ if (xmlData[i] == "?" || xmlData[i] == " ") {
258
+ const tagname = xmlData.substr(start, i - start);
259
+ if (i > 5 && tagname === "xml") {
260
+ return getErrorObject("InvalidXml", "XML declaration allowed only at the start of the document.", getLineNumberForPosition(xmlData, i));
261
+ } else if (xmlData[i] == "?" && xmlData[i + 1] == ">") {
262
+ i++;
263
+ break;
264
+ } else {
265
+ continue;
1185
266
  }
1186
- maxActual = Math.max(maxActual, len);
1187
267
  }
1188
- const m = this.opt.MAX_BUFFER_LENGTH - maxActual;
1189
- this.bufferCheckPosition = m + this.position;
1190
268
  }
1191
- openTag(selfClosing) {
1192
- if (this.opt.xmlns) {
1193
- const tag = this.tag;
1194
- const qn = SAX.qname(this.tagName);
1195
- tag.prefix = qn.prefix;
1196
- tag.local = qn.local;
1197
- tag.uri = tag.ns[qn.prefix] || "";
1198
- if (tag.prefix && !tag.uri) {
1199
- this.strictFail(`Unbound namespace prefix: ${JSON.stringify(this.tagName)}`);
1200
- tag.uri = qn.prefix;
1201
- }
1202
- const parent = this.tags[this.tags.length - 1] || this;
1203
- if (tag.ns && parent.ns !== tag.ns) {
1204
- const that = this;
1205
- Object.keys(tag.ns).forEach((p) => {
1206
- that.emitNode("onopennamespace", {
1207
- prefix: p,
1208
- uri: tag.ns[p]
1209
- });
1210
- });
1211
- }
1212
- for (let i = 0, l = this.attribList.length; i < l; i++) {
1213
- const nv = this.attribList[i];
1214
- const name = nv[0];
1215
- const value = nv[1];
1216
- const qualName = SAX.qname(name, true);
1217
- const prefix = qualName.prefix;
1218
- const local = qualName.local;
1219
- const uri = prefix === "" ? "" : tag.ns[prefix] || "";
1220
- const a = {
1221
- name,
1222
- value,
1223
- prefix,
1224
- local,
1225
- uri
1226
- };
1227
- if (prefix && prefix !== "xmlns" && !uri) {
1228
- this.strictFail(`Unbound namespace prefix: ${JSON.stringify(prefix)}`);
1229
- a.uri = prefix;
1230
- }
1231
- this.tag.attributes[name] = a;
1232
- this.emitNode("onattribute", a);
1233
- }
1234
- this.attribList.length = 0;
1235
- }
1236
- this.tag.isSelfClosing = Boolean(selfClosing);
1237
- this.sawRoot = true;
1238
- this.tags.push(this.tag);
1239
- this.emitNode("onopentag", this.tag);
1240
- if (!selfClosing) {
1241
- if (!this.noscript && this.tagName.toLowerCase() === "script") {
1242
- this.state = this.S.SCRIPT;
1243
- } else {
1244
- this.state = this.S.TEXT;
269
+ return i;
270
+ }
271
+ function readCommentAndCDATA(xmlData, i) {
272
+ if (xmlData.length > i + 5 && xmlData[i + 1] === "-" && xmlData[i + 2] === "-") {
273
+ for (i += 3; i < xmlData.length; i++) {
274
+ if (xmlData[i] === "-" && xmlData[i + 1] === "-" && xmlData[i + 2] === ">") {
275
+ i += 2;
276
+ break;
1245
277
  }
1246
- this.tag = null;
1247
- this.tagName = "";
1248
278
  }
1249
- this.attribName = this.attribValue = "";
1250
- this.attribList.length = 0;
1251
- }
1252
- closeTag() {
1253
- if (!this.tagName) {
1254
- this.strictFail("Weird empty close tag.");
1255
- this.textNode += "</>";
1256
- this.state = this.S.TEXT;
1257
- return;
1258
- }
1259
- if (this.script) {
1260
- if (this.tagName !== "script") {
1261
- this.script += `</${this.tagName}>`;
1262
- this.tagName = "";
1263
- this.state = this.S.SCRIPT;
1264
- return;
279
+ } else if (xmlData.length > i + 8 && xmlData[i + 1] === "D" && xmlData[i + 2] === "O" && xmlData[i + 3] === "C" && xmlData[i + 4] === "T" && xmlData[i + 5] === "Y" && xmlData[i + 6] === "P" && xmlData[i + 7] === "E") {
280
+ let angleBracketsCount = 1;
281
+ for (i += 8; i < xmlData.length; i++) {
282
+ if (xmlData[i] === "<") {
283
+ angleBracketsCount++;
284
+ } else if (xmlData[i] === ">") {
285
+ angleBracketsCount--;
286
+ if (angleBracketsCount === 0) {
287
+ break;
288
+ }
1265
289
  }
1266
- this.emitNode("onscript", this.script);
1267
- this.script = "";
1268
290
  }
1269
- let t = this.tags.length;
1270
- let tagName = this.tagName;
1271
- if (!this.strict) {
1272
- tagName = tagName[this.looseCase]();
1273
- }
1274
- while (t--) {
1275
- const close = this.tags[t];
1276
- if (close.name !== tagName) {
1277
- this.strictFail("Unexpected close tag");
1278
- } else {
291
+ } else if (xmlData.length > i + 9 && xmlData[i + 1] === "[" && xmlData[i + 2] === "C" && xmlData[i + 3] === "D" && xmlData[i + 4] === "A" && xmlData[i + 5] === "T" && xmlData[i + 6] === "A" && xmlData[i + 7] === "[") {
292
+ for (i += 8; i < xmlData.length; i++) {
293
+ if (xmlData[i] === "]" && xmlData[i + 1] === "]" && xmlData[i + 2] === ">") {
294
+ i += 2;
1279
295
  break;
1280
296
  }
1281
297
  }
1282
- if (t < 0) {
1283
- this.strictFail(`Unmatched closing tag: ${this.tagName}`);
1284
- this.textNode += `</${this.tagName}>`;
1285
- this.state = this.S.TEXT;
1286
- return;
1287
- }
1288
- this.tagName = tagName;
1289
- let s = this.tags.length;
1290
- while (s-- > t) {
1291
- const tag = this.tag = this.tags.pop();
1292
- this.tagName = this.tag.name;
1293
- this.emitNode("onclosetag", this.tagName);
1294
- const x = {};
1295
- for (const i in tag.ns) {
1296
- if (tag.ns.hasOwnProperty(i)) {
1297
- x[i] = tag.ns[i];
1298
- }
298
+ }
299
+ return i;
300
+ }
301
+ var doubleQuote = '"';
302
+ var singleQuote = "'";
303
+ function readAttributeStr(xmlData, i) {
304
+ let attrStr = "";
305
+ let startChar = "";
306
+ let tagClosed = false;
307
+ for (; i < xmlData.length; i++) {
308
+ if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) {
309
+ if (startChar === "") {
310
+ startChar = xmlData[i];
311
+ } else if (startChar !== xmlData[i]) {
312
+ } else {
313
+ startChar = "";
1299
314
  }
1300
- const parent = this.tags[this.tags.length - 1] || this;
1301
- if (this.opt.xmlns && tag.ns !== parent.ns) {
1302
- const that = this;
1303
- Object.keys(tag.ns).forEach((p) => {
1304
- const n = tag.ns[p];
1305
- that.emitNode("onclosenamespace", { prefix: p, uri: n });
1306
- });
315
+ } else if (xmlData[i] === ">") {
316
+ if (startChar === "") {
317
+ tagClosed = true;
318
+ break;
1307
319
  }
1308
320
  }
1309
- if (t === 0)
1310
- this.closedRoot = true;
1311
- this.tagName = this.attribValue = this.attribName = "";
1312
- this.attribList.length = 0;
1313
- this.state = this.S.TEXT;
321
+ attrStr += xmlData[i];
1314
322
  }
1315
- };
1316
- SAXParser = class extends SAX {
1317
- constructor(opt) {
1318
- super();
1319
- this.opt = DEFAULT_SAX_PARSER_OPTIONS;
1320
- this.events = DEFAULT_SAX_EVENTS;
1321
- this.clearBuffers();
1322
- this.opt = opt = { ...this.opt, ...opt };
1323
- this.events = { ...this.events, ...opt };
1324
- this.q = this.c = "";
1325
- this.opt.lowercase = this.opt.lowercase || this.opt.lowercasetags;
1326
- this.bufferCheckPosition = this.opt.MAX_BUFFER_LENGTH;
1327
- this.looseCase = this.opt.lowercase ? "toLowerCase" : "toUpperCase";
1328
- this.tags = [];
1329
- this.closed = this.closedRoot = this.sawRoot = false;
1330
- this.tag = this.error = null;
1331
- this.strict = Boolean(this.opt.strict);
1332
- this.noscript = Boolean(this.opt.strict || this.opt.noscript);
1333
- this.state = this.S.BEGIN;
1334
- this.strictEntities = this.opt.strictEntities;
1335
- this.ENTITIES = this.strictEntities ? Object.create(this.XML_ENTITIES) : Object.create(this.ENTITIES);
1336
- this.attribList = [];
1337
- if (this.opt.xmlns) {
1338
- this.ns = Object.create(this.rootNS);
323
+ if (startChar !== "") {
324
+ return false;
325
+ }
326
+ return {
327
+ value: attrStr,
328
+ index: i,
329
+ tagClosed
330
+ };
331
+ }
332
+ var validAttrStrRegxp = new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`, "g");
333
+ function validateAttributeString(attrStr, options) {
334
+ const matches = util.getAllMatches(attrStr, validAttrStrRegxp);
335
+ const attrNames = {};
336
+ for (let i = 0; i < matches.length; i++) {
337
+ if (matches[i][1].length === 0) {
338
+ return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' has no space in starting.", getPositionFromMatch(matches[i]));
339
+ } else if (matches[i][3] !== void 0 && matches[i][4] === void 0) {
340
+ return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' is without value.", getPositionFromMatch(matches[i]));
341
+ } else if (matches[i][3] === void 0 && !options.allowBooleanAttributes) {
342
+ return getErrorObject("InvalidAttr", "boolean attribute '" + matches[i][2] + "' is not allowed.", getPositionFromMatch(matches[i]));
1339
343
  }
1340
- this.trackPosition = this.opt.position !== false;
1341
- if (this.trackPosition) {
1342
- this.position = this.line = this.column = 0;
344
+ const attrName = matches[i][2];
345
+ if (!validateAttrName(attrName)) {
346
+ return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i]));
347
+ }
348
+ if (!attrNames.hasOwnProperty(attrName)) {
349
+ attrNames[attrName] = 1;
350
+ } else {
351
+ return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i]));
1343
352
  }
1344
- this.emit("onready");
1345
353
  }
1346
- resume() {
1347
- this.error = null;
1348
- return this;
354
+ return true;
355
+ }
356
+ function validateNumberAmpersand(xmlData, i) {
357
+ let re = /\d/;
358
+ if (xmlData[i] === "x") {
359
+ i++;
360
+ re = /[\da-fA-F]/;
361
+ }
362
+ for (; i < xmlData.length; i++) {
363
+ if (xmlData[i] === ";")
364
+ return i;
365
+ if (!xmlData[i].match(re))
366
+ break;
1349
367
  }
1350
- close() {
1351
- return this.write(null);
368
+ return -1;
369
+ }
370
+ function validateAmpersand(xmlData, i) {
371
+ i++;
372
+ if (xmlData[i] === ";")
373
+ return -1;
374
+ if (xmlData[i] === "#") {
375
+ i++;
376
+ return validateNumberAmpersand(xmlData, i);
1352
377
  }
1353
- flush() {
1354
- this.flushBuffers();
378
+ let count = 0;
379
+ for (; i < xmlData.length; i++, count++) {
380
+ if (xmlData[i].match(/\w/) && count < 20)
381
+ continue;
382
+ if (xmlData[i] === ";")
383
+ break;
384
+ return -1;
1355
385
  }
1356
- };
1357
- SAXParser.ENTITIES = ENTITIES;
1358
- }
1359
- });
1360
-
1361
- // src/lib/xml-utils/uncapitalize.ts
1362
- function uncapitalize(str) {
1363
- return typeof str === "string" ? str.charAt(0).toLowerCase() + str.slice(1) : str;
1364
- }
1365
- function uncapitalizeKeys(object) {
1366
- if (Array.isArray(object)) {
1367
- return object.map((element) => uncapitalizeKeys(element));
1368
- }
1369
- if (object && typeof object === "object") {
1370
- const newObject = {};
1371
- for (const [key, value] of Object.entries(object)) {
1372
- newObject[uncapitalize(key)] = uncapitalizeKeys(value);
386
+ return i;
387
+ }
388
+ function getErrorObject(code, message, lineNumber) {
389
+ return {
390
+ err: {
391
+ code,
392
+ msg: message,
393
+ line: lineNumber.line || lineNumber,
394
+ col: lineNumber.col
395
+ }
396
+ };
397
+ }
398
+ function validateAttrName(attrName) {
399
+ return util.isName(attrName);
400
+ }
401
+ function validateTagName(tagname) {
402
+ return util.isName(tagname);
403
+ }
404
+ function getLineNumberForPosition(xmlData, index) {
405
+ const lines = xmlData.substring(0, index).split(/\r?\n/);
406
+ return {
407
+ line: lines.length,
408
+ // column number is last line's length + 1, because column numbering starts at 1:
409
+ col: lines[lines.length - 1].length + 1
410
+ };
411
+ }
412
+ function getPositionFromMatch(match) {
413
+ return match.startIndex + match[1].length;
1373
414
  }
1374
- return newObject;
1375
- }
1376
- return object;
1377
- }
1378
- var init_uncapitalize = __esm({
1379
- "src/lib/xml-utils/uncapitalize.ts"() {
1380
415
  }
1381
416
  });
1382
417
 
1383
- // ../../node_modules/fast-xml-parser/src/util.js
1384
- var require_util = __commonJS({
1385
- "../../node_modules/fast-xml-parser/src/util.js"(exports) {
1386
- "use strict";
1387
- var nameStartChar = ":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";
1388
- var nameChar = nameStartChar + "\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
1389
- var nameRegexp = "[" + nameStartChar + "][" + nameChar + "]*";
1390
- var regexName = new RegExp("^" + nameRegexp + "$");
1391
- var getAllMatches = function(string, regex) {
1392
- const matches = [];
1393
- let match = regex.exec(string);
1394
- while (match) {
1395
- const allmatches = [];
1396
- allmatches.startIndex = regex.lastIndex - match[0].length;
1397
- const len = match.length;
1398
- for (let index = 0; index < len; index++) {
1399
- allmatches.push(match[index]);
1400
- }
1401
- matches.push(allmatches);
1402
- match = regex.exec(string);
418
+ // ../../node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js
419
+ var require_OptionsBuilder = __commonJS({
420
+ "../../node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js"(exports) {
421
+ var defaultOptions = {
422
+ preserveOrder: false,
423
+ attributeNamePrefix: "@_",
424
+ attributesGroupName: false,
425
+ textNodeName: "#text",
426
+ ignoreAttributes: true,
427
+ removeNSPrefix: false,
428
+ // remove NS from tag name or attribute name if true
429
+ allowBooleanAttributes: false,
430
+ //a tag can have attributes without any value
431
+ //ignoreRootElement : false,
432
+ parseTagValue: true,
433
+ parseAttributeValue: false,
434
+ trimValues: true,
435
+ //Trim string values of tag and attributes
436
+ cdataPropName: false,
437
+ numberParseOptions: {
438
+ hex: true,
439
+ leadingZeros: true,
440
+ eNotation: true
441
+ },
442
+ tagValueProcessor: function(tagName, val2) {
443
+ return val2;
444
+ },
445
+ attributeValueProcessor: function(attrName, val2) {
446
+ return val2;
447
+ },
448
+ stopNodes: [],
449
+ //nested tags will not be parsed even for errors
450
+ alwaysCreateTextNode: false,
451
+ isArray: () => false,
452
+ commentPropName: false,
453
+ unpairedTags: [],
454
+ processEntities: true,
455
+ htmlEntities: false,
456
+ ignoreDeclaration: false,
457
+ ignorePiTags: false,
458
+ transformTagName: false,
459
+ transformAttributeName: false,
460
+ updateTag: function(tagName, jPath, attrs) {
461
+ return tagName;
1403
462
  }
1404
- return matches;
463
+ // skipEmptyListItem: false
1405
464
  };
1406
- var isName = function(string) {
1407
- const match = regexName.exec(string);
1408
- return !(match === null || typeof match === "undefined");
1409
- };
1410
- exports.isExist = function(v) {
1411
- return typeof v !== "undefined";
1412
- };
1413
- exports.isEmptyObject = function(obj) {
1414
- return Object.keys(obj).length === 0;
465
+ var buildOptions = function(options) {
466
+ return Object.assign({}, defaultOptions, options);
1415
467
  };
1416
- exports.merge = function(target, a, arrayMode) {
1417
- if (a) {
1418
- const keys = Object.keys(a);
1419
- const len = keys.length;
1420
- for (let i = 0; i < len; i++) {
1421
- if (arrayMode === "strict") {
1422
- target[keys[i]] = [a[keys[i]]];
1423
- } else {
1424
- target[keys[i]] = a[keys[i]];
1425
- }
1426
- }
468
+ exports.buildOptions = buildOptions;
469
+ exports.defaultOptions = defaultOptions;
470
+ }
471
+ });
472
+
473
+ // ../../node_modules/fast-xml-parser/src/xmlparser/xmlNode.js
474
+ var require_xmlNode = __commonJS({
475
+ "../../node_modules/fast-xml-parser/src/xmlparser/xmlNode.js"(exports, module) {
476
+ "use strict";
477
+ var XmlNode = class {
478
+ constructor(tagname) {
479
+ this.tagname = tagname;
480
+ this.child = [];
481
+ this[":@"] = {};
1427
482
  }
1428
- };
1429
- exports.getValue = function(v) {
1430
- if (exports.isExist(v)) {
1431
- return v;
1432
- } else {
1433
- return "";
483
+ add(key, val2) {
484
+ if (key === "__proto__")
485
+ key = "#__proto__";
486
+ this.child.push({
487
+ [key]: val2
488
+ });
489
+ }
490
+ addChild(node) {
491
+ if (node.tagname === "__proto__")
492
+ node.tagname = "#__proto__";
493
+ if (node[":@"] && Object.keys(node[":@"]).length > 0) {
494
+ this.child.push({
495
+ [node.tagname]: node.child,
496
+ [":@"]: node[":@"]
497
+ });
498
+ } else {
499
+ this.child.push({
500
+ [node.tagname]: node.child
501
+ });
502
+ }
1434
503
  }
1435
504
  };
1436
- exports.isName = isName;
1437
- exports.getAllMatches = getAllMatches;
1438
- exports.nameRegexp = nameRegexp;
505
+ module.exports = XmlNode;
1439
506
  }
1440
507
  });
1441
508
 
1442
- // ../../node_modules/fast-xml-parser/src/validator.js
1443
- var require_validator = __commonJS({
1444
- "../../node_modules/fast-xml-parser/src/validator.js"(exports) {
1445
- "use strict";
509
+ // ../../node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js
510
+ var require_DocTypeReader = __commonJS({
511
+ "../../node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js"(exports, module) {
1446
512
  var util = require_util();
1447
- var defaultOptions = {
1448
- allowBooleanAttributes: false,
1449
- unpairedTags: []
1450
- };
1451
- exports.validate = function(xmlData, options) {
1452
- options = Object.assign({}, defaultOptions, options);
1453
- const tags = [];
1454
- let tagFound = false;
1455
- let reachedRoot = false;
1456
- if (xmlData[0] === "\uFEFF") {
1457
- xmlData = xmlData.substr(1);
1458
- }
1459
- for (let i = 0; i < xmlData.length; i++) {
1460
- if (xmlData[i] === "<" && xmlData[i + 1] === "?") {
1461
- i += 2;
1462
- i = readPI(xmlData, i);
1463
- if (i.err)
1464
- return i;
1465
- } else if (xmlData[i] === "<") {
1466
- let tagStartPos = i;
1467
- i++;
1468
- if (xmlData[i] === "!") {
1469
- i = readCommentAndCDATA(xmlData, i);
1470
- continue;
1471
- } else {
1472
- let closingTag = false;
1473
- if (xmlData[i] === "/") {
1474
- closingTag = true;
1475
- i++;
1476
- }
1477
- let tagName = "";
1478
- for (; i < xmlData.length && xmlData[i] !== ">" && xmlData[i] !== " " && xmlData[i] !== " " && xmlData[i] !== "\n" && xmlData[i] !== "\r"; i++) {
1479
- tagName += xmlData[i];
1480
- }
1481
- tagName = tagName.trim();
1482
- if (tagName[tagName.length - 1] === "/") {
1483
- tagName = tagName.substring(0, tagName.length - 1);
1484
- i--;
1485
- }
1486
- if (!validateTagName(tagName)) {
1487
- let msg;
1488
- if (tagName.trim().length === 0) {
1489
- msg = "Invalid space after '<'.";
1490
- } else {
1491
- msg = "Tag '" + tagName + "' is an invalid name.";
513
+ function readDocType(xmlData, i) {
514
+ const entities = {};
515
+ if (xmlData[i + 3] === "O" && xmlData[i + 4] === "C" && xmlData[i + 5] === "T" && xmlData[i + 6] === "Y" && xmlData[i + 7] === "P" && xmlData[i + 8] === "E") {
516
+ i = i + 9;
517
+ let angleBracketsCount = 1;
518
+ let hasBody = false, comment = false;
519
+ let exp = "";
520
+ for (; i < xmlData.length; i++) {
521
+ if (xmlData[i] === "<" && !comment) {
522
+ if (hasBody && isEntity(xmlData, i)) {
523
+ i += 7;
524
+ [entityName, val, i] = readEntityExp(xmlData, i + 1);
525
+ if (val.indexOf("&") === -1)
526
+ entities[validateEntityName(entityName)] = {
527
+ regx: RegExp(`&${entityName};`, "g"),
528
+ val
529
+ };
530
+ } else if (hasBody && isElement(xmlData, i))
531
+ i += 8;
532
+ else if (hasBody && isAttlist(xmlData, i))
533
+ i += 8;
534
+ else if (hasBody && isNotation(xmlData, i))
535
+ i += 9;
536
+ else if (isComment)
537
+ comment = true;
538
+ else
539
+ throw new Error("Invalid DOCTYPE");
540
+ angleBracketsCount++;
541
+ exp = "";
542
+ } else if (xmlData[i] === ">") {
543
+ if (comment) {
544
+ if (xmlData[i - 1] === "-" && xmlData[i - 2] === "-") {
545
+ comment = false;
546
+ angleBracketsCount--;
1492
547
  }
1493
- return getErrorObject("InvalidTag", msg, getLineNumberForPosition(xmlData, i));
548
+ } else {
549
+ angleBracketsCount--;
1494
550
  }
1495
- const result = readAttributeStr(xmlData, i);
1496
- if (result === false) {
1497
- return getErrorObject("InvalidAttr", "Attributes for '" + tagName + "' have open quote.", getLineNumberForPosition(xmlData, i));
551
+ if (angleBracketsCount === 0) {
552
+ break;
1498
553
  }
1499
- let attrStr = result.value;
1500
- i = result.index;
1501
- if (attrStr[attrStr.length - 1] === "/") {
1502
- const attrStrStart = i - attrStr.length;
1503
- attrStr = attrStr.substring(0, attrStr.length - 1);
1504
- const isValid = validateAttributeString(attrStr, options);
1505
- if (isValid === true) {
1506
- tagFound = true;
1507
- } else {
1508
- return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line));
1509
- }
1510
- } else if (closingTag) {
1511
- if (!result.tagClosed) {
1512
- return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
1513
- } else if (attrStr.trim().length > 0) {
1514
- return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
1515
- } else {
1516
- const otg = tags.pop();
1517
- if (tagName !== otg.tagName) {
1518
- let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
1519
- return getErrorObject("InvalidTag", "Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.", getLineNumberForPosition(xmlData, tagStartPos));
1520
- }
1521
- if (tags.length == 0) {
1522
- reachedRoot = true;
1523
- }
1524
- }
1525
- } else {
1526
- const isValid = validateAttributeString(attrStr, options);
1527
- if (isValid !== true) {
1528
- return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
1529
- }
1530
- if (reachedRoot === true) {
1531
- return getErrorObject("InvalidXml", "Multiple possible root nodes found.", getLineNumberForPosition(xmlData, i));
1532
- } else if (options.unpairedTags.indexOf(tagName) !== -1) {
1533
- } else {
1534
- tags.push({ tagName, tagStartPos });
1535
- }
1536
- tagFound = true;
1537
- }
1538
- for (i++; i < xmlData.length; i++) {
1539
- if (xmlData[i] === "<") {
1540
- if (xmlData[i + 1] === "!") {
1541
- i++;
1542
- i = readCommentAndCDATA(xmlData, i);
1543
- continue;
1544
- } else if (xmlData[i + 1] === "?") {
1545
- i = readPI(xmlData, ++i);
1546
- if (i.err)
1547
- return i;
1548
- } else {
1549
- break;
1550
- }
1551
- } else if (xmlData[i] === "&") {
1552
- const afterAmp = validateAmpersand(xmlData, i);
1553
- if (afterAmp == -1)
1554
- return getErrorObject("InvalidChar", "char '&' is not expected.", getLineNumberForPosition(xmlData, i));
1555
- i = afterAmp;
1556
- } else {
1557
- if (reachedRoot === true && !isWhiteSpace(xmlData[i])) {
1558
- return getErrorObject("InvalidXml", "Extra text at the end", getLineNumberForPosition(xmlData, i));
1559
- }
1560
- }
1561
- }
1562
- if (xmlData[i] === "<") {
1563
- i--;
1564
- }
1565
- }
1566
- } else {
1567
- if (isWhiteSpace(xmlData[i])) {
1568
- continue;
1569
- }
1570
- return getErrorObject("InvalidChar", "char '" + xmlData[i] + "' is not expected.", getLineNumberForPosition(xmlData, i));
1571
- }
1572
- }
1573
- if (!tagFound) {
1574
- return getErrorObject("InvalidXml", "Start tag expected.", 1);
1575
- } else if (tags.length == 1) {
1576
- return getErrorObject("InvalidTag", "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
1577
- } else if (tags.length > 0) {
1578
- return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t) => t.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", { line: 1, col: 1 });
1579
- }
1580
- return true;
1581
- };
1582
- function isWhiteSpace(char) {
1583
- return char === " " || char === " " || char === "\n" || char === "\r";
1584
- }
1585
- function readPI(xmlData, i) {
1586
- const start = i;
1587
- for (; i < xmlData.length; i++) {
1588
- if (xmlData[i] == "?" || xmlData[i] == " ") {
1589
- const tagname = xmlData.substr(start, i - start);
1590
- if (i > 5 && tagname === "xml") {
1591
- return getErrorObject("InvalidXml", "XML declaration allowed only at the start of the document.", getLineNumberForPosition(xmlData, i));
1592
- } else if (xmlData[i] == "?" && xmlData[i + 1] == ">") {
1593
- i++;
1594
- break;
554
+ } else if (xmlData[i] === "[") {
555
+ hasBody = true;
1595
556
  } else {
1596
- continue;
1597
- }
1598
- }
1599
- }
1600
- return i;
1601
- }
1602
- function readCommentAndCDATA(xmlData, i) {
1603
- if (xmlData.length > i + 5 && xmlData[i + 1] === "-" && xmlData[i + 2] === "-") {
1604
- for (i += 3; i < xmlData.length; i++) {
1605
- if (xmlData[i] === "-" && xmlData[i + 1] === "-" && xmlData[i + 2] === ">") {
1606
- i += 2;
1607
- break;
1608
- }
1609
- }
1610
- } else if (xmlData.length > i + 8 && xmlData[i + 1] === "D" && xmlData[i + 2] === "O" && xmlData[i + 3] === "C" && xmlData[i + 4] === "T" && xmlData[i + 5] === "Y" && xmlData[i + 6] === "P" && xmlData[i + 7] === "E") {
1611
- let angleBracketsCount = 1;
1612
- for (i += 8; i < xmlData.length; i++) {
1613
- if (xmlData[i] === "<") {
1614
- angleBracketsCount++;
1615
- } else if (xmlData[i] === ">") {
1616
- angleBracketsCount--;
1617
- if (angleBracketsCount === 0) {
1618
- break;
1619
- }
1620
- }
1621
- }
1622
- } else if (xmlData.length > i + 9 && xmlData[i + 1] === "[" && xmlData[i + 2] === "C" && xmlData[i + 3] === "D" && xmlData[i + 4] === "A" && xmlData[i + 5] === "T" && xmlData[i + 6] === "A" && xmlData[i + 7] === "[") {
1623
- for (i += 8; i < xmlData.length; i++) {
1624
- if (xmlData[i] === "]" && xmlData[i + 1] === "]" && xmlData[i + 2] === ">") {
1625
- i += 2;
1626
- break;
557
+ exp += xmlData[i];
1627
558
  }
1628
559
  }
1629
- }
1630
- return i;
1631
- }
1632
- var doubleQuote = '"';
1633
- var singleQuote = "'";
1634
- function readAttributeStr(xmlData, i) {
1635
- let attrStr = "";
1636
- let startChar = "";
1637
- let tagClosed = false;
1638
- for (; i < xmlData.length; i++) {
1639
- if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) {
1640
- if (startChar === "") {
1641
- startChar = xmlData[i];
1642
- } else if (startChar !== xmlData[i]) {
1643
- } else {
1644
- startChar = "";
1645
- }
1646
- } else if (xmlData[i] === ">") {
1647
- if (startChar === "") {
1648
- tagClosed = true;
1649
- break;
1650
- }
560
+ if (angleBracketsCount !== 0) {
561
+ throw new Error(`Unclosed DOCTYPE`);
1651
562
  }
1652
- attrStr += xmlData[i];
1653
- }
1654
- if (startChar !== "") {
1655
- return false;
563
+ } else {
564
+ throw new Error(`Invalid Tag instead of DOCTYPE`);
1656
565
  }
1657
566
  return {
1658
- value: attrStr,
1659
- index: i,
1660
- tagClosed
567
+ entities,
568
+ i
1661
569
  };
1662
570
  }
1663
- var validAttrStrRegxp = new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`, "g");
1664
- function validateAttributeString(attrStr, options) {
1665
- const matches = util.getAllMatches(attrStr, validAttrStrRegxp);
1666
- const attrNames = {};
1667
- for (let i = 0; i < matches.length; i++) {
1668
- if (matches[i][1].length === 0) {
1669
- return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' has no space in starting.", getPositionFromMatch(matches[i]));
1670
- } else if (matches[i][3] !== void 0 && matches[i][4] === void 0) {
1671
- return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' is without value.", getPositionFromMatch(matches[i]));
1672
- } else if (matches[i][3] === void 0 && !options.allowBooleanAttributes) {
1673
- return getErrorObject("InvalidAttr", "boolean attribute '" + matches[i][2] + "' is not allowed.", getPositionFromMatch(matches[i]));
1674
- }
1675
- const attrName = matches[i][2];
1676
- if (!validateAttrName(attrName)) {
1677
- return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i]));
1678
- }
1679
- if (!attrNames.hasOwnProperty(attrName)) {
1680
- attrNames[attrName] = 1;
1681
- } else {
1682
- return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i]));
1683
- }
1684
- }
1685
- return true;
1686
- }
1687
- function validateNumberAmpersand(xmlData, i) {
1688
- let re = /\d/;
1689
- if (xmlData[i] === "x") {
1690
- i++;
1691
- re = /[\da-fA-F]/;
571
+ function readEntityExp(xmlData, i) {
572
+ let entityName2 = "";
573
+ for (; i < xmlData.length && xmlData[i] !== "'" && xmlData[i] !== '"'; i++) {
574
+ entityName2 += xmlData[i];
1692
575
  }
1693
- for (; i < xmlData.length; i++) {
1694
- if (xmlData[i] === ";")
1695
- return i;
1696
- if (!xmlData[i].match(re))
1697
- break;
576
+ entityName2 = entityName2.trim();
577
+ if (entityName2.indexOf(" ") !== -1)
578
+ throw new Error("External entites are not supported");
579
+ const startChar = xmlData[i++];
580
+ let val2 = "";
581
+ for (; i < xmlData.length && xmlData[i] !== startChar; i++) {
582
+ val2 += xmlData[i];
1698
583
  }
1699
- return -1;
584
+ return [entityName2, val2, i];
1700
585
  }
1701
- function validateAmpersand(xmlData, i) {
1702
- i++;
1703
- if (xmlData[i] === ";")
1704
- return -1;
1705
- if (xmlData[i] === "#") {
1706
- i++;
1707
- return validateNumberAmpersand(xmlData, i);
1708
- }
1709
- let count = 0;
1710
- for (; i < xmlData.length; i++, count++) {
1711
- if (xmlData[i].match(/\w/) && count < 20)
1712
- continue;
1713
- if (xmlData[i] === ";")
1714
- break;
1715
- return -1;
1716
- }
1717
- return i;
586
+ function isComment(xmlData, i) {
587
+ if (xmlData[i + 1] === "!" && xmlData[i + 2] === "-" && xmlData[i + 3] === "-")
588
+ return true;
589
+ return false;
1718
590
  }
1719
- function getErrorObject(code, message, lineNumber) {
1720
- return {
1721
- err: {
1722
- code,
1723
- msg: message,
1724
- line: lineNumber.line || lineNumber,
1725
- col: lineNumber.col
1726
- }
1727
- };
591
+ function isEntity(xmlData, i) {
592
+ if (xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "N" && xmlData[i + 4] === "T" && xmlData[i + 5] === "I" && xmlData[i + 6] === "T" && xmlData[i + 7] === "Y")
593
+ return true;
594
+ return false;
1728
595
  }
1729
- function validateAttrName(attrName) {
1730
- return util.isName(attrName);
596
+ function isElement(xmlData, i) {
597
+ if (xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "L" && xmlData[i + 4] === "E" && xmlData[i + 5] === "M" && xmlData[i + 6] === "E" && xmlData[i + 7] === "N" && xmlData[i + 8] === "T")
598
+ return true;
599
+ return false;
1731
600
  }
1732
- function validateTagName(tagname) {
1733
- return util.isName(tagname);
601
+ function isAttlist(xmlData, i) {
602
+ if (xmlData[i + 1] === "!" && xmlData[i + 2] === "A" && xmlData[i + 3] === "T" && xmlData[i + 4] === "T" && xmlData[i + 5] === "L" && xmlData[i + 6] === "I" && xmlData[i + 7] === "S" && xmlData[i + 8] === "T")
603
+ return true;
604
+ return false;
1734
605
  }
1735
- function getLineNumberForPosition(xmlData, index) {
1736
- const lines = xmlData.substring(0, index).split(/\r?\n/);
1737
- return {
1738
- line: lines.length,
1739
- col: lines[lines.length - 1].length + 1
1740
- };
606
+ function isNotation(xmlData, i) {
607
+ if (xmlData[i + 1] === "!" && xmlData[i + 2] === "N" && xmlData[i + 3] === "O" && xmlData[i + 4] === "T" && xmlData[i + 5] === "A" && xmlData[i + 6] === "T" && xmlData[i + 7] === "I" && xmlData[i + 8] === "O" && xmlData[i + 9] === "N")
608
+ return true;
609
+ return false;
1741
610
  }
1742
- function getPositionFromMatch(match) {
1743
- return match.startIndex + match[1].length;
611
+ function validateEntityName(name) {
612
+ if (util.isName(name))
613
+ return name;
614
+ else
615
+ throw new Error(`Invalid entity name ${name}`);
1744
616
  }
1745
- }
1746
- });
1747
-
1748
- // ../../node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js
1749
- var require_OptionsBuilder = __commonJS({
1750
- "../../node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js"(exports) {
1751
- var defaultOptions = {
1752
- preserveOrder: false,
1753
- attributeNamePrefix: "@_",
1754
- attributesGroupName: false,
1755
- textNodeName: "#text",
1756
- ignoreAttributes: true,
1757
- removeNSPrefix: false,
1758
- allowBooleanAttributes: false,
1759
- parseTagValue: true,
1760
- parseAttributeValue: false,
1761
- trimValues: true,
1762
- cdataPropName: false,
1763
- numberParseOptions: {
1764
- hex: true,
1765
- leadingZeros: true,
1766
- eNotation: true
1767
- },
1768
- tagValueProcessor: function(tagName, val2) {
1769
- return val2;
1770
- },
1771
- attributeValueProcessor: function(attrName, val2) {
1772
- return val2;
1773
- },
1774
- stopNodes: [],
1775
- alwaysCreateTextNode: false,
1776
- isArray: () => false,
1777
- commentPropName: false,
1778
- unpairedTags: [],
1779
- processEntities: true,
1780
- htmlEntities: false,
1781
- ignoreDeclaration: false,
1782
- ignorePiTags: false,
1783
- transformTagName: false,
1784
- transformAttributeName: false,
1785
- updateTag: function(tagName, jPath, attrs) {
1786
- return tagName;
1787
- }
1788
- };
1789
- var buildOptions = function(options) {
1790
- return Object.assign({}, defaultOptions, options);
1791
- };
1792
- exports.buildOptions = buildOptions;
1793
- exports.defaultOptions = defaultOptions;
1794
- }
1795
- });
1796
-
1797
- // ../../node_modules/fast-xml-parser/src/xmlparser/xmlNode.js
1798
- var require_xmlNode = __commonJS({
1799
- "../../node_modules/fast-xml-parser/src/xmlparser/xmlNode.js"(exports, module) {
1800
- "use strict";
1801
- var XmlNode = class {
1802
- constructor(tagname) {
1803
- this.tagname = tagname;
1804
- this.child = [];
1805
- this[":@"] = {};
1806
- }
1807
- add(key, val2) {
1808
- if (key === "__proto__")
1809
- key = "#__proto__";
1810
- this.child.push({ [key]: val2 });
1811
- }
1812
- addChild(node) {
1813
- if (node.tagname === "__proto__")
1814
- node.tagname = "#__proto__";
1815
- if (node[":@"] && Object.keys(node[":@"]).length > 0) {
1816
- this.child.push({ [node.tagname]: node.child, [":@"]: node[":@"] });
1817
- } else {
1818
- this.child.push({ [node.tagname]: node.child });
1819
- }
1820
- }
1821
- };
1822
- module.exports = XmlNode;
1823
- }
1824
- });
1825
-
1826
- // ../../node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js
1827
- var require_DocTypeReader = __commonJS({
1828
- "../../node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js"(exports, module) {
1829
- var util = require_util();
1830
- function readDocType(xmlData, i) {
1831
- const entities = {};
1832
- if (xmlData[i + 3] === "O" && xmlData[i + 4] === "C" && xmlData[i + 5] === "T" && xmlData[i + 6] === "Y" && xmlData[i + 7] === "P" && xmlData[i + 8] === "E") {
1833
- i = i + 9;
1834
- let angleBracketsCount = 1;
1835
- let hasBody = false, comment = false;
1836
- let exp = "";
1837
- for (; i < xmlData.length; i++) {
1838
- if (xmlData[i] === "<" && !comment) {
1839
- if (hasBody && isEntity(xmlData, i)) {
1840
- i += 7;
1841
- [entityName, val, i] = readEntityExp(xmlData, i + 1);
1842
- if (val.indexOf("&") === -1)
1843
- entities[validateEntityName(entityName)] = {
1844
- regx: RegExp(`&${entityName};`, "g"),
1845
- val
1846
- };
1847
- } else if (hasBody && isElement(xmlData, i))
1848
- i += 8;
1849
- else if (hasBody && isAttlist(xmlData, i))
1850
- i += 8;
1851
- else if (hasBody && isNotation(xmlData, i))
1852
- i += 9;
1853
- else if (isComment)
1854
- comment = true;
1855
- else
1856
- throw new Error("Invalid DOCTYPE");
1857
- angleBracketsCount++;
1858
- exp = "";
1859
- } else if (xmlData[i] === ">") {
1860
- if (comment) {
1861
- if (xmlData[i - 1] === "-" && xmlData[i - 2] === "-") {
1862
- comment = false;
1863
- angleBracketsCount--;
1864
- }
1865
- } else {
1866
- angleBracketsCount--;
1867
- }
1868
- if (angleBracketsCount === 0) {
1869
- break;
1870
- }
1871
- } else if (xmlData[i] === "[") {
1872
- hasBody = true;
1873
- } else {
1874
- exp += xmlData[i];
1875
- }
1876
- }
1877
- if (angleBracketsCount !== 0) {
1878
- throw new Error(`Unclosed DOCTYPE`);
1879
- }
1880
- } else {
1881
- throw new Error(`Invalid Tag instead of DOCTYPE`);
1882
- }
1883
- return { entities, i };
1884
- }
1885
- function readEntityExp(xmlData, i) {
1886
- let entityName2 = "";
1887
- for (; i < xmlData.length && (xmlData[i] !== "'" && xmlData[i] !== '"'); i++) {
1888
- entityName2 += xmlData[i];
1889
- }
1890
- entityName2 = entityName2.trim();
1891
- if (entityName2.indexOf(" ") !== -1)
1892
- throw new Error("External entites are not supported");
1893
- const startChar = xmlData[i++];
1894
- let val2 = "";
1895
- for (; i < xmlData.length && xmlData[i] !== startChar; i++) {
1896
- val2 += xmlData[i];
1897
- }
1898
- return [entityName2, val2, i];
1899
- }
1900
- function isComment(xmlData, i) {
1901
- if (xmlData[i + 1] === "!" && xmlData[i + 2] === "-" && xmlData[i + 3] === "-")
1902
- return true;
1903
- return false;
1904
- }
1905
- function isEntity(xmlData, i) {
1906
- if (xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "N" && xmlData[i + 4] === "T" && xmlData[i + 5] === "I" && xmlData[i + 6] === "T" && xmlData[i + 7] === "Y")
1907
- return true;
1908
- return false;
1909
- }
1910
- function isElement(xmlData, i) {
1911
- if (xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "L" && xmlData[i + 4] === "E" && xmlData[i + 5] === "M" && xmlData[i + 6] === "E" && xmlData[i + 7] === "N" && xmlData[i + 8] === "T")
1912
- return true;
1913
- return false;
1914
- }
1915
- function isAttlist(xmlData, i) {
1916
- if (xmlData[i + 1] === "!" && xmlData[i + 2] === "A" && xmlData[i + 3] === "T" && xmlData[i + 4] === "T" && xmlData[i + 5] === "L" && xmlData[i + 6] === "I" && xmlData[i + 7] === "S" && xmlData[i + 8] === "T")
1917
- return true;
1918
- return false;
1919
- }
1920
- function isNotation(xmlData, i) {
1921
- if (xmlData[i + 1] === "!" && xmlData[i + 2] === "N" && xmlData[i + 3] === "O" && xmlData[i + 4] === "T" && xmlData[i + 5] === "A" && xmlData[i + 6] === "T" && xmlData[i + 7] === "I" && xmlData[i + 8] === "O" && xmlData[i + 9] === "N")
1922
- return true;
1923
- return false;
1924
- }
1925
- function validateEntityName(name) {
1926
- if (util.isName(name))
1927
- return name;
1928
- else
1929
- throw new Error(`Invalid entity name ${name}`);
1930
- }
1931
- module.exports = readDocType;
617
+ module.exports = readDocType;
1932
618
  }
1933
619
  });
1934
620
 
@@ -1948,6 +634,7 @@ Actual: ${this.attribValue}`);
1948
634
  leadingZeros: true,
1949
635
  decimalPoint: ".",
1950
636
  eNotation: true
637
+ //skipLike: /regex/
1951
638
  };
1952
639
  function toNumber(str, options = {}) {
1953
640
  options = Object.assign({}, consider, options);
@@ -2044,21 +731,65 @@ Actual: ${this.attribValue}`);
2044
731
  this.tagsNodeStack = [];
2045
732
  this.docTypeEntities = {};
2046
733
  this.lastEntities = {
2047
- "apos": { regex: /&(apos|#39|#x27);/g, val: "'" },
2048
- "gt": { regex: /&(gt|#62|#x3E);/g, val: ">" },
2049
- "lt": { regex: /&(lt|#60|#x3C);/g, val: "<" },
2050
- "quot": { regex: /&(quot|#34|#x22);/g, val: '"' }
734
+ "apos": {
735
+ regex: /&(apos|#39|#x27);/g,
736
+ val: "'"
737
+ },
738
+ "gt": {
739
+ regex: /&(gt|#62|#x3E);/g,
740
+ val: ">"
741
+ },
742
+ "lt": {
743
+ regex: /&(lt|#60|#x3C);/g,
744
+ val: "<"
745
+ },
746
+ "quot": {
747
+ regex: /&(quot|#34|#x22);/g,
748
+ val: '"'
749
+ }
750
+ };
751
+ this.ampEntity = {
752
+ regex: /&(amp|#38|#x26);/g,
753
+ val: "&"
2051
754
  };
2052
- this.ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" };
2053
755
  this.htmlEntities = {
2054
- "space": { regex: /&(nbsp|#160);/g, val: " " },
2055
- "cent": { regex: /&(cent|#162);/g, val: "\xA2" },
2056
- "pound": { regex: /&(pound|#163);/g, val: "\xA3" },
2057
- "yen": { regex: /&(yen|#165);/g, val: "\xA5" },
2058
- "euro": { regex: /&(euro|#8364);/g, val: "\u20AC" },
2059
- "copyright": { regex: /&(copy|#169);/g, val: "\xA9" },
2060
- "reg": { regex: /&(reg|#174);/g, val: "\xAE" },
2061
- "inr": { regex: /&(inr|#8377);/g, val: "\u20B9" }
756
+ "space": {
757
+ regex: /&(nbsp|#160);/g,
758
+ val: " "
759
+ },
760
+ // "lt" : { regex: /&(lt|#60);/g, val: "<" },
761
+ // "gt" : { regex: /&(gt|#62);/g, val: ">" },
762
+ // "amp" : { regex: /&(amp|#38);/g, val: "&" },
763
+ // "quot" : { regex: /&(quot|#34);/g, val: "\"" },
764
+ // "apos" : { regex: /&(apos|#39);/g, val: "'" },
765
+ "cent": {
766
+ regex: /&(cent|#162);/g,
767
+ val: "\xA2"
768
+ },
769
+ "pound": {
770
+ regex: /&(pound|#163);/g,
771
+ val: "\xA3"
772
+ },
773
+ "yen": {
774
+ regex: /&(yen|#165);/g,
775
+ val: "\xA5"
776
+ },
777
+ "euro": {
778
+ regex: /&(euro|#8364);/g,
779
+ val: "\u20AC"
780
+ },
781
+ "copyright": {
782
+ regex: /&(copy|#169);/g,
783
+ val: "\xA9"
784
+ },
785
+ "reg": {
786
+ regex: /&(reg|#174);/g,
787
+ val: "\xAE"
788
+ },
789
+ "inr": {
790
+ regex: /&(inr|#8377);/g,
791
+ val: "\u20B9"
792
+ }
2062
793
  };
2063
794
  this.addExternalEntities = addExternalEntities;
2064
795
  this.parseXml = parseXml;
@@ -2225,7 +956,9 @@ Actual: ${this.attribValue}`);
2225
956
  if (this.options.commentPropName) {
2226
957
  const comment = xmlData.substring(i + 4, endIndex - 2);
2227
958
  textData = this.saveTextToParentTag(textData, currentNode, jPath);
2228
- currentNode.add(this.options.commentPropName, [{ [this.options.textNodeName]: comment }]);
959
+ currentNode.add(this.options.commentPropName, [{
960
+ [this.options.textNodeName]: comment
961
+ }]);
2229
962
  }
2230
963
  i = endIndex;
2231
964
  } else if (xmlData.substr(i + 1, 2) === "!D") {
@@ -2237,7 +970,9 @@ Actual: ${this.attribValue}`);
2237
970
  const tagExp = xmlData.substring(i + 9, closeIndex);
2238
971
  textData = this.saveTextToParentTag(textData, currentNode, jPath);
2239
972
  if (this.options.cdataPropName) {
2240
- currentNode.add(this.options.cdataPropName, [{ [this.options.textNodeName]: tagExp }]);
973
+ currentNode.add(this.options.cdataPropName, [{
974
+ [this.options.textNodeName]: tagExp
975
+ }]);
2241
976
  } else {
2242
977
  let val2 = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true);
2243
978
  if (val2 == void 0)
@@ -2584,7 +1319,9 @@ Actual: ${this.attribValue}`);
2584
1319
  }
2585
1320
  }
2586
1321
  function isLeafTag(obj, options) {
2587
- const { textNodeName } = options;
1322
+ const {
1323
+ textNodeName
1324
+ } = options;
2588
1325
  const propCount = Object.keys(obj).length;
2589
1326
  if (propCount === 0) {
2590
1327
  return true;
@@ -2601,15 +1338,24 @@ Actual: ${this.attribValue}`);
2601
1338
  // ../../node_modules/fast-xml-parser/src/xmlparser/XMLParser.js
2602
1339
  var require_XMLParser = __commonJS({
2603
1340
  "../../node_modules/fast-xml-parser/src/xmlparser/XMLParser.js"(exports, module) {
2604
- var { buildOptions } = require_OptionsBuilder();
1341
+ var {
1342
+ buildOptions
1343
+ } = require_OptionsBuilder();
2605
1344
  var OrderedObjParser = require_OrderedObjParser();
2606
- var { prettify } = require_node2json();
1345
+ var {
1346
+ prettify
1347
+ } = require_node2json();
2607
1348
  var validator = require_validator();
2608
1349
  var XMLParser = class {
2609
1350
  constructor(options) {
2610
1351
  this.externalEntities = {};
2611
1352
  this.options = buildOptions(options);
2612
1353
  }
1354
+ /**
1355
+ * Parse XML dats to JS object
1356
+ * @param {string|Buffer} xmlData
1357
+ * @param {boolean|Object} validationOption
1358
+ */
2613
1359
  parse(xmlData, validationOption) {
2614
1360
  if (typeof xmlData === "string") {
2615
1361
  } else if (xmlData.toString) {
@@ -2633,6 +1379,11 @@ Actual: ${this.attribValue}`);
2633
1379
  else
2634
1380
  return prettify(orderedResult, this.options);
2635
1381
  }
1382
+ /**
1383
+ * Add Entity which is not by default supported by this library
1384
+ * @param {string} key
1385
+ * @param {string} value
1386
+ */
2636
1387
  addEntity(key, value) {
2637
1388
  if (value.indexOf("&") !== -1) {
2638
1389
  throw new Error("Entity value can't have '&'");
@@ -2803,14 +1554,32 @@ Actual: ${this.attribValue}`);
2803
1554
  commentPropName: false,
2804
1555
  unpairedTags: [],
2805
1556
  entities: [
2806
- { regex: new RegExp("&", "g"), val: "&amp;" },
2807
- { regex: new RegExp(">", "g"), val: "&gt;" },
2808
- { regex: new RegExp("<", "g"), val: "&lt;" },
2809
- { regex: new RegExp("'", "g"), val: "&apos;" },
2810
- { regex: new RegExp('"', "g"), val: "&quot;" }
1557
+ {
1558
+ regex: new RegExp("&", "g"),
1559
+ val: "&amp;"
1560
+ },
1561
+ //it must be on top
1562
+ {
1563
+ regex: new RegExp(">", "g"),
1564
+ val: "&gt;"
1565
+ },
1566
+ {
1567
+ regex: new RegExp("<", "g"),
1568
+ val: "&lt;"
1569
+ },
1570
+ {
1571
+ regex: new RegExp("'", "g"),
1572
+ val: "&apos;"
1573
+ },
1574
+ {
1575
+ regex: new RegExp('"', "g"),
1576
+ val: "&quot;"
1577
+ }
2811
1578
  ],
2812
1579
  processEntities: true,
2813
1580
  stopNodes: [],
1581
+ // transformTagName: false,
1582
+ // transformAttributeName: false,
2814
1583
  oneListGroup: false
2815
1584
  };
2816
1585
  function Builder(options) {
@@ -2887,150 +1656,1538 @@ Actual: ${this.attribValue}`);
2887
1656
  if (this.options.oneListGroup) {
2888
1657
  listTagVal += this.j2x(item, level + 1).val;
2889
1658
  } else {
2890
- listTagVal += this.processTextOrObjNode(item, key, level);
1659
+ listTagVal += this.processTextOrObjNode(item, key, level);
1660
+ }
1661
+ } else {
1662
+ listTagVal += this.buildTextValNode(item, key, "", level);
1663
+ }
1664
+ }
1665
+ if (this.options.oneListGroup) {
1666
+ listTagVal = this.buildObjectNode(listTagVal, key, "", level);
1667
+ }
1668
+ val2 += listTagVal;
1669
+ } else {
1670
+ if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
1671
+ const Ks = Object.keys(jObj[key]);
1672
+ const L = Ks.length;
1673
+ for (let j = 0; j < L; j++) {
1674
+ attrStr += this.buildAttrPairStr(Ks[j], "" + jObj[key][Ks[j]]);
1675
+ }
1676
+ } else {
1677
+ val2 += this.processTextOrObjNode(jObj[key], key, level);
1678
+ }
1679
+ }
1680
+ }
1681
+ return {
1682
+ attrStr,
1683
+ val: val2
1684
+ };
1685
+ };
1686
+ Builder.prototype.buildAttrPairStr = function(attrName, val2) {
1687
+ val2 = this.options.attributeValueProcessor(attrName, "" + val2);
1688
+ val2 = this.replaceEntitiesValue(val2);
1689
+ if (this.options.suppressBooleanAttributes && val2 === "true") {
1690
+ return " " + attrName;
1691
+ } else
1692
+ return " " + attrName + '="' + val2 + '"';
1693
+ };
1694
+ function processTextOrObjNode(object, key, level) {
1695
+ const result = this.j2x(object, level + 1);
1696
+ if (object[this.options.textNodeName] !== void 0 && Object.keys(object).length === 1) {
1697
+ return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level);
1698
+ } else {
1699
+ return this.buildObjectNode(result.val, key, result.attrStr, level);
1700
+ }
1701
+ }
1702
+ Builder.prototype.buildObjectNode = function(val2, key, attrStr, level) {
1703
+ if (val2 === "") {
1704
+ if (key[0] === "?")
1705
+ return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
1706
+ else {
1707
+ return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
1708
+ }
1709
+ } else {
1710
+ let tagEndExp = "</" + key + this.tagEndChar;
1711
+ let piClosingChar = "";
1712
+ if (key[0] === "?") {
1713
+ piClosingChar = "?";
1714
+ tagEndExp = "";
1715
+ }
1716
+ if (attrStr && val2.indexOf("<") === -1) {
1717
+ return this.indentate(level) + "<" + key + attrStr + piClosingChar + ">" + val2 + tagEndExp;
1718
+ } else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
1719
+ return this.indentate(level) + `<!--${val2}-->` + this.newLine;
1720
+ } else {
1721
+ return this.indentate(level) + "<" + key + attrStr + piClosingChar + this.tagEndChar + val2 + this.indentate(level) + tagEndExp;
1722
+ }
1723
+ }
1724
+ };
1725
+ Builder.prototype.closeTag = function(key) {
1726
+ let closeTag = "";
1727
+ if (this.options.unpairedTags.indexOf(key) !== -1) {
1728
+ if (!this.options.suppressUnpairedNode)
1729
+ closeTag = "/";
1730
+ } else if (this.options.suppressEmptyNode) {
1731
+ closeTag = "/";
1732
+ } else {
1733
+ closeTag = `></${key}`;
1734
+ }
1735
+ return closeTag;
1736
+ };
1737
+ Builder.prototype.buildTextValNode = function(val2, key, attrStr, level) {
1738
+ if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
1739
+ return this.indentate(level) + `<![CDATA[${val2}]]>` + this.newLine;
1740
+ } else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
1741
+ return this.indentate(level) + `<!--${val2}-->` + this.newLine;
1742
+ } else if (key[0] === "?") {
1743
+ return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
1744
+ } else {
1745
+ let textValue = this.options.tagValueProcessor(key, val2);
1746
+ textValue = this.replaceEntitiesValue(textValue);
1747
+ if (textValue === "") {
1748
+ return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
1749
+ } else {
1750
+ return this.indentate(level) + "<" + key + attrStr + ">" + textValue + "</" + key + this.tagEndChar;
1751
+ }
1752
+ }
1753
+ };
1754
+ Builder.prototype.replaceEntitiesValue = function(textValue) {
1755
+ if (textValue && textValue.length > 0 && this.options.processEntities) {
1756
+ for (let i = 0; i < this.options.entities.length; i++) {
1757
+ const entity = this.options.entities[i];
1758
+ textValue = textValue.replace(entity.regex, entity.val);
1759
+ }
1760
+ }
1761
+ return textValue;
1762
+ };
1763
+ function indentate(level) {
1764
+ return this.options.indentBy.repeat(level);
1765
+ }
1766
+ function isAttribute(name) {
1767
+ if (name.startsWith(this.options.attributeNamePrefix)) {
1768
+ return name.substr(this.attrPrefixLen);
1769
+ } else {
1770
+ return false;
1771
+ }
1772
+ }
1773
+ module.exports = Builder;
1774
+ }
1775
+ });
1776
+
1777
+ // ../../node_modules/fast-xml-parser/src/fxp.js
1778
+ var require_fxp = __commonJS({
1779
+ "../../node_modules/fast-xml-parser/src/fxp.js"(exports, module) {
1780
+ "use strict";
1781
+ var validator = require_validator();
1782
+ var XMLParser = require_XMLParser();
1783
+ var XMLBuilder = require_json2xml();
1784
+ module.exports = {
1785
+ XMLParser,
1786
+ XMLValidator: validator,
1787
+ XMLBuilder
1788
+ };
1789
+ }
1790
+ });
1791
+
1792
+ // src/index.ts
1793
+ var src_exports = {};
1794
+ __export(src_exports, {
1795
+ HTMLLoader: () => HTMLLoader,
1796
+ SAXParser: () => SAXParser,
1797
+ XMLLoader: () => XMLLoader,
1798
+ _uncapitalize: () => uncapitalize,
1799
+ _uncapitalizeKeys: () => uncapitalizeKeys,
1800
+ convertXMLFieldToArrayInPlace: () => convertXMLFieldToArrayInPlace,
1801
+ convertXMLValueToArray: () => convertXMLValueToArray
1802
+ });
1803
+
1804
+ // src/sax-ts/sax.ts
1805
+ var DEFAULT_SAX_EVENTS = {
1806
+ ontext: () => {
1807
+ },
1808
+ onprocessinginstruction: () => {
1809
+ },
1810
+ onsgmldeclaration: () => {
1811
+ },
1812
+ ondoctype: () => {
1813
+ },
1814
+ oncomment: () => {
1815
+ },
1816
+ onopentagstart: () => {
1817
+ },
1818
+ onattribute: () => {
1819
+ },
1820
+ onopentag: () => {
1821
+ },
1822
+ onclosetag: () => {
1823
+ },
1824
+ onopencdata: () => {
1825
+ },
1826
+ oncdata: () => {
1827
+ },
1828
+ onclosecdata: () => {
1829
+ },
1830
+ onerror: () => {
1831
+ },
1832
+ onend: () => {
1833
+ },
1834
+ onready: () => {
1835
+ },
1836
+ onscript: () => {
1837
+ },
1838
+ onopennamespace: () => {
1839
+ },
1840
+ onclosenamespace: () => {
1841
+ }
1842
+ };
1843
+ var DEFAULT_SAX_PARSER_OPTIONS = {
1844
+ ...DEFAULT_SAX_EVENTS,
1845
+ strict: false,
1846
+ MAX_BUFFER_LENGTH: 64 * 1024,
1847
+ lowercase: false,
1848
+ lowercasetags: false,
1849
+ noscript: false,
1850
+ strictEntities: false,
1851
+ xmlns: void 0,
1852
+ position: void 0,
1853
+ trim: void 0,
1854
+ normalize: void 0
1855
+ };
1856
+ var EVENTS = ["text", "processinginstruction", "sgmldeclaration", "doctype", "comment", "opentagstart", "attribute", "opentag", "closetag", "opencdata", "cdata", "closecdata", "error", "end", "ready", "script", "opennamespace", "closenamespace"];
1857
+ var BUFFERS = ["comment", "sgmlDecl", "textNode", "tagName", "doctype", "procInstName", "procInstBody", "entity", "attribName", "attribValue", "cdata", "script"];
1858
+ var 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]/;
1859
+ var 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-]/;
1860
+ var 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]/;
1861
+ var 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-]/;
1862
+ var ENTITIES = {
1863
+ amp: "&",
1864
+ gt: ">",
1865
+ lt: "<",
1866
+ quot: '"',
1867
+ apos: "'",
1868
+ AElig: 198,
1869
+ Aacute: 193,
1870
+ Acirc: 194,
1871
+ Agrave: 192,
1872
+ Aring: 197,
1873
+ Atilde: 195,
1874
+ Auml: 196,
1875
+ Ccedil: 199,
1876
+ ETH: 208,
1877
+ Eacute: 201,
1878
+ Ecirc: 202,
1879
+ Egrave: 200,
1880
+ Euml: 203,
1881
+ Iacute: 205,
1882
+ Icirc: 206,
1883
+ Igrave: 204,
1884
+ Iuml: 207,
1885
+ Ntilde: 209,
1886
+ Oacute: 211,
1887
+ Ocirc: 212,
1888
+ Ograve: 210,
1889
+ Oslash: 216,
1890
+ Otilde: 213,
1891
+ Ouml: 214,
1892
+ THORN: 222,
1893
+ Uacute: 218,
1894
+ Ucirc: 219,
1895
+ Ugrave: 217,
1896
+ Uuml: 220,
1897
+ Yacute: 221,
1898
+ aacute: 225,
1899
+ acirc: 226,
1900
+ aelig: 230,
1901
+ agrave: 224,
1902
+ aring: 229,
1903
+ atilde: 227,
1904
+ auml: 228,
1905
+ ccedil: 231,
1906
+ eacute: 233,
1907
+ ecirc: 234,
1908
+ egrave: 232,
1909
+ eth: 240,
1910
+ euml: 235,
1911
+ iacute: 237,
1912
+ icirc: 238,
1913
+ igrave: 236,
1914
+ iuml: 239,
1915
+ ntilde: 241,
1916
+ oacute: 243,
1917
+ ocirc: 244,
1918
+ ograve: 242,
1919
+ oslash: 248,
1920
+ otilde: 245,
1921
+ ouml: 246,
1922
+ szlig: 223,
1923
+ thorn: 254,
1924
+ uacute: 250,
1925
+ ucirc: 251,
1926
+ ugrave: 249,
1927
+ uuml: 252,
1928
+ yacute: 253,
1929
+ yuml: 255,
1930
+ copy: 169,
1931
+ reg: 174,
1932
+ nbsp: 160,
1933
+ iexcl: 161,
1934
+ cent: 162,
1935
+ pound: 163,
1936
+ curren: 164,
1937
+ yen: 165,
1938
+ brvbar: 166,
1939
+ sect: 167,
1940
+ uml: 168,
1941
+ ordf: 170,
1942
+ laquo: 171,
1943
+ not: 172,
1944
+ shy: 173,
1945
+ macr: 175,
1946
+ deg: 176,
1947
+ plusmn: 177,
1948
+ sup1: 185,
1949
+ sup2: 178,
1950
+ sup3: 179,
1951
+ acute: 180,
1952
+ micro: 181,
1953
+ para: 182,
1954
+ middot: 183,
1955
+ cedil: 184,
1956
+ ordm: 186,
1957
+ raquo: 187,
1958
+ frac14: 188,
1959
+ frac12: 189,
1960
+ frac34: 190,
1961
+ iquest: 191,
1962
+ times: 215,
1963
+ divide: 247,
1964
+ OElig: 338,
1965
+ oelig: 339,
1966
+ Scaron: 352,
1967
+ scaron: 353,
1968
+ Yuml: 376,
1969
+ fnof: 402,
1970
+ circ: 710,
1971
+ tilde: 732,
1972
+ Alpha: 913,
1973
+ Beta: 914,
1974
+ Gamma: 915,
1975
+ Delta: 916,
1976
+ Epsilon: 917,
1977
+ Zeta: 918,
1978
+ Eta: 919,
1979
+ Theta: 920,
1980
+ Iota: 921,
1981
+ Kappa: 922,
1982
+ Lambda: 923,
1983
+ Mu: 924,
1984
+ Nu: 925,
1985
+ Xi: 926,
1986
+ Omicron: 927,
1987
+ Pi: 928,
1988
+ Rho: 929,
1989
+ Sigma: 931,
1990
+ Tau: 932,
1991
+ Upsilon: 933,
1992
+ Phi: 934,
1993
+ Chi: 935,
1994
+ Psi: 936,
1995
+ Omega: 937,
1996
+ alpha: 945,
1997
+ beta: 946,
1998
+ gamma: 947,
1999
+ delta: 948,
2000
+ epsilon: 949,
2001
+ zeta: 950,
2002
+ eta: 951,
2003
+ theta: 952,
2004
+ iota: 953,
2005
+ kappa: 954,
2006
+ lambda: 955,
2007
+ mu: 956,
2008
+ nu: 957,
2009
+ xi: 958,
2010
+ omicron: 959,
2011
+ pi: 960,
2012
+ rho: 961,
2013
+ sigmaf: 962,
2014
+ sigma: 963,
2015
+ tau: 964,
2016
+ upsilon: 965,
2017
+ phi: 966,
2018
+ chi: 967,
2019
+ psi: 968,
2020
+ omega: 969,
2021
+ thetasym: 977,
2022
+ upsih: 978,
2023
+ piv: 982,
2024
+ ensp: 8194,
2025
+ emsp: 8195,
2026
+ thinsp: 8201,
2027
+ zwnj: 8204,
2028
+ zwj: 8205,
2029
+ lrm: 8206,
2030
+ rlm: 8207,
2031
+ ndash: 8211,
2032
+ mdash: 8212,
2033
+ lsquo: 8216,
2034
+ rsquo: 8217,
2035
+ sbquo: 8218,
2036
+ ldquo: 8220,
2037
+ rdquo: 8221,
2038
+ bdquo: 8222,
2039
+ dagger: 8224,
2040
+ Dagger: 8225,
2041
+ bull: 8226,
2042
+ hellip: 8230,
2043
+ permil: 8240,
2044
+ prime: 8242,
2045
+ Prime: 8243,
2046
+ lsaquo: 8249,
2047
+ rsaquo: 8250,
2048
+ oline: 8254,
2049
+ frasl: 8260,
2050
+ euro: 8364,
2051
+ image: 8465,
2052
+ weierp: 8472,
2053
+ real: 8476,
2054
+ trade: 8482,
2055
+ alefsym: 8501,
2056
+ larr: 8592,
2057
+ uarr: 8593,
2058
+ rarr: 8594,
2059
+ darr: 8595,
2060
+ harr: 8596,
2061
+ crarr: 8629,
2062
+ lArr: 8656,
2063
+ uArr: 8657,
2064
+ rArr: 8658,
2065
+ dArr: 8659,
2066
+ hArr: 8660,
2067
+ forall: 8704,
2068
+ part: 8706,
2069
+ exist: 8707,
2070
+ empty: 8709,
2071
+ nabla: 8711,
2072
+ isin: 8712,
2073
+ notin: 8713,
2074
+ ni: 8715,
2075
+ prod: 8719,
2076
+ sum: 8721,
2077
+ minus: 8722,
2078
+ lowast: 8727,
2079
+ radic: 8730,
2080
+ prop: 8733,
2081
+ infin: 8734,
2082
+ ang: 8736,
2083
+ and: 8743,
2084
+ or: 8744,
2085
+ cap: 8745,
2086
+ cup: 8746,
2087
+ int: 8747,
2088
+ there4: 8756,
2089
+ sim: 8764,
2090
+ cong: 8773,
2091
+ asymp: 8776,
2092
+ ne: 8800,
2093
+ equiv: 8801,
2094
+ le: 8804,
2095
+ ge: 8805,
2096
+ sub: 8834,
2097
+ sup: 8835,
2098
+ nsub: 8836,
2099
+ sube: 8838,
2100
+ supe: 8839,
2101
+ oplus: 8853,
2102
+ otimes: 8855,
2103
+ perp: 8869,
2104
+ sdot: 8901,
2105
+ lceil: 8968,
2106
+ rceil: 8969,
2107
+ lfloor: 8970,
2108
+ rfloor: 8971,
2109
+ lang: 9001,
2110
+ rang: 9002,
2111
+ loz: 9674,
2112
+ spades: 9824,
2113
+ clubs: 9827,
2114
+ hearts: 9829,
2115
+ diams: 9830
2116
+ };
2117
+ Object.keys(ENTITIES).forEach((key) => {
2118
+ const e = ENTITIES[key];
2119
+ ENTITIES[key] = typeof e === "number" ? String.fromCharCode(e) : e;
2120
+ });
2121
+ var SAX = class {
2122
+ EVENTS = EVENTS;
2123
+ ENTITIES = {
2124
+ // TODO: make it readonly, needed for entity-mega test
2125
+ // amp, gt, lt, quot and apos are resolved to strings instead of numerical
2126
+ // codes, IDK why
2127
+ ...ENTITIES
2128
+ };
2129
+ XML_ENTITIES = {
2130
+ amp: "&",
2131
+ gt: ">",
2132
+ lt: "<",
2133
+ quot: '"',
2134
+ apos: "'"
2135
+ };
2136
+ S = 0;
2137
+ trackPosition = false;
2138
+ column = 0;
2139
+ line = 0;
2140
+ c = "";
2141
+ q = "";
2142
+ closed = false;
2143
+ tags = [];
2144
+ looseCase = "";
2145
+ closedRoot = false;
2146
+ sawRoot = false;
2147
+ strict = false;
2148
+ noscript = false;
2149
+ attribList = [];
2150
+ position = 0;
2151
+ STATE = {
2152
+ BEGIN: this.S++,
2153
+ // leading byte order mark or whitespace
2154
+ BEGIN_WHITESPACE: this.S++,
2155
+ // leading whitespace
2156
+ TEXT: this.S++,
2157
+ // general stuff
2158
+ TEXT_ENTITY: this.S++,
2159
+ // &amp and such.
2160
+ OPEN_WAKA: this.S++,
2161
+ // <
2162
+ SGML_DECL: this.S++,
2163
+ // <!BLARG
2164
+ SGML_DECL_QUOTED: this.S++,
2165
+ // <!BLARG foo "bar
2166
+ DOCTYPE: this.S++,
2167
+ // <!DOCTYPE
2168
+ DOCTYPE_QUOTED: this.S++,
2169
+ // <!DOCTYPE "//blah
2170
+ DOCTYPE_DTD: this.S++,
2171
+ // <!DOCTYPE "//blah" [ ...
2172
+ DOCTYPE_DTD_QUOTED: this.S++,
2173
+ // <!DOCTYPE "//blah" [ "foo
2174
+ COMMENT_STARTING: this.S++,
2175
+ // <!-
2176
+ COMMENT: this.S++,
2177
+ // <!--
2178
+ COMMENT_ENDING: this.S++,
2179
+ // <!-- blah -
2180
+ COMMENT_ENDED: this.S++,
2181
+ // <!-- blah --
2182
+ CDATA: this.S++,
2183
+ // <![CDATA[ something
2184
+ CDATA_ENDING: this.S++,
2185
+ // ]
2186
+ CDATA_ENDING_2: this.S++,
2187
+ // ]]
2188
+ PROC_INST: this.S++,
2189
+ // <?hi
2190
+ PROC_INST_BODY: this.S++,
2191
+ // <?hi there
2192
+ PROC_INST_ENDING: this.S++,
2193
+ // <?hi "there" ?
2194
+ OPEN_TAG: this.S++,
2195
+ // <strong
2196
+ OPEN_TAG_SLASH: this.S++,
2197
+ // <strong /
2198
+ ATTRIB: this.S++,
2199
+ // <a
2200
+ ATTRIB_NAME: this.S++,
2201
+ // <a foo
2202
+ ATTRIB_NAME_SAW_WHITE: this.S++,
2203
+ // <a foo _
2204
+ ATTRIB_VALUE: this.S++,
2205
+ // <a foo=
2206
+ ATTRIB_VALUE_QUOTED: this.S++,
2207
+ // <a foo="bar
2208
+ ATTRIB_VALUE_CLOSED: this.S++,
2209
+ // <a foo="bar"
2210
+ ATTRIB_VALUE_UNQUOTED: this.S++,
2211
+ // <a foo=bar
2212
+ ATTRIB_VALUE_ENTITY_Q: this.S++,
2213
+ // <foo bar="&quot;"
2214
+ ATTRIB_VALUE_ENTITY_U: this.S++,
2215
+ // <foo bar=&quot
2216
+ CLOSE_TAG: this.S++,
2217
+ // </a
2218
+ CLOSE_TAG_SAW_WHITE: this.S++,
2219
+ // </a >
2220
+ SCRIPT: this.S++,
2221
+ // <script> ...
2222
+ SCRIPT_ENDING: this.S++
2223
+ // <script> ... <
2224
+ };
2225
+ BUFFERS = BUFFERS;
2226
+ // private parser: (strict: boolean, opt: any) => SAXParser;
2227
+ CDATA = "[CDATA[";
2228
+ DOCTYPE = "DOCTYPE";
2229
+ XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
2230
+ XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
2231
+ rootNS = {
2232
+ xml: this.XML_NAMESPACE,
2233
+ xmlns: this.XMLNS_NAMESPACE
2234
+ };
2235
+ textNode = "";
2236
+ entity = "";
2237
+ cdata = "";
2238
+ script = "";
2239
+ startTagPosition = 0;
2240
+ constructor() {
2241
+ this.S = 0;
2242
+ for (const s in this.STATE) {
2243
+ if (this.STATE.hasOwnProperty(s)) {
2244
+ this.STATE[this.STATE[s]] = s;
2245
+ }
2246
+ }
2247
+ this.S = this.STATE;
2248
+ }
2249
+ static charAt(chunk, i) {
2250
+ let result = "";
2251
+ if (i < chunk.length) {
2252
+ result = chunk.charAt(i);
2253
+ }
2254
+ return result;
2255
+ }
2256
+ static isWhitespace(c) {
2257
+ return c === " " || c === "\n" || c === "\r" || c === " ";
2258
+ }
2259
+ static isQuote(c) {
2260
+ return c === '"' || c === "'";
2261
+ }
2262
+ static isAttribEnd(c) {
2263
+ return c === ">" || SAX.isWhitespace(c);
2264
+ }
2265
+ static isMatch(regex, c) {
2266
+ return regex.test(c);
2267
+ }
2268
+ static notMatch(regex, c) {
2269
+ return !SAX.isMatch(regex, c);
2270
+ }
2271
+ static qname(name, attribute) {
2272
+ const i = name.indexOf(":");
2273
+ const qualName = i < 0 ? ["", name] : name.split(":");
2274
+ let prefix = qualName[0];
2275
+ let local = qualName[1];
2276
+ if (attribute && name === "xmlns") {
2277
+ prefix = "xmlns";
2278
+ local = "";
2279
+ }
2280
+ return {
2281
+ prefix,
2282
+ local
2283
+ };
2284
+ }
2285
+ write(chunk) {
2286
+ if (this.error) {
2287
+ throw this.error;
2288
+ }
2289
+ if (this.closed) {
2290
+ return this.errorFunction("Cannot write after close. Assign an onready handler.");
2291
+ }
2292
+ if (chunk === null) {
2293
+ return this.end();
2294
+ }
2295
+ if (typeof chunk === "object") {
2296
+ chunk = chunk.toString();
2297
+ }
2298
+ let i = 0;
2299
+ let c;
2300
+ while (true) {
2301
+ c = SAX.charAt(chunk, i++);
2302
+ this.c = c;
2303
+ if (!c) {
2304
+ break;
2305
+ }
2306
+ if (this.trackPosition) {
2307
+ this.position++;
2308
+ if (c === "\n") {
2309
+ this.line++;
2310
+ this.column = 0;
2311
+ } else {
2312
+ this.column++;
2313
+ }
2314
+ }
2315
+ switch (this.state) {
2316
+ case this.S.BEGIN:
2317
+ this.state = this.S.BEGIN_WHITESPACE;
2318
+ if (c === "\uFEFF") {
2319
+ continue;
2320
+ }
2321
+ this.beginWhiteSpace(c);
2322
+ continue;
2323
+ case this.S.BEGIN_WHITESPACE:
2324
+ this.beginWhiteSpace(c);
2325
+ continue;
2326
+ case this.S.TEXT:
2327
+ if (this.sawRoot && !this.closedRoot) {
2328
+ const starti = i - 1;
2329
+ while (c && c !== "<" && c !== "&") {
2330
+ c = SAX.charAt(chunk, i++);
2331
+ if (c && this.trackPosition) {
2332
+ this.position++;
2333
+ if (c === "\n") {
2334
+ this.line++;
2335
+ this.column = 0;
2336
+ } else {
2337
+ this.column++;
2338
+ }
2339
+ }
2340
+ }
2341
+ this.textNode += chunk.substring(starti, i - 1);
2342
+ }
2343
+ if (c === "<" && !(this.sawRoot && this.closedRoot && !this.strict)) {
2344
+ this.state = this.S.OPEN_WAKA;
2345
+ this.startTagPosition = this.position;
2346
+ } else {
2347
+ if (!SAX.isWhitespace(c) && (!this.sawRoot || this.closedRoot)) {
2348
+ this.strictFail("Text data outside of root node.");
2349
+ }
2350
+ if (c === "&") {
2351
+ this.state = this.S.TEXT_ENTITY;
2352
+ } else {
2353
+ this.textNode += c;
2354
+ }
2355
+ }
2356
+ continue;
2357
+ case this.S.SCRIPT:
2358
+ if (c === "<") {
2359
+ this.state = this.S.SCRIPT_ENDING;
2360
+ } else {
2361
+ this.script += c;
2362
+ }
2363
+ continue;
2364
+ case this.S.SCRIPT_ENDING:
2365
+ if (c === "/") {
2366
+ this.state = this.S.CLOSE_TAG;
2367
+ } else {
2368
+ this.script += `<${c}`;
2369
+ this.state = this.S.SCRIPT;
2370
+ }
2371
+ continue;
2372
+ case this.S.OPEN_WAKA:
2373
+ if (c === "!") {
2374
+ this.state = this.S.SGML_DECL;
2375
+ this.sgmlDecl = "";
2376
+ } else if (SAX.isWhitespace(c)) {
2377
+ } else if (SAX.isMatch(nameStart, c)) {
2378
+ this.state = this.S.OPEN_TAG;
2379
+ this.tagName = c;
2380
+ } else if (c === "/") {
2381
+ this.state = this.S.CLOSE_TAG;
2382
+ this.tagName = "";
2383
+ } else if (c === "?") {
2384
+ this.state = this.S.PROC_INST;
2385
+ this.procInstName = this.procInstBody = "";
2386
+ } else {
2387
+ this.strictFail("Unencoded <");
2388
+ if (this.startTagPosition + 1 < this.position) {
2389
+ const pad = this.position - this.startTagPosition;
2390
+ c = new Array(pad).join(" ") + c;
2391
+ }
2392
+ this.textNode += `<${c}`;
2393
+ this.state = this.S.TEXT;
2394
+ }
2395
+ continue;
2396
+ case this.S.SGML_DECL:
2397
+ if ((this.sgmlDecl + c).toUpperCase() === this.CDATA) {
2398
+ this.emitNode("onopencdata");
2399
+ this.state = this.S.CDATA;
2400
+ this.sgmlDecl = "";
2401
+ this.cdata = "";
2402
+ } else if (this.sgmlDecl + c === "--") {
2403
+ this.state = this.S.COMMENT;
2404
+ this.comment = "";
2405
+ this.sgmlDecl = "";
2406
+ } else if ((this.sgmlDecl + c).toUpperCase() === this.DOCTYPE) {
2407
+ this.state = this.S.DOCTYPE;
2408
+ if (this.doctype || this.sawRoot) {
2409
+ this.strictFail("Inappropriately located doctype declaration");
2410
+ }
2411
+ this.doctype = "";
2412
+ this.sgmlDecl = "";
2413
+ } else if (c === ">") {
2414
+ this.emitNode("onsgmldeclaration", this.sgmlDecl);
2415
+ this.sgmlDecl = "";
2416
+ this.state = this.S.TEXT;
2417
+ } else if (SAX.isQuote(c)) {
2418
+ this.state = this.S.SGML_DECL_QUOTED;
2419
+ this.sgmlDecl += c;
2420
+ } else {
2421
+ this.sgmlDecl += c;
2422
+ }
2423
+ continue;
2424
+ case this.S.SGML_DECL_QUOTED:
2425
+ if (c === this.q) {
2426
+ this.state = this.S.SGML_DECL;
2427
+ this.q = "";
2428
+ }
2429
+ this.sgmlDecl += c;
2430
+ continue;
2431
+ case this.S.DOCTYPE:
2432
+ if (c === ">") {
2433
+ this.state = this.S.TEXT;
2434
+ this.emitNode("ondoctype", this.doctype);
2435
+ this.doctype = true;
2436
+ } else {
2437
+ this.doctype += c;
2438
+ if (c === "[") {
2439
+ this.state = this.S.DOCTYPE_DTD;
2440
+ } else if (SAX.isQuote(c)) {
2441
+ this.state = this.S.DOCTYPE_QUOTED;
2442
+ this.q = c;
2443
+ }
2444
+ }
2445
+ continue;
2446
+ case this.S.DOCTYPE_QUOTED:
2447
+ this.doctype += c;
2448
+ if (c === this.q) {
2449
+ this.q = "";
2450
+ this.state = this.S.DOCTYPE;
2451
+ }
2452
+ continue;
2453
+ case this.S.DOCTYPE_DTD:
2454
+ this.doctype += c;
2455
+ if (c === "]") {
2456
+ this.state = this.S.DOCTYPE;
2457
+ } else if (SAX.isQuote(c)) {
2458
+ this.state = this.S.DOCTYPE_DTD_QUOTED;
2459
+ this.q = c;
2460
+ }
2461
+ continue;
2462
+ case this.S.DOCTYPE_DTD_QUOTED:
2463
+ this.doctype += c;
2464
+ if (c === this.q) {
2465
+ this.state = this.S.DOCTYPE_DTD;
2466
+ this.q = "";
2467
+ }
2468
+ continue;
2469
+ case this.S.COMMENT:
2470
+ if (c === "-") {
2471
+ this.state = this.S.COMMENT_ENDING;
2472
+ } else {
2473
+ this.comment += c;
2474
+ }
2475
+ continue;
2476
+ case this.S.COMMENT_ENDING:
2477
+ if (c === "-") {
2478
+ this.state = this.S.COMMENT_ENDED;
2479
+ this.comment = this.textApplyOptions(this.comment);
2480
+ if (this.comment) {
2481
+ this.emitNode("oncomment", this.comment);
2482
+ }
2483
+ this.comment = "";
2484
+ } else {
2485
+ this.comment += `-${c}`;
2486
+ this.state = this.S.COMMENT;
2487
+ }
2488
+ continue;
2489
+ case this.S.COMMENT_ENDED:
2490
+ if (c !== ">") {
2491
+ this.strictFail("Malformed comment");
2492
+ this.comment += `--${c}`;
2493
+ this.state = this.S.COMMENT;
2494
+ } else {
2495
+ this.state = this.S.TEXT;
2496
+ }
2497
+ continue;
2498
+ case this.S.CDATA:
2499
+ if (c === "]") {
2500
+ this.state = this.S.CDATA_ENDING;
2501
+ } else {
2502
+ this.cdata += c;
2503
+ }
2504
+ continue;
2505
+ case this.S.CDATA_ENDING:
2506
+ if (c === "]") {
2507
+ this.state = this.S.CDATA_ENDING_2;
2508
+ } else {
2509
+ this.cdata += `]${c}`;
2510
+ this.state = this.S.CDATA;
2511
+ }
2512
+ continue;
2513
+ case this.S.CDATA_ENDING_2:
2514
+ if (c === ">") {
2515
+ if (this.cdata) {
2516
+ this.emitNode("oncdata", this.cdata);
2517
+ }
2518
+ this.emitNode("onclosecdata");
2519
+ this.cdata = "";
2520
+ this.state = this.S.TEXT;
2521
+ } else if (c === "]") {
2522
+ this.cdata += "]";
2523
+ } else {
2524
+ this.cdata += `]]${c}`;
2525
+ this.state = this.S.CDATA;
2526
+ }
2527
+ continue;
2528
+ case this.S.PROC_INST:
2529
+ if (c === "?") {
2530
+ this.state = this.S.PROC_INST_ENDING;
2531
+ } else if (SAX.isWhitespace(c)) {
2532
+ this.state = this.S.PROC_INST_BODY;
2533
+ } else {
2534
+ this.procInstName += c;
2535
+ }
2536
+ continue;
2537
+ case this.S.PROC_INST_BODY:
2538
+ if (!this.procInstBody && SAX.isWhitespace(c)) {
2539
+ continue;
2540
+ } else if (c === "?") {
2541
+ this.state = this.S.PROC_INST_ENDING;
2542
+ } else {
2543
+ this.procInstBody += c;
2544
+ }
2545
+ continue;
2546
+ case this.S.PROC_INST_ENDING:
2547
+ if (c === ">") {
2548
+ this.emitNode("onprocessinginstruction", {
2549
+ name: this.procInstName,
2550
+ body: this.procInstBody
2551
+ });
2552
+ this.procInstName = this.procInstBody = "";
2553
+ this.state = this.S.TEXT;
2554
+ } else {
2555
+ this.procInstBody += `?${c}`;
2556
+ this.state = this.S.PROC_INST_BODY;
2557
+ }
2558
+ continue;
2559
+ case this.S.OPEN_TAG:
2560
+ if (SAX.isMatch(nameBody, c)) {
2561
+ this.tagName += c;
2562
+ } else {
2563
+ this.newTag();
2564
+ if (c === ">") {
2565
+ this.openTag();
2566
+ } else if (c === "/") {
2567
+ this.state = this.S.OPEN_TAG_SLASH;
2568
+ } else {
2569
+ if (!SAX.isWhitespace(c)) {
2570
+ this.strictFail("Invalid character in tag name");
2571
+ }
2572
+ this.state = this.S.ATTRIB;
2573
+ }
2574
+ }
2575
+ continue;
2576
+ case this.S.OPEN_TAG_SLASH:
2577
+ if (c === ">") {
2578
+ this.openTag(true);
2579
+ this.closeTag();
2580
+ } else {
2581
+ this.strictFail("Forward-slash in opening tag not followed by >");
2582
+ this.state = this.S.ATTRIB;
2583
+ }
2584
+ continue;
2585
+ case this.S.ATTRIB:
2586
+ if (SAX.isWhitespace(c)) {
2587
+ continue;
2588
+ } else if (c === ">") {
2589
+ this.openTag();
2590
+ } else if (c === "/") {
2591
+ this.state = this.S.OPEN_TAG_SLASH;
2592
+ } else if (SAX.isMatch(nameStart, c)) {
2593
+ this.attribName = c;
2594
+ this.attribValue = "";
2595
+ this.state = this.S.ATTRIB_NAME;
2596
+ } else {
2597
+ this.strictFail("Invalid attribute name");
2598
+ }
2599
+ continue;
2600
+ case this.S.ATTRIB_NAME:
2601
+ if (c === "=") {
2602
+ this.state = this.S.ATTRIB_VALUE;
2603
+ } else if (c === ">") {
2604
+ this.strictFail("Attribute without value");
2605
+ this.attribValue = this.attribName;
2606
+ this.attrib();
2607
+ this.openTag();
2608
+ } else if (SAX.isWhitespace(c)) {
2609
+ this.state = this.S.ATTRIB_NAME_SAW_WHITE;
2610
+ } else if (SAX.isMatch(nameBody, c)) {
2611
+ this.attribName += c;
2612
+ } else {
2613
+ this.strictFail("Invalid attribute name");
2614
+ }
2615
+ continue;
2616
+ case this.S.ATTRIB_NAME_SAW_WHITE:
2617
+ if (c === "=") {
2618
+ this.state = this.S.ATTRIB_VALUE;
2619
+ } else if (SAX.isWhitespace(c)) {
2620
+ continue;
2621
+ } else {
2622
+ this.strictFail("Attribute without value");
2623
+ this.tag.attributes[this.attribName] = "";
2624
+ this.attribValue = "";
2625
+ this.emitNode("onattribute", {
2626
+ name: this.attribName,
2627
+ value: ""
2628
+ });
2629
+ this.attribName = "";
2630
+ if (c === ">") {
2631
+ this.openTag();
2632
+ } else if (SAX.isMatch(nameStart, c)) {
2633
+ this.attribName = c;
2634
+ this.state = this.S.ATTRIB_NAME;
2635
+ } else {
2636
+ this.strictFail("Invalid attribute name");
2637
+ this.state = this.S.ATTRIB;
2638
+ }
2639
+ }
2640
+ continue;
2641
+ case this.S.ATTRIB_VALUE:
2642
+ if (SAX.isWhitespace(c)) {
2643
+ continue;
2644
+ } else if (SAX.isQuote(c)) {
2645
+ this.q = c;
2646
+ this.state = this.S.ATTRIB_VALUE_QUOTED;
2647
+ } else {
2648
+ this.strictFail("Unquoted attribute value");
2649
+ this.state = this.S.ATTRIB_VALUE_UNQUOTED;
2650
+ this.attribValue = c;
2651
+ }
2652
+ continue;
2653
+ case this.S.ATTRIB_VALUE_QUOTED:
2654
+ if (c !== this.q) {
2655
+ if (c === "&") {
2656
+ this.state = this.S.ATTRIB_VALUE_ENTITY_Q;
2657
+ } else {
2658
+ this.attribValue += c;
2659
+ }
2660
+ continue;
2661
+ }
2662
+ this.attrib();
2663
+ this.q = "";
2664
+ this.state = this.S.ATTRIB_VALUE_CLOSED;
2665
+ continue;
2666
+ case this.S.ATTRIB_VALUE_CLOSED:
2667
+ if (SAX.isWhitespace(c)) {
2668
+ this.state = this.S.ATTRIB;
2669
+ } else if (c === ">") {
2670
+ this.openTag();
2671
+ } else if (c === "/") {
2672
+ this.state = this.S.OPEN_TAG_SLASH;
2673
+ } else if (SAX.isMatch(nameStart, c)) {
2674
+ this.strictFail("No whitespace between attributes");
2675
+ this.attribName = c;
2676
+ this.attribValue = "";
2677
+ this.state = this.S.ATTRIB_NAME;
2678
+ } else {
2679
+ this.strictFail("Invalid attribute name");
2680
+ }
2681
+ continue;
2682
+ case this.S.ATTRIB_VALUE_UNQUOTED:
2683
+ if (!SAX.isAttribEnd(c)) {
2684
+ if (c === "&") {
2685
+ this.state = this.S.ATTRIB_VALUE_ENTITY_U;
2686
+ } else {
2687
+ this.attribValue += c;
2688
+ }
2689
+ continue;
2690
+ }
2691
+ this.attrib();
2692
+ if (c === ">") {
2693
+ this.openTag();
2694
+ } else {
2695
+ this.state = this.S.ATTRIB;
2696
+ }
2697
+ continue;
2698
+ case this.S.CLOSE_TAG:
2699
+ if (!this.tagName) {
2700
+ if (SAX.isWhitespace(c)) {
2701
+ continue;
2702
+ } else if (SAX.notMatch(nameStart, c)) {
2703
+ if (this.script) {
2704
+ this.script += `</${c}`;
2705
+ this.state = this.S.SCRIPT;
2706
+ } else {
2707
+ this.strictFail("Invalid tagname in closing tag.");
2891
2708
  }
2892
2709
  } else {
2893
- listTagVal += this.buildTextValNode(item, key, "", level);
2710
+ this.tagName = c;
2711
+ }
2712
+ } else if (c === ">") {
2713
+ this.closeTag();
2714
+ } else if (SAX.isMatch(nameBody, c)) {
2715
+ this.tagName += c;
2716
+ } else if (this.script) {
2717
+ this.script += `</${this.tagName}`;
2718
+ this.tagName = "";
2719
+ this.state = this.S.SCRIPT;
2720
+ } else {
2721
+ if (!SAX.isWhitespace(c)) {
2722
+ this.strictFail("Invalid tagname in closing tag");
2894
2723
  }
2724
+ this.state = this.S.CLOSE_TAG_SAW_WHITE;
2895
2725
  }
2896
- if (this.options.oneListGroup) {
2897
- listTagVal = this.buildObjectNode(listTagVal, key, "", level);
2726
+ continue;
2727
+ case this.S.CLOSE_TAG_SAW_WHITE:
2728
+ if (SAX.isWhitespace(c)) {
2729
+ continue;
2898
2730
  }
2899
- val2 += listTagVal;
2900
- } else {
2901
- if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
2902
- const Ks = Object.keys(jObj[key]);
2903
- const L = Ks.length;
2904
- for (let j = 0; j < L; j++) {
2905
- attrStr += this.buildAttrPairStr(Ks[j], "" + jObj[key][Ks[j]]);
2906
- }
2731
+ if (c === ">") {
2732
+ this.closeTag();
2907
2733
  } else {
2908
- val2 += this.processTextOrObjNode(jObj[key], key, level);
2734
+ this.strictFail("Invalid characters in closing tag");
2735
+ }
2736
+ continue;
2737
+ case this.S.TEXT_ENTITY:
2738
+ case this.S.ATTRIB_VALUE_ENTITY_Q:
2739
+ case this.S.ATTRIB_VALUE_ENTITY_U:
2740
+ let returnState;
2741
+ let buffer;
2742
+ switch (this.state) {
2743
+ case this.S.TEXT_ENTITY:
2744
+ returnState = this.S.TEXT;
2745
+ buffer = "textNode";
2746
+ break;
2747
+ case this.S.ATTRIB_VALUE_ENTITY_Q:
2748
+ returnState = this.S.ATTRIB_VALUE_QUOTED;
2749
+ buffer = "attribValue";
2750
+ break;
2751
+ case this.S.ATTRIB_VALUE_ENTITY_U:
2752
+ returnState = this.S.ATTRIB_VALUE_UNQUOTED;
2753
+ buffer = "attribValue";
2754
+ break;
2755
+ default:
2756
+ throw new Error(`Unknown state: ${this.state}`);
2757
+ }
2758
+ if (c === ";") {
2759
+ this[buffer] += this.parseEntity();
2760
+ this.entity = "";
2761
+ this.state = returnState;
2762
+ } else if (SAX.isMatch(this.entity.length ? entityBody : entityStart, c)) {
2763
+ this.entity += c;
2764
+ } else {
2765
+ this.strictFail("Invalid character in entity name");
2766
+ this[buffer] += `&${this.entity}${c}`;
2767
+ this.entity = "";
2768
+ this.state = returnState;
2769
+ }
2770
+ continue;
2771
+ default:
2772
+ throw new Error(`Unknown state: ${this.state}`);
2773
+ }
2774
+ }
2775
+ if (this.position >= this.bufferCheckPosition) {
2776
+ this.checkBufferLength();
2777
+ }
2778
+ return this;
2779
+ }
2780
+ emit(event, data) {
2781
+ if (this.events.hasOwnProperty(event)) {
2782
+ const eventName = event.replace(/^on/, "");
2783
+ this.events[event](data, eventName, this);
2784
+ }
2785
+ }
2786
+ clearBuffers() {
2787
+ for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
2788
+ this[this[i]] = "";
2789
+ }
2790
+ }
2791
+ flushBuffers() {
2792
+ this.closeText();
2793
+ if (this.cdata !== "") {
2794
+ this.emitNode("oncdata", this.cdata);
2795
+ this.cdata = "";
2796
+ }
2797
+ if (this.script !== "") {
2798
+ this.emitNode("onscript", this.script);
2799
+ this.script = "";
2800
+ }
2801
+ }
2802
+ end() {
2803
+ if (this.sawRoot && !this.closedRoot)
2804
+ this.strictFail("Unclosed root tag");
2805
+ if (this.state !== this.S.BEGIN && this.state !== this.S.BEGIN_WHITESPACE && this.state !== this.S.TEXT) {
2806
+ this.errorFunction("Unexpected end");
2807
+ }
2808
+ this.closeText();
2809
+ this.c = "";
2810
+ this.closed = true;
2811
+ this.emit("onend");
2812
+ return new SAXParser(this.opt);
2813
+ }
2814
+ errorFunction(er) {
2815
+ this.closeText();
2816
+ if (this.trackPosition) {
2817
+ er += `
2818
+ Line: ${this.line}
2819
+ Column: ${this.column}
2820
+ Char: ${this.c}`;
2821
+ }
2822
+ const error = new Error(er);
2823
+ this.error = error;
2824
+ this.emit("onerror", error);
2825
+ return this;
2826
+ }
2827
+ attrib() {
2828
+ if (!this.strict) {
2829
+ this.attribName = this.attribName[this.looseCase]();
2830
+ }
2831
+ if (this.attribList.indexOf(this.attribName) !== -1 || this.tag.attributes.hasOwnProperty(this.attribName)) {
2832
+ this.attribName = this.attribValue = "";
2833
+ return;
2834
+ }
2835
+ if (this.opt.xmlns) {
2836
+ const qn = SAX.qname(this.attribName, true);
2837
+ const prefix = qn.prefix;
2838
+ const local = qn.local;
2839
+ if (prefix === "xmlns") {
2840
+ if (local === "xml" && this.attribValue !== this.XML_NAMESPACE) {
2841
+ this.strictFail(`xml: prefix must be bound to ${this.XML_NAMESPACE}
2842
+ Actual: ${this.attribValue}`);
2843
+ } else if (local === "xmlns" && this.attribValue !== this.XMLNS_NAMESPACE) {
2844
+ this.strictFail(`xmlns: prefix must be bound to ${this.XMLNS_NAMESPACE}
2845
+ Actual: ${this.attribValue}`);
2846
+ } else {
2847
+ const tag = this.tag;
2848
+ const parent = this.tags[this.tags.length - 1] || this;
2849
+ if (tag.ns === parent.ns) {
2850
+ tag.ns = Object.create(parent.ns);
2909
2851
  }
2852
+ tag.ns[local] = this.attribValue;
2910
2853
  }
2911
2854
  }
2912
- return { attrStr, val: val2 };
2913
- };
2914
- Builder.prototype.buildAttrPairStr = function(attrName, val2) {
2915
- val2 = this.options.attributeValueProcessor(attrName, "" + val2);
2916
- val2 = this.replaceEntitiesValue(val2);
2917
- if (this.options.suppressBooleanAttributes && val2 === "true") {
2918
- return " " + attrName;
2919
- } else
2920
- return " " + attrName + '="' + val2 + '"';
2855
+ this.attribList.push([this.attribName, this.attribValue]);
2856
+ } else {
2857
+ this.tag.attributes[this.attribName] = this.attribValue;
2858
+ this.emitNode("onattribute", {
2859
+ name: this.attribName,
2860
+ value: this.attribValue
2861
+ });
2862
+ }
2863
+ this.attribName = this.attribValue = "";
2864
+ }
2865
+ newTag() {
2866
+ if (!this.strict)
2867
+ this.tagName = this.tagName[this.looseCase]();
2868
+ const parent = this.tags[this.tags.length - 1] || this;
2869
+ const tag = this.tag = {
2870
+ name: this.tagName,
2871
+ attributes: {}
2921
2872
  };
2922
- function processTextOrObjNode(object, key, level) {
2923
- const result = this.j2x(object, level + 1);
2924
- if (object[this.options.textNodeName] !== void 0 && Object.keys(object).length === 1) {
2925
- return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level);
2873
+ if (this.opt.xmlns) {
2874
+ tag.ns = parent.ns;
2875
+ }
2876
+ this.attribList.length = 0;
2877
+ this.emitNode("onopentagstart", tag);
2878
+ }
2879
+ parseEntity() {
2880
+ let entity = this.entity;
2881
+ const entityLC = entity.toLowerCase();
2882
+ let num = NaN;
2883
+ let numStr = "";
2884
+ if (this.ENTITIES[entity]) {
2885
+ return this.ENTITIES[entity];
2886
+ }
2887
+ if (this.ENTITIES[entityLC]) {
2888
+ return this.ENTITIES[entityLC];
2889
+ }
2890
+ entity = entityLC;
2891
+ if (entity.charAt(0) === "#") {
2892
+ if (entity.charAt(1) === "x") {
2893
+ entity = entity.slice(2);
2894
+ num = parseInt(entity, 16);
2895
+ numStr = num.toString(16);
2926
2896
  } else {
2927
- return this.buildObjectNode(result.val, key, result.attrStr, level);
2897
+ entity = entity.slice(1);
2898
+ num = parseInt(entity, 10);
2899
+ numStr = num.toString(10);
2928
2900
  }
2929
2901
  }
2930
- Builder.prototype.buildObjectNode = function(val2, key, attrStr, level) {
2931
- if (val2 === "") {
2932
- if (key[0] === "?")
2933
- return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
2934
- else {
2935
- return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
2936
- }
2937
- } else {
2938
- let tagEndExp = "</" + key + this.tagEndChar;
2939
- let piClosingChar = "";
2940
- if (key[0] === "?") {
2941
- piClosingChar = "?";
2942
- tagEndExp = "";
2902
+ entity = entity.replace(/^0+/, "");
2903
+ if (isNaN(num) || numStr.toLowerCase() !== entity) {
2904
+ this.strictFail("Invalid character entity");
2905
+ return `&${this.entity};`;
2906
+ }
2907
+ return String.fromCodePoint(num);
2908
+ }
2909
+ beginWhiteSpace(c) {
2910
+ if (c === "<") {
2911
+ this.state = this.S.OPEN_WAKA;
2912
+ this.startTagPosition = this.position;
2913
+ } else if (!SAX.isWhitespace(c)) {
2914
+ this.strictFail("Non-whitespace before first tag.");
2915
+ this.textNode = c;
2916
+ this.state = this.S.TEXT;
2917
+ } else {
2918
+ }
2919
+ }
2920
+ strictFail(message) {
2921
+ if (typeof this !== "object" || !(this instanceof SAXParser)) {
2922
+ throw new Error("bad call to strictFail");
2923
+ }
2924
+ if (this.strict) {
2925
+ this.errorFunction(message);
2926
+ }
2927
+ }
2928
+ textApplyOptions(text) {
2929
+ if (this.opt.trim)
2930
+ text = text.trim();
2931
+ if (this.opt.normalize)
2932
+ text = text.replace(/\s+/g, " ");
2933
+ return text;
2934
+ }
2935
+ emitNode(nodeType, data) {
2936
+ if (this.textNode)
2937
+ this.closeText();
2938
+ this.emit(nodeType, data);
2939
+ }
2940
+ closeText() {
2941
+ this.textNode = this.textApplyOptions(this.textNode);
2942
+ if (this.textNode !== void 0 && this.textNode !== "" && this.textNode !== "undefined") {
2943
+ this.emit("ontext", this.textNode);
2944
+ }
2945
+ this.textNode = "";
2946
+ }
2947
+ checkBufferLength() {
2948
+ const maxAllowed = Math.max(this.opt.MAX_BUFFER_LENGTH, 10);
2949
+ let maxActual = 0;
2950
+ for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
2951
+ const len = this[this.BUFFERS[i]]?.length || 0;
2952
+ if (len > maxAllowed) {
2953
+ switch (this.BUFFERS[i]) {
2954
+ case "textNode":
2955
+ this.closeText();
2956
+ break;
2957
+ case "cdata":
2958
+ this.emitNode("oncdata", this.cdata);
2959
+ this.cdata = "";
2960
+ break;
2961
+ case "script":
2962
+ this.emitNode("onscript", this.script);
2963
+ this.script = "";
2964
+ break;
2965
+ default:
2966
+ this.errorFunction(`Max buffer length exceeded: ${this.BUFFERS[i]}`);
2943
2967
  }
2944
- if (attrStr && val2.indexOf("<") === -1) {
2945
- return this.indentate(level) + "<" + key + attrStr + piClosingChar + ">" + val2 + tagEndExp;
2946
- } else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
2947
- return this.indentate(level) + `<!--${val2}-->` + this.newLine;
2948
- } else {
2949
- return this.indentate(level) + "<" + key + attrStr + piClosingChar + this.tagEndChar + val2 + this.indentate(level) + tagEndExp;
2968
+ }
2969
+ maxActual = Math.max(maxActual, len);
2970
+ }
2971
+ const m = this.opt.MAX_BUFFER_LENGTH - maxActual;
2972
+ this.bufferCheckPosition = m + this.position;
2973
+ }
2974
+ openTag(selfClosing) {
2975
+ if (this.opt.xmlns) {
2976
+ const tag = this.tag;
2977
+ const qn = SAX.qname(this.tagName);
2978
+ tag.prefix = qn.prefix;
2979
+ tag.local = qn.local;
2980
+ tag.uri = tag.ns[qn.prefix] || "";
2981
+ if (tag.prefix && !tag.uri) {
2982
+ this.strictFail(`Unbound namespace prefix: ${JSON.stringify(this.tagName)}`);
2983
+ tag.uri = qn.prefix;
2984
+ }
2985
+ const parent = this.tags[this.tags.length - 1] || this;
2986
+ if (tag.ns && parent.ns !== tag.ns) {
2987
+ const that = this;
2988
+ Object.keys(tag.ns).forEach((p) => {
2989
+ that.emitNode("onopennamespace", {
2990
+ prefix: p,
2991
+ uri: tag.ns[p]
2992
+ });
2993
+ });
2994
+ }
2995
+ for (let i = 0, l = this.attribList.length; i < l; i++) {
2996
+ const nv = this.attribList[i];
2997
+ const name = nv[0];
2998
+ const value = nv[1];
2999
+ const qualName = SAX.qname(name, true);
3000
+ const prefix = qualName.prefix;
3001
+ const local = qualName.local;
3002
+ const uri = prefix === "" ? "" : tag.ns[prefix] || "";
3003
+ const a = {
3004
+ name,
3005
+ value,
3006
+ prefix,
3007
+ local,
3008
+ uri
3009
+ };
3010
+ if (prefix && prefix !== "xmlns" && !uri) {
3011
+ this.strictFail(`Unbound namespace prefix: ${JSON.stringify(prefix)}`);
3012
+ a.uri = prefix;
2950
3013
  }
3014
+ this.tag.attributes[name] = a;
3015
+ this.emitNode("onattribute", a);
2951
3016
  }
2952
- };
2953
- Builder.prototype.closeTag = function(key) {
2954
- let closeTag = "";
2955
- if (this.options.unpairedTags.indexOf(key) !== -1) {
2956
- if (!this.options.suppressUnpairedNode)
2957
- closeTag = "/";
2958
- } else if (this.options.suppressEmptyNode) {
2959
- closeTag = "/";
3017
+ this.attribList.length = 0;
3018
+ }
3019
+ this.tag.isSelfClosing = Boolean(selfClosing);
3020
+ this.sawRoot = true;
3021
+ this.tags.push(this.tag);
3022
+ this.emitNode("onopentag", this.tag);
3023
+ if (!selfClosing) {
3024
+ if (!this.noscript && this.tagName.toLowerCase() === "script") {
3025
+ this.state = this.S.SCRIPT;
2960
3026
  } else {
2961
- closeTag = `></${key}`;
3027
+ this.state = this.S.TEXT;
2962
3028
  }
2963
- return closeTag;
2964
- };
2965
- Builder.prototype.buildTextValNode = function(val2, key, attrStr, level) {
2966
- if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
2967
- return this.indentate(level) + `<![CDATA[${val2}]]>` + this.newLine;
2968
- } else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
2969
- return this.indentate(level) + `<!--${val2}-->` + this.newLine;
2970
- } else if (key[0] === "?") {
2971
- return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
3029
+ this.tag = null;
3030
+ this.tagName = "";
3031
+ }
3032
+ this.attribName = this.attribValue = "";
3033
+ this.attribList.length = 0;
3034
+ }
3035
+ closeTag() {
3036
+ if (!this.tagName) {
3037
+ this.strictFail("Weird empty close tag.");
3038
+ this.textNode += "</>";
3039
+ this.state = this.S.TEXT;
3040
+ return;
3041
+ }
3042
+ if (this.script) {
3043
+ if (this.tagName !== "script") {
3044
+ this.script += `</${this.tagName}>`;
3045
+ this.tagName = "";
3046
+ this.state = this.S.SCRIPT;
3047
+ return;
3048
+ }
3049
+ this.emitNode("onscript", this.script);
3050
+ this.script = "";
3051
+ }
3052
+ let t = this.tags.length;
3053
+ let tagName = this.tagName;
3054
+ if (!this.strict) {
3055
+ tagName = tagName[this.looseCase]();
3056
+ }
3057
+ while (t--) {
3058
+ const close = this.tags[t];
3059
+ if (close.name !== tagName) {
3060
+ this.strictFail("Unexpected close tag");
2972
3061
  } else {
2973
- let textValue = this.options.tagValueProcessor(key, val2);
2974
- textValue = this.replaceEntitiesValue(textValue);
2975
- if (textValue === "") {
2976
- return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
2977
- } else {
2978
- return this.indentate(level) + "<" + key + attrStr + ">" + textValue + "</" + key + this.tagEndChar;
2979
- }
3062
+ break;
2980
3063
  }
2981
- };
2982
- Builder.prototype.replaceEntitiesValue = function(textValue) {
2983
- if (textValue && textValue.length > 0 && this.options.processEntities) {
2984
- for (let i = 0; i < this.options.entities.length; i++) {
2985
- const entity = this.options.entities[i];
2986
- textValue = textValue.replace(entity.regex, entity.val);
2987
- }
3064
+ }
3065
+ if (t < 0) {
3066
+ this.strictFail(`Unmatched closing tag: ${this.tagName}`);
3067
+ this.textNode += `</${this.tagName}>`;
3068
+ this.state = this.S.TEXT;
3069
+ return;
3070
+ }
3071
+ this.tagName = tagName;
3072
+ let s = this.tags.length;
3073
+ while (s-- > t) {
3074
+ const tag = this.tag = this.tags.pop();
3075
+ this.tagName = this.tag.name;
3076
+ this.emitNode("onclosetag", this.tagName);
3077
+ const x = {};
3078
+ for (const i in tag.ns) {
3079
+ if (tag.ns.hasOwnProperty(i)) {
3080
+ x[i] = tag.ns[i];
3081
+ }
3082
+ }
3083
+ const parent = this.tags[this.tags.length - 1] || this;
3084
+ if (this.opt.xmlns && tag.ns !== parent.ns) {
3085
+ const that = this;
3086
+ Object.keys(tag.ns).forEach((p) => {
3087
+ const n = tag.ns[p];
3088
+ that.emitNode("onclosenamespace", {
3089
+ prefix: p,
3090
+ uri: n
3091
+ });
3092
+ });
2988
3093
  }
2989
- return textValue;
3094
+ }
3095
+ if (t === 0)
3096
+ this.closedRoot = true;
3097
+ this.tagName = this.attribValue = this.attribName = "";
3098
+ this.attribList.length = 0;
3099
+ this.state = this.S.TEXT;
3100
+ }
3101
+ };
3102
+ var SAXParser = class extends SAX {
3103
+ opt = DEFAULT_SAX_PARSER_OPTIONS;
3104
+ events = DEFAULT_SAX_EVENTS;
3105
+ constructor(opt) {
3106
+ super();
3107
+ this.clearBuffers();
3108
+ this.opt = opt = {
3109
+ ...this.opt,
3110
+ ...opt
2990
3111
  };
2991
- function indentate(level) {
2992
- return this.options.indentBy.repeat(level);
3112
+ this.events = {
3113
+ ...this.events,
3114
+ ...opt
3115
+ };
3116
+ this.q = this.c = "";
3117
+ this.opt.lowercase = this.opt.lowercase || this.opt.lowercasetags;
3118
+ this.bufferCheckPosition = this.opt.MAX_BUFFER_LENGTH;
3119
+ this.looseCase = this.opt.lowercase ? "toLowerCase" : "toUpperCase";
3120
+ this.tags = [];
3121
+ this.closed = this.closedRoot = this.sawRoot = false;
3122
+ this.tag = this.error = null;
3123
+ this.strict = Boolean(this.opt.strict);
3124
+ this.noscript = Boolean(this.opt.strict || this.opt.noscript);
3125
+ this.state = this.S.BEGIN;
3126
+ this.strictEntities = this.opt.strictEntities;
3127
+ this.ENTITIES = this.strictEntities ? Object.create(this.XML_ENTITIES) : Object.create(this.ENTITIES);
3128
+ this.attribList = [];
3129
+ if (this.opt.xmlns) {
3130
+ this.ns = Object.create(this.rootNS);
2993
3131
  }
2994
- function isAttribute(name) {
2995
- if (name.startsWith(this.options.attributeNamePrefix)) {
2996
- return name.substr(this.attrPrefixLen);
2997
- } else {
2998
- return false;
2999
- }
3132
+ this.trackPosition = this.opt.position !== false;
3133
+ if (this.trackPosition) {
3134
+ this.position = this.line = this.column = 0;
3000
3135
  }
3001
- module.exports = Builder;
3136
+ this.emit("onready");
3002
3137
  }
3003
- });
3138
+ resume() {
3139
+ this.error = null;
3140
+ return this;
3141
+ }
3142
+ close() {
3143
+ return this.write(null);
3144
+ }
3145
+ flush() {
3146
+ this.flushBuffers();
3147
+ }
3148
+ };
3149
+ __publicField(SAXParser, "ENTITIES", ENTITIES);
3004
3150
 
3005
- // ../../node_modules/fast-xml-parser/src/fxp.js
3006
- var require_fxp = __commonJS({
3007
- "../../node_modules/fast-xml-parser/src/fxp.js"(exports, module) {
3008
- "use strict";
3009
- var validator = require_validator();
3010
- var XMLParser = require_XMLParser();
3011
- var XMLBuilder = require_json2xml();
3012
- module.exports = {
3013
- XMLParser,
3014
- XMLValidator: validator,
3015
- XMLBuilder
3016
- };
3151
+ // src/lib/xml-utils/uncapitalize.ts
3152
+ function uncapitalize(str) {
3153
+ return typeof str === "string" ? str.charAt(0).toLowerCase() + str.slice(1) : str;
3154
+ }
3155
+ function uncapitalizeKeys(object) {
3156
+ if (Array.isArray(object)) {
3157
+ return object.map((element) => uncapitalizeKeys(element));
3017
3158
  }
3018
- });
3159
+ if (object && typeof object === "object") {
3160
+ const newObject = {};
3161
+ for (const [key, value] of Object.entries(object)) {
3162
+ newObject[uncapitalize(key)] = uncapitalizeKeys(value);
3163
+ }
3164
+ return newObject;
3165
+ }
3166
+ return object;
3167
+ }
3019
3168
 
3020
3169
  // src/lib/parsers/parse-xml.ts
3170
+ var import_fast_xml_parser = __toESM(require_fxp(), 1);
3021
3171
  function parseXMLSync(text, options) {
3022
3172
  if (options?._parser && options._parser !== "fast-xml-parser") {
3023
3173
  throw new Error(options?._parser);
3024
3174
  }
3025
3175
  const fastXMLOptions = {
3176
+ // Default FastXML options
3177
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#allowbooleanattributes
3026
3178
  allowBooleanAttributes: true,
3179
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#ignoredeclaration
3027
3180
  ignoreDeclaration: true,
3181
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#removensprefix
3028
3182
  removeNSPrefix: options?.removeNSPrefix,
3183
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#textnodename
3029
3184
  textNodeName: options?.textNodeName,
3185
+ // Let's application specify keys that are always arrays
3030
3186
  isArray: (name, jpath, isLeafNode, isAttribute) => {
3031
3187
  const array = Boolean(options?.arrayPaths?.some((path) => jpath === path));
3032
3188
  return array;
3033
3189
  },
3190
+ // Application overrides
3034
3191
  ...options?._fastXML
3035
3192
  };
3036
3193
  const xml = fastParseXML(text, fastXMLOptions);
@@ -3045,56 +3202,48 @@ Actual: ${this.attribValue}`);
3045
3202
  const parsedXML = parser.parse(text);
3046
3203
  return parsedXML;
3047
3204
  }
3048
- var import_fast_xml_parser;
3049
- var init_parse_xml = __esm({
3050
- "src/lib/parsers/parse-xml.ts"() {
3051
- init_uncapitalize();
3052
- import_fast_xml_parser = __toModule(require_fxp());
3053
- }
3054
- });
3055
3205
 
3056
3206
  // src/xml-loader.ts
3207
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3208
+ var XMLLoader = {
3209
+ name: "XML",
3210
+ id: "xml",
3211
+ module: "xml",
3212
+ version: VERSION,
3213
+ worker: false,
3214
+ extensions: ["xml"],
3215
+ mimeTypes: ["application/xml", "text/xml"],
3216
+ testText: testXMLFile,
3217
+ options: {
3218
+ xml: {
3219
+ _parser: "fast-xml-parser",
3220
+ uncapitalizeKeys: false,
3221
+ removeNSPrefix: false,
3222
+ textNodeName: "value",
3223
+ arrayPaths: []
3224
+ }
3225
+ },
3226
+ parse: async (arrayBuffer, options) => parseXMLSync(new TextDecoder().decode(arrayBuffer), {
3227
+ ...XMLLoader.options.xml,
3228
+ ...options?.xml
3229
+ }),
3230
+ parseTextSync: (text, options) => parseXMLSync(text, {
3231
+ ...XMLLoader.options.xml,
3232
+ ...options?.xml
3233
+ })
3234
+ };
3057
3235
  function testXMLFile(text) {
3058
3236
  return text.startsWith("<?xml");
3059
3237
  }
3060
- var VERSION, XMLLoader;
3061
- var init_xml_loader = __esm({
3062
- "src/xml-loader.ts"() {
3063
- init_parse_xml();
3064
- VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3065
- XMLLoader = {
3066
- name: "XML",
3067
- id: "xml",
3068
- module: "xml",
3069
- version: VERSION,
3070
- worker: false,
3071
- extensions: ["xml"],
3072
- mimeTypes: ["application/xml", "text/xml"],
3073
- testText: testXMLFile,
3074
- options: {
3075
- xml: {
3076
- _parser: "fast-xml-parser",
3077
- uncapitalizeKeys: false,
3078
- removeNSPrefix: false,
3079
- textNodeName: "value",
3080
- arrayPaths: []
3081
- }
3082
- },
3083
- parse: async (arrayBuffer, options) => parseXMLSync(new TextDecoder().decode(arrayBuffer), {
3084
- ...XMLLoader.options.xml,
3085
- ...options?.xml
3086
- }),
3087
- parseTextSync: (text, options) => parseXMLSync(text, { ...XMLLoader.options.xml, ...options?.xml })
3088
- };
3089
- }
3090
- });
3091
3238
 
3092
3239
  // ../loader-utils/src/lib/option-utils/merge-loader-options.ts
3093
3240
  function mergeLoaderOptions(baseOptions, newOptions) {
3094
3241
  return mergeOptionsRecursively(baseOptions || {}, newOptions);
3095
3242
  }
3096
3243
  function mergeOptionsRecursively(baseOptions, newOptions) {
3097
- const options = { ...baseOptions };
3244
+ const options = {
3245
+ ...baseOptions
3246
+ };
3098
3247
  for (const [key, newValue] of Object.entries(newOptions)) {
3099
3248
  if (newValue && typeof newValue === "object" && !Array.isArray(newValue)) {
3100
3249
  options[key] = mergeOptionsRecursively(options[key] || {}, newOptions[key]);
@@ -3104,19 +3253,18 @@ Actual: ${this.attribValue}`);
3104
3253
  }
3105
3254
  return options;
3106
3255
  }
3107
- var init_merge_loader_options = __esm({
3108
- "../loader-utils/src/lib/option-utils/merge-loader-options.ts"() {
3109
- }
3110
- });
3111
-
3112
- // ../loader-utils/src/index.ts
3113
- var init_src = __esm({
3114
- "../loader-utils/src/index.ts"() {
3115
- init_merge_loader_options();
3116
- }
3117
- });
3118
3256
 
3119
3257
  // src/html-loader.ts
3258
+ var HTMLLoader = {
3259
+ ...XMLLoader,
3260
+ name: "HTML",
3261
+ id: "html",
3262
+ extensions: ["html", "htm"],
3263
+ mimeTypes: ["text/html"],
3264
+ testText: testHTMLFile,
3265
+ parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
3266
+ parseTextSync: (text, options) => parseTextSync(text, options)
3267
+ };
3120
3268
  function testHTMLFile(text) {
3121
3269
  return text.startsWith("<html");
3122
3270
  }
@@ -3131,23 +3279,6 @@ Actual: ${this.attribValue}`);
3131
3279
  });
3132
3280
  return XMLLoader.parseTextSync?.(text, options);
3133
3281
  }
3134
- var HTMLLoader;
3135
- var init_html_loader = __esm({
3136
- "src/html-loader.ts"() {
3137
- init_src();
3138
- init_xml_loader();
3139
- HTMLLoader = {
3140
- ...XMLLoader,
3141
- name: "HTML",
3142
- id: "html",
3143
- extensions: ["html", "htm"],
3144
- mimeTypes: ["text/html"],
3145
- testText: testHTMLFile,
3146
- parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
3147
- parseTextSync: (text, options) => parseTextSync(text, options)
3148
- };
3149
- }
3150
- });
3151
3282
 
3152
3283
  // src/lib/xml-utils/xml-utils.ts
3153
3284
  function convertXMLValueToArray(xmlValue) {
@@ -3164,39 +3295,7 @@ Actual: ${this.attribValue}`);
3164
3295
  function convertXMLFieldToArrayInPlace(xml, key) {
3165
3296
  xml[key] = convertXMLValueToArray(xml[key]);
3166
3297
  }
3167
- var init_xml_utils = __esm({
3168
- "src/lib/xml-utils/xml-utils.ts"() {
3169
- }
3170
- });
3171
-
3172
- // src/index.ts
3173
- var src_exports = {};
3174
- __export(src_exports, {
3175
- HTMLLoader: () => HTMLLoader,
3176
- SAXParser: () => SAXParser,
3177
- XMLLoader: () => XMLLoader,
3178
- _uncapitalize: () => uncapitalize,
3179
- _uncapitalizeKeys: () => uncapitalizeKeys,
3180
- convertXMLFieldToArrayInPlace: () => convertXMLFieldToArrayInPlace,
3181
- convertXMLValueToArray: () => convertXMLValueToArray
3182
- });
3183
- var init_src2 = __esm({
3184
- "src/index.ts"() {
3185
- init_xml_loader();
3186
- init_html_loader();
3187
- init_sax();
3188
- init_xml_utils();
3189
- init_uncapitalize();
3190
- }
3191
- });
3192
-
3193
- // src/bundle.ts
3194
- var require_bundle = __commonJS({
3195
- "src/bundle.ts"(exports, module) {
3196
- var moduleExports = (init_src2(), src_exports);
3197
- globalThis.loaders = globalThis.loaders || {};
3198
- module.exports = Object.assign(globalThis.loaders, moduleExports);
3199
- }
3200
- });
3201
- require_bundle();
3298
+ return __toCommonJS(src_exports);
3202
3299
  })();
3300
+ return __exports__;
3301
+ });