@univerjs/docs-drawing-ui 0.6.7 → 0.6.9-experimental.20250403-d914ddc

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