@univerjs/sheets-drawing-ui 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/lib/cjs/facade.js +1 -1
  2. package/lib/cjs/index.js +7 -2
  3. package/lib/cjs/locale/ca-ES.js +1 -1
  4. package/lib/cjs/locale/en-US.js +1 -1
  5. package/lib/cjs/locale/es-ES.js +1 -1
  6. package/lib/cjs/locale/fa-IR.js +1 -1
  7. package/lib/cjs/locale/fr-FR.js +1 -1
  8. package/lib/cjs/locale/ja-JP.js +1 -1
  9. package/lib/cjs/locale/ko-KR.js +1 -1
  10. package/lib/cjs/locale/ru-RU.js +1 -1
  11. package/lib/cjs/locale/sk-SK.js +1 -1
  12. package/lib/cjs/locale/vi-VN.js +1 -1
  13. package/lib/cjs/locale/zh-CN.js +1 -1
  14. package/lib/cjs/locale/zh-TW.js +1 -1
  15. package/lib/es/facade.js +1 -1389
  16. package/lib/es/index.js +7 -4388
  17. package/lib/es/locale/ca-ES.js +1 -54
  18. package/lib/es/locale/en-US.js +1 -54
  19. package/lib/es/locale/es-ES.js +1 -54
  20. package/lib/es/locale/fa-IR.js +1 -54
  21. package/lib/es/locale/fr-FR.js +1 -54
  22. package/lib/es/locale/ja-JP.js +1 -54
  23. package/lib/es/locale/ko-KR.js +1 -54
  24. package/lib/es/locale/ru-RU.js +1 -54
  25. package/lib/es/locale/sk-SK.js +1 -54
  26. package/lib/es/locale/vi-VN.js +1 -54
  27. package/lib/es/locale/zh-CN.js +1 -54
  28. package/lib/es/locale/zh-TW.js +1 -54
  29. package/lib/facade.js +1 -1389
  30. package/lib/index.css +66 -1
  31. package/lib/index.js +7 -4388
  32. package/lib/locale/ca-ES.js +1 -54
  33. package/lib/locale/en-US.js +1 -54
  34. package/lib/locale/es-ES.js +1 -54
  35. package/lib/locale/fa-IR.js +1 -54
  36. package/lib/locale/fr-FR.js +1 -54
  37. package/lib/locale/ja-JP.js +1 -54
  38. package/lib/locale/ko-KR.js +1 -54
  39. package/lib/locale/ru-RU.js +1 -54
  40. package/lib/locale/sk-SK.js +1 -54
  41. package/lib/locale/vi-VN.js +1 -54
  42. package/lib/locale/zh-CN.js +1 -54
  43. package/lib/locale/zh-TW.js +1 -54
  44. package/lib/types/basics/transform-position.d.ts +18 -3
  45. package/lib/types/commands/commands/delete-drawings.command.d.ts +16 -1
  46. package/lib/types/commands/commands/flip-drawings.command.d.ts +16 -1
  47. package/lib/types/commands/commands/group-sheet-drawing.command.d.ts +16 -1
  48. package/lib/types/commands/commands/insert-image.command.d.ts +16 -1
  49. package/lib/types/commands/commands/insert-sheet-drawing.command.d.ts +16 -1
  50. package/lib/types/commands/commands/interfaces.d.ts +17 -2
  51. package/lib/types/commands/commands/move-drawings.command.d.ts +17 -1
  52. package/lib/types/commands/commands/remove-sheet-drawing.command.d.ts +16 -1
  53. package/lib/types/commands/commands/save-cell-images.command.d.ts +16 -1
  54. package/lib/types/commands/commands/set-drawing-arrange.command.d.ts +18 -2
  55. package/lib/types/commands/commands/set-sheet-drawing.command.d.ts +16 -1
  56. package/lib/types/commands/commands/ungroup-sheet-drawing.command.d.ts +16 -1
  57. package/lib/types/commands/commands/utils.d.ts +23 -1
  58. package/lib/types/commands/operations/clear-drawing-transformer.operation.d.ts +16 -1
  59. package/lib/types/commands/operations/edit-sheet-drawing.operation.d.ts +16 -1
  60. package/lib/types/commands/operations/open-drawing-panel.operation.d.ts +16 -1
  61. package/lib/types/config/config.d.ts +17 -2
  62. package/lib/types/controllers/drawing-context-menu.controller.d.ts +28 -0
  63. package/lib/types/controllers/render-controllers/sheet-celll-image-hover.render-controller.d.ts +16 -1
  64. package/lib/types/controllers/render-controllers/sheet-drawing.render-controller.d.ts +16 -1
  65. package/lib/types/controllers/sheet-cell-image-autofill.controller.d.ts +15 -0
  66. package/lib/types/controllers/sheet-cell-image-copy-paste.controller.d.ts +15 -0
  67. package/lib/types/controllers/sheet-cell-image.controller.d.ts +19 -2
  68. package/lib/types/controllers/sheet-drawing-copy-paste.controller.d.ts +15 -0
  69. package/lib/types/controllers/sheet-drawing-group-copy-paste.controller.d.ts +54 -0
  70. package/lib/types/controllers/sheet-drawing-permission.controller.d.ts +15 -0
  71. package/lib/types/controllers/sheet-drawing-printing.controller.d.ts +15 -0
  72. package/lib/types/controllers/sheet-drawing-transform-affected.controller.d.ts +19 -2
  73. package/lib/types/controllers/sheet-drawing-update.controller.d.ts +20 -3
  74. package/lib/types/controllers/sheet-drawing.controller.d.ts +15 -0
  75. package/lib/types/controllers/shortcuts/drawing.shortcut.d.ts +18 -3
  76. package/lib/types/facade/f-enum.d.ts +15 -0
  77. package/lib/types/facade/f-event.d.ts +21 -5
  78. package/lib/types/facade/f-over-grid-image.d.ts +19 -3
  79. package/lib/types/facade/f-range.d.ts +15 -0
  80. package/lib/types/facade/f-univer.d.ts +16 -1
  81. package/lib/types/facade/f-worksheet.d.ts +23 -7
  82. package/lib/types/index.d.ts +1 -0
  83. package/lib/types/locale/ca-ES.d.ts +16 -1
  84. package/lib/types/locale/es-ES.d.ts +16 -1
  85. package/lib/types/locale/fa-IR.d.ts +16 -1
  86. package/lib/types/locale/fr-FR.d.ts +16 -1
  87. package/lib/types/locale/ja-JP.d.ts +16 -1
  88. package/lib/types/locale/ko-KR.d.ts +16 -1
  89. package/lib/types/locale/ru-RU.d.ts +16 -1
  90. package/lib/types/locale/sk-SK.d.ts +16 -1
  91. package/lib/types/locale/vi-VN.d.ts +16 -1
  92. package/lib/types/locale/zh-CN.d.ts +16 -1
  93. package/lib/types/locale/zh-TW.d.ts +16 -1
  94. package/lib/types/menu/drawing-popup-menu.controller.d.ts +17 -1
  95. package/lib/types/menu/image.menu.d.ts +17 -2
  96. package/lib/types/menu/save-images.menu.d.ts +17 -2
  97. package/lib/types/menu/schema.d.ts +16 -1
  98. package/lib/types/plugin.d.ts +16 -1
  99. package/lib/types/services/batch-save-images.service.d.ts +18 -2
  100. package/lib/types/services/canvas-float-dom-manager.service.d.ts +24 -6
  101. package/lib/types/views/printing-float-dom/index.d.ts +18 -3
  102. package/lib/types/views/sheet-image-panel/SheetDrawingAnchor.d.ts +16 -1
  103. package/lib/umd/facade.js +1 -1
  104. package/lib/umd/index.js +7 -2
  105. package/lib/umd/locale/ca-ES.js +1 -1
  106. package/lib/umd/locale/en-US.js +1 -1
  107. package/lib/umd/locale/es-ES.js +1 -1
  108. package/lib/umd/locale/fa-IR.js +1 -1
  109. package/lib/umd/locale/fr-FR.js +1 -1
  110. package/lib/umd/locale/ja-JP.js +1 -1
  111. package/lib/umd/locale/ko-KR.js +1 -1
  112. package/lib/umd/locale/ru-RU.js +1 -1
  113. package/lib/umd/locale/sk-SK.js +1 -1
  114. package/lib/umd/locale/vi-VN.js +1 -1
  115. package/lib/umd/locale/zh-CN.js +1 -1
  116. package/lib/umd/locale/zh-TW.js +1 -1
  117. package/package.json +17 -16
