react-xml-viewer
Version:
Simple xml viewer component for React
1,377 lines (1,376 loc) • 51.5 kB
JavaScript
import { jsx as d, jsxs as E, Fragment as q } from "react/jsx-runtime";
import * as G from "react";
import { createContext as J, useState as P, useCallback as Ne, useMemo as O, useContext as j, useRef as Q, useEffect as $ } from "react";
const K = ":@", V = "#text", _ = "#comment", k = "#cdata", H = "DECLARATION_TAG", be = "TAG", L = {
tagColor: "#d43900",
textColor: "#333",
attributeKeyColor: "#2a7ab0",
attributeValueColor: "#008000",
separatorColor: "#333",
commentColor: "#aaa",
cdataColor: "#1d781d",
fontFamily: "monospace",
lineNumberBackground: "#eee",
lineNumberColor: "#222"
}, me = {
lines: {},
push: () => {
}
}, D = J(me), Te = ({ children: e }) => {
const [t, n] = P({}), r = Ne((s, u) => {
n((l) => {
var o;
return ((o = l[s]) == null ? void 0 : o.element) === u.element ? l : { ...l, [s]: u };
});
}, []), i = O(() => ({ lines: t, push: r }), [t, r]);
return /* @__PURE__ */ d(D.Provider, { value: i, children: e });
}, ee = () => j(D), ye = {
theme: L,
collapsible: !1,
indentSize: 2
}, te = J(ye), y = () => j(te);
function Ee(e, t) {
return new Array(t * e + 1).join(" ");
}
function ne(e) {
return typeof e == "string" && e.includes(`
`);
}
function Ce(e) {
return typeof e == "string" ? !1 : e.length === 1 && V in e[0] && !ne(e[0][V]);
}
function Ae(e) {
switch (e) {
case V:
case k:
case _:
return e;
default:
return e.startsWith("?") ? H : be;
}
}
function we(e, t) {
const n = {};
for (const r in e)
r !== t && (n[r] = e[r]);
return n;
}
function ve(e) {
const t = e[K], n = we(e, K), [[r, i]] = Object.entries(n), s = Ae(r);
return { attributes: t, tagKey: r, subElements: i, type: s };
}
function Ie(e, t) {
return Object.keys(L).every((r) => e[r] === t[r]);
}
var B = {}, S = {};
(function(e) {
const t = ":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", n = t + "\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040", r = "[" + t + "][" + n + "]*", i = new RegExp("^" + r + "$"), s = function(l, o) {
const f = [];
let a = o.exec(l);
for (; a; ) {
const c = [];
c.startIndex = o.lastIndex - a[0].length;
const h = a.length;
for (let g = 0; g < h; g++)
c.push(a[g]);
f.push(c), a = o.exec(l);
}
return f;
}, u = function(l) {
const o = i.exec(l);
return !(o === null || typeof o > "u");
};
e.isExist = function(l) {
return typeof l < "u";
}, e.isEmptyObject = function(l) {
return Object.keys(l).length === 0;
}, e.merge = function(l, o, f) {
if (o) {
const a = Object.keys(o), c = a.length;
for (let h = 0; h < c; h++)
f === "strict" ? l[a[h]] = [o[a[h]]] : l[a[h]] = o[a[h]];
}
}, e.getValue = function(l) {
return e.isExist(l) ? l : "";
}, e.isName = u, e.getAllMatches = s, e.nameRegexp = r;
})(S);
const X = S, Pe = {
allowBooleanAttributes: !1,
//A tag can have attributes without any value
unpairedTags: []
};
B.validate = function(e, t) {
t = Object.assign({}, Pe, t);
const n = [];
let r = !1, i = !1;
e[0] === "\uFEFF" && (e = e.substr(1));
for (let s = 0; s < e.length; s++)
if (e[s] === "<" && e[s + 1] === "?") {
if (s += 2, s = Z(e, s), s.err)
return s;
} else if (e[s] === "<") {
let u = s;
if (s++, e[s] === "!") {
s = W(e, s);
continue;
} else {
let l = !1;
e[s] === "/" && (l = !0, s++);
let o = "";
for (; s < e.length && e[s] !== ">" && e[s] !== " " && e[s] !== " " && e[s] !== `
` && e[s] !== "\r"; s++)
o += e[s];
if (o = o.trim(), o[o.length - 1] === "/" && (o = o.substring(0, o.length - 1), s--), !Re(o)) {
let c;
return o.trim().length === 0 ? c = "Invalid space after '<'." : c = "Tag '" + o + "' is an invalid name.", N("InvalidTag", c, b(e, s));
}
const f = xe(e, s);
if (f === !1)
return N("InvalidAttr", "Attributes for '" + o + "' have open quote.", b(e, s));
let a = f.value;
if (s = f.index, a[a.length - 1] === "/") {
const c = s - a.length;
a = a.substring(0, a.length - 1);
const h = Y(a, t);
if (h === !0)
r = !0;
else
return N(h.err.code, h.err.msg, b(e, c + h.err.line));
} else if (l)
if (f.tagClosed) {
if (a.trim().length > 0)
return N("InvalidTag", "Closing tag '" + o + "' can't have attributes or invalid starting.", b(e, u));
if (n.length === 0)
return N("InvalidTag", "Closing tag '" + o + "' has not been opened.", b(e, u));
{
const c = n.pop();
if (o !== c.tagName) {
let h = b(e, c.tagStartPos);
return N(
"InvalidTag",
"Expected closing tag '" + c.tagName + "' (opened in line " + h.line + ", col " + h.col + ") instead of closing tag '" + o + "'.",
b(e, u)
);
}
n.length == 0 && (i = !0);
}
} else
return N("InvalidTag", "Closing tag '" + o + "' doesn't have proper closing.", b(e, s));
else {
const c = Y(a, t);
if (c !== !0)
return N(c.err.code, c.err.msg, b(e, s - a.length + c.err.line));
if (i === !0)
return N("InvalidXml", "Multiple possible root nodes found.", b(e, s));
t.unpairedTags.indexOf(o) !== -1 || n.push({ tagName: o, tagStartPos: u }), r = !0;
}
for (s++; s < e.length; s++)
if (e[s] === "<")
if (e[s + 1] === "!") {
s++, s = W(e, s);
continue;
} else if (e[s + 1] === "?") {
if (s = Z(e, ++s), s.err)
return s;
} else
break;
else if (e[s] === "&") {
const c = Se(e, s);
if (c == -1)
return N("InvalidChar", "char '&' is not expected.", b(e, s));
s = c;
} else if (i === !0 && !U(e[s]))
return N("InvalidXml", "Extra text at the end", b(e, s));
e[s] === "<" && s--;
}
} else {
if (U(e[s]))
continue;
return N("InvalidChar", "char '" + e[s] + "' is not expected.", b(e, s));
}
if (r) {
if (n.length == 1)
return N("InvalidTag", "Unclosed tag '" + n[0].tagName + "'.", b(e, n[0].tagStartPos));
if (n.length > 0)
return N("InvalidXml", "Invalid '" + JSON.stringify(n.map((s) => s.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", { line: 1, col: 1 });
} else
return N("InvalidXml", "Start tag expected.", 1);
return !0;
};
function U(e) {
return e === " " || e === " " || e === `
` || e === "\r";
}
function Z(e, t) {
const n = t;
for (; t < e.length; t++)
if (e[t] == "?" || e[t] == " ") {
const r = e.substr(n, t - n);
if (t > 5 && r === "xml")
return N("InvalidXml", "XML declaration allowed only at the start of the document.", b(e, t));
if (e[t] == "?" && e[t + 1] == ">") {
t++;
break;
} else
continue;
}
return t;
}
function W(e, t) {
if (e.length > t + 5 && e[t + 1] === "-" && e[t + 2] === "-") {
for (t += 3; t < e.length; t++)
if (e[t] === "-" && e[t + 1] === "-" && e[t + 2] === ">") {
t += 2;
break;
}
} else if (e.length > t + 8 && e[t + 1] === "D" && e[t + 2] === "O" && e[t + 3] === "C" && e[t + 4] === "T" && e[t + 5] === "Y" && e[t + 6] === "P" && e[t + 7] === "E") {
let n = 1;
for (t += 8; t < e.length; t++)
if (e[t] === "<")
n++;
else if (e[t] === ">" && (n--, n === 0))
break;
} else if (e.length > t + 9 && e[t + 1] === "[" && e[t + 2] === "C" && e[t + 3] === "D" && e[t + 4] === "A" && e[t + 5] === "T" && e[t + 6] === "A" && e[t + 7] === "[") {
for (t += 8; t < e.length; t++)
if (e[t] === "]" && e[t + 1] === "]" && e[t + 2] === ">") {
t += 2;
break;
}
}
return t;
}
const Oe = '"', $e = "'";
function xe(e, t) {
let n = "", r = "", i = !1;
for (; t < e.length; t++) {
if (e[t] === Oe || e[t] === $e)
r === "" ? r = e[t] : r !== e[t] || (r = "");
else if (e[t] === ">" && r === "") {
i = !0;
break;
}
n += e[t];
}
return r !== "" ? !1 : {
value: n,
index: t,
tagClosed: i
};
}
const Ve = new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`, "g");
function Y(e, t) {
const n = X.getAllMatches(e, Ve), r = {};
for (let i = 0; i < n.length; i++) {
if (n[i][1].length === 0)
return N("InvalidAttr", "Attribute '" + n[i][2] + "' has no space in starting.", v(n[i]));
if (n[i][3] !== void 0 && n[i][4] === void 0)
return N("InvalidAttr", "Attribute '" + n[i][2] + "' is without value.", v(n[i]));
if (n[i][3] === void 0 && !t.allowBooleanAttributes)
return N("InvalidAttr", "boolean attribute '" + n[i][2] + "' is not allowed.", v(n[i]));
const s = n[i][2];
if (!Fe(s))
return N("InvalidAttr", "Attribute '" + s + "' is an invalid name.", v(n[i]));
if (!r.hasOwnProperty(s))
r[s] = 1;
else
return N("InvalidAttr", "Attribute '" + s + "' is repeated.", v(n[i]));
}
return !0;
}
function Le(e, t) {
let n = /\d/;
for (e[t] === "x" && (t++, n = /[\da-fA-F]/); t < e.length; t++) {
if (e[t] === ";")
return t;
if (!e[t].match(n))
break;
}
return -1;
}
function Se(e, t) {
if (t++, e[t] === ";")
return -1;
if (e[t] === "#")
return t++, Le(e, t);
let n = 0;
for (; t < e.length; t++, n++)
if (!(e[t].match(/\w/) && n < 20)) {
if (e[t] === ";")
break;
return -1;
}
return t;
}
function N(e, t, n) {
return {
err: {
code: e,
msg: t,
line: n.line || n,
col: n.col
}
};
}
function Fe(e) {
return X.isName(e);
}
function Re(e) {
return X.isName(e);
}
function b(e, t) {
const n = e.substring(0, t).split(/\r?\n/);
return {
line: n.length,
// column number is last line's length + 1, because column numbering starts at 1:
col: n[n.length - 1].length + 1
};
}
function v(e) {
return e.startIndex + e[1].length;
}
var M = {};
const se = {
preserveOrder: !1,
attributeNamePrefix: "@_",
attributesGroupName: !1,
textNodeName: "#text",
ignoreAttributes: !0,
removeNSPrefix: !1,
// remove NS from tag name or attribute name if true
allowBooleanAttributes: !1,
//a tag can have attributes without any value
//ignoreRootElement : false,
parseTagValue: !0,
parseAttributeValue: !1,
trimValues: !0,
//Trim string values of tag and attributes
cdataPropName: !1,
numberParseOptions: {
hex: !0,
leadingZeros: !0,
eNotation: !0
},
tagValueProcessor: function(e, t) {
return t;
},
attributeValueProcessor: function(e, t) {
return t;
},
stopNodes: [],
//nested tags will not be parsed even for errors
alwaysCreateTextNode: !1,
isArray: () => !1,
commentPropName: !1,
unpairedTags: [],
processEntities: !0,
htmlEntities: !1,
ignoreDeclaration: !1,
ignorePiTags: !1,
transformTagName: !1,
transformAttributeName: !1,
updateTag: function(e, t, n) {
return e;
}
// skipEmptyListItem: false
}, _e = function(e) {
return Object.assign({}, se, e);
};
M.buildOptions = _e;
M.defaultOptions = se;
class ke {
constructor(t) {
this.tagname = t, this.child = [], this[":@"] = {};
}
add(t, n) {
t === "__proto__" && (t = "#__proto__"), this.child.push({ [t]: n });
}
addChild(t) {
t.tagname === "__proto__" && (t.tagname = "#__proto__"), t[":@"] && Object.keys(t[":@"]).length > 0 ? this.child.push({ [t.tagname]: t.child, ":@": t[":@"] }) : this.child.push({ [t.tagname]: t.child });
}
}
var Be = ke;
const Xe = S;
function Me(e, t) {
const n = {};
if (e[t + 3] === "O" && e[t + 4] === "C" && e[t + 5] === "T" && e[t + 6] === "Y" && e[t + 7] === "P" && e[t + 8] === "E") {
t = t + 9;
let r = 1, i = !1, s = !1, u = "";
for (; t < e.length; t++)
if (e[t] === "<" && !s) {
if (i && Ue(e, t))
t += 7, [entityName, val, t] = Ge(e, t + 1), val.indexOf("&") === -1 && (n[ze(entityName)] = {
regx: RegExp(`&${entityName};`, "g"),
val
});
else if (i && Ze(e, t))
t += 8;
else if (i && We(e, t))
t += 8;
else if (i && Ye(e, t))
t += 9;
else if (Ke)
s = !0;
else
throw new Error("Invalid DOCTYPE");
r++, u = "";
} else if (e[t] === ">") {
if (s ? e[t - 1] === "-" && e[t - 2] === "-" && (s = !1, r--) : r--, r === 0)
break;
} else
e[t] === "[" ? i = !0 : u += e[t];
if (r !== 0)
throw new Error("Unclosed DOCTYPE");
} else
throw new Error("Invalid Tag instead of DOCTYPE");
return { entities: n, i: t };
}
function Ge(e, t) {
let n = "";
for (; t < e.length && e[t] !== "'" && e[t] !== '"'; t++)
n += e[t];
if (n = n.trim(), n.indexOf(" ") !== -1)
throw new Error("External entites are not supported");
const r = e[t++];
let i = "";
for (; t < e.length && e[t] !== r; t++)
i += e[t];
return [n, i, t];
}
function Ke(e, t) {
return e[t + 1] === "!" && e[t + 2] === "-" && e[t + 3] === "-";
}
function Ue(e, t) {
return e[t + 1] === "!" && e[t + 2] === "E" && e[t + 3] === "N" && e[t + 4] === "T" && e[t + 5] === "I" && e[t + 6] === "T" && e[t + 7] === "Y";
}
function Ze(e, t) {
return e[t + 1] === "!" && e[t + 2] === "E" && e[t + 3] === "L" && e[t + 4] === "E" && e[t + 5] === "M" && e[t + 6] === "E" && e[t + 7] === "N" && e[t + 8] === "T";
}
function We(e, t) {
return e[t + 1] === "!" && e[t + 2] === "A" && e[t + 3] === "T" && e[t + 4] === "T" && e[t + 5] === "L" && e[t + 6] === "I" && e[t + 7] === "S" && e[t + 8] === "T";
}
function Ye(e, t) {
return e[t + 1] === "!" && e[t + 2] === "N" && e[t + 3] === "O" && e[t + 4] === "T" && e[t + 5] === "A" && e[t + 6] === "T" && e[t + 7] === "I" && e[t + 8] === "O" && e[t + 9] === "N";
}
function ze(e) {
if (Xe.isName(e))
return e;
throw new Error(`Invalid entity name ${e}`);
}
var qe = Me;
const Je = /^[-+]?0x[a-fA-F0-9]+$/, je = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;
!Number.parseInt && window.parseInt && (Number.parseInt = window.parseInt);
!Number.parseFloat && window.parseFloat && (Number.parseFloat = window.parseFloat);
const Qe = {
hex: !0,
leadingZeros: !0,
decimalPoint: ".",
eNotation: !0
//skipLike: /regex/
};
function He(e, t = {}) {
if (t = Object.assign({}, Qe, t), !e || typeof e != "string")
return e;
let n = e.trim();
if (t.skipLike !== void 0 && t.skipLike.test(n))
return e;
if (t.hex && Je.test(n))
return Number.parseInt(n, 16);
{
const r = je.exec(n);
if (r) {
const i = r[1], s = r[2];
let u = De(r[3]);
const l = r[4] || r[6];
if (!t.leadingZeros && s.length > 0 && i && n[2] !== ".")
return e;
if (!t.leadingZeros && s.length > 0 && !i && n[1] !== ".")
return e;
{
const o = Number(n), f = "" + o;
return f.search(/[eE]/) !== -1 || l ? t.eNotation ? o : e : n.indexOf(".") !== -1 ? f === "0" && u === "" || f === u || i && f === "-" + u ? o : e : s ? u === f || i + u === f ? o : e : n === f || n === i + f ? o : e;
}
} else
return e;
}
}
function De(e) {
return e && e.indexOf(".") !== -1 && (e = e.replace(/0+$/, ""), e === "." ? e = "0" : e[0] === "." ? e = "0" + e : e[e.length - 1] === "." && (e = e.substr(0, e.length - 1))), e;
}
var et = He;
function tt(e) {
return typeof e == "function" ? e : Array.isArray(e) ? (t) => {
for (const n of e)
if (typeof n == "string" && t === n || n instanceof RegExp && n.test(t))
return !0;
} : () => !1;
}
var re = tt;
const ie = S, I = Be, nt = qe, st = et, rt = re;
let it = class {
constructor(t) {
this.options = t, this.currentNode = null, this.tagsNodeStack = [], this.docTypeEntities = {}, this.lastEntities = {
apos: { regex: /&(apos|#39|#x27);/g, val: "'" },
gt: { regex: /&(gt|#62|#x3E);/g, val: ">" },
lt: { regex: /&(lt|#60|#x3C);/g, val: "<" },
quot: { regex: /&(quot|#34|#x22);/g, val: '"' }
}, this.ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" }, this.htmlEntities = {
space: { regex: /&(nbsp|#160);/g, val: " " },
// "lt" : { regex: /&(lt|#60);/g, val: "<" },
// "gt" : { regex: /&(gt|#62);/g, val: ">" },
// "amp" : { regex: /&(amp|#38);/g, val: "&" },
// "quot" : { regex: /&(quot|#34);/g, val: "\"" },
// "apos" : { regex: /&(apos|#39);/g, val: "'" },
cent: { regex: /&(cent|#162);/g, val: "¢" },
pound: { regex: /&(pound|#163);/g, val: "£" },
yen: { regex: /&(yen|#165);/g, val: "¥" },
euro: { regex: /&(euro|#8364);/g, val: "€" },
copyright: { regex: /&(copy|#169);/g, val: "©" },
reg: { regex: /&(reg|#174);/g, val: "®" },
inr: { regex: /&(inr|#8377);/g, val: "₹" },
num_dec: { regex: /&#([0-9]{1,7});/g, val: (n, r) => String.fromCharCode(Number.parseInt(r, 10)) },
num_hex: { regex: /&#x([0-9a-fA-F]{1,6});/g, val: (n, r) => String.fromCharCode(Number.parseInt(r, 16)) }
}, this.addExternalEntities = ot, this.parseXml = ct, this.parseTextData = lt, this.resolveNameSpace = ut, this.buildAttributesMap = ft, this.isItStopNode = gt, this.replaceEntitiesValue = ht, this.readStopNodeData = bt, this.saveTextToParentTag = pt, this.addChild = dt, this.ignoreAttributesFn = rt(this.options.ignoreAttributes);
}
};
function ot(e) {
const t = Object.keys(e);
for (let n = 0; n < t.length; n++) {
const r = t[n];
this.lastEntities[r] = {
regex: new RegExp("&" + r + ";", "g"),
val: e[r]
};
}
}
function lt(e, t, n, r, i, s, u) {
if (e !== void 0 && (this.options.trimValues && !r && (e = e.trim()), e.length > 0)) {
u || (e = this.replaceEntitiesValue(e));
const l = this.options.tagValueProcessor(t, e, n, i, s);
return l == null ? e : typeof l != typeof e || l !== e ? l : this.options.trimValues ? R(e, this.options.parseTagValue, this.options.numberParseOptions) : e.trim() === e ? R(e, this.options.parseTagValue, this.options.numberParseOptions) : e;
}
}
function ut(e) {
if (this.options.removeNSPrefix) {
const t = e.split(":"), n = e.charAt(0) === "/" ? "/" : "";
if (t[0] === "xmlns")
return "";
t.length === 2 && (e = n + t[1]);
}
return e;
}
const at = new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`, "gm");
function ft(e, t, n) {
if (this.options.ignoreAttributes !== !0 && typeof e == "string") {
const r = ie.getAllMatches(e, at), i = r.length, s = {};
for (let u = 0; u < i; u++) {
const l = this.resolveNameSpace(r[u][1]);
if (this.ignoreAttributesFn(l, t))
continue;
let o = r[u][4], f = this.options.attributeNamePrefix + l;
if (l.length)
if (this.options.transformAttributeName && (f = this.options.transformAttributeName(f)), f === "__proto__" && (f = "#__proto__"), o !== void 0) {
this.options.trimValues && (o = o.trim()), o = this.replaceEntitiesValue(o);
const a = this.options.attributeValueProcessor(l, o, t);
a == null ? s[f] = o : typeof a != typeof o || a !== o ? s[f] = a : s[f] = R(
o,
this.options.parseAttributeValue,
this.options.numberParseOptions
);
} else
this.options.allowBooleanAttributes && (s[f] = !0);
}
if (!Object.keys(s).length)
return;
if (this.options.attributesGroupName) {
const u = {};
return u[this.options.attributesGroupName] = s, u;
}
return s;
}
}
const ct = function(e) {
e = e.replace(/\r\n?/g, `
`);
const t = new I("!xml");
let n = t, r = "", i = "";
for (let s = 0; s < e.length; s++)
if (e[s] === "<")
if (e[s + 1] === "/") {
const l = w(e, ">", s, "Closing Tag is not closed.");
let o = e.substring(s + 2, l).trim();
if (this.options.removeNSPrefix) {
const c = o.indexOf(":");
c !== -1 && (o = o.substr(c + 1));
}
this.options.transformTagName && (o = this.options.transformTagName(o)), n && (r = this.saveTextToParentTag(r, n, i));
const f = i.substring(i.lastIndexOf(".") + 1);
if (o && this.options.unpairedTags.indexOf(o) !== -1)
throw new Error(`Unpaired tag can not be used as closing tag: </${o}>`);
let a = 0;
f && this.options.unpairedTags.indexOf(f) !== -1 ? (a = i.lastIndexOf(".", i.lastIndexOf(".") - 1), this.tagsNodeStack.pop()) : a = i.lastIndexOf("."), i = i.substring(0, a), n = this.tagsNodeStack.pop(), r = "", s = l;
} else if (e[s + 1] === "?") {
let l = F(e, s, !1, "?>");
if (!l)
throw new Error("Pi Tag is not closed.");
if (r = this.saveTextToParentTag(r, n, i), !(this.options.ignoreDeclaration && l.tagName === "?xml" || this.options.ignorePiTags)) {
const o = new I(l.tagName);
o.add(this.options.textNodeName, ""), l.tagName !== l.tagExp && l.attrExpPresent && (o[":@"] = this.buildAttributesMap(l.tagExp, i, l.tagName)), this.addChild(n, o, i);
}
s = l.closeIndex + 1;
} else if (e.substr(s + 1, 3) === "!--") {
const l = w(e, "-->", s + 4, "Comment is not closed.");
if (this.options.commentPropName) {
const o = e.substring(s + 4, l - 2);
r = this.saveTextToParentTag(r, n, i), n.add(this.options.commentPropName, [{ [this.options.textNodeName]: o }]);
}
s = l;
} else if (e.substr(s + 1, 2) === "!D") {
const l = nt(e, s);
this.docTypeEntities = l.entities, s = l.i;
} else if (e.substr(s + 1, 2) === "![") {
const l = w(e, "]]>", s, "CDATA is not closed.") - 2, o = e.substring(s + 9, l);
r = this.saveTextToParentTag(r, n, i);
let f = this.parseTextData(o, n.tagname, i, !0, !1, !0, !0);
f == null && (f = ""), this.options.cdataPropName ? n.add(this.options.cdataPropName, [{ [this.options.textNodeName]: o }]) : n.add(this.options.textNodeName, f), s = l + 2;
} else {
let l = F(e, s, this.options.removeNSPrefix), o = l.tagName;
const f = l.rawTagName;
let a = l.tagExp, c = l.attrExpPresent, h = l.closeIndex;
this.options.transformTagName && (o = this.options.transformTagName(o)), n && r && n.tagname !== "!xml" && (r = this.saveTextToParentTag(r, n, i, !1));
const g = n;
if (g && this.options.unpairedTags.indexOf(g.tagname) !== -1 && (n = this.tagsNodeStack.pop(), i = i.substring(0, i.lastIndexOf("."))), o !== t.tagname && (i += i ? "." + o : o), this.isItStopNode(this.options.stopNodes, i, o)) {
let p = "";
if (a.length > 0 && a.lastIndexOf("/") === a.length - 1)
o[o.length - 1] === "/" ? (o = o.substr(0, o.length - 1), i = i.substr(0, i.length - 1), a = o) : a = a.substr(0, a.length - 1), s = l.closeIndex;
else if (this.options.unpairedTags.indexOf(o) !== -1)
s = l.closeIndex;
else {
const T = this.readStopNodeData(e, f, h + 1);
if (!T)
throw new Error(`Unexpected end of ${f}`);
s = T.i, p = T.tagContent;
}
const m = new I(o);
o !== a && c && (m[":@"] = this.buildAttributesMap(a, i, o)), p && (p = this.parseTextData(p, o, i, !0, c, !0, !0)), i = i.substr(0, i.lastIndexOf(".")), m.add(this.options.textNodeName, p), this.addChild(n, m, i);
} else {
if (a.length > 0 && a.lastIndexOf("/") === a.length - 1) {
o[o.length - 1] === "/" ? (o = o.substr(0, o.length - 1), i = i.substr(0, i.length - 1), a = o) : a = a.substr(0, a.length - 1), this.options.transformTagName && (o = this.options.transformTagName(o));
const p = new I(o);
o !== a && c && (p[":@"] = this.buildAttributesMap(a, i, o)), this.addChild(n, p, i), i = i.substr(0, i.lastIndexOf("."));
} else {
const p = new I(o);
this.tagsNodeStack.push(n), o !== a && c && (p[":@"] = this.buildAttributesMap(a, i, o)), this.addChild(n, p, i), n = p;
}
r = "", s = h;
}
}
else
r += e[s];
return t.child;
};
function dt(e, t, n) {
const r = this.options.updateTag(t.tagname, n, t[":@"]);
r === !1 || (typeof r == "string" && (t.tagname = r), e.addChild(t));
}
const ht = function(e) {
if (this.options.processEntities) {
for (let t in this.docTypeEntities) {
const n = this.docTypeEntities[t];
e = e.replace(n.regx, n.val);
}
for (let t in this.lastEntities) {
const n = this.lastEntities[t];
e = e.replace(n.regex, n.val);
}
if (this.options.htmlEntities)
for (let t in this.htmlEntities) {
const n = this.htmlEntities[t];
e = e.replace(n.regex, n.val);
}
e = e.replace(this.ampEntity.regex, this.ampEntity.val);
}
return e;
};
function pt(e, t, n, r) {
return e && (r === void 0 && (r = Object.keys(t.child).length === 0), e = this.parseTextData(
e,
t.tagname,
n,
!1,
t[":@"] ? Object.keys(t[":@"]).length !== 0 : !1,
r
), e !== void 0 && e !== "" && t.add(this.options.textNodeName, e), e = ""), e;
}
function gt(e, t, n) {
const r = "*." + n;
for (const i in e) {
const s = e[i];
if (r === s || t === s)
return !0;
}
return !1;
}
function Nt(e, t, n = ">") {
let r, i = "";
for (let s = t; s < e.length; s++) {
let u = e[s];
if (r)
u === r && (r = "");
else if (u === '"' || u === "'")
r = u;
else if (u === n[0])
if (n[1]) {
if (e[s + 1] === n[1])
return {
data: i,
index: s
};
} else
return {
data: i,
index: s
};
else
u === " " && (u = " ");
i += u;
}
}
function w(e, t, n, r) {
const i = e.indexOf(t, n);
if (i === -1)
throw new Error(r);
return i + t.length - 1;
}
function F(e, t, n, r = ">") {
const i = Nt(e, t + 1, r);
if (!i)
return;
let s = i.data;
const u = i.index, l = s.search(/\s/);
let o = s, f = !0;
l !== -1 && (o = s.substring(0, l), s = s.substring(l + 1).trimStart());
const a = o;
if (n) {
const c = o.indexOf(":");
c !== -1 && (o = o.substr(c + 1), f = o !== i.data.substr(c + 1));
}
return {
tagName: o,
tagExp: s,
closeIndex: u,
attrExpPresent: f,
rawTagName: a
};
}
function bt(e, t, n) {
const r = n;
let i = 1;
for (; n < e.length; n++)
if (e[n] === "<")
if (e[n + 1] === "/") {
const s = w(e, ">", n, `${t} is not closed`);
if (e.substring(n + 2, s).trim() === t && (i--, i === 0))
return {
tagContent: e.substring(r, n),
i: s
};
n = s;
} else if (e[n + 1] === "?")
n = w(e, "?>", n + 1, "StopNode is not closed.");
else if (e.substr(n + 1, 3) === "!--")
n = w(e, "-->", n + 3, "StopNode is not closed.");
else if (e.substr(n + 1, 2) === "![")
n = w(e, "]]>", n, "StopNode is not closed.") - 2;
else {
const s = F(e, n, ">");
s && ((s && s.tagName) === t && s.tagExp[s.tagExp.length - 1] !== "/" && i++, n = s.closeIndex);
}
}
function R(e, t, n) {
if (t && typeof e == "string") {
const r = e.trim();
return r === "true" ? !0 : r === "false" ? !1 : st(e, n);
} else
return ie.isExist(e) ? e : "";
}
var mt = it, oe = {};
function Tt(e, t) {
return le(e, t);
}
function le(e, t, n) {
let r;
const i = {};
for (let s = 0; s < e.length; s++) {
const u = e[s], l = yt(u);
let o = "";
if (n === void 0 ? o = l : o = n + "." + l, l === t.textNodeName)
r === void 0 ? r = u[l] : r += "" + u[l];
else {
if (l === void 0)
continue;
if (u[l]) {
let f = le(u[l], t, o);
const a = Ct(f, t);
u[":@"] ? Et(f, u[":@"], o, t) : Object.keys(f).length === 1 && f[t.textNodeName] !== void 0 && !t.alwaysCreateTextNode ? f = f[t.textNodeName] : Object.keys(f).length === 0 && (t.alwaysCreateTextNode ? f[t.textNodeName] = "" : f = ""), i[l] !== void 0 && i.hasOwnProperty(l) ? (Array.isArray(i[l]) || (i[l] = [i[l]]), i[l].push(f)) : t.isArray(l, o, a) ? i[l] = [f] : i[l] = f;
}
}
}
return typeof r == "string" ? r.length > 0 && (i[t.textNodeName] = r) : r !== void 0 && (i[t.textNodeName] = r), i;
}
function yt(e) {
const t = Object.keys(e);
for (let n = 0; n < t.length; n++) {
const r = t[n];
if (r !== ":@")
return r;
}
}
function Et(e, t, n, r) {
if (t) {
const i = Object.keys(t), s = i.length;
for (let u = 0; u < s; u++) {
const l = i[u];
r.isArray(l, n + "." + l, !0, !0) ? e[l] = [t[l]] : e[l] = t[l];
}
}
}
function Ct(e, t) {
const { textNodeName: n } = t, r = Object.keys(e).length;
return !!(r === 0 || r === 1 && (e[n] || typeof e[n] == "boolean" || e[n] === 0));
}
oe.prettify = Tt;
const { buildOptions: At } = M, wt = mt, { prettify: vt } = oe, It = B;
let Pt = class {
constructor(t) {
this.externalEntities = {}, this.options = At(t);
}
/**
* Parse XML dats to JS object
* @param {string|Buffer} xmlData
* @param {boolean|Object} validationOption
*/
parse(t, n) {
if (typeof t != "string")
if (t.toString)
t = t.toString();
else
throw new Error("XML data is accepted in String or Bytes[] form.");
if (n) {
n === !0 && (n = {});
const s = It.validate(t, n);
if (s !== !0)
throw Error(`${s.err.msg}:${s.err.line}:${s.err.col}`);
}
const r = new wt(this.options);
r.addExternalEntities(this.externalEntities);
const i = r.parseXml(t);
return this.options.preserveOrder || i === void 0 ? i : vt(i, this.options);
}
/**
* Add Entity which is not by default supported by this library
* @param {string} key
* @param {string} value
*/
addEntity(t, n) {
if (n.indexOf("&") !== -1)
throw new Error("Entity value can't have '&'");
if (t.indexOf("&") !== -1 || t.indexOf(";") !== -1)
throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'");
if (n === "&")
throw new Error("An entity with value '&' is not permitted");
this.externalEntities[t] = n;
}
};
var Ot = Pt;
const $t = `
`;
function xt(e, t) {
let n = "";
return t.format && t.indentBy.length > 0 && (n = $t), ue(e, t, "", n);
}
function ue(e, t, n, r) {
let i = "", s = !1;
for (let u = 0; u < e.length; u++) {
const l = e[u], o = Vt(l);
if (o === void 0)
continue;
let f = "";
if (n.length === 0 ? f = o : f = `${n}.${o}`, o === t.textNodeName) {
let p = l[o];
Lt(f, t) || (p = t.tagValueProcessor(o, p), p = ae(p, t)), s && (i += r), i += p, s = !1;
continue;
} else if (o === t.cdataPropName) {
s && (i += r), i += `<![CDATA[${l[o][0][t.textNodeName]}]]>`, s = !1;
continue;
} else if (o === t.commentPropName) {
i += r + `<!--${l[o][0][t.textNodeName]}-->`, s = !0;
continue;
} else if (o[0] === "?") {
const p = z(l[":@"], t), m = o === "?xml" ? "" : r;
let T = l[o][0][t.textNodeName];
T = T.length !== 0 ? " " + T : "", i += m + `<${o}${T}${p}?>`, s = !0;
continue;
}
let a = r;
a !== "" && (a += t.indentBy);
const c = z(l[":@"], t), h = r + `<${o}${c}`, g = ue(l[o], t, f, a);
t.unpairedTags.indexOf(o) !== -1 ? t.suppressUnpairedNode ? i += h + ">" : i += h + "/>" : (!g || g.length === 0) && t.suppressEmptyNode ? i += h + "/>" : g && g.endsWith(">") ? i += h + `>${g}${r}</${o}>` : (i += h + ">", g && r !== "" && (g.includes("/>") || g.includes("</")) ? i += r + t.indentBy + g + r : i += g, i += `</${o}>`), s = !0;
}
return i;
}
function Vt(e) {
const t = Object.keys(e);
for (let n = 0; n < t.length; n++) {
const r = t[n];
if (e.hasOwnProperty(r) && r !== ":@")
return r;
}
}
function z(e, t) {
let n = "";
if (e && !t.ignoreAttributes)
for (let r in e) {
if (!e.hasOwnProperty(r))
continue;
let i = t.attributeValueProcessor(r, e[r]);
i = ae(i, t), i === !0 && t.suppressBooleanAttributes ? n += ` ${r.substr(t.attributeNamePrefix.length)}` : n += ` ${r.substr(t.attributeNamePrefix.length)}="${i}"`;
}
return n;
}
function Lt(e, t) {
e = e.substr(0, e.length - t.textNodeName.length - 1);
let n = e.substr(e.lastIndexOf(".") + 1);
for (let r in t.stopNodes)
if (t.stopNodes[r] === e || t.stopNodes[r] === "*." + n)
return !0;
return !1;
}
function ae(e, t) {
if (e && e.length > 0 && t.processEntities)
for (let n = 0; n < t.entities.length; n++) {
const r = t.entities[n];
e = e.replace(r.regex, r.val);
}
return e;
}
var St = xt;
const Ft = St, Rt = re, _t = {
attributeNamePrefix: "@_",
attributesGroupName: !1,
textNodeName: "#text",
ignoreAttributes: !0,
cdataPropName: !1,
format: !1,
indentBy: " ",
suppressEmptyNode: !1,
suppressUnpairedNode: !0,
suppressBooleanAttributes: !0,
tagValueProcessor: function(e, t) {
return t;
},
attributeValueProcessor: function(e, t) {
return t;
},
preserveOrder: !1,
commentPropName: !1,
unpairedTags: [],
entities: [
{ regex: new RegExp("&", "g"), val: "&" },
//it must be on top
{ regex: new RegExp(">", "g"), val: ">" },
{ regex: new RegExp("<", "g"), val: "<" },
{ regex: new RegExp("'", "g"), val: "'" },
{ regex: new RegExp('"', "g"), val: """ }
],
processEntities: !0,
stopNodes: [],
// transformTagName: false,
// transformAttributeName: false,
oneListGroup: !1
};
function A(e) {
this.options = Object.assign({}, _t, e), this.options.ignoreAttributes === !0 || this.options.attributesGroupName ? this.isAttribute = function() {
return !1;
} : (this.ignoreAttributesFn = Rt(this.options.ignoreAttributes), this.attrPrefixLen = this.options.attributeNamePrefix.length, this.isAttribute = Xt), this.processTextOrObjNode = kt, this.options.format ? (this.indentate = Bt, this.tagEndChar = `>
`, this.newLine = `
`) : (this.indentate = function() {
return "";
}, this.tagEndChar = ">", this.newLine = "");
}
A.prototype.build = function(e) {
return this.options.preserveOrder ? Ft(e, this.options) : (Array.isArray(e) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1 && (e = {
[this.options.arrayNodeName]: e
}), this.j2x(e, 0, []).val);
};
A.prototype.j2x = function(e, t, n) {
let r = "", i = "";
const s = n.join(".");
for (let u in e)
if (Object.prototype.hasOwnProperty.call(e, u))
if (typeof e[u] > "u")
this.isAttribute(u) && (i += "");
else if (e[u] === null)
this.isAttribute(u) ? i += "" : u[0] === "?" ? i += this.indentate(t) + "<" + u + "?" + this.tagEndChar : i += this.indentate(t) + "<" + u + "/" + this.tagEndChar;
else if (e[u] instanceof Date)
i += this.buildTextValNode(e[u], u, "", t);
else if (typeof e[u] != "object") {
const l = this.isAttribute(u);
if (l && !this.ignoreAttributesFn(l, s))
r += this.buildAttrPairStr(l, "" + e[u]);
else if (!l)
if (u === this.options.textNodeName) {
let o = this.options.tagValueProcessor(u, "" + e[u]);
i += this.replaceEntitiesValue(o);
} else
i += this.buildTextValNode(e[u], u, "", t);
} else if (Array.isArray(e[u])) {
const l = e[u].length;
let o = "", f = "";
for (let a = 0; a < l; a++) {
const c = e[u][a];
if (!(typeof c > "u"))
if (c === null)
u[0] === "?" ? i += this.indentate(t) + "<" + u + "?" + this.tagEndChar : i += this.indentate(t) + "<" + u + "/" + this.tagEndChar;
else if (typeof c == "object")
if (this.options.oneListGroup) {
const h = this.j2x(c, t + 1, n.concat(u));
o += h.val, this.options.attributesGroupName && c.hasOwnProperty(this.options.attributesGroupName) && (f += h.attrStr);
} else
o += this.processTextOrObjNode(c, u, t, n);
else if (this.options.oneListGroup) {
let h = this.options.tagValueProcessor(u, c);
h = this.replaceEntitiesValue(h), o += h;
} else
o += this.buildTextValNode(c, u, "", t);
}
this.options.oneListGroup && (o = this.buildObjectNode(o, u, f, t)), i += o;
} else if (this.options.attributesGroupName && u === this.options.attributesGroupName) {
const l = Object.keys(e[u]), o = l.length;
for (let f = 0; f < o; f++)
r += this.buildAttrPairStr(l[f], "" + e[u][l[f]]);
} else
i += this.processTextOrObjNode(e[u], u, t, n);
return { attrStr: r, val: i };
};
A.prototype.buildAttrPairStr = function(e, t) {
return t = this.options.attributeValueProcessor(e, "" + t), t = this.replaceEntitiesValue(t), this.options.suppressBooleanAttributes && t === "true" ? " " + e : " " + e + '="' + t + '"';
};
function kt(e, t, n, r) {
const i = this.j2x(e, n + 1, r.concat(t));
return e[this.options.textNodeName] !== void 0 && Object.keys(e).length === 1 ? this.buildTextValNode(e[this.options.textNodeName], t, i.attrStr, n) : this.buildObjectNode(i.val, t, i.attrStr, n);
}
A.prototype.buildObjectNode = function(e, t, n, r) {
if (e === "")
return t[0] === "?" ? this.indentate(r) + "<" + t + n + "?" + this.tagEndChar : this.indentate(r) + "<" + t + n + this.closeTag(t) + this.tagEndChar;
{
let i = "</" + t + this.tagEndChar, s = "";
return t[0] === "?" && (s = "?", i = ""), (n || n === "") && e.indexOf("<") === -1 ? this.indentate(r) + "<" + t + n + s + ">" + e + i : this.options.commentPropName !== !1 && t === this.options.commentPropName && s.length === 0 ? this.indentate(r) + `<!--${e}-->` + this.newLine : this.indentate(r) + "<" + t + n + s + this.tagEndChar + e + this.indentate(r) + i;
}
};
A.prototype.closeTag = function(e) {
let t = "";
return this.options.unpairedTags.indexOf(e) !== -1 ? this.options.suppressUnpairedNode || (t = "/") : this.options.suppressEmptyNode ? t = "/" : t = `></${e}`, t;
};
A.prototype.buildTextValNode = function(e, t, n, r) {
if (this.options.cdataPropName !== !1 && t === this.options.cdataPropName)
return this.indentate(r) + `<![CDATA[${e}]]>` + this.newLine;
if (this.options.commentPropName !== !1 && t === this.options.commentPropName)
return this.indentate(r) + `<!--${e}-->` + this.newLine;
if (t[0] === "?")
return this.indentate(r) + "<" + t + n + "?" + this.tagEndChar;
{
let i = this.options.tagValueProcessor(t, e);
return i = this.replaceEntitiesValue(i), i === "" ? this.indentate(r) + "<" + t + n + this.closeTag(t) + this.tagEndChar : this.indentate(r) + "<" + t + n + ">" + i + "</" + t + this.tagEndChar;
}
};
A.prototype.replaceEntitiesValue = function(e) {
if (e && e.length > 0 && this.options.processEntities)
for (let t = 0; t < this.options.entities.length; t++) {
const n = this.options.entities[t];
e = e.replace(n.regex, n.val);
}
return e;
};
function Bt(e) {
return this.options.indentBy.repeat(e);
}
function Xt(e) {
return e.startsWith(this.options.attributeNamePrefix) && e !== this.options.textNodeName ? e.substr(this.attrPrefixLen) : !1;
}
var Mt = A;
const Gt = B, Kt = Ot, Ut = Mt;
var fe = {
XMLParser: Kt,
XMLValidator: Gt,
XMLBuilder: Ut
};
const Zt = new fe.XMLParser({
preserveOrder: !0,
ignoreAttributes: !1,
attributeNamePrefix: "",
allowBooleanAttributes: !0,
commentPropName: _,
cdataPropName: k,
parseTagValue: !1
});
function Wt(e) {
return O(() => {
try {
if (!fe.XMLValidator.validate(e))
throw new Error("Invalid XML!");
const t = Zt.parse(e);
if (typeof e == "string" && e.trim().length > 0 && t.length === 0)
throw new Error("Invalid XML!");
return { json: t, valid: !0 };
} catch (t) {
return { json: null, valid: !1, errorMessage: `Fail to parse: ${t.message}` };
}
}, [e]);
}
function C(e, t = !0) {
const { push: n } = ee(), r = Q(null);
return $(() => {
t && r.current && e && n(e, { element: r.current });
}, [r.current, n, e, t]), r;
}
function Yt(e) {
const { indentation: t, children: n, isInline: r, keyValue: i } = e, { theme: s } = y(), u = C(i), l = C(`${i}-close`, !r);
return /* @__PURE__ */ E("div", { style: { color: s.cdataColor }, children: [
/* @__PURE__ */ d("span", { ref: u, children: `${t}<![CDATA[` }),
n,
/* @__PURE__ */ d("span", { ref: l, children: `${r ? "" : t}]]>` })
] });
}
const zt = (e) => /* @__PURE__ */ G.createElement("svg", { width: "1em", height: "1em", viewBox: "0 0 24 24", ...e }, /* @__PURE__ */ G.createElement("path", { d: "M9 17.898C9 18.972 10.2649 19.546 11.0731 18.8388L17.3838 13.3169C18.1806 12.6197 18.1806 11.3801 17.3838 10.6829L11.0731 5.16108C10.2649 4.45388 9 5.02785 9 6.1018V17.898Z" }));
function ce(e) {
const { collapsible: t, theme: n } = y(), { collapsed: r } = e;
return t ? /* @__PURE__ */ d("span", { style: { position: "relative" }, children: /* @__PURE__ */ d("span", { style: { position: "absolute", right: "0", border: 0, padding: 0, background: "none" }, children: /* @__PURE__ */ d(
zt,
{
fill: n.separatorColor,
style: { transform: `rotate(${r ? 0 : 90}deg)`, transition: "transform 0.2s" }
}
) }) }) : null;
}
function de(e) {
const { collapsible: t, initialCollapsedDepth: n } = y(), r = n != null, [i, s] = P(
() => !r || !t ? !1 : e >= n
), u = () => s((l) => !l);
return $(() => {
s(
!r || !t ? !1 : e >= n
);
}, [n, e, t]), {
collapsed: i,
buttonProps: t ? {
onClick: u,
role: "button",
style: { cursor: "pointer" }
} : {}
};
}
function qt(e) {
const { indentation: t, children: n, isInline: r, level: i, keyValue: s } = e, { theme: u } = y(), { collapsed: l, buttonProps: o } = de(i), f = C(s), a = C(`${s}-close`, !r), c = l ? "none" : void 0;
return /* @__PURE__ */ E("div", { style: { color: u.commentColor }, children: [
/* @__PURE__ */ E("span", { ...o, children: [
/* @__PURE__ */ d("span", { children: t }),
/* @__PURE__ */ d(ce, { collapsed: l }),
/* @__PURE__ */ d("span", { ref: f, children: "<!-- " })
] }),
/* @__PURE__ */ d("span", { style: { display: c }, children: n }),
l && "...",
/* @__PURE__ */ d("span", { style: { display: c }, ref: a, children: `${r || l ? " " : t}-->` })
] });
}
function he(e) {
const { attributes: t } = e, { theme: n } = y();
return t ? /* @__PURE__ */ d("span", { children: Object.entries(t).map(([r, i]) => /* @__PURE__ */ E("span", { children: [
/* @__PURE__ */ d("span", { style: { color: n.attributeKeyColor }, children: ` ${r}` }),
/* @__PURE__ */ d("span", { style: { color: n.separatorColor }, children: "=" }),
/* @__PURE__ */ d("span", { style: { color: n.attributeValueColor }, children: `"${i}"` })
] }, `attribute-${r}`)) }) : null;
}
function Jt(e) {
const { indentation: t, tagKey: n, attributes: r, keyValue: i } = e, { theme: s } = y(), u = C(i);
return /* @__PURE__ */ E("div", { ref: u, children: [
/* @__PURE__ */ d("span", { style: { color: s.separatorColor }, children: `${t}<?` }),
/* @__PURE__ */ d("span", { style: { color: s.tagColor }, children: `${n.slice(1)}` }),
/* @__PURE__ */ d(he, { attributes: r }),
/* @__PURE__ */ d("span", { style: { color: s.separatorColor }, children: "?>" })
] });
}
function jt(e) {
const { indentation: t, tagKey: n, attributes: r, children: i, isInline: s, hasChildren: u, level: l, keyValue: o } = e, { collapsed: f, buttonProps: a } = de(l), { theme: c } = y(), h = C(o), g = C(`${o}-close`, !s), p = f ? "none" : void 0;
return /* @__PURE__ */ E("div", { ref: h, children: [
/* @__PURE__ */ E("span", { ...a, children: [
/* @__PURE__ */ d("span", { children: t }),
/* @__PURE__ */ d(ce, { collapsed: f }),
/* @__PURE__ */ d("span", { style: { color: c.separatorColor }, children: "<" }),
/* @__PURE__ */ d("span", { style: { color: c.tagColor }, children: `${n}` }),
!f && /* @__PURE__ */ d(he, { attributes: r }),
!f && /* @__PURE__ */ d("span", { style: { color: c.separatorColor }, children: u ? ">" : " />" })
] }),
u && /* @__PURE__ */ E(q, { children: [
/* @__PURE__ */ d("span", { style: { display: p }, children: i }),
f && /* @__PURE__ */ d("span", { style: { color: "#777" }, children: "..." }),
/* @__PURE__ */ d("span", { style: { color: c.separatorColor, display: p }, children: `${s || f ? "" : t}</` }),
/* @__PURE__ */ d("span", { style: { color: c.tagColor, display: p }, children: `${n}` }),
/* @__PURE__ */ d("span", { style: { color: c.separatorColor, display: p }, ref: g, children: ">" })
] })
] });
}
function Qt(e) {
const { children: t, keyValue: n } = e, r = C(n);
return /* @__PURE__ */ d("div", { ref: r, children: t });
}
function Ht(e) {
const { hasSiblings: t, text: n, indentation: r, isText: i, keyValue: s } = e, { theme: u } = y(), l = i ? { color: u.textColor } : void 0;
return ne(n) || t ? /* @__PURE__ */ d("div", { style: l, children: n.split(`
`).filter((o) => !!o.trim()).map((o, f) => /* @__PURE__ */ d(
Qt,
{
keyValue: `${s}${f}`,
children: `${r}${o.trim()}`
},
`${s}${f}`
)) }) : /* @__PURE__ */ d("span", { style: l, children: n });
}
function x(e) {
const { elements: t, level: n = 0, isText: r = !0, parentKey: i = "" } = e, { indentSize: s } = y();
return !Array.isArray(t) || t.length === 0 ? null : /* @__PURE__ */ d(q, { children: t.map((u, l) => {
const { tagKey: o, attributes: f, subElements: a, type: c } = ve(u), h = t.length > 1, g = Ee(s, n), p = `${i}-${n + 1}-${l + 1}`, m = Ce(a);
switch (c) {
case V:
return /* @__PURE__ */ d(
Ht,
{
text: a,
indentation: g,
hasSiblings: h,
isText: r,
keyValue: p
},
p
);
case _:
return /* @__PURE__ */ d(
qt,
{
keyValue: p,
isInline: m,
indentation: g,
level: n,
children: /* @__PURE__ */ d(
x,
{
elements: a,
level: n + 1,
parentKey: p,
isText: !1
}
)
},
p
);
case k:
return /* @__PURE__ */ d(Yt, { keyValue: p, indentation: g, isInline: m, children: /* @__PURE__ */ d(
x,
{
elements: a,
level: n + 1,
parentKey: p,
isText: !1
}
) }, p);
case H:
return /* @__PURE__ */ d(
Jt,
{
indentation: g,
tagKey: o,
attributes: f,
keyValue: p
},
p
);
default:
return /* @__PURE__ */ d(
jt,
{
indentation: g,
tagKey: o,
attributes: f,
isInline: m,
hasChildren: a.length > 0,
level: n,
keyValue: p,
children: /* @__PURE__ */ d(x, { elements: a, level: n + 1, parentKey: p })
},
p
);
}
}) });
}
function Dt() {
return /* @__PURE__ */ d("div", { children: "Invalid XML!" });
}
function pe(e) {
return e ? e.checkVisibility ? e.checkVisibility() : !!(e.offsetWidth || e.offsetHeight || e.getClientRects().length) : !1;
}
function ge(e) {
return !e || !e.parentElement ? 0 : pe(e.parentElement) ? e.parentElement.offsetTop : ge(e.parentElement);
}
function en({ viewerContainer: e }) {
const { lines: t } = ee(), { theme: n } = y(), [r, i] = P({ width: 0, height: 0 }), s = Q(null), { sortedLines: u, numberOfLines: l } = O(() => {
const f = Object.values(t).map((a) => {
var h;
const c = pe(a.element);
return {
...a,
offset: c ? (h = a.element) == null ? void 0 : h.offsetTop : ge(a.element),
visible: c
};
}).sort((a, c) => a.offset === c.offset ? a.visible === c.visible ? 0 : a.visible ? -1 : 1 : a.offset - c.offset).map((a, c) => ({
...a,
lineNumber: c + 1
}));
return {
sortedLines: f.filter((a) => a.visible),
numberOfLines: f.length + 1
};
}, [t, r.width, r.height]), o = O(() => new ResizeObserver(function(f) {
const { width: a, height: c } = f[0].contentRect;
i({ width: a, height: c });
}), []);
return $(() => {
e && o.observe(e);
}, [e, o]), $(() => () => {
o.disconnect();
}, []), /* @__PURE__ */ d(
"div",
{
ref: s,
style: {
width: 16 + 8 * String(l).length,
height: "auto",
backgroundColor: n.lineNumberBackground,
color: n.lineNumberColor,
marginRight: 16,
paddingTop: 8,
position: "relative"
},
children: u.map((f) => {
var a;
return /* @__PURE__ */ d(
"div",
{
style: {
position: "absolute",
top: f.offset - (((a = s.current) == null ? void 0 : a.offsetTop) ?? 0),
right: 8
},
children: f.lineNumber
},
f.lineNumber
);
})