@univerjs/docs-ui 0.1.16 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/lib/cjs/index.js +4 -3
  2. package/lib/es/index.js +2280 -1740
  3. package/lib/index.css +1 -1
  4. package/lib/locale/en-US.json +13 -1
  5. package/lib/locale/ru-RU.json +13 -1
  6. package/lib/locale/zh-CN.json +13 -1
  7. package/lib/types/commands/commands/doc-header-footer.command.d.ts +24 -0
  8. package/lib/types/commands/operations/doc-header-footer-panel.operation.d.ts +6 -0
  9. package/lib/types/controllers/doc-editor-bridge.controller.d.ts +1 -3
  10. package/lib/types/controllers/doc-header-footer.controller.d.ts +35 -0
  11. package/lib/types/controllers/menu/menu.d.ts +1 -0
  12. package/lib/types/controllers/render-controllers/back-scroll.render-controller.d.ts +18 -0
  13. package/lib/types/controllers/render-controllers/doc-floating-object.render-controller.d.ts +17 -0
  14. package/lib/types/controllers/render-controllers/doc.render-controller.d.ts +21 -0
  15. package/lib/types/controllers/render-controllers/text-selection.render-controller.d.ts +24 -0
  16. package/lib/types/controllers/render-controllers/zoom.render-controller.d.ts +20 -0
  17. package/lib/types/docs-ui-plugin.d.ts +8 -4
  18. package/lib/types/index.d.ts +6 -1
  19. package/lib/types/locale/zh-CN.d.ts +12 -0
  20. package/lib/types/services/clipboard/clipboard.service.d.ts +2 -1
  21. package/lib/types/services/doc-mark-selection.service.d.ts +27 -0
  22. package/lib/types/services/doc-popup-manager.service.d.ts +3 -1
  23. package/lib/types/services/docs-render.service.d.ts +12 -0
  24. package/lib/types/views/header-footer/panel/DocHeaderFooterOptions.d.ts +6 -0
  25. package/lib/types/views/header-footer/panel/DocHeaderFooterPanel.d.ts +3 -0
  26. package/lib/types/views/header-footer/panel/component-name.d.ts +16 -0
  27. package/lib/types/views/header-footer/text-bubble.d.ts +20 -0
  28. package/lib/umd/index.js +4 -3
  29. package/package.json +18 -16
  30. package/lib/types/controllers/back-scroll.controller.d.ts +0 -16
  31. package/lib/types/controllers/doc-floating-object.controller.d.ts +0 -19
  32. package/lib/types/controllers/doc-render.controller.d.ts +0 -17
  33. package/lib/types/controllers/drawing.controller.d.ts +0 -19
  34. package/lib/types/controllers/text-selection.controller.d.ts +0 -25
  35. package/lib/types/controllers/zoom.controller.d.ts +0 -23
  36. package/lib/types/views/doc-canvas-view.d.ts +0 -20