package/lib/es/facade.js CHANGED
@@ -1,1389 +1 @@
1
- var Z = Object.defineProperty;
2
- var ee = (s, r, t) => r in s ? Z(s, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[r] = t;
3
- var P = (s, r, t) => ee(s, typeof r != "symbol" ? r + "" : r, t);
4
- import { Inject as N, Injector as K, ICommandService as z, ImageSourceType as O, ArrangeTypeEnum as F, DrawingTypeEnum as _, generateRandomId as te, toDisposable as x, CanceledError as k, IURLImageService as re, UniverInstanceType as ie, IUniverInstanceService as ne } from "@univerjs/core";
5
- import { FBase as se, FEnum as X, FEventName as Y, FUniver as $ } from "@univerjs/core/facade";
6
- import { getImageSize as oe, IDrawingManagerService as S, SetDrawingSelectedOperation as j } from "@univerjs/drawing";
7
- import { IRenderManagerService as C, getCurrentTypeOfRenderer as ae } from "@univerjs/engine-render";
8
- import { RemoveSheetDrawingCommand as E, SetSheetDrawingCommand as u, transformToAxisAlignPosition as A, SetDrawingArrangeCommand as T, SheetCanvasFloatDomManagerService as D, transformToDrawingPosition as H, InsertSheetDrawingCommand as b, IBatchSaveImagesService as V, FileNamePart as y, SheetDrawingUpdateController as de } from "@univerjs/sheets-drawing-ui";
9
- import { ISheetSelectionRenderService as B, SheetSkeletonManagerService as L, convertPositionSheetOverGridToAbsolute as ce, convertPositionCellToSheetOverGrid as ge } from "@univerjs/sheets-ui";
10
- import { ISheetDrawingService as I, SheetDrawingAnchorType as me } from "@univerjs/sheets-drawing";
11
- import { transformComponentKey as G } from "@univerjs/sheets-ui/facade";
12
- import { FWorksheet as q, FRange as J } from "@univerjs/sheets/facade";
13
- import { ComponentManager as W } from "@univerjs/ui";
14
- var he = Object.getOwnPropertyDescriptor, Q = (s, r, t, e) => {
15
- for (var i = e > 1 ? void 0 : e ? he(r, t) : r, n = s.length - 1, o; n >= 0; n--)
16
- (o = s[n]) && (i = o(i) || i);
17
- return i;
18
- }, M = (s, r) => (t, e) => r(t, e, s);
19
- function le(s, r) {
20
- const { from: t, to: e, flipY: i = !1, flipX: n = !1, angle: o = 0, skewX: d = 0, skewY: a = 0 } = s.sheetTransform, { column: g, columnOffset: c, row: m, rowOffset: h } = t, f = ce(
21
- s.unitId,
22
- s.subUnitId,
23
- { from: t, to: e },
24
- r
25
- ), { width: w, height: l } = f;
26
- return {
27
- ...s,
28
- column: g,
29
- columnOffset: c,
30
- row: m,
31
- rowOffset: h,
32
- width: w,
33
- height: l,
34
- flipY: i,
35
- flipX: n,
36
- angle: o,
37
- skewX: d,
38
- skewY: a
39
- };
40
- }
41
- function ue(s, r, t) {
42
- const { column: e, columnOffset: i, row: n, rowOffset: o, flipY: d = !1, flipX: a = !1, angle: g = 0, skewX: c = 0, skewY: m = 0, width: h, height: f } = s, w = ge(
43
- s.unitId,
44
- s.subUnitId,
45
- { column: e, columnOffset: i, row: n, rowOffset: o },
46
- h,
47
- f,
48
- r,
49
- t
50
- ), { sheetTransform: l, transform: p } = w;
51
- return {
52
- ...s,
53
- sheetTransform: {
54
- ...l,
55
- flipY: d,
56
- flipX: a,
57
- angle: g,
58
- skewX: c,
59
- skewY: m
60
- },
61
- transform: {
62
- ...p,
63
- flipY: d,
64
- flipX: a,
65
- angle: g,
66
- skewX: c,
67
- skewY: m
68
- },
69
- axisAlignSheetTransform: A(p, r)
70
- };
71
- }
72
- let U = class {
73
- constructor(s, r, t) {
74
- P(this, "_image");
75
- this._injector = t, this._image = {
76
- drawingId: te(6),
77
- drawingType: _.DRAWING_IMAGE,
78
- imageSourceType: O.BASE64,
79
- source: "",
80
- unitId: s,
81
- subUnitId: r,
82
- column: 0,
83
- columnOffset: 0,
84
- row: 0,
85
- rowOffset: 0,
86
- width: 0,
87
- height: 0,
88
- axisAlignSheetTransform: {
89
- from: {
90
- column: 0,
91
- columnOffset: 0,
92
- row: 0,
93
- rowOffset: 0
94
- },
95
- to: {
96
- column: 0,
97
- columnOffset: 0,
98
- row: 0,
99
- rowOffset: 0
100
- }
101
- }
102
- };
103
- }
104
- /**
105
- * Set the initial image configuration for the image builder.
106
- * @param {ISheetImage} image - The image configuration
107
- * @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
108
- * @example
109
- * ```ts
110
- * // create a new image builder and set initial image configuration.
111
- * // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell.
112
- * const fWorkbook = univerAPI.getActiveWorkbook();
113
- * const fWorksheet = fWorkbook.getActiveSheet();
114
- * const image = await fWorksheet.newOverGridImage()
115
- * .setImage({
116
- * drawingId: '123456',
117
- * drawingType: univerAPI.Enum.DrawingType.DRAWING_IMAGE,
118
- * imageSourceType: univerAPI.Enum.ImageSourceType.BASE64,
119
- * source: 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4',
120
- * unitId: fWorkbook.getId(),
121
- * subUnitId: fWorksheet.getSheetId(),
122
- * })
123
- * .setColumn(5)
124
- * .setRow(5)
125
- * .buildAsync();
126
- * fWorksheet.insertImages([image]);
127
- * ```
128
- */
129
- setImage(s) {
130
- const t = this._injector.get(C).getRenderById(s.unitId);
131
- if (!t)
132
- throw new Error(`Render Unit with unitId ${s.unitId} not found`);
133
- const e = t.with(L);
134
- return s.sheetTransform == null && (s.sheetTransform = {
135
- from: {
136
- column: 0,
137
- columnOffset: 0,
138
- row: 0,
139
- rowOffset: 0
140
- },
141
- to: {
142
- column: 0,
143
- columnOffset: 0,
144
- row: 0,
145
- rowOffset: 0
146
- }
147
- }), s.axisAlignSheetTransform == null && (s.axisAlignSheetTransform = {
148
- from: {
149
- column: 0,
150
- columnOffset: 0,
151
- row: 0,
152
- rowOffset: 0
153
- },
154
- to: {
155
- column: 0,
156
- columnOffset: 0,
157
- row: 0,
158
- rowOffset: 0
159
- }
160
- }), this._image = le(s, e), this;
161
- }
162
- setSource(s, r) {
163
- const t = r != null ? r : O.URL;
164
- return this._image.source = s, this._image.imageSourceType = t, this;
165
- }
166
- /**
167
- * Get the source of the image
168
- * @returns {string} The source of the image
169
- * @example
170
- * ```ts
171
- * const fWorkbook = univerAPI.getActiveWorkbook();
172
- * const fWorksheet = fWorkbook.getActiveSheet();
173
- * const images = fWorksheet.getImages();
174
- * images.forEach((image) => {
175
- * console.log(image, image.toBuilder().getSource());
176
- * });
177
- * ```
178
- */
179
- getSource() {
180
- return this._image.source;
181
- }
182
- /**
183
- * Get the source type of the image
184
- * @returns {ImageSourceType} The source type of the image
185
- * @example
186
- * ```ts
187
- * const fWorkbook = univerAPI.getActiveWorkbook();
188
- * const fWorksheet = fWorkbook.getActiveSheet();
189
- * const images = fWorksheet.getImages();
190
- * images.forEach((image) => {
191
- * console.log(image, image.toBuilder().getSourceType());
192
- * });
193
- * ```
194
- */
195
- getSourceType() {
196
- return this._image.imageSourceType;
197
- }
198
- /**
199
- * Set the horizontal position of the image
200
- * @param {number} column - The column index of the image start position, start at 0
201
- * @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
202
- * @example
203
- * ```ts
204
- * // create a new image builder and set image source.
205
- * // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell.
206
- * const fWorkbook = univerAPI.getActiveWorkbook();
207
- * const fWorksheet = fWorkbook.getActiveSheet();
208
- * const image = await fWorksheet.newOverGridImage()
209
- * .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
210
- * .setColumn(5)
211
- * .setRow(5)
212
- * .buildAsync();
213
- * fWorksheet.insertImages([image]);
214
- * ```
215
- */
216
- setColumn(s) {
217
- return this._image.column = s, this;
218
- }
219
- /**
220
- * Set the vertical position of the image
221
- * @param {number} row - The row index of the image start position, start at 0
222
- * @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
223
- * @example
224
- * ```ts
225
- * // create a new image builder and set image source.
226
- * // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell.
227
- * const fWorkbook = univerAPI.getActiveWorkbook();
228
- * const fWorksheet = fWorkbook.getActiveSheet();
229
- * const image = await fWorksheet.newOverGridImage()
230
- * .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
231
- * .setColumn(5)
232
- * .setRow(5)
233
- * .buildAsync();
234
- * fWorksheet.insertImages([image]);
235
- * ```
236
- */
237
- setRow(s) {
238
- return this._image.row = s, this;
239
- }
240
- /**
241
- * Set the horizontal offset of the image
242
- * @param {number} offset - The column offset of the image start position, pixel unit
243
- * @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
244
- * @example
245
- * ```ts
246
- * // create a new image builder and set image source.
247
- * // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell and horizontal offset is 10px.
248
- * const fWorkbook = univerAPI.getActiveWorkbook();
249
- * const fWorksheet = fWorkbook.getActiveSheet();
250
- * const image = await fWorksheet.newOverGridImage()
251
- * .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
252
- * .setColumn(5)
253
- * .setRow(5)
254
- * .setColumnOffset(10)
255
- * .buildAsync();
256
- * fWorksheet.insertImages([image]);
257
- * ```
258
- */
259
- setColumnOffset(s) {
260
- return this._image.columnOffset = s, this;
261
- }
262
- /**
263
- * Set the vertical offset of the image
264
- * @param {number} offset - The row offset of the image start position, pixel unit
265
- * @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
266
- * @example
267
- * ```ts
268
- * // create a new image builder and set image source.
269
- * // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell and vertical offset is 10px.
270
- * const fWorkbook = univerAPI.getActiveWorkbook();
271
- * const fWorksheet = fWorkbook.getActiveSheet();
272
- * const image = await fWorksheet.newOverGridImage()
273
- * .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
274
- * .setColumn(5)
275
- * .setRow(5)
276
- * .setRowOffset(10)
277
- * .buildAsync();
278
- * fWorksheet.insertImages([image]);
279
- * ```
280
- */
281
- setRowOffset(s) {
282
- return this._image.rowOffset = s, this;
283
- }
284
- /**
285
- * Set the width of the image
286
- * @param {number} width - The width of the image, pixel unit
287
- * @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
288
- * @example
289
- * ```ts
290
- * // create a new image builder and set image source.
291
- * // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, width is 120px and height is 50px.
292
- * const fWorkbook = univerAPI.getActiveWorkbook();
293
- * const fWorksheet = fWorkbook.getActiveSheet();
294
- * const image = await fWorksheet.newOverGridImage()
295
- * .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
296
- * .setColumn(5)
297
- * .setRow(5)
298
- * .setWidth(120)
299
- * .setHeight(50)
300
- * .buildAsync();
301
- * fWorksheet.insertImages([image]);
302
- * ```
303
- */
304
- setWidth(s) {
305
- return this._image.width = s, this;
306
- }
307
- /**
308
- * Set the height of the image
309
- * @param {number} height - The height of the image, pixel unit
310
- * @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
311
- * @example
312
- * ```ts
313
- * // create a new image builder and set image source.
314
- * // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, width is 120px and height is 50px.
315
- * const fWorkbook = univerAPI.getActiveWorkbook();
316
- * const fWorksheet = fWorkbook.getActiveSheet();
317
- * const image = await fWorksheet.newOverGridImage()
318
- * .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
319
- * .setColumn(5)
320
- * .setRow(5)
321
- * .setWidth(120)
322
- * .setHeight(50)
323
- * .buildAsync();
324
- * fWorksheet.insertImages([image]);
325
- * ```
326
- */
327
- setHeight(s) {
328
- return this._image.height = s, this;
329
- }
330
- /**
331
- * Set the anchor type of the image, whether the position and size change with the cell
332
- * @param {SheetDrawingAnchorType} anchorType - The anchor type of the image
333
- * @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
334
- * @example
335
- * ```ts
336
- * const fWorkbook = univerAPI.getActiveWorkbook();
337
- * const fWorksheet = fWorkbook.getActiveSheet();
338
- *
339
- * // image1 position is start from A6 cell, anchor type is Position.
340
- * // Only the position of the drawing follows the cell changes. When rows or columns are inserted or deleted, the position of the drawing changes, but the size remains the same.
341
- * const image1 = await fWorksheet.newOverGridImage()
342
- * .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
343
- * .setColumn(0)
344
- * .setRow(5)
345
- * .setAnchorType(univerAPI.Enum.SheetDrawingAnchorType.Position)
346
- * .buildAsync();
347
- *
348
- * // image2 position is start from C6 cell, anchor type is Both.
349
- * // The size and position of the drawing follow the cell changes. When rows or columns are inserted or deleted, the size and position of the drawing change accordingly.
350
- * const image2 = await fWorksheet.newOverGridImage()
351
- * .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
352
- * .setColumn(2)
353
- * .setRow(5)
354
- * .setAnchorType(univerAPI.Enum.SheetDrawingAnchorType.Both)
355
- * .buildAsync();
356
- *
357
- * // image3 position is start from E6 cell, anchor type is None.
358
- * // The size and position of the drawing do not follow the cell changes. When rows or columns are inserted or deleted, the position and size of the drawing remain unchanged.
359
- * const image3 = await fWorksheet.newOverGridImage()
360
- * .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
361
- * .setColumn(4)
362
- * .setRow(5)
363
- * .setAnchorType(univerAPI.Enum.SheetDrawingAnchorType.None)
364
- * .buildAsync();
365
- *
366
- * // insert images into the sheet
367
- * fWorksheet.insertImages([image1, image2, image3]);
368
- *
369
- * // after 2 seconds, set the row height of the 5th row to 100px and insert a row before the 5th row.
370
- * // then observe the position and size changes of the images.
371
- * setTimeout(() => {
372
- * fWorksheet.setRowHeight(5, 100).insertRowBefore(5);
373
- * }, 2000);
374
- * ```
375
- */
376
- setAnchorType(s) {
377
- return this._image.anchorType = s, this;
378
- }
379
- /**
380
- * Set the cropping region of the image by defining the top edges, thereby displaying the specific part of the image you want.
381
- * @param {number} top - The number of pixels to crop from the top of the image
382
- * @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
383
- * @example
384
- * ```ts
385
- * // create a new image builder and set image source.
386
- * // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, top crop is 10px.
387
- * const fWorkbook = univerAPI.getActiveWorkbook();
388
- * const fWorksheet = fWorkbook.getActiveSheet();
389
- * const image = await fWorksheet.newOverGridImage()
390
- * .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
391
- * .setColumn(5)
392
- * .setRow(5)
393
- * .setCropTop(10)
394
- * .buildAsync();
395
- * fWorksheet.insertImages([image]);
396
- * ```
397
- */
398
- setCropTop(s) {
399
- return this._initializeSrcRect(), this._image.srcRect.top = s, this;
400
- }
401
- /**
402
- * Set the cropping region of the image by defining the left edges, thereby displaying the specific part of the image you want.
403
- * @param {number} left - The number of pixels to crop from the left side of the image
404
- * @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
405
- * @example
406
- * ```ts
407
- * // create a new image builder and set image source.
408
- * // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, left crop is 10px.
409
- * const fWorkbook = univerAPI.getActiveWorkbook();
410
- * const fWorksheet = fWorkbook.getActiveSheet();
411
- * const image = await fWorksheet.newOverGridImage()
412
- * .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
413
- * .setColumn(5)
414
- * .setRow(5)
415
- * .setCropLeft(10)
416
- * .buildAsync();
417
- * fWorksheet.insertImages([image]);
418
- * ```
419
- */
420
- setCropLeft(s) {
421
- return this._initializeSrcRect(), this._image.srcRect.left = s, this;
422
- }
423
- /**
424
- * Set the cropping region of the image by defining the bottom edges, thereby displaying the specific part of the image you want.
425
- * @param {number} bottom - The number of pixels to crop from the bottom of the image
426
- * @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
427
- * @example
428
- * ```ts
429
- * // create a new image builder and set image source.
430
- * // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, bottom crop is 10px.
431
- * const fWorkbook = univerAPI.getActiveWorkbook();
432
- * const fWorksheet = fWorkbook.getActiveSheet();
433
- * const image = await fWorksheet.newOverGridImage()
434
- * .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
435
- * .setColumn(5)
436
- * .setRow(5)
437
- * .setCropBottom(10)
438
- * .buildAsync();
439
- * fWorksheet.insertImages([image]);
440
- * ```
441
- */
442
- setCropBottom(s) {
443
- return this._initializeSrcRect(), this._image.srcRect.bottom = s, this;
444
- }
445
- /**
446
- * Set the cropping region of the image by defining the right edges, thereby displaying the specific part of the image you want.
447
- * @param {number} right - The number of pixels to crop from the right side of the image
448
- * @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
449
- * @example
450
- * ```ts
451
- * // create a new image builder and set image source.
452
- * // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, right crop is 10px.
453
- * const fWorkbook = univerAPI.getActiveWorkbook();
454
- * const fWorksheet = fWorkbook.getActiveSheet();
455
- * const image = await fWorksheet.newOverGridImage()
456
- * .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
457
- * .setColumn(5)
458
- * .setRow(5)
459
- * .setCropRight(10)
460
- * .buildAsync();
461
- * fWorksheet.insertImages([image]);
462
- * ```
463
- */
464
- setCropRight(s) {
465
- return this._initializeSrcRect(), this._image.srcRect.right = s, this;
466
- }
467
- _initializeSrcRect() {
468
- this._image.srcRect == null && (this._image.srcRect = {
469
- top: 0,
470
- left: 0,
471
- bottom: 0,
472
- right: 0
473
- });
474
- }
475
- /**
476
- * Set the rotation angle of the image
477
- * @param {number} angle - Degree of rotation of the image, for example, 90, 180, 270, etc.
478
- * @returns {FOverGridImageBuilder} The `FOverGridImageBuilder` for chaining
479
- * @example
480
- * ```ts
481
- * // create a new image builder and set image source.
482
- * // then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, rotate 90 degrees.
483
- * const fWorkbook = univerAPI.getActiveWorkbook();
484
- * const fWorksheet = fWorkbook.getActiveSheet();
485
- * const image = await fWorksheet.newOverGridImage()
486
- * .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL)
487
- * .setColumn(5)
488
- * .setRow(5)
489
- * .setRotate(90)
490
- * .buildAsync();
491
- * fWorksheet.insertImages([image]);
492
- * ```
493
- */
494
- setRotate(s) {
495
- return this._image.angle = s, this;
496
- }
497
- setUnitId(s) {
498
- return this._image.unitId = s, this;
499
- }
500
- setSubUnitId(s) {
501
- return this._image.subUnitId = s, this;
502
- }
503
- async buildAsync() {
504
- const r = this._injector.get(C).getRenderById(this._image.unitId);
505
- if (!r)
506
- throw new Error(`Render Unit with unitId ${this._image.unitId} not found`);
507
- const t = r.with(B), e = r.with(L);
508
- if (this._image.width === 0 || this._image.height === 0) {
509
- const i = await oe(this._image.source), n = i.width, o = i.height;
510
- this._image.width === 0 && (this._image.width = n), this._image.height === 0 && (this._image.height = o);
511
- }
512
- return ue(this._image, t, e);
513
- }
514
- };
515
- U = Q([
516
- M(2, N(K))
517
- ], U);
518
- let v = class extends se {
519
- constructor(s, r, t) {
520
- super(), this._image = s, this._commandService = r, this._injector = t;
521
- }
522
- /**
523
- * Get the id of the image
524
- * @returns {string} The id of the image
525
- * @example
526
- * ```ts
527
- * const fWorkbook = univerAPI.getActiveWorkbook();
528
- * const fWorksheet = fWorkbook.getActiveSheet();
529
- * const images = fWorksheet.getImages();
530
- * images.forEach((image) => {
531
- * console.log(image, image.getId());
532
- * });
533
- * ```
534
- */
535
- getId() {
536
- return this._image.drawingId;
537
- }
538
- /**
539
- * Get the drawing type of the image
540
- * @returns {DrawingTypeEnum} The drawing type of the image
541
- * @example
542
- * ```ts
543
- * const fWorkbook = univerAPI.getActiveWorkbook();
544
- * const fWorksheet = fWorkbook.getActiveSheet();
545
- * const images = fWorksheet.getImages();
546
- * images.forEach((image) => {
547
- * console.log(image, image.getType());
548
- * });
549
- * ```
550
- */
551
- getType() {
552
- return this._image.drawingType;
553
- }
554
- /**
555
- * Remove the image from the sheet
556
- * @returns {boolean} true if the image is removed successfully, otherwise false
557
- * @example
558
- * ```ts
559
- * const fWorkbook = univerAPI.getActiveWorkbook();
560
- * const fWorksheet = fWorkbook.getActiveSheet();
561
- * const image = fWorksheet.getImages()[0];
562
- * const result = image?.remove();
563
- * console.log(result);
564
- * ```
565
- */
566
- remove() {
567
- return this._commandService.syncExecuteCommand(E.id, { unitId: this._image.unitId, drawings: [this._image] });
568
- }
569
- /**
570
- * Convert the image to a FOverGridImageBuilder
571
- * @returns {FOverGridImageBuilder} The builder FOverGridImageBuilder
572
- * @example
573
- * ```ts
574
- * const fWorkbook = univerAPI.getActiveWorkbook();
575
- * const fWorksheet = fWorkbook.getActiveSheet();
576
- * const images = fWorksheet.getImages();
577
- * images.forEach((image) => {
578
- * console.log(image, image.toBuilder().getSource());
579
- * });
580
- * ```
581
- */
582
- toBuilder() {
583
- const s = this._injector.createInstance(U);
584
- return s.setImage(this._image), s;
585
- }
586
- setSource(s, r) {
587
- const t = r != null ? r : O.URL;
588
- return this._image.source = s, this._image.imageSourceType = t, this._commandService.syncExecuteCommand(u.id, { unitId: this._image.unitId, drawings: [this._image] });
589
- }
590
- async setPositionAsync(s, r, t, e) {
591
- const i = this.toBuilder();
592
- i.setColumn(r), i.setRow(s), t != null && i.setRowOffset(t), e != null && i.setColumnOffset(e);
593
- const n = await i.buildAsync();
594
- return this._commandService.syncExecuteCommand(u.id, { unitId: this._image.unitId, drawings: [n] });
595
- }
596
- /**
597
- * Set the size of the image
598
- * @param {number} width - The width of the image, pixel unit
599
- * @param {number} height - The height of the image, pixel unit
600
- * @returns {boolean} true if the size is set successfully, otherwise false
601
- * @example
602
- * ```ts
603
- * // set the image width 120px and height 50px
604
- * const fWorkbook = univerAPI.getActiveWorkbook();
605
- * const fWorksheet = fWorkbook.getActiveSheet();
606
- * const image = fWorksheet.getImages()[0];
607
- * const result = image?.setSizeAsync(120, 50);
608
- * console.log(result);
609
- * ```
610
- */
611
- async setSizeAsync(s, r) {
612
- const t = this.toBuilder();
613
- t.setWidth(s), t.setHeight(r);
614
- const e = await t.buildAsync();
615
- return this._commandService.syncExecuteCommand(u.id, { unitId: this._image.unitId, drawings: [e] });
616
- }
617
- /**
618
- * Set the cropping region of the image by defining the top, bottom, left, and right edges, thereby displaying the specific part of the image you want.
619
- * @param {number} top - The number of pixels to crop from the top of the image
620
- * @param {number} left - The number of pixels to crop from the left side of the image
621
- * @param {number} bottom - The number of pixels to crop from the bottom of the image
622
- * @param {number} right - The number of pixels to crop from the right side of the image
623
- * @returns {boolean} true if the crop is set successfully, otherwise false
624
- * @example
625
- * ```ts
626
- * // set the crop of the image, top 10px, left 10px, bottom 10px, right 10px.
627
- * const fWorkbook = univerAPI.getActiveWorkbook();
628
- * const fWorksheet = fWorkbook.getActiveSheet();
629
- * const image = fWorksheet.getImages()[0];
630
- * const result = image?.setCrop(10, 10, 10, 10);
631
- * console.log(result);
632
- * ```
633
- */
634
- setCrop(s, r, t, e) {
635
- return this._image.srcRect == null && (this._image.srcRect = {
636
- top: 0,
637
- left: 0,
638
- bottom: 0,
639
- right: 0
640
- }), s != null && (this._image.srcRect.top = s), r != null && (this._image.srcRect.left = r), t != null && (this._image.srcRect.bottom = t), e != null && (this._image.srcRect.right = e), this._commandService.syncExecuteCommand(u.id, { unitId: this._image.unitId, drawings: [this._image] });
641
- }
642
- /**
643
- * Set the rotation angle of the image
644
- * @param {number} angle - Degree of rotation of the image, for example, 90, 180, 270, etc.
645
- * @returns {boolean} true if the rotation is set successfully, otherwise false
646
- * @example
647
- * ```ts
648
- * // set 90 degrees rotation of the image
649
- * const fWorkbook = univerAPI.getActiveWorkbook();
650
- * const fWorksheet = fWorkbook.getActiveSheet();
651
- * const image = fWorksheet.getImages()[0];
652
- * const result = image?.setRotate(90);
653
- * console.log(result);
654
- * ```
655
- */
656
- setRotate(s) {
657
- if (this._image.sheetTransform.angle = s, this._image.transform && (this._image.transform.angle = s), this._image.transform) {
658
- const t = this._injector.get(C).getRenderById(this._image.unitId);
659
- if (!t)
660
- throw new Error(`Render Unit with unitId ${this._image.unitId} not found`);
661
- const e = t.with(B);
662
- this._image.axisAlignSheetTransform && (this._image.axisAlignSheetTransform = A(this._image.transform, e));
663
- }
664
- return this._commandService.syncExecuteCommand(u.id, { unitId: this._image.unitId, drawings: [this._image] });
665
- }
666
- /**
667
- * Move the image layer forward by one level
668
- * @returns {boolean} true if the image is moved forward successfully, otherwise false
669
- * @example
670
- * ```ts
671
- * const fWorkbook = univerAPI.getActiveWorkbook();
672
- * const fWorksheet = fWorkbook.getActiveSheet();
673
- * const image = fWorksheet.getImages()[0];
674
- * const result = image?.setForward();
675
- * console.log(result);
676
- * ```
677
- */
678
- setForward() {
679
- return this._commandService.syncExecuteCommand(T.id, {
680
- unitId: this._image.unitId,
681
- subUnitId: this._image.subUnitId,
682
- drawingIds: [this._image.drawingId],
683
- arrangeType: F.forward
684
- });
685
- }
686
- /**
687
- * Move the image layer backward by one level
688
- * @returns {boolean} true if the image is moved backward successfully, otherwise false
689
- * @example
690
- * ```ts
691
- * const fWorkbook = univerAPI.getActiveWorkbook();
692
- * const fWorksheet = fWorkbook.getActiveSheet();
693
- * const image = fWorksheet.getImages()[0];
694
- * const result = image?.setBackward();
695
- * console.log(result);
696
- * ```
697
- */
698
- setBackward() {
699
- return this._commandService.syncExecuteCommand(T.id, {
700
- unitId: this._image.unitId,
701
- subUnitId: this._image.subUnitId,
702
- drawingIds: [this._image.drawingId],
703
- arrangeType: F.backward
704
- });
705
- }
706
- /**
707
- * Move the image layer to the bottom layer
708
- * @returns {boolean} true if the image is moved to the bottom layer successfully, otherwise false
709
- * @example
710
- * ```ts
711
- * const fWorkbook = univerAPI.getActiveWorkbook();
712
- * const fWorksheet = fWorkbook.getActiveSheet();
713
- * const image = fWorksheet.getImages()[0];
714
- * const result = image?.setBack();
715
- * console.log(result);
716
- * ```
717
- */
718
- setBack() {
719
- return this._commandService.syncExecuteCommand(T.id, {
720
- unitId: this._image.unitId,
721
- subUnitId: this._image.subUnitId,
722
- drawingIds: [this._image.drawingId],
723
- arrangeType: F.back
724
- });
725
- }
726
- /**
727
- * Move the image layer to the top layer
728
- * @returns {boolean} true if the image is moved to the top layer successfully, otherwise false
729
- * @example
730
- * ```ts
731
- * const fWorkbook = univerAPI.getActiveWorkbook();
732
- * const fWorksheet = fWorkbook.getActiveSheet();
733
- * const image = fWorksheet.getImages()[0];
734
- * const result = image?.setFront();
735
- * console.log(result);
736
- * ```
737
- */
738
- setFront() {
739
- return this._commandService.syncExecuteCommand(T.id, {
740
- unitId: this._image.unitId,
741
- subUnitId: this._image.subUnitId,
742
- drawingIds: [this._image.drawingId],
743
- arrangeType: F.front
744
- });
745
- }
746
- };
747
- v = Q([
748
- M(1, z),
749
- M(2, N(K))
750
- ], v);
751
- class fe extends q {
752
- getFloatDomById(r) {
753
- const e = this._injector.get(D).getFloatDomInfo(r);
754
- if (!e) return null;
755
- const { unitId: i, subUnitId: n } = e, { rect: o } = e, d = o.getState(), { left: a = 0, top: g = 0, width: c = 0, height: m = 0, flipX: h = !1, flipY: f = !1, angle: w = 0, skewX: l = 0, skewY: p = 0 } = d, R = this._injector.get(I).getDrawingByParam({
756
- drawingId: e.id,
757
- unitId: i,
758
- subUnitId: n
759
- });
760
- return R ? {
761
- position: {
762
- left: a,
763
- top: g,
764
- width: c,
765
- height: m,
766
- flipX: h,
767
- flipY: f,
768
- angle: w,
769
- skewX: l,
770
- skewY: p
771
- },
772
- componentKey: R.componentKey,
773
- allowTransform: R.allowTransform,
774
- data: R.data,
775
- id: e.id
776
- } : null;
777
- }
778
- getAllFloatDoms() {
779
- const r = this._injector.get(D), t = this._workbook.getUnitId(), e = this._worksheet.getSheetId();
780
- return Array.from(r.getFloatDomsBySubUnitId(t, e).values()).map((i) => {
781
- const { rect: n } = i, o = this._injector.get(I).getDrawingByParam({
782
- drawingId: i.id,
783
- unitId: t,
784
- subUnitId: e
785
- }), { left: d, top: a, width: g, height: c, flipX: m, flipY: h, angle: f, skewX: w, skewY: l } = n.getState();
786
- return {
787
- position: {
788
- left: d,
789
- top: a,
790
- width: g,
791
- height: c,
792
- flipX: m,
793
- flipY: h,
794
- angle: f,
795
- skewX: w,
796
- skewY: l
797
- },
798
- componentKey: o.componentKey,
799
- allowTransform: o.allowTransform,
800
- data: o.data,
801
- id: i.id
802
- };
803
- });
804
- }
805
- updateFloatDom(r, t) {
806
- var w, l, p;
807
- const i = this._injector.get(D).getFloatDomInfo(r);
808
- if (!i) return this;
809
- const { unitId: n, subUnitId: o } = i, d = this._injector.get(I).getDrawingByParam({
810
- unitId: n,
811
- subUnitId: o,
812
- drawingId: r
813
- }), a = this._injector.get(C);
814
- if (!a.getRenderById(n)) return this;
815
- if (!this.getSkeleton()) return this;
816
- const m = (w = a.getRenderById(this.getWorkbook().getUnitId())) == null ? void 0 : w.with(B);
817
- if (!m) return this;
818
- const h = {
819
- ...d,
820
- componentKey: t.componentKey || d.componentKey,
821
- allowTransform: t.allowTransform !== void 0 ? t.allowTransform : d.allowTransform,
822
- data: t.data || d.data,
823
- sheetTransform: t.position && (l = H(
824
- t.position,
825
- m
826
- )) != null ? l : d.sheetTransform,
827
- transform: {
828
- ...d.transform,
829
- ...t.position
830
- // Merge with existing transform
831
- },
832
- axisAlignSheetTransform: t.position && (p = A(
833
- t.position,
834
- m
835
- )) != null ? p : d.sheetTransform
836
- };
837
- if (!this._commandService.syncExecuteCommand(u.id, { unitId: n, subUnitId: o, drawings: [h] }))
838
- throw new Error("updateFloatDom failed");
839
- return this;
840
- }
841
- batchUpdateFloatDoms(r) {
842
- var o, d;
843
- const t = this._injector.get(D), e = this._injector.get(I), i = this._injector.get(C), n = [];
844
- for (const a of r) {
845
- const g = t.getFloatDomInfo(a.id);
846
- if (!g) continue;
847
- const { unitId: c, subUnitId: m } = g, h = e.getDrawingByParam({
848
- unitId: c,
849
- subUnitId: m,
850
- drawingId: a.id
851
- });
852
- if (!h) continue;
853
- const f = i.getRenderById(c);
854
- if (!f || !this.getSkeleton()) continue;
855
- const l = f.with(B);
856
- if (!l) return this;
857
- const p = {
858
- ...h,
859
- componentKey: a.config.componentKey || h.componentKey,
860
- allowTransform: a.config.allowTransform !== void 0 ? a.config.allowTransform : h.allowTransform,
861
- data: a.config.data || h.data,
862
- sheetTransform: a.config.position && (o = H(
863
- a.config.position,
864
- l
865
- )) != null ? o : h.sheetTransform,
866
- transform: {
867
- ...h.transform,
868
- ...a.config.position
869
- // Merge with existing transform
870
- },
871
- axisAlignSheetTransform: a.config.position && (d = A(
872
- a.config.position,
873
- l
874
- )) != null ? d : h.sheetTransform
875
- };
876
- n.push(p);
877
- }
878
- if (n.length > 0) {
879
- const a = this._workbook.getUnitId(), g = this._worksheet.getSheetId();
880
- if (!this._commandService.syncExecuteCommand(u.id, { unitId: a, subUnitId: g, drawings: n }))
881
- throw new Error("batchUpdateFloatDoms failed");
882
- }
883
- return this;
884
- }
885
- removeFloatDom(r) {
886
- const e = this._injector.get(D).getFloatDomInfo(r);
887
- if (!e) return this;
888
- const { unitId: i, subUnitId: n } = e, d = this._injector.get(I).getDrawingByParam({
889
- unitId: i,
890
- subUnitId: n,
891
- drawingId: r
892
- });
893
- if (!d) return this;
894
- if (!this._commandService.syncExecuteCommand(E.id, {
895
- unitId: i,
896
- drawings: [d]
897
- }))
898
- throw new Error("removeFloatDom failed");
899
- return this;
900
- }
901
- addFloatDomToPosition(r, t) {
902
- const e = this._workbook.getUnitId(), i = this._worksheet.getSheetId(), { key: n, disposableCollection: o } = G(r, this._injector.get(W)), a = this._injector.get(D).addFloatDomToPosition({ ...r, componentKey: n, unitId: e, subUnitId: i }, t);
903
- return a ? (o.add(a.dispose), {
904
- id: a.id,
905
- dispose: () => {
906
- o.dispose(), a.dispose();
907
- }
908
- }) : (o.dispose(), null);
909
- }
910
- addFloatDomToRange(r, t, e, i) {
911
- const n = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), { key: d, disposableCollection: a } = G(t, this._injector.get(W)), c = this._injector.get(D).addFloatDomToRange(r.getRange(), { ...t, componentKey: d, unitId: n, subUnitId: o }, e, i);
912
- return c ? (a.add(c.dispose), {
913
- id: c.id,
914
- dispose: () => {
915
- a.dispose(), c.dispose();
916
- }
917
- }) : (a.dispose(), null);
918
- }
919
- addFloatDomToColumnHeader(r, t, e, i) {
920
- const n = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), { key: d, disposableCollection: a } = G(t, this._injector.get(W)), c = this._injector.get(D).addFloatDomToColumnHeader(r, { ...t, componentKey: d, unitId: n, subUnitId: o }, e, i);
921
- return c ? (a.add(c.dispose), {
922
- id: c.id,
923
- dispose: () => {
924
- a.dispose(), c.dispose();
925
- }
926
- }) : (a.dispose(), null);
927
- }
928
- async insertImage(r, t, e, i, n) {
929
- const o = this.newOverGridImage();
930
- if (typeof r == "string")
931
- o.setSource(r);
932
- else {
933
- const g = await r.getBlob().getDataAsString();
934
- o.setSource(g, O.BASE64);
935
- }
936
- t !== void 0 ? o.setColumn(t) : o.setColumn(0), e !== void 0 ? o.setRow(e) : o.setRow(0), i !== void 0 ? o.setColumnOffset(i) : o.setColumnOffset(0), n !== void 0 ? o.setRowOffset(n) : o.setRowOffset(0);
937
- const d = await o.buildAsync();
938
- return this._commandService.syncExecuteCommand(b.id, { unitId: this._fWorkbook.getId(), drawings: [d] });
939
- }
940
- insertImages(r) {
941
- const t = r.map((e) => (e.unitId = this._fWorkbook.getId(), e.subUnitId = this.getSheetId(), e));
942
- return this._commandService.syncExecuteCommand(b.id, { unitId: this._fWorkbook.getId(), drawings: t }), this;
943
- }
944
- deleteImages(r) {
945
- const t = r.map((e) => ({
946
- unitId: this._fWorkbook.getId(),
947
- drawingId: e.getId(),
948
- subUnitId: this.getSheetId(),
949
- drawingType: e.getType()
950
- }));
951
- return this._commandService.syncExecuteCommand(E.id, { unitId: this._fWorkbook.getId(), drawings: t }), this;
952
- }
953
- getImages() {
954
- const t = this._injector.get(I).getDrawingData(this._fWorkbook.getId(), this.getSheetId()), e = [];
955
- for (const i in t) {
956
- const n = t[i];
957
- n.drawingType === _.DRAWING_IMAGE && e.push(this._injector.createInstance(v, n));
958
- }
959
- return e;
960
- }
961
- getImageById(r) {
962
- const e = this._injector.get(I).getDrawingByParam({ unitId: this._fWorkbook.getId(), subUnitId: this.getSheetId(), drawingId: r });
963
- return e && e.drawingType === _.DRAWING_IMAGE ? this._injector.createInstance(v, e) : null;
964
- }
965
- getActiveImages() {
966
- const t = this._injector.get(I).getFocusDrawings(), e = [];
967
- for (const i in t) {
968
- const n = t[i];
969
- e.push(this._injector.createInstance(v, n));
970
- }
971
- return e;
972
- }
973
- updateImages(r) {
974
- return this._commandService.syncExecuteCommand(u.id, { unitId: this._fWorkbook.getId(), drawings: r }), this;
975
- }
976
- onImageInserted(r) {
977
- const t = this._injector.get(I);
978
- return x(t.add$.subscribe((e) => {
979
- const i = e.map(
980
- (n) => this._injector.createInstance(v, t.getDrawingByParam(n))
981
- );
982
- r(i);
983
- }));
984
- }
985
- onImageDeleted(r) {
986
- const t = this._injector.get(I);
987
- return x(t.remove$.subscribe((e) => {
988
- const i = e.map(
989
- (n) => this._injector.createInstance(v, t.getDrawingByParam(n))
990
- );
991
- r(i);
992
- }));
993
- }
994
- onImageChanged(r) {
995
- const t = this._injector.get(I);
996
- return x(t.update$.subscribe((e) => {
997
- const i = e.map(
998
- (n) => this._injector.createInstance(v, t.getDrawingByParam(n))
999
- );
1000
- r(i);
1001
- }));
1002
- }
1003
- newOverGridImage() {
1004
- const r = this._fWorkbook.getId(), t = this.getSheetId();
1005
- return this._injector.createInstance(U, r, t);
1006
- }
1007
- async saveCellImagesAsync(r, t) {
1008
- var m;
1009
- const e = this._injector.get(V), i = this._fWorkbook.getId(), n = this.getSheetId(), o = t ? t.map((h) => h.getRange()) : [this._worksheet.getCellMatrix().getDataRange()], d = e.getCellImagesFromRanges(i, n, o);
1010
- if (d.length === 0)
1011
- return !1;
1012
- if (d.length === 1)
1013
- try {
1014
- return await e.downloadSingleImage(d[0]), !0;
1015
- } catch (h) {
1016
- return console.error("Failed to download image:", h), !1;
1017
- }
1018
- const a = [], g = (m = r == null ? void 0 : r.useCellAddress) != null ? m : !0, c = r == null ? void 0 : r.useColumnIndex;
1019
- g && a.push(y.CELL_ADDRESS), c !== void 0 && a.push(y.COLUMN_VALUE), a.length === 0 && a.push(y.CELL_ADDRESS);
1020
- try {
1021
- return await e.saveImagesWithContext(d, {
1022
- fileNameParts: a,
1023
- columnIndex: c
1024
- }, i, n), !0;
1025
- } catch (h) {
1026
- return console.error("Failed to save images:", h), !1;
1027
- }
1028
- }
1029
- }
1030
- q.extend(fe);
1031
- class we extends X {
1032
- get DrawingType() {
1033
- return _;
1034
- }
1035
- get ImageSourceType() {
1036
- return O;
1037
- }
1038
- get SheetDrawingAnchorType() {
1039
- return me;
1040
- }
1041
- }
1042
- X.extend(we);
1043
- class Ie extends Y {
1044
- get BeforeFloatDomAdd() {
1045
- return "BeforeFloatDomAdd";
1046
- }
1047
- get FloatDomAdded() {
1048
- return "FloatDomAdded";
1049
- }
1050
- get BeforeFloatDomUpdate() {
1051
- return "BeforeFloatDomUpdate";
1052
- }
1053
- get FloatDomUpdated() {
1054
- return "FloatDomUpdated";
1055
- }
1056
- get BeforeFloatDomDelete() {
1057
- return "BeforeFloatDomDelete";
1058
- }
1059
- get FloatDomDeleted() {
1060
- return "FloatDomDeleted";
1061
- }
1062
- get BeforeOverGridImageChange() {
1063
- return "BeforeOverGridImageChange";
1064
- }
1065
- get OverGridImageChanged() {
1066
- return "OverGridImageChanged";
1067
- }
1068
- get BeforeOverGridImageInsert() {
1069
- return "BeforeOverGridImageInsert";
1070
- }
1071
- get OverGridImageInserted() {
1072
- return "OverGridImageInserted";
1073
- }
1074
- get BeforeOverGridImageRemove() {
1075
- return "BeforeOverGridImageRemove";
1076
- }
1077
- get OverGridImageRemoved() {
1078
- return "OverGridImageRemoved";
1079
- }
1080
- get BeforeOverGridImageSelect() {
1081
- return "BeforeOverGridImageSelect";
1082
- }
1083
- get OverGridImageSelected() {
1084
- return "OverGridImageSelected";
1085
- }
1086
- }
1087
- Y.extend(Ie);
1088
- class ve extends $ {
1089
- /**
1090
- * @ignore
1091
- */
1092
- // eslint-disable-next-line max-lines-per-function
1093
- _initialize(r) {
1094
- const t = r.get(z);
1095
- this.disposeWithMe(
1096
- this.registerEventHandler(
1097
- this.Event.BeforeFloatDomAdd,
1098
- () => t.beforeCommandExecuted((e) => {
1099
- if (e.id !== b.id) return;
1100
- const i = e.params, n = this.getActiveWorkbook();
1101
- if (n == null || i == null)
1102
- return;
1103
- const { drawings: o } = i, d = o.filter(
1104
- (g) => g.drawingType === _.DRAWING_DOM
1105
- );
1106
- if (d.length === 0)
1107
- return;
1108
- const a = {
1109
- workbook: n,
1110
- drawings: d
1111
- };
1112
- if (this.fireEvent(this.Event.BeforeFloatDomAdd, a), a.cancel)
1113
- throw new k();
1114
- })
1115
- )
1116
- ), this.disposeWithMe(
1117
- this.registerEventHandler(
1118
- this.Event.FloatDomAdded,
1119
- () => t.onCommandExecuted((e) => {
1120
- if (e.id !== b.id) return;
1121
- const i = e.params, n = this.getActiveWorkbook();
1122
- if (n == null || i == null)
1123
- return;
1124
- const { drawings: o } = i, d = o.filter(
1125
- (a) => a.drawingType === _.DRAWING_DOM
1126
- );
1127
- d.length !== 0 && this.fireEvent(this.Event.FloatDomAdded, {
1128
- workbook: n,
1129
- drawings: d
1130
- });
1131
- })
1132
- )
1133
- ), this.disposeWithMe(
1134
- this.registerEventHandler(
1135
- this.Event.BeforeOverGridImageInsert,
1136
- () => t.beforeCommandExecuted((e) => {
1137
- if (e.id !== b.id) return;
1138
- const i = e.params, n = this.getActiveWorkbook();
1139
- if (n == null || i == null)
1140
- return;
1141
- const { drawings: o } = i, d = {
1142
- workbook: n,
1143
- insertImageParams: o
1144
- };
1145
- if (this.fireEvent(this.Event.BeforeOverGridImageInsert, d), d.cancel)
1146
- throw new k();
1147
- })
1148
- )
1149
- ), this.disposeWithMe(
1150
- this.registerEventHandler(
1151
- this.Event.BeforeOverGridImageRemove,
1152
- () => t.beforeCommandExecuted((e) => {
1153
- if (e.id !== E.id) return;
1154
- const i = e.params, n = this.getActiveWorkbook();
1155
- if (n == null || i == null)
1156
- return;
1157
- const o = r.get(S), { drawings: d } = i, a = d.map((c) => o.getDrawingByParam(c)), g = {
1158
- workbook: n,
1159
- images: this._createFOverGridImage(a)
1160
- };
1161
- if (this.fireEvent(this.Event.BeforeOverGridImageRemove, g), g.cancel)
1162
- throw new k();
1163
- })
1164
- )
1165
- ), this.disposeWithMe(
1166
- this.registerEventHandler(
1167
- this.Event.BeforeOverGridImageChange,
1168
- () => t.beforeCommandExecuted((e) => {
1169
- if (e.id !== u.id) return;
1170
- const i = e.params, n = this.getActiveWorkbook();
1171
- if (n == null || i == null)
1172
- return;
1173
- const { drawings: o } = i, d = r.get(S), a = [];
1174
- o.forEach((c) => {
1175
- const m = d.getDrawingByParam(c);
1176
- m != null && a.push({
1177
- changeParam: c,
1178
- image: this._injector.createInstance(v, m)
1179
- });
1180
- });
1181
- const g = {
1182
- workbook: n,
1183
- images: a
1184
- };
1185
- if (this.fireEvent(this.Event.BeforeOverGridImageChange, g), g.cancel)
1186
- throw d.updateNotification(o), new k();
1187
- })
1188
- )
1189
- ), this.disposeWithMe(
1190
- this.registerEventHandler(
1191
- this.Event.BeforeFloatDomUpdate,
1192
- () => t.beforeCommandExecuted((e) => {
1193
- if (e.id !== u.id) return;
1194
- const i = e.params, n = this.getActiveWorkbook();
1195
- if (n == null || i == null)
1196
- return;
1197
- const { drawings: o } = i, d = r.get(S), a = [];
1198
- if (o.forEach((c) => {
1199
- const m = d.getDrawingByParam(c);
1200
- (m == null ? void 0 : m.drawingType) === _.DRAWING_DOM && a.push(m);
1201
- }), a.length === 0)
1202
- return;
1203
- const g = {
1204
- workbook: n,
1205
- drawings: a
1206
- };
1207
- if (this.fireEvent(this.Event.BeforeFloatDomUpdate, g), g.cancel)
1208
- throw d.updateNotification(o), new k();
1209
- })
1210
- )
1211
- ), this.disposeWithMe(
1212
- this.registerEventHandler(
1213
- this.Event.FloatDomUpdated,
1214
- () => t.onCommandExecuted((e) => {
1215
- if (e.id !== u.id) return;
1216
- const i = e.params, n = this.getActiveWorkbook();
1217
- if (n == null || i == null)
1218
- return;
1219
- const { drawings: o } = i, d = r.get(S), a = [];
1220
- o.forEach((g) => {
1221
- const c = d.getDrawingByParam(g);
1222
- (c == null ? void 0 : c.drawingType) === _.DRAWING_DOM && a.push(c);
1223
- }), a.length !== 0 && this.fireEvent(this.Event.FloatDomUpdated, {
1224
- workbook: n,
1225
- drawings: a
1226
- });
1227
- })
1228
- )
1229
- ), this.disposeWithMe(
1230
- this.registerEventHandler(
1231
- this.Event.BeforeFloatDomDelete,
1232
- () => t.beforeCommandExecuted((e) => {
1233
- if (e.id !== E.id) return;
1234
- const i = e.params, n = this.getActiveWorkbook();
1235
- if (n == null || i == null)
1236
- return;
1237
- const o = r.get(S), { drawings: d } = i, a = d.map((c) => o.getDrawingByParam(c)).filter(
1238
- (c) => (c == null ? void 0 : c.drawingType) === _.DRAWING_DOM
1239
- );
1240
- if (a.length === 0)
1241
- return;
1242
- const g = {
1243
- workbook: n,
1244
- drawings: a
1245
- };
1246
- if (this.fireEvent(this.Event.BeforeFloatDomDelete, g), g.cancel)
1247
- throw new k();
1248
- })
1249
- )
1250
- ), this.disposeWithMe(
1251
- this.registerEventHandler(
1252
- this.Event.FloatDomDeleted,
1253
- () => t.onCommandExecuted((e) => {
1254
- if (e.id !== E.id) return;
1255
- const i = e.params, n = this.getActiveWorkbook();
1256
- if (n == null || i == null)
1257
- return;
1258
- const { drawings: o } = i;
1259
- this.fireEvent(this.Event.FloatDomDeleted, {
1260
- workbook: n,
1261
- drawings: o.filter((d) => d.drawingType === _.DRAWING_DOM).map((d) => d.drawingId)
1262
- });
1263
- })
1264
- )
1265
- ), this.disposeWithMe(
1266
- this.registerEventHandler(
1267
- this.Event.BeforeOverGridImageSelect,
1268
- () => t.beforeCommandExecuted((e) => {
1269
- if (e.id !== j.id) return;
1270
- const i = e.params, n = this.getActiveWorkbook();
1271
- if (n == null)
1272
- return;
1273
- const o = r.get(S), d = o.getFocusDrawings(), a = i.map((c) => o.getDrawingByParam(c)), g = {
1274
- workbook: n,
1275
- selectedImages: this._createFOverGridImage(a),
1276
- oldSelectedImages: this._createFOverGridImage(d)
1277
- };
1278
- if (this.fireEvent(this.Event.BeforeOverGridImageSelect, g), g.cancel)
1279
- throw new k();
1280
- })
1281
- )
1282
- ), this.disposeWithMe(
1283
- this.registerEventHandler(
1284
- this.Event.OverGridImageInserted,
1285
- () => t.onCommandExecuted((e) => {
1286
- if (e.id !== b.id) return;
1287
- const i = e.params, n = this.getActiveWorkbook();
1288
- if (n == null || i == null)
1289
- return;
1290
- const { drawings: o } = i;
1291
- this.fireEvent(this.Event.OverGridImageInserted, {
1292
- workbook: n,
1293
- images: this._createFOverGridImage(o)
1294
- });
1295
- })
1296
- )
1297
- ), this.disposeWithMe(
1298
- this.registerEventHandler(
1299
- this.Event.OverGridImageRemoved,
1300
- () => t.onCommandExecuted((e) => {
1301
- if (e.id !== E.id) return;
1302
- const i = e.params, n = this.getActiveWorkbook();
1303
- if (n == null || i == null)
1304
- return;
1305
- const { drawings: o } = i;
1306
- this.fireEvent(this.Event.OverGridImageRemoved, {
1307
- workbook: n,
1308
- removeImageParams: o
1309
- });
1310
- })
1311
- )
1312
- ), this.disposeWithMe(
1313
- this.registerEventHandler(
1314
- this.Event.OverGridImageChanged,
1315
- () => t.onCommandExecuted((e) => {
1316
- if (e.id !== u.id) return;
1317
- const i = e.params, n = this.getActiveWorkbook();
1318
- if (n == null || i == null)
1319
- return;
1320
- const { drawings: o } = i, d = r.get(S), a = o.map((g) => this._injector.createInstance(v, d.getDrawingByParam(g)));
1321
- this.fireEvent(this.Event.OverGridImageChanged, {
1322
- workbook: n,
1323
- images: a
1324
- });
1325
- })
1326
- )
1327
- ), this.disposeWithMe(
1328
- this.registerEventHandler(
1329
- this.Event.OverGridImageSelected,
1330
- () => t.onCommandExecuted((e) => {
1331
- if (e.id !== j.id) return;
1332
- const i = e.params, n = this.getActiveWorkbook();
1333
- if (n == null)
1334
- return;
1335
- const o = r.get(S), d = i.map((a) => o.getDrawingByParam(a));
1336
- this.fireEvent(this.Event.OverGridImageSelected, {
1337
- workbook: n,
1338
- selectedImages: this._createFOverGridImage(d)
1339
- });
1340
- })
1341
- )
1342
- );
1343
- }
1344
- _createFOverGridImage(r) {
1345
- return r.map((t) => this._injector.createInstance(v, t));
1346
- }
1347
- registerURLImageDownloader(r) {
1348
- return this._injector.get(re).registerURLImageDownloader(r);
1349
- }
1350
- }
1351
- $.extend(ve);
1352
- class _e extends J {
1353
- async insertCellImageAsync(r) {
1354
- var n;
1355
- const t = this._injector.get(C), e = (n = ae(ie.UNIVER_SHEET, this._injector.get(ne), t)) == null ? void 0 : n.with(de);
1356
- if (!e)
1357
- return !1;
1358
- const i = {
1359
- unitId: this._workbook.getUnitId(),
1360
- subUnitId: this._worksheet.getSheetId(),
1361
- row: this.getRow(),
1362
- col: this.getColumn()
1363
- };
1364
- return typeof r == "string" ? e.insertCellImageByUrl(r, i) : e.insertCellImageByFile(r, i);
1365
- }
1366
- async saveCellImagesAsync(r) {
1367
- var c;
1368
- const t = this._injector.get(V), e = this._workbook.getUnitId(), i = this._worksheet.getSheetId(), n = this.getRange(), o = t.getCellImagesFromRanges(e, i, [n]);
1369
- if (o.length === 0)
1370
- return !1;
1371
- if (o.length === 1)
1372
- try {
1373
- return await t.downloadSingleImage(o[0]), !0;
1374
- } catch (m) {
1375
- return console.error("Failed to download image:", m), !1;
1376
- }
1377
- const d = [], a = (c = r == null ? void 0 : r.useCellAddress) != null ? c : !0, g = r == null ? void 0 : r.useColumnIndex;
1378
- a && d.push(y.CELL_ADDRESS), g !== void 0 && d.push(y.COLUMN_VALUE), d.length === 0 && d.push(y.CELL_ADDRESS);
1379
- try {
1380
- return await t.saveImagesWithContext(o, {
1381
- fileNameParts: d,
1382
- columnIndex: g
1383
- }, e, i), !0;
1384
- } catch (m) {
1385
- return console.error("Failed to save images:", m), !1;
1386
- }
1387
- }
1388
- }
1389
- J.extend(_e);
1
+ import{ArrangeTypeEnum as e,CanceledError as t,DrawingTypeEnum as n,ICommandService as r,IURLImageService as i,IUniverInstanceService as a,ImageSourceType as o,Inject as s,Injector as c,UniverInstanceType as l,generateRandomId as u,toDisposable as d}from"@univerjs/core";import{FBase as f,FEnum as p,FEventName as m,FUniver as h}from"@univerjs/core/facade";import{IDrawingManagerService as g,SetDrawingSelectedOperation as _,getImageSize as v}from"@univerjs/drawing";import{IRenderManagerService as y,getCurrentTypeOfRenderer as b}from"@univerjs/engine-render";import{FileNamePart as x,IBatchSaveImagesService as S,InsertSheetDrawingCommand as C,RemoveSheetDrawingCommand as w,SetDrawingArrangeCommand as T,SetSheetDrawingCommand as E,SheetCanvasFloatDomManagerService as D,SheetDrawingUpdateController as O,transformToAxisAlignPosition as k,transformToDrawingPosition as A}from"@univerjs/sheets-drawing-ui";import{ISheetSelectionRenderService as j,SheetSkeletonManagerService as M,convertPositionCellToSheetOverGrid as N,convertPositionSheetOverGridToAbsolute as P}from"@univerjs/sheets-ui";import{ISheetDrawingService as F,SheetDrawingAnchorType as I}from"@univerjs/sheets-drawing";import{transformComponentKey as L}from"@univerjs/sheets-ui/facade";import{FRange as R,FWorksheet as z}from"@univerjs/sheets/facade";import{ComponentManager as B}from"@univerjs/ui";function V(e){"@babel/helpers - typeof";return V=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},V(e)}function H(e,t){if(V(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(V(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function U(e){var t=H(e,`string`);return V(t)==`symbol`?t:t+``}function W(e,t,n){return(t=U(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function G(e,t){return function(n,r){t(n,r,e)}}function K(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function q(e,t){let{from:n,to:r,flipY:i=!1,flipX:a=!1,angle:o=0,skewX:s=0,skewY:c=0}=e.sheetTransform,{column:l,columnOffset:u,row:d,rowOffset:f}=n,{width:p,height:m}=P(e.unitId,e.subUnitId,{from:n,to:r},t);return{...e,column:l,columnOffset:u,row:d,rowOffset:f,width:p,height:m,flipY:i,flipX:a,angle:o,skewX:s,skewY:c}}function J(e,t,n){let{column:r,columnOffset:i,row:a,rowOffset:o,flipY:s=!1,flipX:c=!1,angle:l=0,skewX:u=0,skewY:d=0,width:f,height:p}=e,{sheetTransform:m,transform:h}=N(e.unitId,e.subUnitId,{column:r,columnOffset:i,row:a,rowOffset:o},f,p,t,n);return{...e,sheetTransform:{...m,flipY:s,flipX:c,angle:l,skewX:u,skewY:d},transform:{...h,flipY:s,flipX:c,angle:l,skewX:u,skewY:d},axisAlignSheetTransform:k(h,t)}}let Y=class{constructor(e,t,r){this._injector=r,W(this,`_image`,void 0),this._image={drawingId:u(6),drawingType:n.DRAWING_IMAGE,imageSourceType:o.BASE64,source:``,unitId:e,subUnitId:t,column:0,columnOffset:0,row:0,rowOffset:0,width:0,height:0,axisAlignSheetTransform:{from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}}}setImage(e){let t=this._injector.get(y).getRenderById(e.unitId);if(!t)throw Error(`Render Unit with unitId ${e.unitId} not found`);let n=t.with(M);return e.sheetTransform==null&&(e.sheetTransform={from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}),e.axisAlignSheetTransform==null&&(e.axisAlignSheetTransform={from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}),this._image=q(e,n),this}setSource(e,t){let n=t==null?o.URL:t;return this._image.source=e,this._image.imageSourceType=n,this}getSource(){return this._image.source}getSourceType(){return this._image.imageSourceType}setColumn(e){return this._image.column=e,this}setRow(e){return this._image.row=e,this}setColumnOffset(e){return this._image.columnOffset=e,this}setRowOffset(e){return this._image.rowOffset=e,this}setWidth(e){return this._image.width=e,this}setHeight(e){return this._image.height=e,this}setAnchorType(e){return this._image.anchorType=e,this}setCropTop(e){return this._initializeSrcRect(),this._image.srcRect.top=e,this}setCropLeft(e){return this._initializeSrcRect(),this._image.srcRect.left=e,this}setCropBottom(e){return this._initializeSrcRect(),this._image.srcRect.bottom=e,this}setCropRight(e){return this._initializeSrcRect(),this._image.srcRect.right=e,this}_initializeSrcRect(){this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0})}setRotate(e){return this._image.angle=e,this}setUnitId(e){return this._image.unitId=e,this}setSubUnitId(e){return this._image.subUnitId=e,this}async buildAsync(){let e=this._injector.get(y).getRenderById(this._image.unitId);if(!e)throw Error(`Render Unit with unitId ${this._image.unitId} not found`);let t=e.with(j),n=e.with(M);if(this._image.width===0||this._image.height===0){let e=await v(this._image.source),t=e.width,n=e.height;this._image.width===0&&(this._image.width=t),this._image.height===0&&(this._image.height=n)}return J(this._image,t,n)}};Y=K([G(2,s(c))],Y);let X=class extends f{constructor(e,t,n){super(),this._image=e,this._commandService=t,this._injector=n}getId(){return this._image.drawingId}getType(){return this._image.drawingType}remove(){return this._commandService.syncExecuteCommand(w.id,{unitId:this._image.unitId,drawings:[this._image]})}toBuilder(){let e=this._injector.createInstance(Y);return e.setImage(this._image),e}setSource(e,t){let n=t==null?o.URL:t;return this._image.source=e,this._image.imageSourceType=n,this._commandService.syncExecuteCommand(E.id,{unitId:this._image.unitId,drawings:[this._image]})}async setPositionAsync(e,t,n,r){let i=this.toBuilder();i.setColumn(t),i.setRow(e),n!=null&&i.setRowOffset(n),r!=null&&i.setColumnOffset(r);let a=await i.buildAsync();return this._commandService.syncExecuteCommand(E.id,{unitId:this._image.unitId,drawings:[a]})}async setSizeAsync(e,t){let n=this.toBuilder();n.setWidth(e),n.setHeight(t);let r=await n.buildAsync();return this._commandService.syncExecuteCommand(E.id,{unitId:this._image.unitId,drawings:[r]})}setCrop(e,t,n,r){return this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0}),e!=null&&(this._image.srcRect.top=e),t!=null&&(this._image.srcRect.left=t),n!=null&&(this._image.srcRect.bottom=n),r!=null&&(this._image.srcRect.right=r),this._commandService.syncExecuteCommand(E.id,{unitId:this._image.unitId,drawings:[this._image]})}setRotate(e){if(this._image.sheetTransform.angle=e,this._image.transform&&(this._image.transform.angle=e),this._image.transform){let e=this._injector.get(y).getRenderById(this._image.unitId);if(!e)throw Error(`Render Unit with unitId ${this._image.unitId} not found`);let t=e.with(j);this._image.axisAlignSheetTransform&&(this._image.axisAlignSheetTransform=k(this._image.transform,t))}return this._commandService.syncExecuteCommand(E.id,{unitId:this._image.unitId,drawings:[this._image]})}setForward(){return this._commandService.syncExecuteCommand(T.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.forward})}setBackward(){return this._commandService.syncExecuteCommand(T.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.backward})}setBack(){return this._commandService.syncExecuteCommand(T.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.back})}setFront(){return this._commandService.syncExecuteCommand(T.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:e.front})}};X=K([G(1,r),G(2,s(c))],X);var Z=class extends z{getFloatDomById(e){let t=this._injector.get(D).getFloatDomInfo(e);if(!t)return null;let{unitId:n,subUnitId:r}=t,{rect:i}=t,{left:a=0,top:o=0,width:s=0,height:c=0,flipX:l=!1,flipY:u=!1,angle:d=0,skewX:f=0,skewY:p=0}=i.getState(),m=this._injector.get(F).getDrawingByParam({drawingId:t.id,unitId:n,subUnitId:r});return m?{position:{left:a,top:o,width:s,height:c,flipX:l,flipY:u,angle:d,skewX:f,skewY:p},componentKey:m.componentKey,allowTransform:m.allowTransform,data:m.data,id:t.id}:null}getAllFloatDoms(){let e=this._injector.get(D),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId();return Array.from(e.getFloatDomsBySubUnitId(t,n).values()).map(e=>{let{rect:r}=e,i=this._injector.get(F).getDrawingByParam({drawingId:e.id,unitId:t,subUnitId:n}),{left:a,top:o,width:s,height:c,flipX:l,flipY:u,angle:d,skewX:f,skewY:p}=r.getState();return{position:{left:a,top:o,width:s,height:c,flipX:l,flipY:u,angle:d,skewX:f,skewY:p},componentKey:i.componentKey,allowTransform:i.allowTransform,data:i.data,id:e.id}})}updateFloatDom(e,t){var n,r,i;let a=this._injector.get(D).getFloatDomInfo(e);if(!a)return this;let{unitId:o,subUnitId:s}=a,c=this._injector.get(F).getDrawingByParam({unitId:o,subUnitId:s,drawingId:e}),l=this._injector.get(y);if(!l.getRenderById(o)||!this.getSkeleton())return this;let u=(n=l.getRenderById(this.getWorkbook().getUnitId()))==null?void 0:n.with(j);if(!u)return this;let d={...c,componentKey:t.componentKey||c.componentKey,allowTransform:t.allowTransform===void 0?c.allowTransform:t.allowTransform,data:t.data||c.data,sheetTransform:t.position?(r=A(t.position,u))==null?c.sheetTransform:r:c.sheetTransform,transform:{...c.transform,...t.position},axisAlignSheetTransform:t.position?(i=k(t.position,u))==null?c.sheetTransform:i:c.sheetTransform};if(!this._commandService.syncExecuteCommand(E.id,{unitId:o,subUnitId:s,drawings:[d]}))throw Error(`updateFloatDom failed`);return this}batchUpdateFloatDoms(e){let t=this._injector.get(D),n=this._injector.get(F),r=this._injector.get(y),i=[];for(let s of e){var a,o;let e=t.getFloatDomInfo(s.id);if(!e)continue;let{unitId:c,subUnitId:l}=e,u=n.getDrawingByParam({unitId:c,subUnitId:l,drawingId:s.id});if(!u)continue;let d=r.getRenderById(c);if(!d||!this.getSkeleton())continue;let f=d.with(j);if(!f)return this;let p={...u,componentKey:s.config.componentKey||u.componentKey,allowTransform:s.config.allowTransform===void 0?u.allowTransform:s.config.allowTransform,data:s.config.data||u.data,sheetTransform:s.config.position?(a=A(s.config.position,f))==null?u.sheetTransform:a:u.sheetTransform,transform:{...u.transform,...s.config.position},axisAlignSheetTransform:s.config.position?(o=k(s.config.position,f))==null?u.sheetTransform:o:u.sheetTransform};i.push(p)}if(i.length>0){let e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();if(!this._commandService.syncExecuteCommand(E.id,{unitId:e,subUnitId:t,drawings:i}))throw Error(`batchUpdateFloatDoms failed`)}return this}removeFloatDom(e){let t=this._injector.get(D).getFloatDomInfo(e);if(!t)return this;let{unitId:n,subUnitId:r}=t,i=this._injector.get(F).getDrawingByParam({unitId:n,subUnitId:r,drawingId:e});if(!i)return this;if(!this._commandService.syncExecuteCommand(w.id,{unitId:n,drawings:[i]}))throw Error(`removeFloatDom failed`);return this}addFloatDomToPosition(e,t){let n=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),{key:i,disposableCollection:a}=L(e,this._injector.get(B)),o=this._injector.get(D).addFloatDomToPosition({...e,componentKey:i,unitId:n,subUnitId:r},t);return o?(a.add(o.dispose),{id:o.id,dispose:()=>{a.dispose(),o.dispose()}}):(a.dispose(),null)}addFloatDomToRange(e,t,n,r){let i=this._workbook.getUnitId(),a=this._worksheet.getSheetId(),{key:o,disposableCollection:s}=L(t,this._injector.get(B)),c=this._injector.get(D).addFloatDomToRange(e.getRange(),{...t,componentKey:o,unitId:i,subUnitId:a},n,r);return c?(s.add(c.dispose),{id:c.id,dispose:()=>{s.dispose(),c.dispose()}}):(s.dispose(),null)}addFloatDomToColumnHeader(e,t,n,r){let i=this._workbook.getUnitId(),a=this._worksheet.getSheetId(),{key:o,disposableCollection:s}=L(t,this._injector.get(B)),c=this._injector.get(D).addFloatDomToColumnHeader(e,{...t,componentKey:o,unitId:i,subUnitId:a},n,r);return c?(s.add(c.dispose),{id:c.id,dispose:()=>{s.dispose(),c.dispose()}}):(s.dispose(),null)}async insertImage(e,t,n,r,i){let a=this.newOverGridImage();if(typeof e==`string`)a.setSource(e);else{let t=await e.getBlob().getDataAsString();a.setSource(t,o.BASE64)}t===void 0?a.setColumn(0):a.setColumn(t),n===void 0?a.setRow(0):a.setRow(n),r===void 0?a.setColumnOffset(0):a.setColumnOffset(r),i===void 0?a.setRowOffset(0):a.setRowOffset(i);let s=await a.buildAsync();return this._commandService.syncExecuteCommand(C.id,{unitId:this._fWorkbook.getId(),drawings:[s]})}insertImages(e){let t=e.map(e=>(e.unitId=this._fWorkbook.getId(),e.subUnitId=this.getSheetId(),e));return this._commandService.syncExecuteCommand(C.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}deleteImages(e){let t=e.map(e=>({unitId:this._fWorkbook.getId(),drawingId:e.getId(),subUnitId:this.getSheetId(),drawingType:e.getType()}));return this._commandService.syncExecuteCommand(w.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}getImages(){let e=this._injector.get(F).getDrawingData(this._fWorkbook.getId(),this.getSheetId()),t=[];for(let r in e){let i=e[r];i.drawingType===n.DRAWING_IMAGE&&t.push(this._injector.createInstance(X,i))}return t}getImageById(e){let t=this._injector.get(F).getDrawingByParam({unitId:this._fWorkbook.getId(),subUnitId:this.getSheetId(),drawingId:e});return t&&t.drawingType===n.DRAWING_IMAGE?this._injector.createInstance(X,t):null}getActiveImages(){let e=this._injector.get(F).getFocusDrawings(),t=[];for(let n in e){let r=e[n];t.push(this._injector.createInstance(X,r))}return t}updateImages(e){return this._commandService.syncExecuteCommand(E.id,{unitId:this._fWorkbook.getId(),drawings:e}),this}onImageInserted(e){let t=this._injector.get(F);return d(t.add$.subscribe(n=>{e(n.map(e=>this._injector.createInstance(X,t.getDrawingByParam(e))))}))}onImageDeleted(e){let t=this._injector.get(F);return d(t.remove$.subscribe(n=>{e(n.map(e=>this._injector.createInstance(X,t.getDrawingByParam(e))))}))}onImageChanged(e){let t=this._injector.get(F);return d(t.update$.subscribe(n=>{e(n.map(e=>this._injector.createInstance(X,t.getDrawingByParam(e))))}))}newOverGridImage(){let e=this._fWorkbook.getId(),t=this.getSheetId();return this._injector.createInstance(Y,e,t)}async saveCellImagesAsync(e,t){var n;let r=this._injector.get(S),i=this._fWorkbook.getId(),a=this.getSheetId(),o=t?t.map(e=>e.getRange()):[this._worksheet.getCellMatrix().getDataRange()],s=r.getCellImagesFromRanges(i,a,o);if(s.length===0)return!1;if(s.length===1)try{return await r.downloadSingleImage(s[0]),!0}catch(e){return console.error(`Failed to download image:`,e),!1}let c=[],l=(n=e==null?void 0:e.useCellAddress)==null?!0:n,u=e==null?void 0:e.useColumnIndex;l&&c.push(x.CELL_ADDRESS),u!==void 0&&c.push(x.COLUMN_VALUE),c.length===0&&c.push(x.CELL_ADDRESS);try{return await r.saveImagesWithContext(s,{fileNameParts:c,columnIndex:u},i,a),!0}catch(e){return console.error(`Failed to save images:`,e),!1}}};z.extend(Z);var Q=class extends p{get DrawingType(){return n}get ImageSourceType(){return o}get SheetDrawingAnchorType(){return I}};p.extend(Q);var $=class extends m{get BeforeFloatDomAdd(){return`BeforeFloatDomAdd`}get FloatDomAdded(){return`FloatDomAdded`}get BeforeFloatDomUpdate(){return`BeforeFloatDomUpdate`}get FloatDomUpdated(){return`FloatDomUpdated`}get BeforeFloatDomDelete(){return`BeforeFloatDomDelete`}get FloatDomDeleted(){return`FloatDomDeleted`}get BeforeOverGridImageChange(){return`BeforeOverGridImageChange`}get OverGridImageChanged(){return`OverGridImageChanged`}get BeforeOverGridImageInsert(){return`BeforeOverGridImageInsert`}get OverGridImageInserted(){return`OverGridImageInserted`}get BeforeOverGridImageRemove(){return`BeforeOverGridImageRemove`}get OverGridImageRemoved(){return`OverGridImageRemoved`}get BeforeOverGridImageSelect(){return`BeforeOverGridImageSelect`}get OverGridImageSelected(){return`OverGridImageSelected`}};m.extend($);var ee=class extends h{_initialize(e){let i=e.get(r);this.disposeWithMe(this.registerEventHandler(this.Event.BeforeFloatDomAdd,()=>i.beforeCommandExecuted(e=>{if(e.id!==C.id)return;let r=e.params,i=this.getActiveWorkbook();if(i==null||r==null)return;let{drawings:a}=r,o=a.filter(e=>e.drawingType===n.DRAWING_DOM);if(o.length===0)return;let s={workbook:i,drawings:o};if(this.fireEvent(this.Event.BeforeFloatDomAdd,s),s.cancel)throw new t}))),this.disposeWithMe(this.registerEventHandler(this.Event.FloatDomAdded,()=>i.onCommandExecuted(e=>{if(e.id!==C.id)return;let t=e.params,r=this.getActiveWorkbook();if(r==null||t==null)return;let{drawings:i}=t,a=i.filter(e=>e.drawingType===n.DRAWING_DOM);a.length!==0&&this.fireEvent(this.Event.FloatDomAdded,{workbook:r,drawings:a})}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageInsert,()=>i.beforeCommandExecuted(e=>{if(e.id!==C.id)return;let n=e.params,r=this.getActiveWorkbook();if(r==null||n==null)return;let{drawings:i}=n,a={workbook:r,insertImageParams:i};if(this.fireEvent(this.Event.BeforeOverGridImageInsert,a),a.cancel)throw new t}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageRemove,()=>i.beforeCommandExecuted(n=>{if(n.id!==w.id)return;let r=n.params,i=this.getActiveWorkbook();if(i==null||r==null)return;let a=e.get(g),{drawings:o}=r,s=o.map(e=>a.getDrawingByParam(e)),c={workbook:i,images:this._createFOverGridImage(s)};if(this.fireEvent(this.Event.BeforeOverGridImageRemove,c),c.cancel)throw new t}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageChange,()=>i.beforeCommandExecuted(n=>{if(n.id!==E.id)return;let r=n.params,i=this.getActiveWorkbook();if(i==null||r==null)return;let{drawings:a}=r,o=e.get(g),s=[];a.forEach(e=>{let t=o.getDrawingByParam(e);t!=null&&s.push({changeParam:e,image:this._injector.createInstance(X,t)})});let c={workbook:i,images:s};if(this.fireEvent(this.Event.BeforeOverGridImageChange,c),c.cancel)throw o.updateNotification(a),new t}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeFloatDomUpdate,()=>i.beforeCommandExecuted(r=>{if(r.id!==E.id)return;let i=r.params,a=this.getActiveWorkbook();if(a==null||i==null)return;let{drawings:o}=i,s=e.get(g),c=[];if(o.forEach(e=>{let t=s.getDrawingByParam(e);(t==null?void 0:t.drawingType)===n.DRAWING_DOM&&c.push(t)}),c.length===0)return;let l={workbook:a,drawings:c};if(this.fireEvent(this.Event.BeforeFloatDomUpdate,l),l.cancel)throw s.updateNotification(o),new t}))),this.disposeWithMe(this.registerEventHandler(this.Event.FloatDomUpdated,()=>i.onCommandExecuted(t=>{if(t.id!==E.id)return;let r=t.params,i=this.getActiveWorkbook();if(i==null||r==null)return;let{drawings:a}=r,o=e.get(g),s=[];a.forEach(e=>{let t=o.getDrawingByParam(e);(t==null?void 0:t.drawingType)===n.DRAWING_DOM&&s.push(t)}),s.length!==0&&this.fireEvent(this.Event.FloatDomUpdated,{workbook:i,drawings:s})}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeFloatDomDelete,()=>i.beforeCommandExecuted(r=>{if(r.id!==w.id)return;let i=r.params,a=this.getActiveWorkbook();if(a==null||i==null)return;let o=e.get(g),{drawings:s}=i,c=s.map(e=>o.getDrawingByParam(e)).filter(e=>(e==null?void 0:e.drawingType)===n.DRAWING_DOM);if(c.length===0)return;let l={workbook:a,drawings:c};if(this.fireEvent(this.Event.BeforeFloatDomDelete,l),l.cancel)throw new t}))),this.disposeWithMe(this.registerEventHandler(this.Event.FloatDomDeleted,()=>i.onCommandExecuted(e=>{if(e.id!==w.id)return;let t=e.params,r=this.getActiveWorkbook();if(r==null||t==null)return;let{drawings:i}=t;this.fireEvent(this.Event.FloatDomDeleted,{workbook:r,drawings:i.filter(e=>e.drawingType===n.DRAWING_DOM).map(e=>e.drawingId)})}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageSelect,()=>i.beforeCommandExecuted(n=>{if(n.id!==_.id)return;let r=n.params,i=this.getActiveWorkbook();if(i==null)return;let a=e.get(g),o=a.getFocusDrawings(),s=r.map(e=>a.getDrawingByParam(e)),c={workbook:i,selectedImages:this._createFOverGridImage(s),oldSelectedImages:this._createFOverGridImage(o)};if(this.fireEvent(this.Event.BeforeOverGridImageSelect,c),c.cancel)throw new t}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageInserted,()=>i.onCommandExecuted(e=>{if(e.id!==C.id)return;let t=e.params,n=this.getActiveWorkbook();if(n==null||t==null)return;let{drawings:r}=t;this.fireEvent(this.Event.OverGridImageInserted,{workbook:n,images:this._createFOverGridImage(r)})}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageRemoved,()=>i.onCommandExecuted(e=>{if(e.id!==w.id)return;let t=e.params,n=this.getActiveWorkbook();if(n==null||t==null)return;let{drawings:r}=t;this.fireEvent(this.Event.OverGridImageRemoved,{workbook:n,removeImageParams:r})}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageChanged,()=>i.onCommandExecuted(t=>{if(t.id!==E.id)return;let n=t.params,r=this.getActiveWorkbook();if(r==null||n==null)return;let{drawings:i}=n,a=e.get(g),o=i.map(e=>this._injector.createInstance(X,a.getDrawingByParam(e)));this.fireEvent(this.Event.OverGridImageChanged,{workbook:r,images:o})}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageSelected,()=>i.onCommandExecuted(t=>{if(t.id!==_.id)return;let n=t.params,r=this.getActiveWorkbook();if(r==null)return;let i=e.get(g),a=n.map(e=>i.getDrawingByParam(e));this.fireEvent(this.Event.OverGridImageSelected,{workbook:r,selectedImages:this._createFOverGridImage(a)})})))}_createFOverGridImage(e){return e.map(e=>this._injector.createInstance(X,e))}registerURLImageDownloader(e){return this._injector.get(i).registerURLImageDownloader(e)}};h.extend(ee);var te=class extends R{async insertCellImageAsync(e){var t;let n=this._injector.get(y),r=(t=b(l.UNIVER_SHEET,this._injector.get(a),n))==null?void 0:t.with(O);if(!r)return!1;let i={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this.getRow(),col:this.getColumn()};return typeof e==`string`?r.insertCellImageByUrl(e,i):r.insertCellImageByFile(e,i)}async saveCellImagesAsync(e){var t;let n=this._injector.get(S),r=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),a=this.getRange(),o=n.getCellImagesFromRanges(r,i,[a]);if(o.length===0)return!1;if(o.length===1)try{return await n.downloadSingleImage(o[0]),!0}catch(e){return console.error(`Failed to download image:`,e),!1}let s=[],c=(t=e==null?void 0:e.useCellAddress)==null?!0:t,l=e==null?void 0:e.useColumnIndex;c&&s.push(x.CELL_ADDRESS),l!==void 0&&s.push(x.COLUMN_VALUE),s.length===0&&s.push(x.CELL_ADDRESS);try{return await n.saveImagesWithContext(o,{fileNameParts:s,columnIndex:l},r,i),!0}catch(e){return console.error(`Failed to save images:`,e),!1}}};R.extend(te);export{};