@univerjs/docs-drawing-ui 0.2.2 → 0.2.4-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/README.md +16 -5
  2. package/lib/cjs/index.js +1 -1
  3. package/lib/es/index.js +2081 -607
  4. package/lib/index.css +1 -1
  5. package/lib/locale/en-US.json +35 -0
  6. package/lib/locale/ru-RU.json +35 -0
  7. package/lib/locale/vi-VN.json +59 -0
  8. package/lib/locale/zh-CN.json +35 -0
  9. package/lib/locale/zh-TW.json +59 -0
  10. package/lib/types/commands/commands/insert-doc-drawing.command.d.ts +1 -1
  11. package/lib/types/commands/commands/set-drawing-arrange.command.d.ts +1 -1
  12. package/lib/types/commands/commands/update-doc-drawing.command.d.ts +56 -0
  13. package/lib/types/controllers/doc-drawing-notification.controller.d.ts +18 -0
  14. package/lib/types/controllers/doc-drawing-transformer-update.controller.d.ts +32 -0
  15. package/lib/types/controllers/doc-drawing.controller.d.ts +1 -2
  16. package/lib/types/controllers/render-controllers/doc-drawing-transform-update.controller.d.ts +20 -0
  17. package/lib/types/controllers/render-controllers/doc-drawing-update.render-controller.d.ts +9 -6
  18. package/lib/types/index.d.ts +1 -1
  19. package/lib/types/locale/vi-VN.d.ts +4 -0
  20. package/lib/types/locale/zh-CN.d.ts +35 -0
  21. package/lib/types/locale/zh-TW.d.ts +4 -0
  22. package/lib/types/plugin.d.ts +1 -2
  23. package/lib/types/views/doc-image-panel/DocDrawingPosition.d.ts +7 -0
  24. package/lib/types/views/doc-image-panel/DocDrawingTextWrap.d.ts +7 -0
  25. package/lib/types/views/menu/image.menu.d.ts +1 -1
  26. package/lib/umd/index.js +1 -1
  27. package/package.json +23 -25
  28. /package/lib/types/commands/commands/{delete-drawings.command.d.ts → delete-doc-drawing.command.d.ts} +0 -0
