var ne = Object.defineProperty; var re = (e, t, r) => t in e ? ne(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r; var y = (e, t, r) => re(e, typeof t != "symbol" ? t + "" : t, r); import { numfmt as N, CommandType as I, ICommandService as M, IUniverInstanceService as D, IUndoRedoService as se, sequenceExecute as oe, Range as C, CellValueType as A, Inject as E, ThemeService as ce, LocaleService as ae, Disposable as X, LocaleType as b, ObjectMatrix as B, InterceptorEffectEnum as W, isRealNum as ie, UniverInstanceType as Y, DependentOn as ue, Injector as le, Plugin as me, registerDependencies as fe, touchDependencies as G } from "@univerjs/core"; import { getSheetCommandTarget as w, transformCellsToRange as de, rangeMerge as H, SetNumfmtMutation as Z, factorySetNumfmtUndoMutation as he, RemoveNumfmtMutation as ge, factoryRemoveNumfmtUndoMutation as pe, SheetsSelectionsService as V, INumfmtService as F, SheetInterceptorService as ve, INTERCEPTOR_POINT as Se, InterceptCellContentPriority as _e, SetRangeValuesMutation as ye, UniverSheetsPlugin as be } from "@univerjs/sheets"; import { BehaviorSubject as j, merge as Ce, switchMap as Me, of as $e, skip as Ee } from "rxjs"; import { DEFAULT_TEXT_FORMAT as Ne } from "@univerjs/engine-numfmt"; import { stripErrorMargin as Re } from "@univerjs/engine-formula"; const J = [ "$", "£", "¥", "¤", "֏", "؋", "৳", "฿", // '៛', "₡", "₦", "₩", "₪", "₫", "€", "₭", "₮", "₱", "₲", "₴", "₸", "₹", "₺", "₼", "₽", "₾", "₿" ], Ie = { US: "$", // United States Dollar CA: "C$", // Canadian Dollar GB: "£", // British Pound Sterling JP: "¥", // Japanese Yen IN: "₹", // Indian Rupee AU: "A$", // Australian Dollar CN: "¥", // Chinese Yuan KR: "₩", // South Korean Won RU: "₽", // Russian Ruble // Euro countries AT: "€", BE: "€", CY: "€", EE: "€", FI: "€", FR: "€", DE: "€", GR: "€", IE: "€", IT: "€", LV: "€", LT: "€", LU: "€", MT: "€", NL: "€", PT: "€", SK: "€", SI: "€", ES: "€" // Add more mappings as needed }, Te = [ { label: "1930-08-05", suffix: "yyyy-MM-dd" }, { label: "1930/08/05", suffix: "yyyy/MM/dd" }, { label: "1930年08月05日", suffix: 'yyyy"年"MM"月"dd"日"' }, { label: "08-05", suffix: "MM-dd" }, { label: "8月5日", suffix: 'M"月"d"日"' }, { label: "13:30:30", suffix: "h:mm:ss" }, { label: "13:30", suffix: "h:mm" }, { label: "下午01:30", suffix: "A/P hh:mm" }, { label: "下午1:30", suffix: "A/P h:mm" }, { label: "下午1:30:30", suffix: "A/P h:mm:ss" }, { label: "08-05 下午 01:30", suffix: "MM-dd A/P hh:mm" } ], xe = [ { label: "(1,235)", suffix: "#,##0_);(#,##0)" }, { label: "(1,235) ", suffix: "#,##0_);[Red](#,##0)", color: "red" }, { label: "1,234.56", suffix: "#,##0.00_);#,##0.00" }, { label: "1,234.56", suffix: "#,##0.00_);[Red]#,##0.00", color: "red" }, { label: "-1,234.56", suffix: "#,##0.00_);-#,##0.00" }, { label: "-1,234.56", suffix: "#,##0.00_);[Red]-#,##0.00", color: "red" } ], Q = [ { label: (e) => `${e}1,235`, suffix: (e) => `"${e}"#,##0.00_);"${e}"#,##0.00` }, { label: (e) => `${e}1,235`, suffix: (e) => `"${e}"#,##0.00_);[Red]"${e}"#,##0.00`, color: "red" }, { label: (e) => `(${e}1,235)`, suffix: (e) => `"${e}"#,##0.00_);("${e}"#,##0.00)` }, { label: (e) => `(${e}1,235)`, suffix: (e) => `"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`, color: "red" }, { label: (e) => `-${e}1,235`, suffix: (e) => `"${e}"#,##0.00_);-"${e}"#,##0.00` }, { label: (e) => `-${e}1,235`, suffix: (e) => `"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`, color: "red" } ], Pe = "SHEET_NUMFMT_PLUGIN", x = (e, t = 0) => { var n; return e && (n = N.getInfo(e).maxDecimals) != null ? n : t; }, Ze = (e, t) => { if (e && !t || !e && t) return !1; const r = (c) => c.reduce( (l, h) => { if (l.isEnd) return l; const f = h.value || h.num; return h.type === "point" ? (l.isEnd = !0, l) : { ...l, result: l.result + f }; }, { isEnd: !1, result: "" } ).result, n = N.getInfo(e)._partitions, s = N.getInfo(t)._partitions, o = r(n[0].tokens), a = r(s[0].tokens), d = r(n[1].tokens), u = r(s[1].tokens); return o === a && d === u && n[1].color === s[1].color; }, z = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""), P = (e, t) => e.split(";").map((n) => /\.0?/.test(n) ? n.replace( /\.0*/g, `${t > 0 ? "." : ""}${z(Number(t || 0))}` ) : /0([^0]?)|0$/.test(n) ? n.replace( /0([^0]+)|0$/, `0${t > 0 ? "." : ""}${z(Number(t || 0))}$1` ) : n).join(";"), Je = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e), T = { id: "sheet.command.numfmt.set.numfmt", type: I.COMMAND, handler: (e, t) => { if (!t) return !1; const r = e.get(M), n = e.get(D), s = e.get(se), o = w(n, t); if (!o) return !1; const { unitId: a, subUnitId: d } = o, u = t.values.filter((i) => !!i.pattern), c = t.values.filter((i) => !i.pattern), l = de(a, d, u), h = { unitId: a, subUnitId: d, ranges: c.map((i) => ({ startColumn: i.col, startRow: i.row, endColumn: i.col, endRow: i.row })) }, f = [], v = []; if (u.length) { Object.keys(l.values).forEach((g) => { const p = l.values[g]; p.ranges = H(p.ranges); }), f.push({ id: Z.id, params: l }); const i = he(e, l); v.push(...i); } if (c.length) { h.ranges = H(h.ranges), f.push({ id: ge.id, params: h }); const i = pe(e, h); v.push(...i); } const m = oe(f, r).result; return m && s.pushUndoRedo({ unitID: a, undoMutations: v, redoMutations: f }), m; } }, Ue = { id: "sheet.command.numfmt.add.decimal.command", type: I.COMMAND, handler: async (e) => { const t = e.get(M), r = e.get(V), n = e.get(F), s = e.get(D), o = r.getCurrentSelections(); if (!o || !o.length) return !1; const a = w(s); if (!a) return !1; const { unitId: d, subUnitId: u } = a; let c = 0; o.forEach((v) => { C.foreach(v.range, (m, i) => { const g = n.getValue(d, u, m, i); if (!g) { const S = a.worksheet.getCellRaw(m, i); if (!c && S && S.t === A.NUMBER && S.v) { const _ = /\.(\d*)$/.exec(String(S.v)); if (_) { const R = _[1].length; if (!R) return; c = Math.max(c, R); } } return; } const p = x(g.pattern); c = p > c ? p : c; }); }); const l = c + 1, h = P(`0${l > 0 ? ".0" : ""}`, l), f = []; return o.forEach((v) => { C.foreach(v.range, (m, i) => { const g = n.getValue(d, u, m, i); if (!g) f.push({ row: m, col: i, pattern: h }); else { const p = x(g.pattern), S = P(g.pattern, p + 1); S !== g.pattern && f.push({ row: m, col: i, pattern: S }); } }); }), f.length ? await t.executeCommand(T.id, { values: f }) : !1; } }; class k { constructor() { y(this, "_currencySymbol$", new j("US")); y(this, "currencySymbol$", this._currencySymbol$.asObservable()); } /** * Set the currency symbol by setting the country code. */ setCurrencySymbolByCountryCode(t) { this._currencySymbol$.next(t); } getCurrencySymbol() { return this._currencySymbol$.getValue(); } } const Oe = { id: "sheet.command.numfmt.set.currency", type: I.COMMAND, handler: async (e) => { const t = e.get(M), r = e.get(V), n = e.get(k), s = Ie[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections(); if (!o || !o.length) return !1; const a = [], d = Q[4].suffix(s); return o.forEach((c) => { C.foreach(c.range, (l, h) => { a.push({ row: l, col: h, pattern: d, type: "currency" }); }); }), await t.executeCommand(T.id, { values: a }); } }, De = { id: "sheet.command.numfmt.set.percent", type: I.COMMAND, handler: async (e) => { const t = e.get(M), n = e.get(V).getCurrentSelections(); if (!n || !n.length) return !1; const s = [], o = "0%"; return n.forEach((d) => { C.foreach(d.range, (u, c) => { s.push({ row: u, col: c, pattern: o, type: "percent" }); }); }), await t.executeCommand(T.id, { values: s }); } }, Ve = { id: "sheet.command.numfmt.subtract.decimal.command", type: I.COMMAND, handler: async (e) => { const t = e.get(M), r = e.get(V), n = e.get(F), s = e.get(D), o = r.getCurrentSelections(); if (!o || !o.length) return !1; const a = w(s); if (!a) return !1; const { unitId: d, subUnitId: u } = a; let c = 0; o.forEach((m) => { C.foreach(m.range, (i, g) => { const p = n.getValue(d, u, i, g); if (!p) { const _ = a.worksheet.getCellRaw(i, g); if (!c && _ && _.t === A.NUMBER && _.v) { const R = /\.(\d*)$/.exec(String(_.v)); if (R) { const L = R[1].length; if (!L) return; c = Math.max(c, L); } } return; } const S = x(p.pattern); c = S > c ? S : c; }); }); const l = c - 1, h = P(`0${l > 0 ? ".0" : "."}`, l), f = []; return o.forEach((m) => { C.foreach(m.range, (i, g) => { const p = n.getValue(d, u, i, g); if (!p) f.push({ row: i, col: g, pattern: h }); else { const S = x(p.pattern); f.push({ row: i, col: g, pattern: P(p.pattern, S - 1) }); } }); }), await t.executeCommand(T.id, { values: f }); } }, Qe = (e) => N.getInfo(e).type || "unknown", Ae = (e, t, r = "en") => { const s = N.getInfo(e)._partitions[1], o = N.format(e, t, { locale: r, throws: !1 }); return t < 0 ? { result: o, color: s.color } : { result: o }; }, we = (e, t, r) => e === "General" ? { result: String(Re(t)) // In Excel, the default General format also needs to handle numeric precision. } : Ae(e, t, r); var Fe = Object.defineProperty, je = Object.getOwnPropertyDescriptor, Le = (e, t, r, n) => { for (var s = n > 1 ? void 0 : n ? je(t, r) : t, o = e.length - 1, a; o >= 0; o--) (a = e[o]) && (s = (n ? a(t, r, s) : a(s)) || s); return n && s && Fe(t, r, s), s; }, $ = (e, t) => (r, n) => t(r, n, e); let U = class extends X { constructor(t, r, n, s, o, a) { super(); y(this, "_local$", new j("en")); y(this, "local$", this._local$.asObservable()); this._instanceService = t, this._sheetInterceptorService = r, this._themeService = n, this._commandService = s, this._numfmtService = o, this._localeService = a, this._initInterceptorCellContent(); } get local() { const t = this._local$.getValue(); if (t) return t; switch (this._localeService.getCurrentLocale()) { case b.FR_FR: return "fr"; case b.RU_RU: return "ru"; case b.VI_VN: return "vi"; case b.ZH_CN: return "zh-CN"; case b.ZH_TW: return "zh-TW"; case b.EN_US: case b.FA_IR: default: return "en"; } } // eslint-disable-next-line max-lines-per-function _initInterceptorCellContent() { const t = { tl: { size: 6, color: "#409f11" } }, r = new B(); this.disposeWithMe(Ce(this._local$, this._localeService.currentLocale$).subscribe(() => { r.reset(); })), this.disposeWithMe(this._sheetInterceptorService.intercept(Se.CELL_CONTENT, { effect: W.Value | W.Style, handler: (n, s, o) => { const a = s.unitId, d = s.subUnitId; let u; const c = n; if (!c) return o(n); if (n != null && n.s) { const m = s.workbook.getStyles().get(n.s); m != null && m.n && (u = m.n); } if (u || (u = this._numfmtService.getValue(a, d, s.row, s.col)), !u) return o(n); if (u.pattern === Ne && c.v && ie(c.v)) return o({ ...n, markers: { ...n == null ? void 0 : n.markers, ...t } }); if (c.t !== A.NUMBER || c.v == null || Number.isNaN(c.v)) return o(n); let l = ""; const h = r.getValue(s.row, s.col); if (h && h.parameters === `${c.v}_${u.pattern}`) return o({ ...n, ...h.result }); const f = we(u.pattern, Number(c.v), this.local); if (l = f.result, !l) return o(n); const v = { v: l }; if (f.color) { const m = this._themeService.getCurrentTheme()[`${f.color}500`]; m && (v.interceptorStyle = { cl: { rgb: m } }); } return r.setValue(s.row, s.col, { result: v, parameters: `${c.v}_${u.pattern}` }), o({ ...n, ...v }); }, priority: _e.NUMFMT })), this.disposeWithMe(this._commandService.onCommandExecuted((n) => { if (n.id === Z.id) { const s = n.params; Object.keys(s.values).forEach((o) => { s.values[o].ranges.forEach((d) => { C.foreach(d, (u, c) => { r.realDeleteValue(u, c); }); }); }); } else if (n.id === ye.id) { const s = n.params; new B(s.cellValue).forValue((o, a) => { r.realDeleteValue(o, a); }); } })), this.disposeWithMe( this._instanceService.getCurrentTypeOfUnit$(Y.UNIVER_SHEET).pipe( Me((n) => { var s; return (s = n == null ? void 0 : n.activeSheet$) != null ? s : $e(null); }), Ee(1) ).subscribe(() => r.reset()) ); } setNumfmtLocal(t) { this._local$.next(t); } }; U = Le([ $(0, D), $(1, E(ve)), $(2, E(ce)), $(3, E(M)), $(4, E(F)), $(5, E(ae)) ], U); class K extends X { constructor() { super(...arguments); y(this, "_currencySymbol$", new j("US")); y(this, "currencySymbol$", this._currencySymbol$.asObservable()); } /** * Set the currency symbol by setting the country code. */ setCurrencySymbolByCountryCode(r) { this._currencySymbol$.next(r); } getCurrencySymbol() { return this._currencySymbol$.getValue(); } } var ee = Object.defineProperty, Be = Object.getOwnPropertyDescriptor, We = (e, t, r) => t in e ? ee(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, Ge = (e, t, r, n) => { for (var s = n > 1 ? void 0 : n ? Be(t, r) : t, o = e.length - 1, a; o >= 0; o--) (a = e[o]) && (s = (n ? a(t, r, s) : a(s)) || s); return n && s && ee(t, r, s), s; }, q = (e, t) => (r, n) => t(r, n, e), te = (e, t, r) => We(e, typeof t != "symbol" ? t + "" : t, r); let O = class extends me { constructor(e = void 0, t, r) { super(), this._config = e, this._injector = t, this._commandService = r; } onStarting() { fe(this._injector, [ [U], [k], [K] ]), G(this._injector, [ [U] ]); } onRendered() { G(this._injector, [ [K] ]), [ Ue, Ve, Oe, De, T ].forEach((e) => { this.disposeWithMe(this._commandService.registerCommand(e)); }); } }; te(O, "pluginName", Pe); te(O, "type", Y.UNIVER_SHEET); O = Ge([ ue(be), q(1, E(le)), q(2, M) ], O); const ke = (e) => J.find((r) => e.includes(r)), et = () => J.map((e) => ({ label: e, value: e })), tt = (e) => Q.map((t) => ({ label: t.label(e), value: t.suffix(e), color: t.color })), nt = () => Te.map((e) => ({ label: e.label, value: e.suffix })), rt = () => xe.map((e) => ({ label: e.label, value: e.suffix, color: e.color })); export { Ue as AddDecimalCommand, Q as CURRENCYFORMAT, Te as DATEFMTLISG, k as MenuCurrencyService, xe as NUMBERFORMAT, Oe as SetCurrencyCommand, T as SetNumfmtCommand, De as SetPercentCommand, U as SheetsNumfmtCellContentController, Ve as SubtractDecimalCommand, O as UniverSheetsNumfmtPlugin, Ie as countryCurrencyMap, J as currencySymbols, tt as getCurrencyFormatOptions, et as getCurrencyOptions, ke as getCurrencyType, nt as getDateFormatOptions, x as getDecimalFromPattern, z as getDecimalString, rt as getNumberFormatOptions, Ae as getPatternPreview, we as getPatternPreviewIgnoreGeneral, Qe as getPatternType, Ze as isPatternEqualWithoutDecimal, Je as isPatternHasDecimal, P as setPatternDecimal };