@univerjs/sheets-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,3656 @@
1
+ var $r = Object.defineProperty;
2
+ var xr = (i, t, e) => t in i ? $r(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
3
+ var q = (i, t, e) => xr(i, typeof t != "symbol" ? t + "" : t, e);
4
+ import { CommandType as ee, ICommandService as Y, IUndoRedoService as Ve, sequenceExecute as Zn, LocaleService as it, IUniverInstanceService as Ce, Inject as N, Injector as st, IContextService as Jn, RxDisposable as Lr, UniverInstanceType as x, toDisposable as Fr, FOCUSING_COMMON_DRAWINGS as Ye, DrawingTypeEnum as L, Disposable as se, ArrangeTypeEnum as vt, createDocumentModelWithStyle as tn, ObjectRelativeFromV as bn, ObjectRelativeFromH as Rn, WrapTextType as Mn, PositionedObjectLayoutType as yn, BooleanNumber as En, BuildTextUtils as nn, ImageSourceType as Tn, generateRandomId as Ot, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as nt, DOCS_ZEN_EDITOR_UNIT_ID_KEY as Le, InterceptorEffectEnum as Yr, ObjectMatrix as Gr, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as Vr, Tools as ye, IPermissionService as Xr, UserManagerService as Hr, Rectangle as zr, Direction as Ie, FOCUSING_FX_BAR_EDITOR as Kr, EDITOR_ACTIVATED as Zr, FOCUSING_PANEL_EDITOR as Jr, LifecycleService as qr, LifecycleStages as Qr, DisposableCollection as St, fromEventSubject as ei, DependentOn as ti, IConfigService as ni, Plugin as ri, merge as ii, registerDependencies as si, touchDependencies as Kt } from "@univerjs/core";
5
+ import { DocDrawingController as oi, UniverDocsDrawingPlugin as ai } from "@univerjs/docs-drawing";
6
+ import { SetDrawingSelectedOperation as Ft, IImageIoService as qn, IDrawingManagerService as oe, DRAWING_IMAGE_ALLOW_IMAGE_LIST as On, DRAWING_IMAGE_COUNT_LIMIT as Un, ImageUploadStatusType as Be, DRAWING_IMAGE_ALLOW_SIZE as Pn, getImageSize as Zt, DRAWING_IMAGE_WIDTH_LIMIT as An, DRAWING_IMAGE_HEIGHT_LIMIT as Nn, ImageSourceType as ci, getDrawingShapeKeyByDrawingSearch as De, UniverDrawingPlugin as di } from "@univerjs/drawing";
7
+ import { ImageCropperObject as li, COMPONENT_IMAGE_POPUP_MENU as ui, OpenImageCropOperation as hi, ImageResetSizeOperation as gi, DrawingRenderService as Qn, DrawingCommonPanel as mi, UniverDrawingUIPlugin as fi } from "@univerjs/drawing-ui";
8
+ import { IRenderManagerService as te, CURSOR_TYPE as pi, precisionTo as It, transformObjectOutOfGroup as wi, getGroupState as _i, getCurrentTypeOfRenderer as gn, RENDER_CLASS_TYPE as We, Rect as je, ObjectType as kn, DRAWING_OBJECT_LAYER_INDEX as Jt, SHEET_VIEWPORT_KEY as er } from "@univerjs/engine-render";
9
+ import { ISheetDrawingService as ae, DrawingApplyType as P, SetDrawingApplyMutation as A, SheetDrawingAnchorType as U, UniverSheetsDrawingPlugin as vi } from "@univerjs/sheets-drawing";
10
+ import { SheetCanvasPopManagerService as Si, HoverManagerService as Ii, SheetSkeletonManagerService as V, convertPositionSheetOverGridToAbsolute as Ci, ISheetSelectionRenderService as Xe, attachRangeWithCoord as tr, IEditorBridgeService as Di, IAutoFillService as bi, EditingRenderController as Ri, SetCellEditVisibleOperation as Bn, PREDEFINED_HOOK_NAME as Fe, COPY_TYPE as be, discreteRangeToRange as Wn, virtualizeDiscreteRanges as Mi, ISheetClipboardService as yi, SheetPrintInterceptorService as Ei, getCurrentRangeDisable$ as Ti, SetZoomRatioOperation as jn, SetScrollOperation as Oi } from "@univerjs/sheets-ui";
11
+ import { ISidebarService as Ui, useDependency as Ee, IUIPartsService as Pi, BuiltInUIPart as Ai, connectInjector as Ni, ILocalFileService as ki, IMessageService as Bi, IDialogService as Wi, IClipboardInterfaceService as ji, getMenuHiddenObservable as mn, MenuItemType as fn, RibbonStartGroup as $i, KeyCode as Ge, ComponentManager as xi, IMenuManagerService as Li, IShortcutService as Fi, CanvasFloatDomService as Yi } from "@univerjs/ui";
12
+ import { takeUntil as $n, throttleTime as Gi, combineLatest as Ct, switchMap as Se, EMPTY as pe, tap as xn, map as Te, distinctUntilChanged as Ln, Subject as qt, filter as Vi, take as Xi, BehaviorSubject as Je, of as Fn } from "rxjs";
13
+ import { SheetInterceptorService as Yt, getSheetCommandTarget as le, SheetsSelectionsService as pn, SetRangeValuesCommand as Yn, INTERCEPTOR_POINT as Hi, InterceptCellContentPriority as zi, WorkbookViewPermission as Gn, WorksheetViewPermission as Vn, WorkbookEditablePermission as rn, WorksheetEditPermission as sn, InsertRowCommand as nr, InsertColCommand as rr, RemoveRowCommand as ir, RemoveColCommand as sr, DeleteRangeMoveLeftCommand as or, DeleteRangeMoveUpCommand as ar, InsertRangeMoveDownCommand as cr, InsertRangeMoveRightCommand as dr, DeltaRowHeightCommand as on, SetRowHeightCommand as an, DeltaColumnWidthCommand as lr, SetColWidthCommand as ur, SetRowHiddenCommand as hr, SetSpecificRowsVisibleCommand as gr, SetSpecificColsVisibleCommand as mr, SetColHiddenCommand as fr, MoveColsCommand as pr, MoveRowsCommand as wr, MoveRangeCommand as _r, SetRowVisibleMutation as Ki, SetRowHiddenMutation as Zi, SetColVisibleMutation as Ji, SetColHiddenMutation as qi, SetWorksheetRowHeightMutation as Qi, SetWorksheetColWidthMutation as es, SetWorksheetActiveOperation as ts, RangeProtectionPermissionEditPoint as ns, SetFrozenMutation as rs, SetWorksheetRowAutoHeightMutation as is, COMMAND_LISTENER_SKELETON_CHANGE as ss } from "@univerjs/sheets";
14
+ import { jsx as Q, jsxs as Ut } from "react/jsx-runtime";
15
+ import os, { useEffect as wn, forwardRef as vr, useRef as as, createElement as Sr, useState as cn } from "react";
16
+ import { docDrawingPositionToTransform as Xn, ReplaceSnapshotCommand as cs, InnerPasteCommand as ds } from "@univerjs/docs-ui";
17
+ import { MessageType as Re, clsx as Dt, RadioGroup as ls, Radio as Qt } from "@univerjs/design";
18
+ const us = "sheets-drawing-ui.config", Hn = {}, F = {
19
+ id: "sheet.operation.clear-drawing-transformer",
20
+ type: ee.MUTATION,
21
+ handler: (i, t) => {
22
+ const e = i.get(te);
23
+ return t.forEach((n) => {
24
+ var r, s;
25
+ (s = (r = e.getRenderById(n)) == null ? void 0 : r.scene.getTransformer()) == null || s.debounceRefreshControls();
26
+ }), !0;
27
+ }
28
+ }, ot = {
29
+ id: "sheet.command.remove-sheet-image",
30
+ type: ee.COMMAND,
31
+ handler: (i, t) => {
32
+ var S, C, D;
33
+ const e = i.get(Y), n = i.get(Ve), r = i.get(Yt), s = i.get(ae);
34
+ if (!t) return !1;
35
+ const { drawings: o } = t, a = [];
36
+ o.forEach((v) => {
37
+ const { unitId: b } = v;
38
+ a.push(b);
39
+ });
40
+ const c = s.getBatchRemoveOp(o), { unitId: u, subUnitId: l, undo: d, redo: g, objects: h } = c, m = r.onCommandExecute({ id: ot.id, params: t }), p = { id: A.id, params: { unitId: u, subUnitId: l, op: g, objects: h, type: P.REMOVE } }, f = { id: A.id, params: { unitId: u, subUnitId: l, op: d, objects: h, type: P.INSERT } };
41
+ return Zn([...(S = m.preRedos) != null ? S : [], p, ...m.redos], e) ? (n.pushUndoRedo({
42
+ unitID: u,
43
+ undoMutations: [
44
+ ...(C = m.preUndos) != null ? C : [],
45
+ f,
46
+ ...m.undos,
47
+ { id: F.id, params: a }
48
+ ],
49
+ redoMutations: [
50
+ ...(D = m.preRedos) != null ? D : [],
51
+ p,
52
+ ...m.redos,
53
+ { id: F.id, params: a }
54
+ ]
55
+ }), !0) : !1;
56
+ }
57
+ }, Ir = "COMPONENT_SHEET_DRAWING_PANEL", Cr = {
58
+ id: "sidebar.operation.sheet-image",
59
+ type: ee.COMMAND,
60
+ handler: async (i, t) => {
61
+ const e = i.get(Ui), n = i.get(it), r = i.get(Ce), s = i.get(Y);
62
+ if (!le(r)) return !1;
63
+ switch (t.value) {
64
+ case "open":
65
+ e.open({
66
+ header: { title: n.t("sheetImage.panel.title") },
67
+ children: { label: Ir },
68
+ onClose: () => {
69
+ s.syncExecuteCommand(Ft.id, []);
70
+ },
71
+ width: 360
72
+ });
73
+ break;
74
+ case "close":
75
+ default:
76
+ e.close();
77
+ break;
78
+ }
79
+ return !0;
80
+ }
81
+ }, Dr = {
82
+ id: "sheet.operation.edit-sheet-image",
83
+ type: ee.OPERATION,
84
+ handler: (i, t) => {
85
+ const e = i.get(Y);
86
+ return t == null ? !1 : (e.syncExecuteCommand(Ft.id, [t]), e.executeCommand(Cr.id, { value: "open" }), !0);
87
+ }
88
+ }, hs = "univer-upload-loading", gs = "univer-upload-loading-body", ms = "univer-upload-loading-body-animation", fs = "univer-upload-loading-body-text", bt = {
89
+ uploadLoading: hs,
90
+ uploadLoadingBody: gs,
91
+ uploadLoadingBodyAnimation: ms,
92
+ uploadLoadingBodyText: fs
93
+ }, ps = () => {
94
+ const i = Ee(qn), t = Ee(it), [e, n] = os.useState(0);
95
+ return wn(() => {
96
+ const r = i.change$.subscribe((s) => {
97
+ n(s);
98
+ });
99
+ return () => {
100
+ r.unsubscribe();
101
+ };
102
+ }, [i]), /* @__PURE__ */ Q("div", { style: { display: e > 0 ? "block" : "none" }, className: bt.uploadLoading, children: /* @__PURE__ */ Ut("div", { className: bt.uploadLoadingBody, children: [
103
+ /* @__PURE__ */ Q("div", { className: bt.uploadLoadingBodyAnimation }),
104
+ /* @__PURE__ */ Q("div", { className: bt.uploadLoadingBodyText, children: `${t.t("uploadLoading.loading")}: ${e}` })
105
+ ] }) });
106
+ };
107
+ var ws = Object.getOwnPropertyDescriptor, _s = (i, t, e, n) => {
108
+ for (var r = n > 1 ? void 0 : n ? ws(t, e) : t, s = i.length - 1, o; s >= 0; s--)
109
+ (o = i[s]) && (r = o(r) || r);
110
+ return r;
111
+ }, we = (i, t) => (e, n) => t(e, n, i);
112
+ let Pt = class extends Lr {
113
+ constructor(t, e, n, r, s, o, a, c) {
114
+ super();
115
+ q(this, "_initImagePopupMenu", /* @__PURE__ */ new Set());
116
+ this._injector = t, this._drawingManagerService = e, this._canvasPopManagerService = n, this._renderManagerService = r, this._univerInstanceService = s, this._contextService = o, this._uiPartsService = a, this._commandService = c, this._init();
117
+ }
118
+ _init() {
119
+ this._univerInstanceService.getCurrentTypeOfUnit$(x.UNIVER_SHEET).pipe($n(this.dispose$)).subscribe((t) => this._create(t)), this._univerInstanceService.getTypeOfUnitDisposed$(x.UNIVER_SHEET).pipe($n(this.dispose$)).subscribe((t) => this._dispose(t)), this._univerInstanceService.getAllUnitsForType(x.UNIVER_SHEET).forEach((t) => this._create(t)), this._uiPartsService.registerComponent(Ai.CONTENT, () => Ni(ps, this._injector));
120
+ }
121
+ _dispose(t) {
122
+ const e = t.getUnitId();
123
+ this._renderManagerService.removeRender(e);
124
+ }
125
+ _create(t) {
126
+ if (!t)
127
+ return;
128
+ const e = t.getUnitId();
129
+ this._renderManagerService.has(e) && !this._initImagePopupMenu.has(e) && (this._popupMenuListener(e), this._initImagePopupMenu.add(e));
130
+ }
131
+ _hasCropObject(t) {
132
+ const e = t.getAllObjectsByOrder();
133
+ for (const n of e)
134
+ if (n instanceof li)
135
+ return !0;
136
+ return !1;
137
+ }
138
+ _popupMenuListener(t) {
139
+ var s;
140
+ const e = (s = this._renderManagerService.getRenderById(t)) == null ? void 0 : s.scene;
141
+ if (!e)
142
+ return;
143
+ const n = e.getTransformerByCreate();
144
+ if (!n)
145
+ return;
146
+ let r;
147
+ this.disposeWithMe(
148
+ Fr(
149
+ n.createControl$.subscribe(() => {
150
+ if (this._contextService.setContextValue(Ye, !0), this._hasCropObject(e))
151
+ return;
152
+ const o = n.getSelectedObjectMap();
153
+ if (o.size > 1) {
154
+ r == null || r.dispose();
155
+ return;
156
+ }
157
+ const a = o.values().next().value;
158
+ if (!a)
159
+ return;
160
+ const c = a.oKey, u = this._drawingManagerService.getDrawingOKey(c);
161
+ if (!u)
162
+ return;
163
+ const { unitId: l, subUnitId: d, drawingId: g, drawingType: h } = u, m = u.data;
164
+ if (m && m.disablePopup)
165
+ return;
166
+ r == null || r.dispose();
167
+ const p = this._canvasPopManagerService.getFeatureMenu(l, d, g, h);
168
+ r = this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a, {
169
+ componentKey: ui,
170
+ direction: "horizontal",
171
+ offset: [2, 0],
172
+ extraProps: {
173
+ menuItems: p || this._getImageMenuItems(l, d, g, h)
174
+ }
175
+ }));
176
+ })
177
+ )
178
+ ), this.disposeWithMe(
179
+ n.clearControl$.subscribe(() => {
180
+ r == null || r.dispose(), this._contextService.setContextValue(Ye, !1), this._commandService.syncExecuteCommand(Ft.id, []);
181
+ })
182
+ ), this.disposeWithMe(
183
+ this._contextService.contextChanged$.subscribe((o) => {
184
+ o[Ye] === !1 && (r == null || r.dispose());
185
+ })
186
+ ), this.disposeWithMe(
187
+ n.changing$.subscribe(() => {
188
+ r == null || r.dispose();
189
+ })
190
+ );
191
+ }
192
+ _getImageMenuItems(t, e, n, r) {
193
+ return [
194
+ {
195
+ label: "image-popup.edit",
196
+ index: 0,
197
+ commandId: Dr.id,
198
+ commandParams: { unitId: t, subUnitId: e, drawingId: n },
199
+ disable: r === L.DRAWING_DOM
200
+ },
201
+ {
202
+ label: "image-popup.delete",
203
+ index: 1,
204
+ commandId: ot.id,
205
+ commandParams: { unitId: t, drawings: [{ unitId: t, subUnitId: e, drawingId: n }] },
206
+ disable: !1
207
+ },
208
+ {
209
+ label: "image-popup.crop",
210
+ index: 2,
211
+ commandId: hi.id,
212
+ commandParams: { unitId: t, subUnitId: e, drawingId: n },
213
+ disable: r === L.DRAWING_DOM
214
+ },
215
+ {
216
+ label: "image-popup.reset",
217
+ index: 3,
218
+ commandId: gi.id,
219
+ commandParams: [{ unitId: t, subUnitId: e, drawingId: n }],
220
+ disable: r === L.DRAWING_DOM
221
+ }
222
+ ];
223
+ }
224
+ };
225
+ Pt = _s([
226
+ we(0, N(st)),
227
+ we(1, oe),
228
+ we(2, N(Si)),
229
+ we(3, te),
230
+ we(4, Ce),
231
+ we(5, Jn),
232
+ we(6, N(Pi)),
233
+ we(7, Y)
234
+ ], Pt);
235
+ var vs = Object.getOwnPropertyDescriptor, Ss = (i, t, e, n) => {
236
+ for (var r = n > 1 ? void 0 : n ? vs(t, e) : t, s = i.length - 1, o; s >= 0; s--)
237
+ (o = i[s]) && (r = o(r) || r);
238
+ return r;
239
+ }, Rt = (i, t) => (e, n) => t(e, n, i);
240
+ let dn = class extends se {
241
+ constructor(t, e, n, r, s) {
242
+ super();
243
+ q(this, "_isSetCursor", !1);
244
+ this._context = t, this._hoverManagerService = e, this._selectionsService = n, this._drawingRenderService = r, this._sheetSkeletonManagerService = s, this._initHover(), this._initImageClick();
245
+ }
246
+ _initHover() {
247
+ this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(Gi(33)).subscribe((t) => {
248
+ var n, r;
249
+ const e = this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections();
250
+ (t == null ? void 0 : t.unitId) === this._context.unitId && (t != null && t.drawing) && e.length === 1 && ((n = e[0].primary) == null ? void 0 : n.actualRow) === t.row && ((r = e[0].primary) == null ? void 0 : r.actualColumn) === t.col ? (this._isSetCursor = !0, this._context.scene.setCursor(pi.ZOOM_IN)) : this._isSetCursor && (this._isSetCursor = !1, this._context.scene.resetCursor());
251
+ }));
252
+ }
253
+ _initImageClick() {
254
+ this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe((t) => {
255
+ var e;
256
+ if (t != null && t.drawing && this._isSetCursor) {
257
+ const n = t.drawing.drawing.drawingOrigin, r = (e = this._sheetSkeletonManagerService.getCurrentSkeleton()) == null ? void 0 : e.imageCacheMap.getImage(n.imageSourceType, n.source);
258
+ if (!r) return;
259
+ this._drawingRenderService.previewImage("preview-cell-image", r.src, r.width, r.height), this._context.scene.resetCursor(), this._isSetCursor = !1;
260
+ }
261
+ }));
262
+ }
263
+ };
264
+ dn = Ss([
265
+ Rt(1, N(Ii)),
266
+ Rt(2, N(pn)),
267
+ Rt(3, N(Qn)),
268
+ Rt(4, N(V))
269
+ ], dn);
270
+ function H(i, t, e) {
271
+ const { from: n, to: r, flipY: s = !1, flipX: o = !1, angle: a = 0, skewX: c = 0, skewY: u = 0 } = i, l = e.getCurrent();
272
+ if (l == null)
273
+ return;
274
+ const d = Ci(
275
+ l.unitId,
276
+ l.sheetId,
277
+ { from: n, to: r },
278
+ e
279
+ );
280
+ let { left: g, top: h, width: m, height: p } = d;
281
+ const f = e.getCurrentSkeleton(), w = f.rowHeaderWidth + f.columnTotalWidth, S = f.columnHeaderHeight + f.rowTotalHeight;
282
+ return g + m > w && (g = w - m), h + p > S && (h = S - p), {
283
+ flipY: s,
284
+ flipX: o,
285
+ angle: a,
286
+ skewX: c,
287
+ skewY: u,
288
+ left: g,
289
+ top: h,
290
+ width: m,
291
+ height: p
292
+ };
293
+ }
294
+ function $(i, t) {
295
+ const { left: e = 0, top: n = 0, width: r = 0, height: s = 0, flipY: o = !1, flipX: a = !1, angle: c = 0, skewX: u = 0, skewY: l = 0 } = i, d = t.getCellWithCoordByOffset(e, n);
296
+ if (d == null)
297
+ return;
298
+ const g = {
299
+ column: d.actualColumn,
300
+ columnOffset: It(e - d.startX, 1),
301
+ row: d.actualRow,
302
+ rowOffset: It(n - d.startY, 1)
303
+ }, h = t.getCellWithCoordByOffset(e + r, n + s);
304
+ if (h == null)
305
+ return;
306
+ const m = {
307
+ column: h.actualColumn,
308
+ columnOffset: It(e + r - h.startX, 1),
309
+ row: h.actualRow,
310
+ rowOffset: It(n + s - h.startY, 1)
311
+ };
312
+ return {
313
+ flipY: o,
314
+ flipX: a,
315
+ angle: c,
316
+ skewX: u,
317
+ skewY: l,
318
+ from: g,
319
+ to: m
320
+ };
321
+ }
322
+ var Is = Object.getOwnPropertyDescriptor, Cs = (i, t, e, n) => {
323
+ for (var r = n > 1 ? void 0 : n ? Is(t, e) : t, s = i.length - 1, o; s >= 0; s--)
324
+ (o = i[s]) && (r = o(r) || r);
325
+ return r;
326
+ }, Mt = (i, t) => (e, n) => t(e, n, i);
327
+ let ln = class extends se {
328
+ constructor(i, t, e, n, r) {
329
+ super(), this._context = i, this._sheetDrawingService = t, this._drawingManagerService = e, this._sheetSelectionRenderService = n, this._sheetSkeletonManagerService = r, this._init();
330
+ }
331
+ _init() {
332
+ this._drawingInitializeListener();
333
+ }
334
+ _drawingInitializeListener() {
335
+ this._sheetDrawingService.initializeNotification(this._context.unitId);
336
+ const i = this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);
337
+ for (const t in i) {
338
+ const e = i[t];
339
+ for (const n in e.data) {
340
+ const r = e.data[n];
341
+ r.transform = H(r.sheetTransform, this._sheetSelectionRenderService, this._sheetSkeletonManagerService);
342
+ }
343
+ }
344
+ this._drawingManagerService.registerDrawingData(this._context.unitId, this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)), this._drawingManagerService.initializeNotification(this._context.unitId);
345
+ }
346
+ };
347
+ ln = Cs([
348
+ Mt(1, ae),
349
+ Mt(2, oe),
350
+ Mt(3, N(Xe)),
351
+ Mt(4, N(V))
352
+ ], ln);
353
+ function Ds(i) {
354
+ const t = [];
355
+ return i.forEach((e) => {
356
+ const { parent: n, children: r } = e, { unitId: s, subUnitId: o, drawingId: a } = n, c = _i(0, 0, r.map((d) => d.transform || {})), u = r.map((d) => {
357
+ const g = d.transform || { left: 0, top: 0 }, { unitId: h, subUnitId: m, drawingId: p } = d;
358
+ return {
359
+ unitId: h,
360
+ subUnitId: m,
361
+ drawingId: p,
362
+ transform: {
363
+ ...g,
364
+ left: g.left - c.left,
365
+ top: g.top - c.top
366
+ },
367
+ groupId: a
368
+ };
369
+ }), l = {
370
+ unitId: s,
371
+ subUnitId: o,
372
+ drawingId: a,
373
+ drawingType: L.DRAWING_GROUP,
374
+ transform: c
375
+ };
376
+ t.push({
377
+ parent: l,
378
+ children: u
379
+ });
380
+ }), t;
381
+ }
382
+ function bs(i) {
383
+ const t = [];
384
+ return i.forEach((e) => {
385
+ const { parent: n, children: r } = e, { unitId: s, subUnitId: o, drawingId: a, transform: c = { width: 0, height: 0 } } = n;
386
+ if (c == null)
387
+ return;
388
+ const u = r.map((d) => {
389
+ const { transform: g } = d, { unitId: h, subUnitId: m, drawingId: p } = d, f = wi(g || {}, c, c.width || 0, c.height || 0);
390
+ return {
391
+ unitId: h,
392
+ subUnitId: m,
393
+ drawingId: p,
394
+ transform: f,
395
+ groupId: void 0
396
+ };
397
+ }), l = {
398
+ unitId: s,
399
+ subUnitId: o,
400
+ drawingId: a,
401
+ drawingType: L.DRAWING_GROUP,
402
+ transform: {
403
+ left: 0,
404
+ top: 0
405
+ }
406
+ };
407
+ t.push({
408
+ parent: l,
409
+ children: u
410
+ });
411
+ }), t;
412
+ }
413
+ const br = {
414
+ id: "sheet.command.group-sheet-image",
415
+ type: ee.COMMAND,
416
+ handler: (i, t) => {
417
+ const e = i.get(Y), n = i.get(Ve), r = i.get(ae);
418
+ if (!t) return !1;
419
+ const s = [];
420
+ t.forEach(({ parent: h, children: m }) => {
421
+ s.push(h.unitId), m.forEach((p) => {
422
+ s.push(p.unitId);
423
+ });
424
+ });
425
+ const o = r.getGroupDrawingOp(t), { unitId: a, subUnitId: c, undo: u, redo: l, objects: d } = o;
426
+ return e.syncExecuteCommand(A.id, { op: l, unitId: a, subUnitId: c, objects: d, type: P.GROUP }) ? (n.pushUndoRedo({
427
+ unitID: a,
428
+ undoMutations: [
429
+ { id: A.id, params: { op: u, unitId: a, subUnitId: c, objects: bs(d), type: P.UNGROUP } },
430
+ { id: F.id, params: s }
431
+ ],
432
+ redoMutations: [
433
+ { id: A.id, params: { op: l, unitId: a, subUnitId: c, objects: d, type: P.GROUP } },
434
+ { id: F.id, params: s }
435
+ ]
436
+ }), !0) : !1;
437
+ }
438
+ }, Gt = {
439
+ id: "sheet.command.insert-sheet-image",
440
+ type: ee.COMMAND,
441
+ handler: (i, t) => {
442
+ var S, C, D;
443
+ const e = i.get(Y), n = i.get(Ve), r = i.get(ae), s = i.get(Yt);
444
+ if (!t) return !1;
445
+ const o = t.drawings, a = o.map((v) => v.unitId), c = r.getBatchAddOp(o), { unitId: u, subUnitId: l, undo: d, redo: g, objects: h } = c, m = s.onCommandExecute({ id: Gt.id, params: t }), p = { id: A.id, params: { op: g, unitId: u, subUnitId: l, objects: h, type: P.INSERT } }, f = { id: A.id, params: { op: d, unitId: u, subUnitId: l, objects: h, type: P.REMOVE } };
446
+ return Zn([...(S = m.preRedos) != null ? S : [], p, ...m.redos], e) ? (n.pushUndoRedo({
447
+ unitID: u,
448
+ undoMutations: [
449
+ ...(C = m.preUndos) != null ? C : [],
450
+ f,
451
+ ...m.undos,
452
+ { id: F.id, params: a }
453
+ ],
454
+ redoMutations: [
455
+ ...(D = m.preRedos) != null ? D : [],
456
+ p,
457
+ ...m.redos,
458
+ { id: F.id, params: a }
459
+ ]
460
+ }), !0) : !1;
461
+ }
462
+ }, Rr = {
463
+ id: "sheet.command.set-drawing-arrange",
464
+ type: ee.COMMAND,
465
+ handler: (i, t) => {
466
+ const e = i.get(Y), n = i.get(Ve);
467
+ if (!t) return !1;
468
+ const r = i.get(ae), { unitId: s, subUnitId: o, drawingIds: a, arrangeType: c } = t, u = { unitId: s, subUnitId: o, drawingIds: a };
469
+ let l;
470
+ if (c === vt.forward ? l = r.getForwardDrawingsOp(u) : c === vt.backward ? l = r.getBackwardDrawingOp(u) : c === vt.front ? l = r.getFrontDrawingsOp(u) : c === vt.back && (l = r.getBackDrawingsOp(u)), l == null)
471
+ return !1;
472
+ const { objects: d, redo: g, undo: h } = l;
473
+ return e.syncExecuteCommand(A.id, { op: g, unitId: s, subUnitId: o, objects: d, type: P.ARRANGE }) ? (n.pushUndoRedo({
474
+ unitID: s,
475
+ undoMutations: [
476
+ { id: A.id, params: { op: h, unitId: s, subUnitId: o, objects: d, type: P.ARRANGE } }
477
+ ],
478
+ redoMutations: [
479
+ { id: A.id, params: { op: g, unitId: s, subUnitId: o, objects: d, type: P.ARRANGE } }
480
+ ]
481
+ }), !0) : !1;
482
+ }
483
+ }, Vt = {
484
+ id: "sheet.command.set-sheet-image",
485
+ type: ee.COMMAND,
486
+ handler: (i, t) => {
487
+ const e = i.get(Y), n = i.get(Ve), r = i.get(ae);
488
+ if (!t) return !1;
489
+ const { drawings: s } = t, o = r.getBatchUpdateOp(s), { unitId: a, subUnitId: c, undo: u, redo: l, objects: d } = o;
490
+ return e.syncExecuteCommand(A.id, { unitId: a, subUnitId: c, op: l, objects: d, type: P.UPDATE }) ? (n.pushUndoRedo({
491
+ unitID: a,
492
+ undoMutations: [
493
+ { id: A.id, params: { unitId: a, subUnitId: c, op: u, objects: d, type: P.UPDATE } },
494
+ { id: F.id, params: [a] }
495
+ ],
496
+ redoMutations: [
497
+ { id: A.id, params: { unitId: a, subUnitId: c, op: l, objects: d, type: P.UPDATE } },
498
+ { id: F.id, params: [a] }
499
+ ]
500
+ }), !0) : !1;
501
+ }
502
+ }, Mr = {
503
+ id: "sheet.command.ungroup-sheet-image",
504
+ type: ee.COMMAND,
505
+ handler: (i, t) => {
506
+ const e = i.get(Y), n = i.get(Ve), r = i.get(ae);
507
+ if (!t) return !1;
508
+ const s = [];
509
+ t.forEach(({ parent: h, children: m }) => {
510
+ s.push(h.unitId), m.forEach((p) => {
511
+ s.push(p.unitId);
512
+ });
513
+ });
514
+ const o = r.getUngroupDrawingOp(t), { unitId: a, subUnitId: c, undo: u, redo: l, objects: d } = o;
515
+ return e.syncExecuteCommand(A.id, { op: l, unitId: a, subUnitId: c, objects: d, type: P.UNGROUP }) ? (n.pushUndoRedo({
516
+ unitID: a,
517
+ undoMutations: [
518
+ { id: A.id, params: { op: u, unitId: a, subUnitId: c, objects: Ds(d), type: P.GROUP } },
519
+ { id: F.id, params: s }
520
+ ],
521
+ redoMutations: [
522
+ { id: A.id, params: { op: l, unitId: a, subUnitId: c, objects: d, type: P.UNGROUP } },
523
+ { id: F.id, params: s }
524
+ ]
525
+ }), !0) : !1;
526
+ }
527
+ };
528
+ var Rs = Object.getOwnPropertyDescriptor, Ms = (i, t, e, n) => {
529
+ for (var r = n > 1 ? void 0 : n ? Rs(t, e) : t, s = i.length - 1, o; s >= 0; s--)
530
+ (o = i[s]) && (r = o(r) || r);
531
+ return r;
532
+ }, re = (i, t) => (e, n) => t(e, n, i);
533
+ function ys(i, t, e) {
534
+ const n = e * Math.PI / 180, r = Math.abs(i * Math.cos(n)) + Math.abs(t * Math.sin(n)), s = Math.abs(i * Math.sin(n)) + Math.abs(t * Math.cos(n));
535
+ return { rotatedWidth: r, rotatedHeight: s };
536
+ }
537
+ function un(i, t, e, n, r) {
538
+ var S;
539
+ const { rotatedHeight: s, rotatedWidth: o } = ys(e, n, r), c = i.get(te).getRenderById(t.unitId);
540
+ if (!c)
541
+ return !1;
542
+ const l = (S = c.with(V).getSkeletonParam(t.subUnitId)) == null ? void 0 : S.skeleton;
543
+ if (l == null)
544
+ return !1;
545
+ const d = l.getCellByIndex(t.row, t.col), g = d.mergeInfo.endX - d.mergeInfo.startX - 2, h = d.mergeInfo.endY - d.mergeInfo.startY - 2, m = o / s, f = Math.ceil(Math.min(g, h * m)) / o, w = !f || Number.isNaN(f) ? 1e-3 : f;
546
+ return {
547
+ width: e * w,
548
+ height: n * w
549
+ };
550
+ }
551
+ let rt = class extends se {
552
+ constructor(t, e, n, r, s, o, a, c, u, l, d, g, h) {
553
+ super();
554
+ q(this, "_workbookSelections");
555
+ this._context = t, this._skeletonManagerService = e, this._commandService = n, this._selectionRenderService = r, this._imageIoService = s, this._fileOpenerService = o, this._sheetDrawingService = a, this._drawingManagerService = c, this._contextService = u, this._messageService = l, this._localeService = d, this._injector = h, this._workbookSelections = g.getWorkbookSelections(this._context.unitId), this._updateImageListener(), this._updateOrderListener(), this._groupDrawingListener(), this._focusDrawingListener();
556
+ }
557
+ async insertFloatImage() {
558
+ const t = await this._fileOpenerService.openFile({
559
+ multiple: !0,
560
+ accept: On.map((n) => `.${n.replace("image/", "")}`).join(",")
561
+ }), e = t.length;
562
+ return e > Un ? (this._messageService.show({
563
+ type: Re.Error,
564
+ content: this._localeService.t("update-status.exceedMaxCount", String(Un))
565
+ }), !1) : e === 0 ? !1 : (t.forEach(async (n) => await this.insertFloatImageByFile(n)), !0);
566
+ }
567
+ async insertCellImage() {
568
+ const e = (await this._fileOpenerService.openFile({
569
+ multiple: !1,
570
+ accept: On.map((n) => `.${n.replace("image/", "")}`).join(",")
571
+ }))[0];
572
+ return e ? (await this._insertCellImage(e), !0) : !1;
573
+ }
574
+ insertCellImageByFile(t, e) {
575
+ return this._insertCellImage(t, e);
576
+ }
577
+ async insertFloatImageByFile(t) {
578
+ let e;
579
+ try {
580
+ e = await this._imageIoService.saveImage(t);
581
+ } catch (S) {
582
+ const C = S.message;
583
+ C === Be.ERROR_EXCEED_SIZE ? this._messageService.show({
584
+ type: Re.Error,
585
+ content: this._localeService.t("update-status.exceedMaxSize", String(Pn / (1024 * 1024)))
586
+ }) : C === Be.ERROR_IMAGE_TYPE ? this._messageService.show({
587
+ type: Re.Error,
588
+ content: this._localeService.t("update-status.invalidImageType")
589
+ }) : C === Be.ERROR_IMAGE && this._messageService.show({
590
+ type: Re.Error,
591
+ content: this._localeService.t("update-status.invalidImage")
592
+ });
593
+ }
594
+ if (e == null)
595
+ return;
596
+ const n = this._getUnitInfo(), { unitId: r, subUnitId: s } = n, { imageId: o, imageSourceType: a, source: c, base64Cache: u } = e, { width: l, height: d, image: g } = await Zt(u || ""), { width: h, height: m } = this._context.scene;
597
+ this._imageIoService.addImageSourceCache(c, a, g);
598
+ let p = 1;
599
+ if (l > An || d > Nn) {
600
+ const S = An / l, C = Nn / d;
601
+ p = Math.max(S, C);
602
+ }
603
+ const f = this._getImagePosition(l * p, d * p, h, m);
604
+ if (f == null)
605
+ return;
606
+ const w = {
607
+ unitId: r,
608
+ subUnitId: s,
609
+ drawingId: o,
610
+ drawingType: L.DRAWING_IMAGE,
611
+ imageSourceType: a,
612
+ source: c,
613
+ transform: H(f, this._selectionRenderService, this._skeletonManagerService),
614
+ sheetTransform: f
615
+ };
616
+ return this._commandService.executeCommand(Gt.id, {
617
+ unitId: r,
618
+ drawings: [w]
619
+ });
620
+ }
621
+ // eslint-disable-next-line max-lines-per-function
622
+ async _insertCellImage(t, e) {
623
+ var w, S;
624
+ let n;
625
+ try {
626
+ n = await this._imageIoService.saveImage(t);
627
+ } catch (C) {
628
+ const D = C.message;
629
+ D === Be.ERROR_EXCEED_SIZE ? this._messageService.show({
630
+ type: Re.Error,
631
+ content: this._localeService.t("update-status.exceedMaxSize", String(Pn / (1024 * 1024)))
632
+ }) : D === Be.ERROR_IMAGE_TYPE ? this._messageService.show({
633
+ type: Re.Error,
634
+ content: this._localeService.t("update-status.invalidImageType")
635
+ }) : D === Be.ERROR_IMAGE && this._messageService.show({
636
+ type: Re.Error,
637
+ content: this._localeService.t("update-status.invalidImage")
638
+ });
639
+ }
640
+ if (n == null)
641
+ return !1;
642
+ const { imageId: r, imageSourceType: s, source: o, base64Cache: a } = n, { width: c, height: u, image: l } = await Zt(a || "");
643
+ this._imageIoService.addImageSourceCache(o, s, l);
644
+ const d = this._workbookSelections.getCurrentLastSelection();
645
+ if (!d)
646
+ return !1;
647
+ const g = tn("", {}), h = un(
648
+ this._injector,
649
+ {
650
+ unitId: this._context.unitId,
651
+ subUnitId: this._context.unit.getActiveSheet().getSheetId(),
652
+ row: d.primary.actualRow,
653
+ col: d.primary.actualColumn
654
+ },
655
+ c,
656
+ u,
657
+ 0
658
+ );
659
+ if (!h)
660
+ return !1;
661
+ const m = {
662
+ size: {
663
+ width: h.width,
664
+ height: h.height
665
+ },
666
+ positionH: {
667
+ relativeFrom: Rn.PAGE,
668
+ posOffset: 0
669
+ },
670
+ positionV: {
671
+ relativeFrom: bn.PARAGRAPH,
672
+ posOffset: 0
673
+ },
674
+ angle: 0
675
+ }, p = {
676
+ unitId: g.getUnitId(),
677
+ subUnitId: g.getUnitId(),
678
+ drawingId: r,
679
+ drawingType: L.DRAWING_IMAGE,
680
+ imageSourceType: s,
681
+ source: o,
682
+ transform: Xn(m),
683
+ docTransform: m,
684
+ behindDoc: En.FALSE,
685
+ title: "",
686
+ description: "",
687
+ layoutType: yn.INLINE,
688
+ // Insert inline drawing by default.
689
+ wrapText: Mn.BOTH_SIDES,
690
+ distB: 0,
691
+ distL: 0,
692
+ distR: 0,
693
+ distT: 0
694
+ }, f = nn.drawing.add({
695
+ documentDataModel: g,
696
+ drawings: [p],
697
+ selection: {
698
+ collapsed: !0,
699
+ startOffset: 0,
700
+ endOffset: 0
701
+ }
702
+ });
703
+ return f ? (g.apply(f), this._commandService.syncExecuteCommand(Yn.id, {
704
+ value: {
705
+ [(w = e == null ? void 0 : e.row) != null ? w : d.primary.actualRow]: {
706
+ [(S = e == null ? void 0 : e.col) != null ? S : d.primary.actualColumn]: {
707
+ p: g.getSnapshot(),
708
+ t: 1
709
+ }
710
+ }
711
+ },
712
+ unitId: e == null ? void 0 : e.unitId,
713
+ subUnitId: e == null ? void 0 : e.subUnitId
714
+ })) : !1;
715
+ }
716
+ // eslint-disable-next-line max-lines-per-function
717
+ async insertCellImageByUrl(t, e) {
718
+ var g, h;
719
+ const { width: n, height: r, image: s } = await Zt(t || "");
720
+ this._imageIoService.addImageSourceCache(t, Tn.URL, s);
721
+ const o = this._workbookSelections.getCurrentLastSelection();
722
+ if (!o)
723
+ return !1;
724
+ const a = tn("", {}), c = un(
725
+ this._injector,
726
+ {
727
+ unitId: this._context.unitId,
728
+ subUnitId: this._context.unit.getActiveSheet().getSheetId(),
729
+ row: o.primary.actualRow,
730
+ col: o.primary.actualColumn
731
+ },
732
+ n,
733
+ r,
734
+ 0
735
+ );
736
+ if (!c)
737
+ return !1;
738
+ const u = {
739
+ size: {
740
+ width: c.width,
741
+ height: c.height
742
+ },
743
+ positionH: {
744
+ relativeFrom: Rn.PAGE,
745
+ posOffset: 0
746
+ },
747
+ positionV: {
748
+ relativeFrom: bn.PARAGRAPH,
749
+ posOffset: 0
750
+ },
751
+ angle: 0
752
+ }, l = {
753
+ unitId: a.getUnitId(),
754
+ subUnitId: a.getUnitId(),
755
+ drawingId: Ot(),
756
+ drawingType: L.DRAWING_IMAGE,
757
+ imageSourceType: Tn.URL,
758
+ source: t,
759
+ transform: Xn(u),
760
+ docTransform: u,
761
+ behindDoc: En.FALSE,
762
+ title: "",
763
+ description: "",
764
+ layoutType: yn.INLINE,
765
+ // Insert inline drawing by default.
766
+ wrapText: Mn.BOTH_SIDES,
767
+ distB: 0,
768
+ distL: 0,
769
+ distR: 0,
770
+ distT: 0
771
+ }, d = nn.drawing.add({
772
+ documentDataModel: a,
773
+ drawings: [l],
774
+ selection: {
775
+ collapsed: !0,
776
+ startOffset: 0,
777
+ endOffset: 0
778
+ }
779
+ });
780
+ return d ? (a.apply(d), this._commandService.syncExecuteCommand(Yn.id, {
781
+ value: {
782
+ [(g = e == null ? void 0 : e.row) != null ? g : o.primary.actualRow]: {
783
+ [(h = e == null ? void 0 : e.col) != null ? h : o.primary.actualColumn]: {
784
+ p: a.getSnapshot(),
785
+ t: 1
786
+ }
787
+ }
788
+ },
789
+ unitId: e == null ? void 0 : e.unitId,
790
+ subUnitId: e == null ? void 0 : e.subUnitId
791
+ })) : !1;
792
+ }
793
+ _getUnitInfo() {
794
+ const t = this._context.unit, e = t.getActiveSheet(), n = t.getUnitId(), r = e.getSheetId();
795
+ return {
796
+ unitId: n,
797
+ subUnitId: r
798
+ };
799
+ }
800
+ _getImagePosition(t, e, n, r) {
801
+ const s = this._workbookSelections.getCurrentSelections();
802
+ let o = {
803
+ startRow: 0,
804
+ endRow: 0,
805
+ startColumn: 0,
806
+ endColumn: 0
807
+ };
808
+ s && s.length > 0 && (o = s[s.length - 1].range);
809
+ const a = tr(this._skeletonManagerService.getCurrent().skeleton, o);
810
+ if (a == null)
811
+ return;
812
+ let { startColumn: c, startRow: u, startX: l, startY: d } = a, g = !1;
813
+ if (l + t > n && (l = n - t, l < 0 && (l = 0, t = n), g = !0), d + e > r && (d = r - e, d < 0 && (d = 0, e = r), g = !0), g) {
814
+ const f = this._selectionRenderService.getCellWithCoordByOffset(l, d);
815
+ if (f == null)
816
+ return;
817
+ l = f.startX, d = f.startY, c = f.actualColumn, u = f.actualRow;
818
+ }
819
+ const h = {
820
+ column: c,
821
+ columnOffset: 0,
822
+ row: u,
823
+ rowOffset: 0
824
+ }, m = this._selectionRenderService.getCellWithCoordByOffset(l + t, d + e);
825
+ if (m == null)
826
+ return;
827
+ const p = {
828
+ column: m.actualColumn,
829
+ columnOffset: l + t - m.startX,
830
+ row: m.actualRow,
831
+ rowOffset: d + e - m.startY
832
+ };
833
+ return {
834
+ from: h,
835
+ to: p
836
+ };
837
+ }
838
+ _updateOrderListener() {
839
+ this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe((t) => {
840
+ const { unitId: e, subUnitId: n, drawingIds: r, arrangeType: s } = t;
841
+ this._commandService.executeCommand(Rr.id, {
842
+ unitId: e,
843
+ subUnitId: n,
844
+ drawingIds: r,
845
+ arrangeType: s
846
+ });
847
+ }));
848
+ }
849
+ _updateImageListener() {
850
+ this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe((t) => {
851
+ const e = [];
852
+ t.length !== 0 && (t.forEach((n) => {
853
+ const { unitId: r, subUnitId: s, drawingId: o, drawingType: a, transform: c } = n;
854
+ if (c == null)
855
+ return;
856
+ const u = this._sheetDrawingService.getDrawingByParam({ unitId: r, subUnitId: s, drawingId: o });
857
+ if (u == null || u.unitId !== this._context.unitId)
858
+ return;
859
+ const l = $({ ...u.transform, ...c }, this._selectionRenderService);
860
+ if (l == null)
861
+ return;
862
+ const d = {
863
+ ...n,
864
+ transform: { ...u.transform, ...c, ...H(l, this._selectionRenderService, this._skeletonManagerService) },
865
+ sheetTransform: { ...l }
866
+ };
867
+ e.push(d);
868
+ }), e.length > 0 && this._commandService.executeCommand(Vt.id, {
869
+ unitId: t[0].unitId,
870
+ drawings: e
871
+ }));
872
+ }));
873
+ }
874
+ _groupDrawingListener() {
875
+ this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe((t) => {
876
+ this._commandService.executeCommand(br.id, t);
877
+ const { unitId: e, subUnitId: n, drawingId: r } = t[0].parent;
878
+ this._commandService.syncExecuteCommand(Ft.id, [{ unitId: e, subUnitId: n, drawingId: r }]);
879
+ })), this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe((t) => {
880
+ this._commandService.executeCommand(Mr.id, t);
881
+ }));
882
+ }
883
+ _focusDrawingListener() {
884
+ this.disposeWithMe(
885
+ this._drawingManagerService.focus$.subscribe((t) => {
886
+ t == null || t.length === 0 ? (this._contextService.setContextValue(Ye, !1), this._sheetDrawingService.focusDrawing([])) : (this._contextService.setContextValue(Ye, !0), this._sheetDrawingService.focusDrawing(t));
887
+ })
888
+ );
889
+ }
890
+ };
891
+ rt = Ms([
892
+ re(1, N(V)),
893
+ re(2, Y),
894
+ re(3, Xe),
895
+ re(4, qn),
896
+ re(5, ki),
897
+ re(6, ae),
898
+ re(7, oe),
899
+ re(8, Jn),
900
+ re(9, Bi),
901
+ re(10, N(it)),
902
+ re(11, N(pn)),
903
+ re(12, N(st))
904
+ ], rt);
905
+ var Es = Object.getOwnPropertyDescriptor, Ts = (i, t, e, n) => {
906
+ for (var r = n > 1 ? void 0 : n ? Es(t, e) : t, s = i.length - 1, o; s >= 0; s--)
907
+ (o = i[s]) && (r = o(r) || r);
908
+ return r;
909
+ }, $e = (i, t) => (e, n) => t(e, n, i);
910
+ function yr(i, t, e) {
911
+ var n, r, s, o;
912
+ if (((r = (n = e == null ? void 0 : e.p) == null ? void 0 : n.body) == null ? void 0 : r.dataStream.length) === 3 && ((o = (s = e.p) == null ? void 0 : s.drawingsOrder) == null ? void 0 : o.length) === 1) {
913
+ const a = e.p.drawings[e.p.drawingsOrder[0]], c = un(
914
+ i,
915
+ {
916
+ unitId: t.unitId,
917
+ subUnitId: t.subUnitId,
918
+ row: t.row,
919
+ col: t.col
920
+ },
921
+ a.docTransform.size.width,
922
+ a.docTransform.size.height,
923
+ a.docTransform.angle
924
+ );
925
+ if (c)
926
+ return a.transform.width = c.width, a.transform.height = c.height, a.docTransform.size.width = c.width, a.docTransform.size.height = c.height, a.transform.left = 0, a.transform.top = 0, a.docTransform.positionH.posOffset = 0, a.docTransform.positionV.posOffset = 0, e.p.documentStyle.pageSize.width = 1 / 0, e.p.documentStyle.pageSize.height = 1 / 0, !0;
927
+ }
928
+ return !1;
929
+ }
930
+ let At = class extends se {
931
+ constructor(i, t, e, n, r, s) {
932
+ super(), this._commandService = i, this._sheetInterceptorService = t, this._injector = e, this._drawingManagerService = n, this._docDrawingController = r, this._editorBridgeService = s, this._handleInitEditor(), this._initCellContentInterceptor();
933
+ }
934
+ _handleInitEditor() {
935
+ this.disposeWithMe(this._editorBridgeService.visible$.subscribe((i) => {
936
+ i.visible ? i.visible && (this._drawingManagerService.removeDrawingDataForUnit(nt), this._docDrawingController.loadDrawingDataForUnit(nt), this._drawingManagerService.initializeNotification(nt)) : this._drawingManagerService.removeDrawingDataForUnit(nt);
937
+ })), this.disposeWithMe(this._commandService.onCommandExecuted((i) => {
938
+ i.id === cs.id && i.params.unitId === Le && (this._drawingManagerService.removeDrawingDataForUnit(Le), this._docDrawingController.loadDrawingDataForUnit(Le), this._drawingManagerService.initializeNotification(Le));
939
+ }));
940
+ }
941
+ _initCellContentInterceptor() {
942
+ this.disposeWithMe(
943
+ this._sheetInterceptorService.intercept(
944
+ Hi.CELL_CONTENT,
945
+ {
946
+ effect: Yr.Style,
947
+ priority: zi.CELL_IMAGE,
948
+ handler: (i, t, e) => {
949
+ var n;
950
+ return i != null && i.p && ((n = i.p.drawingsOrder) != null && n.length) && (i.interceptorStyle || (i.interceptorStyle = {}), i.interceptorStyle.tr = { a: 0 }, yr(this._injector, { unitId: t.unitId, subUnitId: t.subUnitId, row: t.row, col: t.col }, i)), e(i);
951
+ }
952
+ }
953
+ )
954
+ );
955
+ }
956
+ };
957
+ At = Ts([
958
+ $e(0, Y),
959
+ $e(1, N(Yt)),
960
+ $e(2, N(st)),
961
+ $e(3, oe),
962
+ $e(4, N(oi)),
963
+ $e(5, N(Di))
964
+ ], At);
965
+ var Os = Object.getOwnPropertyDescriptor, Us = (i, t, e, n) => {
966
+ for (var r = n > 1 ? void 0 : n ? Os(t, e) : t, s = i.length - 1, o; s >= 0; s--)
967
+ (o = i[s]) && (r = o(r) || r);
968
+ return r;
969
+ }, zn = (i, t) => (e, n) => t(e, n, i);
970
+ let Nt = class extends se {
971
+ constructor(i, t) {
972
+ super(), this._autoFillService = i, this._injector = t, this._initAutoFillHooks();
973
+ }
974
+ _initAutoFillHooks() {
975
+ this.disposeWithMe(
976
+ this._autoFillService.addHook({
977
+ id: "sheet-cell-image-autofill",
978
+ onBeforeSubmit: (i, t, e, n) => {
979
+ new Gr(n).forValue((r, s, o) => {
980
+ yr(this._injector, { unitId: i.unitId, subUnitId: i.subUnitId, row: r, col: s }, o);
981
+ });
982
+ }
983
+ })
984
+ );
985
+ }
986
+ };
987
+ Nt = Us([
988
+ zn(0, N(bi)),
989
+ zn(1, N(st))
990
+ ], Nt);
991
+ var Ps = Object.getOwnPropertyDescriptor, As = (i, t, e, n) => {
992
+ for (var r = n > 1 ? void 0 : n ? Ps(t, e) : t, s = i.length - 1, o; s >= 0; s--)
993
+ (o = i[s]) && (r = o(r) || r);
994
+ return r;
995
+ }, qe = (i, t) => (e, n) => t(e, n, i);
996
+ const Ns = [
997
+ nt,
998
+ Vr,
999
+ Le
1000
+ ];
1001
+ let kt = class extends se {
1002
+ constructor(i, t, e, n, r) {
1003
+ super(), this._commandService = i, this._univerInstanceService = t, this._dialogService = e, this._renderManagerService = n, this._localeService = r, this._initDocImageCopyPasteHooks();
1004
+ }
1005
+ _setCellImage(i) {
1006
+ var r;
1007
+ const t = tn("", {}), e = (r = gn(x.UNIVER_SHEET, this._univerInstanceService, this._renderManagerService)) == null ? void 0 : r.with(Ri), n = nn.drawing.add({
1008
+ documentDataModel: t,
1009
+ drawings: [i],
1010
+ selection: {
1011
+ collapsed: !0,
1012
+ startOffset: 0,
1013
+ endOffset: 0
1014
+ }
1015
+ });
1016
+ n && (t.apply(n), e && e.submitCellData(t));
1017
+ }
1018
+ _initDocImageCopyPasteHooks() {
1019
+ this.disposeWithMe(
1020
+ this._commandService.beforeCommandExecuted((i) => {
1021
+ var t, e;
1022
+ if (i.id === ds.id) {
1023
+ const n = i.params, { doc: r } = n, s = this._univerInstanceService.getCurrentUnitOfType(x.UNIVER_DOC);
1024
+ if (s == null || !Object.keys((t = r.drawings) != null ? t : {}).length)
1025
+ return;
1026
+ const o = s.getUnitId();
1027
+ if (Ns.includes(o)) {
1028
+ if (o !== Le) {
1029
+ const a = () => {
1030
+ this._dialogService.close("sheet-cell-image-copy-paste"), this._commandService.syncExecuteCommand(Bn.id, {
1031
+ visible: !1
1032
+ });
1033
+ };
1034
+ ((e = s.getBody()) == null ? void 0 : e.dataStream) === `\r
1035
+ ` ? (this._commandService.syncExecuteCommand(Bn.id, {
1036
+ visible: !1
1037
+ }), this._setCellImage(Object.values(r.drawings)[0])) : this._dialogService.open({
1038
+ id: "sheet-cell-image-copy-paste",
1039
+ title: {
1040
+ label: this._localeService.t("cell-image.pasteTitle")
1041
+ },
1042
+ children: {
1043
+ label: this._localeService.t("cell-image.pasteContent")
1044
+ },
1045
+ width: 320,
1046
+ destroyOnClose: !0,
1047
+ onClose: a,
1048
+ showOk: !0,
1049
+ showCancel: !0,
1050
+ onOk: () => {
1051
+ a(), this._setCellImage(Object.values(r.drawings)[0]);
1052
+ },
1053
+ onCancel: a
1054
+ });
1055
+ }
1056
+ throw new Error("Sheet cell image copy paste is not supported in this unit");
1057
+ }
1058
+ }
1059
+ })
1060
+ );
1061
+ }
1062
+ };
1063
+ kt = As([
1064
+ qe(0, Y),
1065
+ qe(1, Ce),
1066
+ qe(2, Wi),
1067
+ qe(3, te),
1068
+ qe(4, N(it))
1069
+ ], kt);
1070
+ const Xt = {
1071
+ id: "sheet.command.insert-float-image",
1072
+ type: ee.COMMAND,
1073
+ handler: async (i, t) => {
1074
+ var o, a;
1075
+ const e = i.get(Ce), n = i.get(te), r = (o = gn(
1076
+ x.UNIVER_SHEET,
1077
+ e,
1078
+ n
1079
+ )) == null ? void 0 : o.with(rt);
1080
+ if (!r)
1081
+ return !1;
1082
+ const s = t == null ? void 0 : t.files;
1083
+ if (s) {
1084
+ const c = s.map((u) => r.insertFloatImageByFile(u));
1085
+ return (await Promise.all(c)).every((u) => u);
1086
+ } else
1087
+ return (a = r.insertFloatImage()) != null ? a : !1;
1088
+ }
1089
+ }, _n = {
1090
+ id: "sheet.command.insert-cell-image",
1091
+ type: ee.COMMAND,
1092
+ handler: (i) => {
1093
+ var n, r;
1094
+ const t = i.get(Ce), e = i.get(te);
1095
+ return (r = (n = gn(
1096
+ x.UNIVER_SHEET,
1097
+ t,
1098
+ e
1099
+ )) == null ? void 0 : n.with(rt).insertCellImage()) != null ? r : !1;
1100
+ }
1101
+ };
1102
+ var ks = Object.getOwnPropertyDescriptor, Bs = (i, t, e, n) => {
1103
+ for (var r = n > 1 ? void 0 : n ? ks(t, e) : t, s = i.length - 1, o; s >= 0; s--)
1104
+ (o = i[s]) && (r = o(r) || r);
1105
+ return r;
1106
+ }, Qe = (i, t) => (e, n) => t(e, n, i);
1107
+ const Er = "image/png";
1108
+ function Ws(i) {
1109
+ const t = i.split(","), e = atob(t[1]), n = e.length, r = new Uint8Array(n);
1110
+ for (let s = 0; s < n; s++)
1111
+ r[s] = e.charCodeAt(s);
1112
+ return new Blob([r], { type: Er });
1113
+ }
1114
+ function js(i) {
1115
+ const t = new ClipboardItem({ [Er]: Ws(i) });
1116
+ navigator.clipboard.write([t]).catch((e) => {
1117
+ console.error("Could not copy image using clipboard API: ", e);
1118
+ });
1119
+ }
1120
+ function $s() {
1121
+ function i() {
1122
+ const n = document.createElement("input");
1123
+ return n.style.position = "absolute", n.style.height = "1px", n.style.width = "1px", n.style.opacity = "0", n;
1124
+ }
1125
+ const t = document.activeElement, e = i();
1126
+ return document.body.appendChild(e), e.focus(), () => {
1127
+ e.blur(), document.body.removeChild(e), t instanceof HTMLElement && t.focus();
1128
+ };
1129
+ }
1130
+ const Kn = [
1131
+ Fe.SPECIAL_PASTE_COL_WIDTH,
1132
+ Fe.SPECIAL_PASTE_VALUE,
1133
+ Fe.SPECIAL_PASTE_FORMAT,
1134
+ Fe.SPECIAL_PASTE_FORMULA
1135
+ ];
1136
+ let Bt = class extends se {
1137
+ constructor(t, e, n, r, s) {
1138
+ super();
1139
+ q(this, "_copyInfo");
1140
+ this._sheetClipboardService = t, this._renderManagerService = e, this._drawingService = n, this._clipboardInterfaceService = r, this._commandService = s, this._initCopyPaste();
1141
+ }
1142
+ get _focusedDrawings() {
1143
+ return this._drawingService.getFocusDrawings();
1144
+ }
1145
+ // eslint-disable-next-line max-lines-per-function
1146
+ _initCopyPaste() {
1147
+ this._sheetClipboardService.addClipboardHook({
1148
+ id: "SHEET_IMAGE_UI_PLUGIN",
1149
+ onBeforeCopy: (t, e, n, r) => {
1150
+ const s = this._focusedDrawings;
1151
+ if (s.length > 0) {
1152
+ const [o] = s;
1153
+ if (r === be.CUT) {
1154
+ const c = {
1155
+ unitId: t,
1156
+ drawings: [o]
1157
+ };
1158
+ this._commandService.executeCommand(ot.id, c);
1159
+ }
1160
+ setTimeout(() => {
1161
+ const c = $s();
1162
+ o.drawingType === L.DRAWING_IMAGE && o.imageSourceType === ci.BASE64 ? js(o.source) : this._clipboardInterfaceService.writeText(""), c();
1163
+ }, 200);
1164
+ const a = {
1165
+ unitId: o.unitId,
1166
+ subUnitId: o.subUnitId,
1167
+ drawings: [o]
1168
+ };
1169
+ this._copyInfo = a;
1170
+ } else {
1171
+ const o = this._createDrawingsCopyInfoByRange(t, e, n);
1172
+ this._copyInfo = o;
1173
+ }
1174
+ },
1175
+ onPasteCells: (t, e, n, r) => {
1176
+ if (!this._copyInfo)
1177
+ return { redos: [], undos: [] };
1178
+ const { copyType: s = be.COPY, pasteType: o } = r, { range: a } = t || {}, { range: c, unitId: u, subUnitId: l } = e;
1179
+ return this._copyInfo.copyRange ? this._generateRangeDrawingsPasteMutations({ pasteType: o, unitId: u, subUnitId: l, pasteRange: c }, { copyRange: a, copyType: s }) : this._generateSingleDrawingPasteMutations({ pasteTo: e, pasteType: o }, be.COPY);
1180
+ },
1181
+ onPastePlainText: (t, e) => ({ undos: [], redos: [] }),
1182
+ onPasteUnrecognized: (t) => this._copyInfo ? this._generateSingleDrawingPasteMutations({ pasteTo: t, pasteType: Fe.DEFAULT_PASTE }, be.COPY) : { undos: [], redos: [] },
1183
+ onPasteFiles: (t, e) => {
1184
+ if (this._copyInfo)
1185
+ return this._generateSingleDrawingPasteMutations({ pasteTo: t, pasteType: Fe.DEFAULT_PASTE }, be.COPY);
1186
+ {
1187
+ const n = e.filter((r) => r.type.includes("image"));
1188
+ if (n.length)
1189
+ return {
1190
+ undos: [],
1191
+ redos: [
1192
+ {
1193
+ id: Xt.id,
1194
+ params: { files: n }
1195
+ }
1196
+ ]
1197
+ };
1198
+ }
1199
+ return { undos: [], redos: [] };
1200
+ }
1201
+ });
1202
+ }
1203
+ _createDrawingsCopyInfoByRange(t, e, n) {
1204
+ var g;
1205
+ const r = (g = this._renderManagerService.getRenderById(t)) == null ? void 0 : g.with(V);
1206
+ if (!r) return;
1207
+ const s = r.attachRangeWithCoord(n);
1208
+ if (!s)
1209
+ return;
1210
+ const { startX: o, endX: a, startY: c, endY: u } = s, l = this._drawingService.getDrawingData(t, e), d = this._focusedDrawings.slice();
1211
+ if (Object.keys(l).forEach((h) => {
1212
+ const m = l[h], { transform: p } = m;
1213
+ if (m.anchorType !== U.Both || !p)
1214
+ return;
1215
+ const { left: f = 0, top: w = 0, width: S = 0, height: C = 0 } = p, { drawingStartX: D, drawingEndX: v, drawingStartY: b, drawingEndY: _ } = {
1216
+ drawingStartX: f,
1217
+ drawingEndX: f + S,
1218
+ drawingStartY: w,
1219
+ drawingEndY: w + C
1220
+ };
1221
+ o <= D && v <= a && c <= b && _ <= u && d.push(m);
1222
+ }), d.length)
1223
+ return {
1224
+ copyRange: n,
1225
+ drawings: d,
1226
+ unitId: t,
1227
+ subUnitId: e
1228
+ };
1229
+ }
1230
+ _generateSingleDrawingPasteMutations(t, e) {
1231
+ const { pasteType: n, pasteTo: r } = t;
1232
+ if (Kn.includes(n))
1233
+ return { redos: [], undos: [] };
1234
+ const { unitId: s, subUnitId: o, range: a } = r, c = this._renderManagerService.getRenderById(s), u = c == null ? void 0 : c.with(V), l = c == null ? void 0 : c.with(Xe), d = this._copyInfo;
1235
+ if (!u || !l)
1236
+ return { redos: [], undos: [] };
1237
+ const { drawings: g } = d, h = Wn(a);
1238
+ return this._generateMutations(g, {
1239
+ unitId: s,
1240
+ subUnitId: o,
1241
+ isCut: e === be.CUT,
1242
+ getTransform: (m, p) => {
1243
+ var S;
1244
+ const f = u.attachRangeWithCoord({
1245
+ startRow: h.startRow,
1246
+ endRow: h.endRow,
1247
+ startColumn: h.startColumn,
1248
+ endColumn: h.endColumn
1249
+ }), w = {
1250
+ ...m,
1251
+ left: f == null ? void 0 : f.startX,
1252
+ top: f == null ? void 0 : f.startY
1253
+ };
1254
+ return {
1255
+ transform: w,
1256
+ sheetTransform: (S = $(w, l)) != null ? S : p
1257
+ };
1258
+ }
1259
+ });
1260
+ }
1261
+ _generateMutations(t, e) {
1262
+ const {
1263
+ unitId: n,
1264
+ subUnitId: r,
1265
+ getTransform: s,
1266
+ isCut: o
1267
+ } = e, a = [], c = [], { _drawingService: u } = this;
1268
+ return t.forEach((l) => {
1269
+ const { transform: d, sheetTransform: g } = l;
1270
+ if (!d)
1271
+ return;
1272
+ const h = s(d, g), m = {
1273
+ ...l,
1274
+ unitId: n,
1275
+ subUnitId: r,
1276
+ drawingId: o ? l.drawingId : ye.generateRandomId(),
1277
+ transform: h.transform,
1278
+ sheetTransform: h.sheetTransform
1279
+ };
1280
+ if (o) {
1281
+ const { undo: p, redo: f, objects: w } = u.getBatchUpdateOp([m]);
1282
+ a.push({
1283
+ id: A.id,
1284
+ params: {
1285
+ unitId: n,
1286
+ subUnitId: r,
1287
+ type: P.UPDATE,
1288
+ op: f,
1289
+ objects: w
1290
+ }
1291
+ }), c.push({
1292
+ id: A.id,
1293
+ params: {
1294
+ unitId: n,
1295
+ subUnitId: r,
1296
+ type: P.UPDATE,
1297
+ op: p,
1298
+ objects: w
1299
+ }
1300
+ });
1301
+ } else {
1302
+ const { undo: p, redo: f, objects: w } = u.getBatchAddOp([m]);
1303
+ a.push({ id: A.id, params: { op: f, unitId: n, subUnitId: r, objects: w, type: P.INSERT } }), c.push({ id: A.id, params: { op: p, unitId: n, subUnitId: r, objects: w, type: P.REMOVE } });
1304
+ }
1305
+ }), { redos: a, undos: c };
1306
+ }
1307
+ // eslint-disable-next-line max-lines-per-function
1308
+ _generateRangeDrawingsPasteMutations(t, e) {
1309
+ var T;
1310
+ const {
1311
+ unitId: n,
1312
+ subUnitId: r,
1313
+ pasteType: s,
1314
+ pasteRange: o
1315
+ } = t, {
1316
+ copyRange: a,
1317
+ copyType: c
1318
+ } = e;
1319
+ if (Kn.includes(s))
1320
+ return { redos: [], undos: [] };
1321
+ const u = (T = this._renderManagerService.getRenderById(n)) == null ? void 0 : T.with(V);
1322
+ if (!u || !this._copyInfo)
1323
+ return { redos: [], undos: [] };
1324
+ const { drawings: l } = this._copyInfo;
1325
+ if (!a)
1326
+ return this._generateSingleDrawingPasteMutations({
1327
+ pasteTo: { unitId: n, subUnitId: r, range: Wn(o) },
1328
+ pasteType: s
1329
+ }, c);
1330
+ const { ranges: [d, g], mapFunc: h } = Mi([a, o]), { row: m, col: p } = h(d.startRow, d.startColumn), { row: f, col: w } = h(g.startRow, g.startColumn), S = u.attachRangeWithCoord({
1331
+ startRow: m,
1332
+ endRow: m,
1333
+ startColumn: p,
1334
+ endColumn: p
1335
+ }), C = u.attachRangeWithCoord({
1336
+ startRow: f,
1337
+ endRow: f,
1338
+ startColumn: w,
1339
+ endColumn: w
1340
+ });
1341
+ if (!S || !C || !this._copyInfo)
1342
+ return { redos: [], undos: [] };
1343
+ const D = C.startX - S.startX, v = C.startY - S.startY, b = f - m, _ = w - p;
1344
+ return this._generateMutations(l, {
1345
+ unitId: n,
1346
+ subUnitId: r,
1347
+ getTransform: (M, y) => {
1348
+ var E, I;
1349
+ return {
1350
+ transform: {
1351
+ ...M,
1352
+ left: ((E = M == null ? void 0 : M.left) != null ? E : 0) + D,
1353
+ top: ((I = M == null ? void 0 : M.top) != null ? I : 0) + v
1354
+ },
1355
+ sheetTransform: {
1356
+ ...y,
1357
+ to: {
1358
+ ...y.to,
1359
+ row: y.to.row + b,
1360
+ column: y.to.column + _
1361
+ },
1362
+ from: {
1363
+ ...y.from,
1364
+ row: y.from.row + b,
1365
+ column: y.from.column + _
1366
+ }
1367
+ }
1368
+ };
1369
+ },
1370
+ isCut: c === be.CUT
1371
+ });
1372
+ }
1373
+ };
1374
+ Bt = Bs([
1375
+ Qe(0, yi),
1376
+ Qe(1, te),
1377
+ Qe(2, oe),
1378
+ Qe(3, ji),
1379
+ Qe(4, Y)
1380
+ ], Bt);
1381
+ var xs = Object.getOwnPropertyDescriptor, Ls = (i, t, e, n) => {
1382
+ for (var r = n > 1 ? void 0 : n ? xs(t, e) : t, s = i.length - 1, o; s >= 0; s--)
1383
+ (o = i[s]) && (r = o(r) || r);
1384
+ return r;
1385
+ }, et = (i, t) => (e, n) => t(e, n, i);
1386
+ let Wt = class extends se {
1387
+ constructor(i, t, e, n, r) {
1388
+ super(), this._drawingManagerService = i, this._renderManagerService = t, this._permissionService = e, this._univerInstanceService = n, this._userManagerService = r, this._initDrawingVisible(), this._initDrawingEditable(), this._initViewPermissionChange(), this._initEditPermissionChange();
1389
+ }
1390
+ _initDrawingVisible() {
1391
+ const i = this._univerInstanceService.getCurrentTypeOfUnit$(x.UNIVER_SHEET), t = this._userManagerService.currentUser$, e = Ct([i, t]);
1392
+ this.disposeWithMe(
1393
+ e.pipe(
1394
+ Se(([n, r]) => n ? n.activeSheet$.pipe(
1395
+ xn((s) => {
1396
+ if (!s) {
1397
+ this._drawingManagerService.setDrawingVisible(!1);
1398
+ return;
1399
+ }
1400
+ const o = n.getUnitId(), a = s.getSheetId();
1401
+ this._permissionService.composePermission([
1402
+ new Gn(o).id,
1403
+ new Vn(o, a).id
1404
+ ]).every((u) => u.value) ? this._drawingManagerService.setDrawingVisible(!0) : this._handleDrawingVisibilityFalse(n, s);
1405
+ })
1406
+ ) : (this._drawingManagerService.setDrawingVisible(!1), pe))
1407
+ ).subscribe()
1408
+ );
1409
+ }
1410
+ _handleDrawingVisibilityFalse(i, t) {
1411
+ this._drawingManagerService.setDrawingVisible(!1);
1412
+ const e = i.getUnitId(), n = t.getSheetId(), r = this._drawingManagerService.getDrawingData(e, n), s = Object.values(r), o = this._renderManagerService.getRenderById(e), a = o == null ? void 0 : o.scene;
1413
+ if (!a)
1414
+ return;
1415
+ a.getAllObjectsByOrder().forEach((u) => {
1416
+ u.classType === We.IMAGE && s.some((l) => u.oKey.includes(l.drawingId)) && a.removeObject(u);
1417
+ });
1418
+ }
1419
+ _initDrawingEditable() {
1420
+ const i = this._univerInstanceService.getCurrentTypeOfUnit$(x.UNIVER_SHEET), t = this._userManagerService.currentUser$, e = Ct([i, t]);
1421
+ this.disposeWithMe(
1422
+ e.pipe(
1423
+ Se(([n, r]) => n ? n.activeSheet$.pipe(
1424
+ xn((s) => {
1425
+ if (!s) {
1426
+ this._drawingManagerService.setDrawingEditable(!1);
1427
+ return;
1428
+ }
1429
+ const o = n.getUnitId(), a = s.getSheetId();
1430
+ this._permissionService.composePermission([
1431
+ new rn(o).id,
1432
+ new sn(o, a).id
1433
+ ]).every((u) => u.value) ? this._drawingManagerService.setDrawingEditable(!0) : this._handleDrawingEditableFalse(n, s);
1434
+ })
1435
+ ) : (this._drawingManagerService.setDrawingEditable(!1), pe))
1436
+ ).subscribe()
1437
+ );
1438
+ }
1439
+ _handleDrawingEditableFalse(i, t) {
1440
+ this._drawingManagerService.setDrawingEditable(!1);
1441
+ const e = i.getUnitId(), n = t.getSheetId(), r = this._drawingManagerService.getDrawingData(e, n), s = Object.values(r), o = this._renderManagerService.getRenderById(e), a = o == null ? void 0 : o.scene;
1442
+ if (!a)
1443
+ return;
1444
+ a.getAllObjectsByOrder().forEach((u) => {
1445
+ u.classType === We.IMAGE && s.some((l) => u.oKey.includes(l.drawingId)) && a.detachTransformerFrom(u);
1446
+ });
1447
+ }
1448
+ _initViewPermissionChange() {
1449
+ const i = this._univerInstanceService.getCurrentTypeOfUnit$(x.UNIVER_SHEET), t = this._userManagerService.currentUser$;
1450
+ this.disposeWithMe(
1451
+ Ct([i, t]).pipe(
1452
+ Se(([e, n]) => e ? e.activeSheet$.pipe(
1453
+ Se((r) => {
1454
+ if (!r)
1455
+ return pe;
1456
+ const s = e.getUnitId(), o = r.getSheetId(), a = this._renderManagerService.getRenderById(s), c = a == null ? void 0 : a.scene;
1457
+ if (!c)
1458
+ return pe;
1459
+ const u = c.getTransformerByCreate();
1460
+ return this._permissionService.composePermission$([
1461
+ new Gn(s).id,
1462
+ new Vn(s, o).id
1463
+ ]).pipe(
1464
+ Te((d) => d.every((g) => g.value)),
1465
+ Ln()
1466
+ ).pipe(
1467
+ Te((d) => ({
1468
+ permission: d,
1469
+ scene: c,
1470
+ transformer: u,
1471
+ unitId: s,
1472
+ subUnitId: o
1473
+ }))
1474
+ );
1475
+ })
1476
+ ) : pe)
1477
+ ).subscribe({
1478
+ next: ({ permission: e, scene: n, transformer: r, unitId: s, subUnitId: o }) => {
1479
+ this._drawingManagerService.setDrawingVisible(e);
1480
+ const a = n.getAllObjectsByOrder(), c = this._drawingManagerService.getDrawingData(s, o), u = Object.values(c);
1481
+ e ? this._drawingManagerService.addNotification(u) : (a.forEach((l) => {
1482
+ l.classType === We.IMAGE && u.some((d) => l.oKey.includes(d.drawingId)) && n.removeObject(l);
1483
+ }), r.clearSelectedObjects());
1484
+ },
1485
+ complete: () => {
1486
+ this._drawingManagerService.setDrawingVisible(!0);
1487
+ const e = this._univerInstanceService.getCurrentUnitForType(x.UNIVER_SHEET), n = e == null ? void 0 : e.getActiveSheet(), r = e == null ? void 0 : e.getUnitId(), s = n == null ? void 0 : n.getSheetId();
1488
+ if (!r || !s)
1489
+ return;
1490
+ const o = this._drawingManagerService.getDrawingData(r, s), a = Object.values(o);
1491
+ this._drawingManagerService.addNotification(a);
1492
+ }
1493
+ })
1494
+ );
1495
+ }
1496
+ _initEditPermissionChange() {
1497
+ const i = this._univerInstanceService.getCurrentTypeOfUnit$(x.UNIVER_SHEET), t = this._userManagerService.currentUser$;
1498
+ this.disposeWithMe(
1499
+ Ct([i, t]).pipe(
1500
+ Se(([e, n]) => e ? e.activeSheet$.pipe(
1501
+ Se((r) => {
1502
+ if (!r)
1503
+ return pe;
1504
+ const s = e.getUnitId(), o = r.getSheetId(), a = this._renderManagerService.getRenderById(s), c = a == null ? void 0 : a.scene;
1505
+ if (!c)
1506
+ return pe;
1507
+ const u = c.getTransformerByCreate();
1508
+ return this._permissionService.composePermission$([
1509
+ new rn(s).id,
1510
+ new sn(s, o).id
1511
+ ]).pipe(
1512
+ Te((d) => d.every((g) => g.value)),
1513
+ Ln()
1514
+ ).pipe(
1515
+ Te((d) => ({
1516
+ permission: d,
1517
+ scene: c,
1518
+ transformer: u,
1519
+ unitId: s,
1520
+ subUnitId: o
1521
+ }))
1522
+ );
1523
+ })
1524
+ ) : pe)
1525
+ ).subscribe({
1526
+ next: ({ permission: e, scene: n, transformer: r, unitId: s, subUnitId: o }) => {
1527
+ this._drawingManagerService.setDrawingEditable(e);
1528
+ const a = n.getAllObjectsByOrder(), c = this._drawingManagerService.getDrawingData(s, o), u = Object.values(c);
1529
+ e ? (a.forEach((l) => {
1530
+ l.classType === We.IMAGE && u.some((d) => l.oKey.includes(d.drawingId)) && n.attachTransformerTo(l);
1531
+ }), this._drawingManagerService.addNotification(u)) : (a.forEach((l) => {
1532
+ l.classType === We.IMAGE && u.some((d) => l.oKey.includes(d.drawingId)) && n.detachTransformerFrom(l);
1533
+ }), r.clearSelectedObjects());
1534
+ },
1535
+ complete: () => {
1536
+ const e = this._univerInstanceService.getCurrentUnitForType(x.UNIVER_SHEET);
1537
+ if (!e)
1538
+ return;
1539
+ const n = e.getUnitId(), r = e.getActiveSheet();
1540
+ if (!r)
1541
+ return;
1542
+ const s = r.getSheetId(), o = this._renderManagerService.getRenderById(n), a = o == null ? void 0 : o.scene;
1543
+ if (!a)
1544
+ return;
1545
+ const c = this._drawingManagerService.getDrawingData(n, s), u = Object.values(c);
1546
+ this._drawingManagerService.setDrawingEditable(!0), a.getAllObjectsByOrder().forEach((d) => {
1547
+ d.classType === We.IMAGE && u.some((g) => d.oKey.includes(g.drawingId)) && a.detachTransformerFrom(d);
1548
+ });
1549
+ }
1550
+ })
1551
+ );
1552
+ }
1553
+ };
1554
+ Wt = Ls([
1555
+ et(0, oe),
1556
+ et(1, te),
1557
+ et(2, Xr),
1558
+ et(3, Ce),
1559
+ et(4, N(Hr))
1560
+ ], Wt);
1561
+ var Fs = Object.getOwnPropertyDescriptor, Ys = (i, t, e, n) => {
1562
+ for (var r = n > 1 ? void 0 : n ? Fs(t, e) : t, s = i.length - 1, o; s >= 0; s--)
1563
+ (o = i[s]) && (r = o(r) || r);
1564
+ return r;
1565
+ }, yt = (i, t) => (e, n) => t(e, n, i);
1566
+ let jt = class extends se {
1567
+ constructor(i, t, e, n) {
1568
+ super(), this._sheetPrintInterceptorService = i, this._drawingRenderService = t, this._drawingManagerService = e, this._renderManagerService = n, this._initPrinting();
1569
+ }
1570
+ _initPrinting() {
1571
+ this.disposeWithMe(
1572
+ this._sheetPrintInterceptorService.interceptor.intercept(
1573
+ this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,
1574
+ {
1575
+ handler: (i, t, e) => {
1576
+ const { unitId: n, scene: r, subUnitId: s } = t, o = this._drawingManagerService.getDrawingDataForUnit(n), a = o == null ? void 0 : o[s];
1577
+ return a && a.order.forEach((c) => {
1578
+ this._drawingRenderService.renderDrawing(a.data[c], r);
1579
+ }), e();
1580
+ }
1581
+ }
1582
+ )
1583
+ ), this.disposeWithMe(
1584
+ this._sheetPrintInterceptorService.interceptor.intercept(
1585
+ this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,
1586
+ {
1587
+ handler: (i, t, e) => {
1588
+ const { unitId: n, subUnitId: r } = t, s = this._renderManagerService.getRenderById(n);
1589
+ if (!s)
1590
+ return e(i);
1591
+ const o = s.with(V).getSkeletonParam(r);
1592
+ if (!o)
1593
+ return e(i);
1594
+ const a = this._drawingManagerService.getDrawingDataForUnit(n), c = a == null ? void 0 : a[t.subUnitId];
1595
+ if (!c)
1596
+ return e(i);
1597
+ const { scaleX: u, scaleY: l } = s.scene, d = i ? { ...i } : { startColumn: 0, endColumn: 0, endRow: 0, startRow: 0 }, g = c.order.map((h) => c.data[h]).filter((h) => h.drawingType !== L.DRAWING_DOM);
1598
+ return g.length ? (g.forEach((h) => {
1599
+ if (!h.groupId && h.transform && ye.isDefine(h.transform.left) && ye.isDefine(h.transform.top) && ye.isDefine(h.transform.width) && ye.isDefine(h.transform.height)) {
1600
+ const m = o.skeleton.getCellIndexByOffset(h.transform.left, h.transform.top, u, l, { x: 0, y: 0 }), p = o.skeleton.getCellIndexByOffset(h.transform.left + h.transform.width, h.transform.top + h.transform.height, u, l, { x: 0, y: 0 });
1601
+ m.column < d.startColumn && (d.startColumn = m.column), m.row < d.startRow && (d.startRow = m.row), d.endRow < p.row && (d.endRow = p.row), d.endColumn < p.column && (d.endColumn = p.column);
1602
+ }
1603
+ }), e(d)) : e(i);
1604
+ }
1605
+ }
1606
+ )
1607
+ );
1608
+ }
1609
+ };
1610
+ jt = Ys([
1611
+ yt(0, N(Ei)),
1612
+ yt(1, N(Qn)),
1613
+ yt(2, oe),
1614
+ yt(3, te)
1615
+ ], jt);
1616
+ var Gs = Object.getOwnPropertyDescriptor, Vs = (i, t, e, n) => {
1617
+ for (var r = n > 1 ? void 0 : n ? Gs(t, e) : t, s = i.length - 1, o; s >= 0; s--)
1618
+ (o = i[s]) && (r = o(r) || r);
1619
+ return r;
1620
+ }, _e = (i, t) => (e, n) => t(e, n, i);
1621
+ const Xs = [
1622
+ nr.id,
1623
+ rr.id,
1624
+ ir.id,
1625
+ sr.id,
1626
+ or.id,
1627
+ ar.id,
1628
+ cr.id,
1629
+ dr.id,
1630
+ on.id,
1631
+ an.id,
1632
+ lr.id,
1633
+ ur.id,
1634
+ hr.id,
1635
+ gr.id,
1636
+ mr.id,
1637
+ fr.id,
1638
+ pr.id,
1639
+ wr.id,
1640
+ _r.id
1641
+ ], Hs = [
1642
+ Ki.id,
1643
+ Zi.id,
1644
+ Ji.id,
1645
+ qi.id,
1646
+ Qi.id,
1647
+ es.id
1648
+ ];
1649
+ let hn = class extends se {
1650
+ constructor(i, t, e, n, r, s, o, a, c) {
1651
+ super(), this._context = i, this._renderManagerService = t, this._commandService = e, this._selectionRenderService = n, this._skeletonManagerService = r, this._sheetInterceptorService = s, this._sheetDrawingService = o, this._drawingManagerService = a, this._univerInstanceService = c, this._sheetInterceptorListener(), this._commandListener(), this._sheetRefreshListener();
1652
+ }
1653
+ _sheetInterceptorListener() {
1654
+ this.disposeWithMe(
1655
+ this._sheetInterceptorService.interceptCommand({
1656
+ getMutations: (i) => {
1657
+ if (!Xs.includes(i.id))
1658
+ return { redos: [], undos: [] };
1659
+ if (i.params == null)
1660
+ return { redos: [], undos: [] };
1661
+ const t = i.id;
1662
+ if (t === nr.id)
1663
+ return this._moveRowInterceptor(i.params, "insert");
1664
+ if ([pr.id, wr.id, _r.id].includes(t))
1665
+ return this._moveRangeInterceptor(i.params);
1666
+ if (t === rr.id)
1667
+ return this._moveColInterceptor(i.params, "insert");
1668
+ if (t === ir.id)
1669
+ return this._moveRowInterceptor(i.params, "remove");
1670
+ if (t === sr.id)
1671
+ return this._moveColInterceptor(i.params, "remove");
1672
+ if (t === or.id) {
1673
+ const { range: e } = i.params;
1674
+ return this._getRangeMoveUndo(
1675
+ e,
1676
+ 0
1677
+ /* deleteLeft */
1678
+ );
1679
+ } else if (t === ar.id) {
1680
+ const { range: e } = i.params;
1681
+ return this._getRangeMoveUndo(
1682
+ e,
1683
+ 1
1684
+ /* deleteUp */
1685
+ );
1686
+ } else if (t === cr.id) {
1687
+ const { range: e } = i.params;
1688
+ return this._getRangeMoveUndo(
1689
+ e,
1690
+ 2
1691
+ /* insertDown */
1692
+ );
1693
+ } else if (t === dr.id) {
1694
+ const { range: e } = i.params;
1695
+ return this._getRangeMoveUndo(
1696
+ e,
1697
+ 3
1698
+ /* insertRight */
1699
+ );
1700
+ } else if (t === hr.id || t === gr.id) {
1701
+ const e = i.params, { unitId: n, subUnitId: r, ranges: s } = e;
1702
+ return this._getDrawingUndoForRowVisible(n, r, s);
1703
+ } else if (t === mr.id || t === fr.id) {
1704
+ const e = i.params, { unitId: n, subUnitId: r, ranges: s } = e;
1705
+ return this._getDrawingUndoForColVisible(n, r, s);
1706
+ } else if (t === on.id || t === an.id || t === lr.id || t === ur.id) {
1707
+ const e = i.params, { unitId: n, subUnitId: r, ranges: s } = e, o = t === on.id || t === an.id;
1708
+ return this._getDrawingUndoForRowAndColSize(n, r, s, o);
1709
+ }
1710
+ return { redos: [], undos: [] };
1711
+ }
1712
+ })
1713
+ );
1714
+ }
1715
+ _getRangeMoveUndo(i, t) {
1716
+ const e = le(this._univerInstanceService);
1717
+ if (e == null)
1718
+ return { redos: [], undos: [] };
1719
+ const n = e.unitId, r = e.subUnitId, s = [], o = [], a = this._sheetDrawingService.getDrawingData(n, r), c = [], u = [];
1720
+ if (Object.keys(a).forEach((l) => {
1721
+ const d = a[l], { updateDrawings: g, deleteDrawings: h } = this._getUpdateOrDeleteDrawings(i, t, d);
1722
+ c.push(...g), u.push(...h);
1723
+ }), c.length === 0 && u.length === 0)
1724
+ return { redos: [], undos: [] };
1725
+ if (c.length > 0) {
1726
+ const l = this._sheetDrawingService.getBatchUpdateOp(c), { undo: d, redo: g, objects: h } = l;
1727
+ s.push({ id: A.id, params: { unitId: n, subUnitId: r, op: g, objects: h, type: P.UPDATE } }), o.push({ id: A.id, params: { unitId: n, subUnitId: r, op: d, objects: h, type: P.UPDATE } });
1728
+ }
1729
+ if (u.length > 0) {
1730
+ const l = this._sheetDrawingService.getBatchRemoveOp(u), d = l.undo, g = l.redo, h = l.objects;
1731
+ s.push({ id: A.id, params: { unitId: n, subUnitId: r, op: g, objects: h, type: P.REMOVE } }), o.push({ id: A.id, params: { unitId: n, subUnitId: r, op: d, objects: h, type: P.INSERT } });
1732
+ }
1733
+ return s.push({ id: F.id, params: [n] }), o.push({ id: F.id, params: [n] }), {
1734
+ redos: s,
1735
+ undos: o
1736
+ };
1737
+ }
1738
+ _getUpdateOrDeleteDrawings(i, t, e) {
1739
+ const n = [], r = [], { sheetTransform: s, anchorType: o = U.Position, transform: a, unitId: c, subUnitId: u, drawingId: l } = e, { from: d, to: g } = s, { row: h, column: m } = d, { row: p, column: f } = g;
1740
+ if (s == null || a == null)
1741
+ return {
1742
+ updateDrawings: n,
1743
+ deleteDrawings: r
1744
+ };
1745
+ const { startRow: w, endRow: S, startColumn: C, endColumn: D } = i;
1746
+ let v = null, b = null;
1747
+ if (t === 0 && h >= w && p <= S)
1748
+ if (m >= C && f <= D)
1749
+ r.push({ unitId: c, subUnitId: u, drawingId: l });
1750
+ else {
1751
+ const _ = this._shrinkCol(s, a, C, D, o);
1752
+ v = _ == null ? void 0 : _.newSheetTransform, b = _ == null ? void 0 : _.newTransform;
1753
+ }
1754
+ else if (t === 1 && m >= C && f <= D)
1755
+ if (h >= w && p <= S)
1756
+ r.push({ unitId: c, subUnitId: u, drawingId: l });
1757
+ else {
1758
+ const _ = this._shrinkRow(s, a, w, S, o);
1759
+ v = _ == null ? void 0 : _.newSheetTransform, b = _ == null ? void 0 : _.newTransform;
1760
+ }
1761
+ else if (t === 2) {
1762
+ const _ = this._expandRow(s, a, w, S, o);
1763
+ v = _ == null ? void 0 : _.newSheetTransform, b = _ == null ? void 0 : _.newTransform;
1764
+ } else if (t === 3) {
1765
+ const _ = this._expandCol(s, a, C, D, o);
1766
+ v = _ == null ? void 0 : _.newSheetTransform, b = _ == null ? void 0 : _.newTransform;
1767
+ }
1768
+ if (v != null && b != null) {
1769
+ const _ = H(v, this._selectionRenderService, this._skeletonManagerService);
1770
+ n.push({ ...e, sheetTransform: v, transform: _ });
1771
+ }
1772
+ return { updateDrawings: n, deleteDrawings: r };
1773
+ }
1774
+ _remainDrawingSize(i, t, e) {
1775
+ const n = $({ ...i }, this._selectionRenderService);
1776
+ n != null && t.push({
1777
+ ...e,
1778
+ sheetTransform: n
1779
+ });
1780
+ }
1781
+ // eslint-disable-next-line max-lines-per-function
1782
+ _getDrawingUndoForColVisible(i, t, e) {
1783
+ const n = this._drawingManagerService.getDrawingData(i, t), r = [], s = [];
1784
+ if (Object.keys(n).forEach((l) => {
1785
+ const d = n[l], { sheetTransform: g, transform: h, anchorType: m = U.Position } = d;
1786
+ if (m === U.None)
1787
+ this._remainDrawingSize(h, r, d);
1788
+ else {
1789
+ const { from: p, to: f } = g, { row: w, column: S } = p, { row: C, column: D } = f;
1790
+ for (let v = 0; v < e.length; v++) {
1791
+ const b = e[v], { startRow: _, endRow: T, startColumn: M, endColumn: y } = b;
1792
+ if (D < M)
1793
+ continue;
1794
+ if (m === U.Position) {
1795
+ let R = null, O = null;
1796
+ if (S >= M && S <= y) {
1797
+ const B = this._skeletonManagerService.attachRangeWithCoord({ startColumn: S, endColumn: y, startRow: p.row, endRow: f.row });
1798
+ if (B == null)
1799
+ return;
1800
+ O = { ...h, left: B.startX };
1801
+ }
1802
+ if (O != null && (R = $(O, this._selectionRenderService), R != null && O != null)) {
1803
+ r.push({ ...d, sheetTransform: R, transform: O });
1804
+ break;
1805
+ }
1806
+ this._remainDrawingSize(h, r, d);
1807
+ continue;
1808
+ }
1809
+ if (S >= M && D <= y)
1810
+ continue;
1811
+ let E = null, I = null;
1812
+ if (S >= M && S <= y) {
1813
+ const R = this._skeletonManagerService.attachRangeWithCoord({ startColumn: S, endColumn: y, startRow: p.row, endRow: f.row });
1814
+ if (R == null)
1815
+ return;
1816
+ I = {
1817
+ ...h,
1818
+ left: (R == null ? void 0 : R.startX) || 0,
1819
+ width: ((h == null ? void 0 : h.width) || 0) - R.endX + R.startX
1820
+ };
1821
+ } else if (D >= M && D <= y) {
1822
+ const R = this._skeletonManagerService.attachRangeWithCoord({ startColumn: M, endColumn: D, startRow: p.row, endRow: f.row });
1823
+ if (R == null)
1824
+ return;
1825
+ I = {
1826
+ ...h,
1827
+ left: R.startX - ((h == null ? void 0 : h.width) || 0)
1828
+ };
1829
+ } else {
1830
+ const R = this._skeletonManagerService.attachRangeWithCoord({ startColumn: M, endColumn: y, startRow: p.row, endRow: f.row });
1831
+ if (R == null)
1832
+ return;
1833
+ if (I = {
1834
+ ...h,
1835
+ width: ((h == null ? void 0 : h.width) || 0) - R.endX + R.startX
1836
+ }, E = $(I, this._selectionRenderService), E != null && I != null) {
1837
+ s.push({ ...d, sheetTransform: E, transform: I });
1838
+ break;
1839
+ }
1840
+ }
1841
+ if (I != null && (E = $(I, this._selectionRenderService)), I != null && E != null) {
1842
+ r.push({ ...d, sheetTransform: E, transform: I });
1843
+ break;
1844
+ } else
1845
+ this._remainDrawingSize(h, r, d);
1846
+ }
1847
+ }
1848
+ }), r.length === 0 && s.length === 0)
1849
+ return { redos: [], undos: [] };
1850
+ const { redos: o, undos: a } = this._createUndoAndRedoMutation(i, t, r), c = [], u = [];
1851
+ if (s.length > 0) {
1852
+ const { redos: l, undos: d } = this._createUndoAndRedoMutation(i, t, s);
1853
+ c.push(...l), u.push(...d);
1854
+ }
1855
+ return {
1856
+ redos: o,
1857
+ undos: a,
1858
+ preRedos: c,
1859
+ preUndos: u
1860
+ };
1861
+ }
1862
+ _createUndoAndRedoMutation(i, t, e) {
1863
+ const n = this._sheetDrawingService.getBatchUpdateOp(e), { undo: r, redo: s, objects: o } = n, a = [
1864
+ { id: A.id, params: { unitId: i, subUnitId: t, op: s, objects: o, type: P.UPDATE } },
1865
+ { id: F.id, params: [i] }
1866
+ ], c = [
1867
+ { id: A.id, params: { unitId: i, subUnitId: t, op: r, objects: o, type: P.UPDATE } },
1868
+ { id: F.id, params: [i] }
1869
+ ];
1870
+ return {
1871
+ redos: a,
1872
+ undos: c
1873
+ };
1874
+ }
1875
+ // eslint-disable-next-line max-lines-per-function
1876
+ _getDrawingUndoForRowVisible(i, t, e) {
1877
+ const n = this._drawingManagerService.getDrawingData(i, t), r = [], s = [];
1878
+ if (Object.keys(n).forEach((l) => {
1879
+ const d = n[l], { sheetTransform: g, transform: h, anchorType: m = U.Position } = d;
1880
+ if (m === U.None)
1881
+ this._remainDrawingSize(h, r, d);
1882
+ else {
1883
+ const { from: p, to: f } = g, { row: w, column: S } = p, { row: C, column: D } = f;
1884
+ for (let v = 0; v < e.length; v++) {
1885
+ const b = e[v], { startRow: _, endRow: T, startColumn: M, endColumn: y } = b;
1886
+ if (C < _)
1887
+ continue;
1888
+ if (m === U.Position) {
1889
+ let R = null, O = null;
1890
+ if (w >= _ && w <= T) {
1891
+ const B = this._skeletonManagerService.attachRangeWithCoord({ startColumn: p.column, endColumn: f.column, startRow: w, endRow: T });
1892
+ if (B == null)
1893
+ return;
1894
+ O = { ...h, top: B.startY };
1895
+ }
1896
+ if (O != null && (R = $(O, this._selectionRenderService), R != null && O != null)) {
1897
+ r.push({ ...d, sheetTransform: R, transform: O });
1898
+ break;
1899
+ }
1900
+ this._remainDrawingSize(h, r, d);
1901
+ continue;
1902
+ }
1903
+ if (w >= _ && C <= T)
1904
+ continue;
1905
+ let E = null, I = null;
1906
+ if (w >= _ && w <= T) {
1907
+ const R = this._skeletonManagerService.attachRangeWithCoord({ startColumn: p.column, endColumn: f.column, startRow: w, endRow: T });
1908
+ if (R == null)
1909
+ return;
1910
+ I = {
1911
+ ...h,
1912
+ top: (R == null ? void 0 : R.startY) || 0,
1913
+ height: ((h == null ? void 0 : h.height) || 0) - R.endY + R.startY
1914
+ };
1915
+ } else if (C >= _ && C <= T) {
1916
+ const R = this._skeletonManagerService.attachRangeWithCoord({ startColumn: p.column, endColumn: f.column, startRow: _, endRow: C });
1917
+ if (R == null)
1918
+ return;
1919
+ I = {
1920
+ ...h,
1921
+ top: R.startY - ((h == null ? void 0 : h.height) || 0)
1922
+ };
1923
+ } else {
1924
+ const R = this._skeletonManagerService.attachRangeWithCoord({ startColumn: p.column, endColumn: f.column, startRow: _, endRow: T });
1925
+ if (R == null)
1926
+ return;
1927
+ if (I = {
1928
+ ...h,
1929
+ height: ((h == null ? void 0 : h.height) || 0) - R.endY + R.startY
1930
+ }, E = $(I, this._selectionRenderService), E != null && I != null) {
1931
+ s.push({ ...d, sheetTransform: E, transform: I });
1932
+ break;
1933
+ }
1934
+ }
1935
+ if (I != null && (E = $(I, this._selectionRenderService)), I != null && E != null) {
1936
+ r.push({ ...d, sheetTransform: E, transform: I });
1937
+ break;
1938
+ } else
1939
+ this._remainDrawingSize(h, r, d);
1940
+ }
1941
+ }
1942
+ }), r.length === 0 && s.length === 0)
1943
+ return { redos: [], undos: [] };
1944
+ const { redos: o, undos: a } = this._createUndoAndRedoMutation(i, t, r), c = [], u = [];
1945
+ if (s.length > 0) {
1946
+ const { redos: l, undos: d } = this._createUndoAndRedoMutation(i, t, s);
1947
+ c.push(...l), u.push(...d);
1948
+ }
1949
+ return {
1950
+ redos: o,
1951
+ undos: a,
1952
+ preRedos: c,
1953
+ preUndos: u
1954
+ };
1955
+ }
1956
+ _getDrawingUndoForRowAndColSize(i, t, e, n) {
1957
+ const r = this._drawingManagerService.getDrawingData(i, t), s = [];
1958
+ return Object.keys(r).forEach((o) => {
1959
+ const a = r[o], { sheetTransform: c, transform: u, anchorType: l = U.Position } = a;
1960
+ if (l === U.None)
1961
+ this._remainDrawingSize(u, s, a);
1962
+ else {
1963
+ const { from: d, to: g } = c, { row: h, column: m } = d, { row: p, column: f } = g;
1964
+ for (let w = 0; w < e.length; w++) {
1965
+ const S = e[w], { startRow: C, endRow: D, startColumn: v, endColumn: b } = S;
1966
+ if (p < C || f < v)
1967
+ continue;
1968
+ if (l === U.Position && (h <= C && p >= D || m <= v && f >= b)) {
1969
+ this._remainDrawingSize(u, s, a);
1970
+ continue;
1971
+ }
1972
+ const _ = H({ ...c }, this._selectionRenderService, this._skeletonManagerService);
1973
+ if (_ != null) {
1974
+ s.push({
1975
+ ...a,
1976
+ transform: _
1977
+ });
1978
+ break;
1979
+ }
1980
+ }
1981
+ }
1982
+ }), s.length === 0 ? { redos: [], undos: [] } : this._createUndoAndRedoMutation(i, t, s);
1983
+ }
1984
+ _getUnitIdAndSubUnitId(i, t) {
1985
+ let e, n;
1986
+ if (t === "insert")
1987
+ e = i.unitId, n = i.subUnitId;
1988
+ else {
1989
+ const r = le(this._univerInstanceService);
1990
+ if (r == null)
1991
+ return;
1992
+ e = r.unitId, n = r.subUnitId;
1993
+ }
1994
+ return { unitId: e, subUnitId: n };
1995
+ }
1996
+ _moveRangeInterceptor(i) {
1997
+ var C, D;
1998
+ const { toRange: t, fromRange: e } = i, n = le(this._univerInstanceService);
1999
+ if (!n)
2000
+ return { redos: [], undos: [] };
2001
+ const { unitId: r, subUnitId: s } = n, o = (D = (C = this._renderManagerService.getRenderById(r)) == null ? void 0 : C.with(V)) == null ? void 0 : D.getCurrentSkeleton();
2002
+ if (!o)
2003
+ return { redos: [], undos: [] };
2004
+ const a = tr(o, e);
2005
+ if (!a)
2006
+ return { redos: [], undos: [] };
2007
+ const { startX: c, endX: u, startY: l, endY: d } = a, g = this._sheetDrawingService.getDrawingData(r, s), h = [];
2008
+ Object.keys(g).forEach((v) => {
2009
+ const b = g[v];
2010
+ if (b.anchorType !== U.Both)
2011
+ return;
2012
+ const { transform: _ } = b;
2013
+ if (!_)
2014
+ return;
2015
+ const { left: T = 0, top: M = 0, width: y = 0, height: E = 0 } = _, { drawingStartX: I, drawingEndX: R, drawingStartY: O, drawingEndY: B } = {
2016
+ drawingStartX: T,
2017
+ drawingEndX: T + y,
2018
+ drawingStartY: M,
2019
+ drawingEndY: M + E
2020
+ };
2021
+ c <= I && R <= u && l <= O && B <= d && h.push(b);
2022
+ });
2023
+ const m = [], p = [], f = t.startRow - e.startRow, w = t.startColumn - e.startColumn, S = h.map((v) => {
2024
+ const b = v.sheetTransform, _ = {
2025
+ to: { ...b.to, row: b.to.row + f, column: b.to.column + w },
2026
+ from: { ...b.from, row: b.from.row + f, column: b.from.column + w }
2027
+ }, T = H(_, this._selectionRenderService, this._skeletonManagerService);
2028
+ return {
2029
+ unitId: r,
2030
+ subUnitId: s,
2031
+ drawingId: v.drawingId,
2032
+ transform: T,
2033
+ sheetTransform: _
2034
+ };
2035
+ });
2036
+ if (S.length) {
2037
+ const v = this._sheetDrawingService.getBatchUpdateOp(S), { undo: b, redo: _, objects: T } = v;
2038
+ m.push({ id: A.id, params: { unitId: r, subUnitId: s, op: _, objects: T, type: P.UPDATE } }), p.push({ id: A.id, params: { unitId: r, subUnitId: s, op: b, objects: T, type: P.UPDATE } });
2039
+ }
2040
+ return { redos: m, undos: p };
2041
+ }
2042
+ _moveRowInterceptor(i, t) {
2043
+ const e = this._getUnitIdAndSubUnitId(i, t);
2044
+ if (e == null)
2045
+ return { redos: [], undos: [] };
2046
+ const { unitId: n, subUnitId: r } = e, { range: s } = i, o = s.startRow, a = s.endRow, c = [], u = [], l = this._sheetDrawingService.getDrawingData(n, r), d = [], g = [];
2047
+ if (Object.keys(l).forEach((h) => {
2048
+ const m = l[h], { sheetTransform: p, transform: f, anchorType: w = U.Position } = m;
2049
+ if (p == null || f == null)
2050
+ return;
2051
+ let S, C;
2052
+ if (t === "insert") {
2053
+ const v = this._expandRow(p, f, o, a, w);
2054
+ S = v == null ? void 0 : v.newSheetTransform, C = v == null ? void 0 : v.newTransform;
2055
+ } else {
2056
+ const { from: v, to: b } = p, { row: _ } = v, { row: T } = b;
2057
+ if (w === U.Both && _ >= o && T <= a)
2058
+ g.push({ unitId: n, subUnitId: r, drawingId: h });
2059
+ else {
2060
+ const M = this._shrinkRow(p, f, o, a, w);
2061
+ S = M == null ? void 0 : M.newSheetTransform, C = M == null ? void 0 : M.newTransform;
2062
+ }
2063
+ }
2064
+ if (!S || !C)
2065
+ return;
2066
+ const D = { unitId: n, subUnitId: r, drawingId: h, transform: C, sheetTransform: S };
2067
+ d.push(D);
2068
+ }), d.length === 0 && g.length === 0)
2069
+ return { redos: [], undos: [] };
2070
+ if (d.length > 0) {
2071
+ const h = this._sheetDrawingService.getBatchUpdateOp(d), { undo: m, redo: p, objects: f } = h;
2072
+ c.push({ id: A.id, params: { unitId: n, subUnitId: r, op: p, objects: f, type: P.UPDATE } }), u.push({ id: A.id, params: { unitId: n, subUnitId: r, op: m, objects: f, type: P.UPDATE } });
2073
+ }
2074
+ if (g.length > 0) {
2075
+ const h = this._sheetDrawingService.getBatchRemoveOp(g), m = h.undo, p = h.redo, f = h.objects;
2076
+ c.push({ id: A.id, params: { unitId: n, subUnitId: r, op: p, objects: f, type: P.REMOVE } }), u.push({ id: A.id, params: { unitId: n, subUnitId: r, op: m, objects: f, type: P.INSERT } });
2077
+ }
2078
+ return c.push({ id: F.id, params: [n] }), u.push({ id: F.id, params: [n] }), {
2079
+ redos: c,
2080
+ undos: u
2081
+ };
2082
+ }
2083
+ _moveColInterceptor(i, t) {
2084
+ const e = this._getUnitIdAndSubUnitId(i, t);
2085
+ if (e == null)
2086
+ return { redos: [], undos: [] };
2087
+ const { unitId: n, subUnitId: r } = e, { range: s } = i, o = s.startColumn, a = s.endColumn, c = [], u = [], l = this._sheetDrawingService.getDrawingData(n, r), d = [], g = [];
2088
+ if (Object.keys(l).forEach((h) => {
2089
+ const m = l[h], { sheetTransform: p, transform: f, anchorType: w = U.Position } = m;
2090
+ if (p == null || f == null)
2091
+ return;
2092
+ let S, C;
2093
+ if (t === "insert") {
2094
+ const v = this._expandCol(p, f, o, a, w);
2095
+ S = v == null ? void 0 : v.newSheetTransform, C = v == null ? void 0 : v.newTransform;
2096
+ } else {
2097
+ const { from: v, to: b } = p, { column: _ } = v, { column: T } = b;
2098
+ if (w === U.Both && _ >= o && T <= a)
2099
+ g.push({ unitId: n, subUnitId: r, drawingId: h });
2100
+ else {
2101
+ const M = this._shrinkCol(p, f, o, a, w);
2102
+ S = M == null ? void 0 : M.newSheetTransform, C = M == null ? void 0 : M.newTransform;
2103
+ }
2104
+ }
2105
+ if (!S || !C)
2106
+ return;
2107
+ const D = { unitId: n, subUnitId: r, drawingId: h, transform: C, sheetTransform: S };
2108
+ d.push(D);
2109
+ }), d.length === 0 && g.length === 0)
2110
+ return { redos: [], undos: [] };
2111
+ if (d.length > 0) {
2112
+ const h = this._sheetDrawingService.getBatchUpdateOp(d), { undo: m, redo: p, objects: f } = h;
2113
+ c.push({ id: A.id, params: { unitId: n, subUnitId: r, op: p, objects: f, type: P.UPDATE } }), u.push({ id: A.id, params: { unitId: n, subUnitId: r, op: m, objects: f, type: P.UPDATE } });
2114
+ }
2115
+ if (g.length > 0) {
2116
+ const h = this._sheetDrawingService.getBatchRemoveOp(g), m = h.undo, p = h.redo, f = h.objects;
2117
+ c.push({ id: A.id, params: { unitId: n, subUnitId: r, op: p, objects: f, type: P.REMOVE } }), u.push({ id: A.id, params: { unitId: n, subUnitId: r, op: m, objects: f, type: P.INSERT } });
2118
+ }
2119
+ return c.push({ id: F.id, params: [n] }), u.push({ id: F.id, params: [n] }), { redos: c, undos: u };
2120
+ }
2121
+ _expandCol(i, t, e, n, r = U.Position) {
2122
+ const s = n - e + 1, { from: o, to: a } = i, { column: c } = o, { column: u } = a;
2123
+ if (r === U.None)
2124
+ return {
2125
+ newSheetTransform: $({ ...t }, this._selectionRenderService),
2126
+ newTransform: t
2127
+ };
2128
+ let l = null, d = null;
2129
+ if (c >= e) {
2130
+ const g = this._skeletonManagerService.attachRangeWithCoord({ startColumn: e, endColumn: n, startRow: o.row, endRow: a.row });
2131
+ if (g == null)
2132
+ return;
2133
+ d = { ...t, left: (t.left || 0) + g.endX - g.startX }, l = $(d, this._selectionRenderService);
2134
+ } else if (u >= n)
2135
+ if (r === U.Both)
2136
+ l = {
2137
+ from: { ...o },
2138
+ to: { ...a, column: u + s }
2139
+ }, d = H(l, this._selectionRenderService, this._skeletonManagerService);
2140
+ else
2141
+ return {
2142
+ newSheetTransform: $({ ...t }, this._selectionRenderService),
2143
+ newTransform: t
2144
+ };
2145
+ return l != null && d != null ? {
2146
+ newSheetTransform: l,
2147
+ newTransform: d
2148
+ } : null;
2149
+ }
2150
+ _shrinkCol(i, t, e, n, r = U.Position) {
2151
+ const s = n - e + 1, { from: o, to: a } = i, { column: c } = o, { column: u } = a;
2152
+ if (r === U.None)
2153
+ return {
2154
+ newSheetTransform: $({ ...t }, this._selectionRenderService),
2155
+ newTransform: t
2156
+ };
2157
+ let l = null, d = null;
2158
+ if (c > n)
2159
+ l = {
2160
+ from: { ...o, column: c - s },
2161
+ to: { ...a, column: u - s }
2162
+ }, d = H(l, this._selectionRenderService, this._skeletonManagerService);
2163
+ else {
2164
+ if (c >= e && u <= n)
2165
+ return null;
2166
+ if (c < e && u > n)
2167
+ if (r === U.Both)
2168
+ l = {
2169
+ from: { ...o },
2170
+ to: { ...a, column: u - s }
2171
+ }, d = H(l, this._selectionRenderService, this._skeletonManagerService);
2172
+ else
2173
+ return {
2174
+ newSheetTransform: $({ ...t }, this._selectionRenderService),
2175
+ newTransform: t
2176
+ };
2177
+ else if (c >= e && c <= n) {
2178
+ if (c === e)
2179
+ d = { ...t, left: (t.left || 0) - i.from.columnOffset };
2180
+ else {
2181
+ const g = this._skeletonManagerService.attachRangeWithCoord({ startColumn: e, endColumn: c - 1, startRow: o.row, endRow: a.row });
2182
+ if (g == null)
2183
+ return;
2184
+ d = { ...t, left: (t.left || 0) - g.endX + g.startX - i.from.columnOffset };
2185
+ }
2186
+ l = $(d, this._selectionRenderService);
2187
+ } else if (u >= e && u <= n && r === U.Both) {
2188
+ const g = this._skeletonManagerService.attachRangeWithCoord({
2189
+ startColumn: e - 1,
2190
+ endColumn: e - 1,
2191
+ startRow: o.row,
2192
+ endRow: a.row
2193
+ });
2194
+ if (g == null)
2195
+ return;
2196
+ l = {
2197
+ from: { ...o },
2198
+ to: { ...a, column: e - 1, columnOffset: g.endX - g.startX }
2199
+ }, d = H(l, this._selectionRenderService, this._skeletonManagerService);
2200
+ }
2201
+ }
2202
+ return l != null && d != null ? {
2203
+ newSheetTransform: l,
2204
+ newTransform: d
2205
+ } : null;
2206
+ }
2207
+ _expandRow(i, t, e, n, r = U.Position) {
2208
+ const s = n - e + 1, { from: o, to: a } = i, { row: c } = o, { row: u } = a;
2209
+ if (r === U.None)
2210
+ return {
2211
+ newSheetTransform: $({ ...t }, this._selectionRenderService),
2212
+ newTransform: t
2213
+ };
2214
+ let l = null, d = null;
2215
+ if (c >= e) {
2216
+ const g = this._skeletonManagerService.attachRangeWithCoord({ startRow: e, endRow: n, startColumn: o.column, endColumn: a.column });
2217
+ if (g == null)
2218
+ return;
2219
+ d = { ...t, top: (t.top || 0) + g.endY - g.startY }, l = $(d, this._selectionRenderService);
2220
+ } else if (u >= n)
2221
+ if (r === U.Both)
2222
+ l = {
2223
+ from: { ...o },
2224
+ to: {
2225
+ ...a,
2226
+ row: u + s
2227
+ }
2228
+ }, d = H(l, this._selectionRenderService, this._skeletonManagerService);
2229
+ else
2230
+ return {
2231
+ newSheetTransform: $({ ...t }, this._selectionRenderService),
2232
+ newTransform: t
2233
+ };
2234
+ return l != null && d != null ? {
2235
+ newSheetTransform: l,
2236
+ newTransform: d
2237
+ } : null;
2238
+ }
2239
+ _shrinkRow(i, t, e, n, r = U.Position) {
2240
+ const s = n - e + 1, { from: o, to: a } = i, { row: c } = o, { row: u } = a;
2241
+ if (r === U.None)
2242
+ return {
2243
+ newSheetTransform: $({ ...t }, this._selectionRenderService),
2244
+ newTransform: t
2245
+ };
2246
+ let l = null, d = null;
2247
+ if (c > n)
2248
+ l = {
2249
+ from: { ...o, row: c - s },
2250
+ to: { ...a, row: u - s }
2251
+ }, d = H(l, this._selectionRenderService, this._skeletonManagerService);
2252
+ else {
2253
+ if (c >= e && u <= n)
2254
+ return null;
2255
+ if (c < e && u > n)
2256
+ if (r === U.Both)
2257
+ l = {
2258
+ from: { ...o },
2259
+ to: { ...a, row: u - s }
2260
+ }, d = H(l, this._selectionRenderService, this._skeletonManagerService);
2261
+ else
2262
+ return {
2263
+ newSheetTransform: $({ ...t }, this._selectionRenderService),
2264
+ newTransform: t
2265
+ };
2266
+ else if (c >= e && c <= n) {
2267
+ if (c === e)
2268
+ d = { ...t, top: (t.top || 0) - i.from.rowOffset };
2269
+ else {
2270
+ const g = this._skeletonManagerService.attachRangeWithCoord({ startRow: e, endRow: c - 1, startColumn: o.column, endColumn: a.column });
2271
+ if (g == null)
2272
+ return;
2273
+ d = { ...t, top: (t.top || 0) - g.endY + g.startY - i.from.rowOffset };
2274
+ }
2275
+ l = $(d, this._selectionRenderService);
2276
+ } else if (u >= e && u <= n && r === U.Both) {
2277
+ const g = this._skeletonManagerService.attachRangeWithCoord({ startColumn: o.column, endColumn: o.column, startRow: e - 1, endRow: e - 1 });
2278
+ if (g == null)
2279
+ return;
2280
+ l = {
2281
+ from: { ...o },
2282
+ to: { ...a, row: e - 1, rowOffset: g.endY - g.startY }
2283
+ }, d = H(l, this._selectionRenderService, this._skeletonManagerService);
2284
+ }
2285
+ }
2286
+ return l != null && d != null ? {
2287
+ newSheetTransform: l,
2288
+ newTransform: d
2289
+ } : null;
2290
+ }
2291
+ _commandListener() {
2292
+ this.disposeWithMe(
2293
+ // TODO@weird94: this should subscribe to the command service
2294
+ // but the skeleton changes like other render modules. These two signals are not equivalent.
2295
+ // As a temp solution, I subscribed to activate$ here.
2296
+ this._commandService.onCommandExecuted((i) => {
2297
+ if (i.id === ts.id) {
2298
+ const { unitId: t, subUnitId: e } = i.params;
2299
+ this._updateDrawings(t, e);
2300
+ }
2301
+ })
2302
+ ), this.disposeWithMe(
2303
+ this._context.activated$.subscribe((i) => {
2304
+ const { unit: t, unitId: e } = this._context;
2305
+ if (i) {
2306
+ const n = t.getActiveSheet().getSheetId();
2307
+ this._updateDrawings(e, n);
2308
+ } else
2309
+ this._clearDrawings(e);
2310
+ })
2311
+ );
2312
+ }
2313
+ _clearDrawings(i) {
2314
+ setTimeout(() => {
2315
+ const t = this._drawingManagerService.drawingManagerData, e = [];
2316
+ Object.keys(t).forEach((n) => {
2317
+ const r = t[n];
2318
+ r != null && Object.keys(r).forEach((s) => {
2319
+ const o = r[s].data;
2320
+ o != null && Object.keys(o).forEach((a) => {
2321
+ n === i && e.push(o[a]);
2322
+ });
2323
+ });
2324
+ }), this._drawingManagerService.removeNotification(e);
2325
+ });
2326
+ }
2327
+ _updateDrawings(i, t) {
2328
+ setTimeout(() => {
2329
+ const e = this._drawingManagerService.drawingManagerData, n = [], r = [];
2330
+ Object.keys(e).forEach((s) => {
2331
+ const o = e[s];
2332
+ o != null && Object.keys(o).forEach((a) => {
2333
+ const c = o[a].data;
2334
+ c != null && Object.keys(c).forEach((u) => {
2335
+ if (s === i && a === t) {
2336
+ const l = c[u];
2337
+ l.transform = H(l.sheetTransform, this._selectionRenderService, this._skeletonManagerService), n.push(c[u]);
2338
+ } else
2339
+ r.push(c[u]);
2340
+ });
2341
+ });
2342
+ }), this._drawingManagerService.removeNotification(r), this._drawingManagerService.addNotification(n);
2343
+ }, 0);
2344
+ }
2345
+ _sheetRefreshListener() {
2346
+ this.disposeWithMe(
2347
+ this._commandService.onCommandExecuted((i) => {
2348
+ Hs.includes(i.id) && requestIdleCallback(() => {
2349
+ const t = i.params, { unitId: e, subUnitId: n, ranges: r } = t;
2350
+ this._refreshDrawingTransform(e, n, r);
2351
+ });
2352
+ })
2353
+ );
2354
+ }
2355
+ _refreshDrawingTransform(i, t, e) {
2356
+ const n = this._drawingManagerService.getDrawingData(i, t), r = [];
2357
+ Object.keys(n).forEach((s) => {
2358
+ const o = n[s], { sheetTransform: a, transform: c, anchorType: u = U.Position } = o;
2359
+ if (u === U.None)
2360
+ return !0;
2361
+ const { from: l, to: d } = a, { row: g, column: h } = l, { row: m, column: p } = d;
2362
+ for (let f = 0; f < e.length; f++) {
2363
+ const w = e[f], { startRow: S, endRow: C, startColumn: D, endColumn: v } = w;
2364
+ if (zr.intersects(
2365
+ {
2366
+ startRow: S,
2367
+ endRow: C,
2368
+ startColumn: D,
2369
+ endColumn: v
2370
+ },
2371
+ {
2372
+ startRow: g,
2373
+ endRow: m,
2374
+ startColumn: h,
2375
+ endColumn: p
2376
+ }
2377
+ ) || g > C || h > v) {
2378
+ const b = u === U.Position, _ = H(a, this._selectionRenderService, this._skeletonManagerService);
2379
+ r.push({
2380
+ ...o,
2381
+ transform: {
2382
+ ..._,
2383
+ width: b ? c == null ? void 0 : c.width : _ == null ? void 0 : _.width,
2384
+ height: b ? c == null ? void 0 : c.height : _ == null ? void 0 : _.height
2385
+ }
2386
+ });
2387
+ break;
2388
+ }
2389
+ }
2390
+ }), r.length !== 0 && (this._drawingManagerService.refreshTransform(r), this._commandService.syncExecuteCommand(F.id, [i]));
2391
+ }
2392
+ };
2393
+ hn = Vs([
2394
+ _e(1, te),
2395
+ _e(2, Y),
2396
+ _e(3, Xe),
2397
+ _e(4, N(V)),
2398
+ _e(5, N(Yt)),
2399
+ _e(6, ae),
2400
+ _e(7, oe),
2401
+ _e(8, Ce)
2402
+ ], hn);
2403
+ var ie = function() {
2404
+ return ie = Object.assign || function(i) {
2405
+ for (var t, e = 1, n = arguments.length; e < n; e++) {
2406
+ t = arguments[e];
2407
+ for (var r in t) Object.prototype.hasOwnProperty.call(t, r) && (i[r] = t[r]);
2408
+ }
2409
+ return i;
2410
+ }, ie.apply(this, arguments);
2411
+ }, zs = function(i, t) {
2412
+ var e = {};
2413
+ for (var n in i) Object.prototype.hasOwnProperty.call(i, n) && t.indexOf(n) < 0 && (e[n] = i[n]);
2414
+ if (i != null && typeof Object.getOwnPropertySymbols == "function")
2415
+ for (var r = 0, n = Object.getOwnPropertySymbols(i); r < n.length; r++)
2416
+ t.indexOf(n[r]) < 0 && Object.prototype.propertyIsEnumerable.call(i, n[r]) && (e[n[r]] = i[n[r]]);
2417
+ return e;
2418
+ }, Tr = vr(function(i, t) {
2419
+ var e = i.icon, n = i.id, r = i.className, s = i.extend, o = zs(i, ["icon", "id", "className", "extend"]), a = "univerjs-icon univerjs-icon-".concat(n, " ").concat(r || "").trim(), c = as("_".concat(Js()));
2420
+ return Or(e, "".concat(n), { defIds: e.defIds, idSuffix: c.current }, ie({ ref: t, className: a }, o), s);
2421
+ });
2422
+ function Or(i, t, e, n, r) {
2423
+ return Sr(i.tag, ie(ie({ key: t }, Ks(i, e, r)), n), (Zs(i, e).children || []).map(function(s, o) {
2424
+ return Or(s, "".concat(t, "-").concat(i.tag, "-").concat(o), e, void 0, r);
2425
+ }));
2426
+ }
2427
+ function Ks(i, t, e) {
2428
+ var n = ie({}, i.attrs);
2429
+ e != null && e.colorChannel1 && n.fill === "colorChannel1" && (n.fill = e.colorChannel1), i.tag === "mask" && n.id && (n.id = n.id + t.idSuffix), Object.entries(n).forEach(function(s) {
2430
+ var o = s[0], a = s[1];
2431
+ o === "mask" && typeof a == "string" && (n[o] = a.replace(/url\(#(.*)\)/, "url(#$1".concat(t.idSuffix, ")")));
2432
+ });
2433
+ var r = t.defIds;
2434
+ return !r || r.length === 0 || (i.tag === "use" && n["xlink:href"] && (n["xlink:href"] = n["xlink:href"] + t.idSuffix), Object.entries(n).forEach(function(s) {
2435
+ var o = s[0], a = s[1];
2436
+ typeof a == "string" && (n[o] = a.replace(/url\(#(.*)\)/, "url(#$1".concat(t.idSuffix, ")")));
2437
+ })), n;
2438
+ }
2439
+ function Zs(i, t) {
2440
+ var e, n = t.defIds;
2441
+ return !n || n.length === 0 ? i : i.tag === "defs" && (!((e = i.children) === null || e === void 0) && e.length) ? ie(ie({}, i), { children: i.children.map(function(r) {
2442
+ return typeof r.attrs.id == "string" && n && n.indexOf(r.attrs.id) > -1 ? ie(ie({}, r), { attrs: ie(ie({}, r.attrs), { id: r.attrs.id + t.idSuffix }) }) : r;
2443
+ }) }) : i;
2444
+ }
2445
+ function Js() {
2446
+ return Math.random().toString(36).substring(2, 8);
2447
+ }
2448
+ Tr.displayName = "UniverIcon";
2449
+ var qs = { 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" } }] }, Ur = vr(function(i, t) {
2450
+ return Sr(Tr, Object.assign({}, i, {
2451
+ id: "add-image-single",
2452
+ ref: t,
2453
+ icon: qs
2454
+ }));
2455
+ });
2456
+ Ur.displayName = "AddImageSingle";
2457
+ const Pr = {
2458
+ id: "sheet.command.delete-drawing",
2459
+ type: ee.COMMAND,
2460
+ handler: (i) => {
2461
+ const t = i.get(Y), n = i.get(ae).getFocusDrawings();
2462
+ if (n.length === 0)
2463
+ return !1;
2464
+ const r = n[0].unitId, s = n.map((o) => {
2465
+ const { unitId: a, subUnitId: c, drawingId: u, drawingType: l } = o;
2466
+ return {
2467
+ unitId: a,
2468
+ subUnitId: c,
2469
+ drawingId: u,
2470
+ drawingType: l
2471
+ };
2472
+ });
2473
+ return t.executeCommand(ot.id, {
2474
+ unitId: r,
2475
+ drawings: s
2476
+ });
2477
+ }
2478
+ }, at = {
2479
+ id: "sheet.command.move-drawing",
2480
+ type: ee.COMMAND,
2481
+ handler: (i, t) => {
2482
+ const e = i.get(Y), n = i.get(ae), r = i.get(Xe), { direction: s } = t, o = n.getFocusDrawings();
2483
+ if (o.length === 0)
2484
+ return !1;
2485
+ const a = o[0].unitId, c = o.map((l) => {
2486
+ const { transform: d } = l;
2487
+ if (d == null)
2488
+ return null;
2489
+ const g = { ...d }, { left: h = 0, top: m = 0 } = d;
2490
+ return s === Ie.UP ? g.top = m - 1 : s === Ie.DOWN ? g.top = m + 1 : s === Ie.LEFT ? g.left = h - 1 : s === Ie.RIGHT && (g.left = h + 1), {
2491
+ ...l,
2492
+ transform: g,
2493
+ sheetTransform: $(g, r)
2494
+ };
2495
+ }).filter((l) => l != null);
2496
+ return e.syncExecuteCommand(Vt.id, {
2497
+ unitId: a,
2498
+ drawings: c
2499
+ }) ? (e.syncExecuteCommand(F.id, [a]), !0) : !1;
2500
+ }
2501
+ }, Ar = "addition-and-subtraction-single", Nr = "sheet.menu.image";
2502
+ function Qs(i) {
2503
+ return {
2504
+ id: Nr,
2505
+ type: fn.SUBITEMS,
2506
+ icon: Ar,
2507
+ tooltip: "sheetImage.title",
2508
+ hidden$: mn(i, x.UNIVER_SHEET),
2509
+ disabled$: Ti(i, { workbookTypes: [rn], worksheetTypes: [sn], rangeTypes: [ns] })
2510
+ };
2511
+ }
2512
+ function eo(i) {
2513
+ return {
2514
+ id: Xt.id,
2515
+ title: "sheetImage.upload.float",
2516
+ type: fn.BUTTON,
2517
+ hidden$: mn(i, x.UNIVER_SHEET)
2518
+ };
2519
+ }
2520
+ function to(i) {
2521
+ return {
2522
+ id: _n.id,
2523
+ title: "sheetImage.upload.cell",
2524
+ type: fn.BUTTON,
2525
+ hidden$: mn(i, x.UNIVER_SHEET)
2526
+ };
2527
+ }
2528
+ const no = "univer-image-common-panel", ro = "univer-image-common-panel-grid", io = "univer-image-common-panel-border", so = "univer-image-common-panel-title", oo = "univer-image-common-panel-row", ao = "univer-image-common-panel-column", ve = {
2529
+ imageCommonPanel: no,
2530
+ imageCommonPanelGrid: ro,
2531
+ imageCommonPanelBorder: io,
2532
+ imageCommonPanelTitle: so,
2533
+ imageCommonPanelRow: oo,
2534
+ imageCommonPanelColumn: ao
2535
+ }, co = (i) => {
2536
+ var C;
2537
+ const t = Ee(Y), e = Ee(it), n = Ee(oe), r = Ee(te), { drawings: s } = i, o = s[0];
2538
+ if (o == null)
2539
+ return;
2540
+ const { unitId: a } = o, c = r.getRenderById(a), u = c == null ? void 0 : c.scene;
2541
+ if (u == null)
2542
+ return;
2543
+ const l = u.getTransformerByCreate(), [d, g] = cn(!0), h = (C = o.anchorType) != null ? C : U.Position, [m, p] = cn(h);
2544
+ function f(D, v) {
2545
+ const b = [];
2546
+ return D.forEach((_) => {
2547
+ const { oKey: T } = _, M = v.getDrawingOKey(T);
2548
+ if (M == null)
2549
+ return b.push(null), !0;
2550
+ const { unitId: y, subUnitId: E, drawingId: I, drawingType: R, anchorType: O, sheetTransform: B } = M;
2551
+ b.push({
2552
+ unitId: y,
2553
+ subUnitId: E,
2554
+ drawingId: I,
2555
+ anchorType: O,
2556
+ sheetTransform: B,
2557
+ drawingType: R
2558
+ });
2559
+ }), b;
2560
+ }
2561
+ wn(() => {
2562
+ const D = l.clearControl$.subscribe((b) => {
2563
+ b === !0 && g(!1);
2564
+ }), v = l.changeStart$.subscribe((b) => {
2565
+ var M;
2566
+ const { objects: _ } = b, T = f(_, n);
2567
+ if (T.length === 0)
2568
+ g(!1);
2569
+ else if (T.length >= 1) {
2570
+ g(!0);
2571
+ const y = ((M = T[0]) == null ? void 0 : M.anchorType) || U.Position;
2572
+ p(y);
2573
+ }
2574
+ });
2575
+ return () => {
2576
+ v.unsubscribe(), D.unsubscribe();
2577
+ };
2578
+ }, []);
2579
+ function w(D) {
2580
+ p(D);
2581
+ const v = n.getFocusDrawings();
2582
+ if (v.length === 0)
2583
+ return;
2584
+ const b = v.map((_) => ({
2585
+ unitId: _.unitId,
2586
+ subUnitId: _.subUnitId,
2587
+ drawingId: _.drawingId,
2588
+ anchorType: D
2589
+ }));
2590
+ t.executeCommand(Vt.id, {
2591
+ unitId: v[0].unitId,
2592
+ drawings: b
2593
+ });
2594
+ }
2595
+ const S = (D) => D ? "block" : "none";
2596
+ return /* @__PURE__ */ Ut("div", { className: Dt(ve.imageCommonPanelGrid, ve.imageCommonPanelBorder), style: { display: S(d) }, children: [
2597
+ /* @__PURE__ */ Q("div", { className: ve.imageCommonPanelRow, children: /* @__PURE__ */ Q("div", { className: Dt(ve.imageCommonPanelColumn, ve.imageCommonPanelTitle), children: /* @__PURE__ */ Q("div", { children: e.t("drawing-anchor.title") }) }) }),
2598
+ /* @__PURE__ */ Q("div", { className: Dt(ve.imageCommonPanelRow), children: /* @__PURE__ */ Q("div", { className: Dt(ve.imageCommonPanelColumn), children: /* @__PURE__ */ Ut(ls, { value: m, onChange: w, direction: "vertical", children: [
2599
+ /* @__PURE__ */ Q(Qt, { value: U.Both, children: e.t("drawing-anchor.both") }),
2600
+ /* @__PURE__ */ Q(Qt, { value: U.Position, children: e.t("drawing-anchor.position") }),
2601
+ /* @__PURE__ */ Q(Qt, { value: U.None, children: e.t("drawing-anchor.none") })
2602
+ ] }) }) })
2603
+ ] });
2604
+ }, lo = () => {
2605
+ const i = Ee(oe), t = i.getFocusDrawings(), [e, n] = cn(t);
2606
+ return wn(() => {
2607
+ const r = i.focus$.subscribe((s) => {
2608
+ n(s);
2609
+ });
2610
+ return () => {
2611
+ r.unsubscribe();
2612
+ };
2613
+ }, []), !!(e != null && e.length) && /* @__PURE__ */ Ut("div", { className: ve.imageCommonPanel, children: [
2614
+ /* @__PURE__ */ Q(mi, { drawings: e }),
2615
+ /* @__PURE__ */ Q(co, { drawings: e })
2616
+ ] });
2617
+ }, uo = {
2618
+ [$i.FORMULAS_INSERT]: {
2619
+ [Nr]: {
2620
+ order: 3,
2621
+ menuItemFactory: Qs,
2622
+ [Xt.id]: {
2623
+ order: 0,
2624
+ menuItemFactory: eo
2625
+ },
2626
+ [_n.id]: {
2627
+ order: 1,
2628
+ menuItemFactory: to
2629
+ }
2630
+ }
2631
+ }
2632
+ };
2633
+ function ct(i) {
2634
+ return !i.getContextValue(Kr) && !i.getContextValue(Zr) && !i.getContextValue(Jr) && i.getContextValue(Ye);
2635
+ }
2636
+ const ho = {
2637
+ id: at.id,
2638
+ description: "shortcut.sheet.drawing-move-down",
2639
+ group: "4_sheet-drawing-view",
2640
+ binding: Ge.ARROW_DOWN,
2641
+ priority: 100,
2642
+ preconditions: ct,
2643
+ staticParameters: {
2644
+ direction: Ie.DOWN
2645
+ }
2646
+ }, go = {
2647
+ id: at.id,
2648
+ description: "shortcut.sheet.drawing-move-up",
2649
+ group: "4_sheet-drawing-view",
2650
+ binding: Ge.ARROW_UP,
2651
+ priority: 100,
2652
+ preconditions: ct,
2653
+ staticParameters: {
2654
+ direction: Ie.UP
2655
+ }
2656
+ }, mo = {
2657
+ id: at.id,
2658
+ description: "shortcut.sheet.drawing-move-left",
2659
+ group: "4_sheet-drawing-view",
2660
+ binding: Ge.ARROW_LEFT,
2661
+ priority: 100,
2662
+ preconditions: ct,
2663
+ staticParameters: {
2664
+ direction: Ie.LEFT
2665
+ }
2666
+ }, fo = {
2667
+ id: at.id,
2668
+ description: "shortcut.sheet.drawing-move-right",
2669
+ group: "4_sheet-drawing-view",
2670
+ binding: Ge.ARROW_RIGHT,
2671
+ priority: 100,
2672
+ preconditions: ct,
2673
+ staticParameters: {
2674
+ direction: Ie.RIGHT
2675
+ }
2676
+ }, po = {
2677
+ id: Pr.id,
2678
+ description: "shortcut.sheet.drawing-delete",
2679
+ group: "4_sheet-drawing-view",
2680
+ // when focusing on any other input tag do not trigger this shortcut
2681
+ preconditions: ct,
2682
+ binding: Ge.DELETE,
2683
+ mac: Ge.BACKSPACE
2684
+ };
2685
+ var wo = Object.getOwnPropertyDescriptor, _o = (i, t, e, n) => {
2686
+ for (var r = n > 1 ? void 0 : n ? wo(t, e) : t, s = i.length - 1, o; s >= 0; s--)
2687
+ (o = i[s]) && (r = o(r) || r);
2688
+ return r;
2689
+ }, xe = (i, t) => (e, n) => t(e, n, i);
2690
+ let $t = class extends se {
2691
+ constructor(i, t, e, n, r, s) {
2692
+ super(), this._componentManager = i, this._menuManagerService = t, this._commandService = e, this._shortcutService = n, this._drawingManagerService = r, this._sheetsSelectionsService = s, this._init();
2693
+ }
2694
+ _initCustomComponents() {
2695
+ const i = this._componentManager;
2696
+ this.disposeWithMe(i.register(Ar, Ur)), this.disposeWithMe(i.register(Ir, lo));
2697
+ }
2698
+ _initMenus() {
2699
+ this._menuManagerService.mergeMenu(uo);
2700
+ }
2701
+ _initCommands() {
2702
+ [
2703
+ Xt,
2704
+ _n,
2705
+ Gt,
2706
+ ot,
2707
+ Vt,
2708
+ Cr,
2709
+ F,
2710
+ Dr,
2711
+ br,
2712
+ Mr,
2713
+ at,
2714
+ Pr,
2715
+ Rr
2716
+ ].forEach((i) => this.disposeWithMe(this._commandService.registerCommand(i)));
2717
+ }
2718
+ _initShortcuts() {
2719
+ [
2720
+ // sheet drawing shortcuts
2721
+ ho,
2722
+ go,
2723
+ mo,
2724
+ fo,
2725
+ po
2726
+ ].forEach((i) => {
2727
+ this.disposeWithMe(this._shortcutService.registerShortcut(i));
2728
+ });
2729
+ }
2730
+ _init() {
2731
+ this._initCommands(), this._initCustomComponents(), this._initMenus(), this._initShortcuts();
2732
+ }
2733
+ };
2734
+ $t = _o([
2735
+ xe(0, N(xi)),
2736
+ xe(1, Li),
2737
+ xe(2, Y),
2738
+ xe(3, Fi),
2739
+ xe(4, oe),
2740
+ xe(5, N(pn))
2741
+ ], $t);
2742
+ var vo = Object.getOwnPropertyDescriptor, So = (i, t, e, n) => {
2743
+ for (var r = n > 1 ? void 0 : n ? vo(t, e) : t, s = i.length - 1, o; s >= 0; s--)
2744
+ (o = i[s]) && (r = o(r) || r);
2745
+ return r;
2746
+ }, Me = (i, t) => (e, n) => t(e, n, i);
2747
+ function Io(i, t, e, n, r) {
2748
+ const { scaleX: s, scaleY: o } = t.getAncestorScale(), a = t.getViewport(er.VIEW_MAIN), c = n.getFreeze(), { startColumn: u, startRow: l, xSplit: d, ySplit: g } = c, h = {
2749
+ left: !0,
2750
+ // left means the left of pic is in a viewMainLeft
2751
+ top: !0
2752
+ };
2753
+ if (!a)
2754
+ return {
2755
+ ...i,
2756
+ absolute: h
2757
+ };
2758
+ const { left: m, right: p, top: f, bottom: w } = i;
2759
+ let { top: S, left: C, viewportScrollX: D, viewportScrollY: v } = a;
2760
+ const { boundsOfViewArea: b, scrollDirectionResponse: _ } = r || {}, { rowHeaderWidth: T, columnHeaderHeight: M } = e, y = {
2761
+ top: M,
2762
+ left: T
2763
+ };
2764
+ b && (ye.isDefine(y.top) && (y.top = b.top), ye.isDefine(y.left) && (y.left = b.left)), _ === "HORIZONTAL" && (v = 0), _ === "VERTICAL" && (D = 0);
2765
+ let E = 0, I = 0;
2766
+ const R = e.rowStartY(l - g) + M, O = e.colStartX(u - d) + T, B = e.rowStartY(l) + M, z = e.colStartX(u) + T;
2767
+ if (d === 0)
2768
+ h.left = !1, E = (m - D) * s, I = (p - D) * s;
2769
+ else {
2770
+ const X = m - (O - T), Z = p - (O - T);
2771
+ p < z ? (E = X * s, I = Z * s) : m <= z && p >= z ? (E = X * s, I = Math.max(C, (p - D) * s)) : m > z && (h.left = !1, E = Math.max((m - D) * s, C), I = Math.max((p - D) * s, C));
2772
+ }
2773
+ let K = 0, G = 0;
2774
+ if (g === 0)
2775
+ h.top = !1, K = (f - v) * o, G = (w - v) * o;
2776
+ else {
2777
+ const X = f - (R - M), Z = w - (R - M);
2778
+ w < B ? (K = X * o, G = Z * o) : f <= B && w >= B ? (K = X * o, G = Math.max(S, (w - v) * o)) : f > B && (h.top = !1, K = Math.max((f - v) * o, S), G = Math.max((w - v) * o, S));
2779
+ }
2780
+ return E = Math.max(E, y.left), K = Math.max(K, y.top), I = Math.max(I, y.left), G = Math.max(G, y.top), {
2781
+ left: E,
2782
+ right: I,
2783
+ top: K,
2784
+ bottom: G,
2785
+ absolute: h
2786
+ };
2787
+ }
2788
+ const me = (i, t, e, n, r) => {
2789
+ const { scene: s } = t, { left: o, top: a, width: c, height: u, angle: l } = i, d = {
2790
+ left: o,
2791
+ right: o + c,
2792
+ top: a,
2793
+ bottom: a + u
2794
+ }, g = Io(d, s, e, n, r), { scaleX: h, scaleY: m } = s.getAncestorScale();
2795
+ return {
2796
+ startX: g.left,
2797
+ endX: g.right,
2798
+ startY: g.top,
2799
+ endY: g.bottom,
2800
+ rotate: l,
2801
+ width: c * h,
2802
+ height: u * m,
2803
+ absolute: g.absolute
2804
+ };
2805
+ };
2806
+ let xt = class extends se {
2807
+ constructor(t, e, n, r, s, o, a) {
2808
+ super();
2809
+ /**
2810
+ * for update dom container position when scrolling and zoom
2811
+ */
2812
+ q(this, "_domLayerMap", /* @__PURE__ */ new Map());
2813
+ /**
2814
+ * for update dom container position when scrolling and zoom
2815
+ */
2816
+ q(this, "_domLayerInfoMap", /* @__PURE__ */ new Map());
2817
+ q(this, "_transformChange$", new qt());
2818
+ q(this, "transformChange$", this._transformChange$.asObservable());
2819
+ q(this, "_add$", new qt());
2820
+ q(this, "add$", this._add$.asObservable());
2821
+ q(this, "_remove$", new qt());
2822
+ q(this, "remove$", this._remove$.asObservable());
2823
+ q(this, "_hooks", []);
2824
+ this._renderManagerService = t, this._univerInstanceService = e, this._commandService = n, this._drawingManagerService = r, this._canvasFloatDomService = s, this._sheetDrawingService = o, this._lifecycleService = a, this._drawingAddListener(), this._featureUpdateListener(), this._deleteListener(), this._bindScrollEvent();
2825
+ }
2826
+ _bindScrollEvent() {
2827
+ this._lifecycleService.lifecycle$.pipe(Vi((t) => t === Qr.Rendered), Xi(1)).subscribe(() => {
2828
+ this._scrollUpdateListener();
2829
+ });
2830
+ }
2831
+ /**
2832
+ * For scrolling and zoom
2833
+ * @param unitId
2834
+ * @param subUnitId
2835
+ */
2836
+ _ensureMap(t, e) {
2837
+ let n = this._domLayerMap.get(t);
2838
+ n || (n = /* @__PURE__ */ new Map(), this._domLayerMap.set(t, n));
2839
+ let r = n.get(e);
2840
+ return r || (r = /* @__PURE__ */ new Map(), n.set(e, r)), r;
2841
+ }
2842
+ getFloatDomInfo(t) {
2843
+ return this._domLayerInfoMap.get(t);
2844
+ }
2845
+ _getSceneAndTransformerByDrawingSearch(t) {
2846
+ if (t == null)
2847
+ return;
2848
+ const e = this._renderManagerService.getRenderById(t), n = e == null ? void 0 : e.scene;
2849
+ if (e == null || n == null)
2850
+ return null;
2851
+ const r = n.getTransformerByCreate(), s = e.engine.getCanvasElement();
2852
+ return { scene: n, transformer: r, renderUnit: e, canvas: s };
2853
+ }
2854
+ _getFloatDomProps(t) {
2855
+ let e;
2856
+ return this._hooks.forEach((n) => {
2857
+ e = n.onGetFloatDomProps(t);
2858
+ }), e;
2859
+ }
2860
+ // eslint-disable-next-line max-lines-per-function
2861
+ _drawingAddListener() {
2862
+ this.disposeWithMe(
2863
+ // eslint-disable-next-line max-lines-per-function
2864
+ this._drawingManagerService.add$.subscribe((t) => {
2865
+ t.forEach((e) => {
2866
+ var Z, ce, J;
2867
+ const { unitId: n, subUnitId: r, drawingId: s } = e, o = le(this._univerInstanceService, { unitId: n, subUnitId: r }), a = this._drawingManagerService.getDrawingByParam(e), c = this._univerInstanceService.getUnit(n, x.UNIVER_SHEET);
2868
+ if (!c)
2869
+ return;
2870
+ const u = c.getActiveSheet().getSheetId();
2871
+ if (!a || !o)
2872
+ return;
2873
+ const l = (Z = this._renderManagerService.getRenderById(n)) == null ? void 0 : Z.with(V).getSkeletonParam(r);
2874
+ if (!l)
2875
+ return;
2876
+ const { transform: d, drawingType: g, data: h } = a;
2877
+ if (g !== L.DRAWING_DOM && g !== L.DRAWING_CHART)
2878
+ return;
2879
+ const m = this._getSceneAndTransformerByDrawingSearch(n);
2880
+ if (m == null)
2881
+ return;
2882
+ const { scene: p, canvas: f } = m;
2883
+ if (d == null)
2884
+ return !0;
2885
+ if (u !== r)
2886
+ return;
2887
+ const { left: w, top: S, width: C, height: D, angle: v, flipX: b, flipY: _, skewX: T, skewY: M } = d, y = De({ unitId: n, subUnitId: r, drawingId: s }), E = p.getObject(y);
2888
+ if (E != null) {
2889
+ E.transformByState({ left: w, top: S, width: C, height: D, angle: v, flipX: b, flipY: _, skewX: T, skewY: M });
2890
+ return;
2891
+ }
2892
+ const I = {
2893
+ left: w,
2894
+ top: S,
2895
+ width: C,
2896
+ height: D,
2897
+ zIndex: this._drawingManagerService.getDrawingOrder(n, r).length - 1
2898
+ }, R = g === L.DRAWING_CHART;
2899
+ if (R) {
2900
+ const W = h ? h.backgroundColor : "white";
2901
+ I.fill = W, I.rotateEnabled = !1, h && h.border && (I.stroke = h.border), I.paintFirst = "stroke", I.strokeWidth = 1, I.borderEnabled = !1, I.radius = 8;
2902
+ }
2903
+ const O = new je(y, I);
2904
+ R && O.setObjectType(kn.CHART), p.addObject(O, Jt), a.allowTransform !== !1 && p.attachTransformerTo(O);
2905
+ const B = this._ensureMap(n, r), z = new St(), K = me(O, m.renderUnit, l.skeleton, o.worksheet), G = new Je(K), fe = {
2906
+ dispose: z,
2907
+ rect: O,
2908
+ position$: G,
2909
+ unitId: n,
2910
+ subUnitId: r
2911
+ };
2912
+ this._canvasFloatDomService.addFloatDom({
2913
+ position$: G,
2914
+ id: s,
2915
+ componentKey: a.componentKey,
2916
+ onPointerDown: (W) => {
2917
+ f.dispatchEvent(new PointerEvent(W.type, W));
2918
+ },
2919
+ onPointerMove: (W) => {
2920
+ f.dispatchEvent(new PointerEvent(W.type, W));
2921
+ },
2922
+ onPointerUp: (W) => {
2923
+ f.dispatchEvent(new PointerEvent(W.type, W));
2924
+ },
2925
+ onWheel: (W) => {
2926
+ f.dispatchEvent(new WheelEvent(W.type, W));
2927
+ },
2928
+ props: (J = (ce = B.get(s)) == null ? void 0 : ce.props) != null ? J : this._getFloatDomProps(s),
2929
+ data: h,
2930
+ unitId: n
2931
+ });
2932
+ const X = O.onTransformChange$.subscribeEvent(() => {
2933
+ const W = me(O, m.renderUnit, l.skeleton, o.worksheet);
2934
+ G.next(
2935
+ W
2936
+ );
2937
+ });
2938
+ z.add(() => {
2939
+ this._canvasFloatDomService.removeFloatDom(s);
2940
+ }), X && z.add(X), this._domLayerInfoMap.set(s, fe), B.set(s, {
2941
+ ...B.get(s)
2942
+ });
2943
+ });
2944
+ })
2945
+ ), this.disposeWithMe(
2946
+ this._drawingManagerService.remove$.subscribe((t) => {
2947
+ t.forEach((e) => {
2948
+ const { unitId: n, subUnitId: r, drawingId: s } = e, o = De({ unitId: n, subUnitId: r, drawingId: s }), a = this._getSceneAndTransformerByDrawingSearch(n);
2949
+ if (a == null)
2950
+ return;
2951
+ const { transformer: c, scene: u } = a, l = u.getObject(o);
2952
+ l != null && l.oKey && c.clearControlByIds([l == null ? void 0 : l.oKey]);
2953
+ });
2954
+ })
2955
+ );
2956
+ }
2957
+ _scrollUpdateListener() {
2958
+ const t = (e, n) => {
2959
+ var u;
2960
+ const r = this._getSceneAndTransformerByDrawingSearch(e), s = this._ensureMap(e, n), o = Array.from(s.keys()), a = le(this._univerInstanceService, { unitId: e, subUnitId: n }), c = (u = this._renderManagerService.getRenderById(e)) == null ? void 0 : u.with(V).getSkeletonParam(n);
2961
+ !r || !a || !c || o.forEach((l) => {
2962
+ const d = this._domLayerInfoMap.get(l);
2963
+ if (d) {
2964
+ const g = me(d.rect, r.renderUnit, c.skeleton, a.worksheet, d);
2965
+ d.position$.next(g);
2966
+ }
2967
+ });
2968
+ };
2969
+ this.disposeWithMe(
2970
+ this._univerInstanceService.getCurrentTypeOfUnit$(x.UNIVER_SHEET).pipe(
2971
+ Se((e) => e ? e.activeSheet$ : Fn(null)),
2972
+ Te((e) => {
2973
+ if (!e) return null;
2974
+ const n = e.getUnitId(), r = this._renderManagerService.getRenderById(n);
2975
+ return r ? { render: r, unitId: n, subUnitId: e.getSheetId() } : null;
2976
+ }),
2977
+ Se(
2978
+ (e) => e ? ei(e.render.scene.getViewport(er.VIEW_MAIN).onScrollAfter$).pipe(Te(() => ({ unitId: e.unitId, subUnitId: e.subUnitId }))) : Fn(null)
2979
+ )
2980
+ ).subscribe((e) => {
2981
+ if (!e) return;
2982
+ const { unitId: n, subUnitId: r } = e;
2983
+ t(n, r);
2984
+ })
2985
+ ), this.disposeWithMe(this._commandService.onCommandExecuted((e) => {
2986
+ var n, r;
2987
+ if (e.id === jn.id) {
2988
+ const s = e.params, { unitId: o } = s;
2989
+ Array.from((r = (n = this._domLayerMap.get(o)) == null ? void 0 : n.keys()) != null ? r : []).forEach((c) => {
2990
+ t(o, c);
2991
+ });
2992
+ } else if (e.id === rs.id) {
2993
+ const { unitId: s, subUnitId: o } = e.params;
2994
+ t(s, o);
2995
+ }
2996
+ }));
2997
+ }
2998
+ _getPosition(t, e) {
2999
+ var g;
3000
+ const { startX: n, endX: r, startY: s, endY: o } = t, a = (g = this._renderManagerService.getRenderById(e)) == null ? void 0 : g.with(Xe);
3001
+ if (a == null)
3002
+ return;
3003
+ const c = a.getCellWithCoordByOffset(n, s);
3004
+ if (c == null)
3005
+ return;
3006
+ const u = {
3007
+ column: c.actualColumn,
3008
+ columnOffset: n - c.startX,
3009
+ row: c.actualRow,
3010
+ rowOffset: s - c.startY
3011
+ }, l = a.getCellWithCoordByOffset(r, o);
3012
+ if (l == null)
3013
+ return;
3014
+ const d = {
3015
+ column: l.actualColumn,
3016
+ columnOffset: r - l.startX,
3017
+ row: l.actualRow,
3018
+ rowOffset: o - l.startY
3019
+ };
3020
+ return {
3021
+ from: u,
3022
+ to: d
3023
+ };
3024
+ }
3025
+ _featureUpdateListener() {
3026
+ this.disposeWithMe(
3027
+ this._drawingManagerService.update$.subscribe((t) => {
3028
+ t.forEach((e) => {
3029
+ const n = this._drawingManagerService.getDrawingByParam(e);
3030
+ if (!n || n.drawingType !== L.DRAWING_DOM && n.drawingType !== L.DRAWING_CHART)
3031
+ return;
3032
+ const r = {
3033
+ ...n.transform
3034
+ };
3035
+ this._transformChange$.next({ id: e.drawingId, value: r });
3036
+ });
3037
+ })
3038
+ );
3039
+ }
3040
+ _deleteListener() {
3041
+ this.disposeWithMe(
3042
+ this._drawingManagerService.remove$.subscribe((t) => {
3043
+ t.forEach((e) => {
3044
+ this._removeDom(e.drawingId);
3045
+ });
3046
+ })
3047
+ );
3048
+ }
3049
+ updateFloatDomProps(t, e, n, r) {
3050
+ const s = this._domLayerInfoMap.get(n), o = this._getSceneAndTransformerByDrawingSearch(t);
3051
+ if (s && o) {
3052
+ const { scene: a } = o, c = De({ unitId: t, subUnitId: e, drawingId: n }), u = a.getObject(c);
3053
+ u && u instanceof je && u.setProps(r);
3054
+ }
3055
+ }
3056
+ // CreateFloatDomCommand --> floatDomService.addFloatDomToPosition
3057
+ addFloatDomToPosition(t, e) {
3058
+ const n = le(this._univerInstanceService, {
3059
+ unitId: t.unitId,
3060
+ subUnitId: t.subUnitId
3061
+ });
3062
+ if (!n)
3063
+ throw new Error("cannot find current target!");
3064
+ const { unitId: r, subUnitId: s } = n, { initPosition: o, componentKey: a, data: c, allowTransform: u = !0 } = t, l = e != null ? e : Ot(), d = this._getPosition(o, r);
3065
+ if (d == null)
3066
+ return;
3067
+ this._ensureMap(r, s).set(l, t);
3068
+ const h = {
3069
+ unitId: r,
3070
+ subUnitId: s,
3071
+ drawingId: l,
3072
+ drawingType: t.type || L.DRAWING_DOM,
3073
+ componentKey: a,
3074
+ sheetTransform: d,
3075
+ transform: {
3076
+ left: o.startX,
3077
+ top: o.startY,
3078
+ width: o.endX - o.startX,
3079
+ height: o.endY - o.startY
3080
+ },
3081
+ data: c,
3082
+ allowTransform: u
3083
+ };
3084
+ return this._commandService.executeCommand(Gt.id, {
3085
+ unitId: r,
3086
+ drawings: [h]
3087
+ }), this._add$.next({ unitId: r, subUnitId: s, id: l }), {
3088
+ id: l,
3089
+ dispose: () => {
3090
+ this._removeDom(l, !0);
3091
+ }
3092
+ };
3093
+ }
3094
+ _removeDom(t, e = !1) {
3095
+ const n = this._domLayerInfoMap.get(t);
3096
+ if (!n)
3097
+ return;
3098
+ const { unitId: r, subUnitId: s } = n;
3099
+ this._domLayerInfoMap.delete(t), n.dispose.dispose();
3100
+ const o = this._getSceneAndTransformerByDrawingSearch(r);
3101
+ if (o && o.scene.removeObject(n.rect), e) {
3102
+ this._ensureMap(r, s).delete(t);
3103
+ const c = this._drawingManagerService.getDrawingByParam({ unitId: r, subUnitId: s, drawingId: t });
3104
+ if (!c)
3105
+ return;
3106
+ const u = this._sheetDrawingService.getBatchRemoveOp([c]), { redo: l, objects: d } = u;
3107
+ this._commandService.syncExecuteCommand(A.id, { unitId: r, subUnitId: s, op: l, objects: d, type: P.REMOVE });
3108
+ }
3109
+ }
3110
+ addHook(t) {
3111
+ return this._hooks.push(t), {
3112
+ dispose: () => {
3113
+ const e = this._hooks.findIndex((n) => n === t);
3114
+ this._hooks.splice(e, 1);
3115
+ }
3116
+ };
3117
+ }
3118
+ // eslint-disable-next-line max-lines-per-function, complexity
3119
+ addFloatDomToRange(t, e, n, r) {
3120
+ var _, T, M, y, E;
3121
+ const s = le(this._univerInstanceService, {
3122
+ unitId: e.unitId,
3123
+ subUnitId: e.subUnitId
3124
+ });
3125
+ if (!s)
3126
+ throw new Error("cannot find current target!");
3127
+ const { unitId: o, subUnitId: a } = s, c = this._getSceneAndTransformerByDrawingSearch(o);
3128
+ if (!c) return;
3129
+ const u = this._renderManagerService.getRenderById(o);
3130
+ if (!u) return;
3131
+ const l = (_ = this._renderManagerService.getRenderById(o)) == null ? void 0 : _.with(V).getWorksheetSkeleton(a);
3132
+ if (!l) return;
3133
+ const { componentKey: d, data: g, allowTransform: h = !0 } = e, m = r != null ? r : Ot(), { position: p, position$: f } = this._createRangePositionObserver(t, u, l.skeleton);
3134
+ if (this._getPosition(p, o) == null)
3135
+ return;
3136
+ this._ensureMap(o, a).set(m, e);
3137
+ const C = c.scene, { scaleX: D } = C.getAncestorScale(), v = Et(p, n, D), b = {
3138
+ unitId: o,
3139
+ subUnitId: a,
3140
+ drawingId: m,
3141
+ drawingType: e.type || L.DRAWING_DOM,
3142
+ componentKey: d,
3143
+ transform: {
3144
+ left: v.startX,
3145
+ top: v.startY,
3146
+ width: v.width,
3147
+ height: v.height
3148
+ },
3149
+ data: g,
3150
+ allowTransform: h
3151
+ };
3152
+ {
3153
+ const { unitId: I, subUnitId: R, drawingId: O } = b, B = le(this._univerInstanceService, { unitId: I, subUnitId: R }), z = b, K = this._univerInstanceService.getUnit(I, x.UNIVER_SHEET);
3154
+ if (!K)
3155
+ return;
3156
+ const G = K.getActiveSheet().getSheetId();
3157
+ if (!z || !B)
3158
+ return;
3159
+ const fe = (T = this._renderManagerService.getRenderById(I)) == null ? void 0 : T.with(V);
3160
+ if (!fe)
3161
+ return;
3162
+ const X = fe.getWorksheetSkeleton(R);
3163
+ if (!X)
3164
+ return;
3165
+ const { transform: Z, drawingType: ce, data: J } = z;
3166
+ if (ce !== L.DRAWING_DOM && ce !== L.DRAWING_CHART)
3167
+ return;
3168
+ const W = this._getSceneAndTransformerByDrawingSearch(I);
3169
+ if (W == null)
3170
+ return;
3171
+ const { scene: Oe, canvas: Ue } = W;
3172
+ if (Z == null || G !== R)
3173
+ return;
3174
+ const { left: dt, top: lt, width: ut, height: ht, angle: Ht, flipX: zt, flipY: gt, skewX: mt, skewY: Pe } = Z, ft = De({ unitId: I, subUnitId: R, drawingId: O }), ue = Oe.getObject(ft);
3175
+ if (ue != null) {
3176
+ ue.transformByState({ left: dt, top: lt, width: ut, height: ht, angle: Ht, flipX: zt, flipY: gt, skewX: mt, skewY: Pe });
3177
+ return;
3178
+ }
3179
+ const ne = {
3180
+ left: dt,
3181
+ // from floatDomParam.transform
3182
+ top: lt,
3183
+ width: ut,
3184
+ height: ht,
3185
+ zIndex: this._drawingManagerService.getDrawingOrder(I, R).length - 1
3186
+ }, Ae = ce === L.DRAWING_CHART;
3187
+ if (Ae) {
3188
+ const k = J ? J.backgroundColor : "white";
3189
+ ne.fill = k, ne.rotateEnabled = !1, J && J.border && (ne.stroke = J.border), ne.paintFirst = "stroke", ne.strokeWidth = 1, ne.borderEnabled = !1, ne.radius = 8;
3190
+ }
3191
+ const de = new je(ft, ne);
3192
+ Ae && de.setObjectType(kn.CHART), Oe.addObject(de, Jt), z.allowTransform !== !1 && Oe.attachTransformerTo(de);
3193
+ const He = this._ensureMap(I, R), he = new St(), pt = Oe.getMainViewport(), { rowHeaderWidth: Ne, columnHeaderHeight: ze } = X.skeleton, wt = {
3194
+ top: ze,
3195
+ left: Ne,
3196
+ bottom: pt.bottom,
3197
+ right: pt.right
3198
+ }, ge = {
3199
+ dispose: he,
3200
+ rect: de,
3201
+ boundsOfViewArea: wt,
3202
+ domAnchor: n,
3203
+ unitId: I,
3204
+ subUnitId: R
3205
+ }, j = me(de, W.renderUnit, X.skeleton, B.worksheet, ge), ke = new Je(j);
3206
+ ge.position$ = ke;
3207
+ let Ke = {
3208
+ position$: ke,
3209
+ id: O,
3210
+ componentKey: z.componentKey,
3211
+ onPointerDown: () => {
3212
+ },
3213
+ onPointerMove: () => {
3214
+ },
3215
+ onPointerUp: () => {
3216
+ },
3217
+ onWheel: (k) => {
3218
+ Ue.dispatchEvent(new WheelEvent(k.type, k));
3219
+ },
3220
+ props: (y = (M = He.get(O)) == null ? void 0 : M.props) != null ? y : this._getFloatDomProps(O),
3221
+ data: J,
3222
+ unitId: I
3223
+ };
3224
+ e.eventPassThrough && (Ke = {
3225
+ ...Ke,
3226
+ onPointerDown: (k) => {
3227
+ Ue.dispatchEvent(new PointerEvent(k.type, k));
3228
+ },
3229
+ onPointerMove: (k) => {
3230
+ Ue.dispatchEvent(new PointerEvent(k.type, k));
3231
+ },
3232
+ onPointerUp: (k) => {
3233
+ Ue.dispatchEvent(new PointerEvent(k.type, k));
3234
+ }
3235
+ }), this._canvasFloatDomService.addFloatDom(Ke), this.disposeWithMe(f.subscribe((k) => {
3236
+ var Sn, In, Cn, Dn;
3237
+ const vn = Et({
3238
+ startX: k.startX,
3239
+ startY: k.startY,
3240
+ endX: k.endX,
3241
+ endY: k.endY,
3242
+ width: (Sn = n.width) != null ? Sn : k.width,
3243
+ height: (In = n.height) != null ? In : k.height,
3244
+ absolute: {
3245
+ left: p.absolute.left,
3246
+ top: p.absolute.top
3247
+ }
3248
+ }, n), Br = De({ unitId: I, subUnitId: R, drawingId: O }), Wr = new je(Br, {
3249
+ left: vn.startX,
3250
+ top: vn.startY,
3251
+ width: (Cn = n.width) != null ? Cn : k.width,
3252
+ height: (Dn = n.height) != null ? Dn : k.height,
3253
+ zIndex: this._drawingManagerService.getDrawingOrder(I, R).length - 1
3254
+ }), jr = me(Wr, W.renderUnit, X.skeleton, B.worksheet, ge);
3255
+ ke.next(jr);
3256
+ }));
3257
+ const Ze = (E = this._renderManagerService.getRenderById(I)) == null ? void 0 : E.with(V);
3258
+ Ze == null || Ze.currentSkeleton$.subscribe((k) => {
3259
+ k && X.sheetId !== k.sheetId && this._removeDom(m, !0);
3260
+ });
3261
+ const _t = de.onTransformChange$.subscribeEvent(() => {
3262
+ const k = me(de, W.renderUnit, X.skeleton, B.worksheet, ge);
3263
+ ke.next(
3264
+ k
3265
+ );
3266
+ });
3267
+ he.add(() => {
3268
+ this._canvasFloatDomService.removeFloatDom(O);
3269
+ }), _t && he.add(_t), this._domLayerInfoMap.set(O, ge), He.set(O, {
3270
+ ...He.get(O)
3271
+ });
3272
+ }
3273
+ return {
3274
+ id: m,
3275
+ dispose: () => {
3276
+ this._removeDom(m, !0);
3277
+ }
3278
+ };
3279
+ }
3280
+ addFloatDomToColumnHeader(t, e, n, r) {
3281
+ var v, b, _, T, M;
3282
+ const s = le(this._univerInstanceService, {
3283
+ unitId: e.unitId,
3284
+ subUnitId: e.subUnitId
3285
+ });
3286
+ if (!s)
3287
+ throw new Error("cannot find current target!");
3288
+ const { unitId: o, subUnitId: a } = s;
3289
+ if (!this._getSceneAndTransformerByDrawingSearch(o)) return;
3290
+ const u = this._renderManagerService.getRenderById(o);
3291
+ if (!u) return;
3292
+ const l = (v = this._renderManagerService.getRenderById(o)) == null ? void 0 : v.with(V).getWorksheetSkeleton(a);
3293
+ if (!l) return;
3294
+ const { componentKey: d, data: g, allowTransform: h = !0 } = e, m = r != null ? r : Ot(), { position: p, position$: f } = this._createRangePositionObserver({
3295
+ startRow: 0,
3296
+ endRow: 0,
3297
+ startColumn: t,
3298
+ endColumn: t
3299
+ }, u, l.skeleton), w = p;
3300
+ if (w.startY = 0, this._getPosition(p, o) == null)
3301
+ return;
3302
+ this._ensureMap(o, a).set(m, e);
3303
+ const D = {
3304
+ unitId: o,
3305
+ subUnitId: a,
3306
+ drawingId: m,
3307
+ drawingType: e.type || L.DRAWING_DOM,
3308
+ componentKey: d,
3309
+ transform: {
3310
+ left: w.startX,
3311
+ top: w.startY,
3312
+ width: w.width,
3313
+ height: w.height
3314
+ },
3315
+ data: g,
3316
+ allowTransform: h
3317
+ };
3318
+ {
3319
+ const { unitId: y, subUnitId: E, drawingId: I } = D, R = le(this._univerInstanceService, { unitId: y, subUnitId: E }), O = D, B = this._univerInstanceService.getUnit(y, x.UNIVER_SHEET);
3320
+ if (!B)
3321
+ return;
3322
+ const z = B.getActiveSheet().getSheetId();
3323
+ if (!O || !R)
3324
+ return;
3325
+ const K = (b = this._renderManagerService.getRenderById(y)) == null ? void 0 : b.with(V);
3326
+ if (!K)
3327
+ return;
3328
+ const G = K.getWorksheetSkeleton(E);
3329
+ if (!G)
3330
+ return;
3331
+ const { transform: fe, data: X } = O, Z = this._getSceneAndTransformerByDrawingSearch(y);
3332
+ if (Z == null)
3333
+ return;
3334
+ const { scene: ce, canvas: J } = Z;
3335
+ if (fe == null || z !== E)
3336
+ return;
3337
+ const { left: W, top: Oe, width: Ue, height: dt, angle: lt, flipX: ut, flipY: ht, skewX: Ht, skewY: zt } = fe, gt = De({ unitId: y, subUnitId: E, drawingId: I }), mt = ce.getObject(gt);
3338
+ if (mt != null) {
3339
+ mt.transformByState({ left: W, top: Oe, width: Ue, height: dt, angle: lt, flipX: ut, flipY: ht, skewX: Ht, skewY: zt });
3340
+ return;
3341
+ }
3342
+ const Pe = Et({
3343
+ startX: w.startX,
3344
+ startY: 0,
3345
+ endX: p.endX,
3346
+ endY: p.endY,
3347
+ width: n.width,
3348
+ height: n.height,
3349
+ absolute: {
3350
+ left: p.absolute.left,
3351
+ top: p.absolute.top
3352
+ }
3353
+ }, n), ft = {
3354
+ left: Pe.startX,
3355
+ top: Pe.startY,
3356
+ width: Pe.width,
3357
+ height: Pe.height,
3358
+ zIndex: this._drawingManagerService.getDrawingOrder(y, E).length - 1
3359
+ }, ue = new je(gt, ft);
3360
+ ce.addObject(ue, Jt), O.allowTransform !== !1 && ce.attachTransformerTo(ue);
3361
+ const ne = this._ensureMap(y, E), Ae = new St(), de = ce.getMainViewport(), He = {
3362
+ top: 0,
3363
+ //viewMain.top,
3364
+ left: de.left,
3365
+ bottom: de.bottom,
3366
+ right: de.right
3367
+ }, he = {
3368
+ dispose: Ae,
3369
+ rect: ue,
3370
+ // position$,
3371
+ unitId: y,
3372
+ subUnitId: E,
3373
+ boundsOfViewArea: He,
3374
+ domAnchor: n,
3375
+ scrollDirectionResponse: "HORIZONTAL"
3376
+ /* HORIZONTAL */
3377
+ }, pt = me(ue, Z.renderUnit, G.skeleton, R.worksheet, he), Ne = new Je(pt);
3378
+ he.position$ = Ne;
3379
+ let ze = {
3380
+ position$: Ne,
3381
+ id: I,
3382
+ componentKey: O.componentKey,
3383
+ onPointerDown: () => {
3384
+ },
3385
+ onPointerMove: () => {
3386
+ },
3387
+ onPointerUp: () => {
3388
+ },
3389
+ onWheel: (j) => {
3390
+ J.dispatchEvent(new WheelEvent(j.type, j));
3391
+ },
3392
+ props: (T = (_ = ne.get(I)) == null ? void 0 : _.props) != null ? T : this._getFloatDomProps(I),
3393
+ data: X,
3394
+ unitId: y
3395
+ };
3396
+ e.eventPassThrough && (ze = {
3397
+ ...ze,
3398
+ onPointerDown: (j) => {
3399
+ J.dispatchEvent(new PointerEvent(j.type, j));
3400
+ },
3401
+ onPointerMove: (j) => {
3402
+ J.dispatchEvent(new PointerEvent(j.type, j));
3403
+ },
3404
+ onPointerUp: (j) => {
3405
+ J.dispatchEvent(new PointerEvent(j.type, j));
3406
+ }
3407
+ }), this._canvasFloatDomService.addFloatDom(ze);
3408
+ const wt = ue.onTransformChange$.subscribeEvent(() => {
3409
+ const j = me(ue, Z.renderUnit, G.skeleton, R.worksheet, he);
3410
+ Ne.next(
3411
+ j
3412
+ );
3413
+ });
3414
+ this.disposeWithMe(f.subscribe((j) => {
3415
+ const ke = Et({
3416
+ startX: j.startX,
3417
+ startY: 0,
3418
+ endX: j.endX,
3419
+ endY: j.endY,
3420
+ width: n.width,
3421
+ height: n.height,
3422
+ absolute: {
3423
+ left: p.absolute.left,
3424
+ top: p.absolute.top
3425
+ }
3426
+ }, n), Ke = De({ unitId: y, subUnitId: E, drawingId: I }), Ze = new je(Ke, {
3427
+ left: ke.startX,
3428
+ top: 0,
3429
+ width: n.width,
3430
+ height: n.height,
3431
+ zIndex: this._drawingManagerService.getDrawingOrder(y, E).length - 1
3432
+ }), _t = me(Ze, Z.renderUnit, G.skeleton, R.worksheet, he);
3433
+ Ne.next(_t);
3434
+ }));
3435
+ const ge = (M = this._renderManagerService.getRenderById(y)) == null ? void 0 : M.with(V);
3436
+ ge == null || ge.currentSkeleton$.subscribe((j) => {
3437
+ j && l.sheetId !== j.sheetId && this._removeDom(m, !0);
3438
+ }), Ae.add(() => {
3439
+ this._canvasFloatDomService.removeFloatDom(I);
3440
+ }), wt && Ae.add(wt), this._domLayerInfoMap.set(I, he), ne.set(I, {
3441
+ ...ne.get(I)
3442
+ });
3443
+ }
3444
+ return {
3445
+ id: m,
3446
+ dispose: () => {
3447
+ this._removeDom(m, !0);
3448
+ }
3449
+ };
3450
+ }
3451
+ /**
3452
+ * Unlike _createCellPositionObserver, this accept a range not a single cell.
3453
+ *
3454
+ * @param initialRow
3455
+ * @param initialCol
3456
+ * @param currentRender
3457
+ * @param skeleton
3458
+ * @param activeViewport
3459
+ * @returns position of cell to canvas.
3460
+ */
3461
+ _createRangePositionObserver(t, e, n) {
3462
+ let { startRow: r, startColumn: s } = t;
3463
+ const o = tt(r, s, n), a = new Je(o), c = tt(t.endRow, t.endColumn, n), u = new Je(c), l = () => {
3464
+ const f = tt(r, s, n), w = tt(t.endRow, t.endColumn, n);
3465
+ a.next(f), u.next(w);
3466
+ }, d = new St();
3467
+ d.add(e.engine.clientRect$.subscribe(() => l())), d.add(this._commandService.onCommandExecuted((f) => {
3468
+ if (f.id === is.id && f.params.rowsAutoHeightInfo.findIndex((S) => S.row === r) > -1) {
3469
+ l();
3470
+ return;
3471
+ }
3472
+ (ss.indexOf(f.id) > -1 || f.id === Oi.id || f.id === jn.id) && l();
3473
+ }));
3474
+ const g = (f, w) => {
3475
+ r = f, s = w, l();
3476
+ }, h = () => ({
3477
+ rotate: 0,
3478
+ width: c.right - o.left,
3479
+ height: c.bottom - o.top,
3480
+ absolute: {
3481
+ left: !0,
3482
+ top: !0
3483
+ },
3484
+ startX: o.left,
3485
+ startY: o.top,
3486
+ endX: c.right,
3487
+ endY: c.bottom
3488
+ }), m = a.pipe(
3489
+ Te((f) => {
3490
+ const w = tt(t.endRow, t.endColumn, n);
3491
+ return {
3492
+ rotate: 0,
3493
+ width: w.right - f.left,
3494
+ height: w.bottom - f.top,
3495
+ absolute: {
3496
+ left: !0,
3497
+ top: !0
3498
+ },
3499
+ startX: f.left,
3500
+ startY: f.top,
3501
+ endX: w.right,
3502
+ endY: w.bottom
3503
+ };
3504
+ })
3505
+ ), p = h();
3506
+ return {
3507
+ position$: m,
3508
+ position: p,
3509
+ updateRowCol: g,
3510
+ topLeftPos$: a,
3511
+ rightBottomPos$: u,
3512
+ disposable: d
3513
+ };
3514
+ }
3515
+ };
3516
+ xt = So([
3517
+ Me(0, N(te)),
3518
+ Me(1, Ce),
3519
+ Me(2, N(Y)),
3520
+ Me(3, oe),
3521
+ Me(4, N(Yi)),
3522
+ Me(5, ae),
3523
+ Me(6, N(qr))
3524
+ ], xt);
3525
+ function tt(i, t, e) {
3526
+ const n = e.getCellWithCoordByIndex(i, t), r = n.isMergedMainCell ? n.mergeInfo : n;
3527
+ return {
3528
+ left: r.startX,
3529
+ right: r.endX,
3530
+ top: r.startY,
3531
+ bottom: r.endY
3532
+ };
3533
+ }
3534
+ function Et(i, t, e) {
3535
+ var u, l;
3536
+ e = e != null ? e : 1;
3537
+ const n = i.endX - i.startX, r = i.endY - i.startY, s = (u = t == null ? void 0 : t.width) != null ? u : n, o = (l = t == null ? void 0 : t.height) != null ? l : r;
3538
+ let a = 0, c = 0;
3539
+ if (t) {
3540
+ if (t.horizonOffsetAlign === "right") {
3541
+ const d = Tt(t.marginX, n * e);
3542
+ a = i.endX - d - s;
3543
+ } else
3544
+ a = i.startX + Tt(t.marginX, n);
3545
+ if (t.verticalOffsetAlign === "bottom") {
3546
+ const d = Tt(t.marginY, r * e);
3547
+ c = i.endY - d - o;
3548
+ } else
3549
+ c = i.startY + Tt(t.marginY, r);
3550
+ }
3551
+ return {
3552
+ rotate: 0,
3553
+ startX: a,
3554
+ startY: c,
3555
+ endX: i.endX,
3556
+ endY: i.endY,
3557
+ width: s,
3558
+ height: o,
3559
+ absolute: {
3560
+ left: i.absolute.left,
3561
+ top: i.absolute.top
3562
+ }
3563
+ };
3564
+ }
3565
+ function Tt(i, t) {
3566
+ if (i === void 0) return 0;
3567
+ if (typeof i == "number") return i;
3568
+ const e = Number.parseFloat(i);
3569
+ return t * e / 100;
3570
+ }
3571
+ var Co = Object.defineProperty, Do = Object.getOwnPropertyDescriptor, bo = (i, t, e) => t in i ? Co(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e, Ro = (i, t, e, n) => {
3572
+ for (var r = n > 1 ? void 0 : n ? Do(t, e) : t, s = i.length - 1, o; s >= 0; s--)
3573
+ (o = i[s]) && (r = o(r) || r);
3574
+ return r;
3575
+ }, en = (i, t) => (e, n) => t(e, n, i), kr = (i, t, e) => bo(i, typeof t != "symbol" ? t + "" : t, e);
3576
+ const Mo = "SHEET_IMAGE_UI_PLUGIN";
3577
+ let Lt = class extends ri {
3578
+ constructor(i = Hn, t, e, n) {
3579
+ super(), this._config = i, this._injector = t, this._renderManagerService = e, this._configService = n;
3580
+ const { menu: r, ...s } = ii(
3581
+ {},
3582
+ Hn,
3583
+ this._config
3584
+ );
3585
+ r && this._configService.setConfig("menu", r, { merge: !0 }), this._configService.setConfig(us, s);
3586
+ }
3587
+ onStarting() {
3588
+ si(this._injector, [
3589
+ [xt],
3590
+ [$t],
3591
+ [Pt],
3592
+ [jt],
3593
+ [Wt],
3594
+ [Bt],
3595
+ [At],
3596
+ [Nt],
3597
+ [kt]
3598
+ ]), Kt(this._injector, [
3599
+ [xt]
3600
+ ]);
3601
+ }
3602
+ onReady() {
3603
+ Kt(this._injector, [
3604
+ [Bt],
3605
+ [kt]
3606
+ ]);
3607
+ }
3608
+ onRendered() {
3609
+ this._registerRenderModules(), Kt(this._injector, [
3610
+ [Wt],
3611
+ [jt],
3612
+ [$t],
3613
+ [At],
3614
+ [Nt]
3615
+ ]);
3616
+ }
3617
+ onSteady() {
3618
+ this._injector.get(Pt);
3619
+ }
3620
+ _registerRenderModules() {
3621
+ [
3622
+ [rt],
3623
+ [hn],
3624
+ [ln],
3625
+ [dn]
3626
+ ].forEach((i) => {
3627
+ this.disposeWithMe(this._renderManagerService.registerRenderModule(x.UNIVER_SHEET, i));
3628
+ });
3629
+ }
3630
+ };
3631
+ kr(Lt, "type", x.UNIVER_SHEET);
3632
+ kr(Lt, "pluginName", Mo);
3633
+ Lt = Ro([
3634
+ ti(di, ai, fi, vi),
3635
+ en(1, N(st)),
3636
+ en(2, te),
3637
+ en(3, ni)
3638
+ ], Lt);
3639
+ export {
3640
+ F as ClearSheetDrawingTransformerOperation,
3641
+ Pr as DeleteDrawingsCommand,
3642
+ Dr as EditSheetDrawingOperation,
3643
+ br as GroupSheetDrawingCommand,
3644
+ Xt as InsertFloatImageCommand,
3645
+ Gt as InsertSheetDrawingCommand,
3646
+ at as MoveDrawingsCommand,
3647
+ ot as RemoveSheetDrawingCommand,
3648
+ Nr as SHEETS_IMAGE_MENU_ID,
3649
+ Rr as SetDrawingArrangeCommand,
3650
+ Vt as SetSheetDrawingCommand,
3651
+ xt as SheetCanvasFloatDomManagerService,
3652
+ rt as SheetDrawingUpdateController,
3653
+ Cr as SidebarSheetDrawingOperation,
3654
+ Mr as UngroupSheetDrawingCommand,
3655
+ Lt as UniverSheetsDrawingUIPlugin
3656
+ };