@univerjs/docs 0.1.0-alpha.1 → 0.1.0-alpha.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.
Files changed (135) hide show
  1. package/LICENSE.txt +178 -0
  2. package/lib/cjs/index.js +2 -5928
  3. package/lib/es/index.js +2885 -0
  4. package/lib/types/basics/component-tools.d.ts +15 -1
  5. package/lib/types/basics/demo-data.d.ts +15 -1
  6. package/lib/types/basics/docs-view-key.d.ts +15 -1
  7. package/lib/types/basics/retain-delete-params.d.ts +15 -1
  8. package/lib/types/commands/commands/__tests__/clipboard.command.spec.d.ts +15 -1
  9. package/lib/types/commands/commands/__tests__/core-editing.command.spec.d.ts +15 -1
  10. package/lib/types/commands/commands/__tests__/create-command-test-bed.d.ts +15 -1
  11. package/lib/types/commands/commands/__tests__/inline-format.command.spec.d.ts +15 -1
  12. package/lib/types/commands/commands/__tests__/replace-content.command.spec.d.ts +15 -1
  13. package/lib/types/commands/commands/clipboard.command.d.ts +15 -1
  14. package/lib/types/commands/commands/clipboard.inner.command.d.ts +15 -1
  15. package/lib/types/commands/commands/core-editing.command.d.ts +16 -1
  16. package/lib/types/commands/commands/ime-input.command.d.ts +15 -1
  17. package/lib/types/commands/commands/inline-format.command.d.ts +15 -1
  18. package/lib/types/commands/commands/insert-floating-object.command.d.ts +15 -1
  19. package/lib/types/commands/commands/remove-floating-object.command.d.ts +15 -1
  20. package/lib/types/commands/commands/replace-content.command.d.ts +15 -1
  21. package/lib/types/commands/commands/set-doc-zoom-ratio.command.d.ts +15 -1
  22. package/lib/types/commands/commands/set-floating-object-transform.command.d.ts +15 -1
  23. package/lib/types/commands/mutations/core-editing.mutation.d.ts +15 -1
  24. package/lib/types/commands/mutations/insert-floating-object.mutation.d.ts +15 -1
  25. package/lib/types/commands/mutations/remove-floating-object.mutation.d.ts +15 -1
  26. package/lib/types/commands/mutations/set-floating-object.mutation.d.ts +15 -1
  27. package/lib/types/commands/operations/cursor.operation.d.ts +15 -1
  28. package/lib/types/commands/operations/select-all.operation.d.ts +15 -1
  29. package/lib/types/commands/operations/set-doc-zoom-ratio.operation.d.ts +15 -1
  30. package/lib/types/commands/operations/text-selection.operation.d.ts +15 -1
  31. package/lib/types/controllers/clipboard.controller.d.ts +15 -1
  32. package/lib/types/controllers/delete.controller.d.ts +15 -1
  33. package/lib/types/controllers/doc-render.controller.d.ts +16 -3
  34. package/lib/types/controllers/floating-object.controller.d.ts +15 -1
  35. package/lib/types/controllers/ime-input.controller.d.ts +15 -1
  36. package/lib/types/controllers/inline-format.controller.d.ts +15 -1
  37. package/lib/types/controllers/line-break-input.controller.d.ts +15 -1
  38. package/lib/types/controllers/move-cursor.controller.d.ts +15 -1
  39. package/lib/types/controllers/normal-input.controller.d.ts +15 -1
  40. package/lib/types/controllers/page-render.controller.d.ts +15 -1
  41. package/lib/types/controllers/text-selection.controller.d.ts +15 -1
  42. package/lib/types/controllers/zoom.controller.d.ts +15 -1
  43. package/lib/types/doc-plugin.d.ts +18 -4
  44. package/lib/types/index.d.ts +16 -2
  45. package/lib/types/services/clipboard/__test__/html-and-udm-convert.spec.d.ts +15 -1
  46. package/lib/types/services/clipboard/clipboard.service.d.ts +15 -1
  47. package/lib/types/services/clipboard/copy-content-cache.d.ts +15 -1
  48. package/lib/types/services/clipboard/html-to-udm/converter.d.ts +15 -1
  49. package/lib/types/services/clipboard/html-to-udm/parse-node-style.d.ts +15 -1
  50. package/lib/types/services/clipboard/html-to-udm/parse-to-dom.d.ts +15 -1
  51. package/lib/types/services/clipboard/html-to-udm/paste-plugins/plugin-lark.d.ts +15 -1
  52. package/lib/types/services/clipboard/html-to-udm/paste-plugins/plugin-word.d.ts +15 -1
  53. package/lib/types/services/clipboard/html-to-udm/paste-plugins/type.d.ts +15 -1
  54. package/lib/types/services/clipboard/html-to-udm/utils.d.ts +15 -1
  55. package/lib/types/services/clipboard/udm-to-html/convertor.d.ts +15 -1
  56. package/lib/types/services/doc-skeleton-manager.service.d.ts +15 -1
  57. package/lib/types/services/doc-view-model-manager.service.d.ts +15 -1
  58. package/lib/types/services/ime-input-manager.service.d.ts +15 -1
  59. package/lib/types/services/text-selection-manager.service.d.ts +15 -1
  60. package/lib/types/shortcuts/core-editing.shortcut.d.ts +15 -1
  61. package/lib/types/shortcuts/cursor.shortcut.d.ts +15 -1
  62. package/lib/types/views/doc-canvas-view.d.ts +15 -1
  63. package/lib/umd/index.js +2 -0
  64. package/package.json +28 -25
  65. package/LICENSE +0 -21
  66. package/lib/cjs/locale/en-US.js +0 -26
  67. package/lib/cjs/locale/zh-CN.js +0 -26
  68. package/lib/esm/index.js +0 -5845
  69. package/lib/esm/locale/en-US.js +0 -5
  70. package/lib/esm/locale/zh-CN.js +0 -5
  71. package/lib/types/basics/component-tools.d.ts.map +0 -1
  72. package/lib/types/basics/demo-data.d.ts.map +0 -1
  73. package/lib/types/basics/docs-view-key.d.ts.map +0 -1
  74. package/lib/types/basics/retain-delete-params.d.ts.map +0 -1
  75. package/lib/types/commands/commands/__tests__/clipboard.command.spec.d.ts.map +0 -1
  76. package/lib/types/commands/commands/__tests__/core-editing.command.spec.d.ts.map +0 -1
  77. package/lib/types/commands/commands/__tests__/create-command-test-bed.d.ts.map +0 -1
  78. package/lib/types/commands/commands/__tests__/inline-format.command.spec.d.ts.map +0 -1
  79. package/lib/types/commands/commands/__tests__/replace-content.command.spec.d.ts.map +0 -1
  80. package/lib/types/commands/commands/clipboard.command.d.ts.map +0 -1
  81. package/lib/types/commands/commands/clipboard.inner.command.d.ts.map +0 -1
  82. package/lib/types/commands/commands/core-editing.command.d.ts.map +0 -1
  83. package/lib/types/commands/commands/ime-input.command.d.ts.map +0 -1
  84. package/lib/types/commands/commands/inline-format.command.d.ts.map +0 -1
  85. package/lib/types/commands/commands/insert-floating-object.command.d.ts.map +0 -1
  86. package/lib/types/commands/commands/remove-floating-object.command.d.ts.map +0 -1
  87. package/lib/types/commands/commands/replace-content.command.d.ts.map +0 -1
  88. package/lib/types/commands/commands/set-doc-zoom-ratio.command.d.ts.map +0 -1
  89. package/lib/types/commands/commands/set-floating-object-transform.command.d.ts.map +0 -1
  90. package/lib/types/commands/mutations/core-editing.mutation.d.ts.map +0 -1
  91. package/lib/types/commands/mutations/insert-floating-object.mutation.d.ts.map +0 -1
  92. package/lib/types/commands/mutations/remove-floating-object.mutation.d.ts.map +0 -1
  93. package/lib/types/commands/mutations/set-floating-object.mutation.d.ts.map +0 -1
  94. package/lib/types/commands/operations/cursor.operation.d.ts.map +0 -1
  95. package/lib/types/commands/operations/select-all.operation.d.ts.map +0 -1
  96. package/lib/types/commands/operations/set-doc-zoom-ratio.operation.d.ts.map +0 -1
  97. package/lib/types/commands/operations/text-selection.operation.d.ts.map +0 -1
  98. package/lib/types/controllers/clipboard.controller.d.ts.map +0 -1
  99. package/lib/types/controllers/delete.controller.d.ts.map +0 -1
  100. package/lib/types/controllers/doc-render.controller.d.ts.map +0 -1
  101. package/lib/types/controllers/floating-object.controller.d.ts.map +0 -1
  102. package/lib/types/controllers/ime-input.controller.d.ts.map +0 -1
  103. package/lib/types/controllers/inline-format.controller.d.ts.map +0 -1
  104. package/lib/types/controllers/line-break-input.controller.d.ts.map +0 -1
  105. package/lib/types/controllers/move-cursor.controller.d.ts.map +0 -1
  106. package/lib/types/controllers/normal-input.controller.d.ts.map +0 -1
  107. package/lib/types/controllers/page-render.controller.d.ts.map +0 -1
  108. package/lib/types/controllers/text-selection.controller.d.ts.map +0 -1
  109. package/lib/types/controllers/zoom.controller.d.ts.map +0 -1
  110. package/lib/types/doc-plugin.d.ts.map +0 -1
  111. package/lib/types/index.d.ts.map +0 -1
  112. package/lib/types/locale/en-US.d.ts +0 -3
  113. package/lib/types/locale/en-US.d.ts.map +0 -1
  114. package/lib/types/locale/index.d.ts +0 -3
  115. package/lib/types/locale/index.d.ts.map +0 -1
  116. package/lib/types/locale/zh-CN.d.ts +0 -3
  117. package/lib/types/locale/zh-CN.d.ts.map +0 -1
  118. package/lib/types/services/clipboard/__test__/html-and-udm-convert.spec.d.ts.map +0 -1
  119. package/lib/types/services/clipboard/clipboard.service.d.ts.map +0 -1
  120. package/lib/types/services/clipboard/copy-content-cache.d.ts.map +0 -1
  121. package/lib/types/services/clipboard/html-to-udm/converter.d.ts.map +0 -1
  122. package/lib/types/services/clipboard/html-to-udm/parse-node-style.d.ts.map +0 -1
  123. package/lib/types/services/clipboard/html-to-udm/parse-to-dom.d.ts.map +0 -1
  124. package/lib/types/services/clipboard/html-to-udm/paste-plugins/plugin-lark.d.ts.map +0 -1
  125. package/lib/types/services/clipboard/html-to-udm/paste-plugins/plugin-word.d.ts.map +0 -1
  126. package/lib/types/services/clipboard/html-to-udm/paste-plugins/type.d.ts.map +0 -1
  127. package/lib/types/services/clipboard/html-to-udm/utils.d.ts.map +0 -1
  128. package/lib/types/services/clipboard/udm-to-html/convertor.d.ts.map +0 -1
  129. package/lib/types/services/doc-skeleton-manager.service.d.ts.map +0 -1
  130. package/lib/types/services/doc-view-model-manager.service.d.ts.map +0 -1
  131. package/lib/types/services/ime-input-manager.service.d.ts.map +0 -1
  132. package/lib/types/services/text-selection-manager.service.d.ts.map +0 -1
  133. package/lib/types/shortcuts/core-editing.shortcut.d.ts.map +0 -1
  134. package/lib/types/shortcuts/cursor.shortcut.d.ts.map +0 -1
  135. package/lib/types/views/doc-canvas-view.d.ts.map +0 -1
