@univerjs/docs-drawing-ui 0.6.7-experimental.20250326-6499c07 → 0.6.7-experimental.20250328-21e0bec

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/index.js ADDED
@@ -0,0 +1,2755 @@
1
+ var At = Object.defineProperty;
2
+ var xt = (i, e, n) => e in i ? At(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n;
3
+ var Se = (i, e, n) => xt(i, typeof e != "symbol" ? e + "" : e, n);
4
+ import { Disposable as Ge, BlockType as Lt, UndoCommand as Ut, RedoCommand as Bt, JSONX as X, IUniverInstanceService as q, ICommandService as $, PositionedObjectLayoutType as W, CommandType as Y, BooleanNumber as se, ObjectRelativeFromH as ee, ObjectRelativeFromV as H, Tools as Me, TextX as Dn, TextXActionType as Q, toDisposable as Oe, throttle as Rn, COLORS as kt, MemoryCursor as Ft, IUndoRedoService as Yn, BuildTextUtils as Wt, ArrangeTypeEnum as Qe, Inject as pe, IContextService as Zn, LocaleService as un, WrapTextType as Xe, DrawingTypeEnum as rn, FOCUSING_COMMON_DRAWINGS as on, UniverInstanceType as Ie, Direction as fe, DocumentFlavor as wn, DOCS_ZEN_EDITOR_UNIT_ID_KEY as Cn, FOCUSING_UNIVER_EDITOR as Ht, DisposableCollection as Gt, fromEventSubject as Qn, generateRandomId as Vt, RxDisposable as jt, SHEET_EDITOR_UNITS as $t, LifecycleService as zt, LifecycleStages as En, DependentOn as Xt, Injector as qt, IConfigService as Kt, Plugin as Yt, merge as Zt } from "@univerjs/core";
5
+ import { IDocDrawingService as Ue, UniverDocsDrawingPlugin as Qt } from "@univerjs/docs-drawing";
6
+ import { IDrawingManagerService as _e, IImageIoService as Jt, DRAWING_IMAGE_ALLOW_IMAGE_LIST as ei, DRAWING_IMAGE_COUNT_LIMIT as Nn, ImageUploadStatusType as vn, DRAWING_IMAGE_ALLOW_SIZE as ni, getImageSize as ti, getDrawingShapeKeyByDrawingSearch as ii, DRAWING_IMAGE_WIDTH_LIMIT as An, DRAWING_IMAGE_HEIGHT_LIMIT as xn, UniverDrawingPlugin as ri } from "@univerjs/drawing";
7
+ import { DrawingCommonPanel as oi, DrawingRenderService as si, ImageCropperObject as ai, COMPONENT_IMAGE_POPUP_MENU as ci, OpenImageCropOperation as di, ImageResetSizeOperation as li, UniverDrawingUIPlugin as gi } from "@univerjs/drawing-ui";
8
+ import { IRenderManagerService as J, DocumentEditArea as We, Liquid as Jn, PageLayoutType as Ln, DocumentSkeletonPageType as Un, Vector2 as mi, Rect as ui, getColor as fi, getCurrentTypeOfRenderer as hi, CURSOR_TYPE as Bn, TRANSFORM_CHANGE_OBSERVABLE_TYPE as pi } from "@univerjs/engine-render";
9
+ import { IMessageService as wi, ILocalFileService as vi, ISidebarService as Ii, useDependency as ve, getMenuHiddenObservable as et, MenuItemType as nt, RibbonStartGroup as _i, KeyCode as He, ComponentManager as Si, IMenuManagerService as Di, IShortcutService as Ci, CanvasFloatDomService as Oi, UniverUIPlugin as Ti } from "@univerjs/ui";
10
+ import { RichTextEditingMutation as ne, DocSkeletonManagerService as te, DocSelectionManagerService as On } from "@univerjs/docs";
11
+ import { DocSelectionRenderService as Re, getRichTextEditPath as qe, NodePositionConvertToCursor as kn, getOneTextSelectionRange as Fn, getAnchorBounding as yi, TEXT_RANGE_LAYER_INDEX as Pi, getDocObject as bi, getCustomBlockIdsInSelections as Mi, docDrawingPositionToTransform as tt, VIEWPORT_KEY as it, SetDocZoomRatioOperation as rt, DocCanvasPopManagerService as Ri, IEditorService as Ei } from "@univerjs/docs-ui";
12
+ import { BehaviorSubject as ot, debounceTime as st, Observable as Ni, map as Wn, switchMap as Ai, of as xi, takeUntil as Hn, filter as Gn } from "rxjs";
13
+ import { MessageType as Vn, clsx as j, InputNumber as Fe, Select as jn, Checkbox as Li, RadioGroup as $n, Radio as be } from "@univerjs/design";
14
+ import { jsxs as K, jsx as p } from "react/jsx-runtime";
15
+ import { forwardRef as at, useRef as Ui, createElement as ct, useState as oe, useEffect as Tn } from "react";
16
+ const Bi = "docs-drawing-ui.config", zn = {};
17
+ var ki = Object.getOwnPropertyDescriptor, Fi = (i, e, n, t) => {
18
+ for (var r = t > 1 ? void 0 : t ? ki(e, n) : e, o = i.length - 1, s; o >= 0; o--)
19
+ (s = i[o]) && (r = s(r) || r);
20
+ return r;
21
+ }, $e = (i, e) => (n, t) => e(n, t, i);
22
+ function Wi(i) {
23
+ var t, r, o, s;
24
+ if (X.isNoop(i) || !Array.isArray(i))
25
+ return null;
26
+ const e = i.find((a) => Array.isArray(a) && (a == null ? void 0 : a[0]) === "drawings");
27
+ 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")
28
+ return null;
29
+ const n = [];
30
+ if (Array.isArray(e == null ? void 0 : e[1]))
31
+ for (const a of e)
32
+ Array.isArray(a) && n.push({
33
+ type: (t = a == null ? void 0 : a[1]) != null && t.i ? "add" : "remove",
34
+ drawingId: a == null ? void 0 : a[0],
35
+ drawing: (r = a == null ? void 0 : a[1]) == null ? void 0 : r.i
36
+ });
37
+ else
38
+ n.push({
39
+ type: (o = e[2]) != null && o.i ? "add" : "remove",
40
+ drawingId: e[1],
41
+ drawing: (s = e[2]) == null ? void 0 : s.i
42
+ });
43
+ return n;
44
+ }
45
+ function Hi(i) {
46
+ if (!Array.isArray(i) || i.length < 3 || i[0] !== "drawingsOrder")
47
+ return [];
48
+ const e = [];
49
+ for (let n = 1; n < i.length; n++) {
50
+ const t = i[n];
51
+ if (Array.isArray(t) && typeof t[0] == "number" && typeof t[1] == "object")
52
+ e.push(t[0]);
53
+ else {
54
+ e.length = 0;
55
+ break;
56
+ }
57
+ }
58
+ return e;
59
+ }
60
+ let sn = class extends Ge {
61
+ constructor(i, e, n, t, r) {
62
+ super(), this._univerInstanceService = i, this._commandService = e, this._drawingManagerService = n, this._docDrawingService = t, this._renderManagerService = r, this._initialize();
63
+ }
64
+ _initialize() {
65
+ this._commandExecutedListener();
66
+ }
67
+ _commandExecutedListener() {
68
+ this.disposeWithMe(
69
+ this._commandService.beforeCommandExecuted((i) => {
70
+ var a, d;
71
+ if (i.id !== ne.id)
72
+ return;
73
+ const e = i.params, { unitId: n, actions: t } = e, r = this._univerInstanceService.getUniverDocInstance(n), o = (d = (a = r == null ? void 0 : r.getBody()) == null ? void 0 : a.customBlocks) != null ? d : [], s = Wi(t);
74
+ if (s != null)
75
+ for (const { type: c, drawingId: g, drawing: m } of s) {
76
+ const l = o.find((f) => f.blockId === g);
77
+ (l == null ? void 0 : l.blockType) !== Lt.CUSTOM && (c === "add" ? this._addDrawings(n, [m]) : this._removeDrawings(n, [g]));
78
+ }
79
+ })
80
+ ), this.disposeWithMe(
81
+ this._commandService.onCommandExecuted((i) => {
82
+ if (i.id !== ne.id)
83
+ return;
84
+ const e = i.params, { unitId: n, actions: t } = e;
85
+ Hi(t).length > 0 && this._updateDrawingsOrder(n);
86
+ })
87
+ ), this.disposeWithMe(
88
+ this._commandService.onCommandExecuted((i) => {
89
+ var s;
90
+ if (i.id !== Ut.id && i.id !== Bt.id)
91
+ return;
92
+ const e = (s = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : s.getUnitId(), n = this._drawingManagerService.getFocusDrawings();
93
+ if (e == null || n.length === 0)
94
+ return;
95
+ const t = this._renderManagerService.getRenderById(e), r = t == null ? void 0 : t.scene;
96
+ if (r == null)
97
+ return !1;
98
+ r.getTransformerByCreate().refreshControls();
99
+ })
100
+ );
101
+ }
102
+ _addDrawings(i, e) {
103
+ const n = this._drawingManagerService, t = this._docDrawingService, r = this._docDrawingService.getBatchAddOp(e), { subUnitId: o, redo: s, objects: a } = r;
104
+ n.applyJson1(i, o, s), t.applyJson1(i, o, s), n.addNotification(a), t.addNotification(a);
105
+ }
106
+ _removeDrawings(i, e) {
107
+ const n = this._drawingManagerService, t = this._docDrawingService, r = this._docDrawingService.getBatchRemoveOp(e.map((d) => ({
108
+ unitId: i,
109
+ subUnitId: i,
110
+ drawingId: d
111
+ }))), { subUnitId: o, redo: s, objects: a } = r;
112
+ n.applyJson1(i, o, s), t.applyJson1(i, o, s), n.removeNotification(a), t.removeNotification(a);
113
+ }
114
+ _updateDrawingsOrder(i) {
115
+ const e = this._univerInstanceService.getUniverDocInstance(i);
116
+ if (e == null)
117
+ return;
118
+ const n = e.getSnapshot().drawingsOrder;
119
+ if (n == null)
120
+ return;
121
+ const t = this._drawingManagerService, r = this._docDrawingService;
122
+ t.setDrawingOrder(i, i, n), r.setDrawingOrder(i, i, n);
123
+ const o = {
124
+ unitId: i,
125
+ subUnitId: i,
126
+ drawingIds: n
127
+ };
128
+ t.orderNotification(o), r.orderNotification(o);
129
+ }
130
+ };
131
+ sn = Fi([
132
+ $e(0, q),
133
+ $e(1, $),
134
+ $e(2, _e),
135
+ $e(3, Ue),
136
+ $e(4, J)
137
+ ], sn);
138
+ class fn {
139
+ constructor() {
140
+ Se(this, "_refreshDrawings$", new ot(null));
141
+ Se(this, "refreshDrawings$", this._refreshDrawings$.asObservable());
142
+ }
143
+ refreshDrawings(e) {
144
+ this._refreshDrawings$.next(e);
145
+ }
146
+ }
147
+ var ue = /* @__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))(ue || {});
148
+ const Gi = {
149
+ inline: W.INLINE,
150
+ wrapSquare: W.WRAP_SQUARE,
151
+ wrapTopAndBottom: W.WRAP_TOP_AND_BOTTOM,
152
+ inFrontOfText: W.WRAP_NONE,
153
+ behindText: W.WRAP_NONE
154
+ };
155
+ function dt(i, e, n, t, r, o, s) {
156
+ var f, u;
157
+ const a = new Dn(), d = X.getInstance(), c = [], g = o.getSelfOrHeaderFooterModel(e).getBody(), m = o.getSelfOrHeaderFooterModel(i).getBody();
158
+ if (g == null || m == null)
159
+ return;
160
+ const l = (u = (f = g.customBlocks) == null ? void 0 : f.find((v) => v.blockId === r)) == null ? void 0 : u.startIndex;
161
+ if (l != null) {
162
+ if (t = Math.min(m.dataStream.length - 2, t), i === e) {
163
+ if (t < l ? (t > 0 && a.push({
164
+ t: Q.RETAIN,
165
+ len: t
166
+ }), a.push({
167
+ t: Q.INSERT,
168
+ body: {
169
+ dataStream: "\b",
170
+ customBlocks: [{
171
+ startIndex: 0,
172
+ blockId: r
173
+ }]
174
+ },
175
+ len: 1
176
+ }), a.push({
177
+ t: Q.RETAIN,
178
+ len: l - t
179
+ }), a.push({
180
+ t: Q.DELETE,
181
+ len: 1
182
+ })) : (l > 0 && a.push({
183
+ t: Q.RETAIN,
184
+ len: l
185
+ }), a.push({
186
+ t: Q.DELETE,
187
+ len: 1
188
+ }), t - l - 1 > 0 && a.push({
189
+ t: Q.RETAIN,
190
+ len: t - l - 1
191
+ }), a.push({
192
+ t: Q.INSERT,
193
+ body: {
194
+ dataStream: "\b",
195
+ customBlocks: [{
196
+ startIndex: 0,
197
+ blockId: r
198
+ }]
199
+ },
200
+ len: 1
201
+ })), t !== l) {
202
+ const v = qe(o, e), w = d.editOp(a.serialize(), v);
203
+ c.push(w);
204
+ }
205
+ } else {
206
+ l > 0 && a.push({
207
+ t: Q.RETAIN,
208
+ len: l
209
+ }), a.push({
210
+ t: Q.DELETE,
211
+ len: 1
212
+ });
213
+ let v = qe(o, e), w = d.editOp(a.serialize(), v);
214
+ c.push(w), a.empty(), t > 0 && a.push({
215
+ t: Q.RETAIN,
216
+ len: t
217
+ }), a.push({
218
+ t: Q.INSERT,
219
+ body: {
220
+ dataStream: "\b",
221
+ customBlocks: [{
222
+ startIndex: 0,
223
+ blockId: r
224
+ }]
225
+ },
226
+ len: 1
227
+ }), v = qe(o, i), w = d.editOp(a.serialize(), v), c.push(w), s.setSegment(i), s.setSegmentPage(n);
228
+ }
229
+ return c;
230
+ }
231
+ }
232
+ const lt = {
233
+ id: "doc.command.update-doc-drawing-wrapping-style",
234
+ type: Y.COMMAND,
235
+ // eslint-disable-next-line max-lines-per-function, complexity
236
+ handler: (i, e) => {
237
+ var N, B;
238
+ if (e == null)
239
+ return !1;
240
+ const { drawings: n, wrappingStyle: t, unitId: r } = e, o = i.get($), s = i.get(q), d = i.get(J).getRenderById(r), c = d == null ? void 0 : d.with(te).getSkeleton().getSkeletonData(), g = d == null ? void 0 : d.with(te).getViewModel(), m = d == null ? void 0 : d.scene, l = s.getCurrentUniverDocInstance();
241
+ if (l == null || c == null || m == null || g == null)
242
+ return !1;
243
+ const f = g.getEditArea(), u = m.getTransformerByCreate(), { pages: v, skeHeaders: w, skeFooters: I } = c, O = X.getInstance(), C = [], { drawings: T = {} } = l.getSnapshot();
244
+ for (const E of n) {
245
+ const { drawingId: _ } = E, L = T[_].layoutType, G = Gi[t];
246
+ if (L !== G) {
247
+ const D = O.replaceOp(["drawings", _, "layoutType"], L, G);
248
+ C.push(D);
249
+ }
250
+ if (t === "behindText" || t === "inFrontOfText") {
251
+ const D = T[_].behindDoc, R = t === "behindText" ? se.TRUE : se.FALSE;
252
+ if (D !== R) {
253
+ const y = O.replaceOp(["drawings", _, "behindDoc"], D, R);
254
+ C.push(y);
255
+ }
256
+ }
257
+ if (t === "inline")
258
+ continue;
259
+ let x = null, V = 0, S = 0;
260
+ for (const D of v) {
261
+ const { headerId: R, footerId: y, marginTop: U, marginLeft: k, marginBottom: b, pageWidth: A, pageHeight: z } = D;
262
+ switch (f) {
263
+ case We.HEADER: {
264
+ const F = (N = w.get(R)) == null ? void 0 : N.get(A);
265
+ F != null && F.skeDrawings.has(_) && (x = F.skeDrawings.get(_), V = F.marginTop, S = k);
266
+ break;
267
+ }
268
+ case We.FOOTER: {
269
+ const F = (B = I.get(y)) == null ? void 0 : B.get(A);
270
+ F != null && F.skeDrawings.has(_) && (x = F.skeDrawings.get(_), V = z - b + F.marginTop, S = k);
271
+ break;
272
+ }
273
+ case We.BODY: {
274
+ D.skeDrawings.has(_) && (x = D.skeDrawings.get(_), V = U, S = k);
275
+ break;
276
+ }
277
+ }
278
+ if (x != null)
279
+ break;
280
+ }
281
+ if (x != null) {
282
+ const { aTop: D, aLeft: R } = x, y = T[_].docTransform.positionH;
283
+ let U = R;
284
+ y.relativeFrom === ee.MARGIN ? U -= S : y.relativeFrom === ee.COLUMN && (U -= x.columnLeft);
285
+ const k = {
286
+ relativeFrom: y.relativeFrom,
287
+ posOffset: U
288
+ };
289
+ if (y.posOffset !== k.posOffset) {
290
+ const F = O.replaceOp(["drawings", _, "docTransform", "positionH"], y, k);
291
+ C.push(F);
292
+ }
293
+ const b = T[_].docTransform.positionV;
294
+ let A = D;
295
+ b.relativeFrom === H.PAGE ? A += V : b.relativeFrom === H.LINE ? A -= x.lineTop : b.relativeFrom === H.PARAGRAPH && (A -= x.blockAnchorTop);
296
+ const z = {
297
+ relativeFrom: b.relativeFrom,
298
+ posOffset: A
299
+ };
300
+ if (b.posOffset !== z.posOffset) {
301
+ const F = O.replaceOp(["drawings", _, "docTransform", "positionV"], b, z);
302
+ C.push(F);
303
+ }
304
+ }
305
+ }
306
+ const M = {
307
+ id: ne.id,
308
+ params: {
309
+ unitId: r,
310
+ actions: [],
311
+ textRanges: null
312
+ }
313
+ };
314
+ M.params.actions = C.reduce((E, _) => X.compose(E, _), null);
315
+ const P = o.syncExecuteCommand(M.id, M.params);
316
+ return u.refreshControls(), !!P;
317
+ }
318
+ }, gt = {
319
+ id: "doc.command.update-doc-drawing-distance",
320
+ type: Y.COMMAND,
321
+ handler: (i, e) => {
322
+ if (e == null)
323
+ return !1;
324
+ const n = i.get($), r = i.get(q).getCurrentUniverDocInstance();
325
+ if (r == null)
326
+ return !1;
327
+ const { drawings: o, dist: s, unitId: a } = e, d = X.getInstance(), c = [], { drawings: g = {} } = r.getSnapshot();
328
+ for (const f of o) {
329
+ const { drawingId: u } = f;
330
+ for (const [v, w] of Object.entries(s)) {
331
+ const I = g[u][v];
332
+ if (I !== w) {
333
+ const O = d.replaceOp(["drawings", u, v], I, w);
334
+ c.push(O);
335
+ }
336
+ }
337
+ }
338
+ const m = {
339
+ id: ne.id,
340
+ params: {
341
+ unitId: a,
342
+ actions: [],
343
+ textRanges: null
344
+ }
345
+ };
346
+ return m.params.actions = c.reduce((f, u) => X.compose(f, u), null), !!n.syncExecuteCommand(m.id, m.params);
347
+ }
348
+ }, mt = {
349
+ id: "doc.command.update-doc-drawing-wrap-text",
350
+ type: Y.COMMAND,
351
+ handler: (i, e) => {
352
+ if (e == null)
353
+ return !1;
354
+ const n = i.get($), r = i.get(q).getCurrentUniverDocInstance();
355
+ if (r == null)
356
+ return !1;
357
+ const { drawings: o, wrapText: s, unitId: a } = e, d = X.getInstance(), c = [], { drawings: g = {} } = r.getSnapshot();
358
+ for (const f of o) {
359
+ const { drawingId: u } = f, v = g[u].wrapText;
360
+ if (v !== s) {
361
+ const w = d.replaceOp(["drawings", u, "wrapText"], v, s);
362
+ c.push(w);
363
+ }
364
+ }
365
+ const m = {
366
+ id: ne.id,
367
+ params: {
368
+ unitId: a,
369
+ actions: [],
370
+ textRanges: null
371
+ }
372
+ };
373
+ return m.params.actions = c.reduce((f, u) => X.compose(f, u), null), !!n.syncExecuteCommand(m.id, m.params);
374
+ }
375
+ }, Ke = {
376
+ id: "doc.command.update-drawing-doc-transform",
377
+ type: Y.COMMAND,
378
+ handler: (i, e) => {
379
+ if (e == null)
380
+ return !1;
381
+ const n = i.get($), t = i.get(q), o = i.get(J).getRenderById(e.unitId), s = o == null ? void 0 : o.scene;
382
+ if (s == null)
383
+ return !1;
384
+ const a = s.getTransformerByCreate(), d = t.getCurrentUniverDocInstance();
385
+ if (d == null)
386
+ return !1;
387
+ const { drawings: c, unitId: g } = e, m = X.getInstance(), l = [], { drawings: f = {} } = d.getSnapshot();
388
+ for (const w of c) {
389
+ const { drawingId: I, key: O, value: C } = w, T = f[I].docTransform[O];
390
+ if (!Me.diffValue(T, C)) {
391
+ const M = m.replaceOp(["drawings", I, "docTransform", O], T, C);
392
+ l.push(M);
393
+ }
394
+ }
395
+ const u = {
396
+ id: ne.id,
397
+ params: {
398
+ unitId: g,
399
+ actions: [],
400
+ textRanges: null,
401
+ debounce: !0
402
+ }
403
+ };
404
+ u.params.actions = l.reduce((w, I) => X.compose(w, I), null);
405
+ const v = n.syncExecuteCommand(u.id, u.params);
406
+ return a.refreshControls(), !!v;
407
+ }
408
+ }, ut = {
409
+ id: "doc.command.move-inline-drawing",
410
+ type: Y.COMMAND,
411
+ handler: (i, e) => {
412
+ var B, E;
413
+ if (e == null)
414
+ return !1;
415
+ const n = i.get(J), t = (B = n.getRenderById(e.unitId)) == null ? void 0 : B.with(Re), r = i.get(fn), o = n.getRenderById(e.unitId), s = o == null ? void 0 : o.scene, a = o == null ? void 0 : o.with(te).getSkeleton();
416
+ if (s == null || t == null)
417
+ return !1;
418
+ const d = s.getTransformerByCreate(), c = i.get($), m = i.get(q).getCurrentUniverDocInstance();
419
+ if (m == null)
420
+ return !1;
421
+ const { drawing: l, unitId: f, offset: u, segmentId: v, segmentPage: w, needRefreshDrawings: I } = e;
422
+ if (I)
423
+ return r.refreshDrawings(a), d.refreshControls(), !0;
424
+ const O = [], { drawingId: C } = l, T = (E = t.getSegment()) != null ? E : "", M = dt(
425
+ v,
426
+ T,
427
+ w,
428
+ u,
429
+ C,
430
+ m,
431
+ t
432
+ );
433
+ if (M == null || M.length === 0)
434
+ return r.refreshDrawings(a), d.refreshControls(), !1;
435
+ O.push(...M);
436
+ const P = {
437
+ id: ne.id,
438
+ params: {
439
+ unitId: f,
440
+ actions: [],
441
+ textRanges: null
442
+ }
443
+ };
444
+ P.params.actions = O.reduce((_, L) => X.compose(_, L), null);
445
+ const N = c.syncExecuteCommand(P.id, P.params);
446
+ return d.refreshControls(), !!N;
447
+ }
448
+ }, ft = {
449
+ id: "doc.command.transform-non-inline-drawing",
450
+ type: Y.COMMAND,
451
+ // eslint-disable-next-line max-lines-per-function
452
+ handler: (i, e) => {
453
+ var x, V;
454
+ if (e == null)
455
+ return !1;
456
+ const n = i.get(J), t = (x = n.getRenderById(e.unitId)) == null ? void 0 : x.with(Re), r = n.getRenderById(e.unitId), o = r == null ? void 0 : r.scene;
457
+ if (o == null || t == null)
458
+ return !1;
459
+ const s = o.getTransformerByCreate(), a = i.get($), c = i.get(q).getCurrentUniverDocInstance();
460
+ if (c == null)
461
+ return !1;
462
+ const { drawing: g, unitId: m, offset: l, docTransform: f, segmentId: u, segmentPage: v } = e, w = [], { drawingId: I } = g, O = (V = t.getSegment()) != null ? V : "", C = dt(
463
+ u,
464
+ O,
465
+ v,
466
+ l,
467
+ I,
468
+ c,
469
+ t
470
+ );
471
+ if (C == null)
472
+ return !1;
473
+ C.length > 0 && w.push(...C);
474
+ const T = X.getInstance(), { drawings: M = {} } = c.getSnapshot(), P = M[I].docTransform, { positionH: N, positionV: B, size: E, angle: _ } = P;
475
+ if (!Me.diffValue(N, f.positionH)) {
476
+ const S = T.replaceOp(["drawings", I, "docTransform", "positionH"], N, f.positionH);
477
+ w.push(S);
478
+ }
479
+ if (!Me.diffValue(B, f.positionV)) {
480
+ const S = T.replaceOp(["drawings", I, "docTransform", "positionV"], B, f.positionV);
481
+ w.push(S);
482
+ }
483
+ if (!Me.diffValue(E, f.size)) {
484
+ const S = T.replaceOp(["drawings", I, "docTransform", "size"], E, f.size);
485
+ w.push(S);
486
+ }
487
+ if (!Me.diffValue(_, f.angle)) {
488
+ const S = T.replaceOp(["drawings", I, "docTransform", "angle"], _, f.angle);
489
+ w.push(S);
490
+ }
491
+ const L = {
492
+ id: ne.id,
493
+ params: {
494
+ unitId: m,
495
+ actions: [],
496
+ textRanges: null,
497
+ debounce: !0
498
+ }
499
+ };
500
+ L.params.actions = w.reduce((S, D) => X.compose(S, D), null);
501
+ const G = a.syncExecuteCommand(L.id, L.params);
502
+ return s.refreshControls(), !!G;
503
+ }
504
+ };
505
+ var Vi = Object.getOwnPropertyDescriptor, ji = (i, e, n, t) => {
506
+ for (var r = t > 1 ? void 0 : t ? Vi(e, n) : e, o = i.length - 1, s; o >= 0; o--)
507
+ (s = i[o]) && (r = s(r) || r);
508
+ return r;
509
+ }, Je = (i, e) => (n, t) => e(n, t, i);
510
+ const $i = "__InlineDrawingAnchor__";
511
+ function Xn(i) {
512
+ const { path: e } = i;
513
+ return e.some((n) => n === "cells");
514
+ }
515
+ let an = class extends Ge {
516
+ constructor(e, n, t, r) {
517
+ super();
518
+ Se(this, "_liquid", new Jn());
519
+ Se(this, "_listenerOnImageMap", /* @__PURE__ */ new Set());
520
+ // Use to cache the drawings is under transforming or scaling.
521
+ Se(this, "_transformerCache", /* @__PURE__ */ new Map());
522
+ Se(this, "_anchorShape");
523
+ this._commandService = e, this._univerInstanceService = n, this._drawingManagerService = t, this._renderManagerService = r, this._init();
524
+ }
525
+ _init() {
526
+ this._listenDrawingFocus();
527
+ }
528
+ _listenDrawingFocus() {
529
+ this.disposeWithMe(
530
+ this._drawingManagerService.add$.subscribe((e) => {
531
+ if (e.length !== 0)
532
+ for (const n of e) {
533
+ const { unitId: t } = n;
534
+ this._listenerOnImageMap.has(t) || (this._listenTransformerChange(t), this._listenerOnImageMap.add(t));
535
+ }
536
+ })
537
+ );
538
+ }
539
+ // Only handle one drawing transformer change.
540
+ // eslint-disable-next-line max-lines-per-function
541
+ _listenTransformerChange(e) {
542
+ var r;
543
+ const n = (r = this._getSceneAndTransformerByDrawingSearch(e)) == null ? void 0 : r.transformer;
544
+ if (n == null)
545
+ return;
546
+ this.disposeWithMe(
547
+ Oe(
548
+ n.changeStart$.subscribe((o) => {
549
+ var a;
550
+ this._transformerCache.clear();
551
+ const { objects: s } = o;
552
+ for (const d of s.values()) {
553
+ const { oKey: c, width: g, height: m, left: l, top: f, angle: u } = d, v = this._drawingManagerService.getDrawingOKey(c);
554
+ if (v == null)
555
+ continue;
556
+ const w = this._univerInstanceService.getUniverDocInstance(v.unitId), I = (a = w == null ? void 0 : w.getSnapshot().drawings) == null ? void 0 : a[v.drawingId];
557
+ if ((I == null ? void 0 : I.layoutType) === W.INLINE)
558
+ try {
559
+ d.setOpacity(0.2);
560
+ } catch {
561
+ }
562
+ I != null && this._transformerCache.set(v.drawingId, {
563
+ drawing: I,
564
+ top: f,
565
+ left: l,
566
+ width: g,
567
+ height: m,
568
+ angle: u
569
+ });
570
+ }
571
+ })
572
+ )
573
+ );
574
+ const t = Rn(this._updateMultipleDrawingDocTransform.bind(this), 50);
575
+ Rn(this._nonInlineDrawingTransform.bind(this), 50), this.disposeWithMe(
576
+ Oe(
577
+ n.changing$.subscribe((o) => {
578
+ const { objects: s, offsetX: a, offsetY: d } = o;
579
+ if (s.size > 1)
580
+ t(s);
581
+ else if (s.size === 1) {
582
+ const c = this._transformerCache.values().next().value, g = s.values().next().value, { width: m, height: l, top: f, left: u, angle: v } = g;
583
+ if (c && m === c.width && l === c.height && f === c.top && u === c.left && v === c.angle)
584
+ return;
585
+ c && (c.drawing.layoutType, W.INLINE), c && c.drawing.layoutType === W.INLINE && a != null && d != null && this._updateInlineDrawingAnchor(c.drawing, a, d);
586
+ }
587
+ })
588
+ )
589
+ ), this.disposeWithMe(
590
+ Oe(
591
+ // eslint-disable-next-line complexity
592
+ n.changeEnd$.subscribe((o) => {
593
+ const { objects: s, offsetX: a, offsetY: d } = o;
594
+ for (const c of s.values()) {
595
+ const g = this._drawingManagerService.getDrawingOKey(c.oKey);
596
+ if (g == null)
597
+ continue;
598
+ const m = this._transformerCache.get(g == null ? void 0 : g.drawingId);
599
+ if ((m == null ? void 0 : m.drawing.layoutType) === W.INLINE)
600
+ try {
601
+ c.setOpacity(1);
602
+ } catch {
603
+ }
604
+ }
605
+ if (this._anchorShape && this._anchorShape.hide(), s.size > 1)
606
+ this._updateMultipleDrawingDocTransform(s);
607
+ else if (s.size === 1) {
608
+ const c = this._transformerCache.values().next().value, g = s.values().next().value, { width: m, height: l, top: f, left: u, angle: v } = g;
609
+ if (c && m === c.width && l === c.height && f === c.top && u === c.left && v === c.angle)
610
+ return;
611
+ c && c.drawing.layoutType === W.INLINE ? m !== c.width || l !== c.height || v !== c.angle ? this._updateDrawingSize(c, g) : a != null && d != null && this._moveInlineDrawing(c.drawing, a, d) : c && this._nonInlineDrawingTransform(c.drawing, g);
612
+ }
613
+ this._transformerCache.clear();
614
+ })
615
+ )
616
+ );
617
+ }
618
+ // eslint-disable-next-line max-lines-per-function
619
+ _updateMultipleDrawingDocTransform(e) {
620
+ if (e.size < 1)
621
+ return;
622
+ const n = [];
623
+ let t, r;
624
+ for (const o of e.values()) {
625
+ const { oKey: s, left: a, top: d, angle: c } = o;
626
+ let { width: g, height: m } = o;
627
+ const l = this._drawingManagerService.getDrawingOKey(s);
628
+ if (l == null)
629
+ continue;
630
+ t == null && (t = l.unitId), r == null && (r = l.subUnitId);
631
+ const f = this._transformerCache.get(l.drawingId);
632
+ if (f == null)
633
+ continue;
634
+ const { drawing: u, top: v, left: w, width: I, height: O, angle: C } = f, { width: T, height: M } = this._getPageContentSize(u);
635
+ if (g = Math.min(g, T), m = Math.min(m, M), (I !== g || O !== m) && n.push({
636
+ drawingId: l.drawingId,
637
+ key: "size",
638
+ value: {
639
+ width: g,
640
+ height: m
641
+ }
642
+ }), C !== c && n.push({
643
+ drawingId: l.drawingId,
644
+ key: "angle",
645
+ value: c
646
+ }), v !== d || w !== a) {
647
+ const P = d - v, N = a - w;
648
+ P !== 0 && n.push({
649
+ drawingId: l.drawingId,
650
+ key: "positionV",
651
+ value: {
652
+ relativeFrom: u.docTransform.positionV.relativeFrom,
653
+ posOffset: u.docTransform.positionV.posOffset + P
654
+ }
655
+ }), N !== 0 && n.push({
656
+ drawingId: l.drawingId,
657
+ key: "positionH",
658
+ value: {
659
+ relativeFrom: u.docTransform.positionH.relativeFrom,
660
+ posOffset: u.docTransform.positionH.posOffset + N
661
+ }
662
+ });
663
+ }
664
+ }
665
+ n.length > 0 && t && r && this._commandService.executeCommand(Ke.id, {
666
+ unitId: t,
667
+ subUnitId: r,
668
+ drawings: n
669
+ });
670
+ }
671
+ // TODO: @JOCS, Use to draw and update the drawing anchor.
672
+ _updateDrawingAnchor(e) {
673
+ if (this._transformerCache.size !== 1)
674
+ return;
675
+ const n = this._transformerCache.values().next().value, t = e.values().next().value;
676
+ this._getDrawingAnchor(n.drawing, t);
677
+ }
678
+ _updateInlineDrawingAnchor(e, n, t) {
679
+ var o;
680
+ if (this._transformerCache.size !== 1)
681
+ return;
682
+ const { contentBoxPointGroup: r } = (o = this._getInlineDrawingAnchor(e, n, t)) != null ? o : {};
683
+ r != null && this._createOrUpdateInlineAnchor(e.unitId, r);
684
+ }
685
+ _getInlineDrawingAnchor(e, n, t) {
686
+ var x, V;
687
+ const r = this._renderManagerService.getRenderById(e.unitId), o = r == null ? void 0 : r.with(te).getSkeleton();
688
+ if (r == null)
689
+ return;
690
+ const { mainComponent: s, scene: a } = r, d = s, c = a.getViewports()[0], {
691
+ pageLayoutType: g = Ln.VERTICAL,
692
+ pageMarginLeft: m,
693
+ pageMarginTop: l
694
+ } = d.getOffsetConfig();
695
+ let f = null, u = !1, v = -1, w = "";
696
+ const I = 0.5, O = this._getTransformCoordForDocumentOffset(d, c, n, t);
697
+ if (O == null)
698
+ return;
699
+ const C = (x = this._renderManagerService.getRenderById(e.unitId)) == null ? void 0 : x.with(Re);
700
+ if (C == null)
701
+ return;
702
+ const T = o == null ? void 0 : o.findNodeByCoord(O, g, m, l, {
703
+ strict: !1,
704
+ segmentId: C.getSegment(),
705
+ segmentPage: C.getSegmentPage()
706
+ });
707
+ if (T) {
708
+ const { node: S, ratioX: D, segmentPage: R, segmentId: y } = T;
709
+ u = D < I, f = S, v = R, w = y;
710
+ }
711
+ if (f == null)
712
+ return;
713
+ const M = o == null ? void 0 : o.findPositionByGlyph(f, v), P = this._getDocObject();
714
+ if (M == null || o == null || P == null || Xn(M))
715
+ return;
716
+ const N = {
717
+ ...M,
718
+ isBack: u
719
+ }, B = P.document.getOffsetConfig(), E = new kn(B, o), { cursorList: _, contentBoxPointGroup: L } = E.getRangePointData(N, N), { startOffset: G } = (V = Fn(_)) != null ? V : {};
720
+ if (G != null)
721
+ return { offset: G, contentBoxPointGroup: L, segmentId: w, segmentPage: v };
722
+ }
723
+ // eslint-disable-next-line max-lines-per-function, complexity
724
+ _getDrawingAnchor(e, n) {
725
+ var De, Ce, de, Te, ye, Ne, Ae, Pe, le, ge, xe;
726
+ const t = this._renderManagerService.getRenderById(e.unitId), r = t == null ? void 0 : t.with(te).getSkeleton(), o = r == null ? void 0 : r.getSkeletonData();
727
+ if (o == null || t == null)
728
+ return;
729
+ const { pages: s, skeHeaders: a, skeFooters: d } = o, { mainComponent: c, scene: g } = t, m = c, l = g.getViewports()[0], { pageLayoutType: f = Ln.VERTICAL, pageMarginLeft: u, pageMarginTop: v, docsLeft: w, docsTop: I } = m.getOffsetConfig(), { left: O, top: C, angle: T } = n;
730
+ let { width: M, height: P } = n;
731
+ const { positionV: N, positionH: B } = e.docTransform, { width: E, height: _ } = this._getPageContentSize(e);
732
+ M = Math.min(M, E), P = Math.min(P, _);
733
+ let L = null, G = "", x = -1;
734
+ const V = !1, S = {
735
+ ...e.docTransform,
736
+ size: {
737
+ width: M,
738
+ height: P
739
+ },
740
+ angle: T
741
+ }, { x: D, y: R } = g.getViewportScrollXY(l), y = this._getTransformCoordForDocumentOffset(m, l, O - D, C - R);
742
+ if (y == null)
743
+ return;
744
+ const U = (De = this._renderManagerService.getRenderById(e.unitId)) == null ? void 0 : De.with(Re);
745
+ if (U == null)
746
+ return;
747
+ const k = r == null ? void 0 : r.findNodeByCoord(y, f, u, v, {
748
+ strict: !1,
749
+ segmentId: U.getSegment(),
750
+ segmentPage: U.getSegmentPage()
751
+ });
752
+ if (k) {
753
+ const { node: we, segmentPage: hn, segmentId: pn } = k;
754
+ L = we, x = hn, G = pn;
755
+ }
756
+ if (L == null)
757
+ return;
758
+ const b = (Ce = L.parent) == null ? void 0 : Ce.parent, A = b == null ? void 0 : b.parent, z = (de = A == null ? void 0 : A.lines.find((we) => we.paragraphIndex === (b == null ? void 0 : b.paragraphIndex) && we.paragraphStart)) != null ? de : A == null ? void 0 : A.lines[0], F = (Te = A == null ? void 0 : A.parent) == null ? void 0 : Te.parent;
759
+ if (b == null || A == null || z == null || F == null)
760
+ return;
761
+ this._liquid.reset();
762
+ const Z = F.type;
763
+ for (const we of s) {
764
+ const { headerId: hn, footerId: pn, pageHeight: Rt, pageWidth: bn, marginLeft: Mn, marginBottom: Et } = we, Nt = s.indexOf(we);
765
+ if (x > -1 && Nt === x) {
766
+ switch (Z) {
767
+ case Un.HEADER: {
768
+ const je = (ye = a.get(hn)) == null ? void 0 : ye.get(bn);
769
+ if (je)
770
+ this._liquid.translatePagePadding({
771
+ marginTop: je.marginTop,
772
+ marginLeft: Mn
773
+ });
774
+ else
775
+ throw new Error("header skeleton not found");
776
+ break;
777
+ }
778
+ case Un.FOOTER: {
779
+ const je = (Ne = d.get(pn)) == null ? void 0 : Ne.get(bn);
780
+ if (je)
781
+ this._liquid.translatePagePadding({
782
+ marginTop: Rt - Et + je.marginTop,
783
+ marginLeft: Mn
784
+ });
785
+ else
786
+ throw new Error("footer skeleton not found");
787
+ break;
788
+ }
789
+ }
790
+ break;
791
+ }
792
+ if (this._liquid.translatePagePadding(we), we === F)
793
+ break;
794
+ this._liquid.restorePagePadding(we), this._liquid.translatePage(we, f, u, v);
795
+ }
796
+ switch (N.relativeFrom === H.LINE ? L = b.divides[0].glyphGroup[0] : L = (ge = (le = (Pe = (Ae = z.divides) == null ? void 0 : Ae[0]) == null ? void 0 : Pe.glyphGroup) == null ? void 0 : le[0]) != null ? ge : L, S.positionH = {
797
+ relativeFrom: B.relativeFrom,
798
+ posOffset: O - this._liquid.x - w
799
+ }, B.relativeFrom) {
800
+ case ee.MARGIN: {
801
+ S.positionH.posOffset = O - this._liquid.x - w - F.marginLeft;
802
+ break;
803
+ }
804
+ case ee.COLUMN: {
805
+ S.positionH.posOffset = O - this._liquid.x - w - A.left;
806
+ break;
807
+ }
808
+ }
809
+ switch (S.positionV = {
810
+ relativeFrom: N.relativeFrom,
811
+ posOffset: C - this._liquid.y - I
812
+ }, N.relativeFrom) {
813
+ case H.PAGE: {
814
+ S.positionV.posOffset = C - this._liquid.y - I - F.marginTop;
815
+ break;
816
+ }
817
+ case H.LINE: {
818
+ S.positionV.posOffset = C - this._liquid.y - I - b.top;
819
+ break;
820
+ }
821
+ case H.PARAGRAPH: {
822
+ S.positionV.posOffset = C - this._liquid.y - I - z.top;
823
+ break;
824
+ }
825
+ }
826
+ if (L == null)
827
+ return;
828
+ const ae = r == null ? void 0 : r.findPositionByGlyph(L, x), Be = this._getDocObject();
829
+ if (ae == null || r == null || Be == null || Xn(ae))
830
+ return;
831
+ const Ee = {
832
+ ...ae,
833
+ isBack: V
834
+ }, Ve = Be.document.getOffsetConfig(), ce = new kn(Ve, r), { cursorList: ie } = ce.getRangePointData(Ee, Ee), { startOffset: re } = (xe = Fn(ie)) != null ? xe : {};
835
+ if (re != null)
836
+ return { offset: re, docTransform: S, segmentId: G, segmentPage: x };
837
+ }
838
+ // Update drawing when use transformer to resize it.
839
+ _updateDrawingSize(e, n) {
840
+ const t = [], { drawing: r, width: o, height: s, angle: a } = e, { unitId: d, subUnitId: c } = r;
841
+ let { width: g, height: m, angle: l } = n;
842
+ const { width: f, height: u } = this._getPageContentSize(r);
843
+ g = Math.min(f, g), m = Math.min(u, m), (g !== o || m !== s) && t.push({
844
+ drawingId: r.drawingId,
845
+ key: "size",
846
+ value: {
847
+ width: g,
848
+ height: m
849
+ }
850
+ }), l !== a && t.push({
851
+ drawingId: r.drawingId,
852
+ key: "angle",
853
+ value: l
854
+ }), t.length > 0 && d && c && this._commandService.executeCommand(Ke.id, {
855
+ unitId: d,
856
+ subUnitId: c,
857
+ drawings: t
858
+ });
859
+ }
860
+ // Update inline drawing when use transformer to move it.
861
+ _moveInlineDrawing(e, n, t) {
862
+ const r = this._getInlineDrawingAnchor(e, n, t), { offset: o, segmentId: s, segmentPage: a } = r != null ? r : {};
863
+ return this._commandService.executeCommand(ut.id, {
864
+ unitId: e.unitId,
865
+ subUnitId: e.unitId,
866
+ drawing: e,
867
+ offset: o,
868
+ segmentId: s,
869
+ segmentPage: a,
870
+ needRefreshDrawings: o == null
871
+ });
872
+ }
873
+ // Limit the drawing to the page area, mainly in the vertical direction,
874
+ // and the upper and lower limits cannot exceed the page margin area.
875
+ _limitDrawingInPage(e, n) {
876
+ const t = this._renderManagerService.getRenderById(e.unitId), { left: r, top: o, width: s, height: a, angle: d } = n, c = t == null ? void 0 : t.with(te).getSkeleton(), g = c == null ? void 0 : c.getSkeletonData(), { pages: m } = g != null ? g : {};
877
+ if (g == null || t == null || m == null)
878
+ return {
879
+ left: r,
880
+ top: o,
881
+ width: s,
882
+ height: a,
883
+ angle: d
884
+ };
885
+ const { mainComponent: l } = t, f = l, { top: u, pageLayoutType: v, pageMarginLeft: w, pageMarginTop: I } = f;
886
+ let O = o;
887
+ this._liquid.reset();
888
+ for (const C of m) {
889
+ const { marginBottom: T, pageHeight: M } = C, P = m.indexOf(C), N = m[P + 1];
890
+ if (N == null)
891
+ continue;
892
+ if (Me.hasIntersectionBetweenTwoRanges(
893
+ o,
894
+ o + a,
895
+ this._liquid.y + u + M - T,
896
+ this._liquid.y + u + M + I + N.marginTop
897
+ )) {
898
+ const E = o + a / 2, _ = this._liquid.y + u + M + I / 2;
899
+ E < _ ? O = Math.min(o, this._liquid.y + u + M - T - a) : O = Math.max(o, this._liquid.y + u + M + I + N.marginTop);
900
+ }
901
+ this._liquid.translatePage(C, v, w, I);
902
+ }
903
+ return {
904
+ left: r,
905
+ top: O,
906
+ width: s,
907
+ height: a,
908
+ angle: d
909
+ };
910
+ }
911
+ _nonInlineDrawingTransform(e, n, t = !1) {
912
+ const r = e.isMultiTransform === se.TRUE ? n : this._limitDrawingInPage(e, n);
913
+ if (t && r.top !== n.top)
914
+ return;
915
+ const o = this._getDrawingAnchor(e, r), { offset: s, docTransform: a, segmentId: d, segmentPage: c } = o != null ? o : {};
916
+ return s == null || a == null ? this._updateMultipleDrawingDocTransform(/* @__PURE__ */ new Map([[e.drawingId, n]])) : this._commandService.executeCommand(ft.id, {
917
+ unitId: e.unitId,
918
+ subUnitId: e.unitId,
919
+ drawing: e,
920
+ offset: s,
921
+ docTransform: a,
922
+ segmentId: d,
923
+ segmentPage: c
924
+ });
925
+ }
926
+ _getSceneAndTransformerByDrawingSearch(e) {
927
+ if (e == null)
928
+ return;
929
+ const n = this._renderManagerService.getRenderById(e), t = n == null ? void 0 : n.scene;
930
+ if (t == null)
931
+ return;
932
+ const r = t.getTransformerByCreate();
933
+ return { scene: t, transformer: r };
934
+ }
935
+ _getTransformCoordForDocumentOffset(e, n, t, r) {
936
+ const { documentTransform: o } = e.getOffsetConfig(), s = n.transformVector2SceneCoord(mi.FromArray([t, r]));
937
+ if (s)
938
+ return o.clone().invert().applyPoint(s);
939
+ }
940
+ _createOrUpdateInlineAnchor(e, n) {
941
+ const t = this._renderManagerService.getRenderById(e);
942
+ if (t == null)
943
+ return;
944
+ const { mainComponent: r, scene: o } = t, s = r, {
945
+ docsLeft: a,
946
+ docsTop: d
947
+ } = s.getOffsetConfig(), c = yi(n), { left: g, top: m, height: l } = c, f = g + a, u = m + d;
948
+ if (this._anchorShape) {
949
+ this._anchorShape.transformByState({ left: f, top: u, height: l }), this._anchorShape.show();
950
+ return;
951
+ }
952
+ const v = 6, w = new ui($i + Me.generateRandomId(v), {
953
+ left: f,
954
+ top: u,
955
+ height: l,
956
+ strokeWidth: 2,
957
+ stroke: fi(kt.darkGray, 1),
958
+ evented: !1
959
+ });
960
+ this._anchorShape = w, o.addObject(w, Pi);
961
+ }
962
+ _getDocObject() {
963
+ return bi(this._univerInstanceService, this._renderManagerService);
964
+ }
965
+ _getPageContentSize(e) {
966
+ const n = this._renderManagerService.getRenderById(e.unitId), t = n == null ? void 0 : n.with(te).getSkeleton(), r = 500, o = 500, s = t == null ? void 0 : t.getSkeletonData();
967
+ if (s == null || n == null)
968
+ return {
969
+ width: r,
970
+ height: o
971
+ };
972
+ const { pages: a } = s;
973
+ let d = null;
974
+ for (const c of a) {
975
+ const { skeDrawings: g } = c;
976
+ if (g.has(e.drawingId)) {
977
+ d = c;
978
+ break;
979
+ }
980
+ }
981
+ if (d) {
982
+ const { pageWidth: c, pageHeight: g, marginLeft: m, marginBottom: l, marginRight: f, marginTop: u } = d;
983
+ return {
984
+ width: Math.max(r, c - m - f),
985
+ height: Math.max(o, g - u - l)
986
+ };
987
+ } else
988
+ return {
989
+ width: r,
990
+ height: o
991
+ };
992
+ }
993
+ };
994
+ an = ji([
995
+ Je(0, $),
996
+ Je(1, q),
997
+ Je(2, _e),
998
+ Je(3, J)
999
+ ], an);
1000
+ var he = function() {
1001
+ return he = Object.assign || function(i) {
1002
+ for (var e, n = 1, t = arguments.length; n < t; n++) {
1003
+ e = arguments[n];
1004
+ for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (i[r] = e[r]);
1005
+ }
1006
+ return i;
1007
+ }, he.apply(this, arguments);
1008
+ }, zi = function(i, e) {
1009
+ var n = {};
1010
+ for (var t in i) Object.prototype.hasOwnProperty.call(i, t) && e.indexOf(t) < 0 && (n[t] = i[t]);
1011
+ if (i != null && typeof Object.getOwnPropertySymbols == "function")
1012
+ for (var r = 0, t = Object.getOwnPropertySymbols(i); r < t.length; r++)
1013
+ e.indexOf(t[r]) < 0 && Object.prototype.propertyIsEnumerable.call(i, t[r]) && (n[t[r]] = i[t[r]]);
1014
+ return n;
1015
+ }, ht = at(function(i, e) {
1016
+ var n = i.icon, t = i.id, r = i.className, o = i.extend, s = zi(i, ["icon", "id", "className", "extend"]), a = "univerjs-icon univerjs-icon-".concat(t, " ").concat(r || "").trim(), d = Ui("_".concat(Ki()));
1017
+ return pt(n, "".concat(t), { defIds: n.defIds, idSuffix: d.current }, he({ ref: e, className: a }, s), o);
1018
+ });
1019
+ function pt(i, e, n, t, r) {
1020
+ return ct(i.tag, he(he({ key: e }, Xi(i, n, r)), t), (qi(i, n).children || []).map(function(o, s) {
1021
+ return pt(o, "".concat(e, "-").concat(i.tag, "-").concat(s), n, void 0, r);
1022
+ }));
1023
+ }
1024
+ function Xi(i, e, n) {
1025
+ var t = he({}, i.attrs);
1026
+ n != null && n.colorChannel1 && t.fill === "colorChannel1" && (t.fill = n.colorChannel1), i.tag === "mask" && t.id && (t.id = t.id + e.idSuffix), Object.entries(t).forEach(function(o) {
1027
+ var s = o[0], a = o[1];
1028
+ s === "mask" && typeof a == "string" && (t[s] = a.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
1029
+ });
1030
+ var r = e.defIds;
1031
+ return !r || r.length === 0 || (i.tag === "use" && t["xlink:href"] && (t["xlink:href"] = t["xlink:href"] + e.idSuffix), Object.entries(t).forEach(function(o) {
1032
+ var s = o[0], a = o[1];
1033
+ typeof a == "string" && (t[s] = a.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
1034
+ })), t;
1035
+ }
1036
+ function qi(i, e) {
1037
+ var n, t = e.defIds;
1038
+ return !t || t.length === 0 ? i : i.tag === "defs" && (!((n = i.children) === null || n === void 0) && n.length) ? he(he({}, i), { children: i.children.map(function(r) {
1039
+ return typeof r.attrs.id == "string" && t && t.indexOf(r.attrs.id) > -1 ? he(he({}, r), { attrs: he(he({}, r.attrs), { id: r.attrs.id + e.idSuffix }) }) : r;
1040
+ }) }) : i;
1041
+ }
1042
+ function Ki() {
1043
+ return Math.random().toString(36).substring(2, 8);
1044
+ }
1045
+ ht.displayName = "UniverIcon";
1046
+ var Yi = { 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" } }] }, wt = at(function(i, e) {
1047
+ return ct(ht, Object.assign({}, i, {
1048
+ id: "add-image-single",
1049
+ ref: e,
1050
+ icon: Yi
1051
+ }));
1052
+ });
1053
+ wt.displayName = "AddImageSingle";
1054
+ const yn = {
1055
+ id: "doc.command.remove-doc-image",
1056
+ type: Y.COMMAND,
1057
+ // eslint-disable-next-line max-lines-per-function
1058
+ handler: (i, e) => {
1059
+ var M, P, N, B;
1060
+ const n = i.get($), t = i.get(q), r = i.get(J), o = t.getCurrentUniverDocInstance();
1061
+ if (e == null || o == null)
1062
+ return !1;
1063
+ const s = r.getRenderById(e.unitId).with(Re), { drawings: a } = e, d = (M = s.getSegment()) != null ? M : "", c = new Dn(), g = X.getInstance(), m = (N = (P = o.getSelfOrHeaderFooterModel(d).getBody()) == null ? void 0 : P.customBlocks) != null ? N : [], l = a.map((E) => m.find((_) => _.blockId === E.drawingId)).filter((E) => !!E).sort((E, _) => E.startIndex > _.startIndex ? 1 : -1), f = a[0].unitId, u = new Ft();
1064
+ u.reset();
1065
+ const v = l[0].startIndex, w = [
1066
+ {
1067
+ startOffset: v,
1068
+ endOffset: v
1069
+ }
1070
+ ], I = {
1071
+ id: ne.id,
1072
+ params: {
1073
+ unitId: f,
1074
+ actions: [],
1075
+ textRanges: w
1076
+ }
1077
+ }, O = [];
1078
+ for (const E of l) {
1079
+ const { startIndex: _ } = E;
1080
+ _ > u.cursor && c.push({
1081
+ t: Q.RETAIN,
1082
+ len: _ - u.cursor
1083
+ }), c.push({
1084
+ t: Q.DELETE,
1085
+ len: 1
1086
+ }), u.moveCursorTo(_ + 1);
1087
+ }
1088
+ const C = qe(o, d);
1089
+ O.push(g.editOp(c.serialize(), C));
1090
+ for (const E of l) {
1091
+ const { blockId: _ } = E, L = ((B = o.getDrawings()) != null ? B : {})[_], x = o.getDrawingsOrder().indexOf(_), V = g.removeOp(["drawings", _], L), S = g.removeOp(["drawingsOrder", x], _);
1092
+ O.push(V), O.push(S);
1093
+ }
1094
+ return I.params.actions = O.reduce((E, _) => X.compose(E, _), null), !!n.syncExecuteCommand(I.id, I.params);
1095
+ }
1096
+ }, vt = {
1097
+ id: "doc.command.delete-drawing",
1098
+ type: Y.COMMAND,
1099
+ handler: (i) => {
1100
+ const e = i.get($), t = i.get(Ue).getFocusDrawings();
1101
+ if (t.length === 0)
1102
+ return !1;
1103
+ const { unitId: r } = t[0], o = t.map((s) => {
1104
+ const { unitId: a, subUnitId: d, drawingId: c, drawingType: g } = s;
1105
+ return {
1106
+ unitId: a,
1107
+ subUnitId: d,
1108
+ drawingId: c,
1109
+ drawingType: g
1110
+ };
1111
+ });
1112
+ return e.executeCommand(yn.id, {
1113
+ unitId: r,
1114
+ drawings: o
1115
+ });
1116
+ }
1117
+ }, It = {
1118
+ id: "doc.command.group-doc-image",
1119
+ type: Y.COMMAND,
1120
+ handler: (i, e) => {
1121
+ i.get($), i.get(Yn);
1122
+ const n = i.get(Ue);
1123
+ if (!e) return !1;
1124
+ const t = [];
1125
+ e.forEach(({ parent: g, children: m }) => {
1126
+ t.push(g.unitId), m.forEach((l) => {
1127
+ t.push(l.unitId);
1128
+ });
1129
+ });
1130
+ const r = n.getGroupDrawingOp(e), { unitId: o, subUnitId: s, undo: a, redo: d, objects: c } = r;
1131
+ return !1;
1132
+ }
1133
+ }, Pn = {
1134
+ id: "doc.command.insert-doc-image",
1135
+ type: Y.COMMAND,
1136
+ // eslint-disable-next-line max-lines-per-function
1137
+ handler: (i, e) => {
1138
+ var P, N, B, E;
1139
+ if (e == null)
1140
+ return !1;
1141
+ const n = i.get($), t = i.get(On), r = i.get(q), o = t.getActiveTextRange(), s = r.getCurrentUniverDocInstance();
1142
+ if (o == null || s == null)
1143
+ return !1;
1144
+ const a = s.getUnitId(), { drawings: d } = e, { collapsed: c, startOffset: g, segmentId: m } = o, l = s.getSelfOrHeaderFooterModel(m).getBody();
1145
+ if (l == null)
1146
+ return !1;
1147
+ const f = new Dn(), u = X.getInstance(), v = [], w = (N = (P = s.getSnapshot().drawingsOrder) == null ? void 0 : P.length) != null ? N : 0;
1148
+ let I = 0;
1149
+ if (c)
1150
+ g > 0 && f.push({
1151
+ t: Q.RETAIN,
1152
+ len: g
1153
+ });
1154
+ else {
1155
+ const _ = Wt.selection.delete([o], l, 0, null, !1);
1156
+ f.push(..._);
1157
+ const L = Mi(l, [o]), G = (B = s.getDrawings()) != null ? B : {}, x = (E = s.getDrawingsOrder()) != null ? E : [], V = L.sort((S, D) => x.indexOf(S) > x.indexOf(D) ? -1 : x.indexOf(S) < x.indexOf(D) ? 1 : 0);
1158
+ if (V.length > 0)
1159
+ for (const S of V) {
1160
+ const D = G[S], R = x.indexOf(S);
1161
+ if (D == null || R < 0)
1162
+ continue;
1163
+ const y = u.removeOp(["drawings", S], D), U = u.removeOp(["drawingsOrder", R], S);
1164
+ v.push(y), v.push(U), I++;
1165
+ }
1166
+ }
1167
+ f.push({
1168
+ t: Q.INSERT,
1169
+ body: {
1170
+ dataStream: "\b".repeat(d.length),
1171
+ customBlocks: d.map((_, L) => ({
1172
+ startIndex: L,
1173
+ blockId: _.drawingId
1174
+ }))
1175
+ },
1176
+ len: d.length
1177
+ });
1178
+ const O = qe(s, m), C = u.editOp(f.serialize(), O);
1179
+ v.push(C);
1180
+ for (const _ of d) {
1181
+ const { drawingId: L } = _, G = u.insertOp(["drawings", L], _), x = u.insertOp(["drawingsOrder", w - I], L);
1182
+ v.push(G), v.push(x);
1183
+ }
1184
+ const T = {
1185
+ id: ne.id,
1186
+ params: {
1187
+ unitId: a,
1188
+ actions: [],
1189
+ textRanges: []
1190
+ }
1191
+ };
1192
+ return T.params.actions = v.reduce((_, L) => X.compose(_, L), null), !!n.syncExecuteCommand(T.id, T.params);
1193
+ }
1194
+ }, _t = {
1195
+ id: "doc.command.set-drawing-arrange",
1196
+ type: Y.COMMAND,
1197
+ handler: (i, e) => {
1198
+ const n = i.get($), t = i.get(Ue);
1199
+ if (e == null)
1200
+ return !1;
1201
+ const { unitId: r, subUnitId: o, drawingIds: s, arrangeType: a } = e, d = { unitId: r, subUnitId: o, drawingIds: s };
1202
+ let c;
1203
+ if (a === Qe.forward ? c = t.getForwardDrawingsOp(d) : a === Qe.backward ? c = t.getBackwardDrawingOp(d) : a === Qe.front ? c = t.getFrontDrawingsOp(d) : a === Qe.back && (c = t.getBackDrawingsOp(d)), c == null)
1204
+ return !1;
1205
+ const { redo: g } = c;
1206
+ if (g == null)
1207
+ return !1;
1208
+ const m = [];
1209
+ let l = Me.deepClone(g);
1210
+ l = l.slice(3), l.unshift("drawingsOrder"), m.push(l);
1211
+ const f = {
1212
+ id: ne.id,
1213
+ params: {
1214
+ unitId: r,
1215
+ actions: [],
1216
+ textRanges: null
1217
+ }
1218
+ };
1219
+ return f.params.actions = m.reduce((v, w) => X.compose(v, w), null), !!n.syncExecuteCommand(f.id, f.params);
1220
+ }
1221
+ }, St = {
1222
+ id: "doc.command.ungroup-doc-image",
1223
+ type: Y.COMMAND,
1224
+ handler: (i, e) => {
1225
+ i.get($), i.get(Yn);
1226
+ const n = i.get(Ue);
1227
+ if (!e) return !1;
1228
+ const t = [];
1229
+ e.forEach(({ parent: g, children: m }) => {
1230
+ t.push(g.unitId), m.forEach((l) => {
1231
+ t.push(l.unitId);
1232
+ });
1233
+ });
1234
+ const r = n.getUngroupDrawingOp(e), { unitId: o, subUnitId: s, undo: a, redo: d, objects: c } = r;
1235
+ return !1;
1236
+ }
1237
+ };
1238
+ var Zi = Object.getOwnPropertyDescriptor, Qi = (i, e, n, t) => {
1239
+ for (var r = t > 1 ? void 0 : t ? Zi(e, n) : e, o = i.length - 1, s; o >= 0; o--)
1240
+ (s = i[o]) && (r = s(r) || r);
1241
+ return r;
1242
+ }, me = (i, e) => (n, t) => e(n, t, i);
1243
+ let cn = class extends Ge {
1244
+ constructor(i, e, n, t, r, o, s, a, d, c, g, m, l) {
1245
+ super(), this._context = i, this._commandService = e, this._docSelectionManagerService = n, this._renderManagerSrv = t, this._imageIoService = r, this._docDrawingService = o, this._drawingManagerService = s, this._contextService = a, this._messageService = d, this._localeService = c, this._docSelectionRenderService = g, this._docRefreshDrawingsService = m, this._fileOpenerService = l, this._updateOrderListener(), this._groupDrawingListener(), this._focusDrawingListener(), this._transformDrawingListener(), this._editAreaChangeListener();
1246
+ }
1247
+ async insertDocImage() {
1248
+ const i = await this._fileOpenerService.openFile({
1249
+ multiple: !0,
1250
+ accept: ei.map((n) => `.${n.replace("image/", "")}`).join(",")
1251
+ }), e = i.length;
1252
+ return e > Nn ? (this._messageService.show({
1253
+ type: Vn.Error,
1254
+ content: this._localeService.t("update-status.exceedMaxCount", String(Nn))
1255
+ }), !1) : e === 0 ? !1 : (await this._insertFloatImages(i), !0);
1256
+ }
1257
+ // eslint-disable-next-line max-lines-per-function
1258
+ async _insertFloatImages(i) {
1259
+ let e = [];
1260
+ try {
1261
+ e = await Promise.all(i.map((r) => this._imageIoService.saveImage(r)));
1262
+ } catch (r) {
1263
+ const o = r.message;
1264
+ let s = "";
1265
+ switch (o) {
1266
+ case vn.ERROR_EXCEED_SIZE:
1267
+ s = this._localeService.t("update-status.exceedMaxSize", String(ni / (1024 * 1024)));
1268
+ break;
1269
+ case vn.ERROR_IMAGE_TYPE:
1270
+ s = this._localeService.t("update-status.invalidImageType");
1271
+ break;
1272
+ case vn.ERROR_IMAGE:
1273
+ s = this._localeService.t("update-status.invalidImage");
1274
+ break;
1275
+ }
1276
+ this._messageService.show({
1277
+ type: Vn.Error,
1278
+ content: s
1279
+ });
1280
+ }
1281
+ if (e.length === 0)
1282
+ return;
1283
+ const { unitId: n } = this._context, t = [];
1284
+ for (const r of e) {
1285
+ if (r == null)
1286
+ continue;
1287
+ const { imageId: o, imageSourceType: s, source: a, base64Cache: d } = r, { width: c, height: g, image: m } = await ti(d || "");
1288
+ this._imageIoService.addImageSourceCache(o, s, m);
1289
+ let l = 1;
1290
+ if (c > An || g > xn) {
1291
+ const w = An / c, I = xn / g;
1292
+ l = Math.min(w, I);
1293
+ }
1294
+ const f = this._getImagePosition(c * l, g * l);
1295
+ if (f == null)
1296
+ return;
1297
+ const u = {
1298
+ unitId: n,
1299
+ subUnitId: n,
1300
+ drawingId: o,
1301
+ drawingType: rn.DRAWING_IMAGE,
1302
+ imageSourceType: s,
1303
+ source: a,
1304
+ transform: tt(f),
1305
+ docTransform: f,
1306
+ behindDoc: se.FALSE,
1307
+ title: "",
1308
+ description: "",
1309
+ layoutType: W.INLINE,
1310
+ // Insert inline drawing by default.
1311
+ wrapText: Xe.BOTH_SIDES,
1312
+ distB: 0,
1313
+ distL: 0,
1314
+ distR: 0,
1315
+ distT: 0
1316
+ };
1317
+ this._isInsertInHeaderFooter() && (u.isMultiTransform = se.TRUE, u.transforms = u.transform ? [u.transform] : null), t.push(u);
1318
+ }
1319
+ this._commandService.executeCommand(Pn.id, {
1320
+ unitId: n,
1321
+ drawings: t
1322
+ });
1323
+ }
1324
+ _isInsertInHeaderFooter() {
1325
+ var t;
1326
+ const { unitId: i } = this._context, e = (t = this._renderManagerSrv.getRenderById(i)) == null ? void 0 : t.with(te).getViewModel(), n = e == null ? void 0 : e.getEditArea();
1327
+ return n === We.HEADER || n === We.FOOTER;
1328
+ }
1329
+ _getImagePosition(i, e) {
1330
+ const n = this._docSelectionRenderService.getActiveTextRange(), t = (n == null ? void 0 : n.getAbsolutePosition()) || {
1331
+ left: 0
1332
+ };
1333
+ return {
1334
+ size: {
1335
+ width: i,
1336
+ height: e
1337
+ },
1338
+ positionH: {
1339
+ relativeFrom: ee.PAGE,
1340
+ posOffset: t.left
1341
+ },
1342
+ positionV: {
1343
+ relativeFrom: H.PARAGRAPH,
1344
+ posOffset: 0
1345
+ },
1346
+ angle: 0
1347
+ };
1348
+ }
1349
+ _updateOrderListener() {
1350
+ this._drawingManagerService.featurePluginOrderUpdate$.subscribe((i) => {
1351
+ const { unitId: e, subUnitId: n, drawingIds: t, arrangeType: r } = i;
1352
+ this._commandService.executeCommand(_t.id, {
1353
+ unitId: e,
1354
+ subUnitId: n,
1355
+ drawingIds: t,
1356
+ arrangeType: r
1357
+ });
1358
+ });
1359
+ }
1360
+ _groupDrawingListener() {
1361
+ this._drawingManagerService.featurePluginGroupUpdate$.subscribe((i) => {
1362
+ this._commandService.executeCommand(It.id, i);
1363
+ }), this._drawingManagerService.featurePluginUngroupUpdate$.subscribe((i) => {
1364
+ this._commandService.executeCommand(St.id, i);
1365
+ });
1366
+ }
1367
+ _getCurrentSceneAndTransformer() {
1368
+ const { scene: i, mainComponent: e } = this._context;
1369
+ if (i == null || e == null)
1370
+ return;
1371
+ const n = i.getTransformerByCreate(), { docsLeft: t, docsTop: r } = e.getOffsetConfig();
1372
+ return { scene: i, transformer: n, docsLeft: t, docsTop: r };
1373
+ }
1374
+ _transformDrawingListener() {
1375
+ const i = this._getCurrentSceneAndTransformer();
1376
+ if (i && i.transformer)
1377
+ this.disposeWithMe(i.transformer.changeEnd$.pipe(st(30)).subscribe((e) => {
1378
+ this._docSelectionManagerService.refreshSelection();
1379
+ }));
1380
+ else
1381
+ throw new Error("transformer is not init");
1382
+ }
1383
+ _focusDrawingListener() {
1384
+ this.disposeWithMe(
1385
+ this._drawingManagerService.focus$.subscribe((i) => {
1386
+ var r;
1387
+ const { transformer: e, docsLeft: n, docsTop: t } = (r = this._getCurrentSceneAndTransformer()) != null ? r : {};
1388
+ if (i == null || i.length === 0)
1389
+ this._contextService.setContextValue(on, !1), this._docDrawingService.focusDrawing([]), e && e.resetProps({
1390
+ zeroTop: 0,
1391
+ zeroLeft: 0
1392
+ });
1393
+ else {
1394
+ this._contextService.setContextValue(on, !0), this._docDrawingService.focusDrawing(i), this._setDrawingSelections(i);
1395
+ const o = this._docSelectionRenderService.getSegment(), s = this._findSegmentIdByDrawingId(i[0].drawingId);
1396
+ o !== s && this._docSelectionRenderService.setSegment(s), e && e.resetProps({
1397
+ zeroTop: t,
1398
+ zeroLeft: n
1399
+ });
1400
+ }
1401
+ })
1402
+ );
1403
+ }
1404
+ _findSegmentIdByDrawingId(i) {
1405
+ var s, a, d;
1406
+ const { unit: e } = this._context, { body: n, headers: t = {}, footers: r = {} } = e.getSnapshot();
1407
+ if (((s = n == null ? void 0 : n.customBlocks) != null ? s : []).some((c) => c.blockId === i))
1408
+ return "";
1409
+ for (const c of Object.keys(t))
1410
+ if ((a = t[c].body.customBlocks) != null && a.some((g) => g.blockId === i))
1411
+ return c;
1412
+ for (const c of Object.keys(r))
1413
+ if ((d = r[c].body.customBlocks) != null && d.some((g) => g.blockId === i))
1414
+ return c;
1415
+ return "";
1416
+ }
1417
+ // Update drawings edit status and opacity. You can not edit header footer images when you are editing body. and vice verse.
1418
+ _updateDrawingsEditStatus() {
1419
+ var a;
1420
+ const { unit: i, scene: e, unitId: n } = this._context, t = (a = this._renderManagerSrv.getRenderById(n)) == null ? void 0 : a.with(te).getViewModel();
1421
+ if (t == null || i == null)
1422
+ return;
1423
+ const r = i.getSnapshot(), { drawings: o = {} } = r, s = t.getEditArea() === We.BODY;
1424
+ for (const d of Object.keys(o)) {
1425
+ const c = o[d], g = ii({ unitId: n, drawingId: c.drawingId, subUnitId: n }), m = e.fuzzyMathObjects(g, !0);
1426
+ if (m.length)
1427
+ for (const l of m) {
1428
+ e.detachTransformerFrom(l);
1429
+ try {
1430
+ l.setOpacity(0.5);
1431
+ } catch {
1432
+ }
1433
+ if (s && c.isMultiTransform !== se.TRUE || !s && c.isMultiTransform === se.TRUE) {
1434
+ c.allowTransform !== !1 && e.attachTransformerTo(l);
1435
+ try {
1436
+ l.setOpacity(1);
1437
+ } catch {
1438
+ }
1439
+ }
1440
+ }
1441
+ }
1442
+ }
1443
+ _editAreaChangeListener() {
1444
+ var n;
1445
+ const { unitId: i } = this._context, e = (n = this._renderManagerSrv.getRenderById(i)) == null ? void 0 : n.with(te).getViewModel();
1446
+ e != null && (this._updateDrawingsEditStatus(), this.disposeWithMe(
1447
+ e.editAreaChange$.subscribe(() => {
1448
+ this._updateDrawingsEditStatus();
1449
+ })
1450
+ ), this._docRefreshDrawingsService.refreshDrawings$.subscribe((t) => {
1451
+ t != null && queueMicrotask(() => {
1452
+ this._updateDrawingsEditStatus();
1453
+ });
1454
+ }), this.disposeWithMe(
1455
+ this._commandService.onCommandExecuted(async (t) => {
1456
+ t.id === ne.id && queueMicrotask(() => {
1457
+ this._updateDrawingsEditStatus();
1458
+ });
1459
+ })
1460
+ ));
1461
+ }
1462
+ _setDrawingSelections(i) {
1463
+ var r, o;
1464
+ const { unit: e } = this._context, n = (o = (r = e.getSnapshot().body) == null ? void 0 : r.customBlocks) != null ? o : [], t = i.map((s) => {
1465
+ const a = s.drawingId, d = n.find((c) => c.blockId === a);
1466
+ return d ? d.startIndex : null;
1467
+ }).filter((s) => s !== null).map((s) => ({ startOffset: s, endOffset: s + 1 }));
1468
+ this._docSelectionManagerService.replaceDocRanges(t);
1469
+ }
1470
+ };
1471
+ cn = Qi([
1472
+ me(1, $),
1473
+ me(2, pe(On)),
1474
+ me(3, J),
1475
+ me(4, Jt),
1476
+ me(5, Ue),
1477
+ me(6, _e),
1478
+ me(7, Zn),
1479
+ me(8, wi),
1480
+ me(9, pe(un)),
1481
+ me(10, pe(Re)),
1482
+ me(11, pe(fn)),
1483
+ me(12, vi)
1484
+ ], cn);
1485
+ const Dt = {
1486
+ id: "doc.command.insert-float-image",
1487
+ type: Y.COMMAND,
1488
+ handler: (i) => {
1489
+ var t, r;
1490
+ const e = i.get(q), n = i.get(J);
1491
+ return (r = (t = hi(Ie.UNIVER_DOC, e, n)) == null ? void 0 : t.with(cn).insertDocImage()) != null ? r : !1;
1492
+ }
1493
+ }, Ye = {
1494
+ id: "doc.command.move-drawing",
1495
+ type: Y.COMMAND,
1496
+ handler: (i, e) => {
1497
+ const n = i.get($), t = i.get(Ue), r = i.get(q), o = i.get(J), { direction: s } = e, a = t.getFocusDrawings();
1498
+ if (a.length === 0)
1499
+ return !1;
1500
+ const d = a[0].unitId, c = o.getRenderById(d), g = c == null ? void 0 : c.scene;
1501
+ if (g == null)
1502
+ return !1;
1503
+ const m = g.getTransformerByCreate(), l = r.getUniverDocInstance(d), f = a.map((v) => {
1504
+ var P, N, B, E, _;
1505
+ const { drawingId: w } = v, I = (P = l == null ? void 0 : l.getSnapshot().drawings) == null ? void 0 : P[w];
1506
+ if (I == null || I.layoutType === W.INLINE)
1507
+ return null;
1508
+ const { positionH: O, positionV: C } = I.docTransform, T = { ...O }, M = { ...C };
1509
+ return s === fe.UP ? M.posOffset = ((N = M.posOffset) != null ? N : 0) - 2 : s === fe.DOWN ? M.posOffset = ((B = M.posOffset) != null ? B : 0) + 2 : s === fe.LEFT ? T.posOffset = ((E = T.posOffset) != null ? E : 0) - 2 : s === fe.RIGHT && (T.posOffset = ((_ = T.posOffset) != null ? _ : 0) + 2), {
1510
+ drawingId: w,
1511
+ key: s === fe.UP || s === fe.DOWN ? "positionV" : "positionH",
1512
+ value: s === fe.UP || s === fe.DOWN ? M : T
1513
+ };
1514
+ }).filter((v) => v != null);
1515
+ if (f.length === 0)
1516
+ return !1;
1517
+ const u = n.syncExecuteCommand(Ke.id, {
1518
+ unitId: d,
1519
+ subUnitId: d,
1520
+ drawings: f
1521
+ });
1522
+ return m.refreshControls(), !!u;
1523
+ }
1524
+ }, Ji = {
1525
+ id: "doc.operation.clear-drawing-transformer",
1526
+ type: Y.MUTATION,
1527
+ handler: (i, e) => {
1528
+ const n = i.get(J);
1529
+ return e.forEach((t) => {
1530
+ var r, o;
1531
+ (o = (r = n.getRenderById(t)) == null ? void 0 : r.scene.getTransformer()) == null || o.debounceRefreshControls();
1532
+ }), !0;
1533
+ }
1534
+ }, Ct = "COMPONENT_DOC_DRAWING_PANEL", Ot = {
1535
+ id: "sidebar.operation.doc-image",
1536
+ type: Y.COMMAND,
1537
+ handler: async (i, e) => {
1538
+ const n = i.get(Ii), t = i.get(un), r = i.get(_e);
1539
+ switch (e.value) {
1540
+ case "open":
1541
+ n.open({
1542
+ header: { title: t.t("docImage.panel.title") },
1543
+ children: { label: Ct },
1544
+ onClose: () => {
1545
+ r.focusDrawing(null);
1546
+ },
1547
+ width: 360
1548
+ });
1549
+ break;
1550
+ case "close":
1551
+ default:
1552
+ n.close();
1553
+ break;
1554
+ }
1555
+ return !0;
1556
+ }
1557
+ }, Tt = {
1558
+ id: "doc.operation.edit-doc-image",
1559
+ type: Y.OPERATION,
1560
+ handler: (i, e) => {
1561
+ const n = i.get(_e), t = i.get($);
1562
+ return e == null ? !1 : (n.focusDrawing([e]), t.executeCommand(Ot.id, { value: "open" }), !0);
1563
+ }
1564
+ }, er = "univer-image-common-panel", nr = "univer-image-common-panel-grid", tr = "univer-image-common-panel-border", ir = "univer-image-common-panel-title", rr = "univer-image-common-panel-subtitle", or = "univer-image-common-panel-row", sr = "univer-image-common-panel-column", ar = "univer-image-common-panel-span2", cr = "univer-image-common-panel-input", h = {
1565
+ imageCommonPanel: er,
1566
+ imageCommonPanelGrid: nr,
1567
+ imageCommonPanelBorder: tr,
1568
+ imageCommonPanelTitle: ir,
1569
+ imageCommonPanelSubtitle: rr,
1570
+ imageCommonPanelRow: or,
1571
+ imageCommonPanelColumn: sr,
1572
+ imageCommonPanelSpan2: ar,
1573
+ imageCommonPanelInput: cr
1574
+ }, qn = -1e3, Kn = 1e3, dr = (i) => {
1575
+ const e = ve($), n = ve(un), t = ve(_e), r = ve(J), o = ve(q), { drawings: s } = i, a = s[0];
1576
+ if (a == null)
1577
+ return;
1578
+ const { unitId: d } = a, c = o.getUniverDocInstance(d), g = c == null ? void 0 : c.getSnapshot().documentStyle.documentFlavor, m = r.getRenderById(d), l = m == null ? void 0 : m.scene;
1579
+ if (l == null)
1580
+ return;
1581
+ const f = l.getTransformerByCreate(), u = [{
1582
+ label: n.t("image-position.column"),
1583
+ value: String(ee.COLUMN)
1584
+ }, {
1585
+ label: n.t("image-position.page"),
1586
+ value: String(ee.PAGE)
1587
+ }, {
1588
+ label: n.t("image-position.margin"),
1589
+ value: String(ee.MARGIN)
1590
+ }], v = [{
1591
+ label: n.t("image-position.line"),
1592
+ value: String(H.LINE),
1593
+ disabled: g === wn.MODERN
1594
+ }, {
1595
+ label: n.t("image-position.page"),
1596
+ value: String(H.PAGE),
1597
+ disabled: g === wn.MODERN
1598
+ }, {
1599
+ label: n.t("image-position.margin"),
1600
+ value: String(H.MARGIN),
1601
+ disabled: g === wn.MODERN
1602
+ }, {
1603
+ label: n.t("image-position.paragraph"),
1604
+ value: String(H.PARAGRAPH)
1605
+ }], [w, I] = oe(!0), [O, C] = oe({
1606
+ relativeFrom: ee.PAGE,
1607
+ posOffset: 0
1608
+ }), [T, M] = oe({
1609
+ relativeFrom: H.PAGE,
1610
+ posOffset: 0
1611
+ }), [P, N] = oe(!0), [B, E] = oe(!0);
1612
+ function _(D, R) {
1613
+ var b;
1614
+ D === "positionH" ? C(R) : M(R);
1615
+ const y = t.getFocusDrawings();
1616
+ if (y.length === 0)
1617
+ return;
1618
+ const U = y.map((A) => ({
1619
+ unitId: A.unitId,
1620
+ subUnitId: A.subUnitId,
1621
+ drawingId: A.drawingId
1622
+ }));
1623
+ e.executeCommand(Ke.id, {
1624
+ unitId: y[0].unitId,
1625
+ subUnitId: y[0].unitId,
1626
+ drawings: U.map((A) => ({
1627
+ drawingId: A.drawingId,
1628
+ key: D,
1629
+ value: R
1630
+ }))
1631
+ });
1632
+ const k = (b = r.getRenderById(d)) == null ? void 0 : b.with(Re);
1633
+ k && k.blur(), f.refreshControls();
1634
+ }
1635
+ function L(D) {
1636
+ var re, De, Ce;
1637
+ const R = O.relativeFrom, y = O.posOffset, U = Number(D);
1638
+ if (R === U)
1639
+ return;
1640
+ const k = t.getFocusDrawings();
1641
+ if (k.length === 0)
1642
+ return;
1643
+ const b = k[0].drawingId, A = k[0].unitId;
1644
+ let z = null, F = 0;
1645
+ const Z = (re = r.getRenderById(A)) == null ? void 0 : re.with(te).getSkeleton(), ae = Z == null ? void 0 : Z.getSkeletonData();
1646
+ if (ae == null)
1647
+ return;
1648
+ const { pages: Be, skeHeaders: Ee, skeFooters: Ve } = ae;
1649
+ for (const de of Be) {
1650
+ const { marginLeft: Te, skeDrawings: ye, headerId: Ne, footerId: Ae, pageWidth: Pe } = de;
1651
+ if (ye.has(b)) {
1652
+ z = ye.get(b), F = Te;
1653
+ break;
1654
+ }
1655
+ const le = (De = Ee.get(Ne)) == null ? void 0 : De.get(Pe);
1656
+ if (le != null && le.skeDrawings.has(b)) {
1657
+ z = le == null ? void 0 : le.skeDrawings.get(b), F = Te;
1658
+ break;
1659
+ }
1660
+ const ge = (Ce = Ve.get(Ae)) == null ? void 0 : Ce.get(Pe);
1661
+ if (ge != null && ge.skeDrawings.has(b)) {
1662
+ z = ge == null ? void 0 : ge.skeDrawings.get(b), F = Te;
1663
+ break;
1664
+ }
1665
+ }
1666
+ if (z == null)
1667
+ return;
1668
+ let ce = 0;
1669
+ R === ee.COLUMN ? ce -= z.columnLeft : R === ee.MARGIN && (ce -= F), U === ee.COLUMN ? ce += z.columnLeft : U === ee.MARGIN ? ce += F : ee.PAGE;
1670
+ const ie = {
1671
+ relativeFrom: U,
1672
+ posOffset: (y != null ? y : 0) - ce
1673
+ };
1674
+ _("positionH", ie);
1675
+ }
1676
+ function G(D) {
1677
+ var ye, Ne, Ae, Pe, le, ge;
1678
+ const R = T.relativeFrom, y = T.posOffset, U = Number(D);
1679
+ if (R === U)
1680
+ return;
1681
+ const k = t.getFocusDrawings();
1682
+ if (k.length === 0)
1683
+ return;
1684
+ const { drawingId: b, unitId: A } = k[0], z = o.getUniverDocInstance(A), F = (ye = r.getRenderById(A)) == null ? void 0 : ye.with(te).getSkeleton(), Z = (Ne = r.getRenderById(A)) == null ? void 0 : Ne.with(Re), ae = Z == null ? void 0 : Z.getSegment(), Be = Z == null ? void 0 : Z.getSegmentPage(), Ee = (Pe = (Ae = z == null ? void 0 : z.getSelfOrHeaderFooterModel(ae).getBody()) == null ? void 0 : Ae.customBlocks) == null ? void 0 : Pe.find((xe) => xe.blockId === b);
1685
+ if (Ee == null || F == null || Z == null)
1686
+ return;
1687
+ const { startIndex: Ve } = Ee, ce = F.findNodeByCharIndex(Ve, ae, Be), ie = (le = ce == null ? void 0 : ce.parent) == null ? void 0 : le.parent, re = ie == null ? void 0 : ie.parent, De = re == null ? void 0 : re.lines.find((xe) => xe.paragraphIndex === (ie == null ? void 0 : ie.paragraphIndex) && xe.paragraphStart), Ce = (ge = re == null ? void 0 : re.parent) == null ? void 0 : ge.parent;
1688
+ if (ce == null || ie == null || De == null || re == null || Ce == null)
1689
+ return;
1690
+ let de = 0;
1691
+ R === H.PARAGRAPH ? de -= De.top : R === H.LINE ? de -= ie.top : R === H.PAGE && (de += Ce.marginTop), U === H.PARAGRAPH ? de += De.top : U === H.LINE ? de += ie.top : U === H.PAGE && (de -= Ce.marginTop);
1692
+ const Te = {
1693
+ relativeFrom: U,
1694
+ posOffset: (y != null ? y : 0) - de
1695
+ };
1696
+ _("positionV", Te);
1697
+ }
1698
+ function x(D) {
1699
+ var A;
1700
+ const R = c == null ? void 0 : c.getSnapshot(), y = (A = R == null ? void 0 : R.drawings) == null ? void 0 : A[D.drawingId];
1701
+ if (y == null)
1702
+ return;
1703
+ const { layoutType: U } = y, {
1704
+ positionH: k,
1705
+ positionV: b
1706
+ } = y.docTransform;
1707
+ C(k), M(b), I(U === W.INLINE), N(b.relativeFrom === H.PARAGRAPH || b.relativeFrom === H.LINE);
1708
+ }
1709
+ function V() {
1710
+ const D = t.getFocusDrawings();
1711
+ D.length !== 0 && x(D[0]);
1712
+ }
1713
+ function S(D) {
1714
+ N(D), G(String(D ? H.PARAGRAPH : H.PAGE));
1715
+ }
1716
+ return Tn(() => {
1717
+ V();
1718
+ const D = t.focus$.subscribe((y) => {
1719
+ if (y.length === 0) {
1720
+ E(!1);
1721
+ return;
1722
+ }
1723
+ E(!0), x(y[0]);
1724
+ }), R = e.onCommandExecuted(async (y) => {
1725
+ y.id === ne.id && V();
1726
+ });
1727
+ return () => {
1728
+ D.unsubscribe(), R.dispose();
1729
+ };
1730
+ }, []), /* @__PURE__ */ K("div", { className: j(h.imageCommonPanelGrid, h.imageCommonPanelBorder), style: { display: B ? "block" : "none" }, children: [
1731
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelTitle), children: /* @__PURE__ */ p("div", { children: n.t("image-position.title") }) }) }),
1732
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelSubtitle), children: /* @__PURE__ */ p("div", { children: n.t("image-position.horizontal") }) }) }),
1733
+ /* @__PURE__ */ K("div", { className: h.imageCommonPanelRow, children: [
1734
+ /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelSpan2), children: /* @__PURE__ */ K("label", { children: [
1735
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: n.t("image-position.absolutePosition") }) }),
1736
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: /* @__PURE__ */ p(
1737
+ Fe,
1738
+ {
1739
+ min: qn,
1740
+ max: Kn,
1741
+ precision: 1,
1742
+ disabled: w,
1743
+ value: O.posOffset,
1744
+ onChange: (D) => {
1745
+ _("positionH", {
1746
+ relativeFrom: O.relativeFrom,
1747
+ posOffset: D
1748
+ });
1749
+ },
1750
+ className: h.imageCommonPanelInput
1751
+ }
1752
+ ) }) })
1753
+ ] }) }),
1754
+ /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelSpan2), children: /* @__PURE__ */ K("label", { children: [
1755
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: n.t("image-position.toTheRightOf") }) }),
1756
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: /* @__PURE__ */ p(
1757
+ jn,
1758
+ {
1759
+ value: String(O.relativeFrom),
1760
+ disabled: w,
1761
+ options: u,
1762
+ onChange: L
1763
+ }
1764
+ ) }) })
1765
+ ] }) })
1766
+ ] }),
1767
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelSubtitle), children: /* @__PURE__ */ p("div", { children: n.t("image-position.vertical") }) }) }),
1768
+ /* @__PURE__ */ K("div", { className: h.imageCommonPanelRow, children: [
1769
+ /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelSpan2), children: /* @__PURE__ */ K("label", { children: [
1770
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: n.t("image-position.absolutePosition") }) }),
1771
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: /* @__PURE__ */ p(
1772
+ Fe,
1773
+ {
1774
+ min: qn,
1775
+ max: Kn,
1776
+ precision: 1,
1777
+ disabled: w,
1778
+ value: T.posOffset,
1779
+ onChange: (D) => {
1780
+ _("positionV", {
1781
+ relativeFrom: T.relativeFrom,
1782
+ posOffset: D
1783
+ });
1784
+ },
1785
+ className: h.imageCommonPanelInput
1786
+ }
1787
+ ) }) })
1788
+ ] }) }),
1789
+ /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelSpan2), children: /* @__PURE__ */ K("label", { children: [
1790
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: n.t("image-position.bellow") }) }),
1791
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: /* @__PURE__ */ p(
1792
+ jn,
1793
+ {
1794
+ disabled: w,
1795
+ value: String(T.relativeFrom),
1796
+ options: v,
1797
+ onChange: G
1798
+ }
1799
+ ) }) })
1800
+ ] }) })
1801
+ ] }),
1802
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelSubtitle), children: /* @__PURE__ */ p("div", { children: n.t("image-position.options") }) }) }),
1803
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, style: { marginBottom: "50px" }, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: /* @__PURE__ */ p(Li, { disabled: w, checked: P, onChange: S, children: n.t("image-position.moveObjectWithText") }) }) })
1804
+ ] });
1805
+ }, en = 0, nn = 100, lr = (i) => {
1806
+ const e = ve($), n = ve(un), t = ve(_e), r = ve(J), o = ve(q), { drawings: s } = i, a = s[0];
1807
+ if (a == null)
1808
+ return null;
1809
+ const { unitId: d } = a, c = o.getUniverDocInstance(d), g = r.getRenderById(d);
1810
+ if ((g == null ? void 0 : g.scene) == null)
1811
+ return null;
1812
+ const [l, f] = oe(!0), [u, v] = oe(!0), [w, I] = oe(!0), [O, C] = oe(ue.INLINE), [T, M] = oe(""), [P, N] = oe({
1813
+ distT: 0,
1814
+ distL: 0,
1815
+ distB: 0,
1816
+ distR: 0
1817
+ }), [B, E] = oe(!0);
1818
+ function _(S) {
1819
+ C(S);
1820
+ const D = t.getFocusDrawings();
1821
+ if (D.length === 0)
1822
+ return;
1823
+ const { unitId: R, subUnitId: y } = D[0], U = D.map(({ unitId: k, subUnitId: b, drawingId: A }) => ({
1824
+ unitId: k,
1825
+ subUnitId: b,
1826
+ drawingId: A
1827
+ }));
1828
+ e.executeCommand(lt.id, {
1829
+ unitId: R,
1830
+ subUnitId: y,
1831
+ drawings: U,
1832
+ wrappingStyle: S
1833
+ });
1834
+ }
1835
+ function L(S) {
1836
+ M(S);
1837
+ const D = t.getFocusDrawings();
1838
+ if (D.length === 0)
1839
+ return;
1840
+ const R = D.map((y) => ({
1841
+ unitId: y.unitId,
1842
+ subUnitId: y.subUnitId,
1843
+ drawingId: y.drawingId
1844
+ }));
1845
+ e.executeCommand(mt.id, {
1846
+ unitId: D[0].unitId,
1847
+ subUnitId: D[0].unitId,
1848
+ drawings: R,
1849
+ wrapText: S
1850
+ });
1851
+ }
1852
+ function G(S, D) {
1853
+ if (S == null)
1854
+ return;
1855
+ const R = { ...P, [D]: S };
1856
+ N(R);
1857
+ const y = t.getFocusDrawings();
1858
+ if (y.length === 0)
1859
+ return;
1860
+ const U = y.map((k) => ({
1861
+ unitId: k.unitId,
1862
+ subUnitId: k.subUnitId,
1863
+ drawingId: k.drawingId
1864
+ }));
1865
+ e.executeCommand(gt.id, {
1866
+ unitId: y[0].unitId,
1867
+ subUnitId: y[0].unitId,
1868
+ drawings: U,
1869
+ dist: {
1870
+ [D]: S
1871
+ }
1872
+ });
1873
+ }
1874
+ function x() {
1875
+ const S = t.getFocusDrawings();
1876
+ S.length !== 0 && V(S[0]);
1877
+ }
1878
+ function V(S) {
1879
+ var Z, ae;
1880
+ const D = (ae = (Z = c == null ? void 0 : c.getSnapshot()) == null ? void 0 : Z.drawings) == null ? void 0 : ae[S.drawingId];
1881
+ if (D == null)
1882
+ return;
1883
+ const {
1884
+ distT: R = 0,
1885
+ distL: y = 0,
1886
+ distB: U = 0,
1887
+ distR: k = 0,
1888
+ layoutType: b = W.INLINE,
1889
+ behindDoc: A = se.FALSE,
1890
+ wrapText: z = Xe.BOTH_SIDES
1891
+ } = D;
1892
+ if (N({
1893
+ distT: R,
1894
+ distL: y,
1895
+ distB: U,
1896
+ distR: k
1897
+ }), M(z), f(b !== W.WRAP_SQUARE), b === W.WRAP_NONE || b === W.INLINE ? v(!0) : v(!1), b === W.WRAP_NONE || b === W.INLINE || b === W.WRAP_TOP_AND_BOTTOM ? I(!0) : I(!1), b === W.WRAP_NONE)
1898
+ A === se.TRUE ? C(ue.BEHIND_TEXT) : C(ue.IN_FRONT_OF_TEXT);
1899
+ else
1900
+ switch (b) {
1901
+ case W.INLINE:
1902
+ C(ue.INLINE);
1903
+ break;
1904
+ case W.WRAP_SQUARE:
1905
+ C(ue.WRAP_SQUARE);
1906
+ break;
1907
+ case W.WRAP_TOP_AND_BOTTOM:
1908
+ C(ue.WRAP_TOP_AND_BOTTOM);
1909
+ break;
1910
+ default:
1911
+ throw new Error(`Unsupported layout type: ${b}`);
1912
+ }
1913
+ }
1914
+ return Tn(() => {
1915
+ x();
1916
+ const S = t.focus$.subscribe((R) => {
1917
+ if (R.length === 0) {
1918
+ E(!1);
1919
+ return;
1920
+ }
1921
+ E(!0), V(R[0]);
1922
+ }), D = e.onCommandExecuted(async (R) => {
1923
+ R.id === ne.id && x();
1924
+ });
1925
+ return () => {
1926
+ S.unsubscribe(), D.dispose();
1927
+ };
1928
+ }, []), /* @__PURE__ */ K("div", { className: j(h.imageCommonPanelGrid, h.imageCommonPanelBorder), style: { display: B ? "block" : "none" }, children: [
1929
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelTitle), children: /* @__PURE__ */ p("div", { children: n.t("image-text-wrap.title") }) }) }),
1930
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelSubtitle), children: /* @__PURE__ */ p("div", { children: n.t("image-text-wrap.wrappingStyle") }) }) }),
1931
+ /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelRow), children: /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn), children: /* @__PURE__ */ K($n, { value: O, onChange: _, direction: "vertical", children: [
1932
+ /* @__PURE__ */ p(be, { value: ue.INLINE, children: n.t("image-text-wrap.inline") }),
1933
+ /* @__PURE__ */ p(be, { value: ue.WRAP_SQUARE, children: n.t("image-text-wrap.square") }),
1934
+ /* @__PURE__ */ p(be, { value: ue.WRAP_TOP_AND_BOTTOM, children: n.t("image-text-wrap.topAndBottom") }),
1935
+ /* @__PURE__ */ p(be, { value: ue.BEHIND_TEXT, children: n.t("image-text-wrap.behindText") }),
1936
+ /* @__PURE__ */ p(be, { value: ue.IN_FRONT_OF_TEXT, children: n.t("image-text-wrap.inFrontText") })
1937
+ ] }) }) }),
1938
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelSubtitle), children: /* @__PURE__ */ p("div", { children: n.t("image-text-wrap.wrapText") }) }) }),
1939
+ /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelRow), children: /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn), children: /* @__PURE__ */ K($n, { disabled: l, value: T, onChange: L, direction: "horizontal", children: [
1940
+ /* @__PURE__ */ p(be, { value: Xe.BOTH_SIDES, children: n.t("image-text-wrap.bothSide") }),
1941
+ /* @__PURE__ */ p(be, { value: Xe.LEFT, children: n.t("image-text-wrap.leftOnly") }),
1942
+ /* @__PURE__ */ p(be, { value: Xe.RIGHT, children: n.t("image-text-wrap.rightOnly") })
1943
+ ] }) }) }),
1944
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelSubtitle), children: /* @__PURE__ */ p("div", { children: n.t("image-text-wrap.distanceFromText") }) }) }),
1945
+ /* @__PURE__ */ K("div", { className: h.imageCommonPanelRow, children: [
1946
+ /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelSpan2), children: /* @__PURE__ */ K("label", { children: [
1947
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: n.t("image-text-wrap.top") }) }),
1948
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: /* @__PURE__ */ p(
1949
+ Fe,
1950
+ {
1951
+ min: en,
1952
+ max: nn,
1953
+ disabled: u,
1954
+ precision: 1,
1955
+ value: P.distT,
1956
+ onChange: (S) => {
1957
+ G(S, "distT");
1958
+ },
1959
+ className: h.imageCommonPanelInput
1960
+ }
1961
+ ) }) })
1962
+ ] }) }),
1963
+ /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelSpan2), children: /* @__PURE__ */ K("label", { children: [
1964
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: n.t("image-text-wrap.left") }) }),
1965
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: /* @__PURE__ */ p(
1966
+ Fe,
1967
+ {
1968
+ min: en,
1969
+ max: nn,
1970
+ disabled: w,
1971
+ precision: 1,
1972
+ value: P.distL,
1973
+ onChange: (S) => {
1974
+ G(S, "distL");
1975
+ },
1976
+ className: h.imageCommonPanelInput
1977
+ }
1978
+ ) }) })
1979
+ ] }) })
1980
+ ] }),
1981
+ /* @__PURE__ */ K("div", { className: h.imageCommonPanelRow, children: [
1982
+ /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelSpan2), children: /* @__PURE__ */ K("label", { children: [
1983
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: n.t("image-text-wrap.bottom") }) }),
1984
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: /* @__PURE__ */ p(
1985
+ Fe,
1986
+ {
1987
+ min: en,
1988
+ max: nn,
1989
+ disabled: u,
1990
+ precision: 1,
1991
+ value: P.distB,
1992
+ onChange: (S) => {
1993
+ G(S, "distB");
1994
+ },
1995
+ className: h.imageCommonPanelInput
1996
+ }
1997
+ ) }) })
1998
+ ] }) }),
1999
+ /* @__PURE__ */ p("div", { className: j(h.imageCommonPanelColumn, h.imageCommonPanelSpan2), children: /* @__PURE__ */ K("label", { children: [
2000
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: n.t("image-text-wrap.right") }) }),
2001
+ /* @__PURE__ */ p("div", { className: h.imageCommonPanelRow, children: /* @__PURE__ */ p("div", { className: h.imageCommonPanelColumn, children: /* @__PURE__ */ p(
2002
+ Fe,
2003
+ {
2004
+ min: en,
2005
+ max: nn,
2006
+ disabled: w,
2007
+ precision: 1,
2008
+ value: P.distR,
2009
+ onChange: (S) => {
2010
+ G(S, "distR");
2011
+ },
2012
+ className: h.imageCommonPanelInput
2013
+ }
2014
+ ) }) })
2015
+ ] }) })
2016
+ ] })
2017
+ ] });
2018
+ }, gr = () => {
2019
+ const i = ve(_e), e = i.getFocusDrawings(), [n, t] = oe(e);
2020
+ return Tn(() => {
2021
+ const r = i.focus$.subscribe((o) => {
2022
+ t(o);
2023
+ });
2024
+ return () => {
2025
+ r.unsubscribe();
2026
+ };
2027
+ }, []), !!(n != null && n.length) && /* @__PURE__ */ K("div", { className: h.imageCommonPanel, children: [
2028
+ /* @__PURE__ */ p(oi, { drawings: n, hasAlign: !1, hasCropper: !1, hasGroup: !1, hasTransform: !1 }),
2029
+ /* @__PURE__ */ p(lr, { drawings: n }),
2030
+ /* @__PURE__ */ p(dr, { drawings: n })
2031
+ ] });
2032
+ }, yt = "addition-and-subtraction-single", Pt = "doc.menu.image", bt = Dt.id, mr = (i) => {
2033
+ const e = i.get(On), n = i.get(q);
2034
+ return new Ni((t) => {
2035
+ const r = e.textSelection$.subscribe(() => {
2036
+ var s;
2037
+ const o = e.getActiveTextRange();
2038
+ if (o) {
2039
+ const { segmentId: a, startOffset: d, endOffset: c } = o, g = n.getCurrentUniverDocInstance(), m = (s = g == null ? void 0 : g.getSelfOrHeaderFooterModel(a).getBody()) == null ? void 0 : s.tables;
2040
+ if (m && m.length && m.some((l) => {
2041
+ const { startIndex: f, endIndex: u } = l;
2042
+ return d >= f && d < u || c >= f && c < u;
2043
+ })) {
2044
+ t.next(!0);
2045
+ return;
2046
+ }
2047
+ } else {
2048
+ t.next(!0);
2049
+ return;
2050
+ }
2051
+ t.next(!1);
2052
+ });
2053
+ return () => r.unsubscribe();
2054
+ });
2055
+ };
2056
+ function ur(i) {
2057
+ return {
2058
+ id: Pt,
2059
+ type: nt.SUBITEMS,
2060
+ icon: yt,
2061
+ tooltip: "docImage.title",
2062
+ disabled$: mr(i),
2063
+ hidden$: et(i, Ie.UNIVER_DOC, void 0, Cn)
2064
+ };
2065
+ }
2066
+ function fr(i) {
2067
+ return {
2068
+ id: bt,
2069
+ title: "docImage.upload.float",
2070
+ type: nt.BUTTON,
2071
+ hidden$: et(i, Ie.UNIVER_DOC, void 0, Cn)
2072
+ };
2073
+ }
2074
+ const hr = {
2075
+ [_i.LAYOUT]: {
2076
+ [Pt]: {
2077
+ order: 0,
2078
+ menuItemFactory: ur,
2079
+ [bt]: {
2080
+ order: 0,
2081
+ menuItemFactory: fr
2082
+ }
2083
+ }
2084
+ }
2085
+ };
2086
+ function Ze(i) {
2087
+ return i.getContextValue(Ht) && i.getContextValue(on);
2088
+ }
2089
+ const pr = {
2090
+ id: Ye.id,
2091
+ description: "shortcut.doc.drawing-move-down",
2092
+ group: "4_doc-drawing-view",
2093
+ binding: He.ARROW_DOWN,
2094
+ priority: 100,
2095
+ preconditions: Ze,
2096
+ staticParameters: {
2097
+ direction: fe.DOWN
2098
+ }
2099
+ }, wr = {
2100
+ id: Ye.id,
2101
+ description: "shortcut.doc.drawing-move-up",
2102
+ group: "4_doc-drawing-view",
2103
+ binding: He.ARROW_UP,
2104
+ priority: 100,
2105
+ preconditions: Ze,
2106
+ staticParameters: {
2107
+ direction: fe.UP
2108
+ }
2109
+ }, vr = {
2110
+ id: Ye.id,
2111
+ description: "shortcut.doc.drawing-move-left",
2112
+ group: "4_doc-drawing-view",
2113
+ binding: He.ARROW_LEFT,
2114
+ priority: 100,
2115
+ preconditions: Ze,
2116
+ staticParameters: {
2117
+ direction: fe.LEFT
2118
+ }
2119
+ }, Ir = {
2120
+ id: Ye.id,
2121
+ description: "shortcut.doc.drawing-move-right",
2122
+ group: "4_doc-drawing-view",
2123
+ binding: He.ARROW_RIGHT,
2124
+ priority: 100,
2125
+ preconditions: Ze,
2126
+ staticParameters: {
2127
+ direction: fe.RIGHT
2128
+ }
2129
+ }, _r = {
2130
+ id: vt.id,
2131
+ description: "shortcut.doc.drawing-delete",
2132
+ group: "4_doc-drawing-view",
2133
+ // when focusing on any other input tag do not trigger this shortcut
2134
+ preconditions: Ze,
2135
+ binding: He.DELETE,
2136
+ mac: He.BACKSPACE
2137
+ };
2138
+ var Sr = Object.getOwnPropertyDescriptor, Dr = (i, e, n, t) => {
2139
+ for (var r = t > 1 ? void 0 : t ? Sr(e, n) : e, o = i.length - 1, s; o >= 0; o--)
2140
+ (s = i[o]) && (r = s(r) || r);
2141
+ return r;
2142
+ }, tn = (i, e) => (n, t) => e(n, t, i);
2143
+ let dn = class extends Ge {
2144
+ constructor(i, e, n, t) {
2145
+ super(), this._componentManager = i, this._menuManagerService = e, this._commandService = n, this._shortcutService = t, this._init();
2146
+ }
2147
+ _initCustomComponents() {
2148
+ const i = this._componentManager;
2149
+ this.disposeWithMe(i.register(yt, wt)), this.disposeWithMe(i.register(Ct, gr));
2150
+ }
2151
+ _initMenus() {
2152
+ this._menuManagerService.mergeMenu(hr);
2153
+ }
2154
+ _initCommands() {
2155
+ [
2156
+ Dt,
2157
+ Pn,
2158
+ lt,
2159
+ gt,
2160
+ mt,
2161
+ Ke,
2162
+ ut,
2163
+ ft,
2164
+ yn,
2165
+ Ot,
2166
+ Ji,
2167
+ Tt,
2168
+ It,
2169
+ St,
2170
+ Ye,
2171
+ vt,
2172
+ _t
2173
+ ].forEach((i) => this.disposeWithMe(this._commandService.registerCommand(i)));
2174
+ }
2175
+ _initShortcuts() {
2176
+ [
2177
+ // sheet drawing shortcuts
2178
+ pr,
2179
+ wr,
2180
+ vr,
2181
+ Ir,
2182
+ _r
2183
+ ].forEach((i) => {
2184
+ this.disposeWithMe(this._shortcutService.registerShortcut(i));
2185
+ });
2186
+ }
2187
+ _init() {
2188
+ this._initCommands(), this._initCustomComponents(), this._initMenus(), this._initShortcuts();
2189
+ }
2190
+ };
2191
+ dn = Dr([
2192
+ tn(0, pe(Si)),
2193
+ tn(1, Di),
2194
+ tn(2, $),
2195
+ tn(3, Ci)
2196
+ ], dn);
2197
+ var Cr = Object.getOwnPropertyDescriptor, Or = (i, e, n, t) => {
2198
+ for (var r = t > 1 ? void 0 : t ? Cr(e, n) : e, o = i.length - 1, s; o >= 0; o--)
2199
+ (s = i[o]) && (r = s(r) || r);
2200
+ return r;
2201
+ }, ke = (i, e) => (n, t) => e(n, t, i);
2202
+ function In(i, e) {
2203
+ const { top: n, left: t, width: r, height: o, angle: s, opacity: a } = i, d = e.scene, c = d.getViewport(it.VIEW_MAIN), { viewportScrollX: g, viewportScrollY: m } = c, { scaleX: l, scaleY: f } = d.getAncestorScale();
2204
+ return {
2205
+ startX: (t - g) * l,
2206
+ startY: (n - m) * f,
2207
+ endX: (t + r - g) * l,
2208
+ endY: (n + o - m) * f,
2209
+ width: r,
2210
+ height: o,
2211
+ rotate: s,
2212
+ absolute: {
2213
+ left: !1,
2214
+ top: !1
2215
+ },
2216
+ opacity: a != null ? a : 1
2217
+ };
2218
+ }
2219
+ let ln = class extends Ge {
2220
+ constructor(e, n, t, r, o, s) {
2221
+ super();
2222
+ Se(this, "_domLayerInfoMap", /* @__PURE__ */ new Map());
2223
+ this._renderManagerService = e, this._drawingManagerService = n, this._drawingRenderService = t, this._canvasFloatDomService = r, this._univerInstanceService = o, this._commandService = s, this._initialize();
2224
+ }
2225
+ dispose() {
2226
+ super.dispose();
2227
+ }
2228
+ _initialize() {
2229
+ this._drawingAddRemoveListener(), this._initScrollAndZoomEvent();
2230
+ }
2231
+ _getSceneAndTransformerByDrawingSearch(e) {
2232
+ if (e == null)
2233
+ return;
2234
+ const n = this._renderManagerService.getRenderById(e);
2235
+ if (n == null)
2236
+ return null;
2237
+ const t = n.scene, r = t.getTransformerByCreate();
2238
+ return { scene: t, transformer: r, renderUnit: n, canvas: n.engine.getCanvasElement() };
2239
+ }
2240
+ _drawingAddRemoveListener() {
2241
+ this.disposeWithMe(
2242
+ this._drawingManagerService.add$.subscribe((e) => {
2243
+ this._insertRects(e);
2244
+ })
2245
+ ), this.disposeWithMe(
2246
+ this._drawingManagerService.remove$.subscribe((e) => {
2247
+ e.forEach((n) => {
2248
+ this._removeDom(n.drawingId);
2249
+ });
2250
+ })
2251
+ );
2252
+ }
2253
+ _insertRects(e) {
2254
+ e.forEach(async (n) => {
2255
+ const { unitId: t } = n;
2256
+ if (!this._univerInstanceService.getUnit(t, Ie.UNIVER_DOC))
2257
+ return;
2258
+ const o = this._getSceneAndTransformerByDrawingSearch(t);
2259
+ if (o == null)
2260
+ return;
2261
+ const s = this._drawingManagerService.getDrawingByParam(n);
2262
+ if (s == null)
2263
+ return;
2264
+ const a = await this._drawingRenderService.renderFloatDom(s, o.scene);
2265
+ if (!(a == null || a.length === 0))
2266
+ for (const d of a) {
2267
+ this._addHoverForRect(d);
2268
+ const c = new Gt(), g = In(d, o.renderUnit), m = new ot(g), l = o.canvas, f = s.data, u = {
2269
+ dispose: c,
2270
+ rect: d,
2271
+ position$: m,
2272
+ unitId: t
2273
+ };
2274
+ this._canvasFloatDomService.addFloatDom({
2275
+ position$: m,
2276
+ id: s.drawingId,
2277
+ componentKey: s.componentKey,
2278
+ onPointerDown: (w) => {
2279
+ l.dispatchEvent(new PointerEvent(w.type, w));
2280
+ },
2281
+ onPointerMove: (w) => {
2282
+ l.dispatchEvent(new PointerEvent(w.type, w));
2283
+ },
2284
+ onPointerUp: (w) => {
2285
+ l.dispatchEvent(new PointerEvent(w.type, w));
2286
+ },
2287
+ onWheel: (w) => {
2288
+ l.dispatchEvent(new WheelEvent(w.type, w));
2289
+ },
2290
+ data: f,
2291
+ unitId: t
2292
+ });
2293
+ const v = d.onTransformChange$.subscribeEvent(() => {
2294
+ const w = In(d, o.renderUnit);
2295
+ m.next(
2296
+ w
2297
+ );
2298
+ });
2299
+ c.add(() => {
2300
+ this._canvasFloatDomService.removeFloatDom(s.drawingId);
2301
+ }), v && c.add(v), this._domLayerInfoMap.set(s.drawingId, u);
2302
+ }
2303
+ });
2304
+ }
2305
+ _addHoverForRect(e) {
2306
+ this.disposeWithMe(
2307
+ Oe(
2308
+ e.onPointerEnter$.subscribeEvent(() => {
2309
+ e.cursor = Bn.GRAB;
2310
+ })
2311
+ )
2312
+ ), this.disposeWithMe(
2313
+ Oe(
2314
+ e.onPointerLeave$.subscribeEvent(() => {
2315
+ e.cursor = Bn.DEFAULT;
2316
+ })
2317
+ )
2318
+ );
2319
+ }
2320
+ _removeDom(e) {
2321
+ const n = this._domLayerInfoMap.get(e);
2322
+ if (!n)
2323
+ return;
2324
+ const { unitId: t } = n;
2325
+ this._domLayerInfoMap.delete(e), n.dispose.dispose();
2326
+ const r = this._getSceneAndTransformerByDrawingSearch(t);
2327
+ r && r.scene.removeObject(n.rect);
2328
+ }
2329
+ _initScrollAndZoomEvent() {
2330
+ const e = (n) => {
2331
+ const t = this._getSceneAndTransformerByDrawingSearch(n);
2332
+ t && this._domLayerInfoMap.forEach((r) => {
2333
+ if (r.unitId !== n) return;
2334
+ const o = In(r.rect, t.renderUnit);
2335
+ r.position$.next(o);
2336
+ });
2337
+ };
2338
+ this.disposeWithMe(
2339
+ this._univerInstanceService.getCurrentTypeOfUnit$(Ie.UNIVER_DOC).pipe(
2340
+ Wn((n) => {
2341
+ if (!n) return null;
2342
+ const t = n.getUnitId(), r = this._renderManagerService.getRenderById(t);
2343
+ return r ? { render: r, unitId: t } : null;
2344
+ }),
2345
+ Ai(
2346
+ (n) => n ? Qn(n.render.scene.getViewport(it.VIEW_MAIN).onScrollAfter$).pipe(Wn(() => ({ unitId: n.unitId }))) : xi(null)
2347
+ )
2348
+ ).subscribe((n) => {
2349
+ if (!n) return;
2350
+ const { unitId: t } = n;
2351
+ e(t);
2352
+ })
2353
+ ), this.disposeWithMe(this._commandService.onCommandExecuted((n) => {
2354
+ if (n.id === rt.id) {
2355
+ const t = n.params, { unitId: r } = t;
2356
+ e(r);
2357
+ }
2358
+ }));
2359
+ }
2360
+ insertFloatDom(e, n) {
2361
+ var v, w, I;
2362
+ const t = this._univerInstanceService.getCurrentUnitOfType(Ie.UNIVER_DOC);
2363
+ if (!t) return !1;
2364
+ const r = this._getSceneAndTransformerByDrawingSearch(t.getUnitId());
2365
+ if (!r) return !1;
2366
+ const a = (v = r.renderUnit.with(te).getSkeleton().getSkeletonData()) == null ? void 0 : v.pages[0];
2367
+ if (!a) return !1;
2368
+ const { pageWidth: d, marginLeft: c, marginRight: g } = a, m = d - c - g, l = {
2369
+ size: {
2370
+ width: (w = n.width) != null ? w : m,
2371
+ height: n.height
2372
+ },
2373
+ positionH: {
2374
+ relativeFrom: ee.PAGE,
2375
+ posOffset: 0
2376
+ },
2377
+ positionV: {
2378
+ relativeFrom: H.PAGE,
2379
+ posOffset: 0
2380
+ },
2381
+ angle: 0
2382
+ }, f = (I = n.drawingId) != null ? I : Vt(), u = {
2383
+ unitId: t.getUnitId(),
2384
+ drawings: [
2385
+ {
2386
+ drawingId: f,
2387
+ drawingType: rn.DRAWING_DOM,
2388
+ subUnitId: t.getUnitId(),
2389
+ unitId: t.getUnitId(),
2390
+ ...e,
2391
+ title: "",
2392
+ description: "",
2393
+ docTransform: l,
2394
+ layoutType: W.INLINE,
2395
+ transform: tt(l)
2396
+ }
2397
+ ]
2398
+ };
2399
+ return this._commandService.syncExecuteCommand(Pn.id, u), f;
2400
+ }
2401
+ };
2402
+ ln = Or([
2403
+ ke(0, J),
2404
+ ke(1, _e),
2405
+ ke(2, pe(si)),
2406
+ ke(3, pe(Oi)),
2407
+ ke(4, q),
2408
+ ke(5, $)
2409
+ ], ln);
2410
+ var Tr = Object.getOwnPropertyDescriptor, yr = (i, e, n, t) => {
2411
+ for (var r = t > 1 ? void 0 : t ? Tr(e, n) : e, o = i.length - 1, s; o >= 0; o--)
2412
+ (s = i[o]) && (r = s(r) || r);
2413
+ return r;
2414
+ }, ze = (i, e) => (n, t) => e(n, t, i);
2415
+ let gn = class extends jt {
2416
+ constructor(e, n, t, r, o) {
2417
+ super();
2418
+ Se(this, "_initImagePopupMenu", /* @__PURE__ */ new Set());
2419
+ this._drawingManagerService = e, this._canvasPopManagerService = n, this._renderManagerService = t, this._univerInstanceService = r, this._contextService = o, this._init();
2420
+ }
2421
+ _init() {
2422
+ this._univerInstanceService.getCurrentTypeOfUnit$(Ie.UNIVER_DOC).pipe(Hn(this.dispose$)).subscribe((e) => this._create(e)), this._univerInstanceService.getTypeOfUnitDisposed$(Ie.UNIVER_DOC).pipe(Hn(this.dispose$)).subscribe((e) => this._dispose(e)), this._univerInstanceService.getAllUnitsForType(Ie.UNIVER_DOC).forEach((e) => this._create(e));
2423
+ }
2424
+ _dispose(e) {
2425
+ const n = e.getUnitId();
2426
+ this._renderManagerService.removeRender(n);
2427
+ }
2428
+ _create(e) {
2429
+ if (!e)
2430
+ return;
2431
+ const n = e.getUnitId();
2432
+ this._renderManagerService.has(n) && !this._initImagePopupMenu.has(n) && (this._popupMenuListener(n), this._initImagePopupMenu.add(n));
2433
+ }
2434
+ _hasCropObject(e) {
2435
+ const n = e.getAllObjects();
2436
+ for (const t of n)
2437
+ if (t instanceof ai)
2438
+ return !0;
2439
+ return !1;
2440
+ }
2441
+ // eslint-disable-next-line max-lines-per-function
2442
+ _popupMenuListener(e) {
2443
+ var o;
2444
+ const n = (o = this._renderManagerService.getRenderById(e)) == null ? void 0 : o.scene;
2445
+ if (!n)
2446
+ return;
2447
+ const t = n.getTransformerByCreate();
2448
+ if (!t)
2449
+ return;
2450
+ const r = [];
2451
+ this.disposeWithMe(
2452
+ Oe(
2453
+ t.createControl$.subscribe(() => {
2454
+ if (this._hasCropObject(n))
2455
+ return;
2456
+ const s = t.getSelectedObjectMap();
2457
+ if (r.forEach((I) => I.dispose()), r.length = 0, s.size > 1)
2458
+ return;
2459
+ const a = s.values().next().value;
2460
+ if (!a)
2461
+ return;
2462
+ const d = a.oKey, c = this._drawingManagerService.getDrawingOKey(d);
2463
+ if (!c || c.drawingType === rn.DRAWING_DOM)
2464
+ return;
2465
+ const { unitId: g, subUnitId: m, drawingId: l, drawingType: f } = c, u = this._canvasPopManagerService.attachPopupToObject(
2466
+ a,
2467
+ {
2468
+ componentKey: ci,
2469
+ direction: "horizontal",
2470
+ offset: [2, 0],
2471
+ extraProps: {
2472
+ menuItems: this._getImageMenuItems(g, m, l, f)
2473
+ }
2474
+ },
2475
+ g
2476
+ );
2477
+ r.push(this.disposeWithMe(u)), !this._drawingManagerService.getFocusDrawings().find((I) => I.unitId === g && I.subUnitId === m && I.drawingId === l) && this._drawingManagerService.focusDrawing([{
2478
+ unitId: g,
2479
+ subUnitId: m,
2480
+ drawingId: l
2481
+ }]);
2482
+ })
2483
+ )
2484
+ ), this.disposeWithMe(
2485
+ Oe(
2486
+ t.clearControl$.subscribe(() => {
2487
+ r.forEach((s) => s.dispose()), r.length = 0, this._contextService.setContextValue(on, !1), this._drawingManagerService.focusDrawing(null);
2488
+ })
2489
+ )
2490
+ ), this.disposeWithMe(
2491
+ Oe(
2492
+ t.changing$.subscribe(() => {
2493
+ r.forEach((s) => s.dispose()), r.length = 0;
2494
+ })
2495
+ )
2496
+ ), this.disposeWithMe(
2497
+ Oe(
2498
+ t.changeStart$.subscribe(() => {
2499
+ r.forEach((s) => s.dispose()), r.length = 0;
2500
+ })
2501
+ )
2502
+ );
2503
+ }
2504
+ _getImageMenuItems(e, n, t, r) {
2505
+ return [
2506
+ {
2507
+ label: "image-popup.edit",
2508
+ index: 0,
2509
+ commandId: Tt.id,
2510
+ commandParams: { unitId: e, subUnitId: n, drawingId: t },
2511
+ disable: !!$t.includes(e) || r === rn.DRAWING_DOM
2512
+ },
2513
+ {
2514
+ label: "image-popup.delete",
2515
+ index: 1,
2516
+ commandId: yn.id,
2517
+ commandParams: { unitId: e, drawings: [{ unitId: e, subUnitId: n, drawingId: t }] },
2518
+ disable: !1
2519
+ },
2520
+ {
2521
+ label: "image-popup.crop",
2522
+ index: 2,
2523
+ commandId: di.id,
2524
+ commandParams: { unitId: e, subUnitId: n, drawingId: t },
2525
+ disable: !0
2526
+ // TODO: @JOCS, feature is not ready.
2527
+ },
2528
+ {
2529
+ label: "image-popup.reset",
2530
+ index: 3,
2531
+ commandId: li.id,
2532
+ commandParams: [{ unitId: e, subUnitId: n, drawingId: t }],
2533
+ disable: !0
2534
+ // TODO: @JOCS, feature is not ready.
2535
+ }
2536
+ ];
2537
+ }
2538
+ };
2539
+ gn = yr([
2540
+ ze(0, _e),
2541
+ ze(1, pe(Ri)),
2542
+ ze(2, J),
2543
+ ze(3, q),
2544
+ ze(4, Zn)
2545
+ ], gn);
2546
+ var Pr = Object.getOwnPropertyDescriptor, br = (i, e, n, t) => {
2547
+ for (var r = t > 1 ? void 0 : t ? Pr(e, n) : e, o = i.length - 1, s; o >= 0; o--)
2548
+ (s = i[o]) && (r = s(r) || r);
2549
+ return r;
2550
+ }, Le = (i, e) => (n, t) => e(n, t, i);
2551
+ let Sn = class extends Ge {
2552
+ constructor(e, n, t, r, o, s, a, d) {
2553
+ super();
2554
+ Se(this, "_liquid", new Jn());
2555
+ this._context = e, this._docSkeletonManagerService = n, this._commandService = t, this._editorService = r, this._drawingManagerService = o, this._docRefreshDrawingsService = s, this._univerInstanceService = a, this._lifecycleService = d, this._initialize(), this._commandExecutedListener();
2556
+ }
2557
+ _initialize() {
2558
+ this._initialRenderRefresh(), this._drawingInitializeListener(), this._initResize();
2559
+ }
2560
+ _initialRenderRefresh() {
2561
+ this._docSkeletonManagerService.currentSkeleton$.subscribe((e) => {
2562
+ e != null && this._refreshDrawing(e);
2563
+ }), this._docRefreshDrawingsService.refreshDrawings$.subscribe((e) => {
2564
+ e != null && this._refreshDrawing(e);
2565
+ });
2566
+ }
2567
+ _commandExecutedListener() {
2568
+ const e = [ne.id, rt.id];
2569
+ this.disposeWithMe(
2570
+ this._commandService.onCommandExecuted((n) => {
2571
+ if (e.includes(n.id)) {
2572
+ const t = n.params, { unitId: r } = t, { unitId: o, mainComponent: s } = this._context;
2573
+ if (r !== o)
2574
+ return;
2575
+ const a = this._docSkeletonManagerService.getSkeleton();
2576
+ if (a == null)
2577
+ return;
2578
+ if (this._editorService.isEditor(o) && o !== Cn) {
2579
+ s == null || s.makeDirty();
2580
+ return;
2581
+ }
2582
+ this._refreshDrawing(a);
2583
+ }
2584
+ })
2585
+ );
2586
+ }
2587
+ _initResize() {
2588
+ this.disposeWithMe(
2589
+ Qn(this._context.engine.onTransformChange$).pipe(
2590
+ Gn((e) => e.type === pi.resize),
2591
+ st(16)
2592
+ ).subscribe(() => {
2593
+ var t;
2594
+ const e = this._docSkeletonManagerService.getSkeleton(), { scene: n } = this._context;
2595
+ (t = n.getTransformer()) == null || t.refreshControls(), this._refreshDrawing(e);
2596
+ })
2597
+ );
2598
+ }
2599
+ _refreshDrawing(e) {
2600
+ var O, C;
2601
+ const n = e == null ? void 0 : e.getSkeletonData(), { mainComponent: t, unitId: r } = this._context, o = t;
2602
+ if (!n)
2603
+ return;
2604
+ const { left: s, top: a, pageLayoutType: d, pageMarginLeft: c, pageMarginTop: g } = o, { pages: m, skeHeaders: l, skeFooters: f } = n, u = {};
2605
+ this._liquid.reset();
2606
+ for (let T = 0, M = m.length; T < M; T++) {
2607
+ const P = m[T], { headerId: N, footerId: B, pageWidth: E } = P;
2608
+ if (N) {
2609
+ const _ = (O = l.get(N)) == null ? void 0 : O.get(E);
2610
+ _ && this._calculateDrawingPosition(
2611
+ r,
2612
+ _,
2613
+ s,
2614
+ a,
2615
+ u,
2616
+ _.marginTop,
2617
+ P.marginLeft
2618
+ );
2619
+ }
2620
+ if (B) {
2621
+ const _ = (C = f.get(B)) == null ? void 0 : C.get(E);
2622
+ _ && this._calculateDrawingPosition(
2623
+ r,
2624
+ _,
2625
+ s,
2626
+ a,
2627
+ u,
2628
+ P.pageHeight - P.marginBottom + _.marginTop,
2629
+ P.marginLeft
2630
+ );
2631
+ }
2632
+ this._calculateDrawingPosition(r, P, s, a, u, P.marginTop, P.marginLeft), this._liquid.translatePage(P, d, c, g);
2633
+ }
2634
+ const v = Object.values(u), w = v.filter((T) => !T.isMultiTransform), I = v.filter((T) => T.isMultiTransform);
2635
+ w.length > 0 && this._drawingManagerService.refreshTransform(w), this._handleMultiDrawingsTransform(I);
2636
+ }
2637
+ _handleMultiDrawingsTransform(e) {
2638
+ const { scene: n, unitId: t } = this._context, r = n.getTransformerByCreate();
2639
+ e.forEach((d) => {
2640
+ const c = this._drawingManagerService.getDrawingByParam(d);
2641
+ c != null && (c.transform = d.transform, c.transforms = d.transforms, c.isMultiTransform = d.isMultiTransform);
2642
+ });
2643
+ const s = [...r.getSelectedObjectMap().keys()], a = Object.values(this._drawingManagerService.getDrawingData(t, t)).filter((d) => d.isMultiTransform === se.TRUE);
2644
+ this._drawingManagerService.removeNotification(a), e.length > 0 && this._drawingManagerService.addNotification(e);
2645
+ for (const d of s) {
2646
+ const c = n.getObject(d);
2647
+ c && r.setSelectedControl(c);
2648
+ }
2649
+ }
2650
+ _calculateDrawingPosition(e, n, t, r, o, s, a) {
2651
+ const { skeDrawings: d } = n;
2652
+ this._liquid.translatePagePadding({
2653
+ marginTop: s,
2654
+ marginLeft: a
2655
+ }), d.forEach((c) => {
2656
+ const { aLeft: g, aTop: m, height: l, width: f, angle: u, drawingId: v, drawingOrigin: w } = c, I = w.layoutType === W.WRAP_NONE && w.behindDoc === se.TRUE, { isMultiTransform: O = se.FALSE } = w, C = {
2657
+ left: g + t + this._liquid.x,
2658
+ top: m + r + this._liquid.y,
2659
+ width: f,
2660
+ height: l,
2661
+ angle: u
2662
+ };
2663
+ o[v] == null ? o[v] = {
2664
+ unitId: e,
2665
+ subUnitId: e,
2666
+ drawingId: v,
2667
+ behindText: I,
2668
+ transform: C,
2669
+ transforms: [C],
2670
+ isMultiTransform: O
2671
+ } : O === se.TRUE && o[v].transforms.push(C);
2672
+ }), this._liquid.restorePagePadding({
2673
+ marginTop: s,
2674
+ marginLeft: a
2675
+ });
2676
+ }
2677
+ _drawingInitializeListener() {
2678
+ const e = () => {
2679
+ const n = this._docSkeletonManagerService.getSkeleton();
2680
+ n != null && (this._refreshDrawing(n), this._drawingManagerService.initializeNotification(this._context.unitId));
2681
+ };
2682
+ this._lifecycleService.stage === En.Steady ? setTimeout(() => {
2683
+ e();
2684
+ }, 1e3) : this._lifecycleService.lifecycle$.pipe(Gn((n) => n === En.Steady)).subscribe(e);
2685
+ }
2686
+ };
2687
+ Sn = br([
2688
+ Le(1, pe(te)),
2689
+ Le(2, $),
2690
+ Le(3, Ei),
2691
+ Le(4, _e),
2692
+ Le(5, pe(fn)),
2693
+ Le(6, q),
2694
+ Le(7, pe(zt))
2695
+ ], Sn);
2696
+ var Mr = Object.defineProperty, Rr = Object.getOwnPropertyDescriptor, Er = (i, e, n) => e in i ? Mr(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n, Nr = (i, e, n, t) => {
2697
+ for (var r = t > 1 ? void 0 : t ? Rr(e, n) : e, o = i.length - 1, s; o >= 0; o--)
2698
+ (s = i[o]) && (r = s(r) || r);
2699
+ return r;
2700
+ }, _n = (i, e) => (n, t) => e(n, t, i), Mt = (i, e, n) => Er(i, typeof e != "symbol" ? e + "" : e, n);
2701
+ const Ar = "DOC_DRAWING_UI_PLUGIN";
2702
+ let mn = class extends Yt {
2703
+ constructor(i = zn, e, n, t) {
2704
+ super(), this._config = i, this._injector = e, this._renderManagerSrv = n, this._configService = t;
2705
+ const { ...r } = Zt(
2706
+ {},
2707
+ zn,
2708
+ this._config
2709
+ );
2710
+ this._configService.setConfig(Bi, r);
2711
+ }
2712
+ onStarting() {
2713
+ [
2714
+ [dn],
2715
+ [gn],
2716
+ [an],
2717
+ [sn],
2718
+ [fn],
2719
+ [ln]
2720
+ ].forEach((e) => this._injector.add(e));
2721
+ }
2722
+ onReady() {
2723
+ [
2724
+ [cn],
2725
+ [Sn]
2726
+ ].forEach((i) => this._renderManagerSrv.registerRenderModule(Ie.UNIVER_DOC, i)), this._injector.get(sn), this._injector.get(dn), this._injector.get(an);
2727
+ }
2728
+ onRendered() {
2729
+ this._injector.get(gn), this._injector.get(ln);
2730
+ }
2731
+ };
2732
+ Mt(mn, "type", Ie.UNIVER_DOC);
2733
+ Mt(mn, "pluginName", Ar);
2734
+ mn = Nr([
2735
+ Xt(gi, ri, Qt, Ti),
2736
+ _n(1, pe(qt)),
2737
+ _n(2, J),
2738
+ _n(3, Kt)
2739
+ ], mn);
2740
+ export {
2741
+ Ji as ClearDocDrawingTransformerOperation,
2742
+ Pt as DOCS_IMAGE_MENU_ID,
2743
+ vt as DeleteDocDrawingsCommand,
2744
+ ln as DocFloatDomController,
2745
+ Tt as EditDocDrawingOperation,
2746
+ It as GroupDocDrawingCommand,
2747
+ Pn as InsertDocDrawingCommand,
2748
+ Dt as InsertDocImageCommand,
2749
+ Ye as MoveDocDrawingsCommand,
2750
+ yn as RemoveDocDrawingCommand,
2751
+ _t as SetDocDrawingArrangeCommand,
2752
+ Ot as SidebarDocDrawingOperation,
2753
+ St as UngroupDocDrawingCommand,
2754
+ mn as UniverDocsDrawingUIPlugin
2755
+ };