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