@univerjs/docs 0.1.0-beta.3 → 0.1.0-beta.4

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