import { F, Gr, N, Q, T, V, Vo, Wn, ea, et, lh, lo, uh, wt, zr } from "./chunk-BW43Z7N3.js"; import { _f } from "./chunk-QRYBFJ3R.js"; import { BehaviorSubject, DC, Fe, K0, Mf, OR, Op, Ot, Pt, Ra, Vn, Vr, _n, ar, cn, dn, kt, merge, ml, mu, nt, of, ot, skip, switchMap, tr, ur } from "./chunk-23V3HWTR.js"; // node_modules/.pnpm/@univerjs+sheets-numfmt@0.5.5_@grpc+grpc-js@1.13.4_react@18.3.1_rxjs@7.8.1/node_modules/@univerjs/sheets-numfmt/lib/es/index.js var ne = Object.defineProperty; var re = (e, t, r) => t in e ? ne(e, t, { enumerable: true, configurable: true, writable: true, value: r }) : e[t] = r; var y = (e, t, r) => re(e, typeof t != "symbol" ? t + "" : t, r); var J = [ "$", "£", "¥", "¤", "֏", "؋", "৳", "฿", // '៛', "₡", "₦", "₩", "₪", "₫", "€", "₭", "₮", "₱", "₲", "₴", "₸", "₹", "₺", "₼", "₽", "₾", "₿" ]; var 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 }; var 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" } ]; var 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" } ]; var Q2 = [ { 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" } ]; var Pe = "SHEET_NUMFMT_PLUGIN"; var x = (e, t = 0) => { var n; return e && (n = Op.getInfo(e).maxDecimals) != null ? n : t; }; var Ze = (e, t) => { if (e && !t || !e && t) return false; const r = (c) => c.reduce( (l, h) => { if (l.isEnd) return l; const f = h.value || h.num; return h.type === "point" ? (l.isEnd = true, l) : { ...l, result: l.result + f }; }, { isEnd: false, result: "" } ).result, n = Op.getInfo(e)._partitions, s = Op.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; }; var z = (e) => new Array(Math.min(Math.max(0, Number(e)), 30)).fill(0).join(""); var 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(";"); var Je = (e) => /\.0?/.test(e) || /0([^0]?)|0$/.test(e); var T2 = { id: "sheet.command.numfmt.set.numfmt", type: ar.COMMAND, handler: (e, t) => { if (!t) return false; const r = e.get(Pt), n = e.get(_n), s = e.get(cn), o = N(n, t); if (!o) return false; const { unitId: a, subUnitId: d } = o, u = t.values.filter((i) => !!i.pattern), c = t.values.filter((i) => !i.pattern), l = lo(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 = Gr(p.ranges); }), f.push({ id: Vo.id, params: l }); const i = uh(e, l); v.push(...i); } if (c.length) { h.ranges = Gr(h.ranges), f.push({ id: zr.id, params: h }); const i = lh(e, h); v.push(...i); } const m = mu(f, r).result; return m && s.pushUndoRedo({ unitID: a, undoMutations: v, redoMutations: f }), m; } }; var Ue = { id: "sheet.command.numfmt.add.decimal.command", type: ar.COMMAND, handler: async (e) => { const t = e.get(Pt), r = e.get(F), n = e.get(wt), s = e.get(_n), o = r.getCurrentSelections(); if (!o || !o.length) return false; const a = N(s); if (!a) return false; const { unitId: d, subUnitId: u } = a; let c = 0; o.forEach((v) => { tr.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 === dn.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) => { tr.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(T2.id, { values: f }) : false; } }; var k = class { constructor() { y(this, "_currencySymbol$", new BehaviorSubject("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(); } }; var Oe = { id: "sheet.command.numfmt.set.currency", type: ar.COMMAND, handler: async (e) => { const t = e.get(Pt), r = e.get(F), n = e.get(k), s = Ie[n.getCurrencySymbol()] || "$", o = r.getCurrentSelections(); if (!o || !o.length) return false; const a = [], d = Q2[4].suffix(s); return o.forEach((c) => { tr.foreach(c.range, (l, h) => { a.push({ row: l, col: h, pattern: d, type: "currency" }); }); }), await t.executeCommand(T2.id, { values: a }); } }; var De = { id: "sheet.command.numfmt.set.percent", type: ar.COMMAND, handler: async (e) => { const t = e.get(Pt), n = e.get(F).getCurrentSelections(); if (!n || !n.length) return false; const s = [], o = "0%"; return n.forEach((d) => { tr.foreach(d.range, (u, c) => { s.push({ row: u, col: c, pattern: o, type: "percent" }); }); }), await t.executeCommand(T2.id, { values: s }); } }; var Ve = { id: "sheet.command.numfmt.subtract.decimal.command", type: ar.COMMAND, handler: async (e) => { const t = e.get(Pt), r = e.get(F), n = e.get(wt), s = e.get(_n), o = r.getCurrentSelections(); if (!o || !o.length) return false; const a = N(s); if (!a) return false; const { unitId: d, subUnitId: u } = a; let c = 0; o.forEach((m) => { tr.foreach(m.range, (i, g) => { const p = n.getValue(d, u, i, g); if (!p) { const _ = a.worksheet.getCellRaw(i, g); if (!c && _ && _.t === dn.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) => { tr.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(T2.id, { values: f }); } }; var Qe = (e) => Op.getInfo(e).type || "unknown"; var Ae = (e, t, r = "en") => { const s = Op.getInfo(e)._partitions[1], o = Op.format(e, t, { locale: r, throws: false }); return t < 0 ? { result: o, color: s.color } : { result: o }; }; var we = (e, t, r) => e === "General" ? { result: String(_f(t)) // In Excel, the default General format also needs to handle numeric precision. } : Ae(e, t, r); var Fe2 = Object.defineProperty; var je = Object.getOwnPropertyDescriptor; var 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 && Fe2(t, r, s), s; }; var $ = (e, t) => (r, n) => t(r, n, e); var U = class extends nt { constructor(t, r, n, s, o, a) { super(); y(this, "_local$", new BehaviorSubject("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 ur.FR_FR: return "fr"; case ur.RU_RU: return "ru"; case ur.VI_VN: return "vi"; case ur.ZH_CN: return "zh-CN"; case ur.ZH_TW: return "zh-TW"; case ur.EN_US: case ur.FA_IR: default: return "en"; } } // eslint-disable-next-line max-lines-per-function _initInterceptorCellContent() { const t = { tl: { size: 6, color: "#409f11" } }, r = new kt(); this.disposeWithMe(merge(this._local$, this._localeService.currentLocale$).subscribe(() => { r.reset(); })), this.disposeWithMe(this._sheetInterceptorService.intercept(et.CELL_CONTENT, { effect: Vn.Value | Vn.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 === T && c.v && DC(c.v)) return o({ ...n, markers: { ...n == null ? void 0 : n.markers, ...t } }); if (c.t !== dn.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: ea.NUMFMT })), this.disposeWithMe(this._commandService.onCommandExecuted((n) => { if (n.id === Vo.id) { const s = n.params; Object.keys(s.values).forEach((o) => { s.values[o].ranges.forEach((d) => { tr.foreach(d, (u, c) => { r.realDeleteValue(u, c); }); }); }); } else if (n.id === Q.id) { const s = n.params; new kt(s.cellValue).forValue((o, a) => { r.realDeleteValue(o, a); }); } })), this.disposeWithMe( this._instanceService.getCurrentTypeOfUnit$(Fe.UNIVER_SHEET).pipe( switchMap((n) => { var s; return (s = n == null ? void 0 : n.activeSheet$) != null ? s : of(null); }), skip(1) ).subscribe(() => r.reset()) ); } setNumfmtLocal(t) { this._local$.next(t); } }; U = Le([ $(0, _n), $(1, ot(V)), $(2, ot(ml)), $(3, ot(Pt)), $(4, ot(wt)), $(5, ot(Vr)) ], U); var K = class extends nt { constructor() { super(...arguments); y(this, "_currencySymbol$", new BehaviorSubject("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; var Be = Object.getOwnPropertyDescriptor; var We = (e, t, r) => t in e ? ee(e, t, { enumerable: true, configurable: true, writable: true, value: r }) : e[t] = r; var 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; }; var q = (e, t) => (r, n) => t(r, n, e); var te = (e, t, r) => We(e, typeof t != "symbol" ? t + "" : t, r); var O = class extends Ra { constructor(e = void 0, t, r) { super(), this._config = e, this._injector = t, this._commandService = r; } onStarting() { K0(this._injector, [ [U], [k], [K] ]), Mf(this._injector, [ [U] ]); } onRendered() { Mf(this._injector, [ [K] ]), [ Ue, Ve, Oe, De, T2 ].forEach((e) => { this.disposeWithMe(this._commandService.registerCommand(e)); }); } }; te(O, "pluginName", Pe); te(O, "type", Fe.UNIVER_SHEET); O = Ge([ OR(Wn), q(1, ot(Ot)), q(2, Pt) ], O); var ke = (e) => J.find((r) => e.includes(r)); var et2 = () => J.map((e) => ({ label: e, value: e })); var tt = (e) => Q2.map((t) => ({ label: t.label(e), value: t.suffix(e), color: t.color })); var nt2 = () => Te.map((e) => ({ label: e.label, value: e.suffix })); var rt = () => xe.map((e) => ({ label: e.label, value: e.suffix, color: e.color })); export { J, Ie, Te, xe, Q2 as Q, x, Ze, z, P, Je, T2 as T, Ue, k, Oe, De, Ve, Qe, Ae, we, U, O, ke, et2 as et, tt, nt2 as nt, rt }; //# sourceMappingURL=chunk-KVSOW4CT.js.map