@sheetxl/io
Version:
IO - Import/Export Libraries for SheetXL.
1,470 lines • 69.5 kB
JavaScript
import { NumberFormat as It, ScalarType as Nt, IColor as we, Tuple as ve, IAutoFilter as Mt, AddressUtils as yt, CoordUtils as se, IRange as Se, FormulaError as Ce, ResourceCollection as ke, CommonUtils as ae, Theme as Ae, JSONStableStringify as Ee, Workbook as De, OutOfBoundsError as Pe } from "@sheetxl/sdk";
import { CommonUtils as fe } from "@sheetxl/utils";
/**
* @license @sheetxl/io - IO - Import/Export Libraries for SheetXL. - v0.4.0
*
* (C) 2025-present SheetXL Inc. & Michael T. Ford
* License: The license can be found at https://www.sheetxl.com/license.
*/
const le = ":A-Z_a-zÀ-ÖØ-öø-˿Ͱ-ͽͿ-⁰-Ⰰ-、-豈-﷏ﷰ-�𐀀-", Oe = new RegExp(`^[${le}][${`-${le}.0-9·̀-ͯ‿-⁀`}]*$`, "u"), Ie = [32, 10, 13, 9];
function me(i) {
return i >= 65 && i <= 90 || i >= 97 && i <= 122 || i === 58 || i === 95 || i === 8204 || i === 8205 || i >= 192 && i <= 214 || i >= 216 && i <= 246 || i >= 248 && i <= 767 || i >= 880 && i <= 893 || i >= 895 && i <= 8191 || i >= 8304 && i <= 8591 || i >= 11264 && i <= 12271 || i >= 12289 && i <= 55295 || i >= 63744 && i <= 64975 || i >= 65008 && i <= 65533 || i >= 65536 && i <= 983039;
}
const ce = "A-Z_a-zÀ-ÖØ-öø-˿Ͱ-ͽͿ--⁰-Ⰰ-、-豈-﷏ﷰ-�𐀀-", Ve = new RegExp(`^[${ce}][${`-${ce}.0-9·̀-ͯ‿-⁀`}]*$`, "u");
function Te(i) {
return i >= 65 && i <= 90 || i === 95 || i >= 97 && i <= 122 || i >= 192 && i <= 214 || i >= 216 && i <= 246 || i >= 248 && i <= 767 || i >= 880 && i <= 893 || i >= 895 && i <= 8191 || i >= 8204 && i <= 8205 || i >= 8304 && i <= 8591 || i >= 11264 && i <= 12271 || i >= 12289 && i <= 55295 || i >= 63744 && i <= 64975 || i >= 65008 && i <= 65533 || i >= 65536 && i <= 983039;
}
const et = function(i) {
return i === 32 || i === 10 || i === 13 || i === 9;
}, Le = function(i) {
return i >= 32 && i <= 55295 || i === 10 || i === 13 || i === 9 || i >= 57344 && i <= 65533 || i >= 65536 && i <= 1114111;
}, Ut = me, he = function(i) {
return me(i) || i >= 48 && i <= 57 || i === 45 || i === 46 || i === 183 || i >= 768 && i <= 879 || i >= 8255 && i <= 8256;
}, ye = Ie, Ne = Oe, Re = function(i) {
return i >= 1 && i <= 55295 || i >= 57344 && i <= 65533 || i >= 65536 && i <= 1114111;
}, $e = Te, Me = function(i) {
return Te(i) || i === 45 || i === 46 || i >= 48 && i <= 57 || i === 183 || i >= 768 && i <= 879 || i >= 8255 && i <= 8256;
}, je = Ve, Yt = "http://www.w3.org/XML/1998/namespace", Xt = "http://www.w3.org/2000/xmlns/", He = { __proto__: null, xml: Yt, xmlns: Xt }, Fe = { __proto__: null, amp: "&", gt: ">", lt: "<", quot: '"', apos: "'" }, N = -1, mt = -2, Y = 13, Vt = 33, ct = 10, Et = 60, Ht = 61, B = 62, Z = 63, Ft = 93, Kt = (i) => i === 34 || i === 39, be = [34, 39], Xe = [...be, 91, B], Be = [...be, Et, Ft], We = [Ht, Z, ...ye], _e = [...ye, B, 38, Et];
function ie(i, t, s) {
switch (t) {
case "xml":
s !== Yt && i.fail(`xml prefix must be bound to ${Yt}.`);
break;
case "xmlns":
s !== Xt && i.fail(`xmlns prefix must be bound to ${Xt}.`);
}
switch (s) {
case Xt:
i.fail(t === "" ? `the default namespace may not be set to ${s}.` : `may not assign a prefix (even "xmlns") to the URI ${Xt}.`);
break;
case Yt:
switch (t) {
case "xml":
break;
case "":
i.fail(`the default namespace may not be set to ${s}.`);
break;
default:
i.fail("may not assign the xml namespace to another prefix.");
}
}
}
const qe = (i) => je.test(i), Ue = (i) => Ne.test(i), ue = { xmldecl: "xmldeclHandler", text: "textHandler", processinginstruction: "piHandler", doctype: "doctypeHandler", comment: "commentHandler", opentagstart: "openTagStartHandler", attribute: "attributeHandler", opentag: "openTagHandler", closetag: "closeTagHandler", cdata: "cdataHandler", error: "errorHandler", end: "endHandler", ready: "readyHandler" };
class ze {
constructor(t) {
this.i = 0, this.prevI = 0, this.opt = t ?? {}, this.fragmentOpt = !!this.opt.fragment;
const s = this.xmlnsOpt = !!this.opt.xmlns;
if (this.trackPosition = this.opt.position !== !1, this.fileName = this.opt.fileName, s) {
this.nameStartCheck = $e, this.nameCheck = Me, this.isName = qe, this.processAttribs = this.processAttribsNS, this.pushAttrib = this.pushAttribNS, this.ns = { __proto__: null, ...He };
const o = this.opt.additionalNamespaces;
o != null && (function(n, a) {
for (const l of Object.keys(a)) ie(n, l, a[l]);
}(this, o), Object.assign(this.ns, o));
} else this.nameStartCheck = Ut, this.nameCheck = he, this.isName = Ue, this.processAttribs = this.processAttribsPlain, this.pushAttrib = this.pushAttribPlain;
this.stateTable = [this.sBegin, this.sBeginWhitespace, this.sDoctype, this.sDoctypeQuote, this.sDTD, this.sDTDQuoted, this.sDTDOpenWaka, this.sDTDOpenWakaBang, this.sDTDComment, this.sDTDCommentEnding, this.sDTDCommentEnded, this.sDTDPI, this.sDTDPIEnding, this.sText, this.sEntity, this.sOpenWaka, this.sOpenWakaBang, this.sComment, this.sCommentEnding, this.sCommentEnded, this.sCData, this.sCDataEnding, this.sCDataEnding2, this.sPIFirstChar, this.sPIRest, this.sPIBody, this.sPIEnding, this.sXMLDeclNameStart, this.sXMLDeclName, this.sXMLDeclEq, this.sXMLDeclValueStart, this.sXMLDeclValue, this.sXMLDeclSeparator, this.sXMLDeclEnding, this.sOpenTag, this.sOpenTagSlash, this.sAttrib, this.sAttribName, this.sAttribNameSawWhite, this.sAttribValue, this.sAttribValueQuoted, this.sAttribValueClosed, this.sAttribValueUnquoted, this.sCloseTag, this.sCloseTagSawWhite], this._init();
}
get closed() {
return this._closed;
}
_init() {
this.openWakaBang = "", this.text = "", this.name = "", this.piTarget = "", this.entity = "", this.q = null, this.tags = [], this.tag = null, this.topNS = null, this.chunk = "", this.chunkPosition = 0, this.i = 0, this.prevI = 0, this.carriedFromPrevious = void 0, this.forbiddenState = 0, this.attribList = [];
const { fragmentOpt: t } = this;
this.state = t ? Y : 0, this.reportedTextBeforeRoot = this.reportedTextAfterRoot = this.closedRoot = this.sawRoot = t, this.xmlDeclPossible = !t, this.xmlDeclExpects = ["version"], this.entityReturnState = void 0;
let { defaultXMLVersion: s } = this.opt;
if (s === void 0) {
if (this.opt.forceXMLVersion === !0) throw new Error("forceXMLVersion set but defaultXMLVersion is not set");
s = "1.0";
}
this.setXMLVersion(s), this.positionAtNewLine = 0, this.doctype = !1, this._closed = !1, this.xmlDecl = { version: void 0, encoding: void 0, standalone: void 0 }, this.line = 1, this.column = 0, this.ENTITIES = Object.create(Fe), this.readyHandler?.();
}
get position() {
return this.chunkPosition + this.i;
}
get columnIndex() {
return this.position - this.positionAtNewLine;
}
on(t, s) {
this[ue[t]] = s;
}
off(t) {
this[ue[t]] = void 0;
}
makeError(t) {
let s = this.fileName ?? "";
return this.trackPosition && (s.length > 0 && (s += ":"), s += `${this.line}:${this.column}`), s.length > 0 && (s += ": "), new Error(s + t);
}
fail(t) {
const s = this.makeError(t), o = this.errorHandler;
if (o === void 0) throw s;
return o(s), this;
}
write(t) {
if (this.closed) return this.fail("cannot write after close; assign an onready handler.");
let s = !1;
t === null ? (s = !0, t = "") : typeof t == "object" && (t = t.toString()), this.carriedFromPrevious !== void 0 && (t = `${this.carriedFromPrevious}${t}`, this.carriedFromPrevious = void 0);
let o = t.length;
const n = t.charCodeAt(o - 1);
!s && (n === 13 || n >= 55296 && n <= 56319) && (this.carriedFromPrevious = t[o - 1], o--, t = t.slice(0, o));
const { stateTable: a } = this;
for (this.chunk = t, this.i = 0; this.i < o; ) a[this.state].call(this);
return this.chunkPosition += o, s ? this.end() : this;
}
close() {
return this.write(null);
}
getCode10() {
const t = this.chunk, s = this.i;
if (this.prevI = s, this.i++, s >= t.length) return N;
const o = t.charCodeAt(s);
if (this.column++, o < 55296) {
if (o >= 32 || o === 9) return o;
switch (o) {
case ct:
return this.line++, this.column = 0, this.positionAtNewLine = this.position, ct;
case 13:
return t.charCodeAt(s + 1) === ct && (this.i = s + 2), this.line++, this.column = 0, this.positionAtNewLine = this.position, mt;
default:
return this.fail("disallowed character."), o;
}
}
if (o > 56319) return o >= 57344 && o <= 65533 || this.fail("disallowed character."), o;
const n = 65536 + 1024 * (o - 55296) + (t.charCodeAt(s + 1) - 56320);
return this.i = s + 2, n > 1114111 && this.fail("disallowed character."), n;
}
getCode11() {
const { chunk: t, i: s } = this;
if (this.prevI = s, this.i = s + 1, s >= t.length) return N;
const o = t.charCodeAt(s);
if (this.column++, o < 55296) {
if (o > 31 && o < 127 || o > 159 && o !== 8232 || o === 9) return o;
switch (o) {
case ct:
return this.line++, this.column = 0, this.positionAtNewLine = this.position, ct;
case 13: {
const a = t.charCodeAt(s + 1);
a !== ct && a !== 133 || (this.i = s + 2);
}
case 133:
case 8232:
return this.line++, this.column = 0, this.positionAtNewLine = this.position, mt;
default:
return this.fail("disallowed character."), o;
}
}
if (o > 56319) return o >= 57344 && o <= 65533 || this.fail("disallowed character."), o;
const n = 65536 + 1024 * (o - 55296) + (t.charCodeAt(s + 1) - 56320);
return this.i = s + 2, n > 1114111 && this.fail("disallowed character."), n;
}
getCodeNorm() {
const t = this.getCode();
return t === mt ? ct : t;
}
unget() {
this.i = this.prevI, this.column--;
}
captureTo(t) {
let { i: s } = this;
const { chunk: o } = this;
for (; ; ) {
const n = this.getCode(), a = n === mt, l = a ? ct : n;
if (l === N || t.includes(l)) return this.text += o.slice(s, this.prevI), l;
a && (this.text += `${o.slice(s, this.prevI)}
`, s = this.i);
}
}
captureToChar(t) {
let { i: s } = this;
const { chunk: o } = this;
for (; ; ) {
let n = this.getCode();
switch (n) {
case mt:
this.text += `${o.slice(s, this.prevI)}
`, s = this.i, n = ct;
break;
case N:
return this.text += o.slice(s), !1;
}
if (n === t) return this.text += o.slice(s, this.prevI), !0;
}
}
captureNameChars() {
const { chunk: t, i: s } = this;
for (; ; ) {
const o = this.getCode();
if (o === N) return this.name += t.slice(s), N;
if (!he(o)) return this.name += t.slice(s, this.prevI), o === mt ? ct : o;
}
}
skipSpaces() {
for (; ; ) {
const t = this.getCodeNorm();
if (t === N || !et(t)) return t;
}
}
setXMLVersion(t) {
this.currentXMLVersion = t, t === "1.0" ? (this.isChar = Le, this.getCode = this.getCode10) : (this.isChar = Re, this.getCode = this.getCode11);
}
sBegin() {
this.chunk.charCodeAt(0) === 65279 && (this.i++, this.column++), this.state = 1;
}
sBeginWhitespace() {
const t = this.i, s = this.skipSpaces();
switch (this.prevI !== t && (this.xmlDeclPossible = !1), s) {
case Et:
if (this.state = 15, this.text.length !== 0) throw new Error("no-empty text at start");
break;
case N:
break;
default:
this.unget(), this.state = Y, this.xmlDeclPossible = !1;
}
}
sDoctype() {
const t = this.captureTo(Xe);
switch (t) {
case B:
this.doctypeHandler?.(this.text), this.text = "", this.state = Y, this.doctype = !0;
break;
case N:
break;
default:
this.text += String.fromCodePoint(t), t === 91 ? this.state = 4 : Kt(t) && (this.state = 3, this.q = t);
}
}
sDoctypeQuote() {
const t = this.q;
this.captureToChar(t) && (this.text += String.fromCodePoint(t), this.q = null, this.state = 2);
}
sDTD() {
const t = this.captureTo(Be);
t !== N && (this.text += String.fromCodePoint(t), t === Ft ? this.state = 2 : t === Et ? this.state = 6 : Kt(t) && (this.state = 5, this.q = t));
}
sDTDQuoted() {
const t = this.q;
this.captureToChar(t) && (this.text += String.fromCodePoint(t), this.state = 4, this.q = null);
}
sDTDOpenWaka() {
const t = this.getCodeNorm();
switch (this.text += String.fromCodePoint(t), t) {
case 33:
this.state = 7, this.openWakaBang = "";
break;
case Z:
this.state = 11;
break;
default:
this.state = 4;
}
}
sDTDOpenWakaBang() {
const t = String.fromCodePoint(this.getCodeNorm()), s = this.openWakaBang += t;
this.text += t, s !== "-" && (this.state = s === "--" ? 8 : 4, this.openWakaBang = "");
}
sDTDComment() {
this.captureToChar(45) && (this.text += "-", this.state = 9);
}
sDTDCommentEnding() {
const t = this.getCodeNorm();
this.text += String.fromCodePoint(t), this.state = t === 45 ? 10 : 8;
}
sDTDCommentEnded() {
const t = this.getCodeNorm();
this.text += String.fromCodePoint(t), t === B ? this.state = 4 : (this.fail("malformed comment."), this.state = 8);
}
sDTDPI() {
this.captureToChar(Z) && (this.text += "?", this.state = 12);
}
sDTDPIEnding() {
const t = this.getCodeNorm();
this.text += String.fromCodePoint(t), t === B && (this.state = 4);
}
sText() {
this.tags.length !== 0 ? this.handleTextInRoot() : this.handleTextOutsideRoot();
}
sEntity() {
let { i: t } = this;
const { chunk: s } = this;
t: for (; ; ) switch (this.getCode()) {
case mt:
this.entity += `${s.slice(t, this.prevI)}
`, t = this.i;
break;
case 59: {
const { entityReturnState: o } = this, n = this.entity + s.slice(t, this.prevI);
let a;
this.state = o, n === "" ? (this.fail("empty entity name."), a = "&;") : (a = this.parseEntity(n), this.entity = ""), o === Y && this.textHandler === void 0 || (this.text += a);
break t;
}
case N:
this.entity += s.slice(t);
break t;
}
}
sOpenWaka() {
const t = this.getCode();
if (Ut(t)) this.state = 34, this.unget(), this.xmlDeclPossible = !1;
else switch (t) {
case 47:
this.state = 43, this.xmlDeclPossible = !1;
break;
case 33:
this.state = 16, this.openWakaBang = "", this.xmlDeclPossible = !1;
break;
case Z:
this.state = 23;
break;
default:
this.fail("disallowed character in tag name"), this.state = Y, this.xmlDeclPossible = !1;
}
}
sOpenWakaBang() {
switch (this.openWakaBang += String.fromCodePoint(this.getCodeNorm()), this.openWakaBang) {
case "[CDATA[":
this.sawRoot || this.reportedTextBeforeRoot || (this.fail("text data outside of root node."), this.reportedTextBeforeRoot = !0), this.closedRoot && !this.reportedTextAfterRoot && (this.fail("text data outside of root node."), this.reportedTextAfterRoot = !0), this.state = 20, this.openWakaBang = "";
break;
case "--":
this.state = 17, this.openWakaBang = "";
break;
case "DOCTYPE":
this.state = 2, (this.doctype || this.sawRoot) && this.fail("inappropriately located doctype declaration."), this.openWakaBang = "";
break;
default:
this.openWakaBang.length >= 7 && this.fail("incorrect syntax.");
}
}
sComment() {
this.captureToChar(45) && (this.state = 18);
}
sCommentEnding() {
const t = this.getCodeNorm();
t === 45 ? (this.state = 19, this.commentHandler?.(this.text), this.text = "") : (this.text += `-${String.fromCodePoint(t)}`, this.state = 17);
}
sCommentEnded() {
const t = this.getCodeNorm();
t !== B ? (this.fail("malformed comment."), this.text += `--${String.fromCodePoint(t)}`, this.state = 17) : this.state = Y;
}
sCData() {
this.captureToChar(Ft) && (this.state = 21);
}
sCDataEnding() {
const t = this.getCodeNorm();
t === Ft ? this.state = 22 : (this.text += `]${String.fromCodePoint(t)}`, this.state = 20);
}
sCDataEnding2() {
const t = this.getCodeNorm();
switch (t) {
case B:
this.cdataHandler?.(this.text), this.text = "", this.state = Y;
break;
case Ft:
this.text += "]";
break;
default:
this.text += `]]${String.fromCodePoint(t)}`, this.state = 20;
}
}
sPIFirstChar() {
const t = this.getCodeNorm();
this.nameStartCheck(t) ? (this.piTarget += String.fromCodePoint(t), this.state = 24) : t === Z || et(t) ? (this.fail("processing instruction without a target."), this.state = t === Z ? 26 : 25) : (this.fail("disallowed character in processing instruction name."), this.piTarget += String.fromCodePoint(t), this.state = 24);
}
sPIRest() {
const { chunk: t, i: s } = this;
for (; ; ) {
const o = this.getCodeNorm();
if (o === N) return void (this.piTarget += t.slice(s));
if (!this.nameCheck(o)) {
this.piTarget += t.slice(s, this.prevI);
const n = o === Z;
n || et(o) ? this.piTarget === "xml" ? (this.xmlDeclPossible || this.fail("an XML declaration must be at the start of the document."), this.state = n ? Vt : 27) : this.state = n ? 26 : 25 : (this.fail("disallowed character in processing instruction name."), this.piTarget += String.fromCodePoint(o));
break;
}
}
}
sPIBody() {
if (this.text.length === 0) {
const t = this.getCodeNorm();
t === Z ? this.state = 26 : et(t) || (this.text = String.fromCodePoint(t));
} else this.captureToChar(Z) && (this.state = 26);
}
sPIEnding() {
const t = this.getCodeNorm();
if (t === B) {
const { piTarget: s } = this;
s.toLowerCase() === "xml" && this.fail("the XML declaration must appear at the start of the document."), this.piHandler?.({ target: s, body: this.text }), this.piTarget = this.text = "", this.state = Y;
} else t === Z ? this.text += "?" : (this.text += `?${String.fromCodePoint(t)}`, this.state = 25);
this.xmlDeclPossible = !1;
}
sXMLDeclNameStart() {
const t = this.skipSpaces();
t !== Z ? t !== N && (this.state = 28, this.name = String.fromCodePoint(t)) : this.state = Vt;
}
sXMLDeclName() {
const t = this.captureTo(We);
if (t === Z) return this.state = Vt, this.name += this.text, this.text = "", void this.fail("XML declaration is incomplete.");
if (et(t) || t === Ht) {
if (this.name += this.text, this.text = "", !this.xmlDeclExpects.includes(this.name)) switch (this.name.length) {
case 0:
this.fail("did not expect any more name/value pairs.");
break;
case 1:
this.fail(`expected the name ${this.xmlDeclExpects[0]}.`);
break;
default:
this.fail(`expected one of ${this.xmlDeclExpects.join(", ")}`);
}
this.state = t === Ht ? 30 : 29;
}
}
sXMLDeclEq() {
const t = this.getCodeNorm();
if (t === Z) return this.state = Vt, void this.fail("XML declaration is incomplete.");
et(t) || (t !== Ht && this.fail("value required."), this.state = 30);
}
sXMLDeclValueStart() {
const t = this.getCodeNorm();
if (t === Z) return this.state = Vt, void this.fail("XML declaration is incomplete.");
et(t) || (Kt(t) ? this.q = t : (this.fail("value must be quoted."), this.q = 32), this.state = 31);
}
sXMLDeclValue() {
const t = this.captureTo([this.q, Z]);
if (t === Z) return this.state = Vt, this.text = "", void this.fail("XML declaration is incomplete.");
if (t === N) return;
const s = this.text;
switch (this.text = "", this.name) {
case "version": {
this.xmlDeclExpects = ["encoding", "standalone"];
const o = s;
this.xmlDecl.version = o, /^1\.[0-9]+$/.test(o) ? this.opt.forceXMLVersion || this.setXMLVersion(o) : this.fail("version number must match /^1\\.[0-9]+$/.");
break;
}
case "encoding":
/^[A-Za-z][A-Za-z0-9._-]*$/.test(s) || this.fail("encoding value must match /^[A-Za-z0-9][A-Za-z0-9._-]*$/."), this.xmlDeclExpects = ["standalone"], this.xmlDecl.encoding = s;
break;
case "standalone":
s !== "yes" && s !== "no" && this.fail('standalone value must match "yes" or "no".'), this.xmlDeclExpects = [], this.xmlDecl.standalone = s;
}
this.name = "", this.state = 32;
}
sXMLDeclSeparator() {
const t = this.getCodeNorm();
t !== Z ? (et(t) || (this.fail("whitespace required."), this.unget()), this.state = 27) : this.state = Vt;
}
sXMLDeclEnding() {
this.getCodeNorm() === B ? (this.piTarget !== "xml" ? this.fail("processing instructions are not allowed before root.") : this.name !== "version" && this.xmlDeclExpects.includes("version") && this.fail("XML declaration must contain a version."), this.xmldeclHandler?.(this.xmlDecl), this.name = "", this.piTarget = this.text = "", this.state = Y) : this.fail("The character ? is disallowed anywhere in XML declarations."), this.xmlDeclPossible = !1;
}
sOpenTag() {
const t = this.captureNameChars();
if (t === N) return;
const s = this.tag = { name: this.name, attributes: /* @__PURE__ */ Object.create(null) };
switch (this.name = "", this.xmlnsOpt && (this.topNS = s.ns = /* @__PURE__ */ Object.create(null)), this.openTagStartHandler?.(s), this.sawRoot = !0, !this.fragmentOpt && this.closedRoot && this.fail("documents may contain only one root."), t) {
case B:
this.openTag();
break;
case 47:
this.state = 35;
break;
default:
et(t) || this.fail("disallowed character in tag name."), this.state = 36;
}
}
sOpenTagSlash() {
this.getCode() === B ? this.openSelfClosingTag() : (this.fail("forward-slash in opening tag not followed by >."), this.state = 36);
}
sAttrib() {
const t = this.skipSpaces();
t !== N && (Ut(t) ? (this.unget(), this.state = 37) : t === B ? this.openTag() : t === 47 ? this.state = 35 : this.fail("disallowed character in attribute name."));
}
sAttribName() {
const t = this.captureNameChars();
t === Ht ? this.state = 39 : et(t) ? this.state = 38 : t === B ? (this.fail("attribute without value."), this.pushAttrib(this.name, this.name), this.name = this.text = "", this.openTag()) : t !== N && this.fail("disallowed character in attribute name.");
}
sAttribNameSawWhite() {
const t = this.skipSpaces();
switch (t) {
case N:
return;
case Ht:
this.state = 39;
break;
default:
this.fail("attribute without value."), this.text = "", this.name = "", t === B ? this.openTag() : Ut(t) ? (this.unget(), this.state = 37) : (this.fail("disallowed character in attribute name."), this.state = 36);
}
}
sAttribValue() {
const t = this.getCodeNorm();
Kt(t) ? (this.q = t, this.state = 40) : et(t) || (this.fail("unquoted attribute value."), this.state = 42, this.unget());
}
sAttribValueQuoted() {
const { q: t, chunk: s } = this;
let { i: o } = this;
for (; ; ) switch (this.getCode()) {
case t:
return this.pushAttrib(this.name, this.text + s.slice(o, this.prevI)), this.name = this.text = "", this.q = null, void (this.state = 41);
case 38:
return this.text += s.slice(o, this.prevI), this.state = 14, void (this.entityReturnState = 40);
case ct:
case mt:
case 9:
this.text += `${s.slice(o, this.prevI)} `, o = this.i;
break;
case Et:
return this.text += s.slice(o, this.prevI), void this.fail("disallowed character.");
case N:
return void (this.text += s.slice(o));
}
}
sAttribValueClosed() {
const t = this.getCodeNorm();
et(t) ? this.state = 36 : t === B ? this.openTag() : t === 47 ? this.state = 35 : Ut(t) ? (this.fail("no whitespace between attributes."), this.unget(), this.state = 37) : this.fail("disallowed character in attribute name.");
}
sAttribValueUnquoted() {
const t = this.captureTo(_e);
switch (t) {
case 38:
this.state = 14, this.entityReturnState = 42;
break;
case Et:
this.fail("disallowed character.");
break;
case N:
break;
default:
this.text.includes("]]>") && this.fail('the string "]]>" is disallowed in char data.'), this.pushAttrib(this.name, this.text), this.name = this.text = "", t === B ? this.openTag() : this.state = 36;
}
}
sCloseTag() {
const t = this.captureNameChars();
t === B ? this.closeTag() : et(t) ? this.state = 44 : t !== N && this.fail("disallowed character in closing tag.");
}
sCloseTagSawWhite() {
switch (this.skipSpaces()) {
case B:
this.closeTag();
break;
case N:
break;
default:
this.fail("disallowed character in closing tag.");
}
}
handleTextInRoot() {
let { i: t, forbiddenState: s } = this;
const { chunk: o, textHandler: n } = this;
t: for (; ; ) switch (this.getCode()) {
case Et:
if (this.state = 15, n !== void 0) {
const { text: a } = this, l = o.slice(t, this.prevI);
a.length !== 0 ? (n(a + l), this.text = "") : l.length !== 0 && n(l);
}
s = 0;
break t;
case 38:
this.state = 14, this.entityReturnState = Y, n !== void 0 && (this.text += o.slice(t, this.prevI)), s = 0;
break t;
case Ft:
switch (s) {
case 0:
s = 1;
break;
case 1:
s = 2;
break;
case 2:
break;
default:
throw new Error("impossible state");
}
break;
case B:
s === 2 && this.fail('the string "]]>" is disallowed in char data.'), s = 0;
break;
case mt:
n !== void 0 && (this.text += `${o.slice(t, this.prevI)}
`), t = this.i, s = 0;
break;
case N:
n !== void 0 && (this.text += o.slice(t));
break t;
default:
s = 0;
}
this.forbiddenState = s;
}
handleTextOutsideRoot() {
let { i: t } = this;
const { chunk: s, textHandler: o } = this;
let n = !1;
t: for (; ; ) {
const a = this.getCode();
switch (a) {
case Et:
if (this.state = 15, o !== void 0) {
const { text: l } = this, p = s.slice(t, this.prevI);
l.length !== 0 ? (o(l + p), this.text = "") : p.length !== 0 && o(p);
}
break t;
case 38:
this.state = 14, this.entityReturnState = Y, o !== void 0 && (this.text += s.slice(t, this.prevI)), n = !0;
break t;
case mt:
o !== void 0 && (this.text += `${s.slice(t, this.prevI)}
`), t = this.i;
break;
case N:
o !== void 0 && (this.text += s.slice(t));
break t;
default:
et(a) || (n = !0);
}
}
n && (this.sawRoot || this.reportedTextBeforeRoot || (this.fail("text data outside of root node."), this.reportedTextBeforeRoot = !0), this.closedRoot && !this.reportedTextAfterRoot && (this.fail("text data outside of root node."), this.reportedTextAfterRoot = !0));
}
pushAttribNS(t, s) {
const { prefix: o, local: n } = this.qname(t), a = { name: t, prefix: o, local: n, value: s };
if (this.attribList.push(a), this.attributeHandler?.(a), o === "xmlns") {
const l = s.trim();
this.currentXMLVersion === "1.0" && l === "" && this.fail("invalid attempt to undefine prefix in XML 1.0"), this.topNS[n] = l, ie(this, n, l);
} else if (t === "xmlns") {
const l = s.trim();
this.topNS[""] = l, ie(this, "", l);
}
}
pushAttribPlain(t, s) {
const o = { name: t, value: s };
this.attribList.push(o), this.attributeHandler?.(o);
}
end() {
this.sawRoot || this.fail("document must contain a root element.");
const { tags: t } = this;
for (; t.length > 0; ) {
const o = t.pop();
this.fail(`unclosed tag: ${o.name}`);
}
this.state !== 0 && this.state !== Y && this.fail("unexpected end.");
const { text: s } = this;
return s.length !== 0 && (this.textHandler?.(s), this.text = ""), this._closed = !0, this.endHandler?.(), this._init(), this;
}
resolve(t) {
let s = this.topNS[t];
if (s !== void 0) return s;
const { tags: o } = this;
for (let n = o.length - 1; n >= 0; n--) if (s = o[n].ns[t], s !== void 0) return s;
return s = this.ns[t], s !== void 0 ? s : this.opt.resolvePrefix?.(t);
}
qname(t) {
const s = t.indexOf(":");
if (s === -1) return { prefix: "", local: t };
const o = t.slice(s + 1), n = t.slice(0, s);
return (n === "" || o === "" || o.includes(":")) && this.fail(`malformed name: ${t}.`), { prefix: n, local: o };
}
processAttribsNS() {
const { attribList: t } = this, s = this.tag;
{
const { prefix: a, local: l } = this.qname(s.name);
s.prefix = a, s.local = l;
const p = s.uri = this.resolve(a) ?? "";
a !== "" && (a === "xmlns" && this.fail('tags may not have "xmlns" as prefix.'), p === "" && (this.fail(`unbound namespace prefix: ${JSON.stringify(a)}.`), s.uri = a));
}
if (t.length === 0) return;
const { attributes: o } = s, n = /* @__PURE__ */ new Set();
for (const a of t) {
const { name: l, prefix: p, local: v } = a;
let b, x;
p === "" ? (b = l === "xmlns" ? Xt : "", x = l) : (b = this.resolve(p), b === void 0 && (this.fail(`unbound namespace prefix: ${JSON.stringify(p)}.`), b = p), x = `{${b}}${v}`), n.has(x) && this.fail(`duplicate attribute: ${x}.`), n.add(x), a.uri = b, o[l] = a;
}
this.attribList = [];
}
processAttribsPlain() {
const { attribList: t } = this, s = this.tag.attributes;
for (const { name: o, value: n } of t) s[o] !== void 0 && this.fail(`duplicate attribute: ${o}.`), s[o] = n;
this.attribList = [];
}
openTag() {
this.processAttribs();
const { tags: t } = this, s = this.tag;
s.isSelfClosing = !1, this.openTagHandler?.(s), t.push(s), this.state = Y, this.name = "";
}
openSelfClosingTag() {
this.processAttribs();
const { tags: t } = this, s = this.tag;
s.isSelfClosing = !0, this.openTagHandler?.(s), this.closeTagHandler?.(s), (this.tag = t[t.length - 1] ?? null) === null && (this.closedRoot = !0), this.state = Y, this.name = "";
}
closeTag() {
const { tags: t, name: s } = this;
if (this.state = Y, this.name = "", s === "") return this.fail("weird empty close tag."), void (this.text += "</>");
const o = this.closeTagHandler;
let n = t.length;
for (; n-- > 0; ) {
const a = this.tag = t.pop();
if (this.topNS = a.ns, o?.(a), a.name === s) break;
this.fail("unexpected close tag.");
}
n === 0 ? this.closedRoot = !0 : n < 0 && (this.fail(`unmatched closing tag: ${s}.`), this.text += `</${s}>`);
}
parseEntity(t) {
if (t[0] !== "#") {
const o = this.ENTITIES[t];
return o !== void 0 ? o : (this.fail(this.isName(t) ? "undefined entity." : "disallowed character in entity name."), `&${t};`);
}
let s = NaN;
return t[1] === "x" && /^#x[0-9a-f]+$/i.test(t) ? s = parseInt(t.slice(2), 16) : /^#[0-9]+$/.test(t) && (s = parseInt(t.slice(1), 10)), this.isChar(s) ? String.fromCodePoint(s) : (this.fail("malformed character entity."), `&${t};`);
}
}
var oe, vt;
(vt = oe || (oe = {})).Events = { XmlDecl: "xmldecl", Text: "text", ProcessingInstruction: "processinginstruction", Doctype: "doctype", Comment: "comment", OpenTagStart: "opentagstart", Attribute: "attribute", OpenTag: "opentag", CloseTag: "closetag", CDdata: "cdata", Error: "error", End: "end", Ready: "ready" }, vt.parseStream = async (i, t, s) => {
const o = new ze({ position: !1, ...s });
let n;
if (t.onOpenTagStart && o.on(vt.Events.OpenTagStart, t.onOpenTagStart), t.onOpenTag && o.on(vt.Events.OpenTag, t.onOpenTag), t.onCloseTag && o.on(vt.Events.CloseTag, t.onCloseTag), t.onAttribute && o.on(vt.Events.Attribute, t.onAttribute), t.onText && o.on(vt.Events.Text, t.onText), t.onError && o.on(vt.Events.Error, t.onError), t.onEnd) {
t.onEnd;
const a = () => {
n = t.onEnd();
};
o.on(vt.Events.End, a);
}
for (; ; ) {
const { value: a, done: l } = await i.read();
if (l) break;
o.write(a);
}
return o.close(), n;
};
const D = (i) => i === !0 || i === "1" || i === "on" || i === "true" || i !== !1 && i !== "0" && i !== "off" && i !== "false" && null, V = (i) => {
const t = parseInt(i);
return isNaN(t) ? null : t;
}, Tt = (i) => {
const t = parseFloat(i);
return isNaN(t) ? null : t;
}, P = null;
class Ge {
constructor() {
this._registeredVisitors = /* @__PURE__ */ new Map();
}
registerVisitor(t) {
this._registeredVisitors.set(t.from, t);
}
createEventHandler(t, s, o) {
const n = this._registeredVisitors, a = [];
let l = null, p = null, v = null, b = null;
const x = [], C = { key: null, source: t };
let w = null, h = !1;
const A = (m, f) => {
let O = v.attributes[m];
if (f) {
if (Array.isArray(f)) {
for (let j = 0; j < f.length; j++)
if (O == null || (O = f[j](O), O == null)) return;
} else if (O == null || (O = f(O), O == null)) return;
}
return O;
}, g = { getSource: () => w.source, setSource: (m) => {
w.source = m;
}, setKey: (m) => {
w.key = m;
}, getFrom: () => v, getAttribute: (m, f) => A(m, f) ?? null, hasAttribute: (m) => g.getAttribute(m) !== null, getParent: () => x[x.length - 2].source, getPath: () => {
const m = [];
for (let f = 0; f < a.length; f++) m.push(a[f].local);
return m.join("\\");
}, parseAttribute: A, copyToObject: (m, f, O, j) => {
const W = A(j ?? f, O);
W !== void 0 && (m[f] = W);
}, copyTo: (m, f, O) => {
const j = A(O ?? m, f);
j !== void 0 && (w.source[m] = j);
}, warn: (m) => {
o ? o?.(m) : console.warn(m);
} };
return { onOpenTag: (m) => {
let f = m.name;
const O = f.indexOf(":");
O !== -1 && (f = f.slice(O + 1));
const j = n.get(f);
if (l = { local: f, visitor: j, tag: m, destination: null }, h) return a.push(l), p = f, void (v = m);
b = l?.visitor ?? null, j && (w = a.length === 0 ? C : b?.to !== null ? { key: null, source: {} } : null, l.destination = w, w && x.push(w)), a.push(l), p = f, v = m, h = b?.to === null, b?.openTag?.(g);
}, onCloseTag: (m) => {
let f = m.name;
const O = f.indexOf(":");
if (O !== -1 && (f = f.slice(O + 1)), f !== p) throw new Error(`mismatch open/close tag: '${f}'/'${p}'`);
h || b?.closeTag?.(g);
const j = a.pop() ?? null;
l = a[a.length - 1] ?? null;
const W = j?.destination;
if (W) {
x.pop(), w = x[x.length - 1] ?? C;
const J = j.visitor;
J && J.to && W.source !== void 0 && (Array.isArray(J.to) ? w.source.push ? w.source.push(W.source) : o?.(`Unable to parse array for ${J.from} at ${g.getPath()}`) : W.key ? w.source[W.key] = W.source : typeof J.to == "string" && (w.source[J.to] = W.source));
}
p = l?.local ?? null, v = l?.tag ?? null, b = l?.visitor ?? null, h = !l?.destination;
}, onText: (m) => {
b?.text?.(m, g);
}, onEnd: s };
}
}
const de = (i, t, s, o = null) => {
if (!i) return null;
let n = i;
n.startsWith("/") && (n = n.substring(1));
let a = o?.parsedRefs?.get(i);
if (a !== void 0) return a;
const l = t(n);
if (!l) return null;
let p = l.content;
try {
s && (p = s(p));
} catch (v) {
console.warn(v);
}
return o?.parsedRefs?.set(i, p), p;
}, re = (i, t, s, o, n = null) => {
if (!i) return null;
let a = i;
a.startsWith("/") && (a = a.substring(1));
let l = n?.parsedRefs?.get(i);
if (l !== void 0) return l;
const p = t(a);
if (!p) return null;
const v = p.content;
try {
const b = new TextDecoder().decode(v), x = s.parseFromString(b, "text/xml"), C = o.convert(x, i, n);
return n?.parsedRefs?.set(i, C), C;
} catch (b) {
console.warn(b);
}
return null;
}, jt = (i, t, s, o, n = null) => {
const a = /* @__PURE__ */ new Map();
let l = t.Directory[i];
const p = l ? l.length : 0;
for (let v = 0; v < p; v++) {
const b = l[v];
if (!b) continue;
let x = b;
x.startsWith("/") && (x = x.substring(1));
const C = re(x, (w) => t.files[w], s, o, n);
a.set(x, C);
}
return a;
}, Ze = async (i, t = 8388608) => {
await (async () => {
if (typeof ReadableStream > "u") if (typeof window > "u") {
const { ReadableStream: a } = await import("./XlPYQzhSzawTEu8J.mjs");
globalThis.ReadableStream = a;
} else console.warn("Browser does not support ReadableStream; consider loading a polyfill.");
})();
const s = new TextDecoder("utf-8");
let o = 0;
const n = i instanceof Uint8Array ? i : new Uint8Array(i);
return new ReadableStream({ pull(a) {
if (o >= n.byteLength) return void a.close();
const l = n.subarray(o, Math.min(o + t, n.byteLength)), p = s.decode(l, { stream: o + t < n.byteLength });
a.enqueue(p), o += l.length;
} }).getReader();
}, Je = ["lt1", "dk1", "lt2", "dk2", "accent1", "accent2", "accent3", "accent4", "accent5", "accent6", "hlink", "folHlink"], pe = (i, t = "dk1") => {
let s;
const o = i("auto");
o === void 0 || o !== "1" && o !== "true" || (s = t);
const n = i("indexed");
n && (s = `index${n}`);
const a = i("rgb");
a && (s = a.toLowerCase(), a.length !== 8 || a.startsWith("FF") || (s = "FF" + a.substring(2, a.length)));
const l = i("theme");
l && (s = Je[l]);
let p = i("tint");
if (p && (s += ` ${we.AdjustmentType.ETint} ${parseFloat(p)}`), s) return s;
}, Qe = (i) => i && i.replace(/^\{([\s\S]+)\}$/, "$1"), os = (i) => i ? fe.roundAccurately(parseFloat(i) / 12700, 4) : null, rs = (i) => i ? fe.roundAccurately(parseFloat(i) / 9525, 1) : null, ns = (i) => parseFloat(i) / 1e3, as = (i) => parseFloat(i) / 6e4, Ke = (i) => i === "true" || i === "1";
class Lt {
static {
this.Collapsed = 1;
}
static {
this.CustomFormat = 2;
}
static {
this.CustomHeight = 4;
}
static {
this.Hidden = 8;
}
static {
this.Ht = 16;
}
static {
this.OutlineLevel = 32;
}
static {
this.Ph = 64;
}
static {
this.R = 128;
}
static {
this.S = 256;
}
static {
this.Spans = 512;
}
static {
this.ThickBot = 1024;
}
static {
this.ThickTop = 2048;
}
}
const Ye = (i, t, s) => {
if (i[0].value[0] === i[1].value[0]) return t;
}, ge = { colStart: 0, colEnd: 0, rowStart: 0, rowEnd: 0 }, ts = (i, t, s, o, n, a) => {
let l = !1, p = !1, v = [], b = !1, x = null, C = null, w = null, h = null, A = null, g = null;
const m = a?.get("richData") ?? [], f = yt.normalizeA1ToR1C1, O = se.createConflatingRanges(), j = /* @__PURE__ */ new Map(), W = [];
let J = null;
const Bt = se.createConflatingRanges();
let ht, rt = !1, H = -1, $ = -1, tt = null, bt = null;
const Wt = [];
let Rt = null, _t = -2, nt = 0, at = "", ut = "", dt = "", Q = "", lt = "", pt = "", xt = "", te = "", Dt = "", zt = "", $t = "", Gt = "", Zt = "", E = "", R = !0, F = null;
return { ...s, onEnd: () => {
Wt.length > 0 && (t.rows = Wt);
let d = O.done(Ye);
const y = d.length;
if (y > 0) {
const L = new Array(y);
for (let k = 0; k < y; k++) {
const U = d[k], X = yt.rangeToString(U), z = U.value[1], st = yt.resolveRelativeToA1(z, U.rowStart, U.colStart);
L[k] = [X, st];
}
t.formulas = L;
}
const S = Bt.done(!0), I = S.length;
if (I > 0) {
const L = new Array(I);
for (let k = 0; k < I; k++) {
const U = S[k], X = yt.rangeToString(U);
L[k] = X;
}
t.volatile = L;
}
if (W.length > 0 && (t.dynamicArray = [...W]), v.length > 0) {
v.sort(se.createRangeComparator(Se.Orientation.Column));
const L = [];
let k = null, U = -1, X = -1, z = -1, st = -1, G = null;
const gt = v.length;
gt > 0 && (k = v[0], U = k.colStart, X = k.colEnd, z = k.rowEnd, st = k.value, L.push(k));
for (let it = 1; it < gt; it++) G = v[it], st !== G.value || U !== G.colStart || X !== G.colEnd || z + 1 !== G.rowEnd ? (L.push(G), k = G, U = k.colStart, X = k.colEnd, z = k.rowEnd, st = k.value) : (z = G.rowEnd, k.rowEnd = z);
let St = [];
for (let it = 0; it < L.length; it++) {
const Ct = L[it];
St.push({ r: { colStart: Ct.colStart, colEnd: Ct.colEnd, rowStart: Ct.rowStart, rowEnd: Ct.rowEnd }, v: Ct.value });
}
t.directStyles = St;
}
const K = i.build();
if (K) {
const L = K.tuples;
t.data = L;
}
s?.onEnd?.();
}, onOpenTag: (d) => {
let y = d.name;
const S = y.indexOf(":");
if (S !== -1 && (y = y.slice(S + 1)), ht) {
const I = d.attributes;
switch (y) {
case "v":
p = !0;
break;
case "f":
switch (I.t ?? null) {
case null:
case "normal":
b = !0;
break;
case "shared":
const K = I.si;
C = I.ref, x = K;
break;
case "array":
b = !0, C = I.ref, J = [C, !1];
break;
case "datatable":
b = !0, C = I.ref, b = !0;
}
I.ca !== void 0 && Bt.append(H, $);
break;
case "is":
return void (rt = !0);
}
return void (rt && n?.onOpenTag(d));
}
if (l) {
if (y === "c") {
ht = d;
const I = d.attributes.r;
$ = yt.fastStringToCol(I);
const K = d.attributes.t;
K === void 0 ? bt = null : (bt = K, bt === "str" && (rt = !0));
let L = d.attributes.s;
L !== void 0 && (L = parseInt(L), F && F.value === L && F.colEnd + 1 === $ ? F.colEnd = $ : (F = { colStart: $, rowStart: H, colEnd: $, rowEnd: H, value: L }, v.push(F)));
}
} else {
if (y === "row") {
l = !0;
const I = d.attributes.r;
if (H = parseInt(I) - 1, nt = 0, ut = d.attributes.customHeight, ut !== void 0 && (nt |= Lt.CustomHeight), ut !== Dt && (R = !0, Dt = ut), at = d.attributes.ht, at !== void 0 && (nt |= Lt.Ht), at !== te && (R = !0, te = at), dt = d.attributes.hidden, dt !== void 0 && (nt |= Lt.Hidden), dt !== zt && (R = !0, zt = dt), lt = d.attributes.s, lt !== void 0 && (nt |= Lt.S), lt !== Gt && (R = !0, Gt = lt), Q = d.attributes.customFormat, Q !== void 0 && (nt |= Lt.CustomFormat), Q !== $t && (R = !0, $t = Q), pt = d.attributes.outlineLevel, pt !== void 0 && (nt |= Lt.OutlineLevel), pt !== Zt && (R = !0, Zt = pt), xt = d.attributes.collapsed, xt !== void 0 && (nt |= Lt.Collapsed), xt !== E && (R = !0, E = xt), nt !== 0) if (_t + 1 !== H || R) {
const K = ut !== void 0 && (ut === "1" || ut === "true"), L = Q !== void 0 && (Q === "1" || Q === "true");
Rt = { min: H, max: H, sz: K && at !== void 0 ? parseFloat(at) : -1, csz: K, h: dt !== void 0 && (dt === "1" || dt === "true"), s: K && lt !== void 0 && lt !== "0" ? parseInt(lt) : 0, cs: L, l: pt === void 0 || pt === "0" ? 0 : parseInt(pt), cl: xt !== void 0 && (xt === "1" || xt === "true") }, Wt.push(Rt);
} else Rt.max = H;
return _t = H, void (R = !1);
}
s?.onOpenTag(d);
}
}, onCloseTag: (d) => {
if (ht) {
let y = d.name;
const S = y.indexOf(":");
if (S !== -1 && (y = y.slice(S + 1)), rt) if (y === "is" || y === "v") {
const I = n?.onEnd();
I !== null && i.addValue(H, $, "" + I);
} else n?.onCloseTag?.(d);
return p && (p = !1), void (y === "c" && (ht = null, rt = !1));
}
if (l) return l = !1, void (F = null);
s?.onCloseTag(d);
}, onText: (d) => {
if (d = d.trim(), p) {
switch (tt = null, bt) {
case null:
case "n":
tt = parseFloat(d);
break;
case "b":
tt = d === "1" || d === "true";
break;
case "s":
tt = d;
break;
case "e":
if (d === "#VALUE!") {
const S = ht.attributes.vm;
if (S !== void 0) {
const I = m[parseInt(S) - 1];
if (I && I.isFormulaError) {
tt = { t: Nt.Error, v: I.getCode() };
break;
}
}
}
const y = Ce.getBuiltInByLabel(d);
y ? tt = { t: Nt.Error, v: y.getCode() } : (tt = d, o?.(`Unknown formula error '${d}' in cell ${yt.cellToString({ colIndex: $, rowIndex: H })}`));
break;
case "str":
case "inlineStr":
rt = !0;
}
tt !== null && i.addValue(H, $, tt);
}
if (J && (bt === "e" && (J[1] = !0), W.push(J), J = null), x) if (A === x) h = g;
else {
if (h = j.get(x), !h) {
const y = [];
w = f(d, H, $, y), h = [w, y, d], j.set(x, h);
}
A = x, g = h;
}
if (b) {
const y = [];
w = f(d, H, $, y), h = [w, y, d];
}
if (h) return O.append(H, $, h), h = null, b = !1, x = null, void (C = null);
rt ? n?.onText(d) : l || s?.onText(d);
} };
}, ls = Object.freeze(Object.defineProperty({ __proto__: null, fromBufferXLSX: async (i, t) => {
const { password: s, onWarning: o, constructorOptions: n = {}, ...a } = t ?? {}, l = import("./DI9z9djr-PuhAoVK.mjs"), p = import("./Ct4f_QLqppwG71i_.mjs");
let v = null;
try {
v = new DOMParser();
} catch {
}
let b = null;
v || (b = import("./Byl-ZKBUNHsYzk3M.mjs").then((h) => h.i));
let x = null, C = null, w = null;
try {
const h = await Promise.all([l, p, b]);
x = h[0], C = h[1], w = h[2];
} catch (h) {
throw new Error("Unable to load XLSX parser.", { cause: h });
}
try {
const h = x.read(i, { type: "array", sheets: [], cellStyles: !1, bookFiles: !0 });
if (!h.Directory) throw new Error("Unable to parse as an Excel document. Try to save as '.xlsx' and try again.");
h.Directory.richstructure = ["/xl/richData/rdrichvaluestructure.xml"], h.Directory.richdata = ["/xl/richData/rdrichvalue.xml"];
const A = new C.FromOOXMLConverter(), g = v ?? new w.DOMParser(), m = n?.resources ?? new ke(), f = m.beginPersist(), O = {}, j = /* @__PURE__ */ new Set(), W = /* @__PURE__ */ new Map();
W.set("richTypes", []);
const J = /* @__PURE__ */ new Map(), Bt = [], ht = (E) => h.files[E], rt = (E, R) => {
const F = E.lastIndexOf("/"), d = E.substring(0, F + 1) + "_rels/" + E.substring(F + 1, E.length) + ".rels";
let y = R.get(d);
return y || (y = ((S, I, K, L, k = null) => {
if (!S) return null;
const U = re(S, I, K, L, k);
if (!U) return null;
const X = /* @__PURE__ */ new Map(), z = Object.keys(U), st = z.length;
for (let G = 0; G < st; G++) {
const gt = z[G], St = U[gt];
X.set(gt, St);
}
return X;
})(d, ht, g, A, $), R.set(d, y)), y;
}, H = (E, R, F, d = J) => {
let y = rt(R, d).get(E), S = y?.target;
if (!S) return null;
if (y.targetMode === "External") return y.target;
const I = R.lastIndexOf("/"), K = R.substring(0, I + 1);
S.startsWith("/") || (S = K + S), S = ((U) => {
const X = U.split(/\/+/);
return X.reduce((st, G, gt) => (G === "." ? st.splice(gt, 1) : G === ".." && st.splice(gt - 1, 2), st), X).join("/");
})(S);
const L = A?.getVisitorParamsState().get("dxfs");
let k = d.get(S);
if (!k)
if (y.type === "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet") {
const X = {};
k = X;
const z = async () => {
const st = ((_, ft, ee, kt, wt, Pt, At) => {
const u = new Ge(), ot = new ve.TransposedBuilder();
let q = null;
u.registerVisitor({ from: "autoFilter", to: "filter", openTag: (e) => {
e.copyTo("ref", P);
} }), u.registerVisitor({ from: "conditionalFormatting", to: {}, openTag: (e) => {
const r = e.getParent();
r.conditionals || (r.conditionals = []), r.conditionals.push(e.getSource());
const c = e.getAttribute("sqref");
c && (e.getSource().ref = c.split(" ").join(",")), e.copyTo("pivot", D);
}, closeTag: (e) => {
const r = e.getSource();
if (r.rule) {
const c = Object.keys(r.rule);
for (let T = 0; T < c.length; T++) {
const M = c[T];
M !== "rule" && (r[M] = r.rule[M]);
}
}
delete r.rule;
} }), u.registerVisitor({ from: "cfRule", to: "rule", openTag: (e) => {
const r = e.getParent();
e.copyToObject(r, "type", P), e.copyToObject(r, "priority", V), e.copyToObject(r, "stopIfTrue", D);
const c = e.getAttribute("dxfId", V);
if (c !== null) {
let T = kt?.get(c);
T || (Pt?.(`Unable to load conditional color. Invalid dxfI: '${c}' at '${e.getPath()}'.`), T = {}), r.style = T;
}
e.copyToObject(r, "aboveAverage", D), e.copyToObject(r, "equalAverage", D), e.copyToObject(r, "stdDev", V), e.copyToObject(r, "bottom", D), e.copyToObject(r, "percent", D), e.copyToObject(r, "rank", V), e.copyToObject(r, "operator", P), e.copyToObject(r, "text", P), e.copyToObject(r, "timePeriod", P);
} }), u.registerVisitor({ from: "colorScale", to: "colorScale" }), u.registerVisitor({ from: "dataBar", to: "dataBar", openTag: (e) => {
e.copyTo("maxLength", V), e.copyTo("minLength", V), e.copyTo("showValue", D);
} }), u.registerVisitor({ from: "iconSet", to: "iconSet", openTag: (e) => {
e.copyTo("iconSet", P), e.copyTo("reverse", D), e.copyTo("showValue", D);
} }), u.registerVisitor({ from: "formula", to: null, text: (e, r) => {
const c = r.getParent();
let T = c.formulas;
T || (T = [], c.formulas = T), T.push(e);
} }), u.registerVisitor({ from: "cfvo", to: {}, openTag: (e) => {
const r = e.getParent();
r.conditions || (r.conditions = []), r.conditions.push(e.getSource()), e.copyTo("type", P), e.copyTo("value", Tt, "val"), e.copyTo("gte", D);
} }), u.registerVisitor({ from: "color", to: {}, openTag: (e) => {
const r = e.getParent();
r.colors || (r.colors = []);
const c = pe((T) => e.getAttribute(T));
r.colors.push(c);
} }), u.registerVisitor({ from: "filterColumn", to: "filterColumn", openTag: (e) => {
const r = e.getParent();
r.fields || (r.fields = []), r.fields.push(e.getSource()), e.copyTo("offset", V, "colId"), e.copyTo("hiddenButton", D), e.copyTo("showButton", D);
} }), u.registerVisitor({ from: "colorFilter", to: "colorFilter", openTag: (e) => {
const r = e.getParent();
r.criteria || (r.criteria = []), r.criteria.push(e.getSource()), e.getSource().type = Mt.Type.Color, e.copyTo("cellColor", D), e.copyTo("styleId", V, "dxfId");
} }), u.registerVisitor({ from: "dynamicFilter", to: "dynamicFilter", openTag: (e) => {
const r = e.getParent();
r.criteria || (r.criteria = []), r.criteria.push(e.getSource()), e.getSource().type = Mt.Type.Dynamic, e.copyTo("dynamicType", P, "type"), e.copyTo("val", Tt), e.copyTo("maxVal", Tt, "maxVal");
} }), u.registerVisitor({ from: "iconFilter", to: "iconFilter", openTag: (e) => {
const r = e.getParent();
r.criteria || (r.criteria = []), r.criteria.push(e.getSource()), e.getSource().type = Mt.Type.Icon, e.copyTo("iconId", V), e.copyTo("iconSet", P);
} }), u.registerVisitor({ from: "top10", to: "top10", openTag: (e) => {
const r = e.getParent();
r.criteria || (r.criteria = []), r.criteria.push(e.getSource()), e.getSource().type = Mt.Type.Top10, e.copyTo("filterVal", Tt), e.copyTo("percent", D), e.copyTo("top", D), e.copyTo("val", Tt);
} }), u.registerVisitor({ from: "filters", to: "filters", openTag: (e) => {
const r = e.getParent();
r.criteria || (r.criteria = []), r.criteria.push(e.getSource()), e.getSource().type = Mt.Type.Items, e.copyTo("blank", D), e.copyTo("calendarType", P);
} }), u.registerVisitor({ from: "dateGroupItem", to: "dateGroupItem", openTag: (e) => {
const r = e.getParent();
r.dateGroups || (r.dateGroups = []), r.dateGroups.push(e.getSource()), e.copyTo("group", P, "dateTimeGrouping"), e.copyTo("day", V), e.copyTo("hour", V), e.copyTo("minute", V), e.copyTo("month", V), e.copyTo("second", V), e.copyTo("year", V);
} }), u.registerVisitor({ from: "filter", to: "filter", openTag: (e) => {
const r = e.getParent();
r.items || (r.items = []), r.items.push(e.getAttribute("val", Tt));
} }), u.registerVisitor({ from: "customFilters", to: "customFilters", openTag: (e) => {
const r = e.getParent();
r.criteria || (r.criteria = []), r.criteria.push(e.getSource()), e.getSource().type = Mt.Type.Custom, e.copyTo("and", D);
} }), u.registerVisitor({ from: "customFilter", to: "customFilter", openTag: (e) => {
const r = e.getParent();
r.filters || (r.filters = []), r.filters.push(e.getSource()), e.copyTo("operator", P), e.copyTo("value", Tt, "val");
} }), u.registerVisitor({ from: "sortState", to: "sort", openTag: (e) => {
e.copyTo("ref", P);
} }), u.registerVisitor({ from: "sortCondition", to: "sortCondition", openTag: (e) => {
const r = e.getParent();
r.fields || (r.fields = []);
const c = e.getSource();
r.fields.push(c), e.copyTo("sortOn", P, "sortBy"), e.copyTo("dxfId", P, "sortBy"), e.copyTo("iconSet", P), e.copyTo("customList", P);
const T = e.getAttribute("ref");
if (T) {
const M = yt.fastStringToRange(T, ge).colStart, Ot = yt.fastStringToRange(r.ref, ge), Qt = Ot.colStart;
c.offset = Ot ? M - Qt : M;
}
c.reverse = e.getAttribute("descending", D) ?? !1;
} }), u.registerVisitor({ from: "AlternateContent", to: null });
const Jt = (e) => {
q = e.getSource(), e.copyTo("topLeft", P, "topLeftCell");
const r = Ke(e.getAttribute("defaultGridColor")), c = e.getAttribute("colorId");
c === null || r || (e.getSource().gridLineColor = "index" + parseFloat(c)), e.copyTo("showZeros", D), e.copyTo("showFormulas", D), e.copyTo("zoomScale", V), e.copyTo("showRowHeaders", D, "showRowColHeaders"), e.copyTo("showColumnHeaders", D, "showRowColHeaders"), e.copyTo("showRowGridlines", D, "showGridLines"), e.copyTo("showColumnGridlines", D, "showGridLines");
};
u.registerVisitor({ from: "sheetView", to: "view", openTag: (e) => {
Jt(e);
}, closeTag: () => {
q = null;
} }), u.registerVisitor({ from: "customSheetViews", to: "customSheetViews", openTag: (e) => {
e.setSource([]);
} }), u.registerVisitor({ from: "customSheetView", to: [], openTag: (e) => {
Jt(e);
}, closeTag: () => {
q = null;
} }), u.registerVisitor({ from: "selection", to: "selection", openTag: (e) => {
if (!q) return;
e.copyTo("cell", P, "activeCell"), e.copyTo("rangeIndex", V, "activeCellId");
const r = e.getAttribute("activeCell"), c = e.getAttribute("sqref");
c && c !== r && (e.getSource().ranges = c.split(" "));
} }), u.registerVisitor({ from: "pane", to: "pane", openTag: (e) => {
if (q && e.getAttribute("state") === "frozen") {
const r = {};
q.freezePanes = r, e.copyToObject(r, "topLeft", P, "topLeftCell");
const c = q.topLeft ? yt.fastStringToCell(q.topLeft) : { colIndex: 0, rowIndex: 0 }, T = { colIndex: 0, rowIndex: 0 };
e.copyToObject(T, "colIndex", V, "xSplit"), e.copyToObject(T, "rowIndex", V, "ySplit");
const M = { colIndex: c.colIndex + T.colIndex, rowIndex: c.rowIndex + T.rowIndex };
r.coords = yt.cellToString(M);
}
} }), u.registerVisitor({ from: "tabColor", to: null, openTag: (e) => {
const r = pe((c) => e.getAttribute(c));
r && (_.tabColor = r);
} }), u.registerVisitor({ from: "pageSetUpPr", to: "pageSetUpPr", openTag: (e) => {
} }), u.registerVisitor({ from: "outlinePr", to: "outlinePr", openTag: (e) => {
} }), u.registerVisitor({ from: "pageMargins", to: "pageMargins", openTag: (e) => {
} }), u.registerVisitor({ from: "pageSetup", to: "pageSetup", openTag: (e) => {
} }), u.registerVisitor({ from: "printOptions", to: "printOptions", openTag: (e) => {
} }), u.registerVisitor({ from: "mergeCells", to: "merges", openTag: (e) => {
e.setSource([]);
} }), u.registerVisitor({ from: "mergeCell", to: [], openTag: (e) => {
const r = e.getAttribute("ref");
e.setSource(r);
} }), u.registerVisitor({ from: "hyperlinks", to: "hyperlinks", openTag: (e) => {
e.setSource([]);
} }), u.registerVisitor({ from: "hyperlink", to: [], openTag: (e) => {
const r = e.getAttribute("r:id"), c = e.getAttribute("ref");
if (!c) return void console.warn("No ref found for hyperlink");
e.setKey(c);
let T = r ? ft(r) : "";
if (typeof T != "string") return void console.warn("Invalid address ", T);
const M = e.getAttribute("location");
T.endsWith("\\") && (T = T.substring(0, T.length - 1));
const Ot = e.getAttribute("location");
if (Ot && (M && M !== Ot && console.warn("display and location are different", M, Ot), T += "#" + Ot), !T) return void console.warn("No address found for hyperlink. r:id", r);
let Qt;
const ne = e.getAttribute("tooltip");
Qt = ne ? { address: T, tooltip: ne } : T, e.setSource({ r: c, v: Qt });
} }), u.registerVisitor({ from: "drawing", to: "movables", openTag: (e) => {
const r = e.getAttribute("r:id");
if (!r) return;
const c = ft(r);
c ? e.setSource(c.movables) : console.warn("no drawing found for rId", r);
} }), u.registerVisitor({ from: "tableParts", to: "tables", openTag: (e) => {
e.setSource([]);
} }), u.registerVisitor({ from: "tablePart", to: [], openTag: (e) => {
const r = e.getAttribute("r:id");
if (!r) return;
const c = ft(r);
c ? e.setSource(c) : console.warn("no table found for rId", r);
} }), u.registerVisitor({ from: "worksheet", to: "worksheet", openTag: (e) => {
} }), u.registerVisitor({ from: "sheetProtection", to: "protection", openTag: (e) => {
let r = !1;
if (e.hasAttribute("sheet") && D(e.getAttribute("sheet")) && (r = !0), !r) return void e.setSource(void 0);
const c = (M) => M === !0 || M === "1" || M === "on" || M === "true" || M === !1 || M === "0" || M === "off" || M === "false" || null;
e.copyTo("autoFilter", c), e.copyTo("deleteColumns", c), e.copyTo("formatCells", c), e.copyTo("formatColumns", c), e.copyTo("formatRows", c), e.copyTo("insertColumns", c), e.copyTo("insertHyperlinks", c), e.copyTo("insertRows", c), e.copyTo("objects", c), e.copyTo("pivotTables", c), e.copyTo("scenarios", c), e.copyTo("selectUnlockedCells", c), e.copyTo("selectUnlockedCells", c), e.copyTo("sort", c);
const T = {};
e.copyToObject(T, "hash", P, "hashValue"), e.copyToObject(T, "algorithm", P, "algorithmName"), e.copyToObject(T, "salt", P, "saltValue"), e.copyToObject(T, "spinCount", V), Object.keys(T).length > 0 && (e.getSource().password = T);
} }), u.registerVisitor({ from: "protectedRanges", to: "protectedRanges", openTag: (e) => {
e.setSource({});
} }), u.registerVisitor({ from: "protectedRange", to: {}, openTag: (e) => {
const r = e.getAttribute("sqref");
e.setKey(r), e.copyTo("name"), e.copyTo("securityDescriptor");
const c = {};
e.copyToObject(c, "hash", P, "hashValue"), e.copyToObject(c, "algorithm", P, "algorithmName"), e.copyToObject(c, "salt", P, "saltValue"), e.copyToObject(c, "spinCount", V), Object.keys(c).length > 0 && (e.getSource().password = c);
} }), u.registerVisitor({ from: "sheetFormatPr", to: "sheetFormatPr", openTag: (e) => {
e.copyToObject(_, "defaultColSize", Tt, "defaultColWidth"), e.copyToObject(_, "outlineLevelCol", V, "outlineLevelCol");
const r = e.getAttribute("customHeight");
r !== "1" && r !== "true" || e.copyToObject(_, "defaultRowSize", Tt, "defaultRowHeight"), e.copyToObject(_, "outlineLevelRow", V, "outlineLevelRow");
} }), u.registerVisitor({ from: "cols", to: "cols", openTag: (e) => {
e.setSource([]);
} }), u.registerVisitor({ from: "col", to: [], openTag: (e) => {
e.copyTo("min", (r) => parseInt(r) - 1), e.copyTo("max", (r) => parseInt(r) - 1), e.copyTo("sz", Tt, "width"), e.copyTo("cs", D, "customWidth"), e.copyTo("h", D, "hidden"), e.copyTo("l", V, "outlineLevel"), e.copyTo("s", V, "style");
} }), u.registerVisitor({ from: "oleObjects", to: null, openTag: (e) => {
e.warn("'OLE Objects' are not supported.");
} });
let qt = null;
const xe = { onOpenTag: (e) => {
qt === null && (qt = "");
}, onText: (e) => {
qt += e;
}, onEnd: () => {
const e = ee(qt);
return qt = null, e;
}, onError: (e) => {
} };
return ts(ot, _, u.createEventHandler(_, wt, Pt), Pt, xe, At);
})(X, (_, ft = !1) => H(_, S, ft) ?? null, nt, L, () => {
}, (_) => {
o && (_ = S + ": " + _, o?.(_));
}, W), G = de(S, ht), gt = await Ze(G);
try {
await oe.parseStream(gt, st, { xmlns: !1 });
} catch (_) {
throw console.warn(`Error parsing sheet: '${S}'`, _), new Error(`Error parsing sheet: '${S}'`, { cause: _ });
}
const St = rt(S, d);
let it, Ct = /* @__PURE__ */ new Map();
if (St) {
const _ = "http://schemas.microsoft.com/office/2017/10/relationships/threadedComment";
let ft;
St.forEach((kt, wt) => {
kt.type === _ && (it = H(wt, S, !1, d)?.comments, it && it.forEach((At) => {
Ct.set(At.id, At);
}));
});
const ee = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
if (St.forEach((kt, wt) => {
kt.type === ee && (ft = H(wt, S, !1, d));
}), ft || it) {
const kt = it ?? [], wt = ft?.comments;
if (wt) {
const Pt = ft?.authors;
for (let At = 0; At < wt.length; At++) {
const u = wt[At];
let ot = u.authorId !== void 0 ? Pt[u.authorId] : void 0;
if ((!ot || ot.startsWith("tc=")) && (ot = Qe(ot.substring(3)), Ct.has(ot))) continue;
let q = at.get(ot);
q || (q = ut.get(ot)), q || (q = { id: ae.uuidV4(), displayName: ot }, ut.set(q.displayName, q), at.set(q.id, q)), ot = q?.id ?? null;
const Jt = { id: ae.uuidV4(), personId: ot, ref: u.ref, done: !1, asNote: !0, content: u.content };
kt.push(Jt);
}
}
X.comments = kt;
}
}
};
Bt.push(z());
} else k = F ? de(S, ht, (X) => {
const z = m.add({ buffer: X });
return z.addReference(O), j.add(z), f.toResourceId(z);
}, $) : re(S, ht, g, A, $);
return k;
}, $ = { paramMap: W, getRefs: rt, getRef: H, parsedRefs: J, onWarning: o, addPerson: (E) => null }, tt = [];
let bt = 0;
h.Strings && (bt = parseInt(h.Strings.Unique ?? h.Strings.length ?? 0));
const Wt = h.Strings ?? [];
for (let E = 0; E < bt; E++) tt.push(Wt[E]?.t ?? "");
const Rt = /* @__PURE__ */ new Map();
let _t = bt;
const nt = (E) => {
const R = Rt.get(E);
if (R !== void 0) return R;
const F = _t;
return Rt.set(E, _t++), tt.push(E), F;
}, at = (jt("richstructure", h, g, A, $), jt("richdata", h, g, A, $), /* @__PURE__ */ new Map()), ut = /* @__PURE__ */ new Map(), dt = jt("people", h, g, A);
let Q = null;
if (dt.size > 0 && (Q = dt.entries().next()?.value?.[1]?.persons, Q)) {
const E = Q.length;
for (let R = 0; R < E; R++) {
const F = Q[R];
at.set(F.id, F), at.set(F.displayName, F);
}
}
const lt = jt("themes", h, g, A, $);
let pt = null;
if (lt && lt.entries) {
let E = lt.entries().next();
E?.value?.[1] && (pt = E.value[1]);
}
const xt = new Ae(pt);
let Dt = jt("styles", h, g, A, $).entries().next()?.value[1];
Dt && (Dt = JSON.parse(Ee(Dt)));
const zt = jt("workbooks", h, g, A, $);
await Promise.all(Bt);
const $t = { ...zt.entries().next().value[1], styles: Dt, theme: xt.toJSON() };
tt.length > 0 && ($t.strings = tt), Q && Q.length > 0 && ($t.people = Q);
const Gt = { ...n, resources: m, json: $t }, Zt = new De(Gt);
return j.forEach((E) => {
E.deleteReference(O);
}), f.endPersist(), Zt;
} catch (h) {
let A = "Unable to parse XLSX.";
throw h instanceof Pe && (A = "Unable to open XLSX. There are too many rows or columns."), new Error(A, { cause: h });
}
}, toBufferXLSX: async (i, t) => {
const s = await import("./DI9z9djr-PuhAoVK.mjs"), o = await i.toJSON(!0), n = s.utils.book_new();
for (let a = 0; a < o.sheets.length; a++) {
const l = o.sheets[a], p = s.utils.json_to_sheet([{}]);
s.utils.book_append_sheet(n, p, l.name);
const v = l.sheet, b = i.getSheetAt(a), x = b.getUsedRange();
if (x ? (p["!ref"] = x.getA1(), x.forEach((C, w) => {
const h = { t: "z" }, A = w.getCell().getStyle();
if (!A.isNormal()) {
let g = A.getNumberFormat();
g !== It.Type.General && (g === It.Type.ShortDate ? g = "m/d/yyyy" : g === It.Type.MediumDate ? g = "d-mmm-yy" : g === It.Type.LongDate ? g = "[$-x-sysdate]dddd, mmmm dd, yyyy" : g === It.Type.ShortTime ? g = "h:mm" : g === It.Type.MediumTime ? g = "h:mm AM/PM" : g === It.Type.LongTime && (g = "h:mm:ss AM/PM"), h.z = g);
}
if (C !== null) switch (w.getType()) {
case Nt.Number:
h.t = "n", h.v = C;
break;
case Nt.String:
h.t = "s", h.v = C;
break;
case Nt.Boolean:
h.t = "b", h.v = C;
break;
case Nt.Error:
h.t = "e", h.v = C.toString();
case Nt.RichData:
}
p[w.getA1()] = h;
})) : p["!ref"] = "A1:A1", v.merges?.length > 0) {
const C = [];
p["!merges"] = C;
for (let w = 0; w < v.merges.length; w++) C.push(s.utils.decode_range(v.merges[w]));
}
if (v.cols?.length > 0) {
const C = [];
p["!cols"] = C;
const w = v.cols, h = { width: v.defaultColSize ?? b.getColumnWidthAsFontUnit(b.getColumnHeaders().getDefaultSize()) };
for (let A = 0; A < w.length; A++) {
const g = w[A];
for (let f = C.length; f <= g.min - 1; f++) C.push(h);
const m = {};
g.sz !== void 0 && (m.width = g.sz), g.h !== void 0 && (m.hidden = g.h), g.l !== void 0 && (m.level = g.l);
for (let f = g.min; f <= g.max; f++) C.push(m);
}
}
}
return s.write(n, { type: "array", bookType: "xlsx" }), s.write(n, { type: "array", bookType: "xlsx" });
} }, Symbol.toStringTag, { value: "Module" }));
export {
ns as a,
Ke as b,
rs as c,
pe as d,
ls as i,
as as p,
Qe as r,
os as t
};