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