@loaders.gl/xml 4.2.0-alpha.4 → 4.2.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dist.dev.js CHANGED
@@ -2,8 +2,8 @@
2
2
  if (typeof exports === 'object' && typeof module === 'object')
3
3
  module.exports = factory();
4
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 () {
5
+ else if (typeof exports === 'object') exports['loaders'] = factory();
6
+ else root['loaders'] = factory();})(globalThis, function () {
7
7
  "use strict";
8
8
  var __exports__ = (() => {
9
9
  var __create = Object.create;
@@ -12,7 +12,6 @@ var __exports__ = (() => {
12
12
  var __getOwnPropNames = Object.getOwnPropertyNames;
13
13
  var __getProtoOf = Object.getPrototypeOf;
14
14
  var __hasOwnProp = Object.prototype.hasOwnProperty;
15
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
16
15
  var __commonJS = (cb, mod) => function __require() {
17
16
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
18
17
  };
@@ -28,6 +27,7 @@ var __exports__ = (() => {
28
27
  }
29
28
  return to;
30
29
  };
30
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
31
31
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
32
32
  // If the importer is in node compatibility mode or this is not an ESM
33
33
  // file that has been converted to a CommonJS file using a Babel-
@@ -37,10 +37,13 @@ var __exports__ = (() => {
37
37
  mod
38
38
  ));
39
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;
43
- };
40
+
41
+ // external-global-plugin:@loaders.gl/core
42
+ var require_core = __commonJS({
43
+ "external-global-plugin:@loaders.gl/core"(exports, module) {
44
+ module.exports = globalThis.loaders;
45
+ }
46
+ });
44
47
 
45
48
  // ../../node_modules/fast-xml-parser/src/util.js
46
49
  var require_util = __commonJS({
@@ -108,6 +111,7 @@ var __exports__ = (() => {
108
111
  var util = require_util();
109
112
  var defaultOptions = {
110
113
  allowBooleanAttributes: false,
114
+ //A tag can have attributes without any value
111
115
  unpairedTags: []
112
116
  };
113
117
  exports.validate = function(xmlData, options) {
@@ -178,7 +182,11 @@ var __exports__ = (() => {
178
182
  const otg = tags.pop();
179
183
  if (tagName !== otg.tagName) {
180
184
  let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
181
- return getErrorObject("InvalidTag", "Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.", getLineNumberForPosition(xmlData, tagStartPos));
185
+ return getErrorObject(
186
+ "InvalidTag",
187
+ "Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.",
188
+ getLineNumberForPosition(xmlData, tagStartPos)
189
+ );
182
190
  }
183
191
  if (tags.length == 0) {
184
192
  reachedRoot = true;
@@ -193,10 +201,7 @@ var __exports__ = (() => {
193
201
  return getErrorObject("InvalidXml", "Multiple possible root nodes found.", getLineNumberForPosition(xmlData, i));
194
202
  } else if (options.unpairedTags.indexOf(tagName) !== -1) {
195
203
  } else {
196
- tags.push({
197
- tagName,
198
- tagStartPos
199
- });
204
+ tags.push({ tagName, tagStartPos });
200
205
  }
201
206
  tagFound = true;
202
207
  }
@@ -240,10 +245,7 @@ var __exports__ = (() => {
240
245
  } else if (tags.length == 1) {
241
246
  return getErrorObject("InvalidTag", "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
242
247
  } else if (tags.length > 0) {
243
- return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t) => t.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", {
244
- line: 1,
245
- col: 1
246
- });
248
+ return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t) => t.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", { line: 1, col: 1 });
247
249
  }
248
250
  return true;
249
251
  };
@@ -404,6 +406,7 @@ var __exports__ = (() => {
404
406
  const lines = xmlData.substring(0, index).split(/\r?\n/);
405
407
  return {
406
408
  line: lines.length,
409
+ // column number is last line's length + 1, because column numbering starts at 1:
407
410
  col: lines[lines.length - 1].length + 1
408
411
  };
409
412
  }
@@ -423,10 +426,14 @@ var __exports__ = (() => {
423
426
  textNodeName: "#text",
424
427
  ignoreAttributes: true,
425
428
  removeNSPrefix: false,
429
+ // remove NS from tag name or attribute name if true
426
430
  allowBooleanAttributes: false,
431
+ //a tag can have attributes without any value
432
+ //ignoreRootElement : false,
427
433
  parseTagValue: true,
428
434
  parseAttributeValue: false,
429
435
  trimValues: true,
436
+ //Trim string values of tag and attributes
430
437
  cdataPropName: false,
431
438
  numberParseOptions: {
432
439
  hex: true,
@@ -440,6 +447,7 @@ var __exports__ = (() => {
440
447
  return val2;
441
448
  },
442
449
  stopNodes: [],
450
+ //nested tags will not be parsed even for errors
443
451
  alwaysCreateTextNode: false,
444
452
  isArray: () => false,
445
453
  commentPropName: false,
@@ -453,6 +461,7 @@ var __exports__ = (() => {
453
461
  updateTag: function(tagName, jPath, attrs) {
454
462
  return tagName;
455
463
  }
464
+ // skipEmptyListItem: false
456
465
  };
457
466
  var buildOptions = function(options) {
458
467
  return Object.assign({}, defaultOptions, options);
@@ -475,22 +484,15 @@ var __exports__ = (() => {
475
484
  add(key, val2) {
476
485
  if (key === "__proto__")
477
486
  key = "#__proto__";
478
- this.child.push({
479
- [key]: val2
480
- });
487
+ this.child.push({ [key]: val2 });
481
488
  }
482
489
  addChild(node) {
483
490
  if (node.tagname === "__proto__")
484
491
  node.tagname = "#__proto__";
485
492
  if (node[":@"] && Object.keys(node[":@"]).length > 0) {
486
- this.child.push({
487
- [node.tagname]: node.child,
488
- [":@"]: node[":@"]
489
- });
493
+ this.child.push({ [node.tagname]: node.child, [":@"]: node[":@"] });
490
494
  } else {
491
- this.child.push({
492
- [node.tagname]: node.child
493
- });
495
+ this.child.push({ [node.tagname]: node.child });
494
496
  }
495
497
  }
496
498
  };
@@ -555,14 +557,11 @@ var __exports__ = (() => {
555
557
  } else {
556
558
  throw new Error(`Invalid Tag instead of DOCTYPE`);
557
559
  }
558
- return {
559
- entities,
560
- i
561
- };
560
+ return { entities, i };
562
561
  }
563
562
  function readEntityExp(xmlData, i) {
564
563
  let entityName2 = "";
565
- for (; i < xmlData.length && xmlData[i] !== "'" && xmlData[i] !== '"'; i++) {
564
+ for (; i < xmlData.length && (xmlData[i] !== "'" && xmlData[i] !== '"'); i++) {
566
565
  entityName2 += xmlData[i];
567
566
  }
568
567
  entityName2 = entityName2.trim();
@@ -723,60 +722,26 @@ var __exports__ = (() => {
723
722
  this.tagsNodeStack = [];
724
723
  this.docTypeEntities = {};
725
724
  this.lastEntities = {
726
- "apos": {
727
- regex: /&(apos|#39|#x27);/g,
728
- val: "'"
729
- },
730
- "gt": {
731
- regex: /&(gt|#62|#x3E);/g,
732
- val: ">"
733
- },
734
- "lt": {
735
- regex: /&(lt|#60|#x3C);/g,
736
- val: "<"
737
- },
738
- "quot": {
739
- regex: /&(quot|#34|#x22);/g,
740
- val: '"'
741
- }
742
- };
743
- this.ampEntity = {
744
- regex: /&(amp|#38|#x26);/g,
745
- val: "&"
725
+ "apos": { regex: /&(apos|#39|#x27);/g, val: "'" },
726
+ "gt": { regex: /&(gt|#62|#x3E);/g, val: ">" },
727
+ "lt": { regex: /&(lt|#60|#x3C);/g, val: "<" },
728
+ "quot": { regex: /&(quot|#34|#x22);/g, val: '"' }
746
729
  };
730
+ this.ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" };
747
731
  this.htmlEntities = {
748
- "space": {
749
- regex: /&(nbsp|#160);/g,
750
- val: " "
751
- },
752
- "cent": {
753
- regex: /&(cent|#162);/g,
754
- val: "\xA2"
755
- },
756
- "pound": {
757
- regex: /&(pound|#163);/g,
758
- val: "\xA3"
759
- },
760
- "yen": {
761
- regex: /&(yen|#165);/g,
762
- val: "\xA5"
763
- },
764
- "euro": {
765
- regex: /&(euro|#8364);/g,
766
- val: "\u20AC"
767
- },
768
- "copyright": {
769
- regex: /&(copy|#169);/g,
770
- val: "\xA9"
771
- },
772
- "reg": {
773
- regex: /&(reg|#174);/g,
774
- val: "\xAE"
775
- },
776
- "inr": {
777
- regex: /&(inr|#8377);/g,
778
- val: "\u20B9"
779
- }
732
+ "space": { regex: /&(nbsp|#160);/g, val: " " },
733
+ // "lt" : { regex: /&(lt|#60);/g, val: "<" },
734
+ // "gt" : { regex: /&(gt|#62);/g, val: ">" },
735
+ // "amp" : { regex: /&(amp|#38);/g, val: "&" },
736
+ // "quot" : { regex: /&(quot|#34);/g, val: "\"" },
737
+ // "apos" : { regex: /&(apos|#39);/g, val: "'" },
738
+ "cent": { regex: /&(cent|#162);/g, val: "\xA2" },
739
+ "pound": { regex: /&(pound|#163);/g, val: "\xA3" },
740
+ "yen": { regex: /&(yen|#165);/g, val: "\xA5" },
741
+ "euro": { regex: /&(euro|#8364);/g, val: "\u20AC" },
742
+ "copyright": { regex: /&(copy|#169);/g, val: "\xA9" },
743
+ "reg": { regex: /&(reg|#174);/g, val: "\xAE" },
744
+ "inr": { regex: /&(inr|#8377);/g, val: "\u20B9" }
780
745
  };
781
746
  this.addExternalEntities = addExternalEntities;
782
747
  this.parseXml = parseXml;
@@ -866,7 +831,11 @@ var __exports__ = (() => {
866
831
  } else if (typeof newVal !== typeof oldVal || newVal !== oldVal) {
867
832
  attrs[aName] = newVal;
868
833
  } else {
869
- attrs[aName] = parseValue(oldVal, this.options.parseAttributeValue, this.options.numberParseOptions);
834
+ attrs[aName] = parseValue(
835
+ oldVal,
836
+ this.options.parseAttributeValue,
837
+ this.options.numberParseOptions
838
+ );
870
839
  }
871
840
  } else if (this.options.allowBooleanAttributes) {
872
841
  attrs[aName] = true;
@@ -943,9 +912,7 @@ var __exports__ = (() => {
943
912
  if (this.options.commentPropName) {
944
913
  const comment = xmlData.substring(i + 4, endIndex - 2);
945
914
  textData = this.saveTextToParentTag(textData, currentNode, jPath);
946
- currentNode.add(this.options.commentPropName, [{
947
- [this.options.textNodeName]: comment
948
- }]);
915
+ currentNode.add(this.options.commentPropName, [{ [this.options.textNodeName]: comment }]);
949
916
  }
950
917
  i = endIndex;
951
918
  } else if (xmlData.substr(i + 1, 2) === "!D") {
@@ -957,9 +924,7 @@ var __exports__ = (() => {
957
924
  const tagExp = xmlData.substring(i + 9, closeIndex);
958
925
  textData = this.saveTextToParentTag(textData, currentNode, jPath);
959
926
  if (this.options.cdataPropName) {
960
- currentNode.add(this.options.cdataPropName, [{
961
- [this.options.textNodeName]: tagExp
962
- }]);
927
+ currentNode.add(this.options.cdataPropName, [{ [this.options.textNodeName]: tagExp }]);
963
928
  } else {
964
929
  let val2 = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true);
965
930
  if (val2 == void 0)
@@ -1082,7 +1047,14 @@ var __exports__ = (() => {
1082
1047
  if (textData) {
1083
1048
  if (isLeafNode === void 0)
1084
1049
  isLeafNode = Object.keys(currentNode.child).length === 0;
1085
- textData = this.parseTextData(textData, currentNode.tagname, jPath, false, currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false, isLeafNode);
1050
+ textData = this.parseTextData(
1051
+ textData,
1052
+ currentNode.tagname,
1053
+ jPath,
1054
+ false,
1055
+ currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false,
1056
+ isLeafNode
1057
+ );
1086
1058
  if (textData !== void 0 && textData !== "")
1087
1059
  currentNode.add(this.options.textNodeName, textData);
1088
1060
  textData = "";
@@ -1306,9 +1278,7 @@ var __exports__ = (() => {
1306
1278
  }
1307
1279
  }
1308
1280
  function isLeafTag(obj, options) {
1309
- const {
1310
- textNodeName
1311
- } = options;
1281
+ const { textNodeName } = options;
1312
1282
  const propCount = Object.keys(obj).length;
1313
1283
  if (propCount === 0) {
1314
1284
  return true;
@@ -1325,19 +1295,20 @@ var __exports__ = (() => {
1325
1295
  // ../../node_modules/fast-xml-parser/src/xmlparser/XMLParser.js
1326
1296
  var require_XMLParser = __commonJS({
1327
1297
  "../../node_modules/fast-xml-parser/src/xmlparser/XMLParser.js"(exports, module) {
1328
- var {
1329
- buildOptions
1330
- } = require_OptionsBuilder();
1298
+ var { buildOptions } = require_OptionsBuilder();
1331
1299
  var OrderedObjParser = require_OrderedObjParser();
1332
- var {
1333
- prettify
1334
- } = require_node2json();
1300
+ var { prettify } = require_node2json();
1335
1301
  var validator = require_validator();
1336
1302
  var XMLParser = class {
1337
1303
  constructor(options) {
1338
1304
  this.externalEntities = {};
1339
1305
  this.options = buildOptions(options);
1340
1306
  }
1307
+ /**
1308
+ * Parse XML dats to JS object
1309
+ * @param {string|Buffer} xmlData
1310
+ * @param {boolean|Object} validationOption
1311
+ */
1341
1312
  parse(xmlData, validationOption) {
1342
1313
  if (typeof xmlData === "string") {
1343
1314
  } else if (xmlData.toString) {
@@ -1361,6 +1332,11 @@ var __exports__ = (() => {
1361
1332
  else
1362
1333
  return prettify(orderedResult, this.options);
1363
1334
  }
1335
+ /**
1336
+ * Add Entity which is not by default supported by this library
1337
+ * @param {string} key
1338
+ * @param {string} value
1339
+ */
1364
1340
  addEntity(key, value) {
1365
1341
  if (value.indexOf("&") !== -1) {
1366
1342
  throw new Error("Entity value can't have '&'");
@@ -1530,24 +1506,18 @@ var __exports__ = (() => {
1530
1506
  preserveOrder: false,
1531
1507
  commentPropName: false,
1532
1508
  unpairedTags: [],
1533
- entities: [{
1534
- regex: new RegExp("&", "g"),
1535
- val: "&amp;"
1536
- }, {
1537
- regex: new RegExp(">", "g"),
1538
- val: "&gt;"
1539
- }, {
1540
- regex: new RegExp("<", "g"),
1541
- val: "&lt;"
1542
- }, {
1543
- regex: new RegExp("'", "g"),
1544
- val: "&apos;"
1545
- }, {
1546
- regex: new RegExp('"', "g"),
1547
- val: "&quot;"
1548
- }],
1509
+ entities: [
1510
+ { regex: new RegExp("&", "g"), val: "&amp;" },
1511
+ //it must be on top
1512
+ { regex: new RegExp(">", "g"), val: "&gt;" },
1513
+ { regex: new RegExp("<", "g"), val: "&lt;" },
1514
+ { regex: new RegExp("'", "g"), val: "&apos;" },
1515
+ { regex: new RegExp('"', "g"), val: "&quot;" }
1516
+ ],
1549
1517
  processEntities: true,
1550
1518
  stopNodes: [],
1519
+ // transformTagName: false,
1520
+ // transformAttributeName: false,
1551
1521
  oneListGroup: false
1552
1522
  };
1553
1523
  function Builder(options) {
@@ -1646,10 +1616,7 @@ var __exports__ = (() => {
1646
1616
  }
1647
1617
  }
1648
1618
  }
1649
- return {
1650
- attrStr,
1651
- val: val2
1652
- };
1619
+ return { attrStr, val: val2 };
1653
1620
  };
1654
1621
  Builder.prototype.buildAttrPairStr = function(attrName, val2) {
1655
1622
  val2 = this.options.attributeValueProcessor(attrName, "" + val2);
@@ -1757,9 +1724,9 @@ var __exports__ = (() => {
1757
1724
  }
1758
1725
  });
1759
1726
 
1760
- // src/index.ts
1761
- var src_exports = {};
1762
- __export(src_exports, {
1727
+ // bundle.ts
1728
+ var bundle_exports = {};
1729
+ __export(bundle_exports, {
1763
1730
  HTMLLoader: () => HTMLLoader,
1764
1731
  SAXParser: () => SAXParser,
1765
1732
  XMLLoader: () => XMLLoader,
@@ -1768,6 +1735,7 @@ var __exports__ = (() => {
1768
1735
  convertXMLFieldToArrayInPlace: () => convertXMLFieldToArrayInPlace,
1769
1736
  convertXMLValueToArray: () => convertXMLValueToArray
1770
1737
  });
1738
+ __reExport(bundle_exports, __toESM(require_core(), 1));
1771
1739
 
1772
1740
  // src/sax-ts/sax.ts
1773
1741
  var DEFAULT_SAX_EVENTS = {
@@ -1821,8 +1789,40 @@ var __exports__ = (() => {
1821
1789
  trim: void 0,
1822
1790
  normalize: void 0
1823
1791
  };
1824
- var EVENTS = ["text", "processinginstruction", "sgmldeclaration", "doctype", "comment", "opentagstart", "attribute", "opentag", "closetag", "opencdata", "cdata", "closecdata", "error", "end", "ready", "script", "opennamespace", "closenamespace"];
1825
- var BUFFERS = ["comment", "sgmlDecl", "textNode", "tagName", "doctype", "procInstName", "procInstBody", "entity", "attribName", "attribValue", "cdata", "script"];
1792
+ var EVENTS = [
1793
+ "text",
1794
+ "processinginstruction",
1795
+ "sgmldeclaration",
1796
+ "doctype",
1797
+ "comment",
1798
+ "opentagstart",
1799
+ "attribute",
1800
+ "opentag",
1801
+ "closetag",
1802
+ "opencdata",
1803
+ "cdata",
1804
+ "closecdata",
1805
+ "error",
1806
+ "end",
1807
+ "ready",
1808
+ "script",
1809
+ "opennamespace",
1810
+ "closenamespace"
1811
+ ];
1812
+ var BUFFERS = [
1813
+ "comment",
1814
+ "sgmlDecl",
1815
+ "textNode",
1816
+ "tagName",
1817
+ "doctype",
1818
+ "procInstName",
1819
+ "procInstBody",
1820
+ "entity",
1821
+ "attribName",
1822
+ "attribValue",
1823
+ "cdata",
1824
+ "script"
1825
+ ];
1826
1826
  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]/;
1827
1827
  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-]/;
1828
1828
  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]/;
@@ -2087,85 +2087,125 @@ var __exports__ = (() => {
2087
2087
  ENTITIES[key] = typeof e === "number" ? String.fromCharCode(e) : e;
2088
2088
  });
2089
2089
  var SAX = class {
2090
- EVENTS = EVENTS;
2091
- ENTITIES = {
2092
- ...ENTITIES
2093
- };
2094
- XML_ENTITIES = {
2095
- amp: "&",
2096
- gt: ">",
2097
- lt: "<",
2098
- quot: '"',
2099
- apos: "'"
2100
- };
2101
- S = 0;
2102
- trackPosition = false;
2103
- column = 0;
2104
- line = 0;
2105
- c = "";
2106
- q = "";
2107
- closed = false;
2108
- tags = [];
2109
- looseCase = "";
2110
- closedRoot = false;
2111
- sawRoot = false;
2112
- strict = false;
2113
- noscript = false;
2114
- attribList = [];
2115
- position = 0;
2116
- STATE = {
2117
- BEGIN: this.S++,
2118
- BEGIN_WHITESPACE: this.S++,
2119
- TEXT: this.S++,
2120
- TEXT_ENTITY: this.S++,
2121
- OPEN_WAKA: this.S++,
2122
- SGML_DECL: this.S++,
2123
- SGML_DECL_QUOTED: this.S++,
2124
- DOCTYPE: this.S++,
2125
- DOCTYPE_QUOTED: this.S++,
2126
- DOCTYPE_DTD: this.S++,
2127
- DOCTYPE_DTD_QUOTED: this.S++,
2128
- COMMENT_STARTING: this.S++,
2129
- COMMENT: this.S++,
2130
- COMMENT_ENDING: this.S++,
2131
- COMMENT_ENDED: this.S++,
2132
- CDATA: this.S++,
2133
- CDATA_ENDING: this.S++,
2134
- CDATA_ENDING_2: this.S++,
2135
- PROC_INST: this.S++,
2136
- PROC_INST_BODY: this.S++,
2137
- PROC_INST_ENDING: this.S++,
2138
- OPEN_TAG: this.S++,
2139
- OPEN_TAG_SLASH: this.S++,
2140
- ATTRIB: this.S++,
2141
- ATTRIB_NAME: this.S++,
2142
- ATTRIB_NAME_SAW_WHITE: this.S++,
2143
- ATTRIB_VALUE: this.S++,
2144
- ATTRIB_VALUE_QUOTED: this.S++,
2145
- ATTRIB_VALUE_CLOSED: this.S++,
2146
- ATTRIB_VALUE_UNQUOTED: this.S++,
2147
- ATTRIB_VALUE_ENTITY_Q: this.S++,
2148
- ATTRIB_VALUE_ENTITY_U: this.S++,
2149
- CLOSE_TAG: this.S++,
2150
- CLOSE_TAG_SAW_WHITE: this.S++,
2151
- SCRIPT: this.S++,
2152
- SCRIPT_ENDING: this.S++
2153
- };
2154
- BUFFERS = BUFFERS;
2155
- CDATA = "[CDATA[";
2156
- DOCTYPE = "DOCTYPE";
2157
- XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
2158
- XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
2159
- rootNS = {
2160
- xml: this.XML_NAMESPACE,
2161
- xmlns: this.XMLNS_NAMESPACE
2162
- };
2163
- textNode = "";
2164
- entity = "";
2165
- cdata = "";
2166
- script = "";
2167
- startTagPosition = 0;
2168
2090
  constructor() {
2091
+ this.EVENTS = EVENTS;
2092
+ this.ENTITIES = {
2093
+ // TODO: make it readonly, needed for entity-mega test
2094
+ // amp, gt, lt, quot and apos are resolved to strings instead of numerical
2095
+ // codes, IDK why
2096
+ ...ENTITIES
2097
+ };
2098
+ this.XML_ENTITIES = {
2099
+ amp: "&",
2100
+ gt: ">",
2101
+ lt: "<",
2102
+ quot: '"',
2103
+ apos: "'"
2104
+ };
2105
+ this.S = 0;
2106
+ this.trackPosition = false;
2107
+ this.column = 0;
2108
+ this.line = 0;
2109
+ this.c = "";
2110
+ this.q = "";
2111
+ this.closed = false;
2112
+ this.tags = [];
2113
+ this.looseCase = "";
2114
+ this.closedRoot = false;
2115
+ this.sawRoot = false;
2116
+ this.strict = false;
2117
+ this.noscript = false;
2118
+ this.attribList = [];
2119
+ this.position = 0;
2120
+ this.STATE = {
2121
+ BEGIN: this.S++,
2122
+ // leading byte order mark or whitespace
2123
+ BEGIN_WHITESPACE: this.S++,
2124
+ // leading whitespace
2125
+ TEXT: this.S++,
2126
+ // general stuff
2127
+ TEXT_ENTITY: this.S++,
2128
+ // &amp and such.
2129
+ OPEN_WAKA: this.S++,
2130
+ // <
2131
+ SGML_DECL: this.S++,
2132
+ // <!BLARG
2133
+ SGML_DECL_QUOTED: this.S++,
2134
+ // <!BLARG foo "bar
2135
+ DOCTYPE: this.S++,
2136
+ // <!DOCTYPE
2137
+ DOCTYPE_QUOTED: this.S++,
2138
+ // <!DOCTYPE "//blah
2139
+ DOCTYPE_DTD: this.S++,
2140
+ // <!DOCTYPE "//blah" [ ...
2141
+ DOCTYPE_DTD_QUOTED: this.S++,
2142
+ // <!DOCTYPE "//blah" [ "foo
2143
+ COMMENT_STARTING: this.S++,
2144
+ // <!-
2145
+ COMMENT: this.S++,
2146
+ // <!--
2147
+ COMMENT_ENDING: this.S++,
2148
+ // <!-- blah -
2149
+ COMMENT_ENDED: this.S++,
2150
+ // <!-- blah --
2151
+ CDATA: this.S++,
2152
+ // <![CDATA[ something
2153
+ CDATA_ENDING: this.S++,
2154
+ // ]
2155
+ CDATA_ENDING_2: this.S++,
2156
+ // ]]
2157
+ PROC_INST: this.S++,
2158
+ // <?hi
2159
+ PROC_INST_BODY: this.S++,
2160
+ // <?hi there
2161
+ PROC_INST_ENDING: this.S++,
2162
+ // <?hi "there" ?
2163
+ OPEN_TAG: this.S++,
2164
+ // <strong
2165
+ OPEN_TAG_SLASH: this.S++,
2166
+ // <strong /
2167
+ ATTRIB: this.S++,
2168
+ // <a
2169
+ ATTRIB_NAME: this.S++,
2170
+ // <a foo
2171
+ ATTRIB_NAME_SAW_WHITE: this.S++,
2172
+ // <a foo _
2173
+ ATTRIB_VALUE: this.S++,
2174
+ // <a foo=
2175
+ ATTRIB_VALUE_QUOTED: this.S++,
2176
+ // <a foo="bar
2177
+ ATTRIB_VALUE_CLOSED: this.S++,
2178
+ // <a foo="bar"
2179
+ ATTRIB_VALUE_UNQUOTED: this.S++,
2180
+ // <a foo=bar
2181
+ ATTRIB_VALUE_ENTITY_Q: this.S++,
2182
+ // <foo bar="&quot;"
2183
+ ATTRIB_VALUE_ENTITY_U: this.S++,
2184
+ // <foo bar=&quot
2185
+ CLOSE_TAG: this.S++,
2186
+ // </a
2187
+ CLOSE_TAG_SAW_WHITE: this.S++,
2188
+ // </a >
2189
+ SCRIPT: this.S++,
2190
+ // <script> ...
2191
+ SCRIPT_ENDING: this.S++
2192
+ // <script> ... <
2193
+ };
2194
+ this.BUFFERS = BUFFERS;
2195
+ // private parser: (strict: boolean, opt: any) => SAXParser;
2196
+ this.CDATA = "[CDATA[";
2197
+ this.DOCTYPE = "DOCTYPE";
2198
+ this.XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
2199
+ this.XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
2200
+ this.rootNS = {
2201
+ xml: this.XML_NAMESPACE,
2202
+ xmlns: this.XMLNS_NAMESPACE
2203
+ };
2204
+ this.textNode = "";
2205
+ this.entity = "";
2206
+ this.cdata = "";
2207
+ this.script = "";
2208
+ this.startTagPosition = 0;
2169
2209
  this.S = 0;
2170
2210
  for (const s in this.STATE) {
2171
2211
  if (this.STATE.hasOwnProperty(s)) {
@@ -2205,10 +2245,7 @@ var __exports__ = (() => {
2205
2245
  prefix = "xmlns";
2206
2246
  local = "";
2207
2247
  }
2208
- return {
2209
- prefix,
2210
- local
2211
- };
2248
+ return { prefix, local };
2212
2249
  }
2213
2250
  write(chunk) {
2214
2251
  if (this.error) {
@@ -2766,11 +2803,15 @@ Char: ${this.c}`;
2766
2803
  const local = qn.local;
2767
2804
  if (prefix === "xmlns") {
2768
2805
  if (local === "xml" && this.attribValue !== this.XML_NAMESPACE) {
2769
- this.strictFail(`xml: prefix must be bound to ${this.XML_NAMESPACE}
2770
- Actual: ${this.attribValue}`);
2806
+ this.strictFail(
2807
+ `xml: prefix must be bound to ${this.XML_NAMESPACE}
2808
+ Actual: ${this.attribValue}`
2809
+ );
2771
2810
  } else if (local === "xmlns" && this.attribValue !== this.XMLNS_NAMESPACE) {
2772
- this.strictFail(`xmlns: prefix must be bound to ${this.XMLNS_NAMESPACE}
2773
- Actual: ${this.attribValue}`);
2811
+ this.strictFail(
2812
+ `xmlns: prefix must be bound to ${this.XMLNS_NAMESPACE}
2813
+ Actual: ${this.attribValue}`
2814
+ );
2774
2815
  } else {
2775
2816
  const tag = this.tag;
2776
2817
  const parent = this.tags[this.tags.length - 1] || this;
@@ -2794,10 +2835,7 @@ Actual: ${this.attribValue}`);
2794
2835
  if (!this.strict)
2795
2836
  this.tagName = this.tagName[this.looseCase]();
2796
2837
  const parent = this.tags[this.tags.length - 1] || this;
2797
- const tag = this.tag = {
2798
- name: this.tagName,
2799
- attributes: {}
2800
- };
2838
+ const tag = this.tag = { name: this.tagName, attributes: {} };
2801
2839
  if (this.opt.xmlns) {
2802
2840
  tag.ns = parent.ns;
2803
2841
  }
@@ -3013,10 +3051,7 @@ Actual: ${this.attribValue}`);
3013
3051
  const that = this;
3014
3052
  Object.keys(tag.ns).forEach((p) => {
3015
3053
  const n = tag.ns[p];
3016
- that.emitNode("onclosenamespace", {
3017
- prefix: p,
3018
- uri: n
3019
- });
3054
+ that.emitNode("onclosenamespace", { prefix: p, uri: n });
3020
3055
  });
3021
3056
  }
3022
3057
  }
@@ -3028,19 +3063,13 @@ Actual: ${this.attribValue}`);
3028
3063
  }
3029
3064
  };
3030
3065
  var SAXParser = class extends SAX {
3031
- opt = DEFAULT_SAX_PARSER_OPTIONS;
3032
- events = DEFAULT_SAX_EVENTS;
3033
3066
  constructor(opt) {
3034
3067
  super();
3068
+ this.opt = DEFAULT_SAX_PARSER_OPTIONS;
3069
+ this.events = DEFAULT_SAX_EVENTS;
3035
3070
  this.clearBuffers();
3036
- this.opt = opt = {
3037
- ...this.opt,
3038
- ...opt
3039
- };
3040
- this.events = {
3041
- ...this.events,
3042
- ...opt
3043
- };
3071
+ this.opt = opt = { ...this.opt, ...opt };
3072
+ this.events = { ...this.events, ...opt };
3044
3073
  this.q = this.c = "";
3045
3074
  this.opt.lowercase = this.opt.lowercase || this.opt.lowercasetags;
3046
3075
  this.bufferCheckPosition = this.opt.MAX_BUFFER_LENGTH;
@@ -3074,7 +3103,7 @@ Actual: ${this.attribValue}`);
3074
3103
  this.flushBuffers();
3075
3104
  }
3076
3105
  };
3077
- __publicField(SAXParser, "ENTITIES", ENTITIES);
3106
+ SAXParser.ENTITIES = ENTITIES;
3078
3107
 
3079
3108
  // src/lib/xml-utils/uncapitalize.ts
3080
3109
  function uncapitalize(str) {
@@ -3101,14 +3130,21 @@ Actual: ${this.attribValue}`);
3101
3130
  throw new Error(options?._parser);
3102
3131
  }
3103
3132
  const fastXMLOptions = {
3133
+ // Default FastXML options
3134
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#allowbooleanattributes
3104
3135
  allowBooleanAttributes: true,
3136
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#ignoredeclaration
3105
3137
  ignoreDeclaration: true,
3138
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#removensprefix
3106
3139
  removeNSPrefix: options?.removeNSPrefix,
3140
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#textnodename
3107
3141
  textNodeName: options?.textNodeName,
3142
+ // Let's application specify keys that are always arrays
3108
3143
  isArray: (name, jpath, isLeafNode, isAttribute) => {
3109
3144
  const array = Boolean(options?.arrayPaths?.some((path) => jpath === path));
3110
3145
  return array;
3111
3146
  },
3147
+ // Application overrides
3112
3148
  ...options?._fastXML
3113
3149
  };
3114
3150
  const xml = fastParseXML(text, fastXMLOptions);
@@ -3125,7 +3161,7 @@ Actual: ${this.attribValue}`);
3125
3161
  }
3126
3162
 
3127
3163
  // src/xml-loader.ts
3128
- var VERSION = true ? "4.2.0-alpha.4" : "latest";
3164
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3129
3165
  var XMLLoader = {
3130
3166
  name: "XML",
3131
3167
  id: "xml",
@@ -3148,10 +3184,7 @@ Actual: ${this.attribValue}`);
3148
3184
  ...XMLLoader.options.xml,
3149
3185
  ...options?.xml
3150
3186
  }),
3151
- parseTextSync: (text, options) => parseXMLSync(text, {
3152
- ...XMLLoader.options.xml,
3153
- ...options?.xml
3154
- })
3187
+ parseTextSync: (text, options) => parseXMLSync(text, { ...XMLLoader.options.xml, ...options?.xml })
3155
3188
  };
3156
3189
  function testXMLFile(text) {
3157
3190
  return text.startsWith("<?xml");
@@ -3165,12 +3198,14 @@ Actual: ${this.attribValue}`);
3165
3198
  if (level > 3) {
3166
3199
  return newOptions;
3167
3200
  }
3168
- const options = {
3169
- ...baseOptions
3170
- };
3201
+ const options = { ...baseOptions };
3171
3202
  for (const [key, newValue] of Object.entries(newOptions)) {
3172
3203
  if (newValue && typeof newValue === "object" && !Array.isArray(newValue)) {
3173
- options[key] = mergeOptionsRecursively(options[key] || {}, newOptions[key], level + 1);
3204
+ options[key] = mergeOptionsRecursively(
3205
+ options[key] || {},
3206
+ newOptions[key],
3207
+ level + 1
3208
+ );
3174
3209
  } else {
3175
3210
  options[key] = newOptions[key];
3176
3211
  }
@@ -3219,7 +3254,7 @@ Actual: ${this.attribValue}`);
3219
3254
  function convertXMLFieldToArrayInPlace(xml, key) {
3220
3255
  xml[key] = convertXMLValueToArray(xml[key]);
3221
3256
  }
3222
- return __toCommonJS(src_exports);
3257
+ return __toCommonJS(bundle_exports);
3223
3258
  })();
3224
3259
  return __exports__;
3225
3260
  });