package/lib/es/index.js CHANGED
@@ -1,898 +1,2372 @@
1
- var Ge = Object.defineProperty;
2
- var Le = (e, n, t) => n in e ? Ge(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
3
- var J = (e, n, t) => Le(e, typeof n != "symbol" ? n + "" : n, t);
4
- import { CommandType as S, ICommandService as I, IUndoRedoService as U, LocaleService as k, RxDisposable as je, UniverInstanceType as E, toDisposable as We, FOCUSING_COMMON_DRAWINGS as V, OnLifecycle as se, LifecycleStages as ce, IUniverInstanceService as Fe, IContextService as de, Direction as P, FOCUSING_UNIVER_EDITOR as $e, Disposable as ue, PositionedObjectLayoutType as Ve, ObjectRelativeFromH as Be, ObjectRelativeFromV as He, Plugin as ze, DependentOn as Ke } from "@univerjs/core";
5
- import { Inject as y, Injector as me } from "@wendellhu/redi";
6
- import { ImageCropperObject as Ze, COMPONENT_IMAGE_POPUP_MENU as Ye, OpenImageCropOperation as ke, ImageResetSizeOperation as Qe, DrawingCommonPanel as Xe, UniverDrawingUIPlugin as qe } from "@univerjs/drawing-ui";
7
- import { IDrawingManagerService as N, DRAWING_IMAGE_ALLOW_IMAGE_LIST as Je, ArrangeTypeEnum as L, DrawingTypeEnum as Q, DRAWING_IMAGE_COUNT_LIMIT as ee, ImageUploadStatusType as K, DRAWING_IMAGE_ALLOW_SIZE as en, getImageSize as nn, DRAWING_IMAGE_WIDTH_LIMIT as ne, DRAWING_IMAGE_HEIGHT_LIMIT as te, IImageIoService as tn, UniverDrawingPlugin as rn } from "@univerjs/drawing";
8
- import { IDocDrawingService as M, SetDocDrawingApplyMutation as p, DocDrawingApplyType as f, UniverDocsDrawingPlugin as on } from "@univerjs/docs-drawing";
9
- import { IRenderManagerService as H, getGroupState as an, transformObjectOutOfGroup as sn } from "@univerjs/engine-render";
10
- import { takeUntil as re } from "rxjs";
11
- import { DocCanvasPopManagerService as cn, transformToDocDrawingPosition as le, docDrawingPositionToTransform as ie } from "@univerjs/docs-ui";
12
- import { ISidebarService as dn, MenuItemType as ge, MenuPosition as un, MenuGroup as mn, getMenuHiddenObservable as pe, KeyCode as R, ComponentManager as ln, IMenuService as gn, IShortcutService as pn, IMessageService as fn } from "@univerjs/ui";
13
- import { useDependency as b } from "@wendellhu/redi/react-bindings";
14
- import C, { forwardRef as fe, useRef as he, createElement as ve, useState as Z, useEffect as Ie } from "react";
15
- import j from "clsx";
16
- import { MessageType as W } from "@univerjs/design";
17
- import { TextSelectionManagerService as hn, DocSkeletonManagerService as vn } from "@univerjs/docs";
18
- const w = {
19
- id: "sheet.operation.clear-drawing-transformer",
20
- type: S.MUTATION,
21
- handler: (e, n) => {
22
- const t = e.get(H);
23
- return n.forEach((r) => {
24
- var i, o;
25
- (o = (i = t.getRenderById(r)) == null ? void 0 : i.scene.getTransformer()) == null || o.debounceRefreshControls();
26
- }), !0;
27
- }
28
- }, X = {
1
+ var dt = Object.defineProperty;
2
+ var mt = (i, e, n) => e in i ? dt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n;
3
+ var Pe = (i, e, n) => mt(i, typeof e != "symbol" ? e + "" : e, n);
4
+ import { CommandType as $, ICommandService as W, IUniverInstanceService as X, TextX as Je, JSONX as k, MemoryCursor as ut, TextXActionType as j, LocaleService as en, RxDisposable as gt, UniverInstanceType as Ce, toDisposable as Ee, FOCUSING_COMMON_DRAWINGS as Ze, OnLifecycle as nn, LifecycleStages as tn, Inject as Se, IContextService as xn, useDependency as ie, PositionedObjectLayoutType as B, BooleanNumber as Me, ObjectRelativeFromH as Y, ObjectRelativeFromV as G, Tools as _e, WrapTextType as Ae, Direction as ae, IUndoRedoService as mn, FOCUSING_UNIVER_EDITOR as pt, Disposable as Ue, Injector as Un, UndoCommand as ft, RedoCommand as ht, throttle as In, COLORS as wt, Plugin as vt, DependentOn as It } from "@univerjs/core";
5
+ import { ImageCropperObject as _t, COMPONENT_IMAGE_POPUP_MENU as Ct, OpenImageCropOperation as St, ImageResetSizeOperation as Dt, DrawingCommonPanel as Pt, UniverDrawingUIPlugin as Et } from "@univerjs/drawing-ui";
6
+ import { IDrawingManagerService as ge, DRAWING_IMAGE_ALLOW_IMAGE_LIST as Ot, ArrangeTypeEnum as He, DrawingTypeEnum as un, DRAWING_IMAGE_COUNT_LIMIT as _n, ImageUploadStatusType as an, DRAWING_IMAGE_ALLOW_SIZE as Tt, getImageSize as Mt, DRAWING_IMAGE_WIDTH_LIMIT as Cn, DRAWING_IMAGE_HEIGHT_LIMIT as Sn, IImageIoService as yt, UniverDrawingPlugin as bt } from "@univerjs/drawing";
7
+ import { IDocDrawingService as De, SetDocDrawingApplyMutation as fe, DocDrawingApplyType as he, UniverDocsDrawingPlugin as Rt } from "@univerjs/docs-drawing";
8
+ import { ITextSelectionRenderManager as Le, IRenderManagerService as Q, DocumentEditArea as sn, getGroupState as Nt, transformObjectOutOfGroup as At, Liquid as Ln, PageLayoutType as Dn, NodePositionConvertToCursor as Pn, getOneTextSelectionRange as En, Vector2 as xt, getAnchorBounding as Ut, Rect as Lt, getColor as Ft, TEXT_RANGE_LAYER_INDEX as Bt } from "@univerjs/engine-render";
9
+ import { takeUntil as On, combineLatest as Gt, Observable as Wt } from "rxjs";
10
+ import { DocCanvasPopManagerService as Ht, docDrawingPositionToTransform as Tn, transformToDocDrawingPosition as Vt } from "@univerjs/docs-ui";
11
+ import { RichTextEditingMutation as Z, getRichTextEditPath as on, DocSkeletonManagerService as me, TextSelectionManagerService as cn, getRetainAndDeleteFromReplace as jt, SetDocZoomRatioOperation as kt, getDocObject as $t } from "@univerjs/docs";
12
+ import { ISidebarService as zt, MenuItemType as Fn, MenuPosition as Xt, MenuGroup as qt, getMenuHiddenObservable as Bn, KeyCode as ye, ComponentManager as Kt, IMenuService as Yt, IShortcutService as Zt, IMessageService as Qt, IEditorService as Jt } from "@univerjs/ui";
13
+ import d, { forwardRef as Gn, useRef as Wn, createElement as Hn, useState as te, useEffect as gn } from "react";
14
+ import H from "clsx";
15
+ import { RadioGroup as Mn, Radio as Ie, InputNumber as Te, Select as yn, Checkbox as ei, MessageType as Ve } from "@univerjs/design";
16
+ const pn = {
29
17
  id: "doc.command.remove-doc-image",
30
- type: S.COMMAND,
31
- handler: (e, n) => {
32
- const t = e.get(I), r = e.get(U), i = e.get(M);
33
- if (!n) return !1;
34
- const { drawings: o } = n, a = [];
35
- o.forEach((h) => {
36
- const { unitId: v } = h;
37
- a.push(v);
38
- });
39
- const s = i.getBatchRemoveOp(o), { unitId: c, subUnitId: u, undo: m, redo: d, objects: l } = s;
40
- return t.syncExecuteCommand(p.id, { unitId: c, subUnitId: u, op: d, objects: l, type: f.REMOVE }) ? (r.pushUndoRedo({
41
- unitID: c,
42
- undoMutations: [
43
- { id: p.id, params: { unitId: c, subUnitId: u, op: m, objects: l, type: f.INSERT } },
44
- { id: w.id, params: a }
45
- ],
46
- redoMutations: [
47
- { id: p.id, params: { unitId: c, subUnitId: u, op: d, objects: l, type: f.REMOVE } },
48
- { id: w.id, params: a }
49
- ]
50
- }), !0) : !1;
18
+ type: $.COMMAND,
19
+ // eslint-disable-next-line max-lines-per-function
20
+ handler: (i, e) => {
21
+ var S, O, R, D;
22
+ const n = i.get(W), t = i.get(X), o = i.get(Le), r = t.getCurrentUniverDocInstance();
23
+ if (e == null || r == null)
24
+ return !1;
25
+ const { drawings: a } = e, s = (S = o.getSegment()) != null ? S : "", l = new Je(), c = k.getInstance(), m = (R = (O = r.getSelfOrHeaderFooterModel(s).getBody()) == null ? void 0 : O.customBlocks) != null ? R : [], u = a.map((b) => m.find((y) => y.blockId === b.drawingId)).filter((b) => !!b).sort((b, y) => b.startIndex > y.startIndex ? 1 : -1), p = a[0].unitId, f = new ut();
26
+ f.reset();
27
+ const g = u[0].startIndex, w = [
28
+ {
29
+ startOffset: g,
30
+ endOffset: g
31
+ }
32
+ ], v = {
33
+ id: Z.id,
34
+ params: {
35
+ unitId: p,
36
+ actions: [],
37
+ textRanges: w
38
+ }
39
+ }, I = [];
40
+ for (const b of u) {
41
+ const { startIndex: y } = b;
42
+ y > f.cursor && l.push({
43
+ t: j.RETAIN,
44
+ len: y - f.cursor,
45
+ segmentId: ""
46
+ }), l.push({
47
+ t: j.DELETE,
48
+ len: 1,
49
+ line: 0,
50
+ segmentId: ""
51
+ }), f.moveCursorTo(y + 1);
52
+ }
53
+ const C = on(r, s);
54
+ I.push(c.editOp(l.serialize(), C));
55
+ for (const b of u) {
56
+ const { blockId: y } = b, T = ((D = r.getDrawings()) != null ? D : {})[y], x = r.getDrawingsOrder().indexOf(y), L = c.removeOp(["drawings", y], T), z = c.removeOp(["drawingsOrder", x], y);
57
+ I.push(L), I.push(z);
58
+ }
59
+ return v.params.actions = I.reduce((b, y) => k.compose(b, y), null), !!n.syncExecuteCommand(v.id, v.params);
51
60
  }
52
- }, _e = "COMPONENT_DOC_DRAWING_PANEL", we = {
61
+ }, Vn = "COMPONENT_DOC_DRAWING_PANEL", jn = {
53
62
  id: "sidebar.operation.doc-image",
54
- type: S.COMMAND,
55
- handler: async (e, n) => {
56
- const t = e.get(dn), r = e.get(k), i = e.get(N);
57
- switch (n.value) {
63
+ type: $.COMMAND,
64
+ handler: async (i, e) => {
65
+ const n = i.get(zt), t = i.get(en), o = i.get(ge);
66
+ switch (e.value) {
58
67
  case "open":
59
- t.open({
60
- header: { title: r.t("docImage.panel.title") },
61
- children: { label: _e },
68
+ n.open({
69
+ header: { title: t.t("docImage.panel.title") },
70
+ children: { label: Vn },
62
71
  onClose: () => {
63
- i.focusDrawing(null);
72
+ o.focusDrawing(null);
64
73
  },
65
74
  width: 360
66
75
  });
67
76
  break;
68
77
  case "close":
69
78
  default:
70
- t.close();
79
+ n.close();
71
80
  break;
72
81
  }
73
82
  return !0;
74
83
  }
75
- }, Se = {
76
- id: "sheet.operation.edit-sheet-image",
77
- type: S.OPERATION,
78
- handler: (e, n) => {
79
- const t = e.get(N), r = e.get(I);
80
- return n == null ? !1 : (t.focusDrawing([n]), r.executeCommand(we.id, { value: "open" }), !0);
84
+ }, kn = {
85
+ id: "doc.operation.edit-doc-image",
86
+ type: $.OPERATION,
87
+ handler: (i, e) => {
88
+ const n = i.get(ge), t = i.get(W);
89
+ return e == null ? !1 : (n.focusDrawing([e]), t.executeCommand(jn.id, { value: "open" }), !0);
81
90
  }
82
91
  };
83
- var In = Object.defineProperty, _n = Object.getOwnPropertyDescriptor, wn = (e, n, t, r) => {
84
- for (var i = r > 1 ? void 0 : r ? _n(n, t) : n, o = e.length - 1, a; o >= 0; o--)
85
- (a = e[o]) && (i = (r ? a(n, t, i) : a(i)) || i);
86
- return r && i && In(n, t, i), i;
87
- }, A = (e, n) => (t, r) => n(t, r, e);
88
- let F = class extends je {
89
- constructor(n, t, r, i, o) {
92
+ var ni = Object.defineProperty, ti = Object.getOwnPropertyDescriptor, ii = (i, e, n, t) => {
93
+ for (var o = t > 1 ? void 0 : t ? ti(e, n) : e, r = i.length - 1, a; r >= 0; r--)
94
+ (a = i[r]) && (o = (t ? a(e, n, o) : a(o)) || o);
95
+ return t && o && ni(e, n, o), o;
96
+ }, be = (i, e) => (n, t) => e(n, t, i);
97
+ let Xe = class extends gt {
98
+ constructor(e, n, t, o, r) {
90
99
  super();
91
- J(this, "_initImagePopupMenu", /* @__PURE__ */ new Set());
92
- this._drawingManagerService = n, this._canvasPopManagerService = t, this._renderManagerService = r, this._univerInstanceService = i, this._contextService = o, this._init();
100
+ Pe(this, "_initImagePopupMenu", /* @__PURE__ */ new Set());
101
+ this._drawingManagerService = e, this._canvasPopManagerService = n, this._renderManagerService = t, this._univerInstanceService = o, this._contextService = r, this._init();
93
102
  }
94
103
  _init() {
95
- this._univerInstanceService.getCurrentTypeOfUnit$(E.UNIVER_DOC).pipe(re(this.dispose$)).subscribe((n) => this._create(n)), this._univerInstanceService.getTypeOfUnitDisposed$(E.UNIVER_DOC).pipe(re(this.dispose$)).subscribe((n) => this._dispose(n)), this._univerInstanceService.getAllUnitsForType(E.UNIVER_DOC).forEach((n) => this._create(n));
104
+ this._univerInstanceService.getCurrentTypeOfUnit$(Ce.UNIVER_DOC).pipe(On(this.dispose$)).subscribe((e) => this._create(e)), this._univerInstanceService.getTypeOfUnitDisposed$(Ce.UNIVER_DOC).pipe(On(this.dispose$)).subscribe((e) => this._dispose(e)), this._univerInstanceService.getAllUnitsForType(Ce.UNIVER_DOC).forEach((e) => this._create(e));
96
105
  }
97
- _dispose(n) {
98
- const t = n.getUnitId();
99
- this._renderManagerService.removeRender(t);
106
+ _dispose(e) {
107
+ const n = e.getUnitId();
108
+ this._renderManagerService.removeRender(n);
100
109
  }
101
- _create(n) {
102
- if (!n)
110
+ _create(e) {
111
+ if (!e)
103
112
  return;
104
- const t = n.getUnitId();
105
- this._renderManagerService.has(t) && !this._initImagePopupMenu.has(t) && (this._popupMenuListener(t), this._initImagePopupMenu.add(t));
113
+ const n = e.getUnitId();
114
+ this._renderManagerService.has(n) && !this._initImagePopupMenu.has(n) && (this._popupMenuListener(n), this._initImagePopupMenu.add(n));
106
115
  }
107
- _hasCropObject(n) {
108
- const t = n.getAllObjects();
109
- for (const r of t)
110
- if (r instanceof Ze)
116
+ _hasCropObject(e) {
117
+ const n = e.getAllObjects();
118
+ for (const t of n)
119
+ if (t instanceof _t)
111
120
  return !0;
112
121
  return !1;
113
122
  }
114
- _popupMenuListener(n) {
115
- var o;
116
- const t = (o = this._renderManagerService.getRenderById(n)) == null ? void 0 : o.scene;
117
- if (!t)
123
+ // eslint-disable-next-line max-lines-per-function
124
+ _popupMenuListener(e) {
125
+ var r;
126
+ const n = (r = this._renderManagerService.getRenderById(e)) == null ? void 0 : r.scene;
127
+ if (!n)
118
128
  return;
119
- const r = t.getTransformerByCreate();
120
- if (!r)
129
+ const t = n.getTransformerByCreate();
130
+ if (!t)
121
131
  return;
122
- const i = [];
132
+ const o = [];
123
133
  this.disposeWithMe(
124
- We(
125
- r.createControl$.subscribe(() => {
126
- if (this._hasCropObject(t))
134
+ Ee(
135
+ t.createControl$.subscribe(() => {
136
+ if (this._hasCropObject(n))
127
137
  return;
128
- const a = r.getSelectedObjectMap();
129
- if (a.size > 1) {
130
- i.forEach((g) => g.dispose());
138
+ const a = t.getSelectedObjectMap();
139
+ if (o.forEach((w) => w.dispose()), o.length = 0, a.size > 1)
131
140
  return;
132
- }
133
141
  const s = a.values().next().value;
134
142
  if (!s)
135
143
  return;
136
- const c = s.oKey, u = this._drawingManagerService.getDrawingOKey(c);
137
- if (!u)
144
+ const l = s.oKey, c = this._drawingManagerService.getDrawingOKey(l);
145
+ if (!c)
138
146
  return;
139
- const { unitId: m, subUnitId: d, drawingId: l } = u;
140
- i.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s, {
141
- componentKey: Ye,
147
+ const { unitId: m, subUnitId: u, drawingId: p } = c;
148
+ o.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s, {
149
+ componentKey: Ct,
142
150
  direction: "horizontal",
143
151
  offset: [2, 0],
144
152
  extraProps: {
145
- menuItems: this._getImageMenuItems(m, d, l)
153
+ menuItems: this._getImageMenuItems(m, u, p)
146
154
  }
147
- }))), this._drawingManagerService.focusDrawing([{
155
+ }))), !this._drawingManagerService.getFocusDrawings().find((w) => w.unitId === m && w.subUnitId === u && w.drawingId === p) && this._drawingManagerService.focusDrawing([{
148
156
  unitId: m,
149
- subUnitId: d,
150
- drawingId: l
157
+ subUnitId: u,
158
+ drawingId: p
151
159
  }]);
152
160
  })
153
161
  )
154
162
  ), this.disposeWithMe(
155
- r.clearControl$.subscribe(() => {
156
- i.forEach((a) => a.dispose()), this._contextService.setContextValue(V, !1), this._drawingManagerService.focusDrawing(null);
157
- })
163
+ Ee(
164
+ t.clearControl$.subscribe(() => {
165
+ o.forEach((a) => a.dispose()), o.length = 0, this._contextService.setContextValue(Ze, !1), this._drawingManagerService.focusDrawing(null);
166
+ })
167
+ )
158
168
  ), this.disposeWithMe(
159
- r.changing$.subscribe(() => {
160
- i.forEach((a) => a.dispose());
161
- })
169
+ Ee(
170
+ t.changing$.subscribe(() => {
171
+ o.forEach((a) => a.dispose()), o.length = 0;
172
+ })
173
+ )
174
+ ), this.disposeWithMe(
175
+ Ee(
176
+ t.changeStart$.subscribe(() => {
177
+ o.forEach((a) => a.dispose()), o.length = 0;
178
+ })
179
+ )
162
180
  );
163
181
  }
164
- _getImageMenuItems(n, t, r) {
182
+ _getImageMenuItems(e, n, t) {
165
183
  return [
166
184
  {
167
185
  label: "image-popup.edit",
168
186
  index: 0,
169
- commandId: Se.id,
170
- commandParams: { unitId: n, subUnitId: t, drawingId: r },
187
+ commandId: kn.id,
188
+ commandParams: { unitId: e, subUnitId: n, drawingId: t },
171
189
  disable: !1
172
190
  },
173
191
  {
174
192
  label: "image-popup.delete",
175
193
  index: 1,
176
- commandId: X.id,
177
- commandParams: { unitId: n, drawings: [{ unitId: n, subUnitId: t, drawingId: r }] },
194
+ commandId: pn.id,
195
+ commandParams: { unitId: e, drawings: [{ unitId: e, subUnitId: n, drawingId: t }] },
178
196
  disable: !1
179
197
  },
180
198
  {
181
199
  label: "image-popup.crop",
182
200
  index: 2,
183
- commandId: ke.id,
184
- commandParams: { unitId: n, subUnitId: t, drawingId: r },
185
- disable: !1
201
+ commandId: St.id,
202
+ commandParams: { unitId: e, subUnitId: n, drawingId: t },
203
+ disable: !0
204
+ // TODO: @JOCS, feature is not ready.
186
205
  },
187
206
  {
188
207
  label: "image-popup.reset",
189
208
  index: 3,
190
- commandId: Qe.id,
191
- commandParams: [{ unitId: n, subUnitId: t, drawingId: r }],
192
- disable: !1
209
+ commandId: Dt.id,
210
+ commandParams: [{ unitId: e, subUnitId: n, drawingId: t }],
211
+ disable: !0
212
+ // TODO: @JOCS, feature is not ready.
193
213
  }
194
214
  ];
195
215
  }
196
216
  };
197
- F = wn([
198
- se(ce.Rendered, F),
199
- A(0, N),
200
- A(1, y(cn)),
201
- A(2, H),
202
- A(3, Fe),
203
- A(4, de)
204
- ], F);
205
- var _ = function() {
206
- return _ = Object.assign || function(e) {
207
- for (var n, t = 1, r = arguments.length; t < r; t++) {
208
- n = arguments[t];
209
- for (var i in n) Object.prototype.hasOwnProperty.call(n, i) && (e[i] = n[i]);
210
- }
211
- return e;
212
- }, _.apply(this, arguments);
213
- }, Sn = function(e, n) {
214
- var t = {};
215
- for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && n.indexOf(r) < 0 && (t[r] = e[r]);
216
- if (e != null && typeof Object.getOwnPropertySymbols == "function")
217
- for (var i = 0, r = Object.getOwnPropertySymbols(e); i < r.length; i++)
218
- n.indexOf(r[i]) < 0 && Object.prototype.propertyIsEnumerable.call(e, r[i]) && (t[r[i]] = e[r[i]]);
219
- return t;
220
- }, Ce = fe(function(e, n) {
221
- var t = e.icon, r = e.id, i = e.className, o = e.extend, a = Sn(e, ["icon", "id", "className", "extend"]), s = "univerjs-icon univerjs-icon-".concat(r, " ").concat(i || "").trim(), c = he("_".concat(Mn()));
222
- return De(t, "".concat(r), { defIds: t.defIds, idSuffix: c.current }, _({ ref: n, className: s }, a), o);
217
+ Xe = ii([
218
+ nn(tn.Rendered, Xe),
219
+ be(0, ge),
220
+ be(1, Se(Ht)),
221
+ be(2, Q),
222
+ be(3, X),
223
+ be(4, xn)
224
+ ], Xe);
225
+ var se = function() {
226
+ return se = Object.assign || function(i) {
227
+ for (var e, n = 1, t = arguments.length; n < t; n++) {
228
+ e = arguments[n];
229
+ for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (i[o] = e[o]);
230
+ }
231
+ return i;
232
+ }, se.apply(this, arguments);
233
+ }, oi = function(i, e) {
234
+ var n = {};
235
+ for (var t in i) Object.prototype.hasOwnProperty.call(i, t) && e.indexOf(t) < 0 && (n[t] = i[t]);
236
+ if (i != null && typeof Object.getOwnPropertySymbols == "function")
237
+ for (var o = 0, t = Object.getOwnPropertySymbols(i); o < t.length; o++)
238
+ e.indexOf(t[o]) < 0 && Object.prototype.propertyIsEnumerable.call(i, t[o]) && (n[t[o]] = i[t[o]]);
239
+ return n;
240
+ }, $n = Gn(function(i, e) {
241
+ var n = i.icon, t = i.id, o = i.className, r = i.extend, a = oi(i, ["icon", "id", "className", "extend"]), s = "univerjs-icon univerjs-icon-".concat(t, " ").concat(o || "").trim(), l = Wn("_".concat(si()));
242
+ return zn(n, "".concat(t), { defIds: n.defIds, idSuffix: l.current }, se({ ref: e, className: s }, a), r);
223
243
  });
224
- function De(e, n, t, r, i) {
225
- return ve(e.tag, _(_({ key: n }, Cn(e, t, i)), r), (Dn(e, t).children || []).map(function(o, a) {
226
- return De(o, "".concat(n, "-").concat(e.tag, "-").concat(a), t, void 0, i);
244
+ function zn(i, e, n, t, o) {
245
+ return Hn(i.tag, se(se({ key: e }, ri(i, n, o)), t), (ai(i, n).children || []).map(function(r, a) {
246
+ return zn(r, "".concat(e, "-").concat(i.tag, "-").concat(a), n, void 0, o);
227
247
  }));
228
248
  }
229
- function Cn(e, n, t) {
230
- var r = _({}, e.attrs);
231
- t != null && t.colorChannel1 && r.fill === "colorChannel1" && (r.fill = t.colorChannel1);
232
- var i = n.defIds;
233
- return !i || i.length === 0 || (e.tag === "use" && r["xlink:href"] && (r["xlink:href"] = r["xlink:href"] + n.idSuffix), Object.entries(r).forEach(function(o) {
234
- var a = o[0], s = o[1];
235
- typeof s == "string" && (r[a] = s.replace(/url\(#(.*)\)/, "url(#$1".concat(n.idSuffix, ")")));
236
- })), r;
249
+ function ri(i, e, n) {
250
+ var t = se({}, i.attrs);
251
+ n != null && n.colorChannel1 && t.fill === "colorChannel1" && (t.fill = n.colorChannel1);
252
+ var o = e.defIds;
253
+ return !o || o.length === 0 || (i.tag === "use" && t["xlink:href"] && (t["xlink:href"] = t["xlink:href"] + e.idSuffix), Object.entries(t).forEach(function(r) {
254
+ var a = r[0], s = r[1];
255
+ typeof s == "string" && (t[a] = s.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
256
+ })), t;
237
257
  }
238
- function Dn(e, n) {
239
- var t, r = n.defIds;
240
- return !r || r.length === 0 ? e : e.tag === "defs" && (!((t = e.children) === null || t === void 0) && t.length) ? _(_({}, e), { children: e.children.map(function(i) {
241
- return typeof i.attrs.id == "string" && r && r.indexOf(i.attrs.id) > -1 ? _(_({}, i), { attrs: _(_({}, i.attrs), { id: i.attrs.id + n.idSuffix }) }) : i;
242
- }) }) : e;
258
+ function ai(i, e) {
259
+ var n, t = e.defIds;
260
+ return !t || t.length === 0 ? i : i.tag === "defs" && (!((n = i.children) === null || n === void 0) && n.length) ? se(se({}, i), { children: i.children.map(function(o) {
261
+ return typeof o.attrs.id == "string" && t && t.indexOf(o.attrs.id) > -1 ? se(se({}, o), { attrs: se(se({}, o.attrs), { id: o.attrs.id + e.idSuffix }) }) : o;
262
+ }) }) : i;
243
263
  }
244
- function Mn() {
264
+ function si() {
245
265
  return Math.random().toString(36).substring(2, 8);
246
266
  }
247
- Ce.displayName = "UniverIcon";
248
- var On = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z", fillRule: "evenodd", clipRule: "evenodd" } }, { tag: "path", attrs: { fill: "currentColor", d: "M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z" } }] }, Me = fe(function(e, n) {
249
- return ve(Ce, Object.assign({}, e, {
267
+ $n.displayName = "UniverIcon";
268
+ var ci = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z", fillRule: "evenodd", clipRule: "evenodd" } }, { tag: "path", attrs: { fill: "currentColor", d: "M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z" } }] }, Xn = Gn(function(i, e) {
269
+ return Hn($n, Object.assign({}, i, {
250
270
  id: "add-image-single",
251
- ref: n,
252
- icon: On
271
+ ref: e,
272
+ icon: ci
253
273
  }));
254
274
  });
255
- Me.displayName = "AddImageSingle";
256
- const z = {
275
+ Xn.displayName = "AddImageSingle";
276
+ const rn = {
257
277
  id: "doc.operation.insert-float-image",
258
- type: S.OPERATION,
278
+ type: $.OPERATION,
259
279
  handler: () => !0
260
- }, Pn = "univer-upload-file-menu", En = "univer-upload-file-menu-input", oe = {
261
- uploadFileMenu: Pn,
262
- uploadFileMenuInput: En
263
- }, yn = () => {
264
- const e = b(I), n = he(null), t = () => {
265
- var o;
266
- (o = n.current) == null || o.click();
267
- }, r = Je.map((o) => `.${o.replace("image/", "")}`).join(","), i = (o) => {
268
- const a = o.target.files;
280
+ }, li = "univer-upload-file-menu", di = "univer-upload-file-menu-input", bn = {
281
+ uploadFileMenu: li,
282
+ uploadFileMenuInput: di
283
+ }, mi = () => {
284
+ const i = ie(W), e = Wn(null), n = () => {
285
+ var r;
286
+ (r = e.current) == null || r.click();
287
+ }, t = Ot.map((r) => `.${r.replace("image/", "")}`).join(","), o = (r) => {
288
+ const a = r.target.files;
269
289
  if (a == null)
270
290
  return;
271
291
  const s = Array.from(a);
272
- e.executeCommand(z.id, { files: s }), n.current && (n.current.value = "");
292
+ i.executeCommand(rn.id, { files: s }), e.current && (e.current.value = "");
273
293
  };
274
- return /* @__PURE__ */ C.createElement("div", { onClick: t, className: oe.uploadFileMenu }, /* @__PURE__ */ C.createElement(
294
+ return /* @__PURE__ */ d.createElement("div", { onClick: n, className: bn.uploadFileMenu }, /* @__PURE__ */ d.createElement(
275
295
  "input",
276
296
  {
277
297
  type: "file",
278
- className: oe.uploadFileMenuInput,
279
- ref: n,
280
- onChange: i,
281
- accept: r,
298
+ className: bn.uploadFileMenuInput,
299
+ ref: e,
300
+ onChange: o,
301
+ accept: t,
282
302
  multiple: !0
283
303
  }
284
304
  ));
285
- }, Oe = "COMPONENT_DOC_UPLOAD_FILE_MENU", Pe = "addition-and-subtraction-single", Ee = "doc.menu.image";
286
- function bn(e) {
305
+ }, qn = "COMPONENT_DOC_UPLOAD_FILE_MENU", Kn = "addition-and-subtraction-single", Yn = "doc.menu.image";
306
+ function ui(i) {
307
+ const e = i.get(X), n = i.get(Q);
308
+ return new Wt((t) => {
309
+ const o = e.focused$.subscribe((s) => {
310
+ if (s == null)
311
+ return t.next(!0);
312
+ const l = n.getRenderById(s);
313
+ if (l == null)
314
+ return t.next(!0);
315
+ l.with(me).getViewModel().editAreaChange$.subscribe((m) => {
316
+ t.next(m === sn.HEADER || m === sn.FOOTER);
317
+ });
318
+ }), r = n.getCurrentTypeOfRenderer(Ce.UNIVER_DOC);
319
+ if (r == null)
320
+ return t.next(!0);
321
+ const a = r.with(me).getViewModel();
322
+ return t.next(a.getEditArea() !== sn.BODY), () => o.unsubscribe();
323
+ });
324
+ }
325
+ function gi(i) {
287
326
  return {
288
- id: Ee,
289
- type: ge.SUBITEMS,
290
- positions: [un.TOOLBAR_START],
291
- group: mn.TOOLBAR_LAYOUT,
292
- icon: Pe,
327
+ id: Yn,
328
+ type: Fn.SUBITEMS,
329
+ positions: [Xt.TOOLBAR_START],
330
+ group: qt.TOOLBAR_LAYOUT,
331
+ icon: Kn,
293
332
  tooltip: "docImage.title",
294
- hidden$: pe(e, E.UNIVER_DOC)
333
+ hidden$: Gt(Bn(i, Ce.UNIVER_DOC), ui(i), (e, n) => e || n)
295
334
  };
296
335
  }
297
- function Rn(e) {
336
+ function pi(i) {
298
337
  return {
299
- id: z.id,
338
+ id: rn.id,
300
339
  title: "docImage.upload.float",
301
- type: ge.SELECTOR,
340
+ type: Fn.SELECTOR,
302
341
  label: {
303
- name: Oe
342
+ name: qn
304
343
  },
305
- positions: [Ee],
306
- hidden$: pe(e, E.UNIVER_DOC)
344
+ positions: [Yn],
345
+ hidden$: Bn(i, Ce.UNIVER_DOC)
307
346
  };
308
347
  }
309
- const Un = "univer-image-common-panel", Nn = "univer-image-common-panel-grid", An = "univer-image-common-panel-border", Tn = "univer-image-common-panel-title", xn = "univer-image-common-panel-row", Gn = "univer-image-common-panel-row-vertical", Ln = "univer-image-common-panel-column", jn = "univer-image-common-panel-column-center", Wn = "univer-image-common-panel-inline", Fn = "univer-image-common-panel-span2", $n = "univer-image-common-panel-span3", Vn = "univer-image-common-panel-input", Bn = "univer-sheet-image-menu", Hn = "univer-sheet-image-menu-input", O = {
310
- imageCommonPanel: Un,
311
- imageCommonPanelGrid: Nn,
312
- imageCommonPanelBorder: An,
313
- imageCommonPanelTitle: Tn,
314
- imageCommonPanelRow: xn,
315
- imageCommonPanelRowVertical: Gn,
316
- imageCommonPanelColumn: Ln,
317
- imageCommonPanelColumnCenter: jn,
318
- imageCommonPanelInline: Wn,
319
- imageCommonPanelSpan2: Fn,
320
- imageCommonPanelSpan3: $n,
321
- imageCommonPanelInput: Vn,
322
- sheetImageMenu: Bn,
323
- sheetImageMenuInput: Hn
324
- }, q = {
325
- id: "doc.command.set-doc-image",
326
- type: S.COMMAND,
327
- handler: (e, n) => {
328
- const t = e.get(I), r = e.get(U), i = e.get(M);
329
- if (!n) return !1;
330
- const { drawings: o } = n, a = i.getBatchUpdateOp(o), { unitId: s, subUnitId: c, undo: u, redo: m, objects: d } = a;
331
- return t.syncExecuteCommand(p.id, { unitId: s, subUnitId: c, op: m, objects: d, type: f.UPDATE }) ? (r.pushUndoRedo({
332
- unitID: s,
333
- undoMutations: [
334
- { id: p.id, params: { unitId: s, subUnitId: c, op: u, objects: d, type: f.UPDATE } },
335
- { id: w.id, params: [s] }
336
- ],
337
- redoMutations: [
338
- { id: p.id, params: { unitId: s, subUnitId: c, op: m, objects: d, type: f.UPDATE } },
339
- { id: w.id, params: [s] }
340
- ]
341
- }), !0) : !1;
348
+ const fi = "univer-image-common-panel", hi = "univer-image-common-panel-grid", wi = "univer-image-common-panel-border", vi = "univer-image-common-panel-title", Ii = "univer-image-common-panel-subtitle", _i = "univer-image-common-panel-row", Ci = "univer-image-common-panel-row-vertical", Si = "univer-image-common-panel-column", Di = "univer-image-common-panel-column-center", Pi = "univer-image-common-panel-inline", Ei = "univer-image-common-panel-span2", Oi = "univer-image-common-panel-span3", Ti = "univer-image-common-panel-input", Mi = "univer-sheet-image-menu", yi = "univer-sheet-image-menu-input", h = {
349
+ imageCommonPanel: fi,
350
+ imageCommonPanelGrid: hi,
351
+ imageCommonPanelBorder: wi,
352
+ imageCommonPanelTitle: vi,
353
+ imageCommonPanelSubtitle: Ii,
354
+ imageCommonPanelRow: _i,
355
+ imageCommonPanelRowVertical: Ci,
356
+ imageCommonPanelColumn: Si,
357
+ imageCommonPanelColumnCenter: Di,
358
+ imageCommonPanelInline: Pi,
359
+ imageCommonPanelSpan2: Ei,
360
+ imageCommonPanelSpan3: Oi,
361
+ imageCommonPanelInput: Ti,
362
+ sheetImageMenu: Mi,
363
+ sheetImageMenuInput: yi
364
+ };
365
+ var re = /* @__PURE__ */ ((i) => (i.INLINE = "inline", i.BEHIND_TEXT = "behindText", i.IN_FRONT_OF_TEXT = "inFrontOfText", i.WRAP_SQUARE = "wrapSquare", i.WRAP_TOP_AND_BOTTOM = "wrapTopAndBottom", i))(re || {});
366
+ const bi = {
367
+ inline: B.INLINE,
368
+ wrapSquare: B.WRAP_SQUARE,
369
+ wrapTopAndBottom: B.WRAP_TOP_AND_BOTTOM,
370
+ inFrontOfText: B.WRAP_NONE,
371
+ behindText: B.WRAP_NONE
372
+ }, Zn = {
373
+ id: "doc.command.update-doc-drawing-wrapping-style",
374
+ type: $.COMMAND,
375
+ // eslint-disable-next-line max-lines-per-function, complexity
376
+ handler: (i, e) => {
377
+ if (e == null)
378
+ return !1;
379
+ const { drawings: n, wrappingStyle: t, unitId: o } = e, r = i.get(W), a = i.get(X), l = i.get(Q).getRenderById(o), c = l == null ? void 0 : l.with(me).getSkeleton().getSkeletonData(), m = l == null ? void 0 : l.scene, u = a.getCurrentUniverDocInstance();
380
+ if (u == null || c == null || m == null)
381
+ return !1;
382
+ const p = m.getTransformerByCreate(), { pages: f } = c, g = k.getInstance(), w = [], { drawings: v = {} } = u.getSnapshot();
383
+ for (const P of n) {
384
+ const { drawingId: S } = P, O = v[S].layoutType, R = bi[t];
385
+ if (O !== R) {
386
+ const T = g.replaceOp(["drawings", S, "layoutType"], O, R);
387
+ w.push(T);
388
+ }
389
+ if (t === "behindText" || t === "inFrontOfText") {
390
+ const T = v[S].behindDoc, V = t === "behindText" ? Me.TRUE : Me.FALSE;
391
+ if (T !== V) {
392
+ const x = g.replaceOp(["drawings", S, "behindDoc"], T, V);
393
+ w.push(x);
394
+ }
395
+ }
396
+ if (t === "inline")
397
+ continue;
398
+ let D = null, b = 0, y = 0;
399
+ for (const T of f)
400
+ if (T.skeDrawings.has(S)) {
401
+ D = T.skeDrawings.get(S), b = T.marginTop, y = T.marginLeft;
402
+ break;
403
+ }
404
+ if (D != null) {
405
+ const { aTop: T, aLeft: V } = D, x = v[S].docTransform.positionH;
406
+ let L = V;
407
+ x.relativeFrom === Y.MARGIN ? L -= y : x.relativeFrom === Y.COLUMN && (L -= D.columnLeft);
408
+ const z = {
409
+ relativeFrom: x.relativeFrom,
410
+ posOffset: L
411
+ };
412
+ if (x.posOffset !== z.posOffset) {
413
+ const E = g.replaceOp(["drawings", S, "docTransform", "positionH"], x, z);
414
+ w.push(E);
415
+ }
416
+ const N = v[S].docTransform.positionV;
417
+ let _ = T;
418
+ N.relativeFrom === G.PAGE ? _ += b : N.relativeFrom === G.LINE ? _ -= D.lineTop : N.relativeFrom === G.PARAGRAPH && (_ -= D.blockAnchorTop);
419
+ const M = {
420
+ relativeFrom: N.relativeFrom,
421
+ posOffset: _
422
+ };
423
+ if (N.posOffset !== M.posOffset) {
424
+ const E = g.replaceOp(["drawings", S, "docTransform", "positionV"], N, M);
425
+ w.push(E);
426
+ }
427
+ }
428
+ }
429
+ const I = {
430
+ id: Z.id,
431
+ params: {
432
+ unitId: o,
433
+ actions: [],
434
+ textRanges: null
435
+ }
436
+ };
437
+ I.params.actions = w.reduce((P, S) => k.compose(P, S), null);
438
+ const C = r.syncExecuteCommand(I.id, I.params);
439
+ return p.refreshControls(), !!C;
342
440
  }
343
- }, zn = (e) => {
344
- b(I);
345
- const n = b(k);
346
- b(N);
347
- const t = b(H), { drawings: r } = e, i = r[0];
348
- if (i == null)
349
- return;
350
- const { unitId: o } = i, a = t.getRenderById(o), s = a == null ? void 0 : a.scene;
441
+ }, Qn = {
442
+ id: "doc.command.update-doc-drawing-distance",
443
+ type: $.COMMAND,
444
+ handler: (i, e) => {
445
+ if (e == null)
446
+ return !1;
447
+ const n = i.get(W), o = i.get(X).getCurrentUniverDocInstance();
448
+ if (o == null)
449
+ return !1;
450
+ const { drawings: r, dist: a, unitId: s } = e, l = k.getInstance(), c = [], { drawings: m = {} } = o.getSnapshot();
451
+ for (const f of r) {
452
+ const { drawingId: g } = f;
453
+ for (const [w, v] of Object.entries(a)) {
454
+ const I = m[g][w];
455
+ if (I !== v) {
456
+ const C = l.replaceOp(["drawings", g, w], I, v);
457
+ c.push(C);
458
+ }
459
+ }
460
+ }
461
+ const u = {
462
+ id: Z.id,
463
+ params: {
464
+ unitId: s,
465
+ actions: [],
466
+ textRanges: null
467
+ }
468
+ };
469
+ return u.params.actions = c.reduce((f, g) => k.compose(f, g), null), !!n.syncExecuteCommand(u.id, u.params);
470
+ }
471
+ }, Jn = {
472
+ id: "doc.command.update-doc-drawing-wrap-text",
473
+ type: $.COMMAND,
474
+ handler: (i, e) => {
475
+ if (e == null)
476
+ return !1;
477
+ const n = i.get(W), o = i.get(X).getCurrentUniverDocInstance();
478
+ if (o == null)
479
+ return !1;
480
+ const { drawings: r, wrapText: a, unitId: s } = e, l = k.getInstance(), c = [], { drawings: m = {} } = o.getSnapshot();
481
+ for (const f of r) {
482
+ const { drawingId: g } = f, w = m[g].wrapText;
483
+ if (w !== a) {
484
+ const v = l.replaceOp(["drawings", g, "wrapText"], w, a);
485
+ c.push(v);
486
+ }
487
+ }
488
+ const u = {
489
+ id: Z.id,
490
+ params: {
491
+ unitId: s,
492
+ actions: [],
493
+ textRanges: null
494
+ }
495
+ };
496
+ return u.params.actions = c.reduce((f, g) => k.compose(f, g), null), !!n.syncExecuteCommand(u.id, u.params);
497
+ }
498
+ }, xe = {
499
+ id: "doc.command.update-drawing-doc-transform",
500
+ type: $.COMMAND,
501
+ handler: (i, e) => {
502
+ if (e == null)
503
+ return !1;
504
+ const n = i.get(W), t = i.get(X), r = i.get(Q).getRenderById(e.unitId), a = r == null ? void 0 : r.scene;
505
+ if (a == null)
506
+ return !1;
507
+ const s = a.getTransformerByCreate(), l = t.getCurrentUniverDocInstance();
508
+ if (l == null)
509
+ return !1;
510
+ const { drawings: c, unitId: m } = e, u = k.getInstance(), p = [], { drawings: f = {} } = l.getSnapshot();
511
+ for (const v of c) {
512
+ const { drawingId: I, key: C, value: P } = v, S = f[I].docTransform[C];
513
+ if (!_e.diffValue(S, P)) {
514
+ const O = u.replaceOp(["drawings", I, "docTransform", C], S, P);
515
+ p.push(O);
516
+ }
517
+ }
518
+ const g = {
519
+ id: Z.id,
520
+ params: {
521
+ unitId: m,
522
+ actions: [],
523
+ textRanges: null,
524
+ debounce: !0
525
+ }
526
+ };
527
+ g.params.actions = p.reduce((v, I) => k.compose(v, I), null);
528
+ const w = n.syncExecuteCommand(g.id, g.params);
529
+ return s.refreshControls(), !!w;
530
+ }
531
+ }, et = {
532
+ id: "doc.command.move-inline-drawing",
533
+ type: $.COMMAND,
534
+ // eslint-disable-next-line max-lines-per-function
535
+ handler: (i, e) => {
536
+ var D, b, y, T;
537
+ if (e == null)
538
+ return !1;
539
+ const n = i.get(Q), t = i.get(Le), o = n.getRenderById(e.unitId), r = o == null ? void 0 : o.scene;
540
+ if (r == null)
541
+ return !1;
542
+ const a = r.getTransformerByCreate(), s = i.get(W), c = i.get(X).getCurrentUniverDocInstance();
543
+ if (c == null)
544
+ return !1;
545
+ const { drawing: m, unitId: u, offset: p } = e, f = new Je(), g = k.getInstance(), w = [], { drawingId: v } = m, I = (D = t.getSegment()) != null ? D : "", C = (T = (y = (b = c.getSelfOrHeaderFooterModel(I).getBody()) == null ? void 0 : b.customBlocks) == null ? void 0 : y.find((V) => V.blockId === v)) == null ? void 0 : T.startIndex;
546
+ if (C == null)
547
+ return !1;
548
+ p < C ? (p > 0 && f.push({
549
+ t: j.RETAIN,
550
+ len: p,
551
+ segmentId: I
552
+ }), f.push({
553
+ t: j.INSERT,
554
+ body: {
555
+ dataStream: "\b",
556
+ customBlocks: [{
557
+ startIndex: 0,
558
+ blockId: m.drawingId
559
+ }]
560
+ },
561
+ len: 1,
562
+ line: 0,
563
+ segmentId: I
564
+ }), f.push({
565
+ t: j.RETAIN,
566
+ len: C - p,
567
+ segmentId: I
568
+ }), f.push({
569
+ t: j.DELETE,
570
+ len: 1,
571
+ line: 0,
572
+ segmentId: ""
573
+ })) : (C > 0 && f.push({
574
+ t: j.RETAIN,
575
+ len: C,
576
+ segmentId: I
577
+ }), f.push({
578
+ t: j.DELETE,
579
+ len: 1,
580
+ line: 0,
581
+ segmentId: ""
582
+ }), p - C - 1 > 0 && f.push({
583
+ t: j.RETAIN,
584
+ len: p - C - 1,
585
+ segmentId: I
586
+ }), f.push({
587
+ t: j.INSERT,
588
+ body: {
589
+ dataStream: "\b",
590
+ customBlocks: [{
591
+ startIndex: 0,
592
+ blockId: m.drawingId
593
+ }]
594
+ },
595
+ len: 1,
596
+ line: 0,
597
+ segmentId: I
598
+ }));
599
+ const P = on(c, I), S = g.editOp(f.serialize(), P);
600
+ w.push(S);
601
+ const O = {
602
+ id: Z.id,
603
+ params: {
604
+ unitId: u,
605
+ actions: [],
606
+ textRanges: null
607
+ }
608
+ };
609
+ O.params.actions = w.reduce((V, x) => k.compose(V, x), null);
610
+ const R = s.syncExecuteCommand(O.id, O.params);
611
+ return a.refreshControls(), !!R;
612
+ }
613
+ }, nt = {
614
+ id: "doc.command.transform-non-inline-drawing",
615
+ type: $.COMMAND,
616
+ // eslint-disable-next-line max-lines-per-function
617
+ handler: (i, e) => {
618
+ var x, L, z, N;
619
+ if (e == null)
620
+ return !1;
621
+ const n = i.get(Le), o = i.get(Q).getRenderById(e.unitId), r = o == null ? void 0 : o.scene;
622
+ if (r == null)
623
+ return !1;
624
+ const a = r.getTransformerByCreate(), s = i.get(W), c = i.get(X).getCurrentUniverDocInstance();
625
+ if (c == null)
626
+ return !1;
627
+ const { drawing: m, unitId: u, offset: p, docTransform: f } = e, g = new Je(), w = k.getInstance(), v = [], { drawingId: I } = m, C = (x = n.getSegment()) != null ? x : "", P = (N = (z = (L = c.getSelfOrHeaderFooterModel(C).getBody()) == null ? void 0 : L.customBlocks) == null ? void 0 : z.find((_) => _.blockId === I)) == null ? void 0 : N.startIndex;
628
+ if (P == null)
629
+ return !1;
630
+ if (p < P ? (p > 0 && g.push({
631
+ t: j.RETAIN,
632
+ len: p,
633
+ segmentId: C
634
+ }), g.push({
635
+ t: j.INSERT,
636
+ body: {
637
+ dataStream: "\b",
638
+ customBlocks: [{
639
+ startIndex: 0,
640
+ blockId: m.drawingId
641
+ }]
642
+ },
643
+ len: 1,
644
+ line: 0,
645
+ segmentId: C
646
+ }), g.push({
647
+ t: j.RETAIN,
648
+ len: P - p,
649
+ segmentId: C
650
+ }), g.push({
651
+ t: j.DELETE,
652
+ len: 1,
653
+ line: 0,
654
+ segmentId: ""
655
+ })) : p > P && (P > 0 && g.push({
656
+ t: j.RETAIN,
657
+ len: P,
658
+ segmentId: C
659
+ }), g.push({
660
+ t: j.DELETE,
661
+ len: 1,
662
+ line: 0,
663
+ segmentId: ""
664
+ }), p - P - 1 > 0 && g.push({
665
+ t: j.RETAIN,
666
+ len: p - P - 1,
667
+ segmentId: C
668
+ }), g.push({
669
+ t: j.INSERT,
670
+ body: {
671
+ dataStream: "\b",
672
+ customBlocks: [{
673
+ startIndex: 0,
674
+ blockId: m.drawingId
675
+ }]
676
+ },
677
+ len: 1,
678
+ line: 0,
679
+ segmentId: C
680
+ })), p !== P) {
681
+ const _ = on(c, C), M = w.editOp(g.serialize(), _);
682
+ v.push(M);
683
+ }
684
+ const { drawings: S = {} } = c.getSnapshot(), O = S[I].docTransform, { positionH: R, positionV: D, size: b, angle: y } = O;
685
+ if (!_e.diffValue(R, f.positionH)) {
686
+ const _ = w.replaceOp(["drawings", I, "docTransform", "positionH"], R, f.positionH);
687
+ v.push(_);
688
+ }
689
+ if (!_e.diffValue(D, f.positionV)) {
690
+ const _ = w.replaceOp(["drawings", I, "docTransform", "positionV"], D, f.positionV);
691
+ v.push(_);
692
+ }
693
+ if (!_e.diffValue(b, f.size)) {
694
+ const _ = w.replaceOp(["drawings", I, "docTransform", "size"], b, f.size);
695
+ v.push(_);
696
+ }
697
+ if (!_e.diffValue(y, f.angle)) {
698
+ const _ = w.replaceOp(["drawings", I, "docTransform", "angle"], y, f.angle);
699
+ v.push(_);
700
+ }
701
+ const T = {
702
+ id: Z.id,
703
+ params: {
704
+ unitId: u,
705
+ actions: [],
706
+ textRanges: null,
707
+ debounce: !0
708
+ }
709
+ };
710
+ T.params.actions = v.reduce((_, M) => k.compose(_, M), null);
711
+ const V = s.syncExecuteCommand(T.id, T.params);
712
+ return a.refreshControls(), !!V;
713
+ }
714
+ }, je = 0, ke = 100, Ri = (i) => {
715
+ const e = ie(W), n = ie(en), t = ie(ge), o = ie(Q), r = ie(X), { drawings: a } = i, s = a[0];
351
716
  if (s == null)
717
+ return null;
718
+ const { unitId: l } = s, c = r.getUniverDocInstance(l), m = o.getRenderById(l);
719
+ if ((m == null ? void 0 : m.scene) == null)
720
+ return null;
721
+ const [p, f] = te(!0), [g, w] = te(!0), [v, I] = te(!0), [C, P] = te(re.INLINE), [S, O] = te(""), [R, D] = te({
722
+ distT: 0,
723
+ distL: 0,
724
+ distB: 0,
725
+ distR: 0
726
+ }), [b, y] = te(!0);
727
+ function T(N) {
728
+ P(N);
729
+ const _ = t.getFocusDrawings();
730
+ if (_.length === 0)
731
+ return;
732
+ const { unitId: M, subUnitId: E } = _[0], A = _.map(({ unitId: U, subUnitId: F, drawingId: q }) => ({
733
+ unitId: U,
734
+ subUnitId: F,
735
+ drawingId: q
736
+ }));
737
+ e.executeCommand(Zn.id, {
738
+ unitId: M,
739
+ subUnitId: E,
740
+ drawings: A,
741
+ wrappingStyle: N
742
+ });
743
+ }
744
+ function V(N) {
745
+ O(N);
746
+ const _ = t.getFocusDrawings();
747
+ if (_.length === 0)
748
+ return;
749
+ const M = _.map((E) => ({
750
+ unitId: E.unitId,
751
+ subUnitId: E.subUnitId,
752
+ drawingId: E.drawingId
753
+ }));
754
+ e.executeCommand(Jn.id, {
755
+ unitId: _[0].unitId,
756
+ subUnitId: _[0].unitId,
757
+ drawings: M,
758
+ wrapText: N
759
+ });
760
+ }
761
+ function x(N, _) {
762
+ if (N == null)
763
+ return;
764
+ const M = { ...R, [_]: N };
765
+ D(M);
766
+ const E = t.getFocusDrawings();
767
+ if (E.length === 0)
768
+ return;
769
+ const A = E.map((U) => ({
770
+ unitId: U.unitId,
771
+ subUnitId: U.subUnitId,
772
+ drawingId: U.drawingId
773
+ }));
774
+ e.executeCommand(Qn.id, {
775
+ unitId: E[0].unitId,
776
+ subUnitId: E[0].unitId,
777
+ drawings: A,
778
+ dist: {
779
+ [_]: N
780
+ }
781
+ });
782
+ }
783
+ function L() {
784
+ const N = t.getFocusDrawings();
785
+ N.length !== 0 && z(N[0]);
786
+ }
787
+ function z(N) {
788
+ var ce, pe;
789
+ const _ = (pe = (ce = c == null ? void 0 : c.getSnapshot()) == null ? void 0 : ce.drawings) == null ? void 0 : pe[N.drawingId];
790
+ if (_ == null)
791
+ return;
792
+ const {
793
+ distT: M = 0,
794
+ distL: E = 0,
795
+ distB: A = 0,
796
+ distR: U = 0,
797
+ layoutType: F = B.INLINE,
798
+ behindDoc: q = Me.FALSE,
799
+ wrapText: J = Ae.BOTH_SIDES
800
+ } = _;
801
+ if (D({
802
+ distT: M,
803
+ distL: E,
804
+ distB: A,
805
+ distR: U
806
+ }), O(J), f(F !== B.WRAP_SQUARE), F === B.WRAP_NONE || F === B.INLINE ? w(!0) : w(!1), F === B.WRAP_NONE || F === B.INLINE || F === B.WRAP_TOP_AND_BOTTOM ? I(!0) : I(!1), F === B.WRAP_NONE)
807
+ q === Me.TRUE ? P(re.BEHIND_TEXT) : P(re.IN_FRONT_OF_TEXT);
808
+ else
809
+ switch (F) {
810
+ case B.INLINE:
811
+ P(re.INLINE);
812
+ break;
813
+ case B.WRAP_SQUARE:
814
+ P(re.WRAP_SQUARE);
815
+ break;
816
+ case B.WRAP_TOP_AND_BOTTOM:
817
+ P(re.WRAP_TOP_AND_BOTTOM);
818
+ break;
819
+ default:
820
+ throw new Error(`Unsupported layout type: ${F}`);
821
+ }
822
+ }
823
+ return gn(() => {
824
+ L();
825
+ const N = t.focus$.subscribe((M) => {
826
+ if (M.length === 0) {
827
+ y(!1);
828
+ return;
829
+ }
830
+ y(!0), z(M[0]);
831
+ }), _ = e.onCommandExecuted(async (M) => {
832
+ M.id === Z.id && L();
833
+ });
834
+ return () => {
835
+ N.unsubscribe(), _.dispose();
836
+ };
837
+ }, []), /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelGrid, h.imageCommonPanelBorder), style: { display: b ? "block" : "none" } }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelTitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-text-wrap.title")))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelSubtitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-text-wrap.wrappingStyle")))), /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelRow) }, /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn) }, /* @__PURE__ */ d.createElement(Mn, { value: C, onChange: T, direction: "vertical" }, /* @__PURE__ */ d.createElement(Ie, { value: re.INLINE }, n.t("image-text-wrap.inline")), /* @__PURE__ */ d.createElement(Ie, { value: re.WRAP_SQUARE }, n.t("image-text-wrap.square")), /* @__PURE__ */ d.createElement(Ie, { value: re.WRAP_TOP_AND_BOTTOM }, n.t("image-text-wrap.topAndBottom")), /* @__PURE__ */ d.createElement(Ie, { value: re.BEHIND_TEXT }, n.t("image-text-wrap.behindText")), /* @__PURE__ */ d.createElement(Ie, { value: re.IN_FRONT_OF_TEXT }, n.t("image-text-wrap.inFrontText"))))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelSubtitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-text-wrap.wrapText")))), /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelRow) }, /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn) }, /* @__PURE__ */ d.createElement(Mn, { disabled: p, value: S, onChange: V, direction: "horizontal" }, /* @__PURE__ */ d.createElement(Ie, { value: Ae.BOTH_SIDES }, n.t("image-text-wrap.bothSide")), /* @__PURE__ */ d.createElement(Ie, { value: Ae.LEFT }, n.t("image-text-wrap.leftOnly")), /* @__PURE__ */ d.createElement(Ie, { value: Ae.RIGHT }, n.t("image-text-wrap.rightOnly"))))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelSubtitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-text-wrap.distanceFromText")))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, n.t("image-text-wrap.top"))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
838
+ Te,
839
+ {
840
+ min: je,
841
+ max: ke,
842
+ disabled: g,
843
+ precision: 1,
844
+ value: R.distT,
845
+ onChange: (N) => {
846
+ x(N, "distT");
847
+ },
848
+ className: h.imageCommonPanelInput
849
+ }
850
+ ))))), /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, n.t("image-text-wrap.left"))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
851
+ Te,
852
+ {
853
+ min: je,
854
+ max: ke,
855
+ disabled: v,
856
+ precision: 1,
857
+ value: R.distL,
858
+ onChange: (N) => {
859
+ x(N, "distL");
860
+ },
861
+ className: h.imageCommonPanelInput
862
+ }
863
+ )))))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, n.t("image-text-wrap.bottom"))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
864
+ Te,
865
+ {
866
+ min: je,
867
+ max: ke,
868
+ disabled: g,
869
+ precision: 1,
870
+ value: R.distB,
871
+ onChange: (N) => {
872
+ x(N, "distB");
873
+ },
874
+ className: h.imageCommonPanelInput
875
+ }
876
+ ))))), /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, n.t("image-text-wrap.right"))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
877
+ Te,
878
+ {
879
+ min: je,
880
+ max: ke,
881
+ disabled: v,
882
+ precision: 1,
883
+ value: R.distR,
884
+ onChange: (N) => {
885
+ x(N, "distR");
886
+ },
887
+ className: h.imageCommonPanelInput
888
+ }
889
+ )))))));
890
+ }, Rn = -1e3, Nn = 1e3, Ni = (i) => {
891
+ const e = ie(W), n = ie(en), t = ie(ge), o = ie(Q), r = ie(X), a = ie(Le), { drawings: s } = i, l = s[0];
892
+ if (l == null)
352
893
  return;
353
- const c = s.getTransformerByCreate(), [u, m] = Z(!0);
354
- Z(""), Ie(() => {
355
- const l = c.clearControl$.subscribe((g) => {
356
- g === !0 && m(!1);
894
+ const { unitId: c } = l, m = r.getUniverDocInstance(c), u = o.getRenderById(c), p = u == null ? void 0 : u.scene;
895
+ if (p == null)
896
+ return;
897
+ const f = p.getTransformerByCreate(), g = [{
898
+ label: n.t("image-position.column"),
899
+ value: String(Y.COLUMN)
900
+ }, {
901
+ label: n.t("image-position.page"),
902
+ value: String(Y.PAGE)
903
+ }, {
904
+ label: n.t("image-position.margin"),
905
+ value: String(Y.MARGIN)
906
+ }], w = [{
907
+ label: n.t("image-position.line"),
908
+ value: String(G.LINE)
909
+ }, {
910
+ label: n.t("image-position.page"),
911
+ value: String(G.PAGE)
912
+ }, {
913
+ label: n.t("image-position.margin"),
914
+ value: String(G.MARGIN)
915
+ }, {
916
+ label: n.t("image-position.paragraph"),
917
+ value: String(G.PARAGRAPH)
918
+ }], [v, I] = te(!0), [C, P] = te({
919
+ relativeFrom: Y.PAGE,
920
+ posOffset: 0
921
+ }), [S, O] = te({
922
+ relativeFrom: G.PAGE,
923
+ posOffset: 0
924
+ }), [R, D] = te(!0), [b, y] = te(!0);
925
+ function T(_, M) {
926
+ _ === "positionH" ? P(M) : O(M);
927
+ const E = t.getFocusDrawings();
928
+ if (E.length === 0)
929
+ return;
930
+ const A = E.map((U) => ({
931
+ unitId: U.unitId,
932
+ subUnitId: U.subUnitId,
933
+ drawingId: U.drawingId
934
+ }));
935
+ e.executeCommand(xe.id, {
936
+ unitId: E[0].unitId,
937
+ subUnitId: E[0].unitId,
938
+ drawings: A.map((U) => ({
939
+ drawingId: U.drawingId,
940
+ key: _,
941
+ value: M
942
+ }))
943
+ }), a.blur(), f.refreshControls();
944
+ }
945
+ function V(_) {
946
+ var ee;
947
+ const M = C.relativeFrom, E = C.posOffset, A = Number(_);
948
+ if (M === A)
949
+ return;
950
+ const U = t.getFocusDrawings();
951
+ if (U.length === 0)
952
+ return;
953
+ const F = U[0].drawingId, q = U[0].unitId;
954
+ let J = null, ue = 0;
955
+ const ce = (ee = o.getRenderById(q)) == null ? void 0 : ee.with(me).getSkeleton(), pe = ce == null ? void 0 : ce.getSkeletonData();
956
+ if (pe == null)
957
+ return;
958
+ for (const we of pe.pages) {
959
+ const { marginLeft: ve, skeDrawings: ne } = we;
960
+ if (ne.has(F)) {
961
+ J = ne.get(F), ue = ve;
962
+ break;
963
+ }
964
+ }
965
+ if (J == null)
966
+ return;
967
+ let oe = 0;
968
+ M === Y.COLUMN ? oe -= J.columnLeft : M === Y.MARGIN && (oe -= ue), A === Y.COLUMN ? oe += J.columnLeft : A === Y.MARGIN ? oe += ue : Y.PAGE;
969
+ const K = {
970
+ relativeFrom: A,
971
+ posOffset: (E != null ? E : 0) - oe
972
+ };
973
+ T("positionH", K);
974
+ }
975
+ function x(_) {
976
+ var Ge, fn, hn, wn, vn;
977
+ const M = S.relativeFrom, E = S.posOffset, A = Number(_);
978
+ if (M === A)
979
+ return;
980
+ const U = t.getFocusDrawings();
981
+ if (U.length === 0)
982
+ return;
983
+ const { drawingId: F, unitId: q } = U[0], J = r.getUniverDocInstance(q), ue = (Ge = o.getRenderById(q)) == null ? void 0 : Ge.with(me).getSkeleton(), ce = (hn = (fn = J == null ? void 0 : J.getBody()) == null ? void 0 : fn.customBlocks) == null ? void 0 : hn.find((We) => We.blockId === F);
984
+ if (ce == null || ue == null)
985
+ return;
986
+ const { startIndex: pe } = ce, oe = ue.findNodeByCharIndex(pe), K = (wn = oe == null ? void 0 : oe.parent) == null ? void 0 : wn.parent, ee = K == null ? void 0 : K.parent, we = ee == null ? void 0 : ee.lines.find((We) => We.paragraphIndex === (K == null ? void 0 : K.paragraphIndex) && We.paragraphStart), ve = (vn = ee == null ? void 0 : ee.parent) == null ? void 0 : vn.parent;
987
+ if (oe == null || K == null || we == null || ee == null || ve == null)
988
+ return;
989
+ let ne = 0;
990
+ M === G.PARAGRAPH ? ne -= we.top : M === G.LINE ? ne -= K.top : M === G.PAGE && (ne += ve.marginTop), A === G.PARAGRAPH ? ne += we.top : A === G.LINE ? ne += K.top : A === G.PAGE && (ne -= ve.marginTop);
991
+ const le = {
992
+ relativeFrom: A,
993
+ posOffset: (E != null ? E : 0) - ne
994
+ };
995
+ T("positionV", le);
996
+ }
997
+ function L(_) {
998
+ var q;
999
+ const M = m == null ? void 0 : m.getSnapshot(), E = (q = M == null ? void 0 : M.drawings) == null ? void 0 : q[_.drawingId];
1000
+ if (E == null)
1001
+ return;
1002
+ const { layoutType: A } = E, {
1003
+ positionH: U,
1004
+ positionV: F
1005
+ } = E.docTransform;
1006
+ P(U), O(F), I(A === B.INLINE), D(F.relativeFrom === G.PARAGRAPH || F.relativeFrom === G.LINE);
1007
+ }
1008
+ function z() {
1009
+ const _ = t.getFocusDrawings();
1010
+ _.length !== 0 && L(_[0]);
1011
+ }
1012
+ function N(_) {
1013
+ D(_), x(String(_ ? G.PARAGRAPH : G.PAGE));
1014
+ }
1015
+ return gn(() => {
1016
+ z();
1017
+ const _ = t.focus$.subscribe((E) => {
1018
+ if (E.length === 0) {
1019
+ y(!1);
1020
+ return;
1021
+ }
1022
+ y(!0), L(E[0]);
1023
+ }), M = e.onCommandExecuted(async (E) => {
1024
+ E.id === Z.id && z();
357
1025
  });
358
1026
  return () => {
359
- l.unsubscribe();
1027
+ _.unsubscribe(), M.dispose();
360
1028
  };
361
- }, []);
362
- const d = (l) => l ? "block" : "none";
363
- return /* @__PURE__ */ C.createElement("div", { className: j(O.imageCommonPanelGrid, O.imageCommonPanelBorder), style: { display: d(u) } }, /* @__PURE__ */ C.createElement("div", { className: O.imageCommonPanelRow }, /* @__PURE__ */ C.createElement("div", { className: j(O.imageCommonPanelColumn, O.imageCommonPanelTitle) }, /* @__PURE__ */ C.createElement("div", null, n.t("drawing-anchor.title")))), /* @__PURE__ */ C.createElement("div", { className: j(O.imageCommonPanelRow) }, /* @__PURE__ */ C.createElement("div", { className: j(O.imageCommonPanelColumn) })));
364
- }, Kn = () => {
365
- const e = b(N), n = e.getFocusDrawings(), [t, r] = Z(n);
366
- return Ie(() => {
367
- const i = e.focus$.subscribe((o) => {
368
- r(o);
1029
+ }, []), /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelGrid, h.imageCommonPanelBorder), style: { display: b ? "block" : "none" } }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelTitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-position.title")))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelSubtitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-position.horizontal")))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, n.t("image-position.absolutePosition"))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
1030
+ Te,
1031
+ {
1032
+ min: Rn,
1033
+ max: Nn,
1034
+ precision: 1,
1035
+ disabled: v,
1036
+ value: C.posOffset,
1037
+ onChange: (_) => {
1038
+ T("positionH", {
1039
+ relativeFrom: C.relativeFrom,
1040
+ posOffset: _
1041
+ });
1042
+ },
1043
+ className: h.imageCommonPanelInput
1044
+ }
1045
+ ))))), /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, n.t("image-position.toTheRightOf"))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
1046
+ yn,
1047
+ {
1048
+ value: String(C.relativeFrom),
1049
+ disabled: v,
1050
+ options: g,
1051
+ onChange: V
1052
+ }
1053
+ )))))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelSubtitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-position.vertical")))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, n.t("image-position.absolutePosition"))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
1054
+ Te,
1055
+ {
1056
+ min: Rn,
1057
+ max: Nn,
1058
+ precision: 1,
1059
+ disabled: v,
1060
+ value: S.posOffset,
1061
+ onChange: (_) => {
1062
+ T("positionV", {
1063
+ relativeFrom: S.relativeFrom,
1064
+ posOffset: _
1065
+ });
1066
+ },
1067
+ className: h.imageCommonPanelInput
1068
+ }
1069
+ ))))), /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, n.t("image-position.bellow"))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
1070
+ yn,
1071
+ {
1072
+ disabled: v,
1073
+ value: String(S.relativeFrom),
1074
+ options: w,
1075
+ onChange: x
1076
+ }
1077
+ )))))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: H(h.imageCommonPanelColumn, h.imageCommonPanelSubtitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-position.options")))), /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelRow, style: { marginBottom: "50px" } }, /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(ei, { disabled: v, checked: R, onChange: N }, n.t("image-position.moveObjectWithText")))));
1078
+ }, Ai = () => {
1079
+ const i = ie(ge), e = i.getFocusDrawings(), [n, t] = te(e);
1080
+ return gn(() => {
1081
+ const o = i.focus$.subscribe((r) => {
1082
+ t(r);
369
1083
  });
370
1084
  return () => {
371
- i.unsubscribe();
1085
+ o.unsubscribe();
372
1086
  };
373
- }, []), !!(t != null && t.length) && /* @__PURE__ */ C.createElement("div", { className: O.imageCommonPanel }, /* @__PURE__ */ C.createElement(Xe, { drawings: t }), /* @__PURE__ */ C.createElement(zn, { drawings: t }));
374
- }, x = {
1087
+ }, []), !!(n != null && n.length) && /* @__PURE__ */ d.createElement("div", { className: h.imageCommonPanel }, /* @__PURE__ */ d.createElement(Pt, { drawings: n, hasAlign: !1, hasCropper: !1, hasGroup: !1, hasTransform: !1 }), /* @__PURE__ */ d.createElement(Ri, { drawings: n }), /* @__PURE__ */ d.createElement(Ni, { drawings: n }));
1088
+ }, Oe = {
1089
+ id: "doc.operation.clear-drawing-transformer",
1090
+ type: $.MUTATION,
1091
+ handler: (i, e) => {
1092
+ const n = i.get(Q);
1093
+ return e.forEach((t) => {
1094
+ var o, r;
1095
+ (r = (o = n.getRenderById(t)) == null ? void 0 : o.scene.getTransformer()) == null || r.debounceRefreshControls();
1096
+ }), !0;
1097
+ }
1098
+ }, Fe = {
375
1099
  id: "doc.command.move-drawing",
376
- type: S.COMMAND,
377
- handler: (e, n) => {
378
- const t = e.get(I), r = e.get(M), { direction: i } = n, o = r.getFocusDrawings();
379
- if (o.length === 0)
1100
+ type: $.COMMAND,
1101
+ handler: (i, e) => {
1102
+ const n = i.get(W), t = i.get(De), o = i.get(X), r = i.get(Q), { direction: a } = e, s = t.getFocusDrawings();
1103
+ if (s.length === 0)
1104
+ return !1;
1105
+ const l = s[0].unitId, c = r.getRenderById(l), m = c == null ? void 0 : c.scene;
1106
+ if (m == null)
380
1107
  return !1;
381
- const a = o[0].unitId, s = o.map((u) => {
382
- const { transform: m } = u;
383
- if (m == null)
1108
+ const u = m.getTransformerByCreate(), p = o.getUniverDocInstance(l), f = s.map((w) => {
1109
+ var R, D, b, y, T;
1110
+ const { drawingId: v } = w, I = (R = p == null ? void 0 : p.getSnapshot().drawings) == null ? void 0 : R[v];
1111
+ if (I == null || I.layoutType === B.INLINE)
384
1112
  return null;
385
- const d = { ...m }, { left: l = 0, top: g = 0 } = m;
386
- return i === P.UP ? d.top = g - 1 : i === P.DOWN ? d.top = g + 1 : i === P.LEFT ? d.left = l - 1 : i === P.RIGHT && (d.left = l + 1), {
387
- ...u,
388
- transform: d,
389
- docTransform: le(d)
1113
+ const { positionH: C, positionV: P } = I.docTransform, S = { ...C }, O = { ...P };
1114
+ return a === ae.UP ? O.posOffset = ((D = O.posOffset) != null ? D : 0) - 2 : a === ae.DOWN ? O.posOffset = ((b = O.posOffset) != null ? b : 0) + 2 : a === ae.LEFT ? S.posOffset = ((y = S.posOffset) != null ? y : 0) - 2 : a === ae.RIGHT && (S.posOffset = ((T = S.posOffset) != null ? T : 0) + 2), {
1115
+ drawingId: v,
1116
+ key: a === ae.UP || a === ae.DOWN ? "positionV" : "positionH",
1117
+ value: a === ae.UP || a === ae.DOWN ? O : S
390
1118
  };
391
- }).filter((u) => u != null);
392
- return t.syncExecuteCommand(q.id, {
393
- unitId: a,
394
- drawings: s
395
- }) ? (t.syncExecuteCommand(w.id, [a]), !0) : !1;
1119
+ }).filter((w) => w != null);
1120
+ if (f.length === 0)
1121
+ return !1;
1122
+ const g = n.syncExecuteCommand(xe.id, {
1123
+ unitId: l,
1124
+ subUnitId: l,
1125
+ drawings: f
1126
+ });
1127
+ return u.refreshControls(), !!g;
396
1128
  }
397
- }, ye = {
1129
+ }, tt = {
398
1130
  id: "doc.command.delete-drawing",
399
- type: S.COMMAND,
400
- handler: (e) => {
401
- const n = e.get(I), r = e.get(M).getFocusDrawings();
402
- if (r.length === 0)
1131
+ type: $.COMMAND,
1132
+ handler: (i) => {
1133
+ const e = i.get(W), t = i.get(De).getFocusDrawings();
1134
+ if (t.length === 0)
403
1135
  return !1;
404
- const i = r[0].unitId, o = r.map((a) => {
405
- const { unitId: s, subUnitId: c, drawingId: u, drawingType: m } = a;
1136
+ const { unitId: o } = t[0], r = t.map((a) => {
1137
+ const { unitId: s, subUnitId: l, drawingId: c, drawingType: m } = a;
406
1138
  return {
407
1139
  unitId: s,
408
- subUnitId: c,
409
- drawingId: u,
1140
+ subUnitId: l,
1141
+ drawingId: c,
410
1142
  drawingType: m
411
1143
  };
412
1144
  });
413
- return n.executeCommand(X.id, {
414
- unitId: i,
415
- drawings: o
1145
+ return e.executeCommand(pn.id, {
1146
+ unitId: o,
1147
+ drawings: r
416
1148
  });
417
1149
  }
418
- }, be = {
1150
+ }, it = {
419
1151
  id: "doc.command.set-drawing-arrange",
420
- type: S.COMMAND,
421
- handler: (e, n) => {
422
- const t = e.get(I), r = e.get(U);
423
- if (!n) return !1;
424
- const i = e.get(M), { unitId: o, subUnitId: a, drawingIds: s, arrangeType: c } = n, u = { unitId: o, subUnitId: a, drawingIds: s };
425
- let m;
426
- if (c === L.forward ? m = i.getForwardDrawingsOp(u) : c === L.backward ? m = i.getBackwardDrawingOp(u) : c === L.front ? m = i.getFrontDrawingsOp(u) : c === L.back && (m = i.getBackDrawingsOp(u)), m == null)
1152
+ type: $.COMMAND,
1153
+ handler: (i, e) => {
1154
+ const n = i.get(W), t = i.get(De);
1155
+ if (e == null)
427
1156
  return !1;
428
- const { objects: d, redo: l, undo: g } = m;
429
- return t.syncExecuteCommand(p.id, { op: l, unitId: o, subUnitId: a, objects: d, type: f.ARRANGE }) ? (r.pushUndoRedo({
430
- unitID: o,
1157
+ const { unitId: o, subUnitId: r, drawingIds: a, arrangeType: s } = e, l = { unitId: o, subUnitId: r, drawingIds: a };
1158
+ let c;
1159
+ if (s === He.forward ? c = t.getForwardDrawingsOp(l) : s === He.backward ? c = t.getBackwardDrawingOp(l) : s === He.front ? c = t.getFrontDrawingsOp(l) : s === He.back && (c = t.getBackDrawingsOp(l)), c == null)
1160
+ return !1;
1161
+ const { redo: m } = c;
1162
+ if (m == null)
1163
+ return !1;
1164
+ const u = [];
1165
+ let p = _e.deepClone(m);
1166
+ p = p.slice(3), p.unshift("drawingsOrder"), u.push(p);
1167
+ const f = {
1168
+ id: Z.id,
1169
+ params: {
1170
+ unitId: o,
1171
+ actions: [],
1172
+ textRanges: null
1173
+ }
1174
+ };
1175
+ return f.params.actions = u.reduce((w, v) => k.compose(w, v), null), !!n.syncExecuteCommand(f.id, f.params);
1176
+ }
1177
+ }, ot = {
1178
+ id: "doc.command.set-doc-image",
1179
+ type: $.COMMAND,
1180
+ handler: (i, e) => {
1181
+ const n = i.get(W), t = i.get(mn), o = i.get(De);
1182
+ if (!e) return !1;
1183
+ const { drawings: r } = e, a = o.getBatchUpdateOp(r), { unitId: s, subUnitId: l, undo: c, redo: m, objects: u } = a;
1184
+ return n.syncExecuteCommand(fe.id, { unitId: s, subUnitId: l, op: m, objects: u, type: he.UPDATE }) ? (t.pushUndoRedo({
1185
+ unitID: s,
431
1186
  undoMutations: [
432
- { id: p.id, params: { op: g, unitId: o, subUnitId: a, objects: d, type: f.ARRANGE } }
1187
+ { id: fe.id, params: { unitId: s, subUnitId: l, op: c, objects: u, type: he.UPDATE } },
1188
+ { id: Oe.id, params: [s] }
433
1189
  ],
434
1190
  redoMutations: [
435
- { id: p.id, params: { op: l, unitId: o, subUnitId: a, objects: d, type: f.ARRANGE } }
1191
+ { id: fe.id, params: { unitId: s, subUnitId: l, op: m, objects: u, type: he.UPDATE } },
1192
+ { id: Oe.id, params: [s] }
436
1193
  ]
437
1194
  }), !0) : !1;
438
1195
  }
439
1196
  };
440
- function Zn(e) {
441
- const n = [];
442
- return e.forEach((t) => {
443
- const { parent: r, children: i } = t, { unitId: o, subUnitId: a, drawingId: s } = r, c = an(0, 0, i.map((d) => d.transform || {})), u = i.map((d) => {
444
- const l = d.transform || { left: 0, top: 0 }, { unitId: g, subUnitId: h, drawingId: v } = d;
1197
+ function xi(i) {
1198
+ const e = [];
1199
+ return i.forEach((n) => {
1200
+ const { parent: t, children: o } = n, { unitId: r, subUnitId: a, drawingId: s } = t, l = Nt(0, 0, o.map((u) => u.transform || {})), c = o.map((u) => {
1201
+ const p = u.transform || { left: 0, top: 0 }, { unitId: f, subUnitId: g, drawingId: w } = u;
445
1202
  return {
446
- unitId: g,
447
- subUnitId: h,
448
- drawingId: v,
1203
+ unitId: f,
1204
+ subUnitId: g,
1205
+ drawingId: w,
449
1206
  transform: {
450
- ...l,
451
- left: l.left - c.left,
452
- top: l.top - c.top
1207
+ ...p,
1208
+ left: p.left - l.left,
1209
+ top: p.top - l.top
453
1210
  },
454
1211
  groupId: s
455
1212
  };
456
1213
  }), m = {
457
- unitId: o,
1214
+ unitId: r,
458
1215
  subUnitId: a,
459
1216
  drawingId: s,
460
- drawingType: Q.DRAWING_GROUP,
461
- transform: c
1217
+ drawingType: un.DRAWING_GROUP,
1218
+ transform: l
462
1219
  };
463
- n.push({
1220
+ e.push({
464
1221
  parent: m,
465
- children: u
1222
+ children: c
466
1223
  });
467
- }), n;
1224
+ }), e;
468
1225
  }
469
- function Yn(e) {
470
- const n = [];
471
- return e.forEach((t) => {
472
- const { parent: r, children: i } = t, { unitId: o, subUnitId: a, drawingId: s, transform: c = { width: 0, height: 0 } } = r;
473
- if (c == null)
1226
+ function Ui(i) {
1227
+ const e = [];
1228
+ return i.forEach((n) => {
1229
+ const { parent: t, children: o } = n, { unitId: r, subUnitId: a, drawingId: s, transform: l = { width: 0, height: 0 } } = t;
1230
+ if (l == null)
474
1231
  return;
475
- const u = i.map((d) => {
476
- const { transform: l } = d, { unitId: g, subUnitId: h, drawingId: v } = d, xe = sn(l || {}, c, c.width || 0, c.height || 0);
1232
+ const c = o.map((u) => {
1233
+ const { transform: p } = u, { unitId: f, subUnitId: g, drawingId: w } = u, v = At(p || {}, l, l.width || 0, l.height || 0);
477
1234
  return {
478
- unitId: g,
479
- subUnitId: h,
480
- drawingId: v,
481
- transform: xe,
1235
+ unitId: f,
1236
+ subUnitId: g,
1237
+ drawingId: w,
1238
+ transform: v,
482
1239
  groupId: void 0
483
1240
  };
484
1241
  }), m = {
485
- unitId: o,
1242
+ unitId: r,
486
1243
  subUnitId: a,
487
1244
  drawingId: s,
488
- drawingType: Q.DRAWING_GROUP,
1245
+ drawingType: un.DRAWING_GROUP,
489
1246
  transform: {
490
1247
  left: 0,
491
1248
  top: 0
492
1249
  }
493
1250
  };
494
- n.push({
1251
+ e.push({
495
1252
  parent: m,
496
- children: u
1253
+ children: c
497
1254
  });
498
- }), n;
1255
+ }), e;
499
1256
  }
500
- const Re = {
1257
+ const rt = {
501
1258
  id: "doc.command.ungroup-doc-image",
502
- type: S.COMMAND,
503
- handler: (e, n) => {
504
- const t = e.get(I), r = e.get(U), i = e.get(M);
505
- if (!n) return !1;
506
- const o = [];
507
- n.forEach(({ parent: g, children: h }) => {
508
- o.push(g.unitId), h.forEach((v) => {
509
- o.push(v.unitId);
1259
+ type: $.COMMAND,
1260
+ handler: (i, e) => {
1261
+ const n = i.get(W), t = i.get(mn), o = i.get(De);
1262
+ if (!e) return !1;
1263
+ const r = [];
1264
+ e.forEach(({ parent: f, children: g }) => {
1265
+ r.push(f.unitId), g.forEach((w) => {
1266
+ r.push(w.unitId);
510
1267
  });
511
1268
  });
512
- const a = i.getUngroupDrawingOp(n), { unitId: s, subUnitId: c, undo: u, redo: m, objects: d } = a;
513
- return t.syncExecuteCommand(p.id, { op: m, unitId: s, subUnitId: c, objects: d, type: f.UNGROUP }) ? (r.pushUndoRedo({
1269
+ const a = o.getUngroupDrawingOp(e), { unitId: s, subUnitId: l, undo: c, redo: m, objects: u } = a;
1270
+ return n.syncExecuteCommand(fe.id, { op: m, unitId: s, subUnitId: l, objects: u, type: he.UNGROUP }) ? (t.pushUndoRedo({
514
1271
  unitID: s,
515
1272
  undoMutations: [
516
- { id: p.id, params: { op: u, unitId: s, subUnitId: c, objects: Zn(d), type: f.GROUP } },
517
- { id: w.id, params: o }
1273
+ { id: fe.id, params: { op: c, unitId: s, subUnitId: l, objects: xi(u), type: he.GROUP } },
1274
+ { id: Oe.id, params: r }
518
1275
  ],
519
1276
  redoMutations: [
520
- { id: p.id, params: { op: m, unitId: s, subUnitId: c, objects: d, type: f.UNGROUP } },
521
- { id: w.id, params: o }
1277
+ { id: fe.id, params: { op: m, unitId: s, subUnitId: l, objects: u, type: he.UNGROUP } },
1278
+ { id: Oe.id, params: r }
522
1279
  ]
523
1280
  }), !0) : !1;
524
1281
  }
525
- }, Ue = {
1282
+ }, at = {
526
1283
  id: "doc.command.group-doc-image",
527
- type: S.COMMAND,
528
- handler: (e, n) => {
529
- const t = e.get(I), r = e.get(U), i = e.get(M);
530
- if (!n) return !1;
531
- const o = [];
532
- n.forEach(({ parent: g, children: h }) => {
533
- o.push(g.unitId), h.forEach((v) => {
534
- o.push(v.unitId);
1284
+ type: $.COMMAND,
1285
+ handler: (i, e) => {
1286
+ const n = i.get(W), t = i.get(mn), o = i.get(De);
1287
+ if (!e) return !1;
1288
+ const r = [];
1289
+ e.forEach(({ parent: f, children: g }) => {
1290
+ r.push(f.unitId), g.forEach((w) => {
1291
+ r.push(w.unitId);
535
1292
  });
536
1293
  });
537
- const a = i.getGroupDrawingOp(n), { unitId: s, subUnitId: c, undo: u, redo: m, objects: d } = a;
538
- return t.syncExecuteCommand(p.id, { op: m, unitId: s, subUnitId: c, objects: d, type: f.GROUP }) ? (r.pushUndoRedo({
1294
+ const a = o.getGroupDrawingOp(e), { unitId: s, subUnitId: l, undo: c, redo: m, objects: u } = a;
1295
+ return n.syncExecuteCommand(fe.id, { op: m, unitId: s, subUnitId: l, objects: u, type: he.GROUP }) ? (t.pushUndoRedo({
539
1296
  unitID: s,
540
1297
  undoMutations: [
541
- { id: p.id, params: { op: u, unitId: s, subUnitId: c, objects: Yn(d), type: f.UNGROUP } },
542
- { id: w.id, params: o }
1298
+ { id: fe.id, params: { op: c, unitId: s, subUnitId: l, objects: Ui(u), type: he.UNGROUP } },
1299
+ { id: Oe.id, params: r }
543
1300
  ],
544
1301
  redoMutations: [
545
- { id: p.id, params: { op: m, unitId: s, subUnitId: c, objects: d, type: f.GROUP } },
546
- { id: w.id, params: o }
1302
+ { id: fe.id, params: { op: m, unitId: s, subUnitId: l, objects: u, type: he.GROUP } },
1303
+ { id: Oe.id, params: r }
547
1304
  ]
548
1305
  }), !0) : !1;
549
1306
  }
550
- }, Ne = {
1307
+ }, st = {
551
1308
  id: "doc.command.insert-doc-image",
552
- type: S.COMMAND,
553
- handler: (e, n) => {
554
- const t = e.get(I), r = e.get(U), i = e.get(M);
555
- if (!n) return !1;
556
- const o = n.drawings, a = o.map((h) => h.unitId), s = i.getBatchAddOp(o), { unitId: c, subUnitId: u, undo: m, redo: d, objects: l } = s;
557
- return t.syncExecuteCommand(p.id, { op: d, unitId: c, subUnitId: u, objects: l, type: f.INSERT }) ? (r.pushUndoRedo({
558
- unitID: c,
559
- undoMutations: [
560
- { id: p.id, params: { op: m, unitId: c, subUnitId: u, objects: l, type: f.REMOVE } },
561
- { id: w.id, params: a }
562
- ],
563
- redoMutations: [
564
- { id: p.id, params: { op: d, unitId: c, subUnitId: u, objects: l, type: f.INSERT } },
565
- { id: w.id, params: a }
566
- ]
567
- }), !0) : !1;
1309
+ type: $.COMMAND,
1310
+ // eslint-disable-next-line max-lines-per-function
1311
+ handler: (i, e) => {
1312
+ var O, R;
1313
+ if (e == null)
1314
+ return !1;
1315
+ const n = i.get(W), t = i.get(cn), o = i.get(X), r = t.getActiveRange(), a = o.getCurrentUniverDocInstance();
1316
+ if (r == null || a == null)
1317
+ return !1;
1318
+ const s = a.getUnitId(), { drawings: l } = e, { collapsed: c, startOffset: m, segmentId: u } = r, p = a.getSelfOrHeaderFooterModel(u).getBody();
1319
+ if (p == null)
1320
+ return !1;
1321
+ const f = new Je(), g = k.getInstance(), w = [], v = (R = (O = a.getSnapshot().drawingsOrder) == null ? void 0 : O.length) != null ? R : 0;
1322
+ if (c)
1323
+ m > 0 && f.push({
1324
+ t: j.RETAIN,
1325
+ len: m,
1326
+ segmentId: u
1327
+ });
1328
+ else {
1329
+ const { dos: D } = jt(r, u, 0, p);
1330
+ f.push(...D);
1331
+ }
1332
+ f.push({
1333
+ t: j.INSERT,
1334
+ body: {
1335
+ dataStream: "\b".repeat(l.length),
1336
+ customBlocks: l.map((D, b) => ({
1337
+ startIndex: b,
1338
+ blockId: D.drawingId
1339
+ }))
1340
+ },
1341
+ len: l.length,
1342
+ line: 0,
1343
+ segmentId: u
1344
+ });
1345
+ const I = on(a, u), C = g.editOp(f.serialize(), I);
1346
+ w.push(C);
1347
+ for (const D of l) {
1348
+ const { drawingId: b } = D, y = g.insertOp(["drawings", b], D), T = g.insertOp(["drawingsOrder", v], b);
1349
+ w.push(y), w.push(T);
1350
+ }
1351
+ const P = {
1352
+ id: Z.id,
1353
+ params: {
1354
+ unitId: s,
1355
+ actions: [],
1356
+ textRanges: []
1357
+ }
1358
+ };
1359
+ return P.params.actions = w.reduce((D, b) => k.compose(D, b), null), !!n.syncExecuteCommand(P.id, P.params);
568
1360
  }
569
1361
  };
570
- function G(e) {
571
- return !e.getContextValue($e) && e.getContextValue(V);
1362
+ function Be(i) {
1363
+ return i.getContextValue(pt) && i.getContextValue(Ze);
572
1364
  }
573
- const kn = {
574
- id: x.id,
1365
+ const Li = {
1366
+ id: Fe.id,
575
1367
  description: "shortcut.doc.drawing-move-down",
576
1368
  group: "4_doc-drawing-view",
577
- binding: R.ARROW_DOWN,
1369
+ binding: ye.ARROW_DOWN,
578
1370
  priority: 100,
579
- preconditions: G,
1371
+ preconditions: Be,
580
1372
  staticParameters: {
581
- direction: P.DOWN
1373
+ direction: ae.DOWN
582
1374
  }
583
- }, Qn = {
584
- id: x.id,
1375
+ }, Fi = {
1376
+ id: Fe.id,
585
1377
  description: "shortcut.doc.drawing-move-up",
586
1378
  group: "4_doc-drawing-view",
587
- binding: R.ARROW_UP,
1379
+ binding: ye.ARROW_UP,
588
1380
  priority: 100,
589
- preconditions: G,
1381
+ preconditions: Be,
590
1382
  staticParameters: {
591
- direction: P.UP
1383
+ direction: ae.UP
592
1384
  }
593
- }, Xn = {
594
- id: x.id,
1385
+ }, Bi = {
1386
+ id: Fe.id,
595
1387
  description: "shortcut.doc.drawing-move-left",
596
1388
  group: "4_doc-drawing-view",
597
- binding: R.ARROW_LEFT,
1389
+ binding: ye.ARROW_LEFT,
598
1390
  priority: 100,
599
- preconditions: G,
1391
+ preconditions: Be,
600
1392
  staticParameters: {
601
- direction: P.LEFT
1393
+ direction: ae.LEFT
602
1394
  }
603
- }, qn = {
604
- id: x.id,
1395
+ }, Gi = {
1396
+ id: Fe.id,
605
1397
  description: "shortcut.doc.drawing-move-right",
606
1398
  group: "4_doc-drawing-view",
607
- binding: R.ARROW_RIGHT,
1399
+ binding: ye.ARROW_RIGHT,
608
1400
  priority: 100,
609
- preconditions: G,
1401
+ preconditions: Be,
610
1402
  staticParameters: {
611
- direction: P.RIGHT
1403
+ direction: ae.RIGHT
612
1404
  }
613
- }, Jn = {
614
- id: ye.id,
1405
+ }, Wi = {
1406
+ id: tt.id,
615
1407
  description: "shortcut.doc.drawing-delete",
616
1408
  group: "4_doc-drawing-view",
617
1409
  // when focusing on any other input tag do not trigger this shortcut
618
- preconditions: G,
619
- binding: R.DELETE,
620
- mac: R.BACKSPACE
1410
+ preconditions: Be,
1411
+ binding: ye.DELETE,
1412
+ mac: ye.BACKSPACE
621
1413
  };
622
- var et = Object.defineProperty, nt = Object.getOwnPropertyDescriptor, tt = (e, n, t, r) => {
623
- for (var i = r > 1 ? void 0 : r ? nt(n, t) : n, o = e.length - 1, a; o >= 0; o--)
624
- (a = e[o]) && (i = (r ? a(n, t, i) : a(i)) || i);
625
- return r && i && et(n, t, i), i;
626
- }, T = (e, n) => (t, r) => n(t, r, e);
627
- let $ = class extends ue {
628
- constructor(e, n, t, r, i) {
629
- super(), this._injector = e, this._componentManager = n, this._menuService = t, this._commandService = r, this._shortcutService = i, this._init();
1414
+ var Hi = Object.defineProperty, Vi = Object.getOwnPropertyDescriptor, ji = (i, e, n, t) => {
1415
+ for (var o = t > 1 ? void 0 : t ? Vi(e, n) : e, r = i.length - 1, a; r >= 0; r--)
1416
+ (a = i[r]) && (o = (t ? a(e, n, o) : a(o)) || o);
1417
+ return t && o && Hi(e, n, o), o;
1418
+ }, Re = (i, e) => (n, t) => e(n, t, i);
1419
+ let qe = class extends Ue {
1420
+ constructor(i, e, n, t, o) {
1421
+ super(), this._injector = i, this._componentManager = e, this._menuService = n, this._commandService = t, this._shortcutService = o, this._init();
630
1422
  }
631
1423
  _initCustomComponents() {
632
- const e = this._componentManager;
633
- this.disposeWithMe(e.register(Pe, Me)), this.disposeWithMe(e.register(Oe, yn)), this.disposeWithMe(e.register(_e, Kn));
1424
+ const i = this._componentManager;
1425
+ this.disposeWithMe(i.register(Kn, Xn)), this.disposeWithMe(i.register(qn, mi)), this.disposeWithMe(i.register(Vn, Ai));
634
1426
  }
635
1427
  _initMenus() {
636
1428
  [
637
- bn,
638
- Rn
639
- ].forEach((e) => {
640
- this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e), {}));
1429
+ gi,
1430
+ pi
1431
+ ].forEach((i) => {
1432
+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(i), {}));
641
1433
  });
642
1434
  }
643
1435
  _initCommands() {
644
1436
  [
645
- z,
646
- Ne,
647
- X,
648
- q,
649
- we,
650
- w,
651
- Se,
652
- Ue,
653
- Re,
654
- x,
655
- ye,
656
- be
657
- ].forEach((e) => this.disposeWithMe(this._commandService.registerCommand(e)));
1437
+ rn,
1438
+ st,
1439
+ Zn,
1440
+ Qn,
1441
+ Jn,
1442
+ xe,
1443
+ et,
1444
+ nt,
1445
+ pn,
1446
+ ot,
1447
+ jn,
1448
+ Oe,
1449
+ kn,
1450
+ at,
1451
+ rt,
1452
+ Fe,
1453
+ tt,
1454
+ it
1455
+ ].forEach((i) => this.disposeWithMe(this._commandService.registerCommand(i)));
658
1456
  }
659
1457
  _initShortcuts() {
660
1458
  [
661
1459
  // sheet drawing shortcuts
662
- kn,
663
- Qn,
664
- Xn,
665
- qn,
666
- Jn
667
- ].forEach((e) => {
668
- this.disposeWithMe(this._shortcutService.registerShortcut(e));
1460
+ Li,
1461
+ Fi,
1462
+ Bi,
1463
+ Gi,
1464
+ Wi
1465
+ ].forEach((i) => {
1466
+ this.disposeWithMe(this._shortcutService.registerShortcut(i));
669
1467
  });
670
1468
  }
671
1469
  _init() {
672
1470
  this._initCommands(), this._initCustomComponents(), this._initMenus(), this._initShortcuts();
673
1471
  }
674
1472
  };
675
- $ = tt([
676
- se(ce.Ready, $),
677
- T(0, y(me)),
678
- T(1, y(ln)),
679
- T(2, gn),
680
- T(3, I),
681
- T(4, pn)
682
- ], $);
683
- var rt = Object.defineProperty, it = Object.getOwnPropertyDescriptor, ot = (e, n, t, r) => {
684
- for (var i = r > 1 ? void 0 : r ? it(n, t) : n, o = e.length - 1, a; o >= 0; o--)
685
- (a = e[o]) && (i = (r ? a(n, t, i) : a(i)) || i);
686
- return r && i && rt(n, t, i), i;
687
- }, D = (e, n) => (t, r) => n(t, r, e);
688
- let Y = class extends ue {
689
- constructor(e, n, t, r, i, o, a, s, c, u) {
690
- super(), this._context = e, this._commandService = n, this._textSelectionManagerService = t, this._docSkeletonManagerService = r, this._sheetDrawingService = i, this._imageIoService = o, this._drawingManagerService = a, this._contextService = s, this._messageService = c, this._localeService = u, this._initCommandListeners(), this._updateDrawingListener(), this._updateOrderListener(), this._groupDrawingListener(), this._focusDrawingListener();
1473
+ qe = ji([
1474
+ nn(tn.Ready, qe),
1475
+ Re(0, Se(Un)),
1476
+ Re(1, Se(Kt)),
1477
+ Re(2, Yt),
1478
+ Re(3, W),
1479
+ Re(4, Zt)
1480
+ ], qe);
1481
+ var ki = Object.defineProperty, $i = Object.getOwnPropertyDescriptor, zi = (i, e, n, t) => {
1482
+ for (var o = t > 1 ? void 0 : t ? $i(e, n) : e, r = i.length - 1, a; r >= 0; r--)
1483
+ (a = i[r]) && (o = (t ? a(e, n, o) : a(o)) || o);
1484
+ return t && o && ki(e, n, o), o;
1485
+ }, de = (i, e) => (n, t) => e(n, t, i);
1486
+ let ln = class extends Ue {
1487
+ constructor(i, e, n, t, o, r, a, s, l, c, m, u) {
1488
+ super(), this._context = i, this._commandService = e, this._textSelectionManagerService = n, this._renderManagerSrv = t, this._imageIoService = o, this._docDrawingService = r, this._drawingManagerService = a, this._contextService = s, this._messageService = l, this._localeService = c, this._textSelectionManager = m, this._textSelectionRenderManager = u, this._initCommandListeners(), this._updateDrawingListener(), this._updateOrderListener(), this._groupDrawingListener(), this._focusDrawingListener();
691
1489
  }
692
1490
  /**
693
1491
  * Upload image to cell or float image
694
1492
  */
695
1493
  _initCommandListeners() {
696
- this.disposeWithMe(this._commandService.onCommandExecuted(async (e) => {
697
- if (e.id === z.id) {
698
- const n = e.params;
699
- if (n.files == null)
700
- return;
701
- const t = n.files.length;
702
- if (t > ee) {
703
- this._messageService.show({
704
- type: W.Error,
705
- content: this._localeService.t("update-status.exceedMaxCount", String(ee))
706
- });
707
- return;
1494
+ this.disposeWithMe(
1495
+ this._commandService.onCommandExecuted(async (i) => {
1496
+ if (i.id === rn.id) {
1497
+ const e = i.params;
1498
+ if (e.files == null)
1499
+ return;
1500
+ const n = e.files.length;
1501
+ if (n > _n) {
1502
+ this._messageService.show({
1503
+ type: Ve.Error,
1504
+ content: this._localeService.t("update-status.exceedMaxCount", String(_n))
1505
+ });
1506
+ return;
1507
+ }
1508
+ this._imageIoService.setWaitCount(n), await this._insertFloatImages(e.files);
708
1509
  }
709
- this._imageIoService.setWaitCount(t), n.files.forEach(async (r) => {
710
- await this._insertFloatImage(r);
711
- });
712
- }
713
- }));
1510
+ })
1511
+ );
714
1512
  }
715
- async _insertFloatImage(e) {
716
- var g;
717
- let n;
1513
+ // eslint-disable-next-line max-lines-per-function
1514
+ async _insertFloatImages(i) {
1515
+ let e = [];
718
1516
  try {
719
- n = await this._imageIoService.saveImage(e);
720
- } catch (h) {
721
- const v = h.message;
722
- v === K.ERROR_EXCEED_SIZE ? this._messageService.show({
723
- type: W.Error,
724
- content: this._localeService.t("update-status.exceedMaxSize", String(en / (1024 * 1024)))
725
- }) : v === K.ERROR_IMAGE_TYPE ? this._messageService.show({
726
- type: W.Error,
1517
+ e = await Promise.all(i.map((o) => this._imageIoService.saveImage(o)));
1518
+ } catch (o) {
1519
+ const r = o.message;
1520
+ r === an.ERROR_EXCEED_SIZE ? this._messageService.show({
1521
+ type: Ve.Error,
1522
+ content: this._localeService.t("update-status.exceedMaxSize", String(Tt / (1024 * 1024)))
1523
+ }) : r === an.ERROR_IMAGE_TYPE ? this._messageService.show({
1524
+ type: Ve.Error,
727
1525
  content: this._localeService.t("update-status.invalidImageType")
728
- }) : v === K.ERROR_IMAGE && this._messageService.show({
729
- type: W.Error,
1526
+ }) : r === an.ERROR_IMAGE && this._messageService.show({
1527
+ type: Ve.Error,
730
1528
  content: this._localeService.t("update-status.invalidImage")
731
1529
  });
732
1530
  }
733
- if (n == null)
1531
+ if (e.length === 0)
734
1532
  return;
735
- const { unitId: t } = this._context, { imageId: r, imageSourceType: i, source: o, base64Cache: a } = n, { width: s, height: c, image: u } = await nn(a || "");
736
- this._imageIoService.addImageSourceCache(r, i, u);
737
- let m = 1;
738
- if (s > ne || c > te) {
739
- const h = ne / s, v = te / c;
740
- m = Math.max(h, v);
1533
+ const { unitId: n } = this._context, t = [];
1534
+ for (const o of e) {
1535
+ if (o == null)
1536
+ continue;
1537
+ const { imageId: r, imageSourceType: a, source: s, base64Cache: l } = o, { width: c, height: m, image: u } = await Mt(l || "");
1538
+ this._imageIoService.addImageSourceCache(r, a, u);
1539
+ let p = 1;
1540
+ if (c > Cn || m > Sn) {
1541
+ const w = Cn / c, v = Sn / m;
1542
+ p = Math.min(w, v);
1543
+ }
1544
+ const f = this._getImagePosition(c * p, m * p);
1545
+ if (f == null)
1546
+ return;
1547
+ const g = {
1548
+ unitId: n,
1549
+ subUnitId: n,
1550
+ drawingId: r,
1551
+ drawingType: un.DRAWING_IMAGE,
1552
+ imageSourceType: a,
1553
+ source: s,
1554
+ transform: Tn(f),
1555
+ docTransform: f,
1556
+ behindDoc: Me.FALSE,
1557
+ title: "",
1558
+ description: "",
1559
+ layoutType: B.INLINE,
1560
+ wrapText: Ae.BOTH_SIDES,
1561
+ distB: 0,
1562
+ distL: 0,
1563
+ distR: 0,
1564
+ distT: 0
1565
+ };
1566
+ t.push(g);
741
1567
  }
742
- const d = this._getImagePosition(s * m, c * m);
743
- if (d == null)
744
- return;
745
- const l = {
746
- unitId: t,
747
- subUnitId: t,
748
- drawingId: r,
749
- drawingType: Q.DRAWING_IMAGE,
750
- imageSourceType: i,
751
- source: o,
752
- transform: ie(d),
753
- docTransform: d,
754
- title: "",
755
- description: "",
756
- layoutType: Ve.WRAP_SQUARE
757
- };
758
- this._commandService.executeCommand(Ne.id, {
759
- unitId: t,
760
- drawings: [l]
761
- }), (g = this._docSkeletonManagerService.getSkeleton()) == null || g.calculate();
1568
+ this._commandService.executeCommand(st.id, {
1569
+ unitId: n,
1570
+ drawings: t
1571
+ });
762
1572
  }
763
- _getImagePosition(e, n) {
764
- const t = this._textSelectionManagerService.getActiveTextRange(), r = (t == null ? void 0 : t.getAbsolutePosition()) || {
1573
+ _getImagePosition(i, e) {
1574
+ const n = this._textSelectionManagerService.getActiveTextRange(), t = (n == null ? void 0 : n.getAbsolutePosition()) || {
765
1575
  left: 0,
766
1576
  top: 0
767
1577
  };
768
1578
  return {
769
1579
  size: {
770
- width: e,
771
- height: n
1580
+ width: i,
1581
+ height: e
772
1582
  },
773
1583
  positionH: {
774
- relativeFrom: Be.MARGIN,
775
- posOffset: r.left
1584
+ relativeFrom: Y.PAGE,
1585
+ posOffset: t.left
776
1586
  },
777
1587
  positionV: {
778
- relativeFrom: He.PAGE,
779
- posOffset: r.top
1588
+ relativeFrom: G.MARGIN,
1589
+ posOffset: t.top
780
1590
  },
781
1591
  angle: 0
782
1592
  };
783
1593
  }
784
1594
  _updateOrderListener() {
785
- this._drawingManagerService.featurePluginOrderUpdate$.subscribe((e) => {
786
- const { unitId: n, subUnitId: t, drawingIds: r, arrangeType: i } = e;
787
- this._commandService.executeCommand(be.id, {
788
- unitId: n,
789
- subUnitId: t,
790
- drawingIds: r,
791
- arrangeType: i
1595
+ this._drawingManagerService.featurePluginOrderUpdate$.subscribe((i) => {
1596
+ const { unitId: e, subUnitId: n, drawingIds: t, arrangeType: o } = i;
1597
+ this._commandService.executeCommand(it.id, {
1598
+ unitId: e,
1599
+ subUnitId: n,
1600
+ drawingIds: t,
1601
+ arrangeType: o
792
1602
  });
793
1603
  });
794
1604
  }
795
1605
  _updateDrawingListener() {
796
- this._drawingManagerService.featurePluginUpdate$.subscribe((e) => {
797
- if (e.length === 0)
1606
+ this._drawingManagerService.featurePluginUpdate$.subscribe((i) => {
1607
+ if (i.length === 0)
798
1608
  return;
799
- const n = [];
800
- if (e.forEach((t) => {
801
- const { unitId: r, subUnitId: i, drawingId: o, transform: a } = t;
1609
+ const e = [];
1610
+ if (i.forEach((n) => {
1611
+ const { unitId: t, subUnitId: o, drawingId: r, transform: a } = n;
802
1612
  if (a == null)
803
1613
  return;
804
- const s = this._sheetDrawingService.getDrawingByParam({ unitId: r, subUnitId: i, drawingId: o });
1614
+ const s = this._docDrawingService.getDrawingByParam({ unitId: t, subUnitId: o, drawingId: r });
805
1615
  if (s == null)
806
1616
  return;
807
- const c = le({ ...s.transform, ...a });
808
- if (c == null)
1617
+ const l = Vt({ ...s.transform, ...a });
1618
+ if (l == null)
809
1619
  return;
810
- const u = {
811
- ...t,
812
- transform: { ...a, ...ie(c) },
813
- docTransform: { ...c }
1620
+ const c = {
1621
+ ...n,
1622
+ transform: { ...a, ...Tn(l) },
1623
+ docTransform: { ...l }
814
1624
  };
815
- n.push(u);
816
- }), n.length > 0) {
817
- const t = e[0].unitId;
818
- this._commandService.syncExecuteCommand(q.id, {
819
- unitId: t,
820
- drawings: n
1625
+ e.push(c);
1626
+ }), e.length > 0) {
1627
+ const n = i[0].unitId;
1628
+ this._commandService.syncExecuteCommand(ot.id, {
1629
+ unitId: n,
1630
+ drawings: e
821
1631
  }), this._refreshDocSkeleton();
822
1632
  }
823
1633
  });
824
1634
  }
825
1635
  _refreshDocSkeleton() {
826
- const e = this._docSkeletonManagerService.getSkeleton(), { mainComponent: n } = this._context;
827
- e == null || e.calculate(), n == null || n.makeDirty();
1636
+ var t;
1637
+ const { mainComponent: i, unitId: e } = this._context, n = (t = this._renderManagerSrv.getRenderById(e)) == null ? void 0 : t.with(me).getSkeleton();
1638
+ n == null || n.calculate(), i == null || i.makeDirty();
828
1639
  }
829
1640
  _groupDrawingListener() {
830
- this._drawingManagerService.featurePluginGroupUpdate$.subscribe((e) => {
831
- this._commandService.executeCommand(Ue.id, e);
832
- }), this._drawingManagerService.featurePluginUngroupUpdate$.subscribe((e) => {
833
- this._commandService.executeCommand(Re.id, e);
1641
+ this._drawingManagerService.featurePluginGroupUpdate$.subscribe((i) => {
1642
+ this._commandService.executeCommand(at.id, i);
1643
+ }), this._drawingManagerService.featurePluginUngroupUpdate$.subscribe((i) => {
1644
+ this._commandService.executeCommand(rt.id, i);
834
1645
  });
835
1646
  }
1647
+ _getCurrentSceneAndTransformer() {
1648
+ const { scene: i, mainComponent: e } = this._context;
1649
+ if (i == null || e == null)
1650
+ return;
1651
+ const n = i.getTransformerByCreate(), { docsLeft: t, docsTop: o } = e.getOffsetConfig();
1652
+ return { scene: i, transformer: n, docsLeft: t, docsTop: o };
1653
+ }
836
1654
  _focusDrawingListener() {
837
1655
  this.disposeWithMe(
838
- this._drawingManagerService.focus$.subscribe((e) => {
839
- e == null || e.length === 0 ? (this._contextService.setContextValue(V, !1), this._sheetDrawingService.focusDrawing([])) : (this._contextService.setContextValue(V, !0), this._sheetDrawingService.focusDrawing(e));
1656
+ this._drawingManagerService.focus$.subscribe((i) => {
1657
+ var o;
1658
+ const { transformer: e, docsLeft: n, docsTop: t } = (o = this._getCurrentSceneAndTransformer()) != null ? o : {};
1659
+ i == null || i.length === 0 ? (this._contextService.setContextValue(Ze, !1), this._docDrawingService.focusDrawing([]), e && e.resetProps({
1660
+ zeroTop: 0,
1661
+ zeroLeft: 0
1662
+ })) : (this._contextService.setContextValue(Ze, !0), this._docDrawingService.focusDrawing(i), this._textSelectionManager.replaceTextRanges([]), e && e.resetProps({
1663
+ zeroTop: t,
1664
+ zeroLeft: n
1665
+ }));
1666
+ })
1667
+ );
1668
+ }
1669
+ };
1670
+ ln = zi([
1671
+ de(1, W),
1672
+ de(2, Se(cn)),
1673
+ de(3, Q),
1674
+ de(4, yt),
1675
+ de(5, De),
1676
+ de(6, ge),
1677
+ de(7, xn),
1678
+ de(8, Qt),
1679
+ de(9, Se(en)),
1680
+ de(10, Se(cn)),
1681
+ de(11, Le)
1682
+ ], ln);
1683
+ var Xi = Object.defineProperty, qi = Object.getOwnPropertyDescriptor, Ki = (i, e, n, t) => {
1684
+ for (var o = t > 1 ? void 0 : t ? qi(e, n) : e, r = i.length - 1, a; r >= 0; r--)
1685
+ (a = i[r]) && (o = (t ? a(e, n, o) : a(o)) || o);
1686
+ return t && o && Xi(e, n, o), o;
1687
+ }, $e = (i, e) => (n, t) => e(n, t, i);
1688
+ let dn = class extends Ue {
1689
+ constructor(e, n, t, o, r) {
1690
+ super();
1691
+ Pe(this, "_liquid", new Ln());
1692
+ this._context = e, this._docSkeletonManagerService = n, this._commandService = t, this._editorService = o, this._drawingManagerService = r, this._initialize(), this._commandExecutedListener();
1693
+ }
1694
+ _initialize() {
1695
+ this._initialRenderRefresh();
1696
+ }
1697
+ _initialRenderRefresh() {
1698
+ const { mainComponent: e } = this._context;
1699
+ this._docSkeletonManagerService.currentSkeleton$.subscribe((n) => {
1700
+ if (n == null)
1701
+ return;
1702
+ e.changeSkeleton(n), this._refreshDrawing(n);
1703
+ });
1704
+ }
1705
+ _commandExecutedListener() {
1706
+ const e = [Z.id, kt.id];
1707
+ this.disposeWithMe(
1708
+ this._commandService.onCommandExecuted((n) => {
1709
+ if (e.includes(n.id)) {
1710
+ const t = n.params, { unitId: o } = t, { unitId: r, mainComponent: a } = this._context;
1711
+ if (o !== r)
1712
+ return;
1713
+ const s = this._docSkeletonManagerService.getSkeleton();
1714
+ if (s == null)
1715
+ return;
1716
+ if (this._editorService.isEditor(r)) {
1717
+ a == null || a.makeDirty();
1718
+ return;
1719
+ }
1720
+ this._refreshDrawing(s);
1721
+ }
840
1722
  })
841
1723
  );
842
1724
  }
1725
+ _refreshDrawing(e) {
1726
+ var w, v;
1727
+ const n = e == null ? void 0 : e.getSkeletonData(), { mainComponent: t, unitId: o } = this._context, r = t;
1728
+ if (!n)
1729
+ return;
1730
+ const { left: a, top: s, pageLayoutType: l, pageMarginLeft: c, pageMarginTop: m } = r, { pages: u, skeHeaders: p, skeFooters: f } = n, g = [];
1731
+ this._liquid.reset();
1732
+ for (let I = 0, C = u.length; I < C; I++) {
1733
+ const P = u[I], { headerId: S, footerId: O, pageWidth: R } = P;
1734
+ if (S) {
1735
+ const D = (w = p.get(S)) == null ? void 0 : w.get(R);
1736
+ D && this._calculateDrawingPosition(o, D, a, s, g);
1737
+ }
1738
+ if (O) {
1739
+ const D = (v = f.get(O)) == null ? void 0 : v.get(R);
1740
+ D && this._calculateDrawingPosition(o, D, a, s, g);
1741
+ }
1742
+ this._calculateDrawingPosition(o, P, a, s, g), this._liquid.translatePage(P, l, c, m);
1743
+ }
1744
+ g.length > 0 && this._drawingManagerService.refreshTransform(g);
1745
+ }
1746
+ _calculateDrawingPosition(e, n, t, o, r) {
1747
+ const { skeDrawings: a } = n;
1748
+ this._liquid.translatePagePadding(n), a.forEach((s) => {
1749
+ const { aLeft: l, aTop: c, height: m, width: u, angle: p, drawingId: f, drawingOrigin: g } = s, w = g.layoutType === B.WRAP_NONE && g.behindDoc === Me.TRUE;
1750
+ r.push({
1751
+ unitId: e,
1752
+ subUnitId: e,
1753
+ drawingId: f,
1754
+ behindText: w,
1755
+ transform: {
1756
+ left: l + t + this._liquid.x,
1757
+ top: c + o + this._liquid.y,
1758
+ width: u,
1759
+ height: m,
1760
+ angle: p
1761
+ }
1762
+ });
1763
+ }), this._liquid.restorePagePadding(n);
1764
+ }
843
1765
  };
844
- Y = ot([
845
- D(1, I),
846
- D(2, y(hn)),
847
- D(3, y(vn)),
848
- D(4, M),
849
- D(5, tn),
850
- D(6, N),
851
- D(7, de),
852
- D(8, fn),
853
- D(9, y(k))
854
- ], Y);
855
- var Ae = Object.defineProperty, at = Object.getOwnPropertyDescriptor, st = (e, n, t) => n in e ? Ae(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t, ct = (e, n, t, r) => {
856
- for (var i = r > 1 ? void 0 : r ? at(n, t) : n, o = e.length - 1, a; o >= 0; o--)
857
- (a = e[o]) && (i = (r ? a(n, t, i) : a(i)) || i);
858
- return r && i && Ae(n, t, i), i;
859
- }, ae = (e, n) => (t, r) => n(t, r, e), Te = (e, n, t) => st(e, typeof n != "symbol" ? n + "" : n, t);
860
- const dt = "DOCS_DRAWING_UI_PLUGIN";
861
- let B = class extends ze {
862
- constructor(e, n, t) {
863
- super(), this._injector = n, this._renderManagerSrv = t;
864
- }
865
- onStarting(e) {
1766
+ dn = Ki([
1767
+ $e(1, Se(me)),
1768
+ $e(2, W),
1769
+ $e(3, Jt),
1770
+ $e(4, ge)
1771
+ ], dn);
1772
+ var Yi = Object.defineProperty, Zi = Object.getOwnPropertyDescriptor, Qi = (i, e, n, t) => {
1773
+ for (var o = t > 1 ? void 0 : t ? Zi(e, n) : e, r = i.length - 1, a; r >= 0; r--)
1774
+ (a = i[r]) && (o = (t ? a(e, n, o) : a(o)) || o);
1775
+ return t && o && Yi(e, n, o), o;
1776
+ }, Ne = (i, e) => (n, t) => e(n, t, i);
1777
+ function Ji(i) {
1778
+ var t, o, r, a;
1779
+ if (k.isNoop(i) || !Array.isArray(i))
1780
+ return null;
1781
+ const e = i.find((s) => Array.isArray(s) && (s == null ? void 0 : s[0]) === "drawings");
1782
+ if (e == null || !Array.isArray(e) || e.length < 3 || typeof e[1] == "string" && typeof e[2] != "object" || Array.isArray(e[1]) && typeof e[1][1] != "object")
1783
+ return null;
1784
+ const n = [];
1785
+ if (Array.isArray(e == null ? void 0 : e[1]))
1786
+ for (const s of e)
1787
+ Array.isArray(s) && n.push({
1788
+ type: (t = s == null ? void 0 : s[1]) != null && t.i ? "add" : "remove",
1789
+ drawingId: s == null ? void 0 : s[0],
1790
+ drawing: (o = s == null ? void 0 : s[1]) == null ? void 0 : o.i
1791
+ });
1792
+ else
1793
+ n.push({
1794
+ type: (r = e[2]) != null && r.i ? "add" : "remove",
1795
+ drawingId: e[1],
1796
+ drawing: (a = e[2]) == null ? void 0 : a.i
1797
+ });
1798
+ return n;
1799
+ }
1800
+ function eo(i) {
1801
+ if (!Array.isArray(i) || i.length < 3 || i[0] !== "drawingsOrder")
1802
+ return [];
1803
+ const e = [];
1804
+ for (let n = 1; n < i.length; n++) {
1805
+ const t = i[n];
1806
+ if (Array.isArray(t) && typeof t[0] == "number" && typeof t[1] == "object")
1807
+ e.push(t[0]);
1808
+ else {
1809
+ e.length = 0;
1810
+ break;
1811
+ }
1812
+ }
1813
+ return e;
1814
+ }
1815
+ let Ke = class extends Ue {
1816
+ constructor(i, e, n, t, o) {
1817
+ super(), this._univerInstanceService = i, this._commandService = e, this._drawingManagerService = n, this._docDrawingService = t, this._renderManagerService = o, this._initialize();
1818
+ }
1819
+ _initialize() {
1820
+ this._commandExecutedListener();
1821
+ }
1822
+ _commandExecutedListener() {
1823
+ this.disposeWithMe(
1824
+ this._commandService.beforeCommandExecuted((i) => {
1825
+ if (i.id !== Z.id)
1826
+ return;
1827
+ const e = i.params, { unitId: n, actions: t } = e, o = Ji(t);
1828
+ if (o != null)
1829
+ for (const { type: r, drawingId: a, drawing: s } of o)
1830
+ r === "add" ? this._addDrawings(n, [s]) : this._removeDrawings(n, [a]);
1831
+ })
1832
+ ), this.disposeWithMe(
1833
+ this._commandService.onCommandExecuted((i) => {
1834
+ if (i.id !== Z.id)
1835
+ return;
1836
+ const e = i.params, { unitId: n, actions: t } = e;
1837
+ eo(t).length > 0 && this._updateDrawingsOrder(n);
1838
+ })
1839
+ ), this.disposeWithMe(
1840
+ this._commandService.onCommandExecuted((i) => {
1841
+ var a;
1842
+ if (i.id !== ft.id && i.id !== ht.id)
1843
+ return;
1844
+ const e = (a = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : a.getUnitId(), n = this._drawingManagerService.getFocusDrawings();
1845
+ if (e == null || n.length === 0)
1846
+ return;
1847
+ const t = this._renderManagerService.getRenderById(e), o = t == null ? void 0 : t.scene;
1848
+ if (o == null)
1849
+ return !1;
1850
+ o.getTransformerByCreate().refreshControls();
1851
+ })
1852
+ );
1853
+ }
1854
+ _addDrawings(i, e) {
1855
+ const n = this._drawingManagerService, t = this._docDrawingService, o = this._docDrawingService.getBatchAddOp(e), { subUnitId: r, redo: a, objects: s } = o;
1856
+ n.applyJson1(i, r, a), t.applyJson1(i, r, a), n.addNotification(s), t.addNotification(s);
1857
+ }
1858
+ _removeDrawings(i, e) {
1859
+ const n = this._drawingManagerService, t = this._docDrawingService, o = this._docDrawingService.getBatchRemoveOp(e.map((l) => ({
1860
+ unitId: i,
1861
+ subUnitId: i,
1862
+ drawingId: l
1863
+ }))), { subUnitId: r, redo: a, objects: s } = o;
1864
+ n.applyJson1(i, r, a), t.applyJson1(i, r, a), n.removeNotification(s), t.removeNotification(s);
1865
+ }
1866
+ _updateDrawingsOrder(i) {
1867
+ const e = this._univerInstanceService.getUniverDocInstance(i);
1868
+ if (e == null)
1869
+ return;
1870
+ const n = e.getSnapshot().drawingsOrder;
1871
+ if (n == null)
1872
+ return;
1873
+ const t = this._drawingManagerService, o = this._docDrawingService;
1874
+ t.setDrawingOrder(i, i, n), o.setDrawingOrder(i, i, n);
1875
+ const r = {
1876
+ unitId: i,
1877
+ subUnitId: i,
1878
+ drawingIds: n
1879
+ };
1880
+ t.orderNotification(r), o.orderNotification(r);
1881
+ }
1882
+ };
1883
+ Ke = Qi([
1884
+ nn(tn.Steady, Ke),
1885
+ Ne(0, X),
1886
+ Ne(1, W),
1887
+ Ne(2, ge),
1888
+ Ne(3, De),
1889
+ Ne(4, Q)
1890
+ ], Ke);
1891
+ var no = Object.defineProperty, to = Object.getOwnPropertyDescriptor, io = (i, e, n, t) => {
1892
+ for (var o = t > 1 ? void 0 : t ? to(e, n) : e, r = i.length - 1, a; r >= 0; r--)
1893
+ (a = i[r]) && (o = (t ? a(e, n, o) : a(o)) || o);
1894
+ return t && o && no(e, n, o), o;
1895
+ }, ze = (i, e) => (n, t) => e(n, t, i);
1896
+ const oo = "__InlineDrawingAnchor__";
1897
+ let Ye = class extends Ue {
1898
+ constructor(e, n, t, o) {
1899
+ super();
1900
+ Pe(this, "_liquid", new Ln());
1901
+ Pe(this, "_listenerOnImageMap", /* @__PURE__ */ new Set());
1902
+ // Use to cache the drawings is under transforming or scaling.
1903
+ Pe(this, "_transformerCache", /* @__PURE__ */ new Map());
1904
+ Pe(this, "_anchorShape");
1905
+ this._commandService = e, this._univerInstanceService = n, this._drawingManagerService = t, this._renderManagerService = o, this._init();
1906
+ }
1907
+ _init() {
1908
+ this._listenDrawingFocus();
1909
+ }
1910
+ _listenDrawingFocus() {
1911
+ this.disposeWithMe(
1912
+ this._drawingManagerService.add$.subscribe((e) => {
1913
+ if (e.length !== 0)
1914
+ for (const n of e) {
1915
+ const { unitId: t } = n;
1916
+ this._listenerOnImageMap.has(t) || (this._listenTransformerChange(t), this._listenerOnImageMap.add(t));
1917
+ }
1918
+ })
1919
+ );
1920
+ }
1921
+ // Only handle one drawing transformer change.
1922
+ // eslint-disable-next-line max-lines-per-function
1923
+ _listenTransformerChange(e) {
1924
+ var o;
1925
+ const n = (o = this._getSceneAndTransformerByDrawingSearch(e)) == null ? void 0 : o.transformer;
1926
+ if (n == null)
1927
+ return;
1928
+ this.disposeWithMe(
1929
+ Ee(
1930
+ n.changeStart$.subscribe((r) => {
1931
+ var s;
1932
+ this._transformerCache.clear();
1933
+ const { objects: a } = r;
1934
+ for (const l of a.values()) {
1935
+ const { oKey: c, width: m, height: u, left: p, top: f, angle: g } = l, w = this._drawingManagerService.getDrawingOKey(c);
1936
+ if (w == null)
1937
+ continue;
1938
+ const v = this._univerInstanceService.getUniverDocInstance(w.unitId), I = (s = v == null ? void 0 : v.getSnapshot().drawings) == null ? void 0 : s[w.drawingId];
1939
+ (I == null ? void 0 : I.layoutType) === B.INLINE && l.setOpacity(0.2), I != null && this._transformerCache.set(w.drawingId, {
1940
+ drawing: I,
1941
+ top: f,
1942
+ left: p,
1943
+ width: m,
1944
+ height: u,
1945
+ angle: g
1946
+ });
1947
+ }
1948
+ })
1949
+ )
1950
+ );
1951
+ const t = In(this._updateMultipleDrawingDocTransform.bind(this), 50);
1952
+ In(this._nonInlineDrawingTransform.bind(this), 50), this.disposeWithMe(
1953
+ Ee(
1954
+ n.changing$.subscribe((r) => {
1955
+ const { objects: a, offsetX: s, offsetY: l } = r;
1956
+ if (a.size > 1)
1957
+ t(a);
1958
+ else if (a.size === 1) {
1959
+ const c = this._transformerCache.values().next().value, m = a.values().next().value, { width: u, height: p, top: f, left: g, angle: w } = m;
1960
+ if (u === c.width && p === c.height && f === c.top && g === c.left && w === c.angle)
1961
+ return;
1962
+ c && (c.drawing.layoutType, B.INLINE), c && c.drawing.layoutType === B.INLINE && s != null && l != null && this._updateInlineDrawingAnchor(c.drawing, s, l);
1963
+ }
1964
+ })
1965
+ )
1966
+ ), this.disposeWithMe(
1967
+ Ee(
1968
+ n.changeEnd$.subscribe((r) => {
1969
+ const { objects: a, offsetX: s, offsetY: l } = r;
1970
+ for (const c of a.values()) {
1971
+ const m = this._drawingManagerService.getDrawingOKey(c.oKey);
1972
+ if (m == null)
1973
+ continue;
1974
+ const u = this._transformerCache.get(m == null ? void 0 : m.drawingId);
1975
+ (u == null ? void 0 : u.drawing.layoutType) === B.INLINE && c.setOpacity(1);
1976
+ }
1977
+ if (this._anchorShape && this._anchorShape.hide(), a.size > 1)
1978
+ this._updateMultipleDrawingDocTransform(a);
1979
+ else if (a.size === 1) {
1980
+ const c = this._transformerCache.values().next().value, m = a.values().next().value, { width: u, height: p, top: f, left: g, angle: w } = m;
1981
+ if (u === c.width && p === c.height && f === c.top && g === c.left && w === c.angle)
1982
+ return;
1983
+ c && c.drawing.layoutType === B.INLINE ? u !== c.width || p !== c.height || w !== c.angle ? this._updateDrawingSize(c, m) : s != null && l != null && this._moveInlineDrawing(c.drawing, s, l) : c && this._nonInlineDrawingTransform(c.drawing, m);
1984
+ }
1985
+ this._transformerCache.clear();
1986
+ })
1987
+ )
1988
+ );
1989
+ }
1990
+ // eslint-disable-next-line max-lines-per-function
1991
+ _updateMultipleDrawingDocTransform(e) {
1992
+ if (e.size < 1)
1993
+ return;
1994
+ const n = [];
1995
+ let t, o;
1996
+ for (const r of e.values()) {
1997
+ const { oKey: a, left: s, top: l, angle: c } = r;
1998
+ let { width: m, height: u } = r;
1999
+ const p = this._drawingManagerService.getDrawingOKey(a);
2000
+ if (p == null)
2001
+ continue;
2002
+ t == null && (t = p.unitId), o == null && (o = p.subUnitId);
2003
+ const f = this._transformerCache.get(p.drawingId);
2004
+ if (f == null)
2005
+ continue;
2006
+ const { drawing: g, top: w, left: v, width: I, height: C, angle: P } = f, { width: S, height: O } = this._getPageContentSize(g);
2007
+ if (m = Math.min(m, S), u = Math.min(u, O), (I !== m || C !== u) && n.push({
2008
+ drawingId: p.drawingId,
2009
+ key: "size",
2010
+ value: {
2011
+ width: m,
2012
+ height: u
2013
+ }
2014
+ }), P !== c && n.push({
2015
+ drawingId: p.drawingId,
2016
+ key: "angle",
2017
+ value: c
2018
+ }), w !== l || v !== s) {
2019
+ const R = l - w, D = s - v;
2020
+ R !== 0 && n.push({
2021
+ drawingId: p.drawingId,
2022
+ key: "positionV",
2023
+ value: {
2024
+ relativeFrom: g.docTransform.positionV.relativeFrom,
2025
+ posOffset: g.docTransform.positionV.posOffset + R
2026
+ }
2027
+ }), D !== 0 && n.push({
2028
+ drawingId: p.drawingId,
2029
+ key: "positionH",
2030
+ value: {
2031
+ relativeFrom: g.docTransform.positionH.relativeFrom,
2032
+ posOffset: g.docTransform.positionH.posOffset + D
2033
+ }
2034
+ });
2035
+ }
2036
+ }
2037
+ n.length > 0 && t && o && this._commandService.executeCommand(xe.id, {
2038
+ unitId: t,
2039
+ subUnitId: o,
2040
+ drawings: n
2041
+ });
2042
+ }
2043
+ // TODO: @JOCS, Use to draw and update the drawing anchor.
2044
+ _updateDrawingAnchor(e) {
2045
+ if (this._transformerCache.size !== 1)
2046
+ return;
2047
+ const n = this._transformerCache.values().next().value, t = e.values().next().value;
2048
+ this._getDrawingAnchor(n.drawing, t);
2049
+ }
2050
+ _updateInlineDrawingAnchor(e, n, t) {
2051
+ var r;
2052
+ if (this._transformerCache.size !== 1)
2053
+ return;
2054
+ const { contentBoxPointGroup: o } = (r = this._getInlineDrawingAnchor(e, n, t)) != null ? r : {};
2055
+ o != null && this._createOrUpdateInlineAnchor(e.unitId, o);
2056
+ }
2057
+ _getInlineDrawingAnchor(e, n, t) {
2058
+ var V;
2059
+ const o = this._renderManagerService.getRenderById(e.unitId), r = o == null ? void 0 : o.with(me).getSkeleton();
2060
+ if (o == null)
2061
+ return;
2062
+ const { mainComponent: a, scene: s } = o, l = a, c = s.getViewports()[0], {
2063
+ pageLayoutType: m = Dn.VERTICAL,
2064
+ pageMarginLeft: u,
2065
+ pageMarginTop: p
2066
+ } = l.getOffsetConfig();
2067
+ let f = null, g = !1, w = -1;
2068
+ const v = 0.5, I = this._getTransformCoordForDocumentOffset(l, c, n, t);
2069
+ if (I == null)
2070
+ return;
2071
+ const C = r == null ? void 0 : r.findNodeByCoord(I, m, u, p);
2072
+ if (C) {
2073
+ const { node: x, ratioX: L, segmentPage: z } = C;
2074
+ g = L < v, f = x, w = z;
2075
+ }
2076
+ if (f == null)
2077
+ return;
2078
+ const P = r == null ? void 0 : r.findPositionByGlyph(f, w), S = this._getDocObject();
2079
+ if (P == null || r == null || S == null)
2080
+ return;
2081
+ const O = {
2082
+ ...P,
2083
+ isBack: g
2084
+ }, R = S.document.getOffsetConfig(), D = new Pn(R, r), { cursorList: b, contentBoxPointGroup: y } = D.getRangePointData(O, O), { startOffset: T } = (V = En(b)) != null ? V : {};
2085
+ if (T != null)
2086
+ return { offset: T, contentBoxPointGroup: y };
2087
+ }
2088
+ // eslint-disable-next-line max-lines-per-function, complexity
2089
+ _getDrawingAnchor(e, n) {
2090
+ var ee, we, ve, ne;
2091
+ const t = this._renderManagerService.getRenderById(e.unitId), o = t == null ? void 0 : t.with(me).getSkeleton(), r = o == null ? void 0 : o.getViewModel(), a = o == null ? void 0 : o.getSkeletonData();
2092
+ if (a == null || t == null || r == null)
2093
+ return;
2094
+ const { pages: s } = a, { mainComponent: l, scene: c } = t, m = l, u = c.getViewports()[0], { pageLayoutType: p = Dn.VERTICAL, pageMarginLeft: f, pageMarginTop: g, docsLeft: w, docsTop: v } = m.getOffsetConfig(), { left: I, top: C, angle: P } = n;
2095
+ let { width: S, height: O } = n;
2096
+ const { positionV: R, positionH: D } = e.docTransform, { width: b, height: y } = this._getPageContentSize(e);
2097
+ S = Math.min(S, b), O = Math.min(O, y);
2098
+ let T = null, V = -1;
2099
+ const x = !1, L = {
2100
+ ...e.docTransform,
2101
+ size: {
2102
+ width: S,
2103
+ height: O
2104
+ },
2105
+ angle: P
2106
+ }, { x: z, y: N } = c.getViewportScrollXY(u), _ = this._getTransformCoordForDocumentOffset(m, u, I - z, C - N);
2107
+ if (_ == null)
2108
+ return;
2109
+ const M = o == null ? void 0 : o.findNodeByCoord(_, p, f, g);
2110
+ if (M) {
2111
+ const { node: le, segmentPage: Ge } = M;
2112
+ T = le, V = Ge;
2113
+ }
2114
+ if (T == null)
2115
+ return;
2116
+ const E = (ee = T.parent) == null ? void 0 : ee.parent, A = E == null ? void 0 : E.parent, U = (we = A == null ? void 0 : A.lines.find((le) => le.paragraphIndex === (E == null ? void 0 : E.paragraphIndex) && le.paragraphStart)) != null ? we : A == null ? void 0 : A.lines[0], F = (ve = A == null ? void 0 : A.parent) == null ? void 0 : ve.parent;
2117
+ this._liquid.reset();
2118
+ for (const le of s) {
2119
+ if (this._liquid.translatePagePadding(le), le === F)
2120
+ break;
2121
+ this._liquid.restorePagePadding(le), this._liquid.translatePage(le, p, f, g);
2122
+ }
2123
+ if (E == null || A == null || U == null || F == null)
2124
+ return;
2125
+ switch (R.relativeFrom === G.LINE ? T = E.divides[0].glyphGroup[0] : T = U.divides[0].glyphGroup[0], L.positionH = {
2126
+ relativeFrom: D.relativeFrom,
2127
+ posOffset: I - this._liquid.x - w
2128
+ }, D.relativeFrom) {
2129
+ case Y.MARGIN: {
2130
+ L.positionH.posOffset = I - this._liquid.x - w - F.marginLeft;
2131
+ break;
2132
+ }
2133
+ case Y.COLUMN: {
2134
+ L.positionH.posOffset = I - this._liquid.x - w - A.left;
2135
+ break;
2136
+ }
2137
+ }
2138
+ switch (L.positionV = {
2139
+ relativeFrom: R.relativeFrom,
2140
+ posOffset: C - this._liquid.y - v
2141
+ }, R.relativeFrom) {
2142
+ case G.PAGE: {
2143
+ L.positionV.posOffset = C - this._liquid.y - v - F.marginTop;
2144
+ break;
2145
+ }
2146
+ case G.LINE: {
2147
+ L.positionV.posOffset = C - this._liquid.y - v - E.top;
2148
+ break;
2149
+ }
2150
+ case G.PARAGRAPH: {
2151
+ L.positionV.posOffset = C - this._liquid.y - v - U.top;
2152
+ break;
2153
+ }
2154
+ }
2155
+ if (T == null)
2156
+ return;
2157
+ const q = o == null ? void 0 : o.findPositionByGlyph(T, V), J = this._getDocObject();
2158
+ if (q == null || o == null || J == null)
2159
+ return;
2160
+ const ue = {
2161
+ ...q,
2162
+ isBack: x
2163
+ }, ce = J.document.getOffsetConfig(), pe = new Pn(ce, o), { cursorList: oe } = pe.getRangePointData(ue, ue), { startOffset: K } = (ne = En(oe)) != null ? ne : {};
2164
+ if (K != null)
2165
+ return { offset: K, docTransform: L };
2166
+ }
2167
+ // Update drawing when use transformer to resize it.
2168
+ _updateDrawingSize(e, n) {
2169
+ const t = [], { drawing: o, width: r, height: a, angle: s } = e, { unitId: l, subUnitId: c } = o;
2170
+ let { width: m, height: u, angle: p } = n;
2171
+ const { width: f, height: g } = this._getPageContentSize(o);
2172
+ m = Math.min(f, m), u = Math.min(g, u), (m !== r || u !== a) && t.push({
2173
+ drawingId: o.drawingId,
2174
+ key: "size",
2175
+ value: {
2176
+ width: m,
2177
+ height: u
2178
+ }
2179
+ }), p !== s && t.push({
2180
+ drawingId: o.drawingId,
2181
+ key: "angle",
2182
+ value: p
2183
+ }), t.length > 0 && l && c && this._commandService.executeCommand(xe.id, {
2184
+ unitId: l,
2185
+ subUnitId: c,
2186
+ drawings: t
2187
+ });
2188
+ }
2189
+ // Update inline drawing when use transformer to move it.
2190
+ _moveInlineDrawing(e, n, t) {
2191
+ const o = this._getInlineDrawingAnchor(e, n, t), { offset: r } = o != null ? o : {};
2192
+ if (r != null)
2193
+ return this._commandService.executeCommand(et.id, {
2194
+ unitId: e.unitId,
2195
+ subUnitId: e.unitId,
2196
+ drawing: e,
2197
+ offset: r
2198
+ });
2199
+ }
2200
+ // Limit the drawing to the page area, mainly in the vertical direction,
2201
+ // and the upper and lower limits cannot exceed the page margin area.
2202
+ _limitDrawingInPage(e, n) {
2203
+ const t = this._renderManagerService.getRenderById(e.unitId), { left: o, top: r, width: a, height: s, angle: l } = n, c = t == null ? void 0 : t.with(me).getSkeleton(), m = c == null ? void 0 : c.getSkeletonData(), { pages: u } = m != null ? m : {};
2204
+ if (m == null || t == null || u == null)
2205
+ return {
2206
+ left: o,
2207
+ top: r,
2208
+ width: a,
2209
+ height: s,
2210
+ angle: l
2211
+ };
2212
+ const { mainComponent: p } = t, f = p, { top: g, pageLayoutType: w, pageMarginLeft: v, pageMarginTop: I } = f;
2213
+ let C = r;
2214
+ this._liquid.reset();
2215
+ for (const P of u) {
2216
+ const { marginBottom: S, pageHeight: O } = P, R = u.indexOf(P), D = u[R + 1];
2217
+ if (D == null)
2218
+ continue;
2219
+ if (_e.hasIntersectionBetweenTwoRanges(
2220
+ r,
2221
+ r + s,
2222
+ this._liquid.y + g + O - S,
2223
+ this._liquid.y + g + O + I + D.marginTop
2224
+ )) {
2225
+ const y = r + s / 2, T = this._liquid.y + g + O + I / 2;
2226
+ y < T ? C = Math.min(r, this._liquid.y + g + O - S - s) : C = Math.max(r, this._liquid.y + g + O + I + D.marginTop);
2227
+ }
2228
+ this._liquid.translatePage(P, w, v, I);
2229
+ }
2230
+ return {
2231
+ left: o,
2232
+ top: C,
2233
+ width: a,
2234
+ height: s,
2235
+ angle: l
2236
+ };
2237
+ }
2238
+ _nonInlineDrawingTransform(e, n, t = !1) {
2239
+ const o = this._limitDrawingInPage(e, n);
2240
+ if (t && o.top !== n.top)
2241
+ return;
2242
+ const r = this._getDrawingAnchor(e, o), { offset: a, docTransform: s } = r != null ? r : {};
2243
+ return a == null || s == null ? this._updateMultipleDrawingDocTransform(/* @__PURE__ */ new Map([[e.drawingId, n]])) : this._commandService.executeCommand(nt.id, {
2244
+ unitId: e.unitId,
2245
+ subUnitId: e.unitId,
2246
+ drawing: e,
2247
+ offset: a,
2248
+ docTransform: s
2249
+ });
2250
+ }
2251
+ _getSceneAndTransformerByDrawingSearch(e) {
2252
+ if (e == null)
2253
+ return;
2254
+ const n = this._renderManagerService.getRenderById(e), t = n == null ? void 0 : n.scene;
2255
+ if (t == null)
2256
+ return;
2257
+ const o = t.getTransformerByCreate();
2258
+ return { scene: t, transformer: o };
2259
+ }
2260
+ _getTransformCoordForDocumentOffset(e, n, t, o) {
2261
+ const { documentTransform: r } = e.getOffsetConfig(), a = n.transformVector2SceneCoord(xt.FromArray([t, o]));
2262
+ if (a)
2263
+ return r.clone().invert().applyPoint(a);
2264
+ }
2265
+ _createOrUpdateInlineAnchor(e, n) {
2266
+ const t = this._renderManagerService.getRenderById(e);
2267
+ if (t == null)
2268
+ return;
2269
+ const { mainComponent: o, scene: r } = t, a = o, {
2270
+ docsLeft: s,
2271
+ docsTop: l
2272
+ } = a.getOffsetConfig(), c = Ut(n), { left: m, top: u, height: p } = c, f = m + s, g = u + l;
2273
+ if (this._anchorShape) {
2274
+ this._anchorShape.transformByState({ left: f, top: g, height: p }), this._anchorShape.show();
2275
+ return;
2276
+ }
2277
+ const w = 6, v = new Lt(oo + _e.generateRandomId(w), {
2278
+ left: f,
2279
+ top: g,
2280
+ height: p,
2281
+ strokeWidth: 2,
2282
+ stroke: Ft(wt.darkGray, 1),
2283
+ evented: !1
2284
+ });
2285
+ this._anchorShape = v, r.addObject(v, Bt);
2286
+ }
2287
+ _getDocObject() {
2288
+ return $t(this._univerInstanceService, this._renderManagerService);
2289
+ }
2290
+ _getPageContentSize(e) {
2291
+ const n = this._renderManagerService.getRenderById(e.unitId), t = n == null ? void 0 : n.with(me).getSkeleton(), o = 500, r = 500, a = t == null ? void 0 : t.getSkeletonData();
2292
+ if (a == null || n == null)
2293
+ return {
2294
+ width: o,
2295
+ height: r
2296
+ };
2297
+ const { pages: s } = a;
2298
+ let l = null;
2299
+ for (const c of s) {
2300
+ const { skeDrawings: m } = c;
2301
+ if (m.has(e.drawingId)) {
2302
+ l = c;
2303
+ break;
2304
+ }
2305
+ }
2306
+ if (l) {
2307
+ const { pageWidth: c, pageHeight: m, marginLeft: u, marginBottom: p, marginRight: f, marginTop: g } = l;
2308
+ return {
2309
+ width: Math.max(o, c - u - f),
2310
+ height: Math.max(r, m - g - p)
2311
+ };
2312
+ } else
2313
+ return {
2314
+ width: o,
2315
+ height: r
2316
+ };
2317
+ }
2318
+ };
2319
+ Ye = io([
2320
+ nn(tn.Rendered, Ye),
2321
+ ze(0, W),
2322
+ ze(1, X),
2323
+ ze(2, ge),
2324
+ ze(3, Q)
2325
+ ], Ye);
2326
+ var ct = Object.defineProperty, ro = Object.getOwnPropertyDescriptor, ao = (i, e, n) => e in i ? ct(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n, so = (i, e, n, t) => {
2327
+ for (var o = t > 1 ? void 0 : t ? ro(e, n) : e, r = i.length - 1, a; r >= 0; r--)
2328
+ (a = i[r]) && (o = (t ? a(e, n, o) : a(o)) || o);
2329
+ return t && o && ct(e, n, o), o;
2330
+ }, An = (i, e) => (n, t) => e(n, t, i), lt = (i, e, n) => ao(i, typeof e != "symbol" ? e + "" : e, n);
2331
+ const co = "DOCS_DRAWING_UI_PLUGIN";
2332
+ let Qe = class extends vt {
2333
+ constructor(i, e, n) {
2334
+ super(), this._injector = e, this._renderManagerSrv = n;
2335
+ }
2336
+ onStarting(i) {
866
2337
  [
867
- [$],
868
- [F]
869
- ].forEach((t) => e.add(t));
2338
+ [qe],
2339
+ [Xe],
2340
+ [Ye],
2341
+ [Ke]
2342
+ ].forEach((n) => i.add(n));
870
2343
  }
871
2344
  onReady() {
872
2345
  [
873
- Y
874
- ].forEach((e) => this._renderManagerSrv.registerRenderModule(E.UNIVER_DOC, e));
2346
+ [ln],
2347
+ [dn]
2348
+ ].forEach((i) => this._renderManagerSrv.registerRenderModule(Ce.UNIVER_DOC, i));
875
2349
  }
876
2350
  };
877
- Te(B, "type", E.UNIVER_DOC);
878
- Te(B, "pluginName", dt);
879
- B = ct([
880
- Ke(qe, rn, on),
881
- ae(1, y(me)),
882
- ae(2, H)
883
- ], B);
2351
+ lt(Qe, "type", Ce.UNIVER_DOC);
2352
+ lt(Qe, "pluginName", co);
2353
+ Qe = so([
2354
+ It(Et, bt, Rt),
2355
+ An(1, Se(Un)),
2356
+ An(2, Q)
2357
+ ], Qe);
884
2358
  export {
885
- w as ClearDocDrawingTransformerOperation,
886
- ye as DeleteDocDrawingsCommand,
887
- Se as EditDocDrawingOperation,
888
- Ue as GroupDocDrawingCommand,
889
- Ne as InsertDocDrawingCommand,
890
- z as InsertDocImageOperation,
891
- x as MoveDocDrawingsCommand,
892
- X as RemoveDocDrawingCommand,
893
- be as SetDocDrawingArrangeCommand,
894
- q as SetDocDrawingCommand,
895
- we as SidebarDocDrawingOperation,
896
- Re as UngroupDocDrawingCommand,
897
- B as UniverDocsDrawingUIPlugin
2359
+ Oe as ClearDocDrawingTransformerOperation,
2360
+ tt as DeleteDocDrawingsCommand,
2361
+ kn as EditDocDrawingOperation,
2362
+ at as GroupDocDrawingCommand,
2363
+ st as InsertDocDrawingCommand,
2364
+ rn as InsertDocImageOperation,
2365
+ Fe as MoveDocDrawingsCommand,
2366
+ pn as RemoveDocDrawingCommand,
2367
+ it as SetDocDrawingArrangeCommand,
2368
+ ot as SetDocDrawingCommand,
2369
+ jn as SidebarDocDrawingOperation,
2370
+ rt as UngroupDocDrawingCommand,
2371
+ Qe as UniverDocsDrawingUIPlugin
898
2372
  };