var re = Object.defineProperty; var ne = (n, e, t) => e in n ? re(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; var h = (n, e, t) => ne(n, typeof e != "symbol" ? e + "" : e, t); import { Disposable as $, CommandType as O, useDependency as se, useObservable as ie, UniverInstanceType as x, Inject as p, ICommandService as oe, RANGE_TYPE as v, Rectangle as T, IContextService as ae, ColorKit as ce, Plugin as le, merge as he, Injector as ge, IConfigService as ue } from "@univerjs/core"; import { Shape as de, Rect as fe, IRenderManagerService as _e } from "@univerjs/engine-render"; import { MenuItemType as Se, getMenuHiddenObservable as pe, ContextMenuPosition as ve, ContextMenuGroup as me, ComponentManager as Ce, IMenuManagerService as Re } from "@univerjs/ui"; import { BehaviorSubject as N, combineLatest as be, startWith as He, tap as Oe, merge as j, map as V } from "rxjs"; import Ie, { forwardRef as Z, useRef as ye, createElement as B, useCallback as Ee } from "react"; import { SheetsSelectionsService as we, REF_SELECTIONS_ENABLED as xe, IRefSelectionsService as $e } from "@univerjs/sheets"; import { SheetSkeletonManagerService as Me, getCoordByCell as L } from "@univerjs/sheets-ui"; const Pe = "sheets-crosshair-highlight.config", A = {}; var g = function() { return g = Object.assign || function(n) { for (var e, t = 1, r = arguments.length; t < r; t++) { e = arguments[t]; for (var s in e) Object.prototype.hasOwnProperty.call(e, s) && (n[s] = e[s]); } return n; }, g.apply(this, arguments); }, Te = function(n, e) { var t = {}; for (var r in n) Object.prototype.hasOwnProperty.call(n, r) && e.indexOf(r) < 0 && (t[r] = n[r]); if (n != null && typeof Object.getOwnPropertySymbols == "function") for (var s = 0, r = Object.getOwnPropertySymbols(n); s < r.length; s++) e.indexOf(r[s]) < 0 && Object.prototype.propertyIsEnumerable.call(n, r[s]) && (t[r[s]] = n[r[s]]); return t; }, F = Z(function(n, e) { var t = n.icon, r = n.id, s = n.className, i = n.extend, o = Te(n, ["icon", "id", "className", "extend"]), a = "univerjs-icon univerjs-icon-".concat(r, " ").concat(s || "").trim(), c = ye("_".concat(Ve())); return W(t, "".concat(r), { defIds: t.defIds, idSuffix: c.current }, g({ ref: e, className: a }, o), i); }); function W(n, e, t, r, s) { return B(n.tag, g(g({ key: e }, Ne(n, t, s)), r), (je(n, t).children || []).map(function(i, o) { return W(i, "".concat(e, "-").concat(n.tag, "-").concat(o), t, void 0, s); })); } function Ne(n, e, t) { var r = g({}, n.attrs); t != null && t.colorChannel1 && r.fill === "colorChannel1" && (r.fill = t.colorChannel1); var s = e.defIds; return !s || s.length === 0 || (n.tag === "use" && r["xlink:href"] && (r["xlink:href"] = r["xlink:href"] + e.idSuffix), Object.entries(r).forEach(function(i) { var o = i[0], a = i[1]; typeof a == "string" && (r[o] = a.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")"))); })), r; } function je(n, e) { var t, r = e.defIds; return !r || r.length === 0 ? n : n.tag === "defs" && (!((t = n.children) === null || t === void 0) && t.length) ? g(g({}, n), { children: n.children.map(function(s) { return typeof s.attrs.id == "string" && r && r.indexOf(s.attrs.id) > -1 ? g(g({}, s), { attrs: g(g({}, s.attrs), { id: s.attrs.id + e.idSuffix }) }) : s; }) }) : n; } function Ve() { return Math.random().toString(36).substring(2, 8); } F.displayName = "UniverIcon"; var Le = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "#E5E5E5", d: "M1.6499 3.65002C1.6499 2.54545 2.54533 1.65002 3.6499 1.65002H12.3499C13.4545 1.65002 14.3499 2.54545 14.3499 3.65002V12.35C14.3499 13.4546 13.4545 14.35 12.3499 14.35H3.6499C2.54533 14.35 1.6499 13.4546 1.6499 12.35V3.65002Z" } }, { tag: "path", attrs: { fill: "#fff", d: "M9.9998 1.65002H5.9998V6H1.6499V10H5.9998V14.35H9.9998V10H14.3499V6H9.9998V1.65002Z" } }, { tag: "path", attrs: { fill: "currentColor", d: "M3.6498 1.05005C2.21386 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V3.65005C14.9498 2.21411 13.7857 1.05005 12.3498 1.05005H3.6498ZM5.4002 2.25005H3.6498C2.87661 2.25005 2.2498 2.87685 2.2498 3.65005V5.40002H5.4002V2.25005ZM2.2498 10.6V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H5.4002V10.6H2.2498ZM6.60019 13.75H9.4002V9.40002H13.7498V6.60002H9.4002V2.25005H6.60019V6.60002H2.25029V9.40002H6.60019V13.75ZM10.6002 2.25005V5.40002H13.7498V3.65005C13.7498 2.87685 13.123 2.25005 12.3498 2.25005H10.6002ZM13.7498 10.6H10.6002V13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.6Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, Y = Z(function(n, e) { return B(F, Object.assign({}, n, { id: "cross-highlighting-single", ref: e, icon: Le })); }); Y.displayName = "CrossHighlightingSingle"; const q = [ "rgba(158, 109, 227, 0.3)", "rgba(254, 75, 75, 0.3)", "rgba(255, 140, 81, 0.3)", "rgba(164, 220, 22, 0.3)", "rgba(45, 174, 255, 0.3)", "rgba(58, 96, 247, 0.3)", "rgba(242, 72, 166, 0.3)", "rgba(153, 153, 153, 0.3)", "rgba(158, 109, 227, 0.15)", "rgba(254, 75, 75, 0.15)", "rgba(255, 140, 81, 0.15)", "rgba(164, 220, 22, 0.15)", "rgba(45, 174, 255, 0.15)", "rgba(58, 96, 247, 0.15)", "rgba(242, 72, 166, 0.15)", "rgba(153, 153, 153, 0.15)" ]; class S extends $ { constructor() { super(...arguments); h(this, "_enabled$", new N(!1)); h(this, "enabled$", this._enabled$.asObservable()); h(this, "_color$", new N(q[0])); h(this, "color$", this._color$.asObservable()); } get enabled() { return this._enabled$.getValue(); } get color() { return this._color$.getValue(); } dispose() { this._enabled$.complete(); } setEnabled(t) { this._enabled$.next(t); } setColor(t) { this._color$.next(t); } } const M = { id: "sheet.operation.toggle-crosshair-highlight", type: O.OPERATION, handler(n) { const e = n.get(S), t = e.enabled; return e.setEnabled(!t), !0; } }, J = { id: "sheet.operation.set-crosshair-highlight-color", type: O.OPERATION, handler(n, { value: e }) { const t = n.get(S); return t.enabled || t.setEnabled(!0), t.setColor(e), !0; } }, Ae = { id: "sheet.operation.enable-crosshair-highlight", type: O.OPERATION, handler(n) { const e = n.get(S); return e.enabled ? !1 : (e.setEnabled(!0), !0); } }, Ge = { id: "sheet.operation.disable-crosshair-highlight", type: O.OPERATION, handler(n) { const e = n.get(S); return e.enabled ? (e.setEnabled(!1), !0) : !1; } }; var I = { exports: {} }, m = {}; /** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var G; function Ue() { if (G) return m; G = 1; var n = Ie, e = Symbol.for("react.element"), t = Symbol.for("react.fragment"), r = Object.prototype.hasOwnProperty, s = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, i = { key: !0, ref: !0, __self: !0, __source: !0 }; function o(a, c, f) { var l, d = {}, _ = null, u = null; f !== void 0 && (_ = "" + f), c.key !== void 0 && (_ = "" + c.key), c.ref !== void 0 && (u = c.ref); for (l in c) r.call(c, l) && !i.hasOwnProperty(l) && (d[l] = c[l]); if (a && a.defaultProps) for (l in c = a.defaultProps, c) d[l] === void 0 && (d[l] = c[l]); return { $$typeof: e, type: a, key: _, ref: u, props: d, _owner: s.current }; } return m.Fragment = t, m.jsx = o, m.jsxs = o, m; } var U; function De() { return U || (U = 1, I.exports = Ue()), I.exports; } var D = De(); function X(n) { var e, t, r = ""; if (typeof n == "string" || typeof n == "number") r += n; else if (typeof n == "object") if (Array.isArray(n)) { var s = n.length; for (e = 0; e < s; e++) n[e] && (t = X(n[e])) && (r && (r += " "), r += t); } else for (t in n) n[t] && (r && (r += " "), r += t); return r; } function ke() { for (var n, e, t = 0, r = "", s = arguments.length; t < s; t++) (n = arguments[t]) && (e = X(n)) && (r && (r += " "), r += e); return r; } const Ze = "univer-crosshair-highlight-overlay", Be = "univer-crosshair-highlight-item", Fe = "univer-crosshair-highlight-item-selected", y = { crosshairHighlightOverlay: Ze, crosshairHighlightItem: Be, crosshairHighlightItemSelected: Fe }; function We(n) { const { onChange: e } = n, t = se(S), r = ie(t.color$), s = Ee((i) => { e == null || e(i); }, [e]); return /* @__PURE__ */ D.jsx("div", { className: y.crosshairHighlightOverlay, children: q.map((i) => /* @__PURE__ */ D.jsx( "div", { className: ke(y.crosshairHighlightItem, { [y.crosshairHighlightItemSelected]: i === r }), style: { backgroundColor: i }, onClick: () => s(i) }, i )) }); } const K = "CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT"; function Ye(n) { const e = n.get(S); return { id: M.id, tooltip: "crosshair.button.tooltip", type: Se.BUTTON_SELECTOR, icon: "CrossHighlightingSingle", selections: [ { label: { name: K, hoverable: !1 } } ], selectionsCommandId: J.id, activated$: e.enabled$, hidden$: pe(n, x.UNIVER_SHEET) }; } const qe = { [ve.FOOTER_MENU]: { [me.OTHERS]: { [M.id]: { order: 0, menuItemFactory: Ye } } } }; var Je = Object.defineProperty, Xe = Object.getOwnPropertyDescriptor, Ke = (n, e, t, r) => { for (var s = r > 1 ? void 0 : r ? Xe(e, t) : e, i = n.length - 1, o; i >= 0; i--) (o = n[i]) && (s = (r ? o(e, t, s) : o(s)) || s); return r && s && Je(e, t, s), s; }, E = (n, e) => (t, r) => e(t, r, n); let b = class extends $ { constructor(n, e, t) { super(), this._componentMgr = n, this._menuManagerService = e, this._cmdSrv = t, this._initCommands(), this._initMenus(), this._initComponents(); } _initCommands() { [ M, J, Ae, Ge ].forEach((n) => this._cmdSrv.registerCommand(n)); } _initMenus() { this._menuManagerService.mergeMenu(qe); } _initComponents() { this._componentMgr.register(K, We), this._componentMgr.register("CrossHighlightingSingle", Y); } }; b = Ke([ E(0, p(Ce)), E(1, Re), E(2, oe) ], b); const ze = 1; class Qe { constructor() { h(this, "_selectedRanges", []); h(this, "_ranges", []); } addRange(e) { if (e.rangeType === v.COLUMN || e.rangeType === v.ROW || e.rangeType === v.ALL) return; const t = this._getIntersects(e), r = this._getSplitRanges(e, t); r.length > 0 && this._ranges.push(...r); } setSelectedRanges(e) { this._selectedRanges = e; } _getSplitRanges(e, t) { let r = [e]; for (const s of t.concat(this._selectedRanges)) { const i = []; for (const o of r) { const a = T.subtract(o, s); a && a.length > 0 && i.push(...a); } r = i; } return r.filter((s) => s.startRow <= s.endRow && s.startColumn <= s.endColumn); } _getIntersects(e) { const t = []; for (const r of this._ranges) { const s = T.getIntersects(r, e); s && t.push(s); } return t; } getRanges() { return this._ranges; } reset() { this._ranges = [], this._selectedRanges = []; } } class et extends de { constructor(t, r) { super(t, r); // protected _showHighLight = false; h(this, "_color"); r && this.setShapeProps(r); } setShapeProps(t) { typeof t.color < "u" && (this._color = t.color), this.transformByState({ width: t.width, height: t.height }); } _draw(t) { const r = `rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${this._color.a})`; fe.drawWith(t, { width: this.width, height: this.height, fill: r, stroke: void 0, strokeWidth: 0, evented: !1 }); } } var tt = Object.defineProperty, rt = Object.getOwnPropertyDescriptor, nt = (n, e, t, r) => { for (var s = r > 1 ? void 0 : r ? rt(e, t) : e, i = n.length - 1, o; i >= 0; i--) (o = n[i]) && (s = (r ? o(e, t, s) : o(s)) || s); return r && s && tt(e, t, s), s; }, C = (n, e) => (t, r) => e(t, r, n); let H = class extends $ { constructor(e, t, r, s, i, o) { super(); h(this, "_shapes", []); h(this, "_rangeCollection", new Qe()); h(this, "_color", "rgba(255,0,0,0.5)"); this._context = e, this._sheetSkeletonManagerService = t, this._sheetsSelectionsService = r, this._sheetsCrosshairHighlightService = s, this._contextService = i, this._refSelectionsService = o, this._initRenderListener(); } _transformSelection(e, t) { if (!e) return; const r = t.getRowCount(), s = t.getColumnCount(), i = []; for (const o of e) { const { startRow: a, endRow: c, startColumn: f, endColumn: l } = o.range; c - a + 1 === r || l - f + 1 === s || i.push(o.range); } this._rangeCollection.setSelectedRanges(i); for (const o of i) this.addSelection(o, t); } _initRenderListener() { const e = this._context.unit; this.disposeWithMe(be([ this._contextService.subscribeContextValue$(xe).pipe(He(!1)), this._sheetSkeletonManagerService.currentSkeleton$, this._sheetsCrosshairHighlightService.enabled$, this._sheetsCrosshairHighlightService.color$.pipe(Oe((t) => this._color = t)), j( this._sheetsSelectionsService.selectionMoveStart$, this._sheetsSelectionsService.selectionMoving$, this._sheetsSelectionsService.selectionMoveEnd$, this._sheetsSelectionsService.selectionSet$, e.activeSheet$.pipe(V(() => this._sheetsSelectionsService.getCurrentSelections())) ), j( this._refSelectionsService.selectionMoveStart$, this._refSelectionsService.selectionMoving$, this._refSelectionsService.selectionMoveEnd$, this._sheetsSelectionsService.selectionSet$, e.activeSheet$.pipe(V(() => this._refSelectionsService.getCurrentSelections())) ) ]).subscribe(([t, r, s, i, o, a]) => { if (this._clear(), !s) return; const c = t ? a : o; this._rangeCollection.reset(), this._transformSelection(c, e.getActiveSheet()), this.render(this._rangeCollection.getRanges()); })); } addSelection(e, t) { if (e.rangeType === v.COLUMN || e.rangeType === v.ROW || e.rangeType === v.ALL) return; const r = t.getRowCount(), s = t.getColumnCount(), { startRow: i, endRow: o, startColumn: a, endColumn: c } = e, f = { startRow: i, endRow: o, startColumn: 0, endColumn: a - 1 }, l = { startRow: i, endRow: o, startColumn: c + 1, endColumn: s }, d = { startRow: 0, endRow: i - 1, startColumn: a, endColumn: c }, _ = { startRow: o + 1, endRow: r, startColumn: a, endColumn: c }; for (const u of [f, l, d, _]) u.startRow <= u.endRow && u.startColumn <= u.endColumn && this._rangeCollection.addRange(u); } _clear() { this._shapes.forEach((e) => { e.dispose(); }), this._shapes = []; } _addShapes(e, t, r, s) { const { startRow: i, endRow: o, startColumn: a, endColumn: c } = e, f = L(i, a, r, s), l = L(o, c, r, s), { startX: d, startY: _ } = f, { endX: u, endY: z } = l, Q = u - d, ee = z - _, te = { left: d, top: _, color: new ce(this._color).toRgb(), width: Q, height: ee, zIndex: ze, evented: !1 }, P = new et(`crosshair-${t}`, te); this._shapes.push(P), r.addObject(P); } render(e) { const t = this._sheetSkeletonManagerService.getCurrentSkeleton(); if (!t) return; const { scene: r } = this._context; this._clear(); for (let s = 0; s < e.length; s++) { const i = e[s]; this._addShapes(i, s, r, t); } r.makeDirty(!0); } async dispose() { super.dispose(); } }; H = nt([ C(1, p(Me)), C(2, p(we)), C(3, p(S)), C(4, p(ae)), C(5, $e) ], H); var st = Object.defineProperty, it = Object.getOwnPropertyDescriptor, ot = (n, e, t, r) => { for (var s = r > 1 ? void 0 : r ? it(e, t) : e, i = n.length - 1, o; i >= 0; i--) (o = n[i]) && (s = (r ? o(e, t, s) : o(s)) || s); return r && s && st(e, t, s), s; }, w = (n, e) => (t, r) => e(t, r, n), R; let k = (R = class extends le { constructor(n = A, e, t, r) { super(), this._config = n, this._injector = e, this._renderManagerService = t, this._configService = r; const { ...s } = he( {}, A, this._config ); this._configService.setConfig(Pe, s); } onStarting() { [ [S], [b] ].forEach((n) => this._injector.add(n)); } onReady() { [ [H] ].forEach((n) => this._injector.add(n)), this._injector.get(b), this._renderManagerService.registerRenderModule(x.UNIVER_SHEET, [H]); } }, h(R, "pluginName", "SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN"), h(R, "type", x.UNIVER_SHEET), R); k = ot([ w(1, p(ge)), w(2, _e), w(3, ue) ], k); export { q as CROSSHAIR_HIGHLIGHT_COLORS, Ge as DisableCrosshairHighlightOperation, Ae as EnableCrosshairHighlightOperation, J as SetCrosshairHighlightColorOperation, S as SheetsCrosshairHighlightService, M as ToggleCrosshairHighlightOperation, k as UniverSheetsCrosshairHighlightPlugin };