@nextcloud/files 3.10.2 → 3.11.0
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/chunks/{dav-CtqjqS4O.cjs → dav-5fPdvOgP.cjs} +19 -3
- package/dist/chunks/dav-5fPdvOgP.cjs.map +1 -0
- package/dist/chunks/{dav-Co9y-hkg.mjs → dav-DY_3WIBa.mjs} +19 -3
- package/dist/chunks/dav-DY_3WIBa.mjs.map +1 -0
- package/dist/dav.cjs +2 -1
- package/dist/dav.mjs +2 -1
- package/dist/files/node.d.ts +6 -2
- package/dist/index.cjs +1489 -1630
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1488 -1631
- package/dist/index.mjs.map +1 -1
- package/dist/navigation/view.d.ts +5 -0
- package/dist/vendor.LICENSE.txt +11 -11
- package/package.json +55 -50
- package/dist/chunks/dav-Co9y-hkg.mjs.map +0 -1
- package/dist/chunks/dav-CtqjqS4O.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const dav = require("./chunks/dav-
|
|
3
|
+
const dav = require("./chunks/dav-5fPdvOgP.cjs");
|
|
4
4
|
const capabilities = require("@nextcloud/capabilities");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const l10n = require("@nextcloud/l10n");
|
|
7
7
|
const typescriptEventTarget = require("typescript-event-target");
|
|
8
|
+
const require$$1 = require("string_decoder");
|
|
9
|
+
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
10
|
+
const require$$1__default = /* @__PURE__ */ _interopDefault(require$$1);
|
|
8
11
|
var NewMenuEntryCategory = /* @__PURE__ */ ((NewMenuEntryCategory2) => {
|
|
9
12
|
NewMenuEntryCategory2[NewMenuEntryCategory2["UploadFromDevice"] = 0] = "UploadFromDevice";
|
|
10
13
|
NewMenuEntryCategory2[NewMenuEntryCategory2["CreateNew"] = 1] = "CreateNew";
|
|
@@ -485,7 +488,7 @@ function sortNodes(nodes, options = {}) {
|
|
|
485
488
|
// 3: Use sorting mode if NOT basename (to be able to use display name too)
|
|
486
489
|
...sortingOptions.sortingMode !== "basename" ? [(v) => v[sortingOptions.sortingMode]] : [],
|
|
487
490
|
// 4: Use display name if available, fallback to name
|
|
488
|
-
(v) => basename(v.displayname || v.attributes?.displayname || v.basename),
|
|
491
|
+
(v) => basename(v.displayname || v.attributes?.displayname || v.basename || ""),
|
|
489
492
|
// 5: Finally, use basename if all previous sorting methods failed
|
|
490
493
|
(v) => v.basename
|
|
491
494
|
];
|
|
@@ -604,1688 +607,1549 @@ const isValidColumn = function(column) {
|
|
|
604
607
|
function getDefaultExportFromCjs(x) {
|
|
605
608
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
606
609
|
}
|
|
607
|
-
var
|
|
608
|
-
var
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
hasRequiredUtil = 1;
|
|
610
|
+
var sax$1 = {};
|
|
611
|
+
var hasRequiredSax;
|
|
612
|
+
function requireSax() {
|
|
613
|
+
if (hasRequiredSax) return sax$1;
|
|
614
|
+
hasRequiredSax = 1;
|
|
613
615
|
(function(exports2) {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
616
|
+
(function(sax2) {
|
|
617
|
+
sax2.parser = function(strict, opt) {
|
|
618
|
+
return new SAXParser(strict, opt);
|
|
619
|
+
};
|
|
620
|
+
sax2.SAXParser = SAXParser;
|
|
621
|
+
sax2.SAXStream = SAXStream;
|
|
622
|
+
sax2.createStream = createStream;
|
|
623
|
+
sax2.MAX_BUFFER_LENGTH = 64 * 1024;
|
|
624
|
+
var buffers = [
|
|
625
|
+
"comment",
|
|
626
|
+
"sgmlDecl",
|
|
627
|
+
"textNode",
|
|
628
|
+
"tagName",
|
|
629
|
+
"doctype",
|
|
630
|
+
"procInstName",
|
|
631
|
+
"procInstBody",
|
|
632
|
+
"entity",
|
|
633
|
+
"attribName",
|
|
634
|
+
"attribValue",
|
|
635
|
+
"cdata",
|
|
636
|
+
"script"
|
|
637
|
+
];
|
|
638
|
+
sax2.EVENTS = [
|
|
639
|
+
"text",
|
|
640
|
+
"processinginstruction",
|
|
641
|
+
"sgmldeclaration",
|
|
642
|
+
"doctype",
|
|
643
|
+
"comment",
|
|
644
|
+
"opentagstart",
|
|
645
|
+
"attribute",
|
|
646
|
+
"opentag",
|
|
647
|
+
"closetag",
|
|
648
|
+
"opencdata",
|
|
649
|
+
"cdata",
|
|
650
|
+
"closecdata",
|
|
651
|
+
"error",
|
|
652
|
+
"end",
|
|
653
|
+
"ready",
|
|
654
|
+
"script",
|
|
655
|
+
"opennamespace",
|
|
656
|
+
"closenamespace"
|
|
657
|
+
];
|
|
658
|
+
function SAXParser(strict, opt) {
|
|
659
|
+
if (!(this instanceof SAXParser)) {
|
|
660
|
+
return new SAXParser(strict, opt);
|
|
661
|
+
}
|
|
662
|
+
var parser = this;
|
|
663
|
+
clearBuffers(parser);
|
|
664
|
+
parser.q = parser.c = "";
|
|
665
|
+
parser.bufferCheckPosition = sax2.MAX_BUFFER_LENGTH;
|
|
666
|
+
parser.opt = opt || {};
|
|
667
|
+
parser.opt.lowercase = parser.opt.lowercase || parser.opt.lowercasetags;
|
|
668
|
+
parser.looseCase = parser.opt.lowercase ? "toLowerCase" : "toUpperCase";
|
|
669
|
+
parser.tags = [];
|
|
670
|
+
parser.closed = parser.closedRoot = parser.sawRoot = false;
|
|
671
|
+
parser.tag = parser.error = null;
|
|
672
|
+
parser.strict = !!strict;
|
|
673
|
+
parser.noscript = !!(strict || parser.opt.noscript);
|
|
674
|
+
parser.state = S.BEGIN;
|
|
675
|
+
parser.strictEntities = parser.opt.strictEntities;
|
|
676
|
+
parser.ENTITIES = parser.strictEntities ? Object.create(sax2.XML_ENTITIES) : Object.create(sax2.ENTITIES);
|
|
677
|
+
parser.attribList = [];
|
|
678
|
+
if (parser.opt.xmlns) {
|
|
679
|
+
parser.ns = Object.create(rootNS);
|
|
680
|
+
}
|
|
681
|
+
if (parser.opt.unquotedAttributeValues === void 0) {
|
|
682
|
+
parser.opt.unquotedAttributeValues = !strict;
|
|
683
|
+
}
|
|
684
|
+
parser.trackPosition = parser.opt.position !== false;
|
|
685
|
+
if (parser.trackPosition) {
|
|
686
|
+
parser.position = parser.line = parser.column = 0;
|
|
627
687
|
}
|
|
628
|
-
|
|
629
|
-
match = regex.exec(string);
|
|
688
|
+
emit2(parser, "onready");
|
|
630
689
|
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
const match = regexName.exec(string);
|
|
635
|
-
return !(match === null || typeof match === "undefined");
|
|
636
|
-
};
|
|
637
|
-
exports2.isExist = function(v) {
|
|
638
|
-
return typeof v !== "undefined";
|
|
639
|
-
};
|
|
640
|
-
exports2.isEmptyObject = function(obj) {
|
|
641
|
-
return Object.keys(obj).length === 0;
|
|
642
|
-
};
|
|
643
|
-
exports2.merge = function(target, a, arrayMode) {
|
|
644
|
-
if (a) {
|
|
645
|
-
const keys = Object.keys(a);
|
|
646
|
-
const len = keys.length;
|
|
647
|
-
for (let i = 0; i < len; i++) {
|
|
648
|
-
if (arrayMode === "strict") {
|
|
649
|
-
target[keys[i]] = [a[keys[i]]];
|
|
650
|
-
} else {
|
|
651
|
-
target[keys[i]] = a[keys[i]];
|
|
690
|
+
if (!Object.create) {
|
|
691
|
+
Object.create = function(o) {
|
|
692
|
+
function F() {
|
|
652
693
|
}
|
|
653
|
-
|
|
694
|
+
F.prototype = o;
|
|
695
|
+
var newf = new F();
|
|
696
|
+
return newf;
|
|
697
|
+
};
|
|
654
698
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
699
|
+
if (!Object.keys) {
|
|
700
|
+
Object.keys = function(o) {
|
|
701
|
+
var a = [];
|
|
702
|
+
for (var i in o) if (o.hasOwnProperty(i)) a.push(i);
|
|
703
|
+
return a;
|
|
704
|
+
};
|
|
661
705
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
if (hasRequiredValidator) return validator;
|
|
672
|
-
hasRequiredValidator = 1;
|
|
673
|
-
const util2 = requireUtil();
|
|
674
|
-
const defaultOptions = {
|
|
675
|
-
allowBooleanAttributes: false,
|
|
676
|
-
//A tag can have attributes without any value
|
|
677
|
-
unpairedTags: []
|
|
678
|
-
};
|
|
679
|
-
validator.validate = function(xmlData, options) {
|
|
680
|
-
options = Object.assign({}, defaultOptions, options);
|
|
681
|
-
const tags = [];
|
|
682
|
-
let tagFound = false;
|
|
683
|
-
let reachedRoot = false;
|
|
684
|
-
if (xmlData[0] === "\uFEFF") {
|
|
685
|
-
xmlData = xmlData.substr(1);
|
|
686
|
-
}
|
|
687
|
-
for (let i = 0; i < xmlData.length; i++) {
|
|
688
|
-
if (xmlData[i] === "<" && xmlData[i + 1] === "?") {
|
|
689
|
-
i += 2;
|
|
690
|
-
i = readPI(xmlData, i);
|
|
691
|
-
if (i.err) return i;
|
|
692
|
-
} else if (xmlData[i] === "<") {
|
|
693
|
-
let tagStartPos = i;
|
|
694
|
-
i++;
|
|
695
|
-
if (xmlData[i] === "!") {
|
|
696
|
-
i = readCommentAndCDATA(xmlData, i);
|
|
697
|
-
continue;
|
|
698
|
-
} else {
|
|
699
|
-
let closingTag = false;
|
|
700
|
-
if (xmlData[i] === "/") {
|
|
701
|
-
closingTag = true;
|
|
702
|
-
i++;
|
|
703
|
-
}
|
|
704
|
-
let tagName = "";
|
|
705
|
-
for (; i < xmlData.length && xmlData[i] !== ">" && xmlData[i] !== " " && xmlData[i] !== " " && xmlData[i] !== "\n" && xmlData[i] !== "\r"; i++) {
|
|
706
|
-
tagName += xmlData[i];
|
|
707
|
-
}
|
|
708
|
-
tagName = tagName.trim();
|
|
709
|
-
if (tagName[tagName.length - 1] === "/") {
|
|
710
|
-
tagName = tagName.substring(0, tagName.length - 1);
|
|
711
|
-
i--;
|
|
712
|
-
}
|
|
713
|
-
if (!validateTagName(tagName)) {
|
|
714
|
-
let msg;
|
|
715
|
-
if (tagName.trim().length === 0) {
|
|
716
|
-
msg = "Invalid space after '<'.";
|
|
717
|
-
} else {
|
|
718
|
-
msg = "Tag '" + tagName + "' is an invalid name.";
|
|
719
|
-
}
|
|
720
|
-
return getErrorObject("InvalidTag", msg, getLineNumberForPosition(xmlData, i));
|
|
721
|
-
}
|
|
722
|
-
const result = readAttributeStr(xmlData, i);
|
|
723
|
-
if (result === false) {
|
|
724
|
-
return getErrorObject("InvalidAttr", "Attributes for '" + tagName + "' have open quote.", getLineNumberForPosition(xmlData, i));
|
|
725
|
-
}
|
|
726
|
-
let attrStr = result.value;
|
|
727
|
-
i = result.index;
|
|
728
|
-
if (attrStr[attrStr.length - 1] === "/") {
|
|
729
|
-
const attrStrStart = i - attrStr.length;
|
|
730
|
-
attrStr = attrStr.substring(0, attrStr.length - 1);
|
|
731
|
-
const isValid = validateAttributeString(attrStr, options);
|
|
732
|
-
if (isValid === true) {
|
|
733
|
-
tagFound = true;
|
|
734
|
-
} else {
|
|
735
|
-
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line));
|
|
736
|
-
}
|
|
737
|
-
} else if (closingTag) {
|
|
738
|
-
if (!result.tagClosed) {
|
|
739
|
-
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
|
|
740
|
-
} else if (attrStr.trim().length > 0) {
|
|
741
|
-
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
742
|
-
} else if (tags.length === 0) {
|
|
743
|
-
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' has not been opened.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
744
|
-
} else {
|
|
745
|
-
const otg = tags.pop();
|
|
746
|
-
if (tagName !== otg.tagName) {
|
|
747
|
-
let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
|
|
748
|
-
return getErrorObject(
|
|
749
|
-
"InvalidTag",
|
|
750
|
-
"Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.",
|
|
751
|
-
getLineNumberForPosition(xmlData, tagStartPos)
|
|
752
|
-
);
|
|
753
|
-
}
|
|
754
|
-
if (tags.length == 0) {
|
|
755
|
-
reachedRoot = true;
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
} else {
|
|
759
|
-
const isValid = validateAttributeString(attrStr, options);
|
|
760
|
-
if (isValid !== true) {
|
|
761
|
-
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
|
|
762
|
-
}
|
|
763
|
-
if (reachedRoot === true) {
|
|
764
|
-
return getErrorObject("InvalidXml", "Multiple possible root nodes found.", getLineNumberForPosition(xmlData, i));
|
|
765
|
-
} else if (options.unpairedTags.indexOf(tagName) !== -1) ;
|
|
766
|
-
else {
|
|
767
|
-
tags.push({ tagName, tagStartPos });
|
|
768
|
-
}
|
|
769
|
-
tagFound = true;
|
|
770
|
-
}
|
|
771
|
-
for (i++; i < xmlData.length; i++) {
|
|
772
|
-
if (xmlData[i] === "<") {
|
|
773
|
-
if (xmlData[i + 1] === "!") {
|
|
774
|
-
i++;
|
|
775
|
-
i = readCommentAndCDATA(xmlData, i);
|
|
776
|
-
continue;
|
|
777
|
-
} else if (xmlData[i + 1] === "?") {
|
|
778
|
-
i = readPI(xmlData, ++i);
|
|
779
|
-
if (i.err) return i;
|
|
780
|
-
} else {
|
|
706
|
+
function checkBufferLength(parser) {
|
|
707
|
+
var maxAllowed = Math.max(sax2.MAX_BUFFER_LENGTH, 10);
|
|
708
|
+
var maxActual = 0;
|
|
709
|
+
for (var i = 0, l = buffers.length; i < l; i++) {
|
|
710
|
+
var len = parser[buffers[i]].length;
|
|
711
|
+
if (len > maxAllowed) {
|
|
712
|
+
switch (buffers[i]) {
|
|
713
|
+
case "textNode":
|
|
714
|
+
closeText(parser);
|
|
781
715
|
break;
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
716
|
+
case "cdata":
|
|
717
|
+
emitNode(parser, "oncdata", parser.cdata);
|
|
718
|
+
parser.cdata = "";
|
|
719
|
+
break;
|
|
720
|
+
case "script":
|
|
721
|
+
emitNode(parser, "onscript", parser.script);
|
|
722
|
+
parser.script = "";
|
|
723
|
+
break;
|
|
724
|
+
default:
|
|
725
|
+
error(parser, "Max buffer length exceeded: " + buffers[i]);
|
|
792
726
|
}
|
|
793
727
|
}
|
|
794
|
-
|
|
795
|
-
i--;
|
|
796
|
-
}
|
|
728
|
+
maxActual = Math.max(maxActual, len);
|
|
797
729
|
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
continue;
|
|
801
|
-
}
|
|
802
|
-
return getErrorObject("InvalidChar", "char '" + xmlData[i] + "' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
730
|
+
var m = sax2.MAX_BUFFER_LENGTH - maxActual;
|
|
731
|
+
parser.bufferCheckPosition = m + parser.position;
|
|
803
732
|
}
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
} else if (tags.length == 1) {
|
|
808
|
-
return getErrorObject("InvalidTag", "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
|
|
809
|
-
} else if (tags.length > 0) {
|
|
810
|
-
return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t) => t.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", { line: 1, col: 1 });
|
|
811
|
-
}
|
|
812
|
-
return true;
|
|
813
|
-
};
|
|
814
|
-
function isWhiteSpace(char) {
|
|
815
|
-
return char === " " || char === " " || char === "\n" || char === "\r";
|
|
816
|
-
}
|
|
817
|
-
function readPI(xmlData, i) {
|
|
818
|
-
const start = i;
|
|
819
|
-
for (; i < xmlData.length; i++) {
|
|
820
|
-
if (xmlData[i] == "?" || xmlData[i] == " ") {
|
|
821
|
-
const tagname = xmlData.substr(start, i - start);
|
|
822
|
-
if (i > 5 && tagname === "xml") {
|
|
823
|
-
return getErrorObject("InvalidXml", "XML declaration allowed only at the start of the document.", getLineNumberForPosition(xmlData, i));
|
|
824
|
-
} else if (xmlData[i] == "?" && xmlData[i + 1] == ">") {
|
|
825
|
-
i++;
|
|
826
|
-
break;
|
|
827
|
-
} else {
|
|
828
|
-
continue;
|
|
733
|
+
function clearBuffers(parser) {
|
|
734
|
+
for (var i = 0, l = buffers.length; i < l; i++) {
|
|
735
|
+
parser[buffers[i]] = "";
|
|
829
736
|
}
|
|
830
737
|
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
for (i += 3; i < xmlData.length; i++) {
|
|
837
|
-
if (xmlData[i] === "-" && xmlData[i + 1] === "-" && xmlData[i + 2] === ">") {
|
|
838
|
-
i += 2;
|
|
839
|
-
break;
|
|
738
|
+
function flushBuffers(parser) {
|
|
739
|
+
closeText(parser);
|
|
740
|
+
if (parser.cdata !== "") {
|
|
741
|
+
emitNode(parser, "oncdata", parser.cdata);
|
|
742
|
+
parser.cdata = "";
|
|
840
743
|
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
for (i += 8; i < xmlData.length; i++) {
|
|
845
|
-
if (xmlData[i] === "<") {
|
|
846
|
-
angleBracketsCount++;
|
|
847
|
-
} else if (xmlData[i] === ">") {
|
|
848
|
-
angleBracketsCount--;
|
|
849
|
-
if (angleBracketsCount === 0) {
|
|
850
|
-
break;
|
|
851
|
-
}
|
|
744
|
+
if (parser.script !== "") {
|
|
745
|
+
emitNode(parser, "onscript", parser.script);
|
|
746
|
+
parser.script = "";
|
|
852
747
|
}
|
|
853
748
|
}
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
749
|
+
SAXParser.prototype = {
|
|
750
|
+
end: function() {
|
|
751
|
+
end(this);
|
|
752
|
+
},
|
|
753
|
+
write,
|
|
754
|
+
resume: function() {
|
|
755
|
+
this.error = null;
|
|
756
|
+
return this;
|
|
757
|
+
},
|
|
758
|
+
close: function() {
|
|
759
|
+
return this.write(null);
|
|
760
|
+
},
|
|
761
|
+
flush: function() {
|
|
762
|
+
flushBuffers(this);
|
|
859
763
|
}
|
|
764
|
+
};
|
|
765
|
+
var Stream;
|
|
766
|
+
try {
|
|
767
|
+
Stream = require("stream").Stream;
|
|
768
|
+
} catch (ex) {
|
|
769
|
+
Stream = function() {
|
|
770
|
+
};
|
|
860
771
|
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
if (startChar === "") {
|
|
873
|
-
startChar = xmlData[i];
|
|
874
|
-
} else if (startChar !== xmlData[i]) ;
|
|
875
|
-
else {
|
|
876
|
-
startChar = "";
|
|
877
|
-
}
|
|
878
|
-
} else if (xmlData[i] === ">") {
|
|
879
|
-
if (startChar === "") {
|
|
880
|
-
tagClosed = true;
|
|
881
|
-
break;
|
|
772
|
+
if (!Stream) Stream = function() {
|
|
773
|
+
};
|
|
774
|
+
var streamWraps = sax2.EVENTS.filter(function(ev) {
|
|
775
|
+
return ev !== "error" && ev !== "end";
|
|
776
|
+
});
|
|
777
|
+
function createStream(strict, opt) {
|
|
778
|
+
return new SAXStream(strict, opt);
|
|
779
|
+
}
|
|
780
|
+
function SAXStream(strict, opt) {
|
|
781
|
+
if (!(this instanceof SAXStream)) {
|
|
782
|
+
return new SAXStream(strict, opt);
|
|
882
783
|
}
|
|
784
|
+
Stream.apply(this);
|
|
785
|
+
this._parser = new SAXParser(strict, opt);
|
|
786
|
+
this.writable = true;
|
|
787
|
+
this.readable = true;
|
|
788
|
+
var me = this;
|
|
789
|
+
this._parser.onend = function() {
|
|
790
|
+
me.emit("end");
|
|
791
|
+
};
|
|
792
|
+
this._parser.onerror = function(er) {
|
|
793
|
+
me.emit("error", er);
|
|
794
|
+
me._parser.error = null;
|
|
795
|
+
};
|
|
796
|
+
this._decoder = null;
|
|
797
|
+
streamWraps.forEach(function(ev) {
|
|
798
|
+
Object.defineProperty(me, "on" + ev, {
|
|
799
|
+
get: function() {
|
|
800
|
+
return me._parser["on" + ev];
|
|
801
|
+
},
|
|
802
|
+
set: function(h) {
|
|
803
|
+
if (!h) {
|
|
804
|
+
me.removeAllListeners(ev);
|
|
805
|
+
me._parser["on" + ev] = h;
|
|
806
|
+
return h;
|
|
807
|
+
}
|
|
808
|
+
me.on(ev, h);
|
|
809
|
+
},
|
|
810
|
+
enumerable: true,
|
|
811
|
+
configurable: false
|
|
812
|
+
});
|
|
813
|
+
});
|
|
883
814
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
return false;
|
|
888
|
-
}
|
|
889
|
-
return {
|
|
890
|
-
value: attrStr,
|
|
891
|
-
index: i,
|
|
892
|
-
tagClosed
|
|
893
|
-
};
|
|
894
|
-
}
|
|
895
|
-
const validAttrStrRegxp = new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`, "g");
|
|
896
|
-
function validateAttributeString(attrStr, options) {
|
|
897
|
-
const matches = util2.getAllMatches(attrStr, validAttrStrRegxp);
|
|
898
|
-
const attrNames = {};
|
|
899
|
-
for (let i = 0; i < matches.length; i++) {
|
|
900
|
-
if (matches[i][1].length === 0) {
|
|
901
|
-
return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' has no space in starting.", getPositionFromMatch(matches[i]));
|
|
902
|
-
} else if (matches[i][3] !== void 0 && matches[i][4] === void 0) {
|
|
903
|
-
return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' is without value.", getPositionFromMatch(matches[i]));
|
|
904
|
-
} else if (matches[i][3] === void 0 && !options.allowBooleanAttributes) {
|
|
905
|
-
return getErrorObject("InvalidAttr", "boolean attribute '" + matches[i][2] + "' is not allowed.", getPositionFromMatch(matches[i]));
|
|
906
|
-
}
|
|
907
|
-
const attrName = matches[i][2];
|
|
908
|
-
if (!validateAttrName(attrName)) {
|
|
909
|
-
return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i]));
|
|
910
|
-
}
|
|
911
|
-
if (!attrNames.hasOwnProperty(attrName)) {
|
|
912
|
-
attrNames[attrName] = 1;
|
|
913
|
-
} else {
|
|
914
|
-
return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i]));
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
return true;
|
|
918
|
-
}
|
|
919
|
-
function validateNumberAmpersand(xmlData, i) {
|
|
920
|
-
let re2 = /\d/;
|
|
921
|
-
if (xmlData[i] === "x") {
|
|
922
|
-
i++;
|
|
923
|
-
re2 = /[\da-fA-F]/;
|
|
924
|
-
}
|
|
925
|
-
for (; i < xmlData.length; i++) {
|
|
926
|
-
if (xmlData[i] === ";")
|
|
927
|
-
return i;
|
|
928
|
-
if (!xmlData[i].match(re2))
|
|
929
|
-
break;
|
|
930
|
-
}
|
|
931
|
-
return -1;
|
|
932
|
-
}
|
|
933
|
-
function validateAmpersand(xmlData, i) {
|
|
934
|
-
i++;
|
|
935
|
-
if (xmlData[i] === ";")
|
|
936
|
-
return -1;
|
|
937
|
-
if (xmlData[i] === "#") {
|
|
938
|
-
i++;
|
|
939
|
-
return validateNumberAmpersand(xmlData, i);
|
|
940
|
-
}
|
|
941
|
-
let count = 0;
|
|
942
|
-
for (; i < xmlData.length; i++, count++) {
|
|
943
|
-
if (xmlData[i].match(/\w/) && count < 20)
|
|
944
|
-
continue;
|
|
945
|
-
if (xmlData[i] === ";")
|
|
946
|
-
break;
|
|
947
|
-
return -1;
|
|
948
|
-
}
|
|
949
|
-
return i;
|
|
950
|
-
}
|
|
951
|
-
function getErrorObject(code, message, lineNumber) {
|
|
952
|
-
return {
|
|
953
|
-
err: {
|
|
954
|
-
code,
|
|
955
|
-
msg: message,
|
|
956
|
-
line: lineNumber.line || lineNumber,
|
|
957
|
-
col: lineNumber.col
|
|
958
|
-
}
|
|
959
|
-
};
|
|
960
|
-
}
|
|
961
|
-
function validateAttrName(attrName) {
|
|
962
|
-
return util2.isName(attrName);
|
|
963
|
-
}
|
|
964
|
-
function validateTagName(tagname) {
|
|
965
|
-
return util2.isName(tagname);
|
|
966
|
-
}
|
|
967
|
-
function getLineNumberForPosition(xmlData, index) {
|
|
968
|
-
const lines = xmlData.substring(0, index).split(/\r?\n/);
|
|
969
|
-
return {
|
|
970
|
-
line: lines.length,
|
|
971
|
-
// column number is last line's length + 1, because column numbering starts at 1:
|
|
972
|
-
col: lines[lines.length - 1].length + 1
|
|
973
|
-
};
|
|
974
|
-
}
|
|
975
|
-
function getPositionFromMatch(match) {
|
|
976
|
-
return match.startIndex + match[1].length;
|
|
977
|
-
}
|
|
978
|
-
return validator;
|
|
979
|
-
}
|
|
980
|
-
var OptionsBuilder = {};
|
|
981
|
-
var hasRequiredOptionsBuilder;
|
|
982
|
-
function requireOptionsBuilder() {
|
|
983
|
-
if (hasRequiredOptionsBuilder) return OptionsBuilder;
|
|
984
|
-
hasRequiredOptionsBuilder = 1;
|
|
985
|
-
const defaultOptions = {
|
|
986
|
-
preserveOrder: false,
|
|
987
|
-
attributeNamePrefix: "@_",
|
|
988
|
-
attributesGroupName: false,
|
|
989
|
-
textNodeName: "#text",
|
|
990
|
-
ignoreAttributes: true,
|
|
991
|
-
removeNSPrefix: false,
|
|
992
|
-
// remove NS from tag name or attribute name if true
|
|
993
|
-
allowBooleanAttributes: false,
|
|
994
|
-
//a tag can have attributes without any value
|
|
995
|
-
//ignoreRootElement : false,
|
|
996
|
-
parseTagValue: true,
|
|
997
|
-
parseAttributeValue: false,
|
|
998
|
-
trimValues: true,
|
|
999
|
-
//Trim string values of tag and attributes
|
|
1000
|
-
cdataPropName: false,
|
|
1001
|
-
numberParseOptions: {
|
|
1002
|
-
hex: true,
|
|
1003
|
-
leadingZeros: true,
|
|
1004
|
-
eNotation: true
|
|
1005
|
-
},
|
|
1006
|
-
tagValueProcessor: function(tagName, val) {
|
|
1007
|
-
return val;
|
|
1008
|
-
},
|
|
1009
|
-
attributeValueProcessor: function(attrName, val) {
|
|
1010
|
-
return val;
|
|
1011
|
-
},
|
|
1012
|
-
stopNodes: [],
|
|
1013
|
-
//nested tags will not be parsed even for errors
|
|
1014
|
-
alwaysCreateTextNode: false,
|
|
1015
|
-
isArray: () => false,
|
|
1016
|
-
commentPropName: false,
|
|
1017
|
-
unpairedTags: [],
|
|
1018
|
-
processEntities: true,
|
|
1019
|
-
htmlEntities: false,
|
|
1020
|
-
ignoreDeclaration: false,
|
|
1021
|
-
ignorePiTags: false,
|
|
1022
|
-
transformTagName: false,
|
|
1023
|
-
transformAttributeName: false,
|
|
1024
|
-
updateTag: function(tagName, jPath, attrs) {
|
|
1025
|
-
return tagName;
|
|
1026
|
-
}
|
|
1027
|
-
// skipEmptyListItem: false
|
|
1028
|
-
};
|
|
1029
|
-
const buildOptions = function(options) {
|
|
1030
|
-
return Object.assign({}, defaultOptions, options);
|
|
1031
|
-
};
|
|
1032
|
-
OptionsBuilder.buildOptions = buildOptions;
|
|
1033
|
-
OptionsBuilder.defaultOptions = defaultOptions;
|
|
1034
|
-
return OptionsBuilder;
|
|
1035
|
-
}
|
|
1036
|
-
var xmlNode;
|
|
1037
|
-
var hasRequiredXmlNode;
|
|
1038
|
-
function requireXmlNode() {
|
|
1039
|
-
if (hasRequiredXmlNode) return xmlNode;
|
|
1040
|
-
hasRequiredXmlNode = 1;
|
|
1041
|
-
class XmlNode {
|
|
1042
|
-
constructor(tagname) {
|
|
1043
|
-
this.tagname = tagname;
|
|
1044
|
-
this.child = [];
|
|
1045
|
-
this[":@"] = {};
|
|
1046
|
-
}
|
|
1047
|
-
add(key, val) {
|
|
1048
|
-
if (key === "__proto__") key = "#__proto__";
|
|
1049
|
-
this.child.push({ [key]: val });
|
|
1050
|
-
}
|
|
1051
|
-
addChild(node) {
|
|
1052
|
-
if (node.tagname === "__proto__") node.tagname = "#__proto__";
|
|
1053
|
-
if (node[":@"] && Object.keys(node[":@"]).length > 0) {
|
|
1054
|
-
this.child.push({ [node.tagname]: node.child, [":@"]: node[":@"] });
|
|
1055
|
-
} else {
|
|
1056
|
-
this.child.push({ [node.tagname]: node.child });
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
xmlNode = XmlNode;
|
|
1061
|
-
return xmlNode;
|
|
1062
|
-
}
|
|
1063
|
-
var DocTypeReader;
|
|
1064
|
-
var hasRequiredDocTypeReader;
|
|
1065
|
-
function requireDocTypeReader() {
|
|
1066
|
-
if (hasRequiredDocTypeReader) return DocTypeReader;
|
|
1067
|
-
hasRequiredDocTypeReader = 1;
|
|
1068
|
-
const util2 = requireUtil();
|
|
1069
|
-
function readDocType(xmlData, i) {
|
|
1070
|
-
const entities = {};
|
|
1071
|
-
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") {
|
|
1072
|
-
i = i + 9;
|
|
1073
|
-
let angleBracketsCount = 1;
|
|
1074
|
-
let hasBody = false, comment = false;
|
|
1075
|
-
let exp = "";
|
|
1076
|
-
for (; i < xmlData.length; i++) {
|
|
1077
|
-
if (xmlData[i] === "<" && !comment) {
|
|
1078
|
-
if (hasBody && isEntity(xmlData, i)) {
|
|
1079
|
-
i += 7;
|
|
1080
|
-
let entityName, val;
|
|
1081
|
-
[entityName, val, i] = readEntityExp(xmlData, i + 1);
|
|
1082
|
-
if (val.indexOf("&") === -1)
|
|
1083
|
-
entities[validateEntityName(entityName)] = {
|
|
1084
|
-
regx: RegExp(`&${entityName};`, "g"),
|
|
1085
|
-
val
|
|
1086
|
-
};
|
|
1087
|
-
} else if (hasBody && isElement(xmlData, i)) i += 8;
|
|
1088
|
-
else if (hasBody && isAttlist(xmlData, i)) i += 8;
|
|
1089
|
-
else if (hasBody && isNotation(xmlData, i)) i += 9;
|
|
1090
|
-
else comment = true;
|
|
1091
|
-
angleBracketsCount++;
|
|
1092
|
-
exp = "";
|
|
1093
|
-
} else if (xmlData[i] === ">") {
|
|
1094
|
-
if (comment) {
|
|
1095
|
-
if (xmlData[i - 1] === "-" && xmlData[i - 2] === "-") {
|
|
1096
|
-
comment = false;
|
|
1097
|
-
angleBracketsCount--;
|
|
1098
|
-
}
|
|
1099
|
-
} else {
|
|
1100
|
-
angleBracketsCount--;
|
|
1101
|
-
}
|
|
1102
|
-
if (angleBracketsCount === 0) {
|
|
1103
|
-
break;
|
|
1104
|
-
}
|
|
1105
|
-
} else if (xmlData[i] === "[") {
|
|
1106
|
-
hasBody = true;
|
|
1107
|
-
} else {
|
|
1108
|
-
exp += xmlData[i];
|
|
815
|
+
SAXStream.prototype = Object.create(Stream.prototype, {
|
|
816
|
+
constructor: {
|
|
817
|
+
value: SAXStream
|
|
1109
818
|
}
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
}
|
|
1117
|
-
return { entities, i };
|
|
1118
|
-
}
|
|
1119
|
-
function readEntityExp(xmlData, i) {
|
|
1120
|
-
let entityName = "";
|
|
1121
|
-
for (; i < xmlData.length && (xmlData[i] !== "'" && xmlData[i] !== '"'); i++) {
|
|
1122
|
-
entityName += xmlData[i];
|
|
1123
|
-
}
|
|
1124
|
-
entityName = entityName.trim();
|
|
1125
|
-
if (entityName.indexOf(" ") !== -1) throw new Error("External entites are not supported");
|
|
1126
|
-
const startChar = xmlData[i++];
|
|
1127
|
-
let val = "";
|
|
1128
|
-
for (; i < xmlData.length && xmlData[i] !== startChar; i++) {
|
|
1129
|
-
val += xmlData[i];
|
|
1130
|
-
}
|
|
1131
|
-
return [entityName, val, i];
|
|
1132
|
-
}
|
|
1133
|
-
function isEntity(xmlData, i) {
|
|
1134
|
-
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") return true;
|
|
1135
|
-
return false;
|
|
1136
|
-
}
|
|
1137
|
-
function isElement(xmlData, i) {
|
|
1138
|
-
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") return true;
|
|
1139
|
-
return false;
|
|
1140
|
-
}
|
|
1141
|
-
function isAttlist(xmlData, i) {
|
|
1142
|
-
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") return true;
|
|
1143
|
-
return false;
|
|
1144
|
-
}
|
|
1145
|
-
function isNotation(xmlData, i) {
|
|
1146
|
-
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") return true;
|
|
1147
|
-
return false;
|
|
1148
|
-
}
|
|
1149
|
-
function validateEntityName(name) {
|
|
1150
|
-
if (util2.isName(name))
|
|
1151
|
-
return name;
|
|
1152
|
-
else
|
|
1153
|
-
throw new Error(`Invalid entity name ${name}`);
|
|
1154
|
-
}
|
|
1155
|
-
DocTypeReader = readDocType;
|
|
1156
|
-
return DocTypeReader;
|
|
1157
|
-
}
|
|
1158
|
-
var strnum;
|
|
1159
|
-
var hasRequiredStrnum;
|
|
1160
|
-
function requireStrnum() {
|
|
1161
|
-
if (hasRequiredStrnum) return strnum;
|
|
1162
|
-
hasRequiredStrnum = 1;
|
|
1163
|
-
const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
|
|
1164
|
-
const numRegex = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;
|
|
1165
|
-
if (!Number.parseInt && window.parseInt) {
|
|
1166
|
-
Number.parseInt = window.parseInt;
|
|
1167
|
-
}
|
|
1168
|
-
if (!Number.parseFloat && window.parseFloat) {
|
|
1169
|
-
Number.parseFloat = window.parseFloat;
|
|
1170
|
-
}
|
|
1171
|
-
const consider = {
|
|
1172
|
-
hex: true,
|
|
1173
|
-
leadingZeros: true,
|
|
1174
|
-
decimalPoint: ".",
|
|
1175
|
-
eNotation: true
|
|
1176
|
-
//skipLike: /regex/
|
|
1177
|
-
};
|
|
1178
|
-
function toNumber(str, options = {}) {
|
|
1179
|
-
options = Object.assign({}, consider, options);
|
|
1180
|
-
if (!str || typeof str !== "string") return str;
|
|
1181
|
-
let trimmedStr = str.trim();
|
|
1182
|
-
if (options.skipLike !== void 0 && options.skipLike.test(trimmedStr)) return str;
|
|
1183
|
-
else if (options.hex && hexRegex.test(trimmedStr)) {
|
|
1184
|
-
return Number.parseInt(trimmedStr, 16);
|
|
1185
|
-
} else {
|
|
1186
|
-
const match = numRegex.exec(trimmedStr);
|
|
1187
|
-
if (match) {
|
|
1188
|
-
const sign = match[1];
|
|
1189
|
-
const leadingZeros = match[2];
|
|
1190
|
-
let numTrimmedByZeros = trimZeros(match[3]);
|
|
1191
|
-
const eNotation = match[4] || match[6];
|
|
1192
|
-
if (!options.leadingZeros && leadingZeros.length > 0 && sign && trimmedStr[2] !== ".") return str;
|
|
1193
|
-
else if (!options.leadingZeros && leadingZeros.length > 0 && !sign && trimmedStr[1] !== ".") return str;
|
|
1194
|
-
else {
|
|
1195
|
-
const num = Number(trimmedStr);
|
|
1196
|
-
const numStr = "" + num;
|
|
1197
|
-
if (numStr.search(/[eE]/) !== -1) {
|
|
1198
|
-
if (options.eNotation) return num;
|
|
1199
|
-
else return str;
|
|
1200
|
-
} else if (eNotation) {
|
|
1201
|
-
if (options.eNotation) return num;
|
|
1202
|
-
else return str;
|
|
1203
|
-
} else if (trimmedStr.indexOf(".") !== -1) {
|
|
1204
|
-
if (numStr === "0" && numTrimmedByZeros === "") return num;
|
|
1205
|
-
else if (numStr === numTrimmedByZeros) return num;
|
|
1206
|
-
else if (sign && numStr === "-" + numTrimmedByZeros) return num;
|
|
1207
|
-
else return str;
|
|
1208
|
-
}
|
|
1209
|
-
if (leadingZeros) {
|
|
1210
|
-
if (numTrimmedByZeros === numStr) return num;
|
|
1211
|
-
else if (sign + numTrimmedByZeros === numStr) return num;
|
|
1212
|
-
else return str;
|
|
819
|
+
});
|
|
820
|
+
SAXStream.prototype.write = function(data) {
|
|
821
|
+
if (typeof Buffer === "function" && typeof Buffer.isBuffer === "function" && Buffer.isBuffer(data)) {
|
|
822
|
+
if (!this._decoder) {
|
|
823
|
+
var SD = require$$1__default.default.StringDecoder;
|
|
824
|
+
this._decoder = new SD("utf8");
|
|
1213
825
|
}
|
|
1214
|
-
|
|
1215
|
-
else if (trimmedStr === sign + numStr) return num;
|
|
1216
|
-
return str;
|
|
826
|
+
data = this._decoder.write(data);
|
|
1217
827
|
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
numStr = numStr.replace(/0+$/, "");
|
|
1226
|
-
if (numStr === ".") numStr = "0";
|
|
1227
|
-
else if (numStr[0] === ".") numStr = "0" + numStr;
|
|
1228
|
-
else if (numStr[numStr.length - 1] === ".") numStr = numStr.substr(0, numStr.length - 1);
|
|
1229
|
-
return numStr;
|
|
1230
|
-
}
|
|
1231
|
-
return numStr;
|
|
1232
|
-
}
|
|
1233
|
-
strnum = toNumber;
|
|
1234
|
-
return strnum;
|
|
1235
|
-
}
|
|
1236
|
-
var ignoreAttributes;
|
|
1237
|
-
var hasRequiredIgnoreAttributes;
|
|
1238
|
-
function requireIgnoreAttributes() {
|
|
1239
|
-
if (hasRequiredIgnoreAttributes) return ignoreAttributes;
|
|
1240
|
-
hasRequiredIgnoreAttributes = 1;
|
|
1241
|
-
function getIgnoreAttributesFn(ignoreAttributes2) {
|
|
1242
|
-
if (typeof ignoreAttributes2 === "function") {
|
|
1243
|
-
return ignoreAttributes2;
|
|
1244
|
-
}
|
|
1245
|
-
if (Array.isArray(ignoreAttributes2)) {
|
|
1246
|
-
return (attrName) => {
|
|
1247
|
-
for (const pattern of ignoreAttributes2) {
|
|
1248
|
-
if (typeof pattern === "string" && attrName === pattern) {
|
|
1249
|
-
return true;
|
|
1250
|
-
}
|
|
1251
|
-
if (pattern instanceof RegExp && pattern.test(attrName)) {
|
|
1252
|
-
return true;
|
|
1253
|
-
}
|
|
828
|
+
this._parser.write(data.toString());
|
|
829
|
+
this.emit("data", data);
|
|
830
|
+
return true;
|
|
831
|
+
};
|
|
832
|
+
SAXStream.prototype.end = function(chunk) {
|
|
833
|
+
if (chunk && chunk.length) {
|
|
834
|
+
this.write(chunk);
|
|
1254
835
|
}
|
|
836
|
+
this._parser.end();
|
|
837
|
+
return true;
|
|
1255
838
|
};
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
hasRequiredOrderedObjParser = 1;
|
|
1267
|
-
const util2 = requireUtil();
|
|
1268
|
-
const xmlNode2 = requireXmlNode();
|
|
1269
|
-
const readDocType = requireDocTypeReader();
|
|
1270
|
-
const toNumber = requireStrnum();
|
|
1271
|
-
const getIgnoreAttributesFn = requireIgnoreAttributes();
|
|
1272
|
-
class OrderedObjParser {
|
|
1273
|
-
constructor(options) {
|
|
1274
|
-
this.options = options;
|
|
1275
|
-
this.currentNode = null;
|
|
1276
|
-
this.tagsNodeStack = [];
|
|
1277
|
-
this.docTypeEntities = {};
|
|
1278
|
-
this.lastEntities = {
|
|
1279
|
-
"apos": { regex: /&(apos|#39|#x27);/g, val: "'" },
|
|
1280
|
-
"gt": { regex: /&(gt|#62|#x3E);/g, val: ">" },
|
|
1281
|
-
"lt": { regex: /&(lt|#60|#x3C);/g, val: "<" },
|
|
1282
|
-
"quot": { regex: /&(quot|#34|#x22);/g, val: '"' }
|
|
839
|
+
SAXStream.prototype.on = function(ev, handler) {
|
|
840
|
+
var me = this;
|
|
841
|
+
if (!me._parser["on" + ev] && streamWraps.indexOf(ev) !== -1) {
|
|
842
|
+
me._parser["on" + ev] = function() {
|
|
843
|
+
var args = arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments);
|
|
844
|
+
args.splice(0, 0, ev);
|
|
845
|
+
me.emit.apply(me, args);
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
return Stream.prototype.on.call(me, ev, handler);
|
|
1283
849
|
};
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
"
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
"
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
850
|
+
var CDATA = "[CDATA[";
|
|
851
|
+
var DOCTYPE = "DOCTYPE";
|
|
852
|
+
var XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
|
|
853
|
+
var XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
|
|
854
|
+
var rootNS = { xml: XML_NAMESPACE, xmlns: XMLNS_NAMESPACE };
|
|
855
|
+
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]/;
|
|
856
|
+
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-]/;
|
|
857
|
+
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]/;
|
|
858
|
+
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-]/;
|
|
859
|
+
function isWhitespace(c) {
|
|
860
|
+
return c === " " || c === "\n" || c === "\r" || c === " ";
|
|
861
|
+
}
|
|
862
|
+
function isQuote(c) {
|
|
863
|
+
return c === '"' || c === "'";
|
|
864
|
+
}
|
|
865
|
+
function isAttribEnd(c) {
|
|
866
|
+
return c === ">" || isWhitespace(c);
|
|
867
|
+
}
|
|
868
|
+
function isMatch(regex, c) {
|
|
869
|
+
return regex.test(c);
|
|
870
|
+
}
|
|
871
|
+
function notMatch(regex, c) {
|
|
872
|
+
return !isMatch(regex, c);
|
|
873
|
+
}
|
|
874
|
+
var S = 0;
|
|
875
|
+
sax2.STATE = {
|
|
876
|
+
BEGIN: S++,
|
|
877
|
+
// leading byte order mark or whitespace
|
|
878
|
+
BEGIN_WHITESPACE: S++,
|
|
879
|
+
// leading whitespace
|
|
880
|
+
TEXT: S++,
|
|
881
|
+
// general stuff
|
|
882
|
+
TEXT_ENTITY: S++,
|
|
883
|
+
// & and such.
|
|
884
|
+
OPEN_WAKA: S++,
|
|
885
|
+
// <
|
|
886
|
+
SGML_DECL: S++,
|
|
887
|
+
// <!BLARG
|
|
888
|
+
SGML_DECL_QUOTED: S++,
|
|
889
|
+
// <!BLARG foo "bar
|
|
890
|
+
DOCTYPE: S++,
|
|
891
|
+
// <!DOCTYPE
|
|
892
|
+
DOCTYPE_QUOTED: S++,
|
|
893
|
+
// <!DOCTYPE "//blah
|
|
894
|
+
DOCTYPE_DTD: S++,
|
|
895
|
+
// <!DOCTYPE "//blah" [ ...
|
|
896
|
+
DOCTYPE_DTD_QUOTED: S++,
|
|
897
|
+
// <!DOCTYPE "//blah" [ "foo
|
|
898
|
+
COMMENT_STARTING: S++,
|
|
899
|
+
// <!-
|
|
900
|
+
COMMENT: S++,
|
|
901
|
+
// <!--
|
|
902
|
+
COMMENT_ENDING: S++,
|
|
903
|
+
// <!-- blah -
|
|
904
|
+
COMMENT_ENDED: S++,
|
|
905
|
+
// <!-- blah --
|
|
906
|
+
CDATA: S++,
|
|
907
|
+
// <![CDATA[ something
|
|
908
|
+
CDATA_ENDING: S++,
|
|
909
|
+
// ]
|
|
910
|
+
CDATA_ENDING_2: S++,
|
|
911
|
+
// ]]
|
|
912
|
+
PROC_INST: S++,
|
|
913
|
+
// <?hi
|
|
914
|
+
PROC_INST_BODY: S++,
|
|
915
|
+
// <?hi there
|
|
916
|
+
PROC_INST_ENDING: S++,
|
|
917
|
+
// <?hi "there" ?
|
|
918
|
+
OPEN_TAG: S++,
|
|
919
|
+
// <strong
|
|
920
|
+
OPEN_TAG_SLASH: S++,
|
|
921
|
+
// <strong /
|
|
922
|
+
ATTRIB: S++,
|
|
923
|
+
// <a
|
|
924
|
+
ATTRIB_NAME: S++,
|
|
925
|
+
// <a foo
|
|
926
|
+
ATTRIB_NAME_SAW_WHITE: S++,
|
|
927
|
+
// <a foo _
|
|
928
|
+
ATTRIB_VALUE: S++,
|
|
929
|
+
// <a foo=
|
|
930
|
+
ATTRIB_VALUE_QUOTED: S++,
|
|
931
|
+
// <a foo="bar
|
|
932
|
+
ATTRIB_VALUE_CLOSED: S++,
|
|
933
|
+
// <a foo="bar"
|
|
934
|
+
ATTRIB_VALUE_UNQUOTED: S++,
|
|
935
|
+
// <a foo=bar
|
|
936
|
+
ATTRIB_VALUE_ENTITY_Q: S++,
|
|
937
|
+
// <foo bar="""
|
|
938
|
+
ATTRIB_VALUE_ENTITY_U: S++,
|
|
939
|
+
// <foo bar="
|
|
940
|
+
CLOSE_TAG: S++,
|
|
941
|
+
// </a
|
|
942
|
+
CLOSE_TAG_SAW_WHITE: S++,
|
|
943
|
+
// </a >
|
|
944
|
+
SCRIPT: S++,
|
|
945
|
+
// <script> ...
|
|
946
|
+
SCRIPT_ENDING: S++
|
|
947
|
+
// <script> ... <
|
|
1301
948
|
};
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
this.replaceEntitiesValue = replaceEntitiesValue;
|
|
1309
|
-
this.readStopNodeData = readStopNodeData;
|
|
1310
|
-
this.saveTextToParentTag = saveTextToParentTag;
|
|
1311
|
-
this.addChild = addChild;
|
|
1312
|
-
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes);
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
function addExternalEntities(externalEntities) {
|
|
1316
|
-
const entKeys = Object.keys(externalEntities);
|
|
1317
|
-
for (let i = 0; i < entKeys.length; i++) {
|
|
1318
|
-
const ent = entKeys[i];
|
|
1319
|
-
this.lastEntities[ent] = {
|
|
1320
|
-
regex: new RegExp("&" + ent + ";", "g"),
|
|
1321
|
-
val: externalEntities[ent]
|
|
949
|
+
sax2.XML_ENTITIES = {
|
|
950
|
+
"amp": "&",
|
|
951
|
+
"gt": ">",
|
|
952
|
+
"lt": "<",
|
|
953
|
+
"quot": '"',
|
|
954
|
+
"apos": "'"
|
|
1322
955
|
};
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
956
|
+
sax2.ENTITIES = {
|
|
957
|
+
"amp": "&",
|
|
958
|
+
"gt": ">",
|
|
959
|
+
"lt": "<",
|
|
960
|
+
"quot": '"',
|
|
961
|
+
"apos": "'",
|
|
962
|
+
"AElig": 198,
|
|
963
|
+
"Aacute": 193,
|
|
964
|
+
"Acirc": 194,
|
|
965
|
+
"Agrave": 192,
|
|
966
|
+
"Aring": 197,
|
|
967
|
+
"Atilde": 195,
|
|
968
|
+
"Auml": 196,
|
|
969
|
+
"Ccedil": 199,
|
|
970
|
+
"ETH": 208,
|
|
971
|
+
"Eacute": 201,
|
|
972
|
+
"Ecirc": 202,
|
|
973
|
+
"Egrave": 200,
|
|
974
|
+
"Euml": 203,
|
|
975
|
+
"Iacute": 205,
|
|
976
|
+
"Icirc": 206,
|
|
977
|
+
"Igrave": 204,
|
|
978
|
+
"Iuml": 207,
|
|
979
|
+
"Ntilde": 209,
|
|
980
|
+
"Oacute": 211,
|
|
981
|
+
"Ocirc": 212,
|
|
982
|
+
"Ograve": 210,
|
|
983
|
+
"Oslash": 216,
|
|
984
|
+
"Otilde": 213,
|
|
985
|
+
"Ouml": 214,
|
|
986
|
+
"THORN": 222,
|
|
987
|
+
"Uacute": 218,
|
|
988
|
+
"Ucirc": 219,
|
|
989
|
+
"Ugrave": 217,
|
|
990
|
+
"Uuml": 220,
|
|
991
|
+
"Yacute": 221,
|
|
992
|
+
"aacute": 225,
|
|
993
|
+
"acirc": 226,
|
|
994
|
+
"aelig": 230,
|
|
995
|
+
"agrave": 224,
|
|
996
|
+
"aring": 229,
|
|
997
|
+
"atilde": 227,
|
|
998
|
+
"auml": 228,
|
|
999
|
+
"ccedil": 231,
|
|
1000
|
+
"eacute": 233,
|
|
1001
|
+
"ecirc": 234,
|
|
1002
|
+
"egrave": 232,
|
|
1003
|
+
"eth": 240,
|
|
1004
|
+
"euml": 235,
|
|
1005
|
+
"iacute": 237,
|
|
1006
|
+
"icirc": 238,
|
|
1007
|
+
"igrave": 236,
|
|
1008
|
+
"iuml": 239,
|
|
1009
|
+
"ntilde": 241,
|
|
1010
|
+
"oacute": 243,
|
|
1011
|
+
"ocirc": 244,
|
|
1012
|
+
"ograve": 242,
|
|
1013
|
+
"oslash": 248,
|
|
1014
|
+
"otilde": 245,
|
|
1015
|
+
"ouml": 246,
|
|
1016
|
+
"szlig": 223,
|
|
1017
|
+
"thorn": 254,
|
|
1018
|
+
"uacute": 250,
|
|
1019
|
+
"ucirc": 251,
|
|
1020
|
+
"ugrave": 249,
|
|
1021
|
+
"uuml": 252,
|
|
1022
|
+
"yacute": 253,
|
|
1023
|
+
"yuml": 255,
|
|
1024
|
+
"copy": 169,
|
|
1025
|
+
"reg": 174,
|
|
1026
|
+
"nbsp": 160,
|
|
1027
|
+
"iexcl": 161,
|
|
1028
|
+
"cent": 162,
|
|
1029
|
+
"pound": 163,
|
|
1030
|
+
"curren": 164,
|
|
1031
|
+
"yen": 165,
|
|
1032
|
+
"brvbar": 166,
|
|
1033
|
+
"sect": 167,
|
|
1034
|
+
"uml": 168,
|
|
1035
|
+
"ordf": 170,
|
|
1036
|
+
"laquo": 171,
|
|
1037
|
+
"not": 172,
|
|
1038
|
+
"shy": 173,
|
|
1039
|
+
"macr": 175,
|
|
1040
|
+
"deg": 176,
|
|
1041
|
+
"plusmn": 177,
|
|
1042
|
+
"sup1": 185,
|
|
1043
|
+
"sup2": 178,
|
|
1044
|
+
"sup3": 179,
|
|
1045
|
+
"acute": 180,
|
|
1046
|
+
"micro": 181,
|
|
1047
|
+
"para": 182,
|
|
1048
|
+
"middot": 183,
|
|
1049
|
+
"cedil": 184,
|
|
1050
|
+
"ordm": 186,
|
|
1051
|
+
"raquo": 187,
|
|
1052
|
+
"frac14": 188,
|
|
1053
|
+
"frac12": 189,
|
|
1054
|
+
"frac34": 190,
|
|
1055
|
+
"iquest": 191,
|
|
1056
|
+
"times": 215,
|
|
1057
|
+
"divide": 247,
|
|
1058
|
+
"OElig": 338,
|
|
1059
|
+
"oelig": 339,
|
|
1060
|
+
"Scaron": 352,
|
|
1061
|
+
"scaron": 353,
|
|
1062
|
+
"Yuml": 376,
|
|
1063
|
+
"fnof": 402,
|
|
1064
|
+
"circ": 710,
|
|
1065
|
+
"tilde": 732,
|
|
1066
|
+
"Alpha": 913,
|
|
1067
|
+
"Beta": 914,
|
|
1068
|
+
"Gamma": 915,
|
|
1069
|
+
"Delta": 916,
|
|
1070
|
+
"Epsilon": 917,
|
|
1071
|
+
"Zeta": 918,
|
|
1072
|
+
"Eta": 919,
|
|
1073
|
+
"Theta": 920,
|
|
1074
|
+
"Iota": 921,
|
|
1075
|
+
"Kappa": 922,
|
|
1076
|
+
"Lambda": 923,
|
|
1077
|
+
"Mu": 924,
|
|
1078
|
+
"Nu": 925,
|
|
1079
|
+
"Xi": 926,
|
|
1080
|
+
"Omicron": 927,
|
|
1081
|
+
"Pi": 928,
|
|
1082
|
+
"Rho": 929,
|
|
1083
|
+
"Sigma": 931,
|
|
1084
|
+
"Tau": 932,
|
|
1085
|
+
"Upsilon": 933,
|
|
1086
|
+
"Phi": 934,
|
|
1087
|
+
"Chi": 935,
|
|
1088
|
+
"Psi": 936,
|
|
1089
|
+
"Omega": 937,
|
|
1090
|
+
"alpha": 945,
|
|
1091
|
+
"beta": 946,
|
|
1092
|
+
"gamma": 947,
|
|
1093
|
+
"delta": 948,
|
|
1094
|
+
"epsilon": 949,
|
|
1095
|
+
"zeta": 950,
|
|
1096
|
+
"eta": 951,
|
|
1097
|
+
"theta": 952,
|
|
1098
|
+
"iota": 953,
|
|
1099
|
+
"kappa": 954,
|
|
1100
|
+
"lambda": 955,
|
|
1101
|
+
"mu": 956,
|
|
1102
|
+
"nu": 957,
|
|
1103
|
+
"xi": 958,
|
|
1104
|
+
"omicron": 959,
|
|
1105
|
+
"pi": 960,
|
|
1106
|
+
"rho": 961,
|
|
1107
|
+
"sigmaf": 962,
|
|
1108
|
+
"sigma": 963,
|
|
1109
|
+
"tau": 964,
|
|
1110
|
+
"upsilon": 965,
|
|
1111
|
+
"phi": 966,
|
|
1112
|
+
"chi": 967,
|
|
1113
|
+
"psi": 968,
|
|
1114
|
+
"omega": 969,
|
|
1115
|
+
"thetasym": 977,
|
|
1116
|
+
"upsih": 978,
|
|
1117
|
+
"piv": 982,
|
|
1118
|
+
"ensp": 8194,
|
|
1119
|
+
"emsp": 8195,
|
|
1120
|
+
"thinsp": 8201,
|
|
1121
|
+
"zwnj": 8204,
|
|
1122
|
+
"zwj": 8205,
|
|
1123
|
+
"lrm": 8206,
|
|
1124
|
+
"rlm": 8207,
|
|
1125
|
+
"ndash": 8211,
|
|
1126
|
+
"mdash": 8212,
|
|
1127
|
+
"lsquo": 8216,
|
|
1128
|
+
"rsquo": 8217,
|
|
1129
|
+
"sbquo": 8218,
|
|
1130
|
+
"ldquo": 8220,
|
|
1131
|
+
"rdquo": 8221,
|
|
1132
|
+
"bdquo": 8222,
|
|
1133
|
+
"dagger": 8224,
|
|
1134
|
+
"Dagger": 8225,
|
|
1135
|
+
"bull": 8226,
|
|
1136
|
+
"hellip": 8230,
|
|
1137
|
+
"permil": 8240,
|
|
1138
|
+
"prime": 8242,
|
|
1139
|
+
"Prime": 8243,
|
|
1140
|
+
"lsaquo": 8249,
|
|
1141
|
+
"rsaquo": 8250,
|
|
1142
|
+
"oline": 8254,
|
|
1143
|
+
"frasl": 8260,
|
|
1144
|
+
"euro": 8364,
|
|
1145
|
+
"image": 8465,
|
|
1146
|
+
"weierp": 8472,
|
|
1147
|
+
"real": 8476,
|
|
1148
|
+
"trade": 8482,
|
|
1149
|
+
"alefsym": 8501,
|
|
1150
|
+
"larr": 8592,
|
|
1151
|
+
"uarr": 8593,
|
|
1152
|
+
"rarr": 8594,
|
|
1153
|
+
"darr": 8595,
|
|
1154
|
+
"harr": 8596,
|
|
1155
|
+
"crarr": 8629,
|
|
1156
|
+
"lArr": 8656,
|
|
1157
|
+
"uArr": 8657,
|
|
1158
|
+
"rArr": 8658,
|
|
1159
|
+
"dArr": 8659,
|
|
1160
|
+
"hArr": 8660,
|
|
1161
|
+
"forall": 8704,
|
|
1162
|
+
"part": 8706,
|
|
1163
|
+
"exist": 8707,
|
|
1164
|
+
"empty": 8709,
|
|
1165
|
+
"nabla": 8711,
|
|
1166
|
+
"isin": 8712,
|
|
1167
|
+
"notin": 8713,
|
|
1168
|
+
"ni": 8715,
|
|
1169
|
+
"prod": 8719,
|
|
1170
|
+
"sum": 8721,
|
|
1171
|
+
"minus": 8722,
|
|
1172
|
+
"lowast": 8727,
|
|
1173
|
+
"radic": 8730,
|
|
1174
|
+
"prop": 8733,
|
|
1175
|
+
"infin": 8734,
|
|
1176
|
+
"ang": 8736,
|
|
1177
|
+
"and": 8743,
|
|
1178
|
+
"or": 8744,
|
|
1179
|
+
"cap": 8745,
|
|
1180
|
+
"cup": 8746,
|
|
1181
|
+
"int": 8747,
|
|
1182
|
+
"there4": 8756,
|
|
1183
|
+
"sim": 8764,
|
|
1184
|
+
"cong": 8773,
|
|
1185
|
+
"asymp": 8776,
|
|
1186
|
+
"ne": 8800,
|
|
1187
|
+
"equiv": 8801,
|
|
1188
|
+
"le": 8804,
|
|
1189
|
+
"ge": 8805,
|
|
1190
|
+
"sub": 8834,
|
|
1191
|
+
"sup": 8835,
|
|
1192
|
+
"nsub": 8836,
|
|
1193
|
+
"sube": 8838,
|
|
1194
|
+
"supe": 8839,
|
|
1195
|
+
"oplus": 8853,
|
|
1196
|
+
"otimes": 8855,
|
|
1197
|
+
"perp": 8869,
|
|
1198
|
+
"sdot": 8901,
|
|
1199
|
+
"lceil": 8968,
|
|
1200
|
+
"rceil": 8969,
|
|
1201
|
+
"lfloor": 8970,
|
|
1202
|
+
"rfloor": 8971,
|
|
1203
|
+
"lang": 9001,
|
|
1204
|
+
"rang": 9002,
|
|
1205
|
+
"loz": 9674,
|
|
1206
|
+
"spades": 9824,
|
|
1207
|
+
"clubs": 9827,
|
|
1208
|
+
"hearts": 9829,
|
|
1209
|
+
"diams": 9830
|
|
1210
|
+
};
|
|
1211
|
+
Object.keys(sax2.ENTITIES).forEach(function(key) {
|
|
1212
|
+
var e = sax2.ENTITIES[key];
|
|
1213
|
+
var s2 = typeof e === "number" ? String.fromCharCode(e) : e;
|
|
1214
|
+
sax2.ENTITIES[key] = s2;
|
|
1215
|
+
});
|
|
1216
|
+
for (var s in sax2.STATE) {
|
|
1217
|
+
sax2.STATE[sax2.STATE[s]] = s;
|
|
1218
|
+
}
|
|
1219
|
+
S = sax2.STATE;
|
|
1220
|
+
function emit2(parser, event, data) {
|
|
1221
|
+
parser[event] && parser[event](data);
|
|
1222
|
+
}
|
|
1223
|
+
function emitNode(parser, nodeType, data) {
|
|
1224
|
+
if (parser.textNode) closeText(parser);
|
|
1225
|
+
emit2(parser, nodeType, data);
|
|
1226
|
+
}
|
|
1227
|
+
function closeText(parser) {
|
|
1228
|
+
parser.textNode = textopts(parser.opt, parser.textNode);
|
|
1229
|
+
if (parser.textNode) emit2(parser, "ontext", parser.textNode);
|
|
1230
|
+
parser.textNode = "";
|
|
1231
|
+
}
|
|
1232
|
+
function textopts(opt, text) {
|
|
1233
|
+
if (opt.trim) text = text.trim();
|
|
1234
|
+
if (opt.normalize) text = text.replace(/\s+/g, " ");
|
|
1235
|
+
return text;
|
|
1236
|
+
}
|
|
1237
|
+
function error(parser, er) {
|
|
1238
|
+
closeText(parser);
|
|
1239
|
+
if (parser.trackPosition) {
|
|
1240
|
+
er += "\nLine: " + parser.line + "\nColumn: " + parser.column + "\nChar: " + parser.c;
|
|
1241
|
+
}
|
|
1242
|
+
er = new Error(er);
|
|
1243
|
+
parser.error = er;
|
|
1244
|
+
emit2(parser, "onerror", er);
|
|
1245
|
+
return parser;
|
|
1246
|
+
}
|
|
1247
|
+
function end(parser) {
|
|
1248
|
+
if (parser.sawRoot && !parser.closedRoot) strictFail(parser, "Unclosed root tag");
|
|
1249
|
+
if (parser.state !== S.BEGIN && parser.state !== S.BEGIN_WHITESPACE && parser.state !== S.TEXT) {
|
|
1250
|
+
error(parser, "Unexpected end");
|
|
1251
|
+
}
|
|
1252
|
+
closeText(parser);
|
|
1253
|
+
parser.c = "";
|
|
1254
|
+
parser.closed = true;
|
|
1255
|
+
emit2(parser, "onend");
|
|
1256
|
+
SAXParser.call(parser, parser.strict, parser.opt);
|
|
1257
|
+
return parser;
|
|
1258
|
+
}
|
|
1259
|
+
function strictFail(parser, message) {
|
|
1260
|
+
if (typeof parser !== "object" || !(parser instanceof SAXParser)) {
|
|
1261
|
+
throw new Error("bad call to strictFail");
|
|
1262
|
+
}
|
|
1263
|
+
if (parser.strict) {
|
|
1264
|
+
error(parser, message);
|
|
1346
1265
|
}
|
|
1347
1266
|
}
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1267
|
+
function newTag(parser) {
|
|
1268
|
+
if (!parser.strict) parser.tagName = parser.tagName[parser.looseCase]();
|
|
1269
|
+
var parent = parser.tags[parser.tags.length - 1] || parser;
|
|
1270
|
+
var tag = parser.tag = { name: parser.tagName, attributes: {} };
|
|
1271
|
+
if (parser.opt.xmlns) {
|
|
1272
|
+
tag.ns = parent.ns;
|
|
1273
|
+
}
|
|
1274
|
+
parser.attribList.length = 0;
|
|
1275
|
+
emitNode(parser, "onopentagstart", tag);
|
|
1276
|
+
}
|
|
1277
|
+
function qname(name, attribute) {
|
|
1278
|
+
var i = name.indexOf(":");
|
|
1279
|
+
var qualName = i < 0 ? ["", name] : name.split(":");
|
|
1280
|
+
var prefix = qualName[0];
|
|
1281
|
+
var local = qualName[1];
|
|
1282
|
+
if (attribute && name === "xmlns") {
|
|
1283
|
+
prefix = "xmlns";
|
|
1284
|
+
local = "";
|
|
1285
|
+
}
|
|
1286
|
+
return { prefix, local };
|
|
1359
1287
|
}
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
const attrsRegx = new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`, "gm");
|
|
1364
|
-
function buildAttributesMap(attrStr, jPath, tagName) {
|
|
1365
|
-
if (this.options.ignoreAttributes !== true && typeof attrStr === "string") {
|
|
1366
|
-
const matches = util2.getAllMatches(attrStr, attrsRegx);
|
|
1367
|
-
const len = matches.length;
|
|
1368
|
-
const attrs = {};
|
|
1369
|
-
for (let i = 0; i < len; i++) {
|
|
1370
|
-
const attrName = this.resolveNameSpace(matches[i][1]);
|
|
1371
|
-
if (this.ignoreAttributesFn(attrName, jPath)) {
|
|
1372
|
-
continue;
|
|
1288
|
+
function attrib(parser) {
|
|
1289
|
+
if (!parser.strict) {
|
|
1290
|
+
parser.attribName = parser.attribName[parser.looseCase]();
|
|
1373
1291
|
}
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
attrs[aName] = parseValue(
|
|
1393
|
-
oldVal,
|
|
1394
|
-
this.options.parseAttributeValue,
|
|
1395
|
-
this.options.numberParseOptions
|
|
1292
|
+
if (parser.attribList.indexOf(parser.attribName) !== -1 || parser.tag.attributes.hasOwnProperty(parser.attribName)) {
|
|
1293
|
+
parser.attribName = parser.attribValue = "";
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
if (parser.opt.xmlns) {
|
|
1297
|
+
var qn = qname(parser.attribName, true);
|
|
1298
|
+
var prefix = qn.prefix;
|
|
1299
|
+
var local = qn.local;
|
|
1300
|
+
if (prefix === "xmlns") {
|
|
1301
|
+
if (local === "xml" && parser.attribValue !== XML_NAMESPACE) {
|
|
1302
|
+
strictFail(
|
|
1303
|
+
parser,
|
|
1304
|
+
"xml: prefix must be bound to " + XML_NAMESPACE + "\nActual: " + parser.attribValue
|
|
1305
|
+
);
|
|
1306
|
+
} else if (local === "xmlns" && parser.attribValue !== XMLNS_NAMESPACE) {
|
|
1307
|
+
strictFail(
|
|
1308
|
+
parser,
|
|
1309
|
+
"xmlns: prefix must be bound to " + XMLNS_NAMESPACE + "\nActual: " + parser.attribValue
|
|
1396
1310
|
);
|
|
1311
|
+
} else {
|
|
1312
|
+
var tag = parser.tag;
|
|
1313
|
+
var parent = parser.tags[parser.tags.length - 1] || parser;
|
|
1314
|
+
if (tag.ns === parent.ns) {
|
|
1315
|
+
tag.ns = Object.create(parent.ns);
|
|
1316
|
+
}
|
|
1317
|
+
tag.ns[local] = parser.attribValue;
|
|
1397
1318
|
}
|
|
1398
|
-
} else if (this.options.allowBooleanAttributes) {
|
|
1399
|
-
attrs[aName] = true;
|
|
1400
1319
|
}
|
|
1320
|
+
parser.attribList.push([parser.attribName, parser.attribValue]);
|
|
1321
|
+
} else {
|
|
1322
|
+
parser.tag.attributes[parser.attribName] = parser.attribValue;
|
|
1323
|
+
emitNode(parser, "onattribute", {
|
|
1324
|
+
name: parser.attribName,
|
|
1325
|
+
value: parser.attribValue
|
|
1326
|
+
});
|
|
1401
1327
|
}
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
const parseXml = function(xmlData) {
|
|
1415
|
-
xmlData = xmlData.replace(/\r\n?/g, "\n");
|
|
1416
|
-
const xmlObj = new xmlNode2("!xml");
|
|
1417
|
-
let currentNode = xmlObj;
|
|
1418
|
-
let textData = "";
|
|
1419
|
-
let jPath = "";
|
|
1420
|
-
for (let i = 0; i < xmlData.length; i++) {
|
|
1421
|
-
const ch = xmlData[i];
|
|
1422
|
-
if (ch === "<") {
|
|
1423
|
-
if (xmlData[i + 1] === "/") {
|
|
1424
|
-
const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.");
|
|
1425
|
-
let tagName = xmlData.substring(i + 2, closeIndex).trim();
|
|
1426
|
-
if (this.options.removeNSPrefix) {
|
|
1427
|
-
const colonIndex = tagName.indexOf(":");
|
|
1428
|
-
if (colonIndex !== -1) {
|
|
1429
|
-
tagName = tagName.substr(colonIndex + 1);
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
if (this.options.transformTagName) {
|
|
1433
|
-
tagName = this.options.transformTagName(tagName);
|
|
1434
|
-
}
|
|
1435
|
-
if (currentNode) {
|
|
1436
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
1437
|
-
}
|
|
1438
|
-
const lastTagName = jPath.substring(jPath.lastIndexOf(".") + 1);
|
|
1439
|
-
if (tagName && this.options.unpairedTags.indexOf(tagName) !== -1) {
|
|
1440
|
-
throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
|
|
1441
|
-
}
|
|
1442
|
-
let propIndex = 0;
|
|
1443
|
-
if (lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1) {
|
|
1444
|
-
propIndex = jPath.lastIndexOf(".", jPath.lastIndexOf(".") - 1);
|
|
1445
|
-
this.tagsNodeStack.pop();
|
|
1446
|
-
} else {
|
|
1447
|
-
propIndex = jPath.lastIndexOf(".");
|
|
1328
|
+
parser.attribName = parser.attribValue = "";
|
|
1329
|
+
}
|
|
1330
|
+
function openTag(parser, selfClosing) {
|
|
1331
|
+
if (parser.opt.xmlns) {
|
|
1332
|
+
var tag = parser.tag;
|
|
1333
|
+
var qn = qname(parser.tagName);
|
|
1334
|
+
tag.prefix = qn.prefix;
|
|
1335
|
+
tag.local = qn.local;
|
|
1336
|
+
tag.uri = tag.ns[qn.prefix] || "";
|
|
1337
|
+
if (tag.prefix && !tag.uri) {
|
|
1338
|
+
strictFail(parser, "Unbound namespace prefix: " + JSON.stringify(parser.tagName));
|
|
1339
|
+
tag.uri = qn.prefix;
|
|
1448
1340
|
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
if (this.options.ignoreDeclaration && tagData.tagName === "?xml" || this.options.ignorePiTags) ;
|
|
1458
|
-
else {
|
|
1459
|
-
const childNode = new xmlNode2(tagData.tagName);
|
|
1460
|
-
childNode.add(this.options.textNodeName, "");
|
|
1461
|
-
if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) {
|
|
1462
|
-
childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName);
|
|
1463
|
-
}
|
|
1464
|
-
this.addChild(currentNode, childNode, jPath);
|
|
1465
|
-
}
|
|
1466
|
-
i = tagData.closeIndex + 1;
|
|
1467
|
-
} else if (xmlData.substr(i + 1, 3) === "!--") {
|
|
1468
|
-
const endIndex = findClosingIndex(xmlData, "-->", i + 4, "Comment is not closed.");
|
|
1469
|
-
if (this.options.commentPropName) {
|
|
1470
|
-
const comment = xmlData.substring(i + 4, endIndex - 2);
|
|
1471
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
1472
|
-
currentNode.add(this.options.commentPropName, [{ [this.options.textNodeName]: comment }]);
|
|
1473
|
-
}
|
|
1474
|
-
i = endIndex;
|
|
1475
|
-
} else if (xmlData.substr(i + 1, 2) === "!D") {
|
|
1476
|
-
const result = readDocType(xmlData, i);
|
|
1477
|
-
this.docTypeEntities = result.entities;
|
|
1478
|
-
i = result.i;
|
|
1479
|
-
} else if (xmlData.substr(i + 1, 2) === "![") {
|
|
1480
|
-
const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
|
|
1481
|
-
const tagExp = xmlData.substring(i + 9, closeIndex);
|
|
1482
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
1483
|
-
let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true, true);
|
|
1484
|
-
if (val == void 0) val = "";
|
|
1485
|
-
if (this.options.cdataPropName) {
|
|
1486
|
-
currentNode.add(this.options.cdataPropName, [{ [this.options.textNodeName]: tagExp }]);
|
|
1487
|
-
} else {
|
|
1488
|
-
currentNode.add(this.options.textNodeName, val);
|
|
1341
|
+
var parent = parser.tags[parser.tags.length - 1] || parser;
|
|
1342
|
+
if (tag.ns && parent.ns !== tag.ns) {
|
|
1343
|
+
Object.keys(tag.ns).forEach(function(p) {
|
|
1344
|
+
emitNode(parser, "onopennamespace", {
|
|
1345
|
+
prefix: p,
|
|
1346
|
+
uri: tag.ns[p]
|
|
1347
|
+
});
|
|
1348
|
+
});
|
|
1489
1349
|
}
|
|
1490
|
-
i =
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1350
|
+
for (var i = 0, l = parser.attribList.length; i < l; i++) {
|
|
1351
|
+
var nv = parser.attribList[i];
|
|
1352
|
+
var name = nv[0];
|
|
1353
|
+
var value = nv[1];
|
|
1354
|
+
var qualName = qname(name, true);
|
|
1355
|
+
var prefix = qualName.prefix;
|
|
1356
|
+
var local = qualName.local;
|
|
1357
|
+
var uri = prefix === "" ? "" : tag.ns[prefix] || "";
|
|
1358
|
+
var a = {
|
|
1359
|
+
name,
|
|
1360
|
+
value,
|
|
1361
|
+
prefix,
|
|
1362
|
+
local,
|
|
1363
|
+
uri
|
|
1364
|
+
};
|
|
1365
|
+
if (prefix && prefix !== "xmlns" && !uri) {
|
|
1366
|
+
strictFail(parser, "Unbound namespace prefix: " + JSON.stringify(prefix));
|
|
1367
|
+
a.uri = prefix;
|
|
1504
1368
|
}
|
|
1369
|
+
parser.tag.attributes[name] = a;
|
|
1370
|
+
emitNode(parser, "onattribute", a);
|
|
1505
1371
|
}
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
let tagContent = "";
|
|
1516
|
-
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
|
|
1517
|
-
if (tagName[tagName.length - 1] === "/") {
|
|
1518
|
-
tagName = tagName.substr(0, tagName.length - 1);
|
|
1519
|
-
jPath = jPath.substr(0, jPath.length - 1);
|
|
1520
|
-
tagExp = tagName;
|
|
1521
|
-
} else {
|
|
1522
|
-
tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
1523
|
-
}
|
|
1524
|
-
i = result.closeIndex;
|
|
1525
|
-
} else if (this.options.unpairedTags.indexOf(tagName) !== -1) {
|
|
1526
|
-
i = result.closeIndex;
|
|
1527
|
-
} else {
|
|
1528
|
-
const result2 = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
|
|
1529
|
-
if (!result2) throw new Error(`Unexpected end of ${rawTagName}`);
|
|
1530
|
-
i = result2.i;
|
|
1531
|
-
tagContent = result2.tagContent;
|
|
1532
|
-
}
|
|
1533
|
-
const childNode = new xmlNode2(tagName);
|
|
1534
|
-
if (tagName !== tagExp && attrExpPresent) {
|
|
1535
|
-
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
|
|
1536
|
-
}
|
|
1537
|
-
if (tagContent) {
|
|
1538
|
-
tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
|
|
1539
|
-
}
|
|
1540
|
-
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
1541
|
-
childNode.add(this.options.textNodeName, tagContent);
|
|
1542
|
-
this.addChild(currentNode, childNode, jPath);
|
|
1372
|
+
parser.attribList.length = 0;
|
|
1373
|
+
}
|
|
1374
|
+
parser.tag.isSelfClosing = !!selfClosing;
|
|
1375
|
+
parser.sawRoot = true;
|
|
1376
|
+
parser.tags.push(parser.tag);
|
|
1377
|
+
emitNode(parser, "onopentag", parser.tag);
|
|
1378
|
+
if (!selfClosing) {
|
|
1379
|
+
if (!parser.noscript && parser.tagName.toLowerCase() === "script") {
|
|
1380
|
+
parser.state = S.SCRIPT;
|
|
1543
1381
|
} else {
|
|
1544
|
-
|
|
1545
|
-
if (tagName[tagName.length - 1] === "/") {
|
|
1546
|
-
tagName = tagName.substr(0, tagName.length - 1);
|
|
1547
|
-
jPath = jPath.substr(0, jPath.length - 1);
|
|
1548
|
-
tagExp = tagName;
|
|
1549
|
-
} else {
|
|
1550
|
-
tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
1551
|
-
}
|
|
1552
|
-
if (this.options.transformTagName) {
|
|
1553
|
-
tagName = this.options.transformTagName(tagName);
|
|
1554
|
-
}
|
|
1555
|
-
const childNode = new xmlNode2(tagName);
|
|
1556
|
-
if (tagName !== tagExp && attrExpPresent) {
|
|
1557
|
-
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
|
|
1558
|
-
}
|
|
1559
|
-
this.addChild(currentNode, childNode, jPath);
|
|
1560
|
-
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
1561
|
-
} else {
|
|
1562
|
-
const childNode = new xmlNode2(tagName);
|
|
1563
|
-
this.tagsNodeStack.push(currentNode);
|
|
1564
|
-
if (tagName !== tagExp && attrExpPresent) {
|
|
1565
|
-
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
|
|
1566
|
-
}
|
|
1567
|
-
this.addChild(currentNode, childNode, jPath);
|
|
1568
|
-
currentNode = childNode;
|
|
1569
|
-
}
|
|
1570
|
-
textData = "";
|
|
1571
|
-
i = closeIndex;
|
|
1382
|
+
parser.state = S.TEXT;
|
|
1572
1383
|
}
|
|
1384
|
+
parser.tag = null;
|
|
1385
|
+
parser.tagName = "";
|
|
1573
1386
|
}
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
else if (typeof result === "string") {
|
|
1584
|
-
childNode.tagname = result;
|
|
1585
|
-
currentNode.addChild(childNode);
|
|
1586
|
-
} else {
|
|
1587
|
-
currentNode.addChild(childNode);
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
const replaceEntitiesValue = function(val) {
|
|
1591
|
-
if (this.options.processEntities) {
|
|
1592
|
-
for (let entityName in this.docTypeEntities) {
|
|
1593
|
-
const entity = this.docTypeEntities[entityName];
|
|
1594
|
-
val = val.replace(entity.regx, entity.val);
|
|
1595
|
-
}
|
|
1596
|
-
for (let entityName in this.lastEntities) {
|
|
1597
|
-
const entity = this.lastEntities[entityName];
|
|
1598
|
-
val = val.replace(entity.regex, entity.val);
|
|
1599
|
-
}
|
|
1600
|
-
if (this.options.htmlEntities) {
|
|
1601
|
-
for (let entityName in this.htmlEntities) {
|
|
1602
|
-
const entity = this.htmlEntities[entityName];
|
|
1603
|
-
val = val.replace(entity.regex, entity.val);
|
|
1387
|
+
parser.attribName = parser.attribValue = "";
|
|
1388
|
+
parser.attribList.length = 0;
|
|
1389
|
+
}
|
|
1390
|
+
function closeTag(parser) {
|
|
1391
|
+
if (!parser.tagName) {
|
|
1392
|
+
strictFail(parser, "Weird empty close tag.");
|
|
1393
|
+
parser.textNode += "</>";
|
|
1394
|
+
parser.state = S.TEXT;
|
|
1395
|
+
return;
|
|
1604
1396
|
}
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
if (textData) {
|
|
1612
|
-
if (isLeafNode === void 0) isLeafNode = Object.keys(currentNode.child).length === 0;
|
|
1613
|
-
textData = this.parseTextData(
|
|
1614
|
-
textData,
|
|
1615
|
-
currentNode.tagname,
|
|
1616
|
-
jPath,
|
|
1617
|
-
false,
|
|
1618
|
-
currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false,
|
|
1619
|
-
isLeafNode
|
|
1620
|
-
);
|
|
1621
|
-
if (textData !== void 0 && textData !== "")
|
|
1622
|
-
currentNode.add(this.options.textNodeName, textData);
|
|
1623
|
-
textData = "";
|
|
1624
|
-
}
|
|
1625
|
-
return textData;
|
|
1626
|
-
}
|
|
1627
|
-
function isItStopNode(stopNodes, jPath, currentTagName) {
|
|
1628
|
-
const allNodesExp = "*." + currentTagName;
|
|
1629
|
-
for (const stopNodePath in stopNodes) {
|
|
1630
|
-
const stopNodeExp = stopNodes[stopNodePath];
|
|
1631
|
-
if (allNodesExp === stopNodeExp || jPath === stopNodeExp) return true;
|
|
1632
|
-
}
|
|
1633
|
-
return false;
|
|
1634
|
-
}
|
|
1635
|
-
function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
|
|
1636
|
-
let attrBoundary;
|
|
1637
|
-
let tagExp = "";
|
|
1638
|
-
for (let index = i; index < xmlData.length; index++) {
|
|
1639
|
-
let ch = xmlData[index];
|
|
1640
|
-
if (attrBoundary) {
|
|
1641
|
-
if (ch === attrBoundary) attrBoundary = "";
|
|
1642
|
-
} else if (ch === '"' || ch === "'") {
|
|
1643
|
-
attrBoundary = ch;
|
|
1644
|
-
} else if (ch === closingChar[0]) {
|
|
1645
|
-
if (closingChar[1]) {
|
|
1646
|
-
if (xmlData[index + 1] === closingChar[1]) {
|
|
1647
|
-
return {
|
|
1648
|
-
data: tagExp,
|
|
1649
|
-
index
|
|
1650
|
-
};
|
|
1397
|
+
if (parser.script) {
|
|
1398
|
+
if (parser.tagName !== "script") {
|
|
1399
|
+
parser.script += "</" + parser.tagName + ">";
|
|
1400
|
+
parser.tagName = "";
|
|
1401
|
+
parser.state = S.SCRIPT;
|
|
1402
|
+
return;
|
|
1651
1403
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
data: tagExp,
|
|
1655
|
-
index
|
|
1656
|
-
};
|
|
1404
|
+
emitNode(parser, "onscript", parser.script);
|
|
1405
|
+
parser.script = "";
|
|
1657
1406
|
}
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
function readTagExp(xmlData, i, removeNSPrefix, closingChar = ">") {
|
|
1673
|
-
const result = tagExpWithClosingIndex(xmlData, i + 1, closingChar);
|
|
1674
|
-
if (!result) return;
|
|
1675
|
-
let tagExp = result.data;
|
|
1676
|
-
const closeIndex = result.index;
|
|
1677
|
-
const separatorIndex = tagExp.search(/\s/);
|
|
1678
|
-
let tagName = tagExp;
|
|
1679
|
-
let attrExpPresent = true;
|
|
1680
|
-
if (separatorIndex !== -1) {
|
|
1681
|
-
tagName = tagExp.substring(0, separatorIndex);
|
|
1682
|
-
tagExp = tagExp.substring(separatorIndex + 1).trimStart();
|
|
1683
|
-
}
|
|
1684
|
-
const rawTagName = tagName;
|
|
1685
|
-
if (removeNSPrefix) {
|
|
1686
|
-
const colonIndex = tagName.indexOf(":");
|
|
1687
|
-
if (colonIndex !== -1) {
|
|
1688
|
-
tagName = tagName.substr(colonIndex + 1);
|
|
1689
|
-
attrExpPresent = tagName !== result.data.substr(colonIndex + 1);
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
return {
|
|
1693
|
-
tagName,
|
|
1694
|
-
tagExp,
|
|
1695
|
-
closeIndex,
|
|
1696
|
-
attrExpPresent,
|
|
1697
|
-
rawTagName
|
|
1698
|
-
};
|
|
1699
|
-
}
|
|
1700
|
-
function readStopNodeData(xmlData, tagName, i) {
|
|
1701
|
-
const startIndex = i;
|
|
1702
|
-
let openTagCount = 1;
|
|
1703
|
-
for (; i < xmlData.length; i++) {
|
|
1704
|
-
if (xmlData[i] === "<") {
|
|
1705
|
-
if (xmlData[i + 1] === "/") {
|
|
1706
|
-
const closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`);
|
|
1707
|
-
let closeTagName = xmlData.substring(i + 2, closeIndex).trim();
|
|
1708
|
-
if (closeTagName === tagName) {
|
|
1709
|
-
openTagCount--;
|
|
1710
|
-
if (openTagCount === 0) {
|
|
1711
|
-
return {
|
|
1712
|
-
tagContent: xmlData.substring(startIndex, i),
|
|
1713
|
-
i: closeIndex
|
|
1714
|
-
};
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
i = closeIndex;
|
|
1718
|
-
} else if (xmlData[i + 1] === "?") {
|
|
1719
|
-
const closeIndex = findClosingIndex(xmlData, "?>", i + 1, "StopNode is not closed.");
|
|
1720
|
-
i = closeIndex;
|
|
1721
|
-
} else if (xmlData.substr(i + 1, 3) === "!--") {
|
|
1722
|
-
const closeIndex = findClosingIndex(xmlData, "-->", i + 3, "StopNode is not closed.");
|
|
1723
|
-
i = closeIndex;
|
|
1724
|
-
} else if (xmlData.substr(i + 1, 2) === "![") {
|
|
1725
|
-
const closeIndex = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2;
|
|
1726
|
-
i = closeIndex;
|
|
1727
|
-
} else {
|
|
1728
|
-
const tagData = readTagExp(xmlData, i, ">");
|
|
1729
|
-
if (tagData) {
|
|
1730
|
-
const openTagName = tagData && tagData.tagName;
|
|
1731
|
-
if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length - 1] !== "/") {
|
|
1732
|
-
openTagCount++;
|
|
1733
|
-
}
|
|
1734
|
-
i = tagData.closeIndex;
|
|
1407
|
+
var t = parser.tags.length;
|
|
1408
|
+
var tagName = parser.tagName;
|
|
1409
|
+
if (!parser.strict) {
|
|
1410
|
+
tagName = tagName[parser.looseCase]();
|
|
1411
|
+
}
|
|
1412
|
+
var closeTo = tagName;
|
|
1413
|
+
while (t--) {
|
|
1414
|
+
var close = parser.tags[t];
|
|
1415
|
+
if (close.name !== closeTo) {
|
|
1416
|
+
strictFail(parser, "Unexpected close tag");
|
|
1417
|
+
} else {
|
|
1418
|
+
break;
|
|
1735
1419
|
}
|
|
1736
1420
|
}
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
const newval = val.trim();
|
|
1743
|
-
if (newval === "true") return true;
|
|
1744
|
-
else if (newval === "false") return false;
|
|
1745
|
-
else return toNumber(val, options);
|
|
1746
|
-
} else {
|
|
1747
|
-
if (util2.isExist(val)) {
|
|
1748
|
-
return val;
|
|
1749
|
-
} else {
|
|
1750
|
-
return "";
|
|
1751
|
-
}
|
|
1752
|
-
}
|
|
1753
|
-
}
|
|
1754
|
-
OrderedObjParser_1 = OrderedObjParser;
|
|
1755
|
-
return OrderedObjParser_1;
|
|
1756
|
-
}
|
|
1757
|
-
var node2json = {};
|
|
1758
|
-
var hasRequiredNode2json;
|
|
1759
|
-
function requireNode2json() {
|
|
1760
|
-
if (hasRequiredNode2json) return node2json;
|
|
1761
|
-
hasRequiredNode2json = 1;
|
|
1762
|
-
function prettify(node, options) {
|
|
1763
|
-
return compress(node, options);
|
|
1764
|
-
}
|
|
1765
|
-
function compress(arr, options, jPath) {
|
|
1766
|
-
let text;
|
|
1767
|
-
const compressedObj = {};
|
|
1768
|
-
for (let i = 0; i < arr.length; i++) {
|
|
1769
|
-
const tagObj = arr[i];
|
|
1770
|
-
const property = propName(tagObj);
|
|
1771
|
-
let newJpath = "";
|
|
1772
|
-
if (jPath === void 0) newJpath = property;
|
|
1773
|
-
else newJpath = jPath + "." + property;
|
|
1774
|
-
if (property === options.textNodeName) {
|
|
1775
|
-
if (text === void 0) text = tagObj[property];
|
|
1776
|
-
else text += "" + tagObj[property];
|
|
1777
|
-
} else if (property === void 0) {
|
|
1778
|
-
continue;
|
|
1779
|
-
} else if (tagObj[property]) {
|
|
1780
|
-
let val = compress(tagObj[property], options, newJpath);
|
|
1781
|
-
const isLeaf = isLeafTag(val, options);
|
|
1782
|
-
if (tagObj[":@"]) {
|
|
1783
|
-
assignAttributes(val, tagObj[":@"], newJpath, options);
|
|
1784
|
-
} else if (Object.keys(val).length === 1 && val[options.textNodeName] !== void 0 && !options.alwaysCreateTextNode) {
|
|
1785
|
-
val = val[options.textNodeName];
|
|
1786
|
-
} else if (Object.keys(val).length === 0) {
|
|
1787
|
-
if (options.alwaysCreateTextNode) val[options.textNodeName] = "";
|
|
1788
|
-
else val = "";
|
|
1421
|
+
if (t < 0) {
|
|
1422
|
+
strictFail(parser, "Unmatched closing tag: " + parser.tagName);
|
|
1423
|
+
parser.textNode += "</" + parser.tagName + ">";
|
|
1424
|
+
parser.state = S.TEXT;
|
|
1425
|
+
return;
|
|
1789
1426
|
}
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1427
|
+
parser.tagName = tagName;
|
|
1428
|
+
var s2 = parser.tags.length;
|
|
1429
|
+
while (s2-- > t) {
|
|
1430
|
+
var tag = parser.tag = parser.tags.pop();
|
|
1431
|
+
parser.tagName = parser.tag.name;
|
|
1432
|
+
emitNode(parser, "onclosetag", parser.tagName);
|
|
1433
|
+
var x = {};
|
|
1434
|
+
for (var i in tag.ns) {
|
|
1435
|
+
x[i] = tag.ns[i];
|
|
1793
1436
|
}
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1437
|
+
var parent = parser.tags[parser.tags.length - 1] || parser;
|
|
1438
|
+
if (parser.opt.xmlns && tag.ns !== parent.ns) {
|
|
1439
|
+
Object.keys(tag.ns).forEach(function(p) {
|
|
1440
|
+
var n = tag.ns[p];
|
|
1441
|
+
emitNode(parser, "onclosenamespace", { prefix: p, uri: n });
|
|
1442
|
+
});
|
|
1800
1443
|
}
|
|
1801
1444
|
}
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
function assignAttributes(obj, attrMap, jpath, options) {
|
|
1817
|
-
if (attrMap) {
|
|
1818
|
-
const keys = Object.keys(attrMap);
|
|
1819
|
-
const len = keys.length;
|
|
1820
|
-
for (let i = 0; i < len; i++) {
|
|
1821
|
-
const atrrName = keys[i];
|
|
1822
|
-
if (options.isArray(atrrName, jpath + "." + atrrName, true, true)) {
|
|
1823
|
-
obj[atrrName] = [attrMap[atrrName]];
|
|
1824
|
-
} else {
|
|
1825
|
-
obj[atrrName] = attrMap[atrrName];
|
|
1445
|
+
if (t === 0) parser.closedRoot = true;
|
|
1446
|
+
parser.tagName = parser.attribValue = parser.attribName = "";
|
|
1447
|
+
parser.attribList.length = 0;
|
|
1448
|
+
parser.state = S.TEXT;
|
|
1449
|
+
}
|
|
1450
|
+
function parseEntity(parser) {
|
|
1451
|
+
var entity = parser.entity;
|
|
1452
|
+
var entityLC = entity.toLowerCase();
|
|
1453
|
+
var num;
|
|
1454
|
+
var numStr = "";
|
|
1455
|
+
if (parser.ENTITIES[entity]) {
|
|
1456
|
+
return parser.ENTITIES[entity];
|
|
1826
1457
|
}
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
}
|
|
1830
|
-
function isLeafTag(obj, options) {
|
|
1831
|
-
const { textNodeName } = options;
|
|
1832
|
-
const propCount = Object.keys(obj).length;
|
|
1833
|
-
if (propCount === 0) {
|
|
1834
|
-
return true;
|
|
1835
|
-
}
|
|
1836
|
-
if (propCount === 1 && (obj[textNodeName] || typeof obj[textNodeName] === "boolean" || obj[textNodeName] === 0)) {
|
|
1837
|
-
return true;
|
|
1838
|
-
}
|
|
1839
|
-
return false;
|
|
1840
|
-
}
|
|
1841
|
-
node2json.prettify = prettify;
|
|
1842
|
-
return node2json;
|
|
1843
|
-
}
|
|
1844
|
-
var XMLParser_1;
|
|
1845
|
-
var hasRequiredXMLParser;
|
|
1846
|
-
function requireXMLParser() {
|
|
1847
|
-
if (hasRequiredXMLParser) return XMLParser_1;
|
|
1848
|
-
hasRequiredXMLParser = 1;
|
|
1849
|
-
const { buildOptions } = requireOptionsBuilder();
|
|
1850
|
-
const OrderedObjParser = requireOrderedObjParser();
|
|
1851
|
-
const { prettify } = requireNode2json();
|
|
1852
|
-
const validator2 = requireValidator();
|
|
1853
|
-
class XMLParser {
|
|
1854
|
-
constructor(options) {
|
|
1855
|
-
this.externalEntities = {};
|
|
1856
|
-
this.options = buildOptions(options);
|
|
1857
|
-
}
|
|
1858
|
-
/**
|
|
1859
|
-
* Parse XML dats to JS object
|
|
1860
|
-
* @param {string|Buffer} xmlData
|
|
1861
|
-
* @param {boolean|Object} validationOption
|
|
1862
|
-
*/
|
|
1863
|
-
parse(xmlData, validationOption) {
|
|
1864
|
-
if (typeof xmlData === "string") ;
|
|
1865
|
-
else if (xmlData.toString) {
|
|
1866
|
-
xmlData = xmlData.toString();
|
|
1867
|
-
} else {
|
|
1868
|
-
throw new Error("XML data is accepted in String or Bytes[] form.");
|
|
1869
|
-
}
|
|
1870
|
-
if (validationOption) {
|
|
1871
|
-
if (validationOption === true) validationOption = {};
|
|
1872
|
-
const result = validator2.validate(xmlData, validationOption);
|
|
1873
|
-
if (result !== true) {
|
|
1874
|
-
throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`);
|
|
1458
|
+
if (parser.ENTITIES[entityLC]) {
|
|
1459
|
+
return parser.ENTITIES[entityLC];
|
|
1875
1460
|
}
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
*/
|
|
1888
|
-
addEntity(key, value) {
|
|
1889
|
-
if (value.indexOf("&") !== -1) {
|
|
1890
|
-
throw new Error("Entity value can't have '&'");
|
|
1891
|
-
} else if (key.indexOf("&") !== -1 || key.indexOf(";") !== -1) {
|
|
1892
|
-
throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'");
|
|
1893
|
-
} else if (value === "&") {
|
|
1894
|
-
throw new Error("An entity with value '&' is not permitted");
|
|
1895
|
-
} else {
|
|
1896
|
-
this.externalEntities[key] = value;
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
}
|
|
1900
|
-
XMLParser_1 = XMLParser;
|
|
1901
|
-
return XMLParser_1;
|
|
1902
|
-
}
|
|
1903
|
-
var orderedJs2Xml;
|
|
1904
|
-
var hasRequiredOrderedJs2Xml;
|
|
1905
|
-
function requireOrderedJs2Xml() {
|
|
1906
|
-
if (hasRequiredOrderedJs2Xml) return orderedJs2Xml;
|
|
1907
|
-
hasRequiredOrderedJs2Xml = 1;
|
|
1908
|
-
const EOL = "\n";
|
|
1909
|
-
function toXml(jArray, options) {
|
|
1910
|
-
let indentation = "";
|
|
1911
|
-
if (options.format && options.indentBy.length > 0) {
|
|
1912
|
-
indentation = EOL;
|
|
1913
|
-
}
|
|
1914
|
-
return arrToStr(jArray, options, "", indentation);
|
|
1915
|
-
}
|
|
1916
|
-
function arrToStr(arr, options, jPath, indentation) {
|
|
1917
|
-
let xmlStr = "";
|
|
1918
|
-
let isPreviousElementTag = false;
|
|
1919
|
-
for (let i = 0; i < arr.length; i++) {
|
|
1920
|
-
const tagObj = arr[i];
|
|
1921
|
-
const tagName = propName(tagObj);
|
|
1922
|
-
if (tagName === void 0) continue;
|
|
1923
|
-
let newJPath = "";
|
|
1924
|
-
if (jPath.length === 0) newJPath = tagName;
|
|
1925
|
-
else newJPath = `${jPath}.${tagName}`;
|
|
1926
|
-
if (tagName === options.textNodeName) {
|
|
1927
|
-
let tagText = tagObj[tagName];
|
|
1928
|
-
if (!isStopNode(newJPath, options)) {
|
|
1929
|
-
tagText = options.tagValueProcessor(tagName, tagText);
|
|
1930
|
-
tagText = replaceEntitiesValue(tagText, options);
|
|
1461
|
+
entity = entityLC;
|
|
1462
|
+
if (entity.charAt(0) === "#") {
|
|
1463
|
+
if (entity.charAt(1) === "x") {
|
|
1464
|
+
entity = entity.slice(2);
|
|
1465
|
+
num = parseInt(entity, 16);
|
|
1466
|
+
numStr = num.toString(16);
|
|
1467
|
+
} else {
|
|
1468
|
+
entity = entity.slice(1);
|
|
1469
|
+
num = parseInt(entity, 10);
|
|
1470
|
+
numStr = num.toString(10);
|
|
1471
|
+
}
|
|
1931
1472
|
}
|
|
1932
|
-
|
|
1933
|
-
|
|
1473
|
+
entity = entity.replace(/^0+/, "");
|
|
1474
|
+
if (isNaN(num) || numStr.toLowerCase() !== entity) {
|
|
1475
|
+
strictFail(parser, "Invalid character entity");
|
|
1476
|
+
return "&" + parser.entity + ";";
|
|
1934
1477
|
}
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1478
|
+
return String.fromCodePoint(num);
|
|
1479
|
+
}
|
|
1480
|
+
function beginWhiteSpace(parser, c) {
|
|
1481
|
+
if (c === "<") {
|
|
1482
|
+
parser.state = S.OPEN_WAKA;
|
|
1483
|
+
parser.startTagPosition = parser.position;
|
|
1484
|
+
} else if (!isWhitespace(c)) {
|
|
1485
|
+
strictFail(parser, "Non-whitespace before first tag.");
|
|
1486
|
+
parser.textNode = c;
|
|
1487
|
+
parser.state = S.TEXT;
|
|
1941
1488
|
}
|
|
1942
|
-
xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
|
|
1943
|
-
isPreviousElementTag = false;
|
|
1944
|
-
continue;
|
|
1945
|
-
} else if (tagName === options.commentPropName) {
|
|
1946
|
-
xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
|
|
1947
|
-
isPreviousElementTag = true;
|
|
1948
|
-
continue;
|
|
1949
|
-
} else if (tagName[0] === "?") {
|
|
1950
|
-
const attStr2 = attr_to_str(tagObj[":@"], options);
|
|
1951
|
-
const tempInd = tagName === "?xml" ? "" : indentation;
|
|
1952
|
-
let piTextNodeName = tagObj[tagName][0][options.textNodeName];
|
|
1953
|
-
piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : "";
|
|
1954
|
-
xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr2}?>`;
|
|
1955
|
-
isPreviousElementTag = true;
|
|
1956
|
-
continue;
|
|
1957
|
-
}
|
|
1958
|
-
let newIdentation = indentation;
|
|
1959
|
-
if (newIdentation !== "") {
|
|
1960
|
-
newIdentation += options.indentBy;
|
|
1961
1489
|
}
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
if (options.suppressUnpairedNode) xmlStr += tagStart + ">";
|
|
1967
|
-
else xmlStr += tagStart + "/>";
|
|
1968
|
-
} else if ((!tagValue || tagValue.length === 0) && options.suppressEmptyNode) {
|
|
1969
|
-
xmlStr += tagStart + "/>";
|
|
1970
|
-
} else if (tagValue && tagValue.endsWith(">")) {
|
|
1971
|
-
xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>`;
|
|
1972
|
-
} else {
|
|
1973
|
-
xmlStr += tagStart + ">";
|
|
1974
|
-
if (tagValue && indentation !== "" && (tagValue.includes("/>") || tagValue.includes("</"))) {
|
|
1975
|
-
xmlStr += indentation + options.indentBy + tagValue + indentation;
|
|
1976
|
-
} else {
|
|
1977
|
-
xmlStr += tagValue;
|
|
1490
|
+
function charAt(chunk, i) {
|
|
1491
|
+
var result = "";
|
|
1492
|
+
if (i < chunk.length) {
|
|
1493
|
+
result = chunk.charAt(i);
|
|
1978
1494
|
}
|
|
1979
|
-
|
|
1495
|
+
return result;
|
|
1980
1496
|
}
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
function propName(obj) {
|
|
1986
|
-
const keys = Object.keys(obj);
|
|
1987
|
-
for (let i = 0; i < keys.length; i++) {
|
|
1988
|
-
const key = keys[i];
|
|
1989
|
-
if (!obj.hasOwnProperty(key)) continue;
|
|
1990
|
-
if (key !== ":@") return key;
|
|
1991
|
-
}
|
|
1992
|
-
}
|
|
1993
|
-
function attr_to_str(attrMap, options) {
|
|
1994
|
-
let attrStr = "";
|
|
1995
|
-
if (attrMap && !options.ignoreAttributes) {
|
|
1996
|
-
for (let attr in attrMap) {
|
|
1997
|
-
if (!attrMap.hasOwnProperty(attr)) continue;
|
|
1998
|
-
let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
|
|
1999
|
-
attrVal = replaceEntitiesValue(attrVal, options);
|
|
2000
|
-
if (attrVal === true && options.suppressBooleanAttributes) {
|
|
2001
|
-
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
|
|
2002
|
-
} else {
|
|
2003
|
-
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
|
|
1497
|
+
function write(chunk) {
|
|
1498
|
+
var parser = this;
|
|
1499
|
+
if (this.error) {
|
|
1500
|
+
throw this.error;
|
|
2004
1501
|
}
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
jPath = jPath.substr(0, jPath.length - options.textNodeName.length - 1);
|
|
2011
|
-
let tagName = jPath.substr(jPath.lastIndexOf(".") + 1);
|
|
2012
|
-
for (let index in options.stopNodes) {
|
|
2013
|
-
if (options.stopNodes[index] === jPath || options.stopNodes[index] === "*." + tagName) return true;
|
|
2014
|
-
}
|
|
2015
|
-
return false;
|
|
2016
|
-
}
|
|
2017
|
-
function replaceEntitiesValue(textValue, options) {
|
|
2018
|
-
if (textValue && textValue.length > 0 && options.processEntities) {
|
|
2019
|
-
for (let i = 0; i < options.entities.length; i++) {
|
|
2020
|
-
const entity = options.entities[i];
|
|
2021
|
-
textValue = textValue.replace(entity.regex, entity.val);
|
|
2022
|
-
}
|
|
2023
|
-
}
|
|
2024
|
-
return textValue;
|
|
2025
|
-
}
|
|
2026
|
-
orderedJs2Xml = toXml;
|
|
2027
|
-
return orderedJs2Xml;
|
|
2028
|
-
}
|
|
2029
|
-
var json2xml;
|
|
2030
|
-
var hasRequiredJson2xml;
|
|
2031
|
-
function requireJson2xml() {
|
|
2032
|
-
if (hasRequiredJson2xml) return json2xml;
|
|
2033
|
-
hasRequiredJson2xml = 1;
|
|
2034
|
-
const buildFromOrderedJs = requireOrderedJs2Xml();
|
|
2035
|
-
const getIgnoreAttributesFn = requireIgnoreAttributes();
|
|
2036
|
-
const defaultOptions = {
|
|
2037
|
-
attributeNamePrefix: "@_",
|
|
2038
|
-
attributesGroupName: false,
|
|
2039
|
-
textNodeName: "#text",
|
|
2040
|
-
ignoreAttributes: true,
|
|
2041
|
-
cdataPropName: false,
|
|
2042
|
-
format: false,
|
|
2043
|
-
indentBy: " ",
|
|
2044
|
-
suppressEmptyNode: false,
|
|
2045
|
-
suppressUnpairedNode: true,
|
|
2046
|
-
suppressBooleanAttributes: true,
|
|
2047
|
-
tagValueProcessor: function(key, a) {
|
|
2048
|
-
return a;
|
|
2049
|
-
},
|
|
2050
|
-
attributeValueProcessor: function(attrName, a) {
|
|
2051
|
-
return a;
|
|
2052
|
-
},
|
|
2053
|
-
preserveOrder: false,
|
|
2054
|
-
commentPropName: false,
|
|
2055
|
-
unpairedTags: [],
|
|
2056
|
-
entities: [
|
|
2057
|
-
{ regex: new RegExp("&", "g"), val: "&" },
|
|
2058
|
-
//it must be on top
|
|
2059
|
-
{ regex: new RegExp(">", "g"), val: ">" },
|
|
2060
|
-
{ regex: new RegExp("<", "g"), val: "<" },
|
|
2061
|
-
{ regex: new RegExp("'", "g"), val: "'" },
|
|
2062
|
-
{ regex: new RegExp('"', "g"), val: """ }
|
|
2063
|
-
],
|
|
2064
|
-
processEntities: true,
|
|
2065
|
-
stopNodes: [],
|
|
2066
|
-
// transformTagName: false,
|
|
2067
|
-
// transformAttributeName: false,
|
|
2068
|
-
oneListGroup: false
|
|
2069
|
-
};
|
|
2070
|
-
function Builder(options) {
|
|
2071
|
-
this.options = Object.assign({}, defaultOptions, options);
|
|
2072
|
-
if (this.options.ignoreAttributes === true || this.options.attributesGroupName) {
|
|
2073
|
-
this.isAttribute = function() {
|
|
2074
|
-
return false;
|
|
2075
|
-
};
|
|
2076
|
-
} else {
|
|
2077
|
-
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes);
|
|
2078
|
-
this.attrPrefixLen = this.options.attributeNamePrefix.length;
|
|
2079
|
-
this.isAttribute = isAttribute;
|
|
2080
|
-
}
|
|
2081
|
-
this.processTextOrObjNode = processTextOrObjNode;
|
|
2082
|
-
if (this.options.format) {
|
|
2083
|
-
this.indentate = indentate;
|
|
2084
|
-
this.tagEndChar = ">\n";
|
|
2085
|
-
this.newLine = "\n";
|
|
2086
|
-
} else {
|
|
2087
|
-
this.indentate = function() {
|
|
2088
|
-
return "";
|
|
2089
|
-
};
|
|
2090
|
-
this.tagEndChar = ">";
|
|
2091
|
-
this.newLine = "";
|
|
2092
|
-
}
|
|
2093
|
-
}
|
|
2094
|
-
Builder.prototype.build = function(jObj) {
|
|
2095
|
-
if (this.options.preserveOrder) {
|
|
2096
|
-
return buildFromOrderedJs(jObj, this.options);
|
|
2097
|
-
} else {
|
|
2098
|
-
if (Array.isArray(jObj) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1) {
|
|
2099
|
-
jObj = {
|
|
2100
|
-
[this.options.arrayNodeName]: jObj
|
|
2101
|
-
};
|
|
2102
|
-
}
|
|
2103
|
-
return this.j2x(jObj, 0, []).val;
|
|
2104
|
-
}
|
|
2105
|
-
};
|
|
2106
|
-
Builder.prototype.j2x = function(jObj, level, ajPath) {
|
|
2107
|
-
let attrStr = "";
|
|
2108
|
-
let val = "";
|
|
2109
|
-
const jPath = ajPath.join(".");
|
|
2110
|
-
for (let key in jObj) {
|
|
2111
|
-
if (!Object.prototype.hasOwnProperty.call(jObj, key)) continue;
|
|
2112
|
-
if (typeof jObj[key] === "undefined") {
|
|
2113
|
-
if (this.isAttribute(key)) {
|
|
2114
|
-
val += "";
|
|
1502
|
+
if (parser.closed) {
|
|
1503
|
+
return error(
|
|
1504
|
+
parser,
|
|
1505
|
+
"Cannot write after close. Assign an onready handler."
|
|
1506
|
+
);
|
|
2115
1507
|
}
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
val += "";
|
|
2119
|
-
} else if (key[0] === "?") {
|
|
2120
|
-
val += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
|
|
2121
|
-
} else {
|
|
2122
|
-
val += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
|
|
1508
|
+
if (chunk === null) {
|
|
1509
|
+
return end(parser);
|
|
2123
1510
|
}
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
} else if (typeof jObj[key] !== "object") {
|
|
2127
|
-
const attr = this.isAttribute(key);
|
|
2128
|
-
if (attr && !this.ignoreAttributesFn(attr, jPath)) {
|
|
2129
|
-
attrStr += this.buildAttrPairStr(attr, "" + jObj[key]);
|
|
2130
|
-
} else if (!attr) {
|
|
2131
|
-
if (key === this.options.textNodeName) {
|
|
2132
|
-
let newval = this.options.tagValueProcessor(key, "" + jObj[key]);
|
|
2133
|
-
val += this.replaceEntitiesValue(newval);
|
|
2134
|
-
} else {
|
|
2135
|
-
val += this.buildTextValNode(jObj[key], key, "", level);
|
|
2136
|
-
}
|
|
1511
|
+
if (typeof chunk === "object") {
|
|
1512
|
+
chunk = chunk.toString();
|
|
2137
1513
|
}
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
listTagVal += result.val;
|
|
2152
|
-
if (this.options.attributesGroupName && item.hasOwnProperty(this.options.attributesGroupName)) {
|
|
2153
|
-
listTagAttr += result.attrStr;
|
|
2154
|
-
}
|
|
1514
|
+
var i = 0;
|
|
1515
|
+
var c = "";
|
|
1516
|
+
while (true) {
|
|
1517
|
+
c = charAt(chunk, i++);
|
|
1518
|
+
parser.c = c;
|
|
1519
|
+
if (!c) {
|
|
1520
|
+
break;
|
|
1521
|
+
}
|
|
1522
|
+
if (parser.trackPosition) {
|
|
1523
|
+
parser.position++;
|
|
1524
|
+
if (c === "\n") {
|
|
1525
|
+
parser.line++;
|
|
1526
|
+
parser.column = 0;
|
|
2155
1527
|
} else {
|
|
2156
|
-
|
|
1528
|
+
parser.column++;
|
|
2157
1529
|
}
|
|
2158
|
-
}
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
1530
|
+
}
|
|
1531
|
+
switch (parser.state) {
|
|
1532
|
+
case S.BEGIN:
|
|
1533
|
+
parser.state = S.BEGIN_WHITESPACE;
|
|
1534
|
+
if (c === "\uFEFF") {
|
|
1535
|
+
continue;
|
|
1536
|
+
}
|
|
1537
|
+
beginWhiteSpace(parser, c);
|
|
1538
|
+
continue;
|
|
1539
|
+
case S.BEGIN_WHITESPACE:
|
|
1540
|
+
beginWhiteSpace(parser, c);
|
|
1541
|
+
continue;
|
|
1542
|
+
case S.TEXT:
|
|
1543
|
+
if (parser.sawRoot && !parser.closedRoot) {
|
|
1544
|
+
var starti = i - 1;
|
|
1545
|
+
while (c && c !== "<" && c !== "&") {
|
|
1546
|
+
c = charAt(chunk, i++);
|
|
1547
|
+
if (c && parser.trackPosition) {
|
|
1548
|
+
parser.position++;
|
|
1549
|
+
if (c === "\n") {
|
|
1550
|
+
parser.line++;
|
|
1551
|
+
parser.column = 0;
|
|
1552
|
+
} else {
|
|
1553
|
+
parser.column++;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
parser.textNode += chunk.substring(starti, i - 1);
|
|
1558
|
+
}
|
|
1559
|
+
if (c === "<" && !(parser.sawRoot && parser.closedRoot && !parser.strict)) {
|
|
1560
|
+
parser.state = S.OPEN_WAKA;
|
|
1561
|
+
parser.startTagPosition = parser.position;
|
|
1562
|
+
} else {
|
|
1563
|
+
if (!isWhitespace(c) && (!parser.sawRoot || parser.closedRoot)) {
|
|
1564
|
+
strictFail(parser, "Text data outside of root node.");
|
|
1565
|
+
}
|
|
1566
|
+
if (c === "&") {
|
|
1567
|
+
parser.state = S.TEXT_ENTITY;
|
|
1568
|
+
} else {
|
|
1569
|
+
parser.textNode += c;
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
continue;
|
|
1573
|
+
case S.SCRIPT:
|
|
1574
|
+
if (c === "<") {
|
|
1575
|
+
parser.state = S.SCRIPT_ENDING;
|
|
1576
|
+
} else {
|
|
1577
|
+
parser.script += c;
|
|
1578
|
+
}
|
|
1579
|
+
continue;
|
|
1580
|
+
case S.SCRIPT_ENDING:
|
|
1581
|
+
if (c === "/") {
|
|
1582
|
+
parser.state = S.CLOSE_TAG;
|
|
1583
|
+
} else {
|
|
1584
|
+
parser.script += "<" + c;
|
|
1585
|
+
parser.state = S.SCRIPT;
|
|
1586
|
+
}
|
|
1587
|
+
continue;
|
|
1588
|
+
case S.OPEN_WAKA:
|
|
1589
|
+
if (c === "!") {
|
|
1590
|
+
parser.state = S.SGML_DECL;
|
|
1591
|
+
parser.sgmlDecl = "";
|
|
1592
|
+
} else if (isWhitespace(c)) ;
|
|
1593
|
+
else if (isMatch(nameStart, c)) {
|
|
1594
|
+
parser.state = S.OPEN_TAG;
|
|
1595
|
+
parser.tagName = c;
|
|
1596
|
+
} else if (c === "/") {
|
|
1597
|
+
parser.state = S.CLOSE_TAG;
|
|
1598
|
+
parser.tagName = "";
|
|
1599
|
+
} else if (c === "?") {
|
|
1600
|
+
parser.state = S.PROC_INST;
|
|
1601
|
+
parser.procInstName = parser.procInstBody = "";
|
|
1602
|
+
} else {
|
|
1603
|
+
strictFail(parser, "Unencoded <");
|
|
1604
|
+
if (parser.startTagPosition + 1 < parser.position) {
|
|
1605
|
+
var pad = parser.position - parser.startTagPosition;
|
|
1606
|
+
c = new Array(pad).join(" ") + c;
|
|
1607
|
+
}
|
|
1608
|
+
parser.textNode += "<" + c;
|
|
1609
|
+
parser.state = S.TEXT;
|
|
1610
|
+
}
|
|
1611
|
+
continue;
|
|
1612
|
+
case S.SGML_DECL:
|
|
1613
|
+
if (parser.sgmlDecl + c === "--") {
|
|
1614
|
+
parser.state = S.COMMENT;
|
|
1615
|
+
parser.comment = "";
|
|
1616
|
+
parser.sgmlDecl = "";
|
|
1617
|
+
continue;
|
|
1618
|
+
}
|
|
1619
|
+
if (parser.doctype && parser.doctype !== true && parser.sgmlDecl) {
|
|
1620
|
+
parser.state = S.DOCTYPE_DTD;
|
|
1621
|
+
parser.doctype += "<!" + parser.sgmlDecl + c;
|
|
1622
|
+
parser.sgmlDecl = "";
|
|
1623
|
+
} else if ((parser.sgmlDecl + c).toUpperCase() === CDATA) {
|
|
1624
|
+
emitNode(parser, "onopencdata");
|
|
1625
|
+
parser.state = S.CDATA;
|
|
1626
|
+
parser.sgmlDecl = "";
|
|
1627
|
+
parser.cdata = "";
|
|
1628
|
+
} else if ((parser.sgmlDecl + c).toUpperCase() === DOCTYPE) {
|
|
1629
|
+
parser.state = S.DOCTYPE;
|
|
1630
|
+
if (parser.doctype || parser.sawRoot) {
|
|
1631
|
+
strictFail(
|
|
1632
|
+
parser,
|
|
1633
|
+
"Inappropriately located doctype declaration"
|
|
1634
|
+
);
|
|
1635
|
+
}
|
|
1636
|
+
parser.doctype = "";
|
|
1637
|
+
parser.sgmlDecl = "";
|
|
1638
|
+
} else if (c === ">") {
|
|
1639
|
+
emitNode(parser, "onsgmldeclaration", parser.sgmlDecl);
|
|
1640
|
+
parser.sgmlDecl = "";
|
|
1641
|
+
parser.state = S.TEXT;
|
|
1642
|
+
} else if (isQuote(c)) {
|
|
1643
|
+
parser.state = S.SGML_DECL_QUOTED;
|
|
1644
|
+
parser.sgmlDecl += c;
|
|
1645
|
+
} else {
|
|
1646
|
+
parser.sgmlDecl += c;
|
|
1647
|
+
}
|
|
1648
|
+
continue;
|
|
1649
|
+
case S.SGML_DECL_QUOTED:
|
|
1650
|
+
if (c === parser.q) {
|
|
1651
|
+
parser.state = S.SGML_DECL;
|
|
1652
|
+
parser.q = "";
|
|
1653
|
+
}
|
|
1654
|
+
parser.sgmlDecl += c;
|
|
1655
|
+
continue;
|
|
1656
|
+
case S.DOCTYPE:
|
|
1657
|
+
if (c === ">") {
|
|
1658
|
+
parser.state = S.TEXT;
|
|
1659
|
+
emitNode(parser, "ondoctype", parser.doctype);
|
|
1660
|
+
parser.doctype = true;
|
|
1661
|
+
} else {
|
|
1662
|
+
parser.doctype += c;
|
|
1663
|
+
if (c === "[") {
|
|
1664
|
+
parser.state = S.DOCTYPE_DTD;
|
|
1665
|
+
} else if (isQuote(c)) {
|
|
1666
|
+
parser.state = S.DOCTYPE_QUOTED;
|
|
1667
|
+
parser.q = c;
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
continue;
|
|
1671
|
+
case S.DOCTYPE_QUOTED:
|
|
1672
|
+
parser.doctype += c;
|
|
1673
|
+
if (c === parser.q) {
|
|
1674
|
+
parser.q = "";
|
|
1675
|
+
parser.state = S.DOCTYPE;
|
|
1676
|
+
}
|
|
1677
|
+
continue;
|
|
1678
|
+
case S.DOCTYPE_DTD:
|
|
1679
|
+
if (c === "]") {
|
|
1680
|
+
parser.doctype += c;
|
|
1681
|
+
parser.state = S.DOCTYPE;
|
|
1682
|
+
} else if (c === "<") {
|
|
1683
|
+
parser.state = S.OPEN_WAKA;
|
|
1684
|
+
parser.startTagPosition = parser.position;
|
|
1685
|
+
} else if (isQuote(c)) {
|
|
1686
|
+
parser.doctype += c;
|
|
1687
|
+
parser.state = S.DOCTYPE_DTD_QUOTED;
|
|
1688
|
+
parser.q = c;
|
|
1689
|
+
} else {
|
|
1690
|
+
parser.doctype += c;
|
|
1691
|
+
}
|
|
1692
|
+
continue;
|
|
1693
|
+
case S.DOCTYPE_DTD_QUOTED:
|
|
1694
|
+
parser.doctype += c;
|
|
1695
|
+
if (c === parser.q) {
|
|
1696
|
+
parser.state = S.DOCTYPE_DTD;
|
|
1697
|
+
parser.q = "";
|
|
1698
|
+
}
|
|
1699
|
+
continue;
|
|
1700
|
+
case S.COMMENT:
|
|
1701
|
+
if (c === "-") {
|
|
1702
|
+
parser.state = S.COMMENT_ENDING;
|
|
1703
|
+
} else {
|
|
1704
|
+
parser.comment += c;
|
|
1705
|
+
}
|
|
1706
|
+
continue;
|
|
1707
|
+
case S.COMMENT_ENDING:
|
|
1708
|
+
if (c === "-") {
|
|
1709
|
+
parser.state = S.COMMENT_ENDED;
|
|
1710
|
+
parser.comment = textopts(parser.opt, parser.comment);
|
|
1711
|
+
if (parser.comment) {
|
|
1712
|
+
emitNode(parser, "oncomment", parser.comment);
|
|
1713
|
+
}
|
|
1714
|
+
parser.comment = "";
|
|
1715
|
+
} else {
|
|
1716
|
+
parser.comment += "-" + c;
|
|
1717
|
+
parser.state = S.COMMENT;
|
|
1718
|
+
}
|
|
1719
|
+
continue;
|
|
1720
|
+
case S.COMMENT_ENDED:
|
|
1721
|
+
if (c !== ">") {
|
|
1722
|
+
strictFail(parser, "Malformed comment");
|
|
1723
|
+
parser.comment += "--" + c;
|
|
1724
|
+
parser.state = S.COMMENT;
|
|
1725
|
+
} else if (parser.doctype && parser.doctype !== true) {
|
|
1726
|
+
parser.state = S.DOCTYPE_DTD;
|
|
1727
|
+
} else {
|
|
1728
|
+
parser.state = S.TEXT;
|
|
1729
|
+
}
|
|
1730
|
+
continue;
|
|
1731
|
+
case S.CDATA:
|
|
1732
|
+
if (c === "]") {
|
|
1733
|
+
parser.state = S.CDATA_ENDING;
|
|
1734
|
+
} else {
|
|
1735
|
+
parser.cdata += c;
|
|
1736
|
+
}
|
|
1737
|
+
continue;
|
|
1738
|
+
case S.CDATA_ENDING:
|
|
1739
|
+
if (c === "]") {
|
|
1740
|
+
parser.state = S.CDATA_ENDING_2;
|
|
1741
|
+
} else {
|
|
1742
|
+
parser.cdata += "]" + c;
|
|
1743
|
+
parser.state = S.CDATA;
|
|
1744
|
+
}
|
|
1745
|
+
continue;
|
|
1746
|
+
case S.CDATA_ENDING_2:
|
|
1747
|
+
if (c === ">") {
|
|
1748
|
+
if (parser.cdata) {
|
|
1749
|
+
emitNode(parser, "oncdata", parser.cdata);
|
|
1750
|
+
}
|
|
1751
|
+
emitNode(parser, "onclosecdata");
|
|
1752
|
+
parser.cdata = "";
|
|
1753
|
+
parser.state = S.TEXT;
|
|
1754
|
+
} else if (c === "]") {
|
|
1755
|
+
parser.cdata += "]";
|
|
1756
|
+
} else {
|
|
1757
|
+
parser.cdata += "]]" + c;
|
|
1758
|
+
parser.state = S.CDATA;
|
|
1759
|
+
}
|
|
1760
|
+
continue;
|
|
1761
|
+
case S.PROC_INST:
|
|
1762
|
+
if (c === "?") {
|
|
1763
|
+
parser.state = S.PROC_INST_ENDING;
|
|
1764
|
+
} else if (isWhitespace(c)) {
|
|
1765
|
+
parser.state = S.PROC_INST_BODY;
|
|
1766
|
+
} else {
|
|
1767
|
+
parser.procInstName += c;
|
|
1768
|
+
}
|
|
1769
|
+
continue;
|
|
1770
|
+
case S.PROC_INST_BODY:
|
|
1771
|
+
if (!parser.procInstBody && isWhitespace(c)) {
|
|
1772
|
+
continue;
|
|
1773
|
+
} else if (c === "?") {
|
|
1774
|
+
parser.state = S.PROC_INST_ENDING;
|
|
1775
|
+
} else {
|
|
1776
|
+
parser.procInstBody += c;
|
|
1777
|
+
}
|
|
1778
|
+
continue;
|
|
1779
|
+
case S.PROC_INST_ENDING:
|
|
1780
|
+
if (c === ">") {
|
|
1781
|
+
emitNode(parser, "onprocessinginstruction", {
|
|
1782
|
+
name: parser.procInstName,
|
|
1783
|
+
body: parser.procInstBody
|
|
1784
|
+
});
|
|
1785
|
+
parser.procInstName = parser.procInstBody = "";
|
|
1786
|
+
parser.state = S.TEXT;
|
|
1787
|
+
} else {
|
|
1788
|
+
parser.procInstBody += "?" + c;
|
|
1789
|
+
parser.state = S.PROC_INST_BODY;
|
|
1790
|
+
}
|
|
1791
|
+
continue;
|
|
1792
|
+
case S.OPEN_TAG:
|
|
1793
|
+
if (isMatch(nameBody, c)) {
|
|
1794
|
+
parser.tagName += c;
|
|
1795
|
+
} else {
|
|
1796
|
+
newTag(parser);
|
|
1797
|
+
if (c === ">") {
|
|
1798
|
+
openTag(parser);
|
|
1799
|
+
} else if (c === "/") {
|
|
1800
|
+
parser.state = S.OPEN_TAG_SLASH;
|
|
1801
|
+
} else {
|
|
1802
|
+
if (!isWhitespace(c)) {
|
|
1803
|
+
strictFail(parser, "Invalid character in tag name");
|
|
1804
|
+
}
|
|
1805
|
+
parser.state = S.ATTRIB;
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
continue;
|
|
1809
|
+
case S.OPEN_TAG_SLASH:
|
|
1810
|
+
if (c === ">") {
|
|
1811
|
+
openTag(parser, true);
|
|
1812
|
+
closeTag(parser);
|
|
1813
|
+
} else {
|
|
1814
|
+
strictFail(parser, "Forward-slash in opening tag not followed by >");
|
|
1815
|
+
parser.state = S.ATTRIB;
|
|
1816
|
+
}
|
|
1817
|
+
continue;
|
|
1818
|
+
case S.ATTRIB:
|
|
1819
|
+
if (isWhitespace(c)) {
|
|
1820
|
+
continue;
|
|
1821
|
+
} else if (c === ">") {
|
|
1822
|
+
openTag(parser);
|
|
1823
|
+
} else if (c === "/") {
|
|
1824
|
+
parser.state = S.OPEN_TAG_SLASH;
|
|
1825
|
+
} else if (isMatch(nameStart, c)) {
|
|
1826
|
+
parser.attribName = c;
|
|
1827
|
+
parser.attribValue = "";
|
|
1828
|
+
parser.state = S.ATTRIB_NAME;
|
|
1829
|
+
} else {
|
|
1830
|
+
strictFail(parser, "Invalid attribute name");
|
|
1831
|
+
}
|
|
1832
|
+
continue;
|
|
1833
|
+
case S.ATTRIB_NAME:
|
|
1834
|
+
if (c === "=") {
|
|
1835
|
+
parser.state = S.ATTRIB_VALUE;
|
|
1836
|
+
} else if (c === ">") {
|
|
1837
|
+
strictFail(parser, "Attribute without value");
|
|
1838
|
+
parser.attribValue = parser.attribName;
|
|
1839
|
+
attrib(parser);
|
|
1840
|
+
openTag(parser);
|
|
1841
|
+
} else if (isWhitespace(c)) {
|
|
1842
|
+
parser.state = S.ATTRIB_NAME_SAW_WHITE;
|
|
1843
|
+
} else if (isMatch(nameBody, c)) {
|
|
1844
|
+
parser.attribName += c;
|
|
1845
|
+
} else {
|
|
1846
|
+
strictFail(parser, "Invalid attribute name");
|
|
1847
|
+
}
|
|
1848
|
+
continue;
|
|
1849
|
+
case S.ATTRIB_NAME_SAW_WHITE:
|
|
1850
|
+
if (c === "=") {
|
|
1851
|
+
parser.state = S.ATTRIB_VALUE;
|
|
1852
|
+
} else if (isWhitespace(c)) {
|
|
1853
|
+
continue;
|
|
1854
|
+
} else {
|
|
1855
|
+
strictFail(parser, "Attribute without value");
|
|
1856
|
+
parser.tag.attributes[parser.attribName] = "";
|
|
1857
|
+
parser.attribValue = "";
|
|
1858
|
+
emitNode(parser, "onattribute", {
|
|
1859
|
+
name: parser.attribName,
|
|
1860
|
+
value: ""
|
|
1861
|
+
});
|
|
1862
|
+
parser.attribName = "";
|
|
1863
|
+
if (c === ">") {
|
|
1864
|
+
openTag(parser);
|
|
1865
|
+
} else if (isMatch(nameStart, c)) {
|
|
1866
|
+
parser.attribName = c;
|
|
1867
|
+
parser.state = S.ATTRIB_NAME;
|
|
1868
|
+
} else {
|
|
1869
|
+
strictFail(parser, "Invalid attribute name");
|
|
1870
|
+
parser.state = S.ATTRIB;
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
continue;
|
|
1874
|
+
case S.ATTRIB_VALUE:
|
|
1875
|
+
if (isWhitespace(c)) {
|
|
1876
|
+
continue;
|
|
1877
|
+
} else if (isQuote(c)) {
|
|
1878
|
+
parser.q = c;
|
|
1879
|
+
parser.state = S.ATTRIB_VALUE_QUOTED;
|
|
1880
|
+
} else {
|
|
1881
|
+
if (!parser.opt.unquotedAttributeValues) {
|
|
1882
|
+
error(parser, "Unquoted attribute value");
|
|
1883
|
+
}
|
|
1884
|
+
parser.state = S.ATTRIB_VALUE_UNQUOTED;
|
|
1885
|
+
parser.attribValue = c;
|
|
1886
|
+
}
|
|
1887
|
+
continue;
|
|
1888
|
+
case S.ATTRIB_VALUE_QUOTED:
|
|
1889
|
+
if (c !== parser.q) {
|
|
1890
|
+
if (c === "&") {
|
|
1891
|
+
parser.state = S.ATTRIB_VALUE_ENTITY_Q;
|
|
1892
|
+
} else {
|
|
1893
|
+
parser.attribValue += c;
|
|
1894
|
+
}
|
|
1895
|
+
continue;
|
|
1896
|
+
}
|
|
1897
|
+
attrib(parser);
|
|
1898
|
+
parser.q = "";
|
|
1899
|
+
parser.state = S.ATTRIB_VALUE_CLOSED;
|
|
1900
|
+
continue;
|
|
1901
|
+
case S.ATTRIB_VALUE_CLOSED:
|
|
1902
|
+
if (isWhitespace(c)) {
|
|
1903
|
+
parser.state = S.ATTRIB;
|
|
1904
|
+
} else if (c === ">") {
|
|
1905
|
+
openTag(parser);
|
|
1906
|
+
} else if (c === "/") {
|
|
1907
|
+
parser.state = S.OPEN_TAG_SLASH;
|
|
1908
|
+
} else if (isMatch(nameStart, c)) {
|
|
1909
|
+
strictFail(parser, "No whitespace between attributes");
|
|
1910
|
+
parser.attribName = c;
|
|
1911
|
+
parser.attribValue = "";
|
|
1912
|
+
parser.state = S.ATTRIB_NAME;
|
|
1913
|
+
} else {
|
|
1914
|
+
strictFail(parser, "Invalid attribute name");
|
|
1915
|
+
}
|
|
1916
|
+
continue;
|
|
1917
|
+
case S.ATTRIB_VALUE_UNQUOTED:
|
|
1918
|
+
if (!isAttribEnd(c)) {
|
|
1919
|
+
if (c === "&") {
|
|
1920
|
+
parser.state = S.ATTRIB_VALUE_ENTITY_U;
|
|
1921
|
+
} else {
|
|
1922
|
+
parser.attribValue += c;
|
|
1923
|
+
}
|
|
1924
|
+
continue;
|
|
1925
|
+
}
|
|
1926
|
+
attrib(parser);
|
|
1927
|
+
if (c === ">") {
|
|
1928
|
+
openTag(parser);
|
|
1929
|
+
} else {
|
|
1930
|
+
parser.state = S.ATTRIB;
|
|
1931
|
+
}
|
|
1932
|
+
continue;
|
|
1933
|
+
case S.CLOSE_TAG:
|
|
1934
|
+
if (!parser.tagName) {
|
|
1935
|
+
if (isWhitespace(c)) {
|
|
1936
|
+
continue;
|
|
1937
|
+
} else if (notMatch(nameStart, c)) {
|
|
1938
|
+
if (parser.script) {
|
|
1939
|
+
parser.script += "</" + c;
|
|
1940
|
+
parser.state = S.SCRIPT;
|
|
1941
|
+
} else {
|
|
1942
|
+
strictFail(parser, "Invalid tagname in closing tag.");
|
|
1943
|
+
}
|
|
1944
|
+
} else {
|
|
1945
|
+
parser.tagName = c;
|
|
1946
|
+
}
|
|
1947
|
+
} else if (c === ">") {
|
|
1948
|
+
closeTag(parser);
|
|
1949
|
+
} else if (isMatch(nameBody, c)) {
|
|
1950
|
+
parser.tagName += c;
|
|
1951
|
+
} else if (parser.script) {
|
|
1952
|
+
parser.script += "</" + parser.tagName;
|
|
1953
|
+
parser.tagName = "";
|
|
1954
|
+
parser.state = S.SCRIPT;
|
|
1955
|
+
} else {
|
|
1956
|
+
if (!isWhitespace(c)) {
|
|
1957
|
+
strictFail(parser, "Invalid tagname in closing tag");
|
|
1958
|
+
}
|
|
1959
|
+
parser.state = S.CLOSE_TAG_SAW_WHITE;
|
|
1960
|
+
}
|
|
1961
|
+
continue;
|
|
1962
|
+
case S.CLOSE_TAG_SAW_WHITE:
|
|
1963
|
+
if (isWhitespace(c)) {
|
|
1964
|
+
continue;
|
|
1965
|
+
}
|
|
1966
|
+
if (c === ">") {
|
|
1967
|
+
closeTag(parser);
|
|
1968
|
+
} else {
|
|
1969
|
+
strictFail(parser, "Invalid characters in closing tag");
|
|
1970
|
+
}
|
|
1971
|
+
continue;
|
|
1972
|
+
case S.TEXT_ENTITY:
|
|
1973
|
+
case S.ATTRIB_VALUE_ENTITY_Q:
|
|
1974
|
+
case S.ATTRIB_VALUE_ENTITY_U:
|
|
1975
|
+
var returnState;
|
|
1976
|
+
var buffer;
|
|
1977
|
+
switch (parser.state) {
|
|
1978
|
+
case S.TEXT_ENTITY:
|
|
1979
|
+
returnState = S.TEXT;
|
|
1980
|
+
buffer = "textNode";
|
|
1981
|
+
break;
|
|
1982
|
+
case S.ATTRIB_VALUE_ENTITY_Q:
|
|
1983
|
+
returnState = S.ATTRIB_VALUE_QUOTED;
|
|
1984
|
+
buffer = "attribValue";
|
|
1985
|
+
break;
|
|
1986
|
+
case S.ATTRIB_VALUE_ENTITY_U:
|
|
1987
|
+
returnState = S.ATTRIB_VALUE_UNQUOTED;
|
|
1988
|
+
buffer = "attribValue";
|
|
1989
|
+
break;
|
|
1990
|
+
}
|
|
1991
|
+
if (c === ";") {
|
|
1992
|
+
var parsedEntity = parseEntity(parser);
|
|
1993
|
+
if (parser.opt.unparsedEntities && !Object.values(sax2.XML_ENTITIES).includes(parsedEntity)) {
|
|
1994
|
+
parser.entity = "";
|
|
1995
|
+
parser.state = returnState;
|
|
1996
|
+
parser.write(parsedEntity);
|
|
1997
|
+
} else {
|
|
1998
|
+
parser[buffer] += parsedEntity;
|
|
1999
|
+
parser.entity = "";
|
|
2000
|
+
parser.state = returnState;
|
|
2001
|
+
}
|
|
2002
|
+
} else if (isMatch(parser.entity.length ? entityBody : entityStart, c)) {
|
|
2003
|
+
parser.entity += c;
|
|
2004
|
+
} else {
|
|
2005
|
+
strictFail(parser, "Invalid character in entity name");
|
|
2006
|
+
parser[buffer] += "&" + parser.entity + c;
|
|
2007
|
+
parser.entity = "";
|
|
2008
|
+
parser.state = returnState;
|
|
2009
|
+
}
|
|
2010
|
+
continue;
|
|
2011
|
+
default: {
|
|
2012
|
+
throw new Error(parser, "Unknown state: " + parser.state);
|
|
2165
2013
|
}
|
|
2166
2014
|
}
|
|
2167
2015
|
}
|
|
2168
|
-
if (
|
|
2169
|
-
|
|
2016
|
+
if (parser.position >= parser.bufferCheckPosition) {
|
|
2017
|
+
checkBufferLength(parser);
|
|
2170
2018
|
}
|
|
2171
|
-
|
|
2172
|
-
}
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2019
|
+
return parser;
|
|
2020
|
+
}
|
|
2021
|
+
/*! http://mths.be/fromcodepoint v0.1.0 by @mathias */
|
|
2022
|
+
if (!String.fromCodePoint) {
|
|
2023
|
+
(function() {
|
|
2024
|
+
var stringFromCharCode = String.fromCharCode;
|
|
2025
|
+
var floor = Math.floor;
|
|
2026
|
+
var fromCodePoint = function() {
|
|
2027
|
+
var MAX_SIZE = 16384;
|
|
2028
|
+
var codeUnits = [];
|
|
2029
|
+
var highSurrogate;
|
|
2030
|
+
var lowSurrogate;
|
|
2031
|
+
var index = -1;
|
|
2032
|
+
var length = arguments.length;
|
|
2033
|
+
if (!length) {
|
|
2034
|
+
return "";
|
|
2035
|
+
}
|
|
2036
|
+
var result = "";
|
|
2037
|
+
while (++index < length) {
|
|
2038
|
+
var codePoint = Number(arguments[index]);
|
|
2039
|
+
if (!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
|
|
2040
|
+
codePoint < 0 || // not a valid Unicode code point
|
|
2041
|
+
codePoint > 1114111 || // not a valid Unicode code point
|
|
2042
|
+
floor(codePoint) !== codePoint) {
|
|
2043
|
+
throw RangeError("Invalid code point: " + codePoint);
|
|
2044
|
+
}
|
|
2045
|
+
if (codePoint <= 65535) {
|
|
2046
|
+
codeUnits.push(codePoint);
|
|
2047
|
+
} else {
|
|
2048
|
+
codePoint -= 65536;
|
|
2049
|
+
highSurrogate = (codePoint >> 10) + 55296;
|
|
2050
|
+
lowSurrogate = codePoint % 1024 + 56320;
|
|
2051
|
+
codeUnits.push(highSurrogate, lowSurrogate);
|
|
2052
|
+
}
|
|
2053
|
+
if (index + 1 === length || codeUnits.length > MAX_SIZE) {
|
|
2054
|
+
result += stringFromCharCode.apply(null, codeUnits);
|
|
2055
|
+
codeUnits.length = 0;
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
return result;
|
|
2059
|
+
};
|
|
2060
|
+
if (Object.defineProperty) {
|
|
2061
|
+
Object.defineProperty(String, "fromCodePoint", {
|
|
2062
|
+
value: fromCodePoint,
|
|
2063
|
+
configurable: true,
|
|
2064
|
+
writable: true
|
|
2065
|
+
});
|
|
2066
|
+
} else {
|
|
2067
|
+
String.fromCodePoint = fromCodePoint;
|
|
2178
2068
|
}
|
|
2179
|
-
}
|
|
2180
|
-
val += this.processTextOrObjNode(jObj[key], key, level, ajPath);
|
|
2181
|
-
}
|
|
2069
|
+
})();
|
|
2182
2070
|
}
|
|
2183
|
-
}
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2071
|
+
})(exports2);
|
|
2072
|
+
})(sax$1);
|
|
2073
|
+
return sax$1;
|
|
2074
|
+
}
|
|
2075
|
+
var saxExports = requireSax();
|
|
2076
|
+
const sax = /* @__PURE__ */ getDefaultExportFromCjs(saxExports);
|
|
2077
|
+
const namespaceMapping = {
|
|
2078
|
+
"http://www.w3.org/2000/svg": {
|
|
2079
|
+
ext: "svg",
|
|
2080
|
+
mime: "image/svg+xml"
|
|
2081
|
+
},
|
|
2082
|
+
"http://www.w3.org/1999/xhtml": {
|
|
2083
|
+
ext: "xhtml",
|
|
2084
|
+
mime: "application/xhtml+xml"
|
|
2085
|
+
},
|
|
2086
|
+
"http://www.opengis.net/kml/2.2": {
|
|
2087
|
+
ext: "kml",
|
|
2088
|
+
mime: "application/vnd.google-earth.kml+xml"
|
|
2089
|
+
},
|
|
2090
|
+
"http://www.opengis.net/gml": {
|
|
2091
|
+
ext: "gml",
|
|
2092
|
+
mime: "application/gml+xml"
|
|
2200
2093
|
}
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2094
|
+
};
|
|
2095
|
+
const rootNameMapping = {
|
|
2096
|
+
rss: {
|
|
2097
|
+
ext: "rss",
|
|
2098
|
+
mime: "application/rss+xml"
|
|
2099
|
+
},
|
|
2100
|
+
"score-partwise": {
|
|
2101
|
+
ext: "musicxml",
|
|
2102
|
+
mime: "application/vnd.recordare.musicxml+xml"
|
|
2103
|
+
},
|
|
2104
|
+
svg: {
|
|
2105
|
+
ext: "svg",
|
|
2106
|
+
mime: "image/svg+xml"
|
|
2107
|
+
}
|
|
2108
|
+
};
|
|
2109
|
+
class XmlTextDetector {
|
|
2110
|
+
constructor(options) {
|
|
2111
|
+
this.options = options ?? {};
|
|
2112
|
+
this.firstTag = true;
|
|
2113
|
+
this.onEnd = false;
|
|
2114
|
+
this.parser = sax.parser(true, { xmlns: true });
|
|
2115
|
+
this.nesting = 0;
|
|
2116
|
+
this.parser.onerror = (e) => {
|
|
2117
|
+
if (e.message.startsWith("Invalid character entity")) {
|
|
2118
|
+
return;
|
|
2213
2119
|
}
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2120
|
+
this.fileType = void 0;
|
|
2121
|
+
this.onEnd = true;
|
|
2122
|
+
};
|
|
2123
|
+
this.parser.onopentag = (node) => {
|
|
2124
|
+
++this.nesting;
|
|
2125
|
+
if (!this.firstTag || this.onEnd) {
|
|
2126
|
+
return;
|
|
2220
2127
|
}
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
if (!this.options.suppressUnpairedNode) closeTag = "/";
|
|
2227
|
-
} else if (this.options.suppressEmptyNode) {
|
|
2228
|
-
closeTag = "/";
|
|
2229
|
-
} else {
|
|
2230
|
-
closeTag = `></${key}`;
|
|
2231
|
-
}
|
|
2232
|
-
return closeTag;
|
|
2233
|
-
};
|
|
2234
|
-
Builder.prototype.buildTextValNode = function(val, key, attrStr, level) {
|
|
2235
|
-
if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
|
|
2236
|
-
return this.indentate(level) + `<![CDATA[${val}]]>` + this.newLine;
|
|
2237
|
-
} else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
|
|
2238
|
-
return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
2239
|
-
} else if (key[0] === "?") {
|
|
2240
|
-
return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
|
|
2241
|
-
} else {
|
|
2242
|
-
let textValue = this.options.tagValueProcessor(key, val);
|
|
2243
|
-
textValue = this.replaceEntitiesValue(textValue);
|
|
2244
|
-
if (textValue === "") {
|
|
2245
|
-
return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
|
|
2246
|
-
} else {
|
|
2247
|
-
return this.indentate(level) + "<" + key + attrStr + ">" + textValue + "</" + key + this.tagEndChar;
|
|
2128
|
+
this.firstTag = false;
|
|
2129
|
+
if (node.uri) {
|
|
2130
|
+
this.fileType = namespaceMapping[node.uri];
|
|
2131
|
+
} else if (node.name) {
|
|
2132
|
+
this.fileType = rootNameMapping[node.name.toLowerCase()];
|
|
2248
2133
|
}
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
Builder.prototype.replaceEntitiesValue = function(textValue) {
|
|
2252
|
-
if (textValue && textValue.length > 0 && this.options.processEntities) {
|
|
2253
|
-
for (let i = 0; i < this.options.entities.length; i++) {
|
|
2254
|
-
const entity = this.options.entities[i];
|
|
2255
|
-
textValue = textValue.replace(entity.regex, entity.val);
|
|
2134
|
+
if (this.fileType && !this.options.fullScan) {
|
|
2135
|
+
this.onEnd = true;
|
|
2256
2136
|
}
|
|
2257
|
-
}
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
return this.options.indentBy.repeat(level);
|
|
2137
|
+
};
|
|
2138
|
+
this.parser.onclosetag = () => {
|
|
2139
|
+
--this.nesting;
|
|
2140
|
+
};
|
|
2262
2141
|
}
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2142
|
+
write(text) {
|
|
2143
|
+
this.parser.write(text);
|
|
2144
|
+
}
|
|
2145
|
+
close() {
|
|
2146
|
+
this.parser.close();
|
|
2147
|
+
this.onEnd = true;
|
|
2148
|
+
}
|
|
2149
|
+
isValid() {
|
|
2150
|
+
return this.nesting === 0;
|
|
2269
2151
|
}
|
|
2270
|
-
json2xml = Builder;
|
|
2271
|
-
return json2xml;
|
|
2272
|
-
}
|
|
2273
|
-
var fxp;
|
|
2274
|
-
var hasRequiredFxp;
|
|
2275
|
-
function requireFxp() {
|
|
2276
|
-
if (hasRequiredFxp) return fxp;
|
|
2277
|
-
hasRequiredFxp = 1;
|
|
2278
|
-
const validator2 = requireValidator();
|
|
2279
|
-
const XMLParser = requireXMLParser();
|
|
2280
|
-
const XMLBuilder = requireJson2xml();
|
|
2281
|
-
fxp = {
|
|
2282
|
-
XMLParser,
|
|
2283
|
-
XMLValidator: validator2,
|
|
2284
|
-
XMLBuilder
|
|
2285
|
-
};
|
|
2286
|
-
return fxp;
|
|
2287
2152
|
}
|
|
2288
|
-
var fxpExports = requireFxp();
|
|
2289
2153
|
function isSvg(string) {
|
|
2290
2154
|
if (typeof string !== "string") {
|
|
2291
2155
|
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
@@ -2294,23 +2158,9 @@ function isSvg(string) {
|
|
|
2294
2158
|
if (string.length === 0) {
|
|
2295
2159
|
return false;
|
|
2296
2160
|
}
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
let jsonObject;
|
|
2301
|
-
const parser = new fxpExports.XMLParser();
|
|
2302
|
-
try {
|
|
2303
|
-
jsonObject = parser.parse(string);
|
|
2304
|
-
} catch {
|
|
2305
|
-
return false;
|
|
2306
|
-
}
|
|
2307
|
-
if (!jsonObject) {
|
|
2308
|
-
return false;
|
|
2309
|
-
}
|
|
2310
|
-
if (!Object.keys(jsonObject).some((x) => x.toLowerCase() === "svg")) {
|
|
2311
|
-
return false;
|
|
2312
|
-
}
|
|
2313
|
-
return true;
|
|
2161
|
+
const xmlTextDetector = new XmlTextDetector();
|
|
2162
|
+
xmlTextDetector.write(string);
|
|
2163
|
+
return xmlTextDetector.isValid() && xmlTextDetector.fileType?.ext === "svg";
|
|
2314
2164
|
}
|
|
2315
2165
|
class View {
|
|
2316
2166
|
_view;
|
|
@@ -2336,6 +2186,9 @@ class View {
|
|
|
2336
2186
|
get getContents() {
|
|
2337
2187
|
return this._view.getContents;
|
|
2338
2188
|
}
|
|
2189
|
+
get hidden() {
|
|
2190
|
+
return this._view.hidden;
|
|
2191
|
+
}
|
|
2339
2192
|
get icon() {
|
|
2340
2193
|
return this._view.icon;
|
|
2341
2194
|
}
|
|
@@ -2392,6 +2245,9 @@ const isValidView = function(view) {
|
|
|
2392
2245
|
if (!view.getContents || typeof view.getContents !== "function") {
|
|
2393
2246
|
throw new Error("View getContents is required and must be a function");
|
|
2394
2247
|
}
|
|
2248
|
+
if ("hidden" in view && typeof view.hidden !== "boolean") {
|
|
2249
|
+
throw new Error("View hidden must be a boolean");
|
|
2250
|
+
}
|
|
2395
2251
|
if (!view.icon || typeof view.icon !== "string" || !isSvg(view.icon)) {
|
|
2396
2252
|
throw new Error("View icon is required and must be a valid svg string");
|
|
2397
2253
|
}
|
|
@@ -2905,7 +2761,7 @@ class ProxyBus {
|
|
|
2905
2761
|
this.bus = bus2;
|
|
2906
2762
|
}
|
|
2907
2763
|
getVersion() {
|
|
2908
|
-
return "3.3.
|
|
2764
|
+
return "3.3.2";
|
|
2909
2765
|
}
|
|
2910
2766
|
subscribe(name, handler) {
|
|
2911
2767
|
this.bus.subscribe(name, handler);
|
|
@@ -2913,14 +2769,14 @@ class ProxyBus {
|
|
|
2913
2769
|
unsubscribe(name, handler) {
|
|
2914
2770
|
this.bus.unsubscribe(name, handler);
|
|
2915
2771
|
}
|
|
2916
|
-
emit(name, event) {
|
|
2917
|
-
this.bus.emit(name, event);
|
|
2772
|
+
emit(name, ...event) {
|
|
2773
|
+
this.bus.emit(name, ...event);
|
|
2918
2774
|
}
|
|
2919
2775
|
}
|
|
2920
2776
|
class SimpleBus {
|
|
2921
2777
|
handlers = /* @__PURE__ */ new Map();
|
|
2922
2778
|
getVersion() {
|
|
2923
|
-
return "3.3.
|
|
2779
|
+
return "3.3.2";
|
|
2924
2780
|
}
|
|
2925
2781
|
subscribe(name, handler) {
|
|
2926
2782
|
this.handlers.set(
|
|
@@ -2936,10 +2792,12 @@ class SimpleBus {
|
|
|
2936
2792
|
(this.handlers.get(name) || []).filter((h) => h !== handler)
|
|
2937
2793
|
);
|
|
2938
2794
|
}
|
|
2939
|
-
emit(name, event) {
|
|
2940
|
-
|
|
2795
|
+
emit(name, ...event) {
|
|
2796
|
+
const handlers = this.handlers.get(name) || [];
|
|
2797
|
+
handlers.forEach((h) => {
|
|
2941
2798
|
try {
|
|
2942
|
-
|
|
2799
|
+
;
|
|
2800
|
+
h(event[0]);
|
|
2943
2801
|
} catch (e) {
|
|
2944
2802
|
console.error("could not invoke event listener", e);
|
|
2945
2803
|
}
|
|
@@ -2973,8 +2831,8 @@ function getBus() {
|
|
|
2973
2831
|
}
|
|
2974
2832
|
return bus;
|
|
2975
2833
|
}
|
|
2976
|
-
function emit(name, event) {
|
|
2977
|
-
getBus().emit(name, event);
|
|
2834
|
+
function emit(name, ...event) {
|
|
2835
|
+
getBus().emit(name, ...event);
|
|
2978
2836
|
}
|
|
2979
2837
|
/*!
|
|
2980
2838
|
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
|
@@ -3091,3 +2949,4 @@ exports.removeNewFileMenuEntry = removeNewFileMenuEntry;
|
|
|
3091
2949
|
exports.sortNodes = sortNodes;
|
|
3092
2950
|
exports.unregisterFileListFilter = unregisterFileListFilter;
|
|
3093
2951
|
exports.validateFilename = validateFilename;
|
|
2952
|
+
//# sourceMappingURL=index.cjs.map
|