UNPKG

@univerjs/docs-ui

Version:

Univer normal ui-plugin-docs

1,379 lines • 539 kB
var Mc = Object.defineProperty; var _c = (n, e, t) => e in n ? Mc(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; var O = (n, e, t) => _c(n, typeof e != "symbol" ? e + "" : e, t); import { IUniverInstanceService as L, Inject as j, Disposable as ge, toDisposable as _n, UniverInstanceType as _, BuildTextUtils as le, JSONX as W, ObjectRelativeFromV as ht, ObjectRelativeFromH as Ro, ICommandService as T, generateRandomId as Fe, DisposableCollection as In, CommandType as D, debounce as Pr, ThemeService as wr, IUndoRedoService as bo, TextX as me, Tools as te, TextXActionType as G, DOC_RANGE_TYPE as He, RANGE_DIRECTION as _e, COLORS as fn, BooleanNumber as z, Rectangle as Dc, ILogService as Nr, RxDisposable as It, DataStreamTreeTokenType as V, isInternalEditorID as St, IContextService as Lr, Injector as Dn, createIdentifier as Gi, EDITOR_ACTIVATED as to, FOCUSING_EDITOR_STANDALONE as Qs, HorizontalAlign as Qe, VerticalAlign as Pc, DEFAULT_EMPTY_DOCUMENT_VALUE as Yi, Direction as de, getPlainText as no, createInternalEditorID as wc, LocaleService as Ke, DocumentFlavor as Pe, PresetListType as be, TableRowHeightRule as Nc, TableSizeType as Ki, TableTextWrapType as Lc, TableAlignmentType as Qc, MemoryCursor as Nt, SHEET_EDITOR_UNITS as Sn, UpdateDocsAttributeType as on, PositionedObjectLayoutType as yo, BlockType as Uc, LRUMap as Fc, BaselineOffset as Ve, ColorKit as Us, DrawingTypeEnum as Qr, skipParseTagNames as Hc, CustomRangeType as Ur, DataStreamTreeNodeType as an, SliceBodyType as sr, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Fr, normalizeBody as kc, getBodySlice as qi, FOCUSING_DOC as Pn, DashStyleType as Vc, PRESET_LIST_TYPE as Wc, NamedStyleType as K, PageOrientType as jc, PAPER_TYPES as zc, PAGE_SIZE as ir, DOCS_ZEN_EDITOR_UNIT_ID_KEY as ot, DEFAULT_STYLES as Xi, NAMED_STYLE_MAP as Gc, fromEventSubject as Bt, deepCompare as Yc, sequenceExecuteAsync as Hr, FOCUSING_UNIVER_EDITOR as kr, FOCUSING_COMMON_DRAWINGS as Zi, SpacingRule as Xt, IConfigService as Vr, QuickListTypeMap as Wo, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as Kc, checkForSubstrings as qc, createInterceptorKey as Ji, InterceptorManager as Xc, UndoCommandId as Fs, RedoCommandId as Hs, DependentOn as Zc, Plugin as Jc, merge as $c, touchDependencies as ks, mergeOverrideWithDependencies as el } from "@univerjs/core"; import { DocSelectionManagerService as Y, RichTextEditingMutation as X, DocSkeletonManagerService as Ae, SetTextSelectionsOperation as Ne, DocStateEmitService as tl, DocInterceptorService as nl } from "@univerjs/docs"; import { DeviceInputEventType as $i, ScrollBar as ar, IRenderManagerService as fe, Liquid as ea, GlyphType as ta, DocumentSkeletonPageType as xe, getPageFromPath as cr, getTableIdAndSliceIndex as Vs, NORMAL_TEXT_SELECTION_PLUGIN_STYLE as vn, getColor as pn, RegularPolygon as na, Rect as qn, getOffsetRectForDom as ol, ScrollTimer as rl, CURSOR_TYPE as Mt, getSystemHighlightColor as sl, Vector2 as Cn, PageLayoutType as Rn, DocumentEditArea as Se, Shape as il, Path as Ws, hasListGlyph as al, isIndentByGlyph as cl, isFirstGlyph as ll, getParagraphByGlyph as dl, pixelToPt as Al, ptToPixel as js, parseDataStreamToTree as ul, pxToNum as oa, TRANSFORM_CHANGE_OBSERVABLE_TYPE as ra, getNumberUnitValue as rn, Viewport as hl, Layer as zs, Documents as gl, DocBackground as fl, getLastLine as pl, lineIterator as ml, getLastColumn as El, UniverRenderEnginePlugin as Il } from "@univerjs/engine-render"; import { useDependency as J, IShortcutService as xo, ILayoutService as Oo, KeyCode as q, MetaKeys as ne, useEvent as En, useObservable as tt, ComponentManager as sn, ISidebarService as sa, IClipboardInterfaceService as ia, FILE_PNG_CLIPBOARD_MIME_TYPE as Sl, FILE__WEBP_CLIPBOARD_MIME_TYPE as vl, FILE__JPEG_CLIPBOARD_MIME_TYPE as Cl, FILE__BMP_CLIPBOARD_MIME_TYPE as Rl, HTML_CLIPBOARD_MIME_TYPE as aa, PLAIN_TEXT_CLIPBOARD_MIME_TYPE as ca, CopyCommand as bl, CutCommand as yl, PasteCommand as xl, IConfirmService as la, getMenuHiddenObservable as ie, MenuItemType as Z, COLOR_PICKER_COMPONENT as da, FONT_FAMILY_LIST as Ol, FONT_FAMILY_COMPONENT as Tl, FONT_FAMILY_ITEM_COMPONENT as Bl, FONT_SIZE_LIST as Ml, FONT_SIZE_COMPONENT as _l, HEADING_LIST as Gs, COMMON_LABEL_COMPONENT as Dl, HEADING_ITEM_COMPONENT as Pl, ICanvasPopupService as wl, IMenuManagerService as Aa, ToolbarItem as Nl, MenuManagerPosition as Ll, RectPopup as Ql, DesktopMenu as Ul, ContextMenuPosition as oo, Slider as Fl, useConfigValue as ua, ContextMenuGroup as cn, RibbonInsertGroup as Hl, RibbonStartGroup as Ys, IUIPartsService as kl, BuiltInUIPart as Ks, connectInjector as qs, imageMimeTypeSet as Vl, IContextMenuService as Wl } from "@univerjs/ui"; import { useMemo as Me, useEffect as ve, useCallback as ha, useState as pe, useLayoutEffect as ga, useRef as ke, forwardRef as Oe, createElement as Te, useImperativeHandle as jl } from "react"; import { jsx as Q, jsxs as se, Fragment as zl } from "react/jsx-runtime"; import { clsx as Ge, borderClassName as wn, Checkbox as Xs, InputNumber as it, Button as Gl, Select as fa, scrollbarClassName as Yl, Tooltip as Kl } from "@univerjs/design"; import { Subject as Re, BehaviorSubject as Ue, merge as pa, filter as ro, takeUntil as gt, fromEvent as ze, Observable as Ee, map as Nn, combineLatest as Ln, distinctUntilChanged as Wt, throttleTime as bn, switchMap as ql, take as Xl, first as Zl, of as Jl, animationFrameScheduler as $l } from "rxjs"; import { filter as lr, bufferTime as ed, map as td } from "rxjs/operators"; import { ImageSourceType as Wr } from "@univerjs/drawing"; var nd = Object.getOwnPropertyDescriptor, od = (n, e, t, o) => { for (var r = o > 1 ? void 0 : o ? nd(e, t) : e, s = n.length - 1, i; s >= 0; s--) (i = n[s]) && (r = i(r) || r); return r; }, Zs = (n, e) => (t, o) => e(t, o, n); let _t = class extends ge { constructor(e, t) { super(); O(this, "_matches", /* @__PURE__ */ new Map()); this._univerInstanceService = e, this._textSelectionManagerService = t; } registerAutoFormat(e) { const t = this._matches.get(e.id); return t ? (t.push(e), t.sort((o, r) => { var s, i; return ((s = r.priority) != null ? s : 0) - ((i = o.priority) != null ? i : 0); })) : this._matches.set(e.id, [e]), _n(() => { const o = this._matches.get(e.id); if (o) { const r = o.findIndex((s) => s === e); r >= 0 && o.splice(r, 1); } }); } onAutoFormat(e, t) { var a, c, d, l, A, h, u, g, f; const o = (a = this._matches.get(e)) != null ? a : [], r = this._univerInstanceService.getCurrentUnitForType(_.UNIVER_DOC), s = this._textSelectionManagerService.getDocRanges(), i = (c = s.find((p) => p.isActive)) != null ? c : s[0]; if (r && i) { const p = r.getSelfOrHeaderFooterModel(i.segmentId), m = { unit: p, selection: i, isBody: !i.segmentId, paragraphs: le.range.getParagraphsInRange(i, (l = (d = p.getBody()) == null ? void 0 : d.paragraphs) != null ? l : [], (h = (A = p.getBody()) == null ? void 0 : A.dataStream) != null ? h : ""), customRanges: le.customRange.getCustomRangesInterestsWithSelection(i, (g = (u = p.getBody()) == null ? void 0 : u.customRanges) != null ? g : []), commandId: e, commandParams: t }, I = o.find((S) => S.match(m)); return (f = I == null ? void 0 : I.getMutations(m)) != null ? f : []; } return []; } }; _t = od([ Zs(0, L), Zs(1, j(Y)) ], _t); const rd = { undo: !0, redo: !0, // Undo redo font: !0, // 'font' fontSize: !0, // 'Font size' bold: !0, // 'Bold (Ctrl+B)' italic: !0, // 'Italic (Ctrl+I)' strikethrough: !0, // 'Strikethrough (Alt+Shift+5)' underline: !0, // 'Underline (Alt+Shift+6)' textColor: !0, // 'Text color' fillColor: !0, // 'Cell color' horizontalAlignMode: !0, // 'Horizontal alignment' verticalAlignMode: !0, // 'Vertical alignment' textWrapMode: !0, // 'Wrap mode' textRotateMode: !0 // 'Text Rotation Mode' }, sd = { outerLeft: !1, outerRight: !1, header: !0, footer: !0, innerLeft: !1, innerRight: !1, frozenHeaderLT: !1, frozenHeaderRT: !1, frozenHeaderLM: !1, frozenContent: !1, infoBar: !0, toolbar: !0 }, id = "DOC_UI_PLUGIN"; var et = /* @__PURE__ */ ((n) => (n.MAIN = "__Document_Render_Main__", n.BACKGROUND = "__Document_Render_Background__", n))(et || {}), je = /* @__PURE__ */ ((n) => (n.VIEW_MAIN = "viewMain", n.VIEW_TOP = "viewTop", n.VIEW_LEFT = "viewLeft", n.VIEW_LEFT_TOP = "viewLeftTop", n))(je || {}); const ad = 0, jo = 2, cd = 4, Js = 10, Yf = "normalTextSelectionPluginName"; function ft(n) { const { mainComponent: e, scene: t, engine: o, components: r } = n, s = e, i = r.get(et.BACKGROUND); return { document: s, docBackground: i, scene: t, engine: o }; } function ld(n, e) { const t = n.getCurrentUnitForType(_.UNIVER_DOC); if (!t) return null; const o = t.getUnitId(), r = e.getRenderById(o); if (r == null) return; const { mainComponent: s, scene: i, engine: a, components: c } = r, d = s, l = c.get(et.BACKGROUND); return { document: d, docBackground: l, scene: i, engine: a }; } function Kf(n, e) { const t = e.getRenderById(n); if (t == null) return; const { mainComponent: o, scene: r, engine: s, components: i } = t, a = o, c = i.get(et.BACKGROUND); return { document: a, docBackground: c, scene: r, engine: s }; } function dd(n) { const { unitId: e, ranges: t, id: o, type: r, segmentId: s } = n, i = { id: X.id, params: { unitId: e, actions: [], textRanges: void 0, // noHistory: true, segmentId: s } }, a = W.getInstance(), c = le.customDecoration.add({ ranges: t, id: o, type: r }); return i.params.actions = a.editOp(c.serialize()), i; } function qf(n, e) { const { segmentId: t, id: o, type: r, unitId: s } = e, i = n.get(Y), a = n.get(L), c = s ? a.getUnit(s, _.UNIVER_DOC) : a.getCurrentUnitForType(_.UNIVER_DOC); if (!c) return !1; const d = c.getUnitId(), l = i.getTextRanges({ unitId: d, subUnitId: d }); return !l || !c.getBody() ? !1 : dd( { unitId: d, ranges: l, id: o, type: r, segmentId: t } ); } function Xf(n, e) { const { unitId: t, id: o, segmentId: r } = e, i = n.get(L).getUnit(t); if (!i) return !1; const a = { id: X.id, params: { unitId: t, actions: [], textRanges: void 0, // noHistory: true, segmentId: r } }, c = le.customDecoration.delete({ id: o, segmentId: r, documentDataModel: i }); if (!c) return !1; const d = W.getInstance(); return a.params.actions = d.editOp(c.serialize()), a; } function Zf(n, e) { return e.some((t) => n.startIndex > t.startIndex && n.startIndex < t.endIndex); } function To(n, e, t, o, r) { const { textRuns: s = [], dataStream: i } = n, a = r && i.startsWith("="), c = { st: 0, ed: 0, ts: {} }; if (a) return c; for (let d = s.length - 1; d >= 0; d--) { const l = s[d], { st: A, ed: h } = l; e > A && e <= h && (c.st = A, c.ed = h, c.ts = { ...c.ts, ...l.ts }); } if (e === 0) { const d = s == null ? void 0 : s[0]; d && d.st === 0 && (c.ts = { ...c.ts, ...d.ts }); } return o && (c.ts = { ...c.ts, ...o }), c; } function jr(n, e, t) { if (t) { const r = n.find((s) => e >= s.startIndex && e <= s.endIndex + 1); return r != null && r.wholeEntity ? null : r; } const o = n.find((r) => e > r.startIndex && e <= r.endIndex); return o != null && o.wholeEntity ? null : o; } function zr(n, e) { return n.filter((t) => e > t.startIndex && e <= t.endIndex); } function Jf(n) { return { left: n.positionH.posOffset, top: n.positionV.posOffset, width: n.size.width, height: n.size.height }; } function $f(n, e = 0, t = 0) { return { size: { width: n.width, height: n.height }, positionH: { relativeFrom: Ro.MARGIN, posOffset: (n.left || 0) - e }, positionV: { relativeFrom: ht.PAGE, posOffset: (n.top || 0) - t }, angle: n.angle || 0 }; } function Ad(n, e, t) { const o = J(T), r = J(xo), s = Me(() => Fe(4), []); ve(() => { if (!t || !n || !e) return; const a = `sheet.operation.editor-${t.getEditorId()}-keyboard-${s}`, c = new In(); return c.add(o.registerCommand({ id: a, type: D.OPERATION, handler(d, l) { const { keyCode: A, metaKey: h } = l; e.handler(A, h); } })), e.keyCodes.map((d) => ({ id: a, binding: d.metaKey ? d.keyCode | d.metaKey : d.keyCode, preconditions: () => !0, priority: 901, staticParameters: { eventType: $i.Keyboard, keyCode: d.keyCode, metaKey: d.metaKey } })).forEach((d) => { c.add(r.registerShortcut(d)); }), () => { c.dispose(); }; }, [o, e, t, n, s, r]); } const ud = (n, e = !0, t, o) => { const r = ha(() => { if (n) { const { scene: i, mainComponent: a } = n.render, c = n.render.with(Ae), { width: d, height: l } = n.getBoundingClientRect(); c.getViewModel().getDataModel().updateDocumentDataPageSize(e ? 1 / 0 : d, 1 / 0), i.transformByState({ width: d, height: l }), a == null || a.resize(d, l); } }, [n, e]), s = Me(() => Pr(() => { var I, S; if (!t || !n || !t) return; const a = n.render.with(Ae).getSkeleton(), { scene: c, mainComponent: d } = n.render, l = c.getViewport(je.VIEW_MAIN), { actualWidth: A, actualHeight: h } = a.getActualSize(), { width: u, height: g } = n.getBoundingClientRect(); let f = l == null ? void 0 : l.getScrollBar(); const p = Math.max(A, u), m = Math.max(h, g); c.transformByState({ width: p, height: m }), d == null || d.resize(p, m), e ? A > u ? (f == null ? l && new ar(l, { barSize: 8, enableVertical: !1, enableHorizontal: !0, minThumbSizeV: 8 }) : l == null || l.resetCanvasSizeAndUpdateScroll(), o && (l == null || l.scrollToBarPos({ x: 1 / 0, y: 0 }))) : (f = null, l == null || l.scrollToBarPos({ x: 0, y: 0 }), (S = l == null ? void 0 : l.getScrollBar()) == null || S.dispose()) : h > g ? (f == null ? l && (f = new ar(l, { enableHorizontal: !1, enableVertical: !0, barSize: 8, minThumbSizeV: 8 })) : l == null || l.resetCanvasSizeAndUpdateScroll(), o && (l == null || l.scrollToBarPos({ x: 0, y: 1 / 0 }))) : (f = null, l == null || l.scrollToBarPos({ x: 0, y: 0 }), (I = l == null ? void 0 : l.getScrollBar()) == null || I.dispose()); }, 30), [n, t, e, o]); return ve(() => { if (t && n) { const i = setTimeout(() => { r(), s(); }, 500); return () => { clearTimeout(i); }; } }, [n, t, r, s]), ve(() => { if (t && n) { const i = n.input$.subscribe(() => { s(); }); return () => { i.unsubscribe(); }; } }, [n, t, s]), { resize: r, checkScrollBar: s }; }; function qe(n, e) { var o; return (o = n.get(fe).getRenderById(e)) == null ? void 0 : o.with(Ae); } function ue(n, e = "") { if (!e) return ["body"]; const { headers: t, footers: o } = n.getSnapshot(); if (t == null && o == null) throw new Error("Document data model must have headers or footers when update by segment id"); if ((t == null ? void 0 : t[e]) != null) return ["headers", e, "body"]; if ((o == null ? void 0 : o[e]) != null) return ["footers", e, "body"]; throw new Error("Segment id not found in headers or footers"); } const ma = { id: "doc.command-replace-snapshot", type: D.COMMAND, // eslint-disable-next-line max-lines-per-function, complexity handler: (n, e) => { const { unitId: t, snapshot: o, textRanges: r, segmentId: s = "", options: i } = e, a = n.get(L), c = n.get(T), d = n.get(Y), l = a.getUnit(t, _.UNIVER_DOC), A = l == null ? void 0 : l.getSelfOrHeaderFooterModel(s).getSnapshot(); if (l == null || A == null) return !1; const { body: h, tableSource: u, footers: g, headers: f, lists: p, drawings: m, drawingsOrder: I, documentStyle: S } = te.deepClone(o), { body: v, tableSource: R, footers: E, headers: b, lists: y, drawings: C, drawingsOrder: B, documentStyle: x } = A; if (h == null || v == null) return !1; if (te.diffValue(h, v) && r) return d.replaceDocRanges(r, { unitId: t, subUnitId: t }, !1), !0; const M = { id: X.id, params: { unitId: t, actions: [], textRanges: r } }; i && (M.params.options = i); const P = [], F = W.getInstance(); if (!te.diffValue(x, S)) { const N = F.replaceOp(["documentStyle"], x, S); N != null && P.push(N); } if (!te.diffValue(h, v)) { const N = F.replaceOp(["body"], v, h); N != null && P.push(N); } if (!te.diffValue(u, R)) { const N = F.replaceOp(["tableSource"], R, u); N != null && P.push(N); } if (!te.diffValue(g, E)) { const N = F.replaceOp(["footers"], E, g); N != null && P.push(N); } if (!te.diffValue(f, b)) { const N = F.replaceOp(["headers"], b, f); N != null && P.push(N); } if (!te.diffValue(p, y)) { const N = F.replaceOp(["lists"], y, p); N != null && P.push(N); } if (!te.diffValue(m, C)) { const N = F.replaceOp(["drawings"], C, m); N != null && P.push(N); } if (!te.diffValue(I, B)) { const N = F.replaceOp(["drawingsOrder"], B, I); N != null && P.push(N); } return M.params.actions = P.reduce((N, ee) => W.compose(N, ee), null), !!c.syncExecuteCommand(M.id, M.params); } }, hd = { id: "doc.command-replace-content", type: D.COMMAND, handler: async (n, e) => { const { unitId: t, body: o, textRanges: r, segmentId: s = "", options: i } = e, a = n.get(L), c = n.get(T), d = n.get(Y), l = a.getUnit(t, _.UNIVER_DOC), A = l == null ? void 0 : l.getSelfOrHeaderFooterModel(s).getSnapshot().body; if (l == null || A == null) return !1; const h = Ea(t, s, l, A, o); return h.params.textRanges = r, i && (h.params.options = i), h.params.actions == null && r ? (d.replaceDocRanges(r, { unitId: t, subUnitId: t }, !1), !0) : !!c.syncExecuteCommand(h.id, h.params); } }, gd = { id: "doc.command-cover-content", type: D.COMMAND, handler: (n, e) => { const { unitId: t, body: o, segmentId: r = "", textRanges: s } = e, i = n.get(L), a = n.get(T), c = n.get(bo), d = i.getUniverDocInstance(t), l = d == null ? void 0 : d.getSnapshot().body; if (d == null || l == null) return !1; const A = Ea(t, r, d, l, o); return A.params.noNeedSetTextRange = !0, A.params.noHistory = !0, A.params.textRanges = s, a.syncExecuteCommand( A.id, A.params ), c.clearUndoRedo(t), !0; } }; function fd(n, e, t, o) { const r = new me(), s = W.getInstance(), i = (t == null ? void 0 : t.dataStream.length) - 2; i > 0 && r.push({ t: G.DELETE, len: i }), o.dataStream.length > 0 && r.push({ t: G.INSERT, body: o, len: o.dataStream.length }); const a = ue(e, n); return s.editOp(r.serialize(), a); } function Ea(n, e, t, o, r) { const s = { id: X.id, params: { unitId: n, actions: [], textRanges: [] } }, i = fd(e, t, o, r); return s.params.actions = i, s; } const Ia = { id: "doc.command.replace-selection", type: D.COMMAND, handler(n, e) { var g; if (!e) return !1; const t = n.get(T), { unitId: o, body: r, textRanges: s } = e, a = n.get(L).getUnit(o), c = n.get(Y); if (!a) return !1; const d = a.getBody(), l = (g = e.selection) != null ? g : c.getActiveTextRange(); if (!l || !d) return !1; const A = { id: X.id, params: { unitId: o, actions: [], textRanges: s, debounce: !0 } }, h = new me(), u = W.getInstance(); return h.push(...le.selection.delete([l], d, 0, r)), A.params.actions = u.editOp(h.serialize()), t.syncExecuteCommand(A.id, A.params); } }, pd = { id: "doc.command.replace-text-runs", type: D.COMMAND, handler: (n, e) => { const { unitId: t, body: o, textRanges: r, segmentId: s = "", options: i } = e, a = n.get(L), c = n.get(T), d = n.get(wr), l = a.getUnit(t, _.UNIVER_DOC), A = l == null ? void 0 : l.getSelfOrHeaderFooterModel(s).getSnapshot().body; if (l == null || A == null) return !1; const h = le.selection.replaceTextRuns({ doc: l, body: o, selection: { startOffset: 0, endOffset: A.dataStream.length - 2, collapsed: !1 }, themeService: d }); if (!h) return !1; const u = { id: X.id, params: { unitId: t, actions: [], textRanges: r, noHistory: !0 } }, g = W.getInstance(), f = ue(l, s); return u.params.actions = g.editOp(h.serialize(), f), u.params.textRanges = r, i && (u.params.options = i), !!c.syncExecuteCommand(u.id, u.params); } }; var Xn = /* @__PURE__ */ ((n) => (n[n.page = 0] = "page", n[n.section = 1] = "section", n[n.column = 2] = "column", n[n.line = 3] = "line", n[n.divide = 4] = "divide", n[n.glyph = 5] = "glyph", n))(Xn || {}); const Kt = { page: 0, section: 1, column: 2, line: 3, divide: 4, glyph: 5 }; function Gr(n, e) { return n.page > e.page ? !1 : n.page < e.page ? !0 : n.section > e.section ? !1 : n.section < e.section ? !0 : n.column > e.column ? !1 : n.column < e.column ? !0 : n.line > e.line ? !1 : n.line < e.line ? !0 : n.divide > e.divide ? !1 : n.divide < e.divide ? !0 : n.glyph > e.glyph ? !1 : (n.glyph < e.glyph, !0); } function dr(n, e) { return Gr(n, e) ? { start: n, end: e } : { start: e, end: n }; } function $s(n) { const e = n.length; if (e === 0) return; const t = n[0], o = n[e - 1], r = n.length === 1 && t.collapsed; return { startOffset: t.startOffset, endOffset: o.endOffset, collapsed: r }; } function md(n, e, t, o) { let r = o, s = o; for (let i = 0; i < n.length; i++) { const c = n[i].count; i < e && (r += c), i < t && (s += c); } return { startOffset: r, endOffset: s }; } function Ar(n) { const { startX: e, startY: t, endX: o, endY: r } = n, s = []; return s.push({ x: e, y: t }), s.push({ x: o, y: t }), s.push({ x: o, y: r }), s.push({ x: e, y: r }), s.push({ x: e, y: t }), s; } class pt { constructor(e, t) { O(this, "_liquid", new ea()); O(this, "_currentStartState", { page: 0, section: 0, column: 0, line: 0, divide: 0, glyph: 0 /* NORMAL */ }); O(this, "_currentEndState", { page: 0, section: 0, column: 0, line: 0, divide: 0, glyph: 0 /* NORMAL */ }); this._documentOffsetConfig = e, this._docSkeleton = t; } // eslint-disable-next-line max-lines-per-function getRangePointData(e, t) { const o = [], r = [], s = []; if (e == null || t == null) return { borderBoxPointGroup: o, contentBoxPointGroup: r, cursorList: s }; if (!this._isValidPosition(e, t)) throw new Error( ` Invalid positions in NodePositionConvertToCursor, they are not in the same segment page when in header or footer.` ); const { start: a, end: c } = dr(e, t); return this._selectionIterator(a, c, (d, l, A, h, u, g) => { const { lineHeight: f, asc: p, paddingTop: m, marginTop: I, marginBottom: S } = g, { glyphGroup: v, st: R } = u; if (v.length === 0) return; const { x: E, y: b } = this._liquid; let y, C; const B = v[d], x = v[l], M = v[d - 1], P = (B == null ? void 0 : B.left) || 0, F = (B == null ? void 0 : B.width) || 0, w = (x == null ? void 0 : x.left) || 0, N = (x == null ? void 0 : x.width) || 0, ee = (B == null ? void 0 : B.glyphType) === ta.LIST, { startOffset: $, endOffset: U } = md(v, d, l, R), H = a.glyph === d && A ? a.isBack : !0, k = c.glyph === l && h ? c.isBack : !1, oe = a === c, ae = H && M != null ? M : B; if (d === 0 && l === v.length - 1) y = { startX: E + P + (ee ? F : 0), startY: b, endX: E + w + (k ? 0 : N), endY: b + f - I - S }, C = { startX: E + P + (ee ? F : 0), startY: b + m + p - ae.bBox.ba, endX: E + w + (k ? 0 : N), endY: b + m + p + ae.bBox.bd }; else { const ce = H && !ee; y = { startX: E + P + (ce ? 0 : F), startY: b, endX: E + w + (k ? 0 : N), endY: b + f - I - S }, C = { startX: E + P + (ce ? 0 : F), startY: b + m + p - ae.bBox.ba, endX: E + w + (k ? 0 : N), endY: b + m + p + ae.bBox.bd }; } o.push(Ar(y)), r.push(Ar(C)), s.push({ startOffset: H ? $ : $ + B.count, endOffset: k ? U : U + x.count, collapsed: oe }); }), { borderBoxPointGroup: o, contentBoxPointGroup: r, cursorList: s }; } _isValidPosition(e, t) { const { segmentPage: o, pageType: r } = e, { segmentPage: s, pageType: i } = t; return r !== i ? !1 : r === xe.HEADER || r === xe.FOOTER ? o === s : !0; } _resetCurrentNodePositionState() { this._currentStartState = { page: 0, section: 0, column: 0, line: 0, divide: 0, glyph: 0 /* NORMAL */ }, this._currentEndState = { page: 0, section: 0, column: 0, line: 0, divide: 0, glyph: 0 /* NORMAL */ }; } _setNodePositionState(e = 0, t, o, r) { r === t ? this._currentStartState[e] = 1 : this._currentStartState[e] = 0, r === o ? this._currentEndState[e] = 2 : this._currentEndState[e] = 0; } _checkPreviousNodePositionState(e, t = !0) { let o = e, r; for (; o >= 0; ) { const s = Xn[o]; let i; if (t ? i = this._currentStartState[s] : i = this._currentEndState[s], i === void 0) return; if (r === void 0 && (r = i), i !== r) return 0; o--; } return r; } _getSelectionRuler(e, t, o, r, s) { let i = 0, a = r; const c = Xn[e], d = Xn[e + 1]; if (d === null || c === null) return { start_next: i, end_next: a }; const l = t[c], A = o[c]; this._setNodePositionState(c, l, A, s); const h = this._checkPreviousNodePositionState(e), u = this._checkPreviousNodePositionState(e, !1); return h === 1 && (i = t[d]), u === 2 && (a = o[d]), { start_next: i, end_next: a }; } // eslint-disable-next-line max-lines-per-function, complexity _selectionIterator(e, t, o) { var v, R; const r = this._docSkeleton; if (!r) return []; const { pageType: s, path: i } = e; this._liquid.reset(); const a = r.getSkeletonData(); if (a == null) return []; const { pages: c, skeHeaders: d, skeFooters: l } = a, { page: A, segmentPage: h } = e, { page: u, segmentPage: g } = t; if (this._resetCurrentNodePositionState(), this._documentOffsetConfig == null) return []; const { pageLayoutType: f, pageMarginLeft: p, pageMarginTop: m } = this._documentOffsetConfig, I = s === xe.BODY || s === xe.CELL ? A : h; for (let E = 0; E < I; E++) { const b = c[E]; this._liquid.translatePage(b, f, p, m); } const S = s === xe.BODY || s === xe.CELL ? u : g; for (let E = I; E <= S; E++) { const b = c[E], { headerId: y, footerId: C, pageWidth: B } = b; let x = b; if (s === xe.HEADER ? x = (v = d.get(y)) == null ? void 0 : v.get(B) : s === xe.FOOTER ? x = (R = l.get(C)) == null ? void 0 : R.get(B) : s === xe.CELL && (x = cr(a, i)), x == null) { this._liquid.translatePage(b, f, p, m); continue; } const M = x.sections, { start_next: P, end_next: F } = this._getSelectionRuler( Kt.page, e, t, M.length - 1, s === xe.BODY || s === xe.CELL ? E : 0 ); switch (this._liquid.translateSave(), s) { case xe.HEADER: this._liquid.translatePagePadding({ ...x, marginLeft: b.marginLeft // Because header or footer margin Left is 0. }); break; case xe.FOOTER: { const w = b.pageHeight - x.height - x.marginBottom; this._liquid.translate(b.marginLeft, w); break; } case xe.CELL: { this._liquid.translatePagePadding(b); const w = x.parent, N = w.parent, { left: ee } = x, { top: $, left: U } = N, { top: H } = w; this._liquid.translate(U + ee, $ + H), this._liquid.translatePagePadding(x); break; } default: this._liquid.translatePagePadding(b); break; } for (let w = P; w <= F; w++) { const N = M[w], ee = N.columns, { start_next: $, end_next: U } = this._getSelectionRuler( Kt.section, e, t, ee.length - 1, w ); this._liquid.translateSection(N); for (let H = $; H <= U; H++) { const k = ee[H], oe = k.lines, { start_next: ae, end_next: ce } = this._getSelectionRuler( Kt.column, e, t, oe.length - 1, H ); this._liquid.translateColumn(k); for (let re = ae; re <= ce; re++) { const he = oe[re], { divides: De } = he, { start_next: Je, end_next: At } = this._getSelectionRuler( Kt.line, e, t, De.length - 1, re ); this._liquid.translateSave(), this._liquid.translateLine(he, !0, !1); for (let $e = Je; $e <= At; $e++) { const Vo = De[$e]; this._liquid.translateSave(), this._liquid.translateDivide(Vo); const { glyphGroup: Oc } = Vo, { start_next: Tc, end_next: Bc } = this._getSelectionRuler( Kt.divide, e, t, Oc.length - 1, $e ); let Ns = !1, Ls = !1; E === I && w === P && H === $ && re === ae && $e === Je && (Ns = !0), E === S && w === F && H === U && re === ce && $e === At && (Ls = !0), o && o(Tc, Bc, Ns, Ls, Vo, he, k, N, x), this._liquid.translateRestore(); } this._liquid.translateRestore(); } } } this._liquid.translateRestore(), this._liquid.translatePage(b, f, p, m); } } } function Ed(n, e) { const { path: t } = n, { path: o } = e; if (t.length !== o.length || t.indexOf("cells") === -1) return !1; const r = t.indexOf("skeTables") + 1, s = t.indexOf("rows") + 1, i = t.indexOf("cells") + 1, { tableId: a, sliceIndex: c } = Vs(t[r]), { tableId: d, sliceIndex: l } = Vs(o[r]); if (a !== d) return !1; const A = t[s], h = o[s], u = t[i], g = o[i]; return !(A === h && u === g && c === l); } function Sa(n, e) { const { path: t } = n, { path: o } = e; return t.indexOf("cells") === -1 || o.indexOf("cells") === -1 || t.length !== o.length ? !1 : te.diffValue(t, o); } function va(n, e, t) { var u, g, f, p, m, I, S, v; const { path: o } = e, { path: r } = t; if (o.indexOf("cells") === -1 || r.indexOf("cells") === -1) return !1; const s = n.findGlyphByPosition(e), i = n.findGlyphByPosition(t), a = (p = (f = (g = (u = s == null ? void 0 : s.parent) == null ? void 0 : u.parent) == null ? void 0 : g.parent) == null ? void 0 : f.parent) == null ? void 0 : p.parent, c = (v = (S = (I = (m = i == null ? void 0 : i.parent) == null ? void 0 : m.parent) == null ? void 0 : I.parent) == null ? void 0 : S.parent) == null ? void 0 : v.parent; if (a == null || c == null) return !1; const d = a.parent, l = c.parent, A = d.cells.indexOf(a), h = l.cells.indexOf(c); return A === h && d.index === l.index; } function zo(n, e) { if (Sa(n, e)) return Gr(n, e); const { path: t } = n, { path: o } = e, r = t[t.length - 5], s = o[o.length - 5]; if (r !== s && typeof r == "string" && typeof s == "string") { const l = r.split("#-#")[1], A = s.split("#-#")[1]; return +l < +A; } const i = t[t.length - 3], a = o[o.length - 3], c = t[t.length - 1], d = o[o.length - 1]; return i < a ? !0 : i > a ? !1 : c <= d; } function jt(n) { return n.sections[0].columns[0].lines.length === 0; } function Id(n, e, t) { let o = e, r = t, s = n[o], i = n[r]; for (; o < r && (jt(s) || jt(i)); ) jt(s) ? (o++, s = n[o]) : jt(i) && (r--, i = n[r]); if (!jt(s) && !jt(i)) return [s, i]; } class Ca { constructor(e, t) { O(this, "_liquid", new ea()); this._documentOffsetConfig = e, this._docSkeleton = t; } // eslint-disable-next-line max-lines-per-function getRangePointData(e, t) { const o = [], s = this._docSkeleton.getSkeletonData(); if (s == null) return; const { pages: i } = s, { segmentPage: a, page: c, pageType: d } = e, l = this._getTableRectRangeInfo(e, t); if (l == null) return; const { tableId: A, startRowIndex: h, startColumnIndex: u, endRowIndex: g, endColumnIndex: f } = l; this._liquid.reset(); const { pageLayoutType: p, pageMarginLeft: m, pageMarginTop: I } = this._documentOffsetConfig, S = d === xe.BODY || d === xe.CELL ? c : a; for (let v = 0; v < S; v++) { const R = i[v]; this._liquid.translatePage(R, p, m, I); } for (let v = S; v < i.length; v++) { const R = i[v]; this._liquid.translatePagePadding(R); const { skeTables: E } = R; let b = null; for (const [x, M] of E.entries()) x.startsWith(A) && (b = M); if (b == null) { this._liquid.restorePagePadding(R), this._liquid.translatePage(R, p, m, I); continue; } this._liquid.translateSave(), this._liquid.translate(0, b.top); const { x: y, y: C } = this._liquid, { left: B } = b; for (const x of b.rows) if (x.index >= h && x.index <= g) { const M = Id(x.cells, u, f); if (M == null) continue; const [P, F] = M, w = { startX: y + P.left + B, startY: C + x.top, endX: y + F.left + F.pageWidth + B, endY: C + x.top + x.height }; o.push(Ar(w)); } this._liquid.translateRestore(), this._liquid.restorePagePadding(R), this._liquid.translatePage(R, p, m, I); } return { pointGroup: o, startRow: h, startColumn: u, endRow: g, endColumn: f, tableId: A }; } getNodePositionGroup(e, t) { const o = [], r = this._docSkeleton.findCharIndexByPosition(e), s = this._docSkeleton.findCharIndexByPosition(t); if (r == null || s == null) return; const i = r < s, a = this._getTableRectRangeInfo(e, t); if (a == null) return; const { tableId: c, startRowIndex: d, startColumnIndex: l, endRowIndex: A, endColumnIndex: h } = a, u = this._docSkeleton.getViewModel().findTableNodeById(c); if (u == null) return; const g = u.children[0].children.length; if (l === 0 && h === g - 1) { const p = u.children[d].children[l], m = this._docSkeleton.findNodePositionByCharIndex(p.startIndex + 1), I = u.children[A].children[h], S = this._docSkeleton.findNodePositionByCharIndex(I.endIndex - 2); if (m == null || S == null) return; o.push({ anchor: i ? m : S, focus: i ? S : m }); } else for (let p = d; p <= A; p++) { const m = u.children[p], I = m.children[l], S = m.children[h], v = this._docSkeleton.findNodePositionByCharIndex(I.startIndex + 1), R = this._docSkeleton.findNodePositionByCharIndex(S.endIndex - 2); if (v == null || R == null) return; o.push({ anchor: i ? v : R, focus: i ? R : v }); } return o; } _getTableRectRangeInfo(e, t) { const r = this._docSkeleton.getSkeletonData(); if (r == null) return; const { pages: s } = r, { path: i } = e, { path: a } = t, c = cr(r, i), d = cr(r, a); if (c == null || d == null) return; const l = c.segmentId, A = c.parent.index, h = c.parent.cells.indexOf(c), u = (d == null ? void 0 : d.parent).index, g = (d == null ? void 0 : d.parent).cells.indexOf(d), f = Math.min(A, u), p = Math.max(A, u), m = Math.min(h, g), I = Math.max(h, g); return { pages: s, tableId: l, startRowIndex: f, startColumnIndex: m, endRowIndex: p, endColumnIndex: I }; } } const Sd = "__TestSelectionRange__", vd = "__TestSelectionAnchor__", ei = 6, Go = 500, Cd = 500, ur = 3; function Zn(n) { const e = n[0], t = e[0], o = e[2], { x: r, y: s } = t, { x: i, y: a } = o; return { left: r, top: s, width: i - r, height: a - s }; } function Yr(n) { return n.map((e) => { let t = 1 / 0, o = -1 / 0, r = 1 / 0, s = -1 / 0; return e.forEach((i) => { t = Math.min(i.x, t), o = Math.max(i.x, o), s = Math.max(i.y, s), r = Math.min(i.y, r); }), { left: t, right: o, top: r, bottom: s }; }); } class Zt { constructor(e, t, o, r, s, i = vn, a = "", c = -1) { O(this, "rangeType", He.TEXT); // Identifies whether the range is the current one, most of which is the last range. O(this, "_current", !1); // The rendered range graphic when collapsed is false O(this, "_rangeShape"); // The rendered range graphic when collapsed is true O(this, "_anchorShape"); O(this, "_cursorList", []); O(this, "_anchorBlinkTimer", null); this._scene = e, this._document = t, this._docSkeleton = o, this.anchorNodePosition = r, this.focusNodePosition = s, this.style = i, this._segmentId = a, this._segmentPage = c, this._anchorBlink(), this.refresh(); } _anchorBlink() { setTimeout(() => { this._anchorShape && this._anchorShape.visible && this.deactivateStatic(); }, Go), this._anchorBlinkTimer = setInterval(() => { this._anchorShape && this._anchorShape.visible && (this.activeStatic(), setTimeout(() => { this.deactivateStatic(); }, Go)); }, Cd + Go); } // The start position of the range get startOffset() { var r; const { startOffset: e } = (r = $s(this._cursorList)) != null ? r : {}, t = this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody(); if (e == null || t == null) return e; const o = t.dataStream.length - 2; return Math.min(o, e); } // The end position of the range get endOffset() { var r; const { endOffset: e } = (r = $s(this._cursorList)) != null ? r : {}, t = this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody(); if (e == null || t == null) return e; const o = t.dataStream.length - 2; return Math.min(e, o); } get collapsed() { const { startOffset: e, endOffset: t } = this; return e != null && e === t; } get startNodePosition() { if (this.anchorNodePosition == null) return null; if (this.focusNodePosition == null) return this.anchorNodePosition; const { start: e } = dr(this.anchorNodePosition, this.focusNodePosition); return e; } get endNodePosition() { if (this.anchorNodePosition == null) return this.focusNodePosition; if (this.focusNodePosition == null) return null; const { end: e } = dr(this.anchorNodePosition, this.focusNodePosition); return e; } get direction() { const { collapsed: e, anchorNodePosition: t, focusNodePosition: o } = this; return e || t == null || o == null ? _e.NONE : Gr(t, o) ? _e.FORWARD : _e.BACKWARD; } get segmentId() { return this._segmentId; } get segmentPage() { return this._segmentPage; } getAbsolutePosition() { const e = this.anchorNodePosition, t = this.focusNodePosition; if (this._isEmpty()) return; const o = this._document.getOffsetConfig(), { docsLeft: r, docsTop: s } = o, i = new pt(o, this._docSkeleton); if (this._isCollapsed()) { const { contentBoxPointGroup: l, cursorList: A } = i.getRangePointData(e, e); if (this._setCursorList(A), l.length === 0) return; const h = Zn(l); return { ...h, left: h.left + r, top: h.top + s }; } const { borderBoxPointGroup: a, cursorList: c } = i.getRangePointData(e, t); if (this._setCursorList(c), a.length === 0) return; const d = Zn(a); return { ...d, left: d.left + r, top: d.top + s }; } getAnchor() { return this._anchorShape; } activeStatic() { var e, t; (t = this._anchorShape) == null || t.setProps({ stroke: ((e = this.style) == null ? void 0 : e.strokeActive) || pn(fn.black, 1) }); } deactivateStatic() { var e, t; (t = this._anchorShape) == null || t.setProps({ stroke: ((e = this.style) == null ? void 0 : e.stroke) || pn(fn.black, 0) }); } isActive() { return this._current === !0; } activate() { this._current = !0; } deactivate() { this._current = !1; } dispose() { var e, t; (e = this._rangeShape) == null || e.dispose(), this._rangeShape = null, (t = this._anchorShape) == null || t.dispose(), this._anchorShape = null, this._anchorBlinkTimer && (clearInterval(this._anchorBlinkTimer), this._anchorBlinkTimer = null); } isIntersection(e) { const { startOffset: t, endOffset: o } = this, { startOffset: r, endOffset: s } = e; return t == null || o == null || r == null || s == null ? !1 : t <= s && o >= r; } // render cursor and selection. refresh() { var A, h; const { _document: e, _docSkeleton: t } = this, o = this.anchorNodePosition, r = this.focusNodePosition; if ((A = this._anchorShape) == null || A.hide(), (h = this._rangeShape) == null || h.hide(), this._isEmpty()) return; const s = e.getOffsetConfig(), { docsLeft: i, docsTop: a } = s, c = new pt(s, t); if (this._isCollapsed()) { const { contentBoxPointGroup: u, cursorList: g } = c.getRangePointData(o, o); if (this._setCursorList(g), u.length > 0) { const f = t.findGlyphByPosition(o); this._createOrUpdateAnchor(u, i, a, f); } return; } const { borderBoxPointGroup: d, cursorList: l } = c.getRangePointData(o, r); this._setCursorList(l), d.length > 0 && this._createOrUpdateRange(d, i, a); } _isEmpty() { return this.anchorNodePosition == null && this.focusNodePosition == null; } _isCollapsed() { const e = this.anchorNodePosition, t = this.focusNodePosition; if (e != null && t == null) return !0; if (e == null || t == null) return !1; const o = Object.keys(Kt); for (const r of o) { const s = e[r], i = t[r]; if (s !== i) return !1; } return e.isBack === t.isBack; } _createOrUpdateRange(e, t, o) { var i; if (this._rangeShape) { this._rangeShape.translate(t, o), this._rangeShape.updatePointGroup(e), this._rangeShape.show(); return; } const r = 0.3, s = new na(Sd + te.generateRandomId(ei), { pointsGroup: e, fill: ((i = this.style) == null ? void 0 : i.fill) || pn(fn.black, r), left: t, top: o, evented: !1, debounceParentDirty: !1 }); this._rangeShape = s, this._scene.addObject(s, ur); } _createOrUpdateAnchor(e, t, o, r) { var f, p, m; const s = Zn(e), { left: i } = s; let { top: a, height: c } = s; const d = 14; c < d && (a -= d - c, c = d); const l = 12; let A = i + t; const h = a + o, u = ((f = r == null ? void 0 : r.ts) == null ? void 0 : f.it) === z.TRUE; if (u && (A += c * Math.tan(l * Math.PI / 180) / 2), this._anchorShape) { this._anchorShape.transformByState({ left: A, top: h, height: c }), this._anchorShape.show(), u ? this._anchorShape.skew(-12, 0) : this._anchorShape.skew(0, 0); return; } const g = new qn(vd + Fe(ei), { left: A, top: h, height: c, strokeWidth: ((p = this.style) == null ? void 0 : p.strokeWidth) || 1, stroke: ((m = this.style) == null ? void 0 : m.strokeActive) || pn(fn.black, 1), evented: !1 }); u && g.skew(-12, 0), this._anchorShape = g, this._scene.addObject(g, ur), this.activeStatic(); } _setCursorList(e) { e.length !== 0 && (this._cursorList = e); } } const Rd = "__DocTableRectRange__", bd = 6; function Yo(n, e, t, o, r, s = vn, i = "", a = -1) { const c = e.getOffsetConfig(), l = new Ca(c, t).getNodePositionGroup(o, r); return (l != null ? l : []).map((A) => new Ra( n, e, t, A.anchor, A.focus, s, i, a )); } class Ra { constructor(e, t, o, r, s, i = vn, a = "", c = -1) { O(this, "rangeType", He.RECT); // The rendered rect range O(this, "_rangeShape"); // Identifies whether the range is the current one, most of which is the last range. O(this, "_current", !1); // Rect Range start row. O(this, "_startRow"); // Rect Range start column. O(this, "_startCol"); // Rect Range end row. O(this, "_endRow"); // Rect Range end column. O(this, "_endCol"); // table id in view model. O(this, "_tableId"); this._scene = e, this._document = t, this._docSkeleton = o, this.anchorNodePosition = r, this.focusNodePosition = s, this.style = i, this._segmentId = a, this._segmentPage = c, this.refresh(); } get startOffset() { const { startNodePosition: e } = this; return this._docSkeleton.findCharIndexByPosition(e); } get endOffset() { const { endNodePosition: e } = this; return this._docSkeleton.findCharIndexByPosition(e); } get collapsed() { return !1; } get startRow() { return this._startRow; } get startColumn() { return this._startCol; } get endRow() { return this._endRow; } get endColumn() { return this._endCol; } get tableId() { return this._tableId; } get segmentId() { return this._segmentId; } get segmentPage() { return this._segmentPage; } get spanEntireRow() { var i; const t = (i = this._docSkeleton.getViewModel().getSnapshot().tableSource) == null ? void 0 : i[this._tableId], { _startCol: o, _endCol: r } = this; if (t == null) throw new Error("Table is not found."); const { tableColumns: s } = t; return o === 0 && r === s.length - 1; } get spanEntireColumn() { var i; const t = (i = this._docSkeleton.getViewModel().getSnapshot().tableSource) == null ? void 0 : i[this._tableId], { _startRow: o, _endRow: r } = this; if (t == null) throw new Error("Table is not found."); const { tableRows: s } = t; return o === 0 && r === s.length - 1; } get spanEntireTable() { return this.spanEntireRow && this.spanEntireColumn; } get startNodePosition() { const { anchorNodePosition: e, focusNodePosition: t } = this; return zo(e, t) ? e : t; } get endNodePosition() { const { anchorNodePosition: e, focusNodePosition: t } = this; return zo(e, t) ? t : e; } get direction() { const { anchorNodePosition: e, focusNodePosition: t } = this; return zo(e, t) ? _e.FORWARD : _e.BACKWARD; } isActive() { return this._current === !0; } activate() { this._current = !0; } deactivate() { this._current = !1; } dispose() { var e; (e = this._rangeShape) == null || e.dispose(), this._rangeShape = null; } isIntersection(e) { const { startRow: t, startColumn: o, endRow: r, endColumn: s } = this, { startRow: i, startColumn: a, endRow: c, endColumn: d } = e, l = { left: o, top: t, right: s, bottom: r }, A = { left: a, top: i, right: d, bottom: c }; return Dc.hasIntersectionBetweenTwoRect(l, A); } refresh() { var p; (p = this._rangeShape) == null || p.hide(); const { startNodePosition: e, endNodePosition: t, _document: o, _docSkeleton: r } = this, s = o.getOffsetConfig(), { docsLeft: i, docsTop: a } = s, d = new Ca(s, r).getRangePointData(e, t); if (d == null) return; const { pointGroup: l = [], startRow: A, endRow: h, startColumn: u, endColumn: g, tableId: f } = d; (l == null ? void 0 : l.length) > 0 && this._createOrUpdateRange(l, i, a), this._updateTableInfo(A, h, u, g, f); } _updateTableInfo(e, t, o, r, s) { this._startRow = e, this._endRow = t, this._startCol = o, this._endCol = r, this._tableId = s; } _createOrUpdateRange(e, t, o) { var i; if (this._rangeShape) { this._rangeShape.translate(t, o), this._rangeShape.updatePointGroup(e), this._rangeShape.show(); return; } const r = 0.3, s = new na(Rd + te.generateRandomId(bd), { pointsGroup: e, fill: ((i = this.style) == null ? void 0 : i.fill) || pn(fn.black, r), left: t, top: o, evented: !1, debounceParentDirty: !1 }); this._rangeShape = s, this._scene.addObject(s, ur); } } function ti(n, e, t, o, r, s, i, a, c = !0, d = !0) { const l = r.findNodePositionByCharIndex(n, c, i, a), A = r.findNodePositionByCharIndex(e, d, i, a); if (!(l == null || A == null)) return new Zt(t, o, r, l, A, s, i, a); } function yd(n, e, t, o, r, s, i, a) { const c = r.findNodePositionByCharIndex(n, !0, i, a), d = r.findNodePositionByCharIndex(e, !0, i, a); if (!(c == null || d == null)) return new Ra(t, o, r, c, d, s, i, a); } function xd(n, e, t, o,