@sheetxl/sdk
Version:
SDK - A high-performance, embeddable spreadsheet engine.
23,843 lines • 1.1 MB
JavaScript
import { ScalarType as Y, IRange as F, FormulaError as pt, Observable as jm } from "@sheetxl/primitives";
import { CommonUtils as k, UndoManager as $m, ChainedError as Gm, TypesUtils as Pi, RangeOrientation as yt, CoordUtils as L, Direction as $t, OutOfBoundsError as Wt, NullNotAllowedError as Qe, RangeOrientations as zr, NotImplementedError as Pu, TypedObject as Yt, AnchorLocation as fn, JSONStableStringify as ea, BufferUtils as Fo, ImageUtils as js, MimeType as Wu, PartialError as Um, ExpectedError as ot, Notifier as Go, TypedError as pc, CommonMessages as qm } from "@sheetxl/utils";
/**
* @license @sheetxl/sdk - SDK - A high-performance, embeddable spreadsheet engine. - v0.7.27
*
* (C) 2025-present SheetXL Inc. & Michael T. Ford
* License: The license can be found at https://www.sheetxl.com/license.
*/
const _c = (a, t) => {
const e = /* @__PURE__ */ new Map();
return a.forEach((n, r) => {
t.get(r) !== n && e.set(r, n);
}), e;
};
let Sc = !1;
class wc {
constructor(t) {
this._record = t;
}
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 Ze {
constructor(t) {
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 = t?.sync ?? Sc, this._isTransient = t?.transient ?? !1, this._author = t?.author;
const e = { id: "0", description: "initial", meta: {}, author: this._author, timestamp: Date.now(), states: /* @__PURE__ */ new Map(), version: 0, previousId: null }, n = { record: e, commit: new wc(e) };
this._current = n, this._cacheModel = null, this._cacheState = null, this._states = e.states, this._transactionStack = [], this._transactionOpen = !1;
const r = /* @__PURE__ */ new Map();
r.set(e.id, n), this._commits = r;
}
static {
this.setDefaultSync = (t) => {
Sc = t;
};
}
getLog(t, e = 100) {
const n = [];
let r = t;
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 < e);
}
getCommitCount() {
return this._commits.size;
}
isOpenTransaction() {
return this._transactionStack.length > 0 || this._transactionOpen;
}
getPendingView() {
const t = this._transactionStack;
return t.length > 0 ? t[0].getView() : null;
}
getState(t) {
const e = this._transactionStack;
if (e.length === 0) {
if (this._cacheModel === t) return this._cacheState;
const n = this._states.get(t);
return this._cacheModel = t, this._cacheState = n, n;
}
return e[e.length - 1].getState(t);
}
getCurrentCommit() {
return this._pending?.commit ?? this._current.commit;
}
restore(t, e) {
const n = this._getCommitContainer(t, e);
if (this._current.commit.getId() === n.commit.getId()) return n.commit;
let r;
e?.viewId && e?.viewId !== "custom" || (r = n.record.viewAfter);
const o = _c(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(t, e) {
const n = this._getCommitContainer(t, e), r = this._commits.get(n.record.previousId);
if (!r) throw new Error(`Invalid commit id: '${n.record.previousId}'`);
let o;
e?.viewId && e?.viewId !== " custom" || (o = n.record.viewBefore ?? n.record.viewAfter);
const s = _c(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(t, e) {
const n = this._commits.get(t);
if (!n) throw new Error(`Invalid commit id: '${t}'`);
if (this._isTransient) throw new Error("Cannot revert transient store");
if (e?.force && this._transactionStack.length > 0 && this._transactionStack[0].rollback(), this._transactionStack.length !== 0) throw new Error("Open transactions.");
return n;
}
_pruneForwards(t) {
}
beginCommit(t, e) {
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 = t?.preventFurtherTransactions, s = this, i = (c, h, d) => {
const u = s._transactionStack;
r !== u.length - 1 && console.warn("Transaction stack out of sync", r, u.length, u), o && (this._locked = !1), u.pop(), e?.(c, h, d), u.length === 0 && (s._pending = null);
};
let l;
if (n.length === 0) {
const c = this._current.record, h = { states: /* @__PURE__ */ new Map(), id: k.uuidV4(), description: typeof t == "string" ? t : t?.description ?? null, meta: {}, timestamp: Date.now(), author: null, version: c.version + 1, previousId: c.id, viewBefore: null, viewAfter: {}, operation: t?.operation }, d = { record: h, commit: new wc(h) };
this._pending = d, this._notify("onCommitStart", d.commit), l = new Jm(this, d, c?.states, t, i);
} else
l = n[n.length - 1].beginTransaction(t, i);
return o && (this._locked = !0), this._transactionStack.push(l), l;
}
doBatch(t, e, n) {
let r;
const o = this.beginCommit(e, n), s = this.getCurrentCommit();
try {
r = t?.(s);
const i = () => {
o.commit(e);
};
if (r && typeof r.then == "function") return new Promise((l, c) => {
r.then((h) => {
try {
i(), l(h);
} catch (d) {
c(d);
}
}).catch((h) => {
o.rollback(), c(h);
});
});
i();
} catch (i) {
throw o.rollback(), i;
}
return r;
}
remove(t) {
return !!t;
}
addListener(t) {
const e = this._listeners;
return e.add(t), () => {
e.delete(t);
};
}
addStateListener(t, e) {
if (!t) throw new Error("Model is required");
if (!e) throw new Error("Listener is required");
let n = this._listenersState.get(t);
return n || (n = /* @__PURE__ */ new Set(), this._listenersState.set(t, n)), n.add(e), () => {
n.delete(e), n.size === 0 && this._listenersState.delete(t);
};
}
dispatchEvents(t, e = !1) {
!e || this._isSync ? t() : setTimeout(t, 0);
}
_commitRecord(t, e, n) {
let r = t.record, o = t.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, t = { record: r, commit: o };
}
}
this._commits.set(r.id, t);
}
this._current = t, this._states = this._current.record.states, this._cacheModel = null, this._cacheState = null, n || this._notify("onCommitChange", o), this._notifyStates("onAfterStateChange", t, e, t.record.viewAfter, !1, !1, !0), n || this._notify("onCommitEnd", o, !0);
}
_notifyStates(t, e, n, r, o = !1, s = !1, i = !1) {
const l = e.commit, c = this._listenersState;
n.forEach((h, d) => {
const u = c.get(d);
u && this.dispatchEvents(() => {
u.forEach((g) => {
g[t]?.(h, r, l, o, s);
});
}, i);
});
}
_notify(t, e, n = !1) {
this.dispatchEvents(() => {
this._listeners.forEach((r) => {
r[t]?.(e);
});
}, n);
}
}
class Hu {
constructor(t, e) {
this._children = /* @__PURE__ */ new Set(), this._depth = 0, this._container = null, this._closed = !1, this._container = t, e = typeof e == "string" ? { description: e } : e, this._description = e?.description ?? "", e?.viewBefore !== void 0 && (t.record.viewBefore = t.record.viewBefore && e.viewBefore ? { ...t.record.viewBefore, ...e.viewBefore } : e.viewBefore), e?.viewAfter !== void 0 && (t.record.viewAfter = t.record.viewAfter && e.viewAfter ? { ...t.record.viewAfter, ...e.viewAfter } : e.viewAfter);
}
getView() {
return this._container.record.viewAfter ?? this._container.record.viewBefore;
}
getDepth() {
return this._depth;
}
getDescription() {
return this._description;
}
getStates() {
return this._states;
}
beginTransaction(t, e) {
this._ensureOpen();
const n = new Km(this, this._container, typeof t == "string" ? { description: t } : t, e);
return this._children || this._children, this._children.add(n), n;
}
updateState(t, e) {
this._ensureOpen();
const n = this.getState(t), r = typeof e == "function" ? e(n) : e === void 0 ? n : { ...n, ...e };
if (r) {
let o = this._states;
o || (o = /* @__PURE__ */ new Map(), this._states = o), o.set(t, r);
}
return r;
}
commit(t) {
if (this._ensureOpen(), typeof t == "string" && (t = { description: t }), t) {
if (t.description && (this._description = t.description), t.meta && (this._meta = k.mergeContentful(t.meta, this._meta)), t.viewAfter !== void 0) {
const e = this._container.record;
let n = t.viewAfter;
if (n === null) e.viewAfter = null;
else {
const r = e.viewAfter;
typeof n == "function" && (n = n(r)), e.viewAfter = { ...r, ...n };
}
}
if (t.viewBefore !== void 0) {
const e = this._container.record;
let n = t.viewBefore;
if (n === null) e.viewAfter = null;
else {
const r = e.viewBefore;
typeof n == "function" && (n = n(r)), e.viewBefore = { ...r, ...n };
}
}
}
return this._children && this._children.forEach((e) => {
e.commit(t);
}), this;
}
isClose() {
return this._closed;
}
_ensureOpen() {
if (this._closed) throw this._descriptions && console.warn(`stack: [${this._descriptions.join(",")}]`), new Error("Transaction already closed");
}
_removeChild(t) {
this._children.delete(t), this._mergeStates(t._states);
}
_mergeStates(t) {
if (!t || t.size === 0) return;
let e = this._states;
return e ? (t.forEach((n, r) => {
const o = this.updateState(r, n);
e.set(r, o);
}), e) : (this._states = t, t);
}
}
class Jm extends Hu {
constructor(t, e, n, r, o) {
super(e, r), this._store = t, this._prevStates = n, this._onClose = o, this._states = /* @__PURE__ */ new Map(), this._meta = e.record.meta;
}
getId() {
return this._container.commit.getId();
}
getParent() {
return this;
}
commit(t) {
const e = this._states, n = this._container, r = n.record.viewAfter;
this._store._notifyStates("onBeforeCommitStart", n, e, r, !1, !1), super.commit(t), this._store._notifyStates("onBeforeCommitEnd", n, e, 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, t), this._store._commitRecord(n, e, t?.forceAmend ?? !1), this;
}
rollback() {
return this._ensureOpen(), this._children && this._children.forEach((t) => {
t.rollback();
}), this._closed = !0, this._onClose?.(this, !0, null), this;
}
updateState(t, e) {
const n = super.updateState(t, e);
return this._states.set(t, n), n;
}
getState(t) {
let e = this._states.get(t);
return e || (e = this._prevStates.get(t)), e;
}
_mergeStates(t) {
return !t || t.size === 0 ? /* @__PURE__ */ new Map() : super._mergeStates(t);
}
}
class Km extends Hu {
constructor(t, e, n, r) {
if (super(e, n), !t) throw new Error("Parent transaction required");
this._parent = t, this._depth = this._parent.getDepth() + 1, this._onClose = r;
}
getId() {
return this._parent.getId();
}
getParent() {
return this._parent;
}
getState(t) {
const e = this._states ? this._states.get(t) : void 0;
return e !== void 0 ? e : this._parent.getState(t);
}
commit(t) {
return super.commit(t), this._parent._removeChild(this), this._closed = !0, this._onClose?.(this, !1, t), this._parent ?? this;
}
rollback() {
return this._ensureOpen(), this._children && this._children.forEach((t) => {
t.rollback();
}), this._parent._removeChild(this), this._closed = !0, this._onClose?.(this, !0, null), this._parent ?? this;
}
}
class my extends $m {
constructor(t, e = 50) {
super(e), this._transactions = t;
const n = this;
t?.addListener({ onCommitEnd: (r) => {
r.getDescription() && n.addUndoOperation({ description: r.getDescription(), undo: () => (t.revert(r.getId()), () => {
t.restore(r.getId());
}) });
} });
}
clear() {
super.clear();
}
close() {
this._removeLister();
}
}
const Vu = () => {
try {
return "0.7.27";
} catch {
return "";
}
}, Mn = Object.freeze(Object.defineProperty({ __proto__: null, getBuildDate: () => {
try {
return "Sat Dec 27 2025";
} catch {
return "";
}
}, getBuildVersion: Vu }, Symbol.toStringTag, { value: "Module" })), Xm = `
https://www.sheetxl.com ${Vu()}`, na = "#1976d2", Ym = () => typeof window == "object" ? window.location.hostname : k.getOS(), vr = 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 t = a ? console.log : k.consoleWithNoSource, e = `%c
███████╗██╗ ██╗███████╗███████╗████████╗ ██╗ ██╗██╗
██╔════╝██║ ██║██╔════╝██╔════╝╚══██╔══╝ ╚██╗██╔╝██║
███████╗███████║█████╗ █████╗ ██║ ╚███╔╝ ██║
╚════██║██╔══██║██╔══╝ ██╔══╝ ██║ ██╔██╗ ██║
███████║██║ ██║███████╗███████╗ ██║ ██╔╝ ██╗███████╗
╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝${Xm}
`;
return await t(`${e}`, `font-family:monospace;color:${na};font-size:12px;`), Promise.resolve();
}, printDetails: async (a, t = !1, e = !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.`;
else {
r = `%cLicensee: ${a.getLicensee() ?? "Invalid License"}`;
const i = a.getExpiration()?.toLocaleDateString();
i && (r += `
Expires: ${i}`);
const l = a.getDomains();
l && l.length > 0 && (r += `
Domains: ${l.join(", ")}`);
const c = a.getCpuCount();
c > 0 && (r += `
Cpus: ${c}`);
}
if (!n && a.hasExceptions()) {
s.push("color:red;font-size:12px"), r += `
Exceptions:
%c`;
const i = a.getExceptions(), l = i.length;
for (let c = 0; c < l; c++) r += ` ${i[c]}`;
}
if (e) {
s.push("color:#FFA726;font-size:12px"), r += "%c", r += `
Location: '${Ym()}'`;
const i = a.getKeyFrom();
i && (r += `
KeyFrom: '${i}'`);
}
return await o(`${r}`, ...s), Promise.resolve();
}, setKey: async (a, t = !1) => {
throw new Error("setKey is not implemented in browser environment");
} }, Symbol.toStringTag, { value: "Module" })), Qm = (a, t, e = 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, e - t), Zm = (a) => typeof window == "object" ? window.atob(a) : Buffer.from(a, "base64").toString("ascii");
function Je(a, t, e, n, r) {
return Ct(r - 585, t);
}
function sr(a, t, e, n, r) {
return Ct(r - -291, t);
}
function Ge(a, t, e, n, r) {
return Ct(n - 336, t);
}
function Ct(a, t) {
const e = Kl();
return Ct = function(n, r) {
let o = e[n -= 287];
if (Ct.dAjZUq === void 0) {
const l = function(c, h) {
let d, u, g = [], m = 0, f = "";
for (c = (function(p) {
let _ = "", S = "";
for (let C, y, E = 0, w = 0; y = p.charAt(w++); ~y && (C = E % 4 ? 64 * C + y : y, E++ % 4) ? _ += String.fromCharCode(255 & C >> (-2 * E & 6)) : 0) y = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=".indexOf(y);
for (let C = 0, y = _.length; C < y; C++) S += "%" + ("00" + _.charCodeAt(C).toString(16)).slice(-2);
return decodeURIComponent(S);
})(c), u = 0; u < 256; u++) g[u] = u;
for (u = 0; u < 256; u++) m = (m + g[u] + h.charCodeAt(u % h.length)) % 256, d = g[u], g[u] = g[m], g[m] = d;
u = 0, m = 0;
for (let p = 0; p < c.length; p++) u = (u + 1) % 256, m = (m + g[u]) % 256, d = g[u], g[u] = g[m], g[m] = d, f += String.fromCharCode(c.charCodeAt(p) ^ g[(g[u] + g[m]) % 256]);
return f;
};
Ct.WDzigD = l, a = arguments, Ct.dAjZUq = !0;
}
const s = n + e[0], i = a[s];
return i ? o = i : (Ct.jSKGYA === void 0 && (Ct.jSKGYA = !0), o = Ct.WDzigD(o, r), a[s] = o), o;
}, Ct(a, t);
}
(function() {
const t = ")fcd", o = "BY8L", s = "yrta", i = "*AVt";
function u(S, C, y, E, w) {
return Ct(C - 921, E);
}
function g(S, C, y, E, w) {
return Ct(w - 321, E);
}
function m(S, C, y, E, w) {
return Ct(S - -487, y);
}
const f = Kl();
function p(S, C, y, E, w) {
return Ct(y - -565, w);
}
function _(S, C, y, E, w) {
return Ct(E - 936, w);
}
for (; ; ) try {
if (-parseInt(g(0, 0, 0, "zi#r", 801)) / 1 + parseInt(g(0, 0, 0, t, 810)) / 2 + parseInt(g(0, 0, 0, "5YcQ", 675)) / 3 * (parseInt(m(-156, 0, "95xO")) / 4) + -parseInt(p(0, 0, -226, 0, ")fcd")) / 5 + -parseInt(p(0, 0, -171, 0, o)) / 6 + parseInt(u(0, 1350, 0, s)) / 7 * (-parseInt(_(0, 0, 0, 1323, "%fv$")) / 8) + parseInt(m(-50, 0, i)) / 9 * (parseInt(_(0, 0, 0, 1280, "2mxJ")) / 10) === 949345) break;
f.push(f.shift());
} catch {
f.push(f.shift());
}
})();
const Si = () => {
const a = "pkPC", e = "BY8L", n = "isRc";
function o(l, c, h, d, u) {
return Ct(u - 638, h);
}
if (typeof window === Ct(393, "cn71")) return window[o(0, 0, a, 0, 1064)][o(0, 0, e, 0, 1074)];
var s, i;
return k[s = n, i = 572, Ct(i - 144, s)]();
}, fl = () => {
const t = "zi#r", r = "^3yY";
function o(s, i, l, c, h) {
return Ct(s - -276, h);
}
return Si()[o(60, 0, 0, 0, t)](Ct(445, "5YcQ")) || Si() === o(116, 0, 0, 0, r);
};
function Vn(a, t, e, n, r) {
return Ct(r - -105, a);
}
const tf = (a, t) => {
function r(s, i, l, c, h) {
return Ct(h - -254, c);
}
function o(s, i, l, c, h) {
return Ct(s - 443, h);
}
return { getLicensee: () => null, getExpiration: () => null, getDomains: () => [], getDeveloperCount: () => 0, getCpuCount: () => 0, getType: () => r(0, 0, 0, "95xO", 137), getExceptions: () => {
return [(s = "95xO", i = -213, r(0, 0, 0, s, i - -308) + a + "'")];
var s, i;
}, hasExceptions: () => !0, isValidFor: (s) => !1, isValid: () => !1, isEval: () => !1, getFeatures: () => {
return Object[s = "pJq^", i = 1061, Ct(i - 622, s)]({});
var s, i;
}, getKeyFrom: () => a, getBuildVersion: Mn[o(747, 0, 0, 0, "ye^p")], getBuildDate: Mn[o(745, 0, 0, 0, "qmIz")] };
}, ef = (a, t, e, n) => {
const r = "PLkM", o = "a8i&";
function c(g, m, f, p, _) {
return Ct(_ - -686, f);
}
function h(g, m, f, p, _) {
return Ct(p - 780, m);
}
function d(g, m, f, p, _) {
return Ct(p - -415, f);
}
function u(g, m, f, p, _) {
return Ct(g - 96, m);
}
return { getLicensee: () => a[d(0, 0, "]X&b", -14)], getExpiration: () => new Date(a[d(0, 0, "5YcQ", -96)]), getDomains: () => a[h(0, "*AVt", 0, 1231)] ?? [], getDeveloperCount: () => a[h(0, "qmIz", 0, 1252)] ?? 1, getCpuCount: () => a[c(0, 0, "qYKj", 0, -304)] ?? 0, getType: () => {
return a[g = "%u^I", m = 20, Ct(m - -327, g)] ?? c(0, 0, "2SvB", 0, -353);
var g, m;
}, getExceptions: () => t, hasExceptions() {
return !!t && t[g = 56, m = "K[Mf", d(0, 0, m, g - 131)] > 0;
var g, m;
}, isValidFor: (g) => {
return !(t?.[m = "2mxJ", f = 524, d(0, 0, m, f - 499)] > 0);
var m, f;
}, isValid: () => !0, isEval: () => !1, getFeatures: () => Object[u(470, "cn71")](a[u(555, "a8i&")] ?? {}), getKeyFrom: () => e, getBuildVersion: Mn[c(0, 0, r, 0, -291)], getBuildDate: Mn[c(0, 0, o, 0, -380)] };
}, yc = (a) => {
const n = "%fv$", r = "tjoR";
function i(g, m, f, p, _) {
return Ct(g - 623, _);
}
function l(g, m, f, p, _) {
return Ct(f - 219, g);
}
function c(g, m, f, p, _) {
return Ct(_ - 537, p);
}
function h(g, m, f, p, _) {
return Ct(p - -175, m);
}
let d = k[l("cn71", 0, 630)];
if (fl() || k[l("0^0L", 0, 516)]()) {
const g = Mn[l("0^0L", 0, 694)](), m = new Date(g), f = /* @__PURE__ */ new Date();
Math[i(949, 0, 0, 0, n)]((f[u(-350, -271, "n]#x")]() - m[i(915, 0, 0, 0, "Htrf")]()) / 864e5) >= 120 && (d = [h(0, "O*g*", 0, 228)]);
} else d = [];
function u(g, m, f, p, _) {
return Ct(g - -658, f);
}
return { getLicensee: () => u(-198, 0, "EQ$v"), getExpiration: () => null, getDomains: () => [Si()], getDeveloperCount: () => 1, getCpuCount: () => 0, getType: () => i(946, 0, 0, 0, "quum"), isEval: () => !0, getExceptions: () => d, hasExceptions: () => d[h(0, "s6t2", 0, 188)] > 0, isValidFor: () => d[c(0, 0, 0, "qmIz", 989)] === 0, isValid: () => !1, getFeatures: () => Object[c(0, 0, 0, "[gr%", 869)]({}), getKeyFrom: () => a, getBuildVersion: Mn[c(0, 0, 0, r, 1016)], getBuildDate: Mn[c(0, 0, 0, "n]#x", 904)] };
}, Cc = () => {
const a = "n]#x", e = "I284", n = "95xO";
if (Dt[o(")fcd", -68, -126)] && Dt[o("qYKj", -153, -71)]) return !1;
function o(d, u, g, m, f) {
return Ct(g - -515, d);
}
const s = Dt[i = -538, l = "Lh3c", Ct(i - -853, l)];
var i, l, c, h;
return !!(s[o(a, 0, -188)]() || s[c = 1257, h = e, Ct(c - 874, h)]() || s[o(n, 0, -68)]()?.pb);
}, Dt = { promise: null, printNeeded: !1, details: null, bannerPrinted: !1, detailsPrinted: !1, licenseKey: null, keyFrom: null };
function Kl() {
const a = ["rCkabHLIWQ1Tm8krWQL5W6mA", "z8o/WOSmWOn8", "WOb7W4RdJaTxW5C0D0qYWQJcJa", "WPHQBrNcUshdKW", "W7nJWOTcW7/cN8os", "W57dMY/dHCk0WQ8eWQVcG8kyW4ldNCo2", "W4BdSCkD", "W7JdUcfZW4ZcHCkcWRBdQaq", "iSohpSo2WOZcVbRdPeyW", "W7RdOrKdWOddMWdcIq", "W4L1W5xcLNSjW7NdUdtdJGDExa", "WPxdSYrqiWK", "WOdcUGrI", "WQxcVHycWONdMYFcRCoOW68", "FSkvabfLWRvA", "v8k/WOqXWObFWOabxSoXWRBcH8ka", "w8k7WOmvWPfqWPyHwmoXWRFcNCkwWOS", "hepcQcWHwCkTW4DHW5tcI8kSW48", "W4lcSxldMW8mW5epvqa", "BSklW4BdMCoNdNS9", "w8krW6DPW6bUwZKMsCks", "lSkMDmkTiXj6", "W6CdDSk6zSobW6Xf", "W4lcGmkfWRTJWQ1n", "W4zCoCkDva", "W4JdVe89ASkbW6yTWRywjvu", "W4NdUH1OW5BcPCkCWQhdJrZcP8kkdmknWOKzdYO", "WQeuWPCCWQaiWRhcNa", "W5NdScvMW5ZcQmkdWPtdUXtcVCkBoSkD", "lmopm8o9WOFcVs/dNuONe8kzW4y", "oZeCW43cQ8kvlCkVW4y", "pWDPpmkIm1CUW6hdPZ/cMmou", "W4ldHLzJoCkcWO3dOW", "W51IW4RdMmknyZZcVCozv2hdGHu", "k8oWB151lmkpWO85CqxcPNS", "W6zuqePXda", "bCkOzSkckrm", "WOP5BbRcTsddPNfUW6K8fee", "s8o/WPumWPK", "WOpdVZvljqnQeSokcW", "wCo9vs3cNCkeq8o3emoUDSkPch0", "bmo2WRj0W6tdTmozzCkE", "W43dPZ5QW5ZcT8kv", "W7BcRCk0WRHsWPr1W6BcIL7cVq", "W5qCz8kYFmoCW4fkCI/dTSkE", "WPNcVdLLnSoD", "oSoLyejKlCkiWPqKDW", "WO44WPlcJmoCo38", "W4BcImkYWQvytW", "W57cTmkGWQq4W548W55zm13cSW", "W6LvyfLQbq", "W7noqeP/eCk0dSkFWOyMlSoawSoSrmo+jwO", "WRpcMgxcLCoPW65WWRNcMmkwW7VdSSox", "WPX9EGa", "sCk4mtvyWOfLcCkPWOftW4ONWPVcLH8NqKC", "W4JcVxddIHqnW5e3", "WOZcOrqlWPldItBcJ8oIW7Gyy1FcJCk7xMDf", "W7lcP8kUWO1yWPLKW4tcKu/cPIuuW7xcJIqVW60A", "W43dPZHPW4hcISkvWQhdRrJcTW", "WPHOW5BdPbPhW5C", "dLNdN8kPWQxdISo+W4FdV8oN", "WRDUyXJcUtBdL3DI", "l8ous8kWW7mFW54jj8oNuCk+yG", "W4FcQ1/dKquA", "irGnW5pdPmkTk8ktW7XDW7ZdPx3dT2ZcPq", "eSkWW5VdLCk5D8ovWRXbpLRdUW", "pCkYW4ddKSkJqCo2WRnbnu0", "WPBcIauvWOJdNc3cUCos", "W47cImkQWQDashCZW7KhWQZdICoCW5u", "WRTyWQOkW6FdKhe", "kSolkCoYWOVcOWW", "x8kBW71nW7XGzcKnwSkdW7K", "W6LvC05Namk8", "W4lcVx/dMrux", "WQrZW5RdRb1hW5DKzLuTWQ/cJCorgWBcOHhdSW", "vmkVW6uvFmo0WOj0W4/cKSk7WPG3W6tcUW", "dSoSW4rdW4SkW5uYE8oQWPxcPmkd", "WOpdSCo5W78", "wmk7WOm2WO1vWOKvFmo9WQVcMSkAWOdcQW", "W4LypSkxFY3dNYhdGv5mo8k7", "nSk9ESkmmW/cNsRcLmkzWPGDW5q", "bmkUW5/dNCk7ASoZW71kke/dOa16vCk1pLO", "W5fljmk8CWRdNYxdLf5pjG", "aHWjW5RcVSke", "z8kHW7L9W6z9zXiw", "W4XdW4b1W6fuW6/cN8oElmoOWPr6", "eKFcQcuWqW", "W5pcT8kQWQmXW5yEW4rjdhZcSW", "wahcHmolgCkEWPPMWOZdNLVcTG", "W68jyCk6E8oeW7b7BIJdVCkyk8kj", "WR3cNSomCXnmvSo7W4m", "kColkCohWOVcOHO", "WOddVIDr", "t8o9rtNcL8kn", "WO4YWOVcJmoCox8", "WOdcV8kNabnyW65dCrNdICotW6S", "uCknW4DGW61S", "cael", "W5KhW452B0BcGaG/", "W5ePmKZdOMFdPNf0W58acq", "tCoQtIhcNCkBvq", "W43cImkOWObztMSYW48LWRFdMq", "W4NcVwxdTqqg", "W79JWOzgW7JcMCotwJxdQaG0W6BcK1e", "W497W5BcMxCvW5O", "W4NcVwxdVbqwW5GGDbJcTHa", "tb/cJCoSW6lcJ8kzW63dMSo9W4Kcoa", "v8ofgdVdOSo5W6W", "pCoBlCoJWPdcQGZdNhm7dSksW5y", "w8kRW6isCCo+WOTGW63cNSkMWOuT", "WQeaWOOLWRWv", "W48FW5L7AKVcHvW+q8oAW4zoWPu", "rSojhWBdV8k0", "W5/dTd9PW5dcTSkGWRBdObpcP8kkoW", "kCkLW53dNCk+B8oK", "pSoCnmo9WPy", "WRDQW4VdOb1aW7yHD0W0WQRcJa", "W5RdScvdW5dcSmkrWQ3dPq4", "dCoHWQf8W7RdPq", "xCkqW618W55GFcu", "W5qADmk3E8omW6jFEq", "W5pdUJvIW7ZcOa", "W6RdQ3m0", "W5ddRwaXBZ8", "jWTPWQ0gnW", "WQTvWQKqW7a", "wCotkrNdQSo4", "W4hdJfXrjCkmWO0", "WQ8ZW4CXWRxdHSkpvYBdUZiqW4K", "oSoCnmoYWO4", "WQldVSkSWPPqWOzdW7W", "lmkXzCkPmbS", "wCkFgr15WRDaiSkC", "W47cImkOWQnfs3qgW7KTWQ3dImoxW4u", "W63dSmoljrLEW6vEz1ZcOSo9W7CN", "wSkWWPmhWQ9vWPez", "WOpcUXz4jSolW6CvWPOh", "W5tdPHrXW5tcQa", "W4DbW4H0W6buWO/cMSocg8oWWQ8", "W4DXW5xcN2Ot", "WRNcPrWjWPpdQIpcImoJW7nk", "y087W6TeC3iDnWSGWObc", "yH/cGmo0fSky", "w8o9uCkCnJZcVIq", "WOddOSoSW7bOW49nWQeU", "W5KbW51ZAfBcOX00qSosW5u", "kmoit8kz", "W5pdRCkcbWrZW6vvCfZdPG", "W5JcPSk2WP9BWPXLWRpcTflcRq4vW5xcHhe2W6Sgc2dcOWbOycpdKG", "gbSFomk2kLO", "qmk6W70+Fq", "WPxdPJvqpva", "WOtcVr5N", "xCkPW6mLWRNcRCocxCkIWRnoWPK", "qmovhWC", "W7SzzSkZ", "Bmk6W6m+z8oP", "W5ZcVwldKq0jW5e", "WOpdRIb1obnyfConbMRcVmoP", "rmoshehdHCk1mCk1W4SkW4jX", "W7xdJuPhjCkkWO7dSG", "dKJdISkqWRtdGa", "W6OuW4f9CKO", "W6RdPwiXCZi", "bGK6cCkOkLaOW6xdTW", "ybtcGSoMeSkEWRLUWO7dGW", "v8ofgc3dVSo9W6xcGCksrmotWR0", "fbWdW5lcRCksjW", "gmoRWRH7W7ZdKSotC8koWPbB", "BSkzW4JdPCo8a3q9WR4", "W4BdS2q5BsjOAWRdJmkthZ/dP8okomkvWR3dMIG", "WQNcNSomDHLr", "WQ7cSGeJWOldNcpcJ8oHW6u", "W5VdPZrIW4/cOq", "W6GfECo1FSoqW7DoEsNdOa", "WQZcMSousbLUrq", "W6ldOZbRW5ZcOmkrWRddRa", "WQPCWRi7W6FdOMy+emoz", "a8kVWONdL8kYEG", "WPCdWRyJWRye", "dLFcTsO", "xSoOva/cM8kDxSot", "fKpcTqC8smkyW4v8W5pcKmkNW5G", "WPBdS3CfbSktC8o0W4VcUvZcJseDfCkZWRSUd8kd", "WPtcLmkyurvlvSoCW5rYW7mrW7SdWPNcGMrjqW", "pqXnWQ8ska", "W7GpWOK7W7VdTu4B", "W7/dR301AdHP", "WPWrWPyIWRCtWO/cMSoylComWRjm", "W5NdGubYi8kBWOW", "W7JcPSk2WP9BWPXL", "tb/cICo1W6hcL8kzWOdcUG", "W5ldTZTIW5BcSa", "WP3cMryLymouW5tdLGjTzSkYW6m", "W6BdJINdRSkVWRiSWQRcOCkCW5NdGSoSieK", "WOddTCkPW6DeW6q", "WPKKW6lcGxu8W47dOq", "sCk/WPSbWP16WPm", "E8kyeSoxWPVcRdBdOW", "nCocCCktW74z", "W5/dNSooWRFdKgf5kq", "mXPMWRWbjtiOns8WWRfBW6e", "W6BdQCkkbqvCW7rzE1FcOSogW7CSWPOMW7zbWP7dItdcR1z/WO8"];
return (Kl = function() {
return a;
})();
}
function Ke(a, t, e, n, r) {
return Ct(t - 364, n);
}
let ra = !1, Ec = !1;
const bc = Ke(0, 739, 0, "pkPC")[Vn("mkg%", 0, 0, 0, 337)]("")[Je(0, "qYKj", 0, 0, 879)]((a, t) => t + a, "");
class nf {
constructor() {
var t, e, n, r;
this[n = -381, r = "dlzU", Ke(0, n - -1179, 0, r)][t = "%fv$", e = 124, Ke(0, e - -713, 0, t)] = null;
}
async [Ge(0, "5EuH", 0, 695)](t, e = !1) {
const n = "n]#x", u = "^3yY", f = "]Wcn", v = "KVqn", B = "%u^I", G = "pkPC", K = "(tPy";
if (!t || t[at(-532, "yrta", -443, -504)](q(n, 387, 451, 391, 440)) || t[at(-439, "Vr18", -439, -391)](X(280, 293, 255, 352, "5EuH")) || t[ut("^3yY", 816, 803, 773)](ut("Htrf", 573, 574, 639)) || t[q(u, 544, 515, 674, 591)](ut(f, 748, 861, 790))) return ra = !0, k[ut("%u^I", 751, 786, 709)]() && await vr[at(-478, "HoeA", -549, -469)](t, e), await this[Q(975, "7&TX", 869, 875)](!0);
if (ra = !1, !e && Dt[X(340, 285, 252, 362, "Htrf")]) {
const tt = await this[ut(v, 822, 795, 774)]();
if (tt[at(-329, "pJq^", -328, -365)]() && !tt[Q(924, "334W", 792, 891)]()) return tt;
}
function q(tt, rt, ct, lt, nt) {
return Je(0, tt, 0, 0, nt - -458);
}
function Q(tt, rt, ct, lt, nt) {
return Ke(0, lt - 141, 0, rt);
}
Dt[Q(988, "EQ$v", 896, 922)] = t, Dt[ut("ye^p", 702, 737, 717)] = X(394, 427, 375, 416, B), Dt[q("*AVt", 0, 0, 0, 422)] = null, Dt[q(v, 0, 0, 0, 534)] = null;
const it = await this[Q(0, G, 0, 826)]();
if (!it[q(K, 0, 0, 0, 477)]()) throw await this[X(252, 195, 181, 226, "quum")](!0), new Error(Q(0, "quum", 0, 876));
function X(tt, rt, ct, lt, nt) {
return Vn(nt, 0, 0, 0, tt - 33);
}
function at(tt, rt, ct, lt, nt) {
return Je(0, rt, 0, 0, lt - -1426);
}
function ut(tt, rt, ct, lt, nt) {
return Ge(0, tt, 0, lt - -27);
}
return await vr[q("^3yY", 0, 0, 0, 489)](t, e), it;
}
async [Vn("s6t2", 0, 0, 0, 194)](t = !1) {
const i = "O*g*", c = "qYKj", d = "EQ$v", u = "HoeA", g = "0^0L", f = "quum", p = "Htrf", _ = "BY8L", C = "a8i&", y = "dlzU", E = "2SvB", b = "pJq^", v = "334W", I = "KVqn", x = "2mxJ", M = "I284", O = "]Wcn", D = "zi#r", z = "n]#x", H = "5YcQ", P = "Htrf", K = "xl6P";
if (t && (Dt[at(1035, 1050, 949, "2SvB")] && !Dt[at(1058, 982, 998, "KVqn")] && this[ut(932, 951, 900, "7&TX")](), Dt[X(-679, i, -665, -562, -641)] = !0), Dt[tt(-236, "cn71", -278, -358, -321)]) return Dt[$(63, c, -11, 77, 58)];
function $(rt, ct, lt, nt, gt) {
return Ge(0, ct, 0, gt - -579);
}
if (!this[ut(915, 999, 1048, d)][tt(-337, u, -368, -343, -391)] && (this[$(0, g, 0, 0, 245)][ut(963, 926, 924, "zi#r")] = new Error("FV")), Dt[X(-574, "xl6P", -431, -502, -526)]) return Dt[X(-631, f, -634, -502, -601)];
let J = null;
Dt[X(-689, "dlzU", -582, -580, -621)] = new Promise((rt) => {
J = rt;
});
let Z, q = null;
const Q = async (rt, ct) => {
try {
const St = ((It) => {
let _t = It;
const Gt = _t[_t.length - 1], ke = Gt.charCodeAt(0) - 52;
if (_t = _t.substring(0, _t.length - 1), _t = _t.split("").reverse().join(""), _t = Zm(_t), _t = _t.trim(), _t[_t.length - 1] !== Gt) throw new Error();
_t = _t.substring(0, _t.length - 1), _t = Qm(_t, ke);
try {
_t.startsWith("{") || (_t = "{" + _t);
const Et = JSON.parse(_t), Ut = { licensee: Et.l, domains: Et.d, nodeId: Et.n, expiry: Et.e, developerCount: Et.dc, cpuCount: Et.cc, type: Et.t };
return Et.f && (Ut.features = Et.f), Ut;
} catch {
throw new Error("Invalid license key.");
}
})(ct), wt = await (async (It) => {
const Gt = "quum", ke = "5EuH", Et = "pkPC", Ut = "(tPy", Rt = "I284", Mt = "cn71", kt = ")fcd", Pt = "2mxJ", At = "0^0L", Jt = "yrta", je = "s6t2", Dn = It[io(1026, 1110, 1109, "K[Mf")];
function rr(en, mn, $e, lo, co) {
return Ct($e - 486, mn);
}
function gn(en, mn, $e, lo, co) {
return Ct($e - -577, en);
}
function io(en, mn, $e, lo, co) {
return Ct(mn - 805, lo);
}
const us = It[io(0, 1169, 0, Gt)] ? new Date(It[ao(-41, ke, -65, -84, -73)]) : null;
function fc(en, mn, $e, lo, co) {
return Ct($e - 711, en);
}
It[gn("cn71", 0, -255)];
const or = [];
if (us ? isNaN(us) ? or[io(0, 1160, 0, "n]#x")](rr(0, "Lh3c", 971)) : us < /* @__PURE__ */ new Date() && or[io(0, 1186, 0, Rt)](io(0, 1283, 0, "xl6P") + us[gn(Mt, 0, -147)]()) : or[gn(Et, 0, -221)](ao(46, Ut, -154, -116, -53)), !k[fc(kt, 0, 1091)]()) {
if (fl()) return or;
if (Dn && Dn[rr(0, Pt, 926)] !== 0) {
let en = !1;
const mn = Si();
for (let $e = 0; !en && $e < Dn[ao(-99, "a8i&", -46, 68, -11)]; $e++) en = mn[ao(-163, At, -179, -146, -168)](Dn[$e]);
!en && or[rr(0, Jt, 902)](fc(je, 0, 1023));
} else or[gn(ke, 0, -284)](ao(-78, "56[0", -91, -108, -104));
}
function ao(en, mn, $e, lo, co) {
return Ct(co - -488, mn);
}
return or;
})(St), jt = ef(St, wt, rt);
return jt[lt = 444, nt = 430, gt = K, ut(lt - 116, nt - -504, nt - 139, gt)]() && (Z = jt), jt;
} catch {
Z = tf(rt);
}
var lt, nt, gt;
};
Dt[$(0, p, 0, 0, 169)] && (q = await Q(Dt[tt(-487, _, -437, -536, -439)], Dt[ut(880, 950, 941, C)]));
let it = !1;
function X(rt, ct, lt, nt, gt) {
return Vn(ct, 0, 0, 0, gt - -884);
}
function at(rt, ct, lt, nt, gt) {
return Vn(nt, 0, 0, 0, rt - 722);
}
function ut(rt, ct, lt, nt, gt) {
return Ke(0, ct - 164, 0, nt);
}
function tt(rt, ct, lt, nt, gt) {
return sr(0, ct, 0, 0, gt - -476);
}
if (ra && (it = !0, q = yc($(0, y, 0, 0, 225))), !q)
if (k[at(1084, 0, 0, "a8i&")]()) {
if (!q) {
const rt = process[tt(0, "O*g*", 0, 0, -357)], ct = rt[tt(0, E, 0, 0, -309)] || rt[ut(0, 955, 0, "95xO")] || rt[$(0, "BY8L", 0, 0, 147)] || rt[at(1072, 0, 0, b)];
ct && (q = await Q(X(0, "r&sB", 0, 0, -646), ct));
}
if (!q) {
const rt = await vr[$(0, C, 0, 0, 60)]();
rt && (q = await Q(ut(0, 952, 0, g), rt));
}
!q && (it = !0);
} else {
if (!q) {
let rt = !1;
try {
const ct = await fetch("./" + bc);
let lt = null;
if (ct[X(0, v, 0, 0, -664)] === 200) {
const nt = (await ct[tt(0, I, 0, 0, -310)]())[tt(0, "tjoR", 0, 0, -416)](`
`), gt = nt[X(0, x, 0, 0, -549)];
for (let St = 0; !lt && St < gt; St++) {
const wt = nt[St][$(0, "yrta", 0, 0, 110)]();
wt[at(904, 0, 0, M)] !== 0 && (wt[$(0, "5EuH", 0, 0, 200)](X(0, i, 0, 0, -693)) ? rt = !0 : lt = wt);
}
}
if (rt && lt) {
const nt = X(0, O, 0, 0, -644) + bc + "')";
q = await Q(nt, lt);
}
} catch {
}
}
!q && fl() && (it = !0);
}
return !q && it && (q = yc($(0, "O*g*", 0, 0, 92))), !q && Z && (q = Z), !q && (q = { getLicensee: () => null, getExpiration: () => null, getDomains: () => [], getDeveloperCount: () => 0, getCpuCount: () => 0, getType: () => null, isEval: () => !1, getExceptions: () => [$(0, "HoeA", 0, 0, 142)], hasExceptions: () => !0, isValidFor: (rt) => !1, isValid: () => !1, getFeatures: () => Object[tt(0, "dlzU", 0, 0, -280)]({}), getKeyFrom: () => tt(0, "Lh3c", 0, 0, -388), getBuildVersion: Mn[tt(0, D, 0, 0, -285)], getBuildDate: Mn[tt(0, z, 0, 0, -400)] }), Dt[tt(0, "[gr%", 0, 0, -342)] = q, Dt[X(0, "cn71", 0, 0, -527)] = t && Cc(), J(q), Dt[at(986, 0, 0, H)] && this[tt(0, ")fcd", 0, 0, -336)](), Dt[ut(0, 1002, 0, P)];
}
async [sr(0, "s6t2", 0, 0, 55)](t) {
const n = "EQ$v", o = "pkPC", l = "isRc", c = "a8i&";
var h, d;
Dt[h = "cn71", d = 1150, sr(0, h, 0, 0, d - 1127)] = !0;
const u = await this[m(1143, "%fv$", 1107, 1065)]();
function g(S, C, y, E, w) {
return Ge(0, S, 0, C - -484);
}
function m(S, C, y, E, w) {
return Vn(C, 0, 0, 0, E - 792);
}
function f(S, C, y, E, w) {
return Je(0, y, 0, 0, C - -1046);
}
var p, _;
return await vr[m(969, n, 940, 1028)](t), !t && !Dt[g(o, 142)] && (u[f(0, -7, "pJq^")]() || u[g("zi#r", 271)]()) && await this[p = "2mxJ", _ = -168, Je(0, p, 0, 0, _ - -1237)](t, u[m(0, l, 0, 1170)]()), Promise[f(0, -103, c)]();
}
async [sr(0, "PLkM", 0, 0, 118)](t = !1, e = !1, n = !1) {
const r = "EQ$v", o = "Htrf", i = "tjoR", l = "pkPC", c = "&JRw";
Dt[p(-171, -94, -78, "qmIz")] = !0;
const h = await this[d = r, u = 553, Ke(0, u - -184, 0, d)]();
var d, u, g, m;
function f(_, S, C, y, E) {
return Ge(0, S, 0, y - -949);
}
Dt[p(-72, -92, -45, o)] || !h[g = "cn71", m = 671, Je(0, g, 0, 0, m - -252)]() && !h[f(0, i, 0, -303)]() ? await vr[f(0, c, 0, -253)](h, t, e, n) : await this[p(-57, -2, 10, l)](t);
function p(_, S, C, y, E) {
return Je(0, y, 0, 0, _ - -1090);
}
}
async [Ge(0, "BY8L", 0, 697)]() {
if (Cc()) {
if (Ec) return void setTimeout(() => {
var r, o;
this[r = "tjoR", o = 1319, Ct(o - 962, r)](!1, !1);
}, 8e3);
await this[e = ")fcd", n = 1269, Vn(e, 0, 0, 0, n - 1063)](!1, !1);
}
var e, n;
}
async [sr(0, "qTUf", 0, 0, 105)](t, e) {
const s = "I284", d = "dlzU", g = "95xO", f = "xl6P";
if (!t && (Dt[y(706, 716, "Vr18", 610, 687)] || Dt[y(673, 751, "zi#r", 581, 669)])) return;
var p, _;
Dt[p = 264, _ = s, Ke(0, p - -521, 0, _)] = !0, Dt[E(-329, -220, -249, -257, "cn71")] = !0, await this[E(-412, -383, -323, -400, "r&sB")](t);
const S = k[w("yrta", 1356, 1381, 1356)](), C = t || S ? console[y(481, 499, d, 480, 547)] : k[w(g, 1417, 1325, 1368)];
function y(b, v, I, x, R) {
return Ge(0, I, 0, R - -87);
}
function E(b, v, I, x, R) {
return Je(0, R, 0, 0, x - -1274);
}
function w(b, v, I, x, R) {
return Ke(0, x - 543, 0, b);
}
S && C(""), await this[E(0, 0, 0, -372, f)](t, e), C("");
}
[sr(0, "cn71", 0, 0, 27)]() {
return this[t = "cn71", e = 39, Ge(0, t, 0, e - -674)](!0);
var t, e;
}
[Ke(0, 680, 0, "Htrf")](t) {
return this[e = -326, n = "mkg%", Je(0, n, 0, 0, e - -1316)](!0, t);
var e, n;
}
[Ge(0, "(tPy", 0, 701)]() {
function t(e, n, r, o, s) {
return Ke(0, r - 261, 0, s);
}
return Dt[t(0, 0, 1039, 0, "K[Mf")] || Dt[t(0, 0, 915, 0, "pkPC")];
}
[Ge(0, "Htrf", 0, 645)](t) {
Ec = !0;
}
async [Ke(0, 834, 0, "Lh3c")]() {
return this[t = "Lh3c", e = 1239, Vn(t, 0, 0, 0, e - 875)](!0);
var t, e;
}
async [Ge(0, "isRc", 0, 822)](t, e) {
const n = "r&sB", r = "2SvB";
function o(i, l, c, h, d) {
return Je(0, l, 0, 0, c - -1132);
}
const s = await this[o(0, n, -181)]();
return await this[o(0, r, -143)](!0, t, e), s;
}
async [Je(0, "HoeA", 0, 0, 876)]() {
var t, e;
return await vr[t = -506, e = "334W", sr(0, e, 0, 0, t - -617)]();
}
}
const ju = new nf(), pl = (a, t) => {
const e = [];
for (let n = 0; n < a.length; n++) {
const r = a[n];
e.push({ x: r.x + t.x, y: r.y + t.y });
}
return e;
}, _l = (a, t) => {
if (!a) return { ...t };
if (!t) return { ...a };
let e = Math.min(a.x, t.x), n = Math.min(a.y, t.y);
return { x: e, y: n, width: Math.max(a.width + a.x, t.width + t.x) - e, height: Math.max(a.height + a.y, t.height + t.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 }], Sl = (a) => {
let t = Number.MAX_SAFE_INTEGER, e = 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];
t = Math.min(t, s.x), e = Math.min(e, s.y), n = Math.max(n, s.x), r = Math.max(r, s.y);
}
return { x: t, y: e, width: n - t, height: r - e };
}, sa = (a, t, e) => {
if (!e) {
const i = Sl(a);
e = { x: i.x + i.width / 2, y: i.y + i.height / 2 };
}
a = pl(a, { x: -e.x, y: -e.y });
const n = t * 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 = pl(s, { x: e.x, y: e.y });
}, $u = (a, t, e, n, r, o, s, i, l = !0) => {
if (a === e && t === n || r === s && o === i) return !1;
let c = (i - o) * (e - a) - (s - r) * (n - t);
if (c === 0) return !1;
let h = ((s - r) * (t - o) - (i - o) * (a - r)) / c, d = ((e - a) * (t - o) - (n - t) * (a - r)) / c;
return (!l || !(h < 0 || h > 1 || d < 0 || d > 1)) && { x: a + h * (e - a), y: t + h * (n - t) };
}, Se = (a, t, e = !0) => $u(a.p1.x, a.p1.y, a.p2.x, a.p2.y, t.p1.x, t.p1.y, t.p2.x, t.p2.y, e), 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] } }), vc = (a, t, e) => {
let n = e * Math.PI / 180, r = Math.sin(n), o = Math.cos(n);
return { x: a * o - t * r, y: a * r + t * o };
}, Ln = (a, t) => {
let e = a.p2.x - t.x, n = a.p2.y - t.y;
const r = vc(e, n, 90);
e = r.x + t.x, n = r.y + t.y;
let o = a.p1.x - t.x, s = a.p1.y - t.y;
const i = vc(o, s, 90);
return o = i.x + t.x, s = i.y + t.y, { p1: { x: o, y: s }, p2: { x: e, y: n } };
}, fy = Object.freeze(Object.defineProperty({ __proto__: null, angleToPoints: (a, t) => {
const e = (180 - a) / 180 * Math.PI, n = Math.abs(t.width * Math.sin(e)) + Math.abs(t.height * Math.cos(e)), r = Math.sin(e) * n / 2, o = Math.cos(e) * n / 2, s = t.width / 2, i = t.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, t, e = 0) => {
if (e < 0 && (e += 360), e > 90 && e <= 180 ? e += 180 : e > 180 && e <= 270 && (e -= 180), e === 0 || e === 180) return { height: t.height, width: t.width };
if (e === 90 || e === 270) return { height: t.width, width: t.height };
let n = oa({ ...t, x: 0, y: 0 }), r = oa({ ...a, x: 0, y: 0 });
r = pl(r, { x: t.width / 2 - a.width / 2, y: t.height / 2 - a.height / 2 }), r = sa(r, e);
let o = gs(r), s = gs(n);
if (e > 90) {
const l = Se(o.top, s.top);
if (l) {
const h = l, d = Se(o.bottom, s.bottom, !1) || r[3];
r[0] = Se(o.top, Ln(o.bottom, d), !1) || r[0], r[1] = h, r[3] = d, r[2] = Se(o.bottom, Ln(o.top, h), !1) || r[2], o = gs(r);
}
const c = Se(o.top, s.left);
if (c) {
const h = c, d = Se(o.bottom, s.right, !1) || r[2];
r[0] = h, r[1] = Se(o.top, Ln(o.bottom, d), !1) || r[1], r[3] = Se(o.bottom, Ln(o.top, h), !1) || r[3], r[2] = d;
}
} else if (e < 90) {
const l = Se(o.top, s.top);
if (l) {
const h = l, d = Se(o.bottom, s.bottom, !1) || r[2];
r[0] = h, r[1] = Se(o.top, Ln(o.bottom, d), !1) || r[1], r[3] = Se(o.bottom, Ln(o.top, h), !1) || r[3], r[2] = d, o = gs(r);
}
const c = Se(o.top, s.right);
if (c) {
const h = c, d = Se(o.bottom, s.left, !1) || r[3];
r[0] = Se(o.top, Ln(o.bottom, d), !1) || r[0], r[1] = h, r[3] = d, r[2] = Se(o.bottom, Ln(o.top, h), !1) || r[2];
}
}
r = sa(r, -e);
const i = Sl(r);
return { width: i.width, height: i.height };
}, findIntersectMath: (a, t, e, n) => {
let r = $u(a.x, a.y, t.x, t.y, 5e4, 0, -5e4, 0);
return r && (e = Math.min(e, r.x), n = Math.max(n, r.x)), { min: e, max: n };
}, leastSquaresSlopeAndIntercept: (a) => {
let t = 0, e = 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) || (t += s, e += i, r += s * s, n += s * i, o++);
const c = (o * n - t * e) / (o * r - t * t);
return { m: c, b: e / o - c * t / o };
}, minBoundingRect: Sl, rotatePoints: sa, unionBounds: _l }, Symbol.toStringTag, { value: "Module" }));
class xt {
constructor(t, e, n) {
this._root = ia, this._size = 0, this._maxNodeSize = n >= 4 ? Math.min(n, 256) : 32, this._compare = e || xt.defaultComparator, t && this.setPairs(t);
}
get size() {
return this._size;
}
get length() {
return this._size;
}
get isEmpty() {
return this._size === 0;
}
clear() {
this._root = ia, this._size = 0;
}
forEach(t, e) {
return e !== void 0 && (t = t.bind(e)), this.forEachPair((n, r) => t(r, n, this));
}
forEachPair(t, e) {
const n = this.minKey(), r = this.maxKey();
return this.forRange(n, r, !0, t, e);
}
get(t, e) {
return this._root.get(t, e, this);
}
set(t, e, n) {
this._root.isShared && (this._root = this._root.clone());
const r = this._root.set(t, e, n, this);
return r === !0 || r === !1 ? r : (this._root = new Uo([this._root, r]), !0);
}
has(t) {
return this.forRange(t, t, !0, void 0) !== 0;
}
delete(t) {
return this.editRange(t, t, !0, xt.DeleteRange) !== 0;
}
with(t, e, n) {
const r = this.clone();
return r.set(t, e, n) || n ? r : this;
}
withPairs(t, e) {
const n = this.clone();
return n.setPairs(t, e) !== 0 || e ? n : this;
}
withKeys(t, e) {
const n = this.clone();
let r = !1;
for (let o = 0; o < t.length; o++) r = n.set(t[o], void 0, !1) || r;
return e && !r ? this : n;
}
without(t, e) {
return this.withoutRange(t, t, !0, e);
}
withoutKeys(t, e) {
const n = this.clone();
return n.deleteKeys(t) || !e ? n : this;
}
withoutRange(t, e, n, r) {
const o = this.clone();
return o.deleteRange(t, e, n) === 0 && r ? this : o;
}
filter(t, e) {
const n = this.greedyClone();
let r;
return n.editAll((o, s, i) => {
if (!t(o, s, i)) return r = xt.DeleteValue;
}), !r && e ? this : n;
}
mapValues(t) {
const e = this.greedyClone();
return e.editAll((n, r, o) => t(r, n, o)), e;
}
reduce(t, e) {
let n, r = 0, o = e;
const s = this.entries(this.minKey());
for (; !(n = s.next()).done; ) o = t(o, n.value, r++, this);
return o;
}
entries(t, e) {
const n = this.findPath(t);
if (n === void 0) return xr();
let { nodeQueue: r, nodeIndex: o, leaf: s } = n, i = e !== void 0 ? 1 : 0, l = t === void 0 ? -1 : s.indexOf(t, 0, this._compare) - 1;
return xr(() => {
t: 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], d = s.values[l];
return e ? (e.done = !1, e.value[0] = h, e.value[1] = d, e) : { done: !1, value: [h, d] };
}
i = 2;
case 2:
for (var c = -1; ; ) {
if (++c >= r.length) {
i = 3;
continue t;
}
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 = e !== void 0 ? 1 : 0;
continue;
case 3:
return wl;
}
});
}
entriesReversed(t, e, n) {
if (t === void 0 && (n = void 0, (t = this.maxKey()) === void 0)) return xr();
let { nodeQueue: r, nodeIndex: o, leaf: s } = this.findPath(t) || this.findPath(this.maxKey());
Me(!r[0] || s === r[0][o[0]], "wat!");
let i = s.indexOf(t, 0, this._compare);
!n && i < s.keys.length && this._compare(s.keys[i], t) <= 0 && i++;
let l = e !== void 0 ? 1 : 0;
return xr(() => {
t: 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], d = s.values[i];
return e ? (e.done = !1, e.value[0] = h, e.value[1] = d, e) : { done: !1, value: [h, d] };
}
l = 2;
case 2:
for (var c = -1; ; ) {
if (++c >= r.length) {
l = 3;
continue t;
}
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 = e !== void 0 ? 1 : 0;
continue;
case 3:
return wl;
}
});
}
findPath(t) {
let e, n, r = this._root;
if (r.isLeaf) e = xc, n = xc;
else {
e = [], n = [];
for (let o = 0; !r.isLeaf; o++) {
if (e[o] = r.children, n[o] = t === void 0 ? 0 : r.indexOf(t, 0, this._compare), n[o] >= e[o].length) return;
r = e[o][n[o]];
}
e.reverse(), n.reverse();
}
return { nodeQueue: e, nodeIndex: n, leaf: r };
}
diffAgainst(t, e, n, r) {
if (t._compare !== this._compare) throw new Error("SortedMap: Comparators are not the same.");
if (this.isEmpty || t.isEmpty)
return this.isEmpty && t.isEmpty ? void 0 : this.isEmpty ? n === void 0 ? void 0 : xt.stepToEnd(xt.makeDiffCursor(t), n) : e === void 0 ? void 0 : xt.stepToEnd(xt.makeDiffCursor(this), e);
const { _compare: o } = this, s = xt.makeDiffCursor(this), i = xt.makeDiffCursor(t);
let l = !0, c = !0, h = xt.compare(s, i, o);
for (; l && c; ) {
const d = xt.compare(s, i, o), { leaf: u, internalSpine: g, levelIndices: m } = s, { leaf: f, internalSpine: p, levelIndices: _ } = i;
if (u || f) {
if (h !== 0) {
if (d === 0) {
if (u && f && r) {
const S = u.values[m[m.length - 1]], C = f.values[_[_.length - 1]];
if (!Object.is(S, C)) {
const y = r(s.currentKey, S, C);
if (y && y.break) return y.break;
}
}
} else if (d > 0) {
if (f && n) {
const S = f.values[_[_.length - 1]], C = n(i.currentKey, S);
if (C && C.break) return C.break;
}
} else if (e && u && h !== 0) {
const S = u.values[m[m.length - 1]], C = e(s.currentKey, S);
if (C && C.break) return C.break;
}
}
} else if (!u && !f && d === 0) {
const S = g.length - 1, C = p.length - 1, y = g[S][m[S]];
if (p[C][_[C]] === y) {
h = 0, l = xt.step(s, !0), c = xt.step(i, !0);
continue;
}
}
h = d, d < 0 ? l = xt.step(s) : c = xt.step(i);
}
return l && e ? xt.finishCursorWalk(s, i, o, e) : c && n ? xt.finishCursorWalk(i, s, o, n) : void 0;
}
static finishCursorWalk(t, e, n, r) {
const o = xt.compare(t, e, n);
if (o === 0) {
if (!xt.step(t)) return;
} else o < 0 && Me(!1, "cursor walk terminated early");
return xt.stepToEnd(t, r);
}
static stepToEnd(t, e) {
let n = !0;
for (; n; ) {
const { leaf: r, levelIndices: o, currentKey: s } = t;
if (r) {
const i = e(s, r.values[o[o.length - 1]]);
if (i && i.break) return i.break;
}
n = xt.step(t);
}
}
static makeDiffCursor(t) {
const { _root: e, height: n } = t;
return { height: n, internalSpine: [[e]], levelIndices: [0], leaf: void 0, currentKey: e.maxKey() };
}
static step(t, e) {
const { internalSpine: n, levelIndices: r, leaf: o } = t;
if (e === !0 || o) {
const s = r.length;
if (e === !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 && (t.leaf = void 0, r.pop()), c < l && (t.internalSpine = n.slice(0, c + 1)), t.currentKey = n[c][--r[c]].maxKey(), !0;
c--;
}
return !1;
}
{
const i = --r[s - 1];
return t.currentKey = o.keys[i], !0;
}
}
{
const s = n.length, i = s - 1, l = n[i][r[i]];
if (l.isLeaf) {
t.leaf = l;
const c = r[s] = l.values.length - 1;
t.currentKey = l.keys[c];
} else {
const c = l.children;
n[s] = c;
const h = c.length - 1;
r[s] = h, t.currentKey = c[h].maxKey();
}
return !0;
}
}
static compare(t, e, n) {
const { height: r, currentKey: o, levelIndices: s } = t, { height: i, currentKey: l, levelIndices: c } = e, h = n(l, o);
if (h !== 0) return h;
const d = r < i ? r : i;
return s.length - (r - d) - (c.length - (i - d));
}
keys(t, e) {
const n = this.entries(t, e);
return xr(() => {
const r = n.next();
return r.value && (r.value = r.value[0]), r;
});
}
values(t, e) {
const n = this.entries(t, e);
return xr(() => {
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 t = new xt(void 0, this._compare, this._maxNodeSize);
return t._root = this._root, t._size = this._size, t;
}
greedyClone(t) {
const e = new xt(void 0, this._compare, this._maxNodeSize);
return e._root = this._root.greedyClone(t), e._size = this._size, e;
}
toArray(t = 2147483647) {
const e = this.minKey(), n = this.maxKey();
return e !== void 0 ? this.getRange(e, n, !0, t) : [];
}
keysArray() {
const t = [];
return this._root.forRange(this.minKey(), this.maxKey(), !0, !1, this, 0, (e, n) => {
t.push(e);
}), t;
}
valuesArray() {
const t = [];
return this._root.forRange(this.minKey(), this.maxKey(), !0, !1, this, 0, (e, n) => {
t.push(n);
}), t;
}
toString() {
return this.toArray().toString();
}
setIfNotPresent(t, e) {
return this.set(t, e, !1);
}
nextHigherPair(t, e) {
return t === void 0 ? this._root.minPair(e) : this._root.getPairOrNextHigher(t, this._compare, !1, e);
}
nextHigherKey(t, e) {
const n = this.nextHigherPair(t, e);
return n && n[0];
}
nextLowerPair(t, e) {
return t === void 0 ? this._root.maxPair(e) : this._root.getPairOrNextLower(t, this._compare, !1, e);
}
nextLowerKey(t, e) {
const n = this.nextLowerPair(t, e);
return n && n[0];
}
getPairOrNextLower(t, e) {
return this._root.getPairOrNextLower(t, this._compare, !0, e);
}
getPairOrNextHigher(t, e) {
return this._root.getPairOrNextHigher(t, this._compare, !0, e);
}
changeIfPresent(t, e) {
return this.editRange(t, t, !0, (n, r) => ({ value: e })) !== 0;
}
getRange(t, e, n, r = 67108863) {
const o = [];
return this._root.forRange(t, e, n, !1, this, 0, (s, i) => (o.push([s, i]), o.length > r ? xt.Break : void 0)), o;
}
setPairs(t, e) {
let n = 0;
for (let r = 0; r < t.length; r++) this.set(t[r][0], t[r][1], e) && n++;
return n;
}
forRange(t, e, n, r, o) {
const s = this._root.forRange(t, e, n, !1, this, o || 0, r);
return typeof s == "number" ? s : s.break;
}
forEditRange(t, e, n, r, o, s) {
return this._root.forRange(t, e, n, r, this, s || 0, o);
}
editRange(t, e, n, r, o) {
let s = this._root;
s.isShared && (this._root = s = s.clone());
try {
const i = s.forRange(t, e, 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(t, e) {
return this.editRange(this.minKey(), this.maxKey(), !0, t, e);
}
deleteRange(t, e, n) {
return this.editRange(t, e, n, xt.DeleteRange);
}
deleteKeys(t) {
let e = 0;
for (let n = 0; n < t.length; n++) this.delete(t[n]) && e++;
return e;
}
get height() {
let t = this._root, e = -1;
for (; t; ) e++, t = t.isLeaf ? void 0 : t.children[0];
return e;
}
freeze() {
const t = this;
t.clear = t.set = t.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 t = this._root.checkValid(0, this, 0);
Me(t === this.size, "size mismatch: counted ", t, "but stored", this.size);
}
}
function xr(a = () => wl) {
const t = { next: a };
return Symbol && Symbol.iterator && (t[Symbol.iterator] = function() {
return this;
}), t;
}
Symbol && Symbol.iterator && (xt.prototype[Symbol.iterator] = xt.prototype.entries), xt.prototype.where = xt.prototype.filter, xt.prototype.setRange = xt.prototype.setPairs, xt.prototype.add = xt.prototype.set;
class Xo {
get isLeaf() {
return this.children === void 0;
}
constructor(t = [], e) {
this.keys = t, this.values = e || de, this.isShared = void 0;
}
maxKey() {
return this.keys[this.keys.length - 1];
}
indexOf(t, e, n) {
const r = this.keys;
let o = 0, s = r.length, i = s >> 1;
for (; o < s; ) {
const l = n(r[i], t);
if (l < 0) o = i + 1;
else {
if (!(l > 0)) {
if (l === 0) return i;
if (t == t) return r.length;
throw new Error("SortedMap: NaN was used as a key.");
}
s = i;
}
i = o + s >> 1;
}
return i ^ e;
}
minKey() {
return this.keys[0];
}
minPair(t) {
if (this.keys.length !== 0) return (t = t ?? [null, null])[0] = this.keys[0], t[1] = this.values[0], t;
}
maxPair(t) {
if (this.keys.length === 0) return;
const e = this.keys.length - 1;
return (t = t ?? [null, null])[0] = this.keys[e], t[1] = this.values[e], t;
}
clone() {
const t = this.values, e = t === de ? t : t.slice(0), n = this.keys.slice(0);
return new Xo(n, e);
}
greedyClone(t) {
return this.isShared && !t ? this : this.clone();
}
get(t, e, n) {
const r = this.indexOf(t, -1, n._compare);
return r < 0 ? e : this.values[r];
}
getPairOrNextLower(t, e, n, r) {
const o = this.indexOf(t, -1, e), 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(t, e, n, r) {
const o = this.indexOf(t, -1, e), 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(t, e, n) {
const r = this.keys.length, o = this.values.length;
return Me(this.values === de ? r <= o : r === o, "keys/values length mismatch: depth", t, "with lengths", r, o, "and baseIndex", n), Me(t === 0 || r > 0, "empty leaf at depth", t, "and baseIndex", n), r;
}
set(t, e, n, r) {
let o = this.indexOf(t, -1, r._compare);
if (o < 0) {
if (o = ~o, r._size++, this.keys.length < r._maxNodeSize) return this.insertInLeaf(o, t, e, n, r);
{
const s = this.splitOffRightSide();
let i = this;
return o > this.keys.length && (o -= this.keys.length, i = s), i.insertInLeaf(o, t, e, n, r), s;
}
}
if (n !== !1) {
e !== void 0 && this.reifyValues(), this.keys[o] = t;
let s = e;
if (typeof n == "function") {
const i = n(this.values[o], t, e);
i !== void 0 && (s = i);
}
this.values[o] = s;
}
return !1;
}
reifyValues() {
return this.values === de ? this.values = this.values.slice(0, this.keys.length) : this.values;
}
insertInLeaf(t, e, n, r, o) {
if (this.keys.splice(t, 0, e), this.values === de) {
for (; de.length < o._maxNodeSize; ) de.push(void 0);
if (n === void 0) return !0;
this.values = de.slice(0, this.keys.length - 1);
}
let s = n;
if (typeof r == "function") {
const i = r(void 0, e, n);
i !== void 0 && (s = i);
}
return this.values.splice(t, 0, s), !0;
}
takeFromRight(t) {
let e = this.values;
t.values === de ? e !== de && e.push(void 0) : (e = this.reifyValues(), e.push(t.values.shift())), this.keys.push(t.keys.shift());
}
takeFromLeft(t) {
let e = this.values;
t.values === de ? e !== de && e.unshift(void 0) : (e = this.reifyValues(), e.unshift(t.values.pop())), this.keys.unshift(t.keys.pop());
}
splitOffRightSide() {
const t = this.keys.length >> 1, e = this.keys.splice(t), n = this.values === de ? de : this.values.splice(t);
return new Xo(e, n);
}
forRange(t, e, n, r, o, s, i) {
const l = o._compare;
let c, h;
if (e === t) {
if (!n || (h = (c = this.indexOf(t, -1, l)) + 1, c < 0)) return s;
} else c = this.indexOf(t, 0, l), h = this.indexOf(e, -1, l), h < 0 ? h = ~h : n === !0 && h++;
const d = this.keys, u = this.values;
if (i !== void 0) for (let g = c; g < h; g++) {
const m = d[g], f = i(m, u[g], s++);
if (f !== void 0) {
if (f.break !== void 0) return f;
if (r === !0) {
if (m !== d[g] && o._compare(m, d[g]) !== 0 || this.isShared === !0) throw new Error("SortedMap: illegally changed or cloned in editRange.");
f.delete ? (this.keys.splice(g, 1), this.values !== de && this.values.splice(g, 1), o._size--, g--, h--) : f.hasOwnProperty("value") && (u[g] = f.value);
}
}
}
else s += h - c;
return s;
}
mergeSibling(t, e) {
if (this.keys.push.apply(this.keys, t.keys), this.values === de) {
if (t.values === de) return;
this.values = this.values.slice(0, this.keys.length);
}
this.values.push.apply(this.values, t.reifyValues());
}
}
class Uo extends Xo {
constructor(t, e) {
if (!e) {
e = [];
for (let n = 0; n < t.length; n++) e[n] = t[n].maxKey();
}
super(e), this.children = t;
}
clone() {
const t = this.children.slice(0);
for (let e = 0; e < t.length; e++) t[e].isShared = !0;
return new Uo(t, this.keys.slice(0));
}
greedyClone(t) {
if (this.isShared && !t) return this;
const e = new Uo(this.children.slice(0), this.keys.slice(0));
for (let n = 0; n < e.children.length; n++) e.children[n] = e.children[n].greedyClone(t);
return e;
}
minKey() {
return this.children[0].minKey();
}
minPair(t) {
return this.children[0].minPair(t);
}
maxPair(t) {
return this.children[this.children.length - 1].maxPair(t);
}
get(t, e, n) {
const r = this.indexOf(t, 0, n._compare), o = this.children;
return r < o.length ? o[r].get(t, e, n) : void 0;
}
getPairOrNextLower(t, e, n, r) {
const o = this.indexOf(t, 0, e), s = this.children;
if (o >= s.length) return this.maxPair(r);
const i = s[o].getPairOrNextLower(t, e, n, r);
return i === void 0 && o > 0 ? s[o - 1].maxPair(r) : i;
}
getPairOrNextHigher(t, e, n, r) {
const o = this.indexOf(t, 0, e), s = this.children, i = s.length;
if (o >= i) return;
const l = s[o].getPairOrNextHigher(t, e, n, r);
return l === void 0 && o < i - 1 ? s[o + 1].minPair(r) : l;
}
checkValid(t, e, n) {
const r = this.keys.length, o = this.children.length;
Me(r === o, "keys/children length mismatch: depth", t, "lengths", r, o, "baseIndex", n), Me(r > 1 || t > 0, "internal node has length", r, "at depth", t, "baseIndex", n);
let s = 0, i = this.children, l = this.keys, c = 0;
for (let d = 0; d < o; d++) s += i[d].checkValid(t + 1, e, n + s), c += i[d].keys.length, Me(s >= c, "wtf", n), Me(d === 0 || i[d - 1].constructor === i[d].constructor, "type mismatch, baseIndex:", n), i[d].maxKey() !== l[d] && Me(!1, "keys[", d, "] =", l[d], "is wrong, should be ", i[d].maxKey(), "at depth", t, "baseIndex", n), d === 0 || e._compare(l[d - 1], l[d]) < 0 || Me(!1, "sort violation at depth", t, "index", d, "keys", l[d - 1], l[d]);
const h = c === 0;
return (h || c > e.maxNodeSize * o) && Me(!1, h ? "too few" : "too many", "children (", c, s, ") at depth", t, "maxNodeSize:", e.maxNodeSize, "children.length:", o, "baseIndex:", n), s;
}
set(t, e, n, r) {
const o = this.children, s = r._maxNodeSize, i = r._compare;
let l = Math.min(this.indexOf(t, 0, i), o.length - 1), c = o[l];
if (c.isShared && (o[l] = c = c.clone()), c.keys.length >= s) {
let d;
l > 0 && (d = o[l - 1]).keys.length < s && i(c.keys[0], t) < 0 ? (d.isShared && (o[l - 1] = d = d.clone()), d.takeFromRight(c), this.keys[l - 1] = d.maxKey()) : (d = o[l + 1]) !== void 0 && d.keys.length < s && i(c.maxKey(), t) < 0 && (d.isShared && (o[l + 1] = d = d.clone()), d.takeFromLeft(c), this.keys[l] = o[l].maxKey());
}
const h = c.set(t, e, 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 d = this.splitOffRightSide();
let u = this;
return i(h.maxKey(), this.maxKey()) > 0 && (u = d, l -= this.keys.length), u.insert(l + 1, h), d;
}
}
insert(t, e) {
this.children.splice(t, 0, e), this.keys.splice(t, 0, e.maxKey());
}
splitOffRightSide() {
const t = this.children.length >> 1;
return new Uo(this.children.splice(t), this.keys.splice(t));
}
takeFromRight(t) {
this.keys.push(t.keys.shift()), this.children.push(t.children.shift());
}
takeFromLeft(t) {
this.keys.unshift(t.keys.pop()), this.children.unshift(t.children.pop());
}
forRange(t, e, n, r, o, s, i) {
const l = o._compare, c = this.keys, h = this.children;
let d = this.indexOf(t, 0, l), u = d, g = Math.min(e === t ? d : this.indexOf(e, 0, l), c.length - 1);
if (r) {
if (u <= g) try {
for (; u <= g; u++) {
h[u].isShared && (h[u] = h[u].clone());
const m = h[u].forRange(t, e, n, r, o, s, i);
if (c[u] = h[u].maxKey(), typeof m != "number") return m;
s = m;
}
} finally {
const m = o._maxNodeSize >> 1;
for (d > 0 && d--, u = g; u >= d; u--) h[u].keys.length <= m && (h[u].keys.length !== 0 ? this.tryMerge(u, o._maxNodeSize) : (c.splice(u, 1), h.splice(u, 1)));
h.length !== 0 && h[0].keys.length === 0 && Me(!1, "emptiness bug");
}
} else for (; u <= g; u++) {
const m = h[u].forRange(t, e, n, r, o, s, i);
if (typeof m != "number") return m;
s = m;
}
return s;
}
tryMerge(t, e) {
const n = this.children;
return t >= 0 && t + 1 < n.length && n[t].keys.length + n[t + 1].keys.length <= e && (n[t].isShared && (n[t] = n[t].clone()), n[t].mergeSibling(n[t + 1], e), n.splice(t + 1, 1), this.keys.splice(t + 1, 1), this.keys[t] = n[t].maxKey(), !0);
}
mergeSibling(t, e) {
const n = this.keys.length;
this.keys.push.apply(this.keys, t.keys);
const r = t.children;
if (this.children.push.apply(this.children, r), t.isShared && !this.isShared) for (let o = 0; o < r.length; o++) r[o].isShared = !0;
this.tryMerge(n - 1, e);
}
}
const de = [], wl = Object.freeze({ done: !0, value: void 0 }), ia = (function() {
const a = new Xo();
return a.isShared = !0, a;
})(), xc = [], Me = (a, ...t) => {
if (!a) throw t.unshift("SortedMap:"), new Error(t.join(" "));
};
var Bn;
(Bn = xt || (xt = {})).DeleteValue = Object.freeze({ delete: !0 }), Bn.Break = Object.freeze({ break: !0 }), Bn.DeleteRange = () => Bn.DeleteValue, Bn.EmptySortedMap = (() => {
const a = new Bn();
return a.freeze(), a;
})(), Bn.defaultComparator = function(a, t) {
if (Number.isFinite(a) && Number.isFinite(t)) return a - t;
let e = typeof a, n = typeof t;
if (e !== n) return e < n ? -1 : 1;
if (e === "object") {
if (a === null) return t === null ? 0 : -1;
if (t === null) return 1;
if (e = typeof (a = a.valueOf()), n = typeof (t = t.valueOf()), e !== n) return e < n ? -1 : 1;
}
return a < t ? -1 : a > t ? 1 : a === t ? 0 : Number.isNaN(a) ? Number.isNaN(t) ? 0 : -1 : Number.isNaN(t) ? 1 : Array.isArray(a) ? 0 : Number.NaN;
}, Bn.simpleComparator = function(a, t) {
return a > t ? 1 : a < t ? -1 : 0;
};
const Ic = [-1, null], rf = { done: !1, value: [-1, null] };
var zt;
((a) => {
a.Builder = class {
constructor(e, 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 = e, this._offsetMajor = n, this._offsetMinor = r;
}
addValues(e, n, r) {
if (r && r.isIList) return this.addValue(e, n, r);
Array.isArray(r) || (r = [r]), this.addValue(e, 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(e, n, r) {
const o = this._majorIndex, s = this._minorIndex;
if (e += this._offsetMajor, n += this._offsetMinor, e < o || e === o && n <= s) throw new t(`major: ${e}, minor: ${n}, prevMajor: ${this._majorIndex}, prevMinor: ${this._minorIndex}`);
let i = this._minors;
if (e !== 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([e, i]), this._majorIndex = e;
}
if (r && r.isIList) {
n === s + 1 && o !== e && this._values;
const l = r;
i.push([n, l]), n = n + l.length - 1;
} else {
let l = null;
n !== s + 1 || o !== e ? (this._values = l = [], i.push([n, l])) : l = this._values, l.push(r);
}
return this._minorIndex = n, this;
}
build() {
const e = this._tuples;
if (e.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: e, bounds: { majorStart: e[0][0], minorStart: this._minorMin, majorEnd: e[e.length - 1][0], minorEnd: this._minorMax } };
}
}, a.TransposedBuilder = class {
constructor(e, 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 = e, this._offsetMajor = n, this._offsetMinor = r, this._minors = new xt();
}
addValues(e, n, r) {
Array.isArray(r) || (r = [r]);
const o = r.length;
for (let s = 0; s < o; s++) {
const i = n + s;
this.addValue(e, i, r[s]);
}
return this;
}
addValue(e, n, r) {
let o, s;
const i = this._majorIndex;
let l = this._minorIndex;
if (e += this._offsetMajor, n += this._offsetMinor, s = this._current, e !== i) {
if (this._majorIndex = e, e < i) throw new t(`major: ${e}, minor: ${n}, prevMajor: ${this._majorIndex}, prevMinor: ${this._minorIndex}`);
l = Number.MIN_SAFE_INTEGER;
} else if (s = this._current, n <= l) throw new t(`major: ${e}, 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 p = m.minor;
m && m.minor === n ? (s = m, o = s.span) : f = p > n ? g.getPairOrNextHigher(n, Ic) : g.getPairOrNextLower(n, Ic), f && (s = f[1], f[0] === n && (o = s.span));
}
if (!o) {
this._majorMin = Math.min(this._majorMin, e), o = [n, [[e, []]]];
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 p = this._first;
(!p || n < p.minor) && (this._first = f), f.next && (this._current = f.next);
}
}
let c = o[1];
const h = c[c.length - 1];
let d = h[0], u = h[1];
return d + u.length !== e && (u = [], d = e, c.push([d, u])), u.push(r), this._majorMax = Math.max(this._majorMax, e), this._minorIndex = n, this;
}
build() {
const e = [], n = this._createList, r = this._minors.entries(void 0, rf);
let o = r.next();
for (; !o.done; ) {
const s = o.value[1].span;
if (n) {
const i = s.length;
for (let l = 0; l < i; l++) s[l][1] = this._createList(s[l][1]);
}
e.push(s), o = r.next();
}
return e.length === 0 ? null : { tuples: e, bounds: { majorStart: e[0][0], minorStart: this._majorMin, majorEnd: e[e.length - 1][0], minorEnd: this._majorMax } };
}
};
class t extends Gm {
constructor(n = "Out of order", r = null) {
super(n, r), this.name = "OutOfOrderError";
}
}
a.OutOfOrderError = t;
})(zt || (zt = {}));
const of = { 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 (t = {}) => {
const e = t.width ? String(t.width) : a.defaultWidth;
return a.formats[e] || a.formats[a.defaultWidth];
};
}
const sf = { 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" }) }, af = { lastWeek: "'last' eeee 'at' p", yesterday: "'yesterday at' p", today: "'today at' p", tomorrow: "'tomorrow at' p", nextWeek: "eeee 'at' p", other: "P" };
function ho(a) {
return (t, e) => {
let n;
if ((e?.context ? String(e.context) : "standalone") === "formatting" && a.formattingValues) {
const r = a.defaultFormattingWidth || a.defaultWidth, o = e?.width ? String(e.width) : r;
n = a.formattingValues[o] || a.formattingValues[r];
} else {
const r = a.defaultWidth, o = e?.width ? String(e.width) : a.defaultWidth;
n = a.values[o] || a.values[r];
}
return n[a.argumentCallback ? a.argumentCallback(t) : t];
};
}
function uo(a) {
return (t, e = {}) => {
const n = e.width, r = n && a.matchPatterns[n] || a.matchPatterns[a.defaultMatchWidth], o = t.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, d) {
for (let u = 0; u < h.length; u++) if (d(h[u])) return u;
})(i, (h) => h.test(s)) : (function(h, d) {
for (const u in h) if (Object.prototype.hasOwnProperty.call(h, u) && d(h[u])) return u;
})(i, (h) => h.test(s));
let c;
return c = a.valueCallback ? a.valueCallback(l) : l, c = e.valueCallback ? e.valueCallback(c) : c, { value: c, rest: t.slice(s.length) };
};
}
var go;
const lf = { code: "en-US", formatDistance: (a, t, e) => {
let n;
const r = of[a];
return n = typeof r == "string" ? r : t === 1 ? r.one : r.other.replace("{{count}}", t.toString()), e?.addSuffix ? e.comparison && e.comparison > 0 ? "in " + n : n + " ago" : n;
}, formatLong: sf, formatRelative: (a, t, e, n) => af[a], localize: { ordinalNumber: (a, t) => {
const e = Number(a), n = e % 100;
if (n > 20 || n < 10) switch (n % 10) {
case 1:
return e + "st";
case 2:
return e + "nd";
case 3:
return e + "rd";
}
return e + "th";
}, era: ho({ values: { narrow: ["B", "A"], abbreviated: ["BC", "AD"], wide: ["Before Christ", "Anno Domini"] }, defaultWidth: "wide" }), quarter: ho({ 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: ho({ 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: ho({ 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: ho({ 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: (go = { matchPattern: /^(\d+)(th|st|nd|rd)?/i, parsePattern: /\d+/i, valueCallback: (a) => parseInt(a, 10) }, (a, t = {}) => {
const e = a.match(go.matchPattern);
if (!e) return null;
const n = e[0], r = a.match(go.parsePattern);
if (!r) return null;
let o = go.valueCallback ? go.valueCallback(r[0]) : r[0];
return o = t.valueCallback ? t.valueCallback(o) : o, { value: o, rest: a.slice(n.length) };
}), era: uo({ 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: uo({ 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: uo({ 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: uo({ 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: uo({ 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 } }, Rc = (a, t) => {
switch (a) {
case "P":
return t.date({ width: "short" });
case "PP":
return t.date({ width: "medium" });
case "PPP":
return t.date({ width: "long" });
default:
return t.date({ width: "full" });
}
}, Ac = (a, t) => {
switch (a) {
case "p":
return t.time({ width: "short" });
case "pp":
return t.time({ width: "medium" });
case "ppp":
return t.time({ width: "long" });
default:
return t.time({ width: "full" });
}
}, Mc = { p: Ac, P: (a, t) => {
const e = a.match(/(P+)(p+)?/) || [], n = e[1], r = e[2];
if (!r) return Rc(a, t);
let o;
switch (n) {
case "P":
o = t.dateTime({ width: "short" });
break;
case "PP":
o = t.dateTime({ width: "medium" });
break;
case "PPP":
o = t.dateTime({ width: "long" });
break;
default:
o = t.dateTime({ width: "full" });
}
return o.replace("{{date}}", Rc(n, t)).replace("{{time}}", Ac(r, t));
} }, cf = /^D+$/, hf = /^Y+$/, df = ["D", "DD", "YY", "YYYY"];
function uf(a) {
return cf.test(a);
}
function gf(a) {
return hf.test(a);
}
function Tc(a, t, e) {
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, t, e);
if (console.warn(n), df.includes(a)) throw new RangeError(n);
}
const Nc = Symbol.for("constructDateFrom");
function jr(a, t) {
return typeof a == "function" ? a(t) : a && typeof a == "object" && Nc in a ? a[Nc](t) : a instanceof Date ? new a.constructor(t) : new Date(t);
}
let mf = {};
function Gu() {
return mf;
}
function wi(a, t) {
return jr(t || a, a);
}
class Uu {
constructor() {
this.subPriority = 0;
}
validate(t, e) {
return !0;
}
}
class ff extends Uu {
constructor(t, e, n, r, o) {
super(), this.value = t, this.validateValue = e, this.setValue = n, this.priority = r, o && (this.subPriority = o);
}
validate(t, e) {
return this.validateValue(t, this.value, e);
}
set(t, e, n) {
return this.setValue(t, e, this.value, n);
}
}
class pf extends Uu {
constructor(t, e) {
super(), this.priority = 10, this.subPriority = -1, this.context = t || ((n) => jr(e, n));
}
set(t, e) {
return e.timestampIsSet ? t : jr(t, (function(n, r) {
const o = (function(s) {
return typeof s == "function" && s.prototype?.constructor === s;
})(r) ? new r(0) : jr(r, 0);
return o.setFullYear(n.getFullYear(), n.getMonth(), n.getDate()), o.setHours(n.getHours(), n.getMinutes(), n.getSeconds(), n.getMilliseconds()), o;
})(t, this.context));
}
}
let $s = class {
run(a, t, e, n) {
const r = this.parse(a, t, e, n);
return r ? { setter: new ff(r.value, this.validate, this.set, this.priority, this.subPriority), rest: r.rest } : null;
}
validate(a, t, e) {
return !0;
}
};
const qu = /^(1[0-2]|0?\d)/, _f = /^(3[0-1]|[0-2]?\d)/, Sf = /^\d/, wf = /^\d{1,2}/, yf = /^\d{1,3}/, Cf = /^\d{1,4}/;
function Tn(a, t) {
return a && { value: t(a.value), rest: a.rest };
}
function qn(a, t) {
const e = t.match(a);
return e ? { value: parseInt(e[0], 10), rest: t.slice(e[0].length) } : null;
}
function qo(a, t) {
switch (a) {
case 1:
return qn(Sf, t);
case 2:
return qn(wf, t);
case 3:
return qn(yf, t);
case 4:
return qn(Cf, t);
default:
return qn(new RegExp("^\\d{1," + a + "}"), t);
}
}
class Ju extends $s {
constructor() {
super(...arguments), this.incompatibleTokens = ["Y", "R", "q", "Q", "L", "w", "I", "D", "i", "e", "c", "t", "T"], this.priority = 110;
}
parse(t, e, n) {
const r = (o) => o - 1;
switch (e) {
case "M":
return Tn(qn(qu, t), r);
case "MM":
return Tn(qo(2, t), r);
case "Mo":
return Tn(n.ordinalNumber(t, { unit: "month" }), r);
case "MMM":
return n.month(t, { width: "abbreviated", context: "formatting" }) || n.month(t, { width: "narrow", context: "formatting" });
case "MMMMM":
return n.month(t, { width: "narrow", context: "formatting" });
default:
return n.month(t, { width: "wide", context: "formatting" }) || n.month(t, { width: "abbreviated", context: "formatting" }) || n.month(t, { width: "narrow", context: "formatting" });
}
}
validate(t, e) {
return e >= 0 && e <= 11;
}
set(t, e, n) {
return t.setMonth(n, 1), t.setHours(0, 0, 0, 0), t;
}
}
const Ef = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], bf = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
function vf(a, t, e) {
const n = Gu(), r = e?.weekStartsOn ?? e?.locale?.options?.weekStartsOn ?? n.weekStartsOn ?? n.locale?.options?.weekStartsOn ?? 0, o = wi(a, e?.in), s = o.getDay(), i = 7 - r;
return (function(l, c, h) {
const d = wi(l, h?.in);
return isNaN(c) ? jr(h?.in || l, NaN) : (c && d.setDate(d.getDate() + c), d);
})(o, t < 0 || t > 6 ? t - (s + i) % 7 : ((t % 7 + 7) % 7 + i) % 7 - (s + i) % 7, e);
}
const ko = { y: new class extends $s {
constructor() {
super(...arguments), this.priority = 130, this.incompatibleTokens = ["Y", "R", "u", "w", "I", "i", "e", "c", "t", "T"];
}
parse(a, t, e) {
const n = (r) => ({ year: r, isTwoDigitYear: t === "yy" });
switch (t) {
case "y":
return Tn(qo(4, a), n);
case "yo":
return Tn(e.ordinalNumber(a, { unit: "year" }), n);
default:
return Tn(qo(t.length, a), n);
}
}
validate(a, t) {
return t.isTwoDigitYear || t.year > 0;
}
set(a, t, e) {
const n = a.getFullYear();
if (e.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 d = c + 50;
h = s + 100 * Math.trunc(d / 100) - (s >= d % 100 ? 100 : 0);
}
return l ? h : 1 - h;
})(e.year, n);
return a.setFullYear(o, 0, 1), a.setHours(0, 0, 0, 0), a;
}
const r = "era" in t && t.era !== 1 ? 1 - e.year : e.year;
return a.setFullYear(r, 0, 1), a.setHours(0, 0, 0, 0), a;
}
}(), M: new Ju(), d: new class extends $s {
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, t, e) {
switch (t) {
case "d":
return qn(_f, a);
case "do":
return e.ordinalNumber(a, { unit: "date" });
default:
return qo(t.length, a);
}
}
validate(a, t) {
const e = (function(r) {
return r % 400 == 0 || r % 4 == 0 && r % 100 != 0;
})(a.getFullYear()), n = a.getMonth();
return e ? t >= 1 && t <= bf[n] : t >= 1 && t <= Ef[n];
}
set(a, t, e) {
return a.setDate(e), a.setHours(0, 0, 0, 0), a;
}
}(), E: new class extends $s {
constructor() {
super(...arguments), this.priority = 90, this.incompatibleTokens = ["D", "i", "e", "c", "t", "T"];
}
parse(a, t, e) {
switch (t) {
case "E":
case "EE":
case "EEE":
return e.day(a, { width: "abbreviated", context: "formatting" }) || e.day(a, { width: "short", context: "formatting" }) || e.day(a, { width: "narrow", context: "formatting" });
case "EEEEE":
return e.day(a, { width: "narrow", context: "formatting" });
case "EEEEEE":
return e.day(a, { width: "short", context: "formatting" }) || e.day(a, { width: "narrow", context: "formatting" });
default:
return e.day(a, { width: "wide", context: "formatting" }) || e.day(a, { width: "abbreviated", context: "formatting" }) || e.day(a, { width: "short", context: "formatting" }) || e.day(a, { width: "narrow", context: "formatting" });
}
}
validate(a, t) {
return t >= 0 && t <= 6;
}
set(a, t, e, n) {
return (a = vf(a, e, n)).setHours(0, 0, 0, 0), a;
}
}() }, xf = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g, If = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g, Rf = /^'([^]*?)'?$/, Af = /''/g, Mf = /\S/, Tf = /[a-zA-Z]/;
function Nf(a, t, e, n) {
const r = () => jr(n?.in || e, NaN), o = Object.assign({}, Gu()), s = n?.locale ?? o.locale ?? lf, 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 (!t) return a ? r() : wi(e, n?.in);
const c = { firstWeekContainsDate: i, weekStartsOn: l, locale: s }, h = [new pf(n?.in, e)], d = t.match(If).map((p) => {
const _ = p[0];
return _ in Mc ? (0, Mc[_])(p, s.formatLong) : p;
}).join("").match(xf), u = [];
for (let p of d) {
!n?.useAdditionalWeekYearTokens && gf(p) && Tc(p, t, a), !n?.useAdditionalDayOfYearTokens && uf(p) && Tc(p, t, a);
const _ = p[0], S = ko[_];
if (S) {
const { incompatibleTokens: C } = S;
if (Array.isArray(C)) {
const E = u.find((w) => C.includes(w.token) || w.token === _);
if (E) throw new RangeError(`The format string mustn't contain \`${E.fullToken}\` and \`${p}\` at the same time`);
} else if (S.incompatibleTokens === "*" && u.length > 0) throw new RangeError(`The format string mustn't contain \`${p}\` and any other token at the same time`);
u.push({ token: _, fullToken: p });
const y = S.run(a, p, s.match, c);
if (!y) return r();
h.push(y.setter), a = y.rest;
} else {
if (_.match(Tf)) throw new RangeError("Format string contains an unescaped latin alphabet character `" + _ + "`");
if (p === "''" ? p = "'" : _ === "'" && (p = Ff(p)), a.indexOf(p) !== 0) return r();
a = a.slice(p.length);
}
}
if (a.length > 0 && Mf.test(a)) return r();
const g = h.map((p) => p.priority).sort((p, _) => _ - p).filter((p, _, S) => S.indexOf(p) === _).map((p) => h.filter((_) => _.priority === p).sort((_, S) => S.subPriority - _.subPriority)).map((p) => p[0]);
let m = wi(e, n?.in);
if (isNaN(+m)) return r();
const f = {};
for (const p of g) {
if (!p.validate(m, c)) return r();
const _ = p.set(m, f, c);
Array.isArray(_) ? (m = _[0], Object.assign(f, _[1])) : m = _;
}
return m;
}
function Ff(a) {
return a.match(Rf)[1].replace(Af, "'");
}
const Ku = (a) => !isNaN(a) && (Object.prototype.toString.call(a) === "[object Date]" || a instanceof Date);
function Fc(a, t, e) {
let n = a, r = a.length, o = t.length;
for (var s = r; s < o; ++s) {
const i = t[s];
if (i === "#") return n;
n = e ? n + i : i + n;
}
return n;
}
function Fe(a, t) {
for (var e = ""; e.length < t; ) e += a;
return e;
}
function $r(a) {
for (var t = "", e = a.length - 1; e >= 0; ) t += a.charAt(e--);
return t;
}
function He(a, t) {
var e = "" + a;
return e.length >= t ? e : Fe("0", t - e.length) + e;
}
function yl(a, t) {
var e = "" + a;
return e.length >= t ? e : Fe(" ", t - e.length) + e;
}
function yi(a, t) {
var e = "" + a;
return e.length >= t ? e : e + Fe(" ", t - e.length);
}
var kc = Math.pow(2, 32);
function Ir(a, t) {
return a > kc || a < -kc ? (function(e, n) {
var r = "" + Math.round(e);
return r.length >= n ? r : Fe("0", n - r.length) + r;
})(a, t) : (function(e, n) {
var r = "" + e;
return r.length >= n ? r : Fe("0", n - r.length) + r;
})(Math.round(a), t);
}
function Gs(a, t) {
return t = t || 0, a.length >= 7 + t && (32 | a.charCodeAt(t)) == 103 && (32 | a.charCodeAt(t + 1)) == 101 && (32 | a.charCodeAt(t + 2)) == 110 && (32 | a.charCodeAt(t + 3)) == 101 && (32 | a.charCodeAt(t + 4)) == 114 && (32 | a.charCodeAt(t + 5)) == 97 && (32 | a.charCodeAt(t + 6)) == 108;
}
var Oc = [["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"]], fr = { 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"秒 "' }, Dc = { 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 }, kf = { 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 Ci(a, t, e) {
for (var n = a < 0 ? -1 : 1, r = a * n, o = 0, s = 1, i = 0, l = 1, c = 0, h = 0, d = Math.floor(r); c < t && (i = (d = Math.floor(r)) * s + o, h = d * c + l, !(r - d < 5e-8)); ) r = 1 / (r - d), o = s, s = i, l = c, c = h;
if (h > t && (c > t ? (h = l, i = o) : (h = c, i = s)), !e) return [0, n * i, h];
var u = Math.floor(n * i / h);
return [u, n * i - u * h, h];
}
function Oo(a, t, e) {
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), t && t.date1904 && (n += 1462), i.u > 0.9999 && (i.u = 0, ++r === 86400 && (i.T = r = 0, ++n, ++i.D)), n === 60) s = e ? [1317, 10, 29] : [1900, 2, 29], o = 3;
else if (n === 0) s = e ? [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), e && (o = (function(c, h) {
h[0] -= 581;
var d = c.getDay();
return c < 60 && (d = (d + 6) % 7), d;
})(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 Xu = new Date(1899, 11, 31, 0, 0, 0), Of = Xu.getTime(), Df = new Date(1900, 2, 1, 0, 0, 0);
function Xl(a, t = !1) {
var e = a.getTime();
return t ? e -= 1262304e5 : a >= Df && (e += 864e5), (e - (Of + 6e4 * (a.getTimezoneOffset() - Xu.getTimezoneOffset()))) / 864e5;
}
function ca(a) {
return a.indexOf(".") === -1 ? a : a.replace(/(?:\.0*|(\.\d*[1-9])0+)$/, "$1");
}
function Lf(a) {
var t, e = Math.floor(Math.log(Math.abs(a)) * Math.LOG10E);
return t = e >= -4 && e <= -1 ? a.toPrecision(10 + e) : Math.abs(e) <= 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) : e === 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");
})(t.toUpperCase()));
}
function ha(a, t) {
switch (typeof a) {
case "string":
return a;
case "boolean":
return a ? "TRUE" : "FALSE";
case "number":
return (0 | a) === a ? a.toString(10) : Lf(a);
case "undefined":
return "";
case "object":
if (a == null) return "";
if (Ku(a)) return ag(14, Xl(a, t && t.date1904), t);
}
throw new Error("unsupported value in General format: " + a);
}
function Bf(a, t, e, n) {
var r, o = "", s = 0, i = 0, l = e.y, c = 0;
switch (a) {
case 98:
l = e.y + 543;
case 121:
switch (t.length) {
case 1:
case 2:
r = l % 100, c = 2;
break;
default:
r = l % 1e4, c = 4;
}
break;
case 109:
switch (t.length) {
case 1:
case 2:
r = e.m, c = t.length;
break;
case 3:
return la[e.m - 1][1];
case 5:
return la[e.m - 1][0];
default:
return la[e.m - 1][2];
}
break;
case 100:
switch (t.length) {
case 1:
case 2:
r = e.d, c = t.length;
break;
case 3:
return Oc[e.q][0];
default:
return Oc[e.q][1];
}
break;
case 104:
switch (t.length) {
case 1:
case 2:
r = 1 + (e.H + 11) % 12, c = t.length;
break;
default:
throw new Error("bad hour format: " + t);
}
break;
case 72:
switch (t.length) {
case 1:
case 2:
r = e.H, c = t.length;
break;
default:
throw new Error("bad hour format: " + t);
}
break;
case 77:
switch (t.length) {
case 1:
case 2:
r = e.M, c = t.length;
break;
default:
throw new Error("bad minute format: " + t);
}
break;
case 115:
if (t !== "s" && t !== "ss" && t !== ".0" && t !== ".00" && t !== ".000") throw new Error("bad second format: " + t);
return e.u !== 0 || t !== "s" && t !== "ss" ? (i = n >= 2 ? n === 3 ? 1e3 : 100 : n === 1 ? 10 : 1, (s = Math.round(i * (e.S + e.u))) >= 60 * i && (s = 0), t === "s" ? s === 0 ? "0" : "" + s / i : (o = He(s, 2 + n), t === "ss" ? o.substr(0, 2) : "." + o.substr(2, t.length - 1))) : He(e.S, t.length);
case 90:
switch (t) {
case "[h]":
case "[hh]":
r = 24 * e.D + e.H;
break;
case "[m]":
case "[mm]":
r = 60 * (24 * e.D + e.H) + e.M;
break;
case "[s]":
case "[ss]":
r = 60 * (60 * (24 * e.D + e.H) + e.M) + Math.round(e.S + e.u);
break;
default:
throw new Error("bad absolute time format: " + t);
}
c = t.length === 3 ? 1 : 2;
break;
case 101:
r = l, c = 1;
}
return c > 0 ? He(r, c) : "";
}
function Xn(a) {
if (a.length <= 3) return a;
for (var t = a.length % 3, e = a.substr(0, t); t !== a.length; t += 3) e += (e.length > 0 ? "," : "") + a.substr(t, 3);
return e;
}
var Yu = /%/g;
function Qu(a, t) {
var e, n = a.indexOf("E") - a.indexOf(".") - 1;
if (a.match(/^#+0.0E\+0$/)) {
if (t === 0) return "0.0E+0";
if (t < 0) return "-" + Qu(a, -t);
var r = a.indexOf(".");
r === -1 && (r = a.indexOf("E"));
var o = Math.floor(Math.log(t) * Math.LOG10E) % r;
if (o < 0 && (o += r), (e = (t / Math.pow(10, o)).toPrecision(n + 1 + (r + o) % r)).indexOf("e") === -1) {
var s = Math.floor(Math.log(t) * Math.LOG10E);
for (e.indexOf(".") === -1 ? e = e.charAt(0) + "." + e.substr(1) + "E+" + (s - e.length + o) : e += "E+" + (s - o); e.substr(0, 2) === "0."; ) e = (e = e.charAt(0) + e.substr(2, r) + "." + e.substr(2 + r)).replace(/^0+([1-9])/, "$1").replace(/^0+\./, "0.");
e = e.replace(/\+-/, "-");
}
e = e.replace(/^([+-]?)(\d*)\.(\d*)[Ee]/, function(i, l, c, h) {
return l + c + h.substr(0, (r + o) % r) + "." + h.substr(o) + "E";
});
} else e = t.toExponential(n);
return a.match(/E\+00$/) && e.match(/e[+-]\d$/) && (e = e.substr(0, e.length - 1) + "0" + e.charAt(e.length - 1)), a.match(/E-/) && e.match(/e\+/) && (e = e.replace(/e\+/, "e")), e.replace("e", "E");
}
var Zu = /[0#?] (\?+)( ?)\/( ?)(\d+)/, tg = /^([0#?]+)\.([0#?]+)/, eg = /\).*[0#]/, ng = /\(###\) ###\\?-####/;
function ze(a) {
var t = "";
let e, n = a.length;
for (var r = 0; r !== n; ++r) switch (e = a.charAt(r), e) {
case "#":
break;
case " ":
t += " ";
break;
case "0":
t += "0";
break;
case "?":
t += "?";
break;
default:
t += String.fromCharCode(cc);
}
return t;
}
function Lc(a, t) {
var e = Math.pow(10, t);
return "" + Math.round(a * e) / e;
}
function Bc(a, t) {
var e = Math.pow(10, t);
return Math.round(a * e) / e;
}
function zc(a, t) {
var e = a - Math.floor(a), n = Math.pow(10, t);
return t < ("" + Math.round(e * n)).length ? 0 : Math.round(e * n);
}
function Re(a, t, e) {
if (a.charCodeAt(0) === 40 && !t.match(eg)) {
var n = t.replace(/\( */, "").replace(/ \)/, "").replace(/\)/, "");
return e >= 0 ? Re("n", n, e) : "(" + Re("n", n, -e) + ")";
}
if (t.charCodeAt(t.length - 1) === 44) return (function(f, p, _) {
let S = p.length - 1;
for (; p.charCodeAt(S - 1) === 44; ) --S;
return Nn(f, p.substr(0, S), _ / Math.pow(10, 3 * (p.length - S)));
})(a, t, e);
if (t.indexOf("%") !== -1) return (function(f, p, _) {
let S = p.replace(Yu, ""), C = p.length - S.length;
return Nn(f, S, _ * Math.pow(10, 2 * C)) + Fe("%", C);
})(a, t, e);
if (t.indexOf("E") !== -1) return Qu(t, e);
if (t.charCodeAt(0) === 36) return "$" + Re(a, t.substr(t.charAt(1) === " " ? 2 : 1), e);
var r, o, s, i, l = Math.abs(e), c = e < 0 ? "-" : "";
if (t.match(/^00+$/)) return c + Ir(l, t.length);
if (t.match(/^[#?]+$/)) return (r = Ir(e, 0)) === "0" && (r = ""), r.length > t.length ? r : ze(t.substr(0, t.length - r.length)) + r;
if (o = t.match(Zu)) return (function(f, p, _) {
var S = parseInt(f[4], 10), C = Math.round(p * S), y = Math.floor(C / S), E = C - y * S, w = S;
return _ + (y === 0 ? "" : "" + y) + " " + (E === 0 ? Fe(" ", f[1].length + 1 + f[4].length) : yl(E, f[1].length) + f[2] + "/" + f[3] + He(w, f[4].length));
})(o, l, c);
if (t.match(/^#+0+$/)) return c + Ir(l, t.length - t.indexOf("0"));
if (o = t.match(tg)) {
s = Math.trunc(Lc(e, o[2].length));
var h = (function(f) {
if (!isFinite(f)) return 0;
for (var p = 1, _ = 0; Math.round(f * p) / p !== f; ) p *= 10, _++;
return _;
})(i = Bc(Math.abs(s - e), o[2].length));
return i = (i = "" + Bc(i, h)).replace(/^0\./, ""), r = Fc("" + Math.abs(s), o[1]) + "." + Fc("" + i, o[2], !0), r = t.indexOf("0.") !== -1 ? r : r.replace(/^0\./, "."), e < 0 ? "-" + r : r;
}
if (o = (t = t.replace(/^#+([0.])/, "$1")).match(/^(0*)\.(#*)$/)) return c + Lc(l, o[2].length).replace(/\.(\d*[1-9])0*$/, ".$1").replace(/^(-?\d*)$/, "$1.").replace(/^0\./, o[1].length ? "0." : ".");
if (o = t.match(/^#{1,3},##0(\.?)$/)) return c + Xn(Ir(l, 0));
if (o = t.match(/^#,##0\.([#0]*0)$/)) return e < 0 ? "-" + Re(a, t, -e) : Xn("" + (Math.floor(e) + (function(f, p) {
return p < ("" + Math.round((f - Math.floor(f)) * Math.pow(10, p))).length ? 1 : 0;
})(e, o[1].length))) + "." + He(zc(e, o[1].length), o[1].length);
if (o = t.match(/^#,#*,#0/)) return Re(a, t.replace(/^#,#*,/, ""), e);
if (o = t.match(/^([0#]+)(\\?-([0#]+))+$/)) return r = $r(Re(a, t.replace(/[\\-]/g, ""), e)), s = 0, $r($r(t.replace(/\\/g, "")).replace(/[0#]/g, function(f) {
return s < r.length ? r.charAt(s++) : f === "0" ? "0" : "";
}));
if (t.match(ng)) return "(" + (r = Re(a, "##########", e)).substr(0, 3) + ") " + r.substr(3, 3) + "-" + r.substr(6);
var d = "";
if (o = t.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/)) return s = Math.min(o[4].length, 7), i = Ci(l, Math.pow(10, s) - 1, !1), r = "" + c, (d = Nn("n", o[1], i[1])).charAt(d.length - 1) === " " && (d = d.substr(0, d.length - 1) + "0"), r += d + o[2] + "/" + o[3], (d = yi(i[2], s)).length < o[4].length && (d = ze(o[4].substr(o[4].length - d.length)) + d), r += d;
if (o = t.match(/[#0?] ([#0?]+)( ?)\/( ?)([#0?]+)/)) return s = Math.min(Math.max(o[1].length, o[4].length), 7), i = Ci(l, Math.pow(10, s) - 1, !0), c + Re(a, t.substring(0, o.index + 1), i[0]) + " " + (i[1] ? yl(i[1], s) + o[2] + "/" + o[3] + yi(i[2], s) : Fe(" ", 2 * s + 1 + o[2].length + o[3].length));
if (o = t.match(/^[#0?]+$/)) return r = Ir(e, 0), t.length <= r.length ? r : ze(t.substr(0, t.length - r.length)) + r;
if (o = t.match(/^([#0?]+)\.([#0]+)$/)) {
r = "" + e.toFixed(Math.min(o[2].length, 10)).replace(/([^0])0+$/, "$1"), s = r.indexOf(".");
var u = t.indexOf(".") - s, g = t.length - r.length - u;
return ze(t.substr(0, u) + r + t.substr(t.length - g));
}
if (o = t.match(/^00,000\.([#0]*0)$/)) return s = zc(e, o[1].length), e < 0 ? "-" + Re(a, t, -e) : Xn((function(f) {
return f < 2147483647 && f > -2147483648 ? "" + (f >= 0 ? 0 | f : f - 1 | 0) : "" + Math.floor(f);
})(e)).replace(/^\d,\d{3}$/, "0$&").replace(/^\d*$/, function(f) {
return "00," + (f.length < 3 ? He(0, 3 - f.length) : "") + f;
}) + "." + He(s, o[1].length);
switch (t) {
case "###,##0.00":
return Re(a, "#,##0.00", e);
case "###,###":
case "##,###":
case "#,###":
var m = Xn(Ir(l, 0));
return m !== "0" ? c + m : "";
case "###,###.00":
return Re(a, "###,##0.00", e).replace(/^0\./, ".");
case "#,###.00":
return Re(a, "#,##0.00", e).replace(/^0\./, ".");
}
throw new Error("unsupported format |" + t + "|");
}
function rg(a, t) {
var e, n = a.indexOf("E") - a.indexOf(".") - 1;
if (a.match(/^#+0.0E\+0$/)) {
if (t === 0) return "0.0E+0";
if (t < 0) return "-" + rg(a, -t);
var r = a.indexOf(".");
r === -1 && (r = a.indexOf("E"));
var o = Math.floor(Math.log(t) * Math.LOG10E) % r;
if (o < 0 && (o += r), !(e = (t / Math.pow(10, o)).toPrecision(n + 1 + (r + o) % r)).match(/[Ee]/)) {
var s = Math.floor(Math.log(t) * Math.LOG10E);
e.indexOf(".") === -1 ? e = e.charAt(0) + "." + e.substr(1) + "E+" + (s - e.length + o) : e += "E+" + (s - o), e = e.replace(/\+-/, "-");
}
e = e.replace(/^([+-]?)(\d*)\.(\d*)[Ee]/, function(i, l, c, h) {
return l + c + h.substr(0, (r + o) % r) + "." + h.substr(o) + "E";
});
} else e = t.toExponential(n);
return a.match(/E\+00$/) && e.match(/e[+-]\d$/) && (e = e.substr(0, e.length - 1) + "0" + e.charAt(e.length - 1)), a.match(/E-/) && e.match(/e\+/) && (e = e.replace(/e\+/, "e")), e.replace("e", "E");
}
function rn(a, t, e) {
if (a.charCodeAt(0) === 40 && !t.match(eg)) {
var n = t.replace(/\( */, "").replace(/ \)/, "").replace(/\)/, "");
return e >= 0 ? rn("n", n, e) : "(" + rn("n", n, -e) + ")";
}
if (t.charCodeAt(t.length - 1) === 44) return (function(m, f, p) {
for (var _ = f.length - 1; f.charCodeAt(_ - 1) === 44; ) --_;
return Nn(m, f.substr(0, _), p / Math.pow(10, 3 * (f.length - _)));
})(a, t, e);
if (t.indexOf("%") !== -1) return (function(m, f, p) {
var _ = f.replace(Yu, ""), S = f.length - _.length;
return Nn(m, _, p * Math.pow(10, 2 * S)) + Fe("%", S);
})(a, t, e);
if (t.indexOf("E") !== -1) return rg(t, e);
if (t.charCodeAt(0) === 36) return "$" + rn(a, t.substr(t.charAt(1) === " " ? 2 : 1), e);
var r, o, s, i, l = Math.abs(e), c = e < 0 ? "-" : "";
if (t.match(/^00+$/)) return c + He(l, t.length);
if (t.match(/^[#?]+$/)) return r = "" + e, e === 0 && (r = ""), r.length > t.length ? r : ze(t.substr(0, t.length - r.length)) + r;
if (o = t.match(Zu)) return (function(m, f, p) {
return p + (f === 0 ? "" : "" + f) + Fe(" ", m[1].length + 2 + m[4].length);
})(o, l, c);
if (t.match(/^#+0+$/)) return c + He(l, t.length - t.indexOf("0"));
if (o = t.match(tg)) return r = ("" + e).replace(/^([^.]+)$/, "." + ze(o[2])).replace(/\.$/, "." + ze(o[2])), r = He(Math.abs(e), o[1].length) + r.replace(/\.(\d*)$/, function(m, f) {
return "." + f + Fe("0", ze(o[2]).length - f.length);
}), r = t.indexOf("0.") !== -1 ? r : r.replace(/^0\./, "."), e < 0 ? "-" + r : r;
if (t = t.replace(/^#+([0.])/, "$1"), o = t.match(/^(0*)\.(#*)$/)) return c + ("" + l).replace(/\.(\d*[1-9])0*$/, ".$1").replace(/^(-?\d*)$/, "$1.").replace(/^0\./, o[1].length ? "0." : ".");
if (o = t.match(/^#{1,3},##0(\.?)$/)) return c + Xn("" + l);
if (o = t.match(/^#,##0\.([#0]*0)$/)) return e < 0 ? "-" + rn(a, t, -e) : Xn("" + e) + "." + Fe("0", o[1].length);
if (o = t.match(/^#,#*,#0/)) return rn(a, t.replace(/^#,#*,/, ""), e);
if (o = t.match(/^([0#]+)(\\?-([0#]+))+$/)) return r = $r(rn(a, t.replace(/[\\-]/g, ""), e)), s = 0, $r($r(t.replace(/\\/g, "")).replace(/[0#]/g, function(m) {
return s < r.length ? r.charAt(s++) : m === "0" ? "0" : "";
}));
if (t.match(ng)) return "(" + (r = rn(a, "##########", e)).substr(0, 3) + ") " + r.substr(3, 3) + "-" + r.substr(6);
var h = "";
if (o = t.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/)) return s = Math.min(o[4].length, 7), i = Ci(l, Math.pow(10, s) - 1, !1), r = "" + c, (h = Nn("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 = ze(o[4].substr(o[4].length - h.length)) + h), r += h;
if (o = t.match(/^# ([#0?]+)( ?)\/( ?)([#0?]+)/)) return s = Math.min(Math.max(o[1].length, o[4].length), 7), c + ((i = Ci(l, Math.pow(10, s) - 1, !0))[0] || (i[1] ? "" : "0")) + " " + (i[1] ? yl(i[1], s) + o[2] + "/" + o[3] + yi(i[2], s) : Fe(" ", 2 * s + 1 + o[2].length + o[3].length));
if (o = t.match(/^[#0?]+$/)) return r = "" + e, t.length <= r.length ? r : ze(t.substr(0, t.length - r.length)) + r;
if (o = t.match(/^([#0]+)\.([#0]+)$/)) {
r = "" + e.toFixed(Math.min(o[2].length, 10)).replace(/([^0])0+$/, "$1"), s = r.indexOf(".");
var d = t.indexOf(".") - s, u = t.length - r.length - d;
return ze(t.substr(0, d) + r + t.substr(t.length - u));
}
if (o = t.match(/^00,000\.([#0]*0)$/)) return e < 0 ? "-" + rn(a, t, -e) : Xn("" + e).replace(/^\d,\d{3}$/, "0$&").replace(/^\d*$/, function(m) {
return "00," + (m.length < 3 ? He(0, 3 - m.length) : "") + m;
}) + "." + He(0, o[1].length);
switch (t) {
case "###,###":
case "##,###":
case "#,###":
var g = Xn("" + l);
return g !== "0" ? c + g : "";
default:
if (t.match(/\.[0#?]*$/)) return rn(a, t.slice(0, t.lastIndexOf(".")), e) + ze(t.slice(t.lastIndexOf(".")));
}
throw new Error("unsupported format |" + t + "|");
}
function Nn(a, t, e) {
return (0 | e) === e ? rn(a, t, e) : Re(a, t, e);
}
function og(a) {
var t = [], e = !1;
const n = a.length;
for (var r = 0, o = 0; r < n; ++r) switch (a.charCodeAt(r)) {
case 34:
e = !e;
break;
case 95:
case 42:
case 92:
++r;
break;
case 59:
t[t.length] = a.substr(o, r - o), o = r + 1;
}
if (t[t.length] = a.substr(o), e === !0) throw new Error("Format |" + a + "| unterminated string ");
return t;
}
var sg = /\[[HhMmSs\u0E0A\u0E19\u0E17]*\]/;
function ig(a) {
for (var t = 0, e = "", n = "", r = a.length; t < r; ) switch (e = a.charAt(t)) {
case "G":
Gs(a, t) && (t += 6), t++;
break;
case '"':
for (; a.charCodeAt(++t) !== 34 && t < a.length; ) ;
++t;
break;
case "\\":
case "_":
t += 2;
break;
case "@":
++t;
break;
case "B":
case "b":
if (a.charAt(t + 1) === "1" || a.charAt(t + 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(t, 3).toUpperCase() === "A/P" || a.substr(t, 5).toUpperCase() === "AM/PM" || a.substr(t, 5).toUpperCase() === "上午/下午") return !0;
++t;
break;
case "[":
for (n = e; a.charAt(t++) !== "]" && t < a.length; ) n += a.charAt(t);
if (n.match(sg)) return !0;
break;
case ".":
case "0":
case "#":
for (; t < a.length && ("0#?.,E+-%".indexOf(e = a.charAt(++t)) > -1 || e === "\\" && a.charAt(t + 1) === "-" && "0#".indexOf(a.charAt(t + 2)) > -1); ) ;
break;
case "?":
for (; a.charAt(++t) === e; ) ;
break;
case "*":
++t, a.charAt(t) !== " " && a.charAt(t) !== "*" || ++t;
break;
case "(":
case ")":
++t;
break;
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
for (; t < a.length && "0123456789".indexOf(a.charAt(++t)) > -1; ) ;
break;
default:
++t;
}
return !1;
}
var Pc = /\[(=|>[=]?|<[>=]?)(-?\d+(?:\.\d*)?)\]/;
function Wc(a, t) {
if (t == null) return !1;
var e = parseFloat(t[2]);
switch (t[1]) {
case "=":
if (a === e) return !0;
break;
case ">":
if (a > e) return !0;
break;
case "<":
if (a < e) return !0;
break;
case "<>":
if (a !== e) return !0;
break;
case ">=":
if (a >= e) return !0;
break;
case "<=":
if (a <= e) return !0;
}
return !1;
}
function ag(a, t, e) {
e == null && (e = k.EmptyObject);
var n = "";
switch (typeof a) {
case "string":
n = a === "m/d/yy" && e.dateNF ? e.dateNF : a;
break;
case "number":
(n = a === 14 && e.dateNF ? e.dateNF : (e.table != null ? e.table : fr)[a]) == null && (n = e.table && e.table[Dc[a]] || fr[Dc[a]]), n == null && (n = kf[a] || "General");
}
if (Gs(n, 0)) return ha(t, e);
Ku(t) && (t = Xl(t, e.date1904));
var r = (function(o, s) {
var i = og(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 d = i[0].match(Pc), u = i[1].match(Pc);
return Wc(s, d) ? [l, i[0]] : Wc(s, u) ? [l, i[1]] : [l, i[d != null && u != null ? 2 : 1]];
}
return [l, h];
})(n, t);
if (Gs(r[1])) return ha(t, e);
if (t === !0) t = "TRUE";
else if (t === !1) t = "FALSE";
else if (t === "" || t == null) return "";
return (function(o, s, i, l) {
var c, h, d, u = [], g = "", m = 0, f = "", p = "t", _ = "H";
let S = o.length;
for (; m < S; ) switch (f = o.charAt(m)) {
case "G":
if (!Gs(o, m)) throw new Error("unrecognized character " + f + " in " + o);
u[u.length] = { t: "G", v: "General" }, m += 7;
break;
case '"':
for (g = ""; (d = o.charCodeAt(++m)) !== 34 && m < o.length; ) g += String.fromCharCode(d);
u[u.length] = { t: "t", v: g }, ++m;
break;
case "\\":
var C = o.charAt(++m), y = C === "(" || C === ")" ? C : "t";
u[u.length] = { t: y, v: C }, ++m;
break;
case "@":
u[u.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 = Oo(s, i, o.charAt(m + 1) === "2")) == null) return "";
u[u.length] = { t: "X", v: o.substr(m, 2) }, p = 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 = Oo(s, i)) == null) return "";
for (g = f; ++m < o.length && o.charAt(m).toLowerCase() === f; ) g += f;
f === "m" && p.toLowerCase() === "h" && (f = "M"), f === "h" && (f = _), u[u.length] = { t: f, v: g }, p = f;
break;
case "A":
case "a":
case "上":
var E = { t: f, v: f };
if (c == null && (c = Oo(s, i)), o.substr(m, 3).toUpperCase() === "A/P" ? (c != null && (E.v = c.H >= 12 ? "P" : "A"), E.t = "T", _ = "h", m += 3) : o.substr(m, 5).toUpperCase() === "AM/PM" ? (c != null && (E.v = c.H >= 12 ? "PM" : "AM"), E.t = "T", m += 5, _ = "h") : o.substr(m, 5).toUpperCase() === "上午/下午" ? (c != null && (E.v = c.H >= 12 ? "下午" : "上午"), E.t = "T", m += 5, _ = "h") : (E.t = "t", ++m), c == null && E.t === "T") return "";
u[u.length] = E, p = 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(sg)) {
if (c == null && (c = Oo(s, i)) == null) return "";
u[u.length] = { t: "Z", v: g.toLowerCase() }, p = g.charAt(1);
} else g.indexOf("$") > -1 && (g = (g.match(/\$([^-[\]]*)/) || [])[1] || "$", ig(o) || (u[u.length] = { t: "t", v: g }));
break;
case ".":
if (c != null) {
for (g = f; ++m < o.length && (f = o.charAt(m)) === "0"; ) g += f;
u[u.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;
u[u.length] = { t: "n", v: g };
break;
case "?":
for (g = f; o.charAt(++m) === f; ) g += f;
u[u.length] = { t: f, v: g }, p = f;
break;
case "*":
if (++m, !(g = o.charAt(m))) throw new Error("no character specified for repeat function: " + o);
u[u.length] = { t: "R", v: g }, ++m;
break;
case "_":
if (++m, !(g = o.charAt(m))) throw new Error("no character specified for spacing function: " + o);
u[u.length] = { t: "S", v: g }, ++m;
break;
case "(":
case ")":
u[u.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);
u[u.length] = { t: "D", v: g };
break;
case " ":
u[u.length] = { t: f, v: f }, ++m;
break;
case "$":
u[u.length] = { t: "t", v: "$" }, ++m;
break;
default:
if (",$-+/():!^&'~{}<>=€acfijklopqrtuvwxzP".indexOf(f) === -1) throw new Error("unrecognized character " + f + " in " + o);
u[u.length] = { t: "t", v: f }, ++m;
}
var w, b = 0, v = 0;
for (m = u.length - 1, p = "t"; m >= 0; --m) switch (u[m].t) {
case "h":
case "H":
u[m].t = _, p = "h", b < 1 && (b = 1);
break;
case "s":
(w = u[m].v.match(/\.0+$/)) && (v = Math.max(v, w[0].length - 1)), b < 3 && (b = 3);
case "d":
case "y":
case "M":
case "e":
p = u[m].t;
break;
case "m":
p === "s" && (u[m].t = "M", b < 2 && (b = 2));
break;
case "X":
break;
case "Z":
b < 1 && u[m].v.match(/[Hh]/) && (b = 1), b < 2 && u[m].v.match(/[Mm]/) && (b = 2), b < 3 && u[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, x = "";
for (S = u.length, m = 0; m < S; ++m) switch (u[m].t) {
case "t":
case "T":
case " ":
case "D":
break;
case "X":
u[m].v = "", u[m].t = ";";
break;
case "d":
case "m":
case "y":
case "h":
case "H":
case "M":
case "s":
case "e":
case "b":
case "Z":
u[m].v = Bf(u[m].t.charCodeAt(0), u[m].v, c, v), u[m].t = "t";
break;
case "n":
case "?":
for (I = m + 1; u[I] != null && ((f = u[I].t) === "?" || f === "D" || (f === " " || f === "t") && u[I + 1] != null && (u[I + 1].t === "?" || u[I + 1].t === "t" && u[I + 1].v === "/") || u[m].t === "(" && (f === " " || f === "n" || f === ")") || f === "t" && (u[I].v === "/" || u[I].v === " " && u[I + 1] != null && u[I + 1].t === "?")); ) u[m].v += u[I].v, u[I] = { v: "", t: ";" }, ++I;
x += u[m].v, m = I - 1;
break;
case "G":
u[m].t = "t", u[m].v = ha(s, i);
}
var R, A, M = "";
if (x.length > 0) {
x.charCodeAt(0) === 40 ? (R = s < 0 && x.charCodeAt(0) === 45 ? -s : s, A = Nn("n", x, R)) : (A = Nn("n", x, R = s < 0 && l > 1 ? -s : s), R < 0 && u[0] && u[0].t === "t" && (A = A.substr(1), u[0].v = "-" + u[0].v)), I = A.length - 1;
var T = u.length;
for (S = u.length, m = 0; m < S; ++m) if (u[m] != null && u[m].t !== "t" && u[m].v.indexOf(".") > -1) {
T = m;
break;
}
var O = S;
if (T === S && A.indexOf("E") === -1) {
for (m = u.length - 1; m >= 0; --m) u[m] != null && "n?".indexOf(u[m].t) !== -1 && (I >= u[m].v.length - 1 ? (I -= u[m].v.length, u[m].v = A.substr(I + 1, u[m].v.length)) : I < 0 ? u[m].v = "" : (u[m].v = A.substr(0, I + 1), I = -1), u[m].t = u[m].v.indexOf("?") >= 0 ? "N" : "t", O = m);
I >= 0 && O < u.length && (u[O].v = A.substr(0, I + 1) + u[O].v);
} else if (T !== u.length && A.indexOf("E") === -1) {
for (I = A.indexOf(".") - 1, m = T; m >= 0; --m) if (u[m] != null && "n?".indexOf(u[m].t) !== -1) {
for (h = u[m].v.indexOf(".") > -1 && m === T ? u[m].v.indexOf(".") - 1 : u[m].v.length - 1, M = u[m].v.substr(h + 1); h >= 0; --h) I >= 0 && (u[m].v.charAt(h) === "0" || u[m].v.charAt(h) === "#" || u[m].v.charAt(h) === "?") && (M = A.charAt(I--) + M);
u[m].v = M, u[m].t = M.indexOf("?") >= 0 ? "N" : "t", O = m;
}
for (I >= 0 && O < u.length && (u[O].v = A.substr(0, I + 1) + u[O].v), I = A.indexOf(".") + 1, m = T; m < u.length; ++m) if (u[m] != null && ("n?(".indexOf(u[m].t) !== -1 || m === T)) {
for (h = u[m].v.indexOf(".") > -1 && m === T ? u[m].v.indexOf(".") + 1 : 0, M = u[m].v.substr(0, h); h < u[m].v.length; ++h) I < A.length && (M += A.charAt(I++));
u[m].v = M, u[m].t = M.indexOf("?") >= 0 ? "N" : "t", O = m;
}
}
}
for (m = 0; m < S; ++m) u[m] != null && "n?".indexOf(u[m].t) > -1 && (R = l > 1 && s < 0 && m > 0 && u[m - 1].v === "-" ? -s : s, u[m].v = Nn(u[m].t, u[m].v, R), u[m].t = u[m].v.indexOf("?") >= 0 ? "N" : "t");
var W = "";
for (S = u.length, m = 0; m < S; m++) if (u[m].t === "R") i?.onRepeatChar?.(W.length, u[m].v);
else if (u[m].t === "S") i?.onSpacingChar?.(W.length, u[m].v), W += i?.spacingCharacter ?? " ";
else if (u[m].t === "N") {
M = u[m].v;
for (var D = 0; D < M.length; D++) (f = M[D]) === "?" && (i?.onDigitChar?.(W.length, f), f = i?.digitCharacter ?? " "), W += f;
} else u[m] != null && (W += u[m].v);
return W;
})(r[1], t, e, r[0]);
}
function Hc(a, t) {
if (typeof t != "number") {
t = +t || -1;
for (var e = 0; e < 392; ++e) if (fr[e] !== void 0) {
if (fr[e] === a) {
t = e;
break;
}
} else t < 0 && (t = e);
t < 0 && (t = 391);
}
return fr[t] = a, t;
}
const ne = { format: ag, dateNumLocal: Xl, load: Hc, split_fmt: og, _table: fr, load_table: function(a) {
for (var t = 0; t !== 392; ++t) a[t] !== void 0 && Hc(a[t], t);
}, parse_date_code: Oo, is_date: ig, get_table: function() {
return ne._table = fr;
} }, se = "\\s*([-]?[0-9e]*[.]?[0-9]+)", zf = new RegExp(`^rgb\\(${se},${se},${se}\\)$`), Pf = new RegExp(`^rgba\\(${se},${se},${se},${se}\\)$`), Wf = new RegExp(`^lrgb\\(${se},${se},${se}\\)$`), Hf = new RegExp(`^lrgba\\(${se},${se},${se},${se}\\)$`), Vf = new RegExp(`^hsl\\(${se},${se},${se}\\)$`), jf = new RegExp(`^hsla\\(${se},${se},${se},${se}\\)$`), $f = new RegExp(/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/), Gf = new RegExp(/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/), Uf = new RegExp("^index(\\d+)$", "i"), da = (a, t, e) => [parseFloat(a), parseFloat(t), parseFloat(e)], ua = (a, t = 255) => {
const e = [...a];
for (var n = 0; n < a.length; n++) e[n] = a[n] / t;
return e;
}, Vc = (a, t = 0) => {
const e = [...a];
for (var n = 0; n < a.length; n++) k.roundAccurately(a[n], t + 8) % 1 == 0.5 ? e[n] = Math.floor(a[n]) : e[n] = k.roundAccurately(a[n], t);
return e;
}, pe = (a, t = !0) => {
const e = [...a], n = t ? 1 : 255;
for (var r = 0; r < a.length; r++) e[r] = Math.max(0, Math.min(n, a[r]));
return e;
}, Pr = (a) => Math.max(0, Math.min(1, a)), lg = (a) => ((a %= 360) < 0 && (a -= 360), a), Sr = (a) => {
const t = [...a];
for (var e = 0; e < a.length; e++) t[e] = Us(a[e]);
return t;
}, yr = (a) => {
const t = [...a];
for (var e = 0; e < a.length; e++) t[e] = qs(a[e]);
return t;
}, Us = (a) => a < 0.04045 ? a / 12.92 : Math.pow((a + 0.055) / 1.055, 2.4), qs = (a) => a < 31308e-7 ? 12.92 * a : 1.055 * Math.pow(a, 1 / 2.4) - 0.055, Cr = (a) => {
let t = a[0], e = a[1], n = a[2];
t %= 360, t /= 360, e /= 100, n /= 100;
let r = n < 0.5 ? n * (1 + e) : n + e - e * n, o = 2 * n - r;
return [Math.max(0, ga(o, r, t + 1 / 3)), Math.max(0, ga(o, r, t)), Math.max(0, ga(o, r, t - 1 / 3))];
}, ga = (a, t, e) => (e < 0 && (e += 1), e > 1 && (e -= 1), 6 * e < 1 ? a + 6 * (t - a) * e : 2 * e < 1 ? t : 3 * e < 2 ? a + 6 * (t - a) * (2 / 3 - e) : a), Zn = (a) => {
let t = a[0], e = a[1], n = a[2], r = Math.min(t, Math.min(e, n)), o = Math.max(t, Math.max(e, n)), s = 0;
o === r ? s = 0 : o === t ? s = (60 * (e - n) / (o - r) + 360) % 360 : o === e ? s = 60 * (n - t) / (o - r) + 120 : o === n && (s = 60 * (t - e) / (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];
}, fe = 0, ma = 1, mo = 2, Js = 0, Ks = 1, Xs = 2, Ys = 0, Qs = 1, Zs = 2, qf = (a, t) => {
let e = t / 100;
return ((n, r) => {
let o = Sr(n);
o[0] = r(o[0], o), o[1] = r(o[1], o), o[2] = r(o[2], o);
let s = yr(o);
return s = pe(s), s;
})(a, (n, r) => n * e);
}, ms = 2.55, Jf = (a, t) => {
const e = Zn(a), n = e[2], r = k.roundAccurately((o = n, (s = t) > 0 ? (o * ms * (1 - s) + (255 - 255 * (1 - s))) / ms : s < 0 ? o * ms * (1 + s) / ms : o), 3);
var o, s;
e[2] = r;
let i = Cr(e);
return i = pe(i), i;
}, Kf = (a, t) => {
let e = Sr(a), n = t / 100;
for (var r = 0; r < 3; r++) e[r] = e[r] * n + (1 - n);
let o = yr(e);
return o = pe(o), o;
}, fa = (a, t, e) => {
let n = Zn(t), r = e / 1;
a === fe && (r = lg(e)), n[a] = r;
let o = Cr(n);
return o = pe(o), o;
}, pa = (a, t, e) => {
let n = Zn(t);
if (a === fe) {
let o = e / 360;
n[fe] = 360 * (n[fe] / 360 + o), n[fe] %= 360, n[fe] < 0 && (n[fe] -= 360);
} else {
let o = e / 0.1;
n[a] = 0.1 * (n[a] / 0.1 + o);
}
let r = Cr(n);
return r = pe(r), r;
}, _a = (a, t, e) => {
let n = Zn(t), r = e / 100;
n[a] = n[a] * r, a === fe && (n[fe] = lg(n[fe]));
let o = Cr(n);
return o = pe(o), o;
}, pn = (a, t, e, n) => {
let r = Sr(t), o = e / 100;
n === Ys ? r[a] = o : n === Qs ? r[a] += o : n === Zs && (r[a] *= o);
let s = yr(r);
return s = pe(s), s;
}, Xf = (a) => {
let t = Sr(a), e = 0.213 * t[Js] + 0.715 * t[Ks] + 0.072 * t[Xs];
t[0] = e, t[1] = e, t[2] = e;
let n = yr(t);
return n = pe(n), n;
}, Yf = (a) => {
let t = Zn(a);
t[fe] += 180, t[fe] %= 360, t[fe] < 0 && (t[fe] -= 360);
let e = Cr(t);
return e = pe(e), e;
}, jc = (a, t = !0) => {
let e = t ? Sr(a) : [...a];
const n = t ? 1 : 255;
return e[0] = n - e[0], e[1] = n - e[1], e[2] = n - e[2], t && (e = yr(e)), e = pe(e, t), e;
}, Qf = (a) => {
const t = [0, 0, 0];
return t[0] = qs(a[0]), t[1] = qs(a[1]), t[2] = qs(a[2]), pe(t);
}, Zf = (a) => {
const t = [0, 0, 0];
return t[0] = Us(a[0]), t[1] = Us(a[1]), t[2] = Us(a[2]), pe(t);
}, $c = (a, t, e, 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(t)).toUpperCase() + r(Number(e)).toUpperCase();
}, Rr = 0.2126, zn = 0.7152, Ar = 0.0722;
var In;
((a) => {
a.RGBA = class {
constructor(e, n, r, o = 1) {
this._private = { red: e, 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(e = !0) {
return e && this._private.alpha !== null ? `rgba(${this.red},${this.green},${this.blue},${this.alpha})` : `rgb(${this.red},${this.green},${this.blue})`;
}
isEqual(e) {
return !!e && e.red === this.red && e.green === this.green && e.blue === this.blue && e.alpha === this.alpha;
}
isAlmostEqual(e) {
if (!e) return !1;
const n = 1.5;
return !(Math.abs(e.red - this.red) > n) && !(Math.abs(e.green - this.green) > n) && !(Math.abs(e.blue - this.blue) > n) && !(Math.abs(e.alpha - this.alpha) > n);
}
}, a.HSLA = class {
constructor(e, n, r, o) {
this._private = { hue: e, 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(e = !0) {
return e && this._private.alpha !== null ? `hsla(${this.hue},${this.sat},${this.lum},${this.alpha})` : `hsl(${this.hue},${this.sat},${this.lum})`;
}
isEqual(e) {
return !!e && e.hue === this.hue && e.sat === this.sat && e.lum === this.lum && e.alpha === this.alpha;
}
isAlmostEqual(e) {
if (!e) return !1;
const n = 1.5;
return !(Math.abs(e.hue - this.hue) > n) && !(Math.abs(e.sat - this.sat) > n) && !(Math.abs(e.lum - this.lum) > n) && !(Math.abs(e.alpha - this.alpha) > n);
}
};
class t extends a.RGBA {
toString(n = !0) {
return n && this._private.alpha !== null ? "#" + $c(this.red, this.green, this.blue, this.alpha ?? 1).toUpperCase() : "#" + $c(this.red, this.green, this.blue).toUpperCase();
}
}
a.HEX = t;
})(In || (In = {}));
const tp = /^#?([a-f\d])([a-f\d])([a-f\d])$/i, ep = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i, ti = function(a) {
if (!a) return null;
a = a.replace(tp, function(e, n, r, o) {
return n + n + r + r + o + o;
});
let t = ep.exec(a);
return t ? new In.RGBA(parseInt(t[1], 16), parseInt(t[2], 16), parseInt(t[3], 16)) : null;
}, Gc = ["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"], dr = /* @__PURE__ */ new Map();
for (let a = 0; a < Gc.length; a++) dr.set(a, ti(Gc[a]));
dr.set(-4105, null), dr.set(-4142, null), dr.set(64, ti("000000")), dr.set(65, ti("FFFFFF")), dr.set(81, ti("FFFFFF"));
const Ei = (a) => dr.get(a), ft = { 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 cg = () => Sa || (Sa = Intl.DateTimeFormat().resolvedOptions().locale ?? "en-US", Sa), np = /^\[\$-(.*?)\]/i, rp = /^[0-9a-fA-F]+$/, op = ne.split_fmt, Yl = (a, t, e) => {
const n = np.exec(a);
let r = cg();
if (n && n[1]) {
let o = n[1];
rp.test(o) || o.includes("-");
}
if (Uc[a] && (a = Uc[a]), typeof t == "number") {
const o = Do(a, t, { locale: r, ...e });
if (o !== null) return o.fmt;
}
return ne.format(a, t, e);
}, Do = (a, t, e) => {
if (typeof t != "number") return null;
const n = oo(t, e?.date1904 ?? !1), r = e?.locale ?? cg();
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 = ne.format(ne.get_table()[15], t, e);
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 = ne.format(ne.get_table()[20], t, e);
s = s.substring(0, i) + l + s.substring(i + 10), o = !0;
}
if ((i = s.indexOf("Medium Time")) !== -1) {
const l = ne.format(ne.get_table()[18], t, e);
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;
}, Uc = Object.freeze({ "General Number": "General", "General Date": "m/d/yyyy h:mm", "Medium Date": ne.get_table()[15], "Medium Time": ne.get_table()[18], "Short Time": ne.get_table()[20], Currency: '"$"#,##0.00_);[Red]\\("$"#,##0.00\\)', Fixed: ne.get_table()[2], Standard: ne.get_table()[4], Percent: ne.get_table()[10], Scientific: ne.get_table()[11], "Yes/No": '"Yes";"Yes";"No";@', "True/False": '"True";"True";"False";@', "On/Off": '"Yes";"Yes";"No";@' }), sp = Object.freeze({ black: 0, white: 1, red: 2, green: 3, blue: 4, yellow: 5, magenta: 6, cyan: 7 }), ip = (a) => {
let t = null;
if ((a = a.toLowerCase()).startsWith("color")) {
const e = parseInt(a.substring(5));
e >= 0 && e <= 56 && (t = `Index${e + 7}`);
}
if (!t) {
const e = sp[a];
e !== void 0 && (t = Ei(e).toString());
}
return t;
}, hg = "=", ap = "<>", dg = ">", ug = "<", gg = ">=", lp = "<=", cr = /* @__PURE__ */ new Map();
cr.set(hg, (a, t) => a === t), cr.set(ap, (a, t) => a !== t), cr.set(dg, (a, t) => a > t), cr.set(ug, (a, t) => a < t), cr.set(gg, (a, t) => a >= t), cr.set(lp, (a, t) => a <= t);
const cp = /(Black|Blue|Cyan|Green|Magenta|Red|White|Yellow|Color[0-9]+)/i, hp = /(=|>[=]?|<[>=]?)(-?\d+(?:\.\d*)?)/i, dp = /\[(.*?)\]/g, up = (a, t) => {
const e = { color: null, condition: null };
let n = null, r = new RegExp(dp);
for (; (n = r.exec(a)) !== null; ) {
let o = !1, s = cp.exec(n[1]);
if (s) {
if (o = !0, e.color) throw new Error(`format error, two colors specified: '${a}' and '${e.color}'.`);
e.color = ip(s[1]), e.color || console.warn("Unable to parse LegacyColor", s[1]);
}
let i = hp.exec(n[1]);
if (i) {
if (o = !0, e.condition) throw new Error(`Format error, two conditions specified: ' ${a}'`);
e.condition = { op: i[1], comp: parseFloat(i[2]) };
}
if (!o) return e;
}
return e.condition || (e.condition = t), e;
}, gp = Object.freeze({ op: gg, comp: 0 }), qc = Object.freeze({ op: ug, comp: 0 }), mp = Object.freeze({ op: dg, comp: 0 }), fp = Object.freeze({ op: hg, comp: 0 }), pp = (a, t) => {
let e = ((o) => {
if (!o) return k.EmptyArray;
const s = [], i = o.split(";"), l = i.length;
for (let c = 0; c < l; c++) {
let h = null;
l === 2 ? c === 0 ? h = gp : c === 1 && (h = qc) : l !== 3 && l !== 4 || (h = c === 0 ? mp : c === 1 ? qc : c === 2 ? fp : null);
const d = i[c], u = up(d, h);
s.push({ format: d, colorAndCondition: u });
}
return s;
})(a);
const n = e.length;
if (n === 0) return null;
let r = e[0].colorAndCondition;
if (n === 1 && r && !r.condition && r.color) return r.color;
for (let o = 0; o < n; o++) {
r = e[o].colorAndCondition;
let s = r?.condition ?? void 0;
if (o === 3) return typeof t == "string" && r?.color ? r.color : null;
if (s && typeof t == "number" && cr.get(s.op)(t, s.comp))
return r?.color ?? null;
}
}, Jc = (a) => {
if (a === ft.MediumDate || a === ft.LongDate || a === ft.ShortDate || a === ft.MediumTime || a === ft.LongTime || a === ft.ShortTime) return !0;
}, _p = (a, t) => a === t ? 0 : Jc(a) ? 1 : Jc(t) ? -1 : a === ft.Percentage ? 1 : t === ft.Percentage ? -1 : a === ft.Currency || a === ft.Accounting ? 1 : t === ft.Currency || t === ft.Accounting ? -1 : 0, ro = (a) => (a instanceof Date || Object.prototype.toString.call(a) === "[object Date]") && !isNaN(a.getTime()), Sp = (a, t, e) => {
return e === "month" || e === "months" || e === "m" ? (n = a, 12 * ((r = t).getUTCFullYear() - n.getUTCFullYear()) + (r.getUTCMonth() - n.getUTCMonth()) + (r.getUTCDate() - n.getUTCDate() < 0 ? -1 : 0)) : e === "year" || e === "years" || e === "y" ? ((o, s) => Math.abs(s.getFullYear() - o.getFullYear()))(a, t) : e === "day" || e === "days" || e === "d" ? ((o, s) => Math.floor((Date.UTC(s.getFullYear(), s.getMonth(), s.getDate()) - Date.UTC(o.getFullYear(), o.getMonth(), o.getDate())) / 864e5))(a, t) : void console.warn("invalid unit" + e);
var n, r;
}, fs = "d", Kc = "m", Xc = "y", Yc = (a, t, e) => {
if (e === "month" || e === "months" || e === "m") {
const n = new Date(a.getTime());
return new Date(n.setMonth(n.getMonth() + t));
}
if (e === "year" || e === "years" || e === "y") {
const n = new Date(a.getTime());
return n.setFullYear(n.getFullYear() + t), n;
}
if (e === "day" || e === "days" || e === "d") {
const n = new Date(a.getTime());
return n.setDate(n.getDate() + t), n;
}
if (e === "hour" || e === "hours" || e === "h") {
const n = new Date(a.getTime());
return n.setHours(n.getHours() + t), n;
}
return console.warn("invalid unit" + e), null;
}, oo = (a, t = !1) => {
let e = ne.parse_date_code(a, { date1904: t });
return e ? new Date(e.y, e.m - 1, e.d, e.H, e.M, e.S, Math.round(1e3 * e.u)) : null;
}, rs = (a, t = !1) => isNaN(a) ? null : ne.dateNumLocal(a, t), wp = new class extends Ju {
parse(a, t, e) {
const n = (r) => r - 1;
switch (t) {
case "M":
return Tn(qn(qu, a), n);
case "MM":
return Tn(qo(2, a), n);
case "Mo":
return Tn(e.ordinalNumber(a, { unit: "month" }), n);
case "MMM":
return e.month(a, { width: "abbreviated", context: "formatting" });
case "MMMMM":
return e.month(a, { width: "narrow", context: "formatting" });
default:
return e.month(a, { width: "wide", context: "formatting" });
}
}
}(), _n = ((a) => {
let t = a, e = [];
for (let n = 0; n < t.length; n++) {
let r = t[n][0].indexOf("yyy") > -1, o = t[n][0].indexOf(".") > -1, s = t[n][0].indexOf("-") > -1;
e.push({ parseFormat: t[n][0], numberFormat: t[n][1], todaysYear: !r, windowYear: !0, containsDot: o, containsDash: s }), r && e.push({ parseFormat: t[n][0].replace(/yyy/g, "yyyy"), numberFormat: t[n][1], todaysYear: !1, windowYear: !1, containsDot: o, containsDash: s });
}
return e;
})([["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"]]), yp = { year: 0, month: 1, day: 0, hour: 0, minute: 0, second: 0, millis: 0 }, Cp = (a, t = !1) => {
const e = { ...yp, ...a };
return e.year = t ? 1904 : 1900, e.dow = -1, e.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 rs(i, r);
})(e, t), e;
}, Ep = new RegExp("([0-9]{1,2})\\s*(P[M]?|A[M]?)\\s*$", "i"), bp = 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"), vp = new RegExp("(\\s*[0-9]{1,4})\\s*([\\.]{1}\\s*[0-9]*)?\\s*$", "i"), mg = (a, t = !1, e = !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, d = null;
do {
let p = h.indexOf(":");
p === -1 ? (c.push(h), h = null) : (c.push(h.substring(0, p + 1)), h = h.substring(p + 1, h.length));
} while (c.length < 3 && h && h.length > 0);
if (h?.length > 0) return null;
const u = (p, _, S) => {
let C = p.match(_);
if (!C) return null;
d === null && (d = p.substring(0, C.index));
let y = parseInt(C[1]);
if (C[2] && o === null) {
if (S) {
let w = parseFloat(C[2].substring(1, C[2].length));
isNaN(w) || (r = w);
}
let E = parseFloat(C[2]);
isNaN(E) || (n = E), o = S;
}
return y;
}, g = (p, _) => {
let S = p.match(_);
if (!S || S.length !== 3) return null;
d === null && (d = p.substring(0, S.index)), s = !0;
let C = parseInt(S[1]);
return i = S[2].charAt(0) === "p" || S[2].charAt(0) === "P", C;
};
c[c.length - 1].trim().length === 0 && c.pop();
const m = [];
if (c.length > 0) {
let p = u(c[0], bp, !1);
if (p === null && (p = g(c[0], Ep)), p === null) return null;
m.push(p);
}
if (c.length > 2) {
let p = u(c[1], Qc, !0);
if (p === null && (p = g(c[0], wa)), p === null) return null;
m.push(p);
}
if (c.length > 1) {
const p = c[c.length - 1];
let _ = u(p, Qc, !1);
if (_ === null && (_ = u(p, vp, !1)), _ === null && (_ = g(p, wa)), _ === null) return null;
m.push(_);
}
if (d !== null && d.length > 0 && !e) 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: Cp(f, t), leadingText: d };
}, xp = {}, Ql = (a, t = !1, e = null) => {
const n = e ?? 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 = ko.M;
ko.M = wp;
for (let c = 0; c < _n.length; c++) {
let h = o;
_n[c].containsDot ? h = s : _n[c].containsDash && (h = i);
let d = Nf(h, _n[c].parseFormat, n, xp), u = ne.dateNumLocal(d, t);
if (ro(d) && (_n[c].windowYear || u > 0)) {
if (_n[c].windowYear) {
let m = d.getFullYear() <= 29 ? 2e3 + d.getFullYear() : 1900 + d.getFullYear();
d.setFullYear(m);
}
if (_n[c].todaysYear && d.setFullYear(r), u = ne.dateNumLocal(d, t), _n[c].parseFormat.indexOf("EEE") > -1) {
const m = Yl("ddd", u, { date1904: t });
if (!h.toLowerCase().includes(m.toLowerCase())) return null;
}
let g = _n[c].numberFormat;
return ko.M = l, { asOADate: u, asJSDate: d, numberFormat: g };
}
}
return ko.M = l, null;
};
function os(a) {
if (!a) return !1;
let t = a.replaceAll(/\[([^)]+)\]/g, "").toLowerCase();
return t = t.replaceAll(/".*"/g, ""), t = t.replaceAll(/\\./g, ""), t = t.replace(/[_*]./g, ""), !t.includes("time") && !!(t.includes("d") || t.includes("m") && !t.includes("h") && !t.includes("s") || t.includes("y") || t === "short date" || t === "medium date" || t === "long date");
}
function Wi(a) {
if (!a) return !1;
let t = a.replaceAll(/\[([^)]+)\]/g, "").toLowerCase();
return t = t.replaceAll(/".*"/g, ""), t = t.replaceAll(/\\./g, ""), t = t.replace(/[_*]./g, ""), !t.includes("date") && !(!t.includes("h") && !t.includes("s") && t !== "short time" && t !== "medium time" && t !== "long time");
}
var bi, Zc, et, Sn;
(Zc = bi || (bi = {})).SmallCaps = { None: "none", Small: "small", All: "all" }, Zc.StrikeStyle = { None: "none", Single: "single", Double: "double" }, (Sn = et || (et = {})).TabStop = class {
}, Sn.HorizontalAlignment = { General: "general", Left: "left", Center: "center", Right: "right", Justify: "justify", Distributed: "distributed", CenterContinuous: "centerContinuous", Fill: "fill" }, Sn.VerticalAlignment = { Top: "top", Center: "center", Bottom: "bottom", Justify: "justify", Distributed: "distributed" }, Sn.Orientation = { Horizontal: "horizontal", Vertical: "90", Vertical270: "270", Stacked: "stacked" }, Sn.ReadingDirection = { Auto: "auto", LeftToRight: "ltr", RightToLeft: "rtl" }, Sn.Overflow = { Visible: "visible", Wrap: "wrap", Clip: "clip", Shrink: "shrink", Ellipsis: "ellipsis" }, Sn.Autofit = { None: "none", Normal: "normal", Shape: "shape" }, Sn.TabStopAlignment = { Default: "default", Left: "left", Right: "right", Center: "center" }, Sn.toCSSHorizontalTextAlign = (a) => a ? a.toLowerCase() : null;
const fg = (a, t, e = 1e3) => {
if (!a) throw new Error("A template string must be specified.");
if (t(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 + e; ) try {
const i = r.replace(/\d+/g, () => "" + o++);
if (t(i)) return i;
} catch {
}
throw new Error(`Unable to find valid name for '${a}'.`);
}, Qr = (a, t = !1) => {
if (!a || a.length === 0) return a;
const e = a.charAt(0);
if (e >= "a" && e <= "z") {
const n = String.fromCharCode(e.charCodeAt(0) - 32);
return t ? n + a.slice(1).toLowerCase() : n + a.slice(1);
}
return a;
}, th = (a) => {
if (!a || typeof a != "string") return "";
const t = a.split(/[\\/]/).pop() || "", e = t.lastIndexOf(".");
return t === "" || e < 1 ? "" : t.slice(e + 1);
}, pg = (a) => a.toLowerCase().replace(/([-_][a-z])/g, (t) => t.toUpperCase().replace("-", "").replace("_", "")), _g = (a, t = 36) => a.substring(0, 36) + (a.length > t ? "…" : ""), ei = (a) => {
if (a === void 0) return 0;
let t = a.toString().split(".");
return t.length <= 1 ? 0 : t[1].length || 0;
}, Sg = new RegExp(/^["|'|`](.*)["|'|`]$/), Ip = 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"), wg = (a = ",", t = "'") => new RegExp(`\\s*${a}\\s*(?=(?:[^${t}]*${t}[^${t}]*${t})*[^${t}]*$)`, "g"), yg = wg(), Cg = (a) => a && a.length > 1 && Sg.test(a) && a[0] === a[a.length - 1], Zl = (a) => a.replace(Sg, "$1"), Eg = (a, t = "'") => `${t}${a}${t}`, bg = (a, t = void 0, e = void 0) => {
let n = yg;
return t === void 0 && e === void 0 || (n = wg(t, e)), a.split(n);
}, vg = (a) => {
let t;
try {
t = new URL(a);
} catch {
return !1;
}
return (t.protocol === "http:" || t.protocol === "https:") && Ip.test(a);
}, Rp = new RegExp(/^[^\s@]+@[^\s@]+\.[^\s@]+$/i), xg = (a) => !!a.toLowerCase().startsWith("mailto:") || Rp.test(a), Ig = (a) => ((a >= 26 ? Ig((a / 26 | 0) - 1) : "") + "abcdefghijklmnopqrstuvwxyz"[a % 26 | 0]).toUpperCase(), py = Object.freeze(Object.defineProperty({ __proto__: null, DefaultUnQuoteRegEx: yg, camelToSnake: (a) => a && a.replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`), capitalize: Qr, clampString: _g, countDecimals: ei, findValidTextValue: fg, getBaseName: (a, t = !1) => {
if (!a || typeof a != "string") return "";
const e = a.split(/[\\/]/).pop() || "";
if (e === "") return "";
const n = th(e), r = n.length === 0 ? e : e.slice(0, e.length - n.length - 1);
return t ? Qr(r, !0) : r;
}, getFileNameExtension: th, isQuoted: Cg, isValidEmail: xg, isValidHttpUrl: vg, numberToAlphabet: Ig, quote: Eg, snakeToCamel: pg, splitUnquoted: bg, unquote: Zl }, Symbol.toStringTag, { value: "Module" })), Ap = (a, t, e, n = null) => {
const r = (t || 11 * dt.getDeviceScale()) / dt.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), d = Math.ceil(0.45 * r), u = Math.ceil(1.1 * r), g = Math.max(1, Math.ceil(0.08 * r));
return { width: i, lineHeight: l, baseline: c, lineGap: h, strikePosition: d, underlinePosition: u, 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 };
}, ue = {}, eh = (a, t) => {
let e = "normal";
return a && t ? e = "bold italic" : a ? e = "bold" : t && (e = "italic"), e;
}, nh = (a) => a.split(",").map((t) => {
const e = (t = t.trim()).indexOf(" ") >= 0, n = t.indexOf('"') >= 0 || t.indexOf("'") >= 0;
return e && !n && (t = `"${t}"`), t;
}).join(", "), rh = /* @__PURE__ */ new Map(), ya = /* @__PURE__ */ new Map();
let wn = null;
const Mp = (a, t, e, n = null) => {
const r = n?.letterSpacing || 0;
typeof window > "u" || ue.contextMeasure || (ue.canvasMeasure = document ? document.createElement("canvas") : null, ue.contextMeasure = ue.canvasMeasure.getContext("2d"), ue.contextMeasure.letterSpacing = `${r}px`, ue.contextMeasure.textRendering = "geometricPrecision", ue.contextMeasure.textBaseline = "alphabetic", ue.contextMeasure.textAlign = "left");
const o = e || "calibri", s = t || 11 * dt.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, C, y) => f + Math.round(100 * p) / 100 + _ + S + C + y)(a, s, o, i, l, r);
const m = rh.get(c);
if (m) return m;
}
if (wn && wn.text === a && wn.size === t && wn.family === e && wn.options?.isBold === n?.isBold && wn.options?.isItalic === n?.isItalic && wn.options?.letterSpacing === n?.letterSpacing) return wn.metrics;
let h = {};
const d = eh(i, l) + " " + k.roundAccurately(s, 2) + "px " + nh(o);
ue.contextMeasure ? (ue.contextMeasure.font = d, ue.contextMeasure.letterSpacing = `${n?.letterSpacing ?? 0}px`, h = ue.contextMeasure.measureText(a)) : h.width = a.length * k.roundAccurately(s / dt.getDeviceScale() * 0.6, 2);
let u = ya.get(d);
if (!u && 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 p = m.getBoundingClientRect(), _ = f.getBoundingClientRect();
document.body.removeChild(m), ue.contextMeasure.font = eh(i, l) + " " + k.roundAccurately(100, 2) + "px " + nh(o);
const S = ue.contextMeasure.measureText("M"), C = p.bottom - p.top, y = C - (S.fontBoundingBoxAscent + S.fontBoundingBoxDescent), E = S.fontBoundingBoxAscent + _.top, w = ue.contextMeasure.measureText("_"), b = E - w.actualBoundingBoxAscent, v = Math.max(1, Math.abs(w.actualBoundingBoxAscent + w.actualBoundingBoxDescent)), I = ue.contextMeasure.measureText("-"), x = k.roundAccurately(E - I.actualBoundingBoxAscent + Math.max(1, 0.05 * C, 0)), R = v, A = s / 100;
u = { lineHeight: Math.ceil(C * A), baseline: Math.ceil(E * A), lineGap: Math.ceil(y * A), strikePosition: Math.ceil(x * A), underlinePosition: Math.ceil(b * A), strikeThickness: Math.ceil(R * A), underlineThickness: Math.ceil(v * A) }, ue.contextMeasure.font = d, ya.set(d, u);
}
u || (u = { 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(d, u));
const g = { ...h, width: h.width, ...u };
return c !== null && rh.set(c, g), wn = { text: a, size: t, family: e, options: n, metrics: g }, g;
};
let Mr = null;
const Tp = () => {
if (Mr) return Mr;
try {
const a = document.createElement("canvas"), t = a.getContext && a.getContext("2d");
t && typeof t.fillText == "function" && (Mr = Mp);
} catch {
}
return Mr || (console.warn("⚠️ CanvasFontMeasurer not available, falling back to SimpleFontMeasurer"), Mr = Ap), Mr;
};
let ps = null;
var dt, yn;
(yn = dt || (dt = {})).Style = { Normal: "normal", Italic: "italic" }, yn.Scheme = { Major: "major", Minor: "minor", None: "none" }, yn.UnderlineStyle = { None: "none", Double: "double", DoubleAccounting: "doubleAccounting", Single: "single", SingleAccounting: "singleAccounting" }, yn.VerticalAlignment = { Baseline: "baseline", Sub: "sub", Super: "super" }, yn.setSharedMeasurer = (a) => {
ps = a;
}, yn.getSharedMeasurer = () => ps || (ps = Tp(), ps), yn.getDeviceScale = () => 96 / 72 * 1, yn.getPanoseFallback = (a) => {
const t = [], e = a.length;
for (let s = 0; s < e; s += 2) t.push(parseInt(a.substring(s, s + 2), 16));
const n = t[0], r = t[1], o = t[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";
}
}, yn.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 Np {
constructor(t) {
this._private = { input: t }, typeof t == "string" ? this._private.name = t : Object.assign(this._private, t);
}
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 Rg = ["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"], be = /* @__PURE__ */ new Map();
be.set(dt.GenericName.Serif, ["Tahoma"]), be.set(dt.GenericName.SanSerif, ["Calibri"]), be.set(dt.GenericName.MonoSpace, ["Courier New"]), be.set(dt.GenericName.Cursive, ["Comic Sans MS"]), be.set(dt.GenericName.Fantasy, ["Luminari"]), be.set(dt.GenericName.UISystem, ["Arial"]), be.set(dt.GenericName.UISerif, ["Tahoma"]), be.set(dt.GenericName.UISanSerif, ["Arial"]), be.set(dt.GenericName.UIMonoSpace, ["Courier New"]), be.set(dt.GenericName.UIRounded, ["Arial"]), be.set(dt.GenericName.Math, []), be.set(dt.GenericName.Emoji, []), be.set(dt.GenericName.Fangsong, []);
const Cl = /* @__PURE__ */ new Map();
let Ag = [];
tc(Rg);
const Fp = eval;
function tc(a) {
a || tc(Rg);
let t = [];
for (let e = 0; e < a.length; e++) {
let n = a[e];
typeof n == "string" && (n = new Np(n));
let r = !0;
const o = "document";
try {
r = Fp(`${o}.fonts.check('12px ${n.getFamily()}')`);
} catch {
}
const s = { fontRef: n, loaded: r };
t.push(s), Cl.set(n.getFamily(), s);
}
Ag = Object.freeze(t);
}
const Ca = /* @__PURE__ */ new Map(), _y = Object.freeze(Object.defineProperty({ __proto__: null, findBestMatch: (a, t) => {
const e = Ca.get(a);
if (e) return e.fontRef === null ? null : e;
let n = [a];
t.fallbacks && (n = n.concat(t.fallbacks));
let r = null;
for (let o = 0; !r && o < n.length; o++) {
let s = n[o];
if (r = Cl.get(s), !r) {
const i = be.get(s);
if (i) for (let l = 0; !r && l < i.length; l++) r = Cl.get(i[l]);
}
}
return r ? Ca.set(a, r) : Ca.set(a, { fontRef: null, loaded: !1 }), r;
}, getFontList: function() {
return Ag;
}, setFontList: tc }, Symbol.toStringTag, { value: "Module" })), oh = Object.freeze([8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 36, 48, 72]), Sy = Object.freeze(Object.defineProperty({ __proto__: null, DefaultFontSizes: oh, findNextFontSize: (a, t = !0, e = oh) => {
if (!e || e.length === 0) return a;
if (a === void 0) return e[0];
if (t && a >= e[e.length - 1] || !t && a <= e[0]) return a;
let n = k.findEqualOrGreater(e, a);
return t ? (e[n] === a && (n += 1), e[n] || (n -= 1), e[n]) : (n -= 1, e[n]);
} }, Symbol.toStringTag, { value: "Module" }));
class Hi {
constructor(t, e, n, r = null, o = null, s = null) {
this._private = { wrapped: !0, insets: Pi.EmptyRect, orientation: et.Orientation.Horizontal, autoFit: et.Autofit.None, fontScale: 1, vertical: !1, columnCount: 1, columnSpacing: 0, verticalAlignment: et.VerticalAlignment.Center, horizontalCentered: !1, lineReduction: 0, isSpaceFirstLastPara: !1, presetTextWarp: null, paragraphs: k.EmptyArray }, this._bounds = null, this._textBounds = null, this._lines = null, this._lastLayoutSize = void 0, this._lastLayout = void 0, this._private = Object.assign(this._private, t || {}), this._defaultFont = e, this._alignment = n, this._lines = r, this._bounds = Object.freeze(o), this._textBounds = Object.freeze(s);
}
visitParas(t) {
t?.visitTextFrame?.(this);
const e = this.paragraphs, n = e.length;
for (let r = 0; r < n; r++) {
const o = e[r];
t?.visitTextParagraph?.(o, r, n);
const s = o.runs, i = s.length;
for (let l = 0; l < i; l++) t?.visitTextRun?.(s[l], l, i);
}
}
visitLines(t) {
t?.visitTextFrame?.(this);
const e = this.lines, n = e.length;
for (let r = 0; r < n; r++) {
const o = e[r];
t?.visitTextLine?.(o, r, n);
const s = o.runs, i = s.length;
for (let l = 0; l < i; l++) t?.visitTextRun?.(s[l], l, i);
}
}
layout(t = null) {
return this._lastLayout && this._lastLayoutSize?.width === t?.width && this._lastLayoutSize?.height === t?.height || (this._lastLayout = Wp(this, this._defaultFont, this._alignment, t), this._lastLayoutSize = t), this._lastLayout;
}
clone(t) {
const e = t?.visitTextFrame?.(this), n = Object.assign(this._private, e || {});
return delete n.bounds, new Hi(n, this._defaultFont, this._alignment);
}
equals(t) {
return k.deepEqual(this._private, t._private);
}
createTemporaryTextFrame(t, e) {
return $i(t, this._defaultFont, this._alignment, e ?? this._private.wrapped);
}
get bounds() {
if (this._bounds === null) throw new Error(sh);
return this._bounds;
}
get textBounds() {
if (this._textBounds === null) throw new Error(sh);
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 sh = "bounds can not be used until layout";
class ih {
static {
this.NL = `
`;
}
static {
this.DefaultLineSpacing = 100;
}
static {
this.DefaultTabWidth = 72;
}
}
class Vi {
constructor(t) {
this._private = { defaultFontSize: 11, defaultTabSize: ih.DefaultTabWidth, tabOverrides: k.EmptyArray, spacingBefore: 0, spacingAfter: 0, lineSpacing: ih.DefaultLineSpacing, align: et.HorizontalAlignment.Left, endParagraphSize: 0, indentLevel: 0, leadingIndent: 0, hangingIndent: 0, rightMargin: 0, bullet: null }, this._private = Object.assign(this._private, t || {});
}
clone(t) {
const e = t?.visitTextParagraph?.(this, 0, 1), n = Object.assign(this._private, e || {});
return delete n.bounds, new Vi(n);
}
equals(t) {
return k.deepEqual(this._private, t._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 ji {
constructor(t, e = 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, ...t }, this._bounds = e;
}
clone(t) {
const e = t?.visitTextRun?.(this, 0, 1), n = Object.assign(this._private, e || {});
return delete n.bounds, new ji(n);
}
equals(t) {
return k.deepEqual(this._private, t._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 Mg {
constructor(t, e, n) {
this._private = {}, this._private = { bounds: t, baseline: e, 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 Tg(a) {
return a && a.__esModule && Object.prototype.hasOwnProperty.call(a, "default") ? a.default : a;
}
var ah, lh, ch, hh, dh, uh;
function kp() {
if (hh) return ch;
hh = 1;
const a = new Uint8Array(new Uint32Array([305419896]).buffer)[0] === 18, t = (e, n, r) => {
let o = e[n];
e[n] = e[r], e[r] = o;
};
return ch = { swap32LE: (e) => {
a && ((n) => {
const r = n.length;
for (let o = 0; o < r; o += 4) t(n, o, o + 3), t(n, o + 1, o + 2);
})(e);
} };
}
var Op = (function() {
if (uh) return dh;
uh = 1;
const a = (function() {
if (lh) return ah;
function e() {
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 e(), this.dtree = new e();
}
lh = 1;
var r = new e(), o = new e(), 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]), d = new e(), u = new Uint8Array(320);
function g(w, b, v, I) {
var x, R;
for (x = 0; x < v; ++x) w[x] = 0;
for (x = 0; x < 30 - v; ++x) w[x + v] = x / v | 0;
for (R = I, x = 0; x < 30; ++x) b[x] = R, R += 1 << w[x];
}
var m = new Uint16Array(16);
function f(w, b, v, I) {
var x, R;
for (x = 0; x < 16; ++x) w.table[x] = 0;
for (x = 0; x < I; ++x) w.table[b[v + x]]++;
for (w.table[0] = 0, R = 0, x = 0; x < 16; ++x) m[x] = R, R += w.table[x];
for (x = 0; x < I; ++x) b[v + x] && (w.trans[m[b[v + x]]++] = x);
}
function p(w) {
w.bitcount-- || (w.tag = w.source[w.sourceIndex++], w.bitcount = 7);
var b = 1 & w.tag;
return w.tag >>>= 1, b;
}
function _(w, b, v) {
if (!b) return v;
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 + v;
}
function S(w, b) {
for (; w.bitcount < 24; ) w.tag |= w.source[w.sourceIndex++] << w.bitcount, w.bitcount += 8;
var v = 0, I = 0, x = 0, R = w.tag;
do
I = 2 * I + (1 & R), R >>>= 1, ++x, v += b.table[x], I -= b.table[x];
while (I >= 0);
return w.tag = R, w.bitcount -= x, b.trans[v + I];
}
function C(w, b, v) {
var I, x, R, A, M, T;
for (I = _(w, 5, 257), x = _(w, 5, 1), R = _(w, 4, 4), A = 0; A < 19; ++A) u[A] = 0;
for (A = 0; A < R; ++A) {
var O = _(w, 3, 0);
u[h[A]] = O;
}
for (f(d, u, 0, 19), M = 0; M < I + x; ) {
var W = S(w, d);
switch (W) {
case 16:
var D = u[M - 1];
for (T = _(w, 2, 3); T; --T) u[M++] = D;
break;
case 17:
for (T = _(w, 3, 3); T; --T) u[M++] = 0;
break;
case 18:
for (T = _(w, 7, 11); T; --T) u[M++] = 0;
break;
default:
u[M++] = W;
}
}
f(b, u, 0, I), f(v, u, I, x);
}
function y(w, b, v) {
for (; ; ) {
var I, x, R, A, M = S(w, b);
if (M === 256) return 0;
if (M < 256) w.dest[w.destLen++] = M;
else for (I = _(w, s[M -= 257], i[M]), x = S(w, v), A = R = w.destLen - _(w, l[x], c[x]); A < R + I; ++A) w.dest[w.destLen++] = w.dest[A];
}
}
function E(w) {
for (var b, v; 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, v = b; v; --v) w.dest[w.destLen++] = w.source[w.sourceIndex++];
return w.bitcount = 0, 0;
}
return (function(w, b) {
var v;
for (v = 0; v < 7; ++v) w.table[v] = 0;
for (w.table[7] = 24, w.table[8] = 152, w.table[9] = 112, v = 0; v < 24; ++v) w.trans[v] = 256 + v;
for (v = 0; v < 144; ++v) w.trans[24 + v] = v;
for (v = 0; v < 8; ++v) w.trans[168 + v] = 280 + v;
for (v = 0; v < 112; ++v) w.trans[176 + v] = 144 + v;
for (v = 0; v < 5; ++v) b.table[v] = 0;
for (b.table[5] = 32, v = 0; v < 32; ++v) b.trans[v] = v;
})(r, o), g(s, i, 4, 3), g(l, c, 2, 1), s[28] = 0, i[28] = 258, ah = function(w, b) {
var v, I, x = new n(w, b);
do {
switch (v = p(x), _(x, 2, 0)) {
case 0:
I = E(x);
break;
case 1:
I = y(x, r, o);
break;
case 2:
C(x, x.ltree, x.dtree), I = y(x, x.ltree, x.dtree);
break;
default:
I = -3;
}
if (I !== 0) throw new Error("Data error");
} while (!v);
return x.destLen < x.dest.length ? typeof x.dest.slice == "function" ? x.dest.slice(0, x.destLen) : x.dest.subarray(0, x.destLen) : x.dest;
};
})(), { swap32LE: t } = kp();
return dh = class {
constructor(e) {
const n = typeof e.readUInt32BE == "function" && typeof e.slice == "function";
if (n || e instanceof Uint8Array) {
let r;
if (n) this.highStart = e.readUInt32LE(0), this.errorValue = e.readUInt32LE(4), r = e.readUInt32LE(8), e = e.slice(12);
else {
const o = new DataView(e.buffer);
this.highStart = o.getUint32(0, !0), this.errorValue = o.getUint32(4, !0), r = o.getUint32(8, !0), e = e.subarray(12);
}
e = a(e, new Uint8Array(r)), e = a(e, new Uint8Array(r)), t(e), this.data = new Uint32Array(e.buffer);
} else ({ data: this.data, highStart: this.highStart, errorValue: this.errorValue } = e);
}
get(e) {
let n;
return e < 0 || e > 1114111 ? this.errorValue : e < 55296 || e > 56319 && e <= 65535 ? (n = (this.data[e >> 5] << 2) + (31 & e), this.data[n]) : e <= 65535 ? (n = (this.data[2048 + (e - 55296 >> 5)] << 2) + (31 & e), this.data[n]) : e < this.highStart ? (n = this.data[2080 + (e >> 11)], n = this.data[n + (e >> 5 & 63)], n = (n << 2) + (31 & e), this.data[n]) : this.data[this.data.length - 4];
}
};
})();
const Dp = Tg(Op);
var gh, mh = {}, Lp = (gh || (gh = 1, (function(a) {
var t = typeof Uint8Array < "u" ? Uint8Array : Array, e = 43, n = 47, r = 48, o = 97, s = 65, i = 45, l = 95;
function c(h) {
var d = h.charCodeAt(0);
return d === e || d === i ? 62 : d === n || d === l ? 63 : d < r ? -1 : d < r + 10 ? d - r + 26 + 26 : d < s + 26 ? d - s : d < o + 26 ? d - o + 26 : void 0;
}
a.toByteArray = function(h) {
var d, u, g, m, f, p;
if (h.length % 4 > 0) throw new Error("Invalid string. Length must be a multiple of 4");
var _ = h.length;
f = h.charAt(_ - 2) === "=" ? 2 : h.charAt(_ - 1) === "=" ? 1 : 0, p = new t(3 * h.length / 4 - f), g = f > 0 ? h.length - 4 : h.length;
var S = 0;
function C(y) {
p[S++] = y;
}
for (d = 0, u = 0; d < g; d += 4, u += 3) C((16711680 & (m = c(h.charAt(d)) << 18 | c(h.charAt(d + 1)) << 12 | c(h.charAt(d + 2)) << 6 | c(h.charAt(d + 3)))) >> 16), C((65280 & m) >> 8), C(255 & m);
return f === 2 ? C(255 & (m = c(h.charAt(d)) << 2 | c(h.charAt(d + 1)) >> 4)) : f === 1 && (C((m = c(h.charAt(d)) << 10 | c(h.charAt(d + 1)) << 4 | c(h.charAt(d + 2)) >> 2) >> 8 & 255), C(255 & m)), p;
}, a.fromByteArray = function(h) {
var d, u, g, m = h.length % 3, f = "";
function p(S) {
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(S);
}
function _(S) {
return p(S >> 18 & 63) + p(S >> 12 & 63) + p(S >> 6 & 63) + p(63 & S);
}
for (d = 0, g = h.length - m; d < g; d += 3) f += _(u = (h[d] << 16) + (h[d + 1] << 8) + h[d + 2]);
switch (m) {
case 1:
f += p((u = h[h.length - 1]) >> 2), f += p(u << 4 & 63), f += "==";
break;
case 2:
f += p((u = (h[h.length - 2] << 8) + h[h.length - 1]) >> 10), f += p(u >> 4 & 63), f += p(u << 2 & 63), f += "=";
}
return f;
};
})(mh)), mh), El = {};
const Bp = [[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]], zp = new Dp(Tg(Lp).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/")), fh = function(a) {
switch (a) {
case 33:
case 39:
case 40:
case 42:
return 12;
case 35:
return 5;
default:
return a;
}
}, ph = function(a) {
switch (a) {
case 37:
case 38:
return 34;
case 41:
return 22;
default:
return a;
}
};
class Ea {
constructor(t, e = !1) {
this.position = t, this.required = e;
}
}
El = class {
nextCodePoint() {
const a = this.string.charCodeAt(this.pos++), t = this.string.charCodeAt(this.pos);
return 55296 <= a && a <= 56319 && 56320 <= t && t <= 57343 ? (this.pos++, 1024 * (a - 55296) + (t - 56320) + 65536) : a;
}
nextCharClass() {
return fh(zp.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 t = !1;
switch (Bp[this.curClass][this.nextClass]) {
case 0:
t = !0;
break;
case 1:
t = a === 41;
break;
case 2:
if (t = a === 41, !t) return t = !1, t;
break;
case 3:
if (a !== 41) return t;
}
return this.LB8a && (t = !1), !this.LB21a || this.curClass !== 16 && this.curClass !== 17 ? this.LB21a = this.curClass === 13 : (t = !1, this.LB21a = !1), this.curClass === 28 ? (this.LB30a++, this.LB30a == 2 && this.nextClass === 28 && (t = !0, this.LB30a = 0)) : this.LB30a = 0, this.curClass = this.nextClass, t;
}
nextBreak() {
if (this.curClass == null) {
let a = this.nextCharClass();
this.curClass = ph(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 = ph(fh(this.nextClass)), new Ea(this.lastPos, !0);
let t = this.getSimpleBreak();
if (t === null && (t = this.getPairTableBreak(a)), this.LB8a = this.nextClass === 31, t) return new Ea(this.lastPos);
}
return this.lastPos < this.string.length ? (this.lastPos = this.string.length, new Ea(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 Pp {
constructor(t) {
this._textMeasurer = t;
}
_measureText(t) {
const e = this._fontSize, n = this._fontName, r = this._metricOptions;
if (this._isSuperSub) {
const o = this._textMeasurer(t, 0.6 * e, n, r);
return { ...this._textMeasurer("M", e, n, r), width: o.width };
}
return this._textMeasurer(t, e, n, r);
}
_breakWord(t, e, n) {
let r = 0;
for (; r < t.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 = t.substring(r, r + i + 1), h = c.replace(/\s+$/, ""), d = this._measureText(h);
let u = d;
c.length !== h.length && (u = this._measureText(c)), (o.x + d.width <= l || c.length <= 1) && (o.text = c, o.width = d.width, o.widthWhitespace = u.width, o.height = Math.max(o.height, d.lineHeight), o.baseline = Math.max(o.baseline, d.baseline), s = !0, i++);
} while (s && r + i < t.length);
if (s) {
const c = t.substring(r, t.length), h = c.replace(/\s+$/, ""), d = this._measureText(h);
let u = d;
c.length !== h.length && (u = this._measureText(c)), e.startPosition = this._charactersRead + r, e.width = d.width, o.widthWhitespace = u.width, e.height = Math.max(e.height, d.lineHeight), e.baseline = Math.max(e.baseline, d.baseline), e.text = c;
} else if (n?.(o) === !1) return !1;
r += i;
}
}
_breakWhiteSpace(t, e = null) {
for (; t && this._charactersRead < t.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 = t.substring(n.startPosition, this._lastBreak.position), h = c.replace(/\s+$/, ""), d = this._measureText(h);
let u = d;
c.length !== h.length && (u = this._measureText(c)), n.x + d.width <= o ? (n.text = c, n.width = d.width, n.widthWhitespace = u.width, n.height = Math.max(n.height, d.lineHeight), n.baseline = Math.max(n.baseline, d.baseline), r = !0, this._charactersRead = this._lastBreak.position) : n.text.length === 0 && this._breakWord(c, n, e) !== !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 (e?.(n) === !1) return !1;
}
}
wrap(t, e = null) {
this._breaker = new El(t), this._linesRead = [], this._charactersRead = 0, this._maxXRead = 0, this._maxXWhitespaceRead = 0, this._maxYRead = 0, this._fontName = e?.fontName ?? "Arial", this._fontSize = e?.fontSize ?? 12, this._metricOptions = { isBold: e?.bold ?? !1, isItalic: e?.italic ?? !1, letterSpacing: e?.letterSpacing ?? 0 }, this._isSuperSub = e?.superSub ?? !1, this._indent = e?.indent ?? 0, this._maxWidth = e?.maxWidth ?? Number.MAX_SAFE_INTEGER, this._maxWidth <= 0 && (this._maxWidth = Number.MAX_SAFE_INTEGER), this._maxHeight = e?.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 (t === "") {
const o = this._measureText(t);
n({ startPosition: 0, text: "", x: 0, y: 0, width: 0, widthWhitespace: 0, height: o.lineHeight, baseline: o.baseline });
} else if (this._breakWhiteSpace(t, n), new El(t.charAt(t.length - 1).repeat(2)).nextBreak().required) {
const o = this._measureText(t);
n({ startPosition: t.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 Wp = (a, t, e, n = null, r = dt.getSharedMeasurer()) => {
let o = "", s = null, i = null;
const l = a.paragraphs, c = l.length;
for (let y = 0; y < c; y++) {
const E = l[y].runs, w = E.length;
for (let b = 0; b < w; b++) o += E[b].text, b === 0 && (s = E[b]);
y === 0 && (i = l[y]);
}
const h = a.insets ?? Pi.EmptyRect, d = new Pp(r), u = n?.width ? n.width - h.right - h.left : n?.width, g = n?.height ? n.height - h.bottom - h.top : null, m = d.wrap(o, { fontName: s.fontName, fontSize: s.fontSize * dt.getDeviceScale(), bold: s.bold, italic: s.italic, superSub: s.superSub, letterSpacing: s.letterSpacing, maxWidth: a.wrapped && u ? u : null, maxHeight: g });
let f = [];
const p = m.lines, _ = p.length, S = new Array(_);
for (let y = 0; y < _; y++) {
const E = p[y], w = { x: E.x, y: E.y, width: E.width, height: E.height }, b = new ji({ text: E.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 Mg(w, E.baseline, [b]);
}
const C = new Vi({ runs: f, align: i.align });
return new Hi({ paragraphs: [C], wrapped: a.wrapped, verticalAlignment: a.verticalAlignment }, t, e, 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 });
}, _h = (a) => {
let t = !1, e = !1;
for (let n = 0; n < a.length; n++) {
const r = a.charCodeAt(n);
if (r >= 65 && r <= 90 ? t = !0 : r >= 97 && r <= 122 && (e = !0), t && e) return 0;
}
return t ? 1 : e ? -1 : 0;
}, $i = (a, t, e, n, r = !1) => {
if (a == null) return null;
const o = new ji({ text: a, fontName: t.toCSS().fontFamily, fontSize: t.getSize(), bold: t.getWeight() > 400, italic: t.getStyle() === dt.Style.Italic, superSub: !r && (t.getVerticalAlignment() === dt.VerticalAlignment.Sub || t.getVerticalAlignment() === dt.VerticalAlignment.Super), letterSpacing: t.getLetterSpacing() }), s = r ? et.HorizontalAlignment.Left : e.getHorizontal(), i = e.getVertical(), l = new Vi({ runs: [o], align: s });
let c = [];
return c.push(new Mg(null, t.getSize(), [o])), new Hi({ paragraphs: [l], wrapped: n && (e.getOverflow() === et.Overflow.Wrap || s === et.HorizontalAlignment.Justify || s === et.HorizontalAlignment.Distributed || i === et.VerticalAlignment.Justify || i === et.VerticalAlignment.Distributed), verticalAlignment: i }, t, e, c);
}, _s = (a, t, e, n) => ({ x: a * n - t * e, y: a * e + t * n }), Sh = (a) => {
let t = 0, e = 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) || (t += s, e += i, r += s * s, n += s * i, o++);
const c = (o * n - t * e) / (o * r - t * t);
return { m: c, b: e / o - c * t / o };
}, bl = (a, t) => {
if (t === null) return null;
const e = k.isObject(t);
return a != null && e ? k.mergeContentful(a, t) : e ? k.cloneObject(t) : t;
}, Hp = (a, t, e) => a == null || typeof a == "object" && Object.keys(a).length === 0;
function ec(a, t, e, n) {
if (a === t) return a ?? null;
}
function Vp(a) {
return a == null;
}
function jp(a, t, e = 1, n) {
if (e === 0) return { preceding: a ? [...a] : [], modified: [], trailing: [] };
const r = (function(l, c, h = 1) {
let d = k.findEqualOrGreater(l, c, (f) => f.max);
const u = l.slice(0, d), g = [], m = [];
if (!l[d]) return { preceding: u, modified: g, trailing: m };
for (let f = d; 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: u, modified: g, trailing: m };
})(a, t, e), 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: wr(i, { onMerge: ec }).modified, trailing: s };
}
function wh(a, t, e) {
if (!a) throw new Error("runs can not be null");
if (!t) return { preceding: [], modified: a ? [...a] : [], trailing: [] };
const n = (function(s, i, l, c, h = !1) {
if (!i) return { preceding: [], modified: s ? [...s] : [], trailing: [] };
let d, u = k.findEqualOrGreater(s, i.min, (S) => S.max), g = s.slice(0, u), m = s.slice(u), f = [], p = { ...i }, _ = m[0] || { min: i.min, max: i.max, value: void 0 };
for (d = h ? (S, C, y) => {
const E = (c || bl)(C, y, S);
E !== void 0 ? S.value = E : delete S.value, f.push(S);
} : (S, C, y) => {
let E = (c || bl)(C ?? null, y, S);
E !== void 0 ? S.value = E : delete S.value, f.push(S);
}; m.length >= 0 && p.max - p.min >= 0; ) {
if (p.min < _.min) d({ min: p.min, max: Math.min(p.max, _.min - 1) }, void 0, p.value), p = { min: _.min, max: p.max, value: p.value }, _ = { min: p.min, max: _.max, value: _.value };
else if (p.min > _.min) {
const S = _.value !== void 0 && l ? l(_, p.min) : [_.value, _.value];
f.push({ min: _.min, max: Math.min(p.min, _.max) - 1, value: S[0] }), p = { min: Math.min(p.min, _.max), max: p.max, value: p.value }, _ = { min: p.min, max: _.max, value: S[1] };
} else {
const S = _.value !== void 0 && l ? l(_, p.min) : [_.value, _.value];
d({ min: _.min, max: Math.min(p.max, _.max) }, S[0], p.value), p = { min: Math.min(p.max, _.max) + 1, max: p.max, value: p.value }, _ = { min: Math.min(p.max, _.max) + 1, max: _.max, value: S[1] };
}
_.min <= _.max ? m[0] = _ : (m = m.slice(1), _ = m[0] || { min: _.min, max: p.max });
}
return { preceding: g, modified: f, trailing: m };
})(a, t, e?.onSplit, e?.onUpdate, e?.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 ?? Vp;
let d = s.slice(0, l), u = 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: d, modified: g, trailing: u };
})(wr(r, { onMerge: e?.onMerge ?? ec }).modified, { cull: e?.isCull || Hp });
return { preceding: n.preceding, modified: o.modified, trailing: n.trailing };
}
function bn(a) {
return [...a.preceding, ...a.modified, ...a.trailing];
}
function wr(a, t) {
if (!a || a.length === 0) return { preceding: [], modified: a ? [...a] : [], trailing: [] };
const e = Math.min(a.length - 1, t?.startOffset ?? 0), n = Math.min(a.length, t?.endOffset ?? a.length), r = t?.onMerge ?? ec;
let o = a.slice(0, e), s = a.slice(n);
const i = [];
let l = { ...a[e] }, c = a[e]?.max || 0;
for (let h = e + 1; h <= n; h++) {
const d = a[h];
let u = !1;
if (d && d.min <= a[h - 1].max + 1) if (l.value === void 0 && d.value === void 0) u = !0;
else {
const g = r(l.value, d.value, l.max - l.min + 1, d.max - d.min + 1);
g !== void 0 && (u = !0, l.value = g);
}
u ? l.max = Math.max(c, d.max) : (i.push(l), l = { ...a[h] }, d && (l.max = Math.max(c, d.max))), l && (c = l.max);
}
return { preceding: o, modified: i, trailing: s };
}
function yh(a) {
return a && a.sort((t, e) => {
let n = t.min - e.min;
return n === 0 && (n = t.max - e.max), n;
});
}
const Ch = (a, t = !1) => {
if (!a || a.length === 0) return k.EmptyArray;
const e = t ? a : a.sort(), n = [];
let r = null;
for (let o = 0; o < e.length; o++) {
const s = e[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;
}, Eh = (a, t) => a ? t ? a || t ? a.min > t.max || a.max < t.min ? null : { min: Math.max(a.min, t.min), max: Math.min(a.max, t.max) } : null : { ...a } : { ...t }, Ng = (a) => {
const t = a.length === 0;
return { runs: a, run: { min: t ? Number.MIN_SAFE_INTEGER : Number.MAX_SAFE_INTEGER, max: t ? Number.MAX_SAFE_INTEGER : Number.MIN_SAFE_INTEGER, value: null }, index: Number.MAX_SAFE_INTEGER };
}, Fg = (a, t) => {
const e = t.run, n = e.min, r = e.max;
if (a >= n && a <= r) return e.value;
let o = t.index;
const s = t.runs;
if (o < s.length - 1 && a > r) {
o++;
const h = s[o], d = h.min, u = h.max;
if (a >= d && a <= u) return t.index = o, e.min = d, e.max = u, e.value = h.value, e.value;
}
if (o !== Number.MAX_SAFE_INTEGER && o > 0 && a < n) {
o--;
const h = s[o], d = h.min, u = h.max;
if (a >= d && a <= u) return t.index = o, e.min = d, e.max = u, e.value = h.value, e.value;
}
if (o = k.findEqualOrGreater(s, a, (h) => h.max), o === s.length) return o = s.length, t.index = o, e.min = s[o - 1].max + 1, e.max = Number.MAX_SAFE_INTEGER, e.value = null, null;
const i = s[o], l = i.min, c = i.max;
if (a >= l && a <= c) {
t.index = o, e.min = l, e.max = c;
const h = i.value;
return e.value = h, h;
}
return o--, t.index = o, e.min = o >= 0 ? s[o].max + 1 : Number.MIN_SAFE_INTEGER, e.max = l - 1, e.value = null, null;
}, kg = function(a, t, e, n) {
if (a.length === 0) {
if (e != null || n != null) {
const c = t({ min: e ?? n, max: n ?? e });
if (c && c.break) return c;
}
return;
}
const r = e ?? a[0].min, o = n ?? a[a.length - 1].max;
let s = r - 1, i = k.findEqualOrGreater(a, r, (c) => c.max), l = a[i];
for (; l && l.min <= o; ) {
if (s < l.min - 1) {
const h = t({ min: Math.max(s + 1, r), max: Math.min(l.min - 1, o) });
if (h && h.break) return h;
}
const c = t({ ...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 = t({ min: Math.min(s + 1, o), max: o });
if (c && c.break) return c;
}
}, bh = new RegExp("([0-9]+)$");
var vi, vh, st, Ss, N, ws;
((a) => {
a.Date = class {
constructor(i) {
this._options = i;
}
canFill(i, l) {
return ro(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((C, y) => C.getTime() - y.getTime()));
let p = !1, _ = -1, S = -1;
for (let C = 0; C < f.length; C++) {
let y = f[C];
if (C > f.length - 1 && y.getTime() < f[C + 1].getTime()) throw new Error("Dates are expected to be sorted.");
let E = 12 * y.getFullYear() + y.getMonth();
if (E === S) return fs;
S = E;
let w = y.getFullYear();
w > _ ? _ = w : p = !0;
}
return p ? Kc : Xc;
})(i));
const d = Yc(i[0], 0, h);
d.setHours(0, 0, 0, 0);
let u = 1;
l?.reverse && (u *= -1, c *= -1);
for (let g = 1; g < i.length; g++) {
let m = Sp(i[g - 1], i[g], h);
if (g === 1) u = m;
else if (m !== u) return null;
}
return i.length === 1 && l.multiFill, (g) => {
const m = Yc(d, u * g, h);
if (c !== 0) {
const f = 0 + c * g, p = f % 1440, _ = Math.floor(p / 60), S = p % 60;
m.setHours(_, S, 0, 0);
const C = Math.floor(f / 1440), y = Math.floor(C / 365), E = C % 365, w = Math.floor(E / 30), b = E % 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 = Sh(i), h = c.b;
let d = c.m;
return i.length === 1 ? (l.reverse && (d = -d), l.multiFill ? (u) => u * d + h : null) : (u) => d * (u + 1) + h;
}
};
const t = { value: null, template: null }, e = { sensitivity: "accent" };
a.Ordinal = class {
_template(i) {
const l = i.match(bh);
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 t.value = null, !1;
const c = this._template(i);
return c && (l === void 0 || l === t.value && c.localeCompare(t.template, void 0, e) === 0) ? (t.value = i, t.template = c, !0) : (t.value = null, !1);
}
createFillAt(i, l) {
const c = [], h = i[0];
let d = null, u = null, g = 0;
if (h) {
const S = h.match(bh);
if (S) {
d = S[1], d.startsWith("0") && (g = d.length);
const C = h.lastIndexOf(d);
u = h.substring(0, C);
}
}
const m = i.length;
for (let S = 0; S < m; S++) {
const C = i[S];
let y = null;
if (C) {
const E = C.substring(u.length, C.length);
E.startsWith("0") && (g = Math.max(g, E.length));
const w = parseFloat(E);
isNaN(w) || (y = w);
}
c.push(y);
}
const f = Sh(c), p = f.b;
let _ = f.m;
return _ !== 0 && Number.isInteger(_) ? (S) => {
if (i[S % m] === null) return null;
const C = (m === 1 ? l.reverse ? -S : S : _ * (S + 1)) + p, y = "" + Math.abs(C), E = "0".repeat(Math.max(0, g - y.length)) + y;
return u + E;
} : 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 d = i.customLists;
for (let u = d.length - 1; u > 0; u--) l.push(d[u]);
}
l.push(s), l.push(o), l.push(r), l.push(n);
const c = this._map, h = [];
for (let d = 0; d < l.length; d++) {
const u = l[d], g = [];
h.push(g);
for (let m = 0; m < u.length; m++) {
const f = u[m], p = Qr(f, !0), _ = p.toLowerCase().trim();
let S = c.get(_);
S || (S = [], c.set(_, S));
const C = { value: p, asKey: _, major: d, minor: m };
S.push(C), g.push(C);
}
}
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 d = this._map.get(c[0]);
let u;
const g = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Set();
for (let x = 0; x < d.length; x++) {
const R = d[x];
g.set(R.major, R);
}
if (i.length > 1) {
for (let x = 1; x < i.length; x++) {
const R = i[x].toLowerCase().trim(), A = this._map.get(R);
if (!A) return null;
x === 1 && (u = 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 p = this._lists;
for (let x = 0; !f && x < p.length; x++) (i.length === 1 || m.has(x)) && (f = g.get(x));
if (!f) return null;
let _ = null;
for (let x = 0; !_ && u && x < u.length; x++) u[x].asKey === c[1] && (_ = u[x]);
let S = !1, C = !1;
const y = _h(h);
y === 1 ? S = !0 : (y === -1 || _h(h[0]) === -1) && (C = !0);
const E = p[f.major];
let w = f.minor, b = 1;
if (c.length > 1) {
b = _.minor - f.minor;
for (let x = 2; x < c.length; x++) if (E[x + w].minor - E[x - 1 + w].minor !== b) return null;
}
i.length === 1 && l?.reverse && (b = -b);
const v = i.length, I = E.length;
return (x) => {
if (i[x % v] === null) return null;
let R = (x * b + w) % I;
R < 0 && (R = I + R);
const A = E[R].value ?? null;
return S ? A.toUpperCase() : C ? 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 d = 0, u = !1;
for (let b = 0; !u && b <= h; b++) i[b] === null ? d++ : u = !0;
let g = 0;
u = !1;
for (let b = h - 1; !u && b >= d; b--) i[b] === null ? g++ : u = !0;
const m = [];
let f = null, p = null, _ = [], S = d, C = 0;
const y = (b) => {
if (f && f.max + 1 === S) {
const v = f.value;
v.fillAt.push(b), f.max = S, v.length++, v.valuesLength++;
} else f = { min: S, max: S, value: { fillAt: [b], start: S, length: 1, valuesLength: h, blankInterval: 0 } };
m.push(f);
}, E = h - g;
for (S = d; S < E; ) {
let b = i[S];
if (b === null) {
S++;
continue;
}
p = null;
let v, I = 1, x = !1;
for (let T = 0; !x && T < c.length + 1; T++) {
const O = c[T];
O && (x = O.canFill(b, v), x && (p = O));
}
if (!p) {
b !== null && y(b), S++;
continue;
}
let R = 0;
C = 0, v = b;
do
b = i[S + I], x = p.canFill(b, v), x && (b !== null ? (v = b, R > 0 && (I - R === 1 ? C = R : R !== C && (C = 0)), R = 0) : R++, I++);
while (x && S + I < E);
_ = [i[S]];
const A = 1 + C, M = I - R;
for (let T = A; T < M; T += A) _.push(i[S + T]);
if (_.length > 0) {
const T = _.length, O = T + (T - 1) * C, W = p.createFillAt?.(_, l) ?? _;
m.push({ min: S, max: S + O - 1, value: { fillAt: W, start: S, length: O, valuesLength: T, blankInterval: C } });
}
S += I;
}
const w = Ng(m);
return (b) => {
const v = b >= 0, I = Math.abs(b), x = Fg(I % h, w);
if (!x) return null;
const R = Math.floor(I / h), A = x.length, M = x.start, T = (R + (v ? 1 : 0)) * M + (R + (v ? 0 : 1)) * (h - (M + A));
let O = b + (v ? -T : T);
const W = x.blankInterval;
if (W !== 0) {
let z = O % A;
if (z % (1 + W) !== 0) return null;
O = Math.floor(z / (1 + W)) + x.valuesLength * R;
}
const D = x.fillAt;
return typeof D == "function" ? D(O) : D[O % D.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: Kc }), DateYears: new a.Date({ unit: Xc }), Copy: new a.Copy() }, a.fillTo = (i, l, c, h) => {
const d = [], u = l.length, g = i.createFillAt(l, h);
for (let m = u; m < c; m++) d.push(g(m));
return d;
};
})(vi || (vi = {})), vh || (vh = {}), (Ss = st || (st = {})).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 xh = [[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]], $p = new class {
constructor() {
this._lookupByName = /* @__PURE__ */ new Map();
for (let a = 0; a < xh.length; a++) {
const t = xh[a], e = t[0], n = (e >> 24 & 255) / 255, r = e >> 16 & 255, o = e >> 8 & 255, s = 255 & e, i = { id: t[1], name: t[2], rgbaColor: { r, g: o, b: s, a: n }, system: t.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" }], Og = /* @__PURE__ */ new Map();
for (let a = 0; a < ba.length; a++) Og.set(ba[a].scheme.toLowerCase(), ba[a]);
const Ih = (a) => a ? { srgb: [a.red / 255, a.green / 255, a.blue / 255], alpha: a.alpha !== void 0 ? a.alpha : 1 } : null, Rh = function(a, t, e, n) {
let r = Ih(((c) => {
let h = $p.valueOfName(c);
return h ? new In.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, Og.get(l.toLowerCase()))) {
if (!t) throw new Error("a scheme val was used but a schemeLookup was not provided");
o = a, s = t(o), r = Ih(s), i = N.Type.Scheme;
}
var l;
if (r === null) {
let c = a.match($f) || a.match(Gf);
if (c) {
let h, d = 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)], d = Pr(parseInt(c[1], 16) / 255)), h = ua(h), h = pe(h), r = { srgb: h, alpha: d }, i = N.Type.Hex;
}
}
if (r === null) {
let c = a.match(zf) || a.match(Pf);
if (c) {
let h = da(c[1], c[2], c[3]);
h = ua(h), h = pe(h), r = { srgb: h, alpha: c[4] ? Pr(parseFloat(c[4])) : 1 }, i = N.Type.RGB;
}
}
if (r === null) {
let c = a.match(Wf) || a.match(Hf);
if (c) {
let h = da(c[1], c[2], c[3]);
h = ua(h, 100), h = yr(h), h = pe(h), r = { srgb: h, alpha: c[4] ? Pr(parseFloat(c[4])) : 1 }, i = N.Type.LRGB;
}
}
if (r === null) {
let c = a.match(Vf) || a.match(jf);
if (c) {
let h = da(c[1], c[2], c[3]);
h = Cr(h), h = pe(h), r = { srgb: h, alpha: c[4] ? Pr(parseFloat(c[4])) : 1 }, i = N.Type.HSL;
}
}
if (r === null) {
let c = a.match(Uf);
if (c) {
const h = parseInt(c[1]);
let d = e?.(h) ?? Ei(h);
d && (r = { srgb: [d.red / 255, d.green / 255, d.blue / 255], alpha: d.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 };
}, vl = /* @__PURE__ */ new Map(), Dg = Object.keys(N.AdjustmentType), Gp = Dg.length;
for (let a = 0; a < Gp; a++) {
const t = Dg[a];
vl.set(N.AdjustmentType[t].toLowerCase(), N.AdjustmentType[t]);
}
const Ah = new RegExp("\\s+\\s*(?![^()]*\\))|,\\s*(?![^()]*\\))"), Mh = new RegExp("\\s*[,]\\s*|\\s+");
let va = null;
const Th = { [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 ae {
constructor(t, e, n, r = null) {
let o = null, s = null;
if (t instanceof ae) o = t.getVal(), t.getAdjustments() && (s = [...t.getAdjustments()]);
else if (typeof t == "string") {
const i = this._parse(t);
o = i.val, s = i.adjs;
} else t?.val && (o = t.val, s = t.adjs);
if (!o) throw new Error("Unable to determine color value");
this._private = { val: o, adjs: s, schemeLookup: e, indexedLookup: n, parsedVal: Rh(o, e, n), adjusted: null, resolved: null };
}
_parse(t) {
let e = null, n = t.toLowerCase().trim();
const r = n.split(Ah);
if (r && (e = r[0], n = n.substring(e.length, n.length).trim()), !e) throw new Error("no color key found");
const o = [], s = n.split(Mh), i = s.length;
for (let l = 0; l < i; l++) {
const c = s[l];
if (!c) continue;
const h = vl.get(c.toLowerCase());
if (!h) throw new Error("Invalid adjustment type:" + c);
let d = null;
if (!(h === N.AdjustmentType.Gray || h === N.AdjustmentType.Comp || h === N.AdjustmentType.Inv || h === N.AdjustmentType.Gamma || h === N.AdjustmentType.InvGamma)) {
l++;
const u = s[l];
if (d = parseFloat(u), d == null) throw new Error(`Invalid adjustment value: missing value for'${c}'`);
if (isNaN(d)) throw new Error("Invalid adjustment value:" + u);
}
o.push({ [h]: d });
}
return { val: e, adjs: o };
}
_forceDark(t = !0) {
this._resolve();
const e = this._private.resolved;
let n = [e.red, e.green, e.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), d = Math.sin(l * Math.PI / 180);
c[0] = Rr + 0.7874 * h - Rr * d, c[1] = zn - zn * h - zn * d, c[2] = Ar - Ar * h + 0.9278 * d, c[3] = Rr - Rr * h + 0.143 * d, c[4] = zn + (1 - zn) * h + 0.14 * d, c[5] = Ar - Ar * h - 0.283 * d, c[6] = Rr - Rr * h - 0.7874 * d, c[7] = zn - zn * h + zn * d, c[8] = Ar + 0.9278 * h + Ar * d;
const u = (p) => Math.round(Math.max(0, Math.min(255, p))), g = i[0], m = i[1], f = i[2];
return [u(c[0] * g + c[1] * m + c[2] * f), u(c[3] * g + c[4] * m + c[5] * f), u(c[6] * g + c[7] * m + c[8] * f)];
})(n, 180), n = jc(n, !1);
let r = Sr(n);
const o = Zn(r);
if (o[mo] = 0.95 * o[mo], r = Cr(o), n = yr(r), n = Vc(n), n = pe(n, !1), t) return new In.RGBA(n[0], n[1], n[2], e.alpha);
const s = Zn(Sr(n));
return new In.HSLA(s[0], s[1], s[2], e.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 t = Rh(this._private.val, this._private.schemeLookup, this._private.indexedLookup, this._private.last);
let e = ((o, s) => {
let i = [...o.srgb], l = o.alpha !== void 0 ? o.alpha : 1;
const c = s ? s.length : 0;
for (var h = 0; h < c; h++) {
const d = s[h], u = Object.keys(d)[0], g = d[u];
u === N.AdjustmentType.Alpha ? (l = g / 100, l = Math.max(0, Math.min(1, l))) : u === N.AdjustmentType.AlphaOff ? (l += g / 100, l = Math.max(0, Math.min(1, l))) : u === N.AdjustmentType.AlphaMod ? (l *= g / 100, l = Math.max(0, Math.min(1, l))) : u === N.AdjustmentType.Hue ? i = fa(fe, i, g) : u === N.AdjustmentType.Sat ? i = fa(ma, i, g) : u === N.AdjustmentType.Lum ? i = fa(mo, i, g) : u === N.AdjustmentType.HueOff ? i = pa(fe, i, g) : u === N.AdjustmentType.SatOff ? i = pa(ma, i, g) : u === N.AdjustmentType.LumOff ? i = pa(mo, i, g) : u === N.AdjustmentType.HueMod ? i = _a(fe, i, g) : u === N.AdjustmentType.SatMod ? i = _a(ma, i, g) : u === N.AdjustmentType.LumMod ? i = _a(mo, i, g) : u === N.AdjustmentType.Red ? i = pn(Js, i, g, Ys) : u === N.AdjustmentType.Green ? i = pn(Ks, i, g, Ys) : u === N.AdjustmentType.Blue ? i = pn(Xs, i, g, Ys) : u === N.AdjustmentType.RedOff ? i = pn(Js, i, g, Qs) : u === N.AdjustmentType.GreenOff ? i = pn(Ks, i, g, Qs) : u === N.AdjustmentType.BlueOff ? i = pn(Xs, i, g, Qs) : u === N.AdjustmentType.RedMod ? i = pn(Js, i, g, Zs) : u === N.AdjustmentType.GreenMod ? i = pn(Ks, i, g, Zs) : u === N.AdjustmentType.BlueMod ? i = pn(Xs, i, g, Zs) : u === N.AdjustmentType.Shade ? i = qf(i, g) : u === N.AdjustmentType.Tint ? i = Kf(i, g) : u === N.AdjustmentType.ETint ? i = Jf(i, g) : u === N.AdjustmentType.Gray ? i = Xf(i) : u === N.AdjustmentType.Comp ? i = Yf(i) : u === N.AdjustmentType.Inv ? i = jc(i, g) : u === N.AdjustmentType.Gamma ? i = Qf(i) : u === N.AdjustmentType.InvGamma ? i = Zf(i) : console.warn("unknown adjustmentType: " + u);
}
return { srgb: i, alpha: l };
})(t.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;
})(e.srgb);
n = Vc(n);
let r = Pr(e.alpha);
this._private.adjusted = e, this._private.parsedVal = t, this._private.resolved = new In.RGBA(n[0], n[1], n[2], r);
}
static parse(t, e, n, r = null) {
if (t instanceof ae) return t;
const o = t;
let s = null, i = o?.trim(), l = null;
try {
if (!s) {
const u = i?.split(Ah);
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(Mh), d = h.length;
for (let u = 0; u < d; u++) {
const g = h[u];
if (!g) continue;
const m = vl.get(g.toLowerCase());
if (!m) throw new Error("Invalid adjustment type:" + g);
let f = null;
if (!(m === N.AdjustmentType.Gray || m === N.AdjustmentType.Comp || m === N.AdjustmentType.Inv || m === N.AdjustmentType.Gamma || m === N.AdjustmentType.InvGamma)) {
u++;
const p = h[u];
if (f = parseFloat(p), f == null) throw new Error(`Invalid adjustment value: missing value for'${g}'`);
if (isNaN(f)) throw new Error("Invalid adjustment value:" + p);
}
c.push({ [m]: f });
}
l = new ae({ val: s, adjs: c }, e, n, r);
} catch (c) {
throw c;
}
return l;
}
static getDefaultSchemeLookup() {
if (!va) {
const t = /* @__PURE__ */ new Map(), e = Object.keys(Th), n = e.length;
for (let r = 0; r < n; r++) {
const o = e[r];
t.set(o.toLowerCase(), ae.parse(Th[o], null));
}
va = (r) => t.get(r.toLowerCase())?.toRGBA();
}
return va;
}
isEqual(t) {
return t instanceof ae && this.toString().toLowerCase() === t.toString().toLowerCase();
}
getVal() {
return this._private.val;
}
getAdjustments() {
return this._private.adjs;
}
adjust(t) {
return new ae({ val: this._private.val, adjs: this._private.adjs ? this._private.adjs.concat(t) : t }, this._private.schemeLookup, this._private.indexedLookup, this._private.last);
}
getType() {
return this._resolve(), this._private.parsedVal.type ?? null;
}
toCSS(t = !1, e = !1) {
const n = t ? this._forceDark() : this.toRGBA();
return n.alpha === 0 ? "none" : n.toString(e);
}
toRGBA(t = !1) {
return this._resolve(), t ? this._forceDark() : this._private.resolved;
}
toHSLA(t = !1) {
if (this._resolve(), t) return this._forceDark(!1);
let e = Zn(this._private.adjusted.srgb);
return new In.HSLA(e[0], e[1], e[2], Pr(this._private.adjusted.alpha ?? 1));
}
toHex(t = !1) {
this._resolve();
const e = t ? this._forceDark() : this._private.resolved;
return new In.HEX(e.red, e.green, e.blue, e.alpha ?? 1);
}
toBlackOrWhite(t = !1, e = 157) {
const n = this.toRGBA(t), r = 0.299 * n.red + 0.587 * n.green + 0.114 * n.blue > e;
return new ae(r ? "#000000" : "#FFFFFF", this._private.schemeLookup, this._private.indexedLookup, this._private.last);
}
get [Symbol.toStringTag]() {
return this.toString();
}
toString() {
let t = this._private.val;
const e = this._private.adjs, n = e ? e.length : 0;
for (let r = 0; r < n; r++) {
const o = e[r];
if (!o) continue;
const s = Object.keys(o)[0];
t += " " + s;
const i = o[s];
typeof i == "number" && (t += " " + i), r < n - 1 && (t += ",");
}
return t;
}
get isIColor() {
return !0;
}
}
var U, Nh;
(Nh = 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" }, Nh.Edge = { Left: "left", Top: "top", Right: "right", Bottom: "bottom", Horizontal: "horizontal", Vertical: "vertical", DiagonalUp: "diagonalUp", DiagonalDown: "diagonalDown" };
const Lg = [], Bg = /* @__PURE__ */ new Map(), Fh = 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 < Fh.length; a++) {
const t = Fh[a], e = t[0], n = Object.freeze({ style: e, description: t[1], width: t[2], pattern: t[3] });
Lg.push(n), Bg.set(e, n);
}
((a) => {
a.isEqualStrokes = (t, e) => !(t && !e || e && !t) && (t === e || t.getStyle() === e.getStyle() && t.getColor().isEqual(e.getColor())), a.oppositeEdge = (t) => t === a.Edge.Left ? a.Edge.Right : t === a.Edge.Right ? a.Edge.Left : t === a.Edge.Top ? a.Edge.Bottom : t === a.Edge.Bottom ? a.Edge.Top : t, a.BuiltInDefinitionsArray = Lg, a.BuiltInDefinitions = Bg;
})(U || (U = {}));
const Up = { Text: "text", Repeat: "repeat", Spacing: "spacing" }, kh = (a) => !(!a.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/) && !a.match(/^# ([#0?]+)( ?)\/( ?)([#0?]+)/)), qp = Object.freeze({ formatValue: Yl, isFractionFormat: kh, adjustDecimalPlaces: (a, t) => {
if (!a) return "";
const e = (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" + e("", i) : s;
if (kh(s)) return s;
let l = s, c = -1, h = -1, d = l.indexOf("E");
if (d >= 0 && (l = l.substring(0, d)), c = l.indexOf("."), c >= 0) {
l = l.substring(c, l.length);
let u = l && l.match(/([.]{1}[0,#]+)/);
if (!u) return s;
l = u[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 = e(l, i), s.substring(0, c) + l + s.substring(h, s.length));
}, r = [];
let o = op(a);
for (let s = 0; s < o.length; s++) r.push(n(o[s].trim(), t));
return r.join(";");
} }), Jp = ne._table, nc = (a) => a === 14 ? "Short Date" : Jp[a] ?? null, fo = [{ numberFormat: "General", formatType: ft.General, primary: 1 }, { numberFormat: "0", formatType: ft.Number, regMatch: /^0[.]{0,1}[0]*$/, args: { decimalPlaces: 0, separator: !1 } }, { numberFormat: "#,##0.00", formatType: ft.Number, regMatch: /^#,##0[.]{0,1}[0]*$/, primary: 2, args: { decimalPlaces: 2, separator: !0 } }, { numberFormat: "#,##0_);(#,##0)", formatType: ft.Number, args: { decimalPlaces: 0, separator: !0 } }, { numberFormat: "#,##0_);[Red](#,##0)", formatType: ft.Number, args: { decimalPlaces: 0, separator: !0 } }, { numberFormat: "#,##0.00_);(#,##0.00)", formatType: ft.Number, args: { decimalPlaces: 2, separator: !0 } }, { numberFormat: "#,##0.00_);[Red](#,##0.00)", formatType: ft.Number, args: { decimalPlaces: 2, separator: !0 } }, { numberFormat: "$#,##0.00", formatType: ft.Currency, primary: 3, args: { decimalPlaces: 2, currencySymbol: "$" } }, { numberFormat: "$#,##0_);($#,##0)", formatType: ft.Currency, args: { decimalPlaces: 0, currencySymbol: "$" } }, { numberFormat: "$#,##0_);[Red]($#,##0)", formatType: ft.Currency, args: { decimalPlaces: 0, currencySymbol: "$" } }, { numberFormat: "$#,##0.00_);($#,##0.00)", formatType: ft.Currency, args: { decimalPlaces: 2, currencySymbol: "$" } }, { numberFormat: "$#,##0.00_);[Red]($#,##0.00)", formatType: ft.Currency, args: { decimalPlaces: 2, currencySymbol: "$" } }, { numberFormat: '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)', primary: 4, formatType: ft.Accounting }, { numberFormat: '_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)', formatType: ft.Accounting }, { numberFormat: '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)', formatType: ft.Accounting }, { numberFormat: '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)', formatType: ft.Accounting }, { numberFormat: "Short Date", formatType: ft.ShortDate, primary: 5 }, { numberFormat: "d-mmm-yy", formatType: ft.MediumDate, primary: 5.5 }, { numberFormat: "Long Date", formatType: ft.LongDate, primary: 6 }, { numberFormat: "h:mm", formatType: ft.ShortTime, primary: 7 }, { numberFormat: "h:mm AM/PM", formatType: ft.MediumTime, primary: 7.5 }, { numberFormat: "Long Time", formatType: ft.LongTime, primary: 8 }, { numberFormat: '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)', formatType: ft.Comma, primary: 9 }, { numberFormat: "0.00%", formatType: ft.Percentage, primary: 10, args: { decimalPlaces: 2 }, regMatch: /^^[0#?]*[.]{0,1}[0#?]*%*$/ }, { numberFormat: "0%", formatType: ft.Percentage, args: { decimalPlaces: 0 } }, { numberFormat: "# ?/?", formatType: ft.Fraction, primary: 11 }, { numberFormat: "# ??/??", formatType: ft.Fraction }, { numberFormat: "0.00E+00", formatType: ft.Scientific, primary: 12, args: { decimalPlaces: 2 }, regMatch: /^[0#?]*[.]{0,1}[0#?]*E\+[0#?]*$/ }, { numberFormat: "##0.0E+0", formatType: ft.Custom, args: { decimalPlaces: 0 } }, { numberFormat: "@", formatType: ft.Text, primary: 13 }, { numberFormat: "d-mmm", formatType: ft.Custom }, { numberFormat: "mmm-yy", formatType: ft.Custom }, { numberFormat: "h:mm:ss", formatType: ft.Custom }, { numberFormat: "m/d/yyyy h:mm", formatType: ft.Custom }, { numberFormat: "mm:ss", formatType: ft.Custom }, { numberFormat: "mm:ss.0", formatType: ft.Custom }, { numberFormat: "[h]:mm:ss", formatType: ft.Custom }], xa = [{ numberFormat: "00000", formatType: ft.Special, primary: 11 }, { numberFormat: "00000-0000", formatType: ft.Special }, { numberFormat: "[<=9999999]###-####;(###) ###-####", formatType: ft.Special }, { numberFormat: "000-00-0000", formatType: ft.Special }], ss = /* @__PURE__ */ new Map(), Lo = [];
for (let a = 0; a < fo.length; a++) {
let t = fo[a].numberFormat.toLowerCase();
ss.set(t, fo[a]), fo[a].regMatch && Lo.unshift(fo[a]);
}
for (let a = 0; a < xa.length; a++) {
let t = xa[a].numberFormat.toLowerCase();
ss.set(t, xa[a]);
}
const xl = [], zg = /* @__PURE__ */ new Map();
ss.forEach(function(a, t, e) {
a.primary && (xl.push(a), zg.set(k.textToKey(a.formatType), a.numberFormat));
}), xl.sort(function(a, t) {
return a.primary - t.primary;
});
const Oh = ss.get(ft.General.toLowerCase());
class Kp {
lookupStyle(t) {
if (!t) return Oh;
if (typeof t == "number" && (t = nc(t)), !t.toLowerCase) return console.warn("Invalid numberFormat", t), Oh;
t = t.toLowerCase();
let e = ss.get(t);
if (e) return e;
for (let n = 0; !e && n < Lo.length; n++) Lo[n].regMatch && t.match(Lo[n].regMatch) && (e = Lo[n]);
return e || { numberFormat: t, formatType: ft.Custom };
}
lookupPrimary() {
return xl;
}
lookupDefault(t) {
return zg.get(k.textToKey(t));
}
}
var Ne, ys, mt, Dh;
(ys = Ne || (Ne = {})).Type = ft, ys.Parser = qp, ys.Styles = new Kp(), ys.ParseRunType = Up, (Dh = mt || (mt = {})).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" }, Dh.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 Xp = (a, t, e, n, r) => {
const o = JSON.parse(JSON.stringify(a.definition));
o.adjs || (o.adjs = []);
let s = "", i = 0, l = 0;
t > 0 ? (l = t, i = 100 - t, s = `Lighter ${t}%`) : t < 0 && (i = 100 + t, s = `Darker ${-t}%`), i && o.adjs.push({ [N.AdjustmentType.LumMod]: i }), l && o.adjs.push({ [N.AdjustmentType.LumOff]: l });
const c = new ae({ val: o.val, adjs: o.adjs }, e), h = c.toString();
n?.set(h, c);
const d = c.toRGBA().toString();
return r?.set(d, c), { description: a.description + ", " + s, definition: o };
}, Yp = (a, t, e, 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(Xp(a[o], c[h], t, e, n));
};
let l = new ae({ val: a[o].definition.val, adjs: a[o].definition.adjs }, t).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 Lh, ur;
(Lh || (Lh = {})).buildPalette = Yp, (ur || (ur = {})).BuiltInFilterType = { BuiltIn: "builtIn", All: "all", Custom: "custom" };
const Qp = [["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"]], Zp = [["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"]], t0 = [["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"]], Ia = "Themes is readonly. To make modifications create a new DocsThemes instance.", Bh = { [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" }, Zr = "Office", Il = [Zr, "Calibri Light", "Calibri"], to = ["dk1", "lt1", "dk2", "lt2", "accent1", "accent2", "accent3", "accent4", "accent5", "accent6", "hlink", "folHlink"], Pg = (a) => {
const t = {};
for (let e = 0; e < a.length; e++) {
const n = a[e], r = n[0], o = { name: r };
t[r] = o;
for (let s = 0; s < to.length; s++) {
const i = to[s], l = n[s + 1];
if (!l) continue;
const c = ae.parse(l);
l && (o[i] = c.toString());
}
}
return t;
}, Wg = (a) => {
const t = {};
for (let e = 0; e < a.length; e++) {
const n = a[e], r = n[0], o = { name: r };
t[r] = o, o.majorFont = n[1] ?? Il[1], o.minorFont = n[2] ?? Il[2];
}
return t;
}, e0 = Pg([[Zr, "windowText", "window", "44546A", "E7E6E6", "4472C4", "ED7D31", "A5A5A5", "FFC000", "5B9BD5", "70AD47", "0563C1", "954F72"]]), n0 = Wg([Il]), Yo = e0[Zr], Lr = n0[Zr];
let sn = null;
const r0 = new class {
constructor() {
this._colors = {};
for (let a = 0; a < to.length; a++) {
const t = to[a], e = ae.parse(Yo[t]);
this._colors[t] = e;
}
}
getName() {
return Yo.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 o0 {
constructor(t, e = r0) {
this._delegate = e, this._fromJSON(t);
}
_fromJSON(t) {
if (this._overrides = {}, !t) return;
const e = Object.keys(t);
if (e.length !== 0) for (let n = 0; n < e.length; n++) {
const r = e[n];
this._overrides[r] = r === "name" ? t[r] : ae.parse(t[r]);
}
}
_value(t, e) {
return this._overrides && this._overrides[t] !== null && this._overrides[t] !== void 0 ? this._overrides[t] : this._delegate?.[e]?.();
}
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 t = k.toSafeJSON(this._overrides), e = this.getName();
return e && (t.name = e), t;
}
}
const s0 = new class {
constructor() {
this._colors = {};
for (let a = 0; a < to.length; a++) {
const t = to[a], e = ae.parse(Yo[t]);
this._colors[t] = e;
}
}
getName() {
return Lr.name;
}
getMajorFont() {
return Lr.majorFont;
}
getMinorFont() {
return Lr.minorFont;
}
getMajorFallbacks() {
return Lr.majorFallbacks;
}
getMinorFallbacks() {
return Lr.minorFallbacks;
}
}();
class i0 {
constructor(t, e = s0) {
this._delegate = e, this._fromJSON(t);
}
_fromJSON(t) {
if (this._overrides = {}, !t) return;
const e = Object.keys(t);
if (e.length !== 0) for (let n = 0; n < e.length; n++) {
const r = e[n];
this._overrides[r] = t[r];
}
}
_value(t, e) {
return this._overrides && this._overrides[t] !== null && this._overrides[t] !== void 0 ? this._overrides[t] : this._delegate?.[e]?.();
}
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 t = k.toSafeJSON(this._overrides), e = this.getName();
return e && (t.name = e), t;
}
}
class Rl {
constructor(t, e = null, n = null) {
if (this._cacheColors = /* @__PURE__ */ new Map(), !e && t?.name) {
const l = sn ? sn.get(t.name.toLowerCase()) : null;
l && (e = l);
}
if (!e && sn && (e = sn.get(Zr.toLowerCase())), this._name = t?.name ?? e?.getName(), !this._name) throw new Error("Theme must have a name.");
this._builtInID = n, this._delegate = e, this._colors = new o0(t?.colors, this._delegate?.getColorScheme()), this._fonts = new i0(t?.fonts, this._delegate?.getFontScheme());
const r = Bh, o = {}, s = Object.keys(r);
for (let l = 0; l < s.length; l++) {
const c = s[l];
o[c] = `get${Qr(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 d = i.getColorScheme();
let u = d[h].bind(d)();
return u || (u = Yo[Bh[l] ?? l]), c = new ae(u).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(t) {
return ae.parse(t, this._schemeLookup);
}
toJSON() {
const t = { name: this.getName() }, e = this._colors.toJSON();
e && (Object.keys(e).length > 1 || e.name && e.name !== t.name) && (t.colors = e);
const n = this._fonts.toJSON();
return n && (Object.keys(n).length > 1 || n.name && n.name !== t.name) && (t.fonts = n), Object.keys(t).length === 1 && t.name === Zr ? null : t;
}
}
const a0 = () => {
if (sn) return sn;
const a = ((e, n, r) => {
const o = [];
for (let s = 0; s < e.length; s++) {
const i = e[s], l = i[0], c = n[i[1]] ?? Yo, h = r[i[2]] ?? Lr;
o.push({ name: l, colors: c, fonts: h });
}
return o;
})(t0, Pg(Qp), Wg(Zp)), t = /* @__PURE__ */ new Map();
for (let e = 0; e < a.length; e++) {
const n = new Rl(a[e]), r = new Rl(null, n, e + 1);
t.set(r.getName().toLowerCase(), r);
}
return sn = t, t;
};
class Hg {
constructor(t = null, e = !1) {
a0(), this._isReadOnly = e, this._customMap = /* @__PURE__ */ new Map(), this._defaultTheme = this.getByName("Office");
}
getDefaultTheme() {
return this._defaultTheme;
}
setDefaultTheme(t) {
if (this._isReadOnly) throw new Error(Ia);
if (!t) throw new Error("Theme cannot be null.");
const e = this.getDefaultTheme();
return this.getByName(t.getName()) || this.setCustomTheme(t), this._defaultTheme = t, e;
}
getByName(t) {
return t = t.toLowerCase(), this._customMap.get(t) || (sn.get(t) ?? null);
}
getItems(t) {
const e = t?.type ?? ur.BuiltInFilterType.All, n = /* @__PURE__ */ new Map();
return e !== ur.BuiltInFilterType.BuiltIn && e !== ur.BuiltInFilterType.All || sn.forEach((r, o) => n.set(o, r)), e !== ur.BuiltInFilterType.Custom && e !== ur.BuiltInFilterType.All || this._customMap.forEach((r, o) => n.set(o, r)), t?.selected && n.set(t.selected.getName().toLowerCase(), t.selected), ((r) => {
const o = [...r];
return o.sort((s, i) => k.isDefined(s.builtInID) && !k.isDefined(i.builtInID) ? 1 : !k.isDefined(s.builtInID) && k.isDefined(i.builtInID) ? -1 : k.isDefined(s.builtInID) && k.isDefined(i.builtInID) ? s.builtInID - i.builtInID : s.getName().localeCompare(i.getName())), o;
})(Array.from(n.values()));
}
getCount() {
return this._customMap.size + sn.size;
}
setCustomTheme(t) {
if (this._isReadOnly) throw new Error(Ia);
const e = t.getName().toLowerCase(), n = this._customMap.get(e);
return this._customMap.set(e, t), n ?? null;
}
deleteCustomTheme(t) {
if (this._isReadOnly) throw new Error(Ia);
let e = null;
e = typeof t == "string" ? t.toLowerCase() : t.getName().toLowerCase();
const n = this._customMap.get(e);
return this._customMap.delete(e), n ?? null;
}
}
var gr, ve;
(gr || (gr = {})).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" }, (gr || (gr = {})).Empty = class {
constructor(a) {
this._normalStyle = a;
}
getName() {
return "None";
}
isShownInTableStyles() {
return !1;
}
isShownInPivotStyles() {
return !1;
}
getRanged(a) {
return null;
}
getProperties() {
return k.EmptyObject;
}
isBuiltIn() {
return !0;
}
delete() {
}
toJSON() {
return null;
}
get isITableStyle() {
return !0;
}
}, (ve || (ve = {})).Type = { Absolute: "absolute", OneCell: "oneCell", TwoCell: "twoCell" };
const We = "Model has been closed. No further operations are allowed.", zh = "Name is required";
class he {
constructor(t, e) {
this._listeners = /* @__PURE__ */ new Set(), this._pending = null, this._listeners = /* @__PURE__ */ new Set(), this._transactions = e ?? new Ze({ transient: !0 }), this._src = t;
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(), l = o.length;
for (let c = 0; c < l; c++) {
const h = o[c];
h.commitId === s && n._doNotify(h.listeners, h.removes, h.options, i);
}
} });
}
addListeners(t, e) {
const n = e?.transactional ?? this._transactions.isOpenTransaction(), r = { listeners: t }, 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 = e?.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(t, e = null, n, r) {
const o = n?.source ?? this._src, s = [], i = n?.params, l = t.length;
for (let h = 0; h < l; h++) {
const d = t[h];
r && r.has(d) || (r?.add(d), s.push(d(o, i)));
}
let c = null;
if (e && (c = () => {
const h = e.length;
for (let d = 0; d < h; d++) e[d]();
}), n?.async) return new Promise(async (h, d) => {
try {
const u = await Promise.all(s);
c?.(), h(u);
} catch (u) {
c?.(), d(u);
}
});
c?.();
}
notify(t, e) {
let n = null, r = null;
const o = (d) => {
d.forEach((u) => {
const g = u.listeners[t];
g && (n || (n = []), n.push(g), u.remove && (r || (r = []), r.push(u.remove)));
});
}, s = e?.transactional ?? this._transactions.isOpenTransaction();
if (s) {
const d = this._transactions.getState(this)?.listeners;
d && o(d);
}
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, e), c) {
let d = this._pending;
return d || (this._pending = d = []), d.push({ commitId: this._transactions.getCurrentCommit().getId(), listeners: c, removes: h, options: e }), this._doNotify(c, l, e);
}
} else if (c) return this._doNotify(c, h, e);
}
close() {
this._transactions.remove(this), this._transactionsRemoveListener();
}
}
class Er {
constructor(t) {
this._emitter = null, this._closed = !1, this._options = { ...t };
const e = this;
this._transactions = this._options?.transactions ?? new Ze({ transient: !0 }), this._emitter = new he(this, this._transactions), this._updateState({ isDeleted: !1 }), t?.json && this._fromJSON(t.json), this._options?.setContainerReadOnlyCallback?.(() => {
e._processOnContainerReadOnly();
}), this._transactionsRemoveListener = this._transactions.addStateListener(this, { onAfterStateChange(n, r, o) {
e._processStateChange(n, r, o);
}, onRestoreOrRevert(n, r, o) {
e._processRestoreOrRevert(n, r, o);
} }), this._processInit();
}
_fromJSON(t) {
}
isReadOnly() {
return this._options.isReadOnly?.() ?? !1;
}
isDeleted() {
return this._getState().isDeleted ?? !1;
}
getType() {
return this._options.type;
}
get isIModel() {
return !0;
}
_processTransactionDone(t) {
}
_getDescription() {
return null;
}
_getState() {
if (this._closed) throw new Error(We);
return this._transactions.getState(this);
}
_beginCommit(t) {
return this._transactions.beginCommit(typeof t == "string" ? { description: t } : t);
}
_getTransactions() {
return this._transactions;
}
_updateState(t, e, n) {
if (this._closed) throw new Error(We);
if (!t) return;
const r = this._beginCommit(e?.description);
try {
r.updateState(this, t);
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(t, e, n) {
}
_processRestoreOrRevert(t, e, n) {
this._emitter.notify("onInvalidated");
}
delete(t) {
if (this._getState().isDeleted) throw new Error("Model has been deleted.");
this._options.deleteFromContainer && this._options.deleteFromContainer?.(t), this._delete();
}
_delete() {
const t = this._getDescription(), e = "Delete", n = t ? `${e} ${t}` : e, 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(t, e) {
return this._emitter.addListeners(t, e);
}
beginCommit(t) {
return this._beginCommit(t);
}
doBatch(t, e) {
const n = this;
return this._transactions.doBatch(t, typeof e == "string" ? { description: e } : e, (r) => {
n._processTransactionDone(r);
});
}
isClosed() {
return this._closed;
}
close() {
this._closed || (this._emitter.notify("onClose"), this._closed = !0, this._transactionsRemoveListener?.());
}
}
class Vg extends Er {
_fromJSON(t) {
const e = {};
if (e.name = t?.name ?? null, !e.name) throw new Error(zh);
e.comment = t?.comment ?? null, e.hidden = t?.hidden ?? !1, e.scope = t?.scope ?? null, this._updateState(e, { description: this._options.createDescription ?? "Create Item" + (e.name ? ` '${e.name}'` : "") });
}
_toJSON() {
const t = this._getState(), e = { name: t.name };
return t.comment && (e.comment = t.comment), t.hidden && (e.hidden = t.hidden), t.hidden && (e.hidden = t.hidden), e;
}
getName() {
return this._getState().name;
}
setName(t, e) {
if (!t) throw new Error(zh);
return this._updateState({ name: t }, { description: `Update Named '${t}'`, ...e });
}
getComment() {
return this._getState().comment;
}
setComment(t, e) {
return this._updateState({ comment: t }, { description: "Set Comment", ...e });
}
isHidden() {
return this._getState().hidden;
}
getScope() {
return this._getState().scope;
}
get isINamed() {
return !0;
}
}
var Ph, Gr, Ee;
(Ph || (Ph = {})).SortOn = { Value: "value", FillColor: "fillColor", FontColor: "fontColor", Icon: "icon" }, (Ee = Gr || (Gr = {})).CaseInsensitiveOptions = { sensitivity: "base", numeric: !1 }, Ee.CaseSensitiveOptions = { sensitivity: "case", numeric: !1 }, Ee.BooleanCollator = Object.freeze({ type: Y.Boolean, compare: (a, t, e) => a === !0 ? 1 : -1 }), Ee.StringCollator = Object.freeze({ type: Y.String, compare: (a, t, e) => a.localeCompare(t, "en", e), defaultOptions: Ee.CaseInsensitiveOptions }), Ee.NumberCollator = Object.freeze({ type: Y.Number, compare: (a, t, e) => a < t ? -1 : 1 }), Ee.RichDataCollator = Object.freeze({ type: Y.RichData, compare: (a, t, e) => a.type.localeCompare(t.type, "en") }), Ee.DefaultRangeOptions = Object.freeze({ hasHeader: !1, reverse: !1, includeHidden: !1, collatorOptions: Ee.CaseInsensitiveOptions, orientation: F.Orientation.Row, offset: 0 }), Ee.DefaultCollators = Object.freeze([Ee.BooleanCollator, Ee.StringCollator, Ee.NumberCollator, Ee.RichDataCollator]);
const l0 = (a, t, e, n) => {
let r;
for (; !(r = a.next()).done; ) try {
t(r.value[1], r.value[0], e);
} catch (o) {
if (typeof a.throw != "function") throw o;
a.throw(o);
}
typeof a.return == "function" && a.return();
}, jg = (a) => {
const t = a.next.bind(a), e = { next: (n) => {
const r = t(n);
return r.done ? Lt : { done: r.done, value: r.value[1] };
}, [Symbol.iterator]: () => e, ...a.return && { return: a.return.bind(a) }, ...a.throw && { throw: a.throw.bind(a) } };
return e;
}, po = (a) => {
if (!a || a.length === 0) return null;
let t = Number.MAX_SAFE_INTEGER, e = -1, n = null;
return (r, o = !1) => {
if (r === t) return r;
o !== !1 && (t = Number.MAX_SAFE_INTEGER), r !== t + (o ? -1 : 1) && (e = ((i, l, c = !0) => {
if (!i || i.length === 0) return null;
let h, d = -1;
return c ? (d = k.findEqualOrGreater(i, l, (u) => u.max), h = i[d]) : (d = k.findEqualOrLesser(i, l, (u) => u.min), h = i[d]), h ? (c ? l > h.max && (d += 1, h = i[d]) : l < h.min && (d -= 1, h = i[d]), h ? d : -1) : -1;
})(a, r, !o), n = a[e]);
let s = r;
if (o) for (; n && s <= n.max; ) s = n.min - 1, n = a[--e];
else for (; n && s >= n.min; ) s = n.max + 1, n = a[++e];
return t = s, s;
};
}, Lt = Object.freeze({ done: !0, value: void 0 }), re = Object.freeze({ next: () => Lt, [Symbol.iterator]: () => re });
var Ur;
Object.seal({ done: !1, value: void 0 }), ((a) => {
a.isList = (e) => !!e && !!e.isIList, a.isListLike = (e) => !!e && typeof e.length == "number" && typeof e.at == "function", a.fromArray = (e, n, r, o) => new t(e, n, r, o);
class t {
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 ?? k.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 t(n, this.g, this.s);
}
get length() {
return this.a.length;
}
get isIList() {
return !0;
}
}
a.ArrayList = t;
})(Ur || (Ur = {}));
class Ve {
constructor(t) {
if (this._s = null, this._r = null, this._l = 0, t && t.length > 0) {
const e = Ur.isList(t) && !Array.isArray(t) ? t : new Ur.ArrayList(t);
this._s = e, this._l = t.length;
}
}
at(t) {
const e = this._s;
if (e) return e.at(t);
const n = this._c;
if (n && n.min <= t && n.max >= t) {
const i = n.value;
return i.v.at(t - n.min + i.s);
}
const r = this._r, o = r[k.findEqualOrGreater(r, t, (i) => i.max)];
if (!o) return;
const s = o.value;
return this._c = o, s.v.at(t - o.min + s.s);
}
toArray(t = Number.MAX_SAFE_INTEGER) {
const e = [], n = this.entries(c0);
let r = n.next();
for (; !r.done && e.length < t; ) e.push(r.value[1]), r = n.next();
return e;
}
entries(t) {
const e = this.length;
if (e === 0) return re;
let n, r, o, s = !0, i = 0, l = e - 1;
if (t) {
s = !t.reverse;
const g = t.bounds;
g && (i = Math.max(g.min ?? i, i), l = Math.min(g.max ?? l, l)), n = t.reuseResult ?? null, r = t.processSkip;
}
const c = s ? 1 : -1;
let h = (s ? i : l) - c;
const d = this._s;
if (d) o = (g) => {
if (!(g < i || g > l)) return d.at(g);
};
else {
const g = this._r;
let m = s ? 0 : g.length - 1, f = g[m];
const p = (_, S) => {
const C = _ === m ? f : g[_];
if (C && S >= C.min && S <= C.max) return m = _, f = C, C;
};
o = (_) => {
if (_ < i || _ > l) return;
let S = p(m, _);
if (S || (S = p(m + c, _)), !S) {
const y = k.findEqualOrGreater(g, _, (E) => E.max);
S = p(y, _);
}
if (!S) return;
const C = S.value;
return C.v.at(_ - S.min + C.s);
};
}
const u = { next: (g) => {
let m, f = h + c;
return g !== void 0 && (g < 0 && (g = e + g), f = g), f < i || f > l || r && (f = r(f, !s), f < i || f > l) ? Lt : (m = o(f), h = f, n ? (Bo.done = !1, Bo.value[0] = f, Bo.value[1] = m, Bo) : { done: !1, value: [h, m] });
}, [Symbol.iterator]: () => u };
return u;
}
slice(t, e = void 0) {
const n = this._r ?? Wh(this._s);
if (!n) return Ra;
const r = this.length;
if (t = Math.min(Math.max(0, t), r), (e = Math.min(Math.max(0, e ?? r), r)) - t <= 0) return Ra;
if (t <= 0 && e >= r) return this;
const o = t, s = e - 1;
let i = [], l = 0;
for (let h = 0; h < n.length; h++) {
let d = n[h];
const u = d.max;
if (o === 0 && u <= s) {
i.push(d);
continue;
}
const g = d.min;
if (g > s) {
h = n.length;
continue;
}
if (u < o) {
l = u + 1;
continue;
}
const m = Math.max(0, o - g), f = Math.max(0, u - s), p = f + m, _ = d.value;
i.push({ min: g - l, max: u - p - l, value: { s: _.s + m, e: _.e - f, v: _.v } }), l += p;
}
const c = new Ve();
return c._r = i, c._l = s - o + 1, c;
}
concat(t) {
if (!t) return this;
if (!Ur.isListLike(t)) throw new Error("Value must be IListLike");
const e = this._l;
if (e === 0) return t.isIReadableList ? t : t.length === 0 ? Ra : new Ve(t);
const n = t, r = t.length;
if (r === 0) return this;
const o = this._r ?? Wh(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, d = h ? h.v : null, u = h ? h.e - h.s : 0;
const g = (p) => {
const _ = p.s, S = p.e, C = S - _;
if (C + u < h0 && d && d.fromArray) {
let w = p.v;
const b = [], v = h.s, I = h.e;
for (let R = v; R <= I; R++) b.push(d.at(R));
for (let R = _; R <= S; R++) b.push(w.at(R));
const x = d.fromArray(b);
if (x) return w = x, u = w.length - 1, h = { s: 0, e: u, v: w }, i = { min: l, max: l + u, value: h }, c = l + u, void (d = w);
}
s.push(i);
const y = c + 1, E = y + C;
i = { min: y, max: E, value: p }, l = y, c = E, h = i ? i.value : null, d = h ? h.v : null, u = h ? h.e - h.s : 0;
};
if (t instanceof Ve) {
const p = t._s;
if (p) g({ s: 0, e: p.length - 1, v: p });
else {
const _ = t._r;
for (let S = 0; S < _.length; S++)
g(_[S].value);
}
} else g({ s: 0, e: r - 1, v: n });
s.push(i);
const m = new Ve(), f = e + 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 jg(this.entries());
}
get isIReadableList() {
return !0;
}
get isIList() {
return !0;
}
get [Symbol.toStringTag]() {
return "[ImmutableList]";
}
toString() {
const t = this.length;
if (t === 0) return "";
let e = "";
for (let n = 0; n < t; n++) {
n > 0 && (e += ",");
const r = this.at(n);
e += r == null ? "" : String(r);
}
return e;
}
}
const Wh = (a) => [{ min: 0, max: a.length - 1, value: { s: 0, e: a.length - 1, v: a } }], Ra = new Ve(), Bo = Object.seal({ done: !1, value: [-1, null] }), c0 = Object.freeze({ reverse: !1, bounds: { min: 0, max: Number.MAX_SAFE_INTEGER }, skipRuns: null, reuseResult: Bo }), h0 = 4;
var Qo;
((a) => {
const t = (n, r) => {
const o = n !== yt.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 d = i[0];
let u = 0, g = 0;
if (o ? (u = l ? c.colEnd : c.colStart, g = d ? h.colEnd : h.colStart) : (u = l ? c.rowEnd : c.rowStart, g = d ? h.rowEnd : h.rowStart), u === g && l !== d) return l ? -1 : 1;
if (u !== g) return g - u;
let m = 0, f = 0;
if (o ? (m = l ? c.colStart : c.colEnd, f = d ? h.colStart : h.colEnd) : (m = l ? c.rowStart : c.rowEnd, f = d ? h.rowStart : h.rowEnd), m === f && l !== d) return l ? -1 : 1;
if (m !== f) return f - m;
const p = s[2] ?? 0;
return (i[2] ?? 0) - p;
} : (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 d = i[0];
let u = 0, g = 0;
if (o ? (u = l ? c.colStart : c.colEnd, g = d ? h.colStart : h.colEnd) : (u = l ? c.rowStart : c.rowEnd, g = d ? h.rowStart : h.rowEnd), u === g && l !== d) return l ? -1 : 1;
if (u !== g) return u - g;
let m = 0, f = 0;
return o ? (m = l ? c.colEnd : c.colStart, f = d ? h.colEnd : h.colStart) : (m = l ? c.rowEnd : c.rowStart, f = d ? h.rowEnd : h.rowStart), m === f && l !== d ? l ? -1 : 1 : m !== f ? m - f : (s[2] ?? 0) - (i[2] ?? 0);
};
};
class e {
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 = yt.Column, i = !1, l = !0, c = !1;
o && (s = o.orientation ?? yt.Column, this._isColumn = l = s !== yt.Row, this._isReverse = i = o.reverse ?? !1, this._isByCell = c = o.byCell ?? !1);
const h = r.length, d = new Array(2 * h);
for (let f = 0; f < h; f++) {
const p = r[f], _ = [null, null];
d[2 * f] = [!0, p, f, _], d[2 * f + 1] = [!1, p, f, _];
}
d.sort(t(s, i)), this._eventsMajor = d;
const u = d[0][1];
this._majorStart = i ? Number.MAX_SAFE_INTEGER : Number.MIN_SAFE_INTEGER, this._majorEnd = l ? i ? u.colEnd + 1 : u.colStart - 1 : i ? u.rowEnd + 1 : u.rowStart - 1, this._eventsMinor = new xt(null, t(l ? yt.Row : yt.Column, i));
const g = new Array(16);
if (g.length = 0, this._cursor = { cell: null, range: { colStart: u.colStart, rowStart: u.rowStart, colEnd: u.colEnd, rowEnd: u.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 }), o?.reuseIterator) throw new Error("Not implemented yet");
}
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 R = L.createCellComparator(o ? yt.Column : yt.Row, s);
let A;
do {
const M = this._cursor, T = M.cell, O = T.colIndex === Number.MAX_SAFE_INTEGER || T.rowIndex === Number.MAX_SAFE_INTEGER;
if (!O && R(T, r) >= 0) throw new Error("nextCell must be after the current iteration cell");
if (A = this.next(), A.done) return A;
const W = A.value.cell;
if (R(W, r) >= 0) return A;
const D = M.range;
if (o) {
const z = r.colIndex === T.colIndex;
T.rowIndex = s ? z ? Math.max(r.rowIndex, D.rowStart) : D.rowStart : z ? Math.min(r.rowIndex, D.rowEnd) : D.rowEnd;
} else {
const z = r.rowIndex === T.rowIndex;
T.colIndex = s ? z ? Math.max(r.colIndex, D.colStart) : D.colStart : z ? Math.min(r.colIndex, D.colEnd) : D.colEnd;
}
if (!O && R(T, r) >= 0) return W.rowIndex = T.rowIndex, W.colIndex = T.colIndex, A;
} while (!A.done);
return A;
}
let i = this._cursor;
if (!i) return Lt;
let l = this._reuse;
const c = i.cell, h = i.range;
if (l) {
l.done = !1;
const R = l.value, A = R.cell;
c ? (A.colIndex = c.colIndex, A.rowIndex = c.rowIndex) : A && (A.colIndex = -1, A.rowIndex = -1);
const M = R.range;
M.colStart = h.colStart, M.rowStart = h.rowStart, M.colEnd = h.colEnd, M.rowEnd = h.rowEnd, R.overlaps = [...i.overlaps], this._cursor.overlaps = R.overlaps;
} else {
const R = { cell: null, range: { colStart: h.colStart, rowStart: h.rowStart, colEnd: h.colEnd, rowEnd: h.rowEnd }, overlaps: [...i.overlaps] };
c && (R.cell = { colIndex: c.colIndex, rowIndex: c.rowIndex }), this._cursor = R, l = { done: !1, value: R };
}
const d = l.value, u = d.range, g = d.cell, m = this._isByCell, f = s ? -1 : 1;
let p = !1;
if (m) {
const R = g.rowIndex, A = g.colIndex, M = o ? R : A, T = o ? s ? u.rowStart : u.rowEnd : s ? u.colStart : u.colEnd;
if ((s ? M >= T : M <= T) && (o ? g.rowIndex = R + f : g.colIndex = A + f, s ? M > T : M < T))
return l;
const O = o ? g.colIndex : g.rowIndex, W = o ? s ? u.colStart : u.colEnd : s ? u.rowStart : u.rowEnd;
(s ? O > W : O < W) && (p = !0);
}
const _ = d.overlaps;
let S = this._majorStart, C = this._majorEnd, y = this._eventsMinor, E = this._minorStart, w = this._minorEnd, b = this._eventsMinorIterator, v = this._eventMinorPeek, I = v;
for (; I && !I.done; ) {
const R = I.value[0];
if (R[0]) I = null;
else {
if (v = b.next(), v.done) _.length = 0;
else {
const A = R[1];
let M = _.length;
if (M > 1) {
const T = _.indexOf(A);
T !== -1 && (_[T] = _[M - 1]);
}
if (_.length = M - 1, M = _.length, M > 0) {
const T = v.value[0], O = T[1], W = o ? s ? O.colStart : O.colEnd : s ? O.rowStart : O.rowEnd;
if (s ? S >= W : S <= W) {
let D = !1;
if (T[0]) {
const z = o ? s ? O.rowEnd : O.rowStart : s ? O.colEnd : O.colStart;
(s ? z < w + f : z > w + f) && (E = w + f, w = z - f, D = !0);
} else {
const z = o ? s ? O.rowStart : O.rowEnd : s ? O.colStart : O.colEnd;
(s ? z < w : z > w) && (E = w + f, w = z, D = !0);
}
if (D) return o ? (u.rowStart = s ? w : E, u.rowEnd = s ? E : w) : (u.colStart = s ? w : E, u.colEnd = s ? E : w), this._minorStart = E, this._minorEnd = w, this._eventMinorPeek = v, l;
}
}
}
v.done && (v = null), I = v;
}
}
if (!v) if (p) {
b = y.entries(void 0, this._localReuse), v = b.next(), this._eventsMinorIterator = b;
const R = v.value[0][1], A = o ? s ? R.rowEnd : R.rowStart : s ? R.colEnd : R.colStart;
o ? (g.colIndex = g.colIndex + f, g.rowIndex = A) : (g.colIndex = A, g.rowIndex = g.rowIndex + f);
} else {
let R = this._eventMajorIndex;
const A = this._eventsMajor, M = A.length;
if (R >= M) return this._cursor = null, Lt;
let T = A[R], O = T[0], W = !1;
for (; !O && !W && T; ) {
const z = T[1], B = o ? s ? z.colStart : z.colEnd : s ? z.rowStart : z.rowEnd;
if (s ? B < C : B > C) {
W = !0;
continue;
}
const H = T[3];
y.delete(H[0]), y.delete(H[1]), R++, T = A[R], T && (O = T[0]);
}
let D = y.size > 0 ? C + f : -1;
for (W = !1; O && !W && T; ) {
const z = T[1];
if (D !== -1 && (o ? s ? z.colEnd : z.colStart : s ? z.rowEnd : z.rowStart) !== D) {
W = !0;
continue;
}
const B = T[2], H = [!0, z, B], P = [!1, z, B], j = T[3];
if (j[0] = H, j[1] = P, y.set(H, 0), y.set(P, 0), D === -1 && (D = o ? s ? z.colEnd : z.colStart : s ? z.rowEnd : z.rowStart), R++, T = A[R], !T || (O = T[0], !O)) continue;
const G = T[1];
(o ? s ? G.colEnd : G.colStart : s ? G.rowEnd : G.rowStart) !== D && (W = !0);
}
if (D !== -1 && (S = D), m && (o ? g.colIndex = S : g.rowIndex = S), this._eventMajorIndex = R, R >= M) return this._eventsMinorIterator = b, this._cursor = null, Lt;
if (T) {
const z = T[0], B = T[1], H = o ? s ? B.colEnd : B.colStart : s ? B.rowEnd : B.rowStart, P = o ? s ? B.colStart : B.colEnd : s ? B.rowStart : B.rowEnd;
C = z ? H - f : P;
}
_.length = 0, b = y.entries(void 0, this._localReuse), v = b.next(), this._eventsMinorIterator = b;
}
let x = v;
do {
const R = x.value;
x = null;
const A = R[0], M = A[1];
if (!A[0]) continue;
const T = o ? s ? M.rowEnd : M.rowStart : s ? M.colEnd : M.colStart;
E !== T && (E = T), v = b.next();
const O = v.value[0], W = O[0], D = O[1], z = o ? s ? D.rowEnd : D.rowStart : s ? D.colEnd : D.colStart;
if (W && z === E) x = v;
else {
const B = o ? s ? M.rowStart : M.rowEnd : s ? M.colStart : M.colEnd, H = o ? s ? D.rowStart : D.rowEnd : s ? D.colStart : D.colEnd;
w = (s ? Math.max : Math.min)(B, W ? z - f : H), m && (o ? g.rowIndex = E : g.colIndex = E);
}
_[_.length] = Object.freeze(M);
} while (x);
return o ? (u.colStart = s ? C : S, u.colEnd = s ? S : C, u.rowStart = s ? w : E, u.rowEnd = s ? E : w) : (u.rowStart = s ? C : S, u.rowEnd = s ? S : C, u.colStart = s ? w : E, u.colEnd = s ? E : w), this._eventMinorPeek = v, this._minorStart = E, this._minorEnd = w, this._majorStart = S, this._majorEnd = C, l;
}
return(r) {
return null;
}
throw(r) {
return null;
}
[Symbol.iterator]() {
return this;
}
}
a.IteratorInstance = e;
})(Qo || (Qo = {}));
const jn = (a, t = $t.Right, e = null) => {
if (!a) return a;
if (a.length === 0) return [];
const n = t === $t.Right, r = t === $t.Left, o = t === $t.Up, s = t === $t.Down;
return a.sort((i, l) => {
if (!i && !l) return 0;
if (i && !l) return -1;
if (l && !i) return 1;
const c = e?.(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;
});
}, d0 = (a, t) => {
const e = t.min, n = a.min;
if (t.max === Number.MAX_SAFE_INTEGER) {
const r = e, o = a.max;
return n <= r && r <= o ? 0 : o < r ? -1 : n > r ? 1 : (console.warn("coords are not inserted correctly", a, t), 0);
}
return n - e;
};
class tr {
constructor(t) {
this._runs = null, this._dataCoords = null, this._count = 0, this._length = 0, this._maxCoords = null, this._options = t, t?.maxCoords && (this._maxCoords = Object.freeze({ ...t.maxCoords })), this._runs = new xt(void 0, d0, t?.nodeSize), this._reuseRunsIterator = { done: !1, value: [null, null] }, this._reuseRunsEntry = [null, null];
}
_validateBounds(t = Number.MIN_SAFE_INTEGER, e = Number.MAX_SAFE_INTEGER) {
const n = this._maxCoords, r = n?.min ?? Number.MIN_SAFE_INTEGER, o = n?.max ?? Number.MAX_SAFE_INTEGER;
if (t < r || e > o) throw new Wt();
}
entries(t) {
let e, n, r = Number.MIN_SAFE_INTEGER, o = Number.MAX_SAFE_INTEGER, s = !0;
t && (t?.bounds && (r = t.bounds?.min ?? Number.MIN_SAFE_INTEGER, o = t.bounds?.max ?? Number.MAX_SAFE_INTEGER, this._validateBounds(r, o)), s = !t.reverse, e = u0(t.reuseResult), n = t.processSkip);
const i = this._dataCoords;
if (!i) return re;
r = Math.max(i.min, r), o = Math.min(i.max, o);
let l = null, c = null, h = Number.MAX_SAFE_INTEGER, d = Number.MIN_SAFE_INTEGER;
if (n) {
const p = n;
n = (_, S) => p(_ + h, S) - h;
}
const u = (p) => {
let _;
p !== Number.MIN_SAFE_INTEGER && p !== Number.MAX_SAFE_INTEGER && (Oe.min = p, _ = Oe), l = s ? this._runs.entries(_, this._reuseRunsIterator) : this._runs.entriesReversed(_, this._reuseRunsIterator), h = Number.MAX_SAFE_INTEGER, d = Number.MIN_SAFE_INTEGER, c = null;
}, g = (p) => {
if (p !== void 0) {
if (p < h || p > d) return void (c = void 0);
p -= h;
}
if (!c) return;
let _ = c.next(p);
if (!c) return;
let S = _.value, C = S?.[1];
return _.done ? void (c = void 0) : g0(S[0] + h, C, e);
}, m = (p) => {
let _;
return _ = g(p), _ || (_ = ((S) => {
let C;
do {
if (S !== void 0 && u(S), !l) return;
if (C = l.next(), C.done) return void (l = void 0);
const y = C.value, E = y[0], w = y[1], b = E.min, v = E.max, I = Math.max(b, r) - b, x = Math.max(I, Math.min(v, o)) - b;
Tr.bounds.min = I, Tr.bounds.max = x, Tr.reverse = !s, Tr.processSkip = n, Tr.reuseResult = e, h = b, d = v, c = w.entries(Tr);
const R = g(S);
if (R) return R;
S = void 0;
} while (!C.done);
l = void 0;
})(p), _ || Lt);
}, f = { next(p) {
if (p !== void 0 && (p < 0 || p > o)) throw new Wt();
return m(p);
}, return: (p) => null, throw: (p) => null };
return u(s ? r : o), f;
}
runs(t) {
let e, n = Number.MIN_SAFE_INTEGER, r = Number.MAX_SAFE_INTEGER, o = !0, s = !1;
t && (t.bounds && (n = t.bounds?.min ?? Number.MIN_SAFE_INTEGER, r = t.bounds?.max ?? Number.MAX_SAFE_INTEGER, this._validateBounds(n, r), t.overflowRun && (s = !0)), o = !t.reverse, e = m0(t.reuseResult));
const i = this._dataCoords;
if (!i) return re;
n = Math.max(i.min, n), r = Math.min(i.max, r);
let l = null;
const c = (d) => {
let u;
d !== Number.MIN_SAFE_INTEGER && d !== Number.MAX_SAFE_INTEGER && (Oe.min = d, u = Oe), l = o ? this._runs.entries(u, this._reuseRunsIterator) : this._runs.entriesReversed(u, this._reuseRunsIterator);
}, h = { next(d) {
if (d !== void 0) {
if (d < n || d > r) throw new Wt();
c(d);
}
if (!l) return Lt;
const u = l.next();
if (u.done) return l = void 0, Lt;
const g = u.value, m = g[0];
let f = m;
const p = f.min, _ = f.max;
if (o && p > r || !o && _ < n) return Lt;
let S = g[1];
return s || (_ > r && (S = S.slice(0, S.length - (_ - r)), f = { ...f }, f.max = r), p < n && (S = S.slice(n - p), f === m && (f = { ...f }), f.min = n)), f0(f, S, e);
}, return: (d) => null, throw: (d) => null };
return c(o ? n : r), h;
}
slice(t, e) {
const n = this._runs, r = n.minKey().min, o = n.maxKey().max;
if (e === void 0 && (e = o + 1), this._count === 0 || t <= r && e - 1 >= o) return this.clone();
const s = Math.max(r, t), i = Math.min(o, e - 1), l = i - s, c = [];
let h = 0;
Ma.bounds.min = s, Ma.bounds.max = i;
const d = this.runs(Ma);
let u = d.next();
for (; !u.done; ) {
const m = u.value;
let f = m[0], p = m[1];
f = { min: f.min - s, max: f.max - s }, f.min < 0 && (p = p.slice(-f.min), f.min = 0), f.max >= l && (p = p.slice(0, p.length - (f.max - l)), f.max = l), h += p.length, c.push([f, p]), u = d.next();
}
const g = new tr(this._options);
return g._runs.setPairs(c), g._updateCount(h), g;
}
concat(t) {
const e = this.clone();
if (!t || t.length === 0) return e;
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 (t.isISparseList) {
const h = t.runs();
let d = h.next();
for (; !d.done; ) {
const u = d.value;
let g = u[0];
const m = { min: g.min + s, max: g.max + s };
let f = u[1];
if (g.min === 0) {
i = !0, l -= o.length, f = o.concat(f);
const p = r.min;
m.min = p, m.max = f.length - 1 + p;
}
l += f.length, c.push([m, f]), d = h.next();
}
} else {
const h = t.length, d = { min: r.min, max: h - 1 + s };
t = o.concat(t), i = !0, l += h, c.push([d, t]);
}
return i && e._runs.delete(r), e._runs.setPairs(c), e._updateCount(l), e;
}
toArray(t = Number.MAX_SAFE_INTEGER, e = !0) {
if (this.length === 0) return k.EmptyArray;
const n = e ? 0 : Number.MIN_SAFE_INTEGER, r = Math.min(this._runs.maxKey().max, t);
return Aa.bounds.min = Number.MIN_SAFE_INTEGER, Aa.bounds.max = r, p0(this.entries(Aa), e, 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(t) {
if (this._count += t, this._lastRunsRead = void 0, this._lastListRead = void 0, this._count > 0) {
const e = this._runs, n = Object.freeze({ min: e.minKey().min, max: e.maxKey().max });
this._dataCoords = n, this._length = n.max + 1;
} else this._dataCoords = null, this._length = 0;
}
_update(t, e, n = null, r = void 0) {
const o = t, s = o + e - 1;
let i = 0, l = s, c = s, h = null, d = null;
Oe.min = o, Nr.min = s, (n || r) && (Oe.min -= 1, Nr.min += 1);
const u = this._runs;
let g = !1;
if (u.editRange(Oe, Nr, !0, (m, f, p) => {
const _ = m.min, S = m.max;
return _ < o && S + 1 >= o && (l = _, h = f), _ - 1 <= s && S > s && (c = _, d = f), i -= S - _ + 1, g = !0, xt.DeleteValue;
}), n || r === void 0 || (n = new Ve([r])), n) {
let m = n;
g = !0;
let f = o;
h && (h = h.slice(0, o - l), m = h.concat(m), f = l), d && (d = d.slice(s + 1 - c), m = m.concat(d)), i += m.length, u.set({ min: f, max: f + m.length - 1 }, m);
} else h && (h = h.slice(0, o - l), i += h.length, u.set({ min: l, max: l + h.length - 1 }, h)), d && (d = d.slice(s + 1 - c), i += d.length, u.set({ min: s + 1, max: s + d.length }, d));
return this._updateCount(i), g;
}
setAt(t, e) {
if (t === void 0) throw new Qe();
return this._validateBounds(t, t), this._update(t, 1, null, e);
}
setRunAt(t, e) {
if (!e || e.length === 0) return !1;
if (t === void 0 || !e.length) throw new Qe();
const n = e.length;
return this._validateBounds(t, t + n - 1), this._update(t, n, e);
}
delete(t, e) {
return e === void 0 && (e = Math.max(this.getCoords().max - t + 1, 0)), !(e <= 0) && (this._validateBounds(t, t), this._update(t, e, null));
}
shift(t, e) {
if (e === 0) return !1;
let n = t, r = t;
e < 0 && (r = t - e - 1), this._validateBounds(n, r);
const o = this._runs, s = o.maxKey();
if (e < 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, d = null;
Oe.min = l, Nr.min = s.min, e < 0 && (Oe.min -= 1, Nr.min += 1);
let u = !1;
const g = [];
if (o.editRange(Oe, Nr, !0, (m, f, p) => {
const _ = m.min, S = m.max;
return _ < n && S + 1 >= n && (l = _, h = f), (_ < n || e < 0) && _ - 1 <= r && m.max > r && (c = _, d = f), e > 0 && _ >= n || e < 0 && _ - 1 > r ? g.push([{ min: _ + e, max: S + e }, f]) : i -= S - _ + 1, u = !0, xt.DeleteValue;
}), e > 0) {
const m = h || d;
m && (h = m.slice(0, n - l), c = t + e, d = m.slice(n - l));
} else h && (h = h.slice(0, n - l)), d && (d = d.slice(r + 1 - c), c = t), h && d && l + h.length === c && (h = h.concat(d), d = null);
return h && h.length > 0 && (i += h.length, o.set({ min: l, max: l + h.length - 1 }, h)), d && (i += d.length, o.set({ min: c, max: c + d.length - 1 }, d)), g.length > 0 && o.setPairs(g), this._updateCount(i), u;
}
at(t) {
Oe.min = t;
const e = this._lastRunsRead;
if (e) {
const s = e.min;
if (s <= t && e.max >= t) return this._lastListRead.at(t - s);
}
let n, r;
const o = this._runs.getPairOrNextHigher(Oe, S0);
if (o && (n = o[0], r = o[1]), this._lastRunsRead = n, this._lastListRead = r, !(!n || t < n.min || t > n.max)) return r.at(t - n.min);
}
[Symbol.iterator]() {
return jg(this.entries());
}
clone() {
const t = new tr(this._options);
return t._runs = this._runs.clone(), t._count = this._count, t._dataCoords = this._dataCoords, t._length = this._length, t;
}
getMaxCoords() {
return this._maxCoords || null;
}
getCount() {
return this._count;
}
getRunsCount() {
return this._runs.size;
}
get [Symbol.toStringTag]() {
return "[SparseList]";
}
}
tr || (tr = {});
const u0 = (a) => typeof a != "boolean" ? (a && !a.value && (a.value = [-1, null]), a) : a === !0 ? rc : void 0, g0 = (a, t, e) => {
const n = e ?? { done: !1, value: [-1, null] }, r = n.value;
return r[0] = a, r[1] = t, n;
}, m0 = (a) => typeof a != "boolean" ? (a && !a.value && (a.value = [null, null]), a) : a === !0 ? _0 : void 0, f0 = (a, t, e) => {
const n = e ?? { done: !1, value: [null, null] }, r = n.value;
return r[0] = a, r[1] = t, n;
}, p0 = (a, t = !1, e = 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 (t) {
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 (t) for (let i = s; i < e; i++) r.push(void 0);
return r;
}, _0 = Object.seal({ done: !1, value: [{ min: Number.MIN_SAFE_INTEGER, max: Number.MAX_SAFE_INTEGER }, null] }), rc = Object.seal({ done: !1, value: [-1, null] }), Tr = { reverse: !1, bounds: { min: Number.MIN_SAFE_INTEGER, max: Number.MAX_SAFE_INTEGER }, processSkip: null, reuseResult: rc }, Aa = Object.freeze({ reverse: !1, bounds: { min: Number.MIN_SAFE_INTEGER, max: Number.MAX_SAFE_INTEGER }, processSkip: null, reuseResult: rc }), Oe = { min: 0, max: Number.MAX_SAFE_INTEGER }, Nr = { min: 0, max: Number.MAX_SAFE_INTEGER }, S0 = [null, null], Ma = { bounds: { min: 0, max: 0 }, overflowRun: !0 };
class w0 {
constructor(t = 9) {
this._maxEntries = Math.max(4, t), this._minEntries = Math.max(2, Math.ceil(0.4 * this._maxEntries)), this.clear();
}
all(t) {
return this.data.children.length === 0 ? [] : this._all(this.data, t ?? []);
}
isEmpty() {
return this.data.children.length === 0;
}
search(t, e) {
let n = this.data;
if (n.children.length === 0) return k.EmptyArray;
if (!Es(t, n)) return k.EmptyArray;
const r = e ?? [], o = this.toBBox, s = [];
for (; n; ) {
const i = n.children, l = i.length, c = n.leaf;
for (let h = 0; h < l; h++) {
const d = i[h], u = c ? o(d) : d;
Es(t, u) && (c ? r.push(d) : Na(t, u) ? this._all(d, r) : s.push(d));
}
n = s.pop();
}
return r;
}
collides(t) {
let e = this.data;
if (!Es(t, e)) return !1;
const n = [];
for (; e; ) {
for (let r = 0; r < e.children.length; r++) {
const o = e.children[r], s = e.leaf ? this.toBBox(o) : o;
if (Es(t, s)) {
if (e.leaf || Na(t, s)) return !0;
n.push(o);
}
}
e = n.pop();
}
return !1;
}
load(t) {
if (!t || !t.length) return this;
const e = this._minEntries;
if (t.length < e) {
for (let r = 0; r < t.length; r++) this.insert(t[r]);
return this;
}
let n = this._build(t.slice(), 0, t.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(t) {
return t && this._insert(t, this.data.height - 1), this;
}
clear() {
return this.data = Br([]), this;
}
remove(t, e) {
if (!t) return this;
let n = this.data;
const r = this.toBBox(t), 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 = y0(t, n.children, e);
if (h !== -1) return n.children.splice(h, 1), o.push(n), this._condense(o), this;
}
c || n.leaf || !Na(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(t) {
return t;
}
compareMinX(t, e) {
return t.minX - e.minX;
}
compareMinY(t, e) {
return t.minY - e.minY;
}
toJSON() {
return this.data;
}
fromJSON(t) {
return this.data = t, this;
}
_all(t, e) {
const n = [];
for (; t; ) t.leaf ? e.push(...t.children) : n.push(...t.children), t = n.pop();
return e;
}
_build(t, e, n, r) {
const o = n - e + 1;
let s, i = this._maxEntries;
if (o <= i) return s = Br(t.slice(e, n + 1)), Fr(s, this.toBBox), s;
r || (r = Math.ceil(Math.log(o) / Math.log(i)), i = Math.ceil(o / Math.pow(i, r - 1))), s = Br([]), s.leaf = !1, s.height = r;
const l = Math.ceil(o / i), c = l * Math.ceil(Math.sqrt(i));
Hh(t, e, n, c, this.compareMinX);
for (let h = e; h <= n; h += c) {
const d = Math.min(h + c - 1, n);
Hh(t, h, d, l, this.compareMinY);
for (let u = h; u <= d; u += l) {
const g = Math.min(u + l - 1, d);
s.children.push(this._build(t, u, g, r - 1));
}
}
return Fr(s, this.toBBox), s;
}
_chooseSubtree(t, e, n, r) {
for (; r.push(e), !e.leaf && r.length - 1 !== n; ) {
let o, s = 1 / 0, i = 1 / 0;
for (let l = 0; l < e.children.length; l++) {
const c = e.children[l], h = Ta(c), d = b0(t, c) - h;
d < i ? (i = d, s = h < s ? h : s, o = c) : d === i && h < s && (s = h, o = c);
}
e = o || e.children[0];
}
return e;
}
_insert(t, e, n = !1) {
const r = n ? t : this.toBBox(t), o = [], s = this._chooseSubtree(r, this.data, e, o);
for (s.children.push(t), Po(s, r); e >= 0 && o[e].children.length > this._maxEntries; ) this._split(o, e), e--;
this._adjustParentBBoxes(r, o, e);
}
_split(t, e) {
const n = t[e], r = n.children.length, o = this._minEntries;
this._chooseSplitAxis(n, o, r);
const s = this._chooseSplitIndex(n, o, r), i = Br(n.children.splice(s, n.children.length - s));
i.height = n.height, i.leaf = n.leaf, Fr(n, this.toBBox), Fr(i, this.toBBox), e ? t[e - 1].children.push(i) : this._splitRoot(n, i);
}
_splitRoot(t, e) {
this.data = Br([t, e]), this.data.height = t.height + 1, this.data.leaf = !1, Fr(this.data, this.toBBox);
}
_chooseSplitIndex(t, e, n) {
let r = -1, o = 1 / 0, s = 1 / 0;
for (let i = e; i <= n - e; i++) {
const l = zo(t, 0, i, this.toBBox), c = zo(t, i, n, this.toBBox), h = v0(l, c), d = Ta(l) + Ta(c);
h < o ? (o = h, r = i, s = d < s ? d : s) : h === o && d < s && (s = d, r = i);
}
return r || n - e;
}
_chooseSplitAxis(t, e, n) {
const r = t.leaf ? this.compareMinX : C0, o = t.leaf ? this.compareMinY : E0;
this._allDistMargin(t, e, n, r) < this._allDistMargin(t, e, n, o) && t.children.sort(r);
}
_allDistMargin(t, e, n, r) {
t.children.sort(r);
const o = this.toBBox, s = zo(t, 0, e, o), i = zo(t, n - e, n, o);
let l = Cs(s) + Cs(i);
for (let c = e; c < n - e; c++) {
const h = t.children[c];
Po(s, t.leaf ? o(h) : h), l += Cs(s);
}
for (let c = n - e - 1; c >= e; c--) {
const h = t.children[c];
Po(i, t.leaf ? o(h) : h), l += Cs(i);
}
return l;
}
_adjustParentBBoxes(t, e, n) {
for (let r = n; r >= 0; r--) Po(e[r], t);
}
_condense(t) {
for (let e, n = t.length - 1; n >= 0; n--) t[n].children.length === 0 ? n > 0 ? (e = t[n - 1].children, e.splice(e.indexOf(t[n]), 1)) : this.clear() : Fr(t[n], this.toBBox);
}
}
function y0(a, t, e) {
if (!e) return t.indexOf(a);
for (let n = 0; n < t.length; n++) if (e(a, t[n])) return n;
return -1;
}
function Fr(a, t) {
zo(a, 0, a.children.length, t, a);
}
function zo(a, t, e, n, r = null) {
r || (r = Br(null)), r.minX = 1 / 0, r.minY = 1 / 0, r.maxX = -1 / 0, r.maxY = -1 / 0;
for (let o = t; o < e; o++) {
const s = a.children[o];
Po(r, a.leaf ? n(s) : s);
}
return r;
}
function Po(a, t) {
return a.minX = Math.min(a.minX, t.minX), a.minY = Math.min(a.minY, t.minY), a.maxX = Math.max(a.maxX, t.maxX), a.maxY = Math.max(a.maxY, t.maxY), a;
}
function C0(a, t) {
return a.minX - t.minX;
}
function E0(a, t) {
return a.minY - t.minY;
}
function Ta(a) {
return (a.maxX - a.minX) * (a.maxY - a.minY);
}
function Cs(a) {
return a.maxX - a.minX + (a.maxY - a.minY);
}
function b0(a, t) {
return (Math.max(t.maxX, a.maxX) - Math.min(t.minX, a.minX)) * (Math.max(t.maxY, a.maxY) - Math.min(t.minY, a.minY));
}
function v0(a, t) {
const e = Math.max(a.minX, t.minX), n = Math.max(a.minY, t.minY), r = Math.min(a.maxX, t.maxX), o = Math.min(a.maxY, t.maxY);
return Math.max(0, r - e) * Math.max(0, o - n);
}
function Na(a, t) {
return a.minX <= t.minX && a.minY <= t.minY && t.maxX <= a.maxX && t.maxY <= a.maxY;
}
function Es(a, t) {
return t.minX <= a.maxX && t.minY <= a.maxY && t.maxX >= a.minX && t.maxY >= a.minY;
}
function Br(a) {
return { children: a, height: 1, leaf: !0, minX: 1 / 0, minY: 1 / 0, maxX: -1 / 0, maxY: -1 / 0 };
}
function Hh(a, t, e, n, r) {
const o = [t, e];
for (; o.length; ) {
if ((e = o.pop()) - (t = o.pop()) <= n) continue;
const s = t + Math.ceil((e - t) / n / 2) * n;
$g(a, s, t, e, r), o.push(t, s, s, e);
}
}
function $g(a, t, e, n, r) {
for (; n > e; ) {
if (n - e > 600) {
const l = n - e + 1, c = t - e + 1, h = Math.log(l), d = 0.5 * Math.exp(2 * h / 3), u = 0.5 * Math.sqrt(h * d * (l - d) / l) * (c - l / 2 < 0 ? -1 : 1);
$g(a, t, Math.max(e, Math.floor(t - c * d / l + u)), Math.min(n, Math.floor(t + (l - c) * d / l + u)), r);
}
const o = a[t];
let s = e, i = n;
for (_o(a, e, t), r(a[n], o) > 0 && _o(a, e, n); s < i; ) {
for (_o(a, s, i), s++, i--; r(a[s], o) < 0; ) s++;
for (; r(a[i], o) > 0; ) i--;
}
r(a[e], o) === 0 ? _o(a, e, i) : (i++, _o(a, i, n)), i <= t && (e = i + 1), t <= i && (n = i - 1);
}
}
function _o(a, t, e) {
const n = a[t];
a[t] = a[e], a[e] = n;
}
class Vh extends w0 {
toBBox(t) {
return { minX: 10 * t.colStart, minY: 10 * t.rowStart, maxX: 10 * t.colEnd + 5, maxY: 10 * t.rowEnd + 5 };
}
compareMinX(t, e) {
return t.colStart - e.colStart;
}
compareMinY(t, e) {
return t.rowStart - e.rowStart;
}
isEmpty() {
return this.data.children.length === 0;
}
searchRange(t, e = !1, n) {
if (this.isEmpty()) return k.EmptyArray;
const r = this.search(this.toBBox(t), n);
return e ? r.filter((o) => o.colStart >= t.colStart && o.rowStart >= t.rowStart && o.colEnd <= t.colEnd && o.rowEnd <= t.rowEnd) : r;
}
}
class Nt {
constructor(t) {
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 = t, this._rTree = new Vh(t?.maxNodeEntries ?? 16);
}
visitRanges(t, e, n = null) {
let r = this.search(t);
n && (r = jn(r, n));
const o = [], s = [];
let i = null;
const l = r.length;
for (let c = 0; !i && c < l; c++) {
const h = r[c], d = e?.(h);
d && (d.delete === !0 ? s.push(h) : d.update !== void 0 && (s.push(h), o.push(d.update)), d && d.break === !0 && (i = d));
}
for (let c = 0; c < s.length; c++) this.remove(s[c]);
return this.load(o), i;
}
getBoundingCoords() {
const t = this._getReadTree().toJSON();
return t && t.children && t.children.length !== 0 ? { colStart: t.minX / 10, rowStart: t.minY / 10, colEnd: (t.maxX - 5) / 10, rowEnd: (t.maxY - 5) / 10 } : null;
}
size() {
return this._getReadTree().all().length;
}
isEmpty() {
return this._getReadTree().isEmpty();
}
search(t, e = !1, n) {
const r = this._getReadTree();
if (r.isEmpty()) return k.EmptyArray;
let o;
if (!e) {
if (o = this._lastMiss, o.colStart !== Number.MAX_SAFE_INTEGER && L.isRangeWithinRange(t, o)) return k.EmptyArray;
if (this._lastSingle && L.isRangeWithinRange(t, o)) return this._lastSingleResult;
}
const s = r.searchRange(t, e, n);
return e || (s.length === 0 ? (o.colStart = t.colStart, o.rowStart = t.rowStart, o.colEnd = t.colEnd, o.rowEnd = t.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(t) {
const e = this._getReadTree();
return e.collides(e.toBBox(t));
}
all(t) {
return this._getReadTree().all(t);
}
shift(t) {
const e = t.range, n = t.direction, r = t.cloneIfUpdate ?? !1, o = t.coordValidator ?? null, s = t.onShift ?? null, i = n === $t.Left || n === $t.Right, l = i ? yt.Column : yt.Row, c = n === $t.Up || n === $t.Left ? -1 : 1, h = (i ? e.colEnd - e.colStart + 1 : e.rowEnd - e.rowStart + 1) * c, d = [], u = [];
let g = null;
const m = this.getBoundingCoords();
if (!m) return this;
const f = n === $t.Up || n === $t.Left ? $t.Right : $t.Left, p = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map(), S = this._options?.updateEntryOptions, C = S?.isMergeOnShift ?? !1, y = S?.isSplitOnExpand ?? !1, E = S?.isTrailingEdge ?? !1, w = n === $t.Left || n === $t.Up, b = S?.getSplit ?? ni, v = S?.getShifted, I = S?.onShifted, x = S?.onRemoved, R = S?.onMerged, A = S?.onUpdated, M = I ? [] : null, T = x ? [] : null, O = A ? [] : null;
this.visitRanges({ colStart: e.colStart - (i ? 1 : 0), rowStart: e.rowStart - (i ? 0 : 1), colEnd: i ? m.colEnd : e.colEnd, rowEnd: i ? e.rowEnd : m.rowEnd }, (z) => {
if ((i ? z.colEnd < e.colStart : z.rowEnd < e.rowStart) && !E) return;
const B = A0(e, z, i ? zr.Column : zr.Row), H = z.group;
if (w && !H && e.colStart <= z.colStart && e.rowStart <= z.rowStart && e.colEnd >= z.colEnd && e.rowEnd >= z.rowEnd) {
const V = Gh(z, null, { after: null, before: z, intersect: e, isSplit: B, orientation: l, amount: h }, v, b, s, !1);
if (V === void 0) return;
if (V === null) return g = L.unionRanges(g, z), T && T.push(z), void d.push(z);
}
let P = { ...z };
n === $t.Right ? (e.colStart <= P.colStart && (P.colStart += h), P.colEnd += h) : n === $t.Left ? e.colStart < P.colStart ? (P.colStart = Math.max(P.colStart + h, e.colStart), P.colEnd = Math.max(P.colEnd + h, P.colStart - 1)) : P.colEnd += Math.max(h, e.colStart - P.colEnd - 1) : n === $t.Down ? (e.rowStart <= P.rowStart && (P.rowStart += h), P.rowEnd += h) : n === $t.Up && (e.rowStart < P.rowStart ? (P.rowStart = Math.max(P.rowStart + h, e.rowStart), P.rowEnd = Math.max(P.rowEnd + h, e.rowStart - 1)) : P.rowEnd += Math.max(h, e.rowStart - P.rowEnd - 1)), (P.colEnd < P.colStart || P.rowEnd < P.rowStart) && (P = null);
const j = Gh(z, P, { after: P, before: z, intersect: e, isSplit: B, orientation: l, amount: h }, v, b, s, y && h > 0);
if (j === void 0) return;
const G = j === null ? [P] : j, K = G.length;
if (G[0] !== z || K !== 1) {
if (o) for (let $ = 0; $ < K; $++) {
const J = G[$];
J && o(J);
}
let V;
H ? (p.set(H.uuid, H), V = [], _.set(z.uuid, V)) : d.push(z);
for (let $ = 0; $ < K; $++) {
const J = G[$];
g = L.unionRanges(g, J), H ? V.push(J) : (u.push(J), M && M.push(J), O && O.push(z));
}
}
}, f);
let W = null;
W = r && (d.length > 0 || u.length > 0 || _.size > 0) ? this.clone() : this, W._updateNodes(u, d), _.size > 0 && W._updateGroupedEntries(p, _);
let D = k.EmptyArray;
if (C && m && g) {
let z = !0;
if (h > 0 && (z = i ? e.rowStart > m.rowStart || e.rowEnd < m.rowEnd : e.colStart > m.colStart || e.colEnd < m.colEnd), z) {
const B = jh(g, L.unionRanges(m, g), i ? 0 : 1, i ? 1 : 0);
R && (D = W._mergeNodes(B, !1));
}
}
return A && O.length > 0 && A(O), I && M.length > 0 && I(M), R && D.length > 0 && R(D), x && T.length > 0 && x(T), W;
}
insertNonOverlapping(t, e) {
const n = e?.onIntersect ?? ((C, y) => ({ ...C, value: y.value })), r = this.search(t), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), i = this._options?.updateEntryOptions, l = i?.onUpdated, c = i?.onRemoved, h = i?.onMerged, d = i?.getSplit, u = i?.getIntersect, g = i?.getUpdate;
let m = null, f = null, p = null, _ = (function(C, y, E) {
const w = E?.getIntersect ?? I0, b = E?.getUpdate ?? R0;
if (C.length === 0) {
if (w) {
const B = w({ ...y, value: null }, y);
y = B && B.value !== null ? { ...B } : null;
}
if (b) {
const B = b(y);
B !== void 0 && (y = B);
}
return y ? [y] : k.EmptyArray;
}
const v = E?.getSplit ?? x0, I = (B, H, P = !0) => {
const j = H.search(B), G = j.length;
for (let K = 0; K < G; K++) {
const V = j[K];
if (L.isEqualRanges(V, B)) continue;
H?.remove(V);
const $ = eo(V, B, v, P);
for (let J = 0; J < $.length; J++) {
const Z = $[J];
H.insert(Z), I(Z, H, !1);
}
}
}, x = new Nt();
x.load(C), I(y, x);
const R = new Nt();
R.load([y]);
const A = x.search(y);
for (let B = 0; B < A.length; B++) I(A[B], R);
const M = (B, H, P) => {
let j = H.search(B);
console.assert(j.length <= 1, "intersecting incorrect ranges");
const G = j[0] ?? { ...B, value: null };
if (L.isEqualRanges(G, B)) {
let K = w(G, B);
H.remove(G), P.insert(K);
} else {
H.remove(G);
const K = eo(G, B, v), V = K.length;
for (let $ = 0; $ < V; $++) {
const J = K[$];
if (L.isEqualRanges(J, B)) {
const Z = w(J, B);
P.insert(Z);
} else H.insert(J);
}
}
}, T = new Nt(), O = R.all(), W = O.length;
for (let B = 0; B < W; B++) M(O[B], x, T);
const D = (B, H) => {
const P = B.all(), j = P.length;
for (let G = 0; G < j; G++) {
let K = P[G];
if (b) {
const V = b(K);
V !== void 0 && (K = V);
}
K !== null && K.value !== null && H.push(K);
}
}, z = x.all();
return D(T, z), z;
})(r, t, { getSplit: (C, y, E, w) => {
let b;
return d ? (b = d(C, y, E, w), b) : (b = ni(C, y, E, w), b);
}, getIntersect: (C, y) => {
u && (y = u(C, y));
const E = n(C, y);
return E === void 0 || (E === null || E.value === null) && C.value?.onRemove?.(C), E;
}, getUpdate: (C) => {
const y = C?.group;
if (y) {
o.set(y.uuid, y);
let w = s.get(C.lastId ?? C.uuid);
w || (w = [], s.set(C.lastId ?? C.uuid, w)), w.push(C.value === null ? null : C);
}
let E = C;
if (g && (E = g(C)), E && E.value !== null) l && (m || (m = []), m.push(E));
else if (c && !p) {
p = [];
let w = E && E.value === null ? E : { ...C, value: null };
p.push(w);
}
return E;
} });
const S = this.getBoundingCoords();
if (o.size > 0) {
const C = [], y = _.length;
for (let E = 0; E < y; E++) {
let w = _[E];
w.group || C.push(w);
}
_ = C;
}
if (this._updateNodes(_, r, e?.onUpdates), o.size > 0 && this._updateGroupedEntries(o, s), S && !i?.noMerge && !e?.noMerge) {
const C = jh(t, L.unionRanges(S, t)), y = this.search(C);
if (y.length > 1) {
const E = i?.getMerged ?? $h;
let w = y;
w = an(w, yt.Column, 1, E), w = an(w, yt.Row, 1, E), y.length !== w.length && (h && w.length > 0 && (f = w), this._updateNodes(w, y, e?.onUpdates));
}
}
return m && l(m), f && h(f), p && c(p), this;
}
insertGroup(t, e) {
e = e ?? k.uuidV4();
const n = [], r = t.length;
for (let o = 0; o < r; o++) {
const s = { ...t[o], group: { entries: n, uuid: e, offset: o }, uuid: k.uuidV4() };
n.push(s), t[o] = s;
}
return this.load(t), this._options?.updateEntryOptions?.onGroupUpdate?.(t, e), this;
}
createCopiedEntries(t, e, n, r, o) {
return M0(this, t, e, n, r, o, this._options?.updateEntryOptions?.getSplit ?? ni);
}
_updateGroupedEntries(t, e) {
const n = [], r = [], o = /* @__PURE__ */ new Map(), s = t.values();
let i = s.next();
for (; !i.done; ) {
const l = i.value, c = l.entries, h = l.uuid, d = [];
for (let u = 0; u < c.length; u++) {
let g = c[u];
n.push(g);
let m = e.get(g.uuid);
m === void 0 && (m = [{ ...g }]);
for (let f = 0; f < m.length; f++) {
let p = m[f];
p !== null && (p = { ...p, group: { offset: d.length, entries: d, uuid: h } }, d.push(p), r.push(p));
}
}
d.sort((u, g) => u.group.offset - g.group.offset), o.set(h, d), 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 d = h.value[0];
l(h.value[1], d), h = c.next();
}
}
}
}
_copy(t, e) {
let n = t.rTree.all();
const r = new Vh(this._options?.maxNodeEntries);
return e && (n = n.concat(e)), n.length > 0 && r.load(n), { refCount: 1, rTree: r };
}
_updateNodes(t, e, n) {
if (!(t && t.length !== 0 || e && e.length !== 0)) return;
const r = this._getWritableTree();
if (e) {
const o = e.length;
for (let s = 0; s < o; s++) r.remove(e[s]);
}
t.length > 0 && r.load(t), n?.(t, e, this), this._options?.updateEntryOptions?.onUpdates?.(t, e, this);
}
_mergeNodes(t, e) {
const n = this.search(t, e);
let r = k.EmptyArray;
if (n.length > 1) {
const o = this._options?.updateEntryOptions.getMerged ?? $h;
let s = n;
s.length > 1 && (s = an(s, yt.Column, 1, o)), s.length > 1 && (s = an(s, yt.Row, 1, o)), n.length !== s.length && (r = s, this._updateNodes(s, n));
}
return r;
}
_getReadTree() {
return this._shared?.rTree ?? this._rTree;
}
_ensureWritable(t) {
const e = this._shared;
if (!e) return;
if (e.refCount--, e.refCount === 0) return this._shared = null, void (t && this._rTree.load(t));
const n = this._copy(e, t);
this._shared = null, this._rTree = n.rTree;
}
_getWritableTree(t) {
return this._lastMiss.colStart = Number.MAX_SAFE_INTEGER, this._lastSingle = null, this._lastSingleResult = null, this._shared ? (this._ensureWritable(t), this._rTree) : (t && this._rTree.load(t), this._rTree);
}
remove(t, e) {
return t && this._getWritableTree().remove(t, e ?? L.isEqualRanges), this;
}
insert(t) {
return t && this._getWritableTree().insert(t), this;
}
load(t) {
return t && t.length > 0 && this._getWritableTree(t), this;
}
clear() {
return this.isEmpty() || this._getWritableTree().clear(), this;
}
clone(t = null) {
if (t !== null && this._cloneKey === t) return this;
let e = this._shared;
e || (e = { rTree: this._rTree, refCount: 1 }, this._shared = e), e.refCount++;
const n = new Nt(this._options);
return n._shared = e, n._cloneKey = t, n;
}
fromJSON(t) {
return this._getWritableTree().fromJSON(t), this;
}
}
const jh = (a, t = a, e = 1, n = 1) => ({ ...a, colStart: Math.max(a.colStart - e, t.colStart), rowStart: Math.max(a.rowStart - n, t.rowStart), colEnd: Math.min(a.colEnd + e, t.colEnd), rowEnd: Math.min(a.rowEnd + n, t.rowEnd) });
function x0(a, t, e, n) {
return [{ ...t[0], value: a.value }, { ...t[0], value: a.value }];
}
function I0(a, t) {
return { ...a };
}
function eo(a, t, e = null, n = !0) {
if (L.isEqualRanges(a, t)) return [{ ...a }];
const r = L.intersectRanges(a, t, T0);
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 = k.uuidV4());
const c = { ...i, colStart: i.colStart, rowStart: r.rowStart, colEnd: i.colEnd, rowEnd: i.rowEnd };
s && (n && (c.lastId = s), c.uuid = k.uuidV4());
const h = c.rowStart - l.rowStart;
De[0] = l, De[1] = c;
const d = e(i, De, yt.Row, h);
d !== void 0 && (o.push(d[0]), i = d[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 = k.uuidV4());
const c = { ...i, colStart: i.colStart, rowStart: r.rowEnd + 1, colEnd: i.colEnd, rowEnd: i.rowEnd };
s && (n && (c.lastId = s), c.uuid = k.uuidV4());
const h = c.rowStart - l.rowStart;
De[0] = l, De[1] = c;
const d = e(i, De, yt.Row, h);
d !== void 0 && (o.push(d[1]), i = d[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 = k.uuidV4());
const c = { ...i, colStart: r.colStart, rowStart: i.rowStart, colEnd: i.colEnd, rowEnd: i.rowEnd };
s && (n && (c.lastId = s), c.uuid = k.uuidV4());
const h = c.colStart - l.colStart;
De[0] = l, De[1] = c;
const d = e(i, De, yt.Column, h);
d !== void 0 && (o.push(d[0]), i = d[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 = k.uuidV4());
const c = { ...i, colStart: r.colEnd + 1, rowStart: i.rowStart, colEnd: i.colEnd, rowEnd: i.rowEnd };
s && (n && (c.lastId = s), c.uuid = k.uuidV4());
const h = c.colStart - l.colStart;
De[0] = l, De[1] = c;
const d = e(i, De, yt.Column, h);
d !== void 0 && (o.push(d[1]), i = d[0]);
}
return i === a && (i = { ...a }), o.push(i), o;
}
function R0(a) {
return a.value === null ? null : a;
}
function an(a, t = yt.Column, e = 2, n, r) {
let o = [...a];
if (e <= 0 || a.length <= 1) return o;
let s = t === yt.Column, i = 0, l = !1;
do {
const c = o.sort(L.createRangeComparator(s ? yt.Row : yt.Column));
o = [], l = !1, o.push(c[0]);
for (let h = 1; h < c.length; h++) {
const d = c[h], u = o[o.length - 1];
let g = !1;
if (g = s ? u && u.rowStart === d.rowStart && u.rowEnd === d.rowEnd && u.colEnd + 1 === d.colStart : u && u.colStart === d.colStart && u.colEnd === d.colEnd && u.rowEnd + 1 === d.rowStart, g) {
let m = { ...u, colEnd: s ? d.colEnd : u.colEnd, rowEnd: s ? u.rowEnd : d.rowEnd };
if (n) {
const f = r ?? [null, null];
f[0] = u, f[1] = d, m = n(f, m, t);
}
if (m) {
o[o.length - 1] = m, l = !0;
continue;
}
}
o.push(d);
}
i++, s = !s;
} while (i < e && l && o.length > 1);
return o;
}
const Al = (a, t = 2, e = yt.Row, n, r, o) => {
if (a.length <= 1) return [...a];
let s = [];
const i = e === yt.Column, l = new Qo.IteratorInstance(a, { orientation: i ? yt.Row : yt.Column });
let c = l.next();
for (; !c.done; ) {
const h = c.value;
c = l.next();
const d = h.range;
if (t > 0) {
const u = s[s.length - 1];
let g = !1;
if (g = i ? u && u.rowStart === d.rowStart && u.rowEnd === d.rowEnd && u.colEnd + 1 === d.colStart : u && u.colStart === d.colStart && u.colEnd === d.colEnd && u.rowEnd + 1 === d.rowStart, g) {
let m = { ...u, colEnd: i ? d.colEnd : u.colEnd, rowEnd: i ? u.rowEnd : d.rowEnd };
if (m) {
s[s.length - 1] = m;
continue;
}
}
}
s.push(d);
}
return t > 1 && (s = an(s, i ? yt.Row : yt.Column, t, n, o)), s;
};
function ni(a, t, e, n) {
const r = a.value;
if (r?.getSplit) {
const o = r.getSplit(t, e, n);
if (o === void 0) return;
t[0].value = o[0], t[1].value = o[1];
}
return t;
}
function $h(a, t, e) {
const n = a[0].value, r = a[1].value;
if (n?.getMerged && r) {
const o = n.getMerged(a[1].value, L.sanitizeRange(t), e);
if (o === void 0) return;
t.value = o;
}
return t;
}
const A0 = (a, t, e = zr.Both) => {
const n = (s) => s ? a.rowStart > t.rowStart && a.rowStart <= t.rowEnd || a.rowEnd < t.rowEnd && a.rowEnd >= t.rowStart : a.colStart > t.colStart && a.colStart <= t.colEnd || a.colEnd < t.colEnd && a.colEnd >= t.colStart;
let r = e === zr.Column, o = e === zr.Row;
return e === zr.Both && (r = o = !0), !(!r || !n(!0)) || !(!o || !n(!1));
};
function Gh(a, t, e, n, r, o, s) {
const i = e.orientation === yt.Column, l = e.intersect, c = (h, d) => {
let u = h.value, g = null, m = d.after;
if (s) {
let f = null, p = 0, _ = 0;
if (i && l.colStart > h.colStart ? (f = { ...h, colEnd: l.colStart - 1 }, _ = d.amount) : !i && l.rowStart > h.rowStart && (f = { ...h, rowEnd: l.rowStart - 1 }, p = d.amount), f) {
const S = eo(a, f, r);
if (S.length > 1) for (let C = 0; C < S.length; C++) {
let y = S[C];
L.isEqualRanges(y, f) ? (g = g ?? [], g.push(y)) : (m = y, u = y.value, d = { ...d, after: { ...y, colStart: y.colStart + _, rowStart: y.rowStart + p, colEnd: y.colEnd + _, rowEnd: y.rowEnd + p, uuid: k.uuidV4() }, before: y, intersect: f, isSplit: !0 });
}
}
}
if (n ? m = n(d.before, d.after, d) : u && u.getShifted ? m = u.getShifted(d) : d.after && (m = { ...d.after, value: h.value }), m !== void 0) return o && (m !== d.after && (d = { ...d, after: m }), o(d)), m = ((f) => {
if (!f) {
const p = a.value;
return p.onRemove && p.onRemove(L.sanitizeRange(e.before)), null;
}
return f;
})(m), m && (g = g ?? [], g.push(m)), g;
};
if (e.isSplit) {
let h;
h = i ? { ...a, rowStart: Math.max(l.rowStart, e.before.rowStart), rowEnd: Math.min(l.rowEnd, e.before.rowEnd) } : { ...a, colStart: Math.max(l.colStart, e.before.colStart), colEnd: Math.min(l.colEnd, e.before.colEnd) };
const d = eo(a, h, r), u = [];
for (let g = 0; g < d.length; g++) {
const m = d[g];
if (L.isEqualRanges(m, h)) {
let f = null;
t && (f = i ? { colStart: t.colStart, rowStart: h.rowStart, colEnd: t.colEnd, rowEnd: h.rowEnd, value: m.value } : { colStart: h.colStart, rowStart: t.rowStart, colEnd: h.colEnd, rowEnd: t.rowEnd, value: m.value });
const p = c(m, { ...e, before: m, after: f });
if (p) for (let _ = 0; _ < p.length; _++) u.push(p[_]);
} else u.push(m);
}
return u;
}
return c(a, e);
}
const M0 = (a, t, e, n, r, o, s) => {
const i = e.colEnd - e.colStart + 1, l = e.rowEnd - e.rowStart + 1, c = e.colStart - t.colStart, h = e.rowStart - t.rowStart, d = n?.transpose ?? !1;
let u = 1, g = 1;
d ? (u = t.rowEnd - t.rowStart + 1, g = t.colEnd - t.colStart + 1) : (u = t.colEnd - t.colStart + 1, g = t.rowEnd - t.rowStart + 1);
const m = Math.ceil(i / u), f = Math.ceil(l / g), p = r ?? [], _ = o ?? k.EmptyArray, S = e.colEnd, C = e.rowEnd;
return a.visitRanges(t, (y) => {
let E = y.value;
if (!E.copyTo) return;
let w = y;
if (!L.isRangeWithinRange(w, t)) {
const O = eo(w, t, s);
w = O[O.length - 1];
}
E = w.value;
let b = w.colEnd - w.colStart + 1, v = w.rowEnd - w.rowStart + 1, I = c + w.colStart, x = h + w.rowStart;
if (d) {
I = w.rowStart - t.rowStart + e.colStart, x = w.colStart - t.colStart + e.rowStart;
const O = b;
b = v, v = O;
}
let R = m, A = f;
const M = i <= R * b, T = l <= A * v;
if (M || T) {
const O = E?.canTile?.({ colStart: I, rowStart: x, colEnd: Math.min(I + (M ? i : b) - 1, S), rowEnd: Math.min(x + (T ? l : v) - 1, C) }, n);
!M || O !== !0 && O !== yt.Column || (b = i, R = 1), !T || O !== !0 && O !== yt.Row || (v = l, A = 1);
}
for (let O = 0; O < R; O++) {
const W = I + O * u;
for (let D = 0; D < A; D++) {
const z = x + D * g, B = Math.min(W + b - 1, S), H = Math.min(z + v - 1, C), P = { colStart: W, rowStart: z, colEnd: B, rowEnd: H };
if (W > B || z > H) continue;
const j = E.copyTo(P, n);
j && p.push({ ...P, value: j });
}
}
}, $t.Right), { inserts: p, removes: _ };
}, De = [null, null], T0 = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0 }, Te = (a = Number.MIN_SAFE_INTEGER, t = Number.MIN_SAFE_INTEGER, e = Number.MAX_SAFE_INTEGER, n = Number.MAX_SAFE_INTEGER, r, o, s) => {
if (o && (a !== Number.MIN_SAFE_INTEGER && a < o.colStart || t !== Number.MIN_SAFE_INTEGER && t < o.rowStart || e !== Number.MAX_SAFE_INTEGER && e > o.colEnd || n !== Number.MAX_SAFE_INTEGER && n > o.rowEnd)) throw new Wt();
return s && (a = Math.max(s.colStart, a), t = Math.max(s.rowStart, t), e = Math.min(s.colEnd, e), n = Math.min(s.rowEnd, n), e < a || n < t) ? null : (So.majorStart = r ? a : t, So.majorEnd = r ? e : n, So.minorStart = r ? t : a, So.minorEnd = r ? n : e, So);
}, Zo = (a, t, e) => {
const n = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0 };
return n.colStart = t ? a.majorStart : a.minorStart, n.rowStart = t ? a.minorStart : a.majorStart, n.colEnd = t ? a.majorEnd : a.minorEnd, n.rowEnd = t ? a.minorEnd : a.majorEnd, n;
}, So = { majorStart: 0, majorEnd: 0, minorStart: 0, minorEnd: 0 }, Uh = (a, t) => a[0] - t[0];
class Gg {
constructor(t, e) {
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 = t;
const n = (e.orientation ?? yt.Column) === yt.Column;
this._isColumn = n, this._isReverse = e.reverse ?? !1, this._skipMajors = e.skipMajors ?? !1;
const r = e.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 ? e.processColumnSkip : e.processRowSkip, this._processMinorSkip = n ? e.processRowSkip : e.processColumnSkip;
const c = t.next();
this._delegateResult = c, this._initialize();
}
_initialize() {
const t = this._isColumn, e = this._isReverse, n = e ? -1 : 1;
let r = e ? this._majorMax : this._majorMin, o = (e ? this._minorMax : this._minorMin) - n;
const s = this._processMinorSkip;
s && (o = s(o, e));
const i = this._processMajorSkip;
i && (r = i(r, e)), 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 = t ? c.colIndex : c.rowIndex, this._delegateMinorIndex = t ? c.rowIndex : c.colIndex;
}
}
next(t) {
t !== void 0 && (this._delegateResult = this._delegate.next(t), this._initialize());
const e = this._isReverse, n = this._isColumn, r = this._majorMin, o = this._majorMax;
let s = this._majorIndex, i = this._minorIndex;
if (s > o || s < r) return Lt;
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 = e ? r : o, l = e ? 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 d = e ? -1 : 1;
if (this._minorIndex = i += d, s === l && i === c && !h) return this._delegateResult;
const u = this._processMinorSkip;
if (u && (i = u(i, e)), i > this._minorMax || i < this._minorMin) {
s += d;
const g = this._processMajorSkip;
g && (s = g(s, e)), this._skipMajors && (!e && s < l || e && s > l) && (s = l), this._majorIndex = s, i = e ? this._minorMax : this._minorMin;
}
return this._minorIndex = i, s === l && i === c && !h ? this._delegateResult : s > o || s < r ? Lt : { done: !1, value: [{ colIndex: n ? s : i, rowIndex: n ? i : s }] };
}
return(t) {
return null;
}
throw(t) {
return null;
}
[Symbol.iterator]() {
return this;
}
}
class Ml {
constructor(t) {
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 e = t.delegate;
this._delegate = e;
const n = (t.orientation ?? yt.Column) === yt.Column;
this._isColumn = n;
const r = t.dims, o = t.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 = e.next();
this._nextDelegateResult = h, this._initialize();
}
_initialize() {
const t = this._isColumn, e = this._nextDelegateResult;
if (e.done) this._nextResult = Lt;
else {
const n = e.value[0], r = t ? n.colIndex : n.rowIndex, o = t ? n.rowIndex : n.colIndex, s = [[o, e.value[1]]];
this._minorSpan = s, this._majorIndex = r, this._minorIndex = o, this._pattern.push([r, s]), this._nextResult = e;
}
}
next(t) {
if (t !== void 0) throw new Pu();
const e = 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, d = h[0], u = n ? d.colIndex : d.rowIndex, g = n ? d.rowIndex : d.colIndex;
if (u === r) return this._minorSpan.push([g, h[1]]), this._minorOffset = this._minorSpan.length - 1, this._minorIndex = g, this._nextResult = o, e;
}
}
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 d = h[c], u = this._minorMin;
if (i = u + (d[0] - u + this._minorSize * this._minorRepeat), this._minorIndex = i, this._minorOffset = c, i <= s) {
const g = [{ colIndex: n ? r : i, rowIndex: n ? i : r }, d[1]];
return this._nextResult = { done: !1, value: g }, e;
}
}
if (!o.done) {
const c = o.value, h = c[0], d = n ? h.colIndex : h.rowIndex, u = n ? h.rowIndex : h.colIndex, g = [[u, c[1]]];
return this._pattern.push([d, g]), this._majorIndex = d, this._minorSpan = g, this._minorOffset = 0, this._minorIndex = u, this._minorRepeat = 0, this._nextResult = o, e;
}
const l = this._majorMax;
if (r < l) {
let c = this._majorOffset;
c++;
const h = this._pattern;
c >= h.length && (c = 0, this._majorRepeat++);
const d = h[c], u = d[1], g = u[0], m = this._majorMin;
if (r = m + (d[0] - m + this._majorSize * this._majorRepeat), this._majorIndex = r, this._majorOffset = c, r <= l) {
this._minorSpan = u, 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 }, e;
}
}
return e.done || (this._nextResult = Lt), e;
}
return(t) {
return null;
}
throw(t) {
return null;
}
[Symbol.iterator]() {
return this;
}
}
class qh {
constructor(t, e, n) {
this._comparator = t?.comparator ?? L.createCellComparator(t.orientation ?? yt.Column, t.reverse ?? !1), this._iterator1 = e, this._iterator2 = n;
const r = e.next();
this._nextResult1 = r;
const o = n.next();
this._nextResult2 = o, t?.reuseResult && (t.reuseResult === !0 ? this._reuseResult = { done: !1, value: [void 0, void 0, void 0, void 0] } : this._reuseResult = t.reuseResult);
}
next(t) {
let e = this._nextResult1, n = this._nextResult2;
if (e.done && n.done) return e;
if (e.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 = e;
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)(e.value[0], n.value[0]);
if (r < 0) {
const i = e;
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] = e.value[0], s[1] = e.value[1], s[2] = n.value[0], s[3] = n.value[1], o;
}
return(t) {
return null;
}
throw(t) {
return null;
}
[Symbol.iterator]() {
return this;
}
}
const Jh = "Must be an array of arrays.", ri = (a, t, e) => {
const n = t.majorStart, r = t.minorStart, o = t.majorEnd, s = [], i = t.minorEnd - r + 1, l = typeof a == "function";
for (let c = n; c <= o; c++) {
const h = new Array(i);
if (l) if (e) {
let u = r;
for (let g = 0; g < i; g++) h[g] = a(u++, c);
} else {
let u = r;
for (let g = 0; g < i; g++) h[g] = a(c, u++);
}
else h.fill(a, 0, i);
const d = [[r, h]];
s.push([c, d]);
}
return { tuples: s, bounds: t };
}, xi = (a, t = !1, e = null, n = !1) => {
let r = 0, o = 0, s = Number.MAX_SAFE_INTEGER, i = Number.MAX_SAFE_INTEGER;
if (e && (r = e.majorStart ?? 0, o = e.minorStart ?? 0, s = (e.majorEnd ?? Number.MAX_SAFE_INTEGER) - r + 1, i = (e.minorEnd ?? Number.MAX_SAFE_INTEGER) - o + 1), t) {
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 Wt();
const l = t ? new zt.TransposedBuilder() : new zt.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 Wt();
if (n) {
let d = -1;
for (let u = 0; u < h.length; u++)
h[u] == null ? d !== -1 && (l.addValues(c + r, o + d, h.slice(d, u)), d = -1) : d === -1 && (d = u);
d !== -1 && l.addValues(c + r, o + d, h.slice(d));
} else l.addValues(c + r, o, h);
}
}
return l.build();
}, N0 = (a, t, e) => {
if (a === t) return t;
}, F0 = (a, t, e) => {
if (a[0].value === a[1].value) return t;
}, k0 = [null, null], Yn = (a = !0, t = N0) => {
const e = [];
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 : t(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 && e.push(n);
const d = a ? i : l, u = a ? l : i;
n = { colStart: d, rowStart: u, colEnd: d, rowEnd: u, value: c }, o = i, s = l, r = c;
}, done: (i = !1) => (n && (e.push(n), n = null), i ? an(e, a ? yt.Column : yt.Row, 2, F0, k0) : e) };
};
class hn {
constructor(t) {
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: yt.Row, ...t }, this._isColumn = (t?.orientation ?? yt.Column) === yt.Column, t?.maxCoords && (this._maxCoords = Object.freeze({ colStart: Math.max(0, t.maxCoords.colStart ?? 0), rowStart: Math.max(0, t.maxCoords.rowStart ?? 0), colEnd: Math.min(Number.MAX_SAFE_INTEGER, t.maxCoords.colEnd ?? Number.MAX_SAFE_INTEGER), rowEnd: Math.min(Number.MAX_SAFE_INTEGER, t.maxCoords.rowEnd ?? Number.MAX_SAFE_INTEGER) })), this._createRun = t?.createRun ?? ((e) => new Ve(e)), this._optionsMinor = {}, this._major = new tr({ nodeSize: O0 });
}
getRuns(t) {
const e = this._isColumn, n = this._maxCoords, r = this.getCoords();
if (!r) return re;
const o = t?.bounds;
let s, i;
if (o) {
const p = Te(o?.colStart ?? Number.MIN_SAFE_INTEGER, o?.rowStart ?? Number.MIN_SAFE_INTEGER, o?.colEnd ?? Number.MAX_SAFE_INTEGER, o?.rowEnd ?? Number.MAX_SAFE_INTEGER, e, n, r);
if (!p) return re;
s = { bounds: { min: p.majorStart, max: p.majorEnd } }, i = { bounds: { min: p.minorStart, max: p.minorEnd } };
}
const l = this._major.entries(s);
let c = l.next();
if (c.done) return re;
let h = c.value[0], d = c.value[1], u = d.runs(i), g = u.next();
if (g.done) return re;
let m = g.value[0].min, f = g.value[1];
return { [Symbol.iterator]() {
return this;
}, next() {
if (c.done) return Lt;
const p = { done: !1, value: [h, m, f] };
for (g = u.next(); g.done && !c.done; ) c = l.next(), c.done || (h = c.value[0], d = c.value[1], u = d.runs(i), g = u.next());
return g.done || (m = g.value[0].min, f = g.value[1]), p;
} };
}
getOrientation() {
return this._isColumn ? yt.Column : yt.Row;
}
entries(t) {
const e = this._isColumn;
let n = e, r = !0;
const o = this._maxCoords, s = this.getCoords(), i = Te(Number.MIN_SAFE_INTEGER, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, e, o, s);
if (!i) return re;
let l, c, h, d = i.majorStart, u = i.majorEnd, g = i.minorStart, m = i.minorEnd, f = !1;
if (t) {
t?.orientation && (n = t?.orientation === yt.Column, r = e === n);
const w = t?.bounds;
if (w) {
const b = Te(w.colStart, w.rowStart, w.colEnd, w.rowEnd, e, o, s);
if (!b) return re;
d = b.majorStart, u = b.majorEnd, g = b.minorStart, m = b.minorEnd;
}
f = t.reverse ?? !1, h = /* @__PURE__ */ ((b) => typeof b != "boolean" ? b : b === !0 ? { done: !1, value: [{ colIndex: -1, rowIndex: -1 }, null] } : void 0)(t.reuseResult), l = e ? t.processColumnSkip : t.processRowSkip, l && (f ? u = l(u, f) : d = l(d, f)), c = e ? t.processRowSkip : t.processColumnSkip, c && (f ? m = c(u, f) : g = c(g, f));
}
if (!s) return re;
r || d !== u || (r = !0), Kt.bounds.min = d, Kt.bounds.max = u, Kt.reverse = f, Kt.processSkip = l, Kt.reuseResult = Wo;
let p = this._major.entries(Kt), _ = Kh();
const S = (w) => {
if (!w.nextActive) return;
const b = (x) => {
const R = w.nextMinorIndex, A = w.nextMinorValue, M = w.nextActive;
return x ? (w.nextMinorIndex = x[0], w.nextMinorValue = x[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, Pn[0] = w.majorIndex, Pn[1] = R, Pn[2] = A, Pn;
}, v = w.minorIterator;
if (!v) return b();
const I = v.next();
return I.done && (w.minorIterator = null), b(I.value);
}, C = (w) => {
if (p) for (; ; ) {
const b = p.next();
if (b.done) return void (p = void 0);
const v = b.value, I = v[1];
I || console.warn("issue", I), w.majorIndex = v[0], w.active = !0, w.nextActive = !1, Le.bounds.min = g, Le.bounds.max = m, Le.reverse = f, Le.processSkip = c, Le.reuseResult = Ug;
const x = I.entries(Le), R = x.next();
if (!R.done) {
const A = R.value;
return w.nextMinorIndex = A[0], w.nextMinorValue = A[1], w.minorIterator = x, w.nextActive = !0, S(w);
}
}
};
let y = null;
if (r)
y = () => {
let w;
return w = S(_), w || (w = C(_), w || void 0);
};
else {
const w = f ? m : g, b = f ? g : m;
let v, I = w, x = b, R = !0;
const A = () => {
if (_.nextMajorCursor) return _ = _.nextMajorCursor, _;
_ = v, (I < g || I > m || I === x) && (_ = null), I = x, x = b;
};
y = () => {
for (; _; ) {
let M = null;
if (R) {
let T = v ? Kh() : _;
if (M = C(T), M) {
v ? (T.prevMajorCursor = _, _.nextMajorCursor = T, _ = T) : v = _, x = f ? Math.max(x, _.nextMinorIndex) : Math.min(x, _.nextMinorIndex);
const O = _.minorIndex;
O !== w && (x = f ? Math.max(x, O) : Math.min(x, O), M = null);
} else R = !1, A();
} else {
const T = _.minorIndex, O = _.nextMinorIndex;
T === I ? (Pn[0] = _.majorIndex, Pn[1] = T, Pn[2] = _.value, M = Pn) : !f && T > I || f && T < I ? x = f ? Math.max(x, T) : Math.min(x, T) : !f && O > I || f && O < I ? x = f ? Math.max(x, O) : Math.min(x, O) : M = S(_), _.active && (x = f ? Math.max(x, _.nextMinorIndex) : Math.min(x, _.nextMinorIndex)), b === I || _.active || (_.prevMajorCursor ? _.prevMajorCursor.nextMajorCursor = _.nextMajorCursor : v = _.nextMajorCursor, _.nextMajorCursor && (_.nextMajorCursor.prevMajorCursor = _.prevMajorCursor)), A();
}
if (M) return M;
}
};
}
return { next(w) {
if (w) throw new Pu("Iterator with next argument is not supported.");
const b = y();
return b ? ((I, x, R, A, M) => {
const T = M ?? { done: !1, value: [{ colIndex: -1, rowIndex: -1 }, null] }, O = T.value, W = O[0];
return W.colIndex = A ? I : x, W.rowIndex = A ? x : I, O[1] = R, T;
})(b[0], b[1], b[2], e, h) : Lt;
}, [Symbol.iterator]() {
return this;
}, return: (w) => null, throw: (w) => null };
}
values(t) {
const e = this.entries(t);
let n;
return t?.reuseResult && (n = t.reuseResult === !0 ? { done: !1, value: null } : t.reuseResult), { next(r) {
const o = e.next(r);
return o.done ? Lt : n ? (n.value = o.value[1], n) : { done: !1, value: o.value[1] };
}, [Symbol.iterator]() {
return this;
}, return: (r) => null, throw: (r) => null };
}
keys(t) {
const e = this.entries(t);
let n;
return t?.reuseResult && (n = t.reuseResult === !0 ? { done: !1, value: null } : t.reuseResult), { next(r) {
const o = e.next(r);
return o.done ? Lt : n ? (n.value = o.value[0], n) : { done: !1, value: o.value[0] };
}, [Symbol.iterator]() {
return this;
}, return: (r) => null, throw: (r) => null };
}
_updateMajorSpan(t, e = !1) {
if (!t || t.length === 0) return;
e && t.sort((l, c) => l[0] - c[0]);
const n = this._major, r = t[0];
let o = r[0], s = o, i = [r[1]];
for (let l = 1; l < t.length; l++) {
const c = t[l], h = c[0], d = c[1];
h === s + 1 ? i.push(d) : (n.setRunAt(o, new Ve(i)), o = h, i = [d]), s = h;
}
i.length > 0 && n.setRunAt(o, new Ve(i));
}
setValues(t) {
if (!t) throw new Qe();
if (t.length === 0) return this;
const e = (t = t.sort(Uh))[0][0], n = t[t.length - 1][0];
let r = Number.MIN_SAFE_INTEGER, o = Number.MAX_SAFE_INTEGER;
const s = this._isColumn, i = this._maxCoords;
if (i) {
const E = s ? i.colStart : i.rowStart, w = s ? i.colEnd : i.rowEnd;
if (e < E || n > w) throw new Wt();
r = s ? i.rowStart : i.colStart, o = s ? i.rowEnd : i.colEnd;
}
if (!t || t.length === 0) return this;
let l = Number.MAX_SAFE_INTEGER, c = Number.MIN_SAFE_INTEGER, h = 0, d = e - 1;
const u = [], g = (E, w, b) => {
if (d === b) throw new zt.OutOfOrderError(`Duplicate major Indices: {${b}}.`);
d = b, w = w.sort(Uh), E = E.clone();
let v = Number.MIN_SAFE_INTEGER;
const I = w.length;
for (let x = 0; x < I; x++) {
const R = w[x], A = R[0], M = R[1], T = A + M.length - 1;
if (v >= A) throw new zt.OutOfOrderError(`Overlapping minor Indices: {${b}, ${A}}.`);
if (A < r || T > o) throw new Wt();
if (M && M.length > 0) {
const O = E.getCount();
E.setRunAt(A, m(M));
const W = E.getCount();
h += W - O, l = Math.min(l, E.getCoords().min), c = Math.max(c, E.getCoords().max);
}
v = T;
}
p++, u.push([b, E]);
}, m = this._createRun, f = this._optionsMinor;
let p = 0;
const _ = () => {
const E = t[p], w = E[0], b = E[1], v = new tr(f);
g(v, b, w);
}, S = this._major;
Kt.bounds.min = e, Kt.bounds.max = n, Kt.reverse = !1, Kt.processSkip = null, Kt.reuseResult = Wo;
const C = S.entries(Kt);
let y = C.next();
for (; !y.done; ) {
const E = y.value, w = E[0];
let b = t[p], v = b[0];
if (v > w) y = C.next();
else {
for (; v < w; ) _(), b = t[p], v = b[0];
if (v === w) {
const I = b[1], x = E[1];
g(x, I, w);
}
y = C.next();
}
}
for (; t[p]; ) _();
return this._updateMajorSpan(u), this._updateCountAndCoords(h, e, l, n, c), this;
}
_updateCountAndCoords(t, e, n, r, o, s = !1) {
const i = this._count + t;
if (this._count = i, this._lastMajor = Number.MIN_SAFE_INTEGER, !this._dataCoords) return;
const l = this._isColumn;
let c = l ? e : n, h = l ? n : e, d = l ? r : o, u = 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), d = (s ? Math.min : Math.max)(d, g.colEnd), u = (s ? Math.min : Math.max)(u, g.rowEnd));
const m = { colStart: c, rowStart: h, colEnd: d, rowEnd: u };
this._dataCoords = m;
}
}
clear() {
this._major.clear(), this._dataCoords = null, this._count = 0;
}
delete(t) {
const e = this._count;
if (!t) return this.clear(), e > 0;
const n = this._isColumn, r = this._maxCoords, o = this.getCoords(), s = Te(t.colStart, t.rowStart, t.colEnd, t.rowEnd, n, r, o);
if (!s || e === 0) return !1;
if (L.isRangeWithinRange(o, t)) return this.clear(), e > 0;
const i = s.majorStart, l = s.majorEnd, c = s.minorStart, h = s.minorEnd;
let d = n ? o.colStart : o.rowStart, u = n ? o.colEnd : o.rowEnd;
const g = n ? o.rowStart : o.colStart, m = n ? o.rowEnd : o.colEnd;
let f = !1, p = 0;
const _ = this._major;
if (c <= g && h >= m) {
Kt.bounds.min = i, Kt.bounds.max = l;
const v = _.entries(Kt);
let I = v.next();
for (; !I.done; )
p -= I.value[1].getCount(), I = v.next();
return _.delete(i, l - i + 1), this._count += p, this._dataCoords = null, p !== 0;
}
const S = [], C = this._isShared, y = [];
Kt.bounds.min = i, Kt.bounds.max = l, Le.reverse = !1, Le.processSkip = null, Le.reuseResult = Wo;
const E = _.entries(Kt);
let w = E.next();
for (; !w.done; ) {
const v = w.value, I = v[0];
let x = v[1];
const R = x.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), p -= x.getCount();
else {
const T = x.getCount();
C && (x = x.clone(), y.push([I, x])), x.delete(c, h - c + 1), p += x.getCount() - T;
}
w = E.next();
}
this._updateMajorSpan(y);
const b = S.length;
if (b > 0) {
const v = Ch(S, !0);
for (let x = 0; x < v.length; x++) {
const R = v[x];
_.delete(R.min, R.max - R.min + 1);
}
const I = _.getCoords();
if (!I) return this.clear(), !0;
d = I.min, u = I.max;
}
return f ? (this._count += p, this._dataCoords = null, !0) : b === 0 ? (this._count += p, p !== 0) : (this._updateCountAndCoords(p, d, g, u, m, !0), p !== 0);
}
shift(t, e) {
if (!t || !e) throw new Qe();
const n = this._isColumn, r = this._maxCoords, o = e === $t.Right || e === $t.Down, s = e === $t.Left || e === $t.Right, i = Te(t.colStart, t.rowStart, t.colEnd, t.rowEnd, n, r, t);
if (!i) return !1;
const l = i.majorStart, c = i.majorEnd, h = i.minorStart, d = i.minorEnd, u = this.getCoords();
if (!u) return !1;
const g = n ? u.colStart : u.rowStart, m = n ? u.colEnd : u.rowEnd, f = n ? u.rowStart : u.colStart, p = n ? u.rowEnd : u.colEnd, _ = h <= f && d >= p, S = n === s;
if ((S && _ || !S && l <= g && c >= m) && !Te(u.colStart, u.rowStart, u.colEnd + (o && s ? t.colEnd - t.colStart + 1 : 0), u.rowEnd + (o && !s ? t.rowEnd - t.rowStart + 1 : 0), n, r) || S && l > m || !S && h > p) return !1;
let C = S ? c - l + 1 : d - h + 1;
if (!o && (C *= -1, L.isRangeWithinRange(u, t))) return this.clear(), !0;
let y = 0;
const E = this._major, w = [];
if (Kt.bounds.min = l, Kt.bounds.max = S ? Number.MAX_SAFE_INTEGER : c, Le.reverse = !o, Le.processSkip = null, Le.reuseResult = Wo, S && _) {
if (!o) {
Kt.bounds.max = c;
const P = E.entries(Kt);
let j = P.next();
for (; !j.done; )
y -= j.value[1].getCount(), j = P.next();
}
E.shift(l, C);
const H = E.getCoords();
return this._dataCoords = null, this._updateCountAndCoords(y, H.min, f, H.max, p), !0;
}
let b = n ? u.colStart : u.rowStart, v = n ? u.colEnd : u.rowEnd, I = n ? u.rowStart : u.colStart, x = n ? u.rowEnd : u.colEnd;
o || (I = Number.MAX_SAFE_INTEGER, x = 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 = [], O = E.entries(Kt), W = { bounds: { min: h, max: d } };
let D = O.next();
for (; !D.done; ) {
const H = D.value, P = H[0], j = H[1].clone(), G = j.getCoords(), K = G.min, V = G.max;
if (S && M.set(P, j), h <= V) {
const $ = j.getCount();
S ? (P >= l - C && l0(j.runs(W), (Z, q) => {
const Q = q.min, it = q.max;
let X = Z;
Q - 1 <= d && it > d && (X = X.slice(0, d + 1 - Q)), Q < h && it + 1 >= h && (X = X.slice(h - Q)), T.push({ majorIndex: P + C, minorIndex: Math.max(Q, h), run: X });
}), j.delete(h, d - h + 1)) : j.shift(h, C);
const J = j.getCount();
if (J === 0) A.add(P), I = Math.min(I, V), x = Math.max(x, K);
else {
const Z = j.getCoords();
if (I = Math.min(I, Z.min), x = Math.max(x, Z.max), x > R) throw new Wt();
}
y += J - $, w.push([P, j]);
}
D = O.next();
}
const z = this._optionsMinor;
let B = !1;
for (let H = 0; H < T.length; H++) {
const P = T[H], j = P.majorIndex, G = P.run;
let K = M.get(j);
K || (K = new tr(z), M.set(j, K), w.push([j, K]), B = !0), K.setRunAt(P.minorIndex, G), y += G.length, b = Math.min(b, j), v = Math.max(v, j), A && A.delete(j);
}
if (this._updateMajorSpan(w, B), A && A.size > 0) {
const H = Array.from(A.values()), P = Ch(H);
for (let G = 0; G < P.length; G++) {
const K = P[G];
E.delete(K.min, K.max - K.min + 1);
}
const j = E.getCoords();
if (!j) return this.clear(), !0;
b = j.min, v = j.max;
}
if (x !== p || I !== f) return this._count += y, this._dataCoords = null, !0;
{
const H = this._count + y;
this._count = H, this._dataCoords = H === 0 ? null : Object.freeze({ colStart: n ? b : I, rowStart: n ? I : b, colEnd: n ? v : x, rowEnd: n ? x : v });
}
return y !== 0 || !L.isEqualRanges(u, this.getCoords());
}
getCount() {
return this._count;
}
getValueAt(t, e) {
const n = this._isColumn, r = n ? e : t, o = n ? t : e, 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(t, e, n) {
const r = this._isColumn, o = [r ? e : t, [[r ? t : e, [n]]]];
this.setValues([o]);
}
copyTo(t, e, n) {
if (this.getCount() === 0) return;
const r = this.getOrientation(), o = t.getOrientation(), s = this.getRuns({ bounds: n });
let i = s.next();
const l = L.cellToRange(e);
l.colEnd = n.colEnd - n.colStart + e.colIndex, l.rowEnd = n.rowEnd - n.rowStart + e.rowIndex;
const c = this._isColumn, h = this._maxCoords, d = this.getCoords();
let u, g = Te(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, d);
g = { ...g };
const m = o !== yt.Row, f = t.getMaxCoords();
u = Te(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), u = { ...u };
const p = u.majorStart - g.majorStart, _ = u.minorStart - g.minorStart, S = r === o ? new zt.Builder() : new zt.TransposedBuilder();
for (; !i.done; ) {
const y = i.value[0];
let E = i.value[1], w = i.value[2];
E + w.length > g.minorEnd && (w = w.slice(0, g.minorEnd - E + 1)), E < g.minorStart && (w = w.slice(g.minorStart - E), E = g.minorStart), S.addValues(y + p, E + _, w), i = s.next();
}
const C = S.build();
t.delete(l), C && t.setValues(C.tuples);
}
getCoords() {
if (this._dataCoords) return this._dataCoords;
if (this._major.getCount() === 0) return null;
let t = Number.MAX_SAFE_INTEGER, e = 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];
t = Math.min(h, t), e = Math.max(h, e);
const d = c[1].getCoords();
n = Math.min(d.min, n), r = Math.max(d.max, r), s = o.next();
}
const i = this._isColumn, l = Object.freeze({ colStart: i ? t : n, rowStart: i ? n : t, colEnd: i ? e : r, rowEnd: i ? r : e });
return this._dataCoords = l, l;
}
clone(t) {
this._isShared = !0;
const e = new hn(this._options);
return e._isShared = !0, e._major = this._major.clone(), e._dataCoords = this._dataCoords, e._count = this._count, e;
}
cloneEmpty(t) {
return new hn(this._options);
}
getMaxCoords() {
return this._maxCoords || null;
}
get [Symbol.toStringTag]() {
let t = "";
const e = this.getCoords();
if (e) {
const n = e.colEnd - e.colStart + 1, r = e.rowEnd - e.rowStart + 1;
t = `${this.getCount()}-${this._isColumn ? n : r}x${this._isColumn ? r : n}`;
}
return `[SparseGrid:${t}]`;
}
}
hn || (hn = {});
const O0 = 12;
Object.seal({ done: !1, value: null });
const Pn = [-1, -1, null], Ug = Object.seal({ done: !1, value: [-1, null] }), Wo = Object.seal({ done: !1, value: [-1, null] }), Le = { bounds: { min: -1, max: -1 }, reverse: !1, processSkip: null, reuseResult: Ug }, Kt = { bounds: { min: -1, max: -1 }, reverse: !1, processSkip: null, reuseResult: Wo }, Kh = () => ({ majorIndex: -1, minorIndex: -1, value: null, active: !1, nextMinorIndex: -1, nextActive: !1, nextMinorValue: null, minorIterator: null, nextMajorCursor: null, prevMajorCursor: null });
class Ii {
constructor(t) {
if (this._l = 0, this._at = null, this._dt = Xh.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, !t) throw new Error("options is required");
const e = t.length;
if (this._l = e, this._dt = t.type, this._cv = t.getCoercedValue ?? null, e > 0) {
t.types && (this._at = t.types, this._vt = new Uint8Array(this._at));
const n = t.values32 ?? null;
n && (this._a32 = n, this._vi32 = new Int32Array(n), this._vf32 = new Float32Array(n));
const r = t.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(t) {
if (t >>> 0 >= this._l) return;
const e = this._vt, n = e && e[t] || this._dt;
let r, o = !1;
switch (this._vi32 ? r = this._vi32[t] : (o = !0, r = Number(this._vi64[t])), n) {
case oi:
return o ? Number(r) : r;
case Jo:
return o ? this._vf64[t] : this._vf32[t];
case si:
return !!r;
case ii:
case ai:
return this._cv(n, o ? Number(r) : r);
case Ho:
return this._vi64[o ? t : r];
case Vo:
return this._vf64[o ? t : r];
case Kg:
return Number.NaN;
case Xg:
return Number.MAX_SAFE_INTEGER;
case Yg:
return Number.MIN_SAFE_INTEGER;
case qg:
return 1 / 0;
case Jg:
return -1 / 0;
case Qg:
return null;
case oc:
case li:
return;
}
return this._cv(n, o ? Number(r) : r);
}
toArray(t) {
const e = [], n = Math.max(t, this._l);
for (let r = 0; r < n; r++) e.push(this.at(r));
return e;
}
get length() {
return this._l;
}
get [Symbol.toStringTag]() {
return "[MixTypedArrayList]";
}
toString() {
const t = this._a32, e = this._a64;
let n = "";
return t && !e ? n = "32" : e && !t && (n = "64"), `{${n}${this._at ? "" : ":SINGLE_TYPE"}}:${this._l}}`;
}
static _createArrayBuffer(t) {
try {
return new SharedArrayBuffer(t);
} catch {
}
return new ArrayBuffer(t);
}
static fromArray(t, e, n, r, o = D0) {
const s = t.length;
if (s === 0) return new Ii({ type: Xh.Undefined, length: s, getCoercedValue: n });
let i = this._createArrayBuffer(s * Int8Array.BYTES_PER_ELEMENT), l = new Uint8Array(i), c = 0, h = !1, d = Yh(t[0], r);
for (let w = 0; w < s; w++) {
const b = t[w], v = Yh(b, r);
v !== Vo && v !== Ho || c++, d !== v && (l[w] = v, h = !0);
}
h || (l = null, i = null);
let u, g, m, f, p, _, S, C, y = !1;
c / s > o && (y = !0, c = s), c !== 0 && (m = this._createArrayBuffer(c * BigInt64Array.BYTES_PER_ELEMENT), f = new BigInt64Array(m), p = new Float64Array(m)), y ? (u = f, g = p) : (_ = this._createArrayBuffer(s * Int32Array.BYTES_PER_ELEMENT), S = new Int32Array(_), C = new Float32Array(_), u = S, g = C);
let E = d;
if (y) for (let w = 0; w < s; w++) {
const b = t[w];
switch (l && (E = l[w] || d), E) {
case oi:
u[w] = BigInt(b);
break;
case si:
u[w] = BigInt(b ? 1 : 0);
break;
case Jo:
g[w] = b;
break;
case Ho:
u[w] = b;
break;
case Vo:
g[w] = b;
break;
case ii:
case ai:
u[w] = BigInt(e?.(E, b) ?? 0);
break;
default:
E > 127 && E < 255 && (u[w] = BigInt(e?.(E, b) ?? 0));
}
}
else {
let w = 0;
for (let b = 0; b < s; b++) {
const v = t[b];
switch (l && (E = l[b] || d), E) {
case oi:
u[b] = v;
break;
case si:
u[b] = v ? 1 : 0;
break;
case Jo:
g[b] = v;
break;
case Ho:
S[b] = w, f[w] = v, w++;
break;
case Vo:
S[b] = w, p[w] = v, w++;
break;
case ii:
case ai:
u[b] = e?.(E, v) ?? 0;
break;
default:
E > 127 && E < 255 && (u[b] = e?.(E, v) ?? 0);
}
}
}
return new Ii({ length: s, types: h ? i : null, type: d, values32: _, values64: m, getCoercedValue: n });
}
}
const D0 = 0.1, oi = 1, Jo = 2, si = 3, Ho = 4, Vo = 5, ii = 6, ai = 7, qg = 8, Jg = 9, Kg = 10, Xg = 11, Yg = 12, Qg = 13, oc = 14, li = 127, Xh = { Undefined: oc }, Yh = (a, t) => {
switch (typeof a) {
case "number":
const e = a;
return Number.isNaN(e) ? Kg : e === 1 / 0 ? qg : e === -1 / 0 ? Jg : Object.is(e, -0) ? Jo : e === Number.MAX_SAFE_INTEGER ? Xg : e === Number.MIN_SAFE_INTEGER ? Yg : Number.isInteger(e) && e <= 2147483647 && e >= -2147483648 ? oi : Math.fround(e) === e ? Jo : Vo;
case "string":
return ii;
case "boolean":
return si;
case "object":
if (a === null) return Qg;
if (a instanceof Error) return ai;
if (!t) return li;
const n = t(a);
if (n < 128 || n > 255) throw new Error("Custom type must be between 128 and 255");
return n;
case "bigint":
return Ho;
case "undefined":
return oc;
case "symbol":
case "function":
return li;
}
return li;
}, jo = (a) => {
if (!a || a.length <= 1) return !1;
if (a.length === 2) return L.isRangesIntersect(a[0], a[1]);
const t = new Nt();
t.load(a);
const e = a.length;
for (let n = 0; n < e; n++)
if (t.search(a[n]).length > 1) return !0;
return !1;
}, Tl = (a, t, e) => {
const n = [];
if (L.isRangesIntersect(a, t)) {
const r = k.subtractRect({ top: a.rowStart, left: a.colStart, bottom: a.rowEnd + 1, right: a.colEnd + 1 }, { top: t.rowStart, left: t.colStart, bottom: t.rowEnd + 1, right: t.colEnd + 1 }, e === F.Orientation.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;
}, Qh = (a, t, e) => {
if (!t || !a?.[0]) return;
const n = a.length;
for (let r = 0; r < n; r++) {
const o = a[r];
L.intersectRanges(o, t) && e(o, !L.isRangeWithinRange(o, t), r);
}
}, Zh = (a, t) => {
const e = a.colStart, n = a.rowStart, r = t.colStart, o = t.rowStart;
return (s, i) => {
const l = s.colIndex - e, c = i.colIndex - r;
return l === c ? s.rowIndex - n - (i.rowIndex - o) : l - c;
};
}, td = (a, t) => {
const e = a.colStart, n = a.rowStart, r = t.colStart, o = t.rowStart;
return (s, i) => {
const l = s.rowIndex - n, c = i.rowIndex - o;
return l === c ? s.colIndex - e - (i.colIndex - r) : l - c;
};
}, Nl = (a, t, e = !1, n = !1) => {
t || (t = a);
let r = t.colEnd - t.colStart + 1, o = t.rowEnd - t.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 (e) {
let c = a.colStart, h = a.rowStart;
return L.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 Fa {
constructor(t, e) {
this._l = 0, t && e > 0 && (this._u = t, this._l = e);
}
at(t) {
if (t > this._l || t < 0 || !this._u) return;
const e = Math.floor(t % this._u.length);
return this._u.at(e);
}
toArray(t) {
const e = [], n = this._u, r = n.length;
for (let o = 0; o < t; o++) {
const s = Math.floor(o % r);
e.push(n.at(s));
}
return e;
}
get length() {
return this._l;
}
get [Symbol.toStringTag]() {
return "[RepeatingList]";
}
get isIList() {
return !0;
}
}
class me {
constructor(t, e, n = null, r = !1) {
this._isLiteral = !1, this._values = t, this._coords = e, this._type = n, this._isLiteral = r;
}
getValueAt(t, e, n) {
const r = this._coords;
if (!r) return;
let o = this._values.getValueAt(t + r.rowStart, e + r.colStart) ?? null;
o === void 0 && (o = null);
const s = n?.type, i = s !== void 0 ? s : this._type;
return i && (o = Xe(o, _e(o, !0), i)), o;
}
_applyBuilder(t, e, n = !1) {
if (!e) return t;
const r = e.build();
return r && (n && (t = t.clone()), t.setValues(r.tuples)), t;
}
_cloneFromBuilder(t, e, n, r) {
if (!t) return this;
const o = t.build();
if (!o) return this;
let s = this._values;
const i = s.getOrientation(), l = (e?.orientation ?? i) === F.Orientation.Column, c = Zo(o.bounds, l), h = this._coords ?? L.EmptyRange, d = Math.max(c.colEnd - c.colStart + 1, n ?? h.colEnd - h.colStart + 1), u = Math.max(c.rowEnd - c.rowStart + 1, r ?? h.rowEnd - h.rowStart + 1), g = h.colStart, m = h.rowStart, f = g + d - 1, p = m + u - 1;
return s = s.clone(), s.setValues(o.tuples), new me(s, { colStart: g, rowStart: m, colEnd: f, rowEnd: p }, this._type, this._isLiteral);
}
forEach(t, e) {
if (!t) return;
const n = this.entries(e);
let r = n.next();
for (; !r.done; ) {
const o = r.value, s = t(o.value, o.coords, this);
if (s) return s.break;
r = n.next();
}
}
reduce(t, e, n) {
if (!t) return e;
const r = this.entries(n);
let o = r.next(), s = e;
for (; !o.done; ) {
const i = o.value;
s = t(s, i.value, i.coords, this), o = r.next();
}
return s;
}
some(t, e) {
if (!t) return !1;
const n = this.entries(e);
let r = n.next();
for (; !r.done; ) {
const o = r.value;
if (t(o.value, o.coords, this)) return !0;
r = n.next();
}
return !1;
}
every(t, e) {
if (!t) return !0;
const n = this.entries(e);
let r = n.next();
for (; !r.done; ) {
const o = r.value;
if (!t(o.value, o.coords, this)) return !1;
r = n.next();
}
return !0;
}
replace(t, e) {
let n;
if (n = t?.isIRange ? t : W0(t, 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 ?? L.EmptyRange, i = this._coords ?? L.EmptyRange, l = i.colStart, c = i.rowStart, h = l + (e.colIndex ?? 0), d = c + (e.rowIndex ?? 0);
o.copyTo(r, { colIndex: h, rowIndex: d }, s);
const u = Math.max(this.getWidth(), n.getWidth() + (e?.colIndex ?? 0)), g = Math.max(this.getHeight(), n.getHeight() + (e?.rowIndex ?? 0));
return new me(r, { colStart: l, rowStart: c, colEnd: l + u - 1, rowEnd: c + +g - 1 }, this._type);
}
slice(t) {
if (!t) return this;
const e = this._coords ?? L.EmptyRange, n = (t.colStart ?? 0) + e.colStart, r = (t.rowStart ?? 0) + e.rowStart, o = { colStart: n, rowStart: r, colEnd: (t.colEnd ?? e.colEnd - n) + e.colStart, rowEnd: (t.rowEnd ?? e.rowEnd - r) + e.rowStart }, s = L.intersectRanges(e, o);
return new me(this._values, s, this._type);
}
resize(t, e, n = null) {
if (t < 0 || e < 0) throw new Error(`Invalid resize dimensions: ${t} x ${e}`);
const r = this._coords ?? L.EmptyRange, o = r.colEnd - r.colStart + 1, s = r.rowEnd - r.rowStart + 1;
if (t === o && e === s) return this;
const i = { colStart: r.colStart, rowStart: r.rowStart, colEnd: r.colStart + t - 1, rowEnd: r.rowStart + e - 1 };
let l = this._values;
return (t > o || e > s) && (l = l.clone(), t > o && (le.colStart = r.colEnd + 1, le.rowStart = r.rowStart, le.colEnd = r.colEnd, le.rowEnd = r.rowEnd, this._fill(l, r, n)), e > s && (le.colStart = r.colStart, le.rowStart = r.rowEnd + 1, le.colEnd = r.colEnd, le.rowEnd = r.rowEnd, this._fill(l, r, n))), new me(l, i, this._type);
}
_mergeIterators(t, e, n) {
const r = this._coords ?? L.EmptyRange, o = t._coords ?? L.EmptyRange, s = this._values.getOrientation(), i = n?.orientation ?? s, l = i !== F.Orientation.Row, c = this._entries(n), h = this._entries(n), d = r.colStart, u = r.rowStart, g = d - o.colStart, m = u - o.rowStart, f = i === s ? new zt.Builder() : new zt.TransposedBuilder(), p = new qh({ ...n, bounds: r, comparator: (l ? Zh : td)(r, o) }, c, h);
let _ = p.next();
for (; !_.done; ) {
const S = _.value;
let C = S[1], y = S[3];
const E = S[0], w = S[2], b = E ? E.colIndex : w.colIndex + g, v = E ? E.rowIndex : w.rowIndex + m, I = e(C, y, { colIndex: b - d, rowIndex: v - u }, this), x = l ? b : v, R = l ? v : b;
f.addValue(x, R, I), _ = p.next();
}
return f;
}
intersect(t, e, n) {
if (!t) throw new Error("Invalid range to intersect");
const r = t, o = this._coords ?? null, s = r._coords ?? null;
if (!L.intersectRanges(o, s)) return new me(this._values, null, this._type);
const i = this._mergeIterators(r, e, n);
return this._cloneFromBuilder(i, n);
}
startIncrementalUpdates(t) {
const e = t?.orientation ?? F.Orientation.Column, n = this._values.getOrientation(), r = (t?.orientation ?? n) !== F.Orientation.Row, o = e === n ? new zt.Builder() : new zt.TransposedBuilder(), s = this, i = this._coords ?? L.EmptyRange, l = i.colStart, c = i.rowStart, h = r ? l : c, d = r ? c : l, u = { pushAt(g, m, f) {
const p = r ? m : g, _ = r ? g : m;
return o.addValue(p + h, _ + d, f), u;
}, pushMultipleAt(g, m, f) {
const p = r ? m : g, _ = r ? g : m;
return o.addValues(p + h, _ + d, f), u;
}, apply() {
const g = o.build();
return g ? (g.bounds.majorStart = h, g.bounds.minorStart = d, s._cloneFromBuilder(o, t)) : null;
} };
return u;
}
map(t, e) {
const n = this._values;
if (!this._coords || n.getCount() === 0) return this;
const r = n.getOrientation(), o = e?.orientation ?? r;
let s;
const i = this.entries(e);
let l = i.next();
l.done || (s = this._createTupleBuilder(o));
const c = o === F.Orientation.Column;
for (; !l.done; ) {
const h = l.value, d = h.coords, u = t(h.value, d, this), g = c ? d.colIndex : d.rowIndex, m = c ? d.rowIndex : d.colIndex;
s.addValue(g, m, u), l = i.next();
}
return this._cloneFromBuilder(s, e);
}
filter(t, e) {
const n = this._values;
if (!this._coords || n.getCount() === 0) return this;
const r = n.getOrientation(), o = e?.orientation ?? r, s = this._createTupleBuilder(o), i = this.entries(e);
let l = i.next();
const c = o === F.Orientation.Column;
for (; !l.done; ) {
const h = l.value, d = h.coords, u = h.value;
if (t(u, d, this)) {
const g = c ? d.colIndex : d.rowIndex, m = c ? d.rowIndex : d.colIndex;
s.addValue(g, m, u);
}
l = i.next();
}
return this._cloneFromBuilder(s, e);
}
broadcast(t, e, n) {
let r = this._coords;
if (t == null) return this;
let o = n?.type, s = n?.otherType ?? o;
const i = o ? Xe(null, Y.Null, o) : null, l = s ? Xe(null, Y.Null, s) : null;
let c;
if (t.isIRange) c = t;
else {
const B = this._values.clone();
B.setValueAt(0, 0, t), c = new me(B, L.EmptyRange, _e(t, !0));
}
const h = c, d = this.getWidth(), u = this.getHeight(), g = h.getWidth(), m = h.getHeight();
let f = Math.min(d, g), p = Math.min(u, m), _ = Math.max(d, g), S = Math.max(u, m);
const C = n?.mismatchFill;
let y = !1;
if (d !== g) if (d === 1) f = g;
else if (g === 1) f = d;
else {
if (!C) throw new Error(`Incompatible shapes for broadcast: width dimensions ${d} and ${g} must be equal or one must be 1`);
y = !0;
}
if (u !== m) if (u === 1) p = m;
else if (m === 1) p = u;
else {
if (!C) throw new Error(`Incompatible shapes for broadcast: height dimensions ${u} and ${m} must be equal or one must be 1`);
y = !0;
}
const E = this._values.getOrientation(), w = E, b = w === F.Orientation.Column;
r = r ?? L.EmptyRange;
let v, I, x = h._coords ?? L.EmptyRange;
if (y && (r = { colStart: r.colStart, rowStart: r.rowStart, colEnd: r.colStart + f - 1, rowEnd: r.rowStart + f - 1 }, x = { colStart: x.colStart, rowStart: x.rowStart, colEnd: x.colStart + f - 1, rowEnd: x.rowStart + f - 1 }), d === 1 && d < g || u === 1 && u < m) {
const B = { ...r };
d === 1 && (B.colEnd = B.colStart), u === 1 && (B.rowEnd = B.rowStart), v = new Ml({ delegate: this._entries({ ...n, orientation: w, bounds: B, reuseResult: !1 }), bounds: B, orientation: w, dims: { major: b ? f : p, minor: b ? p : f } });
} else v = this._entries({ ...n, orientation: w, bounds: r, reuseResult: !1 });
if (g === 1 && g < d || m === 1 && m < u) {
const B = { ...x };
g === 1 && (B.colEnd = B.colStart), m === 1 && (B.rowEnd = B.rowStart), I = new Ml({ delegate: h._entries({ ...n, type: s ?? null, orientation: w, bounds: B, reuseResult: !1 }), bounds: B, orientation: w, dims: { major: b ? f : p, minor: b ? p : f } });
} else I = h._entries({ ...n, type: s ?? null, orientation: w, bounds: x, reuseResult: !1 });
const R = r.colStart, A = r.rowStart, M = R - x.colStart, T = A - x.rowStart, O = w === E ? new zt.Builder() : new zt.TransposedBuilder(), W = new qh({ ...n, bounds: r, comparator: (b ? Zh : td)(r, x) }, v, I);
let D, z = W.next();
for (; !z.done; ) {
const B = z.value;
let H = B[1], P = B[3];
const j = B[0], G = B[2], K = j ? j.colIndex : G.colIndex + M, V = j ? j.rowIndex : G.rowIndex + T;
let $, J;
H instanceof pt.Value ? $ = H : P instanceof pt.Value && ($ = P), J = $ || e(H ?? i, P ?? l, { colIndex: K - R, rowIndex: V - A }, this);
const Z = b ? K : V, q = b ? V : K;
O.addValue(Z, q, J), z = W.next();
}
if (C && _ > f || S > p) {
const B = this._values.clone();
if (this._applyBuilder(B, O), _ > f) {
const H = Te(R + f, A, R + _ - 1, A + S - 1, b), P = ri(C, H, b);
B.setValues(P.tuples);
}
if (S > p) {
const H = Te(R, A + p, R + _ - 1, A + S - 1, b), P = ri(C, H, b);
B.setValues(P.tuples);
}
D = new me(B, { colStart: R, rowStart: A, colEnd: R + _ - 1, rowEnd: A + S - 1 }, this._type);
} else D = this._cloneFromBuilder(O, n, _, S);
return D;
}
_fill(t, e, n) {
if (n === null) return void t.delete(e);
const r = t.getOrientation() === F.Orientation.Column, o = Te(e.colStart, e.rowStart, e.colEnd, e.rowEnd, r), s = ri(n, o, r);
t.setValues(s.tuples);
}
_validateCoords(t) {
}
fill(t, e) {
let n = this._coords;
if (!n && !e) return this;
n = n ?? L.EmptyRange, e && (le.colStart = (e.colStart ?? 0) + n.colStart, le.rowStart = (e.rowStart ?? 0) + n.rowStart, le.colEnd = (e.colEnd ?? n.colEnd - n.colStart) + n.colStart, le.rowEnd = (e.rowEnd ?? n.rowEnd - n.rowStart) + n.rowStart), this._validateCoords(le);
const r = this._values.clone();
return this._fill(r, le, t), (le.rowEnd > n.rowEnd || le.colEnd > n.colEnd) && (n = { colStart: n.colStart, rowStart: n.rowStart, colEnd: Math.max(n.colEnd, le.colEnd), rowEnd: Math.max(n.rowEnd, le.rowEnd) }), new me(r, n, this._type);
}
empty() {
const t = this._values.cloneEmpty();
return new me(t, null, this._type);
}
flatten(t) {
const e = [], n = this.values(t);
let r = n.next();
for (; !r.done; ) e.push(r.value), r = n.next();
return e;
}
fillEmpty(t, e = 1, n = 1) {
const r = this._coords;
if (!r) return this;
const o = this._values;
if (e < 1 && n < 1) throw new Error("Must be at least size of 1");
const s = o.getOrientation(), i = s, l = i === F.Orientation.Column, c = Math.max(this.getWidth(), e), h = Math.max(this.getHeight(), n), d = l ? r.colStart : r.rowStart, u = 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 p = f.next(), _ = d, S = u;
const C = i === s ? new zt.Builder() : new zt.TransposedBuilder();
for (; !p.done; ) {
const y = p.value, E = y[0];
for (; _ < E; ) {
const x = new Fa([t], m + 1 - S);
C.addValues(_, S, x), _++, S = u;
}
const w = y[1], b = Math.max(w, u), v = y[2], I = Math.min(w + v.length - 1, m);
if (S < b) {
const x = new Fa([t], w - S);
C.addValues(_, S, x);
}
S = I + 1, I >= m ? (_ = E + 1, S = u) : _ = E, p = f.next();
}
for (; _ <= g; ) {
const y = new Fa([t], m + 1 - S);
C.addValues(_, S, y), _++, S = u;
}
return this._cloneFromBuilder(C, void 0, c, h);
}
transpose() {
if (this.size <= 1) return this;
const t = this._values.getOrientation(), e = this._coords, n = this.getWidth(), r = this.getHeight(), o = this._entries({ orientation: t === F.Orientation.Column ? F.Orientation.Row : F.Orientation.Column, bounds: e, reuseResult: !0 }), s = t === F.Orientation.Column, i = new zt.Builder(), l = s ? e.colStart : e.rowStart, c = s ? e.rowStart : e.colStart;
let h = o.next();
for (; !h.done; ) {
const d = h.value, u = d[0], g = s ? u.colIndex : u.rowIndex - l, m = (s ? u.rowIndex : u.colIndex - c) + l, f = g + c, p = d[1];
i.addValue(m, f, p), h = o.next();
}
return this._cloneFromBuilder(i, void 0, r, n);
}
values(t) {
const e = this.entries(t);
return { [Symbol.iterator]() {
return this;
}, next() {
const n = e.next();
return n.done ? Lt : { done: !1, value: n.value.value };
} };
}
_createTupleBuilder(t) {
const e = this._coords, n = this._values.getOrientation(), r = t ?? n, o = r !== F.Orientation.Row, s = o ? e.colStart : e.rowStart, i = o ? e.rowStart : e.colStart;
return r === n ? new zt.Builder(null, s, i) : new zt.TransposedBuilder(null, s, i);
}
entries(t) {
const e = this._coords;
if (!e) return re;
const n = t?.bounds;
if (t = { ...t, bounds: e }, n) {
const s = (n.colStart ?? 0) - e.colStart, i = (n.rowStart ?? 0) - e.rowStart, l = Math.max(s + e.colStart, e.colStart), c = Math.max(i + e.rowStart, e.rowStart), h = Math.min((n.colEnd ?? Number.MAX_SAFE_INTEGER) - s, e.colEnd - e.colStart) + 1, d = Math.min((n.rowEnd ?? Number.MAX_SAFE_INTEGER) - i, e.rowEnd - e.rowStart) + 1;
t.bounds = { colStart: l, rowStart: c, colEnd: l + h - 1, rowEnd: c + d - 1 };
}
const r = this._entries(t), o = { [Symbol.iterator]: () => o, next() {
for (; ; ) {
let s = r.next();
if (s.done) return Lt;
const i = s.value, l = i[0];
return { done: !1, value: { coords: { colIndex: l.colIndex - e.colStart, rowIndex: l.rowIndex - e.rowStart }, value: i[1] } };
}
} };
return o;
}
_entries(t) {
if (!this._coords) return re;
let e = this._values.entries(t);
const n = t?.type ?? this._type;
let r = null;
if (t?.includeEmpty && (e = new Gg(e, t), n && (r = Xe(null, Y.Null, n))), n) {
const o = e, s = t.coerce ?? !1, i = t.includeBoolean ?? !1, l = t.includeMistyped ?? !1;
e = { [Symbol.iterator]: () => e, next() {
for (; ; ) {
let c = o.next();
if (c.done) return Lt;
const h = c.value, d = h[1];
let u = d;
if (u == null) u = r;
else if (n && (s || !l)) {
let g = _e(u, !0), m = g !== n;
if (m && (s && (u = Xe(u, g, n, i), m = u?.isFormulaError), m && !l)) continue;
}
return u === d ? c : { done: !1, value: [h[0], u] };
}
} };
}
return e;
}
getValues(t) {
if (!this._coords) return [[]];
const e = { ...t, includeEmpty: !0, reverse: !1, bounds: { colStart: 0, rowStart: 0, colEnd: this.getWidth() - 1, rowEnd: this.getHeight() - 1 } };
let n = !1;
e.orientation = t?.orientation ?? F.Orientation.Row, t && (t.maxHeight && (e.bounds.rowEnd = 0 + t.maxHeight - 1), t.maxWidth && (e.bounds.colEnd = 0 + t.maxWidth - 1), t.trailingEmpties && (n = t.trailingEmpties), e.orientation = t?.orientation ?? F.Orientation.Row);
const r = [];
if (!n) {
e.includeEmpty = !1, e.reverse = !0;
const d = this.entries(e).next();
if (d.done) return L0;
const u = d.value.coords;
e.bounds.colEnd = u.colIndex, e.bounds.rowEnd = u.rowIndex, e.includeEmpty = !0, e.reverse = !1;
}
const o = this.entries(e), s = e.orientation !== F.Orientation.Row, i = t?.onValue;
let l, c = -1, h = [];
for (l = o.next(); !l.done; ) {
const d = l.value, u = d.coords, g = s ? u.colIndex : u.rowIndex;
g !== c && (h = [], r.push(h), c = g);
let m = d.value;
if (i) {
const f = i(m, u.rowIndex, u.colIndex, this);
f !== void 0 && (m = f);
}
h.push(m), l = o.next();
}
return r;
}
toType(t) {
return new me(this._values, this._coords, t, this._isLiteral);
}
getWidth() {
const t = this._coords;
return t ? t.colEnd - t.colStart + 1 : 0;
}
getHeight() {
const t = this._coords;
return t ? t.rowEnd - t.rowStart + 1 : 0;
}
get size() {
const t = this._coords;
return t ? (t.colEnd - t.colStart + 1) * (t.rowEnd - t.rowStart + 1) : 0;
}
isLiteral() {
return this._isLiteral;
}
getScalarType() {
return this._type;
}
[Symbol.iterator]() {
const t = this.entries();
return { next() {
const e = t.next();
return e.done ? Lt : { done: !1, value: e.value.value };
}, [Symbol.iterator]() {
return this;
} };
}
get [Symbol.toStringTag]() {
return "[Range]";
}
toString() {
const t = this._coords, e = t ? `${t.colEnd - t.colStart + 1}x${t.rowEnd - t.rowStart + 1}` : pt.Ref.toString();
let n = "{";
const r = this.entries({ includeEmpty: !0, orientation: F.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 += "...", `[${e}:${n}]`;
}
get isIRange() {
return !0;
}
}
const le = { colStart: Number.MIN_SAFE_INTEGER, rowStart: Number.MIN_SAFE_INTEGER, colEnd: Number.MAX_SAFE_INTEGER, rowEnd: Number.MAX_SAFE_INTEGER }, L0 = Object.freeze([Object.freeze([null])]), is = Object.freeze({ colStart: 0, rowStart: 0, colEnd: Math.pow(2, 14) - 1, rowEnd: Math.pow(2, 20) - 1 }), B0 = Object.freeze({ colIndex: 0, rowIndex: 0 }), Fl = () => is, _e = (a, t = !1) => typeof a == "number" ? isNaN(a) || a === 1 / 0 || a === -1 / 0 ? Y.Error : Y.Number : typeof a == "string" ? Y.String : typeof a == "boolean" ? Y.Boolean : a?.isFormulaError ? Y.Error : a === null ? Y.Null : k.isObject(a) && a.hasOwnProperty("type") && typeof a.type == "string" ? Y.RichData : t && ro(a) ? "Date" : a === void 0 ? (console.warn("undefined"), Y.Null) : null, ed = /* @__PURE__ */ new Map([[Y.Null, "any"], [Y.Number, "number"], [Y.String, "string"], [Y.Boolean, "boolean"], [Y.Error, "FormulaError"], [Y.RichData, "richData"], ["*", "Scalar"]]), z0 = /* @__PURE__ */ new Map([["p", "IReferenceRange"], ["r", "IRange"]]), P0 = { orientation: F.Orientation.Row }, Xe = (a, t, e = Y.Number, n = !1, r = !1) => {
if (t === e || !e) return t === Y.Number && (a = Gi(a, null, "number")), a;
if (e === Y.Number) {
switch (t) {
case Y.Null:
return 0;
case Y.String:
let o = 0;
try {
const s = Am(a);
o = s && typeof s.value == "number" ? s.value : Number.NaN;
} catch {
}
return !Number.isFinite(o) || Math.abs(o) > 999e305 ? pt.BuiltIn.Value : o;
case Y.Boolean:
return n ? a ? 1 : 0 : pt.BuiltIn.Value;
case "Date":
return rs(a, r) ?? pt.BuiltIn.Value;
case Y.Error:
return a;
}
return a.toString();
}
if (e === Y.String) {
switch (t) {
case Y.Null:
return "";
case Y.Number:
return a.toString();
case Y.Boolean:
return a ? "TRUE" : "FALSE";
case Y.Error:
return a;
}
return a;
}
if (e === Y.Boolean) {
switch (t) {
case Y.Null:
return 0;
case Y.Number:
return !!a;
case Y.String:
let o = a.trim().toUpperCase();
return o === "TRUE" || o !== "FALSE" && pt.BuiltIn.Value;
case Y.Error:
return a;
}
return pt.BuiltIn.Value;
}
if (e === "Date") {
switch (t) {
case Y.Number:
return oo(a, r) ?? pt.BuiltIn.Value;
case Y.String:
try {
const o = Ql(a, r);
if (o) return o.asJSDate ?? pt.BuiltIn.Value;
} catch {
}
return a;
case Y.Error:
return a;
}
return pt.BuiltIn.Value;
}
return pt.BuiltIn.Value;
}, nd = (a) => {
let t = a;
for (; Array.isArray(t); ) {
if (t.length > 1) return !1;
t = t[0];
}
return !t || !t.isIRange || t.size === 1;
}, Zg = (a, t, e, n, r, o = !1) => {
if (Array.isArray(e)) {
const s = e.length;
for (let i = 0; i < s; i++) {
let l = e[i];
if (Array.isArray(l)) {
const c = Zg(a, t, l, n, r, o);
if (o) continue;
if (c instanceof pt.Value) return c;
} else {
if (n) {
if (l = Xe(l, _e(l, !0), n, o), o) continue;
if (l instanceof pt.Value) return l;
}
t.push(l);
}
}
return;
}
if (e && e.colStart !== void 0) {
let s = a.getReference?.(e);
n && (s = s.toType(n)), e = s;
}
if (e?.isIRange)
return ((s, i) => {
let l = s.next();
for (; !l.done; ) {
let c = l.value;
if (c instanceof pt.Value) return c;
i.push(c), l = s.next();
}
})(e.values({ type: n, coerce: !0, includeMistyped: !o, ...P0 }), t);
if (n) {
if (e = Xe(e, _e(e, !0), n, r !== null), o) return;
if (e instanceof pt.Value) return e;
}
t.push(e);
}, wo = (a, t, e, n, r, o) => {
if (r === "r") {
let i = e;
return i && i.isIReferenceRange ? (n && (i = i.toType(n)), void t.push(e)) : new pt.Value("Cannot convert a literal to a reference.");
}
let s = e?.isIRange ? e : null;
if (r !== "l") {
if (s) {
const i = s.getValues({ type: n });
return void t.push(i);
}
{
Array.isArray(e) || (e = [e]);
const i = e.length, l = new Array(i);
for (let c = 0; c < i; c++) {
let h = e[c];
Array.isArray(h) || (h = [h]);
const d = h.length, u = new Array(d);
for (let g = 0; g < d; g++) {
let m = h[g];
if (n && (m = Xe(m, _e(m, !0), n)), m instanceof pt.Value) return m;
u[g] = m;
}
l[c] = u;
}
t.push(l);
}
} else {
if (s) n && s.getScalarType() !== n && (s = s.toType(n));
else try {
if (!o && (e = Gi(e), n && (e = Xe(e, _e(e, !0), n, !0), e?.isFormulaError && n !== Y.Error))) return t.push(e), e;
s = a.getRange(e), n && (s = s.toType(n));
} catch (i) {
return i;
}
t.push(s);
}
}, Gi = (a, t, e = typeof a) => {
if (e === "number") return isNaN(a) ? pt.BuiltIn.Num : isFinite(a) ? a += 0 : pt.BuiltIn.Div0;
if (a == null) return null;
if (!t) return a;
if (Array.isArray(a)) try {
a = t.getRange(a);
} catch {
return pt.BuiltIn.Value;
}
return t.isValidDate(a) ? (t.formatResults("Short Date"), t.toOADate(a)) : a;
}, W0 = (a, t, e, n) => {
let r;
r = Array.isArray(a) ? Array.isArray(a[0]) ? a : [a] : [[a]], t || (t = new hn({ orientation: F.Orientation.Column }));
const o = t.getOrientation() === F.Orientation.Column, s = xi(r, o, Te(e?.colStart ?? 0, e?.rowStart ?? 0, void 0, void 0, o), !0), i = Zo(s.bounds, o);
return t.setValues(s.tuples), new me(t, i, n, !e);
}, H0 = new RegExp(/^([$]?[a-zA-Z]*[$]?[0-9]*)[:]?([$]?[a-zA-Z]*[$]?[0-9]*)?$/), V0 = new RegExp(/^(R(?:\[?[-+]?\d+\]?|\d+)?C(?:\[?[-+]?\d+\]?|\d+)?)(:(R(?:\[?[-+]?\d+\]?|\d+)?C(?:\[?[-+]?\d+\]?|\d+)?))?$/, "i"), j0 = new RegExp(/^(R?)(\[?[-+]?\d+\]?|\d+)?(C?)(\[?[-+]?\d+\]?|\d+)?$/, "i"), $0 = new RegExp("(?:'[^']+'|[A-Za-z0-9_\\-.]+?!)?(\\$?[A-Za-z]+\\$?\\d+(?::\\$?[A-Za-z]+\\$?\\d+)?|\\$?[A-Za-z]+:\\$?[A-Za-z]+|\\$?\\d+:\\$?\\d+)", "g"), G0 = /\s+/g, U0 = /"(?:[^"]|"")*"|\[[^[\]]+\]/g, ka = /[\uE000-\uF8FF]/g, ie = "#REF!", tm = Math.pow(2, 14), q0 = Math.pow(2, 20);
let rd, od;
const dn = (a) => (rd === a || (od = "" + (a + 1), rd = a), od);
let sd, Oa;
const tn = (a) => {
if (sd === a) return Oa;
if (sd = a, a < 0) throw new Error("invalid column " + a);
let t = "";
for (++a; a; a = Math.floor((a - 1) / 26)) t = String.fromCharCode((a - 1) % 26 + 65) + t;
return Oa = t, Oa;
}, J0 = /[^a-zA-Z0-9]/, as = (a) => a ? tn(a.colIndex) + dn(a.rowIndex) : null, nr = (a) => {
if (!a) return ie;
const t = tn(a.colIndex), e = dn(a.rowIndex);
return (a.$colIndex ? "$" + t : t) + (a.$rowIndex ? "$" + e : e);
}, sc = (a, t) => {
let e = a ?? t;
var n;
return e && (e = Zl(e), e = e.replace(/'/g, "''"), n = e, J0.test(n) && (e = Eg(e))), e;
}, em = (a, t) => a ? a + (a.endsWith("!") ? "" : "!") + t : ie, kn = (a, t, e = as) => {
if (!a) return null;
const n = a.colStart, r = a.rowStart, o = a.colEnd, s = a.rowEnd;
if (n === o && r === s) return e({ colIndex: n, rowIndex: r });
a = { ...t, ...a };
const i = n === Number.MIN_SAFE_INTEGER || t && n <= t.colStart && o >= t.colEnd, l = r === Number.MIN_SAFE_INTEGER || t && r <= t.rowStart && s >= t.rowEnd;
let c = null;
c = l ? tn(n) : i ? dn(r) : e({ colIndex: n, rowIndex: r });
let h = null;
return h = l ? tn(o) : i ? dn(s) : e({ colIndex: o, rowIndex: s }), c + ":" + h;
}, Da = (a, t, e = nr) => {
if (!a) return ie;
const n = a.colIndex, r = a.rowIndex, o = n === Number.MIN_SAFE_INTEGER;
let s = null;
if (r === Number.MIN_SAFE_INTEGER ? (s = tn(n), a.$colIndex && (s = "$" + s)) : o ? (s = dn(r), a.$rowIndex && (s = "$" + s)) : s = e(a), a.sheetName || t) {
const i = sc(a.sheetName, t);
s = em(i, s);
}
return s;
}, ln = (a, t, e = nr) => {
if (!a) return ie;
const n = a.rowStart !== void 0 && a.rowStart === a.rowEnd;
if (a.colStart !== void 0 && a.colStart === a.colEnd && n) return e({ colIndex: a.colStart, rowIndex: a.rowStart, $colIndex: a.$colStart, $rowIndex: a.$rowStart });
a = { ...t, ...a };
const r = t && a.rowStart <= t.rowStart && a.rowEnd >= t.rowEnd, o = t && a.colStart <= t.colStart && a.colEnd >= t.colEnd;
let s = null;
r ? (s = tn(a.colStart), s = a.$colStart ? "$" + s : s) : o ? (s = dn(a.rowStart), s = a.$rowStart ? "$" + s : s) : s = e({ colIndex: a.colStart, rowIndex: a.rowStart, $colIndex: a.$colStart, $rowIndex: a.$rowStart });
let i = null;
return r ? (i = tn(a.colEnd), i = a.$colEnd ? "$" + i : i) : o ? (i = dn(a.rowEnd), i = a.$rowEnd ? "$" + i : i) : i = e({ colIndex: a.colEnd, rowIndex: a.rowEnd, $colIndex: a.$colEnd, $rowIndex: a.$rowEnd }), s + ":" + i;
}, Ui = (a, t, e = nr) => {
const n = ln(a, t, e), r = sc(a?.sheetName, t?.sheetName);
return em(r, n);
}, nm = (a, t = !1) => {
if (!a) return null;
let e = 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), e === 0 && !t) return;
} else if (c >= 65 && c <= 90) {
if (e = 26 * e + (c - 64), n !== 0) return;
} else if (c >= 97 && c <= 122) {
if (e = 26 * e + (c - 96), n !== 0) return;
} else {
if (c !== 36) return;
if (e !== 0 || r) {
if (n !== 0 || o) return;
o = !0;
} else r = !0;
}
}
const i = {};
return t || n !== 0 && e !== 0 ? (e > 0 && (i.colIndex = e - 1, r && (i.$colIndex = r)), n > 0 && (i.rowIndex = n - 1, (o || t && r) && (i.$rowIndex = o || t && r)), i) : null;
}, Pe = (a, t = is, e = !1) => {
if (!a) return null;
let n = a.toUpperCase();
const r = sm(n, e);
let o = null, s = null;
if (r?.[1]) {
const l = !!r[2], c = e ? ci : nm;
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 > t?.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)), { ...t, ...i });
}, ls = (a, t, e = !1) => {
const n = ((o) => {
const s = o.lastIndexOf("!");
if (s === -1) return null;
let i = o.slice(0, s);
return i = Zl(i), i = i.replace(/''/g, "'"), [i, o.slice(s + 1)];
})(a);
let r;
if (n) {
if (r = Pe(n[1], t, e), !r) return null;
r.sheetName = n[0];
} else r = Pe(a, t, e);
return r || null;
}, ic = (a, t, e = ln, n = nr) => {
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 = e(i, t, n) : typeof i == "string" && (l = i) : l = ie, l && r.push(l);
}
return r;
}, rm = (a, t, e = Ui, n = nr) => {
const r = ic(a, t, e, n);
return r ? r.join(",") : ie;
}, om = (a, t, e, n = ls, r, o = !1) => {
if (t !== null) {
if (typeof t == "string") {
const s = n(t, e, o);
if (!s) {
const i = r?.(t);
if (i) {
const l = i.length;
for (let c = 0; c < l; c++) {
const h = i[c];
om(a, h, e, n, r, o);
}
}
return;
}
t = s;
} else t.isICellRange ? t = t.getCoords() : t.isICell && (t = L.cellToRange(t.getCoords()));
if (t !== null) {
if (t.rowStart !== void 0 || t.colStart !== void 0 || t.colEnd !== void 0 || t.rowEnd !== void 0) {
const s = t;
a.push({ ...e, ...s });
} else if (t.rowIndex !== void 0 || t.colIndex !== void 0) {
const s = t, i = { ...e, ...s, colStart: s.colIndex, rowStart: s.rowIndex, colEnd: s.colIndex, rowEnd: s.rowIndex };
i.sheetName === null && e.sheetName && (i.sheetName = e.sheetName), delete i.colIndex, delete i.rowIndex, a.push(i);
}
} else a.push(null);
} else a.push(null);
}, qi = (a, t, e = ls, n, r = !1) => {
if (!a) return [t];
let o;
o = typeof a == "string" ? bg(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];
om(s, c, t, e, n, r);
}
return s;
}, Wr = (a, t) => {
let e = 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 (e = 10 * e + (s - 48), n === 0) return;
} else if (s >= 65 && s <= 90) {
if (n = 26 * n + (s - 64), e !== 0) return;
} else if (!(s >= 97 && s <= 122) || (n = 26 * n + (s - 96), e !== 0)) return;
}
return t ? (t.colIndex = n - 1, t.rowIndex = e - 1, t) : { colIndex: n - 1, rowIndex: e - 1 };
}, ci = (a, t = !1, e) => {
e ? (e.colIndex = Number.MIN_SAFE_INTEGER, e.rowIndex = Number.MIN_SAFE_INTEGER, e.$colIndex = !1, e.$rowIndex = !1) : e = { colIndex: Number.MIN_SAFE_INTEGER, rowIndex: Number.MIN_SAFE_INTEGER, $colIndex: !1, $rowIndex: !1 };
const n = j0.exec(a);
if (!n) return null;
const r = n[1], o = n[3];
if (!(t || r && o)) return null;
if (r) {
const s = n[2];
s ? s && (s.startsWith("[") ? (e.rowIndex = parseInt(s.slice(1, -1)), e.$rowIndex = !1) : (e.rowIndex = parseInt(s) - 1, e.$rowIndex = !0)) : (e.rowIndex = 0, e.$rowIndex = !1);
}
if (o) {
const s = n[4];
s ? s.startsWith("[") ? (e.colIndex = parseInt(s.slice(1, -1)), e.$colIndex = !1) : (e.colIndex = parseInt(s) - 1, e.$colIndex = !0) : (e.colIndex = 0, e.$colIndex = !1);
}
return e;
}, kl = (a, t) => {
let e = 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 ? e = 10 * e + (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--, e--, t.colIndex = n, t.rowIndex = e, e === -1 ? (t.$colIndex = r, t.$rowIndex = !1, t) : n === -1 ? (t.$colIndex = !1, t.$rowIndex = r, t) : (t.$colIndex = r, t.$rowIndex = o, t);
}, K0 = (a) => {
let t = 0;
const e = a.length;
for (let n = 0; n < e; ++n) {
const r = a.charCodeAt(n);
if (r >= 65 && r <= 90) t = 26 * t + (r - 64);
else {
if (!(r >= 97 && r <= 122)) return t - 1;
t = 26 * t + (r - 96);
}
}
return t - 1;
}, Ae = (a, t) => {
let e = t;
e ? (e.rowStart = 0, e.colStart = 0, e.rowEnd = 0, e.colEnd = 0) : e = { 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 (e.colStart = --n, n = 0; r < s; ++r) {
let i = a.charCodeAt(r) - 48;
if (i < 0 || i > 9) break;
n = 10 * n + i;
}
if (e.rowStart = --n, r === s || a.charCodeAt(++r) === 58) return e.colEnd = e.colStart, e.rowEnd = e.rowStart, e;
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 (e.colEnd = --n, n = 0; r !== s; ++r) {
let i = a.charCodeAt(r) - 48;
if (i < 0 || i > 9) break;
n = 10 * n + i;
}
return e.rowEnd = --n, e;
}, sm = (a, t = !1) => {
const e = a.match(t ? V0 : H0);
return a.endsWith(":") ? null : e;
}, Ol = { rowIndex: -1, colIndex: -1, $colIndex: !1, $rowIndex: !1 }, La = (a, t, e, n = tm) => {
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 - t;
c += g === 0 ? "R" : `R[${g}]`;
}
let d = "";
const u = s.colIndex;
if (u !== -1) if (s.$colIndex) d += `C${u + 1}`;
else {
const g = u - e;
d += g === 0 ? "C" : `C[${g}]`;
}
o += c + d;
};
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);
}, qr = [], X0 = (a) => (qr.push(a), String.fromCharCode(57344 + qr.length - 1)), Y0 = (a) => {
const t = a.charCodeAt(0) - 57344;
return qr[t];
}, Q0 = (a, t, e) => {
let n = "";
const r = a.length;
for (let o = 0; o < r; o++) {
const s = a[o];
n += typeof s == "string" ? s : im(s, t, e);
}
return n;
}, hi = (a, t) => {
let e = "";
const n = a.rowIndex;
n !== Number.MIN_SAFE_INTEGER && (a.$rowIndex ? e += `R${n + 1}` : e += 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 && (e = sc(a.sheetName, t) + "!" + e), e + r;
}, im = (a, t, e) => {
let n = "";
const r = a.colIndex;
r !== Number.MIN_SAFE_INTEGER && (a.$colIndex ? n += "$" + tn(r) : n += tn(r + e));
const o = a.rowIndex;
return o !== Number.MIN_SAFE_INTEGER && (a.$rowIndex ? n += "$" + dn(o) : n += dn(o + t)), n;
}, wy = (a, t, e, 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, d = a.$rowEnd ?? !1;
if (l || r === Number.MIN_SAFE_INTEGER || (r += e), c || o === Number.MIN_SAFE_INTEGER || (o += t), h || s === Number.MAX_SAFE_INTEGER || (s += e), d || i === Number.MAX_SAFE_INTEGER || (i += t), r > s) {
const g = r;
r = s, s = g;
}
if (o > i) {
const g = o;
o = i, i = g;
}
let u;
return n ? (u = n, u.colStart = r, u.rowStart = o, u.colEnd = s, u.rowEnd = i, u.$colStart = l, u.$rowStart = c, u.$colEnd = h, u.$rowEnd = d) : u = { colStart: r, rowStart: o, colEnd: s, rowEnd: i, $colStart: l, $rowStart: c, $colEnd: h, $rowEnd: d }, a.sheetName && (u.sheetName = a.sheetName), u;
}, Z0 = (a, t, e, n) => {
qr.length = 0;
let r = 0, o = a.replace(U0, X0), s = 0, i = o.replace($0, (l, c, h) => {
const d = La(l, t, e);
if (n) {
if (h > s) {
const g = o.slice(s, h).replace(ka, (m, f) => qr[r++]);
n.push(g);
}
const u = l.lastIndexOf(":");
if (u !== -1) {
const g = l.slice(0, u), m = l.slice(u + 1), f = La(g, t, e), p = La(m, t, e);
n.push(ci(f, !0) ?? f), n.push(":"), n.push(ci(p, !0) ?? p);
} else n.push(ci(d, !0) ?? d);
}
return s = h + l.length, d;
});
if (n && s < o.length) {
const l = o.slice(s);
n.push(l.replace(ka, (c, h) => qr[r++]));
}
return i = i.toUpperCase().replace(G0, ""), i.replace(ka, Y0);
}, pr = "Must specify an address.", am = "Only a single range is allowed for this operation. Use 'getRanges' instead.", id = "Only a single cell is allowed.", lm = "Invalid range. The Range must be specified as '{ TOP_LEFT:BOTTOM_RIGHT }'.", Jr = (a) => `Invalid address. Can not parse ${typeof a == "string" ? `'${a}' ` : ""}as an address or named item.`, vt = () => {
throw new Error("Invalid range.");
};
class _r {
constructor(t, e, n = !1) {
this._c = t, this._cycleId = e, this._e = n;
}
getCycleId() {
return this._cycleId;
}
getError() {
return this._e;
}
getCoords() {
return this._c;
}
setError(t, e) {
const n = this._c;
return { ...n, value: new _r(n, e, t) };
}
getShifted(t) {
const e = t.after;
if (!e) return null;
const n = L.sanitizeRange(e);
return { ...n, value: new _r(n, this._cycleId, this._e) };
}
getMerged(t, e, n) {
}
getSplit(t, e) {
}
}
class Ye {
constructor(t, e) {
this._c = t, this._o = e;
}
getCoords() {
return this._c;
}
getOrientation() {
return this._o;
}
getShifted(t) {
return t.after ? { ...t.after, value: new Ye(t.after, this._o) } : null;
}
getMerged(t, e, n) {
const r = this._o;
return new Ye(e, r);
}
getSplit(t, e) {
const n = this._o;
return [new Ye(t[0], n), new Ye(t[1], n)];
}
getState() {
return this._c;
}
}
const ad = (a, t) => {
if (!a || a.length === 0) return k.EmptyArray;
const e = [], n = t ? F.Orientation.Column : F.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], d = c[1].length - 1, u = { colStart: t ? s : h, rowStart: t ? h : s, colEnd: t ? s : h + d, rowEnd: t ? h + d : s, value: new Ye({ colStart: t ? s : h, rowStart: t ? h : s, colEnd: t ? s : h + d, rowEnd: t ? h + d : s }, n) };
e.push(u);
}
}
return e;
}, Dl = 0, ld = 1;
class vn {
constructor(t, e, n) {
this.ref = t, this.formula = e;
const r = t.colStart, o = t.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 d = 0; d < h; d++) {
const u = { ...c[d] };
c[d] = u, u.colIndex = d + r, u.rowIndex = l + o, u.block = this;
}
}
this.calcs = s;
} else {
const s = e.getDirectPrecedentsAt(o, r), i = s?.length ?? 0, l = new Array(t.rowEnd - o + 1), c = t.colEnd - r + 1, h = l.length;
for (let d = 0; d < h; d++) {
const u = new Array(c), g = u.length;
for (let m = 0; m < g; m++) u[m] = { block: this, colIndex: m + r, rowIndex: d + o, cycleId: 0, markId: 0, inDegree: 0, dependents: k.EmptyArray, inputs: i === 0 ? k.EmptyArray : new Array(i), precedents: i === 0 ? k.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[d] = u;
}
this.calcs = l;
}
}
toJSON() {
const t = this.ref;
return [kn(t), this.formula.getTextAt(t.rowStart, t.colStart)];
}
getCoords() {
return this.ref;
}
getShifted(t) {
if (!t.after) return null;
const e = L.sanitizeRange(t.after), n = [...this.calcs], r = new vn(e, this.formula, n);
return { ...t.after, value: r };
}
setReferenceAt(t, e) {
const n = this.formula.setReferenceAt(t, e), r = [...this.calcs];
return new vn(this.ref, n, r);
}
getMerged(t, e, n) {
const r = this.formula, o = t.formula;
if (!r.isEquals(o)) return;
const s = this.calcs, i = t.calcs;
let l;
if (n === F.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 vn(e, r, l);
}
getSplit(t, e, n) {
const r = this.formula, o = e === F.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 d = l[h];
s[h] = d.slice(0, n), i[h] = d.slice(n);
}
} else s = l.slice(0, n), i = l.slice(n);
return [new vn(t[0], r, s), new vn(t[1], r, i)];
}
copyTo(t, e) {
const n = this.formula;
return new vn(t, n);
}
canTile(t, e) {
return !0;
}
onRemove(t) {
const e = t.value.calcs, n = e.length;
for (let r = 0; r < n; r++) {
const o = e[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 t_ = Object.freeze({ break: !0 });
var ht;
(ht || (ht = {})).Type = { Style: "style", Continuous: "continuous", Table: "table", Merge: "merge", Hyperlink: "hyperlink", Comments: "comments", Unlock: "unlock", Contentful: "contentful", Conditional: "conditional", Formula: "formula", Spill: "spill", Pending: "pending", CalcError: "calcError", Validation: "dataValidation" };
const e_ = Object.freeze({ [ht.Type.Style]: !1, [ht.Type.Table]: !1, [ht.Type.Merge]: !1, [ht.Type.Hyperlink]: !1, [ht.Type.Comments]: !1, [ht.Type.Unlock]: !1, [ht.Type.Formula]: !1, [ht.Type.Spill]: !1, [ht.Type.Pending]: !1, [ht.Type.CalcError]: !1, [ht.Type.Contentful]: !1, [ht.Type.Conditional]: !1, [ht.Type.Continuous]: !1 }), cm = Object.freeze({ [ht.Type.Style]: !1, [ht.Type.Table]: !1, [ht.Type.Merge]: !1, [ht.Type.Hyperlink]: !1, [ht.Type.Comments]: !1, [ht.Type.Unlock]: !1, [ht.Type.Formula]: !1, [ht.Type.Spill]: !1, [ht.Type.Pending]: !1, [ht.Type.CalcError]: !1, [ht.Type.Conditional]: !1, [ht.Type.Continuous]: !1 }), n_ = Object.freeze({ [ht.Type.Style]: !1, [ht.Type.Table]: !0, [ht.Type.Merge]: !1, [ht.Type.Hyperlink]: !1, [ht.Type.Comments]: !1, [ht.Type.Unlock]: !1, [ht.Type.Formula]: !1 });
Object.freeze({ [ht.Type.Style]: !1, [ht.Type.Table]: !1, [ht.Type.Hyperlink]: !1, [ht.Type.Comments]: !1, [ht.Type.Unlock]: !1, [ht.Type.Contentful]: !1, [ht.Type.Formula]: !1 });
const r_ = Object.freeze({ [ht.Type.Style]: !1, [ht.Type.Hyperlink]: !1, [ht.Type.Continuous]: !1, [ht.Type.Contentful]: !1 }), bs = "This sheet is protected. To make a change, unprotect the sheet. You might be requested to enter a password.", o_ = (a = "update") => `Unable to ${a}, this sheet is protected. To make a change, unprotect the sheet. You might be requested to enter a password.`, Ri = "The range is outside of the bounds of the sheet.", cd = "Listener can not be null", hd = "We can't insert items. The sheet is protected.", dd = (a) => `We can't create a ${a} that overlaps with another table or merge.`, ud = "Overlapping ranges can not be merged.", Ba = "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.", gd = "Unable to partially fill over merged cells.", md = "Unable to sort merged cells unless they are all the same size.", xe = "Sheet has been closed. No further operations are allowed.", Kr = "IteratorContext can only be used during visit.", fd = "When using addresses directly from the sheet do not include the sheet name.", hm = (a) => `Unable to return more than ${a} values. To access values in a more scalable solution use 'ICellRange.forEach' or an iterator.`, pd = "'setValue' expects a single value; when working with an array use 'setValue'.", _d = "Multiple selection ranges can not be copied.", Sd = "Unable to determine source.", wd = "When pasting before or after the cut area both areas must align.", s_ = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date, yd = /* @__PURE__ */ new Set(), Ll = typeof process == "object" && process ? process : {}, dm = (a, t, e, n) => {
typeof Ll.emitWarning == "function" ? Ll.emitWarning(a, t, e, n) : console.error(`[${e}] ${t}: ${a}`);
};
let Ai = globalThis.AbortController, Cd = globalThis.AbortSignal;
if (Ai === void 0) {
Cd = class {
onabort;
_onabort = [];
reason;
aborted = !1;
addEventListener(e, n) {
this._onabort.push(n);
}
}, Ai = class {
constructor() {
t();
}
signal = new Cd();
abort(e) {
if (!this.signal.aborted) {
this.signal.reason = e, this.signal.aborted = !0;
for (const n of this.signal._onabort) n(e);
this.signal.onabort?.(e);
}
}
};
let a = Ll.env?.LRU_CACHE_IGNORE_AC_WARNING !== "1";
const t = () => {
a && (a = !1, dm("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", t));
};
}
const $n = (a) => a && a === Math.floor(a) && a > 0 && isFinite(a), um = (a) => $n(a) ? a <= Math.pow(2, 8) ? Uint8Array : a <= Math.pow(2, 16) ? Uint16Array : a <= Math.pow(2, 32) ? Uint32Array : a <= Number.MAX_SAFE_INTEGER ? di : null : null;
class di extends Array {
constructor(t) {
super(t), this.fill(0);
}
}
class Hr {
heap;
length;
static #l = !1;
static create(t) {
const e = um(t);
if (!e) return [];
Hr.#l = !0;
const n = new Hr(t, e);
return Hr.#l = !1, n;
}
constructor(t, e) {
if (!Hr.#l) throw new TypeError("instantiate Stack using Stack.create(n)");
this.heap = new e(t), this.length = 0;
}
push(t) {
this.heap[this.length++] = t;
}
pop() {
return this.heap[--this.length];
}
}
class ac {
#l;
#d;
#f;
#A;
#p;
#F;
#k;
#_;
get perf() {
return this.#_;
}
ttl;
ttlResolution;
ttlAutopurge;
updateAgeOnGet;
updateAgeOnHas;
allowStale;
noDisposeOnSet;
noUpdateTTL;
maxEntrySize;
sizeCalculation;
noDeleteOnFetchRejection;
noDeleteOnStaleGet;
allowStaleOnFetchAbort;
allowStaleOnFetchRejection;
ignoreFetchAbort;
#o;
#S;
#r;
#n;
#t;
#c;
#u;
#a;
#s;
#w;
#i;
#y;
#C;
#g;
#E;
#R;
#h;
#O;
static unsafeExposeInternals(t) {
return { starts: t.#C, ttls: t.#g, sizes: t.#y, keyMap: t.#r, keyList: t.#n, valList: t.#t, next: t.#c, prev: t.#u, get head() {
return t.#a;
}, get tail() {
return t.#s;
}, free: t.#w, isBackgroundFetch: (e) => t.#e(e), backgroundFetch: (e, n, r, o) => t.#B(e, n, r, o), moveToTail: (e) => t.#N(e), indexes: (e) => t.#b(e), rindexes: (e) => t.#v(e), isStale: (e) => t.#m(e) };
}
get max() {
return this.#l;
}
get maxSize() {
return this.#d;
}
get calculatedSize() {
return this.#S;
}
get size() {
return this.#o;
}
get fetchMethod() {
return this.#F;
}
get memoMethod() {
return this.#k;
}
get dispose() {
return this.#f;
}
get onInsert() {
return this.#A;
}
get disposeAfter() {
return this.#p;
}
constructor(t) {
const { max: e = 0, ttl: n, ttlResolution: r = 1, ttlAutopurge: o, updateAgeOnGet: s, updateAgeOnHas: i, allowStale: l, dispose: c, onInsert: h, disposeAfter: d, noDisposeOnSet: u, noUpdateTTL: g, maxSize: m = 0, maxEntrySize: f = 0, sizeCalculation: p, fetchMethod: _, memoMethod: S, noDeleteOnFetchRejection: C, noDeleteOnStaleGet: y, allowStaleOnFetchRejection: E, allowStaleOnFetchAbort: w, ignoreFetchAbort: b, perf: v } = t;
if (v !== void 0 && typeof v?.now != "function") throw new TypeError("perf option must have a now() method if specified");
if (this.#_ = v ?? s_, e !== 0 && !$n(e)) throw new TypeError("max option must be a nonnegative integer");
const I = e ? um(e) : Array;
if (!I) throw new Error("invalid max value: " + e);
if (this.#l = e, this.#d = m, this.maxEntrySize = f || this.#d, this.sizeCalculation = p, this.sizeCalculation) {
if (!this.#d && !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.#k = S, _ !== void 0 && typeof _ != "function") throw new TypeError("fetchMethod must be a function if specified");
if (this.#F = _, this.#R = !!_, this.#r = /* @__PURE__ */ new Map(), this.#n = new Array(e).fill(void 0), this.#t = new Array(e).fill(void 0), this.#c = new I(e), this.#u = new I(e), this.#a = 0, this.#s = 0, this.#w = Hr.create(e), this.#o = 0, this.#S = 0, typeof c == "function" && (this.#f = c), typeof h == "function" && (this.#A = h), typeof d == "function" ? (this.#p = d, this.#i = []) : (this.#p = void 0, this.#i = void 0), this.#E = !!this.#f, this.#O = !!this.#A, this.#h = !!this.#p, this.noDisposeOnSet = !!u, this.noUpdateTTL = !!g, this.noDeleteOnFetchRejection = !!C, this.allowStaleOnFetchRejection = !!E, this.allowStaleOnFetchAbort = !!w, this.ignoreFetchAbort = !!b, this.maxEntrySize !== 0) {
if (this.#d !== 0 && !$n(this.#d)) throw new TypeError("maxSize must be a positive integer if specified");
if (!$n(this.maxEntrySize)) throw new TypeError("maxEntrySize must be a positive integer if specified");
this.#$();
}
if (this.allowStale = !!l, this.noDeleteOnStaleGet = !!y, this.updateAgeOnGet = !!s, this.updateAgeOnHas = !!i, this.ttlResolution = $n(r) || r === 0 ? r : 1, this.ttlAutopurge = !!o, this.ttl = n || 0, this.ttl) {
if (!$n(this.ttl)) throw new TypeError("ttl must be a positive integer if specified");
this.#z();
}
if (this.#l === 0 && this.ttl === 0 && this.#d === 0) throw new TypeError("At least one of max, maxSize, or ttl is required");
if (!this.ttlAutopurge && !this.#l && !this.#d) {
const x = "LRU_CACHE_UNBOUNDED";
((R) => !yd.has(R))(x) && (yd.add(x), dm("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", x, ac));
}
}
getRemainingTTL(t) {
return this.#r.has(t) ? 1 / 0 : 0;
}
#z() {
const t = new di(this.#l), e = new di(this.#l);
this.#g = t, this.#C = e, this.#P = (o, s, i = this.#_.now()) => {
if (e[o] = s !== 0 ? i : 0, t[o] = s, s !== 0 && this.ttlAutopurge) {
const l = setTimeout(() => {
this.#m(o) && this.#x(this.#n[o], "expire");
}, s + 1);
l.unref && l.unref();
}
}, this.#M = (o) => {
e[o] = t[o] !== 0 ? this.#_.now() : 0;
}, this.#I = (o, s) => {
if (t[s]) {
const i = t[s], l = e[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 = this.#_.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 = t[s], l = e[s];
return !i || !l ? 1 / 0 : i - ((n || r()) - l);
}, this.#m = (o) => {
const s = e[o], i = t[o];
return !!i && !!s && (n || r()) - s > i;
};
}
#M = () => {
};
#I = () => {
};
#P = () => {
};
#m = () => !1;
#$() {
const t = new di(this.#l);
this.#S = 0, this.#y = t, this.#T = (e) => {
this.#S -= t[e], t[e] = 0;
}, this.#W = (e, n, r, o) => {
if (this.#e(n)) return 0;
if (!$n(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, e), !$n(r)) throw new TypeError("sizeCalculation return invalid (expect positive integer)");
}
return r;
}, this.#D = (e, n, r) => {
if (t[e] = n, this.#d) {
const o = this.#d - t[e];
for (; this.#S > o; ) this.#L(!0);
}
this.#S += t[e], r && (r.entrySize = n, r.totalCalculatedSize = this.#S);
};
}
#T = (t) => {
};
#D = (t, e, n) => {
};
#W = (t, e, n, r) => {
if (n || r) throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
return 0;
};
*#b({ allowStale: t = this.allowStale } = {}) {
if (this.#o) for (let e = this.#s; this.#H(e) && (!t && this.#m(e) || (yield e), e !== this.#a); ) e = this.#u[e];
}
*#v({ allowStale: t = this.allowStale } = {}) {
if (this.#o) for (let e = this.#a; this.#H(e) && (!t && this.#m(e) || (yield e), e !== this.#s); ) e = this.#c[e];
}
#H(t) {
return t !== void 0 && this.#r.get(this.#n[t]) === t;
}
*entries() {
for (const t of this.#b()) this.#t[t] === void 0 || this.#n[t] === void 0 || this.#e(this.#t[t]) || (yield [this.#n[t], this.#t[t]]);
}
*rentries() {
for (const t of this.#v()) this.#t[t] === void 0 || this.#n[t] === void 0 || this.#e(this.#t[t]) || (yield [this.#n[t], this.#t[t]]);
}
*keys() {
for (const t of this.#b()) {
const e = this.#n[t];
e === void 0 || this.#e(this.#t[t]) || (yield e);
}
}
*rkeys() {
for (const t of this.#v()) {
const e = this.#n[t];
e === void 0 || this.#e(this.#t[t]) || (yield e);
}
}
*values() {
for (const t of this.#b())
this.#t[t] === void 0 || this.#e(this.#t[t]) || (yield this.#t[t]);
}
*rvalues() {
for (const t of this.#v())
this.#t[t] === void 0 || this.#e(this.#t[t]) || (yield this.#t[t]);
}
[Symbol.iterator]() {
return this.entries();
}
[Symbol.toStringTag] = "LRUCache";
find(t, e = {}) {
for (const n of this.#b()) {
const r = this.#t[n], o = this.#e(r) ? r.__staleWhileFetching : r;
if (o !== void 0 && t(o, this.#n[n], this)) return this.get(this.#n[n], e);
}
}
forEach(t, e = this) {
for (const n of this.#b()) {
const r = this.#t[n], o = this.#e(r) ? r.__staleWhileFetching : r;
o !== void 0 && t.call(e, o, this.#n[n], this);
}
}
rforEach(t, e = this) {
for (const n of this.#v()) {
const r = this.#t[n], o = this.#e(r) ? r.__staleWhileFetching : r;
o !== void 0 && t.call(e, o, this.#n[n], this);
}
}
purgeStale() {
let t = !1;
for (const e of this.#v({ allowStale: !0 })) this.#m(e) && (this.#x(this.#n[e], "expire"), t = !0);
return t;
}
info(t) {
const e = this.#r.get(t);
if (e === void 0) return;
const n = this.#t[e], r = this.#e(n) ? n.__staleWhileFetching : n;
if (r === void 0) return;
const o = { value: r };
if (this.#g && this.#C) {
const s = this.#g[e], i = this.#C[e];
if (s && i) {
const l = s - (this.#_.now() - i);
o.ttl = l, o.start = Date.now();
}
}
return this.#y && (o.size = this.#y[e]), o;
}
dump() {
const t = [];
for (const e of this.#b({ allowStale: !0 })) {
const n = this.#n[e], r = this.#t[e], o = this.#e(r) ? r.__staleWhileFetching : r;
if (o === void 0 || n === void 0) continue;
const s = { value: o };
if (this.#g && this.#C) {
s.ttl = this.#g[e];
const i = this.#_.now() - this.#C[e];
s.start = Math.floor(Date.now() - i);
}
this.#y && (s.size = this.#y[e]), t.unshift([n, s]);
}
return t;
}
load(t) {
this.clear();
for (const [e, n] of t) {
if (n.start) {
const r = Date.now() - n.start;
n.start = this.#_.now() - r;
}
this.set(e, n.value, n);
}
}
set(t, e, n = {}) {
if (e === void 0) return this.delete(t), 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.#W(t, e, n.size || 0, i);
if (this.maxEntrySize && h > this.maxEntrySize) return l && (l.set = "miss", l.maxEntrySizeExceeded = !0), this.#x(t, "set"), this;
let d = this.#o === 0 ? void 0 : this.#r.get(t);
if (d === void 0) d = this.#o === 0 ? this.#s : this.#w.length !== 0 ? this.#w.pop() : this.#o === this.#l ? this.#L(!1) : this.#o, this.#n[d] = t, this.#t[d] = e, this.#r.set(t, d), this.#c[this.#s] = d, this.#u[d] = this.#s, this.#s = d, this.#o++, this.#D(d, h, l), l && (l.set = "add"), c = !1, this.#O && this.#A?.(e, t, "add");
else {
this.#N(d);
const u = this.#t[d];
if (e !== u) {
if (this.#R && this.#e(u)) {
u.__abortController.abort(new Error("replaced"));
const { __staleWhileFetching: g } = u;
g === void 0 || s || (this.#E && this.#f?.(g, t, "set"), this.#h && this.#i?.push([g, t, "set"]));
} else s || (this.#E && this.#f?.(u, t, "set"), this.#h && this.#i?.push([u, t, "set"]));
if (this.#T(d), this.#D(d, h, l), this.#t[d] = e, l) {
l.set = "replace";
const g = u && this.#e(u) ? u.__staleWhileFetching : u;
g !== void 0 && (l.oldValue = g);
}
} else l && (l.set = "update");
this.#O && this.onInsert?.(e, t, e === u ? "update" : "replace");
}
if (r === 0 || this.#g || this.#z(), this.#g && (c || this.#P(d, r, o), l && this.#I(l, d)), !s && this.#h && this.#i) {
const u = this.#i;
let g;
for (; g = u?.shift(); ) this.#p?.(...g);
}
return this;
}
pop() {
try {
for (; this.#o; ) {
const t = this.#t[this.#a];
if (this.#L(!0), this.#e(t)) {
if (t.__staleWhileFetching) return t.__staleWhileFetching;
} else if (t !== void 0) return t;
}
} finally {
if (this.#h && this.#i) {
const t = this.#i;
let e;
for (; e = t?.shift(); ) this.#p?.(...e);
}
}
}
#L(t) {
const e = this.#a, n = this.#n[e], r = this.#t[e];
return this.#R && this.#e(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.#T(e), t && (this.#n[e] = void 0, this.#t[e] = void 0, this.#w.push(e)), this.#o === 1 ? (this.#a = this.#s = 0, this.#w.length = 0) : this.#a = this.#c[e], this.#r.delete(n), this.#o--, e;
}
has(t, e = {}) {
const { updateAgeOnHas: n = this.updateAgeOnHas, status: r } = e, o = this.#r.get(t);
if (o !== void 0) {
const s = this.#t[o];
if (this.#e(s) && s.__staleWhileFetching === void 0) return !1;
if (!this.#m(o)) return n && this.#M(o), r && (r.has = "hit", this.#I(r, o)), !0;
r && (r.has = "stale", this.#I(r, o));
} else r && (r.has = "miss");
return !1;
}
peek(t, e = {}) {
const { allowStale: n = this.allowStale } = e, r = this.#r.get(t);
if (r === void 0 || !n && this.#m(r)) return;
const o = this.#t[r];
return this.#e(o) ? o.__staleWhileFetching : o;
}
#B(t, e, n, r) {
const o = e === void 0 ? void 0 : this.#t[e];
if (this.#e(o)) return o;
const s = new Ai(), { 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, p = n.ignoreFetchAbort && g !== void 0;
if (n.status && (f && !m ? (n.status.fetchAborted = !0, n.status.fetchError = s.signal.reason, p && (n.status.fetchAbortIgnored = !0)) : n.status.fetchResolved = !0), f && !p && !m) return h(s.signal.reason);
const _ = d, S = this.#t[e];
return (S === d || p && m && S === void 0) && (g === void 0 ? _.__staleWhileFetching !== void 0 ? this.#t[e] = _.__staleWhileFetching : this.#x(t, "fetch") : (n.status && (n.status.fetchUpdated = !0), this.set(t, g, l.options))), g;
}, h = (g) => {
const { aborted: m } = s.signal, f = m && n.allowStaleOnFetchAbort, p = f || n.allowStaleOnFetchRejection, _ = p || n.noDeleteOnFetchRejection, S = d;
if (this.#t[e] === d && (!_ || S.__staleWhileFetching === void 0 ? this.#x(t, "fetch") : f || (this.#t[e] = S.__staleWhileFetching)), p) 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 d = new Promise((g, m) => {
const f = this.#F?.(t, o, l);
f && f instanceof Promise && f.then((p) => g(p === void 0 ? void 0 : p), m), s.signal.addEventListener("abort", () => {
n.ignoreFetchAbort && !n.allowStaleOnFetchAbort || (g(void 0), n.allowStaleOnFetchAbort && (g = (p) => c(p, !0)));
});
}).then(c, (g) => (n.status && (n.status.fetchRejected = !0, n.status.fetchError = g), h(g))), u = Object.assign(d, { __abortController: s, __staleWhileFetching: o, __returned: void 0 });
return e === void 0 ? (this.set(t, u, { ...l.options, status: void 0 }), e = this.#r.get(t)) : this.#t[e] = u, u;
}
#e(t) {
if (!this.#R) return !1;
const e = t;
return !!e && e instanceof Promise && e.hasOwnProperty("__staleWhileFetching") && e.__abortController instanceof Ai;
}
async fetch(t, e = {}) {
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: d = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection: u = this.allowStaleOnFetchRejection, ignoreFetchAbort: g = this.ignoreFetchAbort, allowStaleOnFetchAbort: m = this.allowStaleOnFetchAbort, context: f, forceRefresh: p = !1, status: _, signal: S } = e;
if (!this.#R) return _ && (_.fetch = "get"), this.get(t, { allowStale: n, updateAgeOnGet: r, noDeleteOnStaleGet: o, status: _ });
const C = { allowStale: n, updateAgeOnGet: r, noDeleteOnStaleGet: o, ttl: s, noDisposeOnSet: i, size: l, sizeCalculation: c, noUpdateTTL: h, noDeleteOnFetchRejection: d, allowStaleOnFetchRejection: u, allowStaleOnFetchAbort: m, ignoreFetchAbort: g, status: _, signal: S };
let y = this.#r.get(t);
if (y === void 0) {
_ && (_.fetch = "miss");
const E = this.#B(t, y, C, f);
return E.__returned = E;
}
{
const E = this.#t[y];
if (this.#e(E)) {
const I = n && E.__staleWhileFetching !== void 0;
return _ && (_.fetch = "inflight", I && (_.returnedStale = !0)), I ? E.__staleWhileFetching : E.__returned = E;
}
const w = this.#m(y);
if (!p && !w) return _ && (_.fetch = "hit"), this.#N(y), r && this.#M(y), _ && this.#I(_, y), E;
const b = this.#B(t, y, C, f), v = b.__staleWhileFetching !== void 0 && n;
return _ && (_.fetch = w ? "stale" : "refresh", v && w && (_.returnedStale = !0)), v ? b.__staleWhileFetching : b.__returned = b;
}
}
async forceFetch(t, e = {}) {
const n = await this.fetch(t, e);
if (n === void 0) throw new Error("fetch() returned undefined");
return n;
}
memo(t, e = {}) {
const n = this.#k;
if (!n) throw new Error("no memoMethod provided to constructor");
const { context: r, forceRefresh: o, ...s } = e, i = this.get(t, s);
if (!o && i !== void 0) return i;
const l = n(t, i, { options: s, context: r });
return this.set(t, l, s), l;
}
get(t, e = {}) {
const { allowStale: n = this.allowStale, updateAgeOnGet: r = this.updateAgeOnGet, noDeleteOnStaleGet: o = this.noDeleteOnStaleGet, status: s } = e, i = this.#r.get(t);
if (i !== void 0) {
const l = this.#t[i], c = this.#e(l);
return s && this.#I(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.#x(t, "expire"), s && n && (s.returnedStale = !0), n ? l : void 0)) : (s && (s.get = "hit"), c ? l.__staleWhileFetching : (this.#N(i), r && this.#M(i), l));
}
s && (s.get = "miss");
}
#V(t, e) {
this.#u[e] = t, this.#c[t] = e;
}
#N(t) {
t !== this.#s && (t === this.#a ? this.#a = this.#c[t] : this.#V(this.#u[t], this.#c[t]), this.#V(this.#s, t), this.#s = t);
}
delete(t) {
return this.#x(t, "delete");
}
#x(t, e) {
let n = !1;
if (this.#o !== 0) {
const r = this.#r.get(t);
if (r !== void 0) if (n = !0, this.#o === 1) this.#j(e);
else {
this.#T(r);
const o = this.#t[r];
if (this.#e(o) ? o.__abortController.abort(new Error("deleted")) : (this.#E || this.#h) && (this.#E && this.#f?.(o, t, e), this.#h && this.#i?.push([o, t, e])), this.#r.delete(t), this.#n[r] = void 0, this.#t[r] = void 0, r === this.#s) this.#s = this.#u[r];
else if (r === this.#a) this.#a = this.#c[r];
else {
const s = this.#u[r];
this.#c[s] = this.#c[r];
const i = this.#c[r];
this.#u[i] = this.#u[r];
}
this.#o--, this.#w.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(t) {
for (const e of this.#v({ allowStale: !0 })) {
const n = this.#t[e];
if (this.#e(n)) n.__abortController.abort(new Error("deleted"));
else {
const r = this.#n[e];
this.#E && this.#f?.(n, r, t), this.#h && this.#i?.push([n, r, t]);
}
}
if (this.#r.clear(), this.#t.fill(void 0), this.#n.fill(void 0), this.#g && this.#C && (this.#g.fill(0), this.#C.fill(0)), this.#y && this.#y.fill(0), this.#a = 0, this.#s = 0, this.#w.length = 0, this.#S = 0, this.#o = 0, this.#h && this.#i) {
const e = this.#i;
let n;
for (; n = e?.shift(); ) this.#p?.(...n);
}
}
}
var Ft, Ed;
(Ed = Ft || (Ft = {})).CalcStatus = { Ready: "ready", Stale: "stale", Pending: "pending", Streaming: "streaming" }, Ed.Content = { Values: "values", Formats: "formats", Formulas: "formula", Hyperlinks: "hyperlinks", Tables: "tables", Notes: "notes", Comments: "comments", Warnings: "warnings", Errors: "errors", Merges: "merges" };
class i_ {
constructor(t, e, n) {
if (!n) throw new Qe();
if (typeof n == "string" && (n = { address: n }), typeof n.address != "string") throw new Error("Invalid hyperlink");
this._t = t, this._r = e, this._p = n;
}
open(t, e) {
return this._r(this.getAddress(), null, t ?? this.getTarget(), e);
}
getTarget() {
let t = this._p.target;
return t || (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 bd(a) {
return !/^(-?\d|--)/.test(a);
}
function vd(a) {
const t = [];
let e = "", n = "", r = 7;
for (let o, s = 0; o = a.charAt(s); s++) if (/[a-zA-Z\d\xa0-\uffff_-]/.test(o) && r === 7) e += o;
else if (o === "\\" && r === 7) r = 6;
else if (o === " " && r === 7) {
if (e !== "") {
if (!bd(e)) return null;
t.push(e), e = "";
}
} else if (r === 6) /[0-9a-f]/i.test(o) ? (n += o, r = 8) : (e += o, r = 7);
else {
if (r !== 8) return null;
/[0-9a-f]/i.test(o) && n.length < 6 ? n += o : (e += String.fromCodePoint(parseInt(n, 16)), e += o, n = "", r = 7);
}
if (e !== "") {
if (!bd(e)) return null;
t.push(e);
}
return t.join(" ");
}
function xd(a, t) {
let e = t, n = "";
const r = { "font-family": [] };
for (let o, s = 0; o = a.charAt(s); s += 1) if (e !== 4 || o !== '"' && o !== "'") if (e === 3 && o === ",") e = 4, n = "";
else if (e === 4 && o === ",") {
const i = vd(n);
i && r["font-family"].push(i), n = "";
} else if (e === 5 && o === " ") /^(?:\+|-)?(?:[0-9]*\.)?[0-9]+(?:deg|grad|rad|turn)$/.test(n) ? (r["font-style"] += " " + n, n = "") : s -= 1, e = 1;
else if (e !== 1 || o !== " " && o !== "/") e === 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), e = 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)) e = 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, e = 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, e = 3, n = "";
}
if (e === 3 && !/^\s*$/.test(n)) return null;
if (e === 4) {
const o = vd(n);
o && r["font-family"].push(o);
}
return r;
}
const ui = (a) => {
if (typeof a != "string") return null;
let t = (function(o) {
const s = xd(o, 4);
return s !== null ? s["font-family"] : null;
})(a);
Array.isArray(t) && t.length === 0 && (t = null), t = t ? { "font-family": t } : (function(o) {
const s = xd(o, 1);
return s !== null && s["font-size"] && s["font-family"].length ? s : null;
})(a);
let e = null, n = null, r = null;
if (t) {
let o = t["font-family"];
const s = o.shift();
s && (e = s), o.length > 0 && (n = o), t["font-size"] !== void 0 && (r = t["font-size"]);
}
return { family: e, fallbacks: n, size: r };
}, cn = (a, t = !1) => a?.toHex(t)?.toString(!1).toLowerCase() ?? null, Id = (a) => a == null ? null : k.roundAccurately(a, 2) + "pt", gm = (a, t) => {
let e = "";
const n = a && a !== dt.UnderlineStyle.None;
return t && (e += "line-through"), n && t && (e += " "), n && (e += "underline", a !== !0 && a !== dt.UnderlineStyle.Single && a !== dt.UnderlineStyle.SingleAccounting || (e += " solid"), a !== dt.UnderlineStyle.Double && a !== dt.UnderlineStyle.DoubleAccounting || (e += " double")), e;
}, a_ = Object.freeze({ underline: dt.UnderlineStyle.None, strike: !1 }), mm = (a) => a ? (a = a.toLowerCase()) === "single" ? dt.UnderlineStyle.Single : a === "double" ? dt.UnderlineStyle.Double : a === "single-accounting" || a === "singleaccounting" ? dt.UnderlineStyle.SingleAccounting : a === "double-accounting" || a === "doubleaccounting" ? dt.UnderlineStyle.DoubleAccounting : dt.UnderlineStyle.None : dt.UnderlineStyle.None, Rd = (a) => a ? a.toLowerCase() : null, Ad = (a) => a ? a === et.Overflow.Visible || a === et.Overflow.Clip || a === et.Overflow.Shrink ? "nowrap" : a === et.Overflow.Wrap ? "normal" : void 0 : null, Mi = (a, t) => {
let e = "";
if (a && (a.includes(" ") && (a = '"' + a + '"'), e = a), t) for (let n = 0; n < t.length; n++) e.length > 0 && (e += ", "), e += t[n];
return e;
}, Md = (a) => {
let t = "", e = !1, n = "";
for (let r = 0; r < a.length; r++) {
const o = a.charAt(r);
e && o !== "]" && o !== '"' ? t += o : o === '"' ? (t += "\\0022", e = !e) : ["[", "]", ",", "#", ".", "@", "/", ":", ";", "-", " "].includes(o) ? (t += "\\" + o, o === "[" ? e = !0 : o === "]" && (e = !1)) : ["(", ")"].includes(o) ? t += n === "_" ? "\\" + o : "\\\\\\" + o : ["$"].includes(o) ? t += "\\0022" + o + "\\0022" : t += o, n = o;
}
return '"' + t + '"';
}, l_ = "Thin", c_ = "Hairline", h_ = "Extra Light", d_ = "Ultra Light", u_ = "Light", Td = "Normal", g_ = "Regular", m_ = "Medium", f_ = "Semi Bold", p_ = "Demi Bold", __ = "Bold", S_ = "Extra Bold", w_ = "Ultra Bold", y_ = "Black", C_ = "Heavy", E_ = "Extra Black", b_ = "Ultra Black", v_ = "lighter", x_ = "normal", I_ = "bold", R_ = "bolder", Xt = /* @__PURE__ */ new Map();
Xt.set(k.textToKey(l_), 100), Xt.set(k.textToKey(c_), 100), Xt.set(k.textToKey(h_), 200), Xt.set(k.textToKey(d_), 200), Xt.set(k.textToKey(u_), 300), Xt.set(k.textToKey(Td), 400), Xt.set(k.textToKey(g_), 400), Xt.set(k.textToKey(m_), 500), Xt.set(k.textToKey(f_), 600), Xt.set(k.textToKey(p_), 600), Xt.set(k.textToKey(Td), 400), Xt.set(k.textToKey(__), 700), Xt.set(k.textToKey(S_), 800), Xt.set(k.textToKey(w_), 800), Xt.set(k.textToKey(y_), 900), Xt.set(k.textToKey(C_), 900), Xt.set(k.textToKey(E_), 950), Xt.set(k.textToKey(b_), 950), Xt.set(k.textToKey(v_), 100), Xt.set(k.textToKey(x_), 400), Xt.set(k.textToKey(I_), 700), Xt.set(k.textToKey(R_), 700);
const A_ = "xx-small", M_ = "x-small", T_ = "small", N_ = "medium", F_ = "large", k_ = "x-large", O_ = "xx-large", D_ = "xxx-large", L_ = "smaller", B_ = "larger", z_ = "math", P_ = new RegExp("^[0-9]*[.]?[0-9]+$", "g"), Be = /* @__PURE__ */ new Map();
Be.set(k.textToKey(A_), (a) => 0.4 * a), Be.set(k.textToKey(M_), (a) => 0.5 * a), Be.set(k.textToKey(T_), (a) => 0.6 * a), Be.set(k.textToKey(N_), (a) => a), Be.set(k.textToKey(F_), (a) => 1.1 * a), Be.set(k.textToKey(k_), (a) => 1.25 * a), Be.set(k.textToKey(O_), (a) => 1.5 * a), Be.set(k.textToKey(D_), (a) => 2 * a), Be.set(k.textToKey(L_), (a) => 0.9 * a), Be.set(k.textToKey(B_), (a) => 1.1 * a), Be.set(k.textToKey(z_), (a) => a);
const Xr = (a, t = 11, e = "pt") => {
if (!a) return null;
let n = t;
a = a.trim().toLowerCase();
const r = e === "pt" ? dt.getDeviceScale() : 1, o = e === "pt" ? 1 : dt.getDeviceScale();
if (P_.test(a)) {
const s = parseFloat(a);
isNaN(s) || (a = s + e);
}
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()) * t;
else if (a.endsWith("rem")) n = parseFloat(a.substring(0, a.length - 3).trim()) * t;
else if (a.endsWith("%")) n = parseFloat(a.substring(0, a.length - 1).trim()) / 100 * t;
else if (typeof a == "string") {
const s = k.textToKey(a), i = Be.get(s);
if (i) return i(t);
}
return isNaN(n) ? null : n;
}, te = /* @__PURE__ */ new Map();
te.set(st.BuiltInSheetPattern.None, { description: "None", cssKey: "none" }), te.set(st.BuiltInSheetPattern.Solid, { description: "Solid", cssKey: "solid" }), te.set(st.BuiltInSheetPattern.DarkGray, { description: "75% gray", cssKey: "gray-75" }), te.set(st.BuiltInSheetPattern.MediumGray, { description: "50% gray", cssKey: "gray-50" }), te.set(st.BuiltInSheetPattern.LightGray, { description: "25% gray", cssKey: "gray-25" }), te.set(st.BuiltInSheetPattern.Gray125, { description: "12.5% Gray", cssKey: "gray-125" }), te.set(st.BuiltInSheetPattern.Gray0625, { description: "6.25% Gray", cssKey: "gray-0625" }), te.set(st.BuiltInSheetPattern.DarkHorizontal, { description: "Horizontal Strip", cssKey: "horz-stripe" }), te.set(st.BuiltInSheetPattern.DarkVertical, { description: "Vertical Strip", cssKey: "vert-stripe" }), te.set(st.BuiltInSheetPattern.DarkDown, { description: "Reverse Diagonal Stripe", cssKey: "reverse-diag-stripe" }), te.set(st.BuiltInSheetPattern.DarkUp, { description: "Diagonal Strip", cssKey: "diag-stripe" }), te.set(st.BuiltInSheetPattern.DarkGrid, { description: "Diagonal Crosshatch", cssKey: "diag-cross" }), te.set(st.BuiltInSheetPattern.DarkTrellis, { description: "Thick Diagonal Crosshatch", cssKey: "thick-diag-cross" }), te.set(st.BuiltInSheetPattern.LightHorizontal, { description: "Thin Horizontal Stripe", cssKey: "thin-horz-stripe" }), te.set(st.BuiltInSheetPattern.LightVertical, { description: "Thin Vertical Stripe", cssKey: "thin-vert-stripe" }), te.set(st.BuiltInSheetPattern.LightDown, { description: "Thin Reverse Diagonal Stripe", cssKey: "thin-reverse-diag-stripe" }), te.set(st.BuiltInSheetPattern.LightUp, { description: "Thin Diagonal Stripe", cssKey: "thin-diag-stripe" }), te.set(st.BuiltInSheetPattern.LightGrid, { description: "Thin Horizontal Cross", cssKey: "thin-horz-cross" }), te.set(st.BuiltInSheetPattern.LightTrellis, { description: "Thin Diagonal Cross", cssKey: "thin-diag-cross" });
let gi = "";
const fm = /* @__PURE__ */ new Map();
te.forEach((a, t) => {
gi.length > 0 && (gi += "|"), gi += "\\b" + a.cssKey + "\\b", fm.set(a.cssKey, t);
});
const W_ = new RegExp(`(\\s*(?:${gi}))`, "g"), H_ = (a) => {
if (!a) return null;
let t = a.toLowerCase();
t = t.replace(/;/, "");
let e = t.match(W_);
if (!e) return null;
let n = null;
e && e.length > 0 && (n = ((o) => {
if (!o) return null;
let s = t.indexOf(o);
return t = t.substring(0, s) + t.substring(s + o.length, t.length), o.trim();
})(e[0])), t = t.trim();
const r = t ? t.trim() : null;
return !n && !r ? null : { patternType: fm.get(n ?? "solid"), foreground: r ?? null };
}, pm = (a, t = !1, e = null) => {
if (!a || !a.getStops() || a.getStops().length < 1) return null;
if (a.getStops().length === 1) return cn(a.getStops()[0].getColor(), t);
let n = "";
for (let o = 0; o < a.getStops().length; o++) {
const s = a.getStops()[o];
n += cn(s.getColor(), t) + " " + 100 * (s.getOffset() ?? o * (a.getStops().length - 1)) + "%", o < a.getStops().length - 1 && (n += ", ");
}
let r = a.getAngle() ?? 0;
if (a.getGradientType() === st.GradientType.Path) {
const o = cn(a.getStops()[0]?.getColor(), t), s = cn((a.getStops()[1] ?? a.getStops()[0])?.getColor(), t), 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})`;
}, we = /* @__PURE__ */ new Map();
we.set(U.StrokeStyle.None, { size: null, cssKey: "none" }), we.set(U.StrokeStyle.DashDot, { size: 0.5, cssKey: "dot-dash" }), we.set(U.StrokeStyle.DashDotDot, { size: 0.5, cssKey: "dot-dot-dash" }), we.set(U.StrokeStyle.Dashed, { size: 0.5, cssKey: "dashed" }), we.set(U.StrokeStyle.MediumDashed, { size: 1, cssKey: "dashed" }), we.set(U.StrokeStyle.Dotted, { size: 0.5, cssKey: "dotted" }), we.set(U.StrokeStyle.MediumDashDot, { size: 1, cssKey: "dot-dash" }), we.set(U.StrokeStyle.MediumDashDotDot, { size: 1, cssKey: "dot-dot-dash" }), we.set(U.StrokeStyle.Hair, { size: 0.5, cssKey: "hairline" }), we.set(U.StrokeStyle.Thin, { size: 0.5, cssKey: "solid" }), we.set(U.StrokeStyle.Thick, { size: 1.5, cssKey: "solid" }), we.set(U.StrokeStyle.Medium, { size: 1, cssKey: "solid" }), we.set(U.StrokeStyle.Double, { size: 2, cssKey: "double" }), we.set(U.StrokeStyle.SlantDashDot, { size: 1, cssKey: "dot-dash-slanted" });
const hr = (a) => {
if (!a) return "none";
const t = we.get(a.getStyle());
if (!t) return null;
if (t.cssKey === "none") return t.cssKey;
let e = ((n, r = !1) => n?.toRGBA(r).toString(!1) ?? null)(a?.getColor());
return e = e ? " " + e : "", `${t.size !== null ? `${t.size}pt ` : ""}${t.cssKey}${e}`;
};
let Ji = [];
const Nd = /* @__PURE__ */ new Set(), Bl = /* @__PURE__ */ new Map(), Ko = (a, t) => {
let e = a.size !== null ? `${a.size.toString()} ${a.cssKey}` : a.cssKey;
Bl.set(e, t), Nd.has(a.cssKey) || (Ji.push(a.cssKey), Nd.add(a.cssKey));
};
we.forEach(Ko);
const za = Object.keys(U.StrokeStyle);
for (let a = 0; a < za.length; a++)
Ko({ size: null, cssKey: za[a].toLowerCase() }, U.StrokeStyle[za[a]]);
Ko({ size: null, cssKey: "double" }, U.StrokeStyle.Double), Ko({ size: null, cssKey: "solid" }, U.StrokeStyle.Medium), Ko({ size: null, cssKey: "hidden" }, U.StrokeStyle.None), Ji.sort((a, t) => t.length - a.length);
let mi = "";
const V_ = Ji.length;
for (let a = 0; a < V_; a++) mi.length > 0 && (mi += "|"), mi += "\\b" + Ji[a] + "\\b";
const j_ = new RegExp(`(\\s*(?:${mi}))`, "g"), $_ = new RegExp("(\\s*[0-9]*[.]?[0-9]+(?:pt|px){0,1})", "g"), _m = (a, t) => {
if (!a) return null;
let e = a.toLowerCase(), n = e.match(j_);
if (!n) {
const h = t?.(e);
return h ? { color: h, style: U.StrokeStyle.Medium } : null;
}
const r = (h) => {
if (!h) return null;
let d = e.indexOf(h);
return e = e.substring(0, d) + e.substring(d + h.length, e.length).trim(), h.trim();
};
let o = null;
if (n && n.length > 0 && (o = r(n[0])), !o) return null;
let s = null;
if (n = e.match($_), n && n.length > 0) {
let h = r(n[0]);
s = parseFloat(h.substring(0, h.length - 2));
}
e = e.trim();
const i = e ? e.trim() : null;
let l = s === null ? o : `${s.toString()} ${o}`, c = Bl.get(l);
return c || (c = Bl.get(o)), c ? { color: i, style: c } : null;
}, G_ = "start", U_ = "end", q_ = "left", J_ = "right", K_ = "center", X_ = "justify", Y_ = "justify-all", Q_ = "baseline", Z_ = "top", tS = "middle", eS = "bottom", nS = "sub", rS = "text-top", oS = "justify", sS = "distributed", Gn = /* @__PURE__ */ new Map();
Gn.set(k.textToKey(G_), et.HorizontalAlignment.Left), Gn.set(k.textToKey(q_), et.HorizontalAlignment.Left), Gn.set(k.textToKey(U_), et.HorizontalAlignment.Right), Gn.set(k.textToKey(J_), et.HorizontalAlignment.Right), Gn.set(k.textToKey(K_), et.HorizontalAlignment.Center), Gn.set(k.textToKey(X_), et.HorizontalAlignment.Justify), Gn.set(k.textToKey(Y_), et.HorizontalAlignment.Justify);
const En = /* @__PURE__ */ new Map();
En.set(k.textToKey(Q_), et.VerticalAlignment.Bottom), En.set(k.textToKey(Z_), et.VerticalAlignment.Top), En.set(k.textToKey(tS), et.VerticalAlignment.Center), En.set(k.textToKey(eS), et.VerticalAlignment.Bottom), En.set(k.textToKey(nS), et.VerticalAlignment.Bottom), En.set(k.textToKey(rS), et.VerticalAlignment.Top), En.set(k.textToKey(oS), et.VerticalAlignment.Justify), En.set(k.textToKey(sS), et.VerticalAlignment.Distributed);
const zl = (a) => {
if (a instanceof ae) return { color: a.toString() };
if (typeof a == "string") try {
return { color: a === "none" || a === "transparent" ? null : a };
} catch (t) {
throw t;
}
return a;
}, ts = { shorthand: (a, t) => {
if (!a || a === "none" || a === "transparent") return null;
try {
return t.parseColor(a).toString();
} catch (e) {
console.warn("error", e);
}
return a;
}, merge: (a, t, e) => a }, Wn = { shorthand: (a, t) => {
if (a.isIStroke) return a.getProperties();
if (typeof a == "string" && (a = _m(a, (n) => {
try {
return t.parseColor(n).toString();
} catch {
}
return null;
})), !a) return null;
const e = {};
return a.style && (e.style = a.style), a.color && (e.color = a.color), e;
}, properties: { color: ts } }, iS = { shorthand: (a, t) => {
if (a.isIBorder) return a.getProperties();
if (typeof a == "string") {
const e = _m(a, (n) => {
try {
return t.parseColor(n).toString();
} catch {
}
return null;
});
return { left: e, right: e, top: e, bottom: e, horizontal: null, vertical: null, diagonalUp: null, diagonalDown: null };
}
return a;
}, properties: { top: Wn, left: Wn, right: Wn, bottom: Wn, horizontal: Wn, vertical: Wn, diagonalUp: Wn, diagonalDown: Wn } }, aS = { shorthand: (a, t) => {
if (typeof a == "string") {
let e = Ne.Styles.lookupDefault(a);
return e !== void 0 ? e : a;
}
return typeof a == "number" ? nc(a) : null;
} }, lS = { shorthand: (a, t) => {
if (a.isIStyledFont) return a.toJSON();
if (typeof a == "string") {
const e = ui(a);
if (e) {
const n = {};
if (e.family && (n.family = e.family), e.fallbacks && (n.fallbacks = e.fallbacks), e.size && (n.size = Xr(e.size)), Object.keys(e).length > 0) return n;
}
}
return a;
}, properties: { family: { shorthand: (a, t) => ui(a)?.family ?? null }, fallbacks: { shorthand: (a, t) => {
if (typeof a != "string") return a;
let e = ui(a);
if (!e) return null;
let n = [e.family];
return e.fallbacks && (n = n.concat(e.fallbacks)), n;
} }, size: { shorthand: (a, t) => {
let e = a;
return typeof a == "string" && (e = Xr(a, t.getNormal().getFont().getSize())), isNaN(e) || typeof e != "number" ? null : (e = Math.max(1, Math.min(k.roundAccurately(e, 1), 409)), e);
} }, weight: { shorthand: (a, t) => {
if (typeof a != "string") return a;
const e = ((n) => {
let r = 400;
if (r = typeof n == "number" ? n : parseFloat(n), !isNaN(r)) return r;
if (typeof n == "string") {
const o = k.textToKey(n), s = Xt.get(o);
if (s) return s;
}
return r;
})(a);
return isNaN(e) || typeof e != "number" ? null : e;
} }, underline: { shorthand: (a, t) => a ? a === !0 ? dt.UnderlineStyle.Single : mm(a) : dt.UnderlineStyle.None } } }, cS = { properties: { indent: { shorthand: (a, t) => {
let e = a;
return typeof a == "string" && (e = parseFloat(a)), isNaN(e) || typeof e != "number" ? null : e;
} }, rotation: { shorthand: (a, t) => {
let e = a;
return typeof a == "string" && (e = parseFloat(a)), isNaN(e) || typeof e != "number" ? null : (e %= 360, e < 0 && (e += 360), e);
} } } }, Sm = { shorthand: (a, t) => a === "none" || a === "transparent" || typeof a == "object" && Object.keys(a).length === 0 ? { type: st.Type.None } : (a.getType?.(), st.Type.None, a) }, wm = { shorthand: (a) => (typeof (a = zl(a)) == "object" && a.color && (a.type = st.Type.Solid), a), merge: (a, t) => a.color ? a : (t?.toJSON && (t = t.toJSON()), t?.type === st.Type.Solid ? { ...t } : t?.type === st.Type.Gradient ? { type: st.Type.Solid, color: t?.stops?.[0]?.color ?? N.Scheme.Bg1 } : t?.type === st.Type.Pattern ? { type: st.Type.Solid, color: t?.foreground ?? N.Scheme.Bg1 } : a ? { ...a } : null), properties: { color: ts } }, hS = { shorthand: (a) => (typeof a == "string" && (a = a.split(",").map((t) => t.trim())), Array.isArray(a) && (a = a.map((t, e) => {
if (!t) return;
let n = t;
return typeof t == "string" && (n = zl(t)), t.isIColor && (n = { color: t.toString() }), n;
})), a), arrayType: { shorthand: (a) => a = zl(a), properties: { color: ts } } }, ym = { shorthand: (a) => (typeof a == "object" && a.stops && (a.type = st.Type.Gradient), a), merge: (a, t, e) => a.stops ? a : (t?.toJSON && (t = t.toJSON()), t?.type === st.Type.Gradient ? { ...t } : t?.type === st.Type.Solid ? { type: st.Type.Gradient, stops: [{ offset: 0, color: t?.color ?? N.Scheme.Accent1 }, { offset: 1, color: N.Scheme.Bg1 }] } : t?.type === st.Type.Pattern ? { type: st.Type.Gradient, stops: [{ offset: 0, color: t?.foreground ?? N.Scheme.Bg1 }, { offset: 1, color: t?.background ?? N.Scheme.Accent1 }] } : a ? { ...a } : null), properties: { stops: hS } }, Cm = { shorthand: (a, t) => {
if (typeof a == "object") {
const e = a;
(e.foreground || e.background || e.patternType) && (e.type = st.Type.Pattern, e.patternType = e.patternType ?? st.BuiltInSheetPattern.Solid);
}
return a;
}, merge: (a, t, e) => {
if (a.background && a.foreground) return a;
t?.toJSON && (t = t.toJSON());
const n = st.BuiltInSheetPattern.MediumGray;
if (t?.type === st.Type.Pattern) {
const r = { type: st.Type.Pattern, patternType: a.patternType ?? t.patternType };
return a.foreground || a.background ? (a.foreground && (r.foreground = a.foreground), a.background && (r.background = a.background)) : (t.foreground && (r.foreground = t.foreground), t.background && (r.background = t.background)), r;
}
return t?.type === st.Type.Solid ? { patternType: n, foreground: t?.color ?? N.Named.WindowText, background: N.Scheme.Bg1, ...a } : t?.type === st.Type.Gradient ? { patternType: n, foreground: t?.stops?.[0]?.color ?? N.Named.WindowText, background: t?.stops?.[1]?.color ?? N.Scheme.Bg1, ...a } : a ? { type: st.Type.Pattern, patternType: st.BuiltInSheetPattern.Solid, foreground: N.Named.WindowText, background: N.Scheme.Bg1, ...a } : null;
}, properties: { foreground: ts, background: ts } }, Fd = [Sm, wm, ym, Cm], lc = [];
for (let a = 0; a < Fd.length; a++) {
const t = Fd[a]?.shorthand;
lc.push(t);
}
const dS = lc.length, Qt = { properties: { font: lS, fill: { shorthand: (a, t) => {
a.isIFill && (a = a.toJSON());
for (let e = 0; e < dS; e++) {
let n = lc[e](a, t);
if (n?.type) return n;
}
return a;
}, getSubType: (a) => a.type === st.Type.None ? Sm : a.type === st.Type.Solid ? wm : a.type === st.Type.Gradient ? ym : a.type === st.Type.Pattern ? Cm : null }, alignment: cS, border: iS, numberFormat: aS } }, uS = { properties: { style: Qt } }, gS = Object.freeze({ displayText: "", conditionalColor: null, repeatChars: k.EmptyArray, spacingChars: k.EmptyArray, repeatPlaceholder: null, formattedRuns: Object.freeze({ runs: k.EmptyArray, length: 0, width: 0, lastRepeatIndex: -1 }), canWrap: !1, asDate: null, isDateFormat: !1, isTimeFormat: !1, isDate1904: !1 }), Em = (a, t, e, n, r, o = !1) => {
if (a == null) return gS;
let s = "", i = null, l = null, c = null;
if (e === Y.Error) s = a.getLabel();
else if (e === Y.RichData) s = "(Rich Object)";
else if (e === Y.Boolean) s = a ? "TRUE" : "FALSE";
else if (n) try {
s = Yl(n, a, { date1904: o, spacingCharacter: "", digitCharacter: "", onRepeatChar: (b, v) => {
l || (l = []), l.push({ offset: b, char: v });
}, onSpacingChar: (b, v) => {
c || (c = []), c.push({ offset: b, char: v });
}, onDigitChar: (b) => {
c || (c = []), c.push({ offset: b, char: "0" });
} });
} catch {
}
const h = os(n), d = Wi(n), u = h || d ? oo(a, o) : null;
(h || d) && parseFloat(a) < 0 && (i = "#", s = i.repeat(5));
let g = null;
const m = t.getAlignment(), f = m.getHorizontal(), p = m.getVertical(), _ = m.getOverflow(), S = !(e !== Y.String || f === et.HorizontalAlignment.Fill || l !== null && l.length !== 0 || _ !== et.Overflow.Wrap && f !== et.HorizontalAlignment.Justify && f !== et.HorizontalAlignment.Distributed && p !== et.VerticalAlignment.Justify && p !== et.VerticalAlignment.Distributed);
let C = s;
S || e !== Y.String || (C = C.replaceAll(/\n/g, ""));
const y = c?.length > 0 || l?.length > 0;
if (_ !== et.Overflow.Wrap || y) {
const b = t.getFont();
let v = b.getSize();
b.isSuperSub() && (v *= b.getSuperSubScale());
let I = [];
for (let W = 0; W < c?.length; W++) {
const D = c[W], z = t.measureText(D.char, v).width;
I.push({ ...D, type: "spacing", width: z });
}
if (l?.length > 0) {
const W = l[l.length - 1], D = t.measureText(W.char, v).width;
I.push({ ...W, type: "repeat", width: D });
}
I = I.sort((W, D) => W.offset - D.offset);
let x = [], R = 0, A = 0, M = -1, T = -1;
const O = (W) => {
const D = { type: "text", width: t.measureText(W, v).width, text: W };
x.push(D), A += D.width, R += W.length;
};
for (let W = 0; W < I.length; W++) {
const D = I[W];
if (T !== D.offset) {
const B = C.substring(R, D.offset);
B && O(B);
}
const z = { type: D.type, width: D.width, text: D.char };
D.type !== "repeat" ? A += z.width : M = x.length, x.push(z), T = D.offset;
}
if (R < C.length) {
let W = C.substring(R, C.length);
W && O(W);
}
g = { runs: Object.freeze(x), length: R, width: A, lastRepeatIndex: M };
}
const E = pp(n, a), w = { displayText: s ?? "", conditionalColor: E ? r(E) : null, repeatChars: l ?? k.EmptyArray, spacingChars: c ?? k.EmptyArray, repeatPlaceholder: i, formattedRuns: g, canWrap: S, asDate: u, isDateFormat: h, isTimeFormat: d, isDate1904: o };
return Object.freeze(w);
}, mS = Object.freeze({ fallbacks: k.EmptyArray, weight: 400, style: dt.Style.Normal, fill: N.Scheme.Tx1, letterSpacing: null, underline: dt.UnderlineStyle.None, strike: !1, scheme: dt.Scheme.Minor, verticalAlign: dt.VerticalAlignment.Baseline, shadow: !1, outline: !1, extend: !1 }), Hn = Object.freeze({ style: U.StrokeStyle.None }), fS = Object.freeze({ [U.Edge.Top]: Hn, [U.Edge.Left]: Hn, [U.Edge.Bottom]: Hn, [U.Edge.Right]: Hn, [U.Edge.Horizontal]: Hn, [U.Edge.Vertical]: Hn, [U.Edge.DiagonalUp]: Hn, [U.Edge.DiagonalDown]: Hn }), pS = Object.freeze({ horizontal: et.HorizontalAlignment.General, vertical: et.VerticalAlignment.Bottom, indent: 0, relativeIndent: 0, overflow: et.Overflow.Visible, rotation: 0, stacked: !1, quotePrefix: !1, justifyLastLine: !1, readingOrder: et.ReadingDirection.Auto, readingDirection: et.ReadingDirection.Auto }), _S = Object.freeze({ locked: !1, formulaHidden: !1 }), bm = Object.freeze({ fill: Object.freeze({ type: st.Type.None }), numberFormat: "General", alignment: pS, font: mS, border: fS, protection: _S, quotePrefix: !1, namedStyle: null }), SS = (() => {
const a = [{ named: mt.BuiltInName.Normal }, { named: mt.BuiltInName.RowLevel }, { named: mt.BuiltInName.ColLevel }, { named: mt.BuiltInName.Comma, numberFormat: '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)' }, { named: mt.BuiltInName.Currency, numberFormat: '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)' }, { named: mt.BuiltInName.Percent, numberFormat: "0%" }, { named: mt.BuiltInName.Comma0, numberFormat: '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)' }, { named: mt.BuiltInName.Currency0, numberFormat: '_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)' }, { named: mt.BuiltInName.Hyperlink, font: { fill: N.Scheme.Hlink, underline: dt.UnderlineStyle.Single } }, { named: mt.BuiltInName.FollowedHyperlink, font: { fill: N.Scheme.FolHlink, underline: dt.UnderlineStyle.Single } }, { named: mt.BuiltInName.Note, fill: "FFFFFFCC", font: { style: dt.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: mt.BuiltInName.WarningText, font: { fill: "FFFF0000" } }, { named: mt.BuiltInName.Unknown12 }, { named: mt.BuiltInName.Unknown13 }, { named: mt.BuiltInName.Unknown14 }, { named: mt.BuiltInName.Title, font: { size: 18, fill: N.Scheme.Tx2 } }, { named: mt.BuiltInName.Heading1, font: { size: 15, weight: "bold", fill: N.Scheme.Tx2 }, border: { bottom: { style: U.StrokeStyle.Thick, color: N.Scheme.Accent1 } } }, { named: mt.BuiltInName.Heading2, font: { size: 13, weight: "bold", fill: N.Scheme.Tx2 }, border: { bottom: { style: U.StrokeStyle.Thick, color: "accent1 lumMod 40, lumOff 60" } } }, { named: mt.BuiltInName.Heading3, font: { weight: "bold", fill: N.Scheme.Tx2 }, border: { bottom: { style: U.StrokeStyle.Medium, color: "accent1 lumMod 40, lumOff 60" } } }, { named: mt.BuiltInName.Heading4, font: { weight: "bold", fill: N.Scheme.Tx2 } }, { named: mt.BuiltInName.Input, fill: "FFFFCC99", font: { 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: mt.BuiltInName.Output, fill: "FFF2F2F2", font: { 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: mt.BuiltInName.Calculation, fill: "FFF2F2F2", font: { 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: mt.BuiltInName.CheckCell, fill: "FFA5A5A5", font: { 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: mt.BuiltInName.LinkedCell, font: { fill: "FFFA7D00" }, border: { bottom: { style: U.StrokeStyle.Double, color: "FFFF8001" } } }, { named: mt.BuiltInName.Total, font: { 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: mt.BuiltInName.Good, fill: "FFC6EFCE", font: { fill: "FF006100" } }, { named: mt.BuiltInName.Bad, fill: "FFFFC7CE", font: { fill: "FF9C0006" } }, { named: mt.BuiltInName.Neutral, fill: "FFFFEB9C", font: { fill: "FF9C5700" } }, { named: mt.BuiltInName.Accent1 }, { named: mt.BuiltInName.Accent1_20 }, { named: mt.BuiltInName.Accent1_40 }, { named: mt.BuiltInName.Accent1_60 }, { named: mt.BuiltInName.Accent2 }, { named: mt.BuiltInName.Accent2_20 }, { named: mt.BuiltInName.Accent2_40 }, { named: mt.BuiltInName.Accent2_60 }, { named: mt.BuiltInName.Accent3 }, { named: mt.BuiltInName.Accent3_20 }, { named: mt.BuiltInName.Accent3_40 }, { named: mt.BuiltInName.Accent3_60 }, { named: mt.BuiltInName.Accent4 }, { named: mt.BuiltInName.Accent4_20 }, { named: mt.BuiltInName.Accent4_40 }, { named: mt.BuiltInName.Accent4_60 }, { named: mt.BuiltInName.Accent5 }, { named: mt.BuiltInName.Accent5_20 }, { named: mt.BuiltInName.Accent5_40 }, { named: mt.BuiltInName.Accent5_60 }, { named: mt.BuiltInName.Accent6 }, { named: mt.BuiltInName.Accent6_20 }, { named: mt.BuiltInName.Accent6_40 }, { named: mt.BuiltInName.Accent6_60 }, { named: mt.BuiltInName.ExplanatoryText, font: { style: dt.Style.Italic, fill: "FF7F7F7F" } }];
for (let t = 29; t <= 52; t++) {
const e = (t - 29) % 4, n = Math.floor((t - 29) / 4);
let r = "";
e === 1 ? r = " lumMod 20, lumOff 80" : e === 2 ? r = " lumMod 40, lumOff 60" : e === 3 && (r = " lumMod 60, lumOff 40"), a[t].fill = `accent${n + 1}${r}`, a[t].font = { fill: e === 0 ? N.Scheme.Bg1 : N.Scheme.Tx1 };
}
return k.deepFreeze(a);
})(), wS = new class {
_svgImage(a, t, e, 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='${e}' stroke='${a}' %3E%3C/path%3E%3C/svg%3E")`, backgroundRepeat: "repeat", backgroundSize: `${n}px ${n}px`, backgroundPositionX: "0px", backgroundPositionY: "0px", backgroundPosition: "" + -n, backgroundColor: t };
}
toCSS(a, t, e) {
return a && a !== st.BuiltInSheetPattern.None ? a === st.BuiltInSheetPattern.Solid ? { background: e } : a === st.BuiltInSheetPattern.Gray0625 ? this._svgImage(t, e, "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 === st.BuiltInSheetPattern.LightGray ? this._svgImage(t, e, "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 === st.BuiltInSheetPattern.MediumGray ? this._svgImage(t, e, "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 === st.BuiltInSheetPattern.DarkGray ? this._svgImage(t, e, "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 === st.BuiltInSheetPattern.LightHorizontal ? this._svgImage(t, e, "M 0 2 L 4 2", 4) : a === st.BuiltInSheetPattern.DarkHorizontal ? this._svgImage(t, e, "M 0 2 L 4 2 M 0 3 L 4 3", 4) : a === st.BuiltInSheetPattern.LightVertical ? this._svgImage(t, e, "M 2 0 L 2 4", 4) : a === st.BuiltInSheetPattern.DarkVertical ? this._svgImage(t, e, "M 2 0 L 2 4 M 3 0 L 3 4", 4) : a === st.BuiltInSheetPattern.LightUp ? this._svgImage(t, e, "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 === st.BuiltInSheetPattern.DarkUp ? this._svgImage(t, e, "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 === st.BuiltInSheetPattern.LightDown ? this._svgImage(t, e, "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 === st.BuiltInSheetPattern.DarkDown ? this._svgImage(t, e, "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 === st.BuiltInSheetPattern.LightGrid ? this._svgImage(t, e, "M 1.5 -0.5 L 1.5 4.5 M -0.5 1.5 L 4.5 1.5", 4) : a === st.BuiltInSheetPattern.DarkGrid ? this._svgImage(t, e, "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 === st.BuiltInSheetPattern.LightTrellis ? this._svgImage(t, e, "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 === st.BuiltInSheetPattern.DarkTrellis ? this._svgImage(t, e, "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) : (st.BuiltInSheetPattern.Custom, this._svgImage(t, e, "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" };
}
}(), Ki = (a, t, e) => {
if (t === void 0) return;
if (t === null) return null;
if (t.isIStyle) return t._p.getProperties();
let n = null;
return typeof t == "function" ? n = t(typeof e == "function" ? e() : e) : n = t, n;
};
class yS {
constructor(t) {
this._p = Object.freeze(Array.isArray(t) ? t : [t ?? null]);
}
value(t) {
const e = this._p;
for (let n = e.length - 1; n >= 0; n--) {
const r = e[n];
if (!r) continue;
const o = r[t];
if (o !== void 0) return o;
}
}
values(t) {
const e = this._p, n = e.length;
let r;
for (let o = 0; o < n; o++) {
const s = e[o];
if (!s) continue;
const i = s[t];
i !== void 0 && (r === void 0 && (r = []), r.push(i));
}
return r;
}
getProperties() {
const t = this._p;
return t ? t[t.length - 1] : null;
}
toJSON() {
const t = this._p, e = t.length;
let n = {};
for (let r = 0; r < e; r++) {
const o = t[r];
n = k.deepMerge(n, o);
}
return n;
}
}
class On {
constructor(t, e) {
this._o = t, this._c = t.styles, this._p = Object.freeze(e);
}
_setValue(t, e) {
const n = { [t]: e };
this._o.updater(n);
}
_value(t) {
const e = this._p;
for (let n = e.length - 1; n >= 0; n--) {
const r = e[n];
if (!r) continue;
const o = r[t];
if (o !== void 0) return o;
}
}
_values(t) {
const e = this._p, n = e.length;
let r;
for (let o = 0; o < n; o++) {
const s = e[o];
if (!s) continue;
const i = s[t];
i !== void 0 && (r === void 0 && (r = []), r.push(i));
}
return r;
}
getProperties() {
const t = this._p;
return t ? t[t.length - 1] : null;
}
toJSON() {
return null;
}
}
class kr extends On {
constructor(t, e, n) {
super(e, n), this._edge = t;
}
getStyle() {
return this._value("style");
}
setStyle(t, e) {
const n = this._edge, r = n.charAt(0).toUpperCase() + n.slice(1);
return this._o.updater({ border: { [n]: { style: t } } }, { description: `Set ${r} Border Style`, ...e }).getBorder()["get" + r]();
}
getColor() {
const t = this._value("color");
return t ? this._c.parseColor(t) : null;
}
setColor(t, e) {
const n = this._edge, r = n.charAt(0).toUpperCase() + n.slice(1);
return this._o.updater({ border: { [n]: { color: t } } }, { description: `Set ${r} Border Color`, ...e }).getBorder()["get" + r]();
}
isNone() {
return this.getStyle() === U.StrokeStyle.None;
}
toCSS() {
const t = hr(this);
switch (this._edge) {
case U.Edge.Left:
return { borderLeft: t };
case U.Edge.Right:
return { borderRight: t };
case U.Edge.Top:
return { borderTop: t };
case U.Edge.Bottom:
return { borderBottom: t };
case U.Edge.DiagonalUp:
case U.Edge.DiagonalDown:
return { borderDiagonalUp: t };
}
}
get [Symbol.toStringTag]() {
return "[CellBorderStroke]";
}
toString() {
return "[CellBorderStroke]";
}
get isIStroke() {
return !0;
}
}
class CS extends On {
getLeft() {
return new kr(U.Edge.Left, this._o, this._values(U.Edge.Left));
}
setLeft(t, e) {
return this._o.updater({ border: { left: t } }, { description: "Set Left Border", ...e }).getBorder();
}
getRight() {
return new kr(U.Edge.Right, this._o, this._values(U.Edge.Right));
}
setRight(t, e) {
return this._o.updater({ border: { right: t } }, { description: "Set Right Border", ...e }).getBorder();
}
getTop() {
return new kr(U.Edge.Top, this._o, this._values(U.Edge.Top));
}
setTop(t, e) {
return this._o.updater({ border: { top: t } }, { description: "Set Top Border", ...e }).getBorder();
}
getBottom() {
return new kr(U.Edge.Bottom, this._o, this._values(U.Edge.Bottom));
}
setBottom(t, e) {
return this._o.updater({ border: { bottom: t } }, { description: "Set Bottom Border", ...e }).getBorder();
}
getDiagonalUp() {
return new kr(U.Edge.DiagonalUp, this._o, this._values(U.Edge.DiagonalUp));
}
setDiagonalUp(t, e) {
return this._o.updater({ border: { diagonalUp: t } }, { description: "Set Diagonal Up Border", ...e }).getBorder();
}
getDiagonalDown() {
return new kr(U.Edge.DiagonalDown, this._o, this._values(U.Edge.DiagonalDown));
}
setDiagonalDown(t, e) {
return this._o.updater({ border: { diagonalDown: t } }, { description: "Set Diagonal Down Border", ...e }).getBorder();
}
isEmpty() {
return !1;
}
get [Symbol.toStringTag]() {
return "[CellBorder]";
}
toString() {
return "[CellBorder]";
}
get isIBorder() {
return !0;
}
}
class ES extends On {
getHorizontal() {
return this._value("horizontal");
}
setHorizontal(t, e) {
return this._o.updater({ alignment: { horizontal: t } }, { description: "Set Horizontal Alignment", ...e }).getAlignment();
}
getVertical() {
return this._value("vertical");
}
setVertical(t, e) {
return this._o.updater({ alignment: { vertical: t } }, { description: "Set Vertical Alignment", ...e }).getAlignment();
}
getIndent() {
return this._value("indent");
}
setIndent(t, e) {
return this._o.updater({ alignment: { indent: t } }, { description: "Set Indent", ...e }).getAlignment();
}
getRelativeIndent() {
return this._value("relativeIndent");
}
setRelativeIndent(t, e) {
return this._o.updater({ alignment: { relativeIndent: t } }, { description: "Set Relative Indent", ...e }).getAlignment();
}
getOverflow() {
return this._value("overflow");
}
setOverflow(t, e) {
return this._o.updater({ alignment: { overflow: t } }, { description: "Set Overflow", ...e }).getAlignment();
}
getRotation() {
return this._value("rotation");
}
setRotation(t, e) {
return this._o.updater({ alignment: { rotation: t } }, { description: "Set Rotation", ...e }).getAlignment();
}
getStacked() {
return this._value("stacked");
}
setStacked(t, e) {
return this._o.updater({ alignment: { stacked: t } }, { description: "Set Stacked", ...e }).getAlignment();
}
getJustifyLastLine() {
return this._value("justifyLastLine");
}
setJustifyLastLine(t, e) {
return this._o.updater({ alignment: { justifyLastLine: t } }, { description: "Set Justify Last Line", ...e }).getAlignment();
}
getReadingDirection() {
return this._value("readingDirection");
}
setReadingDirection(t, e) {
return this._o.updater({ alignment: { readingDirection: t } }, { description: "Set Reading Direction", ...e }).getAlignment();
}
get [Symbol.toStringTag]() {
return "[CellAlignment]";
}
toString() {
return "[CellAlignment]";
}
get isITextBoxAlignment() {
return !0;
}
}
class bS extends On {
isEqualMeasure(t) {
return !!t && this.getFamily() === t.getFamily() && !!k.isEqualArrays(this.getFallbacks(), t.getFallbacks()) && this.getSize() === t.getSize() && this.getWeight() === t.getWeight() && this.getStyle() === t.getStyle() && this.getStrike() === t.getStrike() && this.getScheme() === t.getScheme() && this.getShadow() === t.getShadow() && this.getOutline() === t.getOutline() && this.getLetterSpacing() === t.getLetterSpacing() && this.getVerticalAlignment() === t.getVerticalAlignment();
}
toCSS(t, e = 1, n = !1) {
const r = { fontFamily: Mi(this.getFamily(), this.getFallbacks()), letterSpacing: `${this.getLetterSpacing()}px`, fontWeight: this.getWeight(), fontStyle: this.getStyle(), textDecoration: gm(this.getUnderline(), this.getStrike()), color: this.getFill().toCSS(t), fontSize: `${k.roundAccurately(this.getSize() * dt.getDeviceScale() * e, 2)}px`, textRendering: "geometricPrecision" };
if (n) {
const o = this._c.getNormal().getFont().toCSS(t, e, !1), s = r.textDecoration, i = r.fontWeight;
k.removeEqualValues(r, o), s && (r.textDecoration = s), i && (r.fontWeight = i);
}
return r;
}
isSuperSub() {
const t = this.getVerticalAlignment();
return t === dt.VerticalAlignment.Sub || t === dt.VerticalAlignment.Super;
}
isSuperScript() {
const t = this.getVerticalAlignment();
return t === dt.VerticalAlignment.Sub || t === dt.VerticalAlignment.Super;
}
getSuperSubScale() {
return this.getFamily(), this.getSize(), this.getVerticalAlignment(), 0.6;
}
getSuperSubShift() {
return this.getFamily(), t = this.getSize(), (e = this.getVerticalAlignment()) === dt.VerticalAlignment.Super ? -t / 3 : e === dt.VerticalAlignment.Sub ? t / 5 : 0;
var t, e;
}
getFamily() {
return this._value("family") ?? this._c.getTheme().getFontScheme().getMinorFont();
}
setFamily(t, e) {
return this._o.updater({ font: { family: t } }, { description: "Set Font Family", ...e }).getFont();
}
getFallbacks() {
let t = this._value("fallbacks") ?? this._c.getTheme().getFontScheme().getMinorFallbacks() ?? k.EmptyArray;
return this.getFamily() === "Aptos Narrow" && (t = ["Calibri", ...t]), t;
}
setFallbacks(t, e) {
return this._o.updater({ font: { fallbacks: t } }, { description: "Set Font Fallbacks", ...e }).getFont();
}
getSize() {
return this._value("size") ?? this._c.getDefaultFontSize() ?? 11;
}
setSize(t, e) {
return this._o.updater({ font: { size: t } }, { description: "Set Font Size", ...e }).getFont();
}
getWeight() {
return this._value("weight");
}
setWeight(t, e) {
return this._o.updater({ font: { weight: t } }, { description: "Set Font Weight", ...e }).getFont();
}
getStyle() {
return this._value("style");
}
setStyle(t, e) {
return this._o.updater({ font: { style: t } }, { description: "Set Font Style", ...e }).getFont();
}
getFill() {
const t = this._value("fill");
return this._c.parseColor(t ?? N.Scheme.Bg1);
}
setFill(t, e) {
return this._o.updater({ font: { fill: t } }, { description: "Set Font Fill", ...e }).getFont();
}
getLetterSpacing() {
return this._value("letterSpacing") ?? this.getSize() / -25;
}
setLetterSpacing(t, e) {
return this._o.updater({ font: { letterSpacing: t } }, { description: "Set Font Letter Spacing", ...e }).getFont();
}
getUnderline() {
return this._value("underline");
}
setUnderline(t, e) {
return this._o.updater({ font: { underline: t } }, { description: "Set Font Underline", ...e }).getFont();
}
getStrike() {
return this._value("strike");
}
setStrike(t, e) {
return this._o.updater({ font: { strike: t } }, { description: "Set Font Strike", ...e }).getFont();
}
getScheme() {
return this._value("scheme");
}
setScheme(t, e) {
return this._o.updater({ font: { scheme: t } }, { description: "Set Font Scheme", ...e }).getFont();
}
getVerticalAlignment() {
return this._value("verticalAlign");
}
setVerticalAlignment(t, e) {
return this._o.updater({ font: { verticalAlign: t } }, { description: "Set Font Vertical Alignment", ...e }).getFont();
}
getShadow() {
return this._value("shadow");
}
setShadow(t, e) {
return this._o.updater({ font: { shadow: t } }, { description: "Set Font Shadow", ...e }).getFont();
}
getOutline() {
return this._value("outline");
}
setOutline(t, e) {
return this._o.updater({ font: { outline: t } }, { description: "Set Font Outline", ...e }).getFont();
}
getExtend() {
return this._value("extend");
}
setExtend(t, e) {
return this._o.updater({ font: { extend: t } }, { description: "Set Font Extend", ...e }).getFont();
}
get [Symbol.toStringTag]() {
return "[StyledFont]";
}
toString() {
return "[StyledFont]";
}
get isIStyledFont() {
return !0;
}
}
const vS = Object.freeze({ background: "none" });
class kd extends On {
getType() {
return st.Type.None;
}
toCSS(t) {
return vS;
}
toJSON() {
return { type: st.Type.None };
}
get [Symbol.toStringTag]() {
return "[NoneFill]";
}
toString() {
return "[NoneFill]";
}
get isIFill() {
return !0;
}
}
class xS extends On {
getType() {
return st.Type.Solid;
}
getColor() {
return this._c.parseColor(this._value("color") ?? N.Scheme.Bg1);
}
setColor(t, e) {
return this._o.updater({ fill: { color: t } }, { description: "Set Fill Color", ...e }).getFill();
}
toCSS(t) {
return { background: this.getColor().toCSS(t) };
}
toJSON() {
return { type: st.Type.Solid, color: this.getColor()?.toString() ?? null };
}
get [Symbol.toStringTag]() {
return "[SolidFill]";
}
toString() {
return "[SolidFill]";
}
get isIFill() {
return !0;
}
}
class IS extends On {
constructor(t, e, n, r) {
super(n, r), this._i = t, this._l = e;
}
getOffset() {
return this._value("offset") ?? this._i / this._l * 100;
}
getColor() {
return this._c.parseColor(this._value("color") ?? N.Scheme.Bg1);
}
}
class RS extends On {
getType() {
return st.Type.Gradient;
}
getStops() {
const t = this._value("stops") ?? k.EmptyArray, e = t.length, n = e === 0 ? k.EmptyArray : new Array(e);
for (let r = 0; r < e; r++) {
const o = t[r];
n[r] = new IS(r, e, this._o, [o]);
}
return n;
}
setStops(t, e) {
return this._o.updater({ fill: { stops: t } }, { description: "Set Stops", ...e }).getFill();
}
getGradientType() {
return this._value("gradientType") ?? st.GradientType.Linear;
}
setGradientType(t, e) {
return this._o.updater({ fill: { gradientType: t } }, { description: "Set Gradient Type", ...e }).getFill();
}
getAngle() {
return this._value("angle") ?? 0;
}
setAngle(t, e) {
return this._o.updater({ fill: { angle: t } }, { description: "Set Angle", ...e }).getFill();
}
getFillTo() {
return this._value("fillTo") ?? null;
}
setFillTo(t, e) {
return this._o.updater({ fill: { fillTo: t } }, { description: "Set Fill To", ...e }).getFill();
}
toCSS(t, e) {
const n = pm(this, t, e);
return n ? { background: n } : null;
}
toJSON() {
const t = { type: st.Type.Gradient }, e = this._value("stops") ?? k.EmptyArray, n = e.length;
if (n > 0) {
const r = new Array(n);
for (let o = 0; o < n; o++) {
const s = e[o], i = { color: s.color.toString() }, l = s.offset;
l !== void 0 && (i.offset = l), r[o] = i;
}
t.stops = r;
}
return this.getAngle() !== 0 && (t.angle = this.getAngle()), this.getGradientType() !== st.GradientType.Linear && (t.gradientType = this.getGradientType()), this.getFillTo() && (t.fillTo = this.getFillTo()), t;
}
get [Symbol.toStringTag]() {
return "[GradientFill]";
}
toString() {
return "[GradientFill]";
}
get isIFill() {
return !0;
}
}
class AS extends On {
getType() {
return st.Type.Pattern;
}
getBackground() {
const t = this._value("background") ?? N.Named.Window;
return this._c.parseColor(t);
}
setBackground(t, e) {
return this._o.updater({ fill: { background: t } }, { description: "Set Background Color", ...e }).getFill();
}
getForeground() {
return this._c.parseColor(this._value("foreground") ?? N.Scheme.Tx1);
}
setForeground(t, e) {
return this._o.updater({ fill: { foreground: t } }, { description: "Set Foreground Color", ...e }).getFill();
}
getPatternType() {
return this._value("patternType") ?? st.BuiltInSheetPattern.None;
}
setPatternType(t, e) {
return this._o.updater({ fill: { patternType: t } }, { description: "Set Pattern Type", ...e }).getFill();
}
toCSS(t) {
const e = this.getBackground().toCSS(t), n = this.getForeground().toCSS(t);
return this.getPatternType() === st.BuiltInSheetPattern.None ? { background: "none" } : this.getPatternType() === st.BuiltInSheetPattern.Solid ? { background: this.getForeground().toCSS(t) } : wS.toCSS(this.getPatternType(), n, e);
}
toJSON() {
const t = { type: st.Type.Pattern };
this.getPatternType() !== st.BuiltInSheetPattern.None && (t.patternType = this.getPatternType());
const e = this.getForeground();
e && (t.foreground = e.toString());
const n = this.getBackground();
return n && (t.background = n.toString()), t;
}
get [Symbol.toStringTag]() {
return "[PatternFill]";
}
toString() {
return "[PatternFill]";
}
get isIFill() {
return !0;
}
}
class vm {
constructor(t) {
this._o = t, this._p = new yS(t.properties), this._hasVisibleStyling = !this.getFill() || this.getFill().getType() !== st.Type.None || !this.getBorder().isEmpty();
}
toJSON() {
const t = this._p.toJSON(), e = t.namedStyle ?? mt.BuiltInName.Normal;
return delete t.namedStyle, t.named = e, t;
}
hasVisibleStyling() {
return this._hasVisibleStyling;
}
isNormal() {
return !1;
}
createTemporaryStyle(t) {
const e = this._o, n = e.styles, r = Ki(0, t, this), o = e.range, s = e.direct.cloneWithUpdate(r);
return no(n, s, o);
}
measureText(t, e = 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 = Mi(n, s);
return dt.getSharedMeasurer()(t, e * dt.getDeviceScale(), i, { isBold: o.getWeight() > 400, isItalic: o.getStyle().includes("italic"), letterSpacing: o.getLetterSpacing(), ...r });
}
createTemporaryTextFrame(t, e = !1) {
return $i(t, this.getFont(), this.getAlignment(), e);
}
update(t, e) {
return this._o.updater(t, e);
}
getBestFit() {
if (this._bestFit !== void 0) return this._bestFit;
const t = this.getInsets(), e = this.measureText("My");
return this._bestFit = { width: null, height: e.lineHeight + t.top + t.bottom }, this._bestFit;
}
getInsets() {
if (this._insets !== void 0) return this._insets;
const t = (this.getFont().getSize(), 1), e = (n = this.getFont().getSize(), Math.max(2, Math.round(n < 225 ? n / 5 : n / 3.5)));
var n;
const r = { top: t, left: e, bottom: t, right: e }, 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 CS(this._o, this._p.values("border"));
}
setBorder(t, e) {
return this._o.updater({ border: t }, { description: "Set Border", ...e });
}
getFont() {
return new bS(this._o, this._p.values("font"));
}
setFont(t, e) {
return this._o.updater({ font: t }, { description: "Set Font", ...e });
}
getFill() {
const t = this._p;
let e = t.values("fill"), n = t.value("fill");
return n.type === st.Type.None ? new kd(this._o, e) : n.type === st.Type.Solid || !n.type && n.color ? new xS(this._o, e) : n.type === st.Type.Gradient ? new RS(this._o, e) : n.type === st.Type.Pattern ? new AS(this._o, e) : new kd(this._o, e);
}
setFill(t, e) {
return this._o.updater({ fill: t }, { description: "Set Fill", ...e });
}
getAlignment() {
return new ES(this._o, this._p.values("alignment"));
}
setAlignment(t, e) {
return this._o.updater({ alignment: t }, { description: "Set Alignment", ...e });
}
getNumberFormat() {
const t = this._p.value("numberFormat");
return typeof t == "number" ? nc(t) : t;
}
setNumberFormat(t, e) {
return this._o.updater({ numberFormat: t }, { description: "Set Number Format", ...e });
}
getQuotePrefix() {
return this._p.value("quotePrefix");
}
setQuotePrefix(t, e) {
return this._o.updater({ quotePrefix: t }, { description: "Set Quote Prefix", ...e });
}
getNamed() {
const t = this._p.value("named") ?? mt.BuiltInName.Normal;
return this._o.styles.getNamed(t);
}
setNamed(t, e) {
return this._o.updater({ named: t }, { description: "Set Named Style", ...e });
}
get [Symbol.toStringTag]() {
return "[SheetCellStyle]";
}
toString() {
return null;
}
get isIStyle() {
return !0;
}
}
const no = (a, t, e, n = TS) => {
const r = e?.rowStart ?? L.EmptyCell.rowIndex, o = e?.colStart ?? L.EmptyCell.colIndex, s = [bm], i = a.getNormalRanged(), l = i.getPropertiesAt(r, o, null);
l && s.push(l);
const c = (d, u) => n(d, u, e);
if (!t)
return new MS({ styles: a, range: e, properties: s, layerTypes: null, direct: i, updater: c });
const h = t.getPropertiesAt(r, o, null);
return h && s.push(h), new vm({ styles: a, range: e, properties: s, direct: t, updater: c });
};
class MS extends vm {
isNormal() {
return !0;
}
}
const TS = (a) => {
throw new Error("Style is read-only and cannot be updated");
}, ir = (a, t) => {
if (a && !t || t && !a) return !1;
if (a === t) return !0;
if (a.style !== t.style) return !1;
if (a.color === t.color) return !0;
let e = a.color;
(a && a.color).isIColor && (e = a.color.toString());
let n = t.color;
return (t && t.color).isIColor && (n = t.color.toString()), e === n;
};
class oe {
constructor(t, e, n, r, o) {
this._c = t, this._r = e, this._p = n ?? null, this._t = r ?? null, this._o = o ?? F.Orientations.Both, this._e = this._p === null || Object.keys(this._p).length === 1 && this._p.named === mt.BuiltInName.Normal;
}
isEmpty() {
return this._e;
}
getProperties() {
return this._p;
}
getCoords() {
return this._r;
}
cloneWithUpdate(t) {
if (t === void 0) return this;
const e = this._c, n = this._r, r = this._p, o = Yt.resolveTypedUpdates(t, Qt, e, r);
return new oe(e, n, o, this._t, this._o);
}
copyTo(t, e) {
const n = this._c, r = this._r, o = t.rowStart - r.rowStart, s = t.colStart - r.colStart;
let i = null;
return L.isEqualRanges(r, this._t) || (i = L.translateRange(r, o, s)), new oe(n, t, this._p, i, this._o);
}
canTile(t, e) {
return !this._p.border;
}
_createShifted(t) {
return new oe(this._c, t, this._p, this._t, this._o);
}
getShifted(t) {
return t.after ? { ...t.after, value: this._createShifted(L.sanitizeRange(t.after)) } : null;
}
getSplit(t, e) {
const n = this._c, r = this._p, o = this._r;
let s = r;
const i = t[0];
let l = r;
const c = t[1], h = r ? r.border : null;
if (h) {
const g = e === F.Orientation.Column;
if (g ? 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 m = this._splitBorderRange(h, o, i, g);
m ? s.border = m : m === null && delete s.border, l = { ...l };
const f = this._splitBorderRange(h, o, c, g);
f ? l.border = f : f === null && delete l.border;
}
}
const d = this._t, u = this._o;
return [new oe(n, t[0], s, d, u), new oe(n, t[1], l, d, u)];
}
getMerged(t, e, n) {
const r = n === F.Orientation.Column, o = this._p, s = t._p;
if (o && !s || s && !o || !o && !s) return;
let i = Object.keys(o), l = Object.keys(s);
const c = i.length;
if (c !== l.length) return;
for (let g = 0; g < c; g++) {
const m = i[g];
if (m === "border") continue;
const f = o[m], p = s[m];
if (!k.deepEqual(f, p)) return;
}
const h = o.border, d = s.border;
if (h && !d || d && !h) return;
const u = this._c;
if (h || d) {
const g = r ? U.Edge.Top : U.Edge.Left, m = r ? U.Edge.Bottom : U.Edge.Right;
if (!ir(h[g], d[g]) || !ir(h[m], d[m])) return;
const f = this._r, p = t._r, _ = 1 + (r ? f.rowEnd - f.rowStart : f.colEnd - f.colStart), S = 1 + (r ? f.colEnd - f.colStart : f.rowEnd - f.rowStart), C = 1 + (r ? p.colEnd - p.colStart : p.rowEnd - p.rowStart), y = r ? U.Edge.Horizontal : U.Edge.Vertical;
if (_ > 1 && !ir(h[y], d[y])) return;
const E = r ? U.Edge.Right : U.Edge.Bottom, w = r ? U.Edge.Left : U.Edge.Top;
if (!ir(h[E], d[w])) return;
const b = r ? U.Edge.Vertical : U.Edge.Horizontal, v = h[E];
if (S > 1 && !ir(v, h[b])) return;
const I = C === 1 ? d[w] : d[b];
if (C > 1 && !ir(I, d[b]) || !ir(v, I)) return;
const x = { border: { [g]: h[g], [m]: h[m], [y]: h[y], [b]: v, [w]: h[w], [E]: d[E] } }, R = Yt.resolveTypedUpdates(x, Qt, u, o);
return new oe(u, e, R, this._t, this._o);
}
return new oe(u, e, this._p, this._t, this._o);
}
hasTrailingEdge() {
return !0;
}
isMergeOnShift() {
return !0;
}
_splitBorderRange(t, e, 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 ? e.colStart : e.rowStart, c = r ? e.colEnd : e.rowEnd, h = r ? n.colStart : n.rowStart, d = r ? n.colEnd : n.rowEnd;
let u = { ...t };
return delete u[o], delete u[s], delete u[i], l === h ? t[o] && (u[o] = t[o]) : t[i] && (u[o] = t[i]), c === d ? t[s] && (u[s] = t[s]) : t[i] && (u[s] = t[i]), d - h > 0 && t[i] && (u[i] = t[i]), Object.keys(u).length === 0 ? null : u;
}
_localizeBorderRange(t, e, n) {
if (!t) return;
let r = null;
const o = e.rowStart, s = e.rowEnd, i = n.rowStart, l = n.rowEnd;
t.top && i === o && (r = r ?? {}, r.top = t.top), t.bottom && l === s && (r = r ?? {}, r.bottom = t.bottom), t.horizontal && (l - i > 0 && (r = r ?? {}, r.horizontal = t.horizontal), i > o && (r = r ?? {}, r.top = t.horizontal), l < s && (r = r ?? {}, r.bottom = t.horizontal));
const c = e.colStart, h = e.colEnd, d = n.colStart, u = n.colEnd;
return t.left && d === c && (r = r ?? {}, r.left = t.left), t.right && u === h && (r = r ?? {}, r.right = t.right), t.vertical && (u - d > 0 && (r = r ?? {}, r.vertical = t.vertical), d > c && (r = r ?? {}, r.left = t.vertical), u < h && (r = r ?? {}, r.right = t.vertical)), r;
}
_localizeBorder(t, e, n, r) {
if (!t) return;
let o = null;
const s = e.rowStart, i = e.rowEnd;
t.top && n === s && (o = o ?? {}, o.top = t.top), t.bottom && n === i && (o = o ?? {}, o.bottom = t.bottom), t.horizontal && (n > s && (o = o ?? {}, o.top = t.horizontal), n < i && (o = o ?? {}, o.bottom = t.horizontal));
const l = e.colStart, c = e.colEnd;
return t.left && r === l && (o = o ?? {}, o.left = t.left), t.right && r === c && (o = o ?? {}, o.right = t.right), t.vertical && (r > l && (o = o ?? {}, o.left = t.vertical), r < c && (o = o ?? {}, o.right = t.vertical)), o;
}
getPropertiesAt(t, e, n) {
const r = this._p;
let o = r;
const s = this._t;
if (s) {
const l = this._r, c = s.colEnd - s.colStart + 1, h = s.rowEnd - s.rowStart + 1;
e = l.colStart + (e - l.colStart + (s.colStart - l.colStart)) % c, t = l.rowStart + (t - l.rowStart + (s.rowStart - l.rowStart)) % h;
}
const i = o?.border;
if (i) {
const l = s ?? this._r, c = this._localizeBorder(i, l, t, e);
c !== void 0 && (o === r && (o = { ...o }), c === null ? delete o.border : o.border = c);
}
return o;
}
toJSON() {
return k.toSafeJSON(this._p);
}
}
const NS = Object.freeze({ value: null, style: null, hyperlink: null, formula: null, type: Y.Null, stringToParse: null }), Od = Object.seal({ value: void 0, style: void 0, hyperlink: void 0, formula: void 0, type: void 0, stringToParse: void 0 }), FS = Object.seal({ value: void 0, style: void 0, hyperlink: void 0, formula: void 0 }), kS = Object.freeze({ width: 1, height: 1 }), OS = new ac({ max: 1e3 }), DS = new class {
isEditAllowed() {
return !0;
}
isFormulaHidden() {
return !1;
}
get isICellProtection() {
return !0;
}
}(), Pl = (a, t, e = null, n = null, r = !1) => {
if (a === void 0) return;
if (a === null) return NS;
if (a && a.isICell) {
const _ = a, S = Od;
return S.value = _.getValue(), _.getStyle().isNormal() ? S.style = null : S.style = _.getStyle()._p.getProperties(), S.formula = _.getFormulaText(), S.hyperlink = _.getHyperlink(), S.type = _.getType(), S;
}
let o;
a.value !== void 0 || a.style !== void 0 || a.hyperlink !== void 0 ? o = a : (o = FS, o.value = a, o.style = void 0, o.hyperlink = void 0);
const s = Od;
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 = _e(l), i || (c = ro(l), c && (i = Y.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, d, u = null, g = null, m;
if (i === Y.String) {
if (m = o.value, e) {
let _ = n?.get(m);
if (!_) {
const S = m.length, C = m.charAt(0);
C === "=" && S > 1 ? (d = m.substring(1), l = null) : (_ = Am(m, e), !_ || typeof _.value != "string" || C !== "+" && C !== "-" || (d = "=" + m, l = null), _ !== void 0 && n && n.set(m, _));
}
_ && (_.value !== void 0 && (l = _.value, i = _e(l)), _.style !== void 0 && (u = _.style), _.hyperlink !== void 0 && (h = _.hyperlink)), !r && e.parse && (g = m);
}
} else if (c) {
const _ = e?.date1904 ?? t.date1904;
l = rs(o.value, _), u = (S) => {
if (!os(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, u) if (f) {
const _ = f;
f = (S) => {
let C = S.createTemporaryStyle(u);
return C = C.createTemporaryStyle(_), C = C._p.getProperties(), C;
};
} else f = u;
let p = !1;
return l !== void 0 && (l === null ? (s.value = null, s.type = Y.Null) : (s.value = l, s.type = i), p = !0), f !== void 0 && (s.style = f, p = !0), h !== void 0 && (s.hyperlink = h, p = !0), d !== void 0 && (s.formula = d, p = !0), r || (s.stringToParse = g, p = !0), p ? (s.type = i, s) : void 0;
}, xm = (a, t, e, n) => Em(e, t, a, t.getNumberFormat(), (r) => n.styles.parseColor(r), n.date1904), Im = (a, t, e, n, r = !1) => {
if (a === Y.Null) return null;
let o = "";
if (r) o = "" + e;
else {
const s = xm(a, t, e, 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 $i(o, t.getFont(), t.getAlignment(), a === Y.String, r);
}, hc = (a, t) => {
const e = t.getInsets();
if (a === Y.Null) return e;
let n = e;
const r = Xi(a, t), o = t.getAlignment().getIndent();
if (o && (r === et.HorizontalAlignment.Left || r === et.HorizontalAlignment.Right)) {
n = { ...e };
const s = t.measureText(" ".repeat(1 * o)), i = Math.min(3, Math.max(1, (26 - t.getFont().getSize()) / 2));
let l = s.width * i;
r === et.HorizontalAlignment.Left ? n.left += l : r === et.HorizontalAlignment.Right && (n.right += l);
}
return Object.freeze(n);
}, Xi = (a, t) => {
const e = t.getAlignment(), n = e.getRotation(), r = e.getHorizontal();
return n !== 0 && r === et.HorizontalAlignment.General ? n > 0 && n < 90 || n > 180 && n <= 270 ? et.HorizontalAlignment.Right : et.HorizontalAlignment.Left : r === et.HorizontalAlignment.General ? a === Y.Null ? et.HorizontalAlignment.Left : a === Y.Boolean || a === Y.Error ? et.HorizontalAlignment.Center : t.getNumberFormat() === "@" ? et.HorizontalAlignment.Left : a === Y.Number ? et.HorizontalAlignment.Right : et.HorizontalAlignment.Left : r;
}, Rm = (a, t, e, n, r, o, s, i, l) => {
if (e === Y.Null || r === "") return null;
const c = t;
if (!((B, H, P = !1, j = !1) => {
if (B === Y.Null) return !1;
const G = H.getAlignment(), K = G.getHorizontal();
if (K === et.HorizontalAlignment.CenterContinuous || K === et.HorizontalAlignment.Fill) return !0;
if (K === et.HorizontalAlignment.Distributed || B !== Y.String || G.getOverflow() !== et.Overflow.Visible || K === et.HorizontalAlignment.Right && P || K === et.HorizontalAlignment.Center && P && j || j && (K === et.HorizontalAlignment.General || K === et.HorizontalAlignment.Left)) return !1;
const V = G.getVertical();
return V !== et.VerticalAlignment.Justify && V !== et.VerticalAlignment.Distributed;
})(e, n, o !== null && o.colIndex + 1 === c, s !== null && s.colIndex - 1 === c)) return null;
const h = BS(e, n, r, l), d = n.getAlignment(), u = d.getHorizontal(), g = d.getOverflow() === et.Overflow.Wrap || e === Y.String && (u === et.HorizontalAlignment.Justify || u === et.HorizontalAlignment.Distributed || d.getVertical() === et.VerticalAlignment.Justify || d.getVertical() === et.VerticalAlignment.Distributed), m = u === et.HorizontalAlignment.Fill, f = u === et.HorizontalAlignment.CenterContinuous || m;
if (!h && !f) return null;
const p = ((B) => B === et.HorizontalAlignment.Center || B === et.HorizontalAlignment.CenterContinuous ? fn.Center : B === et.HorizontalAlignment.Right ? fn.Right : fn.Left)(Xi(e, n));
let _ = 0, S = 0, C = 0, y = 0, E = 1;
if (f && r !== null && i) {
Pa.colIndex = t, Pa.rowIndex = a;
const B = i.colEnd;
E = Math.min(l.nextContentful(Pa, B), B) - t + 1;
}
const w = l.colHeaders, b = w.findOffset.bind(w), v = w.findIndex.bind(w);
let I = b(c);
const x = I;
let R = b(c + E), A = R - I, M = c, T = c;
const O = { x: 0, y: 0, width: A, height: h?.height ?? 0 }, W = c - c + E;
let D = h ? h.width - A : 0, z = O;
return A > 0 && D > 0 && !g && (p === fn.Center && (D /= 2), p !== fn.Left && p !== fn.Center || (T = v(R + D), s !== null && (T = Math.min(T, s.colIndex - 1)), R = b(T), y = D, S = T - c), p !== fn.Right && p !== fn.Center || (M = v(I - D), o !== null && (M = Math.max(M, o.colIndex + 1)), I = b(M), C = D, _ = c - M), O.x = x - I, z.x = O.x), E > 1 && (S = p === fn.Center ? Math.max(W - 1, S) : E - 1, R = b(c + 1), O.width = R - I, z = { ...O }, z.width = A), { anchorBounds: O, leftIndex: _, rightIndex: S, leftOffset: C, rightOffset: y, colSpan: W, colBounds: z };
};
class LS {
constructor(t, e) {
this._styles = t, this._ri = e;
const n = e?.table;
n && (this._table = n.getStyle().getRanged(n));
const r = e?.conditionals;
if (r) {
const o = r.length, s = new Array(o);
for (let i = 0; i < o; i++) {
const l = r[i];
s[i] = l;
}
this._conditionals = s;
}
}
getCoords() {
return L.EmptyRange;
}
getPropertiesAt(t, e, n) {
let r = null, o = this._ri.directStyle?.getPropertiesAt(t, e, n) ?? null;
const s = this._styles;
if (o && o.named) {
const d = o.named;
if (d !== mt.BuiltInName.Normal) {
const u = this._styles.getNamed(d);
u ? r = u.getRanged().getPropertiesAt(t, e, n) : console.warn(`A named styled was referenced but not found: '${d}'.`);
}
}
let i = null;
const l = this._table?.getPropertiesAt(t, e, n);
l && (i = i ? Yt.resolveTypedUpdates(l, Qt, s, i) : l);
let c = null;
r && (c = c ? Yt.resolveTypedUpdates(r, Qt, s, c) : r), o && (c = c ? Yt.resolveTypedUpdates(o, Qt, s, c) : o), c && (c = s.normalize(c, mt.BuiltInName.Normal), i = i && c ? Yt.resolveTypedUpdates(c, Qt, s, i) : c ?? i);
const h = this._conditionals;
if (h) {
const d = h.length;
for (let u = 0; u < d; u++) {
const g = h[u].getPropertiesAt(t, e, n);
g && (i = i ? Yt.resolveTypedUpdates(g, Qt, s, i) : g);
}
}
return i;
}
cloneWithUpdate(t) {
return (this._ri.directStyle ?? this._styles.getNormalRanged()).cloneWithUpdate(t);
}
}
const Vr = (a, t, e, n) => {
const r = n.styles;
return no(r, e ? new LS(r, e) : null, t, n.styleUpdater);
}, Un = (a, t, e, n, r, o, s, i = null, l = OS) => {
if (e === null) return t ? t.getBestFit() : null;
const c = a === Y.String, h = t.getFont(), d = h.getWeight(), u = h.getSize(), g = h.getFamily(), m = t.getAlignment(), f = m.getOverflow(), p = m.getRotation(), _ = m.getVertical(), S = t.getNumberFormat(), C = c && f === et.Overflow.Visible, y = c && (f === et.Overflow.Wrap || _ === et.VerticalAlignment.Justify || _ === et.VerticalAlignment.Distributed), E = (i ?? "") + "\0" + u + g + d + S + p + C + y + o + s + (i ? "" : e), w = l.get(E);
if (w) return w;
let b = null, v = null;
const I = hc(a, t), x = I.top + I.bottom + +VS(t);
let R = !1, A = !1;
s && (A = !0, (p !== 0 || y) && (A = !1));
const M = A ? void 0 : Im(a, t, e, n), T = I.left + I.right + 2;
if (M) {
if (a === Y.Number && S === "General" && o) {
let D = e, z = k.splitNumber(D), B = "";
B = Math.abs(D) >= Math.pow(10, 12) || Math.abs(D) <= Math.pow(10, -12) ? `0.${"0".repeat(Math.max(2, Math.min(z.ipLength, 5)))}E+00` : Math.abs(z.ipLength) === 0 ? "0.0" : Math.abs(z.fpLength) > 0 ? "0".repeat(z.ipLength) + ".0" : "0".repeat(z.ipLength), D < 0 && (B = "-" + B), B = "0".repeat(B.length);
const H = t.measureText(B);
b = H.width, v = H.lineHeight;
} else {
let D = null;
y && (D = { width: Math.max(1, r - T) });
const z = M.layout(D);
b = z.bounds.width, v = z.bounds.height;
}
if (b !== null && (b += T), v !== null && (v += x), R = a === Y.String, p) {
R && f === et.Overflow.Wrap && (R = !1);
const D = ((z, B) => {
const { x: H, y: P, width: j, height: G } = z, K = B * Math.PI / 180, V = Math.sin(K), $ = Math.cos(K), J = j / 2, Z = G / 2, q = _s(-J, -Z, V, $), Q = _s(J, -Z, V, $), it = _s(-J, Z, V, $), X = _s(J, Z, V, $);
let at = Math.min(q.x, Q.x, it.x, X.x) + J, ut = Math.max(q.x, Q.x, it.x, X.x) + J, tt = Math.min(q.y, Q.y, it.y, X.y) + Z;
return { x: H + at, y: P + tt, width: ut - at, height: Math.max(q.y, Q.y, it.y, X.y) + Z - tt };
})({ x: 0, y: 0, width: b, height: v }, p);
b = D.width, v = D.height;
}
} else v = t.getBestFit().height;
o && R && (b = 0);
const O = { width: b, height: v }, W = Object.freeze(O);
return l.set(E, W), W;
}, BS = (a, t, e, n) => {
const r = hc(a, t), o = Xi(a, t);
let s = r.left + r.right;
o === et.HorizontalAlignment.Left ? s = r.right : o === et.HorizontalAlignment.Right ? s = r.left : o === et.HorizontalAlignment.Center && (s = r.left + r.right);
const i = Un(a, t, e, n, Number.MAX_SAFE_INTEGER, !1, !1);
return { width: Math.ceil(i.width - s), height: Math.ceil(i.height) };
};
class er {
constructor(t, e, n = Y.Null, r = null, o = null, s = null, i = null) {
this._options = t, this._coords = e ?? null, this._t = n, this._ri = o, this._v = r, this._p = s, this._n = i;
}
getRange() {
const t = this._coords;
return this._options.getRange(t ? L.cellToRange(t) : null);
}
isEqual(t) {
if (!t) return !1;
if (this === t) return !0;
const e = t;
return !!e.isICell && this._v === e._v && !!L.isEqualCells(this._coords, t.getCoords()) && this._options.sheet === e._options?.sheet;
}
getCoords() {
return this._coords;
}
getA1() {
const t = this._coords;
return t ? ln(this._options.resolveRange(t).getCoords()) : ie;
}
getSheet() {
return this._options.sheet;
}
select(t) {
return this._options.opener("#" + as(this._coords), t);
}
getColumnFilter() {
if (!this._ri) return null;
let t = null;
if (this._ri.table) {
const e = this._ri.table.getHeaderRange().getCoords();
if (e && L.isCellWithinRange(this._coords, e)) {
const n = this._coords.colIndex - e.colStart;
t = this._ri.table.getColumnFilter(n) ?? null;
}
}
return t;
}
getProtection() {
return DS;
}
getTextOverflow() {
const t = this._to;
if (t !== void 0) return t;
const e = this._ri;
if (e && e.merge) return this._to = null, null;
const n = this._t;
let r = null;
if (n === Y.String || e && e.continuous) {
const o = this.getStyle(), s = this._coords;
r = Rm(s.rowIndex, s.colIndex, n, o, this._v, this._p, this._n, e?.continuous?.getCoords() ?? null, this._options);
}
return r === null || r.leftIndex === 0 && r.rightIndex === 0 && r.colSpan <= 1 ? (this._to = null, null) : (this._to = r, this._to);
}
getRenderHorizontalAlignment() {
return Xi(this._t, this.getStyle());
}
isEmpty() {
return this._v === null && !this._ri;
}
getExtrusions() {
const t = this._ri;
if (!t && this._to === null) return null;
if (t) {
const r = t.merge;
if (r !== void 0) return r.getCoords();
}
const e = this.getTextOverflow();
if (!e) return null;
const n = this._coords;
return { colStart: n.colIndex - e.leftIndex, rowStart: n.rowIndex, colEnd: n.colIndex + e.rightIndex, rowEnd: n.rowIndex };
}
isEditAllowed() {
const t = this._options;
return t ? !t.getProtection().isLocked() || !!this._ri && this.getProtection().isEditAllowed() : !0;
}
isFormulaHidden() {
return !!this._options.getProtection().isLocked() && !!this._ri && this.getProtection().isFormulaHidden();
}
isContentful() {
return this._v !== null;
}
getBestFit(t, e = !1) {
return t === void 0 && (t = this._options.sheet.getColumnHeaders().getSpanSize(this._coords.colIndex) ?? 64), Un(this._t, this.getStyle(), this._v, this._options, t, e, !1);
}
getInsets() {
return this._v === null ? this.getStyle().getInsets() : hc(this._t, this.getStyle());
}
getTextFrame(t) {
let e, n;
if (t && (n = this.getFormulaText()), e = n ?? this._v, e === null) return null;
const r = this.getStyle();
return n ? ((o, s) => s === Y.Null ? null : $i(s, o.getFont(), o.getAlignment(), !1, !0))(r, e, this._options) : Im(this._t, r, e, this._options, t);
}
getValue() {
return this._v;
}
getFormula() {
let t = this._ri?.formula;
if (!t) return null;
const e = this._coords;
return e ? (Array.isArray(t) && (t = t[0]), new PS(this._options, t, e)) : null;
}
getFormulaText() {
let t = this._ri?.formula;
if (!t) return null;
const e = this._coords;
return e ? (Array.isArray(t) && (t = t[0]), "=" + t.getFormulaTextAt(e.rowIndex, e.colIndex)) : null;
}
getCalcStatus() {
const t = this._ri;
return t && t.pending ? Ft.CalcStatus.Pending : Ft.CalcStatus.Ready;
}
getType() {
return this._t;
}
getStyle(t = !1) {
if (!t && this._styleConditional) return this._styleConditional;
if (t && this._styleSpecific) return this._styleSpecific;
const e = Vr(0, L.cellToRange(this._coords), this._ri, this._options);
return t ? this._styleSpecific = e : this._styleConditional = e, e;
}
createTemporaryCell(t) {
const e = this._options;
if (t === null) return new er(e, this._coords, null);
const n = Pl(t, this._options);
let r = this._ri;
if (n.style !== void 0) {
const i = this._coords ?? L.EmptyCell, l = L.cellToRange(i), c = () => Vr(0, l, this._ri, this._options), h = Ki(this._options.styles, n.style, c), d = (this._ri?.directStyle ?? new oe(e.styles, l)).cloneWithUpdate(h);
r = { ...r, directStyle: d };
}
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._ri ? this : s !== null || r ? new er(this._options, this._coords, o, s, r) : new er(this._options, this._coords);
}
_isDate1904() {
return this._options.date1904;
}
getNumberFormat(t) {
if (t !== void 0) {
const e = this._v;
return Em(e, this.getStyle(), this._t, t, (n) => this._options.styles.parseColor(n), this._isDate1904());
}
return xm(this._t, this.getStyle(), this._v, this._options);
}
toDate() {
return this._t !== Y.Number ? null : this._ri ? this.getNumberFormat().asDate : null;
}
toText() {
return this.getNumberFormat().displayText;
}
toTextUnformatted(t) {
if (t) {
const n = this.getFormulaText();
if (n) return n;
}
let e = this._v;
return this.isSpillOverflow() && (e = null), ((n, r, o, s) => {
if (r === Y.Null || n == null) return "";
if (r === Y.Number) {
const i = n, l = os(o), c = Wi(o);
if (l || c) {
const h = parseFloat(n), d = h % 1 != 0, u = h >= 1;
if (h < 0) return k.castToString(n);
if (!l || c || d) if (!c || l || u) {
const g = Do("Short Date", i, s), m = Do("Long Time", i, s);
if (g && m) return g.fmt + " " + m.fmt;
} else {
const g = Do("Long Time", i, s);
if (g) return g.fmt;
}
else {
const g = Do("Short Date", i, s);
if (g) return g.fmt;
}
}
}
if (r === Y.Number && o.endsWith("%")) {
let i = k.roundAccurately(100 * parseFloat(n));
if (!isNaN(i)) return i + "%";
}
return r === Y.Boolean ? n ? "TRUE" : "FALSE" : r === Y.Error ? n?.getLabel?.() ?? pt.Label.Unknown : r === Y.RichData ? "(Rich Object)" : k.castToString(n);
})(e, this._t, this.getStyle().getNumberFormat(), { date1904: this._isDate1904() });
}
getComments() {
const t = this._ri?.comments;
return t ? Object.freeze(t) : null;
}
getHyperlink() {
const t = this._ri?.hyperlink;
return t ? new i_(this.toText.bind(this), this._options.opener, t) : null;
}
getErrors() {
const t = this._ri;
return t && t.calcError ? [t.calcError] : k.EmptyArray;
}
getWarnings() {
return k.EmptyArray;
}
getSpans() {
const t = this._ri?.merge;
if (!t) return kS;
const e = t.getCoords();
return Object.freeze({ width: e.colEnd - e.colStart + 1, height: e.rowEnd - e.rowStart + 1 });
}
isTopLeft() {
const t = this._ri?.merge;
if (!t) return !0;
const e = t.getCoords();
return this._coords && this._coords.colIndex === e.colStart && this._coords.rowIndex === e.rowStart;
}
getSpill() {
let t = this._ri?.spills;
if (!t || !this._coords) return null;
Array.isArray(t) || (vs[0] = t, t = vs);
let e = null;
for (let n = 0; !e && n < t.length; n++) {
const r = t[n];
r.getError() || (e = r);
}
return e || (e = t[0]), this._options.getRange(e.getCoords());
}
isSpillOverflow() {
let t = this._ri?.spills;
if (!t) return !1;
if (!this._coords) return null;
Array.isArray(t) || (vs[0] = t, t = vs);
for (let e = 0; e < t.length; e++) {
const n = t[e].getCoords();
if (this._coords.colIndex === n.colStart && this._coords.rowIndex === n.rowStart) return !1;
}
return !0;
}
get [Symbol.toStringTag]() {
return "[Cell]";
}
toString() {
let t = "{blank}";
return this._v !== null && (t = this.toTextUnformatted(), this.getType() === Y.String && (t = `'${t}'`)), `${this.getA1()} => ${t}`;
}
get isICell() {
return !0;
}
}
let zS = class extends er {
constructor(a) {
super(a, null, null, null);
}
isEmpty() {
return !0;
}
isContentful() {
return !1;
}
toString() {
return "{EMPTY CELL}";
}
};
class PS {
constructor(t, e, n) {
this._options = t, this._entry = e, this._coords = n;
}
getTokens(t) {
const e = this._coords;
return e ? this._entry.getTokensAt(e.rowIndex, e.colIndex, t) : k.EmptyArray;
}
evaluate(t) {
const e = this._coords;
return e ? this._options.calcGraph().evaluateAt(e.rowIndex, e.colIndex, t) : k.EmptyArray;
}
toText(t) {
const e = this._coords;
return e ? "=" + this._entry.getFormulaTextAt(e.rowIndex, e.colIndex, t) : null;
}
getDirectPrecedents() {
const t = this._coords;
return t ? this._options.calcGraph().getDirectPrecedentsAt(t.rowIndex, t.colIndex) : k.EmptyArray;
}
getReferences() {
const t = this._coords;
return t ? this._entry.getReferencesAt(t.rowIndex, t.colIndex) : k.EmptyArray;
}
setReferenceAt(t, e) {
const n = this._coords;
return n ? (this._options.calcGraph().setReferenceAt(n.rowIndex, n.colIndex, t, e), this) : k.EmptyArray;
}
get [Symbol.toStringTag]() {
return "[Formula]";
}
toString() {
return this.toText();
}
}
const vs = [null], Pa = { colIndex: -1, rowIndex: -1 };
let Wa;
const Ti = (a, t, e, n = !1) => {
const r = e === F.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: t.rowStart, colEnd: n ? l.colEnd + c : l.colEnd, rowEnd: t.rowEnd };
} else {
const c = l.rowEnd - l.rowStart + 1;
s[i] = { ...l, colStart: t.colStart, rowStart: n ? l.rowEnd + 1 : l.rowStart, colEnd: t.colEnd, rowEnd: n ? l.rowEnd + c : l.rowEnd };
}
}
return s;
}, Wl = (a, t, e) => {
const n = t, r = a.length, o = n.rowStart, s = n.rowEnd;
for (let i = 0; i < r; i++) {
const l = a[i];
if ((l.rowStart <= o && l.rowEnd >= s) !== e) return !e;
}
return e;
}, Hl = (a, t, e) => {
const n = t, r = a.length, o = n.colStart, s = n.colEnd;
for (let i = 0; i < r; i++) {
const l = a[i];
if ((l.colStart <= o && l.colEnd >= s) !== e) return !e;
}
return e;
}, WS = (a, t) => {
if (t) {
if (a.colStart <= t.colStart && a.colEnd >= t.colEnd) return F.Orientation.Row;
if (a.rowStart <= t.rowStart && a.rowEnd >= t.rowEnd) return F.Orientation.Column;
}
return a ? ((e) => e.rowEnd - e.rowStart > e.colEnd - e.colStart ? F.Orientation.Column : F.Orientation.Row)(a) : F.Orientation.Row;
}, xs = () => !1, Ha = () => !0, Is = () => null, Va = () => re, Cn = () => 0, Dd = new class extends er {
constructor() {
super(null, null);
}
createTemporaryCell() {
return this;
}
getType() {
return Y.Error;
}
getWarnings() {
return [ie];
}
getStyle(a = !1) {
return Wa || (Wa = new cs().getNormal(), Wa);
}
toString() {
return `${this._coords ? as(this._coords) : ie} => ${this._v ?? "{blank}"}`;
}
}(), nn = () => Qn, Qn = { forEach: () => {
}, [Symbol.iterator]: Va, entries: Va, values: Va, select: vt, find: vt, calculate: vt, getCell: () => Dd, getValue: Is, setValue: vt, setFormula: vt, setValues: vt, updateCells: vt, getCells: () => [[Dd]], getStyle: vt, getValues: () => [[null]], toText: () => "", getBounds: Is, getIntersect: nn, getUnion: nn, getDifferences: vt, getResizeBy: nn, getResizeTo: nn, getOffsetBy: nn, getOffsetTo: nn, getFixed: nn, getUsedRange: nn, getEntireRows: nn, getEntireColumns: nn, getSurrounding: vt, getExtended: vt, isEntireRows: xs, isEntireColumns: xs, isEntireRange: xs, getWidth: Cn, getHeight: Cn, size: 0, sort: vt, clear: vt, setHyperlink: vt, setComments: vt, merge: vt, unmerge: vt, getMerges: vt, insert: vt, insertFrom: vt, delete: vt, getDefaultShiftOrientation: vt, getDefaultSortCriteria: vt, autoFill: vt, autoFit: vt, getSnapshot: vt, copyFrom: vt, doBatch: vt, startIncrementalUpdates: vt, getRowHeaders: vt, getColumnHeaders: vt, getCounts: vt, getCount: Cn, isContentful: xs, addListener: vt, getColumnStart: Cn, getRowStart: Cn, getColumnEnd: Cn, getRowEnd: Cn, getRowCount: Cn, getColumnCount: Cn, getVisible: vt, getCoords: Is, isEmpty: Ha, toString: () => ie, getA1: () => ie, isInvalid: Ha, getSheet: Is, isReadOnly: Ha, isICellRange: !0 };
function Rn(a, t = null, e = null, n = ie) {
return a || e ? Object.freeze({ ...Qn, getSheet: () => a, bounds: () => e, getA1: () => n, toString: () => e ? kn(e, t) : n }) : Qn;
}
const HS = /^[\\+-]?[0-9]*\.?[0-9]*$/, Am = (a, t, e) => {
if (a === void 0) throw new Error("A value is required to create a cell from a text.");
const n = e ?? { value: null };
if ((a = k.castToString(a)).trim() === "") return n;
if (a.toUpperCase() === "TRUE" || a.toUpperCase() === "FALSE") return n.value = a.toUpperCase() === "TRUE", n;
if (a.startsWith("'") && !t?.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 = ((p) => {
const _ = new RegExp("([(]{1}([^(|^)]+)[)]{1})").exec(p);
if (_?.[2]) {
const S = p.substring(0, _.index) + _[2].trim() + p.substring(_.index + ("(" + _[2] + ")").length - 1, p.length - 1);
return S.indexOf("(") > -1 || S.indexOf(")") > -1 ? p : (c = !0, l = -1, S);
}
return p;
})(i);
let h = 0;
i = ((p) => {
const _ = new RegExp("[0-9]+([eE][-+]?[0-9]+)?$").exec(p);
if (_?.[1]) {
const S = p.substring(0, p.length - _[1].length);
let C = 1, y = _[1].substring(1, _[1].length);
if (y.startsWith("-") ? (y = y.substring(1, y.length), C = -1) : y.startsWith("+") && (y = y.substring(1, y.length)), !isNaN(y)) return h = y * C, S;
}
return p;
})(i);
let d = !1;
if (i = ((p) => {
const _ = new RegExp(`^(\\${o}[\\ ]*\\-|\\${o}[\\ ]*\\+|\\-[\\ ]*\\${o}|\\+[\\ ]*\\${o}|\\-|\\+)?`).exec(p);
if (_?.[1]) {
const S = _?.[1].indexOf(o) > -1, C = _?.[1].indexOf("-") > -1, y = _?.[1].indexOf("+") > -1, E = (S ? o : "") + p.substring(_.index + _[1].length, p.length).trim(), w = E.indexOf("-") > -1, b = E.indexOf("+") > -1;
return w || b ? p : (d = C || y, C && (l = -1), E);
}
return p;
})(i), d && (c || i.length === 0)) return n;
let u = !1;
if (i = ((p) => {
if (new RegExp(`^(?:\\${o}[\\ ]*)?((\\d{1,3}(${r}\\d{3})*)|(\\d*))(\\${s}|\\${s}\\d*)?(?:[\\ ]*\\%)?$`).test(i)) {
const _ = p.replace(new RegExp(`${r}`, "g"), "");
return u = _.length < p.length, _;
}
return p;
})(i), i.match(HS) && !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 (u) {
let p = ei(i);
n.style = p > 0 ? { numberFormat: `#${r}##0${s + "0".repeat(2)}` } : { numberFormat: `#${r}##0` };
}
return n;
}
if (i.trimEnd().endsWith("%") && i.trimEnd().length > 1) {
let p = i.substring(0, i.length - 1);
if (!isNaN(p)) {
n.value = p * l / 100;
const _ = ei(p);
n.style = (S) => {
if (!S.getNumberFormat().includes("%")) return { numberFormat: _ > 0 ? `0${s + "0".repeat(2)}%` : "0%" };
};
}
return n;
}
if (i.startsWith(o) && a.trim().length > 1) {
let p = i.replace(o, "");
if (!isNaN(p)) {
let _ = ei(p);
n.value = p * l, n.style = (S) => {
if (S.getNumberFormat().includes(o)) return;
let C;
return C = _ > 0 ? `${o}#${r}##0${s + "0".repeat(2)}_);[Red](${o}#${r}##0${s + "0".repeat(2)})` : `${o}#${r}##0_);[Red](${o}#${r}##0)`, { numberFormat: C };
};
}
return n;
}
let g = null, m = null;
try {
m = mg(a, t?.date1904, !0);
let p = a;
m && (p = m.leadingText), p.trim().length > 0 && (g = Ql(p, t?.date1904)), !g && m?.leadingText.trim().length > 0 && (m = null);
} catch {
}
if (g || m) {
n.style = (_) => {
let S = _.getNumberFormat();
const C = os(S);
if (g && C) return;
const y = Wi(S);
if (!m || !y) {
if (g && m && !C && !y ? S = "m/d/yyyy h:mm" : g && !C ? S = g.numberFormat : m && !y && (S = m.numberFormat), m && m.parsed.oaDateTime > 1 && (S = "General"), g && !C && !m) {
const E = Ne.Parser.formatValue(g.numberFormat, g.asOADate, { date1904: t?.date1904 }), w = Intl.DateTimeFormat().resolvedOptions().locale ?? "en-US";
E === new Intl.DateTimeFormat(w).format(g.asJSDate) ? S = "Short Date" : E === new Intl.DateTimeFormat(w, { dateStyle: "full" }).format(g.asJSDate) ? S = "Long Date" : E === new Intl.DateTimeFormat(w, { timeStyle: "medium" }).format(g.asJSDate) && (S = "Long Time");
}
return { numberFormat: S };
}
};
let p = 0;
return g && (p += g.asOADate), m && (p += m.parsed.oaDateTime), n.value = p, n;
}
const f = pt.getBuiltInByLabel(a);
return f ? (n.value = f, n) : (n.value = a, vg(a) ? n.hyperlink = a : xg(a) && (n.hyperlink = a, n.hyperlink.toLowerCase().startsWith("mailto:") || (n.hyperlink = `mailto:${n.hyperlink}`)), a.includes(`
`) && (n.style = { ...n?.style, alignment: { overflow: et.Overflow.Wrap } }), n);
}, VS = (a) => {
const t = a.getFont().getUnderline() === dt.UnderlineStyle.SingleAccounting, e = a.getFont().getUnderline() === dt.UnderlineStyle.DoubleAccounting;
let n = 0;
return (t || e) && (n = a.measureText("").underlineThickness + 1, e ? n *= 2 : n += 1), n;
}, ja = (a) => {
const t = [];
return a.getUsedRange().forEachSpan((e, n) => {
const r = n.getCoords();
e === 0 && t.push(r);
}, { includeStyles: !1 }), bn(wr(t));
}, Ld = (a) => {
if (!a) return null;
let t = null;
const e = a.length;
for (let n = 0; n < e; n++) {
const r = a[n].value;
if (!r) continue;
t || (t = { ...t });
const o = Object.keys(r), s = o.length;
for (let i = 0; i < s; i++) {
const l = o[i], c = t[l];
if (c) if (Array.isArray(c)) {
const h = r[l];
if (Array.isArray(h)) {
const d = h.length;
for (let u = 0; u < d; u++) c.push(h[u]);
} else c.push(h);
} else t[l] = [c, r[l]];
else t[l] = r[l];
}
}
return t;
}, $a = (a, t, e, n) => {
const r = n?.asJSDate;
let o;
e ? o = cm : (r || n?.includeMergeOverflow) && (o = {}, r && (o[ht.Type.Style] = !1, o[ht.Type.Table] = !1), n.includeMergeOverflow && (o[ht.Type.Merge] = !1));
const s = n?.orientation ?? F.Orientation.Row, i = n?.maxSize ?? 1e4, l = a({ includeEmpty: !0, orientation: s, reverse: n?.reverse, ignoreHidden: n?.ignoreHidden, includeMergeOverflow: n?.includeMergeOverflow, includeRangeTypes: o, bounds: t, ignoreCellDetails: !r }), c = s !== F.Orientation.Row, h = [];
let d, u = -1, g = null, m = 0;
for (d = l.next(); !d.done; ) {
if (m > i) throw new Error(hm(i));
const f = d.value, p = f.context.getCoords(), _ = c ? p.colIndex : p.rowIndex;
_ !== u && (g = [], h.push(g), u = _);
let S = f.value;
if (e) S = f.context.getCell();
else if (r && S !== null && typeof S == "number") {
const C = f.context.getCell().toDate();
C && (S = C);
}
g.push(S), d = l.next(), m++;
}
return h;
}, $o = (a, t) => a === t || !(!a || !t) && a.rowStart === t.rowStart && a.rowEnd === t.rowEnd && a.colStart === t.colStart && a.colEnd === t.colEnd && a.$rowStart === t.$rowStart && a.$rowEnd === t.$rowEnd && a.$colStart === t.$colStart && a.$colEnd === t.$colEnd, Mm = (a, t) => {
if (!a) return;
const e = { ...a };
return t ? typeof t == "boolean" ? (e.$colStart = t, e.$rowStart = t, e.$colEnd = t, e.$rowEnd = t, e) : (typeof t.colStart == "boolean" && (e.$colStart = t.colStart), typeof t.rowStart == "boolean" && (e.$rowStart = t.rowStart), typeof t.colEnd == "boolean" && (e.$colEnd = t.colEnd), typeof t.rowEnd == "boolean" && (e.$rowEnd = t.rowEnd), e) : e;
};
class Ga {
constructor(t, e, n) {
const r = this;
this.setState = (o) => {
const s = o[0];
let i = o[1], l = o[2];
if (e && e.includeMergeOverflow && l && l.merge) {
const h = e.bounds, d = l.merge.getCoords();
let u = !1;
const g = d.colStart, m = d.rowStart, f = h.colStart, p = h.rowStart, _ = s.colIndex, S = s.rowIndex;
!u && g < f && m >= p && _ === f && S === m && (u = !0), !u && m < p && g >= f && S === p && _ === g && (u = !0), !u && m < p && g < f && S === p && _ === f && (u = !0), u && (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 = _e(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(Kr);
return o;
}, getCell() {
const o = r._c;
if (!o) throw new Error(Kr);
if (this.ignoreCellDetails) throw new Error("IteratorContext can only return a cell if the forEach ignoreCellDetails has not been set to false.");
const s = r._r, i = r._t, l = r._v;
return l !== null || s ? new er(n, o, i, l, s, r._p, r._n) : new er(n, o);
}, getType: () => r._t, getA1(o) {
if (!r.context) throw new Error(Kr);
let s = r._c;
return o && (s = { ...r._c, ...o }), n.resolveRange(s).toString();
}, toJSDate(o) {
if (r._t !== Y.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 oo(s, n.date1904);
} };
}
}
const Fn = (a, t) => {
if (a || t) return a && t ? { ...a, ...t } : a || t;
}, Bd = (a, t, e, n = F.Orientation.Row) => {
const r = a.getRange(t, { ignoreHidden: n }), o = r.forEach((S, C) => ({ break: C.getCoords() }), { ignoreCellDetails: !0, orientation: n });
if (!o) return;
const s = n === F.Orientation.Row, i = /* @__PURE__ */ new Map();
let l;
const c = /* @__PURE__ */ new Map();
let h = null;
const d = s ? o.rowIndex : o.colIndex;
r.forEach((S, C) => {
const y = C.getCoords(), E = s ? y.colIndex : y.rowIndex;
if ((s ? y.rowIndex : y.colIndex) === d) i.set(E, S), l = C.getType();
else {
const w = C.getType();
l !== w && (h = !0);
}
if (h) return t_;
}, { orientation: n === F.Orientation.Row ? F.Orientation.Column : F.Orientation.Row, ignoreCellDetails: !0, includeEmpty: !0, address: { colStart: t.colStart, rowStart: t.rowStart, colEnd: s ? t.colEnd : t.colStart + 1, rowEnd: s ? t.rowStart + 1 : t.rowEnd } }), h && i.forEach((S, C) => {
c.set(C, S + "");
});
const u = { colStart: o.colIndex, rowStart: o.rowIndex, colEnd: t.colEnd, rowEnd: t.rowEnd };
if (u.colStart > u.colEnd || u.rowStart > u.rowEnd || L.isSingleCell(u)) return null;
const g = Math.min(Math.max(e?.colIndex ?? 0, u.colStart), u.colEnd), m = Math.min(Math.max(e?.rowIndex ?? 0, u.rowStart), u.rowEnd), f = n !== F.Orientation.Row, p = { ...Gr.DefaultRangeOptions, hasHeader: h, orientation: n, offset: f ? m - u.rowStart : g - u.colStart };
let _ = u;
return h && (_ = { colStart: f ? u.colStart + 1 : u.colStart, rowStart: f ? u.rowStart : u.rowStart + 1, colEnd: u.colEnd, rowEnd: u.rowEnd }), { coords: u, options: p, headers: c, sortCoords: _ };
}, zd = (a, t, e = null) => Ur.fromArray(a, (n, r) => {
const o = n?.[1];
if (o == null) return null;
let s = n[0] ?? null;
switch (o) {
case Y.String:
s = t.getById(s);
break;
case Y.Error:
s = pt.getBuiltInById(s);
case Y.RichData:
}
return s;
}, (n, r) => {
const o = _e(n);
let s = n;
switch (o) {
case Y.String:
s = t.add(s);
break;
case Y.Error:
s = s.getCode();
case Y.RichData:
}
return [s, o];
}, e), Pd = (a, t) => {
const e = [], n = t ? F.Orientation.Column : F.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 d = l[h], u = d[0], g = d[1].length - 1, m = { colStart: t ? i : u, rowStart: t ? u : i, colEnd: t ? i : u + g, rowEnd: t ? u + g : i, value: new Ye({ colStart: t ? i : u, rowStart: t ? u : i, colEnd: t ? i : u + g, rowEnd: t ? u + g : i }, n) };
e.push(m);
}
}
return e;
}, Wd = (a, t, e) => {
if (!a || a.length === 0) return null;
const n = a.length;
let r, o = -1;
const s = [], i = t === F.Orientation.Column, l = i ? e.rowStart : e.colStart, c = i ? e.rowEnd : e.colEnd, h = i ? F.Orientations.Column : F.Orientations.Row;
for (let d = 0; d < n; d++) {
const u = a[d], g = u.s;
if (g === void 0) {
o = -1;
continue;
}
const m = u.min, f = u.max;
g !== o || r.colEnd + 1 !== m ? (r = { colStart: i ? m : l, rowStart: i ? l : m, colEnd: i ? f : c, rowEnd: i ? c : f, value: { orientations: h, index: g } }, o = g, s.push(r)) : r.colEnd = f;
}
return s.length === 0 ? null : s;
}, Hd = "Item has been closed. No further operations are allowed.";
class Yi {
constructor(t) {
if (this._emitter = null, this._closed = !1, !t) throw new Error("Anchored.ConstructorOptions is required");
if (this._options = { ...t }, !this._options.initialAnchor) throw new Error("Initial anchor is required");
const e = this;
this._transactions = this._options.transactions ?? new Ze({ transient: !0 }), this._emitter = new he(this, this._transactions), this._updateState({ anchor: this._options.initialAnchor }, { description: t?.createDescription ?? "Create Anchored Item" }), this._options.setContainerShiftCallback?.((n) => e._processContainerShift(n)), this._options.setContainerLayoutCallback?.(() => {
e._processContainerLayout();
}), this._options.setContainerDeleteCallback?.(() => {
e._processContainerDelete();
}), this._options.setContainerProtectionCallback?.(() => {
e._processContainerProtection();
}), this._transactionsRemoveListener = this._transactions.addStateListener(this, { onBeforeCommitStart(n, r, o) {
e._processBeforeCommitStart(n, r, o);
}, onAfterStateChange(n, r, o) {
e._processStateChange(n, r, o), e._processAnchorCoords(), e._emitter.notify("onAnchorCoordsChange");
}, onRestoreOrRevert(n, r, o) {
e._processRestoreOrRevert(n, r, o);
} });
}
_getEmitter() {
return this._emitter;
}
delete(t) {
this._options.deleteFromContainer?.(t);
}
getAnchorCoords() {
return this._getState()?.anchor ?? null;
}
getAnchorType() {
return this._getState()?.anchorType ?? ve.Type.TwoCell;
}
isProtected() {
return this._options.isProtected?.() ?? !1;
}
beginCommit(t) {
return this._beginCommit(t);
}
_getState() {
if (this._closed) throw new Error(Hd);
return this._transactions.getState(this);
}
_beginCommit(t) {
return this._transactions.beginCommit(typeof t == "string" ? { description: t } : t);
}
_getTransactions() {
return this._transactions;
}
_updateState(t, e, n) {
if (this._closed) throw new Error(Hd);
if (!t) return;
const r = this._beginCommit(e?.description);
try {
r.updateState(this, t);
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(t) {
let e = null;
const n = { anchor: t.after };
return t.after || (n.isDeleted = !0, e = ["onDelete"]), this._updateState(n, { description: "Update Anchor" }, e), t.after;
}
_processBeforeCommitStart(t, e, n) {
}
_processStateChange(t, e, n) {
}
_processRestoreOrRevert(t, e, n) {
this._emitter.notify("onInvalidated");
}
_processAnchorCoords() {
}
_processContainerLayout() {
}
_getDescription() {
return null;
}
_delete() {
const t = this._getDescription(), e = "Delete", n = t ? `${e} ${t}` : e, 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(t, e) {
return this._emitter.addListeners(t, e);
}
isClosed() {
return this._closed;
}
_processClose() {
this._closed = !0, this._emitter.notify("onClose"), this._transactionsRemoveListener?.();
}
close() {
this._closed || this._processClose();
}
get isIAnchored() {
return !0;
}
}
var Yr, ar;
(ar = Yr || (Yr = {})).fastStringToCol = K0, ar.fastStringToCell = Wr, ar.fastStringToRange = Ae, ar.rangeToString = kn, ar.cellToString = nr, ar.normalizeA1ToR1C1 = Z0, ar.resolveRelativeToA1 = Q0;
const jS = (a, t) => a.offset - t.offset, Vd = (a) => {
if (!a || a.size === 0) return [];
let t = [];
return a.forEach((e, n) => {
e && Object.keys(e).length !== 0 && t.push({ ...e, offset: n });
}), t.sort(jS);
};
class $S extends Yi {
constructor(t) {
super({ ...t, createDescription: "Insert AutoSort" }), this._apply = t.apply, this._processUpdate = t.processUpdate, this._fromJSON(t.json);
}
getRange() {
return this._getState().anchor;
}
getFieldAt(t) {
const e = this._getState().byOffset.get(t) ?? null;
return e ? Object.keys(e).length === 0 || Object.keys(e).length === 1 && e.hasOwnProperty("offset") ? null : { collatorOptions: null, ...e } : null;
}
insertSort() {
return null;
}
getSort() {
return null;
}
apply(t) {
const e = this._getState().byOffset, n = new Map(e);
for (let r = 0; r < t.length; r++) {
const o = { ...t[r] }, s = o.offset;
delete o.offset, n.set(s, o);
}
return this._updateState({ byOffset: n }, { description: "Set Sort Criteria" }), this.reapply();
}
setFieldAt(t, e) {
const n = this._getState().byOffset, r = new Map(n);
return e && Object.keys(e).length > 0 ? r.set(t, e) : r.delete(t), this._updateState({ byOffset: r }, { description: "Sort" }), this.reapply();
}
_processStateChange(t, e, n) {
super._processStateChange(t, e, n), this._processUpdate?.();
}
reapply() {
const t = this._getState(), e = Vd(t.byOffset);
return this._apply?.(e), this;
}
clear() {
return this._updateState({ byOffset: /* @__PURE__ */ new Map() }, { description: "Clear Sort" }), this.reapply();
}
_fromJSON(t) {
const e = t ?? {}, n = { byOffset: /* @__PURE__ */ new Map() };
if (e.fields) for (let r = 0; r < e.fields.length; r++) {
let o = e.fields[r];
const s = o.offset;
o = { ...e.fields[r] }, delete o.offset, n.byOffset.set(s, o);
}
this._updateState(n, { description: "Load" });
}
toJSON() {
const t = {}, e = this._getState();
e.anchor && (t.ref = Yr.rangeToString(e.anchor, this._options.maxRangeCoords));
const n = Vd(e.byOffset);
return n.length > 0 && (t.fields = n), Object.keys(t).length === 0 ? null : t;
}
}
const GS = (a, t) => a.offset - t.offset, Ua = (a) => {
if (!a || a.size === 0) return [];
let t = [];
return a.forEach((e, n) => {
e && Object.keys(e).length !== 0 && t.push({ ...e, offset: n });
}), t.sort(GS);
}, jd = (a, t = /* @__PURE__ */ new Map()) => {
if (!a || a.length === 0) return t;
for (let e = 0; e < a.length; e++) {
const n = { ...a[e] }, r = n.offset;
delete n.offset, t.set(r, n);
}
return t;
}, qa = (a) => {
let t = 0;
const e = a.entries();
let n = null;
do
n = e.next(), n.value?.[1] && n.value[1].hiddenButton && t++;
while (!n.done);
return t;
};
class Tm extends Yi {
constructor(t) {
super({ ...t, createDescription: "Insert AutoFilter" }), this._apply = t.apply, this._processUpdate = t.processUpdate, t.setFilterCoordsCallback?.((e) => {
this._getState().anchor;
}), this._fromJSON(t.json);
}
getCoords() {
return this._getState().anchor;
}
getFieldAt(t) {
const e = this._getState().byOffset.get(t) ?? null;
return e ? Object.keys(e).length === 0 || Object.keys(e).length === 1 && e.hasOwnProperty("offset") ? null : { hiddenButton: !1, criteria: k.EmptyArray, ...e } : null;
}
insertSort() {
return null;
}
getSort() {
return null;
}
apply(t) {
const e = this._getState().byOffset, n = new Map(e);
return jd(t, n), this._updateState({ byOffset: n, hiddenCount: qa(n) }, { description: "Set Filter Criteria" }), this.reapply();
}
setFieldAt(t, e) {
const n = this._getState(), r = n.anchor.colEnd - n.anchor.colStart + 1;
if (t < 0 || t > r - 1) throw new Error(`Invalid range: '${t}'`);
const o = n.byOffset, s = new Map(o);
e && Object.keys(e).length > 0 ? s.set(t, e) : s.delete(t);
const i = o.get(t)?.hiddenButton === !0 ? 1 : 0, l = e?.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 t = this._getState(), e = t.anchor, n = e.colEnd - e.colStart + 1;
return t.hiddenCount < n;
}
setShowFilterButton(t) {
const e = this.getAnchorCoords(), n = e.colEnd - e.colStart + 1;
let r = Array(n);
const o = this._getState().byOffset, s = Ua(o);
for (let l = 0; s && l < s.length; l++) {
const c = { ...s[l] };
r[c.offset] = c, t ? delete c.hiddenButton : c.hiddenButton = !0;
}
if (!t) 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: t ? i.size : 0 }, { description: (t ? "Hide" : "Show") + " Filter Buttons" }), this._processUpdate?.(), this;
}
_processStateChange(t, e, n) {
super._processStateChange(t, e, n), this._processUpdate?.();
}
_processContainerShift(t) {
if (t.after && t.orientation === F.Orientation.Column) {
let e = t.intersect.colStart - t.before.colStart, n = t.amount;
e <= 0 && (n -= e, e = 0);
const r = this._getState().byOffset, o = new Map(r);
if (r.forEach((s, i) => {
s && Object.keys(s).length !== 0 && (i >= e && o.delete(i), i > e && o.set(i + n, s));
}), n > 0 && this._getState().hiddenCount > 0) for (let s = e; s < e + n; s++) o.set(s, { hiddenButton: !0 });
this._updateState({ byOffset: o, hiddenCount: qa(o), sort: null }, { description: "Update Fields" });
}
return super._processContainerShift(t);
}
reapply() {
const t = this._getState(), e = Ua(t.byOffset);
return this._apply?.(e), this;
}
clear() {
return this._updateState({ byOffset: /* @__PURE__ */ new Map(), hiddenCount: 0, sort: null }, { description: "Set Filter Criteria" }), this.reapply();
}
_fromJSON(t) {
const e = t ?? {}, n = { byOffset: /* @__PURE__ */ new Map(), hiddenCount: 0 };
e.fields && (jd(e.fields, n.byOffset), n.hiddenCount = qa(n.byOffset)), e.sort, this._updateState(n, { description: "Load" });
}
toJSON() {
const t = {}, e = this._getState();
e.anchor && (t.ref = kn(e.anchor, this._options.maxRangeCoords));
const n = Ua(e.byOffset);
return n.length > 0 && (t.fields = n), e.sort, Object.keys(t).length === 0 ? null : t;
}
}
const Vl = "A table must have a least one row for the data.", $d = "Table1", Rs = Object.freeze({ showRowStripes: !0, showColumnStripes: !1, showFirstColumn: !1, showLastColumn: !1 }), Gd = (a, t, e) => {
if (a.length !== t.length) return console.warn("make columns the same length"), !1;
const n = /* @__PURE__ */ new Set();
for (let l = 0; l < t.length; l++) {
const c = t[l]?.name;
c && n.add(c.toLocaleLowerCase());
}
for (let l = 0; e && l < e.length; l++) {
const c = e[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, d, u = 1e3) => {
if (d(l, h = (h ?? "").trim().toLocaleLowerCase())) return l;
for (; o < u; ) try {
const g = c + ++o;
if (d(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 === t[l]?.name) continue;
const h = s(c, a[l]?.name || "Column", t[l]?.name, r);
n.add(h.toLocaleLowerCase()), t[l]?.name !== h && (a[l].name = h, i++);
}
return i > 0;
};
class US {
constructor(t, e, n, r) {
this._name = t, this._filter = e, this._sort = n, this._offset = r;
}
getName() {
return this._name;
}
getField() {
return this._filter ? this._filter.getFieldAt(this._offset) ?? null : null;
}
setField(t) {
return this._filter ? (this._filter.setFieldAt(this._offset, t), this) : this;
}
getSortField() {
return this._sort ? this._sort.getFieldAt(this._offset) : null;
}
setSortField(t) {
return this._sort ? (this._sort.setFieldAt(this._offset, t), 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 qS extends Vg {
constructor(t, e, n, r) {
super({ ...r, type: "namedTable" }), this._names = t, this._sheet = e, 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(t) {
return await this._table.select(t), 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 JS extends Yi {
constructor(t) {
if (super({ ...t, 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, !t.json) throw new Error("json is required");
if (!t.json.ref) throw new Error("json.ref is required");
const e = this;
this._styles = t.styles ?? t.sheet?.getStyles() ?? new cs(), this._names = t.names, this._sheet = t.sheet, this._processTableUpdate = t.processTableUpdate, this._setNameOnContainer = t.setNameOnContainer, this._options = { ...t }, this._styleCache = null, this._stylePropsCache = null, this._stylesRemoveListener = this._styles.addListeners({ onTableStylesChange() {
e._styleCache = null, e._stylePropsCache = null, e._getEmitter().notify("onStyleChange"), e._getEmitter().notify("onAnyChange");
} });
const n = { ...t?.json };
if (t.sheet) {
const r = t.sheet;
if (this._autoExpandRemoveListener = r.getEntireRange().addListener((i) => {
if (i.trigger !== "setCells" || i.isUndo) return;
const l = e.getAnchorCoords();
if (!l) return;
const c = i.getFrom().getCoords()[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 d = { ...c, colStart: l.colEnd + 1 };
if (r.getRange(d).isContentful()) {
const u = { ...d, rowStart: l.rowStart, rowEnd: d.rowStart - 1 };
if (u.rowEnd - u.rowStart < 0 || !r.getRange(u).isContentful()) {
const g = { ...d, rowStart: d.rowEnd + 1, rowEnd: l.rowEnd };
(g.rowEnd - g.rowStart < 0 || !r.getRange(g).isContentful()) && (h = { ...l, colEnd: c.colEnd });
}
}
} else if (!e.getShowTotals() && c.colStart >= l.colStart && c.colEnd <= l.colEnd && c.rowStart >= l.rowStart && c.rowStart <= l.rowEnd + 1 && c.rowEnd > l.rowEnd) {
const d = { ...c, rowStart: l.rowEnd + 1 };
if (r.getRange(d).isContentful()) {
const u = { ...d, colStart: l.colStart, colEnd: d.colStart - 1 };
if (u.colEnd - u.colStart < 0 || !r.getRange(u).isContentful()) {
const g = { ...d, colStart: d.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 d = e._beginCommit("Table Auto Expansion");
try {
e.resize(h), d.commit({ viewAfter: null });
} catch (u) {
d.rollback(), console.warn("Unable to AutoExpand"), console.warn(u);
}
}
}, { transactional: !1, ignoreShifts: !0 }), this._headerValueListener = () => {
if (this._isUpdatingHeader) return;
const i = this._columnsFromSheet();
i && this._updateColumns(i.columns, !1, i.forceUpdate, null);
}, t.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(), d = r.getRowHeaders(), u = h.findVisibleIndex(i.colStart).max, g = d.findVisibleIndex(i.rowStart).max;
this._visibleRange = { colStart: u, colEnd: l, rowStart: g, rowEnd: c }, this._isHeaderVisible = !d.at(i.rowStart).isHidden(), this._isTotalVisible = !d.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(t) {
const e = this.toJSON(), n = this.getAnchorCoords(), r = this.getName(), o = { ...e };
delete o.ref;
const s = this, i = Object.freeze({ ...t });
let l = !1;
return { async copyTo(c, h) {
const d = c.tables, u = c.range;
({ ...i, ...h }).isCut && !l && (s.delete(), l = !0);
const g = { colStart: u.colStart, rowStart: u.rowStart, colEnd: n.colEnd - n.colStart + u.colStart, rowEnd: n.rowEnd - n.rowStart + u.rowStart };
return d.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 ve.Type.TwoCell;
}
getStyle() {
if (this._styleCache) return this._styleCache;
const t = this._getState();
return t ? (this._styleCache = this._styles.getTableStyle(t.styleOptions.name) ?? this._styles.getDefaultTableStyle(), this._styleCache) : this._styles.getTableStyle(null);
}
addRows(t, e = 1) {
const n = { ...this._getState().anchor };
return n.rowEnd += e, this._modifyTable({ anchor: n }, "Add Table Row" + (e > 1 ? "s" : "")), this;
}
deleteRowsAt(t, e = 1) {
let n = { ...this._getState().anchor };
return n.rowEnd -= e, n.rowEnd < n.rowStart && (n = null), this._modifyTable({ anchor: n }, "Delete Table Row" + (e > 1 ? "s" : "")), this;
}
addColumn(t, e) {
const n = this._getState(), r = { ...n.anchor };
r.colEnd += 1;
const o = [], s = { name: `${e ?? n.columns[t - 1]?.name ?? `Column${t + 1}`}3` };
o.push(s);
const i = [...n.columns.slice(0, t), ...o, ...n.columns.slice(t)];
return this._modifyTable({ anchor: r, columns: i }, "Add Table Column"), s;
}
getColumns() {
return this._getState()?.columns;
}
convertToRange(t = Number.MAX_SAFE_INTEGER) {
let e = 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 > t) throw new Error(`There are ${r} and there is a limit of ${t}.`);
const o = this._sheet.getRange(n), s = o.startIncrementalUpdates({ orientation: F.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: F.Orientation.Column }), s.apply();
}
this.delete();
} catch {
e.rollback(), e = null;
}
return e && e.commit(), this._sheet.getRange(this._getState()?.anchor);
}
resize(t, e = "Resize Table") {
let n = this._sheet.getRange(t).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(e);
try {
n = this._options.setContainerCoords(t), L.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(t) {
const e = this._beginCommit(`Set Table Name '${t}'`);
try {
this._modifyTable({ name: t }), e.commit();
} catch (n) {
throw e.rollback(), n;
}
return this;
}
getDescription() {
return this._getState()?.description;
}
setDescription(t) {
return this._modifyTable({ description: t });
}
select(t) {
return this.getUsedRange().select(t);
}
getRange() {
return this._range ? this._range : this._getState() ? this._range = this._sheet.getRange(this._getState().anchor) : Qn;
}
_processRestoreOrRevert(t, e, n) {
this._styleCache = null, super._processRestoreOrRevert(t, e, n);
}
_processAnchorCoords() {
this._range = null, super._processAnchorCoords();
}
getUsedRange() {
const t = this._getUsedCoords();
return t ? this._sheet.getRange(t) : Qn;
}
_getUsedCoords() {
const t = this._getState(), e = t.headerRowCount, n = t.totalsRowCount, r = t.anchor;
if (!r) return null;
const o = { ...r, rowStart: r.rowStart + e, rowEnd: r.rowEnd - n };
return o.rowEnd < o.rowStart || o.colEnd < o.colStart ? null : o;
}
getHeaderRange() {
const t = this._getHeaderCoords();
return t ? this._sheet.getRange(t) : Qn;
}
_getHeaderCoords() {
const t = this._getState(), e = t.headerRowCount;
if (e < 1) return null;
const n = t.anchor;
return n ? { ...n, rowEnd: n.rowStart + e - 1 } : null;
}
getTotalRange() {
const t = this._getTotalCoords();
return t ? this._sheet.getRange(t) : Qn;
}
_getTotalCoords() {
const t = this._getState(), e = t.totalsRowCount;
if (e < 1) return null;
const n = t.anchor;
return n ? { ...n, rowStart: n.rowEnd - e + 1 } : null;
}
getStyleOptions() {
return this.isClosed() ? Rs : this._getState()?.styleOptions;
}
updateStyleOptions(t, e = "Update Style Info") {
const n = this.getStyleOptions(), r = t ? { ...n, ...t } : Rs;
return this._modifyTable({ styleOptions: r }, e), this._styleCache = null, this._getEmitter().notify("onStyleChange"), this;
}
getStyleAt(t) {
let e = this._stylePropsCache;
return e || (e = this.getStyle().getRanged(this), this._stylePropsCache = e), no(this._styles, e, L.cellToRange(t));
}
getShowTotals() {
return this._getState()?.totalsRowCount > 0;
}
setShowTotals(t) {
return this._modifyTable({ totalsRowCount: t ? 1 : 0 }, "Toggle Show Totals");
}
getShowHeaders() {
return this._getState()?.headerRowCount > 0;
}
setShowHeaders(t) {
return this._modifyTable({ headerRowCount: t ? 1 : 0 }, "Toggle Show Headers");
}
getShowFilterButton() {
const t = this.getFilter();
return !!t && t.getShowFilterButton();
}
setShowFilterButton(t) {
const e = this.getFilter();
return e ? (e.setShowFilterButton(t), 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(t) {
const e = this;
return new Tm({ initialAnchor: this._getUsedCoords(), maxRangeCoords: this._options.maxRangeCoords, json: t, transactions: this._getTransactions(), setContainerShiftCallback(n) {
e._filterShiftCallback = n;
}, setFilterCoordsCallback(n) {
e._filterCoordsCallback = n;
}, deleteFromContainer: (n) => {
this._updateState({ filter: null }, { description: n?.description ?? "Delete Filter" }), e._processUpdate?.();
}, apply: (n) => {
e._applyFilterAndSort();
}, processUpdate: () => {
e._processUpdate?.();
}, isProtected: () => e.isProtected() });
}
insertFilter() {
let t = this.getFilter();
return t || (t = this._createFilter(), this._updateState({ filter: t }, { description: "Insert Filter" }), t);
}
getFilter() {
return this._getState()?.filter ?? null;
}
_createSort(t) {
const e = this;
return new $S({ initialAnchor: this._getUsedCoords(), maxRangeCoords: this._options.maxRangeCoords, json: t, transactions: this._getTransactions(), deleteFromContainer: (n) => {
this._updateState({ sort: null }, { description: n?.description ?? "Delete Sort" }), e._processUpdate?.();
}, apply: (n) => {
e._applyFilterAndSort();
}, processUpdate: () => {
e._processUpdate?.();
}, isProtected: () => e.isProtected() });
}
insertSort() {
let t = this.getSort();
return t || (t = this._createSort(), this._updateState({ sort: t }, { description: "Insert Sort" }), t);
}
getSort() {
return this._getState()?.sort ?? null;
}
getColumnFilter(t) {
const e = this.getFilter();
if (!e) return null;
const n = this.getSort();
let r = null;
return r = this._getState()?.columns[t], r === null ? null : new US(r.name, e, n, t);
}
getVisibleRefRangeCoords() {
return this._visibleRange ? this._visibleRange : this.getAnchorCoords();
}
getVisibleCellCoords(t) {
return t && this._visibleRange ? { colIndex: Math.min(this._visibleRange.colEnd, Math.max(this._visibleRange.colStart, this._sheet.getColumnHeaders().findVisibleIndex(t.colIndex).min)), rowIndex: Math.min(this._visibleRange.rowEnd, Math.max(this._visibleRange.rowStart, this._sheet.getRowHeaders().findVisibleIndex(t.rowIndex).min)) } : t;
}
isHeaderVisible() {
return this._isHeaderVisible;
}
isTotalVisible() {
return this._isTotalVisible;
}
isFirstColumnVisible() {
return this._isFirstColumnVisible;
}
isLastColumnVisible() {
return this._isLastColumnVisible;
}
_columnsFromSheet() {
const t = this._getHeaderCoords();
if (!t || !this._sheet) {
const n = this.getAnchorCoords();
return { columns: n ? Array(n.colEnd - n.colStart + 1).fill(null) : [], forceUpdate: !0 };
}
const e = { columns: [], forceUpdate: !1 };
return this._sheet.getRange({ ...t, rowEnd: t.rowStart }).forEach((n, r) => {
const o = r.getCell();
e.columns.push({ name: o.toText() }), e.forceUpdate = e.forceUpdate || o.getType() !== Y.String;
}, { includeEmpty: !0 }), e;
}
_updateColumns(t, e, n = !1, r) {
if (this._isUpdatingHeader) return;
const o = this._getHeaderCoords(), s = this._getUsedCoords(), i = [];
if (s) {
const u = s.colEnd - s.colStart + 1;
for (let g = 0; g < u; g++) {
const m = t[g];
i.push({ ...m });
}
}
let l = !1;
const c = this._getState().columns;
if (l = e ? ((u, g) => {
const m = /* @__PURE__ */ new Set(), f = (S) => !!S && !m.has(S.toLocaleLowerCase()), p = (S, C, y, E) => E(S) ? S : C + (y + 1);
let _ = 0;
for (let S = 0; S < u.length; S++) {
const C = p(u[S]?.name || g[S]?.name, u[S]?.name || "Column", _, f);
m.add(C.toLocaleLowerCase()), u[S]?.name !== C && (u[S].name = C, _++);
}
return _ > 0;
})(i, c) : Gd(i, c, r), !(n || c.length !== i.length || l)) return;
const h = "Update Columns";
this._isUpdatingHeader = !0;
let d = this._beginCommit(h);
try {
if (this._updateState({ columns: i }, { description: h }), this._sheet && o) {
const u = this._sheet.getEntireRange().startIncrementalUpdates({ orientation: F.Orientation.Row });
for (let g = 0; g < i.length; g++) {
const m = i[g].name;
u.pushAt(o.rowStart, o.colStart + g, m);
}
u.apply({ textParser: !1 });
}
} catch {
d.rollback();
}
return d && d.commit(), this._isUpdatingHeader = !1, i;
}
_processDelete() {
this._getState().headerRemoveListener?.(), this._updateState({ headerRemoveListener: null }), super._processDelete();
}
_processFilterUpdate() {
const t = this._getUsedCoords();
console.log("process on Filter and Sort dataRange", t);
}
_processContainerShift(t) {
if (t.isSplit) throw new Error("We can not partially insert or remove cells as this would split a table.");
const e = this._getState();
if (t.after && t.after.rowStart + e.headerRowCount >= t.after.rowEnd + 1) throw new Error(Vl);
const n = t.orientation === F.Orientation.Column;
if (t.amount < 0 && t.after && !n) {
const o = this._getHeaderCoords();
if (o && t.intersect.rowStart <= o.rowEnd && t.intersect.rowEnd >= o.rowStart) throw new Error("We can not remove rows that contain table headers. Remove the table header.");
}
const r = super._processContainerShift(t);
if (n) {
let o = t.amount, s = t.intersect.colStart - t.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 d = /* @__PURE__ */ new Set();
for (let p = 0; p < i.length; p++) d.add(i[p]?.name?.toLowerCase().trim());
const u = i[s - 1], g = u?.name?.match(/\d+$/);
let m = null, f = 0;
g && (m = g.input.substring(0, g.index), f = parseInt(g[0]));
for (let p = 0; p < o; p++) {
let _ = { ...u };
c[s + p] = _;
const S = m + (f + p + 1);
S && !d.has(S.toLowerCase().trim()) && (_.name = S);
}
Gd(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 t.after || this._updateState({ columns: [] }, { description: "Process Columns" });
return t.after || this._delete(), this._filterShiftCallback && this._filterShiftCallback({ ...t, after: this._getUsedCoords() }), r;
}
_modifyTable(t, e = "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(e);
try {
if (this._updateState(t), t.name !== void 0) {
if (!t.name) throw new Error("Table must have a name.");
this._setNameOnContainer?.(t.name);
}
let l = t.anchor ?? null;
if ((t.anchor !== void 0 || t.headerRowCount !== void 0 || t.totalsRowCount !== void 0) && t.headerRowCount !== void 0 && o !== t.headerRowCount) if (t.headerRowCount > o) {
const c = r.rowStart - (t.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 + t.headerRowCount, rowEnd: r.rowStart + t.headerRowCount }).insert(F.Orientation.Row), l = { ...r, rowEnd: r.rowEnd + (t.headerRowCount - o) }) : l = { ...r, rowStart: r.rowStart + (o - t.headerRowCount) };
} else s && this._sheet && this._sheet.doBatch(() => {
this._sheet.getRange(s).clear();
}, {}), l = { ...r, rowStart: r.rowStart + (o - (t.headerRowCount ?? o)) };
if (l) {
let c = n.columns;
const h = t.headerRowCount !== void 0 && t.headerRowCount !== n.headerRowCount || t.totalsRowCount !== void 0 && t.totalsRowCount !== n.totalsRowCount, d = l.colStart !== r.colStart || l.colEnd !== r.colEnd;
let u = [];
if (d) {
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 && (u = 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 && (u = u.concat(g.splice(0, l.colStart - r.colStart))), c = g;
}
if (this._options.setContainerCoords?.(l), this._updateState({ anchor: l, columns: c }, { description: e }), !this._getUsedCoords()) throw new Error(Vl);
if (d || h) {
const g = h ? { columns: c, forceUpdate: !0 } : this._columnsFromSheet();
g && (this._updateColumns(g.columns, !1, g.forceUpdate, u), this._processHeaderListener());
}
this._filterCoordsCallback?.(l);
}
t.styleOptions !== void 0 && (this._styleCache = null), this._getEmitter().notify("onAnyChange"), i.commit();
} catch (l) {
throw i.rollback(), l;
}
return this;
}
addListeners(t, e) {
return this._emitter.addListeners(t, e);
}
_processStateChange(t, e, n) {
super._processStateChange(t, e, n), this._styleCache = null, this._stylePropsCache = null, this._processTableUpdate?.(), this._getEmitter().notify("onAnyChange");
}
_processHeaderListener() {
if (this._getState().headerRemoveListener?.(), this._sheet) {
let e = this._getHeaderCoords();
if (!e) {
const r = this._getUsedCoords();
e = { ...r, rowEnd: r.rowStart };
}
const n = this._sheet.getRange(e).addListener(this._headerValueListener, { transactional: !0 });
this._updateState({ headerRemoveListener: n });
}
}
get [Symbol.toStringTag]() {
return "[Table]";
}
toString() {
return this.getName() ?? "";
}
toJSON() {
const t = {}, e = this._getState();
if (!e) return null;
if (e.name && (t.name = e.name), e.anchor && (t.ref = kn(e.anchor, this._options.maxRangeCoords)), e.description && (t.description = e.description), e.headerRowCount !== 1 && (t.headerRowCount = e.headerRowCount), e.totalsRowCount !== 0 && (t.totalsRowCount = e.totalsRowCount), e.columns && (t.columns = [...e.columns]), e.styleOptions) {
const n = k.diffValues(e.styleOptions, { ...Rs, name: null });
n && (t.styleOptions = n);
}
if (e.filter) {
const n = e.filter.toJSON();
n && (t.filter = n, delete t.filter.ref);
}
return t;
}
_createNamed() {
return this._sheet?.getName() && this._names ? new qS(this._names, this._sheet, this, { transactions: this._getTransactions(), json: { name: this.getName() } }) : null;
}
_fromJSON(t) {
const e = t ?? {}, n = { headerRowCount: 1, totalsRowCount: 0 };
var r;
if (e.name && (n.name = e.name), e.ref && (e.ref = (r = e.ref) && typeof r == "string" ? Pe(r) : r), this._names) {
const i = this._names.findValidName(n.name ?? $d);
n.name !== i && (n.name = i);
}
n.name || (n.name = $d), e.description && (n.description = e.description), e.headerRowCount !== void 0 && (n.headerRowCount = e.headerRowCount), e.totalsRowCount !== void 0 && (n.totalsRowCount = e.totalsRowCount), n.columns = e.columns ?? k.EmptyArray, n.styleOptions = { ...Rs, ...e.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), e.sort && (n.sort = this._createSort(e.sort)), e.filter && (n.filter = this._createFilter(e.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 Ie = null;
const yo = "TableStyleMedium2", Ue = (a, t, e) => {
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, t, e), r = a;
return n !== a.border && (r = { ...a }, Object.keys(n).length > 0 ? r.border = n : delete r.border), r;
};
class KS {
constructor(t, e, n) {
this._table = t, this._styles = e, this._properties = n;
}
_resolveProperties(t) {
const e = { name: t.name }, n = this._styles, r = Object.values(gr.ElementType), o = r.length;
for (let s = 0; s < o; s++) {
const i = r[s], l = t[i];
if (!l || !k.isObject(l)) continue;
const c = Yt.resolveTypedUpdates(Object.freeze(l), Qt, n);
e[i] = c;
}
return Object.freeze(e);
}
getCoords() {
return this._table.getAnchorCoords();
}
getPropertiesAt(t, e) {
const n = this._table, r = this._styles, o = this._properties;
Ja.rowIndex = t, Ja.colIndex = e;
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), d = Math.max(0, s.colIndex - i.colStart), u = { rowIndex: h, colIndex: d }, g = n.getStyleOptions();
let m = {}, f = !1, p = 0;
n.isHeaderVisible() && (p = n.getShowHeaders() ? 1 : 0, f = p > h);
let _ = !1, S = 0;
n.isTotalVisible() && (S = n.getShowTotals() ? 1 : 0, _ = c - S <= h);
let C = d === l - 1 && g.showLastColumn;
n.isLastColumnVisible() || (C = !1);
let y = d === 0 && g.showFirstColumn;
n.isFirstColumnVisible() || (y = !1);
const E = !f && !_;
if (o.wholeTable && (m = o.wholeTable, m.border && (m = Ue(m, u, { rowStart: 0, rowEnd: c - 1, colStart: 0, colEnd: l - 1 }))), E && g.showColumnStripes) {
const w = o.firstColumnStripe?.size ?? 1, b = o.secondColumnStripe?.size ?? 1;
let v = d % (w + b);
const I = v < w;
I || (v -= w);
let x = I ? o.firstColumnStripe : o.secondColumnStripe;
if (x) {
let R = x, A = x.border;
if (A) {
const M = { rowIndex: h, colIndex: v }, T = { rowStart: p, rowEnd: c - S - 1, colStart: 0, colEnd: Math.min(l - d, I ? w : b) };
R = Ue(R, M, T), I && v === 0 && d > 0 && A?.left && o.secondColumnStripe?.border.right && (A = { ...R.border }, R.border = A, A.left = null), I && v === w - 1 && d < l - 1 && A?.right && o.secondColumnStripe?.border.left && (A = { ...R.border }, R.border = A, A.right = null);
}
m = Yt.resolveTypedUpdates(R, Qt, r, m);
}
}
if (E && g.showRowStripes) {
const w = p, b = c - S - 1, v = o.firstRowStripe?.size ?? 1, I = o.secondRowStripe?.size ?? 1;
let x = (h - w) % (v + I);
const R = x < v;
R || (x -= v);
let A = R ? o.firstRowStripe : o.secondRowStripe;
if (A) {
let M = A, T = A.border;
if (T) {
const O = { colIndex: d, rowIndex: x }, W = { colStart: 0, colEnd: l - 1, rowStart: 0, rowEnd: Math.min(c - h, R ? v : I) };
M = Ue(M, O, W), R && x === 0 && h >= w && A.border?.top && o.secondRowStripe?.border.bottom && (T = { ...M.border }, M.border = T, T.top = null);
const D = A.border?.bottom;
(D && R && x === v - 1 && h < b && o.secondRowStripe?.border.top || D && h === b) && (T = { ...M.border }, M.border = T, T.bottom = null);
}
m = Yt.resolveTypedUpdates(M, Qt, r, m);
}
}
if (C && o.lastColumn) {
let w = o.lastColumn;
w.border && (w = Ue(w, u, { rowStart: 0, rowEnd: c - 1, colStart: l - 1, colEnd: l - 1 })), m = Yt.resolveTypedUpdates(w, Qt, r, m);
}
if (y && o.firstColumn) {
let w = o.firstColumn;
w.border && (w = Ue(w, u, { rowStart: 0, rowEnd: c - 1, colStart: 0, colEnd: 0 })), m = Yt.resolveTypedUpdates(w, Qt, r, m);
}
if (f && o.headerRow) {
let w = o.headerRow;
w.border && (w = Ue(w, u, { rowStart: 0, rowEnd: p - 1, colStart: 0, colEnd: l - 1 })), m = Yt.resolveTypedUpdates(w, Qt, r, m);
}
if (_ && o.totalRow) {
let w = o.totalRow;
w.border && (w = Ue(w, u, { rowStart: c - S, rowEnd: c - 1, colStart: 0, colEnd: l - 1 })), m = Yt.resolveTypedUpdates(w, Qt, r, m);
}
if (f && y && o.firstHeaderCell) {
let w = o.firstHeaderCell;
w.border && (w = Ue(w, u, { rowStart: 0, rowEnd: p - 1, colStart: 0, colEnd: 0 })), m = Yt.resolveTypedUpdates(w, Qt, r, m);
}
if (f && C && o.lastHeaderCell) {
let w = o.lastHeaderCell;
w.border && (w = Ue(w, u, { rowStart: 0, rowEnd: p - 1, colStart: l - 1, colEnd: l - 1 })), m = Yt.resolveTypedUpdates(w, Qt, r, m);
}
if (_ && y && o.firstTotalCell) {
let w = o.firstTotalCell;
w.border && (w = Ue(w, u, { rowStart: c - S, rowEnd: c - 1, colStart: 0, colEnd: 0 })), m = Yt.resolveTypedUpdates(w, Qt, r, m);
}
if (_ && C && o.lastTotalCell) {
let w = o.lastTotalCell;
w.border && (w = Ue(w, u, { rowStart: c - S, rowEnd: c - 1, colStart: l - 1, colEnd: l - 1 })), m = Yt.resolveTypedUpdates(w, Qt, r, m);
}
return f && o.headerRow && n.getColumnFilter(d) && !n.getColumnFilter(d).hasHiddenButton() && (m.insets = { right: 15 }), m;
}
}
class Ud {
constructor(t, e, n, r) {
this._styles = t, this._isBuiltIn = n, this._doDelete = r, this._properties = k.deepFreeze(this._resolveProperties(e)), this.isShownInTableStyles();
}
_resolveProperties(t) {
const e = { name: t.name };
t.table !== void 0 && (e.table = t.table), t.pivot !== void 0 && (e.pivot = t.pivot);
const n = this._styles, r = Object.values(gr.ElementType), o = r.length;
for (let s = 0; s < o; s++) {
const i = r[s], l = t[i];
if (!l || !k.isObject(l)) continue;
const c = Yt.resolveTypedUpdates(Object.freeze(l), Qt, n);
e[i] = c;
}
return Object.freeze(e);
}
delete() {
if (!this._doDelete) throw new Error("Not able to delete builtin style.");
this._doDelete(this._properties.name);
}
getRanged(t) {
return new KS(t, 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 t = k.cloneObject(this._properties);
return t.name = this._properties.name, t;
}
get isITableStyle() {
return !0;
}
}
const Ja = { rowIndex: 0, colIndex: 0 };
class XS extends oe {
constructor(t, e) {
super(t, L.EmptyRange, e);
}
isEmpty() {
return this._p === null;
}
getCoords() {
return this._r;
}
cloneWithUpdate(t) {
if (t === void 0) return this;
const e = this._c, n = this._r, r = Yt.resolveTypedUpdates(t, Qt, e, this._p);
return new oe(e, n, r);
}
_createShifted(t) {
return new oe(this._c, t, this._p);
}
getShifted(t) {
return t.after ? { ...t.after, value: this._createShifted(L.sanitizeRange(t.after)) } : null;
}
getSplit(t, e) {
const n = this._c, r = this._p;
return [new oe(n, t[0], r), new oe(n, t[1], r)];
}
getMerged(t, e, n) {
const r = this._p, o = t._p;
if (r && !o || o && !r || !r && !o) return;
let s = Object.keys(r), i = Object.keys(o);
if (r.named === mt.BuiltInName.Normal && (s = s.filter((c) => c.toLowerCase() !== mt.BuiltInName.Normal)), o.named === mt.BuiltInName.Normal && (i = i.filter((c) => c.toLowerCase() !== mt.BuiltInName.Normal)), s.length !== i.length) return;
for (let c = 0; c < s.length; c++) {
const h = s[c], d = r[h], u = o[h];
if (!k.deepEqual(d, u)) return;
}
const l = this._c;
return new oe(l, e, this._p);
}
getPropertiesAt(t, e) {
return this._p;
}
toJSON() {
return k.toSafeJSON(this._p);
}
}
class qd {
constructor(t, e, n, r = null) {
this._name = e.name, this._properties = e, this._rangeStyle = new XS(t, e.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 ? k.toSafeJSON(this._properties) : null;
}
get isINamed() {
return !0;
}
}
let YS = class {
constructor(a, t, e, n, r) {
this._state = a, this._normalJSON = t ?? {}, this._toJSONInternal = e, this._fromJSONInternal = n, this._onLastEnd = r, this._state.openScopes.add(this), this._isClosed = !1, this._state.byJSONs.set(ea(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 t = ea(a = a ?? {});
let e = this._state.byJSONs.get(t);
return e !== void 0 || (e = this._state.byJSONs.size, this._state.byJSONs.set(t, e), this._state.byIds.set(e, a)), e;
}
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 t = JSON.parse(JSON.stringify(a || {}));
this._fromJSONInternal(t);
const e = t.direct, n = e ? e.length : 0;
for (let r = 0; r < n; r++) {
const o = r, s = e[r], i = ea(s);
this._state.byIds.set(o, s), this._state.byJSONs.set(i, o);
}
}
toJSON() {
if (this._isClosed) throw new Error("PersistScope is closed.");
const a = [];
return this._state.byIds.forEach((t, e) => {
a[e] = t;
}), a.length === 1 && a.splice(0, 1), this._toJSONInternal(a);
}
};
class cs {
constructor(t = null, e = null, n = 11) {
this._emitter = null, this._normalRanged = null, this._theme = t ?? new Hg().getDefaultTheme(), this._defaultFontSize = n;
const r = this;
this._emitter = new he(this), this._schemeLookup = (o) => r._theme.schemeLookup()(o), this._indexedColors = this._fromJSONIndexedColors(e), this._indexedLookup = (o) => {
const s = this._indexedColors[o];
return s ? s.toRGBA() : Ei(o);
}, this._initializeBuiltIns(), this._customCellStyles = /* @__PURE__ */ new Map(), this._customTableStyles = /* @__PURE__ */ new Map(), this._indexedColors = [], this._mruColors = [], this._persistCache = null;
}
_initializeNamedStyles(t, e) {
const n = t ? t.length : 0;
for (let r = 0; r < n; r++) {
const o = t[r], s = { ...o }, i = o.named;
delete s.named;
const l = Yt.resolveTypedUpdates(s, Qt, this), c = new qd(this, { name: i, style: l }, this._hideOrRemoveNamed.bind(this), r);
i === mt.BuiltInName.Normal && (this._normalRanged = c.getRanged(), this._normalStyle = no(this, null)), e.set(i.toLowerCase(), c);
}
}
_initializeTableStyles() {
const t = (() => {
if (Ie) return Ie;
Ie = /* @__PURE__ */ new Map();
const n = (d, u) => {
if (u === 0) return "TableStyleNone";
let g = "Custom";
return d === "l" ? g = "Light" : d === "m" ? g = "Medium" : d === "d" && (g = "Dark"), `TableStyle${g}${u}`;
}, r = (d, u = 0) => u === 0 ? d : u > 0 ? `${d} lumMod ${100 - u}, lumOff ${u}` : u < 0 ? `${d} lumMod ${100 + u}` : void 0, o = (d) => ({ type: st.Type.Pattern, patternType: st.BuiltInSheetPattern.Solid, foreground: d, background: d }), s = (d, u = !1) => {
const g = { fill: d };
return u && (g.weight = 700), g;
}, i = (d, u = U.StrokeStyle.Thin) => ({ style: u, color: d }), l = (d, u) => {
for (let g = 0; g < 7; g++) d.push(u(`accent${g + 1}`));
};
let c = 0, h = [];
h.push(["dk1", r("bg1", -15), "dk1"]), l(h, (d) => [r(d, -25), r(d, 80), d]), c = 1;
for (let d = 0; d < 7; d++) {
const u = n("l", d + c), g = h[d][0], m = h[d][1] ?? g, f = h[d][2] ?? g;
Ie.set(u.toLocaleLowerCase(), Object.freeze({ name: u, 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, (d) => ["dk1", d, "lt1"]);
for (let d = 0; d < 7; d++) {
const u = n("l", d + c), g = h[d][0], m = h[d][1], f = h[d][2];
Ie.set(u.toLocaleLowerCase(), Object.freeze({ name: u, 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, (d) => [d, r(d, 80)]);
for (let d = 0; d < 7; d++) {
const u = n("l", d + c), g = "dk1", m = h[d][0], f = h[d][1];
Ie.set(u.toLocaleLowerCase(), Object.freeze({ name: u, 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, (d) => [d, r(d, 40), r(d, 80)]);
for (let d = 0; d < 7; d++) {
const u = n("m", d + c), g = "dk1", m = "lt1", f = h[d][0], p = h[d][1], _ = h[d][2];
Ie.set(u.toLocaleLowerCase(), Object.freeze({ name: u, wholeTable: { font: s(g), border: { left: i(p), right: i(p), top: i(p), bottom: i(p), horizontal: i(p) } }, 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(_) }, firstColumnStripe: { fill: o(_) } }));
}
c += 7, h = [], h.push(["dk1", r("bg1", -15), r("bg1", -35)]), l(h, (d) => [d, r(d, 80), r(d, 60)]);
for (let d = 0; d < 7; d++) {
const u = n("m", d + c), g = "dk1", m = "lt1", f = h[d][0], p = h[d][1], _ = h[d][2];
Ie.set(u.toLocaleLowerCase(), Object.freeze({ name: u, wholeTable: { font: s(g), fill: o(p), 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(_) }, firstColumnStripe: { fill: o(_) } }));
}
c += 7, h = [], h.push(["dk1", r("bg1", -15), r("bg1", -35)]), l(h, (d) => [d, r(d, 80), r(d, 60)]);
for (let d = 0; d < 7; d++) {
const u = n("m", d + c), g = "dk1", m = "lt1", f = h[d][0], p = r("bg1", -15);
Ie.set(u.toLocaleLowerCase(), Object.freeze({ name: u, wholeTable: { font: s(g), border: { top: i(g, U.StrokeStyle.Medium), bottom: i(g, U.StrokeStyle.Medium), left: d === 0 ? i(g, U.StrokeStyle.Thin) : void 0, right: d === 0 ? i(g, U.StrokeStyle.Thin) : void 0, horizontal: d === 0 ? i(g, U.StrokeStyle.Thin) : void 0, vertical: d === 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(p) }, firstColumnStripe: { fill: o(p) } }));
}
c += 7, h = [], h.push(["dk1", r("bg1", -15), r("bg1", -35), "dk1"]), l(h, (d) => [d, r(d, 80), r(d, 60), r(d, 40)]);
for (let d = 0; d < 7; d++) {
const u = n("m", d + c), g = "dk1", m = h[d][0], f = h[d][1], p = h[d][2], _ = h[d][3];
Ie.set(u.toLocaleLowerCase(), Object.freeze({ name: u, wholeTable: { font: s(g), fill: o(f), border: { top: i(_), right: i(_), left: i(_), bottom: i(_), vertical: i(_), horizontal: i(_) } }, 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(p) }, firstColumnStripe: { fill: o(p) } }));
}
c = 1, h = [], h.push(["dk1", r("dk1", 15), r("dk1", 25), r("dk1", 50)]), l(h, (d) => ["dk1", r(d, -50), r(d, -25), d]);
for (let d = 0; d < 7; d++) {
const u = n("d", d + c), g = "lt1", m = h[d][0], f = h[d][1], p = h[d][2], _ = h[d][3];
Ie.set(u.toLocaleLowerCase(), Object.freeze({ name: u, wholeTable: { font: s(g), fill: o(_) }, 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(p), border: { right: i(g, U.StrokeStyle.Medium) } }, lastColumn: { font: s(g, !0), fill: o(p), border: { left: i(g, U.StrokeStyle.Medium) } }, firstRowStripe: { fill: o(p) }, firstColumnStripe: { fill: o(p) } }));
}
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 d = 0; d < 4; d++) {
const u = n("d", d + c), g = "dk1", m = "lt1", f = h[d][0], p = h[d][1], _ = h[d][2];
Ie.set(u.toLocaleLowerCase(), Object.freeze({ name: u, wholeTable: { font: s(g), fill: o(f) }, headerRow: { font: s(m, !0), fill: o(p) }, 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(_) }, firstColumnStripe: { fill: o(_) } }));
}
return Ie;
})(), e = /* @__PURE__ */ new Map();
return t.forEach((n, r) => {
const o = n.name.toLowerCase(), s = new Ud(this, n, !0);
e.set(o, s);
}), e;
}
_initializeBuiltIns() {
const t = /* @__PURE__ */ new Map();
this._builtInsCellStyles = t, this._initializeNamedStyles(SS, t), this._builtInsTableStyles = this._initializeTableStyles(), this._emptyTableStyle = new gr.Empty(this._normalStyle);
}
getNormal() {
return this._normalStyle;
}
getNormalRanged() {
return this._normalRanged;
}
setTheme(t) {
this._theme = t, this._emitter.notify("onThemeChange"), this._emitter.notify("onAnyChange");
}
getTheme() {
return this._theme;
}
setDefaultFontSize(t) {
this._defaultFontSize = t, 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 YS(this._persistCache, {}, this._toJSONInternal.bind(this), this._fromJSONInternal.bind(this), () => {
this._persistCache = null;
});
}
getNamed(t) {
if (!t) return null;
t = t.toLowerCase();
let e = null;
return this._customCellStyles && (e = this._customCellStyles.get(t)), e || (e = this._builtInsCellStyles.get(t)), e ?? null;
}
getCustomNamed() {
const t = Array.from(this._customCellStyles.values());
return t.sort((e, n) => e.getName().localeCompare(n.getName())), t;
}
setNamed(t, e = !1) {
if (!t || !t.name || !t.style) throw new Qe();
this.validateStyleName(t.name, !1);
const n = this._setCustomCellStyleInternal(t, e);
return this._emitter.notify("onNamedStylesChange"), this._emitter.notify("onAnyChange"), n;
}
_setCustomCellStyleInternal(t, e = !1, n = 0) {
const r = t.name.toLowerCase(), o = this._builtInsCellStyles.get(r), s = o?.getBuiltInID() ?? null;
let i = null;
e && (i = (this._customCellStyles.get(r) ?? o)?._properties ?? null);
const l = Ki(0, t.style, this.getNormal());
t = { ...t, style: l };
const c = Yt.resolveTypedUpdates(t, uS, this, i), h = new qd(this, c, this._hideOrRemoveNamed.bind(this), s);
return c.name === mt.BuiltInName.Normal && (this._normalRanged = h.getRanged(), this._normalStyle = no(this, null)), this._customCellStyles.set(r, h), h;
}
_setCustomTableStyleInternal(t, e) {
const n = t.toLowerCase();
let r = this._customTableStyles.get(n) ?? this._builtInsTableStyles.get(n);
r && (t = r.getName());
const o = new Ud(this, { ...e, name: t }, !1, this._deleteCustomTableStyle.bind(this));
return this._customTableStyles.set(n, o), o;
}
_hideOrRemoveNamed(t) {
let e = null;
if (e = typeof t == "string" ? t : t?.getName?.(), !e || (e = e.toLowerCase(), e === mt.BuiltInName.Normal.toLowerCase())) return !1;
const n = this._builtInsCellStyles.get(e);
let r = !1;
if (n && !n.isHidden()) {
const o = n.toJSON();
this.setNamed({ ...o, hidden: !0 }), r = !0;
} else e = e.toLowerCase(), r = this._customCellStyles.delete(e);
return r && (this._emitter.notify("onNamedStylesChange"), this._emitter.notify("onAnyChange")), r;
}
getTableStyle(t) {
if (!t) return this._emptyTableStyle;
let e = this._customTableStyles.get(t.toLowerCase());
return e || (e = this._builtInsTableStyles.get(t.toLowerCase())), e ?? null;
}
getCustomTableStyles() {
const t = Array.from(this._customTableStyles.values());
return t.sort((e, n) => e.getName().localeCompare(n.getName())), t;
}
setDefaultTableStyle(t) {
const e = t?.toLowerCase();
return this._defaultTableStyle = this._customTableStyles.get(e) ?? this._builtInsTableStyles.get(e) ?? this._builtInsTableStyles.get(yo.toLowerCase()), this._emitter.notify("onTableStylesChange"), this._emitter.notify("onAnyChange"), t === this._defaultTableStyle.getName();
}
getDefaultTableStyle() {
return this._defaultTableStyle || (this._defaultTableStyle = this._builtInsTableStyles.get(yo.toLowerCase())), this._defaultTableStyle;
}
_deleteCustomTableStyle(t) {
const e = this._customTableStyles.get(t?.toLowerCase());
return !!e && (this._customTableStyles.delete(t.toLowerCase()), this._defaultTableStyle?.getName() === e.getName() && (this._defaultTableStyle = this._builtInsTableStyles.get(yo.toLowerCase())), this._emitter.notify("onTableStylesChange"), this._emitter.notify("onAnyChange"), !0);
}
setCustomTableStyle(t, e) {
const n = this._setCustomTableStyleInternal(t, e);
return this._emitter.notify("onTableStylesChange"), this._emitter.notify("onAnyChange"), n;
}
validateStyleName(t, e = !1) {
if (!t || t.trim().length === 0) throw new Error("Style name cannot be empty.");
if (e && this.getNamed(t) !== null) throw new Error("Style name is already taken.");
}
normalize(t, e) {
if (!t) return null;
const n = Yt.resolveTypedUpdates(t, Qt, this);
if (!n) return null;
const r = bm;
let o = null;
const s = e ?? n.named ?? mt.BuiltInName.Normal;
if (o = s === mt.BuiltInName.Normal ? this._normalRanged.getPropertiesAt(0, 0, null) : this.getNamed(s)?.getRanged().getPropertiesAt(0, 0, null), o) {
const l = { ...o };
k.removeEqualValues(n, l);
}
const i = this.getTheme().getFontScheme();
return k.removeEqualValues(n, { font: { size: this.getDefaultFontSize(), family: i.getMinorFont(), fallbacks: i.getMinorFallbacks() } }), k.removeEqualValues(n, r), n;
}
schemeLookup() {
return this._schemeLookup;
}
indexedLookup() {
return this._indexedLookup;
}
parseColor(t) {
return ae.parse(t, this._schemeLookup, this._indexedLookup);
}
recentColors() {
return this._mruColors;
}
addRecentColor(t) {
if (!t) return;
const e = this._mruColors, n = [], r = t.toString(), o = e.length;
for (let s = 0; s < o && s < 10; s++) {
const i = e[s];
i.toString() !== r && n.push(i);
}
return n.unshift(t), this._mruColors = Object.freeze(n), this._mruColors;
}
clearRecentColors() {
this._mruColors = k.EmptyArray;
}
getIndexedColors() {
return this._indexedColors;
}
setCustomIndexedColors(t) {
this._indexedColors = t?.length > 0 ? [...t] : null;
}
getCustomIndexedColors() {
const t = this._indexedColors, e = Math.max(t?.length, 66), n = [];
for (let r = 0; r < e; r++) {
const o = t[r];
o !== null && n.push(o ?? new ae(Ei(r)?.toString()));
}
return n;
}
addListeners(t, e) {
return this._emitter.addListeners(t, e);
}
_toJSONInternal(t) {
const e = {};
t.length > 0 && (e.direct = t);
const n = this.getCustomNamed(), r = n.length, o = new Array(r);
for (let m = 0; m < r; m++) {
const f = n[m].toJSON();
o[m] = f;
}
o.length > 0 && (e.named = o);
const s = {};
this._defaultTableStyle && this._defaultTableStyle.getName() !== yo && (s.defaultTableStyle = this._defaultTableStyle.getName());
const i = {}, l = this.getCustomTableStyles(), c = l.length;
for (let m = 0; m < c; m++) {
const f = l[m], p = f.toJSON();
delete p.name, p && Object.keys(p).length > 0 && (i[f.getName()] = p);
}
Object.keys(i).length > 0 && (s.styles = i), Object.keys(s).length > 0 && (e.tables = s);
const h = this._indexedColors, d = h.length ?? 0;
if (d > 0) {
const m = new Array(d);
for (let f = 0; f < d; f++) m[f] = h[f].toString();
e.indexedColors = m;
}
const u = this._mruColors, g = u.length;
if (g > 0) {
const m = new Array(g);
for (let f = 0; f < g; f++) m[f] = u[f].toString();
e.mruColors = m;
}
return Object.keys(e).length === 0 ? null : e;
}
_fromJSONIndexedColors(t) {
if (!t || t.length === 0) return k.EmptyArray;
const e = t.length, n = new Array(e);
if (e > 0) for (let r = 0; r < e; r++) {
const o = t[r];
try {
n[r] = this.parseColor(o);
} catch {
console.warn("Unable to parse color: " + o);
}
}
return n;
}
_fromJSONInternal(t) {
this._indexedColors = this._fromJSONIndexedColors(t.indexedColors);
const e = t.named;
for (let i = 0; e && i < e.length; i++) this._setCustomCellStyleInternal(t.named[i]);
let n = yo;
if (this._defaultTableStyle = null, t.tables) {
t.tables.defaultTableStyle && (n = t.tables.defaultTableStyle);
const i = t.tables.styles, l = i ? Object.keys(i) : null, c = l ? l.length : 0;
for (let h = 0; h < c; h++) {
const d = l[h], u = i[d];
this._setCustomTableStyleInternal(d, u);
}
}
this._defaultTableStyle = this.getTableStyle(n);
const r = t.mruColors, o = r ? r.length : 0, s = new Array(o);
if (o > 0) for (let i = 0; i < o; i++) {
const l = r[i];
try {
s[i] = this.parseColor(l);
} catch {
console.warn("Unable to parse color: " + l);
}
}
this._mruColors = s;
}
}
const Ka = "BinaryResource must have only one initial data value.", Xa = "Resource is closed.";
class Ya {
constructor(t) {
if (this._listeners = /* @__PURE__ */ new Set(), this._type = t.type, this._name = t?.name, t.base64) {
const e = t.base64;
this._asArrayBufferResolve = async () => {
const n = await Promise.resolve(e);
return Promise.resolve(Fo.base64ToArrayBuffer(n));
};
}
if (t.fetch) {
if (this._asArrayBufferResolve) throw new Error(Ka);
const e = t.fetch;
this._asArrayBufferResolve = async () => {
let n, r = null;
r = typeof e == "string" ? e : t.input;
const o = await fetch(r, n), s = o.headers.get("Content-Type");
return !this._type && s && (this._type = s), o.arrayBuffer();
};
}
if (t.buffer) {
if (this._asArrayBufferResolve) throw new Error(Ka);
this._asArrayBufferResolve = async () => {
let e = null;
return e = typeof t.buffer == "function" ? await t.buffer() : t.buffer, Promise.resolve(e);
};
}
if (t.file) {
if (this._asArrayBufferResolve) throw new Error(Ka);
this._asArrayBufferResolve = async () => await (await Promise.resolve(t.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 t = await this.toBuffer(), e = { base64: Fo.arrayBufferToBase64(t) };
return this._type !== Fo.DEFAULT_MIME_TYPE && (e.type = this._type), this._name && (e.name = this._name), e;
}
async toBuffer() {
if (this._asArrayBuffer) return this._asArrayBuffer;
try {
this._asArrayBuffer = this._asArrayBufferResolve();
} catch (t) {
throw t;
}
return this._asArrayBuffer;
}
async getType() {
return this._type ? this._type : (await this.toBuffer(), this._type ?? Fo.DEFAULT_MIME_TYPE);
}
addReference(t) {
if (this._isClosed) throw new Error(Xa);
this._refs.add(t);
}
deleteReference(t) {
if (this._isClosed) throw new Error(Xa);
if (this._refs.size === 0 || !this._refs.has(t)) return;
this._refs.delete(t);
const e = this;
if (this._refs.size === 0) {
const n = this._listeners;
n.forEach((r) => {
r.onUnload?.(e), n.delete(r);
}), this._asArrayBuffer = null, this._isClosed = !0;
}
}
addUnloadListener(t) {
if (this._isClosed) throw new Error(Xa);
this._listeners.add(t);
}
get isIResource() {
return !0;
}
isClosed() {
return this._isClosed;
}
}
let QS = class {
constructor(a, t, e) {
this._state = a, this._fromJSON = t, this._onLastEnd = e, 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 t = this._state.byRefs.get(a);
return t !== void 0 || (t = this._state.byRefs.size, this._state.byRefs.set(a, t), this._state.byIds.set(t, a)), t;
}
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 t = this._state.byRefs.size;
for (let e = 0; e < a.length; e++) {
const n = a[e], r = this._fromJSON(n);
this._state.byRefs.set(r, t + e), this._state.byIds.set(t + e, r);
}
}
toJSONAsync() {
if (this._isClosed) throw new Error("PersistScope is closed.");
const a = [];
return this._state.byRefs.forEach((t, e) => {
a[t] = Promise.resolve(e.toJSONAsync());
}), Promise.all(a);
}
};
class Nm {
constructor() {
this._resources = /* @__PURE__ */ new Set();
}
add(t) {
if (typeof t == "string") {
let r = !1;
this._resources.forEach((o) => {
o.getName() === t && (r = !0, t = o);
}), r || (t = new Ya({ name: t, fetch: t, type: null }));
}
let e = null;
e = t instanceof Ya ? t : new Ya({ ...t });
const n = this;
return this._resources.has(e) || (e.addUnloadListener({ onUnload: (r) => {
n._resources.delete(e);
} }), this._resources.add(e)), e;
}
getItems(t) {
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 t = {}, e = /* @__PURE__ */ new Set(), n = this;
return new QS(this._persistOpen, (r) => {
const o = n.add({ base64: r.base64, name: r.name, type: r.type });
return o.addReference(t), e.add(o), o;
}, () => {
e.forEach((r) => {
r.deleteReference(t);
}), n._persistOpen = null;
});
}
}
class ZS {
constructor(t, e, n) {
this._state = t, this._fromJSON = e, 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(t) {
if (this._isClosed) throw new Error("PersistScope is closed.");
let e = this._state.byRefs.get(t);
return e !== void 0 || (e = this._state.byRefs.size, this._state.byRefs.set(t, e), this._state.byIds.set(e, t)), e;
}
at(t) {
return this._state.byIds.get(t) ?? null;
}
fromJSON(t) {
if (this._isClosed) throw new Error("PersistScope is closed.");
t && t.length !== 0 && this._fromJSON(t);
}
toJSONAsync() {
if (this._isClosed) throw new Error("PersistScope is closed.");
const t = [];
return this._state.byRefs.forEach((e, n) => {
t[e] = Promise.resolve(n.toJSONAsync ? n.toJSONAsync() : n);
}), Promise.all(t);
}
}
class dc {
constructor() {
this._nextId = 0, this._lastReadId = -1, this._lastReadValue = null, this._stringsByText = /* @__PURE__ */ new Map(), this._stringsById = /* @__PURE__ */ new Map();
}
addMultiple(t, e = !1) {
const n = this._stringsByText, r = this._stringsById, o = t.length;
let s = this._nextId;
for (let i = 0; i < o; i++) {
const l = t[i];
n.get(l) !== void 0 && e || (n.set(l, s), r.set(s, l), s++);
}
this._lastReadId = -1, this._nextId = s;
}
add(t) {
const e = this._stringsByText, n = e.get(t);
if (n !== void 0) return n;
const r = this._nextId++;
return e.set(t, r), this._stringsById.set(r, t), this._lastReadId = -1, r;
}
getItems(t) {
if (t?.id !== void 0) {
const e = this.getById(t.id);
return e ? [e] : [];
}
return Array.from(this._stringsById.values());
}
getById(t) {
if (this._lastReadId === t) return this._lastReadValue;
const e = this._stringsById.get(t) ?? null;
return this._lastReadId = t, this._lastReadValue = e, e;
}
getCount() {
return this._stringsById.size;
}
beginPersist() {
this._persistOpen || (this._persistOpen = { byRefs: /* @__PURE__ */ new Map(), byIds: /* @__PURE__ */ new Map(), openScopes: /* @__PURE__ */ new Set() });
const t = this;
return new ZS(this._persistOpen, (e) => (Array.isArray(e) ? t.addMultiple(e) : t.add(e), e), () => {
t._persistOpen = null;
});
}
}
var Jd, ee;
Jd || (Jd = {});
class tw extends Er {
constructor(t) {
super(t), t.json && (this._resource = t.fromResourceId(t.json.resId));
}
getType() {
return "picture";
}
toJSON(t) {
const e = {}, n = t?.(this._resource);
n !== null && (e.resId = n);
const r = this._getState();
return r && r.effects && (e.effects = r.effects), e;
}
getTypeDescription() {
return "Picture";
}
async _asDataUrl() {
if (this._dataUrl) return this._dataUrl;
const t = await this.getDetails(), e = await js.getImageDataUrl(t.asUrl());
return this._dataUrl = e.dataUrl, this._dataUrl;
}
toHtml() {
return null;
}
async toImage() {
const t = (await this._asDataUrl()).substring(js.DATA_URL_PNG_PREFIX.length), e = Fo.base64ToArrayBuffer(t);
return new Blob([e], { type: Wu.png });
}
async getDetails() {
return this._details || (this._details = new Promise(async (t, e) => {
try {
const n = await this._resource.toBuffer(), r = await this._resource.getType(), o = await js.loadImageDetails(n, r);
t({ getNaturalSize: () => o.naturalSize, asUrl: () => o.asUrl, asSVGText: () => o.asSVGText });
} catch (n) {
e(n);
}
})), this._details;
}
_fromDrawingJSON(t, e) {
this._resource?.deleteReference(this), this._resource = e?.(t.resId), this._resource.addReference(this);
}
_toDrawingJSON(t) {
const e = {}, n = t?.(this._resource);
return n !== null && (e.resId = n), e;
}
_processDelete() {
super._processDelete();
}
}
(ee || (ee = {})).Status = { Ready: "ready", Error: "error", Starting: "starting", Stopping: "stopping", Off: "off" };
class es extends me {
constructor(t, e = null, n, r, o) {
if (super(t, n, e), this._sheetName = r || null, this._getEntireCoords = o ?? Fl, this._coords = ew(n, this._getEntireCoords()), !n) throw new Error("ReferenceRange requires a coords");
this._validateCoords(n);
}
toType(t) {
return new es(this._values, t, this._coords, this._sheetName, this._getEntireCoords);
}
getCoords() {
return this._coords;
}
get isIReferenceRange() {
return !0;
}
isLiteral() {
return !1;
}
_validateCoords(t) {
const e = this._getEntireCoords?.();
if (e && (t.rowStart < e.rowStart && t.rowStart !== Number.MIN_SAFE_INTEGER || t.rowEnd > e.rowEnd && t.rowEnd !== Number.MAX_SAFE_INTEGER || t.colStart < e.colStart && t.colStart !== Number.MIN_SAFE_INTEGER || t.colEnd > e.colEnd && t.colEnd !== Number.MAX_SAFE_INTEGER)) throw new Wt();
}
get [Symbol.toStringTag]() {
return "[ReferenceRange]";
}
toString() {
return `${kn(this._coords, this._getEntireCoords?.())}`;
}
}
const ew = (a, t) => {
let e = a.rowStart, n = a.rowEnd, r = a.colStart, o = a.colEnd, s = !1;
return r === Number.MIN_SAFE_INTEGER && (r = t.colStart, s = !0), e === Number.MIN_SAFE_INTEGER && (e = t.rowStart, s = !0), n === Number.MAX_SAFE_INTEGER && (n = t.rowEnd, s = !0), o === Number.MAX_SAFE_INTEGER && (o = t.colEnd, s = !0), s ? { rowStart: e, rowEnd: n, colStart: r, colEnd: o } : a;
}, Kd = (a, t) => a.value?.once === t.value?.once, nw = (a, t) => a.colStart === t.colStart && a.rowStart === t.rowStart, Fm = (a, t, e) => !!e && a === e.rowStart && t === e.colStart, rw = (a, t = 0, e = 0) => {
const n = a._values, r = a._coords, o = n.getRuns({ bounds: r }), s = n.getOrientation() !== F.Orientation.Row, i = s ? r.colStart : r.rowStart, l = s ? r.rowStart : r.colStart, c = new zt.Builder(null, t, e);
let h = o.next();
for (; !h.done; ) {
const d = h.value;
c.addValues(d[0] - i, d[1] - l, d[2]), h = o.next();
}
return c.build();
}, fi = (a, t, e, n, r, o, s, i, l, c, h, d, u = !1) => {
let g, m, f = null, p = r.size();
d === void 0 && (d = o.getOrientation() === F.Orientation.Column);
const _ = t ? t.length : 0, S = e ? e.length : 0;
let C;
const y = _ + S;
for (let w = 0; w < y && p > 0; w++) {
const b = w < _ ? t[w] : e[w - _], v = r.search(b), I = v.length;
for (let x = 0; x < I; x++) {
const R = v[x];
if (!Fm(R.rowStart, R.colStart, b)) {
if (R.value.getError()) continue;
C || (C = []), C.push(R);
}
r.remove(R, nw);
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 = L.unionRanges(f, M), i?.insertNonOverlapping(M), f = L.unionRanges(f, M), T;
} })), p--;
}
}
for (let w = 0; w < _; w++) {
const b = t[w], v = { colStart: b.colStart, rowStart: b.rowStart, colEnd: b.colEnd, rowEnd: b.rowEnd, value: null };
n.insertNonOverlapping(v, { onIntersect: (I, x) => {
if (I.value === null) return;
const R = L.sanitizeRange(x);
return u && i?.insertNonOverlapping(R), c?.insertNonOverlapping({ ...x, value: !1 }), s?.push(R), f = L.unionRanges(f, R), x;
} }), h?.insertNonOverlapping(v, { onIntersect: (I, x) => {
if (I.value !== null) return s?.push(x), f = L.unionRanges(f, x), x;
}, onUpdates: (I, x, R) => {
m || (m = []);
const A = I.length;
for (let T = 0; T < A; T++) {
const O = I[T];
m.push(O);
}
g || (g = []);
const M = x.length;
for (let T = 0; T < M; T++) {
const O = x[T], W = L.sanitizeRange(O);
g.push(W);
}
} });
}
const E = d ? F.Orientation.Column : F.Orientation.Row;
if (C) {
const w = C.length, b = new Array(w);
for (let v = 0; v < w; v++) {
const I = C[v], x = I.value.setError(!0, a);
l?.insert(x), b[v] = x, f = L.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 Ye(I, E) }), s?.push(R);
}
r.load(b);
}
for (let w = 0; w < S; w++) {
const b = L.sanitizeRange(e[w]);
n.insertNonOverlapping({ colStart: b.colStart, rowStart: b.rowStart, colEnd: b.colEnd, rowEnd: b.rowEnd, value: new Ye(b, E) }), u && i?.insertNonOverlapping(b), s?.push(b), f = L.unionRanges(f, b);
}
return f;
}, jl = (a, t, e) => {
if (!t) return a;
const n = t.block;
if (!n) return a;
const r = a ?? [], o = t.colIndex, s = t.rowIndex;
let i, l, c, h;
e ? (i = e.colStart, l = e.rowStart, c = e.colEnd, h = e.rowEnd) : (i = o, l = s, c = o, h = s);
const d = { 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: t } };
let u = t.dynamic;
return u || (u = [], t.dynamic = u), u.push(d), r.push(d), r;
};
class uc {
constructor(t) {
this._fullCalcRequired = !1, this._iterationId = 0, this._uuid = k.uuidV4(), 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 d = aw, u = 0;
if (s) {
const g = c.all();
for (let m = 0; m < g.length; m++) {
const f = g[m].value.calcs, p = f.length;
for (let _ = 0; _ < p; _++) {
const S = f[_], C = S.length;
for (let y = 0; y < C; y++) {
const E = S[y];
E.markId !== o && (d[u++] = E, E.markId = o, E.pending = !1, E.pendingResolved = !1, E.pendingPromise && (E.pendingPromise.cancelled = !0));
}
}
}
} else {
const g = i.length;
for (let m = 0; m < g; m++) {
const f = i[m];
Zd.length = 0;
const p = Zd;
h.search(f, !1, p), c.search(f, !1, p);
const _ = p.length;
if (_ === 0) continue;
const S = f.colStart, C = f.rowStart, y = f.colEnd - S, E = f.rowEnd - C;
for (let w = 0; w < _; w++) {
const b = p[w], v = b.value, I = v.blockEntry?.value ?? v, x = I.ref, R = x.colEnd - x.colStart, A = x.rowEnd - x.rowStart, M = b.colEnd - b.colStart - R, T = b.rowEnd - b.rowStart - A, O = v.once;
if (O) O.markId <= o && (O.removed ? (h.remove(b, Kd), O.removed = !1) : d[u++] = O, O.markId = o);
else {
let W = 0, D = 0, z = R, B = A;
if (!v.$absHeight) {
const P = C - b.rowStart;
D = Math.min(Math.max(P - T, 0), A), B = Math.min(E + C, A);
}
if (!v.$absWidth) {
const P = S - b.colStart;
W = Math.min(Math.max(P - M, 0), R), z = Math.min(y + P, R);
}
const H = I.calcs;
for (let P = D; P <= B; P++) {
const j = H[P];
for (let G = W; G <= z; G++) {
const K = j[G];
K.markId !== o && (d[u++] = K, K.markId = o, K.pendingPromise && (K.pendingPromise.cancelled = !0));
}
}
}
}
}
l && l.forEach((m) => {
if (Array.isArray(m)) {
const f = m.length;
for (let p = 0; p < f; p++) {
const _ = m[p], S = _.length;
for (let C = 0; C < S; C++) {
const y = _[C];
y.markId === o || y.removed || (d[u++] = y, y.markId = o, y.pendingPromise && (y.pendingPromise.cancelled = !0));
}
}
} else m.markId === o || m.removed || (d[u++] = m, m.markId = o, m.pendingPromise && (m.pendingPromise.cancelled = !0));
});
}
return d.length = u, d;
};
const e = (t = { strings: new dc(), ...t }).getEntireCoords ?? Fl;
if (this._getEntireCoords = e, this._options = t, this._strings = t.strings, this._onCalculated = t?.onCalculated ?? (() => {
}), this._cycleId = 1, this._values = new hn({ orientation: F.Orientation.Column }), this._getFormulaParser = t.getFormulaParser, !this._getFormulaParser) throw new Error("Formula parser is not defined");
this._latest = { graph: this }, this._iterationId = 0;
const n = this;
this._formulaSpatial = new Nt({ 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 d = l._precedentSpatial, u = s ? s.length : 0;
if (u > 0) {
let m = h ? h.length : 0;
h ? h.length = m + u : (h = new Array(u), l._notifyFormulaRemoveEntries = h);
for (let f = 0; f < u; f++) {
const p = s[f], _ = p.value, S = _.ref;
h[m + f] = S;
const C = S.rowStart, y = S.colStart, E = _.formula.getDirectPrecedentsAt(C, y);
if (!E) continue;
const w = E.length;
for (let b = 0; b < w; b++) {
const v = E[b];
if (v === null || v instanceof pt.Known) continue;
const I = d.search(v), x = I.length;
for (let R = 0; R < x; R++) {
const A = I[R];
A.value.blockEntry.value === p.value && d.remove(A);
}
}
}
}
const g = o ? o.length : 0;
if (g > 0) {
const m = [];
for (let f = 0; f < g; f++) {
const p = o[f], _ = p.colEnd - p.colStart, S = p.rowEnd - p.rowStart, C = p.value, y = C.formula, E = C.ref, w = E.rowStart, b = E.colStart, v = [], I = y.getDirectPrecedentsAt(w, b, !0, As, Ms), x = I.length;
for (let R = 0; R < x; R++) {
const A = I[R];
if (A instanceof pt.Known) continue;
const M = As[R], T = Ms[R], O = { colStart: A.colStart, rowStart: A.rowStart, colEnd: A.colEnd + (T ? 0 : _), rowEnd: A.rowEnd + (M ? 0 : S), value: { blockEntry: p, width: _ + 1, height: S + 1, index: R, $absWidth: T, $absHeight: M, once: null } };
v.push(A), m.push(O);
}
c || (c = [], l._notifyFormulaInsertEntries = c), c.push({ colStart: p.colStart, rowStart: p.rowStart, colEnd: p.colEnd, rowEnd: p.rowEnd, value: { tokens: y.getTokens(), references: y.getReferences(), precedents: v } });
}
d.load(m);
}
} } }), this._contentfulSpatial = new Nt({ updateEntryOptions: { isSplitOnExpand: !0, isMergeOnShift: !0 } });
const r = { updateEntryOptions: { isSplitOnExpand: !0, isMergeOnShift: !1 } };
this._precedentSpatial = new Nt(r), this._volatile = /* @__PURE__ */ new Set(), this._spillSpatial = new Nt(r), this._errorSpatial = new Nt(r), this._pendingSpatial = new Nt(r), this._invalidations = new Nt(), this._notifyValues = new Nt(), this._notifySpills = new Nt(), this._notifyFormats = new Nt(), this._notifyPending = new Nt(), this._calculation = t.calculation, this._clearScope();
}
addListeners(t, e) {
return this._emitter || (this._emitter = new he(this)), this._emitter.addListeners(t, e);
}
shift(t) {
const e = t.cloneIfUpdate ?? !0 ? this.clone(this) : this, n = { ...t };
delete n.cloneIfUpdate, delete n.onShift, e._values.shift(n.range, n.direction);
const r = e._contentfulSpatial;
e._contentfulSpatial = r.shift(n);
const o = e._spillSpatial;
e._spillSpatial = o.shift(n);
const s = e._formulaSpatial;
if (s.isEmpty()) return e;
const i = t.range, l = t.direction, c = l === F.Direction.Left || l === F.Direction.Right;
l !== F.Direction.Up && F.Direction.Left, c ? (i.colEnd, i.colStart) : (i.rowEnd, i.rowStart), e._notifyFormulaInsertEntries, e._notifyFormulaRemoveEntries;
const h = e._getEntireCoords(), d = /* @__PURE__ */ new Map();
this._precedentSpatial.visitRanges({ ...i, colEnd: c ? h.colEnd : i.colEnd, rowEnd: c ? i.rowEnd : h.rowEnd }, (_) => {
let S = _.value;
if (_.value.once) return;
let C = S.blockEntry, y = d.get(C);
y || (y = { rows: [], cols: [], index: [] }, d.set(C, y)), y.index.push(S.index);
});
const u = [], g = [], m = d.entries();
let f = m.next();
const p = (_, S, C, y) => {
let E = _.value;
const w = E.formula.getReferences(), b = S.length;
for (let v = 0; v < b; v++) {
const I = w[v];
I !== null && (I instanceof pt.Known || typeof I != "string" && I[v]);
}
return _.value = E, _;
};
for (; !f.done; ) {
const [_, S] = f.value, C = _.value, y = S.rows.sort(), E = y.length, w = S.cols.sort().length, b = S.index.sort();
if (g.push(_), E === 0 && w === 0) {
const I = { ..._ };
p(I, b), u.push(I), f = m.next();
continue;
}
let v = 0;
for (let I = 0; I < E; I++) {
const x = y[I];
if (x === v) continue;
rl[0] = { colStart: C.ref.colStart, rowStart: v, colEnd: C.ref.colEnd, rowEnd: x - 1, value: C }, rl[1] = { colStart: C.ref.colStart, rowStart: x, colEnd: C.ref.colStart, rowEnd: C.ref.rowEnd, value: C };
const R = hw(C, rl, F.Orientation.Row, x);
let A = R[0];
p(A, b), u.push(A), A = R[1], p(A, b), u.push(A), v = x;
}
f = m.next();
}
return s._updateNodes(u, g), e._fullCalcRequired = !0, this._invalidate(u), e;
}
clone(t) {
if (t !== void 0 && this._cloneKey === t) return this;
const e = new uc(this._options);
e._cloneKey = t, e._uuid = this._uuid, this._calculation._getAllGraphs().set(this._uuid, this._latest.graph), e._values = this._values.clone(e), e._contentfulSpatial = this._contentfulSpatial.clone(e), e._formulaSpatial = this._formulaSpatial.clone(e), e._precedentSpatial = this._precedentSpatial.clone(e), e._volatile = new Set(this._volatile), e._spillSpatial = this._spillSpatial.clone(e), e._errorSpatial = this._errorSpatial.clone(e), e._pendingSpatial = this._pendingSpatial.clone(e), e._invalidations = this._invalidations.clone(e), e._notifyValues = this._notifyValues.clone(e), e._notifySpills = this._notifySpills.clone(e), e._notifyFormats = this._notifyFormats.clone(e), e._notifyPending = this._notifyPending.clone(e);
const n = this._notifyFormulaInsertEntries;
n && (e._notifyFormulaInsertEntries = [...n]);
const r = this._notifyFormulaRemoveEntries;
r && (e._notifyFormulaRemoveEntries = [...r]);
const o = this._pendingActions;
return o && (e._pendingActions = [...o]), e._cycleId = this._cycleId, e._emitter = this._emitter, e._fullCalcRequired = this._fullCalcRequired, this._latest.graph = e, e._iterationId = this._iterationId + 1, e;
}
invalidate(t) {
const e = this._invalidations;
if (Array.isArray(t)) {
const n = t.length;
for (let r = 0; r < n; r++) {
let o = t[r];
typeof o == "string" && (o = Ae(o)), e.insertNonOverlapping(o);
}
} else {
let n = t;
typeof n == "string" && (n = Ae(n)), e.insertNonOverlapping(n);
}
}
setFormulaAt(t, e) {
let n, r = null;
return typeof t == "string" ? n = Ae(t, Vt) : (Vt.colStart = t.colIndex, Vt.rowStart = t.rowIndex, Vt.colEnd = t.colIndex, Vt.rowEnd = t.rowIndex, n = Vt), e ? r = this._setInputs(null, [{ colStart: n.colStart, rowStart: n.rowStart, colEnd: n.colEnd, rowEnd: n.rowEnd, value: e }]) : this.delete(n), r;
}
getFormulaAt(t, e) {
let n;
typeof t == "string" && (n = Ae(t, Vt));
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, e) : void 0;
}
_formulaAt(t, e) {
Io.colStart = e, Io.rowStart = t, Io.colEnd = e, Io.rowEnd = t;
const n = this._formulaSpatial.search(Io);
if (n.length === 0) throw new Error(`No formula found at ${as({ rowIndex: t, colIndex: e })}`);
return n[0];
}
getDirectPrecedentsAt(t, e, n) {
return this._formulaAt(t, e).value.formula.getDirectPrecedentsAt(t, e, n);
}
getReferencesAt(t, e) {
return this._formulaAt(t, e).value.formula.getReferences();
}
setReferenceAt(t, e, n, r) {
const o = this._formulaAt(t, e).value.formula.setReferenceAt(n, r).getTextAt(t, e);
return this.setFormulaAt({ rowIndex: t, colIndex: e }, o), this;
}
evaluateAt(t, e, n) {
const r = this._formulaAt(t, e), o = r.value, s = o.ref, i = s.colStart - e, l = s.rowStart - t, c = this._calculation._getContext(), h = this._calculation._getScope();
return h.sheetName = this._options.getSheetName?.(), h.rowIndex = t, h.colIndex = e, h.node = o.calcs[l][i], r.value.formula.evaluate(c, n);
}
setInputAt(t, e) {
let n = null;
const r = typeof t == "string" ? Wr(t, sw) : t;
if (e !== null) {
const o = new zt.Builder(), s = this._values.getOrientation() === F.Orientation.Column, i = s ? r.colIndex : r.rowIndex, l = s ? r.rowIndex : r.colIndex;
o.addValue(i, l, e), n = this.setInputs(o.build(), null);
} else this.delete(L.cellToRange(r, Vt));
return n;
}
setInputs(t, e) {
return this._setInputs(t, e);
}
delete(t) {
return typeof t == "string" && (t = Pe(t)), this._setInputs(null, [{ ...t, value: null }], t).removes;
}
_createCopySpillEntries(t, e, n, r, o) {
const s = r ?? [], i = o ?? [], l = e.colStart, c = e.rowStart, h = e.colEnd, d = e.rowEnd, u = n.colStart, g = n.rowStart, m = t.search(e), f = m.length;
for (let p = 0; p < f; p++) {
const _ = m[p];
i && i.push(_);
const S = _.rowStart, C = _.colStart;
if (S < c || S > d || C < l || C > h || _.value.getError()) continue;
const y = u + (_.colEnd - C), E = g + (_.rowEnd - S), w = { colStart: u, rowStart: g, colEnd: y, rowEnd: E };
s.push({ colStart: u, rowStart: g, colEnd: y, rowEnd: E, value: new _r(w, 0, !1) });
}
return { removes: i, inserts: s };
}
_copyCalcs(t, e, n) {
const r = t._formulaSpatial;
if (r.isEmpty()) return;
const o = this._getEntireCoords(), s = o.colStart, i = o.rowStart, l = o.colEnd, c = o.rowEnd, h = r.createCopiedEntries(e, n), d = h.inserts;
let u = d.length, g = 0;
const m = t._spillSpatial;
let f = [];
for (; g < u; ) {
let p = d[g], _ = p.value, S = _.ref, C = S.colStart, y = S.rowStart, E = S.colEnd, w = S.rowEnd;
this._createCopySpillEntries(m, e, S, f, null);
let b = _.formula.getReferences();
const v = b.length;
for (let I = 0; I < v; I++) {
const x = b[I];
if (!x || x.isFormulaError || typeof x == "string") continue;
const R = x, A = R.colStart, M = R.rowStart, T = R.colEnd, O = R.rowEnd;
let W = R.$colStart ? A : A + C, D = R.$rowStart ? M : M + y, z = R.$colEnd ? T : T + E, B = R.$rowEnd ? O : O + w;
if (A === Number.MIN_SAFE_INTEGER && (W = s, z = l), M === Number.MIN_SAFE_INTEGER && (D = i, B = c), W < s || z > l || D < i || B > c) {
const H = s - W, P = i - D, j = l - z, G = c - B;
xo.colStart = Math.max(C, C + H), xo.rowStart = Math.max(y, y + P), xo.colEnd = Math.min(E, E + j), xo.rowEnd = Math.min(w, w + G);
const K = eo(p, xo, ni);
if (K) {
const V = K.length;
p = K[V - 1], _ = p.value, S = _.ref, C = S.colStart, y = S.rowStart, E = S.colEnd, w = S.rowEnd;
for (let $ = 0; $ < V - 1; $++) {
const J = K[$];
d.push(J), u++;
}
} else _ = _.setReferenceAt(I, null), p.value = _, b = _.formula.getReferences();
}
}
d[g++] = p;
}
this._formulaSpatial._updateNodes(d, 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(d), this._invalidate(h.removes);
}
_moveCalcs(t, e, n) {
const r = t._formulaSpatial.createCopiedEntries(e, n);
console.log("_moveCalcs", r, "from:", e, "to:", n);
const o = this._formulaSpatial, s = (g, m, f, p) => {
let _ = g.value;
const S = _.formula.getReferences(), C = S.length, y = m.colStart - f.colStart, E = m.rowStart - f.rowStart, w = _.ref, b = f.colStart - w.colStart, v = f.colEnd - w.colEnd, I = f.rowStart - w.rowStart, x = f.rowEnd - w.rowEnd;
for (let R = 0; R < C; R++) {
const A = S[R];
if (!A || A.isFormulaError || typeof A == "string") continue;
const M = A, T = M.colStart, O = M.rowStart, W = M.colEnd, D = M.rowEnd;
let z = y, B = E;
const H = b <= T && v >= W || T == Number.MIN_SAFE_INTEGER, P = I <= O && x >= D || O == Number.MIN_SAFE_INTEGER;
let j = !P;
M.$colStart || z === 0 || T === Number.MIN_SAFE_INTEGER ? j = !1 : j || (j = T < b || T > v, j || !M.$colEnd || M.$colStart || (j = !0));
let G = !H;
M.$rowStart || B === 0 || O === Number.MIN_SAFE_INTEGER ? G = !1 : G || (G = O < I || O > x, j || !M.$rowEnd || M.$rowStart || (G = !0));
let K = !P;
M.$colEnd || z === 0 || O === Number.MIN_SAFE_INTEGER ? K = !1 : K || (K = W < b || W > v, j || !M.$colStart || M.$colEnd || (K = !0));
let V = !H;
if (M.$rowEnd || B === 0 || O === Number.MIN_SAFE_INTEGER ? V = !1 : V || (V = D < I || D > x, V || !M.$rowEnd || M.$rowStart || (V = !0)), !(j || K || G || V)) continue;
const $ = { ...M };
j && ($.colStart += z), G && ($.rowStart += B), K && ($.colEnd += z), V && ($.rowEnd += B), _ = _.setReferenceAt(R, $);
}
return g.value = _, g;
}, i = t._spillSpatial;
let l = [], c = [];
const h = r.inserts, d = h.length;
for (let g = 0; g < d; g++) {
const m = h[g];
this._createCopySpillEntries(i, e, m, l, c), h[g] = s(m, e, n);
}
o._updateNodes(r.inserts, []), t._formulaSpatial._updateNodes([], r.removes);
const u = [];
l.length > 0 && (this._spillSpatial._updateNodes(l, []), t._spillSpatial._updateNodes([], c), fi(this._cycleId, c, k.EmptyArray, t._contentfulSpatial, i, t._values, u, t._notifyValues, t._notifySpills, t._notifyPending, t._errorSpatial, t._values.getOrientation() !== F.Orientation.Row, !1)), this._fullCalcRequired = !0, this._invalidate(r.inserts), t._invalidate(u), t._invalidate(r.removes);
}
getSnapshot(t) {
const e = this, n = Object.freeze({ ...t });
let r = n.range;
return typeof r == "string" && (r = Ae(r)), { async copyTo(o, s) {
const i = o.calcGraph;
let l = o.range;
typeof l == "string" && (l = Ae(l));
const c = Nl(l, r, s?.fitDestination, s?.transpose);
return { ...n, ...s }.isCut ? i._moveCalcs(e, r, c) : i._copyCalcs(e, r, c), l;
}, getCoords: () => r, getSource: () => e, getName: () => "Calculation", getMarkOptions: () => n, isISnapshot: !0 };
}
autoFill(t, e) {
return typeof t == "string" && (t = Ae(t)), typeof e == "string" && (e = Ae(e)), this._copyCalcs(this, t, e), this;
}
_scheduleRecalculation(t) {
const e = this._pendingInvalidations;
if (t) if (Array.isArray(t)) {
const r = t.length;
for (let o = 0; o < r; o++) e.add(t[o]);
} else e.add(t);
const n = this;
k.debounce(() => {
const r = n._latest.graph, o = r._volatile, s = r._cycleId;
e.forEach((i) => {
i.cycleId > s || o.add(i);
}), e.clear(), r.calculate();
}, 100)();
}
_notifyCalculated(t) {
const e = this, n = e._notifyValues, r = n.all();
return new Promise((o) => {
k.nextTick(() => {
const s = e._cycleId;
let i, l = e._fullCalcRequired;
l || (typeof t == "boolean" ? l = t : t && (i = t, l = i.full ?? !1));
const c = {};
let h = null;
const d = r.length;
if (d > 0) {
n.clear();
let C = r, y = null;
for (let R = 0; R < d; R++) {
const A = r[R], M = A.colStart, T = A.colEnd;
if (M !== T) {
y || (y = []);
for (let O = M + 1; O <= T; O++) y.push({ colStart: O, rowStart: A.rowStart, colEnd: O, rowEnd: A.rowEnd });
A.colEnd = M;
}
}
y && (C = r.concat(y)), C.sort(L.columnFirstRangeComparator);
const E = new zt.Builder((R) => new Ve(R));
let w;
const b = e._values, v = b.getOrientation() === F.Orientation.Column, I = C.length;
for (let R = 0; R < I; R++) {
const A = C[R];
h = L.unionRanges(h, A, Vt);
const M = b.getRuns({ bounds: A });
let T = M.next();
const O = A.colStart, W = A.rowStart, D = A.colEnd, z = A.rowEnd, B = v ? W : O, H = v ? D : z, P = v ? z : D;
let j = v ? O : W, G = B;
for (; !T.done; ) {
const K = T.value, V = K[0];
for (; j < V; ) w || (w = []), w.push({ colStart: v ? j : G, rowStart: v ? G : j, colEnd: v ? j : P, rowEnd: v ? P : j }), j++, G = B;
const $ = K[1], J = K[2], Z = Math.max($, B), q = Math.min($ + J.length - 1, P);
E.addValues(V, Z, J), G < Z && (w || (w = []), w.push({ colStart: v ? V : G, rowStart: v ? G : V, colEnd: v ? V : Z - 1, rowEnd: v ? Z - 1 : V })), G = q + 1, q >= P ? (j = V + 1, G = B) : j = V, T = M.next();
}
for (; j <= H; ) G <= P && (w || (w = []), w.push({ colStart: v ? j : G, rowStart: v ? G : j, colEnd: v ? j : P, rowEnd: v ? P : j })), j++, G = B;
}
const x = E.build();
x && (c.valueInserts = x), w && (c.valueRemoves = w);
}
const u = e._notifyPending, g = u.all();
if (g.length > 0) {
u.clear();
const C = e._pendingSpatial;
let y;
const E = g.length;
for (let w = 0; w < E; w++) {
const b = g[w];
C.insertNonOverlapping(b, { onIntersect: (v, I) => (y || (y = []), y.push({ ...I }), h = L.unionRanges(h, I), I.value === !1 && (I.value = null), I) });
}
y && y.length > 0 && (c.pendingUpdates = y, h = L.unionRangesArrays(y, h, Vt));
}
const m = e._notifySpills, f = m.all();
if (f.length > 0) {
m.clear();
const C = e._spillSpatial;
let y, E, w;
const b = f.length;
for (let v = 0; v < b; v++) {
const I = f[v], x = I.value;
if (x.getCycleId() !== s) y || (y = []), y.push({ colStart: I.colStart, rowStart: I.rowStart, colEnd: I.colEnd, rowEnd: I.rowEnd });
else {
const R = C.search(I), A = R.length;
for (let M = 0; M < A; M++) {
let T = R[M];
if (Fm(I.rowStart, I.colStart, T) && x.getCycleId() === s) {
E || (E = [], w = /* @__PURE__ */ new Set());
const O = tn(T.colStart) + dn(T.rowStart);
if (w.has(O)) continue;
w.add(O), E.push({ colStart: I.colStart, rowStart: I.rowStart, colEnd: I.colEnd, rowEnd: I.rowEnd, value: T.value.getError() });
}
}
}
}
E && (c.spillInserts = E, h = L.unionRangesArrays(E, h, Vt)), y && (c.spillRemoves = y, h = L.unionRangesArrays(y, h, Vt));
}
const p = e._notifyFormats.all();
p.length > 0 && (c.formatInserts = p, h = L.unionRangesArrays(p, h, Vt), e._notifyFormats.clear());
const _ = e._notifyFormulaInsertEntries;
if (_) {
const C = e._formulaSpatial;
for (let y = _.length - 1; y >= 0; y--) {
const E = _[y];
C.search(E).length === 0 ? _.splice(y, 1) : h = L.unionRanges(h, E, Vt);
}
c.formulaInserts = _, e._notifyFormulaInsertEntries = void 0;
}
const S = e._notifyFormulaRemoveEntries;
S && (c.formulaRemoves = S, h = L.unionRangesArrays(S, h, Vt), e._notifyFormulaRemoveEntries = void 0), h && (c.bounds = L.sanitizeRange(h)), Object.keys(c).length === 0 ? c.cycleId = s - 1 : (c.cycleId = s, e._cycleId++), l && (c.isFull = !0), e._fullCalcRequired = !1, e._options.onCalculated?.(c), this._calculation._getCalcingGraphs().delete(e._uuid), o(c);
});
});
}
_setInputs(t, e, n) {
const r = this._formulaSpatial;
let o = !r.isEmpty();
const s = e ? e.length : 0, i = this._calculation;
if ((s > 0 || o) && i.getStatus() === ee.Status.Starting) return this._addToPending(() => {
const x = this._setInputs(t, e, n), R = { formulaInserts: x.inserts ?? k.EmptyArray, formulaRemoves: x.removes ?? k.EmptyArray, cycleId: this._cycleId, bounds: L.unionRanges(L.unionRangesArrays(x.inserts), L.unionRangesArrays(x.removes)) };
return Promise.resolve(R);
}), cw;
const l = this._values.getOrientation() !== F.Orientation.Row, c = this._spillSpatial, h = this._errorSpatial, d = this._contentfulSpatial, u = [];
let g, m, f = o ? [] : null, p = this._values;
if (t && t.tuples) {
if (g = t.tuples, f) {
let x = t.bounds;
if (o) if (x) {
const M = Zo(x, l);
u.push(M);
} else {
const M = { colStart: Number.MIN_SAFE_INTEGER, rowStart: Number.MIN_SAFE_INTEGER, colEnd: Number.MAX_SAFE_INTEGER, rowEnd: Number.MAX_SAFE_INTEGER };
u.push(M);
}
const R = { majorStart: 0, minorStart: 0, majorEnd: 0, minorEnd: 0 }, A = g.length;
for (let M = 0; M < A; M++) {
const T = g[M], O = T[0];
R.majorStart = O, R.majorEnd = O;
const W = T[1], D = W.length;
for (let z = 0; z < D; z++) {
const B = W[z];
R.minorStart = B[0];
const H = B[1];
R.minorEnd = R.minorStart + H.length - 1;
const P = Zo(R, l);
f && r.search(P).length > 0 && f.push(P);
}
}
}
m = ad(t.tuples, l);
}
(n || g) && (fi(this._cycleId, n ? [n] : k.EmptyArray, m, d, c, p, u, this._notifyValues, this._notifySpills, this._notifyPending, h, l, !1), n && p.delete(n), g && p.setValues(g));
const _ = i._getContext(), S = i._getScope();
let C, y;
const E = this._getFormulaParser(), w = (x, R) => {
const A = x.rowStart, M = x.colStart, T = { ...x, value: null };
if (r.insertNonOverlapping(T, { noMerge: !0, onIntersect: (O, W) => O.value === null ? null : (y || (y = []), y.push(O), W) }), R !== null) {
S.rowIndex = A, S.colIndex = M, S.sheetName = this._options.getSheetName?.();
const O = E.parse(_, R), W = new vn(x, O), D = { ...x, value: W };
C || (C = []), C.push(D);
}
}, b = f ? f.length : 0;
for (let x = 0; x < b; x++) w(f[x], null);
for (let x = 0; x < s; x++) {
const R = e[x], A = R.value;
w(L.sanitizeRange(R), A);
}
const v = y ? y.length : 0, I = this._precedentSpatial;
for (let x = 0; x < v; x++) {
const R = y[x].value.calcs;
if (R) {
const A = R.length;
for (let M = 0; M < A; M++) {
const T = R[M], O = T.length;
for (let W = 0; W < O; W++) {
const D = T[W], z = D.dynamic;
if (z) {
const B = z.length;
for (let H = 0; H < B; H++) {
const P = z[H];
I.remove(P);
}
D.dynamic = null;
}
}
}
}
}
return (C || y) && (r._updateNodes(C, k.EmptyArray), fi(this._cycleId, y, C, d, c, p, u, this._notifyValues, this._notifySpills, this._notifyPending, h, l, !0)), (o || C || y) && this._invalidate(u), { inserts: this._notifyFormulaInsertEntries ?? k.EmptyArray, removes: this._notifyFormulaRemoveEntries ?? k.EmptyArray };
}
_invalidate(t) {
if (!t || t.length == 0) return;
const e = this._invalidations, n = an(t, F.Orientation.Column, 2);
for (let r = 0; r < n.length; r++) e.insertNonOverlapping(n[r]);
this._calculation._getCalcingGraphs().set(this._uuid, this._latest.graph), this._emitter?.notify("onInvalidate");
}
_markAndPlan(t, e, n) {
let r;
bo = 0, nl = 0, Fs = 0, vo = 0;
const o = this._precedentSpatial, s = this._formulaSpatial;
tl = 0, Ns = 0;
const i = this._cycleId, l = e.length;
for (let u = 0; u < l; u++) {
const g = e[u];
g.markId !== n && (g.markId = n, g.cycleId = i, g.inDegree = 0, Qa[bo++] = g, Za[Ns++] = g);
}
const c = (u, g, m) => {
(t || u.state === Dl) && (r || (r = []), r.push(g), t || m(u));
}, h = (u) => {
u.markId !== n && (u.markId = n, u.cycleId = i, u.inDegree = 0, Qa[bo++] = u, Za[Ns++] = u);
};
for (; tl < Ns; ) {
const u = Za[tl++], g = u.colIndex, m = u.rowIndex;
Vt.colStart = g, Vt.rowStart = m, Vt.colEnd = g, Vt.rowEnd = m;
const f = o.search(Vt), p = f.length;
if (p === 0) u.dependents = k.EmptyArray;
else for (let _ = 0; _ < p; _++) {
const S = f[_], C = S.value.once;
C ? c(C, S, h) : Yd(S, m, g, h);
}
}
for (let u = 0; u < bo; u++) {
const g = Qa[u], m = g.block, f = g.rowIndex, p = g.colIndex, _ = m.formula.getDirectPrecedentsAt(f, p);
let S = 0;
const C = g.precedents;
for (let y = 0; y < _.length; y++) {
const E = _[y];
if (E.isFormulaError) {
C[y] = E;
continue;
}
{
const A = E;
A.calc = void 0, C[y] = A;
}
const w = E.colStart, b = E.rowStart, v = E.colEnd, I = E.rowEnd, x = s.search(E), R = x.length;
for (let A = 0; A < R; A++) {
const M = x[A], T = M.colStart, O = M.rowStart, W = M.colEnd, D = M.rowEnd, z = Math.max(T, w), B = Math.max(O, b), H = Math.min(W, v), P = Math.min(D, I), j = M.value.calcs;
for (let G = B; G <= P; G++) {
const K = j[G - O];
for (let V = z; V <= H; V++) {
const $ = K[V - T];
$.markId === n && (E.calc = $, S++);
}
}
}
}
g.inDegree = S, g.inDegree === 0 && (el[Fs++] = g);
}
const d = (u) => {
u.markId === n && (u.inDegree--, u.inDegree === 0 && (el[Fs++] = u));
};
for (; nl < Fs; ) {
const u = el[nl++];
Qd[vo++] = u;
const g = u.colIndex, m = u.rowIndex;
Vt.colStart = g, Vt.rowStart = m, Vt.colEnd = g, Vt.rowEnd = m;
const f = o.search(Vt), p = f.length;
for (let _ = 0; _ < p; _++) {
const S = f[_], C = S.value.once;
C ? c(C, S, d) : Yd(S, m, g, d);
}
}
return vo < bo ? { completed: !1, onces: r } : { completed: !0, onces: r };
}
_evaluate(t) {
const e = this._calculation._getContext(), n = this._calculation._getScope();
n.sheetName = this._options.getSheetName?.();
let r = lw;
r.length = 0;
let o = 0, s = !0;
const i = this._cycleId, l = this._invalidations, c = this._contentfulSpatial, h = this._notifyValues, d = this._notifySpills, u = this._precedentSpatial, g = this._spillSpatial, m = this._values, f = m.getOrientation(), p = f === F.Orientation.Column;
let _;
n.spillSpatial = this._spillSpatial, n.values = m;
const S = e.getEntireCoords.bind(e);
let C;
for (let y = 0; y < vo; y++) {
const E = Qd[y];
if (E.state === ld && i === E.cycleId) {
E.state = Dl;
continue;
}
if (E.dynamic) {
for (let X = 0; X < E.dynamic.length; X++) {
const at = E.dynamic[X];
u.remove(at);
}
E.dynamic = null;
}
const w = E.block, b = E.colIndex, v = E.rowIndex;
let I = t ? void 0 : E.cachedValue, x = E.error;
!x && I && I.isFormulaError && (x = I);
let R = !1;
const A = E.precedents;
if (A) {
const X = A.length, at = E.inputs;
for (let ut = 0; ut < X; ut++) {
const tt = A[ut], rt = tt.calc;
if (rt && rt.pending) {
R = !0;
continue;
}
if (tt.isFormulaError) {
at[ut] = tt;
continue;
}
const ct = tt.colStart, lt = tt.rowStart, nt = tt.colEnd;
tt.rowEnd !== lt || ct !== nt ? (o > 0 && (r.length = o, Xd(r, m, h, p), o = 0), at[ut] = new es(m, null, { ...tt }, null, S)) : at[ut] = rt === void 0 ? tt : rt.cachedValue;
}
E.pendingPrecedents = R;
}
const M = p ? b : v, T = p ? v : b;
n.node = E, n.colIndex = b, n.rowIndex = v;
const O = w.formula;
let W, D;
const z = E.pending;
let B = z;
if ((R || E.pendingPromise) && (B = !0, W = E.cachedValue ?? null, E.pendingPromise && (E.pendingResolved ? (E.pendingPromise = null, E.pendingResolved = !1, B = !1) : (E.pendingPromise.cancelled = !0, W = void 0))), W === void 0 && (n.formula = O, n.colIndex = b, n.rowIndex = v, W = O.evaluate(e, void 0, E.inputs), n.formula = null, D = W && W.then ? W : null, B = !!D), B !== z && (E.pending = B, _ || (_ = Yn(p)), _.append(M, T, B)), D && (W = E.cachedValue ?? null, !D.__originator)) {
D.__originator = i;
const X = E;
Ts.add(X), X.pendingPromise = D, X.pendingResolved = !1, D.then((at) => {
if (Ts.delete(X), D.cancelled) return;
X.pendingPromise = D, X.pendingResolved = !0;
let ut = Gi(at, e);
ut === null && (ut = 0), X.cachedValue = ut, this._scheduleRecalculation(X);
}, (at) => {
});
}
let H = 1, P = 1;
const j = I instanceof me;
let G;
const K = I instanceof pt.Spill;
if (j || K) {
Co.colStart = b, Co.rowStart = v, Co.colEnd = b, Co.rowEnd = v;
const X = g.search(Co);
for (let at = 0; !G && at < X.length; at++) {
const ut = X[at];
ut.colStart === b && ut.rowStart === v && (G = ut);
}
if (G) {
if (j) {
const ut = I;
H = ut.getWidth(), P = ut.getHeight();
}
const at = { colStart: b, rowStart: v, colEnd: b + H - 1, rowEnd: v + P - 1 };
g.remove(G), G && G.value.getError() || (c.insertNonOverlapping({ ...at, value: null }), m.delete(at), h.insertNonOverlapping(at));
}
}
let V = 1, $ = 1;
const J = W, Z = J?.isIRange;
let q, Q = W instanceof pt.Spill;
if (Z && J.size > 1) {
V = J.getWidth(), $ = J.getHeight();
const X = { colStart: b, rowStart: v, colEnd: b + V - 1, rowEnd: v + $ - 1 }, at = e.getEntireCoords(), ut = !L.isRangeWithinRange(X, at);
if (ut && (X.colEnd = Math.min(X.colEnd, at.colEnd), X.rowEnd = Math.min(X.rowEnd, at.rowEnd)), Q = ut, !Q) {
const ct = c.search(X);
if (Q = ct.length > 1, !Q && ct.length === 1) {
const lt = ct[0], nt = L.intersectRanges(X, lt, Vt);
(nt && (nt.rowEnd !== nt.rowStart || nt.colStart !== nt.colEnd) || nt.colStart !== b || nt.rowStart !== v) && (Q = !0);
}
}
let tt, rt;
if (Q)
W = pt.BuiltIn.Spill, V = 1, $ = 1, tt = [[M, [[T, [W]]]]], m.setValues(tt), rt = { colStart: b, rowStart: v, colEnd: b, rowEnd: v };
else {
const ct = rw(J, M, T);
ct && (tt = ct.tuples), tt && m.setValues(tt), rt = X;
}
q = { ...X, value: new _r(X, i, Q) }, g.insert(q), C = jl(C, E, X), h.insertNonOverlapping(rt), l.insertNonOverlapping(rt), c.insertNonOverlapping({ ...rt, value: new Ye(rt, f) });
}
(!L.isEqualRanges(G, q) || Q || K) && (G && d.insert(G), q && d.insert(q)), V === H && $ === P || (E.state = ld, l.insertNonOverlapping({ colStart: b, rowStart: v, colEnd: b + Math.max(V, H) - 1, rowEnd: v + Math.max($, P) - 1 }), s = !1);
let it = W && W.isFormulaError ? W : null;
O.getError() && (it = O.getError()), (it || x && !t) && (it && !it.equals(x) || x && x.equals(it)), E.cachedValue = W, r[o++] = E;
}
if (n.node = null, n.colIndex = Number.MAX_SAFE_INTEGER, n.rowIndex = Number.MAX_SAFE_INTEGER, _) {
const y = _.done(!0);
this._notifyPending.load(y);
}
return o > 0 && (r.length = o, Xd(r, m, h, p), o = 0), { completed: s, dynamic: C, count: vo };
}
async calculate(t) {
const e = this._calculation.getStatus();
if (e === ee.Status.Starting) return void this._addToPending(() => this.calculate(t));
if (e !== ee.Status.Ready) return;
let n = this._fullCalcRequired;
n || (typeof t == "boolean" ? n = t : t && (n = t.full ?? !1));
const r = this._invalidations;
if (this._formulaSpatial.isEmpty()) {
if (r.clear(), Ts.size > 0) {
const h = ++Eo;
Ts.forEach((d) => {
d.markId = h;
});
}
return this._notifyCalculated(t);
}
let o = n;
const s = this._volatile;
let i = ++Eo, l = this._collectDirties(i, o, r.all(), s);
if (r.clear(), s.clear(), !o && l.length === 0) return this._notifyCalculated(t);
o && this._clearCalcs();
const c = this._resetScope();
for (; l.length > 0; ) {
i = ++Eo;
const h = this._markAndPlan(o, l, i).onces;
if (h) {
const u = this._precedentSpatial, g = h.length;
for (let m = 0; m < g; m++) u.remove(h[m], Kd);
}
l.length = 0;
const d = this._evaluate(o);
if (d.dynamic && this._precedentSpatial.load(d.dynamic), c.dynamicPrecedentsInserts && (this._precedentSpatial.load(c.dynamicPrecedentsInserts), c.dynamicPrecedentsInserts = []), c.conflatingFormats) {
const u = c.conflatingFormats.done(!0), g = this._notifyFormats;
for (let m = 0; m < u.length; m++) {
const f = u[m];
g.insertNonOverlapping(f);
}
c.conflatingFormats = null;
}
d.completed || (o = !1, i = ++Eo, l = this._collectDirties(i, o, r.all(), s), r.clear());
}
return this._clearScope(), this._notifyCalculated(t);
}
_clearScope() {
const t = this._calculation._getScope();
t && (t.rowIndex = 0, t.colIndex = 0, t.node = null, t.values = this._values, t.formulaSpatial = this._formulaSpatial, t.volatile = this._volatile, t.conflatingFormats = null, t.dynamicPrecedentsInserts = null, t.formula = null, t.getEntireCoords = Fl);
}
_resetScope() {
const t = this._calculation._getScope();
if (t) return t.rowIndex = 0, t.colIndex = 0, t.node = null, t.values = this._values, t.formulaSpatial = this._formulaSpatial, t.volatile = this._volatile, t.conflatingFormats = null, t.dynamicPrecedentsInserts = null, t.formula = null, t.getEntireCoords = this._getEntireCoords, t;
}
_clearCalcs() {
const t = this._values, e = this._spillSpatial, n = this._contentfulSpatial, r = e.all();
for (let o = 0; o < r.length; o++) {
const s = r[o];
s.value.getError() || (t.delete(s), n.insertNonOverlapping({ ...s, value: null }));
}
e.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++, Eo++, 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(t) {
this._calculation._getCalcingGraphs().set(this._uuid, this._latest.graph);
let e = this._pendingActions;
if (!e) {
this._pendingActions = e = [];
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: () => {
} }, dw);
}
e.push(t);
}
fromJSON(t) {
const e = this._calculation.getStatus();
if (e === ee.Status.Starting) return void this._addToPending(() => Promise.resolve(this.fromJSON(t)));
if (e !== ee.Status.Ready) return;
this._clearAll();
const n = { cycleId: 0, isFull: !0 };
if (!t) return n;
this._isProcessingJSON = !0;
try {
if (t.data) {
const s = t.data;
this._values.setValues(s);
const i = this._values.getOrientation() === F.Orientation.Column, l = ad(s, i);
this._contentfulSpatial.load(l);
}
const r = this._formulaSpatial, o = t.formulas;
if (o) {
const s = t.dynamic, i = /* @__PURE__ */ new Set();
if (s) {
const _ = s.length;
for (let S = 0; S < _; S++) {
const C = s[S], y = C[0].split(":")[0];
i.add(y);
}
}
const l = o.length, c = new Array(l), h = [], d = [], u = this._calculation._getContext(), g = this._calculation._getScope();
g.colIndex = 0, g.rowIndex = 0;
const m = this._getFormulaParser();
for (let _ = 0; _ < l; _++) {
const S = o[_], C = S[0], y = Ae(C), E = S[1], w = y.rowStart, b = y.colStart;
g.colIndex = b, g.rowIndex = w;
let v = m.parse(u, E);
const I = v.getDirectPrecedentsAt(w, b, !0, As, Ms), x = I.length;
x === 1 && (v = v.wrapImplicit(w, b, i));
const R = { ...y }, A = new vn(R, v);
y.value = A, c[_] = y;
const M = y.rowEnd, T = y.colEnd - b, O = M - w, W = [];
for (let D = 0; D < x; D++) {
const z = I[D];
if (z instanceof pt.Known) continue;
const B = As[D], H = Ms[D], P = { colStart: z.colStart, rowStart: z.rowStart, colEnd: z.colEnd + (H ? 0 : T), rowEnd: z.rowEnd + (B ? 0 : O), value: { blockEntry: y, width: T + 1, height: O + 1, index: D, $absWidth: H, $absHeight: B, once: null } };
W.push(z), d.push(P);
}
h.push({ colStart: R.colStart, rowStart: R.rowStart, colEnd: R.colEnd, rowEnd: R.rowEnd, value: { tokens: v.getTokens(), references: v.getReferences(), precedents: W } });
}
if (r.load(c), this._precedentSpatial.load(d), h.length > 0 && (n.formulaInserts = h), s) {
const _ = [], S = [];
let C;
const y = this._values, E = s.length;
for (let w = 0; w < E; w++) {
const b = s[w], v = b[0], I = Ae(v), x = b[1], R = { ...I }, A = R.colStart, M = R.rowStart, T = R.colEnd, O = R.rowEnd;
Or.colStart = A, Or.rowStart = M, Or.colEnd = A, Or.rowEnd = M;
const W = r.search(Or);
if (W.length !== 1) continue;
const D = W[0].value, z = D.ref, B = D.calcs, H = M - z.rowStart, P = A - z.colStart, j = B[H][P];
if (x) j.cachedValue = pt.BuiltIn.Spill;
else {
const K = new me(y, R);
j.cachedValue = K;
}
I.value = new _r(R, 0, x), S.push(I);
const G = { colStart: A, rowStart: M, colEnd: T, rowEnd: O, value: x };
L.isSingleCell(G) || _.push(G), jl(C, j, R);
}
this._spillSpatial.load(S), this._precedentSpatial.load(C), _.length > 0 && (n.spillInserts = _);
}
const f = t.volatile, p = f ? f.length : 0;
if (p > 0) {
const _ = this._volatile, S = (C) => {
_.add(C);
};
for (let C = 0; C < p; C++) {
const y = f[C], E = Ae(y, Or), w = r.search(E), b = w.length;
for (let v = 0; v < b; v++) {
const I = w[v];
ow(I, E, S);
}
}
}
}
} catch (r) {
throw r;
} finally {
this._isProcessingJSON = !1;
}
return n;
}
async toJSON(t = !1) {
const e = this._formulaSpatial.all(), n = e.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 = e[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 d = o[h], u = kn(d, l);
c[h] = [u, d.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() === F.Orientation.Column, d = Yn(!0);
for (; !c.done; ) {
const f = c.value;
if (Array.isArray(f)) for (let p = 0; p < f.length; p++) {
const _ = f[p];
for (let S = 0; S < _.length; S++) {
const C = _[S], y = C.colIndex, E = C.rowIndex, w = h ? y : E, b = h ? E : y;
d.append(w, b);
}
}
else {
const p = f.colIndex, _ = f.rowIndex, S = h ? p : _, C = h ? _ : p;
d.append(S, C);
}
c = l.next();
}
const u = d.done(!0), g = u.length, m = new Array(g);
for (let f = 0; f < g; f++) {
const p = u[f], _ = kn(p, this._getEntireCoords());
m[f] = _;
}
r.volatile = m;
}
return r;
}
}
const Xd = (a, t, e, n) => {
const r = new zt.Builder(iw), o = Yn(n);
a.sort(n ? L.columnFirstCellComparator : L.rowFirstCellComparator);
const s = a.length;
for (let c = 0; c < s; c++) {
const h = a[c], d = h.colIndex, u = h.rowIndex;
if (!h.cachedValue?.isIRange) {
const m = n ? d : u, f = n ? u : d;
let p = h.cachedValue;
r.addValue(m, f, p), o.append(m, f);
}
}
const i = r.build();
i && i.tuples && t.setValues(i.tuples);
const l = o.done(!0);
for (let c = 0; c < l.length; c++) {
const h = l[c];
e.insertNonOverlapping(h);
}
}, ow = (a, t, e) => {
const n = a.colStart, r = a.rowStart, o = a.colEnd, s = a.rowEnd, i = t.colStart, l = t.rowStart, c = t.colEnd, h = t.rowEnd, d = Math.max(n, i), u = Math.max(r, l), g = Math.min(o, c), m = Math.min(s, h), f = a.value.calcs;
for (let p = u; p <= m; p++) {
const _ = p - r, S = f[_];
for (let C = d; C <= g; C++) {
const y = C - n;
e(S[y], _, y);
}
}
}, Yd = (a, t, e, n) => {
const r = a.value, o = r.$absHeight, s = r.$absWidth, i = r.width, l = r.height, c = r.blockEntry.value.calcs, h = e - a.colStart, d = t - a.rowStart, u = Math.min(Math.max(h, 0), i - 1), g = Math.min(Math.max(d, 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][u]);
else for (let m = 0; m < l; m++) {
const f = c[m];
for (let p = 0; p < i; p++)
n(f[p]);
}
else
n(c[g][u]);
}, sw = { rowIndex: 0, colIndex: 0 }, Vt = { rowStart: 0, colStart: 0, rowEnd: 0, colEnd: 0 }, As = [], Ms = [], Or = { rowStart: 0, colStart: 0, rowEnd: 0, colEnd: 0 }, Co = { rowStart: 0, colStart: 0, rowEnd: 0, colEnd: 0 };
new pt.Calc("Cyclical dependency");
const iw = (a) => new Ve(a);
let Eo = 0;
const br = 1e4, aw = new Array(br), lw = new Array(br), Ts = /* @__PURE__ */ new Set(), Qa = new Array(br);
let bo = 0;
const Za = new Array(br);
let tl = 0, Ns = 0;
const el = new Array(br);
let nl = 0, Fs = 0;
const Qd = new Array(br);
let vo = 0;
const Zd = new Array(br), xo = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0 }, Io = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0 }, rl = [null, null], cw = Object.freeze({ inserts: k.EmptyArray, removes: k.EmptyArray });
function hw(a, t, e, n) {
const r = a;
if (r?.getSplit) {
const o = r.getSplit(t, e, n);
if (o === void 0) return;
t[0].value = o[0], t[1].value = o[1];
}
return t;
}
const dw = Object.freeze({ once: !0 });
class uw {
constructor(t, e = !0) {
this._options = { ...fw, ...t }, this._getFunction = this._options.getFunction, this._isColumn = e;
}
_setInstanceScope(t) {
this._instanceScope = t;
}
async _initialize() {
const t = await ju._validate(!0), e = mw();
this._calcScope = e, this._runtime = new gw(this._options, t);
const { initializeBuiltIns: n } = await import("./Dxfd2MfY8kHHUtnu.mjs"), r = this;
return this._builtInFunctions = Object.freeze(n(() => r)), { builtInFunctions: this._builtInFunctions, calcScope: this._calcScope };
}
getBuiltInFunctions() {
return this._builtInFunctions;
}
getFunction(t) {
return this._builtInFunctions.get(t) ?? this._getFunction?.(t);
}
getNumberFormat(t, e) {
return Ne.Parser.formatValue(t, e, { date1904: this._options.isDate1904?.() ?? !1 });
}
getEntireCoords() {
return this._calcScope.getEntireCoords();
}
getFormulaAt(t, e) {
const n = this._calcScope.formulaSpatial;
if (!n) return null;
Ro.colStart = e, Ro.rowStart = t, Ro.colEnd = e, Ro.rowEnd = t;
const r = n.search(Ro);
return r.length === 0 ? null : r[0].value.formula.getTextAt(t, e) ?? null;
}
markVolatile() {
const t = this._calcScope, e = t.volatile;
e && e.add(t.node);
}
formatResults(t) {
const e = this._calcScope, n = this._isColumn, r = n ? e.colIndex : e.rowIndex, o = n ? e.rowIndex : e.colIndex;
e.conflatingFormats || (e.conflatingFormats = Yn(n)), e.conflatingFormats.append(r, o, t);
}
getSheetIndex(t) {
const e = this._calcScope;
return t === void 0 && (t = e.sheetName), this._options.getSheetIndex?.(t) ?? -1;
}
getSheetCount() {
return this._options.getSheetCount?.() ?? 1;
}
isValidDate(t) {
return ro(t);
}
fromOADate(t) {
return oo(t, this._options.isDate1904?.() ?? !1);
}
toOADate(t) {
return rs(t, this._options.isDate1904?.() ?? !1);
}
_fromTuples(t, e = null, n = !1) {
if (!t) return null;
const r = Zo(t.bounds, !0), o = this._calcScope, s = this._isColumn ? F.Orientation.Column : F.Orientation.Row, i = new hn({ orientation: s, maxCoords: o.getEntireCoords() });
return i.setValues(t.tuples), new me(i, r, e, n);
}
getValueAt(t, e) {
return this._calcScope.values.getValueAt(t, e) ?? null;
}
getSpillAt(t, e) {
const n = this._calcScope.spillSpatial;
if (!n) return null;
Ao.rowStart = t, Ao.colStart = e, Ao.rowEnd = t, Ao.colEnd = e;
const r = n.search(Ao);
if (r.length === 0) return null;
for (let o = 0; o < r.length; o++) {
const s = r[o];
if (s.rowStart === t && s.colStart === e) return this.getReference(L.sanitizeRange(s));
}
return null;
}
getRange(t, e) {
if (t?.isIRange) return t;
let n;
const r = Array.isArray(t);
if (e = e ?? r, r) if (Array.isArray(t[0])) n = t;
else {
if (t[0]?.isIRange) throw pt.BuiltIn.Value;
n = [t];
}
else n = [[t]];
const o = this._isColumn, s = o ? F.Orientation.Column : F.Orientation.Row, i = this._fromTuples(xi(n, o, Te(0, 0, void 0, void 0, o), !0), void 0, e);
if (i) return i;
const l = new hn({ orientation: s, maxCoords: this._calcScope.getEntireCoords() });
return new me(l, L.EmptyRange, void 0, e);
}
getPosition() {
const t = this._calcScope;
return { colIndex: t.colIndex, rowIndex: t.rowIndex };
}
getReference(t, e) {
if (!t) throw pt.BuiltIn.Ref;
const n = this._calcScope, r = n.getEntireCoords;
if (typeof t == "string") {
if (e) throw pt.BuiltIn.Ref;
try {
const c = qi(t, r(), ls, () => {
throw pt.BuiltIn.Ref;
}, e);
if (c.length > 1) throw pt.BuiltIn.Ref;
t = c[0];
} catch {
throw pt.BuiltIn.Ref;
}
}
if (!t) throw pt.BuiltIn.Ref;
const o = n.values;
let s;
const i = n.node;
let l;
if (i) {
const c = i.precedents;
l = pw(c, t);
}
if (l) {
const c = l.calc;
s = c && c.isIReferenceRange ? c.cachedValue : new es(o, void 0, t, null, r);
} else n.dynamicPrecedentsInserts = jl(n.dynamicPrecedentsInserts, i, t), s = new es(o, void 0, t, null, r);
return s;
}
getAddress(t, e = !1) {
t || (t = this.getPosition());
const n = this.getEntireCoords().sheetName;
return t.colIndex !== void 0 ? ((r, o, s = !1) => s ? hi(r, o) : Da(r, o))(t, n, e) : ((r, o, s = !1) => (s ? hi({ colIndex: r.colStart, rowIndex: r.rowStart, $colIndex: r.$colStart, $rowIndex: r.$rowStart, sheetName: r.sheetName }, o) : Da({ 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) : Da({ colIndex: r.colEnd, rowIndex: r.rowEnd, $colIndex: r.$colEnd, $rowIndex: r.$rowEnd }, null)))(t, n, e);
}
parseAsDateTime(t, e = !1) {
return (function(n, r = !1, o = !1) {
let s = n, i = mg(n, r, !0);
i && (s = i.leadingText);
let l = null;
if (s.trim().length > 0 && (l = Ql(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;
})(t, this._options.isDate1904?.() ?? !1, e);
}
getRuntime() {
return this._runtime;
}
get [Symbol.toStringTag]() {
return "[CalculationContext]";
}
toString() {
let t = "";
const e = this._instanceScope;
let n;
return e && (n = e.toString?.()), n && n && (t = `${t}:[${n}]`), t;
}
}
class gw {
constructor(t, e) {
this._options = t, this._license = e;
}
getCurrencySymbol() {
return "$";
}
getNumberDecimalSeparator() {
return ".";
}
getNumberGroupSeparator() {
return ",";
}
isDate1904() {
return this._options.isDate1904?.() ?? !1;
}
getDescription() {
return "Calculation Runtime";
}
getLocation() {
return k.isNode() ? process.cwd() : window.location?.href ?? "/";
}
getVersion() {
try {
const t = "0.7.27";
if (t.indexOf(".env.") === -1) return `${t}`;
} catch {
return "local";
}
}
getOS() {
return k.getOS();
}
getUser() {
return this._license?.getLicensee?.() ?? null;
}
}
const mw = () => ({ rowIndex: 0, colIndex: 0, sheetName: null, node: null, values: null, formulaSpatial: null, spillSpatial: null, volatile: null, conflatingFormats: null, dynamicPrecedentsInserts: null, formula: null, getEntireCoords: () => is }), fw = { getSheetIndex: (a) => -1, getSheetCount: () => 1, getSheetName: () => null, getEntireCoords: () => is, getNamed: (a, t) => null, getFunction: (a) => null, isDate1904: () => !1 }, pw = (a, t) => {
if (!a) return;
const e = a.length;
if (e === 0) return;
const n = t.colStart, r = t.rowStart, o = t.colEnd, s = t.rowEnd;
for (let i = 0; i < e; 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;
}, Ro = { rowStart: 0, colStart: 0, rowEnd: 0, colEnd: 0 }, Ao = { rowStart: 0, colStart: 0, rowEnd: 0, colEnd: 0 };
class _w {
_setScope(t) {
this._scope = t;
}
_getScope(t = !1) {
const e = this._scope;
if (!e && !t) throw new Error("FunctionContext can only be used in a function.");
return e;
}
getNumberFormat(t, e) {
return this._getScope().getNumberFormat(t, e);
}
getEntireCoords() {
return this._getScope().getEntireCoords() ?? is;
}
isValidDate(t) {
return this._getScope().isValidDate(t);
}
parseAsDateTime(t, e) {
return this._getScope().parseAsDateTime(t, e);
}
fromOADate(t) {
return this._getScope().fromOADate(t);
}
toOADate(t) {
return this._getScope().toOADate(t);
}
getRange(t) {
return this._getScope().getRange(t);
}
getValueAt(t, e) {
return this._getScope().getValueAt(t, e);
}
getPosition() {
return this._getScope().getPosition?.() ?? B0;
}
getReference(t, e) {
return this._getScope().getReference(t, e);
}
getFormulaAt(t, e) {
return this._getScope().getFormulaAt?.(t, e) ?? null;
}
getSpillAt(t, e) {
return this._getScope().getSpillAt?.(t, e) ?? null;
}
getSheetIndex(t) {
return this._getScope().getSheetIndex?.(t) ?? -1;
}
getSheetCount() {
return this._getScope().getSheetCount?.() ?? 1;
}
markVolatile() {
this._getScope().markVolatile?.();
}
formatResults(t) {
this._getScope().formatResults?.(t);
}
getFunction(t) {
return this._getScope().getFunction?.(t) ?? null;
}
getAddress(t, e) {
return this._getScope().getAddress(t, e);
}
getRuntime() {
return this._getScope().getRuntime();
}
get [Symbol.toStringTag]() {
return "[FormulaContext]";
}
toString() {
const t = this._getScope();
if (t) {
const e = t.toString?.();
if (e) return e;
}
return t ? "" : "{NO SCOPE}";
}
}
const Sw = new _w(), Ni = "__SHEETXL";
let mr;
const tu = { FormulaContext: mr, ScalarType: Y, IRange: F, FormulaError: pt, Observable: jm };
let pi;
function gc(a) {
mr || (mr = Sw, tu.FormulaContext = mr), pi = globalThis[Ni], globalThis[Ni] = tu, mr._setScope(a);
}
function Fi() {
pi ? (globalThis[Ni] = pi, pi = void 0) : delete globalThis[Ni], mr && mr._setScope(null);
}
var An;
(An || (An = {})).Context = { Workbook: "workbook", Sheet: "sheet", Ranges: "ranges", Range: "range", Calculation: "calculation" };
class ki {
constructor(t, e, n, r = null, o = !1) {
this._ct = An.Context.Calculation, this._builtIn = !1, this._broadcast = !1, this._pj = null, this._json = t, this._n = t.name, this._d = new Ew(t), this._ct = t.context ?? An.Context.Calculation;
const s = t.parameters;
let i;
this._pj = s, e || (console.log(`TypeFunction '${t.name}' was not provided a function implementation.`), e = () => {
}), this._fn = e.bind(this), this._cf = n ?? yw, this._builtIn = o, i = r ? typeof r == "function" ? r : () => Promise.resolve(r) : ww(t), 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(...t) {
const e = this._pj, n = [], r = this._cf?.();
gc(r);
let o = !1, s = null;
const i = e?.length ?? 0;
let l, c = this._broadcast;
if (c) {
const h = nd(t[0]);
if (i === 1 && h) c = !1;
else if (i === 2) {
const d = nd(t[1]);
h && d && (c = !1);
}
}
try {
for (let d = 0; !o && d < i; d++) {
const u = e[d];
let g = u.scalar ?? null;
g !== Y.Null && g !== "*" || (g = null);
let m = u.range ?? null;
const f = u.rest ?? !1, p = u.optional ?? !1;
let _ = t[d];
if (p && _ === null && (_ = void 0), _ === void 0) {
if (p) {
n.push(void 0);
continue;
}
if (!p && !f) throw d <= t.length ? nu.ARGS_TOO_FEW([u.name], this._n) : nu.PARAM_MISSING(u.name, this._n);
if (d >= t.length) {
o = !0;
continue;
}
}
const S = u.arrayDepth ?? 0;
let C = (u.range ? 2 : 0) + S;
const y = u.rest ?? !1;
if (y) for (; d < t.length && !s; ) _ !== void 0 && (s = $l(r, n, _, g, m, S, y, C)), _ = t[++d];
else c && (m = "l", C = 2), s = $l(r, n, _, g, m, S, y, C), 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 d = n[0];
let u = e[0].scalar;
u !== Y.Null && u !== "*" || (u = null), l = d.map((g) => {
if (g instanceof pt.Known) return g;
let m = g;
try {
m = h(m), (Array.isArray(m) || m?.isIRange) && (m = pt.BuiltIn.Value);
} catch (f) {
m = f;
}
return m;
}, { type: u });
}
if (n.length === 2) {
const d = n[0];
let u = e[0].scalar;
u !== Y.Null && u !== "*" || (u = null);
const g = n[1];
let m = e[1].scalar;
m !== Y.Null && m !== "*" || (m = null), l = d.broadcast(g, (f, p) => {
if (f instanceof pt.Known) return f;
if (p instanceof pt.Known) return p;
let _;
try {
_ = h(f, p), (Array.isArray(_) || _?.isIRange) && (_ = pt.BuiltIn.Value);
} catch (S) {
_ = S;
}
return _;
}, { type: u, otherType: m });
}
} else l = h(...n);
l = Gi(l, r);
} catch (h) {
throw h;
} finally {
Fi();
}
return l;
}
getName() {
return this._n;
}
getDeclaration() {
return this._d;
}
async getDescriptor(t) {
if (this._desc) return this._desc;
const e = await Promise.resolve(this._descFn(t));
return this._desc = new bw(this, e), this._desc;
}
isBuiltIn() {
return this._builtIn;
}
getContext() {
const t = this._ct;
if (t === "sheet" || t === "workbook" || t === "ranges" || t === "range") {
const e = this._json;
return e && e.behavior && e.behavior.default ? "autoRun" : "macro";
}
return "formula";
}
get [Symbol.toStringTag]() {
return "[TypedFunction]";
}
toString() {
let t = "";
const e = this._pj;
return e.length > 0 && (t = e.map((n) => {
let r = n.name;
return n.rest && (r = "..." + r), n.optional && (r += "?"), r += ": " + ((o, s) => {
if (s) {
const i = z0.get(s) ?? "InvalidRange";
return o ? `${i}<${ed.get(o) ?? "InvalidScalar"}>` : i;
}
return ed.get(o) ?? "InvalidScalar";
})(n.scalar, n.range), r += "[]".repeat(n.arrayDepth), r;
}).join(", ")), `${this.getName()}(${t})`;
}
get isIFunction() {
return !0;
}
get isITypedFunction() {
return !0;
}
}
const ww = (a) => async (t) => {
const e = {};
for (let n = 0; n < a.parameters.length; n++) e[a.parameters[n].name] = k.camelToPrettyCase(a.parameters[n].description);
return { summary: k.camelToPrettyCase(a.name), parameters: e, category: "User Defined" };
}, yw = () => null;
class km {
constructor(t) {
this._s = t.scalar, this._r = t.range ?? null, this._d = t.arrayDepth ?? 0;
}
getScalarType() {
return this._s;
}
getRangeType() {
return this._r;
}
getArrayDepth() {
return this._d;
}
}
class Cw extends km {
constructor(t) {
super(t), this._n = t.name, this._o = t.optional ?? !1, this._rest = t.rest ?? !1, this._e = t.enums ? Object.freeze(t.enums) : k.EmptyArray;
}
getName() {
return this._n;
}
isOptional() {
return this._o;
}
isRest() {
return this._rest;
}
getEnums() {
return this._e;
}
}
class eu extends km {
constructor(t) {
super(t), this._a = t.async ?? !1, this._stream = t.stream ?? !1;
}
isAsync() {
return this._a;
}
isStreaming() {
return this._stream;
}
}
class Ew {
constructor(t) {
if (this._n = t.name, t.parameters) {
const e = t.parameters.length, n = new Array(e);
for (let r = 0; r < e; r++) n[r] = new Cw(t.parameters[r]);
this._p = Object.freeze(n);
} else this._p = k.EmptyArray;
t.returnType ? this._r = new eu(t.returnType) : this._r = new eu({ scalar: null, arrayDepth: 0, range: null });
}
getName() {
return this._n;
}
getParameters() {
return this._p;
}
getReturnType() {
return this._r;
}
}
class bw {
constructor(t, e) {
if (this._n = e.name, this._fn = t, this._s = e.summary ?? k.camelToPrettyCase(e.name), this._c = e.category ?? "Uncategorized", this._h = e.hidden ?? !1, e.links && e.links.length > 0) {
const n = e.links.length, r = new Array(n);
for (let o = 0; o < n; o++) r[o] = Object.freeze([e.links[o][0], e.links[o][1]]);
this._l = Object.freeze(r);
} else this._l = k.EmptyArray;
if (e.parameters) {
for (const n in e.parameters) if (Object.prototype.hasOwnProperty.call(e.parameters, n)) {
const r = e.parameters[n].description, o = e.parameters[n].example, s = e.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 t = this._fn;
return `${this.getSummary()}: ${t}`;
}
}
const $l = (a, t, e, n, r, o, s, i) => {
if (e && e.colStart !== void 0) if (r) e = a.getReference?.(e);
else {
const l = e.colStart, c = e.rowStart, h = e.colEnd;
e = e.rowEnd !== c || l !== h ? a.getReference?.(e) : a.getValueAt(c, l);
}
if (i === 0) {
let l = ((c, h = null, d = !1) => {
let u = c;
for (; Array.isArray(u); ) {
if (u.length > 1) return d ? pt.BuiltIn.Value : u;
u = u[0];
}
if (u?.isIRange) {
if (u.size !== 1) return d ? pt.BuiltIn.Value : u;
u = u.getValueAt(0, 0);
}
return h && (u = Xe(u, _e(u, !0), h)), u;
})(e, n, !0);
return l instanceof pt.Known ? l : void t.push(l);
}
if (i === 2) return wo(a, t, e, n, r, Array.isArray(e));
if (i === 1 || i === 3) {
let l;
const c = s ? t : [];
if (r) {
const h = Array.isArray(e);
if (h) {
const d = e.length;
for (let u = 0; !l && u < d; u++) l = wo(a, c, e[u], n, r, h);
} else l = wo(a, c, e, n, r, h);
} else if (i === 3) {
let h = ((d) => {
let u = d, g = 0;
for (; Array.isArray(u); ) g++, u = u[0];
return u.isIRange && (g += 2), g;
})(e);
for (let d = h; d < 2; d++) e = [e], h++;
if (h === 3) {
const d = e.length;
for (let u = 0; !l && u < d; u++) l = wo(a, c, e[u], n, r, !0);
} else l = wo(a, c, e, n, r, !0);
} else l = Zg(a, c, e, n, r, r !== null);
return l?.isFormulaError ? l : void (s || t.push(c));
}
{
if (!Array.isArray(e)) {
if (n && (e = Xe(e, _e(e, !0), n, !1), e?.isFormulaError)) return t.push(e), e;
e = [e];
}
const l = e.length;
for (let c = 0; c < l; c++) {
const h = [], d = $l(a, h, e[c], n, r, o, s, i - 1);
if (d?.isFormulaError) return d;
h.length > 0 && t.push(h);
}
}
}, nu = { PARAM_MISSING: (a, t) => new pt.NA(`Parameter ${a} is missing${t ? ` for ${t}` : ""}.`), ARGS_TOO_FEW: (a, t) => new pt.Parse(`Argument type ${a.join(", ")} is missing${t ? ` for ${t}` : ""}.`) };
class Om {
constructor(t) {
this._emitter = null, this._readonly = null, this._closed = !1, this._options = { ...t };
const e = this;
this._transactions = this._options.transactions ?? new Ze({ transient: !0 }), this._transactionsRemoveListener = this._transactions.addStateListener(this, { onAfterStateChange(n, r, o) {
e._emitter.notify("onCollectionChange");
} }), this._emitter = new he(this, this._transactions), this._readonly = t?.readonlyFunctions, this._initState();
}
getItems(t) {
const e = this._getState();
if (!e) return k.EmptyArray;
const n = Array.from(e.itemsByKey.values()), r = this._readonly;
return r && n.push(...Array.from(r.values())), n;
}
getByName(t) {
if (!t) return null;
const e = this._getState();
if (!e) return null;
if (!e) return k.EmptyArray;
const n = t.toUpperCase(), r = this._readonly;
if (!r || !r.size) return null;
let o = r.get(n);
return o || (o = e.itemsByKey.get(n), o || null);
}
async search(t) {
const e = this._getState();
if (!e) return k.EmptyArray;
const n = t?.name ? t.name.toUpperCase() : null, r = t?.type ? t.type : null;
let o;
const s = t?.category ? t.category.toUpperCase() : null, i = t?.text ? t.text.toUpperCase() : null, l = !!s || !!i;
let c;
const h = async (u, g) => {
if (n && g !== n || r && u.getContext() !== r) return !1;
if (l) {
c || (c = []);
const m = u.getDescriptor();
c.push(m);
const f = await m;
if (i && !f.getSummary().toUpperCase().includes(i) || s && f.getCategory().toUpperCase() !== s) return !1;
}
o || (o = []), o.push(u);
}, d = this._readonly;
return d && d.forEach(h), e.itemsByKey.forEach(h), c && await Promise.all(c), o ?? k.EmptyArray;
}
getCount() {
const t = this._getState();
if (!t) return 0;
let e = t.itemsByKey.size;
return this._readonly && (e += this._readonly.size), e;
}
validateName(t) {
return this._validateName(t);
}
_validateName(t, e = !1) {
if (this._closed) throw new Error(We);
}
add(t) {
if (this._closed) throw new Error(We);
if (!t) throw new Error("Item must be specified.");
let e;
if (t.isIFunction) {
const o = t, s = t._json;
e = new ki(s, o._fn, () => this._options.context, o._desc);
} else {
const o = t;
e = new ki(o.declaration, o.execute, () => this._options.context, o.descriptor);
}
const n = this._getState(), r = e.getName().toUpperCase();
return n.itemsByKey.set(r, e), e;
}
beginCommit(t) {
return this._beginCommit(t);
}
_getState() {
if (this._closed) throw new Error(We);
return this._transactions.getState(this);
}
_beginCommit(t) {
return this._transactions.beginCommit(typeof t == "string" ? { description: t } : t);
}
_updateState(t, e = "Update", n) {
if (!t) return;
const r = this._beginCommit(e);
try {
r.updateState(this, t), r.commit(n);
} catch (o) {
throw r.rollback(), o;
}
}
_initState() {
this._updateState((t) => ({ ...t, itemsByKey: /* @__PURE__ */ new Map() }), "Initialize", { forceAmend: !0 });
}
addListeners(t, e) {
return this._emitter.addListeners(t, e);
}
isClosed() {
return this._closed;
}
close() {
this._closed || (this._emitter.notify("onClose"), this._closed = !0, this._transactionsRemoveListener?.());
}
get isFunctionCollection() {
return !0;
}
}
class Dm extends Er {
constructor(t) {
super(t), this._graphsCalcing = /* @__PURE__ */ new Map(), this._graphsAll = /* @__PURE__ */ new Map(), this._status = ee.Status.Off, this._statusTransition = null, this._emitter = new he(this);
}
_getContext() {
return this._context;
}
_getScope() {
return this._scope;
}
_getCalcingGraphs() {
return this._graphsCalcing;
}
_getAllGraphs() {
return this._graphsAll;
}
start() {
return this._statusTransition || (this._statusTransition = (async () => {
if (this._status === ee.Status.Off) try {
this._status = ee.Status.Starting, this._emitter.notify("onStatusChange"), this._emitter.notify("onStarting");
const t = this, e = this._options, n = (l) => t.getFunctions().getByName(l) ?? e?.getFunction?.(l), r = new uw({ ...e, getFunction: n });
this._context = r;
const o = await r._initialize(), s = o.builtInFunctions;
this._functions = new Om({ transactions: this._transactions, context: r, readonlyFunctions: s });
const i = await import("./zoqPtKWJmGQs1ZUb.mjs");
this._formulaParser = new i.FormulaParser(), this._scope = o.calcScope, this._status = ee.Status.Ready, this._emitter.notify("onStatusChange"), this._emitter.notify("onReady");
} catch (t) {
throw this._status = ee.Status.Off, this._emitter.notify("onError", t), this._emitter.notify("onStatusChange"), t;
} finally {
this._statusTransition = null;
}
})()), this._statusTransition;
}
_createGraph(t) {
const e = this._options;
return new uc({ ...e, ...t, getFormulaParser: () => this._formulaParser, calculation: this });
}
async stop() {
this._status === ee.Status.Ready && (this._status = ee.Status.Stopping, this._emitter.notify("onStatusChange"), this._emitter.notify("onStopping"), this._status = ee.Status.Off, this._emitter.notify("onStatusChange"), this._emitter.notify("onStop"));
}
getStatus() {
return this._status;
}
async ready(t) {
this._status === ee.Status.Starting && await this._statusTransition;
const e = t?.full ?? !1 ? this._getAllGraphs() : this._getCalcingGraphs();
if (e.size === 0) return ru;
const n = e.values(), r = [];
for (const o of n) r.push(o.calculate(t));
return await Promise.all(r), ru;
}
getFunctions() {
return this._checkReady(), this._functions;
}
getRuntime() {
return this._checkReady(), this._runtime;
}
_checkReady() {
if (this._status !== ee.Status.Ready) throw new Error(this._statusMessage());
}
_statusMessage() {
switch (this._status) {
case ee.Status.Off:
return "Calculation is off";
case ee.Status.Starting:
return "Calculation is starting";
case ee.Status.Ready:
return "Calculation is ready";
default:
return "Unknown calculation status";
}
}
get [Symbol.toStringTag]() {
return "[Calculation]";
}
toString() {
return "Calculation";
}
}
const ru = Promise.resolve();
var ou, su;
ou || (ou = {}), su || (su = {});
const yy = Object.freeze(Object.defineProperty({ __proto__: null, nowWithPrecision: (a = 6e4) => new Date(Math.floor(Date.now() / a) * a) }, Symbol.toStringTag, { value: "Module" }));
var iu, au, ks, Gl, Os, on;
iu || (iu = {}), (ks = au || (au = {})).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 = Gl || (Gl = {})).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" }, (on || (on = {})).HeaderTextStyle = { A1: "a1", Zero: "zero", One: "one" };
class vw {
constructor(t, e, n, r) {
this._mergedReading = [], this._colsReading = [], this._rowsReading = [], this._styles = t, this._topLeft = r ?? { rowIndex: 0, colIndex: 0 }, this._sheet = new ns({ styles: this._styles, date1904: e, container: { getName: () => n, getIndex: () => 1 } }), this._cellUpdater = this._sheet.getEntireRange().startIncrementalUpdates();
}
applyCSSStyle(t, e) {
let n = !1;
t.style || (t.style = {}, n = !0);
let r = t.style, o = { ...e };
if (e.msoIgnore) {
const d = e.msoIgnore.split(",");
let u = Object.keys(o);
for (let g = 0; g < u.length; g++) {
const m = u[g];
d.includes(m) && delete o[m];
}
}
const s = ui(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 = ((d) => {
if (!d) return a_;
let u = dt.UnderlineStyle.None, g = !1;
return (d = d.toLowerCase()).includes("underline") && (u = dt.UnderlineStyle.Single), (d.includes("line-through") || d.includes("linethrough")) && (g = !0), { underline: u, strike: g };
})(o.textDecoration);
r.font.underline = i.underline, r.font.strike = i.strike, o.textUnderlineStyle && (r.font.underline = mm(o.textUnderlineStyle)), r.alignment = {}, o?.textAlign && (r.alignment.horizontal = ((d) => {
const u = k.textToKey(d);
return Gn.get(u) || null;
})(o.textAlign)), o?.textAlign && !r.alignment.horizontal && o?.textAlign !== "general" && (o.textAlign === "center-across" ? r.alignment.horizontal = et.HorizontalAlignment.CenterContinuous : o.textAlign === "fill" ? r.alignment.horizontal = et.HorizontalAlignment.Fill : o.textAlign === "121" || o.textAlign === "010" ? (r.alignment.horizontal = et.HorizontalAlignment.Distributed, r.alignment.justifyLastLine = o.textAlign === "121") : console.warn("unknown text-align", o.textAlign)), o.verticalAlign && (o.verticalAlign.toLowerCase() === "super" ? r.font.verticalAlign = dt.VerticalAlignment.Super : o.verticalAlign.toLowerCase() === "sup" ? r.font.verticalAlign = dt.VerticalAlignment.Sub : r.alignment.vertical = ((d) => {
const u = k.textToKey(d);
return En.get(u) || null;
})(o.verticalAlign), r.alignment.vertical || (o.verticalAlign === "121" ? r.alignment.vertical = et.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" ? et.Overflow.Visible : et.Overflow.Wrap), o.msoTextControl === "shrinktofit" && (r.alignment.overflow = et.Overflow.Shrink);
let l = null;
if (o.background ? l = o.background : o.backgroundColor && (l = o.backgroundColor), l && (r.fill = { color: l }), o.msoPattern) {
let d = H_(o.msoPattern);
d && (d.patternType === st.BuiltInSheetPattern.Solid ? r.fill = { color: d.foreground } : d.patternType !== st.BuiltInSheetPattern.None && (l && (d.background = l), r.fill = d));
}
o.msoRotate !== void 0 && (r.alignment.rotation = ((d) => {
let u = parseFloat(d);
return isNaN(u) || (u %= 360, u > 0 ? u = 360 - u : u < 0 && (u *= -1)), u;
})(o.msoRotate));
const c = (d, u) => {
d && (r.border || (r.border = {}), r.border[d] = u);
};
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 = ((d) => {
let u = d.replace(/(\\[0-9]{4})/g, (g) => String.fromCharCode(parseInt(g.replace(/\\/g, ""), 16)));
return u = u.replace(/(\\.{1})/g, (g) => g.substring(g.length - 1, g.length)), u.includes("\\") && (u = u.replace(/(\\.{1})/g, (g) => g.substring(g.length - 1, g.length))), u = u.replace(/^"(.*)"$/, "$1"), u;
})(o.msoNumberFormat), h.includes("\\") ? h = null : h === "Fixed" ? h = Ne.Styles.lookupStyle(r.numberFormat).formatType === Ne.Type.Number ? null : Ne.Type.Number : h === "Percent" && (h = Ne.Styles.lookupStyle(r.numberFormat).formatType === Ne.Type.Percentage ? null : Ne.Type.Percentage)), h && (r.numberFormat = h), t.style = this._styles.normalize(r), n && Object.keys(t.style).length === 0 && delete t.style;
}
onCell(t, e, n, r, o) {
const s = r(o);
let i = { value: e !== void 0 ? e : 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 = dt.VerticalAlignment.Sub), o.querySelectorAll("sup").length > 0 && (c.verticalAlign = dt.VerticalAlignment.Super), (o.querySelectorAll("b").length > 0 || o.querySelectorAll("strong").length > 0) && (c.weight = 700), o.querySelectorAll("i").length > 0 && (c.style = dt.Style.Italic), o.querySelectorAll("u").length > 0 && (c.underline = dt.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 d = h[0].getAttribute("href");
d && (i.hyperlink = d);
}
}
if (!L.isSingleCell(t)) {
const l = { rowStart: this._topLeft.rowIndex + t.rowStart, colStart: this._topLeft.colIndex + t.colStart, rowEnd: this._topLeft.rowIndex + t.rowEnd, colEnd: this._topLeft.colIndex + t.colEnd };
this._mergedReading.push(l);
}
if ((i.value !== void 0 || i.style || !(Object.keys(i).length <= 1)) && (this._cellUpdater.pushAt(this._topLeft.rowIndex + t.rowStart, this._topLeft.colIndex + t.colStart, i), !L.isSingleCell(t) && s.msoIgnore)) {
if (s.msoIgnore.includes("colspan")) {
const l = {};
s && this.applyCSSStyle(l, s);
const c = t.colEnd - t.colStart;
for (let h = 1; h <= c; h++) this._cellUpdater.pushAt(this._topLeft.rowIndex + t.rowStart, this._topLeft.colIndex + t.colStart + h, l);
t = { ...t, colEnd: t.colStart };
}
s.msoIgnore.includes("rowspan") && (t = { ...t, rowEnd: t.rowStart });
}
}
onNoTable(t, e, n) {
this.onCell({ rowStart: this._topLeft.rowIndex, colStart: this._topLeft.colIndex, rowEnd: this._topLeft.rowIndex, colEnd: this._topLeft.colIndex }, t, null, e, n);
}
onRowStart(t, e, n, r) {
const o = n(r);
if (o.msoHeightSource !== "userset") return;
let s = r.getAttribute("height") ?? o.height, i = null;
if (s && (i = Xr(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 d = Xr(h, this._styles.getNormal().getFont().getSize(), "px");
d !== null && (i = Math.max(d, i ?? 0));
}
i !== null && this._rowsReading.push({ address: { min: this._topLeft.rowIndex + t, max: this._topLeft.rowIndex + t + e - 1 }, update: { size: i * dt.getDeviceScale() } });
}
onColumn(t, e, n, r) {
const o = n(r);
if (o.msoWidthSource !== "userset") return;
let s = r.getAttribute("width") ?? o.width, i = null;
s && (i = Xr(s, this._styles.getNormal().getFont().getSize(), "px")), i !== null && this._colsReading.push({ address: { min: this._topLeft.colIndex + t, max: this._topLeft.colIndex + t + e - 1 }, update: { size: i * dt.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 lu = !1;
class xw {
constructor(t, e) {
this._mapStylesByName = /* @__PURE__ */ new Map(), this._arrStyleNames = [], this._mapStylesByName = t, this._arrStyleNames = e;
}
setNode(t) {
this._node = t;
}
addStyle(t, e) {
e != null && (this._node?.styles || (this._node.styles = /* @__PURE__ */ new Map()), this._node.styles.set(t, e));
}
addAttribute(t, e) {
e != null && (this._node?.attributes || (this._node.attributes = /* @__PURE__ */ new Map()), this._node.attributes.set(t, e), t.toLowerCase() === "rowspan" && parseInt(e) > 1 && (this._node.rowspan = parseInt(e)), t.toLowerCase() === "colspan" && parseInt(e) > 1 && (this._node.colspan = parseInt(e)));
}
addSharedStyle(t, e) {
let n = this._mapStylesByName.get(t);
n ? n = { ...e } : (this._arrStyleNames.push(t), n = e), this._mapStylesByName.set(t, n);
}
setPlainText(t) {
this._node.plainText = t;
}
setHTMLText(t) {
this._node.htmlText = t.replace(/(?:\r\n|\r|\n)/g, "<br>");
}
}
const cu = (a) => {
const t = {};
if (!a) return t;
a.endsWith(";") || (a += ";");
const e = new RegExp(';(?=([^"]*"[^"]*")*[^"]*$)', "gsm");
let n, r = 0;
for (; (n = e.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 = pg(i)), t[i] = l);
} catch (o) {
console.warn(o);
}
r = n.index + 1;
}
return t;
}, Ds = (a, t) => {
const e = [];
if (!a) return e;
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();
t.includes(s) && e.push(o);
}
}
return e;
}, Iw = (a, t, e) => {
try {
let n = null, r = null;
const o = (l) => ((c, h) => {
if (!c) return {};
let d = {}, u = h.get(c.localName);
u && (d = Object.assign(d, u));
const g = c.getAttribute("class");
if (g) {
const f = h.get("." + g);
f && (d = Object.assign(d, f));
}
const m = c.getAttribute("style");
if (m) {
const f = cu(m);
f && (d = Object.assign(d, f));
}
return c.getAttribute("align") && !d.textAlign && (d.textAlign = c.getAttribute("align")), d;
})(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"), d = h[h.length - 1];
r = ((_) => {
const S = _.querySelectorAll("style"), C = /* @__PURE__ */ new Map();
if (S.length <= 0) return C;
for (let y = 0; y < S.length; y++) {
const E = S[y].childNodes;
for (let w = 0; w < E.length; w++) if (E[w].nodeType === Node.TEXT_NODE) {
const b = new RegExp("<!--(.*)-->", "gs");
let v = E[w].textContent;
const I = b.exec(E[w].textContent);
if (I && I.length > 1 && (v = I[1]), v = v.replace(/^\s/, ""), v?.startsWith("table")) {
const x = new RegExp("{(.*?)}", "gs");
let R, A = 0;
for (; (R = x.exec(v)) !== null; ) try {
const M = v.substring(A, R.index), T = cu(R[1]);
C.set(M.trim(), T), A = R.index + R[0].length;
} catch (M) {
console.warn(M);
}
return C;
}
}
}
return C;
})(d);
const u = d.querySelectorAll("body"), g = u[u.length - 1];
let f = g.querySelectorAll("table")[0], p = !1;
if (!f) {
let _ = g.querySelectorAll("span");
f = _[0], p = _.length > 1;
}
if (f || (f = Ds(g, l)[0]), f || (f = Ds(a, l)[0]), f?.nodeName.toUpperCase() === "TABLE") {
e.onStart?.(r);
const _ = f;
e.onTableStart?.(o, _);
const S = Ds(_, "COLGROUP");
for (let E = 0; S && E < S.length; E++) {
const w = Ds(S[E], "COL");
let b = 0;
for (let v = 0; v < w.length; v++) {
const I = w[v], x = parseFloat(I.getAttribute("span")), R = isNaN(x) ? 1 : x;
e.onColumn?.(b, R, o, I), b += R;
}
}
const C = _.rows;
let y = 0;
for (let E = 0; E < C.length; E++) {
const w = C[E], b = parseFloat(w.getAttribute("span")), v = isNaN(b) ? 1 : b;
e.onRowStart?.(y, v, o, w);
const I = [];
n.push(I);
const x = w.cells;
for (let R = 0; R < x.length; R++) {
let A = x[R], M = !1;
for (let T = 0; !M && T < A.childNodes.length; T++) if (A.childNodes[T].nodeType === 8) {
const O = A.childNodes[T].textContent;
if (O !== "[if gte vml 1]") {
if (O !== "[if !vml]") {
if (O === "[endif]") {
const W = A.childNodes[T + 1];
W?.querySelectorAll && W.querySelectorAll("table, td").length === 2 && (A = W?.querySelectorAll("table, td")[1], M = !0);
}
}
}
}
I.push({ htmlValue: A.textContent?.replace(/^"|"$/gi, ""), element: A });
}
y += v, e.onRowDow?.(y, v, o, w);
}
e.onTableDone?.(o, _);
} else {
if (f?.nodeName.toUpperCase() === "SPAN") {
const _ = t ? t[0]?.[0] : null, S = p && _ ? _ : f.textContent.replace(/^"|"$/gi, "");
return e.onStart?.(r), e.onCell({ colStart: 0, colEnd: 0, rowStart: 0, rowEnd: 0 }, t ? t[0]?.[0] : null, S, (C) => {
const y = o(C);
return delete y.backgroundColor, y;
}, f), e.onDone?.(), !0;
}
if (f?.textContent) {
const _ = f.textContent.replace(/^"|"$/gi, "");
return e.onStart?.(r), e.onNoTable?.(_, o, f), e.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 = t && (t.length === 0 || t.length === 1 && (t[0] === null || t[0].length === 0));
n && s && (t = null);
const i = (l) => {
const c = /* @__PURE__ */ new Set();
let h = 1, d = 1;
for (let u = 0; u < Math.max(t ? t.length : 0, n ? n.length : 0); u++) {
let g = 0, m = 0, f = n && n[u] ? n[u].length : t[u] ? t[u].length : 0;
for (; m < f; ) {
const p = u + "-" + g;
if (!c.has(p)) {
h = Math.max(h, g + 1), d = Math.max(d, u + 1);
let _ = null;
const S = n ? n[u]?.[m]?.element : void 0;
if (S && (S.getAttribute("rowspan") || S.getAttribute("colspan"))) {
const C = parseInt(S.getAttribute("colspan")) || 1, y = parseInt(S.getAttribute("rowspan")) || 1;
h = Math.max(h, g + C), d = Math.max(d, u + y), _ = { rowStart: u, colStart: g, rowEnd: u + Math.max(0, y - 1), colEnd: g + Math.max(0, C - 1) };
for (let E = u; E < u + y; E++) for (let w = g; w < g + C; w++) E === u && w === g || c.add(E + "-" + w);
} else _ = { rowStart: u, colStart: g, rowEnd: u, colEnd: g };
l(_, t ? t[u]?.[g] : void 0, n ? n[u]?.[m]?.htmlValue : null, o, S || null), m++;
}
g++;
}
}
};
if (n && t) {
let l = 0, c = 0;
i((h) => {
l = Math.max(l, h.colEnd + 1), c = Math.max(c, h.rowEnd + 1);
}), t && n && (t.length !== c || t[0].length !== l) && (console.warn("mismatched mimeTypes", t, n), t = null);
}
return i(e.onCell.bind(e)), e.onDone?.(), !s || n !== null;
} catch (n) {
throw console.warn(n), n;
}
};
class Cy {
constructor(t) {
if (!t) throw new Qe("snapshot is required.");
this._snapshot = t;
}
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 Ey {
constructor(t, e, n, r) {
if (this._parsed = void 0, !t) throw new Qe("nativeItems are required.");
this._native = t, this._markOptions = Object.freeze(e ?? {}), 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 t = this._parsed;
if (t === void 0) throw new Error("Must call 'parse()' before getItem().");
if (t === null) return null;
if (this._snapshot) return this._snapshot;
const e = this;
return this._snapshot = { copyTo: (n, r) => t.copyTo(n, { ...e._markOptions, ...r }), getMarkOptions: () => e._markOptions, getName: () => t?.getName() ?? "Clipboard Data", getCoords: () => t?.getCoords?.() ?? null, toText: () => e.toText(), toHtml: () => e.toHtml(), toImage: () => e.toImage(), getSource: () => t?.getSource?.() ?? null, isISnapshot: !0 }, this._snapshot;
}
async parse() {
let t, e = this._native?.text, n = this._native.html;
if (n === null && e && e.includes("<table")) try {
const r = new DOMParser().parseFromString(e, Wu.html), o = r.querySelector("parsererror");
if (o) throw new ot("Unable to parse: " + o);
n = r, e = null;
} catch {
console.warn("Discovered text as html table but could could not parse.");
}
try {
const r = new vw(this._styles, this._isDate1904, n ? "HTML" : "Text"), o = await Promise.resolve(e ? ((i, l = " ") => new Promise((c, h) => {
import("./BvtSjnucMGltTjeM.mjs").then((d) => d.p).then((d) => {
try {
const u = d.parse(i, { delimiter: l }).data;
u.length > 1 && (u[u.length - 1].length === 0 || u[u.length - 1].length === 1 && u[u.length - 1][0].length === 0) && u.pop(), c(u);
} catch (u) {
console.warn(u), h(u);
}
}, (d) => {
h(d);
});
}))(e) : [[]]);
let s;
if (Iw(n, o, r) ? (t = r.sheet(), s = t.getUsedRange()) : n = null, s) return this._parsed = { async copyTo(i, l) {
return (await i.copyFrom(s, l))?.getCoords() ?? null;
}, getCoords: () => s.getCoords(), getSource: () => t, getName: () => t.getName() }, !0;
} catch (r) {
throw r;
}
if (!e && !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 bt;
(bt || (bt = {})).Visibility = { Visible: "visible", Hidden: "hidden", VeryHidden: "veryHidden" };
class Oi extends Yi {
static {
this.instanceCounter = 0;
}
constructor(t) {
if (super(t), !t.content) throw new Error("Content type is required");
this._content = t.content, this._uuid = k.uuidV4(), this._optionsMovable = t;
const e = this;
this._optionsMovable.setContainerZIndexCallback?.(() => {
e._processZIndex();
}), this._optionsMovable.setContainerSelectionCallback?.((r, o) => {
e._processContainerSelect(r, o);
}), t.json && this._fromJSON(t.json);
const n = this._content.addListeners({ onDelete: () => {
e._options.deleteFromContainer && e._options.deleteFromContainer?.();
} }, { transactional: !0 });
this._updateState({ contentListenerRemove: n }, null, []);
}
getUUID() {
return this._uuid;
}
getContent() {
return this._content;
}
_processStateChange(t, e, n) {
super._processStateChange(t, e, n), this._getEmitter().notify("onBoundsChange"), this._getEmitter().notify("onAnyChange");
}
_processZIndex() {
this._getEmitter().notify("onAnyChange");
}
_processContainerSelect(t, e) {
this._getEmitter().notify("onSelectionChange");
}
isSelected() {
return this._optionsMovable.isSelected?.() ?? !1;
}
async scrollIntoView(t) {
return this._optionsMovable.scrollIntoView?.(t) ?? !1;
}
async select(t) {
if (await this._optionsMovable.select?.(t) === !1) return !1;
if (t?.autoFocus !== !1) {
const e = await this._getEmitter().notify("onRequestFocus", { async: !0 });
if (!e) return !1;
for (let n = 0; n < e.length; n++) if (e[n] === !1) return !1;
}
return !0;
}
unselect() {
const t = this._optionsMovable.isSelected?.() ?? !1;
return this._optionsMovable.unselect?.(), t;
}
_clone() {
const t = this.isSelected(), e = 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: () => t, getZIndex: () => e, getMaxBounds: n, maxRangeCoords: r, transactions: new Ze({ transient: !0 }), json: this.toJSON(), initialAnchor: this.getAnchorCoords(), content: o }, i = new Oi(s), l = this._getState();
return i._updateState({ ...l }), i;
}
getSnapshot(t, e) {
const n = this._optionsMovable.getCoordsAtBounds(t), 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), !L.isRangeWithinRange(o, n)) return null;
const s = this, i = s._clone(), l = Object.freeze({ ...e });
let c = !1;
return { async copyTo(d, u) {
const g = { ...l, ...u };
return await i._doCopy(d, g), g.isCut && !c && (s.delete(), c = !0), d.bounds;
}, getCoords: () => i.getBounds(), getSource: () => i, getName: () => i.getName(), getMarkOptions: () => l, toText: () => i._toText(), toHtml: () => i._toHtml(), toImage: () => i._toImage(), isISnapshot: !0 };
}
async _doCopy(t, e) {
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 = t.movables;
if (!s) throw new Error("Movables is required");
const i = t.bounds ?? this.getBounds();
try {
await s.add({ ...r, ...e, 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(t) {
return this._updateState({ name: t }, { description: "Set Movable Name" }, ["onNameChange"]), this;
}
getName() {
return this.isClosed() ? null : this._getState()?.name;
}
setDescription(t) {
return this._updateState({ description: t }, { description: "Set Movable Description" }), this;
}
getDescription() {
return this.isClosed() ? null : this._getState()?.description;
}
setHidden(t = !1) {
return this._updateState({ hidden: t }, { description: "Set Movable Visibility" }), this;
}
isHidden() {
return this._getState()?.hidden ?? !1;
}
setLockAspectRatio(t) {
return this._updateState({ lockAspectRatio: t }, { description: "Set Lock Aspect Ratio" }), this;
}
isLockAspectRatio() {
return this._getState()?.lockAspectRatio ?? this._optionsMovable.defaultLockAspectRatio ?? !1;
}
setRotation(t = 0) {
return this._updateState({ rotation: t }, { 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(t, e) {
if (!t) return this;
let n = { ...this.getBounds(), ...t };
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 Wt();
const r = this._updateMovableLocation({ bounds: n, anchorType: ve.Type.Absolute }), o = this._beginCommit(e?.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(t) {
let e = t.offsets ?? { tl: { x: 0, y: 0 }, br: { x: 0, y: 0 } }, n = t.anchor ?? this.getAnchorCoords(), r = t.anchorType ?? this.getAnchorType();
const o = t.bounds ?? this.getBounds();
if (o) {
if (r === ve.Type.Absolute) {
n = this._optionsMovable.getCoordsAtBounds(o);
const s = this._optionsMovable.getBoundsAtCoords(n);
e = { ...e, tl: { x: o.x - s.x, y: o.y - s.y } };
}
if (r === ve.Type.Absolute || r === ve.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, e.tl.x), height: o.height + Math.min(s.height, e.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(e?.tl.x ?? 0, s.width)), h = o.height - (l.y - s.y - Math.min(e?.tl.y ?? 0, s.height));
e = { ...e, br: { x: c, y: h } };
}
return e !== t.offsets && (e.br.y <= 0 && (e.br = { ...e.br, y: 0 }, n.rowEnd--), e.br.x <= 0 && (e.br = { ...e.br, x: 0 }, n.colEnd--)), { anchor: n, offsets: e };
}
}
_calcAbsoluteBounds(t, e = { tl: { x: 0, y: 0 }, br: { x: 0, y: 0 } }) {
if (!t) return null;
const n = this._optionsMovable.getBoundsAtCoords({ rowStart: t.rowStart, colStart: t.colStart, colEnd: t.colStart, rowEnd: t.rowStart });
let r = e.br.x ? 0 : 1, o = e.br.y ? 0 : 1;
const s = this._optionsMovable.getBoundsAtCoords({ colStart: t.colEnd + r, rowStart: t.rowEnd + o, colEnd: t.colEnd + r, rowEnd: t.rowEnd + o }), i = Math.min(n.x + (e?.tl.x ?? 0), n.x + n.width), l = Math.min(n.y + (e?.tl.y ?? 0), n.y + n.height);
return { x: i, y: l, width: Math.min(s.x + (e?.br.x ?? 0), s.x + s.width) - i, height: Math.min(s.y + (e?.br.y ?? 0), s.y + s.height) - l };
}
getBounds() {
return this._getState()?.bounds;
}
setAnchorType(t) {
return k.validEnumValue(ve.Type, t), this._updateState({ anchorType: t }, { description: "Set Movable Resize Behavior" }, ["onAnchorTypeChange"]), this;
}
_processContainerShift(t) {
const e = this.getAnchorType(), n = this._getState()?.offsets;
let r = n, o = !1;
const s = t.before, i = t.orientation === F.Orientation.Column, l = t.intersect, c = t.amount;
let h = t.after;
if (e !== ve.Type.Absolute) {
let g = i ? l.colStart : l.rowStart, m = i ? s.colStart : s.rowStart;
e === ve.Type.TwoCell && (m = i ? s.colEnd : s.rowEnd), o = g <= m;
}
if (o && (e !== ve.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 d = null;
const u = this._beginCommit("Shifting Movable Bounds");
try {
if (n !== r || !L.isEqualRanges(s, h)) {
const g = { offsets: r, anchor: h };
this._updateState(g);
}
this._invalidateBounds(), d = super._processContainerShift({ ...t, after: h }), u.commit();
} catch (g) {
throw u.rollback(), g;
}
return d;
}
_invalidateBounds() {
const t = this.getAnchorCoords();
if (t === null) return null;
const e = this._getState()?.offsets, n = this._calcAbsoluteBounds(t, e);
this._updateState({ bounds: n }, null, ["onBoundsChange"]);
}
_processContainerDelete() {
super._processContainerDelete(), this._getState().contentListenerRemove?.(), this.getContent().delete();
}
_processContainerLayout() {
const t = this.getAnchorCoords(), e = this._getState()?.offsets, { offsets: n, anchor: r } = this._updateMovableLocation({ anchor: t, offsets: e }), o = this._beginCommit("Updating Movable Bounds");
try {
if (e !== n || t !== 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(t) {
const e = { tl: { x: 0, y: 0 }, br: { x: 0, y: 0 } }, n = { ...L.EmptyRange };
t.anchor && (e.tl.x = t.anchor.tl?.x ?? 0, e.tl.y = t.anchor.tl?.y ?? 0, e.br.x = t.anchor.br?.x ?? 0, e.br.y = t.anchor.br?.y ?? 0, n.colStart = t.anchor.tl?.c ?? 0, n.rowStart = t.anchor.tl?.r ?? 0, n.colEnd = Math.max(n.colStart, (t.anchor.br?.c ?? 0) + (e.br.x > 0 ? 0 : -1)), n.rowEnd = Math.max(n.rowStart, (t.anchor.br?.r ?? 0) + (e.br.y > 0 ? 0 : -1)));
const r = this._beginCommit("Load Movable"), o = t.content.json, s = { offsets: e, name: o.name ?? null, description: o.name ?? null, hidden: o.hidden ?? !1, rotation: o.rotation ?? 0, lockAspectRatio: o.lockAspect ?? null };
t.anchorType && (s.anchorType = t.anchorType), s.name || (s.name = `${this._content.getTypeDescription()} ${++Oi.instanceCounter}`), s.bounds = this._calcAbsoluteBounds(n, e), this._updateState(s, { description: "Load Movable" }), this._optionsMovable.setContainerCoords?.(n), r.commit();
}
toJSON(t) {
const e = this._getState(), n = e.anchor, r = e.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 = k.roundAccurately(r.tl.x, 1)), r.tl?.y && (o.tl.y = k.roundAccurately(r.tl.y, 1)), r.br?.x && (o.br.x = k.roundAccurately(r.br.x, 1)), r.br?.y && (o.br.y = k.roundAccurately(r.br.y, 1)));
const s = this._content.toJSON(t) ?? {}, i = { anchor: o, content: { type: this._content.getType(), json: s } }, l = e.anchorType;
return l && l !== ve.Type.TwoCell && (i.anchorType = this.getAnchorType()), e.hidden && (i.hidden = e.hidden), e.name && (i.name = e.name), e.description && (i.name = e.description), e.rotation !== void 0 && e.rotation !== 0 && (i.rotation = e.rotation), k.isDefined(e.lockAspectRatio) && e.lockAspectRatio !== this._optionsMovable.defaultLockAspectRatio && (i.lockAspect = e.lockAspectRatio), i;
}
get isIMovable() {
return !0;
}
}
class Rw {
constructor(t, e, n, r, o, s) {
this._add = t, this._getItems = e, this._getCount = n, this._updateSelected = r, this._addListeners = o, this._addImage = s;
}
async add(t) {
return this._add(t);
}
getItems(t) {
return this._getItems(t);
}
getCount() {
return this._getCount();
}
updateSelected(t, e) {
return this._updateSelected(t, e);
}
addListeners(t, e) {
return this._addListeners(t, e);
}
addImage(t, e) {
return this._addImage(t, e);
}
}
const ol = { transactional: !0, ignoreDataChanges: !0 };
class hu extends Vg {
constructor(t) {
super({ ...t, type: "namedReference" });
const e = 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 = e._getState(), g = r.getTo(), m = r.getFrom(), f = [], p = o.getCount(), _ = m.getCount();
for (let y = 0; y < p; y++) {
const E = o.at(y);
if (f.push(E.getCoords()), !E.isInvalid()) {
for (let w = 0; w < _; w++) {
const b = m.at(w).getCoords(), v = E.getCoords();
if (!L.isRangeWithinRange(v, b)) continue;
const I = g.getCoords(), x = I.colStart - b.colStart + v.colStart, R = I.rowStart - b.rowStart + v.rowStart, A = { ...v, colStart: x, rowStart: R, colEnd: x + (v.colEnd - v.colStart), rowEnd: R + (v.rowEnd - v.rowStart) };
(g.size !== 1 || L.isRangeWithinRange(A, I)) && (f[y] = g.getSheet().getRange(A).getCoords(), i = !0);
}
if (!i) return;
}
}
const S = this._options.addressToRanges(f);
let C;
u.removeListener?.(), S.isInvalid() || (C = S.addListener(e._listener, ol)), l.ranges = S, l.removeListener = C;
}
this._updateState(l, null, ["onRangesChange"]);
const c = s.getCoords();
let h = !c || c.length === 0;
const d = c.length;
for (let u = 0; !h && u < d; u++) if (!c[u]) {
h = !0;
break;
}
h && e.delete();
};
const n = t.value;
if (n && !n.isInvalid()) {
const r = n.addListener(this._listener, ol);
this._updateState({ ranges: n, removeListener: r }, null);
}
}
setReference(t) {
const e = this._options.addressToRanges(t);
if (e && !e.isInvalid()) {
this._getState().removeListener?.();
const r = e.addListener(this._listener, ol);
this._updateState({ ranges: e, removeListener: r }, null);
}
return null;
}
async select(t) {
return await this._getState().ranges.select(t), this;
}
getRanges() {
return this._getState().ranges;
}
setHidden(t = !1, e) {
return this._updateState({ hidden: t }, { description: "Set Hidden", ...e }, []), this;
}
setScope(t, e) {
return this._updateState({ scope: t }, { description: "Set Scope", ...e }, []), this;
}
getType() {
return "reference";
}
getValue() {
return this._getState().ranges;
}
toJSON() {
const t = super._toJSON();
return t.ref = this._getState().ranges.toString(), t;
}
_getDescription() {
return `Named '${this.getName()}'`;
}
_processDelete() {
const t = this._getState();
t && t.removeListener?.(), super._processDelete();
}
get [Symbol.toStringTag]() {
return "[NamedReference]";
}
toString() {
return this._getDescription();
}
}
const du = "Item must be specified.", uu = "Name must be a non-empty string", gu = (a, t = null) => `Named item '${a}' already exists${t ? `in scope ${t}` : ""}.`, mu = (a) => {
const t = [];
for (let e = 0; e < a.getCount(); e++) {
let n = null;
try {
n = a.at(e), n.isICellRange && (n = n.getFixed(!0));
} catch (r) {
Go.warn("Invalid range", r);
}
t.push(n ? n.toString().toLowerCase() : ie);
}
return t.sort(), t.join(",");
}, Aw = /^[^a-zA-Z_\\]+$/, Mw = /^[^a-zA-Z0-9_.]+$/;
class Lm {
constructor(t) {
this._emitter = null, this._closed = !1, this._lastLookup = k.EmptyArray, this._lastLookupAddress = null, this._lastLookupScope = null, this._lastLookupType = null, this._allowExtrudes = !1, this._options = { ...t };
const e = this;
this._transactions = this._options.transactions ?? new Ze({ transient: !0 }), this._transactionsRemoveListener = this._transactions.addStateListener(this, { onAfterStateChange(n, r, o) {
r?.initial || e._emitter.notify("onCollectionChange");
} }), this._emitter = new he(this, this._transactions), this._initState(), this._fromJSON(this._options?.json);
}
getItems(t) {
if (this.isClosed()) return k.EmptyArray;
const e = this._getState();
if (!e) return k.EmptyArray;
const n = e.itemsSpatial;
if (n.isEmpty()) return k.EmptyArray;
if (t && t.address === this._lastLookupAddress && t.scope === this._lastLookupScope && t.type === this._lastLookupType && t.allowExtrudes === this._allowExtrudes) return this._lastLookup;
this._lastLookupAddress = t?.address ?? void 0, this._lastLookupScope = t?.scope ?? void 0, this._lastLookupType = t?.type ?? void 0, this._allowExtrudes = t?.allowExtrudes ?? void 0;
let r = null;
if (t?.address) {
const h = this._options.addressToRanges(t?.address);
if (!h) return Go.debug("Invalid range", { details: t?.address }), this._lastLookup = null, null;
r = h.getCoords();
}
let o = null;
if (r) {
o = [];
for (let h = 0; h < r.length; h++) {
const d = n.search(r[h]), u = d.length;
for (let g = 0; g < u; g++) o.push(d[g]);
}
} else o = n.all();
if (!o || o.length === 0) return this._lastLookup = k.EmptyArray, k.EmptyArray;
const s = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
o.forEach((h) => {
const d = h.value;
if (!t?.type || d.getType() === t.type) {
if (r && !t?.allowExtrudes) {
const u = d.getRanges?.();
if (!u || u.getCount() === 0) return;
for (let g = 0; g < r.length; g++) if (!L.isRangeWithinRange(h, r[g])) return;
}
!t?.scope || d.getScope() !== t.scope && t.scope !== "all" ? d.getScope() || i.add(d) : s.add(d);
}
});
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, d) => {
let u = h.getType().localeCompare(d.getType());
return u !== 0 ? u : h.getName().localeCompare(d.getName());
}), this._lastLookup = c, c;
}
lookupByRanges(t) {
const e = this._options.addressToRanges(t);
if (!e || e.getCount() === 0) return null;
const n = this._getState();
if (!n || n.itemsByKey.size === 0) return null;
const r = mu(e), 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(t, e = !1) {
if (!t) return null;
const n = this._getState();
if (!n || n.itemsByKey.size === 0 || typeof t != "string") return null;
const r = t.toLowerCase(), o = this._options.getCurrentScope();
if (!e && 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 t = this._getState();
return t ? t.itemsByKey.size : 0;
}
getRanges(t) {
const e = this._options.addressToRanges(t), n = [];
for (let r = 0; r < e.getCount(); r++) {
const o = e.at(r).getFixed(!0).getCoords();
n.push(o);
}
return this._options.addressToRanges(n);
}
findValidName(t, e = null, n = !1) {
if (!t) throw new Error("A template string must be specified.");
const r = this, o = (s) => {
try {
return r._validateName(s, e, n), !0;
} catch {
}
return !1;
};
return o(t) ? t : fg(t, o);
}
validateName(t, e = null, n = !1) {
return this._validateName(t, e, n);
}
_validateName(t, e, n = !1) {
if (this._closed) throw new Error(We);
if (!t || t.length === 0) throw new Error(uu);
if (t.length > 255) throw new Error("Name must not exceed 255 characters.");
if (t.indexOf(" ") !== -1) throw new Error("Name must not contain any spaces.");
const r = t.trim().toLowerCase(), o = r.substring(1, t.length - 1);
if (new RegExp(Aw).test(r[0])) throw new Error("First letter must be either a letter, an underscore, or a backslash.");
if (new RegExp(Mw).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 = q0, h = tm, d = !1) => {
let u = sm(l, d);
if (!u || u[2] || !u[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);
})(t)) throw new Error("Name can not be an address.");
let s = t.toLowerCase()?.trim();
e && (s = s + ":" + e.toLowerCase());
const i = this._getState()?.itemsByKey.get(s);
if (i) {
const l = i.item.getRanges();
if (!n || l || l.getCount() > 0) throw new Error(gu(t, e));
}
}
addReference(t, e, n = !1) {
const r = this._options.addressToRanges(e), o = this.getByName(t);
let s = null;
const i = this._beginCommit(`${o && n ? "Update" : "Insert"} Named '${t}'`);
try {
if (o) {
if (!n) throw new Error(gu(t));
this._delete(o, { description: `Delete Named '${o.getName()}'` });
}
s = new hu({ value: r, addressToRanges: this._options.addressToRanges, json: { name: t, ref: r.toString() }, transactions: this._transactions }), this.add(s), i.commit();
} catch (l) {
throw i.rollback(), l;
}
return s;
}
add(t) {
if (this._closed) throw new Error(We);
if (!t) throw new Error(du);
if (!t.getName || typeof t == "string") throw new Error("Add must take a 'INamed' object. To add a string use 'addReference'.");
if (this._validateName(t.getName(), t.getScope(), !1), this._options.isReadOnly?.()) throw new Error("Names are read-only.");
const e = this._beginCommit(`Insert Named Item '${t.getName()}'`), n = this._add([t]);
if (n === null) return e.rollback(), null;
const r = n.itemsByKey.get(t.getName().toLowerCase());
return this._updateState((o) => ({ ...o, ...n })), e.commit(), r?.item ?? null;
}
_toKey(t) {
let e = t.getName().toLowerCase();
return e.startsWith("_xlnm.") && (e = e.substring(6)), t.getScope() ? e + ":" + t.getScope().toLowerCase() : e;
}
_delete(t, e) {
if (!t) throw new Error(du);
if (this._closed) throw new Error(We);
const n = this._beginCommit(e?.description ?? `Delete Named Item '${t.getName()}'`);
let r = null;
try {
const o = this._getState()?.itemsByKey, s = this._toKey(t);
if (r = o.get(s), !r) throw new Error(`Item '${t.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 t = this._getState();
return { itemsBySource: new Map(t.itemsBySource), itemsByKey: new Map(t.itemsByKey), itemsSpatial: t.itemsSpatial.clone(), itemsByFullRange: new Map(t.itemsByFullRange), itemsByPartialRange: new Map(t.itemsByPartialRange) };
}
_index(t, e, n) {
const r = n.itemsByKey.get(t);
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(t), 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(t), 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(t), n.itemsBySource.delete(r.item);
}
let o = null;
if (e) {
let s = [], i = null, l = null;
o = e.getRanges?.();
const c = this._toKey(e);
if (o) {
const { asFullRange: g, asPartialRanges: m, asRanges: f } = ((p) => {
const _ = p.getCoords(), S = mu(p), C = S.split(",");
return { asFullRange: S, asPartialRanges: C, asRanges: _ };
})(o);
if (i = g, l = m, f) {
for (let p = 0; p < m.length; p++) {
let _ = n.itemsByPartialRange.get(m[p]);
const S = _ ? new Set(_) : /* @__PURE__ */ new Set();
S.add(c), n.itemsByPartialRange.set(m[p], S), s.push({ ...f[p], value: e });
}
if (n.itemsSpatial.load(s), g) {
let p = n.itemsByFullRange.get(g);
const _ = p ? new Set(p) : /* @__PURE__ */ new Set();
_.add(c), n.itemsByFullRange.set(g, _);
}
}
}
const h = this, d = e.addListeners({ onDelete: (g) => {
h._delete(g);
}, onAnyChange: (g) => {
const m = h._beginCommit(`Update Named '${g.getName()}'`);
try {
const f = h._cloneState(), p = f.itemsBySource.get(g).globalKey;
h._index(p, g, f), h._updateState((_) => ({ ..._, ...f })), m.commit();
} catch (f) {
throw m.rollback(), f;
}
} }, { transactional: !0 }), u = { item: e, asFullRange: i, asPartialRanges: l, unwatch: d, nodes: s, globalKey: c };
n.itemsByKey.set(c, u), n.itemsBySource.set(e, u);
}
}
_add(t) {
if (this._closed) throw new Error(We);
const e = this._getState();
if (!t) return e;
const n = this._cloneState(), r = t.length;
for (let o = 0; o < r; o++) {
const s = t[o];
if (!s.getName()) throw new Error(uu);
const i = this._toKey(s);
try {
this._index(i, s, n);
} catch (l) {
Go.warn(`Unable to add named item '${i}'.`, { details: l?.message });
}
}
return n;
}
beginCommit(t) {
return this._beginCommit(t);
}
_getState() {
if (this._closed) throw new Error(We);
return this._transactions.getState(this);
}
_beginCommit(t) {
return this._transactions.beginCommit(typeof t == "string" ? { description: t } : t);
}
_updateState(t, e = "Update") {
if (!t) return;
this._lastLookup = k.EmptyArray, this._lastLookupAddress = null, this._lastLookupType = null, this._lastLookupScope = null;
const n = this._beginCommit(e);
try {
n.updateState(this, t), n.commit();
} catch (r) {
throw n.rollback(), r;
}
}
fromJSON(t) {
if (this._closed) throw new Error(We);
this._fromJSON(t);
}
_initState() {
this._updateState((t) => ({ ...t, items: /* @__PURE__ */ new Set(), itemsByKey: /* @__PURE__ */ new Map(), itemsSpatial: new Nt(), itemsByFullRange: /* @__PURE__ */ new Map(), itemsByPartialRange: /* @__PURE__ */ new Map() }));
}
_fromJSON(t) {
const e = this._beginCommit("Load Names");
try {
if (t) {
const n = [], r = t.length;
for (let s = 0; s < r; s++) {
const i = t[s];
try {
const l = this._options.addressToRanges(i.ref), c = new hu({ value: l, addressToRanges: this._options.addressToRanges, deleteFromContainer: (h) => {
this._delete(c, h);
}, json: i, transactions: this._transactions });
n.push(c);
} catch (l) {
Go.warn(`Unable to load named item '${i.name}'.`, { details: l?.message });
}
}
const o = this._add(n);
this._updateState((s) => ({ ...s, ...o }));
}
e.commit({ viewAfter: { initial: !0 } });
} catch (n) {
throw e.rollback(), n;
}
}
toJSON() {
const t = this._getState();
if (!t || t.itemsByKey.size === 0) return null;
const e = [], n = Array.from(t.itemsByKey.keys()).sort(), r = n.length;
for (let o = 0; o < r; o++) {
const s = t.itemsByKey.get(n[o]).item, i = s.toJSON?.();
i && e.push(i);
}
return e.length === 0 ? null : e;
}
addListeners(t, e) {
return this._emitter.addListeners(t, e);
}
isClosed() {
return this._closed;
}
close() {
this._closed || (this._emitter.notify("onClose"), this._closed = !0, this._transactionsRemoveListener?.());
}
get isNamedCollection() {
return !0;
}
}
class Tw extends Er {
constructor(t) {
super(t), t.json && this._updateState({ data: t.json });
}
getType() {
return "chart";
}
getDescription() {
return `Chart: ${this._getState()?.data?.types?.[0]?.type ?? "unknown"}`;
}
toJSON(t) {
const e = this._getState();
let n = null;
return e && e.data && (n = e.data), n;
}
getTypeDescription() {
return "Chart";
}
}
class Nw extends Er {
constructor(t) {
super(t), t.json && this._updateState({ data: t.json });
}
getType() {
return "shape";
}
getDescription() {
return `Shape: ${this._getState()?.data}`;
}
toJSON(t) {
const e = this._getState();
let n = null;
return e && e.data && (n = e.data), n;
}
getTypeDescription() {
return "Shape";
}
get [Symbol.toStringTag]() {
return "[Shape]";
}
toString() {
return this.getTypeDescription();
}
}
class Fw extends Er {
constructor(t) {
super(t), t.json && this._updateState({ data: t.json });
}
getType() {
return "custom";
}
getDescription() {
return `CustomElement: ${this._getState()?.data}`;
}
toJSON(t) {
const e = this._getState();
let n = null;
return e && e.data && (n = e.data), n;
}
getTypeDescription() {
return "CustomElement";
}
}
const fu = (a, t, e = !0, n = !0) => {
let r = 0, o = 0;
if (!e && !n) return { x: r, y: o };
let s = !1, i = 0;
do {
const l = { x: t.x + r, y: t.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 d = c[h].getBounds();
d.x === l.x && d.y === l.y && (s = !0);
}
s && (r += e ? 16 : 0, o += n ? 16 : 0);
}
} while (s && ++i < 100);
return { x: r, y: o };
};
class kw {
constructor(t, e, n) {
this._add = t, this._get = e, this._getByName = n;
}
add(t, e) {
if (!t) throw new Error(Vl);
return this._add(t, e);
}
getItems(t) {
if (t && t.name && Object.keys(t).length === 0) return [this._getByName(t.name)];
let e;
t?.address && (e = t.address);
const n = this._get(e, t?.ignoreHidden, t?.fullyContained);
if (t?.name) {
const r = t.name.toLocaleLowerCase();
for (let o = 0; o < n.length; o++) if (n[o].getName().toLocaleLowerCase() === r) return [n[o]];
}
return n;
}
getByName(t) {
if (typeof t != "string") throw new Error("Get by name must take a valid name.");
return this._getByName(t);
}
getCount() {
return this._get(null, !1, !1).length;
}
}
const ye = (a, t, e) => {
if (!a) return t;
let n = t;
const r = e === F.Direction.Right || e === F.Direction.Down;
for (; ; ) {
const o = a(n, !r);
if (o === 0) return n;
r ? n += o : n -= o;
}
}, Ow = Object.freeze({ colIndex: 0, rowIndex: 0 }), Ul = Object.freeze([]), Di = Object.freeze({ cell: L.EmptyCell, ranges: Ul, rangeIndex: -1 }), Bm = (a, t, e) => {
if (!a) return Di;
let n = t.cell;
const r = e.colStart, o = e.rowStart, s = e.colEnd, i = e.rowEnd;
L.isEqualCells(n, a?.cell) || (n = Object.freeze({ colIndex: Math.max(r, Math.min(a?.cell?.colIndex ?? t.cell?.colIndex ?? 0, s)), rowIndex: Math.max(o, Math.min(a?.cell?.rowIndex ?? t?.cell?.rowIndex ?? 0, i)) }));
const l = a?.ranges ? [...a.ranges] : [];
let c = !1;
const h = l.length;
let d = h === 0;
for (let f = 0; f < h; f++) {
const p = l[f];
l[f] = Object.freeze({ colStart: Math.max(r, Math.min(p.colStart, s)), rowStart: Math.max(o, Math.min(p.rowStart, i)), colEnd: Math.max(r, Math.min(p.colEnd, s)), rowEnd: Math.max(o, Math.min(p.rowEnd, i)) }), d = d || L.isCellWithinRange(n, p), c = c || Object.keys(p).length > 4;
}
let u = t?.ranges ?? [];
!c && L.isEqualRangesArrays(u, l) || (u = l);
let g = a?.rangeIndex ?? t?.rangeIndex ?? Di.rangeIndex;
if (g = Math.max(-1, Math.min(g, u.length - 1)), !d) {
const f = u[g];
let p = n.rowIndex;
p < f.rowStart ? p = f.rowStart : p > f.rowEnd && (p = f.rowEnd);
let _ = n.rowIndex;
_ < f.colStart ? _ = f.colStart : _ > f.colEnd && (_ = f.colEnd), n = Object.freeze({ colIndex: _, rowIndex: p });
}
return Object.freeze({ cell: n, ranges: u, rangeIndex: g });
}, zm = (a, t = F.Direction.Right, e, n, r, o = null) => {
if (o && L.isEqualSelectionCoords(o, a)) return a;
const s = a.ranges[a.rangeIndex];
if (!L.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 (t) {
case F.Direction.Right:
i.colIndex = ye(r, i.colIndex + 1, t);
break;
case F.Direction.Left:
i.colIndex = ye(r, i.colIndex - 1, t);
break;
case F.Direction.Down:
i.rowIndex = ye(n, i.rowIndex + 1, t);
break;
case F.Direction.Up:
i.rowIndex = ye(n, i.rowIndex - 1, t);
}
const c = (u) => {
if (u) {
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 (t === F.Direction.Right && i.colIndex > s.colEnd && i.rowIndex === s.rowEnd) c(!0);
else if (t === F.Direction.Left && i.colIndex < s.colStart && i.rowIndex === s.rowStart) c(!1);
else if (t === F.Direction.Down && i.colIndex === s.colEnd && i.rowIndex > s.rowEnd) c(!0);
else if (t === F.Direction.Up && i.colIndex === s.colStart && i.rowIndex < s.rowStart) c(!1);
else {
let u = i.rowIndex, g = i.colIndex;
switch (t) {
case F.Direction.Right:
g > s.colEnd && (u = ye(n, u + 1, t), g = s.colStart, u > s.rowEnd && (u = s.rowStart));
break;
case F.Direction.Left:
g < s.colStart && (u = ye(n, u - 1, t), g = s.colEnd, u < s.rowStart && (u = s.rowEnd));
break;
case F.Direction.Down:
u > s.rowEnd && (g = ye(r, g + 1, t), u = s.rowStart, g > s.colEnd && (g = s.colStart));
break;
case F.Direction.Up:
u < s.rowStart && (g = ye(r, g - 1, t), u = s.rowEnd, g < s.colStart && (g = s.colEnd));
}
i = { rowIndex: u, colIndex: g };
}
let h = e(i);
if (!L.isRangeWithinRange(h, s)) {
const u = L.intersectRanges(h, s);
u && (h = u);
}
let d = { rowStart: ye(n, h.rowStart, F.Direction.Down), colStart: ye(r, h.colStart, F.Direction.Right), rowEnd: ye(n, h.rowEnd, F.Direction.Up), colEnd: ye(r, h.colEnd, F.Direction.Left) };
if (d.rowStart !== i.rowIndex || d.colStart !== i.colIndex) {
switch (t) {
case F.Direction.Right:
a.ranges[l].colStart === d.colStart && a.ranges[l].colEnd === d.colEnd && (i.rowIndex = d.rowEnd), i.colIndex = d.colEnd;
break;
case F.Direction.Left:
a.ranges[l].colStart === d.colStart && a.ranges[l].colEnd === d.colEnd && (i.rowIndex = d.rowStart), i.rowIndex === d.rowStart ? i.colIndex = d.colStart + 1 : i.colIndex = d.colStart;
break;
case F.Direction.Down:
a.ranges[l].rowStart === d.rowStart && a.ranges[l].rowEnd === d.rowEnd && (i.colIndex = d.colEnd), i.rowIndex = d.rowEnd;
break;
case F.Direction.Up:
a.ranges[l].rowStart === d.rowStart && a.ranges[l].rowEnd === d.rowEnd && (i.colIndex = d.colStart), i.colIndex === d.colStart ? i.rowIndex = d.rowStart + 1 : i.rowIndex = d.rowStart;
}
return o && console.warn("call recursive > 1"), zm({ cell: i, ranges: a.ranges, rangeIndex: l }, t, e, n, r, o ?? a);
}
return { ranges: a.ranges, cell: i, rangeIndex: l };
}, Bt = (a, t, e = -1) => {
if (!a || a.length === 0) return null;
const n = a[0], r = a.length === 1 && n.rowStart === n.rowEnd && n.colStart === n.colEnd, o = e === -1 ? a.length - 1 : Math.min(Math.max(0, e), a.length - 1);
if (!t) {
const s = a[o];
t = { rowIndex: s.rowStart, colIndex: s.colStart };
}
return { cell: t, ranges: r ? k.EmptyArray : [...a], rangeIndex: r ? -1 : o };
};
class Dw {
constructor(t) {
this._adjusting = null, this._emitter = null, this._coords = Di, this._sheet = t.sheet, this._emitter = new he(this);
const e = t.sheet;
this._adjusting = null, this._hiddenRowsAt = (n, r) => e.getRowHeaders().hiddenHeadersAt(n, r), this._hiddenColumnsAt = (n, r) => e.getColumnHeaders().hiddenHeadersAt(n, r), this._getCellCoordsAsRangeCoords = (n) => {
const r = L.cellToRange(n);
if (e.isClosed()) return r;
const o = e.getRange(r, { ignoreHidden: !0 }).getMerges();
return o.length === 0 ? r : o[0];
}, this._canSelectionSpanMergedCells = (n) => {
const r = e.getRange(n);
return r.isEntireColumns() || r.isEntireRows();
}, this._getMergedRanges = (n) => e.getRange(n, { ignoreHidden: !0 }).getMerges(), this._isContentfulCell = () => !1, this._contentfulCellFinder = (n, r, o, s, i, l) => {
const c = e.getSelectedRange().getExtended(s, n).getCoords();
switch (s) {
case F.Direction.Up:
return c.rowStart;
case F.Direction.Down:
return c.rowEnd;
case F.Direction.Left:
return c.colStart;
case F.Direction.Right:
return c.colEnd;
}
}, this._scrollCellCoordsIntoView = (n, r) => e.scrollTo(n, r ? { scroll: r } : void 0), this._selectionPolicy = t.selectionPolicy ?? "multiple", this._newSelectionMode = t.newSelectionMode ?? "clear";
}
navigate(t, e = !1, n = !1, r = 0) {
const o = this._coords;
if (!o.cell) return this;
let s = o.cell, i = o.cell;
if (e && o.ranges.length > 0) {
const S = o.ranges[o.rangeIndex], C = o.cell;
switch (t) {
case F.Direction.Up:
i = { rowIndex: C.rowIndex === S.rowStart ? S.rowEnd : S.rowStart, colIndex: S.colEnd }, s = { rowIndex: C.rowIndex === S.rowStart ? S.rowStart : S.rowEnd, colIndex: S.colStart };
break;
case F.Direction.Down:
i = { rowIndex: C.rowIndex === S.rowEnd ? S.rowStart : S.rowEnd, colIndex: S.colEnd }, s = { rowIndex: C.rowIndex === S.rowEnd ? S.rowEnd : S.rowStart, colIndex: S.colStart };
break;
case F.Direction.Left:
i = { rowIndex: S.rowEnd, colIndex: C.colIndex === S.colStart ? S.colEnd : S.colStart }, s = { rowIndex: S.rowStart, colIndex: C.colIndex === S.colStart ? S.colStart : S.colEnd };
break;
case F.Direction.Right:
i = { rowIndex: S.rowEnd, colIndex: C.colIndex === S.colEnd ? S.colStart : S.colEnd }, s = { rowIndex: S.rowStart, colIndex: C.colIndex === S.colEnd ? S.colEnd : S.colStart };
}
}
const l = this._getCellCoordsAsRangeCoords(i);
let { rowStart: c, colStart: h } = l;
const d = this._magicCell;
if (d) switch (t) {
case F.Direction.Up:
case F.Direction.Down:
d.colIndex >= l.colStart && d.colIndex <= l.colEnd && (h = d.colIndex);
break;
case F.Direction.Left:
case F.Direction.Right:
d.rowIndex >= l.rowStart && d.rowIndex <= l.rowEnd && (c = d.rowIndex);
}
if (!r) {
const S = this._getMaxRange();
switch (t) {
case F.Direction.Up:
c = ye(this._hiddenRowsAt, Math.max(l.rowStart - 1, S.rowStart ?? 0), t);
break;
case F.Direction.Down:
c = ye(this._hiddenRowsAt, Math.min(l.rowEnd + 1, S.rowEnd ?? Number.MAX_SAFE_INTEGER), t);
break;
case F.Direction.Left:
h = ye(this._hiddenColumnsAt, Math.max(l.colStart - 1, S.colStart ?? 0), t);
break;
case F.Direction.Right:
h = ye(this._hiddenColumnsAt, Math.min(l.colEnd + 1, S.colEnd ?? Number.MAX_SAFE_INTEGER), t);
}
if (n) {
const C = this._getMaxRange();
let y = 0;
switch (t) {
case F.Direction.Up:
y = C.rowStart ?? 0, c = this._contentfulCellFinder({ ...i, colIndex: this._coords.cell.colIndex }, this._isContentfulCell, this._hiddenRowsAt, t, !1, Math.max(y, this._hiddenRowsAt(y, !1)));
break;
case F.Direction.Down:
y = C.rowEnd ?? Number.MAX_SAFE_INTEGER, c = this._contentfulCellFinder({ ...i, colIndex: this._coords.cell.colIndex }, this._isContentfulCell, this._hiddenRowsAt, t, !1, Math.min(y, y - this._hiddenRowsAt(y, !0)));
break;
case F.Direction.Left:
y = C.colStart ?? 0, h = this._contentfulCellFinder({ ...i, rowIndex: this._coords.cell.rowIndex }, this._isContentfulCell, this._hiddenColumnsAt, t, !1, Math.max(y, this._hiddenColumnsAt(y, !1)));
break;
case F.Direction.Right:
y = C.colEnd ?? Number.MAX_SAFE_INTEGER, h = this._contentfulCellFinder({ ...i, rowIndex: this._coords.cell.rowIndex }, this._isContentfulCell, this._hiddenColumnsAt, t, !1, Math.min(y, y - this._hiddenColumnsAt(y, !0)));
}
}
}
let u = null;
r && (u = {});
const g = { rowIndex: c, colIndex: h }, m = this._getCellCoordsAsRangeCoords(g), f = { rowIndex: m.rowStart, colIndex: m.colStart };
e || (this._magicCell = g);
const p = this._firstActiveCoords, _ = L.isEqualCells(p, f) && L.isEqualCells(p, s);
if (e && !_ ? this.modify(f, s) : this.clearAndModify(f), u) this._scrollCellCoordsIntoView(u);
else {
if (e && p) {
const S = this._getMaxRange();
if (t === F.Direction.Right && p.colIndex === S.colEnd || t === F.Direction.Left && p.colIndex === S.colStart || t === F.Direction.Up && p.rowIndex === S.rowEnd || t === F.Direction.Down && p.rowIndex === S.rowStart) return this;
}
t === F.Direction.Left || t === F.Direction.Right ? this._scrollCellCoordsIntoView({ colStart: g.colIndex }) : t !== F.Direction.Up && t !== F.Direction.Down || this._scrollCellCoordsIntoView({ rowStart: g.rowIndex });
}
return this;
}
getCoords() {
return this._coords;
}
getRangesCoords(t) {
return ((e) => {
if (!e) return null;
const n = [];
if (e.ranges && e.ranges.length > 0) {
const r = Math.max(0, Math.min(e.rangeIndex ?? 0, e.ranges.length));
for (let o = r; o < e.ranges.length; o++) n.push(e.ranges[o]);
for (let o = 0; o < r; o++) n.push(e.ranges[o]);
} else e.cell && n.push(L.cellToRange(e.cell));
return n;
})(t ?? this._coords);
}
updateCoords(t) {
const e = this._coords;
if (L.isEqualSelectionCoords(e, t)) return;
const n = Bm(t, this._coords, this._getMaxRange());
return this._coords = n, this._emitter.notify("onChange"), this;
}
isEntire() {
const t = this._coords;
if (t.ranges.length === 0) return !1;
const e = this._getMaxRange(), n = t.ranges, r = n.length;
for (let o = 0; o < r; o++) {
const s = n[o];
if (!L.isRangeWithinRange(e, s)) return !1;
}
return !0;
}
traverse(t = F.Orientation.Row, e = !1) {
let n = F.Direction.Right;
n = t === F.Orientation.Row ? e ? F.Direction.Left : F.Direction.Right : e ? F.Direction.Up : F.Direction.Down;
const r = this._coords;
if (r.ranges.length === 0) return this.navigate(n);
const o = this._getCellCoordsAsRangeCoords(r.cell);
if (L.isEqualRangesArrays([o], r.ranges)) return this.navigate(n);
const s = zm(r, n, this._getCellCoordsAsRangeCoords.bind(this), this._hiddenRowsAt.bind(this), this._hiddenColumnsAt.bind(this));
this.updateCoords(s);
}
clear() {
this._setSelectionRanges(Ul);
}
modify(t, e, n) {
if (this._selectionPolicy === "single") return;
const r = this._coords, o = this._rangesFromCellOptional(r, t, e ?? 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(t, e = t, n) {
if (this._selectionPolicy !== "multiple" || !t || this._isCellOutOfBounds(t) || this._isCellOutOfBounds(e)) return;
const r = this._coords, o = this._cellToRangeActual(t, e);
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 };
L.isEqualSelectionCoords(i, r) || this.updateCoords(i);
}
clearAndModify(t, e, n) {
const r = this._coords;
t = { ...r.cell, ...t }, e = e ?? t;
const o = this._rangesFromCellOptional(r, t, e);
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(t) {
this._adjusting = t, this._emitter.notify("onAdjustingChange");
}
getAdjusting() {
return this._adjusting;
}
addListeners(t, e) {
return this._emitter.addListeners(t, e);
}
_setSelectionRanges(t) {
const e = this._coords;
let n = typeof t == "function" ? t(e.ranges) : t ?? Ul;
if (L.isEqualRangesArrays(n, e.ranges)) return;
let r = Math.max(n.length ? 0 : -1, Math.min(e.rangeIndex, n.length - 1)), o = e.cell;
r === -1 || L.isCellWithinRange(o, n[r]) || (o = { rowIndex: n[r].rowStart, colIndex: n[r].colStart }), n.length === 1 && L.isSingleCell(n[0]) && L.isCellWithinRange(o, n[0]) && (n = [], r = -1);
const s = { cell: o, ranges: n, rangeIndex: r };
L.isEqualSelectionCoords(s, e) || this.updateCoords(s);
}
_setSelectionCell(t) {
const e = this._coords, n = t ?? Ow, r = this._getCellCoordsAsRangeCoords(n);
if (!L.isSingleCell(r) && e.ranges.length === 0) return this.updateCoords({ ranges: [r], rangeIndex: 0, cell: n });
if (L.isEqualCells(n, e.cell)) return;
let o = e.ranges, s = e.rangeIndex;
e.ranges.length === 1 && (L.isSingleCell(e.ranges[0]) && L.isCellWithinRange(n, e.ranges[0]) || !L.isCellWithinRange(n, e.ranges[0])) && (o = [], s = -1);
const i = { ranges: o, rangeIndex: s, cell: n };
return L.isEqualSelectionCoords(i, e) ? void 0 : this.updateCoords(i);
}
_isCellOutOfBounds(t) {
const e = this._getMaxRange();
return t.rowIndex < e.rowStart || t.colIndex < e.colStart || t.colIndex > e.colEnd || t.rowIndex > e.rowEnd;
}
_cellToRangeActual(t, e) {
const n = { rowStart: Math.min(t.rowIndex, e.rowIndex), colStart: Math.min(t.colIndex, e.colIndex), rowEnd: Math.max(t.rowIndex, e.rowIndex), colEnd: Math.max(t.colIndex, e.colIndex) };
if (this._canSelectionSpanMergedCells(n)) return n;
const r = this._getCellCoordsAsRangeCoords(t), o = this._getCellCoordsAsRangeCoords(e), 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 L.extendRangeToUnionRanges(s, i);
}
_rangesFromCellOptional(t, e, n) {
const r = t.ranges.length > 0 ? t.ranges[t.rangeIndex] : { rowStart: t.cell.rowIndex, colStart: t.cell.colIndex, rowEnd: t.cell.rowIndex, colEnd: t.cell.colIndex }, o = { rowStart: Math.min(e.rowIndex ?? r.rowStart, n.rowIndex ?? r.rowStart), colStart: Math.min(e.colIndex ?? r.colStart, n.colIndex ?? r.colStart), rowEnd: Math.max(e.rowIndex ?? r.rowEnd, n.rowIndex ?? r.rowEnd), colEnd: Math.max(e.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();
}
get [Symbol.toStringTag]() {
return "[RangeShape]";
}
toString() {
let t = "";
return t += `selection:[${this._sheet.getRange(this._coords.cell).toString()}`, this._coords.ranges && this._coords.ranges.length > 0 && (t += `, ${this._sheet.getRanges(this._coords.ranges).toString()}`), this._coords.rangeIndex !== void 0 && this._coords.rangeIndex !== -1 && (t += `, ${this._coords.rangeIndex}`), t += "]", t;
}
}
class Li {
constructor(t, e) {
this._c = t, this._m = e;
}
getModel() {
return this._m;
}
getCoords() {
return this._c;
}
getPropertiesAt(t, e, n) {
return this._m.getPropertiesAt(t, e, n);
}
getSplit(t) {
const e = this._m;
return [new Li(t[0], e), new Li(t[1], e)];
}
}
class Lw extends Er {
constructor(t) {
if (super({ ...t }), this._coordsCache = null, !t.json) throw new Error("json is required");
this._sheet = t.sheet, this._styles = t.sheet?.getStyles() ?? new cs(), this._options = { ...t }, t.setOnContainerCoordsChange(this._processCoordsChange.bind(this)), t.setCreateSpatial(this._createSpatial.bind(this)), this._getContainerRanges = t.getContainerRanges, this._setContainerRanges = t.setContainerRanges;
const e = this;
this._options.transactions.addStateListener(this, { onRestoreOrRevert() {
e._coordsCache = null;
}, onBeforeCommitEnd() {
e._coordsCache = null;
} }), this._fromJSON({ ...t.json });
}
getRanges() {
return this._getContainerRanges();
}
setRanges(t, e) {
const n = this.getRanges(), r = this._setContainerRanges(t, e);
return this._processCoordsChange({ before: n?.getCoords() ?? null, after: r?.getCoords() ?? null }), this;
}
setType(t, e) {
return this._updateState({ type: t }, { description: "Set Conditional Format Type", ...e }), this;
}
getType() {
return this._getState().type;
}
setPriority(t, e) {
return this._updateState({ priority: t }, { description: "Set Priority", ...e }), this;
}
getPriority() {
return this._getState().priority;
}
setStopIfTrue(t, e) {
return this._updateState({ stopIfTrue: t }, { description: `Set Stop ${t ?? !1}`, ...e }), 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(t) {
this.toJSON();
const e = null, n = this, r = Object.freeze({ ...t });
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: e.colEnd - e.colStart + l.colStart, rowEnd: e.rowEnd - e.rowStart + l.rowStart };
return console.log("implement copyTo"), c;
}, getCoords: () => e, getSource: () => n, getName: () => "Conditional Format", getMarkOptions: () => r, isISnapshot: !0 };
}
_processRestoreOrRevert(t, e, n) {
super._processRestoreOrRevert(t, e, n);
}
_createSpatial(t) {
return new Li(t, this);
}
_processCoordsChange(t) {
this._coordsCache = null, t.after ? this._emitter.notify("onAnyChange") : this._delete();
}
update(t, e) {
if (this.isClosed()) throw new Error("Table has been closed. No further operations are allowed.");
const n = this._getState(), r = this._beginCommit(e?.description ?? "Update Conditional Format");
try {
const o = { ...n, ...t };
this._updateState(o, e), this._getEmitter().notify("onAnyChange"), r.commit();
} catch (o) {
throw r.rollback(), o;
}
return this;
}
_processDelete() {
this._getState(), super._processDelete();
}
_processStateChange(t, e, n) {
super._processStateChange(t, e, n), this._getEmitter().notify("onAnyChange");
}
toJSON() {
const t = {}, e = this._getState();
if (e === null) return null;
const n = this.getRanges()?.toString();
return n ? (t.ref = n, t.type = e.type, e.priority !== 0 && (t.priority = e.priority), e.stopIfTrue && (t.stopIfTrue = e.stopIfTrue), e.style && (t.style = e.style), e.colorScale && (t.colorScale = e.colorScale), e.dataBar && (t.dataBar = e.dataBar), e.iconSet && (t.iconSet = e.iconSet), e.aboveAverage && (t.aboveAverage = e.aboveAverage), e.equalAverage && (t.equalAverage = e.equalAverage), e.stdDev !== 0 && (t.stdDev = e.stdDev), e.bottom && (t.bottom = e.bottom), e.percent && (t.percent = e.percent), e.rank !== 0 && (t.rank = e.rank), e.operator && (t.operator = e.operator), e.formulas && (t.formulas = e.formulas), e.text && (t.text = e.text), e.timePeriod && (t.timePeriod = e.timePeriod), t) : null;
}
_fromJSON(t) {
const e = {};
e.type = t.type ?? Gl.Type.CellIs, e.priority = t.priority ?? 0, e.stopIfTrue = t.stopIfTrue ?? !1, e.style = t.style ?? null, e.colorScale = t.colorScale ?? null, e.dataBar = t.dataBar ?? null, e.iconSet = t.iconSet ?? null, e.aboveAverage = t.aboveAverage ?? !1, e.equalAverage = t.equalAverage ?? !1, e.stdDev = t.stdDev ?? 0, e.bottom = t.bottom ?? !1, e.percent = t.percent ?? !1, e.rank = t.rank ?? 0, e.operator = t.operator ?? null, e.formulas = t.formulas ?? null, e.text = t.text ?? null, e.timePeriod = t.timePeriod ?? null, this._updateState(e, { description: "Initialize Conditional Format" });
}
close() {
super.close(), this.isClosed() || (this._updateState({}, { description: "Close Conditional" }), this._stylesRemoveListener?.());
}
getCoords() {
return this.getRanges().getCoords()[0];
}
getPropertiesAt(t, e, n) {
return null;
}
get isIConditionalFormat() {
return !0;
}
}
class Bw {
constructor(t, e) {
this._add = t, this._get = e;
}
add(t, e) {
if (!t) throw new Error(pr);
return this._add(t, e);
}
getItems(t) {
let e;
return t?.address && (e = t.address), this._get(e, t?.ignoreHidden, t?.fullyContained);
}
getCount() {
return this._get(null, !1, !1).length;
}
}
const pu = (a, t) => {
if (t) {
if (t.getType() === st.Type.Solid) a.background = cn(t.getColor()) || "none", a["mso-pattern"] = "black none";
else if (t.getType() === st.Type.Pattern) {
const e = t;
a.background = cn(e.getBackground()) || "none";
const n = cn(e.getForeground()) || "";
if (e.getPatternType() === st.BuiltInSheetPattern.Solid) a["mso-pattern"] = `${a.background} none`, a.background = n;
else {
const r = ((o) => te.get(o)?.cssKey ?? "solid")(e.getPatternType());
a["mso-pattern"] = n + (r ? " " : "") + r;
}
} else if (t.getType() === st.Type.Gradient) {
const e = t;
a.background = cn(e.getStops()?.[0]?.getColor()) || "auto", a.msoGradient = pm(e) || "auto";
}
}
};
class zw {
constructor(t, e) {
if (this._visitedStyles = /* @__PURE__ */ new Map(), this._lastStyleClassId = 63, this._wroteTD = !1, !t) throw new Error("Can not create with a null sheet.");
this._sheet = t, this._includeSizeInCell = e ?? !1, this._normalStyle = t.getStyles().getNormal();
}
_createCSSStyle(t) {
const e = this._normalStyle, n = {}, r = (u, g) => u === g || !(u && !g) && !(!u && g) && g.isEqual?.(u), o = t.getFont(), s = e.getFont();
var i;
r(o.getFill(), s.getFill()) || (n.color = cn(o.getFill())), r(o.getSize(), s.getSize()) || (n["font-size"] = Id(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()) === dt.UnderlineStyle.Single ? "single" : i === dt.UnderlineStyle.Double ? "double" : i === dt.UnderlineStyle.SingleAccounting ? "single-accounting" : i === dt.UnderlineStyle.DoubleAccounting ? "double-accounting" : "none"), r(o.getFamily(), s.getFamily()) && r(o.getFallbacks(), s.getFallbacks()) || (n["font-family"] = Mi(o.getFamily(), o.getFallbacks())), r(t.getNumberFormat(), e.getNumberFormat()) || (n["mso-number-format"] = Md(t.getNumberFormat()));
const l = t.getAlignment(), c = e.getAlignment();
if (!r(l.getHorizontal(), c.getHorizontal())) {
const u = l.getHorizontal();
u === et.HorizontalAlignment.CenterContinuous ? n["text-align"] = "center-across" : u === et.HorizontalAlignment.Fill ? n["text-align"] = "fill" : u === et.HorizontalAlignment.Distributed ? n["text-align"] = l.getJustifyLastLine() ? "121" : "010" : n["text-align"] = et.toCSSHorizontalTextAlign(u);
}
if (!r(l.getVertical(), c.getVertical())) {
const u = l.getVertical();
u === et.VerticalAlignment.Distributed ? n["vertical-align"] = "121" : n["vertical-align"] = Rd(u);
}
if (!r(l.getOverflow(), c.getOverflow())) {
const u = l.getOverflow();
n["white-space"] = Ad(u), u === et.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(t.getFill(), s.getFill()) || pu(n, t.getFill());
const d = t.getBorder();
return d.getTop().isNone() || (n["border-top"] = hr(d.getTop())), d.getLeft().isNone() || (n["border-left"] = hr(d.getLeft())), d.getRight().isNone() || (n["border-right"] = hr(d.getRight())), d.getBottom().isNone() || (n["border-bottom"] = hr(d.getBottom())), d.getDiagonalUp().isNone() || (n["border-mso-diagonal-up"] = hr(d.getDiagonalUp())), d.getDiagonalDown().isNone() || (n["border-mso-diagonal-down"] = hr(d.getDiagonalDown())), Object.keys(n).length === 0 ? null : n;
}
_createCSSNormalStyle() {
const t = this._normalStyle, e = { "padding-top": "1px", "padding-left": "1px", "padding-right": "1px", "mso-ignore": "padding" }, n = t.getFont(), r = t.getAlignment();
return e.color = cn(n.getFill()), pu(e, t.getFill()), e["font-size"] = Id(n.getSize()), e["font-weight"] = n.getWeight(), e["font-style"] = n.getStyle(), e["text-decoration"] = gm(n.getUnderline(), n.getStrike()), e["font-family"] = Mi(n.getFamily(), n.getFallbacks()), e["mso-font-charset"] = "0", e["mso-background-source"] = "auto", e["mso-number-format"] = Md(t.getNumberFormat()), e["text-align"] = et.toCSSHorizontalTextAlign(r.getHorizontal()), e["vertical-align"] = Rd(r.getVertical()), e.border = "none", e["mso-pattern"] = "auto", e["white-space"] = Ad(r.getOverflow()), r.getOverflow() === et.Overflow.Shrink && (e["mso-text-control"] = "shrinktofit"), e["mso-rotate"] = "0", r.getIndent() > 0 && (e["mso-char-indent-count"] = r.getIndent()), e["mso-protection"] = "locked visible", e;
}
onCell(t, e, n) {
let r;
const o = t.getSpans();
if (o.width > 1 || o.height > 1) {
if (!t.isTopLeft()) return !1;
o.height > 1 && n.addAttribute("rowspan", o.height), o.width > 1 && n.addAttribute("colspan", o.width);
}
let s = t.toTextUnformatted();
t.getNumberFormat().repeatPlaceholder && (s = t.getNumberFormat().repeatPlaceholder.repeat(5)), n.setPlainText(s || "");
const i = t.getStyle(), l = i.getFont();
if (l.getVerticalAlignment() === dt.VerticalAlignment.Super && (s = `<sup>${s}</sup>`), l.getVerticalAlignment() === dt.VerticalAlignment.Sub && (s = `<sub>${s}</sub>`), l.getStrike() && (s = `<s>${s}</s>`), t.getHyperlink() && (s = `<a href="${t.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(e.colIndex).getSize();
n.addAttribute("width", h), n.addStyle("width", k.roundAccurately(h / dt.getDeviceScale(), 2) + "pt");
const d = this._sheet.getRowHeaders().at(e.rowIndex).getSize();
n.addAttribute("height", d), n.addStyle("height", k.roundAccurately(d / dt.getDeviceScale(), 2) + "pt");
}
return r;
}
onRow(t, e, n, r) {
const o = t.getSize();
r.addAttribute("height", o), r.addStyle("height", k.roundAccurately(o / dt.getDeviceScale(), 2) + "pt"), t.isCustomSize() && r.addStyle("mso-height-source", "userset");
}
onColumn(t, e, n, r) {
const o = t.getSize();
r.addAttribute("width", o), r.addStyle("width", k.roundAccurately(o / dt.getDeviceScale(), 2) + "pt"), t.isCustomSize() && r.addStyle("mso-width-source", "userset"), n > 1 && r.addAttribute("colspan", n);
}
}
const _u = (a, t, e) => {
const n = a.getOrientation() === F.Orientation.Column, r = (n ? "Column" : "Row") + " Copy", o = a.getSnapshot(e);
return { ...o, getName: () => r, getCoords: () => t, copyTo: async (s, i) => {
const l = n ? s.getColumnHeaders() : s.getRowHeaders(), c = { ...e, ...i };
if (c.includeHeaders === !0) {
const h = await o.copyTo(l, c);
return n ? { colStart: h.min, rowStart: t.rowStart, colEnd: h.max, rowEnd: t.rowEnd } : { colStart: t.colStart, rowStart: h.min, colEnd: t.colEnd, rowEnd: h.max };
}
}, getMarkOptions: () => e };
}, Pw = (a, t, e, n, r, o) => {
const s = e[0];
let i, l;
const c = () => {
if (l !== void 0) return;
const [h, d] = ((u, g) => {
const m = g.getRowHeaders(), f = g.getColumnHeaders(), p = g.getUsedRange()?.getCoords(), _ = m.getUsedRange()?.getCoords(), S = f.getUsedRange()?.getCoords(), C = { ...L.EmptyRange, ...p, colEnd: Math.max(p?.colEnd ?? 0, S?.max ?? 0), rowEnd: Math.max(p?.rowEnd ?? 0, _?.max ?? 0) }, y = /* @__PURE__ */ new Map(), E = [];
u.onStart?.();
const w = { rows: [], cols: [] }, b = new xw(y, E);
b.setNode(w), u.onTable?.(b, C);
let v = 0;
f.forEachSpan((z, B) => {
const H = B.getCoords();
v = v + H.max - H.min + 1;
const P = {};
b.setNode(P), u.onColumn?.(B.getCellHeader(), H.min, H.max - H.min + 1, b), w.cols.push(P);
}, { address: C, includeEmpty: !0, includeStyles: !0 });
let I = 0;
const x = [];
if (m.forEachSpan((z, B) => {
const H = B.getCoords();
I = I + H.max - H.min + 1, x.push({ min: H.min, max: H.max, value: B.getCellHeader() });
}, { address: C, includeEmpty: !0, includeStyles: !0, ignoreHidden: !1 }), v * I > 5e4) {
if (!lu) throw lu = !0, new Um("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((z, B) => {
const H = B.getCoords(), P = B.getCell();
if (H.rowIndex !== A) {
H.rowIndex > x[R].max && ++R;
const G = x[R];
M = { cells: [] }, b.setNode(M), u.onRow?.(G.value, H.rowIndex, 1, b), w.rows.push(M), A = H.rowIndex;
}
const j = {};
b.setNode(j), u.onCell(P, H, b) !== !1 && M.cells.push(j);
}, { address: C, includeEmpty: !0, ignoreHidden: !1 }), u.onDone?.(), w.rows.length === 0 && w.rows.push({ cells: [] });
const T = [];
for (let z = 0; z < E.length; z++) {
const B = E[z], H = y.get(B);
T.push(B);
let P = "";
const j = Object.keys(H);
for (let G = 0; G < j.length; G++) {
P += " ", G === 0 && (P += "{");
const K = j[G];
P += `${K}:${H[K]};`, G === j.length - 1 ? P += "}" : P += `
`;
}
T.push(P);
}
const O = [`<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"
>`];
O.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">`), O.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 && O.push(T.join(`
`)), O.push("</style>"), O.push("</head>"), O.push("<body>"), O.push("<table>"), O.push("<!--StartFragment-->");
const W = (z) => {
let B = ((P) => {
let j = "";
return P && P.attributes && P.attributes.length !== 0 && P.attributes.forEach((G, K) => {
j.length > 0 && (j += " "), j += `${K}=${G}`;
}), j;
})(z);
B.length > 0 && (B = " " + B);
let H = ((P) => {
let j = "";
return P && P.styles && P.styles.length !== 0 && (P.styles.forEach((G, K) => {
j.length > 0 && (j += ";"), j += K + ":" + G;
}), j.length > 0 && (j = `style='${j}'`)), j;
})(z);
return H.length > 0 && (H = " " + H), `${B}${H}`;
}, D = [];
return w.cols?.forEach((z) => {
O.push(` <col${W(z)}>`);
}), w.rows.forEach((z) => {
O.push(` <tr${W(z)}>`);
const B = [];
z.cells.forEach((H) => {
O.push(` <td${W(H)}>${H.htmlText ?? H.plainText ?? ""}</td>`);
const P = `${k.castToString(H.plainText ?? "")?.replace(/"/g, '""')}`;
B.push(P);
}), D.push(B.join(" ")), O.push(" </tr>");
}), O.push("<!--EndFragment-->"), O.push("</table>"), O.push("</body>"), O.push("</html>"), O.push("</div>"), [O.join(`
`), D.join(`
`).concat(`
`)];
})(new zw(t), t.getRange(s));
i = h ?? null, l = d ?? null;
};
return { copyTo(h, d) {
const u = { ...r, ...d };
return d.isCut, o(h, u);
}, getMarkOptions: () => r, getSource: () => a, getName: () => n, getCoords: () => s, toText: () => (c(), l), toHtml: () => (c(), i), toImage: () => null, isISnapshot: !0 };
}, _i = (a, t) => Math.round(a * t), Su = (a, t, e) => {
const n = [], r = [];
if (!a || a.length === 0) return { sizes: n, hidden: r };
if (!t || !e) 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;
const h = a.length;
for (let d = 0; d < h; d++) {
const u = a[d], g = u.min, m = 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: g - 1, runningOffsetMin: o, runningOffsetMax: Math.round(o + (g - s) * t * e) - 1, runningHiddenRuns: i, spanSize: Math.round(t * e) });
const f = n.length, p = n[f - 1];
o = f === 0 ? 0 : p.runningOffsetMax, f > 0 && p.spanSize > 0 && o++;
let _ = 0;
u.value.h || (_ = _i(u.value?.sz ?? t, e));
const S = _ === 0 ? 0 : -1;
_ === 0 && (i += m - g + 1, c + 1 === g ? l.max = m : (l = { min: g, max: m, value: !0 }, r.push(l)), c = m), f > 0 && p.spanSize === _ && p.indexMax + 1 === g ? (p.indexMax = m, p.runningHiddenRuns = i, p.runningOffsetMax = p.runningOffsetMin + (m + 1 - p.indexMin) * _ + S) : n.push({ indexMin: g, indexMax: m, runningOffsetMin: o, runningOffsetMax: Math.round(o + (m + 1 - g) * _) + S, runningHiddenRuns: i, spanSize: _ }), s = m + 1;
}
return { sizes: n, hidden: r };
};
function sl(a, t, e) {
e !== void 0 && (e !== null ? a[t] = e : delete a[t]);
}
const wu = (a, t, e) => {
if (a == null) return null;
let n = {};
if (typeof a == "number") n.colStart = a, n.colEnd = a, n.rowStart = a, n.rowEnd = a;
else if (typeof a == "string") {
if (t) {
if (a.match(/[0-9]+/)) throw new Error("Invalid range address for header orientation");
} else if (a.match(/[a-zA-Z]+/)) throw new Error("Invalid range address for header orientation");
let o = Pe(a, e);
if (!o) {
const s = nm(a.toUpperCase(), !0);
s?.colIndex !== void 0 && (n.colStart = s.colIndex, n.colEnd = s.colIndex), s?.rowIndex !== void 0 && (n.rowStart = s.rowIndex, n.rowEnd = s.rowIndex);
}
n = { ...n, ...o };
}
const r = { min: void 0, max: void 0 };
return t ? (r.min = a.min ?? a.colStart ?? n.colStart, r.max = a.max ?? a.colEnd ?? n.colEnd) : (r.min = a.min ?? a.rowStart ?? n.rowStart, r.max = a.max ?? a.rowEnd ?? n.rowEnd), r.min === void 0 || r.max === void 0 ? null : r;
}, il = () => {
}, al = () => 0, Ww = () => !1, yu = (a, t = !1) => {
if (!a || a.length === 0) return k.EmptyArray;
const e = [];
let n = null;
const r = a.slice().sort((s, i) => s.min - i.min), o = r.length;
for (let s = 0; s < o; s++) {
const i = r[s];
n && i.min <= n.max + 1 ? t ? n.max = Math.max(n.max, i.max) : (n = { min: n.max + 1, max: i.max }, e.push(n)) : (n = { min: i.min, max: i.max }, e.push(n));
}
return e;
}, Pm = (a, t, e, n) => {
if (n !== void 0) {
if (n === null) return null;
if (n?.isICellHeader)
return n._headerState;
if (n) {
const r = n, o = { ...e };
let s, i = r.hidden, l = r.size;
if (r.size !== void 0) {
if (typeof l == "function") {
const c = e?.sz === void 0 ? a.getDefaultSize() : e?.sz * a.getScaleFactor();
l = l?.(c);
}
if (typeof l == "string" && (l = Xr(l, t.getNormal().getFont().getSize(), "px")), typeof l == "number") {
const c = a.getMinSize(), h = a.getMaxSize();
l = Math.max(c, Math.min(k.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 mc {
constructor(t, e, n) {
this._sheetHeader = t;
const r = this._sheetHeader.getSheet().getStyles();
this._styles = r, this._headerState = e, this._template = n;
}
getSize() {
const t = this._headerState?.sz;
return Math.round(t === void 0 ? this._sheetHeader.getDefaultSize() : t * 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(t) {
const e = Pm(this._sheetHeader, this._sheetHeader.getSheet().getStyles(), this._headerState, t);
return new mc(this._sheetHeader, e, this._template);
}
isEqual(t) {
if (!t) return !1;
if (t === this) return;
const e = t;
if (!e.isICellHeader) return !1;
const n = this._headerState, r = e._headerState;
return n === r || !(n && !r || r && !n) && this.getSize() === e.getSize() && this.isCustomSize() === e.isCustomSize() && this.isHidden() === e.isHidden() && this.getStyle() === e.getStyle();
}
isEmpty() {
const t = this._headerState;
return !t || t.sz === void 0 && t.csz === void 0 && !t.cs && t.h === void 0 && !(!t.s || t.s !== this._styles.getNormal() || t.cs);
}
get [Symbol.toStringTag]() {
return "[SheetCellHeader]";
}
toString() {
return `[SheetCellHeader: ${this.getDisplayText()}]`;
}
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.", Jn = "Rows", Kn = "Columns";
class Hw {
constructor(t, e) {
this._header = t, this._coords = e;
}
_forEachSpan(t, e, n, r) {
const o = this._header, s = this._coords, i = o._options;
r || (r = i.createCellHeader);
let l = s;
if (e?.address) {
const h = o._parseHeaderRangeAddress(e?.address);
if (h && (l = Eh(s, h), !l)) return;
}
const c = o._scanHeaders(t, n, r, i, l, e);
if (c && c.break) return c.break;
}
forEachSpan(t, e) {
return this._forEachSpan(t, e, this._header._headers);
}
forEachVisibleSpan(t, e) {
const n = this._coords, r = n?.min ?? null, o = n?.max ?? null;
let s;
if (s = e?.includeHidden ? t(r, o) : kg(this._header._indexedHidden, (i) => {
if (i.value) return;
const l = t(i.min, i.max);
return l && l.break ? l : void 0;
}, r, o), s && s.break) return s.break;
}
forEach(t, e) {
let n = Number.MAX_SAFE_INTEGER, r = null;
const o = { getIndex: () => n, getCellHeader: () => r.getCellHeader(), getA1: (s) => r.getA1(s), getCoords: () => r.getCoords() };
return this._forEachSpan((s, i) => {
r = i;
const l = this._coords, c = l.max;
for (let h = l.min; h < c; h++) n = h, t(s, o);
}, e, this._header._headers, () => this.at(void 0));
}
updateHeaders(t, e) {
const n = this._header;
return n._updateHeaderPairs([{ address: this._coords, update: t }], { description: e?.description ?? `Update ${n._isColumn ? Kn : Jn} ${toString()}`, ...e }), this;
}
getCoords() {
return { ...this._coords };
}
setHidden(t) {
return this._header._setHidden(this._coords, t), this;
}
getUsedRange(t) {
const e = this._header, n = e._headerRunCoords;
return !n || n.min < 0 || n.max > e._maxDataIndex ? null : Eh(n, this._coords) ? e.getRange(n, t) : null;
}
getCount() {
const t = this._coords;
return t.max - t.min + 1;
}
getHeaderCount() {
const t = this._coords;
return t.max - t.min + 1;
}
getVisibleCount() {
const t = this._coords;
return this._header.getVisibleCount(t.min, t.max);
}
isEntireHeaders() {
const t = this._header._maxRunCoords, e = this._coords;
return !(e.min > t.min || e.max < t.max);
}
getSnapshot(t) {
return this._header._getSnapshot(this._coords, t);
}
clear() {
return this._header._clear(this._coords), this;
}
setSize(t, e) {
return this._header._setSize(this._coords, t, e), this;
}
at(t) {
return this._header.at(this._coords.min + t);
}
getOrientation() {
return this._header.getOrientation();
}
doBatch(t, e) {
return this._header.doBatch((n) => t(n), e);
}
getSheetHeader() {
return this._header;
}
getA1() {
const t = this._coords, e = this._header, n = e._isColumn ? { colStart: t.min, colEnd: t.max } : { rowStart: t.min, rowEnd: t.max };
return ln(n, e._maxRangeCoords) ?? ie;
}
get [Symbol.toStringTag]() {
return "[SheetCellHeaderRange]";
}
toString() {
return this.getA1();
}
get isICellHeaderRange() {
return !0;
}
}
class Vw {
constructor(t, e) {
this._header = t, this._coords = e;
}
updateHeaders(t, e) {
const n = this._header;
return n.updateHeaderPairs([{ address: this._coords, update: t }], { description: e?.description ?? `Update ${n._isColumn ? Kn : Jn} ${toString()}`, ...e }), this;
}
getCoords() {
return { ...this._coords };
}
setHidden(t) {
return this._header._setHidden(this._coords, t), this;
}
getCount() {
return this._coords.length;
}
getHeaderCount() {
const t = yu(this._coords, !0);
let e = 0;
const n = t.length;
for (let r = 0; r < n; r++) {
const o = t[r];
e += o.max - o.min + 1;
}
return e;
}
getVisibleCount() {
const t = yu(this._coords, !0);
let e = 0;
const n = this._header, r = t.length;
for (let o = 0; o < r; o++) {
const s = t[o];
e += n.getVisibleCount(s.min, s.max);
}
return e;
}
isEntireHeaders() {
const t = this._header._maxRunCoords, e = this._coords, n = t.min, r = t.max, o = e.length;
for (let s = 0; s < o; s++) {
const i = e[s];
if (n < i.min || r > i.max) return !1;
}
return !0;
}
isEntireHeadersAny() {
const t = this._header._maxRunCoords, e = this._coords, n = t.min, r = t.max, o = e.length;
for (let s = 0; s < o; s++) {
const i = e[s];
if (i.min <= n && i.max >= r) return !0;
}
return !1;
}
clear() {
return this._header._clear(this._coords), this;
}
setSize(t, e) {
return this._header._setSize(this._coords, t, e), this;
}
at(t) {
const e = this._coords;
return t < 0 || t >= e.length ? null : this._header.getRange(e[t]);
}
getOrientation() {
return this._header.getOrientation();
}
doBatch(t, e) {
return this._header.doBatch((n) => t(n), e);
}
getSheetHeader() {
return this._header;
}
getA1() {
const t = this._coords, e = this._header;
return ((n, r, o = ln) => {
if (!n) return ie;
const s = n.length, i = new Array(s);
for (let l = 0; l < s; l++) i[l] = o(n[l], r);
return i.join(",");
})(((n, r, o) => {
if (!n || n.length === 0) return k.EmptyArray;
const s = n.length;
let i = new Array(s);
const l = o ? r.rowStart : r.colStart, c = o ? r.rowEnd : r.colEnd;
for (let h = 0; h < s; h++) {
const d = n[h];
i[h] = { colStart: o ? d.min : l, rowStart: o ? l : d.min, colEnd: o ? d.max : c, rowEnd: o ? c : d.max };
}
return i;
})(t, e._maxRangeCoords, e._isColumn), e._maxRangeCoords) ?? ie;
}
get [Symbol.toStringTag]() {
return "[SheetCellHeaderRanges]";
}
toString() {
return this.getA1();
}
get isICellHeaderRanges() {
return !0;
}
}
class Cu {
constructor(t) {
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, maxSheetCoords: () => null, orientation: F.Orientation.Column, createCellHeader: (r, o, s) => new mc(r, o, s), ...t }, !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 e = this._options.orientation === F.Orientation.Column;
this._isColumn = e, this._cacheMaxIndex();
const n = this;
this._options.setContainerShiftedCallback && this._options.setContainerShiftedCallback((r, o) => {
o < 0 ? n._deleteHeaders(r, -o) : n._insertHeaders(r, o);
}), this._options.sheet && (this._sheetRemoveListener = this._options.sheet.addListeners({ onProtectionChange() {
}, onSelectionChange(r) {
n._selection = r.getSelection().getCoords(), n._selectionRuns = null;
}, onStyleChange: () => {
}, onViewChange() {
const r = { runs: n._headers };
n._invalidSizes(), n._cacheMaxIndex(), n._emitter.notify("onSizesChange", { params: r });
} }, { transactional: !1 }), n._selection = n._options.sheet.getSelection().getCoords()), this._transactions = this._options.transactions ?? new Ze({ transient: !0 }), this._emitter = new he(n, this._transactions), this._transactionsRemoveListener = this._transactions.addStateListener(this, { onAfterStateChange(r) {
n._lastHeaders !== r.headers && n._onHeaderChange();
} }), this.fromJSON(this._options?.json);
}
addListeners(t, e) {
return this._emitter.addListeners(t, e);
}
_cacheMaxIndex() {
const t = this._options.maxSheetCoords() ?? { colStart: 0, rowStart: 0, colEnd: Number.MAX_SAFE_INTEGER, rowEnd: Number.MAX_SAFE_INTEGER };
this._maxSheetCoords = t;
const e = this._isColumn, n = e ? t.colEnd : t.rowEnd;
this._maxDataIndex = n, this._maxRunCoords = { min: 0, max: n }, this._maxDataRange = this.getRange(this._maxRunCoords), this._maxRangeCoords = { colStart: 0, rowStart: 0, colEnd: e ? n : 0, rowEnd: e ? 0 : n };
}
_invalidSizes(t = !1) {
const e = this._defaultCustomSize === -1 ? this._options.defaultSize() : this._defaultCustomSize, n = this._options.scaleFactor();
if (t || e !== this._defaultSize || n !== this._scaleFactor) {
this._defaultSize = e, this._scaleFactor = n, this._defaultPxSize = _i(e, n);
const r = Su(this._headers, e, n);
this._indexedSizes = r.sizes, this._indexedHidden = r.hidden, this._lastVisibleRunsRead = null, this._lastVisibleRunCoords = null;
}
}
_onHeaderChange() {
this._lastHeaders = null;
const t = this._headers, e = this._getState();
this._defaultCustomSize = e.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 = Su(t, n, r);
this._indexedSizes = o.sizes, this._indexedHidden = o.hidden, this._lastHeaderRead = null, this._readCache = Ng(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 = t.length - 1; g >= 0; g--) {
const m = t[g], f = m.value, p = f.s, _ = 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 d = Math.min(t[0]?.min ?? h, h);
this._headerRunCoords = Object.freeze({ min: d, max: h }), this._hasCustomFormats = i, this._hasStyles = l, this._hasHidden = c;
const u = e.runs;
this._emitter.notify("onSizesChange", { params: u });
}
getSheet() {
return this._options.sheet;
}
getOrientation() {
return this._isColumn ? F.Orientation.Column : F.Orientation.Row;
}
getTextAt(t) {
return this._options.getTextAt?.(t) ?? t + "";
}
_scanHeaders(t, e, n, r, o, s) {
const i = o?.min ?? null, l = o?.max ?? null, c = s?.includeEmpty ?? !1, h = s?.includeStyles ?? !1, d = s?.ignoreHidden ?? !1, u = s?.includeSizes ?? !1, g = this, m = this._options.sheet.getStyles().getNormal(), f = this._defaultSize, p = this._scaleFactor, _ = this._emptyHeader;
let S;
const C = { getCoords() {
if (!S) throw new Error(Kr);
return { min: S.min, max: S.max };
}, getIndex: () => S.min, getCellHeader() {
if (!S) throw new Error(Kr);
return S.value ? n(g, S.value) : _;
}, getA1(E) {
if (!S) throw new Error(Kr);
return this._parseHeaderRangeAddress({ min: i + E, end: i + E }) ?? S;
} }, y = kg(e, (E) => {
const w = E.value;
if (!c && !w) return;
let b = c;
if (u && !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 = !d), !b) return;
let v = f;
E.value && (v = E.value.h ? 0 : E.value?.sz ?? f), v *= p, S = E;
const I = t(v, C);
return I && I.break ? I : void 0;
}, i, l);
return S = null, y;
}
getRange(t, e) {
if (!t) throw new Error(pr);
const n = this._parseHeaderRangeAddress(t);
return n.min < 0 || n.max > this._maxDataIndex ? (function(r) {
return Object.freeze({ getCoords: () => null, getOrientation: () => r.getOrientation(), toString: () => ie, getA1: () => ie, getCount: al, getHeaderCount: al, getVisibleCount: al, isEntireHeaders: Ww, forEach: il, forEachSpan: il, forEachVisibleSpan: il, getUsedRange: vt, getSnapshot: vt, updateHeaders: vt, clear: vt, setHidden: vt, setSize: vt, at: vt, doBatch: vt, getSheetHeader: () => r, isICellHeaderRange: !0 });
})(this) : new Hw(this, n);
}
getRanges(t, e) {
if (!t) throw new Error(pr);
const n = ((r, o, s) => {
if (typeof r == "string") {
const c = qi(r, s), h = c ? c.length : 0, d = new Array(h);
for (let u = 0; u < h; u++) {
const g = c[u];
d[u] = { min: o ? g.colStart : g.rowStart, max: o ? g.colEnd : g.rowEnd };
}
return r = d, d;
}
Array.isArray(r) || (r = [r]);
const i = r.length, l = new Array(i);
for (let c = 0; c < i; c++) l[c] = wu(r[c], o, s);
return l;
})(t, this._isColumn, this._maxRangeCoords);
return new Vw(this, n);
}
getSelectedRange(t) {
const e = this._options.sheet.getSelection().getRangesCoords()[0];
return this.getRange(e, t);
}
getSelectedRanges(t) {
return this.getRanges(this._options.sheet.getSelection().getRangesCoords(), t);
}
getUsedRange(t) {
return this.getRange(this._headerRunCoords, t);
}
getEntireRange(t) {
return t ? this.getRange(this._maxRangeCoords, t) : this._maxDataRange;
}
at(t) {
if (t < 0 || t > this._maxDataIndex) return this._emptyHeader;
if (this._lastHeaderRead?.offset === t) return this._lastHeaderRead.header;
const e = Fg(t, this._readCache);
if (!e) return this._emptyHeader;
const n = this._options.getTextAt?.(t) ?? t + "", r = this._options.createCellHeader(this, e, { value: n });
return this._lastHeaderRead = { offset: t, header: r }, r;
}
updateHeaderPairs(t, e) {
if (this.isProtected()) throw new Error(this._isColumn ? Ls : Bs);
return this._updatePairsInternal(t, e);
}
_parseHeaderRangeAddress(t) {
if (t == null) throw new Error("Must specify a range.");
const e = wu(t, this._isColumn, this._maxRangeCoords);
if (!e) throw new Error("Invalid header range.");
return e;
}
_update(t, e, n) {
if (!t || (Array.isArray(t) || (t = [t]), t.length === 0)) return;
const r = [], o = t.length;
for (let s = 0; s < o; s++) {
const i = this._parseHeaderRangeAddress(t[s]);
this.getRange(i).forEachSpan((l, c) => {
const h = c.getCoords();
r.push({ address: h, update: e });
}, { includeEmpty: !0 });
}
return this.updateHeaderPairs(r, n), this;
}
_setSize(t, e = null, n) {
(n?.relativeSize ?? !1) || typeof e != "number" || (e += "px");
const r = { size: e, autoSize: n?.autoSize ?? !1 }, o = `Resize ${this._isColumn ? Kn : Jn}`;
return this._update(t, r, { description: o, ...n }), this;
}
_setHidden(t, e = null) {
const n = { hidden: e }, r = `${e ? "Unhide" : "Hide"} ${this._isColumn ? Kn : Jn}`;
return this._update(t, n, { description: r }), this;
}
_clear(t, e) {
const n = "Clear " + (this._isColumn ? "Column Headers" : "Row Headers");
this.updateHeaderPairs([{ address: t, update: null }], { description: n, ...e });
}
_getSnapshot(t, e) {
if (t.min < 0) return k.EmptyArray;
e = Object.freeze({ ...e });
const n = this, r = this._getState(), o = (this._isColumn ? "Column" : "Row") + " Headers";
return { copyTo(s, i) {
const l = { ...e, ...i }, c = s.getCoords(), h = c.min - t.min, d = [];
if (n._scanHeaders((u, g) => {
const m = g.getCoords();
d.push({ address: { min: m.min + h, max: m.max + h }, update: g.getCellHeader() });
}, r.headers, n._options.createCellHeader, null, t, { includeSizes: !0, includeStyles: !0 }), !l.fitDestination) {
let u = t.max - t.min + 1, g = c.max - c.min + 1, m = k.roundAccurately(g / u);
if (m > 1 && g % u === 0) {
const f = d.length;
for (let p = 0; p < m; p++) for (let _ = 0; _ < f; _++) {
const S = d[_], C = S.address, y = (p + 1) * u;
d.push({ address: { min: C.min + y, max: C.max + y }, update: S.update });
}
}
}
if (s.doBatch(() => {
s.clear(), s.getSheetHeader()._updatePairsInternal(d);
}, o), l.isCut) {
const u = n._maxRunCoords;
t.min <= u.min && t.max >= u.max && n._clear(t);
}
return c;
}, getCoords: () => t, 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(t, e) {
if (!t || t.length === 0) return null;
const n = e?.skipCustomSize ?? !1, r = this._isColumn, o = this.getSheet().getStyles(), s = this._beginCommit({ description: e?.description ?? `Update ${r ? Kn : Jn}` });
let i = [...this._getState().headers], l = !1, c = !1;
const h = r ? U.Edge.Top : U.Edge.Left;
U.oppositeEdge(h);
const d = r ? U.Edge.Right : U.Edge.Bottom;
U.oppositeEdge(d);
const u = this, g = (y, E) => {
if (this.isProtected()) throw new Error(this._isColumn ? Ls : Bs);
c = c || E === null, !c && E && (c = !!E.isICellHeader || E?.size !== void 0 || E?.hidden !== void 0), l = l || E === null || E?.style !== void 0 || E?.isICellHeader;
const w = { onUpdate: (b, v) => n && b && b.csz ? b : Pm(u, o, b, v), onSplit: (b) => [b.value, b.value], onMerge: (b, v, I, x) => {
if (!(b && !v || !b && v || !b && !v) && b.sz === v.sz && b.csz === v.csz && b.h === v.h && b.cs === v.cs) return b;
}, isCull: (b, v, I) => b === void 0 };
i = bn(wh(i, { min: y.min, max: y.max, value: E }, w));
}, m = t.length, f = new Array(m);
for (let y = 0; y < m; y++) {
const E = t[y], w = this._parseHeaderRangeAddress(E.address);
if (w.min < 0 || w.max > this._maxDataIndex) throw new Wt(Ri);
g(w, E.update), f[y] = w;
}
let p = !1, _ = i.length;
if (_ > 0 && i[0].min === 0 && i[_ - 1].max === this._maxDataIndex) {
let y = i[0], E = !1, w = -1;
for (let I = 0; !E && I < _; I++) {
const x = i[I], R = x.min;
if (w + 1 !== R) {
E = !0;
continue;
}
const A = x.max;
w = A, y.max - y.min < A - R && (y = x);
}
E || (this._defaultCustomSize = y.value?.sz ?? -1, p = !0);
const b = this._defaultCustomSize === -1 ? this._options.defaultSize() : this._defaultCustomSize, v = [];
for (let I = 0; I < _; I++) {
const x = i[I], R = x.value;
if (R === null) continue;
const A = Object.keys(R).length;
A !== 0 && (A !== 1 || R.sz === void 0 || R.sz !== null && R.sz !== b) && v.push(x);
}
i = v, _ = i.length;
}
const S = [], C = this._defaultSize;
for (let y = 0; y < _; y++) {
const E = i[y], w = E.value;
if (w === null) continue;
let b = !1;
w.sz !== void 0 && w.sz !== C && (b = !0), w.csz && (b = !0), w.h && (b = !0), w.cs && (b = !0), b && S.push(E);
}
return i = S, _ = i.length, p && u._invalidSizes(!0), 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(t) {
return ((e, n, r) => {
if (n < 0) return 0;
if (!e || e.length === 0) return n * r;
const o = e[e.length - 1];
if (n > o.indexMax) return o.runningOffsetMax + Math.round((n - o.indexMax - 1) * r + (o.spanSize !== 0 ? 1 : 0));
const s = e[e.length === 1 ? 0 : k.findEqualOrGreater(e, n, (l) => l.indexMax)], i = n - s.indexMin;
return s.runningOffsetMin + i * s.spanSize;
})(this._indexedSizes, t, this._defaultPxSize);
}
findIndex(t) {
return Math.min(Math.max(0, ((e, n, r) => {
if (!e || e.length === 0) return Math.floor(n / r);
const o = e[e.length - 1];
if (n > o.runningOffsetMax) return o.indexMax + Math.ceil((n - o.runningOffsetMax) / r);
const s = e[e.length === 1 ? 0 : k.findEqualOrGreater(e, 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, t, this._defaultPxSize)), this._maxDataIndex);
}
findVisibleIndex(t) {
return this._lastVisibleRunsRead === t || (this._lastVisibleRunCoords = ((e, n, r = Number.MAX_SAFE_INTEGER) => {
if (!e || e.length === 0) return { min: n, max: n };
let o = e.length - 1, s = e[o];
if (n > s.indexMax) {
const l = n - s.runningHiddenRuns;
return { min: l, max: l };
}
o = e.length === 1 ? 0 : k.findEqualOrGreater(e, n, (l) => l.indexMax), s = e[o];
const i = s.spanSize === 0 ? Math.max(-1, s.indexMin - 1 - (e[o - 1]?.runningHiddenRuns ?? 1)) : n - s.runningHiddenRuns;
return { min: i, max: i + Math.min(r + 1, s.spanSize === 0 ? 1 : 0) };
})(this._indexedSizes, t, this._maxDataIndex), this._lastVisibleRunsRead = t), this._lastVisibleRunCoords;
}
getSpanSize(t, e = t + 1) {
return this.findOffset(e) - this.findOffset(t);
}
getVisibleCount(t, e) {
if (t > e) throw new Error("Invalid arguments.");
if (t < 0 || e > this._maxDataIndex) throw new Wt();
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 : k.findEqualOrGreater(n, r, (d) => d.indexMax), l = n[i];
let c = l.runningHiddenRuns;
if (l.spanSize === 0 && r <= l.indexMax) {
const d = l.indexMax - l.indexMin + 1;
s -= Math.min(d, l.indexMax - r + 1);
}
o > l.indexMax && i < n.length && (i = k.findEqualOrGreater(n, o, (d) => d.indexMax), l = n[Math.min(i, n.length - 1)]);
let h = l.runningHiddenRuns;
if (l.spanSize === 0 && l.indexMin <= o) {
const d = l.indexMax - l.indexMin + 1;
s -= Math.min(d, o - l.indexMin + 1), h -= d;
}
return s -= h - c, s;
})(this._indexedSizes, t, e) : e - t + 1;
}
isSelectedAll(t) {
const e = this.getSelectedRuns();
if (e.length === 0) return !1;
const n = e[k.findEqualOrGreater(e, t, (r) => r.max)];
return !(!n || t < n.min || t > n.max) && n.value.isSelectedAll;
}
isSelected(t) {
const e = this.getSelectedRuns();
if (e.length === 0) return !1;
const n = e[k.findEqualOrGreater(e, t, (r) => r.max)];
return !(!n || t < n.min || t > n.max);
}
getSelectedRuns() {
let t = this._selectionRuns;
return t || (this._selection && (t = ((e, n, r) => {
let o = [];
n?.ranges && n.ranges.length > 0 ? o = n.ranges : n?.cell && (o = [L.cellToRange(n?.cell)]);
let s = [];
const i = e.getOrientation() === F.Orientation.Column, l = o.length;
for (let c = 0; o && c < l; c++) {
const h = o[c], d = i ? h.colStart : h.rowStart, u = i ? h.colEnd : h.rowEnd, g = i ? h.rowStart : h.colStart, m = i ? h.rowEnd : h.colEnd, f = i ? r.rowStart : r.colStart, p = i ? r.rowEnd : r.colEnd, _ = g <= f && m >= p;
s = bn(wh(s, { min: d, max: u, value: { isSelectedAll: !1 } }, { onUpdate: (S, C) => {
const y = bl(S, C);
return y.isSelectedAll = S?.isSelectedAll || _, y;
} }));
}
return s;
})(this, this._selection, this._maxSheetCoords)), t || (t = k.EmptyArray)), this._selectionRuns = t, this._selectionRuns;
}
hiddenHeadersAt(t, e = !1) {
if (this._indexedSizes.length === 0) return 0;
let n = this._indexedSizes.length === 1 ? 0 : k.findEqualOrGreater(this._indexedSizes, t, (o) => o.indexMax), r = this._indexedSizes[n];
return !r || r.spanSize !== 0 || r.indexMin > t || r.indexMax < t ? 0 : e ? t - r.indexMin + 1 : r.indexMax - t + 1;
}
_insertHeaders(t, e) {
if (this.isProtected()) throw new Error(this._isColumn ? Ls : Bs);
if (e <= 0) return;
const n = this._beginCommit({ description: `Insert ${this._isColumn ? Kn : Jn}` }), r = this._getState();
let o = [...r.headers];
o = bn(((i, l, c = 1) => {
const h = k.findEqualOrGreater(i, l, (m) => m.max), d = i.slice(0, h), u = [], g = [];
if (!i[h]) return { preceding: d, modified: g, trailing: u };
i[h].min >= l ? u.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++) u.push({ ...i[m], min: i[m].min + c, max: i[m].max + c });
return { preceding: d, modified: g, trailing: u };
})(o, t, e));
const s = [{ min: t, max: t + e }];
this._updateState({ headers: o, runs: bn(wr([...r?.runs ?? [], ...s])) }), n.commit();
}
_deleteHeaders(t, e) {
if (this.isProtected()) throw new Error(this._isColumn ? Ls : Bs);
const n = this._beginCommit({ description: `Delete ${this._isColumn ? Kn : Jn}` }), r = this._getState();
let o = [...r.headers];
o = bn(jp(o, t, e));
const s = [{ min: t, max: t + e }];
this._updateState({ headers: o, runs: bn(wr([...r?.runs ?? [], ...s])) }), n.commit();
}
beginCommit(t) {
return this._beginCommit(typeof t == "string" ? { description: t } : t);
}
doBatch(t, e) {
return this._transactions.doBatch(t, typeof e == "string" ? { description: e } : { description: "Update Header", ...e });
}
isClosed() {
return this._closed;
}
close() {
this._sheetRemoveListener?.(), this._emitter.close(), this._transactionsRemoveListener?.(), this._closed = !0;
}
_getState() {
return this._transactions.getState(this);
}
_beginCommit(t) {
return this._transactions.beginCommit(t);
}
_updateState(t) {
const e = this._transactions.beginCommit();
try {
e.updateState(this, t), this._onHeaderChange(), e.commit();
} catch (n) {
throw e.rollback(), n;
}
}
fromJSON(t) {
const e = t || {};
this._defaultCustomSize = e.defaultSize ?? -1, this._defaultCustomSize <= 0 && (this._defaultCustomSize = -1), this._invalidSizes();
const n = this._options.sheet.getStyles().beginPersist();
try {
const r = [], o = e.headers ? e.headers.length : 0, s = this._maxDataIndex;
for (let i = 0; i < o; i++) {
let l = e.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), 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 t = { headers: [] };
if (this._defaultCustomSize !== -1 && (t.defaultSize = k.roundAccurately(this._defaultCustomSize, 8)), this._headers.length === 0) return t;
const e = this._defaultCustomSize, n = this.getSheet().getStyles().beginPersist(), r = this._headers.length;
for (let o = 0; o < r; o++) {
const s = this._headers[o], i = s.value;
if (!i) continue;
const l = { min: s.min, max: s.max };
i.sz !== void 0 && i.sz !== e && (l.sz = k.roundAccurately(i.sz, 8), i.csz !== void 0 && (l.csz = i.csz)), i.h === !0 && (l.h = i.h), Object.keys(l).length > 2 && t.headers.push(l);
}
return n.endPersist(), t;
}
get [Symbol.toStringTag]() {
return "[SheetHeader]";
}
toString() {
return "[SheetHeader]";
}
}
class Eu {
constructor(t, e) {
this._c = t, this._tvTl = e;
}
tvTl() {
return this._tvTl(this._c);
}
getCoords() {
return this._c;
}
}
const jw = (a) => {
let t = "";
const e = hi, n = a.length;
for (let r = 0; r < n; r++) {
const o = a[r];
o.type === "cell" ? t += e(o.value) : t += o.value;
}
return t;
}, $w = (a, t = 0, e = 0) => {
let n = "";
const r = im, o = a.length;
for (let s = 0; s < o; s++) {
const i = a[s];
i.type === "cell" ? n += r(i.value, t, e) : n += i.value;
}
return n;
};
class Gw {
constructor(t, e, n) {
this._c = t, this._tokens = e, this._references = n || k.EmptyArray;
}
getFormulaTextAt(t, e, n = !1) {
return n ? jw(this._tokens) : $w(this._tokens, t, e);
}
getTokensAt(t, e, n) {
let r = this._tokens;
return n !== void 0 && (r = ((o, s) => {
const i = o.length, l = [];
if (s === void 0) return k.EmptyArray;
let c = -1, h = !1;
for (let d = 0; !h && d < i; d++) {
const u = o[d], g = u.evalIndex ?? Number.MAX_SAFE_INTEGER;
if (c === -1) {
if (g !== s) continue;
c = d;
}
g > s ? h = !0 : l.push(u);
}
h = !1;
for (let d = c - 1; !h && d >= 0; d--) {
const u = o[d];
(u.evalIndex ?? Number.MAX_SAFE_INTEGER) > s ? h = !0 : l.unshift(u);
}
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 d = o[h];
if (d.type !== "cell") {
c[h] = d;
continue;
}
const u = { ...d }, g = { ...u.value };
u.value = g, c[h] = u, 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, t, e), r;
}
getReferencesAt(t, e) {
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 pt.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, t, e);
}
toJSON() {
const t = this._c;
return [kn(t), this.getFormulaTextAt(t.rowStart, t.colStart)];
}
getCoords() {
return this._c;
}
}
class Bi {
constructor(t, e, n) {
this.groupId = t, this.uuid = e, this.noShift = n;
}
onRemove(t) {
}
getShifted(t) {
if (!t.after) return null;
const e = this.noShift;
return e ? void 0 : { ...t.after, value: new Bi(this.groupId, this.uuid, e) };
}
getSplit(t, e) {
}
copyTo(t, e) {
return new Bi(this.groupId, this.uuid, this.noShift);
}
canTile(t, e) {
return !1;
}
}
class zi {
constructor(t, e, n, r, o, s, i, l, c, h) {
this.uuid = t, this.spatialsIds = e, 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(t, e) {
const n = this;
let r;
const o = () => {
if (r) return r;
const i = n.sheet, l = n.isRanges, c = n.coords;
return e || !c || c.length === 0 ? Rn(i, i.getEntireRange().getCoords(), null, e) : l ? (r = i.getRanges(n.coords), r) : (r = i.getRange(n.coords[0]), r);
}, s = t.trigger;
return { getSource: o, getFrom: () => null, getTo: () => null, trigger: s, isTransactional: t.isTransactional ?? !0, toString: () => `SheetRangeEvent: ('${s}', ${o().toString()})`, timeStamp: t.timeStamp ?? Date.now() };
}
notify(t, e) {
const n = this.createRangeEvent(t, e), r = this.handler ?? this.handlerW.deref();
try {
r?.(n);
} catch (o) {
console.warn(o);
}
this.options?.once && this.removeListener();
}
processRemove(t) {
const e = this.spatialsIds, n = e.indexOf(t.value.uuid);
console.assert(n !== -1, "invalid uuid");
const r = this.coords, o = r.slice(0, n).concat(r.slice(n + 1)), s = e.slice(0, n).concat(e.slice(n + 1));
return new zi(this.uuid, s, o, this.isRanges, this.sheet, this.generation, this.handler, this.handlerW, this.removeListener, this.options);
}
processShift(t) {
const e = this.spatialsIds.indexOf(t.value.uuid);
console.assert(e !== -1, "invalid uuid");
const n = [...this.coords];
return n[e] = { ...n[e], ...L.sanitizeRange(t) }, new zi(this.uuid, this.spatialsIds, n, this.isRanges, this.sheet, this.generation, this.handler, this.handlerW, this.removeListener, this.options);
}
processSplit(t) {
}
processMerge(t) {
}
}
const Wm = Object.freeze({ coords: L.EmptyCell, topLeft: Pi.EmptyTopLeft }), Uw = Object.freeze({ cell: L.EmptyCell, ranges: k.EmptyArray, rangeIndex: 0 }), ll = Object.freeze({ selection: Uw, topLeft: Pi.EmptyTopLeft, freezePanes: Wm, showRowHeaders: !0, showColumnHeaders: !0, showRowGridlines: !0, showColumnGridlines: !0, rowHeaderStyle: on.HeaderTextStyle.One, columnHeaderStyle: on.HeaderTextStyle.A1, showFormulas: !1, showZeros: !0, zoomScale: 100, gridLineColor: null });
class cl {
constructor(t) {
if (this._emitter = null, !t?.sheet) throw new Error("SheetView requires a sheet.");
const e = new he(this);
this._emitter = e, this._sheet = t.sheet, this.clear(!1), t.json && this._fromJSON(t.json);
}
addListeners(t, e) {
return this._emitter.addListeners(t, e);
}
setTopLeft(t) {
const e = this._state, n = e.topLeft;
return e.topLeft = Object.freeze({ left: t?.left ?? n.left, top: t?.top ?? n.top }), this._emitter.notify("onTopLeftChange"), this;
}
getTopLeft() {
return this._state.topLeft;
}
getFreezePanes() {
return this._state.freezePanes;
}
setFreezePanes(t) {
return this._state.freezePanes = this._mergeFreezePanes(t), this._emitter.notify("onFreezeSplitChange"), this;
}
_mergeFreezePanes(t) {
return t ? { ...this._state.freezePanes, coords: { colIndex: t?.coords?.colIndex ?? this._state.freezePanes.coords.colIndex, rowIndex: t?.coords?.rowIndex ?? this._state.freezePanes.coords.rowIndex }, topLeft: { left: t?.topLeft?.left ?? this._state.topLeft.left, top: t?.topLeft?.top ?? this._state.topLeft.top } } : Wm;
}
isShowRowHeaders() {
return this._state.showRowHeaders;
}
setShowRowHeaders(t) {
return this._state.showRowHeaders = t, this._notifyAll(), this;
}
isShowColumnHeaders() {
return this._state.showColumnHeaders;
}
setShowColumnHeaders(t) {
return this._state.showColumnHeaders = t, this._notifyAll(), this;
}
isShowRowGridlines() {
return this._state.showRowGridlines;
}
setShowRowGridlines(t) {
return this._state.showRowGridlines = t, this._notifyAll(), this;
}
isShowColumnGridlines() {
return this._state.showColumnGridlines;
}
setShowColumnGridlines(t) {
return this._state.showColumnGridlines = t, this._notifyAll(), this;
}
getRowHeaderStyle() {
return this._state.rowHeaderStyle;
}
setRowHeaderStyle(t) {
return this._state.rowHeaderStyle = t, this._notifyAll(), this;
}
getColumnHeaderStyle() {
return this._state.columnHeaderStyle;
}
setColumnHeaderStyle(t) {
return this._state.columnHeaderStyle = t, this._notifyAll(), this;
}
getZoomScale() {
return this._state.zoomScale;
}
setZoomScale(t) {
return this._state.zoomScale = t, this._notifyAll(), this;
}
isShowFormulas() {
return this._state.showFormulas;
}
setShowFormulas(t) {
return this._state.showFormulas = t, this._notifyAll(), this;
}
isShowZeros() {
return this._state.showZeros;
}
setShowZeros(t) {
return this._state.showZeros = t, this._notifyAll(), this;
}
getGridLineColor() {
return this._state.gridLineColor;
}
setGridLineColor(t) {
return this._state.gridLineColor = t, this._notifyAll(), this;
}
setRangeSelection(t) {
return this._state.selection = t, this._emitter.notify("onRangeSelectionChange"), this;
}
getRangeSelection() {
return this._state.selection;
}
getMovableSelection() {
return this._movableSelection;
}
setMovableSelection(t) {
const e = this._movableSelection;
return this._movableSelection = Object.freeze(t ?? []), k.isEqualArrays(e, this._movableSelection) || this._emitter.notify("onMovableSelectionChange"), this;
}
selectMovables(t, e = !1) {
const n = new Set(this._sheet.getMovables().getItems());
let r = null, o = !1;
if (e) {
r = [...this._movableSelection];
for (let s = t.length - 1; s >= 0; s--) {
const i = t[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 = !k.isEqualArrays(t, this._movableSelection), r = [...t];
o && (this._movableSelection = r, this._emitter.notify("onRangeSelectionChange"), this._emitter.notify("onMovableSelectionChange"));
}
unselectMovables(t) {
const e = this._movableSelection, n = [];
for (let r = 0; r < e.length; r++) {
const o = e[r];
t.indexOf(o) === -1 && n.push(o);
}
return e.length !== n.length && (this._movableSelection = n, this._emitter.notify("onRangeSelectionChange"), this._emitter.notify("onMovableSelectionChange")), this;
}
_notifyAll() {
const t = this._emitter;
t.notify("onRangeSelectionChange"), t.notify("onTopLeftChange"), t.notify("onFreezeSplitChange"), t.notify("onAnyChange");
}
toJSON() {
const t = {}, e = Object.keys(this._state);
for (let r = 0; r < e.length; r++) {
const o = this._state[e[r]];
o != null && o !== ll[e[r]] && (t[e[r]] = o);
}
delete t.movableSelection, delete t.gridLineColor, this._state.gridLineColor instanceof ae && (t.gridLineColor = this._state.gridLineColor.toString()), delete t.topLeft, !this._state.topLeft || this._state.topLeft.left === 0 && this._state.topLeft.top === 0 || (t.topLeft = { left: this._state.topLeft.left ?? 0, top: this._state.topLeft.top ?? 0 }), delete t.selection;
const n = this._state.selection;
if (n) {
let r = {};
!n.cell || n.cell.colIndex === 0 && n.cell.rowIndex === 0 || (r.cell = as(n.cell)), n.ranges && n.ranges.length > 0 && (r.ranges = ic(n.ranges), n.rangeIndex !== void 0 && n.rangeIndex !== -1 && n.rangeIndex !== 0 && (r.rangeIndex = n.rangeIndex)), Object.keys(r).length > 0 && (t.selection = r);
}
if (delete t.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), t.freezePanes = r;
}
return Object.keys(t).length === 0 ? null : t;
}
_fromJSON(t) {
let e = JSON.parse(JSON.stringify(t || {}));
e?.zoomScale && (e.zoomScale = k.roundAccurately(parseFloat(t.zoomScale), 2));
const n = (r) => {
const o = this._sheet.getRange(r).getBounds(), s = (e.zoomScale ?? 100) / 100;
return { x: o.x * s, y: o.y * s, width: o.width * s, height: o.height * s };
};
if (typeof e?.gridLineColor == "string" && (this._sheet?.getStyles() ? e.gridLineColor = this._sheet.getStyles().parseColor(t.gridLineColor) : console.warn("Style was created with no styles so gridLineColor can't be parsed.")), e.topLeft) if (typeof e.topLeft == "string") {
const r = n(Wr(e.topLeft));
e.topLeft = { left: r.x, top: r.y };
} else e.topLeft = Object.freeze({ left: e.topLeft?.left ?? e?.x ?? 0, top: e.topLeft?.top ?? e?.y ?? 0 });
if (e.selection) {
let r = Wr(e.selection.cell ?? "A1");
if (e.selection.cell = r, e.selection.ranges) {
let o = Math.max(0, Math.min(e.selection.rangeIndex ?? e.selection.ranges?.length - 1, e.selection.ranges?.length - 1));
e.selection.rangeIndex = o;
let s = !1;
for (let i = 0; i < e.selection.ranges.length; i++) {
const l = Ae(e.selection.ranges[i]);
e.selection.ranges[i] = l, i === o && r && !L.isCellWithinRange(r, l) && (s = !0);
}
if (s) for (let i = 0; s && i < e.selection.ranges.length; i++) L.isCellWithinRange(r, e.selection.ranges[i]) && (s = !1, e.selection.rangeIndex = i);
s && (e.selection.ranges.push(L.cellToRange(r)), e.selection.rangeIndex = e.selection.ranges.length - 1);
} else delete e.selection.rangeIndex;
}
if (e.freezePanes) {
const r = e.freezePanes;
if (typeof r.coords == "string" && (r.coords = Wr(r.coords)), typeof r.topLeft == "string") {
const o = Wr(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 }, e.topLeft || (e.topLeft = { top: 0, left: 0 }), o.colIndex > 0 && (r.topLeft.left = e.topLeft?.left ?? 0, e.topLeft.left = s.x - i.x + r.topLeft.left), o.rowIndex > 0 && (r.topLeft.top = e.topLeft?.top ?? 0, e.topLeft.top = s.y - i.y + r.topLeft.top);
}
e.freezePanes = { coords: { colIndex: r?.coords?.colIndex ?? e.freezePanes?.c ?? 0, rowIndex: r?.coords?.rowIndex ?? e.freezePanes?.r ?? 0 }, topLeft: { left: r?.topLeft?.left ?? e.freezePanes?.x ?? 0, top: r?.topLeft?.top ?? e.freezePanes?.y ?? 0 } };
}
this.update(e);
}
clear(t = !0) {
return this._state = { ...ll }, this._movableSelection = Object.freeze([]), t && this._notifyAll(), this;
}
update(t) {
return this._state = { ...ll, ...this._state, ...t }, 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 bu() {
const { getCrypto: a } = await import("./CRlsrdZLcL-QKyo2.mjs");
return a();
}
const vu = async (a, t, ...e) => {
const n = qw(...e);
return a.subtle.digest(t, n);
}, qw = (...a) => {
const t = a.reduce((r, o) => r + o.byteLength, 0), e = new Uint8Array(t);
let n = 0;
return a.forEach((r) => {
e.set(new Uint8Array(r), n), n += r.byteLength;
}), e.buffer;
}, xu = (a) => {
const t = new Uint8Array(a);
let e = "";
for (let n = 0; n < t.byteLength; n++) e += String.fromCharCode(t[n]);
return btoa(e);
};
class xn {
static {
this.DefaultAlgo = "SHA-512";
}
static {
this.DefaultSpinCount = 1e5;
}
static async generateSaltAndHash(t, e = xn.DefaultAlgo, n = xn.DefaultSpinCount) {
if (!t) return null;
const r = (await bu()).getRandomValues(new Uint8Array(16)), o = xu(r.buffer);
return { salt: o, hash: await xn._convertPasswordToHash(t, o, e, n) };
}
static async verifyPassword(t, e, n = xn.DefaultAlgo, r = xn.DefaultSpinCount) {
if (!t || !e) throw new Qe();
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 xn._convertPasswordToHash(t, e.salt, n, r), e.hash);
}
static async _convertPasswordToHash(t, e, n, r) {
const o = await bu();
n = n.toUpperCase();
const s = ((c) => {
const h = new ArrayBuffer(2 * c.length), d = new DataView(h);
for (let u = 0; u < c.length; u++) d.setUint16(2 * u, c.charCodeAt(u), !0);
return new Uint8Array(h);
})(t), i = ((c) => {
const h = atob(c), d = new Uint8Array(h.length);
for (let u = 0; u < h.length; u++) d[u] = h.charCodeAt(u);
return d.buffer;
})(e);
let l = await vu(o, n, i, s.buffer);
for (let c = 0; c < r; c++) {
const h = new Uint32Array([c]).buffer;
l = await vu(o, n, l, h);
}
return xu(l);
}
}
class Hm {
constructor(t, e = !1) {
this._emitter = null, this._emitter = new he(this), this.fromJSON(t), this._isReadOnly = e;
}
async lock(t, e, 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 (e) {
const s = await xn.generateSaltAndHash(e, n, r);
o = { salt: s.salt, hash: s.hash }, n && (o.algorithm = n), r && (o.spinCount = r);
} else o = null;
return t = t ?? {}, this._updateProperties(t), this._properties = t, this._password = o, this._emitter.notify("onLockChange"), this._emitter.notify("onChange"), this;
}
async unlock(t) {
if (this._isReadOnly) throw new Error("Cannot unlock a readonly workbook.");
return await this._validatePassword(t), this._clearProperties(), this._password = null, this._identities = null, this._password = null, this._emitter.notify("onLockChange"), this._emitter.notify("onChange"), this;
}
checkPassword(t) {
return this._validatePassword(t);
}
hasPassword() {
return this._password !== null;
}
async pause(t) {
return this._emitter.notify("onLockChange"), this._emitter.notify("onChange"), await this._validatePassword(t), 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(t) {
const e = this._password;
if (!(t && t.length !== 0 || e && e.hash)) return !0;
if (!t) throw new Error("Password is required.");
if (!await xn.verifyPassword(t, { salt: e.salt, hash: e.hash }, e.algorithm, e.spinCount)) throw new Error("Invalid password.");
return !0;
}
getProperties() {
return this._properties;
}
_isPropertyAllowed(t) {
if (this._isReadOnly) return !1;
if (!this.isLocked()) return !0;
const e = this._properties[t];
return typeof e == "boolean" && e;
}
_updateProperties(t) {
this._properties = { ...t, ...this._properties ?? {} };
}
_clearProperties() {
this._properties = null;
}
addListeners(t, e) {
return this._emitter.addListeners(t, e);
}
fromJSON(t) {
this._password = null, this._identities = null, this._isPaused = !1, this._properties = null, this._fromJSON(t ?? null), t && (t.password && (this._password = t.password), t.identities && (this._identities = t.identities));
}
_fromJSON(t) {
}
_toJSON(t) {
return t;
}
toJSON() {
if (!this._properties) return null;
let t = {};
return t = this._toJSON(t) ?? {}, this._password && (t.password = this._password), this._identities && (t.identities = this._identities), t;
}
}
const Jw = 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 Iu extends Hm {
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(t) {
super._updateProperties(t), this._properties = t;
}
_clearProperties() {
super._clearProperties(), this._properties = null;
}
_fromJSON(t) {
super._fromJSON(t), this._properties = t;
}
_toJSON(t) {
let e = this._properties;
if (e) {
t = { ...t, ...e };
const n = Object.keys(e);
for (let r = 0; r < n.length; r++) {
const o = e[n[r]];
o != null && o !== Jw[n[r]] && (t[n[r]] = o);
}
}
return super._toJSON(t);
}
get [Symbol.toStringTag]() {
return "[SheetProtection]";
}
toString() {
return null;
}
}
class hs {
constructor(t, e, n) {
this._coords = Object.freeze(t), this._sheet = e, this._readOnly = n?.readOnly ?? null;
}
_createRanges(t, e) {
let n = this._options;
return e && (n = { ...this._options, getOptions: Fn(this._options?.getOptions, e) }), new hs(t, this._sheet, n);
}
_createRange(t, e) {
let n = this._options;
return e && (n = { ...this._options, getOptions: Fn(this._options?.getOptions, e) }), new ds(t, this._sheet, n);
}
_validateWrite() {
const t = this._readOnly;
if (t) throw new Error(t);
}
getCoords() {
return this._coords;
}
[Symbol.iterator]() {
const t = this.entries({ ignoreCellDetails: !0 });
return { next() {
const e = t.next();
return e.done ? Lt : { done: !1, value: e.value.value };
}, [Symbol.iterator]() {
return this;
} };
}
entries(t) {
const e = this.getCoords(), n = t?.reverse ?? !1;
let r = n ? e.length - 1 : 0;
const o = this;
let s = o._createRange(e[r]), i = s.entries(t), l = i.next();
return { next() {
let c = l;
do {
if (l.done) {
if (r = n ? r - 1 : r + 1, r >= e.length || r < 0) return l = Lt, c;
s = o._createRange(e[r]), i = s.entries(t);
}
l = i.next();
} while (l.done);
return c;
}, [Symbol.iterator]() {
return this;
} };
}
async select(t) {
const e = await this._sheet._autoSelect(t ?? !0, Bt(this.getCoords()));
return this._createRanges(e);
}
calculate() {
const t = this.getCoords();
return this._sheet._calculate(t), this;
}
addListener2(t, e) {
return this._sheet._addRangesListeners2(this.getCoords(), t, e, !0);
}
addListener(t, e) {
return this._sheet._addRangesListeners(this.getCoords(), t, e);
}
find(t) {
return this._sheet._find(this.getCoords(), t);
}
getFlattened(t) {
const e = this.getCoords();
if (e.length === 1) return this._createRanges(e, t);
const n = t?.orientations ?? F.Orientations.Both, r = n === F.Orientations.Both, o = r ? Number.MAX_SAFE_INTEGER : 1, s = n === F.Orientations.Row ? F.Orientation.Column : F.Orientation.Row;
let i = Al(e, o, s);
if (r) {
const l = Al(e, o, F.Orientation.Column);
l.length < i.length && (i = l);
}
return this._createRanges(i, t);
}
getVisible(t) {
const e = this._sheet._getVisible(this.getCoords(), t);
return e && e.length !== 0 ? this._createRanges(e, t) : null;
}
getFixed(t) {
const e = [], n = this.getCoords();
for (let r = 0; r < n.length; r++) e.push(Mm(n[r], t));
return this._createRanges(e, t);
}
autoFit(t) {
return this._validateWrite(), this._sheet._autoFit(this.getCoords(), t), this;
}
clear(t, e) {
return this._validateWrite(), this._sheet._clear(this.getCoords(), t, e), this;
}
getStyle() {
return this._sheet._getStyle(this.getCoords());
}
merge(t) {
return this._validateWrite(), this._sheet._merge(this.getCoords(), t), this;
}
unmerge(t) {
return this._validateWrite(), this._sheet._unmerge(this.getCoords(), t), this;
}
getMerges() {
return this._sheet._getMerges(this.getCoords(), this._options?.ignoreHidden ?? !1);
}
insert(t) {
return this._validateWrite(), this._sheet._insertCells(this.getCoords(), t), this;
}
delete(t) {
return this._validateWrite(), this._sheet._deleteCells(this.getCoords(), t), this;
}
async insertFrom(t, e) {
this._validateWrite();
const n = await this._sheet._insertFrom(this.getCoords(), t, e);
return n ? this._createRanges([n]) : null;
}
async copyFrom(t, e) {
const n = await this._sheet._copyFrom(this.getCoords()[0], t, e);
return n ? this._createRanges([n]) : null;
}
isInvalidAny() {
const t = this.getCoords();
if (!t || t.length === 0) return !0;
for (let e = 0; e < t.length; e++) if (t[e] === null) return !0;
return !1;
}
getSnapshot(t) {
return this._sheet._getSnapshot(this.getCoords(), t);
}
getEntireRows(t, e) {
return this._createRanges(Ti(this.getCoords(), this._sheet._entireCoords, F.Orientation.Column, t), e);
}
getEntireColumns(t, e) {
return this._createRanges(Ti(this.getCoords(), this._sheet._entireCoords, F.Orientation.Row, t), e);
}
getRowHeaders(t) {
const e = this.getCoords();
return this._sheet._rowHeaders.getRanges(e, t);
}
getColumnHeaders(t) {
const e = this.getCoords();
return this._sheet._colHeaders.getRanges(e, t);
}
getDefaultShiftOrientation() {
return this._sheet._getDefaultShiftOrientation(this.getCoords()[0]);
}
getCount() {
return this.getCoords()?.length ?? 0;
}
getCounts(t) {
return this._sheet._contentCounts(this.getCoords(), t, this._options?.ignoreHidden ?? !1);
}
isContentful() {
return this._sheet._isContentful(this.getCoords(), this._options?.ignoreHidden ?? !1);
}
getRowCount() {
return this._sheet.getRowHeaders().getRanges(this.getCoords()).getHeaderCount();
}
getColumnCount() {
return this._sheet.getColumnHeaders().getRanges(this.getCoords()).getHeaderCount();
}
isEntireRowsAny() {
return this._sheet.getRowHeaders().getRanges(this.getCoords()).isEntireHeadersAny();
}
isEntireColumnsAny() {
return this._sheet.getColumnHeaders().getRanges(this.getCoords()).isEntireHeadersAny();
}
isEntireRows() {
return this._sheet.getRowHeaders().getRanges(this.getCoords()).isEntireHeaders();
}
isEntireColumns() {
return this._sheet.getColumnHeaders().getRanges(this.getCoords()).isEntireHeaders();
}
isOverlapping() {
return jo(this.getCoords());
}
at(t) {
const e = this.getCoords();
if (t < 0 || t > e.length - 1) throw new Wt();
return this._createRange(e[t]);
}
isReadOnly() {
return this._readOnly !== null;
}
isInvalid() {
return !1;
}
getA1() {
return rm(this.getCoords(), this._sheet._entireCoords, ln, nr);
}
getSheet() {
return this._sheet;
}
doBatch(t, e) {
return this._sheet.doBatch((n) => t(n), typeof e == "string" ? e : { description: "Ranges Update", ...e });
}
get [Symbol.toStringTag]() {
return "[SheetRanges]";
}
toString() {
return this.getA1();
}
get isICellRanges() {
return !0;
}
}
class ds {
constructor(t, e, n) {
this._coords = Object.freeze(t), this._sheet = e, this._readOnly = n?.readOnly ?? null;
}
getCoords() {
return this._coords;
}
_createRange(t, e) {
const n = this._sheet;
if (!t) return Rn(n, n._entireCoords);
if (n._validateCoords(t), n._closed) return Rn(null, n._entireCoords, t);
let r = this._options;
return e && (r = { ...this._options, getOptions: Fn(this._options?.getOptions, e) }), new ds(t, this._sheet, r);
}
_createRanges(t, e) {
let n = this._options;
return e && (n = { ...this._options, getOptions: Fn(this._options?.getOptions, e) }), new hs(t, this._sheet, n);
}
_deriveRanges(t, e) {
const n = this.getCoords();
let r = n;
return e && (r = e(n), !r) ? null : this._createRanges(r, t);
}
_deriveRange(t, e, n) {
if (!t) return this;
let r = this._sheet._rangeToCoords(t);
if (!r) return this;
const o = this.getCoords();
if ($o(r, o)) return this;
if (n) {
const l = n(r, o);
if (!l) return null;
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, Fn(this._options?.getOptions, e));
}
_validateMaxSize(t = 5e4) {
const e = this.getCoords(), n = this._sheet, r = n._colHeaders.getVisibleCount(e.colStart, e.colEnd);
if (n._rowHeaders.getVisibleCount(e.rowStart, e.rowEnd) * r > t) throw new ot(hm(t));
}
entries(t) {
const e = this.getCoords();
let n = e;
const r = this._sheet;
if (t?.address) {
const s = r._rangeToCoords(t?.address);
if (!s) throw new ot(Jr(t?.address));
if (n = L.intersectRanges(s, e), !n) return re;
}
n.colEnd < n.colStart && (n.colStart = e.colStart, n.colEnd = e.colEnd), n.rowEnd < n.rowStart && (n.rowStart = e.rowStart, n.rowEnd = e.rowEnd);
const o = this._options?.ignoreHidden ?? !1;
return r._cellIterator({ ignoreHidden: o, ...t, includeRangeTypes: !t?.ignoreCellDetails, bounds: n });
}
[Symbol.iterator]() {
return this.values();
}
values(t) {
const e = this.entries({ ...t, ignoreCellDetails: !0 });
return { next() {
const n = e.next();
return n.done ? Lt : { done: !1, value: n.value.value };
}, [Symbol.iterator]() {
return this;
} };
}
forEach(t, e) {
if (!t) return;
const n = this.entries(e);
let r = n.next();
for (; !r.done; ) {
const o = r.value, s = t(o.value, o.context);
if (s) return s.break;
r = n.next();
}
}
_validateWrite() {
const t = this._readOnly;
if (t) throw new ot(t);
}
updateCells(t, e, 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 = (e?.orientation ?? F.Orientation.Row) === F.Orientation.Column !== s, c = xi(Array.isArray(t) ? t : [[t]], l, i);
return o._updateTuples(c, { description: e?.description ?? `Set ${L.isSingleCell(n) ? "Cell" : "Range"} ${ln(n, o._entireCoords)}`, ...e }, null, { isCell: !0 }), this;
}
setValues(t, e) {
if (!Array.isArray(t)) throw new ot("'setValues' expects a 2d array; when working with a single value use 'setValue'.");
return this._setValueOrValues(t, e);
}
setValue(t, e) {
if (Array.isArray(t)) throw new ot(pd);
return this._setValueOrValues(t, e);
}
setFormula(t, e) {
if (Array.isArray(t)) throw new ot(pd);
return this._setValueOrValues(t, e);
}
_setValueOrValues(t, e) {
this._validateWrite();
let n = this.getCoords(), r = this;
const o = this._sheet, s = o._isDataColumn, i = (e?.orientation ?? F.Orientation.Row) === F.Orientation.Column, l = Array.isArray(t);
if (e?.skipBoundsCheck && l) {
const u = t;
let g = Math.max(0, u.length - 1), m = 0;
for (let S = 0; S < u.length; S++) m = Math.max(m, u[S].length - 1);
const f = i ? n.colStart : n.rowStart, p = i ? n.rowStart : n.colStart, _ = { ...n, colEnd: i ? f + g : p + m, rowEnd: i ? p + m : f + g };
L.isEqualRanges(_, n) || (n = _, r = this._deriveRange(_, e) ?? this);
}
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 d = null;
return d = l ? xi(Array.isArray(t) ? t : [[t]], h, c) : ri(t, c, s), o._updateTuples(d, { description: e?.description ?? `Set ${L.isSingleCell(n) ? "Value" : "Values"} ${ln(n, o._entireCoords)}`, ...e }), r;
}
getValues(t) {
this._validateMaxSize(t?.maxSize);
const e = this.getCoords(), n = this._sheet;
return $a(n._cellIterator.bind(this._sheet), e, !1, t);
}
toText(t) {
this._validateMaxSize(t?.maxSize);
const e = this.getCoords();
return ((n, r, o) => {
const s = { [ht.Type.Style]: !1, [ht.Type.Table]: !1 }, i = o?.orientation ?? F.Orientation.Row, l = o?.maxSize ?? 1e4, c = n({ includeEmpty: !0, orientation: i, reverse: o?.reverse, ignoreHidden: o?.ignoreHidden, includeMergeOverflow: o?.includeMergeOverflow, includeRangeTypes: s, bounds: r }), h = i !== F.Orientation.Row, d = o?.ignoreFormatting ?? !1;
let u, g = -1, m = 0, f = 0;
u = c.next();
let p = "";
for (; !u.done; ) {
if (m > l || p.length > 32767e3) return p + "...";
const _ = u.value, S = _.context.getCoords(), C = h ? S.colIndex : S.rowIndex;
C !== g && (g !== -1 && (p += `
`), g = C, f = 0);
const y = _.context.getCell();
let E = d ? y.toTextUnformatted() : y.toText();
y.getType() === Y.String && (Cg(E) || (E = `"${E}"`)), f > 0 && (p += ","), p += E, u = c.next(), f++, m++;
}
return p;
})(this._sheet._cellIterator.bind(this._sheet), e, t);
}
getValue(t) {
const e = this.getCoords();
return this._sheet._getScalar(e.rowStart, e.colStart, t?.asJSDate);
}
calculate(t) {
return this._sheet._calculate([this.getCoords()], { full: t }), this;
}
getCells(t) {
this._validateMaxSize(t?.maxSize);
const e = this.getCoords(), n = this._sheet;
return $a(n._cellIterator.bind(this._sheet), e, !0, t);
}
getCell(t) {
const e = this.getCoords();
let n = e.colStart, r = e.rowStart;
const o = this._sheet;
if (t) {
const i = o._cellToCoords(t);
if (!L.isCellWithinRange(i, e)) throw new ot("The cell is outside of the bounds of the range.");
n = i.colIndex, r = i.rowIndex;
}
const s = $a(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(t) {
const e = this._sheet, n = await e._autoSelect(t ?? !0, Bt([this.getCoords()]));
return this._createRange(n[0]);
}
find(t) {
return this._sheet._find([this.getCoords()], t);
}
getFixed(t) {
return this._createRange(Mm(this.getCoords(), t));
}
getSurrounding(t) {
const e = this._sheet;
return this._createRange(e._surroundingRegion(this.getCoords(), t));
}
getExtended(t, e) {
let n = null;
const r = this.getCoords();
switch (t) {
case F.Direction.Up:
n = { colIndex: r.colStart, rowIndex: r.rowStart };
break;
case F.Direction.Down:
n = { colIndex: r.colStart, rowIndex: r.rowEnd };
break;
case F.Direction.Left:
n = { colIndex: r.colStart, rowIndex: r.rowStart };
break;
case F.Direction.Right:
n = { colIndex: r.colEnd, rowIndex: r.rowStart };
}
const o = this._sheet, s = e ? o._cellToCoords(e) : n;
if (!L.isCellWithinRange(s, r)) throw new ot("Invalid cell.");
let i = o._extendRange(t, s);
return i = L.unionRanges(r, i), this._createRange(i);
}
getEntireRows(t, e) {
const n = this._sheet;
return this._createRange(Ti([this.getCoords()], n._entireCoords, F.Orientation.Column, t)[0], e);
}
getEntireColumns(t, e) {
const n = this._sheet;
return this._createRange(Ti([this.getCoords()], n._entireCoords, F.Orientation.Row, t)[0], e);
}
getRowHeaders(t) {
const e = this.getCoords();
return this._sheet._rowHeaders.getRange(e, t);
}
getColumnHeaders(t) {
const e = this.getCoords();
return this._sheet._colHeaders.getRange(e, t);
}
getDifferences(t, e) {
return this._deriveRanges(e, (n) => {
const r = this._sheet, o = r._rangeToCoords(t), s = Tl(n, o, F.Orientation.Row);
return r._getVisible(s, e);
});
}
getIntersect(t, e) {
return this._deriveRange(t, e, (n, r) => L.intersectRanges(n, r));
}
getUnion(t, e) {
return this._deriveRange(t, e, (n, r) => L.unionRanges(n, r));
}
getResizeTo(t, e, n) {
if (e = e ?? 0, (t = t ?? 0) < 0 || e < 0) throw new ot("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: e + r.colStart - 1, rowEnd: t + r.rowStart - 1 }, n);
}
getResizeBy(t, e, n) {
t = t ?? 0, e = e ?? 0;
const r = this.getCoords();
return this._deriveRange({ colStart: r.colStart, rowStart: r.rowStart, colEnd: r.colEnd + e, rowEnd: r.rowEnd + t }, n);
}
getOffsetTo(t, e, n) {
const r = this.getCoords(), o = e, s = t, i = { colStart: o, rowStart: s, colEnd: r.colEnd - r.colStart + o, rowEnd: r.rowEnd - r.rowStart + s };
return this._deriveRange(i, n);
}
getOffsetBy(t, e, n) {
const r = this.getCoords(), o = r.colStart + t, s = r.rowStart + e, i = { colStart: o, rowStart: s, colEnd: r.colEnd - r.colStart + o, rowEnd: r.rowEnd - r.rowStart + s };
return this._deriveRange(i, n);
}
getUsedRange(t) {
const e = this._sheet._getUsedCoords(t);
if (!e) return null;
const n = L.intersectRanges(e, this.getCoords());
return n ? this._deriveRange(n, t) : null;
}
isEmpty() {
const t = this._sheet._getUsedCoords();
return t ? !L.intersectRanges(t, 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 t = this.getCoords();
return t.colEnd - t.colStart + 1;
}
getRowCount() {
const t = this.getCoords();
return t.rowEnd - t.rowStart + 1;
}
getVisible(t) {
return this._deriveRanges(t, (e) => this._sheet._getVisible([e], t));
}
isContentful(t) {
return this._sheet._isContentful([this.getCoords()], t, this._options?.ignoreHidden ?? !1);
}
getCounts(t) {
return this._sheet._contentCounts([this.getCoords()], t, this._options?.ignoreHidden ?? !1);
}
getCount(t) {
return this._sheet._getCount([this.getCoords()], t, this._options?.ignoreHidden ?? !1);
}
isEntireRows() {
const t = this._sheet;
return Wl([this.getCoords()], t._entireCoords, !0);
}
isEntireColumns() {
const t = this._sheet;
return Hl([this.getCoords()], t._entireCoords, !0);
}
isEntireRange() {
const t = this.getCoords(), e = this._sheet;
return Hl([t], e._entireCoords, !0) && Wl([t], e._entireCoords, !0);
}
getWidth() {
const t = this._coords;
return t.colEnd - t.colStart + 1;
}
getHeight() {
const t = this._coords;
return t.rowEnd - t.rowStart + 1;
}
get size() {
const t = this._coords;
return t.colEnd - t.colStart + 1 * (t.rowEnd - t.rowStart + 1);
}
getBounds() {
return this._sheet._getBoundsAtCoords(this.getCoords());
}
isInvalid() {
return !1;
}
getDefaultShiftOrientation() {
return this._sheet._getDefaultShiftOrientation(this.getCoords());
}
getDefaultSortCriteria(t, e) {
return this._sheet._getDefaultSortCriteria(this.getCoords(), t, e);
}
getMerges() {
return this._sheet._getMerges([this.getCoords()], this._options?.ignoreHidden ?? !1);
}
getSnapshot(t) {
return this._sheet._getSnapshot([this.getCoords()], t);
}
isReadOnly() {
return this._readOnly !== null;
}
addListener2(t, e) {
return this._sheet._addRangesListeners2([this.getCoords()], t, e, !1);
}
addListener(t, e) {
return this._sheet._addRangesListeners([this.getCoords()], t, e);
}
getSheet() {
return this._sheet;
}
autoFill(t, e) {
this._validateWrite();
const n = this._sheet, r = n._rangeToCoords(t, () => [], !0);
return n._autoFill(this.getCoords(), r, e) ? this._createRange(r) : this;
}
autoFit(t) {
return this._validateWrite(), this._sheet._autoFit([this.getCoords()], t), this;
}
clear(t, e) {
return this._validateWrite(), this._sheet._clear([this.getCoords()], t, e), this;
}
setHyperlink(t, e) {
return this._validateWrite(), this._sheet._setHyperlinks([this.getCoords()], t, e), this;
}
setComments(t, e) {
return this._validateWrite(), this._sheet._setComments([this.getCoords()], t, e), this;
}
getStyle() {
return this._sheet._getStyle([this.getCoords()]);
}
merge(t) {
return this._validateWrite(), this._sheet._merge([this.getCoords()], t), this;
}
unmerge(t) {
return this._validateWrite(), this._sheet._unmerge([this.getCoords()], t), this;
}
insert(t) {
return this._validateWrite(), this._sheet._insertCells([this.getCoords()], t), this;
}
async insertFrom(t, e) {
this._validateWrite();
const n = this._sheet, r = await n._insertFrom([this.getCoords()], t, e);
return r ? this._createRange(r) : null;
}
async copyFrom(t, e) {
this._validateWrite();
const n = this._sheet, r = await n._copyFrom(this.getCoords(), t, e);
return r ? this._createRange(r) : null;
}
delete(t) {
return this._validateWrite(), this._sheet._deleteCells([this.getCoords()], t), this;
}
sort(t) {
this._validateWrite();
const e = this.getCoords(), n = this._sheet._sort(e, t);
return L.isEqualRanges(n, e) ? this : this._createRange(n);
}
doBatch(t, e) {
return this._sheet.doBatch((n) => t(n), typeof e == "string" ? e : { description: "Range Update", ...e });
}
startIncrementalUpdates(t) {
return this._sheet._createIncrementalUpdater(t, this);
}
getA1() {
const t = this._sheet;
return ln(this.getCoords(), t._entireCoords);
}
get [Symbol.toStringTag]() {
return "[SheetRange]";
}
toString() {
const t = this._sheet;
return ln(this.getCoords(), t._entireCoords);
}
get isICellRange() {
return !0;
}
}
const zs = { width: Math.pow(2, 14), height: Math.pow(2, 20) }, Ru = (a) => `${a}`, Au = (a) => tn(a), Mu = (a) => `${a + 1}`;
let Kw = 0;
const Tu = () => [];
let Xw = 0;
class ns {
constructor(t) {
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 e = Object.freeze({ ...t });
ju._validate(!0), this._transactions = e.transactions ?? new Ze(), this._ownTransactions = !e.transactions;
const n = this._beginCommit({ description: "New Sheet" }), r = this;
try {
this._entireCoords = Object.freeze({ colStart: 0, rowStart: 0, colEnd: (e.maxColumns ?? zs.width) - 1, rowEnd: (e.maxRows ?? zs.height) - 1 }), this._strings = e.strings ?? new dc(), this._ownStrings = !e.strings;
const o = e.styles ?? new cs();
this._styles = o, this._ownStyles = !e.styles, this._names = e.names ?? new Lm({ addressToRanges: (i) => r.getRanges(i), getCurrentScope: () => r.getName(), isReadOnly: () => r._options.readonly ?? !1, transactions: r._transactions }), this._ownNames = !e.names, this._namesRemoveListener = this._names.addListeners({ onCollectionChange: (i) => {
r._calculateFull();
} }, { transactional: !1 }), this._calculation = e.calculation ?? new Dm({ getNamed: (i, l) => {
Nu.address = i, Nu.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 = !e.calculation, this._workbook = e.workbook ?? null, this._normalStyleRanged = o.getNamed(mt.BuiltInName.Normal).getRanged(), this._resources = e.resources ?? new Nm(), this._ownResources = !e.resources;
const s = async () => {
this._ownsCalculation && await this._calculation.start(), this._starting = null;
};
this._starting = s(), e.container?.setNameChangeCallback && e.container.setNameChangeCallback(() => {
r._emitter.notify("onNameChange");
const i = this._getState().rangesListenerMap, l = /* @__PURE__ */ new Map();
i.forEach((h, d) => {
l.set(d, { 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();
}), e.container?.setVisibilityCallback && e.container.setVisibilityCallback(() => {
r._emitter.notify("onVisibilityChange");
}), e.container?.setIndexCallback && e.container.setIndexCallback(() => {
r._calculateFull();
}), this._movables = new Rw(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 he(this._movables, this._transactions), this._tables = new kw(this._addTable.bind(this), (i, l, c) => {
const h = i ? this._rangeToCoords(i) : this._entireCoords;
return r._getRangedEntries("tableSpatial", [h], { ignoreHidden: l, fullyContained: c, onEntry: (d) => d.model });
}, (i) => {
const l = r._getState();
return l ? l.tableMapName.get(i.toLocaleLowerCase()) : null;
}), this._conditionals = new Bw(this._addConditional.bind(this), (i, l, c) => {
const h = i ? this._rangeToCoords(i) : this._entireCoords, d = /* @__PURE__ */ new Set();
return r._getRangedEntries("conditionalSpatial", [h], { ignoreHidden: l, fullyContained: c, onEntry: (u) => {
d.add(u.getModel());
} }), Array.from(d);
}), this._isDate1904 = e.date1904 ?? !1, this._options = e, this._emitter = new he(this, this._transactions), this._entireRange = this.getRange(this._entireCoords), this._initState(), e?.container?.beforeFromJSON?.(this), e.json && this._fromJSON(e.json), e.readonly, n.commit({ forceAmend: this._ownTransactions, viewAfter: { initial: !0, skipProtectionCheck: !0 } });
} catch (o) {
throw n.rollback(), o;
}
this._initializing = !1;
}
_createRange(t, e, n = null) {
if (!t) return Rn(this, this._entireCoords);
if (this._validateCoords(t), this._closed) return Rn(null, this._entireCoords, t);
n === null && this._options.readonly && (n = "Readonly sheet");
let r = null;
return (e || n) && (r = { getOptions: e, readOnly: n }), new ds(((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;
})(t), this, r);
}
_createRanges(t, e, n = null) {
let r = null;
return n === null && this._options.readonly && (n = "Readonly sheet"), (e || n) && (r = { getOptions: e, readOnly: n }), new hs(t, this, r);
}
getRange(t, e) {
let n = !e && t && (t.rowStart !== void 0 || typeof t == "string");
if (n) {
if (typeof t == "string") {
if (this._lastRangeRead.address === t) return this._lastRangeRead.range;
} else if (t.rowStart !== void 0 && $o(t, this._lastRangeRead.address)) return this._lastRangeRead.range;
}
try {
const r = this._rangesToCoords(t);
if (r.length > 1) throw new ot(am);
const o = this._createRange(r[0], e);
return n && (this._lastRangeRead.address = { ...t }, this._lastRangeRead.range = o), o;
} catch (r) {
throw r instanceof Wt ? new Wt(r.message) : new ot(r.message ?? Jr(t));
}
}
getCell(t) {
const e = this.getRange(t);
if (e.size !== 1) throw new ot(id);
return e.getCell();
}
getRanges(t, e) {
if (!t) throw new ot(pr);
const n = this._rangesToCoords(t);
if (n.length === 0) throw this._createRangeError(t);
return this._createRanges(n, e);
}
getSelectedRange(t) {
const e = this.getSelection(), n = e.getCoords();
if (!t && this._lastActiveRead.selection === n && this._lastActiveRead.range) return this._lastActiveRead.range;
const r = e.getRangesCoords(), o = this.getRange(r[0]);
return t || (this._lastActiveRead.selection = n, this._lastActiveRead.range = o, this._lastActiveRead.ranges = this.getRanges(r)), o;
}
getSelectedRanges(t) {
const e = this.getSelection(), n = e.getCoords();
if (!t && this._lastActiveRead.selection === n && this._lastActiveRead.ranges) return this._lastActiveRead.ranges;
const r = e.getRangesCoords(), o = this.getRanges(r, t);
return t || (this._lastActiveRead.selection = n, this._lastActiveRead.ranges = o, this._lastActiveRead.range = this.getRange(r[0])), o;
}
getEntireRange(t) {
return t ? this.getRange(this._entireCoords, t) : this._entireRange;
}
getUsedRange(t) {
const e = this._getUsedCoords(), n = e ? this.getRange(e, t) : null;
return t || (this._lastUsedCoordsRead.coords = e, this._lastUsedCoordsRead.range = n), n;
}
_cellToCoords(t) {
if (this._lastCellDecoded.address === t) return this._lastCellDecoded.coords;
const e = this._rangeToCoords(t);
if (!e || !L.isSingleCell(e)) throw new ot(id);
const n = { colIndex: e.colStart, rowIndex: e.rowStart };
return this._lastCellDecoded.address = t, this._lastCellDecoded.coords = n, n;
}
_validateCoords(t, e = Ri) {
if (!L.isRangeWithinRange(t, this._entireCoords)) throw new Wt(e);
const n = t.colStart, r = t.rowStart, o = t.colEnd, s = t.rowEnd;
if (s < r || o < n) throw new ot(lm);
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 ot("Invalid range. All points must be valid integers.");
}
_createRangeError(t) {
return new ot(t ? pr : Jr(t));
}
_protectionCheck(t = null, e = null, n = null) {
if (t && this._closed) return;
if (!this._initializing && this._options.readonly) throw new ot(((i = "update") => `Unable to ${i}, this sheet is readonly.`)(n));
e && !Array.isArray(e) && (e = [e]);
const r = t(e), o = this.getProtection();
if (o?.getProperties()) {
if (r.length === 0) throw new ot(bs);
if (r) {
const i = r.length;
for (let l = 0; l < i; l++)
if (o[r[l]] !== !0) throw new ot(o_());
}
}
}
_rangesToCoords(t, e = null, n = !0, r = !1) {
if (e && this._closed) return k.EmptyArray;
if (t == null) return k.EmptyArray;
const o = this, s = qi(t, this._entireCoords, r ? Pe : ls, (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(fd), [h.getCoords()];
throw new ot(`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 ot(fd);
}
this._validateCoords(c);
}
}
if (!e) return s;
if (s.length === 0) throw this._createRangeError(t);
return this._protectionCheck(e, s), s;
}
_rangeToCoords(t, e = null, n = !0) {
if (!t) throw new ot(pr);
const r = e ? (s) => e(s) : void 0, o = this._rangesToCoords(t, r, n);
if (o.length === 0) throw new ot(Jr(t));
return o[0];
}
_collectRanges(t, e = [], n = !0, r = this._getState(), o = !1) {
if (!n || typeof n == "object" && 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 d = c.search(t, !1), u = d.length;
if (u === 0) return;
const g = n[l];
for (let m = 0; m < u; m++) {
const f = d[m];
if (g && !L.isRangeWithinRange(t, f)) continue;
const p = L.intersectRanges(t, f);
let _ = f.value;
_ === void 0 && (_ = !0), e.push({ ...p, value: { [h]: _ } });
}
};
if (s(ht.Type.Merge) && r.mergeSpatial) {
const l = r.mergeSpatial.search(t), c = l.length;
for (let h = 0; h < c; h++) {
const d = l[h], u = o ? d : L.intersectRanges(t, d);
e.push({ ...u, value: { merge: d.value } });
}
}
if (i(ht.Type.Unlock, r.unlockSpatial, "unlock"), i(ht.Type.Contentful, r.contentfulSpatial, "contentful"), i(ht.Type.Continuous, r.continuousFillSpatial, "continuous"), i(ht.Type.Hyperlink, r.hyperlinkSpatial, "hyperlink"), i(ht.Type.Comments, r.commentsSpatial, "comments"), i(ht.Type.Style, r.directStyleSpatial, "directStyle"), i(ht.Type.Formula, r.formulaSpatial, "formula"), i(ht.Type.Pending, r.pendingSpatial, "pending"), i(ht.Type.CalcError, r.calcErrorsSpatial, "calcError"), i(ht.Type.Spill, r.spillSpatial, "spills"), s(ht.Type.Conditional) && r.conditionalSpatial) {
const l = r.conditionalSpatial.search(t), c = n[ht.Type.Conditional], h = l.length;
for (let d = 0; d < h; d++) {
const u = l[d], g = L.intersectRanges(t, u);
c && !g || e.push({ ...g, value: { conditionals: [u.value] } });
}
}
if (s(ht.Type.Table) && r.tableSpatial) {
const l = r.tableSpatial.search(t), c = n[ht.Type.Table], h = l.length;
for (let d = 0; d < h; d++) {
const u = l[d];
if (c && !L.isRangeWithinRange(t, u)) continue;
const g = L.intersectRanges(t, u);
e.push({ ...g, value: { table: u.value.model } });
}
}
}
_cellIterator(t) {
const e = this._cellOptions, n = this._strings, r = this._cellStateIterator(t);
return { next(o) {
const s = r.next(o);
if (s.done) return Lt;
const i = s.value, l = new Ga(n, t, e), c = l.context;
return { done: !1, value: { value: l.setState(i), context: c } };
}, [Symbol.iterator]() {
return this;
} };
}
_rangeStateIterator(t) {
const e = this._getState();
if (!e || !t || !t.includeRangeTypes) return re;
const n = t?.bounds ?? this._getUsedCoords() ?? this._entireCoords;
let r = null;
t.includeRangeTypes === !0 ? r = e_ : k.isObject(t.includeRangeTypes) && (r = t.includeRangeTypes);
const o = t?.ignoreHidden, s = o === !0 || o === F.Orientation.Row, i = o === !0 || o === F.Orientation.Column, l = t?.includeMergeOverflow ?? !1, c = [], h = this, d = { includeHidden: !i }, u = { min: n.colStart, max: n.colEnd }, g = { includeHidden: !s }, m = { min: n.rowStart, max: n.rowEnd };
this._rowHeaders.getRange(m).forEachVisibleSpan((C, y) => {
this._colHeaders.getRange(u).forEachVisibleSpan((E, w) => {
h._collectRanges({ rowStart: C, rowEnd: y, colStart: E, colEnd: w }, c, r, e);
}, d);
}, g);
const f = new Qo.IteratorInstance(c, t), p = t?.reverse ?? !1, _ = t?.byCell;
let S;
return { next: (C) => {
if (S = f.next(C), S.done) return Lt;
const y = S.value, E = Ld(y.overlaps);
let w, b = y.range;
if (l) {
const x = E?.merge;
if (x) {
const R = x.getCoords(), A = n.colStart, M = n.rowStart, T = R.colStart, O = R.rowStart;
T < A && M < O && (w = { colIndex: T, rowIndex: O });
}
}
w || (w = { colIndex: b.colStart, rowIndex: b.rowStart });
const v = { colIndex: b.colEnd, rowIndex: b.rowEnd };
let I = null;
return _ && (I = { ...y.cell }), { done: !1, value: { start: p ? v : w, end: p ? w : v, cell: I, intersection: E } };
} };
}
_overflowAndStops(t, e) {
const n = this._getState();
if (!n || !t) return null;
let r = this._entireCoords;
e && (r = { colStart: Math.max(r.colStart - e, r.colStart), rowStart: r.rowStart, colEnd: Math.min(r.colEnd + e, r.colEnd), rowEnd: r.rowEnd });
const o = { rowStart: t.rowStart, colStart: r.colStart, rowEnd: t.rowEnd, colEnd: r.colEnd }, s = { bounds: o, includeRangeTypes: r_, orientation: F.Orientation.Row, ignoreHidden: !0, byCell: !1 }, i = t.colStart, l = t.colEnd;
let c, h, d = -1;
const u = (S, C) => {
let y = S.next();
for (; !y.done; ) {
const E = y.value, w = E.intersection, b = w.contentful;
if (b) {
const v = E.start.rowIndex;
if (!h || v !== d) {
const I = E.end.rowIndex, x = b.getCoords(), R = C ? x.colEnd : x.colStart;
let A = null;
C && (A = w.continuous), c || (c = []);
for (let M = v; M <= I; M++) c.push({ rowIndex: M, colIndex: R, continuous: A, intersection: w, scalar: null, leftIndex: 0, rightIndex: 0, overflow: null, style: null });
}
d = v, h = E;
}
y = S.next();
}
};
i > r.colStart && (o.colStart = r.colStart, o.colEnd = t.colStart - 1, u(this._rangeStateIterator(s), !0)), d = -1, h = void 0, l < r.colEnd && (o.colStart = t.colEnd + 1, o.colEnd = r.colEnd, u(this._rangeStateIterator(s), !1));
const g = n.cellValuesGrid;
if (!c) return null;
c.sort(L.columnFirstCellComparator);
const m = c.length, f = this._cellOptions;
let p, _;
for (let S = 0; S < m; S++) {
const C = c[S], y = C.rowIndex, E = C.colIndex, w = g.getValueAt(y, E);
C.scalar = w;
const b = C.continuous;
if (typeof w == "string" || b) {
No.colStart = E, No.rowStart = y, No.colEnd = E, No.rowEnd = y;
const v = Vr(0, No, C.intersection, f);
C.style = v;
const I = Rm(y, E, Y.String, v, w, null, null, b?.getCoords(), f);
if (I) {
const x = I.leftIndex, R = I.rightIndex;
C.leftIndex = x, C.rightIndex = R, (R > 0 && E < i || x > 0 && E > l) && (C.overflow = I);
}
}
C.overflow ? (p || (p = []), p.push(C)) : (_ || (_ = []), _.push(C));
}
return { overflows: p, stops: _ };
}
_cellStateIterator(t) {
const e = this._getState();
if (!e) return re;
const n = t?.bounds, r = n ?? this._entireCoords, o = t?.orientation ?? F.Orientation.Row, s = t?.reverse ?? !1, i = t?.includeEmpty, l = { bounds: r, orientation: o, reverse: s };
let c;
i && (c = { bounds: r, orientation: o, reverse: s });
const h = t?.ignoreHidden;
if (h === !0 || h === F.Orientation.Row) {
const B = ja(this._rowHeaders);
l.processRowSkip = po(B), i && (c.processRowSkip = po(B));
}
if (h === !0 || h === F.Orientation.Column) {
const B = ja(this._colHeaders);
l.processColumnSkip = po(B), i && (c.processRowSkip = po(B));
}
const d = i || !t?.ignoreEmptyIntersections;
let u = t.includeRangeTypes;
u === !0 && (u = cm);
const g = t?.includeMergeOverflow ?? !1, m = u ? this._rangeStateIterator({ bounds: r, orientation: o, reverse: s, includeRangeTypes: u, includeMergeOverflow: g, ignoreHidden: t.ignoreHidden, byCell: !0 }) : re;
let f, p;
if (g && n) {
const B = this._overflowAndStops(n);
B && (f = B.overflows, f?.sort(L.createCellComparator(o, s)), p = B.stops, p?.sort(L.createCellComparator(o, s)));
}
const _ = f ? f.length : 0, S = p ? p.length : 0;
let C = 0, y = 0;
const E = e?.cellValuesGrid ?? null;
let w = E ? E.entries(l) : re, b = w.next(), v = null, I = null, x = null;
b.done || (v = b.value[0], I = b.value[1]);
let R = f?.[C++], A = m.next(), M = null;
const T = o !== F.Orientation.Row;
let O;
const W = L.createCellComparator(o, s);
let D;
if (!A.done) {
const B = A.value;
M = B.intersection, D = B.start;
}
O = (B) => {
let H = null, P = null, j = null, G = !1, K = !1, V = null, $ = null, J = !1;
if (R && (v ? W(R, v) < 0 && (J = !0) : D ? W(R, D) < 0 && (J = !0) : C <= _ && (J = !0)), J) H = { colIndex: R.colIndex, rowIndex: R.rowIndex }, P = R.scalar, j = R.intersection, R = f[C++];
else if (v && D) {
const X = W(v, D);
X < 0 ? (H = v, P = I, G = !0) : X > 0 ? (H = D, j = M, K = !0) : (H = v, P = I, j = M, G = !0, K = !0);
} else if (v) H = v, P = I, G = !0;
else {
if (!D || !d) return Lt;
H = D, j = M, K = !0;
}
if (G && (b = w.next(), b.done ? v = null : (v = b.value[0], I = b.value[1])), K) {
const X = d ? void 0 : v;
if (A = m.next(X), A.done) D = null, M = null;
else {
const at = A.value;
M = at.intersection, D = at.cell;
}
}
let Z = !1;
const q = H.rowIndex, Q = H.colIndex;
T || (Z = q === x?.rowIndex);
let it = !1;
if (T || (it = q === v?.rowIndex), Z) V = x;
else if (g) {
let X = !1;
for (; !X && y < S; ) {
const at = p[y], ut = at.rowIndex;
ut < q ? y++ : (X = !0, ut === q && at.colIndex < Q && (y++, V = { colIndex: at.colIndex, rowIndex: at.rowIndex }));
}
}
if (it) $ = v;
else if (g) {
let X = !1;
for (; !X && y < S; ) {
const at = p[y], ut = at.rowIndex;
ut < q ? y++ : (X = !0, ut === q && at.colIndex > Q && (y++, $ = { colIndex: at.colIndex, rowIndex: at.rowIndex }));
}
}
return (G || J) && (x = H), { done: !1, value: [H, P, j, V, $] };
};
let z = { next: O, return: (B) => null, throw: (B) => null };
return i && (z = new Gg(z, l)), z;
}
_indexMerges(t, e = null) {
if (!(t && t.length !== 0 || e && e.length !== 0)) return;
const n = this._getState();
if (!n) return;
const r = this._beginCommit({ description: "indexMerges" }), o = n.mergeSpatial.clone();
if (e) {
const s = e.length;
for (let i = 0; i < s; i++) o.remove(e[i]);
}
if (t) {
const s = (c) => this._getState().cellValuesGrid.getValueAt(c.rowStart, c.colStart), i = [], l = t.length;
for (let c = 0; c < l; c++) {
const h = t[c];
i.push({ ...h, value: new Eu(h, s) });
}
o.load(i);
}
this._updateState({ mergeSpatial: o }), r.commit();
}
_updateStyles(t, e, n, r = !1) {
const o = n?.description ?? "Update Style";
this._protectionCheck(() => ["formatCells"], t, o);
const s = this._beginCommit({ description: o }), i = Bt(t);
try {
const l = this._getState();
if (!l) return k.EmptyArray;
const c = l.directStyleSpatial, h = s.getId(), d = c.clone(h);
let u = l.continuousFillSpatial;
const g = this._styles, m = t.length;
for (let f = 0; f < m; f++) {
const p = (v, I) => {
let x = null;
const R = Ki(0, I, () => {
if (x) return x;
const A = v.getCoords();
return x = no(g, v, A), x;
});
return v.cloneWithUpdate(R);
}, _ = !u.isEmpty();
let S = null;
const C = t[f], y = C.value, E = y !== void 0 ? y : e, w = p(new oe(g, C), E), b = (v, I) => {
if (r && v.value && v.value.getProperties()?.numberFormat) return v;
const x = L.sanitizeRange(v);
let R, A = null, M = v.value;
if (M || (M = new oe(g, x)), typeof E == "function") A = p(M, E);
else {
let T = I.value._p ?? null;
A = M.cloneWithUpdate(T);
}
if (A.isEmpty() && (A = null), A) {
const T = A._p?.alignment?.horizontal;
!T || T !== et.HorizontalAlignment.CenterContinuous && T !== et.HorizontalAlignment.Fill || (R = p(new oe(g, C), { alignment: { horizontal: T } }));
}
return (R || _) && (S || (S = []), S.push({ ...v, value: R ?? null })), { ...I, value: A };
};
if (d.insertNonOverlapping({ ...C, value: w }, { onIntersect: b }), S) {
u === l.continuousFillSpatial && (u = u.clone());
const v = S.length;
for (let I = 0; I < v; I++) {
const x = S[I];
u.insertNonOverlapping(x);
}
}
}
if (this._lastUsedCoordsRead.coords = null, this._updateState({ directStyleSpatial: d, continuousFillSpatial: u }), n?.autoFit) {
const f = typeof n.autoFit == "boolean" ? hl : n.autoFit;
this._autoFit(t, f);
}
this._emitter.notify("onStyleChange"), r ? s.commit({ forceAmend: !0 }) : this._commitAndAutoSelect(s, i, n?.autoSelect, { viewAfter: { ranges: t } });
} catch (l) {
throw s.rollback(), l;
}
}
_createIncrementalUpdater(t, e = null, n) {
const r = t?.orientation ?? F.Orientation.Row, o = t?.allowUnorderedWrites ?? !1, s = r === F.Orientation.Column, i = this._isDataColumn, l = s !== i, c = this;
let h, d, u, g = l ? new zt.TransposedBuilder() : new zt.Builder(), m = null;
if (e) {
const C = e.getCoords(), y = C.colStart, E = C.rowStart, w = C.colEnd, b = C.rowEnd;
m = (v, I) => {
if (v < E || v > b || I < y || I > w) throw new Wt();
};
}
s ? (d = (C, y, E) => (m?.(C, y), g.addValue(y, C, E), h), u = (C, y, E) => (m?.(C, y + (E?.length ?? 0)), g.addValues(y, C, E), h)) : (d = (C, y, E) => (m?.(C, y), g.addValue(C, y, E), h), u = (C, y, E) => (m?.(C + (E?.length ?? 0), y), g.addValues(C, y, E), h));
const f = (C) => {
const y = g.build();
return y && c._updateTuples(y, C, null, n), e;
}, p = o !== !1 ? L.createCellComparator(t?.orientation) : null, _ = k.isObject(o) ? o : void 0;
let S = null;
return h = Object.freeze({ push: (C, y) => {
const E = c._cellToCoords(C);
return p && (S && p(E, S) <= 0 && (f(_), g = l ? new zt.TransposedBuilder() : new zt.Builder()), S = E), d(s ? E.colIndex : E.rowIndex, s ? E.rowIndex : E.colIndex, y);
}, pushAt: d, pushMultipleAt: u, apply: f }), h;
}
_updateTuples(t, e, n = void 0, r = null) {
if (!t) return;
const o = r?.isCell ?? !1, s = r?.isHyperlink ?? !1, i = t.tuples, l = t.bounds, c = this._beginCommit({ description: e?.description ?? "Update Cells" });
let h = null;
const d = this._isDataColumn, u = d ? F.Orientation.Column : F.Orientation.Row, g = this.getProtection().isLocked(), m = this.getProtection().isFormatCellsAllowed(), f = this._strings, p = l.majorStart, _ = l.majorEnd, S = l.minorStart, C = l.minorEnd, y = { colStart: d ? p : S, rowStart: d ? S : p, colEnd: d ? _ : C, rowEnd: d ? C : _ }, E = this;
(n = n ?? ((lt, nt) => {
E._validateCoords(lt, nt ?? Ri);
}))(y);
const w = { [ht.Type.Style]: !1, [ht.Type.Table]: !1 };
let b = !1;
g && this._hasRangedEntries("unlockSpatial", y) && (w[ht.Type.Unlock] = !1, b = !0), this._hasRangedEntries("mergeSpatial", y) && (w[ht.Type.Merge] = !1, b = !0);
const v = this._rangeStateIterator({ bounds: y, orientation: u, includeRangeTypes: w });
let I = v.next(), x = -1, R = -1, A = -1, M = -1, T = null;
if (!I.done) {
const lt = I.value, nt = lt.start, gt = lt.end;
x = d ? nt.colIndex : nt.rowIndex, R = d ? gt.colIndex : gt.rowIndex, A = d ? nt.rowIndex : nt.colIndex, M = d ? gt.rowIndex : gt.colIndex, T = lt.intersection;
}
let O = (lt, nt) => {
do {
if (!T || lt <= A && nt < A) return null;
if (lt >= x && nt >= A && lt <= R && nt <= M) return T;
if (I = v.next(), I.done) T = null, O = null, b = !1;
else {
const gt = I.value;
x = d ? gt.start.colIndex : gt.start.rowIndex, R = d ? gt.end.colIndex : gt.end.rowIndex, A = d ? gt.start.rowIndex : gt.start.colIndex, M = d ? gt.end.rowIndex : gt.end.colIndex, T = gt.intersection;
}
} while (T);
return T;
};
const W = c.getState(this), D = W.cellValuesGrid.clone(), z = W.calcGraph.clone(), B = W.formulaSpatial.clone(), H = W.spillSpatial.clone(), P = W.pendingSpatial.clone(), j = W.calcErrorsSpatial.clone(), G = W.contentfulSpatial.clone(), K = Yn(d), V = Yn(d, (lt, nt) => {
if (lt === nt) return nt;
}), $ = Yn(d, (lt, nt) => {
if (lt === nt) return nt;
}), J = Yn(d, (lt, nt) => {
if (lt === nt) return nt;
}), Z = [];
let q = null, Q = null;
if (e?.textParser !== !1) {
const lt = e && e.textParser !== !0 ? e.textParser : {};
Q = { ignoreQuotePrefix: !1, date1904: this._isDate1904, dateNF: !1, parse: null, ...lt }, q = new Ga(f, null, this._cellOptions);
}
const it = [], X = this._cellOptions, at = /* @__PURE__ */ new Map(), ut = zd, tt = (lt, nt, gt) => {
const St = O?.(nt, gt);
if (St?.merge) {
const _t = St.merge.getCoords(), Gt = d ? _t.colStart : _t.rowStart, ke = d ? _t.rowStart : _t.colStart;
if (Gt !== nt || ke !== gt) return;
}
if (o && lt && lt.isICell) {
const _t = lt;
if (_t.isTopLeft()) {
const Gt = _t.getSpans();
Z.push({ colStart: d ? nt : gt, rowStart: d ? gt : nt, colEnd: (d ? nt : gt) + Gt.width - 1, rowEnd: (d ? gt : nt) + Gt.height - 1 });
}
}
let wt = Pl(lt, X, Q, at);
if (wt === void 0) return;
const jt = wt.value;
if (wt.stringToParse) {
To[0].colIndex = d ? nt : gt, To[0].rowIndex = d ? gt : nt, To[1] = jt, To[2] = St, q.setState(To);
const _t = Q?.parse(wt.stringToParse, q.context), Gt = Pl(_t, X, Q, at, !0);
if (q.clear(), Gt === null) return Gt;
Gt !== void 0 && (wt = { ...Gt });
}
if (g) {
if (g && (lt === null || wt.value !== void 0)) throw new ot(bs);
if (!m && wt.style !== void 0) throw new ot(bs);
}
if (!s) {
const _t = wt.style;
_t === void 0 || _t === null && !o || V.append(nt, gt, _t);
const Gt = wt.hyperlink;
Gt === void 0 || Gt === null && !o || $.append(nt, gt, Gt);
}
const It = wt.formula;
return It === void 0 || It === null && !o || J.append(nt, gt, It), jt;
};
let rt = -1, ct = -1;
try {
const lt = i.length;
for (let Et = 0; Et < lt; Et++) {
const Ut = i[Et], Ce = Ut[0];
if (rt >= Ce) throw new zt.OutOfOrderError(`Duplicate or out of order major indices: {${Ce}}.`);
if (rt = Ce, ct = Number.MIN_SAFE_INTEGER, Ce < p || Ce > _) throw new Wt("Provided major bounds is invalid");
const Ht = Ut[1], Rt = [], Mt = Ht.length;
for (let kt = 0; kt < Mt; kt++) {
const Ot = Ht[kt], Pt = Ot[1], Tt = Pt.length;
let Zt = Ot[0], At = Zt;
if (ct > At) throw new zt.OutOfOrderError(`Duplicate or out of order minor indices: {${At}}.`);
if (At < S || At + Tt > C + 1) throw new Wt("Provided minor bounds is invalid");
let Jt = [];
for (let qt = 0; qt < Tt; qt++) {
const je = Pt[qt];
let un = null;
if (b || typeof je != "number" ? (b || je !== null || o) && (un = tt(je, Ce, At)) : un = je, un == null) {
if (un === null && K.append(Ce, At), Jt.length > 0) {
const so = ut(Jt, f);
Rt.push([Zt, so]), Jt = [];
}
Zt = At + 1;
} else Jt.push(un);
At++;
}
if (ct = At, Jt.length > 0) {
const qt = ut(Jt, f);
Rt.push([Zt, qt]), Jt = null;
}
}
Rt.length > 0 && it.push([Ce, Rt]);
}
const nt = K.done(), gt = nt.length;
for (let Et = 0; Et < gt; Et++) {
const Ut = nt[Et];
D.delete(nt[Et]), G.insertNonOverlapping({ ...Ut, value: null });
const Ce = z.delete(Ut);
this._updateFormulaSpatial(B, null, Ce);
}
let St;
it.length > 0 && (D.setValues(it), St = { tuples: it, bounds: l });
let wt, jt = J.done();
if (jt.length > 1 && (jt = an(jt, F.Orientation.Column, 1)), St || jt.length > 0) {
const Et = z.setInputs(St, jt);
wt = this._updateFormulaSpatial(B, Et.inserts, Et.removes, W.directStyleSpatial);
}
const It = Pd(it, d), _t = It.length;
for (let Et = 0; Et < _t; Et++) G.insertNonOverlapping(It[Et]);
const Gt = V.done();
Gt.length > 0 && this._updateStyles(Gt), Z.length > 0 && this._merge(Z);
const ke = $.done();
if (ke.length > 0 && this._setHyperlinks(ke), this._updateState({ cellValuesGrid: D, contentfulSpatial: G, calcGraph: z, formulaSpatial: B, spillSpatial: H, pendingSpatial: P, calcErrorsSpatial: j }), wt && wt.length > 0 && this._updateStyles(wt, void 0, {}, !0), e?.autoFit) {
const Et = typeof e.autoFit == "boolean" ? hl : e.autoFit;
this._autoFit([y], Et);
}
h = { ranges: [y] }, this._addEvent("data", y), this._commitAndAutoSelect(c, h, e?.autoSelect, { viewAfter: { formulas: [y], ranges: [y] } });
} catch (lt) {
throw c.rollback(), lt;
}
}
_sort(t, e) {
typeof e == "boolean" && (e = { reverse: e });
const n = e?.description ?? "Sort " + (e?.reverse ? "Descending" : "Ascending");
this._protectionCheck(() => ["sort"], t, n);
let r = 1, o = 1, s = !1;
const i = this._getMerges([t]);
if (i.length > 0) {
s = !0;
let V = i[0];
if (r = V.colEnd - V.colStart + 1, o = V.rowEnd - V.rowStart + 1, (t.colEnd - t.colStart + 1) % r != 0 || (t.rowEnd - t.rowStart + 1) % o != 0) throw new ot(md);
const $ = i.length;
for (let J = 1; J < $; J++) {
const Z = i[J];
if (Z.colEnd - Z.colStart + 1 !== r || Z.rowEnd - Z.rowStart + 1 !== o) throw new ot(md);
}
}
const l = e?.orientation ?? F.Orientation.Row, c = l === F.Orientation.Row;
let h = e?.offset ?? 0, d = t;
e?.hasHeader && (d = { ...d }, c ? d.rowStart += o : d.colStart += r, h = Math.max(h - 1, 0));
const u = { offset: h, reverse: e?.reverse ?? Gr.DefaultRangeOptions.reverse, collatorOptions: e?.collatorOptions ?? Gr.DefaultRangeOptions.collatorOptions }, g = c ? d.colStart : d.rowStart, m = c ? d.colEnd - d.colStart : d.rowEnd - d.rowStart, f = [], p = e?.fields;
if (p) {
const V = p.length ?? 0;
for (let $ = 0; $ < V; $++) {
let J = p[$];
typeof J == "number" && (J = { offset: J }), f.push(J);
}
} else f.push(u);
const _ = f.length;
for (let V = 0; V < _; V++) {
const $ = f[V] = { ...u, ...f[V] };
if ($.offset < 0 || $.offset > m) throw new Wt("The sort offset is outside of the bounds of the sort.");
$.offset += g;
}
const S = [];
let C = null, y = null, E = null, w = Number.MIN_SAFE_INTEGER;
f.sort((V, $) => V.offset - $.offset);
let b = null;
const v = e?.includeHidden ?? !1;
if (!v) {
const V = ja(c ? this._rowHeaders : this._colHeaders);
b = po(V);
}
const I = this._cellIterator({ bounds: d, orientation: l, ignoreHidden: !v && l, includeRangeTypes: { [ht.Type.Style]: !1, [ht.Type.Merge]: !1 } }), x = c ? o : r;
let R = (c ? d.rowStart : d.colStart) - x, A = I.next();
for (; !A.done; ) {
const V = A.value.context, $ = V.getCell();
if (s && !$.isTopLeft()) {
A = I.next();
continue;
}
const J = V.getCoords(), Z = c ? J.rowIndex : J.colIndex, q = c ? J.colIndex : J.rowIndex;
if (R !== Z) {
for (R += x, b && (R = b(R)); R < Z; ) S.push(null), R += x;
y = [], E = [], C = { minorIndex: Z, values: y, sortValues: E }, S.push(C), R = Z, w = f[0].offset;
}
for (; q > w; ) {
const Q = f[E.length];
w = Q ? Q.offset : Number.MAX_SAFE_INTEGER, q > w && E.push(null);
}
q === w && E.push($), y.push($), A = I.next();
}
if (!C || S.length === 0) return;
const M = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ new Map(), O = e?.collators ?? Gr.DefaultCollators, W = O.length;
for (let V = 0; V < W; V++) M.set(O[V].type, O[V].compare), T.set(O[V].type, V);
let D = null, z = null, B = null;
S.sort((V, $) => {
const J = f.length;
for (let Z = 0; Z < J; Z++) {
const q = f[Z], Q = V ? V.sortValues[Z] : null, it = $ ? $.sortValues[Z] : null, X = Q ? Q.getValue() : null, at = it ? it.getValue() : null, ut = X === null, tt = at === null;
if (X === at) continue;
if (ut && tt) return 0;
if (!ut && tt) return -1;
if (ut && !tt) return 1;
const rt = Q.getType(), ct = it.getType();
let lt = 0;
if (rt !== ct) {
let nt = T.get(rt);
lt = T.get(ct) - nt;
} else {
let nt = z;
if (D !== rt) {
nt = M.get(rt), z = nt, D = rt;
let gt = T.get(ct);
B = { ...O[gt].defaultOptions, ...q.collatorOptions };
}
lt = nt(X, at, B);
}
return q.reverse && (lt *= -1), lt;
}
return 0;
});
const H = this._beginCommit({ description: n });
let P = [d];
v || (P = this._getVisible(P, { orientations: c ? F.Orientations.Row : F.Orientations.Column })), this._clear(P, void 0, void 0, !0);
const j = this._createIncrementalUpdater({ orientation: l });
let G = c ? d.rowStart : d.colStart;
const K = S.length;
for (let V = 0; V < K; V++) {
const $ = S[V];
if (b && (G = b(G)), $) {
const J = $.values, Z = J.length;
for (let q = 0; q < Z; q++) {
const Q = J[q], it = c ? G : Q.getCoords().rowIndex, X = c ? Q.getCoords().colIndex : G;
j.pushAt(it, X, Q);
}
}
G += x;
}
return j.apply(), H.commit(), d;
}
_autoFill(t, e, n) {
const { direction: r, amount: o } = ((f, p) => {
let _ = F.Direction.Down, S = 0;
const C = { ...f };
if (p.colStart < f.colStart ? (_ = F.Direction.Left, S = f.colStart - p.colStart, C.colStart = p.colStart) : p.colEnd > f.colEnd ? (_ = F.Direction.Right, S = p.colEnd - f.colEnd, C.colEnd = p.colEnd) : p.rowStart < f.rowStart ? (_ = F.Direction.Up, S = f.rowStart - p.rowStart, C.rowStart = p.rowStart) : p.rowEnd > f.rowEnd && (_ = F.Direction.Down, S = p.rowEnd - f.rowEnd, C.rowEnd = p.rowEnd), !L.isEqualRanges(C, p)) throw new Error("Autofill destination must be the same as the range for 3 of the 4 edges.");
return { direction: _, amount: S };
})(t, e);
if (o <= 0) return !1;
const s = r === F.Direction.Up || r === F.Direction.Down, i = this.getSelection().getCoords(), l = [], c = n?.previewOnly, h = n?.contentsOnly, d = n?.filler ?? vi.Types.Series, u = { ...n?.fillerOptions };
let g = null, m = null;
try {
const f = { ...t };
let p = { ...t };
const _ = [t], S = this._getMerges(_);
if (S.length > 0 && !L.isRangeWithinRange(L.unionRangesArrays(S), t)) throw new ot(gd);
const C = { ...p };
let y = 1;
if (r === F.Direction.Left) f.colStart = p.colStart = t.colStart - o, f.colEnd = t.colStart - 1, y = S.length === 0 ? y : t.colEnd + 1 - t.colStart, C.rowStart = C.rowEnd;
else if (r === F.Direction.Right) f.colEnd = p.colEnd = t.colEnd + o, f.colStart = t.colEnd + 1, y = S.length === 0 ? y : t.colEnd + 1 - t.colStart, C.rowStart = C.rowEnd;
else if (r === F.Direction.Up) f.rowStart = p.rowStart = t.rowStart - o, f.rowEnd = t.rowStart - 1, y = S.length === 0 ? y : t.rowEnd + 1 - t.rowStart, C.colStart = C.colEnd;
else {
if (r !== F.Direction.Down) throw new ot(qm.MESSAGE_ERROR_INVALID_ARG(r));
f.rowEnd = p.rowEnd = t.rowEnd + o, f.rowStart = t.rowEnd + 1, y = S.length === 0 ? y : t.rowEnd + 1 - t.rowStart, C.colStart = C.colEnd;
}
if (o % y !== 0) throw new ot(((tt) => `When filling with merged cells the amount to fill must be a multiple of the input range [${tt}].`)(y));
const E = s ? "rowIndex" : "colIndex", w = s ? "colIndex" : "rowIndex", b = s ? t.rowEnd + 1 - t.rowStart : t.colEnd + 1 - t.colStart, v = s ? t.rowStart : t.colStart, I = s ? t.rowEnd : t.colEnd, x = s ? e.rowStart : e.colStart, R = s ? e.rowEnd : e.colEnd, A = s ? r === F.Direction.Down : r === F.Direction.Right;
A || (u.reverse = !0);
const M = A ? I + 1 : x, T = (A ? R : v - 1) - M + 1, O = s ? t.colEnd : t.rowEnd;
l.push(L.unionRanges(f, t));
const W = [];
let D = null;
c || (g = this._beginCommit({ description: "Auto Fill", operation: { name: "autoFill", params: [t, e, n] } }));
const z = this._cellIterator({ bounds: c ? C : t, reverse: !A, orientation: s ? F.Orientation.Column : F.Orientation.Row, includeRangeTypes: { [ht.Type.Style]: !1 } });
let B = z.next();
for (; !B.done; ) {
const tt = B.value.context, rt = tt.getCell(), ct = tt.getCoords();
D?.oppositeIndex !== ct[w] && (D = { oppositeIndex: ct[w], lastIndex: A ? v - 1 : I + 1, values: [] }, W.push(D));
const lt = ct[E];
if (A) for (let gt = D.lastIndex + 1; gt < lt; gt++) D.values.push(null);
else for (let gt = D.lastIndex - 1; gt > lt; gt--) D.values.push(null);
D.lastIndex = lt;
const nt = rt.toDate();
if (nt) D.values.push(nt);
else {
let gt = rt.getValue();
D.values.push(gt);
}
B = z.next();
}
const H = W.length;
for (let tt = 0; tt < H; tt++) {
const rt = W[tt].values;
for (let ct = rt.length; ct < b; ct++) rt.push(null);
}
const P = (tt, rt) => {
if (tt.canFill(rt[0], [])) {
const ct = tt.createFillAt(rt, u);
if (ct) return ct;
}
return vi.Types.Copy.createFillAt(rt);
}, j = this;
if (c) {
const tt = W[W.length - 1];
if (W[W.length - 1]?.oppositeIndex !== O) return null;
const rt = P(d, tt.values);
return c((ct) => {
const lt = j._rangeToCoords(ct);
let nt;
r === F.Direction.Down || r === F.Direction.Right ? nt = { rowIndex: lt.rowEnd, colIndex: lt.colEnd } : r === F.Direction.Left ? nt = { rowIndex: lt.rowEnd, colIndex: lt.colStart } : r === F.Direction.Up && (nt = { rowIndex: lt.rowStart, colIndex: lt.colEnd });
const gt = s ? nt.rowIndex : nt.colIndex, St = { value: rt(A ? gt - v : v - gt + b - 1) };
let wt = null;
return wt = h ? this.createTemporaryCell(St, nt) : this.createTemporaryCell(null, nt).createTemporaryCell(St), wt;
}), !1;
}
const G = this._createIncrementalUpdater({ orientation: s ? F.Orientation.Column : F.Orientation.Row }), K = W.length;
W.sort((tt, rt) => tt.oppositeIndex - rt.oppositeIndex);
for (let tt = 0; tt < K; tt++) {
const rt = tt, ct = P(d, W[rt].values), lt = W[rt].oppositeIndex, nt = A ? b : b + T - 1, gt = this.isDate1904();
for (let St = 0; St < T; St++) {
let wt = ct(nt + (A ? St : -St));
ro(wt) && (wt = rs(wt, gt));
const jt = M + St;
s ? G.pushAt(jt, lt, wt) : G.pushAt(lt, jt, wt);
}
}
this._clear([f], n?.contentsOnly ? Ft.Content.Formats : void 0), G.apply();
const V = this._getMerges([p]), $ = L.unionRangesArrays(V);
if (V.length > 0 && !L.isRangeWithinRange($, p)) throw new ot(gd);
if (V.length > 0) {
const tt = [], rt = o / y;
if (s) {
const ct = t.rowEnd - t.rowStart + 1, lt = r === F.Direction.Up ? f.rowStart : t.rowEnd + 1, nt = V.length;
for (let gt = 0; gt < nt; gt++) {
const St = V[gt], wt = St.rowStart - t.rowStart, jt = St.rowEnd - St.rowStart + 1;
for (let It = 0; It < rt; It++) {
const _t = It * ct;
tt.push({ colStart: St.colStart, rowStart: lt + _t + wt, colEnd: St.colEnd, rowEnd: lt + _t + wt + jt - 1 });
}
}
} else {
const ct = t.colEnd - t.colStart + 1, lt = r === F.Direction.Left ? f.colStart : t.colEnd + 1, nt = V.length;
for (let gt = 0; gt < nt; gt++) {
const St = V[gt], wt = St.colStart - t.colStart, jt = St.colEnd - St.colStart + 1;
for (let It = 0; It < rt; It++) {
const _t = It * ct;
tt.push({ colStart: lt + _t + wt, rowStart: St.rowStart, colEnd: lt + _t + wt + jt - 1, rowEnd: St.rowEnd });
}
}
}
this._merge(tt);
}
const J = this._getState(), Z = {}, q = {};
q.directStyleSpatial = J.directStyleSpatial, q.continuousFillSpatial = J.continuousFillSpatial;
let Q = t, it = f;
if (!A) {
let tt = (s ? p.rowEnd + 1 - p.rowStart : p.colEnd + 1 - p.colStart) % b;
const rt = s ? "rowStart" : "colStart", ct = s ? "rowEnd" : "colEnd";
tt !== 0 && (it = { ...f, [ct]: Math.min(f[ct], f[rt] + tt) }, Q = { ...t, [rt]: t[ct] - tt + 1 }, f[rt] = f[rt] + tt);
}
const X = Object.keys(q), at = X.length;
for (let tt = 0; tt < at; tt++) {
const rt = X[tt], ct = q[rt].createCopiedEntries(Q, it), lt = J[rt].clone(), nt = ct.removes, gt = nt.length;
for (let St = 0; St < gt; St++) lt.remove(nt[St]);
lt.load(ct.inserts), Z[rt] = lt;
}
if (A) {
const tt = this.getTables().getItems({ address: { rowIndex: t.rowEnd, colIndex: t.colEnd } });
if (tt.length === 1) {
const rt = tt[0], ct = rt.getRange().getCoords();
rt.resize({ colStart: ct.colStart, rowStart: ct.rowStart, colEnd: s ? ct.colEnd : f.colEnd, rowEnd: s ? f.rowEnd : ct.rowEnd });
}
}
const ut = J.calcGraph.clone();
ut.autoFill(t, f), Z.calcGraph = ut, this._updateState(Z), m = { ...i, ranges: l }, g.commit({ viewBefore: { view: this.getView(), selection: Bt([t]), 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(t, e, n) {
const r = n?.description ?? "Set Hyperlink";
this._protectionCheck(() => ["insertHyperlinks", "formatCells"], t, r);
const o = Bt(t), s = this._beginCommit({ description: r });
let i = null;
try {
const l = this._getState();
if (!l) return k.EmptyArray;
const c = l.hyperlinkSpatial;
let h = c, d = l.directStyleSpatial.clone();
const u = t.length;
for (let g = 0; g < u; g++) {
const m = t[g];
let f = null;
const p = m.value, _ = p !== void 0 ? p : e;
let S;
if (_ !== null) {
if (_.isIHyperlink) S = { ..._._p }, f = _.getDisplayText();
else if (typeof _ == "string") S = { address: _ }, f = _;
else if (_.address || _.displayText) {
const C = _, y = { ...C };
delete y.displayText, S = y, f = C.displayText ?? C.address;
}
} else S = null;
if (i = L.unionRanges(i, m), c === h && (h = c.clone()), S !== null || c.size() > 0) {
if (f && e) {
const C = this._createIncrementalUpdater({ orientation: F.Orientation.Column }, void 0, { isHyperlink: !0 });
for (let y = m.colStart; y <= m.colEnd; y++) for (let E = m.rowStart; E <= m.rowEnd; E++) C.pushAt(E, y, f);
C.apply();
}
if (S === null) this._getRangedEntries("hyperlinkSpatial", [m], { onEntry: (C, y) => (h.insertNonOverlapping({ ...y, value: S }), y.value) });
else {
h.insertNonOverlapping({ ...m, value: S });
const C = this._styles, y = (E) => {
const w = E.value ?? new oe(C, L.sanitizeRange(E));
let b = { ...w.getPropertiesAt(0, 0, null) };
if (b.named) {
const v = C.getNamed(b.named)?.getRanged().getPropertiesAt(0, 0, null);
b = k.mergeContentful(v, b);
}
return delete b.font, b.named = mt.BuiltInName.Hyperlink, { ...E, value: w.cloneWithUpdate(b) };
};
d.insertNonOverlapping({ ...m, value: null }, { onIntersect: y });
}
}
}
this._lastUsedCoordsRead.coords = null, this._updateState({ hyperlinkSpatial: h, directStyleSpatial: d }), this._commitAndAutoSelect(s, o, n?.autoSelect, { viewAfter: { ranges: t } });
} catch (l) {
throw s.rollback(), l;
}
}
_updateFormulaSpatial(t, e, n, r) {
if (n) {
const s = n.length;
for (let i = 0; i < s; i++) {
const l = n[i];
t.remove(l);
}
}
let o;
if (e) {
const s = [], i = e.length;
for (let l = 0; l < i; l++) {
const c = e[l], h = L.sanitizeRange(c), d = new Gw(h, c.value.tokens, c.value.references);
if (s.push({ colStart: h.colStart, rowStart: h.rowStart, colEnd: h.colEnd, rowEnd: h.rowEnd, value: d }), !r) continue;
const u = c.value.precedents;
let g, m, f = !1;
const p = u.length;
for (let _ = 0; !f && _ < p; _++) {
const S = u[_], C = S.colStart;
if (S.colStart === void 0) continue;
const y = S.rowStart;
qe.colStart = C, qe.rowStart = y, qe.colEnd = C, qe.rowEnd = y;
const E = r.search(qe)[0];
if (E) {
const w = E.value.getPropertiesAt(y, C, null), b = w?.numberFormat;
if (b) if (g) {
m || (m = Ne.Styles.lookupStyle(g)?.formatType);
const v = Ne.Styles.lookupStyle(b)?.formatType;
_p(v, m) > 0 ? (m = v, 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 } }));
}
t.load(s);
}
return o;
}
_realizeCalcedValues(t) {
if (!t) return;
const e = this._getState();
if (!e) return;
const n = t.valueInserts, r = t.spillRemoves, o = t.errorRemoves, s = e.cellValuesGrid, i = this._beginCommit();
t.isFull && (e.calcErrorsSpatial.clear(), e.spillSpatial.clear(), e.pendingSpatial.clear());
const l = t.valueRemoves;
if (l) {
const m = e.contentfulSpatial, f = l.length;
for (let p = 0; p < f; p++) {
const _ = l[p];
s.delete(_), m.insertNonOverlapping({ ..._, value: null });
}
}
if (r) {
const m = e.spillSpatial, f = r.length;
for (let p = 0; p < f; p++) {
const _ = r[p];
m.remove(_);
}
}
if (o) {
const m = e.calcErrorsSpatial, f = o.length;
for (let p = 0; p < f; p++) {
const _ = o[p];
m.remove(_);
}
}
this._updateFormulaSpatial(e.formulaSpatial, t.formulaInserts, t.formulaRemoves);
const c = t.formatInserts;
if (c) {
const m = c.length;
for (let f = 0; f < m; f++) {
const p = c[f], _ = { numberFormat: p.value };
p.value = _;
}
this._updateStyles(c, void 0, { autoFit: !0 }, !0);
}
if (n) {
const m = n.tuples;
s.setValues(m);
const f = this._isDataColumn, p = f ? F.Orientation.Column : F.Orientation.Row, _ = e.contentfulSpatial, S = m.length;
for (let C = 0; C < S; C++) {
const y = m[C], E = y[0], w = y[1], b = w.length;
for (let v = 0; v < b; v++) {
const I = w[v], x = I[0], R = x + I[1].length - 1, A = { colStart: f ? E : x, rowStart: f ? x : E, colEnd: f ? E : R, rowEnd: f ? R : E };
_.insertNonOverlapping({ colStart: A.colStart, rowStart: A.rowStart, colEnd: A.colEnd, rowEnd: A.rowEnd, value: new Ye(A, p) });
}
}
}
const h = t.spillInserts;
if (h) {
const m = h.length;
for (let f = 0; f < m; f++) {
const p = h[f], _ = p.value;
p.value = new _r(L.sanitizeRange(p), 0, _);
}
e.spillSpatial.load(h);
}
const d = t.pendingUpdates;
if (d) {
const m = e.pendingSpatial, f = d.length;
for (let p = 0; p < f; p++) {
const _ = d[p];
_.value === !1 && (_.value = null), m.insertNonOverlapping(_);
}
}
const u = t.errorInserts;
u && e.calcErrorsSpatial.load(u);
const g = t.formulaInserts;
if (g) {
const m = an(g);
this._autoFit(m, hl);
}
if (i.commit({ forceAmend: !0, viewAfter: { calculationSideEffect: !0 } }), (t.bounds || t.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, [t.bounds ?? this._entireCoords], f);
}
(h || r) && this._emitter.notify("onSpillsChange");
}
}
_calculate(t, e) {
const n = this._getState().calcGraph;
n.invalidate(t), n.calculate(e);
}
_calculateFull() {
this._initializing || k.debounce(() => {
this._getState()?.calcGraph.calculate({ full: !0 });
}, 100)();
}
_setComments(t, e, n) {
const r = n?.description ?? "Set Comments", o = Bt(t), s = this._beginCommit({ description: r });
let i = null;
try {
const l = this._getState();
if (!l) return k.EmptyArray;
const c = l.commentsSpatial;
let h = c;
const d = t.length;
for (let u = 0; u < d; u++) {
const g = t[u];
let m = null;
if (e !== null) {
let f = e;
if (!f) continue;
m = typeof f == "string" ? { content: { runs: { text: f } } } : { ...f };
}
i = L.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: t } });
} catch (l) {
throw s.rollback(), l;
}
}
_clear(t, e = null, n, r = !1, o = !1) {
let s = null, i = "Clear", l = !1, c = !1, h = !1, d = !1;
e === Ft.Content.Formulas ? (i = `${i} Formulas`, d = !0) : e === Ft.Content.Values ? (i = `${i} Values`, d = !0) : e === Ft.Content.Formats ? (i = `${i} Formats`, l = !0, s = ["formatCells"]) : e === Ft.Content.Comments ? (i = `${i} Comments`, h = !0) : e === Ft.Content.Hyperlinks ? (i = `${i} Hyperlinks`, c = !0, s = ["formatCells"]) : (s = [], i = `${i} All`, d = !0, l = !0, c = !0, h = !0), s !== null && this._protectionCheck(() => s, t, n?.description ?? i);
const u = Bt(t), g = this._beginCommit({ description: n?.description ?? i });
let m = this._getState(), f = m.cellValuesGrid, p = m.calcGraph, _ = m.contentfulSpatial, S = m.formulaSpatial, C = m.spillSpatial, y = m.pendingSpatial, E = m.calcErrorsSpatial, w = m.rangesListenerSpatial2;
d && (f = f.clone(), p = p.clone(), _ = _.clone(), S = S.clone(), C = C.clone(), y = y.clone(), E = E.clone());
try {
if (c && this._setHyperlinks(t, null), h && this._setComments(t, null), l && (this._updateStyles(t, null), r || this._unmerge(t)), l || d) {
fi(0, t, [], _, C, f);
const b = t.length;
for (let v = 0; v < b; v++) {
const I = t[v];
if (d) {
f.delete(I);
const A = { ...I, value: null };
_.insertNonOverlapping(A);
const M = p.delete(I);
this._updateFormulaSpatial(S, null, M);
}
const x = this.getTables().getItems({ address: I }), R = x.length;
for (let A = 0; A < R; A++) {
const M = x[A];
L.isRangeWithinRange(M.getAnchorCoords(), I) && (e === Ft.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 O = A[T];
L.isRangeWithinRange(O, I) && (w === m.rangesListenerSpatial2 && (w = w.clone()), console.log("cut and move listener"), w.remove(O));
}
}
}
}
this._updateState({ cellValuesGrid: f, calcGraph: p, contentfulSpatial: _, formulaSpatial: S, spillSpatial: C, pendingSpatial: y, calcErrorsSpatial: E, rangesListenerSpatial2: w }), this._commitAndAutoSelect(g, u, n?.autoSelect, { viewAfter: { ranges: t } });
} catch (b) {
throw g.rollback(), b;
}
}
_merge(t, e = null) {
if (this._protectionCheck(Tu, t), t.length === 1 && L.isSingleCell(t[0])) return;
let n = F.Orientations.Both;
e?.orientations ? n = e?.orientations : e === F.Orientations.Row ? n = F.Orientations.Row : e === F.Orientations.Column && (n = F.Orientations.Column);
const r = e?.discardMultipleValues ?? !1;
let o = Bt(t);
const s = this.getSelection().getCoords();
let i = null;
const l = this._beginCommit({ description: e?.description ?? "Merge" });
let c = t[0];
try {
const h = this._getMerges(t);
if (jo(t) || h.length > 0) {
const m = L.unionRangesArrays(h), f = L.unionRangesArrays(t);
if (!(!m && !f || m && f && L.isRangeWithinRange(m, f))) throw console.warn(ud, t), new ot(ud);
this._unmerge(h);
}
const d = this._createIncrementalUpdater({ orientation: F.Orientation.Column }), u = [], g = [];
try {
const m = this._entireCoords, f = this._getState().contentfulSpatial, p = this._getState().directStyleSpatial;
let _ = !1;
const S = (E) => {
const w = { rowIndex: E.rowStart, colIndex: E.colStart };
let b = null;
if (_) {
let W = 0;
const D = f.search(E), z = D.length;
for (let B = 0; B < z; B++) {
const H = L.intersectRanges(D[B], E);
if (H && (W += (H.rowEnd - H.rowStart + 1) * (H.colEnd - H.colStart + 1)), W > 1) throw new pc("Merging cells would cause some values to be discarded. Use 'discardMultipleValues' option if desired.", "discardMultipleValues");
}
}
b || (b = w);
let v = null, I = null, x = null, R = null, A = null, M = null, T = null;
ce.colStart = E.colStart, ce.rowStart = E.rowStart, ce.colEnd = E.colStart, ce.rowEnd = E.rowStart;
let O = p.search(ce);
if (O.length > 0) {
T = O[0].value?.getPropertiesAt(E.rowStart, E.colEnd, null);
const D = T?.border;
v = D?.left ?? null, I = D?.top ?? null, A = D?.right ?? null, M = D?.bottom ?? null;
}
if (ce.colStart = E.colEnd, ce.colEnd = E.colEnd, O = p.search(ce), O.length > 0) {
const W = O[0], D = W.value?.getPropertiesAt(E.rowStart, E.colEnd, null)?.border;
D && D.right && (x = D.right);
}
if (ce.colStart = E.colStart, ce.colEnd = E.colStart, ce.rowStart = E.rowEnd, ce.rowEnd = E.rowEnd, O = p.search(ce), O.length > 0) {
const W = O[0], D = W.value?.getPropertiesAt(E.rowEnd, E.colStart, null)?.border;
D && D.bottom && (R = D.bottom);
}
if (!x || !R) {
ce.colStart = E.colEnd, ce.colEnd = E.colEnd, ce.rowStart = E.rowEnd, ce.rowEnd = E.rowEnd, O = p.search(ce);
const W = O?.[0];
if (W) {
const D = W.value?.getPropertiesAt(E.rowEnd, E.colEnd, null)?.border;
D && (x || (x = D.right ?? null), R || (R = D.bottom ?? null));
}
}
u.push({ ...E, value: null }), u.push({ ...E, value: { ...T, border: { top: I, left: v, right: x ?? A, bottom: R ?? M, horizontal: null, vertical: null } } }), L.isEqualCells(b, w) || d.pushAt(b.rowIndex, b.colIndex, null), g.push(E), c = L.unionRanges(c, E);
}, C = [...t].sort(L.createRangeComparator(F.Orientation.Column)), y = C.length;
for (let E = 0; E < y; E++) {
const w = C[E];
if (!L.isSingleCell(w)) {
if (i || !s || !L.isCellWithinRange(s.cell, w) || s.cell.rowIndex === w.rowStart && s.cell.colIndex === w.colStart || (i = { ...o, cell: { rowIndex: w.rowStart, colIndex: w.colStart } }), !r && (_ = 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 ot("We can't merge outside of the maximum cell location.");
if (n === F.Orientations.Column) {
const b = w.rowEnd !== m.rowEnd ? w.rowEnd : Math.max(1, m.rowEnd);
for (let v = w.rowStart; v <= b; v++) S({ ...w, rowStart: v, rowEnd: v });
} else if (n === F.Orientations.Row) {
const b = w.colEnd !== m.colEnd ? w.colEnd : Math.max(1, m.colEnd);
for (let v = w.colStart; v <= b; v++) S({ ...w, colStart: v, colEnd: v });
} else S(w);
}
}
d.apply(), this._indexMerges(g), this._updateStyles(u), this._updateState({});
} catch (m) {
throw m.type ? new pc(m.message ?? "Unable to merge", m.type) : new ot(m.message ?? "Unable to merge");
}
i && (o = i, this.getSelection().updateCoords(i)), l.commit({ viewAfter: { view: this.getView(), selection: o, merges: t, ranges: t, selectOptions: e?.autoSelect } }), this._autoSelect(e?.autoSelect ?? !1, o);
} catch (h) {
throw l.rollback(), h;
}
}
_unmerge(t, e) {
if (this._protectionCheck(Tu, t), jo(t)) throw new ot("We can't unmerge intersecting ranges.");
if (!this._getState()) return null;
const n = L.unionRangesArrays(t), r = Bt(t), o = this._beginCommit({ description: e?.description ?? "Unmerge" }), s = o.getState(this).mergeSpatial, i = [];
try {
const l = t.length;
for (let c = 0; c < l; c++) {
const h = t[c], d = s.search(h), u = d.length;
for (let g = 0; g < u; g++) {
const m = d[g];
if (!L.isSingleCell(h) && !L.isRangeWithinRange(m, n)) throw new ot("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, e?.autoSelect, { viewAfter: { merges: t, ranges: t } });
} catch (l) {
throw o.rollback(), l;
}
}
_getMerges(t, e = !1) {
return t.length === 0 ? k.EmptyArray : this._getRangedEntries("mergeSpatial", t, { ignoreHidden: e, fullyContained: !1, onEntry: (n) => n.getCoords() });
}
_clone() {
const t = { ...this._options, container: null };
this._ownStyles && (t.styles = this._styles), this._ownStrings && (t.strings = this._strings), this._ownResources && (t.resources = this._resources), this._ownNames && (t.names = this._names), this._ownsCalculation && (t.calculation = this._calculation), t.transactions = new Ze({ transient: !0 });
const e = new ns(t), n = this._transactions.getState(this);
e._updateState(n);
const r = new cl({ sheet: this, json: this.getView().toJSON() });
return r.selectMovables(this.getView().getMovableSelection()), e.setView(r), e;
}
_getSnapshot(t, e) {
if (t.length === 0) return k.EmptyArray;
const n = this._getState();
if (!n) return null;
e = Object.freeze({ ...e });
const r = this._clone();
r.isMarked = !0;
const o = this, s = o.getView(), i = "Range", l = [], c = ((_, S, C, y) => {
const E = [];
let w = null, b = null;
const v = C && C.length > 0;
if (v) {
const x = C.length;
for (let R = 0; R < x; R++) {
const A = C[R].getSnapshot?.(y);
A && (E.push(A), w = _l(A.getCoords(), w));
}
} else if (S) {
const x = S.length;
for (let R = 0; R < x; R++) {
const A = S[R], M = _.getMovables().getItems({ ignoreHidden: !1, fullyContained: !0, address: A }), T = M.length;
for (let O = 0; O < T; O++) {
const W = M[O].getSnapshot?.(y);
W && (E.push(W), w = _l(_.getRange(A).getBounds(), w), b = L.unionRanges(b, A));
}
}
}
if (E.length === 0) return null;
const I = () => y.description ?? (E?.length === 1 ? Qr(E[0]?.getName()) : "Drawings");
return { copyTo: async (x, R) => {
const A = { ...y, ...R }, M = x.getSheet(), T = M.getView(), O = T.getMovableSelection(), W = x.getCoords(), D = A?.isCut ?? !1, z = T.getMovableSelection();
T.selectMovables([]);
const B = M.beginCommit(A.description ?? `${D ? "Cut" : "Copy"} ${I()}`);
try {
let H = 0, P = 0;
if (z.length > 0 && E.length > 0) {
let K = Number.MAX_SAFE_INTEGER, V = Number.MAX_SAFE_INTEGER;
for (let X = 0; X < O.length; X++) {
const at = O[X].getBounds();
K = Math.min(at.x, K), V = Math.min(at.y, V);
}
let $ = Number.MAX_SAFE_INTEGER, J = Number.MAX_SAFE_INTEGER;
const Z = E.length;
for (let X = 0; X < Z; X++) {
const at = E[X].getCoords();
$ = Math.min(at.x, $), J = Math.min(at.y, J);
}
H = K - $, P = V - J;
const q = E[0].getCoords(), Q = { ...q, x: q.x + H, y: q.y + P }, it = fu(M.getMovables(), Q);
H += it.x, P += it.y;
} else if (w) {
const K = M.getRange(W).getBounds();
H = K.x - w.x, P = K.y - w.y;
}
const j = [], G = E.length;
for (let K = 0; K < G; K++) {
const V = E[K], $ = V.getCoords(), J = { ...$, x: $.x + H, y: $.y + P };
j.push(V.copyTo({ movables: M.getMovables(), bounds: J }, { autoSelect: { addToSelection: !0 }, ...A }));
}
await Promise.all(j), B?.updateState(M, (K) => K), B.commit({ viewBefore: (K) => ({ ...K, view: _.getView(), movableSelection: z }) });
} catch (H) {
throw B.rollback(), H;
}
return null;
}, getName: I, getCoords: () => b, getMarkOptions: () => y, toText: () => v ? E[0].toText?.() ?? null : null, toHtml: () => v ? E[0].toHtml?.() ?? null : null, toImage: () => v ? E[0].toImage?.() ?? null : null, getSource: () => _, isISnapshot: !0 };
})(r, t, s.getMovableSelection(), e);
if (c) {
if (s.getMovableSelection().length > 0) return c;
l.push(c);
}
if (t.length > 1) throw new ot(_d);
const h = { singleMerge: null };
l.push({ copyTo(_, S) {
const C = { ...e, ...S };
let y = null;
if (!C.skipBlanks) {
const w = _.getSheet(), b = _.getCoords(), v = b;
y = w.getRange(v);
let I = !1;
const x = y.getMerges();
if (x.length === 1 && L.isEqualRanges(x[0], b)) if (L.isSingleCell(t[0])) I = !0;
else {
const R = (E = p) ? { colIndex: E.colStart, rowIndex: E.rowStart } : null;
r._getMerges([L.cellToRange(R)]).length === 1 && (I = !0);
}
return I ? (h.singleMerge = b, y.clear(C.type ?? Ft.Content.Values)) : y.clear(C.type), v;
}
var E;
} });
const d = r._entireCoords, u = t.length;
for (let _ = 0; _ < u; _++) {
const S = t[_], C = n.rangeListenerSpatial.search(S, !1), y = n.rangesListenerMap;
l.push({ async copyTo(E, w) {
if (!w.isCut) return;
const b = /* @__PURE__ */ new Set(), v = C.length;
for (let I = 0; I < v; I++) {
const x = C[I].value, R = x.id;
if (b.has(R)) continue;
const A = y.get(R);
if (b.add(R), A.ranges[x.offset] === null) return;
const M = { isTransactional: !0, isDataChange: !1, trigger: "moveCells", from: r.getRanges(t), to: E }, T = r._createRangeEvent(A.ranges, M);
r._notifyRangeListener2(A, T, M);
}
return null;
}, getMarkOptions: () => e, getCoords: () => null, isISnapshot: !0 });
}
const g = { ignoreHidden: !1, fullyContained: !0, onEntry: (_) => _.model };
for (let _ = 0; _ < u; _++) {
const S = t[_], C = r._getRangedEntries("tableSpatial", [S], g), y = C.length;
for (let E = 0; E < y; E++) {
const w = C[E], b = w.getAnchorCoords(), v = b.colStart - S.colStart, I = b.rowStart - S.rowStart, x = w.getSnapshot(e);
l.push({ async copyTo(R, A) {
const M = R.getSheet(), T = R.getCoords();
if (r.getProtection().isLocked()) return;
const O = { colStart: T.colStart + v, rowStart: T.rowStart + I, colEnd: T.colEnd + v, rowEnd: T.rowEnd + I };
return x.copyTo({ tables: M.getTables(), range: O }, A);
} });
}
}
for (let _ = 0; _ < u; _++) {
const S = t[_];
l.push(_u(o.getColumnHeaders().getRange(S), S, Object.freeze({ ...e, includeHeaders: S.rowStart <= d.rowStart && S.rowEnd >= d.rowEnd })));
}
for (let _ = 0; _ < u; _++) {
const S = t[_];
l.push(_u(o.getRowHeaders().getRange(S), S, Object.freeze({ ...e, includeHeaders: S.colStart <= d.colStart && S.colEnd >= d.colEnd })));
}
const m = Pw(o, r, t, i, e, (_, S) => r._copyRange(o, r, t, _, S, h));
l.push(m);
const f = r._getState().calcGraph.getSnapshot({ range: t[0] });
l.push({ async copyTo(_, S) {
const C = _.getSheet(), y = _.getCoords();
if (r.getProtection().isLocked()) return;
const E = C._getState().calcGraph;
return f.copyTo({ calcGraph: E, range: y }, S);
} });
const p = t[0];
return /* @__PURE__ */ ((_, S, C, y, E, w, b = null) => ({ async copyTo(v, I) {
let x = null;
const R = { ...E, ...I }, A = C.beginCommit(R.description ?? w);
try {
const M = _.length;
for (let T = 0; T < M; T++) {
const O = await _[T].copyTo(v, R);
O && (x = L.unionRanges(x, O));
}
A.commit();
} catch (M) {
throw A.rollback(), M;
}
return x;
}, getMarkOptions: () => E, getName: () => w, getSource: () => S, getCoords: () => y, toText() {
let v = b?.toText?.() ?? null;
const I = _.length;
for (let x = 0; !v && x < I; x++) v = _?.[x].toText?.();
return v ?? null;
}, toHtml() {
let v = b?.toHtml?.() ?? null;
const I = _.length;
for (let x = 0; !v && x < I; x++) v = _?.[x].toHtml?.();
return v ?? null;
}, toImage() {
let v = b?.toImage?.() ?? null;
const I = _.length;
for (let x = 0; !v && x < I; x++) v = _?.[x].toImage?.();
return v ?? null;
}, isISnapshot: !0 }))(l, o, r, p, e, i, m);
}
async _copyRange(t, e, n, r, o, s) {
if (n.length > 1) throw new ot("Only a single selection is supported when using 'Insert Copy'.");
if (!n || n.length === 0) throw new ot("The source has no range.");
const i = r.getSheet();
let l = r.getCoords(), c = { ...n[0] };
const h = (o = { ...o }).isCut;
let d = !o.type || o.type === Ft.Content.Formats, u = !o.type || o.type === Ft.Content.Values, g = !o.type || o.type === Ft.Content.Formats || o.type === Ft.Content.Hyperlinks;
const m = i.getEntireRange(), f = m.getCoords(), p = [], _ = [], S = [];
let C = [], y = [];
const E = (o.fitDestination ?? !1) && !L.isSingleCell(l), w = l;
if (E && (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) }), !L.isRangeWithinRange(w, f)) throw console.warn(w, f), new ot("We can't paste outside of the sheet bounds.");
let b = null;
b = o.undoRange ? { view: i.getView(), selection: Bt([o.undoRange.getCoords()]) } : { sheet: i, selection: Bt([w]) };
const v = i.getTransactions().beginCommit({ description: o.description ?? "Paste" });
try {
if (!this._getState()) return k.EmptyArray;
const I = /* @__PURE__ */ new Set(), x = o.transpose;
let R = !((x || o.adjustCells) && d) && I.size === 1;
if (R) {
const V = I.values().next();
R = L.isRangeWithinRange(c, V.value.getCoords()) && !$o(c, V.value.getCoords());
}
R && (R = i.getTables().getItems({ address: w }).length === 0), x && (R = !0), s.singleMerge && (d = !1, g = !1);
const A = l.colStart - c.colStart, M = l.rowStart - c.rowStart, T = o.adjustCells;
let O = { ...n_ };
if (delete O[ht.Type.Style], !d) {
const V = this.getProtection().isLocked();
O = {}, V && (O[ht.Type.Unlock] = !1);
}
const W = F.Orientation.Column;
let D;
if (u) {
D = m.startIncrementalUpdates({ orientation: o.transpose ? F.Orientation.Row : F.Orientation.Column });
const V = { orientation: W, includeRangeTypes: O, bounds: c }, $ = new Ga(this._strings, V, this._cellOptions), J = (it, X, at) => {
const ut = it[0], tt = $.setState(it), rt = $.context, ct = rt.getCell(), lt = ct.isTopLeft();
let nt = M, gt = A;
if (x) {
const It = ut.colIndex - c.colStart, _t = ut.rowIndex - c.rowStart;
nt = It + at + l.rowStart, gt = _t + X + l.colStart;
} else nt = M + ut.rowIndex + X, gt = A + ut.colIndex + at;
let St = !1;
const wt = { value: void 0, style: void 0, hyperlink: void 0 };
if (u && (wt.value = tt, St = !0), d) {
const It = it[2];
It && (It.directStyle || It.table) && (wt.style = ct.getStyle(!R), St = !0);
}
g && (wt.hyperlink = ct.getHyperlink(), St = !0);
let jt = wt;
if (T && lt) {
const It = T(tt, rt, { rowIndex: nt, colIndex: gt }, o);
It !== void 0 && (jt = It, St = !0);
}
if (St && (D.pushAt(nt, gt, jt), d)) {
const It = ct.getSpans();
(It.width > 1 || It.height > 1) && lt && p.push({ colStart: gt, rowStart: nt, colEnd: gt + (o.transpose ? It.height : It.width) - 1, rowEnd: nt + (o.transpose ? It.width : It.height) - 1 });
}
}, Z = this._cellStateIterator(V);
let q = { next() {
const it = Z.next();
if (it.done) return Lt;
const X = it.value[0];
let at;
return it.value && (at = [X, it.value]), { done: it.done, value: at };
} };
if (!s.singleMerge && !L.isEqualRanges(w, c)) {
const it = w.colEnd - w.colStart + 1, X = w.rowEnd - w.rowStart + 1;
q = new Ml({ delegate: q, bounds: c, orientation: W, dims: { major: o.transpose ? X : it, minor: o.transpose ? it : X } });
}
let Q = q.next();
for (; !Q.done; ) {
const it = Q.value, X = it[1], at = it[0], ut = X[0];
J(X, at.rowIndex - ut.rowIndex, at.colIndex - ut.colIndex), Q = q.next();
}
}
const z = e._getState(), B = {}, H = { transpose: x ?? !1 };
d && (B.directStyleSpatial = z.directStyleSpatial, B.continuousFillSpatial = z.continuousFillSpatial, B.mergeSpatial = z.mergeSpatial), h && (t._clear([c], void 0, void 0, !1, !0), C.push(c), B.rangesListenerSpatial2 = z.rangesListenerSpatial2);
const P = i, j = P._getState(), G = Object.keys(B), K = G.length;
for (let V = 0; V < K; V++) {
const $ = G[V], J = B[$].createCopiedEntries(c, w, H), Z = j[$].clone(), q = J.removes, Q = q.length;
for (let it = 0; it < Q; it++) Z.remove(q[it]);
Z.load(J.inserts), j[$] = Z;
}
P._updateState(j), C.push(w), y.push(w), _ && _.length > 0 && P._colHeaders.updateHeaderPairs(_), S && S.length > 0 && P._rowHeaders.updateHeaderPairs(S), D?.apply(), p.length > 0 && i.getRanges(p).merge(), v.commit({ viewBefore: b, viewAfter: (V) => ({ ...V, view: i.getView(), selection: Bt(y), ranges: C }) });
} catch (I) {
throw console.warn(I), v.rollback(), new Error(((x) => `Unable to paste: ${x}`)(I.message), { cause: I });
}
return L.unionRangesArrays(y);
}
_snapShotFromSource(t, e) {
if (t.isISnapshot) return t;
const n = t;
let r = null;
if (n?.isICellRanges) throw new ot(_d);
if (r = n?.isICellRange ? n : this.getRange(n), r.isICellRange) {
const o = r;
if (o.isInvalid()) throw new ot(Sd);
return o.getSnapshot(e);
}
throw new ot(Sd);
}
async _copyFrom(t, e, n) {
if (!e) throw new ot("Both a source and a destination are required to copy.");
const r = this._snapShotFromSource(e), o = "Paste", s = this._beginCommit({ description: n?.description ?? o });
let i = null;
try {
const l = Nl(t, r.getCoords(), n?.fitDestination, n?.transpose), c = this.getRange(l);
i = await r.copyTo(c, n);
const h = r.getName(), d = [i];
n?.isCut && d.push(r.getCoords()), s.commit({ description: h ? n?.description ?? `${o} ${h}` : o, viewAfter: { view: this.getView(), selection: Bt([i ?? l]), ranges: d } });
} catch (l) {
throw s.rollback(), l;
}
return i;
}
_createFilter(t, e, n) {
const r = this;
return new Tm({ initialAnchor: t, maxRangeCoords: this._entireCoords, json: e, 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(t) {
const e = this._rangeToCoords(t, () => ["autoFilter"]);
let n = this.getFilter();
if (n) return n;
n = this._createFilter(e);
const r = Bt([e]), o = this._beginCommit({ description: "Insert Filter" });
return this._updateState({ filter: n }), o.commit({ viewAfter: { ranges: [e], view: this.getView(), selection: r, selectOptions: void 0 } }), n;
}
getFilter() {
return this._getState()?.filter ?? null;
}
insertSort(t) {
return this._rangeToCoords(t, () => ["sort"]), null;
}
getSort() {
return null;
}
_getDefaultShiftOrientation(t) {
return WS(t, this._entireCoords);
}
_getDefaultSortCriteria(t, e, n) {
return Bd(this, t, n ? this._cellToCoords(n) : null, e);
}
async _insertFrom(t, e, n) {
if (!e) throw new Qe();
const r = this._snapShotFromSource(e), o = r.getCoords();
let s = Nl(t[0], o, n?.fitDestination), i = Bt([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 d = { ...o };
if (i = Bt([d]), s = { ...s }, this === r.getSource()) {
if (c === F.Orientation.Row) {
if (s.colStart < d.colStart && s.colEnd >= d.colStart || s.colEnd > d.colEnd && s.colStart <= d.colEnd) throw new ot(wd);
if (d.colStart === s.colStart && d.colEnd === s.colEnd) {
const u = d.rowEnd - d.rowStart + 1;
s.rowStart <= d.rowStart ? (d.rowStart += u, d.rowEnd += u) : (s.rowStart -= u, s.rowEnd -= u);
}
} else {
if (s.rowStart < d.rowStart && s.rowEnd >= d.rowStart || s.rowEnd > d.rowEnd && s.rowStart <= d.rowEnd) throw new ot(wd);
if (d.rowStart === s.rowStart && d.rowEnd === s.rowEnd) {
const u = d.colEnd - d.colStart + 1;
s.colStart <= d.colStart ? (d.colStart += u, d.colEnd += u) : (s.colStart -= u, s.colEnd -= u);
}
}
l = Bt([s]);
}
r.getSource().getRanges([d]).delete(c);
}
h.commit({ viewBefore: { ranges: t, view: this.getView(), selection: i, selectOptions: n?.autoSelect }, viewAfter: { ranges: t, view: this.getView(), selection: l, selectOptions: n?.autoSelect } }), this._autoSelect(n?.autoSelect ?? !1, l);
} catch (d) {
throw h.rollback(), d;
}
return s;
}
_insertCells(t, e, n = void 0) {
const r = this;
let o;
n = n ?? ((f, p) => {
r._validateCoords(f, p ?? Ba);
}), e === F.Orientation.Column || e === F.Orientation.Row ? (o = e, e = {}) : e && (o = e.orientation);
const s = e?.description ?? "Insert Cells", i = (o ?? this._getDefaultShiftOrientation(t[0])) === F.Orientation.Column;
if (this._protectionCheck(() => [i ? "insertColumns" : "insertRows"], t, s), jo(t)) throw new ot("We can't insert cells with overlapping selections.");
const l = this._entireCoords;
let c = l.colEnd, h = l.rowEnd;
const d = Bt(t), u = this._beginCommit({ description: s, operation: { name: "insertCells" } }), g = u.getState(this), m = i ? F.Direction.Right : F.Direction.Down;
try {
let f = g.cellValuesGrid, p = g.contentfulSpatial, _ = g.unlockSpatial, S = g.mergeSpatial, C = g.directStyleSpatial, y = g.continuousFillSpatial, E = g.conditionalSpatial, w = g.hyperlinkSpatial, b = g.commentsSpatial, v = g.movableSpatial, I = g.tableSpatial, x = g.calcGraph, R = g.rangesListenerSpatial2, A = g.rangeListenerSpatial, M = g.rangesListenerMap;
const T = /* @__PURE__ */ new Map(), O = jn(t.slice(), F.Direction.Left), W = O.length;
for (let H = 0; H < W; H++) {
const P = O[H];
c = Math.min(c, P.colStart), h = Math.min(h, P.rowStart);
const j = i ? P.colEnd - P.colStart + 1 : P.rowEnd - P.rowStart + 1, G = f.getCoords();
if (G) {
const J = { ...P, colEnd: i ? Math.max(P.colEnd, G?.colEnd ?? P.colStart) + (P.colEnd - P.colStart + 1) : P.colStart, rowEnd: i ? P.rowStart : Math.max(P.rowEnd, G?.rowEnd ?? P.rowStart) + (P.rowEnd - P.rowStart + 1) }, Z = p.search(J), q = Z.length;
for (let Q = 0; Q < q; Q++) {
const it = Z[Q], X = { ...P };
i ? X.colEnd = Math.max(X.colEnd, it.colEnd) + j : X.rowEnd = Math.max(X.rowEnd, it.rowEnd) + j, n(X);
}
f = f.clone(), f.shift(P, m), this._updateState({ cellValuesGrid: f });
}
const K = P.colStart <= l.colStart && P.colEnd >= l.colEnd, V = P.rowStart <= l.rowStart && P.rowEnd >= l.rowEnd, $ = (J, Z, q, Q) => {
let it = null;
q > 1 && (it = J.at(q - 1));
const X = Q - q + 1;
Z?.(q, X), it && J.updateHeaderPairs([{ address: { min: q, max: Q }, update: it }]);
};
K && $(this._rowHeaders, this._rowHeadersShiftCallback, P.rowStart, P.rowEnd), V && $(this._colHeaders, this._colHeadersShiftCallback, P.colStart, P.colEnd), p = p.shift({ range: P, direction: m, cloneIfUpdate: p === g.contentfulSpatial, coordValidator: n }), _ = _.shift({ range: P, direction: m, cloneIfUpdate: _ === g.unlockSpatial, coordValidator: n }), S = S.shift({ range: P, direction: m, cloneIfUpdate: S === g.mergeSpatial, coordValidator: n }), C = C.shift({ range: P, direction: m, cloneIfUpdate: C === g.directStyleSpatial, coordValidator: n }), y = y.shift({ range: P, direction: m, cloneIfUpdate: y === g.continuousFillSpatial, coordValidator: n }), E = E.shift({ range: P, direction: m, cloneIfUpdate: E === g.conditionalSpatial, coordValidator: n }), w = w.shift({ range: P, direction: m, cloneIfUpdate: w === g.hyperlinkSpatial, coordValidator: n }), b = b.shift({ range: P, direction: m, cloneIfUpdate: b === g.commentsSpatial, coordValidator: n }), v = v.shift({ range: P, direction: m, cloneIfUpdate: v === g.movableSpatial, coordValidator: n }), I = I.shift({ range: P, direction: m, cloneIfUpdate: I === g.tableSpatial, coordValidator: n }), x = x.shift({ range: P, direction: m, cloneIfUpdate: x === g.calcGraph }), A = A.shift({ range: P, direction: m, cloneIfUpdate: A === g.rangeListenerSpatial, onShift: (J) => {
M === g.rangesListenerMap && (M = new Map(M)), this._processListenerShift(M, T, g.rangesListenerMap, J);
} }), R = R.shift({ range: P, direction: m, cloneIfUpdate: R === g.rangesListenerSpatial2, coordValidator: n });
}
let D = g.formulaSpatial, z = g.spillSpatial, B = g.pendingSpatial;
x !== g.calcGraph && (D = D.clone(), z = z.clone(), B = B.clone()), this._updateState({ contentfulSpatial: p, unlockSpatial: _, mergeSpatial: S, directStyleSpatial: C, continuousFillSpatial: y, conditionalSpatial: E, hyperlinkSpatial: w, commentsSpatial: b, movableSpatial: v, tableSpatial: I, calcGraph: x, formulaSpatial: D, spillSpatial: z, pendingSpatial: B, rangesListenerSpatial2: R, rangeListenerSpatial: A, rangesListenerMap: M }), this._commitAndAutoSelect(u, d, e?.autoSelect, { viewAfter: { ranges: O, listeners: T } }, i ? F.Orientation.Column : F.Orientation.Row);
} catch (f) {
throw u.rollback(), f instanceof Wt ? new ot(f.message ?? Ba) : f;
}
}
_deleteCells(t, e) {
let n;
e === F.Orientation.Column || e === F.Orientation.Row ? (n = e, e = {}) : e && (n = e.orientation);
const r = (n ?? this._getDefaultShiftOrientation(t[0])) === F.Orientation.Column, o = e?.description ?? "Delete Cells";
if (this._protectionCheck(() => [r ? "deleteColumns" : "deleteRows"], t, o), jo(t)) throw new ot("We can't delete cells with overlapping selections.");
const s = this._entireCoords;
let i = s.colEnd, l = s.rowEnd;
const c = r ? F.Direction.Left : F.Direction.Up, h = Bt(t), d = this._beginCommit({ description: o, operation: { name: "deleteCells" } }), u = d.getState(this);
try {
let g = u.cellValuesGrid, m = u.contentfulSpatial, f = u.mergeSpatial, p = u.unlockSpatial, _ = u.directStyleSpatial, S = u.continuousFillSpatial, C = u.conditionalSpatial, y = u.hyperlinkSpatial, E = u.commentsSpatial, w = u.movableSpatial, b = u.movableMapModel, v = u.tableSpatial, I = u.tableMapModel, x = u.calcGraph, R = u.rangesListenerSpatial2, A = u.rangeListenerSpatial, M = u.rangesListenerMap;
const T = /* @__PURE__ */ new Map(), O = jn(t.slice(), F.Direction.Left), W = O.length;
for (let D = 0; D < W; D++) {
const z = O[D];
i = Math.min(i, z.colStart), l = Math.min(l, z.rowStart), g.getCoords() && (g = g.clone(), g.shift(z, c), this._updateState({ cellValuesGrid: g }));
const B = z.colStart <= s.colStart && z.colEnd >= s.colEnd, H = z.rowStart <= s.rowStart && z.rowEnd >= s.rowEnd;
B && this._rowHeadersShiftCallback(z.rowStart, -1 * (z.rowEnd - z.rowStart + 1)), H && this._colHeadersShiftCallback(z.colStart, -1 * (z.colEnd - z.colStart + 1)), m = m.shift({ range: z, direction: c, cloneIfUpdate: m === u.contentfulSpatial }), p = p.shift({ range: z, direction: c, cloneIfUpdate: p === u.unlockSpatial }), f = f.shift({ range: z, direction: c, cloneIfUpdate: f === u.mergeSpatial }), _ = _.shift({ range: z, direction: c, cloneIfUpdate: _ === u.directStyleSpatial }), S = S.shift({ range: z, direction: c, cloneIfUpdate: S === u.continuousFillSpatial }), C = C.shift({ range: z, direction: c, cloneIfUpdate: C === u.conditionalSpatial }), y = y.shift({ range: z, direction: c, cloneIfUpdate: y === u.hyperlinkSpatial }), E = E.shift({ range: z, direction: c, cloneIfUpdate: E === u.commentsSpatial }), w = w.shift({ range: z, direction: c, cloneIfUpdate: w === u.movableSpatial }), v = v.shift({ range: z, direction: c, cloneIfUpdate: v === u.tableSpatial }), x = x.shift({ range: z, direction: c, cloneIfUpdate: x === u.calcGraph }), A = A.shift({ range: z, direction: c, cloneIfUpdate: A === u.rangeListenerSpatial, onShift: (P) => {
M === u.rangesListenerMap && (M = new Map(M)), this._processListenerShift(M, T, u.rangesListenerMap, P);
} }), R = R.shift({ range: z, direction: c, cloneIfUpdate: R === u.rangesListenerSpatial2 });
}
this._updateState({ contentfulSpatial: m, unlockSpatial: p, mergeSpatial: f, directStyleSpatial: _, continuousFillSpatial: S, conditionalSpatial: C, hyperlinkSpatial: y, commentsSpatial: E, movableSpatial: w, movableMapModel: b, tableSpatial: v, tableMapModel: I, calcGraph: x, rangesListenerSpatial2: R, rangeListenerSpatial: A, rangesListenerMap: M }), this._commitAndAutoSelect(d, h, e?.autoSelect, { viewAfter: { ranges: O, listeners: T } });
} catch (g) {
throw d.rollback(), g instanceof Wt ? new ot(g.message ?? Ba) : g;
}
}
_autoFit(t, e) {
if (this._closed) throw new Error(xe);
e = { expandOnly: !1, skipCustomSize: !1, minContent: !1, ...e };
const n = "Autofit";
let r;
const o = Hl(t, this._entireCoords, !0), s = Wl(t, this._entireCoords, !0);
r = !o && s ? `${n} ${Kn}` : !s && o ? `${n} ${Jn}` : s && o ? `${n} All` : `${n}`;
let i = e.orientations !== F.Orientations.Row;
this._colHeaders.isProtected() && (i = !1);
let l = e.orientations !== F.Orientations.Column;
if (this._rowHeaders.isProtected() && (l = !1), !l && !i) return;
const c = i && (e.expandOnly === !1 || e.expandOnly === F.Orientation.Row), h = l && (e.expandOnly === !1 || e.expandOnly === F.Orientation.Column), d = e.minContent;
l && this._protectionCheck(() => ["formatRows"], t, r), i && this._protectionCheck(() => ["formatColumns"], t, r);
const u = (f, p) => f === void 0 ? p : p === void 0 ? f : f.sizeSet - p.sizeSet, g = Bt(t), m = this._beginCommit({ description: e.description ?? r });
try {
let f = Number.MAX_SAFE_INTEGER, p = Number.MIN_SAFE_INTEGER, _ = !1, S = "", C = -1, y = !1, E = !1, w = !1, b = Number.MAX_SAFE_INTEGER, v = Number.MIN_SAFE_INTEGER;
const I = this._styles.getNormal(), x = this._cellOptions, R = e.orientations === F.Orientations.Row, A = /* @__PURE__ */ new Map(), M = Al(t, 1);
M.sort(L.createRangeComparator(F.Orientation.Column));
const T = M.length, O = { skipCustomSize: e.skipCustomSize }, W = dt.getDeviceScale(), D = this._defaultRowHeight() * W, z = this._defaultColWidth(), B = (P, j = 1) => {
if (P !== 0 && !(j > 1)) return P = Math.max(P, D), (G) => h ? P : Math.max(G, P ?? D);
}, H = (P, j = 1) => {
if (P !== 0 && !(j > 1)) return (G) => c ? P : Math.max(G, P ?? z);
};
for (let P = 0; P < T; P++) {
const j = [];
let G = -1, K = !1, V = I, $ = 1, J = 1, Z = 1;
const q = M[P];
let Q = q.colStart, it = q.rowStart, X = q.colEnd, at = q.rowEnd;
const ut = this._getUsedCoords();
(h || c) && ut && (Q = h ? ut.colStart : q.colStart, it = c ? ut.rowStart : q.rowStart, X = h ? ut.colEnd : q.colEnd, at = c ? ut.rowEnd : q.rowEnd);
const tt = { includeRangeTypes: { [ht.Type.Style]: !1, [ht.Type.Merge]: !1, [ht.Type.Continuous]: !1, [ht.Type.Contentful]: !1 }, ignoreHidden: !1, bounds: { colStart: Q, rowStart: it, colEnd: X, rowEnd: at }, orientation: F.Orientation.Column }, rt = l ? [] : void 0, ct = i ? [] : void 0, lt = (Ht, Rt, Mt) => {
if (Ht > Rt) return null;
const kt = [];
let Ot = Ht;
const Pt = Mt ? Mt.length : 0;
for (let Tt = 0; Tt < Pt; Tt++) {
const Zt = Mt[Tt], At = Zt.min, Jt = Zt.max;
if (Ot >= At) {
Ot = Jt + 1;
continue;
}
const qt = { address: { min: Ot, max: At - 1 }, update: Fu };
kt.push(qt), Ot = Jt + 1;
}
if (Ot <= Rt) {
const Tt = { address: { min: Ot, max: Rt }, update: Fu };
kt.push(Tt);
}
return kt;
}, nt = this._rangeStateIterator(tt);
let gt = nt.next();
for (; !gt.done; ) {
const Ht = gt.value, Rt = Ht.intersection, Mt = Ht.start, kt = Ht.end;
Mo.colStart = Mt.colIndex, Mo.rowStart = Mt.rowIndex, Mo.colEnd = kt.colIndex, Mo.rowEnd = kt.rowIndex;
const Ot = L.intersectRanges(Mo, q, Yw), Pt = Vr(0, Ot, Rt, x).getBestFit();
if (l) {
const Tt = Math.max(Mt.rowIndex, it), Zt = Math.min(kt.rowIndex, at), At = Pt.height, Jt = { address: { min: Tt, max: Zt }, update: { size: B(At), autoSize: !0 }, sizeSet: At === null ? -1 : At };
rt.push(Jt);
}
if (i) {
const Tt = Math.max(Mt.colIndex, Q), Zt = Math.min(kt.colIndex, X), At = Pt.width, Jt = { address: { min: Tt, max: Zt }, update: { size: H(At), autoSize: !0 }, sizeSet: At === null ? -1 : At };
ct.push(Jt);
}
gt = nt.next();
}
const St = this._cellStateIterator({ ...tt, includeRangeTypes: { [ht.Type.Merge]: !1, [ht.Type.Table]: !1, [ht.Type.Style]: !1, [ht.Type.Continuous]: !1 }, ignoreEmptyIntersections: !0 });
let wt, jt, It, _t = St.next(), Gt = 1, ke = 1;
for (; !_t.done; ) {
const Ht = _t.value, Rt = Ht[0], Mt = Ht[2];
let kt = I;
const Ot = Mt?.directStyle ?? Mt?.table?.getStyle() ?? null;
Ot === wt ? kt = jt : (kt = Ot ? Vr(0, L.cellToRange(Rt, Qw), Mt, x) : I, jt = kt);
let Pt = 1, Tt = 1;
const Zt = Mt?.merge ?? null;
if (Zt === It) Pt = Gt, Tt = ke;
else {
if (Zt) {
const gn = Zt.getCoords();
Pt = gn.colEnd - gn.colStart + 1, Tt = gn.rowEnd - gn.rowStart + 1;
} else Pt = 1, Tt = 1;
Gt = Pt, ke = Tt;
}
const At = Rt.colIndex, Jt = Rt.rowIndex, qt = Ht[1], je = _e(qt), un = L.isCellWithinRange(Rt, q), so = Mt?.continuous ?? null;
so && (Z = so.getCoords().colEnd - At + 1);
let Dn = !1, rr = !1;
if (wt === Ot && Pt === $ && Tt === J && je !== Y.String && je !== Y.Error && un === K || (Dn = !0, je === Y.RichData && (rr = !0), rr && (Dn = !1)), wt = Ot, It = Zt, (G !== At || Dn) && (G !== -1 && j.push({ col: G, style: V, spanWidth: Pt, spanHeight: Tt, minVal: f, maxVal: p, hasZero: _, text: S, textId: C, hasFalse: E, hasTrue: y, hasEmpty: w, minRow: b, maxRow: v, colWidth: this._colHeaders.getSpanSize(G), measureWidth: -1, measureHeight: -1, colSpan: Z, isFit: K }), G = At, V = kt, K = un, $ = Pt, J = Tt, f = Number.MAX_SAFE_INTEGER, p = Number.MIN_SAFE_INTEGER, _ = !1, S = "", C = -1, E = !1, y = !1, w = !1, b = Jt), v = Jt, !rr) if (qt === null) w = !0;
else switch (je) {
case Y.Number:
qt === 0 && (_ = !0), f = Math.min(f, qt), p = Math.max(p, qt);
break;
case Y.String:
S = qt, C = qt;
break;
case Y.Error:
S = qt.toString(), C = -1;
break;
case Y.Boolean:
qt ? y = !0 : E = !0;
}
_t = St.next();
}
G !== -1 && j.push({ col: G, style: V, spanWidth: $, spanHeight: J, minVal: f, maxVal: p, hasZero: _, text: S, textId: C, hasFalse: E, hasTrue: y, hasEmpty: w, minRow: b, maxRow: v, colWidth: this._colHeaders.getSpanSize(G), colSpan: Z, measureWidth: -1, measureHeight: -1, isFit: K });
let Et = -1, Ut = -1;
const Ce = j.length;
for (let Ht = 0; Ht < Ce; Ht++) {
const Rt = j[Ht], Mt = R || !Rt.isFit, kt = Rt.maxVal, Ot = Rt.style, Pt = Rt.colSpan;
let Tt = Rt.colWidth;
if (Pt > 1 && (Tt = this._colHeaders.getSpanSize(G, G + Pt)), Et = 0, Ut = 0, kt !== Number.MIN_SAFE_INTEGER) {
const At = Un(Y.Number, Ot, kt, x, Tt, d, Mt);
Et = At.width, Ut = At.height;
const Jt = Rt.minVal;
if (Jt * kt < 0) {
const qt = Un(Y.Number, Ot, Jt, x, Tt, d, Mt);
Et = Math.max(Et, qt.width), Ut = Math.max(Ut, qt.height);
}
if (Rt.hasZero && Jt !== 0 && kt !== 0) {
const qt = Un(Y.Number, Ot, 0, x, Tt, d, Mt);
Et = Math.max(Et, qt.width), Ut = Math.max(Ut, qt.height);
}
}
const Zt = Rt.text;
if (Zt.length > 0) {
const At = Un(Y.String, Ot, Zt, x, Tt, d, Mt, void 0, A);
Et = Math.max(Et, At.width), Ut = Math.max(Ut, At.height);
}
if (Rt.hasTrue || Rt.hasFalse) {
const At = Un(Y.Boolean, Ot, !Rt.hasFalse, x, Tt, d, Mt);
Et = Math.max(Et, At.width), Ut = Math.max(Ut, At.height);
}
if (Rt.hasEmpty) {
const At = Un(Y.Boolean, Ot, null, x, Tt, d, Mt);
Et = Math.max(Et, At.width), Ut = Math.max(Ut, At.height);
}
Rt.measureWidth = Et, Rt.measureHeight = Ut;
}
if (i) {
for (let Mt = 0; Mt < Ce; Mt++) {
let kt = j[Mt];
const Ot = kt.col;
let Pt = j[Mt + 1], Tt = kt.measureWidth ?? 0;
for (; Pt && Pt.col === Ot; ) Pt.measureWidth && (Tt = Math.max(Pt.measureWidth ?? 0, Tt)), Mt++, kt = j[Mt], Pt = j[Mt + 1];
Tt === 0 && (Tt = null);
const Zt = H(Tt, kt.spanWidth);
ct.push({ address: { min: Ot, max: Ot }, update: { size: Zt, autoSize: !0 }, sizeSet: Tt === null ? -1 : Tt });
}
ct.sort(u);
let Ht = this._colHeaders.updateHeaderPairs(ct, O);
Ht = bn(wr(yh(Ht)));
const Rt = lt(q.colStart, q.colEnd, Ht);
Rt && this._colHeaders.updateHeaderPairs(Rt, O);
}
if (l) {
for (let Mt = 0; Mt < Ce; Mt++) {
let kt = j[Mt], Ot = kt.measureHeight ?? 0;
Ot === 0 && (Ot = null);
const Pt = B(Ot, kt.spanHeight);
rt.push({ address: { min: kt.minRow, max: kt.maxRow }, update: { size: Pt, autoSize: !0 }, sizeSet: Ot === null ? -1 : Ot });
}
rt.sort(u);
let Ht = this._rowHeaders.updateHeaderPairs(rt, O);
Ht = bn(wr(yh(Ht)));
const Rt = lt(q.rowStart, q.rowEnd, Ht);
Rt && this._rowHeaders.updateHeaderPairs(Rt, O);
}
}
this._commitAndAutoSelect(m, g, e?.autoSelect, { viewAfter: { ranges: t } });
} catch (f) {
throw m.rollback(), f;
}
}
_createRangeEvent(t, e, n) {
const r = this, o = () => {
const i = r._getState();
return this._closed || i.deleted ? Rn(null) : t ? Array.isArray(t) ? r._createRanges(t) : r._createRange(t) : Rn(this, this._entireCoords);
}, s = e.trigger;
return { getSource: o, getFrom: () => {
const i = e.from;
if (i) return i;
let l = n;
return l || (l = o().getCoords()), Array.isArray(l) ? r._createRanges(l) : r._createRanges([l]);
}, getTo: () => e.to ?? null, trigger: s, isUndo: e.isUndo ?? !1, isDataChange: e.isDataChange ?? !1, isTransactional: e.isTransactional ?? !0, toString: () => `SheetRangeEvent: ('${s}', ${o().toString()})`, timeStamp: e.timeStamp ?? Date.now() };
}
_notifyAddressListeners(t, e, n, r) {
const o = e.entries();
let s = o.next();
const i = r.trigger;
for (; !s.done; ) {
const l = s.value[0];
let c = s[1];
if (c || (c = t.get(l)), c && !n.has(l)) {
let h = !1;
const d = c.options;
d && (h = i === "address" ? d.ignoreAddressChanges : d.ignoreDataChanges), h !== !0 && c.notify(r), n.add(l);
}
s = o.next();
}
}
_notifyDataListeners(t, e, n = null, r, o) {
if (!t) return;
const s = n.length;
for (let i = 0; i < s; i++) {
const l = n[i];
if (!l) continue;
const c = t.search(l), h = c.length;
for (let d = 0; d < h; d++) {
const u = c[d].value.groupId;
if (!r.has(u)) {
const g = e.get(u);
g.options?.ignoreDataChanges !== !0 && g.notify(o), r.add(u);
}
}
}
}
_notifyRangeListeners(t, e, n = null, r) {
if (!t) 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 = t.search(l), h = c.length;
for (let d = 0; d < h; d++) {
const u = c[d].value.id;
if (o.has(u)) continue;
const g = e.get(u);
o.add(u);
const m = g.ranges, f = m.length;
for (let p = 0; p < f; p++) {
const _ = m[p], S = this._createRangeEvent(_, r, l);
this._notifyRangeListener2(g, S, r);
}
}
}
}
_notifyRangeListener2(t, e = null, n = null) {
if (t.options?.ignoreDataChanges && n?.isDataChange) return;
const o = t.handler ?? t.handlerW.deref();
if (o) try {
o?.(e);
} catch (s) {
console.warn(s);
}
}
_notifyUsedRangeChange() {
this._lastCellRead.coords = null, this._lastUsedCoordsRead.coords = null, this._emitter.notify("onUsedRangeChange");
}
_notifyMergeChange() {
this._emitter.notify("onMergesChange");
}
addListeners(t, e) {
let n = null;
if (t.onLayoutChange) {
const o = t, s = { onSizesChange: () => {
o.onLayoutChange(this);
} };
n = [], n.push(this._colHeaders.addListeners(s, e)), n.push(this._rowHeaders.addListeners(s, e));
}
let r = this._emitter.addListeners(t, e);
if (n) {
const o = r;
r = () => {
const s = n.length;
for (let i = 0; i < s; i++) n[i]();
o();
};
}
return r;
}
_addRangesListeners(t, e, n) {
if (this._closed) throw new Error(xe);
if (!e) throw new ot(cd);
n = n ? { ...Ws, ...n } : Ws;
const r = n?.transactional ?? !1, o = this, s = Kw++ % Number.MAX_SAFE_INTEGER, i = () => {
let f = null, p = null;
if (r) {
const y = o._getState();
if (!y) return;
f = y.rangeListenerSpatial.clone(), p = new Map(y.rangesListenerMap);
} else f = o._rangeListenerSpatial, p = o._rangesListenerMap;
const _ = p.get(s);
if (!_) return void console.log("Listener not found");
const S = _.ranges, C = S.length;
for (let y = 0; y < C; y++) {
const E = L.sanitizeRange(S[y]);
E !== null && f.remove(E, (w, b) => {
if (b.value.id === s) return !0;
});
}
if (p.delete(s), r) {
const y = this._beginCommit({ description: "Remove Range Listener" });
this._updateState({ rangeListenerSpatial: f, rangesListenerMap: p }), y.commit({ forceAmend: !0 });
}
}, l = [...t];
let c = { id: s, handler: null, handlerW: null, removeListener: i, options: n, ranges: l };
n?.weakly ? c.handlerW = new WeakRef(e) : c.handler = e;
let h = null, d = null, u = null;
if (r) {
u = this._beginCommit({ description: "Add Range Listener" });
const f = this._getState();
h = f.rangeListenerSpatial.clone(), d = new Map(f.rangesListenerMap);
} else h = o._rangeListenerSpatial, d = o._rangesListenerMap;
const g = [], m = t.length;
for (let f = 0; f < m; f++) {
const p = { ...t[f], value: { id: s, offset: f, options: n } };
g.push(p);
}
return h.load(g), d.set(s, c), u && (this._updateState({ rangeListenerSpatial: h, rangesListenerMap: d }), u.commit({ forceAmend: !0 })), i;
}
_addRangesListeners2(t, e, n, r) {
if (this._closed) throw new Error(xe);
if (!e) throw new ot(cd);
n = n ? { ...Ws, ...n } : Ws;
const o = n?.transactional ?? !1, s = this, i = k.uuidV4(), l = Xw++, c = () => {
let E = null, w = null;
const b = s._getState();
if (!b) return;
E = b.rangesListenerSpatial2.clone(), w = b.rangesListenerMap2;
const v = w.get(i);
if (v) {
const x = v?.spatialsIds, R = v?.coords, A = x.length;
for (let M = 0; M < A; M++) {
const T = x[M], O = R[M];
E.remove(O, (W, D) => {
if (D.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, d = this._beginCommit({ description: "Add Range Listener" });
const u = this._getState();
h = u.rangesListenerSpatial2.clone();
let g = null, m = null;
n?.weakly ? m = new WeakRef(e) : g = e;
const f = [], p = [...t];
let _ = [];
const S = t.length;
for (let E = 0; E < S; E++) {
const w = { ...t[E] };
p[E] = w;
const b = k.uuidV4(), v = new Bi(i, b, n?.ignoreAddressChanges ?? !1);
_.push(b);
const I = { ...L.sanitizeRange(w), value: v };
f.push(I);
}
h.load(f), n = { ...n };
const C = new zi(i, _, p, r, this, l, g, m, c, n), y = new Map(u.rangesListenerMap2);
return y.set(i, C), this._updateState({ rangesListenerSpatial2: h, rangesListenerMap2: y }), o || this._rangesListenerSorted.set(l, C), d.commit({ forceAmend: !0 }), c;
}
_getUsedCoords(t) {
const e = this._getState();
if (!e) return null;
let n = e.cellValuesGrid.getCoords();
return n = L.unionRanges(e.mergeSpatial.getBoundingCoords(), n), n = L.unionRanges(e.directStyleSpatial.getBoundingCoords(), n), n = L.unionRanges(e.formulaSpatial.getBoundingCoords(), n), n = L.unionRanges(e.spillSpatial.getBoundingCoords(), n), n = L.unionRanges(e.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 && $o(this._lastUsedCoordsRead.coords, n) || (this._lastUsedCoordsRead.coords = n, this._lastUsedCoordsRead.range = null), this._lastUsedCoordsRead.coords);
}
_isContentful(t, e) {
return !!this._contentCounts(t, void 0, e);
}
_getCount(t, e = !1) {
const n = this._contentCounts(t, Zw, e);
return n ? n[Ft.Content.Values] ?? 0 : 0;
}
_contentCounts(t, e, n) {
if (!e) {
const d = Object.keys(Ft.Content), u = d.length;
e = [];
for (let g = 0; g < u; g++) {
const m = d[g], f = Ft.Content[m];
f !== Ft.Content.Formats && f !== Ft.Content.Tables && e.push(f);
}
}
const r = {}, o = e.length;
let s, i, l = !1;
for (let d = 0; d < o; d++) {
const u = e[d];
u === Ft.Content.Values ? r[ht.Type.Contentful] = !1 : u === Ft.Content.Formulas ? r[ht.Type.Formula] = !1 : u === Ft.Content.Formats ? r[ht.Type.Style] = !1 : u === Ft.Content.Tables && (r[ht.Type.Table] = !1, l = !0);
}
const c = () => {
s = /* @__PURE__ */ new Set(), i = {};
for (let d = 0; d < o; d++) {
const u = e[d];
i[u] = 0;
}
}, h = t.length;
for (let d = 0; d < h; d++) {
const u = t[d], g = this._rangeStateIterator({ includeRangeTypes: r, ignoreHidden: n, bounds: u });
let m = g.next();
for (; !m.done; ) {
i || c();
const f = m.value, p = (f.end.colIndex - f.start.colIndex + 1) * (f.end.rowIndex - f.start.rowIndex + 1), _ = f.intersection;
if (_) {
_.contentful && (i[Ft.Content.Values] += p), _.formula && (i[Ft.Content.Formulas] += p);
const S = _.table;
S && (l && !s.has(S) && (i[Ft.Content.Tables] += 1, s.add(S)), _.contentful || (i[Ft.Content.Values] += p));
}
m = g.next();
}
}
return i;
}
getSelectedCell() {
const t = this.getSelection().getCoords().cell, e = this._lastCellSelected;
if (e?.cell && L.isEqualCells(t, e.coords)) return e.cell;
const n = this.getRange(t).getCell();
return this._lastCellSelected = { coords: t, cell: n }, n;
}
find(t) {
return t ? ((t = typeof t == "string" ? { text: t } : { ...t }).from || (t.from = this.getSelection().getCoords().cell), this.getEntireRange().find(t)) : re;
}
_setMaxSize(t, e) {
const n = t?.width ?? zs.width, r = t?.height ?? zs.height, o = this._entireCoords, s = o.colEnd - o.colStart + 1, i = o.rowEnd - o.rowStart + 1;
if (n === s && r === i) return this;
const l = this._beginCommit({ description: "Set Size" });
try {
const c = Object.freeze({ colStart: 0, rowStart: 0, colEnd: n - 1, rowEnd: r - 1 });
this._entireCoords = c, this._entireRange = this.getRange(c);
const h = this.getSelection(), d = h.getCoords(), u = Bm(d, Di, c);
h.updateCoords(u), this._emitter.notify("onViewChange", { source: this.getView() }), this._emitter.notify("onLayoutChange"), l.commit({ viewBefore: { view: this.getView(), selection: d }, viewAfter: { view: this.getView(), selection: u } }), this._autoSelect(e?.autoSelect, u);
} catch (c) {
throw l.rollback(), c;
}
return this;
}
_find(t, e) {
if (this._closed) throw new Error(xe);
typeof e == "string" && (e = { text: e });
const n = e?.text;
if (!n) return null;
const r = [...t], o = e?.orientation ?? F.Orientation.Row, s = e?.reverse, i = !e?.disableWrap, l = e?.from ? this._cellToCoords(e?.from) : null;
let c = null;
if (l) {
let b = -1;
for (let T = 0; b === -1 && T < r.length; T++) L.isCellWithinRange(l, r[T]) && (b = T);
c = L.cellToRange(l);
let v = Tl(r[b], c, o);
v.push(c);
const I = L.createRangeComparator(o, s);
v.sort(I);
let x = -1;
const R = v.length;
for (let T = 0; T < R; T++)
I(v[T], c) <= 0 && (x = T);
r.splice(b, 1, ...v);
const A = b + x, M = [];
for (let T = 0; T <= A; T++) M.push(r.shift());
if (i) {
const T = M.length;
for (let O = 0; O < T; O++) r.push(M[O]);
}
}
if (r.length === 0) return re;
const h = e?.fields?.includes(Ft.Content.Formulas) ?? !1, d = e?.fields?.includes(Ft.Content.Values) ?? !0, u = e?.matchEntireCell ?? !1, g = e?.matchCase ?? !1, m = e?.useRegex ?? !1, f = ((b, v, I) => {
const x = v ? "" : "i";
return I ? new RegExp(b, x) : new RegExp(((R) => {
let A = R.replace(/[|\\{}()[\]^$+.]/g, "\\$&");
return A = A.replace(/~\?/g, "\\?"), A = A.replace(/~\*/g, "\\*"), A = A.replace(/~~/g, "~"), A;
})(b), x);
})(n, g, m), p = n.length;
let _ = (b, v) => {
const I = (A) => {
if (!A) return !1;
let M = !!A.match(f);
return M && u && A.length !== p && (M = !1), M;
}, x = v.getCell();
let R = !1;
return !R && h ? R = I(x.getFormulaText() ?? x.toTextUnformatted(!0)) : d && (R = I(x.getNumberFormat().displayText)), R;
};
if (e?.matchCustom) {
const b = e.matchCustom, v = { matchCase: g, matchEntireCell: u, useRegex: m, fields: e?.fields ?? [Ft.Content.Formulas] };
let I, x, R = _;
const A = () => R(I, x);
_ = (M, T) => (I = M, x = T, b(M, A, v, T));
}
let S = -1, C = null, y = Lt, E = !1;
const w = () => {
if (y.done) {
if (S++, S >= r.length) return void (E = !0);
C = this._cellIterator({ reverse: s, orientation: o, includeRangeTypes: !1, bounds: r[S] });
}
if (y = C.next(), !y.done) {
const b = y.value;
return _(b.value, b.context);
}
return !1;
};
return { next: () => {
let b = null;
for (; !E && !b; ) w() && (b = y.value.context.getCell());
return b ? { value: b, done: !1 } : Lt;
} };
}
isDate1904() {
return this._isDate1904;
}
_surroundingRegion(t, e) {
const n = this._getState(), r = e?.contentOnly ?? !1, o = this._entireCoords;
if (!r) {
const l = n.tableSpatial.search(t);
if (l.length > 0) {
const c = l[0].value.model, h = c.getUsedRange().getCoords(), d = c.getRange().getCoords();
return L.isEqualRanges(h, t) ? d : L.isEqualRanges(d, t) ? o : h;
}
}
const s = r ? t : o;
return ((l, c, h = 2e4) => {
if (!c || c.length === 0) return null;
let d, u = !1;
for (let E = 0; E < c.length; E++) {
const w = c[E];
d = L.unionRanges(d, w.getBoundingCoords()), u = u || w.search(l).length > 0;
}
if (!d) return null;
const g = { ...L.EmptyRange }, m = l;
let f = u ? { ...l } : null;
if (!f) {
const E = ((b) => {
let v = [];
const I = c.length;
for (let x = 0; x < I; x++) {
const R = c[x].search(b), A = R.length;
v = A > 0 ? new Array(A) : void 0;
for (let M = 0; M < A; M++) {
const T = R[M];
v[M] = T;
}
}
return v || k.EmptyArray;
})({ colStart: l.colEnd, rowStart: l.rowEnd, colEnd: l.colEnd + 1, rowEnd: l.rowEnd + 1 }), w = E.length;
if (w > 0) {
f = { ...l };
for (let b = 0; b < w; b++) {
const v = E[b];
f.colEnd = Math.max(f.colEnd, v.colStart), f.rowEnd = Math.max(f.rowEnd, v.rowStart);
}
}
}
const p = { ...L.EmptyRange }, _ = () => {
const E = c.length;
for (let w = 0; w < E; w++) {
const b = c[w].search(g), v = b.length;
for (let I = 0; I < v; I++) {
const x = b[I];
f = L.unionRanges(f, x, p);
}
}
return f;
};
g.colStart = l.colStart, g.rowStart = l.rowStart, g.colEnd = l.colEnd, g.rowEnd = l.rowEnd, _();
const S = { ...f }, C = { ...L.EmptyRange };
let y = 0;
do {
if (g.colStart = C.colStart = S.colStart, g.rowStart = C.rowStart = S.rowStart, g.colEnd = C.colEnd = S.colEnd, g.rowEnd = C.rowEnd = S.rowEnd, S.colStart > d.colStart && (g.colStart = S.colStart - 1, g.colEnd = S.colStart - 1, g.rowStart = S.rowStart - 1, g.rowEnd = S.rowEnd + 1, _()), S.rowStart > d.rowStart && (g.rowStart = S.rowStart - 1, g.rowEnd = S.rowStart - 1, g.colStart = S.colStart - 1, g.colEnd = S.colEnd + 1, _()), S.colEnd < d.colEnd && (g.colStart = S.colEnd + 1, g.colEnd = S.colEnd + 1, g.rowStart = S.rowStart - 1, g.rowEnd = S.rowEnd + 1, _()), S.rowEnd < d.rowEnd && (g.rowStart = S.rowEnd + 1, g.rowEnd = S.rowEnd + 1, g.colStart = S.colStart - 1, g.colEnd = S.colEnd + 1, _()), !f) return null;
if (S.colStart = f.colStart, S.rowStart = f.rowStart, S.colEnd = f.colEnd, S.rowEnd = f.rowEnd, L.isEqualRanges(S, C)) return L.isEqualRanges(m, S) ? null : S;
if (L.isEqualRanges(S, m)) return null;
if (L.isEqualRanges(S, C)) return S;
y++;
} while (y < h);
return null;
})(t, [n.contentfulSpatial, n.mergeSpatial, n.formulaSpatial, n.spillSpatial, n.pendingSpatial]) || s;
}
_extendRange(t, e) {
if (this._closed) throw new Error(xe);
const n = this._entireCoords, r = this, o = { ignoreHidden: !0, onEntry: (h, d) => d }, s = { ignoreHidden: !0, onEntry: (h, d) => h.tvTl() === void 0 ? null : d };
let i;
const l = r._getRangedEntries("mergeSpatial", [L.cellToRange(e)], s);
l.length > 0 && (i = l[0]);
const c = [(h) => r._getRangedEntries("mergeSpatial", h, s), (h) => r._getRangedEntries("contentfulSpatial", h, o)];
return ((h, d, u, g, m) => {
let f, p, _, S = { ...d }, C = L.cellToRange(S), y = g(C).length > 0;
if (y) {
let b = 1, v = h === F.Direction.Up || h === F.Direction.Down;
u && (b += v ? u.rowEnd - u.rowStart : u.colEnd - u.colStart), h !== F.Direction.Left && h !== F.Direction.Up || (b = -b), v ? S.rowIndex = S.rowIndex + b : S.colIndex = S.colIndex + b, C = L.cellToRange(S), y = g(C).length > 0;
}
switch (h) {
case F.Direction.Up:
C.rowStart = Math.min(m.rowStart, C.rowStart), p = g(C).sort(L.createRangeComparator(F.Orientation.Row, !0)), f = d.rowIndex, _ = y ? p.length === 1 && f === p[0].rowStart ? m.rowStart : p[0].rowStart : p.length === 0 ? m.rowStart : p[0].rowEnd;
break;
case F.Direction.Down:
C.rowEnd = Math.max(m.rowEnd, C.rowEnd), p = g(C).sort(L.createRangeComparator(F.Orientation.Row, !1)), f = d.rowIndex, _ = y ? p.length === 1 && f === p[0].rowEnd ? m.rowEnd : p[0].rowEnd : p.length === 0 ? m.rowEnd : p[0].rowStart;
break;
case F.Direction.Left:
C.colStart = Math.min(m.colStart, C.colStart), p = g(C).sort(L.createRangeComparator(F.Orientation.Column, !0)), f = d.colIndex, _ = y ? p.length === 1 && f === p[0].colStart ? m.colStart : p[0].colStart : p.length === 0 ? m.colStart : p[0].colEnd;
break;
case F.Direction.Right:
C.colEnd = Math.max(m.colEnd, C.colEnd), p = g(C).sort(L.createRangeComparator(F.Orientation.Column, !1)), f = d.colIndex, _ = y ? p.length === 1 && f === p[0].colEnd ? m.colEnd : p[0].colEnd : p.length === 0 ? m.colEnd : p[0].colStart;
}
const E = p ? p.length : 0;
if (E > 1) {
let b = !1;
for (let v = 1; !b && v < E; v++) {
const I = p[v];
switch (h) {
case F.Direction.Up:
I.rowEnd < _ - 1 ? b = !0 : _ = Math.min(_, I.rowStart);
break;
case F.Direction.Down:
I.rowStart > _ + 1 ? b = !0 : _ = Math.max(_, I.rowEnd);
break;
case F.Direction.Left:
I.colEnd < _ - 1 ? b = !0 : _ = Math.min(_, I.colStart);
break;
case F.Direction.Right:
I.colStart > _ + 1 ? b = !0 : _ = Math.max(_, I.colEnd);
}
}
}
const w = L.cellToRange(d);
switch (h) {
case F.Direction.Up:
w.rowStart = _;
break;
case F.Direction.Down:
w.rowEnd = _;
break;
case F.Direction.Left:
w.colStart = _;
break;
case F.Direction.Right:
w.colEnd = _;
}
return w;
})(t, e, i, (h) => {
const d = [], u = [h], g = c.length;
for (let m = 0; m < g; m++) {
const f = (0, c[m])(u), p = f.length;
for (let _ = 0; _ < p; _++) {
const S = f[_];
d.push(S);
}
}
return d;
}, n);
}
_defaultFontDims() {
if (this._defaultFontBoundsCache) return this._defaultFontBoundsCache;
const t = this._styles.getNormal();
let e = 0, n = 0;
for (let r = 0; r <= 9; r++) {
const o = t.measureText(r.toString());
e = Math.ceil(Math.max(o.width, e)), n = Math.max(o.lineHeight, n);
}
return this._defaultFontBoundsCache = { width: e, height: n }, this._defaultFontBoundsCache;
}
getColumnWidthAsFontUnit(t) {
const e = Math.round(this._defaultFontDims().width), n = t / (this.getView().isShowFormulas() ? 2 : 1);
if (!e || !t) return 0;
let r = 5;
return n < r + e && (r = n * (r / (r + e))), (n - r) / e;
}
_defaultColWidth() {
if (this._defaultColWidthCache) return this._defaultColWidthCache;
const t = this._defaultFontDims()?.width || 7, e = 8 * Math.round((8 * t + 5) / 8) / Math.round(this._defaultFontDims().width);
return this._defaultColWidthCache = e;
}
_defaultRowHeight() {
if (this._defaultRowHeightCache) return this._defaultRowHeightCache;
let t = this._defaultFontDims();
if (!t || t.width === 0) return this._defaultRowHeightCache = 20 / dt.getDeviceScale(), this._defaultRowHeightCache;
const e = this._styles.getNormal(), n = /* @__PURE__ */ new Map();
let r = t.height + 2;
return this._colHeaders.getUsedRange().forEachSpan((o, s) => {
const i = s.getCellHeader();
i?.getStyle() !== e && (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 / dt.getDeviceScale() * 4) / 4, this._defaultRowHeightCache;
}
getProtection() {
return this._protection ?? null;
}
async _selectSheet(t, e) {
if (await this._options.container?.requestSelect?.() === !1) return !1;
if (!e) return !0;
e === !0 && (e = k.EmptyObject);
const n = e.orientation;
n === F.Orientation.Column ? t = { colStart: t.colStart, rowStart: void 0, colEnd: t.colEnd, rowEnd: void 0 } : n === F.Orientation.Row && (t = { colStart: void 0, rowStart: t.rowStart, colEnd: void 0, rowEnd: t.rowEnd });
const r = { coords: t }, o = await this._emitter.notify("onRequestScrollIntoView", { params: r, async: !0 });
if (!o) return !1;
const s = o.length;
for (let i = 0; i < s; i++) if (o[i] === !1) return !1;
return !0;
}
async scrollTo(t, e) {
const n = { ...e, coords: t }, 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;
}
_resolveSelectOptions(t, e) {
return t ? (t === !0 && (t = { autoFocus: !0, scrollIntoView: !0 }), t.scrollIntoView === !0 && (t = { ...t, scrollIntoView: {} }), e && (t = { ...t, scrollIntoView: { orientation: e, ...t?.scrollIntoView } }), t) : null;
}
async _commitAndAutoSelect(t, e, n = !1, r, o) {
const s = this._resolveSelectOptions(n, o);
return r = { ...r, viewAfter: { view: this.getView(), selection: e, selectOptions: s, ...r?.viewAfter } }, t.commit(r), this._autoSelect(n, e, o);
}
async _autoSelect(t, e, n) {
if (!t) return;
const r = this._resolveSelectOptions(t, n), o = r?.autoFocus, s = r?.scrollIntoView, i = r?.anchor, l = this.getSelection(), c = l.getCoords(), h = l.getRangesCoords(e), d = this._entireCoords, u = ((S, C, y) => {
if (!S || S.length === 0 || !C) return k.EmptyArray;
const E = [...S], w = E.length, b = y.colStart, v = y.rowStart, I = y.colEnd, x = y.rowEnd;
for (let R = 0; R < w; R++) {
const A = { ...E[R] };
let M = A;
const T = C.search(A), O = A.rowStart <= v && A.rowEnd >= x, W = A.colStart <= b && A.colStart >= I, D = T.length;
for (let z = 0; z < D; z++) {
const B = T[z];
O || (M.colStart = Math.min(M.colStart, B.colStart), M.colEnd = Math.max(M.colEnd, B.colEnd)), W || (M.rowStart = Math.min(M.rowStart, B.rowStart), M.rowEnd = Math.max(M.rowEnd, B.rowEnd));
}
E[R] = M;
}
return E;
})(h, this._getState().mergeSpatial, d);
let g = -1, m = null;
if (!i) {
const S = c?.cell, C = u.length;
for (let y = 0; g === -1 && y < C; y++) {
const E = u[y];
L.isCellWithinRange(S, E) && (g = y, m = S);
}
}
const f = Bt(u, m, g);
this.getSelection().updateCoords(f);
const p = f.ranges?.[f.rangeIndex] ?? L.cellToRange(f.cell), _ = await this._selectSheet(p, s);
if (s !== !1 && _ === !1) return u;
if (o !== !1) {
const S = await this._emitter.notify("onRequestFocus");
if (!S) return u;
const C = S.length;
for (let y = 0; y < C; y++) if (S[y] === !1) return u;
}
return u;
}
getSelection() {
return this._rangeSelection;
}
getView() {
return this._view;
}
setView(t) {
if (this._closed) throw new Error(xe);
if (!t) throw new ot("View can not be empty.");
this._viewRemoveListener?.(), this._view = t, this._viewRemoveListener = t.addListeners(this._viewListener, { transactional: !1 });
const e = this.getSelection().getCoords();
return this._rangeSelection.updateCoords(e), this._emitter.notify("onMovableSelectionChange"), this._emitter.notify("onTopLeftChange"), this._emitter.notify("onFreezeSplitChange"), this._emitter.notify("onViewChange", { source: t }), this;
}
getTabColor() {
return this._tabColor;
}
setTabColor(t) {
if (this._closed) throw new Error(xe);
return this._tabColor = typeof t == "string" ? this._styles.parseColor(t) : t ?? null, this._emitter.notify("onTabColorChange"), this;
}
getRowHeaders() {
return this._rowHeaders;
}
getColumnHeaders() {
return this._colHeaders;
}
async toJSON(t = !1) {
if (this._closed) throw new Error(xe);
await this._emitter.notify("onBeforeSave", { async: !0 }), await Promise.resolve(this._starting);
let e = {};
const n = this._getState();
if (!n) return e;
try {
const p = this._strings.beginPersist();
try {
if (!t) {
const E = [], w = this._cellStateIterator({ includeRangeTypes: !1, orientation: F.Orientation.Column });
let b = w.next(), v = Number.MIN_SAFE_INTEGER, I = Number.MIN_SAFE_INTEGER, x = null, R = null, A = null, M = null;
for (; !b.done; ) {
const T = b.value[0], O = T.colIndex, W = T.rowIndex;
O !== v && (M && E.push(M), x = [], A = [], M = [O, A], v = O, I = W - 2), W > I + 1 && (x = [], R = [W, x], A.push(R));
const D = b.value[1], z = _e(D);
let B;
if (z === Y.Number || z === Y.Boolean) B = D;
else if (z === Y.String)
B = "" + p.add(D);
else if (z === Y.Error) B = { t: z, v: D.getCode() };
else if (z === Y.RichData) {
const H = D, P = H.type, j = H?.toJSON?.();
P && j && (B = { t: z, v: 0 });
} else console.warn("error", B);
x.push(B), I = W, b = w.next();
}
M && E.push(M), E.length > 0 && (e.data = E);
}
this._ownStrings && (e.strings = await p.toJSONAsync());
} catch (E) {
console.warn("error", E);
} finally {
p.endPersist();
}
const _ = this._colHeaders.toJSON();
_ && (_.headers && _.headers.length > 0 && (e.cols = _.headers), _.defaultSize !== void 0 && _.defaultSize !== -1 && (e.defaultColSize = _.defaultSize));
const S = this._rowHeaders.toJSON();
S && (S.headers && S.headers.length > 0 && (e.rows = S.headers), S.defaultSize !== void 0 && S.defaultSize !== -1 && (e.defaultRowSize = S.defaultSize));
const C = this.getProtection().toJSON();
C && (e.protection = C), this._view.setRangeSelection(this.getSelection().getCoords());
const y = this._view.toJSON();
y && (e.view = y), this._tabColor && (e.tabColor = this._tabColor.toString());
} catch (p) {
console.warn(p);
}
const r = jn(n.mergeSpatial.all());
r.length > 0 && (e.merges = ic(r));
const o = jn(n.directStyleSpatial.all());
if (o.length > 0) {
const p = this._styles.beginPersist();
try {
const _ = [], S = o.length;
for (let C = 0; C < S; C++) {
const y = o[C], E = p.getElementID(y.value.toJSON());
_.push({ r: Yr.rangeToString(y), v: E });
}
if (e.directStyles = _, this._ownStyles) {
const C = p.toJSON();
C && Object.keys(C).length > 0 && (e.styles = C);
}
} catch (_) {
console.warn(_);
} finally {
p.endPersist();
}
}
const s = jn(n.hyperlinkSpatial.all()), i = s.length;
if (i > 0) {
const p = [];
for (let _ = 0; _ < i; _++) {
const S = s[_];
let C = S.value;
p.push({ r: Yr.rangeToString(S), v: C });
}
e.hyperlinks = p;
}
const l = jn(n.commentsSpatial.all()), c = l.length;
if (c > 0) {
const p = [];
for (let _ = 0; _ < c; _++) {
const S = l[_], C = { ...S.value };
C.ref = Yr.rangeToString(S), p.push(C);
}
e.comments = p;
}
const h = this._resources.beginPersist();
try {
const p = this.getMovables().getItems(), _ = p.length;
if (_ > 0) {
const S = [];
for (let C = 0; C < _; C++) try {
const y = p[C].toJSON(h.toResourceId.bind(h));
y && S.push(y);
} catch (y) {
console.warn("Unable to persist movable", y);
}
S.length > 0 && (e.movables = S);
}
this._ownResources && (e.resources = await h.toJSONAsync());
} catch (p) {
console.warn(p);
} finally {
h.endPersist();
}
const d = jn(n.tableSpatial.all()), u = d.length;
if (u > 0) {
const p = [];
for (let _ = 0; _ < u; _++) {
const S = d[_].value.model.toJSON();
p.push(S);
}
e.tables = p;
}
const g = Array.from(n.conditionalModels.values()), m = g.length;
if (m > 0) {
const p = [];
for (let _ = 0; _ < m; _++) {
const S = g[_].model.toJSON();
p.push(S);
}
e.conditionals = p;
}
const f = await n.calcGraph.toJSON(!1);
if (f) {
const p = f.formulas;
p && (e.formulas = p);
const _ = f.dynamic;
_ && (e.dynamicArray = _);
const S = f.volatile;
S && (e.volatile = S);
}
return this._emitter.notify("onSave", { params: e }), e;
}
getStyles() {
return this._styles;
}
getResources() {
return this._resources;
}
getTransactions() {
return this._transactions;
}
getStrings() {
return this._strings;
}
_searchMovables(t) {
const e = t?.ignoreHidden ?? !1, n = t?.bounds, r = t?.fullyContained, o = this, s = t?.address ? this._rangeToCoords(t?.address) : this._entireCoords;
return this._getRangedEntries("movableSpatial", [s], { ignoreHidden: e, fullyContained: r, onEntry: (i) => {
if (t?.type && i.model.getContent().getType() !== t.type) return null;
let l = null;
if (e && (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(t, e) {
const n = this.getView().getMovableSelection();
if (!n || n.length === 0) return;
let r = "Movables";
if (n.length === 1) {
const s = n[0];
r = Qr(s.getContent().getType()) ?? "Drawing";
}
const o = this._beginCommit({ description: `${e} ${r}` });
try {
const s = n.length;
for (let i = 0; i < s; i++)
t(n[i]);
o.commit();
} catch (s) {
throw o.rollback(), s;
}
}
async _addMovable(t) {
if (!this.getProtection().isObjectsAllowed()) throw new ot(hd);
if (!t) throw new ot("No movable options provided");
if (this._closed) throw new Error(xe);
const e = {};
t?.type && (e.content = { type: t.type, json: t?.json }), t?.anchorType && (e.anchorType = t?.anchorType), t.bounds && (e.anchor = null);
const n = this._getState().movableSpatial, r = this._beginCommit({ description: t?.description ?? "Insert Drawing" }), o = this._createMovableEntry(e, n.size(), t.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 }), t.bounds && o.value.model.setBounds(t.bounds, t);
let h = null, d = null;
if (t?.autoSelect !== !1) {
h = { view: this.getView(), movableSelection: this.getView().getMovableSelection() };
let u = t?.autoSelect ?? !1;
u === !0 && (u = { autoFocus: !0, scrollIntoView: !0, addToSelection: !1 }), u && this.getView().selectMovables([o.value.model], u.addToSelection), d = (g) => ({ ...g, view: this.getView(), movableSelection: this.getView().getMovableSelection() });
}
return r.commit({ viewBefore: h, viewAfter: d }), this._emitterMovables.notify("onCollectionChange"), this._emitter.notify("onMovablesChange"), o.value.model;
}
async _addImage(t, e = { type: "picture" }) {
if (!t) throw new ot("An image must be provided as a string or a resource option.");
if (!this.getProtection().isObjectsAllowed()) throw new ot(hd);
const n = this._resources.add(t), r = await n.toBuffer(), o = await n.getType(), s = this._getBoundsAtCoords(this.getSelection().getRangesCoords()[0]), { naturalSize: i, asUrl: l } = await js.loadImageDetails(r, o);
URL.revokeObjectURL(l);
const c = { ...s, ...i, ...e?.bounds };
if (k.isNullOrUndefined(e?.bounds?.x) || k.isNullOrUndefined(e?.bounds?.y)) {
const d = fu(this.getMovables(), c, k.isNullOrUndefined(e?.bounds?.x), k.isNullOrUndefined(e?.bounds?.y));
c.x += d.x, c.y += d.y;
}
e?.bounds && e?.json?.lockAspect !== !1 && (k.isNullOrUndefined(e?.bounds.width) && k.isDefined(e?.bounds.height) && (c.width = c.height * i.width / i.height), k.isNullOrUndefined(e?.bounds.height) && k.isDefined(e?.bounds.width) && (c.height = c.width * i.height / i.width));
const h = { ...e?.json, resId: 0 };
return await this._addMovable({ anchorType: ve.Type.OneCell, description: "Insert Image", ...e, bounds: c, type: "picture", json: h, fromResourceId: (d) => d !== 0 ? (console.warn("received an unexpected resourceId", d), null) : n });
}
getTables() {
return this._tables;
}
getConditionals() {
return this._conditionals;
}
getMovables() {
return this._movables;
}
_doPerfTest(t = 1e7, e = !1) {
const n = Array.from({ length: t }, (l, c) => c);
let r, o;
r = performance.now(), e && console.profile("nativeArray");
const s = [t];
for (let l = 0; l < t; l++) s.push(l);
e && console.profileEnd("nativeArray"), window.noLoseArray = s, o = performance.now(), console.log(`NativeArray: ${t} records in ${o - r} milliseconds`), r = performance.now(), e && console.profile("mixedType");
const i = Ii.fromArray(n);
e && console.profileEnd("mixedType"), window.noLoseList = i, o = performance.now(), console.log(`MixedTypedList: ${t} records in ${o - r} milliseconds`);
}
_validateOrRemoveOverlaps(t, e, n = null, r = !1) {
const o = this;
e !== "merge" && Qh(this._getMerges([t]), t, (c, h) => {
if (h || !r) throw new ot(dd(e));
o._unmerge([c]);
});
const s = [], i = this.getTables().getItems({ address: t }), l = i.length;
for (let c = 0; c < l; c++) {
const h = i[c];
n !== h && s.push(h.getAnchorCoords());
}
Qh(s, t, (c, h, d) => {
if (h || !r) throw new ot(dd(e));
i[d].delete();
});
}
_addTable(t, e) {
let n = this._rangeToCoords(t, () => ["objects"]);
const r = this._entireCoords;
let o = e?.hasHeader;
if (n.rowStart === n.rowEnd) {
if (n.rowEnd === r.rowEnd) throw new ot("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 = Bd(this, n)?.options?.hasHeader ?? !1);
const s = Bt([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 }], F.Orientation.Row), n = { ...n, rowEnd: n.rowEnd + 1 });
const h = { ...e?.json, ref: n };
this._validateOrRemoveOverlaps(n, "table", null, !0), h.styleOptions = e?.json?.styleOptions ?? {}, h.styleOptions.name === void 0 && (e?.styleName ? h.styleOptions.name = e.styleName : e?.styleName === void 0 && (h.styleOptions.name = this._styles.getDefaultTableStyle().getName()));
const d = e?.isLoad;
d !== !0 && (h.filter === void 0 && (h.filter = {}), h.sort === void 0 && (h.sort = {}));
const u = this._createTableEntry(h, o && !d), g = this._getState(), m = g.tableSpatial.clone();
m.insert(u);
const f = g.tableMapModel, p = new Map(f), _ = u.value.model;
p.set(_, u);
const S = g.tableMapName, C = new Map(S);
C.set(_.getName().toLocaleLowerCase(), _), e?.clearFormatting && this.getRange(n).getStyle().update(null), c = u.value.model, this._updateState({ tableSpatial: m, tableMapModel: p, tableMapName: C }), this._emitter.notify("onTablesChange"), d || this._autoFit([c.getHeaderRange().getCoords()], { expandOnly: !0 });
const y = Bt([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(t, e) {
const n = this._rangesToCoords(t, () => ["objects"]), r = e?.autoSelect ? Bt(n) : null, o = [...n], s = this._beginCommit({ description: e?.description ?? "Insert Conditional" });
let i = null;
try {
const l = { ...e, ref: o }, c = this._getState(), h = c.conditionalSpatial.clone(), d = new Map(c.conditionalModels), u = this._createConditionalEntries(l, h, d);
this._updateState({ conditionalSpatial: h, conditionalModels: d }), i = u, s.commit({ viewBefore: { view: this.getView(), selection: r, ranges: o }, viewAfter: { view: this.getView(), selection: r, ranges: o } }), this._autoSelect(e?.autoSelect, r);
} catch (l) {
throw s.rollback(), l;
}
return i;
}
createTemporaryCell(t, e = null) {
return t?.createTemporaryCell ? t : (e ? this.getRange(e).getCell() : this._emptyCell).createTemporaryCell(t);
}
_getBoundsAtCoords(t) {
const e = this._rowHeaders, n = this._colHeaders, r = n.findOffset(t.colStart), o = e.findOffset(t.rowStart);
return { x: r, y: o, width: n.findOffset(t.colEnd + 1) - r, height: e.findOffset(t.rowEnd + 1) - o };
}
_getCoordsAtBounds(t) {
const e = this._rowHeaders, n = this._colHeaders;
return { colStart: n.findIndex(t.x), rowStart: e.findIndex(t.y), colEnd: n.findIndex(t.x + t.width), rowEnd: e.findIndex(t.y + t.height) };
}
getRangeAtBounds(t, e) {
if (!t) throw new Qe();
const n = this._getCoordsAtBounds(t);
return this.getRange(n, e);
}
_getVisible(t, e) {
if (t.length === 0) return t;
const n = new Nt();
n.load(t);
const r = e?.orientations ?? F.Orientations.Both, o = (i, l) => {
const c = n.search(i), h = c.length;
for (let d = 0; d < h; d++) {
const u = c[d], g = Tl(u, i, l);
n.remove(u), n.load(g);
}
}, s = this._cellOptions.maxCoords;
if (r === F.Orientations.Both || r === F.Orientations.Row) {
const i = this._rowHeaders, l = t.length;
for (let c = 0; c < l; c++) {
const h = t[c];
i.getRange({ min: h.rowStart, max: h.rowEnd }).forEachSpan((d, u) => {
if (d !== 0) return;
const g = u.getCoords();
o({ colStart: s.colStart, rowStart: g.min, colEnd: s.colEnd, rowEnd: g.max }, F.Orientation.Row);
});
}
}
if (r === F.Orientations.Both || r === F.Orientations.Column) {
const i = this._colHeaders, l = t.length;
for (let c = 0; c < l; c++) {
const h = t[c];
i.getRange({ min: h.colStart, max: h.colEnd }).forEachSpan((d, u) => {
if (d !== 0) return;
const g = u.getCoords();
o({ colStart: g.min, rowStart: s.rowStart, colEnd: g.max, rowEnd: s.rowEnd }, F.Orientation.Column);
});
}
}
return n.all();
}
_hasRangedEntries(t, e) {
const n = this._getState();
if (!n) return k.EmptyArray;
const r = n[t];
if (!r) throw new ot(`Invalid range key ${t}`);
return !(!r || r.isEmpty()) && r.has(e);
}
_getRangedEntries(t, e, n) {
if (e.length === 0) return k.EmptyArray;
const r = n?.ignoreHidden ?? !1, o = n?.fullyContained ?? !1, s = n?.onEntry ?? null, i = this._getState();
if (!i) return k.EmptyArray;
const l = i[t];
if (!l) throw new ot(`Invalid range key ${t}`);
if (!l || l.isEmpty()) return k.EmptyArray;
const c = /* @__PURE__ */ new Set(), h = (p) => {
const _ = p.length;
for (let S = 0; S < _; S++) {
const C = p[S];
c.add(C);
}
}, d = e.length;
for (let p = 0; p < d; p++) {
const _ = e[p];
if (r) {
if (r === !0) {
const S = { min: _.colStart, max: _.colEnd }, C = { min: _.rowStart, max: _.rowEnd };
this._rowHeaders.getRange(C).forEachVisibleSpan((y, E) => {
this._colHeaders.getRange(S).forEachVisibleSpan((w, b) => {
h(l.search({ colStart: w, rowStart: y, colEnd: b, rowEnd: E }, o));
}, Ps);
}, Ps);
} else if (r === F.Orientation.Column) {
const S = { min: _.colStart, max: _.colEnd };
this._colHeaders.getRange(S).forEachVisibleSpan((C, y) => {
h(l.search({ colStart: C, rowStart: _.rowStart, colEnd: y, rowEnd: _.rowEnd }, o));
}, Ps);
} else if (r === F.Orientation.Row) {
const S = { min: _.rowStart, max: _.rowEnd };
this._rowHeaders.getRange(S).forEachVisibleSpan((C, y) => {
h(l.search({ colStart: _.colStart, rowStart: C, colEnd: _.colEnd, rowEnd: y }, o));
}, Ps);
}
} else h(l.search(_, o));
}
if (c.size === 0) return k.EmptyArray;
const u = Array.from(c.values()), g = n?.sort;
g && u.sort(L.createRangeComparator(g.orientation, g.reverse));
let m = [];
const f = u.length;
for (let p = 0; p < f; p++) {
let _;
_ = void 0, s && (_ = s(u[p].value, u[p])), _ === void 0 && (_ = u[p].value), _ !== null && m.push(_);
}
return m || (m = k.EmptyArray), m;
}
_processAnchorShift(t) {
let e = t.after;
const n = L.sanitizeRange(t.after), r = L.sanitizeRange(t.before);
t.after && this._validateCoords(n, "We can't insert cells because this would push items off the end of the worksheet.");
const o = t.before.value.processShiftCallback?.({ ...t, after: n, before: r });
return o && ($o(o, n) || (e || (e = t.before), e = { ...e, ...o })), e;
}
_processListenerShift(t, e, n, r) {
if (r.isSplit || r.before.value.options.ignoreShifts) return [r.before];
let o = null;
r.after && (o = L.intersectRanges(L.sanitizeRange(r.after), this._entireCoords), r.after, o.colStart, o.rowStart, o.colEnd, o.rowEnd);
const s = r.before.value, i = s.id, l = t.get(i), c = { ...l }, h = [...l.ranges];
c.ranges = h, h[s.offset] = o ? { ...h[s.offset], ...o } : null, t.set(i, c);
const d = n.get(i);
e.set(i, { beforeState: d, afterState: c });
}
delete() {
if (this._closed) return;
try {
this._emitter.notify("onBeforeDelete");
} catch (s) {
throw s instanceof Error ? s : new ot(s.message ?? "Unable to delete.");
}
const t = this._beginCommit({ description: `Delete Sheet '${this.getName()}'` }), e = this._getState();
let n = e.rangeListenerSpatial, r = e.rangesListenerMap;
const o = /* @__PURE__ */ new Map();
n = n.shift({ range: this._entireCoords, direction: F.Direction.Left, cloneIfUpdate: n === e.rangeListenerSpatial, onShift: (s) => {
r === e.rangesListenerMap && (r = new Map(r)), this._processListenerShift(r, o, e.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 });
}), t.commit({ viewAfter: (s) => ({ ...s, view: this.getView(), selection: this.getSelection().getCoords(), listeners: o }) });
}
doBatch(t, e) {
const n = this;
return e = typeof e == "string" ? { description: e } : { description: "Update Sheet", ...e }, this._transactions.doBatch(t, e, (r, o) => {
if (r.getDepth() === 0 && (n._lastTransactionUUID = r.getId(), e?.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 Iu(void 0, this._options.readonly);
const t = this._getState().tableMapModel.keys();
for (const e of t) e.close();
this._searchMovables().forEach((e) => {
e.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(t) {
if (this._closed) throw new Error(xe);
return this._beginCommit(typeof t == "string" ? { description: t } : t);
}
_getState() {
return this._closed ? null : this._transactions.getState(this);
}
_beginCommit(t) {
const e = this;
return this._transactions.beginCommit(t, (n) => {
n.getDepth() === 0 && (e._lastTransactionUUID = n.getId());
});
}
_updateState(t) {
if (!t) return;
this._lastGetRangeRead = null;
const e = this._transactions.beginCommit();
let n;
try {
n = e.updateState(this, t), e.commit();
} catch (r) {
throw e.rollback(), r;
}
return n;
}
_addEvent(t, e) {
const n = this.getTransactions().getPendingView();
if (!n) return;
let r = n.events;
if (r || (r = {}, n.events = r), t === "address") {
let o = r.address;
if (o || (o = /* @__PURE__ */ new Map(), r.address = o), typeof e == "string") o.set(e, null);
else {
const s = e;
if (s.options.ignoreAddressChanges) return;
o.set(s.uuid, e);
}
} else if (t === "data") if (typeof e == "string") {
let o = r.dataListeners;
o || (o = /* @__PURE__ */ new Map(), r.dataListeners = o), o.set(e, null);
} else {
let o = r.data;
o || (o = [], r.data = o), o.push(e);
}
}
_getScalar(t, e, n = !1) {
const r = this._getState();
let o;
if (o === void 0 && (o = r.cellValuesGrid.getValueAt(t, e)), o === void 0) return null;
let s = o;
if (n && typeof s == "number") {
let i = !1;
qe.colStart = e, qe.rowStart = t, qe.colEnd = e, qe.rowEnd = t;
const l = this._lastValueRead, c = this._lastValueRead.range;
if (c && L.isRangeWithinRange(qe, c)) i = l.isDateOrTime;
else {
const h = r.directStyleSpatial.search(qe)[0];
if (h) {
const d = h.value.getPropertiesAt(t, e, s), u = d?.numberFormat;
u && (i = os(u) || Wi(u)), l.range = h, l.isDateOrTime = i;
} else l.range = null;
i && (s = oo(s, this._isDate1904));
}
}
return s;
}
_getStyle(t, e) {
let n;
if (e) n = { colStart: e.cell.colIndex, rowStart: e.cell.rowIndex, colEnd: e.cell.colIndex, rowEnd: e.cell.rowIndex };
else {
const l = t[0];
n = { colStart: l.colStart, rowStart: l.rowStart, colEnd: l.colStart, rowEnd: l.rowStart };
}
const r = this;
let o = this._cellOptions;
o = { ...o, styleUpdater: (l, c) => (r._updateStyles(t, l, c), r._getStyle(t, e)) }, ku.length = 0;
const s = ku;
this._collectRanges(n, s);
const i = Ld(s);
return Vr(0, n, i, o);
}
_initState() {
const t = this, e = () => {
t._lastCellDecoded.address = null, t._lastCellSelected.coords = null, t._lastCellRead.coords = null, t._lastValueRead.range = null, t._lastGetRangeRead = {}, t._lastUsedCoordsRead.coords = null, t._lastActiveRead.selection = null, t._lastRangeRead.address = null;
};
this._transactionsRemoveListener = this._transactions.addStateListener(this, { onBeforeCommitStart(m, f, p) {
if (!t._initializing && !f?.skipProtectionCheck && t.getProtection().isLocked())
throw new ot(bs);
}, async onBeforeCommitEnd(m, f, p) {
if (f?.ranges) {
const _ = { isDataChange: !0, isTransactional: !0, timeStamp: p.getTimestamp(), trigger: "setCells" }, S = m.rangeListenerSpatial, C = m.rangesListenerMap;
t._notifyRangeListeners(S, C, f.ranges, _);
}
if (f?.listeners) {
const _ = { isDataChange: !1, isTransactional: !0, timeStamp: p.getTimestamp(), trigger: "shiftCells" }, S = m.rangeListenerSpatial, C = m.rangesListenerMap;
t._notifyRangeListeners(S, C, f.ranges, _);
}
}, async onRestoreOrRevert(m, f, p, _) {
if (e(), t._calculateFull(), f && (f.view === t.getView() && f.selection && t._autoSelect(f.selectOptions ?? !0, f.selection), f.movableSelection && t.getView().selectMovables(f.movableSelection)), t._emitter.notify("onInvalidated"), t._emitterMovables.notify("onInvalidated"), t._notifyUsedRangeChange(), t._rangesListenerMap.size > 0) {
const S = { isDataChange: !0, isTransactional: !1, timeStamp: p.getTimestamp(), isUndo: _, trigger: "invalidate" }, C = m.rangeListenerSpatial, y = m.rangesListenerMap, E = /* @__PURE__ */ new Set();
y.forEach((w, b) => {
const v = w.id;
if (E.has(v)) return;
const I = w.ranges;
I && (E.add(v), t._notifyRangeListeners(C, y, I, S));
});
}
}, async onAfterStateChange(m, f, p, _, S) {
e(), f && p.getId() !== t._lastTransactionUUID && f.view === t.getView() && f.selection && (_ || S) && t._autoSelect(f.selectOptions ?? !0, f.selection), t._lastTransactionUUID = p.getId(), f?.merges && t._notifyMergeChange();
const C = t._rangesListenerSorted;
if (C.size > 0) {
t._notifyUsedRangeChange();
const y = /* @__PURE__ */ new Set(), E = m.rangesListenerMap2, w = { isTransactional: !1, timeStamp: p.getTimestamp() };
if ((S || _) && (w.trigger = "restore", t._notifyAddressListeners(E, E, y, w), C.size > E.size)) {
const v = C.values();
let I = v.next(), x = !1;
for (; !x && !I.done; ) {
const R = I.value;
x = E.has(R.uuid), x || (R.notify(w, "#N/A"), I = v.next());
}
}
const b = f?.events;
b && (b.address && (w.trigger = "address", t._notifyAddressListeners(E, b.address, y, w)), b.dataListeners && (w.trigger = "data", t._notifyAddressListeners(E, b.dataListeners, y, w)), b.data && (w.trigger = "data", t._notifyDataListeners(m.rangesListenerSpatial2, m.rangesListenerMap2, b.data, y, w)));
}
if (f && !f.initial && (!f.calculationSideEffect && f.ranges && m.calcGraph.calculate(), f.ranges)) {
t._notifyUsedRangeChange();
const y = t._rangesListenerMap;
if (y.size > 0) {
const E = { isDataChange: !0, isTransactional: !1, timeStamp: p.getTimestamp(), isUndo: _, trigger: "setCells" };
t._notifyRangeListeners(t._rangeListenerSpatial, y, f.ranges, E);
}
}
}, onClose() {
const m = t._getState();
m && m.movableSpatial.clear();
} });
const n = new Dw({ sheet: this }), r = { onChange() {
t._emitter.notify("onSelectionChange");
} }, o = n.addListeners(r, { transactional: !1 });
this._rangeSelection = n, this._rangeSelectionRemoveListener = o;
const s = (m) => {
const f = t._getState();
if (!f) return;
const p = f.movableSpatial, _ = m.length;
for (let S = 0; S < _; S++) {
const C = p.search(m[S]), y = C.length;
for (let E = 0; E < y; E++)
C[E].value.processLayoutCallback?.();
}
t._emitter.notify("onLayoutChange");
};
this._colHeadersListener = { onSizesChange: (m, f) => {
const p = [];
if (f) {
const _ = f.length;
for (let S = 0; f && S < _; S++) {
const C = { colStart: f[S].min, rowStart: t._entireCoords.rowStart, colEnd: t._entireCoords.colEnd, rowEnd: t._entireCoords.rowEnd };
p.push(C);
}
}
s(p);
} }, this._rowHeadersListener = { onSizesChange: (m, f) => {
const p = [];
if (f) {
const _ = f.length;
for (let S = 0; S < _; S++) {
const C = f[S], y = { colStart: t._entireCoords.colStart, rowStart: C.min, colEnd: t._entireCoords.colEnd, rowEnd: t._entireCoords.rowEnd };
p.push(y);
}
}
s(p);
} };
let i = /* @__PURE__ */ new Set();
const l = { onTopLeftChange() {
t._emitter.notify("onTopLeftChange");
}, onFreezeSplitChange() {
t._emitter.notify("onFreezeSplitChange");
}, onRangeSelectionChange() {
const m = t.getSelection().getCoords();
t._rangeSelection.updateCoords(m);
}, onMovableSelectionChange(m) {
const f = m.getMovableSelection(), p = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Set(), S = t._getState().movableMapModel, C = f.length;
for (let y = 0; y < C; y++) {
const E = f[y];
i.has(E) ? i.delete(E) : p.set(E, y), _.add(E);
}
i.forEach((y) => {
S.get(y)?.value.processSelectionCallback(!1, !1);
}), p.forEach((y, E) => {
S.get(E)?.value.processSelectionCallback(!0, y === 0);
}), i = _, t._emitter.notify("onMovableSelectionChange");
}, onAnyChange() {
t._defaultColWidthCache = 0, t._defaultRowHeightCache = 0, t._defaultFontBoundsCache = null, t._emitter.notify("onLayoutChange"), t._emitter.notify("onViewChange");
} }, c = new cl({ sheet: this });
this._view = c, this._clearState(), this._viewRemoveListener = c.addListeners(l, { transactional: !1 }), this._viewListener = l, this._colHeadersRemoveListener?.(), this._colHeaders = new Cu({ sheet: t, orientation: F.Orientation.Column, transactions: this._transactions, isProtected: () => !t._initializing && !t.getProtection().isFormatColumnsAllowed(), getTextAt: (m) => {
const f = this.getView().getColumnHeaderStyle();
return f === on.HeaderTextStyle.A1 ? Au(m) : f === on.HeaderTextStyle.Zero ? Ru(m) : f === on.HeaderTextStyle.One ? Mu(m) : void 0;
}, defaultSize: () => this._defaultColWidth(), scaleFactor: () => {
const m = this.getView().isShowFormulas() ? 2 : 1;
return Math.round(this._defaultFontDims().width) * m;
}, maxSize: () => 255, maxSheetCoords: () => t._entireCoords, setContainerShiftedCallback: (m) => {
this._colHeadersShiftCallback = m;
} }), this._colHeadersRemoveListener = this._colHeaders.addListeners(this._colHeadersListener, { transactional: !0 }), this._rowHeadersRemoveListener?.();
const h = dt.getDeviceScale();
this._rowHeaders = new Cu({ sheet: t, orientation: F.Orientation.Row, transactions: this._transactions, isProtected: () => !t._initializing && !t.getProtection().isFormatRowsAllowed(), getTextAt: (m) => {
const f = this.getView().getRowHeaderStyle();
return f === on.HeaderTextStyle.One ? Mu(m) : f === on.HeaderTextStyle.Zero ? Ru(m) : f === on.HeaderTextStyle.A1 ? Au(m) : void 0;
}, defaultSize: () => this._defaultRowHeight(), scaleFactor: () => h, minSize: () => 0, maxSize: () => 409, maxSheetCoords: () => t._entireCoords, setContainerShiftedCallback: (m) => {
this._rowHeadersShiftCallback = m;
} }), this._rowHeadersRemoveListener = this._rowHeaders.addListeners(this._rowHeadersListener, { transactional: !0 }), this._defaultFontBoundsCache = null, this._defaultColWidthCache = 0, this._defaultRowHeightCache = 0;
const d = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0 }, u = [d], g = { ignoreHidden: !0, sort: { orientation: F.Orientation.Column, reverse: !1 } };
this._cellOptions = { resolveRange: (m) => {
if (m === null) return this._createRange(null, void 0, "temporary cell");
const f = this._rangesToCoords(m);
return this._createRange(f[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: (m, f, p = !1) => {
d.colStart = p ? f : m.colIndex + 1, d.rowStart = m.rowIndex, d.colEnd = p ? m.colIndex - 1 : f, d.rowEnd = m.rowIndex, g.sort.reverse = p;
const _ = t._getRangedEntries("contentfulSpatial", u, g);
if (!_ || _.length === 0) return f;
const S = _[0], C = p ? S.getState().colStart : S.getState().colEnd;
return p ? Math.min(C + 1, m.colIndex) : Math.max(C - 1, m.colIndex);
}, styleUpdater: (m, f, p) => {
const _ = [p];
return t._updateStyles(_, m, f), t._getStyle(_);
}, opener: async (m, f, p, _) => {
if (m.startsWith("#")) {
m = m.substring(1);
const S = this._rangesToCoords(m);
return await this._autoSelect(f ?? !0, Bt(S)), !0;
}
return window.open(m, p ?? "_blank", _), !0;
} }, this._emptyCell = new zS(this._cellOptions);
}
_clearState() {
this._lastGetRangeRead = null, this._lastCellDecoded.address = null, this._lastCellSelected.coords = null, this._lastCellRead.coords = null, this._protectionRemoveListener?.(), this._protection = new Iu(void 0, this._options.readonly), this._protectionRemoveListener = this._protection.addListeners({ onChange() {
if (t._closed) throw new Error(xe);
t._getState().movableMapModel.forEach((i) => {
i.value.processProtectionCallback?.();
}), t._getState().tableMapModel.forEach((i) => {
i.value.processProtectionCallback?.();
}), t._emitter.notify("onProtectionChange");
} }), this._stylesRemoveListener?.();
const t = this;
this._stylesRemoveListener = this._styles.addListeners({ onAnyChange() {
t._defaultColWidthCache = 0, t._defaultRowHeightCache = 0, t._defaultFontBoundsCache = null, t._emitter.notify("onLayoutChange"), t._emitter.notify("onStyleChange");
const i = t._entireCoords;
t._autoFit([i], { orientations: F.Orientations.Both, skipCustomSize: !0 });
} }), this._view.clear(!1), this._rangeListenerSpatial = new Nt(), this._rangesListenerMap = /* @__PURE__ */ new Map(), this._rangesListenerSorted = new xt();
const e = (i) => {
const l = t._getState().rangesListenerSpatial2;
if (l.isEmpty()) return;
const c = i.length;
for (let h = 0; h < c; h++) {
const d = i[h], u = l.search(d), g = u.length;
for (let m = 0; m < g; m++) {
const f = u[m].value.groupId;
t._addEvent("data", f);
}
}
}, n = this._entireCoords, r = n.rowEnd, o = n.colEnd, s = this._calculation._createGraph({ onCalculated(i) {
t._realizeCalcedValues(i);
}, getEntireCoords: () => t._entireCoords, getSheetName: () => t.getName() });
s.addListeners({ onStart(i) {
}, onInvalidate: () => {
} }), this._updateState({ rangesListenerSpatial2: new Nt({ updateEntryOptions: { onShifted: (i) => {
let l = t._getState().rangesListenerMap2;
if (l.size === 0) return;
l = new Map(l);
const c = i.length;
for (let h = 0; h < c; h++) {
const d = i[h], u = d.value.groupId;
let g = l.get(u);
g = g.processShift(d), t._addEvent("address", g), l.set(u, g);
}
t._updateState({ rangesListenerMap2: l });
}, onRemoved: (i) => {
let l = t._getState().rangesListenerMap2;
if (l.size === 0) return;
l = new Map(l);
const c = i.length;
for (let h = 0; h < c; h++) {
const d = i[h], u = d.value.groupId;
let g = l.get(u);
g = g.processRemove(d), t._addEvent("address", g), l.set(u, g);
}
t._updateState({ rangesListenerMap2: l });
} } }), rangesListenerMap2: /* @__PURE__ */ new Map(), cellValuesGrid: new hn({ orientation: this._isDataColumn ? F.Orientation.Column : F.Orientation.Row }), formulaSpatial: new Nt(), spillSpatial: new Nt(), pendingSpatial: new Nt(), calcErrorsSpatial: new Nt(), calcGraph: s, directStyleSpatial: new Nt({ updateEntryOptions: { isMergeOnShift: !0, isTrailingEdge: !0, onUpdated: e, onRemoved: e } }), continuousFillSpatial: new Nt({ updateEntryOptions: { isMergeOnShift: !0, isTrailingEdge: !0 } }), conditionalModels: /* @__PURE__ */ new Map(), conditionalSpatial: new Nt({ updateEntryOptions: { onGroupUpdate(i, l) {
let c = t._getState().conditionalModels, h = c.get(l);
if (!h) return;
c = new Map(c);
const d = h.spatials;
h = { ...h }, h.spatials = i, c.set(l, h), t._updateState({ conditionalModels: c }), h.processCoordsChange({ before: d, after: h.spatials });
} } }), mergeSpatial: new Nt({ updateEntryOptions: { getShifted: (i, l) => l ? (l.value = new Eu(L.sanitizeRange(l), i.value._tvTl), l) : null, getSplit(i, l) {
throw new ot("We can't insert through merges. Unmerge and try again.");
}, onUpdated: e, onRemoved: e } }), movableMapModel: /* @__PURE__ */ new Map(), movableSpatial: new Nt({ updateEntryOptions: { getShifted(i, l, c) {
const h = i.value.processShiftCallback?.(c);
let d = null;
const u = new Map(t._getState().movableMapModel), g = i.value.model;
return h ? (d = { ...h, value: { ...i.value } }, u.set(g, d)) : u.delete(g), t._updateState({ movableMapModel: u }), d;
} } }), hyperlinkSpatial: new Nt({ updateEntryOptions: { isSplitOnExpand: !0, isMergeOnShift: !0 } }), commentsSpatial: new Nt({ updateEntryOptions: { isSplitOnExpand: !0, isMergeOnShift: !0, onUpdated: e, onRemoved: e } }), tableMapModel: /* @__PURE__ */ new Map(), tableMapName: /* @__PURE__ */ new Map(), tableSpatial: new Nt({ updateEntryOptions: { getShifted(i, l, c) {
const h = new Map(t._getState().tableMapModel), d = i.value.model, u = i.value.processShiftCallback?.(c);
let g = null;
return u ? (g = { ...u, value: { ...l.value } }, h.set(d, g)) : h.delete(d), t._updateState({ tableMapModel: h }), g;
} } }), filter: null, sort: null, rangeListenerSpatial: new Nt(), rangesListenerMap: /* @__PURE__ */ new Map(), contentfulSpatial: new Nt({ updateEntryOptions: { isSplitOnExpand: !0, isMergeOnShift: !0, onShifted: (i) => {
const l = t._getState().rangesListenerSpatial2;
if (l.size() === 0) return;
const c = i.length;
for (let h = 0; h < c; h++) {
const d = i[h], u = l.search({ colStart: d.colStart, rowStart: d.rowStart, colEnd: o, rowEnd: r }), g = u.length;
for (let m = 0; m < g; m++) {
const f = u[m].value.groupId;
t._addEvent("data", f);
}
}
}, onRemoved: e, onUpdated: e } }), unlockSpatial: new Nt({ updateEntryOptions: { isMergeOnShift: !0 } }), deleted: !1 }), this._defaultFontBoundsCache = null, this._defaultColWidthCache = null, this._defaultRowHeightCache = null;
}
_createTableEntry(t, e = !1) {
const n = { model: null, processShiftCallback: null, processDeleteCallback: null, processProtectionCallback: null, currentName: null, removeListener: null };
let r = null;
r = typeof t.ref == "string" ? Pe(t.ref, this._entireCoords) : t.ref;
const o = { ...r, value: n }, s = this, i = () => n.model ? s._getState().tableMapModel?.get(n.model) : o, l = (d, u) => !(!L.isEqualRanges(d, u) || d.value.model !== u.value.model), c = { transactions: this._transactions, sheet: this, names: this._names, readSheetHeader: e, json: t, maxRangeCoords: this._entireCoords, setNameOnContainer(d) {
const u = i().value;
if (!u.currentName || u.currentName.toLowerCase() === d.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, p = d.toLocaleLowerCase();
if (f.has(p)) throw new ot(((S) => `Name must be unique: '${S}' is already in use.`)(d));
const _ = new Map(f);
_.delete(u.currentName), u.currentName = p, _.set(p, u.model), s._updateState({ tableMapName: _ }), m.commit();
} catch (f) {
throw m.rollback(), f;
}
}, setContainerCoords(d, u) {
if (!d) return;
const g = s._rangeToCoords(d, () => ["objects"]), m = i();
if (!m) return;
const f = m.value.model;
s._validateOrRemoveOverlaps(g, "table", f);
const p = s._beginCommit({ description: u?.description ?? "Resize Table" }), _ = s._getState(), S = _.tableSpatial.clone(), C = _.tableMapModel, y = new Map(C);
S.remove(m, l);
const E = { ...m, ...g };
return S.insert(E), y.set(E.value.model, E), s._updateState({ tableSpatial: S, tableMapModel: y }), p.commit({ viewAfter: { view: s.getView(), selection: Bt([h.getAnchorCoords()]) } }), g;
}, deleteFromContainer(d) {
const u = i();
if (!u) return;
const g = u.value.model, m = d?.description ?? `Delete Table '${g.getName()}`;
s._protectionCheck(() => ["objects"], void 0, m);
const f = s._beginCommit({ description: m }), p = s._getState(), _ = p.tableSpatial.clone(), S = p.tableMapModel, C = new Map(S), y = p.tableMapName, E = new Map(y);
_.remove(u, l), C.delete(g), E.delete(g.getName().toLocaleLowerCase()), u.value.processDeleteCallback?.(), s._updateState({ tableSpatial: _, tableMapModel: C, tableMapName: E }), s._emitter.notify("onTablesChange"), s._emitter.notify("onLayoutChange"), f.commit({ viewAfter: { sheet: s, view: s.getView(), selection: Bt([g.getAnchorCoords()]) } });
}, setContainerDeleteCallback(d) {
const u = i()?.value ?? n;
u && (u.processDeleteCallback = d, u.removeListener?.());
}, isProtected: () => !s._initializing && s.getProtection().isLocked(), setContainerProtectionCallback(d) {
(i()?.value ?? n).processProtectionCallback = d;
}, setContainerShiftCallback(d) {
(i()?.value ?? n).processShiftCallback = d;
}, processTableUpdate() {
s._notifyUsedRangeChange();
}, initialAnchor: r }, h = new JS(c);
return o.value.model = h, o.value.removeListener = h.addListeners({ onStyleChange(d) {
s._emitter.notify("onStyleChange");
}, onDelete(d) {
s._emitter.notify("onStyleChange");
} }, { transactional: !1 }), o.value.currentName = h.getName().toLocaleLowerCase(), o;
}
_createConditionalEntries(t, e, n) {
const r = "Conditional Format", o = () => ["objects"], s = t ?? {};
let i = null;
const l = this._entireCoords;
if (typeof s.ref == "string") {
i = [];
const _ = s.ref.split(","), S = _.length;
for (let C = 0; C < S; C++) {
const y = Pe(_[C], l);
y && i.push(y);
}
} else i = Array.isArray(s.ref) ? s.ref : [s.ref];
const c = this, h = k.uuidV4(), d = { model: null, removeListener: null, processCoordsChange: null, spatials: null };
n.set(h, d);
const u = () => d.model ? c._getState().conditionalModels.get(h) : d;
let g = (_) => (console.log("default createSpatialEntry", _), null);
const m = (_, S, C) => {
if (!d.model) return void (i = _);
let y = S.spatials;
if (y) {
const w = y.length;
for (let b = 0; b < w; b++) C.remove(y[b]);
}
let E = [];
if (_) {
const w = _.length;
for (let b = 0; b < w; b++) {
const v = _[b];
E.push({ ...v, value: g(v) });
}
E.length > 0 && C.insertGroup(E, h);
}
S.spatials = E;
}, f = () => {
const _ = u().spatials ?? i;
return _ ? c.getRanges(_) : null;
};
var p;
return d.model = (p = { sheet: c, transactions: c._transactions, json: t, type: "conditional", setOnContainerCoordsChange: (_) => {
u().processCoordsChange = _;
}, setCreateSpatial(_) {
g = _;
}, setContainerRanges: (_, S) => {
const C = c._rangesToCoords(_, o);
if (!d.model) return i = C, C && C.length > 0 ? c.getRanges(C) : null;
const y = c._beginCommit({ description: S?.description ?? `Set ${r} Ranges` });
let E = Bt(C);
try {
const w = c._getState();
let b = w.conditionalSpatial;
b = b.clone();
let v = w.conditionalModels;
v = new Map(v);
let I = u();
I = { ...I }, v.set(h, I), m(C, I, b), c._updateState({ conditionalSpatial: b, conditionalModels: v }), y.commit({ viewBefore: { view: c.getView(), selection: Bt(f()?.getCoords()) }, viewAfter: { view: c.getView(), selection: E } }), c._autoSelect(S?.autoSelect, E);
} catch (w) {
throw y.rollback(), w;
}
return C && C.length > 0 ? c.getRanges(C) : null;
}, getContainerRanges: f, deleteFromContainer(_) {
let S = u();
const C = c._beginCommit({ description: _?.description ?? `Set ${r} Ranges` }), y = _?.autoSelect ? Bt(S.spatials) : void 0;
try {
const E = c._getState();
let w = E.conditionalSpatial;
w = w.clone();
let b = E.conditionalModels;
b = new Map(b), S = { ...S }, m(null, S, w), b.delete(h), c._updateState({ conditionalSpatial: w, conditionalModels: b }), this._commitAndAutoSelect(C, y, _?.autoSelect);
} catch (E) {
throw C.rollback(), E;
}
}, isReadOnly: () => !1, setContainerReadOnlyCallback(_) {
} }, new Lw({ ...p, createDescription: `New ${r}` })), d.removeListener = d.model.addListeners({ onAnyChange(_) {
c._emitter.notify("onStyleChange");
} }, { transactional: !1 }), m(i, d, e), d.model;
}
_createMovableEntry(t, e, n) {
let r = null;
if (t?.anchor) r = { colStart: t.anchor.tl?.c ?? 0, rowStart: t.anchor.tl?.r ?? 0, colEnd: t.anchor.br?.c ?? 0, rowEnd: t.anchor.br?.r ?? 0 }, t.anchor.br?.x || (r.colEnd -= 1), t.anchor.br?.y || (r.rowEnd -= 1);
else {
const y = this.getSelection().getRangesCoords()[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: e }, s = { ...r, value: o }, i = () => o.model ? h._getState()?.movableMapModel?.get(o.model) : s, l = (y, E) => !(!L.isEqualRanges(y, E) || y.value.model !== E.value.model), c = (y, E, w = !0) => {
if (u) return;
const b = i();
if (!b) return;
const v = E ?? "Update Drawing";
h._protectionCheck(() => ["objects"], void 0, v);
const I = h._beginCommit({ description: v }), x = h._getState()?.movableSpatial, R = x.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 O = [...T?.movableSelection ?? []];
return O.push(s.value.model), { ...T, view: this.getView(), movableSelection: O };
}
} }));
}, h = this, d = t.content.type;
let u = !0;
const g = (y, E, w, b) => {
const v = w.all().sort((D, z) => D.value.zIndex - z.value.zIndex), I = E.value.zIndex;
if ((y = Math.max(0, Math.min(v.length - 1, y))) === I) return !1;
const x = [], R = [], A = [], M = I < y, T = (D) => {
const z = v[D];
x.push(z);
const B = { ...z, value: { ...z.value, zIndex: M ? D - 1 : D + 1 } };
z.value.zIndex === I && (B.value.zIndex = y), R.push(B), b.set(B.value.model, B), A.push(B);
};
if (M) for (let D = I; D <= y; D++) T(D);
else for (let D = I; D >= y; D--) T(D);
const O = x.length;
for (let D = 0; D < O; D++) w.remove(x[D], l);
w.load(R);
const W = A.length;
for (let D = 0; D < W; D++) A[D].value.processZIndexCallback?.();
}, m = () => h._resources.beginPersist(), f = d === "picture", p = { 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 E = i()?.value.model;
if (!E) return !1;
try {
h.getView().selectMovables([E], 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, E, w) => g(0, y, E, w), "Move to Back");
}, moveBackwardOnContainer: () => {
c((y, E, w) => g(y.value.zIndex - 1, y, E, w), "Move Backwards");
}, moveForwardOnContainer() {
c((y, E, w) => g(y.value.zIndex + 1, y, E, w), "Move Forward");
}, moveToFrontOnContainer() {
c((y, E, w) => g(E.size() - 1, y, E, w), "Move To Front");
}, getZIndex: () => i()?.value.zIndex ?? 0, setContainerZIndexCallback(y) {
(i()?.value ?? o).processZIndexCallback = y;
}, setContainerCoords(y) {
if (!y) return;
const E = h._rangeToCoords(y, () => ["objects"]);
return c((w, b, v) => {
const I = { ...w, ...E };
b.remove(w, l), b.insert(I), v.set(I.value.model, I);
}, "Update Drawing", !1), E;
}, deleteFromContainer(y) {
const E = i();
E?.value && h.getView().unselectMovables([E.value.model]);
const w = [];
c((v, I, x) => {
x.delete(v.value.model), I.remove(v, l), v.value.processDeleteCallback?.(), w.push(v);
const R = v.value.model.getZIndex(), A = I.all().sort((D, z) => D.value.zIndex - z.value.zIndex), M = [], T = [], O = A.length;
for (let D = R + 1; D < O; D++) {
const z = A[D];
M.push(z);
const B = { ...z, value: { ...z.value, zIndex: D - 1 } };
T.push(B), x.set(B.value.model, B);
}
const W = M.length;
for (let D = 0; D < W; D++) I.remove(M[D], l);
I.load(T);
}, y?.description ?? "Delete Drawing", !0);
const b = w.length;
for (let v = 0; v < b; v++) w[v].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: t }, _ = t.content.json, S = { type: d, transactions: this._transactions, beginPersistResource: m, fromResourceId: n, defaultLockAspectRatio: f, json: _ };
let C = null;
if (d === "picture") C = new tw(S);
else if (d === "chart") C = new Tw(S);
else if (d === "sp" || d === "cxnSp" || d === "grpSp") C = new Nw(S);
else {
if (d !== "graphicFrame") throw new ot(((y) => `Unsupported float type: ${y}`)(d));
C = new Fw(S);
}
return o.model = new Oi({ ...p, content: C }), u = !1, s;
}
_fromJSON(t) {
this._initializing = !0, this._emitter.notify("onBeforeLoad", { params: t }), this._clearState();
const e = this._beginCommit({ description: "Load Sheet", viewAfter: { initial: !0, skipProtectionCheck: !0 } }), n = t || {}, 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);
const l = this._entireCoords, c = Wd(n.cols, F.Orientation.Column, l), h = Wd(n.rows, F.Orientation.Row, l);
this._colHeaders.fromJSON({ headers: n.cols, defaultSize: n.defaultColSize }), this._rowHeaders.fromJSON({ headers: n.rows, defaultSize: n.defaultRowSize }), this.setView(new cl({ sheet: this, json: n.view })), this._rangeSelection.updateCoords(this._view.getRangeSelection()), n.tabColor && (this._tabColor = this._styles.parseColor(n.tabColor));
let d = this._getState();
const u = d.cellValuesGrid, g = d.contentfulSpatial, m = n.data, f = m?.length ?? 0, p = zd, _ = [];
if (f > 0) {
for (let $ = 0; $ < f; $++) {
let J = m[$];
typeof J == "string" && (J = JSON.parse(J));
const Z = J[1], q = Z.length;
let Q;
for (let it = 0; it < q; it++) {
const X = Z[it], at = X[1], ut = at.length;
for (let tt = 0; tt < ut; tt++) {
let rt = at[tt], ct = rt?.t;
if (ct !== void 0) rt = rt?.v;
else switch (typeof rt) {
case "number":
ct = Y.Number;
break;
case "boolean":
ct = Y.Boolean;
break;
case "string":
ct = Y.String, rt = parseInt(rt);
}
at[tt] = [rt, ct];
}
Q = p(null, r, at), X[1] = Q;
}
_.push(J);
}
u.setValues(_);
const V = Pd(_, this._isDataColumn);
g.load(V);
}
const S = d.directStyleSpatial, C = d.continuousFillSpatial, y = this._options.styles, E = t.directStyles;
let w, b;
if (E) {
const V = E.length;
w = new Array(V);
for (let $ = 0; $ < V; $++) {
const J = E[$], Z = J.r, q = typeof Z == "string" ? Pe(Z, l) : { ...Z };
q.value = { orientations: F.Orientations.Both, index: J.v }, w[$] = q;
}
}
if (c || h) {
const V = [...w || k.EmptyArray, ...c || k.EmptyArray, ...h || k.EmptyArray];
w = [];
try {
const $ = new Qo.IteratorInstance(V, { orientation: F.Orientation.Column });
let J = $.next();
for (; !J.done; ) {
const Z = J.value, q = Z.overlaps, Q = q.length;
let it;
if (Q === 1) {
if (it = q[0].value, it.index === 0) {
J = $.next();
continue;
}
} else {
let at, ut, tt;
for (let rt = 0; !at && rt < Q; rt++) {
const ct = q[rt].value, lt = ct.orientations;
lt === F.Orientations.Both ? at = ct : lt === F.Orientations.Row ? tt = ct : lt === F.Orientations.Column && (ut = ct);
}
it = at ?? tt ?? ut;
}
const X = Z.range;
w.push({ ...X, value: it }), J = $.next();
}
} catch ($) {
console.log($);
}
}
if (w) {
let V = [], $ = [];
const J = (Q) => {
const it = Q.value, X = i.getElementJSON(it.index), at = L.sanitizeRange(Q), ut = new oe(y, at, X, void 0, it.orientations), tt = ut._p?.alignment?.horizontal;
return tt === et.HorizontalAlignment.CenterContinuous && V.push(at), tt === et.HorizontalAlignment.Fill && $.push(at), { ...at, value: ut };
}, Z = w.length;
b = new Array(Z);
for (let Q = 0; Q < Z; Q++) b[Q] = J(w[Q]);
S.load(b);
const q = (Q, it) => {
const X = (Q = an(Q, F.Orientation.Column, Number.MAX_SAFE_INTEGER)).length, at = new Array(X);
for (let ut = 0; ut < X; ut++) {
const tt = Q[ut];
at[ut] = { ...tt, value: new oe(y, tt, { alignment: { horizontal: it } }) };
}
C.load(at);
};
q(V, et.HorizontalAlignment.CenterContinuous), q($, et.HorizontalAlignment.Fill);
}
d = this._updateState({ cellValuesGrid: u, contentfulSpatial: g, directStyleSpatial: S, continuousFillSpatial: C });
const v = n.merges;
if (v) {
const V = [], $ = v.length;
for (let J = 0; J < $; J++) {
const Z = Pe(v[J], l);
V.push(Z);
}
this._indexMerges(V);
}
const I = d.hyperlinkSpatial, x = n.hyperlinks;
if (x) {
const V = x, $ = [], J = V.length;
for (let Z = 0; Z < J; Z++) {
const q = V[Z];
let Q = q.r;
Q = typeof Q == "string" ? Pe(Q, l) : L.sanitizeRange(Q);
let it = q.v;
typeof it == "string" && (it = { address: it }), $.push({ ...Q, value: it });
}
I.load($);
}
const R = d.commentsSpatial, A = n.comments;
if (A) {
const V = A, $ = [], J = V.length;
for (let Z = 0; Z < J; Z++) {
const q = V[Z];
let Q = q.ref;
Q = typeof Q == "string" ? Pe(Q, l) : L.sanitizeRange(Q);
const it = { ...q };
delete it.ref, $.push({ ...Q, value: it });
}
R.load($);
}
const M = d.movableMapModel, T = d.movableSpatial;
if (n.movables) {
const V = [], $ = n.movables, J = $.length;
for (let Z = 0; Z < J; Z++) {
const q = $[Z];
try {
const Q = this._createMovableEntry(q, Z, s.fromResourceId.bind(s));
M.set(Q.value.model, Q), V.push(Q);
} catch (Q) {
console.warn("Unable to load movable", Z, q, Q);
}
}
T.load(V);
}
const O = d.tableMapModel, W = d.tableMapName, D = d.tableSpatial, z = n.tables;
if (z) {
const V = [], $ = z.length;
for (let J = 0; J < $; J++) {
const Z = z[J], q = this._createTableEntry(Z), Q = q.value.model;
O.set(Q, q), W.set(q.value.currentName, Q), V.push(q);
}
D.load(V);
}
const B = d.conditionalSpatial, H = d.conditionalModels, P = n.conditionals;
if (P) {
const V = P.length;
for (let $ = 0; $ < V; $++) {
const J = P[$];
this._createConditionalEntries(J, B, H);
}
}
const j = d.calcGraph, G = j.fromJSON({ formulas: n.formulas, data: _, dynamic: n.dynamicArray, volatile: n.volatile });
d = this._updateState({ hyperlinkSpatial: I, commentsSpatial: R, movableSpatial: T, movableMapModel: M, tableSpatial: D, tableMapModel: O, tableMapName: W, conditionalSpatial: B, conditionalModels: H, calcGraph: j });
const K = this._getUsedCoords();
K && this._autoFit([K], { orientations: F.Orientations.Row, skipCustomSize: !0, expandOnly: !0 }), e.commit(), G && this._realizeCalcedValues(G), 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 ? ie : this._options.container?.getName?.() ?? null;
}
setName(t) {
if (this._closed) throw new Error(xe);
const e = this._options.container?.setName;
if (!e) throw new ot("Unable to set name for sheet.");
return e(t), this;
}
getVisibility() {
return this._closed ? bt.Visibility.VeryHidden : this._options.container?.getVisibility?.() ?? bt.Visibility.Hidden;
}
setVisibility(t = !0) {
if (this._closed) throw new Error(xe);
const e = this._options.container?.setVisibility;
if (!e) throw new ot("Unable to set visibility for sheet.");
let n;
return n = t === !0 ? bt.Visibility.Visible : t === !1 ? bt.Visibility.Hidden : t, e(n), this;
}
async select(t) {
return await this._options.container?.requestSelect?.(t), this;
}
duplicate() {
return this._options.container?.duplicate?.();
}
setPosition(t) {
return this._options.container?.setPosition(t), this;
}
getNames() {
return this._names;
}
getCalculation() {
return this._calculation;
}
getWorkbook() {
return this._workbook;
}
get [Symbol.toStringTag]() {
return "[Sheet]";
}
toString() {
return this.getName() || "(untitled sheet)";
}
get isISheet() {
return !0;
}
}
const Nu = { address: null, scope: null }, Yw = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0 }, Mo = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0 }, Qw = { colStart: 0, rowStart: 0, colEnd: 0, rowEnd: 0 }, Ps = { includeHidden: !1 }, Ws = { ignoreDataChanges: !1 }, qe = { colStart: -1, rowStart: -1, colEnd: -1, rowEnd: -1 }, To = [{ colIndex: -1, rowIndex: -1 }, null, null, null, null], Zw = [Ft.Content.Values], Fu = { size: null, autoSize: !0 }, hl = { skipCustomSize: !0, expandOnly: !0, minContent: !0 }, ce = { rowStart: 0, colStart: 0, rowEnd: 0, colEnd: 0 }, No = { rowStart: 0, colStart: 0, rowEnd: 0, colEnd: 0 }, ku = [], dl = { showFormulaBar: !0, showTabs: !0, tabRatio: 600, showHorizontalScrollbar: !0, showVerticalScrollbar: !0, showStatusBar: !0, activeSheetId: null };
class Ou {
constructor(t) {
this._emitter = null, this._emitter = new he(this), this._state = { ...dl }, t?.json && this._fromJSON(t?.json);
}
isShowFormulaBar() {
return this._state.showFormulaBar;
}
setShowFormulaBar(t) {
return this._state.showFormulaBar = t, this._emitter.notify("onViewChange"), this;
}
isShowTabs() {
return this._state.showTabs;
}
setShowTabs(t) {
return this._state.showTabs = t, this._emitter.notify("onViewChange"), this;
}
getTabRatio() {
return this._state.tabRatio;
}
setTabRatio(t) {
return this._state.tabRatio = t, this._emitter.notify("onViewChange"), this;
}
isShowHorizontalScrollbar() {
return this._state.showHorizontalScrollbar;
}
setShowHorizontalScrollbar(t) {
return this._state.showHorizontalScrollbar = t, this._emitter.notify("onViewChange"), this;
}
isShowVerticalScrollbar() {
return this._state.showVerticalScrollbar;
}
setShowVerticalScrollbar(t) {
return this._state.showVerticalScrollbar = t, this._emitter.notify("onViewChange"), this;
}
isShowStatusBar() {
return this._state.showStatusBar;
}
setShowStatusBar(t) {
return this._state.showStatusBar = t, this._emitter.notify("onViewChange"), this;
}
getActiveSheetId() {
return this._state.activeSheetId;
}
setActiveSheetId(t) {
const e = this._state.activeSheetId;
return this._state.activeSheetId = t, e !== t && this._emitter.notify("onViewChange"), this;
}
addListeners(t, e) {
return this._emitter.addListeners(t, e);
}
toJSON() {
let t = {};
const e = Object.keys(this._state);
for (let n = 0; n < e.length; n++) {
const r = this._state[e[n]];
r != null && r !== dl[e[n]] && (t[e[n]] = r);
}
return Object.keys(t).length === 0 && (t = null), t;
}
_fromJSON(t, e = !0) {
let n = t || {};
this.update(n, e);
}
update(t, e = !0) {
this._state = { ...dl, ...this._state, ...t }, e && this._emitter.notify("onViewChange");
}
}
class ty {
constructor(t) {
this._emitter = null, this._closed = !1, this._options = { ...t };
const e = this;
this._transactions = this._options.transactions ?? new Ze({ transient: !0 }), this._transactionsRemoveListener = this._transactions.addStateListener(this, { onAfterStateChange(n, r, o) {
e._emitter.notify("onCollectionChange");
} }), this._emitter = new he(this, this._transactions), this._initState(t?.initial);
}
add(t, e, n) {
const r = this;
e && e.addListeners({ onDelete: (c) => {
r._updateState((h) => {
if (!h.modules[t]) return;
const d = h.modules[t];
if (d) {
const u = { ...h };
return r._options.onRemove?.(t, d), r._emitter.notify("onCollectionChange"), delete u.modules[t], u;
}
return h;
}, "Delete Module");
} }, { once: !0 });
const o = this._getState()?.modules, s = o?.[t], i = n?.replace ?? !1;
if (s && !i) throw new Error(`Already existing '${t}'`);
const l = { ...o };
e ? (l[t] = e, r._options.onAdd?.(t, e), this._updateState({ modules: l }, i ? "Save Scripts" : "Add Script")) : (delete l[t], r._options.onRemove?.(t, null), this._updateState({ modules: l }, "Remove Script")), r._emitter.notify("onCollectionChange");
}
getItems(t) {
const e = this._getState();
if (!e) return k.EmptyArray;
const n = e.modules, r = Object.keys(n), o = r.length;
if (o === 0) return k.EmptyArray;
const s = [], i = t?.name ? t.name.toUpperCase() : null;
for (let l = 0; l < o; l++) {
const c = r[l], h = n[c];
let d = !0;
i && i !== c.toUpperCase() && (d = !1), d && s.push(h);
}
return s ?? k.EmptyArray;
}
getByName(t) {
if (!t) return null;
const e = this._getState();
if (!e) return null;
const n = t.toUpperCase(), r = e.modules, o = Object.keys(r), s = o.length;
for (let i = 0; i < s; i++) {
const l = o[i];
if (n === l.toUpperCase()) return r[l];
}
return null;
}
getCount() {
const t = this._getState();
return t ? Object.keys(t.modules).length : 0;
}
beginCommit(t) {
return this._beginCommit(t);
}
_getState() {
if (this._closed) throw new Error(We);
return this._transactions.getState(this);
}
_beginCommit(t) {
return this._transactions.beginCommit(typeof t == "string" ? { description: t } : t);
}
_updateState(t, e = "Update", n) {
if (!t) return;
const r = this._beginCommit(e);
try {
r.updateState(this, t), r.commit(n);
} catch (o) {
throw r.rollback(), o;
}
}
_initState(t) {
let e = t ?? {};
this._updateState({ modules: e }, "Initialize", { forceAmend: !0 });
const n = this._options.onAdd;
if (n) {
const r = Object.keys(e), o = r.length;
for (let s = 0; s < o; s++) {
const i = r[s];
n(i, e[i]);
}
}
}
addListeners(t, e) {
return this._emitter.addListeners(t, e);
}
toJSON() {
const t = this._getState();
if (!t) return k.EmptyArray;
const e = t.modules, n = Object.keys(e), r = n.length, o = {};
for (let s = 0; s < r; s++) {
const i = n[s];
o[i] = e[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", ey = ul || (ul = k.deepFreeze({ ISheet: { Visibility: bt.Visibility }, ICell: { Content: Ft.Content, CalcStatus: Ft.CalcStatus }, IColor: { Named: N.Named, Scheme: N.Scheme, Type: N.Type, AdjustmentType: N.AdjustmentType }, Direction: $t }), ul);
let Vs;
class ny extends ki {
constructor(t, e, n, r = null, o = !1) {
super(t, e, n, r, o);
}
execute(...t) {
const e = t[0];
if (!e || !e.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 An.Context.Workbook:
r.push(e);
break;
case An.Context.Sheet:
r.push(e.getSelectedSheet());
break;
case An.Context.Ranges:
r.push(e.getSelectedRanges());
break;
case An.Context.Range:
r.push(e.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 (_e(c[0]?.[0])) return void i.setValues(c, { skipBoundsCheck: !0 });
} else if (_e(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 e.doBatch(async () => {
try {
const l = e.getSelectedRange();
let c = this._cf();
c || (c = (function(h) {
return new Proxy(h, { set: (d, u, g) => (console.log(`Adding property "${u}" with value:`, g), d[u] = g, !0), deleteProperty: (d, u) => (console.log(`Deleting property "${u}"`), delete d[u]) });
})({}));
try {
gc({ getPosition: () => l.getCell().getCoords() }), Vs = globalThis[Hs], globalThis[Hs] = ey, s = this._fn.call(c, ...r), Vs ? (globalThis[Hs] = Vs, Vs = void 0) : delete globalThis[Hs], Fi();
} catch (h) {
throw h;
} finally {
Fi();
}
await o(l, s);
} catch (l) {
throw l;
}
}, i), { params: r, results: s };
})();
} catch (r) {
throw r;
}
}
}
class ry {
constructor(t) {
this._emitter = null;
const e = t.json;
if (this._json = e, !this._json) throw new Error("Module JSON is required.");
this._name = t.name ?? null, this._emitter = new he(this), this._functions = new Om({ transactions: null, readonlyFunctions: t.readonlyFunctions });
}
getName() {
return this._name;
}
getFunctions() {
return this._functions;
}
getSource() {
return this._json.source;
}
getLanguage() {
return this._json.language || "typescript";
}
getErrors() {
return null;
}
delete() {
this._emitter.notify("onDelete");
}
addListeners(t, e) {
return this._emitter.addListeners(t, e);
}
toJSON() {
return this._json;
}
}
const oy = async (a, t) => {
let e = null;
try {
gc(null);
} catch (o) {
console.warn("Error setting global scope", o);
}
try {
e = 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 {
Fi();
}
if (!t) throw new Error(`No function available for '${a.name ?? a.commitId}'.`);
const n = t.name;
let r = e[n];
if (!r && t.behavior.default && (r = e.default), !r) throw new Error(`Found the descriptor for '${n}' but not the function. The descriptor manifest must be corrupt.`);
return r;
}, Du = async (a, t, e = !1) => {
const n = t?.functions, r = /* @__PURE__ */ new Map();
if (n) for (let o = 0; o < n.length; o++) {
const s = n[o], i = s[0], l = s[1];
let c, h = e ? () => {
} : await oy(t, i);
c = i.context && i.context !== An.Context.Calculation ? new ny(i, h, () => null, l) : new ki(i, h, () => null, l), r.set(i.name.toUpperCase(), c);
}
return new ry({ json: t, readonlyFunctions: r, name: a });
};
class sy {
constructor(t) {
this._emitter = null, this._options = t, this._emitter = new he(this), this._initState();
}
_initState() {
}
getModules() {
return this._modules;
}
async createModule(t) {
const e = await import("@sheetxl/scripting"), n = await e.ScriptingUtils.compileTypescript(t);
return n ? await Du("scripts", n, t?.declarationsOnly ?? !1) : null;
}
addModule(t, e, n) {
this._modules.add(t, e, n);
}
executeMacro(t, e) {
const n = this._modules.getItems({ name: e }), r = n.length;
for (let o = 0; o < r; o++) {
const s = n[o].getFunctions().getByName(t);
if (s) return s.execute(this._options.workbook);
}
throw new Error(`No macro ${t} found.`);
}
async searchFunctions(t) {
await this._emitter.notify("onBeforeSearch", { async: !0 });
const e = t?.moduleName, n = this._modules;
let r;
if (t.includeBuiltIn) {
const i = this._options.getBuiltInFunctions?.();
i && (r = await i.search(t));
}
if (!n) return r ?? k.EmptyArray;
if (n.getCount() === 0) return r ?? k.EmptyArray;
const o = e ? this._modules.getItems({ name: e }) : this._modules.getItems(), s = o.length;
for (let i = 0; i < s; i++) {
const l = o[i], c = await l.getFunctions().search(t);
c.length > 0 && (r || (r = []), r.push(...c));
}
return Promise.resolve(r);
}
async start() {
if (this._modules) return Promise.resolve();
const t = this._options?.workbook, e = this._options?.json;
let n = {};
if (e) {
const l = Object.keys(e);
for (let c = 0; c < l.length; c++) {
const h = l[c], d = e[h], u = await Du(h, d);
n[h] = u;
}
}
const r = this, o = new ty({ transactions: this._options?.transactions, initial: n, onRemove: (l, c) => {
r._options?.onRemove?.(l, c);
}, onAdd: (l, c) => {
r._emitter.notify("onChange"), r._options?.onAdd?.(l, c);
} });
this._modules = o;
const s = o.getItems();
if (s.length === 0) return Promise.resolve(k.EmptyArray);
const i = s.length;
for (let l = 0; l < i; l++) {
const c = s[l];
try {
const h = c.getFunctions().getItems({ type: "autoRun" }), d = h.length;
for (let u = 0; u < d; u++)
await h[u].execute(t);
} catch (h) {
Go.error("Error executing autoRun script:", h);
}
}
}
addListeners(t, e) {
return this._emitter.addListeners(t, e);
}
isReadOnly() {
return this._options.workbook?.getProtection().isStructureAllowed() === !1;
}
toJSON() {
this._emitter.notify("onBeforeSave");
const t = this._modules;
if (!t) throw new Error("Scripts is initializing.");
return t.toJSON();
}
}
const iy = Object.freeze({ lockStructure: !1, lockWindows: !1, lockRevision: !1, workbookPassword: null, revisionsPassword: null });
class Lu extends Hm {
isWindowsAllowed() {
return this._isPropertyAllowed("windows");
}
isRevisionAllowed() {
return this._isPropertyAllowed("revision");
}
isStructureAllowed() {
return this._isPropertyAllowed("structure");
}
_fromJSON(t) {
this._properties = t;
}
_toJSON(t) {
let e = this._properties;
if (e) {
t = { ...t, ...e };
const n = Object.keys(e), r = n.length;
for (let o = 0; o < r; o++) {
const s = n[o], i = e[s];
i != null && i !== iy[s] && (t[s] = i);
}
}
return super._toJSON(t);
}
}
const gl = (a) => `Invalid SheetKey: ${a}`, ml = "A workbook must contain at least one visible worksheet.", Bu = "Internal error no visible sheetRefs", ge = "Workbook has been closed. No further operations are allowed.", lr = "This workbook structure is protected. To make a change, unprotect the workbook. You might be requested to enter a password.", Qi = "A sheet name", ql = `${Qi} can not be blank.`, ay = `${Qi} can not be longer than 31 characters.`, ly = `${Qi} can not begin or end with a "'" (single quote).`;
class cy {
constructor(t, e) {
this._add = t, this._get = e;
}
add(t) {
return this._add(t);
}
getItems(t) {
return this._get(t?.name, t?.visibility);
}
getByName(t) {
return this._get(t)?.[0] ?? null;
}
getCount() {
return this._get().length;
}
}
const Jl = new RegExp(/[\\/\\*?:[\]]+/), hy = new RegExp(/\(((\d+)(?!.*\d))\)$/, "g"), dy = (a) => `Sheet${a + 1}`, Vm = (a, t) => ({ ...Qn, getSheet: () => null, toString: () => Ui(a, t) }), zu = (a, t = !1) => {
if (!a) throw new Error(ql);
if (Jl.test(a)) {
if (!t) throw new Error(((n) => `${n ? `'${n}'` : Qi} can not contain any of the following characters '\\ , / , * , ? , : , [ , ]'.`)(a));
a = a.replace(Jl, "");
}
if (a.length === 0) throw new Error(ql);
const e = a.length;
if (e > 31) {
if (!t) throw new Error(ay);
a = a.substring(0, 31);
}
if (a.charAt(0) === "'" || a.charAt(e - 1) === "'") {
if (!t) throw new Error(ly);
a = a.replace(/^'|'$/g, "");
}
return a;
};
class Zi extends hs {
constructor(t, e, n, r) {
super(t, e, r), this._workbook = n;
}
getSource() {
return this._workbook;
}
_createRanges(t, e) {
let n = this._options;
return e && (n = { ...this._options, getOptions: Fn(this._options?.getOptions, e) }), new Zi(t, this._sheet, this._workbook, n);
}
_createRange(t, e) {
const n = t ? { ...t } : null;
if (!(n && this._workbook._getSheetRef(n.sheetName, bt.Visibility.VeryHidden))) {
const o = this._workbook.getSelectedSheet();
return delete n?.sheetName, Vm(n, n ? { sheetName: ie, ...o.getEntireRange().getCoords() } : null);
}
let r = this._options;
return e && (r = { ...this._options, getOptions: Fn(this._options.getOptions, e) }), new ta(t, this._sheet, this._workbook, r);
}
async select(t) {
const e = [];
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 && e.push(c));
}
n || (n = this._workbook.getSelectedSheet().getName());
const o = this._workbook.getSheets().getByName(n);
if (!o) return;
const s = await o.getRanges(e).select(t), i = this._workbook._rangesAddressToCoords(s.getCoords());
return this._createRanges(i, t);
}
addListener(t, e) {
if (!this.getCoords()) return () => {
};
const n = this._workbook._sheetToWBEvent(t);
return super.addListener(n, e);
}
get [Symbol.toStringTag]() {
return "[WorkbookRanges]";
}
toString() {
const t = this.getCoords(), e = this._sheet, n = e.getEntireRange().getCoords(), r = { sheetName: e.getName(), ...n };
return rm(t, r, Ui, nr);
}
}
class ta extends ds {
constructor(t, e, n, r) {
super(t, e, r), this._workbook = n;
}
_createRanges(t, e) {
let n = this._options;
return e && (n = { ...this._options, getOptions: Fn(this._options?.getOptions, e) }), new Zi(t, this._sheet, this._workbook, n);
}
_createRange(t, e) {
const n = this._sheet;
if (!t) return Rn(n, n._entireCoords);
if (n._validateCoords(t), n._closed) return Rn(null, n._entireCoords, t);
let r = this._options;
return e && (r = { ...this._options, getOptions: Fn(this._options?.getOptions, e) }), new ta(t, this._sheet, this._workbook, r);
}
addListener(t, e) {
if (!this.getCoords()) return () => {
};
const n = this._workbook._sheetToWBEvent(t);
return super.addListener(n, e);
}
get [Symbol.toStringTag]() {
return "[WorkbookRange]";
}
toString() {
const t = this._sheet, e = t?.getEntireRange().getCoords() ?? null;
return Ui(this.getCoords(), { ...e, sheetName: t.getName() });
}
}
class by {
constructor(t) {
this._lastTransactionUUID = null, this._closed = !1, this._initializing = !0, this._emitter = null, this._names = null, this._calculation = null, this._isDate1904 = !1;
const e = this, n = { ...t }, r = n.json;
delete n.json, this._transactions = n.transactions ?? new Ze(), this._ownTransactions = !n.transactions, this._emitter = new he(this, this._transactions);
const o = this._beginCommit({ description: (r ? "Open" : "New") + " Workbook" });
try {
this._strings = n.strings ?? new dc(), this._ownStrings = !n.strings, this._resources = n.resources ?? new Nm(), this._ownResources = !n.resources, this._createSheetName = n.createSheetNameCallback ?? dy;
let s = n.createSheetCallback;
s || (s = (l) => new ns(l)), this._sheetOnNameChange = /* @__PURE__ */ new Map(), this._sheetOnVisibilityChange = /* @__PURE__ */ new Map(), this._sheetOnIndexChange = /* @__PURE__ */ new Map(), this._createSheet = (l, c, h, d, u) => {
let g = null;
const m = { date1904: e.isDate1904(), readonly: e._options.readonly ?? !1, transactions: e._transactions, styles: e._styles, strings: e._strings, resources: e._resources, names: e._names, workbook: e, calculation: e._calculation, resolveRange: (f) => e._options.resolveRange?.(f) ?? e.getRange(f), container: { beforeFromJSON: (f) => {
g = f, e._addSheetRef({ name: c, id: l, visibility: h ?? bt.Visibility.Visible, sheet: f }, d);
}, getName: () => {
const f = e._getSheetRef(g);
return f ? f.name : e._createSheetName(1);
}, setName: (f) => {
e._getSheetRef(g) && e._setSheetName(g, f);
}, getIndex: () => {
const f = e._getSheetRef(g);
return f ? e._findOffsetForId(f.id, e._getSheetRefs(bt.Visibility.VeryHidden)) : -1;
}, setIndexCallback: (f) => {
e._sheetOnIndexChange.set(l, f);
}, setNameChangeCallback: (f) => {
e._sheetOnNameChange.set(l, f);
}, getVisibility: () => {
const f = e._getSheetRef(g);
return f ? f.visibility : bt.Visibility.Visible;
}, setVisibility: (f) => {
e._setSheetVisibility(g, f);
}, setVisibilityCallback: (f) => {
e._sheetOnVisibilityChange.set(l, f);
}, duplicate: () => e._duplicateSheet(g), setPosition: (f) => {
const p = e._getSheetRef(g, bt.Visibility.VeryHidden);
return !!p && (e._moveSheet(p, f), !0);
}, requestSelect: async () => (e._setSelectedSheet(g), await this._emitter.notify("onRequestSelect", { source: e, params: g, async: !0 }), e.getSelectedSheet() === g) } };
return u && (m.json = u), g = s(m, c, d, h), g;
}, this._names = n.names ?? new Lm({ addressToRanges: (l) => e.getRanges(l), getCurrentScope: () => e.getSelectedSheet().getName(), isReadOnly: () => e._options.readonly ?? !1, transactions: e._transactions }), this._ownNames = !n.names, this._calculation = n.calculation ?? new Dm({ getNamed: (l, c) => {
try {
Dr.address = l, Dr.scope = c;
const h = this._names.getItems(Dr);
return h && h.length !== 0 ? h[0].getRanges().getCoords() : null;
} catch {
return null;
}
}, getSheetIndex: (l) => {
if (l === void 0) return e.getSelectedSheetIndex();
const c = this._getSheetRefs(bt.Visibility.Hidden);
l = l.toLowerCase();
const h = c.length;
for (let d = 0; d < h; d++) if (c[d].name.toLowerCase() === l) return d;
try {
Dr.address = l, Dr.scope = void 0;
const d = this._names.getItems(Dr);
if (!d || d.length === 0) return -1;
let g = d[0].getRanges().getCoords()?.[0]?.sheetName;
if (!g) return -1;
const m = this._getSheetRefs(bt.Visibility.Hidden);
g = g.toLowerCase();
const f = m.length;
for (let p = 0; p < f; p++) if (m[p].name.toLowerCase() === g) return p;
} catch {
return -1;
}
return -1;
}, getSheetCount: () => e.getSheets().getCount(), isDate1904: () => e.isDate1904(), strings: e._strings, transactions: e._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 cy((s) => e._addSheetOptions(s), (s, i) => s ? [this.getSheet(s, i)] : this._getSheets(i)), this._initializing = !1;
}
_initState() {
let t = this._getSheetRefs();
t && t.length, this._isDate1904 = this._options.date1904 ?? !1, this._theme = this._options.theme ?? new Hg().getDefaultTheme(), this._styles = this._options?.styles ?? new cs(this._theme), this._ownStyles = !this._options.styles, this._styles.getTheme() || this._styles.setTheme(this.getTheme()), this._activeSheetOffset = 0, this.setView(new Ou()), this._listenerProtection?.(), this._protection = new Lu(void 0, this._options.readonly ?? !1), this._listenerProtection = this._protection.addListeners({ onChange: (r) => {
e._emitter.notify("onProtectionChange");
} });
const e = this;
this._transactionsRemoveListener = this._transactions.addStateListener(this, { onAfterStateChange(r, o, s) {
if (o && o.activeSheetId !== void 0 && o.view === e.getView() && s.getId() === e._lastTransactionUUID && e._getSheetRef(o.activeSheetId)?.sheet.select(), o && s.getId() !== e._lastTransactionUUID) {
let i = e.getView().getActiveSheetId();
o.view === e.getView() && (i = o.activeSheetId);
let l = 0;
try {
l = e._findOffsetForId(i, r.sheetRefsVisible);
} catch {
}
e._activeSheetOffset = l;
}
e._lastTransactionUUID = s.getId(), e._notifyAllChange();
}, onRestoreOrRevert() {
e._emitter.notify("onInvalidated");
} });
const n = this._getState();
n?.listenersSheets && (n?.listenersSheets.forEach((r) => {
r();
}), n?.listenersSheets.clear()), this._updateState({ name: this._options.name ?? null, 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() });
}
getName() {
return this._closed ? null : this._getState().name;
}
setName(t) {
if (this._closed) throw new Error(ge);
if (t !== null) try {
const e = this._options.validateWorkbookName?.(t);
e !== void 0 && (t = e);
} catch (e) {
throw new ot(`Invalid workbook name: ${e instanceof Error ? e.message : String(e)}`);
}
return this._updateState({ name: t }, "Set Workbook Name"), this._emitter.notify("onNameChange"), this;
}
getView() {
return this._view;
}
setView(t) {
if (this._closed) throw new Error(ge);
if (!t) throw new ot("View can not be empty.");
this._listenerWorkbookView?.();
const e = this;
let n = -1;
return this._listenerWorkbookView = t.addListeners({ onViewChange: (r) => {
const o = e._getState(), s = this._view.getActiveSheetId(), i = this._findOffsetForId(s, o.sheetRefsAll);
this._activeSheetOffset = i, e._emitter.notify("onViewChange"), n !== s && e._emitter.notify("onSelectionChange"), n = s;
} }), this._view = t, e._emitter.notify("onViewChange"), this;
}
isDate1904() {
return this._isDate1904;
}
setDate1904(t) {
if (this._closed) throw new Error(ge);
return this._isDate1904 = t, this._notifyAllChange(), this;
}
getStyles() {
return this._styles;
}
getResources() {
return this._resources;
}
getTransactions() {
return this._transactions;
}
getStrings() {
return this._strings;
}
getTheme() {
return this._theme;
}
setTheme(t) {
if (this._closed) throw new Error(ge);
if (!t) throw new ot("A value must be provided.");
const e = this._theme;
return this._theme = t, this.getStyles().setTheme(t), this._emitter.notify("onThemeChange"), e;
}
getSelectedSheetIndex() {
return this._activeSheetOffset;
}
getSelectedSheet() {
const t = this._getSheetRef(this.getSelectedSheetIndex());
return t ? t?.sheet : null;
}
getSheet(t, e = bt.Visibility.Visible) {
const n = this._getSheetRef(t, e);
if (!n) throw new Wt(`Sheet '${t}' not found.`);
return n.sheet;
}
getSheetAt(t, e = bt.Visibility.Visible) {
const n = this._getSheetRef(t, e);
if (!n) throw new Wt(((r) => `No sheet found at ${r}.`)(t));
return n.sheet;
}
getSheets() {
return this._sheets;
}
addSheet(t) {
return this.getSheets().add(t);
}
_getSheets(t = bt.Visibility.Visible) {
const e = this._getSheetRefs(t), n = [], r = e.length;
for (let o = 0; o < r; o++) n.push(e[o].sheet);
return n;
}
_getSheetRefs(t = bt.Visibility.Visible) {
if (this._closed) return k.EmptyArray;
const e = this._getState();
return e ? t === bt.Visibility.Visible ? e.sheetRefsVisible : t === bt.Visibility.Hidden ? e.sheetRefsVisibleAndHidden : t === bt.Visibility.VeryHidden ? e.sheetRefsAll : k.EmptyArray : [];
}
_getSheetRef(t, e = bt.Visibility.Visible) {
if (this._closed) return null;
let n = null;
return typeof t == "number" ? this._getSheetRefs(e)[t] : (typeof t == "string" ? n = this._getState().refsByLowerCaseName.get(t.toLowerCase()) : t instanceof ns ? n = this._getState().refsByInstance.get(t) : t?.id !== void 0 && t.sheet && (n = this._getState().refsById.get(t.id)), n);
}
_validateNewSheetName(t, e = !0) {
if (t == null) return t;
if (zu(t), e && this._getState().sheetsByLowerCaseName.has(t.toLowerCase())) throw new ot("That name is already taken. Try a different one.");
return t.substring(0, 31);
}
findValidSheetName(t) {
t && (t = zu(t, !0));
try {
return ((e, n) => {
try {
if (n(e)) return e;
} catch {
}
let r, o, s = hy.exec(e);
for (s !== null ? (r = e.substring(0, s.index), o = parseFloat(s[1])) : (r = e + " ", 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(e + " is not a valid sheet name");
})(t, (e) => this._validateNewSheetName(e));
} catch {
return this._nextSheetName();
}
}
isValidSheetNameCharacter(t) {
return !Jl.test(t);
}
_addSheetOptions(t) {
if (this._closed) throw new Error(ge);
if (!this.getProtection().isStructureAllowed()) throw new ot(lr);
let e, n = null;
e = typeof t == "string" ? { name: t } : typeof t == "number" ? { index: t } : t, e = { ...e, description: e?.description ?? "Add Sheet" };
const r = this.beginCommit(e);
try {
const o = e?.autoSelect ?? !1;
n = this._addSheet(!0, e.name, e.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(t = null) {
let e = t ? t.toLowerCase() : null;
const n = this._getState(), r = n.sheetsByLowerCaseName;
if (t && r.has(e)) throw new ot(((s) => `The sheet name '${s}' already exist in workbook.`)(t));
e = (t = this._validateNewSheetName(t)) ? t.toLowerCase() : null;
let o = n.lastId + 1;
for (; !t; ) {
const s = this._createSheetName(o), i = s.toLowerCase();
r.has(i) ? o++ : t = s;
}
return this._updateState({ lastId: o }), t;
}
_addSheet(t, e = null, n = null) {
e = this._nextSheetName(e);
const r = this._getState(), o = this._createSheet(r.lastId, e, bt.Visibility.Visible, n, null);
if (!o) throw new ot(ql);
return t && this._emitter.notify("onSheetsChange"), o;
}
_updateSheetRefStates(t) {
if (this._closed) throw new Error(ge);
if (!this._initializing && !this.getProtection().isStructureAllowed()) throw new ot(lr);
const e = t, n = [], r = [], o = e.length;
for (let s = 0; s < o; s++) e[s].visibility === bt.Visibility.Visible ? (n.push(e[s]), r.push(e[s])) : e[s].visibility === bt.Visibility.Hidden && r.push(e[s]);
this._updateState({ sheetRefsAll: e, sheetRefsVisible: n, sheetRefsVisibleAndHidden: r });
}
_addSheetRef(t, e = null) {
const n = this._getState(), r = n.sheetRefsAll, o = Math.max(0, Math.min(r.length, e ?? r.length));
let s = [...r.slice(0, o), t, ...r.slice(o)];
this._updateSheetRefStates(s);
const i = t.sheet, l = t.name.toLowerCase(), c = new Map(n.refsById);
c.set(t.id, t);
const h = new Map(n.refsByLowerCaseName);
h.set(l, t);
const d = new Map(n.refsByInstance);
d.set(i, t);
const u = new Map(n.sheetsById);
u.set(t.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 w = m._getSheetRef(E, bt.Visibility.VeryHidden);
if (!w) return;
const b = m._beginCommit({ description: `Remove Sheet ${w.name}` });
try {
const v = m._getState(), I = v.sheetRefsAll, x = m._findOffsetForId(w.id, I);
let R = [...I];
R.splice(x, 1), m._updateSheetRefStates(R);
const A = new Map(v.refsById);
A.delete(w.id);
const M = new Map(v.sheetsById);
M.delete(w.id);
const T = w.name.toLowerCase(), O = new Map(v.refsByLowerCaseName);
O.delete(T);
const W = new Map(v.sheetsByLowerCaseName);
W.delete(T);
const D = new Map(v.refsByInstance);
D.delete(E), v.listenersSheets.get(w.id)();
const z = new Map(v.listenersSheets);
z.delete(w.id), m._adjustRemoveSelectionIfRequired(x, w.id), m._adjustSheetNamesIfRequired(), m._emitter.notify("onSheetsChange");
const B = new Set(v.sheetsCreated);
B.has(i) && B.delete(i), m._updateState({ refsById: A, sheetsById: M, refsByLowerCaseName: O, sheetsByLowerCaseName: W, refsByInstance: D, sheetsCreated: B, listenersSheets: z }), b.commit();
} catch (v) {
throw b.rollback(), v;
}
} }), C = i.addListeners({ onSelectionChange: (E) => {
m.getView().getActiveSheetId() === m._getSheetRef(E)?.id && m._emitter.notify("onSelectionChange", { source: m, params: E });
} }, { transactional: !1 }), y = () => {
S(), C();
};
f = new Map(n.listenersSheets), f.set(t.id, y);
}
let p = n.lastId;
p !== -1 && (p = Math.max(p, t.id)), this._updateState({ lastId: p }), this._updateState({ refsById: c, refsByLowerCaseName: h, refsByInstance: d, sheetsById: u, sheetsByLowerCaseName: g, listenersSheets: f }), this._adjustSheetNamesIfRequired();
const _ = new Set(this._getState().sheetsCreated);
return _.add(t.sheet), this._updateState({ sheetsCreated: _ }), t;
}
_adjustRemoveSelectionIfRequired(t, e) {
if (this._view.getActiveSheetId() === e) {
let n;
const r = this._getState().sheetRefsVisible;
n = t < r.length ? r[t].id : r[t - 1].id, this._view.setActiveSheetId(n);
}
}
_adjustSheetNamesIfRequired() {
const t = this._getState(), e = t.lastId;
if (e === -1) return;
let n = this._view.getActiveSheetId();
n == null && (this._view.setActiveSheetId(e), n = e), t.refsById.get(n).visibility === bt.Visibility.Visible && (this._activeSheetOffset = this._findOffsetForId(n, t.sheetRefsVisible));
}
_validateDeleteSheet(t) {
if (this._closed) throw new Error(ge);
if (!this.getProtection().isStructureAllowed()) throw new ot(lr);
let e = this._getSheetRef(t);
if (!e) throw new ot(((r) => `Invalid reference for delete: ${r}`)(t));
const n = this._getState().sheetRefsVisible;
if (n.length === 1 && n[0].id === e.id) throw new ot(ml);
}
_findOffsetForId(t, e) {
const n = e.length;
for (let r = 0; r < n; r++) if (e[r].id === t) return r;
throw new ot(Bu);
}
find(t) {
if (this._closed) throw new Error(ge);
const e = this._getSheets();
if (e.length === 1) return e[0].find(t);
typeof t == "string" && (t = { text: t });
const n = !t?.reverse;
let r = t?.disableWrap ?? !1;
const o = this.getSelectedSheetIndex();
let s = o, i = e[s], l = !1;
t = { ...t, disableWrap: !0 };
let c, h = i.find(t), d = h.next(), u = !1;
if (t?.from) {
const f = this._rangesAddressToCoords(t?.from);
c = { colIndex: f[0].colStart, rowIndex: f[0].rowStart };
}
const g = L.createCellComparator(t?.orientation, t?.reverse);
delete (t = { ...t }).from;
const m = () => {
if (!u && d.done && (l && s === o ? u = !0 : n ? (s++, s > e.length - 1 && (s = 0, l = !0)) : (s--, s < 0 && (s = e.length - 1, l = !0)), r && l && (u = !0), u || c || !l || s !== o || (u = !0), !u)) {
i = e[s], h = i.find(t);
const p = d;
return d = h.next(), p;
}
if (!u && l && s === o && (d.done || !c || !d.done && g(d.value.getCoords(), c) >= 0) && (u = !0), u) {
const p = d;
return d = Lt, p;
}
const f = d;
return d = h.next(), f;
};
return { next: () => {
let f = m();
for (; !u && f.done; ) f = m();
return f;
} };
}
replace(t, e, n) {
let r = 0, o = null;
const s = typeof e == "function", i = n?.maxCount ?? Number.MAX_SAFE_INTEGER;
let l = n.maxCount ? "" : "All";
const c = typeof e == "string" ? ` with '${_g(e)}'` : "";
let h = n?.description ?? "Replace";
const d = this._transactions.beginCommit({ description: h });
try {
let u = null, g = null, m = t.next();
for (; !m.done && r < i; ) {
const f = m.value, p = f.getSheet();
p !== u && (u = p, g !== null && g.apply(), g = u.getEntireRange().startIncrementalUpdates({ orientation: n?.orientation, allowUnorderedWrites: !0 }));
const _ = s ? e(f) : e;
_ !== void 0 && _ !== f && (g.push(f, _), r++, o = f), m = t.next();
}
g?.apply(), r === 1 && i === 1 && o && (l = o.getA1()), r === 0 ? d.rollback() : d.commit({ description: n?.description ?? `Replace ${l}${c}`, viewAfter: { selection: null } });
} catch (u) {
throw d.rollback(), u;
}
return { count: r, last: o };
}
_nextSheetIndex(t, e = this._getSheetRefs()) {
const n = e.length;
return n === 1 ? 0 : (t === void 0 && (t = this.getSelectedSheetIndex()), (t = Math.max(0, Math.min(t, n - 1))) >= n - 1 ? 0 : t + 1);
}
_prevSheetIndex(t, e = this._getSheetRefs()) {
const n = e.length;
return n === 1 ? 0 : (t === void 0 && (t = this.getSelectedSheetIndex()), (t = Math.max(0, Math.min(t, n - 1))) <= 0 ? n - 1 : t - 1);
}
getNextSheet(t) {
if (this._closed) throw new Error(ge);
const e = this._getSheetRefs();
return e[this._nextSheetIndex(t, e)]?.sheet ?? null;
}
getPreviousSheet(t) {
if (this._closed) throw new Error(ge);
const e = this._getSheetRefs();
return e[this._prevSheetIndex(t, e)]?.sheet ?? null;
}
async _duplicateSheet(t) {
if (this._closed) throw new Error(ge);
if (!this.getProtection().isStructureAllowed()) throw new ot(lr);
const e = this._getSheetRefs(), n = this.getSelectedSheetIndex();
let r = null;
if (t) {
if (r = this._getSheetRef(t), !r) throw new ot(gl(r));
} else r = e[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 d = this._getState().refsByInstance.get(o), u = await o.toJSON(), g = e.length + 1, m = this.findValidSheetName(d.name), f = this._createSheet(g, m, d.visibility, n, u);
this._emitter.notify("onSheetsChange"), c = f, h.commit();
} catch (d) {
throw h.rollback(), d;
} finally {
l.endPersist(), i.endPersist(), s.endPersist();
}
return c;
}
_createRange(t, e) {
const n = t ? { ...t } : null;
if (!(n && this._getSheetRef(n.sheetName, bt.Visibility.VeryHidden))) {
const s = this.getSelectedSheet();
return s ? (delete n?.sheetName, Vm(n, n ? { sheetName: ie, ...s.getEntireRange().getCoords() } : null)) : void console.warn(Bu);
}
const r = this.getSelectedSheet();
let o = null;
return e && (o = { getOptions: e }), new ta(t, r, this, o);
}
_createRanges(t, e) {
const n = this.getSelectedSheet();
let r = null;
return e && (r = { getOptions: e }), new Zi(t, n, this, r);
}
getRange(t, e) {
try {
const n = this._rangesAddressToCoords(t);
if (n.length !== 1) throw new ot(am);
return this._createRange(n[0], e);
} catch (n) {
throw n instanceof Wt ? new Wt(n.message) : new ot(n.message ?? Jr(t));
}
}
getRanges(t, e) {
const n = this._rangesAddressToCoords(t);
if (n.length === 0) throw new ot(Jr(t));
return this._createRanges(n, e);
}
_activeRangeCoords() {
const t = this.getSelectedSheet(), e = t.getSelection().getRangesCoords(), n = t.getName(), r = [], o = e.length;
for (let s = 0; s < o; s++) r.push({ sheetName: n, ...e[s] });
return r;
}
getSelectedRange(t) {
return this.getRange(this._activeRangeCoords()[0], t);
}
getSelectedRanges(t) {
return this.getRanges(this._activeRangeCoords(), t);
}
getSelectedCell() {
return this.getSelectedSheet().getSelectedCell();
}
_rangesAddressToCoords(t, e = !0, n = bt.Visibility.Hidden) {
if (!t) throw new ot(pr);
const r = this.getSelectedSheet(), o = r?.getEntireRange().getCoords(), s = { ...o }, i = r?.getName();
if (i && (s.sheetName = i), typeof t == "string") {
const d = t.trim().toLowerCase();
if (d === "r" || d === "c") {
const u = this.getSelectedCell().getCoords(), g = {};
d === "r" ? g.rowStart = g.rowEnd = u.rowIndex : g.colStart = g.colEnd = u.colIndex, t = g;
}
}
const l = this, c = qi(t, s, ls, (d) => {
if (!e) return null;
if (typeof d == "string") {
const u = l.getNames().getByName(d);
if (u) return u.getRanges()?.getCoords();
}
throw new ot(`Invalid sheet reference '${d}'.`);
}), h = c.length;
for (let d = 0; d < h; d++) this._validateCoords(c[d], n);
return c;
}
_validateCoords(t, e = bt.Visibility.Visible, n = Ri) {
if (t === null) return;
const r = this.getSheet(t.sheetName, e).getEntireRange().getCoords();
if (!L.isRangeWithinRange(t, r)) throw new Wt(n);
if (t.rowEnd < t.rowStart || t.colEnd < t.colStart) throw new ot(lm);
}
_updateSheetRef(t, e) {
const n = this._getState();
let r = [...n.sheetRefsAll];
r[this._findOffsetForId(t.id, n.sheetRefsAll)] = e, this._updateSheetRefStates(r);
const o = new Map(n.refsById);
o.set(t.id, e);
const s = t.name.toLowerCase(), i = e.name.toLowerCase(), l = new Map(n.refsByLowerCaseName);
l.delete(s), l.set(i, e);
const c = new Map(n.sheetsByLowerCaseName);
let h = c.get(s);
c.delete(s), c.set(i, h);
const d = new Map(n.refsByInstance);
return d.set(h, e), this._updateState({ refsById: o, refsByLowerCaseName: l, sheetsByLowerCaseName: c, refsByInstance: d }), e;
}
_setSheetName(t, e) {
if (this._closed) throw new Error(ge);
if (!this.getProtection().isStructureAllowed()) throw new ot(lr);
const n = this._getSheetRef(t);
if (!n) throw new ot(gl(t));
if (e === n.name) return n.sheet;
e = this._validateNewSheetName(e);
const r = Object.freeze({ ...n, name: e });
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"), n.id === this.getView().getActiveSheetId() && this._emitter.notify("onSelectionChange"), o = i.sheet, s.commit();
} catch (i) {
throw s.rollback(), i;
}
return o;
}
_setSheetVisibility(t, e = bt.Visibility.Visible) {
if (this._closed) throw new Error(ge);
if (!this.getProtection().isStructureAllowed()) throw new ot(lr);
const n = this._getSheetRef(t, bt.Visibility.VeryHidden);
if (!n) return null;
if (e === n.visibility) return;
let r = null, o = "";
e === bt.Visibility.Visible ? o = "Unhide Sheet" : e === bt.Visibility.Hidden ? o = "Hide Sheet" : e === bt.Visibility.VeryHidden && (o = "Very Hide Sheet");
const s = this.beginCommit(o);
try {
const i = this._getState().sheetRefsVisible;
if (e !== bt.Visibility.Visible && i.length === 1 && i[0].id === n.id) throw new ot(ml);
const l = { ...n, visibility: e };
let c = -1;
e !== bt.Visibility.Visible && (c = this._findOffsetForId(n.id, i));
const h = this._updateSheetRef(n, l);
e !== bt.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(t, e) {
if (this._closed) throw new Error(ge);
if (!this.getProtection().isStructureAllowed()) throw new ot(lr);
let n = null;
const r = this.beginCommit(`Move Sheet '${t.name}'`);
try {
const o = this._getState(), s = o.sheetRefsVisible;
if (e < 0 || e > s.length - 1) throw new ot(`Invalid to index: ${e}`);
const i = { view: this.getView(), activeSheetId: this.getView().getActiveSheetId() }, l = o.sheetRefsAll, c = this._findOffsetForId(t.id, l), h = this._findOffsetForId(s[e].id, l);
if (c === h) return;
const d = l[c];
let u = [...l];
u.splice(c, 1), u.splice(h, 0, d), this._updateSheetRefStates(u), this._adjustSheetNamesIfRequired(), this._sheetOnIndexChange.forEach((g, m) => {
m >= c && m <= h && g();
}), this._emitter.notify("onSheetsChange"), n = d.sheet, r.commit({ viewBefore: i, viewAfter: { view: this.getView(), activeSheetId: this.getView().getActiveSheetId() } });
} catch (o) {
throw r.rollback(), o;
}
return n;
}
_setSelectedSheet(t) {
if (this._closed) throw new Error(ge);
const e = this._getSheetRef(t);
if (!e) throw new ot(gl(t));
let n = null;
return e.visibility !== bt.Visibility.Visible && this._setSheetVisibility(e, bt.Visibility.Visible), this._view.setActiveSheetId(e.id), n = e.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(t, e) {
return this._emitter.addListeners(t, e);
}
_sheetToWBEvent(t) {
const e = this;
return (n) => {
const r = () => {
const s = n.getSource();
if (s.isICellRanges) {
const i = [...s.getCoords()], l = i.length;
for (let c = 0; c < l; c++) {
const h = i[c];
!h.sheetName && s.getSheet().getName() && (i[c] = { ...h, sheetName: s.getSheet().getName() });
}
return e.getRanges(i);
}
if (s.isICellRange) {
const i = s.getCoords(), l = s.getSheet().getName();
return e.getRange({ ...i, sheetName: l });
}
}, o = { getSource: r, trigger: n.trigger, getFrom: () => e.getRanges(n.getFrom()), getTo: () => e.getRange(n.getTo()), isDataChange: n.isDataChange, isTransactional: n.isTransactional, isUndo: n.isUndo, toString: () => `WorkbookRangeEvent: ('${n.trigger}', ${r().toString()})`, timeStamp: Date.now() };
t(o);
};
}
_fromJSON(t) {
if (this._emitter.notify("onBeforeLoad", { params: t }), this._initState(), !t.sheets || t.sheets.length === 0) throw new ot(ml);
t.theme && (this._theme = new Rl(t.theme), this._styles.setTheme(this._theme));
const e = this._strings.beginPersist(), n = this._resources.beginPersist(), r = this._styles.beginPersist();
try {
e.fromJSON(t.strings), n.fromJSON(t.resources), r.fromJSON(t.styles), t.date1904 && (this._isDate1904 = !0), t.view || (t.view = {});
const o = t.sheets, s = o.length;
let i = t.view.activeSheetId ?? null;
i !== null && (i = Math.min(Math.max(1, i), s));
let l = null;
for (let h = 0; h < s; h++) {
const d = o[h], u = d.visibility || bt.Visibility.Visible, g = h + 1;
u === bt.Visibility.Visible ? l = g : i !== null && i === g && (i = null), this._createSheet(g, d.name, u, void 0, d.sheet);
}
this._updateState({ lastId: l }), t.names && this._names.fromJSON(t.names), t.view.activeSheetId = i ?? l, this.setView(new Ou({ json: t.view })), this._adjustSheetNamesIfRequired(), this._listenerProtection?.();
const c = this;
this._protection = new Lu(t?.protection, this._options?.readonly), this._listenerProtection = this._protection.addListeners({ onChange: (h) => {
c._emitter.notify("onProtectionChange", { source: h });
} }), t.scripts && (this._scripts = this._createScripts(t.scripts)), this._emitter.notify("onLoad");
} finally {
r.endPersist(), n.endPersist(), e.endPersist();
}
}
_createScripts(t) {
const e = this;
return new sy({ transactions: this._transactions, json: t, workbook: e, getBuiltInFunctions: () => e._calculation?.getFunctions(), onAdd: (n, r) => {
const o = e._calculation;
o.getStatus() !== ee.Status.Off && o.start().then(() => {
const s = r.getFunctions().getItems({ type: "formula" }), i = s.length;
for (let l = 0; l < i; l++) {
const c = s[l];
this._calculation.getFunctions().add(c);
}
});
}, onRemove: (n, r) => {
} });
}
async toJSON(t = !1) {
if (this._closed) throw new Error(ge);
await this._emitter.notify("onBeforeSave", { async: !0 });
const e = { sheets: [] };
await Promise.resolve(this._starting);
const n = this._theme.toJSON();
(n ? Object.keys(n).length : 0) > 0 && (e.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(), d = h.sheetRefsAll, u = h.sheetsById, g = d.length;
for (let y = 0; y < g; y++) {
const E = d[y], w = y + 1, b = await u.get(E.id).toJSON(t), v = { name: E.name, sheet: b };
E.visibility === bt.Visibility.Visible ? c = w : v.visibility = E.visibility, E.id === i && (l = w), e.sheets.push(v);
}
const m = s.toJSON();
m && Object.keys(m).length > 0 && (e.styles = m);
const f = this.getProtection().toJSON();
f && (e.protection = f);
const p = await r.toJSONAsync();
p && p.length > 0 && (e.strings = p);
const _ = await o.toJSONAsync();
_ && _.length > 0 && (e.resources = _);
const S = this._names.toJSON();
S && S.length > 0 && (e.names = S);
const C = this._view.toJSON();
C && (l !== c ? C.activeSheetId = l : delete C.activeSheetId, Object.keys(C).length > 0 && (e.view = C));
} finally {
s.endPersist(), o.endPersist(), r.endPersist();
}
if (this._scripts) {
const i = this._scripts.toJSON();
i && Object.keys(i).length > 0 && (e.scripts = i);
}
return this._isDate1904 && (e.date1904 = !0), this._emitter.notify("onSave", { params: e }), e;
}
isClosed() {
return this._closed;
}
close() {
if (this._closed) return;
this._emitter.notify("onClose");
const t = this._getState();
t.listenersSheets.forEach((n) => {
n();
}), t.listenersSheets.clear();
const e = t.sheetRefsAll;
for (let n = e.length - 1; n >= 0; n--) try {
e[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(t) {
if (this._closed) throw new Error(ge);
return this._beginCommit(typeof t == "string" ? { description: t } : t);
}
doBatch(t, e) {
const n = this;
return e = typeof e == "string" ? { description: e } : { description: "Update Workbook", ...e }, this._transactions.doBatch(t, e, (r, o) => {
r.getDepth() === 0 && (n._lastTransactionUUID = r.getId());
});
}
_beginCommit(t) {
const e = this;
return this._transactions.beginCommit(typeof t == "string" ? { description: t } : t, (n) => {
n.getDepth() === 0 && (e._lastTransactionUUID = n.getId());
});
}
_getState() {
return this._transactions.getState(this);
}
_updateState(t, e = "Update Workbook") {
if (!t) return;
const n = this._beginCommit(e);
try {
n.updateState(this, t), n.commit();
} catch (r) {
throw n.rollback(), r;
}
}
get options() {
return this._options;
}
get [Symbol.toStringTag]() {
return "[Workbook]";
}
toString() {
return this._getState().name ?? "";
}
get isIWorkbook() {
return !0;
}
}
const Dr = { address: null, scope: null }, vy = "0.7.27", xy = "Sat Dec 27 2025";
export {
Gl as $,
vi as A,
xy as B,
ae as C,
dc as D,
ve as E,
Sw as F,
fy as G,
Jd as H,
vh as I,
ee as J,
Dm as K,
ju as L,
Yr as M,
Ne as N,
Ft as O,
tw as P,
ou as Q,
Ya as R,
Np as S,
ki as T,
su as U,
vy as V,
yy as W,
iu as X,
Ph as Y,
Gr as Z,
au as _,
$w as a,
gr as a0,
JS as a1,
Lh as a2,
ur as a3,
Rl as a4,
Hg as a5,
on as a6,
Cy as a7,
Ey as a8,
bt as a9,
ns as aa,
Ou as ab,
by as ac,
jw as b,
Xe as c,
wy as d,
tn as e,
Fl as f,
W0 as g,
Tg as h,
Ze as i,
my as j,
zt as k,
_y as l,
Gi as m,
Sy as n,
dt as o,
st as p,
N as q,
dn as r,
U as s,
_e as t,
py as u,
bi as v,
et as w,
mt as x,
cs as y,
Nm as z
};