@univerjs/docs-ui 0.1.0-beta.5 → 0.1.2

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,14 +1,16 @@
1
- var Le = Object.defineProperty;
2
- var Ne = (e, t, n) => t in e ? Le(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var h = (e, t, n) => (Ne(e, typeof t != "symbol" ? t + "" : t, n), n);
4
- import { FOCUSING_DOC as m, Direction as b, EDITOR_ACTIVATED as ge, LocaleService as ee, RxDisposable as Ce, ICommandService as _, BooleanNumber as u, UniverInstanceType as S, BaselineOffset as E, ThemeService as Ue, IUniverInstanceService as te, OnLifecycle as Se, LifecycleStages as Oe, Disposable as Te, Tools as ve, LRUMap as Fe, ColorKit as se, ILogService as Re, toDisposable as $e, CommandType as ne, IContextService as we, Plugin as Be, PluginType as je, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as He, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as Ve } from "@univerjs/core";
5
- import { Inject as y, Injector as Y, Optional as We, createIdentifier as ze } from "@wendellhu/redi";
6
- import { KeyCode as g, MetaKeys as w, LayoutService as Ye, MenuGroup as O, MenuItemType as T, MenuPosition as v, getMenuHiddenObservable as R, FONT_FAMILY_LIST as ae, FONT_SIZE_LIST as ke, ComponentManager as Ge, FontFamily as Ke, FontFamilyItem as Ze, FontSize as Xe, IShortcutService as ye, IMenuService as qe, IUIController as Je, IClipboardInterfaceService as oe, PLAIN_TEXT_CLIPBOARD_MIME_TYPE as Qe, HTML_CLIPBOARD_MIME_TYPE as et, CopyCommand as tt, CutCommand as nt, PasteCommand as ot } from "@univerjs/ui";
7
- import { MoveCursorOperation as k, MoveSelectionOperation as G, SelectAllOperation as rt, SetInlineFormatBoldCommand as it, SetTextSelectionsOperation as x, SetInlineFormatCommand as A, SetInlineFormatItalicCommand as st, SetInlineFormatUnderlineCommand as at, SetInlineFormatStrikethroughCommand as ct, SetInlineFormatSubscriptCommand as lt, SetInlineFormatSuperscriptCommand as dt, SetInlineFormatFontFamilyCommand as ce, SetInlineFormatFontSizeCommand as le, SetInlineFormatTextColorCommand as de, OrderListCommand as ut, BulletListCommand as pt, TextSelectionManagerService as Ie, BreakLineCommand as ht, DeleteLeftCommand as ft, DeleteRightCommand as mt, CutContentCommand as be, InnerPasteCommand as xe } from "@univerjs/docs";
8
- import { ITextSelectionRenderManager as De } from "@univerjs/engine-render";
9
- import { ColorPicker as _t } from "@univerjs/design";
10
- import { Observable as I, takeUntil as gt } from "rxjs";
11
- const Ct = {
1
+ var Et = Object.defineProperty;
2
+ var Dt = (i, e, t) => e in i ? Et(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var S = (i, e, t) => (Dt(i, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { FOCUSING_DOC as ye, FOCUSING_UNIVER_EDITOR as ze, FOCUSING_UNIVER_EDITOR_SINGLE_MODE as xt, Direction as j, EDITOR_ACTIVATED as _t, LocaleService as Ve, RxDisposable as ce, ICommandService as O, BooleanNumber as m, UniverInstanceType as I, BaselineOffset as K, ThemeService as Pt, IUniverInstanceService as M, OnLifecycle as P, LifecycleStages as U, Disposable as H, Tools as pt, LRUMap as Ut, ColorKit as qe, ILogService as gt, toDisposable as N, CommandType as ke, IContextService as Lt, IConfigService as Nt, DEFAULT_DOCUMENT_SUB_COMPONENT_ID as $t, IFloatingObjectManagerService as At, Plugin as wt, PluginType as Bt } from "@univerjs/core";
5
+ import { Inject as v, Injector as Ee, Optional as Ft, createIdentifier as jt } from "@wendellhu/redi";
6
+ import { KeyCode as T, MetaKeys as ae, ILayoutService as ft, MenuGroup as y, MenuItemType as E, MenuPosition as D, getMenuHiddenObservable as x, FONT_FAMILY_LIST as Ke, FONT_SIZE_LIST as Wt, ComponentManager as zt, FontFamily as Vt, FontFamilyItem as kt, FontSize as Ht, IEditorService as $, IMenuService as Yt, IUIController as Xt, IClipboardInterfaceService as He, PLAIN_TEXT_CLIPBOARD_MIME_TYPE as Gt, HTML_CLIPBOARD_MIME_TYPE as Zt, CopyCommand as qt, CutCommand as Kt, PasteCommand as Jt, SetEditorResizeOperation as Qt, IShortcutService as en } from "@univerjs/ui";
7
+ import { MoveCursorOperation as De, MoveSelectionOperation as xe, SelectAllOperation as tn, SetInlineFormatBoldCommand as nn, SetTextSelectionsOperation as W, SetInlineFormatCommand as J, SetInlineFormatItalicCommand as rn, SetInlineFormatUnderlineCommand as on, SetInlineFormatStrikethroughCommand as sn, SetInlineFormatSubscriptCommand as cn, SetInlineFormatSuperscriptCommand as an, SetInlineFormatFontFamilyCommand as Je, SetInlineFormatFontSizeCommand as Qe, SetInlineFormatTextColorCommand as et, OrderListCommand as ln, BulletListCommand as dn, TextSelectionManagerService as le, BreakLineCommand as un, DeleteLeftCommand as hn, DeleteRightCommand as _n, CutContentCommand as St, InnerPasteCommand as mt, DocSkeletonManagerService as Q, VIEWPORT_KEY as Pe, CoverContentCommand as pn, RichTextEditingMutation as Ye, DOCS_COMPONENT_MAIN_LAYER_INDEX as tt, DOCS_COMPONENT_HEADER_LAYER_INDEX as gn, DOCS_VIEW_KEY as nt, DOCS_COMPONENT_DEFAULT_Z_INDEX as fn, SetDocZoomRatioOperation as Xe, SetDocZoomRatioCommand as Sn, getDocObject as vt, getDocObjectById as mn } from "@univerjs/docs";
8
+ import { ITextSelectionRenderManager as de, ptToPixel as rt, ScrollBar as Fe, PageLayoutType as it, IRenderManagerService as Y, Viewport as vn, EVENT_TYPE as Cn, Layer as ot, Documents as On, Liquid as Rn, Rect as bn, CURSOR_TYPE as st, NodePositionConvertToCursor as In, getAnchorBounding as Tn } from "@univerjs/engine-render";
9
+ import { connectInjector as Mn } from "@wendellhu/redi/react-bindings";
10
+ import { ColorPicker as yn } from "@univerjs/design";
11
+ import En from "react";
12
+ import { Observable as A, takeUntil as oe, BehaviorSubject as Dn } from "rxjs";
13
+ const xn = {
12
14
  undo: !0,
13
15
  redo: !0,
14
16
  // Undo redo
@@ -36,7 +38,7 @@ const Ct = {
36
38
  // 'Wrap mode'
37
39
  textRotateMode: !0
38
40
  // 'Text Rotation Mode'
39
- }, St = {
41
+ }, Pn = {
40
42
  outerLeft: !1,
41
43
  outerRight: !1,
42
44
  header: !0,
@@ -49,83 +51,90 @@ const Ct = {
49
51
  frozenContent: !1,
50
52
  infoBar: !0,
51
53
  toolbar: !0
52
- }, Ot = {
54
+ }, Un = {
53
55
  layout: {
54
- docContainerConfig: St,
55
- toolbarConfig: Ct
56
+ docContainerConfig: Pn,
57
+ toolbarConfig: xn
56
58
  }
57
- }, Tt = "DocUI", vt = {
58
- id: k.id,
59
- binding: g.ARROW_UP,
60
- preconditions: (e) => e.getContextValue(m),
59
+ }, Ln = "DocUI";
60
+ function L(i) {
61
+ return i.getContextValue(ye) && i.getContextValue(ze);
62
+ }
63
+ function Nn(i) {
64
+ return i.getContextValue(ye) && i.getContextValue(ze) && !i.getContextValue(xt);
65
+ }
66
+ const $n = {
67
+ id: De.id,
68
+ binding: T.ARROW_UP,
69
+ preconditions: L,
61
70
  staticParameters: {
62
- direction: b.UP
71
+ direction: j.UP
63
72
  }
64
- }, Rt = {
65
- id: k.id,
66
- binding: g.ARROW_DOWN,
67
- preconditions: (e) => e.getContextValue(m),
73
+ }, An = {
74
+ id: De.id,
75
+ binding: T.ARROW_DOWN,
76
+ preconditions: L,
68
77
  staticParameters: {
69
- direction: b.DOWN
78
+ direction: j.DOWN
70
79
  }
71
- }, yt = {
72
- id: k.id,
73
- binding: g.ARROW_LEFT,
74
- preconditions: (e) => e.getContextValue(m),
80
+ }, wn = {
81
+ id: De.id,
82
+ binding: T.ARROW_LEFT,
83
+ preconditions: L,
75
84
  staticParameters: {
76
- direction: b.LEFT
85
+ direction: j.LEFT
77
86
  }
78
- }, It = {
79
- id: k.id,
80
- binding: g.ARROW_RIGHT,
81
- preconditions: (e) => e.getContextValue(m),
87
+ }, Bn = {
88
+ id: De.id,
89
+ binding: T.ARROW_RIGHT,
90
+ preconditions: L,
82
91
  staticParameters: {
83
- direction: b.RIGHT
92
+ direction: j.RIGHT
84
93
  }
85
- }, bt = {
86
- id: G.id,
87
- binding: g.ARROW_UP | w.SHIFT,
88
- preconditions: (e) => e.getContextValue(m),
94
+ }, Fn = {
95
+ id: xe.id,
96
+ binding: T.ARROW_UP | ae.SHIFT,
97
+ preconditions: L,
89
98
  staticParameters: {
90
- direction: b.UP
99
+ direction: j.UP
91
100
  }
92
- }, xt = {
93
- id: G.id,
94
- binding: g.ARROW_DOWN | w.SHIFT,
95
- preconditions: (e) => e.getContextValue(m),
101
+ }, jn = {
102
+ id: xe.id,
103
+ binding: T.ARROW_DOWN | ae.SHIFT,
104
+ preconditions: L,
96
105
  staticParameters: {
97
- direction: b.DOWN
106
+ direction: j.DOWN
98
107
  }
99
- }, Dt = {
100
- id: G.id,
101
- binding: g.ARROW_LEFT | w.SHIFT,
102
- preconditions: (e) => e.getContextValue(m),
108
+ }, Wn = {
109
+ id: xe.id,
110
+ binding: T.ARROW_LEFT | ae.SHIFT,
111
+ preconditions: L,
103
112
  staticParameters: {
104
- direction: b.LEFT
113
+ direction: j.LEFT
105
114
  }
106
- }, Pt = {
107
- id: G.id,
108
- binding: g.ARROW_RIGHT | w.SHIFT,
109
- preconditions: (e) => e.getContextValue(m),
115
+ }, zn = {
116
+ id: xe.id,
117
+ binding: T.ARROW_RIGHT | ae.SHIFT,
118
+ preconditions: L,
110
119
  staticParameters: {
111
- direction: b.RIGHT
120
+ direction: j.RIGHT
112
121
  }
113
- }, Mt = {
114
- id: rt.id,
115
- binding: g.A | w.CTRL_COMMAND,
116
- preconditions: (e) => e.getContextValue(m) || e.getContextValue(ge)
122
+ }, Vn = {
123
+ id: tn.id,
124
+ binding: T.A | ae.CTRL_COMMAND,
125
+ preconditions: (i) => i.getContextValue(ze) && (i.getContextValue(ye) || i.getContextValue(_t))
117
126
  };
118
- var Et = Object.defineProperty, At = Object.getOwnPropertyDescriptor, Lt = (e, t, n, o) => {
119
- for (var r = o > 1 ? void 0 : o ? At(t, n) : t, i = e.length - 1, s; i >= 0; i--)
120
- (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
121
- return o && r && Et(t, n, r), r;
122
- }, ue = (e, t) => (n, o) => t(n, o, e);
123
- let J = class {
124
- constructor(e, t, n) {
125
- h(this, "_docContainer");
127
+ var kn = Object.defineProperty, Hn = Object.getOwnPropertyDescriptor, Yn = (i, e, t, n) => {
128
+ for (var r = n > 1 ? void 0 : n ? Hn(e, t) : e, s = i.length - 1, o; s >= 0; s--)
129
+ (o = i[s]) && (r = (n ? o(e, t, r) : o(r)) || r);
130
+ return n && r && kn(e, t, r), r;
131
+ }, ct = (i, e) => (t, n) => e(t, n, i);
132
+ let je = class {
133
+ constructor(i, e, t) {
134
+ S(this, "_docContainer");
126
135
  // 获取SheetContainer组件
127
- h(this, "getComponent", (e) => {
128
- if (this._docContainer = e, !e.getContentRef().current)
136
+ S(this, "getComponent", (i) => {
137
+ if (this._docContainer = i, !i.getContentRef().current)
129
138
  throw new Error("container is not ready");
130
139
  });
131
140
  /**
@@ -135,10 +144,10 @@ let J = class {
135
144
  * e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771
136
145
  *
137
146
  */
138
- h(this, "changeLocale", (e) => {
139
- this._localeService.setLocale(e);
147
+ S(this, "changeLocale", (i) => {
148
+ this._localeService.setLocale(i);
140
149
  });
141
- this._config = e, this._localeService = t, this._injector = n;
150
+ this._config = i, this._localeService = e, this._injector = t;
142
151
  }
143
152
  getUIConfig() {
144
153
  return {
@@ -151,27 +160,27 @@ let J = class {
151
160
  getContentRef() {
152
161
  return this._docContainer.getContentRef();
153
162
  }
154
- UIDidMount(e) {
163
+ UIDidMount(i) {
155
164
  if (this._docContainer)
156
- return e(this._docContainer);
165
+ return i(this._docContainer);
157
166
  }
158
167
  getDocContainer() {
159
168
  return this._docContainer;
160
169
  }
161
170
  };
162
- J = Lt([
163
- ue(1, y(ee)),
164
- ue(2, y(Y))
165
- ], J);
166
- var Nt = Object.defineProperty, Ut = Object.getOwnPropertyDescriptor, Ft = (e, t, n, o) => {
167
- for (var r = o > 1 ? void 0 : o ? Ut(t, n) : t, i = e.length - 1, s; i >= 0; i--)
168
- (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
169
- return o && r && Nt(t, n, r), r;
170
- }, H = (e, t) => (n, o) => t(n, o, e);
171
- let F = class extends Ce {
172
- constructor(t, n, o, r, i) {
171
+ je = Yn([
172
+ ct(1, v(Ve)),
173
+ ct(2, v(Ee))
174
+ ], je);
175
+ var Xn = Object.defineProperty, Gn = Object.getOwnPropertyDescriptor, Zn = (i, e, t, n) => {
176
+ for (var r = n > 1 ? void 0 : n ? Gn(e, t) : e, s = i.length - 1, o; s >= 0; s--)
177
+ (o = i[s]) && (r = (n ? o(e, t, r) : o(r)) || r);
178
+ return n && r && Xn(e, t, r), r;
179
+ }, pe = (i, e) => (t, n) => e(t, n, i);
180
+ let ie = class extends ce {
181
+ constructor(e, t, n, r, s) {
173
182
  super();
174
- h(this, "_docContainerController");
183
+ S(this, "_docContainerController");
175
184
  /**
176
185
  * Change language
177
186
  * @param {string} locale new language
@@ -179,364 +188,409 @@ let F = class extends Ce {
179
188
  * e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771
180
189
  *
181
190
  */
182
- h(this, "changeLocale", (t) => {
183
- this._localeService.setLocale(t);
191
+ S(this, "changeLocale", (e) => {
192
+ this._localeService.setLocale(e);
184
193
  });
185
- this._localeService = n, this._injector = o, this._textSelectionRenderManager = r, this._layoutService = i, this._docContainerController = this._injector.createInstance(J, t), this._registerContainer();
194
+ this._localeService = t, this._injector = n, this._textSelectionRenderManager = r, this._layoutService = s, this._docContainerController = this._injector.createInstance(je, e), this._registerContainer();
186
195
  }
187
196
  _registerContainer() {
188
197
  this._layoutService && this.disposeWithMe(
189
198
  // the content editable div should be regarded as part of the applications container
190
- this._layoutService.registerContainer(this._textSelectionRenderManager.__getEditorContainer())
199
+ this._layoutService.registerContainerElement(this._textSelectionRenderManager.__getEditorContainer())
191
200
  );
192
201
  }
193
202
  getDocContainerController() {
194
203
  return this._docContainerController;
195
204
  }
196
205
  };
197
- F = Ft([
198
- H(1, y(ee)),
199
- H(2, y(Y)),
200
- H(3, De),
201
- H(4, We(Ye))
202
- ], F);
203
- const K = "UI_PLUGIN_DOCS", Pe = `${K}_COLOR_PICKER_COMPONENT`, Me = `${K}_FONT_FAMILY_COMPONENT`, Ee = `${K}_FONT_FAMILY_ITEM_COMPONENT`, Ae = `${K}_FONT_SIZE_COMPONENT`;
204
- function $t(e) {
205
- const t = e.get(_);
206
+ ie = Zn([
207
+ pe(1, v(Ve)),
208
+ pe(2, v(Ee)),
209
+ pe(3, de),
210
+ pe(4, Ft(ft))
211
+ ], ie);
212
+ const Ue = "UI_PLUGIN_DOCS", Ct = `${Ue}_COLOR_PICKER_COMPONENT`, Ot = `${Ue}_FONT_FAMILY_COMPONENT`, Rt = `${Ue}_FONT_FAMILY_ITEM_COMPONENT`, bt = `${Ue}_FONT_SIZE_COMPONENT`;
213
+ var It = { exports: {} }, Le = {};
214
+ /**
215
+ * @license React
216
+ * react-jsx-runtime.production.min.js
217
+ *
218
+ * Copyright (c) Facebook, Inc. and its affiliates.
219
+ *
220
+ * This source code is licensed under the MIT license found in the
221
+ * LICENSE file in the root directory of this source tree.
222
+ */
223
+ var qn = En, Kn = Symbol.for("react.element"), Jn = Symbol.for("react.fragment"), Qn = Object.prototype.hasOwnProperty, er = qn.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, tr = { key: !0, ref: !0, __self: !0, __source: !0 };
224
+ function Tt(i, e, t) {
225
+ var n, r = {}, s = null, o = null;
226
+ t !== void 0 && (s = "" + t), e.key !== void 0 && (s = "" + e.key), e.ref !== void 0 && (o = e.ref);
227
+ for (n in e)
228
+ Qn.call(e, n) && !tr.hasOwnProperty(n) && (r[n] = e[n]);
229
+ if (i && i.defaultProps)
230
+ for (n in e = i.defaultProps, e)
231
+ r[n] === void 0 && (r[n] = e[n]);
232
+ return { $$typeof: Kn, type: i, key: s, ref: o, props: r, _owner: er.current };
233
+ }
234
+ Le.Fragment = Jn;
235
+ Le.jsx = Tt;
236
+ Le.jsxs = Tt;
237
+ It.exports = Le;
238
+ var nr = It.exports;
239
+ const rr = "univer-docs-ui-canvas-background", ir = {
240
+ docsUiCanvasBackground: rr
241
+ }, or = () => /* @__PURE__ */ nr.jsx("div", { className: ir.docsUiCanvasBackground });
242
+ function sr(i) {
243
+ const e = i.get(O);
206
244
  return {
207
- id: it.id,
208
- group: O.TOOLBAR_FORMAT,
209
- type: T.BUTTON,
245
+ id: nn.id,
246
+ group: y.TOOLBAR_FORMAT,
247
+ type: E.BUTTON,
210
248
  icon: "BoldSingle",
211
249
  title: "Set bold",
212
250
  tooltip: "toolbar.bold",
213
- positions: [v.TOOLBAR_START],
214
- activated$: new I((n) => {
215
- const o = t.onCommandExecuted((r) => {
216
- var s;
217
- const i = r.id;
218
- if (i === x.id || i === A.id) {
219
- const a = D(e);
220
- if (a == null)
251
+ positions: [D.TOOLBAR_START],
252
+ activated$: new A((t) => {
253
+ const n = e.onCommandExecuted((r) => {
254
+ var o;
255
+ const s = r.id;
256
+ if (s === W.id || s === J.id) {
257
+ const c = z(i);
258
+ if (c == null)
221
259
  return;
222
- const c = (s = a.ts) == null ? void 0 : s.bl;
223
- n.next(c === u.TRUE);
260
+ const l = (o = c.ts) == null ? void 0 : o.bl;
261
+ t.next(l === m.TRUE);
224
262
  }
225
263
  });
226
- return n.next(!1), o.dispose;
264
+ return t.next(!1), n.dispose;
227
265
  }),
228
- hidden$: R(e, S.DOC)
266
+ hidden$: x(i, I.DOC)
229
267
  };
230
268
  }
231
- function wt(e) {
232
- const t = e.get(_);
269
+ function cr(i) {
270
+ const e = i.get(O);
233
271
  return {
234
- id: st.id,
235
- group: O.TOOLBAR_FORMAT,
236
- type: T.BUTTON,
272
+ id: rn.id,
273
+ group: y.TOOLBAR_FORMAT,
274
+ type: E.BUTTON,
237
275
  icon: "ItalicSingle",
238
276
  title: "Set italic",
239
277
  tooltip: "toolbar.italic",
240
- positions: [v.TOOLBAR_START],
241
- activated$: new I((n) => {
242
- const o = t.onCommandExecuted((r) => {
243
- var s;
244
- const i = r.id;
245
- if (i === x.id || i === A.id) {
246
- const a = D(e);
247
- if (a == null)
278
+ positions: [D.TOOLBAR_START],
279
+ activated$: new A((t) => {
280
+ const n = e.onCommandExecuted((r) => {
281
+ var o;
282
+ const s = r.id;
283
+ if (s === W.id || s === J.id) {
284
+ const c = z(i);
285
+ if (c == null)
248
286
  return;
249
- const c = (s = a.ts) == null ? void 0 : s.it;
250
- n.next(c === u.TRUE);
287
+ const l = (o = c.ts) == null ? void 0 : o.it;
288
+ t.next(l === m.TRUE);
251
289
  }
252
290
  });
253
- return n.next(!1), o.dispose;
291
+ return t.next(!1), n.dispose;
254
292
  }),
255
- hidden$: R(e, S.DOC)
293
+ hidden$: x(i, I.DOC)
256
294
  };
257
295
  }
258
- function Bt(e) {
259
- const t = e.get(_);
296
+ function ar(i) {
297
+ const e = i.get(O);
260
298
  return {
261
- id: at.id,
262
- group: O.TOOLBAR_FORMAT,
263
- type: T.BUTTON,
299
+ id: on.id,
300
+ group: y.TOOLBAR_FORMAT,
301
+ type: E.BUTTON,
264
302
  icon: "UnderlineSingle",
265
303
  title: "Set underline",
266
304
  tooltip: "toolbar.underline",
267
- positions: [v.TOOLBAR_START],
268
- activated$: new I((n) => {
269
- const o = t.onCommandExecuted((r) => {
270
- var s;
271
- const i = r.id;
272
- if (i === x.id || i === A.id) {
273
- const a = D(e);
274
- if (a == null)
305
+ positions: [D.TOOLBAR_START],
306
+ activated$: new A((t) => {
307
+ const n = e.onCommandExecuted((r) => {
308
+ var o;
309
+ const s = r.id;
310
+ if (s === W.id || s === J.id) {
311
+ const c = z(i);
312
+ if (c == null)
275
313
  return;
276
- const c = (s = a.ts) == null ? void 0 : s.ul;
277
- n.next((c == null ? void 0 : c.s) === u.TRUE);
314
+ const l = (o = c.ts) == null ? void 0 : o.ul;
315
+ t.next((l == null ? void 0 : l.s) === m.TRUE);
278
316
  }
279
317
  });
280
- return n.next(!1), o.dispose;
318
+ return t.next(!1), n.dispose;
281
319
  }),
282
- hidden$: R(e, S.DOC)
320
+ hidden$: x(i, I.DOC)
283
321
  };
284
322
  }
285
- function jt(e) {
286
- const t = e.get(_);
323
+ function lr(i) {
324
+ const e = i.get(O);
287
325
  return {
288
- id: ct.id,
289
- group: O.TOOLBAR_FORMAT,
290
- type: T.BUTTON,
326
+ id: sn.id,
327
+ group: y.TOOLBAR_FORMAT,
328
+ type: E.BUTTON,
291
329
  icon: "StrikethroughSingle",
292
330
  title: "Set strike through",
293
331
  tooltip: "toolbar.strikethrough",
294
- positions: [v.TOOLBAR_START],
295
- activated$: new I((n) => {
296
- const o = t.onCommandExecuted((r) => {
297
- var s;
298
- const i = r.id;
299
- if (i === x.id || i === A.id) {
300
- const a = D(e);
301
- if (a == null)
332
+ positions: [D.TOOLBAR_START],
333
+ activated$: new A((t) => {
334
+ const n = e.onCommandExecuted((r) => {
335
+ var o;
336
+ const s = r.id;
337
+ if (s === W.id || s === J.id) {
338
+ const c = z(i);
339
+ if (c == null)
302
340
  return;
303
- const c = (s = a.ts) == null ? void 0 : s.st;
304
- n.next((c == null ? void 0 : c.s) === u.TRUE);
341
+ const l = (o = c.ts) == null ? void 0 : o.st;
342
+ t.next((l == null ? void 0 : l.s) === m.TRUE);
305
343
  }
306
344
  });
307
- return n.next(!1), o.dispose;
345
+ return t.next(!1), n.dispose;
308
346
  }),
309
- hidden$: R(e, S.DOC)
347
+ hidden$: x(i, I.DOC)
310
348
  };
311
349
  }
312
- function Ht(e) {
313
- const t = e.get(_);
350
+ function dr(i) {
351
+ const e = i.get(O);
314
352
  return {
315
- id: lt.id,
316
- group: O.TOOLBAR_FORMAT,
317
- type: T.BUTTON,
353
+ id: cn.id,
354
+ group: y.TOOLBAR_FORMAT,
355
+ type: E.BUTTON,
318
356
  icon: "SubscriptSingle",
319
357
  tooltip: "toolbar.subscript",
320
- positions: [v.TOOLBAR_START],
321
- activated$: new I((n) => {
322
- const o = t.onCommandExecuted((r) => {
323
- var s;
324
- const i = r.id;
325
- if (i === x.id || i === A.id) {
326
- const a = D(e);
327
- if (a == null)
358
+ positions: [D.TOOLBAR_START],
359
+ activated$: new A((t) => {
360
+ const n = e.onCommandExecuted((r) => {
361
+ var o;
362
+ const s = r.id;
363
+ if (s === W.id || s === J.id) {
364
+ const c = z(i);
365
+ if (c == null)
328
366
  return;
329
- const c = (s = a.ts) == null ? void 0 : s.va;
330
- n.next(c === E.SUBSCRIPT);
367
+ const l = (o = c.ts) == null ? void 0 : o.va;
368
+ t.next(l === K.SUBSCRIPT);
331
369
  }
332
370
  });
333
- return n.next(!1), o.dispose;
371
+ return t.next(!1), n.dispose;
334
372
  }),
335
- hidden$: R(e, S.DOC)
373
+ hidden$: x(i, I.DOC)
336
374
  };
337
375
  }
338
- function Vt(e) {
339
- const t = e.get(_);
376
+ function ur(i) {
377
+ const e = i.get(O);
340
378
  return {
341
- id: dt.id,
342
- group: O.TOOLBAR_FORMAT,
343
- type: T.BUTTON,
379
+ id: an.id,
380
+ group: y.TOOLBAR_FORMAT,
381
+ type: E.BUTTON,
344
382
  icon: "SuperscriptSingle",
345
383
  tooltip: "toolbar.superscript",
346
- positions: [v.TOOLBAR_START],
347
- activated$: new I((n) => {
348
- const o = t.onCommandExecuted((r) => {
349
- var s;
350
- const i = r.id;
351
- if (i === x.id || i === A.id) {
352
- const a = D(e);
353
- if (a == null)
384
+ positions: [D.TOOLBAR_START],
385
+ activated$: new A((t) => {
386
+ const n = e.onCommandExecuted((r) => {
387
+ var o;
388
+ const s = r.id;
389
+ if (s === W.id || s === J.id) {
390
+ const c = z(i);
391
+ if (c == null)
354
392
  return;
355
- const c = (s = a.ts) == null ? void 0 : s.va;
356
- n.next(c === E.SUPERSCRIPT);
393
+ const l = (o = c.ts) == null ? void 0 : o.va;
394
+ t.next(l === K.SUPERSCRIPT);
357
395
  }
358
396
  });
359
- return n.next(!1), o.dispose;
397
+ return t.next(!1), n.dispose;
360
398
  }),
361
- hidden$: R(e, S.DOC)
399
+ hidden$: x(i, I.DOC)
362
400
  };
363
401
  }
364
- function Wt(e) {
365
- const t = e.get(_);
402
+ function hr(i) {
403
+ const e = i.get(O);
366
404
  return {
367
- id: ce.id,
405
+ id: Je.id,
368
406
  tooltip: "toolbar.font",
369
- group: O.TOOLBAR_FORMAT,
370
- type: T.SELECTOR,
371
- label: Me,
372
- positions: [v.TOOLBAR_START],
373
- selections: ae.map((n) => ({
407
+ group: y.TOOLBAR_FORMAT,
408
+ type: E.SELECTOR,
409
+ label: Ot,
410
+ positions: [D.TOOLBAR_START],
411
+ selections: Ke.map((t) => ({
374
412
  label: {
375
- name: Ee,
413
+ name: Rt,
376
414
  hoverable: !0
377
415
  },
378
- value: n.value
416
+ value: t.value
379
417
  })),
380
418
  // disabled$: getCurrentSheetDisabled$(accessor),
381
- value$: new I((n) => {
382
- const o = ae[0].value, r = t.onCommandExecuted((i) => {
383
- var a;
384
- const s = i.id;
385
- if (s === x.id || s === ce.id) {
386
- const c = D(e);
387
- if (c == null)
419
+ value$: new A((t) => {
420
+ const n = Ke[0].value, r = e.onCommandExecuted((s) => {
421
+ var c;
422
+ const o = s.id;
423
+ if (o === W.id || o === Je.id) {
424
+ const l = z(i);
425
+ if (l == null)
388
426
  return;
389
- const l = (a = c.ts) == null ? void 0 : a.ff;
390
- n.next(l != null ? l : o);
427
+ const d = (c = l.ts) == null ? void 0 : c.ff;
428
+ t.next(d != null ? d : n);
391
429
  }
392
430
  });
393
- return n.next(o), r.dispose;
431
+ return t.next(n), r.dispose;
394
432
  }),
395
- hidden$: R(e, S.DOC)
433
+ hidden$: x(i, I.DOC)
396
434
  };
397
435
  }
398
- function zt(e) {
399
- const t = e.get(_);
436
+ function _r(i) {
437
+ const e = i.get(O);
400
438
  return {
401
- id: le.id,
402
- group: O.TOOLBAR_FORMAT,
403
- type: T.SELECTOR,
439
+ id: Qe.id,
440
+ group: y.TOOLBAR_FORMAT,
441
+ type: E.SELECTOR,
404
442
  tooltip: "toolbar.fontSize",
405
443
  label: {
406
- name: Ae,
444
+ name: bt,
407
445
  props: {
408
446
  min: 1,
409
447
  max: 400
410
448
  // disabled$,
411
449
  }
412
450
  },
413
- positions: [v.TOOLBAR_START],
414
- selections: ke,
451
+ positions: [D.TOOLBAR_START],
452
+ selections: Wt,
415
453
  // disabled$,
416
- value$: new I((n) => {
417
- const r = t.onCommandExecuted((i) => {
418
- var a;
419
- const s = i.id;
420
- if (s === x.id || s === le.id) {
421
- const c = D(e);
422
- if (c == null)
454
+ value$: new A((t) => {
455
+ const r = e.onCommandExecuted((s) => {
456
+ var c;
457
+ const o = s.id;
458
+ if (o === W.id || o === Qe.id) {
459
+ const l = z(i);
460
+ if (l == null)
423
461
  return;
424
- const l = (a = c.ts) == null ? void 0 : a.fs;
425
- n.next(l != null ? l : 14);
462
+ const d = (c = l.ts) == null ? void 0 : c.fs;
463
+ t.next(d != null ? d : 14);
426
464
  }
427
465
  });
428
- return n.next(14), r.dispose;
466
+ return t.next(14), r.dispose;
429
467
  }),
430
- hidden$: R(e, S.DOC)
468
+ hidden$: x(i, I.DOC)
431
469
  };
432
470
  }
433
- function Yt(e) {
434
- const t = e.get(_), n = e.get(Ue);
471
+ function pr(i) {
472
+ const e = i.get(O), t = i.get(Pt);
435
473
  return {
436
- id: de.id,
474
+ id: et.id,
437
475
  icon: "FontColor",
438
476
  tooltip: "toolbar.textColor.main",
439
- group: O.TOOLBAR_FORMAT,
440
- type: T.BUTTON_SELECTOR,
441
- positions: [v.TOOLBAR_START],
477
+ group: y.TOOLBAR_FORMAT,
478
+ type: E.BUTTON_SELECTOR,
479
+ positions: [D.TOOLBAR_START],
442
480
  selections: [
443
481
  {
444
482
  label: {
445
- name: Pe,
483
+ name: Ct,
446
484
  hoverable: !1
447
485
  }
448
486
  }
449
487
  ],
450
- value$: new I((o) => {
451
- const r = n.getCurrentTheme().textColor, i = t.onCommandExecuted((s) => {
452
- if (s.id === de.id) {
453
- const a = s.params.value;
454
- o.next(a != null ? a : r);
488
+ value$: new A((n) => {
489
+ const r = t.getCurrentTheme().textColor, s = e.onCommandExecuted((o) => {
490
+ if (o.id === et.id) {
491
+ const c = o.params.value;
492
+ n.next(c != null ? c : r);
455
493
  }
456
494
  });
457
- return o.next(r), i.dispose;
495
+ return n.next(r), s.dispose;
458
496
  }),
459
- hidden$: R(e, S.DOC)
497
+ hidden$: x(i, I.DOC)
460
498
  // disabled$: getCurrentSheetDisabled$(accessor),
461
499
  };
462
500
  }
463
- function kt(e) {
501
+ function gr(i) {
464
502
  return {
465
- id: ut.id,
466
- group: O.TOOLBAR_LAYOUT,
467
- type: T.BUTTON,
503
+ id: ln.id,
504
+ group: y.TOOLBAR_LAYOUT,
505
+ type: E.BUTTON,
468
506
  icon: "OrderSingle",
469
507
  tooltip: "toolbar.order",
470
- positions: [v.TOOLBAR_START],
471
- hidden$: R(e, S.DOC)
508
+ positions: [D.TOOLBAR_START],
509
+ hidden$: x(i, I.DOC)
472
510
  };
473
511
  }
474
- function Gt(e) {
512
+ function fr(i) {
475
513
  return {
476
- id: pt.id,
477
- group: O.TOOLBAR_LAYOUT,
478
- type: T.BUTTON,
514
+ id: dn.id,
515
+ group: y.TOOLBAR_LAYOUT,
516
+ type: E.BUTTON,
479
517
  icon: "UnorderSingle",
480
518
  tooltip: "toolbar.unorder",
481
- positions: [v.TOOLBAR_START],
482
- hidden$: R(e, S.DOC)
519
+ positions: [D.TOOLBAR_START],
520
+ hidden$: x(i, I.DOC)
483
521
  };
484
522
  }
485
- function D(e) {
486
- var c;
487
- const t = e.get(te), n = e.get(Ie), o = t.getCurrentUniverDocInstance(), r = n.getActiveRange();
488
- if (o == null || r == null)
523
+ function z(i) {
524
+ var l;
525
+ const e = i.get(M), t = i.get(le), n = e.getCurrentUniverDocInstance(), r = t.getActiveRange();
526
+ if (n == null || r == null)
489
527
  return;
490
- const i = (c = o.getBody()) == null ? void 0 : c.textRuns;
491
- if (i == null)
528
+ const s = (l = n.getBody()) == null ? void 0 : l.textRuns;
529
+ if (s == null)
492
530
  return;
493
- const { startOffset: s } = r;
494
- return i.find(({ st: l, ed: p }) => s >= l && s < p);
531
+ const { startOffset: o } = r;
532
+ return s.find(({ st: d, ed: u }) => o >= d && o < u);
495
533
  }
496
- var Kt = Object.defineProperty, Zt = Object.getOwnPropertyDescriptor, Xt = (e, t, n, o) => {
497
- for (var r = o > 1 ? void 0 : o ? Zt(t, n) : t, i = e.length - 1, s; i >= 0; i--)
498
- (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
499
- return o && r && Kt(t, n, r), r;
500
- }, M = (e, t) => (n, o) => t(n, o, e);
501
- let V = class extends Te {
502
- constructor(e, t, n, o, r, i) {
503
- super(), this._injector = e, this._componentManager = t, this._commandService = n, this._shortcutService = o, this._menuService = r, this._uiController = i, this._init();
534
+ var Sr = Object.defineProperty, mr = Object.getOwnPropertyDescriptor, vr = (i, e, t, n) => {
535
+ for (var r = n > 1 ? void 0 : n ? mr(e, t) : e, s = i.length - 1, o; s >= 0; s--)
536
+ (o = i[s]) && (r = (n ? o(e, t, r) : o(r)) || r);
537
+ return n && r && Sr(e, t, r), r;
538
+ }, V = (i, e) => (t, n) => e(t, n, i);
539
+ let fe = class extends H {
540
+ constructor(i, e, t, n, r, s, o) {
541
+ super(), this._injector = i, this._componentManager = e, this._layoutService = t, this._editorService = n, this._menuService = r, this._uiController = s, this._currentUniverService = o, this._init();
504
542
  }
505
543
  _initCustomComponents() {
506
- const e = this._componentManager;
507
- this.disposeWithMe(e.register(Pe, _t)), this.disposeWithMe(e.register(Me, Ke)), this.disposeWithMe(e.register(Ee, Ze)), this.disposeWithMe(e.register(Ae, Xe));
544
+ const i = this._componentManager;
545
+ this.disposeWithMe(i.register(Ct, yn)), this.disposeWithMe(i.register(Ot, Vt)), this.disposeWithMe(i.register(Rt, kt)), this.disposeWithMe(i.register(bt, Ht));
508
546
  }
509
547
  _initMenus() {
510
548
  [
511
- $t,
512
- wt,
513
- Bt,
514
- jt,
515
- Ht,
516
- Vt,
517
- zt,
518
- Wt,
519
- Yt,
520
- kt,
521
- Gt
522
- ].forEach((e) => {
523
- this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e)));
549
+ sr,
550
+ cr,
551
+ ar,
552
+ lr,
553
+ dr,
554
+ ur,
555
+ _r,
556
+ hr,
557
+ pr,
558
+ gr,
559
+ fr
560
+ ].forEach((i) => {
561
+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(i)));
524
562
  });
525
563
  }
526
564
  _init() {
527
- this._initCustomComponents(), this._initMenus();
565
+ this._initCustomComponents(), this._initMenus(), this._initDocBackground();
566
+ }
567
+ _initDocBackground() {
568
+ const i = this._currentUniverService.getAllUniverDocsInstance()[0].getUnitId();
569
+ if (i == null)
570
+ return;
571
+ this._editorService.isEditor(i) || this.disposeWithMe(
572
+ this._uiController.registerContentComponent(() => Mn(or, this._injector))
573
+ );
574
+ }
575
+ _initFocusHandler() {
576
+ this.disposeWithMe(
577
+ this._layoutService.registerFocusHandler(I.DOC, () => {
578
+ this._injector.get(de).focus();
579
+ })
580
+ );
528
581
  }
529
582
  };
530
- V = Xt([
531
- Se(Oe.Rendered, V),
532
- M(0, y(Y)),
533
- M(1, y(Ge)),
534
- M(2, _),
535
- M(3, ye),
536
- M(4, qe),
537
- M(5, Je)
538
- ], V);
539
- const Nn = {
583
+ fe = vr([
584
+ P(U.Rendered, fe),
585
+ V(0, v(Ee)),
586
+ V(1, v(zt)),
587
+ V(2, ft),
588
+ V(3, $),
589
+ V(4, Yt),
590
+ V(5, Xt),
591
+ V(6, M)
592
+ ], fe);
593
+ const xi = {
540
594
  toolbar: {
541
595
  undo: "Undo",
542
596
  redo: "Redo",
@@ -547,6 +601,7 @@ const Nn = {
547
601
  strikethrough: "Strikethrough",
548
602
  subscript: "Subscript",
549
603
  superscript: "Superscript",
604
+ underline: "Underline",
550
605
  textColor: {
551
606
  main: "Text color",
552
607
  right: "Choose color"
@@ -555,7 +610,7 @@ const Nn = {
555
610
  order: "Ordered list",
556
611
  unorder: "Unordered list"
557
612
  }
558
- }, qt = {
613
+ }, Cr = {
559
614
  toolbar: {
560
615
  undo: "撤销",
561
616
  redo: "重做",
@@ -575,519 +630,1220 @@ const Nn = {
575
630
  order: "有序列表",
576
631
  unorder: "无序列表"
577
632
  }
578
- }, Jt = {
579
- id: ht.id,
580
- preconditions: (e) => e.getContextValue(m),
581
- binding: g.ENTER
582
- }, Qt = {
583
- id: ft.id,
584
- preconditions: (e) => e.getContextValue(m),
585
- binding: g.BACKSPACE
586
- }, en = {
587
- id: mt.id,
588
- preconditions: (e) => e.getContextValue(m),
589
- binding: g.DELETE
590
- }, tn = 10, nn = 6;
591
- function on() {
592
- return ve.generateRandomId(nn);
633
+ }, Or = {
634
+ id: un.id,
635
+ preconditions: Nn,
636
+ binding: T.ENTER
637
+ }, Rr = {
638
+ id: hn.id,
639
+ preconditions: L,
640
+ binding: T.BACKSPACE
641
+ }, br = {
642
+ id: _n.id,
643
+ preconditions: L,
644
+ binding: T.DELETE
645
+ }, Ir = 10, Tr = 6;
646
+ function Mr() {
647
+ return pt.generateRandomId(Tr);
593
648
  }
594
- function rn(e) {
595
- const t = e.match(/data-copy-id="([^\s]+)"/);
596
- return t && t[1] ? t[1] : null;
649
+ function yr(i) {
650
+ const e = i.match(/data-copy-id="([^\s]+)"/);
651
+ return e && e[1] ? e[1] : null;
597
652
  }
598
- class sn {
653
+ class Er {
599
654
  constructor() {
600
- h(this, "_cache", new Fe(tn));
655
+ S(this, "_cache", new Ut(Ir));
601
656
  }
602
- set(t, n) {
603
- this._cache.set(t, n);
657
+ set(e, t) {
658
+ this._cache.set(e, t);
604
659
  }
605
- get(t) {
606
- return this._cache.get(t);
660
+ get(e) {
661
+ return this._cache.get(e);
607
662
  }
608
663
  clear() {
609
664
  this._cache.clear();
610
665
  }
611
666
  }
612
- const pe = new sn();
613
- function re(e) {
614
- const t = e.style, n = {}, o = e.tagName.toLowerCase();
615
- switch (o) {
667
+ const at = new Er();
668
+ function Ge(i) {
669
+ const e = i.style, t = {}, n = i.tagName.toLowerCase();
670
+ switch (n) {
616
671
  case "b":
617
672
  case "em":
618
673
  case "strong": {
619
- n.bl = u.TRUE;
674
+ t.bl = m.TRUE;
620
675
  break;
621
676
  }
622
677
  case "s": {
623
- n.st = {
624
- s: u.TRUE
678
+ t.st = {
679
+ s: m.TRUE
625
680
  };
626
681
  break;
627
682
  }
628
683
  case "u": {
629
- n.ul = {
630
- s: u.TRUE
684
+ t.ul = {
685
+ s: m.TRUE
631
686
  };
632
687
  break;
633
688
  }
634
689
  case "i": {
635
- n.it = u.TRUE;
690
+ t.it = m.TRUE;
636
691
  break;
637
692
  }
638
693
  case "sub":
639
694
  case "sup": {
640
- n.va = o === "sup" ? E.SUPERSCRIPT : E.SUBSCRIPT;
695
+ t.va = n === "sup" ? K.SUPERSCRIPT : K.SUBSCRIPT;
641
696
  break;
642
697
  }
643
698
  }
644
- for (let r = 0; r < t.length; r++) {
645
- const i = t[r], s = t.getPropertyValue(i);
646
- switch (i) {
699
+ for (let r = 0; r < e.length; r++) {
700
+ const s = e[r], o = e.getPropertyValue(s);
701
+ switch (s) {
647
702
  case "font-family": {
648
- n.ff = s;
703
+ t.ff = o;
649
704
  break;
650
705
  }
651
706
  case "font-size": {
652
- const a = Number.parseInt(s);
653
- Number.isNaN(a) || s.endsWith("pt") && (n.fs = a);
707
+ const c = Number.parseInt(o);
708
+ Number.isNaN(c) || o.endsWith("pt") && (t.fs = c);
654
709
  break;
655
710
  }
656
711
  case "font-style": {
657
- s === "italic" && (n.it = u.TRUE);
712
+ o === "italic" && (t.it = m.TRUE);
658
713
  break;
659
714
  }
660
715
  case "font-weight": {
661
- Number(s) > 400 && (n.bl = u.TRUE);
716
+ Number(o) > 400 && (t.bl = m.TRUE);
662
717
  break;
663
718
  }
664
719
  case "text-decoration": {
665
- /underline/.test(s) ? n.ul = {
666
- s: u.TRUE
667
- } : /overline/.test(s) ? n.ol = {
668
- s: u.TRUE
669
- } : /line-through/.test(s) && (n.st = {
670
- s: u.TRUE
720
+ /underline/.test(o) ? t.ul = {
721
+ s: m.TRUE
722
+ } : /overline/.test(o) ? t.ol = {
723
+ s: m.TRUE
724
+ } : /line-through/.test(o) && (t.st = {
725
+ s: m.TRUE
671
726
  });
672
727
  break;
673
728
  }
674
729
  case "color": {
675
- const a = new se(s);
676
- a.isValid && (n.cl = {
677
- rgb: a.toRgbString()
730
+ const c = new qe(o);
731
+ c.isValid && (t.cl = {
732
+ rgb: c.toRgbString()
678
733
  });
679
734
  break;
680
735
  }
681
736
  case "background-color": {
682
- const a = new se(s);
683
- a.isValid && (n.bg = {
684
- rgb: a.toRgbString()
737
+ const c = new qe(o);
738
+ c.isValid && (t.bg = {
739
+ rgb: c.toRgbString()
685
740
  });
686
741
  break;
687
742
  }
688
743
  }
689
744
  }
690
- return n;
745
+ return t;
691
746
  }
692
- function an(e) {
693
- const t = new DOMParser(), n = `<x-univer id="univer-root">${e}</x-univer>`;
694
- return t.parseFromString(n, "text/html").querySelector("#univer-root");
747
+ function Dr(i) {
748
+ const e = new DOMParser(), t = `<x-univer id="univer-root">${i}</x-univer>`;
749
+ return e.parseFromString(t, "text/html").querySelector("#univer-root");
695
750
  }
696
- function he(e, t) {
697
- const n = e.tagName.toLowerCase();
698
- return typeof t == "string" ? n === t : Array.isArray(t) ? t.some((o) => o === n) : t(e);
751
+ function lt(i, e) {
752
+ const t = i.tagName.toLowerCase();
753
+ return typeof e == "string" ? t === e : Array.isArray(e) ? e.some((n) => n === t) : e(i);
699
754
  }
700
- const z = class z {
755
+ const Me = class Me {
701
756
  constructor() {
702
- h(this, "_styleCache", /* @__PURE__ */ new Map());
703
- h(this, "_styleRules", []);
704
- h(this, "_afterProcessRules", []);
757
+ S(this, "_styleCache", /* @__PURE__ */ new Map());
758
+ S(this, "_styleRules", []);
759
+ S(this, "_afterProcessRules", []);
705
760
  }
706
- static use(t) {
707
- if (this._pluginList.includes(t))
708
- throw new Error(`Univer paste plugin ${t.name} already added`);
709
- this._pluginList.push(t);
761
+ static use(e) {
762
+ if (this._pluginList.includes(e))
763
+ throw new Error(`Univer paste plugin ${e.name} already added`);
764
+ this._pluginList.push(e);
710
765
  }
711
- convert(t) {
712
- const n = z._pluginList.find((i) => i.checkPasteType(t)), o = an(t), r = {
766
+ convert(e) {
767
+ const t = Me._pluginList.find((s) => s.checkPasteType(e)), n = Dr(e), r = {
713
768
  dataStream: "",
714
769
  textRuns: []
715
770
  };
716
- return n && (this._styleRules = [...n.stylesRules], this._afterProcessRules = [...n.afterProcessRules]), this._styleCache.clear(), this._process(null, o == null ? void 0 : o.childNodes, r), this._styleCache.clear(), this._styleRules = [], this._afterProcessRules = [], r;
771
+ return t && (this._styleRules = [...t.stylesRules], this._afterProcessRules = [...t.afterProcessRules]), this._styleCache.clear(), this._process(null, n == null ? void 0 : n.childNodes, r), this._styleCache.clear(), this._styleRules = [], this._afterProcessRules = [], r;
717
772
  }
718
- _process(t, n, o) {
773
+ _process(e, t, n) {
719
774
  var r;
720
- for (const i of n)
721
- if (i.nodeType === Node.TEXT_NODE) {
722
- const s = (r = i.nodeValue) == null ? void 0 : r.replace(/[\r\n]/g, "");
723
- let a;
724
- t && this._styleCache.has(t) && (a = this._styleCache.get(t)), o.dataStream += s, a && Object.getOwnPropertyNames(a).length && o.textRuns.push({
725
- st: o.dataStream.length - s.length,
726
- ed: o.dataStream.length,
727
- ts: a
775
+ for (const s of t)
776
+ if (s.nodeType === Node.TEXT_NODE) {
777
+ const o = (r = s.nodeValue) == null ? void 0 : r.replace(/[\r\n]/g, "");
778
+ let c;
779
+ e && this._styleCache.has(e) && (c = this._styleCache.get(e)), n.dataStream += o, c && Object.getOwnPropertyNames(c).length && n.textRuns.push({
780
+ st: n.dataStream.length - o.length,
781
+ ed: n.dataStream.length,
782
+ ts: c
728
783
  });
729
- } else if (i.nodeType === Node.ELEMENT_NODE) {
730
- const s = t ? this._styleCache.get(t) : {}, a = this._styleRules.find(({ filter: C }) => he(i, C)), c = a ? a.getStyle(i) : re(i);
731
- this._styleCache.set(i, { ...s, ...c });
732
- const { childNodes: l } = i;
733
- this._process(i, l, o);
734
- const p = this._afterProcessRules.find(
735
- ({ filter: C }) => he(i, C)
784
+ } else if (s.nodeType === Node.ELEMENT_NODE) {
785
+ const o = e ? this._styleCache.get(e) : {}, c = this._styleRules.find(({ filter: _ }) => lt(s, _)), l = c ? c.getStyle(s) : Ge(s);
786
+ this._styleCache.set(s, { ...o, ...l });
787
+ const { childNodes: d } = s;
788
+ this._process(s, d, n);
789
+ const u = this._afterProcessRules.find(
790
+ ({ filter: _ }) => lt(s, _)
736
791
  );
737
- p && p.handler(o, i);
792
+ u && u.handler(n, s);
738
793
  }
739
794
  }
740
795
  };
741
- h(z, "_pluginList", []);
742
- let $ = z;
743
- const cn = {
796
+ S(Me, "_pluginList", []);
797
+ let se = Me;
798
+ const xr = {
744
799
  name: "univer-doc-paste-plugin-lark",
745
- checkPasteType(e) {
746
- return /lark-record-clipboard/i.test(e);
800
+ checkPasteType(i) {
801
+ return /lark-record-clipboard/i.test(i);
747
802
  },
748
803
  // TODO: @JOCS, support inline code copy from lark.
749
804
  stylesRules: [
750
805
  {
751
806
  filter: ["s"],
752
- getStyle(e) {
753
- const t = re(e);
807
+ getStyle(i) {
808
+ const e = Ge(i);
754
809
  return {
755
810
  st: {
756
- s: u.TRUE
811
+ s: m.TRUE
757
812
  },
758
- ...t
813
+ ...e
759
814
  };
760
815
  }
761
816
  }
762
817
  ],
763
818
  afterProcessRules: [
764
819
  {
765
- filter(e) {
766
- return e.tagName === "DIV" && /ace-line/i.test(e.className);
820
+ filter(i) {
821
+ return i.tagName === "DIV" && /ace-line/i.test(i.className);
767
822
  },
768
- handler(e) {
769
- e.paragraphs == null && (e.paragraphs = []), e.paragraphs.push({
770
- startIndex: e.dataStream.length
771
- }), e.dataStream += "\r";
823
+ handler(i) {
824
+ i.paragraphs == null && (i.paragraphs = []), i.paragraphs.push({
825
+ startIndex: i.dataStream.length
826
+ }), i.dataStream += "\r";
772
827
  }
773
828
  }
774
829
  ]
775
830
  };
776
- function ln(e) {
777
- const t = e.style, n = {};
778
- for (let o = 0; o < t.length; o++) {
779
- const r = t[o], i = t.getPropertyValue(r);
831
+ function Pr(i) {
832
+ const e = i.style, t = {};
833
+ for (let n = 0; n < e.length; n++) {
834
+ const r = e[n], s = e.getPropertyValue(r);
780
835
  switch (r) {
781
836
  case "margin-top": {
782
- const s = Number.parseInt(i);
783
- n.spaceAbove = /pt/.test(i) ? fe(s) : s;
837
+ const o = Number.parseInt(s);
838
+ t.spaceAbove = /pt/.test(s) ? rt(o) : o;
784
839
  break;
785
840
  }
786
841
  case "margin-bottom": {
787
- const s = Number.parseInt(i);
788
- n.spaceBelow = /pt/.test(i) ? fe(s) : s;
842
+ const o = Number.parseInt(s);
843
+ t.spaceBelow = /pt/.test(s) ? rt(o) : o;
789
844
  break;
790
845
  }
791
846
  }
792
847
  }
793
- return Object.getOwnPropertyNames(n).length ? n : null;
794
- }
795
- function fe(e) {
796
- return e / 0.75;
848
+ return Object.getOwnPropertyNames(t).length ? t : null;
797
849
  }
798
- const dn = {
850
+ const Ur = {
799
851
  name: "univer-doc-paste-plugin-word",
800
- checkPasteType(e) {
801
- return /word|mso/i.test(e);
852
+ checkPasteType(i) {
853
+ return /word|mso/i.test(i);
802
854
  },
803
855
  stylesRules: [
804
856
  {
805
857
  filter: ["b"],
806
- getStyle(e) {
807
- const t = re(e);
808
- return { bl: u.TRUE, ...t };
858
+ getStyle(i) {
859
+ const e = Ge(i);
860
+ return { bl: m.TRUE, ...e };
809
861
  }
810
862
  }
811
863
  ],
812
864
  afterProcessRules: [
813
865
  {
814
- filter(e) {
815
- return e.tagName === "P" && /mso/i.test(e.className);
866
+ filter(i) {
867
+ return i.tagName === "P" && /mso/i.test(i.className);
816
868
  },
817
- handler(e, t) {
818
- e.paragraphs == null && (e.paragraphs = []);
819
- const n = {
820
- startIndex: e.dataStream.length
821
- }, o = ln(t);
822
- o && (n.paragraphStyle = o), e.paragraphs.push(n), e.dataStream += "\r";
869
+ handler(i, e) {
870
+ i.paragraphs == null && (i.paragraphs = []);
871
+ const t = {
872
+ startIndex: i.dataStream.length
873
+ }, n = Pr(e);
874
+ n && (t.paragraphStyle = n), i.paragraphs.push(t), i.dataStream += "\r";
823
875
  }
824
876
  }
825
877
  ]
826
878
  };
827
- function un(e, t) {
828
- const { st: n, ed: o, ts: r = {} } = t, { ff: i, fs: s, it: a, bl: c, ul: l, st: p, ol: C, bg: L, cl: j, va: P } = r;
829
- let d = e.slice(n, o);
830
- const f = [];
831
- return a === u.TRUE && (d = `<i>${d}</i>`), P === E.SUPERSCRIPT ? d = `<sup>${d}</sup>` : P === E.SUBSCRIPT && (d = `<sub>${d}</sub>`), (l == null ? void 0 : l.s) === u.TRUE && (d = `<u>${d}</u>`), (p == null ? void 0 : p.s) === u.TRUE && (d = `<s>${d}</s>`), c === u.TRUE && (d = `<strong>${d}</strong>`), i && f.push(`font-family: ${i}`), j && f.push(`color: ${j.rgb}`), s && f.push(`font-size: ${s}px`), C && f.push("text-decoration: overline"), L && f.push(`background: ${L.rgb}`), f.length ? `<span style="${f.join(";")}">${d}</span>` : d;
879
+ function Lr(i, e) {
880
+ const { st: t, ed: n, ts: r = {} } = e, { ff: s, fs: o, it: c, bl: l, ul: d, st: u, ol: _, bg: g, cl: f, va: p } = r;
881
+ let a = i.slice(t, n);
882
+ const h = [];
883
+ return c === m.TRUE && (a = `<i>${a}</i>`), p === K.SUPERSCRIPT ? a = `<sup>${a}</sup>` : p === K.SUBSCRIPT && (a = `<sub>${a}</sub>`), (d == null ? void 0 : d.s) === m.TRUE && (a = `<u>${a}</u>`), (u == null ? void 0 : u.s) === m.TRUE && (a = `<s>${a}</s>`), l === m.TRUE && (a = `<strong>${a}</strong>`), s && h.push(`font-family: ${s}`), f && h.push(`color: ${f.rgb}`), o && h.push(`font-size: ${o}px`), _ && h.push("text-decoration: overline"), g && h.push(`background: ${g.rgb}`), h.length ? `<span style="${h.join(";")}">${a}</span>` : a;
832
884
  }
833
- function me(e, t = !0) {
834
- const { dataStream: n, textRuns: o = [], paragraphs: r = [] } = e;
835
- let i = 0;
836
- const s = [], a = [];
837
- for (const c of o) {
838
- const { st: l, ed: p } = c;
839
- if (l !== i && s.push(n.slice(i, l)), s.push(un(n, c)), i = p, t)
840
- for (const C of r) {
841
- const { startIndex: L, paragraphStyle: j = {} } = C;
842
- if (L >= l && L <= p) {
843
- const { spaceAbove: P, spaceBelow: d } = j, f = [];
844
- P != null && (typeof P == "number" ? f.push(`margin-top: ${P}px`) : f.push(`margin-top: ${P.v}px`)), d != null && (typeof d == "number" ? f.push(`margin-bottom: ${d}px`) : f.push(`margin-bottom: ${d.v}px`)), a.push(
845
- `<p className="UniverNormal" ${f.length ? `style="${f.join(";")}"` : ""}>${s.join("")}</p>`
846
- ), s.length = 0;
885
+ function dt(i, e = !0) {
886
+ const { dataStream: t, textRuns: n = [], paragraphs: r = [] } = i;
887
+ let s = 0;
888
+ const o = [], c = [];
889
+ for (const l of n) {
890
+ const { st: d, ed: u } = l;
891
+ if (d !== s && o.push(t.slice(s, d)), o.push(Lr(t, l)), s = u, e)
892
+ for (const _ of r) {
893
+ const { startIndex: g, paragraphStyle: f = {} } = _;
894
+ if (g >= d && g <= u) {
895
+ const { spaceAbove: p, spaceBelow: a } = f, h = [];
896
+ p != null && (typeof p == "number" ? h.push(`margin-top: ${p}px`) : h.push(`margin-top: ${p.v}px`)), a != null && (typeof a == "number" ? h.push(`margin-bottom: ${a}px`) : h.push(`margin-bottom: ${a.v}px`)), c.push(
897
+ `<p className="UniverNormal" ${h.length ? `style="${h.join(";")}"` : ""}>${o.join("")}</p>`
898
+ ), o.length = 0;
847
899
  }
848
900
  }
849
901
  }
850
- return i < n.length && s.push(n.slice(i, n.length)), a.join("") + s.join("");
902
+ return s < t.length && o.push(t.slice(s, t.length)), c.join("") + o.join("");
851
903
  }
852
- class pn {
853
- convert(t) {
854
- if (t.length === 0)
904
+ class Nr {
905
+ convert(e) {
906
+ if (e.length === 0)
855
907
  throw new Error("The bodyList length at least to be 1");
856
- if (t.length === 1)
857
- return me(t[0]);
858
- let n = "";
859
- for (const o of t)
860
- n += '<p className="UniverNormal">', n += me(o, !1), n += "</p>";
861
- return n;
908
+ if (e.length === 1)
909
+ return dt(e[0]);
910
+ let t = "";
911
+ for (const n of e)
912
+ t += '<p className="UniverNormal">', t += dt(n, !1), t += "</p>";
913
+ return t;
862
914
  }
863
915
  }
864
- var hn = Object.defineProperty, fn = Object.getOwnPropertyDescriptor, mn = (e, t, n, o) => {
865
- for (var r = o > 1 ? void 0 : o ? fn(t, n) : t, i = e.length - 1, s; i >= 0; i--)
866
- (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
867
- return o && r && hn(t, n, r), r;
868
- }, N = (e, t) => (n, o) => t(n, o, e);
869
- $.use(dn);
870
- $.use(cn);
871
- function _n(e) {
872
- const t = e.replace(/\n/g, "\r"), n = [];
873
- for (let o = 0; o < t.length; o++)
874
- t[o] === "\r" && n.push({ startIndex: o });
916
+ var $r = Object.defineProperty, Ar = Object.getOwnPropertyDescriptor, wr = (i, e, t, n) => {
917
+ for (var r = n > 1 ? void 0 : n ? Ar(e, t) : e, s = i.length - 1, o; s >= 0; s--)
918
+ (o = i[s]) && (r = (n ? o(e, t, r) : o(r)) || r);
919
+ return n && r && $r(e, t, r), r;
920
+ }, ee = (i, e) => (t, n) => e(t, n, i);
921
+ se.use(Ur);
922
+ se.use(xr);
923
+ function Br(i) {
924
+ const e = i.replace(/\n/g, "\r"), t = [];
925
+ for (let n = 0; n < e.length; n++)
926
+ e[n] === "\r" && t.push({ startIndex: n });
875
927
  return {
876
- dataStream: t,
877
- paragraphs: n
928
+ dataStream: e,
929
+ paragraphs: t
878
930
  };
879
931
  }
880
- const B = ze("doc.clipboard-service");
881
- let Q = class extends Te {
882
- constructor(t, n, o, r, i) {
932
+ const ue = jt("doc.clipboard-service");
933
+ let We = class extends H {
934
+ constructor(e, t, n, r, s) {
883
935
  super();
884
- h(this, "_clipboardHooks", []);
885
- h(this, "_htmlToUDM", new $());
886
- h(this, "_umdToHtml", new pn());
887
- this._currentUniverService = t, this._logService = n, this._commandService = o, this._clipboardInterfaceService = r, this._textSelectionManagerService = i;
936
+ S(this, "_clipboardHooks", []);
937
+ S(this, "_htmlToUDM", new se());
938
+ S(this, "_umdToHtml", new Nr());
939
+ this._currentUniverService = e, this._logService = t, this._commandService = n, this._clipboardInterfaceService = r, this._textSelectionManagerService = s;
888
940
  }
889
941
  async copy() {
890
- const t = this._getDocumentBodyInRanges();
942
+ const e = this._getDocumentBodyInRanges();
943
+ if (e.length === 0)
944
+ return !1;
891
945
  try {
892
- this._setClipboardData(t);
893
- } catch (n) {
894
- return this._logService.error("[DocClipboardService] copy failed", n), !1;
946
+ this._setClipboardData(e);
947
+ } catch (t) {
948
+ return this._logService.error("[DocClipboardService] copy failed", t), !1;
895
949
  }
896
950
  return !0;
897
951
  }
898
952
  async cut() {
899
953
  return this._cut();
900
954
  }
901
- async paste(t) {
902
- const n = await this._generateBodyFromClipboardItems(t);
903
- return this._paste(n);
955
+ async paste(e) {
956
+ const t = await this._generateBodyFromClipboardItems(e);
957
+ return this._paste(t);
904
958
  }
905
- async legacyPaste(t, n) {
906
- const o = this._generateBodyFromHtmlAndText(t, n);
907
- return this._paste(o);
959
+ async legacyPaste(e, t) {
960
+ const n = this._generateBodyFromHtmlAndText(e, t);
961
+ return this._paste(n);
908
962
  }
909
963
  async _cut() {
910
- var i;
964
+ var s;
911
965
  const {
912
- segmentId: t,
913
- endOffset: n,
914
- style: o
915
- } = (i = this._textSelectionManagerService.getActiveRange()) != null ? i : {}, r = this._textSelectionManagerService.getSelections();
916
- if (t == null && this._logService.error("[DocClipboardController] segmentId is not existed"), n == null || r == null)
966
+ segmentId: e,
967
+ endOffset: t,
968
+ style: n
969
+ } = (s = this._textSelectionManagerService.getActiveRange()) != null ? s : {}, r = this._textSelectionManagerService.getSelections();
970
+ if (e == null && this._logService.error("[DocClipboardController] segmentId is not existed"), t == null || r == null)
917
971
  return !1;
918
972
  this.copy();
919
973
  try {
920
- let s = n;
921
- for (const c of r) {
922
- const { startOffset: l, endOffset: p } = c;
923
- l == null || p == null || p <= n && (s -= p - l);
974
+ let o = t;
975
+ for (const l of r) {
976
+ const { startOffset: d, endOffset: u } = l;
977
+ d == null || u == null || u <= t && (o -= u - d);
924
978
  }
925
- const a = [
979
+ const c = [
926
980
  {
927
- startOffset: s,
928
- endOffset: s,
929
- style: o
981
+ startOffset: o,
982
+ endOffset: o,
983
+ style: n
930
984
  }
931
985
  ];
932
- return this._commandService.executeCommand(be.id, { segmentId: t, textRanges: a });
986
+ return this._commandService.executeCommand(St.id, { segmentId: e, textRanges: c });
933
987
  } catch {
934
988
  return this._logService.error("[DocClipboardController] cut content failed"), !1;
935
989
  }
936
990
  }
937
- async _paste(t) {
938
- var s;
939
- const { segmentId: n, endOffset: o, style: r } = (s = this._textSelectionManagerService.getActiveRange()) != null ? s : {}, i = this._textSelectionManagerService.getSelections();
940
- if (n == null && this._logService.error("[DocClipboardController] segmentId does not exist!"), o == null || i == null)
991
+ async _paste(e) {
992
+ var o;
993
+ const { segmentId: t, endOffset: n, style: r } = (o = this._textSelectionManagerService.getActiveRange()) != null ? o : {}, s = this._textSelectionManagerService.getSelections();
994
+ if (t == null && this._logService.error("[DocClipboardController] segmentId does not exist!"), n == null || s == null)
941
995
  return !1;
942
996
  try {
943
- let a = o;
944
- for (const l of i) {
945
- const { startOffset: p, endOffset: C } = l;
946
- p == null || C == null || C <= o && (a += t.dataStream.length - (C - p));
997
+ let c = n;
998
+ for (const d of s) {
999
+ const { startOffset: u, endOffset: _ } = d;
1000
+ u == null || _ == null || _ <= n && (c += e.dataStream.length - (_ - u));
947
1001
  }
948
- const c = [
1002
+ const l = [
949
1003
  {
950
- startOffset: a,
951
- endOffset: a,
1004
+ startOffset: c,
1005
+ endOffset: c,
952
1006
  style: r
953
1007
  }
954
1008
  ];
955
- return this._commandService.executeCommand(xe.id, { body: t, segmentId: n, textRanges: c });
1009
+ return this._commandService.executeCommand(mt.id, { body: e, segmentId: t, textRanges: l });
956
1010
  } catch {
957
1011
  return this._logService.error("[DocClipboardController]", "clipboard is empty."), !1;
958
1012
  }
959
1013
  }
960
- async _setClipboardData(t) {
961
- const n = on(), o = t.length > 1 ? t.map((i) => i.dataStream).join(`
962
- `) : t[0].dataStream;
963
- let r = this._umdToHtml.convert(t);
964
- return t.length === 1 && (r = r.replace(/(<[a-z]+)/, (i, s) => `${s} data-copy-id="${n}"`), pe.set(n, t[0])), this._clipboardInterfaceService.write(o, r);
1014
+ async _setClipboardData(e) {
1015
+ const t = Mr(), n = e.length > 1 ? e.map((s) => s.dataStream).join(`
1016
+ `) : e[0].dataStream;
1017
+ let r = this._umdToHtml.convert(e);
1018
+ return e.length === 1 && (r = r.replace(/(<[a-z]+)/, (s, o) => `${o} data-copy-id="${t}"`), at.set(t, e[0])), this._clipboardInterfaceService.write(n, r);
965
1019
  }
966
- addClipboardHook(t) {
967
- return this._clipboardHooks.push(t), $e(() => {
968
- const n = this._clipboardHooks.indexOf(t);
969
- n > -1 && this._clipboardHooks.splice(n, 1);
1020
+ addClipboardHook(e) {
1021
+ return this._clipboardHooks.push(e), N(() => {
1022
+ const t = this._clipboardHooks.indexOf(e);
1023
+ t > -1 && this._clipboardHooks.splice(t, 1);
970
1024
  });
971
1025
  }
972
1026
  _getDocumentBodyInRanges() {
973
- const t = this._textSelectionManagerService.getSelections(), n = this._currentUniverService.getCurrentUniverDocInstance(), o = [];
974
- if (t == null)
975
- return o;
976
- for (const r of t) {
977
- const { startOffset: i, endOffset: s, collapsed: a } = r;
978
- if (a || i == null || s == null)
1027
+ const e = this._textSelectionManagerService.getSelections(), t = this._currentUniverService.getCurrentUniverDocInstance(), n = [];
1028
+ if (e == null)
1029
+ return n;
1030
+ for (const r of e) {
1031
+ const { startOffset: s, endOffset: o, collapsed: c } = r;
1032
+ if (c || s == null || o == null)
979
1033
  continue;
980
- const c = n.sliceBody(i, s);
981
- c != null && o.push(c);
1034
+ const l = t.sliceBody(s, o);
1035
+ l != null && n.push(l);
982
1036
  }
983
- return o;
1037
+ return n;
984
1038
  }
985
- async _generateBodyFromClipboardItems(t) {
1039
+ async _generateBodyFromClipboardItems(e) {
986
1040
  try {
987
- let n = "", o = "";
988
- for (const r of t)
989
- for (const i of r.types)
990
- i === Qe ? o = await r.getType(i).then((s) => s && s.text()) : i === et && (n = await r.getType(i).then((s) => s && s.text()));
991
- return this._generateBodyFromHtmlAndText(n, o);
992
- } catch (n) {
993
- return Promise.reject(n);
1041
+ let t = "", n = "";
1042
+ for (const r of e)
1043
+ for (const s of r.types)
1044
+ s === Gt ? n = await r.getType(s).then((o) => o && o.text()) : s === Zt && (t = await r.getType(s).then((o) => o && o.text()));
1045
+ return this._generateBodyFromHtmlAndText(t, n);
1046
+ } catch (t) {
1047
+ return Promise.reject(t);
994
1048
  }
995
1049
  }
996
- _generateBodyFromHtmlAndText(t, n) {
997
- if (!t) {
998
- if (n)
999
- return _n(n);
1050
+ _generateBodyFromHtmlAndText(e, t) {
1051
+ if (!e) {
1052
+ if (t)
1053
+ return Br(t);
1000
1054
  throw new Error("[DocClipboardService] html and text cannot be both empty!");
1001
1055
  }
1002
- const o = rn(t);
1003
- if (o) {
1004
- const r = pe.get(o);
1056
+ const n = yr(e);
1057
+ if (n) {
1058
+ const r = at.get(n);
1005
1059
  if (r)
1006
1060
  return r;
1007
1061
  }
1008
- return this._htmlToUDM.convert(t);
1062
+ return this._htmlToUDM.convert(e);
1009
1063
  }
1010
1064
  };
1011
- Q = mn([
1012
- N(0, te),
1013
- N(1, Re),
1014
- N(2, _),
1015
- N(3, oe),
1016
- N(4, y(Ie))
1017
- ], Q);
1018
- function Z(e) {
1019
- return e.getContextValue(m) || e.getContextValue(ge);
1065
+ We = wr([
1066
+ ee(0, M),
1067
+ ee(1, gt),
1068
+ ee(2, O),
1069
+ ee(3, He),
1070
+ ee(4, v(le))
1071
+ ], We);
1072
+ function Ne(i) {
1073
+ return i.getContextValue(ye) || i.getContextValue(_t);
1020
1074
  }
1021
- const ie = 999, gn = {
1022
- id: tt.id,
1075
+ const Ze = 999, Fr = {
1076
+ id: qt.id,
1023
1077
  name: "doc.command.copy",
1024
- type: ne.COMMAND,
1078
+ type: ke.COMMAND,
1025
1079
  multi: !0,
1026
- priority: ie,
1027
- preconditions: Z,
1028
- handler: async (e) => e.get(B).copy()
1029
- }, Cn = {
1030
- id: nt.id,
1080
+ priority: Ze,
1081
+ preconditions: Ne,
1082
+ handler: async (i) => i.get(ue).copy()
1083
+ }, jr = {
1084
+ id: Kt.id,
1031
1085
  name: "doc.command.cut",
1032
- type: ne.COMMAND,
1086
+ type: ke.COMMAND,
1033
1087
  multi: !0,
1034
- priority: ie,
1035
- preconditions: Z,
1036
- handler: async (e) => e.get(B).cut()
1037
- }, Sn = {
1038
- id: ot.id,
1088
+ priority: Ze,
1089
+ preconditions: Ne,
1090
+ handler: async (i) => i.get(ue).cut()
1091
+ }, Wr = {
1092
+ id: Jt.id,
1039
1093
  name: "doc.command.paste",
1040
- type: ne.COMMAND,
1094
+ type: ke.COMMAND,
1041
1095
  multi: !0,
1042
- priority: ie,
1043
- preconditions: Z,
1044
- handler: async (e) => {
1045
- const t = e.get(B), o = await e.get(oe).read();
1046
- return o.length === 0 ? !1 : t.paste(o);
1096
+ priority: Ze,
1097
+ preconditions: Ne,
1098
+ handler: async (i) => {
1099
+ const e = i.get(ue), n = await i.get(He).read();
1100
+ return n.length === 0 ? !1 : e.paste(n);
1047
1101
  }
1048
1102
  };
1049
- var On = Object.defineProperty, Tn = Object.getOwnPropertyDescriptor, vn = (e, t, n, o) => {
1050
- for (var r = o > 1 ? void 0 : o ? Tn(t, n) : t, i = e.length - 1, s; i >= 0; i--)
1051
- (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
1052
- return o && r && On(t, n, r), r;
1053
- }, U = (e, t) => (n, o) => t(n, o, e);
1054
- let W = class extends Ce {
1055
- constructor(e, t, n, o, r) {
1056
- super(), this._commandService = e, this._clipboardInterfaceService = t, this._docClipboardService = n, this._textSelectionRenderManager = o, this._contextService = r, this._init();
1103
+ var zr = Object.defineProperty, Vr = Object.getOwnPropertyDescriptor, kr = (i, e, t, n) => {
1104
+ for (var r = n > 1 ? void 0 : n ? Vr(e, t) : e, s = i.length - 1, o; s >= 0; s--)
1105
+ (o = i[s]) && (r = (n ? o(e, t, r) : o(r)) || r);
1106
+ return n && r && zr(e, t, r), r;
1107
+ }, te = (i, e) => (t, n) => e(t, n, i);
1108
+ let Se = class extends ce {
1109
+ constructor(i, e, t, n, r) {
1110
+ super(), this._commandService = i, this._clipboardInterfaceService = e, this._docClipboardService = t, this._textSelectionRenderManager = n, this._contextService = r, this._init();
1057
1111
  }
1058
1112
  _init() {
1059
- [gn, Cn, Sn].forEach((e) => this.disposeWithMe(this._commandService.registerMultipleCommand(e))), [xe, be].forEach((e) => this.disposeWithMe(this._commandService.registerCommand(e))), this._initLegacyPasteCommand();
1113
+ [Fr, jr, Wr].forEach((i) => this.disposeWithMe(this._commandService.registerMultipleCommand(i))), [mt, St].forEach((i) => this.disposeWithMe(this._commandService.registerCommand(i))), this._initLegacyPasteCommand();
1060
1114
  }
1061
1115
  _initLegacyPasteCommand() {
1062
- var e;
1063
- this._clipboardInterfaceService.supportClipboard || (e = this._textSelectionRenderManager) == null || e.onPaste$.pipe(gt(this.dispose$)).subscribe((t) => {
1064
- var i, s;
1065
- if (!Z(this._contextService))
1116
+ var i;
1117
+ this._clipboardInterfaceService.supportClipboard || (i = this._textSelectionRenderManager) == null || i.onPaste$.pipe(oe(this.dispose$)).subscribe((e) => {
1118
+ var s, o;
1119
+ if (!Ne(this._contextService))
1066
1120
  return;
1067
- t.event.preventDefault();
1068
- const n = t.event, o = (i = n.clipboardData) == null ? void 0 : i.getData("text/html"), r = (s = n.clipboardData) == null ? void 0 : s.getData("text/plain");
1069
- this._docClipboardService.legacyPaste(o, r);
1121
+ e.event.preventDefault();
1122
+ const t = e.event, n = (s = t.clipboardData) == null ? void 0 : s.getData("text/html"), r = (o = t.clipboardData) == null ? void 0 : o.getData("text/plain");
1123
+ this._docClipboardService.legacyPaste(n, r);
1070
1124
  });
1071
1125
  }
1072
1126
  };
1073
- W = vn([
1074
- Se(Oe.Steady, W),
1075
- U(0, _),
1076
- U(1, oe),
1077
- U(2, B),
1078
- U(3, De),
1079
- U(4, we)
1080
- ], W);
1081
- var Rn = Object.defineProperty, yn = Object.getOwnPropertyDescriptor, In = (e, t, n, o) => {
1082
- for (var r = o > 1 ? void 0 : o ? yn(t, n) : t, i = e.length - 1, s; i >= 0; i--)
1083
- (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
1084
- return o && r && Rn(t, n, r), r;
1085
- }, X = (e, t) => (n, o) => t(n, o, e), q;
1086
- let _e = (q = class extends Be {
1087
- constructor(e, t, n, o) {
1088
- super(Tt), this._config = e, this._injector = t, this._localeService = n, this._logService = o, this._localeService.load({
1089
- zhCN: qt
1090
- }), this._config = ve.deepMerge({}, Ot, this._config), this._initDependencies(t), this._initializeCommands();
1127
+ Se = kr([
1128
+ P(U.Steady, Se),
1129
+ te(0, O),
1130
+ te(1, He),
1131
+ te(2, ue),
1132
+ te(3, de),
1133
+ te(4, Lt)
1134
+ ], Se);
1135
+ var Hr = Object.defineProperty, Yr = Object.getOwnPropertyDescriptor, Xr = (i, e, t, n) => {
1136
+ for (var r = n > 1 ? void 0 : n ? Yr(e, t) : e, s = i.length - 1, o; s >= 0; s--)
1137
+ (o = i[s]) && (r = (n ? o(e, t, r) : o(r)) || r);
1138
+ return n && r && Hr(e, t, r), r;
1139
+ }, ne = (i, e) => (t, n) => e(t, n, i);
1140
+ let me = class extends H {
1141
+ constructor(e, t, n, r, s) {
1142
+ super();
1143
+ S(this, "_initialEditors", /* @__PURE__ */ new Set());
1144
+ this._currentUniverService = e, this._docSkeletonManagerService = t, this._editorService = n, this._commandService = r, this._textSelectionRenderManager = s, this._initialize();
1145
+ }
1146
+ _initialize() {
1147
+ this.disposeWithMe(
1148
+ this._editorService.resize$.subscribe((e) => {
1149
+ this._resize(e);
1150
+ })
1151
+ ), this._editorService.getAllEditor().forEach((e) => {
1152
+ const t = e.editorUnitId;
1153
+ this._initialEditors.has(t) || (this._initialEditors.add(t), this._resize(t));
1154
+ }), this._commandExecutedListener(), this._initialSetValue(), this._initialBlur(), this._initialFocus(), this._initialValueChange();
1155
+ }
1156
+ _resize(e) {
1157
+ var w, B, F;
1158
+ if (e == null)
1159
+ return;
1160
+ const t = this._editorService.getEditor(e);
1161
+ if ((t == null ? void 0 : t.cancelDefaultResizeListener) === !0)
1162
+ return;
1163
+ const n = (w = this._docSkeletonManagerService.getSkeletonByUnitId(e)) == null ? void 0 : w.skeleton, r = this._currentUniverService.getUniverDocInstance(e);
1164
+ if (t == null || t.render == null || n == null || r == null)
1165
+ return;
1166
+ const { marginTop: s = 0, marginBottom: o = 0, marginLeft: c = 0, marginRight: l = 0 } = r.getSnapshot().documentStyle, { scene: d, mainComponent: u } = t.render;
1167
+ let { actualHeight: _, actualWidth: g } = n.getActualSize();
1168
+ _ += s + o, g += c + l;
1169
+ const { width: f, height: p } = t.getBoundingClientRect(), a = d.getViewport(Pe.VIEW_MAIN);
1170
+ let h = a == null ? void 0 : a.getScrollBar();
1171
+ const C = Math.max(g, f), R = Math.max(_, p);
1172
+ d.transformByState({
1173
+ width: C,
1174
+ height: R
1175
+ }), u == null || u.resize(C, R), t.isSingle() ? g > f ? h == null ? a && new Fe(a, { barSize: 8, enableVertical: !1 }) : a == null || a.resetSizeAndScrollBar() : (h = null, a == null || a.scrollTo({ x: 0, y: 0 }), (F = a == null ? void 0 : a.getScrollBar()) == null || F.dispose()) : _ > p ? h == null ? a && new Fe(a, { enableHorizontal: !1, barSize: 8 }) : a == null || a.resetSizeAndScrollBar() : (h = null, a == null || a.scrollTo({ x: 0, y: 0 }), (B = a == null ? void 0 : a.getScrollBar()) == null || B.dispose());
1176
+ }
1177
+ _initialSetValue() {
1178
+ this.disposeWithMe(
1179
+ this._editorService.setValue$.subscribe((e) => {
1180
+ this._commandService.executeCommand(pn.id, {
1181
+ unitId: e.editorUnitId,
1182
+ body: e.body,
1183
+ segmentId: null
1184
+ });
1185
+ })
1186
+ );
1187
+ }
1188
+ _initialBlur() {
1189
+ this.disposeWithMe(
1190
+ this._editorService.blur$.subscribe(() => {
1191
+ this._textSelectionRenderManager.removeAllTextRanges(), this._textSelectionRenderManager.blur();
1192
+ })
1193
+ );
1194
+ }
1195
+ _initialFocus() {
1196
+ this.disposeWithMe(
1197
+ this._editorService.focus$.subscribe((e) => {
1198
+ this._textSelectionRenderManager.removeAllTextRanges(), this._textSelectionRenderManager.addTextRanges([e]);
1199
+ })
1200
+ );
1201
+ }
1202
+ _initialValueChange() {
1203
+ this.disposeWithMe(
1204
+ this._textSelectionRenderManager.onCompositionupdate$.subscribe(this._valueChange.bind(this))
1205
+ ), this.disposeWithMe(
1206
+ this._textSelectionRenderManager.onInput$.subscribe(this._valueChange.bind(this))
1207
+ ), this.disposeWithMe(
1208
+ this._textSelectionRenderManager.onKeydown$.subscribe(this._valueChange.bind(this))
1209
+ ), this.disposeWithMe(
1210
+ this._textSelectionRenderManager.onPaste$.subscribe(this._valueChange.bind(this))
1211
+ );
1212
+ }
1213
+ _valueChange() {
1214
+ const e = this._currentUniverService.getCurrentUniverDocInstance().getUnitId();
1215
+ if (e == null)
1216
+ return;
1217
+ const t = this._editorService.getEditor(e);
1218
+ t == null || t.isSheetEditor() || this._editorService.refreshValueChange(e);
1219
+ }
1220
+ /**
1221
+ * Listen to document edits to refresh the size of the normula editor.
1222
+ */
1223
+ _commandExecutedListener() {
1224
+ const e = [Ye.id, Qt.id];
1225
+ this.disposeWithMe(
1226
+ this._commandService.onCommandExecuted((t) => {
1227
+ if (e.includes(t.id)) {
1228
+ const n = t.params, { unitId: r } = n;
1229
+ if (this._editorService.isSheetEditor(r))
1230
+ return;
1231
+ this._resize(r), this._valueChange();
1232
+ }
1233
+ })
1234
+ );
1235
+ }
1236
+ };
1237
+ me = Xr([
1238
+ P(U.Rendered, me),
1239
+ ne(0, M),
1240
+ ne(1, v(Q)),
1241
+ ne(2, $),
1242
+ ne(3, O),
1243
+ ne(4, de)
1244
+ ], me);
1245
+ var Gr = Object.defineProperty, Zr = Object.getOwnPropertyDescriptor, qr = (i, e, t, n) => {
1246
+ for (var r = n > 1 ? void 0 : n ? Zr(e, t) : e, s = i.length - 1, o; s >= 0; s--)
1247
+ (o = i[s]) && (r = (n ? o(e, t, r) : o(r)) || r);
1248
+ return n && r && Gr(e, t, r), r;
1249
+ }, ge = (i, e) => (t, n) => e(t, n, i);
1250
+ let ve = class extends ce {
1251
+ constructor(e, t, n, r) {
1252
+ super();
1253
+ S(this, "_docRenderMap", /* @__PURE__ */ new Set());
1254
+ this._docSkeletonManagerService = e, this._renderManagerService = t, this._commandService = n, this._editorService = r, this._initialRenderRefresh(), this._commandExecutedListener();
1255
+ }
1256
+ _initialRenderRefresh() {
1257
+ this._docSkeletonManagerService.currentSkeletonBefore$.pipe(oe(this.dispose$)).subscribe((e) => {
1258
+ this._create(e);
1259
+ });
1260
+ }
1261
+ _create(e) {
1262
+ if (e == null)
1263
+ return;
1264
+ const { skeleton: t, unitId: n } = e;
1265
+ let r = this._renderManagerService.getRenderById(n);
1266
+ r == null && (this._renderManagerService.create(n), r = this._renderManagerService.getRenderById(n));
1267
+ const { mainComponent: s } = r;
1268
+ s.changeSkeleton(t), this._recalculateSizeBySkeleton(r, t);
1269
+ }
1270
+ _recalculateSizeBySkeleton(e, t) {
1271
+ var u;
1272
+ const { mainComponent: n, scene: r, unitId: s } = e, o = n, c = (u = t.getSkeletonData()) == null ? void 0 : u.pages;
1273
+ if (c == null)
1274
+ return;
1275
+ let l = 0, d = 0;
1276
+ for (let _ = 0, g = c.length; _ < g; _++) {
1277
+ const f = c[_], { pageWidth: p, pageHeight: a } = f;
1278
+ o.pageLayoutType === it.VERTICAL ? (d += a, d += o.pageMarginTop, _ === g - 1 && (d += o.pageMarginTop), l = Math.max(l, p)) : o.pageLayoutType === it.HORIZONTAL && (l += p, _ !== g - 1 && (l += o.pageMarginLeft), d = Math.max(d, a));
1279
+ }
1280
+ o.resize(l, d), this._editorService.isEditor(s) || r.resize(l, d);
1281
+ }
1282
+ _commandExecutedListener() {
1283
+ const e = [Ye.id];
1284
+ this.disposeWithMe(
1285
+ this._commandService.onCommandExecuted((t) => {
1286
+ var n;
1287
+ if (e.includes(t.id)) {
1288
+ const r = t.params, { unitId: s } = r, o = this._docSkeletonManagerService.getSkeletonByUnitId(s);
1289
+ if (o == null)
1290
+ return;
1291
+ const { skeleton: c } = o, l = this._renderManagerService.getRenderById(s);
1292
+ if (l == null)
1293
+ return;
1294
+ if (c.calculate(), this._editorService.isEditor(s)) {
1295
+ (n = l.mainComponent) == null || n.makeDirty();
1296
+ return;
1297
+ }
1298
+ this._recalculateSizeBySkeleton(l, c);
1299
+ }
1300
+ })
1301
+ );
1302
+ }
1303
+ };
1304
+ ve = qr([
1305
+ P(U.Rendered, ve),
1306
+ ge(0, v(Q)),
1307
+ ge(1, Y),
1308
+ ge(2, O),
1309
+ ge(3, $)
1310
+ ], ve);
1311
+ var Kr = Object.defineProperty, Jr = Object.getOwnPropertyDescriptor, Qr = (i, e, t, n) => {
1312
+ for (var r = n > 1 ? void 0 : n ? Jr(e, t) : e, s = i.length - 1, o; s >= 0; s--)
1313
+ (o = i[s]) && (r = (n ? o(e, t, r) : o(r)) || r);
1314
+ return n && r && Kr(e, t, r), r;
1315
+ }, $e = (i, e) => (t, n) => e(t, n, i);
1316
+ let Ce = class extends ce {
1317
+ constructor(e, t, n) {
1318
+ super();
1319
+ S(this, "_scene");
1320
+ S(this, "_currentDocumentModel");
1321
+ S(this, "_fps$", new Dn(""));
1322
+ S(this, "fps$", this._fps$.asObservable());
1323
+ this._renderManagerService = e, this._configService = t, this._currentUniverService = n, this._initialize();
1324
+ }
1325
+ _initialize() {
1326
+ this._renderManagerService.createRender$.pipe(oe(this.dispose$)).subscribe((e) => {
1327
+ this._create(e);
1328
+ }), this._currentUniverService.currentDoc$.pipe(oe(this.dispose$)).subscribe((e) => {
1329
+ this._create(e == null ? void 0 : e.getUnitId());
1330
+ }), this._currentUniverService.getAllUniverDocsInstance().forEach((e) => {
1331
+ this._create(e.getUnitId());
1332
+ });
1333
+ }
1334
+ dispose() {
1335
+ this._fps$.complete();
1336
+ }
1337
+ _create(e) {
1338
+ if (e == null)
1339
+ return;
1340
+ const t = this._currentUniverService.getUniverDocInstance(e);
1341
+ t != null && (this._currentDocumentModel = t, this._renderManagerService.has(e) || this._addNewRender());
1342
+ }
1343
+ _addNewRender() {
1344
+ const e = this._currentDocumentModel, t = e.getUnitId(), n = e.getContainer(), r = e.getParentRenderUnitId();
1345
+ if (n != null && r != null)
1346
+ throw new Error("container or parentRenderUnitId can only exist one");
1347
+ n == null && r != null ? this._renderManagerService.createRenderWithParent(t, r) : this._renderManagerService.createRender(t);
1348
+ const s = this._renderManagerService.getRenderById(t);
1349
+ if (s == null)
1350
+ return;
1351
+ const { scene: o, engine: c } = s;
1352
+ o.openTransformer(), this._scene = o;
1353
+ const l = new vn(Pe.VIEW_MAIN, o, {
1354
+ left: 0,
1355
+ top: 0,
1356
+ bottom: 0,
1357
+ right: 0,
1358
+ isWheelPreventDefaultX: !0
1359
+ });
1360
+ o.attachControl(), o.on(Cn.wheel, (_, g) => {
1361
+ const f = _;
1362
+ if (f.ctrlKey) {
1363
+ const p = Math.abs(f.deltaX);
1364
+ let a = p < 40 ? 0.2 : p < 80 ? 0.4 : 0.2;
1365
+ a *= f.deltaY > 0 ? -1 : 1, o.scaleX < 1 && (a /= 2), o.scaleX + a > 4 ? o.scale(4, 4) : o.scaleX + a < 0.1 ? o.scale(0.1, 0.1) : f.preventDefault();
1366
+ } else
1367
+ l.onMouseWheel(f, g);
1368
+ }), this._configService.getConfig("hasScroll") !== !1 && new Fe(l), o.addLayer(
1369
+ new ot(o, [], tt),
1370
+ new ot(o, [], gn)
1371
+ ), this._addComponent(s), this._currentDocumentModel.getShouldRenderLoopImmediately() && c.runRenderLoop(() => {
1372
+ o.render(), this._fps$.next(Math.round(c.getFps()).toString());
1373
+ }), this._renderManagerService.setCurrent(t);
1374
+ }
1375
+ _addComponent(e) {
1376
+ const t = this._scene, n = this._currentDocumentModel, r = new On(nt.MAIN, void 0, {
1377
+ pageMarginLeft: n.documentStyle.marginLeft || 0,
1378
+ pageMarginTop: n.documentStyle.marginTop || 0
1379
+ });
1380
+ r.zIndex = fn, e.mainComponent = r, e.components.set(nt.MAIN, r), t.addObjects([r], tt);
1381
+ }
1382
+ };
1383
+ Ce = Qr([
1384
+ P(U.Starting, Ce),
1385
+ $e(0, Y),
1386
+ $e(1, Nt),
1387
+ $e(2, M)
1388
+ ], Ce);
1389
+ var ei = Object.defineProperty, ti = Object.getOwnPropertyDescriptor, ni = (i, e, t, n) => {
1390
+ for (var r = n > 1 ? void 0 : n ? ti(e, t) : e, s = i.length - 1, o; s >= 0; s--)
1391
+ (o = i[s]) && (r = (n ? o(e, t, r) : o(r)) || r);
1392
+ return n && r && ei(e, t, r), r;
1393
+ }, Z = (i, e) => (t, n) => e(t, n, i);
1394
+ let Oe = class extends H {
1395
+ constructor(e, t, n, r, s, o) {
1396
+ super();
1397
+ S(this, "_liquid", new Rn());
1398
+ S(this, "_pageMarginCache", /* @__PURE__ */ new Map());
1399
+ this._docSkeletonManagerService = e, this._currentUniverService = t, this._renderManagerService = n, this._commandService = r, this._floatingObjectManagerService = s, this._editorService = o, this._initialize(), this._commandExecutedListener();
1400
+ }
1401
+ _initialize() {
1402
+ this._initialRenderRefresh(), this._updateOnPluginChange();
1403
+ }
1404
+ _updateOnPluginChange() {
1405
+ this._floatingObjectManagerService.pluginUpdate$.subscribe((e) => {
1406
+ const t = this._docSkeletonManagerService.getCurrent();
1407
+ if (t == null)
1408
+ return;
1409
+ const { unitId: n, skeleton: r } = t, s = this._renderManagerService.getRenderById(n);
1410
+ if (s == null)
1411
+ return;
1412
+ const { mainComponent: o, components: c, scene: l } = s, d = o, { left: u, top: _ } = d;
1413
+ e.forEach((g) => {
1414
+ const { unitId: f, subUnitId: p, floatingObjectId: a, floatingObject: h } = g, { left: C = 0, top: R = 0, width: w = 0, height: B = 0, angle: F, flipX: X, flipY: G, skewX: he, skewY: _e } = h, b = this._pageMarginCache.get(a), Mt = (b == null ? void 0 : b.marginLeft) || 0, yt = (b == null ? void 0 : b.marginTop) || 0;
1415
+ r == null || r.getViewModel().getDataModel().updateDrawing(a, {
1416
+ left: C - u - Mt,
1417
+ top: R - _ - yt,
1418
+ height: B,
1419
+ width: w
1420
+ });
1421
+ }), r == null || r.calculate(), o == null || o.makeDirty();
1422
+ });
1423
+ }
1424
+ _initialRenderRefresh() {
1425
+ this._docSkeletonManagerService.currentSkeleton$.subscribe((e) => {
1426
+ if (e == null)
1427
+ return;
1428
+ const { skeleton: t, unitId: n } = e, r = this._renderManagerService.getRenderById(n);
1429
+ if (r == null)
1430
+ return;
1431
+ const { mainComponent: s } = r;
1432
+ s.changeSkeleton(t), this._refreshFloatingObject(n, t, r);
1433
+ });
1434
+ }
1435
+ _commandExecutedListener() {
1436
+ const e = [Ye.id, Xe.id];
1437
+ this.disposeWithMe(
1438
+ this._commandService.onCommandExecuted((t) => {
1439
+ var n;
1440
+ if (e.includes(t.id)) {
1441
+ const r = t.params, { unitId: s } = r, o = this._docSkeletonManagerService.getCurrent();
1442
+ if (o == null)
1443
+ return;
1444
+ const { unitId: c, skeleton: l } = o;
1445
+ if (s !== c)
1446
+ return;
1447
+ const d = this._renderManagerService.getRenderById(c);
1448
+ if (d == null)
1449
+ return;
1450
+ if (this._editorService.isEditor(c)) {
1451
+ (n = d.mainComponent) == null || n.makeDirty();
1452
+ return;
1453
+ }
1454
+ this._refreshFloatingObject(c, l, d);
1455
+ }
1456
+ })
1457
+ );
1458
+ }
1459
+ _refreshFloatingObject(e, t, n) {
1460
+ const r = t == null ? void 0 : t.getSkeletonData(), { mainComponent: s, scene: o } = n, c = s;
1461
+ if (!r)
1462
+ return;
1463
+ const { left: l, top: d, pageLayoutType: u, pageMarginLeft: _, pageMarginTop: g } = c, { pages: f } = r, p = [];
1464
+ o.getAncestorScale(), this._liquid.reset(), this._pageMarginCache.clear();
1465
+ for (let a = 0, h = f.length; a < h; a++) {
1466
+ const C = f[a], { skeDrawings: R, marginLeft: w, marginTop: B } = C;
1467
+ this._liquid.translatePagePadding(C), R.forEach((F) => {
1468
+ const { aLeft: X, aTop: G, height: he, width: _e, objectId: b } = F;
1469
+ p.push({
1470
+ unitId: e,
1471
+ subUnitId: $t,
1472
+ floatingObjectId: b,
1473
+ floatingObject: {
1474
+ left: X + l + this._liquid.x,
1475
+ top: G + d + this._liquid.y,
1476
+ width: _e,
1477
+ height: he
1478
+ }
1479
+ }), this._pageMarginCache.set(b, {
1480
+ marginLeft: this._liquid.x,
1481
+ marginTop: this._liquid.y
1482
+ });
1483
+ }), this._liquid.translatePage(C, u, _, g);
1484
+ }
1485
+ this._floatingObjectManagerService.BatchAddOrUpdate(p);
1486
+ }
1487
+ };
1488
+ Oe = ni([
1489
+ P(U.Steady, Oe),
1490
+ Z(0, v(Q)),
1491
+ Z(1, M),
1492
+ Z(2, Y),
1493
+ Z(3, O),
1494
+ Z(4, At),
1495
+ Z(5, $)
1496
+ ], Oe);
1497
+ var ri = Object.defineProperty, ii = Object.getOwnPropertyDescriptor, oi = (i, e, t, n) => {
1498
+ for (var r = n > 1 ? void 0 : n ? ii(e, t) : e, s = i.length - 1, o; s >= 0; s--)
1499
+ (o = i[s]) && (r = (n ? o(e, t, r) : o(r)) || r);
1500
+ return n && r && ri(e, t, r), r;
1501
+ }, Ae = (i, e) => (t, n) => e(t, n, i);
1502
+ const si = "rgba(198, 198, 198, 1)", ci = "rgba(255, 255, 255, 1)";
1503
+ let Re = class extends H {
1504
+ constructor(i, e, t) {
1505
+ super(), this._renderManagerService = i, this._editorService = e, this._currentUniverService = t, this._initialize(), this._commandExecutedListener();
1506
+ }
1507
+ _initialize() {
1508
+ this._initialRenderRefresh();
1509
+ }
1510
+ _initialRenderRefresh() {
1511
+ this._renderManagerService.currentRender$.subscribe((i) => {
1512
+ var s;
1513
+ if (i == null)
1514
+ return;
1515
+ const e = this._renderManagerService.getRenderById(i);
1516
+ if (this._editorService.isEditor(i) || this._currentUniverService.getUniverDocInstance(i) == null || e == null)
1517
+ return;
1518
+ const { mainComponent: t } = e, n = t, r = (s = n.getSkeleton()) == null ? void 0 : s.getPageSize();
1519
+ this.disposeWithMe(
1520
+ N(
1521
+ n.onPageRenderObservable.add((o) => {
1522
+ var a, h, C, R;
1523
+ if (this._editorService.isEditor(i))
1524
+ return;
1525
+ const { page: c, pageLeft: l, pageTop: d, ctx: u } = o, { width: _, pageWidth: g, height: f, pageHeight: p } = c;
1526
+ u.save(), u.translate(l - 0.5, d - 0.5), bn.drawWith(u, {
1527
+ width: (h = (a = r == null ? void 0 : r.width) != null ? a : g) != null ? h : _,
1528
+ height: (R = (C = r == null ? void 0 : r.height) != null ? C : p) != null ? R : f,
1529
+ strokeWidth: 1,
1530
+ stroke: si,
1531
+ fill: ci,
1532
+ zIndex: 3
1533
+ }), u.restore();
1534
+ })
1535
+ )
1536
+ );
1537
+ });
1538
+ }
1539
+ _commandExecutedListener() {
1540
+ }
1541
+ };
1542
+ Re = oi([
1543
+ P(U.Rendered, Re),
1544
+ Ae(0, Y),
1545
+ Ae(1, $),
1546
+ Ae(2, M)
1547
+ ], Re);
1548
+ var ai = Object.defineProperty, li = Object.getOwnPropertyDescriptor, di = (i, e, t, n) => {
1549
+ for (var r = n > 1 ? void 0 : n ? li(e, t) : e, s = i.length - 1, o; s >= 0; s--)
1550
+ (o = i[s]) && (r = (n ? o(e, t, r) : o(r)) || r);
1551
+ return n && r && ai(e, t, r), r;
1552
+ }, q = (i, e) => (t, n) => e(t, n, i);
1553
+ let be = class extends H {
1554
+ constructor(e, t, n, r, s, o) {
1555
+ super();
1556
+ S(this, "_initializedRender", /* @__PURE__ */ new Set());
1557
+ this._docSkeletonManagerService = e, this._currentUniverService = t, this._commandService = n, this._renderManagerService = r, this._textSelectionManagerService = s, this._editorService = o, this._initialize();
1558
+ }
1559
+ dispose() {
1560
+ super.dispose();
1561
+ }
1562
+ _initialize() {
1563
+ this._skeletonListener(), this._commandExecutedListener(), this._initialRenderRefresh();
1564
+ }
1565
+ _initialRenderRefresh() {
1566
+ this._docSkeletonManagerService.currentSkeleton$.subscribe((e) => {
1567
+ if (e == null)
1568
+ return;
1569
+ const { unitId: t } = e, n = this._renderManagerService.getRenderById(t);
1570
+ if (n == null || this._initializedRender.has(t) || this._editorService.isEditor(t))
1571
+ return;
1572
+ this._initializedRender.add(t);
1573
+ const { scene: r } = n;
1574
+ this.disposeWithMe(
1575
+ N(
1576
+ r.onMouseWheelObserver.add((s) => {
1577
+ if (!s.ctrlKey)
1578
+ return;
1579
+ const o = Math.abs(s.deltaX);
1580
+ let c = o < 40 ? 0.2 : o < 80 ? 0.4 : 0.2;
1581
+ c *= s.deltaY > 0 ? -1 : 1, r.scaleX < 1 && (c /= 2);
1582
+ const l = this._currentUniverService.getCurrentUniverDocInstance(), d = l.zoomRatio;
1583
+ let u = +Number.parseFloat(`${d + c}`).toFixed(1);
1584
+ u = u >= 4 ? 4 : u <= 0.1 ? 0.1 : u, this._commandService.executeCommand(Sn.id, {
1585
+ zoomRatio: u,
1586
+ unitId: l.getUnitId()
1587
+ }), s.preventDefault();
1588
+ })
1589
+ )
1590
+ );
1591
+ });
1592
+ }
1593
+ // private _zoomEventBinding() {
1594
+ // const scene = this._getDocObject()?.scene;
1595
+ // if (scene == null) {
1596
+ // return;
1597
+ // }
1598
+ // const viewportMain = scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);
1599
+ // }
1600
+ _skeletonListener() {
1601
+ this.disposeWithMe(
1602
+ N(
1603
+ this._docSkeletonManagerService.currentSkeleton$.subscribe((e) => {
1604
+ if (e == null)
1605
+ return;
1606
+ const n = this._currentUniverService.getCurrentUniverDocInstance().zoomRatio || 1;
1607
+ this._updateViewZoom(n, !1);
1608
+ })
1609
+ )
1610
+ );
1611
+ }
1612
+ _commandExecutedListener() {
1613
+ const e = [Xe.id];
1614
+ this.disposeWithMe(
1615
+ this._commandService.onCommandExecuted((t) => {
1616
+ if (e.includes(t.id)) {
1617
+ const n = this._currentUniverService.getCurrentUniverDocInstance(), r = t.params, { unitId: s } = r;
1618
+ if (s !== n.getUnitId())
1619
+ return;
1620
+ const o = n.zoomRatio || 1;
1621
+ this._updateViewZoom(o);
1622
+ }
1623
+ })
1624
+ );
1625
+ }
1626
+ _updateViewZoom(e, t = !0) {
1627
+ var r;
1628
+ const n = this._getDocObject();
1629
+ n != null && (n.scene.scale(e, e), this._calculatePagePosition(n, e), t && this._textSelectionManagerService.refreshSelection(), (r = n.scene.getTransformer()) == null || r.hideControl());
1630
+ }
1631
+ _calculatePagePosition(e, t) {
1632
+ const { document: n, scene: r } = e, s = r == null ? void 0 : r.getParent(), { width: o, height: c, pageMarginLeft: l, pageMarginTop: d } = n;
1633
+ if (s == null || o === Number.POSITIVE_INFINITY || c === Number.POSITIVE_INFINITY)
1634
+ return;
1635
+ const { width: u, height: _ } = s;
1636
+ let g = 0, f = 0, p = 0, a = 0, h = Number.POSITIVE_INFINITY;
1637
+ u > (o + l * 2) * t ? (g = u / 2 - o * t / 2, g /= t, p = (u - l * 2) / t, h = 0) : (g = l, p = o + l * 2, h = (p - u / t) / 2), _ > c ? (f = _ / 2 - c / 2, a = (_ - d * 2) / t) : (f = d, a = c + d * 2), r.resize(p, a + 200), n.translate(g, f);
1638
+ const C = r.getViewport(Pe.VIEW_MAIN);
1639
+ if (h !== Number.POSITIVE_INFINITY && C != null) {
1640
+ const R = C.getBarScroll(h, 0).x;
1641
+ C.scrollTo({
1642
+ x: R
1643
+ });
1644
+ }
1645
+ return this;
1646
+ }
1647
+ _getDocObject() {
1648
+ return vt(this._currentUniverService, this._renderManagerService);
1649
+ }
1650
+ };
1651
+ be = di([
1652
+ P(U.Rendered, be),
1653
+ q(0, v(Q)),
1654
+ q(1, M),
1655
+ q(2, O),
1656
+ q(3, Y),
1657
+ q(4, v(le)),
1658
+ q(5, $)
1659
+ ], be);
1660
+ var ui = Object.defineProperty, hi = Object.getOwnPropertyDescriptor, _i = (i, e, t, n) => {
1661
+ for (var r = n > 1 ? void 0 : n ? hi(e, t) : e, s = i.length - 1, o; s >= 0; s--)
1662
+ (o = i[s]) && (r = (n ? o(e, t, r) : o(r)) || r);
1663
+ return n && r && ui(e, t, r), r;
1664
+ }, k = (i, e) => (t, n) => e(t, n, i);
1665
+ let Ie = class extends H {
1666
+ constructor(e, t, n, r, s, o, c) {
1667
+ super();
1668
+ S(this, "_loadedMap", /* @__PURE__ */ new WeakSet());
1669
+ this._docSkeletonManagerService = e, this._currentUniverService = t, this._commandService = n, this._renderManagerService = r, this._textSelectionRenderManager = s, this._textSelectionManagerService = o, this._editorService = c, this._initialize();
1670
+ }
1671
+ _initialize() {
1672
+ this._init(), this._skeletonListener(), this._commandExecutedListener();
1673
+ }
1674
+ _init() {
1675
+ this.disposeWithMe(
1676
+ this._renderManagerService.currentRender$.subscribe((e) => {
1677
+ this._create(e);
1678
+ })
1679
+ ), this._renderManagerService.getRenderAll().forEach((e, t) => {
1680
+ this._create(t);
1681
+ });
1682
+ }
1683
+ _create(e) {
1684
+ if (e == null || this._currentUniverService.getUniverDocInstance(e) == null)
1685
+ return;
1686
+ const t = this._getDocObjectById(e);
1687
+ t == null || t.document == null || this._loadedMap.has(t.document) || (this._initialMain(e), this._loadedMap.add(t.document));
1688
+ }
1689
+ _initialMain(e) {
1690
+ const t = this._getDocObjectById(e);
1691
+ if (t == null)
1692
+ return;
1693
+ const { document: n, scene: r } = t;
1694
+ this.disposeWithMe(
1695
+ N(
1696
+ n.onPointerEnterObserver.add(() => {
1697
+ this._isEditorReadOnly(e) || (n.cursor = st.TEXT);
1698
+ })
1699
+ )
1700
+ ), this.disposeWithMe(
1701
+ N(
1702
+ n.onPointerLeaveObserver.add(() => {
1703
+ n.cursor = st.DEFAULT, r.resetCursor();
1704
+ })
1705
+ )
1706
+ ), this.disposeWithMe(
1707
+ N(
1708
+ n == null ? void 0 : n.onPointerDownObserver.add((s, o) => {
1709
+ if (this._isEditorReadOnly(e))
1710
+ return;
1711
+ this._currentUniverService.getCurrentUniverDocInstance().getUnitId() !== e && this._currentUniverService.setCurrentUniverDocInstance(e), this._textSelectionRenderManager.eventTrigger(s), this._setEditorFocus(e), s.button !== 2 && o.stopPropagation();
1712
+ })
1713
+ )
1714
+ ), this.disposeWithMe(
1715
+ N(
1716
+ n == null ? void 0 : n.onDblclickObserver.add((s) => {
1717
+ this._textSelectionRenderManager.handleDblClick(s);
1718
+ })
1719
+ )
1720
+ ), this.disposeWithMe(
1721
+ N(
1722
+ n == null ? void 0 : n.onTripleClickObserver.add((s) => {
1723
+ this._textSelectionRenderManager.handleTripleClick(s);
1724
+ })
1725
+ )
1726
+ );
1727
+ }
1728
+ _isEditorReadOnly(e) {
1729
+ const t = this._editorService.getEditor(e);
1730
+ return t ? t.isReadOnly() : !1;
1731
+ }
1732
+ _setEditorFocus(e) {
1733
+ if (this._currentUniverService.getAllUniverSheetsInstance().length > 0) {
1734
+ const n = this._currentUniverService.getCurrentUniverSheetInstance();
1735
+ this._editorService.setOperationSheetUnitId(n.getUnitId());
1736
+ }
1737
+ this._editorService.focusStyle(e);
1738
+ }
1739
+ _commandExecutedListener() {
1740
+ const e = [Xe.id];
1741
+ this.disposeWithMe(
1742
+ this._commandService.onCommandExecuted((t) => {
1743
+ var n;
1744
+ if (e.includes(t.id)) {
1745
+ const r = t.params, { unitId: s } = r, o = (n = this._textSelectionManagerService.getCurrentSelection()) == null ? void 0 : n.unitId;
1746
+ if (s !== o)
1747
+ return;
1748
+ this._textSelectionManagerService.refreshSelection();
1749
+ }
1750
+ })
1751
+ );
1752
+ }
1753
+ _skeletonListener() {
1754
+ this.disposeWithMe(
1755
+ this._docSkeletonManagerService.currentSkeleton$.subscribe((e) => {
1756
+ if (e == null)
1757
+ return;
1758
+ const { unitId: t, skeleton: n } = e, r = this._renderManagerService.getRenderById(t);
1759
+ if (r == null)
1760
+ return;
1761
+ const { scene: s, mainComponent: o } = r;
1762
+ this._textSelectionRenderManager.changeRuntime(n, s, o), this._textSelectionManagerService.setCurrentSelectionNotRefresh({
1763
+ unitId: t,
1764
+ subUnitId: ""
1765
+ });
1766
+ })
1767
+ );
1768
+ }
1769
+ _getDocObjectById(e) {
1770
+ return mn(e, this._renderManagerService);
1771
+ }
1772
+ };
1773
+ Ie = _i([
1774
+ P(U.Rendered, Ie),
1775
+ k(0, v(Q)),
1776
+ k(1, M),
1777
+ k(2, O),
1778
+ k(3, Y),
1779
+ k(4, de),
1780
+ k(5, v(le)),
1781
+ k(6, $)
1782
+ ], Ie);
1783
+ var pi = Object.defineProperty, gi = Object.getOwnPropertyDescriptor, fi = (i, e, t, n) => {
1784
+ for (var r = n > 1 ? void 0 : n ? gi(e, t) : e, s = i.length - 1, o; s >= 0; s--)
1785
+ (o = i[s]) && (r = (n ? o(e, t, r) : o(r)) || r);
1786
+ return n && r && pi(e, t, r), r;
1787
+ }, re = (i, e) => (t, n) => e(t, n, i);
1788
+ const ut = 1.5;
1789
+ let Te = class extends ce {
1790
+ constructor(i, e, t, n, r) {
1791
+ super(), this._docSkeletonManagerService = i, this._textSelectionManagerService = e, this._editorService = t, this._currentUniverService = n, this._renderManagerService = r, this._init();
1792
+ }
1793
+ _init() {
1794
+ this._textSelectionManagerService.textSelection$.pipe(oe(this.dispose$)).subscribe((i) => {
1795
+ if (i == null)
1796
+ return;
1797
+ const { isEditing: e, unitId: t } = i;
1798
+ e && this._scrollToSelection(t);
1799
+ });
1800
+ }
1801
+ // Let the selection show on the current screen.
1802
+ _scrollToSelection(i) {
1803
+ var b;
1804
+ const e = this._textSelectionManagerService.getActiveRange(), t = this._getDocObject(), n = (b = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : b.skeleton;
1805
+ if (e == null || t == null || n == null)
1806
+ return;
1807
+ const { collapsed: r, startNodePosition: s } = e;
1808
+ if (!r)
1809
+ return;
1810
+ const o = t.document.getOffsetConfig(), { docsLeft: c, docsTop: l } = o, d = new In(o, n), { contentBoxPointGroup: u } = d.getRangePointData(s, s), { left: _, top: g, height: f } = Tn(u), p = _ + c, a = g + l, h = t.scene.getViewport(Pe.VIEW_MAIN), C = !!this._editorService.getEditor(i);
1811
+ if (h == null)
1812
+ return;
1813
+ const {
1814
+ left: R,
1815
+ top: w,
1816
+ right: B,
1817
+ bottom: F
1818
+ } = h.getBounding().viewBound;
1819
+ let X = 0, G = 0;
1820
+ const he = C ? 0 : 100;
1821
+ a < w ? X = a - w : a > F - f && (X = a - F + f + he), p < R ? G = p - R : p > B - ut && (G = p - B + ut);
1822
+ const _e = h.getBarScroll(G, X);
1823
+ h.scrollBy(_e);
1824
+ }
1825
+ _getDocObject() {
1826
+ return vt(this._currentUniverService, this._renderManagerService);
1827
+ }
1828
+ };
1829
+ Te = fi([
1830
+ P(U.Rendered, Te),
1831
+ re(0, v(Q)),
1832
+ re(1, v(le)),
1833
+ re(2, $),
1834
+ re(3, M),
1835
+ re(4, Y)
1836
+ ], Te);
1837
+ var Si = Object.defineProperty, mi = Object.getOwnPropertyDescriptor, vi = (i, e, t, n) => {
1838
+ for (var r = n > 1 ? void 0 : n ? mi(e, t) : e, s = i.length - 1, o; s >= 0; s--)
1839
+ (o = i[s]) && (r = (n ? o(e, t, r) : o(r)) || r);
1840
+ return n && r && Si(e, t, r), r;
1841
+ }, we = (i, e) => (t, n) => e(t, n, i), Be;
1842
+ let ht = (Be = class extends wt {
1843
+ constructor(i, e, t, n) {
1844
+ super(Ln), this._config = i, this._injector = e, this._localeService = t, this._logService = n, this._localeService.load({
1845
+ zhCN: Cr
1846
+ }), this._config = pt.deepMerge({}, Un, this._config), this._initDependencies(e), this._initializeCommands();
1091
1847
  }
1092
1848
  onRendered() {
1093
1849
  this._initModules(), this._markDocAsFocused();
@@ -1096,67 +1852,78 @@ let _e = (q = class extends Be {
1096
1852
  }
1097
1853
  _initializeCommands() {
1098
1854
  [
1099
- vt,
1100
- Rt,
1101
- It,
1102
- yt,
1103
- bt,
1104
- xt,
1105
- Dt,
1106
- Pt,
1107
- Mt,
1108
- Qt,
1109
- en,
1110
- Jt
1111
- ].forEach((e) => {
1112
- this._injector.get(ye).registerShortcut(e);
1855
+ $n,
1856
+ An,
1857
+ Bn,
1858
+ wn,
1859
+ Fn,
1860
+ jn,
1861
+ Wn,
1862
+ zn,
1863
+ Vn,
1864
+ Rr,
1865
+ br,
1866
+ Or
1867
+ ].forEach((i) => {
1868
+ this._injector.get(en).registerShortcut(i);
1113
1869
  });
1114
1870
  }
1115
- _initDependencies(e) {
1871
+ _initDependencies(i) {
1116
1872
  [
1117
- [V],
1118
- [W],
1873
+ // Controller
1874
+ [fe],
1875
+ [Se],
1876
+ [me],
1877
+ [ve],
1878
+ [Oe],
1879
+ [Re],
1880
+ [be],
1881
+ [Ie],
1882
+ [Te],
1119
1883
  [
1120
1884
  // controllers
1121
- F,
1885
+ ie,
1122
1886
  {
1123
- useFactory: () => this._injector.createInstance(F, this._config)
1887
+ useFactory: () => this._injector.createInstance(ie, this._config)
1124
1888
  }
1125
1889
  ],
1126
1890
  [
1127
- B,
1891
+ ue,
1128
1892
  {
1129
- useClass: Q
1893
+ useClass: We
1130
1894
  }
1131
- ]
1132
- ].forEach((n) => {
1133
- e.add(n);
1895
+ ],
1896
+ // Render views
1897
+ [Ce]
1898
+ ].forEach((t) => {
1899
+ i.add(t);
1134
1900
  });
1135
1901
  }
1136
1902
  _markDocAsFocused() {
1137
- const e = this._injector.get(te);
1903
+ const i = this._injector.get(M), e = this._injector.get($);
1138
1904
  try {
1139
- const t = e.getCurrentUniverDocInstance(), n = t.getUnitId();
1140
- n !== He && n !== Ve && e.focusUniverInstance(t.getUnitId());
1905
+ const t = i.getCurrentUniverDocInstance(), n = t.getUnitId();
1906
+ e.isEditor(n) || i.focusUniverInstance(t.getUnitId());
1141
1907
  } catch (t) {
1142
1908
  this._logService.warn(t);
1143
1909
  }
1144
1910
  }
1145
1911
  _initModules() {
1146
- this._injector.get(F);
1147
- }
1148
- }, h(q, "type", je.Doc), q);
1149
- _e = In([
1150
- X(1, y(Y)),
1151
- X(2, y(ee)),
1152
- X(3, Re)
1153
- ], _e);
1912
+ this._injector.get(ie);
1913
+ }
1914
+ }, S(Be, "type", Bt.Doc), Be);
1915
+ ht = vi([
1916
+ we(1, v(Ee)),
1917
+ we(2, v(Ve)),
1918
+ we(3, gt)
1919
+ ], ht);
1154
1920
  export {
1155
- Tt as DOC_UI_PLUGIN_NAME,
1156
- St as DefaultDocContainerConfig,
1157
- Ot as DefaultDocUiConfig,
1158
- Ct as DefaultToolbarConfig,
1159
- _e as UniverDocsUIPlugin,
1160
- Nn as enUS,
1161
- qt as zhCN
1921
+ Ln as DOC_UI_PLUGIN_NAME,
1922
+ Pn as DefaultDocContainerConfig,
1923
+ Un as DefaultDocUiConfig,
1924
+ xn as DefaultToolbarConfig,
1925
+ Ce as DocCanvasView,
1926
+ ht as UniverDocsUIPlugin,
1927
+ xi as enUS,
1928
+ Cr as zhCN
1162
1929
  };