@sheetxl/sdk
Version:
SDK - A high-performance, embeddable spreadsheet engine.
22,967 lines • 1.07 MB
JavaScript
import { ScalarType as q, IRange as O, FormulaError as Ee, Observable as Fm } from "@sheetxl/primitives";
import { CommonUtils as F, UndoManager as km, ChainedError as Om, TypesUtils as Hi, RangeOrientation as xe, CoordUtils as D, Direction as He, OutOfBoundsError as ze, NullNotAllowedError as Kt, RangeOrientations as Br, NotImplementedError as kd, TypedObject as $e, AnchorLocation as Nn, JSONStableStringify as ta, BufferUtils as Ro, ImageUtils as js, MimeType as Od, PartialError as Dm, TypedError as mc, CommonMessages as Lm } from "@sheetxl/utils";
/**
* @license @sheetxl/sdk - SDK - A high-performance, embeddable spreadsheet engine. - v0.6.4
*
* (C) 2025-present SheetXL Inc. & Michael T. Ford
* License: The license can be found at https://www.sheetxl.com/license.
*/
const fc = (a, e) => {
const t = /* @__PURE__ */ new Map();
return a.forEach((n, r) => {
e.get(r) !== n && t.set(r, n);
}), t;
};
let pc = !1;
class _c {
constructor(e) {
this._record = e;
}
getId() {
return this._record.id;
}
getDescription() {
return this._record.description;
}
getMeta() {
return Object.freeze(this._record.meta);
}
getAuthor() {
return this._record.author;
}
getTimestamp() {
return this._record.timestamp;
}
getOperation() {
return this._record.operation;
}
}
class Xt {
constructor(e) {
this._listeners = /* @__PURE__ */ new Set(), this._listenersState = /* @__PURE__ */ new Map(), this._commits = /* @__PURE__ */ new Map(), this._locked = !1, this._current = null, this._pending = null, this._isSync = e?.sync ?? pc, this._isTransient = e?.transient ?? !1, this._author = e?.author;
const t = { id: "0", description: "initial", meta: {}, author: this._author, timestamp: Date.now(), states: /* @__PURE__ */ new Map(), version: 0, previousId: null }, n = { record: t, commit: new _c(t) };
this._current = n, this._cacheModel = null, this._cacheState = null, this._states = t.states, this._transactionStack = [], this._transactionOpen = !1;
const r = /* @__PURE__ */ new Map();
r.set(t.id, n), this._commits = r;
}
static {
this.setDefaultSync = (e) => {
pc = e;
};
}
getLog(e, t = 100) {
const n = [];
let r = e;
do {
const o = this._commits.get(r);
if (!o) throw new Error(`Invalid commit id: '${r}'`);
if (n.push(o.commit), r = o.record.previousId, !r) return n;
} while (n.length < t);
}
getCommitCount() {
return this._commits.size;
}
isOpenTransaction() {
return this._transactionStack.length > 0 || this._transactionOpen;
}
getPendingView() {
const e = this._transactionStack;
return e.length > 0 ? e[0].getView() : null;
}
getState(e) {
const t = this._transactionStack;
if (t.length === 0) {
if (this._cacheModel === e) return this._cacheState;
const n = this._states.get(e);
return this._cacheModel = e, this._cacheState = n, n;
}
return t[t.length - 1].getState(e);
}
getCurrentCommit() {
return this._pending?.commit ?? this._current.commit;
}
restore(e, t) {
const n = this._getCommitContainer(e, t);
if (this._current.commit.getId() === n.commit.getId()) return n.commit;
let r;
t?.viewId && t?.viewId !== "custom" || (r = n.record.viewAfter);
const o = fc(n.record.states, this._current.record.states);
this._notifyStates("onBeforeCommitStart", this._current, o, r, !0, !1), this._current = n, this._states = this._current.record.states, this._cacheModel = null, this._cacheState = null, this._notifyStates("onAfterStateChange", n, o, r, !1, !0, !0), this._notify("onCommitChange", n.commit, !0), this._transactionOpen = !0;
try {
this._notifyStates("onRestoreOrRevert", n, n.record.states, r, !1, !0);
} finally {
this._transactionOpen = !1;
}
return n.commit;
}
revert(e, t) {
const n = this._getCommitContainer(e, t), r = this._commits.get(n.record.previousId);
if (!r) throw new Error(`Invalid commit id: '${n.record.previousId}'`);
let o;
t?.viewId && t?.viewId !== " custom" || (o = n.record.viewBefore ?? n.record.viewAfter);
const s = fc(r.record.states, this._current.record.states);
this._notifyStates("onBeforeCommitStart", this._current, s, o, !0, !1), this._current = r, this._states = this._current.record.states, this._cacheModel = null, this._cacheState = null, this._notifyStates("onAfterStateChange", r, s, o, !0, !1, !0), this._notify("onCommitChange", r.commit, !0), this._transactionOpen = !0;
try {
this._notifyStates("onRestoreOrRevert", r, r.record.states, o, !0, !0);
} finally {
this._transactionOpen = !1;
}
return r.commit;
}
_getCommitContainer(e, t) {
const n = this._commits.get(e);
if (!n) throw new Error(`Invalid commit id: '${e}'`);
if (this._isTransient) throw new Error("Cannot revert transient store");
if (t?.force && this._transactionStack.length > 0 && this._transactionStack[0].rollback(), this._transactionStack.length !== 0) throw new Error("Open transactions.");
return n;
}
_pruneForwards(e) {
}
beginCommit(e, t) {
const n = this._transactionStack, r = n.length;
if (this._locked) throw console.warn("TransactionStore locked", n), new Error(`TransactionStore is locked by '${n[r - 1].getDescription()}`);
const o = e?.preventFurtherTransactions, s = this, i = (c, h, u) => {
const d = s._transactionStack;
r !== d.length - 1 && console.warn("Transaction stack out of sync", r, d.length, d), o && (this._locked = !1), d.pop(), t?.(c, h, u), d.length === 0 && (s._pending = null);
};
let l;
if (n.length === 0) {
const c = this._current.record, h = { states: /* @__PURE__ */ new Map(), id: F.uuidV4(), description: typeof e == "string" ? e : e?.description ?? null, meta: {}, timestamp: Date.now(), author: null, version: c.version + 1, previousId: c.id, viewBefore: null, viewAfter: {}, operation: e?.operation }, u = { record: h, commit: new _c(h) };
this._pending = u, this._notify("onCommitStart", u.commit), l = new Bm(this, u, c?.states, e, i);
} else
l = n[n.length - 1].beginTransaction(e, i);
return o && (this._locked = !0), this._transactionStack.push(l), l;
}
doBatch(e, t, n) {
let r;
const o = this.beginCommit(t, n), s = this.getCurrentCommit();
try {
r = e?.(s);
const i = () => {
o.commit(t);
};
if (r && typeof r.then == "function") return new Promise((l, c) => {
r.then((h) => {
try {
i(), l(h);
} catch (u) {
c(u);
}
}).catch((h) => {
o.rollback(), c(h);
});
});
i();
} catch (i) {
throw o.rollback(), i;
}
return r;
}
remove(e) {
return !!e;
}
addListener(e) {
const t = this._listeners;
return t.add(e), () => {
t.delete(e);
};
}
addStateListener(e, t) {
if (!e) throw new Error("Model is required");
if (!t) throw new Error("Listener is required");
let n = this._listenersState.get(e);
return n || (n = /* @__PURE__ */ new Set(), this._listenersState.set(e, n)), n.add(t), () => {
n.delete(t), n.size === 0 && this._listenersState.delete(e);
};
}
dispatchEvents(e, t = !1) {
!t || this._isSync ? e() : setTimeout(e, 0);
}
_commitRecord(e, t, n) {
let r = e.record, o = e.commit;
if (!this._isTransient) {
if (n) {
const s = this._commits.get(r.previousId);
if (s) {
r.previousId = s.record.id;
const i = s.record, l = i.states;
l && r.states.forEach((c, h) => {
l.set(h, c);
}), i.viewAfter = { ...i.viewAfter, ...r.viewAfter }, i.meta = { ...i.meta, ...r.meta }, i.timestamp = r.timestamp, r = i, o = s.commit, e = { record: r, commit: o };
}
}
this._commits.set(r.id, e);
}
this._current = e, this._states = this._current.record.states, this._cacheModel = null, this._cacheState = null, n || this._notify("onCommitChange", o), this._notifyStates("onAfterStateChange", e, t, e.record.viewAfter, !1, !1, !0), n || this._notify("onCommitEnd", o, !0);
}
_notifyStates(e, t, n, r, o = !1, s = !1, i = !1) {
const l = t.commit, c = this._listenersState;
n.forEach((h, u) => {
const d = c.get(u);
d && this.dispatchEvents(() => {
d.forEach((g) => {
g[e]?.(h, r, l, o, s);
});
}, i);
});
}
_notify(e, t, n = !1) {
this.dispatchEvents(() => {
this._listeners.forEach((r) => {
r[e]?.(t);
});
}, n);
}
}
class Dd {
constructor(e, t) {
this._children = /* @__PURE__ */ new Set(), this._depth = 0, this._container = null, this._closed = !1, this._container = e, t = typeof t == "string" ? { description: t } : t, this._description = t?.description ?? "", t?.viewBefore !== void 0 && (e.record.viewBefore = e.record.viewBefore && t.viewBefore ? { ...e.record.viewBefore, ...t.viewBefore } : t.viewBefore), t?.viewAfter !== void 0 && (e.record.viewAfter = e.record.viewAfter && t.viewAfter ? { ...e.record.viewAfter, ...t.viewAfter } : t.viewAfter);
}
getView() {
return this._container.record.viewAfter ?? this._container.record.viewBefore;
}
getDepth() {
return this._depth;
}
getDescription() {
return this._description;
}
getStates() {
return this._states;
}
beginTransaction(e, t) {
this._ensureOpen();
const n = new zm(this, this._container, typeof e == "string" ? { description: e } : e, t);
return this._children || this._children, this._children.add(n), n;
}
updateState(e, t) {
this._ensureOpen();
const n = this.getState(e), r = typeof t == "function" ? t(n) : t === void 0 ? n : { ...n, ...t };
if (r) {
let o = this._states;
o || (o = /* @__PURE__ */ new Map(), this._states = o), o.set(e, r);
}
return r;
}
commit(e) {
if (this._ensureOpen(), typeof e == "string" && (e = { description: e }), e) {
if (e.description && (this._description = e.description), e.meta && (this._meta = F.mergeContentful(e.meta, this._meta)), e.viewAfter !== void 0) {
const t = this._container.record;
let n = e.viewAfter;
if (n === null) t.viewAfter = null;
else {
const r = t.viewAfter;
typeof n == "function" && (n = n(r)), t.viewAfter = { ...r, ...n };
}
}
if (e.viewBefore !== void 0) {
const t = this._container.record;
let n = e.viewBefore;
if (n === null) t.viewAfter = null;
else {
const r = t.viewBefore;
typeof n == "function" && (n = n(r)), t.viewBefore = { ...r, ...n };
}
}
}
return this._children && this._children.forEach((t) => {
t.commit(e);
}), this;
}
isClose() {
return this._closed;
}
_ensureOpen() {
if (this._closed) throw this._descriptions && console.warn(`stack: [${this._descriptions.join(",")}]`), new Error("Transaction already closed");
}
_removeChild(e) {
this._children.delete(e), this._mergeStates(e._states);
}
_mergeStates(e) {
if (!e || e.size === 0) return;
let t = this._states;
return t ? (e.forEach((n, r) => {
const o = this.updateState(r, n);
t.set(r, o);
}), t) : (this._states = e, e);
}
}
class Bm extends Dd {
constructor(e, t, n, r, o) {
super(t, r), this._store = e, this._prevStates = n, this._onClose = o, this._states = /* @__PURE__ */ new Map(), this._meta = t.record.meta;
}
getId() {
return this._container.commit.getId();
}
getParent() {
return this;
}
commit(e) {
const t = this._states, n = this._container, r = n.record.viewAfter;
this._store._notifyStates("onBeforeCommitStart", n, t, r, !1, !1), super.commit(e), this._store._notifyStates("onBeforeCommitEnd", n, t, r, !1, !1);
const o = new Map(this._prevStates);
return this._states.forEach((s, i) => {
s === null ? o.delete(i) : o.set(i, s);
}), this._states = o, this._description && (n.record.description = this._description), this._meta && (n.record.meta = this._meta), n.record.states = o, this._closed = !0, this._onClose?.(this, !1, e), this._store._commitRecord(n, t, e?.forceAmend ?? !1), this;
}
rollback() {
return this._ensureOpen(), this._children && this._children.forEach((e) => {
e.rollback();
}), this._closed = !0, this._onClose?.(this, !0, null), this;
}
updateState(e, t) {
const n = super.updateState(e, t);
return this._states.set(e, n), n;
}
getState(e) {
let t = this._states.get(e);
return t || (t = this._prevStates.get(e)), t;
}
_mergeStates(e) {
return !e || e.size === 0 ? /* @__PURE__ */ new Map() : super._mergeStates(e);
}
}
class zm extends Dd {
constructor(e, t, n, r) {
if (super(t, n), !e) throw new Error("Parent transaction required");
this._parent = e, this._depth = this._parent.getDepth() + 1, this._onClose = r;
}
getId() {
return this._parent.getId();
}
getParent() {
return this._parent;
}
getState(e) {
const t = this._states ? this._states.get(e) : void 0;
return t !== void 0 ? t : this._parent.getState(e);
}
commit(e) {
return super.commit(e), this._parent._removeChild(this), this._closed = !0, this._onClose?.(this, !1, e), this._parent ?? this;
}
rollback() {
return this._ensureOpen(), this._children && this._children.forEach((e) => {
e.rollback();
}), this._parent._removeChild(this), this._closed = !0, this._onClose?.(this, !0, null), this._parent ?? this;
}
}
class Zw extends km {
constructor(e, t = 50) {
super(t), this._transactions = e;
const n = this;
e?.addListener({ onCommitEnd: (r) => {
r.getDescription() && n.addUndoOperation({ description: r.getDescription(), undo: () => (e.revert(r.getId()), () => {
e.restore(r.getId());
}) });
} });
}
clear() {
super.clear();
}
close() {
this._removeLister();
}
}
const Ld = () => {
try {
return "0.6.4";
} catch {
return "";
}
}, pn = Object.freeze(Object.defineProperty({ __proto__: null, getBuildDate: () => {
try {
return "Thu Aug 21 2025";
} catch {
return "";
}
}, getBuildVersion: Ld }, Symbol.toStringTag, { value: "Module" })), Pm = `
https://www.sheetxl.com ${Ld()}`, na = "#1976d2", Hm = () => typeof window == "object" ? window.location.hostname : F.getOS(), yr = Object.freeze(Object.defineProperty({ __proto__: null, generateNodeId: async () => "0", getKey: async () => {
throw new Error("getKey is not implemented in browser environment");
}, printBanner: async (a) => {
const e = a ? console.log : F.consoleWithNoSource, t = `%c
███████╗██╗ ██╗███████╗███████╗████████╗ ██╗ ██╗██╗
██╔════╝██║ ██║██╔════╝██╔════╝╚══██╔══╝ ╚██╗██╔╝██║
███████╗███████║█████╗ █████╗ ██║ ╚███╔╝ ██║
╚════██║██╔══██║██╔══╝ ██╔══╝ ██║ ██╔██╗ ██║
███████║██║ ██║███████╗███████╗ ██║ ██╔╝ ██╗███████╗
╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝${Pm}
`;
return await e(`${t}`, `font-family:monospace;color:${na};font-size:12px;`), Promise.resolve();
}, printDetails: async (a, e = !1, t = !1, n = !1) => {
let r;
const o = console.log, s = [`color:${na};font-size:12px`];
if (a.isEval() ? (s.push(`font-family:monospace;color:${na};font-size:12px;`), r = "%cEvaluation Only", s[0] = "color:#E12929;font-size:12px", r += `%c
Please visit https://my.sheetxl.com to register.`) : (r = `%cLicensee: ${a.licensee() ?? "Invalid License"}
`, r += `Expires: ${a.expiration()?.toLocaleDateString() ?? "Never"}`, a.domains() && a.domains().length > 0 && (r += `
Domains: ${a.domains().join(", ")}`), a.cpuCount() > 0 && (r += `
Cpus: ${a.cpuCount()}`)), !n && a.exceptions().length > 0) {
s.push("color:red;font-size:12px"), r += `
Exceptions:
%c`;
for (let i = 0; i < a.exceptions().length; i++) r += ` ${a.exceptions()[i]}`;
}
return t && (s.push("color:#FFA726;font-size:12px"), r += "%c", r += `
Location: '${Hm()}'`, r += `
KeyFrom: '${a.keyFrom()}'`), await o(`${r}`, ...s), Promise.resolve();
}, setKey: async (a, e = !1) => {
throw new Error("setKey is not implemented in browser environment");
} }, Symbol.toStringTag, { value: "Module" })), Wm = (a, e, t = 126) => ((n, r, o = 126) => {
let s = n.split("");
for (let i = 0; i < s.length; i++) s[i].charCodeAt(0) <= o && (s[i] = String.fromCharCode((s[i].charCodeAt(0) + r) % o));
return s.join("");
})(a, t - e), jm = (a) => typeof window == "object" ? window.atob(a) : Buffer.from(a, "base64").toString("ascii");
function Ct(a, e, t, n, r) {
return Fe(e - 508, n);
}
(function() {
const e = ")&5E", t = "e$L5", r = "*rPU", s = "4uRu";
function l(g, m, f, _, p) {
return Fe(f - 622, p);
}
function c(g, m, f, _, p) {
return Fe(m - -260, p);
}
function h(g, m, f, _, p) {
return Fe(m - -223, g);
}
function u(g, m, f, _, p) {
return Fe(m - -437, f);
}
const d = Jl();
for (; ; ) try {
if (-parseInt(h("70A6", 426)) / 1 + parseInt(c(0, 337, 0, 0, "*rPU")) / 2 + -parseInt(c(0, 311, 0, 0, e)) / 3 * (-parseInt(u(0, 133, "wj3Q")) / 4) + parseInt(h(t, 409)) / 5 + -parseInt(c(0, 278, 0, 0, "b0Sp")) / 6 + -parseInt(u(0, 209, "bLtP")) / 7 + -parseInt(h(r, 267)) / 8 * (-parseInt(l(0, 0, 1211, 0, s)) / 9) === 430105) break;
d.push(d.shift());
} catch {
d.push(d.shift());
}
})();
const Si = () => {
const a = "]Wfy", e = "Nns7";
function n(l, c, h, u, d) {
return Fe(l - 727, d);
}
return typeof window === n(1282, 0, 0, 0, "*rPU") ? window[r = 819, o = "DXBj", Fe(r - 190, o)][n(1223, 0, 0, 0, a)] : F[s = e, i = 1530, Fe(i - 905, s)]();
var r, o, s, i;
};
function Ut(a, e, t, n, r) {
return Fe(t - 541, n);
}
const ml = () => {
const a = ")&5E", e = "d3gQ";
function n(r, o, s, i, l) {
return Fe(s - -450, o);
}
return Si()[n(0, a, 155)](n(0, "wAgp", 215)) || Si() === n(0, e, 161);
};
function ln(a, e, t, n, r) {
return Fe(a - 591, n);
}
const Sc = (a) => {
const e = "DEAz", r = "Gda1", l = "!qWp", g = "($u9";
let f = F[y("[c$g", 1481, 1488, 1471, 1421)];
if (ml() || F[y(e, 1270, 1317, 1260, 1326)]()) {
const C = pn[y(r, 1464, 1473, 1371, 1387)](), w = new Date(C), b = /* @__PURE__ */ new Date();
Math[S(97, 132, 182, "EKeb", 150)]((b[_ = l, p = -164, Fe(p - -713, _)]() - w[y("!qWp", 1399, 1374, 1393, 1394)]()) / 864e5) >= 120 && (f = [S(41, -8, -18, "[c$g", 55)]);
} else f = [];
var _, p;
function S(C, w, b, x, I) {
return Fe(I - -452, x);
}
function E(C, w, b, x, I) {
return Fe(b - -335, C);
}
function y(C, w, b, x, I) {
return Fe(I - 845, C);
}
return { licensee: () => y("$LH]", 0, 0, 0, 1411), expiration: () => null, domains: () => [Si()], developerCount: () => 1, cpuCount: () => 0, type: () => E("*rPU", 0, 226), isEval: () => !0, exceptions: () => f, isValidFor: () => f[E("Nns7", 0, 192)] === 0, isValid: () => !1, features: () => Object[y("CV8D", 0, 0, 0, 1508)]({}), keyFrom: () => a, getBuildVersion: pn[S(0, 0, 0, "H#1x", 208)], getBuildDate: pn[y(g, 0, 0, 0, 1413)] };
};
function Yn(a, e, t, n, r) {
return Fe(e - 154, r);
}
const Le = { promise: null, details: null, bannerPrinted: !1, detailsPrinted: !1, licenseKey: null, keyFrom: null };
let ra = !1, wc = !1;
const yc = Ct(0, 1155, 0, "$BFF")[Ct(0, 1062, 0, "DEAz")]("")[Ut(0, 0, 1116, "b0Sp")]((a, e) => e + a, "");
function Jl() {
const a = ["WOHXdJSzW68", "bCkTicBdTCog", "W7JcGHNcLCk9W6hcKCkg", "hCoBtbVcO8oEWQuE", "W4NcI8kLW7ZcMmo5whpcL8oi", "h0BdIrxdKMdcSIBcL8oRhMBcHG4", "xmkjamk5agJcVG", "WQlcQHxcRSo0aCkdtCo/WPbKW7FdKH1a", "WOalW43cGSkQWQVcHmk6W517", "B8kEdCkGee/cVdLYACokySowWQKKESkmwSkvndG+wSoXcG", "gmkZW5jsEItcJdFdRW", "rfFdQ0NcHYu", "CCokW6i8WOzocWyt", "W7ZdT8oTW78Hj8k7", "WQ/cPSoDp2DjvaLgWRJdGmkK", "WRBdTmojW7hdNmkuB1RdVh0nWQu", "E8kPW50tW4L8W5u", "gmoiW6/dQcZdKx3cImk4", "zmkhtmkPhv7cOsj8C8kdFCoD", "gYhdPL1ThdhdGSkBWQNdReC", "iCkHW4PyWPtcOYNcQWXyfG", "jSkRW5bFWPtcQaNcJXfdhCodWQ1x", "vmkTW5msW4LRW5hdNSkM", "e8k/W4v5EZpcJdxdRSkn", "cCkMbJxdPmoEWP/dKCoEpG", "gCkZW5j/FwJdJLdcPa", "W5xcG2JcGLZdMN3dP8oJDZRdQSkTeGzO", "d8kJW5v0", "tf7dIIRcKuqQW6lcRmkrqSkwW77dQG", "vMBcMmo1pmow", "W7BcGMHWbmo+", "W7ZdU8ozeHCeW5G", "hSocFSotW5pcJWtdTCkUbcJdPq", "umkLx8oSqq", "sNhcMCo/iContq", "j8ofwGhcMSodWPmxD8oheMG", "Dmosy2KsEYLX", "WQ9uvt/cISkIEG", "W7VdTmkytcSqErTAWQ7dRCkB", "mSk8W4TtWPtcTX8", "tCkKz8o9W4/dHSoBWPTCp8o/W4NdJW", "WRhdO8kAifBcRa4", "nCoMW75ynqbDw8kBc14fdG", "WOajW4ZcG8oRW5pcP8kxW4n8hSoT", "W59CWONdSSkSWO3cGmkDW7n/c8on", "pmodzSoXvSoB", "ymofWPLpb8oJbXRcJCo4", "WPe3WP8WW4TKwa", "WQ8FW45rumoL", "W405WO9FWPlcQtddNhBdPW", "W4RdUmo9gHuz", "WRuId1aSWOZcTW", "WRj5hZChW6/cKmkpWRZdJW", "W63dL3KzcvpcVs/dGd4Hw8kl", "WRbKeJCfW7RcJCkfWPZdKYuOCCky", "WPXZwCk3WRtcRCofWOVcR1ZcPmoq", "WPi1WPW0W5y", "zmk5W5GBW4n7", "W40OWPPMWOpcOW", "xLddHflcLJm", "WPddNqFcUSoqWQy", "WQJcJCo+CtWuxSkwA8kH", "n0RdNHhdLx/cPfBcI8oTbdlcLqVdUtmYECkovSoTWQj4W5tcUrxcImo3W7u", "BSkTW5ms", "dshdQLzJpq", "u2ZcUIzHWRJcKshdUmol", "o8oIW75rjbO", "W7tcIgjYoCoY", "WPtdP8oCW5/dNmkCD1FdL3jzWOZdHW1/W5JdJSo0", "xKZdGepcLZJcUSo3k8osW6Csp8oDhrT7WRBdPa", "uxhcRqfKWQxcLcRdKSozAsO", "W6e9WPXeWOJcRIpdKhBdRI8nEa", "sbxcIrldS2dcJJdcRW", "eaNcJNNcI2CXW7hcTmkD", "h8oqxcZcKCodWRaFDCoA", "tSonWQxcOwlcQmoMWRXOW7D0WQaVygldTG", "guldKXRdNN7cKqtcJmoSbhFcHW", "c8o3m8k5WP/cMW", "B8kfhmk4hg/cUIj8FG", "WOZcOrFcJCoTaCklcComWO1MW63dIrnAW7tdM8ky", "fmoqrG/cGmoF", "W7ddKmkUiMiPCCkOwSkqW5y", "wmoqWP9IdmoJiHBcLCoQwgRdHa", "jtZcR39WoZhdMmkjWQxcOh8yW74", "xwBcGSoqpCoxrmkeW5ldUJ/dUSk9kCoE", "W5ddQwCfa1xcGGldTG", "WRrdrrFcJa", "z8oHwfLJWOe9WRmZja", "gCoOWRbDnqS", "lmkEW6nzqrJcPq", "u2ZcQsPJWRu", "WOX+W5GAWRlcJWZdHLldVW", "oL7dK8oMdaa", "WRBdTmojW7hdNmkuB1RdRNKlWRpdHWf0", "CCo7t312WOa", "y8ofWPLQc8o7fq", "W6BdHuewaeJcIq", "WORdKrRcTmoqW64", "uCoIWPzjW6VdOmkzWOu8WQCW", "oSoQWOriWPC8WOJdK8koD8k8g8o4", "W5XCWONdKCkWWOJcN8kPW4v3eCoCWPaH", "AuVcQtf+WRJcLXhdIq", "cCoGpSkIWOJcVmkcWRrHc8ok", "WOtdLrRcVCobW7tcKCovxKVcMdlcNW", "WPNcVCoPWRtdSq", "WR3dTmotW5tdNCkv", "rCo1WOTgW7BdJSklWRSGWQSSW4PBuq", "tvxdMJJcR0eTW5O", "q8kBiSkJauS", "WO7dOCopW5RdH8kj", "CCoJW7mIWObEbs0P", "ySocCxu", "W6/cMg7cK0ldLMRcTmoDAJFdOCkq", "fCoLaCkJhsmYW6hcUq", "qNVcLsXYWQ3cLcVdKSozAsRcHrFcM8oIWO8a", "fNdcTIzIW6ZcLIhdOSkyCc7cOGdcGCkR", "WOflv8o2g8kU", "WQCvW41xtCoJWQq", "BSotWRTQdSo+aG", "mCoBxGNcMmoEWRvwDCoafh92W6GLW7G3W6aQCa", "DCkEdCkGdeRcQsr4", "W7pdRCoUbW4FW5NcHW", "WQzTxq", "hXFcKXhcTXxcVCoBf8ol", "WQqFW5rYqCo5WRzsW6nv", "WRmpW5nE", "vmkLx8oJwuLNWRVdQthdJKG", "xwBcGSoDgW", "mg1PWO5ajW", "WRldQCkdbvRcTHZdRCotWO4", "EN3cUIz/WR/cNw7dS8oaBsBcPaBcJCkRWO4jiW", "lSkHW4DFWONcRrxcSq", "WOZcTmoYWPFdQSkXW5JcVwmHW5O9DW", "CComW7e5WOfE", "zmkWWQehAujmx8kQeNm6", "gmooW7ZdRsVdGq", "WQqFW5r0uCoKWRTFW4Thg8oh", "tSkngSkPcuhcUdvVrmkfz8oDWQ8", "WPu8WOa4", "W7ddUmkpAZakCdr7WRy", "tf7dIIRcKuqQ", "W5C+WQbcWOlcVW", "dSoqW7JdPsNdNhJdNmkXDISMcmk0W796o8oSWOPY", "W5rqWP7dLCk3WPFcICkC", "WQ1cAq/cMCkH", "WRjEs8o4aCkYW5FcU3JcMZFcOW", "mCk5WOz4EI3cIbFdPCkhW4q2W4BdQ8klW6CMnSkAAq", "WPBdHHVcVSonW7xcPa", "imkcncLFpx5Bst/cTcNcRq", "D8o8vqv7WOOEWR8IjmoH", "WQnbgCo9bSkLW7dcTgxcKhlcOxT2sHeIWRvQ", "gCkGW44uWQ3cLCkZWOuMWQaJW7S", "bmorW6pdQtddM3xcImkK", "WPFcRmoyuqy/D8kcqSkrW5JdU1RdPJNdL8kctWu", "D0VdJclcLLW", "zmkXWQrqgb5cB8k4", "WQBdPmksjeVcUHe", "rmoMWP5l", "m8kUfZNdUSoEWRldM8oelc1RW5a", "k8oBW6ddOZhdNq", "WO3dKq3cLCowW6NcRa", "t0xdI0JcHJlcHSoAlSovW7asnq", "h8oqxcRcGCoEWR0st8ombwLXW7qU", "nCobya", "qmkYqSoSrgfXWP/dUJhdJe9yW6i", "yCosWOHUgmoY", "umkkEKveW7WjaGfW", "WOfbwSoWa8kUW7RcQwi", "W7NcLw7cIKldIG", "sxFcL8oGpmonF8kjW7ddTW", "zcO6W58cDSoKW5ySuM8pvW", "WQFdSmorW4BdJmk7Dq", "BCkPW5CBW5PQ", "xvhdLK4", "qCkFDvLvW70ogrX2WOpcTtu", "w8ozDhWlycGIzJhcHcNcSSoTFG7cVauRumoVWPBcSXrCWQdcIa", "i1JdPCo4", "jfpdJX3dLxJcHrpcKCoJgx7cKa", "hConwahcHSoo", "WRbdrrq", "W63dVCoWW6mIpCk7pJyHhSk9khP/EHZcRLe", "W4HmWO7dMa", "E8ozDhWlycG", "WOG2WR4YW4zY", "nColACo/tSkt", "W6hcUSohCaZdUKxdHCoSWQZcSt9O", "W7pcHCkNW7xcGCoPugJcNa", "u8klAf8", "v8oXWPnsW7RdPmko", "WPWmW4fAtCoPWRzpW6O", "W6/cMx/cKutdGe7cRSo5Ca", "imoMW6nMiHTJxCkxaq", "p8oVWOfiWPbbW7RdN8kxBSkA", "uxhcTYzJWQ3cJcVdMmoxEsRcNWC", "DCosDLycCa", "w0VdKIlcJa", "iJ3dUvj1mtdcLSkEWQ/dRvuuW6K", "W7RdT8oMW6q", "W7pcNr/cOSk8W7xcKSkx", "WR5YmJ0tW74"];
return (Jl = function() {
return a;
})();
}
function Er(a, e, t, n, r) {
return Fe(n - -961, e);
}
class Vm {
constructor() {
const t = "$LH]";
function n(r, o, s, i, l) {
return Ut(0, 0, i - -725, l);
}
this[n(0, 0, 0, 415, "($u9")][n(0, 0, 0, 485, t)] = null;
}
async [Yn(0, 784, 0, 0, "EKeb")](e, t = !1) {
const g = "I^RK", m = "4uRu", b = "kD1l", x = "CV8D", I = "DEAz", R = "dJ7W", M = "4uRu", T = "vPt$";
if (!e || e[B(1523, 1572, 1554, "##1)")](H(621, 646, "4!Tp", 634)) || e[z("$BFF", 1255, 1356, 1268, 1278)](z("vLwY", 1171, 1263, 1302, 1236)) || e[B(1442, 1379, 1378, g)](H(512, 650, "d3gQ", 607)) || e[z(m, 1143, 1218, 1286, 1240)](z("70A6", 1391, 1344, 1367, 1348))) return ra = !0, await this[W(-348, "dJ7W", -279, -249)](!0);
function B(G, V, $, J, K) {
return Ut(0, 0, $ - 349, J);
}
function H(G, V, $, J, K) {
return Ct(0, J - -432, 0, $);
}
function z(G, V, $, J, K) {
return Yn(0, K - 539, 0, 0, G);
}
if (ra = !1, !t && Le[W(-111, "*U&x", -107, -205)]) {
const G = await this[z("B&#O", 0, 0, 0, 1203)]();
if (G[H(0, 0, "CZ9L", 670)]() && !G[H(0, 0, "LHOe", 575)]()) return G;
}
function W(G, V, $, J, K) {
return Ut(0, 0, J - -1305, V);
}
Le[B(0, 0, 1527, b)] = e, Le[j(-188, -170, -126, "4!Tp")] = j(-158, -216, -154, "EKeb"), Le[j(-234, -163, -191, x)] = null, Le[j(-272, -226, -239, I)] = null;
const L = await this[B(0, 0, 1377, "O9ng")]();
if (!L[H(0, 0, "CV8D", 692)]()) throw await this[H(0, 0, "vPt$", 624)](!0), new Error(W(0, R, 0, -124));
function j(G, V, $, J, K) {
return Ct(0, $ - -1292, 0, J);
}
if (F[H(0, 0, "!h[j", 573)]() && (await yr[j(0, 0, -228, M)](e, t), !(await this[j(0, 0, -300, "TECB")]())[W(0, T, 0, -235)]()))
throw await this[j(0, 0, -151, R)](!0), new Error(z("H#1x", 0, 0, 0, 1310));
return L;
}
async [Ct(0, 1126, 0, "[c$g")](e = !1) {
const t = "4!Tp", i = "CZ9L", l = "70A6", h = "Nns7", u = "1TsQ", d = "RzYp", g = "OvMJ", m = "LH%L", p = "*U&x", E = "VT$[", C = "$BFF", x = "bLtP", v = "DXBj", M = "zs#a", k = ")&5E", L = ")&5E", G = "TECB", $ = "vLwY", he = "!h[j";
if (Le[ge(1463, 1389, 1399, 1372, "DEAz")]) return Le[ge(1520, 1584, 1499, 1519, t)];
if (!this[ee(1384, 1419, 1325, "B&#O", 1361)][ue(-220, "[c$g", -141)] && (this[ee(1415, 1304, 1382, i, 1336)][ue(-139, l, -159)] = new Error("FV")), Le[re(648, "*rPU", 688)]) return Le[Z(718, 729, 745, h)];
function ee(se, _e, ve, ie, de) {
return ln(de - 162, 0, 0, ie);
}
let ne = null;
function ue(se, _e, ve, ie, de) {
return ln(ve - -1236, 0, 0, _e);
}
Le[ue(-183, "DXBj", -108)] = new Promise((se) => {
ne = se;
});
let be, Q = null;
const fe = async (se, _e) => {
function ve(ie, de, ye, we, me) {
return ee(0, 0, 0, me, de - -452);
}
try {
const ie = ((ye) => {
let we = ye;
const me = we[we.length - 1], Me = me.charCodeAt(0) - 52;
if (we = we.substring(0, we.length - 1), we = we.split("").reverse().join(""), we = jm(we), we = we.trim(), we[we.length - 1] !== me) throw new Error();
we = we.substring(0, we.length - 1), we = Wm(we, Me);
try {
we.startsWith("{") || (we = "{" + we);
const Ce = JSON.parse(we), We = { licensee: Ce.l, domains: Ce.d, nodeId: Ce.n, expiry: Ce.e, developerCount: Ce.dc, cpuCount: Ce.cc, type: Ce.t };
return Ce.f && (We.features = Ce.f), We;
} catch {
throw new Error("Invalid license key.");
}
})(_e), de = ((ye, we, me) => {
const Me = "O9ng", We = "dJ7W";
function et(vt, st, Ue, it, wt) {
return Fe(wt - -597, it);
}
function tt(vt, st, Ue, it, wt) {
return Fe(st - 375, vt);
}
function ot(vt, st, Ue, it, wt) {
return Fe(st - 505, it);
}
function Vt(vt, st, Ue, it, wt) {
return Fe(it - 229, wt);
}
return { licensee: () => ye[ot(0, 1146, 0, "Gda1")], expiration: () => new Date(ye[ot(0, 1171, 0, "I^RK")]), domains: () => ye[ot(0, 1120, 0, "O9ng")] ?? [], developerCount: () => ye[tt("[c$g", 1010)] ?? 1, cpuCount: () => ye[Vt(0, 0, 0, 729, "]Wfy")] ?? 0, type: () => ye[et(0, 0, 0, "DEAz", 39)] ?? ot(0, 1155, 0, "dJ7W"), exceptions: () => we, isValidFor: (vt) => {
return !(we?.[st = We, Ue = 218, Vt(0, 0, 0, Ue - -668, st)] > 0);
var st, Ue;
}, isValid: () => !0, isEval: () => !1, features: () => Object[Vt(0, 0, 0, 791, "my]0")](ye[ot(0, 1124, 0, "vPt$")] ?? {}), keyFrom: () => me, getBuildVersion: pn[tt("$LH]", 966)], getBuildDate: pn[et(0, 0, 0, Me, 37)] };
})(ie, await (async (ye) => {
const me = "($u9", tt = "H#1x", ot = "hd28", Vt = "Gda1", Ue = "##1)", it = "bJ@o", Am = "J#cY", Mm = "($u9", Tm = "O9ng", Nm = "1TsQ";
function Sr(kt, Zt, Mn, so, Tn) {
return Fe(Zt - -513, kt);
}
const cs = ye[oo(744, "VT$[", 745, 745, 755)], hs = ye[oo(767, me, 842, 733, 804)] ? new Date(ye[wr(198, 318, 280, 288, tt)]) : null, ea = ye[oo(688, ot, 818, 788, 781)], Qt = [];
function us(kt, Zt, Mn, so, Tn) {
return Fe(Zt - -78, Tn);
}
if (hs ? isNaN(hs) ? Qt[wr(302, 199, 304, 297, Ue)](oo(851, it, 813, 872, 793)) : hs < /* @__PURE__ */ new Date() && Qt[wr(433, 539, 457, 483, "LH%L")](us(0, 550, 0, 0, "($u9") + hs[wr(498, 509, 388, 424, me)]()) : Qt[Sr(Vt, -34)](Sr("[c$g", 3)), F[ds(1557, "4uRu", 1700, 1568, 1630)]()) {
if (!ea) return Qt[Sr(Am, -39)](us(0, 482, 0, 0, "wj3Q")), Qt;
const kt = await yr[Sr("($u9", -22)]();
kt !== ea && Qt[ds(1557, "bLtP", 1529, 1513, 1600)](oo(665, "I^RK", 748, 747, 740) + ea + Sr(Mm, 100) + kt);
} else {
if (ml()) return Qt;
if (cs && cs[ds(1538, "H#1x", 1655, 1481, 1569)] !== 0) {
let kt = !1;
const Zt = Si();
for (let Mn = 0; !kt && Mn < cs[ds(1560, "wAgp", 1634, 1688, 1605)]; Mn++) kt = Zt[wr(237, 324, 248, 313, "H#1x")](cs[Mn]);
!kt && Qt[us(0, 447, 0, 0, Nm)](wr(281, 259, 314, 306, "my]0"));
} else Qt[us(0, 545, 0, 0, Tm)](Sr("1TsQ", 131));
}
function ds(kt, Zt, Mn, so, Tn) {
return Fe(Tn - 991, Zt);
}
function wr(kt, Zt, Mn, so, Tn) {
return Fe(so - -188, Tn);
}
function oo(kt, Zt, Mn, so, Tn) {
return Fe(Tn - 216, Zt);
}
return Qt;
})(ie), se);
return de[ve(0, 851, 0, 0, "!h[j")]()[ve(0, 829, 0, 0, "hd28")] > 0 && (be = de), de;
} catch {
be = ((de) => {
const ye = "bLtP";
function me(Ce, We, et, tt, ot) {
return Fe(We - 98, Ce);
}
function Me(Ce, We, et, tt, ot) {
return Fe(tt - -665, Ce);
}
return { licensee: () => null, expiration: () => null, domains: () => [], developerCount: () => 0, cpuCount: () => 0, type: () => me("bLtP", 578), exceptions: () => {
return [(Ce = 588, We = ye, me(We, Ce - 17) + de + "'")];
var Ce, We;
}, isValidFor: (Ce) => !1, isValid: () => !1, isEval: () => !1, features: () => Object[Me("%Fm@", 0, 0, -39)]({}), keyFrom: () => de, getBuildVersion: pn[Me("Nns7", 0, 0, -83)], getBuildDate: pn[Me("kD1l", 0, 0, -129)] };
})(se);
}
};
function ge(se, _e, ve, ie, de) {
return ln(ve - 263, 0, 0, de);
}
Le[ge(0, 0, 1375, 0, u)] && (Q = await fe(Le[ue(0, d, -110)], Le[ge(0, 0, 1375, 0, "1TsQ")]));
let ae = !1;
function Z(se, _e, ve, ie, de) {
return Ct(0, _e - -311, 0, ie);
}
if (ra && (ae = !0, Q = Sc(Z(0, 770, 0, g))), !Q)
if (F[ee(0, 0, 0, m, 1262)]()) {
if (!Q) {
const se = process[Z(0, 817, 0, "A9SG")], _e = se[ee(0, 0, 0, p, 1404)] || se[ue(0, u, -58)] || se[ge(0, 0, 1508, 0, E)] || se[ee(0, 0, 0, "LH%L", 1320)];
_e && (Q = await fe(ee(0, 0, 0, C, 1345), _e));
}
if (!Q) {
const se = await yr[ge(0, 0, 1346, 0, x)]();
se && (Q = await fe(Z(0, 715, 0, v), se));
}
!Q && (ae = !0);
} else {
if (!Q) try {
const se = await fetch("./" + yc);
let _e = null;
if (se[re(707, m, 731, 773, 781)] === 200) {
const ve = (await se[ue(0, M, -150)]())[ue(0, k, -152)](`
`);
for (let ie = 0; !_e && ie < ve[ue(0, "e$L5", -81)]; ie++) {
const de = ve[ie][re(572, d, 651, 573, 583)]();
de[ee(0, 0, 0, "Nns7", 1420)]("#") || de[ue(0, "O9ng", -99)] === 0 || (_e = de);
}
}
if (_e) {
const ve = ue(0, "1TsQ", -122) + yc + "')";
Q = await fe(ve, _e);
}
} catch {
}
!Q && ml() && (ae = !0);
}
function re(se, _e, ve, ie, de) {
return Er(0, _e, 0, ve - 1135);
}
if (!Q && ae && (Q = Sc(ee(0, 0, 0, "my]0", 1334))), !Q && be && (Q = be), !Q && (Q = { licensee: () => null, expiration: () => null, domains: () => [], developerCount: () => 0, cpuCount: () => 0, type: () => null, isEval: () => !1, exceptions: () => [ue(0, "wAgp", 3)], isValidFor: (se) => !1, isValid: () => !1, features: () => Object[ge(0, 0, 1524, 0, "*rPU")]({}), keyFrom: () => ue(0, "e$L5", -59), getBuildVersion: pn[Z(0, 702, 0, "bJ@o")], getBuildDate: pn[re(0, "$LH]", 687)] }), Le[ue(0, L, -7)] = Q, ne(Q), e && !(Le[ue(0, "LH%L", 14)] && Le[Z(0, 795, 0, "Gda1")]) && (ae || Q[ee(0, 0, 0, G, 1255)]()[re(0, $, 656)] > 0 || Q[ee(0, 0, 0, x, 1287)]()?.pb)) {
if (wc) return void setTimeout(() => {
var se, _e;
this[se = 254, _e = he, ee(0, 0, 0, _e, se - -997)](!1, !1);
}, 8e3);
await this[ue(0, k, 7)](!1, !1);
}
return Le[ue(0, "CV8D", -52)];
}
async [Er(0, "H#1x", 0, -428)](e) {
const t = "CV8D", r = "$LH]", s = "zs#a";
function i(d, g, m, f, _) {
return Yn(0, f - -597, 0, 0, d);
}
function l(d, g, m, f, _) {
return Ct(0, d - -381, 0, f);
}
Le[u("CZ9L", 960, 871, 983, 957)] = !0;
const c = await this[h(-318, t, -373, -231, -299)]();
function h(d, g, m, f, _) {
return Ut(0, 0, _ - -1384, g);
}
function u(d, g, m, f, _) {
return Ut(0, 0, _ - -135, d);
}
return await yr[h(-147, "70A6", -286, -275, -247)](e), !Le[l(653, 0, 0, ")&5E")] && (c[i("RzYp", 0, 0, 199)]() || c[l(690, 0, 0, "($u9")]()[i(r, 0, 0, 160)] > 0) && await this[u("CV8D", 973, 903, 940, 986)](e), Promise[i(s, 0, 0, 68)]();
}
async [Ct(0, 1077, 0, "4uRu")](e = !1, t = !1, n = !1) {
const s = "J#cY", h = "Xc0]";
function g(C, w, b, x, I) {
return Er(0, b, 0, C - 481);
}
Le[y(-3, "70A6", 118, 80)] = !0;
const m = await this[y(99, "VT$[", 177, 103)]();
function f(C, w, b, x, I) {
return Ut(0, 0, w - 294, I);
}
var _, p, S, E;
Le[f(0, 1436, 0, 0, "4!Tp")] || !(m[S = s, E = 942, Ct(0, E - -156, 0, S)]() || m[f(0, 1357, 0, 0, "LHOe")]()[_ = 468, p = "4!Tp", Yn(0, _ - -281, 0, 0, p)] > 0) ? await yr[g(144, 0, "d3gQ")](m, e, t, n) : await this[g(50, 0, h)](e);
function y(C, w, b, x, I) {
return ln(x - -1115, 0, 0, w);
}
}
async [Yn(0, 785, 0, 0, "B&#O")](e, t) {
const r = "wj3Q", o = "DXBj", s = "A9SG", i = "[c$g", l = "vLwY", h = "zs#a";
if (!e && (Le[g(661, 685, "e$L5", 684)] || Le[g(673, 568, r, 647)])) return;
function g(w, b, x, I, v) {
return ln(I - -447, 0, 0, x);
}
function m(w, b, x, I, v) {
return Ct(0, b - 110, 0, v);
}
var f, _;
function p(w, b, x, I, v) {
return ln(x - -1397, 0, 0, w);
}
Le[p("##1)", -170, -134)] = !0, Le[f = 452, _ = o, Er(0, _, 0, f - 894)] = !0, await this[p(s, 0, -253)](e);
const S = F[m(0, 1224, 0, 0, i)](), E = e || S ? console[g(0, 0, l, 805)] : F[m(0, 1096, 0, 0, h)];
var y, C;
S && E(""), await this[y = 1416, C = "wj3Q", Er(0, C, 0, y - 1902)](e, t), E("");
}
[ln(1163, 0, 0, "H#1x")]() {
return this[e = 866, t = "*rPU", Yn(0, e - 192, 0, 0, t)]();
var e, t;
}
[Ut(0, 0, 1125, "RzYp")](e) {
return this[t = "$LH]", n = 341, Er(0, t, 0, n - 695)](!0, e);
var t, n;
}
[ln(1080, 0, 0, "e$L5")]() {
const e = "d3gQ";
function t(n, r, o, s, i) {
return Ut(0, 0, r - -824, o);
}
return Le[t(0, 291, "wj3Q")] || Le[t(0, 379, e)];
}
[ln(1201, 0, 0, "I^RK")](e) {
wc = !0;
}
async [Ct(0, 1108, 0, "b0Sp")]() {
return this[e = "wAgp", t = 262, Ct(0, t - -889, 0, e)](!0);
var e, t;
}
async [Yn(0, 671, 0, 0, "my]0")](e, t) {
const n = "LHOe", o = await this[s = 505, i = "O9ng", Ut(0, 0, s - -658, i)]();
var s, i, l, c;
return await this[l = n, c = 1431, Ut(0, 0, c - 234, l)](!0, e, t), o;
}
async [Ct(0, 1016, 0, "1TsQ")]() {
var e, t;
return await yr[e = -386, t = "!h[j", Ct(0, e - -1446, 0, t)]();
}
}
const Bd = new Vm();
function Fe(a, e) {
const t = Jl();
return Fe = function(n, r) {
let o = t[n -= 473];
if (Fe.vbArKj === void 0) {
const l = function(c, h) {
let u, d, g = [], m = 0, f = "";
for (c = function(_) {
let p = "", S = "";
for (let E, y, C = 0, w = 0; y = _.charAt(w++); ~y && (E = C % 4 ? 64 * E + y : y, C++ % 4) ? p += String.fromCharCode(255 & E >> (-2 * C & 6)) : 0) y = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=".indexOf(y);
for (let E = 0, y = p.length; E < y; E++) S += "%" + ("00" + p.charCodeAt(E).toString(16)).slice(-2);
return decodeURIComponent(S);
}(c), d = 0; d < 256; d++) g[d] = d;
for (d = 0; d < 256; d++) m = (m + g[d] + h.charCodeAt(d % h.length)) % 256, u = g[d], g[d] = g[m], g[m] = u;
d = 0, m = 0;
for (let _ = 0; _ < c.length; _++) d = (d + 1) % 256, m = (m + g[d]) % 256, u = g[d], g[d] = g[m], g[m] = u, f += String.fromCharCode(c.charCodeAt(_) ^ g[(g[d] + g[m]) % 256]);
return f;
};
Fe.sWZulW = l, a = arguments, Fe.vbArKj = !0;
}
const s = n + t[0], i = a[s];
return i ? o = i : (Fe.STUJxL === void 0 && (Fe.STUJxL = !0), o = Fe.sWZulW(o, r), a[s] = o), o;
}, Fe(a, e);
}
const fl = (a, e) => {
const t = [];
for (let n = 0; n < a.length; n++) {
const r = a[n];
t.push({ x: r.x + e.x, y: r.y + e.y });
}
return t;
}, pl = (a, e) => {
if (!a) return { ...e };
if (!e) return { ...a };
let t = Math.min(a.x, e.x), n = Math.min(a.y, e.y);
return { x: t, y: n, width: Math.max(a.width + a.x, e.width + e.x) - t, height: Math.max(a.height + a.y, e.height + e.y) - n };
}, oa = (a) => [{ x: a.x, y: a.y }, { x: a.x + a.width, y: a.y }, { x: a.x + a.width, y: a.y + a.height }, { x: a.x, y: a.y + a.height }], _l = (a) => {
let e = Number.MAX_SAFE_INTEGER, t = Number.MAX_SAFE_INTEGER, n = Number.MIN_SAFE_INTEGER, r = Number.MIN_SAFE_INTEGER;
for (let o = 0; o < a.length; o++) {
let s = a[o];
e = Math.min(e, s.x), t = Math.min(t, s.y), n = Math.max(n, s.x), r = Math.max(r, s.y);
}
return { x: e, y: t, width: n - e, height: r - t };
}, sa = (a, e, t) => {
if (!t) {
const i = _l(a);
t = { x: i.x + i.width / 2, y: i.y + i.height / 2 };
}
a = fl(a, { x: -t.x, y: -t.y });
const n = e * Math.PI / 180, r = Math.sin(n), o = Math.cos(n), s = [];
for (let i = 0; i < a.length; i++) {
const l = a[i], c = o * l.x - r * l.y, h = r * l.x + o * l.y;
s.push({ x: c, y: h });
}
return a = fl(s, { x: t.x, y: t.y });
}, zd = (a, e, t, n, r, o, s, i, l = !0) => {
if (a === t && e === n || r === s && o === i) return !1;
let c = (i - o) * (t - a) - (s - r) * (n - e);
if (c === 0) return !1;
let h = ((s - r) * (e - o) - (i - o) * (a - r)) / c, u = ((t - a) * (e - o) - (n - e) * (a - r)) / c;
return (!l || !(h < 0 || h > 1 || u < 0 || u > 1)) && { x: a + h * (t - a), y: e + h * (n - e) };
}, ft = (a, e, t = !0) => zd(a.p1.x, a.p1.y, a.p2.x, a.p2.y, e.p1.x, e.p1.y, e.p2.x, e.p2.y, t), gs = (a) => ({ top: { p1: a[0], p2: a[1] }, left: { p1: a[3], p2: a[0] }, right: { p1: a[1], p2: a[2] }, bottom: { p1: a[2], p2: a[3] } }), Ec = (a, e, t) => {
let n = t * Math.PI / 180, r = Math.sin(n), o = Math.cos(n);
return { x: a * o - e * r, y: a * r + e * o };
}, Fn = (a, e) => {
let t = a.p2.x - e.x, n = a.p2.y - e.y;
const r = Ec(t, n, 90);
t = r.x + e.x, n = r.y + e.y;
let o = a.p1.x - e.x, s = a.p1.y - e.y;
const i = Ec(o, s, 90);
return o = i.x + e.x, s = i.y + e.y, { p1: { x: o, y: s }, p2: { x: t, y: n } };
}, ey = Object.freeze(Object.defineProperty({ __proto__: null, angleToPoints: (a, e) => {
const t = (180 - a) / 180 * Math.PI, n = Math.abs(e.width * Math.sin(t)) + Math.abs(e.height * Math.cos(t)), r = Math.sin(t) * n / 2, o = Math.cos(t) * n / 2, s = e.width / 2, i = e.height / 2;
return { x1: s - r, y1: i - o, x2: s + r, y2: i + o };
}, boundsToPoints: oa, centerPoint: (a) => ({ x: a.width / 2 + a.x, y: a.height / 2 + a.y }), clipToOuterRect: (a, e, t = 0) => {
if (t < 0 && (t += 360), t > 90 && t <= 180 ? t += 180 : t > 180 && t <= 270 && (t -= 180), t === 0 || t === 180) return { height: e.height, width: e.width };
if (t === 90 || t === 270) return { height: e.width, width: e.height };
let n = oa({ ...e, x: 0, y: 0 }), r = oa({ ...a, x: 0, y: 0 });
r = fl(r, { x: e.width / 2 - a.width / 2, y: e.height / 2 - a.height / 2 }), r = sa(r, t);
let o = gs(r), s = gs(n);
if (t > 90) {
const l = ft(o.top, s.top);
if (l) {
const h = l, u = ft(o.bottom, s.bottom, !1) || r[3];
r[0] = ft(o.top, Fn(o.bottom, u), !1) || r[0], r[1] = h, r[3] = u, r[2] = ft(o.bottom, Fn(o.top, h), !1) || r[2], o = gs(r);
}
const c = ft(o.top, s.left);
if (c) {
const h = c, u = ft(o.bottom, s.right, !1) || r[2];
r[0] = h, r[1] = ft(o.top, Fn(o.bottom, u), !1) || r[1], r[3] = ft(o.bottom, Fn(o.top, h), !1) || r[3], r[2] = u;
}
} else if (t < 90) {
const l = ft(o.top, s.top);
if (l) {
const h = l, u = ft(o.bottom, s.bottom, !1) || r[2];
r[0] = h, r[1] = ft(o.top, Fn(o.bottom, u), !1) || r[1], r[3] = ft(o.bottom, Fn(o.top, h), !1) || r[3], r[2] = u, o = gs(r);
}
const c = ft(o.top, s.right);
if (c) {
const h = c, u = ft(o.bottom, s.left, !1) || r[3];
r[0] = ft(o.top, Fn(o.bottom, u), !1) || r[0], r[1] = h, r[3] = u, r[2] = ft(o.bottom, Fn(o.top, h), !1) || r[2];
}
}
r = sa(r, -t);
const i = _l(r);
return { width: i.width, height: i.height };
}, findIntersectMath: (a, e, t, n) => {
let r = zd(a.x, a.y, e.x, e.y, 5e4, 0, -5e4, 0);
return r && (t = Math.min(t, r.x), n = Math.max(n, r.x)), { min: t, max: n };
}, leastSquaresSlopeAndIntercept: (a) => {
let e = 0, t = 0, n = 0, r = 0, o = 0, s = 0, i = 0, l = a.length;
if (l === 0) return { m: 0, b: 0 };
if (l === 1) return { m: 1, b: a[0] };
for (let h = 0; h < l; h++) s = h + 1, i = a[h], i == null || isNaN(i) || (e += s, t += i, r += s * s, n += s * i, o++);
const c = (o * n - e * t) / (o * r - e * e);
return { m: c, b: t / o - c * e / o };
}, minBoundingRect: _l, rotatePoints: sa, unionBounds: pl }, Symbol.toStringTag, { value: "Module" }));
class Ae {
constructor(e, t, n) {
this._root = ia, this._size = 0, this._maxNodeSize = n >= 4 ? Math.min(n, 256) : 32, this._compare = t || Ae.defaultComparator, e && this.setPairs(e);
}
get size() {
return this._size;
}
get length() {
return this._size;
}
get isEmpty() {
return this._size === 0;
}
clear() {
this._root = ia, this._size = 0;
}
forEach(e, t) {
return t !== void 0 && (e = e.bind(t)), this.forEachPair((n, r) => e(r, n, this));
}
forEachPair(e, t) {
const n = this.minKey(), r = this.maxKey();
return this.forRange(n, r, !0, e, t);
}
get(e, t) {
return this._root.get(e, t, this);
}
set(e, t, n) {
this._root.isShared && (this._root = this._root.clone());
const r = this._root.set(e, t, n, this);
return r === !0 || r === !1 ? r : (this._root = new Ho([this._root, r]), !0);
}
has(e) {
return this.forRange(e, e, !0, void 0) !== 0;
}
delete(e) {
return this.editRange(e, e, !0, Ae.DeleteRange) !== 0;
}
with(e, t, n) {
const r = this.clone();
return r.set(e, t, n) || n ? r : this;
}
withPairs(e, t) {
const n = this.clone();
return n.setPairs(e, t) !== 0 || t ? n : this;
}
withKeys(e, t) {
const n = this.clone();
let r = !1;
for (let o = 0; o < e.length; o++) r = n.set(e[o], void 0, !1) || r;
return t && !r ? this : n;
}
without(e, t) {
return this.withoutRange(e, e, !0, t);
}
withoutKeys(e, t) {
const n = this.clone();
return n.deleteKeys(e) || !t ? n : this;
}
withoutRange(e, t, n, r) {
const o = this.clone();
return o.deleteRange(e, t, n) === 0 && r ? this : o;
}
filter(e, t) {
const n = this.greedyClone();
let r;
return n.editAll((o, s, i) => {
if (!e(o, s, i)) return r = Ae.DeleteValue;
}), !r && t ? this : n;
}
mapValues(e) {
const t = this.greedyClone();
return t.editAll((n, r, o) => e(r, n, o)), t;
}
reduce(e, t) {
let n, r = 0, o = t;
const s = this.entries(this.minKey());
for (; !(n = s.next()).done; ) o = e(o, n.value, r++, this);
return o;
}
entries(e, t) {
const n = this.findPath(e);
if (n === void 0) return Cr();
let { nodeQueue: r, nodeIndex: o, leaf: s } = n, i = t !== void 0 ? 1 : 0, l = e === void 0 ? -1 : s.indexOf(e, 0, this._compare) - 1;
return Cr(() => {
e: for (; ; ) switch (i) {
case 0:
if (++l < s.keys.length) return { done: !1, value: [s.keys[l], s.values[l]] };
i = 2;
continue;
case 1:
if (++l < s.keys.length) {
const h = s.keys[l], u = s.values[l];
return t ? (t.done = !1, t.value[0] = h, t.value[1] = u, t) : { done: !1, value: [h, u] };
}
i = 2;
case 2:
for (var c = -1; ; ) {
if (++c >= r.length) {
i = 3;
continue e;
}
if (++o[c] < r[c].length) break;
}
for (; c > 0; c--) r[c - 1] = r[c][o[c]].children, o[c - 1] = 0;
s = r[0][o[0]], l = -1, i = t !== void 0 ? 1 : 0;
continue;
case 3:
return Sl;
}
});
}
entriesReversed(e, t, n) {
if (e === void 0 && (n = void 0, (e = this.maxKey()) === void 0)) return Cr();
let { nodeQueue: r, nodeIndex: o, leaf: s } = this.findPath(e) || this.findPath(this.maxKey());
Mt(!r[0] || s === r[0][o[0]], "wat!");
let i = s.indexOf(e, 0, this._compare);
!n && i < s.keys.length && this._compare(s.keys[i], e) <= 0 && i++;
let l = t !== void 0 ? 1 : 0;
return Cr(() => {
e: for (; ; ) switch (l) {
case 0:
if (--i >= 0) return { done: !1, value: [s.keys[i], s.values[i]] };
l = 2;
continue;
case 1:
if (--i >= 0) {
const h = s.keys[i], u = s.values[i];
return t ? (t.done = !1, t.value[0] = h, t.value[1] = u, t) : { done: !1, value: [h, u] };
}
l = 2;
case 2:
for (var c = -1; ; ) {
if (++c >= r.length) {
l = 3;
continue e;
}
if (--o[c] >= 0) break;
}
for (; c > 0; c--) r[c - 1] = r[c][o[c]].children, o[c - 1] = r[c - 1].length - 1;
s = r[0][o[0]], i = s.keys.length, l = t !== void 0 ? 1 : 0;
continue;
case 3:
return Sl;
}
});
}
findPath(e) {
let t, n, r = this._root;
if (r.isLeaf) t = Cc, n = Cc;
else {
t = [], n = [];
for (let o = 0; !r.isLeaf; o++) {
if (t[o] = r.children, n[o] = e === void 0 ? 0 : r.indexOf(e, 0, this._compare), n[o] >= t[o].length) return;
r = t[o][n[o]];
}
t.reverse(), n.reverse();
}
return { nodeQueue: t, nodeIndex: n, leaf: r };
}
diffAgainst(e, t, n, r) {
if (e._compare !== this._compare) throw new Error("SortedMap: Comparators are not the same.");
if (this.isEmpty || e.isEmpty)
return this.isEmpty && e.isEmpty ? void 0 : this.isEmpty ? n === void 0 ? void 0 : Ae.stepToEnd(Ae.makeDiffCursor(e), n) : t === void 0 ? void 0 : Ae.stepToEnd(Ae.makeDiffCursor(this), t);
const { _compare: o } = this, s = Ae.makeDiffCursor(this), i = Ae.makeDiffCursor(e);
let l = !0, c = !0, h = Ae.compare(s, i, o);
for (; l && c; ) {
const u = Ae.compare(s, i, o), { leaf: d, internalSpine: g, levelIndices: m } = s, { leaf: f, internalSpine: _, levelIndices: p } = i;
if (d || f) {
if (h !== 0) {
if (u === 0) {
if (d && f && r) {
const S = d.values[m[m.length - 1]], E = f.values[p[p.length - 1]];
if (!Object.is(S, E)) {
const y = r(s.currentKey, S, E);
if (y && y.break) return y.break;
}
}
} else if (u > 0) {
if (f && n) {
const S = f.values[p[p.length - 1]], E = n(i.currentKey, S);
if (E && E.break) return E.break;
}
} else if (t && d && h !== 0) {
const S = d.values[m[m.length - 1]], E = t(s.currentKey, S);
if (E && E.break) return E.break;
}
}
} else if (!d && !f && u === 0) {
const S = g.length - 1, E = _.length - 1, y = g[S][m[S]];
if (_[E][p[E]] === y) {
h = 0, l = Ae.step(s, !0), c = Ae.step(i, !0);
continue;
}
}
h = u, u < 0 ? l = Ae.step(s) : c = Ae.step(i);
}
return l && t ? Ae.finishCursorWalk(s, i, o, t) : c && n ? Ae.finishCursorWalk(i, s, o, n) : void 0;
}
static finishCursorWalk(e, t, n, r) {
const o = Ae.compare(e, t, n);
if (o === 0) {
if (!Ae.step(e)) return;
} else o < 0 && Mt(!1, "cursor walk terminated early");
return Ae.stepToEnd(e, r);
}
static stepToEnd(e, t) {
let n = !0;
for (; n; ) {
const { leaf: r, levelIndices: o, currentKey: s } = e;
if (r) {
const i = t(s, r.values[o[o.length - 1]]);
if (i && i.break) return i.break;
}
n = Ae.step(e);
}
}
static makeDiffCursor(e) {
const { _root: t, height: n } = e;
return { height: n, internalSpine: [[t]], levelIndices: [0], leaf: void 0, currentKey: t.maxKey() };
}
static step(e, t) {
const { internalSpine: n, levelIndices: r, leaf: o } = e;
if (t === !0 || o) {
const s = r.length;
if (t === !0 || r[s - 1] === 0) {
const i = n.length;
if (i === 0) return !1;
const l = i - 1;
let c = l;
for (; c >= 0; ) {
if (r[c] > 0) return c < s - 1 && (e.leaf = void 0, r.pop()), c < l && (e.internalSpine = n.slice(0, c + 1)), e.currentKey = n[c][--r[c]].maxKey(), !0;
c--;
}
return !1;
}
{
const i = --r[s - 1];
return e.currentKey = o.keys[i], !0;
}
}
{
const s = n.length, i = s - 1, l = n[i][r[i]];
if (l.isLeaf) {
e.leaf = l;
const c = r[s] = l.values.length - 1;
e.currentKey = l.keys[c];
} else {
const c = l.children;
n[s] = c;
const h = c.length - 1;
r[s] = h, e.currentKey = c[h].maxKey();
}
return !0;
}
}
static compare(e, t, n) {
const { height: r, currentKey: o, levelIndices: s } = e, { height: i, currentKey: l, levelIndices: c } = t, h = n(l, o);
if (h !== 0) return h;
const u = r < i ? r : i;
return s.length - (r - u) - (c.length - (i - u));
}
keys(e, t) {
const n = this.entries(e, t);
return Cr(() => {
const r = n.next();
return r.value && (r.value = r.value[0]), r;
});
}
values(e, t) {
const n = this.entries(e, t);
return Cr(() => {
const r = n.next();
return r.value && (r.value = r.value[1]), r;
});
}
get maxNodeSize() {
return this._maxNodeSize;
}
minKey() {
return this._root.minKey();
}
maxKey() {
return this._root.maxKey();
}
clone() {
this._root.isShared = !0;
const e = new Ae(void 0, this._compare, this._maxNodeSize);
return e._root = this._root, e._size = this._size, e;
}
greedyClone(e) {
const t = new Ae(void 0, this._compare, this._maxNodeSize);
return t._root = this._root.greedyClone(e), t._size = this._size, t;
}
toArray(e = 2147483647) {
const t = this.minKey(), n = this.maxKey();
return t !== void 0 ? this.getRange(t, n, !0, e) : [];
}
keysArray() {
const e = [];
return this._root.forRange(this.minKey(), this.maxKey(), !0, !1, this, 0, (t, n) => {
e.push(t);
}), e;
}
valuesArray() {
const e = [];
return this._root.forRange(this.minKey(), this.maxKey(), !0, !1, this, 0, (t, n) => {
e.push(n);
}), e;
}
toString() {
return this.toArray().toString();
}
setIfNotPresent(e, t) {
return this.set(e, t, !1);
}
nextHigherPair(e, t) {
return e === void 0 ? this._root.minPair(t) : this._root.getPairOrNextHigher(e, this._compare, !1, t);
}
nextHigherKey(e, t) {
const n = this.nextHigherPair(e, t);
return n && n[0];
}
nextLowerPair(e, t) {
return e === void 0 ? this._root.maxPair(t) : this._root.getPairOrNextLower(e, this._compare, !1, t);
}
nextLowerKey(e, t) {
const n = this.nextLowerPair(e, t);
return n && n[0];
}
getPairOrNextLower(e, t) {
return this._root.getPairOrNextLower(e, this._compare, !0, t);
}
getPairOrNextHigher(e, t) {
return this._root.getPairOrNextHigher(e, this._compare, !0, t);
}
changeIfPresent(e, t) {
return this.editRange(e, e, !0, (n, r) => ({ value: t })) !== 0;
}
getRange(e, t, n, r = 67108863) {
const o = [];
return this._root.forRange(e, t, n, !1, this, 0, (s, i) => (o.push([s, i]), o.length > r ? Ae.Break : void 0)), o;
}
setPairs(e, t) {
let n = 0;
for (let r = 0; r < e.length; r++) this.set(e[r][0], e[r][1], t) && n++;
return n;
}
forRange(e, t, n, r, o) {
const s = this._root.forRange(e, t, n, !1, this, o || 0, r);
return typeof s == "number" ? s : s.break;
}
forEditRange(e, t, n, r, o, s) {
return this._root.forRange(e, t, n, r, this, s || 0, o);
}
editRange(e, t, n, r, o) {
let s = this._root;
s.isShared && (this._root = s = s.clone());
try {
const i = s.forRange(e, t, n, !0, this, o || 0, r);
return typeof i == "number" ? i : i.break;
} finally {
let i;
for (; s.keys.length <= 1 && !s.isLeaf; ) i ||= s.isShared, this._root = s = s.keys.length === 0 ? ia : s.children[0];
i && (s.isShared = !0);
}
}
editAll(e, t) {
return this.editRange(this.minKey(), this.maxKey(), !0, e, t);
}
deleteRange(e, t, n) {
return this.editRange(e, t, n, Ae.DeleteRange);
}
deleteKeys(e) {
let t = 0;
for (let n = 0; n < e.length; n++) this.delete(e[n]) && t++;
return t;
}
get height() {
let e = this._root, t = -1;
for (; e; ) t++, e = e.isLeaf ? void 0 : e.children[0];
return t;
}
freeze() {
const e = this;
e.clear = e.set = e.editRange = function() {
throw new Error("SortedMap: Attempted to modify when frozen.");
};
}
unfreeze() {
delete this.clear, delete this.set, delete this.editRange;
}
get isFrozen() {
return this.hasOwnProperty("editRange");
}
checkValid() {
const e = this._root.checkValid(0, this, 0);
Mt(e === this.size, "size mismatch: counted ", e, "but stored", this.size);
}
}
function Cr(a = () => Sl) {
const e = { next: a };
return Symbol && Symbol.iterator && (e[Symbol.iterator] = function() {
return this;
}), e;
}
Symbol && Symbol.iterator && (Ae.prototype[Symbol.iterator] = Ae.prototype.entries), Ae.prototype.where = Ae.prototype.filter, Ae.prototype.setRange = Ae.prototype.setPairs, Ae.prototype.add = Ae.prototype.set;
class $o {
get isLeaf() {
return this.children === void 0;
}
constructor(e = [], t) {
this.keys = e, this.values = t || lt, this.isShared = void 0;
}
maxKey() {
return this.keys[this.keys.length - 1];
}
indexOf(e, t, n) {
const r = this.keys;
let o = 0, s = r.length, i = s >> 1;
for (; o < s; ) {
const l = n(r[i], e);
if (l < 0) o = i + 1;
else {
if (!(l > 0)) {
if (l === 0) return i;
if (e == e) return r.length;
throw new Error("SortedMap: NaN was used as a key.");
}
s = i;
}
i = o + s >> 1;
}
return i ^ t;
}
minKey() {
return this.keys[0];
}
minPair(e) {
if (this.keys.length !== 0) return (e = e ?? [null, null])[0] = this.keys[0], e[1] = this.values[0], e;
}
maxPair(e) {
if (this.keys.length === 0) return;
const t = this.keys.length - 1;
return (e = e ?? [null, null])[0] = this.keys[t], e[1] = this.values[t], e;
}
clone() {
const e = this.values, t = e === lt ? e : e.slice(0), n = this.keys.slice(0);
return new $o(n, t);
}
greedyClone(e) {
return this.isShared && !e ? this : this.clone();
}
get(e, t, n) {
const r = this.indexOf(e, -1, n._compare);
return r < 0 ? t : this.values[r];
}
getPairOrNextLower(e, t, n, r) {
const o = this.indexOf(e, -1, t), s = o < 0 ? ~o - 1 : n ? o : o - 1;
if (s >= 0) {
const i = this.keys[s], l = this.values[s];
return r ? (r[0] = i, r[1] = l, r) : [i, l];
}
}
getPairOrNextHigher(e, t, n, r) {
const o = this.indexOf(e, -1, t), s = o < 0 ? ~o : n ? o : o + 1;
if (s < this.keys.length) {
const i = this.keys[s], l = this.values[s];
return r ? (r[0] = i, r[1] = l, r) : [i, l];
}
}
checkValid(e, t, n) {
const r = this.keys.length, o = this.values.length;
return Mt(this.values === lt ? r <= o : r === o, "keys/values length mismatch: depth", e, "with lengths", r, o, "and baseIndex", n), Mt(e === 0 || r > 0, "empty leaf at depth", e, "and baseIndex", n), r;
}
set(e, t, n, r) {
let o = this.indexOf(e, -1, r._compare);
if (o < 0) {
if (o = ~o, r._size++, this.keys.length < r._maxNodeSize) return this.insertInLeaf(o, e, t, n, r);
{
const s = this.splitOffRightSide();
let i = this;
return o > this.keys.length && (o -= this.keys.length, i = s), i.insertInLeaf(o, e, t, n, r), s;
}
}
if (n !== !1) {
t !== void 0 && this.reifyValues(), this.keys[o] = e;
let s = t;
if (typeof n == "function") {
const i = n(this.values[o], e, t);
i !== void 0 && (s = i);
}
this.values[o] = s;
}
return !1;
}
reifyValues() {
return this.values === lt ? this.values = this.values.slice(0, this.keys.length) : this.values;
}
insertInLeaf(e, t, n, r, o) {
if (this.keys.splice(e, 0, t), this.values === lt) {
for (; lt.length < o._maxNodeSize; ) lt.push(void 0);
if (n === void 0) return !0;
this.values = lt.slice(0, this.keys.length - 1);
}
let s = n;
if (typeof r == "function") {
const i = r(void 0, t, n);
i !== void 0 && (s = i);
}
return this.values.splice(e, 0, s), !0;
}
takeFromRight(e) {
let t = this.values;
e.values === lt ? t !== lt && t.push(void 0) : (t = this.reifyValues(), t.push(e.values.shift())), this.keys.push(e.keys.shift());
}
takeFromLeft(e) {
let t = this.values;
e.values === lt ? t !== lt && t.unshift(void 0) : (t = this.reifyValues(), t.unshift(e.values.pop())), this.keys.unshift(e.keys.pop());
}
splitOffRightSide() {
const e = this.keys.length >> 1, t = this.keys.splice(e), n = this.values === lt ? lt : this.values.splice(e);
return new $o(t, n);
}
forRange(e, t, n, r, o, s, i) {
const l = o._compare;
let c, h;
if (t === e) {
if (!n || (h = (c = this.indexOf(e, -1, l)) + 1, c < 0)) return s;
} else c = this.indexOf(e, 0, l), h = this.indexOf(t, -1, l), h < 0 ? h = ~h : n === !0 && h++;
const u = this.keys, d = this.values;
if (i !== void 0) for (let g = c; g < h; g++) {
const m = u[g], f = i(m, d[g], s++);
if (f !== void 0) {
if (f.break !== void 0) return f;
if (r === !0) {
if (m !== u[g] && o._compare(m, u[g]) !== 0 || this.isShared === !0) throw new Error("SortedMap: illegally changed or cloned in editRange.");
f.delete ? (this.keys.splice(g, 1), this.values !== lt && this.values.splice(g, 1), o._size--, g--, h--) : f.hasOwnProperty("value") && (d[g] = f.value);
}
}
}
else s += h - c;
return s;
}
mergeSibling(e, t) {
if (this.keys.push.apply(this.keys, e.keys), this.values === lt) {
if (e.values === lt) return;
this.values = this.values.slice(0, this.keys.length);
}
this.values.push.apply(this.values, e.reifyValues());
}
}
class Ho extends $o {
constructor(e, t) {
if (!t) {
t = [];
for (let n = 0; n < e.length; n++) t[n] = e[n].maxKey();
}
super(t), this.children = e;
}
clone() {
const e = this.children.slice(0);
for (let t = 0; t < e.length; t++) e[t].isShared = !0;
return new Ho(e, this.keys.slice(0));
}
greedyClone(e) {
if (this.isShared && !e) return this;
const t = new Ho(this.children.slice(0), this.keys.slice(0));
for (let n = 0; n < t.children.length; n++) t.children[n] = t.children[n].greedyClone(e);
return t;
}
minKey() {
return this.children[0].minKey();
}
minPair(e) {
return this.children[0].minPair(e);
}
maxPair(e) {
return this.children[this.children.length - 1].maxPair(e);
}
get(e, t, n) {
const r = this.indexOf(e, 0, n._compare), o = this.children;
return r < o.length ? o[r].get(e, t, n) : void 0;
}
getPairOrNextLower(e, t, n, r) {
const o = this.indexOf(e, 0, t), s = this.children;
if (o >= s.length) return this.maxPair(r);
const i = s[o].getPairOrNextLower(e, t, n, r);
return i === void 0 && o > 0 ? s[o - 1].maxPair(r) : i;
}
getPairOrNextHigher(e, t, n, r) {
const o = this.indexOf(e, 0, t), s = this.children, i = s.length;
if (o >= i) return;
const l = s[o].getPairOrNextHigher(e, t, n, r);
return l === void 0 && o < i - 1 ? s[o + 1].minPair(r) : l;
}
checkValid(e, t, n) {
const r = this.keys.length, o = this.children.length;
Mt(r === o, "keys/children length mismatch: depth", e, "lengths", r, o, "baseIndex", n), Mt(r > 1 || e > 0, "internal node has length", r, "at depth", e, "baseIndex", n);
let s = 0, i = this.children, l = this.keys, c = 0;
for (let u = 0; u < o; u++) s += i[u].checkValid(e + 1, t, n + s), c += i[u].keys.length, Mt(s >= c, "wtf", n), Mt(u === 0 || i[u - 1].constructor === i[u].constructor, "type mismatch, baseIndex:", n), i[u].maxKey() !== l[u] && Mt(!1, "keys[", u, "] =", l[u], "is wrong, should be ", i[u].maxKey(), "at depth", e, "baseIndex", n), u === 0 || t._compare(l[u - 1], l[u]) < 0 || Mt(!1, "sort violation at depth", e, "index", u, "keys", l[u - 1], l[u]);
const h = c === 0;
return (h || c > t.maxNodeSize * o) && Mt(!1, h ? "too few" : "too many", "children (", c, s, ") at depth", e, "maxNodeSize:", t.maxNodeSize, "children.length:", o, "baseIndex:", n), s;
}
set(e, t, n, r) {
const o = this.children, s = r._maxNodeSize, i = r._compare;
let l = Math.min(this.indexOf(e, 0, i), o.length - 1), c = o[l];
if (c.isShared && (o[l] = c = c.clone()), c.keys.length >= s) {
let u;
l > 0 && (u = o[l - 1]).keys.length < s && i(c.keys[0], e) < 0 ? (u.isShared && (o[l - 1] = u = u.clone()), u.takeFromRight(c), this.keys[l - 1] = u.maxKey()) : (u = o[l + 1]) !== void 0 && u.keys.length < s && i(c.maxKey(), e) < 0 && (u.isShared && (o[l + 1] = u = u.clone()), u.takeFromLeft(c), this.keys[l] = o[l].maxKey());
}
const h = c.set(e, t, n, r);
if (h === !1) return !1;
if (this.keys[l] = c.maxKey(), h === !0) return !0;
if (this.keys.length < s) return this.insert(l + 1, h), !0;
{
const u = this.splitOffRightSide();
let d = this;
return i(h.maxKey(), this.maxKey()) > 0 && (d = u, l -= this.keys.length), d.insert(l + 1, h), u;
}
}
insert(e, t) {
this.children.splice(e, 0, t), this.keys.splice(e, 0, t.maxKey());
}
splitOffRightSide() {
const e = this.children.length >> 1;
return new Ho(this.children.splice(e), this.keys.splice(e));
}
takeFromRight(e) {
this.keys.push(e.keys.shift()), this.children.push(e.children.shift());
}
takeFromLeft(e) {
this.keys.unshift(e.keys.pop()), this.children.unshift(e.children.pop());
}
forRange(e, t, n, r, o, s, i) {
const l = o._compare, c = this.keys, h = this.children;
let u = this.indexOf(e, 0, l), d = u, g = Math.min(t === e ? u : this.indexOf(t, 0, l), c.length - 1);
if (r) {
if (d <= g) try {
for (; d <= g; d++) {
h[d].isShared && (h[d] = h[d].clone());
const m = h[d].forRange(e, t, n, r, o, s, i);
if (c[d] = h[d].maxKey(), typeof m != "number") return m;
s = m;
}
} finally {
const m = o._maxNodeSize >> 1;
for (u > 0 && u--, d = g; d >= u; d--) h[d].keys.length <= m && (h[d].keys.length !== 0 ? this.tryMerge(d, o._maxNodeSize) : (c.splice(d, 1), h.splice(d, 1)));
h.length !== 0 && h[0].keys.length === 0 && Mt(!1, "emptiness bug");
}
} else for (; d <= g; d++) {
const m = h[d].forRange(e, t, n, r, o, s, i);
if (typeof m != "number") return m;
s = m;
}
return s;
}
tryMerge(e, t) {
const n = this.children;
return e >= 0 && e + 1 < n.length && n[e].keys.length + n[e + 1].keys.length <= t && (n[e].isShared && (n[e] = n[e].clone()), n[e].mergeSibling(n[e + 1], t), n.splice(e + 1, 1), this.keys.splice(e + 1, 1), this.keys[e] = n[e].maxKey(), !0);
}
mergeSibling(e, t) {
const n = this.keys.length;
this.keys.push.apply(this.keys, e.keys);
const r = e.children;
if (this.children.push.apply(this.children, r), e.isShared && !this.isShared) for (let o = 0; o < r.length; o++) r[o].isShared = !0;
this.tryMerge(n - 1, t);
}
}
const lt = [], Sl = Object.freeze({ done: !0, value: void 0 }), ia = function() {
const a = new $o();
return a.isShared = !0, a;
}(), Cc = [], Mt = (a, ...e) => {
if (!a) throw e.unshift("SortedMap:"), new Error(e.join(" "));
};
var kn;
(kn = Ae || (Ae = {})).DeleteValue = Object.freeze({ delete: !0 }), kn.Break = Object.freeze({ break: !0 }), kn.DeleteRange = () => kn.DeleteValue, kn.EmptySortedMap = (() => {
const a = new kn();
return a.freeze(), a;
})(), kn.defaultComparator = function(a, e) {
if (Number.isFinite(a) && Number.isFinite(e)) return a - e;
let t = typeof a, n = typeof e;
if (t !== n) return t < n ? -1 : 1;
if (t === "object") {
if (a === null) return e === null ? 0 : -1;
if (e === null) return 1;
if (t = typeof (a = a.valueOf()), n = typeof (e = e.valueOf()), t !== n) return t < n ? -1 : 1;
}
return a < e ? -1 : a > e ? 1 : a === e ? 0 : Number.isNaN(a) ? Number.isNaN(e) ? 0 : -1 : Number.isNaN(e) ? 1 : Array.isArray(a) ? 0 : Number.NaN;
}, kn.simpleComparator = function(a, e) {
return a > e ? 1 : a < e ? -1 : 0;
};
const bc = [-1, null], $m = { done: !1, value: [-1, null] };
var Oe;
((a) => {
a.Builder = class {
constructor(t, n = 0, r = 0) {
this._tuples = [], this._minors = null, this._values = null, this._minorMin = Number.MAX_SAFE_INTEGER, this._minorMax = 0, this._majorIndex = Number.MIN_SAFE_INTEGER, this._minorIndex = Number.MIN_SAFE_INTEGER, this._offsetMajor = 0, this._offsetMinor = 0, this._createList = t, this._offsetMajor = n, this._offsetMinor = r;
}
addValues(t, n, r) {
if (r && r.isIList) return this.addValue(t, n, r);
Array.isArray(r) || (r = [r]), this.addValue(t, n, r[0]);
const o = r.length, s = this._values;
for (let i = 1; i < o; i++) s.push(r[i]);
return this._minorIndex = this._minorIndex + s.length - 1, this;
}
addValue(t, n, r) {
const o = this._majorIndex, s = this._minorIndex;
if (t += this._offsetMajor, n += this._offsetMinor, t < o || t === o && n <= s) throw new e(`major: ${t}, minor: ${n}, prevMajor: ${this._majorIndex}, prevMinor: ${this._minorIndex}`);
let i = this._minors;
if (t !== o) {
if (i) {
this._minorMin = Math.min(this._minorMin, i[0][0]);
const l = i[i.length - 1];
this._minorMax = Math.max(this._minorMax, l[0] + l[1].length - 1);
}
this._minors = i = [], this._tuples.push([t, i]), this._majorIndex = t;
}
if (r && r.isIList) {
n === s + 1 && o !== t && this._values;
const l = r;
i.push([n, l]), n = n + l.length - 1;
} else {
let l = null;
n !== s + 1 || o !== t ? (this._values = l = [], i.push([n, l])) : l = this._values, l.push(r);
}
return this._minorIndex = n, this;
}
build() {
const t = this._tuples;
if (t.length === 0) return null;
const n = this._minors;
this._minorMin = Math.min(this._minorMin, n[0][0]);
const r = n[n.length - 1];
this._minorMax = Math.max(this._minorMax, r[0] + r[1].length - 1);
const o = this._createList;
if (o) {
const s = n.length;
for (let i = 0; i < s; i++) n[i][1] = o(n[i][1]);
}
return { tuples: t, bounds: { majorStart: t[0][0], minorStart: this._minorMin, majorEnd: t[t.length - 1][0], minorEnd: this._minorMax } };
}
}, a.TransposedBuilder = class {
constructor(t, n = 0, r = 0) {
this._majorMin = Number.MAX_SAFE_INTEGER, this._majorMax = 0, this._majorIndex = Number.MIN_SAFE_INTEGER, this._minorIndex = Number.MIN_SAFE_INTEGER, this._offsetMajor = 0, this._offsetMinor = 0, this._createList = t, this._offsetMajor = n, this._offsetMinor = r, this._minors = new Ae();
}
addValues(t, n, r) {
Array.isArray(r) || (r = [r]);
const o = r.length;
for (let s = 0; s < o; s++) {
const i = n + s;
this.addValue(t, i, r[s]);
}
return this;
}
addValue(t, n, r) {
let o, s;
const i = this._majorIndex;
let l = this._minorIndex;
if (t += this._offsetMajor, n += this._offsetMinor, s = this._current, t !== i) {
if (this._majorIndex = t, t < i) throw new e(`major: ${t}, minor: ${n}, prevMajor: ${this._majorIndex}, prevMinor: ${this._minorIndex}`);
l = Number.MIN_SAFE_INTEGER;
} else if (s = this._current, n <= l) throw new e(`major: ${t}, minor: ${n}, prevMajor: ${this._majorIndex}, prevMinor: ${this._minorIndex}`);
if (s && s.minor === n && (o = s.span), o) s.minor >= n && s.next && (this._current = s.next);
else {
const g = this._minors, m = s ? s.next ?? s.prev : null;
if (m) {
let f;
const _ = m.minor;
m && m.minor === n ? (s = m, o = s.span) : f = _ > n ? g.getPairOrNextHigher(n, bc) : g.getPairOrNextLower(n, bc), f && (s = f[1], f[0] === n && (o = s.span));
}
if (!o) {
this._majorMin = Math.min(this._majorMin, t), o = [n, [[t, []]]];
const f = { minor: n, span: o, prev: null, next: null };
s && (s.minor < n ? (f.prev = s, f.next = s.next, s.next && (s.next.prev = f), s.next = f) : (f.prev = s.prev, f.next = s, s.prev && (s.prev.next = f), s.prev = f)), g.set(n, f), this._current = f;
const _ = this._first;
(!_ || n < _.minor) && (this._first = f), f.next && (this._current = f.next);
}
}
let c = o[1];
const h = c[c.length - 1];
let u = h[0], d = h[1];
return u + d.length !== t && (d = [], u = t, c.push([u, d])), d.push(r), this._majorMax = Math.max(this._majorMax, t), this._minorIndex = n, this;
}
build() {
const t = [], n = this._createList, r = this._minors.entries(void 0, $m);
let o = r.next();
for (; !o.done; ) {
const s = o.value[1].span;
if (n) for (let i = 0; i < s.length; i++) s[i][1] = this._createList(s[i][1]);
t.push(s), o = r.next();
}
return t.length === 0 ? null : { tuples: t, bounds: { majorStart: t[0][0], minorStart: this._majorMin, majorEnd: t[t.length - 1][0], minorEnd: this._majorMax } };
}
};
class e extends Om {
constructor(n = "Out of order", r = null) {
super(n, r), this.name = "OutOfOrderError";
}
}
a.OutOfOrderError = e;
})(Oe || (Oe = {}));
const Gm = { lessThanXSeconds: { one: "less than a second", other: "less than {{count}} seconds" }, xSeconds: { one: "1 second", other: "{{count}} seconds" }, halfAMinute: "half a minute", lessThanXMinutes: { one: "less than a minute", other: "less than {{count}} minutes" }, xMinutes: { one: "1 minute", other: "{{count}} minutes" }, aboutXHours: { one: "about 1 hour", other: "about {{count}} hours" }, xHours: { one: "1 hour", other: "{{count}} hours" }, xDays: { one: "1 day", other: "{{count}} days" }, aboutXWeeks: { one: "about 1 week", other: "about {{count}} weeks" }, xWeeks: { one: "1 week", other: "{{count}} weeks" }, aboutXMonths: { one: "about 1 month", other: "about {{count}} months" }, xMonths: { one: "1 month", other: "{{count}} months" }, aboutXYears: { one: "about 1 year", other: "about {{count}} years" }, xYears: { one: "1 year", other: "{{count}} years" }, overXYears: { one: "over 1 year", other: "over {{count}} years" }, almostXYears: { one: "almost 1 year", other: "almost {{count}} years" } };
function aa(a) {
return (e = {}) => {
const t = e.width ? String(e.width) : a.defaultWidth;
return a.formats[t] || a.formats[a.defaultWidth];
};
}
const Um = { date: aa({ formats: { full: "EEEE, MMMM do, y", long: "MMMM do, y", medium: "MMM d, y", short: "MM/dd/yyyy" }, defaultWidth: "full" }), time: aa({ formats: { full: "h:mm:ss a zzzz", long: "h:mm:ss a z", medium: "h:mm:ss a", short: "h:mm a" }, defaultWidth: "full" }), dateTime: aa({ formats: { full: "{{date}} 'at' {{time}}", long: "{{date}} 'at' {{time}}", medium: "{{date}}, {{time}}", short: "{{date}}, {{time}}" }, defaultWidth: "full" }) }, Jm = { lastWeek: "'last' eeee 'at' p", yesterday: "'yesterday at' p", today: "'today at' p", tomorrow: "'tomorrow at' p", nextWeek: "eeee 'at' p", other: "P" };
function io(a) {
return (e, t) => {
let n;
if ((t?.context ? String(t.context) : "standalone") === "formatting" && a.formattingValues) {
const r = a.defaultFormattingWidth || a.defaultWidth, o = t?.width ? String(t.width) : r;
n = a.formattingValues[o] || a.formattingValues[r];
} else {
const r = a.defaultWidth, o = t?.width ? String(t.width) : a.defaultWidth;
n = a.values[o] || a.values[r];
}
return n[a.argumentCallback ? a.argumentCallback(e) : e];
};
}
function ao(a) {
return (e, t = {}) => {
const n = t.width, r = n && a.matchPatterns[n] || a.matchPatterns[a.defaultMatchWidth], o = e.match(r);
if (!o) return null;
const s = o[0], i = n && a.parsePatterns[n] || a.parsePatterns[a.defaultParseWidth], l = Array.isArray(i) ? function(h, u) {
for (let d = 0; d < h.length; d++) if (u(h[d])) return d;
}(i, (h) => h.test(s)) : function(h, u) {
for (const d in h) if (Object.prototype.hasOwnProperty.call(h, d) && u(h[d])) return d;
}(i, (h) => h.test(s));
let c;
return c = a.valueCallback ? a.valueCallback(l) : l, c = t.valueCallback ? t.valueCallback(c) : c, { value: c, rest: e.slice(s.length) };
};
}
var lo;
const qm = { code: "en-US", formatDistance: (a, e, t) => {
let n;
const r = Gm[a];
return n = typeof r == "string" ? r : e === 1 ? r.one : r.other.replace("{{count}}", e.toString()), t?.addSuffix ? t.comparison && t.comparison > 0 ? "in " + n : n + " ago" : n;
}, formatLong: Um, formatRelative: (a, e, t, n) => Jm[a], localize: { ordinalNumber: (a, e) => {
const t = Number(a), n = t % 100;
if (n > 20 || n < 10) switch (n % 10) {
case 1:
return t + "st";
case 2:
return t + "nd";
case 3:
return t + "rd";
}
return t + "th";
}, era: io({ values: { narrow: ["B", "A"], abbreviated: ["BC", "AD"], wide: ["Before Christ", "Anno Domini"] }, defaultWidth: "wide" }), quarter: io({ values: { narrow: ["1", "2", "3", "4"], abbreviated: ["Q1", "Q2", "Q3", "Q4"], wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"] }, defaultWidth: "wide", argumentCallback: (a) => a - 1 }), month: io({ values: { narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"], abbreviated: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], wide: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] }, defaultWidth: "wide" }), day: io({ values: { narrow: ["S", "M", "T", "W", "T", "F", "S"], short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], wide: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] }, defaultWidth: "wide" }), dayPeriod: io({ values: { narrow: { am: "a", pm: "p", midnight: "mi", noon: "n", morning: "morning", afternoon: "afternoon", evening: "evening", night: "night" }, abbreviated: { am: "AM", pm: "PM", midnight: "midnight", noon: "noon", morning: "morning", afternoon: "afternoon", evening: "evening", night: "night" }, wide: { am: "a.m.", pm: "p.m.", midnight: "midnight", noon: "noon", morning: "morning", afternoon: "afternoon", evening: "evening", night: "night" } }, defaultWidth: "wide", formattingValues: { narrow: { am: "a", pm: "p", midnight: "mi", noon: "n", morning: "in the morning", afternoon: "in the afternoon", evening: "in the evening", night: "at night" }, abbreviated: { am: "AM", pm: "PM", midnight: "midnight", noon: "noon", morning: "in the morning", afternoon: "in the afternoon", evening: "in the evening", night: "at night" }, wide: { am: "a.m.", pm: "p.m.", midnight: "midnight", noon: "noon", morning: "in the morning", afternoon: "in the afternoon", evening: "in the evening", night: "at night" } }, defaultFormattingWidth: "wide" }) }, match: { ordinalNumber: (lo = { matchPattern: /^(\d+)(th|st|nd|rd)?/i, parsePattern: /\d+/i, valueCallback: (a) => parseInt(a, 10) }, (a, e = {}) => {
const t = a.match(lo.matchPattern);
if (!t) return null;
const n = t[0], r = a.match(lo.parsePattern);
if (!r) return null;
let o = lo.valueCallback ? lo.valueCallback(r[0]) : r[0];
return o = e.valueCallback ? e.valueCallback(o) : o, { value: o, rest: a.slice(n.length) };
}), era: ao({ matchPatterns: { narrow: /^(b|a)/i, abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i, wide: /^(before christ|before common era|anno domini|common era)/i }, defaultMatchWidth: "wide", parsePatterns: { any: [/^b/i, /^(a|c)/i] }, defaultParseWidth: "any" }), quarter: ao({ matchPatterns: { narrow: /^[1234]/i, abbreviated: /^q[1234]/i, wide: /^[1234](th|st|nd|rd)? quarter/i }, defaultMatchWidth: "wide", parsePatterns: { any: [/1/i, /2/i, /3/i, /4/i] }, defaultParseWidth: "any", valueCallback: (a) => a + 1 }), month: ao({ matchPatterns: { narrow: /^[jfmasond]/i, abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i, wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i }, defaultMatchWidth: "wide", parsePatterns: { narrow: [/^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i], any: [/^ja/i, /^f/i, /^mar/i, /^ap/i, /^may/i, /^jun/i, /^jul/i, /^au/i, /^s/i, /^o/i, /^n/i, /^d/i] }, defaultParseWidth: "any" }), day: ao({ matchPatterns: { narrow: /^[smtwf]/i, short: /^(su|mo|tu|we|th|fr|sa)/i, abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i, wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i }, defaultMatchWidth: "wide", parsePatterns: { narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i], any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i] }, defaultParseWidth: "any" }), dayPeriod: ao({ matchPatterns: { narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i, any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i }, defaultMatchWidth: "any", parsePatterns: { any: { am: /^a/i, pm: /^p/i, midnight: /^mi/i, noon: /^no/i, morning: /morning/i, afternoon: /afternoon/i, evening: /evening/i, night: /night/i } }, defaultParseWidth: "any" }) }, options: { weekStartsOn: 0, firstWeekContainsDate: 1 } }, vc = (a, e) => {
switch (a) {
case "P":
return e.date({ width: "short" });
case "PP":
return e.date({ width: "medium" });
case "PPP":
return e.date({ width: "long" });
default:
return e.date({ width: "full" });
}
}, xc = (a, e) => {
switch (a) {
case "p":
return e.time({ width: "short" });
case "pp":
return e.time({ width: "medium" });
case "ppp":
return e.time({ width: "long" });
default:
return e.time({ width: "full" });
}
}, Ic = { p: xc, P: (a, e) => {
const t = a.match(/(P+)(p+)?/) || [], n = t[1], r = t[2];
if (!r) return vc(a, e);
let o;
switch (n) {
case "P":
o = e.dateTime({ width: "short" });
break;
case "PP":
o = e.dateTime({ width: "medium" });
break;
case "PPP":
o = e.dateTime({ width: "long" });
break;
default:
o = e.dateTime({ width: "full" });
}
return o.replace("{{date}}", vc(n, e)).replace("{{time}}", xc(r, e));
} }, Km = /^D+$/, Xm = /^Y+$/, Ym = ["D", "DD", "YY", "YYYY"];
function Qm(a) {
return Km.test(a);
}
function Zm(a) {
return Xm.test(a);
}
function Rc(a, e, t) {
const n = function(r, o, s) {
const i = r[0] === "Y" ? "years" : "days of the month";
return `Use \`${r.toLowerCase()}\` instead of \`${r}\` (in \`${o}\`) for formatting ${i} to the input \`${s}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
}(a, e, t);
if (console.warn(n), Ym.includes(a)) throw new RangeError(n);
}
const Ac = Symbol.for("constructDateFrom");
function Wr(a, e) {
return typeof a == "function" ? a(e) : a && typeof a == "object" && Ac in a ? a[Ac](e) : a instanceof Date ? new a.constructor(e) : new Date(e);
}
let ef = {};
function Pd() {
return ef;
}
function wi(a, e) {
return Wr(e || a, a);
}
class Hd {
constructor() {
this.subPriority = 0;
}
validate(e, t) {
return !0;
}
}
class tf extends Hd {
constructor(e, t, n, r, o) {
super(), this.value = e, this.validateValue = t, this.setValue = n, this.priority = r, o && (this.subPriority = o);
}
validate(e, t) {
return this.validateValue(e, this.value, t);
}
set(e, t, n) {
return this.setValue(e, t, this.value, n);
}
}
class nf extends Hd {
constructor(e, t) {
super(), this.priority = 10, this.subPriority = -1, this.context = e || ((n) => Wr(t, n));
}
set(e, t) {
return t.timestampIsSet ? e : Wr(e, function(n, r) {
const o = function(s) {
return typeof s == "function" && s.prototype?.constructor === s;
}(r) ? new r(0) : Wr(r, 0);
return o.setFullYear(n.getFullYear(), n.getMonth(), n.getDate()), o.setHours(n.getHours(), n.getMinutes(), n.getSeconds(), n.getMilliseconds()), o;
}(e, this.context));
}
}
let Vs = class {
run(a, e, t, n) {
const r = this.parse(a, e, t, n);
return r ? { setter: new tf(r.value, this.validate, this.set, this.priority, this.subPriority), rest: r.rest } : null;
}
validate(a, e, t) {
return !0;
}
};
const Wd = /^(1[0-2]|0?\d)/, rf = /^(3[0-1]|[0-2]?\d)/, of = /^\d/, sf = /^\d{1,2}/, af = /^\d{1,3}/, lf = /^\d{1,4}/;
function vn(a, e) {
return a && { value: e(a.value), rest: a.rest };
}
function Vn(a, e) {
const t = e.match(a);
return t ? { value: parseInt(t[0], 10), rest: e.slice(t[0].length) } : null;
}
function Wo(a, e) {
switch (a) {
case 1:
return Vn(of, e);
case 2:
return Vn(sf, e);
case 3:
return Vn(af, e);
case 4:
return Vn(lf, e);
default:
return Vn(new RegExp("^\\d{1," + a + "}"), e);
}
}
class jd extends Vs {
constructor() {
super(...arguments), this.incompatibleTokens = ["Y", "R", "q", "Q", "L", "w", "I", "D", "i", "e", "c", "t", "T"], this.priority = 110;
}
parse(e, t, n) {
const r = (o) => o - 1;
switch (t) {
case "M":
return vn(Vn(Wd, e), r);
case "MM":
return vn(Wo(2, e), r);
case "Mo":
return vn(n.ordinalNumber(e, { unit: "month" }), r);
case "MMM":
return n.month(e, { width: "abbreviated", context: "formatting" }) || n.month(e, { width: "narrow", context: "formatting" });
case "MMMMM":
return n.month(e, { width: "narrow", context: "formatting" });
default:
return n.month(e, { width: "wide", context: "formatting" }) || n.month(e, { width: "abbreviated", context: "formatting" }) || n.month(e, { width: "narrow", context: "formatting" });
}
}
validate(e, t) {
return t >= 0 && t <= 11;
}
set(e, t, n) {
return e.setMonth(n, 1), e.setHours(0, 0, 0, 0), e;
}
}
const cf = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], hf = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
function uf(a, e, t) {
const n = Pd(), r = t?.weekStartsOn ?? t?.locale?.options?.weekStartsOn ?? n.weekStartsOn ?? n.locale?.options?.weekStartsOn ?? 0, o = wi(a, t?.in), s = o.getDay(), i = 7 - r;
return function(l, c, h) {
const u = wi(l, h?.in);
return isNaN(c) ? Wr(h?.in || l, NaN) : (c && u.setDate(u.getDate() + c), u);
}(o, e < 0 || e > 6 ? e - (s + i) % 7 : ((e % 7 + 7) % 7 + i) % 7 - (s + i) % 7, t);
}
const Ao = { y: new class extends Vs {
constructor() {
super(...arguments), this.priority = 130, this.incompatibleTokens = ["Y", "R", "u", "w", "I", "i", "e", "c", "t", "T"];
}
parse(a, e, t) {
const n = (r) => ({ year: r, isTwoDigitYear: e === "yy" });
switch (e) {
case "y":
return vn(Wo(4, a), n);
case "yo":
return vn(t.ordinalNumber(a, { unit: "year" }), n);
default:
return vn(Wo(e.length, a), n);
}
}
validate(a, e) {
return e.isTwoDigitYear || e.year > 0;
}
set(a, e, t) {
const n = a.getFullYear();
if (t.isTwoDigitYear) {
const o = function(s, i) {
const l = i > 0, c = l ? i : 1 - i;
let h;
if (c <= 50) h = s || 100;
else {
const u = c + 50;
h = s + 100 * Math.trunc(u / 100) - (s >= u % 100 ? 100 : 0);
}
return l ? h : 1 - h;
}(t.year, n);
return a.setFullYear(o, 0, 1), a.setHours(0, 0, 0, 0), a;
}
const r = "era" in e && e.era !== 1 ? 1 - t.year : t.year;
return a.setFullYear(r, 0, 1), a.setHours(0, 0, 0, 0), a;
}
}(), M: new jd(), d: new class extends Vs {
constructor() {
super(...arguments), this.priority = 90, this.subPriority = 1, this.incompatibleTokens = ["Y", "R", "q", "Q", "w", "I", "D", "i", "e", "c", "t", "T"];
}
parse(a, e, t) {
switch (e) {
case "d":
return Vn(rf, a);
case "do":
return t.ordinalNumber(a, { unit: "date" });
default:
return Wo(e.length, a);
}
}
validate(a, e) {
const t = function(r) {
return r % 400 == 0 || r % 4 == 0 && r % 100 != 0;
}(a.getFullYear()), n = a.getMonth();
return t ? e >= 1 && e <= hf[n] : e >= 1 && e <= cf[n];
}
set(a, e, t) {
return a.setDate(t), a.setHours(0, 0, 0, 0), a;
}
}(), E: new class extends Vs {
constructor() {
super(...arguments), this.priority = 90, this.incompatibleTokens = ["D", "i", "e", "c", "t", "T"];
}
parse(a, e, t) {
switch (e) {
case "E":
case "EE":
case "EEE":
return t.day(a, { width: "abbreviated", context: "formatting" }) || t.day(a, { width: "short", context: "formatting" }) || t.day(a, { width: "narrow", context: "formatting" });
case "EEEEE":
return t.day(a, { width: "narrow", context: "formatting" });
case "EEEEEE":
return t.day(a, { width: "short", context: "formatting" }) || t.day(a, { width: "narrow", context: "formatting" });
default:
return t.day(a, { width: "wide", context: "formatting" }) || t.day(a, { width: "abbreviated", context: "formatting" }) || t.day(a, { width: "short", context: "formatting" }) || t.day(a, { width: "narrow", context: "formatting" });
}
}
validate(a, e) {
return e >= 0 && e <= 6;
}
set(a, e, t, n) {
return (a = uf(a, t, n)).setHours(0, 0, 0, 0), a;
}
}() }, df = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g, gf = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g, mf = /^'([^]*?)'?$/, ff = /''/g, pf = /\S/, _f = /[a-zA-Z]/;
function Sf(a, e, t, n) {
const r = () => Wr(n?.in || t, NaN), o = Object.assign({}, Pd()), s = n?.locale ?? o.locale ?? qm, i = n?.firstWeekContainsDate ?? n?.locale?.options?.firstWeekContainsDate ?? o.firstWeekContainsDate ?? o.locale?.options?.firstWeekContainsDate ?? 1, l = n?.weekStartsOn ?? n?.locale?.options?.weekStartsOn ?? o.weekStartsOn ?? o.locale?.options?.weekStartsOn ?? 0;
if (!e) return a ? r() : wi(t, n?.in);
const c = { firstWeekContainsDate: i, weekStartsOn: l, locale: s }, h = [new nf(n?.in, t)], u = e.match(gf).map((_) => {
const p = _[0];
return p in Ic ? (0, Ic[p])(_, s.formatLong) : _;
}).join("").match(df), d = [];
for (let _ of u) {
!n?.useAdditionalWeekYearTokens && Zm(_) && Rc(_, e, a), !n?.useAdditionalDayOfYearTokens && Qm(_) && Rc(_, e, a);
const p = _[0], S = Ao[p];
if (S) {
const { incompatibleTokens: E } = S;
if (Array.isArray(E)) {
const C = d.find((w) => E.includes(w.token) || w.token === p);
if (C) throw new RangeError(`The format string mustn't contain \`${C.fullToken}\` and \`${_}\` at the same time`);
} else if (S.incompatibleTokens === "*" && d.length > 0) throw new RangeError(`The format string mustn't contain \`${_}\` and any other token at the same time`);
d.push({ token: p, fullToken: _ });
const y = S.run(a, _, s.match, c);
if (!y) return r();
h.push(y.setter), a = y.rest;
} else {
if (p.match(_f)) throw new RangeError("Format string contains an unescaped latin alphabet character `" + p + "`");
if (_ === "''" ? _ = "'" : p === "'" && (_ = wf(_)), a.indexOf(_) !== 0) return r();
a = a.slice(_.length);
}
}
if (a.length > 0 && pf.test(a)) return r();
const g = h.map((_) => _.priority).sort((_, p) => p - _).filter((_, p, S) => S.indexOf(_) === p).map((_) => h.filter((p) => p.priority === _).sort((p, S) => S.subPriority - p.subPriority)).map((_) => _[0]);
let m = wi(t, n?.in);
if (isNaN(+m)) return r();
const f = {};
for (const _ of g) {
if (!_.validate(m, c)) return r();
const p = _.set(m, f, c);
Array.isArray(p) ? (m = p[0], Object.assign(f, p[1])) : m = p;
}
return m;
}
function wf(a) {
return a.match(mf)[1].replace(ff, "'");
}
const Vd = (a) => !isNaN(a) && (Object.prototype.toString.call(a) === "[object Date]" || a instanceof Date);
function Mc(a, e, t) {
let n = a, r = a.length, o = e.length;
for (var s = r; s < o; ++s) {
const i = e[s];
if (i === "#") return n;
n = t ? n + i : i + n;
}
return n;
}
function Ft(a, e) {
for (var t = ""; t.length < e; ) t += a;
return t;
}
function jr(a) {
for (var e = "", t = a.length - 1; t >= 0; ) e += a.charAt(t--);
return e;
}
function Wt(a, e) {
var t = "" + a;
return t.length >= e ? t : Ft("0", e - t.length) + t;
}
function wl(a, e) {
var t = "" + a;
return t.length >= e ? t : Ft(" ", e - t.length) + t;
}
function yi(a, e) {
var t = "" + a;
return t.length >= e ? t : t + Ft(" ", e - t.length);
}
var Tc = Math.pow(2, 32);
function br(a, e) {
return a > Tc || a < -Tc ? function(t, n) {
var r = "" + Math.round(t);
return r.length >= n ? r : Ft("0", n - r.length) + r;
}(a, e) : function(t, n) {
var r = "" + t;
return r.length >= n ? r : Ft("0", n - r.length) + r;
}(Math.round(a), e);
}
function $s(a, e) {
return e = e || 0, a.length >= 7 + e && (32 | a.charCodeAt(e)) == 103 && (32 | a.charCodeAt(e + 1)) == 101 && (32 | a.charCodeAt(e + 2)) == 110 && (32 | a.charCodeAt(e + 3)) == 101 && (32 | a.charCodeAt(e + 4)) == 114 && (32 | a.charCodeAt(e + 5)) == 97 && (32 | a.charCodeAt(e + 6)) == 108;
}
var Nc = [["Sun", "Sunday"], ["Mon", "Monday"], ["Tue", "Tuesday"], ["Wed", "Wednesday"], ["Thu", "Thursday"], ["Fri", "Friday"], ["Sat", "Saturday"]], la = [["J", "Jan", "January"], ["F", "Feb", "February"], ["M", "Mar", "March"], ["A", "Apr", "April"], ["M", "May", "May"], ["J", "Jun", "June"], ["J", "Jul", "July"], ["A", "Aug", "August"], ["S", "Sep", "September"], ["O", "Oct", "October"], ["N", "Nov", "November"], ["D", "Dec", "December"]], cr = { 0: "General", 1: "0", 2: "0.00", 3: "#,##0", 4: "#,##0.00", 5: "$#,##0_);($#,##0)", 6: "$#,##0_);[Red]($#,##0)", 7: "$#,##0.00_);($#,##0.00)", 8: "$#,##0.00_);[Red]($#,##0.00)", 9: "0%", 10: "0.00%", 11: "0.00E+00", 12: "# ?/?", 13: "# ??/??", 14: "m/d/yy", 15: "d-mmm-yy", 16: "d-mmm", 17: "mmm-yy", 18: "h:mm AM/PM", 19: "h:mm:ss AM/PM", 20: "h:mm", 21: "h:mm:ss", 22: "m/d/yy h:mm", 23: "General", 24: "General", 25: "General", 26: "General", 27: "m/d/yyyy", 28: "m/d/yyyy", 29: "m/d/yyyy", 30: "m/d/yyyy", 32: "h:mm:ss", 31: "m/d/yyyy", 33: "h:mm:ss", 34: "h:mm:ss", 35: "h:mm:ss", 36: "m/d/yyyy", 37: "#,##0_);(#,##0)", 38: "#,##0_);[Red](#,##0)", 39: "#,##0.00_);(#,##0.00)", 40: "#,##0.00_);[Red](#,##0.00)", 41: '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)', 42: '_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)', 43: '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)', 44: '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)', 45: "mm:ss", 46: "[h]:mm:ss", 47: "mmss.0", 48: "##0.0E+0", 49: "@", 50: "m/d/yyyy", 51: "m/d/yyyy", 52: "m/d/yyyy", 53: "m/d/yyyy", 54: "m/d/yyyy", 55: "m/d/yyyy", 56: '"上午/下午 "hh"時"mm"分"ss"秒 "' }, Fc = { 5: 37, 6: 38, 7: 39, 8: 40, 23: 0, 24: 0, 25: 0, 26: 0, 27: 14, 28: 14, 29: 14, 30: 14, 31: 14, 50: 14, 51: 14, 52: 14, 53: 14, 54: 14, 55: 14, 56: 14, 57: 14, 58: 14, 59: 1, 60: 2, 61: 3, 62: 4, 67: 9, 68: 10, 69: 12, 70: 13, 71: 14, 72: 14, 73: 15, 74: 16, 75: 17, 76: 20, 77: 21, 78: 22, 79: 45, 80: 46, 81: 47, 82: 0 }, yf = { 5: '"$"#,##0_);\\("$"#,##0\\)', 63: '"$"#,##0_);\\("$"#,##0\\)', 6: '"$"#,##0_);[Red]\\("$"#,##0\\)', 64: '"$"#,##0_);[Red]\\("$"#,##0\\)', 7: '"$"#,##0.00_);\\("$"#,##0.00\\)', 65: '"$"#,##0.00_);\\("$"#,##0.00\\)', 8: '"$"#,##0.00_);[Red]\\("$"#,##0.00\\)', 66: '"$"#,##0.00_);[Red]\\("$"#,##0.00\\)', 41: '_(* #,##0_);_(* \\(#,##0\\);_(* "-"_);_(@_)', 42: '_("$"* #,##0_);_("$"* \\(#,##0\\);_("$"* "-"_);_(@_)', 43: '_(* #,##0.00_);_(* \\(#,##0.00\\);_(* "-"??_);_(@_)', 44: '_("$"* #,##0.00_);_("$"* \\(#,##0.00\\);_("$"* "-"??_);_(@_)' };
function Ei(a, e, t) {
for (var n = a < 0 ? -1 : 1, r = a * n, o = 0, s = 1, i = 0, l = 1, c = 0, h = 0, u = Math.floor(r); c < e && (i = (u = Math.floor(r)) * s + o, h = u * c + l, !(r - u < 5e-8)); ) r = 1 / (r - u), o = s, s = i, l = c, c = h;
if (h > e && (c > e ? (h = l, i = o) : (h = c, i = s)), !t) return [0, n * i, h];
var d = Math.floor(n * i / h);
return [d, n * i - d * h, h];
}
function Mo(a, e, t) {
if (a > 2958465 || a < 0) return null;
var n = 0 | a, r = Math.floor(86400 * (a - n)), o = 0, s = [], i = { D: n, T: r, u: 86400 * (a - n) - r, y: 0, m: 0, d: 0, H: 0, M: 0, S: 0, q: 0 };
if (Math.abs(i.u) < 1e-6 && (i.u = 0), e && e.date1904 && (n += 1462), i.u > 0.9999 && (i.u = 0, ++r === 86400 && (i.T = r = 0, ++n, ++i.D)), n === 60) s = t ? [1317, 10, 29] : [1900, 2, 29], o = 3;
else if (n === 0) s = t ? [1317, 8, 29] : [1900, 1, 0], o = 6;
else {
n > 60 && --n;
var l = new Date(1900, 0, 1);
l.setDate(l.getDate() + n - 1), s = [l.getFullYear(), l.getMonth() + 1, l.getDate()], o = l.getDay(), n < 60 && (o = (o + 6) % 7), t && (o = function(c, h) {
h[0] -= 581;
var u = c.getDay();
return c < 60 && (u = (u + 6) % 7), u;
}(l, s));
}
return i.y = s[0], i.m = s[1], i.d = s[2], i.S = r % 60, r = Math.floor(r / 60), i.M = r % 60, r = Math.floor(r / 60), i.H = r, i.q = o, i;
}
var $d = new Date(1899, 11, 31, 0, 0, 0), Ef = $d.getTime(), Cf = new Date(1900, 2, 1, 0, 0, 0);
function ql(a, e = !1) {
var t = a.getTime();
return e ? t -= 1262304e5 : a >= Cf && (t += 864e5), (t - (Ef + 6e4 * (a.getTimezoneOffset() - $d.getTimezoneOffset()))) / 864e5;
}
function ca(a) {
return a.indexOf(".") === -1 ? a : a.replace(/(?:\.0*|(\.\d*[1-9])0+)$/, "$1");
}
function bf(a) {
var e, t = Math.floor(Math.log(Math.abs(a)) * Math.LOG10E);
return e = t >= -4 && t <= -1 ? a.toPrecision(10 + t) : Math.abs(t) <= 9 ? function(n) {
var r = n < 0 ? 12 : 11, o = ca(n.toFixed(12));
return o.length <= r || (o = n.toPrecision(10)).length <= r ? o : n.toExponential(5);
}(a) : t === 10 ? a.toFixed(10).substr(0, 12) : function(n) {
var r = ca(n.toFixed(11));
return r.length > (n < 0 ? 12 : 11) || r === "0" || r === "-0" ? n.toPrecision(6) : r;
}(a), ca(function(n) {
return n.indexOf("E") === -1 ? n : n.replace(/(?:\.0*|(\.\d*[1-9])0+)[Ee]/, "$1E").replace(/(E[+-])(\d)$/, "$10$2");
}(e.toUpperCase()));
}
function ha(a, e) {
switch (typeof a) {
case "string":
return a;
case "boolean":
return a ? "TRUE" : "FALSE";
case "number":
return (0 | a) === a ? a.toString(10) : bf(a);
case "undefined":
return "";
case "object":
if (a == null) return "";
if (Vd(a)) return tg(14, ql(a, e && e.date1904), e);
}
throw new Error("unsupported value in General format: " + a);
}
function vf(a, e, t, n) {
var r, o = "", s = 0, i = 0, l = t.y, c = 0;
switch (a) {
case 98:
l = t.y + 543;
case 121:
switch (e.length) {
case 1:
case 2:
r = l % 100, c = 2;
break;
default:
r = l % 1e4, c = 4;
}
break;
case 109:
switch (e.length) {
case 1:
case 2:
r = t.m, c = e.length;
break;
case 3:
return la[t.m - 1][1];
case 5:
return la[t.m - 1][0];
default:
return la[t.m - 1][2];
}
break;
case 100:
switch (e.length) {
case 1:
case 2:
r = t.d, c = e.length;
break;
case 3:
return Nc[t.q][0];
default:
return Nc[t.q][1];
}
break;
case 104:
switch (e.length) {
case 1:
case 2:
r = 1 + (t.H + 11) % 12, c = e.length;
break;
default:
throw new Error("bad hour format: " + e);
}
break;
case 72:
switch (e.length) {
case 1:
case 2:
r = t.H, c = e.length;
break;
default:
throw new Error("bad hour format: " + e);
}
break;
case 77:
switch (e.length) {
case 1:
case 2:
r = t.M, c = e.length;
break;
default:
throw new Error("bad minute format: " + e);
}
break;
case 115:
if (e !== "s" && e !== "ss" && e !== ".0" && e !== ".00" && e !== ".000") throw new Error("bad second format: " + e);
return t.u !== 0 || e !== "s" && e !== "ss" ? (i = n >= 2 ? n === 3 ? 1e3 : 100 : n === 1 ? 10 : 1, (s = Math.round(i * (t.S + t.u))) >= 60 * i && (s = 0), e === "s" ? s === 0 ? "0" : "" + s / i : (o = Wt(s, 2 + n), e === "ss" ? o.substr(0, 2) : "." + o.substr(2, e.length - 1))) : Wt(t.S, e.length);
case 90:
switch (e) {
case "[h]":
case "[hh]":
r = 24 * t.D + t.H;
break;
case "[m]":
case "[mm]":
r = 60 * (24 * t.D + t.H) + t.M;
break;
case "[s]":
case "[ss]":
r = 60 * (60 * (24 * t.D + t.H) + t.M) + Math.round(t.S + t.u);
break;
default:
throw new Error("bad absolute time format: " + e);
}
c = e.length === 3 ? 1 : 2;
break;
case 101:
r = l, c = 1;
}
return c > 0 ? Wt(r, c) : "";
}
function $n(a) {
if (a.length <= 3) return a;
for (var e = a.length % 3, t = a.substr(0, e); e !== a.length; e += 3) t += (t.length > 0 ? "," : "") + a.substr(e, 3);
return t;
}
var Gd = /%/g;
function Ud(a, e) {
var t, n = a.indexOf("E") - a.indexOf(".") - 1;
if (a.match(/^#+0.0E\+0$/)) {
if (e === 0) return "0.0E+0";
if (e < 0) return "-" + Ud(a, -e);
var r = a.indexOf(".");
r === -1 && (r = a.indexOf("E"));
var o = Math.floor(Math.log(e) * Math.LOG10E) % r;
if (o < 0 && (o += r), (t = (e / Math.pow(10, o)).toPrecision(n + 1 + (r + o) % r)).indexOf("e") === -1) {
var s = Math.floor(Math.log(e) * Math.LOG10E);
for (t.indexOf(".") === -1 ? t = t.charAt(0) + "." + t.substr(1) + "E+" + (s - t.length + o) : t += "E+" + (s - o); t.substr(0, 2) === "0."; ) t = (t = t.charAt(0) + t.substr(2, r) + "." + t.substr(2 + r)).replace(/^0+([1-9])/, "$1").replace(/^0+\./, "0.");
t = t.replace(/\+-/, "-");
}
t = t.replace(/^([+-]?)(\d*)\.(\d*)[Ee]/, function(i, l, c, h) {
return l + c + h.substr(0, (r + o) % r) + "." + h.substr(o) + "E";
});
} else t = e.toExponential(n);
return a.match(/E\+00$/) && t.match(/e[+-]\d$/) && (t = t.substr(0, t.length - 1) + "0" + t.charAt(t.length - 1)), a.match(/E-/) && t.match(/e\+/) && (t = t.replace(/e\+/, "e")), t.replace("e", "E");
}
var Jd = /[0#?] (\?+)( ?)\/( ?)(\d+)/, qd = /^([0#?]+)\.([0#?]+)/, Kd = /\).*[0#]/, Xd = /\(###\) ###\\?-####/;
function zt(a) {
var e = "";
let t, n = a.length;
for (var r = 0; r !== n; ++r) switch (t = a.charAt(r), t) {
case "#":
break;
case " ":
e += " ";
break;
case "0":
e += "0";
break;
case "?":
e += "?";
break;
default:
e += String.fromCharCode(cc);
}
return e;
}
function kc(a, e) {
var t = Math.pow(10, e);
return "" + Math.round(a * t) / t;
}
function Oc(a, e) {
var t = Math.pow(10, e);
return Math.round(a * t) / t;
}
function Dc(a, e) {
var t = a - Math.floor(a), n = Math.pow(10, e);
return e < ("" + Math.round(t * n)).length ? 0 : Math.round(t * n);
}
function Rt(a, e, t) {
if (a.charCodeAt(0) === 40 && !e.match(Kd)) {
var n = e.replace(/\( */, "").replace(/ \)/, "").replace(/\)/, "");
return t >= 0 ? Rt("n", n, t) : "(" + Rt("n", n, -t) + ")";
}
if (e.charCodeAt(e.length - 1) === 44) return function(f, _, p) {
let S = _.length - 1;
for (; _.charCodeAt(S - 1) === 44; ) --S;
return xn(f, _.substr(0, S), p / Math.pow(10, 3 * (_.length - S)));
}(a, e, t);
if (e.indexOf("%") !== -1) return function(f, _, p) {
let S = _.replace(Gd, ""), E = _.length - S.length;
return xn(f, S, p * Math.pow(10, 2 * E)) + Ft("%", E);
}(a, e, t);
if (e.indexOf("E") !== -1) return Ud(e, t);
if (e.charCodeAt(0) === 36) return "$" + Rt(a, e.substr(e.charAt(1) === " " ? 2 : 1), t);
var r, o, s, i, l = Math.abs(t), c = t < 0 ? "-" : "";
if (e.match(/^00+$/)) return c + br(l, e.length);
if (e.match(/^[#?]+$/)) return (r = br(t, 0)) === "0" && (r = ""), r.length > e.length ? r : zt(e.substr(0, e.length - r.length)) + r;
if (o = e.match(Jd)) return function(f, _, p) {
var S = parseInt(f[4], 10), E = Math.round(_ * S), y = Math.floor(E / S), C = E - y * S, w = S;
return p + (y === 0 ? "" : "" + y) + " " + (C === 0 ? Ft(" ", f[1].length + 1 + f[4].length) : wl(C, f[1].length) + f[2] + "/" + f[3] + Wt(w, f[4].length));
}(o, l, c);
if (e.match(/^#+0+$/)) return c + br(l, e.length - e.indexOf("0"));
if (o = e.match(qd)) {
s = Math.trunc(kc(t, o[2].length));
var h = function(f) {
if (!isFinite(f)) return 0;
for (var _ = 1, p = 0; Math.round(f * _) / _ !== f; ) _ *= 10, p++;
return p;
}(i = Oc(Math.abs(s - t), o[2].length));
return i = (i = "" + Oc(i, h)).replace(/^0\./, ""), r = Mc("" + Math.abs(s), o[1]) + "." + Mc("" + i, o[2], !0), r = e.indexOf("0.") !== -1 ? r : r.replace(/^0\./, "."), t < 0 ? "-" + r : r;
}
if (o = (e = e.replace(/^#+([0.])/, "$1")).match(/^(0*)\.(#*)$/)) return c + kc(l, o[2].length).replace(/\.(\d*[1-9])0*$/, ".$1").replace(/^(-?\d*)$/, "$1.").replace(/^0\./, o[1].length ? "0." : ".");
if (o = e.match(/^#{1,3},##0(\.?)$/)) return c + $n(br(l, 0));
if (o = e.match(/^#,##0\.([#0]*0)$/)) return t < 0 ? "-" + Rt(a, e, -t) : $n("" + (Math.floor(t) + function(f, _) {
return _ < ("" + Math.round((f - Math.floor(f)) * Math.pow(10, _))).length ? 1 : 0;
}(t, o[1].length))) + "." + Wt(Dc(t, o[1].length), o[1].length);
if (o = e.match(/^#,#*,#0/)) return Rt(a, e.replace(/^#,#*,/, ""), t);
if (o = e.match(/^([0#]+)(\\?-([0#]+))+$/)) return r = jr(Rt(a, e.replace(/[\\-]/g, ""), t)), s = 0, jr(jr(e.replace(/\\/g, "")).replace(/[0#]/g, function(f) {
return s < r.length ? r.charAt(s++) : f === "0" ? "0" : "";
}));
if (e.match(Xd)) return "(" + (r = Rt(a, "##########", t)).substr(0, 3) + ") " + r.substr(3, 3) + "-" + r.substr(6);
var u = "";
if (o = e.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/)) return s = Math.min(o[4].length, 7), i = Ei(l, Math.pow(10, s) - 1, !1), r = "" + c, (u = xn("n", o[1], i[1])).charAt(u.length - 1) === " " && (u = u.substr(0, u.length - 1) + "0"), r += u + o[2] + "/" + o[3], (u = yi(i[2], s)).length < o[4].length && (u = zt(o[4].substr(o[4].length - u.length)) + u), r += u;
if (o = e.match(/[#0?] ([#0?]+)( ?)\/( ?)([#0?]+)/)) return s = Math.min(Math.max(o[1].length, o[4].length), 7), i = Ei(l, Math.pow(10, s) - 1, !0), c + Rt(a, e.substring(0, o.index + 1), i[0]) + " " + (i[1] ? wl(i[1], s) + o[2] + "/" + o[3] + yi(i[2], s) : Ft(" ", 2 * s + 1 + o[2].length + o[3].length));
if (o = e.match(/^[#0?]+$/)) return r = br(t, 0), e.length <= r.length ? r : zt(e.substr(0, e.length - r.length)) + r;
if (o = e.match(/^([#0?]+)\.([#0]+)$/)) {
r = "" + t.toFixed(Math.min(o[2].length, 10)).replace(/([^0])0+$/, "$1"), s = r.indexOf(".");
var d = e.indexOf(".") - s, g = e.length - r.length - d;
return zt(e.substr(0, d) + r + e.substr(e.length - g));
}
if (o = e.match(/^00,000\.([#0]*0)$/)) return s = Dc(t, o[1].length), t < 0 ? "-" + Rt(a, e, -t) : $n(function(f) {
return f < 2147483647 && f > -2147483648 ? "" + (f >= 0 ? 0 | f : f - 1 | 0) : "" + Math.floor(f);
}(t)).replace(/^\d,\d{3}$/, "0$&").replace(/^\d*$/, function(f) {
return "00," + (f.length < 3 ? Wt(0, 3 - f.length) : "") + f;
}) + "." + Wt(s, o[1].length);
switch (e) {
case "###,##0.00":
return Rt(a, "#,##0.00", t);
case "###,###":
case "##,###":
case "#,###":
var m = $n(br(l, 0));
return m !== "0" ? c + m : "";
case "###,###.00":
return Rt(a, "###,##0.00", t).replace(/^0\./, ".");
case "#,###.00":
return Rt(a, "#,##0.00", t).replace(/^0\./, ".");
}
throw new Error("unsupported format |" + e + "|");
}
function Yd(a, e) {
var t, n = a.indexOf("E") - a.indexOf(".") - 1;
if (a.match(/^#+0.0E\+0$/)) {
if (e === 0) return "0.0E+0";
if (e < 0) return "-" + Yd(a, -e);
var r = a.indexOf(".");
r === -1 && (r = a.indexOf("E"));
var o = Math.floor(Math.log(e) * Math.LOG10E) % r;
if (o < 0 && (o += r), !(t = (e / Math.pow(10, o)).toPrecision(n + 1 + (r + o) % r)).match(/[Ee]/)) {
var s = Math.floor(Math.log(e) * Math.LOG10E);
t.indexOf(".") === -1 ? t = t.charAt(0) + "." + t.substr(1) + "E+" + (s - t.length + o) : t += "E+" + (s - o), t = t.replace(/\+-/, "-");
}
t = t.replace(/^([+-]?)(\d*)\.(\d*)[Ee]/, function(i, l, c, h) {
return l + c + h.substr(0, (r + o) % r) + "." + h.substr(o) + "E";
});
} else t = e.toExponential(n);
return a.match(/E\+00$/) && t.match(/e[+-]\d$/) && (t = t.substr(0, t.length - 1) + "0" + t.charAt(t.length - 1)), a.match(/E-/) && t.match(/e\+/) && (t = t.replace(/e\+/, "e")), t.replace("e", "E");
}
function tn(a, e, t) {
if (a.charCodeAt(0) === 40 && !e.match(Kd)) {
var n = e.replace(/\( */, "").replace(/ \)/, "").replace(/\)/, "");
return t >= 0 ? tn("n", n, t) : "(" + tn("n", n, -t) + ")";
}
if (e.charCodeAt(e.length - 1) === 44) return function(m, f, _) {
for (var p = f.length - 1; f.charCodeAt(p - 1) === 44; ) --p;
return xn(m, f.substr(0, p), _ / Math.pow(10, 3 * (f.length - p)));
}(a, e, t);
if (e.indexOf("%") !== -1) return function(m, f, _) {
var p = f.replace(Gd, ""), S = f.length - p.length;
return xn(m, p, _ * Math.pow(10, 2 * S)) + Ft("%", S);
}(a, e, t);
if (e.indexOf("E") !== -1) return Yd(e, t);
if (e.charCodeAt(0) === 36) return "$" + tn(a, e.substr(e.charAt(1) === " " ? 2 : 1), t);
var r, o, s, i, l = Math.abs(t), c = t < 0 ? "-" : "";
if (e.match(/^00+$/)) return c + Wt(l, e.length);
if (e.match(/^[#?]+$/)) return r = "" + t, t === 0 && (r = ""), r.length > e.length ? r : zt(e.substr(0, e.length - r.length)) + r;
if (o = e.match(Jd)) return function(m, f, _) {
return _ + (f === 0 ? "" : "" + f) + Ft(" ", m[1].length + 2 + m[4].length);
}(o, l, c);
if (e.match(/^#+0+$/)) return c + Wt(l, e.length - e.indexOf("0"));
if (o = e.match(qd)) return r = ("" + t).replace(/^([^.]+)$/, "." + zt(o[2])).replace(/\.$/, "." + zt(o[2])), r = Wt(Math.abs(t), o[1].length) + r.replace(/\.(\d*)$/, function(m, f) {
return "." + f + Ft("0", zt(o[2]).length - f.length);
}), r = e.indexOf("0.") !== -1 ? r : r.replace(/^0\./, "."), t < 0 ? "-" + r : r;
if (e = e.replace(/^#+([0.])/, "$1"), o = e.match(/^(0*)\.(#*)$/)) return c + ("" + l).replace(/\.(\d*[1-9])0*$/, ".$1").replace(/^(-?\d*)$/, "$1.").replace(/^0\./, o[1].length ? "0." : ".");
if (o = e.match(/^#{1,3},##0(\.?)$/)) return c + $n("" + l);
if (o = e.match(/^#,##0\.([#0]*0)$/)) return t < 0 ? "-" + tn(a, e, -t) : $n("" + t) + "." + Ft("0", o[1].length);
if (o = e.match(/^#,#*,#0/)) return tn(a, e.replace(/^#,#*,/, ""), t);
if (o = e.match(/^([0#]+)(\\?-([0#]+))+$/)) return r = jr(tn(a, e.replace(/[\\-]/g, ""), t)), s = 0, jr(jr(e.replace(/\\/g, "")).replace(/[0#]/g, function(m) {
return s < r.length ? r.charAt(s++) : m === "0" ? "0" : "";
}));
if (e.match(Xd)) return "(" + (r = tn(a, "##########", t)).substr(0, 3) + ") " + r.substr(3, 3) + "-" + r.substr(6);
var h = "";
if (o = e.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/)) return s = Math.min(o[4].length, 7), i = Ei(l, Math.pow(10, s) - 1, !1), r = "" + c, (h = xn("n", o[1], i[1])).charAt(h.length - 1) === " " && (h = h.substr(0, h.length - 1) + "0"), r += h + o[2] + "/" + o[3], (h = yi(i[2], s)).length < o[4].length && (h = zt(o[4].substr(o[4].length - h.length)) + h), r += h;
if (o = e.match(/^# ([#0?]+)( ?)\/( ?)([#0?]+)/)) return s = Math.min(Math.max(o[1].length, o[4].length), 7), c + ((i = Ei(l, Math.pow(10, s) - 1, !0))[0] || (i[1] ? "" : "0")) + " " + (i[1] ? wl(i[1], s) + o[2] + "/" + o[3] + yi(i[2], s) : Ft(" ", 2 * s + 1 + o[2].length + o[3].length));
if (o = e.match(/^[#0?]+$/)) return r = "" + t, e.length <= r.length ? r : zt(e.substr(0, e.length - r.length)) + r;
if (o = e.match(/^([#0]+)\.([#0]+)$/)) {
r = "" + t.toFixed(Math.min(o[2].length, 10)).replace(/([^0])0+$/, "$1"), s = r.indexOf(".");
var u = e.indexOf(".") - s, d = e.length - r.length - u;
return zt(e.substr(0, u) + r + e.substr(e.length - d));
}
if (o = e.match(/^00,000\.([#0]*0)$/)) return t < 0 ? "-" + tn(a, e, -t) : $n("" + t).replace(/^\d,\d{3}$/, "0$&").replace(/^\d*$/, function(m) {
return "00," + (m.length < 3 ? Wt(0, 3 - m.length) : "") + m;
}) + "." + Wt(0, o[1].length);
switch (e) {
case "###,###":
case "##,###":
case "#,###":
var g = $n("" + l);
return g !== "0" ? c + g : "";
default:
if (e.match(/\.[0#?]*$/)) return tn(a, e.slice(0, e.lastIndexOf(".")), t) + zt(e.slice(e.lastIndexOf(".")));
}
throw new Error("unsupported format |" + e + "|");
}
function xn(a, e, t) {
return (0 | t) === t ? tn(a, e, t) : Rt(a, e, t);
}
function Qd(a) {
var e = [], t = !1;
const n = a.length;
for (var r = 0, o = 0; r < n; ++r) switch (a.charCodeAt(r)) {
case 34:
t = !t;
break;
case 95:
case 42:
case 92:
++r;
break;
case 59:
e[e.length] = a.substr(o, r - o), o = r + 1;
}
if (e[e.length] = a.substr(o), t === !0) throw new Error("Format |" + a + "| unterminated string ");
return e;
}
var Zd = /\[[HhMmSs\u0E0A\u0E19\u0E17]*\]/;
function eg(a) {
for (var e = 0, t = "", n = "", r = a.length; e < r; ) switch (t = a.charAt(e)) {
case "G":
$s(a, e) && (e += 6), e++;
break;
case '"':
for (; a.charCodeAt(++e) !== 34 && e < a.length; ) ;
++e;
break;
case "\\":
case "_":
e += 2;
break;
case "@":
++e;
break;
case "B":
case "b":
if (a.charAt(e + 1) === "1" || a.charAt(e + 1) === "2") return !0;
case "M":
case "D":
case "Y":
case "H":
case "S":
case "E":
case "m":
case "d":
case "y":
case "h":
case "s":
case "e":
case "g":
return !0;
case "A":
case "a":
case "上":
if (a.substr(e, 3).toUpperCase() === "A/P" || a.substr(e, 5).toUpperCase() === "AM/PM" || a.substr(e, 5).toUpperCase() === "上午/下午") return !0;
++e;
break;
case "[":
for (n = t; a.charAt(e++) !== "]" && e < a.length; ) n += a.charAt(e);
if (n.match(Zd)) return !0;
break;
case ".":
case "0":
case "#":
for (; e < a.length && ("0#?.,E+-%".indexOf(t = a.charAt(++e)) > -1 || t === "\\" && a.charAt(e + 1) === "-" && "0#".indexOf(a.charAt(e + 2)) > -1); ) ;
break;
case "?":
for (; a.charAt(++e) === t; ) ;
break;
case "*":
++e, a.charAt(e) !== " " && a.charAt(e) !== "*" || ++e;
break;
case "(":
case ")":
++e;
break;
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
for (; e < a.length && "0123456789".indexOf(a.charAt(++e)) > -1; ) ;
break;
default:
++e;
}
return !1;
}
var Lc = /\[(=|>[=]?|<[>=]?)(-?\d+(?:\.\d*)?)\]/;
function Bc(a, e) {
if (e == null) return !1;
var t = parseFloat(e[2]);
switch (e[1]) {
case "=":
if (a === t) return !0;
break;
case ">":
if (a > t) return !0;
break;
case "<":
if (a < t) return !0;
break;
case "<>":
if (a !== t) return !0;
break;
case ">=":
if (a >= t) return !0;
break;
case "<=":
if (a <= t) return !0;
}
return !1;
}
function tg(a, e, t) {
t == null && (t = F.EmptyObject);
var n = "";
switch (typeof a) {
case "string":
n = a === "m/d/yy" && t.dateNF ? t.dateNF : a;
break;
case "number":
(n = a === 14 && t.dateNF ? t.dateNF : (t.table != null ? t.table : cr)[a]) == null && (n = t.table && t.table[Fc[a]] || cr[Fc[a]]), n == null && (n = yf[a] || "General");
}
if ($s(n, 0)) return ha(e, t);
Vd(e) && (e = ql(e, t.date1904));
var r = function(o, s) {
var i = Qd(o), l = i.length, c = i[l - 1].indexOf("@");
if (c !== -1 && i[l - 1][c - 1] === "\\" && (c = -1), l < 4 && c > -1 && --l, i.length > 4) throw new Error("We can't find right format for |" + i.join("|") + "|");
if (typeof s != "number") return [4, i.length === 4 || c > -1 ? i[i.length - 1] : "@"];
switch (i.length) {
case 1:
i = c > -1 ? ["General", "General", "General", i[0]] : [i[0], i[0], i[0], "@"];
break;
case 2:
i = c > -1 ? [i[0], i[0], i[0], i[1]] : [i[0], i[1], i[0], "@"];
break;
case 3:
i = c > -1 ? [i[0], i[1], i[0], i[2]] : [i[0], i[1], i[2], "@"];
}
var h = s > 0 ? i[0] : s < 0 ? i[1] : i[2];
if (i[0].indexOf("[") === -1 && i[1].indexOf("[") === -1) return [l, h];
if (i[0].match(/\[[=<>]/) != null || i[1].match(/\[[=<>]/) != null) {
var u = i[0].match(Lc), d = i[1].match(Lc);
return Bc(s, u) ? [l, i[0]] : Bc(s, d) ? [l, i[1]] : [l, i[u != null && d != null ? 2 : 1]];
}
return [l, h];
}(n, e);
if ($s(r[1])) return ha(e, t);
if (e === !0) e = "TRUE";
else if (e === !1) e = "FALSE";
else if (e === "" || e == null) return "";
return function(o, s, i, l) {
var c, h, u, d = [], g = "", m = 0, f = "", _ = "t", p = "H";
let S = o.length;
for (; m < S; ) switch (f = o.charAt(m)) {
case "G":
if (!$s(o, m)) throw new Error("unrecognized character " + f + " in " + o);
d[d.length] = { t: "G", v: "General" }, m += 7;
break;
case '"':
for (g = ""; (u = o.charCodeAt(++m)) !== 34 && m < o.length; ) g += String.fromCharCode(u);
d[d.length] = { t: "t", v: g }, ++m;
break;
case "\\":
var E = o.charAt(++m), y = E === "(" || E === ")" ? E : "t";
d[d.length] = { t: y, v: E }, ++m;
break;
case "@":
d[d.length] = { t: "T", v: s }, ++m;
break;
case "B":
case "b":
if (o.charAt(m + 1) === "1" || o.charAt(m + 1) === "2") {
if (c == null && (c = Mo(s, i, o.charAt(m + 1) === "2")) == null) return "";
d[d.length] = { t: "X", v: o.substr(m, 2) }, _ = f, m += 2;
break;
}
case "M":
case "D":
case "Y":
case "H":
case "S":
case "E":
f = f.toLowerCase();
case "m":
case "d":
case "y":
case "h":
case "s":
case "e":
case "g":
if (s < 0 || c == null && (c = Mo(s, i)) == null) return "";
for (g = f; ++m < o.length && o.charAt(m).toLowerCase() === f; ) g += f;
f === "m" && _.toLowerCase() === "h" && (f = "M"), f === "h" && (f = p), d[d.length] = { t: f, v: g }, _ = f;
break;
case "A":
case "a":
case "上":
var C = { t: f, v: f };
if (c == null && (c = Mo(s, i)), o.substr(m, 3).toUpperCase() === "A/P" ? (c != null && (C.v = c.H >= 12 ? "P" : "A"), C.t = "T", p = "h", m += 3) : o.substr(m, 5).toUpperCase() === "AM/PM" ? (c != null && (C.v = c.H >= 12 ? "PM" : "AM"), C.t = "T", m += 5, p = "h") : o.substr(m, 5).toUpperCase() === "上午/下午" ? (c != null && (C.v = c.H >= 12 ? "下午" : "上午"), C.t = "T", m += 5, p = "h") : (C.t = "t", ++m), c == null && C.t === "T") return "";
d[d.length] = C, _ = f;
break;
case "[":
for (g = f; o.charAt(m++) !== "]" && m < o.length; ) g += o.charAt(m);
if (g.slice(-1) !== "]") throw new Error('unterminated "[" block: |' + g + "|");
if (g.match(Zd)) {
if (c == null && (c = Mo(s, i)) == null) return "";
d[d.length] = { t: "Z", v: g.toLowerCase() }, _ = g.charAt(1);
} else g.indexOf("$") > -1 && (g = (g.match(/\$([^-[\]]*)/) || [])[1] || "$", eg(o) || (d[d.length] = { t: "t", v: g }));
break;
case ".":
if (c != null) {
for (g = f; ++m < o.length && (f = o.charAt(m)) === "0"; ) g += f;
d[d.length] = { t: "s", v: g };
break;
}
case "0":
case "#":
for (g = f; ++m < o.length && "0#?.,E+-%".indexOf(f = o.charAt(m)) > -1; ) g += f;
d[d.length] = { t: "n", v: g };
break;
case "?":
for (g = f; o.charAt(++m) === f; ) g += f;
d[d.length] = { t: f, v: g }, _ = f;
break;
case "*":
if (++m, !(g = o.charAt(m))) throw new Error("no character specified for repeat function: " + o);
d[d.length] = { t: "R", v: g }, ++m;
break;
case "_":
if (++m, !(g = o.charAt(m))) throw new Error("no character specified for spacing function: " + o);
d[d.length] = { t: "S", v: g }, ++m;
break;
case "(":
case ")":
d[d.length] = { t: l === 1 ? "t" : f, v: f }, ++m;
break;
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
for (g = f; m < o.length && "0123456789".indexOf(o.charAt(++m)) > -1; ) g += o.charAt(m);
d[d.length] = { t: "D", v: g };
break;
case " ":
d[d.length] = { t: f, v: f }, ++m;
break;
case "$":
d[d.length] = { t: "t", v: "$" }, ++m;
break;
default:
if (",$-+/():!^&'~{}<>=€acfijklopqrtuvwxzP".indexOf(f) === -1) throw new Error("unrecognized character " + f + " in " + o);
d[d.length] = { t: "t", v: f }, ++m;
}
var w, b = 0, x = 0;
for (m = d.length - 1, _ = "t"; m >= 0; --m) switch (d[m].t) {
case "h":
case "H":
d[m].t = p, _ = "h", b < 1 && (b = 1);
break;
case "s":
(w = d[m].v.match(/\.0+$/)) && (x = Math.max(x, w[0].length - 1)), b < 3 && (b = 3);
case "d":
case "y":
case "M":
case "e":
_ = d[m].t;
break;
case "m":
_ === "s" && (d[m].t = "M", b < 2 && (b = 2));
break;
case "X":
break;
case "Z":
b < 1 && d[m].v.match(/[Hh]/) && (b = 1), b < 2 && d[m].v.match(/[Mm]/) && (b = 2), b < 3 && d[m].v.match(/[Ss]/) && (b = 3);
}
switch (b) {
case 0:
break;
case 1:
c.u >= 0.5 && (c.u = 0, ++c.S), c.S >= 60 && (c.S = 0, ++c.M), c.M >= 60 && (c.M = 0, ++c.H);
break;
case 2:
c.u >= 0.5 && (c.u = 0, ++c.S), c.S >= 60 && (c.S = 0, ++c.M);
}
var I, v = "";
for (S = d.length, m = 0; m < S; ++m) switch (d[m].t) {
case "t":
case "T":
case " ":
case "D":
break;
case "X":
d[m].v = "", d[m].t = ";";
break;
case "d":
case "m":
case "y":
case "h":
case "H":
case "M":
case "s":
case "e":
case "b":
case "Z":
d[m].v = vf(d[m].t.charCodeAt(0), d[m].v, c, x), d[m].t = "t";
break;
case "n":
case "?":
for (I = m + 1; d[I] != null && ((f = d[I].t) === "?" || f === "D" || (f === " " || f === "t") && d[I + 1] != null && (d[I + 1].t === "?" || d[I + 1].t === "t" && d[I + 1].v === "/") || d[m].t === "(" && (f === " " || f === "n" || f === ")") || f === "t" && (d[I].v === "/" || d[I].v === " " && d[I + 1] != null && d[I + 1].t === "?")); ) d[m].v += d[I].v, d[I] = { v: "", t: ";" }, ++I;
v += d[m].v, m = I - 1;
break;
case "G":
d[m].t = "t", d[m].v = ha(s, i);
}
var R, A, M = "";
if (v.length > 0) {
v.charCodeAt(0) === 40 ? (R = s < 0 && v.charCodeAt(0) === 45 ? -s : s, A = xn("n", v, R)) : (A = xn("n", v, R = s < 0 && l > 1 ? -s : s), R < 0 && d[0] && d[0].t === "t" && (A = A.substr(1), d[0].v = "-" + d[0].v)), I = A.length - 1;
var T = d.length;
for (S = d.length, m = 0; m < S; ++m) if (d[m] != null && d[m].t !== "t" && d[m].v.indexOf(".") > -1) {
T = m;
break;
}
var k = S;
if (T === S && A.indexOf("E") === -1) {
for (m = d.length - 1; m >= 0; --m) d[m] != null && "n?".indexOf(d[m].t) !== -1 && (I >= d[m].v.length - 1 ? (I -= d[m].v.length, d[m].v = A.substr(I + 1, d[m].v.length)) : I < 0 ? d[m].v = "" : (d[m].v = A.substr(0, I + 1), I = -1), d[m].t = d[m].v.indexOf("?") >= 0 ? "N" : "t", k = m);
I >= 0 && k < d.length && (d[k].v = A.substr(0, I + 1) + d[k].v);
} else if (T !== d.length && A.indexOf("E") === -1) {
for (I = A.indexOf(".") - 1, m = T; m >= 0; --m) if (d[m] != null && "n?".indexOf(d[m].t) !== -1) {
for (h = d[m].v.indexOf(".") > -1 && m === T ? d[m].v.indexOf(".") - 1 : d[m].v.length - 1, M = d[m].v.substr(h + 1); h >= 0; --h) I >= 0 && (d[m].v.charAt(h) === "0" || d[m].v.charAt(h) === "#" || d[m].v.charAt(h) === "?") && (M = A.charAt(I--) + M);
d[m].v = M, d[m].t = M.indexOf("?") >= 0 ? "N" : "t", k = m;
}
for (I >= 0 && k < d.length && (d[k].v = A.substr(0, I + 1) + d[k].v), I = A.indexOf(".") + 1, m = T; m < d.length; ++m) if (d[m] != null && ("n?(".indexOf(d[m].t) !== -1 || m === T)) {
for (h = d[m].v.indexOf(".") > -1 && m === T ? d[m].v.indexOf(".") + 1 : 0, M = d[m].v.substr(0, h); h < d[m].v.length; ++h) I < A.length && (M += A.charAt(I++));
d[m].v = M, d[m].t = M.indexOf("?") >= 0 ? "N" : "t", k = m;
}
}
}
for (m = 0; m < S; ++m) d[m] != null && "n?".indexOf(d[m].t) > -1 && (R = l > 1 && s < 0 && m > 0 && d[m - 1].v === "-" ? -s : s, d[m].v = xn(d[m].t, d[m].v, R), d[m].t = d[m].v.indexOf("?") >= 0 ? "N" : "t");
var P = "";
for (S = d.length, m = 0; m < S; m++) if (d[m].t === "R") i?.onRepeatChar?.(P.length, d[m].v);
else if (d[m].t === "S") i?.onSpacingChar?.(P.length, d[m].v), P += i?.spacingCharacter ?? " ";
else if (d[m].t === "N") {
M = d[m].v;
for (var B = 0; B < M.length; B++) (f = M[B]) === "?" && (i?.onDigitChar?.(P.length, f), f = i?.digitCharacter ?? " "), P += f;
} else d[m] != null && (P += d[m].v);
return P;
}(r[1], e, t, r[0]);
}
function zc(a, e) {
if (typeof e != "number") {
e = +e || -1;
for (var t = 0; t < 392; ++t) if (cr[t] !== void 0) {
if (cr[t] === a) {
e = t;
break;
}
} else e < 0 && (e = t);
e < 0 && (e = 391);
}
return cr[e] = a, e;
}
const Ke = { format: tg, dateNumLocal: ql, load: zc, split_fmt: Qd, _table: cr, load_table: function(a) {
for (var e = 0; e !== 392; ++e) a[e] !== void 0 && zc(a[e], e);
}, parse_date_code: Mo, is_date: eg, get_table: function() {
return Ke._table = cr;
} }, Xe = "\\s*([-]?[0-9e]*[.]?[0-9]+)", xf = new RegExp(`^rgb\\(${Xe},${Xe},${Xe}\\)$`), If = new RegExp(`^rgba\\(${Xe},${Xe},${Xe},${Xe}\\)$`), Rf = new RegExp(`^lrgb\\(${Xe},${Xe},${Xe}\\)$`), Af = new RegExp(`^lrgba\\(${Xe},${Xe},${Xe},${Xe}\\)$`), Mf = new RegExp(`^hsl\\(${Xe},${Xe},${Xe}\\)$`), Tf = new RegExp(`^hsla\\(${Xe},${Xe},${Xe},${Xe}\\)$`), Nf = new RegExp(/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/), Ff = new RegExp(/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/), kf = new RegExp("^index(\\d+)$", "i"), ua = (a, e, t) => [parseFloat(a), parseFloat(e), parseFloat(t)], da = (a, e = 255) => {
const t = [...a];
for (var n = 0; n < a.length; n++) t[n] = a[n] / e;
return t;
}, Pc = (a, e = 0) => {
const t = [...a];
for (var n = 0; n < a.length; n++) F.roundAccurately(a[n], e + 8) % 1 == 0.5 ? t[n] = Math.floor(a[n]) : t[n] = F.roundAccurately(a[n], e);
return t;
}, dt = (a, e = !0) => {
const t = [...a], n = e ? 1 : 255;
for (var r = 0; r < a.length; r++) t[r] = Math.max(0, Math.min(n, a[r]));
return t;
}, zr = (a) => Math.max(0, Math.min(1, a)), ng = (a) => ((a %= 360) < 0 && (a -= 360), a), ur = (a) => {
const e = [...a];
for (var t = 0; t < a.length; t++) e[t] = Gs(a[t]);
return e;
}, dr = (a) => {
const e = [...a];
for (var t = 0; t < a.length; t++) e[t] = Us(a[t]);
return e;
}, Gs = (a) => a < 0.04045 ? a / 12.92 : Math.pow((a + 0.055) / 1.055, 2.4), Us = (a) => a < 31308e-7 ? 12.92 * a : 1.055 * Math.pow(a, 1 / 2.4) - 0.055, gr = (a) => {
let e = a[0], t = a[1], n = a[2];
e %= 360, e /= 360, t /= 100, n /= 100;
let r = n < 0.5 ? n * (1 + t) : n + t - t * n, o = 2 * n - r;
return [Math.max(0, ga(o, r, e + 1 / 3)), Math.max(0, ga(o, r, e)), Math.max(0, ga(o, r, e - 1 / 3))];
}, ga = (a, e, t) => (t < 0 && (t += 1), t > 1 && (t -= 1), 6 * t < 1 ? a + 6 * (e - a) * t : 2 * t < 1 ? e : 3 * t < 2 ? a + 6 * (e - a) * (2 / 3 - t) : a), Jn = (a) => {
let e = a[0], t = a[1], n = a[2], r = Math.min(e, Math.min(t, n)), o = Math.max(e, Math.max(t, n)), s = 0;
o === r ? s = 0 : o === e ? s = (60 * (t - n) / (o - r) + 360) % 360 : o === t ? s = 60 * (n - e) / (o - r) + 120 : o === n && (s = 60 * (e - t) / (o - r) + 240);
const i = (o + r) / 2;
let l = 0;
return l = o === r ? 0 : i <= 0.5 ? (o - r) / (o + r) : (o - r) / (2 - o - r), [s, 100 * l, 100 * i];
}, ut = 0, ma = 1, co = 2, Js = 0, qs = 1, Ks = 2, Xs = 0, Ys = 1, Qs = 2, Of = (a, e) => {
let t = e / 100;
return ((n, r) => {
let o = ur(n);
o[0] = r(o[0], o), o[1] = r(o[1], o), o[2] = r(o[2], o);
let s = dr(o);
return s = dt(s), s;
})(a, (n, r) => n * t);
}, ms = 2.55, Df = (a, e) => {
const t = Jn(a), n = t[2], r = F.roundAccurately((o = n, (s = e) > 0 ? (o * ms * (1 - s) + (255 - 255 * (1 - s))) / ms : s < 0 ? o * ms * (1 + s) / ms : o), 3);
var o, s;
t[2] = r;
let i = gr(t);
return i = dt(i), i;
}, Lf = (a, e) => {
let t = ur(a), n = e / 100;
for (var r = 0; r < 3; r++) t[r] = t[r] * n + (1 - n);
let o = dr(t);
return o = dt(o), o;
}, fa = (a, e, t) => {
let n = Jn(e), r = t / 1;
a === ut && (r = ng(t)), n[a] = r;
let o = gr(n);
return o = dt(o), o;
}, pa = (a, e, t) => {
let n = Jn(e);
if (a === ut) {
let o = t / 360;
n[ut] = 360 * (n[ut] / 360 + o), n[ut] %= 360, n[ut] < 0 && (n[ut] -= 360);
} else {
let o = t / 0.1;
n[a] = 0.1 * (n[a] / 0.1 + o);
}
let r = gr(n);
return r = dt(r), r;
}, _a = (a, e, t) => {
let n = Jn(e), r = t / 100;
n[a] = n[a] * r, a === ut && (n[ut] = ng(n[ut]));
let o = gr(n);
return o = dt(o), o;
}, cn = (a, e, t, n) => {
let r = ur(e), o = t / 100;
n === Xs ? r[a] = o : n === Ys ? r[a] += o : n === Qs && (r[a] *= o);
let s = dr(r);
return s = dt(s), s;
}, Bf = (a) => {
let e = ur(a), t = 0.213 * e[Js] + 0.715 * e[qs] + 0.072 * e[Ks];
e[0] = t, e[1] = t, e[2] = t;
let n = dr(e);
return n = dt(n), n;
}, zf = (a) => {
let e = Jn(a);
e[ut] += 180, e[ut] %= 360, e[ut] < 0 && (e[ut] -= 360);
let t = gr(e);
return t = dt(t), t;
}, Hc = (a, e = !0) => {
let t = e ? ur(a) : [...a];
const n = e ? 1 : 255;
return t[0] = n - t[0], t[1] = n - t[1], t[2] = n - t[2], e && (t = dr(t)), t = dt(t, e), t;
}, Pf = (a) => {
const e = [0, 0, 0];
return e[0] = Us(a[0]), e[1] = Us(a[1]), e[2] = Us(a[2]), dt(e);
}, Hf = (a) => {
const e = [0, 0, 0];
return e[0] = Gs(a[0]), e[1] = Gs(a[1]), e[2] = Gs(a[2]), dt(e);
}, Wc = (a, e, t, n = null) => {
const r = (o) => {
let s = o.toString(16);
return s.length === 1 ? "0" + s : s;
};
return (n === null ? "" : r(Math.round(255 * n))) + r(Number(a)).toUpperCase() + r(Number(e)).toUpperCase() + r(Number(t)).toUpperCase();
}, vr = 0.2126, On = 0.7152, xr = 0.0722;
var wn;
((a) => {
a.RGBA = class {
constructor(t, n, r, o = 1) {
this._private = { red: t, green: n, blue: r, alpha: o };
}
get red() {
return this._private.red;
}
get green() {
return this._private.green;
}
get blue() {
return this._private.blue;
}
get alpha() {
return this._private.alpha ?? 1;
}
toString(t = !0) {
return t && this._private.alpha !== null ? `rgba(${this.red},${this.green},${this.blue},${this.alpha})` : `rgb(${this.red},${this.green},${this.blue})`;
}
isEqual(t) {
return !!t && t.red === this.red && t.green === this.green && t.blue === this.blue && t.alpha === this.alpha;
}
isAlmostEqual(t) {
if (!t) return !1;
const n = 1.5;
return !(Math.abs(t.red - this.red) > n) && !(Math.abs(t.green - this.green) > n) && !(Math.abs(t.blue - this.blue) > n) && !(Math.abs(t.alpha - this.alpha) > n);
}
}, a.HSLA = class {
constructor(t, n, r, o) {
this._private = { hue: t, sat: n, lum: r, alpha: o };
}
get hue() {
return this._private.hue;
}
get sat() {
return this._private.sat;
}
get lum() {
return this._private.lum;
}
get alpha() {
return this._private.alpha ?? 1;
}
toString(t = !0) {
return t && this._private.alpha !== null ? `hsla(${this.hue},${this.sat},${this.lum},${this.alpha})` : `hsl(${this.hue},${this.sat},${this.lum})`;
}
isEqual(t) {
return !!t && t.hue === this.hue && t.sat === this.sat && t.lum === this.lum && t.alpha === this.alpha;
}
isAlmostEqual(t) {
if (!t) return !1;
const n = 1.5;
return !(Math.abs(t.hue - this.hue) > n) && !(Math.abs(t.sat - this.sat) > n) && !(Math.abs(t.lum - this.lum) > n) && !(Math.abs(t.alpha - this.alpha) > n);
}
};
class e extends a.RGBA {
toString(n = !0) {
return n && this._private.alpha !== null ? "#" + Wc(this.red, this.green, this.blue, this.alpha ?? 1).toUpperCase() : "#" + Wc(this.red, this.green, this.blue).toUpperCase();
}
}
a.HEX = e;
})(wn || (wn = {}));
const Wf = /^#?([a-f\d])([a-f\d])([a-f\d])$/i, jf = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i, Zs = function(a) {
if (!a) return null;
a = a.replace(Wf, function(t, n, r, o) {
return n + n + r + r + o + o;
});
let e = jf.exec(a);
return e ? new wn.RGBA(parseInt(e[1], 16), parseInt(e[2], 16), parseInt(e[3], 16)) : null;
}, jc = ["000000", "FFFFFF", "FF0000", "00FF00", "0000FF", "FFFF00", "FF00FF", "00FFFF", "000000", "FFFFFF", "FF0000", "00FF00", "0000FF", "FFFF00", "FF00FF", "00FFFF", "800000", "008000", "000080", "808000", "800080", "008080", "C0C0C0", "808080", "9999FF", "993366", "FFFFCC", "CCFFFF", "660066", "FF8080", "0066CC", "CCCCFF", "000080", "FF00FF", "FFFF00", "00FFFF", "800080", "800000", "008080", "0000FF", "00CCFF", "CCFFFF", "CCFFCC", "FFFF99", "99CCFF", "FF99CC", "CC99FF", "FFCC99", "3366FF", "33CCCC", "99CC00", "FFCC00", "FF9900", "FF6600", "666699", "969696", "003366", "339966", "003300", "333300", "993300", "993366", "333399", "333333"], sr = /* @__PURE__ */ new Map();
for (let a = 0; a < jc.length; a++) sr.set(a, Zs(jc[a]));
sr.set(-4105, null), sr.set(-4142, null), sr.set(64, Zs("000000")), sr.set(65, Zs("FFFFFF")), sr.set(81, Zs("FFFFFF"));
const Ci = (a) => sr.get(a), Se = { General: "General", Number: "Number", Currency: "Currency", Accounting: "Accounting", ShortDate: "Short Date", LongDate: "Long Date", MediumDate: "Medium Date", ShortTime: "Short Time", MediumTime: "Medium Time", LongTime: "Long Time", Comma: "Comma", Percentage: "Percentage", Fraction: "Fraction", Scientific: "Scientific", Text: "Text", Special: "Special", Custom: "Custom" };
let Sa = null;
const rg = () => Sa || (Sa = Intl.DateTimeFormat().resolvedOptions().locale ?? "en-US", Sa), Vf = /^\[\$-(.*?)\]/i, $f = /^[0-9a-fA-F]+$/, Gf = Ke.split_fmt, Kl = (a, e, t) => {
const n = Vf.exec(a);
let r = rg();
if (n && n[1]) {
let o = n[1];
$f.test(o) || o.includes("-");
}
if (Vc[a] && (a = Vc[a]), typeof e == "number") {
const o = To(a, e, { locale: r, ...t });
if (o !== null) return o.fmt;
}
return Ke.format(a, e, t);
}, To = (a, e, t) => {
if (typeof e != "number") return null;
const n = no(e, t?.date1904 ?? !1), r = t?.locale ?? rg();
let o = !1, s = a, i = -1;
if ((i = s.indexOf("Short Date")) !== -1) {
const l = new Intl.DateTimeFormat(r).format(n);
s = s.substring(0, i) + l + s.substring(i + 10), o = !0;
}
if ((i = s.indexOf("Medium Date")) !== -1) {
const l = Ke.format(Ke.get_table()[15], e, t);
s = s.substring(0, i) + l + s.substring(i + 11), o = !0;
}
if ((i = s.indexOf("Long Date")) !== -1) {
const l = new Intl.DateTimeFormat(r, { dateStyle: "full" }).format(n);
s = s.substring(0, i) + l + s.substring(i + 9), o = !0;
}
if ((i = s.indexOf("Short Time")) !== -1) {
const l = Ke.format(Ke.get_table()[20], e, t);
s = s.substring(0, i) + l + s.substring(i + 10), o = !0;
}
if ((i = s.indexOf("Medium Time")) !== -1) {
const l = Ke.format(Ke.get_table()[18], e, t);
s = s.substring(0, i) + l + s.substring(i + 11), o = !0;
}
if ((i = s.indexOf("Long Time")) !== -1) {
const l = new Intl.DateTimeFormat(r, { timeStyle: "medium" }).format(n);
s = s.substring(0, i) + l + s.substring(i + 9), o = !0;
}
return o ? { fmt: s, date: n } : null;
}, Vc = Object.freeze({ "General Number": "General", "General Date": "m/d/yyyy h:mm", "Medium Date": Ke.get_table()[15], "Medium Time": Ke.get_table()[18], "Short Time": Ke.get_table()[20], Currency: '"$"#,##0.00_);[Red]\\("$"#,##0.00\\)', Fixed: Ke.get_table()[2], Standard: Ke.get_table()[4], Percent: Ke.get_table()[10], Scientific: Ke.get_table()[11], "Yes/No": '"Yes";"Yes";"No";@', "True/False": '"True";"True";"False";@', "On/Off": '"Yes";"Yes";"No";@' }), Uf = Object.freeze({ black: 0, white: 1, red: 2, green: 3, blue: 4, yellow: 5, magenta: 6, cyan: 7 }), Jf = (a) => {
let e = null;
if ((a = a.toLowerCase()).startsWith("color")) {
const t = parseInt(a.substring(5));
t >= 0 && t <= 56 && (e = `Index${t + 7}`);
}
if (!e) {
const t = Uf[a];
t !== void 0 && (e = Ci(t).toString());
}
return e;
}, og = "=", qf = "<>", sg = ">", yl = "<", ig = ">=", Kf = "<=", tr = /* @__PURE__ */ new Map();
tr.set(og, (a, e) => a === e), tr.set(qf, (a, e) => a !== e), tr.set(sg, (a, e) => a > e), tr.set(yl, (a, e) => a < e), tr.set(ig, (a, e) => a >= e), tr.set(Kf, (a, e) => a <= e);
const Xf = /(Black|Blue|Cyan|Green|Magenta|Red|White|Yellow|Color[0-9]+)/i, Yf = /(=|>[=]?|<[>=]?)(-?\d+(?:\.\d*)?)/i, Qf = /\[(.*?)\]/g, Zf = (a, e) => {
const t = { color: null, condition: null };
let n = null, r = new RegExp(Qf);
for (; (n = r.exec(a)) !== null; ) {
let o = !1, s = Xf.exec(n[1]);
if (s) {
if (o = !0, t.color) throw new Error(`format error, two colors specified: '${a}' and '${t.color}'.`);
t.color = Jf(s[1]), t.color || console.warn("Unable to parse LegacyColor", s[1]);
}
let i = Yf.exec(n[1]);
if (i) {
if (o = !0, t.condition) throw new Error(`Format error, two conditions specified: ' ${a}'`);
t.condition = { op: i[1], comp: parseFloat(i[2]) };
}
if (!o) return t;
}
return t.condition || (t.condition = e), t;
}, ep = (a, e) => {
let t = ((r) => {
const o = [];
if (!r) return o;
const s = r.split(";");
for (let i = 0; i < s.length; i++) {
let l = null;
s.length === 2 ? i === 0 ? l = { op: ig, comp: 0 } : i === 1 && (l = { op: yl, comp: 0 }) : s.length !== 3 && s.length !== 4 || (l = i === 0 ? { op: sg, comp: 0 } : i === 1 ? { op: yl, comp: 0 } : i === 2 ? { op: og, comp: 0 } : null);
const c = s[i], h = Zf(c, l);
o.push({ format: c, colorAndCondition: h });
}
return o;
})(a), n = t[0].colorAndCondition;
if (t.length === 1 && n && !n.condition && n.color) return n.color;
for (let r = 0; r < t.length; r++) {
n = t[r].colorAndCondition;
let o = n?.condition ?? void 0;
if (r === 3) return typeof e == "string" && n?.color ? n.color : null;
if (o && typeof e == "number" && tr.get(o.op)(e, o.comp))
return n?.color ?? null;
}
}, $c = (a) => {
if (a === Se.MediumDate || a === Se.LongDate || a === Se.ShortDate || a === Se.MediumTime || a === Se.LongTime || a === Se.ShortTime) return !0;
}, tp = (a, e) => a === e ? 0 : $c(a) ? 1 : $c(e) ? -1 : a === Se.Percentage ? 1 : e === Se.Percentage ? -1 : a === Se.Currency || a === Se.Accounting ? 1 : e === Se.Currency || e === Se.Accounting ? -1 : 0, to = (a) => (a instanceof Date || Object.prototype.toString.call(a) === "[object Date]") && !isNaN(a.getTime()), np = (a, e, t) => {
return t === "month" || t === "months" || t === "m" ? (n = a, 12 * ((r = e).getUTCFullYear() - n.getUTCFullYear()) + (r.getUTCMonth() - n.getUTCMonth()) + (r.getUTCDate() - n.getUTCDate() < 0 ? -1 : 0)) : t === "year" || t === "years" || t === "y" ? ((o, s) => Math.abs(s.getFullYear() - o.getFullYear()))(a, e) : t === "day" || t === "days" || t === "d" ? ((o, s) => Math.floor((Date.UTC(s.getFullYear(), s.getMonth(), s.getDate()) - Date.UTC(o.getFullYear(), o.getMonth(), o.getDate())) / 864e5))(a, e) : void console.warn("invalid unit" + t);
var n, r;
}, fs = "d", Gc = "m", Uc = "y", Jc = (a, e, t) => {
if (t === "month" || t === "months" || t === "m") {
const n = new Date(a.getTime());
return new Date(n.setMonth(n.getMonth() + e));
}
if (t === "year" || t === "years" || t === "y") {
const n = new Date(a.getTime());
return n.setFullYear(n.getFullYear() + e), n;
}
if (t === "day" || t === "days" || t === "d") {
const n = new Date(a.getTime());
return n.setDate(n.getDate() + e), n;
}
if (t === "hour" || t === "hours" || t === "h") {
const n = new Date(a.getTime());
return n.setHours(n.getHours() + e), n;
}
return console.warn("invalid unit" + t), null;
}, no = (a, e = !1) => {
let t = Ke.parse_date_code(a, { date1904: e });
return t ? new Date(t.y, t.m - 1, t.d, t.H, t.M, t.S, Math.round(1e3 * t.u)) : null;
}, es = (a, e = !1) => isNaN(a) ? null : Ke.dateNumLocal(a, e), rp = new class extends jd {
parse(a, e, t) {
const n = (r) => r - 1;
switch (e) {
case "M":
return vn(Vn(Wd, a), n);
case "MM":
return vn(Wo(2, a), n);
case "Mo":
return vn(t.ordinalNumber(a, { unit: "month" }), n);
case "MMM":
return t.month(a, { width: "abbreviated", context: "formatting" });
case "MMMMM":
return t.month(a, { width: "narrow", context: "formatting" });
default:
return t.month(a, { width: "wide", context: "formatting" });
}
}
}(), hn = ((a) => {
let e = a, t = [];
for (let n = 0; n < e.length; n++) {
let r = e[n][0].indexOf("yyy") > -1, o = e[n][0].indexOf(".") > -1, s = e[n][0].indexOf("-") > -1;
t.push({ parseFormat: e[n][0], numberFormat: e[n][1], todaysYear: !r, windowYear: !0, containsDot: o, containsDash: s }), r && t.push({ parseFormat: e[n][0].replace(/yyy/g, "yyyy"), numberFormat: e[n][1], todaysYear: !1, windowYear: !1, containsDot: o, containsDash: s });
}
return t;
})([["MM-d", "d-mmm"], ["MM-yyy", "mmm-yy"], ["M-yyy", "mmm-yy"], ["M-d-yyy", "m/d/yyyy"], ["yyy-M-d", "m/d/yyyy"], ["yyy-d-M", "m/d/yyyy"], ["d.MMM", "d-mmm"], ["d.MMMM", "d-mmm"], ["d.MMM.yyy", "d-mmm-yy"], ["d.MMMM.yyy", "d-mmm-yy"], ["MMM.d", "d-mmm"], ["MMMM.d", "d-mmm"], ["MMM.yyy", "mmm-yy"], ["MMMM.yyy", "mmm-yy"], ["MMM dd, yyy", "d-mmm-yy"], ["MMMM dd, yyy", "d-mmm-yy"], ["EEE, MMMM dd, yyy", "[$-x-sysdate]ddd, mmmm dd, yyyy"], ["EEEE, MMMM dd, yyy", "[$-x-sysdate]dddd, mmmm dd, yyyy"]]), op = { year: 0, month: 1, day: 0, hour: 0, minute: 0, second: 0, millis: 0 }, sp = (a, e = !1) => {
const t = { ...op, ...a };
return t.year = e ? 1904 : 1900, t.dow = -1, t.oaDateTime = ((n, r = !1) => {
if (!n) return null;
let o = n.day, s = n.hour;
s > 24 && (o += Math.floor(s / 24), s %= 24), o > 60 && --o;
const i = new Date(n.year, n.month - 1, o, s, n.minute, n.second, n.millis);
return es(i, r);
})(t, e), t;
}, ip = new RegExp("([0-9]{1,2})\\s*(P[M]?|A[M]?)\\s*$", "i"), ap = new RegExp("([0-9]+)\\s*\\:$", "i"), wa = new RegExp("(\\s*[0-9]{1,2})\\s+(P[M]?|A[M]?)\\s*$", "i"), qc = new RegExp("(\\s*[0-9]{1,4})\\s*([\\.]{1}\\s*[0-9]+)?\\s*\\:", "i"), lp = new RegExp("(\\s*[0-9]{1,4})\\s*([\\.]{1}\\s*[0-9]*)?\\s*$", "i"), ag = (a, e = !1, t = !1) => {
if (!a || a.trim().length < 2 || a.indexOf(":") === -1 && a.match(wa) === null) return null;
let n = null, r = null, o = null, s = !1, i = !1, l = "h:mm AM/PM", c = [], h = a, u = null;
do {
let _ = h.indexOf(":");
_ === -1 ? (c.push(h), h = null) : (c.push(h.substring(0, _ + 1)), h = h.substring(_ + 1, h.length));
} while (c.length < 3 && h && h.length > 0);
if (h?.length > 0) return null;
const d = (_, p, S) => {
let E = _.match(p);
if (!E) return null;
u === null && (u = _.substring(0, E.index));
let y = parseInt(E[1]);
if (E[2] && o === null) {
if (S) {
let w = parseFloat(E[2].substring(1, E[2].length));
isNaN(w) || (r = w);
}
let C = parseFloat(E[2]);
isNaN(C) || (n = C), o = S;
}
return y;
}, g = (_, p) => {
let S = _.match(p);
if (!S || S.length !== 3) return null;
u === null && (u = _.substring(0, S.index)), s = !0;
let E = parseInt(S[1]);
return i = S[2].charAt(0) === "p" || S[2].charAt(0) === "P", E;
};
c[c.length - 1].trim().length === 0 && c.pop();
const m = [];
if (c.length > 0) {
let _ = d(c[0], ap, !1);
if (_ === null && (_ = g(c[0], ip)), _ === null) return null;
m.push(_);
}
if (c.length > 2) {
let _ = d(c[1], qc, !0);
if (_ === null && (_ = g(c[0], wa)), _ === null) return null;
m.push(_);
}
if (c.length > 1) {
const _ = c[c.length - 1];
let p = d(_, qc, !1);
if (p === null && (p = d(_, lp, !1)), p === null && (p = g(_, wa)), p === null) return null;
m.push(p);
}
if (u !== null && u.length > 0 && !t) return null;
if (o === !0 && (m.length === 2 && m.splice(1, 0, 0), m[2] = r || 0), s) {
if (m[0] > 12 || m[1] >= 60 || m[2] >= 60) return null;
m[0] === 12 ? m[0] = i ? 12 : 0 : i && (m[0] += 12);
} else l = c.length > 2 ? "h:mm:ss" : "h:mm", m[0] > 23 && (l = "[h]:mm:ss"), n !== null && (l = "mm:ss.0"), m[1] >= 60 && (l = "General"), m[2] >= 60 && (l = "General");
l !== "General" && (m.length === 1 && m.push(0), m.length === 2 && (n === null ? m.push(0) : m.unshift(0)));
let f = { hour: m[0] ?? 0, minute: m[1] ?? 0, second: m[2] ?? 0, millis: 1e3 * (n ?? 0) };
return { numberFormat: l, parsed: sp(f, e), leadingText: u };
}, cp = {}, Xl = (a, e = !1, t = null) => {
const n = t ?? Date.now(), r = new Date(n).getFullYear();
let o = a.trim().replaceAll(/\s+/g, " ");
o = o.replaceAll(/\s*([-/])\s*/g, "$1");
let s = o.replaceAll(/[-/ ]/g, "."), i = o.replaceAll(/[/]/g, "-");
const l = Ao.M;
Ao.M = rp;
for (let c = 0; c < hn.length; c++) {
let h = o;
hn[c].containsDot ? h = s : hn[c].containsDash && (h = i);
let u = Sf(h, hn[c].parseFormat, n, cp), d = Ke.dateNumLocal(u, e);
if (to(u) && (hn[c].windowYear || d > 0)) {
if (hn[c].windowYear) {
let m = u.getFullYear() <= 29 ? 2e3 + u.getFullYear() : 1900 + u.getFullYear();
u.setFullYear(m);
}
if (hn[c].todaysYear && u.setFullYear(r), d = Ke.dateNumLocal(u, e), hn[c].parseFormat.indexOf("EEE") > -1) {
const m = Kl("ddd", d, { date1904: e });
if (!h.toLowerCase().includes(m.toLowerCase())) return null;
}
let g = hn[c].numberFormat;
return Ao.M = l, { asOADate: d, asJSDate: u, numberFormat: g };
}
}
return Ao.M = l, null;
};
function ts(a) {
if (!a) return !1;
let e = a.replaceAll(/\[([^)]+)\]/g, "").toLowerCase();
return e = e.replaceAll(/".*"/g, ""), e = e.replaceAll(/\\./g, ""), e = e.replace(/[_*]./g, ""), !e.includes("time") && !!(e.includes("d") || e.includes("m") && !e.includes("h") && !e.includes("s") || e.includes("y") || e === "short date" || e === "medium date" || e === "long date");
}
function Wi(a) {
if (!a) return !1;
let e = a.replaceAll(/\[([^)]+)\]/g, "").toLowerCase();
return e = e.replaceAll(/".*"/g, ""), e = e.replaceAll(/\\./g, ""), e = e.replace(/[_*]./g, ""), !e.includes("date") && !(!e.includes("h") && !e.includes("s") && e !== "short time" && e !== "medium time" && e !== "long time");
}
var bi, Kc, X, un;
(Kc = bi || (bi = {})).SmallCaps = { None: "none", Small: "small", All: "all" }, Kc.StrikeStyle = { None: "none", Single: "single", Double: "double" }, (un = X || (X = {})).TabStop = class {
}, un.HorizontalAlignment = { General: "general", Left: "left", Center: "center", Right: "right", Justify: "justify", Distributed: "distributed", CenterContinuous: "centerContinuous", Fill: "fill" }, un.VerticalAlignment = { Top: "top", Center: "center", Bottom: "bottom", Justify: "justify", Distributed: "distributed" }, un.Orientation = { Horizontal: "horizontal", Vertical: "90", Vertical270: "270", Stacked: "stacked" }, un.ReadingDirection = { Auto: "auto", LeftToRight: "ltr", RightToLeft: "rtl" }, un.Overflow = { Visible: "visible", Wrap: "wrap", Clip: "clip", Shrink: "shrink", Ellipsis: "ellipsis" }, un.Autofit = { None: "none", Normal: "normal", Shape: "shape" }, un.TabStopAlignment = { Default: "default", Left: "left", Right: "right", Center: "center" }, un.toCSSHorizontalTextAlign = (a) => a ? a.toLowerCase() : null;
const lg = (a, e, t = 1e3) => {
if (!a) throw new Error("A template string must be specified.");
if (e(a)) return a;
let n = new RegExp(/\d+/, "g").exec(a), r = null, o = 0;
n !== null ? (r = a, o = parseFloat(n[0]), isNaN(o) && (o = 0)) : (o = 1, r = `${a}_${o}`);
let s = isNaN(o) ? 0 : o;
for (; o < s + t; ) try {
const i = r.replace(/\d+/g, () => "" + o++);
if (e(i)) return i;
} catch {
}
throw new Error(`Unable to find valid name for '${a}'.`);
}, Xr = (a, e = !1) => {
if (!a || a.length === 0) return a;
const t = a.charAt(0);
if (t >= "a" && t <= "z") {
const n = String.fromCharCode(t.charCodeAt(0) - 32);
return e ? n + a.slice(1).toLowerCase() : n + a.slice(1);
}
return a;
}, Xc = (a) => {
if (!a || typeof a != "string") return "";
const e = a.split(/[\\/]/).pop() || "", t = e.lastIndexOf(".");
return e === "" || t < 1 ? "" : e.slice(t + 1);
}, cg = (a) => a.toLowerCase().replace(/([-_][a-z])/g, (e) => e.toUpperCase().replace("-", "").replace("_", "")), hg = (a, e = 36) => a.substring(0, 36) + (a.length > e ? "…" : ""), ei = (a) => {
if (a === void 0) return 0;
let e = a.toString().split(".");
return e.length <= 1 ? 0 : e[1].length || 0;
}, ug = new RegExp(/^["|'|`](.*)["|'|`]$/), hp = new RegExp("^([a-zA-Z]+:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$", "i"), dg = (a = ",", e = "'") => new RegExp(`\\s*${a}\\s*(?=(?:[^${e}]*${e}[^${e}]*${e})*[^${e}]*$)`, "g"), gg = dg(), Yl = (a) => a.replace(ug, "$1"), mg = (a, e = "'") => `${e}${a}${e}`, fg = (a, e = void 0, t = void 0) => {
let n = gg;
return e === void 0 && t === void 0 || (n = dg(e, t)), a.split(n);
}, pg = (a) => {
let e;
try {
e = new URL(a);
} catch {
return !1;
}
return (e.protocol === "http:" || e.protocol === "https:") && hp.test(a);
}, up = new RegExp(/^[^\s@]+@[^\s@]+\.[^\s@]+$/i), _g = (a) => !!a.toLowerCase().startsWith("mailto:") || up.test(a), Sg = (a) => ((a >= 26 ? Sg((a / 26 | 0) - 1) : "") + "abcdefghijklmnopqrstuvwxyz"[a % 26 | 0]).toUpperCase(), ty = Object.freeze(Object.defineProperty({ __proto__: null, DefaultUnQuoteRegEx: gg, camelToSnake: (a) => a && a.replace(/[A-Z]/g, (e) => `_${e.toLowerCase()}`), capitalize: Xr, clampString: hg, countDecimals: ei, findValidTextValue: lg, getBaseName: (a, e = !1) => {
if (!a || typeof a != "string") return "";
const t = a.split(/[\\/]/).pop() || "";
if (t === "") return "";
const n = Xc(t), r = n.length === 0 ? t : t.slice(0, t.length - n.length - 1);
return e ? Xr(r, !0) : r;
}, getFileNameExtension: Xc, isQuoted: (a) => a && a.length > 1 && ug.test(a) && a[0] === a[a.length - 1], isValidEmail: _g, isValidHttpUrl: pg, numberToAlphabet: Sg, quote: mg, snakeToCamel: cg, splitUnquoted: fg, unquote: Yl }, Symbol.toStringTag, { value: "Module" })), dp = (a, e, t, n = null) => {
const r = (e || 11 * te.getDeviceScale()) / te.getDeviceScale(), o = n?.letterSpacing || 0, s = a.length, i = s * (0.55 * r) - (a.match(/[il.,;!|]/g) || []).length * r * 0.15 + (a.match(/[mwMW]/g) || []).length * r * 0.1 + (s > 0 ? (s - 1) * o : 0), l = Math.ceil(1.2 * r), c = Math.ceil(0.8 * r), h = Math.ceil(0.2 * r), u = Math.ceil(0.45 * r), d = Math.ceil(1.1 * r), g = Math.max(1, Math.ceil(0.08 * r));
return { width: i, lineHeight: l, baseline: c, lineGap: h, strikePosition: u, underlinePosition: d, strikeThickness: g, underlineThickness: g, actualBoundingBoxLeft: 0, actualBoundingBoxRight: i, actualBoundingBoxAscent: c, actualBoundingBoxDescent: l - c, fontBoundingBoxAscent: c, fontBoundingBoxDescent: l - c, emHeightAscent: c, emHeightDescent: l - c, hangingBaseline: 0.8 * c, alphabeticBaseline: c, ideographicBaseline: l };
}, ct = {}, Yc = (a, e) => {
let t = "normal";
return a && e ? t = "bold italic" : a ? t = "bold" : e && (t = "italic"), t;
}, Qc = (a) => a.split(",").map((e) => {
const t = (e = e.trim()).indexOf(" ") >= 0, n = e.indexOf('"') >= 0 || e.indexOf("'") >= 0;
return t && !n && (e = `"${e}"`), e;
}).join(", "), Zc = /* @__PURE__ */ new Map(), ya = /* @__PURE__ */ new Map();
let dn = null;
const gp = (a, e, t, n = null) => {
const r = n?.letterSpacing || 0;
typeof window > "u" || ct.contextMeasure || (ct.canvasMeasure = document ? document.createElement("canvas") : null, ct.contextMeasure = ct.canvasMeasure.getContext("2d"), ct.contextMeasure.letterSpacing = `${r}px`, ct.contextMeasure.textRendering = "geometricPrecision", ct.contextMeasure.textBaseline = "alphabetic", ct.contextMeasure.textAlign = "left");
const o = t || "calibri", s = e || 11 * te.getDeviceScale(), i = n?.isBold || !1, l = n?.isItalic || !1;
let c = null;
if (a === "#" || a === "0" || a === "M" || a === "" || a === "_" || a === "-") {
c = ((f, _, p, S, E, y) => f + Math.round(100 * _) / 100 + p + S + E + y)(a, s, o, i, l, r);
const m = Zc.get(c);
if (m) return m;
}
if (dn && dn.text === a && dn.size === e && dn.family === t && dn.options?.isBold === n?.isBold && dn.options?.isItalic === n?.isItalic && dn.options?.letterSpacing === n?.letterSpacing) return dn.metrics;
let h = {};
const u = Yc(i, l) + " " + F.roundAccurately(s, 2) + "px " + Qc(o);
ct.contextMeasure ? (ct.contextMeasure.font = u, ct.contextMeasure.letterSpacing = `${n?.letterSpacing ?? 0}px`, h = ct.contextMeasure.measureText(a)) : h.width = a.length * F.roundAccurately(s / te.getDeviceScale() * 0.6, 2);
let d = ya.get(u);
if (!d && typeof window < "u") {
const m = document.createElement("div");
m.style.visibility = "hidden", m.style.position = "absolute";
const f = document.createElement("span");
f.textContent = "Mj", f.style.fontSize = "100px", f.style.fontWeight = n?.isBold ? "bold" : "normal", f.style.fontStyle = n?.isItalic ? "italic" : "normal", f.style.fontFamily = `'${o}'`, f.style.lineHeight = "1.2", m.appendChild(f), document.body.appendChild(m);
const _ = m.getBoundingClientRect(), p = f.getBoundingClientRect();
document.body.removeChild(m), ct.contextMeasure.font = Yc(i, l) + " " + F.roundAccurately(100, 2) + "px " + Qc(o);
const S = ct.contextMeasure.measureText("M"), E = _.bottom - _.top, y = E - (S.fontBoundingBoxAscent + S.fontBoundingBoxDescent), C = S.fontBoundingBoxAscent + p.top, w = ct.contextMeasure.measureText("_"), b = C - w.actualBoundingBoxAscent, x = Math.max(1, Math.abs(w.actualBoundingBoxAscent + w.actualBoundingBoxDescent)), I = ct.contextMeasure.measureText("-"), v = F.roundAccurately(C - I.actualBoundingBoxAscent + Math.max(1, 0.05 * E, 0)), R = x, A = s / 100;
d = { lineHeight: Math.ceil(E * A), baseline: Math.ceil(C * A), lineGap: Math.ceil(y * A), strikePosition: Math.ceil(v * A), underlinePosition: Math.ceil(b * A), strikeThickness: Math.ceil(R * A), underlineThickness: Math.ceil(x * A) }, ct.contextMeasure.font = u, ya.set(u, d);
}
d || (d = { lineHeight: Math.ceil(1.2 * s), baseline: Math.ceil(s) + Math.floor(0.1 * s), lineGap: Math.ceil(0.1 * s), strikePosition: Math.ceil(0.55 * s) + Math.floor(0.1 * s), strikeThickness: 1, underlinePosition: Math.ceil(1.1 * s), underlineThickness: 1 }, ya.set(u, d));
const g = { ...h, width: h.width, ...d };
return c !== null && Zc.set(c, g), dn = { text: a, size: e, family: t, options: n, metrics: g }, g;
};
let Ir = null;
const mp = () => {
if (Ir) return Ir;
try {
const a = document.createElement("canvas"), e = a.getContext && a.getContext("2d");
e && typeof e.fillText == "function" && (Ir = gp);
} catch {
}
return Ir || (console.warn("⚠️ CanvasFontMeasurer not available, falling back to SimpleFontMeasurer"), Ir = dp), Ir;
};
let ps = null;
var te, gn;
(gn = te || (te = {})).Style = { Normal: "normal", Italic: "italic" }, gn.Scheme = { Major: "major", Minor: "minor", None: "none" }, gn.UnderlineStyle = { None: "none", Double: "double", DoubleAccounting: "doubleAccounting", Single: "single", SingleAccounting: "singleAccounting" }, gn.VerticalAlignment = { Baseline: "baseline", Sub: "sub", Super: "super" }, gn.setSharedMeasurer = (a) => {
ps = a;
}, gn.getSharedMeasurer = () => ps || (ps = mp(), ps), gn.getDeviceScale = () => 96 / 72 * 1, gn.getPanoseFallback = (a) => {
const e = [], t = a.length;
for (let s = 0; s < t; s += 2) e.push(parseInt(a.substring(s, s + 2), 16));
const n = e[0], r = e[1], o = e[3];
switch (n) {
case 2:
return o === 9 ? "monospace" : r >= 2 && r <= 8 ? "serif" : "sans-serif";
case 3:
return "cursive";
case 4:
return "fantasy";
case 5:
return "monospace";
default:
return "sans-serif";
}
}, gn.GenericName = { Serif: "serif", SanSerif: "sans-serif", MonoSpace: "monospace", Cursive: "cursive", Fantasy: "fantasy", SystemUI: "system-ui", UISystem: "ui-system", UISerif: "ui-serif", UISanSerif: "ui-sans-serif", UIMonoSpace: "ui-monospace", UIRounded: "ui-rounded", Math: "math", Emoji: "emoji", Fangsong: "fangsong" };
class fp {
constructor(e) {
this._private = { input: e }, typeof e == "string" ? this._private.name = e : Object.assign(this._private, e);
}
toJSON() {
return this._private.input;
}
getFamily() {
return this._private.name;
}
getPitch() {
return this._private.pitch;
}
getPanose() {
return this._private.panose;
}
toString() {
return typeof this._private.input == "string" ? this._private.input : JSON.stringify(this._private.input);
}
get isIFont() {
return !0;
}
}
const wg = ["Arial", "Arial Black", "Brush Script MT", "Calibri", "Comic Sans MS", "Courier New", "Garamond", "Georgia", "Impact", "Luminari", "Palatino Linotype", "Tahoma", "Times New Roman", "Trebuchet MS", "Verdana"], Et = /* @__PURE__ */ new Map();
Et.set(te.GenericName.Serif, ["Tahoma"]), Et.set(te.GenericName.SanSerif, ["Calibri"]), Et.set(te.GenericName.MonoSpace, ["Courier New"]), Et.set(te.GenericName.Cursive, ["Comic Sans MS"]), Et.set(te.GenericName.Fantasy, ["Luminari"]), Et.set(te.GenericName.UISystem, ["Arial"]), Et.set(te.GenericName.UISerif, ["Tahoma"]), Et.set(te.GenericName.UISanSerif, ["Arial"]), Et.set(te.GenericName.UIMonoSpace, ["Courier New"]), Et.set(te.GenericName.UIRounded, ["Arial"]), Et.set(te.GenericName.Math, []), Et.set(te.GenericName.Emoji, []), Et.set(te.GenericName.Fangsong, []);
const El = /* @__PURE__ */ new Map();
let yg = [];
Ql(wg);
const pp = eval;
function Ql(a) {
a || Ql(wg);
let e = [];
for (let t = 0; t < a.length; t++) {
let n = a[t];
typeof n == "string" && (n = new fp(n));
let r = !0;
const o = "document";
try {
r = pp(`${o}.fonts.check('12px ${n.getFamily()}')`);
} catch {
}
const s = { fontRef: n, loaded: r };
e.push(s), El.set(n.getFamily(), s);
}
yg = Object.freeze(e);
}
const Ea = /* @__PURE__ */ new Map(), ny = Object.freeze(Object.defineProperty({ __proto__: null, findBestMatch: (a, e) => {
const t = Ea.get(a);
if (t) return t.fontRef === null ? null : t;
let n = [a];
e.fallbacks && (n = n.concat(e.fallbacks));
let r = null;
for (let o = 0; !r && o < n.length; o++) {
let s = n[o];
if (r = El.get(s), !r) {
const i = Et.get(s);
if (i) for (let l = 0; !r && l < i.length; l++) r = El.get(i[l]);
}
}
return r ? Ea.set(a, r) : Ea.set(a, { fontRef: null, loaded: !1 }), r;
}, getFontList: function() {
return yg;
}, setFontList: Ql }, Symbol.toStringTag, { value: "Module" }));
class ji {
constructor(e, t, n, r = null, o = null, s = null) {
this._private = { wrapped: !0, insets: Hi.EmptyRect, orientation: X.Orientation.Horizontal, autoFit: X.Autofit.None, fontScale: 1, vertical: !1, columnCount: 1, columnSpacing: 0, verticalAlignment: X.VerticalAlignment.Center, horizontalCentered: !1, lineReduction: 0, isSpaceFirstLastPara: !1, presetTextWarp: null, paragraphs: F.EmptyArray }, this._bounds = null, this._textBounds = null, this._lines = null, this._lastLayoutDims = void 0, this._lastLayout = void 0, this._private = Object.assign(this._private, e || {}), this._defaultFont = t, this._alignment = n, this._lines = r, this._bounds = Object.freeze(o), this._textBounds = Object.freeze(s);
}
visitParas(e) {
e?.visitTextFrame?.(this);
const t = this.paragraphs, n = t.length;
for (let r = 0; r < n; r++) {
const o = t[r];
e?.visitTextParagraph?.(o, r, n);
const s = o.runs, i = s.length;
for (let l = 0; l < i; l++) e?.visitTextRun?.(s[l], l, i);
}
}
visitLines(e) {
e?.visitTextFrame?.(this);
const t = this.lines, n = t.length;
for (let r = 0; r < n; r++) {
const o = t[r];
e?.visitTextLine?.(o, r, n);
const s = o.runs, i = s.length;
for (let l = 0; l < i; l++) e?.visitTextRun?.(s[l], l, i);
}
}
layout(e = null) {
return this._lastLayout && this._lastLayoutDims?.width === e?.width && this._lastLayoutDims?.height === e?.height || (this._lastLayout = vp(this, this._defaultFont, this._alignment, e), this._lastLayoutDims = e), this._lastLayout;
}
clone(e) {
const t = e?.visitTextFrame?.(this), n = Object.assign(this._private, t || {});
return delete n.bounds, new ji(n, this._defaultFont, this._alignment);
}
equals(e) {
return F.deepEqual(this._private, e._private);
}
createTemporaryTextFrame(e, t) {
return Gi(e, this._defaultFont, this._alignment, t ?? this._private.wrapped);
}
get bounds() {
if (this._bounds === null) throw new Error(eh);
return this._bounds;
}
get textBounds() {
if (this._textBounds === null) throw new Error(eh);
return this._textBounds;
}
get lines() {
return this._lines;
}
get wrapped() {
return this._private.wrapped;
}
get insets() {
return this._private.insets;
}
get orientation() {
return this._private.orientation;
}
get autoFit() {
return this._private.autoFit;
}
get fontScale() {
return this._private.fontScale;
}
get vertical() {
return this._private.vertical;
}
get columnCount() {
return this._private.columnCount;
}
get columnSpacing() {
return this._private.columnSpacing;
}
get verticalAlignment() {
return this._private.verticalAlignment;
}
get horizontalCentered() {
return this._private.horizontalCentered;
}
get lineReduction() {
return this._private.lineReduction;
}
get isSpaceFirstLastPara() {
return this._private.isSpaceFirstLastPara;
}
get presetTextWarp() {
return this._private.presetTextWarp;
}
get paragraphs() {
return this._private.paragraphs;
}
}
const eh = "bounds can not be used until layout";
class th {
static {
this.NL = `
`;
}
static {
this.DefaultLineSpacing = 100;
}
static {
this.DefaultTabWidth = 72;
}
}
class Vi {
constructor(e) {
this._private = { defaultFontSize: 11, defaultTabSize: th.DefaultTabWidth, tabOverrides: F.EmptyArray, spacingBefore: 0, spacingAfter: 0, lineSpacing: th.DefaultLineSpacing, align: X.HorizontalAlignment.Left, endParagraphSize: 0, indentLevel: 0, leadingIndent: 0, hangingIndent: 0, rightMargin: 0, bullet: null }, this._private = Object.assign(this._private, e || {});
}
clone(e) {
const t = e?.visitTextParagraph?.(this, 0, 1), n = Object.assign(this._private, t || {});
return delete n.bounds, new Vi(n);
}
equals(e) {
return F.deepEqual(this._private, e._private);
}
get bounds() {
return this._bounds;
}
get defaultFontSize() {
return this._private.defaultFontSize;
}
get defaultTabSize() {
return this._private.defaultTabSize;
}
get tabOverrides() {
return this._private.tabOverrides;
}
get spacingBefore() {
return this._private.spacingBefore;
}
get spacingAfter() {
return this._private.spacingAfter;
}
get lineSpacing() {
return this._private.lineSpacing;
}
get align() {
return this._private.align;
}
get endParagraphSize() {
return this._private.endParagraphSize;
}
get indentLevel() {
return this._private.indentLevel;
}
get leadingIndent() {
return this._private.leadingIndent;
}
get hangingIndent() {
return this._private.hangingIndent;
}
get rightMargin() {
return this._private.rightMargin;
}
get bullet() {
return this._private.bullet;
}
get runs() {
return this._private.runs;
}
}
class $i {
constructor(e, t = null) {
this._private = { text: null, fontName: "Arial", bold: !1, italic: !1, superSub: !1, fontSize: 11, letterSpacing: 0, kerningMin: 10, smallCaps: bi.SmallCaps.None, offset: 0, strikeStyle: bi.StrikeStyle.None }, this._private = { ...this._private, ...e }, this._bounds = t;
}
clone(e) {
const t = e?.visitTextRun?.(this, 0, 1), n = Object.assign(this._private, t || {});
return delete n.bounds, new $i(n);
}
equals(e) {
return F.deepEqual(this._private, e._private);
}
get bounds() {
return this._bounds;
}
get text() {
return this._private.text;
}
get fontName() {
return this._private.fontName;
}
get bold() {
return this._private.bold;
}
get italic() {
return this._private.italic;
}
get fontSize() {
return this._private.fontSize;
}
get superSub() {
return this._private.superSub;
}
get letterSpacing() {
return this._private.letterSpacing;
}
get kerningMin() {
return this._private.kerningMin;
}
get smallCaps() {
return this._private.smallCaps;
}
get offset() {
return this._private.offset;
}
get strikeStyle() {
return this._private.strikeStyle;
}
}
class Eg {
constructor(e, t, n) {
this._private = {}, this._private = { bounds: e, baseline: t, runs: n };
}
get bounds() {
return this._private.bounds;
}
get baseline() {
return this._private.baseline;
}
get runs() {
return this._private.runs;
}
get bullet() {
return null;
}
}
function Cg(a) {
return a && a.__esModule && Object.prototype.hasOwnProperty.call(a, "default") ? a.default : a;
}
var nh, rh, oh, sh, ih, ah;
function _p() {
if (sh) return oh;
sh = 1;
const a = new Uint8Array(new Uint32Array([305419896]).buffer)[0] === 18, e = (t, n, r) => {
let o = t[n];
t[n] = t[r], t[r] = o;
};
return oh = { swap32LE: (t) => {
a && ((n) => {
const r = n.length;
for (let o = 0; o < r; o += 4) e(n, o, o + 3), e(n, o + 1, o + 2);
})(t);
} };
}
var Sp = function() {
if (ah) return ih;
ah = 1;
const a = function() {
if (rh) return nh;
function t() {
this.table = new Uint16Array(16), this.trans = new Uint16Array(288);
}
function n(w, b) {
this.source = w, this.sourceIndex = 0, this.tag = 0, this.bitcount = 0, this.dest = b, this.destLen = 0, this.ltree = new t(), this.dtree = new t();
}
rh = 1;
var r = new t(), o = new t(), s = new Uint8Array(30), i = new Uint16Array(30), l = new Uint8Array(30), c = new Uint16Array(30), h = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), u = new t(), d = new Uint8Array(320);
function g(w, b, x, I) {
var v, R;
for (v = 0; v < x; ++v) w[v] = 0;
for (v = 0; v < 30 - x; ++v) w[v + x] = v / x | 0;
for (R = I, v = 0; v < 30; ++v) b[v] = R, R += 1 << w[v];
}
var m = new Uint16Array(16);
function f(w, b, x, I) {
var v, R;
for (v = 0; v < 16; ++v) w.table[v] = 0;
for (v = 0; v < I; ++v) w.table[b[x + v]]++;
for (w.table[0] = 0, R = 0, v = 0; v < 16; ++v) m[v] = R, R += w.table[v];
for (v = 0; v < I; ++v) b[x + v] && (w.trans[m[b[x + v]]++] = v);
}
function _(w) {
w.bitcount-- || (w.tag = w.source[w.sourceIndex++], w.bitcount = 7);
var b = 1 & w.tag;
return w.tag >>>= 1, b;
}
function p(w, b, x) {
if (!b) return x;
for (; w.bitcount < 24; ) w.tag |= w.source[w.sourceIndex++] << w.bitcount, w.bitcount += 8;
var I = w.tag & 65535 >>> 16 - b;
return w.tag >>>= b, w.bitcount -= b, I + x;
}
function S(w, b) {
for (; w.bitcount < 24; ) w.tag |= w.source[w.sourceIndex++] << w.bitcount, w.bitcount += 8;
var x = 0, I = 0, v = 0, R = w.tag;
do
I = 2 * I + (1 & R), R >>>= 1, ++v, x += b.table[v], I -= b.table[v];
while (I >= 0);
return w.tag = R, w.bitcount -= v, b.trans[x + I];
}
function E(w, b, x) {
var I, v, R, A, M, T;
for (I = p(w, 5, 257), v = p(w, 5, 1), R = p(w, 4, 4), A = 0; A < 19; ++A) d[A] = 0;
for (A = 0; A < R; ++A) {
var k = p(w, 3, 0);
d[h[A]] = k;
}
for (f(u, d, 0, 19), M = 0; M < I + v; ) {
var P = S(w, u);
switch (P) {
case 16:
var B = d[M - 1];
for (T = p(w, 2, 3); T; --T) d[M++] = B;
break;
case 17:
for (T = p(w, 3, 3); T; --T) d[M++] = 0;
break;
case 18:
for (T = p(w, 7, 11); T; --T) d[M++] = 0;
break;
default:
d[M++] = P;
}
}
f(b, d, 0, I), f(x, d, I, v);
}
function y(w, b, x) {
for (; ; ) {
var I, v, R, A, M = S(w, b);
if (M === 256) return 0;
if (M < 256) w.dest[w.destLen++] = M;
else for (I = p(w, s[M -= 257], i[M]), v = S(w, x), A = R = w.destLen - p(w, l[v], c[v]); A < R + I; ++A) w.dest[w.destLen++] = w.dest[A];
}
}
function C(w) {
for (var b, x; w.bitcount > 8; ) w.sourceIndex--, w.bitcount -= 8;
if ((b = 256 * (b = w.source[w.sourceIndex + 1]) + w.source[w.sourceIndex]) !== (65535 & ~(256 * w.source[w.sourceIndex + 3] + w.source[w.sourceIndex + 2]))) return -3;
for (w.sourceIndex += 4, x = b; x; --x) w.dest[w.destLen++] = w.source[w.sourceIndex++];
return w.bitcount = 0, 0;
}
return function(w, b) {
var x;
for (x = 0; x < 7; ++x) w.table[x] = 0;
for (w.table[7] = 24, w.table[8] = 152, w.table[9] = 112, x = 0; x < 24; ++x) w.trans[x] = 256 + x;
for (x = 0; x < 144; ++x) w.trans[24 + x] = x;
for (x = 0; x < 8; ++x) w.trans[168 + x] = 280 + x;
for (x = 0; x < 112; ++x) w.trans[176 + x] = 144 + x;
for (x = 0; x < 5; ++x) b.table[x] = 0;
for (b.table[5] = 32, x = 0; x < 32; ++x) b.trans[x] = x;
}(r, o), g(s, i, 4, 3), g(l, c, 2, 1), s[28] = 0, i[28] = 258, nh = function(w, b) {
var x, I, v = new n(w, b);
do {
switch (x = _(v), p(v, 2, 0)) {
case 0:
I = C(v);
break;
case 1:
I = y(v, r, o);
break;
case 2:
E(v, v.ltree, v.dtree), I = y(v, v.ltree, v.dtree);
break;
default:
I = -3;
}
if (I !== 0) throw new Error("Data error");
} while (!x);
return v.destLen < v.dest.length ? typeof v.dest.slice == "function" ? v.dest.slice(0, v.destLen) : v.dest.subarray(0, v.destLen) : v.dest;
};
}(), { swap32LE: e } = _p();
return ih = class {
constructor(t) {
const n = typeof t.readUInt32BE == "function" && typeof t.slice == "function";
if (n || t instanceof Uint8Array) {
let r;
if (n) this.highStart = t.readUInt32LE(0), this.errorValue = t.readUInt32LE(4), r = t.readUInt32LE(8), t = t.slice(12);
else {
const o = new DataView(t.buffer);
this.highStart = o.getUint32(0, !0), this.errorValue = o.getUint32(4, !0), r = o.getUint32(8, !0), t = t.subarray(12);
}
t = a(t, new Uint8Array(r)), t = a(t, new Uint8Array(r)), e(t), this.data = new Uint32Array(t.buffer);
} else ({ data: this.data, highStart: this.highStart, errorValue: this.errorValue } = t);
}
get(t) {
let n;
return t < 0 || t > 1114111 ? this.errorValue : t < 55296 || t > 56319 && t <= 65535 ? (n = (this.data[t >> 5] << 2) + (31 & t), this.data[n]) : t <= 65535 ? (n = (this.data[2048 + (t - 55296 >> 5)] << 2) + (31 & t), this.data[n]) : t < this.highStart ? (n = this.data[2080 + (t >> 11)], n = this.data[n + (t >> 5 & 63)], n = (n << 2) + (31 & t), this.data[n]) : this.data[this.data.length - 4];
}
};
}();
const wp = Cg(Sp);
var lh, ch = {}, yp = (lh || (lh = 1, function(a) {
var e = typeof Uint8Array < "u" ? Uint8Array : Array, t = 43, n = 47, r = 48, o = 97, s = 65, i = 45, l = 95;
function c(h) {
var u = h.charCodeAt(0);
return u === t || u === i ? 62 : u === n || u === l ? 63 : u < r ? -1 : u < r + 10 ? u - r + 26 + 26 : u < s + 26 ? u - s : u < o + 26 ? u - o + 26 : void 0;
}
a.toByteArray = function(h) {
var u, d, g, m, f, _;
if (h.length % 4 > 0) throw new Error("Invalid string. Length must be a multiple of 4");
var p = h.length;
f = h.charAt(p - 2) === "=" ? 2 : h.charAt(p - 1) === "=" ? 1 : 0, _ = new e(3 * h.length / 4 - f), g = f > 0 ? h.length - 4 : h.length;
var S = 0;
function E(y) {
_[S++] = y;
}
for (u = 0, d = 0; u < g; u += 4, d += 3) E((16711680 & (m = c(h.charAt(u)) << 18 | c(h.charAt(u + 1)) << 12 | c(h.charAt(u + 2)) << 6 | c(h.charAt(u + 3)))) >> 16), E((65280 & m) >> 8), E(255 & m);
return f === 2 ? E(255 & (m = c(h.charAt(u)) << 2 | c(h.charAt(u + 1)) >> 4)) : f === 1 && (E((m = c(h.charAt(u)) << 10 | c(h.charAt(u + 1)) << 4 | c(h.charAt(u + 2)) >> 2) >> 8 & 255), E(255 & m)), _;
}, a.fromByteArray = function(h) {
var u, d, g, m = h.length % 3, f = "";
function _(S) {
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(S);
}
function p(S) {
return _(S >> 18 & 63) + _(S >> 12 & 63) + _(S >> 6 & 63) + _(63 & S);
}
for (u = 0, g = h.length - m; u < g; u += 3) f += p(d = (h[u] << 16) + (h[u + 1] << 8) + h[u + 2]);
switch (m) {
case 1:
f += _((d = h[h.length - 1]) >> 2), f += _(d << 4 & 63), f += "==";
break;
case 2:
f += _((d = (h[h.length - 2] << 8) + h[h.length - 1]) >> 10), f += _(d >> 4 & 63), f += _(d << 2 & 63), f += "=";
}
return f;
};
}(ch)), ch), Cl = {};
const Ep = [[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], [0, 4, 4, 1, 1, 4, 4, 4, 4, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 4, 4, 1, 1, 4, 4, 4, 4, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [4, 4, 4, 1, 1, 1, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 2, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 4, 4, 1, 1, 1, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 2, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 4, 4, 1, 1, 1, 4, 4, 4, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 4, 4, 1, 1, 1, 4, 4, 4, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 4, 4, 1, 1, 1, 4, 4, 4, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 4, 4, 1, 1, 1, 4, 4, 4, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [1, 4, 4, 1, 1, 1, 4, 4, 4, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 4, 2, 4, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0], [1, 4, 4, 1, 1, 1, 4, 4, 4, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [1, 4, 4, 1, 1, 1, 4, 4, 4, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [1, 4, 4, 1, 1, 1, 4, 4, 4, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [1, 4, 4, 1, 1, 1, 4, 4, 4, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 4, 4, 1, 1, 1, 4, 4, 4, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 4, 4, 1, 1, 1, 4, 4, 4, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 4, 4, 1, 0, 1, 4, 4, 4, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 4, 4, 1, 0, 1, 4, 4, 4, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [1, 4, 4, 1, 1, 1, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 2, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 4, 4, 1, 1, 1, 4, 4, 4, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 4, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 4, 4, 1, 1, 1, 4, 4, 4, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [1, 4, 4, 1, 1, 1, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 2, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 4, 4, 1, 1, 1, 4, 4, 4, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0], [0, 4, 4, 1, 1, 1, 4, 4, 4, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0], [0, 4, 4, 1, 1, 1, 4, 4, 4, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 2, 4, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0], [0, 4, 4, 1, 1, 1, 4, 4, 4, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0], [0, 4, 4, 1, 1, 1, 4, 4, 4, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0], [0, 4, 4, 1, 1, 1, 4, 4, 4, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0], [0, 4, 4, 1, 1, 1, 4, 4, 4, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0], [0, 4, 4, 1, 1, 1, 4, 4, 4, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [1, 4, 4, 1, 1, 1, 4, 4, 4, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 4, 4, 1, 1, 0, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]], Cp = new wp(Cg(yp).toByteArray("AAgOAAAAAAAQ4QAAAQ0P8vDtnQuMXUUZx+eyu7d7797d9m5bHoWltKVUlsjLWE0VJNigQoMVqkStEoNQQUl5GIo1KKmogEgqkKbBRki72lYabZMGKoGAjQRtJJDaCCIRiiigREBQS3z+xzOTnZ3O+3HOhd5NfpkzZx7fN9988zivu2M9hGwB28F94DnwEngd/Asc1EtIs9c/bIPDwCxwLDgezHcodyo4w5C+CCwBS8FnwSXgCnA1uFbI93XwbXAbWAfWgx+CzWAb+An4KfgFeAzsYWWfYuFz4CXwGvgb+Dfo6yNkEEwGh4CZYB44FpwI3g1OY+kfBItZOo2fB84Hy8DF4HJwNbiWpV8PVoO1LH4n2NRXyN+KcAd4kNVP9XsY4aPgcfAbsBfs6SniL4K/sPjfEf6HlanXCRkCw2BGvUh/keWfXS/CY+pFXs7x9XHmM94LTmWIeU2cgbxnS/k/B3kf86jDhU8L9V2E40vAFWAlWFUfb++NOL4F3C7JX4/4GiE+hvgWsF0oS7mXldspnN+F493gyXrh9xTav0cg3EvzgVfBG6wsmVSEkxBOBgdPGpd7JI6PnqRvJ68/xlbHof53gPeA94OzwLngk+ACsAwsByvASrAK3MB0Ws3CtQjvBJvAVrADPMDSHkb4CNijaccTwvnf4fiPEs8Lxy+D18A/QU8/xjgYBjPAbDAKTgYLwOngTHAO+EQ/8wuEF4EvsPiVCFf2+9tsFStzA8LVHuXXBsi6QyqzUYiPMR/7Mc7dAx7oL8bzw/3u/Bw8Bp4Az4AXwCtgHzsmDXP5fiF9iiVvly5d0sHngar16NKlS5cuXbp06fLmYlqHXrcd3ph4P0THUY3iXh49novju4S0tzfs5d+JPKewfAsRntZb3K9ZhOMlrO6lCC8An28U9+OuovcPcPxlVu5rCL/VmHh/iHIrzn3fIPu7SN8Axmg+8AOwEWwCm7tp3bRuWjetm5Y8bSu4B9zbKO6ZVsnORrVU3f4uXTqZ2H3sLoyx3eDXjfDndE9qyj6L838CfwVvgFpzYnof4oNgOhgBc8Fos9DrZIQLmtXPP1MmF6wGj4H+KXoWguvADkXaPil+YpuQy8Am8Ey7ODdtmJDF4HowBp4De6HDTNjhfHAHeBr0DBBy0kDxfPbcgSIusgrcWhtnJ8vL+TPix7UIOQtcBq4C28Cr4KRBnANbwSuDE+s50JgyNNFuXbp06XIgsXjIvPafjvXozKY+fVFz/z0LT1uCtKVSWbrOLWPnztG8e0Xfy7ol8XtZJi7WtG+5od2UFXQ/A12vUeS7jp27yVKHjdsU9lXB869TyNvAzt0lpP2oWbwLdjiO78bx/Sz+EMJHwK9Y/LcIfw+eZ3F67/Hl5vh9xX80J+rwX8SvRDhpgL17iPAQMHNArfPrqHPewLheI+AERV6efwV418B4nOZ/H+IfYHV8GOF5LJ3eAz0fx8sM9S0fUNud39O9CulfGZhY5huI3wzWgNvBelbHZoTbNPVpfYjKQpkHwUNgl0LWblbnk0LbbDxr0OMFpL3iqWdu9nWYPlVAWkXY39LnGdCkDbeqv1YNbfcMQ3t9oe8lzm6NH9N1ZB6Ln4BwfkJZJk7RyFnYKt6b/JDQXx9p5X+eFdqOjzM9P9MB/lUlFzr20aXIdzlY4dmn9F3YqtvoO76/2hp/D/xA5Zue88nNyL8GbFbs075X0tyUig3Qd2MCnf//HjnzpbsR3g9+1kHzzVjdnE71/qVBX9rGPUh/ysNWe1neFzvIDi5zAufV1sT0N0poR22wkFUfTOPfA4N2mbZ5fSrqOHSw+IbkSBbOGSzSRgf91/GTUWYBOB2cIZQ/G8cfBZ8CFwrnL8XxF8FKcA24jqXdiPA7Qr61OF7H4mMItwzuv2/YLth1ISt3Hzu3k4W7EH5JqPdRHD/O4k+z8A8IX5Lq3y7Z4nXE9xn6kX6vQ4bKfy+ok+hH+xf3hq9dnTTHhjKd2GmDuWA242iHMq4cC7A8kJ7i8o1+skSa7Jieo38HCWnoNjKFhdSFBxzpZ7QE6lI8N4S14aASZcryaV/WWHw66f6NHuCoxuQxmvM56GX9QMd8Q4D65ywGP+ZzRJuM+zQvx/MOS2VFeqQ4IXnH26zM9Xe6/E6D+4foAzzuajPZp8Qyw5ayZVDWuH0z0BtYRkeIDqH9KO9VbH1btd/lhNqCzvl8zeLnG0S/hnU6baHfpiuO6yy0rd+DHURo/zYF5H26j03rQsip2ndzz82u1z9N4VjWKWeb68Tedpt95HRVXp7H1R6p+/Wt4FPy/PpWwscOLRJ+PVWF/+W0iVyGzs18TIvXkOJ1Wxm66vSXz+vylenrZcj1ub439W+K8RNCGTJi2p/TJ1K23VaXr35tRpnzmjxequgfcfyk6B/TGBVlyedsNgpdd/h+W1U3P99QyFPNo1X3TwpM/WLTIWYfoBqXrv6iskHZ/RFr79R6hIyHBrH3f1nrUVnjP8SnZZ+rYtzr9Exld5MNbPNErusAPg+77u/eDOPftU9yj39TH7rezxd1LvsZQJlzkWlOirG/79zjMj/mtHUKu7vKy+3/LnXr9okyKedjX5/0He9iP/j63LwOQdarEVlfy8OO/Lqw023j6xcqmwxLiOd6heM2i9cV9LJy8jMJ23yQ+rpbfu7EQ/pXE8KYvUSqvVnb4XzZa6LrHMXHR+zcLvqWbm/Bn0/HzIs6fWPHoat8XfnDKmZGxRxeMbn2UqZ5Q94nmcZRbqqUXbZ8+lcjE+cPX11t814orvvAXNcG8vqj2vvk1MGn3anlj0bIT72v47bvE+Lc98T9b6r7AKn6j+8Duf7D0nnZx/j7Zjn0j9nbpSTndaLr9WNLivP+iN23xF7L+fqv6ZouFyb78jxVXvv5jJ9YUs9/sddO8h7KNg5jrhfaJGztT6G7KF+1d6yCmD5Kdb2fan60rSc552fZr3zeQ9DpnPp+Si5cx5Ktv2QfSzF/mMbWdOm46rFI4XstnU9xeqX4NKb7TKEdcr6pZOK3ID1k/LvFHkVczEuZLEDr499YqvqBym1aEHWgcvoYOtv0M91qQl5TfpO/in6rWx8OVpT1Wedkv3f5xom3T/xeR/6Gx6V86PWAOB4bBpqWdN+yTcVxjIyGRz/FrDGu6w/3d7kPm8StX8RyPu+uuvpNju/vTLJV37GpvoM0oZPnW87VLnL/5pDno1NoW1R6yedU6TyUv3u19a3KFnIbTLYz+ZCLP4T0tU1uivFgso0pnsJ/UtXvarNY28Xq5cvkBDrQP/E5ZaiuQwwfmTlsOiQRU1fMuqrDd/3ISSuwjOwXOfTyGUMpZIXq4GpLn3pUcdfzch2x7XO1u2uZHOPb1G6b3Xg9PH1IIWeEpJlPQtqos2EKW8b0u8rnuP1UeVLoXJb9be0uG9nnbchjU+XTszT5VeNBThPHnc5OKj1U9aj0GTHIVaGy1YhEWT4ixns00DT+XEzWn/7VAsIc63Cov3OdyhwjrnaqQqZvWKXdypRdlq+k8msZ031U+Rm4fA+3TtyeR9hwfW9G9yxDN0fZMN33F+9TE6md4hwoxumfaUzI9fN3PFT3xVV2msrQ3UsnChm6Nulk8TndpS28D3zX9tTIPsF/z7Am5OkTjm1tI1JZW74+4VgsZ0N3L1yXV3WeP5uR7TGHHdvC3JQlxybfpd22tDlk/2eofRK8TzrN/qnar/K/OUTth6I/+jAnEptNbPvFHP2gs40N3+dfMWtwqvVct7/wfd8gtQ7imifial9ZJ9/3IHLYU6eDj3+4PhsNhX+vwvcWLnu6kGfEMe8DuciPfUfGZB8X/7HJy/Gefe5n+VRGFd/wyP2ta7/LO4yh/sbLV/k9lev6kfO9Dt/5U67b1/6u/epqB1U9Me23jfHY9sscAg4tkbLl+e4/U36rJ9ddxfd6sg5vq5ice42Wpk/pb9FOJ36/W9tpv4kbC79nUbZceX8Zu6/qJ+P3WvhvA8v3reh7Jbn2d6rrNC7XNZTLma4Ba0JI9efX2uLzF5scG/w9UNU1ZxW+ymUfzELeTllXlQ1rUuhzjS5fp9c964iFBOqeSz63bU065nZKdU+mDEz3qHIjjifquw0pnb/raRtvrnsYcb46ihT3taoYz6brdNW9l6rWRnE/navdPn1XlR1km7hcz1WlH/elKuSOSvLLuE8U6m8uzwRdfcGl73VyTHuyMvzJ1Sa2cWDTP/Z63Kc94n2B1PYr24dz1JlyHLlcP+S4B6vD1c9EW4q2LWstCvUjeVy63k/LMYdUNd5D1xQfvVTzX1VjkMsUv88N8VH5fReVn/Fjn++/h6X6Q8a6b1/q3g/i/ewi0/Scs8zxXeV6mWIOUPlPzBgdFerW+bZrm2P18dnjuK6HunEp+rHvPMXbr+sHVb/lnL+pTP57jPw9Cvk3PW178JD9qChfzuvTf7Htl38L1QUf/VKu9SFjwWbTWPvFEvu7Uq76y7+31g6QlYPc669pbsm9Xur2LWI9Pu8ypfDXqm3A2z8s1FWGn4ntL9NfQu2oSlftX9uetvTtv7J8Ql4zxfXGZ3zk8PeQ9w59x2uMfqI8/q5eKh/l9cb2rwsu9rSNl06ZP2Pmxtz+rNMx93yno0n2/82rVH7rQ+y9P15H6FyRun9ViH81ATmffI7nJ5r8uXXW6enbP6b/B8/l5OifVHYLnb9S39s2zcc+Ph+rh8+eQgVPS72elzGWY/tUtbbabBpDiI7yN1q6/4th2y+ErAc5+9BVvu/7KamJbWNZeuqI/R4tRf+YyD1HmOZM1bMV3/14Sn10c0Xu+Sj1nOXb5jL73ncdy02uvlXZNde65dOHYl7Vs4KYuS6FzWLn2zJlpZqPXPVPOa5yzKOyn1VhT9lmMfdbfH7D11Wf2PXN5h9y+dD287+qxgSnaYmnIrRtIb8pJe6/Uv9OVer6Whn0zfGO/BEloZI9ojmfAlUflClDd178bTmVHVTpZXOkAlk/lb42UujmI89HH5V+cl7XtowY6vTxLVWok6UrGzoGTHN+bB+6ri05687VNpvfuvRfaP2uMlNQth1D5JjGelm/8yn+9p3p/7qk9gnfeddXZmq/Sm333PJT659Kv1zjNbZ9uv2Oi//67CV8/N1nj1DmviyXDNVeJkaeaX8UsyesYg8cu2+NvdaPfb+lLDu5tvt/")), hh = function(a) {
switch (a) {
case 33:
case 39:
case 40:
case 42:
return 12;
case 35:
return 5;
default:
return a;
}
}, uh = function(a) {
switch (a) {
case 37:
case 38:
return 34;
case 41:
return 22;
default:
return a;
}
};
class Ca {
constructor(e, t = !1) {
this.position = e, this.required = t;
}
}
Cl = class {
nextCodePoint() {
const a = this.string.charCodeAt(this.pos++), e = this.string.charCodeAt(this.pos);
return 55296 <= a && a <= 56319 && 56320 <= e && e <= 57343 ? (this.pos++, 1024 * (a - 55296) + (e - 56320) + 65536) : a;
}
nextCharClass() {
return hh(Cp.get(this.nextCodePoint()));
}
getSimpleBreak() {
switch (this.nextClass) {
case 41:
return !1;
case 34:
case 37:
case 38:
return this.curClass = 34, !1;
case 36:
return this.curClass = 36, !1;
}
return null;
}
getPairTableBreak(a) {
let e = !1;
switch (Ep[this.curClass][this.nextClass]) {
case 0:
e = !0;
break;
case 1:
e = a === 41;
break;
case 2:
if (e = a === 41, !e) return e = !1, e;
break;
case 3:
if (a !== 41) return e;
}
return this.LB8a && (e = !1), !this.LB21a || this.curClass !== 16 && this.curClass !== 17 ? this.LB21a = this.curClass === 13 : (e = !1, this.LB21a = !1), this.curClass === 28 ? (this.LB30a++, this.LB30a == 2 && this.nextClass === 28 && (e = !0, this.LB30a = 0)) : this.LB30a = 0, this.curClass = this.nextClass, e;
}
nextBreak() {
if (this.curClass == null) {
let a = this.nextCharClass();
this.curClass = uh(a), this.nextClass = a, this.LB8a = a === 31, this.LB30a = 0;
}
for (; this.pos < this.string.length; ) {
this.lastPos = this.pos;
const a = this.nextClass;
if (this.nextClass = this.nextCharClass(), this.curClass === 34 || this.curClass === 36 && this.nextClass !== 37) return this.curClass = uh(hh(this.nextClass)), new Ca(this.lastPos, !0);
let e = this.getSimpleBreak();
if (e === null && (e = this.getPairTableBreak(a)), this.LB8a = this.nextClass === 31, e) return new Ca(this.lastPos);
}
return this.lastPos < this.string.length ? (this.lastPos = this.string.length, new Ca(this.string.length)) : null;
}
constructor(a) {
this.string = a, this.pos = 0, this.lastPos = 0, this.curClass = null, this.nextClass = null, this.LB8a = !1, this.LB21a = !1, this.LB30a = 0;
}
};
class bp {
constructor(e) {
this._textMeasurer = e;
}
_measureText(e) {
const t = this._fontSize, n = this._fontName, r = this._metricOptions;
if (this._isSuperSub) {
const o = this._textMeasurer(e, 0.6 * t, n, r);
return { ...this._textMeasurer("M", t, n, r), width: o.width };
}
return this._textMeasurer(e, t, n, r);
}
_breakWord(e, t, n) {
let r = 0;
for (; r < e.length; ) {
let o = { startPosition: this._charactersRead + r, text: "", x: 0, y: 0, width: 0, widthWhitespace: 0, height: 0, baseline: 0 }, s = !1, i = 0;
const l = this._maxWidth;
do {
s = !1;
const c = e.substring(r, r + i + 1), h = c.replace(/\s+$/, ""), u = this._measureText(h);
let d = u;
c.length !== h.length && (d = this._measureText(c)), (o.x + u.width <= l || c.length <= 1) && (o.text = c, o.width = u.width, o.widthWhitespace = d.width, o.height = Math.max(o.height, u.lineHeight), o.baseline = Math.max(o.baseline, u.baseline), s = !0, i++);
} while (s && r + i < e.length);
if (s) {
const c = e.substring(r, e.length), h = c.replace(/\s+$/, ""), u = this._measureText(h);
let d = u;
c.length !== h.length && (d = this._measureText(c)), t.startPosition = this._charactersRead + r, t.width = u.width, o.widthWhitespace = d.width, t.height = Math.max(t.height, u.lineHeight), t.baseline = Math.max(t.baseline, u.baseline), t.text = c;
} else if (n?.(o) === !1) return !1;
r += i;
}
}
_breakWhiteSpace(e, t = null) {
for (; e && this._charactersRead < e.length; ) {
let n = { startPosition: this._charactersRead, text: "", x: 0, y: 0, width: 0, widthWhitespace: 0, height: 0, baseline: 0 }, r = !1;
const o = this._maxWidth, s = this._indent, i = this._breaker;
do
if (r = !1, n.startPosition === 0 && n.text.length === 0 && (n.x = s, this._lastBreak = i.nextBreak()), this._lastBreak) {
const c = e.substring(n.startPosition, this._lastBreak.position), h = c.replace(/\s+$/, ""), u = this._measureText(h);
let d = u;
c.length !== h.length && (d = this._measureText(c)), n.x + u.width <= o ? (n.text = c, n.width = u.width, n.widthWhitespace = d.width, n.height = Math.max(n.height, u.lineHeight), n.baseline = Math.max(n.baseline, u.baseline), r = !0, this._charactersRead = this._lastBreak.position) : n.text.length === 0 && this._breakWord(c, n, t) !== !1 && (r = !0, this._charactersRead = this._lastBreak.position), (r || c.indexOf(`
`) === -1) && this._lastBreak.required && (this._lastBreak = i.nextBreak(), r = !1);
}
while (r && (this._lastBreak = i.nextBreak()));
if (t?.(n) === !1) return !1;
}
}
wrap(e, t = null) {
this._breaker = new Cl(e), this._linesRead = [], this._charactersRead = 0, this._maxXRead = 0, this._maxXWhitespaceRead = 0, this._maxYRead = 0, this._fontName = t?.fontName ?? "Arial", this._fontSize = t?.fontSize ?? 12, this._metricOptions = { isBold: t?.bold ?? !1, isItalic: t?.italic ?? !1, letterSpacing: t?.letterSpacing ?? 0 }, this._isSuperSub = t?.superSub ?? !1, this._indent = t?.indent ?? 0, this._maxWidth = t?.maxWidth ?? Number.MAX_SAFE_INTEGER, this._maxWidth <= 0 && (this._maxWidth = Number.MAX_SAFE_INTEGER), this._maxHeight = t?.maxHeight ?? Number.MAX_SAFE_INTEGER, this._maxHeight <= 0 && (this._maxHeight = Number.MAX_SAFE_INTEGER);
const n = (o) => {
if (this._linesRead.length > 0) {
let s = this._linesRead[this._linesRead.length - 1];
o.y = s.y + s.height;
}
if (o.y + o.height > this._maxHeight) return !1;
this._maxXRead = Math.max(this._maxXRead, o.x + o.width), this._maxXWhitespaceRead = Math.max(this._maxXWhitespaceRead, o.x + o.widthWhitespace), this._maxYRead = Math.max(this._maxYRead, o.y + o.height), this._linesRead.push(o);
};
if (e === "") {
const o = this._measureText(e);
n({ startPosition: 0, text: "", x: 0, y: 0, width: 0, widthWhitespace: 0, height: o.lineHeight, baseline: o.baseline });
} else if (this._breakWhiteSpace(e, n), new Cl(e.charAt(e.length - 1).repeat(2)).nextBreak().required) {
const o = this._measureText(e);
n({ startPosition: e.length, text: "", x: 0, y: 0, width: 0, widthWhitespace: 0, height: o.lineHeight, baseline: o.baseline });
}
const r = { bounds: { x: 0, y: 0, width: this._maxXRead, widthWhitespace: this._maxXWhitespaceRead, height: this._maxYRead }, lines: this._linesRead };
return this._breaker = null, this._linesRead = [], r;
}
}
const vp = (a, e, t, n = null, r = te.getSharedMeasurer()) => {
let o = "", s = null, i = null;
const l = a.paragraphs, c = l.length;
for (let y = 0; y < c; y++) {
const C = l[y].runs, w = C.length;
for (let b = 0; b < w; b++) o += C[b].text, b === 0 && (s = C[b]);
y === 0 && (i = l[y]);
}
const h = a.insets ?? Hi.EmptyRect, u = new bp(r), d = n?.width ? n.width - h.right - h.left : n?.width, g = n?.height ? n.height - h.bottom - h.top : null, m = u.wrap(o, { fontName: s.fontName, fontSize: s.fontSize * te.getDeviceScale(), bold: s.bold, italic: s.italic, superSub: s.superSub, letterSpacing: s.letterSpacing, maxWidth: a.wrapped && d ? d : null, maxHeight: g });
let f = [];
const _ = m.lines, p = _.length, S = new Array(p);
for (let y = 0; y < p; y++) {
const C = _[y], w = { x: C.x, y: C.y, width: C.width, height: C.height }, b = new $i({ text: C.text, fontName: s.fontFamily, fontSize: s.fontSize, bold: s.bold, italic: s.italic, superSub: s.superSub, letterSpacing: s.letterSpacing }, w);
f.push(b), S[y] = new Eg(w, C.baseline, [b]);
}
const E = new Vi({ runs: f, align: i.align });
return new ji({ paragraphs: [E], wrapped: a.wrapped, verticalAlignment: a.verticalAlignment }, e, t, S, { x: m.bounds.x, y: m.bounds.y, width: m.bounds.widthWhitespace, height: m.bounds.height }, { x: m.bounds.x, y: m.bounds.y, width: m.bounds.width, height: m.bounds.height });
}, dh = (a) => {
let e = !1, t = !1;
for (let n = 0; n < a.length; n++) {
const r = a.charCodeAt(n);
if (r >= 65 && r <= 90 ? e = !0 : r >= 97 && r <= 122 && (t = !0), e && t) return 0;
}
return e ? 1 : t ? -1 : 0;
}, Gi = (a, e, t, n, r = !1) => {
if (a == null) return null;
const o = new $i({ text: a, fontName: e.toCSS().fontFamily, fontSize: e.getSize(), bold: e.getWeight() > 400, italic: e.getStyle() === te.Style.Italic, superSub: !r && (e.getVerticalAlignment() === te.VerticalAlignment.Sub || e.getVerticalAlignment() === te.VerticalAlignment.Super), letterSpacing: e.getLetterSpacing() }), s = r ? X.HorizontalAlignment.Left : t.getHorizontal(), i = t.getVertical(), l = new Vi({ runs: [o], align: s });
let c = [];
return c.push(new Eg(null, e.getSize(), [o])), new ji({ paragraphs: [l], wrapped: n && (t.getOverflow() === X.Overflow.Wrap || s === X.HorizontalAlignment.Justify || s === X.HorizontalAlignment.Distributed || i === X.VerticalAlignment.Justify || i === X.VerticalAlignment.Distributed), verticalAlignment: i }, e, t, c);
}, _s = (a, e, t, n) => ({ x: a * n - e * t, y: a * t + e * n }), gh = (a) => {
let e = 0, t = 0, n = 0, r = 0, o = 0, s = 0, i = 0, l = a.length;
if (l === 0) return { m: 0, b: 0 };
if (l === 1) return { m: 1, b: a[0] };
for (let h = 0; h < l; h++) s = h + 1, i = a[h], i == null || isNaN(i) || (e += s, t += i, r += s * s, n += s * i, o++);
const c = (o * n - e * t) / (o * r - e * e);
return { m: c, b: t / o - c * e / o };
}, bl = (a, e) => {
if (e === null) return null;
const t = F.isObject(e);
return a != null && t ? F.mergeContentful(a, e) : t ? F.cloneObject(e) : e;
}, xp = (a, e, t) => a == null || typeof a == "object" && Object.keys(a).length === 0;
function Zl(a, e, t, n) {
if (a === e) return a ?? null;
}
function Ip(a) {
return a == null;
}
function Rp(a, e, t = 1, n) {
if (t === 0) return { preceding: a ? [...a] : [], modified: [], trailing: [] };
const r = function(l, c, h = 1) {
let u = F.findEqualOrGreater(l, c, (f) => f.max);
const d = l.slice(0, u), g = [], m = [];
if (!l[u]) return { preceding: d, modified: g, trailing: m };
for (let f = u; f < l.length; f++) c + h < l[f].min ? m.push({ ...l[f], min: l[f].min - h, max: l[f].max - h }) : c >= l[f].min ? Math.max(c, l[f].max + 1 - h) > l[f].min && g.push({ ...l[f], max: Math.max(c - 1, l[f].max - h) }) : c < l[f].min && c + h <= l[f].max && g.push({ ...l[f], min: Math.max(c, l[f].min - h), max: l[f].max - h });
return { preceding: d, modified: g, trailing: m };
}(a, e, t), o = r.preceding, s = r.trailing;
let i = [];
return o.length > 0 && i.push(o.pop()), i = i.concat(r.modified), s.length > 0 && i.push(s.shift()), { preceding: o, modified: Go(i, { onMerge: Zl }).modified, trailing: s };
}
function vl(a, e, t) {
if (!a) throw new Error("runs can not be null");
if (!e) return { preceding: [], modified: a ? [...a] : [], trailing: [] };
const n = function(s, i, l, c, h = !1) {
if (!i) return { preceding: [], modified: s ? [...s] : [], trailing: [] };
let u, d = F.findEqualOrGreater(s, i.min, (S) => S.max), g = s.slice(0, d), m = s.slice(d), f = [], _ = { ...i }, p = m[0] || { min: i.min, max: i.max, value: void 0 };
for (u = h ? (S, E, y) => {
const C = (c || bl)(E, y, S);
C !== void 0 ? S.value = C : delete S.value, f.push(S);
} : (S, E, y) => {
const C = (c || bl)(E ?? null, y, S);
C !== void 0 ? S.value = C : delete S.value, f.push(S);
}; m.length >= 0 && _.max - _.min >= 0; ) {
if (_.min < p.min) u({ min: _.min, max: Math.min(_.max, p.min - 1) }, void 0, _.value), _ = { min: p.min, max: _.max, value: _.value }, p = { min: _.min, max: p.max, value: p.value };
else if (_.min > p.min) {
const S = p.value !== void 0 && l ? l(p, _.min) : [p.value, p.value];
f.push({ min: p.min, max: Math.min(_.min, p.max) - 1, value: S[0] }), _ = { min: Math.min(_.min, p.max), max: _.max, value: _.value }, p = { min: _.min, max: p.max, value: S[1] };
} else {
const S = p.value !== void 0 && l ? l(p, _.min) : [p.value, p.value];
u({ min: p.min, max: Math.min(_.max, p.max) }, S[0], _.value), _ = { min: Math.min(_.max, p.max) + 1, max: _.max, value: _.value }, p = { min: Math.min(_.max, p.max) + 1, max: p.max, value: S[1] };
}
p.min <= p.max ? m[0] = p : (m = m.slice(1), p = m[0] || { min: p.min, max: _.max });
}
return { preceding: g, modified: f, trailing: m };
}(a, e, t?.onSplit, t?.onUpdate, t?.inPlace);
let r = [];
n.preceding.length > 0 && r.push(n.preceding.pop()), r = r.concat(n.modified), n.trailing.length > 0 && r.push(n.trailing.shift());
const o = function(s, i) {
if (!s || s.length === 0) return { preceding: [], modified: s ? [...s] : [], trailing: [] };
const l = Math.min(s.length - 1, i?.startOffset ?? 0), c = Math.min(s.length, i?.endOffset ?? s.length), h = i?.cull ?? Ip;
let u = s.slice(0, l), d = s.slice(c);
const g = [];
for (let m = l; m < c; m++) h(s[m].value, s[m].min, s[m].max) !== !0 && g.push(s[m]);
return { preceding: u, modified: g, trailing: d };
}(Go(r, { onMerge: t?.onMerge ?? Zl }).modified, { cull: t?.isCull || xp });
return { preceding: n.preceding, modified: o.modified, trailing: n.trailing };
}
function Wn(a) {
return [...a.preceding, ...a.modified, ...a.trailing];
}
function Go(a, e) {
if (!a || a.length === 0) return { preceding: [], modified: a ? [...a] : [], trailing: [] };
const t = Math.min(a.length - 1, e?.startOffset ?? 0), n = Math.min(a.length, e?.endOffset ?? a.length), r = e?.onMerge ?? Zl;
let o = a.slice(0, t), s = a.slice(n);
const i = [];
let l = { ...a[t] }, c = a[t]?.max || 0;
for (let h = t + 1; h <= n; h++) {
const u = a[h];
let d = !1;
if (u && u.min <= a[h - 1].max + 1) if (l.value === void 0 && u.value === void 0) d = !0;
else {
const g = r(l.value, u.value, l.max - l.min + 1, u.max - u.min + 1);
g !== void 0 && (d = !0, l.value = g);
}
d ? l.max = Math.max(c, u.max) : (i.push(l), l = { ...a[h] }, u && (l.max = Math.max(c, u.max))), l && (c = l.max);
}
return { preceding: o, modified: i, trailing: s };
}
const mh = (a, e = !1) => {
if (!a || a.length === 0) return F.EmptyArray;
const t = e ? a : a.sort(), n = [];
let r = null;
for (let o = 0; o < t.length; o++) {
const s = t[o];
r ? r.max === s - 1 ? r.max = s : (n.push(r), r = { min: s, max: s }) : r = { min: s, max: s };
}
return r && n.push(r), n;
}, fh = (a, e) => a ? e ? a || e ? a.min > e.max || a.max < e.min ? null : { min: Math.max(a.min, e.min), max: Math.min(a.max, e.max) } : null : { ...a } : { ...e }, bg = (a) => {
const e = a.length === 0;
return { runs: a, run: { min: e ? Number.MIN_SAFE_INTEGER : Number.MAX_SAFE_INTEGER, max: e ? Number.MAX_SAFE_INTEGER : Number.MIN_SAFE_INTEGER, value: null }, index: Number.MAX_SAFE_INTEGER };
}, vg = (a, e) => {
const t = e.run, n = t.min, r = t.max;
if (a >= n && a <= r) return t.value;
let o = e.index;
const s = e.runs;
if (o < s.length - 1 && a > r) {
o++;
const h = s[o], u = h.min, d = h.max;
if (a >= u && a <= d) return e.index = o, t.min = u, t.max = d, t.value = h.value, t.value;
}
if (o !== Number.MAX_SAFE_INTEGER && o > 0 && a < n) {
o--;
const h = s[o], u = h.min, d = h.max;
if (a >= u && a <= d) return e.index = o, t.min = u, t.max = d, t.value = h.value, t.value;
}
if (o = F.findEqualOrGreater(s, a, (h) => h.max), o === s.length) return o = s.length, e.index = o, t.min = s[o - 1].max + 1, t.max = Number.MAX_SAFE_INTEGER, t.value = null, null;
const i = s[o], l = i.min, c = i.max;
if (a >= l && a <= c) {
e.index = o, t.min = l, t.max = c;
const h = i.value;
return t.value = h, h;
}
return o--, e.index = o, t.min = o >= 0 ? s[o].max + 1 : Number.MIN_SAFE_INTEGER, t.max = l - 1, t.value = null, null;
}, ph = function(a, e, t, n) {
if (a.length === 0) {
if (t != null || n != null) {
const c = e({ min: t ?? n, max: n ?? t });
if (c && c.break) return c;
}
return;
}
const r = t ?? a[0].min, o = n ?? a[a.length - 1].max;
let s = r - 1, i = F.findEqualOrGreater(a, r, (c) => c.max), l = a[i];
for (; l && l.min <= o; ) {
if (s < l.min - 1) {
const h = e({ min: Math.max(s + 1, r), max: Math.min(l.min - 1, o) });
if (h && h.break) return h;
}
const c = e({ ...l, min: Math.max(l.min, r), max: Math.min(l.max, o) });
if (c && c.break) return c;
s = l.max, l = a[++i];
}
if (s < o) {
const c = e({ min: Math.min(s + 1, o), max: o });
if (c && c.break) return c;
}
}, _h = new RegExp("([0-9]+)$");
var vi, Sh, Y, Ss, N, ws;
((a) => {
a.Date = class {
constructor(i) {
this._options = i;
}
canFill(i, l) {
return to(i);
}
createFillAt(i, l) {
l = { ...this._options, ...l };
let c = 0, h = this._options?.unit;
h || (h = i.length === 1 ? fs : ((g, m = !1) => {
if (!g || g.length < 1) return fs;
let f = g;
m || (f = g.slice(), f = f.sort((E, y) => E.getTime() - y.getTime()));
let _ = !1, p = -1, S = -1;
for (let E = 0; E < f.length; E++) {
let y = f[E];
if (E > f.length - 1 && y.getTime() < f[E + 1].getTime()) throw new Error("Dates are expected to be sorted.");
let C = 12 * y.getFullYear() + y.getMonth();
if (C === S) return fs;
S = C;
let w = y.getFullYear();
w > p ? p = w : _ = !0;
}
return _ ? Gc : Uc;
})(i));
const u = Jc(i[0], 0, h);
u.setHours(0, 0, 0, 0);
let d = 1;
l?.reverse && (d *= -1, c *= -1);
for (let g = 1; g < i.length; g++) {
let m = np(i[g - 1], i[g], h);
if (g === 1) d = m;
else if (m !== d) return null;
}
return i.length === 1 && l.multiFill, (g) => {
const m = Jc(u, d * g, h);
if (c !== 0) {
const f = 0 + c * g, _ = f % 1440, p = Math.floor(_ / 60), S = _ % 60;
m.setHours(p, S, 0, 0);
const E = Math.floor(f / 1440), y = Math.floor(E / 365), C = E % 365, w = Math.floor(C / 30), b = C % 30;
y > 0 && m.setFullYear(m.getFullYear() + y), w > 0 && m.setMonth(m.getMonth() + w), b > 0 && m.setDate(m.getDate() + b);
}
return m;
};
}
}, a.Linear = class {
constructor(i) {
this._options = i;
}
canFill(i, l) {
return typeof i == "number" || i === null;
}
createFillAt(i, l) {
l = { ...this._options, ...l };
const c = gh(i), h = c.b;
let u = c.m;
return i.length === 1 ? (l.reverse && (u = -u), l.multiFill ? (d) => d * u + h : null) : (d) => u * (d + 1) + h;
}
};
const e = { value: null, template: null }, t = { sensitivity: "accent" };
a.Ordinal = class {
_template(i) {
const l = i.match(_h);
if (!l) return null;
const c = l[1], h = i.lastIndexOf(c);
return h === -1 ? null : i.substring(0, h);
}
canFill(i, l) {
if (i === null) return !0;
if (typeof i != "string") return e.value = null, !1;
const c = this._template(i);
return c && (l === void 0 || l === e.value && c.localeCompare(e.template, void 0, t) === 0) ? (e.value = i, e.template = c, !0) : (e.value = null, !1);
}
createFillAt(i, l) {
const c = [], h = i[0];
let u = null, d = null, g = 0;
if (h) {
const S = h.match(_h);
if (S) {
u = S[1], u.startsWith("0") && (g = u.length);
const E = h.lastIndexOf(u);
d = h.substring(0, E);
}
}
const m = i.length;
for (let S = 0; S < m; S++) {
const E = i[S];
let y = null;
if (E) {
const C = E.substring(d.length, E.length);
C.startsWith("0") && (g = Math.max(g, C.length));
const w = parseFloat(C);
isNaN(w) || (y = w);
}
c.push(y);
}
const f = gh(c), _ = f.b;
let p = f.m;
return p !== 0 && Number.isInteger(p) ? (S) => {
if (i[S % m] === null) return null;
const E = (m === 1 ? l.reverse ? -S : S : p * (S + 1)) + _, y = "" + Math.abs(E), C = "0".repeat(Math.max(0, g - y.length)) + y;
return d + C;
} : null;
}
}, a.Copy = class {
canFill(i, l) {
return !0;
}
createFillAt(i, l) {
const c = i.length;
return (h) => i[h % c] ?? null;
}
};
const n = Object.freeze(["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]), r = Object.freeze(["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]), o = Object.freeze(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]), s = Object.freeze(["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]);
a.List = class {
constructor(i) {
this._lists = [], this._map = /* @__PURE__ */ new Map();
const l = [];
if (i?.customLists) {
const u = i.customLists;
for (let d = u.length - 1; d > 0; d--) l.push(u[d]);
}
l.push(s), l.push(o), l.push(r), l.push(n);
const c = this._map, h = [];
for (let u = 0; u < l.length; u++) {
const d = l[u], g = [];
h.push(g);
for (let m = 0; m < d.length; m++) {
const f = d[m], _ = Xr(f, !0), p = _.toLowerCase().trim();
let S = c.get(p);
S || (S = [], c.set(p, S));
const E = { value: _, asKey: p, major: u, minor: m };
S.push(E), g.push(E);
}
}
this._lists = Object.freeze(h);
}
canFill(i, l) {
return i === null ? !0 : typeof i != "string" ? !1 : !!this._map.get(i.toLowerCase().trim());
}
createFillAt(i, l) {
const c = [], h = i[0];
c.push(h.toLowerCase().trim());
const u = this._map.get(c[0]);
let d;
const g = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Set();
for (let v = 0; v < u.length; v++) {
const R = u[v];
g.set(R.major, R);
}
if (i.length > 1) {
for (let v = 1; v < i.length; v++) {
const R = i[v].toLowerCase().trim(), A = this._map.get(R);
if (!A) return null;
v === 1 && (d = A), c.push(R);
for (let M = 0; M < A.length; M++) {
const T = A[M].major;
g.has(T) && m.add(T);
}
}
if (m.size === 0) return null;
}
let f = null;
const _ = this._lists;
for (let v = 0; !f && v < _.length; v++) (i.length === 1 || m.has(v)) && (f = g.get(v));
if (!f) return null;
let p = null;
for (let v = 0; !p && d && v < d.length; v++) d[v].asKey === c[1] && (p = d[v]);
let S = !1, E = !1;
const y = dh(h);
y === 1 ? S = !0 : (y === -1 || dh(h[0]) === -1) && (E = !0);
const C = _[f.major];
let w = f.minor, b = 1;
if (c.length > 1) {
b = p.minor - f.minor;
for (let v = 2; v < c.length; v++) if (C[v + w].minor - C[v - 1 + w].minor !== b) return null;
}
i.length === 1 && l?.reverse && (b = -b);
const x = i.length, I = C.length;
return (v) => {
if (i[v % x] === null) return null;
let R = (v * b + w) % I;
R < 0 && (R = I + R);
const A = C[R].value ?? null;
return S ? A.toUpperCase() : E ? A.toLowerCase() : A;
};
}
}, a.Composite = class {
constructor(i) {
i = Array.isArray(i) ? [...i] : [i], this._fillers = i;
}
canFill(i, l) {
return !0;
}
createFillAt(i, l) {
const c = this._fillers;
l = { multiFill: i.length > 1, ...l };
const h = i.length;
let u = 0, d = !1;
for (let b = 0; !d && b <= h; b++) i[b] === null ? u++ : d = !0;
let g = 0;
d = !1;
for (let b = h - 1; !d && b >= u; b--) i[b] === null ? g++ : d = !0;
const m = [];
let f = null, _ = null, p = [], S = u, E = 0;
const y = (b) => {
if (f && f.max + 1 === S) {
const x = f.value;
x.fillAt.push(b), f.max = S, x.length++, x.valuesLength++;
} else f = { min: S, max: S, value: { fillAt: [b], start: S, length: 1, valuesLength: h, blankInterval: 0 } };
m.push(f);
}, C = h - g;
for (S = u; S < C; ) {
let b = i[S];
if (b === null) {
S++;
continue;
}
_ = null;
let x, I = 1, v = !1;
for (let T = 0; !v && T < c.length + 1; T++) {
const k = c[T];
k && (v = k.canFill(b, x), v && (_ = k));
}
if (!_) {
b !== null && y(b), S++;
continue;
}
let R = 0;
E = 0, x = b;
do
b = i[S + I], v = _.canFill(b, x), v && (b !== null ? (x = b, R > 0 && (I - R === 1 ? E = R : R !== E && (E = 0)), R = 0) : R++, I++);
while (v && S + I < C);
p = [i[S]];
const A = 1 + E, M = I - R;
for (let T = A; T < M; T += A) p.push(i[S + T]);
if (p.length > 0) {
const T = p.length, k = T + (T - 1) * E, P = _.createFillAt?.(p, l) ?? p;
m.push({ min: S, max: S + k - 1, value: { fillAt: P, start: S, length: k, valuesLength: T, blankInterval: E } });
}
S += I;
}
const w = bg(m);
return (b) => {
const x = b >= 0, I = Math.abs(b), v = vg(I % h, w);
if (!v) return null;
const R = Math.floor(I / h), A = v.length, M = v.start, T = (R + (x ? 1 : 0)) * M + (R + (x ? 0 : 1)) * (h - (M + A));
let k = b + (x ? -T : T);
const P = v.blankInterval;
if (P !== 0) {
let H = k % A;
if (H % (1 + P) !== 0) return null;
k = Math.floor(H / (1 + P)) + v.valuesLength * R;
}
const B = v.fillAt;
return typeof B == "function" ? B(k) : B[k % B.length];
};
}
}, a.Types = { Series: new a.Composite([new a.Date(), new a.Linear(), new a.Ordinal(), new a.List()]), DateDays: new a.Date({ unit: fs }), DateMonths: new a.Date({ unit: Gc }), DateYears: new a.Date({ unit: Uc }), Copy: new a.Copy() }, a.fillTo = (i, l, c, h) => {
const u = [], d = l.length, g = i.createFillAt(l, h);
for (let m = d; m < c; m++) u.push(g(m));
return u;
};
})(vi || (vi = {})), Sh || (Sh = {}), (Ss = Y || (Y = {})).Type = { None: "none", Solid: "solid", Gradient: "gradient", Pattern: "pattern", Image: "pattern", Background: "background", Group: "group", Custom: "custom" }, Ss.GradientType = { Linear: "linear", Path: "path", Circular: "circular", Rect: "rect" }, Ss.TileMirror = { None: "none", Vertical: "v", Horizontal: "h", Both: "b" }, Ss.BuiltInSheetPattern = { None: "none", Solid: "solid", DarkGray: "darkGray", MediumGray: "mediumGray", LightGray: "lightGray", Gray0625: "gray0625", Gray125: "gray125", DarkHorizontal: "darkHorizontal", DarkVertical: "darkVertical", DarkDown: "darkDown", DarkUp: "darkUp", DarkGrid: "darkGrid", DarkTrellis: "darkTrellis", LightHorizontal: "lightHorizontal", LightVertical: "lightVertical", LightDown: "lightDown", LightUp: "lightUp", LightGrid: "lightGrid", LightTrellis: "lightTrellis", Custom: "custom" }, (ws = N || (N = {})).AdjustmentType = { Alpha: "alpha", AlphaOff: "alphaOff", AlphaMod: "alphaMod", Hue: "hue", Sat: "sat", Lum: "lum", HueOff: "hueOff", SatOff: "satOff", LumOff: "lumOff", HueMod: "hueMod", SatMod: "satMod", LumMod: "lumMod", Red: "red", Green: "green", Blue: "blue", RedOff: "redOff", GreenOff: "greenOff", BlueOff: "blueOff", RedMod: "redMod", GreenMod: "greenMod", BlueMod: "blueMod", Shade: "shade", Tint: "tint", ETint: "eTint", Gray: "gray", Comp: "comp", Inv: "inv", Gamma: "gamma", InvGamma: "invGamma" }, ws.Named = { ActiveBorder: "activeBorder", ActiveCaption: "activeCaption", CaptionText: "captionText", AppWorkspace: "appWorkspace", BtnFace: "btnFace", BtnShadow: "btnShadow", DkShadow3d: "3dDkShadow", BtnHighlight: "btnHighlight", Light3d: "3dLight", BtnText: "btnText", Background: "background", GrayText: "grayText", Highlight: "highlight", HighlightText: "highlightText", HotLight: "hotLight", InactiveBorder: "inactiveBorder", InactiveCaption: "inactiveCaption", InactiveCaptionText: "inactiveCaptionText", InfoBk: "infoBk", InfoText: "infoText", Menu: "menu", MenuText: "menuText", ScrollBar: "scrollBar", Window: "window", WindowFrame: "windowFrame", WindowText: "windowText", Transparent: "transparent", AliceBlue: "aliceBlue", AntiqueWhite: "antiqueWhite", Aqua: "aqua", Aquamarine: "aquamarine", Azure: "azure", Beige: "beige", Bisque: "bisque", Black: "black", BlanchedAlmond: "blanchedAlmond", Blue: "blue", BlueViolet: "blueViolet", Brown: "brown", BurlyWood: "burlyWood", CadetBlue: "cadetBlue", Chartreuse: "chartreuse", Chocolate: "chocolate", Coral: "coral", CornflowerBlue: "cornflowerBlue", Cornsilk: "cornsilk", Crimson: "crimson", Cyan: "cyan", DkBlue: "dkBlue", DkCyan: "dkCyan", DkGoldenrod: "dkGoldenrod", DkGray: "dkGray", DkGreen: "dkGreen", DkKhaki: "dkKhaki", DkMagenta: "dkMagenta", DkOliveGreen: "dkOliveGreen", DkOrange: "dkOrange", DkOrchid: "dkOrchid", DkRed: "dkRed", DkSalmon: "dkSalmon", DkSeaGreen: "dkSeaGreen", DkSlateBlue: "dkSlateBlue", DkSlateGray: "dkSlateGray", DkTurquoise: "dkTurquoise", DkViolet: "dkViolet", DeepPink: "deepPink", DeepSkyBlue: "deepSkyBlue", DimGray: "dimGray", DodgerBlue: "dodgerBlue", Firebrick: "firebrick", FloralWhite: "floralWhite", ForestGreen: "forestGreen", Fuchsia: "fuchsia", Gainsboro: "gainsboro", GhostWhite: "ghostWhite", Gold: "gold", Goldenrod: "goldenrod", Gray: "gray", Green: "green", GreenYellow: "greenYellow", Honeydew: "honeydew", HotPink: "hotPink", IndianRed: "indianRed", Indigo: "indigo", Ivory: "ivory", Khaki: "khaki", Lavender: "lavender", LavenderBlush: "lavenderBlush", LawnGreen: "lawnGreen", LemonChiffon: "lemonChiffon", LtBlue: "ltBlue", LtCoral: "ltCoral", LtCyan: "ltCyan", LtGoldenrodYellow: "ltGoldenrodYellow", LtGray: "ltGray", LtGreen: "ltGreen", LtPink: "ltPink", LtSalmon: "ltSalmon", LtSeaGreen: "ltSeaGreen", LtSkyBlue: "ltSkyBlue", LtSlateGray: "ltSlateGray", LtSteelBlue: "ltSteelBlue", LtYellow: "ltYellow", Lime: "lime", LimeGreen: "limeGreen", Linen: "linen", Magenta: "magenta", Maroon: "maroon", MedAquamarine: "medAquamarine", MedBlue: "medBlue", MedOrchid: "medOrchid", MedPurple: "medPurple", MedSeaGreen: "medSeaGreen", MedSlateBlue: "medSlateBlue", MedSpringGreen: "medSpringGreen", MedTurquoise: "medTurquoise", MedVioletRed: "medVioletRed", MidnightBlue: "midnightBlue", MintCream: "mintCream", MistyRose: "mistyRose", Moccasin: "moccasin", NavajoWhite: "navajoWhite", Navy: "navy", OldLace: "oldLace", Olive: "olive", OliveDrab: "oliveDrab", Orange: "orange", OrangeRed: "orangeRed", Orchid: "orchid", PaleGoldenrod: "paleGoldenrod", PaleGreen: "paleGreen", PaleTurquoise: "paleTurquoise", PaleVioletRed: "paleVioletRed", PapayaWhip: "papayaWhip", PeachPuff: "peachPuff", Peru: "peru", Pink: "pink", Plum: "plum", PowderBlue: "powderBlue", Purple: "purple", Red: "red", RosyBrown: "rosyBrown", RoyalBlue: "royalBlue", SaddleBrown: "saddleBrown", Salmon: "salmon", SandyBrown: "sandyBrown", SeaGreen: "seaGreen", SeaShell: "seaShell", Sienna: "sienna", Silver: "silver", SkyBlue: "skyBlue", SlateBlue: "slateBlue", SlateGray: "slateGray", Snow: "snow", SpringGreen: "springGreen", SteelBlue: "steelBlue", Tan: "tan", Teal: "teal", Thistle: "thistle", Tomato: "tomato", Turquoise: "turquoise", Violet: "violet", Wheat: "wheat", White: "white", WhiteSmoke: "whiteSmoke", Yellow: "yellow", YellowGreen: "yellowGreen", ButtonFace: "buttonFace", ButtonHighlight: "buttonHighlight", ButtonShadow: "buttonShadow", GradientActiveCaption: "gradientActiveCaption", GradientInactiveCaption: "gradientInactiveCaption", MenuBar: "menuBar", MenuHighlight: "menuHighlight" }, ws.Scheme = { Bg1: "bg1", Bg2: "bg2", Tx1: "tx1", Tx2: "tx2", Accent1: "accent1", Accent2: "accent2", Accent3: "accent3", Accent4: "accent4", Accent5: "accent5", Accent6: "accent6", Hlink: "hlink", FolHlink: "folHlink" }, ws.Type = { Scheme: "scheme", Named: "named", Index: "index", HSL: "hsl", RGB: "rgb", LRGB: "lrgb", Hex: "hex" };
const wh = [[4290032820, 1, N.Named.ActiveBorder, !0], [4288263377, 2, N.Named.ActiveCaption, !0], [4278190080, 3, N.Named.CaptionText, !0], [4289440683, 4, N.Named.AppWorkspace, !0], [4293980400, 5, N.Named.BtnFace, !0], [4285098345, 6, N.Named.BtnShadow, !0], [4278190080, 7, N.Named.DkShadow3d, !0], [4293125091, 8, N.Named.BtnHighlight, !0], [4293125091, 9, N.Named.Light3d, !0], [4278190080, 10, N.Named.BtnText, !0], [4278190080, 11, N.Named.Background, !0], [4285361517, 12, N.Named.GrayText, !0], [4281571839, 13, N.Named.Highlight, !0], [4294967295, 14, N.Named.HighlightText, !0], [4278216396, 15, N.Named.HotLight, !0], [4294244348, 16, N.Named.InactiveBorder, !0], [4290760155, 17, N.Named.InactiveCaption, !0], [4278190080, 18, N.Named.InactiveCaptionText, !0], [4294967265, 19, N.Named.InfoBk, !0], [4278190080, 20, N.Named.InfoText, !0], [4293980400, 21, N.Named.Menu, !0], [4278190080, 22, N.Named.MenuText, !0], [4291348680, 23, N.Named.ScrollBar, !0], [4294967295, 24, N.Named.Window, !0], [4284769380, 25, N.Named.WindowFrame, !0], [4278190080, 26, N.Named.WindowText, !0], [16777215, 27, N.Named.Transparent], [4293982463, 28, N.Named.AliceBlue], [4294634455, 29, N.Named.AntiqueWhite], [4278255615, 30, N.Named.Aqua], [4286578644, 31, N.Named.Aquamarine], [4293984255, 32, N.Named.Azure], [4294309340, 33, N.Named.Beige], [4294960324, 34, N.Named.Bisque], [4278190080, 35, N.Named.Black], [4294962125, 36, N.Named.BlanchedAlmond], [4278190335, 37, N.Named.Blue], [4287245282, 38, N.Named.BlueViolet], [4289014314, 39, N.Named.Brown], [4292786311, 40, N.Named.BurlyWood], [4284456608, 41, N.Named.CadetBlue], [4286578432, 42, N.Named.Chartreuse], [4291979550, 43, N.Named.Chocolate], [4294934352, 44, N.Named.Coral], [4284782061, 45, N.Named.CornflowerBlue], [4294965468, 46, N.Named.Cornsilk], [4292613180, 47, N.Named.Crimson], [4278255615, 48, N.Named.Cyan], [4278190219, 49, N.Named.DkBlue], [4278225803, 50, N.Named.DkCyan], [4290283019, 51, N.Named.DkGoldenrod], [4289309097, 52, N.Named.DkGray], [4278215680, 53, N.Named.DkGreen], [4290623339, 54, N.Named.DkKhaki], [4287299723, 55, N.Named.DkMagenta], [4283788079, 56, N.Named.DkOliveGreen], [4294937600, 57, N.Named.DkOrange], [4288230092, 58, N.Named.DkOrchid], [4287299584, 59, N.Named.DkRed], [4293498490, 60, N.Named.DkSalmon], [4287609995, 61, N.Named.DkSeaGreen], [4282924427, 62, N.Named.DkSlateBlue], [4281290575, 63, N.Named.DkSlateGray], [4278243025, 64, N.Named.DkTurquoise], [4287889619, 65, N.Named.DkViolet], [4294907027, 66, N.Named.DeepPink], [4278239231, 67, N.Named.DeepSkyBlue], [4285098345, 68, N.Named.DimGray], [4280193279, 69, N.Named.DodgerBlue], [4289864226, 70, N.Named.Firebrick], [4294966e3, 71, N.Named.FloralWhite], [4280453922, 72, N.Named.ForestGreen], [4294902015, 73, N.Named.Fuchsia], [4292664540, 74, N.Named.Gainsboro], [4294506751, 75, N.Named.GhostWhite], [4294956800, 76, N.Named.Gold], [4292519200, 77, N.Named.Goldenrod], [4286611584, 78, N.Named.Gray], [4278222848, 79, N.Named.Green], [4289593135, 80, N.Named.GreenYellow], [4293984240, 81, N.Named.Honeydew], [4294928820, 82, N.Named.HotPink], [4291648604, 83, N.Named.IndianRed], [4283105410, 84, N.Named.Indigo], [4294967280, 85, N.Named.Ivory], [4293977740, 86, N.Named.Khaki], [4293322490, 87, N.Named.Lavender], [4294963445, 88, N.Named.LavenderBlush], [4286381056, 89, N.Named.LawnGreen], [4294965965, 90, N.Named.LemonChiffon], [4289583334, 91, N.Named.LtBlue], [4293951616, 92, N.Named.LtCoral], [4292935679, 93, N.Named.LtCyan], [4294638200, 94, N.Named.LtGoldenrodYellow], [4292072403, 95, N.Named.LtGray], [4287688336, 96, N.Named.LtGreen], [4294948545, 97, N.Named.LtPink], [4294942842, 98, N.Named.LtSalmon], [4280332970, 99, N.Named.LtSeaGreen], [4287090426, 100, N.Named.LtSkyBlue], [4286023833, 101, N.Named.LtSlateGray], [4289774814, 102, N.Named.LtSteelBlue], [4294967264, 103, N.Named.LtYellow], [4278255360, 104, N.Named.Lime], [4281519410, 105, N.Named.LimeGreen], [4294635750, 106, N.Named.Linen], [4294902015, 107, N.Named.Magenta], [4286578688, 108, N.Named.Maroon], [4284927402, 109, N.Named.MedAquamarine], [4278190285, 110, N.Named.MedBlue], [4290401747, 111, N.Named.MedOrchid], [4287852763, 112, N.Named.MedPurple], [4282168177, 113, N.Named.MedSeaGreen], [4286277870, 114, N.Named.MedSlateBlue], [4278254234, 115, N.Named.MedSpringGreen], [4282962380, 116, N.Named.MedTurquoise], [4291237253, 117, N.Named.MedVioletRed], [4279834992, 118, N.Named.MidnightBlue], [4294311930, 119, N.Named.MintCream], [4294960353, 120, N.Named.MistyRose], [4294960309, 121, N.Named.Moccasin], [4294958765, 122, N.Named.NavajoWhite], [4278190208, 123, N.Named.Navy], [4294833638, 124, N.Named.OldLace], [4286611456, 125, N.Named.Olive], [4285238819, 126, N.Named.OliveDrab], [4294944e3, 127, N.Named.Orange], [4294919424, 128, N.Named.OrangeRed], [4292505814, 129, N.Named.Orchid], [4293847210, 130, N.Named.PaleGoldenrod], [4288215960, 131, N.Named.PaleGreen], [4289720046, 132, N.Named.PaleTurquoise], [4292571283, 133, N.Named.PaleVioletRed], [4294963157, 134, N.Named.PapayaWhip], [4294957753, 135, N.Named.PeachPuff], [4291659071, 136, N.Named.Peru], [4294951115, 137, N.Named.Pink], [4292714717, 138, N.Named.Plum], [4289781990, 139, N.Named.PowderBlue], [4286578816, 140, N.Named.Purple], [4294901760, 141, N.Named.Red], [4290547599, 142, N.Named.RosyBrown], [4282477025, 143, N.Named.RoyalBlue], [4287317267, 144, N.Named.SaddleBrown], [4294606962, 145, N.Named.Salmon], [4294222944, 146, N.Named.SandyBrown], [4281240407, 147, N.Named.SeaGreen], [4294964718, 148, N.Named.SeaShell], [4288696877, 149, N.Named.Sienna], [4290822336, 150, N.Named.Silver], [4287090411, 151, N.Named.SkyBlue], [4285160141, 152, N.Named.SlateBlue], [4285563024, 153, N.Named.SlateGray], [4294966010, 154, N.Named.Snow], [4278255487, 155, N.Named.SpringGreen], [4282811060, 156, N.Named.SteelBlue], [4291998860, 157, N.Named.Tan], [4278222976, 158, N.Named.Teal], [4292394968, 159, N.Named.Thistle], [4294927175, 160, N.Named.Tomato], [4282441936, 161, N.Named.Turquoise], [4293821166, 162, N.Named.Violet], [4294303411, 163, N.Named.Wheat], [4294967295, 164, N.Named.White], [4294309365, 165, N.Named.WhiteSmoke], [4294967040, 166, N.Named.Yellow], [4288335154, 167, N.Named.YellowGreen], [4293980400, 168, N.Named.ButtonFace], [4294967295, 169, N.Named.ButtonHighlight], [4288716960, 170, N.Named.ButtonShadow], [4290367978, 171, N.Named.GradientActiveCaption], [4292338930, 172, N.Named.GradientInactiveCaption], [4293980400, 173, N.Named.MenuBar], [4281571839, 174, N.Named.MenuHighlight]], Ap = new class {
constructor() {
this._lookupByName = /* @__PURE__ */ new Map();
for (let a = 0; a < wh.length; a++) {
const e = wh[a], t = e[0], n = (t >> 24 & 255) / 255, r = t >> 16 & 255, o = t >> 8 & 255, s = 255 & t, i = { id: e[1], name: e[2], rgbaColor: { r, g: o, b: s, a: n }, system: e.length > 3 };
this._lookupByName.set(i.name.toLowerCase(), i);
}
}
valueOfName(a) {
return this._lookupByName.get(a ? a.toLowerCase() : "transparent");
}
}(), ba = [{ scheme: N.Scheme.Tx1, description: "First Text Color" }, { scheme: N.Scheme.Tx2, description: "Second Text Color" }, { scheme: N.Scheme.Bg1, description: "First Background Color" }, { scheme: N.Scheme.Bg2, description: "Second Background Color" }, { scheme: N.Scheme.Accent1, description: "Accent 1" }, { scheme: N.Scheme.Accent2, description: "Accent 2" }, { scheme: N.Scheme.Accent3, description: "Accent 3" }, { scheme: N.Scheme.Accent4, description: "Accent 4" }, { scheme: N.Scheme.Accent5, description: "Accent 5" }, { scheme: N.Scheme.Accent6, description: "Accent 6" }, { scheme: N.Scheme.Hlink, description: "Hyperlink" }, { scheme: N.Scheme.FolHlink, description: "Followed Hyperlink" }, { scheme: "dk1", description: "Text/Background - Dark 1" }, { scheme: "lt1", description: "Text/Background - Light 1" }, { scheme: "dk2", description: "Text/Background - Dark 2" }, { scheme: "lt2", description: "Text/Background - Light 2" }], xg = /* @__PURE__ */ new Map();
for (let a = 0; a < ba.length; a++) xg.set(ba[a].scheme.toLowerCase(), ba[a]);
const yh = (a) => a ? { srgb: [a.red / 255, a.green / 255, a.blue / 255], alpha: a.alpha !== void 0 ? a.alpha : 1 } : null, Eh = function(a, e, t, n) {
let r = yh(((c) => {
let h = Ap.valueOfName(c);
return h ? new wn.RGBA(h.rgbaColor.r, h.rgbaColor.g, h.rgbaColor.b, h.rgbaColor.a) : null;
})(a)), o = null, s = null, i = null;
if (r === null && (l = a, xg.get(l.toLowerCase()))) {
if (!e) throw new Error("a scheme val was used but a schemeLookup was not provided");
o = a, s = e(o), r = yh(s), i = N.Type.Scheme;
}
var l;
if (r === null) {
let c = a.match(Nf) || a.match(Ff);
if (c) {
let h, u = 1;
c.length === 4 ? h = [parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16)] : (h = [parseInt(c[2], 16), parseInt(c[3], 16), parseInt(c[4], 16)], u = zr(parseInt(c[1], 16) / 255)), h = da(h), h = dt(h), r = { srgb: h, alpha: u }, i = N.Type.Hex;
}
}
if (r === null) {
let c = a.match(xf) || a.match(If);
if (c) {
let h = ua(c[1], c[2], c[3]);
h = da(h), h = dt(h), r = { srgb: h, alpha: c[4] ? zr(parseFloat(c[4])) : 1 }, i = N.Type.RGB;
}
}
if (r === null) {
let c = a.match(Rf) || a.match(Af);
if (c) {
let h = ua(c[1], c[2], c[3]);
h = da(h, 100), h = dr(h), h = dt(h), r = { srgb: h, alpha: c[4] ? zr(parseFloat(c[4])) : 1 }, i = N.Type.LRGB;
}
}
if (r === null) {
let c = a.match(Mf) || a.match(Tf);
if (c) {
let h = ua(c[1], c[2], c[3]);
h = gr(h), h = dt(h), r = { srgb: h, alpha: c[4] ? zr(parseFloat(c[4])) : 1 }, i = N.Type.HSL;
}
}
if (r === null) {
let c = a.match(kf);
if (c) {
const h = parseInt(c[1]);
let u = t?.(h) ?? Ci(h);
u && (r = { srgb: [u.red / 255, u.green / 255, u.blue / 255], alpha: u.alpha }, i = N.Type.Index);
}
}
if (r === null) throw new Error("Not a valid color format: " + a);
return { srgbAlpha: r, key: o, color: s, type: i };
}, xl = /* @__PURE__ */ new Map(), va = Object.keys(N.AdjustmentType);
for (let a = 0; a < va.length; a++) xl.set(N.AdjustmentType[va[a]].toLowerCase(), N.AdjustmentType[va[a]]);
const Ch = new RegExp("\\s+\\s*(?![^()]*\\))|,\\s*(?![^()]*\\))"), bh = new RegExp("\\s*[,]\\s*|\\s+");
let xa = null;
const vh = { [N.Scheme.Bg1]: "window", [N.Scheme.Bg2]: "E7E6E6", [N.Scheme.Tx1]: "windowText", [N.Scheme.Tx2]: "44546A", [N.Scheme.Accent1]: "4472C4", [N.Scheme.Accent2]: "ED7D31", [N.Scheme.Accent3]: "A5A5A5", [N.Scheme.Accent4]: "FFC000", [N.Scheme.Accent5]: "5B9BD5", [N.Scheme.Accent6]: "70AD47", [N.Scheme.Hlink]: "0563C1", [N.Scheme.FolHlink]: "954F72" };
class Qe {
constructor(e, t, n, r = null) {
let o = null, s = null;
if (e instanceof Qe) o = e.getVal(), e.getAdjustments() && (s = [...e.getAdjustments()]);
else if (typeof e == "string") {
const i = this._parse(e);
o = i.val, s = i.adjs;
} else e?.val && (o = e.val, s = e.adjs);
if (!o) throw new Error("Unable to determine color value");
this._private = { val: o, adjs: s, schemeLookup: t, indexedLookup: n, parsedVal: Eh(o, t, n), adjusted: null, resolved: null };
}
_parse(e) {
let t = null, n = e.toLowerCase().trim();
const r = n.split(Ch);
if (r && (t = r[0], n = n.substring(t.length, n.length).trim()), !t) throw new Error("no color key found");
const o = [], s = n.split(bh);
for (let i = 0; i < s.length; i++) {
const l = s[i];
if (!l) continue;
const c = xl.get(l.toLowerCase());
if (!c) throw new Error("Invalid adjustment type:" + l);
let h = null;
if (!(c === N.AdjustmentType.Gray || c === N.AdjustmentType.Comp || c === N.AdjustmentType.Inv || c === N.AdjustmentType.Gamma || c === N.AdjustmentType.InvGamma)) {
i++;
const u = s[i];
if (h = parseFloat(u), h == null) throw new Error(`Invalid adjustment value: missing value for'${l}'`);
if (isNaN(h)) throw new Error("Invalid adjustment value:" + u);
}
o.push({ [c]: h });
}
return { val: t, adjs: o };
}
_forceDark(e = !0) {
this._resolve();
const t = this._private.resolved;
let n = [t.red, t.green, t.blue];
n = ((i, l) => {
l = (l % 360 + 360) % 360;
const c = [1, 0, 0, 0, 1, 0, 0, 0, 1], h = Math.cos(l * Math.PI / 180), u = Math.sin(l * Math.PI / 180);
c[0] = vr + 0.7874 * h - vr * u, c[1] = On - On * h - On * u, c[2] = xr - xr * h + 0.9278 * u, c[3] = vr - vr * h + 0.143 * u, c[4] = On + (1 - On) * h + 0.14 * u, c[5] = xr - xr * h - 0.283 * u, c[6] = vr - vr * h - 0.7874 * u, c[7] = On - On * h + On * u, c[8] = xr + 0.9278 * h + xr * u;
const d = (_) => Math.round(Math.max(0, Math.min(255, _))), g = i[0], m = i[1], f = i[2];
return [d(c[0] * g + c[1] * m + c[2] * f), d(c[3] * g + c[4] * m + c[5] * f), d(c[6] * g + c[7] * m + c[8] * f)];
})(n, 180), n = Hc(n, !1);
let r = ur(n);
const o = Jn(r);
if (o[co] = 0.95 * o[co], r = gr(o), n = dr(r), n = Pc(n), n = dt(n, !1), e) return new wn.RGBA(n[0], n[1], n[2], t.alpha);
const s = Jn(ur(n));
return new wn.HSLA(s[0], s[1], s[2], t.alpha);
}
_resolve() {
if (this._private.resolved) {
if (!this._private.parsedVal.key) return;
let o = this._private.schemeLookup(this._private.parsedVal.key);
if (o === this._private.parsedVal.color || o?.isEqual(this._private.parsedVal.color)) return;
}
const e = Eh(this._private.val, this._private.schemeLookup, this._private.indexedLookup, this._private.last);
let t = ((o, s) => {
let i = [...o.srgb], l = o.alpha !== void 0 ? o.alpha : 1;
for (var c = 0; s && c < s.length; c++) {
const h = s[c], u = Object.keys(h)[0], d = h[u];
u === N.AdjustmentType.Alpha ? (l = d / 100, l = Math.max(0, Math.min(1, l))) : u === N.AdjustmentType.AlphaOff ? (l += d / 100, l = Math.max(0, Math.min(1, l))) : u === N.AdjustmentType.AlphaMod ? (l *= d / 100, l = Math.max(0, Math.min(1, l))) : u === N.AdjustmentType.Hue ? i = fa(ut, i, d) : u === N.AdjustmentType.Sat ? i = fa(ma, i, d) : u === N.AdjustmentType.Lum ? i = fa(co, i, d) : u === N.AdjustmentType.HueOff ? i = pa(ut, i, d) : u === N.AdjustmentType.SatOff ? i = pa(ma, i, d) : u === N.AdjustmentType.LumOff ? i = pa(co, i, d) : u === N.AdjustmentType.HueMod ? i = _a(ut, i, d) : u === N.AdjustmentType.SatMod ? i = _a(ma, i, d) : u === N.AdjustmentType.LumMod ? i = _a(co, i, d) : u === N.AdjustmentType.Red ? i = cn(Js, i, d, Xs) : u === N.AdjustmentType.Green ? i = cn(qs, i, d, Xs) : u === N.AdjustmentType.Blue ? i = cn(Ks, i, d, Xs) : u === N.AdjustmentType.RedOff ? i = cn(Js, i, d, Ys) : u === N.AdjustmentType.GreenOff ? i = cn(qs, i, d, Ys) : u === N.AdjustmentType.BlueOff ? i = cn(Ks, i, d, Ys) : u === N.AdjustmentType.RedMod ? i = cn(Js, i, d, Qs) : u === N.AdjustmentType.GreenMod ? i = cn(qs, i, d, Qs) : u === N.AdjustmentType.BlueMod ? i = cn(Ks, i, d, Qs) : u === N.AdjustmentType.Shade ? i = Of(i, d) : u === N.AdjustmentType.Tint ? i = Lf(i, d) : u === N.AdjustmentType.ETint ? i = Df(i, d) : u === N.AdjustmentType.Gray ? i = Bf(i) : u === N.AdjustmentType.Comp ? i = zf(i) : u === N.AdjustmentType.Inv ? i = Hc(i, d) : u === N.AdjustmentType.Gamma ? i = Pf(i) : u === N.AdjustmentType.InvGamma ? i = Hf(i) : console.warn("unknown adjustmentType: " + u);
}
return { srgb: i, alpha: l };
})(e.srgbAlpha, this._private.adjs), n = ((o, s = 255) => {
const i = [...o];
for (var l = 0; l < o.length; l++) i[l] = o[l] * s;
return i;
})(t.srgb);
n = Pc(n);
let r = zr(t.alpha);
this._private.adjusted = t, this._private.parsedVal = e, this._private.resolved = new wn.RGBA(n[0], n[1], n[2], r);
}
static parse(e, t, n, r = null) {
if (e instanceof Qe) return e;
const o = e;
let s = null, i = o?.trim(), l = null;
try {
if (!s) {
const u = i?.split(Ch);
u && (s = u[0], i = i.substring(s.length, i.length).trim());
}
if (!s) throw new Error("no color found");
const c = [], h = i.split(bh);
for (let u = 0; u < h.length; u++) {
const d = h[u];
if (!d) continue;
const g = xl.get(d.toLowerCase());
if (!g) throw new Error("Invalid adjustment type:" + d);
let m = null;
if (!(g === N.AdjustmentType.Gray || g === N.AdjustmentType.Comp || g === N.AdjustmentType.Inv || g === N.AdjustmentType.Gamma || g === N.AdjustmentType.InvGamma)) {
u++;
const f = h[u];
if (m = parseFloat(f), m == null) throw new Error(`Invalid adjustment value: missing value for'${d}'`);
if (isNaN(m)) throw new Error("Invalid adjustment value:" + f);
}
c.push({ [g]: m });
}
l = new Qe({ val: s, adjs: c }, t, n, r);
} catch (c) {
throw c;
}
return l;
}
static getDefaultSchemeLookup() {
if (!xa) {
const e = /* @__PURE__ */ new Map(), t = Object.keys(vh);
for (let n = 0; n < t.length; n++) {
const r = t[n];
e.set(r.toLowerCase(), Qe.parse(vh[r], null));
}
xa = (n) => e.get(n.toLowerCase())?.toRGBA();
}
return xa;
}
isEqual(e) {
return e instanceof Qe && this.toString().toLowerCase() === e.toString().toLowerCase();
}
getVal() {
return this._private.val;
}
getAdjustments() {
return this._private.adjs;
}
adjust(e) {
return new Qe({ val: this._private.val, adjs: this._private.adjs ? this._private.adjs.concat(e) : e }, this._private.schemeLookup, this._private.indexedLookup, this._private.last);
}
getType() {
return this._resolve(), this._private.parsedVal.type ?? null;
}
toCSS(e = !1, t = !0) {
const n = e ? this._forceDark() : this.toRGBA();
return n.alpha === 0 ? "none" : n.toString(t);
}
toRGBA(e = !1) {
return this._resolve(), e ? this._forceDark() : this._private.resolved;
}
toHSLA(e = !1) {
if (this._resolve(), e) return this._forceDark(!1);
let t = Jn(this._private.adjusted.srgb);
return new wn.HSLA(t[0], t[1], t[2], zr(this._private.adjusted.alpha ?? 1));
}
toHex(e = !1) {
this._resolve();
const t = e ? this._forceDark() : this._private.resolved;
return new wn.HEX(t.red, t.green, t.blue, t.alpha ?? 1);
}
toBlackOrWhite(e = !1, t = 157) {
const n = this.toRGBA(e), r = 0.299 * n.red + 0.587 * n.green + 0.114 * n.blue > t;
return new Qe(r ? "#000000" : "#FFFFFF", this._private.schemeLookup, this._private.indexedLookup, this._private.last);
}
get [Symbol.toStringTag]() {
return this.toString();
}
toString() {
let e = this._private.val;
const t = this._private.adjs;
for (let n = 0; t && n < t.length; n++) {
const r = t[n];
if (!r) continue;
const o = Object.keys(r)[0];
e += " " + o;
const s = r[o];
typeof s == "number" && (e += " " + s), n < t.length - 1 && (e += ",");
}
return e;
}
get isIColor() {
return !0;
}
}
var U, xh;
(xh = U || (U = {})).StrokeStyle = { None: "none", DashDot: "dashDot", MediumDashDot: "mediumDashDot", Dotted: "dotted", Hair: "hair", Thin: "thin", Medium: "medium", Thick: "thick", MediumDashDotDot: "mediumDashDotDot", DashDotDot: "dashDotDot", Dashed: "dashed", MediumDashed: "mediumDashed", SlantDashDot: "slantDashDot", Double: "double" }, xh.Edge = { Left: "left", Top: "top", Right: "right", Bottom: "bottom", Horizontal: "horizontal", Vertical: "vertical", DiagonalUp: "diagonalUp", DiagonalDown: "diagonalDown" };
const Ig = [], Rg = /* @__PURE__ */ new Map(), Ih = Object.freeze([[U.StrokeStyle.Thin, "Thin", 1, null], [U.StrokeStyle.Hair, "Hair", 1, [1, 1]], [U.StrokeStyle.Dotted, "Dotted", 1, [2, 2]], [U.StrokeStyle.Dashed, "Dashed", 1, [3, 1]], [U.StrokeStyle.DashDot, "Dash Dot", 1, [3, 3, 9, 3]], [U.StrokeStyle.DashDotDot, "Dash Dot Dot", 1, [3, 3, 3, 3, 9, 3]], [U.StrokeStyle.Double, "Double", 3, null], [U.StrokeStyle.Medium, "Medium", 2, null], [U.StrokeStyle.MediumDashed, "Medium Dashed", 2, [9, 3]], [U.StrokeStyle.MediumDashDot, "Medium Dash Dot", 2, [3, 3, 9, 3]], [U.StrokeStyle.MediumDashDotDot, "Medium Dash Dot Dot", 2, [3, 3, 3, 3, 9, 3]], [U.StrokeStyle.SlantDashDot, "Slant Dash Dot", 2, [5, 1, 11, 1]], [U.StrokeStyle.Thick, "Thick", 3, null], [U.StrokeStyle.None, "None", 0, null]]);
for (let a = 0; a < Ih.length; a++) {
const e = Ih[a], t = e[0], n = Object.freeze({ style: t, description: e[1], width: e[2], pattern: e[3] });
Ig.push(n), Rg.set(t, n);
}
((a) => {
a.isEqualStrokes = (e, t) => !(e && !t || t && !e) && (e === t || e.getStyle() === t.getStyle() && e.getColor().isEqual(t.getColor())), a.oppositeEdge = (e) => e === a.Edge.Left ? a.Edge.Right : e === a.Edge.Right ? a.Edge.Left : e === a.Edge.Top ? a.Edge.Bottom : e === a.Edge.Bottom ? a.Edge.Top : e, a.BuiltInDefinitionsArray = Ig, a.BuiltInDefinitions = Rg;
})(U || (U = {}));
const Mp = { Text: "text", Repeat: "repeat", Spacing: "spacing" }, Rh = (a) => !(!a.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/) && !a.match(/^# ([#0?]+)( ?)\/( ?)([#0?]+)/)), Tp = Object.freeze({ formatValue: Kl, isFractionFormat: Rh, adjustDecimalPlaces: (a, e) => {
if (!a) return "";
const t = (s, i) => {
let l = s || "";
const c = l.length === 0 || l.endsWith(".") ? "0" : l.charAt(l.length - 1);
return i < 0 ? (l = l.substring(0, Math.max(0, l.length + i)), l === "." && (l = "")) : (l.startsWith(".") || (l += "."), l += c.repeat(i)), l;
}, n = (s, i) => {
if (s === "General") return i > 0 ? "0" + t("", i) : s;
if (Rh(s)) return s;
let l = s, c = -1, h = -1, u = l.indexOf("E");
if (u >= 0 && (l = l.substring(0, u)), c = l.indexOf("."), c >= 0) {
l = l.substring(c, l.length);
let d = l && l.match(/([.]{1}[0,#]+)/);
if (!d) return s;
l = d[1], h = c + l.length;
} else {
if (i <= 0) return s;
c = l.lastIndexOf("0"), c < 0 && (c = l.lastIndexOf("#")), c >= 0 && (c += 1), h = c, l = "";
}
return c === -1 ? s : (l = t(l, i), s.substring(0, c) + l + s.substring(h, s.length));
}, r = [];
let o = Gf(a);
for (let s = 0; s < o.length; s++) r.push(n(o[s].trim(), e));
return r.join(";");
} }), Np = Ke._table, ec = (a) => a === 14 ? "Short Date" : Np[a] ?? null, ho = [{ numberFormat: "General", formatType: Se.General, primary: 1 }, { numberFormat: "0", formatType: Se.Number, regMatch: /^0[.]{0,1}[0]*$/, args: { decimalPlaces: 0, separator: !1 } }, { numberFormat: "#,##0.00", formatType: Se.Number, regMatch: /^#,##0[.]{0,1}[0]*$/, primary: 2, args: { decimalPlaces: 2, separator: !0 } }, { numberFormat: "#,##0_);(#,##0)", formatType: Se.Number, args: { decimalPlaces: 0, separator: !0 } }, { numberFormat: "#,##0_);[Red](#,##0)", formatType: Se.Number, args: { decimalPlaces: 0, separator: !0 } }, { numberFormat: "#,##0.00_);(#,##0.00)", formatType: Se.Number, args: { decimalPlaces: 2, separator: !0 } }, { numberFormat: "#,##0.00_);[Red](#,##0.00)", formatType: Se.Number, args: { decimalPlaces: 2, separator: !0 } }, { numberFormat: "$#,##0.00", formatType: Se.Currency, primary: 3, args: { decimalPlaces: 2, currencySymbol: "$" } }, { numberFormat: "$#,##0_);($#,##0)", formatType: Se.Currency, args: { decimalPlaces: 0, currencySymbol: "$" } }, { numberFormat: "$#,##0_);[Red]($#,##0)", formatType: Se.Currency, args: { decimalPlaces: 0, currencySymbol: "$" } }, { numberFormat: "$#,##0.00_);($#,##0.00)", formatType: Se.Currency, args: { decimalPlaces: 2, currencySymbol: "$" } }, { numberFormat: "$#,##0.00_);[Red]($#,##0.00)", formatType: Se.Currency, args: { decimalPlaces: 2, currencySymbol: "$" } }, { numberFormat: '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)', primary: 4, formatType: Se.Accounting }, { numberFormat: '_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)', formatType: Se.Accounting }, { numberFormat: '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)', formatType: Se.Accounting }, { numberFormat: '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)', formatType: Se.Accounting }, { numberFormat: "Short Date", formatType: Se.ShortDate, primary: 5 }, { numberFormat: "d-mmm-yy", formatType: Se.MediumDate, primary: 5.5 }, { numberFormat: "Long Date", formatType: Se.LongDate, primary: 6 }, { numberFormat: "h:mm", formatType: Se.ShortTime, primary: 7 }, { numberFormat: "h:mm AM/PM", formatType: Se.MediumTime, primary: 7.5 }, { numberFormat: "Long Time", formatType: Se.LongTime, primary: 8 }, { numberFormat: '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)', formatType: Se.Comma, primary: 9 }, { numberFormat: "0.00%", formatType: Se.Percentage, primary: 10, args: { decimalPlaces: 2 }, regMatch: /^^[0#?]*[.]{0,1}[0#?]*%*$/ }, { numberFormat: "0%", formatType: Se.Percentage, args: { decimalPlaces: 0 } }, { numberFormat: "# ?/?", formatType: Se.Fraction, primary: 11 }, { numberFormat: "# ??/??", formatType: Se.Fraction }, { numberFormat: "0.00E+00", formatType: Se.Scientific, primary: 12, args: { decimalPlaces: 2 }, regMatch: /^[0#?]*[.]{0,1}[0#?]*E\+[0#?]*$/ }, { numberFormat: "##0.0E+0", formatType: Se.Custom, args: { decimalPlaces: 0 } }, { numberFormat: "@", formatType: Se.Text, primary: 13 }, { numberFormat: "d-mmm", formatType: Se.Custom }, { numberFormat: "mmm-yy", formatType: Se.Custom }, { numberFormat: "h:mm:ss", formatType: Se.Custom }, { numberFormat: "m/d/yyyy h:mm", formatType: Se.Custom }, { numberFormat: "mm:ss", formatType: Se.Custom }, { numberFormat: "mm:ss.0", formatType: Se.Custom }, { numberFormat: "[h]:mm:ss", formatType: Se.Custom }], Ia = [{ numberFormat: "00000", formatType: Se.Special, primary: 11 }, { numberFormat: "00000-0000", formatType: Se.Special }, { numberFormat: "[<=9999999]###-####;(###) ###-####", formatType: Se.Special }, { numberFormat: "000-00-0000", formatType: Se.Special }], ns = /* @__PURE__ */ new Map(), No = [];
for (let a = 0; a < ho.length; a++) {
let e = ho[a].numberFormat.toLowerCase();
ns.set(e, ho[a]), ho[a].regMatch && No.unshift(ho[a]);
}
for (let a = 0; a < Ia.length; a++) {
let e = Ia[a].numberFormat.toLowerCase();
ns.set(e, Ia[a]);
}
const Il = [], Ag = /* @__PURE__ */ new Map();
ns.forEach(function(a, e, t) {
a.primary && (Il.push(a), Ag.set(F.textToKey(a.formatType), a.numberFormat));
}), Il.sort(function(a, e) {
return a.primary - e.primary;
});
const Ah = ns.get(Se.General.toLowerCase());
class Fp {
lookupStyle(e) {
if (!e) return Ah;
if (typeof e == "number" && (e = ec(e)), !e.toLowerCase) return console.warn("Invalid numberFormat", e), Ah;
e = e.toLowerCase();
let t = ns.get(e);
if (t) return t;
for (let n = 0; !t && n < No.length; n++) No[n].regMatch && e.match(No[n].regMatch) && (t = No[n]);
return t || { numberFormat: e, formatType: Se.Custom };
}
lookupPrimary() {
return Il;
}
lookupDefault(e) {
return Ag.get(F.textToKey(e));
}
}
var Nt, ys, ce, Mh;
(ys = Nt || (Nt = {})).Type = Se, ys.Parser = Tp, ys.Styles = new Fp(), ys.ParseRunType = Mp, (Mh = ce || (ce = {})).BuiltInName = { Normal: "Normal", RowLevel: "RowLevel_#", ColLevel: "ColLevel_#", Comma: "Comma", Currency: "Currency", Percent: "Percent", Comma0: "Comma [0]", Currency0: "Currency [0]", Hyperlink: "Hyperlink", FollowedHyperlink: "Followed Hyperlink", Note: "Note", WarningText: "Warning Text", Unknown12: "??-12", Unknown13: "??-13", Unknown14: "??-14", Title: "Title", Heading1: "Heading 1", Heading2: "Heading 2", Heading3: "Heading 3", Heading4: "Heading 4", Input: "Input", Output: "Output", Calculation: "Calculation", CheckCell: "Check Cell", LinkedCell: "Linked Cell", Total: "Total", Good: "Good", Bad: "Bad", Neutral: "Neutral", Accent1: "Accent1", Accent1_20: "20% - Accent1", Accent1_40: "40% - Accent1", Accent1_60: "60% - Accent1", Accent2: "Accent2", Accent2_20: "20% - Accent2", Accent2_40: "40% - Accent2", Accent2_60: "60% - Accent2", Accent3: "Accent3", Accent3_20: "20% - Accent3", Accent3_40: "40% - Accent3", Accent3_60: "60% - Accent3", Accent4: "Accent4", Accent4_20: "20% - Accent4", Accent4_40: "40% - Accent4", Accent4_60: "60% - Accent4", Accent5: "Accent5", Accent5_20: "20% - Accent5", Accent5_40: "40% - Accent5", Accent5_60: "60% - Accent5", Accent6: "Accent6", Accent6_20: "20% - Accent6", Accent6_40: "40% - Accent6", Accent6_60: "60% - Accent6", ExplanatoryText: "Explanatory Text" }, Mh.IconSet = { Arrows3: "3Arrows", ArrowsGray3: "3ArrowsGray", Flags3: "3Flags", Signs3: "3Signs", Symbols3: "3Symbols", Symbols3_2: "3Symbols2", TrafficLights3: "3TrafficLights1", TrafficLights3_2: "3TrafficLights2", Arrows4: "4Arrows", ArrowsGray4: "4ArrowsGray", Rating4: "4Rating", RedToBlack4: "4RedToBlack", TrafficLights4: "4TrafficLights", Arrows5: "5Arrows", ArrowsGray5: "5ArrowsGray", Quarters5: "5Quarters", Rating5: "5Rating" };
const kp = (a, e, t, n, r) => {
const o = JSON.parse(JSON.stringify(a.definition));
o.adjs || (o.adjs = []);
let s = "", i = 0, l = 0;
e > 0 ? (l = e, i = 100 - e, s = `Lighter ${e}%`) : e < 0 && (i = 100 + e, s = `Darker ${-e}%`), i && o.adjs.push({ [N.AdjustmentType.LumMod]: i }), l && o.adjs.push({ [N.AdjustmentType.LumOff]: l });
const c = new Qe({ val: o.val, adjs: o.adjs }, t), h = c.toString();
n?.set(h, c);
const u = c.toRGBA().toString();
return r?.set(u, c), { description: a.description + ", " + s, definition: o };
}, Op = (a, e, t, n) => {
let r = [];
for (let o = 0; o < a.length; o++) {
let s = [];
r.push(s);
const i = (c) => {
for (let h = 0; h < c.length; h++) s.push(kp(a[o], c[h], e, t, n));
};
let l = new Qe({ val: a[o].definition.val, adjs: a[o].definition.adjs }, e).toHSLA().lum;
i(l === 0 ? [50, 35, 25, 15, 5] : l === 100 ? [-5, -15, -25, -35, -50] : l <= 20 ? [90, 75, 50, 25, 10] : l >= 80 ? [-10, -25, -50, -75, -90] : [80, 60, 40, -25, -50]);
}
return r;
};
var Th, ir;
(Th || (Th = {})).buildPalette = Op, (ir || (ir = {})).BuiltInFilterType = { BuiltIn: "builtIn", All: "all", Custom: "custom" };
const Dp = [["Office", "windowText", "window", "0E2841", "E8E8E8", "156082", "E97132", "196B24", "0F9ED5", "A02B93", "4EA72E", "467886", "96607D"], ["Office 2013-2022", "windowText", "window", "44546A", "E7E6E6", "4472C4", "ED7D31", "A5A5A5", "FFC000", "5B9BD5", "70AD47", "0563C1", "954F72"], ["Office 2007-2010", "windowText", "window", "1F497D", "EEECE1", "4F81BD", "C0504D", "9BBB59", "8064A2", "4BACC6", "F79646", "0000FF", "800080"], ["Grayscale", "windowText", "window", "000000", "F8F8F8", "DDDDDD", "B2B2B2", "969696", "808080", "5F5F5F", "4D4D4D", "5F5F5F", "919191"], ["Atlas", "windowText", "window", "454545", "E0E0E0", "F81B02", "FC7715", "AFBF41", "50C49F", "3B95C4", "B560D4", "FC5A1A", "B49E74"], ["Banded", "2C2C2C", "FFFFFF", "099BDD", "F2F2F2", "FFC000", "A5D028", "08CC78", "F24099", "828288", "F56617", "005DBA", "6C606A"], ["Basis", "000000", "FFFFFF", "565349", "DDDDDD", "A6B727", "DF5327", "FE9E00", "418AB3", "D7D447", "818183", "F59E00", "B2B2B2"], ["Berlin", "windowText", "window", "9D360E", "E7E6E6", "F09415", "C1B56B", "4BAF73", "5AA6C0", "D17DF9", "FA7E5C", "FFAE3E", "FCC77E"], ["Celestial", "windowText", "window", "18276C", "EBEBEB", "AC3EC1", "477BD1", "46B298", "90BA4C", "DD9D31", "E25247", "C573D2", "CCAEE8"], ["Circuit", "windowText", "window", "134770", "82FFFF", "9ACD4C", "FAA93A", "D35940", "B258D3", "63A0CC", "8AC4A7", "B8FA56", "7AF8CC"], ["Damask", "windowText", "window", "2A5B7F", "ABDAFC", "9EC544", "50BEA3", "4A9CCC", "9A66CA", "C54F71", "DE9C3C", "6BA9DA", "A0BCD3"], ["Depth", "windowText", "window", "455F51", "94D7E4", "41AEBD", "97E9D5", "A2CF49", "608F3D", "F4DE3A", "FCB11C", "FBCA98", "D3B86D"], ["Dividend", "windowText", "window", "3D3D3D", "EBEBEB", "4D1434", "903163", "B2324B", "969FA7", "66B1CE", "40619D", "828282", "A5A5A5"], ["Droplet", "windowText", "window", "355071", "AABED7", "2FA3EE", "4BCAAD", "86C157", "D99C3F", "CE6633", "A35DD1", "56BCFE", "97C5E3"], ["Facet", "windowText", "window", "2C3C43", "EBEBEB", "90C226", "54A021", "E6B91E", "E76618", "C42F1A", "918655", "99CA3C", "B9D181"], ["Frame", "000000", "FFFFFF", "545454", "BFBFBF", "40BAD2", "FAB900", "90BB23", "EE7008", "1AB39F", "D5393D", "90BB23", "EE7008"], ["Gallery", "windowText", "window", "454545", "DFDBD5", "B71E42", "DE478E", "BC72F0", "795FAF", "586EA6", "6892A0", "FA2B5C", "BC658E"], ["Integral", "windowText", "window", "335B74", "DFE3E5", "1CADE4", "2683C6", "27CED7", "42BA97", "3E8853", "62A39F", "6B9F25", "B26B02"], ["Ion Boardroom", "windowText", "window", "3B3059", "EBEBEB", "B31166", "E33D6F", "E45F3C", "E9943A", "9B6BF2", "D53DD0", "8F8F8F", "A5A5A5"], ["Ion", "windowText", "window", "1E5155", "EBEBEB", "B01513", "EA6312", "E6B729", "6AAC90", "54849A", "9E5E9B", "58C1BA", "9DFFCB"], ["Madison", "windowText", "window", "1F2D29", "C5FAEB", "A1D68B", "5EC795", "4DADCF", "CDB756", "E29C36", "8EC0C1", "6D9D9B", "6D8583"], ["Main Event", "windowText", "window", "424242", "C8C8C8", "B80E0F", "A6987D", "7F9A71", "64969F", "9B75B2", "80737A", "F21213", "B6A394"], ["Mesh", "windowText", "window", "363D46", "EBEBEB", "6F6F6F", "BFBFA5", "DCD084", "E7BF5F", "E9A039", "CF7133", "F28943", "F1B76C"], ["Metropolitan", "windowText", "window", "162F33", "EAF0E0", "50B4C8", "A8B97F", "9B9256", "657689", "7A855D", "84AC9D", "2370CD", "877589"], ["Organic", "windowText", "window", "212121", "DADADA", "83992A", "3C9770", "44709D", "A23C33", "D97828", "DEB340", "A8BF4D", "B4CA80"], ["Parallax", "windowText", "window", "212121", "CDD0D1", "30ACEC", "80C34F", "E29D3E", "D64A3B", "D64787", "A666E1", "3085ED", "82B6F4"], ["Parcel", "000000", "FFFFFF", "4A5356", "E8E3CE", "F6A21D", "9BAFB5", "C96731", "9CA383", "87795D", "A0988C", "00B0F0", "738F97"], ["Quotable", "windowText", "window", "212121", "636363", "00C6BB", "6FEBA0", "B6DF5E", "EFB251", "EF755F", "ED515C", "8F8F8F", "A5A5A5"], ["Retrospect", "000000", "window", "637052", "CCDDEA", "E48312", "BD582C", "865640", "9B8357", "C2BC80", "94A088", "2998E3", "8C8C8C"], ["Savon", "windowText", "window", "1485A4", "E3DED1", "1CADE4", "2683C6", "27CED7", "42BA97", "3E8853", "62A39F", "F49100", "739D9B"], ["Slate", "windowText", "window", "212123", "DADADA", "BC451B", "D3BA68", "BB8640", "AD9277", "A55A43", "AD9D7B", "E98052", "F4B69B"], ["Slice", "windowText", "window", "146194", "76DBF4", "052F61", "A50E82", "14967C", "6A9E1F", "E87D37", "C62324", "0D2E46", "356A95"], ["Vapor Trail", "windowText", "window", "454545", "DADADA", "DF2E28", "FE801A", "E9BF35", "81BB42", "32C7A9", "4A9BDC", "F0532B", "F38B53"], ["View", "000000", "FFFFFF", "46464A", "D6D3CC", "6F6F74", "92A9B9", "A7B789", "B9A489", "8D6374", "9B7362", "67AABF", "ABAFA5"], ["Wisp", "windowText", "window", "766F54", "E3EACF", "A53010", "DE7E18", "9F8351", "728653", "92AA4C", "6AAC91", "FB4A18", "FB9318"], ["Wood Type", "windowText", "window", "696464", "E9E5DC", "D34817", "9B2D1F", "A28E6A", "956251", "918485", "855D5D", "CC9900", "96A9A9"]], Lp = [["Office", "Calibri Light", "Calibri"], ["Office 2013-2022", "Calibri Light", "Calibri"], ["Office 2007-2010", "Calibri Light", "Calibri"], ["Grayscale", "Calibri Light", "Calibri"], ["Atlas", "Calibri Light", "Rockwell"], ["Banded", "Corbel", "Corbel"], ["Basis", "Corbel", "Corbel"], ["Berlin", "Trebuchet MS", "Trebuchet MS"], ["Celestial", "Calibri Light", "Calibri"], ["Circuit", "Tw Cen MT", "Tw Cen MT"], ["Damask", "Bookman Old Style", "Rockwell"], ["Depth", "Corbel", "Corbel"], ["Madison", "Arial", "Arial"], ["Main Event", "Impact", "Impact"], ["Mesh", "Century Gothic", "Century Gothic"], ["Metropolitan", "Calibri Light", "Calibri Light"], ["Organic", "Garamond", "Garamond"], ["Parallax", "Corbel", "Corbel"], ["Parcel", "Gill Sans MT", "Gill Sans MT"], ["Quotable", "Century Gothic", "Century Gothic"], ["Retrospect", "Calibri Light", "Calibri"], ["Savon", "Century Gothic", "Century Gothic"], ["Slate", "Calisto MT", "Calisto MT"], ["Slice", "Century Gothic", "Century Gothic"], ["Vapor Trail", "Century Gothic", "Century Gothic"], ["View", "Century Schoolbook", "Century Schoolbook"], ["Wisp", "Century Gothic", "Century Gothic"], ["Wood Type", "Rockwell Condensed", "Rockwell"]], Bp = [["Office", "Office", "Office"], ["2013-2022", "Office 2013-2022", "Office 2013-2022"], ["Atlas", "Atlas", "Atlas"], ["Banded", "Banded", "Banded"], ["Basis", "Basis", "Basis"], ["Berlin", "Berlin", "Berlin"], ["Celestial", "Celestial", "Celestial"], ["Circuit", "Circuit", "Circuit"], ["Damask", "Damask", "Damask"], ["Depth", "Depth", "Depth"], ["Dividend", "Dividend", "Dividend"], ["Droplet", "Droplet", "Droplet"], ["Facet", "Facet", "Facet"], ["Frame", "Frame", "Frame"], ["Gallery", "Gallery", "Gallery"], ["Grayscale", "Grayscale", "Grayscale"], ["Integral", "Integral", "Integral"], ["Ion Boardroom", "Ion Boardroom", "Ion Boardroom"], ["Ion", "Ion", "Ion"], ["Madison", "Madison", "Madison"], ["Main Event", "Main Event", "Main Event"], ["Mesh", "Mesh", "Mesh"], ["Metropolitan", "Metropolitan", "Metropolitan"], ["Organic", "Organic", "Organic"], ["Parallax", "Parallax", "Parallax"], ["Parcel", "Parcel", "Parcel"], ["Quotable", "Quotable", "Quotable"], ["Retrospect", "Retrospect", "Retrospect"], ["Savon", "Savon", "Savon"], ["Slate", "Slate", "Slate"], ["Slice", "Slice", "Slice"], ["Vapor Trail", "Vapor Trail", "Vapor Trail"], ["View", "View", "View"], ["Wisp", "Wisp", "Wisp"], ["Wood Type", "Wood Type", "Wood Type"], ["Office 2007-2010", "Office 2007-2010", "Office 2007-2010"]], Ra = "Themes is readonly. To make modifications create a new DocsThemes instance.", Nh = { [N.Scheme.Bg1]: "lt1", [N.Scheme.Bg2]: "lt2", [N.Scheme.Tx1]: "dk1", [N.Scheme.Tx2]: "dk2", [N.Scheme.Accent1]: "accent1", [N.Scheme.Accent2]: "accent2", [N.Scheme.Accent3]: "accent3", [N.Scheme.Accent4]: "accent4", [N.Scheme.Accent5]: "accent5", [N.Scheme.Accent6]: "accent6", [N.Scheme.Hlink]: "hlink", [N.Scheme.FolHlink]: "folHlink" }, Yr = "Office", Rl = [Yr, "Calibri Light", "Calibri"], Qr = ["dk1", "lt1", "dk2", "lt2", "accent1", "accent2", "accent3", "accent4", "accent5", "accent6", "hlink", "folHlink"], Mg = (a) => {
const e = {};
for (let t = 0; t < a.length; t++) {
const n = a[t], r = n[0], o = { name: r };
e[r] = o;
for (let s = 0; s < Qr.length; s++) {
const i = Qr[s], l = n[s + 1];
if (!l) continue;
const c = Qe.parse(l);
l && (o[i] = c.toString());
}
}
return e;
}, Tg = (a) => {
const e = {};
for (let t = 0; t < a.length; t++) {
const n = a[t], r = n[0], o = { name: r };
e[r] = o, o.majorFont = n[1] ?? Rl[1], o.minorFont = n[2] ?? Rl[2];
}
return e;
}, zp = Mg([[Yr, "windowText", "window", "44546A", "E7E6E6", "4472C4", "ED7D31", "A5A5A5", "FFC000", "5B9BD5", "70AD47", "0563C1", "954F72"]]), Pp = Tg([Rl]), Uo = zp[Yr], Or = Pp[Yr];
let rn = null;
const Hp = new class {
constructor() {
this._colors = {};
for (let a = 0; a < Qr.length; a++) {
const e = Qr[a], t = Qe.parse(Uo[e]);
this._colors[e] = t;
}
}
getName() {
return Uo.name;
}
getDk1() {
return this._colors.dk1;
}
getLt1() {
return this._colors.lt1;
}
getDk2() {
return this._colors.dk2;
}
getLt2() {
return this._colors.lt2;
}
getAccent1() {
return this._colors.accent1;
}
getAccent2() {
return this._colors.accent2;
}
getAccent3() {
return this._colors.accent3;
}
getAccent4() {
return this._colors.accent4;
}
getAccent5() {
return this._colors.accent5;
}
getAccent6() {
return this._colors.accent6;
}
getHlink() {
return this._colors.hlink;
}
getFolHlink() {
return this._colors.folHlink;
}
toJSON() {
return null;
}
}();
class Wp {
constructor(e, t = Hp) {
this._delegate = t, this._fromJSON(e);
}
_fromJSON(e) {
if (this._overrides = {}, !e) return;
const t = Object.keys(e);
if (t.length !== 0) for (let n = 0; n < t.length; n++) {
const r = t[n];
this._overrides[r] = r === "name" ? e[r] : Qe.parse(e[r]);
}
}
_value(e, t) {
return this._overrides && this._overrides[e] !== null && this._overrides[e] !== void 0 ? this._overrides[e] : this._delegate?.[t]?.();
}
getName() {
return this._value("name", "getName");
}
getDk1() {
return this._value("dk1", "getDk1");
}
getLt1() {
return this._value("lt1", "getLt1");
}
getDk2() {
return this._value("dk2", "getDk2");
}
getLt2() {
return this._value("lt2", "getLt2");
}
getAccent1() {
return this._value("accent1", "getAccent1");
}
getAccent2() {
return this._value("accent2", "getAccent2");
}
getAccent3() {
return this._value("accent3", "getAccent3");
}
getAccent4() {
return this._value("accent4", "getAccent4");
}
getAccent5() {
return this._value("accent5", "getAccent5");
}
getAccent6() {
return this._value("accent6", "getAccent6");
}
getHlink() {
return this._value("hlink", "getHlink");
}
getFolHlink() {
return this._value("folHlink", "getFolHlink");
}
toJSON() {
const e = F.toSafeJSON(this._overrides), t = this.getName();
return t && (e.name = t), e;
}
}
const jp = new class {
constructor() {
this._colors = {};
for (let a = 0; a < Qr.length; a++) {
const e = Qr[a], t = Qe.parse(Uo[e]);
this._colors[e] = t;
}
}
getName() {
return Or.name;
}
getMajorFont() {
return Or.majorFont;
}
getMinorFont() {
return Or.minorFont;
}
getMajorFallbacks() {
return Or.majorFallbacks;
}
getMinorFallbacks() {
return Or.minorFallbacks;
}
}();
class Vp {
constructor(e, t = jp) {
this._delegate = t, this._fromJSON(e);
}
_fromJSON(e) {
if (this._overrides = {}, !e) return;
const t = Object.keys(e);
if (t.length !== 0) for (let n = 0; n < t.length; n++) {
const r = t[n];
this._overrides[r] = e[r];
}
}
_value(e, t) {
return this._overrides && this._overrides[e] !== null && this._overrides[e] !== void 0 ? this._overrides[e] : this._delegate?.[t]?.();
}
getName() {
return this._value("name", "getName");
}
getMajorFont() {
return this._value("majorFont", "getMajorFont");
}
getMinorFont() {
return this._value("minorFont", "getMinorFont");
}
getMajorFallbacks() {
return this._value("majorFallbacks", "getMajorFallbacks");
}
getMinorFallbacks() {
return this._value("minorFallbacks", "getMinorFallbacks");
}
toJSON() {
const e = F.toSafeJSON(this._overrides), t = this.getName();
return t && (e.name = t), e;
}
}
class Al {
constructor(e, t = null, n = null) {
if (this._cacheColors = /* @__PURE__ */ new Map(), !t && e?.name) {
const l = rn ? rn.get(e.name.toLowerCase()) : null;
l && (t = l);
}
if (!t && rn && (t = rn.get(Yr.toLowerCase())), this._name = e?.name ?? t?.getName(), !this._name) throw new Error("Theme must have a name.");
this._builtInID = n, this._delegate = t, this._colors = new Wp(e?.colors, this._delegate?.getColorScheme()), this._fonts = new Vp(e?.fonts, this._delegate?.getFontScheme());
const r = Nh, o = {}, s = Object.keys(r);
for (let l = 0; l < s.length; l++) {
const c = s[l];
o[c] = `get${Xr(r[c])}`;
}
o.dk1 = "getDk1", o.dk2 = "getDk2", o.lt1 = "getLt1", o.lt2 = "getLt2", o.folhlink = "getFolHlink", this._colorMap = o;
const i = this;
this._schemeLookup = (l) => {
let c = i._cacheColors[l];
if (c) return c;
const h = i._colorMap[l];
if (!h) throw new Error(`Invalid color scheme key: ${l}`);
const u = i.getColorScheme();
let d = u[h].bind(u)();
return d || (d = Uo[Nh[l] ?? l]), c = new Qe(d).toRGBA(), i._cacheColors[l] = c, c;
};
}
get builtInID() {
return this._builtInID ?? null;
}
getName() {
return this._name ?? this._delegate?.getName() ?? null;
}
isCustom() {
return this._builtInID !== null && this._builtInID !== void 0;
}
getColorScheme() {
return this._colors;
}
getFontScheme() {
return this._fonts;
}
schemeLookup() {
return this._schemeLookup;
}
parseColor(e) {
return Qe.parse(e, this._schemeLookup);
}
toJSON() {
const e = { name: this.getName() }, t = this._colors.toJSON();
t && (Object.keys(t).length > 1 || t.name && t.name !== e.name) && (e.colors = t);
const n = this._fonts.toJSON();
return n && (Object.keys(n).length > 1 || n.name && n.name !== e.name) && (e.fonts = n), Object.keys(e).length === 1 && e.name === Yr ? null : e;
}
}
const $p = () => {
if (rn) return rn;
const a = ((t, n, r) => {
const o = [];
for (let s = 0; s < t.length; s++) {
const i = t[s], l = i[0], c = n[i[1]] ?? Uo, h = r[i[2]] ?? Or;
o.push({ name: l, colors: c, fonts: h });
}
return o;
})(Bp, Mg(Dp), Tg(Lp)), e = /* @__PURE__ */ new Map();
for (let t = 0; t < a.length; t++) {
const n = new Al(a[t]), r = new Al(null, n, t + 1);
e.set(r.getName().toLowerCase(), r);
}
return rn = e, e;
};
class Ng {
constructor(e = null, t = !1) {
$p(), this._isReadOnly = t, this._customMap = /* @__PURE__ */ new Map(), this._defaultTheme = this.getByName("Office");
}
getDefaultTheme() {
return this._defaultTheme;
}
setDefaultTheme(e) {
if (this._isReadOnly) throw new Error(Ra);
if (!e) throw new Error("Theme cannot be null.");
const t = this.getDefaultTheme();
return this.getByName(e.getName()) || this.setCustomTheme(e), this._defaultTheme = e, t;
}
getByName(e) {
return e = e.toLowerCase(), this._customMap.get(e) || (rn.get(e) ?? null);
}
getItems(e) {
const t = e?.type ?? ir.BuiltInFilterType.All, n = /* @__PURE__ */ new Map();
return t !== ir.BuiltInFilterType.BuiltIn && t !== ir.BuiltInFilterType.All || rn.forEach((r, o) => n.set(o, r)), t !== ir.BuiltInFilterType.Custom && t !== ir.BuiltInFilterType.All || this._customMap.forEach((r, o) => n.set(o, r)), e?.selected && n.set(e.selected.getName().toLowerCase(), e.selected), ((r) => {
const o = [...r];
return o.sort((s, i) => F.isDefined(s.builtInID) && !F.isDefined(i.builtInID) ? 1 : !F.isDefined(s.builtInID) && F.isDefined(i.builtInID) ? -1 : F.isDefined(s.builtInID) && F.isDefined(i.builtInID) ? s.builtInID - i.builtInID : s.getName().localeCompare(i.getName())), o;
})(Array.from(n.values()));
}
getCount() {
return this._customMap.size + rn.size;
}
setCustomTheme(e) {
if (this._isReadOnly) throw new Error(Ra);
const t = e.getName().toLowerCase(), n = this._customMap.get(t);
return this._customMap.set(t, e), n ?? null;
}
deleteCustomTheme(e) {
if (this._isReadOnly) throw new Error(Ra);
let t = null;
t = typeof e == "string" ? e.toLowerCase() : e.getName().toLowerCase();
const n = this._customMap.get(t);
return this._customMap.delete(t), n ?? null;
}
}
var ar, bt;
(ar || (ar = {})).ElementType = { WholeTable: "wholeTable", FirstColumnStripe: "firstColumnStripe", SecondColumnStripe: "secondColumnStripe", FirstRowStripe: "firstRowStripe", SecondRowStripe: "secondRowStripe", LastColumn: "lastColumn", FirstColumn: "firstColumn", HeaderRow: "headerRow", TotalRow: "totalRow", FirstHeaderCell: "firstHeaderCell", LastHeaderCell: "lastHeaderCell", FirstTotalCell: "firstTotalCell", LastTotalCell: "lastTotalCell" }, (ar || (ar = {})).Empty = class {
constructor(a) {
this._normalStyle = a;
}
getName() {
return "None";
}
isShownInTableStyles() {
return !1;
}
isShownInPivotStyles() {
return !1;
}
getRanged(a) {
return null;
}
getProperties() {
return F.EmptyObject;
}
isBuiltIn() {
return !0;
}
delete() {
}
toJSON() {
return null;
}
get isITableStyle() {
return !0;
}
}, (bt || (bt = {})).Type = { Absolute: "absolute", OneCell: "oneCell", TwoCell: "twoCell" };
const Ht = "Model has been closed. No further operations are allowed.", Fh = "Name is required";
class mt {
constructor(e, t) {
this._listeners = /* @__PURE__ */ new Set(), this._pending = null, this._listeners = /* @__PURE__ */ new Set(), this._transactions = t ?? new Xt({ transient: !0 }), this._src = e;
const n = this;
this._transactionsRemoveListener = this._transactions?.addListener({ onCommitEnd(r) {
const o = n._pending;
if (!o) return;
n._pending = null;
const s = r.getId(), i = /* @__PURE__ */ new Set();
for (let l = 0; l < o.length; l++) {
const c = o[l];
c.commitId === s && n._doNotify(c.listeners, c.removes, c.options, i);
}
} });
}
addListeners(e, t) {
const n = t?.transactional ?? this._transactions.isOpenTransaction(), r = { listeners: e }, o = this, s = () => {
if (!n) return void o._listeners.delete(r);
const i = o._transactions.getState(o)?.listeners, l = new Set(i);
l.delete(r);
const c = o._transactions.beginCommit();
try {
c.updateState(o, { listeners: l }), c.commit({ forceAmend: !0 });
} catch (h) {
throw c.rollback(), h;
}
};
if (r.remove = t?.once ? s : null, n) {
const i = o._transactions.getState(o)?.listeners, l = new Set(i);
l.add(r);
const c = this._transactions.beginCommit();
try {
c.updateState(o, { listeners: l }), c.commit({ forceAmend: !0 });
} catch (h) {
throw c.rollback(), h;
}
} else o._listeners.add(r);
return s;
}
async _doNotify(e, t = null, n, r) {
const o = n?.source ?? this._src, s = [], i = n?.params;
for (let c = 0; c < e.length; c++) {
const h = e[c];
r && r.has(h) || (r?.add(h), s.push(h(o, i)));
}
let l = null;
if (t && (l = () => {
for (let c = 0; c < t.length; c++) t[c]();
}), n?.async) return new Promise(async (c, h) => {
try {
const u = await Promise.all(s);
l?.(), c(u);
} catch (u) {
l?.(), h(u);
}
});
l?.();
}
notify(e, t) {
let n = null, r = null;
const o = (u) => {
u.forEach((d) => {
const g = d.listeners[e];
g && (n || (n = []), n.push(g), d.remove && (r || (r = []), r.push(d.remove)));
});
}, s = t?.transactional ?? this._transactions.isOpenTransaction();
if (s) {
const u = this._transactions.getState(this)?.listeners;
u && o(u);
}
const i = n, l = r;
n = null, r = null, o(this._listeners);
const c = n, h = r;
if (n = null, r = null, s) {
if (i && this._doNotify(i, l, t), c) {
let u = this._pending;
return u || (this._pending = u = []), u.push({ commitId: this._transactions.getCurrentCommit().getId(), listeners: c, removes: h, options: t }), this._doNotify(c, l, t);
}
} else if (c) return this._doNotify(c, h, t);
}
close() {
this._transactions.remove(this), this._transactionsRemoveListener();
}
}
class mr {
constructor(e) {
this._emitter = null, this._closed = !1, this._options = { ...e };
const t = this;
this._transactions = this._options?.transactions ?? new Xt({ transient: !0 }), this._emitter = new mt(this, this._transactions), this._updateState({ isDeleted: !1 }), e?.json && this._fromJSON(e.json), this._options?.setContainerReadOnlyCallback?.(() => {
t._processOnContainerReadOnly();
}), this._transactionsRemoveListener = this._transactions.addStateListener(this, { onAfterStateChange(n, r, o) {
t._processStateChange(n, r, o);
}, onRestoreOrRevert(n, r, o) {
t._processRestoreOrRevert(n, r, o);
} }), this._processInit();
}
_fromJSON(e) {
}
isReadOnly() {
return this._options.isReadOnly?.() ?? !1;
}
isDeleted() {
return this._getState().isDeleted ?? !1;
}
getType() {
return this._options.type;
}
get isIModel() {
return !0;
}
_processTransactionDone(e) {
}
_getDescription() {
return null;
}
_getState() {
if (this._closed) throw new Error(Ht);
return this._transactions.getState(this);
}
_beginCommit(e) {
return this._transactions.beginCommit(typeof e == "string" ? { description: e } : e);
}
_getTransactions() {
return this._transactions;
}
_updateState(e, t, n) {
if (this._closed) throw new Error(Ht);
if (!e) return;
const r = this._beginCommit(t?.description);
try {
r.updateState(this, e);
let o = !1;
if (n) for (let s = 0; s < n.length; s++) {
const i = n[s];
o = o || i === "onAnyChange", this._emitter.notify(i);
}
!o && n && n.length > 0 && this._emitter.notify("onAnyChange"), r.commit();
} catch (o) {
throw r.rollback(), o;
}
return this;
}
_getEmitter() {
return this._emitter;
}
_processInit() {
}
_processStateChange(e, t, n) {
}
_processRestoreOrRevert(e, t, n) {
this._emitter.notify("onInvalidated");
}
delete(e) {
if (this._getState().isDeleted) throw new Error("Model has been deleted.");
this._options.deleteFromContainer && this._options.deleteFromContainer?.(e), this._delete();
}
_delete() {
const e = this._getDescription(), t = "Delete", n = e ? `${t} ${e}` : t, r = this._beginCommit(n);
try {
this._processDelete(), r.commit();
} catch (o) {
throw r.rollback(), o;
}
}
_processOnContainerDeleted() {
this._processDelete();
}
_processDelete() {
this._updateState({ isDeleted: !0 }, null, ["onDelete"]);
}
_processOnContainerReadOnly() {
this._emitter.notify("onReadOnlyChange");
}
addListeners(e, t) {
return this._emitter.addListeners(e, t);
}
beginCommit(e) {
return this._beginCommit(e);
}
doBatch(e, t) {
const n = this;
return this._transactions.doBatch(e, typeof t == "string" ? { description: t } : t, (r) => {
n._processTransactionDone(r);
});
}
isClosed() {
return this._closed;
}
close() {
this._closed || (this._emitter.notify("onClose"), this._closed = !0, this._transactionsRemoveListener?.());
}
}
class Fg extends mr {
_fromJSON(e) {
const t = {};
if (t.name = e?.name ?? null, !t.name) throw new Error(Fh);
t.comment = e?.comment ?? null, t.hidden = e?.hidden ?? !1, t.scope = e?.scope ?? null, this._updateState(t, { description: this._options.createDescription ?? "Create Item" + (t.name ? ` '${t.name}'` : "") });
}
_toJSON() {
const e = this._getState(), t = { name: e.name };
return e.comment && (t.comment = e.comment), e.hidden && (t.hidden = e.hidden), e.hidden && (t.hidden = e.hidden), t;
}
getName() {
return this._getState().name;
}
setName(e, t) {
if (!e) throw new Error(Fh);
return this._updateState({ name: e }, { description: `Update Named '${e}'`, ...t });
}
getComment() {
return this._getState().comment;
}
setComment(e, t) {
return this._updateState({ comment: e }, { description: "Set Comment", ...t });
}
isHidden() {
return this._getState().hidden;
}
getScope() {
return this._getState().scope;
}
get isINamed() {
return !0;
}
}
var kh, Vr, yt;
(kh || (kh = {})).SortOn = { Value: "value", FillColor: "fillColor", FontColor: "fontColor", Icon: "icon" }, (yt = Vr || (Vr = {})).CaseInsensitiveOptions = { sensitivity: "base", numeric: !1 }, yt.CaseSensitiveOptions = { sensitivity: "case", numeric: !1 }, yt.BooleanCollator = Object.freeze({ type: q.Boolean, compare: (a, e, t) => a === !0 ? 1 : -1 }), yt.StringCollator = Object.freeze({ type: q.String, compare: (a, e, t) => a.localeCompare(e, "en", t), defaultOptions: yt.CaseInsensitiveOptions }), yt.NumberCollator = Object.freeze({ type: q.Number, compare: (a, e, t) => a < e ? -1 : 1 }), yt.RichDataCollator = Object.freeze({ type: q.RichData, compare: (a, e, t) => a.type.localeCompare(e.type, "en") }), yt.DefaultRangeOptions = Object.freeze({ hasHeader: !1, reverse: !1, includeHidden: !1, collatorOptions: yt.CaseInsensitiveOptions, orientation: O.Orientation.Row, offset: 0 }), yt.DefaultCollators = Object.freeze([yt.BooleanCollator, yt.StringCollator, yt.NumberCollator, yt.RichDataCollator]);
const Gp = (a, e, t, n) => {
let r;
for (; !(r = a.next()).done; ) try {
e(r.value[1], r.value[0], t);
} catch (o) {
if (typeof a.throw != "function") throw o;
a.throw(o);
}
typeof a.return == "function" && a.return();
}, kg = (a) => {
const e = a.next.bind(a), t = { next: (n) => {
const r = e(n);
return r.done ? ke : { done: r.done, value: r.value[1] };
}, [Symbol.iterator]: () => t, ...a.return && { return: a.return.bind(a) }, ...a.throw && { throw: a.throw.bind(a) } };
return t;
}, uo = (a) => {
if (!a || a.length === 0) return null;
let e = Number.MAX_SAFE_INTEGER, t = -1, n = null;
return (r, o = !1) => {
if (r === e) return r;
o !== !1 && (e = Number.MAX_SAFE_INTEGER), r !== e + (o ? -1 : 1) && (t = ((i, l, c = !0) => {
if (!i || i.length === 0) return null;
let h, u = -1;
return c ? (u = F.findEqualOrGreater(i, l, (d) => d.max), h = i[u]) : (u = F.findEqualOrLesser(i, l, (d) => d.min), h = i[u]), h ? (c ? l > h.max && (u += 1, h = i[u]) : l < h.min && (u -= 1, h = i[u]), h ? u : -1) : -1;
})(a, r, !o), n = a[t]);
let s = r;
if (o) for (; n && s <= n.max; ) s = n.min - 1, n = a[--t];
else for (; n && s >= n.min; ) s = n.max + 1, n = a[++t];
return e = s, s;
};
}, ke = Object.freeze({ done: !0, value: void 0 }), Ze = Object.freeze({ next: () => ke, [Symbol.iterator]: () => Ze });
var $r;
Object.seal({ done: !1, value: void 0 }), ((a) => {
a.isList = (t) => !!t && !!t.isIList, a.isListLike = (t) => !!t && typeof t.length == "number" && typeof t.at == "function", a.fromArray = (t, n, r, o) => new e(t, n, r, o);
class e {
constructor(n, r, o, s) {
this.g = r, this.s = o;
let i = n ?? s;
if (o && n && !s) {
s = new Array(n.length);
for (let l = 0; l < n.length; l++) {
let c = n[l];
s[l] = o(c, l);
}
i = s;
}
this.a = i ?? F.EmptyArray, r && (this.at = (l) => {
l < 0 && (l = i.length + l);
const c = i[l];
if (c !== void 0) return r(c, l);
});
}
at(n) {
const r = this.a;
return n < 0 && (n = r.length + n), r[n];
}
fromArray(n) {
return new e(n, this.g, this.s);
}
get length() {
return this.a.length;
}
get isIList() {
return !0;
}
}
a.ArrayList = e;
})($r || ($r = {}));
class jt {
constructor(e) {
if (this._s = null, this._r = null, this._l = 0, e && e.length > 0) {
const t = $r.isList(e) && !Array.isArray(e) ? e : new $r.ArrayList(e);
this._s = t, this._l = e.length;
}
}
at(e) {
const t = this._s;
if (t) return t.at(e);
const n = this._c;
if (n && n.min <= e && n.max >= e) {
const i = n.value;
return i.v.at(e - n.min + i.s);
}
const r = this._r, o = r[F.findEqualOrGreater(r, e, (i) => i.max)];
if (!o) return;
const s = o.value;
return this._c = o, s.v.at(e - o.min + s.s);
}
toArray(e = Number.MAX_SAFE_INTEGER) {
const t = [], n = this.entries(Up);
let r = n.next();
for (; !r.done && t.length < e; ) t.push(r.value[1]), r = n.next();
return t;
}
entries(e) {
const t = this.length;
if (t === 0) return Ze;
let n, r, o, s = !0, i = 0, l = t - 1;
if (e) {
s = !e.reverse;
const g = e.bounds;
g && (i = Math.max(g.min ?? i, i), l = Math.min(g.max ?? l, l)), n = e.reuseResult ?? null, r = e.processSkip;
}
const c = s ? 1 : -1;
let h = (s ? i : l) - c;
const u = this._s;
if (u) o = (g) => {
if (!(g < i || g > l)) return u.at(g);
};
else {
const g = this._r;
let m = s ? 0 : g.length - 1, f = g[m];
const _ = (p, S) => {
const E = p === m ? f : g[p];
if (E && S >= E.min && S <= E.max) return m = p, f = E, E;
};
o = (p) => {
if (p < i || p > l) return;
let S = _(m, p);
if (S || (S = _(m + c, p)), !S) {
const y = F.findEqualOrGreater(g, p, (C) => C.max);
S = _(y, p);
}
if (!S) return;
const E = S.value;
return E.v.at(p - S.min + E.s);
};
}
const d = { next: (g) => {
let m, f = h + c;
return g !== void 0 && (g < 0 && (g = t + g), f = g), f < i || f > l || r && (f = r(f, !s), f < i || f > l) ? ke : (m = o(f), h = f, n ? (Fo.done = !1, Fo.value[0] = f, Fo.value[1] = m, Fo) : { done: !1, value: [h, m] });
}, [Symbol.iterator]: () => d };
return d;
}
slice(e, t = void 0) {
const n = this._r ?? Oh(this._s);
if (!n) return Aa;
const r = this.length;
if (e = Math.min(Math.max(0, e), r), (t = Math.min(Math.max(0, t ?? r), r)) - e <= 0) return Aa;
if (e <= 0 && t >= r) return this;
const o = e, s = t - 1;
let i = [], l = 0;
for (let h = 0; h < n.length; h++) {
let u = n[h];
const d = u.max;
if (o === 0 && d <= s) {
i.push(u);
continue;
}
const g = u.min;
if (g > s) {
h = n.length;
continue;
}
if (d < o) {
l = d + 1;
continue;
}
const m = Math.max(0, o - g), f = Math.max(0, d - s), _ = f + m, p = u.value;
i.push({ min: g - l, max: d - _ - l, value: { s: p.s + m, e: p.e - f, v: p.v } }), l += _;
}
const c = new jt();
return c._r = i, c._l = s - o + 1, c;
}
concat(e) {
if (!e) return this;
if (!$r.isListLike(e)) throw new Error("Value must be IListLike");
const t = this._l;
if (t === 0) return e.isIReadableList ? e : e.length === 0 ? Aa : new jt(e);
const n = e, r = e.length;
if (r === 0) return this;
const o = this._r ?? Oh(this._s), s = o.slice(0, o.length - 1);
let i = o[o.length - 1], l = i ? i.min : 0, c = i ? i.max : 0, h = i ? i.value : null, u = h ? h.v : null, d = h ? h.e - h.s : 0;
const g = (_) => {
const p = _.s, S = _.e, E = S - p;
if (E + d < Jp && u && u.fromArray) {
let w = _.v;
const b = [], x = h.s, I = h.e;
for (let R = x; R <= I; R++) b.push(u.at(R));
for (let R = p; R <= S; R++) b.push(w.at(R));
const v = u.fromArray(b);
if (v) return w = v, d = w.length - 1, h = { s: 0, e: d, v: w }, i = { min: l, max: l + d, value: h }, c = l + d, void (u = w);
}
s.push(i);
const y = c + 1, C = y + E;
i = { min: y, max: C, value: _ }, l = y, c = C, h = i ? i.value : null, u = h ? h.v : null, d = h ? h.e - h.s : 0;
};
if (e instanceof jt) {
const _ = e._s;
if (_) g({ s: 0, e: _.length - 1, v: _ });
else {
const p = e._r;
for (let S = 0; S < p.length; S++)
g(p[S].value);
}
} else g({ s: 0, e: r - 1, v: n });
s.push(i);
const m = new jt(), f = t + r;
return s.length === 1 && s[0].min === 0 && s[0].max === f - 1 ? m._s = s[0].value.v : m._r = s, m._l = f, m;
}
get length() {
return this._l;
}
[Symbol.iterator]() {
return kg(this.entries());
}
get isIReadableList() {
return !0;
}
get isIList() {
return !0;
}
get [Symbol.toStringTag]() {
return "[ImmutableList]";
}
toString() {
const e = this.length;
if (e === 0) return "";
let t = "";
for (let n = 0; n < e; n++) {
n > 0 && (t += ",");
const r = this.at(n);
t += r == null ? "" : String(r);
}
return t;
}
}
const Oh = (a) => [{ min: 0, max: a.length - 1, value: { s: 0, e: a.length - 1, v: a } }], Aa = new jt(), Fo = Object.seal({ done: !1, value: [-1, null] }), Up = Object.freeze({ reverse: !1, bounds: { min: 0, max: Number.MAX_SAFE_INTEGER }, skipRuns: null, reuseResult: Fo }), Jp = 4;
var xi;
((a) => {
const e = (n, r) => {
const o = n !== xe.Row;
return r ? (s, i) => {
if (s === i) return 0;
const l = s[0], c = s[1], h = i[1];
if (c === h) return l ? -1 : 1;
const u = i[0];
let d = 0, g = 0;
if (o ? (d = l ? c.colEnd : c.colStart, g = u ? h.colEnd : h.colStart) : (d = l ? c.rowEnd : c.rowStart, g = u ? h.rowEnd : h.rowStart), d === g && l !== u) return l ? -1 : 1;
if (d !== g) return g - d;
let m = 0, f = 0;
if (o ? (m = l ? c.colStart : c.colEnd, f = u ? h.colStart : h.colEnd) : (m = l ? c.rowStart : c.rowEnd, f = u ? h.rowStart : h.rowEnd), m === f && l !== u) return l ? -1 : 1;
if (m !== f) return f - m;
const _ = s[2] ?? 0;
return (i[2] ?? 0) - _;
} : (s, i) => {
if (s === i) return 0;
const l = s[0], c = s[1], h = i[1];
if (c === h) return l ? -1 : 1;
const u = i[0];
let d = 0, g = 0;
if (o ? (d = l ? c.colStart : c.colEnd, g = u ? h.colStart : h.colEnd) : (d = l ? c.rowStart : c.rowEnd, g = u ? h.rowStart : h.rowEnd), d === g && l !== u) return l ? -1 : 1;
if (d !== g) return d - g;
let m = 0, f = 0;
return o ? (m = l ? c.colEnd : c.colStart, f = u ? h.colEnd : h.colStart) : (m = l ? c.rowEnd : c.rowStart, f = u ? h.rowEnd : h.rowStart), m === f && l !== u ? l ? -1 : 1 : m !== f ? m - f : (s[2] ?? 0) - (i[2] ?? 0);
};
};
class t {
constructor(r, o) {
if (this._isColumn = !0, this._isByCell = !1, this._isReverse = !1, this._cursor = null, this._reuse = null, this._localReuse = { done: !1, value: [null, null] }, this._eventsMajor = null, this._eventMajorIndex = 0, this._majorStart = 0, this._majorEnd = 0, this._eventMinorPeek = null, this._minorStart = 0, this._minorEnd = 0, !r || r.length === 0) return;
let s = xe.Column, i = !1, l = !0, c = !1;
o && (s = o.orientation ?? xe.Column, this._isColumn = l = s !== xe.Row, this._isReverse = i = o.reverse ?? !1, this._isByCell = c = o.byCell ?? !1);
const h = r.length, u = new Array(2 * h);
for (let f = 0; f < h; f++) {
const _ = r[f], p = [null, null];
u[2 * f] = [!0, _, f, p], u[2 * f + 1] = [!1, _, f, p];
}
u.sort(e(s, i)), this._eventsMajor = u;
const d = u[0][1];
this._majorStart = i ? Number.MAX_SAFE_INTEGER : Number.MIN_SAFE_INTEGER, this._majorEnd = l ? i ? d.colEnd + 1 : d.colStart - 1 : i ? d.rowEnd + 1 : d.rowStart - 1, this._eventsMinor = new Ae(null, e(l ? xe.Row : xe.Column, i));
const g = new Array(16);
g.length = 0, this._cursor = { cell: null, range: { colStart: d.colStart, rowStart: d.rowStart, colEnd: d.colEnd, rowEnd: d.rowEnd }, overlaps: g }, c && (this._cursor.cell = { colIndex: i ? Number.MIN_SAFE_INTEGER : Number.MAX_SAFE_INTEGER, rowIndex: i ? Number.MIN_SAFE_INTEGER : Number.MAX_SAFE_INTEGER });
const m = o?.reuseIterator;
m && (this._reuse = m, m.value = this._cursor);
}
next(r) {
const o = this._isColumn, s = this._isReverse;
if (r) {
if (!this._isByCell) throw new Error("nextCell is only supported when byCell is true");
const I = D.createCellComparator(o ? xe.Column : xe.Row, s);
let v;
do {
const R = this._cursor, A = R.cell;
if (A.colIndex !== Number.MAX_SAFE_INTEGER && I(A, r) >= 0) throw new Error("nextCell must be after the current iteration cell");
if (v = this.next(), v.done) return v;
const M = v.value.cell;
if (I(M, r) >= 0) return v;
const T = R.range;
if (o) {
const k = r.colIndex === A.colIndex;
A.rowIndex = s ? k ? Math.max(r.rowIndex, T.rowStart) : T.rowStart : k ? Math.min(r.rowIndex, T.rowEnd) : T.rowEnd;
} else {
const k = r.rowIndex === A.rowIndex;
A.colIndex = s ? k ? Math.max(r.colIndex, T.colStart) : T.colStart : k ? Math.min(r.colIndex, T.colEnd) : T.colEnd;
}
if (I(A, r) >= 0) return M.rowIndex = A.rowIndex, M.colIndex = A.colIndex, v;
} while (!v.done);
return v;
}
let i = this._cursor;
if (!i) return ke;
let l = this._reuse;
if (!l) {
const I = i.cell, v = i.range, R = { cell: null, range: { colStart: v.colStart, rowStart: v.rowStart, colEnd: v.colEnd, rowEnd: v.rowEnd }, overlaps: [...i.overlaps] };
I && (R.cell = { colIndex: I.colIndex, rowIndex: I.rowIndex }), this._cursor = R, l = { done: !1, value: R };
}
const c = l.value, h = c.range, u = c.cell, d = this._isByCell, g = s ? -1 : 1;
let m = !1;
if (d) {
const I = u.rowIndex, v = u.colIndex, R = o ? I : v, A = o ? s ? h.rowStart : h.rowEnd : s ? h.colStart : h.colEnd;
if ((s ? R >= A : R <= A) && (o ? u.rowIndex = I + g : u.colIndex = v + g, s ? R > A : R < A))
return l;
const M = o ? u.colIndex : u.rowIndex, T = o ? s ? h.colStart : h.colEnd : s ? h.rowStart : h.rowEnd;
(s ? M > T : M < T) && (m = !0);
}
const f = c.overlaps;
let _ = this._majorStart, p = this._majorEnd, S = this._eventsMinor, E = this._minorStart, y = this._minorEnd, C = this._eventsMinorIterator, w = this._eventMinorPeek, b = w;
for (; b && !b.done; ) {
const I = b.value[0];
if (I[0]) b = null;
else {
if (w = C.next(), w.done) f.length = 0;
else {
const v = I[1];
let R = f.length;
if (R > 1) {
const A = f.indexOf(v);
A !== -1 && (f[A] = f[R - 1]);
}
if (f.length = R - 1, R = f.length, R > 0) {
const A = w.value[0], M = A[1], T = o ? s ? M.colStart : M.colEnd : s ? M.rowStart : M.rowEnd;
if (s ? _ >= T : _ <= T) {
let k = !1;
if (A[0]) {
const P = o ? s ? M.rowEnd : M.rowStart : s ? M.colEnd : M.colStart;
(s ? P < y + g : P > y + g) && (E = y + g, y = P - g, k = !0);
} else {
const P = o ? s ? M.rowStart : M.rowEnd : s ? M.colStart : M.colEnd;
(s ? P < y : P > y) && (E = y + g, y = P, k = !0);
}
if (k) return o ? (h.rowStart = s ? y : E, h.rowEnd = s ? E : y) : (h.colStart = s ? y : E, h.colEnd = s ? E : y), this._minorStart = E, this._minorEnd = y, this._eventMinorPeek = w, l;
}
}
}
w.done && (w = null), b = w;
}
}
if (!w) if (m) {
C = S.entries(void 0, this._localReuse), w = C.next(), this._eventsMinorIterator = C;
const I = w.value[0][1], v = o ? s ? I.rowEnd : I.rowStart : s ? I.colEnd : I.colStart;
o ? (u.colIndex = u.colIndex + g, u.rowIndex = v) : (u.colIndex = v, u.rowIndex = u.rowIndex + g);
} else {
let I = this._eventMajorIndex;
const v = this._eventsMajor, R = v.length;
if (I >= R) return this._cursor = null, ke;
let A = v[I], M = A[0], T = !1;
for (; !M && !T && A; ) {
const P = A[1], B = o ? s ? P.colStart : P.colEnd : s ? P.rowStart : P.rowEnd;
if (s ? B < p : B > p) {
T = !0;
continue;
}
const H = A[3];
S.delete(H[0]), S.delete(H[1]), I++, A = v[I], A && (M = A[0]);
}
let k = S.size > 0 ? p + g : -1;
for (T = !1; M && !T && A; ) {
const P = A[1];
if (k !== -1 && (o ? s ? P.colEnd : P.colStart : s ? P.rowEnd : P.rowStart) !== k) {
T = !0;
continue;
}
const B = A[2], H = [!0, P, B], z = [!1, P, B], W = A[3];
if (W[0] = H, W[1] = z, S.set(H, 0), S.set(z, 0), k === -1 && (k = o ? s ? P.colEnd : P.colStart : s ? P.rowEnd : P.rowStart), I++, A = v[I], !A || (M = A[0], !M)) continue;
const L = A[1];
(o ? s ? L.colEnd : L.colStart : s ? L.rowEnd : L.rowStart) !== k && (T = !0);
}
if (k !== -1 && (_ = k), d && (o ? u.colIndex = _ : u.rowIndex = _), this._eventMajorIndex = I, I >= R) return this._eventsMinorIterator = C, this._cursor = null, ke;
if (A) {
const P = A[0], B = A[1], H = o ? s ? B.colEnd : B.colStart : s ? B.rowEnd : B.rowStart, z = o ? s ? B.colStart : B.colEnd : s ? B.rowStart : B.rowEnd;
p = P ? H - g : z;
}
f.length = 0, C = S.entries(void 0, this._localReuse), w = C.next(), this._eventsMinorIterator = C;
}
let x = w;
do {
const I = x.value;
x = null;
const v = I[0], R = v[1];
if (!v[0]) continue;
const A = o ? s ? R.rowEnd : R.rowStart : s ? R.colEnd : R.colStart;
E !== A && (E = A), w = C.next();
const M = w.value[0], T = M[0], k = M[1], P = o ? s ? k.rowEnd : k.rowStart : s ? k.colEnd : k.colStart;
if (T && P === E) x = w;
else {
const B = o ? s ? R.rowStart : R.rowEnd : s ? R.colStart : R.colEnd, H = o ? s ? k.rowStart : k.rowEnd : s ? k.colStart : k.colEnd;
y = (s ? Math.max : Math.min)(B, T ? P - g : H), d && (o ? u.rowIndex = E : u.colIndex = E);
}
f[f.length] = Object.freeze(R);
} while (x);
return o ? (h.colStart = s ? p : _, h.colEnd = s ? _ : p, h.rowStart = s ? y : E, h.rowEnd = s ? E : y) : (h.rowStart = s ? p : _, h.rowEnd = s ? _ : p, h.colStart = s ? y : E, h.colEnd = s ? E : y), this._eventMinorPeek = w, this._minorStart = E, this._minorEnd = y, this._majorStart = _, this._majorEnd = p, l;
}
return(r) {
return null;
}
throw(r) {
return null;
}
[Symbol.iterator]() {
return this;
}
}
a.IteratorInstance = t;
})(xi || (xi = {}));
const zn = (a, e = He.Right, t = null) => {
if (!a) return a;
if (a.length === 0) return [];
const n = e === He.Right, r = e === He.Left, o = e === He.Up, s = e === He.Down;
return a.sort((i, l) => {
if (!i && !l) return 0;
if (i && !l) return -1;
if (l && !i) return 1;
const c = t?.(i, l) ?? 0;
return c !== 0 ? c : n ? i.rowStart === l.rowStart ? i.colStart - l.colStart : i.rowStart - l.rowStart : s ? i.colStart === l.colStart ? i.rowStart - l.rowStart : i.colStart - l.colStart : r ? i.rowStart === l.rowStart ? l.colStart - i.colStart : l.rowStart - i.rowStart : o ? i.colStart === l.colStart ? l.rowStart - i.rowStart : l.colStart - i.colStart : 0;
});
}, qp = (a, e) => {
const t = e.min, n = a.min;
if (e.max === Number.MAX_SAFE_INTEGER) {
const r = t, o = a.max;
return n <= r && r <= o ? 0 : o < r ? -1 : n > r ? 1 : (console.warn("coords are not inserted correctly", a, e), 0);
}
return n - t;
};
class qn {
constructor(e) {
this._runs = null, this._dataCoords = null, this._count = 0, this._length = 0, this._maxCoords = null, this._options = e, e?.maxCoords && (this._maxCoords = Object.freeze({ ...e.maxCoords })), this._runs = new Ae(void 0, qp, e?.nodeSize), this._reuseRunsIterator = { done: !1, value: [null, null] }, this._reuseRunsEntry = [null, null];
}
_validateBounds(e = Number.MIN_SAFE_INTEGER, t = Number.MAX_SAFE_INTEGER) {
const n = this._maxCoords, r = n?.min ?? Number.MIN_SAFE_INTEGER, o = n?.max ?? Number.MAX_SAFE_INTEGER;
if (e < r || t > o) throw new ze();
}
entries(e) {
let t, n, r = Number.MIN_SAFE_INTEGER, o = Number.MAX_SAFE_INTEGER, s = !0;
e && (e?.bounds && (r = e.bounds?.min ?? Number.MIN_SAFE_INTEGER, o = e.bounds?.max ?? Number.MAX_SAFE_INTEGER, this._validateBounds(r, o)), s = !e.reverse, t = Kp(e.reuseResult), n = e.processSkip);
const i = this._dataCoords;
if (!i) return Ze;
r = Math.max(i.min, r), o = Math.min(i.max, o);
let l = null, c = null, h = Number.MAX_SAFE_INTEGER, u = Number.MIN_SAFE_INTEGER;
if (n) {
const _ = n;
n = (p, S) => _(p + h, S) - h;
}
const d = (_) => {
let p;
_ !== Number.MIN_SAFE_INTEGER && _ !== Number.MAX_SAFE_INTEGER && (Ot.min = _, p = Ot), l = s ? this._runs.entries(p, this._reuseRunsIterator) : this._runs.entriesReversed(p, this._reuseRunsIterator), h = Number.MAX_SAFE_INTEGER, u = Number.MIN_SAFE_INTEGER, c = null;
}, g = (_) => {
if (_ !== void 0) {
if (_ < h || _ > u) return void (c = void 0);
_ -= h;
}
if (!c) return;
let p = c.next(_);
if (!c) return;
let S = p.value, E = S?.[1];
return p.done ? void (c = void 0) : Xp(S[0] + h, E, t);
}, m = (_) => {
let p;
return p = g(_), p || (p = ((S) => {
let E;
do {
if (S !== void 0 && d(S), !l) return;
if (E = l.next(), E.done) return void (l = void 0);
const y = E.value, C = y[0], w = y[1], b = C.min, x = C.max, I = Math.max(b, r) - b, v = Math.max(I, Math.min(x, o)) - b;
Rr.bounds.min = I, Rr.bounds.max = v, Rr.reverse = !s, Rr.processSkip = n, Rr.reuseResult = t, h = b, u = x, c = w.entries(Rr);
const R = g(S);
if (R) return R;
S = void 0;
} while (!E.done);
l = void 0;
})(_), p || ke);
}, f = { next(_) {
if (_ !== void 0 && (_ < 0 || _ > o)) throw new ze();
return m(_);
}, return: (_) => null, throw: (_) => null };
return d(s ? r : o), f;
}
runs(e) {
let t, n = Number.MIN_SAFE_INTEGER, r = Number.MAX_SAFE_INTEGER, o = !0, s = !1;
e && (e.bounds && (n = e.bounds?.min ?? Number.MIN_SAFE_INTEGER, r = e.bounds?.max ?? Number.MAX_SAFE_INTEGER, this._validateBounds(n, r), e.overflowRun && (s = !0)), o = !e.reverse, t = Yp(e.reuseResult));
const i = this._dataCoords;
if (!i) return Ze;
n = Math.max(i.min, n), r = Math.min(i.max, r);
let l = null;
const c = (u) => {
let d;
u !== Number.MIN_SAFE_INTEGER && u !== Number.MAX_SAFE_INTEGER && (Ot.min = u, d = Ot), l = o ? this._runs.entries(d, this._reuseRunsIterator) : this._runs.entriesReversed(d, this._reuseRunsIterator);
}, h = { next(u) {
if (u !== void 0) {
if (u < n || u > r) throw new ze();
c(u);
}
if (!l) return ke;
const d = l.next();
if (d.done) return l = void 0, ke;
const g = d.value, m = g[0];
let f = m;
const _ = f.min, p = f.max;
if (o && _ > r || !o && p < n) return ke;
let S = g[1];
return s || (p > r && (S = S.slice(0, S.length - (p - r)), f = { ...f }, f.max = r), _ < n && (S = S.slice(n - _), f === m && (f = { ...f }), f.min = n)), Qp(f, S, t);
}, return: (u) => null, throw: (u) => null };
return c(o ? n : r), h;
}
slice(e, t) {
const n = this._runs, r = n.minKey().min, o = n.maxKey().max;
if (t === void 0 && (t = o + 1), this._count === 0 || e <= r && t - 1 >= o) return this.clone();
const s = Math.max(r, e), i = Math.min(o, t - 1), l = i - s, c = [];
let h = 0;
Ta.bounds.min = s, Ta.bounds.max = i;
const u = this.runs(Ta);
let d = u.next();
for (; !d.done; ) {
const m = d.value;
let f = m[0], _ = m[1];
f = { min: f.min - s, max: f.max - s }, f.min < 0 && (_ = _.slice(-f.min), f.min = 0), f.max >= l && (_ = _.slice(0, _.length - (f.max - l)), f.max = l), h += _.length, c.push([f, _]), d = u.next();
}
const g = new qn(this._options);
return g._runs.setPairs(c), g._updateCount(h), g;
}
concat(e) {
const t = this.clone();
if (!e || e.length === 0) return t;
const n = this._runs.nextLowerPair(void 0, this._reuseRunsEntry), r = n[0], o = n[1], s = r.max + 1;
let i = !1, l = 0;
const c = [];
if (e.isISparseList) {
const h = e.runs();
let u = h.next();
for (; !u.done; ) {
const d = u.value;
let g = d[0];
const m = { min: g.min + s, max: g.max + s };
let f = d[1];
if (g.min === 0) {
i = !0, l -= o.length, f = o.concat(f);
const _ = r.min;
m.min = _, m.max = f.length - 1 + _;
}
l += f.length, c.push([m, f]), u = h.next();
}
} else {
const h = e.length, u = { min: r.min, max: h - 1 + s };
e = o.concat(e), i = !0, l += h, c.push([u, e]);
}
return i && t._runs.delete(r), t._runs.setPairs(c), t._updateCount(l), t;
}
toArray(e = Number.MAX_SAFE_INTEGER, t = !0) {
if (this.length === 0) return F.EmptyArray;
const n = t ? 0 : Number.MIN_SAFE_INTEGER, r = Math.min(this._runs.maxKey().max, e);
return Ma.bounds.min = Number.MIN_SAFE_INTEGER, Ma.bounds.max = r, Zp(this.entries(Ma), t, r, n);
}
get isIReadableList() {
return !0;
}
get length() {
return this._length;
}
getCoords() {
return this._dataCoords;
}
clear() {
this._runs.clear(), this._dataCoords = null, this._count = 0, this._length = 0;
}
get isISparseList() {
return !0;
}
get isIList() {
return !0;
}
_updateCount(e) {
if (this._count += e, this._lastRunsRead = void 0, this._lastListRead = void 0, this._count > 0) {
const t = this._runs, n = Object.freeze({ min: t.minKey().min, max: t.maxKey().max });
this._dataCoords = n, this._length = n.max + 1;
} else this._dataCoords = null, this._length = 0;
}
_update(e, t, n = null, r = void 0) {
const o = e, s = o + t - 1;
let i = 0, l = s, c = s, h = null, u = null;
Ot.min = o, Ar.min = s, (n || r) && (Ot.min -= 1, Ar.min += 1);
const d = this._runs;
let g = !1;
if (d.editRange(Ot, Ar, !0, (m, f, _) => {
const p = m.min, S = m.max;
return p < o && S + 1 >= o && (l = p, h = f), p - 1 <= s && S > s && (c = p, u = f), i -= S - p + 1, g = !0, Ae.DeleteValue;
}), n || r === void 0 || (n = new jt([r])), n) {
let m = n;
g = !0;
let f = o;
h && (h = h.slice(0, o - l), m = h.concat(m), f = l), u && (u = u.slice(s + 1 - c), m = m.concat(u)), i += m.length, d.set({ min: f, max: f + m.length - 1 }, m);
} else h && (h = h.slice(0, o - l), i += h.length, d.set({ min: l, max: l + h.length - 1 }, h)), u && (u = u.slice(s + 1 - c), i += u.length, d.set({ min: s + 1, max: s + u.length }, u));
return this._updateCount(i), g;
}
setAt(e, t) {
if (e === void 0) throw new Kt();
return this._validateBounds(e, e), this._update(e, 1, null, t);
}
setRunAt(e, t) {
if (!t || t.length === 0) return !1;
if (e === void 0 || !t.length) throw new Kt();
const n = t.length;
return this._validateBounds(e, e + n - 1), this._update(e, n, t);
}
delete(e, t) {
return t === void 0 && (t = Math.max(this.getCoords().max - e + 1, 0)), !(t <= 0) && (this._validateBounds(e, e), this._update(e, t, null));
}
shift(e, t) {
if (t === 0) return !1;
let n = e, r = e;
t < 0 && (r = e - t - 1), this._validateBounds(n, r);
const o = this._runs, s = o.maxKey();
if (t < 0 && r >= s.max && n <= o.minKey().min) return this._runs.clear(), this._dataCoords = null, this._count = 0, this._length = 0, !0;
let i = 0, l = n, c = r, h = null, u = null;
Ot.min = l, Ar.min = s.min, t < 0 && (Ot.min -= 1, Ar.min += 1);
let d = !1;
const g = [];
if (o.editRange(Ot, Ar, !0, (m, f, _) => {
const p = m.min, S = m.max;
return p < n && S + 1 >= n && (l = p, h = f), (p < n || t < 0) && p - 1 <= r && m.max > r && (c = p, u = f), t > 0 && p >= n || t < 0 && p - 1 > r ? g.push([{ min: p + t, max: S + t }, f]) : i -= S - p + 1, d = !0, Ae.DeleteValue;
}), t > 0) {
const m = h || u;
m && (h = m.slice(0, n - l), c = e + t, u = m.slice(n - l));
} else h && (h = h.slice(0, n - l)), u && (u = u.slice(r + 1 - c), c = e), h && u && l + h.length === c && (h = h.concat(u), u = null);
return h && h.length > 0 && (i += h.length, o.set({ min: l, max: l + h.length - 1 }, h)), u && (i += u.length, o.set({ min: c, max: c + u.length - 1 }, u)), g.length > 0 && o.setPairs(g), this._updateCount(i), d;
}
at(e) {
Ot.min = e;
const t = this._lastRunsRead;
if (t) {
const s = t.min;
if (s <= e && t.max >= e) return this._lastListRead.at(e - s);
}
let n, r;
const o = this._runs.getPairOrNextHigher(Ot, t0);
if (o && (n = o[0], r = o[1]), this._lastRunsRead = n, this._lastListRead = r, !(!n || e < n.min || e > n.max)) return r.at(e - n.min);
}
[Symbol.iterator]() {
return kg(this.entries());
}
clone() {
const e = new qn(this._options);
return e._runs = this._runs.clone(), e._count = this._count, e._dataCoords = this._dataCoords, e._length = this._length, e;
}
getMaxCoords() {
return this._maxCoords || null;
}
getCount() {
return this._count;
}
getRunsCount() {
return this._runs.size;
}
get [Symbol.toStringTag]() {
return "[SparseList]";
}
}
qn || (qn = {});
const Kp = (a) => typeof a != "boolean" ? (a && !a.value && (a.value = [-1, null]), a) : a === !0 ? tc : void 0, Xp = (a, e, t) => {
const n = t ?? { done: !1, value: [-1, null] }, r = n.value;
return r[0] = a, r[1] = e, n;
}, Yp = (a) => typeof a != "boolean" ? (a && !a.value && (a.value = [null, null]), a) : a === !0 ? e0 : void 0, Qp = (a, e, t) => {
const n = t ?? { done: !1, value: [null, null] }, r = n.value;
return r[0] = a, r[1] = e, n;
}, Zp = (a, e = !1, t = Number.MIN_SAFE_INTEGER, n = Number.MAX_SAFE_INTEGER) => {
const r = [];
let o = a.next(), s = Math.max(n, 0) - 1;
for (; !o.done; ) {
if (e) {
const i = o.value[0];
for (let l = s; l < i - 1; l++) r.push(void 0);
s = i;
}
r.push(o.value[1]), o = a.next();
}
if (e) for (let i = s; i < t; i++) r.push(void 0);
return r;
}, e0 = Object.seal({ done: !1, value: [{ min: Number.MIN_SAFE_INTEGER, max: Number.MAX_SAFE_INTEGER }, null] }), tc = Object.seal({ done: !1, value: [-1, null] }), Rr = { reverse: !1, bounds: { min: Number.MIN_SAFE_INTEGER, max: Number.MAX_SAFE_INTEGER }, processSkip: null, reuseResult: tc }, Ma = Object.freeze({ reverse: !1, bounds: { min: Number.MIN_SAFE_INTEGER, max: Number.MAX_SAFE_INTEGER }, processSkip: null, reuseResult: tc }), Ot = { min: 0, max: Number.MAX_SAFE_INTEGER }, Ar = { min: 0, max: Number.MAX_SAFE_INTEGER }, t0 = [null, null], Ta = { bounds: { min: 0, max: 0 }, overflowRun: !0 };
class n0 {
constructor(e = 9) {
this._maxEntries = Math.max(4, e), this._minEntries = Math.max(2, Math.ceil(0.4 * this._maxEntries)), this.clear();
}
all(e) {
return this.data.children.length === 0 ? [] : this._all(this.data, e ?? []);
}
isEmpty() {
return this.data.children.length === 0;
}
search(e, t) {
let n = this.data;
if (n.children.length === 0) return F.EmptyArray;
if (!Cs(e, n)) return F.EmptyArray;
const r = t ?? [], o = this.toBBox, s = [];
for (; n; ) {
const i = n.children, l = i.length, c = n.leaf;
for (let h = 0; h < l; h++) {
const u = i[h], d = c ? o(u) : u;
Cs(e, d) && (c ? r.push(u) : Fa(e, d) ? this._all(u, r) : s.push(u));
}
n = s.pop();
}
return r;
}
collides(e) {
let t = this.data;
if (!Cs(e, t)) return !1;
const n = [];
for (; t; ) {
for (let r = 0; r < t.children.length; r++) {
const o = t.children[r], s = t.leaf ? this.toBBox(o) : o;
if (Cs(e, s)) {
if (t.leaf || Fa(e, s)) return !0;
n.push(o);
}
}
t = n.pop();
}
return !1;
}
load(e) {
if (!e || !e.length) return this;
const t = this._minEntries;
if (e.length < t) {
for (let r = 0; r < e.length; r++) this.insert(e[r]);
return this;
}
let n = this._build(e.slice(), 0, e.length - 1, 0);
if (this.data.children.length) if (this.data.height === n.height) this._splitRoot(this.data, n);
else {
if (this.data.height < n.height) {
const r = this.data;
this.data = n, n = r;
}
this._insert(n, this.data.height - n.height - 1, !0);
}
else this.data = n;
return this;
}
insert(e) {
return e && this._insert(e, this.data.height - 1), this;
}
clear() {
return this.data = Dr([]), this;
}
remove(e, t) {
if (!e) return this;
let n = this.data;
const r = this.toBBox(e), o = [], s = [];
let i, l, c;
for (; n || o.length; ) {
if (n || (n = o.pop(), l = o[o.length - 1], i = s.pop(), c = !0), n.leaf) {
const h = r0(e, n.children, t);
if (h !== -1) return n.children.splice(h, 1), o.push(n), this._condense(o), this;
}
c || n.leaf || !Fa(n, r) ? l ? (i++, n = l.children[i], c = !1) : n = null : (o.push(n), s.push(i), i = 0, l = n, n = n.children[0]);
}
return this;
}
toBBox(e) {
return e;
}
compareMinX(e, t) {
return e.minX - t.minX;
}
compareMinY(e, t) {
return e.minY - t.minY;
}
toJSON() {
return this.data;
}
fromJSON(e) {
return this.data = e, this;
}
_all(e, t) {
const n = [];
for (; e; ) e.leaf ? t.push(...e.children) : n.push(...e.children), e = n.pop();
return t;
}
_build(e, t, n, r) {
const o = n - t + 1;
let s, i = this._maxEntries;
if (o <= i) return s = Dr(e.slice(t, n + 1)), Mr(s, this.toBBox), s;
r || (r = Math.ceil(Math.log(o) / Math.log(i)), i = Math.ceil(o / Math.pow(i, r - 1))), s = Dr([]), s.leaf = !1, s.height = r;
const l = Math.ceil(o / i), c = l * Math.ceil(Math.sqrt(i));
Dh(e, t, n, c, this.compareMinX);
for (let h = t; h <= n; h += c) {
const u = Math.min(h + c - 1, n);
Dh(e, h, u, l, this.compareMinY);
for (let d = h; d <= u; d += l) {
const g = Math.min(d + l - 1, u);
s.children.push(this._build(e, d, g, r - 1));
}
}
return Mr(s, this.toBBox), s;
}
_chooseSubtree(e, t, n, r) {
for (; r.push(t), !t.leaf && r.length - 1 !== n; ) {
let o, s = 1 / 0, i = 1 / 0;
for (let l = 0; l < t.children.length; l++) {
const c = t.children[l], h = Na(c), u = i0(e, c) - h;
u < i ? (i = u, s = h < s ? h : s, o = c) : u === i && h < s && (s = h, o = c);
}
t = o || t.children[0];
}
return t;
}
_insert(e, t, n = !1) {
const r = n ? e : this.toBBox(e), o = [], s = this._chooseSubtree(r, this.data, t, o);
for (s.children.push(e), Oo(s, r); t >= 0 && o[t].children.length > this._maxEntries; ) this._split(o, t), t--;
this._adjustParentBBoxes(r, o, t);
}
_split(e, t) {
const n = e[t], r = n.children.length, o = this._minEntries;
this._chooseSplitAxis(n, o, r);
const s = this._chooseSplitIndex(n, o, r), i = Dr(n.children.splice(s, n.children.length - s));
i.height = n.height, i.leaf = n.leaf, Mr(n, this.toBBox), Mr(i, this.toBBox), t ? e[t - 1].children.push(i) : this._splitRoot(n, i);
}
_splitRoot(e, t) {
this.data = Dr([e, t]), this.data.height = e.height + 1, this.data.leaf = !1, Mr(this.data, this.toBBox);
}
_chooseSplitIndex(e, t, n) {
let r = -1, o = 1 / 0, s = 1 / 0;
for (let i = t; i <= n - t; i++) {
const l = ko(e, 0, i, this.toBBox), c = ko(e, i, n, this.toBBox), h = a0(l, c), u = Na(l) + Na(c);
h < o ? (o = h, r = i, s = u < s ? u : s) : h === o && u < s && (s = u, r = i);
}
return r || n - t;
}
_chooseSplitAxis(e, t, n) {
const r = e.leaf ? this.compareMinX : o0, o = e.leaf ? this.compareMinY : s0;
this._allDistMargin(e, t, n, r) < this._allDistMargin(e, t, n, o) && e.children.sort(r);
}
_allDistMargin(e, t, n, r) {
e.children.sort(r);
const o = this.toBBox, s = ko(e, 0, t, o), i = ko(e, n - t, n, o);
let l = Es(s) + Es(i);
for (let c = t; c < n - t; c++) {
const h = e.children[c];
Oo(s, e.leaf ? o(h) : h), l += Es(s);
}
for (let c = n - t - 1; c >= t; c--) {
const h = e.children[c];
Oo(i, e.leaf ? o(h) : h), l += Es(i);
}
return l;
}
_adjustParentBBoxes(e, t, n) {
for (let r = n; r >= 0; r--) Oo(t[r], e);
}
_condense(e) {
for (let t, n = e.length - 1; n >= 0; n--) e[n].children.length === 0 ? n > 0 ? (t = e[n - 1].children, t.splice(t.indexOf(e[n]), 1)) : this.clear() : Mr(e[n], this.toBBox);
}
}
function r0(a, e, t) {
if (!t) return e.indexOf(a);
for (let n = 0; n < e.length; n++) if (t(a, e[n])) return n;
return -1;
}
function Mr(a, e) {
ko(a, 0, a.children.length, e, a);
}
function ko(a, e, t, n, r = null) {
r || (r = Dr(null)), r.minX = 1 / 0, r.minY = 1 / 0, r.maxX = -1 / 0, r.maxY = -1 / 0;
for (let o = e; o < t; o++) {
const s = a.children[o];
Oo(r, a.leaf ? n(s) : s);
}
return r;
}
function Oo(a, e) {
return a.minX = Math.min(a.minX, e.minX), a.minY = Math.min(a.minY, e.minY), a.maxX = Math.max(a.maxX, e.maxX), a.maxY = Math.max(a.maxY, e.maxY), a;
}
function o0(a, e) {
return a.minX - e.minX;
}
function s0(a, e) {
return a.minY - e.minY;
}
function Na(a) {
return (a.maxX - a.minX) * (a.maxY - a.minY);
}
function Es(a) {
return a.maxX - a.minX + (a.maxY - a.minY);
}
function i0(a, e) {
return (Math.max(e.maxX, a.maxX) - Math.min(e.minX, a.minX)) * (Math.max(e.maxY, a.maxY) - Math.min(e.minY, a.minY));
}
function a0(a, e) {
const t = Math.max(a.minX, e.minX), n = Math.max(a.minY, e.minY), r = Math.min(a.maxX, e.maxX), o = Math.min(a.maxY, e.maxY);
return Math.max(0, r - t) * Math.max(0, o - n);
}
function Fa(a, e) {
return a.minX <= e.minX && a.minY <= e.minY && e.maxX <= a.maxX && e.maxY <= a.maxY;
}
function Cs(a, e) {
return e.minX <= a.maxX && e.minY <= a.maxY && e.maxX >= a.minX && e.maxY >= a.minY;
}
function Dr(a) {
return { children: a, height: 1, leaf: !0, minX: 1 / 0, minY: 1 / 0, maxX: -1 / 0, maxY: -1 / 0 };
}
function Dh(a, e, t, n, r) {
const o = [e, t];
for (; o.length; ) {
if ((t = o.pop()) - (e = o.pop()) <= n) continue;
const s = e + Math.ceil((t - e) / n / 2) * n;
Og(a, s, e, t, r), o.push(e, s, s, t);
}
}
function Og(a, e, t, n, r) {
for (; n > t; ) {
if (n - t > 600) {
const l = n - t + 1, c = e - t + 1, h = Math.log(l), u = 0.5 * Math.exp(2 * h / 3), d = 0.5 * Math.sqrt(h * u * (l - u) / l) * (c - l / 2 < 0 ? -1 : 1);
Og(a, e, Math.max(t, Math.floor(e - c * u / l + d)), Math.min(n, Math.floor(e + (l - c) * u / l + d)), r);
}
const o = a[e];
let s = t, i = n;
for (go(a, t, e), r(a[n], o) > 0 && go(a, t, n); s < i; ) {
for (go(a, s, i), s++, i--; r(a[s], o) < 0; ) s++;
for (; r(a[i], o) > 0; ) i--;
}
r(a[t], o) === 0 ? go(a, t, i) : (i++, go(a, i, n)), i <= e && (t = i + 1), e <= i && (n = i - 1);
}
}
function go(a, e, t) {
const n = a[e];
a[e] = a[t], a[t] = n;
}
class Lh extends n0 {
toBBox(e) {
return { minX: 10 * e.colStart, minY: 10 * e.rowStart, maxX: 10 * e.colEnd + 5, maxY: 10 * e.rowEnd + 5 };
}
compareMinX(e, t) {
return e.colStart - t.colStart;
}
compareMinY(e, t) {
return e.rowStart - t.rowStart;
}
isEmpty() {
return this.data.children.length === 0;
}
searchRange(e, t = !1, n) {
if (this.isEmpty()) return F.EmptyArray;
const r = this.search(this.toBBox(e), n);
return t ? r.filter((o) => o.colStart >= e.colStart && o.rowStart >= e.rowStart && o.colEnd <= e.colEnd && o.rowEnd <= e.rowEnd) : r;
}
}
class Ne {
constructor(e) {
this._shared = null, this._rTree = null, this._cloneKey = null, this._lastMiss = { colStart: Number.MAX_SAFE_INTEGER, rowStart: 0, colEnd: 0, rowEnd: 0 }, this._lastSingle = null, this._lastSingleResult = null, this._options = e, this._rTree = new Lh(e?.maxNodeEntries ?? 16);
}
visitRanges(e, t, n = null) {
let r = this.search(e);
n && (r = zn(r, n));
const o = [], s = [];
let i = null;
const l = r.length;
for (let c = 0; !i && c < l; c++) {
const h = r[c], u = t?.(h);
u && (u.delete === !0 ? s.push(h) : u.update !== void 0 && (s.push(h), o.push(u.update)), u && u.break === !0 && (i = u));
}
for (let c = 0; c < s.length; c++) this.remove(s[c]);
return this.load(o), i;
}
getBoundingCoords() {
const e = this._getReadTree().toJSON();
return e && e.children && e.children.length !== 0 ? { colStart: e.minX / 10, rowStart: e.minY / 10, colEnd: (e.maxX - 5) / 10, rowEnd: (e.maxY - 5) / 10 } : null;
}
size() {
return this._getReadTree().all().length;
}
isEmpty() {
return this._getReadTree().isEmpty();
}
search(e, t = !1, n) {
const r = this._getReadTree();
if (r.isEmpty()) return F.EmptyArray;
let o;
if (!t) {
if (o = this._lastMiss, o.colStart !== Number.MAX_SAFE_INTEGER && D.isRangeWithinRange(e, o)) return F.EmptyArray;
if (this._lastSingle && D.isRangeWithinRange(e, o)) return this._lastSingleResult;
}
const s = r.searchRange(e, t, n);
return t || (s.length === 0 ? (o.colStart = e.colStart, o.rowStart = e.rowStart, o.colEnd = e.colEnd, o.rowEnd = e.rowEnd) : s.length === 1 ? (this._lastSingle = s[0], this._lastSingleResult = s) : (this._lastMiss.colStart = Number.MAX_SAFE_INTEGER, this._lastSingle = null, this._lastSingleResult = null)), s;
}
has(e) {
const t = this._getReadTree();
return t.collides(t.toBBox(e));
}
all(e) {
return this._getReadTree().all(e);
}
shift(e) {
const t = e.range, n = e.direction, r = e.cloneIfUpdate ?? !1, o = e.coordValidator ?? null, s = e.onShift ?? null, i = n === He.Left || n === He.Right, l = i ? xe.Column : xe.Row, c = n === He.Up || n === He.Left ? -1 : 1, h = (i ? t.colEnd - t.colStart + 1 : t.rowEnd - t.rowStart + 1) * c, u = [], d = [];
let g = null;
const m = this.getBoundingCoords();
if (!m) return this;
const f = n === He.Up || n === He.Left ? He.Right : He.Left, _ = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), S = this._options?.updateEntryOptions, E = S?.isMergeOnShift ?? !1, y = S?.isSplitOnExpand ?? !1, C = S?.isTrailingEdge ?? !1, w = n === He.Left || n === He.Up, b = S?.getSplit ?? ti, x = S?.getShifted, I = S?.onShifted, v = S?.onRemoved, R = S?.onMerged, A = S?.onUpdated, M = I ? [] : null, T = v ? [] : null, k = A ? [] : null;
this.visitRanges({ colStart: t.colStart - (i ? 1 : 0), rowStart: t.rowStart - (i ? 0 : 1), colEnd: i ? m.colEnd : t.colEnd, rowEnd: i ? t.rowEnd : m.rowEnd }, (H) => {
if ((i ? H.colEnd < t.colStart : H.rowEnd < t.rowStart) && !C) return;
const z = u0(t, H, i ? Br.Column : Br.Row), W = H.group;
if (w && !W && t.colStart <= H.colStart && t.rowStart <= H.rowStart && t.colEnd >= H.colEnd && t.rowEnd >= H.rowEnd) {
const $ = Ph(H, null, { after: null, before: H, intersect: t, isSplit: z, orientation: l, amount: h }, x, b, s, !1);
if ($ === void 0) return;
if ($ === null) return g = D.unionRanges(g, H), T && T.push(H), void u.push(H);
}
let L = { ...H };
n === He.Right ? (t.colStart <= L.colStart && (L.colStart += h), L.colEnd += h) : n === He.Left ? t.colStart < L.colStart ? (L.colStart = Math.max(L.colStart + h, t.colStart), L.colEnd = Math.max(L.colEnd + h, L.colStart - 1)) : L.colEnd += Math.max(h, t.colStart - L.colEnd - 1) : n === He.Down ? (t.rowStart <= L.rowStart && (L.rowStart += h), L.rowEnd += h) : n === He.Up && (t.rowStart < L.rowStart ? (L.rowStart = Math.max(L.rowStart + h, t.rowStart), L.rowEnd = Math.max(L.rowEnd + h, t.rowStart - 1)) : L.rowEnd += Math.max(h, t.rowStart - L.rowEnd - 1)), (L.colEnd < L.colStart || L.rowEnd < L.rowStart) && (L = null);
const j = Ph(H, L, { after: L, before: H, intersect: t, isSplit: z, orientation: l, amount: h }, x, b, s, y && h > 0);
if (j === void 0) return;
const G = j === null ? [L] : j, V = G.length;
if (G[0] !== H || V !== 1) {
if (o) for (let J = 0; J < V; J++) {
const K = G[J];
K && o(K);
}
let $;
W ? (_.set(W.uuid, W), $ = [], p.set(H.uuid, $)) : u.push(H);
for (let J = 0; J < V; J++) {
const K = G[J];
g = D.unionRanges(g, K), W ? $.push(K) : (d.push(K), M && M.push(K), k && k.push(H));
}
}
}, f);
let P = null;
P = r && (u.length > 0 || d.length > 0 || p.size > 0) ? this.clone() : this, P._updateNodes(d, u), p.size > 0 && P._updateGroupedEntries(_, p);
let B = F.EmptyArray;
if (E && m && g) {
let H = !0;
if (h > 0 && (H = i ? t.rowStart > m.rowStart || t.rowEnd < m.rowEnd : t.colStart > m.colStart || t.colEnd < m.colEnd), H) {
const z = Bh(g, D.unionRanges(m, g), i ? 0 : 1, i ? 1 : 0);
R && (B = P._mergeNodes(z, !1));
}
}
return A && k.length > 0 && A(k), I && M.length > 0 && I(M), R && B.length > 0 && R(B), v && T.length > 0 && v(T), P;
}
insertNonOverlapping(e, t) {
const n = t?.onIntersect ?? ((E, y) => ({ ...E, value: y.value })), r = this.search(e), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), i = this._options?.updateEntryOptions, l = i?.onUpdated, c = i?.onRemoved, h = i?.onMerged, u = i?.getSplit, d = i?.getIntersect, g = i?.getUpdate;
let m = null, f = null, _ = null, p = function(E, y, C) {
const w = C?.getIntersect ?? c0, b = C?.getUpdate ?? h0;
if (E.length === 0) {
if (w) {
const z = w({ ...y, value: null }, y);
y = z && z.value !== null ? { ...z } : null;
}
if (b) {
const z = b(y);
z !== void 0 && (y = z);
}
return y ? [y] : F.EmptyArray;
}
const x = C?.getSplit ?? l0, I = (z, W, L = !0) => {
const j = W.search(z), G = j.length;
for (let V = 0; V < G; V++) {
const $ = j[V];
if (D.isEqualRanges($, z)) continue;
W?.remove($);
const J = Zr($, z, x, L);
for (let K = 0; K < J.length; K++) {
const he = J[K];
W.insert(he), I(he, W, !1);
}
}
}, v = new Ne();
v.load(E), I(y, v);
const R = new Ne();
R.load([y]);
const A = v.search(y);
for (let z = 0; z < A.length; z++) I(A[z], R);
const M = (z, W, L) => {
let j = W.search(z);
console.assert(j.length <= 1, "intersecting incorrect ranges");
const G = j[0] ?? { ...z, value: null };
if (D.isEqualRanges(G, z)) {
let V = w(G, z);
W.remove(G), L.insert(V);
} else {
W.remove(G);
const V = Zr(G, z, x), $ = V.length;
for (let J = 0; J < $; J++) {
const K = V[J];
if (D.isEqualRanges(K, z)) {
const he = w(K, z);
L.insert(he);
} else W.insert(K);
}
}
}, T = new Ne(), k = R.all(), P = k.length;
for (let z = 0; z < P; z++) M(k[z], v, T);
const B = (z, W) => {
const L = z.all(), j = L.length;
for (let G = 0; G < j; G++) {
let V = L[G];
if (b) {
const $ = b(V);
$ !== void 0 && (V = $);
}
V !== null && V.value !== null && W.push(V);
}
}, H = v.all();
return B(T, H), H;
}(r, e, { getSplit: (E, y, C, w) => {
let b;
return u ? (b = u(E, y, C, w), b) : (b = ti(E, y, C, w), b);
}, getIntersect: (E, y) => {
d && (y = d(E, y));
const C = n(E, y);
return C === void 0 || (C === null || C.value === null) && E.value?.onRemove?.(E), C;
}, getUpdate: (E) => {
const y = E?.group;
if (y) {
o.set(y.uuid, y);
let w = s.get(E.lastId ?? E.uuid);
w || (w = [], s.set(E.lastId ?? E.uuid, w)), w.push(E.value === null ? null : E);
}
let C = E;
if (g && (C = g(E)), C && C.value !== null) l && (m || (m = []), m.push(C));
else if (c && !_) {
_ = [];
let w = C && C.value === null ? C : { ...E, value: null };
_.push(w);
}
return C;
} });
const S = this.getBoundingCoords();
if (o.size > 0) {
const E = [], y = p.length;
for (let C = 0; C < y; C++) {
let w = p[C];
w.group || E.push(w);
}
p = E;
}
if (this._updateNodes(p, r, t?.onUpdates), o.size > 0 && this._updateGroupedEntries(o, s), S && !t?.noMerge) {
const E = Bh(e, D.unionRanges(S, e)), y = this.search(E);
if (y.length > 1) {
const C = i?.getMerged ?? zh;
let w = y;
w = yn(w, xe.Column, 1, C), w = yn(w, xe.Row, 1, C), y.length !== w.length && (h && w.length > 0 && (f = w), this._updateNodes(w, y, t?.onUpdates));
}
}
return m && l(m), f && h(f), _ && c(_), this;
}
insertGroup(e, t) {
t = t ?? F.uuidV4();
const n = [], r = e.length;
for (let o = 0; o < r; o++) {
const s = { ...e[o], group: { entries: n, uuid: t, offset: o }, uuid: F.uuidV4() };
n.push(s), e[o] = s;
}
return this.load(e), this._options?.updateEntryOptions?.onGroupUpdate?.(e, t), this;
}
createCopiedEntries(e, t, n, r, o) {
return d0(this, e, t, n, r, o, this._options?.updateEntryOptions?.getSplit ?? ti);
}
_updateGroupedEntries(e, t) {
const n = [], r = [], o = /* @__PURE__ */ new Map(), s = e.values();
let i = s.next();
for (; !i.done; ) {
const l = i.value, c = l.entries, h = l.uuid, u = [];
for (let d = 0; d < c.length; d++) {
let g = c[d];
n.push(g);
let m = t.get(g.uuid);
m === void 0 && (m = [{ ...g }]);
for (let f = 0; f < m.length; f++) {
let _ = m[f];
_ !== null && (_ = { ..._, group: { offset: u.length, entries: u, uuid: h } }, u.push(_), r.push(_));
}
}
u.sort((d, g) => d.group.offset - g.group.offset), o.set(h, u), i = s.next();
}
if (this._updateNodes(r, n), o) {
const l = this._options?.updateEntryOptions?.onGroupUpdate;
if (l) {
const c = o.entries();
let h = c.next();
for (; !h.done; ) {
const u = h.value[0];
l(h.value[1], u), h = c.next();
}
}
}
}
_copy(e, t) {
let n = e.rTree.all();
const r = new Lh(this._options?.maxNodeEntries);
return t && (n = n.concat(t)), n.length > 0 && r.load(n), { refCount: 1, rTree: r };
}
_updateNodes(e, t, n) {
if (!(e && e.length !== 0 || t && t.length !== 0)) return;
const r = this._getWritableTree();
if (t) {
const o = t.length;
for (let s = 0; s < o; s++) r.remove(t[s]);
}
e.length > 0 && r.load(e), n?.(e, t, this), this._options?.updateEntryOptions?.onUpdates?.(e, t, this);
}
_mergeNodes(e, t) {
const n = this.search(e, t);
let r = F.EmptyArray;
if (n.length > 1) {
const o = this._options?.updateEntryOptions.getMerged ?? zh;
let s = n;
s.length > 1 && (s = yn(s, xe.Column, 1, o)), s.length > 1 && (s = yn(s, xe.Row, 1, o)), n.length !== s.length && (r = s, this._updateNodes(s, n));
}
return r;
}
_getReadTree() {
return this._shared?.rTree ?? this._rTree;
}
_ensureWritable(e) {
const t = this._shared;
if (!t) return;
if (t.refCount--, t.refCount === 0) return this._shared = null, void (e && this._rTree.load(e));
const n = this._copy(t, e);
this._shared = null, this._rTree = n.rTree;
}
_getWritableTree(e) {
return this._lastMiss.colStart = Number.MAX_SAFE_INTEGER, this._lastSingle = null, this._lastSingleResult = null, this._shared ? (this._ensureWritable(e), this._rTree) : (e && this._rTree.load(e), this._rTree);
}
remove(e, t) {
return e && this._getWritableTree().remove(e, t ?? D.isEqualRanges), this;
}
insert(e) {
return e && this._getWritableTree().insert(e), this;
}
load(e) {
return e && e.length > 0 && this._getWritableTree(e), this;
}
clear() {
return this.isEmpty() || this._getWritableTree().clear(), this;
}
clone(e = null) {
if (e !== null && this._cloneKey === e) return this;
let t = this._shared;
t || (t = { rTree: this._rTree, refCount: 1 }, this._shared = t), t.refCount++;
const n = new Ne(this._options);
return n._shared = t, n._cloneKey = e, n;
}
fromJSON(e) {
return this._getWritableTree().fromJSON(e), this;
}
}
const Bh = (a, e = a, t = 1, n = 1) => ({ ...a, colStart: Math.max(a.colStart - t, e.colStart), rowStart: Math.max(a.rowStart - n, e.rowStart), colEnd: Math.min(a.colEnd + t, e.colEnd), rowEnd: Math.min(a.rowEnd + n, e.rowEnd) });
function l0(a, e, t, n) {
return [{ ...e[0], value: a.value }, { ...e[0], value: a.value }];
}
function c0(a, e) {
return { ...a };
}
function Zr(a, e, t = null, n = !0) {
if (D.isEqualRanges(a, e)) return [{ ...a }];
const r = D.intersectRanges(a, e, g0);
if (!r) return null;
const o = [], s = a.uuid;
let i = a;
if (i.rowStart < r.rowStart) {
const l = { ...i, colStart: i.colStart, rowStart: i.rowStart, colEnd: i.colEnd, rowEnd: r.rowStart - 1 };
s && (n && (l.lastId = s), l.uuid = F.uuidV4());
const c = { ...i, colStart: i.colStart, rowStart: r.rowStart, colEnd: i.colEnd, rowEnd: i.rowEnd };
s && (n && (c.lastId = s), c.uuid = F.uuidV4());
const h = c.rowStart - l.rowStart;
Dt[0] = l, Dt[1] = c;
const u = t(i, Dt, xe.Row, h);
u !== void 0 && (o.push(u[0]), i = u[1]);
}
if (i.rowEnd > r.rowEnd) {
const l = { ...i, colStart: i.colStart, rowStart: i.rowStart, colEnd: i.colEnd, rowEnd: r.rowEnd };
s && (n && (l.lastId = s), l.uuid = F.uuidV4());
const c = { ...i, colStart: i.colStart, rowStart: r.rowEnd + 1, colEnd: i.colEnd, rowEnd: i.rowEnd };
s && (n && (c.lastId = s), c.uuid = F.uuidV4());
const h = c.rowStart - l.rowStart;
Dt[0] = l, Dt[1] = c;
const u = t(i, Dt, xe.Row, h);
u !== void 0 && (o.push(u[1]), i = u[0]);
}
if (i.colStart < r.colStart) {
const l = { ...i, colStart: i.colStart, rowStart: i.rowStart, colEnd: r.colStart - 1, rowEnd: i.rowEnd };
s && (n && (l.lastId = s), l.uuid = F.uuidV4());
const c = { ...i, colStart: r.colStart, rowStart: i.rowStart, colEnd: i.colEnd, rowEnd: i.rowEnd };
s && (n && (c.lastId = s), c.uuid = F.uuidV4());
const h = c.colStart - l.colStart;
Dt[0] = l, Dt[1] = c;
const u = t(i, Dt, xe.Column, h);
u !== void 0 && (o.push(u[0]), i = u[1]);
}
if (i.colEnd > r.colEnd) {
const l = { ...i, colStart: i.colStart, rowStart: i.rowStart, colEnd: r.colEnd, rowEnd: i.rowEnd };
s && (n && (l.lastId = s), l.uuid = F.uuidV4());
const c = { ...i, colStart: r.colEnd + 1, rowStart: i.rowStart, colEnd: i.colEnd, rowEnd: i.rowEnd };
s && (n && (c.lastId = s), c.uuid = F.uuidV4());
const h = c.colStart - l.colStart;
Dt[0] = l, Dt[1] = c;
const u = t(i, Dt, xe.Column, h);
u !== void 0 && (o.push(u[1]), i = u[0]);
}
return i === a && (i = { ...a }), o.push(i), o;
}
function h0(a) {
return a.value === null ? null : a;
}
function yn(a, e = xe.Column, t = 2, n, r) {
let o = [...a];
if (t <= 0 || a.length <= 1) return o;
let s = e === xe.Column, i = 0, l = !1;
do {
const c = o.sort(D.createRangeComparator(s ? xe.Row : xe.Column));
o = [], l = !1, o.push(c[0]);
for (let h = 1; h < c.length; h++) {
const u = c[h], d = o[o.length - 1];
let g = !1;
if (g = s ? d && d.rowStart === u.rowStart && d.rowEnd === u.rowEnd && d.colEnd + 1 === u.colStart : d && d.colStart === u.colStart && d.colEnd === u.colEnd && d.rowEnd + 1 === u.rowStart, g) {
let m = { ...d, colEnd: s ? u.colEnd : d.colEnd, rowEnd: s ? d.rowEnd : u.rowEnd };
if (n) {
const f = r ?? [null, null];
f[0] = d, f[1] = u, m = n(f, m, e);
}
if (m) {
o[o.length - 1] = m, l = !0;
continue;
}
}
o.push(u);
}
i++, s = !s;
} while (i < t && l && o.length > 1);
return o;
}
const Ml = (a, e = 2, t = xe.Row, n, r, o) => {
if (a.length <= 1) return [...a];
let s = [];
const i = t === xe.Column, l = new xi.IteratorInstance(a, { orientation: i ? xe.Row : xe.Column });
let c = l.next();
for (; !c.done; ) {
const h = c.value;
c = l.next();
const u = h.range;
if (e > 0) {
const d = s[s.length - 1];
let g = !1;
if (g = i ? d && d.rowStart === u.rowStart && d.rowEnd === u.rowEnd && d.colEnd + 1 === u.colStart : d && d.colStart === u.colStart && d.colEnd === u.colEnd && d.rowEnd + 1 === u.rowStart, g) {
let m = { ...d, colEnd: i ? u.colEnd : d.colEnd, rowEnd: i ? d.rowEnd : u.rowEnd };
if (m) {
s[s.length - 1] = m;
continue;
}
}
}
s.push(u);
}
return e > 1 && (s = yn(s, i ? xe.Row : xe.Column, e, n, o)), s;
};
function ti(a, e, t, n) {
const r = a.value;
if (r?.getSplit) {
const o = r.getSplit(e, t, n);
if (o === void 0) return;
e[0].value = o[0], e[1].value = o[1];
}
return e;
}
function zh(a, e, t) {
const n = a[0].value, r = a[1].value;
if (n?.getMerged && r) {
const o = n.getMerged(a[1].value, D.sanitizeRange(e), t);
if (o === void 0) return;
e.value = o;
}
return e;
}
const u0 = (a, e, t = Br.Both) => {
const n = (s) => s ? a.rowStart > e.rowStart && a.rowStart <= e.rowEnd || a.rowEnd < e.rowEnd && a.rowEnd >= e.rowStart : a.colStart > e.colStart && a.colStart <= e.colEnd || a.colEnd < e.colEnd && a.colEnd >= e.colStart;
let r = t === Br.Column, o = t === Br.Row;
return t === Br.Both && (r = o = !0), !(!r || !n(!0)) || !(!o || !n(!1));
};
function Ph(a, e, t, n, r, o, s) {
const i = t.orientation === xe.Column, l = t.intersect, c = (h, u) => {
let d = h.value, g = null, m = u.after;
if (s) {
let f = null, _ = 0, p = 0;
if (i && l.colStart > h.colStart ? (f = { ...h, colEnd: l.colStart - 1 }, p = u.amount) : !i && l.rowStart > h.rowStart && (f = { ...h, rowEnd: l.rowStart - 1 }, _ = u.amount), f) {
const S = Zr(a, f, r);
if (S.length > 1) for (let E = 0; E < S.length; E++) {
let y = S[E];
D.isEqualRanges(y, f) ? (g = g ?? [], g.push(y)) : (m = y, d = y.value, u = { ...u, after: { ...y, colStart: y.colStart + p, rowStart: y.rowStart + _, colEnd: y.colEnd + p, rowEnd: y.rowEnd + _, uuid: F.uuidV4() }, before: y, intersect: f, isSplit: !0 });
}
}
}
if (n ? m = n(u.before, u.after, u) : d && d.getShifted ? m = d.getShifted(u) : u.after && (m = { ...u.after, value: h.value }), m !== void 0) return o && (m !== u.after && (u = { ...u, after: m }), o(u)), m = ((f) => {
if (!f) {
const _ = a.value;
return _.onRemove && _.onRemove(D.sanitizeRange(t.before)), null;
}
return f;
})(m), m && (g = g ?? [], g.push(m)), g;
};
if (t.isSplit) {
let h;
h = i ? { ...a, rowStart: Math.max(l.rowStart, t.before.rowStart), rowEnd: Math.min(l.rowEnd, t.before.rowEnd) } : { ...a, colStart: Math.max(l.colStart, t.before.colStart), colEnd: Math.min(l.colEnd, t.before.colEnd) };
const u = Zr(a, h, r), d = [];
for (let g = 0; g < u.length; g++) {
const m = u[g];
if (D.isEqualRanges(m, h)) {
let f = null;
e && (f = i ? { colStart: e.colStart, rowStart: h.rowStart, colEnd: e.colEnd, rowEnd: h.rowEnd, value: m.value } : { colStart: h.colStart, rowStart: e.rowStart, colEnd: h.colEnd, rowEnd: e.rowEnd, value: m.value });
const _ = c(m, { ...t, before: m, after: f });
if (_) for (let p = 0; p < _.length; p++) d.push(_[p]);
} else d.push(m);
}
return d;
}
return c(a, t);
}
const d0 = (a, e, t, n, r, o, s) => {
const i = t.colEnd - t.colStart + 1, l = t.rowEnd - t.rowStart + 1, c = t.colStart - e.colStart, h = t.rowStart - e.rowStart, u = n?.transpose ?? !1;
let d = 1, g = 1;
u ? (d = e.rowEnd - e.rowStart + 1, g = e.colEnd - e.colStart + 1) : (d = e.colEnd - e.colStart + 1, g = e.rowEnd - e.rowStart + 1);
const m = Math.ceil(i / d), f = Math.ceil(l / g), _ = r ?? [], p = o ?? F.EmptyArray, S = t.colEnd, E = t.rowEnd;
return a.visitRanges(e, (y) => {
let C = y.value;
if (!C.copyTo) return;
let w = y;
if (!D.isRangeWithinRange(w, e)) {
const k = Zr(w, e, s);
w = k[k.length - 1];
}
C = w.value;
let b = w.colEnd - w.colStart + 1, x = w.rowEnd - w.rowStart + 1, I = c + w.colStart, v = h + w.rowStart;
if (u) {
I = w.rowStart - e.rowStart + t.colStart, v = w.colStart - e.colStart + t.rowStart;
const k = b;
b = x, x = k;
}
let R = m, A = f;
const M = i <= R * b, T = l <= A * x;
if (M || T) {
const k = C?.canTile?.({ colStart: I, rowStart: v, colEnd: Math.min(I + (M ? i : b) - 1, S), rowEnd: Math.min(v + (T ? l : x) - 1, E) }, n);
!M || k !== !0 && k !== xe.Column || (b = i, R = 1), !T || k !== !0 && k !== xe.Row || (x = l, A = 1);
}
for (let k = 0; k < R; k++) {
const P = I + k * d;
for (let B = 0; B < A; B++) {
const H = v + B * g, z = Math.min(P + b - 1, S), W = Math.min(H + x - 1, E), L = { colStart: P, rowStart: H, colEnd: z, rowEnd: W };
if (P > z || H > W) continue;
const j = C.copyTo(L, n);
j && _.push({ ...L, value: j });
}
}
}, He.Right), { inserts: _, removes: p };
}, Dt = [null, null], g0 = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0 }, Tt = (a = Number.MIN_SAFE_INTEGER, e = Number.MIN_SAFE_INTEGER, t = Number.MAX_SAFE_INTEGER, n = Number.MAX_SAFE_INTEGER, r, o, s) => {
if (o && (a !== Number.MIN_SAFE_INTEGER && a < o.colStart || e !== Number.MIN_SAFE_INTEGER && e < o.rowStart || t !== Number.MAX_SAFE_INTEGER && t > o.colEnd || n !== Number.MAX_SAFE_INTEGER && n > o.rowEnd)) throw new ze();
return s && (a = Math.max(s.colStart, a), e = Math.max(s.rowStart, e), t = Math.min(s.colEnd, t), n = Math.min(s.rowEnd, n), t < a || n < e) ? null : (mo.majorStart = r ? a : e, mo.majorEnd = r ? t : n, mo.minorStart = r ? e : a, mo.minorEnd = r ? n : t, mo);
}, Jo = (a, e, t) => {
const n = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0 };
return n.colStart = e ? a.majorStart : a.minorStart, n.rowStart = e ? a.minorStart : a.majorStart, n.colEnd = e ? a.majorEnd : a.minorEnd, n.rowEnd = e ? a.minorEnd : a.majorEnd, n;
}, mo = { majorStart: 0, majorEnd: 0, minorStart: 0, minorEnd: 0 }, Hh = (a, e) => a[0] - e[0];
class Dg {
constructor(e, t) {
this._isColumn = !0, this._isReverse = !1, this._skipMajors = !1, this._majorMin = Number.MAX_SAFE_INTEGER, this._majorMax = Number.MIN_SAFE_INTEGER, this._minorMin = Number.MAX_SAFE_INTEGER, this._minorMax = Number.MIN_SAFE_INTEGER, this._majorIndex = Number.MIN_SAFE_INTEGER, this._minorIndex = Number.MIN_SAFE_INTEGER, this._delegateMajorIndex = Number.MIN_SAFE_INTEGER, this._delegateMinorIndex = Number.MIN_SAFE_INTEGER, this._delegate = e;
const n = (t.orientation ?? xe.Column) === xe.Column;
this._isColumn = n, this._isReverse = t.reverse ?? !1, this._skipMajors = t.skipMajors ?? !1;
const r = t.bounds, o = r.colStart, s = r.rowStart, i = r.colEnd, l = r.rowEnd;
this._majorMin = n ? o : s, this._majorMax = n ? i : l, this._minorMin = n ? s : o, this._minorMax = n ? l : i, this._processMajorSkip = n ? t.processColumnSkip : t.processRowSkip, this._processMinorSkip = n ? t.processRowSkip : t.processColumnSkip;
const c = e.next();
this._delegateResult = c, this._initialize();
}
_initialize() {
const e = this._isColumn, t = this._isReverse, n = t ? -1 : 1;
let r = t ? this._majorMax : this._majorMin, o = (t ? this._minorMax : this._minorMin) - n;
const s = this._processMinorSkip;
s && (o = s(o, t));
const i = this._processMajorSkip;
i && (r = i(r, t)), this._majorIndex = r, this._minorIndex = o;
const l = this._delegateResult;
if (l.done) this._delegateMajorIndex = this._majorMax, this._delegateMinorIndex = this._minorMax + n;
else {
const c = l.value[0];
this._delegateMajorIndex = e ? c.colIndex : c.rowIndex, this._delegateMinorIndex = e ? c.rowIndex : c.colIndex;
}
}
next(e) {
e !== void 0 && (this._delegateResult = this._delegate.next(e), this._initialize());
const t = this._isReverse, n = this._isColumn, r = this._majorMin, o = this._majorMax;
let s = this._majorIndex, i = this._minorIndex;
if (s > o || s < r) return ke;
let l = this._delegateMajorIndex, c = this._delegateMinorIndex, h = this._delegateResult.done;
if (s === l && i === c) {
const g = this._delegate.next();
if (this._delegateResult = g, h = g.done, h) l = t ? r : o, l = t ? this._minorMin : this._minorMax;
else {
const m = g.value[0];
l = n ? m.colIndex : m.rowIndex, c = n ? m.rowIndex : m.colIndex;
}
this._delegateMajorIndex = l, this._delegateMinorIndex = c;
}
const u = t ? -1 : 1;
if (this._minorIndex = i += u, s === l && i === c && !h) return this._delegateResult;
const d = this._processMinorSkip;
if (d && (i = d(i, t)), i > this._minorMax || i < this._minorMin) {
s += u;
const g = this._processMajorSkip;
g && (s = g(s, t)), this._skipMajors && (!t && s < l || t && s > l) && (s = l), this._majorIndex = s, i = t ? this._minorMax : this._minorMin;
}
return this._minorIndex = i, s === l && i === c && !h ? this._delegateResult : s > o || s < r ? ke : { done: !1, value: [{ colIndex: n ? s : i, rowIndex: n ? i : s }] };
}
return(e) {
return null;
}
throw(e) {
return null;
}
[Symbol.iterator]() {
return this;
}
}
class Tl {
constructor(e) {
this._isColumn = !0, this._majorSize = Number.MAX_SAFE_INTEGER, this._minorSize = Number.MAX_SAFE_INTEGER, this._majorMin = Number.MAX_SAFE_INTEGER, this._majorMax = Number.MIN_SAFE_INTEGER, this._minorMin = Number.MAX_SAFE_INTEGER, this._minorMax = Number.MIN_SAFE_INTEGER, this._majorIndex = Number.MAX_SAFE_INTEGER, this._minorIndex = Number.MAX_SAFE_INTEGER, this._minorOffset = 0, this._minorRepeat = 0, this._majorOffset = -1, this._majorRepeat = 1, this._pattern = [];
const t = e.delegate;
this._delegate = t;
const n = (e.orientation ?? xe.Column) === xe.Column;
this._isColumn = n;
const r = e.dims, o = e.bounds, s = o.colStart, i = o.rowStart, l = o.colEnd, c = o.rowEnd;
if (this._majorSize = 1 + (n ? l - s : c - i), this._minorSize = 1 + (n ? c - i : l - s), this._majorMin = n ? s : i, this._minorMin = n ? i : s, this._majorMax = (n ? s + r.major : i + r.major) - 1, this._minorMax = (n ? i + r.minor : s + r.minor) - 1, this._majorSize > this._majorMax + 1 || this._minorSize > this._minorMax + 1) throw new Error("The dimensions must be larger than the bounds.");
const h = t.next();
this._nextDelegateResult = h, this._initialize();
}
_initialize() {
const e = this._isColumn, t = this._nextDelegateResult;
if (t.done) this._nextResult = ke;
else {
const n = t.value[0], r = e ? n.colIndex : n.rowIndex, o = e ? n.rowIndex : n.colIndex, s = [[o, t.value[1]]];
this._minorSpan = s, this._majorIndex = r, this._minorIndex = o, this._pattern.push([r, s]), this._nextResult = t;
}
}
next(e) {
if (e !== void 0) throw new kd();
const t = this._nextResult, n = this._isColumn;
let r = this._majorIndex, o = this._nextDelegateResult;
if (!o.done) {
const c = o.value[0];
if ((n ? c.colIndex : c.rowIndex) === r && (o = this._delegate.next(), this._nextDelegateResult = o, !o.done)) {
const h = o.value, u = h[0], d = n ? u.colIndex : u.rowIndex, g = n ? u.rowIndex : u.colIndex;
if (d === r) return this._minorSpan.push([g, h[1]]), this._minorOffset = this._minorSpan.length - 1, this._minorIndex = g, this._nextResult = o, t;
}
}
const s = this._minorMax;
let i = this._minorIndex;
if (i < s) {
let c = this._minorOffset;
c++;
const h = this._minorSpan;
c >= h.length && (c = 0, this._minorRepeat++);
const u = h[c], d = this._minorMin;
if (i = d + (u[0] - d + this._minorSize * this._minorRepeat), this._minorIndex = i, this._minorOffset = c, i <= s) {
const g = [{ colIndex: n ? r : i, rowIndex: n ? i : r }, u[1]];
return this._nextResult = { done: !1, value: g }, t;
}
}
if (!o.done) {
const c = o.value, h = c[0], u = n ? h.colIndex : h.rowIndex, d = n ? h.rowIndex : h.colIndex, g = [[d, c[1]]];
return this._pattern.push([u, g]), this._majorIndex = u, this._minorSpan = g, this._minorOffset = 0, this._minorIndex = d, this._minorRepeat = 0, this._nextResult = o, t;
}
const l = this._majorMax;
if (r < l) {
let c = this._majorOffset;
c++;
const h = this._pattern;
c >= h.length && (c = 0, this._majorRepeat++);
const u = h[c], d = u[1], g = d[0], m = this._majorMin;
if (r = m + (u[0] - m + this._majorSize * this._majorRepeat), this._majorIndex = r, this._majorOffset = c, r <= l) {
this._minorSpan = d, this._minorOffset = 0, i = g[0], this._minorIndex = i, this._minorRepeat = 0;
const f = [{ colIndex: n ? r : i, rowIndex: n ? i : r }, g[1]];
return this._nextResult = { done: !1, value: f }, t;
}
}
return t.done || (this._nextResult = ke), t;
}
return(e) {
return null;
}
throw(e) {
return null;
}
[Symbol.iterator]() {
return this;
}
}
class Wh {
constructor(e, t, n) {
this._comparator = e?.comparator ?? D.createCellComparator(e.orientation ?? xe.Column, e.reverse ?? !1), this._iterator1 = t, this._iterator2 = n;
const r = t.next();
this._nextResult1 = r;
const o = n.next();
this._nextResult2 = o, e?.reuseResult && (e.reuseResult === !0 ? this._reuseResult = { done: !1, value: [void 0, void 0, void 0, void 0] } : this._reuseResult = e.reuseResult);
}
next(e) {
let t = this._nextResult1, n = this._nextResult2;
if (t.done && n.done) return t;
if (t.done) {
const i = n;
this._nextResult2 = this._iterator2.next();
const l = this._reuseResult ?? { done: !1, value: [void 0, void 0, void 0, void 0] };
l.done = !1;
const c = l.value, h = i.value;
return c[2] = h[0], c[3] = h[1], c[0] = void 0, c[1] = void 0, l;
}
if (n.done) {
const i = t;
this._nextResult1 = this._iterator1.next();
const l = this._reuseResult ?? { done: !1, value: [void 0, void 0, void 0, void 0] };
l.done = !1;
const c = l.value, h = i.value;
return c[0] = h[0], c[1] = h[1], c[2] = void 0, c[3] = void 0, l;
}
let r = (0, this._comparator)(t.value[0], n.value[0]);
if (r < 0) {
const i = t;
this._nextResult1 = this._iterator1.next();
const l = this._reuseResult ?? { done: !1, value: [void 0, void 0, void 0, void 0] };
l.done = !1;
const c = l.value, h = i.value;
return c[0] = h[0], c[1] = h[1], c[2] = void 0, c[3] = void 0, l;
}
if (r > 0) {
const i = n;
this._nextResult2 = this._iterator2.next();
const l = this._reuseResult ?? { done: !1, value: [void 0, void 0, void 0, void 0] };
l.done = !1;
const c = l.value, h = i.value;
return c[2] = h[0], c[3] = h[1], c[0] = void 0, c[1] = void 0, l;
}
this._nextResult1 = this._iterator1.next(), this._nextResult2 = this._iterator2.next();
const o = this._reuseResult ?? { done: !1, value: [void 0, void 0, void 0, void 0] };
o.done = !1;
const s = o.value;
return s[0] = t.value[0], s[1] = t.value[1], s[2] = n.value[0], s[3] = n.value[1], o;
}
return(e) {
return null;
}
throw(e) {
return null;
}
[Symbol.iterator]() {
return this;
}
}
const jh = "Must be an array of arrays.", ni = (a, e, t) => {
const n = e.majorStart, r = e.minorStart, o = e.majorEnd, s = [], i = e.minorEnd - r + 1, l = typeof a == "function";
for (let c = n; c <= o; c++) {
const h = new Array(i);
if (l) if (t) {
let d = r;
for (let g = 0; g < i; g++) h[g] = a(d++, c);
} else {
let d = r;
for (let g = 0; g < i; g++) h[g] = a(c, d++);
}
else h.fill(a, 0, i);
const u = [[r, h]];
s.push([c, u]);
}
return { tuples: s, bounds: e };
}, Ii = (a, e = !1, t = null, n = !1) => {
let r = 0, o = 0, s = Number.MAX_SAFE_INTEGER, i = Number.MAX_SAFE_INTEGER;
if (t && (r = t.majorStart ?? 0, o = t.minorStart ?? 0, s = (t.majorEnd ?? Number.MAX_SAFE_INTEGER) - r + 1, i = (t.minorEnd ?? Number.MAX_SAFE_INTEGER) - o + 1), e) {
const c = r;
r = o, o = c;
const h = s;
s = i, i = h;
}
if (!Array.isArray(a)) throw new Error(jh);
if (a.length > s) throw new ze();
const l = e ? new Oe.TransposedBuilder() : new Oe.Builder();
for (let c = 0; c < a.length; c++) {
let h = a[c];
if (h != null && h.length !== 0) {
if (!Array.isArray(h)) throw new Error(jh);
if (h.length > i) throw new ze();
if (n) {
let u = -1;
for (let d = 0; d < h.length; d++)
h[d] == null ? u !== -1 && (l.addValues(c + r, o + u, h.slice(u, d)), u = -1) : u === -1 && (u = d);
u !== -1 && l.addValues(c + r, o + u, h.slice(u));
} else l.addValues(c + r, o, h);
}
}
return l.build();
}, m0 = (a, e, t) => {
if (a === e) return e;
}, f0 = (a, e, t) => {
if (a[0].value === a[1].value) return e;
}, p0 = [null, null], Gn = (a = !0, e = m0) => {
const t = [];
let n, r, o = Number.MIN_SAFE_INTEGER, s = Number.MIN_SAFE_INTEGER;
return { append: (i, l, c) => {
let h = !0;
if (c !== void 0) {
const g = r === void 0 ? c : e(r, c, a);
g === void 0 ? h = !1 : c = g;
}
if (h && l === s + 1 && i === o) return a ? n.rowEnd = l : n.colEnd = l, s = l, void (r = c);
n && t.push(n);
const u = a ? i : l, d = a ? l : i;
n = { colStart: u, rowStart: d, colEnd: u, rowEnd: d, value: c }, o = i, s = l, r = c;
}, done: (i = !1) => (n && (t.push(n), n = null), i ? yn(t, a ? xe.Column : xe.Row, 2, f0, p0) : t) };
};
class sn {
constructor(e) {
this._major = null, this._dataCoords = null, this._count = 0, this._isColumn = !0, this._lastMajor = Number.MIN_SAFE_INTEGER, this._lastMinorSpan = null, this._maxCoords = null, this._isShared = !1, this._options = { orientation: xe.Row, ...e }, this._isColumn = (e?.orientation ?? xe.Column) === xe.Column, e?.maxCoords && (this._maxCoords = Object.freeze({ colStart: Math.max(0, e.maxCoords.colStart ?? 0), rowStart: Math.max(0, e.maxCoords.rowStart ?? 0), colEnd: Math.min(Number.MAX_SAFE_INTEGER, e.maxCoords.colEnd ?? Number.MAX_SAFE_INTEGER), rowEnd: Math.min(Number.MAX_SAFE_INTEGER, e.maxCoords.rowEnd ?? Number.MAX_SAFE_INTEGER) })), this._createRun = e?.createRun ?? ((t) => new jt(t)), this._optionsMinor = {}, this._major = new qn({ nodeSize: _0 });
}
getRuns(e) {
const t = this._isColumn, n = this._maxCoords, r = this.getCoords();
if (!r) return Ze;
const o = e?.bounds;
let s, i;
if (o) {
const _ = Tt(o?.colStart ?? Number.MIN_SAFE_INTEGER, o?.rowStart ?? Number.MIN_SAFE_INTEGER, o?.colEnd ?? Number.MAX_SAFE_INTEGER, o?.rowEnd ?? Number.MAX_SAFE_INTEGER, t, n, r);
if (!_) return Ze;
s = { bounds: { min: _.majorStart, max: _.majorEnd } }, i = { bounds: { min: _.minorStart, max: _.minorEnd } };
}
const l = this._major.entries(s);
let c = l.next();
if (c.done) return Ze;
let h = c.value[0], u = c.value[1], d = u.runs(i), g = d.next();
if (g.done) return Ze;
let m = g.value[0].min, f = g.value[1];
return { [Symbol.iterator]() {
return this;
}, next() {
if (c.done) return ke;
const _ = { done: !1, value: [h, m, f] };
for (g = d.next(); g.done && !c.done; ) c = l.next(), c.done || (h = c.value[0], u = c.value[1], d = u.runs(i), g = d.next());
return g.done || (m = g.value[0].min, f = g.value[1]), _;
} };
}
getOrientation() {
return this._isColumn ? xe.Column : xe.Row;
}
entries(e) {
const t = this._isColumn;
let n = t, r = !0;
const o = this._maxCoords, s = this.getCoords(), i = Tt(Number.MIN_SAFE_INTEGER, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, t, o, s);
if (!i) return Ze;
let l, c, h, u = i.majorStart, d = i.majorEnd, g = i.minorStart, m = i.minorEnd, f = !1;
if (e) {
e?.orientation && (n = e?.orientation === xe.Column, r = t === n);
const w = e?.bounds;
if (w) {
const b = Tt(w.colStart, w.rowStart, w.colEnd, w.rowEnd, t, o, s);
if (!b) return Ze;
u = b.majorStart, d = b.majorEnd, g = b.minorStart, m = b.minorEnd;
}
f = e.reverse ?? !1, h = /* @__PURE__ */ ((b) => typeof b != "boolean" ? b : b === !0 ? { done: !1, value: [{ colIndex: -1, rowIndex: -1 }, null] } : void 0)(e.reuseResult), l = t ? e.processColumnSkip : e.processRowSkip, l && (f ? d = l(d, f) : u = l(u, f)), c = t ? e.processRowSkip : e.processColumnSkip, c && (f ? m = c(d, f) : g = c(g, f));
}
if (!s) return Ze;
r || u !== d || (r = !0), je.bounds.min = u, je.bounds.max = d, je.reverse = f, je.processSkip = l, je.reuseResult = Do;
let _ = this._major.entries(je), p = Vh();
const S = (w) => {
if (!w.nextActive) return;
const b = (v) => {
const R = w.nextMinorIndex, A = w.nextMinorValue, M = w.nextActive;
return v ? (w.nextMinorIndex = v[0], w.nextMinorValue = v[1], w.nextActive = !0) : (w.nextActive = !1, w.nextMinorIndex = f ? Number.MIN_SAFE_INTEGER : Number.MAX_SAFE_INTEGER, w.nextMinorValue = null), w.value = A, w.minorIndex = R, w.active = M, Dn[0] = w.majorIndex, Dn[1] = R, Dn[2] = A, Dn;
}, x = w.minorIterator;
if (!x) return b();
const I = x.next();
return I.done && (w.minorIterator = null), b(I.value);
}, E = (w) => {
if (_) for (; ; ) {
const b = _.next();
if (b.done) return void (_ = void 0);
const x = b.value, I = x[1];
I || console.warn("issue", I), w.majorIndex = x[0], w.active = !0, w.nextActive = !1, Lt.bounds.min = g, Lt.bounds.max = m, Lt.reverse = f, Lt.processSkip = c, Lt.reuseResult = Lg;
const v = I.entries(Lt), R = v.next();
if (!R.done) {
const A = R.value;
return w.nextMinorIndex = A[0], w.nextMinorValue = A[1], w.minorIterator = v, w.nextActive = !0, S(w);
}
}
};
let y = null;
if (r)
y = () => {
let w;
return w = S(p), w || (w = E(p), w || void 0);
};
else {
const w = f ? m : g, b = f ? g : m;
let x, I = w, v = b, R = !0;
const A = () => {
if (p.nextMajorCursor) return p = p.nextMajorCursor, p;
p = x, (I < g || I > m || I === v) && (p = null), I = v, v = b;
};
y = () => {
for (; p; ) {
let M = null;
if (R) {
let T = x ? Vh() : p;
if (M = E(T), M) {
x ? (T.prevMajorCursor = p, p.nextMajorCursor = T, p = T) : x = p, v = f ? Math.max(v, p.nextMinorIndex) : Math.min(v, p.nextMinorIndex);
const k = p.minorIndex;
k !== w && (v = f ? Math.max(v, k) : Math.min(v, k), M = null);
} else R = !1, A();
} else {
const T = p.minorIndex, k = p.nextMinorIndex;
T === I ? (Dn[0] = p.majorIndex, Dn[1] = T, Dn[2] = p.value, M = Dn) : !f && T > I || f && T < I ? v = f ? Math.max(v, T) : Math.min(v, T) : !f && k > I || f && k < I ? v = f ? Math.max(v, k) : Math.min(v, k) : M = S(p), p.active && (v = f ? Math.max(v, p.nextMinorIndex) : Math.min(v, p.nextMinorIndex)), b === I || p.active || (p.prevMajorCursor ? p.prevMajorCursor.nextMajorCursor = p.nextMajorCursor : x = p.nextMajorCursor, p.nextMajorCursor && (p.nextMajorCursor.prevMajorCursor = p.prevMajorCursor)), A();
}
if (M) return M;
}
};
}
return { next(w) {
if (w) throw new kd("Iterator with next argument is not supported.");
const b = y();
return b ? ((I, v, R, A, M) => {
const T = M ?? { done: !1, value: [{ colIndex: -1, rowIndex: -1 }, null] }, k = T.value, P = k[0];
return P.colIndex = A ? I : v, P.rowIndex = A ? v : I, k[1] = R, T;
})(b[0], b[1], b[2], t, h) : ke;
}, [Symbol.iterator]() {
return this;
}, return: (w) => null, throw: (w) => null };
}
values(e) {
const t = this.entries(e);
let n;
return e?.reuseResult && (n = e.reuseResult === !0 ? { done: !1, value: null } : e.reuseResult), { next(r) {
const o = t.next(r);
return o.done ? ke : n ? (n.value = o.value[1], n) : { done: !1, value: o.value[1] };
}, [Symbol.iterator]() {
return this;
}, return: (r) => null, throw: (r) => null };
}
keys(e) {
const t = this.entries(e);
let n;
return e?.reuseResult && (n = e.reuseResult === !0 ? { done: !1, value: null } : e.reuseResult), { next(r) {
const o = t.next(r);
return o.done ? ke : n ? (n.value = o.value[0], n) : { done: !1, value: o.value[0] };
}, [Symbol.iterator]() {
return this;
}, return: (r) => null, throw: (r) => null };
}
_updateMajorSpan(e, t = !1) {
if (!e || e.length === 0) return;
t && e.sort((l, c) => l[0] - c[0]);
const n = this._major, r = e[0];
let o = r[0], s = o, i = [r[1]];
for (let l = 1; l < e.length; l++) {
const c = e[l], h = c[0], u = c[1];
h === s + 1 ? i.push(u) : (n.setRunAt(o, new jt(i)), o = h, i = [u]), s = h;
}
i.length > 0 && n.setRunAt(o, new jt(i));
}
setValues(e) {
if (!e) throw new Kt();
if (e.length === 0) return this;
const t = (e = e.sort(Hh))[0][0], n = e[e.length - 1][0];
let r = Number.MIN_SAFE_INTEGER, o = Number.MAX_SAFE_INTEGER;
const s = this._isColumn, i = this._maxCoords;
if (i) {
const C = s ? i.colStart : i.rowStart, w = s ? i.colEnd : i.rowEnd;
if (t < C || n > w) throw new ze();
r = s ? i.rowStart : i.colStart, o = s ? i.rowEnd : i.colEnd;
}
if (!e || e.length === 0) return this;
let l = Number.MAX_SAFE_INTEGER, c = Number.MIN_SAFE_INTEGER, h = 0, u = t - 1;
const d = [], g = (C, w, b) => {
if (u === b) throw new Oe.OutOfOrderError(`Duplicate major Indices: {${b}}.`);
u = b, w = w.sort(Hh), C = C.clone();
let x = Number.MIN_SAFE_INTEGER;
const I = w.length;
for (let v = 0; v < I; v++) {
const R = w[v], A = R[0], M = R[1], T = A + M.length - 1;
if (x >= A) throw new Oe.OutOfOrderError(`Overlapping minor Indices: {${b}, ${A}}.`);
if (A < r || T > o) throw new ze();
if (M && M.length > 0) {
const k = C.getCount();
C.setRunAt(A, m(M));
const P = C.getCount();
h += P - k, l = Math.min(l, C.getCoords().min), c = Math.max(c, C.getCoords().max);
}
x = T;
}
_++, d.push([b, C]);
}, m = this._createRun, f = this._optionsMinor;
let _ = 0;
const p = () => {
const C = e[_], w = C[0], b = C[1], x = new qn(f);
g(x, b, w);
}, S = this._major;
je.bounds.min = t, je.bounds.max = n, je.reverse = !1, je.processSkip = null, je.reuseResult = Do;
const E = S.entries(je);
let y = E.next();
for (; !y.done; ) {
const C = y.value, w = C[0];
let b = e[_], x = b[0];
if (x > w) y = E.next();
else {
for (; x < w; ) p(), b = e[_], x = b[0];
if (x === w) {
const I = b[1], v = C[1];
g(v, I, w);
}
y = E.next();
}
}
for (; e[_]; ) p();
return this._updateMajorSpan(d), this._updateCountAndCoords(h, t, l, n, c), this;
}
_updateCountAndCoords(e, t, n, r, o, s = !1) {
const i = this._count + e;
if (this._count = i, this._lastMajor = Number.MIN_SAFE_INTEGER, !this._dataCoords) return;
const l = this._isColumn;
let c = l ? t : n, h = l ? n : t, u = l ? r : o, d = l ? o : r;
if (i === 0) this._dataCoords = null;
else {
const g = this._dataCoords;
g && (c = (s ? Math.max : Math.min)(c, g.colStart), h = (s ? Math.max : Math.min)(h, g.rowStart), u = (s ? Math.min : Math.max)(u, g.colEnd), d = (s ? Math.min : Math.max)(d, g.rowEnd));
const m = { colStart: c, rowStart: h, colEnd: u, rowEnd: d };
this._dataCoords = m;
}
}
clear() {
this._major.clear(), this._dataCoords = null, this._count = 0;
}
delete(e) {
const t = this._count;
if (!e) return this.clear(), t > 0;
const n = this._isColumn, r = this._maxCoords, o = this.getCoords(), s = Tt(e.colStart, e.rowStart, e.colEnd, e.rowEnd, n, r, o);
if (!s || t === 0) return !1;
if (D.isRangeWithinRange(o, e)) return this.clear(), t > 0;
const i = s.majorStart, l = s.majorEnd, c = s.minorStart, h = s.minorEnd;
let u = n ? o.colStart : o.rowStart, d = n ? o.colEnd : o.rowEnd;
const g = n ? o.rowStart : o.colStart, m = n ? o.rowEnd : o.colEnd;
let f = !1, _ = 0;
const p = this._major;
if (c <= g && h >= m) {
je.bounds.min = i, je.bounds.max = l;
const x = p.entries(je);
let I = x.next();
for (; !I.done; )
_ -= I.value[1].getCount(), I = x.next();
return p.delete(i, l - i + 1), this._count += _, this._dataCoords = null, _ !== 0;
}
const S = [], E = this._isShared, y = [];
je.bounds.min = i, je.bounds.max = l, Lt.reverse = !1, Lt.processSkip = null, Lt.reuseResult = Do;
const C = p.entries(je);
let w = C.next();
for (; !w.done; ) {
const x = w.value, I = x[0];
let v = x[1];
const R = v.getCoords(), A = R.min, M = R.max;
if (c <= A && h >= A || c <= M && c <= M) if ((A === g && c <= g || M === m && h >= m) && (f = !0), A >= c && M <= h) S.push(I), _ -= v.getCount();
else {
const T = v.getCount();
E && (v = v.clone(), y.push([I, v])), v.delete(c, h - c + 1), _ += v.getCount() - T;
}
w = C.next();
}
this._updateMajorSpan(y);
const b = S.length;
if (b > 0) {
const x = mh(S, !0);
for (let v = 0; v < x.length; v++) {
const R = x[v];
p.delete(R.min, R.max - R.min + 1);
}
const I = p.getCoords();
if (!I) return this.clear(), !0;
u = I.min, d = I.max;
}
return f ? (this._count += _, this._dataCoords = null, !0) : b === 0 ? (this._count += _, _ !== 0) : (this._updateCountAndCoords(_, u, g, d, m, !0), _ !== 0);
}
shift(e, t) {
if (!e || !t) throw new Kt();
const n = this._isColumn, r = this._maxCoords, o = t === He.Right || t === He.Down, s = t === He.Left || t === He.Right, i = Tt(e.colStart, e.rowStart, e.colEnd, e.rowEnd, n, r, e);
if (!i) return !1;
const l = i.majorStart, c = i.majorEnd, h = i.minorStart, u = i.minorEnd, d = this.getCoords();
if (!d) return !1;
const g = n ? d.colStart : d.rowStart, m = n ? d.colEnd : d.rowEnd, f = n ? d.rowStart : d.colStart, _ = n ? d.rowEnd : d.colEnd, p = h <= f && u >= _, S = n === s;
if ((S && p || !S && l <= g && c >= m) && !Tt(d.colStart, d.rowStart, d.colEnd + (o && s ? e.colEnd - e.colStart + 1 : 0), d.rowEnd + (o && !s ? e.rowEnd - e.rowStart + 1 : 0), n, r) || S && l > m || !S && h > _) return !1;
let E = S ? c - l + 1 : u - h + 1;
if (!o && (E *= -1, D.isRangeWithinRange(d, e))) return this.clear(), !0;
let y = 0;
const C = this._major, w = [];
if (je.bounds.min = l, je.bounds.max = S ? Number.MAX_SAFE_INTEGER : c, Lt.reverse = !o, Lt.processSkip = null, Lt.reuseResult = Do, S && p) {
if (!o) {
je.bounds.max = c;
const L = C.entries(je);
let j = L.next();
for (; !j.done; )
y -= j.value[1].getCount(), j = L.next();
}
C.shift(l, E);
const W = C.getCoords();
return this._dataCoords = null, this._updateCountAndCoords(y, W.min, f, W.max, _), !0;
}
let b = n ? d.colStart : d.rowStart, x = n ? d.colEnd : d.rowEnd, I = n ? d.rowStart : d.colStart, v = n ? d.rowEnd : d.colEnd;
o || (I = Number.MAX_SAFE_INTEGER, v = Number.MIN_SAFE_INTEGER);
let R = Number.MAX_SAFE_INTEGER;
r && (R = s ? r.colEnd : r.rowEnd);
const A = /* @__PURE__ */ new Set(), M = S ? /* @__PURE__ */ new Map() : null, T = [], k = C.entries(je), P = { bounds: { min: h, max: u } };
let B = k.next();
for (; !B.done; ) {
const W = B.value, L = W[0], j = W[1].clone(), G = j.getCoords(), V = G.min, $ = G.max;
if (S && M.set(L, j), h <= $) {
const J = j.getCount();
S ? (L >= l - E && Gp(j.runs(P), (he, le) => {
const pe = le.min, ee = le.max;
let ne = he;
pe - 1 <= u && ee > u && (ne = ne.slice(0, u + 1 - pe)), pe < h && ee + 1 >= h && (ne = ne.slice(h - pe)), T.push({ majorIndex: L + E, minorIndex: Math.max(pe, h), run: ne });
}), j.delete(h, u - h + 1)) : j.shift(h, E);
const K = j.getCount();
if (K === 0) A.add(L), I = Math.min(I, $), v = Math.max(v, V);
else {
const he = j.getCoords();
if (I = Math.min(I, he.min), v = Math.max(v, he.max), v > R) throw new ze();
}
y += K - J, w.push([L, j]);
}
B = k.next();
}
const H = this._optionsMinor;
let z = !1;
for (let W = 0; W < T.length; W++) {
const L = T[W], j = L.majorIndex, G = L.run;
let V = M.get(j);
V || (V = new qn(H), M.set(j, V), w.push([j, V]), z = !0), V.setRunAt(L.minorIndex, G), y += G.length, b = Math.min(b, j), x = Math.max(x, j), A && A.delete(j);
}
if (this._updateMajorSpan(w, z), A && A.size > 0) {
const W = Array.from(A.values()), L = mh(W);
for (let G = 0; G < L.length; G++) {
const V = L[G];
C.delete(V.min, V.max - V.min + 1);
}
const j = C.getCoords();
if (!j) return this.clear(), !0;
b = j.min, x = j.max;
}
if (v !== _ || I !== f) return this._count += y, this._dataCoords = null, !0;
{
const W = this._count + y;
this._count = W, this._dataCoords = W === 0 ? null : Object.freeze({ colStart: n ? b : I, rowStart: n ? I : b, colEnd: n ? x : v, rowEnd: n ? v : x });
}
return y !== 0 || !D.isEqualRanges(d, this.getCoords());
}
getCount() {
return this._count;
}
getValueAt(e, t) {
const n = this._isColumn, r = n ? t : e, o = n ? e : t, s = this._lastMajor;
let i;
if (s === r && s !== Number.MIN_SAFE_INTEGER ? i = this._lastMinorSpan : (i = this._major.at(r), this._lastMajor = r, this._lastMinorSpan = i), !!i)
return i.at(o);
}
setValueAt(e, t, n) {
const r = this._isColumn, o = [r ? t : e, [[r ? e : t, [n]]]];
this.setValues([o]);
}
copyTo(e, t, n) {
if (this.getCount() === 0) return;
const r = this.getOrientation(), o = e.getOrientation(), s = this.getRuns({ bounds: n });
let i = s.next();
const l = D.cellToRange(t);
l.colEnd = n.colEnd - n.colStart + t.colIndex, l.rowEnd = n.rowEnd - n.rowStart + t.rowIndex;
const c = this._isColumn, h = this._maxCoords, u = this.getCoords();
let d, g = Tt(n.colStart ?? Number.MIN_SAFE_INTEGER, n.rowStart ?? Number.MIN_SAFE_INTEGER, n.colEnd ?? Number.MAX_SAFE_INTEGER, n.rowEnd ?? Number.MAX_SAFE_INTEGER, c, h, u);
g = { ...g };
const m = o !== xe.Row, f = e.getMaxCoords();
d = Tt(l?.colStart ?? Number.MIN_SAFE_INTEGER, l?.rowStart ?? Number.MIN_SAFE_INTEGER, l?.colEnd ?? Number.MAX_SAFE_INTEGER, l?.rowEnd ?? Number.MAX_SAFE_INTEGER, m, f), d = { ...d };
const _ = d.majorStart - g.majorStart, p = d.minorStart - g.minorStart, S = r === o ? new Oe.Builder() : new Oe.TransposedBuilder();
for (; !i.done; ) {
const y = i.value[0];
let C = i.value[1], w = i.value[2];
C + w.length > g.minorEnd && (w = w.slice(0, g.minorEnd - C + 1)), C < g.minorStart && (w = w.slice(g.minorStart - C), C = g.minorStart), S.addValues(y + _, C + p, w), i = s.next();
}
const E = S.build();
e.delete(l), E && e.setValues(E.tuples);
}
getCoords() {
if (this._dataCoords) return this._dataCoords;
if (this._major.getCount() === 0) return null;
let e = Number.MAX_SAFE_INTEGER, t = Number.MIN_SAFE_INTEGER, n = Number.MAX_SAFE_INTEGER, r = Number.MIN_SAFE_INTEGER;
const o = this._major.entries();
let s = o.next();
for (; !s.done; ) {
const c = s.value, h = c[0];
e = Math.min(h, e), t = Math.max(h, t);
const u = c[1].getCoords();
n = Math.min(u.min, n), r = Math.max(u.max, r), s = o.next();
}
const i = this._isColumn, l = Object.freeze({ colStart: i ? e : n, rowStart: i ? n : e, colEnd: i ? t : r, rowEnd: i ? r : t });
return this._dataCoords = l, l;
}
clone(e) {
this._isShared = !0;
const t = new sn(this._options);
return t._isShared = !0, t._major = this._major.clone(), t._dataCoords = this._dataCoords, t._count = this._count, t;
}
cloneEmpty(e) {
return new sn(this._options);
}
getMaxCoords() {
return this._maxCoords || null;
}
get [Symbol.toStringTag]() {
let e = "";
const t = this.getCoords();
if (t) {
const n = t.colEnd - t.colStart + 1, r = t.rowEnd - t.rowStart + 1;
e = `${this.getCount()}-${this._isColumn ? n : r}x${this._isColumn ? r : n}`;
}
return `[SparseGrid:${e}]`;
}
}
sn || (sn = {});
const _0 = 12;
Object.seal({ done: !1, value: null });
const Dn = [-1, -1, null], Lg = Object.seal({ done: !1, value: [-1, null] }), Do = Object.seal({ done: !1, value: [-1, null] }), Lt = { bounds: { min: -1, max: -1 }, reverse: !1, processSkip: null, reuseResult: Lg }, je = { bounds: { min: -1, max: -1 }, reverse: !1, processSkip: null, reuseResult: Do }, Vh = () => ({ majorIndex: -1, minorIndex: -1, value: null, active: !1, nextMinorIndex: -1, nextActive: !1, nextMinorValue: null, minorIterator: null, nextMajorCursor: null, prevMajorCursor: null });
class Ri {
constructor(e) {
if (this._l = 0, this._at = null, this._dt = $h.Undefined, this._a32 = null, this._a64 = null, this._cv = null, this._vt = null, this._vi32 = null, this._vi64 = null, this._vf32 = null, this._vf64 = null, !e) throw new Error("options is required");
const t = e.length;
if (this._l = t, this._dt = e.type, this._cv = e.getCoercedValue ?? null, t > 0) {
e.types && (this._at = e.types, this._vt = new Uint8Array(this._at));
const n = e.values32 ?? null;
n && (this._a32 = n, this._vi32 = new Int32Array(n), this._vf32 = new Float32Array(n));
const r = e.values64 ?? null;
if (r && (this._a64 = r, this._vf64 = new Float64Array(r), this._vi64 = new BigInt64Array(r)), !n && !r) throw new Error("values32 or values64 is required");
}
}
getConstructorOptions() {
return { length: this._l, type: this._dt, types: this._at, values32: this._a32, values64: this._a64, getCoercedValue: this._cv };
}
at(e) {
if (e >>> 0 >= this._l) return;
const t = this._vt, n = t && t[e] || this._dt;
let r, o = !1;
switch (this._vi32 ? r = this._vi32[e] : (o = !0, r = Number(this._vi64[e])), n) {
case ri:
return o ? Number(r) : r;
case jo:
return o ? this._vf64[e] : this._vf32[e];
case oi:
return !!r;
case si:
case ii:
return this._cv(n, o ? Number(r) : r);
case Lo:
return this._vi64[o ? e : r];
case Bo:
return this._vf64[o ? e : r];
case Pg:
return Number.NaN;
case Hg:
return Number.MAX_SAFE_INTEGER;
case Wg:
return Number.MIN_SAFE_INTEGER;
case Bg:
return 1 / 0;
case zg:
return -1 / 0;
case jg:
return null;
case nc:
case ai:
return;
}
return this._cv(n, o ? Number(r) : r);
}
toArray(e) {
const t = [], n = Math.max(e, this._l);
for (let r = 0; r < n; r++) t.push(this.at(r));
return t;
}
get length() {
return this._l;
}
get [Symbol.toStringTag]() {
return "[MixTypedArrayList]";
}
toString() {
const e = this._a32, t = this._a64;
let n = "";
return e && !t ? n = "32" : t && !e && (n = "64"), `{${n}${this._at ? "" : ":SINGLE_TYPE"}}:${this._l}}`;
}
static _createArrayBuffer(e) {
try {
return new SharedArrayBuffer(e);
} catch {
}
return new ArrayBuffer(e);
}
static fromArray(e, t, n, r, o = S0) {
const s = e.length;
if (s === 0) return new Ri({ type: $h.Undefined, length: s, getCoercedValue: n });
let i = this._createArrayBuffer(s * Int8Array.BYTES_PER_ELEMENT), l = new Uint8Array(i), c = 0, h = !1, u = Gh(e[0], r);
for (let w = 0; w < s; w++) {
const b = e[w], x = Gh(b, r);
x !== Bo && x !== Lo || c++, u !== x && (l[w] = x, h = !0);
}
h || (l = null, i = null);
let d, g, m, f, _, p, S, E, y = !1;
c / s > o && (y = !0, c = s), c !== 0 && (m = this._createArrayBuffer(c * BigInt64Array.BYTES_PER_ELEMENT), f = new BigInt64Array(m), _ = new Float64Array(m)), y ? (d = f, g = _) : (p = this._createArrayBuffer(s * Int32Array.BYTES_PER_ELEMENT), S = new Int32Array(p), E = new Float32Array(p), d = S, g = E);
let C = u;
if (y) for (let w = 0; w < s; w++) {
const b = e[w];
switch (l && (C = l[w] || u), C) {
case ri:
d[w] = BigInt(b);
break;
case oi:
d[w] = BigInt(b ? 1 : 0);
break;
case jo:
g[w] = b;
break;
case Lo:
d[w] = b;
break;
case Bo:
g[w] = b;
break;
case si:
case ii:
d[w] = BigInt(t?.(C, b) ?? 0);
break;
default:
C > 127 && C < 255 && (d[w] = BigInt(t?.(C, b) ?? 0));
}
}
else {
let w = 0;
for (let b = 0; b < s; b++) {
const x = e[b];
switch (l && (C = l[b] || u), C) {
case ri:
d[b] = x;
break;
case oi:
d[b] = x ? 1 : 0;
break;
case jo:
g[b] = x;
break;
case Lo:
S[b] = w, f[w] = x, w++;
break;
case Bo:
S[b] = w, _[w] = x, w++;
break;
case si:
case ii:
d[b] = t?.(C, x) ?? 0;
break;
default:
C > 127 && C < 255 && (d[b] = t?.(C, x) ?? 0);
}
}
}
return new Ri({ length: s, types: h ? i : null, type: u, values32: p, values64: m, getCoercedValue: n });
}
}
const S0 = 0.1, ri = 1, jo = 2, oi = 3, Lo = 4, Bo = 5, si = 6, ii = 7, Bg = 8, zg = 9, Pg = 10, Hg = 11, Wg = 12, jg = 13, nc = 14, ai = 127, $h = { Undefined: nc }, Gh = (a, e) => {
switch (typeof a) {
case "number":
const t = a;
return Number.isNaN(t) ? Pg : t === 1 / 0 ? Bg : t === -1 / 0 ? zg : Object.is(t, -0) ? jo : t === Number.MAX_SAFE_INTEGER ? Hg : t === Number.MIN_SAFE_INTEGER ? Wg : Number.isInteger(t) && t <= 2147483647 && t >= -2147483648 ? ri : Math.fround(t) === t ? jo : Bo;
case "string":
return si;
case "boolean":
return oi;
case "object":
if (a === null) return jg;
if (a instanceof Error) return ii;
if (!e) return ai;
const n = e(a);
if (n < 128 || n > 255) throw new Error("Custom type must be between 128 and 255");
return n;
case "bigint":
return Lo;
case "undefined":
return nc;
case "symbol":
case "function":
return ai;
}
return ai;
}, zo = (a) => {
if (!a || a.length <= 1) return !1;
if (a.length === 2) return D.isRangesIntersect(a[0], a[1]);
const e = new Ne();
e.load(a);
const t = a.length;
for (let n = 0; n < t; n++)
if (e.search(a[n]).length > 1) return !0;
return !1;
}, Nl = (a, e, t) => {
const n = [];
if (D.isRangesIntersect(a, e)) {
const r = F.subtractRect({ top: a.rowStart, left: a.colStart, bottom: a.rowEnd + 1, right: a.colEnd + 1 }, { top: e.rowStart, left: e.colStart, bottom: e.rowEnd + 1, right: e.colEnd + 1 }, t === xe.Column), o = r.length;
for (let s = 0; s < o; s++) {
const i = { colStart: r[s].left, rowStart: r[s].top, colEnd: r[s].right - 1, rowEnd: r[s].bottom - 1 };
n.push(i);
}
} else n.push(a);
return n;
}, Uh = (a, e, t) => {
if (!e || !a?.[0]) return;
const n = a.length;
for (let r = 0; r < n; r++) {
const o = a[r];
D.intersectRanges(o, e) && t(o, !D.isRangeWithinRange(o, e), r);
}
}, Jh = (a, e) => {
const t = a.colStart, n = a.rowStart, r = e.colStart, o = e.rowStart;
return (s, i) => {
const l = s.colIndex - t, c = i.colIndex - r;
return l === c ? s.rowIndex - n - (i.rowIndex - o) : l - c;
};
}, qh = (a, e) => {
const t = a.colStart, n = a.rowStart, r = e.colStart, o = e.rowStart;
return (s, i) => {
const l = s.rowIndex - n, c = i.rowIndex - o;
return l === c ? s.colIndex - t - (i.colIndex - r) : l - c;
};
}, li = (a, e, t = !1, n = !1) => {
let r = e.colEnd - e.colStart + 1, o = e.rowEnd - e.rowStart + 1;
if (n) {
const c = r;
r = o, o = c;
}
const s = { colStart: a.colStart, rowStart: a.rowStart, colEnd: a.colStart + r - 1, rowEnd: a.rowStart + o - 1 };
if (t) {
let c = a.colStart, h = a.rowStart;
return D.isSingleCell(a) ? (c += r - 1, h += o - 1) : (c += a.colEnd - a.colStart, h += a.rowEnd - a.rowStart), s.colEnd = n ? h : c, s.rowEnd = n ? c : h, s;
}
const i = a.colEnd - a.colStart + 1;
if (i % r !== 0) return s;
const l = a.rowEnd - a.rowStart + 1;
return l % o !== 0 || (s.colEnd = a.colStart + i - 1, s.rowEnd = a.rowStart + l - 1), s;
};
class ka {
constructor(e, t) {
this._l = 0, e && t > 0 && (this._u = e, this._l = t);
}
at(e) {
if (e > this._l || e < 0 || !this._u) return;
const t = Math.floor(e % this._u.length);
return this._u.at(t);
}
toArray(e) {
const t = [], n = this._u, r = n.length;
for (let o = 0; o < e; o++) {
const s = Math.floor(o % r);
t.push(n.at(s));
}
return t;
}
get length() {
return this._l;
}
get [Symbol.toStringTag]() {
return "[RepeatingList]";
}
get isIList() {
return !0;
}
}
class ht {
constructor(e, t, n = null, r = !1) {
this._isLiteral = !1, this._values = e, this._coords = t, this._type = n, this._isLiteral = r;
}
getValueAt(e, t, n) {
const r = this._coords;
if (!r) return;
let o = this._values.getValueAt(e + r.rowStart, t + r.colStart) ?? null;
o === void 0 && (o = null);
const s = n?.type, i = s !== void 0 ? s : this._type;
return i && (o = Jt(o, gt(o, !0), i)), o;
}
_applyBuilder(e, t, n = !1) {
if (!t) return e;
const r = t.build();
return r && (n && (e = e.clone()), e.setValues(r.tuples)), e;
}
_cloneFromBuilder(e, t, n, r) {
if (!e) return this;
const o = e.build();
if (!o) return this;
let s = this._values;
const i = s.getOrientation(), l = (t?.orientation ?? i) === O.Orientation.Column, c = Jo(o.bounds, l), h = this._coords ?? D.EmptyRange, u = Math.max(c.colEnd - c.colStart + 1, n ?? h.colEnd - h.colStart + 1), d = Math.max(c.rowEnd - c.rowStart + 1, r ?? h.rowEnd - h.rowStart + 1), g = h.colStart, m = h.rowStart, f = g + u - 1, _ = m + d - 1;
return s = s.clone(), s.setValues(o.tuples), new ht(s, { colStart: g, rowStart: m, colEnd: f, rowEnd: _ }, this._type, this._isLiteral);
}
forEach(e, t) {
if (!e) return;
const n = this.entries(t);
let r = n.next();
for (; !r.done; ) {
const o = r.value, s = e(o.value, o.coords, this);
if (s) return s.break;
r = n.next();
}
}
reduce(e, t, n) {
if (!e) return t;
const r = this.entries(n);
let o = r.next(), s = t;
for (; !o.done; ) {
const i = o.value;
s = e(s, i.value, i.coords, this), o = r.next();
}
return s;
}
some(e, t) {
if (!e) return !1;
const n = this.entries(t);
let r = n.next();
for (; !r.done; ) {
const o = r.value;
if (e(o.value, o.coords, this)) return !0;
r = n.next();
}
return !1;
}
every(e, t) {
if (!e) return !0;
const n = this.entries(t);
let r = n.next();
for (; !r.done; ) {
const o = r.value;
if (!e(o.value, o.coords, this)) return !1;
r = n.next();
}
return !0;
}
replace(e, t) {
let n;
if (n = e?.isIRange ? e : b0(e, this._values, this._coords, this._type), this.size === 0) return n;
if (n.size === 0) return this;
const r = this._values.clone(), o = n._values, s = n._coords ?? D.EmptyRange, i = this._coords ?? D.EmptyRange, l = i.colStart, c = i.rowStart, h = l + (t.colIndex ?? 0), u = c + (t.rowIndex ?? 0);
o.copyTo(r, { colIndex: h, rowIndex: u }, s);
const d = Math.max(this.getWidth(), n.getWidth() + (t?.colIndex ?? 0)), g = Math.max(this.getHeight(), n.getHeight() + (t?.rowIndex ?? 0));
return new ht(r, { colStart: l, rowStart: c, colEnd: l + d - 1, rowEnd: c + +g - 1 }, this._type);
}
slice(e) {
if (!e) return this;
const t = this._coords ?? D.EmptyRange, n = (e.colStart ?? 0) + t.colStart, r = (e.rowStart ?? 0) + t.rowStart, o = { colStart: n, rowStart: r, colEnd: (e.colEnd ?? t.colEnd - n) + t.colStart, rowEnd: (e.rowEnd ?? t.rowEnd - r) + t.rowStart }, s = D.intersectRanges(t, o);
return new ht(this._values, s, this._type);
}
resize(e, t, n = null) {
if (e < 0 || t < 0) throw new Error(`Invalid resize dimensions: ${e} x ${t}`);
const r = this._coords ?? D.EmptyRange, o = r.colEnd - r.colStart + 1, s = r.rowEnd - r.rowStart + 1;
if (e === o && t === s) return this;
const i = { colStart: r.colStart, rowStart: r.rowStart, colEnd: r.colStart + e - 1, rowEnd: r.rowStart + t - 1 };
let l = this._values;
return (e > o || t > s) && (l = l.clone(), e > o && (at.colStart = r.colEnd + 1, at.rowStart = r.rowStart, at.colEnd = r.colEnd, at.rowEnd = r.rowEnd, this._fill(l, r, n)), t > s && (at.colStart = r.colStart, at.rowStart = r.rowEnd + 1, at.colEnd = r.colEnd, at.rowEnd = r.rowEnd, this._fill(l, r, n))), new ht(l, i, this._type);
}
_mergeIterators(e, t, n) {
const r = this._coords ?? D.EmptyRange, o = e._coords ?? D.EmptyRange, s = this._values.getOrientation(), i = n?.orientation ?? s, l = i !== O.Orientation.Row, c = this._entries(n), h = this._entries(n), u = r.colStart, d = r.rowStart, g = u - o.colStart, m = d - o.rowStart, f = i === s ? new Oe.Builder() : new Oe.TransposedBuilder(), _ = new Wh({ ...n, bounds: r, comparator: (l ? Jh : qh)(r, o) }, c, h);
let p = _.next();
for (; !p.done; ) {
const S = p.value;
let E = S[1], y = S[3];
const C = S[0], w = S[2], b = C ? C.colIndex : w.colIndex + g, x = C ? C.rowIndex : w.rowIndex + m, I = t(E, y, { colIndex: b - u, rowIndex: x - d }, this), v = l ? b : x, R = l ? x : b;
f.addValue(v, R, I), p = _.next();
}
return f;
}
intersect(e, t, n) {
if (!e) throw new Error("Invalid range to intersect");
const r = e, o = this._coords ?? null, s = r._coords ?? null;
if (!D.intersectRanges(o, s)) return new ht(this._values, null, this._type);
const i = this._mergeIterators(r, t, n);
return this._cloneFromBuilder(i, n);
}
startIncrementalUpdates(e) {
const t = e?.orientation ?? O.Orientation.Column, n = this._values.getOrientation(), r = (e?.orientation ?? n) !== O.Orientation.Row, o = t === n ? new Oe.Builder() : new Oe.TransposedBuilder(), s = this, i = this._coords ?? D.EmptyRange, l = i.colStart, c = i.rowStart, h = r ? l : c, u = r ? c : l, d = { pushAt(g, m, f) {
const _ = r ? m : g, p = r ? g : m;
return o.addValue(_ + h, p + u, f), d;
}, pushMultipleAt(g, m, f) {
const _ = r ? m : g, p = r ? g : m;
return o.addValues(_ + h, p + u, f), d;
}, apply() {
const g = o.build();
return g ? (g.bounds.majorStart = h, g.bounds.minorStart = u, s._cloneFromBuilder(o, e)) : null;
} };
return d;
}
map(e, t) {
const n = this._values;
if (!this._coords || n.getCount() === 0) return this;
const r = n.getOrientation(), o = t?.orientation ?? r;
let s;
const i = this.entries(t);
let l = i.next();
l.done || (s = this._createTupleBuilder(o));
const c = o === O.Orientation.Column;
for (; !l.done; ) {
const h = l.value, u = h.coords, d = e(h.value, u, this), g = c ? u.colIndex : u.rowIndex, m = c ? u.rowIndex : u.colIndex;
s.addValue(g, m, d), l = i.next();
}
return this._cloneFromBuilder(s, t);
}
filter(e, t) {
const n = this._values;
if (!this._coords || n.getCount() === 0) return this;
const r = n.getOrientation(), o = t?.orientation ?? r, s = this._createTupleBuilder(o), i = this.entries(t);
let l = i.next();
const c = o === O.Orientation.Column;
for (; !l.done; ) {
const h = l.value, u = h.coords, d = h.value;
if (e(d, u, this)) {
const g = c ? u.colIndex : u.rowIndex, m = c ? u.rowIndex : u.colIndex;
s.addValue(g, m, d);
}
l = i.next();
}
return this._cloneFromBuilder(s, t);
}
broadcast(e, t, n) {
let r = this._coords;
if (e == null) return this;
let o = n?.type, s = n?.otherType ?? o;
const i = o ? Jt(null, q.Null, o) : null, l = s ? Jt(null, q.Null, s) : null;
let c;
if (e.isIRange) c = e;
else {
const z = this._values.clone();
z.setValueAt(0, 0, e), c = new ht(z, D.EmptyRange, gt(e, !0));
}
const h = c, u = this.getWidth(), d = this.getHeight(), g = h.getWidth(), m = h.getHeight();
let f = Math.min(u, g), _ = Math.min(d, m), p = Math.max(u, g), S = Math.max(d, m);
const E = n?.mismatchFill;
let y = !1;
if (u !== g) if (u === 1) f = g;
else if (g === 1) f = u;
else {
if (!E) throw new Error(`Incompatible shapes for broadcast: width dimensions ${u} and ${g} must be equal or one must be 1`);
y = !0;
}
if (d !== m) if (d === 1) _ = m;
else if (m === 1) _ = d;
else {
if (!E) throw new Error(`Incompatible shapes for broadcast: height dimensions ${d} and ${m} must be equal or one must be 1`);
y = !0;
}
const C = this._values.getOrientation(), w = C, b = w === O.Orientation.Column;
r = r ?? D.EmptyRange;
let x, I, v = h._coords ?? D.EmptyRange;
if (y && (r = { colStart: r.colStart, rowStart: r.rowStart, colEnd: r.colStart + f - 1, rowEnd: r.rowStart + f - 1 }, v = { colStart: v.colStart, rowStart: v.rowStart, colEnd: v.colStart + f - 1, rowEnd: v.rowStart + f - 1 }), u === 1 && u < g || d === 1 && d < m) {
const z = { ...r };
u === 1 && (z.colEnd = z.colStart), d === 1 && (z.rowEnd = z.rowStart), x = new Tl({ delegate: this._entries({ ...n, orientation: w, bounds: z, reuseResult: !1 }), bounds: z, orientation: w, dims: { major: b ? f : _, minor: b ? _ : f } });
} else x = this._entries({ ...n, orientation: w, bounds: r, reuseResult: !1 });
if (g === 1 && g < u || m === 1 && m < d) {
const z = { ...v };
g === 1 && (z.colEnd = z.colStart), m === 1 && (z.rowEnd = z.rowStart), I = new Tl({ delegate: h._entries({ ...n, type: s ?? null, orientation: w, bounds: z, reuseResult: !1 }), bounds: z, orientation: w, dims: { major: b ? f : _, minor: b ? _ : f } });
} else I = h._entries({ ...n, type: s ?? null, orientation: w, bounds: v, reuseResult: !1 });
const R = r.colStart, A = r.rowStart, M = R - v.colStart, T = A - v.rowStart, k = w === C ? new Oe.Builder() : new Oe.TransposedBuilder(), P = new Wh({ ...n, bounds: r, comparator: (b ? Jh : qh)(r, v) }, x, I);
let B, H = P.next();
for (; !H.done; ) {
const z = H.value;
let W = z[1], L = z[3];
const j = z[0], G = z[2], V = j ? j.colIndex : G.colIndex + M, $ = j ? j.rowIndex : G.rowIndex + T;
let J, K;
W instanceof Ee.Value ? J = W : L instanceof Ee.Value && (J = L), K = J || t(W ?? i, L ?? l, { colIndex: V - R, rowIndex: $ - A }, this);
const he = b ? V : $, le = b ? $ : V;
k.addValue(he, le, K), H = P.next();
}
if (E && p > f || S > _) {
const z = this._values.clone();
if (this._applyBuilder(z, k), p > f) {
const W = Tt(R + f, A, R + p - 1, A + S - 1, b), L = ni(E, W, b);
z.setValues(L.tuples);
}
if (S > _) {
const W = Tt(R, A + _, R + p - 1, A + S - 1, b), L = ni(E, W, b);
z.setValues(L.tuples);
}
B = new ht(z, { colStart: R, rowStart: A, colEnd: R + p - 1, rowEnd: A + S - 1 }, this._type);
} else B = this._cloneFromBuilder(k, n, p, S);
return B;
}
_fill(e, t, n) {
if (n === null) return void e.delete(t);
const r = e.getOrientation() === O.Orientation.Column, o = Tt(t.colStart, t.rowStart, t.colEnd, t.rowEnd, r), s = ni(n, o, r);
e.setValues(s.tuples);
}
_validateCoords(e) {
}
fill(e, t) {
let n = this._coords;
if (!n && !t) return this;
n = n ?? D.EmptyRange, t && (at.colStart = (t.colStart ?? 0) + n.colStart, at.rowStart = (t.rowStart ?? 0) + n.rowStart, at.colEnd = (t.colEnd ?? n.colEnd - n.colStart) + n.colStart, at.rowEnd = (t.rowEnd ?? n.rowEnd - n.rowStart) + n.rowStart), this._validateCoords(at);
const r = this._values.clone();
return this._fill(r, at, e), (at.rowEnd > n.rowEnd || at.colEnd > n.colEnd) && (n = { colStart: n.colStart, rowStart: n.rowStart, colEnd: Math.max(n.colEnd, at.colEnd), rowEnd: Math.max(n.rowEnd, at.rowEnd) }), new ht(r, n, this._type);
}
empty() {
const e = this._values.cloneEmpty();
return new ht(e, null, this._type);
}
flatten(e) {
const t = [], n = this.values(e);
let r = n.next();
for (; !r.done; ) t.push(r.value), r = n.next();
return t;
}
fillEmpty(e, t = 1, n = 1) {
const r = this._coords;
if (!r) return this;
const o = this._values;
if (t < 1 && n < 1) throw new Error("Must be at least size of 1");
const s = o.getOrientation(), i = s, l = i === O.Orientation.Column, c = Math.max(this.getWidth(), t), h = Math.max(this.getHeight(), n), u = l ? r.colStart : r.rowStart, d = l ? r.rowStart : r.colStart, g = l ? r.colStart + c - 1 : r.rowStart + h - 1, m = l ? r.rowStart + h - 1 : r.colStart + c - 1, f = o.getRuns({ bounds: { colStart: r.colStart, rowStart: r.rowStart, colEnd: l ? g : m, rowEnd: l ? m : g }, overflowRun: !0 });
let _ = f.next(), p = u, S = d;
const E = i === s ? new Oe.Builder() : new Oe.TransposedBuilder();
for (; !_.done; ) {
const y = _.value, C = y[0];
for (; p < C; ) {
const v = new ka([e], m + 1 - S);
E.addValues(p, S, v), p++, S = d;
}
const w = y[1], b = Math.max(w, d), x = y[2], I = Math.min(w + x.length - 1, m);
if (S < b) {
const v = new ka([e], w - S);
E.addValues(p, S, v);
}
S = I + 1, I >= m ? (p = C + 1, S = d) : p = C, _ = f.next();
}
for (; p <= g; ) {
const y = new ka([e], m + 1 - S);
E.addValues(p, S, y), p++, S = d;
}
return this._cloneFromBuilder(E, void 0, c, h);
}
transpose() {
if (this.size <= 1) return this;
const e = this._values.getOrientation(), t = this._coords, n = this.getWidth(), r = this.getHeight(), o = this._entries({ orientation: e === O.Orientation.Column ? O.Orientation.Row : O.Orientation.Column, bounds: t, reuseResult: !0 }), s = e === O.Orientation.Column, i = new Oe.Builder(), l = s ? t.colStart : t.rowStart, c = s ? t.rowStart : t.colStart;
let h = o.next();
for (; !h.done; ) {
const u = h.value, d = u[0], g = s ? d.colIndex : d.rowIndex - l, m = (s ? d.rowIndex : d.colIndex - c) + l, f = g + c, _ = u[1];
i.addValue(m, f, _), h = o.next();
}
return this._cloneFromBuilder(i, void 0, r, n);
}
values(e) {
const t = this.entries(e);
return { [Symbol.iterator]() {
return this;
}, next() {
const n = t.next();
return n.done ? ke : { done: !1, value: n.value.value };
} };
}
_createTupleBuilder(e) {
const t = this._coords, n = this._values.getOrientation(), r = e ?? n, o = r !== O.Orientation.Row, s = o ? t.colStart : t.rowStart, i = o ? t.rowStart : t.colStart;
return r === n ? new Oe.Builder(null, s, i) : new Oe.TransposedBuilder(null, s, i);
}
entries(e) {
const t = this._coords;
if (!t) return Ze;
const n = e?.bounds;
if (e = { ...e, bounds: t }, n) {
const s = (n.colStart ?? 0) - t.colStart, i = (n.rowStart ?? 0) - t.rowStart, l = Math.max(s + t.colStart, t.colStart), c = Math.max(i + t.rowStart, t.rowStart), h = Math.min((n.colEnd ?? Number.MAX_SAFE_INTEGER) - s, t.colEnd - t.colStart) + 1, u = Math.min((n.rowEnd ?? Number.MAX_SAFE_INTEGER) - i, t.rowEnd - t.rowStart) + 1;
e.bounds = { colStart: l, rowStart: c, colEnd: l + h - 1, rowEnd: c + u - 1 };
}
const r = this._entries(e), o = { [Symbol.iterator]: () => o, next() {
for (; ; ) {
let s = r.next();
if (s.done) return ke;
const i = s.value, l = i[0];
return { done: !1, value: { coords: { colIndex: l.colIndex - t.colStart, rowIndex: l.rowIndex - t.rowStart }, value: i[1] } };
}
} };
return o;
}
_entries(e) {
if (!this._coords) return Ze;
let t = this._values.entries(e);
const n = e?.type ?? this._type;
let r = null;
if (e?.includeEmpty && (t = new Dg(t, e), n && (r = Jt(null, q.Null, n))), n) {
const o = t, s = e.coerce ?? !1, i = e.includeBoolean ?? !1, l = e.includeMistyped ?? !1;
t = { [Symbol.iterator]: () => t, next() {
for (; ; ) {
let c = o.next();
if (c.done) return ke;
const h = c.value, u = h[1];
let d = u;
if (d == null) d = r;
else if (n && (s || !l)) {
let g = gt(d, !0), m = g !== n;
if (m && (s && (d = Jt(d, g, n, i), m = d?.isFormulaError), m && !l)) continue;
}
return d === u ? c : { done: !1, value: [h[0], d] };
}
} };
}
return t;
}
getValues(e) {
if (!this._coords) return [[]];
const t = { ...e, includeEmpty: !0, reverse: !1, bounds: { colStart: 0, rowStart: 0, colEnd: this.getWidth() - 1, rowEnd: this.getHeight() - 1 } };
let n = !1;
t.orientation = e?.orientation ?? O.Orientation.Row, e && (e.maxHeight && (t.bounds.rowEnd = 0 + e.maxHeight - 1), e.maxWidth && (t.bounds.colEnd = 0 + e.maxWidth - 1), e.trailingEmpties && (n = e.trailingEmpties), t.orientation = e?.orientation ?? O.Orientation.Row);
const r = [];
if (!n) {
t.includeEmpty = !1, t.reverse = !0;
const u = this.entries(t).next();
if (u.done) return w0;
const d = u.value.coords;
t.bounds.colEnd = d.colIndex, t.bounds.rowEnd = d.rowIndex, t.includeEmpty = !0, t.reverse = !1;
}
const o = this.entries(t), s = t.orientation !== O.Orientation.Row, i = e?.onValue;
let l, c = -1, h = [];
for (l = o.next(); !l.done; ) {
const u = l.value, d = u.coords, g = s ? d.colIndex : d.rowIndex;
g !== c && (h = [], r.push(h), c = g);
let m = u.value;
if (i) {
const f = i(m, d.rowIndex, d.colIndex, this);
f !== void 0 && (m = f);
}
h.push(m), l = o.next();
}
return r;
}
toType(e) {
return new ht(this._values, this._coords, e, this._isLiteral);
}
getWidth() {
const e = this._coords;
return e ? e.colEnd - e.colStart + 1 : 0;
}
getHeight() {
const e = this._coords;
return e ? e.rowEnd - e.rowStart + 1 : 0;
}
get size() {
const e = this._coords;
return e ? (e.colEnd - e.colStart + 1) * (e.rowEnd - e.rowStart + 1) : 0;
}
isLiteral() {
return this._isLiteral;
}
getScalarType() {
return this._type;
}
[Symbol.iterator]() {
const e = this.entries();
return { next() {
const t = e.next();
return t.done ? ke : { done: !1, value: t.value.value };
}, [Symbol.iterator]() {
return this;
} };
}
get [Symbol.toStringTag]() {
return "[Range]";
}
toString() {
const e = this._coords, t = e ? `${e.colEnd - e.colStart + 1}x${e.rowEnd - e.rowStart + 1}` : Ee.Ref.toString();
let n = "{";
const r = this.entries({ includeEmpty: !0, orientation: O.Orientation.Row });
let o = r.next(), s = 0, i = o.value?.coords.rowIndex ?? 0;
for (; !o.done && s < 10; ) {
const l = o.value;
l.coords.rowIndex > i ? (n += ";", i = l.coords.rowIndex) : s > 0 && (n += ","), s++;
let c = l.value;
typeof c == "string" ? c = `"${c}"` : typeof c == "boolean" && (c = c ? "TRUE" : "FALSE"), n += c, o = r.next();
}
return o.done ? n += "}" : n += "...", `[${t}:${n}]`;
}
get isIRange() {
return !0;
}
}
const at = { colStart: Number.MIN_SAFE_INTEGER, rowStart: Number.MIN_SAFE_INTEGER, colEnd: Number.MAX_SAFE_INTEGER, rowEnd: Number.MAX_SAFE_INTEGER }, w0 = Object.freeze([Object.freeze([null])]), rs = Object.freeze({ colStart: 0, rowStart: 0, colEnd: Math.pow(2, 14) - 1, rowEnd: Math.pow(2, 20) - 1 }), y0 = Object.freeze({ colIndex: 0, rowIndex: 0 }), Fl = () => rs, gt = (a, e = !1) => typeof a == "number" ? isNaN(a) || a === 1 / 0 || a === -1 / 0 ? q.Error : q.Number : typeof a == "string" ? q.String : typeof a == "boolean" ? q.Boolean : a?.isFormulaError ? q.Error : a === null ? q.Null : F.isObject(a) && a.hasOwnProperty("type") && typeof a.type == "string" ? q.RichData : e && to(a) ? "Date" : a === void 0 ? (console.warn("undefined"), q.Null) : null, Kh = /* @__PURE__ */ new Map([[q.Null, "any"], [q.Number, "number"], [q.String, "string"], [q.Boolean, "boolean"], [q.Error, "FormulaError"], [q.RichData, "richData"], ["*", "Scalar"]]), E0 = /* @__PURE__ */ new Map([["p", "IReferenceRange"], ["r", "IRange"]]), C0 = { orientation: O.Orientation.Row }, Jt = (a, e, t = q.Number, n = !1, r = !1) => {
if (e === t || !t) return e === q.Number && (a = Ui(a, null, "number")), a;
if (t === q.Number) {
switch (e) {
case q.Null:
return 0;
case q.String:
let o = 0;
try {
const s = mm(a);
o = s && typeof s.value == "number" ? s.value : Number.NaN;
} catch {
}
return !Number.isFinite(o) || Math.abs(o) > 999e305 ? Ee.BuiltIn.Value : o;
case q.Boolean:
return n ? a ? 1 : 0 : Ee.BuiltIn.Value;
case "Date":
return es(a, r) ?? Ee.BuiltIn.Value;
case q.Error:
return a;
}
return a.toString();
}
if (t === q.String) {
switch (e) {
case q.Null:
return "";
case q.Number:
return a.toString();
case q.Boolean:
return a ? "TRUE" : "FALSE";
case q.Error:
return a;
}
return a;
}
if (t === q.Boolean) {
switch (e) {
case q.Null:
return 0;
case q.Number:
return !!a;
case q.String:
let o = a.trim().toUpperCase();
return o === "TRUE" || o !== "FALSE" && Ee.BuiltIn.Value;
case q.Error:
return a;
}
return Ee.BuiltIn.Value;
}
if (t === "Date") {
switch (e) {
case q.Number:
return no(a, r) ?? Ee.BuiltIn.Value;
case q.String:
try {
const o = Xl(a, r);
if (o) return o.asJSDate ?? Ee.BuiltIn.Value;
} catch {
}
return a;
case q.Error:
return a;
}
return Ee.BuiltIn.Value;
}
return Ee.BuiltIn.Value;
}, Xh = (a) => {
let e = a;
for (; Array.isArray(e); ) {
if (e.length > 1) return !1;
e = e[0];
}
return !e || !e.isIRange || e.size === 1;
}, Vg = (a, e, t, n, r, o = !1) => {
if (Array.isArray(t)) {
const s = t.length;
for (let i = 0; i < s; i++) {
let l = t[i];
if (Array.isArray(l)) {
const c = Vg(a, e, l, n, r, o);
if (o) continue;
if (c instanceof Ee.Value) return c;
} else {
if (n) {
if (l = Jt(l, gt(l, !0), n, o), o) continue;
if (l instanceof Ee.Value) return l;
}
e.push(l);
}
}
return;
}
if (t && t.colStart !== void 0) {
let s = a.getReference?.(t);
n && (s = s.toType(n)), t = s;
}
if (t?.isIRange)
return ((s, i) => {
let l = s.next();
for (; !l.done; ) {
let c = l.value;
if (c instanceof Ee.Value) return c;
i.push(c), l = s.next();
}
})(t.values({ type: n, coerce: !0, includeMistyped: !o, ...C0 }), e);
if (n) {
if (t = Jt(t, gt(t, !0), n, r !== null), o) return;
if (t instanceof Ee.Value) return t;
}
e.push(t);
}, fo = (a, e, t, n, r, o) => {
if (r === "r") {
let i = t;
return i && i.isIReferenceRange ? (n && (i = i.toType(n)), void e.push(t)) : new Ee.Value("Cannot convert a literal to a reference.");
}
let s = t?.isIRange ? t : null;
if (r !== "l") {
if (s) {
const i = s.getValues({ type: n });
return void e.push(i);
}
{
Array.isArray(t) || (t = [t]);
const i = t.length, l = new Array(i);
for (let c = 0; c < i; c++) {
let h = t[c];
Array.isArray(h) || (h = [h]);
const u = h.length, d = new Array(u);
for (let g = 0; g < u; g++) {
let m = h[g];
if (n && (m = Jt(m, gt(m, !0), n)), m instanceof Ee.Value) return m;
d[g] = m;
}
l[c] = d;
}
e.push(l);
}
} else {
if (s) n && s.getScalarType() !== n && (s = s.toType(n));
else try {
if (!o && (t = Ui(t), n && (t = Jt(t, gt(t, !0), n, !0), t?.isFormulaError && n !== q.Error))) return e.push(t), t;
s = a.getRange(t), n && (s = s.toType(n));
} catch (i) {
return i;
}
e.push(s);
}
}, Ui = (a, e, t = typeof a) => {
if (t === "number") return isNaN(a) ? Ee.BuiltIn.Num : isFinite(a) ? a += 0 : Ee.BuiltIn.Div0;
if (a == null) return null;
if (!e) return a;
if (Array.isArray(a)) try {
a = e.getRange(a);
} catch {
return Ee.BuiltIn.Value;
}
return e.isValidDate(a) ? (e.formatResults("Short Date"), e.toOADate(a)) : a;
}, b0 = (a, e, t, n) => {
let r;
r = Array.isArray(a) ? Array.isArray(a[0]) ? a : [a] : [[a]], e || (e = new sn({ orientation: O.Orientation.Column }));
const o = e.getOrientation() === O.Orientation.Column, s = Ii(r, o, Tt(t?.colStart ?? 0, t?.rowStart ?? 0, void 0, void 0, o), !0), i = Jo(s.bounds, o);
return e.setValues(s.tuples), new ht(e, i, n, !t);
}, v0 = new RegExp(/^([$]?[a-zA-Z]*[$]?[0-9]*)[:]?([$]?[a-zA-Z]*[$]?[0-9]*)?$/), x0 = new RegExp(/^(R(?:\[?[-+]?\d+\]?|\d+)?C(?:\[?[-+]?\d+\]?|\d+)?)(:(R(?:\[?[-+]?\d+\]?|\d+)?C(?:\[?[-+]?\d+\]?|\d+)?))?$/, "i"), I0 = new RegExp(/^(R?)(\[?[-+]?\d+\]?|\d+)?(C?)(\[?[-+]?\d+\]?|\d+)?$/, "i"), R0 = new RegExp("(?:'[^']+'|[A-Za-z0-9_\\-.]+?!)?(\\$?[A-Za-z]+\\$?\\d+(?::\\$?[A-Za-z]+\\$?\\d+)?|\\$?[A-Za-z]+:\\$?[A-Za-z]+|\\$?\\d+:\\$?\\d+)", "g"), A0 = /\s+/g, M0 = /"(?:[^"]|"")*"|\[[^[\]]+\]/g, Oa = /[\uE000-\uF8FF]/g, rt = "#REF!", $g = Math.pow(2, 14), T0 = Math.pow(2, 20);
let Yh, Qh;
const an = (a) => (Yh === a || (Qh = "" + (a + 1), Yh = a), Qh);
let Zh, Da;
const Yt = (a) => {
if (Zh === a) return Da;
if (Zh = a, a < 0) throw new Error("invalid column " + a);
let e = "";
for (++a; a; a = Math.floor((a - 1) / 26)) e = String.fromCharCode((a - 1) % 26 + 65) + e;
return Da = e, Da;
}, N0 = /[^a-zA-Z0-9]/, os = (a) => a ? Yt(a.colIndex) + an(a.rowIndex) : null, Xn = (a) => {
if (!a) return rt;
const e = Yt(a.colIndex), t = an(a.rowIndex);
return (a.$colIndex ? "$" + e : e) + (a.$rowIndex ? "$" + t : t);
}, rc = (a, e) => {
let t = a ?? e;
var n;
return t && (t = Yl(t), t = t.replace(/'/g, "''"), n = t, N0.test(n) && (t = mg(t))), t;
}, Gg = (a, e) => a ? a + (a.endsWith("!") ? "" : "!") + e : rt, Rn = (a, e, t = os) => {
if (!a) return null;
const n = a.colStart, r = a.rowStart, o = a.colEnd, s = a.rowEnd;
if (n === o && r === s) return t({ colIndex: n, rowIndex: r });
a = { ...e, ...a };
const i = n === Number.MIN_SAFE_INTEGER || e && n <= e.colStart && o >= e.colEnd, l = r === Number.MIN_SAFE_INTEGER || e && r <= e.rowStart && s >= e.rowEnd;
let c = null;
c = l ? Yt(n) : i ? an(r) : t({ colIndex: n, rowIndex: r });
let h = null;
return h = l ? Yt(o) : i ? an(s) : t({ colIndex: o, rowIndex: s }), c + ":" + h;
}, La = (a, e, t = Xn) => {
if (!a) return rt;
const n = a.colIndex, r = a.rowIndex, o = n === Number.MIN_SAFE_INTEGER;
let s = null;
if (r === Number.MIN_SAFE_INTEGER ? (s = Yt(n), a.$colIndex && (s = "$" + s)) : o ? (s = an(r), a.$rowIndex && (s = "$" + s)) : s = t(a), a.sheetName || e) {
const i = rc(a.sheetName, e);
s = Gg(i, s);
}
return s;
}, En = (a, e, t = Xn) => {
if (!a) return rt;
const n = a.rowStart !== void 0 && a.rowStart === a.rowEnd;
if (a.colStart !== void 0 && a.colStart === a.colEnd && n) return t({ colIndex: a.colStart, rowIndex: a.rowStart, $colIndex: a.$colStart, $rowIndex: a.$rowStart });
a = { ...e, ...a };
const r = e && a.rowStart <= e.rowStart && a.rowEnd >= e.rowEnd, o = e && a.colStart <= e.colStart && a.colEnd >= e.colEnd;
let s = null;
r ? (s = Yt(a.colStart), s = a.$colStart ? "$" + s : s) : o ? (s = an(a.rowStart), s = a.$rowStart ? "$" + s : s) : s = t({ colIndex: a.colStart, rowIndex: a.rowStart, $colIndex: a.$colStart, $rowIndex: a.$rowStart });
let i = null;
return r ? (i = Yt(a.colEnd), i = a.$colEnd ? "$" + i : i) : o ? (i = an(a.rowEnd), i = a.$rowEnd ? "$" + i : i) : i = t({ colIndex: a.colEnd, rowIndex: a.rowEnd, $colIndex: a.$colEnd, $rowIndex: a.$rowEnd }), s + ":" + i;
}, Ji = (a, e, t = Xn) => {
const n = En(a, e, t), r = rc(a?.sheetName, e?.sheetName);
return Gg(r, n);
}, Ug = (a, e = !1) => {
if (!a) return null;
let t = 0, n = 0, r = !1, o = !1;
const s = a.length;
for (let l = 0; l < s; ++l) {
const c = a.charCodeAt(l);
if (c >= 48 && c <= 57) {
if (n = 10 * n + (c - 48), t === 0 && !e) return;
} else if (c >= 65 && c <= 90) {
if (t = 26 * t + (c - 64), n !== 0) return;
} else if (c >= 97 && c <= 122) {
if (t = 26 * t + (c - 96), n !== 0) return;
} else {
if (c !== 36) return;
if (t !== 0 || r) {
if (n !== 0 || o) return;
o = !0;
} else r = !0;
}
}
const i = {};
return e || n !== 0 && t !== 0 ? (t > 0 && (i.colIndex = t - 1, r && (i.$colIndex = r)), n > 0 && (i.rowIndex = n - 1, (o || e && r) && (i.$rowIndex = o || e && r)), i) : null;
}, Pt = (a, e = rs, t = !1) => {
if (!a) return null;
let n = a.toUpperCase();
const r = Kg(n, t);
let o = null, s = null;
if (r?.[1]) {
const l = !!r[2], c = t ? ci : Ug;
o = c(r[1], l), s = c(r[2] ?? r[1], l);
}
if (!o && !s || o && s && (o.rowIndex === void 0 && s.rowIndex !== void 0 || o.rowIndex !== void 0 && s.rowIndex === void 0 || o.colIndex === void 0 && s.colIndex !== void 0 || o.colIndex !== void 0 && s.colIndex === void 0))
return null;
const i = {};
return o && (o.colIndex !== void 0 && (i.colStart = o.colIndex), o.rowIndex !== void 0 && (i.rowStart = o.rowIndex), o.$colIndex !== void 0 && (i.$colStart = o.$colIndex), o.$rowIndex !== void 0 && (i.$rowStart = o.$rowIndex), i?.colStart !== void 0 && i?.colStart > e?.colEnd) ? null : (s && (s.colIndex !== void 0 && (i.colEnd = s.colIndex), s.rowIndex !== void 0 && (i.rowEnd = s.rowIndex), s.$colIndex !== void 0 && (i.$colEnd = s.$colIndex), s.$rowIndex !== void 0 && (i.$rowEnd = s.$rowIndex)), { ...e, ...i });
}, ss = (a, e, t = !1) => {
const n = ((o) => {
const s = o.lastIndexOf("!");
if (s === -1) return null;
let i = o.slice(0, s);
return i = Yl(i), i = i.replace(/''/g, "'"), [i, o.slice(s + 1)];
})(a);
let r;
if (n) {
if (r = Pt(n[1], e, t), !r) return null;
r.sheetName = n[0];
} else r = Pt(a, e, t);
return r || null;
}, oc = (a, e, t = En, n = Xn) => {
if (!a || a.length === 0) return null;
const r = [], o = a.length;
for (let s = 0; s < o; s++) {
const i = a[s];
let l = null;
i ? i.rowIndex !== void 0 || i.colIndex !== void 0 ? l = n(i) : i.rowStart !== void 0 || i.colStart !== void 0 ? l = t(i, e, n) : typeof i == "string" && (l = i) : l = rt, l && r.push(l);
}
return r;
}, Jg = (a, e, t = Ji, n = Xn) => {
const r = oc(a, e, t, n);
return r ? r.join(",") : rt;
}, qg = (a, e, t, n = ss, r, o = !1) => {
if (e !== null) {
if (typeof e == "string") {
const s = n(e, t, o);
if (!s) {
const i = r?.(e);
if (i) {
const l = i.length;
for (let c = 0; c < l; c++) {
const h = i[c];
qg(a, h, t, n, r, o);
}
}
return;
}
e = s;
} else e.isICellRange ? e = e.getCoords() : e.isICell && (e = D.cellToRange(e.getCoords()));
if (e !== null) {
if (e.rowStart !== void 0 || e.colStart !== void 0 || e.colEnd !== void 0 || e.rowEnd !== void 0) {
const s = e;
a.push({ ...t, ...s });
} else if (e.rowIndex !== void 0 || e.colIndex !== void 0) {
const s = e, i = { ...t, ...s, colStart: s.colIndex, rowStart: s.rowIndex, colEnd: s.colIndex, rowEnd: s.rowIndex };
i.sheetName === null && t.sheetName && (i.sheetName = t.sheetName), delete i.colIndex, delete i.rowIndex, a.push(i);
}
} else a.push(null);
} else a.push(null);
}, sc = (a, e, t = ss, n, r = !1) => {
if (!a) return [e];
let o;
o = typeof a == "string" ? fg(a) : a.isICellRanges ? a.getCoords() : Array.isArray(a) ? a : [a];
const s = [], i = o.length;
for (let l = 0; l < i; l++) {
const c = o[l];
qg(s, c, e, t, n, r);
}
return s;
}, Pr = (a, e) => {
let t = 0, n = 0;
const r = a.length;
for (let o = 0; o < r; ++o) {
const s = a.charCodeAt(o);
if (s >= 48 && s <= 57) {
if (t = 10 * t + (s - 48), n === 0) return;
} else if (s >= 65 && s <= 90) {
if (n = 26 * n + (s - 64), t !== 0) return;
} else if (!(s >= 97 && s <= 122) || (n = 26 * n + (s - 96), t !== 0)) return;
}
return e ? (e.colIndex = n - 1, e.rowIndex = t - 1, e) : { colIndex: n - 1, rowIndex: t - 1 };
}, ci = (a, e = !1, t) => {
t ? (t.colIndex = Number.MIN_SAFE_INTEGER, t.rowIndex = Number.MIN_SAFE_INTEGER, t.$colIndex = !1, t.$rowIndex = !1) : t = { colIndex: Number.MIN_SAFE_INTEGER, rowIndex: Number.MIN_SAFE_INTEGER, $colIndex: !1, $rowIndex: !1 };
const n = I0.exec(a);
if (!n) return null;
const r = n[1], o = n[3];
if (!(e || r && o)) return null;
if (r) {
const s = n[2];
s ? s && (s.startsWith("[") ? (t.rowIndex = parseInt(s.slice(1, -1)), t.$rowIndex = !1) : (t.rowIndex = parseInt(s) - 1, t.$rowIndex = !0)) : (t.rowIndex = 0, t.$rowIndex = !1);
}
if (o) {
const s = n[4];
s ? s.startsWith("[") ? (t.colIndex = parseInt(s.slice(1, -1)), t.$colIndex = !1) : (t.colIndex = parseInt(s) - 1, t.$colIndex = !0) : (t.colIndex = 0, t.$colIndex = !1);
}
return t;
}, kl = (a, e) => {
let t = 0, n = 0, r = !1, o = !1;
const s = a.length;
for (let i = 0; i < s; ++i) {
const l = a.charCodeAt(i);
l >= 48 && l <= 57 ? t = 10 * t + (l - 48) : l >= 65 && l <= 90 ? n = 26 * n + (l - 64) : l >= 97 && l <= 122 ? n = 26 * n + (l - 96) : l === 36 && (i === 0 ? r = !0 : o = !0);
}
return n--, t--, e.colIndex = n, e.rowIndex = t, t === -1 ? (e.$colIndex = r, e.$rowIndex = !1, e) : n === -1 ? (e.$colIndex = !1, e.$rowIndex = r, e) : (e.$colIndex = r, e.$rowIndex = o, e);
}, F0 = (a) => {
let e = 0;
const t = a.length;
for (let n = 0; n < t; ++n) {
const r = a.charCodeAt(n);
if (r >= 65 && r <= 90) e = 26 * e + (r - 64);
else {
if (!(r >= 97 && r <= 122)) return e - 1;
e = 26 * e + (r - 96);
}
}
return e - 1;
}, At = (a, e) => {
let t = e;
t ? (t.rowStart = 0, t.colStart = 0, t.rowEnd = 0, t.colEnd = 0) : t = { rowStart: 0, colStart: 0, rowEnd: 0, colEnd: 0 };
let n = 0, r = 0, o = 0, s = a.length;
for (n = 0; r < s && (o = a.charCodeAt(r), o > 96 && o < 123 && (o -= 32), !(o < 65 || o > 91)); ++r) n = 26 * n + (o - 64);
for (t.colStart = --n, n = 0; r < s; ++r) {
let i = a.charCodeAt(r) - 48;
if (i < 0 || i > 9) break;
n = 10 * n + i;
}
if (t.rowStart = --n, r === s || a.charCodeAt(++r) === 58) return t.colEnd = t.colStart, t.rowEnd = t.rowStart, t;
for (n = 0; r !== s && (o = a.charCodeAt(r), o > 96 && o < 123 && (o -= 32), !(o < 65 || o > 91)); ++r) n = 26 * n + (o - 64);
for (t.colEnd = --n, n = 0; r !== s; ++r) {
let i = a.charCodeAt(r) - 48;
if (i < 0 || i > 9) break;
n = 10 * n + i;
}
return t.rowEnd = --n, t;
}, Kg = (a, e = !1) => {
const t = a.match(e ? x0 : v0);
return a.endsWith(":") ? null : t;
}, Ol = { rowIndex: -1, colIndex: -1, $colIndex: !1, $rowIndex: !1 }, Ba = (a, e, t, n = $g) => {
let r = a.lastIndexOf("!"), o = "";
r !== -1 && (o = a.slice(0, r) + "!", a = a.slice(r + 1));
let s = null;
const i = () => {
let c = "";
const h = s.rowIndex;
if (h !== -1) if (s.$rowIndex) c += `R${h + 1}`;
else {
const g = h - e;
c += g === 0 ? "R" : `R[${g}]`;
}
let u = "";
const d = s.colIndex;
if (d !== -1) if (s.$colIndex) u += `C${d + 1}`;
else {
const g = d - t;
u += g === 0 ? "C" : `C[${g}]`;
}
o += c + u;
};
r = a.lastIndexOf(":");
const l = r !== -1;
if (l) {
const c = a.slice(0, r);
a = a.slice(r + 1), s = kl(c, Ol), s.colIndex !== -1 && s.rowIndex !== -1 && (i(), o += ":");
}
return s = kl(a, Ol), !l && s.colIndex > n ? a : (i(), o);
}, Gr = [], k0 = (a) => (Gr.push(a), String.fromCharCode(57344 + Gr.length - 1)), O0 = (a) => {
const e = a.charCodeAt(0) - 57344;
return Gr[e];
}, D0 = (a, e, t) => {
let n = "";
const r = a.length;
for (let o = 0; o < r; o++) {
const s = a[o];
n += typeof s == "string" ? s : Xg(s, e, t);
}
return n;
}, hi = (a, e) => {
let t = "";
const n = a.rowIndex;
n !== Number.MIN_SAFE_INTEGER && (a.$rowIndex ? t += `R${n + 1}` : t += n === 0 ? "R" : `R[${n + 1}]`);
let r = "";
const o = a.colIndex;
return o !== Number.MIN_SAFE_INTEGER && (a.$colIndex ? r += `C${o + 1}` : r += o === 0 ? "C" : `C[${o + 1}]`), a.sheetName && (t = rc(a.sheetName, e) + "!" + t), t + r;
}, Xg = (a, e, t) => {
let n = "";
const r = a.colIndex;
r !== Number.MIN_SAFE_INTEGER && (a.$colIndex ? n += "$" + Yt(r) : n += Yt(r + t));
const o = a.rowIndex;
return o !== Number.MIN_SAFE_INTEGER && (a.$rowIndex ? n += "$" + an(o) : n += an(o + e)), n;
}, ry = (a, e, t, n) => {
let r = a.colStart, o = a.rowStart, s = a.colEnd, i = a.rowEnd;
const l = a.$colStart ?? !1, c = a.$rowStart ?? !1, h = a.$colEnd ?? !1, u = a.$rowEnd ?? !1;
if (l || r === Number.MIN_SAFE_INTEGER || (r += t), c || o === Number.MIN_SAFE_INTEGER || (o += e), h || s === Number.MAX_SAFE_INTEGER || (s += t), u || i === Number.MAX_SAFE_INTEGER || (i += e), r > s) {
const g = r;
r = s, s = g;
}
if (o > i) {
const g = o;
o = i, i = g;
}
let d;
return n ? (d = n, d.colStart = r, d.rowStart = o, d.colEnd = s, d.rowEnd = i, d.$colStart = l, d.$rowStart = c, d.$colEnd = h, d.$rowEnd = u) : d = { colStart: r, rowStart: o, colEnd: s, rowEnd: i, $colStart: l, $rowStart: c, $colEnd: h, $rowEnd: u }, a.sheetName && (d.sheetName = a.sheetName), d;
}, L0 = (a, e, t, n) => {
Gr.length = 0;
let r = 0, o = a.replace(M0, k0), s = 0, i = o.replace(R0, (l, c, h) => {
const u = Ba(l, e, t);
if (n) {
if (h > s) {
const g = o.slice(s, h).replace(Oa, (m, f) => Gr[r++]);
n.push(g);
}
const d = l.lastIndexOf(":");
if (d !== -1) {
const g = l.slice(0, d), m = l.slice(d + 1), f = Ba(g, e, t), _ = Ba(m, e, t);
n.push(ci(f, !0) ?? f), n.push(":"), n.push(ci(_, !0) ?? _);
} else n.push(ci(u, !0) ?? u);
}
return s = h + l.length, u;
});
if (n && s < o.length) {
const l = o.slice(s);
n.push(l.replace(Oa, (c, h) => Gr[r++]));
}
return i = i.toUpperCase().replace(A0, ""), i.replace(Oa, O0);
}, Ur = "Must specify an address.", Yg = "Only a single range is allowed for this operation. Use 'getRanges' instead.", eu = "Only a single cell is allowed.", Qg = "Invalid range. The Range must be specified as '{ TOP_LEFT:BOTTOM_RIGHT }'.", qo = (a) => `Invalid address. Can not parse ${typeof a == "string" ? `'${a}' ` : ""}as an address or named item.`, Ie = () => {
throw new Error("Invalid range.");
};
class hr {
constructor(e, t, n = !1) {
this._c = e, this._cycleId = t, this._e = n;
}
getCycleId() {
return this._cycleId;
}
getError() {
return this._e;
}
getCoords() {
return this._c;
}
setError(e, t) {
const n = this._c;
return { ...n, value: new hr(n, t, e) };
}
getShifted(e) {
const t = e.after;
if (!t) return null;
const n = D.sanitizeRange(t);
return { ...n, value: new hr(n, this._cycleId, this._e) };
}
getMerged(e, t, n) {
}
getSplit(e, t) {
}
}
class qt {
constructor(e, t) {
this._c = e, this._o = t;
}
getCoords() {
return this._c;
}
getOrientation() {
return this._o;
}
getShifted(e) {
return e.after ? { ...e.after, value: new qt(e.after, this._o) } : null;
}
getMerged(e, t, n) {
const r = this._o;
return new qt(t, r);
}
getSplit(e, t) {
const n = this._o;
return [new qt(e[0], n), new qt(e[1], n)];
}
getState() {
return this._c;
}
}
const tu = (a, e) => {
if (!a || a.length === 0) return F.EmptyArray;
const t = [], n = e ? O.Orientation.Column : O.Orientation.Row;
for (let r = 0; r < a.length; r++) {
const o = a[r], s = o[0], i = o[1];
for (let l = 0; l < i.length; l++) {
const c = i[l], h = c[0], u = c[1].length - 1, d = { colStart: e ? s : h, rowStart: e ? h : s, colEnd: e ? s : h + u, rowEnd: e ? h + u : s, value: new qt({ colStart: e ? s : h, rowStart: e ? h : s, colEnd: e ? s : h + u, rowEnd: e ? h + u : s }, n) };
t.push(d);
}
}
return t;
}, Dl = 0, nu = 1;
class _n {
constructor(e, t, n) {
this.ref = e, this.formula = t;
const r = e.colStart, o = e.rowStart;
if (n) {
const s = n, i = s.length;
for (let l = 0; l < i; l++) {
const c = [...s[l]];
s[l] = c;
const h = c.length;
for (let u = 0; u < h; u++) {
const d = { ...c[u] };
c[u] = d, d.colIndex = u + r, d.rowIndex = l + o, d.block = this;
}
}
this.calcs = s;
} else {
const s = t.getDirectPrecedentsAt(o, r), i = s?.length ?? 0, l = new Array(e.rowEnd - o + 1), c = e.colEnd - r + 1, h = l.length;
for (let u = 0; u < h; u++) {
const d = new Array(c), g = d.length;
for (let m = 0; m < g; m++) d[m] = { block: this, colIndex: m + r, rowIndex: u + o, cycleId: 0, markId: 0, inDegree: 0, dependents: F.EmptyArray, inputs: i === 0 ? F.EmptyArray : new Array(i), precedents: i === 0 ? F.EmptyArray : new Array(i), dynamic: null, cachedValue: void 0, removed: !1, pending: !1, pendingPrecedents: !1, pendingPromise: null, pendingResolved: !1, state: Dl, error: void 0 };
l[u] = d;
}
this.calcs = l;
}
}
toJSON() {
const e = this.ref;
return [Rn(e), this.formula.getTextAt(e.rowStart, e.colStart)];
}
getCoords() {
return this.ref;
}
getShifted(e) {
if (!e.after) return null;
const t = D.sanitizeRange(e.after), n = [...this.calcs], r = new _n(t, this.formula, n);
return { ...e.after, value: r };
}
setReferenceAt(e, t) {
const n = this.formula.setReferenceAt(e, t), r = [...this.calcs];
return new _n(this.ref, n, r);
}
getMerged(e, t, n) {
const r = this.formula, o = e.formula;
if (!r.isEquals(o)) return;
const s = this.calcs, i = e.calcs;
let l;
if (n === O.Orientation.Row) l = [...s, ...i];
else {
const c = s.length;
l = new Array(c);
for (let h = 0; h < c; h++) l[h] = [...s[h], ...i[h]];
}
return new _n(t, r, l);
}
getSplit(e, t, n) {
const r = this.formula, o = t === O.Orientation.Column;
let s, i;
const l = this.calcs;
if (o) {
const c = l.length;
s = new Array(c), i = new Array(c);
for (let h = 0; h < c; h++) {
const u = l[h];
s[h] = u.slice(0, n), i[h] = u.slice(n);
}
} else s = l.slice(0, n), i = l.slice(n);
return [new _n(e[0], r, s), new _n(e[1], r, i)];
}
copyTo(e, t) {
const n = this.formula;
return new _n(e, n);
}
canTile(e, t) {
return !0;
}
onRemove(e) {
const t = e.value.calcs, n = t.length;
for (let r = 0; r < n; r++) {
const o = t[r], s = o.length;
for (let i = 0; i < s; i++) {
const l = o[i];
l.pendingPromise && (l.pendingPromise.cancelled = !0), l.removed = !0;
}
}
}
}
const ru = Object.freeze({ break: !0 });
var oe;
(oe || (oe = {})).Type = { Style: "style", Table: "table", Merge: "merge", Hyperlink: "hyperlink", Comments: "comments", Unlock: "unlock", Contentful: "contentful", Conditional: "conditional", Formula: "formula", Spill: "spill", Continuous: "continuous", Pending: "pending", CalcError: "calcError" };
const B0 = Object.freeze({ [oe.Type.Style]: !1, [oe.Type.Table]: !1, [oe.Type.Merge]: !1, [oe.Type.Hyperlink]: !1, [oe.Type.Comments]: !1, [oe.Type.Unlock]: !1, [oe.Type.Formula]: !1, [oe.Type.Spill]: !1, [oe.Type.Pending]: !1, [oe.Type.CalcError]: !1, [oe.Type.Contentful]: !1, [oe.Type.Conditional]: !1, [oe.Type.Continuous]: !1 }), Zg = Object.freeze({ [oe.Type.Style]: !1, [oe.Type.Table]: !1, [oe.Type.Merge]: !1, [oe.Type.Hyperlink]: !1, [oe.Type.Comments]: !1, [oe.Type.Unlock]: !1, [oe.Type.Formula]: !1, [oe.Type.Spill]: !1, [oe.Type.Pending]: !1, [oe.Type.CalcError]: !1, [oe.Type.Conditional]: !1, [oe.Type.Continuous]: !1 }), z0 = Object.freeze({ [oe.Type.Style]: !1, [oe.Type.Table]: !0, [oe.Type.Merge]: !1, [oe.Type.Hyperlink]: !1, [oe.Type.Comments]: !1, [oe.Type.Unlock]: !1, [oe.Type.Formula]: !1 });
Object.freeze({ [oe.Type.Style]: !1, [oe.Type.Table]: !1, [oe.Type.Hyperlink]: !1, [oe.Type.Comments]: !1, [oe.Type.Unlock]: !1, [oe.Type.Contentful]: !1, [oe.Type.Formula]: !1 });
const bs = "This sheet is protected. To make a change, unprotect the sheet. You might be requested to enter a password.", P0 = (a = "update") => `Unable to ${a}, this sheet is protected. To make a change, unprotect the sheet. You might be requested to enter a password.`, Ai = "The range is outside of the bounds of the sheet.", ou = "Listener can not be null", su = "We can't insert items. The sheet is protected.", iu = (a) => `We can't create a ${a} that overlaps with another table or merge.`, au = "Overlapping ranges can not be merged.", za = "We can't insert cells because this would push values off the end of the worksheet. These cells may appear empty but they have some formatting or formulas. Delete enough rows or columns and try again.", lu = "Unable to partially fill over merged cells.", cu = "Unable to sort merged cells unless they are all the same size.", xt = "Sheet has been closed. No further operations are allowed.", Jr = "IteratorContext can only be used during visit.", hu = "When using addresses directly from the sheet do not include the sheet name.", em = (a) => `Unable to return more than ${a} values. To access values in a more scalable solution use 'ICellRange.forEach' or an iterator.`, uu = "'setValue' expects a single value; when working with an array use 'setValue'.", du = "Multiple selection ranges can not be copied.", gu = "Unable to determine source.", mu = "When pasting before or after the cut area both areas must align.", Tr = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date, fu = /* @__PURE__ */ new Set(), Ll = typeof process == "object" && process ? process : {}, tm = (a, e, t, n) => {
typeof Ll.emitWarning == "function" ? Ll.emitWarning(a, e, t, n) : console.error(`[${t}] ${e}: ${a}`);
};
let Mi = globalThis.AbortController, pu = globalThis.AbortSignal;
if (Mi === void 0) {
pu = class {
onabort;
_onabort = [];
reason;
aborted = !1;
addEventListener(t, n) {
this._onabort.push(n);
}
}, Mi = class {
constructor() {
e();
}
signal = new pu();
abort(t) {
if (!this.signal.aborted) {
this.signal.reason = t, this.signal.aborted = !0;
for (const n of this.signal._onabort) n(t);
this.signal.onabort?.(t);
}
}
};
let a = Ll.env?.LRU_CACHE_IGNORE_AC_WARNING !== "1";
const e = () => {
a && (a = !1, tm("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.", "NO_ABORT_CONTROLLER", "ENOTSUP", e));
};
}
const Pn = (a) => a && a === Math.floor(a) && a > 0 && isFinite(a), nm = (a) => Pn(a) ? a <= Math.pow(2, 8) ? Uint8Array : a <= Math.pow(2, 16) ? Uint16Array : a <= Math.pow(2, 32) ? Uint32Array : a <= Number.MAX_SAFE_INTEGER ? ui : null : null;
class ui extends Array {
constructor(e) {
super(e), this.fill(0);
}
}
class Hr {
heap;
length;
static #l = !1;
static create(e) {
const t = nm(e);
if (!t) return [];
Hr.#l = !0;
const n = new Hr(e, t);
return Hr.#l = !1, n;
}
constructor(e, t) {
if (!Hr.#l) throw new TypeError("instantiate Stack using Stack.create(n)");
this.heap = new t(e), this.length = 0;
}
push(e) {
this.heap[this.length++] = e;
}
pop() {
return this.heap[--this.length];
}
}
class ic {
#l;
#u;
#f;
#R;
#p;
#N;
#F;
ttl;
ttlResolution;
ttlAutopurge;
updateAgeOnGet;
updateAgeOnHas;
allowStale;
noDisposeOnSet;
noUpdateTTL;
maxEntrySize;
sizeCalculation;
noDeleteOnFetchRejection;
noDeleteOnStaleGet;
allowStaleOnFetchAbort;
allowStaleOnFetchRejection;
ignoreFetchAbort;
#o;
#_;
#r;
#n;
#e;
#c;
#d;
#a;
#s;
#S;
#i;
#w;
#y;
#g;
#E;
#I;
#h;
#k;
static unsafeExposeInternals(e) {
return { starts: e.#y, ttls: e.#g, sizes: e.#w, keyMap: e.#r, keyList: e.#n, valList: e.#e, next: e.#c, prev: e.#d, get head() {
return e.#a;
}, get tail() {
return e.#s;
}, free: e.#S, isBackgroundFetch: (t) => e.#t(t), backgroundFetch: (t, n, r, o) => e.#L(t, n, r, o), moveToTail: (t) => e.#T(t), indexes: (t) => e.#C(t), rindexes: (t) => e.#b(t), isStale: (t) => e.#m(t) };
}
get max() {
return this.#l;
}
get maxSize() {
return this.#u;
}
get calculatedSize() {
return this.#_;
}
get size() {
return this.#o;
}
get fetchMethod() {
return this.#N;
}
get memoMethod() {
return this.#F;
}
get dispose() {
return this.#f;
}
get onInsert() {
return this.#R;
}
get disposeAfter() {
return this.#p;
}
constructor(e) {
const { max: t = 0, ttl: n, ttlResolution: r = 1, ttlAutopurge: o, updateAgeOnGet: s, updateAgeOnHas: i, allowStale: l, dispose: c, onInsert: h, disposeAfter: u, noDisposeOnSet: d, noUpdateTTL: g, maxSize: m = 0, maxEntrySize: f = 0, sizeCalculation: _, fetchMethod: p, memoMethod: S, noDeleteOnFetchRejection: E, noDeleteOnStaleGet: y, allowStaleOnFetchRejection: C, allowStaleOnFetchAbort: w, ignoreFetchAbort: b } = e;
if (t !== 0 && !Pn(t)) throw new TypeError("max option must be a nonnegative integer");
const x = t ? nm(t) : Array;
if (!x) throw new Error("invalid max value: " + t);
if (this.#l = t, this.#u = m, this.maxEntrySize = f || this.#u, this.sizeCalculation = _, this.sizeCalculation) {
if (!this.#u && !this.maxEntrySize) throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
if (typeof this.sizeCalculation != "function") throw new TypeError("sizeCalculation set to non-function");
}
if (S !== void 0 && typeof S != "function") throw new TypeError("memoMethod must be a function if defined");
if (this.#F = S, p !== void 0 && typeof p != "function") throw new TypeError("fetchMethod must be a function if specified");
if (this.#N = p, this.#I = !!p, this.#r = /* @__PURE__ */ new Map(), this.#n = new Array(t).fill(void 0), this.#e = new Array(t).fill(void 0), this.#c = new x(t), this.#d = new x(t), this.#a = 0, this.#s = 0, this.#S = Hr.create(t), this.#o = 0, this.#_ = 0, typeof c == "function" && (this.#f = c), typeof h == "function" && (this.#R = h), typeof u == "function" ? (this.#p = u, this.#i = []) : (this.#p = void 0, this.#i = void 0), this.#E = !!this.#f, this.#k = !!this.#R, this.#h = !!this.#p, this.noDisposeOnSet = !!d, this.noUpdateTTL = !!g, this.noDeleteOnFetchRejection = !!E, this.allowStaleOnFetchRejection = !!C, this.allowStaleOnFetchAbort = !!w, this.ignoreFetchAbort = !!b, this.maxEntrySize !== 0) {
if (this.#u !== 0 && !Pn(this.#u)) throw new TypeError("maxSize must be a positive integer if specified");
if (!Pn(this.maxEntrySize)) throw new TypeError("maxEntrySize must be a positive integer if specified");
this.#V();
}
if (this.allowStale = !!l, this.noDeleteOnStaleGet = !!y, this.updateAgeOnGet = !!s, this.updateAgeOnHas = !!i, this.ttlResolution = Pn(r) || r === 0 ? r : 1, this.ttlAutopurge = !!o, this.ttl = n || 0, this.ttl) {
if (!Pn(this.ttl)) throw new TypeError("ttl must be a positive integer if specified");
this.#B();
}
if (this.#l === 0 && this.ttl === 0 && this.#u === 0) throw new TypeError("At least one of max, maxSize, or ttl is required");
if (!this.ttlAutopurge && !this.#l && !this.#u) {
const I = "LRU_CACHE_UNBOUNDED";
((v) => !fu.has(v))(I) && (fu.add(I), tm("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", I, ic));
}
}
getRemainingTTL(e) {
return this.#r.has(e) ? 1 / 0 : 0;
}
#B() {
const e = new ui(this.#l), t = new ui(this.#l);
this.#g = e, this.#y = t, this.#z = (o, s, i = Tr.now()) => {
if (t[o] = s !== 0 ? i : 0, e[o] = s, s !== 0 && this.ttlAutopurge) {
const l = setTimeout(() => {
this.#m(o) && this.#v(this.#n[o], "expire");
}, s + 1);
l.unref && l.unref();
}
}, this.#A = (o) => {
t[o] = e[o] !== 0 ? Tr.now() : 0;
}, this.#x = (o, s) => {
if (e[s]) {
const i = e[s], l = t[s];
if (!i || !l) return;
o.ttl = i, o.start = l, o.now = n || r();
const c = o.now - l;
o.remainingTTL = i - c;
}
};
let n = 0;
const r = () => {
const o = Tr.now();
if (this.ttlResolution > 0) {
n = o;
const s = setTimeout(() => n = 0, this.ttlResolution);
s.unref && s.unref();
}
return o;
};
this.getRemainingTTL = (o) => {
const s = this.#r.get(o);
if (s === void 0) return 0;
const i = e[s], l = t[s];
return !i || !l ? 1 / 0 : i - ((n || r()) - l);
}, this.#m = (o) => {
const s = t[o], i = e[o];
return !!i && !!s && (n || r()) - s > i;
};
}
#A = () => {
};
#x = () => {
};
#z = () => {
};
#m = () => !1;
#V() {
const e = new ui(this.#l);
this.#_ = 0, this.#w = e, this.#M = (t) => {
this.#_ -= e[t], e[t] = 0;
}, this.#P = (t, n, r, o) => {
if (this.#t(n)) return 0;
if (!Pn(r)) {
if (!o) throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
if (typeof o != "function") throw new TypeError("sizeCalculation must be a function");
if (r = o(n, t), !Pn(r)) throw new TypeError("sizeCalculation return invalid (expect positive integer)");
}
return r;
}, this.#O = (t, n, r) => {
if (e[t] = n, this.#u) {
const o = this.#u - e[t];
for (; this.#_ > o; ) this.#D(!0);
}
this.#_ += e[t], r && (r.entrySize = n, r.totalCalculatedSize = this.#_);
};
}
#M = (e) => {
};
#O = (e, t, n) => {
};
#P = (e, t, n, r) => {
if (n || r) throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
return 0;
};
*#C({ allowStale: e = this.allowStale } = {}) {
if (this.#o) for (let t = this.#s; this.#H(t) && (!e && this.#m(t) || (yield t), t !== this.#a); ) t = this.#d[t];
}
*#b({ allowStale: e = this.allowStale } = {}) {
if (this.#o) for (let t = this.#a; this.#H(t) && (!e && this.#m(t) || (yield t), t !== this.#s); ) t = this.#c[t];
}
#H(e) {
return e !== void 0 && this.#r.get(this.#n[e]) === e;
}
*entries() {
for (const e of this.#C()) this.#e[e] === void 0 || this.#n[e] === void 0 || this.#t(this.#e[e]) || (yield [this.#n[e], this.#e[e]]);
}
*rentries() {
for (const e of this.#b()) this.#e[e] === void 0 || this.#n[e] === void 0 || this.#t(this.#e[e]) || (yield [this.#n[e], this.#e[e]]);
}
*keys() {
for (const e of this.#C()) {
const t = this.#n[e];
t === void 0 || this.#t(this.#e[e]) || (yield t);
}
}
*rkeys() {
for (const e of this.#b()) {
const t = this.#n[e];
t === void 0 || this.#t(this.#e[e]) || (yield t);
}
}
*values() {
for (const e of this.#C())
this.#e[e] === void 0 || this.#t(this.#e[e]) || (yield this.#e[e]);
}
*rvalues() {
for (const e of this.#b())
this.#e[e] === void 0 || this.#t(this.#e[e]) || (yield this.#e[e]);
}
[Symbol.iterator]() {
return this.entries();
}
[Symbol.toStringTag] = "LRUCache";
find(e, t = {}) {
for (const n of this.#C()) {
const r = this.#e[n], o = this.#t(r) ? r.__staleWhileFetching : r;
if (o !== void 0 && e(o, this.#n[n], this)) return this.get(this.#n[n], t);
}
}
forEach(e, t = this) {
for (const n of this.#C()) {
const r = this.#e[n], o = this.#t(r) ? r.__staleWhileFetching : r;
o !== void 0 && e.call(t, o, this.#n[n], this);
}
}
rforEach(e, t = this) {
for (const n of this.#b()) {
const r = this.#e[n], o = this.#t(r) ? r.__staleWhileFetching : r;
o !== void 0 && e.call(t, o, this.#n[n], this);
}
}
purgeStale() {
let e = !1;
for (const t of this.#b({ allowStale: !0 })) this.#m(t) && (this.#v(this.#n[t], "expire"), e = !0);
return e;
}
info(e) {
const t = this.#r.get(e);
if (t === void 0) return;
const n = this.#e[t], r = this.#t(n) ? n.__staleWhileFetching : n;
if (r === void 0) return;
const o = { value: r };
if (this.#g && this.#y) {
const s = this.#g[t], i = this.#y[t];
if (s && i) {
const l = s - (Tr.now() - i);
o.ttl = l, o.start = Date.now();
}
}
return this.#w && (o.size = this.#w[t]), o;
}
dump() {
const e = [];
for (const t of this.#C({ allowStale: !0 })) {
const n = this.#n[t], r = this.#e[t], o = this.#t(r) ? r.__staleWhileFetching : r;
if (o === void 0 || n === void 0) continue;
const s = { value: o };
if (this.#g && this.#y) {
s.ttl = this.#g[t];
const i = Tr.now() - this.#y[t];
s.start = Math.floor(Date.now() - i);
}
this.#w && (s.size = this.#w[t]), e.unshift([n, s]);
}
return e;
}
load(e) {
this.clear();
for (const [t, n] of e) {
if (n.start) {
const r = Date.now() - n.start;
n.start = Tr.now() - r;
}
this.set(t, n.value, n);
}
}
set(e, t, n = {}) {
if (t === void 0) return this.delete(e), this;
const { ttl: r = this.ttl, start: o, noDisposeOnSet: s = this.noDisposeOnSet, sizeCalculation: i = this.sizeCalculation, status: l } = n;
let { noUpdateTTL: c = this.noUpdateTTL } = n;
const h = this.#P(e, t, n.size || 0, i);
if (this.maxEntrySize && h > this.maxEntrySize) return l && (l.set = "miss", l.maxEntrySizeExceeded = !0), this.#v(e, "set"), this;
let u = this.#o === 0 ? void 0 : this.#r.get(e);
if (u === void 0) u = this.#o === 0 ? this.#s : this.#S.length !== 0 ? this.#S.pop() : this.#o === this.#l ? this.#D(!1) : this.#o, this.#n[u] = e, this.#e[u] = t, this.#r.set(e, u), this.#c[this.#s] = u, this.#d[u] = this.#s, this.#s = u, this.#o++, this.#O(u, h, l), l && (l.set = "add"), c = !1, this.#k && this.#R?.(t, e, "add");
else {
this.#T(u);
const d = this.#e[u];
if (t !== d) {
if (this.#I && this.#t(d)) {
d.__abortController.abort(new Error("replaced"));
const { __staleWhileFetching: g } = d;
g === void 0 || s || (this.#E && this.#f?.(g, e, "set"), this.#h && this.#i?.push([g, e, "set"]));
} else s || (this.#E && this.#f?.(d, e, "set"), this.#h && this.#i?.push([d, e, "set"]));
if (this.#M(u), this.#O(u, h, l), this.#e[u] = t, l) {
l.set = "replace";
const g = d && this.#t(d) ? d.__staleWhileFetching : d;
g !== void 0 && (l.oldValue = g);
}
} else l && (l.set = "update");
this.#k && this.onInsert?.(t, e, t === d ? "update" : "replace");
}
if (r === 0 || this.#g || this.#B(), this.#g && (c || this.#z(u, r, o), l && this.#x(l, u)), !s && this.#h && this.#i) {
const d = this.#i;
let g;
for (; g = d?.shift(); ) this.#p?.(...g);
}
return this;
}
pop() {
try {
for (; this.#o; ) {
const e = this.#e[this.#a];
if (this.#D(!0), this.#t(e)) {
if (e.__staleWhileFetching) return e.__staleWhileFetching;
} else if (e !== void 0) return e;
}
} finally {
if (this.#h && this.#i) {
const e = this.#i;
let t;
for (; t = e?.shift(); ) this.#p?.(...t);
}
}
}
#D(e) {
const t = this.#a, n = this.#n[t], r = this.#e[t];
return this.#I && this.#t(r) ? r.__abortController.abort(new Error("evicted")) : (this.#E || this.#h) && (this.#E && this.#f?.(r, n, "evict"), this.#h && this.#i?.push([r, n, "evict"])), this.#M(t), e && (this.#n[t] = void 0, this.#e[t] = void 0, this.#S.push(t)), this.#o === 1 ? (this.#a = this.#s = 0, this.#S.length = 0) : this.#a = this.#c[t], this.#r.delete(n), this.#o--, t;
}
has(e, t = {}) {
const { updateAgeOnHas: n = this.updateAgeOnHas, status: r } = t, o = this.#r.get(e);
if (o !== void 0) {
const s = this.#e[o];
if (this.#t(s) && s.__staleWhileFetching === void 0) return !1;
if (!this.#m(o)) return n && this.#A(o), r && (r.has = "hit", this.#x(r, o)), !0;
r && (r.has = "stale", this.#x(r, o));
} else r && (r.has = "miss");
return !1;
}
peek(e, t = {}) {
const { allowStale: n = this.allowStale } = t, r = this.#r.get(e);
if (r === void 0 || !n && this.#m(r)) return;
const o = this.#e[r];
return this.#t(o) ? o.__staleWhileFetching : o;
}
#L(e, t, n, r) {
const o = t === void 0 ? void 0 : this.#e[t];
if (this.#t(o)) return o;
const s = new Mi(), { signal: i } = n;
i?.addEventListener("abort", () => s.abort(i.reason), { signal: s.signal });
const l = { signal: s.signal, options: n, context: r }, c = (g, m = !1) => {
const { aborted: f } = s.signal, _ = n.ignoreFetchAbort && g !== void 0;
if (n.status && (f && !m ? (n.status.fetchAborted = !0, n.status.fetchError = s.signal.reason, _ && (n.status.fetchAbortIgnored = !0)) : n.status.fetchResolved = !0), f && !_ && !m) return h(s.signal.reason);
const p = u;
return this.#e[t] === u && (g === void 0 ? p.__staleWhileFetching ? this.#e[t] = p.__staleWhileFetching : this.#v(e, "fetch") : (n.status && (n.status.fetchUpdated = !0), this.set(e, g, l.options))), g;
}, h = (g) => {
const { aborted: m } = s.signal, f = m && n.allowStaleOnFetchAbort, _ = f || n.allowStaleOnFetchRejection, p = _ || n.noDeleteOnFetchRejection, S = u;
if (this.#e[t] === u && (!p || S.__staleWhileFetching === void 0 ? this.#v(e, "fetch") : f || (this.#e[t] = S.__staleWhileFetching)), _) return n.status && S.__staleWhileFetching !== void 0 && (n.status.returnedStale = !0), S.__staleWhileFetching;
if (S.__returned === S) throw g;
};
n.status && (n.status.fetchDispatched = !0);
const u = new Promise((g, m) => {
const f = this.#N?.(e, o, l);
f && f instanceof Promise && f.then((_) => g(_ === void 0 ? void 0 : _), m), s.signal.addEventListener("abort", () => {
n.ignoreFetchAbort && !n.allowStaleOnFetchAbort || (g(void 0), n.allowStaleOnFetchAbort && (g = (_) => c(_, !0)));
});
}).then(c, (g) => (n.status && (n.status.fetchRejected = !0, n.status.fetchError = g), h(g))), d = Object.assign(u, { __abortController: s, __staleWhileFetching: o, __returned: void 0 });
return t === void 0 ? (this.set(e, d, { ...l.options, status: void 0 }), t = this.#r.get(e)) : this.#e[t] = d, d;
}
#t(e) {
if (!this.#I) return !1;
const t = e;
return !!t && t instanceof Promise && t.hasOwnProperty("__staleWhileFetching") && t.__abortController instanceof Mi;
}
async fetch(e, t = {}) {
const { allowStale: n = this.allowStale, updateAgeOnGet: r = this.updateAgeOnGet, noDeleteOnStaleGet: o = this.noDeleteOnStaleGet, ttl: s = this.ttl, noDisposeOnSet: i = this.noDisposeOnSet, size: l = 0, sizeCalculation: c = this.sizeCalculation, noUpdateTTL: h = this.noUpdateTTL, noDeleteOnFetchRejection: u = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection: d = this.allowStaleOnFetchRejection, ignoreFetchAbort: g = this.ignoreFetchAbort, allowStaleOnFetchAbort: m = this.allowStaleOnFetchAbort, context: f, forceRefresh: _ = !1, status: p, signal: S } = t;
if (!this.#I) return p && (p.fetch = "get"), this.get(e, { allowStale: n, updateAgeOnGet: r, noDeleteOnStaleGet: o, status: p });
const E = { allowStale: n, updateAgeOnGet: r, noDeleteOnStaleGet: o, ttl: s, noDisposeOnSet: i, size: l, sizeCalculation: c, noUpdateTTL: h, noDeleteOnFetchRejection: u, allowStaleOnFetchRejection: d, allowStaleOnFetchAbort: m, ignoreFetchAbort: g, status: p, signal: S };
let y = this.#r.get(e);
if (y === void 0) {
p && (p.fetch = "miss");
const C = this.#L(e, y, E, f);
return C.__returned = C;
}
{
const C = this.#e[y];
if (this.#t(C)) {
const I = n && C.__staleWhileFetching !== void 0;
return p && (p.fetch = "inflight", I && (p.returnedStale = !0)), I ? C.__staleWhileFetching : C.__returned = C;
}
const w = this.#m(y);
if (!_ && !w) return p && (p.fetch = "hit"), this.#T(y), r && this.#A(y), p && this.#x(p, y), C;
const b = this.#L(e, y, E, f), x = b.__staleWhileFetching !== void 0 && n;
return p && (p.fetch = w ? "stale" : "refresh", x && w && (p.returnedStale = !0)), x ? b.__staleWhileFetching : b.__returned = b;
}
}
async forceFetch(e, t = {}) {
const n = await this.fetch(e, t);
if (n === void 0) throw new Error("fetch() returned undefined");
return n;
}
memo(e, t = {}) {
const n = this.#F;
if (!n) throw new Error("no memoMethod provided to constructor");
const { context: r, forceRefresh: o, ...s } = t, i = this.get(e, s);
if (!o && i !== void 0) return i;
const l = n(e, i, { options: s, context: r });
return this.set(e, l, s), l;
}
get(e, t = {}) {
const { allowStale: n = this.allowStale, updateAgeOnGet: r = this.updateAgeOnGet, noDeleteOnStaleGet: o = this.noDeleteOnStaleGet, status: s } = t, i = this.#r.get(e);
if (i !== void 0) {
const l = this.#e[i], c = this.#t(l);
return s && this.#x(s, i), this.#m(i) ? (s && (s.get = "stale"), c ? (s && n && l.__staleWhileFetching !== void 0 && (s.returnedStale = !0), n ? l.__staleWhileFetching : void 0) : (o || this.#v(e, "expire"), s && n && (s.returnedStale = !0), n ? l : void 0)) : (s && (s.get = "hit"), c ? l.__staleWhileFetching : (this.#T(i), r && this.#A(i), l));
}
s && (s.get = "miss");
}
#W(e, t) {
this.#d[t] = e, this.#c[e] = t;
}
#T(e) {
e !== this.#s && (e === this.#a ? this.#a = this.#c[e] : this.#W(this.#d[e], this.#c[e]), this.#W(this.#s, e), this.#s = e);
}
delete(e) {
return this.#v(e, "delete");
}
#v(e, t) {
let n = !1;
if (this.#o !== 0) {
const r = this.#r.get(e);
if (r !== void 0) if (n = !0, this.#o === 1) this.#j(t);
else {
this.#M(r);
const o = this.#e[r];
if (this.#t(o) ? o.__abortController.abort(new Error("deleted")) : (this.#E || this.#h) && (this.#E && this.#f?.(o, e, t), this.#h && this.#i?.push([o, e, t])), this.#r.delete(e), this.#n[r] = void 0, this.#e[r] = void 0, r === this.#s) this.#s = this.#d[r];
else if (r === this.#a) this.#a = this.#c[r];
else {
const s = this.#d[r];
this.#c[s] = this.#c[r];
const i = this.#c[r];
this.#d[i] = this.#d[r];
}
this.#o--, this.#S.push(r);
}
}
if (this.#h && this.#i?.length) {
const r = this.#i;
let o;
for (; o = r?.shift(); ) this.#p?.(...o);
}
return n;
}
clear() {
return this.#j("delete");
}
#j(e) {
for (const t of this.#b({ allowStale: !0 })) {
const n = this.#e[t];
if (this.#t(n)) n.__abortController.abort(new Error("deleted"));
else {
const r = this.#n[t];
this.#E && this.#f?.(n, r, e), this.#h && this.#i?.push([n, r, e]);
}
}
if (this.#r.clear(), this.#e.fill(void 0), this.#n.fill(void 0), this.#g && this.#y && (this.#g.fill(0), this.#y.fill(0)), this.#w && this.#w.fill(0), this.#a = 0, this.#s = 0, this.#S.length = 0, this.#_ = 0, this.#o = 0, this.#h && this.#i) {
const t = this.#i;
let n;
for (; n = t?.shift(); ) this.#p?.(...n);
}
}
}
var Te, _u;
(_u = Te || (Te = {})).CalcStatus = { Ready: "ready", Stale: "stale", Pending: "pending", Streaming: "streaming" }, _u.Content = { Values: "values", Formats: "formats", Formulas: "formula", Hyperlinks: "hyperlinks", Tables: "tables", Notes: "notes", Comments: "comments", Warnings: "warnings", Errors: "errors", Merges: "merges" };
class H0 {
constructor(e, t, n) {
if (!n) throw new Kt();
if (typeof n == "string" && (n = { address: n }), typeof n.address != "string") throw new Error("Invalid hyperlink");
this._t = e, this._r = t, this._p = n;
}
open(e, t) {
return this._r(this.getAddress(), null, e ?? this.getTarget(), t);
}
getTarget() {
let e = this._p.target;
return e || (this._p.address.startsWith("#") ? "_self" : "_blank");
}
getDisplayText() {
return this._t() ?? this.getAddress();
}
getAddress() {
return this._p.address ?? "";
}
getTooltip() {
return this._p.tooltip ?? null;
}
get isIHyperlink() {
return !0;
}
}
function Su(a) {
return !/^(-?\d|--)/.test(a);
}
function wu(a) {
const e = [];
let t = "", n = "", r = 7;
for (let o, s = 0; o = a.charAt(s); s++) if (/[a-zA-Z\d\xa0-\uffff_-]/.test(o) && r === 7) t += o;
else if (o === "\\" && r === 7) r = 6;
else if (o === " " && r === 7) {
if (t !== "") {
if (!Su(t)) return null;
e.push(t), t = "";
}
} else if (r === 6) /[0-9a-f]/i.test(o) ? (n += o, r = 8) : (t += o, r = 7);
else {
if (r !== 8) return null;
/[0-9a-f]/i.test(o) && n.length < 6 ? n += o : (t += String.fromCodePoint(parseInt(n, 16)), t += o, n = "", r = 7);
}
if (t !== "") {
if (!Su(t)) return null;
e.push(t);
}
return e.join(" ");
}
function yu(a, e) {
let t = e, n = "";
const r = { "font-family": [] };
for (let o, s = 0; o = a.charAt(s); s += 1) if (t !== 4 || o !== '"' && o !== "'") if (t === 3 && o === ",") t = 4, n = "";
else if (t === 4 && o === ",") {
const i = wu(n);
i && r["font-family"].push(i), n = "";
} else if (t === 5 && o === " ") /^(?:\+|-)?(?:[0-9]*\.)?[0-9]+(?:deg|grad|rad|turn)$/.test(n) ? (r["font-style"] += " " + n, n = "") : s -= 1, t = 1;
else if (t !== 1 || o !== " " && o !== "/") t === 2 && o === " " ? (/^(?:\+|-)?([0-9]*\.)?[0-9]+(?:em|ex|ch|rem|vh|vw|vmin|vmax|px|mm|cm|in|pt|pc|%)?$/.test(n) && (r["line-height"] = n), t = 4, n = "") : n += o;
else {
if (/^(?:(?:xx|x)-large|(?:xx|s)-small|small|large|medium)$/.test(n) || /^(?:larg|small)er$/.test(n) || /^(?:\+|-)?(?:[0-9]*\.)?[0-9]+(?:em|ex|ch|rem|vh|vw|vmin|vmax|px|mm|cm|in|pt|pc|%)$/.test(n)) t = o === "/" ? 2 : 4, r["font-size"] = n;
else if (/^italic$/.test(n)) r["font-style"] = n;
else if (/^oblique$/.test(n)) r["font-style"] = n, t = 5;
else if (/^small-caps$/.test(n)) r["font-variant"] = n;
else if (/^(?:bold(?:er)?|lighter|normal)$/.test(n)) r["font-weight"] = n;
else if (/^[+-]?(?:[0-9]*\.)?[0-9]+(?:e[+-]?(?:0|[1-9][0-9]*))?$/.test(n)) {
const i = parseFloat(n);
i >= 1 && i <= 1e3 && (r["font-weight"] = n);
} else /^(?:(?:ultra|extra|semi)-)?(?:condensed|expanded)$/.test(n) && (r["font-stretch"] = n);
n = "";
}
else {
let i = s + 1;
do
if (i = a.indexOf(o, i) + 1, !i) return null;
while (a.charAt(i - 2) === "\\");
r["font-family"].push(a.slice(s + 1, i - 1).replace(/\\('|")/g, "$1")), s = i - 1, t = 3, n = "";
}
if (t === 3 && !/^\s*$/.test(n)) return null;
if (t === 4) {
const o = wu(n);
o && r["font-family"].push(o);
}
return r;
}
const di = (a) => {
if (typeof a != "string") return null;
let e = function(o) {
const s = yu(o, 4);
return s !== null ? s["font-family"] : null;
}(a);
Array.isArray(e) && e.length === 0 && (e = null), e = e ? { "font-family": e } : function(o) {
const s = yu(o, 1);
return s !== null && s["font-size"] && s["font-family"].length ? s : null;
}(a);
let t = null, n = null, r = null;
if (e) {
let o = e["font-family"];
const s = o.shift();
s && (t = s), o.length > 0 && (n = o), e["font-size"] !== void 0 && (r = e["font-size"]);
}
return { family: t, fallbacks: n, size: r };
}, on = (a, e = !1) => a?.toHex(e)?.toString(!1).toLowerCase() ?? null, Eu = (a) => a == null ? null : F.roundAccurately(a, 2) + "pt", rm = (a, e) => {
let t = "";
const n = a && a !== te.UnderlineStyle.None;
return e && (t += "line-through"), n && e && (t += " "), n && (t += "underline", a !== !0 && a !== te.UnderlineStyle.Single && a !== te.UnderlineStyle.SingleAccounting || (t += " solid"), a !== te.UnderlineStyle.Double && a !== te.UnderlineStyle.DoubleAccounting || (t += " double")), t;
}, W0 = Object.freeze({ underline: te.UnderlineStyle.None, strike: !1 }), om = (a) => a ? (a = a.toLowerCase()) === "single" ? te.UnderlineStyle.Single : a === "double" ? te.UnderlineStyle.Double : a === "single-accounting" || a === "singleaccounting" ? te.UnderlineStyle.SingleAccounting : a === "double-accounting" || a === "doubleaccounting" ? te.UnderlineStyle.DoubleAccounting : te.UnderlineStyle.None : te.UnderlineStyle.None, Cu = (a) => a ? a.toLowerCase() : null, bu = (a) => a ? a === X.Overflow.Visible || a === X.Overflow.Clip || a === X.Overflow.Shrink ? "nowrap" : a === X.Overflow.Wrap ? "normal" : void 0 : null, Ti = (a, e) => {
let t = "";
if (a && (a.includes(" ") && (a = '"' + a + '"'), t = a), e) for (let n = 0; n < e.length; n++) t.length > 0 && (t += ", "), t += e[n];
return t;
}, vu = (a) => {
let e = "", t = !1, n = "";
for (let r = 0; r < a.length; r++) {
const o = a.charAt(r);
t && o !== "]" && o !== '"' ? e += o : o === '"' ? (e += "\\0022", t = !t) : ["[", "]", ",", "#", ".", "@", "/", ":", ";", "-", " "].includes(o) ? (e += "\\" + o, o === "[" ? t = !0 : o === "]" && (t = !1)) : ["(", ")"].includes(o) ? e += n === "_" ? "\\" + o : "\\\\\\" + o : ["$"].includes(o) ? e += "\\0022" + o + "\\0022" : e += o, n = o;
}
return '"' + e + '"';
}, j0 = "Thin", V0 = "Hairline", $0 = "Extra Light", G0 = "Ultra Light", U0 = "Light", xu = "Normal", J0 = "Regular", q0 = "Medium", K0 = "Semi Bold", X0 = "Demi Bold", Y0 = "Bold", Q0 = "Extra Bold", Z0 = "Ultra Bold", e_ = "Black", t_ = "Heavy", n_ = "Extra Black", r_ = "Ultra Black", o_ = "lighter", s_ = "normal", i_ = "bold", a_ = "bolder", Ve = /* @__PURE__ */ new Map();
Ve.set(F.textToKey(j0), 100), Ve.set(F.textToKey(V0), 100), Ve.set(F.textToKey($0), 200), Ve.set(F.textToKey(G0), 200), Ve.set(F.textToKey(U0), 300), Ve.set(F.textToKey(xu), 400), Ve.set(F.textToKey(J0), 400), Ve.set(F.textToKey(q0), 500), Ve.set(F.textToKey(K0), 600), Ve.set(F.textToKey(X0), 600), Ve.set(F.textToKey(xu), 400), Ve.set(F.textToKey(Y0), 700), Ve.set(F.textToKey(Q0), 800), Ve.set(F.textToKey(Z0), 800), Ve.set(F.textToKey(e_), 900), Ve.set(F.textToKey(t_), 900), Ve.set(F.textToKey(n_), 950), Ve.set(F.textToKey(r_), 950), Ve.set(F.textToKey(o_), 100), Ve.set(F.textToKey(s_), 400), Ve.set(F.textToKey(i_), 700), Ve.set(F.textToKey(a_), 700);
const l_ = "xx-small", c_ = "x-small", h_ = "small", u_ = "medium", d_ = "large", g_ = "x-large", m_ = "xx-large", f_ = "xxx-large", p_ = "smaller", __ = "larger", S_ = "math", w_ = new RegExp("^[0-9]*[.]?[0-9]+$", "g"), Bt = /* @__PURE__ */ new Map();
Bt.set(F.textToKey(l_), (a) => 0.4 * a), Bt.set(F.textToKey(c_), (a) => 0.5 * a), Bt.set(F.textToKey(h_), (a) => 0.6 * a), Bt.set(F.textToKey(u_), (a) => a), Bt.set(F.textToKey(d_), (a) => 1.1 * a), Bt.set(F.textToKey(g_), (a) => 1.25 * a), Bt.set(F.textToKey(m_), (a) => 1.5 * a), Bt.set(F.textToKey(f_), (a) => 2 * a), Bt.set(F.textToKey(p_), (a) => 0.9 * a), Bt.set(F.textToKey(__), (a) => 1.1 * a), Bt.set(F.textToKey(S_), (a) => a);
const qr = (a, e = 11, t = "pt") => {
if (!a) return null;
let n = e;
a = a.trim().toLowerCase();
const r = t === "pt" ? te.getDeviceScale() : 1, o = t === "pt" ? 1 : te.getDeviceScale();
if (w_.test(a)) {
const s = parseFloat(a);
isNaN(s) || (a = s + t);
}
if (a.endsWith("pt")) n = parseFloat(a.substring(0, a.length - 2).trim()) * o;
else if (a.endsWith("px")) n = parseFloat(a.substring(0, a.length - 2).trim()) / r;
else if (a.endsWith("em")) n = parseFloat(a.substring(0, a.length - 2).trim()) * e;
else if (a.endsWith("rem")) n = parseFloat(a.substring(0, a.length - 3).trim()) * e;
else if (a.endsWith("%")) n = parseFloat(a.substring(0, a.length - 1).trim()) / 100 * e;
else if (typeof a == "string") {
const s = F.textToKey(a), i = Bt.get(s);
if (i) return i(e);
}
return isNaN(n) ? null : n;
}, qe = /* @__PURE__ */ new Map();
qe.set(Y.BuiltInSheetPattern.None, { description: "None", cssKey: "none" }), qe.set(Y.BuiltInSheetPattern.Solid, { description: "Solid", cssKey: "solid" }), qe.set(Y.BuiltInSheetPattern.DarkGray, { description: "75% gray", cssKey: "gray-75" }), qe.set(Y.BuiltInSheetPattern.MediumGray, { description: "50% gray", cssKey: "gray-50" }), qe.set(Y.BuiltInSheetPattern.LightGray, { description: "25% gray", cssKey: "gray-25" }), qe.set(Y.BuiltInSheetPattern.Gray125, { description: "12.5% Gray", cssKey: "gray-125" }), qe.set(Y.BuiltInSheetPattern.Gray0625, { description: "6.25% Gray", cssKey: "gray-0625" }), qe.set(Y.BuiltInSheetPattern.DarkHorizontal, { description: "Horizontal Strip", cssKey: "horz-stripe" }), qe.set(Y.BuiltInSheetPattern.DarkVertical, { description: "Vertical Strip", cssKey: "vert-stripe" }), qe.set(Y.BuiltInSheetPattern.DarkDown, { description: "Reverse Diagonal Stripe", cssKey: "reverse-diag-stripe" }), qe.set(Y.BuiltInSheetPattern.DarkUp, { description: "Diagonal Strip", cssKey: "diag-stripe" }), qe.set(Y.BuiltInSheetPattern.DarkGrid, { description: "Diagonal Crosshatch", cssKey: "diag-cross" }), qe.set(Y.BuiltInSheetPattern.DarkTrellis, { description: "Thick Diagonal Crosshatch", cssKey: "thick-diag-cross" }), qe.set(Y.BuiltInSheetPattern.LightHorizontal, { description: "Thin Horizontal Stripe", cssKey: "thin-horz-stripe" }), qe.set(Y.BuiltInSheetPattern.LightVertical, { description: "Thin Vertical Stripe", cssKey: "thin-vert-stripe" }), qe.set(Y.BuiltInSheetPattern.LightDown, { description: "Thin Reverse Diagonal Stripe", cssKey: "thin-reverse-diag-stripe" }), qe.set(Y.BuiltInSheetPattern.LightUp, { description: "Thin Diagonal Stripe", cssKey: "thin-diag-stripe" }), qe.set(Y.BuiltInSheetPattern.LightGrid, { description: "Thin Horizontal Cross", cssKey: "thin-horz-cross" }), qe.set(Y.BuiltInSheetPattern.LightTrellis, { description: "Thin Diagonal Cross", cssKey: "thin-diag-cross" });
let gi = "";
const sm = /* @__PURE__ */ new Map();
qe.forEach((a, e) => {
gi.length > 0 && (gi += "|"), gi += "\\b" + a.cssKey + "\\b", sm.set(a.cssKey, e);
});
const y_ = new RegExp(`(\\s*(?:${gi}))`, "g"), E_ = (a) => {
if (!a) return null;
let e = a.toLowerCase();
e = e.replace(/;/, "");
let t = e.match(y_);
if (!t) return null;
let n = null;
t && t.length > 0 && (n = ((o) => {
if (!o) return null;
let s = e.indexOf(o);
return e = e.substring(0, s) + e.substring(s + o.length, e.length), o.trim();
})(t[0])), e = e.trim();
const r = e ? e.trim() : null;
return !n && !r ? null : { patternType: sm.get(n ?? "solid"), foreground: r ?? null };
}, im = (a, e = !1, t = null) => {
if (!a || !a.getStops() || a.getStops().length < 1) return null;
if (a.getStops().length === 1) return on(a.getStops()[0].getColor(), e);
let n = "";
for (let o = 0; o < a.getStops().length; o++) {
const s = a.getStops()[o];
n += on(s.getColor(), e) + " " + 100 * (s.getOffset() ?? o * (a.getStops().length - 1)) + "%", o < a.getStops().length - 1 && (n += ", ");
}
let r = a.getAngle() ?? 0;
if (a.getGradientType() === Y.GradientType.Path) {
const o = on(a.getStops()[0]?.getColor(), e), s = on((a.getStops()[1] ?? a.getStops()[0])?.getColor(), e), i = a.getFillTo() ?? { left: 0, top: 0, right: 0, bottom: 0 }, l = -1;
let c = `${100 - l}% ${100 - l}%`;
if (r = 315, i.left === 1 && i.right === 1 && i.right === 1 && i.bottom === 1) r = 135, c = `${l}% ${l}%`;
else if (i.top !== 0 && i.bottom !== 0 && i.left === 0 && i.right === 0) r = 225, c = `${100 - l}% ${l}%`;
else if (i.left === 1 && i.right !== 0 && i.top === 0 && i.bottom === 0) r = 45, c = `${l}% ${100 - l}%`;
else if (i.left !== 0 && i.right !== 0 && i.top !== 0 && i.bottom !== 0) return `radial-gradient(${n})`;
const h = 70;
return `conic-gradient(from ${r}deg at ${c}, ${o} 0deg, ${s} ${h / 2}deg,${s} ${360 - h / 2}deg, ${o} 360deg)`;
}
return `linear-gradient(${r}deg, ${n})`;
}, _t = /* @__PURE__ */ new Map();
_t.set(U.StrokeStyle.None, { size: null, cssKey: "none" }), _t.set(U.StrokeStyle.DashDot, { size: 0.5, cssKey: "dot-dash" }), _t.set(U.StrokeStyle.DashDotDot, { size: 0.5, cssKey: "dot-dot-dash" }), _t.set(U.StrokeStyle.Dashed, { size: 0.5, cssKey: "dashed" }), _t.set(U.StrokeStyle.MediumDashed, { size: 1, cssKey: "dashed" }), _t.set(U.StrokeStyle.Dotted, { size: 0.5, cssKey: "dotted" }), _t.set(U.StrokeStyle.MediumDashDot, { size: 1, cssKey: "dot-dash" }), _t.set(U.StrokeStyle.MediumDashDotDot, { size: 1, cssKey: "dot-dot-dash" }), _t.set(U.StrokeStyle.Hair, { size: 0.5, cssKey: "hairline" }), _t.set(U.StrokeStyle.Thin, { size: 0.5, cssKey: "solid" }), _t.set(U.StrokeStyle.Thick, { size: 1.5, cssKey: "solid" }), _t.set(U.StrokeStyle.Medium, { size: 1, cssKey: "solid" }), _t.set(U.StrokeStyle.Double, { size: 2, cssKey: "double" }), _t.set(U.StrokeStyle.SlantDashDot, { size: 1, cssKey: "dot-dash-slanted" });
const nr = (a) => {
if (!a) return "none";
const e = _t.get(a.getStyle());
if (!e) return null;
if (e.cssKey === "none") return e.cssKey;
let t = ((n, r = !1) => n?.toRGBA(r).toString(!1) ?? null)(a?.getColor());
return t = t ? " " + t : "", `${e.size !== null ? `${e.size}pt ` : ""}${e.cssKey}${t}`;
};
let Ni = [];
const Iu = /* @__PURE__ */ new Set(), Bl = /* @__PURE__ */ new Map(), Vo = (a, e) => {
let t = a.size !== null ? `${a.size.toString()} ${a.cssKey}` : a.cssKey;
Bl.set(t, e), Iu.has(a.cssKey) || (Ni.push(a.cssKey), Iu.add(a.cssKey));
};
_t.forEach(Vo);
const Pa = Object.keys(U.StrokeStyle);
for (let a = 0; a < Pa.length; a++)
Vo({ size: null, cssKey: Pa[a].toLowerCase() }, U.StrokeStyle[Pa[a]]);
Vo({ size: null, cssKey: "double" }, U.StrokeStyle.Double), Vo({ size: null, cssKey: "solid" }, U.StrokeStyle.Medium), Vo({ size: null, cssKey: "hidden" }, U.StrokeStyle.None), Ni.sort((a, e) => e.length - a.length);
let mi = "";
for (let a = 0; a < Ni.length; a++) mi.length > 0 && (mi += "|"), mi += "\\b" + Ni[a] + "\\b";
const C_ = new RegExp(`(\\s*(?:${mi}))`, "g"), b_ = new RegExp("(\\s*[0-9]*[.]?[0-9]+(?:pt|px){0,1})", "g"), am = (a) => {
if (!a) return null;
let e = a.toLowerCase(), t = e.match(C_);
if (!t) return null;
const n = (c) => {
if (!c) return null;
let h = e.indexOf(c);
return e = e.substring(0, h) + e.substring(h + c.length, e.length).trim(), c.trim();
};
let r = null;
if (t && t.length > 0 && (r = n(t[0])), !r) return null;
let o = null;
if (t = e.match(b_), t && t.length > 0) {
let c = n(t[0]);
o = parseFloat(c.substring(0, c.length - 2));
}
e = e.trim();
const s = e ? e.trim() : null;
let i = o === null ? r : `${o.toString()} ${r}`, l = Bl.get(i);
return l || (l = Bl.get(r)), l ? { color: s, style: l } : null;
}, v_ = "start", x_ = "end", I_ = "left", R_ = "right", A_ = "center", M_ = "justify", T_ = "justify-all", N_ = "baseline", F_ = "top", k_ = "middle", O_ = "bottom", D_ = "sub", L_ = "text-top", B_ = "justify", z_ = "distributed", Hn = /* @__PURE__ */ new Map();
Hn.set(F.textToKey(v_), X.HorizontalAlignment.Left), Hn.set(F.textToKey(I_), X.HorizontalAlignment.Left), Hn.set(F.textToKey(x_), X.HorizontalAlignment.Right), Hn.set(F.textToKey(R_), X.HorizontalAlignment.Right), Hn.set(F.textToKey(A_), X.HorizontalAlignment.Center), Hn.set(F.textToKey(M_), X.HorizontalAlignment.Justify), Hn.set(F.textToKey(T_), X.HorizontalAlignment.Justify);
const fn = /* @__PURE__ */ new Map();
fn.set(F.textToKey(N_), X.VerticalAlignment.Bottom), fn.set(F.textToKey(F_), X.VerticalAlignment.Top), fn.set(F.textToKey(k_), X.VerticalAlignment.Center), fn.set(F.textToKey(O_), X.VerticalAlignment.Bottom), fn.set(F.textToKey(D_), X.VerticalAlignment.Bottom), fn.set(F.textToKey(L_), X.VerticalAlignment.Top), fn.set(F.textToKey(B_), X.VerticalAlignment.Justify), fn.set(F.textToKey(z_), X.VerticalAlignment.Distributed);
const lm = (a, e) => {
if (a instanceof Qe) return { color: a };
if (typeof a == "string") try {
return { color: a === "none" || a === "transparent" ? null : e(a) };
} catch (t) {
throw t;
}
return a;
}, Ko = { shorthand: (a, e) => {
if (!a || a === "none" || a === "transparent") return null;
try {
return e.parseColor(a).toString();
} catch (t) {
console.warn("error", t);
}
return a;
}, merge: (a, e, t) => a }, Ln = { shorthand: (a, e) => {
if (typeof a == "string" && (a = am(a)), !a) return null;
const t = {};
return a.style && (t.style = a.style), a.color && (t.color = a.color), a.isIStroke ? a.getProperties() : t;
}, properties: { color: Ko } }, Ru = { shorthand: (a, e) => a === "none" || a === "transparent" || typeof a == "object" && Object.keys(a).length === 0 ? { type: Y.Type.None } : (a.getType?.(), Y.Type.None, a) }, Au = { shorthand: (a, e) => (typeof (a = lm(a, e.parseColor.bind(e))) == "object" && a.color && (a.type = Y.Type.Solid), a), merge: (a, e, t) => a.color ? a : (e?.toJSON && (e = e.toJSON()), e?.type === Y.Type.Solid ? { ...e } : e?.type === Y.Type.Gradient ? { type: Y.Type.Solid, color: e?.stops?.[0]?.color ?? t.parseColor(N.Scheme.Bg1) } : e?.type === Y.Type.Pattern ? { type: Y.Type.Solid, color: e?.foreground ?? t.parseColor(N.Scheme.Bg1) } : a ? { ...a } : null), properties: { color: Ko } }, Mu = { shorthand: (a, e) => (typeof a == "object" && a.stops && (a.type = Y.Type.Gradient), a), merge: (a, e, t) => a.stops ? a : (e?.toJSON && (e = e.toJSON()), e?.type === Y.Type.Gradient ? { ...e } : e?.type === Y.Type.Solid ? { type: Y.Type.Gradient, stops: [{ offset: 0, color: e?.color ?? N.Scheme.Accent1 }, { offset: 1, color: N.Scheme.Bg1 }] } : e?.type === Y.Type.Pattern ? { type: Y.Type.Gradient, stops: [{ offset: 0, color: e?.foreground ?? N.Scheme.Bg1 }, { offset: 1, color: e?.background ?? N.Scheme.Accent1 }] } : a ? { ...a } : null), properties: { stops: { shorthand: (a, e) => a, arrayType: { shorthand: (a, e) => a = lm(a, e.parseColor.bind(e)), properties: { color: Ko } } } } }, Tu = { shorthand: (a, e) => {
if (typeof a == "object") {
const t = a;
(t.foreground || t.background || t.patternType) && (t.type = Y.Type.Pattern, t.patternType = t.patternType ?? Y.BuiltInSheetPattern.Solid);
}
return a;
}, merge: (a, e, t) => {
if (a.background && a.foreground) return a;
e?.toJSON && (e = e.toJSON());
const n = Y.BuiltInSheetPattern.MediumGray;
return e?.type === Y.Type.Pattern ? { ...e, ...a } : e?.type === Y.Type.Solid ? { patternType: n, ...a, foreground: e?.color ?? N.Named.WindowText, background: N.Scheme.Bg1 } : e?.type === Y.Type.Gradient ? { patternType: n, ...a, foreground: e?.stops?.[0]?.color ?? N.Named.WindowText, background: e?.stops?.[1]?.color ?? N.Scheme.Bg1 } : a ? { type: Y.Type.Pattern, patternType: Y.BuiltInSheetPattern.Solid, foreground: N.Named.WindowText, background: N.Scheme.Bg1, ...a } : null;
}, properties: { foreground: Ko, background: Ko } }, Ge = { properties: { font: { shorthand: (a, e) => {
if (typeof a == "string") {
const t = di(a);
if (t) {
const n = {};
if (t.family && (n.family = t.family), t.fallbacks && (n.fallbacks = t.fallbacks), t.size && (n.size = qr(t.size)), Object.keys(t).length > 0) return n;
}
}
return a;
}, properties: { family: { shorthand: (a, e) => di(a)?.family ?? null }, fallbacks: { shorthand: (a, e) => {
if (typeof a != "string") return a;
let t = di(a);
if (!t) return null;
let n = [t.family];
return t.fallbacks && (n = n.concat(t.fallbacks)), n;
} }, size: { shorthand: (a, e) => {
let t = a;
return typeof a == "string" && (t = qr(a, e.getNormal().getFont().getSize())), isNaN(t) || typeof t != "number" ? null : (t = Math.max(1, Math.min(F.roundAccurately(t, 1), 409)), t);
} }, weight: { shorthand: (a, e) => {
if (typeof a != "string") return a;
const t = ((n) => {
let r = 400;
if (r = typeof n == "number" ? n : parseFloat(n), !isNaN(r)) return r;
if (typeof n == "string") {
const o = F.textToKey(n), s = Ve.get(o);
if (s) return s;
}
return r;
})(a);
return isNaN(t) || typeof t != "number" ? null : t;
} }, underline: { shorthand: (a, e) => a ? a === !0 ? te.UnderlineStyle.Single : om(a) : te.UnderlineStyle.None } } }, fill: { shorthand: (a, e) => {
const t = [Ru, Au, Mu, Tu];
for (let n = 0; n < t.length; n++) {
let r = t[n]?.shorthand?.(a, e);
if (r?.type) return r;
}
return a;
}, getSubType: (a) => a.type === Y.Type.None ? Ru : a.type === Y.Type.Solid ? Au : a.type === Y.Type.Gradient ? Mu : a.type === Y.Type.Pattern ? Tu : null }, alignment: { properties: { indent: { shorthand: (a, e) => {
let t = a;
return typeof a == "string" && (t = parseFloat(a)), isNaN(t) || typeof t != "number" ? null : t;
} }, rotation: { shorthand: (a, e) => {
let t = a;
return typeof a == "string" && (t = parseFloat(a)), isNaN(t) || typeof t != "number" ? null : (t %= 360, t < 0 && (t += 360), t);
} } } }, border: { shorthand: (a, e) => {
if (typeof a == "string") {
const t = am(a);
return { left: t, right: t, top: t, bottom: t, horizontal: null, vertical: null, diagonalUp: null, diagonalDown: null };
}
return a.isIBorder ? a.getProperties() : a;
}, properties: { top: Ln, left: Ln, right: Ln, bottom: Ln, horizontal: Ln, vertical: Ln, diagonalUp: Ln, diagonalDown: Ln } }, numberFormat: { shorthand: (a, e) => {
if (typeof a == "string") {
let t = Nt.Styles.lookupDefault(a);
return t !== void 0 ? t : a;
}
return typeof a == "number" ? ec(a) : null;
} } } }, P_ = { properties: { style: Ge } }, H_ = Object.freeze({ displayText: "", conditionalColor: null, repeatChars: F.EmptyArray, spacingChars: F.EmptyArray, repeatPlaceholder: null, formattedRuns: Object.freeze({ runs: F.EmptyArray, length: 0, width: 0, lastRepeatIndex: -1 }), canWrap: !1, asDate: null, isDateFormat: !1, isTimeFormat: !1, isDate1904: !1 }), cm = (a, e, t, n, r, o = !1) => {
if (a == null) return H_;
let s = "", i = null, l = null, c = null;
if (t === q.Error) s = a.getLabel();
else if (t === q.RichData) s = "(Rich Object)";
else if (t === q.Boolean) s = a ? "TRUE" : "FALSE";
else if (n) try {
s = Kl(n, a, { date1904: o, spacingCharacter: "", digitCharacter: "", onRepeatChar: (b, x) => {
l || (l = []), l.push({ offset: b, char: x });
}, onSpacingChar: (b, x) => {
c || (c = []), c.push({ offset: b, char: x });
}, onDigitChar: (b) => {
c || (c = []), c.push({ offset: b, char: "0" });
} });
} catch {
}
const h = ts(n), u = Wi(n), d = h || u ? no(a, o) : null;
(h || u) && parseFloat(a) < 0 && (i = "#", s = i.repeat(5));
let g = null;
const m = e.getAlignment(), f = m.getHorizontal(), _ = m.getVertical(), p = m.getOverflow(), S = !(t !== q.String || f === X.HorizontalAlignment.Fill || l !== null && l.length !== 0 || p !== X.Overflow.Wrap && f !== X.HorizontalAlignment.Justify && f !== X.HorizontalAlignment.Distributed && _ !== X.VerticalAlignment.Justify && _ !== X.VerticalAlignment.Distributed);
let E = s;
S || t !== q.String || (E = E.replaceAll(/\n/g, ""));
const y = c?.length > 0 || l?.length > 0;
if (p !== X.Overflow.Wrap || y) {
const b = e.getFont();
let x = b.getSize();
b.isSuperSub() && (x *= b.getSuperSubScale());
let I = [];
for (let P = 0; P < c?.length; P++) {
const B = c[P], H = e.measureText(B.char, x).width;
I.push({ ...B, type: "spacing", width: H });
}
if (l?.length > 0) {
const P = l[l.length - 1], B = e.measureText(P.char, x).width;
I.push({ ...P, type: "repeat", width: B });
}
I = I.sort((P, B) => P.offset - B.offset);
let v = [], R = 0, A = 0, M = -1, T = -1;
const k = (P) => {
const B = { type: "text", width: e.measureText(P, x).width, text: P };
v.push(B), A += B.width, R += P.length;
};
for (let P = 0; P < I.length; P++) {
const B = I[P];
if (T !== B.offset) {
const z = E.substring(R, B.offset);
z && k(z);
}
const H = { type: B.type, width: B.width, text: B.char };
B.type !== "repeat" ? A += H.width : M = v.length, v.push(H), T = B.offset;
}
if (R < E.length) {
let P = E.substring(R, E.length);
P && k(P);
}
g = { runs: Object.freeze(v), length: R, width: A, lastRepeatIndex: M };
}
const C = ep(n, a), w = { displayText: s ?? "", conditionalColor: C ? r(C) : null, repeatChars: l ?? F.EmptyArray, spacingChars: c ?? F.EmptyArray, repeatPlaceholder: i, formattedRuns: g, canWrap: S, asDate: d, isDateFormat: h, isTimeFormat: u, isDate1904: o };
return Object.freeze(w);
}, Je = Object.freeze({ fallbacks: F.EmptyArray, weight: 400, style: te.Style.Normal, fill: N.Scheme.Tx1, letterSpacing: null, underline: te.UnderlineStyle.None, strike: !1, scheme: te.Scheme.Minor, verticalAlign: te.VerticalAlignment.Baseline, shadow: !1, outline: !1, extend: !1 }), Bn = Object.freeze({ style: U.StrokeStyle.None, color: N.Scheme.Tx1 }), W_ = Object.freeze({ [U.Edge.Top]: Bn, [U.Edge.Left]: Bn, [U.Edge.Bottom]: Bn, [U.Edge.Right]: Bn, [U.Edge.Horizontal]: Bn, [U.Edge.Vertical]: Bn, [U.Edge.DiagonalUp]: Bn, [U.Edge.DiagonalDown]: Bn }), j_ = Object.freeze({ horizontal: X.HorizontalAlignment.General, vertical: X.VerticalAlignment.Bottom, indent: 0, relativeIndent: 0, overflow: X.Overflow.Visible, rotation: 0, stacked: !1, quotePrefix: !1, justifyLastLine: !1, readingOrder: X.ReadingDirection.Auto, readingDirection: X.ReadingDirection.Auto }), V_ = Object.freeze({ locked: !1, formulaHidden: !1 }), hm = Object.freeze({ fill: { type: Y.Type.None }, numberFormat: "General", alignment: j_, font: Je, border: W_, protection: V_, quotePrefix: !1, namedStyle: null }), $_ = (() => {
const a = [{ named: ce.BuiltInName.Normal }, { named: ce.BuiltInName.RowLevel }, { named: ce.BuiltInName.ColLevel }, { named: ce.BuiltInName.Comma, numberFormat: '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)' }, { named: ce.BuiltInName.Currency, numberFormat: '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)' }, { named: ce.BuiltInName.Percent, numberFormat: "0%" }, { named: ce.BuiltInName.Comma0, numberFormat: '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)' }, { named: ce.BuiltInName.Currency0, numberFormat: '_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)' }, { named: ce.BuiltInName.Hyperlink, font: { ...Je, fill: N.Scheme.Hlink, underline: te.UnderlineStyle.Single } }, { named: ce.BuiltInName.FollowedHyperlink, font: { ...Je, fill: N.Scheme.FolHlink, underline: te.UnderlineStyle.Single } }, { named: ce.BuiltInName.Note, fill: "FFFFFFCC", font: { ...Je, style: te.Style.Normal, fill: N.Scheme.Tx1 }, border: { left: { style: U.StrokeStyle.Thin, color: "FFB2B2B2" }, top: { style: U.StrokeStyle.Thin, color: "FFB2B2B2" }, right: { style: U.StrokeStyle.Thin, color: "FFB2B2B2" }, bottom: { style: U.StrokeStyle.Thin, color: "FFB2B2B2" } } }, { named: ce.BuiltInName.WarningText, font: { ...Je, fill: "FFFF0000" } }, { named: ce.BuiltInName.Unknown12 }, { named: ce.BuiltInName.Unknown13 }, { named: ce.BuiltInName.Unknown14 }, { named: ce.BuiltInName.Title, font: { ...Je, size: 18, fill: N.Scheme.Tx2 } }, { named: ce.BuiltInName.Heading1, font: { ...Je, size: 15, weight: "bold", fill: N.Scheme.Tx2 }, border: { bottom: { style: U.StrokeStyle.Thick, color: N.Scheme.Accent1 } } }, { named: ce.BuiltInName.Heading2, font: { ...Je, size: 13, weight: "bold", fill: N.Scheme.Tx2 }, border: { bottom: { style: U.StrokeStyle.Thick, color: "accent1 lumMod 40, lumOff 60" } } }, { named: ce.BuiltInName.Heading3, font: { ...Je, weight: "bold", fill: N.Scheme.Tx2 }, border: { bottom: { style: U.StrokeStyle.Medium, color: "accent1 lumMod 40, lumOff 60" } } }, { named: ce.BuiltInName.Heading4, font: { weight: "bold", fill: N.Scheme.Tx2, ...Je } }, { named: ce.BuiltInName.Input, fill: "FFFFCC99", font: { ...Je, fill: "FF3F3F76" }, border: { left: { style: U.StrokeStyle.Thin, color: "FF7F7F7F" }, top: { style: U.StrokeStyle.Thin, color: "FF7F7F7F" }, right: { style: U.StrokeStyle.Thin, color: "FF7F7F7F" }, bottom: { style: U.StrokeStyle.Thin, color: "FF7F7F7F" } } }, { named: ce.BuiltInName.Output, fill: "FFF2F2F2", font: { ...Je, fill: "FF3F3F3F" }, border: { left: { style: U.StrokeStyle.Thin, color: "FF3F3F3F" }, top: { style: U.StrokeStyle.Thin, color: "FF3F3F3F" }, right: { style: U.StrokeStyle.Thin, color: "FF3F3F3F" }, bottom: { style: U.StrokeStyle.Thin, color: "FF3F3F3F" } } }, { named: ce.BuiltInName.Calculation, fill: "FFF2F2F2", font: { ...Je, fill: "FFFA7D00" }, border: { left: { style: U.StrokeStyle.Thin, color: "FF7F7F7F" }, top: { style: U.StrokeStyle.Thin, color: "FF7F7F7F" }, right: { style: U.StrokeStyle.Thin, color: "FF7F7F7F" }, bottom: { style: U.StrokeStyle.Thin, color: "FF7F7F7F" } } }, { named: ce.BuiltInName.CheckCell, fill: "FFA5A5A5", font: { ...Je, fill: N.Scheme.Bg1 }, border: { left: { style: U.StrokeStyle.Double, color: "FF3F3F3F" }, top: { style: U.StrokeStyle.Double, color: "FF3F3F3F" }, right: { style: U.StrokeStyle.Double, color: "FF3F3F3F" }, bottom: { style: U.StrokeStyle.Double, color: "FF3F3F3F" } } }, { named: ce.BuiltInName.LinkedCell, font: { ...Je, fill: "FFFA7D00" }, border: { bottom: { style: U.StrokeStyle.Double, color: "FFFF8001" } } }, { named: ce.BuiltInName.Total, font: { ...Je, weight: "bold", fill: N.Scheme.Tx1 }, border: { top: { style: U.StrokeStyle.Thin, color: N.Scheme.Accent1 }, bottom: { style: U.StrokeStyle.Double, color: N.Scheme.Accent1 } } }, { named: ce.BuiltInName.Good, fill: "FFC6EFCE", font: { ...Je, fill: "FF006100" } }, { named: ce.BuiltInName.Bad, fill: "FFFFC7CE", font: { ...Je, fill: "FF9C0006" } }, { named: ce.BuiltInName.Neutral, fill: "FFFFEB9C", font: { ...Je, fill: "FF9C5700" } }, { named: ce.BuiltInName.Accent1 }, { named: ce.BuiltInName.Accent1_20 }, { named: ce.BuiltInName.Accent1_40 }, { named: ce.BuiltInName.Accent1_60 }, { named: ce.BuiltInName.Accent2 }, { named: ce.BuiltInName.Accent2_20 }, { named: ce.BuiltInName.Accent2_40 }, { named: ce.BuiltInName.Accent2_60 }, { named: ce.BuiltInName.Accent3 }, { named: ce.BuiltInName.Accent3_20 }, { named: ce.BuiltInName.Accent3_40 }, { named: ce.BuiltInName.Accent3_60 }, { named: ce.BuiltInName.Accent4 }, { named: ce.BuiltInName.Accent4_20 }, { named: ce.BuiltInName.Accent4_40 }, { named: ce.BuiltInName.Accent4_60 }, { named: ce.BuiltInName.Accent5 }, { named: ce.BuiltInName.Accent5_20 }, { named: ce.BuiltInName.Accent5_40 }, { named: ce.BuiltInName.Accent5_60 }, { named: ce.BuiltInName.Accent6 }, { named: ce.BuiltInName.Accent6_20 }, { named: ce.BuiltInName.Accent6_40 }, { named: ce.BuiltInName.Accent6_60 }, { named: ce.BuiltInName.ExplanatoryText, font: { ...Je, style: te.Style.Italic, fill: "FF7F7F7F" } }];
for (let e = 29; e <= 52; e++) {
const t = (e - 29) % 4, n = Math.floor((e - 29) / 4);
let r = "";
t === 1 ? r = " lumMod 20, lumOff 80" : t === 2 ? r = " lumMod 40, lumOff 60" : t === 3 && (r = " lumMod 60, lumOff 40"), a[e].fill = `accent${n + 1}${r}`, a[e].font = { fill: t === 0 ? N.Scheme.Bg1 : N.Scheme.Tx1, ...Je };
}
return F.deepFreeze(a);
})(), G_ = new class {
_svgImage(a, e, t, n = 8) {
return { backgroundImage: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='${n}' height='${n}' viewBox='0 0 ${n} ${n}' shape-rendering='crispEdges' %3E%3Cpath d='${t}' stroke='${a}' %3E%3C/path%3E%3C/svg%3E")`, backgroundRepeat: "repeat", backgroundSize: `${n}px ${n}px`, backgroundPositionX: "0px", backgroundPositionY: "0px", backgroundPosition: "" + -n, backgroundColor: e };
}
toCSS(a, e, t) {
return a && a !== Y.BuiltInSheetPattern.None ? a === Y.BuiltInSheetPattern.Solid ? { background: t } : a === Y.BuiltInSheetPattern.Gray0625 ? this._svgImage(e, t, "M 0.5 0.5 L 0.5 1.5 M 0.5 4.5 L 0.5 5.5 M 4.5 2.5 L 4.5 3.5 M 4.5 6.5 L 4.5 7.5", 8) : a === Y.BuiltInSheetPattern.LightGray ? this._svgImage(e, t, "M 0.5 0.5 L 0.5 1.5 M 0.5 2.5 L 0.5 3.5 M 2.5 -0.5 L 2.5 0.5 M 2.5 1.5 L 2.5 2.5 M 2.5 3.5 L 2.5 4.5", 4) : a === Y.BuiltInSheetPattern.MediumGray ? this._svgImage(e, t, "M 0.5 0.5 L 0.5 1.5 M 1.5 1.5 L 1.5 2.5 M 1.5 -0.5 L 1.5 0.5 M -0.5 -0.5 L -0.5 0.5", 2) : a === Y.BuiltInSheetPattern.DarkGray ? this._svgImage(e, t, "M 0 0 L 0 4 M 1 1 L 1 2 M 1 3 L 1 4 M 2 0 L 2 4 M 3 0.5 L 3 1.5 M 3 2.5 L 3 3.5 M 4 0 L 4 4", 4) : a === Y.BuiltInSheetPattern.LightHorizontal ? this._svgImage(e, t, "M 0 2 L 4 2", 4) : a === Y.BuiltInSheetPattern.DarkHorizontal ? this._svgImage(e, t, "M 0 2 L 4 2 M 0 3 L 4 3", 4) : a === Y.BuiltInSheetPattern.LightVertical ? this._svgImage(e, t, "M 2 0 L 2 4", 4) : a === Y.BuiltInSheetPattern.DarkVertical ? this._svgImage(e, t, "M 2 0 L 2 4 M 3 0 L 3 4", 4) : a === Y.BuiltInSheetPattern.LightUp ? this._svgImage(e, t, "M 0.5 0.5 L 0.5 1.5 M 1.5 3.5 L 1.5 4.5 M 1.5 -0.5 L 1.5 0.5 M 2.5 2.5 L 2.5 3.5 M 3.5 1.5 L 3.5 2.5", 4) : a === Y.BuiltInSheetPattern.DarkUp ? this._svgImage(e, t, "M 0.5 -0.5 L 0.5 1.5 M 0.5 3.5 L 0.5 4.5 M 1.5 2.5 L 1.5 4.5 M 2.5 1.5 L 2.5 3.5 M 3.5 0.5 L 3.5 2.5 M 1.5 -0.5 L 1.5 0.5", 4) : a === Y.BuiltInSheetPattern.LightDown ? this._svgImage(e, t, "M 0.5 0 L 0.5 1 M 1.5 1 L 1.5 2 M 2.5 2 L 2.5 3 M 3.5 3 L 3.5 4", 4) : a === Y.BuiltInSheetPattern.DarkDown ? this._svgImage(e, t, "M 0.5 -0.5 L 0.5 2 M 1.5 1 L 1.5 3 M 2.5 2 L 2.5 4 M 3.5 3 L 3.5 5 M 3.5 -0.5 L 3.5 1.0", 4) : a === Y.BuiltInSheetPattern.LightGrid ? this._svgImage(e, t, "M 1.5 -0.5 L 1.5 4.5 M -0.5 1.5 L 4.5 1.5", 4) : a === Y.BuiltInSheetPattern.DarkGrid ? this._svgImage(e, t, "M 0.5 -0.5 L 0.5 1.5 M 1.5 -0.5 L 1.5 1.5 M 2.5 1.5 L 2.5 3.5 M 3.5 1.5 L 3.5 3.5 M 0.5 3.5 L 0.5 4.5 M 1.5 3.5 L 1.5 4.5", 4) : a === Y.BuiltInSheetPattern.LightTrellis ? this._svgImage(e, t, "M 0.5 0.5 L 0.5 1.5 M 1.5 3.5 L 1.5 4.5 M 1.5 -0.5 L 1.5 0.5 M 2.5 2.5 L 2.5 3.5 M 3.5 1.5 L 3.5 2.5 M 1.5 1.5 L 1.5 2.5 M 3.5 3.5 L 3.5 4.5 M 3.5 -0.5 L 3.5 0.5", 4) : a === Y.BuiltInSheetPattern.DarkTrellis ? this._svgImage(e, t, "M 0 0 L 4 0 M 0 1 L 2 1 M 0 2 L 4 2 M 2 3 L 4 3 M 0 4 L 4 4", 4) : (Y.BuiltInSheetPattern.Custom, this._svgImage(e, t, "M 0.5 0.5 L 0.5 1.5 M 0.5 4.5 L 0.5 5.5 M 2.5 2.5 L 2.5 3.5 M 2.5 6.5 L 2.5 7.5 M 4.5 0.5 L 4.5 1.5 M 4.5 4.5 L 4.5 5.5 M 6.5 2.5 L 6.5 3.5 M 6.5 6.5 L 6.5 7.5", 8)) : { background: "none" };
}
}(), qi = (a, e, t) => {
if (e === void 0) return;
if (e === null) return null;
if (e.isIStyle) return e._p.getProperties();
let n = null;
return typeof e == "function" ? n = e(typeof t == "function" ? t() : t) : n = e, n;
};
class U_ {
constructor(e, t) {
this._c = e, this._p = Object.freeze(Array.isArray(t) ? t : [t ?? null]);
}
value(e) {
const t = this._p;
for (let n = t.length - 1; n >= 0; n--) {
const r = t[n];
if (!r) continue;
const o = r[e];
if (o !== void 0) return o;
}
}
values(e) {
const t = this._p, n = t.length;
let r;
for (let o = 0; o < n; o++) {
const s = t[o];
if (!s) continue;
const i = s[e];
i !== void 0 && (r === void 0 && (r = []), r.push(i));
}
return r;
}
getProperties() {
const e = this._p;
return e ? e[e.length - 1] : null;
}
toJSON() {
return null;
}
}
class An {
constructor(e, t) {
this._c = e, this._p = Object.freeze(t);
}
_value(e) {
const t = this._p;
for (let n = t.length - 1; n >= 0; n--) {
const r = t[n];
if (!r) continue;
const o = r[e];
if (o !== void 0) return o;
}
}
_values(e) {
const t = this._p, n = t.length;
let r;
for (let o = 0; o < n; o++) {
const s = t[o];
if (!s) continue;
const i = s[e];
i !== void 0 && (r === void 0 && (r = []), r.push(i));
}
return r;
}
getProperties() {
const e = this._p;
return e ? e[e.length - 1] : null;
}
toJSON() {
return null;
}
}
class Nr extends An {
constructor(e, t, n) {
super(t, n), this._edge = e;
}
getStyle() {
return this._value("style");
}
getColor() {
const e = this._value("color");
return e ? this._c.parseColor(e) : null;
}
isNone() {
return this.getStyle() === U.StrokeStyle.None;
}
toCSS() {
const e = nr(this);
switch (this._edge) {
case U.Edge.Left:
return { borderLeft: e };
case U.Edge.Right:
return { borderRight: e };
case U.Edge.Top:
return { borderTop: e };
case U.Edge.Bottom:
return { borderBottom: e };
case U.Edge.DiagonalUp:
case U.Edge.DiagonalDown:
return { borderDiagonalUp: e };
}
}
get isIStroke() {
return !0;
}
}
class J_ extends An {
getLeft() {
return new Nr(U.Edge.Left, this._c, this._values(U.Edge.Left));
}
getRight() {
return new Nr(U.Edge.Right, this._c, this._values(U.Edge.Right));
}
getTop() {
return new Nr(U.Edge.Top, this._c, this._values(U.Edge.Top));
}
getBottom() {
return new Nr(U.Edge.Bottom, this._c, this._values(U.Edge.Bottom));
}
getDiagonalUp() {
return new Nr(U.Edge.DiagonalUp, this._c, this._values(U.Edge.DiagonalUp));
}
getDiagonalDown() {
return new Nr(U.Edge.DiagonalDown, this._c, this._values(U.Edge.DiagonalDown));
}
isEmpty() {
return !1;
}
get isIBorder() {
return !0;
}
}
class q_ extends An {
get isITextBoxAlignment() {
return !0;
}
getHorizontal() {
return this._value("horizontal");
}
getVertical() {
return this._value("vertical");
}
getIndent() {
return this._value("indent");
}
getRelativeIndent() {
return this._value("relativeIndent");
}
getOverflow() {
return this._value("overflow");
}
getRotation() {
return this._value("rotation");
}
getStacked() {
return this._value("stacked");
}
getJustifyLastLine() {
return this._value("justifyLastLine");
}
getReadingDirection() {
return this._value("readingDirection");
}
}
class K_ extends An {
isEqualMeasure(e) {
return !!e && this.getFamily() === e.getFamily() && !!F.isEqualArrays(this.getFallbacks(), e.getFallbacks()) && this.getSize() === e.getSize() && this.getWeight() === e.getWeight() && this.getStyle() === e.getStyle() && this.getStrike() === e.getStrike() && this.getScheme() === e.getScheme() && this.getShadow() === e.getShadow() && this.getOutline() === e.getOutline() && this.getLetterSpacing() === e.getLetterSpacing() && this.getVerticalAlignment() === e.getVerticalAlignment();
}
isSuperSub() {
const e = this.getVerticalAlignment();
return e === te.VerticalAlignment.Sub || e === te.VerticalAlignment.Super;
}
isSuperScript() {
const e = this.getVerticalAlignment();
return e === te.VerticalAlignment.Sub || e === te.VerticalAlignment.Super;
}
getSuperSubScale() {
return this.getFamily(), this.getSize(), this.getVerticalAlignment(), 0.6;
}
getSuperSubShift() {
return this.getFamily(), e = this.getSize(), (t = this.getVerticalAlignment()) === te.VerticalAlignment.Super ? -e / 3 : t === te.VerticalAlignment.Sub ? e / 5 : 0;
var e, t;
}
toCSS(e, t = 1, n = !1) {
const r = { fontFamily: Ti(this.getFamily(), this.getFallbacks()), letterSpacing: `${this.getLetterSpacing()}px`, fontWeight: this.getWeight(), fontStyle: this.getStyle(), textDecoration: rm(this.getUnderline(), this.getStrike()), color: this.getFill().toCSS(e), fontSize: `${F.roundAccurately(this.getSize() * te.getDeviceScale() * t, 2)}px`, textRendering: "geometricPrecision" };
if (n) {
const o = this._c.getNormal().getFont().toCSS(e, t, !1), s = r.textDecoration, i = r.fontWeight;
F.removeEqualValues(r, o), s && (r.textDecoration = s), i && (r.fontWeight = i);
}
return r;
}
getFamily() {
return this._value("family") ?? this._c.getTheme().getFontScheme().getMinorFont();
}
getFallbacks() {
let e = this._value("fallbacks") ?? this._c.getTheme().getFontScheme().getMinorFallbacks() ?? F.EmptyArray;
return this.getFamily() === "Aptos Narrow" && (e = ["Calibri", ...e]), e;
}
getSize() {
return this._value("size") ?? this._c.getDefaultFontSize() ?? 11;
}
getWeight() {
return this._value("weight");
}
getStyle() {
return this._value("style");
}
getFill() {
const e = this._value("fill");
return this._c.parseColor(e ?? N.Scheme.Bg1);
}
getLetterSpacing() {
return this._value("letterSpacing") ?? this.getSize() / -25;
}
getUnderline() {
return this._value("underline");
}
getStrike() {
return this._value("strike");
}
getScheme() {
return this._value("scheme");
}
getVerticalAlignment() {
return this._value("verticalAlign");
}
getShadow() {
return this._value("shadow");
}
getOutline() {
return this._value("outline");
}
getExtend() {
return this._value("extend");
}
get isIStyledFont() {
return !0;
}
}
const X_ = Object.freeze({ background: "none" });
class Nu extends An {
getType() {
return Y.Type.None;
}
toCSS(e) {
return X_;
}
toJSON() {
return { type: Y.Type.None };
}
}
class Y_ extends An {
getType() {
return Y.Type.Solid;
}
getColor() {
return this._c.parseColor(this._value("color") ?? N.Scheme.Bg1);
}
toCSS(e) {
return { background: this.getColor().toCSS(e) };
}
toJSON() {
return { type: Y.Type.Solid, color: this.getColor()?.toString() ?? null };
}
}
class Q_ extends An {
getOffset() {
return this._value("offset") ?? 0;
}
getColor() {
return this._c.parseColor(this._value("color") ?? N.Scheme.Bg1);
}
}
class Z_ extends An {
getType() {
return Y.Type.Gradient;
}
getStops() {
const e = this._value("stops") ?? [], t = [], n = this._c;
for (let r = 0; r < e.length; r++) {
const o = e[r];
t.push(new Q_(n, [o]));
}
return t;
}
getGradientType() {
return this._value("gradientType") ?? Y.GradientType.Linear;
}
getAngle() {
return this._value("angle") ?? 0;
}
getFillTo() {
return this._value("fillTo") ?? null;
}
toCSS(e, t) {
const n = im(this, e, t);
return n ? { background: n } : null;
}
toJSON() {
const e = { type: Y.Type.Gradient };
if (this.getStops().length > 0) {
let t = [];
for (let n = 0; n < t.length; n++) t.push({ offset: t[n].offset, color: t[n].color.toString() });
e.stops = t;
}
return this.getAngle() !== 0 && (e.angle = this.getAngle()), this.getGradientType() !== Y.GradientType.Linear && (e.gradientType = this.getGradientType()), this.getFillTo() && (e.fillTo = this.getFillTo()), e;
}
}
class eS extends An {
getType() {
return Y.Type.Pattern;
}
getBackground() {
const e = this._value("background") ?? N.Named.Window;
return this._c.parseColor(e);
}
getForeground() {
return this._c.parseColor(this._value("foreground") ?? N.Scheme.Tx1);
}
getPatternType() {
return this._value("patternType") ?? Y.BuiltInSheetPattern.None;
}
toCSS(e) {
const t = this.getBackground().toCSS(e), n = this.getForeground().toCSS(e);
return this.getPatternType() === Y.BuiltInSheetPattern.None ? { background: "none" } : this.getPatternType() === Y.BuiltInSheetPattern.Solid ? { background: this.getForeground().toCSS(e) } : G_.toCSS(this.getPatternType(), n, t);
}
toJSON() {
const e = { type: Y.Type.Pattern };
this.getPatternType() !== Y.BuiltInSheetPattern.None && (e.patternType = this.getPatternType());
const t = this.getForeground();
t && (e.foreground = t.toString());
const n = this.getBackground();
return n && (e.background = n.toString()), e;
}
}
class um {
constructor(e) {
this._options = e, this._c = e.styles, this._p = new U_(e.styles, e.properties), this._hasVisibleStyling = !this.getFill() || this.getFill().getType() !== Y.Type.None || !this.getBorder().isEmpty();
}
hasVisibleStyling() {
return this._hasVisibleStyling;
}
isNormal() {
return !1;
}
getNamed() {
const e = this._p.value("named") ?? ce.BuiltInName.Normal;
return this._c.getNamed(e);
}
createTemporaryStyle(e) {
const t = this._c, n = qi(0, e, this), r = this._options, o = r.range, s = r.direct.cloneWithUpdate(n);
return eo(t, s, o);
}
measureText(e, t = this.getFont().getSize(), n, r) {
const o = this.getFont();
n || (n = o.getFamily());
let s = o.getFallbacks();
n === "Aptos Narrow" && (s = ["Calibri", ...s]);
const i = Ti(n, s);
return te.getSharedMeasurer()(e, t * te.getDeviceScale(), i, { isBold: o.getWeight() > 400, isItalic: o.getStyle().includes("italic"), letterSpacing: o.getLetterSpacing(), ...r });
}
createTemporaryTextFrame(e, t = !1) {
return Gi(e, this.getFont(), this.getAlignment(), t);
}
getBestFit() {
if (this._bestFit !== void 0) return this._bestFit;
const e = this.getInsets(), t = this.measureText("My");
return this._bestFit = { width: null, height: t.lineHeight + e.top + e.bottom }, this._bestFit;
}
getInsets() {
if (this._insets !== void 0) return this._insets;
const e = (this.getFont().getSize(), 1), t = (n = this.getFont().getSize(), Math.max(2, Math.round(n < 225 ? n / 5 : n / 3.5)));
var n;
const r = { top: e, left: t, bottom: e, right: t }, o = this._p, s = o?.value("insets");
return s && (s.top !== void 0 && (r.top += s.top), s.left !== void 0 && (r.left += s.left), s.bottom !== void 0 && (r.bottom += s.bottom), s.right !== void 0 && (r.right += s.right)), this._insets = Object.freeze(r), this._insets;
}
getBorder() {
return new J_(this._c, this._p.values("border"));
}
getFont() {
return new K_(this._c, this._p.values("font"));
}
getFill() {
const e = this._p;
let t = e.values("fill"), n = e.value("fill");
return n.type === Y.Type.None ? new Nu(this._c, t) : n.type === Y.Type.Solid || !n.type && n.color ? new Y_(this._c, t) : n.type === Y.Type.Gradient ? new Z_(this._c, t) : n.type === Y.Type.Pattern ? new eS(this._c, t) : new Nu(this._c, t);
}
getAlignment() {
return new q_(this._c, this._p.values("alignment"));
}
getNumberFormat() {
const e = this._p.value("numberFormat");
return typeof e == "number" ? ec(e) : e;
}
getQuotePrefix() {
return this._p.value("quotePrefix");
}
get isIStyle() {
return !0;
}
}
const eo = (a, e, t) => {
const n = t?.rowStart ?? D.EmptyCell.rowIndex, r = t?.colStart ?? D.EmptyCell.colIndex, o = [hm], s = a.getNormalRanged(), i = s.getPropertiesAt(n, r, null);
if (i && o.push(i), !e)
return new tS({ styles: a, range: t, properties: o, layerTypes: null, direct: s });
const l = e.getPropertiesAt(n, r, null);
return l && o.push(l), new um({ styles: a, range: t, properties: o, direct: e });
};
class tS extends um {
isNormal() {
return !0;
}
}
const Qn = (a, e) => {
if (a && !e || e && !a) return !1;
if (a === e) return !0;
if (a.style !== e.style) return !1;
if (a.color === e.color) return !0;
let t = a.color;
(a && a.color).isIColor && (t = a.color.toString());
let n = e.color;
return (e && e.color).isIColor && (n = e.color.toString()), t === n;
};
class nt {
constructor(e, t, n, r) {
this._c = e, this._r = t, this._p = n ?? null, this._t = r ?? null, this._e = this._p === null || Object.keys(this._p).length === 1 && this._p.named === ce.BuiltInName.Normal;
}
isEmpty() {
return this._e;
}
getProperties() {
return this._p;
}
getCoords() {
return this._r;
}
cloneWithUpdate(e) {
if (e === void 0) return this;
const t = this._c, n = this._r, r = this._p, o = $e.resolveTypedUpdates(e, Ge, t, r);
return new nt(t, n, o);
}
copyTo(e, t) {
const n = this._c, r = this._r, o = e.rowStart - r.rowStart, s = e.colStart - r.colStart;
let i = null;
return D.isEqualRanges(r, this._t) || (i = D.translateRange(r, o, s)), new nt(n, e, this._p, i);
}
canTile(e, t) {
return !this._p.border;
}
_createShifted(e) {
return new nt(this._c, e, this._p);
}
getShifted(e) {
return e.after ? { ...e.after, value: this._createShifted(D.sanitizeRange(e.after)) } : null;
}
getSplit(e, t) {
const n = this._c, r = this._p, o = this._r;
let s = r;
const i = e[0];
let l = r;
const c = e[1], h = r ? r.border : null;
if (h) {
const d = t === O.Orientation.Column;
if (d ? h.left !== void 0 || h.right !== void 0 || h.vertical !== void 0 : h.top !== void 0 || h.bottom !== void 0 || h.horizontal !== void 0) {
s = { ...s };
const g = this._splitBorderRange(h, o, i, d);
g ? s.border = g : g === null && delete s.border, l = { ...l };
const m = this._splitBorderRange(h, o, c, d);
m ? l.border = m : m === null && delete l.border;
}
}
const u = this._t;
return [new nt(n, e[0], s, u), new nt(n, e[1], l, u)];
}
getMerged(e, t, n) {
const r = n === O.Orientation.Column, o = this._p, s = e._p;
if (o && !s || s && !o || !o && !s) return;
let i = Object.keys(o), l = Object.keys(s);
if (i.length !== l.length) return;
for (let d = 0; d < i.length; d++) {
const g = i[d];
if (g === "border") continue;
const m = o[g], f = s[g];
if (!F.deepEqual(m, f)) return;
}
const c = o.border, h = s.border;
if (c && !h || h && !c) return;
const u = this._c;
if (c || h) {
const d = r ? U.Edge.Top : U.Edge.Left, g = r ? U.Edge.Bottom : U.Edge.Right;
if (!Qn(c[d], h[d]) || !Qn(c[g], h[g])) return;
const m = this._r, f = e._r, _ = 1 + (r ? m.rowEnd - m.rowStart : m.colEnd - m.colStart), p = 1 + (r ? m.colEnd - m.colStart : m.rowEnd - m.rowStart), S = 1 + (r ? f.colEnd - f.colStart : f.rowEnd - f.rowStart), E = r ? U.Edge.Horizontal : U.Edge.Vertical;
if (_ > 1 && !Qn(c[E], h[E])) return;
const y = r ? U.Edge.Right : U.Edge.Bottom, C = r ? U.Edge.Left : U.Edge.Top;
if (!Qn(c[y], h[C])) return;
const w = r ? U.Edge.Vertical : U.Edge.Horizontal, b = c[y];
if (p > 1 && !Qn(b, c[w])) return;
const x = S === 1 ? h[C] : h[w];
if (S > 1 && !Qn(x, h[w]) || !Qn(b, x)) return;
const I = { border: { [d]: c[d], [g]: c[g], [E]: c[E], [w]: b, [C]: c[C], [y]: h[y] } }, v = $e.resolveTypedUpdates(I, Ge, u, o);
return new nt(u, t, v);
}
return new nt(u, t, this._p);
}
hasTrailingEdge() {
return !0;
}
isMergeOnShift() {
return !0;
}
_splitBorderRange(e, t, n, r) {
const o = r ? U.Edge.Left : U.Edge.Top, s = r ? U.Edge.Right : U.Edge.Bottom, i = r ? U.Edge.Vertical : U.Edge.Horizontal, l = r ? t.colStart : t.rowStart, c = r ? t.colEnd : t.rowEnd, h = r ? n.colStart : n.rowStart, u = r ? n.colEnd : n.rowEnd;
let d = { ...e };
return delete d[o], delete d[s], delete d[i], l === h ? e[o] && (d[o] = e[o]) : e[i] && (d[o] = e[i]), c === u ? e[s] && (d[s] = e[s]) : e[i] && (d[s] = e[i]), u - h > 0 && e[i] && (d[i] = e[i]), Object.keys(d).length === 0 ? null : d;
}
_localizeBorderRange(e, t, n) {
if (!e) return;
let r = null;
const o = t.rowStart, s = t.rowEnd, i = n.rowStart, l = n.rowEnd;
e.top && i === o && (r = r ?? {}, r.top = e.top), e.bottom && l === s && (r = r ?? {}, r.bottom = e.bottom), e.horizontal && (l - i > 0 && (r = r ?? {}, r.horizontal = e.horizontal), i > o && (r = r ?? {}, r.top = e.horizontal), l < s && (r = r ?? {}, r.bottom = e.horizontal));
const c = t.colStart, h = t.colEnd, u = n.colStart, d = n.colEnd;
return e.left && u === c && (r = r ?? {}, r.left = e.left), e.right && d === h && (r = r ?? {}, r.right = e.right), e.vertical && (d - u > 0 && (r = r ?? {}, r.vertical = e.vertical), u > c && (r = r ?? {}, r.left = e.vertical), d < h && (r = r ?? {}, r.right = e.vertical)), r;
}
_localizeBorder(e, t, n, r) {
if (!e) return;
let o = null;
const s = t.rowStart, i = t.rowEnd;
e.top && n === s && (o = o ?? {}, o.top = e.top), e.bottom && n === i && (o = o ?? {}, o.bottom = e.bottom), e.horizontal && (n > s && (o = o ?? {}, o.top = e.horizontal), n < i && (o = o ?? {}, o.bottom = e.horizontal));
const l = t.colStart, c = t.colEnd;
return e.left && r === l && (o = o ?? {}, o.left = e.left), e.right && r === c && (o = o ?? {}, o.right = e.right), e.vertical && (r > l && (o = o ?? {}, o.left = e.vertical), r < c && (o = o ?? {}, o.right = e.vertical)), o;
}
getPropertiesAt(e, t, n) {
const r = this._p;
let o = r, s = null;
const i = this._t;
if (i) {
const u = this._r, d = i.colEnd - i.colStart + 1, g = i.rowEnd - i.rowStart + 1;
t = u.colStart + (t - u.colStart + (i.colStart - u.colStart)) % d, e = u.rowStart + (e - u.rowStart + (i.rowStart - u.rowStart)) % g;
}
const l = r?.font;
l && l.fill && (s = s ?? this._c.getNormalRanged().getPropertiesAt(e, t, n), s && s.font && l.fill === s.font.fill && (o === r && (o = { ...o }), o.font = { ...l }, delete o.font.fill));
const c = r?.fill;
c && (s = s ?? this._c.getNormalRanged().getPropertiesAt(e, t, n), s && F.deepEqual(c, s.fill) && (o === r && (o = { ...o }), delete o.fill));
const h = o?.border;
if (h) {
const u = i ?? this._r, d = this._localizeBorder(h, u, e, t);
d !== void 0 && (o === r && (o = { ...o }), d === null ? delete o.border : o.border = d);
}
return o;
}
toJSON() {
return F.toSafeJSON(this._p);
}
}
const nS = Object.freeze({ value: null, style: null, hyperlink: null, formula: null, type: q.Null, stringToParse: null }), Fu = Object.seal({ value: void 0, style: void 0, hyperlink: void 0, formula: void 0, type: void 0, stringToParse: void 0 }), rS = Object.seal({ value: void 0, style: void 0, hyperlink: void 0, formula: void 0 }), oS = Object.freeze({ width: 1, height: 1 }), sS = new ic({ max: 1e3 }), iS = new class {
isEditAllowed() {
return !0;
}
isFormulaHidden() {
return !1;
}
get isICellProtection() {
return !0;
}
}(), zl = (a, e, t = null, n = null, r = !1) => {
if (a === void 0) return;
if (a === null) return nS;
if (a && a.isICell) {
const p = a, S = Fu;
return S.value = p.getValue(), p.getStyle().isNormal() || (S.style = p.getStyle()._p.getProperties()), S.formula = p.getFormulaText(), S.hyperlink = p.getHyperlink(), S.type = p.getType(), S;
}
let o;
a.value !== void 0 || a.style !== void 0 || a.hyperlink !== void 0 ? o = a : (o = rS, o.value = a, o.style = void 0, o.hyperlink = void 0);
const s = Fu;
s.type = void 0, s.value = void 0, s.style = void 0, s.formula = void 0, s.hyperlink = void 0, s.stringToParse = void 0;
let i, l = o.value, c = !1;
if (o.value !== void 0 && (i = gt(l), i || (c = to(l), c && (i = q.Number)), !i)) throw new Error("Invalid cell type. See documentation for information on valid built in cell types and creating custom cell types.");
let h, u, d = null, g = null, m;
if (i === q.String) {
if (m = o.value, t) {
let p = n?.get(m);
if (!p) {
const S = m.length, E = m.charAt(0);
E === "=" && S > 1 ? (u = m.substring(1), l = null) : (p = mm(m, t), !p || typeof p.value != "string" || E !== "+" && E !== "-" || (u = "=" + m, l = null), p !== void 0 && n && n.set(m, p));
}
p && (p.value !== void 0 && (l = p.value, i = gt(l)), p.style !== void 0 && (d = p.style), p.hyperlink !== void 0 && (h = p.hyperlink)), !r && t.parse && (g = m);
}
} else if (c) {
const p = t?.date1904 ?? e.date1904;
l = es(o.value, p), d = (S) => {
if (!ts(S.getNumberFormat())) return { numberFormat: "Short Date" };
};
} else l = o.value;
let f = o.style;
if (f && f.isIStyle && (f = f._p.getProperties()), h = o.hyperlink ?? h, d) if (f) {
const p = f;
f = (S) => {
let E = S.createTemporaryStyle(d);
return E = E.createTemporaryStyle(p), E = E._p.getProperties(), E;
};
} else f = d;
let _ = !1;
return l !== void 0 && (l === null ? (s.value = null, s.type = q.Null) : (s.value = l, s.type = i), _ = !0), f !== void 0 && (s.style = f, _ = !0), h !== void 0 && (s.hyperlink = h, _ = !0), u !== void 0 && (s.formula = u, _ = !0), r || (s.stringToParse = g, _ = !0), _ ? (s.type = i, s) : void 0;
}, dm = (a, e, t, n) => cm(t, e, a, e.getNumberFormat(), (r) => n.styles.parseColor(r), n.date1904), gm = (a, e, t, n, r = !1) => {
if (a === q.Null) return null;
let o = "";
if (r) o = "" + t;
else {
const s = dm(a, e, t, n);
if (s.formattedRuns) {
const i = s.formattedRuns.runs;
for (let l = 0; l < i.length; l++)
o += i[l].text;
} else o = s.displayText;
}
return Gi(o, e.getFont(), e.getAlignment(), a === q.String, r);
}, ac = (a, e) => {
const t = e.getInsets();
if (a === q.Null) return t;
let n = t;
const r = Ki(a, e), o = e.getAlignment().getIndent();
if (o && (r === X.HorizontalAlignment.Left || r === X.HorizontalAlignment.Right)) {
n = { ...t };
const s = e.measureText(" ".repeat(1 * o)), i = Math.min(3, Math.max(1, (26 - e.getFont().getSize()) / 2));
let l = s.width * i;
r === X.HorizontalAlignment.Left ? n.left += l : r === X.HorizontalAlignment.Right && (n.right += l);
}
return Object.freeze(n);
}, Ki = (a, e) => {
const t = e.getAlignment(), n = t.getRotation(), r = t.getHorizontal();
return n !== 0 && r === X.HorizontalAlignment.General ? n > 0 && n < 90 || n > 180 && n <= 270 ? X.HorizontalAlignment.Right : X.HorizontalAlignment.Left : r === X.HorizontalAlignment.General ? a === q.Null ? X.HorizontalAlignment.Left : a === q.Boolean || a === q.Error ? X.HorizontalAlignment.Center : e.getNumberFormat() === "@" ? X.HorizontalAlignment.Left : a === q.Number ? X.HorizontalAlignment.Right : X.HorizontalAlignment.Left : r;
}, aS = (a, e, t, n, r, o, s, i) => {
if (e === q.Null || n === "") return null;
const l = a.colIndex;
if (!((B, H, z = !1, W = !1) => {
if (B === q.Null) return !1;
const L = H.getAlignment(), j = L.getHorizontal();
if (j === X.HorizontalAlignment.CenterContinuous) return !0;
if (j === X.HorizontalAlignment.Fill || j === X.HorizontalAlignment.Distributed || B !== q.String || L.getOverflow() !== X.Overflow.Visible || j === X.HorizontalAlignment.Right && z || j === X.HorizontalAlignment.Center && z && W || W && (j === X.HorizontalAlignment.General || j === X.HorizontalAlignment.Left)) return !1;
const G = L.getVertical();
return G !== X.VerticalAlignment.Justify && G !== X.VerticalAlignment.Distributed;
})(e, t, r !== null && r.colIndex + 1 === l, o !== null && o.colIndex - 1 === l)) return null;
const c = cS(e, t, n, i), h = t.getAlignment().getHorizontal(), u = h === X.HorizontalAlignment.Fill, d = h === X.HorizontalAlignment.CenterContinuous || u;
if (!c && !d) return null;
const g = (m = Ki(e, t)) === X.HorizontalAlignment.Center || m === X.HorizontalAlignment.CenterContinuous ? Nn.Center : m === X.HorizontalAlignment.Right ? Nn.Right : Nn.Left;
var m;
let f = 0, _ = 0, p = 0, S = 0, E = 1;
if (d && n !== null && s.directStyle) {
const B = s.directStyle.getCoords();
E = Math.min(i.nextContentful(a, B.colEnd), B.colEnd) - a.colIndex + 1;
}
const y = i.colHeaders, C = y.findOffset.bind(y), w = y.findIndex.bind(y);
let b = C(l);
const x = b;
let I = C(l + E), v = I - b, R = l, A = l;
const M = { x: 0, y: 0, width: v, height: c?.height ?? 0 }, T = l - l + E;
let k = c ? c.width - v : 0, P = M;
return u && (k = 0), v > 0 && k > 0 && (g === Nn.Center && (k /= 2), g !== Nn.Left && g !== Nn.Center || (A = w(I + k), o !== null && (A = Math.min(A, o.colIndex - 1)), I = C(A), S = k, _ = A - l), g !== Nn.Right && g !== Nn.Center || (R = w(b - k), r !== null && (R = Math.max(R, r.colIndex + 1)), b = C(R), p = k, f = l - R), M.x = x - b, P.x = M.x), { anchorBounds: M, leftIndex: f, rightIndex: _, leftOffset: p, rightOffset: S, colSpan: T, colBounds: P };
};
class lS {
constructor(e, t) {
if (this._styles = e, this._rs = t, t?.table) {
const n = t?.table;
this._table = n.getStyle().getRanged(n);
}
if (t?.conditionals) {
this._conditionals = [];
for (let n = 0; n < t.conditionals.length; n++) {
const r = t.conditionals[n];
this._conditionals.push(r);
}
}
}
getCoords() {
return D.EmptyRange;
}
getPropertiesAt(e, t, n) {
let r = null, o = this._rs.directStyle?.getPropertiesAt(e, t, n) ?? null;
const s = this._styles;
if (o && o.named) {
const h = o.named;
if (h !== ce.BuiltInName.Normal) {
const u = this._styles.getNamed(h);
u ? r = u.getRanged().getPropertiesAt(e, t, n) : console.warn(`A named styled was referenced but not found: '${h}'.`);
}
}
let i = null;
const l = this._table?.getPropertiesAt(e, t, n);
l && (i = i ? $e.resolveTypedUpdates(l, Ge, s, i) : l), r && (i = i ? $e.resolveTypedUpdates(r, Ge, s, i) : r);
const c = this._conditionals;
if (c) for (let h = 0; h < c.length; h++) {
const u = c[h].getPropertiesAt(e, t, n);
u && (i = i ? $e.resolveTypedUpdates(u, Ge, s, i) : u);
}
return o && (i = i ? $e.resolveTypedUpdates(o, Ge, s, i) : o), i;
}
cloneWithUpdate(e) {
return (this._rs.directStyle ?? this._styles.getNormalRanged()).cloneWithUpdate(e);
}
}
const Pl = (a, e, t, n) => {
if (!t) return n.styles.getNormal();
const r = n.styles;
return eo(r, t ? new lS(r, t) : null, e);
}, jn = (a, e, t, n, r, o, s, i = null, l = sS) => {
if (t === null) return e ? e.getBestFit() : null;
const c = a === q.String, h = e.getFont(), u = h.getWeight(), d = h.getSize(), g = h.getFamily(), m = e.getAlignment(), f = m.getOverflow(), _ = m.getRotation(), p = m.getVertical(), S = e.getNumberFormat(), E = c && f === X.Overflow.Visible, y = c && (f === X.Overflow.Wrap || p === X.VerticalAlignment.Justify || p === X.VerticalAlignment.Distributed), C = (i ?? "") + "\0" + d + g + u + S + _ + E + y + o + s + (i ? "" : t), w = l.get(C);
if (w) return w;
let b = null, x = null;
const I = ac(a, e), v = I.top + I.bottom + +mS(e);
let R = !1, A = !1;
s && (A = !0, (_ !== 0 || y) && (A = !1));
const M = A ? void 0 : gm(a, e, t, n), T = I.left + I.right + 2;
if (M) {
if (a === q.Number && S === "General" && o) {
let B = t, H = F.splitNumber(B), z = "";
z = Math.abs(B) >= Math.pow(10, 12) || Math.abs(B) <= Math.pow(10, -12) ? `0.${"0".repeat(Math.max(2, Math.min(H.ipLength, 5)))}E+00` : Math.abs(H.ipLength) === 0 ? "0.0" : Math.abs(H.fpLength) > 0 ? "0".repeat(H.ipLength) + ".0" : "0".repeat(H.ipLength), B < 0 && (z = "-" + z), z = "0".repeat(z.length);
const W = e.measureText(z);
b = W.width, x = W.lineHeight;
} else {
let B = null;
y && (B = { width: Math.max(1, r - T) });
const H = M.layout(B);
b = H.bounds.width, x = H.bounds.height;
}
if (b !== null && (b += T), x !== null && (x += v), R = a === q.String, _) {
R && f === X.Overflow.Wrap && (R = !1);
const B = ((H, z) => {
const { x: W, y: L, width: j, height: G } = H, V = z * Math.PI / 180, $ = Math.sin(V), J = Math.cos(V), K = j / 2, he = G / 2, le = _s(-K, -he, $, J), pe = _s(K, -he, $, J), ee = _s(-K, he, $, J), ne = _s(K, he, $, J);
let ue = Math.min(le.x, pe.x, ee.x, ne.x) + K, be = Math.max(le.x, pe.x, ee.x, ne.x) + K, Q = Math.min(le.y, pe.y, ee.y, ne.y) + he;
return { x: W + ue, y: L + Q, width: be - ue, height: Math.max(le.y, pe.y, ee.y, ne.y) + he - Q };
})({ x: 0, y: 0, width: b, height: x }, _);
b = B.width, x = B.height;
}
} else x = e.getBestFit().height;
o && R && (b = 0);
const k = { width: b, height: x }, P = Object.freeze(k);
return l.set(C, P), P;
}, cS = (a, e, t, n) => {
const r = ac(a, e), o = Ki(a, e);
let s = r.left + r.right;
o === X.HorizontalAlignment.Left ? s = r.right : o === X.HorizontalAlignment.Right ? s = r.left : o === X.HorizontalAlignment.Center && (s = r.left + r.right);
const i = jn(a, e, t, n, Number.MAX_SAFE_INTEGER, !1, !1);
return { width: Math.ceil(i.width - s), height: Math.ceil(i.height) };
};
class Kn {
constructor(e, t, n = q.Null, r = null, o = null, s = null, i = null) {
this._options = e, this._coords = t ?? null, this._t = n, this._rs = o, this._v = r, this._p = s, this._n = i;
}
getRange() {
const e = this._coords;
return this._options.getRange(e ? D.cellToRange(e) : null);
}
isEqual(e) {
if (!e) return !1;
if (this === e) return !0;
const t = e;
return !!t.isICell && this._v === t._v && !!D.isEqualCells(this._coords, e.getCoords()) && this._options.sheet === t._options?.sheet;
}
getCoords() {
return this._coords;
}
getA1() {
const e = this._coords;
return e ? En(this._options.resolveRange(e).getCoords()) : rt;
}
getSheet() {
return this._options.sheet;
}
select(e) {
return this._options.opener("#" + os(this._coords), e);
}
getColumnFilter() {
if (!this._rs) return null;
let e = null;
if (this._rs.table) {
const t = this._rs.table.getHeaderRange().getCoords();
if (t && D.isCellWithinRange(this._coords, t)) {
const n = this._coords.colIndex - t.colStart;
e = this._rs.table.getColumnFilter(n) ?? null;
}
}
return e;
}
getProtection() {
return iS;
}
getTextOverflow() {
const e = this._to;
if (e !== void 0) return e;
if (this._rs && this._rs.merge) return this._to = null, null;
const t = this.getStyle(), n = aS(this._coords, this._t, t, this._v, this._p, this._n, this._rs, this._options);
return n === null || n.leftIndex === 0 && n.rightIndex === 0 && n.colSpan <= 1 ? (this._to = null, null) : (this._to = n, this._to);
}
getRenderHorizontalAlignment() {
return Ki(this._t, this.getStyle());
}
isEmpty() {
return this._v === null && !this._rs;
}
getExtrusions() {
const e = this._rs;
if (!e && this._to === null) return null;
if (e) {
const r = e.merge;
if (r !== void 0) return r.getCoords();
}
const t = this.getTextOverflow();
if (!t) return null;
const n = this._coords;
return { colStart: n.colIndex - t.leftIndex, rowStart: n.rowIndex, colEnd: n.colIndex + t.rightIndex + t.colSpan - 1, rowEnd: n.rowIndex };
}
isEditAllowed() {
const e = this._options;
return e ? !e.getProtection().isLocked() || !!this._rs && this.getProtection().isEditAllowed() : !0;
}
isFormulaHidden() {
return !!this._options.getProtection().isLocked() && !!this._rs && this.getProtection().isFormulaHidden();
}
isContentful() {
return this._v !== null;
}
getBestFit(e, t = !1) {
return e === void 0 && (e = this._options.sheet.getColumnHeaders().getSpanSize(this._coords.colIndex) ?? 64), jn(this._t, this.getStyle(), this._v, this._options, e, t, !1);
}
getInsets() {
return this._v === null ? this.getStyle().getInsets() : ac(this._t, this.getStyle());
}
getTextFrame(e) {
let t, n;
if (e && (n = this.getFormulaText()), t = n ?? this._v, t === null) return null;
const r = this.getStyle();
return n ? ((o, s) => s === q.Null ? null : Gi(s, o.getFont(), o.getAlignment(), !1, !0))(r, t, this._options) : gm(this._t, r, t, this._options, e);
}
getValue() {
return this._v;
}
getFormula() {
let e = this._rs?.formula;
if (!e) return null;
const t = this._coords;
return t ? (Array.isArray(e) && (e = e[0]), new uS(this._options, e, t)) : null;
}
getFormulaText() {
let e = this._rs?.formula;
if (!e) return null;
const t = this._coords;
return t ? (Array.isArray(e) && (e = e[0]), "=" + e.getFormulaTextAt(t.rowIndex, t.colIndex)) : null;
}
getCalcStatus() {
const e = this._rs;
return e && e.pending ? Te.CalcStatus.Pending : Te.CalcStatus.Ready;
}
getType() {
return this._t;
}
getStyle(e = !1) {
if (!e && this._styleConditional) return this._styleConditional;
if (e && this._styleSpecific) return this._styleSpecific;
const t = Pl(0, D.cellToRange(this._coords), this._rs, this._options);
return e ? this._styleSpecific = t : this._styleConditional = t, t;
}
createTemporaryCell(e) {
const t = this._options;
if (e === null) return new Kn(t, this._coords, null);
const n = zl(e, this._options);
let r = this._rs;
if (n.style !== void 0) {
const i = this._coords ?? D.EmptyCell, l = D.cellToRange(i), c = () => Pl(0, l, this._rs, this._options), h = qi(this._options.styles, n.style, c), u = (this._rs?.directStyle ?? new nt(t.styles, l)).cloneWithUpdate(h);
r = { ...r, directStyle: u };
}
let o = this._t, s = this._v;
return n && n.value !== void 0 && (s = n.value, o = n.type), s === this._v && o === this._t && r === this._rs ? this : s !== null || r ? new Kn(this._options, this._coords, o, s, r) : new Kn(this._options, this._coords);
}
_isDate1904() {
return this._options.date1904;
}
getNumberFormat(e) {
if (e !== void 0) {
const t = this._v;
return cm(t, this.getStyle(), this._t, e, (n) => this._options.styles.parseColor(n), this._isDate1904());
}
return dm(this._t, this.getStyle(), this._v, this._options);
}
toDate() {
return this._t !== q.Number ? null : this._rs ? this.getNumberFormat().asDate : null;
}
toText(e) {
return this.getNumberFormat(e).displayText;
}
toTextUnformatted(e) {
if (e) {
const n = this.getFormulaText();
if (n) return n;
}
let t = this._v;
return this.isSpillOverflow() && (t = null), ((n, r, o, s) => {
if (r === q.Null || n == null) return "";
if (r === q.Number) {
const i = n, l = ts(o), c = Wi(o);
if (l || c) {
const h = parseFloat(n), u = h % 1 != 0, d = h >= 1;
if (h < 0) return F.castToString(n);
if (!l || c || u) if (!c || l || d) {
const g = To("Short Date", i, s), m = To("Long Time", i, s);
if (g && m) return g.fmt + " " + m.fmt;
} else {
const g = To("Long Time", i, s);
if (g) return g.fmt;
}
else {
const g = To("Short Date", i, s);
if (g) return g.fmt;
}
}
}
if (r === q.Number && o.endsWith("%")) {
let i = F.roundAccurately(100 * parseFloat(n));
if (!isNaN(i)) return i + "%";
}
return r === q.Boolean ? n ? "TRUE" : "FALSE" : r === q.Error ? n?.getLabel?.() ?? Ee.Label.Unknown : r === q.RichData ? "(Rich Object)" : F.castToString(n);
})(t, this._t, this.getStyle().getNumberFormat(), { date1904: this._isDate1904() });
}
getComments() {
const e = this._rs?.comments;
return e ? Object.freeze(e) : null;
}
getHyperlink() {
const e = this._rs?.hyperlink;
return e ? new H0(this.toText.bind(this), this._options.opener, e) : null;
}
getErrors() {
const e = this._rs;
return e && e.calcError ? [e.calcError] : F.EmptyArray;
}
getWarnings() {
return F.EmptyArray;
}
getSpans() {
const e = this._rs?.merge;
if (!e) return oS;
const t = e.getCoords();
return Object.freeze({ width: t.colEnd - t.colStart + 1, height: t.rowEnd - t.rowStart + 1 });
}
isTopLeft() {
const e = this._rs?.merge;
if (!e) return !0;
const t = e.getCoords();
return this._coords && this._coords.colIndex === t.colStart && this._coords.rowIndex === t.rowStart;
}
getSpill() {
let e = this._rs?.spills;
if (!e || !this._coords) return null;
Array.isArray(e) || (vs[0] = e, e = vs);
let t = null;
for (let n = 0; !t && n < e.length; n++) {
const r = e[n];
r.getError() || (t = r);
}
return t || (t = e[0]), this._options.getRange(t.getCoords());
}
isSpillOverflow() {
let e = this._rs?.spills;
if (!e) return !1;
if (!this._coords) return null;
Array.isArray(e) || (vs[0] = e, e = vs);
for (let t = 0; t < e.length; t++) {
const n = e[t].getCoords();
if (this._coords.colIndex === n.colStart && this._coords.rowIndex === n.rowStart) return !1;
}
return !0;
}
get [Symbol.toStringTag]() {
return "[Cell]";
}
toString() {
let e = "{blank}";
return this._v !== null && (e = this.toTextUnformatted(), this.getType() === q.String && (e = `'${e}'`)), `${this.getA1()} => ${e}`;
}
get isICell() {
return !0;
}
}
let hS = class extends Kn {
constructor(a) {
super(a, null, null, null);
}
isEmpty() {
return !0;
}
isContentful() {
return !1;
}
toString() {
return "{EMPTY CELL}";
}
};
class uS {
constructor(e, t, n) {
this._options = e, this._entry = t, this._coords = n;
}
getTokens(e) {
const t = this._coords;
return t ? this._entry.getTokensAt(t.rowIndex, t.colIndex, e) : F.EmptyArray;
}
evaluate(e) {
const t = this._coords;
return t ? this._options.calcGraph().evaluateAt(t.rowIndex, t.colIndex, e) : F.EmptyArray;
}
toText(e) {
const t = this._coords;
return t ? "=" + this._entry.getFormulaTextAt(t.rowIndex, t.colIndex, e) : null;
}
getDirectPrecedents() {
const e = this._coords;
return e ? this._options.calcGraph().getDirectPrecedentsAt(e.rowIndex, e.colIndex) : F.EmptyArray;
}
getReferences() {
const e = this._coords;
return e ? this._entry.getReferencesAt(e.rowIndex, e.colIndex) : F.EmptyArray;
}
setReferenceAt(e, t) {
const n = this._coords;
return n ? (this._options.calcGraph().setReferenceAt(n.rowIndex, n.colIndex, e, t), this) : F.EmptyArray;
}
get [Symbol.toStringTag]() {
return "[Formula]";
}
toString() {
return this.toText();
}
}
const vs = [null];
let Ha;
const Fi = (a, e, t, n = !1) => {
const r = t === O.Orientation.Row, o = a.length, s = new Array(o);
for (let i = 0; i < o; i++) {
const l = a[i];
if (r) {
const c = l.colEnd - l.colStart + 1;
s[i] = { ...l, colStart: n ? l.colEnd + 1 : l.colStart, rowStart: e.rowStart, colEnd: n ? l.colEnd + c : l.colEnd, rowEnd: e.rowEnd };
} else {
const c = l.rowEnd - l.rowStart + 1;
s[i] = { ...l, colStart: e.colStart, rowStart: n ? l.rowEnd + 1 : l.rowStart, colEnd: e.colEnd, rowEnd: n ? l.rowEnd + c : l.rowEnd };
}
}
return s;
}, Xo = (a, e, t) => {
const n = e, r = a.length;
for (let o = 0; o < r; o++) {
const s = a[o];
if ((s.rowStart <= n.rowStart && s.rowEnd >= n.rowEnd) !== t) return !t;
}
return t;
}, Yo = (a, e, t) => {
const n = e, r = a.length;
for (let o = 0; o < r; o++) {
const s = a[o];
if ((s.colStart <= n.colStart && s.colEnd >= n.colEnd) !== t) return !t;
}
return t;
}, ku = (a, e) => {
let t = 0;
const n = a.length;
for (let r = 0; r < n; r++) {
const o = a[r];
e === O.Orientation.Column ? t += o.colEnd - o.colStart + 1 : t += o.rowEnd - o.rowStart + 1;
}
return t;
}, dS = (a, e) => {
if (e) {
if (a.colStart <= e.colStart && a.colEnd >= e.colEnd) return O.Orientation.Row;
if (a.rowStart <= e.rowStart && a.rowEnd >= e.rowEnd) return O.Orientation.Column;
}
return a ? ((t) => t.rowEnd - t.rowStart > t.colEnd - t.colStart ? O.Orientation.Column : O.Orientation.Row)(a) : O.Orientation.Row;
}, xs = () => !1, Wa = () => !0, Is = () => null, Ou = () => Ze, mn = () => 0, Du = new class extends Kn {
constructor() {
super(null, null);
}
createTemporaryCell() {
return this;
}
getType() {
return q.Error;
}
getWarnings() {
return [rt];
}
getStyle(a = !1) {
return Ha || (Ha = new is().getNormal(), Ha);
}
toString() {
return `${this._coords ? os(this._coords) : rt} => ${this._v ?? "{blank}"}`;
}
}(), en = () => Un, Un = { forEach: () => {
}, [Symbol.iterator]: Ou, entries: Ou, select: Ie, find: Ie, calculate: Ie, getCell: () => Du, getValue: Is, setValue: Ie, setFormula: Ie, setValues: Ie, updateCells: Ie, updateStyle: Ie, getCells: () => [[Du]], getStyleUpdater: Ie, getValues: () => [[null]], getBounds: Is, getIntersect: en, getUnion: en, getDifferences: Ie, getResizeBy: en, getResizeTo: en, getOffsetBy: en, getOffsetTo: en, getFixed: en, getUsedRange: en, getEntireRows: en, getEntireColumns: en, getSurrounding: Ie, getExtended: Ie, isEntireRows: xs, isEntireColumns: xs, isEntireRange: xs, getWidth: mn, getHeight: mn, size: 0, sort: Ie, clear: Ie, setHyperlink: Ie, setComments: Ie, merge: Ie, unmerge: Ie, getMerges: Ie, insert: Ie, insertFrom: Ie, delete: Ie, getDefaultShiftOrientation: Ie, getDefaultSortCriteria: Ie, autoFill: Ie, autoFit: Ie, getSnapshot: Ie, copyFrom: Ie, doBatch: Ie, startIncrementalUpdates: Ie, getRowHeaders: Ie, getColumnHeaders: Ie, getCounts: Ie, getCount: mn, isContentful: xs, addListener: Ie, getColumnStart: mn, getRowStart: mn, getColumnEnd: mn, getRowEnd: mn, getRowCount: mn, getColumnCount: mn, getVisible: Ie, getCoords: Is, isEmpty: Wa, toString: () => rt, getA1: () => rt, isInvalid: Wa, getSheet: Is, isReadOnly: Wa, isICellRange: !0 };
function Cn(a, e = null, t = null, n = rt) {
return a || t ? Object.freeze({ ...Un, getSheet: () => a, bounds: () => t, getA1: () => n, toString: () => t ? Rn(t, e) : n }) : Un;
}
const gS = /^[\\+-]?[0-9]*\.?[0-9]*$/, mm = (a, e, t) => {
if (a === void 0) throw new Error("A value is required to create a cell from a text.");
const n = t ?? { value: null };
if ((a = F.castToString(a)).trim() === "") return n;
if (a.toUpperCase() === "TRUE" || a.toUpperCase() === "FALSE") return n.value = a.toUpperCase() === "TRUE", n;
if (a.startsWith("'") && !e?.ignoreQuotePrefix) return n.style = { quotePrefix: !0 }, n.value = a.substring(1, a.length), n;
n.value = a;
const r = ",", o = "$", s = ".";
let i = a.trim(), l = 1, c = !1;
i = ((_) => {
const p = new RegExp("([(]{1}([^(|^)]+)[)]{1})").exec(_);
if (p?.[2]) {
const S = _.substring(0, p.index) + p[2].trim() + _.substring(p.index + ("(" + p[2] + ")").length - 1, _.length - 1);
return S.indexOf("(") > -1 || S.indexOf(")") > -1 ? _ : (c = !0, l = -1, S);
}
return _;
})(i);
let h = 0;
i = ((_) => {
const p = new RegExp("[0-9]+([eE][-+]?[0-9]+)?$").exec(_);
if (p?.[1]) {
const S = _.substring(0, _.length - p[1].length);
let E = 1, y = p[1].substring(1, p[1].length);
if (y.startsWith("-") ? (y = y.substring(1, y.length), E = -1) : y.startsWith("+") && (y = y.substring(1, y.length)), !isNaN(y)) return h = y * E, S;
}
return _;
})(i);
let u = !1;
if (i = ((_) => {
const p = new RegExp(`^(\\${o}[\\ ]*\\-|\\${o}[\\ ]*\\+|\\-[\\ ]*\\${o}|\\+[\\ ]*\\${o}|\\-|\\+)?`).exec(_);
if (p?.[1]) {
const S = p?.[1].indexOf(o) > -1, E = p?.[1].indexOf("-") > -1, y = p?.[1].indexOf("+") > -1, C = (S ? o : "") + _.substring(p.index + p[1].length, _.length).trim(), w = C.indexOf("-") > -1, b = C.indexOf("+") > -1;
return w || b ? _ : (u = E || y, E && (l = -1), C);
}
return _;
})(i), u && (c || i.length === 0)) return n;
let d = !1;
if (i = ((_) => {
if (new RegExp(`^(?:\\${o}[\\ ]*)?((\\d{1,3}(${r}\\d{3})*)|(\\d*))(\\${s}|\\${s}\\d*)?(?:[\\ ]*\\%)?$`).test(i)) {
const p = _.replace(new RegExp(`${r}`, "g"), "");
return d = p.length < _.length, p;
}
return _;
})(i), i.match(gS) && !isNaN(i)) {
if (n.value = i * l, h !== 0) n.value = n.value * Math.pow(10, h), n.style = { numberFormat: `0${s + "0".repeat(2)}E+00` };
else if (d) {
let _ = ei(i);
n.style = _ > 0 ? { numberFormat: `#${r}##0${s + "0".repeat(2)}` } : { numberFormat: `#${r}##0` };
}
return n;
}
if (i.trimEnd().endsWith("%") && i.trimEnd().length > 1) {
let _ = i.substring(0, i.length - 1);
if (!isNaN(_)) {
n.value = _ * l / 100;
const p = ei(_);
n.style = (S) => {
if (!S.getNumberFormat().includes("%")) return { numberFormat: p > 0 ? `0${s + "0".repeat(2)}%` : "0%" };
};
}
return n;
}
if (i.startsWith(o) && a.trim().length > 1) {
let _ = i.replace(o, "");
if (!isNaN(_)) {
let p = ei(_);
n.value = _ * l, n.style = (S) => {
if (S.getNumberFormat().includes(o)) return;
let E;
return E = p > 0 ? `${o}#${r}##0${s + "0".repeat(2)}_);[Red](${o}#${r}##0${s + "0".repeat(2)})` : `${o}#${r}##0_);[Red](${o}#${r}##0)`, { numberFormat: E };
};
}
return n;
}
let g = null, m = null;
try {
m = ag(a, e?.date1904, !0);
let _ = a;
m && (_ = m.leadingText), _.trim().length > 0 && (g = Xl(_, e?.date1904)), !g && m?.leadingText.trim().length > 0 && (m = null);
} catch {
}
if (g || m) {
n.style = (p) => {
let S = p.getNumberFormat();
const E = ts(S);
if (g && E) return;
const y = Wi(S);
if (!m || !y) {
if (g && m && !E && !y ? S = "m/d/yyyy h:mm" : g && !E ? S = g.numberFormat : m && !y && (S = m.numberFormat), m && m.parsed.oaDateTime > 1 && (S = "General"), g && !E && !m) {
const C = Nt.Parser.formatValue(g.numberFormat, g.asOADate, { date1904: e?.date1904 }), w = Intl.DateTimeFormat().resolvedOptions().locale ?? "en-US";
C === new Intl.DateTimeFormat(w).format(g.asJSDate) ? S = "Short Date" : C === new Intl.DateTimeFormat(w, { dateStyle: "full" }).format(g.asJSDate) ? S = "Long Date" : C === new Intl.DateTimeFormat(w, { timeStyle: "medium" }).format(g.asJSDate) && (S = "Long Time");
}
return { numberFormat: S };
}
};
let _ = 0;
return g && (_ += g.asOADate), m && (_ += m.parsed.oaDateTime), n.value = _, n;
}
const f = Ee.getBuiltInByLabel(a);
return f ? (n.value = f, n) : (n.value = a, pg(a) ? n.hyperlink = a : _g(a) && (n.hyperlink = a, n.hyperlink.toLowerCase().startsWith("mailto:") || (n.hyperlink = `mailto:${n.hyperlink}`)), a.includes(`
`) && (n.style = { ...n?.style, alignment: { overflow: X.Overflow.Wrap } }), n);
}, mS = (a) => {
const e = a.getFont().getUnderline() === te.UnderlineStyle.SingleAccounting, t = a.getFont().getUnderline() === te.UnderlineStyle.DoubleAccounting;
let n = 0;
return (e || t) && (n = a.measureText("").underlineThickness + 1, t ? n *= 2 : n += 1), n;
}, ja = (a) => {
const e = [];
return a.getUsedRange().forEachSpan((t, n) => {
const r = n.getCoords();
t === 0 && e.push(r);
}, { includeStyles: !1 }), Wn(Go(e));
}, Va = (a, e, t, n) => {
const r = n?.asJSDate;
let o;
t ? o = Zg : (r || n?.includeMergeOverflow) && (o = {}, r && (o[oe.Type.Style] = !1, o[oe.Type.Table] = !1), n.includeMergeOverflow && (o[oe.Type.Merge] = !1));
const s = n?.orientation ?? O.Orientation.Row, i = n?.maxSize ?? 1e4, l = a({ includeEmpty: !0, orientation: s, reverse: n?.reverse, excludeHidden: n?.excludeHidden, includeMergeOverflow: n?.includeMergeOverflow, includeRangeTypes: o, bounds: e, excludeCellDetails: !r }), c = s !== O.Orientation.Row, h = [];
let u, d = -1, g = null, m = 0;
for (u = l.next(); !u.done; ) {
if (m > i) throw new Error(em(i));
const f = u.value, _ = f.context.getCoords(), p = c ? _.colIndex : _.rowIndex;
p !== d && (g = [], h.push(g), d = p);
let S = f.value;
if (t) S = f.context.getCell();
else if (r && S !== null && typeof S == "number") {
const E = f.context.getCell().toDate();
E && (S = E);
}
g.push(S), u = l.next(), m++;
}
return h;
}, Po = (a, e) => a === e || !(!a || !e) && a.rowStart === e.rowStart && a.rowEnd === e.rowEnd && a.colStart === e.colStart && a.colEnd === e.colEnd && a.$rowStart === e.$rowStart && a.$rowEnd === e.$rowEnd && a.$colStart === e.$colStart && a.$colEnd === e.$colEnd, fm = (a, e) => {
if (!a) return;
const t = { ...a };
return e ? typeof e == "boolean" ? (t.$colStart = e, t.$rowStart = e, t.$colEnd = e, t.$rowEnd = e, t) : (typeof e.colStart == "boolean" && (t.$colStart = e.colStart), typeof e.rowStart == "boolean" && (t.$rowStart = e.rowStart), typeof e.colEnd == "boolean" && (t.$colEnd = e.colEnd), typeof e.rowEnd == "boolean" && (t.$rowEnd = e.rowEnd), t) : t;
};
class $a {
constructor(e, t, n) {
const r = this;
this.setState = (o) => {
const s = o[0];
let i = o[1], l = o[2];
if (t && t.includeMergeOverflow && l && l.merge) {
const h = t.bounds, u = l.merge.getCoords();
let d = !1;
const g = u.colStart, m = u.rowStart, f = h.colStart, _ = h.rowStart, p = s.colIndex, S = s.rowIndex;
!d && g < f && m >= _ && p === f && S === m && (d = !0), !d && m < _ && g >= f && S === _ && p === g && (d = !0), !d && m < _ && g < f && S === _ && p === f && (d = !0), d && (i = l.merge.tvTl());
}
l && Object.keys(l).length === 0 && (l = null);
let c = i;
return i === void 0 ? (this._t = null, this._v = null, c = null) : (this._t = gt(c), this._v = c), this._r = l, this._p = o[3], this._n = o[4], this._c = s, c;
}, this.clear = () => {
r._c = null;
}, this.context = { getCoords() {
const o = r._c;
if (!o) throw new Error(Jr);
return o;
}, getCell() {
const o = r._c;
if (!o) throw new Error(Jr);
if (this.excludeCellDetails) throw new Error("IteratorContext can only return a cell if the forEach excludeCellDetails has not been set to false.");
const s = r._r, i = r._t, l = r._v;
return l !== null || s ? new Kn(n, o, i, l, s, r._p, r._n) : new Kn(n, o);
}, getType: () => r._t, getA1(o) {
if (!r.context) throw new Error(Jr);
let s = r._c;
return o && (s = { ...r._c, ...o }), n.resolveRange(s).toString();
}, toJSDate(o) {
if (r._t !== q.Number) return null;
let s = o;
if (s === void 0) s = r._v;
else if (typeof s != "number") throw new Error("The arguments are not valid.");
return no(s, n.date1904);
} };
}
}
const In = (a, e) => {
if (a || e) return a && e ? { ...a, ...e } : a || e;
}, Lu = (a, e, t, n = O.Orientation.Row) => {
const r = a.getRange(e, { excludeHidden: n }), o = r.forEach((p, S) => ({ break: S.getCoords() }), { excludeCellDetails: !0, orientation: n });
if (!o) return;
const s = n === O.Orientation.Row, i = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
let h = null;
const u = a.getRange(o).getMerges();
let d = u.length > 0 ? 1 + (s ? u[0].rowEnd - u[0].rowStart : u[0].colEnd - u[0].colStart) : 1;
const g = s ? o.rowIndex : o.colIndex;
if (r.forEach((p, S) => {
const E = S.getCoords(), y = s ? E.colIndex : E.rowIndex, C = s ? E.rowIndex : E.colIndex;
if (C === g) i.set(y, p);
else {
if (C !== g + d) return ru;
typeof p == "string" ? h = !1 : p !== null && l.set(y, p);
}
if (h != null) return ru;
}, { orientation: n, excludeCellDetails: !0, address: e }), h === null) {
const p = l.entries();
let S = p.next();
for (; h === null && !S.done; ) {
const [E, y] = S.value, C = i.get(E);
C && (typeof C == "string" ? c.set(E, C) : h = !1), S = p.next();
}
h = h ?? c.size > 0;
}
const m = { colStart: o.colIndex, rowStart: o.rowIndex, colEnd: e.colEnd, rowEnd: e.rowEnd };
if (m.colStart > m.colEnd || m.rowStart > m.rowEnd || D.isSingleCell(m)) return null;
const f = Math.min(Math.max(t?.colIndex ?? 0, m.colStart), m.colEnd), _ = Math.min(Math.max(t?.rowIndex ?? 0, m.rowStart), m.rowEnd);
return { coords: m, options: { ...Vr.DefaultRangeOptions, hasHeader: h, orientation: n, offset: n === O.Orientation.Row ? f - m.colStart : _ - m.rowStart }, headers: c };
}, Bu = (a, e, t = null) => $r.fromArray(a, (n, r) => {
const o = n?.[1];
if (o == null) return null;
let s = n[0] ?? null;
switch (o) {
case q.String:
s = e.getById(s);
break;
case q.Error:
s = Ee.getBuiltInById(s);
case q.RichData:
}
return s;
}, (n, r) => {
const o = gt(n);
let s = n;
switch (o) {
case q.String:
s = e.add(s);
break;
case q.Error:
s = s.getCode();
case q.RichData:
}
return [s, o];
}, t), zu = (a, e) => {
const t = [], n = e ? O.Orientation.Column : O.Orientation.Row, r = a.length;
for (let o = 0; o < r; o++) {
const s = a[o], i = s[0], l = s[1], c = l.length;
for (let h = 0; h < c; h++) {
const u = l[h], d = u[0], g = u[1].length - 1, m = { colStart: e ? i : d, rowStart: e ? d : i, colEnd: e ? i : d + g, rowEnd: e ? d + g : i, value: new qt({ colStart: e ? i : d, rowStart: e ? d : i, colEnd: e ? i : d + g, rowEnd: e ? d + g : i }, n) };
t.push(m);
}
}
return t;
}, po = (a, e, t = -1) => {
if (!a || a.length === 0) return null;
const n = a.length === 1 && a[0].rowStart === a[0].rowEnd && a[0].colStart === a[0].colEnd, r = t === -1 ? a.length - 1 : Math.min(Math.max(0, t), a.length - 1);
return { cell: e ?? { rowIndex: a[r].rowStart, colIndex: a[r].colStart }, ranges: n ? [] : [...a], rangeIndex: n ? -1 : r };
}, Lr = (a) => {
if (!a) return null;
const e = [];
if (a.ranges && a.ranges.length > 0) {
const t = Math.max(0, Math.min(a.rangeIndex ?? 0, a.ranges.length));
for (let n = t; n < a.ranges.length; n++) e.push(a.ranges[n]);
for (let n = 0; n < t; n++) e.push(a.ranges[n]);
} else a.cell && e.push(D.cellToRange(a.cell));
return e;
}, Pe = (a, e) => {
if (!a || a.length === 0) return null;
let t = a.length - 1;
const n = a[t], r = a[0];
if (!r || !r) return null;
const o = a.length === 1 && r.rowStart === r.rowEnd && r.colStart === r.colEnd;
return n ? { cell: { rowIndex: n.rowStart, colIndex: n.colStart }, ranges: o ? [] : [...a], rangeIndex: o ? -1 : t } : null;
}, Pu = "Item has been closed. No further operations are allowed.";
class Xi {
constructor(e) {
if (this._emitter = null, this._closed = !1, !e) throw new Error("Anchored.ConstructorOptions is required");
if (this._options = { ...e }, !this._options.initialAnchor) throw new Error("Initial anchor is required");
const t = this;
this._transactions = this._options.transactions ?? new Xt({ transient: !0 }), this._emitter = new mt(this, this._transactions), this._updateState({ anchor: this._options.initialAnchor }, { description: e?.createDescription ?? "Create Anchored Item" }), this._options.setContainerShiftCallback?.((n) => t._processContainerShift(n)), this._options.setContainerLayoutCallback?.(() => {
t._processContainerLayout();
}), this._options.setContainerDeleteCallback?.(() => {
t._processContainerDelete();
}), this._options.setContainerProtectionCallback?.(() => {
t._processContainerProtection();
}), this._transactionsRemoveListener = this._transactions.addStateListener(this, { onBeforeCommitStart(n, r, o) {
t._processBeforeCommitStart(n, r, o);
}, onAfterStateChange(n, r, o) {
t._processStateChange(n, r, o), t._processAnchorCoords(), t._emitter.notify("onAnchorCoordsChange");
}, onRestoreOrRevert(n, r, o) {
t._processRestoreOrRevert(n, r, o);
} });
}
_getEmitter() {
return this._emitter;
}
delete(e) {
this._options.deleteFromContainer?.(e);
}
getAnchorCoords() {
return this._getState()?.anchor ?? null;
}
getAnchorType() {
return this._getState()?.anchorType ?? bt.Type.TwoCell;
}
isProtected() {
return this._options.isProtected?.() ?? !1;
}
beginCommit(e) {
return this._beginCommit(e);
}
_getState() {
if (this._closed) throw new Error(Pu);
return this._transactions.getState(this);
}
_beginCommit(e) {
return this._transactions.beginCommit(typeof e == "string" ? { description: e } : e);
}
_getTransactions() {
return this._transactions;
}
_updateState(e, t, n) {
if (this._closed) throw new Error(Pu);
if (!e) return;
const r = this._beginCommit(t?.description);
try {
r.updateState(this, e);
let o = !1;
if (n) for (let s = 0; s < n.length; s++) {
const i = n[s];
o = o || i === "onAnyChange", this._emitter.notify(i);
}
!o && n && n.length > 0 && this._emitter.notify("onAnyChange"), r.commit();
} catch (o) {
throw r.rollback(), o;
}
return this;
}
_processContainerShift(e) {
let t = null;
const n = { anchor: e.after };
return e.after || (n.isDeleted = !0, t = ["onDelete"]), this._updateState(n, { description: "Update Anchor" }, t), e.after;
}
_processBeforeCommitStart(e, t, n) {
}
_processStateChange(e, t, n) {
}
_processRestoreOrRevert(e, t, n) {
this._emitter.notify("onInvalidated");
}
_processAnchorCoords() {
}
_processContainerLayout() {
}
_getDescription() {
return null;
}
_delete() {
const e = this._getDescription(), t = "Delete", n = e ? `${t} ${e}` : t, r = this._beginCommit(n);
try {
this._processDelete(), r.commit();
} catch (o) {
throw r.rollback(), o;
}
}
_processContainerDelete() {
this._processDelete();
}
_processDelete() {
}
_processContainerProtection() {
this._emitter.notify("onProtectedChange");
}
addListeners(e, t) {
return this._emitter.addListeners(e, t);
}
isClosed() {
return this._closed;
}
_processClose() {
this._closed = !0, this._emitter.notify("onClose"), this._transactionsRemoveListener?.();
}
close() {
this._closed || this._processClose();
}
get isIAnchored() {
return !0;
}
}
var Kr, Zn;
(Zn = Kr || (Kr = {})).fastStringToCol = F0, Zn.fastStringToCell = Pr, Zn.fastStringToRange = At, Zn.rangeToString = Rn, Zn.cellToString = Xn, Zn.normalizeA1ToR1C1 = L0, Zn.resolveRelativeToA1 = D0;
const fS = (a, e) => a.offset - e.offset, Hu = (a) => {
if (!a || a.size === 0) return [];
let e = [];
return a.forEach((t, n) => {
t && Object.keys(t).length !== 0 && e.push({ ...t, offset: n });
}), e.sort(fS);
};
class pS extends Xi {
constructor(e) {
super({ ...e, createDescription: "Insert AutoSort" }), this._apply = e.apply, this._processUpdate = e.processUpdate, this._fromJSON(e.json);
}
getRange() {
return this._getState().anchor;
}
getFieldAt(e) {
const t = this._getState().byOffset.get(e) ?? null;
return t ? Object.keys(t).length === 0 || Object.keys(t).length === 1 && t.hasOwnProperty("offset") ? null : { collatorOptions: null, ...t } : null;
}
insertSort() {
return null;
}
getSort() {
return null;
}
apply(e) {
const t = this._getState().byOffset, n = new Map(t);
for (let r = 0; r < e.length; r++) {
const o = { ...e[r] }, s = o.offset;
delete o.offset, n.set(s, o);
}
return this._updateState({ byOffset: n }, { description: "Set Sort Criteria" }), this.reapply();
}
setFieldAt(e, t) {
const n = this._getState().byOffset, r = new Map(n);
return t && Object.keys(t).length > 0 ? r.set(e, t) : r.delete(e), this._updateState({ byOffset: r }, { description: "Sort" }), this.reapply();
}
_processStateChange(e, t, n) {
super._processStateChange(e, t, n), this._processUpdate?.();
}
reapply() {
const e = this._getState(), t = Hu(e.byOffset);
return this._apply?.(t), this;
}
clear() {
return this._updateState({ byOffset: /* @__PURE__ */ new Map() }, { description: "Clear Sort" }), this.reapply();
}
_fromJSON(e) {
const t = e ?? {}, n = { byOffset: /* @__PURE__ */ new Map() };
if (t.fields) for (let r = 0; r < t.fields.length; r++) {
let o = t.fields[r];
const s = o.offset;
o = { ...t.fields[r] }, delete o.offset, n.byOffset.set(s, o);
}
this._updateState(n, { description: "Load" });
}
toJSON() {
const e = {}, t = this._getState();
t.anchor && (e.ref = Kr.rangeToString(t.anchor, this._options.maxRangeCoords));
const n = Hu(t.byOffset);
return n.length > 0 && (e.fields = n), Object.keys(e).length === 0 ? null : e;
}
}
const _S = (a, e) => a.offset - e.offset, Ga = (a) => {
if (!a || a.size === 0) return [];
let e = [];
return a.forEach((t, n) => {
t && Object.keys(t).length !== 0 && e.push({ ...t, offset: n });
}), e.sort(_S);
}, Wu = (a, e = /* @__PURE__ */ new Map()) => {
if (!a || a.length === 0) return e;
for (let t = 0; t < a.length; t++) {
const n = { ...a[t] }, r = n.offset;
delete n.offset, e.set(r, n);
}
return e;
}, Ua = (a) => {
let e = 0;
const t = a.entries();
let n = null;
do
n = t.next(), n.value?.[1] && n.value[1].hiddenButton && e++;
while (!n.done);
return e;
};
class pm extends Xi {
constructor(e) {
super({ ...e, createDescription: "Insert AutoFilter" }), this._apply = e.apply, this._processUpdate = e.processUpdate, e.setFilterCoordsCallback?.((t) => {
this._getState().anchor;
}), this._fromJSON(e.json);
}
getCoords() {
return this._getState().anchor;
}
getFieldAt(e) {
const t = this._getState().byOffset.get(e) ?? null;
return t ? Object.keys(t).length === 0 || Object.keys(t).length === 1 && t.hasOwnProperty("offset") ? null : { hiddenButton: !1, criteria: F.EmptyArray, ...t } : null;
}
insertSort() {
return null;
}
getSort() {
return null;
}
apply(e) {
const t = this._getState().byOffset, n = new Map(t);
return Wu(e, n), this._updateState({ byOffset: n, hiddenCount: Ua(n) }, { description: "Set Filter Criteria" }), this.reapply();
}
setFieldAt(e, t) {
const n = this._getState(), r = n.anchor.colEnd - n.anchor.colStart + 1;
if (e < 0 || e > r - 1) throw new Error(`Invalid range: '${e}'`);
const o = n.byOffset, s = new Map(o);
t && Object.keys(t).length > 0 ? s.set(e, t) : s.delete(e);
const i = o.get(e)?.hiddenButton === !0 ? 1 : 0, l = t?.hiddenButton === !0 ? 1 : 0;
return this._updateState({ byOffset: s, hiddenCount: Math.min(r, Math.max(0, n.hiddenCount + l - i)) }, { description: "Set Filter Criteria" }), this.reapply();
}
getShowFilterButton() {
const e = this._getState(), t = e.anchor, n = t.colEnd - t.colStart + 1;
return e.hiddenCount < n;
}
setShowFilterButton(e) {
const t = this.getAnchorCoords(), n = t.colEnd - t.colStart + 1;
let r = Array(n);
const o = this._getState().byOffset, s = Ga(o);
for (let l = 0; s && l < s.length; l++) {
const c = { ...s[l] };
r[c.offset] = c, e ? delete c.hiddenButton : c.hiddenButton = !0;
}
if (!e) for (let l = 0; l < r.length; l++) r[l] || (r[l] = { hiddenButton: !0 });
const i = /* @__PURE__ */ new Map();
for (let l = 0; l < r.length; l++) {
const c = r[l];
i.set(l, c);
}
return this._updateState({ byOffset: i, hiddenCount: e ? i.size : 0 }, { description: (e ? "Hide" : "Show") + " Filter Buttons" }), this._processUpdate?.(), this;
}
_processStateChange(e, t, n) {
super._processStateChange(e, t, n), this._processUpdate?.();
}
_processContainerShift(e) {
if (e.after && e.orientation === O.Orientation.Column) {
let t = e.intersect.colStart - e.before.colStart, n = e.amount;
t <= 0 && (n -= t, t = 0);
const r = this._getState().byOffset, o = new Map(r);
if (r.forEach((s, i) => {
s && Object.keys(s).length !== 0 && (i >= t && o.delete(i), i > t && o.set(i + n, s));
}), n > 0 && this._getState().hiddenCount > 0) for (let s = t; s < t + n; s++) o.set(s, { hiddenButton: !0 });
this._updateState({ byOffset: o, hiddenCount: Ua(o), sort: null }, { description: "Update Fields" });
}
return super._processContainerShift(e);
}
reapply() {
const e = this._getState(), t = Ga(e.byOffset);
return this._apply?.(t), this;
}
clear() {
return this._updateState({ byOffset: /* @__PURE__ */ new Map(), hiddenCount: 0, sort: null }, { description: "Set Filter Criteria" }), this.reapply();
}
_fromJSON(e) {
const t = e ?? {}, n = { byOffset: /* @__PURE__ */ new Map(), hiddenCount: 0 };
t.fields && (Wu(t.fields, n.byOffset), n.hiddenCount = Ua(n.byOffset)), t.sort, this._updateState(n, { description: "Load" });
}
toJSON() {
const e = {}, t = this._getState();
t.anchor && (e.ref = Rn(t.anchor, this._options.maxRangeCoords));
const n = Ga(t.byOffset);
return n.length > 0 && (e.fields = n), t.sort, Object.keys(e).length === 0 ? null : e;
}
}
const Hl = "A table must have a least one row for the data.", ju = "Table1", Rs = Object.freeze({ showRowStripes: !0, showColumnStripes: !1, showFirstColumn: !1, showLastColumn: !1 }), Vu = (a, e, t) => {
if (a.length !== e.length) return console.warn("make columns the same length"), !1;
const n = /* @__PURE__ */ new Set();
for (let l = 0; l < e.length; l++) {
const c = e[l]?.name;
c && n.add(c.toLocaleLowerCase());
}
for (let l = 0; t && l < t.length; l++) {
const c = t[l]?.name;
c && n.add(c.toLocaleLowerCase());
}
const r = (l, c = "") => {
if (!l) return !1;
const h = l.toLocaleLowerCase();
return h === c || !n.has(h);
};
let o = 1;
const s = (l, c, h, u, d = 1e3) => {
if (u(l, h = (h ?? "").trim().toLocaleLowerCase())) return l;
for (; o < d; ) try {
const g = c + ++o;
if (u(g, h)) return g;
} catch {
}
throw new Error(`Unable to find valid name for '${c}'.`);
};
let i = 0;
for (let l = 0; l < a.length; l++) {
const c = a[l]?.name;
if (c && c === e[l]?.name) continue;
const h = s(c, a[l]?.name || "Column", e[l]?.name, r);
n.add(h.toLocaleLowerCase()), e[l]?.name !== h && (a[l].name = h, i++);
}
return i > 0;
};
class SS {
constructor(e, t, n, r) {
this._name = e, this._filter = t, this._sort = n, this._offset = r;
}
getName() {
return this._name;
}
getField() {
return this._filter ? this._filter.getFieldAt(this._offset) ?? null : null;
}
setField(e) {
return this._filter ? (this._filter.setFieldAt(this._offset, e), this) : this;
}
getSortField() {
return this._sort ? this._sort.getFieldAt(this._offset) : null;
}
setSortField(e) {
return this._sort ? (this._sort.setFieldAt(this._offset, e), this) : this;
}
reapply() {
return this._filter?.reapply(), this;
}
clear() {
return this._filter?.setFieldAt(this._offset, null), this._sort?.setFieldAt(this._offset, null), this;
}
hasHiddenButton() {
return this._filter?.getFieldAt(this._offset)?.hiddenButton ?? !1;
}
}
class wS extends Fg {
constructor(e, t, n, r) {
super({ ...r, type: "namedTable" }), this._names = e, this._sheet = t, this._table = n;
const o = this;
this._table.addListeners({ onDelete: () => {
o._options.deleteFromContainer ? o._options.deleteFromContainer?.() : o._delete();
}, onAnyChange: () => {
o._emitter.notify("onAnyChange");
}, onAnchorCoordsChange: () => {
o._emitter.notify("onAnyChange");
} }, { transactional: !0 });
}
async select(e) {
return await this._table.select(e), this;
}
getRanges() {
return this._names.getRanges(this._table.getUsedRange());
}
getScope() {
return null;
}
getType() {
return "table";
}
getName() {
return this._table.getName();
}
getValue() {
return this._table;
}
}
class yS extends Xi {
constructor(e) {
if (super({ ...e, createDescription: "Insert Table" }), this._isUpdatingHeader = !1, this._colHeadersSizeUnlistener = null, this._rowHeadersSizeUnlistener = null, this._visibleRange = null, this._isHeaderVisible = !0, this._isTotalVisible = !0, this._isFirstColumnVisible = !0, this._isLastColumnVisible = !0, this._range = null, !e.json) throw new Error("json is required");
if (!e.json.ref) throw new Error("json.ref is required");
const t = this;
this._styles = e.styles ?? e.sheet?.getStyles() ?? new is(), this._names = e.names, this._sheet = e.sheet, this._processTableUpdate = e.processTableUpdate, this._setNameOnContainer = e.setNameOnContainer, this._options = { ...e }, this._styleCache = null, this._stylePropsCache = null, this._stylesRemoveListener = this._styles.addListeners({ onTableStylesChange() {
t._styleCache = null, t._stylePropsCache = null, t._getEmitter().notify("onStyleChange"), t._getEmitter().notify("onAnyChange");
} });
const n = { ...e?.json };
if (e.sheet) {
const r = e.sheet;
if (this._autoExpandRemoveListener = r.getEntireRange().addListener((i) => {
if (i.trigger !== "setCells" || i.isUndo) return;
const l = t.getAnchorCoords();
if (!l) return;
let c = i.getSource().getCoords();
Array.isArray(c) && (c = c[0]);
let h = null;
if (c.rowStart >= l.rowStart && c.rowEnd <= l.rowEnd && c.colStart >= l.colStart && c.colStart <= l.colEnd + 1 && c.colEnd > l.colEnd) {
const u = { ...c, colStart: l.colEnd + 1 };
if (r.getRange(u).isContentful()) {
const d = { ...u, rowStart: l.rowStart, rowEnd: u.rowStart - 1 };
if (d.rowEnd - d.rowStart < 0 || !r.getRange(d).isContentful()) {
const g = { ...u, rowStart: u.rowEnd + 1, rowEnd: l.rowEnd };
(g.rowEnd - g.rowStart < 0 || !r.getRange(g).isContentful()) && (h = { ...l, colEnd: c.colEnd });
}
}
} else if (!t.getShowTotals() && c.colStart >= l.colStart && c.colEnd <= l.colEnd && c.rowStart >= l.rowStart && c.rowStart <= l.rowEnd + 1 && c.rowEnd > l.rowEnd) {
const u = { ...c, rowStart: l.rowEnd + 1 };
if (r.getRange(u).isContentful()) {
const d = { ...u, colStart: l.colStart, colEnd: u.colStart - 1 };
if (d.colEnd - d.colStart < 0 || !r.getRange(d).isContentful()) {
const g = { ...u, colStart: u.colEnd + 1, colEnd: l.colEnd };
(g.colEnd - g.colStart < 0 || !r.getRange(g).isContentful()) && (h = { ...l, rowEnd: c.rowEnd });
}
}
}
if (h && r.getRange(h).getMerges().length > 0 && (h = null), h && r.getTables().getItems({ address: h }).length !== 1 && (h = null), h) {
const u = t._beginCommit("Table Auto Expansion");
try {
t.resize(h), u.commit({ viewAfter: null });
} catch (d) {
u.rollback(), console.warn("Unable to AutoExpand"), console.warn(d);
}
}
}, { transactional: !1, ignoreShifts: !0 }), this._headerValueListener = () => {
if (this._isUpdatingHeader) return;
const i = this._columnsFromSheet();
i && this._updateColumns(i.columns, !1, i.forceUpdate, null);
}, e.readSheetHeader) {
const i = this._columnsFromSheet();
n.columns = i.columns;
}
const o = () => {
const i = this.getAnchorCoords();
let l = 0, c = 0;
if (i && (l = r.getColumnHeaders().findVisibleIndex(i.colEnd).min, c = r.getRowHeaders().findVisibleIndex(i.rowEnd).min), i && (l < i.colEnd || c < i.rowEnd)) {
const h = r.getColumnHeaders(), u = r.getRowHeaders(), d = h.findVisibleIndex(i.colStart).max, g = u.findVisibleIndex(i.rowStart).max;
this._visibleRange = { colStart: d, colEnd: l, rowStart: g, rowEnd: c }, this._isHeaderVisible = !u.at(i.rowStart).isHidden(), this._isTotalVisible = !u.at(i.rowEnd).isHidden(), this._isFirstColumnVisible = !h.at(i.colStart).isHidden(), this._isLastColumnVisible = !h.at(i.colEnd).isHidden();
} else this._visibleRange = null, this._isHeaderVisible = !0, this._isTotalVisible = !0, this._isFirstColumnVisible = !0, this._isLastColumnVisible = !0;
}, s = { onSizesChange: () => {
o();
} };
this._colHeadersSizeUnlistener = r.getColumnHeaders().addListeners(s), this._rowHeadersSizeUnlistener = r.getRowHeaders().addListeners(s), o();
}
this._fromJSON(n), this._names && (this._namedItem = this._createNamed(), this._namedItem && this._names.add(this._namedItem));
}
getSnapshot(e) {
const t = this.toJSON(), n = this.getAnchorCoords(), r = this.getName(), o = { ...t };
delete o.ref;
const s = this, i = Object.freeze({ ...e });
let l = !1;
return { async copyTo(c, h) {
const u = c.tables, d = c.range;
({ ...i, ...h }).isCut && !l && (s.delete(), l = !0);
const g = { colStart: d.colStart, rowStart: d.rowStart, colEnd: n.colEnd - n.colStart + d.colStart, rowEnd: n.rowEnd - n.rowStart + d.rowStart };
return u.add(g, { json: o, isLoad: !0, hasHeader: !0, styleName: o.styleOptions?.name ?? null }), g;
}, getCoords: () => n, getSource: () => s, getName: () => r, getMarkOptions: () => i, isISnapshot: !0 };
}
getAnchorType() {
return bt.Type.TwoCell;
}
getStyle() {
if (this._styleCache) return this._styleCache;
const e = this._getState();
return e ? (this._styleCache = this._styles.getTableStyle(e.styleOptions.name) ?? this._styles.getDefaultTableStyle(), this._styleCache) : this._styles.getTableStyle(null);
}
addRows(e, t = 1) {
const n = { ...this._getState().anchor };
return n.rowEnd += t, this._modifyTable({ anchor: n }, "Add Table Row" + (t > 1 ? "s" : "")), this;
}
deleteRowsAt(e, t = 1) {
let n = { ...this._getState().anchor };
return n.rowEnd -= t, n.rowEnd < n.rowStart && (n = null), this._modifyTable({ anchor: n }, "Delete Table Row" + (t > 1 ? "s" : "")), this;
}
addColumn(e, t) {
const n = this._getState(), r = { ...n.anchor };
r.colEnd += 1;
const o = [], s = { name: `${t ?? n.columns[e - 1]?.name ?? `Column${e + 1}`}3` };
o.push(s);
const i = [...n.columns.slice(0, e), ...o, ...n.columns.slice(e)];
return this._modifyTable({ anchor: r, columns: i }, "Add Table Column"), s;
}
getColumns() {
return this._getState()?.columns;
}
convertToRange(e = Number.MAX_SAFE_INTEGER) {
let t = this._beginCommit("Convert to Range");
try {
if (this._sheet) {
const n = this.getAnchorCoords(), r = (n.colEnd - n.colStart + 1) * (n.rowEnd - n.rowStart + 1);
if (r > e) throw new Error(`There are ${r} and there is a limit of ${e}.`);
const o = this._sheet.getRange(n), s = o.startIncrementalUpdates({ orientation: O.Orientation.Column });
o.forEach((i, l) => {
const c = l.getCoords(), h = l.getCell();
s.pushAt(c.rowIndex, c.colIndex, { style: h.getStyle(!1) });
}, { includeEmpty: !0, orientation: O.Orientation.Column }), s.apply();
}
this.delete();
} catch {
t.rollback(), t = null;
}
return t && t.commit(), this._sheet.getRange(this._getState()?.anchor);
}
resize(e, t = "Resize Table") {
let n = this._sheet.getRange(e).getCoords();
const r = this._getState().anchor;
if (r.rowStart !== n.rowStart || n.colEnd < r.colStart || n.colStart > r.colEnd) throw new Error("The top of the table must not change and the new table location must overlap with the original table.");
const o = this._beginCommit(t);
try {
n = this._options.setContainerCoords(e), D.isEqualRanges(n, r) || this._modifyTable({ anchor: n }), o.commit();
} catch (s) {
throw console.warn(s), o.rollback(), s;
}
return this._sheet.getRange(n);
}
getName() {
return this._getState()?.name;
}
setName(e) {
const t = this._beginCommit(`Set Table Name '${e}'`);
try {
this._modifyTable({ name: e }), t.commit();
} catch (n) {
throw t.rollback(), n;
}
return this;
}
getDescription() {
return this._getState()?.description;
}
setDescription(e) {
return this._modifyTable({ description: e });
}
select(e) {
return this.getUsedRange().select(e);
}
getRange() {
return this._range ? this._range : this._getState() ? this._range = this._sheet.getRange(this._getState().anchor) : Un;
}
_processRestoreOrRevert(e, t, n) {
this._styleCache = null, super._processRestoreOrRevert(e, t, n);
}
_processAnchorCoords() {
this._range = null, super._processAnchorCoords();
}
getUsedRange() {
const e = this._getUsedCoords();
return e ? this._sheet.getRange(e) : Un;
}
_getUsedCoords() {
const e = this._getState(), t = e.headerRowCount, n = e.totalsRowCount, r = e.anchor;
if (!r) return null;
const o = { ...r, rowStart: r.rowStart + t, rowEnd: r.rowEnd - n };
return o.rowEnd < o.rowStart || o.colEnd < o.colStart ? null : o;
}
getHeaderRange() {
const e = this._getHeaderCoords();
return e ? this._sheet.getRange(e) : Un;
}
_getHeaderCoords() {
const e = this._getState(), t = e.headerRowCount;
if (t < 1) return null;
const n = e.anchor;
return n ? { ...n, rowEnd: n.rowStart + t - 1 } : null;
}
getTotalRange() {
const e = this._getTotalCoords();
return e ? this._sheet.getRange(e) : Un;
}
_getTotalCoords() {
const e = this._getState(), t = e.totalsRowCount;
if (t < 1) return null;
const n = e.anchor;
return n ? { ...n, rowStart: n.rowEnd - t + 1 } : null;
}
getStyleOptions() {
return this.isClosed() ? Rs : this._getState()?.styleOptions;
}
updateStyleOptions(e, t = "Update Style Info") {
const n = this.getStyleOptions(), r = e ? { ...n, ...e } : Rs;
return this._modifyTable({ styleOptions: r }, t), this._styleCache = null, this._getEmitter().notify("onStyleChange"), this;
}
getStyleAt(e) {
let t = this._stylePropsCache;
return t || (t = this.getStyle().getRanged(this), this._stylePropsCache = t), eo(this._styles, t, D.cellToRange(e));
}
getShowTotals() {
return this._getState()?.totalsRowCount > 0;
}
setShowTotals(e) {
return this._modifyTable({ totalsRowCount: e ? 1 : 0 }, "Toggle Show Totals");
}
getShowHeaders() {
return this._getState()?.headerRowCount > 0;
}
setShowHeaders(e) {
return this._modifyTable({ headerRowCount: e ? 1 : 0 }, "Toggle Show Headers");
}
getShowFilterButton() {
const e = this.getFilter();
return !!e && e.getShowFilterButton();
}
setShowFilterButton(e) {
const t = this.getFilter();
return t ? (t.setShowFilterButton(e), this) : this;
}
_applyFilterAndSort() {
console.log("apply Filter", this.getFilter(), this.getSort()), this._processTableUpdate?.(), this._getEmitter().notify("onAnyChange");
}
_processUpdate() {
this._processTableUpdate?.(), this._getEmitter().notify("onAnyChange");
}
_createFilter(e) {
const t = this;
return new pm({ initialAnchor: this._getUsedCoords(), maxRangeCoords: this._options.maxRangeCoords, json: e, transactions: this._getTransactions(), setContainerShiftCallback(n) {
t._filterShiftCallback = n;
}, setFilterCoordsCallback(n) {
t._filterCoordsCallback = n;
}, deleteFromContainer: (n) => {
this._updateState({ filter: null }, { description: n?.description ?? "Delete Filter" }), t._processUpdate?.();
}, apply: (n) => {
t._applyFilterAndSort();
}, processUpdate: () => {
t._processUpdate?.();
}, isProtected: () => t.isProtected() });
}
insertFilter() {
let e = this.getFilter();
return e || (e = this._createFilter(), this._updateState({ filter: e }, { description: "Insert Filter" }), e);
}
getFilter() {
return this._getState()?.filter ?? null;
}
_createSort(e) {
const t = this;
return new pS({ initialAnchor: this._getUsedCoords(), maxRangeCoords: this._options.maxRangeCoords, json: e, transactions: this._getTransactions(), deleteFromContainer: (n) => {
this._updateState({ sort: null }, { description: n?.description ?? "Delete Sort" }), t._processUpdate?.();
}, apply: (n) => {
t._applyFilterAndSort();
}, processUpdate: () => {
t._processUpdate?.();
}, isProtected: () => t.isProtected() });
}
insertSort() {
let e = this.getSort();
return e || (e = this._createSort(), this._updateState({ sort: e }, { description: "Insert Sort" }), e);
}
getSort() {
return this._getState()?.sort ?? null;
}
getColumnFilter(e) {
const t = this.getFilter();
if (!t) return null;
const n = this.getSort();
let r = null;
return r = this._getState()?.columns[e], r === null ? null : new SS(r.name, t, n, e);
}
getVisibleRefRangeCoords() {
return this._visibleRange ? this._visibleRange : this.getAnchorCoords();
}
getVisibleCellCoords(e) {
return e && this._visibleRange ? { colIndex: Math.min(this._visibleRange.colEnd, Math.max(this._visibleRange.colStart, this._sheet.getColumnHeaders().findVisibleIndex(e.colIndex).min)), rowIndex: Math.min(this._visibleRange.rowEnd, Math.max(this._visibleRange.rowStart, this._sheet.getRowHeaders().findVisibleIndex(e.rowIndex).min)) } : e;
}
isHeaderVisible() {
return this._isHeaderVisible;
}
isTotalVisible() {
return this._isTotalVisible;
}
isFirstColumnVisible() {
return this._isFirstColumnVisible;
}
isLastColumnVisible() {
return this._isLastColumnVisible;
}
_columnsFromSheet() {
const e = this._getHeaderCoords();
if (!e || !this._sheet) {
const n = this.getAnchorCoords();
return { columns: n ? Array(n.colEnd - n.colStart + 1).fill(null) : [], forceUpdate: !0 };
}
const t = { columns: [], forceUpdate: !1 };
return this._sheet.getRange({ ...e, rowEnd: e.rowStart }).forEach((n, r) => {
const o = r.getCell();
t.columns.push({ name: o.toText() }), t.forceUpdate = t.forceUpdate || o.getType() !== q.String;
}, { includeEmpty: !0 }), t;
}
_updateColumns(e, t, n = !1, r) {
if (this._isUpdatingHeader) return;
const o = this._getHeaderCoords(), s = this._getUsedCoords(), i = [];
if (s) {
const d = s.colEnd - s.colStart + 1;
for (let g = 0; g < d; g++) {
const m = e[g];
i.push({ ...m });
}
}
let l = !1;
const c = this._getState().columns;
if (l = t ? ((d, g) => {
const m = /* @__PURE__ */ new Set(), f = (S) => !!S && !m.has(S.toLocaleLowerCase()), _ = (S, E, y, C) => C(S) ? S : E + (y + 1);
let p = 0;
for (let S = 0; S < d.length; S++) {
const E = _(d[S]?.name || g[S]?.name, d[S]?.name || "Column", p, f);
m.add(E.toLocaleLowerCase()), d[S]?.name !== E && (d[S].name = E, p++);
}
return p > 0;
})(i, c) : Vu(i, c, r), !(n || c.length !== i.length || l)) return;
const h = "Update Columns";
this._isUpdatingHeader = !0;
let u = this._beginCommit(h);
try {
if (this._updateState({ columns: i }, { description: h }), this._sheet && o) {
const d = this._sheet.getEntireRange().startIncrementalUpdates({ orientation: O.Orientation.Row });
for (let g = 0; g < i.length; g++) {
const m = i[g].name;
d.pushAt(o.rowStart, o.colStart + g, m);
}
d.apply({ textParser: !1 });
}
} catch {
u.rollback();
}
return u && u.commit(), this._isUpdatingHeader = !1, i;
}
_processDelete() {
this._getState().headerRemoveListener?.(), this._updateState({ headerRemoveListener: null }), super._processDelete();
}
_processFilterUpdate() {
const e = this._getUsedCoords();
console.log("process on Filter and Sort dataRange", e);
}
_processContainerShift(e) {
if (e.isSplit) throw new Error("We can not partially insert or remove cells as this would split a table.");
const t = this._getState();
if (e.after && e.after.rowStart + t.headerRowCount >= e.after.rowEnd + 1) throw new Error(Hl);
const n = e.orientation === O.Orientation.Column;
if (e.amount < 0 && e.after && !n) {
const o = this._getHeaderCoords();
if (o && e.intersect.rowStart <= o.rowEnd && e.intersect.rowEnd >= o.rowStart) throw new Error("We can not remove rows that contain table headers. Remove the table header.");
}
const r = super._processContainerShift(e);
if (n) {
let o = e.amount, s = e.intersect.colStart - e.before.colStart;
if (s <= 0 && o > 0) return;
s < 0 && (o -= s, s = 0);
const i = this._getState()?.columns;
let l = [...i], c = [], h = [];
if (o > 0) {
l.splice(s, 0, ...Array(o).fill(null)), c = [...l];
const u = /* @__PURE__ */ new Set();
for (let _ = 0; _ < i.length; _++) u.add(i[_]?.name?.toLowerCase().trim());
const d = i[s - 1], g = d?.name?.match(/\d+$/);
let m = null, f = 0;
g && (m = g.input.substring(0, g.index), f = parseInt(g[0]));
for (let _ = 0; _ < o; _++) {
let p = { ...d };
c[s + _] = p;
const S = m + (f + _ + 1);
S && !u.has(S.toLowerCase().trim()) && (p.name = S);
}
Vu(c, l, null);
} else c = l, h = c.splice(s, -o);
this._updateState({ columns: c }, { description: "Process Columns" }), this._updateColumns(c, !1, !0, h);
} else e.after || this._updateState({ columns: [] }, { description: "Process Columns" });
return e.after || this._delete(), this._filterShiftCallback && this._filterShiftCallback({ ...e, after: this._getUsedCoords() }), r;
}
_modifyTable(e, t = "Modify Table") {
if (this.isClosed()) throw new Error("Table has been closed. No further operations are allowed.");
const n = this._getState(), r = n.anchor, o = n.headerRowCount, s = this._getHeaderCoords();
let i = this._beginCommit(t);
try {
if (this._updateState(e), e.name !== void 0) {
if (!e.name) throw new Error("Table must have a name.");
this._setNameOnContainer?.(e.name);
}
let l = e.anchor ?? null;
if ((e.anchor !== void 0 || e.headerRowCount !== void 0 || e.totalsRowCount !== void 0) && e.headerRowCount !== void 0 && o !== e.headerRowCount) if (e.headerRowCount > o) {
const c = r.rowStart - (e.headerRowCount - o);
this._sheet && (c < this._options.maxRangeCoords.rowStart || this._sheet.getRange({ ...r, rowStart: c, rowEnd: r.rowStart - 1 }).isContentful()) ? (this._sheet.getRange({ ...r, rowStart: r.rowStart + e.headerRowCount, rowEnd: r.rowStart + e.headerRowCount }).insert(O.Orientation.Row), l = { ...r, rowEnd: r.rowEnd + (e.headerRowCount - o) }) : l = { ...r, rowStart: r.rowStart + (o - e.headerRowCount) };
} else s && this._sheet && this._sheet.doBatch(() => {
this._sheet.getRange(s).clear();
}, {}), l = { ...r, rowStart: r.rowStart + (o - (e.headerRowCount ?? o)) };
if (l) {
let c = n.columns;
const h = e.headerRowCount !== void 0 && e.headerRowCount !== n.headerRowCount || e.totalsRowCount !== void 0 && e.totalsRowCount !== n.totalsRowCount, u = l.colStart !== r.colStart || l.colEnd !== r.colEnd;
let d = [];
if (u) {
const g = [...n.columns];
l.colEnd > r.colEnd ? g.splice(r.colEnd + 1, 0, ...Array(l.colEnd - r.colEnd).fill(null)) : l.colEnd < r.colEnd && (d = g.splice(l.colEnd - 1, r.colEnd - l.colEnd)), l.colStart < r.colStart ? g.splice(0, 0, ...Array(r.colStart - l.colStart).fill(null)) : l.colStart > r.colStart && (d = d.concat(g.splice(0, l.colStart - r.colStart))), c = g;
}
if (this._options.setContainerCoords?.(l), this._updateState({ anchor: l, columns: c }, { description: t }), !this._getUsedCoords()) throw new Error(Hl);
if (u || h) {
const g = h ? { columns: c, forceUpdate: !0 } : this._columnsFromSheet();
g && (this._updateColumns(g.columns, !1, g.forceUpdate, d), this._processHeaderListener());
}
this._filterCoordsCallback?.(l);
}
e.styleOptions !== void 0 && (this._styleCache = null), this._getEmitter().notify("onAnyChange"), i.commit();
} catch (l) {
throw i.rollback(), l;
}
return this;
}
addListeners(e, t) {
return this._emitter.addListeners(e, t);
}
_processStateChange(e, t, n) {
super._processStateChange(e, t, n), this._styleCache = null, this._stylePropsCache = null, this._processTableUpdate?.(), this._getEmitter().notify("onAnyChange");
}
_processHeaderListener() {
if (this._getState().headerRemoveListener?.(), this._sheet) {
let t = this._getHeaderCoords();
if (!t) {
const r = this._getUsedCoords();
t = { ...r, rowEnd: r.rowStart };
}
const n = this._sheet.getRange(t).addListener(this._headerValueListener, { transactional: !0 });
this._updateState({ headerRemoveListener: n });
}
}
toJSON() {
const e = {}, t = this._getState();
if (!t) return null;
if (t.name && (e.name = t.name), t.anchor && (e.ref = Rn(t.anchor, this._options.maxRangeCoords)), t.description && (e.description = t.description), t.headerRowCount !== 1 && (e.headerRowCount = t.headerRowCount), t.totalsRowCount !== 0 && (e.totalsRowCount = t.totalsRowCount), t.columns && (e.columns = [...t.columns]), t.styleOptions) {
const n = F.diffValues(t.styleOptions, { ...Rs, name: null });
n && (e.styleOptions = n);
}
if (t.filter) {
const n = t.filter.toJSON();
n && (e.filter = n, delete e.filter.ref);
}
return e;
}
_createNamed() {
return this._sheet?.getName() && this._names ? new wS(this._names, this._sheet, this, { transactions: this._getTransactions(), json: { name: this.getName() } }) : null;
}
_fromJSON(e) {
const t = e ?? {}, n = { headerRowCount: 1, totalsRowCount: 0 };
var r;
if (t.name && (n.name = t.name), t.ref && (t.ref = (r = t.ref) && typeof r == "string" ? Pt(r) : r), this._names) {
const i = this._names.findValidName(n.name ?? ju);
n.name !== i && (n.name = i);
}
n.name || (n.name = ju), t.description && (n.description = t.description), t.headerRowCount !== void 0 && (n.headerRowCount = t.headerRowCount), t.totalsRowCount !== void 0 && (n.totalsRowCount = t.totalsRowCount), n.columns = t.columns ?? F.EmptyArray, n.styleOptions = { ...Rs, ...t.styleOptions };
const o = "Insert Table";
this._updateState(n, { description: o });
const s = this._columnsFromSheet();
s && (n.columns = this._updateColumns(s.columns, !0, s.forceUpdate, null), delete n.columns), t.sort && (n.sort = this._createSort(t.sort)), t.filter && (n.filter = this._createFilter(t.filter)), this._modifyTable(n, o), this._processHeaderListener();
}
close() {
super.close(), this.isClosed() || (this._autoExpandRemoveListener?.(), this._getState()?.headerRemoveListener?.(), this._updateState({ headerRemoveListener: null }, { description: "Close Table" }), this._stylesRemoveListener?.(), this._colHeadersSizeUnlistener?.(), this._rowHeadersSizeUnlistener?.());
}
get isITable() {
return !0;
}
}
let It = null;
const _o = "TableStyleMedium2", $t = (a, e, t) => {
if (!a.border) return a;
let n = ((o, s, i) => {
if (!o) return o;
let l = null;
return (o.top || o.horizontal) && (s.rowIndex !== i.rowStart || s.colIndex < i.colStart || s.colIndex > i.colEnd) && (l = l ?? { ...o }, delete l.top, o.horizontal && (l.top = o.horizontal)), (o.bottom || o.horizontal) && (s.rowIndex !== i.rowEnd || s.colIndex < i.colStart || s.colIndex > i.colEnd) && (l = l ?? { ...o }, delete l.bottom, o.horizontal && (l.bottom = o.horizontal)), (o.left || o.vertical) && (s.colIndex !== i.colStart || s.rowIndex < i.rowStart || s.rowIndex > i.rowEnd) && (l = l ?? { ...o }, delete l.left, o.vertical && (l.left = o.vertical)), (o.right || o.vertical) && (s.colIndex !== i.colEnd || s.rowIndex < i.rowStart || s.rowIndex > i.rowEnd) && (l = l ?? { ...o }, delete l.right, o.vertical && (l.right = o.vertical)), o.horizontal && (l = l ?? { ...o }, delete l.horizontal), o.vertical && (l = l ?? { ...o }, delete l.vertical), l ?? o;
})(a.border, e, t), r = a;
return n !== a.border && (r = { ...a }, Object.keys(n).length > 0 ? r.border = n : delete r.border), r;
};
class ES {
constructor(e, t, n) {
this._table = e, this._styles = t, this._properties = n;
}
_resolveProperties(e) {
const t = { name: e.name }, n = this._styles, r = Object.values(ar.ElementType), o = r.length;
for (let s = 0; s < o; s++) {
const i = r[s], l = e[i];
if (!l || !F.isObject(l)) continue;
const c = $e.resolveTypedUpdates(Object.freeze(l), Ge, n);
t[i] = c;
}
return Object.freeze(t);
}
getCoords() {
return this._table.getAnchorCoords();
}
getPropertiesAt(e, t) {
const n = this._table, r = this._styles, o = this._properties;
Ja.rowIndex = e, Ja.colIndex = t;
const s = n.getVisibleCellCoords(Ja), i = n.getVisibleRefRangeCoords();
if (!i) return null;
const l = Math.max(0, i.colEnd - i.colStart) + 1, c = Math.max(0, i.rowEnd - i.rowStart) + 1, h = Math.max(0, s.rowIndex - i.rowStart), u = Math.max(0, s.colIndex - i.colStart), d = { rowIndex: h, colIndex: u }, g = n.getStyleOptions();
let m = {}, f = !1, _ = 0;
n.isHeaderVisible() && (_ = n.getShowHeaders() ? 1 : 0, f = _ > h);
let p = !1, S = 0;
n.isTotalVisible() && (S = n.getShowTotals() ? 1 : 0, p = c - S <= h);
let E = u === l - 1 && g.showLastColumn;
n.isLastColumnVisible() || (E = !1);
let y = u === 0 && g.showFirstColumn;
n.isFirstColumnVisible() || (y = !1);
const C = !f && !p;
if (o.wholeTable && (m = o.wholeTable, m.border && (m = $t(m, d, { rowStart: 0, rowEnd: c - 1, colStart: 0, colEnd: l - 1 }))), C && g.showColumnStripes) {
const w = o.firstColumnStripe?.size ?? 1, b = o.secondColumnStripe?.size ?? 1;
let x = u % (w + b);
const I = x < w;
I || (x -= w);
let v = I ? o.firstColumnStripe : o.secondColumnStripe;
if (v) {
const R = { rowIndex: h, colIndex: x }, A = { rowStart: _, rowEnd: c - S - 1, colStart: 0, colEnd: Math.min(l - u, I ? w : b) };
I && x === 0 && u > 0 && v.border?.left && o.secondColumnStripe?.border.right && (v = { ...v }, v.border = { ...v.border }, delete v.border.left), I && x === w - 1 && u < l - 1 && v.border?.right && o.secondColumnStripe?.border.left && (v = { ...v }, v.border = { ...v.border }, delete v.border.right);
const M = v.border ? $t(v, R, A) : v;
m = $e.resolveTypedUpdates(M, Ge, r, m);
}
}
if (C && g.showRowStripes) {
const w = _, b = o.firstRowStripe?.size ?? 1, x = o.secondRowStripe?.size ?? 1;
let I = (h - w) % (b + x);
const v = I < b;
v || (I -= b);
let R = v ? o.firstRowStripe : o.secondRowStripe;
if (R) {
const A = { colIndex: u, rowIndex: I }, M = { colStart: 0, colEnd: l - 1, rowStart: 0, rowEnd: Math.min(c - h, v ? b : x) };
v && I === 0 && h > w && R.border?.top && o.secondRowStripe?.border.bottom && (R = { ...R }, R.border = { ...R.border }, delete R.border.top), v && I === b - 1 && h < c - 1 && R.border?.bottom && o.secondRowStripe?.border.top && (R = { ...R }, R.border = { ...R.border }, delete R.border.bottom);
const T = R.border ? $t(R, A, M) : R;
m = $e.resolveTypedUpdates(T, Ge, r, m);
}
}
if (E && o.lastColumn) {
let w = o.lastColumn;
w.border && (w = $t(w, d, { rowStart: 0, rowEnd: c - 1, colStart: l - 1, colEnd: l - 1 })), m = $e.resolveTypedUpdates(w, Ge, r, m);
}
if (y && o.firstColumn) {
let w = o.firstColumn;
w.border && (w = $t(w, d, { rowStart: 0, rowEnd: c - 1, colStart: 0, colEnd: 0 })), m = $e.resolveTypedUpdates(w, Ge, r, m);
}
if (f && o.headerRow) {
let w = o.headerRow;
w.border && (w = $t(w, d, { rowStart: 0, rowEnd: _ - 1, colStart: 0, colEnd: l - 1 })), m = $e.resolveTypedUpdates(w, Ge, r, m);
}
if (p && o.totalRow) {
let w = o.totalRow;
w.border && (w = $t(w, d, { rowStart: c - S, rowEnd: c - 1, colStart: 0, colEnd: l - 1 })), m = $e.resolveTypedUpdates(w, Ge, r, m);
}
if (f && y && o.firstHeaderCell) {
let w = o.firstHeaderCell;
w.border && (w = $t(w, d, { rowStart: 0, rowEnd: _ - 1, colStart: 0, colEnd: 0 })), m = $e.resolveTypedUpdates(w, Ge, r, m);
}
if (f && E && o.lastHeaderCell) {
let w = o.lastHeaderCell;
w.border && (w = $t(w, d, { rowStart: 0, rowEnd: _ - 1, colStart: l - 1, colEnd: l - 1 })), m = $e.resolveTypedUpdates(w, Ge, r, m);
}
if (p && y && o.firstTotalCell) {
let w = o.firstTotalCell;
w.border && (w = $t(w, d, { rowStart: c - S, rowEnd: c - 1, colStart: 0, colEnd: 0 })), m = $e.resolveTypedUpdates(w, Ge, r, m);
}
if (p && E && o.lastTotalCell) {
let w = o.lastTotalCell;
w.border && (w = $t(w, d, { rowStart: c - S, rowEnd: c - 1, colStart: l - 1, colEnd: l - 1 })), m = $e.resolveTypedUpdates(w, Ge, r, m);
}
return f && o.headerRow && n.getColumnFilter(u) && !n.getColumnFilter(u).hasHiddenButton() && (m.insets = { right: 15 }), m;
}
}
class $u {
constructor(e, t, n, r) {
this._styles = e, this._isBuiltIn = n, this._doDelete = r, this._properties = F.deepFreeze(this._resolveProperties(t)), this.isShownInTableStyles();
}
_resolveProperties(e) {
const t = { name: e.name };
e.table !== void 0 && (t.table = e.table), e.pivot !== void 0 && (t.pivot = e.pivot);
const n = this._styles, r = Object.values(ar.ElementType), o = r.length;
for (let s = 0; s < o; s++) {
const i = r[s], l = e[i];
if (!l || !F.isObject(l)) continue;
const c = $e.resolveTypedUpdates(Object.freeze(l), Ge, n);
t[i] = c;
}
return Object.freeze(t);
}
delete() {
if (!this._doDelete) throw new Error("Not able to delete builtin style.");
this._doDelete(this._properties.name);
}
getRanged(e) {
return new ES(e, this._styles, this._properties);
}
getProperties() {
return this._properties;
}
getName() {
return this._properties.name;
}
isShownInTableStyles() {
return this._properties.table !== !1;
}
isShownInPivotStyles() {
return this._properties.pivot ?? !1;
}
isBuiltIn() {
return this._isBuiltIn;
}
toJSON() {
const e = F.cloneObject(this._properties);
return e.name = this._properties.name, e;
}
get isITableStyle() {
return !0;
}
}
const Ja = { rowIndex: 0, colIndex: 0 };
class CS extends nt {
constructor(e, t) {
super(e, D.EmptyRange, t);
}
isEmpty() {
return this._p === null;
}
getCoords() {
return this._r;
}
cloneWithUpdate(e) {
if (e === void 0) return this;
const t = this._c, n = this._r, r = $e.resolveTypedUpdates(e, Ge, t, this._p);
return new nt(t, n, r);
}
_createShifted(e) {
return new nt(this._c, e, this._p);
}
getShifted(e) {
return e.after ? { ...e.after, value: this._createShifted(D.sanitizeRange(e.after)) } : null;
}
getSplit(e, t) {
const n = this._c, r = this._p;
return [new nt(n, e[0], r), new nt(n, e[1], r)];
}
getMerged(e, t, n) {
const r = this._p, o = e._p;
if (r && !o || o && !r || !r && !o) return;
let s = Object.keys(r), i = Object.keys(o);
if (r.named === ce.BuiltInName.Normal && (s = s.filter((c) => c.toLowerCase() !== ce.BuiltInName.Normal)), o.named === ce.BuiltInName.Normal && (i = i.filter((c) => c.toLowerCase() !== ce.BuiltInName.Normal)), s.length !== i.length) return;
for (let c = 0; c < s.length; c++) {
const h = s[c], u = r[h], d = o[h];
if (!F.deepEqual(u, d)) return;
}
const l = this._c;
return new nt(l, t, this._p);
}
getPropertiesAt(e, t) {
return this._p;
}
toJSON() {
return F.toSafeJSON(this._p);
}
}
class Gu {
constructor(e, t, n, r = null) {
this._name = t.name, this._properties = t, this._rangeStyle = new CS(e, t.style), this._doDelete = n, this._builtInID = r;
}
getRanged() {
return this._rangeStyle;
}
getName() {
return this._name;
}
isHidden() {
return this._properties.hidden ?? !1;
}
getILevel() {
return this._properties.iLevel ?? null;
}
getBuiltInID() {
return this._builtInID;
}
delete() {
this._doDelete?.(this);
}
toJSON() {
return this._properties ? F.toSafeJSON(this._properties) : null;
}
get isINamed() {
return !0;
}
}
let bS = class {
constructor(a, e, t, n, r) {
this._state = a, this._normalJSON = e ?? {}, this._toJSONInternal = t, this._fromJSONInternal = n, this._onLastEnd = r, this._state.openScopes.add(this), this._isClosed = !1, this._state.byJSONs.set(ta(this._normalJSON), 0), this._state.byIds.set(0, this._normalJSON);
}
endPersist() {
if (!this._state.openScopes.delete(this)) throw new Error("PersistScope is closed.");
this._isClosed = !0, this._state.openScopes.size === 0 && this._onLastEnd();
}
getElementID(a) {
if (this._isClosed) throw new Error("PersistScope is closed.");
const e = ta(a = a ?? {});
let t = this._state.byJSONs.get(e);
return t !== void 0 || (t = this._state.byJSONs.size, this._state.byJSONs.set(e, t), this._state.byIds.set(t, a)), t;
}
getElementJSON(a) {
if (this._isClosed) throw new Error("PersistScope is closed.");
return this._state.byIds.get(a) ?? null;
}
fromJSON(a) {
if (this._isClosed) throw new Error("PersistScope is closed.");
const e = JSON.parse(JSON.stringify(a || {}));
this._fromJSONInternal(e);
const t = e.direct;
if (t) for (let n = 0; n < t.length; n++) {
const r = n, o = t[n], s = ta(o);
this._state.byIds.set(r, o), this._state.byJSONs.set(s, r);
}
}
toJSON() {
if (this._isClosed) throw new Error("PersistScope is closed.");
const a = [];
return this._state.byIds.forEach((e, t) => {
a[t] = e;
}), a.length === 1 && a.splice(0, 1), this._toJSONInternal(a);
}
};
class is {
constructor(e = null, t = null, n = 11) {
this._emitter = null, this._normalRanged = null, this._theme = e ?? new Ng().getDefaultTheme(), this._defaultFontSize = n;
const r = this;
this._emitter = new mt(this), this._schemeLookup = (o) => r._theme.schemeLookup()(o), this._indexedColors = this._fromJSONIndexedColors(t), this._indexedLookup = (o) => {
const s = this._indexedColors[o];
return s ? s.toRGBA() : Ci(o);
}, this._initializeBuiltIns(), this._customCellStyles = /* @__PURE__ */ new Map(), this._customTableStyles = /* @__PURE__ */ new Map(), this._indexedColors = [], this._mruColors = [], this._persistCache = null;
}
_initializeNamedStyles(e, t) {
for (let n = 0; n < e.length; n++) {
const r = e[n], o = { ...r }, s = r.named;
delete o.named;
const i = $e.resolveTypedUpdates(o, Ge, this), l = new Gu(this, { name: s, style: i }, this._hideOrRemoveNamed.bind(this), n);
s === ce.BuiltInName.Normal && (this._normalRanged = l.getRanged(), this._normalStyle = eo(this, null)), t.set(s.toLowerCase(), l);
}
}
_initializeTableStyles() {
const e = (() => {
if (It) return It;
It = /* @__PURE__ */ new Map();
const n = (u, d) => {
if (d === 0) return "TableStyleNone";
let g = "Custom";
return u === "l" ? g = "Light" : u === "m" ? g = "Medium" : u === "d" && (g = "Dark"), `TableStyle${g}${d}`;
}, r = (u, d = 0) => d === 0 ? u : d > 0 ? `${u} lumMod ${100 - d}, lumOff ${d}` : d < 0 ? `${u} lumMod ${100 + d}` : void 0, o = (u) => ({ type: Y.Type.Pattern, patternType: Y.BuiltInSheetPattern.Solid, foreground: u, background: u }), s = (u, d = !1) => {
const g = { fill: u };
return d && (g.weight = 700), g;
}, i = (u, d = U.StrokeStyle.Thin) => ({ style: d, color: u }), l = (u, d) => {
for (let g = 0; g < 7; g++) u.push(d(`accent${g + 1}`));
};
let c = 0, h = [];
h.push(["dk1", r("bg1", -15), "dk1"]), l(h, (u) => [r(u, -25), r(u, 80), u]), c = 1;
for (let u = 0; u < 7; u++) {
const d = n("l", u + c), g = h[u][0], m = h[u][1] ?? g, f = h[u][2] ?? g;
It.set(d.toLocaleLowerCase(), Object.freeze({ name: d, wholeTable: { font: s(g), border: { top: i(f), bottom: i(f) } }, headerRow: { font: s(g, !0), border: { bottom: i(f) } }, totalRow: { font: s(g, !0), border: { top: i(f) } }, firstColumn: { font: s(g, !0) }, lastColumn: { font: s(g, !0) }, firstRowStripe: { fill: o(m) }, firstColumnStripe: { fill: o(m) } }));
}
c += 7, h = [], h.push(["dk1", "dk1", "lt1"]), l(h, (u) => ["dk1", u, "lt1"]);
for (let u = 0; u < 7; u++) {
const d = n("l", u + c), g = h[u][0], m = h[u][1], f = h[u][2];
It.set(d.toLocaleLowerCase(), Object.freeze({ name: d, wholeTable: { font: s(g), border: { left: i(m), right: i(m), top: i(m), bottom: i(m) } }, headerRow: { font: s(f, !0), fill: o(m) }, totalRow: { font: s(g, !0), border: { top: i(m, U.StrokeStyle.Double) } }, firstColumn: { font: s(g, !0) }, lastColumn: { font: s(g, !0) }, firstRowStripe: { border: { top: i(m) } }, secondRowStripe: { border: { top: i(m) } }, firstColumnStripe: { border: { left: i(m) } }, secondColumnStripe: { border: { left: i(m) } } }));
}
c += 7, h = [], h.push(["dk1", r("bg1", -15)]), l(h, (u) => [u, r(u, 80)]);
for (let u = 0; u < 7; u++) {
const d = n("l", u + c), g = "dk1", m = h[u][0], f = h[u][1];
It.set(d.toLocaleLowerCase(), Object.freeze({ name: d, wholeTable: { font: s(g), border: { left: i(m), right: i(m), top: i(m), bottom: i(m), horizontal: i(m), vertical: i(m) } }, headerRow: { font: s(g, !0) }, totalRow: { font: s(g, !0), border: { top: i(m, U.StrokeStyle.Double) } }, firstColumn: { font: s(g, !0) }, lastColumn: { font: s(g, !0) }, firstRowStripe: { fill: o(f) }, firstColumnStripe: { fill: o(f) } }));
}
c = 1, h = [], h.push(["dk1", "dk1", r("bg1", -15)]), l(h, (u) => [u, r(u, 40), r(u, 80)]);
for (let u = 0; u < 7; u++) {
const d = n("m", u + c), g = "dk1", m = "lt1", f = h[u][0], _ = h[u][1], p = h[u][2];
It.set(d.toLocaleLowerCase(), Object.freeze({ name: d, wholeTable: { font: s(g), border: { left: i(_), right: i(_), top: i(_), bottom: i(_), horizontal: i(_) } }, headerRow: { font: s(m, !0), fill: o(f) }, totalRow: { font: s(g, !0), border: { top: i(f, U.StrokeStyle.Double) } }, firstColumn: { font: s(g, !0) }, lastColumn: { font: s(g, !0) }, firstRowStripe: { fill: o(p) }, firstColumnStripe: { fill: o(p) } }));
}
c += 7, h = [], h.push(["dk1", r("bg1", -15), r("bg1", -35)]), l(h, (u) => [u, r(u, 80), r(u, 60)]);
for (let u = 0; u < 7; u++) {
const d = n("m", u + c), g = "dk1", m = "lt1", f = h[u][0], _ = h[u][1], p = h[u][2];
It.set(d.toLocaleLowerCase(), Object.freeze({ name: d, wholeTable: { font: s(g), fill: o(_), border: { horizontal: i(m), vertical: i(m) } }, headerRow: { font: s(m, !0), fill: o(f), border: { bottom: i(m, U.StrokeStyle.Thick) } }, totalRow: { font: s(m, !0), fill: o(f), border: { top: i(m, U.StrokeStyle.Thick) } }, firstColumn: { font: s(m, !0), fill: o(f) }, lastColumn: { font: s(m, !0), fill: o(f) }, firstRowStripe: { fill: o(p) }, firstColumnStripe: { fill: o(p) } }));
}
c += 7, h = [], h.push(["dk1", r("bg1", -15), r("bg1", -35)]), l(h, (u) => [u, r(u, 80), r(u, 60)]);
for (let u = 0; u < 7; u++) {
const d = n("m", u + c), g = "dk1", m = "lt1", f = h[u][0], _ = r("bg1", -15);
It.set(d.toLocaleLowerCase(), Object.freeze({ name: d, wholeTable: { font: s(g), border: { top: i(g, U.StrokeStyle.Medium), bottom: i(g, U.StrokeStyle.Medium), left: u === 0 ? i(g, U.StrokeStyle.Thin) : void 0, right: u === 0 ? i(g, U.StrokeStyle.Thin) : void 0, horizontal: u === 0 ? i(g, U.StrokeStyle.Thin) : void 0, vertical: u === 0 ? i(g, U.StrokeStyle.Thin) : void 0 } }, headerRow: { font: s(m, !0), fill: o(f), border: { bottom: i(g, U.StrokeStyle.Medium) } }, totalRow: { border: { top: i(g, U.StrokeStyle.Double) } }, firstColumn: { font: s(m, !0), fill: o(f) }, lastColumn: { font: s(m, !0), fill: o(f) }, firstRowStripe: { fill: o(_) }, firstColumnStripe: { fill: o(_) } }));
}
c += 7, h = [], h.push(["dk1", r("bg1", -15), r("bg1", -35), "dk1"]), l(h, (u) => [u, r(u, 80), r(u, 60), r(u, 40)]);
for (let u = 0; u < 7; u++) {
const d = n("m", u + c), g = "dk1", m = h[u][0], f = h[u][1], _ = h[u][2], p = h[u][3];
It.set(d.toLocaleLowerCase(), Object.freeze({ name: d, wholeTable: { font: s(g), fill: o(f), border: { top: i(p), right: i(p), left: i(p), bottom: i(p), vertical: i(p), horizontal: i(p) } }, headerRow: { font: s(g), fill: o(f) }, totalRow: { font: s(g), border: { top: i(m, U.StrokeStyle.Medium) } }, firstColumn: { font: s(g, !0) }, lastColumn: { font: s(g, !0) }, firstRowStripe: { fill: o(_) }, firstColumnStripe: { fill: o(_) } }));
}
c = 1, h = [], h.push(["dk1", r("dk1", 15), r("dk1", 25), r("dk1", 50)]), l(h, (u) => ["dk1", r(u, -50), r(u, -25), u]);
for (let u = 0; u < 7; u++) {
const d = n("d", u + c), g = "lt1", m = h[u][0], f = h[u][1], _ = h[u][2], p = h[u][3];
It.set(d.toLocaleLowerCase(), Object.freeze({ name: d, wholeTable: { font: s(g), fill: o(p) }, headerRow: { font: s(g, !0), fill: o(m), border: { bottom: i(g, U.StrokeStyle.Medium) } }, totalRow: { font: s(g, !0), fill: o(f), border: { top: i(g, U.StrokeStyle.Medium) } }, firstColumn: { font: s(g, !0), fill: o(_), border: { right: i(g, U.StrokeStyle.Medium) } }, lastColumn: { font: s(g, !0), fill: o(_), border: { left: i(g, U.StrokeStyle.Medium) } }, firstRowStripe: { fill: o(_) }, firstColumnStripe: { fill: o(_) } }));
}
c += 7, h = [], h.push([r("bg1", -15), "dk1", r("bg1", -35)]), h.push([r("accent1", 80), "accent2", r("accent1", 60)]), h.push([r("accent3", 80), "accent4", r("accent3", 60)]), h.push([r("accent5", 80), "accent6", r("accent5", 60)]);
for (let u = 0; u < 4; u++) {
const d = n("d", u + c), g = "dk1", m = "lt1", f = h[u][0], _ = h[u][1], p = h[u][2];
It.set(d.toLocaleLowerCase(), Object.freeze({ name: d, wholeTable: { font: s(g), fill: o(f) }, headerRow: { font: s(m, !0), fill: o(_) }, totalRow: { font: s(g, !0), border: { top: i(g, U.StrokeStyle.Double) } }, firstColumn: { font: s(g, !0) }, lastColumn: { font: s(g, !0) }, firstRowStripe: { fill: o(p) }, firstColumnStripe: { fill: o(p) } }));
}
return It;
})(), t = /* @__PURE__ */ new Map();
return e.forEach((n, r) => {
const o = n.name.toLowerCase(), s = new $u(this, n, !0);
t.set(o, s);
}), t;
}
_initializeBuiltIns() {
const e = /* @__PURE__ */ new Map();
this._builtInsCellStyles = e, this._initializeNamedStyles($_, e), this._builtInsTableStyles = this._initializeTableStyles(), this._emptyTableStyle = new ar.Empty(this._normalStyle);
}
getNormal() {
return this._normalStyle;
}
getNormalRanged() {
return this._normalRanged;
}
setTheme(e) {
this._theme = e, this._emitter.notify("onThemeChange"), this._emitter.notify("onAnyChange");
}
getTheme() {
return this._theme;
}
setDefaultFontSize(e) {
this._defaultFontSize = e, this._emitter.notify("onDefaultFontChange"), this._emitter.notify("onAnyChange");
}
getDefaultFontSize() {
return this._defaultFontSize;
}
beginPersist() {
return this._persistCache || (this._persistCache = { byIds: /* @__PURE__ */ new Map(), byJSONs: /* @__PURE__ */ new Map(), openScopes: /* @__PURE__ */ new Set() }), new bS(this._persistCache, {}, this._toJSONInternal.bind(this), this._fromJSONInternal.bind(this), () => {
this._persistCache = null;
});
}
getNamed(e) {
if (!e) return null;
e = e.toLowerCase();
let t = null;
return this._customCellStyles && (t = this._customCellStyles.get(e)), t || (t = this._builtInsCellStyles.get(e)), t ?? null;
}
getCustomNamed() {
const e = Array.from(this._customCellStyles.values());
return e.sort((t, n) => t.getName().localeCompare(n.getName())), e;
}
setNamed(e, t = !1) {
if (!e || !e.name || !e.style) throw new Kt();
this.validateStyleName(e.name, !1);
const n = this._setCustomCellStyleInternal(e, t);
return this._emitter.notify("onNamedStylesChange"), this._emitter.notify("onAnyChange"), n;
}
_setCustomCellStyleInternal(e, t = !1, n = 0) {
const r = e.name.toLowerCase(), o = this._builtInsCellStyles.get(r), s = o?.getBuiltInID() ?? null;
let i = null;
t && (i = (this._customCellStyles.get(r) ?? o)?._properties ?? null);
const l = qi(0, e.style, this.getNormal());
e = { ...e, style: l };
const c = $e.resolveTypedUpdates(e, P_, this, i), h = new Gu(this, c, this._hideOrRemoveNamed.bind(this), s);
return c.name === ce.BuiltInName.Normal && (this._normalRanged = h.getRanged(), this._normalStyle = eo(this, null)), this._customCellStyles.set(r, h), h;
}
_setCustomTableStyleInternal(e, t) {
const n = e.toLowerCase();
let r = this._customTableStyles.get(n) ?? this._builtInsTableStyles.get(n);
r && (e = r.getName());
const o = new $u(this, { ...t, name: e }, !1, this._deleteCustomTableStyle.bind(this));
return this._customTableStyles.set(n, o), o;
}
_hideOrRemoveNamed(e) {
let t = null;
if (t = typeof e == "string" ? e : e?.getName?.(), !t || (t = t.toLowerCase(), t === ce.BuiltInName.Normal.toLowerCase())) return !1;
const n = this._builtInsCellStyles.get(t);
let r = !1;
if (n && !n.isHidden()) {
const o = n.toJSON();
this.setNamed({ ...o, hidden: !0 }), r = !0;
} else t = t.toLowerCase(), r = this._customCellStyles.delete(t);
return r && (this._emitter.notify("onNamedStylesChange"), this._emitter.notify("onAnyChange")), r;
}
getTableStyle(e) {
if (!e) return this._emptyTableStyle;
let t = this._customTableStyles.get(e.toLowerCase());
return t || (t = this._builtInsTableStyles.get(e.toLowerCase())), t ?? null;
}
getCustomTableStyles() {
const e = Array.from(this._customTableStyles.values());
return e.sort((t, n) => t.getName().localeCompare(n.getName())), e;
}
setDefaultTableStyle(e) {
const t = e?.toLowerCase();
return this._defaultTableStyle = this._customTableStyles.get(t) ?? this._builtInsTableStyles.get(t) ?? this._builtInsTableStyles.get(_o.toLowerCase()), this._emitter.notify("onTableStylesChange"), this._emitter.notify("onAnyChange"), e === this._defaultTableStyle.getName();
}
getDefaultTableStyle() {
return this._defaultTableStyle || (this._defaultTableStyle = this._builtInsTableStyles.get(_o.toLowerCase())), this._defaultTableStyle;
}
_deleteCustomTableStyle(e) {
const t = this._customTableStyles.get(e?.toLowerCase());
return !!t && (this._customTableStyles.delete(e.toLowerCase()), this._defaultTableStyle?.getName() === t.getName() && (this._defaultTableStyle = this._builtInsTableStyles.get(_o.toLowerCase())), this._emitter.notify("onTableStylesChange"), this._emitter.notify("onAnyChange"), !0);
}
setCustomTableStyle(e, t) {
const n = this._setCustomTableStyleInternal(e, t);
return this._emitter.notify("onTableStylesChange"), this._emitter.notify("onAnyChange"), n;
}
validateStyleName(e, t = !1) {
if (!e || e.trim().length === 0) throw new Error("Style name cannot be empty.");
if (t && this.getNamed(e) !== null) throw new Error("Style name is already taken.");
}
normalize(e) {
if (!e) return null;
const t = $e.resolveTypedUpdates(e, Ge, this), n = hm;
let r = null;
if (r = t.named ? this.getNamed(t.named)?.getRanged().getPropertiesAt(0, 0, null) : this._normalRanged.getPropertiesAt(0, 0, null), r) {
const s = { ...r };
F.removeEqualValues(t, s);
}
const o = this.getTheme().getFontScheme();
return F.removeEqualValues(t, { font: { size: this.getDefaultFontSize(), family: o.getMinorFont(), fallbacks: o.getMinorFallbacks() } }), F.removeEqualValues(t, n), t;
}
schemeLookup() {
return this._schemeLookup;
}
indexedLookup() {
return this._indexedLookup;
}
parseColor(e) {
return Qe.parse(e, this._schemeLookup, this._indexedLookup);
}
recentColors() {
return this._mruColors;
}
addRecentColor(e) {
if (!e) return;
const t = this._mruColors, n = [], r = e.toString();
for (let o = 0; o < t.length && o < 10; o++)
t[o].toString() !== r && n.push(t[o]);
return n.unshift(e), this._mruColors = Object.freeze(n), this._mruColors;
}
clearRecentColors() {
this._mruColors = Object.freeze([]);
}
getIndexedColors() {
return this._indexedColors;
}
setCustomIndexedColors(e) {
this._indexedColors = e?.length > 0 ? [...e] : null;
}
getCustomIndexedColors() {
const e = Math.max(this._indexedColors?.length, 66), t = [];
for (let n = 0; n < e; n++) this._indexedColors[n] !== null && t.push(this._indexedColors[n] ?? new Qe(Ci(n)?.toString()));
return t;
}
addListeners(e, t) {
return this._emitter.addListeners(e, t);
}
_toJSONInternal(e) {
const t = {};
e.length > 0 && (t.direct = e);
const n = this.getCustomNamed();
let r = [];
for (let l = 0; l < n.length; l++) {
let c = n[l].toJSON();
r.push(c);
}
r.length > 0 && (t.named = r);
const o = {};
this._defaultTableStyle && this._defaultTableStyle.getName() !== _o && (o.defaultTableStyle = this._defaultTableStyle.getName());
const s = {}, i = this.getCustomTableStyles();
for (let l = 0; l < i.length; l++) {
let c = i[l].toJSON();
delete c.name, c && Object.keys(c).length > 0 && (s[i[l].getName()] = c);
}
if (Object.keys(s).length > 0 && (o.styles = s), Object.keys(o).length > 0 && (t.tables = o), this._indexedColors.length > 0) {
t.indexedColors = [];
for (let l = 0; l < this._indexedColors.length; l++) t.indexedColors.push(this._indexedColors[l].toString());
}
if (this._mruColors.length > 0) {
t.mruColors = [];
for (let l = 0; l < this._mruColors.length; l++) t.mruColors.push(this._mruColors[l].toString());
}
return Object.keys(t).length === 0 ? null : t;
}
_fromJSONIndexedColors(e) {
if (!e || e.length === 0) return F.EmptyArray;
const t = [];
if (e?.length > 0) for (let n = 0; n < e.length; n++) try {
t.push(this.parseColor(e[n]));
} catch {
console.warn("Unable to parse color: " + e[n]);
}
return t;
}
_fromJSONInternal(e) {
this._indexedColors = this._fromJSONIndexedColors(e.indexedColors);
const t = e.named;
for (let o = 0; t && o < t.length; o++) this._setCustomCellStyleInternal(e.named[o]);
let n = _o;
if (this._defaultTableStyle = null, e.tables) {
e.tables.defaultTableStyle && (n = e.tables.defaultTableStyle);
const o = e.tables.styles ? Object.keys(e.tables.styles) : null;
for (let s = 0; o && s < o.length; s++) {
const i = o[s], l = e.tables.styles[i];
this._setCustomTableStyleInternal(i, l);
}
}
this._defaultTableStyle = this.getTableStyle(n);
let r = [];
if (e.mruColors?.length > 0) for (let o = 0; o < e.mruColors.length; o++) try {
r.push(this.parseColor(e.mruColors[o]));
} catch {
console.warn("Unable to parse color: " + e.mruColors[o]);
}
this._mruColors = r;
}
}
const qa = "BinaryResource must have only one initial data value.", Ka = "Resource is closed.";
class Xa {
constructor(e) {
if (this._listeners = /* @__PURE__ */ new Set(), this._type = e.type, this._name = e?.name, e.base64) {
const t = e.base64;
this._asArrayBufferResolve = async () => {
const n = await Promise.resolve(t);
return Promise.resolve(Ro.base64ToArrayBuffer(n));
};
}
if (e.fetch) {
if (this._asArrayBufferResolve) throw new Error(qa);
const t = e.fetch;
this._asArrayBufferResolve = async () => {
let n, r = null;
r = typeof t == "string" ? t : e.input;
const o = await fetch(r, n), s = o.headers.get("Content-Type");
return !this._type && s && (this._type = s), o.arrayBuffer();
};
}
if (e.buffer) {
if (this._asArrayBufferResolve) throw new Error(qa);
this._asArrayBufferResolve = async () => {
let t = null;
return t = typeof e.buffer == "function" ? await e.buffer() : e.buffer, Promise.resolve(t);
};
}
if (e.file) {
if (this._asArrayBufferResolve) throw new Error(qa);
this._asArrayBufferResolve = async () => await (await Promise.resolve(e.file)).arrayBuffer();
}
if (!this._asArrayBufferResolve) throw new Error("BinaryResource must have an initial data value.");
this._refs = /* @__PURE__ */ new Set(), this._isClosed = !1;
}
getName() {
return this._name;
}
async toJSONAsync() {
const e = await this.toBuffer(), t = { base64: Ro.arrayBufferToBase64(e) };
return this._type !== Ro.DEFAULT_MIME_TYPE && (t.type = this._type), this._name && (t.name = this._name), t;
}
async toBuffer() {
if (this._asArrayBuffer) return this._asArrayBuffer;
try {
this._asArrayBuffer = this._asArrayBufferResolve();
} catch (e) {
throw e;
}
return this._asArrayBuffer;
}
async getType() {
return this._type ? this._type : (await this.toBuffer(), this._type ?? Ro.DEFAULT_MIME_TYPE);
}
addReference(e) {
if (this._isClosed) throw new Error(Ka);
this._refs.add(e);
}
deleteReference(e) {
if (this._isClosed) throw new Error(Ka);
if (this._refs.size === 0 || !this._refs.has(e)) return;
this._refs.delete(e);
const t = this;
if (this._refs.size === 0) {
const n = this._listeners;
n.forEach((r) => {
r.onUnload?.(t), n.delete(r);
}), this._asArrayBuffer = null, this._isClosed = !0;
}
}
addUnloadListener(e) {
if (this._isClosed) throw new Error(Ka);
this._listeners.add(e);
}
get isIResource() {
return !0;
}
isClosed() {
return this._isClosed;
}
}
let vS = class {
constructor(a, e, t) {
this._state = a, this._fromJSON = e, this._onLastEnd = t, this._state.openScopes.add(this), this._isClosed = !1;
}
endPersist() {
if (!this._state.openScopes.delete(this)) throw new Error("PersistScope is closed.");
this._isClosed = !0, this._state.openScopes.size === 0 && this._onLastEnd();
}
toResourceId(a) {
if (this._isClosed) throw new Error("PersistScope is closed.");
let e = this._state.byRefs.get(a);
return e !== void 0 || (e = this._state.byRefs.size, this._state.byRefs.set(a, e), this._state.byIds.set(e, a)), e;
}
fromResourceId(a) {
return this._state.byIds.get(a) ?? null;
}
fromJSON(a) {
if (this._isClosed) throw new Error("PersistScope is closed.");
if (!a || a.length === 0) return;
const e = this._state.byRefs.size;
for (let t = 0; t < a.length; t++) {
const n = a[t], r = this._fromJSON(n);
this._state.byRefs.set(r, e + t), this._state.byIds.set(e + t, r);
}
}
toJSONAsync() {
if (this._isClosed) throw new Error("PersistScope is closed.");
const a = [];
return this._state.byRefs.forEach((e, t) => {
a[e] = Promise.resolve(t.toJSONAsync());
}), Promise.all(a);
}
};
class _m {
constructor() {
this._resources = /* @__PURE__ */ new Set();
}
add(e) {
if (typeof e == "string") {
let r = !1;
this._resources.forEach((o) => {
o.getName() === e && (r = !0, e = o);
}), r || (e = new Xa({ name: e, fetch: e, type: null }));
}
let t = null;
t = e instanceof Xa ? e : new Xa({ ...e });
const n = this;
return this._resources.has(t) || (t.addUnloadListener({ onUnload: (r) => {
n._resources.delete(t);
} }), this._resources.add(t)), t;
}
getItems(e) {
return Array.from(this._resources);
}
getCount() {
return this._resources.size;
}
beginPersist() {
this._persistOpen || (this._persistOpen = { byRefs: /* @__PURE__ */ new Map(), byIds: /* @__PURE__ */ new Map(), openScopes: /* @__PURE__ */ new Set() });
const e = {}, t = /* @__PURE__ */ new Set(), n = this;
return new vS(this._persistOpen, (r) => {
const o = n.add({ base64: r.base64, name: r.name, type: r.type });
return o.addReference(e), t.add(o), o;
}, () => {
t.forEach((r) => {
r.deleteReference(e);
}), n._persistOpen = null;
});
}
}
class xS {
constructor(e, t, n) {
this._state = e, this._fromJSON = t, this._onLastEnd = n, this._state.openScopes.add(this), this._isClosed = !1;
}
endPersist() {
if (!this._state.openScopes.delete(this)) throw new Error("PersistScope is closed.");
this._isClosed = !0, this._state.openScopes.size === 0 && this._onLastEnd();
}
add(e) {
if (this._isClosed) throw new Error("PersistScope is closed.");
let t = this._state.byRefs.get(e);
return t !== void 0 || (t = this._state.byRefs.size, this._state.byRefs.set(e, t), this._state.byIds.set(t, e)), t;
}
at(e) {
return this._state.byIds.get(e) ?? null;
}
fromJSON(e) {
if (this._isClosed) throw new Error("PersistScope is closed.");
e && e.length !== 0 && this._fromJSON(e);
}
toJSONAsync() {
if (this._isClosed) throw new Error("PersistScope is closed.");
const e = [];
return this._state.byRefs.forEach((t, n) => {
e[t] = Promise.resolve(n.toJSONAsync ? n.toJSONAsync() : n);
}), Promise.all(e);
}
}
class lc {
constructor() {
this._nextId = 0, this._lastReadId = -1, this._lastReadValue = null, this._stringsByText = /* @__PURE__ */ new Map(), this._stringsById = /* @__PURE__ */ new Map();
}
addMultiple(e, t = !1) {
const n = this._stringsByText, r = this._stringsById, o = e.length;
let s = this._nextId;
for (let i = 0; i < o; i++) {
const l = e[i];
n.get(l) !== void 0 && t || (n.set(l, s), r.set(s, l), s++);
}
this._lastReadId = -1, this._nextId = s;
}
add(e) {
const t = this._stringsByText, n = t.get(e);
if (n !== void 0) return n;
const r = this._nextId++;
return t.set(e, r), this._stringsById.set(r, e), this._lastReadId = -1, r;
}
getItems(e) {
if (e?.id !== void 0) {
const t = this.getById(e.id);
return t ? [t] : [];
}
return Array.from(this._stringsById.values());
}
getById(e) {
if (this._lastReadId === e) return this._lastReadValue;
const t = this._stringsById.get(e) ?? null;
return this._lastReadId = e, this._lastReadValue = t, t;
}
getCount() {
return this._stringsById.size;
}
beginPersist() {
this._persistOpen || (this._persistOpen = { byRefs: /* @__PURE__ */ new Map(), byIds: /* @__PURE__ */ new Map(), openScopes: /* @__PURE__ */ new Set() });
const e = this;
return new xS(this._persistOpen, (t) => (Array.isArray(t) ? e.addMultiple(t) : e.add(t), t), () => {
e._persistOpen = null;
});
}
}
var Uu, Ye;
Uu || (Uu = {});
class IS extends mr {
constructor(e) {
super(e), e.json && (this._resource = e.fromResourceId(e.json.resId));
}
getType() {
return "picture";
}
toJSON(e) {
const t = {}, n = e?.(this._resource);
n !== null && (t.resId = n);
const r = this._getState();
return r && r.effects && (t.effects = r.effects), t;
}
getTypeDescription() {
return "Picture";
}
async _asDataUrl() {
if (this._dataUrl) return this._dataUrl;
const e = await this.getDetails(), t = await js.getImageDataUrl(e.asUrl());
return this._dataUrl = t.dataUrl, this._dataUrl;
}
toHtml() {
return null;
}
async toImage() {
const e = (await this._asDataUrl()).substring(js.DATA_URL_PNG_PREFIX.length), t = Ro.base64ToArrayBuffer(e);
return new Blob([t], { type: Od.png });
}
async getDetails() {
return this._details || (this._details = new Promise(async (e, t) => {
try {
const n = await this._resource.toBuffer(), r = await this._resource.getType(), o = await js.loadImageDetails(n, r);
e({ getNaturalDimensions: () => o.naturalDimensions, asUrl: () => o.asUrl, asSVGText: () => o.asSVGText });
} catch (n) {
t(n);
}
})), this._details;
}
_fromDrawingJSON(e, t) {
this._resource?.deleteReference(this), this._resource = t?.(e.resId), this._resource.addReference(this);
}
_toDrawingJSON(e) {
const t = {}, n = e?.(this._resource);
return n !== null && (t.resId = n), t;
}
_processDelete() {
super._processDelete();
}
}
(Ye || (Ye = {})).Status = { Ready: "ready", Error: "error", Starting: "starting", Stopping: "stopping", Off: "off" };
class Qo extends ht {
constructor(e, t = null, n, r, o) {
if (super(e, n, t), this._sheetName = r || null, this._getEntireCoords = o ?? Fl, this._coords = RS(n, this._getEntireCoords()), !n) throw new Error("ReferenceRange requires a coords");
this._validateCoords(n);
}
toType(e) {
return new Qo(this._values, e, this._coords, this._sheetName, this._getEntireCoords);
}
getCoords() {
return this._coords;
}
get isIReferenceRange() {
return !0;
}
isLiteral() {
return !1;
}
_validateCoords(e) {
const t = this._getEntireCoords?.();
if (t && (e.rowStart < t.rowStart && e.rowStart !== Number.MIN_SAFE_INTEGER || e.rowEnd > t.rowEnd && e.rowEnd !== Number.MAX_SAFE_INTEGER || e.colStart < t.colStart && e.colStart !== Number.MIN_SAFE_INTEGER || e.colEnd > t.colEnd && e.colEnd !== Number.MAX_SAFE_INTEGER)) throw new ze();
}
get [Symbol.toStringTag]() {
return "[ReferenceRange]";
}
toString() {
return `${Rn(this._coords, this._getEntireCoords?.())}`;
}
}
const RS = (a, e) => {
let t = a.rowStart, n = a.rowEnd, r = a.colStart, o = a.colEnd, s = !1;
return r === Number.MIN_SAFE_INTEGER && (r = e.colStart, s = !0), t === Number.MIN_SAFE_INTEGER && (t = e.rowStart, s = !0), n === Number.MAX_SAFE_INTEGER && (n = e.rowEnd, s = !0), o === Number.MAX_SAFE_INTEGER && (o = e.colEnd, s = !0), s ? { rowStart: t, rowEnd: n, colStart: r, colEnd: o } : a;
}, Ju = (a, e) => a.value?.once === e.value?.once, AS = (a, e) => a.colStart === e.colStart && a.rowStart === e.rowStart, Sm = (a, e, t) => !!t && a === t.rowStart && e === t.colStart, MS = (a, e = 0, t = 0) => {
const n = a._values, r = a._coords, o = n.getRuns({ bounds: r }), s = n.getOrientation() !== O.Orientation.Row, i = s ? r.colStart : r.rowStart, l = s ? r.rowStart : r.colStart, c = new Oe.Builder(null, e, t);
let h = o.next();
for (; !h.done; ) {
const u = h.value;
c.addValues(u[0] - i, u[1] - l, u[2]), h = o.next();
}
return c.build();
}, fi = (a, e, t, n, r, o, s, i, l, c, h, u, d = !1) => {
let g, m, f = null, _ = r.size();
u === void 0 && (u = o.getOrientation() === O.Orientation.Column);
const p = e ? e.length : 0, S = t ? t.length : 0;
let E;
const y = p + S;
for (let w = 0; w < y && _ > 0; w++) {
const b = w < p ? e[w] : t[w - p], x = r.search(b), I = x.length;
for (let v = 0; v < I; v++) {
const R = x[v];
if (!Sm(R.rowStart, R.colStart, b)) {
if (R.value.getError()) continue;
E || (E = []), E.push(R);
}
r.remove(R, AS);
const A = R.value;
A.getCycleId() !== a && l?.insert(R), A.getError() || (o.delete(R), n.insertNonOverlapping({ colStart: R.colStart, rowStart: R.rowStart, colEnd: R.colEnd, rowEnd: R.rowEnd, value: null }, { onIntersect: (M, T) => {
if (M.value !== null) return s?.push(M), f = D.unionRanges(f, M), i?.insertNonOverlapping(M), f = D.unionRanges(f, M), T;
} })), _--;
}
}
for (let w = 0; w < p; w++) {
const b = e[w], x = { colStart: b.colStart, rowStart: b.rowStart, colEnd: b.colEnd, rowEnd: b.rowEnd, value: null };
n.insertNonOverlapping(x, { onIntersect: (I, v) => {
if (I.value === null) return;
const R = D.sanitizeRange(v);
return d && i?.insertNonOverlapping(R), c?.insertNonOverlapping({ ...v, value: !1 }), s?.push(R), f = D.unionRanges(f, R), v;
} }), h?.insertNonOverlapping(x, { onIntersect: (I, v) => {
if (I.value !== null) return s?.push(v), f = D.unionRanges(f, v), v;
}, onUpdates: (I, v, R) => {
m || (m = []);
const A = I.length;
for (let T = 0; T < A; T++) {
const k = I[T];
m.push(k);
}
g || (g = []);
const M = v.length;
for (let T = 0; T < M; T++) {
const k = v[T], P = D.sanitizeRange(k);
g.push(P);
}
} });
}
const C = u ? O.Orientation.Column : O.Orientation.Row;
if (E) {
const w = E.length, b = new Array(w);
for (let x = 0; x < w; x++) {
const I = E[x], v = I.value.setError(!0, a);
l?.insert(v), b[x] = v, f = D.unionRanges(f, I);
const R = { colStart: I.colStart, rowStart: I.rowStart, colEnd: I.colStart, rowEnd: I.rowStart };
n.insertNonOverlapping({ colStart: I.colStart, rowStart: I.rowStart, colEnd: I.colStart, rowEnd: I.rowStart, value: new qt(I, C) }), s?.push(R);
}
r.load(b);
}
for (let w = 0; w < S; w++) {
const b = D.sanitizeRange(t[w]);
n.insertNonOverlapping({ colStart: b.colStart, rowStart: b.rowStart, colEnd: b.colEnd, rowEnd: b.rowEnd, value: new qt(b, C) }), d && i?.insertNonOverlapping(b), s?.push(b), f = D.unionRanges(f, b);
}
return f;
}, Wl = (a, e, t) => {
if (!e) return a;
const n = e.block;
if (!n) return a;
const r = a ?? [], o = e.colIndex, s = e.rowIndex;
let i, l, c, h;
t ? (i = t.colStart, l = t.rowStart, c = t.colEnd, h = t.rowEnd) : (i = o, l = s, c = o, h = s);
const u = { colStart: i, rowStart: l, colEnd: c, rowEnd: h, value: { blockEntry: { colStart: i, rowStart: l, colEnd: c, rowEnd: h, value: n }, width: 1, height: 1, index: -1, $absWidth: !1, $absHeight: !1, once: e } };
let d = e.dynamic;
return d || (d = [], e.dynamic = d), d.push(u), r.push(u), r;
};
class hc {
constructor(e) {
this._fullCalcRequired = !1, this._iterationId = 0, this._cycleId = 1, this._pendingInvalidations = /* @__PURE__ */ new Set(), this._emitter = null, this._isProcessingJSON = !1, this._collectDirties = (o, s = !1, i, l) => {
const c = this._formulaSpatial, h = this._precedentSpatial;
let u = kS, d = 0;
if (s) {
const g = c.all();
for (let m = 0; m < g.length; m++) {
const f = g[m].value.calcs, _ = f.length;
for (let p = 0; p < _; p++) {
const S = f[p], E = S.length;
for (let y = 0; y < E; y++) {
const C = S[y];
C.markId !== o && (u[d++] = C, C.markId = o, C.pending = !1, C.pendingResolved = !1, C.pendingPromise && (C.pendingPromise.cancelled = !0));
}
}
}
} else {
const g = i.length;
for (let m = 0; m < g; m++) {
const f = i[m];
Yu.length = 0;
const _ = Yu;
h.search(f, !1, _), c.search(f, !1, _);
const p = _.length;
if (p === 0) continue;
const S = f.colStart, E = f.rowStart, y = f.colEnd - S, C = f.rowEnd - E;
for (let w = 0; w < p; w++) {
const b = _[w], x = b.value, I = x.blockEntry?.value ?? x, v = I.ref, R = v.colEnd - v.colStart, A = v.rowEnd - v.rowStart, M = b.colEnd - b.colStart - R, T = b.rowEnd - b.rowStart - A, k = x.once;
if (k) k.markId <= o && (k.removed ? (h.remove(b, Ju), k.removed = !1) : u[d++] = k, k.markId = o);
else {
let P = 0, B = 0, H = R, z = A;
if (!x.$absHeight) {
const L = E - b.rowStart;
B = Math.min(Math.max(L - T, 0), A), z = Math.min(C + E, A);
}
if (!x.$absWidth) {
const L = S - b.colStart;
P = Math.min(Math.max(L - M, 0), R), H = Math.min(y + L, R);
}
const W = I.calcs;
for (let L = B; L <= z; L++) {
const j = W[L];
for (let G = P; G <= H; G++) {
const V = j[G];
V.markId !== o && (u[d++] = V, V.markId = o, V.pendingPromise && (V.pendingPromise.cancelled = !0));
}
}
}
}
}
l && l.forEach((m) => {
if (Array.isArray(m)) {
const f = m.length;
for (let _ = 0; _ < f; _++) {
const p = m[_], S = p.length;
for (let E = 0; E < S; E++) {
const y = p[E];
y.markId === o || y.removed || (u[d++] = y, y.markId = o, y.pendingPromise && (y.pendingPromise.cancelled = !0));
}
}
} else m.markId === o || m.removed || (u[d++] = m, m.markId = o, m.pendingPromise && (m.pendingPromise.cancelled = !0));
});
}
return u.length = d, u;
};
const t = (e = { strings: new lc(), ...e }).getEntireCoords ?? Fl;
if (this._getEntireCoords = t, this._options = e, this._strings = e.strings, this._onCalculated = e?.onCalculated ?? (() => {
}), this._cycleId = 1, this._values = new sn({ orientation: O.Orientation.Column }), this._getFormulaParser = e.getFormulaParser, !this._getFormulaParser) throw new Error("Formula parser is not defined");
this._latest = { graph: this }, this._iterationId = 0;
const n = this;
this._formulaSpatial = new Ne({ updateEntryOptions: { isMergeOnShift: !0, isSplitOnExpand: !0, onUpdates: (o, s, i) => {
const l = i._cloneKey ?? n;
if (l._isProcessingJSON) return;
let c = l._notifyFormulaInsertEntries, h = l._notifyFormulaRemoveEntries;
const u = l._precedentSpatial, d = s ? s.length : 0;
if (d > 0) {
let m = h ? h.length : 0;
h ? h.length = m + d : (h = new Array(d), l._notifyFormulaRemoveEntries = h);
for (let f = 0; f < d; f++) {
const _ = s[f], p = _.value, S = p.ref;
h[m + f] = S;
const E = S.rowStart, y = S.colStart, C = p.formula.getDirectPrecedentsAt(E, y);
if (!C) continue;
const w = C.length;
for (let b = 0; b < w; b++) {
const x = C[b];
if (x === null || x instanceof Ee.Known) continue;
const I = u.search(x), v = I.length;
for (let R = 0; R < v; R++) {
const A = I[R];
A.value.blockEntry.value === _.value && u.remove(A);
}
}
}
}
const g = o ? o.length : 0;
if (g > 0) {
const m = [];
for (let f = 0; f < g; f++) {
const _ = o[f], p = _.colEnd - _.colStart, S = _.rowEnd - _.rowStart, E = _.value, y = E.formula, C = E.ref, w = C.rowStart, b = C.colStart, x = [], I = y.getDirectPrecedentsAt(w, b, !0, As, Ms), v = I.length;
for (let R = 0; R < v; R++) {
const A = I[R];
if (A instanceof Ee.Known) continue;
const M = As[R], T = Ms[R], k = { colStart: A.colStart, rowStart: A.rowStart, colEnd: A.colEnd + (T ? 0 : p), rowEnd: A.rowEnd + (M ? 0 : S), value: { blockEntry: _, width: p + 1, height: S + 1, index: R, $absWidth: T, $absHeight: M, once: null } };
x.push(A), m.push(k);
}
c || (c = [], l._notifyFormulaInsertEntries = c), c.push({ colStart: _.colStart, rowStart: _.rowStart, colEnd: _.colEnd, rowEnd: _.rowEnd, value: { tokens: y.getTokens(), references: y.getReferences(), precedents: x } });
}
u.load(m);
}
} } }), this._contentfulSpatial = new Ne({ updateEntryOptions: { isSplitOnExpand: !0, isMergeOnShift: !0 } });
const r = { updateEntryOptions: { isSplitOnExpand: !0, isMergeOnShift: !1 } };
this._precedentSpatial = new Ne(r), this._volatile = /* @__PURE__ */ new Set(), this._spillSpatial = new Ne(r), this._errorSpatial = new Ne(r), this._pendingSpatial = new Ne(r), this._invalidations = new Ne(), this._notifyValues = new Ne(), this._notifySpills = new Ne(), this._notifyFormats = new Ne(), this._notifyPending = new Ne(), this._calculation = e.calculation, this._clearScope();
}
addListeners(e, t) {
return this._emitter || (this._emitter = new mt(this)), this._emitter.addListeners(e, t);
}
shift(e) {
const t = e.cloneIfUpdate ?? !0 ? this.clone(this) : this, n = { ...e };
delete n.cloneIfUpdate, delete n.onShift, t._values.shift(n.range, n.direction);
const r = t._contentfulSpatial;
t._contentfulSpatial = r.shift(n);
const o = t._spillSpatial;
t._spillSpatial = o.shift(n);
const s = t._formulaSpatial;
if (s.isEmpty()) return t;
const i = e.range, l = e.direction, c = l === O.Direction.Left || l === O.Direction.Right;
l !== O.Direction.Up && O.Direction.Left, c ? (i.colEnd, i.colStart) : (i.rowEnd, i.rowStart), t._notifyFormulaInsertEntries, t._notifyFormulaRemoveEntries;
const h = t._getEntireCoords(), u = /* @__PURE__ */ new Map();
this._precedentSpatial.visitRanges({ ...i, colEnd: c ? h.colEnd : i.colEnd, rowEnd: c ? i.rowEnd : h.rowEnd }, (p) => {
let S = p.value;
if (p.value.once) return;
let E = S.blockEntry, y = u.get(E);
y || (y = { rows: [], cols: [], index: [] }, u.set(E, y)), y.index.push(S.index);
});
const d = [], g = [], m = u.entries();
let f = m.next();
const _ = (p, S, E, y) => {
let C = p.value;
const w = C.formula.getReferences(), b = S.length;
for (let x = 0; x < b; x++) {
const I = w[x];
I !== null && (I instanceof Ee.Known || typeof I != "string" && I[x]);
}
return p.value = C, p;
};
for (; !f.done; ) {
const [p, S] = f.value, E = p.value, y = S.rows.sort(), C = y.length, w = S.cols.sort().length, b = S.index.sort();
if (g.push(p), C === 0 && w === 0) {
const I = { ...p };
_(I, b), d.push(I), f = m.next();
continue;
}
let x = 0;
for (let I = 0; I < C; I++) {
const v = y[I];
if (v === x) continue;
nl[0] = { colStart: E.ref.colStart, rowStart: x, colEnd: E.ref.colEnd, rowEnd: v - 1, value: E }, nl[1] = { colStart: E.ref.colStart, rowStart: v, colEnd: E.ref.colStart, rowEnd: E.ref.rowEnd, value: E };
const R = LS(E, nl, O.Orientation.Row, v);
let A = R[0];
_(A, b), d.push(A), A = R[1], _(A, b), d.push(A), x = v;
}
f = m.next();
}
return s._updateNodes(d, g), t._fullCalcRequired = !0, this._invalidate(d), t;
}
clone(e) {
if (e !== void 0 && this._cloneKey === e) return this;
const t = new hc(this._options);
t._cloneKey = e, t._values = this._values.clone(t), t._contentfulSpatial = this._contentfulSpatial.clone(t), t._formulaSpatial = this._formulaSpatial.clone(t), t._precedentSpatial = this._precedentSpatial.clone(t), t._volatile = new Set(this._volatile), t._spillSpatial = this._spillSpatial.clone(t), t._errorSpatial = this._errorSpatial.clone(t), t._pendingSpatial = this._pendingSpatial.clone(t), t._invalidations = this._invalidations.clone(t), t._notifyValues = this._notifyValues.clone(t), t._notifySpills = this._notifySpills.clone(t), t._notifyFormats = this._notifyFormats.clone(t), t._notifyPending = this._notifyPending.clone(t);
const n = this._notifyFormulaInsertEntries;
n && (t._notifyFormulaInsertEntries = [...n]);
const r = this._notifyFormulaRemoveEntries;
r && (t._notifyFormulaRemoveEntries = [...r]);
const o = this._pendingActions;
return o && (t._pendingActions = [...o]), t._cycleId = this._cycleId, t._emitter = this._emitter, t._fullCalcRequired = this._fullCalcRequired, this._latest.graph = t, t._iterationId = this._iterationId + 1, t;
}
invalidate(e) {
const t = this._invalidations;
if (Array.isArray(e)) {
const n = e.length;
for (let r = 0; r < n; r++) {
let o = e[r];
typeof o == "string" && (o = At(o)), t.insertNonOverlapping(o);
}
} else {
let n = e;
typeof n == "string" && (n = At(n)), t.insertNonOverlapping(n);
}
}
setFormulaAt(e, t) {
let n, r = null;
return typeof e == "string" ? n = At(e, Be) : (Be.colStart = e.colIndex, Be.rowStart = e.rowIndex, Be.colEnd = e.colIndex, Be.rowEnd = e.rowIndex, n = Be), t ? r = this._setInputs(null, [{ colStart: n.colStart, rowStart: n.rowStart, colEnd: n.colEnd, rowEnd: n.rowEnd, value: t }]) : this.delete(n), r;
}
getFormulaAt(e, t) {
let n;
typeof e == "string" && (n = At(e, Be));
const r = this._formulaSpatial.search(n);
if (r.length === 0) return null;
const o = r[0].value;
return o.formula ? o.formula.getTextAt(n.rowStart, n.colStart, t) : void 0;
}
_formulaAt(e, t) {
bo.colStart = t, bo.rowStart = e, bo.colEnd = t, bo.rowEnd = e;
const n = this._formulaSpatial.search(bo);
if (n.length === 0) throw new Error(`No formula found at ${os({ rowIndex: e, colIndex: t })}`);
return n[0];
}
getDirectPrecedentsAt(e, t, n) {
return this._formulaAt(e, t).value.formula.getDirectPrecedentsAt(e, t, n);
}
getReferencesAt(e, t) {
return this._formulaAt(e, t).value.formula.getReferences();
}
setReferenceAt(e, t, n, r) {
const o = this._formulaAt(e, t).value.formula.setReferenceAt(n, r).getTextAt(e, t);
return this.setFormulaAt({ rowIndex: e, colIndex: t }, o), this;
}
evaluateAt(e, t, n) {
const r = this._formulaAt(e, t), o = r.value, s = o.ref, i = s.colStart - t, l = s.rowStart - e, c = this._calculation._getContext(), h = this._calculation._getScope();
return h.sheetName = this._options.getSheetName?.(), h.rowIndex = e, h.colIndex = t, h.node = o.calcs[l][i], r.value.formula.evaluate(c, n);
}
setInputAt(e, t) {
let n = null;
const r = typeof e == "string" ? Pr(e, NS) : e;
if (t !== null) {
const o = new Oe.Builder(), s = this._values.getOrientation() === O.Orientation.Column, i = s ? r.colIndex : r.rowIndex, l = s ? r.rowIndex : r.colIndex;
o.addValue(i, l, t), n = this.setInputs(o.build(), null);
} else this.delete(D.cellToRange(r, Be));
return n;
}
setInputs(e, t) {
return this._setInputs(e, t);
}
delete(e) {
typeof e == "string" && (e = Pt(e));
const t = this._setInputs(null, [{ ...e, value: null }], e);
return this._emitter?.notify("onInvalidate"), t.removes;
}
_createCopySpillEntries(e, t, n, r, o) {
const s = r ?? [], i = o ?? [], l = t.colStart, c = t.rowStart, h = t.colEnd, u = t.rowEnd, d = n.colStart, g = n.rowStart, m = e.search(t), f = m.length;
for (let _ = 0; _ < f; _++) {
const p = m[_];
i && i.push(p);
const S = p.rowStart, E = p.colStart;
if (S < c || S > u || E < l || E > h || p.value.getError()) continue;
const y = d + (p.colEnd - E), C = g + (p.rowEnd - S), w = { colStart: d, rowStart: g, colEnd: y, rowEnd: C };
s.push({ colStart: d, rowStart: g, colEnd: y, rowEnd: C, value: new hr(w, 0, !1) });
}
return { removes: i, inserts: s };
}
_copyCalcs(e, t, n) {
const r = e._formulaSpatial;
if (r.isEmpty()) return;
const o = this._getEntireCoords(), s = o.colStart, i = o.rowStart, l = o.colEnd, c = o.rowEnd, h = r.createCopiedEntries(t, n), u = h.inserts;
let d = u.length, g = 0;
const m = e._spillSpatial;
let f = [];
for (; g < d; ) {
let _ = u[g], p = _.value, S = p.ref, E = S.colStart, y = S.rowStart, C = S.colEnd, w = S.rowEnd;
this._createCopySpillEntries(m, t, S, f, null);
let b = p.formula.getReferences();
const x = b.length;
for (let I = 0; I < x; I++) {
const v = b[I];
if (!v || v.isFormulaError || typeof v == "string") continue;
const R = v, A = R.colStart, M = R.rowStart, T = R.colEnd, k = R.rowEnd;
let P = R.$colStart ? A : A + E, B = R.$rowStart ? M : M + y, H = R.$colEnd ? T : T + C, z = R.$rowEnd ? k : k + w;
if (A === Number.MIN_SAFE_INTEGER && (P = s, H = l), M === Number.MIN_SAFE_INTEGER && (B = i, z = c), P < s || H > l || B < i || z > c) {
const W = s - P, L = i - B, j = l - H, G = c - z;
Co.colStart = Math.max(E, E + W), Co.rowStart = Math.max(y, y + L), Co.colEnd = Math.min(C, C + j), Co.rowEnd = Math.min(w, w + G);
const V = Zr(_, Co, ti);
if (V) {
const $ = V.length;
_ = V[$ - 1], p = _.value, S = p.ref, E = S.colStart, y = S.rowStart, C = S.colEnd, w = S.rowEnd;
for (let J = 0; J < $ - 1; J++) {
const K = V[J];
u.push(K), d++;
}
} else p = p.setReferenceAt(I, null), _.value = p, b = p.formula.getReferences();
}
}
u[g++] = _;
}
this._formulaSpatial._updateNodes(u, h.removes), r._mergeNodes({ colStart: n.colStart - 1, rowStart: n.rowStart - 1, colEnd: n.colEnd + 1, rowEnd: n.rowEnd + 1 }), f && this._spillSpatial._updateNodes(f, []), this._fullCalcRequired = !0, this._invalidate(u), this._invalidate(h.removes);
}
_moveCalcs(e, t, n) {
const r = e._formulaSpatial.createCopiedEntries(t, n);
console.log("_moveCalcs", r, "from:", t, "to:", n);
const o = this._formulaSpatial, s = (g, m, f, _) => {
let p = g.value;
const S = p.formula.getReferences(), E = S.length, y = m.colStart - f.colStart, C = m.rowStart - f.rowStart, w = p.ref, b = f.colStart - w.colStart, x = f.colEnd - w.colEnd, I = f.rowStart - w.rowStart, v = f.rowEnd - w.rowEnd;
for (let R = 0; R < E; R++) {
const A = S[R];
if (!A || A.isFormulaError || typeof A == "string") continue;
const M = A, T = M.colStart, k = M.rowStart, P = M.colEnd, B = M.rowEnd;
let H = y, z = C;
const W = b <= T && x >= P || T == Number.MIN_SAFE_INTEGER, L = I <= k && v >= B || k == Number.MIN_SAFE_INTEGER;
let j = !L;
M.$colStart || H === 0 || T === Number.MIN_SAFE_INTEGER ? j = !1 : j || (j = T < b || T > x, j || !M.$colEnd || M.$colStart || (j = !0));
let G = !W;
M.$rowStart || z === 0 || k === Number.MIN_SAFE_INTEGER ? G = !1 : G || (G = k < I || k > v, j || !M.$rowEnd || M.$rowStart || (G = !0));
let V = !L;
M.$colEnd || H === 0 || k === Number.MIN_SAFE_INTEGER ? V = !1 : V || (V = P < b || P > x, j || !M.$colStart || M.$colEnd || (V = !0));
let $ = !W;
if (M.$rowEnd || z === 0 || k === Number.MIN_SAFE_INTEGER ? $ = !1 : $ || ($ = B < I || B > v, $ || !M.$rowEnd || M.$rowStart || ($ = !0)), !(j || V || G || $)) continue;
const J = { ...M };
j && (J.colStart += H), G && (J.rowStart += z), V && (J.colEnd += H), $ && (J.rowEnd += z), p = p.setReferenceAt(R, J);
}
return g.value = p, g;
}, i = e._spillSpatial;
let l = [], c = [];
const h = r.inserts, u = h.length;
for (let g = 0; g < u; g++) {
const m = h[g];
this._createCopySpillEntries(i, t, m, l, c), h[g] = s(m, t, n);
}
o._updateNodes(r.inserts, []), e._formulaSpatial._updateNodes([], r.removes);
const d = [];
l.length > 0 && (this._spillSpatial._updateNodes(l, []), e._spillSpatial._updateNodes([], c), fi(this._cycleId, c, F.EmptyArray, e._contentfulSpatial, i, e._values, d, e._notifyValues, e._notifySpills, e._notifyPending, e._errorSpatial, e._values.getOrientation() !== O.Orientation.Row, !1)), this._fullCalcRequired = !0, this._invalidate(r.inserts), e._invalidate(d), e._invalidate(r.removes);
}
getSnapshot(e) {
const t = this, n = Object.freeze({ ...e });
let r = n.range;
return typeof r == "string" && (r = At(r)), { async copyTo(o, s) {
const i = o.calcGraph;
let l = o.range;
typeof l == "string" && (l = At(l));
const c = li(l, r, s?.fitDestination, s?.transpose);
return { ...n, ...s }.isCut ? i._moveCalcs(t, r, c) : i._copyCalcs(t, r, c), l;
}, getCoords: () => r, getSource: () => t, getName: () => "Calculation", getMarkOptions: () => n, isISnapshot: !0 };
}
autoFill(e, t) {
return typeof e == "string" && (e = At(e)), typeof t == "string" && (t = At(t)), this._copyCalcs(this, e, t), this;
}
_scheduleRecalculation(e) {
const t = this._pendingInvalidations;
if (e) if (Array.isArray(e)) {
const r = e.length;
for (let o = 0; o < r; o++) t.add(e[o]);
} else t.add(e);
const n = this;
F.debounce(() => {
const r = n._latest.graph, o = r._volatile, s = r._cycleId;
t.forEach((i) => {
i.cycleId > s || o.add(i);
}), t.clear(), r.calculate();
}, 100)();
}
_notifyCalculated(e) {
const t = this, n = t._notifyValues, r = n.all();
return new Promise((o) => {
F.nextTick(() => {
const s = t._cycleId;
let i, l = t._fullCalcRequired;
l || (typeof e == "boolean" ? l = e : e && (i = e, l = i.full ?? !1));
const c = {};
let h = null;
const u = r.length;
if (u > 0) {
n.clear();
let E = r, y = null;
for (let R = 0; R < u; R++) {
const A = r[R], M = A.colStart, T = A.colEnd;
if (M !== T) {
y || (y = []);
for (let k = M + 1; k <= T; k++) y.push({ colStart: k, rowStart: A.rowStart, colEnd: k, rowEnd: A.rowEnd });
A.colEnd = M;
}
}
y && (E = r.concat(y)), E.sort(D.columnFirstRangeComparator);
const C = new Oe.Builder((R) => new jt(R));
let w;
const b = t._values, x = b.getOrientation() === O.Orientation.Column, I = E.length;
for (let R = 0; R < I; R++) {
const A = E[R];
h = D.unionRanges(h, A, Be);
const M = b.getRuns({ bounds: A });
let T = M.next();
const k = A.colStart, P = A.rowStart, B = A.colEnd, H = A.rowEnd, z = x ? P : k, W = x ? B : H, L = x ? H : B;
let j = x ? k : P, G = z;
for (; !T.done; ) {
const V = T.value, $ = V[0];
for (; j < $; ) w || (w = []), w.push({ colStart: x ? j : G, rowStart: x ? G : j, colEnd: x ? j : L, rowEnd: x ? L : j }), j++, G = z;
const J = V[1], K = V[2], he = Math.max(J, z), le = Math.min(J + K.length - 1, L);
C.addValues($, he, K), G < he && (w || (w = []), w.push({ colStart: x ? $ : G, rowStart: x ? G : $, colEnd: x ? $ : he - 1, rowEnd: x ? he - 1 : $ })), G = le + 1, le >= L ? (j = $ + 1, G = z) : j = $, T = M.next();
}
for (; j <= W; ) G <= L && (w || (w = []), w.push({ colStart: x ? j : G, rowStart: x ? G : j, colEnd: x ? j : L, rowEnd: x ? L : j })), j++, G = z;
}
const v = C.build();
v && (c.valueInserts = v), w && (c.valueRemoves = w);
}
const d = t._notifyPending, g = d.all();
if (g.length > 0) {
d.clear();
const E = t._pendingSpatial;
let y;
const C = g.length;
for (let w = 0; w < C; w++) {
const b = g[w];
E.insertNonOverlapping(b, { onIntersect: (x, I) => (y || (y = []), y.push({ ...I }), h = D.unionRanges(h, I), I.value === !1 && (I.value = null), I) });
}
y && y.length > 0 && (c.pendingUpdates = y, h = D.unionRangesArrays(y, h, Be));
}
const m = t._notifySpills, f = m.all();
if (f.length > 0) {
m.clear();
const E = t._spillSpatial;
let y, C, w;
const b = f.length;
for (let x = 0; x < b; x++) {
const I = f[x], v = I.value;
if (v.getCycleId() !== s) y || (y = []), y.push({ colStart: I.colStart, rowStart: I.rowStart, colEnd: I.colEnd, rowEnd: I.rowEnd });
else {
const R = E.search(I), A = R.length;
for (let M = 0; M < A; M++) {
let T = R[M];
if (Sm(I.rowStart, I.colStart, T) && v.getCycleId() === s) {
C || (C = [], w = /* @__PURE__ */ new Set());
const k = Yt(T.colStart) + an(T.rowStart);
if (w.has(k)) continue;
w.add(k), C.push({ colStart: I.colStart, rowStart: I.rowStart, colEnd: I.colEnd, rowEnd: I.rowEnd, value: T.value.getError() });
}
}
}
}
C && (c.spillInserts = C, h = D.unionRangesArrays(C, h, Be)), y && (c.spillRemoves = y, h = D.unionRangesArrays(y, h, Be));
}
const _ = t._notifyFormats.all();
_.length > 0 && (c.formatInserts = _, h = D.unionRangesArrays(_, h, Be), t._notifyFormats.clear());
const p = t._notifyFormulaInsertEntries;
if (p) {
const E = t._formulaSpatial;
for (let y = p.length - 1; y >= 0; y--) {
const C = p[y];
E.search(C).length === 0 ? p.splice(y, 1) : h = D.unionRanges(h, C, Be);
}
c.formulaInserts = p, t._notifyFormulaInsertEntries = void 0;
}
const S = t._notifyFormulaRemoveEntries;
S && (c.formulaRemoves = S, h = D.unionRangesArrays(S, h, Be), t._notifyFormulaRemoveEntries = void 0), h && (c.bounds = D.sanitizeRange(h)), Object.keys(c).length === 0 ? c.cycleId = s - 1 : (c.cycleId = s, t._cycleId++), l && (c.isFull = !0), t._fullCalcRequired = !1, t._options.onCalculated?.(c), o(c);
});
});
}
_setInputs(e, t, n) {
if (this._calculation.getStatus() === Ye.Status.Starting) return this._addToPending(() => {
const I = this._setInputs(e, t, n), v = { formulaInserts: I.inserts ?? F.EmptyArray, formulaRemoves: I.removes ?? F.EmptyArray, cycleId: this._cycleId, bounds: D.unionRanges(D.unionRangesArrays(I.inserts), D.unionRangesArrays(I.removes)) };
return Promise.resolve(v);
}), DS;
const r = this._values.getOrientation() !== O.Orientation.Row, o = this._spillSpatial, s = this._errorSpatial, i = this._contentfulSpatial, l = [], c = this._formulaSpatial;
let h, u, d = !c.isEmpty(), g = d ? [] : null, m = this._values;
if (e && e.tuples) {
if (h = e.tuples, g) {
let I = e.bounds;
if (d) if (I) {
const A = Jo(I, r);
l.push(A);
} else {
const A = { colStart: Number.MIN_SAFE_INTEGER, rowStart: Number.MIN_SAFE_INTEGER, colEnd: Number.MAX_SAFE_INTEGER, rowEnd: Number.MAX_SAFE_INTEGER };
l.push(A);
}
const v = { majorStart: 0, minorStart: 0, majorEnd: 0, minorEnd: 0 }, R = h.length;
for (let A = 0; A < R; A++) {
const M = h[A], T = M[0];
v.majorStart = T, v.majorEnd = T;
const k = M[1], P = k.length;
for (let B = 0; B < P; B++) {
const H = k[B];
v.minorStart = H[0];
const z = H[1];
v.minorEnd = v.minorStart + z.length - 1;
const W = Jo(v, r);
g && c.search(W).length > 0 && g.push(W);
}
}
}
u = tu(e.tuples, r);
}
(n || h) && (fi(this._cycleId, n ? [n] : F.EmptyArray, u, i, o, m, l, this._notifyValues, this._notifySpills, this._notifyPending, s, r, !1), n && m.delete(n), h && m.setValues(h));
const f = this._calculation._getContext(), _ = this._calculation._getScope();
let p, S;
_.sheetName = this._options.getSheetName?.();
const E = this._getFormulaParser(), y = (I, v) => {
const R = I.rowStart, A = I.colStart, M = { ...I, value: null };
if (c.insertNonOverlapping(M, { noMerge: !0, onIntersect: (T, k) => T.value === null ? null : (S || (S = []), S.push(T), k) }), v !== null) {
_.rowIndex = R, _.colIndex = A;
const T = E.parse(f, v), k = new _n(I, T), P = { ...I, value: k };
p || (p = []), p.push(P);
}
}, C = g ? g.length : 0;
for (let I = 0; I < C; I++) y(g[I], null);
const w = t ? t.length : 0;
for (let I = 0; I < w; I++) {
const v = t[I], R = v.value;
y(D.sanitizeRange(v), R);
}
const b = S ? S.length : 0, x = this._precedentSpatial;
for (let I = 0; I < b; I++) {
const v = S[I].value.calcs;
if (v) {
const R = v.length;
for (let A = 0; A < R; A++) {
const M = v[A];
for (let T = 0; T < M.length; T++) {
const k = M[T];
if (k.dynamic) {
for (let P = 0; P < k.dynamic.length; P++) {
const B = k.dynamic[P];
x.remove(B);
}
k.dynamic = null;
}
}
}
}
}
return t && (c._updateNodes(p, F.EmptyArray), fi(this._cycleId, S, p, i, o, m, l, this._notifyValues, this._notifySpills, this._notifyPending, s, r, !0)), this._invalidate(l), { inserts: this._notifyFormulaInsertEntries ?? F.EmptyArray, removes: this._notifyFormulaRemoveEntries ?? F.EmptyArray };
}
_invalidate(e) {
if (!e || e.length == 0) return;
const t = this._invalidations, n = yn(e, O.Orientation.Column, 2);
for (let r = 0; r < n.length; r++) t.insertNonOverlapping(n[r]);
this._emitter?.notify("onInvalidate");
}
_markAndPlan(e, t, n) {
let r;
yo = 0, tl = 0, Fs = 0, Eo = 0;
const o = this._precedentSpatial, s = this._formulaSpatial;
Za = 0, Ns = 0;
const i = this._cycleId, l = t.length;
for (let d = 0; d < l; d++) {
const g = t[d];
g.markId !== n && (g.markId = n, g.cycleId = i, g.inDegree = 0, Ya[yo++] = g, Qa[Ns++] = g);
}
const c = (d, g, m) => {
(e || d.state === Dl) && (r || (r = []), r.push(g), e || m(d));
}, h = (d) => {
d.markId !== n && (d.markId = n, d.cycleId = i, d.inDegree = 0, Ya[yo++] = d, Qa[Ns++] = d);
};
for (; Za < Ns; ) {
const d = Qa[Za++], g = d.colIndex, m = d.rowIndex;
Be.colStart = g, Be.rowStart = m, Be.colEnd = g, Be.rowEnd = m;
const f = o.search(Be), _ = f.length;
if (_ === 0) d.dependents = F.EmptyArray;
else for (let p = 0; p < _; p++) {
const S = f[p], E = S.value.once;
E ? c(E, S, h) : Ku(S, m, g, h);
}
}
for (let d = 0; d < yo; d++) {
const g = Ya[d], m = g.block, f = g.rowIndex, _ = g.colIndex, p = m.formula.getDirectPrecedentsAt(f, _);
let S = 0;
const E = g.precedents;
for (let y = 0; y < p.length; y++) {
const C = p[y];
if (C.isFormulaError) {
E[y] = C;
continue;
}
{
const A = C;
A.calc = void 0, E[y] = A;
}
const w = C.colStart, b = C.rowStart, x = C.colEnd, I = C.rowEnd, v = s.search(C), R = v.length;
for (let A = 0; A < R; A++) {
const M = v[A], T = M.colStart, k = M.rowStart, P = M.colEnd, B = M.rowEnd, H = Math.max(T, w), z = Math.max(k, b), W = Math.min(P, x), L = Math.min(B, I), j = M.value.calcs;
for (let G = z; G <= L; G++) {
const V = j[G - k];
for (let $ = H; $ <= W; $++) {
const J = V[$ - T];
J.markId === n && (C.calc = J, S++);
}
}
}
}
g.inDegree = S, g.inDegree === 0 && (el[Fs++] = g);
}
const u = (d) => {
d.markId === n && (d.inDegree--, d.inDegree === 0 && (el[Fs++] = d));
};
for (; tl < Fs; ) {
const d = el[tl++];
Xu[Eo++] = d;
const g = d.colIndex, m = d.rowIndex;
Be.colStart = g, Be.rowStart = m, Be.colEnd = g, Be.rowEnd = m;
const f = o.search(Be), _ = f.length;
for (let p = 0; p < _; p++) {
const S = f[p], E = S.value.once;
E ? c(E, S, u) : Ku(S, m, g, u);
}
}
return Eo < yo ? { completed: !1, onces: r } : { completed: !0, onces: r };
}
_evaluate(e) {
const t = this._calculation._getContext(), n = this._calculation._getScope();
n.sheetName = this._options.getSheetName?.();
let r = OS;
r.length = 0;
let o = 0, s = !0;
const i = this._cycleId, l = this._invalidations, c = this._contentfulSpatial, h = this._notifyValues, u = this._notifySpills, d = this._precedentSpatial, g = this._spillSpatial, m = this._values, f = m.getOrientation(), _ = f === O.Orientation.Column;
let p;
n.spillSpatial = this._spillSpatial, n.values = m;
const S = t.getEntireCoords.bind(t);
let E;
for (let y = 0; y < Eo; y++) {
const C = Xu[y];
if (C.state === nu && i === C.cycleId) {
C.state = Dl;
continue;
}
if (C.dynamic) {
for (let ne = 0; ne < C.dynamic.length; ne++) {
const ue = C.dynamic[ne];
d.remove(ue);
}
C.dynamic = null;
}
const w = C.block, b = C.colIndex, x = C.rowIndex;
let I = e ? void 0 : C.cachedValue, v = C.error;
!v && I && I.isFormulaError && (v = I);
let R = !1;
const A = C.precedents;
if (A) {
const ne = A.length, ue = C.inputs;
for (let be = 0; be < ne; be++) {
const Q = A[be], fe = Q.calc;
if (fe && fe.pending) {
R = !0;
continue;
}
if (Q.isFormulaError) {
ue[be] = Q;
continue;
}
const ge = Q.colStart, ae = Q.rowStart, Z = Q.colEnd;
Q.rowEnd !== ae || ge !== Z ? (o > 0 && (r.length = o, qu(r, m, h, _), o = 0), ue[be] = new Qo(m, null, { ...Q }, null, S)) : ue[be] = fe === void 0 ? Q : fe.cachedValue;
}
C.pendingPrecedents = R;
}
const M = _ ? b : x, T = _ ? x : b;
n.node = C, n.colIndex = b, n.rowIndex = x;
const k = w.formula;
let P, B;
const H = C.pending;
let z = H;
if ((R || C.pendingPromise) && (z = !0, P = C.cachedValue ?? null, C.pendingPromise && (C.pendingResolved ? (C.pendingPromise = null, C.pendingResolved = !1, z = !1) : (C.pendingPromise.cancelled = !0, P = void 0))), P === void 0 && (n.formula = k, n.colIndex = b, n.rowIndex = x, P = k.evaluate(t, void 0, C.inputs), n.formula = null, B = P && P.then ? P : null, z = !!B), z !== H && (C.pending = z, p || (p = Gn(_)), p.append(M, T, z)), B && (P = C.cachedValue ?? null, !B.__originator)) {
B.__originator = i;
const ne = C;
Ts.add(ne), ne.pendingPromise = B, ne.pendingResolved = !1, B.then((ue) => {
if (Ts.delete(ne), B.cancelled) return;
ne.pendingPromise = B, ne.pendingResolved = !0;
let be = Ui(ue, t);
be === null && (be = 0), ne.cachedValue = be, this._scheduleRecalculation(ne);
}, (ue) => {
});
}
let W = 1, L = 1;
const j = I instanceof ht;
let G;
const V = I instanceof Ee.Spill;
if (j || V) {
So.colStart = b, So.rowStart = x, So.colEnd = b, So.rowEnd = x;
const ne = g.search(So);
for (let ue = 0; !G && ue < ne.length; ue++) {
const be = ne[ue];
be.colStart === b && be.rowStart === x && (G = be);
}
if (G) {
if (j) {
const be = I;
W = be.getWidth(), L = be.getHeight();
}
const ue = { colStart: b, rowStart: x, colEnd: b + W - 1, rowEnd: x + L - 1 };
g.remove(G), G && G.value.getError() || (c.insertNonOverlapping({ ...ue, value: null }), m.delete(ue), h.insertNonOverlapping(ue));
}
}
let $ = 1, J = 1;
const K = P, he = K?.isIRange;
let le, pe = P instanceof Ee.Spill;
if (he && K.size > 1) {
$ = K.getWidth(), J = K.getHeight();
const ne = { colStart: b, rowStart: x, colEnd: b + $ - 1, rowEnd: x + J - 1 }, ue = t.getEntireCoords(), be = !D.isRangeWithinRange(ne, ue);
if (be && (ne.colEnd = Math.min(ne.colEnd, ue.colEnd), ne.rowEnd = Math.min(ne.rowEnd, ue.rowEnd)), pe = be, !pe) {
const ge = c.search(ne);
if (pe = ge.length > 1, !pe && ge.length === 1) {
const ae = ge[0], Z = D.intersectRanges(ne, ae, Be);
(Z && (Z.rowEnd !== Z.rowStart || Z.colStart !== Z.colEnd) || Z.colStart !== b || Z.rowStart !== x) && (pe = !0);
}
}
let Q, fe;
if (pe)
P = Ee.BuiltIn.Spill, $ = 1, J = 1, Q = [[M, [[T, [P]]]]], m.setValues(Q), fe = { colStart: b, rowStart: x, colEnd: b, rowEnd: x };
else {
const ge = MS(K, M, T);
ge && (Q = ge.tuples), Q && m.setValues(Q), fe = ne;
}
le = { ...ne, value: new hr(ne, i, pe) }, g.insert(le), E = Wl(E, C, ne), h.insertNonOverlapping(fe), l.insertNonOverlapping(fe), c.insertNonOverlapping({ ...fe, value: new qt(fe, f) });
}
(!D.isEqualRanges(G, le) || pe || V) && (G && u.insert(G), le && u.insert(le)), $ === W && J === L || (C.state = nu, l.insertNonOverlapping({ colStart: b, rowStart: x, colEnd: b + Math.max($, W) - 1, rowEnd: x + Math.max(J, L) - 1 }), s = !1);
let ee = P && P.isFormulaError ? P : null;
k.getError() && (ee = k.getError()), (ee || v && !e) && (ee && !ee.equals(v) || v && v.equals(ee)), C.cachedValue = P, r[o++] = C;
}
if (n.node = null, n.colIndex = Number.MAX_SAFE_INTEGER, n.rowIndex = Number.MAX_SAFE_INTEGER, p) {
const y = p.done(!0);
this._notifyPending.load(y);
}
return o > 0 && (r.length = o, qu(r, m, h, _), o = 0), { completed: s, dynamic: E, count: Eo };
}
async calculate(e) {
const t = this._calculation.getStatus();
if (t === Ye.Status.Starting) return void this._addToPending(() => this.calculate(e));
if (t !== Ye.Status.Ready) return;
let n = this._fullCalcRequired;
n || (typeof e == "boolean" ? n = e : e && (n = e.full ?? !1));
const r = this._invalidations;
if (this._formulaSpatial.isEmpty()) {
if (r.clear(), Ts.size > 0) {
const h = ++wo;
Ts.forEach((u) => {
u.markId = h;
});
}
return this._notifyCalculated(e);
}
let o = n;
const s = this._volatile;
let i = ++wo, l = this._collectDirties(i, o, r.all(), s);
if (r.clear(), s.clear(), !o && l.length === 0) return this._notifyCalculated(e);
o && this._clearCalcs();
const c = this._resetScope();
for (; l.length > 0; ) {
i = ++wo;
const h = this._markAndPlan(o, l, i).onces;
if (h) {
const d = this._precedentSpatial, g = h.length;
for (let m = 0; m < g; m++) d.remove(h[m], Ju);
}
l.length = 0;
const u = this._evaluate(o);
if (u.dynamic && this._precedentSpatial.load(u.dynamic), c.dynamicPrecedentsInserts && (this._precedentSpatial.load(c.dynamicPrecedentsInserts), c.dynamicPrecedentsInserts = []), c.conflatingFormats) {
const d = c.conflatingFormats.done(!0), g = this._notifyFormats;
for (let m = 0; m < d.length; m++) {
const f = d[m];
g.insertNonOverlapping(f);
}
c.conflatingFormats = null;
}
u.completed || (o = !1, i = ++wo, l = this._collectDirties(i, o, r.all(), s), r.clear());
}
return this._clearScope(), this._notifyCalculated(e);
}
_clearScope() {
const e = this._calculation._getScope();
e && (e.rowIndex = 0, e.colIndex = 0, e.node = null, e.values = this._values, e.formulaSpatial = this._formulaSpatial, e.volatile = this._volatile, e.conflatingFormats = null, e.dynamicPrecedentsInserts = null, e.formula = null, e.getEntireCoords = Fl);
}
_resetScope() {
const e = this._calculation._getScope();
if (e) return e.rowIndex = 0, e.colIndex = 0, e.node = null, e.values = this._values, e.formulaSpatial = this._formulaSpatial, e.volatile = this._volatile, e.conflatingFormats = null, e.dynamicPrecedentsInserts = null, e.formula = null, e.getEntireCoords = this._getEntireCoords, e;
}
_clearCalcs() {
const e = this._values, t = this._spillSpatial, n = this._contentfulSpatial, r = t.all();
for (let o = 0; o < r.length; o++) {
const s = r[o];
s.value.getError() || (e.delete(s), n.insertNonOverlapping({ ...s, value: null }));
}
t.clear(), this._errorSpatial.clear(), this._pendingSpatial.clear(), this._volatile.clear(), this._clearNotifications();
}
_clearNotifications() {
this._invalidations.clear(), this._notifyValues.clear(), this._notifySpills.clear(), this._notifyFormats.clear(), this._notifyPending.clear();
}
_clearAll() {
this._cycleId !== 1 && this._cycleId++, wo++, this._formulaSpatial.clear(), this._contentfulSpatial.clear(), this._pendingInvalidations.clear(), this._values.clear(), this._precedentSpatial.clear(), this._volatile.clear(), this._spillSpatial.clear(), this._errorSpatial.clear(), this._pendingSpatial.clear(), this._clearNotifications(), this._notifyFormulaInsertEntries = void 0, this._notifyFormulaRemoveEntries = void 0;
}
_addToPending(e) {
let t = this._pendingActions;
if (!t) {
this._pendingActions = t = [];
const n = this;
n._calculation.addListeners({ onReady: () => {
(async () => {
const r = n._pendingActions, o = r.length;
for (let s = 0; s < o; s++) {
const i = r[s], l = await i.bind(n)();
n._options.onCalculated?.(l);
}
this._pendingActions = null;
})();
}, onError: () => {
} }, { once: !0 });
}
t.push(e);
}
fromJSON(e) {
const t = this._calculation.getStatus();
if (t === Ye.Status.Starting) return void this._addToPending(() => Promise.resolve(this.fromJSON(e)));
if (t !== Ye.Status.Ready) return;
this._clearAll();
const n = { cycleId: 0, isFull: !0 };
if (!e) return n;
this._isProcessingJSON = !0;
try {
if (e.data) {
const s = e.data;
this._values.setValues(s);
const i = this._values.getOrientation() === O.Orientation.Column, l = tu(s, i);
this._contentfulSpatial.load(l);
}
const r = this._formulaSpatial, o = e.formulas;
if (o) {
const s = e.dynamic, i = /* @__PURE__ */ new Set();
if (s) {
const p = s.length;
for (let S = 0; S < p; S++) {
const E = s[S], y = E[0].split(":")[0];
i.add(y);
}
}
const l = o.length, c = new Array(l), h = [], u = [], d = this._calculation._getContext(), g = this._calculation._getScope();
g.colIndex = 0, g.rowIndex = 0;
const m = this._getFormulaParser();
for (let p = 0; p < l; p++) {
const S = o[p], E = S[0], y = At(E), C = S[1], w = y.rowStart, b = y.colStart;
g.colIndex = b, g.rowIndex = w;
let x = m.parse(d, C);
const I = x.getDirectPrecedentsAt(w, b, !0, As, Ms), v = I.length;
v === 1 && (x = x.wrapImplicit(w, b, i));
const R = { ...y }, A = new _n(R, x);
y.value = A, c[p] = y;
const M = y.rowEnd, T = y.colEnd - b, k = M - w, P = [];
for (let B = 0; B < v; B++) {
const H = I[B];
if (H instanceof Ee.Known) continue;
const z = As[B], W = Ms[B], L = { colStart: H.colStart, rowStart: H.rowStart, colEnd: H.colEnd + (W ? 0 : T), rowEnd: H.rowEnd + (z ? 0 : k), value: { blockEntry: y, width: T + 1, height: k + 1, index: B, $absWidth: W, $absHeight: z, once: null } };
P.push(H), u.push(L);
}
h.push({ colStart: R.colStart, rowStart: R.rowStart, colEnd: R.colEnd, rowEnd: R.rowEnd, value: { tokens: x.getTokens(), references: x.getReferences(), precedents: P } });
}
if (r.load(c), this._precedentSpatial.load(u), h.length > 0 && (n.formulaInserts = h), s) {
const p = [], S = [];
let E;
const y = this._values, C = s.length;
for (let w = 0; w < C; w++) {
const b = s[w], x = b[0], I = At(x), v = b[1], R = { ...I }, A = R.colStart, M = R.rowStart, T = R.colEnd, k = R.rowEnd;
Fr.colStart = A, Fr.rowStart = M, Fr.colEnd = A, Fr.rowEnd = M;
const P = r.search(Fr);
if (P.length !== 1) continue;
const B = P[0].value, H = B.ref, z = B.calcs, W = M - H.rowStart, L = A - H.colStart, j = z[W][L];
if (v) j.cachedValue = Ee.BuiltIn.Spill;
else {
const V = new ht(y, R);
j.cachedValue = V;
}
I.value = new hr(R, 0, v), S.push(I);
const G = { colStart: A, rowStart: M, colEnd: T, rowEnd: k, value: v };
D.isSingleCell(G) || p.push(G), Wl(E, j, R);
}
this._spillSpatial.load(S), this._precedentSpatial.load(E), p.length > 0 && (n.spillInserts = p);
}
const f = e.volatile, _ = f ? f.length : 0;
if (_ > 0) {
const p = this._volatile, S = (E) => {
p.add(E);
};
for (let E = 0; E < _; E++) {
const y = f[E], C = At(y, Fr), w = r.search(C), b = w.length;
for (let x = 0; x < b; x++) {
const I = w[x];
TS(I, C, S);
}
}
}
}
} catch (r) {
throw r;
} finally {
this._isProcessingJSON = !1;
}
return n;
}
async toJSON(e = !1) {
const t = this._formulaSpatial.all(), n = t.length;
if (n === 0) return null;
const r = {};
if (n > 0) {
const l = new Array(n);
for (let c = 0; c < n; c++) {
const h = t[c];
l[c] = h.value.toJSON();
}
r.formulas = l;
}
const o = this._spillSpatial.all(), s = o.length;
if (s > 0) {
const l = this._getEntireCoords(), c = new Array(s);
for (let h = 0; h < s; h++) {
const u = o[h], d = Rn(u, l);
c[h] = [d, u.value.getError()];
}
r.dynamic = c;
}
const i = this._volatile;
if (i.size > 0) {
const l = i.values();
let c = l.next();
const h = this._values.getOrientation() === O.Orientation.Column, u = Gn(!0);
for (; !c.done; ) {
const f = c.value;
if (Array.isArray(f)) for (let _ = 0; _ < f.length; _++) {
const p = f[_];
for (let S = 0; S < p.length; S++) {
const E = p[S], y = E.colIndex, C = E.rowIndex, w = h ? y : C, b = h ? C : y;
u.append(w, b);
}
}
else {
const _ = f.colIndex, p = f.rowIndex, S = h ? _ : p, E = h ? p : _;
u.append(S, E);
}
c = l.next();
}
const d = u.done(!0), g = d.length, m = new Array(g);
for (let f = 0; f < g; f++) {
const _ = d[f], p = Rn(_, this._getEntireCoords());
m[f] = p;
}
r.volatile = m;
}
return r;
}
}
const qu = (a, e, t, n) => {
const r = new Oe.Builder(FS), o = Gn(n);
a.sort(n ? D.columnFirstCellComparator : D.rowFirstCellComparator);
const s = a.length;
for (let c = 0; c < s; c++) {
const h = a[c], u = h.colIndex, d = h.rowIndex;
if (!h.cachedValue?.isIRange) {
const m = n ? u : d, f = n ? d : u;
let _ = h.cachedValue;
r.addValue(m, f, _), o.append(m, f);
}
}
const i = r.build();
i && i.tuples && e.setValues(i.tuples);
const l = o.done(!0);
for (let c = 0; c < l.length; c++) {
const h = l[c];
t.insertNonOverlapping(h);
}
}, TS = (a, e, t) => {
const n = a.colStart, r = a.rowStart, o = a.colEnd, s = a.rowEnd, i = e.colStart, l = e.rowStart, c = e.colEnd, h = e.rowEnd, u = Math.max(n, i), d = Math.max(r, l), g = Math.min(o, c), m = Math.min(s, h), f = a.value.calcs;
for (let _ = d; _ <= m; _++) {
const p = _ - r, S = f[p];
for (let E = u; E <= g; E++) {
const y = E - n;
t(S[y], p, y);
}
}
}, Ku = (a, e, t, n) => {
const r = a.value, o = r.$absHeight, s = r.$absWidth, i = r.width, l = r.height, c = r.blockEntry.value.calcs, h = t - a.colStart, u = e - a.rowStart, d = Math.min(Math.max(h, 0), i - 1), g = Math.min(Math.max(u, 0), l - 1);
if (o || s) if (s) {
const m = c[g];
for (let f = 0; f < i; f++)
n(m[f]);
} else if (o) for (let m = 0; m < l; m++)
n(c[m][d]);
else for (let m = 0; m < l; m++) {
const f = c[m];
for (let _ = 0; _ < i; _++)
n(f[_]);
}
else
n(c[g][d]);
}, NS = { rowIndex: 0, colIndex: 0 }, Be = { rowStart: 0, colStart: 0, rowEnd: 0, colEnd: 0 }, As = [], Ms = [], Fr = { rowStart: 0, colStart: 0, rowEnd: 0, colEnd: 0 }, So = { rowStart: 0, colStart: 0, rowEnd: 0, colEnd: 0 };
new Ee.Calc("Cyclical dependency");
const FS = (a) => new jt(a);
let wo = 0;
const fr = 1e4, kS = new Array(fr), OS = new Array(fr), Ts = /* @__PURE__ */ new Set(), Ya = new Array(fr);
let yo = 0;
const Qa = new Array(fr);
let Za = 0, Ns = 0;
const el = new Array(fr);
let tl = 0, Fs = 0;
const Xu = new Array(fr);
let Eo = 0;
const Yu = new Array(fr), Co = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0 }, bo = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0 }, nl = [null, null], DS = Object.freeze({ inserts: F.EmptyArray, removes: F.EmptyArray });
function LS(a, e, t, n) {
const r = a;
if (r?.getSplit) {
const o = r.getSplit(e, t, n);
if (o === void 0) return;
e[0].value = o[0], e[1].value = o[1];
}
return e;
}
class BS {
constructor(e, t = !0) {
this._options = { ...HS, ...e }, this._getFunction = this._options.getFunction, this._isColumn = t;
}
_setInstanceScope(e) {
this._instanceScope = e;
}
async _initialize() {
const e = await Bd._validate(!0), t = PS();
this._calcScope = t, this._runtime = new zS(this._options, e);
const { initializeBuiltIns: n } = await import("./BzoFQzdPKafR43T-.mjs"), r = this;
return this._builtInFunctions = Object.freeze(n(() => r)), { builtInFunctions: this._builtInFunctions, calcScope: this._calcScope };
}
getBuiltInFunctions() {
return this._builtInFunctions;
}
getFunction(e) {
return this._builtInFunctions.get(e) ?? this._getFunction?.(e);
}
getNumberFormat(e, t) {
return Nt.Parser.formatValue(e, t, { date1904: this._options.isDate1904?.() ?? !1 });
}
getEntireCoords() {
return this._calcScope.getEntireCoords();
}
getFormulaAt(e, t) {
const n = this._calcScope.formulaSpatial;
if (!n) return null;
vo.colStart = t, vo.rowStart = e, vo.colEnd = t, vo.rowEnd = e;
const r = n.search(vo);
return r.length === 0 ? null : r[0].value.formula.getTextAt(e, t) ?? null;
}
markVolatile() {
const e = this._calcScope, t = e.volatile;
t && t.add(e.node);
}
formatResults(e) {
const t = this._calcScope, n = this._isColumn, r = n ? t.colIndex : t.rowIndex, o = n ? t.rowIndex : t.colIndex;
t.conflatingFormats || (t.conflatingFormats = Gn(n)), t.conflatingFormats.append(r, o, e);
}
getSheetIndex(e) {
const t = this._calcScope;
return e === void 0 && (e = t.sheetName), this._options.getSheetIndex?.(e) ?? -1;
}
getSheetCount() {
return this._options.getSheetCount?.() ?? 1;
}
isValidDate(e) {
return to(e);
}
fromOADate(e) {
return no(e, this._options.isDate1904?.() ?? !1);
}
toOADate(e) {
return es(e, this._options.isDate1904?.() ?? !1);
}
_fromTuples(e, t = null, n = !1) {
if (!e) return null;
const r = Jo(e.bounds, !0), o = this._calcScope, s = this._isColumn ? O.Orientation.Column : O.Orientation.Row, i = new sn({ orientation: s, maxCoords: o.getEntireCoords() });
return i.setValues(e.tuples), new ht(i, r, t, n);
}
getValueAt(e, t) {
return this._calcScope.values.getValueAt(e, t) ?? null;
}
getSpillAt(e, t) {
const n = this._calcScope.spillSpatial;
if (!n) return null;
xo.rowStart = e, xo.colStart = t, xo.rowEnd = e, xo.colEnd = t;
const r = n.search(xo);
if (r.length === 0) return null;
for (let o = 0; o < r.length; o++) {
const s = r[o];
if (s.rowStart === e && s.colStart === t) return this.getReference(D.sanitizeRange(s));
}
return null;
}
getRange(e, t) {
if (e?.isIRange) return e;
let n;
const r = Array.isArray(e);
if (t = t ?? r, r) if (Array.isArray(e[0])) n = e;
else {
if (e[0]?.isIRange) throw Ee.BuiltIn.Value;
n = [e];
}
else n = [[e]];
const o = this._isColumn, s = o ? O.Orientation.Column : O.Orientation.Row, i = this._fromTuples(Ii(n, o, Tt(0, 0, void 0, void 0, o), !0), void 0, t);
if (i) return i;
const l = new sn({ orientation: s, maxCoords: this._calcScope.getEntireCoords() });
return new ht(l, D.EmptyRange, void 0, t);
}
getPosition() {
const e = this._calcScope;
return { colIndex: e.colIndex, rowIndex: e.rowIndex };
}
getReference(e, t) {
if (!e) throw Ee.BuiltIn.Ref;
const n = this._calcScope, r = n.getEntireCoords;
if (typeof e == "string") {
if (t) throw Ee.BuiltIn.Ref;
try {
const c = sc(e, r(), ss, () => {
throw Ee.BuiltIn.Ref;
}, t);
if (c.length > 1) throw Ee.BuiltIn.Ref;
e = c[0];
} catch {
throw Ee.BuiltIn.Ref;
}
}
if (!e) throw Ee.BuiltIn.Ref;
const o = n.values;
let s;
const i = n.node;
let l;
if (i) {
const c = i.precedents;
l = WS(c, e);
}
if (l) {
const c = l.calc;
s = c && c.isIReferenceRange ? c.cachedValue : new Qo(o, void 0, e, null, r);
} else n.dynamicPrecedentsInserts = Wl(n.dynamicPrecedentsInserts, i, e), s = new Qo(o, void 0, e, null, r);
return s;
}
getAddress(e, t = !1) {
e || (e = this.getPosition());
const n = this.getEntireCoords().sheetName;
return e.colIndex !== void 0 ? ((r, o, s = !1) => s ? hi(r, o) : La(r, o))(e, n, t) : ((r, o, s = !1) => (s ? hi({ colIndex: r.colStart, rowIndex: r.rowStart, $colIndex: r.$colStart, $rowIndex: r.$rowStart, sheetName: r.sheetName }, o) : La({ colIndex: r.colStart, rowIndex: r.rowStart, $colIndex: r.$colStart, $rowIndex: r.$rowStart, sheetName: r.sheetName }, o)) + ":" + (s ? hi({ colIndex: r.colEnd, rowIndex: r.rowEnd, $colIndex: r.$colEnd, $rowIndex: r.$rowEnd }, null) : La({ colIndex: r.colEnd, rowIndex: r.rowEnd, $colIndex: r.$colEnd, $rowIndex: r.$rowEnd }, null)))(e, n, t);
}
parseAsDateTime(e, t = !1) {
return function(n, r = !1, o = !1) {
let s = n, i = ag(n, r, !0);
i && (s = i.leadingText);
let l = null;
if (s.trim().length > 0 && (l = Xl(s, r), !l && o)) return null;
!l && i?.leadingText.trim().length > 0 && (i = null);
let c = 0;
return l && (c += l.asOADate), i && (c += i.parsed.oaDateTime), c;
}(e, this._options.isDate1904?.() ?? !1, t);
}
getRuntime() {
return this._runtime;
}
get [Symbol.toStringTag]() {
return "[CalculationContext]";
}
toString() {
let e = "";
const t = this._instanceScope;
let n;
return t && (n = t.toString?.()), n && n && (e = `${e}:[${n}]`), e;
}
}
class zS {
constructor(e, t) {
this._options = e, this._license = t;
}
getCurrencySymbol() {
return "$";
}
getNumberDecimalSeparator() {
return ".";
}
getNumberGroupSeparator() {
return ",";
}
isDate1904() {
return this._options.isDate1904?.() ?? !1;
}
getDescription() {
return "Calculation Runtime";
}
getLocation() {
return F.isNode() ? process.cwd() : window.location?.href ?? "/";
}
getVersion() {
try {
const e = "0.6.4";
if (e.indexOf(".env.") === -1) return `${e}`;
} catch {
return "local";
}
}
getOS() {
return F.getOS();
}
getUser() {
return this._license?.licensee?.() ?? null;
}
}
const PS = () => ({ rowIndex: 0, colIndex: 0, sheetName: null, node: null, values: null, formulaSpatial: null, spillSpatial: null, volatile: null, conflatingFormats: null, dynamicPrecedentsInserts: null, formula: null, getEntireCoords: () => rs }), HS = { getSheetIndex: (a) => -1, getSheetCount: () => 1, getSheetName: () => null, getEntireCoords: () => rs, getNamed: (a, e) => null, getFunction: (a) => null, isDate1904: () => !1 }, WS = (a, e) => {
if (!a) return;
const t = a.length;
if (t === 0) return;
const n = e.colStart, r = e.rowStart, o = e.colEnd, s = e.rowEnd;
for (let i = 0; i < t; i++) {
const l = a[i], c = l;
if (c !== void 0 && l.colStart === n && l.rowStart === r && l.colEnd === o && l.rowEnd === s) return c;
}
return null;
}, vo = { rowStart: 0, colStart: 0, rowEnd: 0, colEnd: 0 }, xo = { rowStart: 0, colStart: 0, rowEnd: 0, colEnd: 0 };
class jS {
_setScope(e) {
this._scope = e;
}
_getScope(e = !1) {
const t = this._scope;
if (!t && !e) throw new Error("FunctionContext can only be used in a function.");
return t;
}
getNumberFormat(e, t) {
return this._getScope().getNumberFormat(e, t);
}
getEntireCoords() {
return this._getScope().getEntireCoords() ?? rs;
}
isValidDate(e) {
return this._getScope().isValidDate(e);
}
parseAsDateTime(e, t) {
return this._getScope().parseAsDateTime(e, t);
}
fromOADate(e) {
return this._getScope().fromOADate(e);
}
toOADate(e) {
return this._getScope().toOADate(e);
}
getRange(e) {
return this._getScope().getRange(e);
}
getValueAt(e, t) {
return this._getScope().getValueAt(e, t);
}
getPosition() {
return this._getScope().getPosition?.() ?? y0;
}
getReference(e, t) {
return this._getScope().getReference(e, t);
}
getFormulaAt(e, t) {
return this._getScope().getFormulaAt?.(e, t) ?? null;
}
getSpillAt(e, t) {
return this._getScope().getSpillAt?.(e, t) ?? null;
}
getSheetIndex(e) {
return this._getScope().getSheetIndex?.(e) ?? -1;
}
getSheetCount() {
return this._getScope().getSheetCount?.() ?? 1;
}
markVolatile() {
this._getScope().markVolatile?.();
}
formatResults(e) {
this._getScope().formatResults?.(e);
}
getFunction(e) {
return this._getScope().getFunction?.(e) ?? null;
}
getAddress(e, t) {
return this._getScope().getAddress(e, t);
}
getRuntime() {
return this._getScope().getRuntime();
}
get [Symbol.toStringTag]() {
return "[FormulaContext]";
}
toString() {
const e = this._getScope();
if (e) {
const t = e.toString?.();
if (t) return t;
}
return e ? "" : "{NO SCOPE}";
}
}
const VS = new jS(), ki = "__SHEETXL";
let lr;
const Qu = { FormulaContext: lr, ScalarType: q, IRange: O, FormulaError: Ee, Observable: Fm };
let pi;
function uc(a) {
lr || (lr = VS, Qu.FormulaContext = lr), pi = globalThis[ki], globalThis[ki] = Qu, lr._setScope(a);
}
function Oi() {
pi ? (globalThis[ki] = pi, pi = void 0) : delete globalThis[ki], lr && lr._setScope(null);
}
var bn;
(bn || (bn = {})).Context = { Workbook: "workbook", Sheet: "sheet", Ranges: "ranges", Range: "range", Calculation: "calculation" };
class Di {
constructor(e, t, n, r = null, o = !1) {
this._ct = bn.Context.Calculation, this._builtIn = !1, this._broadcast = !1, this._pj = null, this._json = e, this._n = e.name, this._d = new JS(e), this._ct = e.context ?? bn.Context.Calculation;
const s = e.parameters;
let i;
this._pj = s, t || (console.log(`TypeFunction '${e.name}' was not provided a function implementation.`), t = () => {
}), this._fn = t.bind(this), this._cf = n ?? GS, this._builtIn = o, i = r ? typeof r == "function" ? r : () => Promise.resolve(r) : $S(e), this._descFn = i;
const l = s?.length ?? 0;
let c = l === 1 || l === 2;
c && (s[0].arrayDepth > 0 || s[0].range) && (c = !1), c && l === 2 && (s[1].arrayDepth > 0 || s[1].range) && (c = !1), this._broadcast = c;
}
execute(...e) {
const t = this._pj, n = [], r = this._cf?.();
uc(r);
let o = !1, s = null;
const i = t?.length ?? 0;
let l, c = this._broadcast;
if (c) {
const h = Xh(e[0]);
if (i === 1 && h) c = !1;
else if (i === 2) {
const u = Xh(e[1]);
h && u && (c = !1);
}
}
try {
for (let u = 0; !o && u < i; u++) {
const d = t[u];
let g = d.scalar ?? null;
g !== q.Null && g !== "*" || (g = null);
let m = d.range ?? null;
const f = d.rest ?? !1, _ = d.optional ?? !1;
let p = e[u];
if (_ && p === null && (p = void 0), p === void 0) {
if (_) {
n.push(void 0);
continue;
}
if (!_ && !f) throw u <= e.length ? ed.ARGS_TOO_FEW([d.name], this._n) : ed.PARAM_MISSING(d.name, this._n);
if (u >= e.length) {
o = !0;
continue;
}
}
const S = d.arrayDepth ?? 0;
let E = (d.range ? 2 : 0) + S;
const y = d.rest ?? !1;
if (y) for (; u < e.length && !s; ) p !== void 0 && (s = jl(r, n, p, g, m, S, y, E)), p = e[++u];
else c && (m = "l", E = 2), s = jl(r, n, p, g, m, S, y, E), o = !!s;
}
if (s) throw s;
for (; n.length > 0 && n[n.length - 1] === void 0; ) n.length--;
const h = this._fn;
if (c) {
if (n.length === 1) {
const u = n[0];
let d = t[0].scalar;
d !== q.Null && d !== "*" || (d = null), l = u.map((g) => {
if (g instanceof Ee.Known) return g;
let m = g;
try {
m = h(m), (Array.isArray(m) || m?.isIRange) && (m = Ee.BuiltIn.Value);
} catch (f) {
m = f;
}
return m;
}, { type: d });
}
if (n.length === 2) {
const u = n[0];
let d = t[0].scalar;
d !== q.Null && d !== "*" || (d = null);
const g = n[1];
let m = t[1].scalar;
m !== q.Null && m !== "*" || (m = null), l = u.broadcast(g, (f, _) => {
if (f instanceof Ee.Known) return f;
if (_ instanceof Ee.Known) return _;
let p;
try {
p = h(f, _), (Array.isArray(p) || p?.isIRange) && (p = Ee.BuiltIn.Value);
} catch (S) {
p = S;
}
return p;
}, { type: d, otherType: m });
}
} else l = h(...n);
l = Ui(l, r);
} catch (h) {
throw h;
} finally {
Oi();
}
return l;
}
getName() {
return this._n;
}
getDeclaration() {
return this._d;
}
async getDescriptor(e) {
if (this._desc) return this._desc;
const t = await Promise.resolve(this._descFn(e));
return this._desc = new qS(this, t), this._desc;
}
isBuiltIn() {
return this._builtIn;
}
getContext() {
const e = this._ct;
if (e === "sheet" || e === "workbook" || e === "ranges" || e === "range") {
const t = this._json;
return t && t.behavior && t.behavior.default ? "autoRun" : "macro";
}
return "formula";
}
get [Symbol.toStringTag]() {
return "[TypedFunction]";
}
toString() {
let e = "";
const t = this._pj;
return t.length > 0 && (e = t.map((n) => {
let r = n.name;
return n.rest && (r = "..." + r), n.optional && (r += "?"), r += ": " + ((o, s) => {
if (s) {
const i = E0.get(s) ?? "InvalidRange";
return o ? `${i}<${Kh.get(o) ?? "InvalidScalar"}>` : i;
}
return Kh.get(o) ?? "InvalidScalar";
})(n.scalar, n.range), r += "[]".repeat(n.arrayDepth), r;
}).join(", ")), `${this.getName()}(${e})`;
}
get isIFunction() {
return !0;
}
get isITypedFunction() {
return !0;
}
}
const $S = (a) => async (e) => {
const t = {};
for (let n = 0; n < a.parameters.length; n++) t[a.parameters[n].name] = F.camelToPrettyCase(a.parameters[n].description);
return { summary: F.camelToPrettyCase(a.name), parameters: t, category: "User Defined" };
}, GS = () => null;
class wm {
constructor(e) {
this._s = e.scalar, this._r = e.range ?? null, this._d = e.arrayDepth ?? 0;
}
getScalarType() {
return this._s;
}
getRangeType() {
return this._r;
}
getArrayDepth() {
return this._d;
}
}
class US extends wm {
constructor(e) {
super(e), this._n = e.name, this._o = e.optional ?? !1, this._rest = e.rest ?? !1, this._e = e.enums ? Object.freeze(e.enums) : F.EmptyArray;
}
getName() {
return this._n;
}
isOptional() {
return this._o;
}
isRest() {
return this._rest;
}
getEnums() {
return this._e;
}
}
class Zu extends wm {
constructor(e) {
super(e), this._a = e.async ?? !1, this._stream = e.stream ?? !1;
}
isAsync() {
return this._a;
}
isStreaming() {
return this._stream;
}
}
class JS {
constructor(e) {
if (this._n = e.name, e.parameters) {
const t = e.parameters.length, n = new Array(t);
for (let r = 0; r < t; r++) n[r] = new US(e.parameters[r]);
this._p = Object.freeze(n);
} else this._p = F.EmptyArray;
e.returnType ? this._r = new Zu(e.returnType) : this._r = new Zu({ scalar: null, arrayDepth: 0, range: null });
}
getName() {
return this._n;
}
getParameters() {
return this._p;
}
getReturnType() {
return this._r;
}
}
class qS {
constructor(e, t) {
if (this._n = t.name, this._fn = e, this._s = t.summary ?? F.camelToPrettyCase(t.name), this._c = t.category ?? "Uncategorized", this._h = t.hidden ?? !1, t.links && t.links.length > 0) {
const n = t.links.length, r = new Array(n);
for (let o = 0; o < n; o++) r[o] = Object.freeze([t.links[o][0], t.links[o][1]]);
this._l = Object.freeze(r);
} else this._l = F.EmptyArray;
if (t.parameters) {
for (const n in t.parameters) if (Object.prototype.hasOwnProperty.call(t.parameters, n)) {
const r = t.parameters[n].description, o = t.parameters[n].example, s = t.parameters[n].defaultValue, i = {};
r && (i.description = r), o && (i.example = o), s !== void 0 && (i.defaultValue = s), Object.freeze(i);
}
}
}
getName() {
return this._n;
}
getSummary() {
return this._s;
}
getCategory() {
return this._c;
}
isHidden() {
return this._h;
}
getLinks() {
return this._l;
}
getParameters() {
return this._p;
}
get [Symbol.toStringTag]() {
return "[Descriptor]";
}
toString() {
const e = this._fn;
return `${this.getSummary()}: ${e}`;
}
}
const jl = (a, e, t, n, r, o, s, i) => {
if (t && t.colStart !== void 0) if (r) t = a.getReference?.(t);
else {
const l = t.colStart, c = t.rowStart, h = t.colEnd;
t = t.rowEnd !== c || l !== h ? a.getReference?.(t) : a.getValueAt(c, l);
}
if (i === 0) {
let l = ((c, h = null, u = !1) => {
let d = c;
for (; Array.isArray(d); ) {
if (d.length > 1) return u ? Ee.BuiltIn.Value : d;
d = d[0];
}
if (d?.isIRange) {
if (d.size !== 1) return u ? Ee.BuiltIn.Value : d;
d = d.getValueAt(0, 0);
}
return h && (d = Jt(d, gt(d, !0), h)), d;
})(t, n, !0);
return l instanceof Ee.Known ? l : void e.push(l);
}
if (i === 2) return fo(a, e, t, n, r, Array.isArray(t));
if (i === 1 || i === 3) {
let l;
const c = s ? e : [];
if (r) {
const h = Array.isArray(t);
if (h) {
const u = t.length;
for (let d = 0; !l && d < u; d++) l = fo(a, c, t[d], n, r, h);
} else l = fo(a, c, t, n, r, h);
} else if (i === 3) {
let h = ((u) => {
let d = u, g = 0;
for (; Array.isArray(d); ) g++, d = d[0];
return d.isIRange && (g += 2), g;
})(t);
for (let u = h; u < 2; u++) t = [t], h++;
if (h === 3) {
const u = t.length;
for (let d = 0; !l && d < u; d++) l = fo(a, c, t[d], n, r, !0);
} else l = fo(a, c, t, n, r, !0);
} else l = Vg(a, c, t, n, r, r !== null);
return l?.isFormulaError ? l : void (s || e.push(c));
}
{
if (!Array.isArray(t)) {
if (n && (t = Jt(t, gt(t, !0), n, !1), t?.isFormulaError)) return e.push(t), t;
t = [t];
}
const l = t.length;
for (let c = 0; c < l; c++) {
const h = [], u = jl(a, h, t[c], n, r, o, s, i - 1);
if (u?.isFormulaError) return u;
h.length > 0 && e.push(h);
}
}
}, ed = { PARAM_MISSING: (a, e) => new Ee.NA(`Parameter ${a} is missing${e ? ` for ${e}` : ""}.`), ARGS_TOO_FEW: (a, e) => new Ee.Parse(`Argument type ${a.join(", ")} is missing${e ? ` for ${e}` : ""}.`) };
class ym {
constructor(e) {
this._emitter = null, this._readonly = null, this._closed = !1, this._options = { ...e };
const t = this;
this._transactions = this._options.transactions ?? new Xt({ transient: !0 }), this._transactionsRemoveListener = this._transactions.addStateListener(this, { onAfterStateChange(n, r, o) {
t._emitter.notify("onCollectionChange");
} }), this._emitter = new mt(this, this._transactions), this._readonly = e?.readonlyFunctions, this._initState();
}
getItems(e) {
const t = this._getState();
if (!t) return F.EmptyArray;
const n = e?.name ? e.name.toUpperCase() : null, r = e?.type ? e.type : null;
let o;
e?.category && e.category.toUpperCase(), e?.text && e.text;
const s = (l, c) => (!n || c === n) && (!r || l.getContext() === r) && (o || (o = []), void o.push(l)), i = this._readonly;
return i && i.forEach(s), t.itemsByKey.forEach(s), o ?? F.EmptyArray;
}
getByName(e) {
if (!e) return null;
const t = this._getState();
if (!t) return null;
if (!t) return F.EmptyArray;
const n = e.toUpperCase(), r = this._readonly;
if (!r || !r.size) return null;
let o = r.get(n);
return o || (o = t.itemsByKey.get(n), o || null);
}
getCount() {
const e = this._getState();
if (!e) return 0;
let t = e.itemsByKey.size;
return this._readonly && (t += this._readonly.size), t;
}
validateName(e) {
return this._validateName(e);
}
_validateName(e, t = !1) {
if (this._closed) throw new Error(Ht);
}
add(e) {
if (this._closed) throw new Error(Ht);
if (!e) throw new Error("Item must be specified.");
let t;
if (e.isIFunction) {
const o = e, s = e._json;
t = new Di(s, o._fn, () => this._options.context, o._desc);
} else {
const o = e;
t = new Di(o.declaration, o.execute, () => this._options.context, o.descriptor);
}
const n = this._getState(), r = t.getName().toUpperCase();
return n.itemsByKey.set(r, t), t;
}
beginCommit(e) {
return this._beginCommit(e);
}
_getState() {
if (this._closed) throw new Error(Ht);
return this._transactions.getState(this);
}
_beginCommit(e) {
return this._transactions.beginCommit(typeof e == "string" ? { description: e } : e);
}
_updateState(e, t = "Update", n) {
if (!e) return;
const r = this._beginCommit(t);
try {
r.updateState(this, e), r.commit(n);
} catch (o) {
throw r.rollback(), o;
}
}
_initState() {
this._updateState((e) => ({ ...e, itemsByKey: /* @__PURE__ */ new Map() }), "Initialize", { forceAmend: !0 });
}
addListeners(e, t) {
return this._emitter.addListeners(e, t);
}
isClosed() {
return this._closed;
}
close() {
this._closed || (this._emitter.notify("onClose"), this._closed = !0, this._transactionsRemoveListener?.());
}
get isFunctionCollection() {
return !0;
}
}
class Em extends mr {
constructor(e) {
super(e), this._status = Ye.Status.Off, this._statusTransition = null, this._emitter = new mt(this);
}
_getContext() {
return this._context;
}
_getScope() {
return this._scope;
}
start() {
return this._statusTransition || (this._statusTransition = (async () => {
if (this._status === Ye.Status.Off) try {
this._status = Ye.Status.Starting, this._emitter.notify("onStatusChange"), this._emitter.notify("onStarting");
const e = this, t = this._options, n = (l) => e.getFunctions().getByName(l) ?? t?.getFunction?.(l), r = new BS({ ...t, getFunction: n });
this._context = r;
const o = await r._initialize(), s = o.builtInFunctions;
this._functions = new ym({ transactions: this._transactions, context: r, readonlyFunctions: s });
const i = await import("./CW0BShcAxwxHqGt6.mjs");
this._formulaParser = new i.FormulaParser(), this._scope = o.calcScope, this._status = Ye.Status.Ready, this._emitter.notify("onStatusChange"), this._emitter.notify("onReady");
} catch (e) {
throw this._status = Ye.Status.Off, this._emitter.notify("onError", e), this._emitter.notify("onStatusChange"), e;
} finally {
this._statusTransition = null;
}
})()), this._statusTransition;
}
_createGraph(e) {
const t = this._options;
return new hc({ ...t, ...e, getFormulaParser: () => this._formulaParser, calculation: this });
}
async stop() {
this._status === Ye.Status.Ready && (this._status = Ye.Status.Stopping, this._emitter.notify("onStatusChange"), this._emitter.notify("onStopping"), this._status = Ye.Status.Off, this._emitter.notify("onStatusChange"), this._emitter.notify("onStop"));
}
getStatus() {
return this._status;
}
getFunctions() {
return this._checkReady(), this._functions;
}
getRuntime() {
return this._checkReady(), this._runtime;
}
_checkReady() {
if (this._status !== Ye.Status.Ready) throw new Error(this._statusMessage());
}
_statusMessage() {
switch (this._status) {
case Ye.Status.Off:
return "Calculation is off";
case Ye.Status.Starting:
return "Calculation is starting";
case Ye.Status.Ready:
return "Calculation is ready";
default:
return "Unknown calculation status";
}
}
}
var td, nd, rd, od, ks, Vl, Os, nn;
td || (td = {}), nd || (nd = {}), rd || (rd = {}), (ks = od || (od = {})).NumberFilterOperatorType = { Equal: "equal", GreaterThan: "greaterThan", GreaterThanOrEqual: "greaterThanOrEqual", LessThan: "lessThan", LessThanOrEqual: "lessThanOrEqual", NotEqual: "notEqual" }, ks.Type = { Color: "color", Custom: "custom", Dynamic: "dynamic", Items: "items", Icon: "icon", Top10: "top10" }, ks.DynamicType = { AboveAverage: "aboveAverage", BelowAverage: "belowAverage", LastMonth: "lastMonth", LastQuarter: "lastQuarter", LastWeek: "lastWeek", LastYear: "lastYear", M1: "M1", M2: "M2", M3: "M3", M4: "M4", M5: "M5", M6: "M6", M7: "M7", M8: "M8", M9: "M9", M10: "M10", M11: "M11", M12: "M12", NextMonth: "nextMonth", NextQuarter: "nextQuarter", NextWeek: "nextWeek", Null: "null", Q1: "Q1", Q2: "Q2", Q3: "Q3", Q4: "Q4", ThisMonth: "thisMonth", ThisQuarter: "thisQuarter", ThisWeek: "thisWeek", Today: "today", Tomorrow: "tomorrow", YearToDate: "yearToDate", Yesterday: "yesterday" }, ks.DateItemGroupingType = { Day: "day", Hour: "hour", Minute: "minute", Month: "month", Second: "Second", Year: "year" }, (Os = Vl || (Vl = {})).Type = { AboveAverage: "aboveAverage", BeginsWith: "beginsWith", CellIs: "cellIs", ColorScale: "colorScale", ContainsBlanks: "containsBlanks", ContainsErrors: "containsErrors", ContainsText: "containsText", DataBar: "dataBar", DuplicateValues: "duplicateValues", EndsWith: "endsWith", Expression: "expression", IconSet: "iconSet", NotContainsBlanks: "notContainsBlanks", NotContainsErrors: "notContainsErrors", NotContainsText: "notContainsText", TimePeriod: "timePeriod", Top10: "top10", UniqueValues: "uniqueValues" }, Os.OperatorType = { BeginsWith: "beginsWith", Between: "between", ContainsText: "containsText", EndsWith: "endsWith", Equal: "equal", GreaterThan: "greaterThan", GreaterThanOrEqual: "greaterThanOrEqual", LessThan: "lessThan", LessThanOrEqual: "lessThanOrEqual", NotBetween: "notBetween", NotContains: "notContains", NotEqual: "notEqual" }, Os.TimePeriod = { Last7Days: "last7Days", LastMonth: "lastMonth", LastWeek: "lastWeek", NextMonth: "nextMonth", NextWeek: "nextWeek", ThisMonth: "thisMonth", ThisWeek: "thisWeek", Today: "today", Tomorrow: "tomorrow", Yesterday: "yesterday" }, Os.ConditionalBoundsType = { Formula: "formula", Max: "max", Min: "min", Num: "num", Percent: "percent", Percentile: "percentile" }, (nn || (nn = {})).HeaderTextStyle = { A1: "a1", Zero: "zero", One: "one" };
class KS {
constructor(e, t, n, r) {
this._mergedReading = [], this._colsReading = [], this._rowsReading = [], this._styles = e, this._topLeft = r ?? { rowIndex: 0, colIndex: 0 }, this._sheet = new Zo({ styles: this._styles, date1904: t, container: { getName: () => n, getIndex: () => 1 } }), this._cellUpdater = this._sheet.getEntireRange().startIncrementalUpdates();
}
applyCSSStyle(e, t) {
let n = !1;
e.style || (e.style = {}, n = !0);
let r = e.style, o = { ...t };
if (t.msoIgnore) {
const u = t.msoIgnore.split(",");
let d = Object.keys(o);
for (let g = 0; g < d.length; g++) {
const m = d[g];
u.includes(m) && delete o[m];
}
}
const s = di(o.fontFamily);
r.font = {}, s && (r.font.family = s.family, r.font.fallbacks = s.fallbacks, r.font.size = s.size), r.font.size = o.fontSize, r.font.weight = o.fontWeight, r.font.style = o.fontStyle, r.font.fill = o.color;
const i = ((u) => {
if (!u) return W0;
let d = te.UnderlineStyle.None, g = !1;
return (u = u.toLowerCase()).includes("underline") && (d = te.UnderlineStyle.Single), (u.includes("line-through") || u.includes("linethrough")) && (g = !0), { underline: d, strike: g };
})(o.textDecoration);
r.font.underline = i.underline, r.font.strike = i.strike, o.textUnderlineStyle && (r.font.underline = om(o.textUnderlineStyle)), r.alignment = {}, o?.textAlign && (r.alignment.horizontal = ((u) => {
const d = F.textToKey(u);
return Hn.get(d) || null;
})(o.textAlign)), o?.textAlign && !r.alignment.horizontal && o?.textAlign !== "general" && (o.textAlign === "center-across" ? r.alignment.horizontal = X.HorizontalAlignment.CenterContinuous : o.textAlign === "fill" ? r.alignment.horizontal = X.HorizontalAlignment.Fill : o.textAlign === "121" || o.textAlign === "010" ? (r.alignment.horizontal = X.HorizontalAlignment.Distributed, r.alignment.justifyLastLine = o.textAlign === "121") : console.warn("unknown text-align", o.textAlign)), o.verticalAlign && (o.verticalAlign.toLowerCase() === "super" ? r.font.verticalAlign = te.VerticalAlignment.Super : o.verticalAlign.toLowerCase() === "sup" ? r.font.verticalAlign = te.VerticalAlignment.Sub : r.alignment.vertical = ((u) => {
const d = F.textToKey(u);
return fn.get(d) || null;
})(o.verticalAlign), r.alignment.vertical || (o.verticalAlign === "121" ? r.alignment.vertical = X.VerticalAlignment.Distributed : console.warn("unknown vertical-align", o.verticalAlign))), o.msoCharIndentCount && (r.alignment.indent = o.msoCharIndentCount), o.whiteSpace && (r.alignment.overflow = o.whiteSpace === "no-wrap" || o.whiteSpace === "nowrap" ? X.Overflow.Visible : X.Overflow.Wrap), o.msoTextControl === "shrinktofit" && (r.alignment.overflow = X.Overflow.Shrink);
let l = null;
if (o.background ? l = o.background : o.backgroundColor && (l = o.backgroundColor), l && (r.fill = { color: l }), o.msoPattern) {
let u = E_(o.msoPattern);
u && (u.patternType === Y.BuiltInSheetPattern.Solid ? r.fill = { color: u.foreground } : u.patternType !== Y.BuiltInSheetPattern.None && (l && (u.background = l), r.fill = u));
}
o.msoRotate !== void 0 && (r.alignment.rotation = ((u) => {
let d = parseFloat(u);
return isNaN(d) || (d %= 360, d > 0 ? d = 360 - d : d < 0 && (d *= -1)), d;
})(o.msoRotate));
const c = (u, d) => {
u && (r.border || (r.border = {}), r.border[u] = d);
};
o.border && o.border !== "none" && (c("top", o.border), c("left", o.border), c("right", o.border), c("bottom", o.border)), o.borderTop && c("top", o.borderTop), o.borderLeft && c("left", o.borderLeft), o.borderRight && c("right", o.borderRight), o.borderBottom && c("bottom", o.borderBottom), o.msoDiagonalUp && c("diagonalUp", o.msoDiagonalUp), o.msoDiagonalDown && c("diagonalDown", o.msoDiagonalDown);
let h = r.numberFormat;
o.msoNumberFormat && (h = ((u) => {
let d = u.replace(/(\\[0-9]{4})/g, (g) => String.fromCharCode(parseInt(g.replace(/\\/g, ""), 16)));
return d = d.replace(/(\\.{1})/g, (g) => g.substring(g.length - 1, g.length)), d.includes("\\") && (d = d.replace(/(\\.{1})/g, (g) => g.substring(g.length - 1, g.length))), d = d.replace(/^"(.*)"$/, "$1"), d;
})(o.msoNumberFormat), h.includes("\\") ? h = null : h === "Fixed" ? h = Nt.Styles.lookupStyle(r.numberFormat).formatType === Nt.Type.Number ? null : Nt.Type.Number : h === "Percent" && (h = Nt.Styles.lookupStyle(r.numberFormat).formatType === Nt.Type.Percentage ? null : Nt.Type.Percentage)), h && (r.numberFormat = h), e.style = this._styles.normalize(r), n && Object.keys(e.style).length === 0 && delete e.style;
}
onCell(e, t, n, r, o) {
const s = r(o);
let i = { value: t !== void 0 ? t : n ?? "" };
if (typeof i.value == "string" && i.value.length === 0 && (i.value = void 0), s && this.applyCSSStyle(i, s), o?.tagName.toUpperCase() === "TD") {
let l = i.style, c = l?.font ?? {};
(o.querySelectorAll("s").length > 0 || o.querySelectorAll("strike").length > 0) && (c.strike = !0), o.querySelectorAll("sub").length > 0 && (c.verticalAlign = te.VerticalAlignment.Sub), o.querySelectorAll("sup").length > 0 && (c.verticalAlign = te.VerticalAlignment.Super), (o.querySelectorAll("b").length > 0 || o.querySelectorAll("strong").length > 0) && (c.weight = 700), o.querySelectorAll("i").length > 0 && (c.style = te.Style.Italic), o.querySelectorAll("u").length > 0 && (c.underline = te.UnderlineStyle.Single), Object.keys(c).length > 0 && (l || (l = {}, i.style = l), l.font || (l.font = c));
const h = o.querySelectorAll("a");
if (h.length > 0) {
const u = h[0].getAttribute("href");
u && (i.hyperlink = u);
}
}
if (!D.isSingleCell(e)) {
const l = { rowStart: this._topLeft.rowIndex + e.rowStart, colStart: this._topLeft.colIndex + e.colStart, rowEnd: this._topLeft.rowIndex + e.rowEnd, colEnd: this._topLeft.colIndex + e.colEnd };
this._mergedReading.push(l);
}
if ((i.value !== void 0 || i.style || !(Object.keys(i).length <= 1)) && (this._cellUpdater.pushAt(this._topLeft.rowIndex + e.rowStart, this._topLeft.colIndex + e.colStart, i), !D.isSingleCell(e) && s.msoIgnore)) {
if (s.msoIgnore.includes("colspan")) {
const l = {};
s && this.applyCSSStyle(l, s);
const c = e.colEnd - e.colStart;
for (let h = 1; h <= c; h++) this._cellUpdater.pushAt(this._topLeft.rowIndex + e.rowStart, this._topLeft.colIndex + e.colStart + h, l);
e = { ...e, colEnd: e.colStart };
}
s.msoIgnore.includes("rowspan") && (e = { ...e, rowEnd: e.rowStart });
}
}
onNoTable(e, t, n) {
this.onCell({ rowStart: this._topLeft.rowIndex, colStart: this._topLeft.colIndex, rowEnd: this._topLeft.rowIndex, colEnd: this._topLeft.colIndex }, e, null, t, n);
}
onRowStart(e, t, n, r) {
const o = n(r);
if (o.msoHeightSource !== "userset") return;
let s = r.getAttribute("height") ?? o.height, i = null;
if (s && (i = qr(s, this._styles.getNormal().getFont().getSize(), "px")), i === null) for (let l = 0; l < r.cells.length; l++) {
const c = r.cells[l], h = c.getAttribute("height") ?? n(c).height;
let u = qr(h, this._styles.getNormal().getFont().getSize(), "px");
u !== null && (i = Math.max(u, i ?? 0));
}
i !== null && this._rowsReading.push({ address: { min: this._topLeft.rowIndex + e, max: this._topLeft.rowIndex + e + t - 1 }, update: { size: i * te.getDeviceScale() } });
}
onColumn(e, t, n, r) {
const o = n(r);
if (o.msoWidthSource !== "userset") return;
let s = r.getAttribute("width") ?? o.width, i = null;
s && (i = qr(s, this._styles.getNormal().getFont().getSize(), "px")), i !== null && this._colsReading.push({ address: { min: this._topLeft.colIndex + e, max: this._topLeft.colIndex + e + t - 1 }, update: { size: i * te.getDeviceScale() } });
}
onDone() {
this._colsReading.length > 0 && this._sheet.getColumnHeaders().updateHeaderPairs(this._colsReading), this._rowsReading.length > 0 && this._sheet.getRowHeaders().updateHeaderPairs(this._rowsReading), this._sheet.doBatch(() => {
this._cellUpdater.apply();
}), this._mergedReading.length > 0 && this._sheet.getRanges(this._mergedReading).merge();
}
sheet() {
return this._sheet;
}
}
let sd = !1;
class XS {
constructor(e, t) {
this._mapStylesByName = /* @__PURE__ */ new Map(), this._arrStyleNames = [], this._mapStylesByName = e, this._arrStyleNames = t;
}
setNode(e) {
this._node = e;
}
addStyle(e, t) {
t != null && (this._node?.styles || (this._node.styles = /* @__PURE__ */ new Map()), this._node.styles.set(e, t));
}
addAttribute(e, t) {
t != null && (this._node?.attributes || (this._node.attributes = /* @__PURE__ */ new Map()), this._node.attributes.set(e, t), e.toLowerCase() === "rowspan" && parseInt(t) > 1 && (this._node.rowspan = parseInt(t)), e.toLowerCase() === "colspan" && parseInt(t) > 1 && (this._node.colspan = parseInt(t)));
}
addSharedStyle(e, t) {
let n = this._mapStylesByName.get(e);
n ? n = { ...t } : (this._arrStyleNames.push(e), n = t), this._mapStylesByName.set(e, n);
}
setPlainText(e) {
this._node.plainText = e;
}
setHTMLText(e) {
this._node.htmlText = e.replace(/(?:\r\n|\r|\n)/g, "<br>");
}
}
const id = (a) => {
const e = {};
if (!a) return e;
a.endsWith(";") || (a += ";");
const t = new RegExp(';(?=([^"]*"[^"]*")*[^"]*$)', "gsm");
let n, r = 0;
for (; (n = t.exec(a)) !== null; ) {
try {
let o = a.substring(r, n.index).trim();
const s = new RegExp(':(?=([^"]*"[^"]*")*[^"]*$)', "gsm");
let i, l, c;
for (; (c = s.exec(o)) !== null; ) i = unescape(o.substring(0, c.index)).trim(), l = unescape(o.substring(c.index + 1, o.length)).trim();
l !== null && l !== "null" && (i && (i = cg(i)), e[i] = l);
} catch (o) {
console.warn(o);
}
r = n.index + 1;
}
return e;
}, Ds = (a, e) => {
const t = [];
if (!a) return t;
const n = a.children;
for (let r = 0; r < n.length; r++) {
const o = n.item(r);
if (o.nodeType === 1) {
const s = o.tagName.toUpperCase();
e.includes(s) && t.push(o);
}
}
return t;
}, YS = (a, e, t) => {
try {
let n = null, r = null;
const o = (l) => ((c, h) => {
if (!c) return {};
let u = {}, d = h.get(c.localName);
d && (u = Object.assign(u, d));
const g = c.getAttribute("class");
if (g) {
const f = h.get("." + g);
f && (u = Object.assign(u, f));
}
const m = c.getAttribute("style");
if (m) {
const f = id(m);
f && (u = Object.assign(u, f));
}
return c.getAttribute("align") && !u.textAlign && (u.textAlign = c.getAttribute("align")), u;
})(l, r);
if (a) try {
n = [];
const l = "P, H1, H2, H3, H4, H5, H6, PRE", c = a.querySelector("parsererror");
if (c) return console.warn("error", c), !1;
const h = a.querySelectorAll("html"), u = h[h.length - 1];
r = ((p) => {
const S = p.querySelectorAll("style"), E = /* @__PURE__ */ new Map();
if (S.length <= 0) return E;
for (let y = 0; y < S.length; y++) {
const C = S[y].childNodes;
for (let w = 0; w < C.length; w++) if (C[w].nodeType === Node.TEXT_NODE) {
const b = new RegExp("<!--(.*)-->", "gs");
let x = C[w].textContent;
const I = b.exec(C[w].textContent);
if (I && I.length > 1 && (x = I[1]), x = x.replace(/^\s/, ""), x?.startsWith("table")) {
const v = new RegExp("{(.*?)}", "gs");
let R, A = 0;
for (; (R = v.exec(x)) !== null; ) try {
const M = x.substring(A, R.index), T = id(R[1]);
E.set(M.trim(), T), A = R.index + R[0].length;
} catch (M) {
console.warn(M);
}
return E;
}
}
}
return E;
})(u);
const d = u.querySelectorAll("body"), g = d[d.length - 1];
let f = g.querySelectorAll("table")[0], _ = !1;
if (!f) {
let p = g.querySelectorAll("span");
f = p[0], _ = p.length > 1;
}
if (f || (f = Ds(g, l)[0]), f || (f = Ds(a, l)[0]), f?.nodeName.toUpperCase() === "TABLE") {
t.onStart?.(r);
const p = f;
t.onTableStart?.(o, p);
const S = Ds(p, "COLGROUP");
for (let C = 0; S && C < S.length; C++) {
const w = Ds(S[C], "COL");
let b = 0;
for (let x = 0; x < w.length; x++) {
const I = w[x], v = parseFloat(I.getAttribute("span")), R = isNaN(v) ? 1 : v;
t.onColumn?.(b, R, o, I), b += R;
}
}
const E = p.rows;
let y = 0;
for (let C = 0; C < E.length; C++) {
const w = E[C], b = parseFloat(w.getAttribute("span")), x = isNaN(b) ? 1 : b;
t.onRowStart?.(y, x, o, w);
const I = [];
n.push(I);
const v = w.cells;
for (let R = 0; R < v.length; R++) {
let A = v[R], M = !1;
for (let T = 0; !M && T < A.childNodes.length; T++) if (A.childNodes[T].nodeType === 8) {
const k = A.childNodes[T].textContent;
if (k !== "[if gte vml 1]") {
if (k !== "[if !vml]") {
if (k === "[endif]") {
const P = A.childNodes[T + 1];
P?.querySelectorAll && P.querySelectorAll("table, td").length === 2 && (A = P?.querySelectorAll("table, td")[1], M = !0);
}
}
}
}
I.push({ htmlValue: A.textContent?.replace(/^"|"$/gi, ""), element: A });
}
y += x, t.onRowDow?.(y, x, o, w);
}
t.onTableDone?.(o, p);
} else {
if (f?.nodeName.toUpperCase() === "SPAN") {
const p = e ? e[0]?.[0] : null, S = _ && p ? p : f.textContent.replace(/^"|"$/gi, "");
return t.onStart?.(r), t.onCell({ colStart: 0, colEnd: 0, rowStart: 0, rowEnd: 0 }, e ? e[0]?.[0] : null, S, o, f), t.onDone?.(), !0;
}
if (f?.textContent) {
const p = f.textContent.replace(/^"|"$/gi, "");
return t.onStart?.(r), t.onNoTable?.(p, o, f), t.onDone?.(), !0;
}
}
} catch (l) {
console.warn(l), n = null;
}
!n || n.length !== 0 && (n.length !== 1 || n[0] !== null && n[0].length !== 0) || (n = null);
const s = e && (e.length === 0 || e.length === 1 && (e[0] === null || e[0].length === 0));
n && s && (e = null);
const i = (l) => {
const c = /* @__PURE__ */ new Set();
let h = 1, u = 1;
for (let d = 0; d < Math.max(e ? e.length : 0, n ? n.length : 0); d++) {
let g = 0, m = 0, f = n && n[d] ? n[d].length : e[d] ? e[d].length : 0;
for (; m < f; ) {
const _ = d + "-" + g;
if (!c.has(_)) {
h = Math.max(h, g + 1), u = Math.max(u, d + 1);
let p = null;
const S = n ? n[d]?.[m]?.element : void 0;
if (S && (S.getAttribute("rowspan") || S.getAttribute("colspan"))) {
const E = parseInt(S.getAttribute("colspan")) || 1, y = parseInt(S.getAttribute("rowspan")) || 1;
h = Math.max(h, g + E), u = Math.max(u, d + y), p = { rowStart: d, colStart: g, rowEnd: d + Math.max(0, y - 1), colEnd: g + Math.max(0, E - 1) };
for (let C = d; C < d + y; C++) for (let w = g; w < g + E; w++) C === d && w === g || c.add(C + "-" + w);
} else p = { rowStart: d, colStart: g, rowEnd: d, colEnd: g };
l(p, e ? e[d]?.[g] : void 0, n ? n[d]?.[m]?.htmlValue : null, o, S || null), m++;
}
g++;
}
}
};
if (n && e) {
let l = 0, c = 0;
i((h) => {
l = Math.max(l, h.colEnd + 1), c = Math.max(c, h.rowEnd + 1);
}), e && n && (e.length !== c || e[0].length !== l) && (console.warn("mismatched mimeTypes", e, n), e = null);
}
return i(t.onCell.bind(t)), t.onDone?.(), !s || n !== null;
} catch (n) {
throw console.warn(n), n;
}
};
class oy {
constructor(e) {
if (!e) throw new Kt("snapshot is required.");
this._snapshot = e;
}
getItemType() {
return "range";
}
getItem() {
return this._snapshot;
}
editMode() {
return this._snapshot?.getMarkOptions().editMode ?? null;
}
isCut() {
return this._snapshot?.getMarkOptions().isCut ?? !1;
}
getName() {
return this._snapshot.getName();
}
toText() {
return this._snapshot.toText();
}
toHtml() {
return this._snapshot.toHtml();
}
toImage() {
return this._snapshot.toImage();
}
get isClipboardItem() {
return !0;
}
}
class sy {
constructor(e, t, n, r) {
if (this._parsed = void 0, !e) throw new Kt("nativeItems are required.");
this._native = e, this._markOptions = Object.freeze(t ?? {}), this._styles = n, this._isDate1904 = r;
}
getItemType() {
return "range";
}
isCut() {
return !1;
}
toText() {
return this._native?.text;
}
toHtml() {
return this._native?.html?.documentElement.outerHTML || null;
}
toImage() {
return this._native?.image;
}
getItem() {
const e = this._parsed;
if (e === void 0) throw new Error("Must call 'parse()' before getItem().");
if (e === null) return null;
if (this._snapshot) return this._snapshot;
const t = this;
return this._snapshot = { copyTo: (n, r) => e.copyTo(n, { ...t._markOptions, ...r }), getMarkOptions: () => t._markOptions, getName: () => e?.getName() ?? "Clipboard Data", getCoords: () => e?.getCoords?.() ?? null, toText: () => t.toText(), toHtml: () => t.toHtml(), toImage: () => t.toImage(), getSource: () => e?.getSource?.() ?? null, isISnapshot: !0 }, this._snapshot;
}
async parse() {
let e, t = this._native?.text, n = this._native.html;
if (n === null && t && t.includes("<table")) try {
const r = new DOMParser().parseFromString(t, Od.html), o = r.querySelector("parsererror");
if (o) throw new Error("Unable to parse: " + o);
n = r, t = null;
} catch {
console.warn("Discovered text as html table but could could not parse.");
}
try {
const r = new KS(this._styles, this._isDate1904, n ? "HTML" : "Text"), o = await Promise.resolve(t ? ((i, l = " ") => new Promise((c, h) => {
import("./s8drfDrkJDhCgKWX.mjs").then((u) => u.p).then((u) => {
try {
const d = u.parse(i, { delimiter: l }).data;
d.length > 1 && (d[d.length - 1].length === 0 || d[d.length - 1].length === 1 && d[d.length - 1][0].length === 0) && d.pop(), c(d);
} catch (d) {
console.warn(d), h(d);
}
}, (u) => {
h(u);
});
}))(t) : [[]]);
let s;
if (YS(n, o, r) ? (e = r.sheet(), s = e.getUsedRange()) : n = null, s) return this._parsed = { async copyTo(i, l) {
return (await i.copyFrom(s, l))?.getCoords() ?? null;
}, getCoords: () => s.getCoords(), getSource: () => e, getName: () => e.getName() }, !0;
} catch (r) {
throw r;
}
if (!t && !n && this._native.image) {
const r = this;
return this._parsed = { async copyTo(o, s) {
const i = o.getSheet(), l = await i.getMovables().addImage({ buffer: r._native.image.arrayBuffer() }, { type: "picture", description: "Copy Image from Clipboard" });
return i.getView().selectMovables([l]), null;
}, getName: () => "Image" }, !0;
}
return !1;
}
get isClipboardItem() {
return !0;
}
}
var Re;
(Re || (Re = {})).Visibility = { Visible: "visible", Hidden: "hidden", VeryHidden: "veryHidden" };
class Li extends Xi {
static {
this.instanceCounter = 0;
}
constructor(e) {
if (super(e), !e.content) throw new Error("Content type is required");
this._content = e.content, this._uuid = F.uuidV4(), this._optionsMovable = e;
const t = this;
this._optionsMovable.setContainerZIndexCallback?.(() => {
t._processZIndex();
}), this._optionsMovable.setContainerSelectionCallback?.((r, o) => {
t._processContainerSelect(r, o);
}), e.json && this._fromJSON(e.json);
const n = this._content.addListeners({ onDelete: () => {
t._options.deleteFromContainer && t._options.deleteFromContainer?.();
} }, { transactional: !0 });
this._updateState({ contentListenerRemove: n }, null, []);
}
getUUID() {
return this._uuid;
}
getContent() {
return this._content;
}
_processStateChange(e, t, n) {
super._processStateChange(e, t, n), this._getEmitter().notify("onBoundsChange"), this._getEmitter().notify("onAnyChange");
}
_processZIndex() {
this._getEmitter().notify("onAnyChange");
}
_processContainerSelect(e, t) {
this._getEmitter().notify("onSelectionChange");
}
isSelected() {
return this._optionsMovable.isSelected?.() ?? !1;
}
async scrollIntoView(e) {
return this._optionsMovable.scrollIntoView?.(e) ?? !1;
}
async select(e) {
if (await this._optionsMovable.select?.(e) === !1) return !1;
if (e?.autoFocus !== !1) {
const t = await this._getEmitter().notify("onRequestFocus", { async: !0 });
if (!t) return !1;
for (let n = 0; n < t.length; n++) if (t[n] === !1) return !1;
}
return !0;
}
unselect() {
const e = this._optionsMovable.isSelected?.() ?? !1;
return this._optionsMovable.unselect?.(), e;
}
_clone() {
const e = this.isSelected(), t = this.getZIndex(), n = this._optionsMovable.getMaxBounds, r = this._options.maxRangeCoords, o = this.getContent(), s = { beginPersistResource: this._optionsMovable.beginPersistResource, getBoundsAtCoords: this._optionsMovable.getBoundsAtCoords, getCoordsAtBounds: this._optionsMovable.getCoordsAtBounds, isSelected: () => e, getZIndex: () => t, getMaxBounds: n, maxRangeCoords: r, transactions: new Xt({ transient: !0 }), json: this.toJSON(), initialAnchor: this.getAnchorCoords(), content: o }, i = new Li(s), l = this._getState();
return i._updateState({ ...l }), i;
}
getSnapshot(e, t) {
const n = this._optionsMovable.getCoordsAtBounds(e), r = this._getState().offsets;
let o = this.getAnchorCoords();
if ((r.br.x > 0 || r.br.y > 0) && (o = { ...o }, o.colEnd -= r.br.x > 0 ? 1 : 0, o.rowEnd -= r.br.y > 0 ? 1 : 0), !D.isRangeWithinRange(o, n)) return null;
const s = this, i = s._clone(), l = Object.freeze({ ...t });
let c = !1;
return { async copyTo(u, d) {
const g = { ...l, ...d };
return await i._doCopy(u, g), g.isCut && !c && (s.delete(), c = !0), u.bounds;
}, getCoords: () => i.getBounds(), getSource: () => i, getName: () => i.getName(), getMarkOptions: () => l, toText: () => i._toText(), toHtml: () => i._toHtml(), toImage: () => i._toImage(), isISnapshot: !0 };
}
async _doCopy(e, t) {
const n = this._optionsMovable.beginPersistResource(), r = this.toJSON(n.toResourceId.bind(n));
r.content.json.name = `${this.getName()} (Copy)`;
const o = r.content.json;
delete r.content;
const s = e.movables;
if (!s) throw new Error("Movables is required");
const i = e.bounds ?? this.getBounds();
try {
await s.add({ ...r, ...t, fromResourceId: n.fromResourceId.bind(n), bounds: i, type: this.getContent().getType(), json: o, description: "Copy Movable" });
} finally {
n.endPersist();
}
}
_toText() {
return this.getContent().toText?.();
}
_toHtml() {
return this.getContent().toHtml?.();
}
_toImage() {
return this.getContent().toImage?.();
}
setName(e) {
return this._updateState({ name: e }, { description: "Set Movable Name" }, ["onNameChange"]), this;
}
getName() {
return this.isClosed() ? null : this._getState()?.name;
}
setDescription(e) {
return this._updateState({ description: e }, { description: "Set Movable Description" }), this;
}
getDescription() {
return this.isClosed() ? null : this._getState()?.description;
}
setHidden(e = !1) {
return this._updateState({ hidden: e }, { description: "Set Movable Visibility" }), this;
}
isHidden() {
return this._getState()?.hidden ?? !1;
}
setLockAspectRatio(e) {
return this._updateState({ lockAspectRatio: e }, { description: "Set Lock Aspect Ratio" }), this;
}
isLockAspectRatio() {
return this._getState()?.lockAspectRatio ?? this._optionsMovable.defaultLockAspectRatio ?? !1;
}
setRotation(e = 0) {
return this._updateState({ rotation: e }, { description: "Set Movable Rotation" }), this;
}
getRotation() {
return this._getState()?.rotation ?? 0;
}
moveToBack() {
return this._optionsMovable.moveToBackOnContainer?.(), this;
}
moveBackward() {
return this._optionsMovable.moveBackwardOnContainer?.(), this;
}
moveToFront() {
return this._optionsMovable.moveToFrontOnContainer?.(), this;
}
moveForward() {
return this._optionsMovable.moveForwardOnContainer?.(), this;
}
getZIndex() {
return this._optionsMovable.getZIndex?.() ?? 0;
}
setBounds(e, t) {
if (!e) return this;
let n = { ...this.getBounds(), ...e };
if (this._optionsMovable.getMaxBounds && (n = { x: Math.max(n.x, this._optionsMovable.getMaxBounds().x), y: Math.max(n.y, this._optionsMovable.getMaxBounds().y), width: Math.min(n.width, this._optionsMovable.getMaxBounds().width), height: Math.min(n.height, this._optionsMovable.getMaxBounds().height) }), n.width < 0 || n.height < 0) throw new ze();
const r = this._updateMovableLocation({ bounds: n, anchorType: bt.Type.Absolute }), o = this._beginCommit(t?.description ?? "Set Movable Bounds");
return this._updateState({ offsets: r.offsets, anchor: r.anchor }, { description: "Update Movable Bounds" }), this._options.setContainerCoords(r.anchor), this._invalidateBounds(), o.commit(), this;
}
_updateMovableLocation(e) {
let t = e.offsets ?? { tl: { x: 0, y: 0 }, br: { x: 0, y: 0 } }, n = e.anchor ?? this.getAnchorCoords(), r = e.anchorType ?? this.getAnchorType();
const o = e.bounds ?? this.getBounds();
if (o) {
if (r === bt.Type.Absolute) {
n = this._optionsMovable.getCoordsAtBounds(o);
const s = this._optionsMovable.getBoundsAtCoords(n);
t = { ...t, tl: { x: o.x - s.x, y: o.y - s.y } };
}
if (r === bt.Type.Absolute || r === bt.Type.OneCell) {
const s = this._optionsMovable.getBoundsAtCoords({ rowStart: n.rowStart, colStart: n.colStart, colEnd: n.colStart, rowEnd: n.rowStart }), i = this._optionsMovable.getCoordsAtBounds({ x: s.x, y: s.y, width: o.width + Math.min(s.width, t.tl.x), height: o.height + Math.min(s.height, t.tl.y) });
n = { ...n, colEnd: i.colEnd, rowEnd: i.rowEnd };
const l = this._optionsMovable.getBoundsAtCoords({ colStart: n.colEnd, rowStart: n.rowEnd, colEnd: n.colEnd, rowEnd: n.rowEnd }), c = o.width - (l.x - s.x - Math.min(t?.tl.x ?? 0, s.width)), h = o.height - (l.y - s.y - Math.min(t?.tl.y ?? 0, s.height));
t = { ...t, br: { x: c, y: h } };
}
return t !== e.offsets && (t.br.y <= 0 && (t.br = { ...t.br, y: 0 }, n.rowEnd--), t.br.x <= 0 && (t.br = { ...t.br, x: 0 }, n.colEnd--)), { anchor: n, offsets: t };
}
}
_calcAbsoluteBounds(e, t = { tl: { x: 0, y: 0 }, br: { x: 0, y: 0 } }) {
if (!e) return null;
const n = this._optionsMovable.getBoundsAtCoords({ rowStart: e.rowStart, colStart: e.colStart, colEnd: e.colStart, rowEnd: e.rowStart });
let r = t.br.x ? 0 : 1, o = t.br.y ? 0 : 1;
const s = this._optionsMovable.getBoundsAtCoords({ colStart: e.colEnd + r, rowStart: e.rowEnd + o, colEnd: e.colEnd + r, rowEnd: e.rowEnd + o }), i = Math.min(n.x + (t?.tl.x ?? 0), n.x + n.width), l = Math.min(n.y + (t?.tl.y ?? 0), n.y + n.height);
return { x: i, y: l, width: Math.min(s.x + (t?.br.x ?? 0), s.x + s.width) - i, height: Math.min(s.y + (t?.br.y ?? 0), s.y + s.height) - l };
}
getBounds() {
return this._getState()?.bounds;
}
setAnchorType(e) {
return F.validEnumValue(bt.Type, e), this._updateState({ anchorType: e }, { description: "Set Movable Resize Behavior" }, ["onAnchorTypeChange"]), this;
}
_processContainerShift(e) {
const t = this.getAnchorType(), n = this._getState()?.offsets;
let r = n, o = !1;
const s = e.before, i = e.orientation === O.Orientation.Column, l = e.intersect, c = e.amount;
let h = e.after;
if (t !== bt.Type.Absolute) {
let g = i ? l.colStart : l.rowStart, m = i ? s.colStart : s.rowStart;
t === bt.Type.TwoCell && (m = i ? s.colEnd : s.rowEnd), o = g <= m;
}
if (o && (t !== bt.Type.OneCell || h) || (h = s), o && h && c < 0 && (i ? (l.colStart <= s.colStart && l.colEnd >= s.colStart && (r = { ...r, tl: { ...r.tl, x: 0 } }), r.br.x > 0 && l.colStart <= s.colEnd && l.colEnd >= s.colEnd && (r = { ...r, br: { ...r.br, x: 0 } }, h = { ...h, colEnd: h.colEnd + 1 })) : (l.rowStart <= s.rowStart && l.rowEnd >= s.rowStart && (r = { ...r, tl: { ...r.tl, y: 0 } }), r.br.y > 0 && l.rowStart <= s.rowEnd && l.rowEnd >= s.rowEnd && (r = { ...r, br: { ...r.br, y: 0 } }, h = { ...h, rowEnd: h.rowEnd + 1 }))), h !== null) {
const { offsets: g, anchor: m } = this._updateMovableLocation({ anchor: h, offsets: r });
r = g, h = m;
}
let u = null;
const d = this._beginCommit("Shifting Movable Bounds");
try {
if (n !== r || !D.isEqualRanges(s, h)) {
const g = { offsets: r, anchor: h };
this._updateState(g);
}
this._invalidateBounds(), u = super._processContainerShift({ ...e, after: h }), d.commit();
} catch (g) {
throw d.rollback(), g;
}
return u;
}
_invalidateBounds() {
const e = this.getAnchorCoords();
if (e === null) return null;
const t = this._getState()?.offsets, n = this._calcAbsoluteBounds(e, t);
this._updateState({ bounds: n }, null, ["onBoundsChange"]);
}
_processContainerDelete() {
super._processContainerDelete(), this._getState().contentListenerRemove?.(), this.getContent().delete();
}
_processContainerLayout() {
const e = this.getAnchorCoords(), t = this._getState()?.offsets, { offsets: n, anchor: r } = this._updateMovableLocation({ anchor: e, offsets: t }), o = this._beginCommit("Updating Movable Bounds");
try {
if (t !== n || e !== r) {
const s = { offsets: n, anchor: r };
this._updateState(s);
}
this._invalidateBounds(), super._processContainerLayout(), o.commit();
} catch (s) {
throw o.rollback(), s;
}
}
_processAnchorCoords() {
super._processAnchorCoords();
}
_fromJSON(e) {
const t = { tl: { x: 0, y: 0 }, br: { x: 0, y: 0 } }, n = { ...D.EmptyRange };
e.anchor && (t.tl.x = e.anchor.tl?.x ?? 0, t.tl.y = e.anchor.tl?.y ?? 0, t.br.x = e.anchor.br?.x ?? 0, t.br.y = e.anchor.br?.y ?? 0, n.colStart = e.anchor.tl?.c ?? 0, n.rowStart = e.anchor.tl?.r ?? 0, n.colEnd = Math.max(n.colStart, (e.anchor.br?.c ?? 0) + (t.br.x > 0 ? 0 : -1)), n.rowEnd = Math.max(n.rowStart, (e.anchor.br?.r ?? 0) + (t.br.y > 0 ? 0 : -1)));
const r = this._beginCommit("Load Movable"), o = e.content.json, s = { offsets: t, name: o.name ?? null, description: o.name ?? null, hidden: o.hidden ?? !1, rotation: o.rotation ?? 0, lockAspectRatio: o.lockAspect ?? null };
e.anchorType && (s.anchorType = e.anchorType), s.name || (s.name = `${this._content.getTypeDescription()} ${++Li.instanceCounter}`), s.bounds = this._calcAbsoluteBounds(n, t), this._updateState(s, { description: "Load Movable" }), this._optionsMovable.setContainerCoords?.(n), r.commit();
}
toJSON(e) {
const t = this._getState(), n = t.anchor, r = t.offsets, o = { tl: { c: n.colStart, r: n.rowStart }, br: { c: n.colEnd + (r.br.x ? 0 : 1), r: n.rowEnd + (r.br.y ? 0 : 1) } };
r && (r.tl?.x && (o.tl.x = F.roundAccurately(r.tl.x, 1)), r.tl?.y && (o.tl.y = F.roundAccurately(r.tl.y, 1)), r.br?.x && (o.br.x = F.roundAccurately(r.br.x, 1)), r.br?.y && (o.br.y = F.roundAccurately(r.br.y, 1)));
const s = this._content.toJSON(e) ?? {}, i = { anchor: o, content: { type: this._content.getType(), json: s } }, l = t.anchorType;
return l && l !== bt.Type.TwoCell && (i.anchorType = this.getAnchorType()), t.hidden && (i.hidden = t.hidden), t.name && (i.name = t.name), t.description && (i.name = t.description), t.rotation !== void 0 && t.rotation !== 0 && (i.rotation = t.rotation), F.isDefined(t.lockAspectRatio) && t.lockAspectRatio !== this._optionsMovable.defaultLockAspectRatio && (i.lockAspect = t.lockAspectRatio), i;
}
get isIMovable() {
return !0;
}
}
class QS {
constructor(e, t, n, r, o, s) {
this._add = e, this._getItems = t, this._getCount = n, this._updateSelected = r, this._addListeners = o, this._addImage = s;
}
async add(e) {
return this._add(e);
}
getItems(e) {
return this._getItems(e);
}
getCount() {
return this._getCount();
}
updateSelected(e, t) {
return this._updateSelected(e, t);
}
addListeners(e, t) {
return this._addListeners(e, t);
}
addImage(e, t) {
return this._addImage(e, t);
}
}
const rl = { transactional: !0, ignoreDataChanges: !0 };
class ad extends Fg {
constructor(e) {
super({ ...e, type: "namedReference" });
const t = this;
this._listener = (r) => {
const o = this._getState().ranges;
let s = r.getSource(), i = !1;
const l = { ranges: s };
if (r.trigger === "moveCells") {
const u = t._getState(), d = r.getTo(), g = r.getFrom(), m = [];
for (let p = 0; p < o.getCount(); p++) {
const S = o.at(p);
if (m.push(S.getCoords()), !S.isInvalid()) {
for (let E = 0; E < g.getCount(); E++) {
const y = g.at(E).getCoords(), C = S.getCoords();
if (!D.isRangeWithinRange(C, y)) continue;
const w = d.getCoords(), b = w.colStart - y.colStart + C.colStart, x = w.rowStart - y.rowStart + C.rowStart, I = { ...C, colStart: b, rowStart: x, colEnd: b + (C.colEnd - C.colStart), rowEnd: x + (C.rowEnd - C.rowStart) };
(d.size !== 1 || D.isRangeWithinRange(I, w)) && (m[p] = d.getSource().getRange(I).getCoords(), i = !0);
}
if (!i) return;
}
}
const f = this._options.addressToRanges(m);
let _;
u.removeListener?.(), f.isInvalid() || (_ = f.addListener(t._listener, rl)), l.ranges = f, l.removeListener = _;
}
this._updateState(l, null, ["onRangesChange"]);
const c = s.getCoords();
let h = !c || c.length === 0;
for (let u = 0; !h && u < c.length; u++) if (!c[u]) {
h = !0;
break;
}
h && t.delete();
};
const n = e.value;
if (n && !n.isInvalid()) {
const r = n.addListener(this._listener, rl);
this._updateState({ ranges: n, removeListener: r }, null);
}
}
setReference(e) {
const t = this._options.addressToRanges(e);
if (t && !t.isInvalid()) {
this._getState().removeListener?.();
const r = t.addListener(this._listener, rl);
this._updateState({ ranges: t, removeListener: r }, null);
}
return null;
}
async select(e) {
return await this._getState().ranges.select(e), this;
}
getRanges() {
return this._getState().ranges;
}
setHidden(e = !1, t) {
return this._updateState({ hidden: e }, { description: "Set Hidden", ...t }, []), this;
}
setScope(e, t) {
return this._updateState({ scope: e }, { description: "Set Scope", ...t }, []), this;
}
getType() {
return "reference";
}
getValue() {
return this._getState().ranges;
}
toJSON() {
const e = super._toJSON();
return e.ref = this._getState().ranges.toString(), e;
}
_getDescription() {
return `Named '${this.getName()}'`;
}
_processDelete() {
const e = this._getState();
e && e.removeListener?.(), super._processDelete();
}
}
const ld = "Item must be specified.", cd = "Name must be a non-empty string", hd = (a, e = null) => `Named item '${a}' already exists${e ? `in scope ${e}` : ""}.`, ud = (a) => {
const e = [];
for (let t = 0; t < a.getCount(); t++) {
let n = null;
try {
n = a.at(t), n.isICellRange && (n = n.getFixed(!0));
} catch (r) {
console.warn("Invalid range", r);
}
e.push(n ? n.toString().toLowerCase() : rt);
}
return e.sort(), e.join(",");
}, ZS = /^[^a-zA-Z_\\]+$/, ew = /^[^a-zA-Z0-9_.]+$/;
class Cm {
constructor(e) {
this._emitter = null, this._closed = !1, this._lastLookup = F.EmptyArray, this._lastLookupAddress = null, this._lastLookupScope = null, this._lastLookupType = null, this._allowExtrudes = !1, this._options = { ...e };
const t = this;
this._transactions = this._options.transactions ?? new Xt({ transient: !0 }), this._transactionsRemoveListener = this._transactions.addStateListener(this, { onAfterStateChange(n, r, o) {
r?.initial || t._emitter.notify("onCollectionChange");
} }), this._emitter = new mt(this, this._transactions), this._initState(), this._fromJSON(this._options?.json);
}
getItems(e) {
if (this.isClosed()) return F.EmptyArray;
const t = this._getState();
if (!t) return F.EmptyArray;
const n = t.itemsSpatial;
if (n.isEmpty()) return F.EmptyArray;
if (e && e.address === this._lastLookupAddress && e.scope === this._lastLookupScope && e.type === this._lastLookupType && e.allowExtrudes === this._allowExtrudes) return this._lastLookup;
this._lastLookupAddress = e?.address ?? void 0, this._lastLookupScope = e?.scope ?? void 0, this._lastLookupType = e?.type ?? void 0, this._allowExtrudes = e?.allowExtrudes ?? void 0;
let r = null;
if (e?.address) {
const h = this._options.addressToRanges(e?.address);
if (!h) return console.debug("invalid address", e?.address), this._lastLookup = null, null;
r = h.getCoords();
}
let o = null;
if (r) {
o = [];
for (let h = 0; h < r.length; h++) {
const u = n.search(r[h]), d = u.length;
for (let g = 0; g < d; g++) o.push(u[g]);
}
} else o = n.all();
if (!o || o.length === 0) return this._lastLookup = F.EmptyArray, F.EmptyArray;
const s = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
o.forEach((h) => {
const u = h.value;
if (!e?.type || u.getType() === e.type) {
if (r && !e?.allowExtrudes) {
const d = u.getRanges?.();
if (!d || d.getCount() === 0) return;
for (let g = 0; g < r.length; g++) if (!D.isRangeWithinRange(h, r[g])) return;
}
!e?.scope || u.getScope() !== e.scope && e.scope !== "all" ? u.getScope() || i.add(u) : s.add(u);
}
});
const l = /* @__PURE__ */ new Map();
i.forEach((h) => {
l.set(h.getName(), h);
}), s.forEach((h) => {
l.set(h.getName(), h);
});
let c = [];
return l.forEach((h) => {
c.push(h);
}), c = c.sort((h, u) => {
let d = h.getType().localeCompare(u.getType());
return d !== 0 ? d : h.getName().localeCompare(u.getName());
}), this._lastLookup = c, c;
}
lookupByRanges(e) {
const t = this._options.addressToRanges(e);
if (!t || t.getCount() === 0) return null;
const n = this._getState();
if (!n || n.itemsByKey.size === 0) return null;
const r = ud(t), o = n.itemsByFullRange.get(r);
if (!o) return null;
const s = [];
return o.forEach((i) => {
const l = n.itemsByKey.get(i);
l && s.push(l.item);
}), s.length > 0 ? s : null;
}
getByName(e, t = !1) {
if (!e) return null;
const n = this._getState();
if (!n || n.itemsByKey.size === 0 || typeof e != "string") return null;
const r = e.toLowerCase(), o = this._options.getCurrentScope();
if (!t && o) {
const i = r + ":" + o.toLowerCase(), l = n.itemsByKey.get(i);
if (l) return l.item;
}
return n.itemsByKey.get(r)?.item ?? null;
}
getCount() {
const e = this._getState();
return e ? e.itemsByKey.size : 0;
}
getRanges(e) {
const t = this._options.addressToRanges(e), n = [];
for (let r = 0; r < t.getCount(); r++) {
const o = t.at(r).getFixed(!0).getCoords();
n.push(o);
}
return this._options.addressToRanges(n);
}
findValidName(e, t = null, n = !1) {
if (!e) throw new Error("A template string must be specified.");
const r = this, o = (s) => {
try {
return r._validateName(s, t, n), !0;
} catch {
}
return !1;
};
return o(e) ? e : lg(e, o);
}
validateName(e, t = null, n = !1) {
return this._validateName(e, t, n);
}
_validateName(e, t, n = !1) {
if (this._closed) throw new Error(Ht);
if (!e || e.length === 0) throw new Error(cd);
if (e.length > 255) throw new Error("Name must not exceed 255 characters.");
if (e.indexOf(" ") !== -1) throw new Error("Name must not contain any spaces.");
const r = e.trim().toLowerCase(), o = r.substring(1, e.length - 1);
if (new RegExp(ZS).test(r[0])) throw new Error("First letter must be either a letter, an underscore, or a backslash.");
if (new RegExp(ew).test(o)) throw new Error("Name must be either letters, numbers, periods or underscores.");
if (r.length === 1 && (r[0] === "r" || r[0] === "c")) throw new Error("Name can not be 'r' or 'c'.");
if (((l, c = T0, h = $g, u = !1) => {
let d = Kg(l, u);
if (!d || d[2] || !d[1]) return !1;
const g = kl(l, Ol);
if (!g) return !1;
const m = g.rowIndex;
if (m < 0 || m > c) return !1;
const f = g.colIndex;
return !(f < 0 || f >= h);
})(e)) throw new Error("Name can not be an address.");
let s = e.toLowerCase()?.trim();
t && (s = s + ":" + t.toLowerCase());
const i = this._getState()?.itemsByKey.get(s);
if (i) {
const l = i.item.getRanges();
if (!n || l || l.getCount() > 0) throw new Error(hd(e, t));
}
}
addReference(e, t, n = !1) {
const r = this._options.addressToRanges(t), o = this.getByName(e);
let s = null;
const i = this._beginCommit(`${o && n ? "Update" : "Insert"} Named '${e}'`);
try {
if (o) {
if (!n) throw new Error(hd(e));
this._delete(o, { description: `Delete Named '${o.getName()}'` });
}
s = new ad({ value: r, addressToRanges: this._options.addressToRanges, json: { name: e, ref: r.toString() }, transactions: this._transactions }), this.add(s), i.commit();
} catch (l) {
throw i.rollback(), l;
}
return s;
}
add(e) {
if (this._closed) throw new Error(Ht);
if (!e) throw new Error(ld);
if (!e.getName || typeof e == "string") throw new Error("Add must take a 'INamed' object. To add a string use 'addReference'.");
if (this._validateName(e.getName(), e.getScope(), !1), this._options.isReadOnly?.()) throw new Error("Names are read-only.");
const t = this._beginCommit(`Insert Named Item '${e.getName()}'`), n = this._add([e]);
if (n === null) return t.rollback(), null;
const r = n.itemsByKey.get(e.getName().toLowerCase());
return this._updateState((o) => ({ ...o, ...n })), t.commit(), r?.item ?? null;
}
_toKey(e) {
let t = e.getName().toLowerCase();
return t.startsWith("_xlnm.") && (t = t.substring(6)), e.getScope() ? t + ":" + e.getScope().toLowerCase() : t;
}
_delete(e, t) {
if (!e) throw new Error(ld);
if (this._closed) throw new Error(Ht);
const n = this._beginCommit(t?.description ?? `Delete Named Item '${e.getName()}'`);
let r = null;
try {
const o = this._getState()?.itemsByKey, s = this._toKey(e);
if (r = o.get(s), !r) throw new Error(`Item '${e.getName()}' does not exist.`);
const i = this._cloneState();
this._index(s, null, i), this._updateState((l) => ({ ...l, ...i })), n.commit();
} catch (o) {
throw n.rollback(), o;
}
return this._emitter.notify("onCollectionChange"), r.item;
}
_cloneState() {
const e = this._getState();
return { itemsBySource: new Map(e.itemsBySource), itemsByKey: new Map(e.itemsByKey), itemsSpatial: e.itemsSpatial.clone(), itemsByFullRange: new Map(e.itemsByFullRange), itemsByPartialRange: new Map(e.itemsByPartialRange) };
}
_index(e, t, n) {
const r = n.itemsByKey.get(e);
if (r) {
const s = r.asPartialRanges;
if (s) for (let l = 0; l < s.length; l++) {
const c = n.itemsByPartialRange.get(s[l]);
if (c) if (c.size === 1) n.itemsByPartialRange.delete(s[l]);
else {
const h = new Set(c);
h.delete(e), n.itemsByPartialRange.set(s[l], h);
}
}
const i = r.asFullRange;
if (i) {
const l = n.itemsByFullRange.get(i);
if (l) if (l.size === 1) n.itemsByFullRange.delete(i);
else {
const c = new Set(l);
c.delete(e), n.itemsByFullRange.set(i, c);
}
}
if (r.nodes) for (let l = 0; l < r.nodes.length; l++) n.itemsSpatial.remove(r.nodes[l]);
r.unwatch?.(), n.itemsByKey.delete(e), n.itemsBySource.delete(r.item);
}
let o = null;
if (t) {
let s = [], i = null, l = null;
o = t.getRanges?.();
const c = this._toKey(t);
if (o) {
const { asFullRange: g, asPartialRanges: m, asRanges: f } = ((_) => {
const p = _.getCoords(), S = ud(_), E = S.split(",");
return { asFullRange: S, asPartialRanges: E, asRanges: p };
})(o);
if (i = g, l = m, f) {
for (let _ = 0; _ < m.length; _++) {
let p = n.itemsByPartialRange.get(m[_]);
const S = p ? new Set(p) : /* @__PURE__ */ new Set();
S.add(c), n.itemsByPartialRange.set(m[_], S), s.push({ ...f[_], value: t });
}
if (n.itemsSpatial.load(s), g) {
let _ = n.itemsByFullRange.get(g);
const p = _ ? new Set(_) : /* @__PURE__ */ new Set();
p.add(c), n.itemsByFullRange.set(g, p);
}
}
}
const h = this, u = t.addListeners({ onDelete: (g) => {
h._delete(g);
}, onAnyChange: (g) => {
const m = h._beginCommit(`Update Named '${g.getName()}'`);
try {
const f = h._cloneState(), _ = f.itemsBySource.get(g).globalKey;
h._index(_, g, f), h._updateState((p) => ({ ...p, ...f })), m.commit();
} catch (f) {
throw m.rollback(), f;
}
} }, { transactional: !0 }), d = { item: t, asFullRange: i, asPartialRanges: l, unwatch: u, nodes: s, globalKey: c };
n.itemsByKey.set(c, d), n.itemsBySource.set(t, d);
}
}
_add(e) {
if (this._closed) throw new Error(Ht);
const t = this._getState();
if (!e) return t;
const n = this._cloneState(), r = e.length;
for (let o = 0; o < r; o++) {
const s = e[o];
if (!s.getName()) throw new Error(cd);
const i = this._toKey(s);
try {
this._index(i, s, n);
} catch (l) {
console.debug(`Unable to add named item '${i}'.`, l);
}
}
return n;
}
beginCommit(e) {
return this._beginCommit(e);
}
_getState() {
if (this._closed) throw new Error(Ht);
return this._transactions.getState(this);
}
_beginCommit(e) {
return this._transactions.beginCommit(typeof e == "string" ? { description: e } : e);
}
_updateState(e, t = "Update") {
if (!e) return;
this._lastLookup = F.EmptyArray, this._lastLookupAddress = null, this._lastLookupType = null, this._lastLookupScope = null;
const n = this._beginCommit(t);
try {
n.updateState(this, e), n.commit();
} catch (r) {
throw n.rollback(), r;
}
}
fromJSON(e) {
if (this._closed) throw new Error(Ht);
this._fromJSON(e);
}
_initState() {
this._updateState((e) => ({ ...e, items: /* @__PURE__ */ new Set(), itemsByKey: /* @__PURE__ */ new Map(), itemsSpatial: new Ne(), itemsByFullRange: /* @__PURE__ */ new Map(), itemsByPartialRange: /* @__PURE__ */ new Map() }));
}
_fromJSON(e) {
const t = this._beginCommit("Load Names");
try {
if (e) {
const n = [], r = e.length;
for (let s = 0; s < r; s++) {
const i = e[s];
try {
const l = this._options.addressToRanges(i.ref), c = new ad({ value: l, addressToRanges: this._options.addressToRanges, deleteFromContainer: (h) => {
this._delete(c, h);
}, json: i, transactions: this._transactions });
n.push(c);
} catch (l) {
console.debug("Unable to load named item.", i, l.message);
}
}
const o = this._add(n);
this._updateState((s) => ({ ...s, ...o }));
}
t.commit({ viewAfter: { initial: !0 } });
} catch (n) {
throw t.rollback(), n;
}
}
toJSON() {
const e = this._getState();
if (!e || e.itemsByKey.size === 0) return null;
const t = [], n = Array.from(e.itemsByKey.keys()).sort(), r = n.length;
for (let o = 0; o < r; o++) {
const s = e.itemsByKey.get(n[o]).item, i = s.toJSON?.();
i && t.push(i);
}
return t.length === 0 ? null : t;
}
addListeners(e, t) {
return this._emitter.addListeners(e, t);
}
isClosed() {
return this._closed;
}
close() {
this._closed || (this._emitter.notify("onClose"), this._closed = !0, this._transactionsRemoveListener?.());
}
get isNamedCollection() {
return !0;
}
}
class tw extends mr {
constructor(e) {
super(e), e.json && this._updateState({ data: e.json });
}
getType() {
return "chart";
}
getDescription() {
return `Chart: ${this._getState()?.data?.types?.[0]?.type ?? "unknown"}`;
}
toJSON(e) {
const t = this._getState();
let n = null;
return t && t.data && (n = t.data), n;
}
getTypeDescription() {
return "Chart";
}
}
class nw extends mr {
constructor(e) {
super(e), e.json && this._updateState({ data: e.json });
}
getType() {
return "shape";
}
getDescription() {
return `Shape: ${this._getState()?.data}`;
}
toJSON(e) {
const t = this._getState();
let n = null;
return t && t.data && (n = t.data), n;
}
getTypeDescription() {
return "Shape";
}
}
class rw extends mr {
constructor(e) {
super(e), e.json && this._updateState({ data: e.json });
}
getType() {
return "custom";
}
getDescription() {
return `CustomElement: ${this._getState()?.data}`;
}
toJSON(e) {
const t = this._getState();
let n = null;
return t && t.data && (n = t.data), n;
}
getTypeDescription() {
return "CustomElement";
}
}
const dd = (a, e, t = !0, n = !0) => {
let r = 0, o = 0;
if (!t && !n) return { x: r, y: o };
let s = !1, i = 0;
do {
const l = { x: e.x + r, y: e.y + o, width: 0, height: 0 }, c = a.getItems({ bounds: l });
if (s = !1, c.length > 0) {
for (let h = 0; !s && h < c.length; h++) {
const u = c[h].getBounds();
u.x === l.x && u.y === l.y && (s = !0);
}
s && (r += t ? 16 : 0, o += n ? 16 : 0);
}
} while (s && ++i < 100);
return { x: r, y: o };
};
class ow {
constructor(e, t, n) {
this._add = e, this._get = t, this._getByName = n;
}
add(e, t) {
if (!e) throw new Error(Hl);
return this._add(e, t);
}
getItems(e) {
if (e && e.name && Object.keys(e).length === 0) return [this._getByName(e.name)];
let t;
e?.address && (t = e.address);
const n = this._get(t, e?.excludeHidden, e?.fullyContained);
if (e?.name) {
const r = e.name.toLocaleLowerCase();
for (let o = 0; o < n.length; o++) if (n[o].getName().toLocaleLowerCase() === r) return [n[o]];
}
return n;
}
getByName(e) {
if (typeof e != "string") throw new Error("Get by name must take a valid name.");
return this._getByName(e);
}
getCount() {
return this._get(null, !1, !1).length;
}
}
const St = (a, e, t) => {
if (!a) return e;
let n = e;
const r = t === O.Direction.Right || t === O.Direction.Down;
for (; ; ) {
const o = a(n, !r);
if (o === 0) return n;
r ? n += o : n -= o;
}
}, sw = Object.freeze({ colIndex: 0, rowIndex: 0 }), $l = Object.freeze([]), ol = Object.freeze({ cell: D.EmptyCell, ranges: $l, rangeIndex: -1 }), bm = (a, e = O.Direction.Right, t, n, r, o = null) => {
if (o && D.isEqualSelectionCoords(o, a)) return a;
const s = a.ranges[a.rangeIndex];
if (!D.isRangesIntersect({ rowStart: a.cell.rowIndex, colStart: a.cell.colIndex, rowEnd: a.cell.rowIndex, colEnd: a.cell.colIndex }, s)) return a;
let i = { ...a.cell }, l = a.rangeIndex;
switch (e) {
case O.Direction.Right:
i.colIndex = St(r, i.colIndex + 1, e);
break;
case O.Direction.Left:
i.colIndex = St(r, i.colIndex - 1, e);
break;
case O.Direction.Down:
i.rowIndex = St(n, i.rowIndex + 1, e);
break;
case O.Direction.Up:
i.rowIndex = St(n, i.rowIndex - 1, e);
}
const c = (d) => {
if (d) {
l = a.rangeIndex >= a.ranges.length - 1 ? 0 : a.rangeIndex + 1;
const g = a.ranges[l];
i = { colIndex: g.colStart, rowIndex: g.rowStart };
} else {
l = a.rangeIndex <= 0 ? a.ranges.length - 1 : a.rangeIndex - 1;
const g = a.ranges[l];
i = { colIndex: g.colEnd, rowIndex: g.rowEnd };
}
};
if (e === O.Direction.Right && i.colIndex > s.colEnd && i.rowIndex === s.rowEnd) c(!0);
else if (e === O.Direction.Left && i.colIndex < s.colStart && i.rowIndex === s.rowStart) c(!1);
else if (e === O.Direction.Down && i.colIndex === s.colEnd && i.rowIndex > s.rowEnd) c(!0);
else if (e === O.Direction.Up && i.colIndex === s.colStart && i.rowIndex < s.rowStart) c(!1);
else {
let d = i.rowIndex, g = i.colIndex;
switch (e) {
case O.Direction.Right:
g > s.colEnd && (d = St(n, d + 1, e), g = s.colStart, d > s.rowEnd && (d = s.rowStart));
break;
case O.Direction.Left:
g < s.colStart && (d = St(n, d - 1, e), g = s.colEnd, d < s.rowStart && (d = s.rowEnd));
break;
case O.Direction.Down:
d > s.rowEnd && (g = St(r, g + 1, e), d = s.rowStart, g > s.colEnd && (g = s.colStart));
break;
case O.Direction.Up:
d < s.rowStart && (g = St(r, g - 1, e), d = s.rowEnd, g < s.colStart && (g = s.colEnd));
}
i = { rowIndex: d, colIndex: g };
}
let h = t(i);
if (!D.isRangeWithinRange(h, s)) {
const d = D.intersectRanges(h, s);
d && (h = d);
}
let u = { rowStart: St(n, h.rowStart, O.Direction.Down), colStart: St(r, h.colStart, O.Direction.Right), rowEnd: St(n, h.rowEnd, O.Direction.Up), colEnd: St(r, h.colEnd, O.Direction.Left) };
if (u.rowStart !== i.rowIndex || u.colStart !== i.colIndex) {
switch (e) {
case O.Direction.Right:
a.ranges[l].colStart === u.colStart && a.ranges[l].colEnd === u.colEnd && (i.rowIndex = u.rowEnd), i.colIndex = u.colEnd;
break;
case O.Direction.Left:
a.ranges[l].colStart === u.colStart && a.ranges[l].colEnd === u.colEnd && (i.rowIndex = u.rowStart), i.rowIndex === u.rowStart ? i.colIndex = u.colStart + 1 : i.colIndex = u.colStart;
break;
case O.Direction.Down:
a.ranges[l].rowStart === u.rowStart && a.ranges[l].rowEnd === u.rowEnd && (i.colIndex = u.colEnd), i.rowIndex = u.rowEnd;
break;
case O.Direction.Up:
a.ranges[l].rowStart === u.rowStart && a.ranges[l].rowEnd === u.rowEnd && (i.colIndex = u.colStart), i.colIndex === u.colStart ? i.rowIndex = u.rowStart + 1 : i.rowIndex = u.rowStart;
}
return o && console.warn("call recursive > 1"), bm({ cell: i, ranges: a.ranges, rangeIndex: l }, e, t, n, r, o ?? a);
}
return { ranges: a.ranges, cell: i, rangeIndex: l };
};
class iw {
constructor(e) {
this._adjusting = null, this._emitter = null, this._coords = ol, this._sheet = e.sheet, this._emitter = new mt(this);
const t = e.sheet;
this._adjusting = null, this._hiddenRowsAt = (n, r) => t.getRowHeaders().hiddenHeadersAt(n, r), this._hiddenColumnsAt = (n, r) => t.getColumnHeaders().hiddenHeadersAt(n, r), this._getCellCoordsAsRangeCoords = (n) => {
const r = D.cellToRange(n);
if (t.isClosed()) return r;
const o = t.getRange(r, { excludeHidden: !0 }).getMerges();
return o.length === 0 ? r : o[0];
}, this._canSelectionSpanMergedCells = (n) => {
const r = t.getRange(n);
return r.isEntireColumns() || r.isEntireRows();
}, this._getMergedRanges = (n) => t.getRange(n, { excludeHidden: !0 }).getMerges(), this._isContentfulCell = () => !1, this._contentfulCellFinder = (n, r, o, s, i, l) => {
const c = t.getSelectedRange().getExtended(s, n).getCoords();
switch (s) {
case O.Direction.Up:
return c.rowStart;
case O.Direction.Down:
return c.rowEnd;
case O.Direction.Left:
return c.colStart;
case O.Direction.Right:
return c.colEnd;
}
}, this._scrollCellCoordsIntoView = (n, r) => t.scrollTo(n, r ? { scroll: r } : void 0), this._selectionPolicy = e.selectionPolicy ?? "multiple", this._newSelectionMode = e.newSelectionMode ?? "clear";
}
navigate(e, t = !1, n = !1, r = 0) {
const o = this._coords;
if (!o.cell) return this;
let s = o.cell, i = o.cell;
if (t && o.ranges.length > 0) {
const S = o.ranges[o.rangeIndex], E = o.cell;
switch (e) {
case O.Direction.Up:
i = { rowIndex: E.rowIndex === S.rowStart ? S.rowEnd : S.rowStart, colIndex: S.colEnd }, s = { rowIndex: E.rowIndex === S.rowStart ? S.rowStart : S.rowEnd, colIndex: S.colStart };
break;
case O.Direction.Down:
i = { rowIndex: E.rowIndex === S.rowEnd ? S.rowStart : S.rowEnd, colIndex: S.colEnd }, s = { rowIndex: E.rowIndex === S.rowEnd ? S.rowEnd : S.rowStart, colIndex: S.colStart };
break;
case O.Direction.Left:
i = { rowIndex: S.rowEnd, colIndex: E.colIndex === S.colStart ? S.colEnd : S.colStart }, s = { rowIndex: S.rowStart, colIndex: E.colIndex === S.colStart ? S.colStart : S.colEnd };
break;
case O.Direction.Right:
i = { rowIndex: S.rowEnd, colIndex: E.colIndex === S.colEnd ? S.colStart : S.colEnd }, s = { rowIndex: S.rowStart, colIndex: E.colIndex === S.colEnd ? S.colEnd : S.colStart };
}
}
const l = this._getCellCoordsAsRangeCoords(i);
let { rowStart: c, colStart: h } = l;
const u = this._magicCell;
if (u) switch (e) {
case O.Direction.Up:
case O.Direction.Down:
u.colIndex >= l.colStart && u.colIndex <= l.colEnd && (h = u.colIndex);
break;
case O.Direction.Left:
case O.Direction.Right:
u.rowIndex >= l.rowStart && u.rowIndex <= l.rowEnd && (c = u.rowIndex);
}
if (!r) {
const S = this._getMaxRange();
switch (e) {
case O.Direction.Up:
c = St(this._hiddenRowsAt, Math.max(l.rowStart - 1, S.rowStart ?? 0), e);
break;
case O.Direction.Down:
c = St(this._hiddenRowsAt, Math.min(l.rowEnd + 1, S.rowEnd ?? Number.MAX_SAFE_INTEGER), e);
break;
case O.Direction.Left:
h = St(this._hiddenColumnsAt, Math.max(l.colStart - 1, S.colStart ?? 0), e);
break;
case O.Direction.Right:
h = St(this._hiddenColumnsAt, Math.min(l.colEnd + 1, S.colEnd ?? Number.MAX_SAFE_INTEGER), e);
}
if (n) {
const E = this._getMaxRange();
let y = 0;
switch (e) {
case O.Direction.Up:
y = E.rowStart ?? 0, c = this._contentfulCellFinder({ ...i, colIndex: this._coords.cell.colIndex }, this._isContentfulCell, this._hiddenRowsAt, e, !1, Math.max(y, this._hiddenRowsAt(y, !1)));
break;
case O.Direction.Down:
y = E.rowEnd ?? Number.MAX_SAFE_INTEGER, c = this._contentfulCellFinder({ ...i, colIndex: this._coords.cell.colIndex }, this._isContentfulCell, this._hiddenRowsAt, e, !1, Math.min(y, y - this._hiddenRowsAt(y, !0)));
break;
case O.Direction.Left:
y = E.colStart ?? 0, h = this._contentfulCellFinder({ ...i, rowIndex: this._coords.cell.rowIndex }, this._isContentfulCell, this._hiddenColumnsAt, e, !1, Math.max(y, this._hiddenColumnsAt(y, !1)));
break;
case O.Direction.Right:
y = E.colEnd ?? Number.MAX_SAFE_INTEGER, h = this._contentfulCellFinder({ ...i, rowIndex: this._coords.cell.rowIndex }, this._isContentfulCell, this._hiddenColumnsAt, e, !1, Math.min(y, y - this._hiddenColumnsAt(y, !0)));
}
}
}
let d = null;
r && (d = {});
const g = { rowIndex: c, colIndex: h }, m = this._getCellCoordsAsRangeCoords(g), f = { rowIndex: m.rowStart, colIndex: m.colStart };
t || (this._magicCell = g);
const _ = this._firstActiveCoords, p = D.isEqualCells(_, f) && D.isEqualCells(_, s);
if (t && !p ? this.modify(f, s) : this.clearAndModify(f), d) this._scrollCellCoordsIntoView(d);
else {
if (t && _) {
const S = this._getMaxRange();
if (e === O.Direction.Right && _.colIndex === S.colEnd || e === O.Direction.Left && _.colIndex === S.colStart || e === O.Direction.Up && _.rowIndex === S.rowEnd || e === O.Direction.Down && _.rowIndex === S.rowStart) return this;
}
e === O.Direction.Left || e === O.Direction.Right ? this._scrollCellCoordsIntoView({ colStart: g.colIndex }) : e !== O.Direction.Up && e !== O.Direction.Down || this._scrollCellCoordsIntoView({ rowStart: g.rowIndex });
}
return this;
}
getCoords() {
return this._coords;
}
updateCoords(e) {
const t = this._coords;
if (D.isEqualSelectionCoords(t, e)) return;
const n = ((r, o, s) => {
if (!r) return ol;
let i = o.cell;
D.isEqualCells(i, r?.cell) || (i = Object.freeze({ colIndex: Math.max(0, Math.min(r?.cell?.colIndex ?? o.cell?.colIndex ?? 0)), rowIndex: Math.max(0, Math.min(r?.cell?.rowIndex ?? o?.cell?.rowIndex ?? 0)) }));
const l = r?.ranges ? [...r.ranges] : [];
let c = !1;
const h = l.length;
let u = h === 0;
for (let f = 0; f < h; f++) {
const _ = l[f];
l[f] = Object.freeze({ colStart: Math.max(s.colStart, Math.min(_.colStart, s.colEnd)), colEnd: Math.max(s.colStart, Math.min(_.colEnd, s.colEnd)), rowStart: Math.max(s.rowStart, Math.min(_.rowStart, s.rowEnd)), rowEnd: Math.max(s.rowStart, Math.min(_.rowEnd, s.rowEnd)) }), u = u || D.isCellWithinRange(i, _), c = c || Object.keys(_).length > 4;
}
let d = o?.ranges ?? [];
!c && D.isEqualRangesArrays(d, l) || (d = l);
let g = r?.rangeIndex ?? o?.rangeIndex ?? ol.rangeIndex;
if (g = Math.max(-1, Math.min(g, d.length - 1)), !u) {
const f = d[g];
let _ = i.rowIndex;
_ < f.rowStart ? _ = f.rowStart : _ > f.rowEnd && (_ = f.rowEnd);
let p = i.rowIndex;
p < f.colStart ? p = f.colStart : p > f.colEnd && (p = f.colEnd), i = Object.freeze({ colIndex: p, rowIndex: _ });
}
return Object.freeze({ cell: i, ranges: d, rangeIndex: g });
})(e, this._coords, this._getMaxRange());
return this._coords = n, !D.isEqualCells(n.cell, t.cell) && this._scrollCellCoordsIntoView({ colStart: n.cell.colIndex, rowStart: n.cell.rowIndex }), this._emitter.notify("onChange"), this;
}
isEntire() {
const e = this._coords;
if (e.ranges.length === 0) return !1;
const t = this._getMaxRange();
for (let n = 0; n < e.ranges.length; n++) {
const r = e.ranges[n];
if (!D.isRangeWithinRange(t, r)) return !1;
}
return !0;
}
traverse(e = O.Orientation.Row, t = !1) {
let n = O.Direction.Right;
n = e === O.Orientation.Row ? t ? O.Direction.Left : O.Direction.Right : t ? O.Direction.Up : O.Direction.Down;
const r = this._coords;
if (r.ranges.length === 0) return this.navigate(n);
const o = this._getCellCoordsAsRangeCoords(r.cell);
if (D.isEqualRangesArrays([o], r.ranges)) return this.navigate(n);
const s = bm(r, n, this._getCellCoordsAsRangeCoords.bind(this), this._hiddenRowsAt.bind(this), this._hiddenColumnsAt.bind(this));
this.updateCoords(s);
}
clear() {
this._setSelectionRanges($l);
}
modify(e, t, n) {
if (this._selectionPolicy === "single") return;
const r = this._coords, o = this._rangesFromCellOptional(r, e, t ?? r.cell);
if (!o) return;
const s = r.rangeIndex;
this._setSelectionRanges((i) => i.length ? i.map((l, c) => s === c ? o : l) : [o]), n && o && this._setSelectionCell({ colIndex: o.colStart, rowIndex: o.rowStart });
}
append(e, t = e, n) {
if (this._selectionPolicy !== "multiple" || !e || this._isCellOutOfBounds(e) || this._isCellOutOfBounds(t)) return;
const r = this._coords, o = this._cellToRangeActual(e, t);
if (!o) return;
const s = r.ranges.length > 0 ? [...r.ranges] : [this._cellToRangeActual(r.cell, r.cell)];
s.push(o);
const i = { ranges: s, cell: { rowIndex: o.rowStart, colIndex: o.colStart, ...n }, rangeIndex: s.length - 1 };
D.isEqualSelectionCoords(i, r) || this.updateCoords(i);
}
clearAndModify(e, t, n) {
const r = this._coords;
e = { ...r.cell, ...e }, t = t ?? e;
const o = this._rangesFromCellOptional(r, e, t);
if (!o) return;
const s = { rowIndex: o.rowStart, colIndex: o.colStart }, i = { ...s, ...n }, l = this._newSelectionMode;
l === "clear" ? (this._firstActiveCoords = i, this.clear()) : l === "modify" ? this.modify(s) : this.append(s), this._setSelectionCell(i);
}
setAdjusting(e) {
this._adjusting = e, this._emitter.notify("onAdjustingChange");
}
getAdjusting() {
return this._adjusting;
}
addListeners(e, t) {
return this._emitter.addListeners(e, t);
}
_setSelectionRanges(e) {
const t = this._coords;
let n = typeof e == "function" ? e(t.ranges) : e ?? $l;
if (D.isEqualRangesArrays(n, t.ranges)) return;
let r = Math.max(n.length ? 0 : -1, Math.min(t.rangeIndex, n.length - 1)), o = t.cell;
r === -1 || D.isCellWithinRange(o, n[r]) || (o = { rowIndex: n[r].rowStart, colIndex: n[r].colStart }), n.length === 1 && D.isSingleCell(n[0]) && D.isCellWithinRange(o, n[0]) && (n = [], r = -1);
const s = { cell: o, ranges: n, rangeIndex: r };
D.isEqualSelectionCoords(s, t) || this.updateCoords(s);
}
_setSelectionCell(e) {
const t = this._coords, n = e ?? sw, r = this._getCellCoordsAsRangeCoords(n);
if (!D.isSingleCell(r) && t.ranges.length === 0) return this.updateCoords({ ranges: [r], rangeIndex: 0, cell: n });
if (D.isEqualCells(n, t.cell)) return;
let o = t.ranges, s = t.rangeIndex;
t.ranges.length === 1 && (D.isSingleCell(t.ranges[0]) && D.isCellWithinRange(n, t.ranges[0]) || !D.isCellWithinRange(n, t.ranges[0])) && (o = [], s = -1);
const i = { ranges: o, rangeIndex: s, cell: n };
return D.isEqualSelectionCoords(i, t) ? void 0 : this.updateCoords(i);
}
_isCellOutOfBounds(e) {
const t = this._getMaxRange();
return e.rowIndex < t.rowStart || e.colIndex < t.colStart || e.colIndex > t.colEnd || e.rowIndex > t.rowEnd;
}
_cellToRangeActual(e, t) {
const n = { rowStart: Math.min(e.rowIndex, t.rowIndex), colStart: Math.min(e.colIndex, t.colIndex), rowEnd: Math.max(e.rowIndex, t.rowIndex), colEnd: Math.max(e.colIndex, t.colIndex) };
if (this._canSelectionSpanMergedCells(n)) return n;
const r = this._getCellCoordsAsRangeCoords(e), o = this._getCellCoordsAsRangeCoords(t), s = { rowStart: Math.min(r.rowStart, o.rowStart), colStart: Math.min(r.colStart, o.colStart), rowEnd: Math.max(r.rowEnd, o.rowEnd), colEnd: Math.max(r.colEnd, o.colEnd) }, i = this._getMergedRanges(s);
return D.extendRangeToUnionRanges(s, i);
}
_rangesFromCellOptional(e, t, n) {
const r = e.ranges.length > 0 ? e.ranges[e.rangeIndex] : { rowStart: e.cell.rowIndex, colStart: e.cell.colIndex, rowEnd: e.cell.rowIndex, colEnd: e.cell.colIndex }, o = { rowStart: Math.min(t.rowIndex ?? r.rowStart, n.rowIndex ?? r.rowStart), colStart: Math.min(t.colIndex ?? r.colStart, n.colIndex ?? r.colStart), rowEnd: Math.max(t.rowIndex ?? r.rowEnd, n.rowIndex ?? r.rowEnd), colEnd: Math.max(t.colIndex ?? r.colEnd, n.colIndex ?? r.colEnd) }, s = { rowIndex: o.rowStart, colIndex: o.colStart }, i = { rowIndex: o.rowEnd, colIndex: o.colEnd };
if (!(this._isCellOutOfBounds(s) || this._isCellOutOfBounds(i)))
return this._cellToRangeActual(s, i);
}
_getMaxRange() {
return this._sheet.getEntireRange().getCoords();
}
toString() {
let e = "";
return e += `selection:[${this._sheet.getRange(this._coords.cell).toString()}`, this._coords.ranges && this._coords.ranges.length > 0 && (e += `, ${this._sheet.getRanges(this._coords.ranges).toString()}`), this._coords.rangeIndex !== void 0 && this._coords.rangeIndex !== -1 && (e += `, ${this._coords.rangeIndex}`), e += "]", e;
}
}
class Bi {
constructor(e, t) {
this._c = e, this._m = t;
}
getModel() {
return this._m;
}
getCoords() {
return this._c;
}
getPropertiesAt(e, t, n) {
return this._m.getPropertiesAt(e, t, n);
}
getSplit(e) {
const t = this._m;
return [new Bi(e[0], t), new Bi(e[1], t)];
}
}
class aw extends mr {
constructor(e) {
if (super({ ...e }), this._coordsCache = null, !e.json) throw new Error("json is required");
this._sheet = e.sheet, this._styles = e.sheet?.getStyles() ?? new is(), this._options = { ...e }, e.setOnContainerCoordsChange(this._processCoordsChange.bind(this)), e.setCreateSpatial(this._createSpatial.bind(this)), this._getContainerRanges = e.getContainerRanges, this._setContainerRanges = e.setContainerRanges;
const t = this;
this._options.transactions.addStateListener(this, { onRestoreOrRevert() {
t._coordsCache = null;
}, onBeforeCommitEnd() {
t._coordsCache = null;
} }), this._fromJSON({ ...e.json });
}
getRanges() {
return this._getContainerRanges();
}
setRanges(e, t) {
const n = this.getRanges(), r = this._setContainerRanges(e, t);
return this._processCoordsChange({ before: n?.getCoords() ?? null, after: r?.getCoords() ?? null }), this;
}
setType(e, t) {
return this._updateState({ type: e }, { description: "Set Conditional Format Type", ...t }), this;
}
getType() {
return this._getState().type;
}
setPriority(e, t) {
return this._updateState({ priority: e }, { description: "Set Priority", ...t }), this;
}
getPriority() {
return this._getState().priority;
}
setStopIfTrue(e, t) {
return this._updateState({ stopIfTrue: e }, { description: `Set Stop ${e ?? !1}`, ...t }), this;
}
getStopIfTrue() {
return this._getState().stopIfTrue ?? !1;
}
getScalar() {
return this._getState().value ?? null;
}
getColorScale() {
return this._getState().colorScale ?? null;
}
getContainsText() {
return this._getState().text;
}
getCustom() {
return this._getState().formulas;
}
getDataBar() {
return this._getState().dataBar ?? null;
}
getIconSet() {
return this._getState().iconSet;
}
getPresetCriteria() {
return this._getState().style;
}
getTopBottom() {
return this._getState();
}
getSnapshot(e) {
this.toJSON();
const t = null, n = this, r = Object.freeze({ ...e });
let o = !1;
return { async copyTo(s, i) {
s.conditionals;
const l = s.range;
({ ...r, ...i }).isCut && !o && (n.delete(), o = !0);
const c = { colStart: l.colStart, rowStart: l.rowStart, colEnd: t.colEnd - t.colStart + l.colStart, rowEnd: t.rowEnd - t.rowStart + l.rowStart };
return console.log("implement copyTo"), c;
}, getCoords: () => t, getSource: () => n, getName: () => "Conditional Format", getMarkOptions: () => r, isISnapshot: !0 };
}
_processRestoreOrRevert(e, t, n) {
super._processRestoreOrRevert(e, t, n);
}
_createSpatial(e) {
return new Bi(e, this);
}
_processCoordsChange(e) {
this._coordsCache = null, e.after ? this._emitter.notify("onAnyChange") : this._delete();
}
update(e, t) {
if (this.isClosed()) throw new Error("Table has been closed. No further operations are allowed.");
const n = this._getState(), r = this._beginCommit(t?.description ?? "Update Conditional Format");
try {
const o = { ...n, ...e };
this._updateState(o, t), this._getEmitter().notify("onAnyChange"), r.commit();
} catch (o) {
throw r.rollback(), o;
}
return this;
}
_processDelete() {
this._getState(), super._processDelete();
}
_processStateChange(e, t, n) {
super._processStateChange(e, t, n), this._getEmitter().notify("onAnyChange");
}
toJSON() {
const e = {}, t = this._getState();
if (t === null) return null;
const n = this.getRanges()?.toString();
return n ? (e.ref = n, e.type = t.type, t.priority !== 0 && (e.priority = t.priority), t.stopIfTrue && (e.stopIfTrue = t.stopIfTrue), t.style && (e.style = t.style), t.colorScale && (e.colorScale = t.colorScale), t.dataBar && (e.dataBar = t.dataBar), t.iconSet && (e.iconSet = t.iconSet), t.aboveAverage && (e.aboveAverage = t.aboveAverage), t.equalAverage && (e.equalAverage = t.equalAverage), t.stdDev !== 0 && (e.stdDev = t.stdDev), t.bottom && (e.bottom = t.bottom), t.percent && (e.percent = t.percent), t.rank !== 0 && (e.rank = t.rank), t.operator && (e.operator = t.operator), t.formulas && (e.formulas = t.formulas), t.text && (e.text = t.text), t.timePeriod && (e.timePeriod = t.timePeriod), e) : null;
}
_fromJSON(e) {
const t = {};
t.type = e.type ?? Vl.Type.CellIs, t.priority = e.priority ?? 0, t.stopIfTrue = e.stopIfTrue ?? !1, t.style = e.style ?? null, t.colorScale = e.colorScale ?? null, t.dataBar = e.dataBar ?? null, t.iconSet = e.iconSet ?? null, t.aboveAverage = e.aboveAverage ?? !1, t.equalAverage = e.equalAverage ?? !1, t.stdDev = e.stdDev ?? 0, t.bottom = e.bottom ?? !1, t.percent = e.percent ?? !1, t.rank = e.rank ?? 0, t.operator = e.operator ?? null, t.formulas = e.formulas ?? null, t.text = e.text ?? null, t.timePeriod = e.timePeriod ?? null, this._updateState(t, { description: "Initialize Conditional Format" });
}
close() {
super.close(), this.isClosed() || (this._updateState({}, { description: "Close Conditional" }), this._stylesRemoveListener?.());
}
getCoords() {
return this.getRanges().getCoords()[0];
}
getPropertiesAt(e, t, n) {
let r = this._coordsCache;
r || (r = this._coordsCache = this.getRanges().getCoords());
let o = 0, s = 0;
const i = { rowIndex: e, colIndex: t };
for (let c = 0; c < r.length; c++) {
const h = r[c];
if (D.isCellWithinRange(i, h)) {
const u = e - h.rowStart, d = t - h.colStart;
s = o + (u * (h.colEnd - h.colStart + 1) + d + 1);
}
o += (h.rowEnd - h.rowStart + 1) * (h.colEnd - h.colStart + 1);
}
let l = { fill: { type: "solid", color: "red" } };
return l.fill.color = ((c, h, u, d) => {
let g = 1;
h !== 0 && (g = c / h);
const m = u[0] + g * (d[0] - u[0]), f = u[1] + g * (d[1] - u[1]), _ = u[2] + g * (d[2] - u[2]);
return `rgb(${Math.round(m)}, ${Math.round(f)}, ${Math.round(_)})`;
})(s, o, [255, 255, 255], [255, 0, 0]), l;
}
get isIConditionalFormat() {
return !0;
}
}
class lw {
constructor(e, t) {
this._add = e, this._get = t;
}
add(e, t) {
if (!e) throw new Error(Ur);
return this._add(e, t);
}
getItems(e) {
let t;
return e?.address && (t = e.address), this._get(t, e?.excludeHidden, e?.fullyContained);
}
getCount() {
return this._get(null, !1, !1).length;
}
}
const gd = (a, e) => {
if (e) {
if (e.getType() === Y.Type.Solid) a.background = on(e.getColor()) || "none", a["mso-pattern"] = "black none";
else if (e.getType() === Y.Type.Pattern) {
const t = e;
a.background = on(t.getBackground()) || "none";
const n = on(t.getForeground()) || "";
if (t.getPatternType() === Y.BuiltInSheetPattern.Solid) a["mso-pattern"] = `${a.background} none`, a.background = n;
else {
const r = ((o) => qe.get(o)?.cssKey ?? "solid")(t.getPatternType());
a["mso-pattern"] = n + (r ? " " : "") + r;
}
} else if (e.getType() === Y.Type.Gradient) {
const t = e;
a.background = on(t.getStops()?.[0]?.getColor()) || "auto", a.msoGradient = im(t) || "auto";
}
}
};
class cw {
constructor(e, t) {
if (this._visitedStyles = /* @__PURE__ */ new Map(), this._lastStyleClassId = 63, this._wroteTD = !1, !e) throw new Error("Can not create with a null sheet.");
this._sheet = e, this._includeSizeInCell = t ?? !1, this._normalStyle = e.getStyles().getNormal();
}
_createCSSStyle(e) {
const t = this._normalStyle, n = {}, r = (d, g) => d === g || !(d && !g) && !(!d && g) && g.isEqual?.(d), o = e.getFont(), s = t.getFont();
var i;
r(o.getFill(), s.getFill()) || (n.color = on(o.getFill())), r(o.getSize(), s.getSize()) || (n["font-size"] = Eu(o.getSize())), r(o.getWeight(), s.getWeight()) || (n["font-weight"] = o.getWeight()), r(o.getStyle(), s.getStyle()) || (n["font-style"] = o.getStyle()), r(o.getUnderline(), s.getUnderline()) || (n["text-decoration"] = "underline", n["text-underline-style"] = (i = o.getUnderline()) === te.UnderlineStyle.Single ? "single" : i === te.UnderlineStyle.Double ? "double" : i === te.UnderlineStyle.SingleAccounting ? "single-accounting" : i === te.UnderlineStyle.DoubleAccounting ? "double-accounting" : "none"), r(o.getFamily(), s.getFamily()) && r(o.getFallbacks(), s.getFallbacks()) || (n["font-family"] = Ti(o.getFamily(), o.getFallbacks())), r(e.getNumberFormat(), t.getNumberFormat()) || (n["mso-number-format"] = vu(e.getNumberFormat()));
const l = e.getAlignment(), c = t.getAlignment();
if (!r(l.getHorizontal(), c.getHorizontal())) {
const d = l.getHorizontal();
d === X.HorizontalAlignment.CenterContinuous ? n["text-align"] = "center-across" : d === X.HorizontalAlignment.Fill ? n["text-align"] = "fill" : d === X.HorizontalAlignment.Distributed ? n["text-align"] = l.getJustifyLastLine() ? "121" : "010" : n["text-align"] = X.toCSSHorizontalTextAlign(d);
}
if (!r(l.getVertical(), c.getVertical())) {
const d = l.getVertical();
d === X.VerticalAlignment.Distributed ? n["vertical-align"] = "121" : n["vertical-align"] = Cu(d);
}
if (!r(l.getOverflow(), c.getOverflow())) {
const d = l.getOverflow();
n["white-space"] = bu(d), d === X.Overflow.Shrink && (n["mso-text-control"] = "shrinktofit");
}
var h;
r(l.getRotation(), c.getRotation()) || (n["mso-rotate"] = (h = l.getRotation(), (h %= 360) < 0 && (h += 360), h > 180 ? h = 360 - h : h > 1 && (h *= -1), h)), r(l.getIndent(), c.getIndent()) || (n["mso-char-indent-count"] = l.getIndent()), r(e.getFill(), s.getFill()) || gd(n, e.getFill());
const u = e.getBorder();
return u.getTop().isNone() || (n["border-top"] = nr(u.getTop())), u.getLeft().isNone() || (n["border-left"] = nr(u.getLeft())), u.getRight().isNone() || (n["border-right"] = nr(u.getRight())), u.getBottom().isNone() || (n["border-bottom"] = nr(u.getBottom())), u.getDiagonalUp().isNone() || (n["border-mso-diagonal-up"] = nr(u.getDiagonalUp())), u.getDiagonalDown().isNone() || (n["border-mso-diagonal-down"] = nr(u.getDiagonalDown())), Object.keys(n).length === 0 ? null : n;
}
_createCSSNormalStyle() {
const e = this._normalStyle, t = { "padding-top": "1px", "padding-left": "1px", "padding-right": "1px", "mso-ignore": "padding" }, n = e.getFont(), r = e.getAlignment();
return t.color = on(n.getFill()), gd(t, e.getFill()), t["font-size"] = Eu(n.getSize()), t["font-weight"] = n.getWeight(), t["font-style"] = n.getStyle(), t["text-decoration"] = rm(n.getUnderline(), n.getStrike()), t["font-family"] = Ti(n.getFamily(), n.getFallbacks()), t["mso-font-charset"] = "0", t["mso-background-source"] = "auto", t["mso-number-format"] = vu(e.getNumberFormat()), t["text-align"] = X.toCSSHorizontalTextAlign(r.getHorizontal()), t["vertical-align"] = Cu(r.getVertical()), t.border = "none", t["mso-pattern"] = "auto", t["white-space"] = bu(r.getOverflow()), r.getOverflow() === X.Overflow.Shrink && (t["mso-text-control"] = "shrinktofit"), t["mso-rotate"] = "0", r.getIndent() > 0 && (t["mso-char-indent-count"] = r.getIndent()), t["mso-protection"] = "locked visible", t;
}
onCell(e, t, n) {
let r;
const o = e.getSpans();
if (o.width > 1 || o.height > 1) {
if (!e.isTopLeft()) return !1;
o.height > 1 && n.addAttribute("rowspan", o.height), o.width > 1 && n.addAttribute("colspan", o.width);
}
let s = e.toTextUnformatted();
e.getNumberFormat().repeatPlaceholder && (s = e.getNumberFormat().repeatPlaceholder.repeat(5)), n.setPlainText(s || "");
const i = e.getStyle(), l = i.getFont();
if (l.getVerticalAlignment() === te.VerticalAlignment.Super && (s = `<sup>${s}</sup>`), l.getVerticalAlignment() === te.VerticalAlignment.Sub && (s = `<sub>${s}</sub>`), l.getStrike() && (s = `<s>${s}</s>`), e.getHyperlink() && (s = `<a href="${e.getHyperlink().getAddress()}">${s}</a>`), n.setHTMLText(s || " "), !this._wroteTD) {
const h = this._createCSSNormalStyle();
n.addSharedStyle("td", h), this._wroteTD = !0;
}
let c = this._visitedStyles.get(i);
if (!c) {
const h = this._createCSSStyle(i);
h && (c = "xl" + ++this._lastStyleClassId, this._visitedStyles.set(i, c), n.addSharedStyle("." + c, h));
}
if (c && n.addAttribute("class", c), this._includeSizeInCell) {
const h = this._sheet.getColumnHeaders().at(t.colIndex).getSize();
n.addAttribute("width", h), n.addStyle("width", F.roundAccurately(h / te.getDeviceScale(), 2) + "pt");
const u = this._sheet.getRowHeaders().at(t.rowIndex).getSize();
n.addAttribute("height", u), n.addStyle("height", F.roundAccurately(u / te.getDeviceScale(), 2) + "pt");
}
return r;
}
onRow(e, t, n, r) {
const o = e.getSize();
r.addAttribute("height", o), r.addStyle("height", F.roundAccurately(o / te.getDeviceScale(), 2) + "pt"), e.isCustomSize() && r.addStyle("mso-height-source", "userset");
}
onColumn(e, t, n, r) {
const o = e.getSize();
r.addAttribute("width", o), r.addStyle("width", F.roundAccurately(o / te.getDeviceScale(), 2) + "pt"), e.isCustomSize() && r.addStyle("mso-width-source", "userset"), n > 1 && r.addAttribute("colspan", n);
}
}
const md = (a, e, t) => {
const n = a.getOrientation() === xe.Column, r = (n ? "Column" : "Row") + " Copy", o = a.getSnapshot(t);
return { ...o, getName: () => r, getCoords: () => e, copyTo: async (s, i) => {
const l = n ? s.getColumnHeaders() : s.getRowHeaders(), c = { ...t, ...i };
if (c.includeHeaders === !0) {
const h = await o.copyTo(l, c);
return n ? { colStart: h.min, rowStart: e.rowStart, colEnd: h.max, rowEnd: e.rowEnd } : { colStart: e.colStart, rowStart: h.min, colEnd: e.colEnd, rowEnd: h.max };
}
}, getMarkOptions: () => t };
}, hw = (a, e, t, n, r, o) => {
const s = t[0];
let i, l;
const c = () => {
if (l !== void 0) return;
const [h, u] = ((d, g) => {
const m = g.getRowHeaders(), f = g.getColumnHeaders(), _ = g.getUsedRange()?.getCoords(), p = m.getUsedRange()?.getCoords(), S = f.getUsedRange()?.getCoords(), E = { ...D.EmptyRange, ..._, colEnd: Math.max(_?.colEnd ?? 0, S?.max ?? 0), rowEnd: Math.max(_?.rowEnd ?? 0, p?.max ?? 0) }, y = /* @__PURE__ */ new Map(), C = [];
d.onStart?.();
const w = { rows: [], cols: [] }, b = new XS(y, C);
b.setNode(w), d.onTable?.(b, E);
let x = 0;
f.forEachSpan((H, z) => {
const W = z.getCoords();
x = x + W.max - W.min + 1;
const L = {};
b.setNode(L), d.onColumn?.(z.getCellHeader(), W.min, W.max - W.min + 1, b), w.cols.push(L);
}, { address: E, includeEmpty: !0, includeStyles: !0 });
let I = 0;
const v = [];
if (m.forEachSpan((H, z) => {
const W = z.getCoords();
I = I + W.max - W.min + 1, v.push({ min: W.min, max: W.max, value: z.getCellHeader() });
}, { address: E, includeEmpty: !0, includeStyles: !0, excludeHidden: !1 }), x * I > 5e4) {
if (!sd) throw sd = !0, new Dm("Unable to write more than 50000 cells to system clipboard. Items can still be pasted within the application to but if you want to copy to another application select a smaller set of data.");
return [null, null];
}
let R = 0, A = -1, M = null;
g.forEach((H, z) => {
const W = z.getCoords(), L = z.getCell();
if (W.rowIndex !== A) {
W.rowIndex > v[R].max && ++R;
const G = v[R];
M = { cells: [] }, b.setNode(M), d.onRow?.(G.value, W.rowIndex, 1, b), w.rows.push(M), A = W.rowIndex;
}
const j = {};
b.setNode(j), d.onCell(L, W, b) !== !1 && M.cells.push(j);
}, { address: E, includeEmpty: !0, excludeHidden: !1 }), d.onDone?.(), w.rows.length === 0 && w.rows.push({ cells: [] });
const T = [];
for (let H = 0; H < C.length; H++) {
const z = C[H], W = y.get(z);
T.push(z);
let L = "";
const j = Object.keys(W);
for (let G = 0; G < j.length; G++) {
L += " ", G === 0 && (L += "{");
const V = j[G];
L += `${V}:${W[V]};`, G === j.length - 1 ? L += "}" : L += `
`;
}
T.push(L);
}
const k = [`<div clipboard-uuid=xxx>
<html
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40"
>`];
k.push(`<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 15">`), k.push(`<style>
table
{mso-displayed-decimal-separator:"\\.";
mso-displayed-thousand-separator:"\\,";}
@page
{margin:.75in .25in .75in .25in;
mso-header-margin:.3in;
mso-footer-margin:.3in;
mso-horizontal-page-align:center;}
tr
{mso-height-source:auto;}
col
{mso-width-source:auto;}
br
{mso-data-placement:same-cell;}`), T.length > 0 && k.push(T.join(`
`)), k.push("</style>"), k.push("</head>"), k.push("<body>"), k.push("<table>"), k.push("<!--StartFragment-->");
const P = (H) => {
let z = ((L) => {
let j = "";
return L && L.attributes && L.attributes.length !== 0 && L.attributes.forEach((G, V) => {
j.length > 0 && (j += " "), j += `${V}=${G}`;
}), j;
})(H);
z.length > 0 && (z = " " + z);
let W = ((L) => {
let j = "";
return L && L.styles && L.styles.length !== 0 && (L.styles.forEach((G, V) => {
j.length > 0 && (j += ";"), j += V + ":" + G;
}), j.length > 0 && (j = `style='${j}'`)), j;
})(H);
return W.length > 0 && (W = " " + W), `${z}${W}`;
}, B = [];
return w.cols?.forEach((H) => {
k.push(` <col${P(H)}>`);
}), w.rows.forEach((H) => {
k.push(` <tr${P(H)}>`);
const z = [];
H.cells.forEach((W) => {
k.push(` <td${P(W)}>${W.htmlText ?? W.plainText ?? ""}</td>`);
const L = `${F.castToString(W.plainText ?? "")?.replace(/"/g, '""')}`;
z.push(L);
}), B.push(z.join(" ")), k.push(" </tr>");
}), k.push("<!--EndFragment-->"), k.push("</table>"), k.push("</body>"), k.push("</html>"), k.push("</div>"), [k.join(`
`), B.join(`
`).concat(`
`)];
})(new cw(e), e.getRange(s));
i = h ?? null, l = u ?? null;
};
return { copyTo(h, u) {
const d = { ...r, ...u };
return u.isCut, o(h, d);
}, getMarkOptions: () => r, getSource: () => a, getName: () => n, getCoords: () => s, toText: () => (c(), l), toHtml: () => (c(), i), toImage: () => null, isISnapshot: !0 };
}, _i = (a, e) => Math.round(a * e), fd = (a, e, t) => {
const n = [], r = [];
if (!a || a.length === 0) return { sizes: n, hidden: r };
if (!e || !t) return console.warn("_HeaderUtils:default size and scaleFactor should be available"), { sizes: n, hidden: r };
let o = 0, s = 0, i = 0, l = null, c = -2;
for (let h = 0; h < a.length; h++) {
const u = a[h], d = u.min, g = u.max;
o = n.length === 0 ? 0 : n[n.length - 1].runningOffsetMax, n.length > 0 && n[n.length - 1].spanSize > 0 && o++, s < u.min && n.push({ indexMin: s, indexMax: d - 1, runningOffsetMin: o, runningOffsetMax: Math.round(o + (d - s) * e * t) - 1, runningHiddenRuns: i, spanSize: Math.round(e * t) });
const m = n.length, f = n[m - 1];
o = m === 0 ? 0 : f.runningOffsetMax, m > 0 && f.spanSize > 0 && o++;
let _ = 0;
u.value.h || (_ = _i(u.value?.sz ?? e, t));
const p = _ === 0 ? 0 : -1;
_ === 0 && (i += g - d + 1, c + 1 === d ? l.max = g : (l = { min: d, max: g, value: !0 }, r.push(l)), c = g), m > 0 && f.spanSize === _ && f.indexMax + 1 === d ? (f.indexMax = g, f.runningHiddenRuns = i, f.runningOffsetMax = f.runningOffsetMin + (g + 1 - f.indexMin) * _ + p) : n.push({ indexMin: d, indexMax: g, runningOffsetMin: o, runningOffsetMax: Math.round(o + (g + 1 - d) * _) + p, runningHiddenRuns: i, spanSize: _ }), s = g + 1;
}
return { sizes: n, hidden: r };
};
function sl(a, e, t) {
t !== void 0 && (t !== null ? a[e] = t : delete a[e]);
}
const il = () => {
}, pd = () => 0, uw = () => !1, vm = (a, e, t, n) => {
if (n !== void 0) {
if (n === null) return null;
if (n?.isICellHeader)
return n._headerState;
if (n) {
const r = n, o = { ...t };
let s, i = r.hidden, l = r.size;
if (r.size !== void 0) {
if (typeof l == "function") {
const c = t?.sz === void 0 ? a.getDefaultSize() : t?.sz * a.getScaleFactor();
l = l?.(c);
}
if (typeof l == "string" && (l = qr(l, e.getNormal().getFont().getSize(), "px")), typeof l == "number") {
const c = a.getMinSize(), h = a.getMaxSize();
l = Math.max(c, Math.min(F.roundAccurately(l, c), h)), r.relativeSize !== !0 && (l /= a.getScaleFactor()), isNaN(l) && (console.warn("headerSize can not be NaN"), l = void 0), l === 0 && (i = !0, l = void 0), s = !r.autoSize;
} else l === null ? (l = null, s = !r.autoSize) : l !== void 0 && (console.warn("headerSize can not be type", l), l = void 0);
}
return sl(o, "sz", l), sl(o, "h", i), sl(o, "csz", s), Object.keys(o).length === 0 ? null : o;
}
}
};
class dc {
constructor(e, t, n) {
this._sheetHeader = e;
const r = this._sheetHeader.getSheet().getStyles();
this._styles = r, this._headerState = t, this._template = n;
}
getSize() {
const e = this._headerState?.sz;
return Math.round(e === void 0 ? this._sheetHeader.getDefaultSize() : e * this._sheetHeader.getScaleFactor());
}
getDisplayText() {
return "" + this.asCell().getValue();
}
getOrientation() {
return this._sheetHeader.getOrientation();
}
isHidden() {
return this._headerState?.h ?? !1;
}
isCustomSize() {
return this._headerState?.cs ?? !1;
}
getSheetHeader() {
return this._sheetHeader;
}
getStyle() {
return this._headerState?.s ?? this._styles.getNormal();
}
asCell() {
return this._cellTemplate || (this._cellTemplate = this._sheetHeader.getSheet().createTemporaryCell({ style: this.getStyle(), ...this._template })), this._cellTemplate;
}
getSizeRelative() {
return this.getSize() / this._sheetHeader.getScaleFactor();
}
createTemporaryCellHeader(e) {
const t = vm(this._sheetHeader, this._sheetHeader.getSheet().getStyles(), this._headerState, e);
return new dc(this._sheetHeader, t, this._template);
}
isEqual(e) {
if (!e) return !1;
if (e === this) return;
const t = e;
if (!t.isICellHeader) return !1;
const n = this._headerState, r = t._headerState;
return n === r || !(n && !r || r && !n) && this.getSize() === t.getSize() && this.isCustomSize() === t.isCustomSize() && this.isHidden() === t.isHidden() && this.getStyle() === t.getStyle();
}
isEmpty() {
const e = this._headerState;
return !e || e.sz === void 0 && e.csz === void 0 && !e.cs && e.h === void 0 && !(!e.s || e.s !== this._styles.getNormal() || e.cs);
}
get isICellHeader() {
return !0;
}
}
const Ls = "The columns are protected. To make a change, unprotect the sheet. You might be requested to enter a password.", Bs = "The rows are protected. To make a change, unprotect the sheet. You might be requested to enter a password.", rr = "Rows", or = "Columns";
class _d {
constructor(e) {
if (this._emitter = null, this._closed = !1, this._scaleFactor = 1, this._defaultSize = -1, this._defaultCustomSize = -1, this._defaultPxSize = 1, this._isColumn = !0, this._indexedSizes = [], this._indexedHidden = [], this._headerRunCoords = null, this._hasCustomFormats = !1, this._hasStyles = !1, this._hasHidden = !1, this._lastHeaderRead = null, this._readCache = null, this._lastVisibleRunsRead = null, this._lastVisibleRunCoords = null, this._options = { isProtected: () => !1, getUpdateId: () => null, scaleFactor: () => 1, defaultSize: () => 100, minSize: () => 0, maxSize: () => 500, orientation: O.Orientation.Column, createCellHeader: (s, i, l) => new dc(s, i, l), ...e }, !this._options.sheet) throw new Error("An ISheet must be provided");
if (this._emptyHeader = this._options.createCellHeader(this, null, null), this._scaleFactor = this._options.scaleFactor(), this._defaultSize = this._options.defaultSize(), this._defaultSize <= 0) throw new Error("defaultSize must be greater than 0");
this._defaultPxSize = _i(this._defaultSize, this._scaleFactor);
const t = this._options.orientation === O.Orientation.Column;
this._isColumn = t;
const n = this._options.maxSheetCoords ?? { colStart: 0, rowStart: 0, colEnd: Number.MAX_SAFE_INTEGER, rowEnd: Number.MAX_SAFE_INTEGER };
this._maxSheetCoords = n;
const r = t ? n.colEnd : n.rowEnd;
this._maxDataIndex = r, this._maxRunCoords = { min: 0, max: r }, this._maxDataRange = this.getRange(this._maxRunCoords), this._maxRangeCoords = { colStart: 0, rowStart: 0, colEnd: t ? r : 0, rowEnd: t ? 0 : r };
const o = this;
this._options.setContainerShiftedCallback && this._options.setContainerShiftedCallback((s, i) => {
i < 0 ? o._deleteHeaders(s, -i) : o._insertHeaders(s, i);
}), this._options.sheet && (this._sheetRemoveListener = this._options.sheet.addListeners({ onProtectionChange() {
}, onSelectionChange(s) {
o._selection = s.getSelection().getCoords(), o._selectionRuns = null;
}, onStyleChange: () => {
}, onViewChange() {
const s = { runs: o._headers };
o._invalidSizes(), o._emitter.notify("onSizesChange", { params: s });
} }, { transactional: !1 }), o._selection = o._options.sheet.getSelection().getCoords()), this._transactions = this._options.transactions ?? new Xt({ transient: !0 }), this._emitter = new mt(o, this._transactions), this._transactionsRemoveListener = this._transactions.addStateListener(this, { onAfterStateChange(s) {
o._lastHeaders !== s.headers && o._onHeaderChange();
} }), this.fromJSON(this._options?.json);
}
addListeners(e, t) {
return this._emitter.addListeners(e, t);
}
_invalidSizes() {
const e = this._defaultCustomSize === -1 ? this._options.defaultSize() : this._defaultCustomSize, t = this._options.scaleFactor();
if (e !== this._defaultSize || t !== this._scaleFactor) {
this._defaultSize = e, this._scaleFactor = t, this._defaultPxSize = _i(e, t);
const n = fd(this._headers, e, t);
this._indexedSizes = n.sizes, this._indexedHidden = n.hidden, this._lastVisibleRunsRead = null, this._lastVisibleRunCoords = null;
}
}
_onHeaderChange() {
this._lastHeaders = null;
const e = this._headers, t = this._getState();
this._defaultCustomSize = t.defaultCustomSize;
const n = this._defaultCustomSize === -1 ? this._options.defaultSize() : this._defaultCustomSize;
this._defaultSize = n;
const r = this._scaleFactor;
this._defaultPxSize = _i(n, r);
const o = fd(e, n, r);
this._indexedSizes = o.sizes, this._indexedHidden = o.hidden, this._lastHeaderRead = null, this._readCache = bg(this._lastHeaders), this._lastVisibleRunsRead = null, this._lastVisibleRunCoords = null;
const s = this._options.sheet.getStyles().getNormal();
let i = !1, l = !1, c = !1, h = -1;
for (let g = e.length - 1; g >= 0; g--) {
const m = e[g], f = m.value, _ = f.s, p = f.csz || f.sz !== n;
h !== -1 || !p && _ === s || (h = m.max), i = i || f.cs, l = l || f.s !== s, c = c || f.h || f.sz === 0;
}
h = Math.min(h ?? 0, this._maxDataIndex);
const u = Math.min(e[0]?.min ?? h, h);
this._headerRunCoords = Object.freeze({ min: u, max: h }), this._hasCustomFormats = i, this._hasStyles = l, this._hasHidden = c;
const d = t.runs;
this._emitter.notify("onSizesChange", { params: d });
}
getSheet() {
return this._options.sheet;
}
getOrientation() {
return this._isColumn ? O.Orientation.Column : O.Orientation.Row;
}
getTextAt(e) {
return this._options.getTextAt?.(e) ?? e + "";
}
_scanHeaders(e, t, n, r, o, s) {
const i = o?.min ?? null, l = o?.max ?? null, c = s?.includeEmpty ?? !1, h = s?.includeStyles ?? !1, u = s?.excludeHidden ?? !1, d = s?.includeSizes ?? !1, g = this, m = this._options.sheet.getStyles().getNormal(), f = this._defaultSize, _ = this._scaleFactor, p = this._emptyHeader;
let S;
const E = { getCoords() {
if (!S) throw new Error(Jr);
return { min: S.min, max: S.max };
}, getIndex: () => S.min, getCellHeader() {
if (!S) throw new Error(Jr);
return S.value ? n(g, S.value) : p;
}, getA1(C) {
if (!S) throw new Error(Jr);
return this._parseHeaderRangeAddress({ min: i + C, end: i + C }) ?? S;
} }, y = ph(t, (C) => {
const w = C.value;
if (!c && !w) return;
let b = c;
if (d && !b && w && (w.csz || w.sz !== f) && (b = !0), h && !b && w && (w.s && w.s !== m || w.cs) && (b = !0), w && w.h === !0 && (b = !u), !b) return;
let x = f;
C.value && (x = C.value.h ? 0 : C.value?.sz ?? f), x *= _, S = C;
const I = e(x, E);
return I && I.break ? I : void 0;
}, i, l);
return S = null, y;
}
getRange(e, t) {
if (!e) throw new Error(Ur);
const n = this, r = this._parseHeaderRangeAddress(e);
if (r.min < 0 || r.max > this._maxDataIndex) return function(l) {
return Object.freeze({ getCoords: () => null, getOrientation: () => l.getOrientation(), toString: () => rt, getA1: () => rt, getCount: pd, getVisibleCount: pd, isEntireHeaders: uw, forEach: il, forEachSpan: il, forEachVisibleSpan: il, getUsedRange: Ie, getSnapshot: Ie, updateHeaders: Ie, clear: Ie, setHidden: Ie, setSize: Ie, at: Ie, doBatch: Ie, getSheetHeader: () => l, isICellHeaderRange: !0 });
}(this);
const o = (l, c, h, u = n._options.createCellHeader) => {
let d = r;
if (c?.address) {
const m = n._parseHeaderRangeAddress(c?.address);
if (m && (d = fh(r, m), !d)) return;
}
const g = this._scanHeaders(l, h, u, t, d, c);
if (g && g.break) return g.break;
}, s = () => {
const l = n._isColumn ? { colStart: r.min, colEnd: r.max } : { rowStart: r.min, rowEnd: r.max };
return En(l, n._maxRangeCoords) ?? rt;
}, i = { getCoords: () => r, getA1: s, toString: s, forEach: (l, c) => {
let h = Number.MAX_SAFE_INTEGER, u = null;
const d = { getIndex: () => h, getCellHeader: () => u.getCellHeader(), getA1: (g) => u.getA1(g), getCoords: () => u.getCoords() };
return o((g, m) => {
u = m;
for (let f = r.min; f < r.max; f++) h = f, l(g, d);
}, c, this._headers, () => this.at(void 0));
}, forEachSpan: (l, c) => o(l, c, this._headers), forEachVisibleSpan: (l, c) => {
const h = r?.min ?? null, u = r?.max ?? null;
let d;
if (d = c?.includeHidden ? l(h, u) : ph(this._indexedHidden, (g) => {
if (g.value) return;
const m = l(g.min, g.max);
return m && m.break ? m : void 0;
}, h, u), d && d.break) return d.break;
}, updateHeaders: (l, c) => (n.updateHeaderPairs([{ address: r, update: l }], { description: c?.description ?? `Update ${n._isColumn ? or : rr} ${toString()}`, ...c }), i), setHidden: (l) => (n.setHidden(r, l), i), getUsedRange: (l) => {
const c = n._headerRunCoords;
return !c || c.min < 0 || c.max > n._maxDataIndex ? null : fh(c, r) ? n.getRange(c, l) : null;
}, getCount: () => r.max - r.min + 1, getVisibleCount: () => n.getVisibleCount(r.min, r.max), isEntireHeaders: () => {
const l = n._maxRunCoords;
return !(r.min > l.min || r.max < l.max);
}, getSnapshot: (l) => this._getSnapshot(r, l), clear: () => (n._clear(r), i), setSize: (l, c) => (n.setSize(r, l, c), i), at: (l) => n.at(r.min + l), getOrientation: () => n.getOrientation(), doBatch: (l, c) => this.doBatch((h) => l(h), c), getSheetHeader: () => n, isICellHeaderRange: !0 };
return Object.freeze(i);
}
getSelectedRange(e) {
const t = ((n) => {
if (!n) return null;
let r = D.cellToRange(n.cell);
for (let o = 0; o < n.ranges.length; o++) r = D.unionRanges(r, n.ranges[o]);
return r;
})(this._options.sheet.getSelection().getCoords());
return this.getRange(t, e);
}
getUsedRange(e) {
return this.getRange(this._headerRunCoords, e);
}
getEntireRange(e) {
return e ? this.getRange(this._maxRangeCoords, e) : this._maxDataRange;
}
at(e) {
if (e < 0 || e > this._maxDataIndex) return this._emptyHeader;
if (this._lastHeaderRead?.offset === e) return this._lastHeaderRead.header;
const t = vg(e, this._readCache);
if (!t) return this._emptyHeader;
const n = this._options.getTextAt?.(e) ?? e + "", r = this._options.createCellHeader(this, t, { value: n });
return this._lastHeaderRead = { offset: e, header: r }, r;
}
updateHeaderPairs(e, t) {
if (this.isProtected()) throw new Error(this._isColumn ? Ls : Bs);
return this._updatePairsInternal(e, t);
}
_parseHeaderRangeAddress(e) {
if (e == null) throw new Error("Must specify a range.");
const t = ((n, r, o) => {
if (n == null) return null;
let s = {};
if (typeof n == "number") s.colStart = n, s.colEnd = n, s.rowStart = n, s.rowEnd = n;
else if (typeof n == "string") {
if (r) {
if (n.match(/[0-9]+/)) throw new Error("Invalid range address for header orientation");
} else if (n.match(/[a-zA-Z]+/)) throw new Error("Invalid range address for header orientation");
let l = Pt(n, o);
if (!l) {
const c = Ug(n.toUpperCase(), !0);
c?.colIndex !== void 0 && (s.colStart = c.colIndex, s.colEnd = c.colIndex), c?.rowIndex !== void 0 && (s.rowStart = c.rowIndex, s.rowEnd = c.rowIndex);
}
s = { ...s, ...l };
}
const i = { min: void 0, max: void 0 };
return r ? (i.min = n.min ?? n.colStart ?? s.colStart, i.max = n.max ?? n.colEnd ?? s.colEnd) : (i.min = n.min ?? n.rowStart ?? s.rowStart, i.max = n.max ?? n.rowEnd ?? s.rowEnd), i.min === void 0 || i.max === void 0 ? null : i;
})(e, this._isColumn, this._maxRangeCoords);
if (!t) throw new Error("Invalid header range.");
return t;
}
update(e, t, n) {
if (!e || (Array.isArray(e) || (e = [e]), e.length === 0)) return;
const r = [];
for (let o = 0; o < e.length; o++) {
const s = this._parseHeaderRangeAddress(e[o]);
this.getRange(s).forEachSpan((i, l) => {
const c = l.getCoords();
r.push({ address: c, update: t });
}, { includeEmpty: !0 });
}
return this.updateHeaderPairs(r, n), this;
}
setSize(e, t = null, n) {
(n?.relativeSize ?? !1) || typeof t != "number" || (t += "px");
const r = { size: t, autoSize: n?.autoSize ?? !1 }, o = `Resize ${this._isColumn ? or : rr}`;
return this.update(e, r, { description: o, ...n }), this;
}
setHidden(e, t = null) {
const n = { hidden: t }, r = `${t ? "Unhide" : "Hide"} ${this._isColumn ? or : rr}`;
return this.update(e, n, { description: r }), this;
}
_clear(e, t) {
const n = "Clear " + (this._isColumn ? "Column Headers" : "Row Headers");
this.updateHeaderPairs([{ address: e, update: null }], { description: n, ...t });
}
_getSnapshot(e, t) {
if (e.min < 0) return F.EmptyArray;
t = Object.freeze({ ...t });
const n = this, r = this._getState(), o = (this._isColumn ? "Column" : "Row") + " Headers";
return { copyTo(s, i) {
const l = { ...t, ...i }, c = s.getCoords(), h = c.min - e.min, u = [];
if (n._scanHeaders((d, g) => {
const m = g.getCoords();
u.push({ address: { min: m.min + h, max: m.max + h }, update: g.getCellHeader() });
}, r.headers, n._options.createCellHeader, null, e, { includeSizes: !0, includeStyles: !0 }), !l.fitDestination) {
let d = e.max - e.min + 1, g = c.max - c.min + 1, m = F.roundAccurately(g / d);
if (m > 1 && g % d === 0) {
const f = u.length;
for (let _ = 0; _ < m; _++) for (let p = 0; p < f; p++) {
const S = u[p], E = S.address, y = (_ + 1) * d;
u.push({ address: { min: E.min + y, max: E.max + y }, update: S.update });
}
}
}
if (s.doBatch(() => {
s.clear(), s.getSheetHeader()._updatePairsInternal(u);
}, o), l.isCut) {
const d = n._maxRunCoords;
e.min <= d.min && e.max >= d.max && n._clear(e);
}
return c;
}, getCoords: () => e, toText: () => null, toHtml: () => null, toImage: () => null, getSource: () => n, getName: () => o, isISnapshot: !0 };
}
isProtected() {
return this._options?.isProtected() ?? !1;
}
getScaleFactor() {
return this._options.scaleFactor() ?? 1;
}
get _headers() {
return this._lastHeaders === null && (this._lastHeaders = this._getState()?.headers), this._lastHeaders;
}
_updatePairsInternal(e, t) {
if (!e || e.length === 0) return null;
const n = t?.skipCustomSize ?? !1, r = this._isColumn, o = this.getSheet().getStyles(), s = this._beginCommit({ description: t?.description ?? `Update ${r ? or : rr}` });
let i = [...this._getState().headers], l = !1, c = !1;
const h = r ? U.Edge.Top : U.Edge.Left;
U.oppositeEdge(h);
const u = r ? U.Edge.Right : U.Edge.Bottom;
U.oppositeEdge(u);
const d = this, g = (y, C) => {
if (this.isProtected()) throw new Error(this._isColumn ? Ls : Bs);
c = c || C === null, !c && C && (c = !!C.isICellHeader || C?.size !== void 0 || C?.hidden !== void 0), l = l || C === null || C?.style !== void 0 || C?.isICellHeader;
const w = { onUpdate: (b, x) => n && b && b.csz ? b : vm(d, o, b, x), onSplit: (b) => [b.value, b.value], onMerge: (b, x, I, v) => {
if (!(b && !x || !b && x || !b && !x) && b.sz === x.sz && b.csz === x.csz && b.h === x.h && b.cs === x.cs) return b;
}, isCull: (b, x, I) => b === void 0 };
i = Wn(vl(i, { min: y.min, max: y.max, value: C }, w));
}, m = e.length, f = new Array(m);
for (let y = 0; y < m; y++) {
const C = e[y], w = this._parseHeaderRangeAddress(C.address);
if (w.min < 0 || w.max > this._maxDataIndex) throw new ze(Ai);
g(w, C.update), f[y] = w;
}
let _ = !1, p = i.length;
if (p > 0 && i[0].min === 0 && i[p - 1].max === this._maxDataIndex) {
let y = i[0], C = !1, w = -1;
for (let I = 0; !C && I < p; I++) {
const v = i[I], R = v.min;
if (w + 1 !== R) {
C = !0;
continue;
}
const A = v.max;
w = A, y.max - y.min < A - R && (y = v);
}
C || (this._defaultCustomSize = y.value?.sz ?? -1, _ = !0);
const b = this._defaultCustomSize === -1 ? this._options.defaultSize() : this._defaultCustomSize, x = [];
for (let I = 0; I < p; I++) {
const v = i[I], R = v.value;
if (R === null) continue;
const A = Object.keys(R);
A.length !== 0 && (A.length !== 1 || R.sz === void 0 || R.sz !== null && R.sz !== b) && x.push(v);
}
i = x, p = i.length;
}
const S = [], E = this._defaultSize;
for (let y = 0; y < p; y++) {
const C = i[y], w = C.value;
if (w === null) continue;
let b = !1;
w.sz !== void 0 && w.sz !== E && (b = !0), w.csz && (b = !0), w.h && (b = !0), w.cs && (b = !0), b && S.push(C);
}
return i = S, p = i.length, _ && d._invalidSizes(), this._updateState({ headers: i, defaultCustomSize: this._defaultCustomSize, runs: f }), s.commit(), f;
}
hasCustomFormats() {
return this._hasCustomFormats;
}
hasCustomStyles() {
return this._hasStyles;
}
hasHidden() {
return this._hasHidden;
}
getDefaultSize() {
return this._defaultPxSize;
}
getMaxSize() {
return Math.ceil(this._options.maxSize() * this._options.scaleFactor());
}
getMinSize() {
return Math.floor(this._options.minSize() * this._options.scaleFactor());
}
findOffset(e) {
return ((t, n, r) => {
if (n < 0) return 0;
if (!t || t.length === 0) return n * r;
const o = t[t.length - 1];
if (n > o.indexMax) return o.runningOffsetMax + Math.round((n - o.indexMax - 1) * r + (o.spanSize !== 0 ? 1 : 0));
const s = t[t.length === 1 ? 0 : F.findEqualOrGreater(t, n, (l) => l.indexMax)], i = n - s.indexMin;
return s.runningOffsetMin + i * s.spanSize;
})(this._indexedSizes, e, this._defaultPxSize);
}
findIndex(e) {
return Math.min(Math.max(0, ((t, n, r) => {
if (!t || t.length === 0) return Math.floor(n / r);
const o = t[t.length - 1];
if (n > o.runningOffsetMax) return o.indexMax + Math.ceil((n - o.runningOffsetMax) / r);
const s = t[t.length === 1 ? 0 : F.findEqualOrGreater(t, n, (l) => l.runningOffsetMax)];
if (s.spanSize === 0) return Math.max(0, s.indexMin - 1);
const i = n - s.runningOffsetMin;
return s.indexMin + Math.floor(i / s.spanSize);
})(this._indexedSizes, e, this._defaultPxSize)), this._maxDataIndex);
}
findVisibleIndex(e) {
return this._lastVisibleRunsRead === e || (this._lastVisibleRunCoords = ((t, n, r = Number.MAX_SAFE_INTEGER) => {
if (!t || t.length === 0) return { min: n, max: n };
let o = t.length - 1, s = t[o];
if (n > s.indexMax) {
const l = n - s.runningHiddenRuns;
return { min: l, max: l };
}
o = t.length === 1 ? 0 : F.findEqualOrGreater(t, n, (l) => l.indexMax), s = t[o];
const i = s.spanSize === 0 ? Math.max(-1, s.indexMin - 1 - (t[o - 1]?.runningHiddenRuns ?? 1)) : n - s.runningHiddenRuns;
return { min: i, max: i + Math.min(r + 1, s.spanSize === 0 ? 1 : 0) };
})(this._indexedSizes, e, this._maxDataIndex), this._lastVisibleRunsRead = e), this._lastVisibleRunCoords;
}
getSpanSize(e, t = e + 1) {
return this.findOffset(t) - this.findOffset(e);
}
getVisibleCount(e, t) {
if (e > t) throw new Error("Invalid arguments.");
if (e < 0 || t > this._maxDataIndex) throw new ze();
return this._hasHidden ? ((n, r, o) => {
let s = o - r + 1;
if (n.length === 0) return s;
let i = n.length - 1, l = n[i];
if (r > l.indexMax) return s;
i = n.length === 1 ? 0 : F.findEqualOrGreater(n, r, (u) => u.indexMax), l = n[i];
let c = l.runningHiddenRuns;
if (l.spanSize === 0 && r <= l.indexMax) {
const u = l.indexMax - l.indexMin + 1;
s -= Math.min(u, l.indexMax - r + 1);
}
o > l.indexMax && i < n.length && (i = F.findEqualOrGreater(n, o, (u) => u.indexMax), l = n[Math.min(i, n.length - 1)]);
let h = l.runningHiddenRuns;
if (l.spanSize === 0 && l.indexMin <= o) {
const u = l.indexMax - l.indexMin + 1;
s -= Math.min(u, o - l.indexMin + 1), h -= u;
}
return s -= h - c, s;
})(this._indexedSizes, e, t) : t - e + 1;
}
isSelectedAll(e) {
const t = this.getSelectedRuns();
if (t.length === 0) return !1;
const n = t[F.findEqualOrGreater(t, e, (r) => r.max)];
return !(!n || e < n.min || e > n.max) && n.value.isSelectedAll;
}
isSelected(e) {
const t = this.getSelectedRuns();
if (t.length === 0) return !1;
const n = t[F.findEqualOrGreater(t, e, (r) => r.max)];
return !(!n || e < n.min || e > n.max);
}
getSelectedRuns() {
let e = this._selectionRuns;
return e || (this._selection && (e = ((t, n, r) => {
let o = [];
n?.ranges && n.ranges.length > 0 ? o = n.ranges : n?.cell && (o = [D.cellToRange(n?.cell)]);
let s = [];
const i = t.getOrientation() === O.Orientation.Column;
for (let l = 0; o && l < o.length; l++) {
const c = o[l], h = i ? c.colStart : c.rowStart, u = i ? c.colEnd : c.rowEnd, d = i ? c.rowStart : c.colStart, g = i ? c.rowEnd : c.colEnd, m = i ? r.rowStart : r.colStart, f = i ? r.rowEnd : r.colEnd, _ = d <= m && g >= f;
s = Wn(vl(s, { min: h, max: u, value: { isSelectedAll: !1 } }, { onUpdate: (p, S) => {
const E = bl(p, S);
return E.isSelectedAll = p?.isSelectedAll || _, E;
} }));
}
return s;
})(this, this._selection, this._maxSheetCoords)), e || (e = F.EmptyArray)), this._selectionRuns = e, this._selectionRuns;
}
hiddenHeadersAt(e, t = !1) {
if (this._indexedSizes.length === 0) return 0;
let n = this._indexedSizes.length === 1 ? 0 : F.findEqualOrGreater(this._indexedSizes, e, (o) => o.indexMax), r = this._indexedSizes[n];
return !r || r.spanSize !== 0 || r.indexMin > e || r.indexMax < e ? 0 : t ? e - r.indexMin + 1 : r.indexMax - e + 1;
}
_insertHeaders(e, t) {
if (this.isProtected()) throw new Error(this._isColumn ? Ls : Bs);
if (t <= 0) return;
const n = this._beginCommit({ description: `Insert ${this._isColumn ? or : rr}` }), r = this._getState();
let o = [...r.headers];
o = Wn(((i, l, c = 1) => {
const h = F.findEqualOrGreater(i, l, (m) => m.max), u = i.slice(0, h), d = [], g = [];
if (!i[h]) return { preceding: u, modified: g, trailing: d };
i[h].min >= l ? d.push({ ...i[h], min: i[h].min + c, max: i[h].max + c }) : g.push({ ...i[h], min: i[h].min, max: i[h].max + c });
for (let m = h + 1; m < i.length; m++) d.push({ ...i[m], min: i[m].min + c, max: i[m].max + c });
return { preceding: u, modified: g, trailing: d };
})(o, e, t));
const s = [{ min: e, max: e + t }];
this._updateState({ headers: o, runs: Wn(Go([...r?.runs ?? [], ...s])) }), n.commit();
}
_deleteHeaders(e, t) {
if (this.isProtected()) throw new Error(this._isColumn ? Ls : Bs);
const n = this._beginCommit({ description: `Delete ${this._isColumn ? or : rr}` }), r = this._getState();
let o = [...r.headers];
o = Wn(Rp(o, e, t));
const s = [{ min: e, max: e + t }];
this._updateState({ headers: o, runs: Wn(Go([...r?.runs ?? [], ...s])) }), n.commit();
}
beginCommit(e) {
return this._beginCommit(typeof e == "string" ? { description: e } : e);
}
doBatch(e, t) {
return this._transactions.doBatch(e, typeof t == "string" ? { description: t } : { description: "Update Header", ...t });
}
isClosed() {
return this._closed;
}
close() {
this._sheetRemoveListener?.(), this._emitter.close(), this._transactionsRemoveListener?.(), this._closed = !0;
}
_getState() {
return this._transactions.getState(this);
}
_beginCommit(e) {
return this._transactions.beginCommit(e);
}
_updateState(e) {
const t = this._transactions.beginCommit();
try {
t.updateState(this, e), this._onHeaderChange(), t.commit();
} catch (n) {
throw t.rollback(), n;
}
}
fromJSON(e) {
const t = e || {};
this._defaultCustomSize = t.defaultSize ?? -1, this._defaultCustomSize <= 0 && (this._defaultCustomSize = -1), this._invalidSizes();
const n = this._options.sheet.getStyles().beginPersist();
try {
const r = [], o = t.headers ? t.headers.length : 0, s = this._maxDataIndex;
for (let i = 0; i < o; i++) {
let l = t.headers[i];
if (l.min >= s) continue;
let c = { min: l.min, max: Math.min(l.max, s) };
const h = {};
l.sz !== void 0 && l.sz !== -1 && (h.sz = l.sz), l.h !== void 0 && (h.h = l.h), l.csz !== void 0 && (h.csz = l.csz), l.cs !== void 0 && (h.cs = l.cs), Object.keys(h).length === 0 && (h.cs = !0), c.value = h, r.push(c);
}
this._updateState({ headers: r, defaultCustomSize: this._defaultCustomSize });
} finally {
n.endPersist();
}
}
toJSON() {
if (this._headers.length === 0 && this._defaultCustomSize === -1) return null;
const e = { headers: [] };
if (this._defaultCustomSize !== -1 && (e.defaultSize = F.roundAccurately(this._defaultCustomSize, 8)), this._headers.length === 0) return e;
const t = this._defaultCustomSize, n = this.getSheet().getStyles().beginPersist();
for (let r = 0; r < this._headers.length; r++) {
const o = this._headers[r], s = o.value;
if (!s) continue;
const i = { min: o.min, max: o.max };
s.sz !== void 0 && s.sz !== t && (i.sz = F.roundAccurately(s.sz, 8), s.csz !== void 0 && (i.csz = s.csz)), s.h === !0 && (i.h = s.h), Object.keys(i).length > 2 && e.headers.push(i);
}
return n.endPersist(), e;
}
}
class Sd {
constructor(e, t) {
this._c = e, this._tvTl = t;
}
tvTl() {
return this._tvTl(this._c);
}
getCoords() {
return this._c;
}
}
const dw = (a) => {
let e = "";
const t = hi, n = a.length;
for (let r = 0; r < n; r++) {
const o = a[r];
o.type === "cell" ? e += t(o.value) : e += o.value;
}
return e;
}, gw = (a, e = 0, t = 0) => {
let n = "";
const r = Xg, o = a.length;
for (let s = 0; s < o; s++) {
const i = a[s];
i.type === "cell" ? n += r(i.value, e, t) : n += i.value;
}
return n;
};
class mw {
constructor(e, t, n) {
this._c = e, this._tokens = t, this._references = n || F.EmptyArray;
}
getFormulaTextAt(e, t, n = !1) {
return n ? dw(this._tokens) : gw(this._tokens, e, t);
}
getTokensAt(e, t, n) {
let r = this._tokens;
return n !== void 0 && (r = ((o, s) => {
const i = o.length, l = [];
if (s === void 0) return F.EmptyArray;
let c = -1, h = !1;
for (let u = 0; !h && u < i; u++) {
const d = o[u], g = d.evalIndex ?? Number.MAX_SAFE_INTEGER;
if (c === -1) {
if (g !== s) continue;
c = u;
}
g > s ? h = !0 : l.push(d);
}
h = !1;
for (let u = c - 1; !h && u >= 0; u--) {
const d = o[u];
(d.evalIndex ?? Number.MAX_SAFE_INTEGER) > s ? h = !0 : l.unshift(d);
}
return l.length > 1 && l[0].type === "whitespace" && l.shift(), l.length > 1 && l[l.length - 1].type === "whitespace" && l.pop(), l;
})(r, n)), r = ((o, s = 0, i = 0) => {
const l = o.length, c = new Array(l);
for (let h = 0; h < l; h++) {
const u = o[h];
if (u.type !== "cell") {
c[h] = u;
continue;
}
const d = { ...u }, g = { ...d.value };
d.value = g, c[h] = d, g.colIndex === Number.MIN_SAFE_INTEGER || g.$colIndex || (g.colIndex += i), g.rowIndex === Number.MIN_SAFE_INTEGER || g.$rowIndex || (g.rowIndex += s);
}
return c;
})(r, e, t), r;
}
getReferencesAt(e, t) {
return ((n, r = 0, o = 0) => {
const s = n.length, i = new Array(s);
for (let l = 0; l < s; l++) {
const c = n[l];
if (typeof c == "string" || c instanceof Ee.Known) {
i[l] = c;
continue;
}
const h = { ...c };
i[l] = h, h.colStart === Number.MIN_SAFE_INTEGER || h.$colStart || (h.colStart += o), h.rowStart === Number.MIN_SAFE_INTEGER || h.$rowStart || (h.rowStart += r), h.colEnd === Number.MIN_SAFE_INTEGER || h.$colEnd || (h.colEnd += o), h.rowEnd === Number.MIN_SAFE_INTEGER || h.$rowEnd || (h.rowEnd += r);
}
return i;
})(this._references, e, t);
}
toJSON() {
const e = this._c;
return [Rn(e), this.getFormulaTextAt(e.rowStart, e.colStart)];
}
getCoords() {
return this._c;
}
}
class zi {
constructor(e, t, n) {
this.groupId = e, this.uuid = t, this.noShift = n;
}
onRemove(e) {
}
getShifted(e) {
if (!e.after) return null;
const t = this.noShift;
return t ? void 0 : { ...e.after, value: new zi(this.groupId, this.uuid, t) };
}
getSplit(e, t) {
}
copyTo(e, t) {
return new zi(this.groupId, this.uuid, this.noShift);
}
canTile(e, t) {
return !1;
}
}
class Pi {
constructor(e, t, n, r, o, s, i, l, c, h) {
this.uuid = e, this.spatialsIds = t, this.isRanges = r, this.coords = n, this.sheet = o, this.generation = s, this.handler = i, this.handlerW = l, this.removeListener = c, this.options = h;
}
delete() {
this.removeListener();
}
createRangeEvent(e, t) {
const n = this;
let r;
const o = () => {
if (r) return r;
const i = n.sheet, l = n.isRanges, c = n.coords;
return t || !c || c.length === 0 ? Cn(i, i.getEntireRange().getCoords(), null, t) : l ? (r = i.getRanges(n.coords), r) : (r = i.getRange(n.coords[0]), r);
}, s = e.trigger;
return { getSource: o, trigger: s, isTransactional: e.isTransactional ?? !0, toString: () => `SheetRangeEvent: ('${s}', ${o().toString()})`, timeStamp: e.timeStamp ?? Date.now() };
}
notify(e, t) {
const n = this.createRangeEvent(e, t), r = this.handler ?? this.handlerW.deref();
try {
r?.(n);
} catch (o) {
console.warn(o);
}
this.options?.once && this.removeListener();
}
processRemove(e) {
const t = this.spatialsIds, n = t.indexOf(e.value.uuid);
console.assert(n !== -1, "invalid uuid");
const r = this.coords, o = r.slice(0, n).concat(r.slice(n + 1)), s = t.slice(0, n).concat(t.slice(n + 1));
return new Pi(this.uuid, s, o, this.isRanges, this.sheet, this.generation, this.handler, this.handlerW, this.removeListener, this.options);
}
processShift(e) {
const t = this.spatialsIds.indexOf(e.value.uuid);
console.assert(t !== -1, "invalid uuid");
const n = [...this.coords];
return n[t] = { ...n[t], ...D.sanitizeRange(e) }, new Pi(this.uuid, this.spatialsIds, n, this.isRanges, this.sheet, this.generation, this.handler, this.handlerW, this.removeListener, this.options);
}
processSplit(e) {
}
processMerge(e) {
}
}
const xm = Object.freeze({ coords: D.EmptyCell, topLeft: Hi.EmptyTopLeft }), fw = Object.freeze({ cell: D.EmptyCell, ranges: F.EmptyArray, rangeIndex: 0 }), al = Object.freeze({ selection: fw, topLeft: Hi.EmptyTopLeft, freezePanes: xm, showRowHeaders: !0, showColumnHeaders: !0, showRowGridlines: !0, showColumnGridlines: !0, rowHeaderStyle: nn.HeaderTextStyle.One, columnHeaderStyle: nn.HeaderTextStyle.A1, showFormulas: !1, showZeros: !0, zoomScale: 100, gridLineColor: null });
class ll {
constructor(e) {
if (this._emitter = null, !e?.sheet) throw new Error("SheetView requires a sheet.");
const t = new mt(this);
this._emitter = t, this._sheet = e.sheet, this.clear(!1), e.json && this._fromJSON(e.json);
}
addListeners(e, t) {
return this._emitter.addListeners(e, t);
}
setTopLeft(e) {
return this._state.topLeft = Object.freeze({ left: e?.left ?? this._state.topLeft.left, top: e?.top ?? this._state.topLeft.top }), this._emitter.notify("onTopLeftChange"), this;
}
getTopLeft() {
return this._state.topLeft;
}
getFreezePanes() {
return this._state.freezePanes;
}
setFreezePanes(e) {
return this._state.freezePanes = this._mergeFreezePanes(e), this._emitter.notify("onFreezeSplitChange"), this;
}
_mergeFreezePanes(e) {
return e ? { ...this._state.freezePanes, coords: { colIndex: e?.coords?.colIndex ?? this._state.freezePanes.coords.colIndex, rowIndex: e?.coords?.rowIndex ?? this._state.freezePanes.coords.rowIndex }, topLeft: { left: e?.topLeft?.left ?? this._state.topLeft.left, top: e?.topLeft?.top ?? this._state.topLeft.top } } : xm;
}
isShowRowHeaders() {
return this._state.showRowHeaders;
}
setShowRowHeaders(e) {
return this._state.showRowHeaders = e, this._notifyAll(), this;
}
isShowColumnHeaders() {
return this._state.showColumnHeaders;
}
setShowColumnHeaders(e) {
return this._state.showColumnHeaders = e, this._notifyAll(), this;
}
isShowRowGridlines() {
return this._state.showRowGridlines;
}
setShowRowGridlines(e) {
return this._state.showRowGridlines = e, this._notifyAll(), this;
}
isShowColumnGridlines() {
return this._state.showColumnGridlines;
}
setShowColumnGridlines(e) {
return this._state.showColumnGridlines = e, this._notifyAll(), this;
}
getRowHeaderStyle() {
return this._state.rowHeaderStyle;
}
setRowHeaderStyle(e) {
return this._state.rowHeaderStyle = e, this._notifyAll(), this;
}
getColumnHeaderStyle() {
return this._state.columnHeaderStyle;
}
setColumnHeaderStyle(e) {
return this._state.columnHeaderStyle = e, this._notifyAll(), this;
}
getZoomScale() {
return this._state.zoomScale;
}
setZoomScale(e) {
return this._state.zoomScale = e, this._notifyAll(), this;
}
isShowFormulas() {
return this._state.showFormulas;
}
setShowFormulas(e) {
return this._state.showFormulas = e, this._notifyAll(), this;
}
isShowZeros() {
return this._state.showZeros;
}
setShowZeros(e) {
return this._state.showZeros = e, this._notifyAll(), this;
}
getGridLineColor() {
return this._state.gridLineColor;
}
setGridLineColor(e) {
return this._state.gridLineColor = e, this._notifyAll(), this;
}
setRangeSelection(e) {
return this._state.selection = e, this._emitter.notify("onRangeSelectionChange"), this;
}
getRangeSelection() {
return this._state.selection;
}
getMovableSelection() {
return this._movableSelection;
}
setMovableSelection(e) {
const t = this._movableSelection;
return this._movableSelection = Object.freeze(e ?? []), F.isEqualArrays(t, this._movableSelection) || this._emitter.notify("onMovableSelectionChange"), this;
}
selectMovables(e, t = !1) {
const n = new Set(this._sheet.getMovables().getItems());
let r = null, o = !1;
if (t) {
r = [...this._movableSelection];
for (let s = e.length - 1; s >= 0; s--) {
const i = e[s];
let l = r.indexOf(i);
if (l !== s) {
if (o = !0, !n.has(i)) throw new Error(`Movable ${i.getName()} not found in sheet.`);
l !== -1 && r.splice(l, 1), r.unshift(i);
}
}
} else o = !F.isEqualArrays(e, this._movableSelection), r = [...e];
o && (this._movableSelection = r, this._emitter.notify("onRangeSelectionChange"), this._emitter.notify("onMovableSelectionChange"));
}
unselectMovables(e) {
const t = this._movableSelection, n = [];
for (let r = 0; r < t.length; r++) {
const o = t[r];
e.indexOf(o) === -1 && n.push(o);
}
return t.length !== n.length && (this._movableSelection = n, this._emitter.notify("onRangeSelectionChange"), this._emitter.notify("onMovableSelectionChange")), this;
}
_notifyAll() {
const e = this._emitter;
e.notify("onRangeSelectionChange"), e.notify("onTopLeftChange"), e.notify("onFreezeSplitChange"), e.notify("onAnyChange");
}
toJSON() {
const e = {}, t = Object.keys(this._state);
for (let r = 0; r < t.length; r++) {
const o = this._state[t[r]];
o != null && o !== al[t[r]] && (e[t[r]] = o);
}
delete e.movableSelection, delete e.gridLineColor, this._state.gridLineColor instanceof Qe && (e.gridLineColor = this._state.gridLineColor.toString()), delete e.topLeft, !this._state.topLeft || this._state.topLeft.left === 0 && this._state.topLeft.top === 0 || (e.topLeft = { left: this._state.topLeft.left ?? 0, top: this._state.topLeft.top ?? 0 }), delete e.selection;
const n = this._state.selection;
if (n) {
let r = {};
!n.cell || n.cell.colIndex === 0 && n.cell.rowIndex === 0 || (r.cell = os(n.cell)), n.ranges && n.ranges.length > 0 && (r.ranges = oc(n.ranges), n.rangeIndex !== void 0 && n.rangeIndex !== -1 && n.rangeIndex !== 0 && (r.rangeIndex = n.rangeIndex)), Object.keys(r).length > 0 && (e.selection = r);
}
if (delete e.freezePanes, this._state.freezePanes && (this._state.freezePanes.coords.colIndex !== 0 || this._state.freezePanes.coords.rowIndex !== 0)) {
const r = {};
this._state.freezePanes.coords.colIndex !== 0 && (r.c = this._state.freezePanes.coords.colIndex), this._state.freezePanes.coords.rowIndex !== 0 && (r.r = this._state.freezePanes.coords.rowIndex), this._state.freezePanes.topLeft.left !== 0 && (r.x = this._state.freezePanes.topLeft.left), this._state.freezePanes.topLeft.top !== 0 && (r.y = this._state.freezePanes.topLeft.top), e.freezePanes = r;
}
return Object.keys(e).length === 0 ? null : e;
}
_fromJSON(e) {
let t = JSON.parse(JSON.stringify(e || {}));
t?.zoomScale && (t.zoomScale = F.roundAccurately(parseFloat(e.zoomScale), 2));
const n = (r) => {
const o = this._sheet.getRange(r).getBounds(), s = (t.zoomScale ?? 100) / 100;
return { x: o.x * s, y: o.y * s, width: o.width * s, height: o.height * s };
};
if (typeof t?.gridLineColor == "string" && (this._sheet?.getStyles() ? t.gridLineColor = this._sheet.getStyles().parseColor(e.gridLineColor) : console.warn("Style was created with no styles so gridLineColor can't be parsed.")), t.topLeft) if (typeof t.topLeft == "string") {
const r = n(Pr(t.topLeft));
t.topLeft = { left: r.x, top: r.y };
} else t.topLeft = Object.freeze({ left: t.topLeft?.left ?? t?.x ?? 0, top: t.topLeft?.top ?? t?.y ?? 0 });
if (t.selection) {
let r = Pr(t.selection.cell ?? "A1");
if (t.selection.cell = r, t.selection.ranges) {
let o = Math.max(0, Math.min(t.selection.rangeIndex ?? t.selection.ranges?.length - 1, t.selection.ranges?.length - 1));
t.selection.rangeIndex = o;
let s = !1;
for (let i = 0; i < t.selection.ranges.length; i++) {
const l = At(t.selection.ranges[i]);
t.selection.ranges[i] = l, i === o && r && !D.isCellWithinRange(r, l) && (s = !0);
}
if (s) for (let i = 0; s && i < t.selection.ranges.length; i++) D.isCellWithinRange(r, t.selection.ranges[i]) && (s = !1, t.selection.rangeIndex = i);
s && (t.selection.ranges.push(D.cellToRange(r)), t.selection.rangeIndex = t.selection.ranges.length - 1);
} else delete t.selection.rangeIndex;
}
if (t.freezePanes) {
const r = t.freezePanes;
if (typeof r.coords == "string" && (r.coords = Pr(r.coords)), typeof r.topLeft == "string") {
const o = Pr(r.topLeft), s = n({ colIndex: o.colIndex + 1, rowIndex: o.rowIndex + 1 }), i = n({ colIndex: (r?.coords?.colIndex ?? -1) + 1, rowIndex: (r?.coords?.rowIndex ?? -1) + 1 });
r.topLeft = { left: 0, top: 0 }, t.topLeft || (t.topLeft = { top: 0, left: 0 }), o.colIndex > 0 && (r.topLeft.left = t.topLeft?.left ?? 0, t.topLeft.left = s.x - i.x + r.topLeft.left), o.rowIndex > 0 && (r.topLeft.top = t.topLeft?.top ?? 0, t.topLeft.top = s.y - i.y + r.topLeft.top);
}
t.freezePanes = { coords: { colIndex: r?.coords?.colIndex ?? t.freezePanes?.c ?? 0, rowIndex: r?.coords?.rowIndex ?? t.freezePanes?.r ?? 0 }, topLeft: { left: r?.topLeft?.left ?? t.freezePanes?.x ?? 0, top: r?.topLeft?.top ?? t.freezePanes?.y ?? 0 } };
}
this.update(t);
}
clear(e = !0) {
return this._state = { ...al }, this._movableSelection = Object.freeze([]), e && this._notifyAll(), this;
}
update(e) {
return this._state = { ...al, ...this._state, ...e }, this._state.freezePanes = this._mergeFreezePanes(this._state.freezePanes), this._state.zoomScale = Math.min(400, Math.max(10, this._state.zoomScale)), this._notifyAll(), this;
}
get isISheetView() {
return !0;
}
}
async function wd() {
const { getCrypto: a } = await import("./KGsrafeyxbtvDiYV.mjs");
return a();
}
const yd = async (a, e, ...t) => {
const n = pw(...t);
return a.subtle.digest(e, n);
}, pw = (...a) => {
const e = a.reduce((r, o) => r + o.byteLength, 0), t = new Uint8Array(e);
let n = 0;
return a.forEach((r) => {
t.set(new Uint8Array(r), n), n += r.byteLength;
}), t.buffer;
}, Ed = (a) => {
const e = new Uint8Array(a);
let t = "";
for (let n = 0; n < e.byteLength; n++) t += String.fromCharCode(e[n]);
return btoa(t);
};
class Sn {
static {
this.DefaultAlgo = "SHA-512";
}
static {
this.DefaultSpinCount = 1e5;
}
static async generateSaltAndHash(e, t = Sn.DefaultAlgo, n = Sn.DefaultSpinCount) {
if (!e) return null;
const r = (await wd()).getRandomValues(new Uint8Array(16)), o = Ed(r.buffer);
return { salt: o, hash: await Sn._convertPasswordToHash(e, o, t, n) };
}
static async verifyPassword(e, t, n = Sn.DefaultAlgo, r = Sn.DefaultSpinCount) {
if (!e || !t) throw new Kt();
return ((o, s) => {
const i = o.length, l = s.length;
let c = i === l ? 0 : 1;
for (let h = 0; h < Math.max(i, l); h++) c |= o.charCodeAt(h % i) ^ s.charCodeAt(h % l);
return c === 0;
})(await Sn._convertPasswordToHash(e, t.salt, n, r), t.hash);
}
static async _convertPasswordToHash(e, t, n, r) {
const o = await wd();
n = n.toUpperCase();
const s = ((c) => {
const h = new ArrayBuffer(2 * c.length), u = new DataView(h);
for (let d = 0; d < c.length; d++) u.setUint16(2 * d, c.charCodeAt(d), !0);
return new Uint8Array(h);
})(e), i = ((c) => {
const h = atob(c), u = new Uint8Array(h.length);
for (let d = 0; d < h.length; d++) u[d] = h.charCodeAt(d);
return u.buffer;
})(t);
let l = await yd(o, n, i, s.buffer);
for (let c = 0; c < r; c++) {
const h = new Uint32Array([c]).buffer;
l = await yd(o, n, l, h);
}
return Ed(l);
}
}
class Im {
constructor(e, t = !1) {
this._emitter = null, this._emitter = new mt(this), this.fromJSON(e), this._isReadOnly = t;
}
async lock(e, t, n, r) {
if (this._isReadOnly) return this;
if (this.isLocked() && !this._isPaused) throw new Error("Cannot lock an already locked object. Use unlock first.");
try {
this._validatePassword();
} catch {
throw new Error("A password is already set. Unlock first to change.");
}
let o;
if (t) {
const s = await Sn.generateSaltAndHash(t, n, r);
o = { salt: s.salt, hash: s.hash }, n && (o.algorithm = n), r && (o.spinCount = r);
} else o = null;
return e = e ?? {}, this._updateProperties(e), this._properties = e, this._password = o, this._emitter.notify("onLockChange"), this._emitter.notify("onChange"), this;
}
async unlock(e) {
if (this._isReadOnly) throw new Error("Cannot unlock a readonly workbook.");
return await this._validatePassword(e), this._clearProperties(), this._password = null, this._identities = null, this._password = null, this._emitter.notify("onLockChange"), this._emitter.notify("onChange"), this;
}
checkPassword(e) {
return this._validatePassword(e);
}
hasPassword() {
return this._password !== null;
}
async pause(e) {
return this._emitter.notify("onLockChange"), this._emitter.notify("onChange"), await this._validatePassword(e), this._password && (this._isPaused = !0), this;
}
resume() {
return this._isPaused = !1, this;
}
isPaused() {
return this._isPaused;
}
isLocked() {
return this._properties !== null && !this._isPaused;
}
isReadOnly() {
return this._isReadOnly;
}
async _validatePassword(e) {
const t = this._password;
if (!(e && e.length !== 0 || t && t.hash)) return !0;
if (!e) throw new Error("Password is required.");
if (!await Sn.verifyPassword(e, { salt: t.salt, hash: t.hash }, t.algorithm, t.spinCount)) throw new Error("Invalid password.");
return !0;
}
getProperties() {
return this._properties;
}
_isPropertyAllowed(e) {
if (this._isReadOnly) return !1;
if (!this.isLocked()) return !0;
const t = this._properties[e];
return typeof t == "boolean" && t;
}
_updateProperties(e) {
this._properties = { ...e, ...this._properties ?? {} };
}
_clearProperties() {
this._properties = null;
}
addListeners(e, t) {
return this._emitter.addListeners(e, t);
}
fromJSON(e) {
this._password = null, this._identities = null, this._isPaused = !1, this._properties = null, this._fromJSON(e ?? null), e && (e.password && (this._password = e.password), e.identities && (this._identities = e.identities));
}
_fromJSON(e) {
}
_toJSON(e) {
return e;
}
toJSON() {
if (!this._properties) return null;
let e = {};
return e = this._toJSON(e) ?? {}, this._password && (e.password = this._password), this._identities && (e.identities = this._identities), e;
}
}
const _w = Object.freeze({ selectLockedCells: !0, selectUnlockedCells: !0, autoFilter: !1, deleteColumns: !1, deleteRows: !1, formatCells: !1, formatColumns: !1, formatRows: !1, insertColumns: !1, insertHyperlinks: !1, insertRows: !1, objects: !1, pivotTables: !1, scenarios: !1, sheet: !1, sort: !1, verifier: null });
class Cd extends Im {
isAutoFilterAllowed() {
return this._isPropertyAllowed("autoFilter");
}
isDeleteColumnsAllowed() {
return this._isPropertyAllowed("deleteColumns");
}
isDeleteRowsAllowed() {
return this._isPropertyAllowed("deleteRows");
}
isFormatCellsAllowed() {
return this._isPropertyAllowed("formatCells");
}
isFormatColumnsAllowed() {
return this._isPropertyAllowed("formatColumns");
}
isFormatRowsAllowed() {
return this._isPropertyAllowed("formatRows");
}
isInsertColumnsAllowed() {
return this._isPropertyAllowed("insertColumns");
}
isInsertHyperlinksAllowed() {
return this._isPropertyAllowed("insertHyperlinks");
}
isInsertRowsAllowed() {
return this._isPropertyAllowed("insertRows");
}
isObjectsAllowed() {
return this._isPropertyAllowed("objects");
}
isPivotTablesAllowed() {
return this._isPropertyAllowed("pivotTables");
}
isScenariosAllowed() {
return this._isPropertyAllowed("scenarios");
}
isSortAllowed() {
return this._isPropertyAllowed("sort");
}
isSelectLockedCellsAllowed() {
return !1;
}
isSelectUnlockedCellsAllowed() {
return !1;
}
_updateProperties(e) {
super._updateProperties(e), this._properties = e;
}
_clearProperties() {
super._clearProperties(), this._properties = null;
}
_fromJSON(e) {
super._fromJSON(e), this._properties = e;
}
_toJSON(e) {
let t = this._properties;
if (t) {
e = { ...e, ...t };
const n = Object.keys(t);
for (let r = 0; r < n.length; r++) {
const o = t[n[r]];
o != null && o !== _w[n[r]] && (e[n[r]] = o);
}
}
return super._toJSON(e);
}
}
class as {
constructor(e, t, n) {
this._coords = Object.freeze(e), this._sheet = t, this._readOnly = n?.readOnly ?? null;
}
_createRanges(e, t) {
let n = this._options;
return t && (n = { ...this._options, getOptions: In(this._options?.getOptions, t) }), new as(e, this._sheet, n);
}
_createRange(e, t) {
let n = this._options;
return t && (n = { ...this._options, getOptions: In(this._options?.getOptions, t) }), new ls(e, this._sheet, n);
}
_validateWrite() {
const e = this._readOnly;
if (e) throw new Error(e);
}
getCoords() {
return this._coords;
}
[Symbol.iterator]() {
const e = this.entries({ excludeCellDetails: !0 });
return { next() {
const t = e.next();
return t.done ? ke : { done: !1, value: t.value.value };
}, [Symbol.iterator]() {
return this;
} };
}
entries(e) {
const t = this.getCoords(), n = e?.reverse ?? !1;
let r = n ? t.length - 1 : 0;
const o = this;
let s = o._createRange(t[r]), i = s.entries(e), l = i.next();
return { next() {
let c = l;
do {
if (l.done) {
if (r = n ? r - 1 : r + 1, r >= t.length || r < 0) return l = ke, c;
s = o._createRange(t[r]), i = s.entries(e);
}
l = i.next();
} while (l.done);
return c;
}, [Symbol.iterator]() {
return this;
} };
}
async select(e) {
const t = await this._sheet._autoSelect(e ?? !0, Pe(this.getCoords()));
return this._createRanges(t);
}
calculate() {
const e = this.getCoords();
return this._sheet._calculate(e), this;
}
addListener2(e, t) {
return this._sheet._addRangesListeners2(this.getCoords(), e, t, !0);
}
addListener(e, t) {
return this._sheet._addRangesListeners(this.getCoords(), e, t);
}
find(e, t) {
return this._sheet._find(this.getCoords(), e, t);
}
getFlattened(e) {
const t = this.getCoords();
if (t.length === 1) return this._createRanges(t, e);
const n = e?.orientations ?? O.Orientations.Both, r = n === O.Orientations.Both, o = r ? Number.MAX_SAFE_INTEGER : 1, s = n === O.Orientations.Row ? O.Orientation.Column : O.Orientation.Row;
let i = Ml(t, o, s);
if (r) {
const l = Ml(t, o, O.Orientation.Column);
l.length < i.length && (i = l);
}
return this._createRanges(i, e);
}
getVisible(e) {
const t = this._sheet._getVisible(this.getCoords(), e);
return t && t.length !== 0 ? this._createRanges(t, e) : null;
}
getFixed(e) {
const t = [], n = this.getCoords();
for (let r = 0; r < n.length; r++) t.push(fm(n[r], e));
return this._createRanges(t, e);
}
autoFit(e) {
return this._validateWrite(), this._sheet._autoFit(this.getCoords(), e), this;
}
clear(e, t) {
return this._validateWrite(), this._sheet._clear(this.getCoords(), e, t), this;
}
updateStyle(e, t) {
return this._validateWrite(), this._sheet._updateStyles(this.getCoords(), e, t), this;
}
getStyleUpdater() {
return this._sheet._getStyleUpdater(this.getCoords());
}
merge(e) {
return this._validateWrite(), this._sheet._merge(this.getCoords(), e), this;
}
unmerge(e) {
return this._validateWrite(), this._sheet._unmerge(this.getCoords(), e), this;
}
getMerges() {
return this._sheet._getMerges(this.getCoords(), this._options?.excludeHidden ?? !1);
}
insert(e, t) {
return this._validateWrite(), this._sheet._insertCells(this.getCoords(), e, t), this;
}
delete(e, t) {
return this._validateWrite(), this._sheet._deleteCells(this.getCoords(), e, t), this;
}
async insertFrom(e, t) {
this._validateWrite();
const n = await this._sheet._insertFrom(this.getCoords(), e, t);
return n ? this._createRanges([n]) : null;
}
async copyFrom(e, t) {
const n = await this._sheet._copyFrom(this.getCoords()[0], e, t);
return n ? this._createRanges([n]) : null;
}
isInvalidAny() {
const e = this.getCoords();
if (!e || e.length === 0) return !0;
for (let t = 0; t < e.length; t++) if (e[t] === null) return !0;
return !1;
}
getSnapshot(e) {
return this._sheet._getSnapshot(this.getCoords(), e);
}
getEntireRows(e, t) {
return this._createRanges(Fi(this.getCoords(), this._sheet._entireCoords, O.Orientation.Column, e), t);
}
getEntireColumns(e, t) {
return this._createRanges(Fi(this.getCoords(), this._sheet._entireCoords, O.Orientation.Row, e), t);
}
getDefaultShiftOrientation() {
return this._sheet._getDefaultShiftOrientation(this.getCoords()[0]);
}
getCount() {
return this.getCoords()?.length ?? 0;
}
getCounts(e) {
return this._sheet._contentCounts(this.getCoords(), e, this._options?.excludeHidden ?? !1);
}
isContentful() {
return this._sheet._isContentful(this.getCoords(), this._options?.excludeHidden ?? !1);
}
getRowCount() {
return ku(this.getCoords(), O.Orientation.Row);
}
getColumnCount() {
return ku(this.getCoords(), O.Orientation.Column);
}
isEntireRowsAny() {
return Xo(this.getCoords(), this._sheet._entireCoords, !1);
}
isEntireColumnsAny() {
return Yo(this.getCoords(), this._sheet._entireCoords, !1);
}
isEntireRows() {
return Xo(this.getCoords(), this._sheet._entireCoords, !0);
}
isEntireColumns() {
return Yo(this.getCoords(), this._sheet._entireCoords, !0);
}
isOverlapping() {
return zo(this.getCoords());
}
at(e) {
const t = this.getCoords();
if (e < 0 || e > t.length - 1) throw new ze();
return this._createRange(t[e]);
}
isReadOnly() {
return this._readOnly !== null;
}
isInvalid() {
return !1;
}
getA1() {
return Jg(this.getCoords(), this._sheet._entireCoords, En, Xn);
}
getSheet() {
return this._sheet;
}
doBatch(e, t) {
return this._sheet.doBatch((n) => e(n), typeof t == "string" ? t : { description: "Ranges Update", ...t });
}
get [Symbol.toStringTag]() {
return "[SheetRanges]";
}
toString() {
return this.getA1();
}
get isICellRanges() {
return !0;
}
}
class ls {
constructor(e, t, n) {
this._coords = Object.freeze(e), this._sheet = t, this._readOnly = n?.readOnly ?? null;
}
getCoords() {
return this._coords;
}
_createRange(e, t) {
const n = this._sheet;
if (!e) return Cn(n, n._entireCoords);
if (n._validateCoords(e), n._closed) return Cn(null, n._entireCoords, e);
let r = this._options;
return t && (r = { ...this._options, getOptions: In(this._options?.getOptions, t) }), new ls(e, this._sheet, r);
}
_createRanges(e, t) {
let n = this._options;
return t && (n = { ...this._options, getOptions: In(this._options?.getOptions, t) }), new as(e, this._sheet, n);
}
_deriveRanges(e, t) {
const n = this.getCoords();
let r = n;
return t && (r = t(n), !r) ? null : this._createRanges(r, e);
}
_deriveRange(e, t, n) {
if (!e) return this;
let r = this._sheet._rangeToCoords(e);
if (!r) return this;
const o = this.getCoords();
if (Po(r, o)) return this;
if (n) {
const l = n(r, o);
if (!l) return this;
r = { ...o, ...l };
}
var s, i;
return s = r, (i = o) && (i.$colStart === void 0 ? delete s.$colStart : s.$colStart = i.$colStart, i.$rowStart === void 0 ? delete s.$rowStart : s.$rowStart = i.$rowStart, i.$colEnd === void 0 ? delete s.$colEnd : s.$colEnd = i.$colEnd, i.$rowEnd === void 0 ? delete s.$rowEnd : s.$rowEnd = i.$rowEnd), this._createRange(r, In(this._options?.getOptions, t));
}
_validateMaxSize(e = 5e4) {
const t = this.getCoords(), n = this._sheet, r = n._colHeaders.getVisibleCount(t.colStart, t.colEnd);
if (n._rowHeaders.getVisibleCount(t.rowStart, t.rowEnd) * r > e) throw new Error(em(e));
}
[Symbol.iterator]() {
const e = this.entries({ excludeCellDetails: !0 });
return { next() {
const t = e.next();
return t.done ? ke : { done: !1, value: t.value.value };
}, [Symbol.iterator]() {
return this;
} };
}
entries(e) {
const t = this.getCoords();
let n = t;
const r = this._sheet;
if (e?.address) {
const s = r._rangeToCoords(e?.address);
if (!s) throw new Error(qo(e?.address));
if (n = D.intersectRanges(s, t), !n) return Ze;
}
n.colEnd < n.colStart && (n.colStart = t.colStart, n.colEnd = t.colEnd), n.rowEnd < n.rowStart && (n.rowStart = t.rowStart, n.rowEnd = t.rowEnd);
const o = this._options?.excludeHidden ?? !1;
return r._cellIterator({ excludeHidden: o, ...e, includeRangeTypes: !e?.excludeCellDetails, bounds: n });
}
forEach(e, t) {
if (!e) return;
const n = this.entries(t);
let r = n.next();
for (; !r.done; ) {
const o = r.value, s = e(o.value, o.context);
if (s) return s.break;
r = n.next();
}
}
_validateWrite() {
const e = this._readOnly;
if (e) throw new Error(e);
}
updateCells(e, t, n) {
this._validateWrite();
const r = this.getCoords();
n || (n = r);
const o = this._sheet, s = o._isDataColumn, i = { majorStart: s ? r.colStart : r.rowStart, majorEnd: s ? r.colEnd : r.rowEnd, minorStart: s ? r.rowStart : r.colStart, minorEnd: s ? r.rowEnd : r.colEnd }, l = (t?.orientation ?? O.Orientation.Row) === O.Orientation.Column !== s, c = Ii(Array.isArray(e) ? e : [[e]], l, i);
return o._updateTuples(c, { description: t?.description ?? `Set ${D.isSingleCell(n) ? "Cell" : "Range"} ${En(n, o._entireCoords)}`, ...t }, null, { isCell: !0 }), this;
}
setValues(e, t) {
if (!Array.isArray(e)) throw new Error("'setValues' expects a 2d array; when working with a single value use 'setValue'.");
return this._setValueOrValues(e, t);
}
setValue(e, t) {
if (Array.isArray(e)) throw new Error(uu);
return this._setValueOrValues(e, t);
}
setFormula(e, t) {
if (Array.isArray(e)) throw new Error(uu);
return this._setValueOrValues(e, t);
}
_setValueOrValues(e, t) {
this._validateWrite();
let n = this.getCoords(), r = this;
const o = this._sheet, s = o._isDataColumn, i = (t?.orientation ?? O.Orientation.Row) === O.Orientation.Column, l = Array.isArray(e);
if (t?.skipBoundsCheck && l) {
const d = e;
let g = Math.max(0, d.length - 1), m = 0;
for (let S = 0; S < d.length; S++) m = Math.max(m, d[S].length - 1);
const f = i ? n.colStart : n.rowStart, _ = i ? n.rowStart : n.colStart, p = { ...n, colEnd: i ? f + g : _ + m, rowEnd: i ? _ + m : f + g };
D.isEqualRanges(p, n) || (n = p, r = this._deriveRange(p, t));
}
const c = { majorStart: s ? n.colStart : n.rowStart, majorEnd: s ? n.colEnd : n.rowEnd, minorStart: s ? n.rowStart : n.colStart, minorEnd: s ? n.rowEnd : n.colEnd }, h = i !== s;
let u = null;
return u = l ? Ii(Array.isArray(e) ? e : [[e]], h, c) : ni(e, c, s), o._updateTuples(u, { description: t?.description ?? `Set ${D.isSingleCell(n) ? "Value" : "Values"} ${En(n, o._entireCoords)}`, ...t }), r;
}
getValues(e) {
this._validateMaxSize(e?.maxSize);
const t = this.getCoords(), n = this._sheet;
return Va(n._cellIterator.bind(this._sheet), t, !1, e);
}
getValue(e) {
const t = this.getCoords();
return this._sheet._getScalar(t.rowStart, t.colStart, e?.asJSDate);
}
calculate(e) {
return this._sheet._calculate([this.getCoords()], { full: e }), this;
}
getCells(e) {
this._validateMaxSize(e?.maxSize);
const t = this.getCoords(), n = this._sheet;
return Va(n._cellIterator.bind(this._sheet), t, !0, e);
}
getCell(e) {
const t = this.getCoords();
let n = t.colStart, r = t.rowStart;
const o = this._sheet;
if (e) {
const i = o._cellToCoords(e);
if (!D.isCellWithinRange(i, t)) throw new Error("The cell is outside of the bounds of the range.");
n = i.colIndex, r = i.rowIndex;
}
const s = Va(o._cellIterator.bind(this._sheet), { colStart: n, rowStart: r, colEnd: n, rowEnd: r }, !0, null);
return s.length === 0 ? o._emptyCell : s[0][0];
}
async select(e) {
const t = this._sheet, n = await t._autoSelect(e ?? !0, Pe([this.getCoords()]));
return this._createRange(n[0]);
}
find(e, t) {
return this._sheet._find([this.getCoords()], e, t);
}
getFixed(e) {
return this._createRange(fm(this.getCoords(), e));
}
getSurrounding(e) {
const t = this._sheet;
return this._createRange(t._surroundingRegion(this.getCoords(), e));
}
getExtended(e, t) {
let n = null;
const r = this.getCoords();
switch (e) {
case O.Direction.Up:
n = { colIndex: r.colStart, rowIndex: r.rowStart };
break;
case O.Direction.Down:
n = { colIndex: r.colStart, rowIndex: r.rowEnd };
break;
case O.Direction.Left:
n = { colIndex: r.colStart, rowIndex: r.rowStart };
break;
case O.Direction.Right:
n = { colIndex: r.colEnd, rowIndex: r.rowStart };
}
const o = this._sheet, s = t ? o._cellToCoords(t) : n;
if (!D.isCellWithinRange(s, r)) throw new Error("Invalid cell.");
let i = o._extendRange(e, s);
return i = D.unionRanges(r, i), this._createRange(i);
}
getEntireRows(e, t) {
const n = this._sheet;
return this._createRange(Fi([this.getCoords()], n._entireCoords, O.Orientation.Column, e)[0], t);
}
getEntireColumns(e, t) {
const n = this._sheet;
return this._createRange(Fi([this.getCoords()], n._entireCoords, O.Orientation.Row, e)[0], t);
}
getRowHeaders(e) {
const t = this.getCoords();
return this._sheet._rowHeaders.getRange(t, e);
}
getColumnHeaders(e) {
const t = this.getCoords();
return this._sheet._colHeaders.getRange(t, e);
}
getDifferences(e, t) {
return this._deriveRanges(t, (n) => {
const r = this._sheet, o = r._rangeToCoords(e), s = Nl(n, o, O.Orientation.Row);
return r._getVisible(s, t);
});
}
getIntersect(e, t) {
return this._deriveRange(e, t, (n, r) => D.intersectRanges(n, r));
}
getUnion(e, t) {
return this._deriveRange(e, t, (n, r) => D.unionRanges(n, r));
}
getResizeTo(e, t, n) {
if (t = t ?? 0, (e = e ?? 0) < 0 || t < 0) throw new Error("Invalid range. The Range must be at a size of at least 1x1'.");
const r = this.getCoords();
return this._deriveRange({ colStart: r.colStart, rowStart: r.rowStart, colEnd: t + r.colStart - 1, rowEnd: e + r.rowStart - 1 }, n);
}
getResizeBy(e, t, n) {
e = e ?? 0, t = t ?? 0;
const r = this.getCoords();
return this._deriveRange({ colStart: r.colStart, rowStart: r.rowStart, colEnd: r.colEnd + t, rowEnd: r.rowEnd + e }, n);
}
getOffsetTo(e, t, n) {
const r = this.getCoords(), o = t, s = e, i = { colStart: o, rowStart: s, colEnd: r.colEnd - r.colStart + o, rowEnd: r.rowEnd - r.rowStart + s };
return this._deriveRange(i, n);
}
getOffsetBy(e, t, n) {
const r = this.getCoords(), o = r.colStart + e, s = r.rowStart + t, i = { colStart: o, rowStart: s, colEnd: r.colEnd - r.colStart + o, rowEnd: r.rowEnd - r.rowStart + s };
return this._deriveRange(i, n);
}
getUsedRange(e) {
const t = this._sheet._getUsedCoords(e);
if (!t) return null;
const n = D.intersectRanges(t, this.getCoords());
return n ? this._deriveRange(n, e) : null;
}
isEmpty() {
const e = this._sheet._getUsedCoords();
return e ? !D.intersectRanges(e, this.getCoords()) : !0;
}
getColumnStart() {
return this.getCoords().colStart;
}
getRowStart() {
return this.getCoords().rowStart;
}
getColumnEnd() {
return this.getCoords().colEnd;
}
getRowEnd() {
return this.getCoords().rowEnd;
}
getColumnCount() {
const e = this.getCoords();
return e.colEnd - e.colStart + 1;
}
getRowCount() {
const e = this.getCoords();
return e.rowEnd - e.rowStart + 1;
}
getVisible(e) {
return this._deriveRanges(e, (t) => this._sheet._getVisible([t], e));
}
isContentful(e) {
return this._sheet._isContentful([this.getCoords()], e, this._options?.excludeHidden ?? !1);
}
getCounts(e) {
return this._sheet._contentCounts([this.getCoords()], e, this._options?.excludeHidden ?? !1);
}
getCount(e) {
return this._sheet._getCount([this.getCoords()], e, this._options?.excludeHidden ?? !1);
}
isEntireRows() {
const e = this._sheet;
return Xo([this.getCoords()], e._entireCoords, !0);
}
isEntireColumns() {
const e = this._sheet;
return Yo([this.getCoords()], e._entireCoords, !0);
}
isEntireRange() {
const e = this.getCoords(), t = this._sheet;
return Yo([e], t._entireCoords, !0) && Xo([e], t._entireCoords, !0);
}
getWidth() {
const e = this._coords;
return e.colEnd - e.colStart + 1;
}
getHeight() {
const e = this._coords;
return e.rowEnd - e.rowStart + 1;
}
get size() {
const e = this._coords;
return e.colEnd - e.colStart + 1 * (e.rowEnd - e.rowStart + 1);
}
getBounds() {
return this._sheet._getBoundsAtCoords(this.getCoords());
}
isInvalid() {
return !1;
}
getDefaultShiftOrientation() {
return this._sheet._getDefaultShiftOrientation(this.getCoords());
}
getDefaultSortCriteria(e, t) {
return this._sheet._getDefaultSortCriteria(this.getCoords(), e, t);
}
getMerges() {
return this._sheet._getMerges([this.getCoords()], this._options?.excludeHidden ?? !1);
}
getSnapshot(e) {
return this._sheet._getSnapshot([this.getCoords()], e);
}
isReadOnly() {
return this._readOnly !== null;
}
addListener2(e, t) {
return this._sheet._addRangesListeners2([this.getCoords()], e, t, !1);
}
addListener(e, t) {
return this._sheet._addRangesListeners([this.getCoords()], e, t);
}
getSheet() {
return this._sheet;
}
autoFill(e, t) {
this._validateWrite();
const n = this._sheet, r = n._rangeToCoords(e, () => [], !0);
return n._autoFill(this.getCoords(), r, t) ? this._createRange(r) : this;
}
autoFit(e) {
return this._validateWrite(), this._sheet._autoFit([this.getCoords()], e), this;
}
clear(e, t) {
return this._validateWrite(), this._sheet._clear([this.getCoords()], e, t), this;
}
setHyperlink(e, t) {
return this._validateWrite(), this._sheet._setHyperlinks([this.getCoords()], e, t), this;
}
setComments(e, t) {
return this._validateWrite(), this._sheet._setComments([this.getCoords()], e, t), this;
}
updateStyle(e, t) {
return this._validateWrite(), this._sheet._updateStyles([this.getCoords()], e, t), this;
}
getStyleUpdater() {
return this._sheet._getStyleUpdater([this.getCoords()]);
}
merge(e) {
return this._validateWrite(), this._sheet._merge([this.getCoords()], e), this;
}
unmerge(e) {
return this._validateWrite(), this._sheet._unmerge([this.getCoords()], e), this;
}
insert(e, t) {
return this._validateWrite(), this._sheet._insertCells([this.getCoords()], e, t), this;
}
async insertFrom(e, t) {
this._validateWrite();
const n = this._sheet, r = await n._insertFrom([this.getCoords()], e, t);
return r ? this._createRange(r) : null;
}
async copyFrom(e, t) {
this._validateWrite();
const n = this._sheet, r = await n._copyFrom(this.getCoords(), e, t);
return r ? this._createRange(r) : null;
}
delete(e, t) {
return this._validateWrite(), this._sheet._deleteCells([this.getCoords()], e, t), this;
}
sort(e) {
this._validateWrite();
const t = this.getCoords(), n = this._sheet._sort(t, e);
return D.isEqualRanges(n, t) ? this : this._createRange(n);
}
doBatch(e, t) {
return this._sheet.doBatch((n) => e(n), typeof t == "string" ? t : { description: "Range Update", ...t });
}
startIncrementalUpdates(e) {
return this._sheet._createIncrementalUpdater(e, this);
}
getA1() {
const e = this._sheet;
return En(this.getCoords(), e._entireCoords);
}
get [Symbol.toStringTag]() {
return "[SheetRange]";
}
toString() {
const e = this._sheet;
return En(this.getCoords(), e._entireCoords);
}
get isICellRange() {
return !0;
}
}
const Sw = Math.pow(2, 14), ww = Math.pow(2, 20), bd = (a) => `${a}`, vd = (a) => Yt(a), xd = (a) => `${a + 1}`;
let yw = 0;
const Id = () => [];
let Ew = 0;
class Zo {
constructor(e) {
this._lastTransactionUUID = null, this._emitter = null, this._initializing = !0, this._emitterMovables = null, this._rangesListenerSorted = null, this._lastCellDecoded = { address: null, coords: null }, this._lastCellSelected = { coords: null, cell: null }, this._lastCellRead = { coords: null, cell: null }, this._lastValueRead = { range: null, isDateOrTime: null }, this._lastGetRangeRead = {}, this._lastUsedCoordsRead = { coords: null, range: null }, this._lastActiveRead = { selection: null, range: null, ranges: null }, this._lastRangeRead = { address: null, range: null, ranges: null }, this._isDataColumn = !0, this._isDate1904 = !1, this._colHeaders = null, this._colHeadersShiftCallback = null, this._colHeadersListener = null, this._colHeadersRemoveListener = null, this._rowHeaders = null, this._rowHeadersShiftCallback = null, this._rowHeadersListener = null, this._rowHeadersRemoveListener = null, this._closed = !1;
const t = Object.freeze({ ...e });
Bd._validate(!0), this._transactions = t.transactions ?? new Xt(), this._ownTransactions = !t.transactions;
const n = this._beginCommit({ description: "New Sheet" }), r = this;
try {
this._entireCoords = Object.freeze({ colStart: 0, rowStart: 0, colEnd: (t.maxColumns ?? Sw) - 1, rowEnd: (t.maxRows ?? ww) - 1 }), this._strings = t.strings ?? new lc(), this._ownStrings = !t.strings;
const o = t.styles ?? new is();
this._styles = o, this._ownStyles = !t.styles, this._names = t.names ?? new Cm({ addressToRanges: (i) => r.getRanges(i), getCurrentScope: () => r.getName(), isReadOnly: () => r._options.readonly ?? !1, transactions: r._transactions }), this._ownNames = !t.names, this._namesRemoveListener = this._names.addListeners({ onCollectionChange: (i) => {
r._calculateFull();
} }, { transactional: !1 }), this._calculation = t.calculation ?? new Em({ getNamed: (i, l) => {
Rd.address = i, Rd.scope = l;
const c = this._names.getItems({ address: i, scope: l });
return c && c.length !== 0 ? c[0].getRanges().getCoords() : null;
}, getSheetIndex: (i) => i === void 0 || i === r.getName() ? 1 : 0, getSheetCount: () => 1, isDate1904: () => r.isDate1904(), strings: r._strings, transactions: r._transactions }), this._ownsCalculation = !t.calculation, this._normalStyleRanged = o.getNamed(ce.BuiltInName.Normal).getRanged(), this._resources = t.resources ?? new _m(), this._ownResources = !t.resources;
const s = async () => {
this._ownsCalculation && await this._calculation.start(), this._starting = null;
};
this._starting = s(), t.container?.setNameChangeCallback && t.container.setNameChangeCallback(() => {
r._emitter.notify("onNameChange");
const i = this._getState().rangesListenerMap, l = /* @__PURE__ */ new Map();
i.forEach((h, u) => {
l.set(u, { beforeState: h, afterState: h });
});
const c = this._beginCommit({ description: "Set Name" });
c.updateState(r, {}), c.commit({ viewAfter: { ranges: [r._entireCoords], listeners: l }, forceAmend: !0 }), r._calculateFull();
}), t.container?.setVisibilityCallback && t.container.setVisibilityCallback(() => {
r._emitter.notify("onVisibilityChange");
}), t.container?.setIndexCallback && t.container.setIndexCallback(() => {
r._calculateFull();
}), this._movables = new QS(this._addMovable.bind(this), this._searchMovables.bind(this), () => {
const i = r._getState();
return i ? i.movableMapModel?.size ?? 0 : 0;
}, this._updateSelectedMovables.bind(this), (i, l) => this._emitterMovables.addListeners(i, l), this._addImage.bind(this)), this._emitterMovables = new mt(this._movables, this._transactions), this._tables = new ow(this._addTable.bind(this), (i, l, c) => {
const h = i ? this._rangeToCoords(i) : this._entireCoords;
return r._getRangedEntries("tableSpatial", [h], { excludeHidden: l, fullyContained: c, onEntry: (u) => u.model });
}, (i) => {
const l = r._getState();
return l ? l.tableMapName.get(i.toLocaleLowerCase()) : null;
}), this._conditionals = new lw(this._addConditional.bind(this), (i, l, c) => {
const h = i ? this._rangeToCoords(i) : this._entireCoords, u = /* @__PURE__ */ new Set();
return r._getRangedEntries("conditionalSpatial", [h], { excludeHidden: l, fullyContained: c, onEntry: (d) => {
u.add(d.getModel());
} }), Array.from(u);
}), this._isDate1904 = t.date1904 ?? !1, this._options = t, this._emitter = new mt(this, this._transactions), this._entireRange = this.getRange(this._entireCoords), this._initState(), t?.container?.beforeFromJSON?.(this), t.json && this._fromJSON(t.json), n.commit({ forceAmend: this._ownTransactions, viewAfter: { initial: !0, skipProtectionCheck: !0 } });
} catch (o) {
throw n.rollback(), o;
}
this._initializing = !1;
}
_createRange(e, t, n = null) {
if (!e) return Cn(this, this._entireCoords);
if (this._validateCoords(e), this._closed) return Cn(null, this._entireCoords, e);
n === null && this._options.readonly && (n = "Readonly sheet");
let r = null;
return (t || n) && (r = { getOptions: t, readOnly: n }), new ls(((o) => {
if (!o) return null;
const s = { colStart: o.colIndex ?? o.colStart ?? 0, rowStart: o.rowIndex ?? o.rowStart ?? 0, colEnd: o.colIndex ?? o.colEnd ?? 0, rowEnd: o.rowIndex ?? o.rowEnd ?? 0 };
return (o.$colStart || o.$colIndex) && (s.$colStart = !0), (o.$colEnd || o.$colIndex) && (s.$colEnd = !0), (o.$rowStart || o.$rowIndex) && (s.$rowStart = !0), (o.$rowEnd || o.$rowIndex) && (s.$rowEnd = !0), s;
})(e), this, r);
}
_createRanges(e, t, n = null) {
let r = null;
return n === null && this._options.readonly && (n = "Readonly sheet"), (t || n) && (r = { getOptions: t, readOnly: n }), new as(e, this, r);
}
getRange(e, t) {
let n = !t && e && (e.rowStart !== void 0 || typeof e == "string");
if (n) {
if (typeof e == "string") {
if (this._lastRangeRead.address === e) return this._lastRangeRead.range;
} else if (e.rowStart !== void 0 && Po(e, this._lastRangeRead.address)) return this._lastRangeRead.range;
}
const r = this._rangesToCoords(e);
if (r.length > 1) throw new Error(Yg);
const o = this._createRange(r[0], t);
return n && (this._lastRangeRead.address = { ...e }, this._lastRangeRead.range = o), o;
}
getCell(e) {
const t = this.getRange(e);
if (t.size !== 1) throw new Error(eu);
return t.getCell();
}
getRanges(e, t) {
if (!e) throw new Error(Ur);
const n = this._rangesToCoords(e);
if (n.length === 0) throw this._createRangeError(e);
return this._createRanges(n, t);
}
getSelectedRange(e) {
const t = this.getSelection().getCoords();
if (!e && this._lastActiveRead.selection === t && this._lastActiveRead.range) return this._lastActiveRead.range;
const n = Lr(t), r = this.getRange(n[0]);
return e || (this._lastActiveRead.selection = t, this._lastActiveRead.range = r, this._lastActiveRead.ranges = this.getRanges(n)), r;
}
getSelectedRanges(e) {
const t = this.getSelection().getCoords();
if (!e && this._lastActiveRead.selection === t && this._lastActiveRead.ranges) return this._lastActiveRead.ranges;
const n = Lr(t), r = this.getRanges(n, e);
return e || (this._lastActiveRead.selection = t, this._lastActiveRead.ranges = r, this._lastActiveRead.range = this.getRange(n[0])), r;
}
getEntireRange(e) {
return e ? this.getRange(this._entireCoords, e) : this._entireRange;
}
getUsedRange(e) {
const t = this._getUsedCoords(), n = t ? this.getRange(t, e) : null;
return e || (this._lastUsedCoordsRead.coords = t, this._lastUsedCoordsRead.range = n), n;
}
_cellToCoords(e) {
if (this._lastCellDecoded.address === e) return this._lastCellDecoded.coords;
const t = this._rangeToCoords(e);
if (!t || !D.isSingleCell(t)) throw new Error(eu);
const n = { colIndex: t.colStart, rowIndex: t.rowStart };
return this._lastCellDecoded.address = e, this._lastCellDecoded.coords = n, n;
}
_validateCoords(e, t = Ai) {
if (!D.isRangeWithinRange(e, this._entireCoords)) throw new ze(t);
const n = e.colStart, r = e.rowStart, o = e.colEnd, s = e.rowEnd;
if (s < r || o < n) throw new Error(Qg);
if (!(Number.isInteger(n) && Number.isFinite(n) && Number.isInteger(r) && Number.isFinite(r) && Number.isInteger(o) && Number.isFinite(o) && Number.isInteger(s) && Number.isFinite(s))) throw new Error("Invalid range. All points must be valid integers.");
}
_createRangeError(e) {
return e ? new Error(Ur) : new Error(qo(e));
}
_protectionCheck(e = null, t = null, n = null) {
if (e && this._closed) return;
if (!this._initializing && this._options.readonly) throw new Error(((i = "update") => `Unable to ${i}, this sheet is readonly.`)(n));
t && !Array.isArray(t) && (t = [t]);
const r = e(t), o = this.getProtection();
if (o?.getProperties()) {
if (r.length === 0) throw new Error(bs);
if (r) {
const i = r.length;
for (let l = 0; l < i; l++)
if (o[r[l]] !== !0) throw new Error(P0());
}
}
}
_rangesToCoords(e, t = null, n = !0, r = !1) {
if (t && this._closed) return F.EmptyArray;
if (e == null) return F.EmptyArray;
const o = this, s = sc(e, this._entireCoords, r ? Pt : ss, (l) => {
if (n && typeof l == "string") {
const c = o.getNames()?.getByName(l);
if (c) return c.getRanges().getCoords();
const h = this._options.resolveRange?.(l);
if (h && h.getSheet() === o) return console.warn(hu), [h.getCoords()];
throw new Error(`Invalid sheet reference '${l}'.`);
}
}), i = s.length;
for (let l = 0; l < i; l++) {
const c = s[l];
if (c) {
if (r) {
const h = c.sheetName;
if (h && h !== this.getName()) throw new Error(hu);
}
this._validateCoords(c);
}
}
if (!t) return s;
if (s.length === 0) throw this._createRangeError(e);
return this._protectionCheck(t, s), s;
}
_rangeToCoords(e, t = null, n = !0) {
if (!e) throw new Error(Ur);
const r = t ? (s) => t(s) : void 0, o = this._rangesToCoords(e, r, n);
if (o.length === 0) throw new Error(qo(e));
return o[0];
}
_collectRanges(e, t = [], n = !0, r = this._getState(), o = !1) {
if (!n || Object.keys(n).length === 0) return;
const s = (l) => n === !0 || n[l] !== void 0, i = (l, c, h) => {
if (n !== !0 && n[l] === void 0) return;
const u = c.search(e, !1), d = u.length;
if (d === 0) return;
const g = n[l];
for (let m = 0; m < d; m++) {
const f = u[m];
if (g && !D.isRangeWithinRange(e, f)) continue;
const _ = D.intersectRanges(e, f);
let p = f.value;
p === void 0 && (p = !0), t.push({ ..._, value: { [h]: p } });
}
};
if (s(oe.Type.Merge) && r.mergeSpatial) {
const l = r.mergeSpatial.search(e), c = l.length;
for (let h = 0; h < c; h++) {
const u = l[h], d = o ? u : D.intersectRanges(e, u);
t.push({ ...d, value: { merge: u.value } });
}
}
if (i(oe.Type.Unlock, r.unlockSpatial, "unlock"), i(oe.Type.Contentful, r.contentfulSpatial, "contentful"), i(oe.Type.Continuous, r.continuousFillSpatial, "continuous"), i(oe.Type.Hyperlink, r.hyperlinkSpatial, "hyperlink"), i(oe.Type.Comments, r.commentsSpatial, "comments"), i(oe.Type.Style, r.directStyleSpatial, "directStyle"), i(oe.Type.Formula, r.formulaSpatial, "formula"), i(oe.Type.Pending, r.pendingSpatial, "pending"), i(oe.Type.CalcError, r.calcErrorsSpatial, "calcError"), i(oe.Type.Spill, r.spillSpatial, "spills"), s(oe.Type.Conditional) && r.conditionalSpatial) {
const l = r.conditionalSpatial.search(e), c = n[oe.Type.Conditional], h = l.length;
for (let u = 0; u < h; u++) {
const d = l[u], g = D.intersectRanges(e, d);
c && !g || t.push({ ...g, value: { conditionals: [d.value] } });
}
}
if (s(oe.Type.Table) && r.tableSpatial) {
const l = r.tableSpatial.search(e), c = n[oe.Type.Table], h = l.length;
for (let u = 0; u < h; u++) {
const d = l[u];
if (c && !D.isRangeWithinRange(e, d)) continue;
const g = D.intersectRanges(e, d);
t.push({ ...g, value: { table: d.value.model } });
}
}
}
_cellIterator(e) {
const t = this._cellOptions, n = this._strings, r = this._cellStateIterator(e);
return { next(o) {
const s = r.next(o);
if (s.done) return ke;
const i = s.value, l = new $a(n, e, t), c = l.context;
return { done: !1, value: { value: l.setState(i), context: c } };
}, [Symbol.iterator]() {
return this;
} };
}
_rangeStateIterator(e) {
const t = this._getState();
if (!t || !e || !e.includeRangeTypes) return Ze;
const n = e?.bounds ?? this._getUsedCoords() ?? this._entireCoords;
let r = null;
e.includeRangeTypes === !0 ? r = B0 : F.isObject(e.includeRangeTypes) && (r = e.includeRangeTypes);
const o = e?.excludeHidden, s = o === !0 || o === O.Orientation.Row, i = o === !0 || o === O.Orientation.Column, l = e?.includeMergeOverflow ?? !1, c = [], h = this, u = { includeHidden: !i }, d = { min: n.colStart, max: n.colEnd }, g = { includeHidden: !s }, m = { min: n.rowStart, max: n.rowEnd };
this._rowHeaders.getRange(m).forEachVisibleSpan((E, y) => {
this._colHeaders.getRange(d).forEachVisibleSpan((C, w) => {
h._collectRanges({ rowStart: E, rowEnd: y, colStart: C, colEnd: w }, c, r, t);
}, u);
}, g);
const f = new xi.IteratorInstance(c, e), _ = e?.reverse ?? !1, p = e?.byCell;
let S;
return { next: (E) => {
if (S = f.next(E), S.done) return ke;
const y = S.value, C = ((v) => {
if (!v) return null;
let R = null;
const A = v.length;
for (let M = 0; M < A; M++) {
const T = v[M].value;
if (!T) continue;
R || (R = { ...R });
const k = Object.keys(T), P = k.length;
for (let B = 0; B < P; B++) {
const H = k[B], z = R[H];
if (z) if (Array.isArray(z)) {
const W = T[H];
if (Array.isArray(W)) {
const L = W.length;
for (let j = 0; j < L; j++) z.push(W[j]);
} else z.push(W);
} else R[H] = [z, T[H]];
else R[H] = T[H];
}
}
return R;
})(y.overlaps);
let w, b = y.range;
if (l) {
const v = C?.merge;
if (v) {
const R = v.getCoords(), A = n.colStart, M = n.rowStart, T = R.colStart, k = R.rowStart;
T < A && M < k && (w = { colIndex: T, rowIndex: k });
}
}
w || (w = { colIndex: b.colStart, rowIndex: b.rowStart });
const x = { colIndex: b.colEnd, rowIndex: b.rowEnd };
let I = null;
return p && (I = { ...y.cell }), { done: !1, value: { start: _ ? x : w, end: _ ? w : x, cell: I, intersection: C } };
} };
}
_cellStateIterator(e) {
const t = this._getState();
if (!t) return Ze;
const n = e?.bounds ?? this._entireCoords, r = e?.orientation ?? O.Orientation.Row, o = e?.reverse ?? !1, s = e?.includeEmpty, i = { bounds: n, orientation: r, reverse: o };
let l;
s && (l = { bounds: n, orientation: r, reverse: o });
const c = e?.excludeHidden;
if (c === !0 || c === O.Orientation.Row) {
const A = ja(this._rowHeaders);
i.processRowSkip = uo(A), s && (l.processRowSkip = uo(A));
}
if (c === !0 || c === O.Orientation.Column) {
const A = ja(this._colHeaders);
i.processColumnSkip = uo(A), s && (l.processRowSkip = uo(A));
}
const h = s || !e?.ignoreEmptyIntersections;
let u = e.includeRangeTypes;
u === !0 && (u = Zg);
const d = e?.includeMergeOverflow ?? !1, g = this._getState().contentfulSpatial, m = u ? this._rangeStateIterator({ bounds: n, orientation: r, reverse: o, includeRangeTypes: u, includeMergeOverflow: d, excludeHidden: e.excludeHidden, byCell: !0 }) : Ze, f = t?.cellValuesGrid ?? null;
let _ = f ? f.entries(i) : Ze, p = _.next(), S = null, E = null, y = null;
p.done || (S = p.value[0], E = p.value[1]);
let C = m.next(), w = null;
const b = r !== O.Orientation.Row;
let x;
const I = D.createCellComparator(r, o);
let v;
if (!C.done) {
const A = C.value;
w = A.intersection, v = A.start;
}
x = (A) => {
let M = null, T = null, k = null, P = !1, B = !1;
if (S && v) {
const V = I(S, v);
V < 0 ? (M = S, T = E, P = !0) : V > 0 ? (M = v, k = w, B = !0) : (M = S, T = E, k = w, P = !0, B = !0);
} else if (S) M = S, T = E, P = !0;
else {
if (!v || !h) return ke;
M = v, k = w, B = !0;
}
if (P && (p = _.next(), p.done ? S = null : (S = p.value[0], E = p.value[1])), B) {
const V = h ? void 0 : S;
if (C = m.next(V), C.done) v = null, w = null;
else {
const $ = C.value;
w = $.intersection, v = $.cell;
}
}
let H = !1;
const z = M.rowIndex, W = M.colIndex;
b || (H = z === y?.rowIndex);
let L = !1;
b || (L = z === S?.rowIndex);
let j = null;
if (H) j = y;
else if (d && !y) {
De.rowStart = z, De.rowEnd = z, De.colStart = W - 5, De.colEnd = W - 1;
const V = g.search(De, !1);
if (V.length > 0) {
V.sort(D.columnFirstRangeComparator);
const $ = V[V.length - 1];
j = { colIndex: $.colStart, rowIndex: $.rowStart };
}
}
let G = null;
if (L) G = S;
else if (d && !S) {
De.colStart = W + 1, De.rowStart = z, De.colEnd = W + 5, De.rowEnd = z;
const V = g.search(De, !1);
if (V.length > 0) {
V.sort(D.columnFirstRangeComparator);
const $ = V[0];
G = { colIndex: $.colStart, rowIndex: $.rowStart };
}
}
return P && (y = M), { done: !1, value: [M, T, k, j, G] };
};
let R = { next: x, return: (A) => null, throw: (A) => null };
return s && (R = new Dg(R, i)), R;
}
_indexMerges(e, t = null) {
if (!(e && e.length !== 0 || t && t.length !== 0)) return;
const n = this._getState();
if (!n) return;
const r = this._beginCommit({ description: "indexMerges" }), o = n.mergeSpatial.clone();
if (t) {
const s = t.length;
for (let i = 0; i < s; i++) o.remove(t[i]);
}
if (e) {
const s = (c) => this._getState().cellValuesGrid.getValueAt(c.rowStart, c.colStart), i = [], l = e.length;
for (let c = 0; c < l; c++) {
const h = e[c];
i.push({ ...h, value: new Sd(h, s) });
}
o.load(i);
}
this._updateState({ mergeSpatial: o }), r.commit();
}
_updateStyles(e, t, n, r = !1) {
const o = n?.description ?? "Update Style";
this._protectionCheck(() => ["formatCells"], e, o);
const s = this._beginCommit({ description: o }), i = po(e);
try {
const l = this._getState();
if (!l) return F.EmptyArray;
const c = l.directStyleSpatial, h = s.getId(), u = c.clone(h);
let d = l.continuousFillSpatial;
const g = !d.isEmpty();
let m = null;
const f = this._styles, _ = e.length;
for (let p = 0; p < _; p++) {
const S = (x, I) => {
let v = null;
const R = qi(0, I, () => {
if (v) return v;
const A = x.getCoords();
return v = eo(f, x, A), v;
});
return x.cloneWithUpdate(R);
}, E = e[p], y = E.value, C = y !== void 0 ? y : t, w = S(new nt(f, E), C), b = (x, I) => {
if (r && x.value && x.value.getProperties()?.numberFormat) return x;
const v = D.sanitizeRange(x);
let R = null, A = x.value;
if (A || (A = new nt(f, v)), typeof C == "function") R = S(A, C);
else {
let T = I.value._p ?? null;
C !== null && (T = C), R = A.cloneWithUpdate(T);
}
R.isEmpty() && (R = null);
let M = !1;
if (R) {
const T = R._p?.alignment?.horizontal;
!T || T !== X.HorizontalAlignment.CenterContinuous && T !== X.HorizontalAlignment.Fill || (M = !0);
}
return (M || g) && (m || (m = []), m.push({ ...x, value: M ? R : null })), { ...I, value: R };
};
u.insertNonOverlapping({ ...E, value: w }, { onIntersect: b });
}
if (m) {
d = d.clone();
const p = m.length;
for (let S = 0; S < p; S++) {
const E = m[S];
d.insertNonOverlapping(E);
}
}
if (this._lastUsedCoordsRead.coords = null, this._updateState({ directStyleSpatial: u, continuousFillSpatial: d }), n?.autoFit) {
const p = typeof n.autoFit == "boolean" ? cl : n.autoFit;
this._autoFit(e, p);
}
this._emitter.notify("onStyleChange"), r ? this._commitAndAutoSelect(s, i, n?.autoSelect, { viewAfter: { ranges: e } }) : s.commit({ forceAmend: !0 });
} catch (l) {
throw s.rollback(), l;
}
}
_createIncrementalUpdater(e, t = null, n) {
const r = e?.orientation ?? O.Orientation.Row, o = e?.allowUnorderedWrites ?? !1, s = r === O.Orientation.Column, i = this._isDataColumn, l = s !== i, c = this;
let h, u, d, g = l ? new Oe.TransposedBuilder() : new Oe.Builder(), m = null;
if (t) {
const E = t.getCoords(), y = E.colStart, C = E.rowStart, w = E.colEnd, b = E.rowEnd;
m = (x, I) => {
if (x < C || x > b || I < y || I > w) throw new ze();
};
}
s ? (u = (E, y, C) => (m?.(E, y), g.addValue(y, E, C), h), d = (E, y, C) => (m?.(E, y + (C?.length ?? 0)), g.addValues(y, E, C), h)) : (u = (E, y, C) => (m?.(E, y), g.addValue(E, y, C), h), d = (E, y, C) => (m?.(E + (C?.length ?? 0), y), g.addValues(E, y, C), h));
const f = (E) => {
const y = g.build();
return y && c._updateTuples(y, E, null, n), t;
}, _ = o !== !1 ? D.createCellComparator(e?.orientation) : null, p = F.isObject(o) ? o : void 0;
let S = null;
return h = Object.freeze({ push: (E, y) => {
const C = c._cellToCoords(E);
return _ && (S && _(C, S) <= 0 && (f(p), g = l ? new Oe.TransposedBuilder() : new Oe.Builder()), S = C), u(s ? C.colIndex : C.rowIndex, s ? C.rowIndex : C.colIndex, y);
}, pushAt: u, pushMultipleAt: d, apply: f }), h;
}
_updateTuples(e, t, n = void 0, r = null) {
if (!e) return;
const o = r?.isCell ?? !1, s = r?.isHyperlink ?? !1, i = e.tuples, l = e.bounds, c = this._beginCommit({ description: t?.description ?? "Update Cells" });
let h = null;
const u = this._isDataColumn, d = u ? O.Orientation.Column : O.Orientation.Row, g = this.getProtection().isLocked(), m = this.getProtection().isFormatCellsAllowed(), f = this._strings, _ = l.majorStart, p = l.majorEnd, S = l.minorStart, E = l.minorEnd, y = { colStart: u ? _ : S, rowStart: u ? S : _, colEnd: u ? p : E, rowEnd: u ? E : p }, C = this;
(n = n ?? ((ae, Z) => {
C._validateCoords(ae, Z ?? Ai);
}))(y);
const w = { [oe.Type.Style]: !1, [oe.Type.Table]: !1 };
let b = !1;
g && this._hasRangedEntries("unlockSpatial", y) && (w[oe.Type.Unlock] = !1, b = !0), this._hasRangedEntries("mergeSpatial", y) && (w[oe.Type.Merge] = !1, b = !0);
const x = this._rangeStateIterator({ bounds: y, orientation: d, includeRangeTypes: w, reuseIterator: { done: !1, value: null } });
let I = x.next(), v = -1, R = -1, A = -1, M = -1, T = null;
if (!I.done) {
const ae = I.value, Z = ae.start, re = ae.end;
v = u ? Z.colIndex : Z.rowIndex, R = u ? re.colIndex : re.rowIndex, A = u ? Z.rowIndex : Z.colIndex, M = u ? re.rowIndex : re.colIndex, T = ae.intersection;
}
let k = (ae, Z) => {
do {
if (!T || ae <= A && Z < A) return null;
if (ae >= v && Z >= A && ae <= R && Z <= M) return T;
if (I = x.next(), I.done) T = null, k = null, b = !1;
else {
const re = I.value;
v = u ? re.start.colIndex : re.start.rowIndex, R = u ? re.end.colIndex : re.end.rowIndex, A = u ? re.start.rowIndex : re.start.colIndex, M = u ? re.end.rowIndex : re.end.colIndex, T = re.intersection;
}
} while (T);
return T;
};
const P = c.getState(this), B = P.cellValuesGrid.clone(), H = P.calcGraph.clone(), z = P.formulaSpatial.clone(), W = P.spillSpatial.clone(), L = P.pendingSpatial.clone(), j = P.calcErrorsSpatial.clone(), G = P.contentfulSpatial.clone(), V = Gn(u), $ = Gn(u, (ae, Z) => {
if (ae === Z) return Z;
}), J = Gn(u, (ae, Z) => {
if (ae === Z) return Z;
}), K = Gn(u, (ae, Z) => {
if (ae === Z) return Z;
}), he = [];
let le = null, pe = null;
if (t?.textParser !== !1) {
const ae = t && t.textParser !== !0 ? t.textParser : {};
pe = { ignoreQuotePrefix: !1, date1904: this._isDate1904, dateNF: !1, parse: null, ...ae }, le = new $a(f, null, this._cellOptions);
}
const ee = [], ne = this._cellOptions, ue = /* @__PURE__ */ new Map(), be = Bu, Q = (ae, Z, re) => {
const se = k?.(Z, re);
if (se?.merge) {
const de = se.merge.getCoords(), ye = u ? de.colStart : de.rowStart, we = u ? de.rowStart : de.colStart;
if (ye !== Z || we !== re) return;
}
if (o && ae && ae.isICell) {
const de = ae;
if (de.isTopLeft()) {
const ye = de.getSpans();
he.push({ colStart: u ? Z : re, rowStart: u ? re : Z, colEnd: (u ? Z : re) + ye.width - 1, rowEnd: (u ? re : Z) + ye.height - 1 });
}
}
let _e = zl(ae, ne, pe, ue);
if (_e === void 0) return;
const ve = _e.value;
if (_e.stringToParse) {
Io[0].colIndex = u ? Z : re, Io[0].rowIndex = u ? re : Z, Io[1] = ve, Io[2] = se, le.setState(Io);
const de = pe?.parse(_e.stringToParse, le.context), ye = zl(de, ne, pe, ue, !0);
if (le.clear(), ye === null) return ye;
ye !== void 0 && (_e = { ...ye });
}
if (g) {
if (g && (ae === null || _e.value !== void 0)) throw new Error(bs);
if (!m && _e.style !== void 0) throw new Error(bs);
}
if (!s) {
const de = _e.style;
de === void 0 || de === null && !o || $.append(Z, re, de);
const ye = _e.hyperlink;
ye === void 0 || ye === null && !o || J.append(Z, re, ye);
}
const ie = _e.formula;
return ie === void 0 || ie === null && !o || K.append(Z, re, ie), ve;
};
let fe = -1, ge = -1;
try {
const ae = i.length;
for (let me = 0; me < ae; me++) {
const Me = i[me], Ce = Me[0];
if (fe >= Ce) throw new Oe.OutOfOrderError(`Duplicate or out of order major indices: {${Ce}}.`);
if (fe = Ce, ge = Number.MIN_SAFE_INTEGER, Ce < _ || Ce > p) throw new ze("Provided major bounds is invalid");
const We = Me[1], et = [], tt = We.length;
for (let ot = 0; ot < tt; ot++) {
const Vt = We[ot], vt = Vt[1], st = vt.length;
let Ue = Vt[0], it = Ue;
if (ge > it) throw new Oe.OutOfOrderError(`Duplicate or out of order minor indices: {${it}}.`);
if (it < S || it + st > E + 1) throw new ze("Provided minor bounds is invalid");
let wt = [];
for (let pr = 0; pr < st; pr++) {
const ro = vt[pr];
let _r = null;
if (b || typeof ro != "number" ? (b || ro !== null || o) && (_r = Q(ro, Ce, it)) : _r = ro, _r == null) {
if (_r === null && V.append(Ce, it), wt.length > 0) {
const gc = be(wt, f);
et.push([Ue, gc]), wt = [];
}
Ue = it + 1;
} else wt.push(_r);
it++;
}
if (ge = it, wt.length > 0) {
const pr = be(wt, f);
et.push([Ue, pr]), wt = null;
}
}
et.length > 0 && ee.push([Ce, et]);
}
const Z = V.done(), re = Z.length;
for (let me = 0; me < re; me++) {
const Me = Z[me];
B.delete(Z[me]), G.insertNonOverlapping({ ...Me, value: null });
const Ce = H.delete(Me);
this._updateFormulaSpatial(z, null, Ce);
}
let se;
ee.length > 0 && (B.setValues(ee), se = { tuples: ee, bounds: l });
let _e, ve = K.done();
if (ve.length > 1 && (ve = yn(ve, O.Orientation.Column, 1)), se || ve.length > 0) {
const me = H.setInputs(se, ve);
_e = this._updateFormulaSpatial(z, me.inserts, me.removes, P.directStyleSpatial);
}
const ie = zu(ee, u), de = ie.length;
for (let me = 0; me < de; me++) G.insertNonOverlapping(ie[me]);
const ye = $.done();
ye.length > 0 && this._updateStyles(ye), he.length > 0 && this._merge(he);
const we = J.done();
if (we.length > 0 && this._setHyperlinks(we), this._updateState({ cellValuesGrid: B, contentfulSpatial: G, calcGraph: H, formulaSpatial: z, spillSpatial: W, pendingSpatial: L, calcErrorsSpatial: j }), _e && _e.length > 0 && this._updateStyles(_e, void 0, {}, !0), t?.autoFit) {
const me = typeof t.autoFit == "boolean" ? cl : t.autoFit;
this._autoFit([y], me);
}
h = { ranges: [y] }, this._addEvent("data", y), this._commitAndAutoSelect(c, h, t?.autoSelect, { viewAfter: { formulas: [y], ranges: [y] } });
} catch (ae) {
throw c.rollback(), ae;
}
}
_sort(e, t) {
typeof t == "boolean" && (t = { reverse: t });
const n = t?.description ?? "Sort " + (t?.reverse ? "Descending" : "Ascending");
this._protectionCheck(() => ["sort"], e, n);
let r = 1, o = 1, s = !1;
const i = this._getMerges([e]);
if (i.length > 0) {
s = !0;
let V = i[0];
if (r = V.colEnd - V.colStart + 1, o = V.rowEnd - V.rowStart + 1, (e.colEnd - e.colStart + 1) % r != 0 || (e.rowEnd - e.rowStart + 1) % o != 0) throw new Error(cu);
const $ = i.length;
for (let J = 1; J < $; J++) {
const K = i[J];
if (K.colEnd - K.colStart + 1 !== r || K.rowEnd - K.rowStart + 1 !== o) throw new Error(cu);
}
}
const l = t?.orientation ?? O.Orientation.Row, c = l === O.Orientation.Row;
let h = t?.offset ?? 0, u = e;
t?.hasHeader && (u = { ...u }, c ? u.rowStart += o : u.colStart += r, h = Math.max(h - 1, 0));
const d = { offset: h, reverse: t?.reverse ?? Vr.DefaultRangeOptions.reverse, collatorOptions: t?.collatorOptions ?? Vr.DefaultRangeOptions.collatorOptions }, g = c ? u.colStart : u.rowStart, m = c ? u.colEnd - u.colStart : u.rowEnd - u.rowStart, f = [];
if (t?.fields) {
const V = t?.fields.length ?? 0;
for (let $ = 0; $ < V; $++) {
let J = t.fields[$];
typeof J == "number" && (J = { offset: J }), f.push(J);
}
} else f.push(d);
const _ = f.length;
for (let V = 0; V < _; V++) {
const $ = f[V] = { ...d, ...f[V] };
if ($.offset < 0 || $.offset > m) throw new ze("The sort offset is outside of the bounds of the sort.");
$.offset += g;
}
const p = [];
let S = null, E = null, y = null, C = Number.MIN_SAFE_INTEGER;
f.sort((V, $) => V.offset - $.offset);
let w = null;
const b = t?.includeHidden ?? !1;
if (!b) {
const V = ja(c ? this._rowHeaders : this._colHeaders);
w = uo(V);
}
const x = this._cellIterator({ bounds: u, orientation: l, excludeHidden: !b && l, includeRangeTypes: { [oe.Type.Style]: !1, [oe.Type.Merge]: !1 } }), I = c ? o : r;
let v = (c ? u.rowStart : u.colStart) - I, R = x.next();
for (; !R.done; ) {
const V = R.value.context, $ = V.getCell();
if (s && !$.isTopLeft()) {
R = x.next();
continue;
}
const J = V.getCoords(), K = c ? J.rowIndex : J.colIndex, he = c ? J.colIndex : J.rowIndex;
if (v !== K) {
for (v += I, w && (v = w(v)); v < K; ) p.push(null), v += I;
E = [], y = [], S = { minorIndex: K, values: E, sortValues: y }, p.push(S), v = K, C = f[0].offset;
}
for (; he > C; ) {
const le = f[y.length];
C = le ? le.offset : Number.MAX_SAFE_INTEGER, he > C && y.push(null);
}
he === C && y.push($), E.push($), R = x.next();
}
if (!S || p.length === 0) return;
const A = /* @__PURE__ */ new Map(), M = /* @__PURE__ */ new Map(), T = t?.collators ?? Vr.DefaultCollators, k = T.length;
for (let V = 0; V < k; V++) A.set(T[V].type, T[V].compare), M.set(T[V].type, V);
let P = null, B = null, H = null;
p.sort((V, $) => {
const J = f.length;
for (let K = 0; K < J; K++) {
const he = f[K], le = V ? V.sortValues[K] : null, pe = $ ? $.sortValues[K] : null, ee = le ? le.getValue() : null, ne = pe ? pe.getValue() : null, ue = ee === null, be = ne === null;
if (ee === ne) continue;
if (ue && be) return 0;
if (!ue && be) return -1;
if (ue && !be) return 1;
const Q = le.getType(), fe = pe.getType();
let ge = 0;
if (Q !== fe) {
let ae = M.get(Q);
ge = M.get(fe) - ae;
} else {
let ae = B;
if (P !== Q) {
ae = A.get(Q), B = ae, P = Q;
let Z = M.get(fe);
H = { ...T[Z].defaultOptions, ...he.collatorOptions };
}
ge = ae(ee, ne, H);
}
return he.reverse && (ge *= -1), ge;
}
return 0;
});
const z = this._beginCommit({ description: n });
let W = [u];
b || (W = this._getVisible(W, { orientations: c ? O.Orientations.Row : O.Orientations.Column })), this._clear(W, void 0, void 0, !0);
const L = this._createIncrementalUpdater({ orientation: l });
let j = c ? u.rowStart : u.colStart;
const G = p.length;
for (let V = 0; V < G; V++) {
const $ = p[V];
if (w && (j = w(j)), $) {
const J = $.values, K = J.length;
for (let he = 0; he < K; he++) {
const le = J[he], pe = c ? j : le.getCoords().rowIndex, ee = c ? le.getCoords().colIndex : j;
L.pushAt(pe, ee, le);
}
}
j += I;
}
return L.apply(), z.commit(), u;
}
_autoFill(e, t, n) {
const { direction: r, amount: o } = ((f, _) => {
let p = O.Direction.Down, S = 0;
const E = { ...f };
if (_.colStart < f.colStart ? (p = O.Direction.Left, S = f.colStart - _.colStart, E.colStart = _.colStart) : _.colEnd > f.colEnd ? (p = O.Direction.Right, S = _.colEnd - f.colEnd, E.colEnd = _.colEnd) : _.rowStart < f.rowStart ? (p = O.Direction.Up, S = f.rowStart - _.rowStart, E.rowStart = _.rowStart) : _.rowEnd > f.rowEnd && (p = O.Direction.Down, S = _.rowEnd - f.rowEnd, E.rowEnd = _.rowEnd), !D.isEqualRanges(E, _)) throw new Error("Autofill destination must be the same as the range for 3 of the 4 edges.");
return { direction: p, amount: S };
})(e, t);
if (o <= 0) return !1;
const s = r === O.Direction.Up || r === O.Direction.Down, i = this.getSelection().getCoords(), l = [], c = n?.previewOnly, h = n?.contentsOnly, u = n?.filler ?? vi.Types.Series, d = { ...n?.fillerOptions };
let g = null, m = null;
try {
const f = { ...e };
let _ = { ...e };
const p = [e], S = this._getMerges(p);
if (S.length > 0 && !D.isRangeWithinRange(D.unionRangesArrays(S), e)) throw new Error(lu);
const E = { ..._ };
let y = 1;
if (r === O.Direction.Left) f.colStart = _.colStart = e.colStart - o, f.colEnd = e.colStart - 1, y = S.length === 0 ? y : e.colEnd + 1 - e.colStart, E.rowStart = E.rowEnd;
else if (r === O.Direction.Right) f.colEnd = _.colEnd = e.colEnd + o, f.colStart = e.colEnd + 1, y = S.length === 0 ? y : e.colEnd + 1 - e.colStart, E.rowStart = E.rowEnd;
else if (r === O.Direction.Up) f.rowStart = _.rowStart = e.rowStart - o, f.rowEnd = e.rowStart - 1, y = S.length === 0 ? y : e.rowEnd + 1 - e.rowStart, E.colStart = E.colEnd;
else {
if (r !== O.Direction.Down) throw new Error(Lm.MESSAGE_ERROR_INVALID_ARG(r));
f.rowEnd = _.rowEnd = e.rowEnd + o, f.rowStart = e.rowEnd + 1, y = S.length === 0 ? y : e.rowEnd + 1 - e.rowStart, E.colStart = E.colEnd;
}
if (o % y !== 0) throw new Error(((Q) => `When filling with merged cells the amount to fill must be a multiple of the input range [${Q}].`)(y));
const C = s ? "rowIndex" : "colIndex", w = s ? "colIndex" : "rowIndex", b = s ? e.rowEnd + 1 - e.rowStart : e.colEnd + 1 - e.colStart, x = s ? e.rowStart : e.colStart, I = s ? e.rowEnd : e.colEnd, v = s ? t.rowStart : t.colStart, R = s ? t.rowEnd : t.colEnd, A = s ? r === O.Direction.Down : r === O.Direction.Right;
A || (d.reverse = !0);
const M = A ? I + 1 : v, T = (A ? R : x - 1) - M + 1, k = s ? e.colEnd : e.rowEnd;
l.push(D.unionRanges(f, e));
const P = [];
let B = null;
c || (g = this._beginCommit({ description: "Auto Fill", operation: { name: "autoFill", params: [e, t, n] } }));
const H = this._cellIterator({ bounds: c ? E : e, reverse: !A, orientation: s ? O.Orientation.Column : O.Orientation.Row, includeRangeTypes: { [oe.Type.Style]: !1 } });
let z = H.next();
for (; !z.done; ) {
const Q = z.value.context, fe = Q.getCell(), ge = Q.getCoords();
B?.oppositeIndex !== ge[w] && (B = { oppositeIndex: ge[w], lastIndex: A ? x - 1 : I + 1, values: [] }, P.push(B));
const ae = ge[C];
if (A) for (let re = B.lastIndex + 1; re < ae; re++) B.values.push(null);
else for (let re = B.lastIndex - 1; re > ae; re--) B.values.push(null);
B.lastIndex = ae;
const Z = fe.toDate();
if (Z) B.values.push(Z);
else {
let re = fe.getValue();
B.values.push(re);
}
z = H.next();
}
const W = P.length;
for (let Q = 0; Q < W; Q++) {
const fe = P[Q].values;
for (let ge = fe.length; ge < b; ge++) fe.push(null);
}
const L = (Q, fe) => {
if (Q.canFill(fe[0], [])) {
const ge = Q.createFillAt(fe, d);
if (ge) return ge;
}
return vi.Types.Copy.createFillAt(fe);
}, j = this;
if (c) {
const Q = P[P.length - 1];
if (P[P.length - 1]?.oppositeIndex !== k) return null;
const fe = L(u, Q.values);
return c((ge) => {
const ae = j._rangeToCoords(ge);
let Z;
r === O.Direction.Down || r === O.Direction.Right ? Z = { rowIndex: ae.rowEnd, colIndex: ae.colEnd } : r === O.Direction.Left ? Z = { rowIndex: ae.rowEnd, colIndex: ae.colStart } : r === O.Direction.Up && (Z = { rowIndex: ae.rowStart, colIndex: ae.colEnd });
const re = s ? Z.rowIndex : Z.colIndex, se = { value: fe(A ? re - x : x - re + b - 1) };
let _e = null;
return _e = h ? this.createTemporaryCell(se, Z) : this.createTemporaryCell(null, Z).createTemporaryCell(se), _e;
}), !1;
}
const G = this._createIncrementalUpdater({ orientation: s ? O.Orientation.Column : O.Orientation.Row }), V = P.length;
P.sort((Q, fe) => Q.oppositeIndex - fe.oppositeIndex);
for (let Q = 0; Q < V; Q++) {
const fe = Q, ge = L(u, P[fe].values), ae = P[fe].oppositeIndex, Z = A ? b : b + T - 1, re = this.isDate1904();
for (let se = 0; se < T; se++) {
let _e = ge(Z + (A ? se : -se));
to(_e) && (_e = es(_e, re));
const ve = M + se;
s ? G.pushAt(ve, ae, _e) : G.pushAt(ae, ve, _e);
}
}
this._clear([f], n?.contentsOnly ? Te.Content.Formats : void 0), G.apply();
const $ = this._getMerges([_]), J = D.unionRangesArrays($);
if ($.length > 0 && !D.isRangeWithinRange(J, _)) throw new Error(lu);
if ($.length > 0) {
const Q = [], fe = o / y;
if (s) {
const ge = e.rowEnd - e.rowStart + 1, ae = r === O.Direction.Up ? f.rowStart : e.rowEnd + 1, Z = $.length;
for (let re = 0; re < Z; re++) {
const se = $[re], _e = se.rowStart - e.rowStart, ve = se.rowEnd - se.rowStart + 1;
for (let ie = 0; ie < fe; ie++) {
const de = ie * ge;
Q.push({ colStart: se.colStart, rowStart: ae + de + _e, colEnd: se.colEnd, rowEnd: ae + de + _e + ve - 1 });
}
}
} else {
const ge = e.colEnd - e.colStart + 1, ae = r === O.Direction.Left ? f.colStart : e.colEnd + 1, Z = $.length;
for (let re = 0; re < Z; re++) {
const se = $[re], _e = se.colStart - e.colStart, ve = se.colEnd - se.colStart + 1;
for (let ie = 0; ie < fe; ie++) {
const de = ie * ge;
Q.push({ colStart: ae + de + _e, rowStart: se.rowStart, colEnd: ae + de + _e + ve - 1, rowEnd: se.rowEnd });
}
}
}
this._merge(Q);
}
const K = this._getState(), he = {}, le = {};
le.directStyleSpatial = K.directStyleSpatial, le.continuousFillSpatial = K.continuousFillSpatial;
let pe = e, ee = f;
if (!A) {
let Q = (s ? _.rowEnd + 1 - _.rowStart : _.colEnd + 1 - _.colStart) % b;
const fe = s ? "rowStart" : "colStart", ge = s ? "rowEnd" : "colEnd";
Q !== 0 && (ee = { ...f, [ge]: Math.min(f[ge], f[fe] + Q) }, pe = { ...e, [fe]: e[ge] - Q + 1 }, f[fe] = f[fe] + Q);
}
const ne = Object.keys(le), ue = ne.length;
for (let Q = 0; Q < ue; Q++) {
const fe = ne[Q], ge = le[fe].createCopiedEntries(pe, ee), ae = K[fe].clone(), Z = ge.removes, re = Z.length;
for (let se = 0; se < re; se++) ae.remove(Z[se]);
ae.load(ge.inserts), he[fe] = ae;
}
if (A) {
const Q = this.getTables().getItems({ address: { rowIndex: e.rowEnd, colIndex: e.colEnd } });
if (Q.length === 1) {
const fe = Q[0], ge = fe.getRange().getCoords();
fe.resize({ colStart: ge.colStart, rowStart: ge.rowStart, colEnd: s ? ge.colEnd : f.colEnd, rowEnd: s ? f.rowEnd : ge.rowEnd });
}
}
const be = K.calcGraph.clone();
be.autoFill(e, f), he.calcGraph = be, this._updateState(he), m = { ...i, ranges: l }, g.commit({ viewBefore: { view: this.getView(), selection: Pe([e]), selectOptions: n?.autoSelect }, viewAfter: { view: this.getView(), selection: m, selectOptions: n?.autoSelect } }), this._autoSelect(n?.autoSelect ?? !1, m);
} catch (f) {
throw g?.rollback(), f;
}
return !0;
}
_setHyperlinks(e, t, n) {
const r = n?.description ?? "Set Hyperlink";
this._protectionCheck(() => ["insertHyperlinks", "formatCells"], e, r);
const o = Pe(e), s = this._beginCommit({ description: r });
let i = null;
try {
const l = this._getState();
if (!l) return F.EmptyArray;
const c = l.hyperlinkSpatial;
let h = c, u = l.directStyleSpatial.clone();
const d = e.length;
for (let g = 0; g < d; g++) {
const m = e[g];
let f = null;
const _ = m.value, p = _ !== void 0 ? _ : t;
let S;
if (p !== null) {
if (p.isIHyperlink) S = { ...p._j }, f = p.getDisplayText();
else if (typeof p == "string") S = { address: p }, f = p;
else if (p.address) {
const E = p, y = { ...E };
delete y.displayText, S = y, f = E.displayText ?? E.address;
}
} else S = null;
if (i = D.unionRanges(i, m), c === h && (h = c.clone()), S !== null || c.size() > 0) {
if (f && t) {
const E = this._createIncrementalUpdater({ orientation: O.Orientation.Column }, void 0, { isHyperlink: !0 });
for (let y = m.colStart; y <= m.colEnd; y++) for (let C = m.rowStart; C <= m.rowEnd; C++) E.pushAt(C, y, f);
E.apply();
}
if (S === null) this._getRangedEntries("hyperlinkSpatial", [m], { onEntry: (E, y) => (h.insertNonOverlapping({ ...y, value: S }), y.value) });
else {
h.insertNonOverlapping({ ...m, value: S });
const E = this._styles, y = (C) => {
const w = C.value ?? new nt(E, D.sanitizeRange(C));
let b = { ...w.getPropertiesAt(0, 0, null) };
if (b.named) {
const x = E.getNamed(b.named)?.getRanged().getPropertiesAt(0, 0, null);
b = F.mergeContentful(x, b);
}
return delete b.font, b.named = ce.BuiltInName.Hyperlink, { ...C, value: w.cloneWithUpdate(b) };
};
u.insertNonOverlapping({ ...m, value: null }, { onIntersect: y });
}
}
}
this._lastUsedCoordsRead.coords = null, this._updateState({ hyperlinkSpatial: h, directStyleSpatial: u }), this._commitAndAutoSelect(s, o, n?.autoSelect, { viewAfter: { ranges: e } });
} catch (l) {
throw s.rollback(), l;
}
}
_updateFormulaSpatial(e, t, n, r) {
if (n) {
const s = n.length;
for (let i = 0; i < s; i++) {
const l = n[i];
e.remove(l);
}
}
let o;
if (t) {
const s = [], i = t.length;
for (let l = 0; l < i; l++) {
const c = t[l], h = D.sanitizeRange(c), u = new mw(h, c.value.tokens, c.value.references);
if (s.push({ colStart: h.colStart, rowStart: h.rowStart, colEnd: h.colEnd, rowEnd: h.rowEnd, value: u }), !r) continue;
const d = c.value.precedents;
let g, m, f = !1;
const _ = d.length;
for (let p = 0; !f && p < _; p++) {
const S = d[p], E = S.colStart;
if (S.colStart === void 0) continue;
const y = S.rowStart;
Gt.colStart = E, Gt.rowStart = y, Gt.colEnd = E, Gt.rowEnd = y;
const C = r.search(Gt)[0];
if (C) {
const w = C.value.getPropertiesAt(y, E, null), b = w?.numberFormat;
if (b) if (g) {
m || (m = Nt.Styles.lookupStyle(g)?.formatType);
const x = Nt.Styles.lookupStyle(b)?.formatType;
tp(x, m) > 0 ? (m = x, g = b) : f = !0;
} else g = b;
}
}
g && (o || (o = []), o.push({ colStart: h.colStart, rowStart: h.rowStart, colEnd: h.colEnd, rowEnd: h.rowEnd, value: { numberFormat: g } }));
}
e.load(s);
}
return o;
}
_realizeCalcedValues(e) {
if (!e) return;
const t = this._getState();
if (!t) return;
const n = e.valueInserts, r = e.spillRemoves, o = e.errorRemoves, s = t.cellValuesGrid, i = this._beginCommit();
e.isFull && (t.calcErrorsSpatial.clear(), t.spillSpatial.clear(), t.pendingSpatial.clear());
const l = e.valueRemoves;
if (l) {
const m = t.contentfulSpatial, f = l.length;
for (let _ = 0; _ < f; _++) {
const p = l[_];
s.delete(p), m.insertNonOverlapping({ ...p, value: null });
}
}
if (r) {
const m = t.spillSpatial, f = r.length;
for (let _ = 0; _ < f; _++) {
const p = r[_];
m.remove(p);
}
}
if (o) {
const m = t.calcErrorsSpatial, f = o.length;
for (let _ = 0; _ < f; _++) {
const p = o[_];
m.remove(p);
}
}
this._updateFormulaSpatial(t.formulaSpatial, e.formulaInserts, e.formulaRemoves);
const c = e.formatInserts;
if (c) {
const m = c.length;
for (let f = 0; f < m; f++) {
const _ = c[f], p = { numberFormat: _.value };
_.value = p;
}
this._updateStyles(c, void 0, { autoFit: !0 }, !0);
}
if (n) {
const m = n.tuples;
s.setValues(m);
const f = this._isDataColumn, _ = f ? O.Orientation.Column : O.Orientation.Row, p = t.contentfulSpatial, S = m.length;
for (let E = 0; E < S; E++) {
const y = m[E], C = y[0], w = y[1], b = w.length;
for (let x = 0; x < b; x++) {
const I = w[x], v = I[0], R = v + I[1].length - 1, A = { colStart: f ? C : v, rowStart: f ? v : C, colEnd: f ? C : R, rowEnd: f ? R : C };
p.insertNonOverlapping({ colStart: A.colStart, rowStart: A.rowStart, colEnd: A.colEnd, rowEnd: A.rowEnd, value: new qt(A, _) });
}
}
}
const h = e.spillInserts;
if (h) {
const m = h.length;
for (let f = 0; f < m; f++) {
const _ = h[f], p = _.value;
_.value = new hr(D.sanitizeRange(_), 0, p);
}
t.spillSpatial.load(h);
}
const u = e.pendingUpdates;
if (u) {
const m = t.pendingSpatial, f = u.length;
for (let _ = 0; _ < f; _++) {
const p = u[_];
p.value === !1 && (p.value = null), m.insertNonOverlapping(p);
}
}
const d = e.errorInserts;
d && t.calcErrorsSpatial.load(d);
const g = e.formulaInserts;
if (g) {
const m = yn(g);
this._autoFit(m, cl);
}
if (i.commit({ forceAmend: !0, viewAfter: { calculationSideEffect: !0 } }), (e.bounds || e.isFull) && !this._initializing) {
const m = this._rangesListenerMap;
if (m.size > 0) {
const f = { isDataChange: !0, isTransactional: !1, timeStamp: Date.now(), isUndo: !1, trigger: "calc" };
this._notifyRangeListeners(this._rangeListenerSpatial, m, [e.bounds ?? this._entireCoords], f);
}
(h || r) && this._emitter.notify("onSpillsChange");
}
}
_calculate(e, t) {
const n = this._getState().calcGraph;
n.invalidate(e), n.calculate(t);
}
_calculateFull() {
this._initializing || F.debounce(() => {
this._getState()?.calcGraph.calculate({ full: !0 });
}, 100)();
}
_setComments(e, t, n) {
const r = n?.description ?? "Set Comments", o = Pe(e), s = this._beginCommit({ description: r });
let i = null;
try {
const l = this._getState();
if (!l) return F.EmptyArray;
const c = l.commentsSpatial;
let h = c;
const u = e.length;
for (let d = 0; d < u; d++) {
const g = e[d];
let m = null;
if (t !== null) {
let f = t;
if (!f) continue;
m = typeof f == "string" ? { content: { runs: { text: f } } } : { ...f };
}
i = D.unionRanges(i, g), c === h && (h = c.clone()), h.insertNonOverlapping({ ...g, value: m });
}
this._lastUsedCoordsRead.coords = null, this._updateState({ commentsSpatial: h }), this._commitAndAutoSelect(s, o, n?.autoSelect, { viewAfter: { ranges: e } });
} catch (l) {
throw s.rollback(), l;
}
}
_clear(e, t = null, n, r = !1, o = !1) {
let s = null, i = "Clear", l = !1, c = !1, h = !1, u = !1;
t === Te.Content.Formulas ? (i = `${i} Formulas`, u = !0) : t === Te.Content.Values ? (i = `${i} Values`, u = !0) : t === Te.Content.Formats ? (i = `${i} Formats`, l = !0, s = ["formatCells"]) : t === Te.Content.Comments ? (i = `${i} Comments`, h = !0) : t === Te.Content.Hyperlinks ? (i = `${i} Hyperlinks`, c = !0, s = ["formatCells"]) : (s = [], i = `${i} All`, u = !0, l = !0, c = !0, h = !0), s !== null && this._protectionCheck(() => s, e, n?.description ?? i);
const d = Pe(e), g = this._beginCommit({ description: n?.description ?? i });
let m = this._getState(), f = m.cellValuesGrid, _ = m.calcGraph, p = m.contentfulSpatial, S = m.formulaSpatial, E = m.spillSpatial, y = m.pendingSpatial, C = m.calcErrorsSpatial, w = m.rangesListenerSpatial2;
u && (f = f.clone(), _ = _.clone(), p = p.clone(), S = S.clone(), E = E.clone(), y = y.clone(), C = C.clone());
try {
if (c && this._setHyperlinks(e, null), h && this._setComments(e, null), l && (this._updateStyles(e, null), r || this._unmerge(e)), l || u) {
fi(0, e, [], p, E, f);
const b = e.length;
for (let x = 0; x < b; x++) {
const I = e[x];
if (u) {
f.delete(I);
const A = { ...I, value: null };
p.insertNonOverlapping(A);
const M = _.delete(I);
this._updateFormulaSpatial(S, null, M);
}
const v = this.getTables().getItems({ address: I }), R = v.length;
for (let A = 0; A < R; A++) {
const M = v[A];
D.isRangeWithinRange(M.getAnchorCoords(), I) && (t === Te.Content.Formats ? M.updateStyleOptions({ name: null }) : M.delete());
}
if (l) {
let A = m.conditionalSpatial;
A.size() > 0 && (A = A.clone(g.getId()), A.insertNonOverlapping({ ...I, value: null }, { noMerge: !0 }), m = this._updateState({ conditionalSpatial: A }));
}
if (o) {
const A = w.search(I), M = A.length;
for (let T = 0; T < M; T++) {
const k = A[T];
D.isRangeWithinRange(k, I) && (w === m.rangesListenerSpatial2 && (w = w.clone()), console.log("cut and move listener"), w.remove(k));
}
}
}
}
this._updateState({ cellValuesGrid: f, calcGraph: _, contentfulSpatial: p, formulaSpatial: S, spillSpatial: E, pendingSpatial: y, calcErrorsSpatial: C, rangesListenerSpatial2: w }), this._commitAndAutoSelect(g, d, n?.autoSelect, { viewAfter: { ranges: e } });
} catch (b) {
throw g.rollback(), b;
}
}
_merge(e, t = null) {
if (this._protectionCheck(Id, e), e.length === 1 && D.isSingleCell(e[0])) return;
let n = O.Orientations.Both;
t?.orientations ? n = t?.orientations : t === O.Orientations.Row ? n = O.Orientations.Row : t === O.Orientations.Column && (n = O.Orientations.Column);
const r = t?.discardMultipleValues ?? !1;
let o = Pe(e);
const s = this.getSelection().getCoords();
let i = null;
const l = this._beginCommit({ description: t?.description ?? "Merge" });
let c = e[0];
try {
const h = this._getMerges(e);
if (zo(e) || h.length > 0) {
const m = D.unionRangesArrays(h), f = D.unionRangesArrays(e);
if (!(!m && !f || m && f && D.isRangeWithinRange(m, f))) throw console.warn(au, e), new Error(au);
this._unmerge(h);
}
const u = this._createIncrementalUpdater({ orientation: O.Orientation.Column }), d = [], g = [];
try {
const m = this._entireCoords, f = this._getState().contentfulSpatial, _ = this._getState().directStyleSpatial;
let p = !1;
const S = (C) => {
const w = { rowIndex: C.rowStart, colIndex: C.colStart };
let b = null;
if (p) {
let P = 0;
const B = f.search(C), H = B.length;
for (let z = 0; z < H; z++) {
const W = D.intersectRanges(B[z], C);
if (W && (P += (W.rowEnd - W.rowStart + 1) * (W.colEnd - W.colStart + 1)), P > 1) throw new mc("Merging cells would cause some values to be discarded. Use 'discardMultipleValues' option if desired.", "discardMultipleValues");
}
}
b || (b = w);
let x = null, I = null, v = null, R = null, A = null, M = null, T = null;
De.colStart = C.colStart, De.rowStart = C.rowStart, De.colEnd = C.colStart, De.rowEnd = C.rowStart;
let k = _.search(De);
if (k.length > 0) {
T = k[0].value?.getPropertiesAt(C.rowStart, C.colEnd, null);
const B = T?.border;
x = B?.left ?? null, I = B?.top ?? null, A = B?.right ?? null, M = B?.bottom ?? null;
}
if (De.colStart = C.colEnd, De.colEnd = C.colEnd, k = _.search(De), k.length > 0) {
const P = k[0], B = P.value?.getPropertiesAt(C.rowStart, C.colEnd, null)?.border;
B && B.right && (v = B.right);
}
if (De.colStart = C.colStart, De.colEnd = C.colStart, De.rowStart = C.rowEnd, De.rowEnd = C.rowEnd, k = _.search(De), k.length > 0) {
const P = k[0], B = P.value?.getPropertiesAt(C.rowEnd, C.colStart, null)?.border;
B && B.bottom && (R = B.bottom);
}
if (!v || !R) {
De.colStart = C.colEnd, De.colEnd = C.colEnd, De.rowStart = C.rowEnd, De.rowEnd = C.rowEnd, k = _.search(De);
const P = k?.[0];
if (P) {
const B = P.value?.getPropertiesAt(C.rowEnd, C.colEnd, null)?.border;
B && (v || (v = B.right ?? null), R || (R = B.bottom ?? null));
}
}
d.push({ ...C, value: null }), d.push({ ...C, value: { ...T, border: { top: I, left: x, right: v ?? A, bottom: R ?? M, horizontal: null, vertical: null } } }), D.isEqualCells(b, w) || u.pushAt(b.rowIndex, b.colIndex, null), g.push(C), c = D.unionRanges(c, C);
}, E = [...e].sort(D.createRangeComparator(O.Orientation.Column)), y = E.length;
for (let C = 0; C < y; C++) {
const w = E[C];
if (!D.isSingleCell(w)) {
if (i || !s || !D.isCellWithinRange(s.cell, w) || s.cell.rowIndex === w.rowStart && s.cell.colIndex === w.colStart || (i = { ...o, cell: { rowIndex: w.rowStart, colIndex: w.colStart } }), !r && (p = f.search(w).length > 0), this._validateOrRemoveOverlaps(w, "merge"), w.colStart < m.colStart || w.rowStart < m.rowStart || w.colEnd > m.colEnd || w.rowEnd > m.rowEnd) throw new Error("We can't merge outside of the maximum cell location.");
if (n === O.Orientations.Column) {
const b = w.rowEnd !== m.rowEnd ? w.rowEnd : Math.max(1, m.rowEnd);
for (let x = w.rowStart; x <= b; x++) S({ ...w, rowStart: x, rowEnd: x });
} else if (n === O.Orientations.Row) {
const b = w.colEnd !== m.colEnd ? w.colEnd : Math.max(1, m.colEnd);
for (let x = w.colStart; x <= b; x++) S({ ...w, colStart: x, colEnd: x });
} else S(w);
}
}
u.apply(), this._indexMerges(g), this._updateStyles(d), this._updateState({});
} catch (m) {
throw m.type ? new mc(m.message ?? "Unable to merge", m.type) : new Error(m.message ?? "Unable to merge");
}
i && (o = i, this.getSelection().updateCoords(i)), l.commit({ viewAfter: { view: this.getView(), selection: o, merges: e, ranges: e, selectOptions: t?.autoSelect } }), this._autoSelect(t?.autoSelect ?? !1, o);
} catch (h) {
throw l.rollback(), h;
}
}
_unmerge(e, t) {
if (this._protectionCheck(Id, e), zo(e)) throw new Error("We can't unmerge intersecting ranges.");
if (!this._getState()) return null;
const n = D.unionRangesArrays(e), r = Pe(e), o = this._beginCommit({ description: t?.description ?? "Unmerge" }), s = o.getState(this).mergeSpatial, i = [];
try {
const l = e.length;
for (let c = 0; c < l; c++) {
const h = e[c], u = s.search(h), d = u.length;
for (let g = 0; g < d; g++) {
const m = u[g];
if (!D.isSingleCell(h) && !D.isRangeWithinRange(m, n)) throw new Error("We can't unmerge partial cells.");
i.push(m);
}
}
if (i.length === 0) return o.rollback(), null;
this._indexMerges(null, i), this._commitAndAutoSelect(o, r, t?.autoSelect, { viewAfter: { merges: e, ranges: e } });
} catch (l) {
throw o.rollback(), l;
}
}
_getMerges(e, t = !1) {
return e.length === 0 ? F.EmptyArray : this._getRangedEntries("mergeSpatial", e, { excludeHidden: t, fullyContained: !1, onEntry: (n) => n.getCoords() });
}
_clone() {
const e = { ...this._options, container: null };
this._ownStyles && (e.styles = this._styles), this._ownStrings && (e.strings = this._strings), this._ownResources && (e.resources = this._resources), this._ownNames && (e.names = this._names), this._ownsCalculation && (e.calculation = this._calculation), e.transactions = new Xt({ transient: !0 });
const t = new Zo(e), n = this._transactions.getState(this);
t._updateState(n);
const r = new ll({ sheet: this, json: this.getView().toJSON() });
return r.selectMovables(this.getView().getMovableSelection()), t.setView(r), t;
}
_getSnapshot(e, t) {
if (e.length === 0) return F.EmptyArray;
const n = this._getState();
if (!n) return null;
t = Object.freeze({ ...t });
const r = this._clone();
r.isMarked = !0;
const o = this, s = o.getView(), i = "Range", l = [], c = ((p, S, E, y) => {
const C = [];
let w = null, b = null;
const x = E && E.length > 0;
if (x) {
const v = E.length;
for (let R = 0; R < v; R++) {
const A = E[R].getSnapshot?.(y);
A && (C.push(A), w = pl(A.getCoords(), w));
}
} else if (S) {
const v = S.length;
for (let R = 0; R < v; R++) {
const A = S[R], M = p.getMovables().getItems({ excludeHidden: !1, fullyContained: !0, address: A }), T = M.length;
for (let k = 0; k < T; k++) {
const P = M[k].getSnapshot?.(y);
P && (C.push(P), w = pl(p.getRange(A).getBounds(), w), b = D.unionRanges(b, A));
}
}
}
if (C.length === 0) return null;
const I = () => y.description ?? (C?.length === 1 ? Xr(C[0]?.getName()) : "Drawings");
return { copyTo: async (v, R) => {
const A = { ...y, ...R }, M = v.getSheet(), T = M.getView(), k = T.getMovableSelection(), P = v.getCoords(), B = A?.isCut ?? !1, H = T.getMovableSelection();
T.selectMovables([]);
const z = M.beginCommit(A.description ?? `${B ? "Cut" : "Copy"} ${I()}`);
try {
let W = 0, L = 0;
if (H.length > 0 && C.length > 0) {
let V = Number.MAX_SAFE_INTEGER, $ = Number.MAX_SAFE_INTEGER;
for (let ne = 0; ne < k.length; ne++) {
const ue = k[ne].getBounds();
V = Math.min(ue.x, V), $ = Math.min(ue.y, $);
}
let J = Number.MAX_SAFE_INTEGER, K = Number.MAX_SAFE_INTEGER;
const he = C.length;
for (let ne = 0; ne < he; ne++) {
const ue = C[ne].getCoords();
J = Math.min(ue.x, J), K = Math.min(ue.y, K);
}
W = V - J, L = $ - K;
const le = C[0].getCoords(), pe = { ...le, x: le.x + W, y: le.y + L }, ee = dd(M.getMovables(), pe);
W += ee.x, L += ee.y;
} else if (w) {
const V = M.getRange(P).getBounds();
W = V.x - w.x, L = V.y - w.y;
}
const j = [], G = C.length;
for (let V = 0; V < G; V++) {
const $ = C[V], J = $.getCoords(), K = { ...J, x: J.x + W, y: J.y + L };
j.push($.copyTo({ movables: M.getMovables(), bounds: K }, { autoSelect: { addToSelection: !0 }, ...A }));
}
await Promise.all(j), z?.updateState(M, (V) => V), z.commit({ viewBefore: (V) => ({ ...V, view: p.getView(), movableSelection: H }) });
} catch (W) {
throw z.rollback(), W;
}
return null;
}, getName: I, getCoords: () => b, getMarkOptions: () => y, toText: () => x ? C[0].toText?.() ?? null : null, toHtml: () => x ? C[0].toHtml?.() ?? null : null, toImage: () => x ? C[0].toImage?.() ?? null : null, getSource: () => p, isISnapshot: !0 };
})(r, e, s.getMovableSelection(), t);
if (c) {
if (s.getMovableSelection().length > 0) return c;
l.push(c);
}
if (e.length > 1) throw new Error(du);
const h = { singleMerge: null };
l.push({ copyTo(p, S) {
const E = { ...t, ...S };
let y = null;
if (!E.skipBlanks) {
const w = p.getSheet(), b = p.getCoords(), x = li(b, e[0], E?.fitDestination, E?.transpose);
y = w.getRange(x);
let I = !1;
const v = y.getMerges();
if (v.length === 1 && D.isEqualRanges(v[0], b)) if (D.isSingleCell(e[0])) I = !0;
else {
const R = (C = _) ? { colIndex: C.colStart, rowIndex: C.rowStart } : null;
r._getMerges([D.cellToRange(R)]).length === 1 && (I = !0);
}
return I ? (h.singleMerge = b, y.clear(E.type ?? Te.Content.Values)) : y.clear(E.type), x;
}
var C;
} });
const u = r._entireCoords, d = e.length;
for (let p = 0; p < d; p++) {
const S = e[p], E = n.rangeListenerSpatial.search(S, !1), y = n.rangesListenerMap;
l.push({ async copyTo(C, w) {
if (!w.isCut) return;
const b = /* @__PURE__ */ new Set(), x = E.length;
for (let I = 0; I < x; I++) {
const v = E[I].value, R = v.id;
if (b.has(R)) continue;
const A = y.get(R);
if (b.add(R), A.ranges[v.offset] === null) return;
const M = { isTransactional: !0, isDataChange: !1, trigger: "moveCells", from: r.getRanges(e), to: C }, T = r._createRangeEvent(A.ranges, M);
r._notifyRangeListener2(A, T, M);
}
return null;
}, getMarkOptions: () => t, getCoords: () => null, isISnapshot: !0 });
}
const g = { excludeHidden: !1, fullyContained: !0, onEntry: (p) => p.model };
for (let p = 0; p < d; p++) {
const S = e[p], E = r._getRangedEntries("tableSpatial", [S], g), y = E.length;
for (let C = 0; C < y; C++) {
const w = E[C], b = w.getAnchorCoords(), x = b.colStart - S.colStart, I = b.rowStart - S.rowStart, v = w.getSnapshot(t);
l.push({ async copyTo(R, A) {
const M = R.getSheet(), T = R.getCoords();
if (r.getProtection().isLocked()) return;
const k = { colStart: T.colStart + x, rowStart: T.rowStart + I, colEnd: T.colEnd + x, rowEnd: T.rowEnd + I };
return v.copyTo({ tables: M.getTables(), range: k }, A);
} });
}
}
for (let p = 0; p < d; p++) {
const S = e[p];
l.push(md(o.getColumnHeaders().getRange(S), S, Object.freeze({ ...t, includeHeaders: S.rowStart <= u.rowStart && S.rowEnd >= u.rowEnd })));
}
for (let p = 0; p < d; p++) {
const S = e[p];
l.push(md(o.getRowHeaders().getRange(S), S, Object.freeze({ ...t, includeHeaders: S.colStart <= u.colStart && S.colEnd >= u.colEnd })));
}
const m = hw(o, r, e, i, t, (p, S) => r._copyRange(o, r, e, p, S, h));
l.push(m);
const f = r._getState().calcGraph.getSnapshot({ range: e[0] });
l.push({ async copyTo(p, S) {
const E = p.getSheet(), y = p.getCoords();
if (r.getProtection().isLocked()) return;
const C = E._getState().calcGraph;
return f.copyTo({ calcGraph: C, range: y }, S);
} });
const _ = e[0];
return /* @__PURE__ */ ((p, S, E, y, C, w, b = null) => ({ async copyTo(x, I) {
let v = null;
const R = { ...C, ...I }, A = E.beginCommit(R.description ?? w);
try {
const M = p.length;
for (let T = 0; T < M; T++) {
const k = await p[T].copyTo(x, R);
k && (v = D.unionRanges(v, k));
}
A.commit();
} catch (M) {
throw A.rollback(), M;
}
return v;
}, getMarkOptions: () => C, getName: () => w, getSource: () => S, getCoords: () => y, toText() {
let x = b?.toText?.() ?? null;
const I = p.length;
for (let v = 0; !x && v < I; v++) x = p?.[v].toText?.();
return x ?? null;
}, toHtml() {
let x = b?.toHtml?.() ?? null;
const I = p.length;
for (let v = 0; !x && v < I; v++) x = p?.[v].toHtml?.();
return x ?? null;
}, toImage() {
let x = b?.toImage?.() ?? null;
const I = p.length;
for (let v = 0; !x && v < I; v++) x = p?.[v].toImage?.();
return x ?? null;
}, isISnapshot: !0 }))(l, o, r, _, t, i, m);
}
async _copyRange(e, t, n, r, o, s) {
if (n.length > 1) throw new Error("Only a single selection is supported when using 'Insert Copy'.");
if (!n || n.length === 0) throw new Error("The source has no range.");
const i = r.getSheet();
let l = r.getCoords(), c = { ...n[0] };
const h = (o = { ...o }).isCut;
let u = !o.type || o.type === Te.Content.Formats, d = !o.type || o.type === Te.Content.Values, g = !o.type || o.type === Te.Content.Formats || o.type === Te.Content.Hyperlinks;
const m = i.getEntireRange(), f = m.getCoords(), _ = [], p = [], S = [];
let E = [], y = [];
const C = (o.fitDestination ?? !1) && !D.isSingleCell(l), w = li(l, c, C, o.transpose);
if (C && (c = { ...c, colEnd: c.colStart + Math.min(w.colEnd - w.colStart, c.colEnd - c.colStart), rowEnd: c.rowStart + Math.min(w.rowEnd - w.rowStart, c.rowEnd - c.rowStart) }), !D.isRangeWithinRange(w, f)) throw console.warn(w, f), new Error("We can't paste outside of the sheet bounds.");
let b = null;
b = o.undoRange ? { view: i.getView(), selection: Pe([o.undoRange.getCoords()]) } : { sheet: i, selection: Pe([w]) };
const x = i.getTransactions().beginCommit({ description: o.description ?? "Paste" });
try {
if (!this._getState()) return F.EmptyArray;
const I = /* @__PURE__ */ new Set(), v = o.transpose;
let R = !((v || o.adjustCells) && u) && I.size === 1;
if (R) {
const $ = I.values().next();
R = D.isRangeWithinRange(c, $.value.getCoords()) && !Po(c, $.value.getCoords());
}
R && (R = i.getTables().getItems({ address: w }).length === 0), v && (R = !0), s.singleMerge && (u = !1, g = !1);
const A = l.colStart - c.colStart, M = l.rowStart - c.rowStart, T = o.adjustCells;
let k = { ...z0 };
if (delete k[oe.Type.Style], !u) {
const $ = this.getProtection().isLocked();
k = {}, $ && (k[oe.Type.Unlock] = !1);
}
const P = O.Orientation.Column;
let B;
if (d) {
B = m.startIncrementalUpdates({ orientation: o.transpose ? O.Orientation.Row : O.Orientation.Column });
const $ = { orientation: P, includeRangeTypes: k, bounds: c }, J = new $a(this._strings, $, this._cellOptions), K = (ee, ne, ue) => {
const be = ee[0], Q = J.setState(ee), fe = J.context, ge = fe.getCell(), ae = ge.isTopLeft();
let Z = M, re = A;
if (v) {
const ie = be.colIndex - c.colStart, de = be.rowIndex - c.rowStart;
Z = ie + ue + l.rowStart, re = de + ne + l.colStart;
} else Z = M + be.rowIndex + ne, re = A + be.colIndex + ue;
let se = !1;
const _e = { value: void 0, style: void 0, hyperlink: void 0 };
if (d && (_e.value = Q, se = !0), u) {
const ie = ee[2];
ie && (ie.directStyle || ie.table) && (_e.style = ge.getStyle(!R), se = !0);
}
g && (_e.hyperlink = ge.getHyperlink(), se = !0);
let ve = _e;
if (T && ae) {
const ie = T(Q, fe, { rowIndex: Z, colIndex: re }, o);
ie !== void 0 && (ve = ie, se = !0);
}
if (se && (B.pushAt(Z, re, ve), u)) {
const ie = ge.getSpans();
(ie.width > 1 || ie.height > 1) && ae && _.push({ colStart: re, rowStart: Z, colEnd: re + (o.transpose ? ie.height : ie.width) - 1, rowEnd: Z + (o.transpose ? ie.width : ie.height) - 1 });
}
}, he = this._cellStateIterator($);
let le = { next() {
const ee = he.next();
if (ee.done) return ke;
const ne = ee.value[0];
let ue;
return ee.value && (ue = [ne, ee.value]), { done: ee.done, value: ue };
} };
if (!s.singleMerge && !D.isEqualRanges(w, c)) {
const ee = w.colEnd - w.colStart + 1, ne = w.rowEnd - w.rowStart + 1;
le = new Tl({ delegate: le, bounds: c, orientation: P, dims: { major: o.transpose ? ne : ee, minor: o.transpose ? ee : ne } });
}
let pe = le.next();
for (; !pe.done; ) {
const ee = pe.value, ne = ee[1], ue = ee[0], be = ne[0];
K(ne, ue.rowIndex - be.rowIndex, ue.colIndex - be.colIndex), pe = le.next();
}
}
const H = t._getState(), z = {}, W = { transpose: v ?? !1 };
u && (z.directStyleSpatial = H.directStyleSpatial, z.continuousFillSpatial = H.continuousFillSpatial, z.mergeSpatial = H.mergeSpatial), h && (e._clear([c], void 0, void 0, !1, !0), E.push(c), z.rangesListenerSpatial2 = H.rangesListenerSpatial2);
const L = i, j = L._getState(), G = Object.keys(z), V = G.length;
for (let $ = 0; $ < V; $++) {
const J = G[$], K = z[J].createCopiedEntries(c, w, W), he = j[J].clone(), le = K.removes, pe = le.length;
for (let ee = 0; ee < pe; ee++) he.remove(le[ee]);
he.load(K.inserts), j[J] = he;
}
L._updateState(j), E.push(w), y.push(w), p && p.length > 0 && L._colHeaders.updateHeaderPairs(p), S && S.length > 0 && L._rowHeaders.updateHeaderPairs(S), B?.apply(), _.length > 0 && i.getRanges(_).merge(), x.commit({ viewBefore: b, viewAfter: ($) => ({ ...$, view: i.getView(), selection: Pe(y), ranges: E }) });
} catch (I) {
throw console.warn(I), x.rollback(), new Error(((v) => `Unable to paste: ${v}`)(I.message), { cause: I });
}
return D.unionRangesArrays(y);
}
_snapShotFromSource(e, t) {
if (e.isISnapshot) return e;
const n = e;
let r = null;
if (n?.isICellRanges) throw new Error(du);
if (r = n?.isICellRange ? n : this.getRange(n), r.isICellRange) {
const o = r;
if (o.isInvalid()) throw new Error(gu);
return o.getSnapshot(t);
}
throw new Error(gu);
}
async _copyFrom(e, t, n) {
if (!t) throw new Error("Both a source and a destination are required to copy.");
const r = this._snapShotFromSource(t), o = "Paste", s = this._beginCommit({ description: n?.description ?? o });
let i = null;
try {
const l = this.getRange(e);
i = await r.copyTo(l, n);
const c = r.getName(), h = [i];
n?.isCut && h.push(r.getCoords()), s.commit({ description: c ? n?.description ?? `${o} ${c}` : o, viewAfter: { view: this.getView(), selection: Pe([i]), ranges: h } });
} catch (l) {
throw s.rollback(), l;
}
return i;
}
_createFilter(e, t, n) {
const r = this;
return new pm({ initialAnchor: e, maxRangeCoords: this._entireCoords, json: t, transactions: this._transactions, deleteFromContainer: (o) => {
const s = this._beginCommit({ description: o?.description ?? "Delete Filter" });
this._updateState({ filter: null }), s.commit();
}, apply: (o) => {
console.log("apply Filter", o);
}, processUpdate: () => {
}, isProtected: () => !r._initializing && !r.getProtection().isAutoFilterAllowed() });
}
insertFilter(e) {
const t = this._rangeToCoords(e, () => ["autoFilter"]);
let n = this.getFilter();
if (n) return n;
n = this._createFilter(t);
const r = Pe([t]), o = this._beginCommit({ description: "Insert Filter" });
return this._updateState({ filter: n }), o.commit({ viewAfter: { ranges: [t], view: this.getView(), selection: r, selectOptions: void 0 } }), n;
}
getFilter() {
return this._getState()?.filter ?? null;
}
insertSort(e) {
return this._rangeToCoords(e, () => ["sort"]), null;
}
getSort() {
return null;
}
_getDefaultShiftOrientation(e) {
return dS(e, this._entireCoords);
}
_getDefaultSortCriteria(e, t, n) {
return Lu(this, e, n ? this._cellToCoords(n) : null, t);
}
async _insertFrom(e, t, n) {
if (!t) throw new Kt();
const r = this._snapShotFromSource(t), o = r.getCoords();
let s = li(e[0], o, n?.fitDestination), i = po([s]), l = i;
const c = n?.orientation ?? this._getDefaultShiftOrientation(s), h = this._beginCommit({ description: n?.description ?? "Insert Copied Cells", autoSelect: n?.autoSelect });
try {
if (this._insertCells([s], c), await this._copyFrom(s, r, { ...n, isCut: !1 }), n.isCut) {
const u = { ...o };
if (i = po([u]), s = { ...s }, this === r.getSource()) {
if (c === O.Orientation.Row) {
if (s.colStart < u.colStart && s.colEnd >= u.colStart || s.colEnd > u.colEnd && s.colStart <= u.colEnd) throw new Error(mu);
if (u.colStart === s.colStart && u.colEnd === s.colEnd) {
const d = u.rowEnd - u.rowStart + 1;
s.rowStart <= u.rowStart ? (u.rowStart += d, u.rowEnd += d) : (s.rowStart -= d, s.rowEnd -= d);
}
} else {
if (s.rowStart < u.rowStart && s.rowEnd >= u.rowStart || s.rowEnd > u.rowEnd && s.rowStart <= u.rowEnd) throw new Error(mu);
if (u.rowStart === s.rowStart && u.rowEnd === s.rowEnd) {
const d = u.colEnd - u.colStart + 1;
s.colStart <= u.colStart ? (u.colStart += d, u.colEnd += d) : (s.colStart -= d, s.colEnd -= d);
}
}
l = po([s]);
}
r.getSource().getRanges([u]).delete(c);
}
h.commit({ viewBefore: { ranges: e, view: this.getView(), selection: i, selectOptions: n?.autoSelect }, viewAfter: { ranges: e, view: this.getView(), selection: l, selectOptions: n?.autoSelect } }), this._autoSelect(n?.autoSelect ?? !1, l);
} catch (u) {
throw h.rollback(), u;
}
return s;
}
_insertCells(e, t, n, r = void 0) {
const o = this;
r = r ?? ((f, _) => {
o._validateCoords(f, _ ?? za);
});
const s = n?.description ?? "Insert Cells", i = (t ?? this._getDefaultShiftOrientation(e[0])) === O.Orientation.Column;
if (this._protectionCheck(() => [i ? "insertColumns" : "insertRows"], e, s), zo(e)) throw new Error("We can't insert cells with overlapping selections.");
const l = this._entireCoords;
let c = l.colEnd, h = l.rowEnd;
const u = Pe(e), d = this._beginCommit({ description: s, operation: { name: "insertCells" } }), g = d.getState(this), m = i ? O.Direction.Right : O.Direction.Down;
try {
let f = g.cellValuesGrid, _ = g.contentfulSpatial, p = g.unlockSpatial, S = g.mergeSpatial, E = g.directStyleSpatial, y = g.continuousFillSpatial, C = g.conditionalSpatial, w = g.hyperlinkSpatial, b = g.commentsSpatial, x = g.movableSpatial, I = g.tableSpatial, v = g.calcGraph, R = g.rangesListenerSpatial2, A = g.rangeListenerSpatial, M = g.rangesListenerMap;
const T = /* @__PURE__ */ new Map(), k = zn(e.slice(), O.Direction.Left), P = k.length;
for (let W = 0; W < P; W++) {
const L = k[W];
c = Math.min(c, L.colStart), h = Math.min(h, L.rowStart);
const j = i ? L.colEnd - L.colStart + 1 : L.rowEnd - L.rowStart + 1, G = f.getCoords();
if (G) {
const K = { ...L, colEnd: i ? Math.max(L.colEnd, G?.colEnd ?? L.colStart) + (L.colEnd - L.colStart + 1) : L.colStart, rowEnd: i ? L.rowStart : Math.max(L.rowEnd, G?.rowEnd ?? L.rowStart) + (L.rowEnd - L.rowStart + 1) }, he = _.search(K), le = he.length;
for (let pe = 0; pe < le; pe++) {
const ee = he[pe], ne = { ...L };
i ? ne.colEnd = Math.max(ne.colEnd, ee.colEnd) + j : ne.rowEnd = Math.max(ne.rowEnd, ee.rowEnd) + j, r(ne);
}
f = f.clone(), f.shift(L, m), this._updateState({ cellValuesGrid: f });
}
const V = L.colStart <= l.colStart && L.colEnd >= l.colEnd, $ = L.rowStart <= l.rowStart && L.rowEnd >= l.rowEnd, J = (K, he, le, pe) => {
let ee = null;
le > 1 && (ee = K.at(le - 1));
const ne = pe - le + 1;
he?.(le, ne), ee && K.updateHeaderPairs([{ address: { min: le, max: pe }, update: ee }]);
};
V && J(this._rowHeaders, this._rowHeadersShiftCallback, L.rowStart, L.rowEnd), $ && J(this._colHeaders, this._colHeadersShiftCallback, L.colStart, L.colEnd), _ = _.shift({ range: L, direction: m, cloneIfUpdate: _ === g.contentfulSpatial, coordValidator: r }), p = p.shift({ range: L, direction: m, cloneIfUpdate: p === g.unlockSpatial, coordValidator: r }), S = S.shift({ range: L, direction: m, cloneIfUpdate: S === g.mergeSpatial, coordValidator: r }), E = E.shift({ range: L, direction: m, cloneIfUpdate: E === g.directStyleSpatial, coordValidator: r }), y = y.shift({ range: L, direction: m, cloneIfUpdate: y === g.continuousFillSpatial, coordValidator: r }), C = C.shift({ range: L, direction: m, cloneIfUpdate: C === g.conditionalSpatial, coordValidator: r }), w = w.shift({ range: L, direction: m, cloneIfUpdate: w === g.hyperlinkSpatial, coordValidator: r }), b = b.shift({ range: L, direction: m, cloneIfUpdate: b === g.commentsSpatial, coordValidator: r }), x = x.shift({ range: L, direction: m, cloneIfUpdate: x === g.movableSpatial, coordValidator: r }), I = I.shift({ range: L, direction: m, cloneIfUpdate: I === g.tableSpatial, coordValidator: r }), v = v.shift({ range: L, direction: m, cloneIfUpdate: v === g.calcGraph }), A = A.shift({ range: L, direction: m, cloneIfUpdate: A === g.rangeListenerSpatial, onShift: (K) => {
M === g.rangesListenerMap && (M = new Map(M)), this._processListenerShift(M, T, g.rangesListenerMap, K);
} }), R = R.shift({ range: L, direction: m, cloneIfUpdate: R === g.rangesListenerSpatial2, coordValidator: r });
}
let B = g.formulaSpatial, H = g.spillSpatial, z = g.pendingSpatial;
v !== g.calcGraph && (B = B.clone(), H = H.clone(), z = z.clone()), this._updateState({ contentfulSpatial: _, unlockSpatial: p, mergeSpatial: S, directStyleSpatial: E, continuousFillSpatial: y, conditionalSpatial: C, hyperlinkSpatial: w, commentsSpatial: b, movableSpatial: x, tableSpatial: I, calcGraph: v, formulaSpatial: B, spillSpatial: H, pendingSpatial: z, rangesListenerSpatial2: R, rangeListenerSpatial: A, rangesListenerMap: M }), this._commitAndAutoSelect(d, u, n?.autoSelect, { viewAfter: { ranges: k, listeners: T } });
} catch (f) {
throw console.warn(f), d.rollback(), f instanceof ze ? new Error(f.message ?? za) : f;
}
}
_deleteCells(e, t, n) {
const r = (t ?? this._getDefaultShiftOrientation(e[0])) === O.Orientation.Column, o = n?.description ?? "Delete Cells";
if (this._protectionCheck(() => [r ? "deleteColumns" : "deleteRows"], e, o), zo(e)) throw new Error("We can't delete cells with overlapping selections.");
const s = this._entireCoords;
let i = s.colEnd, l = s.rowEnd;
const c = r ? O.Direction.Left : O.Direction.Up, h = Pe(e), u = this._beginCommit({ description: o, operation: { name: "deleteCells" } }), d = u.getState(this);
try {
let g = d.cellValuesGrid, m = d.contentfulSpatial, f = d.mergeSpatial, _ = d.unlockSpatial, p = d.directStyleSpatial, S = d.continuousFillSpatial, E = d.conditionalSpatial, y = d.hyperlinkSpatial, C = d.commentsSpatial, w = d.movableSpatial, b = d.movableMapModel, x = d.tableSpatial, I = d.tableMapModel, v = d.calcGraph, R = d.rangesListenerSpatial2, A = d.rangeListenerSpatial, M = d.rangesListenerMap;
const T = /* @__PURE__ */ new Map(), k = zn(e.slice(), O.Direction.Left), P = k.length;
for (let B = 0; B < P; B++) {
const H = k[B];
i = Math.min(i, H.colStart), l = Math.min(l, H.rowStart), g.getCoords() && (g = g.clone(), g.shift(H, c), this._updateState({ cellValuesGrid: g }));
const z = H.colStart <= s.colStart && H.colEnd >= s.colEnd, W = H.rowStart <= s.rowStart && H.rowEnd >= s.rowEnd;
z && this._rowHeadersShiftCallback(H.rowStart, -1 * (H.rowEnd - H.rowStart + 1)), W && this._colHeadersShiftCallback(H.colStart, -1 * (H.colEnd - H.colStart + 1)), m = m.shift({ range: H, direction: c, cloneIfUpdate: m === d.contentfulSpatial }), _ = _.shift({ range: H, direction: c, cloneIfUpdate: _ === d.unlockSpatial }), f = f.shift({ range: H, direction: c, cloneIfUpdate: f === d.mergeSpatial }), p = p.shift({ range: H, direction: c, cloneIfUpdate: p === d.directStyleSpatial }), S = S.shift({ range: H, direction: c, cloneIfUpdate: S === d.continuousFillSpatial }), E = E.shift({ range: H, direction: c, cloneIfUpdate: E === d.conditionalSpatial }), y = y.shift({ range: H, direction: c, cloneIfUpdate: y === d.hyperlinkSpatial }), C = C.shift({ range: H, direction: c, cloneIfUpdate: C === d.commentsSpatial }), w = w.shift({ range: H, direction: c, cloneIfUpdate: w === d.movableSpatial }), x = x.shift({ range: H, direction: c, cloneIfUpdate: x === d.tableSpatial }), v = v.shift({ range: H, direction: c, cloneIfUpdate: v === d.calcGraph }), A = A.shift({ range: H, direction: c, cloneIfUpdate: A === d.rangeListenerSpatial, onShift: (L) => {
M === d.rangesListenerMap && (M = new Map(M)), this._processListenerShift(M, T, d.rangesListenerMap, L);
} }), R = R.shift({ range: H, direction: c, cloneIfUpdate: R === d.rangesListenerSpatial2 });
}
this._updateState({ contentfulSpatial: m, unlockSpatial: _, mergeSpatial: f, directStyleSpatial: p, continuousFillSpatial: S, conditionalSpatial: E, hyperlinkSpatial: y, commentsSpatial: C, movableSpatial: w, movableMapModel: b, tableSpatial: x, tableMapModel: I, calcGraph: v, rangesListenerSpatial2: R, rangeListenerSpatial: A, rangesListenerMap: M }), this._commitAndAutoSelect(u, h, n?.autoSelect, { viewAfter: { ranges: k, listeners: T } });
} catch (g) {
throw u.rollback(), g instanceof ze ? new Error(g.message ?? za) : g;
}
}
_autoFit(e, t) {
if (this._closed) throw new Error(xt);
t = { expandOnly: !1, skipCustomSize: !1, minContent: !1, ...t };
const n = "Autofit";
let r;
const o = Yo(e, this._entireCoords, !0), s = Xo(e, this._entireCoords, !0);
!o && s ? (t.orientations = t.orientations ?? O.Orientations.Column, r = `${n} ${or}`) : !s && o ? (t.orientations = t.orientations ?? O.Orientations.Row, r = `${n} ${rr}`) : s && o ? (t.orientations = t.orientations ?? O.Orientations.Both, r = `${n} All`) : (t.orientations = t.orientations ?? O.Orientations.Both, r = `${n}`);
let i = t.orientations !== O.Orientations.Row;
this._colHeaders.isProtected() && (i = !1);
let l = t.orientations !== O.Orientations.Column;
if (this._rowHeaders.isProtected() && (l = !1), !l && !i) return;
const c = i && (t.expandOnly === !1 || t.expandOnly === O.Orientation.Row), h = l && (t.expandOnly === !1 || t.expandOnly === O.Orientation.Column), u = t.minContent, d = Pe(e), g = this._beginCommit({ description: t.description ?? r });
try {
let m = Number.MAX_SAFE_INTEGER, f = Number.MIN_SAFE_INTEGER, _ = !1, p = "", S = -1, E = !1, y = !1, C = !1, w = Number.MAX_SAFE_INTEGER, b = Number.MIN_SAFE_INTEGER;
const x = this._styles.getNormal(), I = this._cellOptions, v = t.orientations === O.Orientations.Row, R = /* @__PURE__ */ new Map(), A = Ml(e, 1);
A.sort(D.createRangeComparator(O.Orientation.Column));
const M = A.length, T = { skipCustomSize: t.skipCustomSize }, k = te.getDeviceScale(), P = this._defaultRowHeight() * k, B = (z, W = 1) => {
if (z !== 0 && z !== null && !(W > 1)) return z = Math.max(z, P), (L) => h ? z : Math.max(L, z);
}, H = (z, W = 1) => {
if (z !== 0 && z !== null && !(W > 1)) return (L) => c ? z : Math.max(L, z);
};
for (let z = 0; z < M; z++) {
const W = [];
let L = -1, j = !1, G = x, V = 1, $ = 1;
const J = A[z];
let K = J.colStart, he = J.rowStart, le = J.colEnd, pe = J.rowEnd;
const ee = this._getUsedCoords();
(h || c) && ee && (K = h ? ee.colStart : J.colStart, he = c ? ee.rowStart : J.rowStart, le = h ? ee.colEnd : J.colEnd, pe = c ? ee.rowEnd : J.rowEnd);
const ne = { includeRangeTypes: { [oe.Type.Style]: !1, [oe.Type.Merge]: !1, [oe.Type.Contentful]: !1 }, excludeHidden: !1, bounds: { colStart: K, rowStart: he, colEnd: le, rowEnd: pe }, orientation: O.Orientation.Column }, ue = this._cellStateIterator({ ...ne, includeRangeTypes: { [oe.Type.Merge]: !1, [oe.Type.Table]: !1, [oe.Type.Style]: !1 }, ignoreEmptyIntersections: !0 });
let be, Q, fe, ge = ue.next(), ae = 1, Z = 1;
for (; !ge.done; ) {
const ve = ge.value, ie = ve[0], de = ve[2];
let ye = x;
const we = de?.directStyle ?? de?.table.getStyle() ?? null;
we === be ? ye = Q : (ye = we ? Pl(0, D.cellToRange(ie, Cw), de, I) : x, Q = ye);
let me = 1, Me = 1;
const Ce = de?.merge ?? null;
if (Ce === fe) me = ae, Me = Z;
else {
if (Ce) {
const Ue = Ce.getCoords();
me = Ue.colEnd - Ue.colStart + 1, Me = Ue.rowEnd - Ue.rowStart + 1;
} else me = 1, Me = 1;
ae = me, Z = Me;
}
const We = ie.colIndex, et = ie.rowIndex, tt = ve[1], ot = gt(tt), Vt = D.isCellWithinRange(ie, J);
let vt = !1, st = !1;
if (be !== we || me !== V || Me !== $ || ot === q.String || ot === q.Error || Vt !== j) {
if (vt = !0, ot === q.RichData && (st = !0), !st && de) {
const Ue = ye.getAlignment().getHorizontal();
Ue !== X.HorizontalAlignment.CenterContinuous && Ue !== X.HorizontalAlignment.Fill || (st = !0);
}
st && (vt = !1);
}
if (be = we, fe = Ce, (L !== We || vt) && (L !== -1 && W.push({ col: L, style: G, spanWidth: me, spanHeight: Me, minVal: m, maxVal: f, hasZero: _, text: p, textId: S, hasFalse: y, hasTrue: E, hasEmpty: C, minRow: w, maxRow: b, colWidth: this._colHeaders.getSpanSize(L), measureWidth: -1, measureHeight: -1, isFit: j }), L = We, G = ye, j = Vt, V = me, $ = Me, m = Number.MAX_SAFE_INTEGER, f = Number.MIN_SAFE_INTEGER, _ = !1, p = "", S = -1, y = !1, E = !1, C = !1, w = et), b = et, !st) if (tt === null) C = !0;
else switch (ot) {
case q.Number:
tt === 0 && (_ = !0), m = Math.min(m, tt), f = Math.max(f, tt);
break;
case q.String:
p = tt, S = tt;
break;
case q.Error:
p = tt.toString(), S = -1;
break;
case q.Boolean:
tt ? E = !0 : y = !0;
}
ge = ue.next();
}
L !== -1 && W.push({ col: L, style: G, spanWidth: V, spanHeight: $, minVal: m, maxVal: f, hasZero: _, text: p, textId: S, hasFalse: y, hasTrue: E, hasEmpty: C, minRow: w, maxRow: b, colWidth: this._colHeaders.getSpanSize(L), measureWidth: -1, measureHeight: -1, isFit: j });
let re = -1, se = -1;
const _e = W.length;
for (let ve = 0; ve < _e; ve++) {
const ie = W[ve], de = v || !ie.isFit, ye = ie.maxVal, we = ie.style, me = ie.colWidth;
if (re = 0, se = 0, ye !== Number.MIN_SAFE_INTEGER) {
const Ce = jn(q.Number, we, ye, I, me, u, de);
re = Ce.width, se = Ce.height;
const We = ie.minVal;
if (We * ye < 0) {
const et = jn(q.Number, we, We, I, me, u, de);
re = Math.max(re, et.width), se = Math.max(se, et.height);
}
if (ie.hasZero && We !== 0 && ye !== 0) {
const et = jn(q.Number, we, 0, I, me, u, de);
re = Math.max(re, et.width), se = Math.max(se, et.height);
}
}
const Me = ie.text;
if (Me.length > 0) {
const Ce = jn(q.String, we, Me, I, me, u, de, void 0, R);
re = Math.max(re, Ce.width), se = Math.max(se, Ce.height);
}
if (ie.hasTrue || ie.hasFalse) {
const Ce = jn(q.Boolean, we, !ie.hasFalse, I, me, u, de);
re = Math.max(re, Ce.width), se = Math.max(se, Ce.height);
}
if (ie.hasEmpty) {
const Ce = jn(q.Boolean, we, null, I, me, u, de);
re = Math.max(re, Ce.width), se = Math.max(se, Ce.height);
}
ie.measureWidth = re, ie.measureHeight = se;
}
if (i) {
const ve = [];
for (let ie = 0; ie < _e; ie++) {
let de = W[ie];
const ye = de.col;
let we = W[ie + 1], me = de.measureWidth ?? 0;
for (; we && we.col === ye; ) we.measureWidth && (me = Math.max(we.measureWidth ?? 0, me)), ie++, de = W[ie], we = W[ie + 1];
me === 0 && (me = null);
const Me = H(me, de.spanWidth);
ve.push({ address: { min: ye, max: ye }, update: { size: Me, autoSize: !0 } });
}
this._colHeaders.updateHeaderPairs(ve, T);
}
if (l) {
let ve = 1;
const ie = { onUpdate: (me, Me, Ce) => {
if (!(ve > 1)) return me === null ? Me : Math.max(Me, me);
} };
let de = [];
for (let me = 0; me < _e; me++) {
const Me = W[me];
ve = Me.spanHeight, de = Wn(vl(de, { min: Me.minRow, max: Me.maxRow, value: Me.measureHeight }, ie));
}
const ye = de.length, we = new Array(ye);
for (let me = 0; me < ye; me++) {
const Me = de[me], Ce = B(Me.value, 1), We = { address: { min: Me.min, max: Me.max }, update: { size: Ce, autoSize: !0 } };
we[me] = We;
}
this._rowHeaders.updateHeaderPairs(we, T);
}
}
this._commitAndAutoSelect(g, d, t?.autoSelect, { viewAfter: { ranges: e } });
} catch (m) {
throw g.rollback(), m;
}
}
_createRangeEvent(e, t) {
const n = this, r = () => {
const s = n._getState();
return this._closed || s.deleted ? Cn(null) : e ? Array.isArray(e) ? n._createRanges(e) : n._createRange(e) : Cn(this, this._entireCoords);
}, o = t.trigger;
return { getSource: r, getFrom: () => t.from ?? null, getTo: () => t.to ?? null, trigger: o, isUndo: t.isUndo ?? !1, isDataChange: t.isDataChange ?? !1, isTransactional: t.isTransactional ?? !0, toString: () => `SheetRangeEvent: ('${o}', ${r().toString()})`, timeStamp: t.timeStamp ?? Date.now() };
}
_notifyAddressListeners(e, t, n, r) {
const o = t.entries();
let s = o.next();
const i = r.trigger;
for (; !s.done; ) {
const l = s.value[0];
let c = s[1];
if (c || (c = e.get(l)), c && !n.has(l)) {
let h = !1;
const u = c.options;
u && (h = i === "address" ? u.ignoreAddressChanges : u.ignoreDataChanges), h !== !0 && c.notify(r), n.add(l);
}
s = o.next();
}
}
_notifyDataListeners(e, t, n = null, r, o) {
if (!e) return;
const s = n.length;
for (let i = 0; i < s; i++) {
const l = n[i];
if (!l) continue;
const c = e.search(l), h = c.length;
for (let u = 0; u < h; u++) {
const d = c[u].value.groupId;
if (!r.has(d)) {
const g = t.get(d);
g.options?.ignoreDataChanges !== !0 && g.notify(o), r.add(d);
}
}
}
}
_notifyRangeListeners(e, t, n = null, r) {
if (!e) return;
const o = /* @__PURE__ */ new Set();
r.timeStamp || (r.timeStamp = Date.now());
const s = n.length;
for (let i = 0; i < s; i++) {
const l = n[i];
if (!l) continue;
const c = e.search(l), h = c.length;
for (let u = 0; u < h; u++) {
const d = c[u].value.id;
if (o.has(d)) continue;
const g = t.get(d);
o.add(d);
const m = g.ranges, f = m.length;
for (let _ = 0; _ < f; _++) {
const p = m[_], S = this._createRangeEvent(p, r);
this._notifyRangeListener2(g, S, r);
}
}
}
}
_notifyRangeListener2(e, t = null, n = null) {
if (e.options?.ignoreDataChanges && n?.isDataChange) return;
const o = e.handler ?? e.handlerW.deref();
if (o) try {
o?.(t);
} catch (s) {
console.warn(s);
}
}
_notifyUsedRangeChange() {
this._lastCellRead.coords = null, this._lastUsedCoordsRead.coords = null, this._emitter.notify("onUsedRangeChange");
}
_notifyMergeChange() {
this._emitter.notify("onMergesChange");
}
addListeners(e, t) {
let n = null;
if (e.onLayoutChange) {
const o = e, s = { onSizesChange: () => {
o.onLayoutChange(this);
} };
n = [], n.push(this._colHeaders.addListeners(s, t)), n.push(this._rowHeaders.addListeners(s, t));
}
let r = this._emitter.addListeners(e, t);
if (n) {
const o = r;
r = () => {
const s = n.length;
for (let i = 0; i < s; i++) n[i]();
o();
};
}
return r;
}
_addRangesListeners(e, t, n) {
if (this._closed) throw new Error(xt);
if (!t) throw new Error(ou);
n = n ? { ...Ps, ...n } : Ps;
const r = n?.transactional ?? !1, o = this, s = yw++ % Number.MAX_SAFE_INTEGER, i = () => {
let f = null, _ = null;
if (r) {
const y = o._getState();
if (!y) return;
f = y.rangeListenerSpatial.clone(), _ = new Map(y.rangesListenerMap);
} else f = o._rangeListenerSpatial, _ = o._rangesListenerMap;
const p = _.get(s);
if (!p) return void console.log("Listener not found");
const S = p.ranges, E = S.length;
for (let y = 0; y < E; y++) {
const C = D.sanitizeRange(S[y]);
C !== null && f.remove(C, (w, b) => {
if (b.value.id === s) return !0;
});
}
if (_.delete(s), r) {
const y = this._beginCommit({ description: "Remove Range Listener" });
this._updateState({ rangeListenerSpatial: f, rangesListenerMap: _ }), y.commit({ forceAmend: !0 });
}
}, l = [...e];
let c = { id: s, handler: null, handlerW: null, removeListener: i, options: n, ranges: l };
n?.weakly ? c.handlerW = new WeakRef(t) : c.handler = t;
let h = null, u = null, d = null;
if (r) {
d = this._beginCommit({ description: "Add Range Listener" });
const f = this._getState();
h = f.rangeListenerSpatial.clone(), u = new Map(f.rangesListenerMap);
} else h = o._rangeListenerSpatial, u = o._rangesListenerMap;
const g = [], m = e.length;
for (let f = 0; f < m; f++) {
const _ = { ...e[f], value: { id: s, offset: f, options: n } };
g.push(_);
}
return h.load(g), u.set(s, c), d && (this._updateState({ rangeListenerSpatial: h, rangesListenerMap: u }), d.commit({ forceAmend: !0 })), i;
}
_addRangesListeners2(e, t, n, r) {
if (this._closed) throw new Error(xt);
if (!t) throw new Error(ou);
n = n ? { ...Ps, ...n } : Ps;
const o = n?.transactional ?? !1, s = this, i = F.uuidV4(), l = Ew++, c = () => {
let C = null, w = null;
const b = s._getState();
if (!b) return;
C = b.rangesListenerSpatial2.clone(), w = b.rangesListenerMap2;
const x = w.get(i);
if (x) {
const v = x?.spatialsIds, R = x?.coords, A = v.length;
for (let M = 0; M < A; M++) {
const T = v[M], k = R[M];
C.remove(k, (P, B) => {
if (B.value.uuid === T) return !0;
});
}
w = new Map(b.rangesListenerMap2), w.delete(i);
}
const I = this._beginCommit({ description: "Remove Range Listener" });
this._updateState({ rangesListenerMap2: w }), I.commit({ forceAmend: !0 }), o || this._rangesListenerSorted.delete(l);
};
let h = null, u = this._beginCommit({ description: "Add Range Listener" });
const d = this._getState();
h = d.rangesListenerSpatial2.clone();
let g = null, m = null;
n?.weakly ? m = new WeakRef(t) : g = t;
const f = [], _ = [...e];
let p = [];
const S = e.length;
for (let C = 0; C < S; C++) {
const w = { ...e[C] };
_[C] = w;
const b = F.uuidV4(), x = new zi(i, b, n?.ignoreAddressChanges ?? !1);
p.push(b);
const I = { ...D.sanitizeRange(w), value: x };
f.push(I);
}
h.load(f), n = { ...n };
const E = new Pi(i, p, _, r, this, l, g, m, c, n), y = new Map(d.rangesListenerMap2);
return y.set(i, E), this._updateState({ rangesListenerSpatial2: h, rangesListenerMap2: y }), o || this._rangesListenerSorted.set(l, E), u.commit({ forceAmend: !0 }), c;
}
_getUsedCoords(e) {
const t = this._getState();
if (!t) return null;
let n = t.cellValuesGrid.getCoords();
return n = D.unionRanges(t.mergeSpatial.getBoundingCoords(), n), n = D.unionRanges(t.directStyleSpatial.getBoundingCoords(), n), n = D.unionRanges(t.formulaSpatial.getBoundingCoords(), n), n = D.unionRanges(t.spillSpatial.getBoundingCoords(), n), n = D.unionRanges(t.pendingSpatial.getBoundingCoords(), n), n && (n.colStart = Math.max(n.colStart, this._entireCoords.colStart), n.rowStart = Math.max(n.rowStart, this._entireCoords.rowStart), n.colEnd = Math.min(n.colEnd, this._entireCoords.colEnd), n.rowEnd = Math.min(n.rowEnd, this._entireCoords.rowEnd)), !n || n.rowStart > n.rowEnd || n.colStart > n.colEnd ? (this._lastUsedCoordsRead.coords = null, null) : (this._lastUsedCoordsRead && this._lastUsedCoordsRead.coords && Po(this._lastUsedCoordsRead.coords, n) || (this._lastUsedCoordsRead.coords = n, this._lastUsedCoordsRead.range = null), this._lastUsedCoordsRead.coords);
}
_isContentful(e, t) {
return !!this._contentCounts(e, void 0, t);
}
_getCount(e, t = !1) {
const n = this._contentCounts(e, bw, t);
return n ? n[Te.Content.Values] ?? 0 : 0;
}
_contentCounts(e, t, n) {
if (!t) {
const u = Object.keys(Te.Content), d = u.length;
t = new Array(d);
for (let g = 0; g < d; g++) {
const m = u[g];
t[g] = Te.Content[m];
}
}
const r = {}, o = t.length;
let s, i, l = !1;
for (let u = 0; u < o; u++) {
const d = t[u];
d === Te.Content.Values ? (r[oe.Type.Contentful] = !1, r[oe.Type.Table] = !1) : d === Te.Content.Formulas ? r[oe.Type.Formula] = !1 : d === Te.Content.Formats ? r[oe.Type.Style] = !1 : d === Te.Content.Tables && (r[oe.Type.Table] = !1, l = !0);
}
const c = () => {
s = /* @__PURE__ */ new Set(), i = {};
for (let u = 0; u < o; u++) {
const d = t[u];
i[d] = 0;
}
}, h = e.length;
for (let u = 0; u < h; u++) {
const d = e[u], g = this._rangeStateIterator({ includeRangeTypes: r, excludeHidden: n, bounds: d });
let m = g.next();
for (; !m.done; ) {
i || c();
const f = m.value, _ = (f.end.colIndex - f.start.colIndex + 1) * (f.end.rowIndex - f.start.rowIndex + 1), p = f.intersection;
if (p) {
p.contentful && (i[Te.Content.Values] += _), p.formula && (i[Te.Content.Formulas] += _);
const S = p.table;
S && (l && !s.has(S) && (i[Te.Content.Tables] += 1, s.add(S)), p.contentful || (i[Te.Content.Values] += _));
}
m = g.next();
}
}
return i;
}
getSelectedCell() {
const e = this.getSelection().getCoords().cell, t = this._lastCellSelected;
if (t?.cell && D.isEqualCells(e, t.coords)) return t.cell;
const n = this.getRange(e).getCell();
return this._lastCellSelected = { coords: e, cell: n }, n;
}
find(e, t) {
return this.getEntireRange().find(e, t);
}
_find(e, t, n) {
if (this._closed) throw new Error(xt);
if (!t) return null;
const r = [...e], o = n?.orientation ?? O.Orientation.Row, s = n?.reverse, i = !n?.disableWrap, l = n?.from ? this._cellToCoords(n?.from) : null;
let c = null;
if (l) {
let b = -1;
for (let T = 0; b === -1 && T < r.length; T++) D.isCellWithinRange(l, r[T]) && (b = T);
c = D.cellToRange(l);
let x = Nl(r[b], c, o);
x.push(c);
const I = D.createRangeComparator(o, s);
x.sort(I);
let v = -1;
const R = x.length;
for (let T = 0; T < R; T++)
I(x[T], c) <= 0 && (v = T);
r.splice(b, 1, ...x);
const A = b + v, M = [];
for (let T = 0; T <= A; T++) M.push(r.shift());
if (i) {
const T = M.length;
for (let k = 0; k < T; k++) r.push(M[k]);
}
}
if (r.length === 0) return Ze;
const h = n?.fields?.includes(Te.Content.Formulas) ?? !1, u = n?.fields?.includes(Te.Content.Values) ?? !0, d = n?.matchEntireCell ?? !1, g = n?.matchCase ?? !1, m = n?.useRegex ?? !1, f = ((b, x, I) => {
const v = x ? "" : "i";
return I ? new RegExp(b, v) : new RegExp(((R) => {
let A = R.replace(/[|\\{}()[\]^$+.]/g, "\\$&");
return A = A.replace(/~\?/g, "\\?"), A = A.replace(/~\*/g, "\\*"), A = A.replace(/~~/g, "~"), A;
})(b), v);
})(t, g, m), _ = t.length;
let p = (b, x) => {
const I = (A) => {
if (!A) return !1;
let M = !!A.match(f);
return M && d && A.length !== _ && (M = !1), M;
}, v = x.getCell();
let R = !1;
return !R && h ? R = I(v.getFormulaText() ?? v.toTextUnformatted(!0)) : u && (R = I(v.getNumberFormat().displayText)), R;
};
if (n?.matchCustom) {
const b = n.matchCustom, x = { matchCase: g, matchEntireCell: d, useRegex: m, fields: n?.fields ?? [Te.Content.Formulas] };
let I, v, R = p;
const A = () => R(I, v);
p = (M, T) => (I = M, v = T, b(M, A, x, T));
}
let S = -1, E = null, y = ke, C = !1;
const w = () => {
if (y.done) {
if (S++, S >= r.length) return void (C = !0);
E = this._cellIterator({ reverse: s, orientation: o, includeRangeTypes: !1, bounds: r[S] });
}
if (y = E.next(), !y.done) {
const b = y.value;
return p(b.value, b.context);
}
return !1;
};
return { next: () => {
let b = null;
for (; !C && !b; ) w() && (b = y.value.context.getCell());
return b ? { value: b, done: !1 } : ke;
} };
}
isDate1904() {
return this._isDate1904;
}
_surroundingRegion(e, t) {
const n = this._getState(), r = t?.contentOnly ?? !1, o = this._entireCoords;
if (!r) {
const l = n.tableSpatial.search(e);
if (l.length > 0) {
const c = l[0].value.model, h = c.getUsedRange().getCoords(), u = c.getRange().getCoords();
return D.isEqualRanges(h, e) ? u : D.isEqualRanges(u, e) ? o : h;
}
}
const s = r ? e : o;
return ((l, c, h = 2e4) => {
if (!c || c.length === 0) return null;
let u, d = !1;
for (let C = 0; C < c.length; C++) {
const w = c[C];
u = D.unionRanges(u, w.getBoundingCoords()), d = d || w.search(l).length > 0;
}
if (!u) return null;
const g = { ...D.EmptyRange }, m = l;
let f = d ? { ...l } : null;
if (!f) {
const C = ((b) => {
let x = [];
const I = c.length;
for (let v = 0; v < I; v++) {
const R = c[v].search(b), A = R.length;
x = A > 0 ? new Array(A) : void 0;
for (let M = 0; M < A; M++) {
const T = R[M];
x[M] = T;
}
}
return x || F.EmptyArray;
})({ colStart: l.colEnd, rowStart: l.rowEnd, colEnd: l.colEnd + 1, rowEnd: l.rowEnd + 1 }), w = C.length;
if (w > 0) {
f = { ...l };
for (let b = 0; b < w; b++) {
const x = C[b];
f.colEnd = Math.max(f.colEnd, x.colStart), f.rowEnd = Math.max(f.rowEnd, x.rowStart);
}
}
}
const _ = { ...D.EmptyRange }, p = () => {
const C = c.length;
for (let w = 0; w < C; w++) {
const b = c[w].search(g), x = b.length;
for (let I = 0; I < x; I++) {
const v = b[I];
f = D.unionRanges(f, v, _);
}
}
return f;
};
g.colStart = l.colStart, g.rowStart = l.rowStart, g.colEnd = l.colEnd, g.rowEnd = l.rowEnd, p();
const S = { ...f }, E = { ...D.EmptyRange };
let y = 0;
do {
if (g.colStart = E.colStart = S.colStart, g.rowStart = E.rowStart = S.rowStart, g.colEnd = E.colEnd = S.colEnd, g.rowEnd = E.rowEnd = S.rowEnd, S.colStart > u.colStart && (g.colStart = S.colStart - 1, g.colEnd = S.colStart - 1, g.rowStart = S.rowStart - 1, g.rowEnd = S.rowEnd + 1, p()), S.rowStart > u.rowStart && (g.rowStart = S.rowStart - 1, g.rowEnd = S.rowStart - 1, g.colStart = S.colStart - 1, g.colEnd = S.colEnd + 1, p()), S.colEnd < u.colEnd && (g.colStart = S.colEnd + 1, g.colEnd = S.colEnd + 1, g.rowStart = S.rowStart - 1, g.rowEnd = S.rowEnd + 1, p()), S.rowEnd < u.rowEnd && (g.rowStart = S.rowEnd + 1, g.rowEnd = S.rowEnd + 1, g.colStart = S.colStart - 1, g.colEnd = S.colEnd + 1, p()), !f) return null;
if (S.colStart = f.colStart, S.rowStart = f.rowStart, S.colEnd = f.colEnd, S.rowEnd = f.rowEnd, D.isEqualRanges(S, E)) return D.isEqualRanges(m, S) ? null : S;
if (D.isEqualRanges(S, m)) return null;
if (D.isEqualRanges(S, E)) return S;
y++;
} while (y < h);
return null;
})(e, [n.contentfulSpatial, n.mergeSpatial, n.formulaSpatial, n.spillSpatial, n.pendingSpatial]) || s;
}
_extendRange(e, t) {
if (this._closed) throw new Error(xt);
const n = this._entireCoords, r = this, o = { excludeHidden: !0, onEntry: (h, u) => u }, s = { excludeHidden: !0, onEntry: (h, u) => h.tvTl() === void 0 ? null : u };
let i;
const l = r._getRangedEntries("mergeSpatial", [D.cellToRange(t)], s);
l.length > 0 && (i = l[0]);
const c = [(h) => r._getRangedEntries("mergeSpatial", h, s), (h) => r._getRangedEntries("contentfulSpatial", h, o)];
return ((h, u, d, g, m) => {
let f, _, p, S = { ...u }, E = D.cellToRange(S), y = g(E).length > 0;
if (y) {
let w = 1, b = h === O.Direction.Up || h === O.Direction.Down;
d && (w += b ? d.rowEnd - d.rowStart : d.colEnd - d.colStart), h !== O.Direction.Left && h !== O.Direction.Up || (w = -w), b ? S.rowIndex = S.rowIndex + w : S.colIndex = S.colIndex + w, E = D.cellToRange(S), y = g(E).length > 0;
}
switch (h) {
case O.Direction.Up:
E.rowStart = Math.min(m.rowStart, E.rowStart), _ = g(E).sort(D.createRangeComparator(O.Orientation.Row, !0)), f = u.rowIndex, p = y ? _.length === 1 && f === _[0].rowStart ? m.rowStart : _[0].rowStart : _.length === 0 ? m.rowStart : _[0].rowEnd;
break;
case O.Direction.Down:
E.rowEnd = Math.max(m.rowEnd, E.rowEnd), _ = g(E).sort(D.createRangeComparator(O.Orientation.Row, !1)), f = u.rowIndex, p = y ? _.length === 1 && f === _[0].rowEnd ? m.rowEnd : _[0].rowEnd : _.length === 0 ? m.rowEnd : _[0].rowStart;
break;
case O.Direction.Left:
E.colStart = Math.min(m.colStart, E.colStart), _ = g(E).sort(D.createRangeComparator(O.Orientation.Column, !0)), f = u.colIndex, p = y ? _.length === 1 && f === _[0].colStart ? m.colStart : _[0].colStart : _.length === 0 ? m.colStart : _[0].colEnd;
break;
case O.Direction.Right:
E.colEnd = Math.max(m.colEnd, E.colEnd), _ = g(E).sort(D.createRangeComparator(O.Orientation.Column, !1)), f = u.colIndex, p = y ? _.length === 1 && f === _[0].colEnd ? m.colEnd : _[0].colEnd : _.length === 0 ? m.colEnd : _[0].colStart;
}
if (y && _.length > 1) {
let w = !1;
for (let b = 1; !w && b < _.length; b++) {
const x = _[b];
switch (h) {
case O.Direction.Up:
x.rowEnd < p - 1 ? w = !0 : p = Math.min(p, x.rowStart);
break;
case O.Direction.Down:
x.rowStart > p + 1 ? w = !0 : p = Math.max(p, x.rowEnd);
break;
case O.Direction.Left:
x.colEnd < p - 1 ? w = !0 : p = Math.min(p, x.colStart);
break;
case O.Direction.Right:
x.colStart > p + 1 ? w = !0 : p = Math.max(p, x.colEnd);
}
}
}
const C = D.cellToRange(u);
switch (h) {
case O.Direction.Up:
C.rowStart = p;
break;
case O.Direction.Down:
C.rowEnd = p;
break;
case O.Direction.Left:
C.colStart = p;
break;
case O.Direction.Right:
C.colEnd = p;
}
return C;
})(e, t, i, (h) => {
const u = [], d = [h], g = c.length;
for (let m = 0; m < g; m++) {
const f = (0, c[m])(d), _ = f.length;
for (let p = 0; p < _; p++) {
const S = f[p];
u.push(S);
}
}
return u;
}, n);
}
_defaultFontDims() {
if (this._defaultFontBoundsCache) return this._defaultFontBoundsCache;
const e = this._styles.getNormal();
let t = 0, n = 0;
for (let r = 0; r <= 9; r++) {
const o = e.measureText(r.toString());
t = Math.ceil(Math.max(o.width, t)), n = Math.max(o.lineHeight, n);
}
return this._defaultFontBoundsCache = { width: t, height: n }, this._defaultFontBoundsCache;
}
getColumnWidthAsFontUnit(e) {
const t = Math.round(this._defaultFontDims().width), n = e / (this.getView().isShowFormulas() ? 2 : 1);
if (!t || !e) return 0;
let r = 5;
return n < r + t && (r = n * (r / (r + t))), (n - r) / t;
}
_defaultColWidth() {
if (this._defaultColWidthCache) return this._defaultColWidthCache;
const e = this._defaultFontDims()?.width || 7, t = 8 * Math.round((8 * e + 5) / 8);
return this._defaultColWidthCache = t;
}
_defaultRowHeight() {
if (this._defaultRowHeightCache) return this._defaultRowHeightCache;
let e = this._defaultFontDims();
if (!e || e.width === 0) return this._defaultRowHeightCache = 20 / te.getDeviceScale(), this._defaultRowHeightCache;
const t = this._styles.getNormal(), n = /* @__PURE__ */ new Map();
let r = e.height + 2;
return this._colHeaders.getUsedRange().forEachSpan((o, s) => {
const i = s.getCellHeader();
i?.getStyle() !== t && (r = Math.max(((l) => {
let c = n.get(l);
return c === void 0 && (c = l.measureText("M").lineHeight + 2, n.set(l, c)), c;
})(i.getStyle()), r));
}), this._defaultRowHeightCache = Math.round(r / te.getDeviceScale() * 4) / 4, this._defaultRowHeightCache;
}
getProtection() {
return this._protection ?? null;
}
async _selectSheet(e, t) {
if (await this._options.container?.requestSelect?.() === !1) return !1;
if (t === !1) return !0;
const n = { coords: e };
t !== !0 && t !== void 0 && (n.scrollIntoView = t);
const r = await this._emitter.notify("onRequestScrollIntoView", { params: n, async: !0 });
if (!r) return !1;
const o = r.length;
for (let s = 0; s < o; s++) if (r[s] === !1) return !1;
return !0;
}
async scrollTo(e, t) {
const n = { ...t, coords: e }, r = await this._emitter.notify("onRequestScrollIntoView", { params: n, async: !0 });
if (!r) return !1;
const o = r.length;
for (let s = 0; s < o; s++) if (r[s] === !1) return !1;
}
async _commitAndAutoSelect(e, t, n = !1, r) {
return r = { ...r, viewAfter: { view: this.getView(), selection: t, selectOptions: n, ...r?.viewAfter } }, e.commit(r), this._autoSelect(n, t);
}
async _autoSelect(e, t) {
if (!e) return;
e === !0 && (e = { autoFocus: !0, scrollIntoView: !0 });
const n = e?.autoFocus, r = e?.scrollIntoView, o = e?.anchor, s = this.getSelection().getCoords(), i = Lr(t ?? s), l = this._entireCoords, c = ((f, _, p) => {
if (!f || f.length === 0 || !_) return F.EmptyArray;
const S = [...f];
for (let E = 0; E < S.length; E++) {
const y = { ...S[E] };
let C = y;
const w = _.search(y), b = y.rowStart <= p.rowStart && y.rowEnd >= p.rowEnd, x = y.colStart <= p.colStart && y.colStart >= p.colEnd;
for (let I = 0; I < w.length; I++) {
const v = w[I];
b || (C.colStart = Math.min(C.colStart, v.colStart), C.colEnd = Math.max(C.colEnd, v.colEnd)), x || (C.rowStart = Math.min(C.rowStart, v.rowStart), C.rowEnd = Math.max(C.rowEnd, v.rowEnd));
}
S[E] = C;
}
return S;
})(i, this._getState().mergeSpatial, l);
let h = -1, u = null;
if (!o) {
const f = s?.cell;
for (let _ = 0; h === -1 && _ < c.length; _++) {
const p = c[_];
D.isCellWithinRange(f, p) && (h = _, u = f);
}
}
const d = po(c, u, h);
this.getSelection().updateCoords(d);
const g = d.ranges?.[d.rangeIndex] ?? D.cellToRange(d.cell), m = await this._selectSheet(g, r);
if (r !== !1 && m === !1) return c;
if (n !== !1) {
const f = await this._emitter.notify("onRequestFocus");
if (!f) return c;
const _ = f.length;
for (let p = 0; p < _; p++) if (f[p] === !1) return c;
}
return c;
}
getSelection() {
return this._rangeSelection;
}
getView() {
return this._view;
}
setView(e) {
if (this._closed) throw new Error(xt);
if (!e) throw new Error("View can not be empty.");
this._viewRemoveListener?.(), this._view = e, this._viewRemoveListener = e.addListeners(this._viewListener, { transactional: !1 });
const t = this.getSelection().getCoords();
return this._rangeSelection.updateCoords(t), this._emitter.notify("onMovableSelectionChange"), this._emitter.notify("onTopLeftChange"), this._emitter.notify("onFreezeSplitChange"), this._emitter.notify("onViewChange", { source: e }), this;
}
getTabColor() {
return this._tabColor;
}
setTabColor(e) {
if (this._closed) throw new Error(xt);
return this._tabColor = typeof e == "string" ? this._styles.parseColor(e) : e ?? null, this._emitter.notify("onTabColorChange"), this;
}
getRowHeaders() {
return this._rowHeaders;
}
getColumnHeaders() {
return this._colHeaders;
}
async toJSON(e = !1) {
if (this._closed) throw new Error(xt);
await this._emitter.notify("onBeforeSave", { async: !0 }), await Promise.resolve(this._starting);
let t = {};
const n = this._getState();
if (!n) return t;
try {
const _ = this._strings.beginPersist();
try {
if (!e) {
const C = [], w = this._cellStateIterator({ includeRangeTypes: !1, orientation: O.Orientation.Column });
let b = w.next(), x = Number.MIN_SAFE_INTEGER, I = Number.MIN_SAFE_INTEGER, v = null, R = null, A = null, M = null;
for (; !b.done; ) {
const T = b.value[0], k = T.colIndex, P = T.rowIndex;
k !== x && (M && C.push(M), v = [], A = [], M = [k, A], x = k, I = P - 2), P > I + 1 && (v = [], R = [P, v], A.push(R));
const B = b.value[1], H = gt(B);
let z;
if (H === q.Number || H === q.Boolean) z = B;
else if (H === q.String)
z = "" + _.add(B);
else if (H === q.Error) z = { t: H, v: B.getCode() };
else if (H === q.RichData) {
const W = B, L = W.type, j = W?.toJSON?.();
L && j && (z = { t: H, v: 0 });
} else console.warn("error", z);
v.push(z), I = P, b = w.next();
}
M && C.push(M), C.length > 0 && (t.data = C);
}
this._ownStrings && (t.strings = await _.toJSONAsync());
} catch (C) {
console.warn("error", C);
} finally {
_.endPersist();
}
const p = this._colHeaders.toJSON();
p && (p.headers && p.headers.length > 0 && (t.cols = p.headers), p.defaultSize !== void 0 && p.defaultSize !== -1 && (t.defaultColSize = p.defaultSize));
const S = this._rowHeaders.toJSON();
S && (S.headers && S.headers.length > 0 && (t.rows = S.headers), S.defaultSize !== void 0 && S.defaultSize !== -1 && (t.defaultRowSize = S.defaultSize));
const E = this.getProtection().toJSON();
E && (t.protection = E), this._view.setRangeSelection(this.getSelection().getCoords());
const y = this._view.toJSON();
y && (t.view = y), this._tabColor && (t.tabColor = this._tabColor.toString());
} catch (_) {
console.warn(_);
}
const r = zn(n.mergeSpatial.all());
r.length > 0 && (t.merges = oc(r));
const o = zn(n.directStyleSpatial.all());
if (o.length > 0) {
const _ = this._styles.beginPersist();
try {
const p = [], S = o.length;
for (let E = 0; E < S; E++) {
const y = o[E], C = _.getElementID(y.value.toJSON());
p.push({ r: Kr.rangeToString(y), v: C });
}
if (t.directStyles = p, this._ownStyles) {
const E = _.toJSON();
E && Object.keys(E).length > 0 && (t.styles = E);
}
} catch (p) {
console.warn(p);
} finally {
_.endPersist();
}
}
const s = zn(n.hyperlinkSpatial.all()), i = s.length;
if (i > 0) {
const _ = [];
for (let p = 0; p < i; p++) {
const S = s[p];
let E = S.value;
_.push({ r: Kr.rangeToString(S), v: E });
}
t.hyperlinks = _;
}
const l = zn(n.commentsSpatial.all()), c = l.length;
if (c > 0) {
const _ = [];
for (let p = 0; p < c; p++) {
const S = l[p], E = { ...S.value };
E.ref = Kr.rangeToString(S), _.push(E);
}
t.comments = _;
}
const h = this._resources.beginPersist();
try {
const _ = this.getMovables().getItems(), p = _.length;
if (p > 0) {
const S = [];
for (let E = 0; E < p; E++) try {
const y = _[E].toJSON(h.toResourceId.bind(h));
y && S.push(y);
} catch (y) {
console.warn("Unable to persist movable", y);
}
S.length > 0 && (t.movables = S);
}
this._ownResources && (t.resources = await h.toJSONAsync());
} catch (_) {
console.warn(_);
} finally {
h.endPersist();
}
const u = zn(n.tableSpatial.all()), d = u.length;
if (d > 0) {
const _ = [];
for (let p = 0; p < d; p++) {
const S = u[p].value.model.toJSON();
_.push(S);
}
t.tables = _;
}
const g = Array.from(n.conditionalModels.values()), m = g.length;
if (m > 0) {
const _ = [];
for (let p = 0; p < m; p++) {
const S = g[p].model.toJSON();
_.push(S);
}
t.conditionals = _;
}
const f = await n.calcGraph.toJSON(!1);
if (f) {
const _ = f.formulas;
_ && (t.formulas = _);
const p = f.dynamic;
p && (t.dynamicArray = p);
const S = f.volatile;
S && (t.volatile = S);
}
return this._emitter.notify("onSave", { params: t }), t;
}
getStyles() {
return this._styles;
}
getResources() {
return this._resources;
}
getTransactions() {
return this._transactions;
}
getStrings() {
return this._strings;
}
_searchMovables(e) {
const t = e?.excludeHidden ?? !1, n = e?.bounds, r = e?.fullyContained, o = this, s = e?.address ? this._rangeToCoords(e?.address) : this._entireCoords;
return this._getRangedEntries("movableSpatial", [s], { excludeHidden: t, fullyContained: r, onEntry: (i) => {
if (e?.type && i.model.getContent().getType() !== e.type) return null;
let l = null;
if (t && (i.model.isHidden() || (l = o._getBoundsAtCoords(i.model.getAnchorCoords()), l.width === 0 || l.height === 0)))
return null;
if (n) {
l || (l = o._getBoundsAtCoords(i.model.getAnchorCoords()));
const c = l, h = n;
if (c.y > h.y + h.height || c.y + c.height < h.y || c.x > h.x + h.width || c.x + c.width < h.x) return null;
}
return i.model;
} }).sort((i, l) => i.getZIndex() - l.getZIndex());
}
_updateSelectedMovables(e, t) {
const n = this.getView().getMovableSelection();
if (!n || n.length === 0) return;
let r = "Movables";
if (n.length === 1) {
const s = n[0];
r = Xr(s.getContent().getType()) ?? "Drawing";
}
const o = this._beginCommit({ description: `${t} ${r}` });
try {
const s = n.length;
for (let i = 0; i < s; i++)
e(n[i]);
o.commit();
} catch (s) {
throw o.rollback(), s;
}
}
async _addMovable(e) {
if (!this.getProtection().isObjectsAllowed()) throw new Error(su);
if (!e) throw new Error("No movable options provided");
if (this._closed) throw new Error(xt);
const t = {};
e?.type && (t.content = { type: e.type, json: e?.json }), e?.anchorType && (t.anchorType = e?.anchorType), e.bounds && (t.anchor = null);
const n = this._getState().movableSpatial, r = this._beginCommit({ description: e?.description ?? "Insert Drawing" }), o = this._createMovableEntry(t, n.size(), e.fromResourceId), s = n.clone();
s.insert(o);
const i = this._getState().movableMapModel, l = new Map(i), c = o.value.model;
l.set(c, o), this._updateState({ movableSpatial: s, movableMapModel: l }), e.bounds && o.value.model.setBounds(e.bounds, e);
let h = null, u = null;
if (e?.autoSelect !== !1) {
h = { view: this.getView(), movableSelection: this.getView().getMovableSelection() };
let d = e?.autoSelect ?? !1;
d === !0 && (d = { autoFocus: !0, scrollIntoView: !0, addToSelection: !1 }), d && this.getView().selectMovables([o.value.model], d.addToSelection), u = (g) => ({ ...g, view: this.getView(), movableSelection: this.getView().getMovableSelection() });
}
return r.commit({ viewBefore: h, viewAfter: u }), this._emitterMovables.notify("onCollectionChange"), this._emitter.notify("onMovablesChange"), o.value.model;
}
async _addImage(e, t = { type: "picture" }) {
if (!e) throw new Error("An image must be provided as a string or a resource option.");
if (!this.getProtection().isObjectsAllowed()) throw new Error(su);
const n = this._resources.add(e), r = await n.toBuffer(), o = await n.getType(), s = this._getBoundsAtCoords(Lr(this.getSelection().getCoords())[0]), { naturalDimensions: i, asUrl: l } = await js.loadImageDetails(r, o);
URL.revokeObjectURL(l);
const c = { ...s, ...i, ...t?.bounds };
if (F.isNullOrUndefined(t?.bounds?.x) || F.isNullOrUndefined(t?.bounds?.y)) {
const u = dd(this.getMovables(), c, F.isNullOrUndefined(t?.bounds?.x), F.isNullOrUndefined(t?.bounds?.y));
c.x += u.x, c.y += u.y;
}
t?.bounds && t?.json?.lockAspect !== !1 && (F.isNullOrUndefined(t?.bounds.width) && F.isDefined(t?.bounds.height) && (c.width = c.height * i.width / i.height), F.isNullOrUndefined(t?.bounds.height) && F.isDefined(t?.bounds.width) && (c.height = c.width * i.height / i.width));
const h = { ...t?.json, resId: 0 };
return await this._addMovable({ anchorType: bt.Type.OneCell, description: "Insert Image", ...t, bounds: c, type: "picture", json: h, fromResourceId: (u) => u !== 0 ? (console.warn("received an unexpected resourceId", u), null) : n });
}
getTables() {
return this._tables;
}
getConditionals() {
return this._conditionals;
}
getMovables() {
return this._movables;
}
_doPerfTest(e = 1e7, t = !1) {
const n = Array.from({ length: e }, (l, c) => c);
let r, o;
r = performance.now(), t && console.profile("nativeArray");
const s = [e];
for (let l = 0; l < e; l++) s.push(l);
t && console.profileEnd("nativeArray"), window.noLoseArray = s, o = performance.now(), console.log(`NativeArray: ${e} records in ${o - r} milliseconds`), r = performance.now(), t && console.profile("mixedType");
const i = Ri.fromArray(n);
t && console.profileEnd("mixedType"), window.noLoseList = i, o = performance.now(), console.log(`MixedTypedList: ${e} records in ${o - r} milliseconds`);
}
_validateOrRemoveOverlaps(e, t, n = null, r = !1) {
const o = this;
t !== "merge" && Uh(this._getMerges([e]), e, (c, h) => {
if (h || !r) throw new Error(iu(t));
o._unmerge([c]);
});
const s = [], i = this.getTables().getItems({ address: e }), l = i.length;
for (let c = 0; c < l; c++) {
const h = i[c];
n !== h && s.push(h.getAnchorCoords());
}
Uh(s, e, (c, h, u) => {
if (h || !r) throw new Error(iu(t));
i[u].delete();
});
}
_addTable(e, t) {
let n = this._rangeToCoords(e, () => ["objects"]);
const r = this._entireCoords;
let o = t?.hasHeader;
if (n.rowStart === n.rowEnd) {
if (n.rowEnd === r.rowEnd) throw new Error("A table must have a least two rows; one for the table header and one for data.");
n.rowEnd = n.rowEnd + 1;
}
o === void 0 && (o = Lu(this, n)?.options?.hasHeader ?? !1);
const s = Pe([n]), i = { ...n }, l = this._beginCommit({ description: "Insert Table" });
let c = null;
try {
o || (this._isContentful([n]) && this._insertCells([{ ...n, rowStart: n.rowStart, rowEnd: n.rowStart }], O.Orientation.Row), n = { ...n, rowEnd: n.rowEnd + 1 });
const h = { ...t?.json, ref: n };
this._validateOrRemoveOverlaps(n, "table", null, !0), h.styleOptions = t?.json?.styleOptions ?? {}, h.styleOptions.name === void 0 && (t?.styleName ? h.styleOptions.name = t.styleName : t?.styleName === void 0 && (h.styleOptions.name = this._styles.getDefaultTableStyle().getName()));
const u = t?.isLoad;
u !== !0 && (h.filter === void 0 && (h.filter = {}), h.sort === void 0 && (h.sort = {}));
const d = this._createTableEntry(h, o && !u), g = this._getState(), m = g.tableSpatial.clone();
m.insert(d);
const f = g.tableMapModel, _ = new Map(f), p = d.value.model;
_.set(p, d);
const S = g.tableMapName, E = new Map(S);
E.set(p.getName().toLocaleLowerCase(), p), t?.clearFormatting && this.getRange(n).updateStyle(null), c = d.value.model, this._updateState({ tableSpatial: m, tableMapModel: _, tableMapName: E }), this._emitter.notify("onTablesChange"), u || this._autoFit([c.getHeaderRange().getCoords()], { expandOnly: !0 });
const y = Pe([n]);
l.commit({ viewBefore: { view: this.getView(), selection: s, ranges: [i] }, viewAfter: { view: this.getView(), selection: y, ranges: [n] } });
} catch (h) {
throw l.rollback(), h;
}
return c;
}
_addConditional(e, t) {
const n = this._rangesToCoords(e, () => ["objects"]), r = t?.autoSelect ? Pe(n) : null, o = [...n], s = this._beginCommit({ description: t?.description ?? "Insert Conditional" });
let i = null;
try {
const l = { ...t, ref: o }, c = this._getState(), h = c.conditionalSpatial.clone(), u = new Map(c.conditionalModels), d = this._createConditionalEntries(l, h, u);
this._updateState({ conditionalSpatial: h, conditionalModels: u }), i = d, s.commit({ viewBefore: { view: this.getView(), selection: r, ranges: o }, viewAfter: { view: this.getView(), selection: r, ranges: o } }), this._autoSelect(t?.autoSelect, r);
} catch (l) {
throw s.rollback(), l;
}
return i;
}
createTemporaryCell(e, t = null) {
return e?.createTemporaryCell ? e : (t ? this.getRange(t).getCell() : this._emptyCell).createTemporaryCell(e);
}
_getBoundsAtCoords(e) {
const t = this._rowHeaders, n = this._colHeaders, r = n.findOffset(e.colStart), o = t.findOffset(e.rowStart);
return { x: r, y: o, width: n.findOffset(e.colEnd + 1) - r, height: t.findOffset(e.rowEnd + 1) - o };
}
_getCoordsAtBounds(e) {
const t = this._rowHeaders, n = this._colHeaders;
return { colStart: n.findIndex(e.x), rowStart: t.findIndex(e.y), colEnd: n.findIndex(e.x + e.width), rowEnd: t.findIndex(e.y + e.height) };
}
getRangeAtBounds(e, t) {
if (!e) throw new Kt();
const n = this._getCoordsAtBounds(e);
return this.getRange(n, t);
}
_getVisible(e, t) {
if (e.length === 0) return e;
const n = new Ne();
n.load(e);
const r = t?.orientations ?? O.Orientations.Both, o = (i, l) => {
const c = n.search(i), h = c.length;
for (let u = 0; u < h; u++) {
const d = c[u], g = Nl(d, i, l);
n.remove(d), n.load(g);
}
}, s = this._cellOptions.maxCoords;
if (r === O.Orientations.Both || r === O.Orientations.Row) {
const i = this._rowHeaders, l = e.length;
for (let c = 0; c < l; c++) {
const h = e[c];
i.getRange({ min: h.rowStart, max: h.rowEnd }).forEachSpan((u, d) => {
if (u !== 0) return;
const g = d.getCoords();
o({ colStart: s.colStart, rowStart: g.min, colEnd: s.colEnd, rowEnd: g.max }, O.Orientation.Row);
});
}
}
if (r === O.Orientations.Both || r === O.Orientations.Column) {
const i = this._colHeaders, l = e.length;
for (let c = 0; c < l; c++) {
const h = e[c];
i.getRange({ min: h.colStart, max: h.colEnd }).forEachSpan((u, d) => {
if (u !== 0) return;
const g = d.getCoords();
o({ colStart: g.min, rowStart: s.rowStart, colEnd: g.max, rowEnd: s.rowEnd }, O.Orientation.Column);
});
}
}
return n.all();
}
_hasRangedEntries(e, t) {
const n = this._getState();
if (!n) return F.EmptyArray;
const r = n[e];
if (!r) throw new Error(`Invalid range key ${e}`);
return !(!r || r.isEmpty()) && r.has(t);
}
_getRangedEntries(e, t, n) {
if (t.length === 0) return F.EmptyArray;
const r = n?.excludeHidden ?? !1, o = n?.fullyContained ?? !1, s = n?.onEntry ?? null, i = this._getState();
if (!i) return F.EmptyArray;
const l = i[e];
if (!l) throw new Error(`Invalid range key ${e}`);
if (!l || l.isEmpty()) return F.EmptyArray;
const c = /* @__PURE__ */ new Set(), h = (_) => {
const p = _.length;
for (let S = 0; S < p; S++) {
const E = _[S];
c.add(E);
}
}, u = t.length;
for (let _ = 0; _ < u; _++) {
const p = t[_];
if (r) {
if (r === !0) {
const S = { min: p.colStart, max: p.colEnd }, E = { min: p.rowStart, max: p.rowEnd };
this._rowHeaders.getRange(E).forEachVisibleSpan((y, C) => {
this._colHeaders.getRange(S).forEachVisibleSpan((w, b) => {
h(l.search({ colStart: w, rowStart: y, colEnd: b, rowEnd: C }, o));
}, zs);
}, zs);
} else if (r === O.Orientation.Column) {
const S = { min: p.colStart, max: p.colEnd };
this._colHeaders.getRange(S).forEachVisibleSpan((E, y) => {
h(l.search({ colStart: E, rowStart: p.rowStart, colEnd: y, rowEnd: p.rowEnd }, o));
}, zs);
} else if (r === O.Orientation.Row) {
const S = { min: p.rowStart, max: p.rowEnd };
this._rowHeaders.getRange(S).forEachVisibleSpan((E, y) => {
h(l.search({ colStart: p.colStart, rowStart: E, colEnd: p.colEnd, rowEnd: y }, o));
}, zs);
}
} else h(l.search(p, o));
}
if (c.size === 0) return F.EmptyArray;
const d = Array.from(c.values()), g = n?.sort;
g && d.sort(D.createRangeComparator(g.orientation, g.reverse));
let m = [];
const f = d.length;
for (let _ = 0; _ < f; _++) {
let p;
p = void 0, s && (p = s(d[_].value, d[_])), p === void 0 && (p = d[_].value), p !== null && m.push(p);
}
return m || (m = F.EmptyArray), m;
}
_processAnchorShift(e) {
let t = e.after;
const n = D.sanitizeRange(e.after), r = D.sanitizeRange(e.before);
e.after && this._validateCoords(n, "We can't insert cells because this would push items off the end of the worksheet.");
const o = e.before.value.processShiftCallback?.({ ...e, after: n, before: r });
return o && (Po(o, n) || (t || (t = e.before), t = { ...t, ...o })), t;
}
_processListenerShift(e, t, n, r) {
if (r.isSplit || r.before.value.options.ignoreShifts) return [r.before];
let o = null;
r.after && (o = D.intersectRanges(D.sanitizeRange(r.after), this._entireCoords), r.after, o.colStart, o.rowStart, o.colEnd, o.rowEnd);
const s = r.before.value, i = s.id, l = e.get(i), c = { ...l }, h = [...l.ranges];
c.ranges = h, h[s.offset] = o ? { ...h[s.offset], ...o } : null, e.set(i, c);
const u = n.get(i);
t.set(i, { beforeState: u, afterState: c });
}
delete() {
if (this._closed) return;
try {
this._emitter.notify("onBeforeDelete");
} catch (s) {
throw s instanceof Error ? s : new Error(s.message ?? "Unable to delete.");
}
const e = this._beginCommit({ description: `Delete Sheet '${this.getName()}'` }), t = this._getState();
let n = t.rangeListenerSpatial, r = t.rangesListenerMap;
const o = /* @__PURE__ */ new Map();
n = n.shift({ range: this._entireCoords, direction: O.Direction.Left, cloneIfUpdate: n === t.rangeListenerSpatial, onShift: (s) => {
r === t.rangesListenerMap && (r = new Map(r)), this._processListenerShift(r, o, t.rangesListenerMap, s);
} }), this._updateState({ rangeListenerSpatial: n, rangesListenerMap: r, deleted: !0 }), this._deleteCells([this._entireCoords]), this._emitter.notify("onDelete"), this._rangesListenerMap.forEach((s, i) => {
o.set(i, { beforeState: s, afterState: null });
}), e.commit({ viewAfter: (s) => ({ ...s, view: this.getView(), selection: this.getSelection().getCoords(), listeners: o }) });
}
doBatch(e, t) {
const n = this;
return t = typeof t == "string" ? { description: t } : { description: "Update Sheet", ...t }, this._transactions.doBatch(e, t, (r, o) => {
if (r.getDepth() === 0 && (n._lastTransactionUUID = r.getId(), t?.autoSelect)) {
const s = r.getView()?.selection;
s && n._autoSelect(!0, s);
}
});
}
isClosed() {
return this._closed;
}
close() {
if (this._closed) return;
this._protectionRemoveListener?.(), this._protection = new Cd(void 0, this._options.readonly);
const e = this._getState().tableMapModel.keys();
for (const t of e) t.close();
this._searchMovables().forEach((t) => {
t.close();
}), this._emitter.notify("onClose"), this._ownResources, this._namesRemoveListener?.(), this._ownNames && this._names.close(), this._ownsCalculation && this._calculation.close(), this._ownStyles, this._colHeaders.close(), this._rowHeaders.close(), this._emitter.close(), this._transactionsRemoveListener?.(), this._closed = !0;
}
beginCommit(e) {
if (this._closed) throw new Error(xt);
return this._beginCommit(typeof e == "string" ? { description: e } : e);
}
_getState() {
return this._closed ? null : this._transactions.getState(this);
}
_beginCommit(e) {
const t = this;
return this._transactions.beginCommit(e, (n) => {
n.getDepth() === 0 && (t._lastTransactionUUID = n.getId());
});
}
_updateState(e) {
if (!e) return;
this._lastGetRangeRead = null;
const t = this._transactions.beginCommit();
let n;
try {
n = t.updateState(this, e), t.commit();
} catch (r) {
throw t.rollback(), r;
}
return n;
}
_addEvent(e, t) {
const n = this.getTransactions().getPendingView();
if (!n) return;
let r = n.events;
if (r || (r = {}, n.events = r), e === "address") {
let o = r.address;
if (o || (o = /* @__PURE__ */ new Map(), r.address = o), typeof t == "string") o.set(t, null);
else {
const s = t;
if (s.options.ignoreAddressChanges) return;
o.set(s.uuid, t);
}
} else if (e === "data") if (typeof t == "string") {
let o = r.dataListeners;
o || (o = /* @__PURE__ */ new Map(), r.dataListeners = o), o.set(t, null);
} else {
let o = r.data;
o || (o = [], r.data = o), o.push(t);
}
}
_getScalar(e, t, n = !1) {
const r = this._getState();
let o;
if (o === void 0 && (o = r.cellValuesGrid.getValueAt(e, t)), o === void 0) return null;
let s = o;
if (n && typeof s == "number") {
let i = !1;
Gt.colStart = t, Gt.rowStart = e, Gt.colEnd = t, Gt.rowEnd = e;
const l = this._lastValueRead, c = this._lastValueRead.range;
if (c && D.isRangeWithinRange(Gt, c)) i = l.isDateOrTime;
else {
const h = r.directStyleSpatial.search(Gt)[0];
if (h) {
const u = h.value.getPropertiesAt(e, t, s), d = u?.numberFormat;
d && (i = ts(d) || Wi(d)), l.range = h, l.isDateOrTime = i;
} else l.range = null;
i && (s = no(s, this._isDate1904));
}
}
return s;
}
getStyleUpdater(e, t) {
return null;
}
_initState() {
const e = this, t = () => {
e._lastCellDecoded.address = null, e._lastCellSelected.coords = null, e._lastCellRead.coords = null, e._lastValueRead.range = null, e._lastGetRangeRead = {}, e._lastUsedCoordsRead.coords = null, e._lastActiveRead.selection = null, e._lastRangeRead.address = null;
};
this._transactionsRemoveListener = this._transactions.addStateListener(this, { onBeforeCommitStart(f, _, p) {
if (!e._initializing && !_?.skipProtectionCheck && e.getProtection().isLocked())
throw new Error(bs);
}, async onBeforeCommitEnd(f, _, p) {
if (_?.ranges) {
const S = { isDataChange: !0, isTransactional: !0, timeStamp: p.getTimestamp(), trigger: "setCells" }, E = f.rangeListenerSpatial, y = f.rangesListenerMap;
e._notifyRangeListeners(E, y, _.ranges, S);
}
if (_?.listeners) {
const S = { isDataChange: !1, isTransactional: !0, timeStamp: p.getTimestamp(), trigger: "shiftCells" }, E = f.rangeListenerSpatial, y = f.rangesListenerMap;
e._notifyRangeListeners(E, y, _.ranges, S);
}
}, async onRestoreOrRevert(f, _, p, S) {
if (t(), e._calculateFull(), _ && (_.view === e.getView() && _.selection && e._autoSelect(!0, _.selection), _.movableSelection && e.getView().selectMovables(_.movableSelection)), e._emitter.notify("onInvalidated"), e._emitterMovables.notify("onInvalidated"), e._notifyUsedRangeChange(), e._rangesListenerMap.size > 0) {
const E = { isDataChange: !0, isTransactional: !1, timeStamp: p.getTimestamp(), isUndo: S, trigger: "invalidate" }, y = f.rangeListenerSpatial, C = f.rangesListenerMap, w = /* @__PURE__ */ new Set();
C.forEach((b, x) => {
const I = b.id;
if (w.has(I)) return;
const v = b.ranges;
v && (w.add(I), e._notifyRangeListeners(y, C, v, E));
});
}
}, async onAfterStateChange(f, _, p, S, E) {
t(), _ && p.getId() !== e._lastTransactionUUID && _.view === e.getView() && _.selection && (S || E) && e._autoSelect(!0, _.selection), e._lastTransactionUUID = p.getId(), _?.merges && e._notifyMergeChange();
const y = e._rangesListenerSorted;
if (y.size > 0) {
e._notifyUsedRangeChange();
const C = /* @__PURE__ */ new Set(), w = f.rangesListenerMap2, b = { isTransactional: !1, timeStamp: p.getTimestamp() };
if ((E || S) && (b.trigger = "restore", e._notifyAddressListeners(w, w, C, b), y.size > w.size)) {
const I = y.values();
let v = I.next(), R = !1;
for (; !R && !v.done; ) {
const A = v.value;
R = w.has(A.uuid), R || (A.notify(b, "#N/A"), v = I.next());
}
}
const x = _?.events;
x && (x.address && (b.trigger = "address", e._notifyAddressListeners(w, x.address, C, b)), x.dataListeners && (b.trigger = "data", e._notifyAddressListeners(w, x.dataListeners, C, b)), x.data && (b.trigger = "data", e._notifyDataListeners(f.rangesListenerSpatial2, f.rangesListenerMap2, x.data, C, b)));
}
if (_ && !_.calculationSideEffect && _.ranges && !_.initial && f.calcGraph.calculate(), _?.ranges) {
e._notifyUsedRangeChange();
const C = e._rangesListenerMap;
if (C.size > 0) {
const w = { isDataChange: !0, isTransactional: !1, timeStamp: p.getTimestamp(), isUndo: S, trigger: "setCells" };
e._notifyRangeListeners(e._rangeListenerSpatial, C, _.ranges, w);
}
}
}, onClose() {
const f = e._getState();
f && f.movableSpatial.clear();
} });
const n = new iw({ sheet: this }), r = { onChange() {
e._emitter.notify("onSelectionChange");
} }, o = n.addListeners(r, { transactional: !1 });
this._rangeSelection = n, this._rangeSelectionRemoveListener = o;
const s = (f) => {
const _ = e._getState();
if (!_) return;
const p = _.movableSpatial, S = f.length;
for (let E = 0; E < S; E++) {
const y = p.search(f[E]), C = y.length;
for (let w = 0; w < C; w++)
y[w].value.processLayoutCallback?.();
}
};
this._colHeadersListener = { onSizesChange: (f, _) => {
const p = [];
if (_) {
const S = _.length;
for (let E = 0; _ && E < S; E++) {
const y = { colStart: _[E].min, rowStart: e._entireCoords.rowStart, colEnd: e._entireCoords.colEnd, rowEnd: e._entireCoords.rowEnd };
p.push(y);
}
}
s(p);
} }, this._rowHeadersListener = { onSizesChange: (f, _) => {
const p = [];
if (_) {
const S = _.length;
for (let E = 0; E < S; E++) {
const y = _[E], C = { colStart: e._entireCoords.colStart, rowStart: y.min, colEnd: e._entireCoords.colEnd, rowEnd: e._entireCoords.rowEnd };
p.push(C);
}
}
s(p);
} };
let i = /* @__PURE__ */ new Set();
const l = { onTopLeftChange() {
e._emitter.notify("onTopLeftChange");
}, onFreezeSplitChange() {
e._emitter.notify("onFreezeSplitChange");
}, onRangeSelectionChange() {
const f = e.getSelection().getCoords();
e._rangeSelection.updateCoords(f);
}, onMovableSelectionChange(f) {
const _ = f.getMovableSelection(), p = /* @__PURE__ */ new Map(), S = /* @__PURE__ */ new Set(), E = e._getState().movableMapModel, y = _.length;
for (let C = 0; C < y; C++) {
const w = _[C];
i.has(w) ? i.delete(w) : p.set(w, C), S.add(w);
}
i.forEach((C) => {
E.get(C)?.value.processSelectionCallback(!1, !1);
}), p.forEach((C, w) => {
E.get(w)?.value.processSelectionCallback(!0, C === 0);
}), i = S, e._emitter.notify("onMovableSelectionChange");
}, onAnyChange() {
e._emitter.notify("onViewChange");
} }, c = new ll({ sheet: this });
this._view = c, this._clearState(), this._viewRemoveListener = c.addListeners(l, { transactional: !1 }), this._viewListener = l, this._colHeadersRemoveListener?.();
const h = () => Math.round(this._defaultFontDims().width);
this._colHeaders = new _d({ sheet: e, orientation: O.Orientation.Column, maxSheetCoords: this._entireCoords, transactions: this._transactions, isProtected: () => !e._initializing && !e.getProtection().isFormatColumnsAllowed(), getTextAt: (f) => {
const _ = this.getView().getColumnHeaderStyle();
return _ === nn.HeaderTextStyle.A1 ? vd(f) : _ === nn.HeaderTextStyle.Zero ? bd(f) : _ === nn.HeaderTextStyle.One ? xd(f) : void 0;
}, defaultSize: () => {
const f = this.getView().isShowFormulas() ? 2 : 1;
return this._defaultColWidth() / h() * f;
}, scaleFactor: h, maxSize: () => 255, setContainerShiftedCallback: (f) => {
this._colHeadersShiftCallback = f;
} }), this._colHeadersRemoveListener = this._colHeaders.addListeners(this._colHeadersListener, { transactional: !0 }), this._rowHeadersRemoveListener?.();
const u = te.getDeviceScale();
this._rowHeaders = new _d({ sheet: e, orientation: O.Orientation.Row, maxSheetCoords: this._entireCoords, transactions: this._transactions, isProtected: () => !e._initializing && !e.getProtection().isFormatRowsAllowed(), getTextAt: (f) => {
const _ = this.getView().getRowHeaderStyle();
return _ === nn.HeaderTextStyle.One ? xd(f) : _ === nn.HeaderTextStyle.Zero ? bd(f) : _ === nn.HeaderTextStyle.A1 ? vd(f) : void 0;
}, defaultSize: () => this._defaultRowHeight(), scaleFactor: () => u, minSize: () => 0, maxSize: () => 409, setContainerShiftedCallback: (f) => {
this._rowHeadersShiftCallback = f;
} }), this._rowHeadersRemoveListener = this._rowHeaders.addListeners(this._rowHeadersListener, { transactional: !0 }), this._defaultFontBoundsCache = null, this._defaultColWidthCache = null, this._defaultRowHeightCache = null;
const d = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0 }, g = [d], m = { excludeHidden: !0, sort: { orientation: O.Orientation.Column, reverse: !1 } };
this._cellOptions = { resolveRange: (f) => {
if (f === null) return this._createRange(null, void 0, "temporary cell");
const _ = this._rangesToCoords(f);
return this._createRange(_[0], null);
}, date1904: this._isDate1904, sheet: this, normalStyleRanged: this._normalStyleRanged, colHeaders: this._colHeaders, styles: this._styles, maxCoords: this._entireCoords, getRange: this.getRange.bind(this), getProtection: this.getProtection.bind(this), calcGraph: () => this._getState().calcGraph, nextContentful: (f, _, p = !1) => {
d.colStart = p ? _ : f.colIndex + 1, d.rowStart = f.rowIndex, d.colEnd = p ? f.colIndex - 1 : _, d.rowEnd = f.rowIndex, m.sort.reverse = p;
const S = e._getRangedEntries("contentfulSpatial", g, m);
if (!S || S.length === 0) return _;
const E = S[0], y = p ? E.getState().colStart : E.getState().colEnd;
return p ? Math.min(y + 1, f.colIndex) : Math.max(y - 1, f.colIndex);
}, opener: async (f, _, p, S) => {
if (f.startsWith("#")) {
f = f.substring(1);
const E = this._rangesToCoords(f);
return await this._autoSelect(_ ?? !0, Pe(E)), !0;
}
return window.open(f, p ?? "_blank", S), !0;
} }, this._emptyCell = new hS(this._cellOptions);
}
_clearState() {
this._lastGetRangeRead = null, this._lastCellDecoded.address = null, this._lastCellSelected.coords = null, this._lastCellRead.coords = null, this._protectionRemoveListener?.(), this._protection = new Cd(void 0, this._options.readonly), this._protectionRemoveListener = this._protection.addListeners({ onChange() {
if (e._closed) throw new Error(xt);
e._getState().movableMapModel.forEach((i) => {
i.value.processProtectionCallback?.();
}), e._getState().tableMapModel.forEach((i) => {
i.value.processProtectionCallback?.();
}), e._emitter.notify("onProtectionChange");
} }), this._stylesRemoveListener?.();
const e = this;
this._stylesRemoveListener = this._styles.addListeners({ onAnyChange() {
e._defaultColWidthCache = null, e._defaultRowHeightCache = null, e._defaultFontBoundsCache = null, e._emitter.notify("onLayoutChange"), e._emitter.notify("onStyleChange");
} }), this._view.clear(!1), this._rangeListenerSpatial = new Ne(), this._rangesListenerMap = /* @__PURE__ */ new Map(), this._rangesListenerSorted = new Ae();
const t = (i) => {
const l = e._getState().rangesListenerSpatial2;
if (l.isEmpty()) return;
const c = i.length;
for (let h = 0; h < c; h++) {
const u = i[h], d = l.search(u), g = d.length;
for (let m = 0; m < g; m++) {
const f = d[m].value.groupId;
e._addEvent("data", f);
}
}
}, n = this._entireCoords, r = n.rowEnd, o = n.colEnd, s = this._calculation._createGraph({ onCalculated(i) {
e._realizeCalcedValues(i);
}, getEntireCoords: () => e._entireCoords, getSheetName: () => e.getName() });
s.addListeners({ onStart(i) {
}, onInvalidate: () => {
} }), this._updateState({ rangesListenerSpatial2: new Ne({ updateEntryOptions: { onShifted: (i) => {
let l = e._getState().rangesListenerMap2;
if (l.size === 0) return;
l = new Map(l);
const c = i.length;
for (let h = 0; h < c; h++) {
const u = i[h], d = u.value.groupId;
let g = l.get(d);
g = g.processShift(u), e._addEvent("address", g), l.set(d, g);
}
e._updateState({ rangesListenerMap2: l });
}, onRemoved: (i) => {
let l = e._getState().rangesListenerMap2;
if (l.size === 0) return;
l = new Map(l);
const c = i.length;
for (let h = 0; h < c; h++) {
const u = i[h], d = u.value.groupId;
let g = l.get(d);
g = g.processRemove(u), e._addEvent("address", g), l.set(d, g);
}
e._updateState({ rangesListenerMap2: l });
} } }), rangesListenerMap2: /* @__PURE__ */ new Map(), cellValuesGrid: new sn({ orientation: this._isDataColumn ? O.Orientation.Column : O.Orientation.Row }), formulaSpatial: new Ne(), spillSpatial: new Ne(), pendingSpatial: new Ne(), calcErrorsSpatial: new Ne(), calcGraph: s, directStyleSpatial: new Ne({ updateEntryOptions: { isMergeOnShift: !0, isTrailingEdge: !0, onUpdated: t, onRemoved: t } }), continuousFillSpatial: new Ne({ updateEntryOptions: { isMergeOnShift: !0, isTrailingEdge: !0 } }), conditionalModels: /* @__PURE__ */ new Map(), conditionalSpatial: new Ne({ updateEntryOptions: { onGroupUpdate(i, l) {
let c = e._getState().conditionalModels, h = c.get(l);
if (!h) return;
c = new Map(c);
const u = h.spatials;
h = { ...h }, h.spatials = i, c.set(l, h), e._updateState({ conditionalModels: c }), h.processCoordsChange({ before: u, after: h.spatials });
} } }), mergeSpatial: new Ne({ updateEntryOptions: { getShifted: (i, l) => l ? (l.value = new Sd(D.sanitizeRange(l), i.value._tvTl), l) : null, getSplit(i, l) {
throw new Error("We can't insert through merges. Unmerge and try again.");
}, onUpdated: t, onRemoved: t } }), movableMapModel: /* @__PURE__ */ new Map(), movableSpatial: new Ne({ updateEntryOptions: { getShifted(i, l, c) {
const h = i.value.processShiftCallback?.(c);
let u = null;
const d = new Map(e._getState().movableMapModel), g = i.value.model;
return h ? (u = { ...h, value: { ...i.value } }, d.set(g, u)) : d.delete(g), e._updateState({ movableMapModel: d }), u;
} } }), hyperlinkSpatial: new Ne({ updateEntryOptions: { isSplitOnExpand: !0, isMergeOnShift: !0 } }), commentsSpatial: new Ne({ updateEntryOptions: { isSplitOnExpand: !0, isMergeOnShift: !0, onUpdated: t, onRemoved: t } }), tableMapModel: /* @__PURE__ */ new Map(), tableMapName: /* @__PURE__ */ new Map(), tableSpatial: new Ne({ updateEntryOptions: { getShifted(i, l, c) {
const h = new Map(e._getState().tableMapModel), u = i.value.model, d = i.value.processShiftCallback?.(c);
let g = null;
return d ? (g = { ...d, value: { ...l.value } }, h.set(u, g)) : h.delete(u), e._updateState({ tableMapModel: h }), g;
} } }), filter: null, sort: null, rangeListenerSpatial: new Ne(), rangesListenerMap: /* @__PURE__ */ new Map(), contentfulSpatial: new Ne({ updateEntryOptions: { isSplitOnExpand: !0, isMergeOnShift: !0, onShifted: (i) => {
const l = e._getState().rangesListenerSpatial2;
if (l.size() === 0) return;
const c = i.length;
for (let h = 0; h < c; h++) {
const u = i[h], d = l.search({ colStart: u.colStart, rowStart: u.rowStart, colEnd: o, rowEnd: r }), g = d.length;
for (let m = 0; m < g; m++) {
const f = d[m].value.groupId;
e._addEvent("data", f);
}
}
}, onRemoved: t, onUpdated: t } }), unlockSpatial: new Ne({ updateEntryOptions: { isMergeOnShift: !0 } }), deleted: !1 }), this._defaultFontBoundsCache = null, this._defaultColWidthCache = null, this._defaultRowHeightCache = null;
}
_createTableEntry(e, t = !1) {
const n = { model: null, processShiftCallback: null, processDeleteCallback: null, processProtectionCallback: null, currentName: null, removeListener: null };
let r = null;
r = typeof e.ref == "string" ? Pt(e.ref, this._entireCoords) : e.ref;
const o = { ...r, value: n }, s = this, i = () => n.model ? s._getState().tableMapModel?.get(n.model) : o, l = (u, d) => !(!D.isEqualRanges(u, d) || u.value.model !== d.value.model), c = { transactions: this._transactions, sheet: this, names: this._names, readSheetHeader: t, json: e, maxRangeCoords: this._entireCoords, setNameOnContainer(u) {
const d = i().value;
if (!d.currentName || d.currentName.toLowerCase() === u.toLowerCase()) return;
const g = "Set Table Name";
s._protectionCheck(() => ["objects"], void 0, g);
const m = s._beginCommit({ description: g });
try {
const f = s._getState()?.tableMapName, _ = u.toLocaleLowerCase();
if (f.has(_)) throw new Error(((S) => `Name must be unique: '${S}' is already in use.`)(u));
const p = new Map(f);
p.delete(d.currentName), d.currentName = _, p.set(_, d.model), s._updateState({ tableMapName: p }), m.commit();
} catch (f) {
throw m.rollback(), f;
}
}, setContainerCoords(u, d) {
if (!u) return;
const g = s._rangeToCoords(u, () => ["objects"]), m = i();
if (!m) return;
const f = m.value.model;
s._validateOrRemoveOverlaps(g, "table", f);
const _ = s._beginCommit({ description: d?.description ?? "Resize Table" }), p = s._getState(), S = p.tableSpatial.clone(), E = p.tableMapModel, y = new Map(E);
S.remove(m, l);
const C = { ...m, ...g };
return S.insert(C), y.set(C.value.model, C), s._updateState({ tableSpatial: S, tableMapModel: y }), _.commit({ viewAfter: { view: s.getView(), selection: Pe([h.getAnchorCoords()]) } }), g;
}, deleteFromContainer(u) {
const d = i();
if (!d) return;
const g = d.value.model, m = u?.description ?? `Delete Table '${g.getName()}`;
s._protectionCheck(() => ["objects"], void 0, m);
const f = s._beginCommit({ description: m }), _ = s._getState(), p = _.tableSpatial.clone(), S = _.tableMapModel, E = new Map(S), y = _.tableMapName, C = new Map(y);
p.remove(d, l), E.delete(g), C.delete(g.getName().toLocaleLowerCase()), d.value.processDeleteCallback?.(), s._updateState({ tableSpatial: p, tableMapModel: E, tableMapName: C }), s._emitter.notify("onTablesChange"), f.commit({ viewAfter: { sheet: s, view: s.getView(), selection: Pe([g.getAnchorCoords()]) } });
}, setContainerDeleteCallback(u) {
const d = i()?.value ?? n;
d && (d.processDeleteCallback = u, d.removeListener?.());
}, isProtected: () => !s._initializing && s.getProtection().isLocked(), setContainerProtectionCallback(u) {
(i()?.value ?? n).processProtectionCallback = u;
}, setContainerShiftCallback(u) {
(i()?.value ?? n).processShiftCallback = u;
}, processTableUpdate() {
s._notifyUsedRangeChange();
}, initialAnchor: r }, h = new yS(c);
return o.value.model = h, o.value.removeListener = h.addListeners({ onStyleChange(u) {
s._emitter.notify("onStyleChange");
}, onDelete(u) {
s._emitter.notify("onStyleChange");
} }, { transactional: !1 }), o.value.currentName = h.getName().toLocaleLowerCase(), o;
}
_createConditionalEntries(e, t, n) {
const r = "Conditional Format", o = () => ["objects"], s = e ?? {};
let i = null;
const l = this._entireCoords;
if (typeof s.ref == "string") {
i = [];
const p = s.ref.split(","), S = p.length;
for (let E = 0; E < S; E++) {
const y = Pt(p[E], l);
y && i.push(y);
}
} else i = Array.isArray(s.ref) ? s.ref : [s.ref];
const c = this, h = F.uuidV4(), u = { model: null, removeListener: null, processCoordsChange: null, spatials: null };
n.set(h, u);
const d = () => u.model ? c._getState().conditionalModels.get(h) : u;
let g = (p) => (console.log("default createSpatialEntry", p), null);
const m = (p, S, E) => {
if (!u.model) return void (i = p);
let y = S.spatials;
if (y) {
const w = y.length;
for (let b = 0; b < w; b++) E.remove(y[b]);
}
let C = [];
if (p) {
const w = p.length;
for (let b = 0; b < w; b++) {
const x = p[b];
C.push({ ...x, value: g(x) });
}
C.length > 0 && E.insertGroup(C, h);
}
S.spatials = C;
}, f = () => {
const p = d().spatials ?? i;
return p ? c.getRanges(p) : null;
};
var _;
return u.model = (_ = { sheet: c, transactions: c._transactions, json: e, type: "conditional", setOnContainerCoordsChange: (p) => {
d().processCoordsChange = p;
}, setCreateSpatial(p) {
g = p;
}, setContainerRanges: (p, S) => {
const E = c._rangesToCoords(p, o);
if (!u.model) return i = E, E && E.length > 0 ? c.getRanges(E) : null;
const y = c._beginCommit({ description: S?.description ?? `Set ${r} Ranges` });
let C = Pe(E);
try {
const w = c._getState();
let b = w.conditionalSpatial;
b = b.clone();
let x = w.conditionalModels;
x = new Map(x);
let I = d();
I = { ...I }, x.set(h, I), m(E, I, b), c._updateState({ conditionalSpatial: b, conditionalModels: x }), y.commit({ viewBefore: { view: c.getView(), selection: Pe(f()?.getCoords()) }, viewAfter: { view: c.getView(), selection: C } }), c._autoSelect(S?.autoSelect, C);
} catch (w) {
throw y.rollback(), w;
}
return E && E.length > 0 ? c.getRanges(E) : null;
}, getContainerRanges: f, deleteFromContainer(p) {
let S = d();
const E = c._beginCommit({ description: p?.description ?? `Set ${r} Ranges` }), y = p?.autoSelect ? Pe(S.spatials) : void 0;
try {
const C = c._getState();
let w = C.conditionalSpatial;
w = w.clone();
let b = C.conditionalModels;
b = new Map(b), S = { ...S }, m(null, S, w), b.delete(h), c._updateState({ conditionalSpatial: w, conditionalModels: b }), this._commitAndAutoSelect(E, y, p?.autoSelect);
} catch (C) {
throw E.rollback(), C;
}
}, isReadOnly: () => !1, setContainerReadOnlyCallback(p) {
} }, new aw({ ..._, createDescription: `New ${r}` })), u.removeListener = u.model.addListeners({ onAnyChange(p) {
c._emitter.notify("onStyleChange");
} }, { transactional: !1 }), m(i, u, t), u.model;
}
_createMovableEntry(e, t, n) {
let r = null;
if (e?.anchor) r = { colStart: e.anchor.tl?.c ?? 0, rowStart: e.anchor.tl?.r ?? 0, colEnd: e.anchor.br?.c ?? 0, rowEnd: e.anchor.br?.r ?? 0 }, e.anchor.br?.x || (r.colEnd -= 1), e.anchor.br?.y || (r.rowEnd -= 1);
else {
const y = Lr(this.getSelection().getCoords())[0];
r = { colStart: y.colStart, rowStart: y.rowStart, colEnd: y.colEnd, rowEnd: y.rowEnd };
}
const o = { model: null, processShiftCallback: null, processLayoutCallback: null, processDeleteCallback: null, processZIndexCallback: null, processSelectionCallback: null, processProtectionCallback: null, zIndex: t }, s = { ...r, value: o }, i = () => o.model ? h._getState()?.movableMapModel?.get(o.model) : s, l = (y, C) => !(!D.isEqualRanges(y, C) || y.value.model !== C.value.model), c = (y, C, w = !0) => {
if (d) return;
const b = i();
if (!b) return;
const x = C ?? "Update Drawing";
h._protectionCheck(() => ["objects"], void 0, x);
const I = h._beginCommit({ description: x }), v = h._getState()?.movableSpatial, R = v.clone(), A = h._getState()?.movableMapModel, M = new Map(A);
y(b, R, M) !== !1 && (h._updateState({ movableSpatial: R, movableMapModel: M }), w && (h._emitterMovables.notify("onCollectionChange", { source: h, transactional: !0 }), h._emitter.notify("onMovablesChange")), I.commit({ viewAfter: (T) => {
if (s.value.model.isSelected() && !T?.movableSelection?.includes(s.value.model)) {
const k = [...T?.movableSelection ?? []];
return k.push(s.value.model), { ...T, view: this.getView(), movableSelection: k };
}
} }));
}, h = this, u = e.content.type;
let d = !0;
const g = (y, C, w, b) => {
const x = w.all().sort((B, H) => B.value.zIndex - H.value.zIndex), I = C.value.zIndex;
if ((y = Math.max(0, Math.min(x.length - 1, y))) === I) return !1;
const v = [], R = [], A = [], M = I < y, T = (B) => {
const H = x[B];
v.push(H);
const z = { ...H, value: { ...H.value, zIndex: M ? B - 1 : B + 1 } };
H.value.zIndex === I && (z.value.zIndex = y), R.push(z), b.set(z.value.model, z), A.push(z);
};
if (M) for (let B = I; B <= y; B++) T(B);
else for (let B = I; B >= y; B--) T(B);
const k = v.length;
for (let B = 0; B < k; B++) w.remove(v[B], l);
w.load(R);
const P = A.length;
for (let B = 0; B < P; B++) A[B].value.processZIndexCallback?.();
}, m = () => h._resources.beginPersist(), f = u === "picture", _ = { content: null, fromResourceId: n, defaultLockAspectRatio: f, beginPersistResource: m, getMaxBounds: () => h._getBoundsAtCoords(h._entireCoords), transactions: this._transactions, getBoundsAtCoords: h._getBoundsAtCoords.bind(h), getCoordsAtBounds: h._getCoordsAtBounds.bind(h), scrollIntoView: (y) => h._selectSheet(i()?.value.model.getAnchorCoords(), y), select: async (y) => {
const C = i()?.value.model;
if (!C) return !1;
try {
h.getView().selectMovables([C], y?.addToSelection);
} catch (b) {
return console.warn(b), !1;
}
const w = await h._selectSheet(i()?.value.model.getAnchorCoords(), y?.scrollIntoView);
return !y?.scrollIntoView || w !== !1;
}, unselect: () => {
const y = i()?.value.model;
return !!y && (h.getView().unselectMovables([y]), !0);
}, isSelected: () => h.getView().getMovableSelection().includes(i()?.value.model), setContainerSelectionCallback(y) {
(i()?.value ?? o).processSelectionCallback = y;
}, moveToBackOnContainer: () => {
c((y, C, w) => g(0, y, C, w), "Move to Back");
}, moveBackwardOnContainer: () => {
c((y, C, w) => g(y.value.zIndex - 1, y, C, w), "Move Backwards");
}, moveForwardOnContainer() {
c((y, C, w) => g(y.value.zIndex + 1, y, C, w), "Move Forward");
}, moveToFrontOnContainer() {
c((y, C, w) => g(C.size() - 1, y, C, w), "Move To Front");
}, getZIndex: () => i()?.value.zIndex ?? 0, setContainerZIndexCallback(y) {
(i()?.value ?? o).processZIndexCallback = y;
}, setContainerCoords(y) {
if (!y) return;
const C = h._rangeToCoords(y, () => ["objects"]);
return c((w, b, x) => {
const I = { ...w, ...C };
b.remove(w, l), b.insert(I), x.set(I.value.model, I);
}, "Update Drawing", !1), C;
}, deleteFromContainer(y) {
const C = i();
C?.value && h.getView().unselectMovables([C.value.model]);
const w = [];
c((x, I, v) => {
v.delete(x.value.model), I.remove(x, l), x.value.processDeleteCallback?.(), w.push(x);
const R = x.value.model.getZIndex(), A = I.all().sort((B, H) => B.value.zIndex - H.value.zIndex), M = [], T = [], k = A.length;
for (let B = R + 1; B < k; B++) {
const H = A[B];
M.push(H);
const z = { ...H, value: { ...H.value, zIndex: B - 1 } };
T.push(z), v.set(z.value.model, z);
}
const P = M.length;
for (let B = 0; B < P; B++) I.remove(M[B], l);
I.load(T);
}, y?.description ?? "Delete Drawing", !0);
const b = w.length;
for (let x = 0; x < b; x++) w[x].value.processZIndexCallback?.();
}, setContainerDeleteCallback(y) {
(i()?.value ?? o).processDeleteCallback = y;
}, isProtected: () => !h._initializing && !h.getProtection().isObjectsAllowed(), setContainerProtectionCallback(y) {
(i()?.value ?? o).processProtectionCallback = y;
}, setContainerShiftCallback(y) {
(i()?.value ?? o).processShiftCallback = y;
}, setContainerLayoutCallback(y) {
(i()?.value ?? o).processLayoutCallback = y;
}, initialAnchor: r, maxRangeCoords: this._entireCoords, json: e }, p = e.content.json, S = { type: u, transactions: this._transactions, beginPersistResource: m, fromResourceId: n, defaultLockAspectRatio: f, json: p };
let E = null;
if (u === "picture") E = new IS(S);
else if (u === "chart") E = new tw(S);
else if (u === "sp" || u === "cxnSp" || u === "grpSp") E = new nw(S);
else {
if (u !== "graphicFrame") throw new Error(((y) => `Unsupported float type: ${y}`)(u));
E = new rw(S);
}
return o.model = new Li({ ..._, content: E }), d = !1, s;
}
_fromJSON(e) {
this._initializing = !0, this._emitter.notify("onBeforeLoad", { params: e }), this._clearState();
const t = this._beginCommit({ description: "Load Sheet", viewAfter: { initial: !0, skipProtectionCheck: !0 } }), n = e || {}, r = this._strings, o = r.beginPersist(), s = this._resources.beginPersist(), i = this._styles.beginPersist();
try {
this._ownStrings && o.fromJSON(n.strings), this._ownResources && s.fromJSON(n.resources), this._ownStyles && i.fromJSON(n.styles), this._colHeaders.fromJSON({ headers: n.cols, defaultSize: n.defaultColSize }), this._rowHeaders.fromJSON({ headers: n.rows, defaultSize: n.defaultRowSize }), this.setView(new ll({ sheet: this, json: n.view })), this._rangeSelection.updateCoords(this._view.getRangeSelection()), n.tabColor && (this._tabColor = this._styles.parseColor(n.tabColor));
let l = this._getState();
const c = l.cellValuesGrid, h = l.contentfulSpatial, u = n.data, d = u?.length ?? 0, g = Bu, m = [];
if (d > 0) {
for (let L = 0; L < d; L++) {
let j = u[L];
typeof j == "string" && (j = JSON.parse(j));
const G = j[1], V = G.length;
let $;
for (let J = 0; J < V; J++) {
const K = G[J][1], he = K.length;
for (let le = 0; le < he; le++) {
let pe = K[le], ee = pe?.t;
if (ee !== void 0) pe = pe?.v;
else switch (typeof pe) {
case "number":
ee = q.Number;
break;
case "boolean":
ee = q.Boolean;
break;
case "string":
ee = q.String, pe = parseInt(pe);
}
K[le] = [pe, ee];
}
$ = g(null, r, K), G[J][1] = $;
}
m.push(j);
}
c.setValues(m);
const W = zu(m, this._isDataColumn);
h.load(W);
}
const f = this._entireCoords, _ = l.directStyleSpatial, p = l.continuousFillSpatial, S = this._options.styles;
if (e.directStyles) {
const W = [], L = [], j = e.directStyles, G = (V, $) => {
const J = i.getElementJSON($), K = new nt(S, D.sanitizeRange(V), J), he = { ...V, value: K };
W.push(he);
const le = K._p?.alignment?.horizontal;
!le || le !== X.HorizontalAlignment.CenterContinuous && le !== X.HorizontalAlignment.Fill || L.push(he);
};
if (Array.isArray(j)) {
const V = j.length;
for (let $ = 0; $ < V; $++) {
const J = j[$], K = J.r;
G(typeof K == "string" ? Pt(K, f) : K, J.v);
}
}
_.load(W), p.load(L);
}
l = this._updateState({ cellValuesGrid: c, contentfulSpatial: h, directStyleSpatial: _, continuousFillSpatial: p });
const E = n.merges;
if (E) {
const W = [], L = E.length;
for (let j = 0; j < L; j++) {
const G = Pt(E[j], f);
W.push(G);
}
this._indexMerges(W);
}
const y = l.hyperlinkSpatial, C = n.hyperlinks;
if (C) {
const W = C, L = [], j = W.length;
for (let G = 0; G < j; G++) {
const V = W[G];
let $ = V.r;
$ = typeof $ == "string" ? Pt($, f) : D.sanitizeRange($);
let J = V.v;
typeof J == "string" && (J = { address: J }), L.push({ ...$, value: J });
}
y.load(L);
}
const w = l.commentsSpatial, b = n.comments;
if (b) {
const W = b, L = [], j = W.length;
for (let G = 0; G < j; G++) {
const V = W[G];
let $ = V.ref;
$ = typeof $ == "string" ? Pt($, f) : D.sanitizeRange($);
const J = { ...V };
delete J.ref, L.push({ ...$, value: J });
}
w.load(L);
}
const x = l.movableMapModel, I = l.movableSpatial;
if (n.movables) {
const W = [], L = n.movables, j = L.length;
for (let G = 0; G < j; G++) {
const V = L[G];
try {
const $ = this._createMovableEntry(V, G, s.fromResourceId.bind(s));
x.set($.value.model, $), W.push($);
} catch ($) {
console.warn("Unable to load movable", G, V, $);
}
}
I.load(W);
}
const v = l.tableMapModel, R = l.tableMapName, A = l.tableSpatial, M = n.tables;
if (M) {
const W = [], L = M.length;
for (let j = 0; j < L; j++) {
const G = M[j], V = this._createTableEntry(G), $ = V.value.model;
v.set($, V), R.set(V.value.currentName, $), W.push(V);
}
A.load(W);
}
const T = l.conditionalSpatial, k = l.conditionalModels, P = n.conditionals;
if (P) {
const W = P.length;
for (let L = 0; L < W; L++) {
const j = P[L];
this._createConditionalEntries(j, T, k);
}
}
const B = l.calcGraph, H = B.fromJSON({ formulas: n.formulas, data: m, dynamic: n.dynamicArray, volatile: n.volatile });
l = this._updateState({ hyperlinkSpatial: y, commentsSpatial: w, movableSpatial: I, movableMapModel: x, tableSpatial: A, tableMapModel: v, tableMapName: R, conditionalSpatial: T, conditionalModels: k, calcGraph: B });
const z = this._getUsedCoords();
z && this._autoFit([z], { orientations: O.Orientations.Row, skipCustomSize: !0 }), t.commit(), H && this._realizeCalcedValues(H), n.protection && this._protection.fromJSON(n.protection), this._emitter.notify("onLoad");
} finally {
i.endPersist(), s.endPersist(), o.endPersist();
}
this._initializing = !1;
}
getName() {
return this._closed ? rt : this._options.container?.getName?.() ?? null;
}
setName(e) {
if (this._closed) throw new Error(xt);
const t = this._options.container?.setName;
if (!t) throw new Error("Unable to set name for sheet.");
return t(e), this;
}
getVisibility() {
return this._closed ? Re.Visibility.VeryHidden : this._options.container?.getVisibility?.() ?? Re.Visibility.Hidden;
}
setVisibility(e = !0) {
if (this._closed) throw new Error(xt);
const t = this._options.container?.setVisibility;
if (!t) throw new Error("Unable to set visibility for sheet.");
let n;
return n = e === !0 ? Re.Visibility.Visible : e === !1 ? Re.Visibility.Hidden : e, t(n), this;
}
async select(e) {
return await this._options.container?.requestSelect?.(e), this;
}
duplicate() {
return this._options.container?.duplicate?.();
}
setPosition(e) {
return this._options.container?.setPosition(e), this;
}
getNames() {
return this._names;
}
getCalculation() {
return this._calculation;
}
get [Symbol.toStringTag]() {
return "[Sheet]";
}
toString() {
return this.getName() || "(untitled sheet)";
}
get isISheet() {
return !0;
}
}
const Rd = { address: null, scope: null }, Cw = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0 }, zs = { includeHidden: !1 };
Object.freeze({ [Te.Content.Values]: Number.MAX_SAFE_INTEGER, [Te.Content.Formulas]: Number.MAX_SAFE_INTEGER }), Object.freeze({ [Te.Content.Values]: 1, [Te.Content.Formulas]: 1 });
const Ps = { ignoreDataChanges: !1 }, Gt = { colStart: -1, rowStart: -1, colEnd: -1, rowEnd: -1 }, Io = [{ colIndex: -1, rowIndex: -1 }, null, null, null, null], bw = [Te.Content.Values], cl = { skipCustomSize: !0, expandOnly: !0, minContent: !0 }, De = { rowStart: 0, colStart: 0, rowEnd: 0, colEnd: 0 }, hl = { showFormulaBar: !0, showTabs: !0, tabRatio: 600, showHorizontalScrollbar: !0, showVerticalScrollbar: !0, showStatusBar: !0, activeSheetId: null };
class Ad {
constructor(e) {
this._emitter = null, this._emitter = new mt(this), this._state = { ...hl }, e?.json && this._fromJSON(e?.json);
}
isShowFormulaBar() {
return this._state.showFormulaBar;
}
setShowFormulaBar(e) {
return this._state.showFormulaBar = e, this._emitter.notify("onViewChange"), this;
}
isShowTabs() {
return this._state.showTabs;
}
setShowTabs(e) {
return this._state.showTabs = e, this._emitter.notify("onViewChange"), this;
}
getTabRatio() {
return this._state.tabRatio;
}
setTabRatio(e) {
return this._state.tabRatio = e, this._emitter.notify("onViewChange"), this;
}
isShowHorizontalScrollbar() {
return this._state.showHorizontalScrollbar;
}
setShowHorizontalScrollbar(e) {
return this._state.showHorizontalScrollbar = e, this._emitter.notify("onViewChange"), this;
}
isShowVerticalScrollbar() {
return this._state.showVerticalScrollbar;
}
setShowVerticalScrollbar(e) {
return this._state.showVerticalScrollbar = e, this._emitter.notify("onViewChange"), this;
}
isShowStatusBar() {
return this._state.showStatusBar;
}
setShowStatusBar(e) {
return this._state.showStatusBar = e, this._emitter.notify("onViewChange"), this;
}
getActiveSheetId() {
return this._state.activeSheetId;
}
setActiveSheetId(e) {
return this._state.activeSheetId = e, this._emitter.notify("onViewChange"), this;
}
addListeners(e, t) {
return this._emitter.addListeners(e, t);
}
toJSON() {
let e = {};
const t = Object.keys(this._state);
for (let n = 0; n < t.length; n++) {
const r = this._state[t[n]];
r != null && r !== hl[t[n]] && (e[t[n]] = r);
}
return Object.keys(e).length === 0 && (e = null), e;
}
_fromJSON(e, t = !0) {
let n = e || {};
this.update(n, t);
}
update(e, t = !0) {
this._state = { ...hl, ...this._state, ...e }, t && this._emitter.notify("onViewChange");
}
}
class vw {
constructor(e) {
this._emitter = null, this._closed = !1, this._options = { ...e };
const t = this;
this._transactions = this._options.transactions ?? new Xt({ transient: !0 }), this._transactionsRemoveListener = this._transactions.addStateListener(this, { onAfterStateChange(n, r, o) {
t._emitter.notify("onCollectionChange");
} }), this._emitter = new mt(this, this._transactions), this._initState(e?.initial);
}
add(e, t, n) {
const r = this;
t && t.addListeners({ onDelete: (c) => {
r._updateState((h) => {
if (!h.modules[e]) return;
const u = h.modules[e];
if (u) {
const d = { ...h };
return r._options.onRemove?.(e, u), r._emitter.notify("onCollectionChange"), delete d.modules[e], d;
}
return h;
}, "Delete Module");
} }, { once: !0 });
const o = this._getState()?.modules, s = o?.[e], i = n?.replace ?? !1;
if (s && !i) throw new Error(`Already existing '${e}'`);
const l = { ...o };
t ? (l[e] = t, r._options.onAdd?.(e, t), this._updateState({ modules: l }, i ? "Save Scripts" : "Add Script")) : (delete l[e], r._options.onRemove?.(e, null), this._updateState({ modules: l }, "Remove Script")), r._emitter.notify("onCollectionChange");
}
getItems(e) {
const t = this._getState();
if (!t) return F.EmptyArray;
const n = t.modules, r = Object.keys(n), o = r.length;
if (o === 0) return F.EmptyArray;
const s = [], i = e?.name ? e.name.toUpperCase() : null;
for (let l = 0; l < o; l++) {
const c = r[l], h = n[c];
let u = !0;
i && i !== c.toUpperCase() && (u = !1), u && s.push(h);
}
return s ?? F.EmptyArray;
}
getByName(e) {
if (!e) return null;
const t = this._getState();
if (!t) return null;
const n = e.toUpperCase(), r = t.modules, o = Object.keys(r), s = o.length;
for (let i = 0; i < s; i++) {
const l = o[i];
if (n === l) return r[l];
}
return null;
}
getCount() {
const e = this._getState();
return e ? Object.keys(e.modules).length : 0;
}
beginCommit(e) {
return this._beginCommit(e);
}
_getState() {
if (this._closed) throw new Error(Ht);
return this._transactions.getState(this);
}
_beginCommit(e) {
return this._transactions.beginCommit(typeof e == "string" ? { description: e } : e);
}
_updateState(e, t = "Update", n) {
if (!e) return;
const r = this._beginCommit(t);
try {
r.updateState(this, e), r.commit(n);
} catch (o) {
throw r.rollback(), o;
}
}
_initState(e) {
let t = e ?? {};
this._updateState({ modules: t }, "Initialize", { forceAmend: !0 });
const n = this._options.onAdd;
if (n) {
const r = Object.keys(t), o = r.length;
for (let s = 0; s < o; s++) {
const i = r[s];
n(i, t[i]);
}
}
}
addListeners(e, t) {
return this._emitter.addListeners(e, t);
}
toJSON() {
const e = this._getState();
if (!e) return F.EmptyArray;
const t = e.modules, n = Object.keys(t), r = n.length, o = {};
for (let s = 0; s < r; s++) {
const i = n[s];
o[i] = t[i].toJSON();
}
return o;
}
isClosed() {
return this._closed;
}
close() {
this._closed || (this._emitter.notify("onClose"), this._closed = !0, this._transactionsRemoveListener?.());
}
get isFunctionCollection() {
return !0;
}
}
let ul;
const Hs = "SheetXL", xw = ul || (ul = F.deepFreeze({ ISheet: { Visibility: Re.Visibility }, ICell: { Content: Te.Content, CalcStatus: Te.CalcStatus }, IColor: { Named: N.Named, Scheme: N.Scheme, Type: N.Type, AdjustmentType: N.AdjustmentType }, Direction: He }), ul);
let Ws;
class Iw extends Di {
constructor(e, t, n, r = null, o = !1) {
super(e, t, n, r, o);
}
execute(...e) {
const t = e[0];
if (!t || !t.isIWorkbook) throw new Error(`Macro '${this.getName()}' must be called with a valid workbook as the only argument.`);
const n = this._ct;
try {
const r = [];
switch (n) {
case bn.Context.Workbook:
r.push(t);
break;
case bn.Context.Sheet:
r.push(t.getSelectedSheet());
break;
case bn.Context.Ranges:
r.push(t.getSelectedRanges());
break;
case bn.Context.Range:
r.push(t.getSelectedRange());
break;
default:
throw new Error(`Function '${this.getName()}' is not a valid macro function.`);
}
const o = async (i, l) => {
const c = await l;
if (c !== void 0) if (c !== null) {
if (Array.isArray(c)) {
if (gt(c[0]?.[0])) return void i.setValues(c, { skipBoundsCheck: !0 });
} else if (gt(c)) return void i.setValues([[c]]);
c.isICell ? i.updateCells(c) : c.isICellRange && await i.copyFrom(c);
} else i.clear();
};
let s;
return (async () => {
const i = (await this.getDescriptor()).getSummary() ?? `Macro '${this.getName()}'`;
return await t.doBatch(async () => {
try {
const l = t.getSelectedRange();
let c = this._cf();
c || (c = function(h) {
return new Proxy(h, { set: (u, d, g) => (console.log(`Adding property "${d}" with value:`, g), u[d] = g, !0), deleteProperty: (u, d) => (console.log(`Deleting property "${d}"`), delete u[d]) });
}({}));
try {
uc({ getPosition: () => l.getCell().getCoords() }), Ws = globalThis[Hs], globalThis[Hs] = xw, s = this._fn.call(c, ...r), Ws ? (globalThis[Hs] = Ws, Ws = void 0) : delete globalThis[Hs], Oi();
} catch (h) {
throw h;
} finally {
Oi();
}
await o(l, s);
} catch (l) {
throw l;
}
}, i), { params: r, results: s };
})();
} catch (r) {
throw r;
}
}
}
class Rw {
constructor(e) {
this._emitter = null;
const t = e.json;
if (this._json = t, !this._json) throw new Error("Module JSON is required.");
this._emitter = new mt(this), this._functions = new ym({ transactions: null, readonlyFunctions: e.readonlyFunctions });
}
getFunctions() {
return this._functions;
}
getSource() {
return this._json.source;
}
getLanguage() {
return this._json.language || "typescript";
}
getErrors() {
return null;
}
delete() {
this._emitter.notify("onDelete");
}
addListeners(e, t) {
return this._emitter.addListeners(e, t);
}
toJSON() {
return this._json;
}
}
const Aw = async (a, e) => {
let t = null;
try {
uc(null);
} catch (o) {
console.warn("Error setting global scope", o);
}
try {
t = await new Function("modulePath", "return import(modulePath)")(
/* @vite-ignore */
/* webpackIgnore: true */
`data:text/javascript,${encodeURIComponent(a.compiled)}`
);
} catch (o) {
throw new Error("Invalid Javascript module.", { cause: o });
} finally {
Oi();
}
if (!e) throw new Error(`No function available for '${a.name ?? a.commitId}'.`);
const n = e.name;
let r = t[n];
if (!r && e.behavior.default && (r = t.default), !r) throw new Error(`Found the descriptor for '${n}' but not the function. The descriptor manifest must be corrupt.`);
return r;
}, Md = async (a, e = !1) => {
const t = a?.functions, n = /* @__PURE__ */ new Map();
if (t) for (let r = 0; r < t.length; r++) {
const o = t[r], s = o[0], i = o[1];
let l, c = e ? () => {
} : await Aw(a, s);
l = s.context && s.context !== bn.Context.Calculation ? new Iw(s, c, () => null, i) : new Di(s, c, () => null, i), n.set(s.name.toUpperCase(), l);
}
return new Rw({ json: a, readonlyFunctions: n });
};
class Mw {
constructor(e) {
this._options = e, this._initState();
}
_initState() {
}
getModules() {
return this._modules;
}
async createModule(e) {
const t = await import("@sheetxl/scripting"), n = await t.ScriptingUtils.compileTypescript(e);
return n ? await Md(n, e?.declarationsOnly ?? !1) : null;
}
addModule(e, t, n) {
this._modules.add(e, t, n);
}
executeMacro(e, t) {
const n = this._modules.getItems({ name: t }), r = n.length;
for (let o = 0; o < r; o++) {
const s = n[o].getFunctions().getByName(e);
if (s) return s.execute(this._options.workbook);
}
throw new Error(`No macro ${e} found.`);
}
searchFunction(e) {
const t = e?.name, n = e?.moduleName, r = e?.type, o = this._modules;
if (!o) return F.EmptyArray;
const s = o.getCount();
if (s === 0) return F.EmptyArray;
if (n) {
const l = this._modules.getItems({ name: n });
return l.length === 0 ? F.EmptyArray() : l[0].getFunctions().getItems({ name: t, type: r });
}
const i = this._modules.getItems();
for (let l = 0; l < s; l++) {
const c = i[l].getFunctions().getItems({ name: t, type: r });
if (c.length > 0) return c;
}
return F.EmptyArray;
}
async start() {
if (this._modules) return Promise.resolve();
const e = this._options?.workbook, t = this._options?.json;
let n = {};
if (t) {
const i = Object.keys(t);
for (let l = 0; l < i.length; l++) {
const c = i[l], h = t[c], u = await Md(h);
n[c] = u;
}
}
const r = new vw({ transactions: this._options?.transactions, initial: n, onRemove: this._options?.onRemove, onAdd: this._options?.onAdd });
this._modules = r;
const o = r.getItems();
if (o.length === 0) return Promise.resolve(F.EmptyArray);
const s = o.length;
for (let i = 0; i < s; i++) {
const l = o[i];
try {
const c = l.getFunctions().getItems({ type: "autoRun" }), h = c.length;
for (let u = 0; u < h; u++)
await c[u].execute(e);
} catch (c) {
console.error("Error executing autoRun script:", c);
}
}
}
toJSON() {
const e = this._modules;
if (!e) throw new Error("Scripts is initializing.");
return e.toJSON();
}
}
const Tw = Object.freeze({ lockStructure: !1, lockWindows: !1, lockRevision: !1, workbookPassword: null, revisionsPassword: null });
class Td extends Im {
isWindowsAllowed() {
return this._isPropertyAllowed("windows");
}
isRevisionAllowed() {
return this._isPropertyAllowed("revision");
}
isStructureAllowed() {
return this._isPropertyAllowed("structure");
}
_fromJSON(e) {
this._properties = e;
}
_toJSON(e) {
let t = this._properties;
if (t) {
e = { ...e, ...t };
const n = Object.keys(t), r = n.length;
for (let o = 0; o < r; o++) {
const s = n[o], i = t[s];
i != null && i !== Tw[s] && (e[s] = i);
}
}
return super._toJSON(e);
}
}
const dl = (a) => `Invalid SheetKey: ${a}`, gl = "A workbook must contain at least one visible worksheet.", Nd = "Internal error no visible sheetRefs", pt = "Workbook has been closed. No further operations are allowed.", er = "This workbook structure is protected. To make a change, unprotect the workbook. You might be requested to enter a password.", Yi = "A sheet name", Gl = `${Yi} can not be blank.`, Nw = `${Yi} can not be longer than 31 characters.`, Fw = `${Yi} can not begin or end with a "'" (single quote).`;
class kw {
constructor(e, t) {
this._add = e, this._get = t;
}
add(e) {
return this._add(e);
}
getItems(e) {
return this._get(e?.name, e?.visibility);
}
getByName(e) {
return this._get(e)?.[0] ?? null;
}
getCount() {
return this._get().length;
}
}
const Ul = new RegExp(/[\\/\\*?:[\]]+/), Ow = new RegExp(/\(((\d+)(?!.*\d))\)$/, "g"), Dw = (a) => `Sheet${a + 1}`, Rm = (a, e) => ({ ...Un, getSheet: () => null, toString: () => Ji(a, e) }), Fd = (a, e = !1) => {
if (!a) throw new Error(Gl);
if (Ul.test(a)) {
if (!e) throw new Error(((n) => `${n ? `'${n}'` : Yi} can not contain any of the following characters '\\ , / , * , ? , : , [ , ]'.`)(a));
a = a.replace(Ul, "");
}
if (a.length === 0) throw new Error(Gl);
const t = a.length;
if (t > 31) {
if (!e) throw new Error(Nw);
a = a.substring(0, 31);
}
if (a.charAt(0) === "'" || a.charAt(t - 1) === "'") {
if (!e) throw new Error(Fw);
a = a.replace(/^'|'$/g, "");
}
return a;
};
class Qi extends as {
constructor(e, t, n, r) {
super(e, t, r), this._workbook = n;
}
getSource() {
return this._workbook;
}
_createRanges(e, t) {
let n = this._options;
return t && (n = { ...this._options, getOptions: In(this._options?.getOptions, t) }), new Qi(e, this._sheet, this._workbook, n);
}
_createRange(e, t) {
const n = e ? { ...e } : null;
if (!(n && this._workbook._getSheetRef(n.sheetName, Re.Visibility.VeryHidden))) {
const o = this._workbook.getSelectedSheet();
return delete n?.sheetName, Rm(n, n ? { sheetName: rt, ...o.getEntireRange().getCoords() } : null);
}
let r = this._options;
return t && (r = { ...this._options, getOptions: In(this._options.getOptions, t) }), new Zi(e, this._sheet, this._workbook, r);
}
async select(e) {
const t = [];
let n = null;
const r = this.getCoords();
for (let l = 0; l < r.length; l++) {
const c = r[l];
c && (n || (n = c.sheetName), c && c.sheetName === n && t.push(c));
}
n || (n = this._workbook.getSelectedSheet().getName());
const o = this._workbook.getSheets().getByName(n);
if (!o) return;
const s = await o.getRanges(t).select(e), i = this._workbook._rangesAddressToCoords(s.getCoords());
return this._createRanges(i, e);
}
addListener(e, t) {
if (!this.getCoords()) return () => {
};
const n = this._workbook._sheetToWBEvent(e);
return super.addListener(n, t);
}
get [Symbol.toStringTag]() {
return "[WorkbookRanges]";
}
toString() {
const e = this.getCoords(), t = this._sheet, n = t.getEntireRange().getCoords(), r = { sheetName: t.getName(), ...n };
return Jg(e, r, Ji, Xn);
}
}
class Zi extends ls {
constructor(e, t, n, r) {
super(e, t, r), this._workbook = n;
}
_createRanges(e, t) {
let n = this._options;
return t && (n = { ...this._options, getOptions: In(this._options?.getOptions, t) }), new Qi(e, this._sheet, this._workbook, n);
}
_createRange(e, t) {
const n = this._sheet;
if (!e) return Cn(n, n._entireCoords);
if (n._validateCoords(e), n._closed) return Cn(null, n._entireCoords, e);
let r = this._options;
return t && (r = { ...this._options, getOptions: In(this._options?.getOptions, t) }), new Zi(e, this._sheet, this._workbook, r);
}
getSource() {
return this._workbook;
}
get [Symbol.toStringTag]() {
return "[WorkbookRange]";
}
toString() {
const e = this._sheet, t = e?.getEntireRange().getCoords() ?? null;
return Ji(this.getCoords(), { ...t, sheetName: e.getName() });
}
addListener(e, t) {
if (!this.getCoords()) return () => {
};
const n = this._workbook._sheetToWBEvent(e);
return super.addListener(n, t);
}
}
class iy {
constructor(e) {
this._lastTransactionUUID = null, this._closed = !1, this._initializing = !0, this._emitter = null, this._names = null, this._calculation = null, this._isDate1904 = !1;
const t = this, n = { ...e }, r = n.json;
delete n.json, this._transactions = n.transactions ?? new Xt(), this._ownTransactions = !n.transactions, this._emitter = new mt(this, this._transactions);
const o = this._beginCommit({ description: (r ? "Open" : "New") + " Workbook" });
try {
this._strings = n.strings ?? new lc(), this._ownStrings = !n.strings, this._resources = n.resources ?? new _m(), this._ownResources = !n.resources, this._createSheetName = n.createSheetNameCallback ?? Dw;
let s = n.createSheetCallback;
s || (s = (l) => new Zo(l)), this._sheetOnNameChange = /* @__PURE__ */ new Map(), this._sheetOnVisibilityChange = /* @__PURE__ */ new Map(), this._sheetOnIndexChange = /* @__PURE__ */ new Map(), this._createSheet = (l, c, h, u, d) => {
let g = null;
const m = { date1904: t.isDate1904(), readonly: t._options.readonly ?? !1, transactions: t._transactions, styles: t._styles, strings: t._strings, resources: t._resources, names: t._names, calculation: t._calculation, resolveRange: (f) => t._options.resolveRange?.(f) ?? t.getRange(f), container: { beforeFromJSON: (f) => {
g = f, t._addSheetRef({ name: c, id: l, visibility: h ?? Re.Visibility.Visible, sheet: f }, u);
}, getName: () => {
const f = t._getSheetRef(g);
return f ? f.name : t._createSheetName(1);
}, setName: (f) => {
t._getSheetRef(g) && t._setSheetName(g, f);
}, getIndex: () => {
const f = t._getSheetRef(g);
return f ? t._findOffsetForId(f.id, t._getSheetRefs(Re.Visibility.VeryHidden)) : -1;
}, setIndexCallback: (f) => {
t._sheetOnIndexChange.set(l, f);
}, setNameChangeCallback: (f) => {
t._sheetOnNameChange.set(l, f);
}, getVisibility: () => {
const f = t._getSheetRef(g);
return f ? f.visibility : Re.Visibility.Visible;
}, setVisibility: (f) => {
t._setSheetVisibility(g, f);
}, setVisibilityCallback: (f) => {
t._sheetOnVisibilityChange.set(l, f);
}, duplicate: () => t._duplicateSheet(g), setPosition: (f) => {
const _ = t._getSheetRef(g, Re.Visibility.VeryHidden);
return !!_ && (t._moveSheet(_, f), !0);
}, requestSelect: async () => (t._setSelectedSheet(g), await this._emitter.notify("onRequestSelect", { source: t, params: g, async: !0 }), t.getSelectedSheet() === g) } };
return d && (m.json = d), g = s(m, c, u, h), g;
}, this._names = n.names ?? new Cm({ addressToRanges: (l) => t.getRanges(l), getCurrentScope: () => t.getSelectedSheet().getName(), isReadOnly: () => t._options.readonly ?? !1, transactions: t._transactions }), this._ownNames = !n.names, this._calculation = n.calculation ?? new Em({ getNamed: (l, c) => {
try {
kr.address = l, kr.scope = c;
const h = this._names.getItems(kr);
return h && h.length !== 0 ? h[0].getRanges().getCoords() : null;
} catch {
return null;
}
}, getSheetIndex: (l) => {
if (l === void 0) return t.getSelectedSheetIndex();
const c = this._getSheetRefs(Re.Visibility.Hidden);
l = l.toLowerCase();
for (let h = 0; h < c.length; h++) if (c[h].name.toLowerCase() === l) return h;
try {
kr.address = l, kr.scope = void 0;
const h = this._names.getItems(kr);
if (!h || h.length === 0) return -1;
let d = h[0].getRanges().getCoords()?.[0]?.sheetName;
if (!d) return -1;
const g = this._getSheetRefs(Re.Visibility.Hidden);
d = d.toLowerCase();
for (let m = 0; m < g.length; m++) if (g[m].name.toLowerCase() === d) return m;
} catch {
return -1;
}
return -1;
}, getSheetCount: () => t.getSheets().getCount(), isDate1904: () => t.isDate1904(), strings: t._strings, transactions: t._transactions }), this._ownsCalculation = !n.calculation, this._scripts = this._createScripts(), this._ownNames = !n.names, this._options = { ...n };
const i = async () => {
this._ownsCalculation && await this._calculation.start(), await this._scripts.start(), this._starting = null;
};
this._starting = i(), r ? this._fromJSON(r) : (this._initState(), this._addSheet(!1)), this._emitter.notify("onLoad"), o.commit({ forceAmend: this._ownTransactions });
} catch (s) {
throw o.rollback(), s;
}
this._sheets = new kw((s) => t._addSheetOptions(s), (s, i) => s ? [this.getSheet(s, i)] : this._getSheets(i)), this._initializing = !1;
}
_initState() {
let e = this._getSheetRefs();
for (let r = e && e.length - 1; r >= 0; r--) ;
this._isDate1904 = this._options.date1904 ?? !1, this._theme = this._options.theme ?? new Ng().getDefaultTheme(), this._styles = this._options?.styles ?? new is(this._theme), this._ownStyles = !this._options.styles, this._styles.getTheme() || this._styles.setTheme(this.getTheme()), this._activeSheetOffset = 0, this.setView(new Ad()), this._listenerProtection?.(), this._protection = new Td(void 0, this._options.readonly ?? !1), this._listenerProtection = this._protection.addListeners({ onChange: (r) => {
t._emitter.notify("onProtectionChange");
} });
const t = this;
this._transactionsRemoveListener = this._transactions.addStateListener(this, { onAfterStateChange(r, o, s) {
if (o && o.activeSheetId !== void 0 && o.view === t.getView() && s.getId() === t._lastTransactionUUID && t._getSheetRef(o.activeSheetId)?.sheet.select(), o && s.getId() !== t._lastTransactionUUID) {
let i = t.getView().getActiveSheetId();
o.view === t.getView() && (i = o.activeSheetId);
let l = 0;
try {
l = t._findOffsetForId(i, r.sheetRefsVisible);
} catch {
}
t._activeSheetOffset = l;
}
t._lastTransactionUUID = s.getId(), t._notifyAllChange();
}, onRestoreOrRevert() {
t._emitter.notify("onInvalidated");
} });
const n = this._getState();
n?.listenersSheets && (n?.listenersSheets.forEach((r) => {
r();
}), n?.listenersSheets.clear()), this._updateState({ sheetRefsAll: [], sheetRefsVisibleAndHidden: [], sheetRefsVisible: [], refsById: /* @__PURE__ */ new Map(), sheetsById: /* @__PURE__ */ new Map(), refsByLowerCaseName: /* @__PURE__ */ new Map(), sheetsByLowerCaseName: /* @__PURE__ */ new Map(), refsByInstance: /* @__PURE__ */ new Map(), lastId: -1, sheetsCreated: /* @__PURE__ */ new Set(), listenersSheets: /* @__PURE__ */ new Map() });
}
getView() {
return this._view;
}
setView(e) {
if (this._closed) throw new Error(pt);
if (!e) throw new Error("View can not be empty.");
this._listenerWorkbookView?.();
const t = this;
return this._listenerWorkbookView = e.addListeners({ onViewChange: (n) => {
const r = t._getState();
this._activeSheetOffset = this._findOffsetForId(this._view.getActiveSheetId(), r.sheetRefsVisible), t._emitter.notify("onViewChange");
} }), this._view = e, t._emitter.notify("onViewChange"), this;
}
isDate1904() {
return this._isDate1904;
}
setDate1904(e) {
if (this._closed) throw new Error(pt);
return this._isDate1904 = e, this._notifyAllChange(), this;
}
getStyles() {
return this._styles;
}
getResources() {
return this._resources;
}
getTransactions() {
return this._transactions;
}
getStrings() {
return this._strings;
}
getTheme() {
return this._theme;
}
setTheme(e) {
if (this._closed) throw new Error(pt);
if (!e) throw new Error("A value must be provided.");
const t = this._theme;
return this._theme = e, this.getStyles().setTheme(e), this._emitter.notify("onThemeChange"), t;
}
getSelectedSheetIndex() {
return this._activeSheetOffset;
}
getSelectedSheet() {
const e = this._getSheetRef(this.getSelectedSheetIndex());
return e ? e?.sheet : null;
}
getSheet(e, t = Re.Visibility.Visible) {
const n = this._getSheetRef(e, t);
if (!n) throw new ze(`Sheet '${e}' not found.`);
return n.sheet;
}
getSheetAt(e, t = Re.Visibility.Visible) {
const n = this._getSheetRef(e, t);
if (!n) throw new ze(((r) => `No sheet found at ${r}.`)(e));
return n.sheet;
}
getSheets() {
return this._sheets;
}
addSheet(e) {
return this.getSheets().add(e);
}
_getSheets(e = Re.Visibility.Visible) {
const t = this._getSheetRefs(e), n = [];
for (let r = 0; r < t.length; r++) n.push(t[r].sheet);
return n;
}
_getSheetRefs(e = Re.Visibility.Visible) {
if (this._closed) return F.EmptyArray;
const t = this._getState();
return t ? e === Re.Visibility.Visible ? t.sheetRefsVisible : e === Re.Visibility.Hidden ? t.sheetRefsVisibleAndHidden : e === Re.Visibility.VeryHidden ? t.sheetRefsAll : F.EmptyArray : [];
}
_getSheetRef(e, t = Re.Visibility.Visible) {
if (this._closed) return null;
let n = null;
return typeof e == "number" ? this._getSheetRefs(t)[e] : (typeof e == "string" ? n = this._getState().refsByLowerCaseName.get(e.toLowerCase()) : e instanceof Zo ? n = this._getState().refsByInstance.get(e) : e?.id && e.sheet && (n = this._getState().refsById.get(e.id)), n);
}
_validateNewSheetName(e, t = !0) {
if (e == null) return e;
if (Fd(e), t && this._getState().sheetsByLowerCaseName.has(e.toLowerCase())) throw new Error("That name is already taken. Try a different one.");
return e.substring(0, 31);
}
findValidSheetName(e) {
e && (e = Fd(e, !0));
try {
return ((t, n) => {
try {
if (n(t)) return t;
} catch {
}
let r, o, s = Ow.exec(t);
for (s !== null ? (r = t.substring(0, s.index), o = parseFloat(s[1])) : (r = t + " ", o = 1); o < 256; ) {
o++;
const i = "(" + o + ")", l = r.substring(0, 31 - i.length) + i;
try {
if (n(l)) return l;
} catch {
}
}
throw new Error(t + " is not a valid sheet name");
})(e, (t) => this._validateNewSheetName(t));
} catch {
return this._nextSheetName();
}
}
isValidSheetNameCharacter(e) {
return !Ul.test(e);
}
_addSheetOptions(e) {
if (this._closed) throw new Error(pt);
if (!this.getProtection().isStructureAllowed()) throw new Error(er);
let t, n = null;
t = typeof e == "string" ? { name: e } : typeof e == "number" ? { index: e } : e, t = { ...t, description: t?.description ?? "Add Sheet" };
const r = this.beginCommit(t);
try {
const o = t?.autoSelect;
n = this._addSheet(!0, t.name, t.index ?? null);
const s = this.getView().getActiveSheetId();
let i, l;
if (o !== !1) {
let c = this.getView().getActiveSheetId();
c = this._getSheetRef(n).id, o && (i = { view: this.getView(), activeSheetId: s }, l = { view: this.getView(), activeSheetId: c });
}
if (r.commit({ description: `Add Sheet '${n.getName()}'`, viewBefore: i, viewAfter: l }), o !== !1) {
const c = typeof o == "boolean" ? void 0 : o;
n.select(c);
}
} catch (o) {
throw r.rollback(), o;
}
return n;
}
_nextSheetName(e = null) {
let t = e ? e.toLowerCase() : null;
const n = this._getState(), r = n.sheetsByLowerCaseName;
if (e && r.has(t)) throw new Error(((s) => `The sheet name '${s}' already exist in workbook.`)(e));
t = (e = this._validateNewSheetName(e)) ? e.toLowerCase() : null;
let o = n.lastId + 1;
for (; !e; ) {
const s = this._createSheetName(o), i = s.toLowerCase();
r.has(i) ? o++ : e = s;
}
return this._updateState({ lastId: o }), e;
}
_addSheet(e, t = null, n = null) {
t = this._nextSheetName(t);
const r = this._getState(), o = this._createSheet(r.lastId, t, Re.Visibility.Visible, n, null);
if (!o) throw new Error(Gl);
return e && this._emitter.notify("onSheetsChange"), o;
}
_updateSheetRefStates(e) {
if (this._closed) throw new Error(pt);
if (!this._initializing && !this.getProtection().isStructureAllowed()) throw new Error(er);
const t = e, n = [], r = [];
for (let o = 0; o < t.length; o++) t[o].visibility === Re.Visibility.Visible ? (n.push(t[o]), r.push(t[o])) : t[o].visibility === Re.Visibility.Hidden && r.push(t[o]);
this._updateState({ sheetRefsAll: t, sheetRefsVisible: n, sheetRefsVisibleAndHidden: r });
}
_addSheetRef(e, t = null) {
const n = this._getState(), r = n.sheetRefsAll, o = Math.max(0, Math.min(r.length, t ?? r.length));
let s = [...r.slice(0, o), e, ...r.slice(o)];
this._updateSheetRefStates(s);
const i = e.sheet, l = e.name.toLowerCase(), c = new Map(n.refsById);
c.set(e.id, e);
const h = new Map(n.refsByLowerCaseName);
h.set(l, e);
const u = new Map(n.refsByInstance);
u.set(i, e);
const d = new Map(n.sheetsById);
d.set(e.id, i);
const g = new Map(n.sheetsByLowerCaseName);
g.set(l, i);
const m = this;
let f = n.listenersSheets;
if (i !== void 0) {
const S = i.addListeners({ onBeforeDelete: (E) => {
m._validateDeleteSheet(E);
}, onDelete(E) {
let y = m._getSheetRef(E, Re.Visibility.VeryHidden);
if (!y) return;
const C = m._beginCommit({ description: `Remove Sheet ${y.name}` });
try {
const w = m._getState(), b = w.sheetRefsAll, x = m._findOffsetForId(y.id, b);
let I = [...b];
I.splice(x, 1), m._updateSheetRefStates(I);
const v = new Map(w.refsById);
v.delete(y.id);
const R = new Map(w.sheetsById);
R.delete(y.id);
const A = y.name.toLowerCase(), M = new Map(w.refsByLowerCaseName);
M.delete(A);
const T = new Map(w.sheetsByLowerCaseName);
T.delete(A);
const k = new Map(w.refsByInstance);
k.delete(E), w.listenersSheets.get(y.id)();
const P = new Map(w.listenersSheets);
P.delete(y.id), m._adjustRemoveSelectionIfRequired(x, y.id), m._adjustSheetNamesIfRequired(), m._emitter.notify("onSheetsChange");
const B = new Set(w.sheetsCreated);
B.has(i) && B.delete(i), m._updateState({ refsById: v, sheetsById: R, refsByLowerCaseName: M, sheetsByLowerCaseName: T, refsByInstance: k, sheetsCreated: B, listenersSheets: P }), C.commit();
} catch (w) {
throw C.rollback(), w;
}
} });
f = new Map(n.listenersSheets), f.set(e.id, S);
}
let _ = n.lastId;
_ !== -1 && (_ = Math.max(_, e.id)), this._updateState({ lastId: _ }), this._updateState({ refsById: c, refsByLowerCaseName: h, refsByInstance: u, sheetsById: d, sheetsByLowerCaseName: g, listenersSheets: f }), this._adjustSheetNamesIfRequired();
const p = new Set(this._getState().sheetsCreated);
return p.add(e.sheet), this._updateState({ sheetsCreated: p }), e;
}
_adjustRemoveSelectionIfRequired(e, t) {
if (this._view.getActiveSheetId() === t) {
let n;
const r = this._getState().sheetRefsVisible;
n = e < r.length ? r[e].id : r[e - 1].id, this._view.setActiveSheetId(n);
}
}
_adjustSheetNamesIfRequired() {
const e = this._getState(), t = e.lastId;
if (t === -1) return;
let n = this._view.getActiveSheetId();
n == null && (this._view.setActiveSheetId(t), n = t), e.refsById.get(n).visibility === Re.Visibility.Visible && (this._activeSheetOffset = this._findOffsetForId(n, e.sheetRefsVisible));
}
_validateDeleteSheet(e) {
if (this._closed) throw new Error(pt);
if (!this.getProtection().isStructureAllowed()) throw new Error(er);
let t = this._getSheetRef(e);
if (!t) throw new Error(((r) => `Invalid reference for delete: ${r}`)(e));
const n = this._getState().sheetRefsVisible;
if (n.length === 1 && n[0].id === t.id) throw new Error(gl);
}
_findOffsetForId(e, t) {
for (let n = 0; n < t.length; n++) if (t[n].id === e) return n;
throw new Error(Nd);
}
find(e, t) {
if (this._closed) throw new Error(pt);
const n = this._getSheets();
if (n.length === 1) return n[0].find(e, t);
const r = !t?.reverse;
let o = t?.disableWrap ?? !1;
const s = this.getSelectedSheetIndex();
let i = s, l = n[i], c = !1;
t = { ...t, disableWrap: !0 };
let h, u = l.find(e, t), d = u.next(), g = !1;
if (t?.from) {
const _ = this._rangesAddressToCoords(t?.from);
h = { colIndex: _[0].colStart, rowIndex: _[0].rowStart };
} else h = { colIndex: 0, rowIndex: 0 };
const m = D.createCellComparator(t?.orientation, t?.reverse);
delete (t = { ...t }).from;
const f = () => {
if (!g && d.done && (c && i === s ? g = !0 : r ? (i++, i > n.length - 1 && (i = 0, c = !0)) : (i--, i < 0 && (i = n.length - 1, c = !0)), o && c && (g = !0), !g)) return l = n[i], u = l.find(e, t), d = u.next(), d;
if (!g && c && i === s && (d.done || !d.done && m(d.value.getCoords(), h) >= 0) && (g = !0), g) return ke;
const _ = d;
return d = u.next(), _;
};
return { next: () => {
let _ = f();
for (; !g && _.done; ) _ = f();
return _;
} };
}
replace(e, t, n) {
let r = 0, o = null;
const s = typeof t == "function", i = n?.maxCount ?? Number.MAX_SAFE_INTEGER;
let l = n.maxCount ? "" : "All";
const c = typeof t == "string" ? ` with '${hg(t)}'` : "";
let h = n?.description ?? "Replace";
const u = this._transactions.beginCommit({ description: h });
try {
let d = null, g = null, m = e.next();
for (; !m.done && r < i; ) {
const f = m.value, _ = f.getSheet();
_ !== d && (d = _, g !== null && g.apply(), g = d.getEntireRange().startIncrementalUpdates({ orientation: n?.orientation, allowUnorderedWrites: !0 }));
const p = s ? t(f) : t;
p !== void 0 && p !== f && (g.push(f, p), r++, o = f), m = e.next();
}
g?.apply(), r === 1 && i === 1 && o && (l = o.getA1()), u.commit({ description: n?.description ?? `Replace ${l}${c}` });
} catch (d) {
throw u.rollback(), d;
}
return { count: r, last: o };
}
_nextSheetIndex(e, t = this._getSheetRefs()) {
return t.length === 1 ? 0 : (e === void 0 && (e = this.getSelectedSheetIndex()), (e = Math.max(0, Math.min(e, t.length - 1))) >= t.length - 1 ? 0 : e + 1);
}
_prevSheetIndex(e, t = this._getSheetRefs()) {
return t.length === 1 ? 0 : (e === void 0 && (e = this.getSelectedSheetIndex()), (e = Math.max(0, Math.min(e, t.length - 1))) <= 0 ? t.length - 1 : e - 1);
}
getNextSheet(e) {
if (this._closed) throw new Error(pt);
const t = this._getSheetRefs();
return t[this._nextSheetIndex(e, t)]?.sheet ?? null;
}
getPreviousSheet(e) {
if (this._closed) throw new Error(pt);
const t = this._getSheetRefs();
return t[this._prevSheetIndex(e, t)]?.sheet ?? null;
}
async _duplicateSheet(e) {
if (this._closed) throw new Error(pt);
if (!this.getProtection().isStructureAllowed()) throw new Error(er);
const t = this._getSheetRefs(), n = this.getSelectedSheetIndex();
let r = null;
if (e) {
if (r = this._getSheetRef(e), !r) throw new Error(dl(r));
} else r = t[n];
if (!r) return null;
const o = r.sheet, s = this._strings.beginPersist(), i = this.getResources().beginPersist(), l = this.getStyles().beginPersist();
let c = null;
const h = this.beginCommit(`Duplicate '${o.getName()}'`);
try {
const u = this._getState().refsByInstance.get(o), d = await o.toJSON(), g = t.length + 1, m = this.findValidSheetName(u.name), f = this._createSheet(g, m, u.visibility, n, d);
this._emitter.notify("onSheetsChange"), c = f, h.commit();
} catch (u) {
throw h.rollback(), u;
} finally {
l.endPersist(), i.endPersist(), s.endPersist();
}
return c;
}
_createRange(e, t) {
const n = e ? { ...e } : null;
if (!(n && this._getSheetRef(n.sheetName, Re.Visibility.VeryHidden))) {
const s = this.getSelectedSheet();
return s ? (delete n?.sheetName, Rm(n, n ? { sheetName: rt, ...s.getEntireRange().getCoords() } : null)) : void console.warn(Nd);
}
const r = this.getSelectedSheet();
let o = null;
return t && (o = { getOptions: t }), new Zi(e, r, this, o);
}
_createRanges(e, t) {
const n = this.getSelectedSheet();
let r = null;
return t && (r = { getOptions: t }), new Qi(e, n, this, r);
}
getRange(e, t) {
try {
const n = this._rangesAddressToCoords(e);
if (n.length !== 1) throw new Error(Yg);
return this._createRange(n[0], t);
} catch (n) {
throw n instanceof ze ? new ze(n.message) : new Error(n.message ?? qo(e));
}
}
getRanges(e, t) {
const n = this._rangesAddressToCoords(e);
if (n.length === 0) throw new Error(qo(e));
return this._createRanges(n, t);
}
_activeRangeCoords() {
const e = this.getSelectedSheet(), t = Lr(e.getSelection().getCoords()), n = e.getName(), r = [];
for (let o = 0; o < t.length; o++) r.push({ sheetName: n, ...t[o] });
return r;
}
getSelectedRange(e) {
return this.getRange(this._activeRangeCoords()[0], e);
}
getSelectedRanges(e) {
return this.getRanges(this._activeRangeCoords(), e);
}
getSelectedCell() {
return this.getSelectedSheet().getSelectedCell();
}
_rangesAddressToCoords(e, t = !0, n = Re.Visibility.Hidden) {
if (!e) throw new Error(Ur);
const r = this.getSelectedSheet(), o = r?.getEntireRange().getCoords(), s = { ...o }, i = r?.getName();
if (i && (s.sheetName = i), typeof e == "string") {
const h = e.trim().toLowerCase();
if (h === "r" || h === "c") {
const u = this.getSelectedCell().getCoords(), d = {};
h === "r" ? d.rowStart = d.rowEnd = u.rowIndex : d.colStart = d.colEnd = u.colIndex, e = d;
}
}
const l = this, c = sc(e, s, ss, (h) => {
if (!t) return null;
if (typeof h == "string") {
const u = l.getNames().getByName(h);
if (u) return u.getRanges()?.getCoords();
}
throw new Error(`Invalid sheet reference '${h}'.`);
});
for (let h = 0; h < c.length; h++) this._validateCoords(c[h], n);
return c;
}
_validateCoords(e, t = Re.Visibility.Visible, n = Ai) {
if (e === null) return;
const r = this.getSheet(e.sheetName, t).getEntireRange().getCoords();
if (!D.isRangeWithinRange(e, r)) throw new ze(n);
if (e.rowEnd < e.rowStart || e.colEnd < e.colStart) throw new Error(Qg);
}
_updateSheetRef(e, t) {
const n = this._getState();
let r = [...n.sheetRefsAll];
r[this._findOffsetForId(e.id, n.sheetRefsAll)] = t, this._updateSheetRefStates(r);
const o = new Map(n.refsById);
o.set(e.id, t);
const s = e.name.toLowerCase(), i = t.name.toLowerCase(), l = new Map(n.refsByLowerCaseName);
l.delete(s), l.set(i, t);
const c = new Map(n.sheetsByLowerCaseName);
let h = c.get(s);
c.delete(s), c.set(i, h);
const u = new Map(n.refsByInstance);
return u.set(h, t), this._updateState({ refsById: o, refsByLowerCaseName: l, sheetsByLowerCaseName: c, refsByInstance: u }), t;
}
_setSheetName(e, t) {
if (this._closed) throw new Error(pt);
if (!this.getProtection().isStructureAllowed()) throw new Error(er);
const n = this._getSheetRef(e);
if (!n) throw new Error(dl(e));
if (t === n.name) return n.sheet;
t = this._validateNewSheetName(t);
const r = Object.freeze({ ...n, name: t });
let o = null;
const s = this.beginCommit("Rename Sheet");
try {
const i = this._updateSheetRef(n, r);
this._adjustSheetNamesIfRequired(), this._sheetOnNameChange.forEach((l, c) => {
n.id === c && l();
}), this._emitter.notify("onSheetsChange"), o = i.sheet, s.commit();
} catch (i) {
throw s.rollback(), i;
}
return o;
}
_setSheetVisibility(e, t = Re.Visibility.Visible) {
if (this._closed) throw new Error(pt);
if (!this.getProtection().isStructureAllowed()) throw new Error(er);
const n = this._getSheetRef(e);
if (!n) return null;
if (t === n.visibility) return;
let r = null, o = "";
t === Re.Visibility.Visible ? o = "Unhide Sheet" : t === Re.Visibility.Hidden ? o = "Hide Sheet" : t === Re.Visibility.VeryHidden && (o = "Very Hide Sheet");
const s = this.beginCommit(o);
try {
const i = this._getState().sheetRefsVisible;
if (t !== Re.Visibility.Visible && i.length === 1 && i[0].id === n.id) throw new Error(gl);
const l = { ...n, visibility: t };
let c = -1;
t !== Re.Visibility.Visible && (c = this._findOffsetForId(n.id, i));
const h = this._updateSheetRef(n, l);
t !== Re.Visibility.Visible && this._adjustRemoveSelectionIfRequired(c, n.id), r = h.sheet, this._adjustSheetNamesIfRequired(), s.commit();
} catch (i) {
throw s.rollback(), i;
}
return this._sheetOnVisibilityChange.forEach((i, l) => {
n.id === l && i();
}), this._emitter.notify("onSheetsChange"), r;
}
_moveSheet(e, t) {
if (this._closed) throw new Error(pt);
if (!this.getProtection().isStructureAllowed()) throw new Error(er);
let n = null;
const r = this.beginCommit(`Move Sheet '${e.name}'`);
try {
const o = this._getState(), s = o.sheetRefsVisible;
if (t < 0 || t > s.length - 1) throw new Error(`Invalid to index: ${t}`);
const i = { view: this.getView(), activeSheetId: this.getView().getActiveSheetId() }, l = o.sheetRefsAll, c = this._findOffsetForId(e.id, l), h = this._findOffsetForId(s[t].id, l);
if (c === h) return;
const u = l[c];
let d = [...l];
d.splice(c, 1), d.splice(h, 0, u), this._updateSheetRefStates(d), this._adjustSheetNamesIfRequired(), this._sheetOnIndexChange.forEach((g, m) => {
m >= c && m <= h && g();
}), this._emitter.notify("onSheetsChange"), n = u.sheet, r.commit({ viewBefore: i, viewAfter: { view: this.getView(), activeSheetId: this.getView().getActiveSheetId() } });
} catch (o) {
throw r.rollback(), o;
}
return n;
}
_setSelectedSheet(e) {
if (this._closed) throw new Error(pt);
const t = this._getSheetRef(e);
if (!t) throw new Error(dl(e));
let n = null;
return t.visibility !== Re.Visibility.Visible && this._setSheetVisibility(t, Re.Visibility.Visible), this._view.setActiveSheetId(t.id), n = t.sheet, n;
}
getProtection() {
return this._protection;
}
getNames() {
return this._names;
}
getCalculation() {
return this._calculation;
}
getScripts() {
return this._scripts ?? null;
}
_notifyAllChange() {
this._emitter.notify("onSheetsChange"), this._emitter.notify("onViewChange");
}
addListeners(e, t) {
return this._emitter.addListeners(e, t);
}
_sheetToWBEvent(e) {
const t = this;
return (n) => {
const r = () => {
const s = n.getSource();
if (s.isICellRanges) {
const i = [...s.getCoords()];
for (let l = 0; l < i.length; l++) {
const c = i[l];
!c.sheetName && s.getSheet().getName() && (i[l] = { ...c, sheetName: s.getSheet().getName() });
}
return t.getRanges(i);
}
if (s.isICellRange) {
const i = s.getCoords(), l = s.getSheet().getName();
return t.getRange({ ...i, sheetName: l });
}
}, o = { getSource: r, trigger: n.trigger, getFrom: () => t.getRanges(n.getFrom()), getTo: () => t.getRange(n.getTo()), isDataChange: n.isDataChange, isTransactional: n.isTransactional, isUndo: n.isUndo, toString: () => `WorkbookRangeEvent: ('${n.trigger}', ${r().toString()})`, timeStamp: Date.now() };
e(o);
};
}
_fromJSON(e) {
if (this._emitter.notify("onBeforeLoad", { params: e }), this._initState(), !e.sheets || e.sheets.length === 0) throw new Error(gl);
e.theme && (this._theme = new Al(e.theme), this._styles.setTheme(this._theme));
const t = this._strings.beginPersist(), n = this._resources.beginPersist(), r = this._styles.beginPersist();
try {
t.fromJSON(e.strings), n.fromJSON(e.resources), r.fromJSON(e.styles), e.date1904 && (this._isDate1904 = !0), e.view || (e.view = {});
const o = e.sheets, s = o.length;
let i = e.view.activeSheetId ?? null;
i !== null && (i = Math.min(Math.max(1, i), s));
let l = null;
for (let h = 0; h < s; h++) {
const u = o[h], d = u.visibility || Re.Visibility.Visible, g = h + 1;
d === Re.Visibility.Visible ? l = g : i !== null && i === g && (i = null), this._createSheet(g, u.name, d, void 0, u.sheet);
}
this._updateState({ lastId: l }), e.names && this._names.fromJSON(e.names), e.view.activeSheetId = i ?? l, this.setView(new Ad({ json: e.view })), this._adjustSheetNamesIfRequired(), this._listenerProtection?.();
const c = this;
this._protection = new Td(e?.protection, this._options?.readonly), this._listenerProtection = this._protection.addListeners({ onChange: (h) => {
c._emitter.notify("onProtectionChange", { source: h });
} }), e.scripts && (this._scripts = this._createScripts(e.scripts)), this._emitter.notify("onLoad");
} finally {
r.endPersist(), n.endPersist(), t.endPersist();
}
}
_createScripts(e) {
return new Mw({ transactions: this._transactions, json: e, workbook: this, onAdd: (t, n) => {
const r = this._calculation;
r.getStatus() !== Ye.Status.Off && r.start().then(() => {
const o = n.getFunctions().getItems({ type: "formula" });
for (let s = 0; s < o.length; s++) {
const i = o[s];
this._calculation.getFunctions().add(i);
}
});
}, onRemove: (t, n) => {
} });
}
async toJSON(e = !1) {
if (this._closed) throw new Error(pt);
await this._emitter.notify("onBeforeSave", { async: !0 });
const t = { sheets: [] };
await Promise.resolve(this._starting);
const n = this._theme.toJSON();
(n ? Object.keys(n).length : 0) > 0 && (t.theme = n);
const r = this._strings.beginPersist(), o = this._resources.beginPersist(), s = this._styles.beginPersist();
try {
const i = this._getSheetRef(this.getSelectedSheetIndex()).id;
let l = i, c = null;
const h = this._getState(), u = h.sheetRefsAll, d = h.sheetsById;
for (let E = 0; E < u.length; E++) {
const y = u[E], C = E + 1, w = await d.get(y.id).toJSON(e), b = { name: y.name, sheet: w };
y.visibility === Re.Visibility.Visible ? c = C : b.visibility = y.visibility, y.id === i && (l = C), t.sheets.push(b);
}
const g = s.toJSON();
g && Object.keys(g).length > 0 && (t.styles = g);
const m = this.getProtection().toJSON();
m && (t.protection = m);
const f = await r.toJSONAsync();
f && f.length > 0 && (t.strings = f);
const _ = await o.toJSONAsync();
_ && _.length > 0 && (t.resources = _);
const p = this._names.toJSON();
p && p.length > 0 && (t.names = p);
const S = this._view.toJSON();
S && (l !== c ? S.activeSheetId = l : delete S.activeSheetId, Object.keys(S).length > 0 && (t.view = S));
} finally {
s.endPersist(), o.endPersist(), r.endPersist();
}
if (this._scripts) {
const i = this._scripts.toJSON();
i && Object.keys(i).length > 0 && (t.scripts = i);
}
return this._isDate1904 && (t.date1904 = !0), this._emitter.notify("onSave", { params: t }), t;
}
isClosed() {
return this._closed;
}
close() {
if (this._closed) return;
this._emitter.notify("onClose");
const e = this._getState();
e.listenersSheets.forEach((n) => {
n();
}), e.listenersSheets.clear();
const t = e.sheetRefsAll;
for (let n = t.length - 1; n >= 0; n--) try {
t[n].sheet.close();
} catch (r) {
console.warn("error on close", r);
}
this._ownResources, this._ownNames && this._names.close(), this._ownsCalculation && this._calculation.close(), this._ownStyles, this._transactionsRemoveListener?.(), this._closed = !0;
}
beginCommit(e) {
if (this._closed) throw new Error(pt);
return this._beginCommit(typeof e == "string" ? { description: e } : e);
}
doBatch(e, t) {
const n = this;
return t = typeof t == "string" ? { description: t } : { description: "Update Workbook", ...t }, this._transactions.doBatch(e, t, (r, o) => {
r.getDepth() === 0 && (n._lastTransactionUUID = r.getId());
});
}
_beginCommit(e) {
const t = this;
return this._transactions.beginCommit(typeof e == "string" ? { description: e } : e, (n) => {
n.getDepth() === 0 && (t._lastTransactionUUID = n.getId());
});
}
_getState() {
return this._transactions.getState(this);
}
_updateState(e, t = "Update Workbook") {
if (!e) return;
const n = this._beginCommit(t);
try {
n.updateState(this, e), n.commit();
} catch (r) {
throw n.rollback(), r;
}
}
get options() {
return this._options;
}
get [Symbol.toStringTag]() {
return "[Workbook]";
}
toString() {
return "";
}
get isIWorkbook() {
return !0;
}
}
const kr = { address: null, scope: null };
export {
ir as $,
vi as A,
bt as B,
Qe as C,
Uu as D,
Ye as E,
VS as F,
ey as G,
Em as H,
Sh as I,
Kr as J,
Te as K,
Bd as L,
td as M,
Nt as N,
nd as O,
IS as P,
rd as Q,
Xa as R,
fp as S,
Di as T,
kh as U,
Vr as V,
od as W,
Vl as X,
ar as Y,
yS as Z,
Th as _,
gw as a,
Al as a0,
Ng as a1,
nn as a2,
oy as a3,
sy as a4,
Re as a5,
Zo as a6,
Ad as a7,
iy as a8,
dw as b,
Jt as c,
ry as d,
Yt as e,
Fl as f,
b0 as g,
Cg as h,
Xt as i,
Zw as j,
Oe as k,
ny as l,
Ui as m,
te as n,
Y as o,
N as p,
U as q,
an as r,
ty as s,
gt as t,
bi as u,
X as v,
ce as w,
is as x,
_m as y,
lc as z
};