excel-builder-vanilla
Version:
An easy way of building Excel files with javascript
1,213 lines • 65.4 kB
JavaScript
import { strToU8, zip, zipSync } from "fflate";
function isObject(s) {
let D = typeof s;
return s != null && (D === "object" || D === "function");
}
function isPlainObject(s) {
if (typeof s != "object" || !s || Object.prototype.toString.call(s) !== "[object Object]") return !1;
/* v8 ignore next 4 */
let D = Object.getPrototypeOf(s);
if (D === null) return !0;
let O = Object.prototype.hasOwnProperty.call(D, "constructor") && D.constructor;
return typeof O == "function" && O instanceof O && Function.prototype.call(O) === Function.prototype.call(s);
}
function isString(s) {
return s != null && typeof s.valueOf() == "string";
}
var htmlEscapes = {
"&": "&",
"<": "<",
">": ">",
"\"": """,
"'": "'"
};
const htmlEscape = (s) => (typeof s != "string" && (s = `${s}`), s.replace(/[&<>"']/g, (s) => htmlEscapes[s]));
var XMLDOM = class {
documentElement;
constructor(s, D) {
this.documentElement = this.createElement(D), this.documentElement.setAttribute("xmlns", s);
}
createElement(s) {
return new XMLNode({ nodeName: s });
}
createTextNode(s) {
return new TextNode(s);
}
toString() {
return this.documentElement.toString();
}
static Node = { Create: (s) => {
switch (s.type) {
case "XML": return new XMLNode(s);
case "TEXT": return new TextNode(s.nodeValue);
default: return null;
}
} };
}, TextNode = class {
nodeValue;
constructor(s) {
this.nodeValue = s;
}
toJSON() {
return {
nodeValue: this.nodeValue,
type: "TEXT"
};
}
toString() {
return htmlEscape(this.nodeValue);
}
}, XMLNode = class s {
nodeName;
children;
nodeValue;
attributes;
firstChild;
constructor(s) {
if (this.nodeName = s.nodeName, this.children = [], this.nodeValue = s.nodeValue || "", this.attributes = {}, s.children) for (let D = 0, O = s.children.length; D < O; D++) this.appendChild(XMLDOM.Node.Create(s.children[D]));
if (s.attributes) for (let [D, O] of Object.entries(s.attributes)) this.setAttribute(D, O);
}
toString() {
let s = `<${this.nodeName}`;
for (let D in this.attributes) this.attributes.hasOwnProperty(D) && (s = `${s} ${D}="${htmlEscape(this.attributes[D])}"`);
let D = "";
for (let s = 0, O = this.children.length; s < O; s++) D += this.children[s].toString();
return D ? s += `>${D}</${this.nodeName}>` : s += "/>", s;
}
toJSON() {
let s = [];
for (let D = 0, O = this.children.length; D < O; D++) s.push(this.children[D].toJSON());
return {
nodeName: this.nodeName,
children: s,
nodeValue: this.nodeValue,
attributes: this.attributes,
type: "XML"
};
}
setAttribute(s, D) {
if (D === null) {
delete this.attributes[s], delete this[s];
return;
}
this.attributes[s] = D, this[s] = D;
}
appendChild(s) {
this.children.push(s), this.firstChild = this.children[0];
}
cloneNode(D) {
return new s(this.toJSON());
}
}, Util = class s {
static _idSpaces = {};
static uniqueId(D) {
return s._idSpaces[D] || (s._idSpaces[D] = 1), s._idSpaces[D]++;
}
static createXmlDoc(s, D) {
return new XMLDOM(s || null, D);
}
static createElement(s, D, O) {
let k = s.createElement(D);
O ||= [];
let A = O.length;
for (; A--;) k.setAttribute(O[A][0], O[A][1]);
return k;
}
static setAttributesOnDoc(s, D) {
for (let [O, k] of Object.entries(D)) {
if (isPlainObject(k)) if (k.v !== null && k.v !== void 0) switch (k.type) {
case Boolean:
k = k.v ? "1" : "0";
break;
}
else k = null;
k != null && s.setAttribute(O, k);
}
}
static LETTER_REFS = {};
static positionToLetterRef(D, O) {
let k = 1, A, j = D, M = "";
if (s.LETTER_REFS[D]) return s.LETTER_REFS[D].concat(O);
for (; j > 0;) j -= 26 ** (k - 1), A = j % 26 ** k, j -= A, A /= 26 ** (k - 1), M = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(A) + M, k += 1;
return s.LETTER_REFS[D] = M, M.concat(String(O));
}
static schemas = {
worksheet: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",
sharedStrings: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",
stylesheet: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
relationships: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
relationshipPackage: "http://schemas.openxmlformats.org/package/2006/relationships",
contentTypes: "http://schemas.openxmlformats.org/package/2006/content-types",
spreadsheetml: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
markupCompat: "http://schemas.openxmlformats.org/markup-compatibility/2006",
x14ac: "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac",
officeDocument: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
package: "http://schemas.openxmlformats.org/package/2006/relationships",
table: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table",
spreadsheetDrawing: "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",
drawing: "http://schemas.openxmlformats.org/drawingml/2006/main",
drawingRelationship: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing",
image: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
chart: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
hyperlink: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
};
}, AbsoluteAnchor = class {
x = null;
y = null;
width = null;
height = null;
constructor(s) {
s && (this.setPos(s.x, s.y), this.setDimensions(s.width || 0, s.height || 0));
}
setPos(s, D) {
this.x = s, this.y = D;
}
setDimensions(s, D) {
this.width = s, this.height = D;
}
toXML(s, D) {
let O = Util.createElement(s, "xdr:absoluteAnchor"), k = Util.createElement(s, "xdr:pos");
k.setAttribute("x", this.x), k.setAttribute("y", this.y), O.appendChild(k);
let A = Util.createElement(s, "xdr:ext");
return A.setAttribute("cx", this.width), A.setAttribute("cy", this.height), O.appendChild(A), O.appendChild(D), O.appendChild(Util.createElement(s, "xdr:clientData")), O;
}
}, idCounter = {};
function uniqueId(s = "$lodash$") {
idCounter[s] || (idCounter[s] = 0);
let D = ++idCounter[s];
return s === "$lodash$" ? `${D}` : `${s}${D}`;
}
var OneCellAnchor = class {
x = null;
y = null;
xOff = null;
yOff = null;
width = null;
height = null;
constructor(s) {
s && (this.setPos(s.x, s.y, s.xOff, s.yOff), this.setDimensions(s.width || 0, s.height || 0));
}
setPos(s, D, O, k) {
this.x = s, this.y = D, O !== void 0 && (this.xOff = O), k !== void 0 && (this.yOff = k);
}
setDimensions(s, D) {
this.width = s, this.height = D;
}
toXML(s, D) {
let O = Util.createElement(s, "xdr:oneCellAnchor"), k = Util.createElement(s, "xdr:from"), A = Util.createElement(s, "xdr:col");
A.appendChild(s.createTextNode(String(this.x)));
let j = Util.createElement(s, "xdr:colOff");
j.appendChild(s.createTextNode(String(this.xOff || 0)));
let M = Util.createElement(s, "xdr:row");
M.appendChild(s.createTextNode(String(this.y)));
let N = Util.createElement(s, "xdr:rowOff");
N.appendChild(s.createTextNode(String(this.yOff || 0))), k.appendChild(A), k.appendChild(j), k.appendChild(M), k.appendChild(N), O.appendChild(k);
let P = Util.createElement(s, "xdr:ext");
return P.setAttribute("cx", String(this.width)), P.setAttribute("cy", String(this.height)), O.appendChild(P), O.appendChild(D), O.appendChild(Util.createElement(s, "xdr:clientData")), O;
}
}, TwoCellAnchor = class {
from = {
xOff: 0,
yOff: 0
};
to = {
xOff: 0,
yOff: 0
};
constructor(s) {
s && (this.setFrom(s.from.x, s.from.y, s.from.xOff, s.from.yOff), this.setTo(s.to.x, s.to.y, s.to.xOff, s.to.yOff));
}
setFrom(s, D, O, k) {
this.from.x = s, this.from.y = D, O !== void 0 && (this.from.xOff = O), k !== void 0 && (this.from.yOff = k);
}
setTo(s, D, O, k) {
this.to.x = s, this.to.y = D, O !== void 0 && (this.to.xOff = O), k !== void 0 && (this.to.yOff = k);
}
toXML(s, D) {
let O = Util.createElement(s, "xdr:twoCellAnchor"), k = Util.createElement(s, "xdr:from"), A = Util.createElement(s, "xdr:col");
A.appendChild(s.createTextNode(this.from.x));
let j = Util.createElement(s, "xdr:colOff");
j.appendChild(s.createTextNode(this.from.xOff));
let M = Util.createElement(s, "xdr:row");
M.appendChild(s.createTextNode(this.from.y));
let N = Util.createElement(s, "xdr:rowOff");
N.appendChild(s.createTextNode(this.from.yOff)), k.appendChild(A), k.appendChild(j), k.appendChild(M), k.appendChild(N);
let P = Util.createElement(s, "xdr:to"), F = Util.createElement(s, "xdr:col");
F.appendChild(s.createTextNode(this.to.x));
let I = Util.createElement(s, "xdr:colOff");
I.appendChild(s.createTextNode(this.from.xOff));
let L = Util.createElement(s, "xdr:row");
L.appendChild(s.createTextNode(this.to.y));
let R = Util.createElement(s, "xdr:rowOff");
return R.appendChild(s.createTextNode(this.from.yOff)), P.appendChild(F), P.appendChild(I), P.appendChild(L), P.appendChild(R), O.appendChild(k), O.appendChild(P), O.appendChild(D), O.appendChild(Util.createElement(s, "xdr:clientData")), O;
}
}, Drawing = class {
anchor;
id = uniqueId("Drawing");
createAnchor(s, D) {
switch (D ??= {}, D.drawing = this, s) {
case "absoluteAnchor":
this.anchor = new AbsoluteAnchor(D);
break;
case "oneCellAnchor":
this.anchor = new OneCellAnchor(D);
break;
case "twoCellAnchor":
this.anchor = new TwoCellAnchor(D);
break;
}
return this.anchor;
}
}, Chart = class extends Drawing {
relId = null;
index = null;
target = null;
options;
constructor(s) {
super(), this.options = s;
}
getMediaType() {
return "chart";
}
setRelationshipId(s) {
this.relId = s;
}
toXML(s) {
return this.anchor.toXML(s, this._createGraphicFrame(s));
}
toChartSpaceXML() {
let s = Util.createXmlDoc("http://schemas.openxmlformats.org/drawingml/2006/chart", "c:chartSpace"), D = s.documentElement;
D.setAttribute("xmlns:c", "http://schemas.openxmlformats.org/drawingml/2006/chart"), D.setAttribute("xmlns:a", Util.schemas.drawing), D.setAttribute("xmlns:r", Util.schemas.relationships);
let O = Util.createElement(s, "c:chart");
this.options.title ? (O.appendChild(this._createTitleNode(s, this.options.title)), O.appendChild(Util.createElement(s, "c:autoTitleDeleted", [["val", "0"]]))) : O.appendChild(Util.createElement(s, "c:autoTitleDeleted", [["val", "1"]]));
let k = Util.createElement(s, "c:plotArea"), A = this._nextAxisIdBase(), j = A + 1, M = A + 2, N = this.options.type || "column", P = this.options.categoriesRange || "", F = this._createPrimaryChartNode(s, N, this.options.stacking), I = this.options.series || [];
I.forEach((D, O) => {
F.appendChild(this._createSeriesNode(s, D, O, N, P));
});
let L = this.options.dataLabels;
if (L) {
let D = Util.createElement(s, "c:dLbls"), O = (O, k) => D.appendChild(Util.createElement(s, O, [["val", k === !0 ? "1" : "0"]]));
O("c:showVal", L.showValue), O("c:showCatName", L.showCategory), O("c:showPercent", L.showPercent), O("c:showSerName", L.showSeriesName), F.appendChild(D);
}
if (N !== "pie" && N !== "doughnut" && (F.appendChild(Util.createElement(s, "c:axId", [["val", String(j)]])), F.appendChild(Util.createElement(s, "c:axId", [["val", String(M)]]))), k.appendChild(F), N !== "pie" && N !== "doughnut") {
let D = this.options.axis?.x, O = this.options.axis?.y, A = D?.title, P = O?.title;
N === "scatter" ? (k.appendChild(this._createValueAxis(s, j, M, "b", A, D)), k.appendChild(this._createValueAxis(s, M, j, "l", P, O))) : (k.appendChild(this._createCategoryAxis(s, j, M, A, D)), k.appendChild(this._createValueAxis(s, M, j, "l", P, O)));
}
let R = this.options.legend, z = I.length > 1;
return (typeof R?.show == "boolean" ? R.show : z) && O.appendChild(this._createLegendNode(s, R)), O.appendChild(k), O.appendChild(Util.createElement(s, "c:plotVisOnly", [["val", "1"]])), D.appendChild(O), D.appendChild(Util.createElement(s, "c:printSettings")), s;
}
_createGraphicFrame(s) {
let D = Util.createElement(s, "xdr:graphicFrame"), O = Util.createElement(s, "xdr:nvGraphicFramePr");
O.appendChild(Util.createElement(s, "xdr:cNvPr", [["id", String(this.index || 1)], ["name", this.options.title || "Chart"]])), O.appendChild(Util.createElement(s, "xdr:cNvGraphicFramePr")), D.appendChild(O);
let k = Util.createElement(s, "xdr:xfrm");
k.appendChild(Util.createElement(s, "a:off", [["x", "0"], ["y", "0"]])), k.appendChild(Util.createElement(s, "a:ext", [["cx", String(this.options.width || 4e6)], ["cy", String(this.options.height || 3e6)]])), D.appendChild(k);
let A = Util.createElement(s, "a:graphic"), j = Util.createElement(s, "a:graphicData", [["uri", "http://schemas.openxmlformats.org/drawingml/2006/chart"]]);
return j.appendChild(Util.createElement(s, "c:chart", [
["xmlns:c", "http://schemas.openxmlformats.org/drawingml/2006/chart"],
["xmlns:r", Util.schemas.relationships],
["r:id", this.relId || ""]
])), A.appendChild(j), D.appendChild(A), D;
}
_createPrimaryChartNode(s, D, O) {
let k, A = this._resolveGrouping(D, O);
switch (D) {
case "line":
k = Util.createElement(s, "c:lineChart"), k.appendChild(Util.createElement(s, "c:grouping", [["val", A]])), k.appendChild(Util.createElement(s, "c:varyColors", [["val", "0"]]));
break;
case "pie":
k = Util.createElement(s, "c:pieChart"), k.appendChild(Util.createElement(s, "c:grouping", [["val", "clustered"]])), k.appendChild(Util.createElement(s, "c:varyColors", [["val", "1"]]));
break;
case "doughnut":
k = Util.createElement(s, "c:doughnutChart"), k.appendChild(Util.createElement(s, "c:grouping", [["val", "clustered"]])), k.appendChild(Util.createElement(s, "c:varyColors", [["val", "1"]])), k.appendChild(Util.createElement(s, "c:holeSize", [["val", "50"]]));
break;
case "scatter":
k = Util.createElement(s, "c:scatterChart"), k.appendChild(Util.createElement(s, "c:scatterStyle", [["val", "marker"]])), k.appendChild(Util.createElement(s, "c:varyColors", [["val", "0"]]));
break;
case "bar":
k = Util.createElement(s, "c:barChart"), k.appendChild(Util.createElement(s, "c:barDir", [["val", "bar"]])), k.appendChild(Util.createElement(s, "c:grouping", [["val", A]])), O && k.appendChild(Util.createElement(s, "c:overlap", [["val", "100"]])), k.appendChild(Util.createElement(s, "c:varyColors", [["val", "0"]]));
break;
case "column":
default:
k = Util.createElement(s, "c:barChart"), k.appendChild(Util.createElement(s, "c:barDir", [["val", "col"]])), k.appendChild(Util.createElement(s, "c:grouping", [["val", A]])), O && k.appendChild(Util.createElement(s, "c:overlap", [["val", "100"]])), k.appendChild(Util.createElement(s, "c:varyColors", [["val", "0"]]));
break;
}
return k;
}
_createSeriesNode(s, D, O, k, A) {
let j = Util.createElement(s, "c:ser"), M = String(O);
j.appendChild(Util.createElement(s, "c:idx", [["val", M]])), j.appendChild(Util.createElement(s, "c:order", [["val", M]]));
let N = Util.createElement(s, "c:tx"), P = Util.createElement(s, "c:v");
if (P.appendChild(s.createTextNode(D.name)), N.appendChild(P), j.appendChild(N), k === "scatter") {
let O = Util.createElement(s, "c:xVal");
if (D.scatterXRange) {
let k = Util.createElement(s, "c:numRef"), A = Util.createElement(s, "c:f");
A.appendChild(s.createTextNode(D.scatterXRange)), k.appendChild(A), O.appendChild(k);
} else {
let D = Util.createElement(s, "c:numLit");
D.appendChild(Util.createElement(s, "c:ptCount", [["val", "0"]])), O.appendChild(D);
}
j.appendChild(O);
let k = Util.createElement(s, "c:yVal"), A = Util.createElement(s, "c:numRef"), M = Util.createElement(s, "c:f");
M.appendChild(s.createTextNode(D.valuesRange)), A.appendChild(M), k.appendChild(A), j.appendChild(k);
} else {
if (A) {
let D = Util.createElement(s, "c:cat"), O = Util.createElement(s, "c:strRef"), k = Util.createElement(s, "c:f");
k.appendChild(s.createTextNode(A)), O.appendChild(k), D.appendChild(O), j.appendChild(D);
}
if (D.valuesRange) {
let O = Util.createElement(s, "c:val"), k = Util.createElement(s, "c:numRef"), A = Util.createElement(s, "c:f");
A.appendChild(s.createTextNode(D.valuesRange)), k.appendChild(A), O.appendChild(k), j.appendChild(O);
}
}
return this._applySeriesColor(s, j, k, D.color), j;
}
_applySeriesColor(s, D, O, k) {
if (!k || typeof k != "string") return;
let A = k.trim().replace(/^#/, "").toUpperCase();
if (/^[0-9A-F]{8}$/.test(A)) A = A.slice(2);
else if (!/^[0-9A-F]{6}$/.test(A)) return;
let j = Util.createElement(s, "c:spPr");
if (O === "line" || O === "scatter") {
let D = Util.createElement(s, "a:ln"), O = Util.createElement(s, "a:solidFill");
O.appendChild(Util.createElement(s, "a:srgbClr", [["val", A]])), D.appendChild(O), j.appendChild(D);
} else if (O !== "pie" && O !== "doughnut") {
let D = Util.createElement(s, "a:solidFill");
D.appendChild(Util.createElement(s, "a:srgbClr", [["val", A]])), j.appendChild(D);
} else return;
D.appendChild(j);
}
_createLegendNode(s, D) {
let O = Util.createElement(s, "c:legend"), k = {
right: "r",
left: "l",
top: "t",
bottom: "b",
topRight: "tr"
}[D?.position || "right"] || "r";
return O.appendChild(Util.createElement(s, "c:legendPos", [["val", k]])), O.appendChild(Util.createElement(s, "c:layout")), O.appendChild(Util.createElement(s, "c:overlay", [["val", D?.overlay ? "1" : "0"]])), O;
}
_createTitleNode(s, D) {
let O = Util.createElement(s, "c:title"), k = Util.createElement(s, "c:tx"), A = Util.createElement(s, "c:rich");
A.appendChild(Util.createElement(s, "a:bodyPr")), A.appendChild(Util.createElement(s, "a:lstStyle"));
let j = Util.createElement(s, "a:p"), M = Util.createElement(s, "a:r"), N = Util.createElement(s, "a:rPr", [["lang", "en-US"]]);
M.appendChild(N);
let P = Util.createElement(s, "a:t");
return P.appendChild(s.createTextNode(D)), M.appendChild(P), j.appendChild(M), j.appendChild(Util.createElement(s, "a:endParaRPr", [["lang", "en-US"]])), A.appendChild(j), k.appendChild(A), O.appendChild(k), O.appendChild(Util.createElement(s, "c:layout")), O.appendChild(Util.createElement(s, "c:overlay", [["val", "0"]])), O;
}
_createCategoryAxis(s, D, O, k, A) {
let j = Util.createElement(s, "c:catAx");
j.appendChild(Util.createElement(s, "c:axId", [["val", String(D)]]));
let M = Util.createElement(s, "c:scaling");
return M.appendChild(Util.createElement(s, "c:orientation", [["val", "minMax"]])), j.appendChild(M), j.appendChild(Util.createElement(s, "c:delete", [["val", "0"]])), j.appendChild(Util.createElement(s, "c:axPos", [["val", "b"]])), j.appendChild(Util.createElement(s, "c:tickLblPos", [["val", "nextTo"]])), j.appendChild(Util.createElement(s, "c:crossAx", [["val", String(O)]])), j.appendChild(Util.createElement(s, "c:crosses", [["val", "autoZero"]])), A?.showGridLines && j.appendChild(Util.createElement(s, "c:majorGridlines")), k && j.appendChild(this._createTitleNode(s, k)), j;
}
_createValueAxis(s, D, O, k, A, j) {
let M = Util.createElement(s, "c:valAx");
M.appendChild(Util.createElement(s, "c:axId", [["val", String(D)]]));
let N = Util.createElement(s, "c:scaling");
return N.appendChild(Util.createElement(s, "c:orientation", [["val", "minMax"]])), typeof j?.minimum == "number" && N.appendChild(Util.createElement(s, "c:min", [["val", String(j.minimum)]])), typeof j?.maximum == "number" && N.appendChild(Util.createElement(s, "c:max", [["val", String(j.maximum)]])), M.appendChild(N), M.appendChild(Util.createElement(s, "c:delete", [["val", "0"]])), M.appendChild(Util.createElement(s, "c:axPos", [["val", k]])), M.appendChild(Util.createElement(s, "c:crossAx", [["val", String(O)]])), M.appendChild(Util.createElement(s, "c:crosses", [["val", "autoZero"]])), M.appendChild(Util.createElement(s, "c:crossBetween", [["val", "between"]])), j?.showGridLines && M.appendChild(Util.createElement(s, "c:majorGridlines")), A && M.appendChild(this._createTitleNode(s, A)), M;
}
_nextAxisIdBase() {
return (this.index || 1) * 1e3;
}
_resolveGrouping(s, D) {
return s === "pie" || s === "doughnut" ? "clustered" : s === "line" ? D === "stacked" ? "stacked" : D === "percent" ? "percentStacked" : "standard" : s === "bar" || s === "column" ? D === "stacked" ? "stacked" : D === "percent" ? "percentStacked" : "clustered" : "standard";
}
}, Picture = class extends Drawing {
id = uniqueId("Picture");
pictureId = Util.uniqueId("Picture");
fill = {};
mediaData = null;
description = "";
constructor() {
super(), this.id = uniqueId("Picture"), this.pictureId = Util.uniqueId("Picture");
}
setMedia(s) {
this.mediaData = s;
}
setDescription(s) {
this.description = s;
}
setFillType(s) {
this.fill.type = s;
}
setFillConfig(s) {
Object.assign(this.fill, s);
}
getMediaType() {
return "image";
}
getMediaData() {
return this.mediaData;
}
setRelationshipId(s) {
this.mediaData.rId = s;
}
toXML(s) {
let D = Util.createElement(s, "xdr:pic"), O = Util.createElement(s, "xdr:nvPicPr"), k = Util.createElement(s, "xdr:cNvPr", [
["id", this.pictureId],
["name", this.mediaData.fileName],
["descr", this.description || ""]
]);
O.appendChild(k);
let A = Util.createElement(s, "xdr:cNvPicPr");
A.appendChild(Util.createElement(s, "a:picLocks", [["noChangeAspect", "1"], ["noChangeArrowheads", "1"]])), O.appendChild(A), D.appendChild(O);
let j = Util.createElement(s, "xdr:blipFill");
j.appendChild(Util.createElement(s, "a:blip", [["xmlns:r", Util.schemas.relationships], ["r:embed", this.mediaData.rId]])), j.appendChild(Util.createElement(s, "a:srcRect"));
let M = Util.createElement(s, "a:stretch");
M.appendChild(Util.createElement(s, "a:fillRect")), j.appendChild(M), D.appendChild(j);
let N = Util.createElement(s, "xdr:spPr", [["bwMode", "auto"]]), P = Util.createElement(s, "a:xfrm");
N.appendChild(P);
let F = Util.createElement(s, "a:prstGeom", [["prst", "rect"]]);
return N.appendChild(F), D.appendChild(N), this.anchor.toXML(s, D);
}
};
const Paths = {};
var RelationshipManager = class {
relations = {};
lastId = 1;
constructor() {
uniqueId("rId");
}
importData(s) {
this.relations = s.relations, this.lastId = s.lastId;
}
exportData() {
return {
relations: this.relations,
lastId: this.lastId
};
}
addRelation(s, D) {
return this.relations[s.id] = {
id: uniqueId("rId"),
schema: Util.schemas[D],
object: s
}, this.relations[s.id].id;
}
getRelationshipId(s) {
return this.relations[s.id] ? this.relations[s.id].id : null;
}
toXML() {
let s = Util.createXmlDoc(Util.schemas.relationshipPackage, "Relationships"), D = s.documentElement;
for (let [O, k] of Object.entries(this.relations)) {
let A = Util.createElement(s, "Relationship", [
["Id", k.id],
["Type", k.schema],
["Target", k.object.target || Paths[O]]
]);
k.object.targetMode && A.setAttribute("TargetMode", k.object.targetMode), D.appendChild(A);
}
return s;
}
}, Drawings = class {
drawings = [];
relations = new RelationshipManager();
id = uniqueId("Drawings");
addDrawing(s) {
this.drawings.push(s);
}
getCount() {
return this.drawings.length;
}
toXML() {
let s = Util.createXmlDoc(Util.schemas.spreadsheetDrawing, "xdr:wsDr"), D = s.documentElement;
D.setAttribute("xmlns:a", Util.schemas.drawing), D.setAttribute("xmlns:r", Util.schemas.relationships), D.setAttribute("xmlns:xdr", Util.schemas.spreadsheetDrawing);
for (let O = 0, k = this.drawings.length; O < k; O++) {
let k = this.drawings[O];
if (k instanceof Picture) {
let O = this.relations.getRelationshipId(k.getMediaData());
O ||= this.relations.addRelation(k.getMediaData(), k.getMediaType()), k.setRelationshipId(O), D.appendChild(k.toXML(s));
} else if (k instanceof Chart) {
let O = this.relations.getRelationshipId(k);
O ||= this.relations.addRelation(k, k.getMediaType()), k.setRelationshipId(O), D.appendChild(k.toXML(s));
}
}
return s;
}
}, Pane = class {
state = null;
xSplit = null;
ySplit = null;
activePane = "bottomRight";
topLeftCell = null;
_freezePane;
freezePane(s, D, O) {
this._freezePane = {
xSplit: s,
ySplit: D,
cell: O
};
}
exportXML(s) {
let D = s.createElement("pane");
return this.state !== null && (D.setAttribute("xSplit", this._freezePane.xSplit), D.setAttribute("ySplit", this._freezePane.ySplit), D.setAttribute("topLeftCell", this._freezePane.cell), D.setAttribute("activePane", "bottomRight"), D.setAttribute("state", "frozen")), D;
}
}, Positioning = class {
static pixelsToEMUs(s) {
return Math.round(s * 914400 / 96);
}
}, SharedStrings = class {
strings = {};
stringArray = [];
id = uniqueId("SharedStrings");
addString(s) {
return this.strings[s] = this.stringArray.length, this.stringArray[this.stringArray.length] = s, this.strings[s];
}
exportData() {
return this.strings;
}
toXML() {
let s = Util.createXmlDoc(Util.schemas.spreadsheetml, "sst"), D = s.documentElement;
this.stringArray.reverse();
let O = this.stringArray.length;
D.setAttribute("count", O), D.setAttribute("uniqueCount", O);
let k = s.createElement("si"), A = s.createElement("t");
A.appendChild(s.createTextNode("--placeholder--")), k.appendChild(A);
let j = this.stringArray;
for (; O--;) {
let s = k.cloneNode(!0);
typeof j[O] == "string" && j[O].match(/\s+/) && s.firstChild.setAttribute("xml:space", "preserve"), s.firstChild.firstChild.nodeValue = j[O], D.appendChild(s);
}
return s;
}
}, SheetView = class {
pane;
showZeros = null;
defaultGridColor = null;
colorId = null;
rightToLeft = null;
showFormulas = null;
showGridLines = null;
showOutlineSymbols = null;
showRowColHeaders = null;
showRuler = null;
showWhiteSpace = null;
tabSelected = null;
topLeftCell = null;
viewType = null;
windowProtection = null;
zoomScale = null;
zoomScaleNormal = null;
zoomScalePageLayoutView = null;
zoomScaleSheetLayoutView = null;
constructor(s) {
this.pane = (s || {}).pane || new Pane();
}
freezePane(s, D, O) {
this.pane.state = "frozen", this.pane.xSplit = s, this.pane.ySplit = D, this.pane.topLeftCell = O;
}
exportXML(s) {
let D = s.createElement("sheetViews"), O = s.createElement("sheetView");
return Util.setAttributesOnDoc(O, {
workbookViewId: 0,
showZeros: {
v: this.showZeros,
type: Boolean
},
defaultGridColor: {
v: this.defaultGridColor,
type: Boolean
},
colorId: this.colorId,
rightToLeft: {
v: this.rightToLeft,
type: Boolean
},
showFormulas: {
v: this.showFormulas,
type: Boolean
},
showGridLines: {
v: this.showGridLines,
type: Boolean
},
showOutlineSymbols: {
v: this.showOutlineSymbols,
type: Boolean
},
showRowColHeaders: {
v: this.showRowColHeaders,
type: Boolean
},
showRuler: {
v: this.showRuler,
type: Boolean
},
showWhiteSpace: {
v: this.showWhiteSpace,
type: Boolean
},
tabSelected: {
v: this.tabSelected,
type: Boolean
},
viewType: this.viewType,
windowProtection: {
v: this.windowProtection,
type: Boolean
},
zoomScale: {
v: this.zoomScale,
type: Boolean
},
zoomScaleNormal: this.zoomScaleNormal,
zoomScalePageLayoutView: this.zoomScalePageLayoutView,
zoomScaleSheetLayoutView: this.zoomScaleSheetLayoutView
}), O.appendChild(this.pane.exportXML(s)), D.appendChild(O), D;
}
};
function pick(s, D) {
return D.reduce((D, O) => (s?.hasOwnProperty(O) && (D[O] = s[O]), D), {});
}
var StyleSheet = class {
id = uniqueId("StyleSheet");
cellStyles = [{
name: "Normal",
xfId: "0",
builtinId: "0"
}];
defaultTableStyle = !1;
differentialStyles = [{}];
masterCellFormats = [{
numFmtId: 0,
fontId: 0,
fillId: 0,
borderId: 0,
xfid: 0
}];
masterCellStyles = [{
numFmtId: 0,
fontId: 0,
fillId: 0,
borderId: 0
}];
fonts = [{}];
numberFormatters = [];
fills = [{}, {
type: "pattern",
patternType: "gray125",
fgColor: "FF333333",
bgColor: "FF333333"
}];
borders = [{
top: {},
left: {},
right: {},
bottom: {},
diagonal: {}
}];
tableStyles = [];
createSimpleFormatter(s) {
let D = { id: this.masterCellFormats.length };
switch (s) {
case "date":
D.numFmtId = 14;
break;
}
return this.masterCellFormats.push(D), D;
}
createFill(s) {
let D = this.fills.length, O = s;
return O.id = D, this.fills.push(O), O;
}
createNumberFormatter(s) {
let D = {
id: this.numberFormatters.length + 100,
formatCode: s
};
return this.numberFormatters.push(D), D;
}
createFormat(s) {
let D = { id: this.masterCellFormats.length };
if (s.protection && (D.protection = s.protection), s.font && isObject(s.font)) D.fontId = this.createFontStyle(s.font).id;
else if (s.font) {
if (Number.isNaN(Number.parseInt(s.font, 10))) throw Error("Passing a non-numeric font id is not supported");
D.fontId = s.font;
}
if (s.format && isString(s.format)) D.numFmtId = this.createNumberFormatter(s.format).id;
else if (s.format) {
if (Number.isNaN(Number.parseInt(s.format, 10))) throw Error("Invalid number formatter id");
D.numFmtId = s.format;
}
if (s.border && isObject(s.border)) D.borderId = this.createBorderFormatter(s.border).id;
else if (s.border) {
if (Number.isNaN(Number.parseInt(s.border, 10))) throw Error("Passing a non-numeric border id is not supported");
D.borderId = s.border;
}
if (s.fill && isObject(s.fill)) D.fillId = this.createFill(s.fill).id;
else if (s.fill) {
if (Number.isNaN(Number.parseInt(s.fill, 10))) throw Error("Passing a non-numeric fill id is not supported");
D.fillId = s.fill;
}
return s.alignment && isObject(s.alignment) && (D.alignment = pick(s.alignment, [
"horizontal",
"justifyLastLine",
"readingOrder",
"relativeIndent",
"shrinkToFit",
"textRotation",
"vertical",
"wrapText"
])), this.masterCellFormats.push(D), D;
}
createDifferentialStyle(s) {
let D = this.differentialStyles.length, O = { id: D };
return s.font && isObject(s.font) && (O.font = s.font), s.border && isObject(s.border) && (O.border = Object.assign({
top: {},
left: {},
right: {},
bottom: {},
diagonal: {}
}, s.border)), s.fill && isObject(s.fill) && (O.fill = s.fill), s.alignment && isObject(s.alignment) && (O.alignment = s.alignment), s.format && isString(s.format) && (O.numFmt = s.format), this.differentialStyles[D] = O, O;
}
createTableStyle(s) {
this.tableStyles.push(s);
}
createBorderFormatter(s) {
return s = {
top: {},
left: {},
right: {},
bottom: {},
diagonal: {},
id: this.borders.length,
...s
}, this.borders.push(s), s;
}
createFontStyle(s) {
let D = { id: this.fonts.length };
return s.bold && (D.bold = !0), s.italic && (D.italic = !0), s.superscript && (D.vertAlign = "superscript"), s.subscript && (D.vertAlign = "subscript"), s.underline && (typeof s.underline == "string" && [
"double",
"singleAccounting",
"doubleAccounting"
].includes(s.underline) ? D.underline = s.underline : D.underline = !0), s.strike && (D.strike = !0), s.outline && (D.outline = !0), s.shadow && (D.shadow = !0), s.size && (D.size = s.size), s.color && (D.color = s.color), s.fontName && (D.fontName = s.fontName), this.fonts.push(D), D;
}
exportBorders(s) {
let D = s.createElement("borders");
D.setAttribute("count", this.borders.length);
for (let O = 0, k = this.borders.length; O < k; O++) D.appendChild(this.exportBorder(s, this.borders[O]));
return D;
}
exportBorder(s, D) {
let O = s.createElement("border"), k = (O) => {
let k = s.createElement(O);
return D[O].style && k.setAttribute("style", D[O].style), D[O].color && k.appendChild(this.exportColor(s, D[O].color)), k;
};
return O.appendChild(k("left")), O.appendChild(k("right")), O.appendChild(k("top")), O.appendChild(k("bottom")), O.appendChild(k("diagonal")), O;
}
exportColor(s, D) {
let O = s.createElement("color");
return isString(D) ? (O.setAttribute("rgb", D), O) : (D.tint !== void 0 && O.setAttribute("tint", D.tint), D.auto !== void 0 && O.setAttribute("auto", String(!!D.auto)), D.theme !== void 0 && O.setAttribute("theme", D.theme), O);
}
exportMasterCellFormats(s) {
let D = Util.createElement(s, "cellXfs", [["count", this.masterCellFormats.length]]);
for (let O = 0, k = this.masterCellFormats.length; O < k; O++) {
let k = this.masterCellFormats[O];
D.appendChild(this.exportCellFormatElement(s, k));
}
return D;
}
exportMasterCellStyles(s) {
let D = Util.createElement(s, "cellStyleXfs", [["count", this.masterCellStyles.length]]);
for (let O = 0, k = this.masterCellStyles.length; O < k; O++) {
let k = this.masterCellStyles[O];
D.appendChild(this.exportCellFormatElement(s, k));
}
return D;
}
exportCellFormatElement(s, D) {
let O = s.createElement("xf"), k = [
"applyAlignment",
"applyBorder",
"applyFill",
"applyFont",
"applyNumberFormat",
"applyProtection",
"borderId",
"fillId",
"fontId",
"numFmtId",
"pivotButton",
"quotePrefix",
"xfId"
], A = Object.keys(D).filter((s) => k.indexOf(s) !== -1);
if (D.alignment) {
let k = D.alignment;
O.appendChild(this.exportAlignment(s, k));
}
D.protection && (O.appendChild(this.exportProtection(s, D.protection)), O.setAttribute("applyProtection", "1"));
let j = A.length;
for (; j--;) O.setAttribute(A[j], D[A[j]]);
return D.fillId && O.setAttribute("applyFill", "1"), D.fontId && O.setAttribute("applyFont", "1"), D.borderId && O.setAttribute("applyBorder", "1"), D.alignment && O.setAttribute("applyAlignment", "1"), D.numFmtId && O.setAttribute("applyNumberFormat", "1"), D.numFmtId !== void 0 && D.xfId === void 0 && O.setAttribute("xfId", "0"), O;
}
exportAlignment(s, D) {
let O = s.createElement("alignment"), k = Object.keys(D);
for (let s = 0, A = k.length; s < A; s++) O.setAttribute(k[s], D[k[s]]);
return O;
}
exportFonts(s) {
let D = s.createElement("fonts");
D.setAttribute("count", String(this.fonts.length));
for (let O = 0, k = this.fonts.length; O < k; O++) {
let k = this.fonts[O];
D.appendChild(this.exportFont(s, k));
}
return D;
}
exportFont(s, D) {
let O = s.createElement("font");
if (D.size) {
let k = s.createElement("sz");
k.setAttribute("val", D.size), O.appendChild(k);
}
if (D.fontName) {
let k = s.createElement("name");
k.setAttribute("val", D.fontName), O.appendChild(k);
}
if (D.bold && O.appendChild(s.createElement("b")), D.italic && O.appendChild(s.createElement("i")), D.vertAlign) {
let k = s.createElement("vertAlign");
k.setAttribute("val", D.vertAlign), O.appendChild(k);
}
if (D.underline) {
let k = s.createElement("u");
D.underline !== !0 && k.setAttribute("val", D.underline), O.appendChild(k);
}
return D.strike && O.appendChild(s.createElement("strike")), D.shadow && O.appendChild(s.createElement("shadow")), D.outline && O.appendChild(s.createElement("outline")), D.color && O.appendChild(this.exportColor(s, D.color)), O;
}
exportFills(s) {
let D = s.createElement("fills");
D.setAttribute("count", String(this.fills.length));
for (let O = 0, k = this.fills.length; O < k; O++) {
let k = this.fills[O];
D.appendChild(this.exportFill(s, k));
}
return D;
}
exportFill(s, D) {
let O, k = s.createElement("fill");
return D.type === "pattern" ? (O = this.exportPatternFill(s, D), k.appendChild(O)) : D.type === "gradient" && (O = this.exportGradientFill(s, D), k.appendChild(O)), k;
}
exportGradientFill(s, D) {
let O = s.createElement("gradientFill");
D.degree ? O.setAttribute("degree", D.degree) : D.left && (O.setAttribute("left", D.left), O.setAttribute("right", D.right), O.setAttribute("top", D.top), O.setAttribute("bottom", D.bottom));
let k = s.createElement("stop");
k.setAttribute("position", D.start.pureAt || 0);
let A = s.createElement("color");
typeof D.start == "string" || D.start.color ? A.setAttribute("rgb", D.start.color || D.start) : D.start.theme && A.setAttribute("theme", D.start.theme);
let j = s.createElement("stop"), M = s.createElement("color");
return j.setAttribute("position", D.end.pureAt || 1), typeof D.start == "string" || D.end.color ? M.setAttribute("rgb", D.end.color || D.end) : D.end.theme && M.setAttribute("theme", D.end.theme), k.appendChild(A), j.appendChild(M), O.appendChild(k), O.appendChild(j), O;
}
exportPatternFill(s, D) {
let O = Util.createElement(s, "patternFill", [["patternType", D.patternType]]);
D.bgColor ||= "FFFFFFFF", D.fgColor ||= "FFFFFFFF";
let k = s.createElement("bgColor");
isString(D.bgColor) ? k.setAttribute("rgb", D.bgColor) : D.bgColor.theme ? k.setAttribute("theme", D.bgColor.theme) : k.setAttribute("rgb", D.bgColor.rbg);
let A = s.createElement("fgColor");
return isString(D.fgColor) ? A.setAttribute("rgb", D.fgColor) : D.fgColor.theme ? A.setAttribute("theme", D.fgColor.theme) : A.setAttribute("rgb", D.fgColor.rbg), O.appendChild(A), O.appendChild(k), O;
}
exportNumberFormatters(s) {
let D = s.createElement("numFmts");
D.setAttribute("count", String(this.numberFormatters.length));
for (let O = 0, k = this.numberFormatters.length; O < k; O++) {
let k = this.numberFormatters[O];
D.appendChild(this.exportNumberFormatter(s, k));
}
return D;
}
exportNumberFormatter(s, D) {
let O = s.createElement("numFmt");
return O.setAttribute("numFmtId", D.id), O.setAttribute("formatCode", D.formatCode), O;
}
exportCellStyles(s) {
let D = s.createElement("cellStyles");
D.setAttribute("count", String(this.cellStyles.length));
for (let O = 0, k = this.cellStyles.length; O < k; O++) {
let k = this.cellStyles[O];
delete k.id;
let A = Util.createElement(s, "cellStyle");
D.appendChild(A);
let j = Object.keys(k), M = j.length;
for (; M--;) A.setAttribute(j[M], k[j[M]]);
}
return D;
}
exportDifferentialStyles(s) {
let D = s.createElement("dxfs");
D.setAttribute("count", String(this.differentialStyles.length));
for (let O = 0, k = this.differentialStyles.length; O < k; O++) {
let k = this.differentialStyles[O];
D.appendChild(this.exportDFX(s, k));
}
return D;
}
exportDFX(s, D) {
let O = s.createElement("dxf");
return D.font && O.appendChild(this.exportFont(s, D.font)), D.fill && O.appendChild(this.exportFill(s, D.fill)), D.border && O.appendChild(this.exportBorder(s, D.border)), D.numFmt && O.appendChild(this.exportNumberFormatter(s, D.numFmt)), D.alignment && O.appendChild(this.exportAlignment(s, D.alignment)), O;
}
exportTableStyles(s) {
let D = s.createElement("tableStyles");
D.setAttribute("count", String(this.tableStyles.length)), this.defaultTableStyle && D.setAttribute("defaultTableStyle", String(this.defaultTableStyle));
for (let O = 0, k = this.tableStyles.length; O < k; O++) D.appendChild(this.exportTableStyle(s, this.tableStyles[O]));
return D;
}
exportTableStyle(s, D) {
let O = s.createElement("tableStyle");
O.setAttribute("name", D.name), O.setAttribute("pivot", "0");
let k = 0;
return Object.entries(D).forEach(([D, A]) => {
if (D === "name") return;
k++;
let j = s.createElement("tableStyleElement");
j.setAttribute("type", D), j.setAttribute("dxfId", A), O.appendChild(j);
}), O.setAttribute("count", String(k)), O;
}
exportProtection(s, D) {
let O = s.createElement("protection");
for (let s in D) s in D && O.setAttribute(s, D[s]);
return O;
}
toXML() {
let s = Util.createXmlDoc(Util.schemas.spreadsheetml, "styleSheet"), D = s.documentElement;
return D.appendChild(this.exportNumberFormatters(s)), D.appendChild(this.exportFonts(s)), D.appendChild(this.exportFills(s)), D.appendChild(this.exportBorders(s)), D.appendChild(this.exportMasterCellStyles(s)), D.appendChild(this.exportMasterCellFormats(s)), D.appendChild(this.exportCellStyles(s)), D.appendChild(this.exportDifferentialStyles(s)), this.tableStyles.length && D.appendChild(this.exportTableStyles(s)), s;
}
}, Table = class {
name = "";
id = "";
tableId = "";
displayName = "";
dataCellStyle = null;
dataDfxId = null;
headerRowBorderDxfId = null;
headerRowCellStyle = null;
headerRowCount = 1;
headerRowDxfId = null;
insertRow = !1;
insertRowShift = !1;
ref = null;
tableBorderDxfId = null;
totalsRowBorderDxfId = null;
totalsRowCellStyle = null;
totalsRowCount = 0;
totalsRowDxfId = null;
tableColumns = [];
autoFilter = null;
sortState = null;
styleInfo = {};
constructor(s) {
this.initialize(s);
}
initialize(s) {
this.displayName = uniqueId("Table"), this.name = this.displayName, this.id = this.name, this.tableId = this.id.replace("Table", ""), s && Object.assign(this, s);
}
setReferenceRange(s, D) {
this.ref = [s, D];
}
setTableColumns(s) {
s.forEach((s) => {
this.addTableColumn(s);
});
}
addTableColumn(s) {
let D = isString(s) ? { name: s } : s;
if (!D.name) throw Error("Invalid argument for addTableColumn - minimum requirement is a name property");
this.tableColumns.push(D);
}
setSortState(s) {
this.sortState = s;
}
toXML() {
if (!this.ref) throw Error("Needs at least a reference range");
let s = Util.createXmlDoc(Util.schemas.spreadsheetml, "table"), D = s.documentElement;
D.setAttribute("id", this.tableId), D.setAttribute("name", this.name), D.setAttribute("displayName", this.displayName);
let O = this.ref[0], k = this.ref[1];
return D.setAttribute("ref", `${Util.positionToLetterRef(O[0], O[1])}:${Util.positionToLetterRef(k[0], k[1])}`), D.setAttribute("totalsRowCount", String(this.totalsRowCount)), D.setAttribute("headerRowCount", String(this.headerRowCount)), this.headerRowDxfId && D.setAttribute("headerRowDxfId", String(this.headerRowDxfId)), this.headerRowBorderDxfId && D.setAttribute("headerRowBorderDxfId", String(this.headerRowBorderDxfId)), this.autoFilter || this.addAutoFilter(this.ref[0], this.ref[1]), D.appendChild(this.exportAutoFilter(s)), D.appendChild(this.exportTableColumns(s)), D.appendChild(this.exportTableStyleInfo(s)), s;
}
exportTableColumns(s) {
let D = s.createElement("tableColumns");
D.setAttribute("count", String(this.tableColumns.length));
for (let O = 0, k = this.tableColumns.length; O < k; O++) {
let k = this.tableColumns[O], A = s.createElement("tableColumn");
A.setAttribute("id", String(O + 1)), A.setAttribute("name", k.name), k.totalsRowFunction && A.setAttribute("totalsRowFunction", k.totalsRowFunction), k.totalsRowLabel && A.setAttribute("totalsRowLabel", k.totalsRowLabel), D.appendChild(A);
}
return D;
}
exportAutoFilter(s) {
let D = s.createElement("autoFilter");
if (this.autoFilter) {
let s = this.autoFilter[0], O = this.autoFilter[1];
D.setAttribute("ref", `${Util.positionToLetterRef(s[0], s[1])}:${Util.positionToLetterRef(O[0], O[1] - this.totalsRowCount)}`);
}
return D;
}
exportTableStyleInfo(s) {
let D = this.styleInfo, O = s.createElement("tableStyleInfo");
return O.setAttribute("name", D.themeStyle ?? ""), O.setAttribute("showFirstColumn", D.showFirstColumn ? "1" : "0"), O.setAttribute("showLastColumn", D.showLastColumn ? "1" : "0"), O.setAttribute("showColumnStripes", D.showColumnStripes ? "1" : "0"), O.setAttribute("showRowStripes", D.showRowStripes ? "1" : "0"), O;
}
addAutoFilter(s, D) {
this.autoFilter = [s, D];
}
}, Worksheet = class {
name = "";
id = uniqueId("Worksheet");
_timezoneOffset;
relations = null;
columnFormats = [];
data = [];
mergedCells = [];
columns = [];
sheetProtection = !1;
_headers = [];
_footers = [];
_tables = [];
_drawings = [];
_orientation;
_margin;
_rowInstructions = {};
_freezePane = {};
sharedStrings = null;
hyperlinks = [];
sheetView;
showZeros = null;
constructor(s) {
this._timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset() * 60 * 1e3, this.sheetView = s.sheetView || new SheetView(), this.initialize(s);
}
initialize(s) {
s ||= {}, this.name = s.name, this.id = uniqueId("Worksheet"), this._timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset() * 60 * 1e3, s.columns && this.setColumns(s.columns), this.relations = new RelationshipManager();
}
exportData() {
return {
relations: this.relations?.exportData(),
columnFormats: this.columnFormats,
data: this.data,
columns: this.columns,
mergedCells: this.mergedCells,
_headers: this._headers,
_footers: this._footers,
_tables: this._tables,
_rowInstructions: this._rowInstructions,
_freezePane: this._freezePane,
name: this.name,
id: this.id
};
}
importData(s) {
this.relations?.importData(s.relations), delete s.relations, Object.assign(this, s);
}
setSharedStringCollection(s) {
this.sharedStrings = s;
}
addTable(s) {
this._tables.push(s), this.relations?.addRelation(s, "table");
}
addDrawings(s) {
this._drawings.push(s), this.relations?.addRelation(s, "drawingRelationship");
}
setRowInstructions(s, D) {
this._rowInstructions[s] = D;
}
setHeader(s) {
if (!Array.isArray(s)) throw Error("Invalid argument type - setHeader expects an array of three instructions");
this._headers = s;
}
setFooter(s) {
if (!Array.isArray(s)) throw Error("Invalid argument type - setFooter expects an array of three instructions");
this._footers = s;
}
compilePageDetailPackage(s) {
return s ||= "", [
"&L",
this.compilePageDetailPiece(s[0] || ""),
"&C",
this.compilePageDetailPiece(s[1] || ""),
"&R",
this.compilePageDetailPiece(s[2] || "")
].join("");
}
compilePageDetailPiece(s) {
if (isString(s)) return `&"-,Regular"${s}`;
if (isObject(s) && !Array.isArray(s)) {
let D = "";
if (s.font || s.bold) {
let O = s.bold ? "Bold" : "Regular";
D += `&"${s.font || "-"}`, D += `,${O}"`;
} else D += "&\"-,Regular\"";
return s.underline && (D += "&U"), s.fontSize && (D += `&${s.fontSize}`), D += s.text, D;
}
if (Array.isArray(s)) return s.reduce((s, D) => s.concat(this.compilePageDetailPiece(D)), "");
}
exportHeader(s) {
let D = s.createElement("oddHeader");
return D.appendChild(s.createTextNode(this.compilePageDetailPackage(this._headers))), D;
}
exportFooter(s) {
let D = s.createElement("oddFooter");
return D.appendChild(s.createTextNode(this.compilePageDetailPackage(this._footers))), D;
}
_buildCache(s) {
let D = s.createElement("c"), O = s.createElement("v");
O.appendChild(s.createTextNode("--temp--")), D.appendChild(O);
let k = s.createElement("c"), A = s.createElement("f");
A.appendChild(s.createTextNode("--temp--")), k.appendChild(A);
let j = s.createElement("c");
j.setAttribute("t", "s");
let M = s.createElement("v");
return M.appendChild(s.createTextNode("--temp--")), j.appendChild(M), {
number: D,
date: D,
string: j,
formula: k
};
}
collectSharedStrings() {
let s = this.data, D = 0, O = {};
for (let k = 0, A = s.length; k < A; k++) {
let A = s[k], j = A.length;
D = j > D ? j : D;
for (let s = 0; s < j; s++) {
let D = A[s], k = D?.metadata || {};
D && typeof D == "object" && (D = D.value), k.type || typeof D == "number" && (k.type = "number"), (k.type === "text" || !k.type) && O[D] === void 0 && (O[D] = !0);
}
}
return Object.keys(O);
}
toXML() {
let s = this.data, D = this.columns || [], O = Util.createXmlDoc(Util.schemas.spreadsheetml, "worksheet"), k = O.documentElement, A, j, M;
k.setAttribute("xmlns:r", Util.schemas.relationships), k.setAttribute("xmlns:mc", Util.schemas.markupCompat);
let N = 0, P = Util.createElement(O, "sheetData"), F = this._buildCache(O);
for (M = 0, j = s.length; M < j; M++) {
let k = s[M], A = k.length;
N = A > N ? A : N;
let j = O.createElement("row");
for (let s = 0; s < A; s++) {
D[s] = D[s] || {};
let O = k[s], A, N = O?.metadata || {};
switch (O && typeof O == "object" && (O = O.value), N.type || typeof O == "number" && (N.type = "number"), N.type) {
case "number":
A = F.number.cloneNode(!0), A.firstChild.firstChild.nodeValue = O;
break;
case "date":
A = F.date.cloneNode(!0), O instanceof Date && (O = O.getTime()), A.firstChild.firstChild.nodeValue = 25569 + (O - this._timezoneOffset) / (3600 * 24 * 1e3);
break;
case "formula":
A = F.formula.cloneNode(!0), A.firstChild.firstChild.nodeValue = O;
break;
case "text":
default: {
let s;
s = this.sharedStrings?.strings[O] === void 0 ? this.sharedStrings?.addString(O) : this.sharedStrings.strings[O], A = F.string.cloneNode(!0), A.firstChild.firstChild.nodeValue = s;
break;
}
}
N.style ? A.setAttribute("s", N.style) : this._rowInstructions[M]?.style !== void 0 && A.setAttribute("s", this._rowInstructions[M].style), A.setAttribute("r", Util.positionToLetterRef(s + 1, String(M + 1))), j.appendChild(A);
}
if (j.setAttribute("r", M + 1), this._rowInstructions[M]) {
let s = this._rowInstructions[M];
s.height !== void 0 && (j.setAttribute("customHeight", "1"), j.setAttribute("ht", s.height)), s.style !== void 0 && (j.setAttribute("customFormat", "1"), j.setAttribute("s", s.style));
}
P.appendChild(j);
}
if (N === 0 ? k.appendChild(Util.createElement(O, "dimension", [["ref", Util.positionToLetterRef(1, 1)]])) : k.appendChild(Util.createElement(O, "dimension", [["ref", `${Util.positionToLetterRef(1, 1)}:${Util.positionToLetterRef(N, String(s.length))}`]])), k.appendChild(this.sheetView.exportXML(O)), this.columns.length && k.appendChild(this.exportColumns(O)), k.appendChild(P), this.sheetProtection && k.appendChild(this.sheetProtection.exportXML(O)), this.hyperlinks.length > 0) {
let s = O.createElement("hyperlinks"), D = this.hyperlinks;
for (A = 0, j = D.length; A < j; A++) {
let k = O.createElement("hyperlink"), j = D[A];
k.setAttribute("ref", String(j.cel