@@ -0,0 +1,2885 @@
1
+ var Lt = Object.defineProperty;
2
+ var At = (r, e, t) => e in r ? Lt(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var _ = (r, e, t) => (At(r, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { CommandType as C, FOCUSING_DOC as T, FOCUSING_EDITOR as ge, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as te, IUniverInstanceService as I, MemoryCursor as He, IUndoRedoService as B, ICommandService as D, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as ne, BooleanNumber as O, Tools as Q, getDocsUpdateBody as Nt, LRUMap as $t, BaselineOffset as Le, Disposable as w, toDisposable as Ke, OnLifecycle as U, LifecycleStages as L, ILogService as Bt, IContextService as jt, LocaleService as xt, UpdateDocsAttributeType as Vt, DEFAULT_DOCUMENT_SUB_COMPONENT_ID as kt, IFloatingObjectManagerService as Ft, DataStreamTreeTokenType as Je, Direction as R, IConfigService as Ot, Plugin as zt, PluginType as Wt } from "@univerjs/core";
5
+ import { CopyCommand as Ht, CutCommand as Gt, PasteCommand as Xt, PLAIN_TEXT_CLIPBOARD_MIME_TYPE as qt, HTML_CLIPBOARD_MIME_TYPE as Yt, IClipboardInterfaceService as Zt, KeyCode as N, MetaKeys as fe, IShortcutService as Kt } from "@univerjs/ui";
6
+ import { BehaviorSubject as Ae } from "rxjs";
7
+ import { DocumentViewModel as Jt, ITextSelectionRenderManager as V, DocumentSkeleton as Qt, hasListSpan as lt, isIndentBySpan as en, isFirstSpan as tn, getParagraphBySpan as nn, isSameLine as rn, PageLayoutType as dt, IRenderManagerService as j, Liquid as sn, RANGE_DIRECTION as ut, NodePositionConvertToCursor as ht, Rect as on, CURSOR_TYPE as gt, Viewport as an, EVENT_TYPE as cn, ScrollBar as ln, Layer as ft, Documents as dn, TextSelectionRenderManager as un } from "@univerjs/engine-render";
8
+ import { createIdentifier as hn, Inject as b, Injector as gn } from "@wendellhu/redi";
9
+ import { TinyColor as pt } from "@ctrl/tinycolor";
10
+ function pe(r, e) {
11
+ const n = r.getCurrentUniverDocInstance().getUnitId(), s = e.getRenderById(n);
12
+ if (s == null)
13
+ return;
14
+ const { mainComponent: i, scene: o, engine: a } = s;
15
+ return {
16
+ document: i,
17
+ scene: o,
18
+ engine: a
19
+ };
20
+ }
21
+ function fn(r, e) {
22
+ const t = e.getRenderById(r);
23
+ if (t == null)
24
+ return;
25
+ const { components: n, mainComponent: s, scene: i, engine: o } = t;
26
+ return {
27
+ document: s,
28
+ scene: i,
29
+ engine: o
30
+ };
31
+ }
32
+ var Qe = /* @__PURE__ */ ((r) => (r.MAIN = "__Document_Render_Main__", r))(Qe || {}), ue = /* @__PURE__ */ ((r) => (r.VIEW_MAIN = "viewMain", r.VIEW_TOP = "viewTop", r.VIEW_LEFT = "viewLeft", r.VIEW_LEFT_TOP = "viewLeftTop", r))(ue || {});
33
+ const mt = 0, pn = 2, mn = 10, Ne = "normalTextSelectionPluginName", Ge = {
34
+ id: Ht.id,
35
+ name: "doc.command.copy",
36
+ type: C.COMMAND,
37
+ multi: !0,
38
+ priority: 999,
39
+ preconditions: (r) => r.getContextValue(T) || r.getContextValue(ge),
40
+ handler: async () => !0
41
+ }, Xe = {
42
+ id: Gt.id,
43
+ name: "doc.command.cut",
44
+ type: C.COMMAND,
45
+ multi: !0,
46
+ priority: 999,
47
+ preconditions: (r) => r.getContextValue(T) || r.getContextValue(ge),
48
+ handler: async () => !0
49
+ }, qe = {
50
+ id: Xt.id,
51
+ name: "doc.command.paste",
52
+ type: C.COMMAND,
53
+ multi: !0,
54
+ priority: 999,
55
+ preconditions: (r) => r.getContextValue(T) || r.getContextValue(ge),
56
+ handler: async () => !0
57
+ };
58
+ function me(r, e = "", t = 0) {
59
+ const { startOffset: n, endOffset: s } = r, i = [], o = n - t, a = s - t;
60
+ return o > 0 && i.push({
61
+ t: "r",
62
+ len: o,
63
+ segmentId: e
64
+ }), i.push({
65
+ t: "d",
66
+ len: a - o,
67
+ line: 0,
68
+ segmentId: e
69
+ }), i;
70
+ }
71
+ class P {
72
+ constructor() {
73
+ _(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
74
+ _(this, "_currentSelection", null);
75
+ _(this, "_textSelectionInfo$", new Ae(null));
76
+ _(this, "textSelectionInfo$", this._textSelectionInfo$.asObservable());
77
+ }
78
+ getCurrentSelection() {
79
+ return this._currentSelection;
80
+ }
81
+ dispose() {
82
+ this._textSelectionInfo$.complete();
83
+ }
84
+ refreshSelection() {
85
+ this._currentSelection != null && this._refresh(this._currentSelection);
86
+ }
87
+ setCurrentSelection(e) {
88
+ this._currentSelection = e, this._refresh(e);
89
+ }
90
+ setCurrentSelectionNotRefresh(e) {
91
+ this._currentSelection = e;
92
+ }
93
+ getTextSelectionInfo() {
94
+ return this._textSelectionInfo;
95
+ }
96
+ getTextRangesByParam(e) {
97
+ return this._getTextRanges(e);
98
+ }
99
+ getSelections() {
100
+ return this._getTextRanges(this._currentSelection);
101
+ }
102
+ getFirst() {
103
+ return this._getFirstByParam(this._currentSelection);
104
+ }
105
+ getLast() {
106
+ return this._getLastByParam(this._currentSelection);
107
+ }
108
+ // Only used in tests.
109
+ add(e) {
110
+ this._currentSelection != null && this._addByParam({
111
+ ...this._currentSelection,
112
+ textRanges: e
113
+ });
114
+ }
115
+ replaceTextRanges(e) {
116
+ this._currentSelection != null && this._textSelectionInfo$.next(e);
117
+ }
118
+ replaceTextRangesWithNoRefresh(e) {
119
+ this._currentSelection != null && this._replaceByParam({
120
+ ...this._currentSelection,
121
+ textRanges: e
122
+ });
123
+ }
124
+ _addByParam(e) {
125
+ const { pluginName: t, unitId: n, textRanges: s } = e;
126
+ this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map());
127
+ const i = this._textSelectionInfo.get(t);
128
+ i.has(n) ? i.get(n).push(...s) : i.set(n, [...s]), this._refresh({ pluginName: t, unitId: n });
129
+ }
130
+ // It is will being opened when it needs to be used
131
+ _clear() {
132
+ this._currentSelection != null && this._clearByParam(this._currentSelection);
133
+ }
134
+ // It is will being opened when it needs to be used
135
+ _remove(e) {
136
+ this._currentSelection != null && this._removeByParam(e, this._currentSelection);
137
+ }
138
+ // It is will being opened when it needs to be used
139
+ _reset() {
140
+ var e;
141
+ this._currentSelection != null && (this._currentSelection = {
142
+ pluginName: Ne,
143
+ unitId: (e = this._currentSelection) == null ? void 0 : e.unitId
144
+ }, this._textSelectionInfo.clear(), this._refresh(this._currentSelection));
145
+ }
146
+ // It is will being opened when it needs to be used
147
+ _resetPlugin() {
148
+ this._currentSelection != null && (this._currentSelection.pluginName = Ne, this._refresh(this._currentSelection));
149
+ }
150
+ _getTextRanges(e) {
151
+ var s;
152
+ if (e == null)
153
+ return;
154
+ const { pluginName: t, unitId: n } = e;
155
+ return (s = this._textSelectionInfo.get(t)) == null ? void 0 : s.get(n);
156
+ }
157
+ _refresh(e) {
158
+ const t = this._getTextRanges(e) ?? [];
159
+ this._textSelectionInfo$.next(
160
+ t.map((n) => {
161
+ const s = n.startOffset, i = n.endOffset, o = n.collapsed, a = n.style;
162
+ return {
163
+ startOffset: s,
164
+ endOffset: i,
165
+ collapsed: o,
166
+ style: a
167
+ };
168
+ })
169
+ );
170
+ }
171
+ _getFirstByParam(e) {
172
+ const t = this._getTextRanges(e);
173
+ return t == null ? void 0 : t[0];
174
+ }
175
+ _getLastByParam(e) {
176
+ const t = this._getTextRanges(e);
177
+ return t == null ? void 0 : t[t.length - 1];
178
+ }
179
+ _replaceByParam(e) {
180
+ const { pluginName: t, unitId: n, textRanges: s } = e;
181
+ this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(t).set(n, s);
182
+ }
183
+ _clearByParam(e) {
184
+ const t = this._getTextRanges(e);
185
+ t == null || t.splice(0), this._refresh(e);
186
+ }
187
+ _removeByParam(e, t) {
188
+ const n = this._getTextRanges(t);
189
+ n == null || n.splice(e, 1), this._refresh(t);
190
+ }
191
+ }
192
+ var _n = Object.defineProperty, Sn = Object.getOwnPropertyDescriptor, vn = (r, e, t, n) => {
193
+ for (var s = n > 1 ? void 0 : n ? Sn(e, t) : e, i = r.length - 1, o; i >= 0; i--)
194
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
195
+ return n && s && _n(e, t, s), s;
196
+ }, Mn = (r, e) => (t, n) => e(t, n, r);
197
+ let ee = class {
198
+ constructor(r) {
199
+ _(this, "_currentViewModelUnitId", "");
200
+ _(this, "_docViewModelMap", /* @__PURE__ */ new Map());
201
+ _(this, "_currentDocViewModel$", new Ae(null));
202
+ _(this, "currentDocViewModel$", this._currentDocViewModel$.asObservable());
203
+ this._currentUniverService = r;
204
+ }
205
+ dispose() {
206
+ this._currentDocViewModel$.complete(), this._docViewModelMap = /* @__PURE__ */ new Map();
207
+ }
208
+ getCurrent() {
209
+ return this._docViewModelMap.get(this._currentViewModelUnitId);
210
+ }
211
+ getViewModel(r) {
212
+ var e;
213
+ return (e = this._docViewModelMap.get(r)) == null ? void 0 : e.docViewModel;
214
+ }
215
+ setCurrent(r) {
216
+ var t;
217
+ const e = this._currentUniverService.getUniverDocInstance(r);
218
+ if (e == null)
219
+ throw new Error(`Document data model with id ${r} not found when build view model.`);
220
+ if (e.getBody() != null) {
221
+ if (!this._docViewModelMap.has(r)) {
222
+ const n = this._buildDocViewModel(e);
223
+ this._docViewModelMap.set(r, {
224
+ unitId: r,
225
+ docViewModel: n
226
+ });
227
+ }
228
+ if (r === te) {
229
+ const n = (t = this._docViewModelMap.get(r)) == null ? void 0 : t.docViewModel;
230
+ if (n == null)
231
+ return;
232
+ n.reset(e);
233
+ }
234
+ this._currentViewModelUnitId = r, this._currentDocViewModel$.next(this.getCurrent());
235
+ }
236
+ }
237
+ _buildDocViewModel(r) {
238
+ return new Jt(r);
239
+ }
240
+ };
241
+ ee = vn([
242
+ Mn(0, I)
243
+ ], ee);
244
+ const S = {
245
+ id: "doc.mutation.rich-text-editing",
246
+ type: C.MUTATION,
247
+ handler: (r, e) => {
248
+ const { unitId: t, mutations: n } = e, i = r.get(I).getUniverDocInstance(t), a = r.get(ee).getViewModel(t);
249
+ if (!i)
250
+ throw new Error(`DocumentDataModel not found for unitId: ${t}`);
251
+ const c = new He();
252
+ c.reset(), n.forEach((d) => {
253
+ const { segmentId: f, len: h } = d, u = a == null ? void 0 : a.getSelfOrHeaderFooterViewModel(f);
254
+ if (d.t === "r") {
255
+ const { len: g } = d;
256
+ c.moveCursor(g);
257
+ } else if (d.t === "i") {
258
+ const { body: g } = d;
259
+ if (g.dataStream.length > 1 && /\r/.test(g.dataStream)) {
260
+ const p = i.getSelfOrHeaderFooterModel(f);
261
+ u.reset(p);
262
+ } else
263
+ u.insert(g, c.cursor);
264
+ c.moveCursor(h);
265
+ } else if (d.t === "d")
266
+ u.delete(c.cursor, h);
267
+ else
268
+ throw new Error(`Unknown mutation type for mutation: ${d}.`);
269
+ });
270
+ const l = i.apply(n);
271
+ return {
272
+ unitId: t,
273
+ mutations: l
274
+ };
275
+ }
276
+ }, $e = {
277
+ id: "doc.command.delete-left",
278
+ type: C.COMMAND,
279
+ handler: async () => !0
280
+ }, Be = {
281
+ id: "doc.command.delete-right",
282
+ type: C.COMMAND,
283
+ handler: async () => !0
284
+ }, st = {
285
+ id: "doc.command.break-line",
286
+ type: C.COMMAND,
287
+ handler: async () => !0
288
+ }, it = {
289
+ id: "doc.command.insert-text",
290
+ type: C.COMMAND,
291
+ handler: async (r, e) => {
292
+ const t = r.get(B), n = r.get(D), s = r.get(P), { range: i, segmentId: o, body: a, unitId: c, textRanges: l } = e, { startOffset: d, collapsed: f } = i, h = {
293
+ id: S.id,
294
+ params: {
295
+ unitId: c,
296
+ mutations: []
297
+ }
298
+ };
299
+ f ? h.params.mutations.push({
300
+ t: "r",
301
+ len: d,
302
+ segmentId: o
303
+ }) : h.params.mutations.push(...me(i, o)), h.params.mutations.push({
304
+ t: "i",
305
+ body: a,
306
+ len: a.dataStream.length,
307
+ line: 0,
308
+ segmentId: o
309
+ });
310
+ const u = n.syncExecuteCommand(h.id, h.params);
311
+ return s.replaceTextRanges(l), u ? (t.pushUndoRedo({
312
+ unitID: c,
313
+ undoMutations: [{ id: S.id, params: u }],
314
+ redoMutations: [{ id: S.id, params: h.params }],
315
+ undo() {
316
+ return n.syncExecuteCommand(S.id, u), s.replaceTextRanges([i]), !0;
317
+ },
318
+ redo() {
319
+ return n.syncExecuteCommand(S.id, h.params), s.replaceTextRanges(l), !0;
320
+ }
321
+ }), !0) : !1;
322
+ }
323
+ };
324
+ var et = /* @__PURE__ */ ((r) => (r[r.LEFT = 0] = "LEFT", r[r.RIGHT = 1] = "RIGHT", r))(et || {});
325
+ const tt = {
326
+ id: "doc.command.delete-text",
327
+ type: C.COMMAND,
328
+ handler: async (r, e) => {
329
+ const t = r.get(D), n = r.get(B), s = r.get(P), { range: i, segmentId: o, unitId: a, direction: c, textRanges: l, len: d = 1 } = e, { collapsed: f, startOffset: h } = i, u = {
330
+ id: S.id,
331
+ params: {
332
+ unitId: a,
333
+ mutations: []
334
+ }
335
+ };
336
+ f ? (h > 0 && u.params.mutations.push({
337
+ t: "r",
338
+ len: c === 0 ? h - d : h,
339
+ segmentId: o
340
+ }), u.params.mutations.push({
341
+ t: "d",
342
+ len: d,
343
+ line: 0,
344
+ segmentId: o
345
+ })) : u.params.mutations.push(...me(i, o));
346
+ const g = t.syncExecuteCommand(u.id, u.params);
347
+ return s.replaceTextRanges(l), g && n.pushUndoRedo({
348
+ unitID: a,
349
+ undoMutations: [{ id: S.id, params: g }],
350
+ redoMutations: [{ id: S.id, params: u.params }],
351
+ undo() {
352
+ return t.syncExecuteCommand(S.id, g), s.replaceTextRanges([i]), !0;
353
+ },
354
+ redo() {
355
+ return t.syncExecuteCommand(S.id, u.params), s.replaceTextRanges(l), !0;
356
+ }
357
+ }), !1;
358
+ }
359
+ }, yt = {
360
+ id: "doc.command.update-text",
361
+ type: C.COMMAND,
362
+ handler: async (r, e) => {
363
+ const { range: t, segmentId: n, updateBody: s, coverType: i, unitId: o, textRanges: a } = e, c = r.get(D), l = r.get(B), d = r.get(P), f = {
364
+ id: S.id,
365
+ params: {
366
+ unitId: o,
367
+ mutations: []
368
+ }
369
+ }, { startOffset: h, endOffset: u } = t;
370
+ f.params.mutations.push({
371
+ t: "r",
372
+ len: h,
373
+ segmentId: n
374
+ }), f.params.mutations.push({
375
+ t: "r",
376
+ body: s,
377
+ len: u - h,
378
+ segmentId: n,
379
+ coverType: i
380
+ });
381
+ const g = c.syncExecuteCommand(f.id, f.params);
382
+ return d.replaceTextRanges(a), g ? (l.pushUndoRedo({
383
+ unitID: o,
384
+ undoMutations: [{ id: S.id, params: g }],
385
+ redoMutations: [{ id: S.id, params: f.params }],
386
+ undo() {
387
+ return c.syncExecuteCommand(S.id, g), d.replaceTextRanges(a), !0;
388
+ },
389
+ redo() {
390
+ return c.syncExecuteCommand(S.id, f.params), d.replaceTextRanges(a), !0;
391
+ }
392
+ }), !0) : !1;
393
+ }
394
+ };
395
+ class ot {
396
+ constructor() {
397
+ _(this, "_previousActiveRange", null);
398
+ _(this, "_undoMutationParamsCache", []);
399
+ _(this, "_redoMutationParamsCache", []);
400
+ }
401
+ clearUndoRedoMutationParamsCache() {
402
+ this._undoMutationParamsCache = [], this._redoMutationParamsCache = [];
403
+ }
404
+ setActiveRange(e) {
405
+ this._previousActiveRange = e;
406
+ }
407
+ pushUndoRedoMutationParams(e, t) {
408
+ this._undoMutationParamsCache.push(e), this._redoMutationParamsCache.push(t);
409
+ }
410
+ fetchComposedUndoRedoMutationParams(e) {
411
+ if (this._undoMutationParamsCache.length === 0 || this._previousActiveRange == null)
412
+ return null;
413
+ const { unitId: t } = this._undoMutationParamsCache[0], { segmentId: n, startOffset: s, collapsed: i } = this._previousActiveRange, o = {
414
+ unitId: t,
415
+ mutations: []
416
+ }, a = {
417
+ unitId: t,
418
+ mutations: []
419
+ };
420
+ return i ? (o.mutations.push({
421
+ t: "r",
422
+ len: s,
423
+ segmentId: n
424
+ }), a.mutations.push({
425
+ t: "r",
426
+ len: s,
427
+ segmentId: n
428
+ })) : (s > 0 && o.mutations.push({
429
+ t: "r",
430
+ len: s,
431
+ segmentId: n
432
+ }), o.mutations.push(this._undoMutationParamsCache[0].mutations.find((c) => c.t === "i")), a.mutations.push(...me(this._previousActiveRange, n))), e.length && (o.mutations.push({
433
+ t: "d",
434
+ len: e.length,
435
+ line: 0,
436
+ segmentId: n
437
+ }), a.mutations.push({
438
+ t: "i",
439
+ body: {
440
+ dataStream: e
441
+ },
442
+ len: e.length,
443
+ line: 0,
444
+ segmentId: n
445
+ })), { redoMutationParams: a, undoMutationParams: o, previousActiveRange: this._previousActiveRange };
446
+ }
447
+ dispose() {
448
+ this._undoMutationParamsCache = [], this._redoMutationParamsCache = [], this._previousActiveRange = null;
449
+ }
450
+ }
451
+ const bt = {
452
+ id: "doc.command.ime-input",
453
+ type: C.COMMAND,
454
+ handler: async (r, e) => {
455
+ const { unitId: t, newText: n, oldTextLen: s, range: i, segmentId: o, textRanges: a, isCompositionEnd: c } = e, l = r.get(D), d = r.get(B), f = r.get(P), h = r.get(ot), u = {
456
+ id: S.id,
457
+ params: {
458
+ unitId: t,
459
+ mutations: []
460
+ }
461
+ };
462
+ i.collapsed ? u.params.mutations.push({
463
+ t: "r",
464
+ len: i.startOffset,
465
+ segmentId: o
466
+ }) : u.params.mutations.push(...me(i, o)), s > 0 && u.params.mutations.push({
467
+ t: "d",
468
+ len: s,
469
+ line: 0,
470
+ segmentId: o
471
+ }), u.params.mutations.push({
472
+ t: "i",
473
+ body: {
474
+ dataStream: n
475
+ },
476
+ len: n.length,
477
+ line: 0,
478
+ segmentId: o
479
+ });
480
+ const g = l.syncExecuteCommand(u.id, u.params);
481
+ if (h.pushUndoRedoMutationParams(g, u.params), f.replaceTextRanges(a), c) {
482
+ if (g) {
483
+ const p = h.fetchComposedUndoRedoMutationParams(n);
484
+ if (p == null)
485
+ return !1;
486
+ const { undoMutationParams: m, redoMutationParams: v, previousActiveRange: M } = p;
487
+ return d.pushUndoRedo({
488
+ unitID: t,
489
+ undoMutations: [{ id: S.id, params: m }],
490
+ redoMutations: [{ id: S.id, params: v }],
491
+ undo() {
492
+ return l.syncExecuteCommand(S.id, m), f.replaceTextRanges([M]), !0;
493
+ },
494
+ redo() {
495
+ return l.syncExecuteCommand(S.id, v), f.replaceTextRanges(a), !0;
496
+ }
497
+ }), !0;
498
+ }
499
+ } else
500
+ return !!g;
501
+ return !1;
502
+ }
503
+ }, ce = {
504
+ id: "doc.command.set-inline-format-bold",
505
+ type: C.COMMAND,
506
+ handler: async () => !0
507
+ }, je = {
508
+ id: "doc.command.set-inline-format-italic",
509
+ type: C.COMMAND,
510
+ handler: async () => !0
511
+ }, Ve = {
512
+ id: "doc.command.set-inline-format-underline",
513
+ type: C.COMMAND,
514
+ handler: async () => !0
515
+ }, ke = {
516
+ id: "doc.command.set-inline-format-strikethrough",
517
+ type: C.COMMAND,
518
+ handler: async () => !0
519
+ }, le = {
520
+ id: "doc.command.set-inline-format-fontsize",
521
+ type: C.COMMAND,
522
+ handler: async () => !0
523
+ }, de = {
524
+ id: "doc.command.set-inline-format-font-family",
525
+ type: C.COMMAND,
526
+ handler: async () => !0
527
+ }, Fe = {
528
+ id: "doc.command.set-inline-format-text-color",
529
+ type: C.COMMAND,
530
+ handler: async () => !0
531
+ }, Dt = {
532
+ id: "doc.command.set-inline-format",
533
+ type: C.COMMAND,
534
+ handler: async (r, e) => {
535
+ const { segmentId: t, value: n, preCommandId: s } = e, i = r.get(B), o = r.get(D), a = r.get(P), c = r.get(I), l = a.getSelections();
536
+ if (!Array.isArray(l) || l.length === 0)
537
+ return !1;
538
+ let d = c.getCurrentUniverDocInstance(), f = d.getUnitId();
539
+ f === ne && (d = c.getUniverDocInstance(te), f = d.getUnitId());
540
+ let h;
541
+ const u = {
542
+ [ce.id]: "bl",
543
+ [je.id]: "it",
544
+ [Ve.id]: "ul",
545
+ [ke.id]: "st",
546
+ [le.id]: "fs",
547
+ [de.id]: "ff",
548
+ [Fe.id]: "cl"
549
+ };
550
+ switch (s) {
551
+ case ce.id:
552
+ case je.id:
553
+ case Ve.id:
554
+ case ke.id: {
555
+ h = Rn(
556
+ d.body.textRuns,
557
+ u[s],
558
+ l
559
+ );
560
+ break;
561
+ }
562
+ case le.id:
563
+ case de.id: {
564
+ h = n;
565
+ break;
566
+ }
567
+ case Fe.id: {
568
+ h = {
569
+ rgb: n
570
+ };
571
+ break;
572
+ }
573
+ default:
574
+ throw new Error(`Unknown command: ${s} in handleInlineFormat`);
575
+ }
576
+ const g = {
577
+ id: S.id,
578
+ params: {
579
+ unitId: f,
580
+ mutations: []
581
+ }
582
+ }, p = new He();
583
+ p.reset();
584
+ for (const M of l) {
585
+ const { startOffset: y, endOffset: E } = M, z = {
586
+ dataStream: "",
587
+ textRuns: [
588
+ {
589
+ st: 0,
590
+ ed: E - y,
591
+ ts: {
592
+ [u[s]]: h
593
+ }
594
+ }
595
+ ]
596
+ }, k = y - p.cursor;
597
+ k !== 0 && g.params.mutations.push({
598
+ t: "r",
599
+ len: k,
600
+ segmentId: t
601
+ }), g.params.mutations.push({
602
+ t: "r",
603
+ body: z,
604
+ len: E - y,
605
+ segmentId: t
606
+ }), p.reset(), p.moveCursor(E);
607
+ }
608
+ const m = o.syncExecuteCommand(g.id, g.params), v = [
609
+ ce.id,
610
+ le.id,
611
+ de.id
612
+ ];
613
+ return v.includes(s) && a.refreshSelection(), m ? (i.pushUndoRedo({
614
+ unitID: f,
615
+ undoMutations: [{ id: S.id, params: m }],
616
+ redoMutations: [{ id: S.id, params: g.params }],
617
+ undo() {
618
+ return o.syncExecuteCommand(S.id, m), v.includes(s) && a.refreshSelection(), !0;
619
+ },
620
+ redo() {
621
+ return o.syncExecuteCommand(S.id, g.params), v.includes(s) && a.refreshSelection(), !0;
622
+ }
623
+ }), !0) : !1;
624
+ }
625
+ };
626
+ function Cn(r) {
627
+ return r !== null && typeof r == "object";
628
+ }
629
+ function Rn(r, e, t) {
630
+ let n = 0, s = 0;
631
+ for (; n !== r.length && s !== t.length; ) {
632
+ const { startOffset: i, endOffset: o } = t[s], { st: a, ed: c, ts: l } = r[n];
633
+ if (o <= a)
634
+ s++;
635
+ else if (c <= i)
636
+ n++;
637
+ else {
638
+ if ((l == null ? void 0 : l[e]) == null)
639
+ return /bl|it/.test(e) ? O.TRUE : {
640
+ s: O.TRUE
641
+ };
642
+ if (l[e] === O.FALSE)
643
+ return O.TRUE;
644
+ if (Cn(l[e]) && l[e].s === O.FALSE)
645
+ return {
646
+ s: O.TRUE
647
+ };
648
+ n++;
649
+ }
650
+ }
651
+ return /bl|it/.test(e) ? O.FALSE : {
652
+ s: O.FALSE
653
+ };
654
+ }
655
+ const In = {
656
+ id: "doc.command-replace-content",
657
+ type: C.COMMAND,
658
+ handler: async (r, e) => {
659
+ var g;
660
+ const { unitId: t, body: n, textRanges: s, segmentId: i = "" } = e, o = r.get(I), a = r.get(D), c = r.get(P), l = r.get(B), d = (g = o.getUniverDocInstance(t)) == null ? void 0 : g.getSnapshot().body, f = c.getSelections();
661
+ if (d == null || !Array.isArray(f) || f.length === 0)
662
+ return !1;
663
+ const h = Pt(t, i, d, n), u = a.syncExecuteCommand(h.id, h.params);
664
+ return c.replaceTextRanges(s), u ? (l.pushUndoRedo({
665
+ unitID: t,
666
+ undoMutations: [{ id: S.id, params: u }],
667
+ redoMutations: [{ id: S.id, params: h.params }],
668
+ undo() {
669
+ return a.syncExecuteCommand(S.id, u), c.replaceTextRanges(f), !0;
670
+ },
671
+ redo() {
672
+ return a.syncExecuteCommand(S.id, h.params), c.replaceTextRanges(s), !0;
673
+ }
674
+ }), !0) : !1;
675
+ }
676
+ }, xn = {
677
+ id: "doc.command-cover-content",
678
+ type: C.COMMAND,
679
+ handler: async (r, e) => {
680
+ var d;
681
+ const { unitId: t, body: n, segmentId: s = "" } = e, i = r.get(I), o = r.get(D), a = r.get(B), c = (d = i.getUniverDocInstance(t)) == null ? void 0 : d.getSnapshot().body;
682
+ if (c == null)
683
+ return !1;
684
+ const l = Pt(t, s, c, n);
685
+ return o.syncExecuteCommand(
686
+ l.id,
687
+ l.params
688
+ ), a.clearUndoRedo(t), !0;
689
+ }
690
+ };
691
+ function Pt(r, e, t, n) {
692
+ const s = {
693
+ id: S.id,
694
+ params: {
695
+ unitId: r,
696
+ mutations: []
697
+ }
698
+ }, i = (t == null ? void 0 : t.dataStream.length) - 2;
699
+ return i > 0 && s.params.mutations.push({
700
+ t: "d",
701
+ len: i,
702
+ line: 0,
703
+ segmentId: e
704
+ }), n.dataStream.length > 0 && s.params.mutations.push({
705
+ t: "i",
706
+ body: n,
707
+ len: n.dataStream.length,
708
+ line: 0,
709
+ segmentId: e
710
+ }), s;
711
+ }
712
+ const G = {
713
+ id: "doc.operation.move-cursor",
714
+ type: C.OPERATION,
715
+ handler: (r, e) => !!e
716
+ }, X = {
717
+ id: "doc.operation.move-selection",
718
+ type: C.OPERATION,
719
+ handler: (r, e) => !!e
720
+ }, Tt = {
721
+ id: "doc.operation.set-selections",
722
+ type: C.OPERATION,
723
+ handler: (r, e) => (r.get(P).replaceTextRangesWithNoRefresh(e.ranges), !0)
724
+ }, On = (r, e) => {
725
+ const t = r.get(I).getUniverDocInstance(e.unitId), n = (t == null ? void 0 : t.zoomRatio) || 1;
726
+ return {
727
+ ...Q.deepClone(e),
728
+ zoomRatio: n
729
+ };
730
+ }, H = {
731
+ id: "doc.operation.set-zoom-ratio",
732
+ type: C.OPERATION,
733
+ handler: (r, e) => {
734
+ const t = r.get(I).getUniverDocInstance(e.unitId);
735
+ if (!t)
736
+ return !1;
737
+ const n = t.getSnapshot();
738
+ return n.settings == null ? n.settings = {
739
+ zoomRatio: e.zoomRatio
740
+ } : n.settings.zoomRatio = e.zoomRatio, !0;
741
+ }
742
+ }, Et = {
743
+ type: C.COMMAND,
744
+ id: "doc.command.set-zoom-ratio",
745
+ handler: async (r, e) => {
746
+ const t = r.get(D), n = r.get(B), s = r.get(I);
747
+ let i = s.getCurrentUniverDocInstance().getUnitId(), o = 1;
748
+ if (e && (i = e.documentId ?? i, o = e.zoomRatio ?? o), !s.getUniverDocInstance(i))
749
+ return !1;
750
+ const c = {
751
+ zoomRatio: o,
752
+ unitId: i
753
+ }, l = On(r, c);
754
+ return t.syncExecuteCommand(H.id, c) ? (n.pushUndoRedo({
755
+ unitID: i,
756
+ undoMutations: [{ id: H.id, params: l }],
757
+ redoMutations: [{ id: H.id, params: c }]
758
+ }), !0) : !1;
759
+ }
760
+ }, wt = {
761
+ id: "doc.operation.select-all",
762
+ type: C.COMMAND,
763
+ handler: async (r) => {
764
+ const e = r.get(I), t = r.get(P), n = e.getCurrentUniverDocInstance().getSnapshot().body;
765
+ if (n == null)
766
+ return !1;
767
+ const s = [
768
+ {
769
+ startOffset: 0,
770
+ endOffset: n.dataStream.length - 2,
771
+ collapsed: !1
772
+ }
773
+ ];
774
+ return t.replaceTextRanges(s), !0;
775
+ }
776
+ }, _t = {
777
+ id: "doc.command.inner-paste",
778
+ type: C.COMMAND,
779
+ handler: async (r, e) => {
780
+ const { segmentId: t, body: n, textRanges: s } = e, i = r.get(B), o = r.get(D), a = r.get(P), c = r.get(I), l = a.getSelections();
781
+ if (!Array.isArray(l) || l.length === 0)
782
+ return !1;
783
+ const f = c.getCurrentUniverDocInstance().getUnitId(), h = {
784
+ id: S.id,
785
+ params: {
786
+ unitId: f,
787
+ mutations: []
788
+ }
789
+ }, u = new He();
790
+ u.reset();
791
+ for (const p of l) {
792
+ const { startOffset: m, endOffset: v, collapsed: M } = p, y = m - u.cursor;
793
+ M ? h.params.mutations.push({
794
+ t: "r",
795
+ len: y,
796
+ segmentId: t
797
+ }) : h.params.mutations.push(
798
+ ...me(p, t, u.cursor)
799
+ ), h.params.mutations.push({
800
+ t: "i",
801
+ body: n,
802
+ len: n.dataStream.length,
803
+ line: 0,
804
+ segmentId: t
805
+ }), u.reset(), u.moveCursor(v);
806
+ }
807
+ const g = o.syncExecuteCommand(h.id, h.params);
808
+ return a.replaceTextRanges(s), g ? (i.pushUndoRedo({
809
+ unitID: f,
810
+ undoMutations: [{ id: S.id, params: g }],
811
+ redoMutations: [{ id: S.id, params: h.params }],
812
+ undo() {
813
+ return o.syncExecuteCommand(S.id, g), a.replaceTextRanges(l), !0;
814
+ },
815
+ redo() {
816
+ return o.syncExecuteCommand(S.id, h.params), a.replaceTextRanges(s), !0;
817
+ }
818
+ }), !0) : !1;
819
+ }
820
+ }, ze = {
821
+ id: "doc.command.inner-cut",
822
+ type: C.COMMAND,
823
+ handler: async (r, e) => {
824
+ const { segmentId: t, textRanges: n } = e, s = r.get(B), i = r.get(D), o = r.get(P), a = r.get(I), c = o.getSelections();
825
+ if (!Array.isArray(c) || c.length === 0)
826
+ return !1;
827
+ const l = a.getCurrentUniverDocInstance().getUnitId(), d = a.getUniverDocInstance(l), f = Nt(d.snapshot, t);
828
+ if (f == null)
829
+ return !1;
830
+ const h = {
831
+ id: S.id,
832
+ params: {
833
+ unitId: l,
834
+ mutations: []
835
+ }
836
+ }, u = new He();
837
+ u.reset();
838
+ for (const p of c) {
839
+ const { startOffset: m, endOffset: v, collapsed: M } = p, y = m - u.cursor;
840
+ M ? h.params.mutations.push({
841
+ t: "r",
842
+ len: y,
843
+ segmentId: t
844
+ }) : h.params.mutations.push(
845
+ ...yn(p, f, t, u.cursor)
846
+ ), u.reset(), u.moveCursor(v);
847
+ }
848
+ const g = i.syncExecuteCommand(h.id, h.params);
849
+ return o.replaceTextRanges(n), g ? (s.pushUndoRedo({
850
+ unitID: l,
851
+ undoMutations: [{ id: S.id, params: g }],
852
+ redoMutations: [{ id: S.id, params: h.params }],
853
+ undo() {
854
+ return i.syncExecuteCommand(S.id, g), o.replaceTextRanges(c), !0;
855
+ },
856
+ redo() {
857
+ return i.syncExecuteCommand(S.id, h.params), o.replaceTextRanges(n), !0;
858
+ }
859
+ }), !0) : !1;
860
+ }
861
+ };
862
+ function yn(r, e, t = "", n = 0) {
863
+ const { startOffset: s, endOffset: i } = r, o = [], { paragraphs: a = [] } = e, c = s - n, l = i - n, d = a == null ? void 0 : a.find(
864
+ (f) => f.startIndex - n >= c && f.startIndex - n <= l
865
+ );
866
+ if (c > 0 && o.push({
867
+ t: "r",
868
+ len: c,
869
+ segmentId: t
870
+ }), d && d.startIndex - n > c) {
871
+ const f = d.startIndex - n;
872
+ o.push({
873
+ t: "d",
874
+ len: f - c,
875
+ line: 0,
876
+ segmentId: t
877
+ }), o.push({
878
+ t: "r",
879
+ len: 1,
880
+ segmentId: t
881
+ }), l > f + 1 && o.push({
882
+ t: "d",
883
+ len: l - f - 1,
884
+ line: 0,
885
+ segmentId: t
886
+ });
887
+ } else
888
+ o.push({
889
+ t: "d",
890
+ len: l - c,
891
+ line: 0,
892
+ segmentId: t
893
+ });
894
+ return o;
895
+ }
896
+ const bn = 10, Dn = 6;
897
+ function Pn() {
898
+ return Q.generateRandomId(Dn);
899
+ }
900
+ function Tn(r) {
901
+ const e = r.match(/data-copy-id="([^\s]+)"/);
902
+ return e && e[1] ? e[1] : null;
903
+ }
904
+ class En {
905
+ constructor() {
906
+ _(this, "_cache", new $t(bn));
907
+ }
908
+ set(e, t) {
909
+ this._cache.set(e, t);
910
+ }
911
+ get(e) {
912
+ return this._cache.get(e);
913
+ }
914
+ clear() {
915
+ this._cache.clear();
916
+ }
917
+ }
918
+ const St = new En();
919
+ function wn(r) {
920
+ const e = r.style, t = {};
921
+ for (let n = 0; n < e.length; n++) {
922
+ const s = e[n], i = e.getPropertyValue(s);
923
+ switch (s) {
924
+ case "margin-top": {
925
+ const o = parseInt(i);
926
+ t.spaceAbove = /pt/.test(i) ? nt(o) : o;
927
+ break;
928
+ }
929
+ case "margin-bottom": {
930
+ const o = parseInt(i);
931
+ t.spaceBelow = /pt/.test(i) ? nt(o) : o;
932
+ break;
933
+ }
934
+ }
935
+ }
936
+ return Object.getOwnPropertyNames(t).length ? t : null;
937
+ }
938
+ function nt(r) {
939
+ return r / 0.75;
940
+ }
941
+ function at(r) {
942
+ const e = r.style, t = {}, n = r.tagName.toLowerCase();
943
+ switch (n) {
944
+ case "b":
945
+ case "em":
946
+ case "strong": {
947
+ t.bl = O.TRUE;
948
+ break;
949
+ }
950
+ case "s": {
951
+ t.st = {
952
+ s: O.TRUE
953
+ };
954
+ break;
955
+ }
956
+ case "u": {
957
+ t.ul = {
958
+ s: O.TRUE
959
+ };
960
+ break;
961
+ }
962
+ case "i": {
963
+ t.it = O.TRUE;
964
+ break;
965
+ }
966
+ case "sub":
967
+ case "sup": {
968
+ t.va = n === "sup" ? Le.SUPERSCRIPT : Le.SUBSCRIPT;
969
+ break;
970
+ }
971
+ }
972
+ for (let s = 0; s < e.length; s++) {
973
+ const i = e[s], o = e.getPropertyValue(i);
974
+ switch (i) {
975
+ case "font-family": {
976
+ t.ff = o;
977
+ break;
978
+ }
979
+ case "font-size": {
980
+ const a = parseInt(o);
981
+ Number.isNaN(a) || (t.fs = /pt$/.test(o) ? nt(a) : a);
982
+ break;
983
+ }
984
+ case "font-style": {
985
+ o === "italic" && (t.it = O.TRUE);
986
+ break;
987
+ }
988
+ case "font-weight": {
989
+ Number(o) > 400 && (t.bl = O.TRUE);
990
+ break;
991
+ }
992
+ case "text-decoration": {
993
+ /underline/.test(o) ? t.ul = {
994
+ s: O.TRUE
995
+ } : /overline/.test(o) ? t.ol = {
996
+ s: O.TRUE
997
+ } : /line-through/.test(o) && (t.st = {
998
+ s: O.TRUE
999
+ });
1000
+ break;
1001
+ }
1002
+ case "color": {
1003
+ const a = new pt(o);
1004
+ a.isValid && (t.cl = {
1005
+ rgb: a.toRgbString()
1006
+ });
1007
+ break;
1008
+ }
1009
+ case "background-color": {
1010
+ const a = new pt(o);
1011
+ a.isValid && (t.bg = {
1012
+ rgb: a.toRgbString()
1013
+ });
1014
+ break;
1015
+ }
1016
+ }
1017
+ }
1018
+ return t;
1019
+ }
1020
+ function Un(r) {
1021
+ const e = new DOMParser(), t = `<x-univer id="univer-root">${r}</x-univer>`;
1022
+ return e.parseFromString(t, "text/html").querySelector("#univer-root");
1023
+ }
1024
+ function vt(r, e) {
1025
+ const t = r.tagName.toLowerCase();
1026
+ return typeof e == "string" ? t === e : Array.isArray(e) ? e.some((n) => n === t) : e(r);
1027
+ }
1028
+ const We = class We {
1029
+ constructor() {
1030
+ _(this, "styleCache", /* @__PURE__ */ new Map());
1031
+ _(this, "styleRules", []);
1032
+ _(this, "afterProcessRules", []);
1033
+ }
1034
+ static use(e) {
1035
+ if (this.pluginList.includes(e))
1036
+ throw new Error(`Univer paste plugin ${e.name} already added`);
1037
+ this.pluginList.push(e);
1038
+ }
1039
+ convert(e) {
1040
+ const t = We.pluginList.find((i) => i.checkPasteType(e)), n = Un(e), s = {
1041
+ dataStream: "",
1042
+ textRuns: []
1043
+ };
1044
+ return t && (this.styleRules = [...t.stylesRules], this.afterProcessRules = [...t.afterProcessRules]), this.styleCache.clear(), this.process(null, n == null ? void 0 : n.childNodes, s), this.styleCache.clear(), this.styleRules = [], this.afterProcessRules = [], s;
1045
+ }
1046
+ process(e, t, n) {
1047
+ var s;
1048
+ for (const i of t)
1049
+ if (i.nodeType === Node.TEXT_NODE) {
1050
+ const o = (s = i.nodeValue) == null ? void 0 : s.replace(/[\r\n]/g, "");
1051
+ let a;
1052
+ e && this.styleCache.has(e) && (a = this.styleCache.get(e)), n.dataStream += o, a && Object.getOwnPropertyNames(a).length && n.textRuns.push({
1053
+ st: n.dataStream.length - o.length,
1054
+ ed: n.dataStream.length,
1055
+ ts: a
1056
+ });
1057
+ } else if (i.nodeType === Node.ELEMENT_NODE) {
1058
+ const o = e ? this.styleCache.get(e) : {}, a = this.styleRules.find(({ filter: f }) => vt(i, f)), c = a ? a.getStyle(i) : at(i);
1059
+ this.styleCache.set(i, { ...o, ...c });
1060
+ const { childNodes: l } = i;
1061
+ this.process(i, l, n);
1062
+ const d = this.afterProcessRules.find(
1063
+ ({ filter: f }) => vt(i, f)
1064
+ );
1065
+ d && d.handler(n, i);
1066
+ }
1067
+ }
1068
+ };
1069
+ _(We, "pluginList", []);
1070
+ let he = We;
1071
+ const Ln = {
1072
+ name: "univer-doc-paste-plugin-lark",
1073
+ checkPasteType(r) {
1074
+ return /lark-record-clipboard/i.test(r);
1075
+ },
1076
+ // TODO: @JOCS, support inline code copy from lark.
1077
+ stylesRules: [
1078
+ {
1079
+ filter: ["s"],
1080
+ getStyle(r) {
1081
+ const e = at(r);
1082
+ return {
1083
+ st: {
1084
+ s: O.TRUE
1085
+ },
1086
+ ...e
1087
+ };
1088
+ }
1089
+ }
1090
+ ],
1091
+ afterProcessRules: [
1092
+ {
1093
+ filter(r) {
1094
+ return r.tagName === "DIV" && /ace-line/i.test(r.className);
1095
+ },
1096
+ handler(r) {
1097
+ r.paragraphs == null && (r.paragraphs = []), r.paragraphs.push({
1098
+ startIndex: r.dataStream.length
1099
+ }), r.dataStream += "\r";
1100
+ }
1101
+ }
1102
+ ]
1103
+ }, An = {
1104
+ name: "univer-doc-paste-plugin-word",
1105
+ checkPasteType(r) {
1106
+ return /word|mso/i.test(r);
1107
+ },
1108
+ stylesRules: [
1109
+ {
1110
+ filter: ["b"],
1111
+ getStyle(r) {
1112
+ const e = at(r);
1113
+ return { bl: O.TRUE, ...e };
1114
+ }
1115
+ }
1116
+ ],
1117
+ afterProcessRules: [
1118
+ {
1119
+ filter(r) {
1120
+ return r.tagName === "P" && /mso/i.test(r.className);
1121
+ },
1122
+ handler(r, e) {
1123
+ r.paragraphs == null && (r.paragraphs = []);
1124
+ const t = {
1125
+ startIndex: r.dataStream.length
1126
+ }, n = wn(e);
1127
+ n && (t.paragraphStyle = n), r.paragraphs.push(t), r.dataStream += "\r";
1128
+ }
1129
+ }
1130
+ ]
1131
+ };
1132
+ function Nn(r, e) {
1133
+ const { st: t, ed: n, ts: s = {} } = e, { ff: i, fs: o, it: a, bl: c, ul: l, st: d, ol: f, bg: h, cl: u, va: g } = s;
1134
+ let p = r.slice(t, n);
1135
+ const m = [];
1136
+ return a === O.TRUE && (p = `<i>${p}</i>`), g === Le.SUPERSCRIPT ? p = `<sup>${p}</sup>` : g === Le.SUBSCRIPT && (p = `<sub>${p}</sub>`), (l == null ? void 0 : l.s) === O.TRUE && (p = `<u>${p}</u>`), (d == null ? void 0 : d.s) === O.TRUE && (p = `<s>${p}</s>`), c === O.TRUE && (p = `<strong>${p}</strong>`), i && m.push(`font-family: ${i}`), u && m.push(`color: ${u.rgb}`), o && m.push(`font-size: ${o}px`), f && m.push("text-decoration: overline"), h && m.push(`background: ${h.rgb}`), m.length ? `<span style="${m.join(";")}">${p}</span>` : p;
1137
+ }
1138
+ function Mt(r, e = !0) {
1139
+ const { dataStream: t, textRuns: n = [], paragraphs: s = [] } = r;
1140
+ let i = 0;
1141
+ const o = [], a = [];
1142
+ for (const c of n) {
1143
+ const { st: l, ed: d } = c;
1144
+ if (l !== i && o.push(t.slice(i, l)), o.push(Nn(t, c)), i = d, e)
1145
+ for (const f of s) {
1146
+ const { startIndex: h, paragraphStyle: u = {} } = f;
1147
+ if (h >= l && h <= d) {
1148
+ const { spaceAbove: g, spaceBelow: p } = u, m = [];
1149
+ g != null && (typeof g == "number" ? m.push(`margin-top: ${g}px`) : m.push(`margin-top: ${g.v}px`)), p != null && (typeof p == "number" ? m.push(`margin-bottom: ${p}px`) : m.push(`margin-bottom: ${p.v}px`)), a.push(
1150
+ `<p className="UniverNormal" ${m.length ? `style="${m.join(";")}"` : ""}>${o.join("")}</p>`
1151
+ ), o.length = 0;
1152
+ }
1153
+ }
1154
+ }
1155
+ return a.join("") + o.join("");
1156
+ }
1157
+ class $n {
1158
+ convert(e) {
1159
+ if (e.length === 0)
1160
+ throw new Error("The bodyList length at least to be 1");
1161
+ if (e.length === 1)
1162
+ return Mt(e[0]);
1163
+ let t = "";
1164
+ for (const n of e)
1165
+ t += '<p className="UniverNormal">', t += Mt(n, !1), t += "</p>";
1166
+ return t;
1167
+ }
1168
+ }
1169
+ var Bn = Object.defineProperty, jn = Object.getOwnPropertyDescriptor, Vn = (r, e, t, n) => {
1170
+ for (var s = n > 1 ? void 0 : n ? jn(e, t) : e, i = r.length - 1, o; i >= 0; i--)
1171
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
1172
+ return n && s && Bn(e, t, s), s;
1173
+ }, Ct = (r, e) => (t, n) => e(t, n, r);
1174
+ he.use(An);
1175
+ he.use(Ln);
1176
+ const Ut = hn("doc.clipboard-service");
1177
+ let rt = class extends w {
1178
+ constructor(e, t) {
1179
+ super();
1180
+ _(this, "_clipboardHooks", []);
1181
+ _(this, "_htmlToUDM", new he());
1182
+ _(this, "_umdToHtml", new $n());
1183
+ this._currentUniverService = e, this._clipboardInterfaceService = t;
1184
+ }
1185
+ async queryClipboardData() {
1186
+ const e = await this._clipboardInterfaceService.read();
1187
+ if (e.length === 0)
1188
+ return Promise.reject();
1189
+ const t = e[0], n = await t.getType(qt).then((o) => o && o.text()), s = await t.getType(Yt).then((o) => o && o.text());
1190
+ if (!s)
1191
+ return {
1192
+ dataStream: n
1193
+ };
1194
+ const i = Tn(s);
1195
+ if (i) {
1196
+ const o = St.get(i);
1197
+ if (o)
1198
+ return o;
1199
+ }
1200
+ return this._htmlToUDM.convert(s);
1201
+ }
1202
+ async setClipboardData(e) {
1203
+ const t = Pn(), n = e.length > 1 ? e.map((i) => i.dataStream).join(`
1204
+ `) : e[0].dataStream;
1205
+ let s = this._umdToHtml.convert(e);
1206
+ return e.length === 1 && (s = s.replace(/(<[a-z]+)/, (i, o) => `${o} data-copy-id="${t}"`), St.set(t, e[0])), this._clipboardInterfaceService.write(n, s);
1207
+ }
1208
+ addClipboardHook(e) {
1209
+ return this._clipboardHooks.push(e), Ke(() => {
1210
+ const t = this._clipboardHooks.indexOf(e);
1211
+ t > -1 && this._clipboardHooks.splice(t, 1);
1212
+ });
1213
+ }
1214
+ };
1215
+ rt = Vn([
1216
+ Ct(0, I),
1217
+ Ct(1, Zt)
1218
+ ], rt);
1219
+ var kn = Object.defineProperty, Fn = Object.getOwnPropertyDescriptor, zn = (r, e, t, n) => {
1220
+ for (var s = n > 1 ? void 0 : n ? Fn(e, t) : e, i = r.length - 1, o; i >= 0; i--)
1221
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
1222
+ return n && s && kn(e, t, s), s;
1223
+ }, q = (r, e) => (t, n) => e(t, n, r);
1224
+ let Ce = class extends w {
1225
+ constructor(r, e, t, n, s, i) {
1226
+ super(), this._logService = r, this._commandService = e, this._currentUniverService = t, this._docClipboardService = n, this._textSelectionRenderManager = s, this._contextService = i, this._commandExecutedListener(), this.initialize();
1227
+ }
1228
+ initialize() {
1229
+ [Ge, Xe, qe].forEach(
1230
+ (r) => this.disposeWithMe(this._commandService.registerAsMultipleCommand(r))
1231
+ ), [_t, ze].forEach(
1232
+ (r) => this.disposeWithMe(this._commandService.registerCommand(r))
1233
+ );
1234
+ }
1235
+ _commandExecutedListener() {
1236
+ const r = [Xe.id, Ge.id, qe.id];
1237
+ this.disposeWithMe(
1238
+ this._commandService.onCommandExecuted((e) => {
1239
+ if (r.includes(e.id) && !(!this._contextService.getContextValue(T) && !this._contextService.getContextValue(ge)))
1240
+ switch (e.id) {
1241
+ case qe.id: {
1242
+ this._handlePaste();
1243
+ break;
1244
+ }
1245
+ case Ge.id: {
1246
+ this._handleCopy();
1247
+ break;
1248
+ }
1249
+ case Xe.id: {
1250
+ this._handleCut();
1251
+ break;
1252
+ }
1253
+ default:
1254
+ throw new Error(`Unhandled command ${e.id}`);
1255
+ }
1256
+ })
1257
+ );
1258
+ }
1259
+ async _handlePaste() {
1260
+ const { _docClipboardService: r } = this, {
1261
+ segmentId: e,
1262
+ endOffset: t,
1263
+ style: n
1264
+ } = this._textSelectionRenderManager.getActiveRange() ?? {}, s = this._textSelectionRenderManager.getAllTextRanges();
1265
+ if (e == null && this._logService.error("[DocClipboardController] segmentId is not existed"), t != null)
1266
+ try {
1267
+ const i = await r.queryClipboardData();
1268
+ let o = t;
1269
+ for (const c of s) {
1270
+ const { startOffset: l, endOffset: d } = c;
1271
+ l == null || d == null || d <= t && (o += i.dataStream.length - (d - l));
1272
+ }
1273
+ const a = [
1274
+ {
1275
+ startOffset: o,
1276
+ endOffset: o,
1277
+ collapsed: !0,
1278
+ style: n
1279
+ }
1280
+ ];
1281
+ this._commandService.executeCommand(_t.id, { body: i, segmentId: e, textRanges: a });
1282
+ } catch {
1283
+ this._logService.error("[DocClipboardController] clipboard is empty");
1284
+ }
1285
+ }
1286
+ _getDocumentBodyInRanges() {
1287
+ const r = this._textSelectionRenderManager.getAllTextRanges(), e = this._currentUniverService.getCurrentUniverDocInstance(), { dataStream: t, textRuns: n = [], paragraphs: s = [] } = e.getBody(), i = [];
1288
+ for (const o of r) {
1289
+ const { startOffset: a, endOffset: c, collapsed: l } = o;
1290
+ if (l || a == null || c == null)
1291
+ continue;
1292
+ const d = {
1293
+ dataStream: t.slice(a, c)
1294
+ }, f = [];
1295
+ for (const u of n) {
1296
+ const g = Q.deepClone(u), { st: p, ed: m } = g;
1297
+ Q.hasIntersectionBetweenTwoRanges(p, m, a, c) && (a >= p && a <= m ? f.push({
1298
+ ...g,
1299
+ st: a,
1300
+ ed: Math.min(c, m)
1301
+ }) : c >= p && c <= m ? f.push({
1302
+ ...g,
1303
+ st: Math.max(a, p),
1304
+ ed: c
1305
+ }) : f.push(g));
1306
+ }
1307
+ f.length && (d.textRuns = f.map((u) => {
1308
+ const { st: g, ed: p } = u;
1309
+ return {
1310
+ ...u,
1311
+ st: g - a,
1312
+ ed: p - a
1313
+ };
1314
+ }));
1315
+ const h = [];
1316
+ for (const u of s) {
1317
+ const { startIndex: g } = u;
1318
+ g >= a && g <= c && h.push(Q.deepClone(u));
1319
+ }
1320
+ h.length && (d.paragraphs = h.map((u) => ({
1321
+ ...u,
1322
+ startIndex: u.startIndex - a
1323
+ }))), i.push(d);
1324
+ }
1325
+ return i;
1326
+ }
1327
+ async _handleCopy() {
1328
+ const { _docClipboardService: r } = this, e = this._getDocumentBodyInRanges();
1329
+ try {
1330
+ r.setClipboardData(e);
1331
+ } catch {
1332
+ this._logService.error("[DocClipboardController] set clipboard failed");
1333
+ }
1334
+ }
1335
+ async _handleCut() {
1336
+ const {
1337
+ segmentId: r,
1338
+ endOffset: e,
1339
+ style: t
1340
+ } = this._textSelectionRenderManager.getActiveRange() ?? {}, n = this._textSelectionRenderManager.getAllTextRanges();
1341
+ if (r == null && this._logService.error("[DocClipboardController] segmentId is not existed"), e != null) {
1342
+ this._handleCopy();
1343
+ try {
1344
+ let s = e;
1345
+ for (const o of n) {
1346
+ const { startOffset: a, endOffset: c } = o;
1347
+ a == null || c == null || c <= e && (s -= c - a);
1348
+ }
1349
+ const i = [
1350
+ {
1351
+ startOffset: s,
1352
+ endOffset: s,
1353
+ collapsed: !0,
1354
+ style: t
1355
+ }
1356
+ ];
1357
+ this._commandService.executeCommand(ze.id, { segmentId: r, textRanges: i });
1358
+ } catch {
1359
+ this._logService.error("[DocClipboardController] cut content failed");
1360
+ }
1361
+ }
1362
+ }
1363
+ };
1364
+ Ce = zn([
1365
+ U(L.Rendered, Ce),
1366
+ q(0, Bt),
1367
+ q(1, D),
1368
+ q(2, I),
1369
+ q(3, Ut),
1370
+ q(4, V),
1371
+ q(5, jt)
1372
+ ], Ce);
1373
+ var Wn = Object.defineProperty, Hn = Object.getOwnPropertyDescriptor, Gn = (r, e, t, n) => {
1374
+ for (var s = n > 1 ? void 0 : n ? Hn(e, t) : e, i = r.length - 1, o; i >= 0; i--)
1375
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
1376
+ return n && s && Wn(e, t, s), s;
1377
+ }, Rt = (r, e) => (t, n) => e(t, n, r);
1378
+ let A = class {
1379
+ constructor(r, e) {
1380
+ _(this, "_currentSkeletonUnitId", "");
1381
+ _(this, "_docSkeletonMap", /* @__PURE__ */ new Map());
1382
+ _(this, "_currentSkeleton$", new Ae(null));
1383
+ _(this, "currentSkeleton$", this._currentSkeleton$.asObservable());
1384
+ /**
1385
+ * CurrentSkeletonBefore for pre-triggered logic during registration
1386
+ */
1387
+ _(this, "_currentSkeletonBefore$", new Ae(null));
1388
+ _(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
1389
+ this._localeService = r, this._docViewModelManagerService = e, this.initialize();
1390
+ }
1391
+ initialize() {
1392
+ this._docViewModelManagerService.currentDocViewModel$.subscribe((r) => {
1393
+ r != null && this._setCurrent(r);
1394
+ });
1395
+ }
1396
+ dispose() {
1397
+ this._currentSkeletonBefore$.complete(), this._currentSkeleton$.complete(), this._docSkeletonMap = /* @__PURE__ */ new Map();
1398
+ }
1399
+ getCurrent() {
1400
+ return this.getSkeletonByUnitId(this._currentSkeletonUnitId);
1401
+ }
1402
+ makeDirtyCurrent(r = !0) {
1403
+ this.makeDirty(this._currentSkeletonUnitId, r);
1404
+ }
1405
+ makeDirty(r, e = !0) {
1406
+ const t = this.getSkeletonByUnitId(r);
1407
+ t != null && (t.dirty = e);
1408
+ }
1409
+ _setCurrent(r) {
1410
+ const { unitId: e } = r;
1411
+ if (this._docSkeletonMap.has(e)) {
1412
+ const t = this.getSkeletonByUnitId(e);
1413
+ t.skeleton.calculate(), t.dirty = !0;
1414
+ } else {
1415
+ const t = this._buildSkeleton(r.docViewModel);
1416
+ t.calculate(), this._docSkeletonMap.set(e, {
1417
+ unitId: e,
1418
+ skeleton: t,
1419
+ dirty: !1
1420
+ });
1421
+ }
1422
+ return this._currentSkeletonUnitId = e, this._currentSkeletonBefore$.next(this.getCurrent()), this._currentSkeleton$.next(this.getCurrent()), this.getCurrent();
1423
+ }
1424
+ getSkeletonByUnitId(r) {
1425
+ return this._docSkeletonMap.get(r);
1426
+ }
1427
+ _buildSkeleton(r) {
1428
+ return Qt.create(r, this._localeService);
1429
+ }
1430
+ };
1431
+ A = Gn([
1432
+ Rt(0, b(xt)),
1433
+ Rt(1, b(ee))
1434
+ ], A);
1435
+ var Xn = Object.defineProperty, qn = Object.getOwnPropertyDescriptor, Yn = (r, e, t, n) => {
1436
+ for (var s = n > 1 ? void 0 : n ? qn(e, t) : e, i = r.length - 1, o; i >= 0; i--)
1437
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
1438
+ return n && s && Xn(e, t, s), s;
1439
+ }, _e = (r, e) => (t, n) => e(t, n, r);
1440
+ let Re = class extends w {
1441
+ constructor(r, e, t, n) {
1442
+ super(), this._docSkeletonManagerService = r, this._currentUniverService = e, this._textSelectionRenderManager = t, this._commandService = n, this._initialize(), this._commandExecutedListener();
1443
+ }
1444
+ _initialize() {
1445
+ }
1446
+ _commandExecutedListener() {
1447
+ const r = [$e.id, Be.id];
1448
+ this.disposeWithMe(
1449
+ this._commandService.onCommandExecuted((e) => {
1450
+ if (r.includes(e.id))
1451
+ switch (e.id) {
1452
+ case $e.id:
1453
+ this._handleDeleteLeft();
1454
+ break;
1455
+ case Be.id:
1456
+ this._handleDeleteRight();
1457
+ break;
1458
+ default:
1459
+ throw new Error("Unknown command");
1460
+ }
1461
+ })
1462
+ );
1463
+ }
1464
+ // Use BACKSPACE to delete left.
1465
+ _handleDeleteLeft() {
1466
+ var u;
1467
+ const r = this._textSelectionRenderManager.getActiveRange(), e = (u = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : u.skeleton;
1468
+ if (r == null || e == null)
1469
+ return;
1470
+ const t = this._currentUniverService.getCurrentUniverDocInstance(), { startOffset: n, collapsed: s, segmentId: i, style: o } = r;
1471
+ if (n === 0 && s)
1472
+ return;
1473
+ const a = e.findNodeByCharIndex(n), c = lt(a), l = en(a, t.body);
1474
+ let d = n;
1475
+ const f = e.findNodeByCharIndex(n - 1);
1476
+ if (tn(a) && f !== a && (c === !0 || l === !0)) {
1477
+ const g = nn(a, t.body);
1478
+ if (g == null)
1479
+ return;
1480
+ const p = g == null ? void 0 : g.startIndex, m = { startIndex: 0 }, v = g.paragraphStyle;
1481
+ if (c === !0) {
1482
+ const y = g.paragraphStyle;
1483
+ y && (m.paragraphStyle = y);
1484
+ } else if (l === !0) {
1485
+ const y = g.bullet;
1486
+ y && (m.bullet = y), v != null && (m.paragraphStyle = { ...v }, delete m.paragraphStyle.hanging, delete m.paragraphStyle.indentStart);
1487
+ }
1488
+ const M = [
1489
+ {
1490
+ startOffset: d,
1491
+ endOffset: d,
1492
+ collapsed: !0,
1493
+ style: o
1494
+ }
1495
+ ];
1496
+ this._commandService.executeCommand(yt.id, {
1497
+ unitId: t.getUnitId(),
1498
+ updateBody: {
1499
+ dataStream: "",
1500
+ paragraphs: [{ ...m }]
1501
+ },
1502
+ range: {
1503
+ startOffset: p,
1504
+ endOffset: p + 1,
1505
+ collapsed: !1
1506
+ },
1507
+ textRanges: M,
1508
+ coverType: Vt.REPLACE,
1509
+ segmentId: i
1510
+ });
1511
+ } else {
1512
+ const { endNodePosition: g } = r;
1513
+ if (g != null) {
1514
+ const p = e.findSpanByPosition(g);
1515
+ lt(p) && !rn(a, p) && (r.endOffset -= 1);
1516
+ }
1517
+ if (s === !0) {
1518
+ d -= f.count;
1519
+ const p = [
1520
+ {
1521
+ startOffset: d,
1522
+ endOffset: d,
1523
+ collapsed: !0,
1524
+ style: o
1525
+ }
1526
+ ];
1527
+ this._commandService.executeCommand(tt.id, {
1528
+ unitId: t.getUnitId(),
1529
+ range: r,
1530
+ segmentId: i,
1531
+ direction: et.LEFT,
1532
+ len: f.count,
1533
+ textRanges: p
1534
+ });
1535
+ } else {
1536
+ const p = this._getTextRangesWhenDelete();
1537
+ this._commandService.executeCommand(ze.id, {
1538
+ segmentId: i,
1539
+ textRanges: p
1540
+ });
1541
+ }
1542
+ }
1543
+ e == null || e.calculate();
1544
+ }
1545
+ // Use DELETE to delete right.
1546
+ _handleDeleteRight() {
1547
+ var a;
1548
+ const r = this._textSelectionRenderManager.getActiveRange(), e = (a = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : a.skeleton;
1549
+ if (r == null || e == null)
1550
+ return;
1551
+ const t = this._currentUniverService.getCurrentUniverDocInstance(), { startOffset: n, collapsed: s, segmentId: i, style: o } = r;
1552
+ if (!(n === t.getBody().dataStream.length - 2 && s)) {
1553
+ if (s === !0) {
1554
+ const c = [
1555
+ {
1556
+ startOffset: n,
1557
+ endOffset: n,
1558
+ collapsed: !0,
1559
+ style: o
1560
+ }
1561
+ ], l = e.findNodeByCharIndex(n);
1562
+ this._commandService.executeCommand(tt.id, {
1563
+ unitId: t.getUnitId(),
1564
+ range: r,
1565
+ segmentId: i,
1566
+ direction: et.RIGHT,
1567
+ textRanges: c,
1568
+ len: l.count
1569
+ });
1570
+ } else {
1571
+ const c = this._getTextRangesWhenDelete();
1572
+ this._commandService.executeCommand(ze.id, {
1573
+ segmentId: i,
1574
+ textRanges: c
1575
+ });
1576
+ }
1577
+ e == null || e.calculate();
1578
+ }
1579
+ }
1580
+ // get cursor position when BACKSPACE/DELETE excuse the CutContentCommand.
1581
+ _getTextRangesWhenDelete() {
1582
+ const r = this._textSelectionRenderManager.getActiveRange(), e = this._textSelectionRenderManager.getAllTextRanges();
1583
+ let t = r.endOffset;
1584
+ for (const s of e) {
1585
+ const { startOffset: i, endOffset: o } = s;
1586
+ i == null || o == null || o <= r.endOffset && (t -= o - i);
1587
+ }
1588
+ return [
1589
+ {
1590
+ startOffset: t,
1591
+ endOffset: t,
1592
+ collapsed: !0,
1593
+ style: r.style
1594
+ }
1595
+ ];
1596
+ }
1597
+ };
1598
+ Re = Yn([
1599
+ U(L.Rendered, Re),
1600
+ _e(0, b(A)),
1601
+ _e(1, I),
1602
+ _e(2, V),
1603
+ _e(3, D)
1604
+ ], Re);
1605
+ var Zn = Object.defineProperty, Kn = Object.getOwnPropertyDescriptor, Jn = (r, e, t, n) => {
1606
+ for (var s = n > 1 ? void 0 : n ? Kn(e, t) : e, i = r.length - 1, o; i >= 0; i--)
1607
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
1608
+ return n && s && Zn(e, t, s), s;
1609
+ }, Ye = (r, e) => (t, n) => e(t, n, r);
1610
+ let Ie = class extends w {
1611
+ constructor(r, e, t) {
1612
+ super(), this._docSkeletonManagerService = r, this._renderManagerService = e, this._commandService = t, this._initialRenderRefresh(), this._commandExecutedListener();
1613
+ }
1614
+ _initialRenderRefresh() {
1615
+ this._docSkeletonManagerService.currentSkeletonBefore$.subscribe((r) => {
1616
+ if (r == null)
1617
+ return;
1618
+ const { skeleton: e, unitId: t } = r, n = this._renderManagerService.getRenderById(t);
1619
+ if (n == null)
1620
+ return;
1621
+ const { mainComponent: s } = n;
1622
+ s.changeSkeleton(e), this._recalculateSizeBySkeleton(n, e);
1623
+ });
1624
+ }
1625
+ // calculatePagePosition(currentRender: IRender) {
1626
+ // const { mainComponent, scene } = currentRender;
1627
+ // const docsComponent = mainComponent as Documents;
1628
+ // const parent = scene?.getParent();
1629
+ // const { width: docsWidth, height: docsHeight, pageMarginLeft, pageMarginTop } = docsComponent;
1630
+ // if (parent == null || docsWidth === Infinity || docsHeight === Infinity) {
1631
+ // return;
1632
+ // }
1633
+ // const { width: engineWidth, height: engineHeight } = parent;
1634
+ // let docsLeft = 0;
1635
+ // let docsTop = 0;
1636
+ // let sceneWidth = 0;
1637
+ // let sceneHeight = 0;
1638
+ // if (engineWidth > docsWidth) {
1639
+ // docsLeft = engineWidth / 2 - docsWidth / 2;
1640
+ // sceneWidth = engineWidth - 34;
1641
+ // } else {
1642
+ // docsLeft = pageMarginLeft;
1643
+ // sceneWidth = docsWidth + pageMarginLeft * 2;
1644
+ // }
1645
+ // if (engineHeight > docsHeight) {
1646
+ // docsTop = engineHeight / 2 - docsHeight / 2;
1647
+ // sceneHeight = engineHeight - 34;
1648
+ // } else {
1649
+ // docsTop = pageMarginTop;
1650
+ // sceneHeight = docsHeight + pageMarginTop * 2;
1651
+ // }
1652
+ // // this.docsLeft = docsLeft;
1653
+ // // this.docsTop = docsTop;
1654
+ // scene.resize(sceneWidth, sceneHeight + 200);
1655
+ // docsComponent.translate(docsLeft, docsTop);
1656
+ // return this;
1657
+ // }
1658
+ _recalculateSizeBySkeleton(r, e) {
1659
+ var a;
1660
+ const { mainComponent: t } = r, n = t, s = (a = e.getSkeletonData()) == null ? void 0 : a.pages;
1661
+ if (s == null)
1662
+ return;
1663
+ let i = 0, o = 0;
1664
+ for (let c = 0, l = s.length; c < l; c++) {
1665
+ const d = s[c], { pageWidth: f, pageHeight: h } = d;
1666
+ n.pageLayoutType === dt.VERTICAL ? (o += h, c !== l - 1 && (o += n.pageMarginTop), i = Math.max(i, f)) : n.pageLayoutType === dt.HORIZONTAL && (i += f, c !== l - 1 && (i += n.pageMarginLeft), o = Math.max(o, h));
1667
+ }
1668
+ n.resize(i, o);
1669
+ }
1670
+ _commandExecutedListener() {
1671
+ const r = [S.id], e = [te, ne];
1672
+ this.disposeWithMe(
1673
+ this._commandService.onCommandExecuted((t) => {
1674
+ var n;
1675
+ if (r.includes(t.id)) {
1676
+ const s = t.params, { unitId: i } = s, o = this._docSkeletonManagerService.getSkeletonByUnitId(i);
1677
+ if (o == null)
1678
+ return;
1679
+ const { skeleton: a } = o, c = this._renderManagerService.getRenderById(i);
1680
+ if (c == null)
1681
+ return;
1682
+ if (a.calculate(), e.includes(i)) {
1683
+ (n = c.mainComponent) == null || n.makeDirty();
1684
+ return;
1685
+ }
1686
+ this._recalculateSizeBySkeleton(c, a);
1687
+ }
1688
+ })
1689
+ );
1690
+ }
1691
+ };
1692
+ Ie = Jn([
1693
+ U(L.Rendered, Ie),
1694
+ Ye(0, b(A)),
1695
+ Ye(1, j),
1696
+ Ye(2, D)
1697
+ ], Ie);
1698
+ var Qn = Object.defineProperty, er = Object.getOwnPropertyDescriptor, tr = (r, e, t, n) => {
1699
+ for (var s = n > 1 ? void 0 : n ? er(e, t) : e, i = r.length - 1, o; i >= 0; i--)
1700
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
1701
+ return n && s && Qn(e, t, s), s;
1702
+ }, oe = (r, e) => (t, n) => e(t, n, r);
1703
+ let xe = class extends w {
1704
+ constructor(e, t, n, s, i) {
1705
+ super();
1706
+ _(this, "_liquid", new sn());
1707
+ _(this, "_pageMarginCache", /* @__PURE__ */ new Map());
1708
+ this._docSkeletonManagerService = e, this._currentUniverService = t, this._renderManagerService = n, this._commandService = s, this._floatingObjectManagerService = i, this._initialize(), this._commandExecutedListener();
1709
+ }
1710
+ _initialize() {
1711
+ this._initialRenderRefresh(), this._updateOnPluginChange();
1712
+ }
1713
+ _updateOnPluginChange() {
1714
+ this._floatingObjectManagerService.pluginUpdate$.subscribe((e) => {
1715
+ const t = this._docSkeletonManagerService.getCurrent();
1716
+ if (t == null)
1717
+ return;
1718
+ const { unitId: n, skeleton: s } = t, i = this._renderManagerService.getRenderById(n);
1719
+ if (i == null)
1720
+ return;
1721
+ const { mainComponent: o, components: a, scene: c } = i, l = o, { left: d, top: f } = l;
1722
+ e.forEach((h) => {
1723
+ const { unitId: u, subComponentId: g, floatingObjectId: p, floatingObject: m } = h, { left: v = 0, top: M = 0, width: y = 0, height: E = 0, angle: z, flipX: k, flipY: re, skewX: se, skewY: ie } = m, x = this._pageMarginCache.get(p), F = (x == null ? void 0 : x.marginLeft) || 0, $ = (x == null ? void 0 : x.marginTop) || 0;
1724
+ s == null || s.getViewModel().getDataModel().updateDrawing(p, {
1725
+ left: v - d - F,
1726
+ top: M - f - $,
1727
+ height: E,
1728
+ width: y
1729
+ });
1730
+ }), s == null || s.calculate(), o == null || o.makeDirty();
1731
+ });
1732
+ }
1733
+ _initialRenderRefresh() {
1734
+ this._docSkeletonManagerService.currentSkeleton$.subscribe((e) => {
1735
+ if (e == null)
1736
+ return;
1737
+ const { skeleton: t, unitId: n } = e, s = this._renderManagerService.getRenderById(n);
1738
+ if (s == null)
1739
+ return;
1740
+ const { mainComponent: i } = s;
1741
+ i.changeSkeleton(t), this._refreshFloatingObject(n, t, s);
1742
+ });
1743
+ }
1744
+ _commandExecutedListener() {
1745
+ const e = [S.id, H.id], t = [te, ne];
1746
+ this.disposeWithMe(
1747
+ this._commandService.onCommandExecuted((n) => {
1748
+ var s;
1749
+ if (e.includes(n.id)) {
1750
+ const i = n.params, { unitId: o } = i, a = this._docSkeletonManagerService.getCurrent();
1751
+ if (a == null)
1752
+ return;
1753
+ const { unitId: c, skeleton: l } = a;
1754
+ if (o !== c)
1755
+ return;
1756
+ const d = this._renderManagerService.getRenderById(c);
1757
+ if (d == null)
1758
+ return;
1759
+ if (t.includes(c)) {
1760
+ (s = d.mainComponent) == null || s.makeDirty();
1761
+ return;
1762
+ }
1763
+ this._refreshFloatingObject(c, l, d);
1764
+ }
1765
+ })
1766
+ );
1767
+ }
1768
+ _refreshFloatingObject(e, t, n) {
1769
+ const s = t == null ? void 0 : t.getSkeletonData(), { mainComponent: i, scene: o } = n, a = i;
1770
+ if (!s)
1771
+ return;
1772
+ const { left: c, top: l, pageLayoutType: d, pageMarginLeft: f, pageMarginTop: h } = a, { pages: u } = s, g = [];
1773
+ o.getAncestorScale(), this._liquid.reset(), this._pageMarginCache.clear();
1774
+ for (let p = 0, m = u.length; p < m; p++) {
1775
+ const v = u[p], { skeDrawings: M, marginLeft: y, marginTop: E } = v;
1776
+ this._liquid.translatePagePadding(v), M.forEach((z) => {
1777
+ const { aLeft: k, aTop: re, height: se, width: ie, objectId: x } = z;
1778
+ g.push({
1779
+ unitId: e,
1780
+ subComponentId: kt,
1781
+ floatingObjectId: x,
1782
+ floatingObject: {
1783
+ left: k + c + this._liquid.x,
1784
+ top: re + l + this._liquid.y,
1785
+ width: ie,
1786
+ height: se
1787
+ }
1788
+ }), this._pageMarginCache.set(x, {
1789
+ marginLeft: this._liquid.x,
1790
+ marginTop: this._liquid.y
1791
+ });
1792
+ }), this._liquid.translatePage(v, d, f, h);
1793
+ }
1794
+ this._floatingObjectManagerService.BatchAddOrUpdate(g);
1795
+ }
1796
+ };
1797
+ xe = tr([
1798
+ U(L.Steady, xe),
1799
+ oe(0, b(A)),
1800
+ oe(1, I),
1801
+ oe(2, j),
1802
+ oe(3, D),
1803
+ oe(4, Ft)
1804
+ ], xe);
1805
+ var nr = Object.defineProperty, rr = Object.getOwnPropertyDescriptor, sr = (r, e, t, n) => {
1806
+ for (var s = n > 1 ? void 0 : n ? rr(e, t) : e, i = r.length - 1, o; i >= 0; i--)
1807
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
1808
+ return n && s && nr(e, t, s), s;
1809
+ }, W = (r, e) => (t, n) => e(t, n, r);
1810
+ let Oe = class extends w {
1811
+ constructor(e, t, n, s, i, o, a) {
1812
+ super();
1813
+ _(this, "_previousIMEContent", "");
1814
+ _(this, "_previousIMERange");
1815
+ _(this, "_onStartSubscription");
1816
+ _(this, "_onUpdateSubscription");
1817
+ _(this, "_onEndSubscription");
1818
+ this._docSkeletonManagerService = e, this._currentUniverService = t, this._renderManagerService = n, this._textSelectionRenderManager = s, this._textSelectionManagerService = i, this._imeInputManagerService = o, this._commandService = a, this._initialize();
1819
+ }
1820
+ dispose() {
1821
+ var e, t, n;
1822
+ (e = this._onStartSubscription) == null || e.unsubscribe(), (t = this._onUpdateSubscription) == null || t.unsubscribe(), (n = this._onEndSubscription) == null || n.unsubscribe();
1823
+ }
1824
+ _initialize() {
1825
+ this._initialOnCompositionstart(), this._initialOnCompositionUpdate(), this._initialOnCompositionend();
1826
+ }
1827
+ _initialOnCompositionstart() {
1828
+ this._onStartSubscription = this._textSelectionRenderManager.onCompositionstart$.subscribe((e) => {
1829
+ if (e == null)
1830
+ return;
1831
+ const { activeRange: t } = e;
1832
+ t != null && (this._imeInputManagerService.clearUndoRedoMutationParamsCache(), this._imeInputManagerService.setActiveRange(Q.deepClone(t)), this._previousIMERange = t);
1833
+ });
1834
+ }
1835
+ _initialOnCompositionUpdate() {
1836
+ this._onUpdateSubscription = this._textSelectionRenderManager.onCompositionupdate$.subscribe(async (e) => {
1837
+ this._updateContent(e, !0);
1838
+ });
1839
+ }
1840
+ _initialOnCompositionend() {
1841
+ this._onEndSubscription = this._textSelectionRenderManager.onCompositionend$.subscribe((e) => {
1842
+ this._updateContent(e, !1);
1843
+ });
1844
+ }
1845
+ async _updateContent(e, t) {
1846
+ var g;
1847
+ const n = (g = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : g.skeleton;
1848
+ if (this._previousIMERange == null || e == null || n == null)
1849
+ return;
1850
+ const s = this._currentUniverService.getCurrentUniverDocInstance(), { event: i, activeRange: o } = e, { startOffset: a, segmentId: c, style: l } = this._previousIMERange;
1851
+ if (n == null || o == null)
1852
+ return;
1853
+ const f = i.data;
1854
+ if (f === this._previousIMEContent && t)
1855
+ return;
1856
+ const h = f.length, u = [
1857
+ {
1858
+ startOffset: a + h,
1859
+ endOffset: a + h,
1860
+ collapsed: !0,
1861
+ style: l
1862
+ }
1863
+ ];
1864
+ await this._commandService.executeCommand(bt.id, {
1865
+ unitId: s.getUnitId(),
1866
+ newText: f,
1867
+ oldTextLen: this._previousIMEContent.length,
1868
+ range: this._previousIMERange,
1869
+ textRanges: u,
1870
+ isCompositionEnd: !t,
1871
+ segmentId: c
1872
+ }), n.calculate(), t ? (this._previousIMERange.collapsed || (this._previousIMERange.collapsed = !0), this._previousIMEContent = f) : this._resetIME();
1873
+ }
1874
+ _resetIME() {
1875
+ this._previousIMEContent = "", this._previousIMERange = null, this._imeInputManagerService.clearUndoRedoMutationParamsCache(), this._imeInputManagerService.setActiveRange(null);
1876
+ }
1877
+ _getDocObject() {
1878
+ return pe(this._currentUniverService, this._renderManagerService);
1879
+ }
1880
+ };
1881
+ Oe = sr([
1882
+ U(L.Rendered, Oe),
1883
+ W(0, b(A)),
1884
+ W(1, I),
1885
+ W(2, j),
1886
+ W(3, V),
1887
+ W(4, b(P)),
1888
+ W(5, b(ot)),
1889
+ W(6, D)
1890
+ ], Oe);
1891
+ var ir = Object.defineProperty, or = Object.getOwnPropertyDescriptor, ar = (r, e, t, n) => {
1892
+ for (var s = n > 1 ? void 0 : n ? or(e, t) : e, i = r.length - 1, o; i >= 0; i--)
1893
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
1894
+ return n && s && ir(e, t, s), s;
1895
+ }, Se = (r, e) => (t, n) => e(t, n, r);
1896
+ let ye = class extends w {
1897
+ constructor(r, e, t, n) {
1898
+ super(), this._currentUniverService = r, this._textSelectionRenderManager = e, this._textSelectionManagerService = t, this._commandService = n, this._commandExecutedListener();
1899
+ }
1900
+ _commandExecutedListener() {
1901
+ const r = [
1902
+ ce.id,
1903
+ je.id,
1904
+ Ve.id,
1905
+ ke.id,
1906
+ le.id,
1907
+ de.id,
1908
+ Fe.id
1909
+ ];
1910
+ this.disposeWithMe(
1911
+ this._commandService.onCommandExecuted((e) => {
1912
+ r.includes(e.id) && this._handleInlineFormat(e);
1913
+ })
1914
+ );
1915
+ }
1916
+ _handleInlineFormat(r) {
1917
+ const { segmentId: e } = this._textSelectionRenderManager.getActiveRange() ?? {};
1918
+ e != null && this._commandService.executeCommand(Dt.id, {
1919
+ segmentId: e,
1920
+ preCommandId: r.id,
1921
+ ...r.params ?? {}
1922
+ });
1923
+ }
1924
+ };
1925
+ ye = ar([
1926
+ U(L.Rendered, ye),
1927
+ Se(0, I),
1928
+ Se(1, V),
1929
+ Se(2, b(P)),
1930
+ Se(3, D)
1931
+ ], ye);
1932
+ var cr = Object.defineProperty, lr = Object.getOwnPropertyDescriptor, dr = (r, e, t, n) => {
1933
+ for (var s = n > 1 ? void 0 : n ? lr(e, t) : e, i = r.length - 1, o; i >= 0; i--)
1934
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
1935
+ return n && s && cr(e, t, s), s;
1936
+ }, Y = (r, e) => (t, n) => e(t, n, r);
1937
+ function ur(r) {
1938
+ const e = [];
1939
+ for (let t = 0, n = r.length; t < n; t++)
1940
+ r[t] === Je.PARAGRAPH && e.push({
1941
+ startIndex: t
1942
+ });
1943
+ return e;
1944
+ }
1945
+ let be = class extends w {
1946
+ constructor(e, t, n, s, i, o) {
1947
+ super();
1948
+ _(this, "_onInputSubscription");
1949
+ this._docSkeletonManagerService = e, this._currentUniverService = t, this._renderManagerService = n, this._textSelectionRenderManager = s, this._textSelectionManagerService = i, this._commandService = o, this._initialize(), this._commandExecutedListener();
1950
+ }
1951
+ dispose() {
1952
+ var e;
1953
+ (e = this._onInputSubscription) == null || e.unsubscribe();
1954
+ }
1955
+ _initialize() {
1956
+ }
1957
+ _commandExecutedListener() {
1958
+ const e = [st.id];
1959
+ this.disposeWithMe(
1960
+ this._commandService.onCommandExecuted((t) => {
1961
+ e.includes(t.id) && this._handleBreakLine();
1962
+ })
1963
+ );
1964
+ }
1965
+ _handleBreakLine() {
1966
+ var l;
1967
+ const e = (l = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : l.skeleton, t = this._textSelectionRenderManager.getActiveRange();
1968
+ if (t == null || e == null)
1969
+ return;
1970
+ const s = this._currentUniverService.getCurrentUniverDocInstance().getUnitId(), { startOffset: i, segmentId: o, style: a } = t, c = [
1971
+ {
1972
+ startOffset: i + 1,
1973
+ endOffset: i + 1,
1974
+ collapsed: !0,
1975
+ style: a
1976
+ }
1977
+ ];
1978
+ this._commandService.executeCommand(it.id, {
1979
+ unitId: s,
1980
+ body: {
1981
+ dataStream: Je.PARAGRAPH,
1982
+ paragraphs: ur(Je.PARAGRAPH)
1983
+ },
1984
+ range: t,
1985
+ textRanges: c,
1986
+ segmentId: o
1987
+ }), e == null || e.calculate();
1988
+ }
1989
+ _getDocObject() {
1990
+ return pe(this._currentUniverService, this._renderManagerService);
1991
+ }
1992
+ };
1993
+ be = dr([
1994
+ U(L.Rendered, be),
1995
+ Y(0, b(A)),
1996
+ Y(1, I),
1997
+ Y(2, j),
1998
+ Y(3, V),
1999
+ Y(4, b(P)),
2000
+ Y(5, D)
2001
+ ], be);
2002
+ var hr = Object.defineProperty, gr = Object.getOwnPropertyDescriptor, fr = (r, e, t, n) => {
2003
+ for (var s = n > 1 ? void 0 : n ? gr(e, t) : e, i = r.length - 1, o; i >= 0; i--)
2004
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
2005
+ return n && s && hr(e, t, s), s;
2006
+ }, Z = (r, e) => (t, n) => e(t, n, r);
2007
+ let De = class extends w {
2008
+ constructor(e, t, n, s, i, o) {
2009
+ super();
2010
+ _(this, "_onInputSubscription");
2011
+ this._docSkeletonManagerService = e, this._currentUniverService = t, this._renderManagerService = n, this._textSelectionRenderManager = s, this._textSelectionManagerService = i, this._commandService = o, this._initialize(), this._commandExecutedListener();
2012
+ }
2013
+ dispose() {
2014
+ var e;
2015
+ (e = this._onInputSubscription) == null || e.unsubscribe();
2016
+ }
2017
+ _initialize() {
2018
+ }
2019
+ _commandExecutedListener() {
2020
+ const e = [G.id, X.id];
2021
+ this.disposeWithMe(
2022
+ this._commandService.onCommandExecuted((t) => {
2023
+ if (!e.includes(t.id))
2024
+ return;
2025
+ const n = t.params;
2026
+ switch (t.id) {
2027
+ case G.id:
2028
+ return this._handleMoveCursor(n.direction);
2029
+ case X.id:
2030
+ return this._handleShiftMoveSelection(n.direction);
2031
+ default:
2032
+ throw new Error("Unknown command");
2033
+ }
2034
+ })
2035
+ );
2036
+ }
2037
+ _handleShiftMoveSelection(e) {
2038
+ var p;
2039
+ const t = this._textSelectionRenderManager.getActiveRange(), n = this._textSelectionRenderManager.getAllTextRanges(), s = this._currentUniverService.getCurrentUniverDocInstance(), i = (p = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : p.skeleton, o = this._getDocObject();
2040
+ if (t == null || i == null || o == null)
2041
+ return;
2042
+ const { startOffset: a, endOffset: c, style: l, collapsed: d, direction: f } = t;
2043
+ if (n.length > 1) {
2044
+ let m = 1 / 0, v = -1 / 0;
2045
+ for (const M of n)
2046
+ m = Math.min(m, M.startOffset), v = Math.max(v, M.endOffset);
2047
+ this._textSelectionManagerService.replaceTextRanges([
2048
+ {
2049
+ startOffset: e === R.LEFT || e === R.UP ? v : m,
2050
+ endOffset: e === R.LEFT || e === R.UP ? m : v,
2051
+ collapsed: !1,
2052
+ style: l
2053
+ }
2054
+ ]);
2055
+ return;
2056
+ }
2057
+ const h = d || f === ut.FORWARD ? a : c;
2058
+ let u = d || f === ut.FORWARD ? c : a;
2059
+ const g = s.getBody().dataStream.length ?? 1 / 0;
2060
+ if (e === R.LEFT || e === R.RIGHT) {
2061
+ const m = i.findNodeByCharIndex(u - 1), v = i.findNodeByCharIndex(u);
2062
+ u = e === R.RIGHT ? u + v.count : u - m.count, u = Math.min(g - 2, Math.max(0, u)), this._textSelectionManagerService.replaceTextRanges([
2063
+ {
2064
+ startOffset: h,
2065
+ endOffset: u,
2066
+ collapsed: h === u,
2067
+ style: l
2068
+ }
2069
+ ]);
2070
+ } else {
2071
+ const m = i.findNodeByCharIndex(u), v = o.document.getOffsetConfig(), M = this._getTopOrBottomPosition(i, m, e === R.DOWN);
2072
+ if (M == null) {
2073
+ const E = e === R.UP ? 0 : g - 2;
2074
+ if (E === u)
2075
+ return;
2076
+ this._textSelectionManagerService.replaceTextRanges([
2077
+ {
2078
+ startOffset: h,
2079
+ endOffset: E,
2080
+ collapsed: h === E,
2081
+ style: l
2082
+ }
2083
+ ]);
2084
+ return;
2085
+ }
2086
+ const y = new ht(v, i).getRangePointData(
2087
+ M,
2088
+ M
2089
+ ).cursorList[0];
2090
+ this._textSelectionManagerService.replaceTextRanges([
2091
+ {
2092
+ startOffset: h,
2093
+ endOffset: y.endOffset,
2094
+ collapsed: h === y.endOffset,
2095
+ style: l
2096
+ }
2097
+ ]);
2098
+ }
2099
+ }
2100
+ _handleMoveCursor(e) {
2101
+ var h;
2102
+ const t = this._textSelectionRenderManager.getActiveRange(), n = this._textSelectionRenderManager.getAllTextRanges(), s = this._currentUniverService.getCurrentUniverDocInstance(), i = (h = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : h.skeleton, o = this._getDocObject();
2103
+ if (t == null || i == null || o == null)
2104
+ return;
2105
+ const { startOffset: a, endOffset: c, style: l, collapsed: d } = t, f = s.getBody().dataStream.length ?? 1 / 0;
2106
+ if (e === R.LEFT || e === R.RIGHT) {
2107
+ let u;
2108
+ if (!t.collapsed || n.length > 1) {
2109
+ let g = 1 / 0, p = -1 / 0;
2110
+ for (const m of n)
2111
+ g = Math.min(g, m.startOffset), p = Math.max(p, m.endOffset);
2112
+ u = e === R.LEFT ? g : p;
2113
+ } else {
2114
+ const g = i.findNodeByCharIndex(a - 1), p = i.findNodeByCharIndex(a);
2115
+ e === R.LEFT ? u = Math.max(0, a - g.count) : u = Math.min(f - 2, c + p.count);
2116
+ }
2117
+ this._textSelectionManagerService.replaceTextRanges([
2118
+ {
2119
+ startOffset: u,
2120
+ endOffset: u,
2121
+ collapsed: !0,
2122
+ style: l
2123
+ }
2124
+ ]);
2125
+ } else {
2126
+ const u = i.findNodeByCharIndex(a), g = i.findNodeByCharIndex(c), p = o.document.getOffsetConfig(), m = this._getTopOrBottomPosition(
2127
+ i,
2128
+ e === R.UP ? u : g,
2129
+ e === R.DOWN
2130
+ );
2131
+ if (m == null) {
2132
+ let M;
2133
+ d ? M = e === R.UP ? 0 : f - 2 : M = e === R.UP ? a : c, this._textSelectionManagerService.replaceTextRanges([
2134
+ {
2135
+ startOffset: M,
2136
+ endOffset: M,
2137
+ collapsed: !0,
2138
+ style: l
2139
+ }
2140
+ ]);
2141
+ return;
2142
+ }
2143
+ const v = new ht(p, i).getRangePointData(
2144
+ m,
2145
+ m
2146
+ ).cursorList[0];
2147
+ this._textSelectionManagerService.replaceTextRanges([
2148
+ {
2149
+ ...v,
2150
+ style: l
2151
+ }
2152
+ ]);
2153
+ }
2154
+ }
2155
+ _getTopOrBottomPosition(e, t, n) {
2156
+ if (t == null)
2157
+ return;
2158
+ const s = this._getSpanLeftOffsetInLine(t), i = this._getNextOrPrevLine(t, n);
2159
+ if (i == null)
2160
+ return;
2161
+ const o = this._matchPositionByLeftOffset(e, i, s);
2162
+ if (o != null)
2163
+ return { ...o, isBack: !0 };
2164
+ }
2165
+ _getSpanLeftOffsetInLine(e) {
2166
+ const t = e.parent;
2167
+ if (t == null)
2168
+ return -1 / 0;
2169
+ const n = t.left, { left: s } = e;
2170
+ return n + s;
2171
+ }
2172
+ _matchPositionByLeftOffset(e, t, n) {
2173
+ const s = {
2174
+ distance: 1 / 0
2175
+ };
2176
+ for (const i of t.divides) {
2177
+ const o = i.left;
2178
+ for (const a of i.spanGroup) {
2179
+ const { left: c } = a, l = o + c, d = Math.abs(n - l);
2180
+ d < s.distance && (s.span = a, s.distance = d);
2181
+ }
2182
+ }
2183
+ if (s.span != null)
2184
+ return e.findPositionBySpan(s.span);
2185
+ }
2186
+ _getNextOrPrevLine(e, t) {
2187
+ var g, p, m, v, M, y, E, z, k, re, se, ie;
2188
+ const n = e.parent;
2189
+ if (n == null)
2190
+ return;
2191
+ const s = n.parent;
2192
+ if (s == null)
2193
+ return;
2194
+ const i = s.parent;
2195
+ if (i == null)
2196
+ return;
2197
+ const o = i.lines.indexOf(s);
2198
+ if (o === -1)
2199
+ return;
2200
+ let a;
2201
+ if (t === !0 ? a = i.lines[o + 1] : a = i.lines[o - 1], a != null)
2202
+ return a;
2203
+ const c = i.parent;
2204
+ if (c == null)
2205
+ return;
2206
+ const l = c.columns.indexOf(i);
2207
+ if (l === -1)
2208
+ return;
2209
+ if (t === !0)
2210
+ a = (g = c.columns[l + 1]) == null ? void 0 : g.lines[0];
2211
+ else {
2212
+ const x = (m = (p = c.columns) == null ? void 0 : p[l - 1]) == null ? void 0 : m.lines;
2213
+ a = x == null ? void 0 : x[x.length - 1];
2214
+ }
2215
+ if (a != null)
2216
+ return a;
2217
+ const d = c.parent;
2218
+ if (d == null)
2219
+ return;
2220
+ const f = d.sections.indexOf(c);
2221
+ if (f === -1)
2222
+ return;
2223
+ if (t === !0)
2224
+ a = (M = (v = d.sections[f - 1]) == null ? void 0 : v.columns[0]) == null ? void 0 : M.lines[0];
2225
+ else {
2226
+ const x = (E = (y = d.sections) == null ? void 0 : y[f - 1]) == null ? void 0 : E.columns, F = x == null ? void 0 : x[x.length - 1], $ = F == null ? void 0 : F.lines;
2227
+ a = $ == null ? void 0 : $[$.length - 1];
2228
+ }
2229
+ if (a != null)
2230
+ return a;
2231
+ const h = d.parent;
2232
+ if (h == null)
2233
+ return;
2234
+ const u = h.pages.indexOf(d);
2235
+ if (u !== -1) {
2236
+ if (t === !0)
2237
+ a = (re = (k = (z = h.pages[u + 1]) == null ? void 0 : z.sections[0]) == null ? void 0 : k.columns[0]) == null ? void 0 : re.lines[0];
2238
+ else {
2239
+ const x = (se = h.pages[u - 1]) == null ? void 0 : se.sections;
2240
+ if (x == null)
2241
+ return;
2242
+ const F = (ie = x[x.length - 1]) == null ? void 0 : ie.columns, $ = F[F.length - 1], ct = $ == null ? void 0 : $.lines;
2243
+ a = ct[ct.length - 1];
2244
+ }
2245
+ if (a != null)
2246
+ return a;
2247
+ }
2248
+ }
2249
+ _getDocObject() {
2250
+ return pe(this._currentUniverService, this._renderManagerService);
2251
+ }
2252
+ };
2253
+ De = fr([
2254
+ U(L.Rendered, De),
2255
+ Z(0, b(A)),
2256
+ Z(1, I),
2257
+ Z(2, j),
2258
+ Z(3, V),
2259
+ Z(4, b(P)),
2260
+ Z(5, D)
2261
+ ], De);
2262
+ var pr = Object.defineProperty, mr = Object.getOwnPropertyDescriptor, _r = (r, e, t, n) => {
2263
+ for (var s = n > 1 ? void 0 : n ? mr(e, t) : e, i = r.length - 1, o; i >= 0; i--)
2264
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
2265
+ return n && s && pr(e, t, s), s;
2266
+ }, K = (r, e) => (t, n) => e(t, n, r);
2267
+ let Pe = class extends w {
2268
+ constructor(e, t, n, s, i, o) {
2269
+ super();
2270
+ _(this, "_onInputSubscription");
2271
+ this._docSkeletonManagerService = e, this._currentUniverService = t, this._renderManagerService = n, this._textSelectionRenderManager = s, this._textSelectionManagerService = i, this._commandService = o, this._initialize(), this._commandExecutedListener();
2272
+ }
2273
+ dispose() {
2274
+ var e;
2275
+ (e = this._onInputSubscription) == null || e.unsubscribe();
2276
+ }
2277
+ _initialize() {
2278
+ this._initialNormalInput();
2279
+ }
2280
+ _initialNormalInput() {
2281
+ this._onInputSubscription = this._textSelectionRenderManager.onInput$.subscribe(async (e) => {
2282
+ var u;
2283
+ if (e == null)
2284
+ return;
2285
+ const t = this._currentUniverService.getCurrentUniverDocInstance(), { event: n, content: s = "", activeRange: i } = e, o = n, a = (u = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : u.skeleton;
2286
+ if (o.data == null || a == null || !a || !i)
2287
+ return;
2288
+ const { startOffset: c, segmentId: l, style: d } = i, f = s.length, h = [
2289
+ {
2290
+ startOffset: c + f,
2291
+ endOffset: c + f,
2292
+ collapsed: !0,
2293
+ style: d
2294
+ }
2295
+ ];
2296
+ await this._commandService.executeCommand(it.id, {
2297
+ unitId: t.getUnitId(),
2298
+ body: {
2299
+ dataStream: s
2300
+ },
2301
+ range: i,
2302
+ textRanges: h,
2303
+ segmentId: l
2304
+ }), a.calculate();
2305
+ });
2306
+ }
2307
+ _commandExecutedListener() {
2308
+ }
2309
+ _getDocObject() {
2310
+ return pe(this._currentUniverService, this._renderManagerService);
2311
+ }
2312
+ };
2313
+ Pe = _r([
2314
+ U(L.Rendered, Pe),
2315
+ K(0, b(A)),
2316
+ K(1, I),
2317
+ K(2, j),
2318
+ K(3, V),
2319
+ K(4, b(P)),
2320
+ K(5, D)
2321
+ ], Pe);
2322
+ var Sr = Object.defineProperty, vr = Object.getOwnPropertyDescriptor, Mr = (r, e, t, n) => {
2323
+ for (var s = n > 1 ? void 0 : n ? vr(e, t) : e, i = r.length - 1, o; i >= 0; i--)
2324
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
2325
+ return n && s && Sr(e, t, s), s;
2326
+ }, Cr = (r, e) => (t, n) => e(t, n, r);
2327
+ const Rr = "rgba(198,198,198, 1)", Ir = "rgba(255,255,255, 1)";
2328
+ let Te = class extends w {
2329
+ constructor(r) {
2330
+ super(), this._renderManagerService = r, this._initialize(), this._commandExecutedListener();
2331
+ }
2332
+ _initialize() {
2333
+ this._initialRenderRefresh();
2334
+ }
2335
+ _initialRenderRefresh() {
2336
+ this._renderManagerService.currentRender$.subscribe((r) => {
2337
+ var i;
2338
+ if (r == null)
2339
+ return;
2340
+ const e = this._renderManagerService.getRenderById(r);
2341
+ if (e == null)
2342
+ return;
2343
+ const { mainComponent: t } = e, n = t, s = (i = n.getSkeleton()) == null ? void 0 : i.getPageSize();
2344
+ n.onPageRenderObservable.add((o) => {
2345
+ if ([te, ne].includes(r))
2346
+ return;
2347
+ const { page: a, pageLeft: c, pageTop: l, ctx: d } = o, { width: f, height: h } = a;
2348
+ d.save(), d.translate(c - 0.5, l - 0.5), on.drawWith(d, {
2349
+ width: (s == null ? void 0 : s.width) || f,
2350
+ height: (s == null ? void 0 : s.height) || h,
2351
+ strokeWidth: 1,
2352
+ stroke: Rr,
2353
+ fill: Ir,
2354
+ zIndex: 3
2355
+ }), d.restore();
2356
+ });
2357
+ });
2358
+ }
2359
+ _commandExecutedListener() {
2360
+ }
2361
+ };
2362
+ Te = Mr([
2363
+ U(L.Rendered, Te),
2364
+ Cr(0, j)
2365
+ ], Te);
2366
+ var xr = Object.defineProperty, Or = Object.getOwnPropertyDescriptor, yr = (r, e, t, n) => {
2367
+ for (var s = n > 1 ? void 0 : n ? Or(e, t) : e, i = r.length - 1, o; i >= 0; i--)
2368
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
2369
+ return n && s && xr(e, t, s), s;
2370
+ }, J = (r, e) => (t, n) => e(t, n, r);
2371
+ let Ee = class extends w {
2372
+ constructor(e, t, n, s, i, o) {
2373
+ super();
2374
+ _(this, "_moveInObserver");
2375
+ _(this, "_moveOutObserver");
2376
+ _(this, "_downObserver");
2377
+ _(this, "_dblClickObserver");
2378
+ _(this, "_tripleClickObserver");
2379
+ _(this, "_loadedMap", /* @__PURE__ */ new Set());
2380
+ this._docSkeletonManagerService = e, this._currentUniverService = t, this._commandService = n, this._renderManagerService = s, this._textSelectionRenderManager = i, this._textSelectionManagerService = o, this._renderManagerService.currentRender$.subscribe((a) => {
2381
+ a != null && this._currentUniverService.getUniverDocInstance(a) != null && (this._loadedMap.has(a) || (this._initialMain(a), this._loadedMap.add(a)));
2382
+ }), this._initialize();
2383
+ }
2384
+ dispose() {
2385
+ this._renderManagerService.getRenderAll().forEach((e) => {
2386
+ const { mainComponent: t } = e;
2387
+ t != null && (t.onPointerEnterObserver.remove(this._moveInObserver), t.onPointerLeaveObserver.remove(this._moveOutObserver), t.onPointerDownObserver.remove(this._downObserver), t.onDblclickObserver.remove(this._dblClickObserver), t.onTripleClickObserver.remove(this._tripleClickObserver));
2388
+ });
2389
+ }
2390
+ _initialize() {
2391
+ this._onChangeListener(), this._skeletonListener(), this._userActionSyncListener(), this._commandExecutedListener();
2392
+ }
2393
+ _initialMain(e) {
2394
+ const t = this._getDocObjectById(e);
2395
+ if (t == null)
2396
+ return;
2397
+ const { document: n, scene: s } = t, i = s.getViewport(ue.VIEW_MAIN);
2398
+ this._moveInObserver = n.onPointerEnterObserver.add(() => {
2399
+ n.cursor = gt.TEXT;
2400
+ }), this._moveOutObserver = n.onPointerLeaveObserver.add(() => {
2401
+ n.cursor = gt.DEFAULT, s.resetCursor();
2402
+ }), this._downObserver = n == null ? void 0 : n.onPointerDownObserver.add((o, a) => {
2403
+ this._currentUniverService.getCurrentUniverDocInstance().getUnitId() !== e && this._currentUniverService.setCurrentUniverDocInstance(e), this._textSelectionRenderManager.eventTrigger(o, n.getOffsetConfig(), i), o.button !== 2 && a.stopPropagation();
2404
+ }), this._dblClickObserver = n == null ? void 0 : n.onDblclickObserver.add((o) => {
2405
+ this._textSelectionRenderManager.handleDblClick(o, n.getOffsetConfig(), i);
2406
+ }), this._tripleClickObserver = n == null ? void 0 : n.onTripleClickObserver.add((o) => {
2407
+ this._textSelectionRenderManager.handleTripleClick(o, n.getOffsetConfig(), i);
2408
+ });
2409
+ }
2410
+ _onChangeListener() {
2411
+ this._textSelectionManagerService.textSelectionInfo$.subscribe((e) => {
2412
+ var a, c;
2413
+ const t = (a = this._textSelectionManagerService.getCurrentSelection()) == null ? void 0 : a.unitId;
2414
+ if (this._textSelectionRenderManager.removeAllTextRanges(), e == null || t == null)
2415
+ return;
2416
+ const n = (c = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : c.skeleton, s = this._getDocObjectById(t);
2417
+ if (s == null || n == null)
2418
+ return;
2419
+ const { scene: i, document: o } = s;
2420
+ this._textSelectionRenderManager.addTextRanges(e, {
2421
+ scene: i,
2422
+ skeleton: n,
2423
+ documentOffsetConfig: o.getOffsetConfig()
2424
+ });
2425
+ });
2426
+ }
2427
+ _userActionSyncListener() {
2428
+ this._textSelectionRenderManager.textSelection$.subscribe((e) => {
2429
+ const t = this._docSkeletonManagerService.getCurrent();
2430
+ if (t == null)
2431
+ return;
2432
+ const { unitId: n } = t;
2433
+ this._commandService.executeCommand(Tt.id, {
2434
+ unitId: n,
2435
+ pluginName: Ne,
2436
+ ranges: e
2437
+ });
2438
+ });
2439
+ }
2440
+ _getDocObjectById(e) {
2441
+ return fn(e, this._renderManagerService);
2442
+ }
2443
+ _commandExecutedListener() {
2444
+ const e = [H.id];
2445
+ this.disposeWithMe(
2446
+ this._commandService.onCommandExecuted((t) => {
2447
+ var n;
2448
+ if (e.includes(t.id)) {
2449
+ const s = t.params, { unitId: i } = s, o = (n = this._textSelectionManagerService.getCurrentSelection()) == null ? void 0 : n.unitId;
2450
+ if (i !== o)
2451
+ return;
2452
+ this._textSelectionManagerService.refreshSelection();
2453
+ }
2454
+ })
2455
+ );
2456
+ }
2457
+ _skeletonListener() {
2458
+ this._docSkeletonManagerService.currentSkeleton$.subscribe((e) => {
2459
+ if (e == null)
2460
+ return;
2461
+ const { unitId: t, skeleton: n } = e, s = this._renderManagerService.getRenderById(t);
2462
+ if (s == null)
2463
+ return;
2464
+ const { scene: i, mainComponent: o } = s, a = i.getViewport(ue.VIEW_MAIN);
2465
+ this._textSelectionRenderManager.changeRuntime(
2466
+ n,
2467
+ i,
2468
+ a,
2469
+ o.getOffsetConfig()
2470
+ ), this._textSelectionManagerService.setCurrentSelectionNotRefresh({
2471
+ pluginName: Ne,
2472
+ unitId: t
2473
+ });
2474
+ });
2475
+ }
2476
+ };
2477
+ Ee = yr([
2478
+ U(L.Rendered, Ee),
2479
+ J(0, b(A)),
2480
+ J(1, I),
2481
+ J(2, D),
2482
+ J(3, j),
2483
+ J(4, V),
2484
+ J(5, b(P))
2485
+ ], Ee);
2486
+ var br = Object.defineProperty, Dr = Object.getOwnPropertyDescriptor, Pr = (r, e, t, n) => {
2487
+ for (var s = n > 1 ? void 0 : n ? Dr(e, t) : e, i = r.length - 1, o; i >= 0; i--)
2488
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
2489
+ return n && s && br(e, t, s), s;
2490
+ }, ae = (r, e) => (t, n) => e(t, n, r);
2491
+ let we = class extends w {
2492
+ constructor(e, t, n, s, i) {
2493
+ super();
2494
+ _(this, "_initializedRender", /* @__PURE__ */ new Set());
2495
+ this._docSkeletonManagerService = e, this._currentUniverService = t, this._commandService = n, this._renderManagerService = s, this._textSelectionManagerService = i, this._initialize();
2496
+ }
2497
+ dispose() {
2498
+ super.dispose();
2499
+ }
2500
+ _initialize() {
2501
+ this._skeletonListener(), this._commandExecutedListener(), this._initialRenderRefresh();
2502
+ }
2503
+ _initialRenderRefresh() {
2504
+ this._docSkeletonManagerService.currentSkeleton$.subscribe((e) => {
2505
+ if (e == null)
2506
+ return;
2507
+ const { unitId: t } = e, n = this._renderManagerService.getRenderById(t);
2508
+ if (n == null || this._initializedRender.has(t) || [te, ne].includes(t))
2509
+ return;
2510
+ this._initializedRender.add(t);
2511
+ const { scene: s } = n;
2512
+ this.disposeWithMe(
2513
+ Ke(
2514
+ s.onMouseWheelObserver.add((i) => {
2515
+ if (!i.ctrlKey)
2516
+ return;
2517
+ const o = Math.abs(i.deltaX);
2518
+ let a = o < 40 ? 0.2 : o < 80 ? 0.4 : 0.2;
2519
+ a *= i.deltaY > 0 ? -1 : 1, s.scaleX < 1 && (a /= 2);
2520
+ const c = this._currentUniverService.getCurrentUniverDocInstance(), l = c.zoomRatio;
2521
+ let d = +parseFloat(`${l + a}`).toFixed(1);
2522
+ d = d >= 4 ? 4 : d <= 0.1 ? 0.1 : d, this._commandService.executeCommand(Et.id, {
2523
+ zoomRatio: d,
2524
+ workbookId: c.getUnitId()
2525
+ }), i.preventDefault();
2526
+ })
2527
+ )
2528
+ );
2529
+ });
2530
+ }
2531
+ // private _zoomEventBinding() {
2532
+ // const scene = this._getDocObject()?.scene;
2533
+ // if (scene == null) {
2534
+ // return;
2535
+ // }
2536
+ // const viewportMain = scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);
2537
+ // }
2538
+ _skeletonListener() {
2539
+ this.disposeWithMe(
2540
+ Ke(
2541
+ this._docSkeletonManagerService.currentSkeletonBefore$.subscribe((e) => {
2542
+ if (e == null)
2543
+ return;
2544
+ const n = this._currentUniverService.getCurrentUniverDocInstance().zoomRatio || 1;
2545
+ this._updateViewZoom(n, !1);
2546
+ })
2547
+ )
2548
+ );
2549
+ }
2550
+ _commandExecutedListener() {
2551
+ const e = [H.id];
2552
+ this.disposeWithMe(
2553
+ this._commandService.onCommandExecuted((t) => {
2554
+ if (e.includes(t.id)) {
2555
+ const n = this._currentUniverService.getCurrentUniverDocInstance(), s = t.params, { unitId: i } = s;
2556
+ if (i !== n.getUnitId())
2557
+ return;
2558
+ const o = n.zoomRatio || 1;
2559
+ this._updateViewZoom(o);
2560
+ }
2561
+ })
2562
+ );
2563
+ }
2564
+ _updateViewZoom(e, t = !0) {
2565
+ var s;
2566
+ const n = this._getDocObject();
2567
+ n != null && (n.scene.scale(e, e), this._calculatePagePosition(n, e), t && this._textSelectionManagerService.refreshSelection(), (s = n.scene.getTransformer()) == null || s.hideControl());
2568
+ }
2569
+ _calculatePagePosition(e, t) {
2570
+ const { document: n, scene: s } = e, i = s == null ? void 0 : s.getParent(), { width: o, height: a, pageMarginLeft: c, pageMarginTop: l } = n;
2571
+ if (i == null || o === 1 / 0 || a === 1 / 0)
2572
+ return;
2573
+ const { width: d, height: f } = i;
2574
+ let h = 0, u = 0, g = 0, p = 0, m = 1 / 0;
2575
+ d > (o + c * 2) * t ? (h = d / 2 - o * t / 2, h /= t, g = (d - c * 2) / t, m = 0) : (h = c, g = o + c * 2, m = (g - d / t) / 2), f > a ? (u = f / 2 - a / 2, p = (f - l * 2) / t) : (u = l, p = a + l * 2), s.resize(g, p + 200), n.translate(h, u);
2576
+ const v = s.getViewport(ue.VIEW_MAIN);
2577
+ if (m !== 1 / 0 && v != null) {
2578
+ const M = v.getBarScroll(m, 0).x;
2579
+ v.scrollTo({
2580
+ x: M
2581
+ });
2582
+ }
2583
+ return this;
2584
+ }
2585
+ _getDocObject() {
2586
+ return pe(this._currentUniverService, this._renderManagerService);
2587
+ }
2588
+ };
2589
+ we = Pr([
2590
+ U(L.Rendered, we),
2591
+ ae(0, b(A)),
2592
+ ae(1, I),
2593
+ ae(2, D),
2594
+ ae(3, j),
2595
+ ae(4, b(P))
2596
+ ], we);
2597
+ const Tr = {
2598
+ id: st.id,
2599
+ preconditions: (r) => r.getContextValue(T),
2600
+ binding: N.ENTER
2601
+ }, Er = {
2602
+ id: $e.id,
2603
+ preconditions: (r) => r.getContextValue(T),
2604
+ binding: N.BACKSPACE
2605
+ }, wr = {
2606
+ id: Be.id,
2607
+ preconditions: (r) => r.getContextValue(T),
2608
+ binding: N.DELETE
2609
+ }, Ur = {
2610
+ id: G.id,
2611
+ binding: N.ARROW_UP,
2612
+ preconditions: (r) => r.getContextValue(T),
2613
+ staticParameters: {
2614
+ direction: R.UP
2615
+ }
2616
+ }, Lr = {
2617
+ id: G.id,
2618
+ binding: N.ARROW_DOWN,
2619
+ preconditions: (r) => r.getContextValue(T),
2620
+ staticParameters: {
2621
+ direction: R.DOWN
2622
+ }
2623
+ }, Ar = {
2624
+ id: G.id,
2625
+ binding: N.ARROW_LEFT,
2626
+ preconditions: (r) => r.getContextValue(T),
2627
+ staticParameters: {
2628
+ direction: R.LEFT
2629
+ }
2630
+ }, Nr = {
2631
+ id: G.id,
2632
+ binding: N.ARROW_RIGHT,
2633
+ preconditions: (r) => r.getContextValue(T),
2634
+ staticParameters: {
2635
+ direction: R.RIGHT
2636
+ }
2637
+ }, $r = {
2638
+ id: X.id,
2639
+ binding: N.ARROW_UP | fe.SHIFT,
2640
+ preconditions: (r) => r.getContextValue(T),
2641
+ staticParameters: {
2642
+ direction: R.UP
2643
+ }
2644
+ }, Br = {
2645
+ id: X.id,
2646
+ binding: N.ARROW_DOWN | fe.SHIFT,
2647
+ preconditions: (r) => r.getContextValue(T),
2648
+ staticParameters: {
2649
+ direction: R.DOWN
2650
+ }
2651
+ }, jr = {
2652
+ id: X.id,
2653
+ binding: N.ARROW_LEFT | fe.SHIFT,
2654
+ preconditions: (r) => r.getContextValue(T),
2655
+ staticParameters: {
2656
+ direction: R.LEFT
2657
+ }
2658
+ }, Vr = {
2659
+ id: X.id,
2660
+ binding: N.ARROW_RIGHT | fe.SHIFT,
2661
+ preconditions: (r) => r.getContextValue(T),
2662
+ staticParameters: {
2663
+ direction: R.RIGHT
2664
+ }
2665
+ }, kr = {
2666
+ id: wt.id,
2667
+ binding: N.A | fe.CTRL_COMMAND,
2668
+ preconditions: (r) => r.getContextValue(T) || r.getContextValue(ge)
2669
+ };
2670
+ var Fr = Object.defineProperty, zr = Object.getOwnPropertyDescriptor, Wr = (r, e, t, n) => {
2671
+ for (var s = n > 1 ? void 0 : n ? zr(e, t) : e, i = r.length - 1, o; i >= 0; i--)
2672
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
2673
+ return n && s && Fr(e, t, s), s;
2674
+ }, ve = (r, e) => (t, n) => e(t, n, r);
2675
+ let Ue = class {
2676
+ constructor(r, e, t, n) {
2677
+ _(this, "_scene");
2678
+ _(this, "_currentDocumentModel");
2679
+ _(this, "_loadedMap", /* @__PURE__ */ new Set());
2680
+ this._renderManagerService = r, this._configService = e, this._currentUniverService = t, this._docViewModelManagerService = n, this._initialize();
2681
+ }
2682
+ _initialize() {
2683
+ this._currentUniverService.currentDoc$.subscribe((r) => {
2684
+ if (r == null)
2685
+ return;
2686
+ this._currentDocumentModel = r;
2687
+ const e = r.getUnitId();
2688
+ this._docViewModelManagerService.setCurrent(e), this._loadedMap.has(e) || (this._addNewRender(), this._loadedMap.add(e));
2689
+ });
2690
+ }
2691
+ _addNewRender() {
2692
+ const r = this._currentDocumentModel, e = r.getUnitId(), t = r.getContainer(), n = r.getParentRenderUnitId();
2693
+ if (t != null && n != null)
2694
+ throw new Error("container or parentRenderUnitId can only exist one");
2695
+ t == null && n != null ? this._renderManagerService.createRenderWithParent(e, n) : this._renderManagerService.createRender(e);
2696
+ const s = this._renderManagerService.getRenderById(e);
2697
+ if (s == null)
2698
+ return;
2699
+ const { scene: i, engine: o } = s;
2700
+ i.openTransformer(), this._scene = i;
2701
+ const a = new an(ue.VIEW_MAIN, i, {
2702
+ left: 0,
2703
+ top: 0,
2704
+ bottom: 0,
2705
+ right: 0,
2706
+ isWheelPreventDefaultX: !0
2707
+ });
2708
+ i.addViewport(a).attachControl(), i.on(cn.wheel, (d, f) => {
2709
+ const h = d;
2710
+ if (h.ctrlKey) {
2711
+ const u = Math.abs(h.deltaX);
2712
+ let g = u < 40 ? 0.2 : u < 80 ? 0.4 : 0.2;
2713
+ g *= h.deltaY > 0 ? -1 : 1, i.scaleX < 1 && (g /= 2), i.scaleX + g > 4 ? i.scale(4, 4) : i.scaleX + g < 0.1 ? i.scale(0.1, 0.1) : h.preventDefault();
2714
+ } else
2715
+ a.onMouseWheel(h, f);
2716
+ }), this._configService.getConfig("hasScroll") !== !1 && e !== ne && new ln(a), i.addLayer(
2717
+ ft.create(i, [], mt),
2718
+ ft.create(i, [], pn)
2719
+ ), this._addComponent(s), this._currentDocumentModel.getShouldRenderLoopImmediately() && o.runRenderLoop(() => {
2720
+ i.render();
2721
+ }), this._renderManagerService.setCurrent(e);
2722
+ }
2723
+ _addComponent(r) {
2724
+ const e = this._scene, t = this._currentDocumentModel, n = new dn(Qe.MAIN, void 0, {
2725
+ pageMarginLeft: t.documentStyle.marginLeft || 0,
2726
+ pageMarginTop: t.documentStyle.marginTop || 0
2727
+ });
2728
+ n.zIndex = mn, r.mainComponent = n, r.components.set(Qe.MAIN, n), e.addObjects([n], mt);
2729
+ }
2730
+ };
2731
+ Ue = Wr([
2732
+ U(L.Ready, Ue),
2733
+ ve(0, j),
2734
+ ve(1, Ot),
2735
+ ve(2, I),
2736
+ ve(3, b(ee))
2737
+ ], Ue);
2738
+ var Hr = Object.defineProperty, Gr = Object.getOwnPropertyDescriptor, Xr = (r, e, t, n) => {
2739
+ for (var s = n > 1 ? void 0 : n ? Gr(e, t) : e, i = r.length - 1, o; i >= 0; i--)
2740
+ (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
2741
+ return n && s && Hr(e, t, s), s;
2742
+ }, Me = (r, e) => (t, n) => e(t, n, r);
2743
+ const qr = {
2744
+ hasScroll: !0
2745
+ }, Yr = "docs";
2746
+ var Ze;
2747
+ let It = (Ze = class extends zt {
2748
+ constructor(e = {}, t, n, s, i) {
2749
+ super(Yr);
2750
+ _(this, "_config");
2751
+ this._injector = t, this._localeService = n, this._configService = s, this._currentUniverService = i, this._config = Object.assign(qr, e), this._initializeDependencies(t), this._initializeCommands();
2752
+ }
2753
+ initialize() {
2754
+ }
2755
+ _initializeCommands() {
2756
+ [
2757
+ G,
2758
+ X,
2759
+ $e,
2760
+ Be,
2761
+ ce,
2762
+ je,
2763
+ Ve,
2764
+ ke,
2765
+ le,
2766
+ de,
2767
+ Fe,
2768
+ Dt,
2769
+ st,
2770
+ it,
2771
+ tt,
2772
+ yt,
2773
+ bt,
2774
+ S,
2775
+ In,
2776
+ xn,
2777
+ Et,
2778
+ H,
2779
+ Tt,
2780
+ wt
2781
+ ].forEach((e) => {
2782
+ this._injector.get(D).registerCommand(e);
2783
+ }), [
2784
+ Ur,
2785
+ Lr,
2786
+ Nr,
2787
+ Ar,
2788
+ $r,
2789
+ Br,
2790
+ jr,
2791
+ Vr,
2792
+ kr,
2793
+ Er,
2794
+ wr,
2795
+ Tr
2796
+ ].forEach((e) => {
2797
+ this._injector.get(Kt).registerShortcut(e);
2798
+ });
2799
+ }
2800
+ onReady() {
2801
+ this.initialize();
2802
+ }
2803
+ _initializeDependencies(e) {
2804
+ [
2805
+ // [
2806
+ // CanvasView,
2807
+ // { useFactory: () => docInjector.createInstance(CanvasView, this._config.standalone ?? true) },
2808
+ // ], // FIXME: CanvasView shouldn't be a dependency of UniverDocs. Because it maybe created dynamically.
2809
+ //views
2810
+ [Ue],
2811
+ // services
2812
+ [A],
2813
+ [ee],
2814
+ [ot],
2815
+ [
2816
+ Ut,
2817
+ {
2818
+ useClass: rt
2819
+ }
2820
+ ],
2821
+ [
2822
+ V,
2823
+ {
2824
+ useClass: un
2825
+ }
2826
+ ],
2827
+ [P],
2828
+ // controllers
2829
+ [Ie],
2830
+ [Te],
2831
+ [Ee],
2832
+ [Pe],
2833
+ [Oe],
2834
+ [Re],
2835
+ [ye],
2836
+ [Ce],
2837
+ [be],
2838
+ [De],
2839
+ [we],
2840
+ [xe]
2841
+ ].forEach((t) => e.add(t));
2842
+ }
2843
+ }, _(Ze, "type", Wt.Doc), Ze);
2844
+ It = Xr([
2845
+ Me(1, b(gn)),
2846
+ Me(2, b(xt)),
2847
+ Me(3, Ot),
2848
+ Me(4, I)
2849
+ ], It);
2850
+ export {
2851
+ st as BreakLineCommand,
2852
+ xn as CoverContentCommand,
2853
+ mn as DOCS_COMPONENT_DEFAULT_Z_INDEX,
2854
+ pn as DOCS_COMPONENT_HEADER_LAYER_INDEX,
2855
+ mt as DOCS_COMPONENT_MAIN_LAYER_INDEX,
2856
+ Qe as DOCS_VIEW_KEY,
2857
+ tt as DeleteCommand,
2858
+ $e as DeleteLeftCommand,
2859
+ Ge as DocCopyCommand,
2860
+ Xe as DocCutCommand,
2861
+ qe as DocPasteCommand,
2862
+ A as DocSkeletonManagerService,
2863
+ ee as DocViewModelManagerService,
2864
+ bt as IMEInputCommand,
2865
+ it as InsertCommand,
2866
+ G as MoveCursorOperation,
2867
+ X as MoveSelectionOperation,
2868
+ Ne as NORMAL_TEXT_SELECTION_PLUGIN_NAME,
2869
+ In as ReplaceContentCommand,
2870
+ S as RichTextEditingMutation,
2871
+ ce as SetInlineFormatBoldCommand,
2872
+ Dt as SetInlineFormatCommand,
2873
+ de as SetInlineFormatFontFamilyCommand,
2874
+ le as SetInlineFormatFontSizeCommand,
2875
+ je as SetInlineFormatItalicCommand,
2876
+ ke as SetInlineFormatStrikethroughCommand,
2877
+ Fe as SetInlineFormatTextColorCommand,
2878
+ Ve as SetInlineFormatUnderlineCommand,
2879
+ Tt as SetTextSelectionsOperation,
2880
+ P as TextSelectionManagerService,
2881
+ It as UniverDocsPlugin,
2882
+ yt as UpdateCommand,
2883
+ ue as VIEWPORT_KEY,
2884
+ pe as getDocObject
2885
+ };