package/lib/es/index.js CHANGED
@@ -1,216 +1,767 @@
1
- var jt = Object.defineProperty;
2
- var Wt = (i, e, t) => e in i ? jt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var g = (i, e, t) => Wt(i, typeof e != "symbol" ? e + "" : e, t);
4
- import { FOCUSING_DOC as xe, FOCUSING_UNIVER_EDITOR as Ze, FOCUSING_COMMON_DRAWINGS as bt, FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE as zt, Direction as w, EDITOR_ACTIVATED as Mt, LocaleService as qe, RxDisposable as de, ICommandService as v, BooleanNumber as C, UniverInstanceType as f, BaselineOffset as K, ThemeService as yt, HorizontalAlign as De, IUniverInstanceService as P, Disposable as k, OnLifecycle as U, LifecycleStages as A, Tools as Je, LRUMap as kt, ColorKit as st, toDisposable as B, ILogService as Et, CommandType as Qe, IContextService as Ht, checkForSubstrings as Yt, IConfigService as Gt, PositionedObjectLayoutType as Xt, DEFAULT_DOCUMENT_SUB_COMPONENT_ID as Kt, DisposableCollection as Zt, Plugin as qt, ObjectRelativeFromH as Jt, ObjectRelativeFromV as Qt } from "@univerjs/core";
5
- import { Inject as O, Injector as Pe, Optional as en, createIdentifier as tn } from "@wendellhu/redi";
6
- import { KeyCode as E, MetaKeys as ue, ILayoutService as xt, MenuGroup as I, MenuItemType as T, MenuPosition as b, getMenuHiddenObservable as M, FONT_FAMILY_LIST as at, FONT_SIZE_LIST as nn, FontFamily as rn, FontFamilyItem as on, FontSize as sn, BuiltInUIPart as an, ComponentManager as cn, IEditorService as L, IMenuService as ln, IUIPartsService as dn, PLAIN_TEXT_CLIPBOARD_MIME_TYPE as un, HTML_CLIPBOARD_MIME_TYPE as hn, IClipboardInterfaceService as et, CopyCommand as pn, CutCommand as _n, PasteCommand as gn, SetEditorResizeOperation as fn, ICanvasPopupService as mn, IShortcutService as Sn } from "@univerjs/ui";
7
- import { MoveCursorOperation as Ne, MoveSelectionOperation as Ue, SelectAllOperation as vn, SetInlineFormatBoldCommand as Cn, SetTextSelectionsOperation as x, SetInlineFormatCommand as q, SetInlineFormatItalicCommand as On, SetInlineFormatUnderlineCommand as Rn, SetInlineFormatStrikethroughCommand as Tn, SetInlineFormatSubscriptCommand as In, SetInlineFormatSuperscriptCommand as bn, SetInlineFormatFontFamilyCommand as ct, SetInlineFormatFontSizeCommand as lt, SetInlineFormatTextColorCommand as dt, AlignLeftCommand as Mn, AlignOperationCommand as Ae, AlignCenterCommand as yn, AlignRightCommand as En, AlignJustifyCommand as xn, OrderListCommand as Dn, BulletListCommand as Pn, ResetInlineFormatTextBackgroundColorCommand as Nn, SetInlineFormatTextBackgroundColorCommand as He, TextSelectionManagerService as J, BreakLineCommand as Un, DeleteLeftCommand as An, DeleteRightCommand as Ln, CutContentCommand as Dt, InnerPasteCommand as Pt, VIEWPORT_KEY as Q, CoverContentCommand as $n, RichTextEditingMutation as tt, DocSkeletonManagerService as ee, DOCS_VIEW_KEY as X, DOCS_COMPONENT_MAIN_LAYER_INDEX as We, DOCS_COMPONENT_HEADER_LAYER_INDEX as Bn, DOCS_COMPONENT_DEFAULT_Z_INDEX as ut, DOCS_COMPONENT_BACKGROUND_LAYER_INDEX as wn, SetDocZoomRatioOperation as Le, SetDocZoomRatioCommand as Fn, getDocObject as Nt, getDocObjectById as Vn } from "@univerjs/docs";
8
- import { connectInjector as jn } from "@wendellhu/redi/react-bindings";
9
- import { ITextSelectionRenderManager as he, pixelToPt as Wn, ptToPixel as ht, ScrollBar as Ye, IRenderManagerService as F, PageLayoutType as pt, Viewport as zn, EVENT_TYPE as kn, Layer as _t, Documents as Hn, DocBackground as Yn, Liquid as Gn, CURSOR_TYPE as gt, NodePositionConvertToCursor as Xn, getAnchorBounding as Kn } from "@univerjs/engine-render";
10
- import Zn from "react";
11
- import { Observable as y, takeUntil as le, fromEvent as ft, BehaviorSubject as Ut } from "rxjs";
12
- import { ColorPicker as qn } from "@univerjs/design";
13
- const Jn = {
14
- undo: !0,
15
- redo: !0,
16
- // Undo redo
17
- font: !0,
18
- // 'font'
19
- fontSize: !0,
20
- // 'Font size'
21
- bold: !0,
22
- // 'Bold (Ctrl+B)'
23
- italic: !0,
24
- // 'Italic (Ctrl+I)'
25
- strikethrough: !0,
26
- // 'Strikethrough (Alt+Shift+5)'
27
- underline: !0,
28
- // 'Underline (Alt+Shift+6)'
29
- textColor: !0,
30
- // 'Text color'
31
- fillColor: !0,
32
- // 'Cell color'
33
- horizontalAlignMode: !0,
34
- // 'Horizontal alignment'
35
- verticalAlignMode: !0,
36
- // 'Vertical alignment'
37
- textWrapMode: !0,
38
- // 'Wrap mode'
39
- textRotateMode: !0
40
- // 'Text Rotation Mode'
41
- }, Qn = {
42
- outerLeft: !1,
43
- outerRight: !1,
44
- header: !0,
45
- footer: !0,
46
- innerLeft: !1,
47
- innerRight: !1,
48
- frozenHeaderLT: !1,
49
- frozenHeaderRT: !1,
50
- frozenHeaderLM: !1,
51
- frozenContent: !1,
52
- infoBar: !0,
53
- toolbar: !0
54
- }, ei = {
55
- layout: {
56
- docContainerConfig: Qn,
57
- toolbarConfig: Jn
58
- }
59
- }, ti = "DocUI";
60
- function N(i) {
61
- return i.getContextValue(xe) && i.getContextValue(Ze) && !i.getContextValue(bt);
1
+ var vn = Object.defineProperty;
2
+ var On = (n, e, t) => e in n ? vn(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var E = (n, e, t) => On(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { FOCUSING_DOC as Ne, FOCUSING_UNIVER_EDITOR as ht, FOCUSING_COMMON_DRAWINGS as Kt, FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE as Rn, Tools as ee, LRUMap as Cn, BaselineOffset as ae, BooleanNumber as S, ColorKit as St, skipParseTagNames as En, IUniverInstanceService as L, ILogService as Zt, ICommandService as C, Disposable as K, normalizeBody as Tn, toDisposable as qt, RxDisposable as Oe, Direction as Z, EDITOR_ACTIVATED as Jt, LocaleService as le, CommandType as de, DocumentFlavor as In, JSONX as et, UniverInstanceType as v, ThemeService as Qt, HorizontalAlign as Le, OnLifecycle as Ue, LifecycleStages as we, IContextService as bn, checkForSubstrings as Mn, IConfigService as xn, PositionedObjectLayoutType as yn, DEFAULT_DOCUMENT_SUB_COMPONENT_ID as Pn, DisposableCollection as vt, Plugin as Dn, ObjectRelativeFromH as An, ObjectRelativeFromV as Fn } from "@univerjs/core";
5
+ import { IClipboardInterfaceService as gt, PLAIN_TEXT_CLIPBOARD_MIME_TYPE as Nn, HTML_CLIPBOARD_MIME_TYPE as Ln, IEditorService as Y, KeyCode as H, MetaKeys as Re, ILayoutService as en, ISidebarService as Un, ComponentManager as tn, MenuGroup as P, MenuItemType as x, MenuPosition as D, getMenuHiddenObservable as A, FONT_FAMILY_LIST as Ot, FONT_SIZE_LIST as wn, getHeaderFooterMenuHiddenObservable as Bn, FontFamily as $n, FontFamilyItem as Hn, FontSize as Vn, BuiltInUIPart as jn, IMenuService as Wn, IUIPartsService as kn, CopyCommand as zn, CutCommand as Gn, PasteCommand as Yn, SetEditorResizeOperation as Xn, ICanvasPopupService as Kn, IShortcutService as Zn } from "@univerjs/ui";
6
+ import { createIdentifier as qn, Inject as T, Injector as Be, Optional as Jn } from "@wendellhu/redi";
7
+ import { TextSelectionManagerService as ne, CutContentCommand as nn, InnerPasteCommand as on, getDeleteSelection as Qn, DocSkeletonManagerService as N, VIEWPORT_KEY as te, getDocObject as eo, MoveCursorOperation as $e, MoveSelectionOperation as He, SelectAllOperation as to, neoGetDocObject as Q, RichTextEditingMutation as Ve, SetInlineFormatBoldCommand as no, SetTextSelectionsOperation as V, SetInlineFormatCommand as ue, SetInlineFormatItalicCommand as oo, SetInlineFormatUnderlineCommand as io, SetInlineFormatStrikethroughCommand as ro, SetInlineFormatSubscriptCommand as so, SetInlineFormatSuperscriptCommand as ao, SetInlineFormatFontFamilyCommand as Rt, SetInlineFormatFontSizeCommand as Ct, SetInlineFormatTextColorCommand as Et, AlignLeftCommand as co, AlignOperationCommand as je, AlignCenterCommand as lo, AlignRightCommand as uo, AlignJustifyCommand as ho, OrderListCommand as go, BulletListCommand as po, ResetInlineFormatTextBackgroundColorCommand as _o, SetInlineFormatTextBackgroundColorCommand as tt, BreakLineCommand as fo, DeleteLeftCommand as mo, DeleteRightCommand as So, CoverContentCommand as vo, DOCS_COMPONENT_MAIN_LAYER_INDEX as Ye, DOCS_COMPONENT_HEADER_LAYER_INDEX as Oo, DOCS_VIEW_KEY as ie, DOCS_COMPONENT_DEFAULT_Z_INDEX as Tt, DOCS_COMPONENT_BACKGROUND_LAYER_INDEX as Ro, SetDocZoomRatioOperation as ve, SetDocZoomRatioCommand as Co, DocInterceptorService as Eo } from "@univerjs/docs";
8
+ import { pixelToPt as To, ptToPixel as It, NodePositionConvertToCursor as rn, getAnchorBounding as Io, IRenderManagerService as k, ITextSelectionRenderManager as oe, Shape as bo, DocumentEditArea as F, PageLayoutType as De, Vector2 as sn, Rect as Xe, Path as bt, ScrollBar as nt, Viewport as Mo, Layer as Mt, Documents as xo, DocBackground as yo, Liquid as Po, CURSOR_TYPE as xt, getLineBounding as Do } from "@univerjs/engine-render";
9
+ import { takeUntil as se, Observable as w, combineLatest as Ao, fromEvent as yt, BehaviorSubject as Pt, map as Fo } from "rxjs";
10
+ import { useDependency as G, connectInjector as No } from "@wendellhu/redi/react-bindings";
11
+ import Lo, { useState as an, useEffect as cn } from "react";
12
+ import { Checkbox as Dt, InputNumber as At, Button as Uo, ColorPicker as wo } from "@univerjs/design";
13
+ import Bo from "clsx";
14
+ function z(n) {
15
+ return n.getContextValue(Ne) && n.getContextValue(ht) && !n.getContextValue(Kt);
62
16
  }
63
- function ni(i) {
64
- return i.getContextValue(xe) && i.getContextValue(Ze) && !i.getContextValue(zt) && !i.getContextValue(bt);
17
+ function $o(n) {
18
+ return n.getContextValue(Ne) && n.getContextValue(ht) && !n.getContextValue(Rn) && !n.getContextValue(Kt);
65
19
  }
66
- const ii = {
67
- id: Ne.id,
68
- binding: E.ARROW_UP,
69
- preconditions: N,
70
- staticParameters: {
71
- direction: w.UP
72
- }
73
- }, ri = {
74
- id: Ne.id,
75
- binding: E.ARROW_DOWN,
76
- preconditions: N,
77
- staticParameters: {
78
- direction: w.DOWN
20
+ const Ho = 10, Vo = 6;
21
+ function jo() {
22
+ return ee.generateRandomId(Vo);
23
+ }
24
+ function Wo(n) {
25
+ const e = n.match(/data-copy-id="([^\s]+)"/);
26
+ return e && e[1] ? e[1] : null;
27
+ }
28
+ class ko {
29
+ constructor() {
30
+ E(this, "_cache", new Cn(Ho));
79
31
  }
80
- }, oi = {
81
- id: Ne.id,
82
- binding: E.ARROW_LEFT,
83
- preconditions: N,
84
- staticParameters: {
85
- direction: w.LEFT
32
+ set(e, t) {
33
+ this._cache.set(e, t);
86
34
  }
87
- }, si = {
88
- id: Ne.id,
89
- binding: E.ARROW_RIGHT,
90
- preconditions: N,
91
- staticParameters: {
92
- direction: w.RIGHT
35
+ get(e) {
36
+ return this._cache.get(e);
93
37
  }
94
- }, ai = {
95
- id: Ue.id,
96
- binding: E.ARROW_UP | ue.SHIFT,
97
- preconditions: N,
98
- staticParameters: {
99
- direction: w.UP
38
+ clear() {
39
+ this._cache.clear();
100
40
  }
101
- }, ci = {
102
- id: Ue.id,
103
- binding: E.ARROW_DOWN | ue.SHIFT,
104
- preconditions: N,
105
- staticParameters: {
106
- direction: w.DOWN
41
+ }
42
+ const Ft = new ko();
43
+ function pt(n) {
44
+ const e = n.style, t = {}, o = n.tagName.toLowerCase();
45
+ switch (o) {
46
+ case "b":
47
+ case "em":
48
+ case "strong": {
49
+ t.bl = S.TRUE;
50
+ break;
51
+ }
52
+ case "s": {
53
+ t.st = {
54
+ s: S.TRUE
55
+ };
56
+ break;
57
+ }
58
+ case "u": {
59
+ t.ul = {
60
+ s: S.TRUE
61
+ };
62
+ break;
63
+ }
64
+ case "i": {
65
+ t.it = S.TRUE;
66
+ break;
67
+ }
68
+ case "sub":
69
+ case "sup": {
70
+ t.va = o === "sup" ? ae.SUPERSCRIPT : ae.SUBSCRIPT;
71
+ break;
72
+ }
107
73
  }
108
- }, li = {
109
- id: Ue.id,
110
- binding: E.ARROW_LEFT | ue.SHIFT,
111
- preconditions: N,
112
- staticParameters: {
113
- direction: w.LEFT
74
+ for (let i = 0; i < e.length; i++) {
75
+ const r = e[i], s = e.getPropertyValue(r);
76
+ switch (r) {
77
+ case "font-family": {
78
+ t.ff = s;
79
+ break;
80
+ }
81
+ case "font-size": {
82
+ const a = Number.parseInt(s);
83
+ Number.isNaN(a) || (s.endsWith("pt") ? t.fs = a : s.endsWith("px") && (t.fs = To(a)));
84
+ break;
85
+ }
86
+ case "font-style": {
87
+ s === "italic" && (t.it = S.TRUE);
88
+ break;
89
+ }
90
+ case "font-weight": {
91
+ (Number(s) > 400 || String(s) === "bold") && (t.bl = S.TRUE);
92
+ break;
93
+ }
94
+ case "text-decoration": {
95
+ /underline/.test(s) ? t.ul = {
96
+ s: S.TRUE
97
+ } : /overline/.test(s) ? t.ol = {
98
+ s: S.TRUE
99
+ } : /line-through/.test(s) && (t.st = {
100
+ s: S.TRUE
101
+ });
102
+ break;
103
+ }
104
+ case "color": {
105
+ const a = new St(s);
106
+ a.isValid && (t.cl = {
107
+ rgb: a.toRgbString()
108
+ });
109
+ break;
110
+ }
111
+ case "background-color": {
112
+ const a = new St(s);
113
+ a.isValid && (t.bg = {
114
+ rgb: a.toRgbString()
115
+ });
116
+ break;
117
+ }
118
+ }
114
119
  }
115
- }, di = {
116
- id: Ue.id,
117
- binding: E.ARROW_RIGHT | ue.SHIFT,
118
- preconditions: N,
119
- staticParameters: {
120
- direction: w.RIGHT
120
+ return t;
121
+ }
122
+ function zo(n) {
123
+ const e = new DOMParser(), t = `<x-univer id="univer-root">${n}</x-univer>`;
124
+ return e.parseFromString(t, "text/html").querySelector("#univer-root");
125
+ }
126
+ function Nt(n, e) {
127
+ const t = n.tagName.toLowerCase();
128
+ return typeof e == "string" ? t === e : Array.isArray(e) ? e.some((o) => o === t) : e(n);
129
+ }
130
+ const Fe = class Fe {
131
+ constructor() {
132
+ E(this, "_styleCache", /* @__PURE__ */ new Map());
133
+ E(this, "_styleRules", []);
134
+ E(this, "_afterProcessRules", []);
121
135
  }
122
- }, ui = {
123
- id: vn.id,
124
- binding: E.A | ue.CTRL_COMMAND,
125
- preconditions: (i) => i.getContextValue(Ze) && (i.getContextValue(xe) || i.getContextValue(Mt))
126
- };
127
- var hi = Object.defineProperty, pi = Object.getOwnPropertyDescriptor, _i = (i, e, t, n) => {
128
- for (var r = n > 1 ? void 0 : n ? pi(e, t) : e, o = i.length - 1, s; o >= 0; o--)
129
- (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
130
- return n && r && hi(e, t, r), r;
131
- }, mt = (i, e) => (t, n) => e(t, n, i);
132
- let Ge = class {
133
- constructor(i, e, t) {
134
- g(this, "_docContainer");
135
- // 获取SheetContainer组件
136
- g(this, "getComponent", (i) => {
137
- if (this._docContainer = i, !i.getContentRef().current)
138
- throw new Error("container is not ready");
139
- });
140
- /**
141
- * Change language
142
- * @param {string} lang new language
143
- *
144
- * e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771
145
- *
146
- */
147
- g(this, "changeLocale", (i) => {
148
- this._localeService.setLocale(i);
149
- });
150
- this._config = i, this._localeService = e, this._injector = t;
136
+ static use(e) {
137
+ if (this._pluginList.includes(e))
138
+ throw new Error(`Univer paste plugin ${e.name} already added`);
139
+ this._pluginList.push(e);
151
140
  }
152
- getUIConfig() {
153
- return {
154
- injector: this._injector,
155
- config: this._config,
156
- changeLocale: this.changeLocale,
157
- getComponent: this.getComponent
141
+ convert(e) {
142
+ const t = Fe._pluginList.find((r) => r.checkPasteType(e)), o = zo(e), i = {
143
+ dataStream: "",
144
+ textRuns: []
158
145
  };
146
+ return t && (this._styleRules = [...t.stylesRules], this._afterProcessRules = [...t.afterProcessRules]), this._styleCache.clear(), this._process(null, o == null ? void 0 : o.childNodes, i), this._styleCache.clear(), this._styleRules = [], this._afterProcessRules = [], i;
147
+ }
148
+ _process(e, t, o) {
149
+ var i, r;
150
+ for (const s of t)
151
+ if (s.nodeType === Node.TEXT_NODE) {
152
+ if (((i = s.nodeValue) == null ? void 0 : i.trim()) === "")
153
+ continue;
154
+ const a = (r = s.nodeValue) == null ? void 0 : r.replace(/[\r\n]/g, "");
155
+ let c;
156
+ e && this._styleCache.has(e) && (c = this._styleCache.get(e)), o.dataStream += a, c && Object.getOwnPropertyNames(c).length && o.textRuns.push({
157
+ st: o.dataStream.length - a.length,
158
+ ed: o.dataStream.length,
159
+ ts: c
160
+ });
161
+ } else {
162
+ if (En.includes(s.nodeName.toLowerCase()))
163
+ continue;
164
+ if (s.nodeType === Node.ELEMENT_NODE) {
165
+ const a = e ? this._styleCache.get(e) : {}, c = this._styleRules.find(({ filter: h }) => Nt(s, h)), d = c ? c.getStyle(s) : pt(s);
166
+ this._styleCache.set(s, { ...a, ...d });
167
+ const { childNodes: p } = s;
168
+ this._process(s, p, o);
169
+ const g = this._afterProcessRules.find(
170
+ ({ filter: h }) => Nt(s, h)
171
+ );
172
+ g && g.handler(o, s);
173
+ }
174
+ }
159
175
  }
160
- getContentRef() {
161
- return this._docContainer.getContentRef();
176
+ };
177
+ E(Fe, "_pluginList", []);
178
+ let ce = Fe;
179
+ const Go = {
180
+ name: "univer-doc-paste-plugin-lark",
181
+ checkPasteType(n) {
182
+ return /lark-record-clipboard/i.test(n);
183
+ },
184
+ // TODO: @JOCS, support inline code copy from lark.
185
+ stylesRules: [
186
+ {
187
+ filter: ["s"],
188
+ getStyle(n) {
189
+ const e = pt(n);
190
+ return {
191
+ st: {
192
+ s: S.TRUE
193
+ },
194
+ ...e
195
+ };
196
+ }
197
+ }
198
+ ],
199
+ afterProcessRules: [
200
+ {
201
+ filter(n) {
202
+ return n.tagName === "DIV" && /ace-line/i.test(n.className);
203
+ },
204
+ handler(n) {
205
+ n.paragraphs == null && (n.paragraphs = []), n.paragraphs.push({
206
+ startIndex: n.dataStream.length
207
+ }), n.dataStream += "\r";
208
+ }
209
+ }
210
+ ]
211
+ }, Yo = Go;
212
+ function ln(n) {
213
+ const e = n.style, t = {};
214
+ for (let o = 0; o < e.length; o++) {
215
+ const i = e[o], r = e.getPropertyValue(i);
216
+ switch (i) {
217
+ case "margin-top": {
218
+ const s = Number.parseInt(r);
219
+ t.spaceAbove = /pt/.test(r) ? It(s) : s;
220
+ break;
221
+ }
222
+ case "margin-bottom": {
223
+ const s = Number.parseInt(r);
224
+ t.spaceBelow = /pt/.test(r) ? It(s) : s;
225
+ break;
226
+ }
227
+ case "line-height": {
228
+ const s = Number.parseFloat(r);
229
+ t.lineSpacing = s;
230
+ break;
231
+ }
232
+ }
162
233
  }
163
- UIDidMount(i) {
164
- if (this._docContainer)
165
- return i(this._docContainer);
234
+ return Object.getOwnPropertyNames(t).length ? t : null;
235
+ }
236
+ const Xo = {
237
+ name: "univer-doc-paste-plugin-word",
238
+ checkPasteType(n) {
239
+ return /word|mso/i.test(n);
240
+ },
241
+ stylesRules: [
242
+ {
243
+ filter: ["b"],
244
+ getStyle(n) {
245
+ const e = pt(n);
246
+ return { bl: S.TRUE, ...e };
247
+ }
248
+ }
249
+ ],
250
+ afterProcessRules: [
251
+ {
252
+ filter(n) {
253
+ return n.tagName === "P";
254
+ },
255
+ handler(n, e) {
256
+ n.paragraphs == null && (n.paragraphs = []);
257
+ const t = {
258
+ startIndex: n.dataStream.length
259
+ }, o = ln(e);
260
+ o && (t.paragraphStyle = o), n.paragraphs.push(t), n.dataStream += "\r";
261
+ }
262
+ }
263
+ ]
264
+ }, Ko = Xo, Zo = {
265
+ name: "univer-doc-paste-plugin-univer",
266
+ checkPasteType(n) {
267
+ return /UniverNormal/i.test(n);
268
+ },
269
+ stylesRules: [],
270
+ afterProcessRules: [
271
+ {
272
+ filter(n) {
273
+ return n.tagName === "P" && /UniverNormal/i.test(n.className);
274
+ },
275
+ handler(n, e) {
276
+ n.paragraphs == null && (n.paragraphs = []);
277
+ const t = {
278
+ startIndex: n.dataStream.length
279
+ }, o = ln(e);
280
+ o && (t.paragraphStyle = o), n.paragraphs.push(t), n.dataStream += "\r";
281
+ }
282
+ }
283
+ ]
284
+ }, qo = Zo;
285
+ function Lt(n, e) {
286
+ const { st: t, ed: o, ts: i = {} } = e, { ff: r, fs: s, it: a, bl: c, ul: d, st: p, ol: g, bg: h, cl: l, va: f } = i;
287
+ let u = n.slice(t, o);
288
+ const _ = [];
289
+ return a === S.TRUE && (u = `<i>${u}</i>`), f === ae.SUPERSCRIPT ? u = `<sup>${u}</sup>` : f === ae.SUBSCRIPT && (u = `<sub>${u}</sub>`), (d == null ? void 0 : d.s) === S.TRUE && (u = `<u>${u}</u>`), (p == null ? void 0 : p.s) === S.TRUE && (u = `<s>${u}</s>`), c === S.TRUE && (u = `<strong>${u}</strong>`), r && _.push(`font-family: ${r}`), l && _.push(`color: ${l.rgb}`), s && _.push(`font-size: ${s}pt`), g && _.push("text-decoration: overline"), h && _.push(`background: ${h.rgb}`), _.length ? `<span style="${_.join("; ")};">${u}</span>` : u;
290
+ }
291
+ function Ke(n, e, t) {
292
+ const { dataStream: o, textRuns: i = [] } = n;
293
+ let r = e;
294
+ const s = [];
295
+ for (const a of i) {
296
+ const { st: c, ed: d } = a;
297
+ ee.hasIntersectionBetweenTwoRanges(e, t, c, d) && (c > r ? (s.push(o.slice(r, c)), s.push(Lt(o, {
298
+ ...a,
299
+ ed: Math.min(d, t)
300
+ }))) : s.push(Lt(o, {
301
+ ...a,
302
+ st: r,
303
+ ed: Math.min(d, t)
304
+ }))), r = Math.max(e, Math.min(d, t));
166
305
  }
167
- getDocContainer() {
168
- return this._docContainer;
306
+ return r !== t && s.push(o.slice(r, t)), s.join("");
307
+ }
308
+ function Ut(n, e = !0) {
309
+ var t;
310
+ if (e && ((t = n.paragraphs) != null && t.length)) {
311
+ const { dataStream: o, paragraphs: i = [] } = n;
312
+ let r = "", s = -1;
313
+ for (const a of i) {
314
+ const { startIndex: c, paragraphStyle: d = {} } = a, { spaceAbove: p, spaceBelow: g, lineSpacing: h } = d, l = [];
315
+ p != null && (typeof p == "number" ? l.push(`margin-top: ${p}px`) : l.push(`margin-top: ${p.v}px`)), g != null && (typeof g == "number" ? l.push(`margin-bottom: ${g}px`) : l.push(`margin-bottom: ${g.v}px`)), h != null && l.push(`line-height: ${h}`), c > s + 1 ? r += `<p class="UniverNormal" ${l.length ? `style="${l.join("; ")};"` : ""}>${Ke(n, s + 1, c)}</p>` : r += `<p class="UniverNormal" ${l.length ? `style="${l.join("; ")};"` : ""}></p>`, s = c;
316
+ }
317
+ return s !== o.length && (r += Ke(n, s, o.length)), r;
318
+ } else
319
+ return Ke(n, 0, n.dataStream.length);
320
+ }
321
+ class Jo {
322
+ convert(e) {
323
+ if (e.length === 0)
324
+ throw new Error("The bodyList length at least to be 1");
325
+ if (e.length === 1)
326
+ return Ut(e[0]);
327
+ let t = "";
328
+ for (const o of e)
329
+ t += '<p className="UniverNormal">', t += Ut(o, !1), t += "</p>";
330
+ return t;
169
331
  }
170
- };
171
- Ge = _i([
172
- mt(1, O(qe)),
173
- mt(2, O(Pe))
174
- ], Ge);
175
- var gi = Object.defineProperty, fi = Object.getOwnPropertyDescriptor, mi = (i, e, t, n) => {
176
- for (var r = n > 1 ? void 0 : n ? fi(e, t) : e, o = i.length - 1, s; o >= 0; o--)
177
- (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
178
- return n && r && gi(e, t, r), r;
179
- }, _e = (i, e) => (t, n) => e(t, n, i);
180
- let ae = class extends de {
181
- constructor(e, t, n, r, o) {
332
+ }
333
+ var Qo = Object.defineProperty, ei = Object.getOwnPropertyDescriptor, ti = (n, e, t, o) => {
334
+ for (var i = o > 1 ? void 0 : o ? ei(e, t) : e, r = n.length - 1, s; r >= 0; r--)
335
+ (s = n[r]) && (i = (o ? s(e, t, i) : s(i)) || i);
336
+ return o && i && Qo(e, t, i), i;
337
+ }, he = (n, e) => (t, o) => e(t, o, n);
338
+ ce.use(Ko);
339
+ ce.use(Yo);
340
+ ce.use(qo);
341
+ function ni(n) {
342
+ const e = n.replace(/\n/g, "\r"), t = [];
343
+ for (let o = 0; o < e.length; o++)
344
+ e[o] === "\r" && t.push({ startIndex: o });
345
+ return {
346
+ dataStream: e,
347
+ paragraphs: t
348
+ };
349
+ }
350
+ const Ce = qn("doc.clipboard-service");
351
+ let ot = class extends K {
352
+ constructor(e, t, o, i, r) {
182
353
  super();
183
- g(this, "_docContainerController");
184
- /**
185
- * Change language
186
- * @param {string} locale new language
187
- *
188
- * e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771
189
- *
190
- */
191
- g(this, "changeLocale", (e) => {
192
- this._localeService.setLocale(e);
193
- });
194
- this._localeService = t, this._injector = n, this._textSelectionRenderManager = r, this._layoutService = o, this._docContainerController = this._injector.createInstance(Ge, e), this._registerContainer();
354
+ E(this, "_clipboardHooks", []);
355
+ E(this, "_htmlToUDM", new ce());
356
+ E(this, "_umdToHtml", new Jo());
357
+ this._univerInstanceService = e, this._logService = t, this._commandService = o, this._clipboardInterfaceService = i, this._textSelectionManagerService = r;
195
358
  }
196
- _registerContainer() {
197
- this._layoutService && this.disposeWithMe(
198
- // the content editable div should be regarded as part of the applications container
199
- this._layoutService.registerContainerElement(this._textSelectionRenderManager.__getEditorContainer())
200
- );
359
+ async copy() {
360
+ const e = this._getDocumentBodyInRanges();
361
+ if (e.length === 0)
362
+ return !1;
363
+ try {
364
+ const t = this._textSelectionManagerService.getActiveRange(), o = !!(t != null && t.segmentId);
365
+ this._setClipboardData(e, !o);
366
+ } catch (t) {
367
+ return this._logService.error("[DocClipboardService] copy failed", t), !1;
368
+ }
369
+ return !0;
370
+ }
371
+ async cut() {
372
+ return this._cut();
373
+ }
374
+ async paste(e) {
375
+ const t = await this._generateBodyFromClipboardItems(e);
376
+ return this._paste(t);
377
+ }
378
+ async legacyPaste(e, t) {
379
+ const o = this._generateBodyFromHtmlAndText(e, t);
380
+ return this._paste(o);
381
+ }
382
+ async _cut() {
383
+ var r;
384
+ const {
385
+ segmentId: e,
386
+ endOffset: t,
387
+ style: o
388
+ } = (r = this._textSelectionManagerService.getActiveRange()) != null ? r : {}, i = this._textSelectionManagerService.getSelections();
389
+ if (e == null && this._logService.error("[DocClipboardController] segmentId is not existed"), t == null || i == null)
390
+ return !1;
391
+ this.copy();
392
+ try {
393
+ let s = t;
394
+ for (const c of i) {
395
+ const { startOffset: d, endOffset: p } = c;
396
+ d == null || p == null || p <= t && (s -= p - d);
397
+ }
398
+ const a = [
399
+ {
400
+ startOffset: s,
401
+ endOffset: s,
402
+ style: o
403
+ }
404
+ ];
405
+ return this._commandService.executeCommand(nn.id, { segmentId: e, textRanges: a });
406
+ } catch {
407
+ return this._logService.error("[DocClipboardController] cut content failed"), !1;
408
+ }
409
+ }
410
+ async _paste(e) {
411
+ let t = Tn(e);
412
+ this._clipboardHooks.forEach((c) => {
413
+ c.onBeforePaste && (t = c.onBeforePaste(t));
414
+ });
415
+ const o = this._textSelectionManagerService.getActiveRange(), { segmentId: i, endOffset: r, style: s } = o || {}, a = this._textSelectionManagerService.getSelections();
416
+ if (i == null && this._logService.error("[DocClipboardController] segmentId does not exist!"), r == null || a == null)
417
+ return !1;
418
+ try {
419
+ let c = r;
420
+ for (const p of a) {
421
+ const { startOffset: g, endOffset: h } = p;
422
+ g == null || h == null || h <= r && (c += t.dataStream.length - (h - g));
423
+ }
424
+ const d = [
425
+ {
426
+ startOffset: c,
427
+ endOffset: c,
428
+ style: s
429
+ }
430
+ ];
431
+ return this._commandService.executeCommand(on.id, { body: t, segmentId: i, textRanges: d });
432
+ } catch {
433
+ return this._logService.error("[DocClipboardController]", "clipboard is empty."), !1;
434
+ }
435
+ }
436
+ async _setClipboardData(e, t = !0) {
437
+ const o = jo(), i = e.length > 1 ? e.map((s) => s.dataStream).join(`
438
+ `) : e[0].dataStream;
439
+ let r = this._umdToHtml.convert(e);
440
+ return e.length === 1 && t && (r = r.replace(/(<[a-z]+)/, (s, a) => `${a} data-copy-id="${o}"`), Ft.set(o, e[0])), this._clipboardInterfaceService.write(i, r);
441
+ }
442
+ addClipboardHook(e) {
443
+ return this._clipboardHooks.push(e), qt(() => {
444
+ const t = this._clipboardHooks.indexOf(e);
445
+ t > -1 && this._clipboardHooks.splice(t, 1);
446
+ });
447
+ }
448
+ _getDocumentBodyInRanges() {
449
+ const e = this._textSelectionManagerService.getSelections(), t = this._textSelectionManagerService.getActiveRange(), o = this._univerInstanceService.getCurrentUniverDocInstance(), i = [], r = o == null ? void 0 : o.getBody();
450
+ if (e == null || o == null || r == null || t == null)
451
+ return i;
452
+ const { segmentId: s } = t;
453
+ for (const a of e) {
454
+ const { startOffset: c, endOffset: d, collapsed: p } = a;
455
+ if (p || c == null || d == null)
456
+ continue;
457
+ const g = Qn({ startOffset: c, endOffset: d, collapsed: p }, r), h = o.getSelfOrHeaderFooterModel(s).sliceBody(g.startOffset, g.endOffset);
458
+ if (h != null) {
459
+ if (h.customRanges) {
460
+ const l = [];
461
+ h.customRanges.forEach((_) => {
462
+ _.startIndex === _.endIndex && l.push(_);
463
+ }), h.customRanges = h.customRanges.filter((_) => l.indexOf(_) === -1);
464
+ let f = "", u = 0;
465
+ l.forEach((_) => {
466
+ f += h.dataStream.slice(u, _.endIndex), u = _.endIndex + 1;
467
+ }), f += h.dataStream.slice(u, h.dataStream.length), h.dataStream = f;
468
+ }
469
+ i.push(h);
470
+ }
471
+ }
472
+ return i;
473
+ }
474
+ async _generateBodyFromClipboardItems(e) {
475
+ try {
476
+ let t = "", o = "";
477
+ for (const i of e)
478
+ for (const r of i.types)
479
+ r === Nn ? o = await i.getType(r).then((s) => s && s.text()) : r === Ln && (t = await i.getType(r).then((s) => s && s.text()));
480
+ return this._generateBodyFromHtmlAndText(t, o);
481
+ } catch (t) {
482
+ return Promise.reject(t);
483
+ }
484
+ }
485
+ _generateBodyFromHtmlAndText(e, t) {
486
+ if (!e) {
487
+ if (t)
488
+ return ni(t);
489
+ throw new Error("[DocClipboardService] html and text cannot be both empty!");
490
+ }
491
+ const o = Wo(e);
492
+ if (o) {
493
+ const i = Ft.get(o);
494
+ if (i)
495
+ return i;
496
+ }
497
+ return this._htmlToUDM.convert(e);
498
+ }
499
+ };
500
+ ot = ti([
501
+ he(0, L),
502
+ he(1, Zt),
503
+ he(2, C),
504
+ he(3, gt),
505
+ he(4, T(ne))
506
+ ], ot);
507
+ var oi = Object.defineProperty, ii = Object.getOwnPropertyDescriptor, ri = (n, e, t, o) => {
508
+ for (var i = o > 1 ? void 0 : o ? ii(e, t) : e, r = n.length - 1, s; r >= 0; r--)
509
+ (s = n[r]) && (i = (o ? s(e, t, i) : s(i)) || i);
510
+ return o && i && oi(e, t, i), i;
511
+ }, Ee = (n, e) => (t, o) => e(t, o, n);
512
+ const wt = 1.5;
513
+ let it = class extends Oe {
514
+ constructor(n, e, t, o, i) {
515
+ super(), this._context = n, this._textSelectionManagerService = e, this._editorService = t, this._univerInstanceService = o, this._renderManagerService = i, this._init();
516
+ }
517
+ _init() {
518
+ this._textSelectionManagerService.textSelection$.pipe(se(this.dispose$)).subscribe((n) => {
519
+ if (n == null)
520
+ return;
521
+ const { isEditing: e, unitId: t } = n;
522
+ e && this._scrollToSelection(t);
523
+ });
524
+ }
525
+ scrollToRange(n, e) {
526
+ var s;
527
+ const t = (s = this._renderManagerService.getRenderById(n)) == null ? void 0 : s.with(N), o = t == null ? void 0 : t.getSkeleton();
528
+ if (!o)
529
+ return;
530
+ const { startOffset: i } = e, r = o.findNodePositionByCharIndex(i);
531
+ this.scrollToNode(n, r);
532
+ }
533
+ scrollToNode(n, e) {
534
+ var $;
535
+ const t = this._getDocObject(), o = ($ = this._renderManagerService.getRenderById(n)) == null ? void 0 : $.with(N), i = o == null ? void 0 : o.getSkeleton();
536
+ if (t == null || i == null)
537
+ return;
538
+ const r = t.document.getOffsetConfig(), { docsLeft: s, docsTop: a } = r, c = new rn(r, i), { contentBoxPointGroup: d } = c.getRangePointData(e, e), { left: p, top: g, height: h } = Io(d), l = p + s, f = g + a, u = t.scene.getViewport(te.VIEW_MAIN), _ = !!this._editorService.getEditor(n);
539
+ if (u == null)
540
+ return;
541
+ const {
542
+ left: m,
543
+ top: O,
544
+ right: M,
545
+ bottom: I
546
+ } = u.getBounding().viewBound;
547
+ let R = 0, y = 0;
548
+ const j = _ ? 0 : 100;
549
+ f < O ? R = f - O - j : f > I - h && (R = f - I + h + j), l < m ? y = l - m : l > M - wt && (y = l - M + wt);
550
+ const W = u.transViewportScroll2ScrollValue(y, R);
551
+ u.scrollBy(W);
552
+ }
553
+ // Let the selection show on the current screen.
554
+ _scrollToSelection(n) {
555
+ const e = this._textSelectionManagerService.getActiveRange();
556
+ if (e == null)
557
+ return;
558
+ const { collapsed: t, startNodePosition: o } = e;
559
+ t && this.scrollToNode(n, o);
560
+ }
561
+ _getDocObject() {
562
+ return eo(this._univerInstanceService, this._renderManagerService);
563
+ }
564
+ };
565
+ it = ri([
566
+ Ee(1, T(ne)),
567
+ Ee(2, Y),
568
+ Ee(3, T(L)),
569
+ Ee(4, k)
570
+ ], it);
571
+ const si = {
572
+ undo: !0,
573
+ redo: !0,
574
+ // Undo redo
575
+ font: !0,
576
+ // 'font'
577
+ fontSize: !0,
578
+ // 'Font size'
579
+ bold: !0,
580
+ // 'Bold (Ctrl+B)'
581
+ italic: !0,
582
+ // 'Italic (Ctrl+I)'
583
+ strikethrough: !0,
584
+ // 'Strikethrough (Alt+Shift+5)'
585
+ underline: !0,
586
+ // 'Underline (Alt+Shift+6)'
587
+ textColor: !0,
588
+ // 'Text color'
589
+ fillColor: !0,
590
+ // 'Cell color'
591
+ horizontalAlignMode: !0,
592
+ // 'Horizontal alignment'
593
+ verticalAlignMode: !0,
594
+ // 'Vertical alignment'
595
+ textWrapMode: !0,
596
+ // 'Wrap mode'
597
+ textRotateMode: !0
598
+ // 'Text Rotation Mode'
599
+ }, ai = {
600
+ outerLeft: !1,
601
+ outerRight: !1,
602
+ header: !0,
603
+ footer: !0,
604
+ innerLeft: !1,
605
+ innerRight: !1,
606
+ frozenHeaderLT: !1,
607
+ frozenHeaderRT: !1,
608
+ frozenHeaderLM: !1,
609
+ frozenContent: !1,
610
+ infoBar: !0,
611
+ toolbar: !0
612
+ }, ci = {
613
+ layout: {
614
+ docContainerConfig: ai,
615
+ toolbarConfig: si
616
+ }
617
+ }, li = "DocUI", di = {
618
+ id: $e.id,
619
+ binding: H.ARROW_UP,
620
+ preconditions: z,
621
+ staticParameters: {
622
+ direction: Z.UP
623
+ }
624
+ }, ui = {
625
+ id: $e.id,
626
+ binding: H.ARROW_DOWN,
627
+ preconditions: z,
628
+ staticParameters: {
629
+ direction: Z.DOWN
630
+ }
631
+ }, hi = {
632
+ id: $e.id,
633
+ binding: H.ARROW_LEFT,
634
+ preconditions: z,
635
+ staticParameters: {
636
+ direction: Z.LEFT
637
+ }
638
+ }, gi = {
639
+ id: $e.id,
640
+ binding: H.ARROW_RIGHT,
641
+ preconditions: z,
642
+ staticParameters: {
643
+ direction: Z.RIGHT
644
+ }
645
+ }, pi = {
646
+ id: He.id,
647
+ binding: H.ARROW_UP | Re.SHIFT,
648
+ preconditions: z,
649
+ staticParameters: {
650
+ direction: Z.UP
651
+ }
652
+ }, _i = {
653
+ id: He.id,
654
+ binding: H.ARROW_DOWN | Re.SHIFT,
655
+ preconditions: z,
656
+ staticParameters: {
657
+ direction: Z.DOWN
658
+ }
659
+ }, fi = {
660
+ id: He.id,
661
+ binding: H.ARROW_LEFT | Re.SHIFT,
662
+ preconditions: z,
663
+ staticParameters: {
664
+ direction: Z.LEFT
665
+ }
666
+ }, mi = {
667
+ id: He.id,
668
+ binding: H.ARROW_RIGHT | Re.SHIFT,
669
+ preconditions: z,
670
+ staticParameters: {
671
+ direction: Z.RIGHT
672
+ }
673
+ }, Si = {
674
+ id: to.id,
675
+ binding: H.A | Re.CTRL_COMMAND,
676
+ preconditions: (n) => n.getContextValue(ht) && (n.getContextValue(Ne) || n.getContextValue(Jt))
677
+ };
678
+ var vi = Object.defineProperty, Oi = Object.getOwnPropertyDescriptor, Ri = (n, e, t, o) => {
679
+ for (var i = o > 1 ? void 0 : o ? Oi(e, t) : e, r = n.length - 1, s; r >= 0; r--)
680
+ (s = n[r]) && (i = (o ? s(e, t, i) : s(i)) || i);
681
+ return o && i && vi(e, t, i), i;
682
+ }, Bt = (n, e) => (t, o) => e(t, o, n);
683
+ let rt = class {
684
+ constructor(n, e, t) {
685
+ E(this, "_docContainer");
686
+ // 获取SheetContainer组件
687
+ E(this, "getComponent", (n) => {
688
+ if (this._docContainer = n, !n.getContentRef().current)
689
+ throw new Error("container is not ready");
690
+ });
691
+ /**
692
+ * Change language
693
+ * @param {string} lang new language
694
+ *
695
+ * e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771
696
+ *
697
+ */
698
+ E(this, "changeLocale", (n) => {
699
+ this._localeService.setLocale(n);
700
+ });
701
+ this._config = n, this._localeService = e, this._injector = t;
702
+ }
703
+ getUIConfig() {
704
+ return {
705
+ injector: this._injector,
706
+ config: this._config,
707
+ changeLocale: this.changeLocale,
708
+ getComponent: this.getComponent
709
+ };
710
+ }
711
+ getContentRef() {
712
+ return this._docContainer.getContentRef();
713
+ }
714
+ UIDidMount(n) {
715
+ if (this._docContainer)
716
+ return n(this._docContainer);
717
+ }
718
+ getDocContainer() {
719
+ return this._docContainer;
720
+ }
721
+ };
722
+ rt = Ri([
723
+ Bt(1, T(le)),
724
+ Bt(2, T(Be))
725
+ ], rt);
726
+ var Ci = Object.defineProperty, Ei = Object.getOwnPropertyDescriptor, Ti = (n, e, t, o) => {
727
+ for (var i = o > 1 ? void 0 : o ? Ei(e, t) : e, r = n.length - 1, s; r >= 0; r--)
728
+ (s = n[r]) && (i = (o ? s(e, t, i) : s(i)) || i);
729
+ return o && i && Ci(e, t, i), i;
730
+ }, Te = (n, e) => (t, o) => e(t, o, n);
731
+ let me = class extends Oe {
732
+ constructor(e, t, o, i, r) {
733
+ super();
734
+ E(this, "_docContainerController");
735
+ /**
736
+ * Change language
737
+ * @param {string} locale new language
738
+ *
739
+ * e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771
740
+ *
741
+ */
742
+ E(this, "changeLocale", (e) => {
743
+ this._localeService.setLocale(e);
744
+ });
745
+ this._localeService = t, this._injector = o, this._textSelectionRenderManager = i, this._layoutService = r, this._docContainerController = this._injector.createInstance(rt, e), this._registerContainer();
746
+ }
747
+ _registerContainer() {
748
+ this._layoutService && this.disposeWithMe(
749
+ // the content editable div should be regarded as part of the applications container
750
+ this._layoutService.registerContainerElement(this._textSelectionRenderManager.__getEditorContainer())
751
+ );
201
752
  }
202
753
  getDocContainerController() {
203
754
  return this._docContainerController;
204
755
  }
205
756
  };
206
- ae = mi([
207
- _e(1, O(qe)),
208
- _e(2, O(Pe)),
209
- _e(3, he),
210
- _e(4, en(xt))
211
- ], ae);
212
- const $e = "UI_PLUGIN_DOCS", nt = `${$e}_COLOR_PICKER_COMPONENT`, At = `${$e}_FONT_FAMILY_COMPONENT`, Lt = `${$e}_FONT_FAMILY_ITEM_COMPONENT`, $t = `${$e}_FONT_SIZE_COMPONENT`;
213
- var Bt = { exports: {} }, Be = {};
757
+ me = Ti([
758
+ Te(1, T(le)),
759
+ Te(2, T(Be)),
760
+ Te(3, oe),
761
+ Te(4, Jn(en))
762
+ ], me);
763
+ const We = "UI_PLUGIN_DOCS", _t = `${We}_COLOR_PICKER_COMPONENT`, dn = `${We}_FONT_FAMILY_COMPONENT`, un = `${We}_FONT_FAMILY_ITEM_COMPONENT`, hn = `${We}_FONT_SIZE_COMPONENT`;
764
+ var gn = { exports: {} }, ke = {};
214
765
  /**
215
766
  * @license React
216
767
  * react-jsx-runtime.production.min.js
@@ -220,1101 +771,1177 @@ var Bt = { exports: {} }, Be = {};
220
771
  * This source code is licensed under the MIT license found in the
221
772
  * LICENSE file in the root directory of this source tree.
222
773
  */
223
- var Si = Zn, vi = Symbol.for("react.element"), Ci = Symbol.for("react.fragment"), Oi = Object.prototype.hasOwnProperty, Ri = Si.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, Ti = { key: !0, ref: !0, __self: !0, __source: !0 };
224
- function wt(i, e, t) {
225
- var n, r = {}, o = null, s = null;
226
- t !== void 0 && (o = "" + t), e.key !== void 0 && (o = "" + e.key), e.ref !== void 0 && (s = e.ref);
227
- for (n in e) Oi.call(e, n) && !Ti.hasOwnProperty(n) && (r[n] = e[n]);
228
- if (i && i.defaultProps) for (n in e = i.defaultProps, e) r[n] === void 0 && (r[n] = e[n]);
229
- return { $$typeof: vi, type: i, key: o, ref: s, props: r, _owner: Ri.current };
774
+ var Ii = Lo, bi = Symbol.for("react.element"), Mi = Symbol.for("react.fragment"), xi = Object.prototype.hasOwnProperty, yi = Ii.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, Pi = { key: !0, ref: !0, __self: !0, __source: !0 };
775
+ function pn(n, e, t) {
776
+ var o, i = {}, r = null, s = null;
777
+ t !== void 0 && (r = "" + t), e.key !== void 0 && (r = "" + e.key), e.ref !== void 0 && (s = e.ref);
778
+ for (o in e) xi.call(e, o) && !Pi.hasOwnProperty(o) && (i[o] = e[o]);
779
+ if (n && n.defaultProps) for (o in e = n.defaultProps, e) i[o] === void 0 && (i[o] = e[o]);
780
+ return { $$typeof: bi, type: n, key: r, ref: s, props: i, _owner: yi.current };
230
781
  }
231
- Be.Fragment = Ci;
232
- Be.jsx = wt;
233
- Be.jsxs = wt;
234
- Bt.exports = Be;
235
- var Ii = Bt.exports;
236
- const bi = "univer-docs-ui-canvas-background", Mi = {
237
- docsUiCanvasBackground: bi
238
- }, yi = () => /* @__PURE__ */ Ii.jsx("div", { className: Mi.docsUiCanvasBackground });
239
- function Ei(i) {
240
- const e = i.get(v);
241
- return {
242
- id: Cn.id,
243
- group: I.TOOLBAR_FORMAT,
244
- type: T.BUTTON,
245
- icon: "BoldSingle",
246
- title: "Set bold",
247
- tooltip: "toolbar.bold",
248
- positions: [b.TOOLBAR_START],
249
- activated$: new y((t) => {
250
- const n = e.onCommandExecuted((r) => {
251
- var s;
252
- const o = r.id;
253
- if (o === x.id || o === q.id) {
254
- const a = V(i);
255
- if (a == null)
256
- return;
257
- const c = (s = a.ts) == null ? void 0 : s.bl;
258
- t.next(c === C.TRUE);
259
- }
260
- });
261
- return t.next(!1), n.dispose;
262
- }),
263
- hidden$: M(i, f.UNIVER_DOC)
264
- };
782
+ ke.Fragment = Mi;
783
+ ke.jsx = pn;
784
+ ke.jsxs = pn;
785
+ gn.exports = ke;
786
+ var b = gn.exports;
787
+ const Di = "univer-docs-ui-canvas-background", Ai = {
788
+ docsUiCanvasBackground: Di
789
+ }, Fi = () => /* @__PURE__ */ b.jsx("div", { className: Ai.docsUiCanvasBackground }), $t = 18, Ht = 200, Ze = 6, Ni = 4;
790
+ function Li(n, e) {
791
+ let { radius: t, width: o, height: i } = e;
792
+ t = t != null ? t : 0, o = o != null ? o : 30, i = i != null ? i : 30;
793
+ let r = 0;
794
+ r = Math.min(t, o / 2, i / 2), n.beginPath(), n.moveTo(0, 0), n.lineTo(o, 0), n.lineTo(o, i - r), n.arc(o - r, i - r, r, 0, Math.PI / 2, !1), n.lineTo(0, i), n.lineTo(0, 0), n.closePath(), e.fill && (n.save(), n.fillStyle = e.fill, e.fillRule === "evenodd" ? n.fill("evenodd") : n.fill(), n.restore());
265
795
  }
266
- function xi(i) {
267
- const e = i.get(v);
268
- return {
269
- id: On.id,
270
- group: I.TOOLBAR_FORMAT,
271
- type: T.BUTTON,
272
- icon: "ItalicSingle",
273
- title: "Set italic",
274
- tooltip: "toolbar.italic",
275
- positions: [b.TOOLBAR_START],
276
- activated$: new y((t) => {
277
- const n = e.onCommandExecuted((r) => {
278
- var s;
279
- const o = r.id;
280
- if (o === x.id || o === q.id) {
281
- const a = V(i);
282
- if (a == null)
283
- return;
284
- const c = (s = a.ts) == null ? void 0 : s.it;
285
- t.next(c === C.TRUE);
796
+ class Ae extends bo {
797
+ constructor(t, o) {
798
+ super(t, o);
799
+ E(this, "color");
800
+ E(this, "text");
801
+ this.color = o == null ? void 0 : o.color, this.text = o == null ? void 0 : o.text;
802
+ }
803
+ static drawWith(t, o) {
804
+ const { text: i, color: r } = o;
805
+ t.save(), t.font = "13px Source Han Sans CN";
806
+ const s = t.measureText(i).width, a = Math.min(
807
+ s + 2 * Ze,
808
+ Ht
809
+ );
810
+ Li(t, {
811
+ height: $t,
812
+ width: a,
813
+ radius: 4,
814
+ fill: r,
815
+ evented: !1
816
+ }), t.fillStyle = "rgba(58, 96, 247, 1)";
817
+ const c = Ze, d = $t - Ni, p = Ht - 2 * Ze;
818
+ if (s > p) {
819
+ let g = "", h = 0;
820
+ for (const l of i) {
821
+ const f = t.measureText(l).width;
822
+ if (h + f <= p - t.measureText("...").width)
823
+ g += l, h += f;
824
+ else {
825
+ g += "...";
826
+ break;
286
827
  }
287
- });
288
- return t.next(!1), n.dispose;
289
- }),
290
- hidden$: M(i, f.UNIVER_DOC)
291
- };
828
+ }
829
+ t.fillText(g, c, d);
830
+ } else
831
+ t.fillText(i, c, d);
832
+ t.restore();
833
+ }
834
+ _draw(t) {
835
+ Ae.drawWith(t, this);
836
+ }
292
837
  }
293
- function Di(i) {
294
- const e = i.get(v);
295
- return {
296
- id: Rn.id,
297
- group: I.TOOLBAR_FORMAT,
298
- type: T.BUTTON,
299
- icon: "UnderlineSingle",
300
- title: "Set underline",
301
- tooltip: "toolbar.underline",
302
- positions: [b.TOOLBAR_START],
303
- activated$: new y((t) => {
304
- const n = e.onCommandExecuted((r) => {
305
- var s;
306
- const o = r.id;
307
- if (o === x.id || o === q.id) {
308
- const a = V(i);
309
- if (a == null)
310
- return;
311
- const c = (s = a.ts) == null ? void 0 : s.ul;
312
- t.next((c == null ? void 0 : c.s) === C.TRUE);
838
+ const _n = "COMPONENT_DOC_HEADER_FOOTER_PANEL", Ui = "univer-panel", wi = "univer-options-section", Bi = "univer-options-form-item", $i = "univer-options-input", Hi = "univer-options-margin-setting", B = {
839
+ panel: Ui,
840
+ optionsSection: wi,
841
+ optionsFormItem: Bi,
842
+ optionsInput: $i,
843
+ optionsMarginSetting: Hi
844
+ }, Vi = (n) => {
845
+ const e = G(le), t = G(L), o = G(k), i = G(C), r = G(oe), s = G(ne), { unitId: a } = n, [c, d] = an({}), p = (l, f) => {
846
+ var j;
847
+ d((W) => ({
848
+ ...W,
849
+ [f]: l ? S.TRUE : S.FALSE
850
+ }));
851
+ const u = t.getUniverDocInstance(a), _ = u == null ? void 0 : u.getSnapshot().documentStyle, m = (j = o.getRenderById(a)) == null ? void 0 : j.with(N), O = m == null ? void 0 : m.getViewModel();
852
+ if (_ == null || O == null)
853
+ return;
854
+ const M = O.getEditArea();
855
+ let I = !1;
856
+ const R = r.getSegmentPage();
857
+ let y = !1;
858
+ if (f === "useFirstPageHeaderFooter" && l === !0 && ((M === F.HEADER && !_.firstPageHeaderId || M === F.FOOTER && !_.firstPageFooterId) && (I = !0), I && R === 0 && (y = !0)), f === "evenAndOddHeaders" && l === !0 && ((M === F.HEADER && !_.evenPageHeaderId || M === F.FOOTER && !_.evenPageFooterId) && (I = !0), I && R % 2 === 1 && (y = !0)), I) {
859
+ const $ = ee.generateRandomId(6);
860
+ y && r.setSegment($), i.executeCommand(Me, {
861
+ unitId: a,
862
+ segmentId: $,
863
+ headerFooterProps: {
864
+ [f]: l ? S.TRUE : S.FALSE
313
865
  }
314
866
  });
315
- return t.next(!1), n.dispose;
316
- }),
317
- hidden$: M(i, f.UNIVER_DOC)
318
- };
319
- }
320
- function Pi(i) {
321
- const e = i.get(v);
322
- return {
323
- id: Tn.id,
324
- group: I.TOOLBAR_FORMAT,
325
- type: T.BUTTON,
326
- icon: "StrikethroughSingle",
327
- title: "Set strike through",
328
- tooltip: "toolbar.strikethrough",
329
- positions: [b.TOOLBAR_START],
330
- activated$: new y((t) => {
331
- const n = e.onCommandExecuted((r) => {
332
- var s;
333
- const o = r.id;
334
- if (o === x.id || o === q.id) {
335
- const a = V(i);
336
- if (a == null)
337
- return;
338
- const c = (s = a.ts) == null ? void 0 : s.st;
339
- t.next((c == null ? void 0 : c.s) === C.TRUE);
867
+ } else
868
+ i.executeCommand(Me, {
869
+ unitId: a,
870
+ headerFooterProps: {
871
+ [f]: l ? S.TRUE : S.FALSE
340
872
  }
341
873
  });
342
- return t.next(!1), n.dispose;
343
- }),
344
- hidden$: M(i, f.UNIVER_DOC)
874
+ }, g = async (l, f) => {
875
+ d((u) => ({
876
+ ...u,
877
+ [f]: l
878
+ })), await i.executeCommand(Me, {
879
+ unitId: a,
880
+ headerFooterProps: {
881
+ [f]: l
882
+ }
883
+ }), r.removeAllTextRanges(), r.blur();
884
+ }, h = () => {
885
+ var m, O;
886
+ const l = (m = o.getRenderById(a)) == null ? void 0 : m.with(N), f = l == null ? void 0 : l.getSkeleton(), u = l == null ? void 0 : l.getViewModel(), _ = o.getRenderById(a);
887
+ _ == null || u == null || f == null || (s.replaceTextRanges([]), r.setSegment(""), r.setSegmentPage(-1), u.setEditArea(F.BODY), f.calculate(), (O = _.mainComponent) == null || O.makeDirty(!0));
888
+ };
889
+ return cn(() => {
890
+ const l = t.getUniverDocInstance(a), f = l == null ? void 0 : l.getSnapshot().documentStyle;
891
+ if (f) {
892
+ const { marginHeader: u, marginFooter: _, useFirstPageHeaderFooter: m, evenAndOddHeaders: O } = f;
893
+ d({
894
+ marginHeader: u,
895
+ marginFooter: _,
896
+ useFirstPageHeaderFooter: m,
897
+ evenAndOddHeaders: O
898
+ });
899
+ }
900
+ }, [a]), /* @__PURE__ */ b.jsxs("div", { className: B.options, children: [
901
+ /* @__PURE__ */ b.jsxs("div", { className: B.optionsSection, children: [
902
+ /* @__PURE__ */ b.jsx("div", { className: B.optionsFormItem, children: /* @__PURE__ */ b.jsx(
903
+ Dt,
904
+ {
905
+ checked: c.useFirstPageHeaderFooter === S.TRUE,
906
+ onChange: (l) => {
907
+ p(l, "useFirstPageHeaderFooter");
908
+ },
909
+ children: e.t("headerFooter.firstPageCheckBox")
910
+ }
911
+ ) }),
912
+ /* @__PURE__ */ b.jsx("div", { className: B.optionsFormItem, children: /* @__PURE__ */ b.jsx(
913
+ Dt,
914
+ {
915
+ checked: c.evenAndOddHeaders === S.TRUE,
916
+ onChange: (l) => {
917
+ p(l, "evenAndOddHeaders");
918
+ },
919
+ children: e.t("headerFooter.oddEvenCheckBox")
920
+ }
921
+ ) })
922
+ ] }),
923
+ /* @__PURE__ */ b.jsxs("div", { className: Bo(B.optionsSection, B.optionsMarginSetting), children: [
924
+ /* @__PURE__ */ b.jsxs("div", { className: B.optionsMarginItem, children: [
925
+ /* @__PURE__ */ b.jsx("span", { children: e.t("headerFooter.headerTopMargin") }),
926
+ /* @__PURE__ */ b.jsx(
927
+ At,
928
+ {
929
+ min: 0,
930
+ max: 200,
931
+ precision: 1,
932
+ value: c.marginHeader,
933
+ onChange: (l) => {
934
+ g(l, "marginHeader");
935
+ },
936
+ className: B.optionsInput
937
+ }
938
+ )
939
+ ] }),
940
+ /* @__PURE__ */ b.jsxs("div", { className: B.optionsMarginItem, children: [
941
+ /* @__PURE__ */ b.jsx("span", { children: e.t("headerFooter.footerBottomMargin") }),
942
+ /* @__PURE__ */ b.jsx(
943
+ At,
944
+ {
945
+ min: 0,
946
+ max: 200,
947
+ precision: 1,
948
+ value: c.marginFooter,
949
+ onChange: (l) => {
950
+ g(l, "marginFooter");
951
+ },
952
+ className: B.optionsInput
953
+ }
954
+ )
955
+ ] })
956
+ ] }),
957
+ /* @__PURE__ */ b.jsx("div", { className: B.optionsSection, children: /* @__PURE__ */ b.jsx(Uo, { onClick: h, children: e.t("headerFooter.closeHeaderFooter") }) })
958
+ ] });
959
+ }, ji = () => {
960
+ var d;
961
+ const n = G(le), e = G(k), i = G(L).getCurrentUniverDocInstance().getUnitId(), s = ((d = e.getRenderById(i)) == null ? void 0 : d.with(N)).getViewModel(), [a, c] = an(!0);
962
+ return cn(() => {
963
+ const p = s.getEditArea();
964
+ c(p !== F.BODY);
965
+ const g = s.editAreaChange$.subscribe((h) => {
966
+ h != null && c(h !== F.BODY);
967
+ });
968
+ return () => {
969
+ g.unsubscribe();
970
+ };
971
+ }, []), /* @__PURE__ */ b.jsx("div", { className: B.panel, children: a ? /* @__PURE__ */ b.jsx(Vi, { unitId: i }) : /* @__PURE__ */ b.jsx("div", { className: B.panelDisableText, children: n.t("headerFooter.disableText") }) });
972
+ }, fn = {
973
+ id: "sidebar.operation.doc-header-footer-panel",
974
+ type: de.COMMAND,
975
+ handler: async (n, e) => {
976
+ const t = n.get(Un), o = n.get(le);
977
+ switch (e.value) {
978
+ case "open":
979
+ t.open({
980
+ header: { title: o.t("headerFooter.panel") },
981
+ children: { label: _n },
982
+ onClose: () => {
983
+ },
984
+ width: 400
985
+ });
986
+ break;
987
+ case "close":
988
+ default:
989
+ t.close();
990
+ break;
991
+ }
992
+ return !0;
993
+ }
994
+ };
995
+ var Wi = Object.defineProperty, ki = Object.getOwnPropertyDescriptor, zi = (n, e, t, o) => {
996
+ for (var i = o > 1 ? void 0 : o ? ki(e, t) : e, r = n.length - 1, s; r >= 0; r--)
997
+ (s = n[r]) && (i = (o ? s(e, t, i) : s(i)) || i);
998
+ return o && i && Wi(e, t, i), i;
999
+ }, X = (n, e) => (t, o) => e(t, o, n);
1000
+ const Vt = "rgba(58, 96, 247, 1)", jt = "rgba(58, 96, 247, 0.08)";
1001
+ var U = /* @__PURE__ */ ((n) => (n[n.FIRST_PAGE_HEADER = 0] = "FIRST_PAGE_HEADER", n[n.FIRST_PAGE_FOOTER = 1] = "FIRST_PAGE_FOOTER", n[n.DEFAULT_HEADER = 2] = "DEFAULT_HEADER", n[n.DEFAULT_FOOTER = 3] = "DEFAULT_FOOTER", n[n.EVEN_PAGE_HEADER = 4] = "EVEN_PAGE_HEADER", n[n.EVEN_PAGE_FOOTER = 5] = "EVEN_PAGE_FOOTER", n))(U || {});
1002
+ function Gi(n, e, t) {
1003
+ const { documentStyle: o } = n.getDataModel().getSnapshot(), {
1004
+ defaultHeaderId: i,
1005
+ defaultFooterId: r,
1006
+ evenPageHeaderId: s,
1007
+ evenPageFooterId: a,
1008
+ firstPageHeaderId: c,
1009
+ firstPageFooterId: d,
1010
+ evenAndOddHeaders: p,
1011
+ useFirstPageHeaderFooter: g
1012
+ } = o;
1013
+ switch (e) {
1014
+ case F.BODY:
1015
+ return {
1016
+ createType: null,
1017
+ headerFooterId: null
1018
+ };
1019
+ case F.HEADER:
1020
+ return g === S.TRUE && !c ? {
1021
+ createType: 0,
1022
+ headerFooterId: null
1023
+ } : p === S.TRUE && t % 2 === 0 && !s ? {
1024
+ createType: 4,
1025
+ headerFooterId: null
1026
+ } : i ? {
1027
+ createType: null,
1028
+ headerFooterId: i
1029
+ } : {
1030
+ createType: 2,
1031
+ headerFooterId: null
1032
+ };
1033
+ case F.FOOTER:
1034
+ return g === S.TRUE && !d ? {
1035
+ createType: 1,
1036
+ headerFooterId: null
1037
+ } : p === S.TRUE && t % 2 === 0 && !a ? {
1038
+ createType: 5,
1039
+ headerFooterId: null
1040
+ } : r ? {
1041
+ createType: null,
1042
+ headerFooterId: r
1043
+ } : {
1044
+ createType: 3,
1045
+ headerFooterId: null
1046
+ };
1047
+ default:
1048
+ throw new Error(`Invalid editArea: ${e}`);
1049
+ }
1050
+ }
1051
+ let st = class extends K {
1052
+ constructor(e, t, o, i, r, s, a, c, d) {
1053
+ super();
1054
+ E(this, "_loadedMap", /* @__PURE__ */ new WeakSet());
1055
+ this._context = e, this._commandService = t, this._editorService = o, this._instanceSrv = i, this._renderManagerService = r, this._docSkeletonManagerService = s, this._textSelectionRenderManager = a, this._localeService = c, this._componentManager = d, this._initialize();
1056
+ }
1057
+ _initialize() {
1058
+ this._context.unit.getSnapshot().documentStyle.documentFlavor === In.TRADITIONAL && (this._init(), this._drawHeaderFooterLabel(), this._registerCommands(), this._initCustomComponents());
1059
+ }
1060
+ _registerCommands() {
1061
+ [
1062
+ kt,
1063
+ mn,
1064
+ fn
1065
+ ].forEach((e) => this.disposeWithMe(this._commandService.registerCommand(e)));
1066
+ }
1067
+ _initCustomComponents() {
1068
+ const e = this._componentManager;
1069
+ this.disposeWithMe(e.register(_n, ji));
1070
+ }
1071
+ _init() {
1072
+ const { unitId: e } = this._context, t = Q(this._context);
1073
+ t == null || t.document == null || this._loadedMap.has(t.document) || (this._initialMain(e), this._loadedMap.add(t.document));
1074
+ }
1075
+ _initialMain(e) {
1076
+ const t = Q(this._context), { document: o } = t;
1077
+ this.disposeWithMe(o.onDblclick$.subscribeEvent(async (i) => {
1078
+ if (this._isEditorReadOnly(e))
1079
+ return;
1080
+ const { offsetX: r, offsetY: s } = i, {
1081
+ pageLayoutType: a = De.VERTICAL,
1082
+ pageMarginLeft: c,
1083
+ pageMarginTop: d
1084
+ } = o.getOffsetConfig(), p = this._getTransformCoordForDocumentOffset(r, s);
1085
+ if (p == null)
1086
+ return;
1087
+ const g = this._docSkeletonManagerService.getViewModel(), h = this._docSkeletonManagerService.getSkeleton(), l = g.getEditArea(), { editArea: f, pageNumber: u } = h.findEditAreaByCoord(
1088
+ p,
1089
+ a,
1090
+ c,
1091
+ d
1092
+ );
1093
+ if (l === f)
1094
+ return;
1095
+ g.setEditArea(f);
1096
+ const { createType: _, headerFooterId: m } = Gi(g, f, u);
1097
+ if (f === F.BODY)
1098
+ this._textSelectionRenderManager.setSegment(""), this._textSelectionRenderManager.setSegmentPage(-1), this._textSelectionRenderManager.setCursorManually(r, s);
1099
+ else if (_ != null) {
1100
+ const M = ee.generateRandomId(6);
1101
+ this._textSelectionRenderManager.setSegment(M), this._textSelectionRenderManager.setSegmentPage(u), await this._commandService.executeCommand(kt.id, {
1102
+ unitId: e,
1103
+ createType: _,
1104
+ segmentId: M
1105
+ });
1106
+ } else m != null && (this._textSelectionRenderManager.setSegment(m), this._textSelectionRenderManager.setSegmentPage(u), this._textSelectionRenderManager.setCursorManually(r, s));
1107
+ }));
1108
+ }
1109
+ _getTransformCoordForDocumentOffset(e, t) {
1110
+ const o = Q(this._context), { document: i, scene: r } = o, { documentTransform: s } = i.getOffsetConfig(), a = r.getViewports()[0];
1111
+ if (a == null)
1112
+ return;
1113
+ const c = a.transformVector2SceneCoord(sn.FromArray([e, t]));
1114
+ return s.clone().invert().applyPoint(c);
1115
+ }
1116
+ // eslint-disable-next-line max-lines-per-function
1117
+ _drawHeaderFooterLabel() {
1118
+ const e = this._localeService;
1119
+ this._renderManagerService.currentRender$.subscribe((t) => {
1120
+ if (t == null)
1121
+ return;
1122
+ const o = this._renderManagerService.getRenderById(t);
1123
+ if (this._editorService.isEditor(t) || this._instanceSrv.getUniverDocInstance(t) == null || o == null)
1124
+ return;
1125
+ const { mainComponent: i } = o, r = i;
1126
+ this.disposeWithMe(
1127
+ qt(
1128
+ // eslint-disable-next-line max-lines-per-function
1129
+ r.pageRender$.subscribe((s) => {
1130
+ if (this._editorService.isEditor(t))
1131
+ return;
1132
+ const d = this._docSkeletonManagerService.getViewModel().getEditArea() === F.BODY, { page: p, pageLeft: g, pageTop: h, ctx: l } = s, { pageWidth: f, pageHeight: u, marginTop: _, marginBottom: m } = p;
1133
+ if (l.save(), l.translate(g - 0.5, h - 0.5), d ? (Xe.drawWith(l, {
1134
+ left: 0,
1135
+ top: 0,
1136
+ width: f,
1137
+ height: _,
1138
+ fill: "rgba(255, 255, 255, 0.5)"
1139
+ }), l.save(), l.translate(0, u - m), Xe.drawWith(l, {
1140
+ left: 0,
1141
+ top: 0,
1142
+ width: f,
1143
+ height: m,
1144
+ fill: "rgba(255, 255, 255, 0.5)"
1145
+ }), l.restore()) : (l.save(), l.translate(0, _), Xe.drawWith(l, {
1146
+ left: 0,
1147
+ top: _,
1148
+ width: f,
1149
+ height: u - _ - m,
1150
+ fill: "rgba(255, 255, 255, 0.5)"
1151
+ }), l.restore()), !d) {
1152
+ const O = {
1153
+ dataArray: [{
1154
+ command: "M",
1155
+ points: [0, _]
1156
+ }, {
1157
+ command: "L",
1158
+ points: [f, _]
1159
+ }],
1160
+ strokeWidth: 1,
1161
+ stroke: Vt
1162
+ }, M = {
1163
+ dataArray: [{
1164
+ command: "M",
1165
+ points: [0, u - m]
1166
+ }, {
1167
+ command: "L",
1168
+ points: [f, u - m]
1169
+ }],
1170
+ strokeWidth: 1,
1171
+ stroke: Vt
1172
+ };
1173
+ bt.drawWith(l, O), bt.drawWith(l, M), l.translate(0, _ + 1), Ae.drawWith(l, {
1174
+ text: e.t("headerFooter.header"),
1175
+ color: jt
1176
+ }), l.translate(0, u - _ - m), Ae.drawWith(l, {
1177
+ text: e.t("headerFooter.footer"),
1178
+ color: jt
1179
+ });
1180
+ }
1181
+ l.restore();
1182
+ })
1183
+ )
1184
+ );
1185
+ });
1186
+ }
1187
+ _isEditorReadOnly(e) {
1188
+ const t = this._editorService.getEditor(e);
1189
+ return t ? t.isReadOnly() : !1;
1190
+ }
1191
+ _getDocDataModel() {
1192
+ return this._context.unit;
1193
+ }
1194
+ };
1195
+ st = zi([
1196
+ X(1, C),
1197
+ X(2, Y),
1198
+ X(3, L),
1199
+ X(4, k),
1200
+ X(5, T(N)),
1201
+ X(6, oe),
1202
+ X(7, T(le)),
1203
+ X(8, T(tn))
1204
+ ], st);
1205
+ function Wt() {
1206
+ return {
1207
+ dataStream: `\r
1208
+ `,
1209
+ textRuns: [{
1210
+ st: 0,
1211
+ ed: 0,
1212
+ ts: {
1213
+ fs: 9
1214
+ // The default header footer text size.
1215
+ }
1216
+ }],
1217
+ paragraphs: [
1218
+ {
1219
+ startIndex: 0,
1220
+ spaceAbove: 0,
1221
+ lineSpacing: 1.5,
1222
+ spaceBelow: 0
1223
+ }
1224
+ ],
1225
+ sectionBreaks: [
1226
+ {
1227
+ startIndex: 1
1228
+ }
1229
+ ]
1230
+ };
1231
+ }
1232
+ function qe(n, e, t, o) {
1233
+ const i = et.getInstance(), r = 6, s = n != null ? n : ee.generateRandomId(r), a = e === U.DEFAULT_HEADER || e === U.FIRST_PAGE_HEADER || e === U.EVEN_PAGE_HEADER, c = i.insertOp([a ? "headers" : "footers", s], {
1234
+ [a ? "headerId" : "footerId"]: s,
1235
+ body: Wt()
1236
+ });
1237
+ o.push(c);
1238
+ const d = ee.generateRandomId(r), p = i.insertOp([a ? "footers" : "headers", d], {
1239
+ [a ? "footers" : "headers"]: d,
1240
+ body: Wt()
1241
+ });
1242
+ o.push(p);
1243
+ let g = "defaultHeaderId", h = "defaultFooterId";
1244
+ switch (e) {
1245
+ case U.DEFAULT_HEADER:
1246
+ g = "defaultHeaderId", h = "defaultFooterId";
1247
+ break;
1248
+ case U.DEFAULT_FOOTER:
1249
+ g = "defaultFooterId", h = "defaultHeaderId";
1250
+ break;
1251
+ case U.FIRST_PAGE_HEADER:
1252
+ g = "firstPageHeaderId", h = "firstPageFooterId";
1253
+ break;
1254
+ case U.FIRST_PAGE_FOOTER:
1255
+ g = "firstPageFooterId", h = "firstPageHeaderId";
1256
+ break;
1257
+ case U.EVEN_PAGE_HEADER:
1258
+ g = "evenPageHeaderId", h = "evenPageFooterId";
1259
+ break;
1260
+ case U.EVEN_PAGE_FOOTER:
1261
+ g = "evenPageFooterId", h = "evenPageHeaderId";
1262
+ break;
1263
+ default:
1264
+ throw new Error(`Unknown header footer type: ${e}`);
1265
+ }
1266
+ for (const [l, f] of [[g, s], [h, d]])
1267
+ if (t[l] != null) {
1268
+ const u = i.replaceOp(["documentStyle", l], t[l], f);
1269
+ o.push(u);
1270
+ } else {
1271
+ const u = i.insertOp(["documentStyle", l], f);
1272
+ o.push(u);
1273
+ }
1274
+ return o;
1275
+ }
1276
+ const Me = "doc.command.core-header-footer", kt = {
1277
+ id: Me,
1278
+ type: de.COMMAND,
1279
+ // eslint-disable-next-line max-lines-per-function
1280
+ handler: async (n, e) => {
1281
+ var I;
1282
+ const t = n.get(C), o = n.get(L), i = n.get(k), { unitId: r, segmentId: s, createType: a, headerFooterProps: c } = e, d = (I = i.getRenderById(r)) == null ? void 0 : I.with(N), p = o.getUniverDocInstance(r), g = d == null ? void 0 : d.getViewModel();
1283
+ if (p == null || g == null)
1284
+ return !1;
1285
+ const h = g.getEditArea(), { documentStyle: l } = p.getSnapshot(), f = (c == null ? void 0 : c.marginFooter) != null || (c == null ? void 0 : c.marginHeader) != null, u = [{
1286
+ startOffset: 0,
1287
+ endOffset: 0,
1288
+ collapsed: !0
1289
+ }], _ = {
1290
+ id: Ve.id,
1291
+ params: {
1292
+ unitId: r,
1293
+ actions: [],
1294
+ textRanges: u,
1295
+ debounce: !0
1296
+ }
1297
+ };
1298
+ f && (_.params.noNeedSetTextRange = !0);
1299
+ const m = et.getInstance(), O = [];
1300
+ return a != null && qe(s, a, l, O), c != null && Object.keys(c).forEach((R) => {
1301
+ const y = c[R], j = l[R];
1302
+ if (y === j)
1303
+ return;
1304
+ let W;
1305
+ if (j === void 0 ? W = m.insertOp(["documentStyle", R], y) : W = m.replaceOp(["documentStyle", R], j, y), O.push(W), R === "useFirstPageHeaderFooter" && y === S.TRUE && !l.firstPageHeaderId) {
1306
+ const $ = h === F.HEADER ? U.FIRST_PAGE_HEADER : U.FIRST_PAGE_FOOTER;
1307
+ qe(s, $, l, O);
1308
+ } else if (R === "evenAndOddHeaders" && y === S.TRUE && !l.evenPageHeaderId) {
1309
+ const $ = h === F.HEADER ? U.EVEN_PAGE_HEADER : U.EVEN_PAGE_FOOTER;
1310
+ qe(s, $, l, O);
1311
+ }
1312
+ }), O.length === 0 ? !1 : (_.params.actions = O.reduce((R, y) => et.compose(R, y), null), !!t.syncExecuteCommand(_.id, _.params));
1313
+ }
1314
+ }, mn = {
1315
+ id: "doc.command.open-header-footer-panel",
1316
+ type: de.COMMAND,
1317
+ handler: async (n, e) => n.get(C).executeCommand(fn.id, { value: "open" })
1318
+ };
1319
+ function Yi(n) {
1320
+ const e = n.get(C);
1321
+ return {
1322
+ id: no.id,
1323
+ group: P.TOOLBAR_FORMAT,
1324
+ type: x.BUTTON,
1325
+ icon: "BoldSingle",
1326
+ title: "Set bold",
1327
+ tooltip: "toolbar.bold",
1328
+ positions: [D.TOOLBAR_START],
1329
+ activated$: new w((t) => {
1330
+ const o = e.onCommandExecuted((i) => {
1331
+ var s;
1332
+ const r = i.id;
1333
+ if (r === V.id || r === ue.id) {
1334
+ const a = q(n);
1335
+ if (a == null)
1336
+ return;
1337
+ const c = (s = a.ts) == null ? void 0 : s.bl;
1338
+ t.next(c === S.TRUE);
1339
+ }
1340
+ });
1341
+ return t.next(!1), o.dispose;
1342
+ }),
1343
+ hidden$: A(n, v.UNIVER_DOC)
345
1344
  };
346
1345
  }
347
- function Ni(i) {
348
- const e = i.get(v);
1346
+ function Xi(n) {
1347
+ const e = n.get(C);
349
1348
  return {
350
- id: In.id,
351
- group: I.TOOLBAR_FORMAT,
352
- type: T.BUTTON,
1349
+ id: oo.id,
1350
+ group: P.TOOLBAR_FORMAT,
1351
+ type: x.BUTTON,
1352
+ icon: "ItalicSingle",
1353
+ title: "Set italic",
1354
+ tooltip: "toolbar.italic",
1355
+ positions: [D.TOOLBAR_START],
1356
+ activated$: new w((t) => {
1357
+ const o = e.onCommandExecuted((i) => {
1358
+ var s;
1359
+ const r = i.id;
1360
+ if (r === V.id || r === ue.id) {
1361
+ const a = q(n);
1362
+ if (a == null)
1363
+ return;
1364
+ const c = (s = a.ts) == null ? void 0 : s.it;
1365
+ t.next(c === S.TRUE);
1366
+ }
1367
+ });
1368
+ return t.next(!1), o.dispose;
1369
+ }),
1370
+ hidden$: A(n, v.UNIVER_DOC)
1371
+ };
1372
+ }
1373
+ function Ki(n) {
1374
+ const e = n.get(C);
1375
+ return {
1376
+ id: io.id,
1377
+ group: P.TOOLBAR_FORMAT,
1378
+ type: x.BUTTON,
1379
+ icon: "UnderlineSingle",
1380
+ title: "Set underline",
1381
+ tooltip: "toolbar.underline",
1382
+ positions: [D.TOOLBAR_START],
1383
+ activated$: new w((t) => {
1384
+ const o = e.onCommandExecuted((i) => {
1385
+ var s;
1386
+ const r = i.id;
1387
+ if (r === V.id || r === ue.id) {
1388
+ const a = q(n);
1389
+ if (a == null)
1390
+ return;
1391
+ const c = (s = a.ts) == null ? void 0 : s.ul;
1392
+ t.next((c == null ? void 0 : c.s) === S.TRUE);
1393
+ }
1394
+ });
1395
+ return t.next(!1), o.dispose;
1396
+ }),
1397
+ hidden$: A(n, v.UNIVER_DOC)
1398
+ };
1399
+ }
1400
+ function Zi(n) {
1401
+ const e = n.get(C);
1402
+ return {
1403
+ id: ro.id,
1404
+ group: P.TOOLBAR_FORMAT,
1405
+ type: x.BUTTON,
1406
+ icon: "StrikethroughSingle",
1407
+ title: "Set strike through",
1408
+ tooltip: "toolbar.strikethrough",
1409
+ positions: [D.TOOLBAR_START],
1410
+ activated$: new w((t) => {
1411
+ const o = e.onCommandExecuted((i) => {
1412
+ var s;
1413
+ const r = i.id;
1414
+ if (r === V.id || r === ue.id) {
1415
+ const a = q(n);
1416
+ if (a == null)
1417
+ return;
1418
+ const c = (s = a.ts) == null ? void 0 : s.st;
1419
+ t.next((c == null ? void 0 : c.s) === S.TRUE);
1420
+ }
1421
+ });
1422
+ return t.next(!1), o.dispose;
1423
+ }),
1424
+ hidden$: A(n, v.UNIVER_DOC)
1425
+ };
1426
+ }
1427
+ function qi(n) {
1428
+ const e = n.get(C);
1429
+ return {
1430
+ id: so.id,
1431
+ group: P.TOOLBAR_FORMAT,
1432
+ type: x.BUTTON,
353
1433
  icon: "SubscriptSingle",
354
1434
  tooltip: "toolbar.subscript",
355
- positions: [b.TOOLBAR_START],
356
- activated$: new y((t) => {
357
- const n = e.onCommandExecuted((r) => {
1435
+ positions: [D.TOOLBAR_START],
1436
+ activated$: new w((t) => {
1437
+ const o = e.onCommandExecuted((i) => {
358
1438
  var s;
359
- const o = r.id;
360
- if (o === x.id || o === q.id) {
361
- const a = V(i);
1439
+ const r = i.id;
1440
+ if (r === V.id || r === ue.id) {
1441
+ const a = q(n);
362
1442
  if (a == null)
363
1443
  return;
364
1444
  const c = (s = a.ts) == null ? void 0 : s.va;
365
- t.next(c === K.SUBSCRIPT);
1445
+ t.next(c === ae.SUBSCRIPT);
366
1446
  }
367
1447
  });
368
- return t.next(!1), n.dispose;
1448
+ return t.next(!1), o.dispose;
369
1449
  }),
370
- hidden$: M(i, f.UNIVER_DOC)
1450
+ hidden$: A(n, v.UNIVER_DOC)
371
1451
  };
372
1452
  }
373
- function Ui(i) {
374
- const e = i.get(v);
1453
+ function Ji(n) {
1454
+ const e = n.get(C);
375
1455
  return {
376
- id: bn.id,
377
- group: I.TOOLBAR_FORMAT,
378
- type: T.BUTTON,
1456
+ id: ao.id,
1457
+ group: P.TOOLBAR_FORMAT,
1458
+ type: x.BUTTON,
379
1459
  icon: "SuperscriptSingle",
380
1460
  tooltip: "toolbar.superscript",
381
- positions: [b.TOOLBAR_START],
382
- activated$: new y((t) => {
383
- const n = e.onCommandExecuted((r) => {
1461
+ positions: [D.TOOLBAR_START],
1462
+ activated$: new w((t) => {
1463
+ const o = e.onCommandExecuted((i) => {
384
1464
  var s;
385
- const o = r.id;
386
- if (o === x.id || o === q.id) {
387
- const a = V(i);
1465
+ const r = i.id;
1466
+ if (r === V.id || r === ue.id) {
1467
+ const a = q(n);
388
1468
  if (a == null)
389
1469
  return;
390
1470
  const c = (s = a.ts) == null ? void 0 : s.va;
391
- t.next(c === K.SUPERSCRIPT);
1471
+ t.next(c === ae.SUPERSCRIPT);
392
1472
  }
393
1473
  });
394
- return t.next(!1), n.dispose;
1474
+ return t.next(!1), o.dispose;
395
1475
  }),
396
- hidden$: M(i, f.UNIVER_DOC)
1476
+ hidden$: A(n, v.UNIVER_DOC)
397
1477
  };
398
1478
  }
399
- function Ai(i) {
400
- const e = i.get(v);
1479
+ function Qi(n) {
1480
+ const e = n.get(C);
401
1481
  return {
402
- id: ct.id,
1482
+ id: Rt.id,
403
1483
  tooltip: "toolbar.font",
404
- group: I.TOOLBAR_FORMAT,
405
- type: T.SELECTOR,
406
- label: At,
407
- positions: [b.TOOLBAR_START],
408
- selections: at.map((t) => ({
1484
+ group: P.TOOLBAR_FORMAT,
1485
+ type: x.SELECTOR,
1486
+ label: dn,
1487
+ positions: [D.TOOLBAR_START],
1488
+ selections: Ot.map((t) => ({
409
1489
  label: {
410
- name: Lt,
1490
+ name: un,
411
1491
  hoverable: !0
412
1492
  },
413
1493
  value: t.value
414
1494
  })),
415
1495
  // disabled$: getCurrentSheetDisabled$(accessor),
416
- value$: new y((t) => {
417
- const n = at[0].value, r = e.onCommandExecuted((o) => {
1496
+ value$: new w((t) => {
1497
+ const o = Ot[0].value, i = e.onCommandExecuted((r) => {
418
1498
  var a;
419
- const s = o.id;
420
- if (s === x.id || s === ct.id) {
421
- const c = V(i);
1499
+ const s = r.id;
1500
+ if (s === V.id || s === Rt.id) {
1501
+ const c = q(n);
422
1502
  if (c == null)
423
1503
  return;
424
- const l = (a = c.ts) == null ? void 0 : a.ff;
425
- t.next(l != null ? l : n);
1504
+ const d = (a = c.ts) == null ? void 0 : a.ff;
1505
+ t.next(d != null ? d : o);
426
1506
  }
427
1507
  });
428
- return t.next(n), r.dispose;
1508
+ return t.next(o), i.dispose;
429
1509
  }),
430
- hidden$: M(i, f.UNIVER_DOC)
1510
+ hidden$: A(n, v.UNIVER_DOC)
431
1511
  };
432
1512
  }
433
- function Li(i) {
434
- const e = i.get(v);
1513
+ function er(n) {
1514
+ const e = n.get(C);
435
1515
  return {
436
- id: lt.id,
437
- group: I.TOOLBAR_FORMAT,
438
- type: T.SELECTOR,
1516
+ id: Ct.id,
1517
+ group: P.TOOLBAR_FORMAT,
1518
+ type: x.SELECTOR,
439
1519
  tooltip: "toolbar.fontSize",
440
1520
  label: {
441
- name: $t,
1521
+ name: hn,
442
1522
  props: {
443
1523
  min: 1,
444
1524
  max: 400
445
1525
  // disabled$,
446
1526
  }
447
1527
  },
448
- positions: [b.TOOLBAR_START],
449
- selections: nn,
1528
+ positions: [D.TOOLBAR_START],
1529
+ selections: wn,
450
1530
  // disabled$,
451
- value$: new y((t) => {
452
- const r = e.onCommandExecuted((o) => {
1531
+ value$: new w((t) => {
1532
+ const i = e.onCommandExecuted((r) => {
453
1533
  var a;
454
- const s = o.id;
455
- if (s === x.id || s === lt.id) {
456
- const c = V(i);
1534
+ const s = r.id;
1535
+ if (s === V.id || s === Ct.id) {
1536
+ const c = q(n);
457
1537
  if (c == null)
458
1538
  return;
459
- const l = (a = c.ts) == null ? void 0 : a.fs;
460
- t.next(l != null ? l : 14);
1539
+ const d = (a = c.ts) == null ? void 0 : a.fs;
1540
+ t.next(d != null ? d : 14);
461
1541
  }
462
1542
  });
463
- return t.next(14), r.dispose;
1543
+ return t.next(14), i.dispose;
464
1544
  }),
465
- hidden$: M(i, f.UNIVER_DOC)
1545
+ hidden$: A(n, v.UNIVER_DOC)
466
1546
  };
467
1547
  }
468
- function $i(i) {
469
- const e = i.get(v), t = i.get(yt);
1548
+ function tr(n) {
1549
+ const e = n.get(C), t = n.get(Qt);
470
1550
  return {
471
- id: dt.id,
1551
+ id: Et.id,
472
1552
  icon: "FontColor",
473
1553
  tooltip: "toolbar.textColor.main",
474
- group: I.TOOLBAR_FORMAT,
475
- type: T.BUTTON_SELECTOR,
476
- positions: [b.TOOLBAR_START],
1554
+ group: P.TOOLBAR_FORMAT,
1555
+ type: x.BUTTON_SELECTOR,
1556
+ positions: [D.TOOLBAR_START],
477
1557
  selections: [
478
1558
  {
479
1559
  label: {
480
- name: nt,
1560
+ name: _t,
481
1561
  hoverable: !1
482
1562
  }
483
1563
  }
484
1564
  ],
485
- value$: new y((n) => {
486
- const r = t.getCurrentTheme().textColor, o = e.onCommandExecuted((s) => {
487
- if (s.id === dt.id) {
1565
+ value$: new w((o) => {
1566
+ const i = t.getCurrentTheme().textColor, r = e.onCommandExecuted((s) => {
1567
+ if (s.id === Et.id) {
488
1568
  const a = s.params.value;
489
- n.next(a != null ? a : r);
1569
+ o.next(a != null ? a : i);
490
1570
  }
491
1571
  });
492
- return n.next(r), o.dispose;
1572
+ return o.next(i), r.dispose;
493
1573
  }),
494
- hidden$: M(i, f.UNIVER_DOC)
1574
+ hidden$: A(n, v.UNIVER_DOC)
495
1575
  // disabled$: getCurrentSheetDisabled$(accessor),
496
1576
  };
497
1577
  }
498
- function Bi(i) {
499
- const e = i.get(v);
1578
+ function nr(n) {
1579
+ return {
1580
+ id: mn.id,
1581
+ group: P.TOOLBAR_OTHERS,
1582
+ type: x.BUTTON,
1583
+ icon: "FreezeRowSingle",
1584
+ tooltip: "toolbar.headerFooter",
1585
+ positions: [D.TOOLBAR_START],
1586
+ hidden$: Ao(A(n, v.UNIVER_DOC), Bn(n), (e, t) => e || t)
1587
+ };
1588
+ }
1589
+ function or(n) {
1590
+ const e = n.get(C);
500
1591
  return {
501
- id: Mn.id,
502
- group: I.TOOLBAR_LAYOUT,
503
- type: T.BUTTON,
1592
+ id: co.id,
1593
+ group: P.TOOLBAR_LAYOUT,
1594
+ type: x.BUTTON,
504
1595
  icon: "LeftJustifyingSingle",
505
1596
  tooltip: "toolbar.alignLeft",
506
- positions: [b.TOOLBAR_START],
507
- activated$: new y((t) => {
508
- const n = e.onCommandExecuted((r) => {
1597
+ positions: [D.TOOLBAR_START],
1598
+ activated$: new w((t) => {
1599
+ const o = e.onCommandExecuted((i) => {
509
1600
  var s;
510
- const o = r.id;
511
- if (o === x.id || o === Ae.id) {
512
- const a = we(i);
1601
+ const r = i.id;
1602
+ if (r === V.id || r === je.id) {
1603
+ const a = ze(n);
513
1604
  if (a == null)
514
1605
  return;
515
1606
  const c = (s = a.paragraphStyle) == null ? void 0 : s.horizontalAlign;
516
- t.next(c === De.LEFT);
1607
+ t.next(c === Le.LEFT);
517
1608
  }
518
1609
  });
519
- return t.next(!1), n.dispose;
1610
+ return t.next(!1), o.dispose;
520
1611
  }),
521
- hidden$: M(i, f.UNIVER_DOC)
1612
+ hidden$: A(n, v.UNIVER_DOC)
522
1613
  };
523
1614
  }
524
- function wi(i) {
525
- const e = i.get(v);
1615
+ function ir(n) {
1616
+ const e = n.get(C);
526
1617
  return {
527
- id: yn.id,
528
- group: I.TOOLBAR_LAYOUT,
529
- type: T.BUTTON,
1618
+ id: lo.id,
1619
+ group: P.TOOLBAR_LAYOUT,
1620
+ type: x.BUTTON,
530
1621
  icon: "HorizontallySingle",
531
1622
  tooltip: "toolbar.alignCenter",
532
- positions: [b.TOOLBAR_START],
533
- activated$: new y((t) => {
534
- const n = e.onCommandExecuted((r) => {
1623
+ positions: [D.TOOLBAR_START],
1624
+ activated$: new w((t) => {
1625
+ const o = e.onCommandExecuted((i) => {
535
1626
  var s;
536
- const o = r.id;
537
- if (o === x.id || o === Ae.id) {
538
- const a = we(i);
1627
+ const r = i.id;
1628
+ if (r === V.id || r === je.id) {
1629
+ const a = ze(n);
539
1630
  if (a == null)
540
1631
  return;
541
1632
  const c = (s = a.paragraphStyle) == null ? void 0 : s.horizontalAlign;
542
- t.next(c === De.CENTER);
1633
+ t.next(c === Le.CENTER);
543
1634
  }
544
1635
  });
545
- return t.next(!1), n.dispose;
1636
+ return t.next(!1), o.dispose;
546
1637
  }),
547
- hidden$: M(i, f.UNIVER_DOC)
1638
+ hidden$: A(n, v.UNIVER_DOC)
548
1639
  };
549
1640
  }
550
- function Fi(i) {
551
- const e = i.get(v);
1641
+ function rr(n) {
1642
+ const e = n.get(C);
552
1643
  return {
553
- id: En.id,
554
- group: I.TOOLBAR_LAYOUT,
555
- type: T.BUTTON,
1644
+ id: uo.id,
1645
+ group: P.TOOLBAR_LAYOUT,
1646
+ type: x.BUTTON,
556
1647
  icon: "RightJustifyingSingle",
557
1648
  tooltip: "toolbar.alignRight",
558
- positions: [b.TOOLBAR_START],
559
- activated$: new y((t) => {
560
- const n = e.onCommandExecuted((r) => {
1649
+ positions: [D.TOOLBAR_START],
1650
+ activated$: new w((t) => {
1651
+ const o = e.onCommandExecuted((i) => {
561
1652
  var s;
562
- const o = r.id;
563
- if (o === x.id || o === Ae.id) {
564
- const a = we(i);
1653
+ const r = i.id;
1654
+ if (r === V.id || r === je.id) {
1655
+ const a = ze(n);
565
1656
  if (a == null)
566
1657
  return;
567
1658
  const c = (s = a.paragraphStyle) == null ? void 0 : s.horizontalAlign;
568
- t.next(c === De.RIGHT);
1659
+ t.next(c === Le.RIGHT);
569
1660
  }
570
1661
  });
571
- return t.next(!1), n.dispose;
1662
+ return t.next(!1), o.dispose;
572
1663
  }),
573
- hidden$: M(i, f.UNIVER_DOC)
1664
+ hidden$: A(n, v.UNIVER_DOC)
574
1665
  };
575
1666
  }
576
- function Vi(i) {
577
- const e = i.get(v);
1667
+ function sr(n) {
1668
+ const e = n.get(C);
578
1669
  return {
579
- id: xn.id,
580
- group: I.TOOLBAR_LAYOUT,
581
- type: T.BUTTON,
1670
+ id: ho.id,
1671
+ group: P.TOOLBAR_LAYOUT,
1672
+ type: x.BUTTON,
582
1673
  icon: "AlignTextBothSingle",
583
1674
  tooltip: "toolbar.alignJustify",
584
- positions: [b.TOOLBAR_START],
585
- activated$: new y((t) => {
586
- const n = e.onCommandExecuted((r) => {
1675
+ positions: [D.TOOLBAR_START],
1676
+ activated$: new w((t) => {
1677
+ const o = e.onCommandExecuted((i) => {
587
1678
  var s;
588
- const o = r.id;
589
- if (o === x.id || o === Ae.id) {
590
- const a = we(i);
1679
+ const r = i.id;
1680
+ if (r === V.id || r === je.id) {
1681
+ const a = ze(n);
591
1682
  if (a == null)
592
1683
  return;
593
1684
  const c = (s = a.paragraphStyle) == null ? void 0 : s.horizontalAlign;
594
- t.next(c === De.JUSTIFIED);
1685
+ t.next(c === Le.JUSTIFIED);
595
1686
  }
596
1687
  });
597
- return t.next(!1), n.dispose;
1688
+ return t.next(!1), o.dispose;
598
1689
  }),
599
- hidden$: M(i, f.UNIVER_DOC)
1690
+ hidden$: A(n, v.UNIVER_DOC)
600
1691
  };
601
1692
  }
602
- function ji(i) {
1693
+ function ar(n) {
603
1694
  return {
604
- id: Dn.id,
605
- group: I.TOOLBAR_LAYOUT,
606
- type: T.BUTTON,
1695
+ id: go.id,
1696
+ group: P.TOOLBAR_LAYOUT,
1697
+ type: x.BUTTON,
607
1698
  icon: "OrderSingle",
608
1699
  tooltip: "toolbar.order",
609
- positions: [b.TOOLBAR_START],
610
- hidden$: M(i, f.UNIVER_DOC)
1700
+ positions: [D.TOOLBAR_START],
1701
+ hidden$: A(n, v.UNIVER_DOC)
611
1702
  };
612
1703
  }
613
- function Wi(i) {
1704
+ function cr(n) {
614
1705
  return {
615
- id: Pn.id,
616
- group: I.TOOLBAR_LAYOUT,
617
- type: T.BUTTON,
1706
+ id: po.id,
1707
+ group: P.TOOLBAR_LAYOUT,
1708
+ type: x.BUTTON,
618
1709
  icon: "UnorderSingle",
619
- tooltip: "toolbar.unorder",
620
- positions: [b.TOOLBAR_START],
621
- hidden$: M(i, f.UNIVER_DOC)
622
- };
623
- }
624
- function zi(i) {
625
- return {
626
- id: Nn.id,
627
- type: T.BUTTON,
628
- title: "toolbar.resetColor",
629
- icon: "NoColor",
630
- positions: He.id
631
- };
632
- }
633
- function ki(i) {
634
- const e = i.get(v), t = i.get(yt);
635
- return {
636
- id: He.id,
637
- tooltip: "toolbar.fillColor.main",
638
- group: I.TOOLBAR_FORMAT,
639
- type: T.BUTTON_SELECTOR,
640
- positions: [b.TOOLBAR_START],
641
- icon: "PaintBucket",
642
- selections: [
643
- {
644
- label: {
645
- name: nt,
646
- hoverable: !1
647
- }
648
- }
649
- ],
650
- value$: new y((n) => {
651
- const r = t.getCurrentTheme().primaryColor, o = e.onCommandExecuted((s) => {
652
- if (s.id === He.id) {
653
- const a = s.params.value;
654
- n.next(a != null ? a : r);
655
- }
656
- });
657
- return n.next(r), o.dispose;
658
- }),
659
- hidden$: M(i, f.UNIVER_DOC)
660
- };
661
- }
662
- function V(i) {
663
- var c;
664
- const e = i.get(P), t = i.get(J), n = e.getCurrentUniverDocInstance(), r = t.getActiveRange();
665
- if (n == null || r == null)
666
- return;
667
- const o = (c = n.getBody()) == null ? void 0 : c.textRuns;
668
- if (o == null)
669
- return;
670
- const { startOffset: s } = r;
671
- let a;
672
- for (let l = 0; l < o.length; l++) {
673
- const u = o[l], h = o[l + 1];
674
- if (h && h.st === h.ed && s === h.st) {
675
- a = h;
676
- break;
677
- }
678
- if (u.st <= s && s <= u.ed) {
679
- a = u;
680
- break;
681
- }
682
- }
683
- return a;
684
- }
685
- function we(i) {
686
- var c;
687
- const e = i.get(P), t = i.get(J), n = e.getCurrentUniverDocInstance(), r = t.getActiveRange();
688
- if (n == null || r == null)
689
- return;
690
- const o = (c = n.getBody()) == null ? void 0 : c.paragraphs;
691
- if (o == null)
692
- return;
693
- const { startOffset: s } = r;
694
- let a = -1;
695
- for (const l of o) {
696
- const { startIndex: u } = l;
697
- if (s > a && s <= u)
698
- return l;
699
- a = u;
700
- }
701
- return null;
702
- }
703
- var Hi = Object.defineProperty, Yi = Object.getOwnPropertyDescriptor, Gi = (i, e, t, n) => {
704
- for (var r = n > 1 ? void 0 : n ? Yi(e, t) : e, o = i.length - 1, s; o >= 0; o--)
705
- (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
706
- return n && r && Hi(e, t, r), r;
707
- }, W = (i, e) => (t, n) => e(t, n, i);
708
- let ce = class extends k {
709
- constructor(i, e, t, n, r, o, s, a) {
710
- super(), this._config = i, this._injector = e, this._componentManager = t, this._layoutService = n, this._editorService = r, this._menuService = o, this._uiPartsService = s, this._univerInstanceService = a, this._init();
711
- }
712
- _initCustomComponents() {
713
- const i = this._componentManager;
714
- this.disposeWithMe(i.register(nt, qn)), this.disposeWithMe(i.register(At, rn)), this.disposeWithMe(i.register(Lt, on)), this.disposeWithMe(i.register($t, sn));
715
- }
716
- _initMenus() {
717
- const { menu: i = {} } = this._config;
718
- [
719
- Ei,
720
- xi,
721
- Di,
722
- Pi,
723
- Ni,
724
- Ui,
725
- Li,
726
- Ai,
727
- $i,
728
- Bi,
729
- wi,
730
- Fi,
731
- Vi,
732
- ji,
733
- Wi,
734
- zi,
735
- ki
736
- ].forEach((e) => {
737
- this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e), i));
738
- });
739
- }
740
- _init() {
741
- this._initCustomComponents(), this._initMenus(), this._initDocBackground(), this._initFocusHandler();
742
- }
743
- _initDocBackground() {
744
- const i = this._univerInstanceService.getAllUnitsForType(f.UNIVER_DOC)[0].getUnitId();
745
- if (i == null)
746
- return;
747
- this._editorService.isEditor(i) || this.disposeWithMe(
748
- this._uiPartsService.registerComponent(an.CONTENT, () => jn(yi, this._injector))
749
- );
750
- }
751
- _initFocusHandler() {
752
- this.disposeWithMe(
753
- this._layoutService.registerFocusHandler(f.UNIVER_DOC, () => {
754
- this._injector.get(he).focus();
755
- })
756
- );
757
- }
758
- };
759
- ce = Gi([
760
- U(A.Rendered, ce),
761
- W(1, O(Pe)),
762
- W(2, O(cn)),
763
- W(3, xt),
764
- W(4, L),
765
- W(5, ln),
766
- W(6, dn),
767
- W(7, P)
768
- ], ce);
769
- const Xi = {
770
- id: Un.id,
771
- preconditions: ni,
772
- binding: E.ENTER
773
- }, Ki = {
774
- id: An.id,
775
- preconditions: N,
776
- binding: E.BACKSPACE
777
- }, Zi = {
778
- id: Ln.id,
779
- preconditions: N,
780
- binding: E.DELETE
781
- }, qi = 10, Ji = 6;
782
- function Qi() {
783
- return Je.generateRandomId(Ji);
784
- }
785
- function er(i) {
786
- const e = i.match(/data-copy-id="([^\s]+)"/);
787
- return e && e[1] ? e[1] : null;
788
- }
789
- class tr {
790
- constructor() {
791
- g(this, "_cache", new kt(qi));
792
- }
793
- set(e, t) {
794
- this._cache.set(e, t);
795
- }
796
- get(e) {
797
- return this._cache.get(e);
798
- }
799
- clear() {
800
- this._cache.clear();
801
- }
802
- }
803
- const St = new tr();
804
- function it(i) {
805
- const e = i.style, t = {}, n = i.tagName.toLowerCase();
806
- switch (n) {
807
- case "b":
808
- case "em":
809
- case "strong": {
810
- t.bl = C.TRUE;
811
- break;
812
- }
813
- case "s": {
814
- t.st = {
815
- s: C.TRUE
816
- };
817
- break;
818
- }
819
- case "u": {
820
- t.ul = {
821
- s: C.TRUE
822
- };
823
- break;
824
- }
825
- case "i": {
826
- t.it = C.TRUE;
827
- break;
828
- }
829
- case "sub":
830
- case "sup": {
831
- t.va = n === "sup" ? K.SUPERSCRIPT : K.SUBSCRIPT;
832
- break;
833
- }
834
- }
835
- for (let r = 0; r < e.length; r++) {
836
- const o = e[r], s = e.getPropertyValue(o);
837
- switch (o) {
838
- case "font-family": {
839
- t.ff = s;
840
- break;
841
- }
842
- case "font-size": {
843
- const a = Number.parseInt(s);
844
- Number.isNaN(a) || (s.endsWith("pt") ? t.fs = a : s.endsWith("px") && (t.fs = Wn(a)));
845
- break;
846
- }
847
- case "font-style": {
848
- s === "italic" && (t.it = C.TRUE);
849
- break;
850
- }
851
- case "font-weight": {
852
- Number(s) > 400 && (t.bl = C.TRUE);
853
- break;
854
- }
855
- case "text-decoration": {
856
- /underline/.test(s) ? t.ul = {
857
- s: C.TRUE
858
- } : /overline/.test(s) ? t.ol = {
859
- s: C.TRUE
860
- } : /line-through/.test(s) && (t.st = {
861
- s: C.TRUE
862
- });
863
- break;
864
- }
865
- case "color": {
866
- const a = new st(s);
867
- a.isValid && (t.cl = {
868
- rgb: a.toRgbString()
869
- });
870
- break;
871
- }
872
- case "background-color": {
873
- const a = new st(s);
874
- a.isValid && (t.bg = {
875
- rgb: a.toRgbString()
876
- });
877
- break;
878
- }
879
- }
880
- }
881
- return t;
882
- }
883
- function nr(i) {
884
- const e = new DOMParser(), t = `<x-univer id="univer-root">${i}</x-univer>`;
885
- return e.parseFromString(t, "text/html").querySelector("#univer-root");
886
- }
887
- function vt(i, e) {
888
- const t = i.tagName.toLowerCase();
889
- return typeof e == "string" ? t === e : Array.isArray(e) ? e.some((n) => n === t) : e(i);
890
- }
891
- const Ee = class Ee {
892
- constructor() {
893
- g(this, "_styleCache", /* @__PURE__ */ new Map());
894
- g(this, "_styleRules", []);
895
- g(this, "_afterProcessRules", []);
896
- }
897
- static use(e) {
898
- if (this._pluginList.includes(e))
899
- throw new Error(`Univer paste plugin ${e.name} already added`);
900
- this._pluginList.push(e);
901
- }
902
- convert(e) {
903
- const t = Ee._pluginList.find((o) => o.checkPasteType(e)), n = nr(e), r = {
904
- dataStream: "",
905
- textRuns: []
906
- };
907
- return t && (this._styleRules = [...t.stylesRules], this._afterProcessRules = [...t.afterProcessRules]), this._styleCache.clear(), this._process(null, n == null ? void 0 : n.childNodes, r), this._styleCache.clear(), this._styleRules = [], this._afterProcessRules = [], r;
908
- }
909
- _process(e, t, n) {
910
- var r;
911
- for (const o of t)
912
- if (o.nodeType === Node.TEXT_NODE) {
913
- const s = (r = o.nodeValue) == null ? void 0 : r.replace(/[\r\n]/g, "");
914
- let a;
915
- e && this._styleCache.has(e) && (a = this._styleCache.get(e)), n.dataStream += s, a && Object.getOwnPropertyNames(a).length && n.textRuns.push({
916
- st: n.dataStream.length - s.length,
917
- ed: n.dataStream.length,
918
- ts: a
919
- });
920
- } else if (o.nodeType === Node.ELEMENT_NODE) {
921
- const s = e ? this._styleCache.get(e) : {}, a = this._styleRules.find(({ filter: h }) => vt(o, h)), c = a ? a.getStyle(o) : it(o);
922
- this._styleCache.set(o, { ...s, ...c });
923
- const { childNodes: l } = o;
924
- this._process(o, l, n);
925
- const u = this._afterProcessRules.find(
926
- ({ filter: h }) => vt(o, h)
927
- );
928
- u && u.handler(n, o);
929
- }
930
- }
931
- };
932
- g(Ee, "_pluginList", []);
933
- let Z = Ee;
934
- const ir = {
935
- name: "univer-doc-paste-plugin-lark",
936
- checkPasteType(i) {
937
- return /lark-record-clipboard/i.test(i);
938
- },
939
- // TODO: @JOCS, support inline code copy from lark.
940
- stylesRules: [
941
- {
942
- filter: ["s"],
943
- getStyle(i) {
944
- const e = it(i);
945
- return {
946
- st: {
947
- s: C.TRUE
948
- },
949
- ...e
950
- };
951
- }
952
- }
953
- ],
954
- afterProcessRules: [
955
- {
956
- filter(i) {
957
- return i.tagName === "DIV" && /ace-line/i.test(i.className);
958
- },
959
- handler(i) {
960
- i.paragraphs == null && (i.paragraphs = []), i.paragraphs.push({
961
- startIndex: i.dataStream.length
962
- }), i.dataStream += "\r";
963
- }
964
- }
965
- ]
966
- }, rr = ir;
967
- function Ft(i) {
968
- const e = i.style, t = {};
969
- for (let n = 0; n < e.length; n++) {
970
- const r = e[n], o = e.getPropertyValue(r);
971
- switch (r) {
972
- case "margin-top": {
973
- const s = Number.parseInt(o);
974
- t.spaceAbove = /pt/.test(o) ? ht(s) : s;
975
- break;
976
- }
977
- case "margin-bottom": {
978
- const s = Number.parseInt(o);
979
- t.spaceBelow = /pt/.test(o) ? ht(s) : s;
980
- break;
981
- }
982
- case "line-height": {
983
- const s = Number.parseFloat(o);
984
- t.lineSpacing = s;
985
- break;
986
- }
987
- }
988
- }
989
- return Object.getOwnPropertyNames(t).length ? t : null;
990
- }
991
- const or = {
992
- name: "univer-doc-paste-plugin-word",
993
- checkPasteType(i) {
994
- return /word|mso/i.test(i);
995
- },
996
- stylesRules: [
997
- {
998
- filter: ["b"],
999
- getStyle(i) {
1000
- const e = it(i);
1001
- return { bl: C.TRUE, ...e };
1002
- }
1003
- }
1004
- ],
1005
- afterProcessRules: [
1006
- {
1007
- filter(i) {
1008
- return i.tagName === "P" && /mso/i.test(i.className);
1009
- },
1010
- handler(i, e) {
1011
- i.paragraphs == null && (i.paragraphs = []);
1012
- const t = {
1013
- startIndex: i.dataStream.length
1014
- }, n = Ft(e);
1015
- n && (t.paragraphStyle = n), i.paragraphs.push(t), i.dataStream += "\r";
1016
- }
1017
- }
1018
- ]
1019
- }, sr = or, ar = {
1020
- name: "univer-doc-paste-plugin-univer",
1021
- checkPasteType(i) {
1022
- return /UniverNormal/i.test(i);
1023
- },
1024
- stylesRules: [],
1025
- afterProcessRules: [
1026
- {
1027
- filter(i) {
1028
- return i.tagName === "P" && /UniverNormal/i.test(i.className);
1029
- },
1030
- handler(i, e) {
1031
- i.paragraphs == null && (i.paragraphs = []);
1032
- const t = {
1033
- startIndex: i.dataStream.length
1034
- }, n = Ft(e);
1035
- n && (t.paragraphStyle = n), i.paragraphs.push(t), i.dataStream += "\r";
1036
- }
1037
- }
1038
- ]
1039
- }, cr = ar;
1040
- function Ct(i, e) {
1041
- const { st: t, ed: n, ts: r = {} } = e, { ff: o, fs: s, it: a, bl: c, ul: l, st: u, ol: h, bg: m, cl: p, va: S } = r;
1042
- let d = i.slice(t, n);
1043
- const _ = [];
1044
- return a === C.TRUE && (d = `<i>${d}</i>`), S === K.SUPERSCRIPT ? d = `<sup>${d}</sup>` : S === K.SUBSCRIPT && (d = `<sub>${d}</sub>`), (l == null ? void 0 : l.s) === C.TRUE && (d = `<u>${d}</u>`), (u == null ? void 0 : u.s) === C.TRUE && (d = `<s>${d}</s>`), c === C.TRUE && (d = `<strong>${d}</strong>`), o && _.push(`font-family: ${o}`), p && _.push(`color: ${p.rgb}`), s && _.push(`font-size: ${s}pt`), h && _.push("text-decoration: overline"), m && _.push(`background: ${m.rgb}`), _.length ? `<span style="${_.join("; ")};">${d}</span>` : d;
1045
- }
1046
- function ze(i, e, t) {
1047
- const { dataStream: n, textRuns: r = [] } = i;
1048
- let o = e;
1049
- const s = [];
1050
- for (const a of r) {
1051
- const { st: c, ed: l } = a;
1052
- Je.hasIntersectionBetweenTwoRanges(e, t, c, l) && (c > o ? (s.push(n.slice(o, c)), s.push(Ct(n, {
1053
- ...a,
1054
- ed: Math.min(l, t)
1055
- }))) : s.push(Ct(n, {
1056
- ...a,
1057
- st: o,
1058
- ed: Math.min(l, t)
1059
- }))), o = Math.max(e, Math.min(l, t));
1060
- }
1061
- return o !== t && s.push(n.slice(o, t)), s.join("");
1062
- }
1063
- function Ot(i, e = !0) {
1064
- var t;
1065
- if (e && ((t = i.paragraphs) != null && t.length)) {
1066
- const { dataStream: n, paragraphs: r = [] } = i;
1067
- let o = "", s = -1;
1068
- for (const a of r) {
1069
- const { startIndex: c, paragraphStyle: l = {} } = a, { spaceAbove: u, spaceBelow: h, lineSpacing: m } = l, p = [];
1070
- u != null && (typeof u == "number" ? p.push(`margin-top: ${u}px`) : p.push(`margin-top: ${u.v}px`)), h != null && (typeof h == "number" ? p.push(`margin-bottom: ${h}px`) : p.push(`margin-bottom: ${h.v}px`)), m != null && p.push(`line-height: ${m}`), c > s + 1 ? o += `<p class="UniverNormal" ${p.length ? `style="${p.join("; ")};"` : ""}>${ze(i, s + 1, c)}</p>` : o += `<p class="UniverNormal" ${p.length ? `style="${p.join("; ")};"` : ""}></p>`, s = c;
1071
- }
1072
- return s !== n.length && (o += ze(i, s, n.length)), o;
1073
- } else
1074
- return ze(i, 0, i.dataStream.length);
1075
- }
1076
- class lr {
1077
- convert(e) {
1078
- if (e.length === 0)
1079
- throw new Error("The bodyList length at least to be 1");
1080
- if (e.length === 1)
1081
- return Ot(e[0]);
1082
- let t = "";
1083
- for (const n of e)
1084
- t += '<p className="UniverNormal">', t += Ot(n, !1), t += "</p>";
1085
- return t;
1086
- }
1087
- }
1088
- var dr = Object.defineProperty, ur = Object.getOwnPropertyDescriptor, hr = (i, e, t, n) => {
1089
- for (var r = n > 1 ? void 0 : n ? ur(e, t) : e, o = i.length - 1, s; o >= 0; o--)
1090
- (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
1091
- return n && r && dr(e, t, r), r;
1092
- }, re = (i, e) => (t, n) => e(t, n, i);
1093
- Z.use(sr);
1094
- Z.use(rr);
1095
- Z.use(cr);
1096
- function pr(i) {
1097
- const e = i.replace(/\n/g, "\r"), t = [];
1098
- for (let n = 0; n < e.length; n++)
1099
- e[n] === "\r" && t.push({ startIndex: n });
1100
- return {
1101
- dataStream: e,
1102
- paragraphs: t
1103
- };
1104
- }
1105
- const pe = tn("doc.clipboard-service");
1106
- let Xe = class extends k {
1107
- constructor(e, t, n, r, o) {
1108
- super();
1109
- g(this, "_clipboardHooks", []);
1110
- g(this, "_htmlToUDM", new Z());
1111
- g(this, "_umdToHtml", new lr());
1112
- this._univerInstanceService = e, this._logService = t, this._commandService = n, this._clipboardInterfaceService = r, this._textSelectionManagerService = o;
1113
- }
1114
- async copy() {
1115
- const e = this._getDocumentBodyInRanges();
1116
- if (e.length === 0)
1117
- return !1;
1118
- try {
1119
- this._setClipboardData(e);
1120
- } catch (t) {
1121
- return this._logService.error("[DocClipboardService] copy failed", t), !1;
1122
- }
1123
- return !0;
1124
- }
1125
- async cut() {
1126
- return this._cut();
1127
- }
1128
- async paste(e) {
1129
- const t = await this._generateBodyFromClipboardItems(e);
1130
- return this._paste(t);
1131
- }
1132
- async legacyPaste(e, t) {
1133
- const n = this._generateBodyFromHtmlAndText(e, t);
1134
- return this._paste(n);
1135
- }
1136
- async _cut() {
1137
- var o;
1138
- const {
1139
- segmentId: e,
1140
- endOffset: t,
1141
- style: n
1142
- } = (o = this._textSelectionManagerService.getActiveRange()) != null ? o : {}, r = this._textSelectionManagerService.getSelections();
1143
- if (e == null && this._logService.error("[DocClipboardController] segmentId is not existed"), t == null || r == null)
1144
- return !1;
1145
- this.copy();
1146
- try {
1147
- let s = t;
1148
- for (const c of r) {
1149
- const { startOffset: l, endOffset: u } = c;
1150
- l == null || u == null || u <= t && (s -= u - l);
1151
- }
1152
- const a = [
1153
- {
1154
- startOffset: s,
1155
- endOffset: s,
1156
- style: n
1710
+ tooltip: "toolbar.unorder",
1711
+ positions: [D.TOOLBAR_START],
1712
+ hidden$: A(n, v.UNIVER_DOC)
1713
+ };
1714
+ }
1715
+ function lr(n) {
1716
+ return {
1717
+ id: _o.id,
1718
+ type: x.BUTTON,
1719
+ title: "toolbar.resetColor",
1720
+ icon: "NoColor",
1721
+ positions: tt.id
1722
+ };
1723
+ }
1724
+ function dr(n) {
1725
+ const e = n.get(C), t = n.get(Qt);
1726
+ return {
1727
+ id: tt.id,
1728
+ tooltip: "toolbar.fillColor.main",
1729
+ group: P.TOOLBAR_FORMAT,
1730
+ type: x.BUTTON_SELECTOR,
1731
+ positions: [D.TOOLBAR_START],
1732
+ icon: "PaintBucket",
1733
+ selections: [
1734
+ {
1735
+ label: {
1736
+ name: _t,
1737
+ hoverable: !1
1157
1738
  }
1158
- ];
1159
- return this._commandService.executeCommand(Dt.id, { segmentId: e, textRanges: a });
1160
- } catch {
1161
- return this._logService.error("[DocClipboardController] cut content failed"), !1;
1162
- }
1163
- }
1164
- async _paste(e) {
1165
- var s;
1166
- const { segmentId: t, endOffset: n, style: r } = (s = this._textSelectionManagerService.getActiveRange()) != null ? s : {}, o = this._textSelectionManagerService.getSelections();
1167
- if (t == null && this._logService.error("[DocClipboardController] segmentId does not exist!"), n == null || o == null)
1168
- return !1;
1169
- try {
1170
- let a = n;
1171
- for (const l of o) {
1172
- const { startOffset: u, endOffset: h } = l;
1173
- u == null || h == null || h <= n && (a += e.dataStream.length - (h - u));
1174
1739
  }
1175
- const c = [
1176
- {
1177
- startOffset: a,
1178
- endOffset: a,
1179
- style: r
1740
+ ],
1741
+ value$: new w((o) => {
1742
+ const i = t.getCurrentTheme().primaryColor, r = e.onCommandExecuted((s) => {
1743
+ if (s.id === tt.id) {
1744
+ const a = s.params.value;
1745
+ o.next(a != null ? a : i);
1180
1746
  }
1181
- ];
1182
- return this._commandService.executeCommand(Pt.id, { body: e, segmentId: t, textRanges: c });
1183
- } catch {
1184
- return this._logService.error("[DocClipboardController]", "clipboard is empty."), !1;
1747
+ });
1748
+ return o.next(i), r.dispose;
1749
+ }),
1750
+ hidden$: A(n, v.UNIVER_DOC)
1751
+ };
1752
+ }
1753
+ function q(n) {
1754
+ var d;
1755
+ const e = n.get(L), t = n.get(ne), o = e.getCurrentUniverDocInstance(), i = t.getActiveRange();
1756
+ if (o == null || i == null)
1757
+ return;
1758
+ const { startOffset: r, segmentId: s } = i, a = (d = o.getSelfOrHeaderFooterModel(s).getBody()) == null ? void 0 : d.textRuns;
1759
+ if (a == null)
1760
+ return;
1761
+ let c;
1762
+ for (let p = 0; p < a.length; p++) {
1763
+ const g = a[p], h = a[p + 1];
1764
+ if (h && h.st === h.ed && r === h.st) {
1765
+ c = h;
1766
+ break;
1767
+ }
1768
+ if (g.st <= r && r <= g.ed) {
1769
+ c = g;
1770
+ break;
1185
1771
  }
1186
1772
  }
1187
- async _setClipboardData(e) {
1188
- const t = Qi(), n = e.length > 1 ? e.map((o) => o.dataStream).join(`
1189
- `) : e[0].dataStream;
1190
- let r = this._umdToHtml.convert(e);
1191
- return e.length === 1 && (r = r.replace(/(<[a-z]+)/, (o, s) => `${s} data-copy-id="${t}"`), St.set(t, e[0])), this._clipboardInterfaceService.write(n, r);
1773
+ return c;
1774
+ }
1775
+ function ze(n) {
1776
+ var d;
1777
+ const e = n.get(L), t = n.get(ne), o = e.getCurrentUniverDocInstance(), i = t.getActiveRange();
1778
+ if (o == null || i == null)
1779
+ return;
1780
+ const { startOffset: r, segmentId: s } = i, a = (d = o.getSelfOrHeaderFooterModel(s).getBody()) == null ? void 0 : d.paragraphs;
1781
+ if (a == null)
1782
+ return;
1783
+ let c = -1;
1784
+ for (const p of a) {
1785
+ const { startIndex: g } = p;
1786
+ if (r > c && r <= g)
1787
+ return p;
1788
+ c = g;
1192
1789
  }
1193
- addClipboardHook(e) {
1194
- return this._clipboardHooks.push(e), B(() => {
1195
- const t = this._clipboardHooks.indexOf(e);
1196
- t > -1 && this._clipboardHooks.splice(t, 1);
1790
+ return null;
1791
+ }
1792
+ var ur = Object.defineProperty, hr = Object.getOwnPropertyDescriptor, gr = (n, e, t, o) => {
1793
+ for (var i = o > 1 ? void 0 : o ? hr(e, t) : e, r = n.length - 1, s; r >= 0; r--)
1794
+ (s = n[r]) && (i = (o ? s(e, t, i) : s(i)) || i);
1795
+ return o && i && ur(e, t, i), i;
1796
+ }, J = (n, e) => (t, o) => e(t, o, n);
1797
+ let Se = class extends K {
1798
+ constructor(n, e, t, o, i, r, s, a) {
1799
+ super(), this._config = n, this._injector = e, this._componentManager = t, this._layoutService = o, this._editorService = i, this._menuService = r, this._uiPartsService = s, this._univerInstanceService = a, this._init();
1800
+ }
1801
+ _initCustomComponents() {
1802
+ const n = this._componentManager;
1803
+ this.disposeWithMe(n.register(_t, wo)), this.disposeWithMe(n.register(dn, $n)), this.disposeWithMe(n.register(un, Hn)), this.disposeWithMe(n.register(hn, Vn));
1804
+ }
1805
+ _initMenus() {
1806
+ const { menu: n = {} } = this._config;
1807
+ [
1808
+ Yi,
1809
+ Xi,
1810
+ Ki,
1811
+ Zi,
1812
+ qi,
1813
+ Ji,
1814
+ er,
1815
+ Qi,
1816
+ tr,
1817
+ nr,
1818
+ or,
1819
+ ir,
1820
+ rr,
1821
+ sr,
1822
+ ar,
1823
+ cr,
1824
+ lr,
1825
+ dr
1826
+ ].forEach((e) => {
1827
+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e), n));
1197
1828
  });
1198
1829
  }
1199
- _getDocumentBodyInRanges() {
1200
- const e = this._textSelectionManagerService.getSelections(), t = this._univerInstanceService.getCurrentUniverDocInstance(), n = [];
1201
- if (e == null || !t)
1202
- return n;
1203
- for (const r of e) {
1204
- const { startOffset: o, endOffset: s, collapsed: a } = r;
1205
- if (a || o == null || s == null)
1206
- continue;
1207
- const c = t.sliceBody(o, s);
1208
- c != null && n.push(c);
1209
- }
1210
- return n;
1830
+ _init() {
1831
+ this._initCustomComponents(), this._initMenus(), this._initDocBackground(), this._initFocusHandler();
1211
1832
  }
1212
- async _generateBodyFromClipboardItems(e) {
1213
- try {
1214
- let t = "", n = "";
1215
- for (const r of e)
1216
- for (const o of r.types)
1217
- o === un ? n = await r.getType(o).then((s) => s && s.text()) : o === hn && (t = await r.getType(o).then((s) => s && s.text()));
1218
- return this._generateBodyFromHtmlAndText(t, n);
1219
- } catch (t) {
1220
- return Promise.reject(t);
1221
- }
1833
+ _initDocBackground() {
1834
+ const n = this._univerInstanceService.getAllUnitsForType(v.UNIVER_DOC)[0].getUnitId();
1835
+ if (n == null)
1836
+ return;
1837
+ this._editorService.isEditor(n) || this.disposeWithMe(
1838
+ this._uiPartsService.registerComponent(jn.CONTENT, () => No(Fi, this._injector))
1839
+ );
1222
1840
  }
1223
- _generateBodyFromHtmlAndText(e, t) {
1224
- if (!e) {
1225
- if (t)
1226
- return pr(t);
1227
- throw new Error("[DocClipboardService] html and text cannot be both empty!");
1228
- }
1229
- const n = er(e);
1230
- if (n) {
1231
- const r = St.get(n);
1232
- if (r)
1233
- return r;
1234
- }
1235
- return this._htmlToUDM.convert(e);
1841
+ _initFocusHandler() {
1842
+ this.disposeWithMe(
1843
+ this._layoutService.registerFocusHandler(v.UNIVER_DOC, () => {
1844
+ this._injector.get(oe).focus();
1845
+ })
1846
+ );
1236
1847
  }
1237
1848
  };
1238
- Xe = hr([
1239
- re(0, P),
1240
- re(1, Et),
1241
- re(2, v),
1242
- re(3, et),
1243
- re(4, O(J))
1244
- ], Xe);
1245
- function Fe(i) {
1246
- return i.getContextValue(xe) || i.getContextValue(Mt);
1849
+ Se = gr([
1850
+ Ue(we.Rendered, Se),
1851
+ J(1, T(Be)),
1852
+ J(2, T(tn)),
1853
+ J(3, en),
1854
+ J(4, Y),
1855
+ J(5, Wn),
1856
+ J(6, kn),
1857
+ J(7, L)
1858
+ ], Se);
1859
+ const pr = {
1860
+ id: fo.id,
1861
+ preconditions: $o,
1862
+ binding: H.ENTER
1863
+ }, _r = {
1864
+ id: mo.id,
1865
+ preconditions: z,
1866
+ binding: H.BACKSPACE
1867
+ }, fr = {
1868
+ id: So.id,
1869
+ preconditions: z,
1870
+ binding: H.DELETE
1871
+ };
1872
+ function Ge(n) {
1873
+ return n.getContextValue(Ne) || n.getContextValue(Jt);
1247
1874
  }
1248
- const rt = 999, _r = {
1249
- id: pn.id,
1875
+ const ft = 999, mr = {
1876
+ id: zn.id,
1250
1877
  name: "doc.command.copy",
1251
- type: Qe.COMMAND,
1878
+ type: de.COMMAND,
1252
1879
  multi: !0,
1253
- priority: rt,
1254
- preconditions: Fe,
1255
- handler: async (i) => i.get(pe).copy()
1256
- }, gr = {
1257
- id: _n.id,
1880
+ priority: ft,
1881
+ preconditions: Ge,
1882
+ handler: async (n) => n.get(Ce).copy()
1883
+ }, Sr = {
1884
+ id: Gn.id,
1258
1885
  name: "doc.command.cut",
1259
- type: Qe.COMMAND,
1886
+ type: de.COMMAND,
1260
1887
  multi: !0,
1261
- priority: rt,
1262
- preconditions: Fe,
1263
- handler: async (i) => i.get(pe).cut()
1264
- }, fr = {
1265
- id: gn.id,
1888
+ priority: ft,
1889
+ preconditions: Ge,
1890
+ handler: async (n) => n.get(Ce).cut()
1891
+ }, vr = {
1892
+ id: Yn.id,
1266
1893
  name: "doc.command.paste",
1267
- type: Qe.COMMAND,
1894
+ type: de.COMMAND,
1268
1895
  multi: !0,
1269
- priority: rt,
1270
- preconditions: Fe,
1271
- handler: async (i) => {
1272
- const e = i.get(pe), n = await i.get(et).read();
1273
- return n.length === 0 ? !1 : e.paste(n);
1896
+ priority: ft,
1897
+ preconditions: Ge,
1898
+ handler: async (n) => {
1899
+ const e = n.get(Ce), o = await n.get(gt).read();
1900
+ return o.length === 0 ? !1 : e.paste(o);
1274
1901
  }
1275
1902
  };
1276
- var mr = Object.defineProperty, Sr = Object.getOwnPropertyDescriptor, vr = (i, e, t, n) => {
1277
- for (var r = n > 1 ? void 0 : n ? Sr(e, t) : e, o = i.length - 1, s; o >= 0; o--)
1278
- (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
1279
- return n && r && mr(e, t, r), r;
1280
- }, oe = (i, e) => (t, n) => e(t, n, i);
1281
- let Ce = class extends de {
1282
- constructor(i, e, t, n, r) {
1283
- super(), this._commandService = i, this._clipboardInterfaceService = e, this._docClipboardService = t, this._textSelectionRenderManager = n, this._contextService = r, this._init();
1903
+ var Or = Object.defineProperty, Rr = Object.getOwnPropertyDescriptor, Cr = (n, e, t, o) => {
1904
+ for (var i = o > 1 ? void 0 : o ? Rr(e, t) : e, r = n.length - 1, s; r >= 0; r--)
1905
+ (s = n[r]) && (i = (o ? s(e, t, i) : s(i)) || i);
1906
+ return o && i && Or(e, t, i), i;
1907
+ }, ge = (n, e) => (t, o) => e(t, o, n);
1908
+ let xe = class extends Oe {
1909
+ constructor(n, e, t, o, i) {
1910
+ super(), this._commandService = n, this._clipboardInterfaceService = e, this._docClipboardService = t, this._textSelectionRenderManager = o, this._contextService = i, this._init();
1284
1911
  }
1285
1912
  _init() {
1286
- [_r, gr, fr].forEach((i) => this.disposeWithMe(this._commandService.registerMultipleCommand(i))), [Pt, Dt].forEach((i) => this.disposeWithMe(this._commandService.registerCommand(i))), this._initLegacyPasteCommand();
1913
+ [mr, Sr, vr].forEach((n) => this.disposeWithMe(this._commandService.registerMultipleCommand(n))), [on, nn].forEach((n) => this.disposeWithMe(this._commandService.registerCommand(n))), this._initLegacyPasteCommand();
1287
1914
  }
1288
1915
  _initLegacyPasteCommand() {
1289
- var i;
1290
- (i = this._textSelectionRenderManager) == null || i.onPaste$.pipe(le(this.dispose$)).subscribe((e) => {
1291
- var o, s;
1292
- if (!Fe(this._contextService))
1916
+ var n;
1917
+ (n = this._textSelectionRenderManager) == null || n.onPaste$.pipe(se(this.dispose$)).subscribe((e) => {
1918
+ var r, s;
1919
+ if (!Ge(this._contextService))
1293
1920
  return;
1294
1921
  e.event.preventDefault();
1295
- const t = e.event, n = (o = t.clipboardData) == null ? void 0 : o.getData("text/html"), r = (s = t.clipboardData) == null ? void 0 : s.getData("text/plain");
1296
- this._docClipboardService.legacyPaste(n, r);
1922
+ const t = e.event, o = (r = t.clipboardData) == null ? void 0 : r.getData("text/html"), i = (s = t.clipboardData) == null ? void 0 : s.getData("text/plain");
1923
+ this._docClipboardService.legacyPaste(o, i);
1297
1924
  });
1298
1925
  }
1299
1926
  };
1300
- Ce = vr([
1301
- U(A.Rendered, Ce),
1302
- oe(0, v),
1303
- oe(1, et),
1304
- oe(2, pe),
1305
- oe(3, he),
1306
- oe(4, Ht)
1307
- ], Ce);
1308
- var Cr = Object.defineProperty, Or = Object.getOwnPropertyDescriptor, Rr = (i, e, t, n) => {
1309
- for (var r = n > 1 ? void 0 : n ? Or(e, t) : e, o = i.length - 1, s; o >= 0; o--)
1310
- (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
1311
- return n && r && Cr(e, t, r), r;
1312
- }, Y = (i, e) => (t, n) => e(t, n, i);
1313
- let Oe = class extends k {
1314
- constructor(e, t, n, r, o, s) {
1927
+ xe = Cr([
1928
+ Ue(we.Rendered, xe),
1929
+ ge(0, C),
1930
+ ge(1, gt),
1931
+ ge(2, Ce),
1932
+ ge(3, oe),
1933
+ ge(4, bn)
1934
+ ], xe);
1935
+ var Er = Object.defineProperty, Tr = Object.getOwnPropertyDescriptor, Ir = (n, e, t, o) => {
1936
+ for (var i = o > 1 ? void 0 : o ? Tr(e, t) : e, r = n.length - 1, s; r >= 0; r--)
1937
+ (s = n[r]) && (i = (o ? s(e, t, i) : s(i)) || i);
1938
+ return o && i && Er(e, t, i), i;
1939
+ }, pe = (n, e) => (t, o) => e(t, o, n);
1940
+ let ye = class extends K {
1941
+ constructor(e, t, o, i, r) {
1315
1942
  super();
1316
- g(this, "_initialEditors", /* @__PURE__ */ new Set());
1317
- this._univerInstanceService = e, this._docSkeletonManagerService = t, this._editorService = n, this._commandService = r, this._textSelectionRenderManager = o, this._renderManagerService = s, this._initialize();
1943
+ E(this, "_initialEditors", /* @__PURE__ */ new Set());
1944
+ this._univerInstanceService = e, this._editorService = t, this._commandService = o, this._textSelectionRenderManager = i, this._renderManagerService = r, this._initialize();
1318
1945
  }
1319
1946
  _initialize() {
1320
1947
  this.disposeWithMe(
@@ -1327,31 +1954,34 @@ let Oe = class extends k {
1327
1954
  }), this._commandExecutedListener(), this._initialSetValue(), this._initialBlur(), this._initialFocus(), this._initialValueChange();
1328
1955
  }
1329
1956
  _resize(e) {
1330
- var $, H, j;
1957
+ var M, I, R;
1331
1958
  if (e == null)
1332
1959
  return;
1333
1960
  const t = this._editorService.getEditor(e);
1334
1961
  if ((t == null ? void 0 : t.cancelDefaultResizeListener) === !0)
1335
1962
  return;
1336
- const n = ($ = this._docSkeletonManagerService.getSkeletonByUnitId(e)) == null ? void 0 : $.skeleton, r = this._univerInstanceService.getUniverDocInstance(e);
1337
- if (t == null || t.render == null || n == null || r == null)
1963
+ const o = this._univerInstanceService.getUniverDocInstance(e);
1964
+ if (!o)
1338
1965
  return;
1339
- n.calculate();
1340
- const { marginTop: o = 0, marginBottom: s = 0, marginLeft: a = 0, marginRight: c = 0 } = r.getSnapshot().documentStyle, { scene: l, mainComponent: u } = t.render;
1341
- let { actualHeight: h, actualWidth: m } = n.getActualSize();
1342
- h += o + s, m += a + c;
1343
- const { width: p, height: S } = t.getBoundingClientRect(), d = l.getViewport(Q.VIEW_MAIN);
1344
- let _ = d == null ? void 0 : d.getScrollBar();
1345
- const R = Math.max(m, p), D = Math.max(h, S);
1346
- l.transformByState({
1347
- width: R,
1348
- height: D
1349
- }), u == null || u.resize(R, D), t.isSingle() ? m > p ? _ == null ? d && new Ye(d, { barSize: 8, enableVertical: !1 }) : d == null || d.resetCanvasSizeAndUpdateScrollBar() : (_ = null, d == null || d.scrollTo({ x: 0, y: 0 }), (j = d == null ? void 0 : d.getScrollBar()) == null || j.dispose()) : h > S ? _ == null ? d && new Ye(d, { enableHorizontal: !1, barSize: 8 }) : d == null || d.resetCanvasSizeAndUpdateScrollBar() : (_ = null, d == null || d.scrollTo({ x: 0, y: 0 }), (H = d == null ? void 0 : d.getScrollBar()) == null || H.dispose());
1966
+ const i = (M = this._renderManagerService.getRenderById(o.getUnitId())) == null ? void 0 : M.with(N).getSkeleton();
1967
+ if (t == null || t.render == null || i == null || o == null)
1968
+ return;
1969
+ i.calculate();
1970
+ const { marginTop: r = 0, marginBottom: s = 0, marginLeft: a = 0, marginRight: c = 0 } = o.getSnapshot().documentStyle, { scene: d, mainComponent: p } = t.render;
1971
+ let { actualHeight: g, actualWidth: h } = i.getActualSize();
1972
+ g += r + s, h += a + c;
1973
+ const { width: l, height: f } = t.getBoundingClientRect(), u = d.getViewport(te.VIEW_MAIN);
1974
+ let _ = u == null ? void 0 : u.getScrollBar();
1975
+ const m = Math.max(h, l), O = Math.max(g, f);
1976
+ d.transformByState({
1977
+ width: m,
1978
+ height: O
1979
+ }), p == null || p.resize(m, O), t.isSingle() ? h > l ? _ == null ? u && new nt(u, { barSize: 8, enableVertical: !1 }) : u == null || u.resetCanvasSizeAndUpdateScrollBar() : (_ = null, u == null || u.scrollTo({ x: 0, y: 0 }), (R = u == null ? void 0 : u.getScrollBar()) == null || R.dispose()) : g > f ? _ == null ? u && new nt(u, { enableHorizontal: !1, barSize: 8 }) : u == null || u.resetCanvasSizeAndUpdateScrollBar() : (_ = null, u == null || u.scrollTo({ x: 0, y: 0 }), (I = u == null ? void 0 : u.getScrollBar()) == null || I.dispose());
1350
1980
  }
1351
1981
  _initialSetValue() {
1352
1982
  this.disposeWithMe(
1353
1983
  this._editorService.setValue$.subscribe((e) => {
1354
- this._commandService.executeCommand($n.id, {
1984
+ this._commandService.executeCommand(vo.id, {
1355
1985
  unitId: e.editorUnitId,
1356
1986
  body: e.body,
1357
1987
  segmentId: null
@@ -1366,19 +1996,19 @@ let Oe = class extends k {
1366
1996
  })
1367
1997
  ), this.disposeWithMe(
1368
1998
  this._textSelectionRenderManager.onBlur$.subscribe(() => {
1369
- var r;
1370
- const e = (r = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : r.getUnitId();
1999
+ var i;
2000
+ const e = (i = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : i.getUnitId();
1371
2001
  if (e == null)
1372
2002
  return;
1373
- const t = this._editorService.getEditor(e), n = this._editorService.getFocusEditor();
1374
- t == null || t.isSheetEditor() || n && n.editorUnitId === e || this._editorService.blur();
2003
+ const t = this._editorService.getEditor(e), o = this._editorService.getFocusEditor();
2004
+ t == null || t.isSheetEditor() || o && o.editorUnitId === e || this._editorService.blur();
1375
2005
  })
1376
2006
  );
1377
2007
  }
1378
2008
  _initialFocus() {
1379
2009
  this.disposeWithMe(
1380
- this._editorService.focus$.subscribe((n) => {
1381
- this._textSelectionRenderManager.removeAllTextRanges(), this._textSelectionRenderManager.addTextRanges([n]);
2010
+ this._editorService.focus$.subscribe((o) => {
2011
+ this._textSelectionRenderManager.removeAllTextRanges(), this._textSelectionRenderManager.addTextRanges([o]);
1382
2012
  })
1383
2013
  );
1384
2014
  const e = [
@@ -1388,17 +2018,17 @@ let Oe = class extends k {
1388
2018
  "univer-formula-help-param"
1389
2019
  ];
1390
2020
  this.disposeWithMe(
1391
- ft(window, "mousedown").subscribe((n) => {
1392
- const o = n.target.classList[0] || "";
1393
- if (Yt(o, e)) {
1394
- this._editorService.changeSpreadsheetFocusState(!0), n.stopPropagation();
2021
+ yt(window, "mousedown").subscribe((o) => {
2022
+ const r = o.target.classList[0] || "";
2023
+ if (Mn(r, e)) {
2024
+ this._editorService.changeSpreadsheetFocusState(!0), o.stopPropagation();
1395
2025
  return;
1396
2026
  }
1397
2027
  this._editorService.changeSpreadsheetFocusState(!1);
1398
2028
  })
1399
- ), this._univerInstanceService.getAllUnitsForType(f.UNIVER_SHEET).forEach((n) => {
1400
- const r = n.getUnitId(), o = this._renderManagerService.getRenderById(r), s = o == null ? void 0 : o.engine.getCanvas().getCanvasEle();
1401
- s != null && ft(s, "mousedown").subscribe((a) => {
2029
+ ), this._univerInstanceService.getAllUnitsForType(v.UNIVER_SHEET).forEach((o) => {
2030
+ const i = o.getUnitId(), r = this._renderManagerService.getRenderById(i), s = r == null ? void 0 : r.engine.getCanvas().getCanvasEle();
2031
+ s != null && yt(s, "mousedown").subscribe((a) => {
1402
2032
  this._editorService.changeSpreadsheetFocusState(!0), a.stopPropagation();
1403
2033
  });
1404
2034
  });
@@ -1415,8 +2045,8 @@ let Oe = class extends k {
1415
2045
  );
1416
2046
  }
1417
2047
  _valueChange() {
1418
- var n;
1419
- const e = (n = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : n.getUnitId();
2048
+ var o;
2049
+ const e = (o = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : o.getUnitId();
1420
2050
  if (e == null)
1421
2051
  return;
1422
2052
  const t = this._editorService.getEditor(e);
@@ -1426,135 +2056,49 @@ let Oe = class extends k {
1426
2056
  * Listen to document edits to refresh the size of the formula editor.
1427
2057
  */
1428
2058
  _commandExecutedListener() {
1429
- const e = [tt.id, fn.id];
2059
+ const e = [Ve.id, Xn.id];
1430
2060
  this.disposeWithMe(
1431
2061
  this._commandService.onCommandExecuted((t) => {
1432
2062
  if (e.includes(t.id)) {
1433
- const n = t.params, { unitId: r } = n;
1434
- if (this._editorService.isSheetEditor(r))
2063
+ const o = t.params, { unitId: i } = o;
2064
+ if (this._editorService.isSheetEditor(i))
1435
2065
  return;
1436
- this._resize(r), this._valueChange();
2066
+ this._resize(i), this._valueChange();
1437
2067
  }
1438
2068
  })
1439
2069
  );
1440
2070
  }
1441
2071
  };
1442
- Oe = Rr([
1443
- U(A.Rendered, Oe),
1444
- Y(0, P),
1445
- Y(1, O(ee)),
1446
- Y(2, L),
1447
- Y(3, v),
1448
- Y(4, he),
1449
- Y(5, F)
1450
- ], Oe);
1451
- var Tr = Object.defineProperty, Ir = Object.getOwnPropertyDescriptor, br = (i, e, t, n) => {
1452
- for (var r = n > 1 ? void 0 : n ? Ir(e, t) : e, o = i.length - 1, s; o >= 0; o--)
1453
- (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
1454
- return n && r && Tr(e, t, r), r;
1455
- }, ge = (i, e) => (t, n) => e(t, n, i);
1456
- let Re = class extends de {
1457
- constructor(e, t, n, r) {
1458
- super();
1459
- g(this, "_docRenderMap", /* @__PURE__ */ new Set());
1460
- this._docSkeletonManagerService = e, this._renderManagerService = t, this._commandService = n, this._editorService = r, this._initialRenderRefresh(), this._commandExecutedListener();
1461
- }
1462
- _initialRenderRefresh() {
1463
- this._docSkeletonManagerService.currentSkeletonBefore$.pipe(le(this.dispose$)).subscribe((e) => {
1464
- this._create(e);
1465
- });
1466
- }
1467
- _create(e) {
1468
- if (e == null)
1469
- return;
1470
- const { skeleton: t, unitId: n } = e;
1471
- let r = this._renderManagerService.getRenderById(n);
1472
- r == null && (this._renderManagerService.create(n), r = this._renderManagerService.getRenderById(n));
1473
- const { mainComponent: o, components: s } = r, a = o, c = s.get(X.BACKGROUND);
1474
- a.changeSkeleton(t), c.changeSkeleton(t), this._recalculateSizeBySkeleton(r, t);
1475
- }
1476
- _recalculateSizeBySkeleton(e, t) {
1477
- var m;
1478
- const { mainComponent: n, scene: r, unitId: o, components: s } = e, a = n, c = s.get(X.BACKGROUND), l = (m = t.getSkeletonData()) == null ? void 0 : m.pages;
1479
- if (l == null)
1480
- return;
1481
- let u = 0, h = 0;
1482
- for (let p = 0, S = l.length; p < S; p++) {
1483
- const d = l[p], { pageWidth: _, pageHeight: R } = d;
1484
- a.pageLayoutType === pt.VERTICAL ? (h += R, h += a.pageMarginTop, p === S - 1 && (h += a.pageMarginTop), u = Math.max(u, _)) : a.pageLayoutType === pt.HORIZONTAL && (u += _, p !== S - 1 && (u += a.pageMarginLeft), h = Math.max(h, R));
2072
+ ye = Ir([
2073
+ Ue(we.Rendered, ye),
2074
+ pe(0, L),
2075
+ pe(1, Y),
2076
+ pe(2, C),
2077
+ pe(3, oe),
2078
+ pe(4, k)
2079
+ ], ye);
2080
+ var br = Object.defineProperty, Mr = Object.getOwnPropertyDescriptor, xr = (n, e, t, o) => {
2081
+ for (var i = o > 1 ? void 0 : o ? Mr(e, t) : e, r = n.length - 1, s; r >= 0; r--)
2082
+ (s = n[r]) && (i = (o ? s(e, t, i) : s(i)) || i);
2083
+ return o && i && br(e, t, i), i;
2084
+ }, _e = (n, e) => (t, o) => e(t, o, n);
2085
+ let at = class extends Oe {
2086
+ constructor(n, e, t, o, i, r) {
2087
+ super(), this._context = n, this._commandService = e, this._docSkeletonManagerService = t, this._configService = o, this._editorService = i, this._renderManagerService = r, this._addNewRender(), this._initRenderRefresh(), this._initCommandListener();
2088
+ }
2089
+ reRender(n) {
2090
+ var i, r;
2091
+ const e = (i = this._renderManagerService.getRenderById(n)) == null ? void 0 : i.with(N), t = e == null ? void 0 : e.getSkeleton();
2092
+ if (!(!t || t.getViewModel().getDataModel().getSnapshot().disabled)) {
2093
+ if (t.calculate(), this._editorService.isEditor(n)) {
2094
+ (r = this._context.mainComponent) == null || r.makeDirty();
2095
+ return;
2096
+ }
2097
+ this._recalculateSizeBySkeleton(t);
1485
2098
  }
1486
- a.resize(u, h), c.resize(u, h), this._editorService.isEditor(o) || r.resize(u, h);
1487
- }
1488
- _commandExecutedListener() {
1489
- const e = [tt.id];
1490
- this.disposeWithMe(
1491
- this._commandService.onCommandExecuted((t) => {
1492
- var n;
1493
- if (e.includes(t.id)) {
1494
- const r = t.params, { unitId: o } = r, s = this._docSkeletonManagerService.getSkeletonByUnitId(o);
1495
- if (s == null)
1496
- return;
1497
- const { skeleton: a } = s, c = this._renderManagerService.getRenderById(o);
1498
- if (c == null || !!a.getViewModel().getDataModel().getSnapshot().disabled)
1499
- return;
1500
- if (a.calculate(), this._editorService.isEditor(o)) {
1501
- (n = c.mainComponent) == null || n.makeDirty();
1502
- return;
1503
- }
1504
- this._recalculateSizeBySkeleton(c, a);
1505
- }
1506
- })
1507
- );
1508
- }
1509
- };
1510
- Re = br([
1511
- U(A.Rendered, Re),
1512
- ge(0, O(ee)),
1513
- ge(1, F),
1514
- ge(2, v),
1515
- ge(3, L)
1516
- ], Re);
1517
- var Mr = Object.defineProperty, yr = Object.getOwnPropertyDescriptor, Er = (i, e, t, n) => {
1518
- for (var r = n > 1 ? void 0 : n ? yr(e, t) : e, o = i.length - 1, s; o >= 0; o--)
1519
- (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
1520
- return n && r && Mr(e, t, r), r;
1521
- }, fe = (i, e) => (t, n) => e(t, n, i);
1522
- let Te = class extends de {
1523
- constructor(e, t, n, r) {
1524
- super();
1525
- g(this, "_scene");
1526
- g(this, "_currentDocumentModel");
1527
- g(this, "_fps$", new Ut(""));
1528
- g(this, "fps$", this._fps$.asObservable());
1529
- this._renderManagerService = e, this._configService = t, this._univerInstanceService = n, this._editorService = r, this._initialize();
1530
- }
1531
- _initialize() {
1532
- this._renderManagerService.createRender$.pipe(le(this.dispose$)).subscribe((e) => {
1533
- this._create(e);
1534
- }), this._univerInstanceService.getCurrentTypeOfUnit$(f.UNIVER_DOC).pipe(le(this.dispose$)).subscribe((e) => {
1535
- this._create(e == null ? void 0 : e.getUnitId());
1536
- }), this._univerInstanceService.getAllUnitsForType(f.UNIVER_DOC).forEach((e) => {
1537
- this._create(e.getUnitId());
1538
- });
1539
- }
1540
- dispose() {
1541
- this._fps$.complete();
1542
- }
1543
- _create(e) {
1544
- if (e == null)
1545
- return;
1546
- const t = this._univerInstanceService.getUniverDocInstance(e);
1547
- t != null && (this._currentDocumentModel = t, this._renderManagerService.has(e) || this._addNewRender());
1548
2099
  }
1549
2100
  _addNewRender() {
1550
- const t = this._currentDocumentModel.getUnitId();
1551
- this._renderManagerService.createRender(t);
1552
- const n = this._renderManagerService.getRenderById(t);
1553
- if (n == null)
1554
- return;
1555
- const { scene: r, engine: o } = n;
1556
- this._scene = r;
1557
- const s = new zn(Q.VIEW_MAIN, r, {
2101
+ const { scene: n, engine: e, unit: t } = this._context, o = new Mo(te.VIEW_MAIN, n, {
1558
2102
  left: 0,
1559
2103
  top: 0,
1560
2104
  bottom: 0,
@@ -1563,336 +2107,307 @@ let Te = class extends de {
1563
2107
  isRelativeY: !0,
1564
2108
  isWheelPreventDefaultX: !0
1565
2109
  });
1566
- r.attachControl(), r.on(kn.wheel, (l, u) => {
1567
- const h = l;
1568
- if (h.ctrlKey) {
1569
- const m = Math.abs(h.deltaX);
1570
- let p = m < 40 ? 0.2 : m < 80 ? 0.4 : 0.2;
1571
- p *= h.deltaY > 0 ? -1 : 1, r.scaleX < 1 && (p /= 2), r.scaleX + p > 4 ? r.scale(4, 4) : r.scaleX + p < 0.1 ? r.scale(0.1, 0.1) : h.preventDefault();
2110
+ n.attachControl(), n.onMouseWheel$.subscribeEvent((s, a) => {
2111
+ const c = s;
2112
+ if (c.ctrlKey) {
2113
+ const d = Math.abs(c.deltaX);
2114
+ let p = d < 40 ? 0.2 : d < 80 ? 0.4 : 0.2;
2115
+ p *= c.deltaY > 0 ? -1 : 1, n.scaleX < 1 && (p /= 2), n.scaleX + p > 4 ? n.scale(4, 4) : n.scaleX + p < 0.1 ? n.scale(0.1, 0.1) : c.preventDefault();
1572
2116
  } else
1573
- s.onMouseWheel(h, u);
1574
- }), this._configService.getConfig("hasScroll") !== !1 && new Ye(s), r.addLayer(
1575
- new _t(r, [], We),
1576
- new _t(r, [], Bn)
1577
- ), this._addComponent(n), this._currentDocumentModel.getShouldRenderLoopImmediately() && o.runRenderLoop(() => {
1578
- r.render(), this._fps$.next(Math.round(o.getFps()).toString());
1579
- }), this._renderManagerService.setCurrent(t);
1580
- }
1581
- _addComponent(e) {
1582
- const t = this._scene, n = this._currentDocumentModel, r = {
1583
- pageMarginLeft: n.documentStyle.marginLeft || 0,
1584
- pageMarginTop: n.documentStyle.marginTop || 0
1585
- }, o = new Hn(X.MAIN, void 0, r), s = new Yn(X.BACKGROUND, void 0, r);
1586
- o.zIndex = ut, s.zIndex = ut, e.mainComponent = o, e.components.set(X.MAIN, o), e.components.set(X.BACKGROUND, s), t.addObjects([o], We), t.addObjects([s], wn), this._editorService.getEditor(n.getUnitId()) == null && t.enableLayerCache(We);
2117
+ o.onMouseWheel(c, a);
2118
+ }), this._configService.getConfig("hasScroll") !== !1 && new nt(o), n.addLayer(
2119
+ new Mt(n, [], Ye),
2120
+ new Mt(n, [], Oo)
2121
+ ), this._addComponent(), t.getShouldRenderLoopImmediately() && e.runRenderLoop(() => {
2122
+ n.render();
2123
+ });
2124
+ }
2125
+ _addComponent() {
2126
+ const { scene: n, unit: e, components: t } = this._context, o = {
2127
+ pageMarginLeft: e.documentStyle.marginLeft || 0,
2128
+ pageMarginTop: e.documentStyle.marginTop || 0
2129
+ }, i = new xo(ie.MAIN, void 0, o);
2130
+ i.zIndex = Tt;
2131
+ const r = new yo(ie.BACKGROUND, void 0, o);
2132
+ r.zIndex = Tt, this._context.mainComponent = i, t.set(ie.MAIN, i), t.set(ie.BACKGROUND, r), n.addObjects([i], Ye), n.addObjects([r], Ro), this._editorService.getEditor(e.getUnitId()) == null && n.enableLayerCache(Ye);
2133
+ }
2134
+ _initRenderRefresh() {
2135
+ this._docSkeletonManagerService.currentSkeletonBefore$.pipe(se(this.dispose$)).subscribe((n) => {
2136
+ this._create(n);
2137
+ });
2138
+ }
2139
+ _create(n) {
2140
+ if (!n)
2141
+ return;
2142
+ const { mainComponent: e, components: t } = this._context, o = e, i = t.get(ie.BACKGROUND);
2143
+ o.changeSkeleton(n), i.changeSkeleton(n), this._recalculateSizeBySkeleton(n);
2144
+ }
2145
+ _initCommandListener() {
2146
+ const n = [Ve.id];
2147
+ this.disposeWithMe(this._commandService.onCommandExecuted((e) => {
2148
+ if (n.includes(e.id)) {
2149
+ const t = e.params, { unitId: o } = t;
2150
+ this.reRender(o);
2151
+ }
2152
+ }));
2153
+ }
2154
+ _recalculateSizeBySkeleton(n) {
2155
+ var p;
2156
+ const { mainComponent: e, scene: t, unitId: o, components: i } = this._context, r = e, s = i.get(ie.BACKGROUND), a = (p = n.getSkeletonData()) == null ? void 0 : p.pages;
2157
+ if (a == null)
2158
+ return;
2159
+ let c = 0, d = 0;
2160
+ for (let g = 0, h = a.length; g < h; g++) {
2161
+ const l = a[g], { pageWidth: f, pageHeight: u } = l;
2162
+ r.pageLayoutType === De.VERTICAL ? (d += u, d += r.pageMarginTop, g === h - 1 && (d += r.pageMarginTop), c = Math.max(c, f)) : r.pageLayoutType === De.HORIZONTAL && (c += f, g !== h - 1 && (c += r.pageMarginLeft), d = Math.max(d, u));
2163
+ }
2164
+ r.resize(c, d), s.resize(c, d), this._editorService.isEditor(o) || t.resize(c, d);
1587
2165
  }
1588
2166
  };
1589
- Te = Er([
1590
- U(A.Starting, Te),
1591
- fe(0, F),
1592
- fe(1, Gt),
1593
- fe(2, P),
1594
- fe(3, L)
1595
- ], Te);
1596
- var xr = Object.defineProperty, Dr = Object.getOwnPropertyDescriptor, Pr = (i, e, t, n) => {
1597
- for (var r = n > 1 ? void 0 : n ? Dr(e, t) : e, o = i.length - 1, s; o >= 0; o--)
1598
- (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
1599
- return n && r && xr(e, t, r), r;
1600
- }, me = (i, e) => (t, n) => e(t, n, i);
1601
- let Ie = class extends k {
1602
- constructor(e, t, n, r) {
2167
+ at = xr([
2168
+ _e(1, C),
2169
+ _e(2, T(N)),
2170
+ _e(3, xn),
2171
+ _e(4, Y),
2172
+ _e(5, k)
2173
+ ], at);
2174
+ var yr = Object.defineProperty, Pr = Object.getOwnPropertyDescriptor, Dr = (n, e, t, o) => {
2175
+ for (var i = o > 1 ? void 0 : o ? Pr(e, t) : e, r = n.length - 1, s; r >= 0; r--)
2176
+ (s = n[r]) && (i = (o ? s(e, t, i) : s(i)) || i);
2177
+ return o && i && yr(e, t, i), i;
2178
+ }, Je = (n, e) => (t, o) => e(t, o, n);
2179
+ let ct = class extends K {
2180
+ constructor(e, t, o, i) {
1603
2181
  super();
1604
- g(this, "_liquid", new Gn());
1605
- g(this, "_pageMarginCache", /* @__PURE__ */ new Map());
1606
- this._docSkeletonManagerService = e, this._renderManagerService = t, this._commandService = n, this._editorService = r, this._initialize(), this._commandExecutedListener();
2182
+ E(this, "_liquid", new Po());
2183
+ E(this, "_pageMarginCache", /* @__PURE__ */ new Map());
2184
+ this._context = e, this._docSkeletonManagerService = t, this._commandService = o, this._editorService = i, this._initialize(), this._commandExecutedListener();
1607
2185
  }
1608
2186
  _initialize() {
1609
- this._initialRenderRefresh(), this._updateOnPluginChange();
1610
- }
1611
- _updateOnPluginChange() {
1612
- }
1613
- _initialRenderRefresh() {
1614
2187
  this._docSkeletonManagerService.currentSkeleton$.subscribe((e) => {
1615
- if (e == null)
1616
- return;
1617
- const { skeleton: t, unitId: n } = e, r = this._renderManagerService.getRenderById(n);
1618
- if (r == null)
1619
- return;
1620
- const { mainComponent: o } = r;
1621
- o.changeSkeleton(t), this._refreshDrawing(n, t, r);
2188
+ e != null && this._refreshDrawing(e);
1622
2189
  });
1623
2190
  }
1624
2191
  _commandExecutedListener() {
1625
- const e = [tt.id, Le.id];
2192
+ const e = [Ve.id, ve.id];
1626
2193
  this.disposeWithMe(
1627
2194
  this._commandService.onCommandExecuted((t) => {
1628
- var n;
2195
+ var o;
1629
2196
  if (e.includes(t.id)) {
1630
- const r = t.params, { unitId: o } = r, s = this._docSkeletonManagerService.getCurrent();
1631
- if (s == null)
1632
- return;
1633
- const { unitId: a, skeleton: c } = s;
1634
- if (o !== a)
2197
+ const i = t.params, { unitId: r } = i, s = this._docSkeletonManagerService.getSkeleton();
2198
+ if (!s)
1635
2199
  return;
1636
- const l = this._renderManagerService.getRenderById(a);
1637
- if (l == null)
1638
- return;
1639
- if (this._editorService.isEditor(a)) {
1640
- (n = l.mainComponent) == null || n.makeDirty();
2200
+ if (this._editorService.isEditor(r)) {
2201
+ (o = this._context.mainComponent) == null || o.makeDirty();
1641
2202
  return;
1642
2203
  }
1643
- this._refreshDrawing(a, c, l);
2204
+ this._refreshDrawing(s);
1644
2205
  }
1645
2206
  })
1646
2207
  );
1647
2208
  }
1648
- _refreshDrawing(e, t, n) {
1649
- const r = t == null ? void 0 : t.getSkeletonData(), { mainComponent: o, scene: s } = n, a = o;
1650
- if (!r)
2209
+ _refreshDrawing(e) {
2210
+ const t = e == null ? void 0 : e.getSkeletonData(), { mainComponent: o, scene: i, unitId: r } = this._context, s = o;
2211
+ if (!t)
1651
2212
  return;
1652
- const { left: c, top: l, pageLayoutType: u, pageMarginLeft: h, pageMarginTop: m } = a, { pages: p } = r, S = [];
1653
- s.getAncestorScale(), this._liquid.reset(), this._pageMarginCache.clear();
1654
- for (let d = 0, _ = p.length; d < _; d++) {
1655
- const R = p[d], { skeDrawings: D, marginLeft: $, marginTop: H } = R;
1656
- this._liquid.translatePagePadding(R), D.forEach((j) => {
1657
- const { aLeft: te, aTop: ne, height: Ve, width: je, drawingId: ie, drawingOrigin: ot } = j, Vt = ot.layoutType === Xt.WRAP_NONE && ot.behindDoc === C.TRUE;
1658
- S.push({
1659
- unitId: e,
1660
- subUnitId: Kt,
1661
- floatingObjectId: ie,
1662
- behindText: Vt,
2213
+ const { left: a, top: c, pageLayoutType: d, pageMarginLeft: p, pageMarginTop: g } = s, { pages: h } = t, l = [];
2214
+ i.getAncestorScale(), this._liquid.reset(), this._pageMarginCache.clear();
2215
+ for (let f = 0, u = h.length; f < u; f++) {
2216
+ const _ = h[f], { skeDrawings: m, marginLeft: O, marginTop: M } = _;
2217
+ this._liquid.translatePagePadding(_), m.forEach((I) => {
2218
+ const { aLeft: R, aTop: y, height: j, width: W, drawingId: $, drawingOrigin: mt } = I, Sn = mt.layoutType === yn.WRAP_NONE && mt.behindDoc === S.TRUE;
2219
+ l.push({
2220
+ unitId: r,
2221
+ subUnitId: Pn,
2222
+ floatingObjectId: $,
2223
+ behindText: Sn,
1663
2224
  floatingObject: {
1664
- left: te + c + this._liquid.x,
1665
- top: ne + l + this._liquid.y,
1666
- width: je,
1667
- height: Ve
2225
+ left: R + a + this._liquid.x,
2226
+ top: y + c + this._liquid.y,
2227
+ width: W,
2228
+ height: j
1668
2229
  }
1669
- }), this._pageMarginCache.set(ie, {
2230
+ }), this._pageMarginCache.set($, {
1670
2231
  marginLeft: this._liquid.x,
1671
2232
  marginTop: this._liquid.y
1672
2233
  });
1673
- }), this._liquid.restorePagePadding(R), this._liquid.translatePage(R, u, h, m);
2234
+ }), this._liquid.restorePagePadding(_), this._liquid.translatePage(_, d, p, g);
1674
2235
  }
1675
2236
  }
1676
2237
  };
1677
- Ie = Pr([
1678
- U(A.Steady, Ie),
1679
- me(0, O(ee)),
1680
- me(1, F),
1681
- me(2, v),
1682
- me(3, L)
1683
- ], Ie);
1684
- var Nr = Object.defineProperty, Ur = Object.getOwnPropertyDescriptor, Ar = (i, e, t, n) => {
1685
- for (var r = n > 1 ? void 0 : n ? Ur(e, t) : e, o = i.length - 1, s; o >= 0; o--)
1686
- (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
1687
- return n && r && Nr(e, t, r), r;
1688
- }, G = (i, e) => (t, n) => e(t, n, i);
1689
- let be = class extends k {
1690
- constructor(e, t, n, r, o, s) {
1691
- super();
1692
- g(this, "_initializedRender", /* @__PURE__ */ new Set());
1693
- this._docSkeletonManagerService = e, this._univerInstanceService = t, this._commandService = n, this._renderManagerService = r, this._textSelectionManagerService = o, this._editorService = s, this._initialize();
2238
+ ct = Dr([
2239
+ Je(1, T(N)),
2240
+ Je(2, C),
2241
+ Je(3, Y)
2242
+ ], ct);
2243
+ var Ar = Object.defineProperty, Fr = Object.getOwnPropertyDescriptor, Nr = (n, e, t, o) => {
2244
+ for (var i = o > 1 ? void 0 : o ? Fr(e, t) : e, r = n.length - 1, s; r >= 0; r--)
2245
+ (s = n[r]) && (i = (o ? s(e, t, i) : s(i)) || i);
2246
+ return o && i && Ar(e, t, i), i;
2247
+ }, fe = (n, e) => (t, o) => e(t, o, n);
2248
+ let lt = class extends K {
2249
+ constructor(n, e, t, o, i, r) {
2250
+ super(), this._context = n, this._docSkeletonManagerService = e, this._univerInstanceService = t, this._commandService = o, this._textSelectionManagerService = i, this._editorService = r, this._init();
1694
2251
  }
1695
- dispose() {
1696
- super.dispose();
1697
- }
1698
- _initialize() {
1699
- this._skeletonListener(), this._commandExecutedListener(), this._initialRenderRefresh();
2252
+ _init() {
2253
+ this._initSkeletonListener(), this._initCommandExecutedListener(), this._initRenderRefresher(), setTimeout(() => this._updateViewZoom(1, !0), 20);
1700
2254
  }
1701
- _initialRenderRefresh() {
1702
- this._docSkeletonManagerService.currentSkeleton$.subscribe((e) => {
1703
- if (e == null)
2255
+ _initRenderRefresher() {
2256
+ this._docSkeletonManagerService.currentSkeleton$.subscribe((n) => {
2257
+ if (n == null)
1704
2258
  return;
1705
- const { unitId: t } = e, n = this._renderManagerService.getRenderById(t);
1706
- if (n == null || this._initializedRender.has(t) || this._editorService.isEditor(t))
1707
- return;
1708
- this._initializedRender.add(t);
1709
- const { scene: r } = n;
1710
- this.disposeWithMe(
1711
- B(
1712
- r.onMouseWheelObserver.add((o) => {
1713
- if (!o.ctrlKey)
1714
- return;
1715
- const s = this._univerInstanceService.getCurrentUniverDocInstance();
1716
- if (!s)
1717
- return;
1718
- const a = Math.abs(o.deltaX);
1719
- let c = a < 40 ? 0.2 : a < 80 ? 0.4 : 0.2;
1720
- c *= o.deltaY > 0 ? -1 : 1, r.scaleX < 1 && (c /= 2);
1721
- const l = s.zoomRatio;
1722
- let u = +Number.parseFloat(`${l + c}`).toFixed(1);
1723
- u = u >= 4 ? 4 : u <= 0.1 ? 0.1 : u, this._commandService.executeCommand(Fn.id, {
1724
- zoomRatio: u,
1725
- unitId: s.getUnitId()
1726
- }), o.preventDefault();
1727
- })
1728
- )
1729
- );
2259
+ const { unitId: e, scene: t } = this._context;
2260
+ this._editorService.isEditor(e) || this.disposeWithMe(t.onMouseWheel$.subscribeEvent((o) => {
2261
+ if (!o.ctrlKey)
2262
+ return;
2263
+ const i = this._univerInstanceService.getCurrentUniverDocInstance();
2264
+ if (!i)
2265
+ return;
2266
+ const r = Math.abs(o.deltaX);
2267
+ let s = r < 40 ? 0.2 : r < 80 ? 0.4 : 0.2;
2268
+ s *= o.deltaY > 0 ? -1 : 1, t.scaleX < 1 && (s /= 2);
2269
+ const a = i.zoomRatio;
2270
+ let c = +Number.parseFloat(`${a + s}`).toFixed(1);
2271
+ c = c >= 4 ? 4 : c <= 0.1 ? 0.1 : c, this._commandService.executeCommand(Co.id, {
2272
+ zoomRatio: c,
2273
+ unitId: i.getUnitId()
2274
+ }), o.preventDefault();
2275
+ }));
1730
2276
  });
1731
2277
  }
1732
- // private _zoomEventBinding() {
1733
- // const scene = this._getDocObject()?.scene;
1734
- // if (scene == null) {
1735
- // return;
1736
- // }
1737
- // const viewportMain = scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);
1738
- // }
1739
- _skeletonListener() {
1740
- this.disposeWithMe(
1741
- B(
1742
- this._docSkeletonManagerService.currentSkeleton$.subscribe((e) => {
1743
- if (e == null)
1744
- return;
1745
- const t = this._univerInstanceService.getCurrentUniverDocInstance();
1746
- if (!t) return;
1747
- const n = t.zoomRatio || 1;
1748
- this._updateViewZoom(n, !1);
1749
- })
1750
- )
1751
- );
2278
+ _initSkeletonListener() {
2279
+ this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe((n) => {
2280
+ if (n == null)
2281
+ return;
2282
+ const e = this._univerInstanceService.getCurrentUniverDocInstance();
2283
+ if (!e) return;
2284
+ const t = e.zoomRatio || 1;
2285
+ this._updateViewZoom(t, !1);
2286
+ }));
1752
2287
  }
1753
- _commandExecutedListener() {
1754
- const e = [Le.id];
1755
- this.disposeWithMe(
1756
- this._commandService.onCommandExecuted((t) => {
1757
- if (e.includes(t.id)) {
1758
- const n = this._univerInstanceService.getCurrentUniverDocInstance();
1759
- if (!n) return;
1760
- const r = t.params, { unitId: o } = r;
1761
- if (o !== n.getUnitId())
1762
- return;
1763
- const s = n.zoomRatio || 1;
1764
- this._updateViewZoom(s);
1765
- }
1766
- })
1767
- );
2288
+ _initCommandExecutedListener() {
2289
+ const n = [ve.id];
2290
+ this.disposeWithMe(this._commandService.onCommandExecuted((e) => {
2291
+ if (n.includes(e.id)) {
2292
+ const t = this._univerInstanceService.getCurrentUniverDocInstance();
2293
+ if (!t) return;
2294
+ const o = e.params, { unitId: i } = o;
2295
+ if (i !== t.getUnitId())
2296
+ return;
2297
+ const r = t.zoomRatio || 1;
2298
+ this._updateViewZoom(r);
2299
+ }
2300
+ }));
1768
2301
  }
1769
- _updateViewZoom(e, t = !0) {
1770
- var r;
1771
- const n = this._getDocObject();
1772
- n != null && (n.scene.scale(e, e), this._calculatePagePosition(n, e), t && this._textSelectionManagerService.refreshSelection(), (r = n.scene.getTransformer()) == null || r.clearSelectedObjects());
2302
+ _updateViewZoom(n, e = !0) {
2303
+ var o;
2304
+ const t = Q(this._context);
2305
+ t.scene.scale(n, n), this._calculatePagePosition(t, n), e && this._textSelectionManagerService.refreshSelection(), (o = t.scene.getTransformer()) == null || o.clearSelectedObjects();
1773
2306
  }
1774
- _calculatePagePosition(e, t) {
1775
- const { document: n, scene: r, docBackground: o } = e, s = r == null ? void 0 : r.getParent(), { width: a, height: c, pageMarginLeft: l, pageMarginTop: u } = n;
1776
- if (s == null || a === Number.POSITIVE_INFINITY || c === Number.POSITIVE_INFINITY)
2307
+ _calculatePagePosition(n, e) {
2308
+ const { document: t, scene: o, docBackground: i } = n, r = o == null ? void 0 : o.getParent(), { width: s, height: a, pageMarginLeft: c, pageMarginTop: d } = t;
2309
+ if (r == null || s === Number.POSITIVE_INFINITY || a === Number.POSITIVE_INFINITY)
1777
2310
  return;
1778
- const { width: h, height: m } = s;
1779
- let p = 0, S = 0, d = 0, _ = 0, R = Number.POSITIVE_INFINITY;
1780
- h > (a + l * 2) * t ? (p = h / 2 - a * t / 2, p /= t, d = (h - l * 2) / t, R = 0) : (p = l, d = a + l * 2, R = (d - h / t) / 2), m > c ? (S = m / 2 - c / 2, _ = (m - u * 2) / t) : (S = u, _ = c + u * 2), r.resize(d, _ + 200), n.translate(p, S), o.translate(p, S);
1781
- const D = r.getViewport(Q.VIEW_MAIN);
1782
- if (R !== Number.POSITIVE_INFINITY && D != null) {
1783
- const $ = D.transViewportScroll2ScrollValue(R, 0).x;
1784
- D.scrollTo({
1785
- x: $
2311
+ const { width: p, height: g } = r;
2312
+ let h = 0, l = 0, f = 0, u = 0, _ = Number.POSITIVE_INFINITY;
2313
+ p > (s + c * 2) * e ? (h = p / 2 - s * e / 2, h /= e, f = (p - c * 2) / e, _ = 0) : (h = c, f = s + c * 2, _ = (f - p / e) / 2), g > a ? (l = g / 2 - a / 2, u = (g - d * 2) / e) : (l = d, u = a + d * 2), o.resize(f, u + 200), t.translate(h, l), i.translate(h, l);
2314
+ const m = o.getViewport(te.VIEW_MAIN);
2315
+ if (_ !== Number.POSITIVE_INFINITY && m != null) {
2316
+ const O = m.transViewportScroll2ScrollValue(_, 0).x;
2317
+ m.scrollTo({
2318
+ x: O
1786
2319
  });
1787
2320
  }
1788
2321
  return this;
1789
2322
  }
1790
- _getDocObject() {
1791
- return Nt(this._univerInstanceService, this._renderManagerService);
1792
- }
1793
2323
  };
1794
- be = Ar([
1795
- U(A.Rendered, be),
1796
- G(0, O(ee)),
1797
- G(1, P),
1798
- G(2, v),
1799
- G(3, F),
1800
- G(4, O(J)),
1801
- G(5, L)
1802
- ], be);
1803
- var Lr = Object.defineProperty, $r = Object.getOwnPropertyDescriptor, Br = (i, e, t, n) => {
1804
- for (var r = n > 1 ? void 0 : n ? $r(e, t) : e, o = i.length - 1, s; o >= 0; o--)
1805
- (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
1806
- return n && r && Lr(e, t, r), r;
1807
- }, z = (i, e) => (t, n) => e(t, n, i);
1808
- let Me = class extends k {
1809
- constructor(e, t, n, r, o, s, a) {
2324
+ lt = Nr([
2325
+ fe(1, T(N)),
2326
+ fe(2, L),
2327
+ fe(3, C),
2328
+ fe(4, T(ne)),
2329
+ fe(5, Y)
2330
+ ], lt);
2331
+ var Lr = Object.defineProperty, Ur = Object.getOwnPropertyDescriptor, wr = (n, e, t, o) => {
2332
+ for (var i = o > 1 ? void 0 : o ? Ur(e, t) : e, r = n.length - 1, s; r >= 0; r--)
2333
+ (s = n[r]) && (i = (o ? s(e, t, i) : s(i)) || i);
2334
+ return o && i && Lr(e, t, i), i;
2335
+ }, re = (n, e) => (t, o) => e(t, o, n);
2336
+ let dt = class extends K {
2337
+ constructor(e, t, o, i, r, s, a) {
1810
2338
  super();
1811
- g(this, "_loadedMap", /* @__PURE__ */ new WeakSet());
1812
- this._docSkeletonManagerService = e, this._univerInstanceService = t, this._commandService = n, this._renderManagerService = r, this._textSelectionRenderManager = o, this._textSelectionManagerService = s, this._editorService = a, this._initialize();
2339
+ E(this, "_loadedMap", /* @__PURE__ */ new WeakSet());
2340
+ this._context = e, this._commandService = t, this._editorService = o, this._instanceSrv = i, this._textSelectionRenderManager = r, this._docSkeletonManagerService = s, this._textSelectionManagerService = a, this._initialize();
1813
2341
  }
1814
2342
  _initialize() {
1815
2343
  this._init(), this._skeletonListener(), this._commandExecutedListener();
1816
2344
  }
1817
2345
  _init() {
1818
- this.disposeWithMe(
1819
- this._renderManagerService.currentRender$.subscribe((e) => {
1820
- this._create(e);
1821
- })
1822
- ), this._renderManagerService.getRenderAll().forEach((e, t) => {
1823
- this._create(t);
1824
- });
1825
- }
1826
- _create(e) {
1827
- if (e == null || this._univerInstanceService.getUniverDocInstance(e) == null)
1828
- return;
1829
- const t = this._getDocObjectById(e);
2346
+ const { unitId: e } = this._context, t = Q(this._context);
1830
2347
  t == null || t.document == null || this._loadedMap.has(t.document) || (this._initialMain(e), this._loadedMap.add(t.document));
1831
2348
  }
1832
2349
  // eslint-disable-next-line max-lines-per-function
1833
2350
  _initialMain(e) {
1834
- const t = this._getDocObjectById(e);
1835
- if (t == null)
2351
+ const t = Q(this._context), { document: o, scene: i } = t;
2352
+ this.disposeWithMe(o.onPointerEnter$.subscribeEvent(() => {
2353
+ this._isEditorReadOnly(e) || (o.cursor = xt.TEXT);
2354
+ })), this.disposeWithMe(o.onPointerLeave$.subscribeEvent(() => {
2355
+ o.cursor = xt.DEFAULT, i.resetCursor();
2356
+ })), this.disposeWithMe(o.onPointerDown$.subscribeEvent((r, s) => {
2357
+ if (this._isEditorReadOnly(e))
2358
+ return;
2359
+ const a = this._instanceSrv.getCurrentUnitForType(v.UNIVER_DOC);
2360
+ (a == null ? void 0 : a.getUnitId()) !== e && this._instanceSrv.setCurrentUnitForType(e);
2361
+ const c = this._docSkeletonManagerService.getSkeleton(), { offsetX: d, offsetY: p } = r, g = this._getTransformCoordForDocumentOffset(d, p);
2362
+ if (g != null) {
2363
+ const {
2364
+ pageLayoutType: h = De.VERTICAL,
2365
+ pageMarginLeft: l,
2366
+ pageMarginTop: f
2367
+ } = o.getOffsetConfig(), { editArea: u } = c.findEditAreaByCoord(
2368
+ g,
2369
+ h,
2370
+ l,
2371
+ f
2372
+ ), _ = this._docSkeletonManagerService.getViewModel(), m = _.getEditArea();
2373
+ m !== F.BODY && u !== F.BODY && u !== m && _.setEditArea(u);
2374
+ }
2375
+ if (this._textSelectionRenderManager.eventTrigger(r), this._editorService.getEditor(e)) {
2376
+ this._setEditorFocus(e);
2377
+ const { offsetX: h, offsetY: l } = r;
2378
+ setTimeout(() => {
2379
+ this._setEditorFocus(e), this._textSelectionRenderManager.setCursorManually(h, l);
2380
+ }, 0);
2381
+ }
2382
+ r.button !== 2 && s.stopPropagation();
2383
+ })), this.disposeWithMe(o.onDblclick$.subscribeEvent((r) => {
2384
+ this._isEditorReadOnly(e) || this._textSelectionRenderManager.handleDblClick(r);
2385
+ })), this.disposeWithMe(o.onTripleClick$.subscribeEvent((r) => {
2386
+ this._isEditorReadOnly(e) || this._textSelectionRenderManager.handleTripleClick(r);
2387
+ }));
2388
+ }
2389
+ _getTransformCoordForDocumentOffset(e, t) {
2390
+ const o = Q(this._context), { document: i, scene: r } = o, { documentTransform: s } = i.getOffsetConfig(), a = r.getViewports()[0];
2391
+ if (a == null)
1836
2392
  return;
1837
- const { document: n, scene: r } = t;
1838
- this.disposeWithMe(
1839
- B(
1840
- n.onPointerEnterObserver.add(() => {
1841
- this._isEditorReadOnly(e) || (n.cursor = gt.TEXT);
1842
- })
1843
- )
1844
- ), this.disposeWithMe(
1845
- B(
1846
- n.onPointerLeaveObserver.add(() => {
1847
- n.cursor = gt.DEFAULT, r.resetCursor();
1848
- })
1849
- )
1850
- ), this.disposeWithMe(
1851
- B(
1852
- n == null ? void 0 : n.onPointerDownObserver.add((o, s) => {
1853
- if (this._isEditorReadOnly(e))
1854
- return;
1855
- const a = this._univerInstanceService.getCurrentUniverDocInstance();
1856
- (a == null ? void 0 : a.getUnitId()) !== e && this._univerInstanceService.setCurrentUnitForType(e), this._textSelectionRenderManager.eventTrigger(o);
1857
- const { offsetX: c, offsetY: l } = o;
1858
- this._editorService.getEditor(e) && (this._setEditorFocus(e), setTimeout(() => {
1859
- this._setEditorFocus(e), this._textSelectionRenderManager.setCursorManually(c, l);
1860
- }, 0)), o.button !== 2 && s.stopPropagation();
1861
- })
1862
- )
1863
- ), this.disposeWithMe(
1864
- B(
1865
- n == null ? void 0 : n.onDblclickObserver.add((o) => {
1866
- this._isEditorReadOnly(e) || this._textSelectionRenderManager.handleDblClick(o);
1867
- })
1868
- )
1869
- ), this.disposeWithMe(
1870
- B(
1871
- n == null ? void 0 : n.onTripleClickObserver.add((o) => {
1872
- this._isEditorReadOnly(e) || this._textSelectionRenderManager.handleTripleClick(o);
1873
- })
1874
- )
1875
- );
2393
+ const c = a.transformVector2SceneCoord(sn.FromArray([e, t]));
2394
+ return s.clone().invert().applyPoint(c);
1876
2395
  }
1877
2396
  _isEditorReadOnly(e) {
1878
2397
  const t = this._editorService.getEditor(e);
1879
2398
  return t ? t.isReadOnly() : !1;
1880
2399
  }
1881
2400
  _setEditorFocus(e) {
1882
- if (this._univerInstanceService.getAllUnitsForType(f.UNIVER_SHEET).length > 0) {
1883
- const n = this._univerInstanceService.getCurrentUnitForType(f.UNIVER_SHEET);
1884
- this._editorService.setOperationSheetUnitId(n.getUnitId());
1885
- }
1886
2401
  this._editorService.focusStyle(e);
1887
2402
  }
1888
2403
  _commandExecutedListener() {
1889
- const e = [Le.id];
2404
+ const e = [ve.id];
1890
2405
  this.disposeWithMe(
1891
2406
  this._commandService.onCommandExecuted((t) => {
1892
- var n;
2407
+ var o;
1893
2408
  if (e.includes(t.id)) {
1894
- const r = t.params, { unitId: o } = r, s = (n = this._textSelectionManagerService.getCurrentSelection()) == null ? void 0 : n.unitId;
1895
- if (o !== s)
2409
+ const i = t.params, { unitId: r } = i, s = (o = this._textSelectionManagerService.getCurrentSelection()) == null ? void 0 : o.unitId;
2410
+ if (r !== s)
1896
2411
  return;
1897
2412
  this._textSelectionManagerService.refreshSelection();
1898
2413
  }
@@ -1904,14 +2419,11 @@ let Me = class extends k {
1904
2419
  this._docSkeletonManagerService.currentSkeleton$.subscribe((e) => {
1905
2420
  if (e == null)
1906
2421
  return;
1907
- const { unitId: t, skeleton: n } = e, r = this._renderManagerService.getRenderById(t);
1908
- if (r == null)
1909
- return;
1910
- const { scene: o, mainComponent: s } = r;
1911
- this._textSelectionRenderManager.changeRuntime(n, o, s), this._textSelectionManagerService.setCurrentSelectionNotRefresh({
1912
- unitId: t,
2422
+ const { scene: t, mainComponent: o, unitId: i } = this._context;
2423
+ this._textSelectionRenderManager.changeRuntime(e, t, o), this._textSelectionManagerService.setCurrentSelectionNotRefresh({
2424
+ unitId: i,
1913
2425
  subUnitId: ""
1914
- }), this._editorService.isEditor(t) || this._textSelectionManagerService.replaceTextRanges([
2426
+ }), this._editorService.isEditor(i) || this._textSelectionManagerService.replaceTextRanges([
1915
2427
  {
1916
2428
  startOffset: 0,
1917
2429
  endOffset: 0
@@ -1920,131 +2432,102 @@ let Me = class extends k {
1920
2432
  })
1921
2433
  );
1922
2434
  }
1923
- _getDocObjectById(e) {
1924
- return this._univerInstanceService.getUnitType(e) !== f.UNIVER_DOC ? null : Vn(e, this._renderManagerService);
1925
- }
1926
- };
1927
- Me = Br([
1928
- U(A.Rendered, Me),
1929
- z(0, O(ee)),
1930
- z(1, P),
1931
- z(2, v),
1932
- z(3, F),
1933
- z(4, he),
1934
- z(5, O(J)),
1935
- z(6, L)
1936
- ], Me);
1937
- var wr = Object.defineProperty, Fr = Object.getOwnPropertyDescriptor, Vr = (i, e, t, n) => {
1938
- for (var r = n > 1 ? void 0 : n ? Fr(e, t) : e, o = i.length - 1, s; o >= 0; o--)
1939
- (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
1940
- return n && r && wr(e, t, r), r;
1941
- }, se = (i, e) => (t, n) => e(t, n, i);
1942
- const Rt = 1.5;
1943
- let ye = class extends de {
1944
- constructor(i, e, t, n, r) {
1945
- super(), this._docSkeletonManagerService = i, this._textSelectionManagerService = e, this._editorService = t, this._univerInstanceService = n, this._renderManagerService = r, this._init();
1946
- }
1947
- _init() {
1948
- this._textSelectionManagerService.textSelection$.pipe(le(this.dispose$)).subscribe((i) => {
1949
- if (i == null)
1950
- return;
1951
- const { isEditing: e, unitId: t } = i;
1952
- e && this._scrollToSelection(t);
1953
- });
1954
- }
1955
- // Let the selection show on the current screen.
1956
- _scrollToSelection(i) {
1957
- var ie;
1958
- const e = this._textSelectionManagerService.getActiveRange(), t = this._getDocObject(), n = (ie = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : ie.skeleton;
1959
- if (e == null || t == null || n == null)
1960
- return;
1961
- const { collapsed: r, startNodePosition: o } = e;
1962
- if (!r)
1963
- return;
1964
- const s = t.document.getOffsetConfig(), { docsLeft: a, docsTop: c } = s, l = new Xn(s, n), { contentBoxPointGroup: u } = l.getRangePointData(o, o), { left: h, top: m, height: p } = Kn(u), S = h + a, d = m + c, _ = t.scene.getViewport(Q.VIEW_MAIN), R = !!this._editorService.getEditor(i);
1965
- if (_ == null)
1966
- return;
1967
- const {
1968
- left: D,
1969
- top: $,
1970
- right: H,
1971
- bottom: j
1972
- } = _.getBounding().viewBound;
1973
- let te = 0, ne = 0;
1974
- const Ve = R ? 0 : 100;
1975
- d < $ ? te = d - $ : d > j - p && (te = d - j + p + Ve), S < D ? ne = S - D : S > H - Rt && (ne = S - H + Rt);
1976
- const je = _.transViewportScroll2ScrollValue(ne, te);
1977
- _.scrollBy(je);
1978
- }
1979
- _getDocObject() {
1980
- return Nt(this._univerInstanceService, this._renderManagerService);
1981
- }
1982
2435
  };
1983
- ye = Vr([
1984
- U(A.Rendered, ye),
1985
- se(0, O(ee)),
1986
- se(1, O(J)),
1987
- se(2, L),
1988
- se(3, P),
1989
- se(4, F)
1990
- ], ye);
1991
- var jr = Object.defineProperty, Wr = Object.getOwnPropertyDescriptor, zr = (i, e, t, n) => {
1992
- for (var r = n > 1 ? void 0 : n ? Wr(e, t) : e, o = i.length - 1, s; o >= 0; o--)
1993
- (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
1994
- return n && r && jr(e, t, r), r;
1995
- }, Se = (i, e) => (t, n) => e(t, n, i);
1996
- function kr(i, e) {
1997
- const t = Tt(i.left, i.top, e), n = Tt(i.right, i.bottom, e);
2436
+ dt = wr([
2437
+ re(1, C),
2438
+ re(2, Y),
2439
+ re(3, L),
2440
+ re(4, oe),
2441
+ re(5, T(N)),
2442
+ re(6, T(ne))
2443
+ ], dt);
2444
+ var Br = Object.defineProperty, $r = Object.getOwnPropertyDescriptor, Hr = (n, e, t, o) => {
2445
+ for (var i = o > 1 ? void 0 : o ? $r(e, t) : e, r = n.length - 1, s; r >= 0; r--)
2446
+ (s = n[r]) && (i = (o ? s(e, t, i) : s(i)) || i);
2447
+ return o && i && Br(e, t, i), i;
2448
+ }, Ie = (n, e) => (t, o) => e(t, o, n);
2449
+ function zt(n, e) {
2450
+ const t = Gt(n.left, n.top, e), o = Gt(n.right, n.bottom, e);
1998
2451
  return {
1999
2452
  left: t.x,
2000
2453
  top: t.y,
2001
- right: n.x,
2002
- bottom: n.y
2454
+ right: o.x,
2455
+ bottom: o.y
2003
2456
  };
2004
2457
  }
2005
- function Tt(i, e, t) {
2006
- const { scaleX: n, scaleY: r } = t.getAncestorScale(), o = t.getViewport(Q.VIEW_MAIN);
2007
- if (!o)
2458
+ function Gt(n, e, t) {
2459
+ const { scaleX: o, scaleY: i } = t.getAncestorScale(), r = t.getViewport(te.VIEW_MAIN);
2460
+ if (!r)
2008
2461
  return {
2009
- x: i,
2462
+ x: n,
2010
2463
  y: e
2011
2464
  };
2012
- const { viewportScrollX: s, viewportScrollY: a } = o, c = (i - s) * n, l = (e - a) * r;
2465
+ const { viewportScrollX: s, viewportScrollY: a } = r, c = (n - s) * o, d = (e - a) * i;
2013
2466
  return {
2014
2467
  x: c,
2015
- y: l
2468
+ y: d
2016
2469
  };
2017
2470
  }
2018
- let Ke = class extends k {
2019
- constructor(i, e, t, n) {
2020
- super(), this._globalPopupManagerService = i, this._renderManagerService = e, this._univerInstanceService = t, this._commandService = n;
2471
+ let ut = class extends K {
2472
+ constructor(n, e, t, o) {
2473
+ super(), this._globalPopupManagerService = n, this._renderManagerService = e, this._univerInstanceService = t, this._commandService = o;
2021
2474
  }
2022
2475
  // #region attach to object
2023
- _createObjectPositionObserver(i, e) {
2476
+ _createObjectPositionObserver(n, e) {
2024
2477
  const t = () => {
2025
- const { scene: a } = e, { left: c, top: l, width: u, height: h } = i, m = {
2478
+ const { scene: a } = e, { left: c, top: d, width: p, height: g } = n, h = {
2026
2479
  left: c,
2027
- right: c + u,
2028
- top: l,
2029
- bottom: l + h
2030
- }, p = kr(m, a);
2480
+ right: c + p,
2481
+ top: d,
2482
+ bottom: d + g
2483
+ }, l = zt(h, a);
2031
2484
  return {
2032
- left: p.left,
2033
- right: p.right,
2034
- top: p.top,
2035
- bottom: p.bottom
2485
+ left: l.left,
2486
+ right: l.right,
2487
+ top: l.top,
2488
+ bottom: l.bottom
2036
2489
  };
2037
- }, n = t(), r = new Ut(n), o = new Zt();
2038
- o.add(this._commandService.onCommandExecuted((a) => {
2039
- a.id === Le.id && r.next(t());
2490
+ }, o = t(), i = new Pt(o), r = new vt();
2491
+ r.add(this._commandService.onCommandExecuted((a) => {
2492
+ a.id === ve.id && i.next(t());
2493
+ }));
2494
+ const s = e.scene.getViewport(te.VIEW_MAIN);
2495
+ return s && r.add(s.onScrollAfter$.subscribeEvent(() => {
2496
+ i.next(t());
2497
+ })), {
2498
+ position: o,
2499
+ position$: i,
2500
+ disposable: r
2501
+ };
2502
+ }
2503
+ _createRangePositionObserver(n, e) {
2504
+ var a;
2505
+ const t = () => {
2506
+ const { scene: c, mainComponent: d } = e, p = e.with(N).getSkeleton(), g = p.findNodePositionByCharIndex(n.startOffset), h = p.findNodePositionByCharIndex(n.endOffset), l = d;
2507
+ if (!h || !g)
2508
+ return;
2509
+ const f = l.getOffsetConfig(), { docsLeft: u, docsTop: _ } = f, m = new rn(f, p), { borderBoxPointGroup: O } = m.getRangePointData(g, h);
2510
+ return Do(O).map((R) => zt(R, c)).map((R) => ({
2511
+ left: R.left + u,
2512
+ right: R.right + u,
2513
+ top: R.top + _,
2514
+ bottom: R.bottom + _
2515
+ }));
2516
+ }, o = (a = t()) != null ? a : [], i = new Pt(o), r = new vt();
2517
+ r.add(this._commandService.onCommandExecuted((c) => {
2518
+ if (c.id === ve.id) {
2519
+ const d = t();
2520
+ d && i.next(d);
2521
+ }
2040
2522
  }));
2041
- const s = e.scene.getViewport(Q.VIEW_MAIN);
2042
- return o.add(s == null ? void 0 : s.onScrollAfterObserver.add(() => {
2043
- r.next(t());
2523
+ const s = e.scene.getViewport(te.VIEW_MAIN);
2524
+ return s && r.add(s.onScrollAfter$.subscribeEvent(() => {
2525
+ const c = t();
2526
+ c && i.next(c);
2044
2527
  })), {
2045
- position: n,
2046
- position$: r,
2047
- disposable: o
2528
+ positions: o,
2529
+ positions$: i,
2530
+ disposable: r
2048
2531
  };
2049
2532
  }
2050
2533
  /**
@@ -2053,18 +2536,18 @@ let Ke = class extends k {
2053
2536
  * @param popup popup item
2054
2537
  * @returns disposable
2055
2538
  */
2056
- attachPopupToObject(i, e) {
2057
- const n = this._univerInstanceService.getCurrentUnitForType(f.UNIVER_DOC).getUnitId(), r = this._renderManagerService.getRenderById(n);
2058
- if (!r)
2539
+ attachPopupToObject(n, e) {
2540
+ const o = this._univerInstanceService.getCurrentUnitForType(v.UNIVER_DOC).getUnitId(), i = this._renderManagerService.getRenderById(o);
2541
+ if (!i)
2059
2542
  return {
2060
2543
  dispose: () => {
2061
2544
  }
2062
2545
  };
2063
- const { position: o, position$: s, disposable: a } = this._createObjectPositionObserver(i, r), c = this._globalPopupManagerService.addPopup({
2546
+ const { position: r, position$: s, disposable: a } = this._createObjectPositionObserver(n, i), c = this._globalPopupManagerService.addPopup({
2064
2547
  ...e,
2065
- unitId: n,
2548
+ unitId: o,
2066
2549
  subUnitId: "default",
2067
- anchorRect: o,
2550
+ anchorRect: r,
2068
2551
  anchorRect$: s
2069
2552
  });
2070
2553
  return {
@@ -2073,135 +2556,192 @@ let Ke = class extends k {
2073
2556
  }
2074
2557
  };
2075
2558
  }
2559
+ attachPopupToRange(n, e) {
2560
+ const o = this._univerInstanceService.getCurrentUnitForType(v.UNIVER_DOC).getUnitId(), { direction: i = "top" } = e, r = this._renderManagerService.getRenderById(o);
2561
+ if (!r)
2562
+ return {
2563
+ dispose: () => {
2564
+ }
2565
+ };
2566
+ const { positions: s, positions$: a, disposable: c } = this._createRangePositionObserver(n, r), d = a.pipe(Fo((g) => i === "top" ? g[0] : g[g.length - 1])), p = this._globalPopupManagerService.addPopup({
2567
+ ...e,
2568
+ unitId: o,
2569
+ subUnitId: "default",
2570
+ anchorRect: i === "top" ? s[0] : s[s.length - 1],
2571
+ anchorRect$: d,
2572
+ excludeRects: s,
2573
+ excludeRects$: a,
2574
+ direction: i === "top" ? "top" : "bottom"
2575
+ });
2576
+ return {
2577
+ dispose: () => {
2578
+ this._globalPopupManagerService.removePopup(p), a.complete(), c.dispose();
2579
+ }
2580
+ };
2581
+ }
2582
+ };
2583
+ ut = Hr([
2584
+ Ie(0, T(Kn)),
2585
+ Ie(1, k),
2586
+ Ie(2, L),
2587
+ Ie(3, C)
2588
+ ], ut);
2589
+ var Vr = Object.defineProperty, jr = Object.getOwnPropertyDescriptor, Wr = (n, e, t, o) => {
2590
+ for (var i = o > 1 ? void 0 : o ? jr(e, t) : e, r = n.length - 1, s; r >= 0; r--)
2591
+ (s = n[r]) && (i = (o ? s(e, t, i) : s(i)) || i);
2592
+ return o && i && Vr(e, t, i), i;
2593
+ }, Yt = (n, e) => (t, o) => e(t, o, n);
2594
+ let Pe = class extends Oe {
2595
+ constructor(n, e) {
2596
+ super(), this._instanceSrv = n, this._renderManagerService = e, this._init();
2597
+ }
2598
+ _init() {
2599
+ this._renderManagerService.createRender$.pipe(se(this.dispose$)).subscribe((n) => this._createRenderWithId(n)), this._instanceSrv.getTypeOfUnitAdded$(v.UNIVER_DOC).pipe(se(this.dispose$)).subscribe((n) => this._createRenderer(n)), this._instanceSrv.getAllUnitsForType(v.UNIVER_DOC).forEach((n) => this._createRenderer(n)), this._instanceSrv.getTypeOfUnitDisposed$(v.UNIVER_DOC).pipe(se(this.dispose$)).subscribe((n) => this._disposeRenderer(n));
2600
+ }
2601
+ _createRenderer(n) {
2602
+ const e = n.getUnitId();
2603
+ this._renderManagerService.has(e) || (this._createRenderWithId(e), this._renderManagerService.setCurrent(e));
2604
+ }
2605
+ _createRenderWithId(n) {
2606
+ this._renderManagerService.createRender(n);
2607
+ }
2608
+ _disposeRenderer(n) {
2609
+ const e = n.getUnitId();
2610
+ this._renderManagerService.removeRender(e);
2611
+ }
2076
2612
  };
2077
- Ke = zr([
2078
- Se(0, O(mn)),
2079
- Se(1, F),
2080
- Se(2, P),
2081
- Se(3, v)
2082
- ], Ke);
2083
- var Hr = Object.defineProperty, Yr = Object.getOwnPropertyDescriptor, Gr = (i, e, t, n) => {
2084
- for (var r = n > 1 ? void 0 : n ? Yr(e, t) : e, o = i.length - 1, s; o >= 0; o--)
2085
- (s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
2086
- return n && r && Hr(e, t, r), r;
2087
- }, ke = (i, e) => (t, n) => e(t, n, i), ve;
2088
- let It = (ve = class extends qt {
2089
- constructor(i, e, t, n) {
2090
- super(), this._config = i, this._injector = e, this._localeService = t, this._logService = n, this._config = Je.deepMerge({}, ei, this._config), this._initDependencies(e), this._initializeCommands();
2613
+ Pe = Wr([
2614
+ Ue(we.Ready, Pe),
2615
+ Yt(0, L),
2616
+ Yt(1, k)
2617
+ ], Pe);
2618
+ var kr = Object.defineProperty, zr = Object.getOwnPropertyDescriptor, Gr = (n, e, t, o) => {
2619
+ for (var i = o > 1 ? void 0 : o ? zr(e, t) : e, r = n.length - 1, s; r >= 0; r--)
2620
+ (s = n[r]) && (i = (o ? s(e, t, i) : s(i)) || i);
2621
+ return o && i && kr(e, t, i), i;
2622
+ }, Qe = (n, e) => (t, o) => e(t, o, n), be;
2623
+ let Xt = (be = class extends Dn {
2624
+ constructor(n, e, t, o) {
2625
+ super(), this._config = n, this._injector = e, this._renderManagerSrv = t, this._logService = o, this._config = ee.deepMerge({}, ci, this._config), this._initDependencies(e), this._initializeCommands();
2626
+ }
2627
+ onReady() {
2628
+ this._initRenderBasics();
2091
2629
  }
2092
2630
  onRendered() {
2093
- this._initModules(), this._markDocAsFocused();
2631
+ this._initUI(), this._initRenderModules(), this._markDocAsFocused();
2094
2632
  }
2095
2633
  _initializeCommands() {
2096
2634
  [
2097
- ii,
2098
- ri,
2099
- si,
2100
- oi,
2101
- ai,
2102
- ci,
2103
- li,
2104
2635
  di,
2105
2636
  ui,
2106
- Ki,
2107
- Zi,
2108
- Xi
2109
- ].forEach((i) => {
2110
- this._injector.get(Sn).registerShortcut(i);
2637
+ gi,
2638
+ hi,
2639
+ pi,
2640
+ _i,
2641
+ fi,
2642
+ mi,
2643
+ Si,
2644
+ _r,
2645
+ fr,
2646
+ pr
2647
+ ].forEach((n) => {
2648
+ this._injector.get(Zn).registerShortcut(n);
2111
2649
  });
2112
2650
  }
2113
- _initDependencies(i) {
2651
+ _initDependencies(n) {
2114
2652
  [
2115
- // Controller
2116
- [
2117
- ce,
2118
- {
2119
- useFactory: () => this._injector.createInstance(ce, this._config)
2120
- }
2121
- ],
2122
- [Ce],
2123
- [Oe],
2124
- [Re],
2125
- [Ie],
2126
- [be],
2127
- [Me],
2653
+ [Se, { useFactory: () => this._injector.createInstance(Se, this._config) }],
2654
+ [xe],
2128
2655
  [ye],
2129
- [
2130
- // controllers
2131
- ae,
2132
- {
2133
- useFactory: () => this._injector.createInstance(ae, this._config)
2134
- }
2135
- ],
2136
- [
2137
- pe,
2138
- {
2139
- useClass: Xe
2140
- }
2141
- ],
2142
- [Ke],
2143
- // Render views
2144
- [Te]
2145
- ].forEach((t) => {
2146
- i.add(t);
2147
- });
2656
+ [Pe],
2657
+ [me, { useFactory: () => this._injector.createInstance(me, this._config) }],
2658
+ [Ce, { useClass: ot }],
2659
+ [ut]
2660
+ ].forEach((t) => n.add(t));
2148
2661
  }
2149
2662
  _markDocAsFocused() {
2150
- const i = this._injector.get(P), e = this._injector.get(L);
2663
+ const n = this._injector.get(L), e = this._injector.get(Y);
2151
2664
  try {
2152
- const t = i.getCurrentUniverDocInstance();
2665
+ const t = n.getCurrentUnitForType(v.UNIVER_DOC);
2153
2666
  if (!t) return;
2154
- const n = t.getUnitId();
2155
- e.isEditor(n) || i.focusUnit(t.getUnitId());
2667
+ const o = t.getUnitId();
2668
+ e.isEditor(o) || n.focusUnit(t.getUnitId());
2156
2669
  } catch (t) {
2157
2670
  this._logService.warn(t);
2158
2671
  }
2159
2672
  }
2160
- _initModules() {
2161
- this._injector.get(ae);
2673
+ _initUI() {
2674
+ this._injector.get(me);
2675
+ }
2676
+ _initRenderBasics() {
2677
+ [
2678
+ N,
2679
+ Eo,
2680
+ at,
2681
+ lt
2682
+ ].forEach((n) => {
2683
+ this._renderManagerSrv.registerRenderModule(v.UNIVER_DOC, n);
2684
+ });
2685
+ }
2686
+ _initRenderModules() {
2687
+ [
2688
+ it,
2689
+ ct,
2690
+ dt,
2691
+ st
2692
+ ].forEach((n) => {
2693
+ this._renderManagerSrv.registerRenderModule(v.UNIVER_DOC, n);
2694
+ });
2162
2695
  }
2163
- }, g(ve, "pluginName", ti), g(ve, "type", f.UNIVER_DOC), ve);
2164
- It = Gr([
2165
- ke(1, O(Pe)),
2166
- ke(2, O(qe)),
2167
- ke(3, Et)
2168
- ], It);
2169
- function ro(i) {
2696
+ }, E(be, "pluginName", li), E(be, "type", v.UNIVER_DOC), be);
2697
+ Xt = Gr([
2698
+ Qe(1, T(Be)),
2699
+ Qe(2, k),
2700
+ Qe(3, Zt)
2701
+ ], Xt);
2702
+ function is(n) {
2170
2703
  return {
2171
- left: i.positionH.posOffset,
2172
- top: i.positionV.posOffset,
2173
- width: i.size.width,
2174
- height: i.size.height
2704
+ left: n.positionH.posOffset,
2705
+ top: n.positionV.posOffset,
2706
+ width: n.size.width,
2707
+ height: n.size.height
2175
2708
  };
2176
2709
  }
2177
- function oo(i, e = 0, t = 0) {
2710
+ function rs(n, e = 0, t = 0) {
2178
2711
  return {
2179
2712
  size: {
2180
- width: i.width,
2181
- height: i.height
2713
+ width: n.width,
2714
+ height: n.height
2182
2715
  },
2183
2716
  positionH: {
2184
- relativeFrom: Jt.MARGIN,
2185
- posOffset: (i.left || 0) - e
2717
+ relativeFrom: An.MARGIN,
2718
+ posOffset: (n.left || 0) - e
2186
2719
  },
2187
2720
  positionV: {
2188
- relativeFrom: Qt.PAGE,
2189
- posOffset: (i.top || 0) - t
2721
+ relativeFrom: Fn.PAGE,
2722
+ posOffset: (n.top || 0) - t
2190
2723
  },
2191
- angle: i.angle || 0
2724
+ angle: n.angle || 0
2192
2725
  };
2193
2726
  }
2194
2727
  export {
2195
- ti as DOC_UI_PLUGIN_NAME,
2196
- Qn as DefaultDocContainerConfig,
2197
- ei as DefaultDocUiConfig,
2198
- Jn as DefaultToolbarConfig,
2199
- Ke as DocCanvasPopManagerService,
2200
- Te as DocCanvasView,
2201
- rr as PastePluginLark,
2202
- cr as PastePluginUniver,
2203
- sr as PastePluginWord,
2204
- It as UniverDocsUIPlugin,
2205
- ro as docDrawingPositionToTransform,
2206
- oo as transformToDocDrawingPosition
2728
+ li as DOC_UI_PLUGIN_NAME,
2729
+ ai as DefaultDocContainerConfig,
2730
+ ci as DefaultDocUiConfig,
2731
+ si as DefaultToolbarConfig,
2732
+ it as DocBackScrollRenderController,
2733
+ ut as DocCanvasPopManagerService,
2734
+ mr as DocCopyCommand,
2735
+ Sr as DocCutCommand,
2736
+ vr as DocPasteCommand,
2737
+ at as DocRenderController,
2738
+ Pe as DocsRenderService,
2739
+ Ce as IDocClipboardService,
2740
+ Yo as PastePluginLark,
2741
+ qo as PastePluginUniver,
2742
+ Ko as PastePluginWord,
2743
+ Xt as UniverDocsUIPlugin,
2744
+ is as docDrawingPositionToTransform,
2745
+ rs as transformToDocDrawingPosition,
2746
+ z as whenDocAndEditorFocused
2207
2747
  };