@univerjs/docs-drawing-ui 0.2.2 → 0.2.3

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