@univerjs/sheets
Version:
UniverSheet normal base-sheets
1,391 lines • 492 kB
JavaScript
var Ra = Object.defineProperty;
var Ca = (n, e, t) => e in n ? Ra(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
var R = (n, e, t) => Ca(n, typeof e != "symbol" ? e + "" : e, t);
import { CellValueType as ue, isTextFormat as sn, isRealNum as Es, isBooleanString as Rr, willLoseNumericPrecision as pa, UniverInstanceType as G, CommandType as M, IUniverInstanceService as _, Tools as D, createInterceptorKey as wt, Disposable as he, InterceptorEffectEnum as Re, InterceptorManager as uo, toDisposable as Te, remove as Ye, composeInterceptors as Sa, DisposableCollection as xt, BooleanNumber as ie, HorizontalAlign as lo, BorderStyleTypes as Cr, Inject as W, IResourceManagerService as Tn, RTree as wa, generateRandomId as At, ObjectMatrix as Z, Rectangle as O, moveMatrixArray as pr, sliceMatrixArray as Sr, concatMatrixArray as wr, spliceArray as vr, Range as ne, normalizeTextRuns as va, isSafeNumeric as Ia, RANGE_TYPE as z, createRowColIter as Ma, mergeIntervals as Ir, ICommandService as E, IUndoRedoService as V, RxDisposable as Mr, sequenceExecute as L, selectionToArray as _a, createIdentifier as ks, IContextService as _r, ErrorService as Yt, LocaleService as st, cellToRange as yr, PermissionStatus as Q, IPermissionService as ot, isICellData as br, mapObjectMatrix as ya, Dimension as Ie, getArrayLength as Er, Direction as F, throttle as ba, Injector as qt, MAX_ROW_COUNT as xo, MAX_COLUMN_COUNT as Ao, queryObjectMatrix as vt, IConfirmService as Ea, CellModeEnum as ka, FontWeight as Ua, FontItalic as Ta, isFormulaString as Pa, isFormulaId as Na, numfmt as $o, cloneWorksheetData as kr, IConfigService as Pn, mergeWorksheetSnapshotWithDefault as Oa, BorderType as fe, ILogService as Ur, DocumentDataModel as Da, BuildTextUtils as xa, TextX as Aa, CustomCommandExecutionError as $a, IAuthzIoService as Wa, UserManagerService as Va, LRUMap as La, Optional as Ha, isDefaultFormat as Fa, DependentOn as Ba, Plugin as ja, merge as za, IS_ROW_STYLE_PRECEDE_COLUMN_STYLE as Ga, AUTO_HEIGHT_FOR_MERGED_CELLS as Ka, registerDependencies as Ja, mergeOverrideWithDependencies as Ya, touchDependencies as Wn } from "@univerjs/core";
import { Subject as He, BehaviorSubject as We, merge as nn, shareReplay as qa, takeUntil as rt, switchMap as it, of as Ee, distinctUntilChanged as Za, skip as Tr, map as Zs, first as Xa, filter as Wo } from "rxjs";
import { SetDefinedNameMutation as fn, RemoveDefinedNameMutation as Kn, SetDefinedNameMutationFactory as Qa, IDefinedNamesService as Pr, LexerTreeBuilder as eu, operatorToken as tu, deserializeRangeWithSheet as nu, sequenceNodeType as su, deserializeRangeWithSheetWithCache as ou, SetFormulaCalculationResultMutation as ru, handleNumfmtInCell as iu, stripErrorMargin as au, UniverFormulaEnginePlugin as uu } from "@univerjs/engine-formula";
import { takeUntil as Vo, filter as Lo, map as lu } from "rxjs/operators";
import { DataSyncPrimaryController as cu } from "@univerjs/rpc";
function du(n, e, t) {
var r, i, a;
if (e.t) return e.t;
if (e.v === null) return null;
const s = n.getStyleByCell(e), o = n.getStyleByCell(t);
if (t.t === ue.FORCE_STRING) {
if (!sn((r = o == null ? void 0 : o.n) == null ? void 0 : r.pattern) && e.v !== void 0) {
if (Es(e.v))
return ue.NUMBER;
if (Rr(`${e.v}`))
return ue.BOOLEAN;
}
return ue.FORCE_STRING;
}
return hu(s) ? sn((i = s == null ? void 0 : s.n) == null ? void 0 : i.pattern) ? ue.STRING : Ho(e, t) : sn((a = o == null ? void 0 : o.n) == null ? void 0 : a.pattern) ? ue.STRING : Ho(e, t);
}
function Ho(n, e) {
return n.v !== void 0 ? Fo(n.v, n.t) : Fo(e.v, e.t);
}
function hu(n) {
var e;
return !!((e = n == null ? void 0 : n.n) != null && e.pattern);
}
function Fo(n, e) {
return n === null ? null : typeof n == "string" ? Es(n) ? (+n == 0 || +n == 1) && e === ue.BOOLEAN ? ue.BOOLEAN : e !== ue.STRING && e !== ue.FORCE_STRING && pa(n) ? ue.FORCE_STRING : ue.NUMBER : Rr(n) ? ue.BOOLEAN : ue.STRING : typeof n == "number" ? (n === 0 || n === 1) && e === ue.BOOLEAN ? ue.BOOLEAN : ue.NUMBER : typeof n == "boolean" ? ue.BOOLEAN : ue.FORCE_STRING;
}
function Nr(n, e) {
const { unitId: t } = e, s = t ? n.getUnit(t, G.UNIVER_SHEET) : n.getCurrentUnitOfType(G.UNIVER_SHEET);
return s ? {
workbook: s,
unitId: s.getUnitId()
} : null;
}
function k(n, e = {}) {
const { unitId: t, subUnitId: s } = e, o = t ? n.getUnit(t, G.UNIVER_SHEET) : n.getCurrentUnitOfType(G.UNIVER_SHEET);
if (!o) return null;
const r = s ? o.getSheetBySheetId(s) : o.getActiveSheet(!0);
return r ? {
worksheet: r,
workbook: o,
unitId: o.getUnitId(),
subUnitId: r.getSheetId()
} : null;
}
function Se(n, e) {
const { unitId: t, subUnitId: s } = e, o = n.getUnit(t, G.UNIVER_SHEET);
if (!o) return null;
const r = o.getSheetBySheetId(s);
return r ? {
worksheet: r,
workbook: o
} : null;
}
const Ae = (n, e) => {
if (!Se(n.get(_), e))
throw new Error("Workbook or worksheet is null error!");
return {
unitId: e.unitId,
subUnitId: e.subUnitId,
ranges: D.deepClone(e.ranges)
};
}, re = {
id: "sheet.mutation.add-worksheet-merge",
type: M.MUTATION,
handler: (n, e) => {
const t = Se(n.get(_), e);
if (!t)
throw new Error("Workbook or worksheet is null error!");
const { worksheet: s } = t, r = s.getConfig().mergeData, i = e.ranges;
for (let a = 0; a < i.length; a++)
r.push(i[a]);
return s.getSpanModel().rebuild(r), !0;
}
}, gu = wt("CELL_CONTENT"), mu = wt("ROW_FILTERED"), Rt = {
CELL_CONTENT: gu,
ROW_FILTERED: mu
};
var fu = /* @__PURE__ */ ((n) => (n[n.DATA_VALIDATION = 9] = "DATA_VALIDATION", n[n.NUMFMT = 10] = "NUMFMT", n[n.CELL_IMAGE = 11] = "CELL_IMAGE", n))(fu || {});
const Or = "sheet.interceptor.range-theme-id", Bo = "sheet.interceptor.ignore-range-theme";
var Ru = Object.getOwnPropertyDescriptor, Cu = (n, e, t, s) => {
for (var o = s > 1 ? void 0 : s ? Ru(e, t) : e, r = n.length - 1, i; r >= 0; r--)
(i = n[r]) && (o = i(o) || o);
return o;
}, pu = (n, e) => (t, s) => e(t, s, n);
const jo = wt("BEFORE_CELL_EDIT"), Vs = wt("AFTER_CELL_EDIT"), Ls = wt("VALIDATE_CELL");
let Y = class extends he {
/** @ignore */
constructor(e) {
super();
R(this, "_interceptorsByName", /* @__PURE__ */ new Map());
R(this, "_commandInterceptors", []);
R(this, "_rangeInterceptors", []);
R(this, "_autoHeightInterceptors", []);
R(this, "_beforeCommandInterceptor", []);
R(this, "_afterCommandInterceptors", []);
R(this, "_workbookDisposables", /* @__PURE__ */ new Map());
R(this, "_worksheetDisposables", /* @__PURE__ */ new Map());
R(this, "_interceptorsDirty", !1);
R(this, "_composedInterceptorByKey", /* @__PURE__ */ new Map());
R(this, "writeCellInterceptor", new uo({
BEFORE_CELL_EDIT: jo,
AFTER_CELL_EDIT: Vs,
VALIDATE_CELL: Ls
}));
this._univerInstanceService = e, this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(G.UNIVER_SHEET).subscribe((t) => {
this._interceptWorkbook(t);
})), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(G.UNIVER_SHEET).subscribe(
(t) => this._disposeWorkbookInterceptor(t)
)), this.intercept(Rt.CELL_CONTENT, {
priority: -1,
effect: Re.Style | Re.Value,
handler: (t) => t
}), this.disposeWithMe(this.writeCellInterceptor.intercept(Vs, {
priority: -1,
handler: (t) => t
})), this.disposeWithMe(this.writeCellInterceptor.intercept(jo, {
priority: -1,
handler: (t) => t
})), this.disposeWithMe(this.writeCellInterceptor.intercept(Ls, {
priority: -1,
handler: (t) => t
}));
}
dispose() {
super.dispose(), this._workbookDisposables.forEach((e) => e.dispose()), this._workbookDisposables.clear(), this._worksheetDisposables.forEach((e) => e.dispose()), this._worksheetDisposables.clear(), this._interceptorsByName.clear();
}
// #region intercept command execution
/**
* Add a listener function to a specific command to add affiliated mutations. It should be called in controllers.
*
* Pairs with {@link onCommandExecute}.
*
* @param interceptor
* @returns
*/
interceptCommand(e) {
if (this._commandInterceptors.includes(e))
throw new Error("[SheetInterceptorService]: Interceptor already exists!");
return this._commandInterceptors.push(e), this._commandInterceptors.sort((t, s) => {
var o, r;
return ((o = s.priority) != null ? o : 0) - ((r = t.priority) != null ? r : 0);
}), this.disposeWithMe(Te(() => Ye(this._commandInterceptors, e)));
}
/**
* When command is executing, call this method to gether undo redo mutations from upper features.
* @param command
* @returns
*/
onCommandExecute(e) {
const t = this._commandInterceptors.map((s) => s.getMutations(e));
return {
preUndos: t.map((s) => {
var o;
return (o = s.preUndos) != null ? o : [];
}).flat(),
undos: t.map((s) => s.undos).flat(),
preRedos: t.map((s) => {
var o;
return (o = s.preRedos) != null ? o : [];
}).flat(),
redos: t.map((s) => s.redos).flat()
};
}
interceptAfterCommand(e) {
if (this._afterCommandInterceptors.includes(e))
throw new Error("[SheetInterceptorService]: Interceptor already exists!");
return this._afterCommandInterceptors.push(e), this._afterCommandInterceptors.sort((t, s) => {
var o, r;
return ((o = s.priority) != null ? o : 0) - ((r = t.priority) != null ? r : 0);
}), this.disposeWithMe(Te(() => Ye(this._afterCommandInterceptors, e)));
}
afterCommandExecute(e) {
const t = this._afterCommandInterceptors.map((s) => s.getMutations(e));
return {
undos: t.map((s) => s.undos).flat(),
redos: t.map((s) => s.redos).flat()
};
}
interceptAutoHeight(e) {
if (this._autoHeightInterceptors.includes(e))
throw new Error("[SheetInterceptorService]: Interceptor already exists!");
return this._autoHeightInterceptors.push(e), this._autoHeightInterceptors.sort((t, s) => {
var o, r;
return ((o = s.priority) != null ? o : 0) - ((r = t.priority) != null ? r : 0);
}), this.disposeWithMe(Te(() => Ye(this._autoHeightInterceptors, e)));
}
generateMutationsOfAutoHeight(e) {
const t = this._autoHeightInterceptors.map((s) => s.getMutations(e));
return {
preUndos: t.map((s) => {
var o;
return (o = s.preUndos) != null ? o : [];
}).flat(),
undos: t.map((s) => s.undos).flat(),
preRedos: t.map((s) => {
var o;
return (o = s.preRedos) != null ? o : [];
}).flat(),
redos: t.map((s) => s.redos).flat()
};
}
/**
* Add a listener function to a specific command to determine if the command can execute mutations. It should be
* called in controllers.
*
* Pairs with {@link beforeCommandExecute}.
*
* @param interceptor
* @returns
*/
interceptBeforeCommand(e) {
if (this._beforeCommandInterceptor.includes(e))
throw new Error("[SheetInterceptorService]: Interceptor already exists!");
return this._beforeCommandInterceptor.push(e), this._beforeCommandInterceptor.sort((t, s) => {
var o, r;
return ((o = s.priority) != null ? o : 0) - ((r = t.priority) != null ? r : 0);
}), this.disposeWithMe(Te(() => Ye(this._beforeCommandInterceptor, e)));
}
/**
* before command execute, call this method to get the flag of whether it can be executed the command,
* @param info ICommandInfo
* @returns Promise<boolean>
*/
async beforeCommandExecute(e) {
return (await Promise.all(this._beforeCommandInterceptor.map((s) => s.performCheck(e)))).every((s) => s);
}
// #endregion
// #region intercept ranges - mainly for pivot table currently (2024/10/28).
/**
* By adding callbacks to some Ranges can get some additional mutations, such as clearing all plugin data in a certain area.
* @param interceptor IRangeInterceptors
* @returns IDisposable
*/
interceptRanges(e) {
if (this._rangeInterceptors.includes(e))
throw new Error("[SheetInterceptorService]: Interceptor already exists!");
return this._rangeInterceptors.push(e), this._rangeInterceptors.sort((t, s) => {
var o, r;
return ((o = s.priority) != null ? o : 0) - ((r = t.priority) != null ? r : 0);
}), this.disposeWithMe(Te(() => Ye(this._rangeInterceptors, e)));
}
generateMutationsByRanges(e) {
const t = this._rangeInterceptors.map((s) => s.getMutations(e));
return {
preUndos: t.map((s) => {
var o;
return (o = s.preUndos) != null ? o : [];
}).flat(),
undos: t.map((s) => s.undos).flat(),
preRedos: t.map((s) => {
var o;
return (o = s.preRedos) != null ? o : [];
}).flat(),
redos: t.map((s) => s.redos).flat()
};
}
// #endregion
// #region intercept on writing cell
onWriteCell(e, t, s, o, r) {
const i = {
subUnitId: t.getSheetId(),
unitId: e.getUnitId(),
workbook: e,
worksheet: t,
row: s,
col: o,
origin: D.deepClone(r)
};
return this.writeCellInterceptor.fetchThroughInterceptors(Vs)(r, i);
}
// #endregion
onValidateCell(e, t, s, o) {
const r = {
subUnitId: t.getSheetId(),
unitId: e.getUnitId(),
workbook: e,
worksheet: t,
row: s,
col: o
};
return this.writeCellInterceptor.fetchThroughInterceptors(Ls)(Promise.resolve(!0), r);
}
intercept(e, t) {
const s = e;
this._interceptorsByName.has(s) || this._interceptorsByName.set(s, []);
const o = this._interceptorsByName.get(s);
o.push(t);
const r = o.sort((i, a) => {
var u, l;
return ((u = a.priority) != null ? u : 0) - ((l = i.priority) != null ? l : 0);
});
if (this._interceptorsDirty = !0, s === Rt.CELL_CONTENT) {
const i = Re.Style | Re.Value;
this._interceptorsByName.set(`${s}-${i}`, r);
const a = Re.Style | Re.Value;
return this._interceptorsByName.set(
`${s}-${Re.Style}`,
r.filter((u) => ((u.effect || a) & Re.Style) > 0)
), this._interceptorsByName.set(
`${s}-${Re.Value}`,
r.filter((u) => ((u.effect || a) & Re.Value) > 0)
), this.disposeWithMe(Te(() => {
Ye(this._interceptorsByName.get(s), t), Ye(this._interceptorsByName.get(`${s}-${i}`), t), Ye(this._interceptorsByName.get(`${s}-${Re.Style}`), t), Ye(this._interceptorsByName.get(`${s}-${Re.Value}`), t);
}));
} else
return this._interceptorsByName.set(s, r), this.disposeWithMe(Te(() => Ye(this._interceptorsByName.get(s), t)));
}
fetchThroughInterceptors(e, t, s, o) {
const r = t === void 0 ? e : `${e}-${t}`, i = s != null ? s : r;
let a = this._composedInterceptorByKey.get(i);
if (!a || !this._interceptorsDirty) {
let u = this._interceptorsByName.get(r);
u && o && (u = u.filter(o)), a = Sa(u || []), this._composedInterceptorByKey.set(i, a);
}
return a;
}
_interceptWorkbook(e) {
const t = new xt(), s = e.getUnitId(), o = this, r = (i) => {
const a = i.getSheetId();
i.__interceptViewModel((u) => {
const l = new xt();
o._worksheetDisposables.set(zo(s, i), l), l.add(u.registerCellContentInterceptor({
getCell(c, d, h, g, m) {
const f = i.getCellRaw(c, d);
return o.fetchThroughInterceptors(Rt.CELL_CONTENT, h, g, m)(
f,
{
unitId: s,
subUnitId: a,
row: c,
col: d,
worksheet: i,
workbook: e,
rawData: f
}
);
}
})), l.add(u.registerRowFilteredInterceptor({
getRowFiltered(c) {
return !!o.fetchThroughInterceptors(Rt.ROW_FILTERED)(
!1,
{
unitId: s,
subUnitId: a,
row: c,
workbook: e,
worksheet: i
}
);
}
}));
});
};
e.getSheets().forEach((i) => r(i)), t.add(e.sheetCreated$.subscribe((i) => r(i))), t.add(Te(() => e.getSheets().forEach((i) => this._disposeSheetInterceptor(s, i)))), t.add(e.sheetDisposed$.subscribe((i) => this._disposeSheetInterceptor(s, i))), this._workbookDisposables.set(s, t);
}
_disposeWorkbookInterceptor(e) {
const t = e.getUnitId(), s = this._workbookDisposables.get(t);
s && (s.dispose(), this._workbookDisposables.delete(t));
}
_disposeSheetInterceptor(e, t) {
const s = zo(e, t), o = this._worksheetDisposables.get(s);
o && (o.dispose(), this._worksheetDisposables.delete(s));
}
};
Y = Cu([
pu(0, _)
], Y);
function zo(n, e) {
return `${n}|${e.getSheetId()}`;
}
const Ce = (n) => {
const e = {};
return n.bg && (e.bg = { ...n.bg }), n.ol && (e.ol = { ...n.ol }), n.bd && (e.bd = { ...n.bd }), n.cl && (e.cl = { ...n.cl }), n.ht && (e.ht = n.ht), n.vt && (e.vt = n.vt), n.bl !== void 0 && (e.bl = n.bl), e;
};
function Su(n) {
const e = {};
if (n.length === 1)
return n[0];
for (const t of n)
t.bg && (e.bg = t.bg), t.ol && (e.ol = t.ol), t.bd && (e.bd = { ...e.bd, ...t.bd }), t.cl && (e.cl = t.cl), t.ht && (e.ht = t.ht), t.vt && (e.vt = t.vt), t.bl !== void 0 && (e.bl = t.bl);
return e;
}
const ge = {
wholeStyle: 1,
headerRowStyle: 2,
headerColumnStyle: 4,
firstRowStyle: 8,
secondRowStyle: 16,
lastRowStyle: 32,
firstColumnStyle: 128,
secondColumnStyle: 256,
lastColumnStyle: 512
};
class It {
/**
* @constructor
* @param {string} name The name of the range theme style, it used to identify the range theme style.
* @param {IRangeThemeStyleJSON} [options] The options to initialize the range theme style.
*/
constructor(e, t) {
R(this, "_name");
/**
* @property {Nullable<IRangeThemeStyleItem>} wholeStyle effect for the whole range.
*/
R(this, "wholeStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} headerRowStyle effect for the header row.
*/
R(this, "headerRowStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} headerColumnStyle effect for the header column.
*/
R(this, "headerColumnStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} firstRowStyle effect for the first row.
*/
R(this, "firstRowStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} secondRowStyle effect for the second row.
*/
R(this, "secondRowStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} lastRowStyle effect for the last row.
*/
R(this, "lastRowStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} firstColumnStyle effect for the first column.
*/
R(this, "firstColumnStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} secondColumnStyle effect for the second column.
*/
R(this, "secondColumnStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} lastColumnStyle effect for the last column.
*/
R(this, "lastColumnStyle", null);
/**
* @property {Nullable<IRangeThemeStyleItem>} quickly get merge style
*/
R(this, "_mergeCacheMap", /* @__PURE__ */ new Map());
t && this.fromJson({ ...t, name: e }), this._name = e;
}
/**
* Gets the name of the range theme style.The name is read only, and use to identifier the range theme style.
* @returns {string} The name of the range theme style.
*/
getName() {
return this._name;
}
getWholeStyle() {
return this.wholeStyle;
}
setWholeStyle(e) {
this.wholeStyle = e, this._resetStyleCache();
}
getFirstRowStyle() {
return this.firstRowStyle;
}
setFirstRowStyle(e) {
this.firstRowStyle = e, this._resetStyleCache();
}
getSecondRowStyle() {
return this.secondRowStyle;
}
setSecondRowStyle(e) {
this.secondRowStyle = e, this._resetStyleCache();
}
getLastRowStyle() {
return this.lastRowStyle;
}
setLastRowStyle(e) {
this.lastRowStyle = e, this._resetStyleCache();
}
getFirstColumnStyle() {
return this.firstColumnStyle;
}
setFirstColumnStyle(e) {
this.firstColumnStyle = e, this._resetStyleCache();
}
getSecondColumnStyle() {
return this.secondColumnStyle;
}
setSecondColumnStyle(e) {
this.secondColumnStyle = e, this._resetStyleCache();
}
getLastColumnStyle() {
return this.lastColumnStyle;
}
setLastColumnStyle(e) {
this.lastColumnStyle = e, this._resetStyleCache();
}
getHeaderRowStyle() {
return this.headerRowStyle;
}
setHeaderRowStyle(e) {
this.headerRowStyle = e, this._resetStyleCache();
}
getHeaderColumnStyle() {
return this.headerColumnStyle;
}
setHeaderColumnStyle(e) {
this.headerColumnStyle = e, this._resetStyleCache();
}
getStyle(e, t, s, o, r) {
let i = 0;
return s && (i = i | ge.lastRowStyle), o && (i = i | ge.lastColumnStyle), e >= 0 && t >= 0 && (i = i | ge.wholeStyle), e % 2 === 1 && (i = i | (r ? ge.secondRowStyle : ge.firstRowStyle)), e % 2 === 0 && (i = i | (r ? ge.firstRowStyle : ge.secondRowStyle)), e === 0 && (i = i | ge.headerRowStyle), t === 0 && (i = i | ge.headerColumnStyle), t % 2 === 1 && (i = i | ge.firstColumnStyle), t % 2 === 0 && (i = i | ge.secondColumnStyle), i === 0 ? null : this._getMergeStyle(i);
}
_getMergeStyle(e) {
let t = this._mergeCacheMap.get(e);
return t || (t = this._mergeStyle(e), this._mergeCacheMap.set(e, t)), t;
}
_mergeStyle(e) {
const t = [];
return this.wholeStyle && e & ge.wholeStyle && t.push(this.wholeStyle), this.firstColumnStyle && e & ge.firstColumnStyle && t.push(this.firstColumnStyle), this.secondColumnStyle && e & ge.secondColumnStyle && t.push(this.secondColumnStyle), this.firstRowStyle && e & ge.firstRowStyle && t.push(this.firstRowStyle), this.secondRowStyle && e & ge.secondRowStyle && t.push(this.secondRowStyle), this.headerColumnStyle && e & ge.headerColumnStyle && t.push(this.headerColumnStyle), this.lastColumnStyle && e & ge.lastColumnStyle && t.push(this.lastColumnStyle), this.headerRowStyle && e & ge.headerRowStyle && t.push(this.headerRowStyle), this.lastRowStyle && e & ge.lastRowStyle && t.push(this.lastRowStyle), Su(t);
}
_resetStyleCache() {
this._mergeCacheMap.clear();
}
toJson() {
const e = {
name: this._name
};
return this.wholeStyle && (e.wholeStyle = Ce(this.wholeStyle)), this.headerRowStyle && (e.headerRowStyle = Ce(this.headerRowStyle)), this.headerColumnStyle && (e.headerColumnStyle = Ce(this.headerColumnStyle)), this.firstRowStyle && (e.firstRowStyle = Ce(this.firstRowStyle)), this.secondRowStyle && (e.secondRowStyle = Ce(this.secondRowStyle)), this.lastRowStyle && (e.lastRowStyle = Ce(this.lastRowStyle)), this.firstColumnStyle && (e.firstColumnStyle = Ce(this.firstColumnStyle)), this.secondColumnStyle && (e.secondColumnStyle = Ce(this.secondColumnStyle)), this.lastColumnStyle && (e.lastColumnStyle = Ce(this.lastColumnStyle)), e;
}
fromJson(e) {
this._name = e.name, e.wholeStyle && (this.wholeStyle = Ce(e.wholeStyle)), e.headerRowStyle && (this.headerRowStyle = Ce(e.headerRowStyle)), e.headerColumnStyle && (this.headerColumnStyle = Ce(e.headerColumnStyle)), e.firstRowStyle && (this.firstRowStyle = Ce(e.firstRowStyle)), e.secondRowStyle && (this.secondRowStyle = Ce(e.secondRowStyle)), e.lastRowStyle && (this.lastRowStyle = Ce(e.lastRowStyle)), e.firstColumnStyle && (this.firstColumnStyle = Ce(e.firstColumnStyle)), e.secondColumnStyle && (this.secondColumnStyle = Ce(e.secondColumnStyle)), e.lastColumnStyle && (this.lastColumnStyle = Ce(e.lastColumnStyle));
}
dispose() {
this._mergeCacheMap.clear();
}
}
const wu = (n, e, t) => new It(`light-${n}`, {
headerRowStyle: {
bg: {
rgb: e
}
},
firstColumnStyle: {
bg: {
rgb: "rgb(255, 255, 255)"
}
},
secondColumnStyle: {
bg: {
rgb: t
}
},
lastRowStyle: {
bg: {
rgb: e
}
}
}), vu = (n, e, t) => new It(`middle-${n}`, {
headerRowStyle: {
bg: {
rgb: e
}
},
headerColumnStyle: {
bg: {
rgb: t
}
},
secondRowStyle: {
bg: {
rgb: t
}
},
lastRowStyle: {
bg: {
rgb: e
}
},
lastColumnStyle: {
bg: {
rgb: t
}
}
}), Iu = (n, e, t, s) => new It(`dark-${n}`, {
headerRowStyle: {
bg: {
rgb: e
},
cl: {
rgb: "rgb(255, 255, 255)"
},
ht: lo.CENTER,
bl: ie.TRUE
},
firstRowStyle: {
bg: {
rgb: t
}
},
secondRowStyle: {
bg: {
rgb: s
}
},
lastRowStyle: {
bg: {
rgb: e
}
}
}), Mu = [
{
baseName: "blue",
header: "rgb(164, 202, 254)",
color: "rgb(225, 239, 254)"
},
{
baseName: "grey",
header: "rgb(205, 208, 216)",
color: "rgb(238, 239, 241)"
},
{
baseName: "red",
header: "rgb(248, 180, 180)",
color: "rgb(253, 232, 232)"
},
{
baseName: "orange",
header: "rgb(253, 186, 140)",
color: "rgb(254, 236, 220)"
},
{
baseName: "yellow",
header: "rgb(250, 200, 21)",
color: "rgb(255, 244, 185)"
},
{
baseName: "green",
header: "rgb(132, 225, 188)",
color: "rgb(222, 247, 236)"
},
{
baseName: "azure",
header: "rgb(126, 220, 226)",
color: "rgb(213, 245, 246)"
},
{
baseName: "indigo",
header: "rgb(186, 198, 248)",
color: "rgb(233, 237, 255)"
},
{
baseName: "purple",
header: "rgb(202, 191, 253)",
color: "rgb(237, 235, 254)"
},
{
baseName: "magenta",
header: "rgb(248, 180, 217)",
color: "rgb(252, 232, 243)"
}
], _u = [
{
baseName: "blue",
rowHeader: "rgb(63, 131, 248)",
colHeader: "rgb(195, 221, 253)"
},
{
baseName: "grey",
rowHeader: "rgb(95, 101, 116)",
colHeader: "rgb(227, 229, 234)"
},
{
baseName: "red",
rowHeader: "rgb(240, 82, 82)",
colHeader: "rgb(251, 213, 213)"
},
{
baseName: "orange",
rowHeader: "rgb(255, 90, 31)",
colHeader: "rgb(252, 217, 189)"
},
{
baseName: "yellow",
rowHeader: "rgb(212, 157, 15)",
colHeader: "rgb(252, 220, 106)"
},
{
baseName: "green",
rowHeader: "rgb(13, 164, 113)",
colHeader: "rgb(188, 240, 218)"
},
{
baseName: "azure",
rowHeader: "rgb(6, 148, 162)",
colHeader: "rgb(175, 236, 239)"
},
{
baseName: "indigo",
rowHeader: "rgb(70, 106, 247)",
colHeader: "rgb(210, 218, 250)"
},
{
baseName: "purple",
rowHeader: "rgb(144, 97, 249)",
colHeader: "rgb(220, 215, 254)"
},
{
baseName: "magenta",
rowHeader: "rgb(231, 70, 148)",
colHeader: "rgb(250, 209, 232)"
}
], yu = [
{
baseName: "blue",
rowHeader: "rgb(30, 66, 159)",
firstRow: "rgb(195, 221, 253)",
secondRow: "rgb(118, 169, 250)"
},
{
baseName: "grey",
rowHeader: "rgb(44, 48, 64)",
firstRow: "rgb(227, 229, 234)",
secondRow: "rgb(151, 157, 172)"
},
{
baseName: "red",
rowHeader: "rgb(155, 28, 28)",
firstRow: "rgb(251, 213, 213)",
secondRow: "rgb(249, 128, 128)"
},
{
baseName: "orange",
rowHeader: "rgb(180, 52, 3)",
firstRow: "rgb(252, 217, 189)",
secondRow: "rgb(255, 138, 76)"
},
{
baseName: "yellow",
rowHeader: "rgb(154, 109, 21)",
firstRow: "rgb(252, 220, 106)",
secondRow: "rgb(212, 157, 15)"
},
{
baseName: "green",
rowHeader: "rgb(4, 108, 78)",
firstRow: "rgb(188, 240, 218)",
secondRow: "rgb(49, 196, 141)"
},
{
baseName: "azure",
rowHeader: "rgb(3, 102, 114)",
firstRow: "rgb(175, 236, 239)",
secondRow: "rgb(22, 189, 202)"
},
{
baseName: "indigo",
rowHeader: "rgb(16, 51, 191)",
firstRow: "rgb(210, 218, 250)",
secondRow: "rgb(98, 128, 249)"
},
{
baseName: "purple",
rowHeader: "rgb(74, 29, 150)",
firstRow: "rgb(220, 215, 254)",
secondRow: "rgb(172, 148, 250)"
},
{
baseName: "magenta",
rowHeader: "rgb(153, 21, 75)",
firstRow: "rgb(250, 209, 232)",
secondRow: "rgb(241, 126, 184)"
}
], bu = Mu.map(({ baseName: n, header: e, color: t }) => wu(n, e, t)), Eu = _u.map(({ baseName: n, rowHeader: e, colHeader: t }) => vu(n, e, t)), ku = yu.map(({ baseName: n, rowHeader: e, firstRow: t, secondRow: s }) => Iu(n, e, t, s)), Uu = [
...bu,
...Eu,
...ku
], Dr = {
headerRowStyle: {
bg: {
rgb: "rgb(68,114,196)"
},
cl: {
rgb: "rgb(255,255,255)"
},
ht: lo.CENTER,
bl: ie.TRUE
},
firstRowStyle: {
bg: {
rgb: "rgb(217,225,242)"
}
}
}, Tu = new It("default", Dr), Pu = new It("default-last-row", {
...Dr,
lastRowStyle: {
bd: {
t: {
s: Cr.THIN,
cl: {
rgb: "rgb(68,114,196)"
}
}
},
ht: lo.CENTER,
bl: ie.TRUE
}
});
class Nu {
constructor() {
R(this, "_toggleRanges", []);
}
/**
* Refresh the cache based on the given range and visibility function.
* This method calculates toggle ranges for rows that are visible within the specified range.
* Hidden rows are excluded from the toggle calculation.
* @param range The range of rows to refresh (startRow and endRow are required).
* @param visibleFunc A function to determine if a row is visible.
*/
refresh(e, t) {
const { startRow: s, endRow: o } = e, r = [];
let i = 0, a = !1, u = -1;
for (let l = s; l <= o; l++) {
if (!t(l)) {
i++, i % 2 === 1 ? a = !0 : (a = !1, u !== -1 && (r.push([u, l - 1]), u = -1));
continue;
}
i % 2 === 1 ? a ? u === -1 && (u = l) : (a = !0, u = l) : a && (r.push([u, l - 2]), a = !1, u = -1), l === o && a && r.push([u, l]);
}
this._toggleRanges = r;
}
/**
* This function returns the toggle ranges. Only for testing purposes. In production, you should use `getIsToggled` to check if a row is toggled.
* @returns [IToggleRange[]] The toggle ranges calculated by the last refresh.
*/
getToggleRanges() {
return this._toggleRanges.concat();
}
/**
* Check if the given row is toggled (odd/even state).
* This method uses binary search to efficiently determine if the row is within a toggle range.
* @param row The row to check.
* @returns True if the row is toggled (odd), false otherwise (even or hidden).
*/
getIsToggled(e) {
let t = 0, s = this._toggleRanges.length - 1;
for (; t <= s; ) {
const o = Math.floor((t + s) / 2), [r, i] = this._toggleRanges[o];
if (e < r)
s = o - 1;
else if (e > i)
t = o + 1;
else
return !0;
}
return !1;
}
}
var Ou = Object.getOwnPropertyDescriptor, Du = (n, e, t, s) => {
for (var o = s > 1 ? void 0 : s ? Ou(e, t) : e, r = n.length - 1, i; r >= 0; r--)
(i = n[r]) && (o = i(o) || o);
return o;
}, Hs = (n, e) => (t, s) => e(t, s, n);
const xu = "SHEET_RANGE_THEME_MODEL_PLUGIN";
let ke = class extends he {
constructor(e, t, s) {
super();
R(this, "_rangeThemeStyleMap", /* @__PURE__ */ new Map());
R(this, "_rangeThemeStyleRuleMap", /* @__PURE__ */ new Map());
R(this, "_rTreeCollection", /* @__PURE__ */ new Map());
R(this, "_defaultRangeThemeMap", /* @__PURE__ */ new Map());
/**
* This map is used to cache zebra crossing toggle ranges for each unitId and subUnitId, IRangeThemeStyleRule id
*/
R(this, "_zebraCrossingCacheMap", /* @__PURE__ */ new Map());
R(this, "_rowVisibleFuncSet", /* @__PURE__ */ new Map());
R(this, "_rangeThemeMapChanged$", new He());
R(this, "rangeThemeMapChange$", this._rangeThemeMapChanged$.asObservable());
this._sheetInterceptorService = e, this._resourceManagerService = t, this._univerInstanceService = s, this._registerIntercept(), this._initSnapshot(), this._initDefaultTheme();
}
_initDefaultTheme() {
this.registerDefaultRangeTheme(Tu), this.registerDefaultRangeTheme(Pu);
for (const e of Uu)
this.registerDefaultRangeTheme(e);
}
_ensureRangeThemeStyleMap(e) {
return this._rangeThemeStyleMap.has(e) || this._rangeThemeStyleMap.set(e, /* @__PURE__ */ new Map()), this._rangeThemeStyleMap.get(e);
}
_ensureRangeThemeStyleRuleMap(e) {
return this._rangeThemeStyleRuleMap.has(e) || this._rangeThemeStyleRuleMap.set(e, /* @__PURE__ */ new Map()), this._rangeThemeStyleRuleMap.get(e);
}
_ensureRTreeCollection(e) {
return this._rTreeCollection.has(e) || this._rTreeCollection.set(e, new wa()), this._rTreeCollection.get(e);
}
getDefaultRangeThemeStyle(e) {
return this._defaultRangeThemeMap.get(e);
}
getCustomRangeThemeStyle(e, t) {
return this._ensureRangeThemeStyleMap(e).get(t);
}
_getSheetRowVisibleFuncSet(e, t) {
this._rowVisibleFuncSet.has(e) || this._rowVisibleFuncSet.set(e, /* @__PURE__ */ new Map());
const s = this._rowVisibleFuncSet.get(e);
return s.has(t) || s.set(t, /* @__PURE__ */ new Set()), s.get(t);
}
_getSheetRowVisibleHasInit(e, t) {
var s;
return !!(this._rowVisibleFuncSet.has(e) && ((s = this._rowVisibleFuncSet.get(e)) != null && s.has(t)));
}
refreshSheetRowVisibleFuncSet(e, t) {
const s = this._getSheetRowVisibleFuncSet(e, t);
s.clear();
const o = this._univerInstanceService.getUnit(e);
if (o) {
const r = o.getSheetBySheetId(t);
if (r) {
const i = r.getRowCount(), a = r.getRowManager();
for (let u = 1; u <= i; u++)
r.getRowVisible(u) ? a.getRowHeight(u) === 0 && s.add(u) : s.add(u);
}
}
}
_ensureZebraCrossingCache(e, t, s) {
this._zebraCrossingCacheMap.has(e) || this._zebraCrossingCacheMap.set(e, /* @__PURE__ */ new Map());
const o = this._zebraCrossingCacheMap.get(e);
o.has(t) || o.set(t, /* @__PURE__ */ new Map());
const r = o.get(t);
return r.has(s) || r.set(s, new Nu()), r.get(s);
}
/**
* Register range theme styles
* @param {string} themeName
* @param {IRangeThemeRangeInfo} rangeInfo
*/
registerRangeThemeRule(e, t) {
const { unitId: s, subUnitId: o, range: r } = t, i = At(), a = this._ensureRangeThemeStyleRuleMap(s), u = this._ensureRTreeCollection(s);
a.set(i, { rangeInfo: t, themeName: e }), u.insert({ unitId: s, sheetId: o, range: r, id: i }), this._getSheetRowVisibleHasInit(s, o) || this.refreshSheetRowVisibleFuncSet(s, o);
const l = this._ensureZebraCrossingCache(s, o, i), c = this._getSheetRowVisibleFuncSet(s, o);
l.refresh(r, (d) => !c.has(d));
}
getRegisteredRangeThemeStyle(e) {
const { unitId: t, subUnitId: s, range: o } = e, r = this._ensureRTreeCollection(t), i = Array.from(r.bulkSearch([{ unitId: t, sheetId: s, range: o }]));
if (i[0]) {
const u = this._ensureRangeThemeStyleRuleMap(t).get(i[0]);
if (u)
return u.themeName;
}
}
refreshZebraCrossingCacheBySheet(e, t) {
this._zebraCrossingCacheMap.has(e) || this._zebraCrossingCacheMap.set(e, /* @__PURE__ */ new Map());
const s = this._zebraCrossingCacheMap.get(e);
s.has(t) || s.set(t, /* @__PURE__ */ new Map());
const o = s.get(t);
o && o.forEach((r, i) => {
const u = this._ensureRangeThemeStyleRuleMap(e).get(i);
u ? r.refresh(u.rangeInfo.range, (l) => !this._getSheetRowVisibleFuncSet(e, t).has(l)) : o.delete(i);
});
}
removeRangeThemeRule(e, t) {
const { unitId: s, subUnitId: o, range: r } = t, i = this._ensureRTreeCollection(s), a = Array.from(i.bulkSearch([{ unitId: s, sheetId: o, range: r }])), u = this._ensureRangeThemeStyleRuleMap(s);
for (let l = 0; l < a.length; l++) {
const c = u.get(a[l]);
if (c && c.themeName === e) {
u.delete(a[l]), i.remove({ unitId: s, sheetId: o, range: r, id: a[l] });
const d = this._zebraCrossingCacheMap.get(s);
if (d) {
const h = d.get(o);
h && h.delete(a[l]);
}
break;
}
}
}
registerDefaultRangeTheme(e) {
this._defaultRangeThemeMap.set(e.getName(), e), this._rangeThemeMapChanged$.next({ type: "add", styleName: e.getName() });
}
unRegisterDefaultRangeTheme(e) {
this._defaultRangeThemeMap.delete(e), this._rangeThemeMapChanged$.next({ type: "remove", styleName: e });
}
getRegisteredRangeThemes() {
return Array.from(this._defaultRangeThemeMap.keys());
}
/**
* Register custom range theme style.
* @param {string} unitId The unit id.
* @param {RangeThemeStyle} rangeThemeStyle The range theme style.
*/
registerRangeThemeStyle(e, t) {
this._ensureRangeThemeStyleMap(e).set(t.getName(), t), this._rangeThemeMapChanged$.next({ type: "add", styleName: t.getName() });
}
/**
* Unregister custom range theme style.
* @param {string} unitId The unit id.
* @param {string} name The name of the range theme style.
*/
unregisterRangeThemeStyle(e, t) {
this._ensureRangeThemeStyleMap(e).delete(t), this._rangeThemeMapChanged$.next({ type: "remove", styleName: t });
}
/**
* Gets all custom register themes
* @param {string} unitId Which unit to register the range theme style.
* @return {string[]} The array of all custom registered themes.
*/
getALLRegisteredTheme(e) {
return Array.from(this._ensureRangeThemeStyleMap(e).keys());
}
getRangeThemeStyle(e, t) {
return this._defaultRangeThemeMap.has(t) ? this._defaultRangeThemeMap.get(t) : this._ensureRangeThemeStyleMap(e).get(t);
}
getCellStyle(e, t, s, o) {
const r = { startRow: s, startColumn: o, endRow: s, endColumn: o }, i = this._ensureRTreeCollection(e), a = Array.from(i.bulkSearch([{ unitId: e, sheetId: t, range: r }]));
if (a[0]) {
const l = this._ensureRangeThemeStyleRuleMap(e).get(a[0]);
if (l) {
const { rangeInfo: c, themeName: d } = l, h = s - c.range.startRow, g = o - c.range.startColumn, m = this.getRangeThemeStyle(e, d), C = this._ensureZebraCrossingCache(e, t, a[0]).getIsToggled(s);
if (m)
return m.getStyle(h, g, s === c.range.endRow, o === c.range.endColumn, C);
}
}
}
_registerIntercept() {
this.disposeWithMe(this._sheetInterceptorService.intercept(Rt.CELL_CONTENT, {
id: Or,
effect: Re.Style,
handler: (e, t, s) => {
const { row: o, col: r, unitId: i, subUnitId: a } = t, u = this.getCellStyle(i, a, o, r);
if (u) {
const l = !e || e === t.rawData ? { ...t.rawData } : e;
return l.themeStyle = u, s(l);
}
return s(e);
}
}));
}
toJson(e) {
const t = this._ensureRangeThemeStyleRuleMap(e), s = this._ensureRangeThemeStyleMap(e);
if (s.size === 0 && t.size === 0)
return "{}";
const o = {};
t.forEach((i, a) => {
o[a] = i;
});
const r = {};
return s.forEach((i, a) => {
r[a] = i.toJson();
}), JSON.stringify({
rangeThemeStyleRuleMap: o,
rangeThemeStyleMapJson: r
});
}
fromJSON(e, t) {
const { rangeThemeStyleRuleMap: s, rangeThemeStyleMapJson: o } = t;
s && Object.keys(s).forEach((r) => {
const i = s[r], { themeName: a, rangeInfo: u } = i;
a.startsWith("table") || (this.registerRangeThemeRule(a, u), this._ensureRTreeCollection(u.unitId).insert({ unitId: r, sheetId: u.subUnitId, range: u.range, id: r }));
}), o && Object.keys(o).forEach((r) => {
const i = o[r], a = new It(i.name);
a.fromJson(i), this._ensureRangeThemeStyleMap(e).set(a.getName(), a);
});
}
deleteUnitId(e) {
this._rangeThemeStyleMap.delete(e), this._rangeThemeStyleRuleMap.delete(e), this._rTreeCollection.delete(e);
}
_initSnapshot() {
this.disposeWithMe(this._resourceManagerService.registerPluginResource({
toJson: (e) => this.toJson(e),
parseJson: (e) => {
if (!e)
return {};
try {
return JSON.parse(e);
} catch {
return {};
}
},
businesses: [G.UNIVER_SHEET],
pluginName: xu,
onLoad: (e, t) => {
this.fromJSON(e, t);
},
onUnLoad: (e) => {
this.deleteUnitId(e);
}
}));
}
dispose() {
super.dispose(), this._rangeThemeStyleMap.clear(), this._rangeThemeStyleRuleMap.clear(), this._defaultRangeThemeMap.clear(), this._rTreeCollection.clear(), this._zebraCrossingCacheMap.clear(), this._rowVisibleFuncSet.clear();
}
};
ke = Du([
Hs(0, W(Y)),
Hs(1, W(Tn)),
Hs(2, W(_))
], ke);
const Rn = {
id: "sheet.mutation.set-worksheet-range-theme-style",
type: M.MUTATION,
handler: (n, e) => {
if (!k(n.get(_), e)) return !1;
const s = n.get(ke), { unitId: o, subUnitId: r, range: i, themeName: a } = e;
return s.registerRangeThemeRule(a, { range: i, unitId: o, subUnitId: r }), !0;
}
}, Au = (n, e) => {
const t = Se(n.get(_), e);
if (!t)
throw new Error("[SetWorksheetRangeThemeStyleMutation]: worksheet is null error!");
const { worksheet: s } = t;
return {
unitId: e.unitId,
subUnitId: s.getSheetId(),
range: e.range,
themeName: e.themeName
};
}, Cn = {
id: "sheet.mutation.remove-worksheet-range-theme-style",
type: M.MUTATION,
handler: (n, e) => {
if (!k(n.get(_), e)) return !1;
const s = n.get(ke), { unitId: o, subUnitId: r, range: i, themeName: a } = e;
return s.removeRangeThemeRule(a, { range: i, unitId: o, subUnitId: r }), !0;
}
}, $u = (n, e) => {
const t = Se(n.get(_), e);
if (!t)
throw new Error("[DeleteWorksheetRangeThemeStyleMutationFactory]: worksheet is null error!");
const { worksheet: s } = t;
return {
unitId: e.unitId,
subUnitId: s.getSheetId(),
range: e.range,
themeName: e.themeName
};
}, co = (n, e) => {
if (!Se(n.get(_), e))
throw new Error("Workbook or Worksheet not found at InsertRowMutationUndoFactory");
return {
unitId: e.unitId,
subUnitId: e.subUnitId,
range: e.range
};
}, Oe = {
id: "sheet.mutation.insert-row",
type: M.MUTATION,
handler: (n, e) => {
const t = Se(n.get(_), e);
if (!t)
throw new Error("Workbook or Worksheet not found at InsertRowMutation");
const { worksheet: s } = t, o = s.getRowManager(), { range: r, rowInfo: i } = e, { startRow: a, endRow: u } = r;
o.insertRowsWithData(a, u, i);
const l = u - a + 1;
return s.setRowCount(s.getRowCount() + l), s.getCellMatrix().insertRows(a, l), !0;
}
}, Us = (n, e) => {
if (!Se(n.get(_), e))
throw new Error("Workbook or Worksheet not found at InsertColMutationUndoFactory");
return {
unitId: e.unitId,
subUnitId: e.subUnitId,
range: e.range
};
}, De = {
id: "sheet.mutation.insert-col",
type: M.MUTATION,
handler: (n, e) => {
const t = Se(n.get(_), e);
if (!t)
throw new Error("Workbook or Worksheet not found at InsertColMutation");
const { worksheet: s } = t, o = s.getColumnManager(), { range: r, colInfo: i } = e, { startColumn: a, endColumn: u } = r;
o.insertColumnsWithData(a, u, i);
const l = u - a + 1;
return s.setColumnCount(s.getColumnCount() + l), s.getCellMatrix().insertColumns(r.startColumn, l), !0;
}
}, Et = {
id: "sheet.mutation.move-range",
type: M.MUTATION,
handler: (n, e) => {
const { from: t, to: s } = e;
if (!t || !s)
return !1;
const r = n.get(_).getCurrentUnitForType(G.UNIVER_SHEET);
if (!r)
return !1;
const i = r.getSheetBySheetId(e.from.subUnitId), a = r.getSheetBySheetId(e.to.subUnitId);
if (!i || !a)
return !1;
const u = i.getCellMatrix(), l = a.getCellMatrix();
return new Z(t.value).forValue((c, d, h) => {
h == null ? u.realDeleteValue(c, d) : u.setValue(c, d, h);
}), new Z(s.value).forValue((c, d, h) => {
h == null ? l.realDeleteValue(c, d) : l.setValue(c, d, h);
}), !0;
}
};
function Wu(n, e) {
const { unitId: t, subUnitId: s, sourceRange: o, targetRange: r } = e, i = o.startRow > r.startRow, a = o.endRow - o.startRow + 1;
return i ? {
unitId: t,
subUnitId: s,
sourceRange: O.clone(r),
targetRange: {
...o,
endRow: o.endRow + a,
startRow: o.startRow + a
}
} : {
unitId: t,
subUnitId: s,
targetRange: O.clone(o),
sourceRange: {
...r,
endRow: r.endRow - a,
startRow: r.startRow - a
}
};
}
const Qe = {
id: "sheet.mutation.move-rows",
type: M.MUTATION,
handler: (n, e) => {
const { unitId: t, subUnitId: s, sourceRange: o, targetRange: r } = e, a = n.get(_).getUniverSheetInstance(t);
if (!a)
throw new Error("[MoveRowMutation] univerSheet is null!");
const u = a.getSheetBySheetId(s);
if (!u)
throw new Error("[MoveRowMutation] worksheet is null!");
const l = o.startRow, c = o.endRow - o.startRow + 1, d = r.startRow, h = u.getRowManager().getRowData();
return pr(l, c, d, h), u.getCellMatrix().moveRows(l, c, d), !0;
}
};
function Vu(n, e) {
const { unitId: t, subUnitId: s, sourceRange: o, targetRange: r } = e, i = o.startColumn > r.startColumn, a = o.endColumn - o.startColumn + 1;
return i ? {
unitId: t,
subUnitId: s,
sourceRange: O.clone(r),
targetRange: {
...o,
endColumn: o.endColumn + a,
startColumn: o.startColumn + a
}
} : {
unitId: t,
subUnitId: s,
targetRange: O.clone(o),
sourceRange: {
...r,
startColumn: r.startColumn - a,
endColumn: r.endColumn - a
}
};
}
const et = {
id: "sheet.mutation.move-columns",
type: M.MUTATION,
handler: (n, e) => {
const { unitId: t, subUnitId: s, sourceRange: o, targetRange: r } = e, a = n.get(_).getUniverSheetInstance(t);
if (!a)
throw new Error("[MoveColumnMutation] univerSheet is null!");
const u = a.getSheetBySheetId(s);
if (!u)
throw new Error("[MoveColumnMutation] worksheet is null!");
const l = o.startColumn, c = o.endColumn - o.startColumn + 1, d = r.startColumn, h = u.getColumnManager().getColumnData();
return pr(l, c, d, h), u.getCellMatrix().moveColumns(l, c, d), !0;
}
}, Lu = (n, e) => {
const o = e.getRowManager().getRowData(), r = {}, i = n.range, a = Sr(i.startRow, i.endRow, o), u = wr(r, a);
return {
unitId: n.unitId,
subUnitId: n.subUnitId,
range: n.range,
rowInfo: u
};
}, xe = {
id: "sheet.mutation.remove-rows",
type: M.MUTATION,
handler: (n, e) => {
const s = n.get(_).getUniverSheetInstance(e.unitId);
if (s == null)
throw new Error("universheet is null error!");
const o = s.getSheetBySheetId(e.subUnitId);
if (!o) return !1;
const r = e.range, a = o.getRowManager().getRowData();
for (let c = r.startRow; c <= r.endRow; c++)
o.getRowFiltered(c);
const u = r.endRow - r.startRow + 1;
return vr(r.startRow, u, a), o.getCellMatrix().removeRows(r.startRow, u), o.setRowCount(o.getRowCount() - u), !0;
}
}, Hu = (n, e) => {
const s = n.get(_).getUniverSheetInstance(e.unitId);
if (s == null)
throw new Error("universheet is null error!");
const o = s.getSheetBySheetId(e.subUnitId);
if (o == null)
throw new Error("worksheet is null error!");
const a = o.getColumnManager().getColumnData(), u = {}, l = e.range, c = Sr(l.startColumn, l.endColumn, a), d = wr(u, c);
return {
unitId: e.unitId,
subUnitId: e.subUnitId,
range: e.range,
colInfo: d
};
}, Ue = {
id: "sheet.mutation.remove-col",
type: M.MUTATION,
handler: (n, e) => {
const s = n.get(_).getUniverSheetInstance(e.unitId);
if (s == null)
throw new Error("universheet is null error!");
const o = s.getSheetBySheetId(e.subUnitId);
if (!o) return !1;
const r = e.range, a = o.getColumnManager().getColumnData(), u = r.endColumn - r.startColumn + 1;
return vr(r.startColumn, u, a), o.setColumnCount(o.getColumnCount() - u), o.getCellMatrix().removeColumns(r.startColumn, u), !0;
}
}, be = (n, e) => {
const t = Se(n.get(_), e);
if (!t)
throw new Error("Workbook or worksheet is null error!");
const { worksheet: s } = t, r = s.getConfig().mergeData, i = e.ranges, a = [];
for (let u = 0; u < i.length; u++)
for (let l = r.length - 1; l >= 0; l--) {
const c = r[l], d = i[u];
O.intersects(c, d) && a.push(r[l]);
}
return {
unitId: e.unitId,
subUnitId: e.subUnitId,
ranges: a
};
}, ae = {
id: "sheet.mutation.remove-worksheet-merge",
type: M.MUTATION,
handler: (n, e) => {
const t = Se(n.get(_), e);
if (!t)
throw new Error("Workbook or worksheet is null error!");
const { worksheet: s } = t, r = s.getConfig().mergeData, i = e.ranges;
for (let a = 0; a < i.length; a++)
for (let u = r.length - 1; u >= 0; u--) {
const l = r[u], c = i[a];
O.intersects(l, c) && r.splice(u, 1);
}
return s.getSpanModel().rebuild(r), !0;
}
}, Fu = (n) => {
const { order: e } = n, t = {};
return Object.keys(e).forEach((s) => {
t[e[Number(s)]] = Number(s);
}), {
...n,
order: t
};
}, Jn = {
id: "sheet.mutation.reorder-range",
type: M.MUTATION,
handler: (n, e) => {
const { subUnitId: t, unitId: s, range: o, order: r } = e, u = n.get(_).getUnit(s).getSheetBySheetId(t);
if (!u)
return !1;
const l = new Z();
ne.foreach(o, (d, h) => {
if (r.hasOwnProperty(d)) {
const g = r[d], m = D.deepClone(u.getCellRaw(g, h));
l.setValue(d, h, m);
}
});
const c = u.getCellMatrix();
return l.forValue((d, h, g) => {
c.setValue(d, h, g);
}), !0;
}
};
function Bu(n, e) {
if (n == null)
return n;
const t = D.deepClone(n);
if (e == null)
return t;
const s = {};
return "h" in e && (s.h = t.h), "ia" in e && (s.ia = t.ia), "ah" in e && (s.ah = t.ah), "hd" in e && (s.hd = t.hd), "s" in e && (s.s = t.s), "custom" in e && (s.custom = t.custom), s;
}
function ju(n, e) {
if (n == null)
return n;
const t = D.deepClone(n);
if (e == null)
return t;
const s = {};
return "w" in e && (s.w = t.w), "hd" in e && (s.hd