@univerjs/sheets-drawing-ui 1.0.0-beta.1 → 1.0.0-beta.2

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/cjs/index.js CHANGED
@@ -1624,18 +1624,8 @@ function createExternalRuntimeDisposable(owner, id, disposeById) {
1624
1624
  };
1625
1625
  }
1626
1626
  const SHEET_EMBED_FLOAT_DOM_TRANSFORMER_CONFIG = {
1627
- borderEnabled: true,
1628
- borderStroke: "#4086f4",
1629
- borderStrokeWidth: 1,
1630
- borderSpacing: 2,
1631
- anchorFill: "#ffffff",
1632
- anchorStroke: "#4086f4",
1633
- anchorStrokeWidth: 1.5,
1634
- anchorSize: 8,
1635
- anchorCornerRadius: 2,
1636
- anchorStyle: "canva",
1627
+ ..._univerjs_engine_render.DEFAULT_TRANSFORMER_CONFIG,
1637
1628
  rotateEnabled: false,
1638
- resizeEnabled: true,
1639
1629
  moveBoundaryEnabled: false
1640
1630
  };
1641
1631
  /**
@@ -1643,18 +1633,8 @@ const SHEET_EMBED_FLOAT_DOM_TRANSFORMER_CONFIG = {
1643
1633
  * Charts retain resize handles but do not expose a rotation control.
1644
1634
  */
1645
1635
  const SHEET_CHART_TRANSFORMER_CONFIG = {
1646
- borderEnabled: true,
1647
- borderStroke: "#4086f4",
1648
- borderStrokeWidth: 1,
1649
- borderSpacing: 2,
1650
- anchorFill: "#ffffff",
1651
- anchorStroke: "#4086f4",
1652
- anchorStrokeWidth: 1.5,
1653
- anchorSize: 8,
1654
- anchorCornerRadius: 2,
1655
- anchorStyle: "canva",
1636
+ ..._univerjs_engine_render.DEFAULT_TRANSFORMER_CONFIG,
1656
1637
  rotateEnabled: false,
1657
- resizeEnabled: true,
1658
1638
  keepRatio: false,
1659
1639
  moveBoundaryEnabled: false
1660
1640
  };
@@ -2224,6 +2204,11 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2224
2204
  canvas: renderUnit.engine.getCanvasElement()
2225
2205
  };
2226
2206
  }
2207
+ _getDrawingZIndex(unitId, subUnitId, drawingId) {
2208
+ const drawingOrder = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
2209
+ const drawingIndex = drawingOrder.indexOf(drawingId);
2210
+ return drawingIndex < 0 ? drawingOrder.length - 1 : drawingIndex;
2211
+ }
2227
2212
  _drawingAddListener() {
2228
2213
  this.disposeWithMe(this._drawingManagerService.add$.subscribe((params) => {
2229
2214
  params.forEach((param) => {
@@ -2287,7 +2272,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2287
2272
  top,
2288
2273
  width,
2289
2274
  height,
2290
- zIndex: this._drawingManagerService.getDrawingOrder(unitId, subUnitId).length - 1
2275
+ zIndex: this._getDrawingZIndex(unitId, subUnitId, drawingId)
2291
2276
  };
2292
2277
  const isChart = drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_CHART;
2293
2278
  if (isChart) {
@@ -2502,7 +2487,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2502
2487
  this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
2503
2488
  if (commandInfo.id === _univerjs_sheets_ui.SetZoomRatioOperation.id) {
2504
2489
  const { unitId } = commandInfo.params;
2505
- Array.from(this._domLayerInfoMap.values()).filter((info) => info.unitId === unitId).map((info) => info.subUnitId).forEach((subUnitId) => {
2490
+ new Set(Array.from(this._domLayerInfoMap.values()).filter((info) => info.unitId === unitId).map((info) => info.subUnitId)).forEach((subUnitId) => {
2506
2491
  updateSheet(unitId, subUnitId);
2507
2492
  });
2508
2493
  } else if (commandInfo.id === _univerjs_sheets.SetFrozenMutation.id) {
@@ -3433,7 +3418,7 @@ const menuSchema = {
3433
3418
  //#endregion
3434
3419
  //#region package.json
3435
3420
  var name = "@univerjs/sheets-drawing-ui";
3436
- var version = "1.0.0-beta.1";
3421
+ var version = "1.0.0-beta.2";
3437
3422
 
3438
3423
  //#endregion
3439
3424
  //#region src/config/config.ts
package/lib/es/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BooleanNumber, BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, FOCUSING_PANEL_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, FOCUSING_SHEET, ICommandService, IConfigService, IContextService, IImageIoService, IPermissionService, IURLImageService, IUndoRedoService, IUniverInstanceService, ImageSourceType, ImageUploadStatusType, Inject, Injector, InterceptorEffectEnum, LifecycleService, LifecycleStages, LocaleService, ObjectMatrix, Optional, Plugin, PositionedObjectLayoutType, RxDisposable, Tools, UniverInstanceType, UserManagerService, WrapTextType, createDocumentModelWithStyle, createIdentifier, fromEventSubject, generateRandomId, merge, registerDependencies, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
2
2
  import { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SetSheetDrawingPlacementCommand, SheetDrawingAnchorType, UniverSheetsDrawingPlugin, drawingPositionToTransform, getSheetDrawingPlacement, transformToAxisAlignPosition, transformToDrawingPosition } from "@univerjs/sheets-drawing";
3
- import { CURSOR_TYPE, DRAWING_OBJECT_LAYER_INDEX, IRenderManagerService, Image, ObjectType, Rect, SHEET_VIEWPORT_KEY, UniverRenderEnginePlugin, Vector2, getCurrentTypeOfRenderer, getGroupState, transformObjectOutOfGroup } from "@univerjs/engine-render";
3
+ import { CURSOR_TYPE, DEFAULT_TRANSFORMER_CONFIG, DRAWING_OBJECT_LAYER_INDEX, IRenderManagerService, Image, ObjectType, Rect, SHEET_VIEWPORT_KEY, UniverRenderEnginePlugin, Vector2, getCurrentTypeOfRenderer, getGroupState, transformObjectOutOfGroup } from "@univerjs/engine-render";
4
4
  import { Button, Checkbox, CheckboxGroup, FormLayout, MessageType, Radio, RadioGroup, Select, clsx, render, unmount } from "@univerjs/design";
5
5
  import { buildDocTransform, docDrawingPositionToTransform } from "@univerjs/docs";
6
6
  import { DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, IDrawingManagerService, SetDrawingSelectedOperation, UniverDrawingPlugin, getDrawingImageAllowSize, getDrawingShapeKeyByDrawingSearch, getImageSize } from "@univerjs/drawing";
@@ -1623,18 +1623,8 @@ function createExternalRuntimeDisposable(owner, id, disposeById) {
1623
1623
  };
1624
1624
  }
1625
1625
  const SHEET_EMBED_FLOAT_DOM_TRANSFORMER_CONFIG = {
1626
- borderEnabled: true,
1627
- borderStroke: "#4086f4",
1628
- borderStrokeWidth: 1,
1629
- borderSpacing: 2,
1630
- anchorFill: "#ffffff",
1631
- anchorStroke: "#4086f4",
1632
- anchorStrokeWidth: 1.5,
1633
- anchorSize: 8,
1634
- anchorCornerRadius: 2,
1635
- anchorStyle: "canva",
1626
+ ...DEFAULT_TRANSFORMER_CONFIG,
1636
1627
  rotateEnabled: false,
1637
- resizeEnabled: true,
1638
1628
  moveBoundaryEnabled: false
1639
1629
  };
1640
1630
  /**
@@ -1642,18 +1632,8 @@ const SHEET_EMBED_FLOAT_DOM_TRANSFORMER_CONFIG = {
1642
1632
  * Charts retain resize handles but do not expose a rotation control.
1643
1633
  */
1644
1634
  const SHEET_CHART_TRANSFORMER_CONFIG = {
1645
- borderEnabled: true,
1646
- borderStroke: "#4086f4",
1647
- borderStrokeWidth: 1,
1648
- borderSpacing: 2,
1649
- anchorFill: "#ffffff",
1650
- anchorStroke: "#4086f4",
1651
- anchorStrokeWidth: 1.5,
1652
- anchorSize: 8,
1653
- anchorCornerRadius: 2,
1654
- anchorStyle: "canva",
1635
+ ...DEFAULT_TRANSFORMER_CONFIG,
1655
1636
  rotateEnabled: false,
1656
- resizeEnabled: true,
1657
1637
  keepRatio: false,
1658
1638
  moveBoundaryEnabled: false
1659
1639
  };
@@ -2223,6 +2203,11 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2223
2203
  canvas: renderUnit.engine.getCanvasElement()
2224
2204
  };
2225
2205
  }
2206
+ _getDrawingZIndex(unitId, subUnitId, drawingId) {
2207
+ const drawingOrder = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
2208
+ const drawingIndex = drawingOrder.indexOf(drawingId);
2209
+ return drawingIndex < 0 ? drawingOrder.length - 1 : drawingIndex;
2210
+ }
2226
2211
  _drawingAddListener() {
2227
2212
  this.disposeWithMe(this._drawingManagerService.add$.subscribe((params) => {
2228
2213
  params.forEach((param) => {
@@ -2286,7 +2271,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2286
2271
  top,
2287
2272
  width,
2288
2273
  height,
2289
- zIndex: this._drawingManagerService.getDrawingOrder(unitId, subUnitId).length - 1
2274
+ zIndex: this._getDrawingZIndex(unitId, subUnitId, drawingId)
2290
2275
  };
2291
2276
  const isChart = drawingType === DrawingTypeEnum.DRAWING_CHART;
2292
2277
  if (isChart) {
@@ -2501,7 +2486,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2501
2486
  this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
2502
2487
  if (commandInfo.id === SetZoomRatioOperation.id) {
2503
2488
  const { unitId } = commandInfo.params;
2504
- Array.from(this._domLayerInfoMap.values()).filter((info) => info.unitId === unitId).map((info) => info.subUnitId).forEach((subUnitId) => {
2489
+ new Set(Array.from(this._domLayerInfoMap.values()).filter((info) => info.unitId === unitId).map((info) => info.subUnitId)).forEach((subUnitId) => {
2505
2490
  updateSheet(unitId, subUnitId);
2506
2491
  });
2507
2492
  } else if (commandInfo.id === SetFrozenMutation.id) {
@@ -3432,7 +3417,7 @@ const menuSchema = {
3432
3417
  //#endregion
3433
3418
  //#region package.json
3434
3419
  var name = "@univerjs/sheets-drawing-ui";
3435
- var version = "1.0.0-beta.1";
3420
+ var version = "1.0.0-beta.2";
3436
3421
 
3437
3422
  //#endregion
3438
3423
  //#region src/config/config.ts
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BooleanNumber, BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, FOCUSING_PANEL_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, FOCUSING_SHEET, ICommandService, IConfigService, IContextService, IImageIoService, IPermissionService, IURLImageService, IUndoRedoService, IUniverInstanceService, ImageSourceType, ImageUploadStatusType, Inject, Injector, InterceptorEffectEnum, LifecycleService, LifecycleStages, LocaleService, ObjectMatrix, Optional, Plugin, PositionedObjectLayoutType, RxDisposable, Tools, UniverInstanceType, UserManagerService, WrapTextType, createDocumentModelWithStyle, createIdentifier, fromEventSubject, generateRandomId, merge, registerDependencies, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
2
2
  import { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SetSheetDrawingPlacementCommand, SheetDrawingAnchorType, UniverSheetsDrawingPlugin, drawingPositionToTransform, getSheetDrawingPlacement, transformToAxisAlignPosition, transformToDrawingPosition } from "@univerjs/sheets-drawing";
3
- import { CURSOR_TYPE, DRAWING_OBJECT_LAYER_INDEX, IRenderManagerService, Image, ObjectType, Rect, SHEET_VIEWPORT_KEY, UniverRenderEnginePlugin, Vector2, getCurrentTypeOfRenderer, getGroupState, transformObjectOutOfGroup } from "@univerjs/engine-render";
3
+ import { CURSOR_TYPE, DEFAULT_TRANSFORMER_CONFIG, DRAWING_OBJECT_LAYER_INDEX, IRenderManagerService, Image, ObjectType, Rect, SHEET_VIEWPORT_KEY, UniverRenderEnginePlugin, Vector2, getCurrentTypeOfRenderer, getGroupState, transformObjectOutOfGroup } from "@univerjs/engine-render";
4
4
  import { Button, Checkbox, CheckboxGroup, FormLayout, MessageType, Radio, RadioGroup, Select, clsx, render, unmount } from "@univerjs/design";
5
5
  import { buildDocTransform, docDrawingPositionToTransform } from "@univerjs/docs";
6
6
  import { DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, IDrawingManagerService, SetDrawingSelectedOperation, UniverDrawingPlugin, getDrawingImageAllowSize, getDrawingShapeKeyByDrawingSearch, getImageSize } from "@univerjs/drawing";
@@ -1623,18 +1623,8 @@ function createExternalRuntimeDisposable(owner, id, disposeById) {
1623
1623
  };
1624
1624
  }
1625
1625
  const SHEET_EMBED_FLOAT_DOM_TRANSFORMER_CONFIG = {
1626
- borderEnabled: true,
1627
- borderStroke: "#4086f4",
1628
- borderStrokeWidth: 1,
1629
- borderSpacing: 2,
1630
- anchorFill: "#ffffff",
1631
- anchorStroke: "#4086f4",
1632
- anchorStrokeWidth: 1.5,
1633
- anchorSize: 8,
1634
- anchorCornerRadius: 2,
1635
- anchorStyle: "canva",
1626
+ ...DEFAULT_TRANSFORMER_CONFIG,
1636
1627
  rotateEnabled: false,
1637
- resizeEnabled: true,
1638
1628
  moveBoundaryEnabled: false
1639
1629
  };
1640
1630
  /**
@@ -1642,18 +1632,8 @@ const SHEET_EMBED_FLOAT_DOM_TRANSFORMER_CONFIG = {
1642
1632
  * Charts retain resize handles but do not expose a rotation control.
1643
1633
  */
1644
1634
  const SHEET_CHART_TRANSFORMER_CONFIG = {
1645
- borderEnabled: true,
1646
- borderStroke: "#4086f4",
1647
- borderStrokeWidth: 1,
1648
- borderSpacing: 2,
1649
- anchorFill: "#ffffff",
1650
- anchorStroke: "#4086f4",
1651
- anchorStrokeWidth: 1.5,
1652
- anchorSize: 8,
1653
- anchorCornerRadius: 2,
1654
- anchorStyle: "canva",
1635
+ ...DEFAULT_TRANSFORMER_CONFIG,
1655
1636
  rotateEnabled: false,
1656
- resizeEnabled: true,
1657
1637
  keepRatio: false,
1658
1638
  moveBoundaryEnabled: false
1659
1639
  };
@@ -2223,6 +2203,11 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2223
2203
  canvas: renderUnit.engine.getCanvasElement()
2224
2204
  };
2225
2205
  }
2206
+ _getDrawingZIndex(unitId, subUnitId, drawingId) {
2207
+ const drawingOrder = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
2208
+ const drawingIndex = drawingOrder.indexOf(drawingId);
2209
+ return drawingIndex < 0 ? drawingOrder.length - 1 : drawingIndex;
2210
+ }
2226
2211
  _drawingAddListener() {
2227
2212
  this.disposeWithMe(this._drawingManagerService.add$.subscribe((params) => {
2228
2213
  params.forEach((param) => {
@@ -2286,7 +2271,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2286
2271
  top,
2287
2272
  width,
2288
2273
  height,
2289
- zIndex: this._drawingManagerService.getDrawingOrder(unitId, subUnitId).length - 1
2274
+ zIndex: this._getDrawingZIndex(unitId, subUnitId, drawingId)
2290
2275
  };
2291
2276
  const isChart = drawingType === DrawingTypeEnum.DRAWING_CHART;
2292
2277
  if (isChart) {
@@ -2501,7 +2486,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2501
2486
  this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
2502
2487
  if (commandInfo.id === SetZoomRatioOperation.id) {
2503
2488
  const { unitId } = commandInfo.params;
2504
- Array.from(this._domLayerInfoMap.values()).filter((info) => info.unitId === unitId).map((info) => info.subUnitId).forEach((subUnitId) => {
2489
+ new Set(Array.from(this._domLayerInfoMap.values()).filter((info) => info.unitId === unitId).map((info) => info.subUnitId)).forEach((subUnitId) => {
2505
2490
  updateSheet(unitId, subUnitId);
2506
2491
  });
2507
2492
  } else if (commandInfo.id === SetFrozenMutation.id) {
@@ -3432,7 +3417,7 @@ const menuSchema = {
3432
3417
  //#endregion
3433
3418
  //#region package.json
3434
3419
  var name = "@univerjs/sheets-drawing-ui";
3435
- var version = "1.0.0-beta.1";
3420
+ var version = "1.0.0-beta.2";
3436
3421
 
3437
3422
  //#endregion
3438
3423
  //#region src/config/config.ts
@@ -117,20 +117,31 @@ export interface IDOMAnchor {
117
117
  * Charts retain resize handles but do not expose a rotation control.
118
118
  */
119
119
  export declare const SHEET_CHART_TRANSFORMER_CONFIG: {
120
- readonly borderEnabled: true;
121
- readonly borderStroke: "#4086f4";
122
- readonly borderStrokeWidth: 1;
123
- readonly borderSpacing: 2;
124
- readonly anchorFill: "#ffffff";
125
- readonly anchorStroke: "#4086f4";
126
- readonly anchorStrokeWidth: 1.5;
127
- readonly anchorSize: 8;
128
- readonly anchorCornerRadius: 2;
129
- readonly anchorStyle: "canva";
130
120
  readonly rotateEnabled: false;
131
- readonly resizeEnabled: true;
132
121
  readonly keepRatio: false;
133
122
  readonly moveBoundaryEnabled: false;
123
+ readonly resizeEnabled: true;
124
+ readonly rotateAnchorOffset: number;
125
+ readonly rotateAnchorPosition: "bottom";
126
+ readonly rotateLineEnabled: false;
127
+ readonly rotateSize: number;
128
+ readonly rotateCornerRadius: number;
129
+ readonly rotateFill: string;
130
+ readonly rotateStroke: string;
131
+ readonly rotateStrokeWidth: number;
132
+ readonly rotateIconEnabled: true;
133
+ readonly rotateIconStroke: string;
134
+ readonly rotateIconStrokeWidth: number;
135
+ readonly borderEnabled: true;
136
+ readonly borderStroke: string;
137
+ readonly borderStrokeWidth: number;
138
+ readonly borderSpacing: number;
139
+ readonly anchorFill: string;
140
+ readonly anchorStroke: string;
141
+ readonly anchorStrokeWidth: number;
142
+ readonly anchorSize: number;
143
+ readonly anchorCornerRadius: number;
144
+ readonly anchorStyle: "canva";
134
145
  };
135
146
  export declare const EMBED_FLOAT_DRAG_HANDLE_POINTER_DOWN_EVENT = "univer:embed-float-drag-handle:pointerdown";
136
147
  export interface IFloatDomHostClickIntent {
@@ -293,6 +304,7 @@ export declare class SheetCanvasFloatDomManagerService extends Disposable {
293
304
  private _syncFloatDomVisibilityForActiveSheet;
294
305
  promoteFloatDomRuntimeStage(id: string): ICanvasFloatDomInfo['runtimeStage'] | undefined;
295
306
  private _getSceneAndTransformerByDrawingSearch;
307
+ private _getDrawingZIndex;
296
308
  private _drawingAddListener;
297
309
  private _scrollUpdateListener;
298
310
  private _bindFloatDomScroll;
package/lib/umd/index.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets-drawing"),require("@univerjs/engine-render"),require("@univerjs/design"),require("@univerjs/docs"),require("@univerjs/drawing"),require("@univerjs/sheets"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("@univerjs/drawing-ui"),require("rxjs"),require("@univerjs/docs-drawing"),require("react"),require("react/jsx-runtime"),require("@univerjs/docs-ui")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-drawing`,`@univerjs/engine-render`,`@univerjs/design`,`@univerjs/docs`,`@univerjs/drawing`,`@univerjs/sheets`,`@univerjs/sheets-ui`,`@univerjs/ui`,`@univerjs/drawing-ui`,`rxjs`,`@univerjs/docs-drawing`,`react`,`react/jsx-runtime`,`@univerjs/docs-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDrawingUi={},e.UniverCore,e.UniverSheetsDrawing,e.UniverEngineRender,e.UniverDesign,e.UniverDocs,e.UniverDrawing,e.UniverSheets,e.UniverSheetsUi,e.UniverUi,e.UniverDrawingUi,e.rxjs,e.UniverDocsDrawing,e.React,e.React,e.UniverDocsUi))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let g={id:`sheet.command.delete-drawing`,type:t.CommandType.COMMAND,handler:e=>{let r=e.get(t.ICommandService),i=e.get(n.ISheetDrawingService).getFocusDrawings();if(i.length===0)return!1;let a=i[0].unitId,o=i.map(e=>{let{unitId:t,subUnitId:n,drawingId:r,drawingType:i}=e;return{unitId:t,subUnitId:n,drawingId:r,drawingType:i}});return r.executeCommand(n.RemoveSheetDrawingCommand.id,{unitId:a,drawings:o})}};function _(e){let n=[];return e.forEach(e=>{let{parent:i,children:a}=e,{unitId:o,subUnitId:s,drawingId:c}=i,l=(0,r.getGroupState)(0,0,a.map(e=>e.transform||{})),u=a.map(e=>{let t=e.transform||{left:0,top:0},{unitId:n,subUnitId:r,drawingId:i}=e;return{unitId:n,subUnitId:r,drawingId:i,transform:{...t,left:t.left,top:t.top},groupId:c}}),d={unitId:o,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_GROUP,groupBaseBound:{...i.groupBaseBound},transform:l};n.push({parent:d,children:u})}),n}function v(e){let n=[];return e.forEach(e=>{let{parent:i,children:a}=e,{unitId:o,subUnitId:s,drawingId:c,transform:l={width:0,height:0}}=i;if(l==null)return;let u=a.map(e=>{let{transform:t}=e,{unitId:n,subUnitId:a,drawingId:o}=e;return{unitId:n,subUnitId:a,drawingId:o,transform:(0,r.transformObjectOutOfGroup)(t||{},l,l.width||0,l.height||0,i.groupBaseBound),groupId:void 0}}),d={unitId:o,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:d,children:u})}),n}function y(e){var n;let r=new Map;(n=e.flatChildren)==null||n.forEach(e=>r.set(e.drawingId,(0,t.generateRandomId)(10))),e.groups.forEach(e=>r.set(e.drawingId,(0,t.generateRandomId)(10)));let i={};for(let[t,n]of Object.entries(e.nestedIdRecord)){var a;let e=r.get(t)??t;i[e]={drawingId:e,children:(a=n.children)==null?void 0:a.map(e=>r.get(e)??e)}}let o=[],s=[];for(let t of e.groups){let e=r.get(t.drawingId)??t.drawingId,n=t.groupId?r.get(t.groupId)??t.groupId:void 0;s.push(b(t,e,n))}for(let t of e.flatChildren||[]){let e=r.get(t.drawingId)??t.drawingId,n=t.groupId?r.get(t.groupId)??t.groupId:void 0;o.push(b(t,e,n))}return{cloned:{nestedIdRecord:i,flatChildren:o,groups:s},idMap:r}}function b(e,t,n){let r={...e};return t&&(r.drawingId=t),n?r.groupId=n:delete r.groupId,JSON.parse(JSON.stringify(r))}let x={id:`sheet.command.group-sheet-image`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(n.ISheetDrawingService);if(!r)return!1;let s=[];r.forEach(({parent:e,children:t})=>{s.push(e.unitId),t.forEach(e=>{s.push(e.unitId)})});let{unitId:c,subUnitId:l,undo:u,redo:d,objects:f}=o.getGroupDrawingOp(r);return i.syncExecuteCommand(n.SetDrawingApplyMutation.id,{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.GROUP})?(a.pushUndoRedo({unitID:c,undoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:v(f),type:n.DrawingApplyType.UNGROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}],redoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.GROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}]}),!0):!1}},S={id:`sheet.command.ungroup-sheet-image`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(n.ISheetDrawingService);if(!r)return!1;let s=[];r.forEach(({parent:e,children:t})=>{s.push(e.unitId),t.forEach(e=>{s.push(e.unitId)})});let{unitId:c,subUnitId:l,undo:u,redo:d,objects:f}=o.getUngroupDrawingOp(r);return i.syncExecuteCommand(n.SetDrawingApplyMutation.id,{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.UNGROUP})?(a.pushUndoRedo({unitID:c,undoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:_(f),type:n.DrawingApplyType.GROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}],redoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.UNGROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}]}),!0):!1}};function C(e){"@babel/helpers - typeof";return C=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},C(e)}function w(e,t){if(C(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(C(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function T(e){var t=w(e,`string`);return C(t)==`symbol`?t:t+``}function E(e,t,n){return(t=T(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function D(e,t){return function(n,r){t(n,r,e)}}function O(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 k(e,t,n){let r=n*Math.PI/180;return{rotatedWidth:Math.abs(e*Math.cos(r))+Math.abs(t*Math.sin(r)),rotatedHeight:Math.abs(e*Math.sin(r))+Math.abs(t*Math.cos(r))}}function A(e,t,n,i,a){var o;let{rotatedHeight:s,rotatedWidth:l}=k(n,i,a),u=e.get(r.IRenderManagerService).getRenderUnitById(t.unitId);if(!u)return!1;let d=(o=u.with(c.SheetSkeletonManagerService).getSkeletonParam(t.subUnitId))==null?void 0:o.skeleton;if(d==null)return!1;let f=d.getCellWithCoordByIndex(t.row,t.col),p=f.mergeInfo.endX-f.mergeInfo.startX-2,m=f.mergeInfo.endY-f.mergeInfo.startY-2,h=l/s,g=Math.ceil(Math.min(p,m*h))/l,_=!g||Number.isNaN(g)?.001:g;return{width:n*_,height:i*_}}let j=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m){super(),this._context=e,this._commandService=t,this._sheetInterceptorService=n,this._selectionRenderService=r,this._imageIoService=i,this._fileOpenerService=a,this._sheetDrawingService=o,this._drawingManagerService=s,this._contextService=c,this._messageService=l,this._localeService=u,this._sheetSkeletonService=f,this._injector=p,this._urlImageService=m,E(this,`_workbookSelections`,void 0),this._workbookSelections=d.getWorkbookSelections(this._context.unitId),this._updateDrawingListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){let e=await this._fileOpenerService.openFile({multiple:!0,accept:o.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace(`image/`,``)}`).join(`,`)}),t=e.length;return t>o.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxCount`,String(o.DRAWING_IMAGE_COUNT_LIMIT))}),!1):t===0?!1:(e.forEach(async e=>await this.insertFloatImageByFile(e)),!0)}async insertCellImage(){let e=(await this._fileOpenerService.openFile({multiple:!1,accept:o.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace(`image/`,``)}`).join(`,`)}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(e,t){return this._insertCellImage(e,t)}async insertFloatImageByFile(e){let r;try{r=await this._imageIoService.saveImage(e)}catch(e){let n=e.message;n===t.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxSize`,String((0,o.getDrawingImageAllowSize)()/(1024*1024)))}):n===t.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImageType`)}):n===t.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImage`)})}if(r==null)return;let{unitId:a,subUnitId:s}=this._getUnitInfo(),{imageId:c,imageSourceType:l,source:u,base64Cache:d}=r,{width:f,height:p,image:m}=await(0,o.getImageSize)(d||``),{width:h,height:g}=this._context.scene;this._imageIoService.addImageSourceCache(u,l,m);let _=1;if(f>o.DRAWING_IMAGE_WIDTH_LIMIT||p>o.DRAWING_IMAGE_HEIGHT_LIMIT){let e=o.DRAWING_IMAGE_WIDTH_LIMIT/f,t=o.DRAWING_IMAGE_HEIGHT_LIMIT/p;_=Math.max(e,t)}let v=this._sheetSkeletonService.getSkeletonParam(a,s);if(!v)return;let{skeleton:y}=v,b=this._getImagePosition(f*_,p*_,h,g,y);if(!b)return;let x=(0,n.drawingPositionToTransform)(b,v);if(!x)return;let S={unitId:a,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:u,transform:x,sheetTransform:b,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(x,y)??b};return this._commandService.executeCommand(n.InsertSheetDrawingCommand.id,{unitId:a,drawings:[S]})}async _insertCellImage(e,n){let r;try{r=await this._imageIoService.saveImage(e)}catch(e){let n=e.message;n===t.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxSize`,String((0,o.getDrawingImageAllowSize)()/(1024*1024)))}):n===t.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImageType`)}):n===t.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImage`)})}if(r==null)return!1;let{imageId:c,imageSourceType:l,source:u,base64Cache:d}=r,{width:f,height:p,image:m}=await(0,o.getImageSize)(d||``);this._imageIoService.addImageSourceCache(u,l,m);let h=this._workbookSelections.getCurrentLastSelection();if(!h)return!1;let g=h.primary.actualRow,_=h.primary.actualColumn;h.primary.isMerged&&(g=h.primary.startRow,_=h.primary.startColumn);let v=(0,t.createDocumentModelWithStyle)(``,{}),y=A(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:g,col:_},f,p,0);if(!y)return!1;let b=(0,a.buildDocTransform)(y.width,y.height),x={unitId:v.getUnitId(),subUnitId:v.getUnitId(),drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:u,transform:(0,a.docDrawingPositionToTransform)(b),docTransform:b,behindDoc:t.BooleanNumber.FALSE,title:``,description:``,layoutType:t.PositionedObjectLayoutType.INLINE,wrapText:t.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=t.BuildTextUtils.drawing.add({documentDataModel:v,drawings:[x],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(v.apply(S),this._commandService.syncExecuteCommand(s.SetRangeValuesCommand.id,{value:{[(n==null?void 0:n.row)??g]:{[(n==null?void 0:n.col)??_]:{p:v.getSnapshot(),t:1}}},unitId:n==null?void 0:n.unitId,subUnitId:n==null?void 0:n.subUnitId})):!1}async insertCellImageByUrl(e,n){let r=e;try{r=await this._urlImageService.getImage(e)}catch(t){console.error(`Failed to get image from URLImageService: ${e}`,t)}let{width:i,height:c,image:l}=await(0,o.getImageSize)(r||``);this._imageIoService.addImageSourceCache(e,t.ImageSourceType.URL,l);let u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;let d=(0,t.createDocumentModelWithStyle)(``,{}),f=A(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},i,c,0);if(!f)return!1;let p=(0,a.buildDocTransform)(f.width,f.height),m={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:(0,t.generateRandomId)(),drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t.ImageSourceType.URL,source:e,transform:(0,a.docDrawingPositionToTransform)(p),docTransform:p,behindDoc:t.BooleanNumber.FALSE,title:``,description:``,layoutType:t.PositionedObjectLayoutType.INLINE,wrapText:t.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},h=t.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[m],selection:{collapsed:!0,startOffset:0,endOffset:0}});return h?(d.apply(h),this._commandService.syncExecuteCommand(s.SetRangeValuesCommand.id,{value:{[(n==null?void 0:n.row)??u.primary.actualRow]:{[(n==null?void 0:n.col)??u.primary.actualColumn]:{p:d.getSnapshot(),t:1}}},unitId:n==null?void 0:n.unitId,subUnitId:n==null?void 0:n.subUnitId})):!1}_getUnitInfo(){let e=this._context.unit,t=e.getActiveSheet();return{unitId:e.getUnitId(),subUnitId:t.getSheetId()}}_getImagePosition(e,t,n,r,i){let a=this._workbookSelections.getCurrentSelections(),o={startRow:0,endRow:0,startColumn:0,endColumn:0};a&&a.length>0&&(o=a[a.length-1].range);let c=(0,s.attachRangeWithCoord)(i,o);if(c==null)return;let{startColumn:l,startRow:u,startX:d,startY:f}=c,p=!1;if(d+e>n&&(d=n-e,d<0&&(d=0,e=n),p=!0),f+t>r&&(f=r-t,f<0&&(f=0,t=r),p=!0),p){let e=this._selectionRenderService.getCellWithCoordByOffset(d,f);if(e==null)return;d=e.startX,f=e.startY,l=e.actualColumn,u=e.actualRow}let m={column:l,columnOffset:0,row:u,rowOffset:0},h=this._selectionRenderService.getCellWithCoordByOffset(d+e,f+t);if(h!=null)return{from:m,to:{column:h.actualColumn,columnOffset:d+e-h.startX,row:h.actualRow,rowOffset:f+t-h.startY}}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{let{unitId:t,subUnitId:r,drawingIds:i,arrangeType:a}=e;this._commandService.executeCommand(n.SetDrawingArrangeCommand.id,{unitId:t,subUnitId:r,drawingIds:i,arrangeType:a})}))}_updateDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{let t=[];e.length!==0&&(e.forEach(e=>{let{unitId:r,subUnitId:i,drawingId:a,transform:o}=e,s=this._sheetSkeletonService.getSkeletonParam(r,i);if(!o||!s)return;let{skeleton:c}=s,l=this._sheetDrawingService.getDrawingByParam({unitId:r,subUnitId:i,drawingId:a});if(l==null||l.unitId!==this._context.unitId)return;let u=(0,n.transformToDrawingPosition)({...l.transform,...o},c),d=(0,n.transformToAxisAlignPosition)({...l.transform,...o},c);if(u==null||d==null)return;let f={...e,transform:{...l.transform,...o,...(0,n.drawingPositionToTransform)(u,s)},sheetTransform:{...u},axisAlignSheetTransform:{...d}};t.push(f)}),t.length>0&&this._commandService.executeCommand(n.SetSheetDrawingCommand.id,{unitId:e[0].unitId,drawings:t}))}))}_getSheetTransformByParam(e,t){let{unitId:r,subUnitId:i,drawingId:a,transform:o}=e,s=this._sheetSkeletonService.getSkeleton(r,i);if(!o||!s)return null;let c=this._sheetDrawingService.getDrawingByParam({unitId:r,subUnitId:i,drawingId:a}),l=c==null?void 0:c.transform;if(t&&(l={}),!t&&(!c||c.unitId!==this._context.unitId))return null;let u=(0,n.transformToDrawingPosition)({...l,...o},s),d=(0,n.transformToAxisAlignPosition)({...l,...o},s);return!u||!d?null:{sheetTransform:u,axisAlignSheetTransform:d}}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{let t=[];for(let n of e){let e=n.parent,r=this._getSheetTransformByParam(e,!0),i=[];for(let e of n.children){let t=this._getSheetTransformByParam(e,!1);t!=null&&i.push({...e,sheetTransform:t.sheetTransform,axisAlignSheetTransform:t.axisAlignSheetTransform})}let a={parent:{...e,sheetTransform:r==null?void 0:r.sheetTransform,axisAlignSheetTransform:r==null?void 0:r.axisAlignSheetTransform},children:i};t.push(a)}if(t.length>0){this._commandService.executeCommand(x.id,t);let{unitId:n,subUnitId:r,drawingId:i}=e[0].parent;this._commandService.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:r,drawingId:i}])}})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{let t=[];for(let n of e){let{children:e}=n,r=[];for(let t of e){let e=this._getSheetTransformByParam(t,!1);e!=null&&r.push({...t,sheetTransform:e.sheetTransform,axisAlignSheetTransform:e.axisAlignSheetTransform})}t.push({...n,children:r})}this._commandService.executeCommand(S.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}};j=O([D(1,t.ICommandService),D(2,(0,t.Inject)(s.SheetInterceptorService)),D(3,c.ISheetSelectionRenderService),D(4,t.IImageIoService),D(5,l.ILocalFileService),D(6,n.ISheetDrawingService),D(7,o.IDrawingManagerService),D(8,t.IContextService),D(9,l.IMessageService),D(10,(0,t.Inject)(t.LocaleService)),D(11,(0,t.Inject)(s.SheetsSelectionsService)),D(12,(0,t.Inject)(s.SheetSkeletonService)),D(13,(0,t.Inject)(t.Injector)),D(14,t.IURLImageService)],j);let M={id:`sheet.command.insert-float-image`,type:t.CommandType.COMMAND,handler:async(e,n)=>{var i;let a=e.get(t.IUniverInstanceService),o=e.get(r.IRenderManagerService),s=(i=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,a,o))==null?void 0:i.with(j);if(!s)return!1;let c=n==null?void 0:n.files;if(c){let e=c.map(e=>s.insertFloatImageByFile(e));return(await Promise.all(e)).every(e=>e)}else return s.insertFloatImage()??!1}},N={id:`sheet.command.insert-cell-image`,type:t.CommandType.COMMAND,handler:e=>{var n;let i=e.get(t.IUniverInstanceService),a=e.get(r.IRenderManagerService);return((n=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,i,a))==null?void 0:n.with(j).insertCellImage())??!1}},P={id:`sheet.command.move-drawing`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(n.ISheetDrawingService),o=e.get(s.SheetSkeletonService),c=e.get(l.UndoRedoGroupService),{direction:u}=r,d=a.getFocusDrawings();if(d.length===0)return!1;let f=d[0].unitId,p=d.map(e=>{let{transform:r,unitId:i,subUnitId:a}=e,s=o.getSkeleton(i,a);if(!r||!s)return null;let c={...r},{left:l=0,top:d=0}=r;return u===t.Direction.UP?c.top=d-1:u===t.Direction.DOWN?c.top=d+1:u===t.Direction.LEFT?c.left=l-1:u===t.Direction.RIGHT&&(c.left=l+1),{...e,transform:c,sheetTransform:(0,n.transformToDrawingPosition)(c,s),axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(c,s)}}).filter(e=>e!=null);return c.runTimed(f,`sheet-drawing:nudge:${d[0].subUnitId}:${d.map(e=>e.drawingId).sort().join(`,`)}`,()=>i.syncExecuteCommand(n.SetSheetDrawingCommand.id,{unitId:f,drawings:p}))?(i.syncExecuteCommand(n.ClearSheetDrawingTransformerOperation.id,[f]),!0):!1}},F=function(e){return e.CELL_ADDRESS=`cellAddress`,e.COLUMN_VALUE=`columnValue`,e}({}),I=(0,t.createIdentifier)(`sheets-drawing-ui.batch-save-images.service`);function L(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function R(e,t){return`${L(t)}${e+1}`}function z(e){let t=R(e.startRow,e.startColumn),n=R(e.endRow,e.endColumn);return t===n?t:`${t}:${n}`}function B(e){var t;let n=e.p,r=n==null||(t=n.drawingsOrder)==null?void 0:t[0];if(!(0,s.isCellImage)(n)||!r||!(n!=null&&n.drawings))return null;let i=n.drawings[r];return!i||!(`source`in i)||!(`imageSourceType`in i)?null:i}function V(e,n){if(n===t.ImageSourceType.BASE64){let t=e.match(/^data:image\/(\w+);/);if(t)return t[1]===`jpeg`?`jpg`:t[1]}if(n===t.ImageSourceType.URL){let t=e.match(/\.(\w+)(?:\?|$)/);if(t)return t[1].toLowerCase()}return`png`}async function H(e,n){if(n===t.ImageSourceType.BASE64||n===t.ImageSourceType.URL)return(await fetch(e)).blob();throw Error(`UUID image type requires additional handling`)}let U=class extends t.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._selectionService=t,this._imageIoService=n,this._urlImageService=r}getCellImagesInSelection(){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return[];let n=e.getActiveSheet();if(!n)return[];let r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return[];let i=n.getCellMatrix(),a=[];for(let e of r){let{startRow:t,endRow:n,startColumn:r,endColumn:o}=e.range;for(let e=t;e<=n;e++)for(let t=r;t<=o;t++){let n=i.getValue(e,t);if((0,s.isCellImage)(n==null?void 0:n.p)){let r=B(n);r&&a.push({row:e,col:t,cellAddress:R(e,t),source:r.source,imageSourceType:r.imageSourceType,imageId:r.drawingId})}}}return a}getCellImagesFromRanges(e,n,r){let i=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!i)return[];let a=i.getSheetBySheetId(n);if(!a)return[];let o=a.getCellMatrix(),c=[];for(let e of r){let{startRow:t,endRow:n,startColumn:r,endColumn:i}=e;for(let e=t;e<=n;e++)for(let t=r;t<=i;t++){let n=o.getValue(e,t);if((0,s.isCellImage)(n==null?void 0:n.p)){let r=B(n);r&&c.push({row:e,col:t,cellAddress:R(e,t),source:r.source,imageSourceType:r.imageSourceType,imageId:r.drawingId})}}}return c}getDataColumns(){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return[];let n=e.getActiveSheet();if(!n)return[];let r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return[];let i=n.getCellMatrix(),a=i.getDataRange(),o=1/0,s=-1/0,c=new Set;for(let e of r){o=Math.min(o,e.range.startRow),s=Math.max(s,e.range.endRow);for(let t=e.range.startColumn;t<=e.range.endColumn;t++)c.add(t)}let l=new Set;for(let e=a.startColumn;e<=a.endColumn;e++)if(!c.has(e))for(let t=o;t<=s;t++){let n=i.getValue(t,e);if(n){var u,d;if((u=n.v)!=null&&u.toString()||(d=n.p)!=null&&(d=d.body)!=null&&(d=d.dataStream)!=null&&d.trim()){l.add(e);break}}}let f=[],p=Array.from(l).sort((e,t)=>e-t);for(let e of p)f.push({index:e,label:L(e)});return f}getDataColumnsForRanges(e,n,r){let i=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!i)return[];let a=i.getSheetBySheetId(n);if(!a)return[];let o=a.getCellMatrix(),s=o.getDataRange(),c=1/0,l=-1/0,u=new Set;for(let e of r){c=Math.min(c,e.startRow),l=Math.max(l,e.endRow);for(let t=e.startColumn;t<=e.endColumn;t++)u.add(t)}let d=new Set;for(let e=s.startColumn;e<=s.endColumn;e++)if(!u.has(e))for(let t=c;t<=l;t++){let n=o.getValue(t,e);if(n){var f,p;if((f=n.v)!=null&&f.toString()||(p=n.p)!=null&&(p=p.body)!=null&&(p=p.dataStream)!=null&&p.trim()){d.add(e);break}}}let m=[],h=Array.from(d).sort((e,t)=>e-t);for(let e of h)m.push({index:e,label:L(e)});return m}getSelectionRangeNotation(){let e=this._selectionService.getCurrentSelections();return!e||e.length===0?``:e.map(e=>z(e.range)).join(`, `)}getSelectionRowRange(){let e=this._selectionService.getCurrentSelections();if(!e||e.length===0)return null;let t=1/0,n=-1/0;for(let r of e)t=Math.min(t,r.range.startRow),n=Math.max(n,r.range.endRow);return{startRow:t,endRow:n}}getSelectionColumnIndices(){let e=this._selectionService.getCurrentSelections();if(!e||e.length===0)return new Set;let t=new Set;for(let n of e)for(let e=n.range.startColumn;e<=n.range.endColumn;e++)t.add(e);return t}generateFileName(e,n){let r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),i=V(e.source,e.imageSourceType),a=[];for(let t of n.fileNameParts)if(t===`cellAddress`)a.push(e.cellAddress);else if(t===`columnValue`&&n.columnIndex!==void 0){let t=r==null?void 0:r.getActiveSheet();if(t){let r=t.getCellMatrix().getValue(e.row,n.columnIndex);if(r){var o,s;let e=((o=r.v)==null?void 0:o.toString())||((s=r.p)==null||(s=s.body)==null||(s=s.dataStream)==null?void 0:s.trim())||``;if(e){let t=e.replace(/[<>:"/\\|?*]/g,`_`).trim();t&&a.push(t)}}}}return a.length===0?`${e.cellAddress}.${i}`:`${a.join(`_`)}.${i}`}generateFileNameWithContext(e,n,r,i){let a=this._univerInstanceService.getUnit(r,t.UniverInstanceType.UNIVER_SHEET),o=V(e.source,e.imageSourceType),s=[];for(let t of n.fileNameParts)if(t===`cellAddress`)s.push(e.cellAddress);else if(t===`columnValue`&&n.columnIndex!==void 0){let t=a==null?void 0:a.getSheetBySheetId(i);if(t){let r=t.getCellMatrix().getValue(e.row,n.columnIndex);if(r){var c,l;let e=((c=r.v)==null?void 0:c.toString())||((l=r.p)==null||(l=l.body)==null||(l=l.dataStream)==null?void 0:l.trim())||``;if(e){let t=e.replace(/[<>:"/\\|?*]/g,`_`).trim();t&&s.push(t)}}}}return s.length===0?`${e.cellAddress}.${o}`:`${s.join(`_`)}.${o}`}async saveImages(e,t){let n=await window.showDirectoryPicker({mode:`readwrite`}),r=new Map;for(let a of e){var i;let e=this.generateFileName(a,t),o=e.replace(/\.\w+$/,``),s=((i=e.match(/\.\w+$/))==null?void 0:i[0])||`.png`,c=r.get(o)||0;c>0&&(e=`${o}_${c}${s}`),r.set(o,c+1);try{let t=await this._getImageBlob(a),r=await(await n.getFileHandle(e,{create:!0})).createWritable();await r.write(t),await r.close()}catch(t){throw console.error(`Failed to save image ${e}:`,t),t}}}async saveImagesWithContext(e,t,n,r){let i=await window.showDirectoryPicker({mode:`readwrite`}),a=new Map;for(let s of e){var o;let e=this.generateFileNameWithContext(s,t,n,r),c=e.replace(/\.\w+$/,``),l=((o=e.match(/\.\w+$/))==null?void 0:o[0])||`.png`,u=a.get(c)||0;u>0&&(e=`${c}_${u}${l}`),a.set(c,u+1);try{let t=await this._getImageBlob(s),n=await(await i.getFileHandle(e,{create:!0})).createWritable();await n.write(t),await n.close()}catch(t){throw console.error(`Failed to save image ${e}:`,t),t}}}async downloadSingleImage(e){let t=V(e.source,e.imageSourceType),n=`${e.cellAddress}.${t}`;try{let t=await this._getImageBlob(e),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=n,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}catch(e){throw console.error(`Failed to download image ${n}:`,e),e}}async _getImageBlob(e){return e.imageSourceType===t.ImageSourceType.UUID?H(await this._imageIoService.getImage(e.source),t.ImageSourceType.URL):e.imageSourceType===t.ImageSourceType.URL?this._urlImageService.downloadImage(e.source):H(e.source,e.imageSourceType)}};U=O([D(0,t.IUniverInstanceService),D(1,(0,t.Inject)(s.SheetsSelectionsService)),D(2,t.IImageIoService),D(3,t.IURLImageService)],U);let W=`sheet.dialog.batch-save-images`,G={id:`sheet.command.save-cell-images`,type:t.CommandType.COMMAND,handler:async e=>{let n=e.get(l.IDialogService),r=e.get(I),i=r.getCellImagesInSelection();if(i.length===1)try{return await r.downloadSingleImage(i[0]),!0}catch(e){return console.error(`Failed to download image:`,e),!1}let a=e.get(t.LocaleService),o=r.getSelectionRangeNotation(),s=`${a.t(`sheets-drawing-ui.save.title`)} (${o})`;return n.open({id:W,draggable:!0,width:360,title:{title:s},children:{label:W},preservePositionOnDestroy:!0,onClose:()=>n.close(W)}),!0}},K=`COMPONENT_SHEET_DRAWING_PANEL`,q={id:`sidebar.operation.sheet-image`,type:t.CommandType.COMMAND,handler:async(e,n)=>{let r=e.get(l.ISidebarService),i=e.get(t.LocaleService),a=e.get(t.IUniverInstanceService),c=e.get(o.IDrawingManagerService),u=e.get(t.ICommandService);if(!(0,s.getSheetCommandTarget)(a))return!1;switch(n.value){case`open`:r.open({id:K,header:{title:i.t(`sheets-drawing-ui.panel.title`)},children:{label:K},onClose:()=>{let e=c.getFocusDrawings();e.length===1&&e[0].drawingType===t.DrawingTypeEnum.DRAWING_IMAGE&&u.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[])},width:360});break;default:r.close(K);break}return!0}},J={id:`sheet.operation.edit-sheet-image`,type:t.CommandType.OPERATION,handler:(e,n)=>{let r=e.get(t.ICommandService);return n==null?!1:(r.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[n]),r.executeCommand(q.id,{value:`open`}),!0)}},Y=[c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA],X=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._sheetClipboardService=e,this._renderManagerService=t,this._sheetSkeletonService=n,this._sheetDrawingService=r,this._drawingManagerService=i,E(this,`_featurePasteHooks`,[]),E(this,`_copyInfo`,void 0),this._initCopyPaste()}get _focusedDrawings(){return this._sheetDrawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:`SHEET_DRAWING_GROUP`,onBeforeCopy:(e,n)=>{this._copyInfo=null;let r=this._focusedDrawings;if(r.length===0)return;let i=r.find(e=>e.drawingType===t.DrawingTypeEnum.DRAWING_GROUP);if(!i)return;let a=this._drawingManagerService.getDrawingsByGroupNested({unitId:i.unitId,subUnitId:i.subUnitId,drawingId:i.drawingId});a&&(this._copyInfo={unitId:i.unitId,subUnitId:i.subUnitId,groupNestedParam:a})},onPasteCells:(e,t,n,r)=>{if(!this._copyInfo)return{redos:[],undos:[]};let{pasteType:i}=r;return Y.includes(i)?{redos:[],undos:[]}:this._generateGroupPasteMutations(t)},onPasteUnrecognized:e=>this._copyInfo?this._generateGroupPasteMutations(e):{redos:[],undos:[]}})}registerFeaturePasteHook(e){this._featurePasteHooks.push(e)}_getGroupFeaturePasteMutations(e){let t=[],n=[];for(let r of this._featurePasteHooks){let i=r(e);t.push(...i.redos),n.push(...i.undos)}return{redos:t,undos:n}}_generateGroupPasteMutations(e){if(!this._copyInfo)return{redos:[],undos:[]};let{unitId:t,subUnitId:r,range:i}=e,a=this._sheetSkeletonService.getSkeleton(t,r);if(!a)return{redos:[],undos:[]};let{groupNestedParam:o}=this._copyInfo,c=o.groups[o.groups.length-1],{cloned:l,idMap:u}=y(o),d=l.groups[l.groups.length-1].drawingId,f=(0,s.discreteRangeToRange)(i),p=(0,s.attachRangeWithCoord)(a,{startRow:f.startRow,endRow:f.endRow,startColumn:f.startColumn,endColumn:f.endColumn});if(!p)return{redos:[],undos:[]};let m={...c.transform,left:p.startX,top:p.startY},h=[...(l.flatChildren??[]).map(e=>({...e,unitId:t,subUnitId:r})),...l.groups.map(e=>e.drawingId===d?{...e,unitId:t,subUnitId:r,transform:m,sheetTransform:(0,n.transformToDrawingPosition)(m,a)??c.sheetTransform,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(m,a)??c.sheetTransform}:{...e,unitId:t,subUnitId:r})],{undo:g,redo:_,objects:v}=this._sheetDrawingService.getBatchAddOp(h),b=[{id:n.SetDrawingApplyMutation.id,params:{op:_,unitId:t,subUnitId:r,objects:v,type:n.DrawingApplyType.INSERT}}],x=[{id:n.SetDrawingApplyMutation.id,params:{op:g,unitId:t,subUnitId:r,objects:v,type:n.DrawingApplyType.REMOVE}}],S=this._getGroupFeaturePasteMutations({fromUnitId:this._copyInfo.unitId,fromSubUnitId:this._copyInfo.subUnitId,toUnitId:t,toSubUnitId:r,idMap:u,cloned:l});return b.push(...S.redos),x.push(...S.undos),{redos:b,undos:x}}dispose(){this._copyInfo=null,this._featurePasteHooks.length=0,super.dispose()}};X=O([D(0,c.ISheetClipboardService),D(1,r.IRenderManagerService),D(2,(0,t.Inject)(s.SheetSkeletonService)),D(3,n.ISheetDrawingService),D(4,o.IDrawingManagerService)],X);let ee=Object.freeze({borderEnabled:!1,paintFirst:`stroke`,radius:8,rotateEnabled:!1,strokeWidth:1});var te;let ne=`univer-sheet-float-dom-`;function re(e,t,n){let r=new WeakRef(e),i=!1;return{id:t,dispose(){if(i)return;i=!0;let e=r.deref();e&&n(e,t)}}}let ie={borderEnabled:!0,borderStroke:`#4086f4`,borderStrokeWidth:1,borderSpacing:2,anchorFill:`#ffffff`,anchorStroke:`#4086f4`,anchorStrokeWidth:1.5,anchorSize:8,anchorCornerRadius:2,anchorStyle:`canva`,rotateEnabled:!1,resizeEnabled:!0,moveBoundaryEnabled:!1},ae={borderEnabled:!0,borderStroke:`#4086f4`,borderStrokeWidth:1,borderSpacing:2,anchorFill:`#ffffff`,anchorStroke:`#4086f4`,anchorStrokeWidth:1.5,anchorSize:8,anchorCornerRadius:2,anchorStyle:`canva`,rotateEnabled:!1,resizeEnabled:!0,keepRatio:!1,moveBoundaryEnabled:!1},oe=-100,se=`univer:embed-float-drag-handle:pointerdown`;function ce(e,t){return t.hostAnchorId===e.id&&(t.hostUnitId==null||t.hostUnitId===e.unitId)&&(t.button==null||t.button===0)&&typeof t.clientX==`number`&&typeof t.clientY==`number`}function le(e,t){if(typeof t.clientX==`number`&&typeof t.clientY==`number`)return{pointerId:t.pointerId,startClientX:t.clientX,startClientY:t.clientY,startLeft:Number(e.rect.left??0),startTop:Number(e.rect.top??0)}}function ue(e,t,n){let{scaleX:r,scaleY:i}=n.getAncestorScale();return{left:e.startLeft+(t.clientX-e.startClientX)/(r||1),top:e.startTop+(t.clientY-e.startClientY)/(i||1)}}function de(e,t){let n=t.data;if(!n||typeof n!=`object`)return;let r=n;r.version===1&&typeof r.embedId==`string`&&(e.transformerConfig={...ie,keepRatio:r.resizeBehavior===`aspect-ratio`})}function fe(e){e.transformerConfig={...e.transformerConfig,...ae}}function pe(e){if(!me(e))return!1;let n=e.data;return n.hostType===t.UniverInstanceType.UNIVER_SHEET&&n.childType===t.UniverInstanceType.UNIVER_SHEET&&n.runtimeMountMode===`stage2`}function me(e){let t=e.data;if(!t||typeof t!=`object`)return!1;let n=t;return n.version===1&&typeof n.embedId==`string`}function he(e){if(!me(e))return!1;let n=e.data;return n.hostType===t.UniverInstanceType.UNIVER_SHEET&&n.childType!=null}function ge(e,t=`inactive`){return{autoMountRuntime:!pe(e),passThroughRuntimeEvents:!(he(e)&&t===`stage2`),preserveOnFocusChange:me(e),usePreviewObject:pe(e)}}function _e(e){return ge(e).autoMountRuntime}function ve(e){return ge(e).preserveOnFocusChange}function ye(e){return ge(e).usePreviewObject}function be(e,t=`inactive`){return ge(e,t).passThroughRuntimeEvents}function xe(e){return me(e)&&!_e(e)}function Se(e,t){var n,r;if(!he(e))return!0;let i=t.target,a=i==null||(n=i.closest)==null?void 0:n.call(i,`[data-embed-float-dom="true"]`);return(a==null||(r=a.dataset)==null?void 0:r.embedFloatStage)!==`stage2`}function Ce(e){return e!==`stage2`}function we(e,t,n){if(t){if(e===`stage1`){var r,i;(r=(i=t.scene).attachTransformerTo)==null||r.call(i,n);return}if(e===`stage2`&&n.oKey){var a,o,s;t.transformer.clearControlByIds([n.oKey]),(a=(o=t.scene).getTransformer)==null||(a=a.call(o))==null||(s=a.clearSelectedObjects)==null||s.call(a)}}}function Te(e,t){return e.domLayers.some(([e])=>e===t)}function Ee(e){return e===t.DrawingTypeEnum.DRAWING_DOM||e===t.DrawingTypeEnum.DRAWING_BLOCK||e===t.DrawingTypeEnum.DRAWING_CHART}function De(e,t){if(e.runtimeMounted||e.runtimeStage!==`stage1`)return!1;let{offsetX:n,offsetY:r}=t;if(typeof n!=`number`||typeof r!=`number`)return!1;let i=e.position$.getValue();if(n>=Math.min(i.startX,i.endX)&&n<=Math.max(i.startX,i.endX)&&r>=Math.min(i.startY,i.endY)&&r<=Math.max(i.startY,i.endY))return!0;let a=e.rect;if(typeof a.isHit==`function`)try{return a.isHit({x:n,y:r})}catch{}return n>=a.left&&n<=a.left+a.width&&r>=a.top&&r<=a.top+a.height}function Oe(e,t){if(!(t.type!==`pointerdown`||!De(e,t)))return{pointerId:t.pointerId,startOffsetX:t.offsetX,startOffsetY:t.offsetY,startedAt:Date.now()}}function ke(e,t,n){return!t||n.type!==`pointerup`||t.pointerId!=null&&n.pointerId!=null&&t.pointerId!==n.pointerId||!De(e,n)?!1:Math.hypot(n.offsetX-t.startOffsetX,n.offsetY-t.startOffsetY)<=4}function Ae(e,n,i,a,o,s=!1){let{scaleX:c,scaleY:l}=n.getAncestorScale(),u=n.getViewport(r.SHEET_VIEWPORT_KEY.VIEW_MAIN),{startColumn:d,startRow:f,xSplit:p,ySplit:m}=a.getFreeze(),h={left:!0,top:!0};if(!u)return{...e,absolute:h};let{left:g,right:_,top:v,bottom:y}=e,{top:b,left:x,viewportScrollX:S,viewportScrollY:C}=u,{boundsOfViewArea:w,scrollDirectionResponse:T}=o||{},{rowHeaderWidth:E,columnHeaderHeight:D}=i,O={top:s?0:D,left:s?0:E};w&&(t.Tools.isDefine(O.top)&&(O.top=w.top),t.Tools.isDefine(O.left)&&(O.left=w.left)),T===`HORIZONTAL`&&(C=0),T===`VERTICAL`&&(S=0);let k=0,A=0,j=i.rowStartY(f-m)+D,M=i.colStartX(d-p)+E,N=i.rowStartY(f)+D,P=i.colStartX(d)+E;if(p===0)h.left=!1,k=(g-S)*c,A=(_-S)*c;else{let e=g-(M-E),t=_-(M-E);_<P?(k=e*c,A=t*c):g<=P&&_>=P?(k=e*c,A=Math.max(x,(_-S)*c)):g>P&&(h.left=!1,k=Math.max((g-S)*c,x),A=Math.max((_-S)*c,x))}let F=0,I=0;if(m===0)h.top=!1,F=(v-C)*l,I=(y-C)*l;else{let e=v-(j-D),t=y-(j-D);y<N?(F=e*l,I=t*l):v<=N&&y>=N?(F=e*l,I=Math.max(b,(y-C)*l)):v>N&&(h.top=!1,F=Math.max((v-C)*l,b),I=Math.max((y-C)*l,b))}return k=Math.max(k,O.left),F=Math.max(F,O.top),A=Math.max(A,O.left),I=Math.max(I,O.top),{left:k,right:A,top:F,bottom:I,absolute:h}}let Z=(e,t,n,r,i)=>{let{left:a,top:o,width:s,height:c,angle:l}=e,u=Ae({left:a,right:a+s,top:o,bottom:o+c},t,n,r,i),{scaleX:d,scaleY:f}=t.getAncestorScale();return{startX:u.left,endX:u.right,startY:u.top,endY:u.bottom,rotate:l,width:s*d,height:c*f,absolute:u.absolute}},Q=te=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._renderManagerService=e,this._univerInstanceService=t,this._commandService=n,this._drawingManagerService=r,this._canvasFloatDomService=i,this._sheetDrawingService=a,this._lifecycleService=o,this._canvasFloatDomPreviewService=s,E(this,`_domLayerInfoMap`,new Map),E(this,`_transformChange$`,new d.Subject),E(this,`transformChange$`,this._transformChange$.asObservable()),E(this,`_add$`,new d.Subject),E(this,`add$`,this._add$.asObservable()),E(this,`_remove$`,new d.Subject),E(this,`remove$`,this._remove$.asObservable()),E(this,`_renderObjectFactories`,new Map),this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent(),this._bindEmbedFloatDragHandleEvent()}registerRenderObjectFactory(e,t){let n=this._renderObjectFactories.get(e)??[];return n.push(t),this._renderObjectFactories.set(e,n),{dispose:()=>{let n=this._renderObjectFactories.get(e);if(!n)return;let r=n.indexOf(t);r>=0&&n.splice(r,1),n.length===0&&this._renderObjectFactories.delete(e)}}}_createRenderObject(e){let t=this._renderObjectFactories.get(e.drawingType),n=t==null?void 0:t[t.length-1];return(n==null?void 0:n(e))??new r.Rect(e.key,e.config)}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe((0,d.filter)(e=>e===t.LifecycleStages.Rendered),(0,d.take)(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(e){return this._domLayerInfoMap.get(e)}getFloatDomsBySubUnitId(e,t){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===t&&n.unitId===e)}static _disposeExternalFloatDom(e,t){e._removeDom(t,!0)}_createFloatDomDisposable(e){return re(this,e,te._disposeExternalFloatDom)}_bindEmbedFloatDragHandleEvent(){if(typeof document>`u`)return;let e=e=>this._handleEmbedFloatDragHandlePointerDown(e);document.addEventListener(se,e),this.disposeWithMe(()=>document.removeEventListener(se,e))}_handleEmbedFloatDragHandlePointerDown(e){let t=e.detail;if(!(t!=null&&t.hostAnchorId))return;let n=this._domLayerInfoMap.get(t.hostAnchorId);if(!n||!ce(n,t))return;let r=le(n,t),i=this._getSceneAndTransformerByDrawingSearch(n.unitId);if(!r||!i)return;let{scene:a,transformer:o}=i;if(n.rect.oKey){var s;o.clearControlByIds([n.rect.oKey]),(s=a.getTransformer())==null||s.clearSelectedObjects()}let c=e=>{if(r.pointerId!=null&&e.pointerId!==r.pointerId)return;e.preventDefault();let t=ue(r,e,a);n.rect.transformByState(t)},l=e=>{if((r.pointerId==null||e.pointerId===r.pointerId)&&(window.removeEventListener(`pointermove`,c,!0),window.removeEventListener(`pointerup`,l,!0),window.removeEventListener(`pointercancel`,u,!0),e.preventDefault(),(n.rect.left!==r.startLeft||n.rect.top!==r.startTop)&&this._commitFloatDomMove(n),n.runtimeStage===`stage1`)){var t;(t=a.attachTransformerTo)==null||t.call(a,n.rect)}},u=e=>{if((r.pointerId==null||e.pointerId===r.pointerId)&&(window.removeEventListener(`pointermove`,c,!0),window.removeEventListener(`pointerup`,l,!0),window.removeEventListener(`pointercancel`,u,!0),n.rect.transformByState({left:r.startLeft,top:r.startTop}),n.runtimeStage===`stage1`)){var t;(t=a.attachTransformerTo)==null||t.call(a,n.rect)}};window.addEventListener(`pointermove`,c,!0),window.addEventListener(`pointerup`,l,!0),window.addEventListener(`pointercancel`,u,!0)}_commitFloatDomMove(e){var t;let r=(t=this._renderManagerService.getRenderUnitById(e.unitId))==null?void 0:t.with(c.SheetSkeletonManagerService).getSkeletonParam(e.subUnitId),i=this._sheetDrawingService.getDrawingByParam({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.id});if(!r||!(i!=null&&i.transform))return;let a={...i.transform,left:e.rect.left,top:e.rect.top,width:e.rect.width,height:e.rect.height,angle:e.rect.angle,flipX:e.rect.flipX,flipY:e.rect.flipY,skewX:e.rect.skewX,skewY:e.rect.skewY},o=(0,n.transformToDrawingPosition)(a,r.skeleton),s=(0,n.transformToAxisAlignPosition)(a,r.skeleton);!o||!s||this._commandService.syncExecuteCommand(n.SetSheetDrawingCommand.id,{unitId:e.unitId,drawings:[{...i,transform:a,sheetTransform:o,axisAlignSheetTransform:s}]})}isFloatDomRuntimeMounted(e){var t;return((t=this._domLayerInfoMap.get(e))==null?void 0:t.runtimeMounted)===!0}_getFloatDomPreviewObjectKey(e){return`${e}__preview`}_syncPreviewObjectTransform(e,t){e==null||e.transformByState({left:t.left,top:t.top,width:t.width,height:t.height,angle:t.angle,flipX:t.flipX,flipY:t.flipY,skewX:t.skewX,skewY:t.skewY})}_requestFloatDomPreview(e,t,n){this._canvasFloatDomPreviewService&&this._canvasFloatDomPreviewService.requestPreview({id:e,width:t.width,height:t.height,data:n})}_upsertFloatDomPreviewObject(e,t,n,i,a){var o;let s=(o=this._canvasFloatDomPreviewService)==null?void 0:o.getPreview(i);if(!(s!=null&&s.image)){this._requestFloatDomPreview(i,t,a);return}let c=this._getFloatDomPreviewObjectKey(n),l=e.getObject(c);if(l instanceof r.Image)return l.changeSource(s.image),this._syncPreviewObjectTransform(l,t),l;let u=new r.Image(c,{left:t.left,top:t.top,width:t.width,height:t.height,angle:t.angle,flipX:t.flipX,flipY:t.flipY,skewX:t.skewX,skewY:t.skewY,url:s.image,evented:!1,rotateEnabled:!1,resizeEnabled:!1});return e.addObject(u,r.DRAWING_OBJECT_LAYER_INDEX),u}mountFloatDomRuntime(e){let t=this._domLayerInfoMap.get(e);return t!=null&&t.floatDomConfig?t.runtimeMounted?!0:(Te(this._canvasFloatDomService,e)?this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:!1,props:{...t.floatDomConfig.props,initialStage:`stage2`,onRuntimeStageExit:()=>this.unmountFloatDomRuntime(e)}}):this._canvasFloatDomService.addFloatDom({...t.floatDomConfig,eventPassThrough:!1,props:{...t.floatDomConfig.props,initialStage:`stage2`,onRuntimeStageExit:()=>this.unmountFloatDomRuntime(e)}}),t.runtimeMounted=!0,t.runtimeStage=`stage2`,!0):!1}unmountFloatDomRuntime(e){let t=this._domLayerInfoMap.get(e);t!=null&&t.runtimeMounted&&(t.floatDomConfig&&!_e(t.floatDomConfig)?this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:be(t.floatDomConfig,`inactive`),props:t.floatDomConfig.props}):this._canvasFloatDomService.removeFloatDom(e),t.runtimeMounted=!1,t.runtimeStage=`inactive`)}_syncFloatDomVisibilityForActiveSheet(e,t){Array.from(this._domLayerInfoMap.values()).filter(t=>t.unitId===e&&t.floatDomConfig).forEach(e=>{let n=e.subUnitId===t,r=Te(this._canvasFloatDomService,e.id);if(!n){r&&this._canvasFloatDomService.removeFloatDom(e.id),e.runtimeMounted=!1,e.runtimeStage=`inactive`;return}if(r||!e.floatDomConfig)return;this._canvasFloatDomService.addFloatDom(e.floatDomConfig);let i=_e(e.floatDomConfig);e.runtimeMounted=i,e.runtimeStage=me(e.floatDomConfig)?`inactive`:i?`stage2`:`inactive`})}promoteFloatDomRuntimeStage(e){let t=this._domLayerInfoMap.get(e);if(!(t!=null&&t.floatDomConfig))return;let n=he(t.floatDomConfig);return t.runtimeMounted&&!n?(t.runtimeStage=`stage2`,`stage2`):t.runtimeStage===`stage1`?t.runtimeMounted?(t.runtimeStage=`stage2`,xe(t.floatDomConfig)&&this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:be(t.floatDomConfig,`stage2`)}),`stage2`):(this.mountFloatDomRuntime(e),`stage2`):(t.runtimeStage=`stage1`,xe(t.floatDomConfig)&&this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:be(t.floatDomConfig,`stage1`)}),`stage1`)}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderUnitById(e),n=t==null?void 0:t.scene;return t==null||n==null?null:{scene:n,transformer:n.getTransformerByCreate(),renderUnit:t,canvas:t.engine.getCanvasElement()}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(e=>{var n;let{unitId:i,subUnitId:a,drawingId:l}=e,f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:i,subUnitId:a}),p=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(i,t.UniverInstanceType.UNIVER_SHEET);if(!m)return;let h=m.getActiveSheet().getSheetId();if(!p||!f)return;let g=(n=this._renderManagerService.getRenderUnitById(i))==null?void 0:n.with(c.SheetSkeletonManagerService).getSkeletonParam(a);if(!g)return;let{transform:_,drawingType:v,data:y,hidden:b,groupId:x}=p;if(!Ee(v))return;let S=this._getSceneAndTransformerByDrawingSearch(i);if(S==null||b)return;let{scene:C,canvas:w}=S;if(_==null)return!0;if(h!==a)return;let{left:T,top:E,width:D,height:O,angle:k,flipX:A,flipY:j,skewX:M,skewY:N}=_,P=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:l}),F=x?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:x}):void 0,I=this._getObjectIncludingGroup(C,P,F);if(I!=null&&(this._removeTopLevelDuplicateIfGrouped(C,P,I),de(I,p),v===t.DrawingTypeEnum.DRAWING_CHART&&fe(I),I.transformByState({left:T,top:E,width:D,height:O,angle:k,flipX:A,flipY:j,skewX:M,skewY:N}),this._syncFloatDomRect(l,I),ye(p)&&(this._syncPreviewObjectTransform(C.getObject(this._getFloatDomPreviewObjectKey(P)),I),this._requestFloatDomPreview(l,I,y)),this._domLayerInfoMap.has(l)))return;let L={left:T,top:E,width:D,height:O,zIndex:this._drawingManagerService.getDrawingOrder(i,a).length-1},R=v===t.DrawingTypeEnum.DRAWING_CHART;if(R){let e=this._getChartDataBackground(y);e!==void 0&&(L.fill=e),y&&y.border&&(L.stroke=y.border),Object.assign(L,ee)}else L.rotateEnabled=!1;let z=I??this._createRenderObject({key:P,config:L,unitId:i,subUnitId:a,drawingId:l,drawingType:v,data:y});de(z,p),R&&fe(z),R?z.objectType=r.ObjectType.CHART:(v===t.DrawingTypeEnum.DRAWING_DOM||v===t.DrawingTypeEnum.DRAWING_BLOCK)&&(z.objectType=r.ObjectType.DRAWING_DOM),I||C.addObject(z,r.DRAWING_OBJECT_LAYER_INDEX),!I&&p.allowTransform!==!1&&C.attachTransformerTo(z),!I&&R&&x&&(0,u.insertGroupObject)({drawingId:x,unitId:i,subUnitId:a},z,C,this._drawingManagerService);let B=new t.DisposableCollection,V=ye(p),H=V?this._getFloatDomPreviewObjectKey(P):void 0;if(V){var U;this._upsertFloatDomPreviewObject(C,z,P,l,y);let e=(U=this._canvasFloatDomPreviewService)==null?void 0:U.previewUpdated$.subscribe(e=>{e.id===l&&this._upsertFloatDomPreviewObject(C,z,P,l,y)});e&&B.add(e)}let W=new d.BehaviorSubject(Z(z,S.renderUnit.scene,g.skeleton,f.worksheet)),G=`${ne}${(0,t.generateRandomId)(6)}`,K=_e(p),q=me(p),J,Y={position$:W,id:l,domId:G,componentKey:p.componentKey,eventPassThrough:be(p,`inactive`),preserveOnFocusChange:ve(p),onPointerDown:e=>{Se(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{Se(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{Se(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onWheel:e=>{Se(p,e)&&w.dispatchEvent(new WheelEvent(e.type,e))},data:y,props:q?{onRuntimeStageEnter:e=>{J&&(J.runtimeStage=e,J.runtimeMounted=K||e===`stage2`,xe(p)&&this._canvasFloatDomService.updateFloatDom(l,{eventPassThrough:be(p,e)})),we(e,this._getSceneAndTransformerByDrawingSearch(i),z)}}:void 0,unitId:i};if(J={dispose:B,rect:z,position$:W,unitId:i,subUnitId:a,id:l,domId:G,floatDomConfig:Y,runtimeMounted:K,runtimeStage:q?`inactive`:K?`stage2`:`inactive`,previewObjectKey:H},this._canvasFloatDomService.addFloatDom(Y),!K){let e,t=t=>{if(e&&(e.pointerId==null||t.pointerId==null||e.pointerId===t.pointerId)){if(typeof t.offsetX!=`number`||typeof t.offsetY!=`number`){e=void 0;return}Math.hypot(t.offsetX-e.startOffsetX,t.offsetY-e.startOffsetY)>4&&(e=void 0)}},n=z.onPointerDown$.subscribeEvent({priority:oe,next:([t,n])=>{if((J==null?void 0:J.runtimeStage)===`stage1`){e=Oe(J,t);return}let r=this.promoteFloatDomRuntimeStage(l);r===`stage2`&&(we(r,S,z),n.skipNextObservers=!0),Ce(r)||n.stopPropagation()}}),r=C.onPointerDown$.subscribeEvent({priority:oe,next:([t])=>{J&&(e=Oe(J,t))}}),i=C.onPointerMove$.subscribeEvent({priority:oe,next:([e])=>{t(e)}}),a=C.onPointerUp$.subscribeEvent({priority:oe,next:([t,n])=>{let r=J&&ke(J,e,t);if(e=void 0,!r)return;let i=this.promoteFloatDomRuntimeStage(l);i===`stage2`&&(we(i,S,z),n.stopPropagation(),n.skipNextObservers=!0)}});B.add(n),B.add(r),B.add(i),B.add(a)}let X=z.onTransformChange$.subscribeEvent(()=>{let e=Z(z,S.renderUnit.scene,g.skeleton,f.worksheet);W.next(e),H&&this._syncPreviewObjectTransform(C.getObject(H),z)});B.add(()=>{this._canvasFloatDomService.removeFloatDom(l),H&&C.removeObject(H)}),X&&B.add(X),this._bindFloatDomScroll(B,J,S.renderUnit.scene,g.skeleton,f.worksheet),this._domLayerInfoMap.set(l,J)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:n,drawingId:r}),a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let{transformer:s,scene:c}=a,l=this._getObjectIncludingGroup(c,i);if(l!=null&&l.oKey){var u;s.clearControlByIds([l==null?void 0:l.oKey]),(u=c.getTransformer())==null||u.clearSelectedObjects()}})}))}_scrollUpdateListener(){let e=(e,t)=>{var n;let r=this._getSceneAndTransformerByDrawingSearch(e),i=Array.from(this._domLayerInfoMap.keys()).map(e=>({id:e,...this._domLayerInfoMap.get(e)})).filter(n=>n.subUnitId===t&&n.unitId===e).map(e=>e.id),a=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:t}),o=(n=this._renderManagerService.getRenderUnitById(e))==null?void 0:n.with(c.SheetSkeletonManagerService).getSkeletonParam(t);!r||!a||!o||i.forEach(e=>{let t=this._domLayerInfoMap.get(e);if(t){let e=Z(t.rect,r.renderUnit.scene,o.skeleton,a.worksheet,t);t.position$.next(e)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,d.switchMap)(e=>e?e.activeSheet$:(0,d.of)(null))).subscribe(t=>{if(!t)return;let n=t.getUnitId(),r=t.getSheetId();this._syncFloatDomVisibilityForActiveSheet(n,r),e(n,r)})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===c.SetZoomRatioOperation.id){let{unitId:n}=t.params;Array.from(this._domLayerInfoMap.values()).filter(e=>e.unitId===n).map(e=>e.subUnitId).forEach(t=>{e(n,t)})}else if(t.id===s.SetFrozenMutation.id){let{unitId:n,subUnitId:r}=t.params;e(n,r)}else if(t.id===s.SetSelectionsOperation.id){let{unitId:n,subUnitId:r}=t.params;e(n,r)}}))}_bindFloatDomScroll(e,n,i,a,o){let s=i.getViewport(r.SHEET_VIEWPORT_KEY.VIEW_MAIN);s&&e.add((0,t.fromEventSubject)(s.onScrollAfter$).subscribe(()=>{n.position$.next(Z(n.rect,i,a,o,n))}))}updateFloatDomProps(e,t,n,i){let a=this._domLayerInfoMap.get(n),s=this._getSceneAndTransformerByDrawingSearch(e);if(a&&s){let{scene:a}=s,c=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:n}),l=this._drawingManagerService.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n}),u=l!=null&&l.groupId?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:l.groupId}):void 0,d=this._getObjectIncludingGroup(a,c,u);d&&d instanceof r.Rect&&(this._removeTopLevelDuplicateIfGrouped(a,c,d),d.setProps(i),this._syncFloatDomRect(n,d))}}_getObjectIncludingGroup(e,t,n){var r;return this._getChildObjectFromGroup(e,t,n)??((r=e.getObjectIncludeInGroup)==null?void 0:r.call(e,t))??e.getObject(t)??null}_getChildObjectFromGroup(e,t,n){var r;if(!n)return null;let i=((r=e.getObjectIncludeInGroup)==null?void 0:r.call(e,n))??e.getObject(n);return this._findChildObject(i,t)}_findChildObject(e,t){if(!e)return null;let n=e.getObjects();for(let e of n){if(e.oKey===t)return e;let n=this._findChildObject(e,t);if(n)return n}return null}_removeTopLevelDuplicateIfGrouped(e,t,n){if(!n.isInGroup)return;let r=e.getObject(t);r&&r!==n&&e.removeObject(r)}_syncFloatDomRect(e,t){if(!(t instanceof r.Rect))return;let n=this._domLayerInfoMap.get(e);n&&(n.rect=t)}_getChartDataBackground(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e,n=t.backgroundColor??t.background;return typeof n==`string`?n:void 0}_getPosition(e,t){var n;let{startX:r,endX:i,startY:a,endY:o}=e,s=(n=this._renderManagerService.getRenderUnitById(t))==null?void 0:n.with(c.ISheetSelectionRenderService);if(s==null)return;let l=s.getCellWithCoordByOffset(r,a);if(l==null)return;let u={column:l.actualColumn,columnOffset:r-l.startX,row:l.actualRow,rowOffset:a-l.startY},d=s.getCellWithCoordByOffset(i,o);if(d!=null)return{from:u,to:{column:d.actualColumn,columnOffset:i-d.startX,row:d.actualRow,rowOffset:o-d.startY}}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let n=this._drawingManagerService.getDrawingByParam(e);if(!n||!Ee(n.drawingType))return;if(n.hidden){this._removeDom(e.drawingId);return}if(!this._domLayerInfoMap.has(e.drawingId)){this._drawingManagerService.addNotification([e]);return}let r={...n.transform};this._transformChange$.next({id:e.drawingId,value:r}),this._canvasFloatDomService.updateFloatDom(e.drawingId,{...n});let i=this._getSceneAndTransformerByDrawingSearch(e.unitId);if(i&&n.drawingType!==t.DrawingTypeEnum.DRAWING_CHART){let{scene:t}=i,r=this._domLayerInfoMap.get(e.drawingId);r!=null&&r.rect&&(n.allowTransform===!1?t.detachTransformerFrom(r.rect):t.attachTransformerTo(r.rect))}})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{this._removeDom(e.drawingId)})}))}addFloatDomToPosition(e,r){let i=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!i)throw Error(`cannot find current target!`);let{unitId:a,subUnitId:o}=i,{initPosition:c,componentKey:l,data:u,allowTransform:d=!0}=e,f=r??(0,t.generateRandomId)(),p=this._getPosition(c,a);if(p==null)return;let m={unitId:a,subUnitId:o,drawingId:f,drawingType:e.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:p,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},axisAlignSheetTransform:p,data:u,allowTransform:d};return this._commandService.executeCommand(n.InsertSheetDrawingCommand.id,{unitId:a,drawings:[m]}),this._add$.next({unitId:a,subUnitId:o,id:f}),this._createFloatDomDisposable(f)}_removeDom(e,t=!1){let r=this._domLayerInfoMap.get(e);if(!r)return;let{unitId:i,subUnitId:a}=r;this._domLayerInfoMap.delete(e),r.dispose.dispose();let o=this._getSceneAndTransformerByDrawingSearch(i);if(o){let{scene:t,transformer:n}=o;if((0,u.disposeDrawingRenderObject)(t,{unitId:i,subUnitId:a,drawingId:e})){var s;n.clearControlByIds([r.rect.oKey]),(s=t.getTransformer())==null||s.clearSelectedObjects()}}if(t){let t=this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:a,drawingId:e});if(!t)return;let{redo:r,objects:o}=this._sheetDrawingService.getBatchRemoveOp([t]);this._commandService.syncExecuteCommand(n.SetDrawingApplyMutation.id,{unitId:i,subUnitId:a,op:r,objects:o,type:n.DrawingApplyType.REMOVE})}}removeFloatDom(e,t=!0){this._removeDom(e,t)}addFloatDomToRange(e,n,i,a){var l;let f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!f)throw Error(`cannot find current target!`);let{unitId:p,subUnitId:m}=f,h=this._getSceneAndTransformerByDrawingSearch(p);if(!h)return;let g=this._renderManagerService.getRenderUnitById(p);if(!g)return;let _=(l=this._renderManagerService.getRenderUnitById(p))==null?void 0:l.with(c.SheetSkeletonManagerService).getSkeletonParam(m);if(!_)return;let{componentKey:v,data:y,allowTransform:b=!0}=n,x=a??(0,t.generateRandomId)(),{position:S,position$:C}=this._createRangePositionObserver(e,g,_.skeleton),w=this._getPosition(S,p);if(w==null)return;let{scaleX:T}=h.scene.getAncestorScale(),E=Me(S,i,T),D={unitId:p,subUnitId:m,drawingId:x,drawingType:n.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:v,sheetTransform:w,axisAlignSheetTransform:w,transform:{left:E.startX,top:E.startY,width:E.width,height:E.height},data:y,allowTransform:b};{var O,k;let{unitId:e,subUnitId:a,drawingId:l}=D,f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:a}),p=D,m=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!m)return;let h=m.getActiveSheet().getSheetId();if(!p||!f)return;let g=(O=this._renderManagerService.getRenderUnitById(e))==null?void 0:O.with(c.SheetSkeletonManagerService);if(!g)return;let _=g.getSkeletonParam(a);if(!_)return;let{transform:v,drawingType:y,data:b,groupId:w}=p;if(!Ee(y))return;let T=this._getSceneAndTransformerByDrawingSearch(e);if(T==null)return;let{scene:E,canvas:A}=T;if(v==null||h!==a)return;let{left:j,top:M,width:N,height:P,angle:F,flipX:I,flipY:L,skewX:R,skewY:z}=v,B=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),V=w?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:w}):void 0,H=this._getObjectIncludingGroup(E,B,V);if(H!=null){this._removeTopLevelDuplicateIfGrouped(E,B,H),y===t.DrawingTypeEnum.DRAWING_CHART&&fe(H),H.transformByState({left:j,top:M,width:N,height:P,angle:F,flipX:I,flipY:L,skewX:R,skewY:z}),this._syncFloatDomRect(l,H);return}let U={left:j,top:M,width:N,height:P,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1},W=y===t.DrawingTypeEnum.DRAWING_CHART;if(W){let e=this._getChartDataBackground(b);e!==void 0&&(U.fill=e),U.rotateEnabled=!1,b&&b.border&&(U.stroke=b.border),U.paintFirst=`stroke`,U.strokeWidth=1,U.radius=8}let G=this._createRenderObject({key:B,config:U,unitId:e,subUnitId:a,drawingId:l,drawingType:y,data:b});W&&(G.setObjectType(r.ObjectType.CHART),fe(G)),E.addObject(G,r.DRAWING_OBJECT_LAYER_INDEX),p.allowTransform!==!1&&E.attachTransformerTo(G),W&&w&&(0,u.insertGroupObject)({drawingId:w,unitId:e,subUnitId:a},G,E,this._drawingManagerService);let K=new t.DisposableCollection,q=E.getMainViewport(),{rowHeaderWidth:J,columnHeaderHeight:Y}=_.skeleton,X={dispose:K,rect:G,boundsOfViewArea:{top:Y,left:J,bottom:q.bottom,right:q.right},domAnchor:i,unitId:e,subUnitId:a,id:l},ee=new d.BehaviorSubject(Z(G,T.renderUnit.scene,_.skeleton,f.worksheet,X));X.position$=ee;let te={position$:ee,id:l,componentKey:p.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:e=>{A.dispatchEvent(new WheelEvent(e.type,e))},data:b,unitId:e};n.eventPassThrough&&(te={...te,onPointerDown:e=>{A.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{A.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{A.dispatchEvent(new PointerEvent(e.type,e))}}),this._canvasFloatDomService.addFloatDom(te),this.disposeWithMe(C.subscribe(t=>{let n=Me({rotate:0,startX:t.startX,startY:t.startY,endX:t.endX,endY:t.endY,width:i.width??t.width,height:i.height??t.height,absolute:{left:S.absolute.left,top:S.absolute.top}},i),s=new r.Rect((0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),{left:n.startX,top:n.startY,width:i.width??t.width,height:i.height??t.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1}),c=Z(s,T.renderUnit.scene,_.skeleton,f.worksheet,X);ee.next(c)}));let ne=(k=this._renderManagerService.getRenderUnitById(e))==null?void 0:k.with(c.SheetSkeletonManagerService),re=ne==null?void 0:ne.currentSkeleton$.subscribe(e=>{e&&_.sheetId!==e.sheetId&&this._removeDom(x,!0)});re&&K.add(re);let ie=G.onTransformChange$.subscribeEvent(()=>{let e=Z(G,T.renderUnit.scene,_.skeleton,f.worksheet,X);ee.next(e)});K.add(()=>{this._canvasFloatDomService.removeFloatDom(l)}),ie&&K.add(ie),this._bindFloatDomScroll(K,X,T.renderUnit.scene,_.skeleton,f.worksheet),this._domLayerInfoMap.set(l,X)}return this._createFloatDomDisposable(x)}addFloatDomToColumnHeader(e,n,i,a){var l;let u=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!u)throw Error(`cannot find current target!`);let{unitId:f,subUnitId:p}=u;if(!this._getSceneAndTransformerByDrawingSearch(f))return;let m=this._renderManagerService.getRenderUnitById(f);if(!m)return;let h=(l=this._renderManagerService.getRenderUnitById(f))==null?void 0:l.with(c.SheetSkeletonManagerService).getSkeletonParam(p);if(!h)return;let{componentKey:g,data:_,allowTransform:v=!0}=n,y=a??(0,t.generateRandomId)(),{position:b,position$:x}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:e,endColumn:e},m,h.skeleton),S=b;S.startY=0;let C=this._getPosition(b,f);if(C==null)return;let w={unitId:f,subUnitId:p,drawingId:y,drawingType:n.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:g,sheetTransform:C,axisAlignSheetTransform:C,transform:{left:S.startX,top:S.startY,width:S.width,height:S.height},data:_,allowTransform:v};{var T,E;let{unitId:e,subUnitId:a,drawingId:l}=w,u=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:a}),f=w,p=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!p)return;let m=p.getActiveSheet().getSheetId();if(!f||!u)return;let g=(T=this._renderManagerService.getRenderUnitById(e))==null?void 0:T.with(c.SheetSkeletonManagerService);if(!g)return;let _=g.getSkeletonParam(a);if(!_)return;let{transform:v,data:C}=f,D=this._getSceneAndTransformerByDrawingSearch(e);if(D==null)return;let{scene:O,canvas:k}=D;if(v==null||m!==a)return;let{left:A,top:j,width:M,height:N,angle:P,flipX:F,flipY:I,skewX:L,skewY:R}=v,z=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),B=this._getObjectIncludingGroup(O,z);if(B!=null){this._removeTopLevelDuplicateIfGrouped(O,z,B),B.transformByState({left:A,top:j,width:M,height:N,angle:P,flipX:F,flipY:I,skewX:L,skewY:R}),this._syncFloatDomRect(l,B);return}let V=Me({rotate:0,startX:S.startX,startY:0,endX:b.endX,endY:b.endY,width:i.width,height:i.height,absolute:{left:b.absolute.left,top:b.absolute.top}},i),H=new r.Rect(z,{left:V.startX,top:V.startY,width:V.width,height:V.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1});O.addObject(H,r.DRAWING_OBJECT_LAYER_INDEX),f.allowTransform!==!1&&O.attachTransformerTo(H);let U=new t.DisposableCollection,W=O.getMainViewport(),G={dispose:U,rect:H,unitId:e,subUnitId:a,id:l,boundsOfViewArea:{top:0,left:W.left,bottom:W.bottom,right:W.right},domAnchor:i,scrollDirectionResponse:`HORIZONTAL`},K=new d.BehaviorSubject(Z(H,D.renderUnit.scene,_.skeleton,u.worksheet,G));G.position$=K;let q={position$:K,id:l,componentKey:f.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:e=>{k.dispatchEvent(new WheelEvent(e.type,e))},data:C,unitId:e};n.eventPassThrough&&(q={...q,onPointerDown:e=>{k.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{k.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{k.dispatchEvent(new PointerEvent(e.type,e))}}),this._canvasFloatDomService.addFloatDom(q);let J=H.onTransformChange$.subscribeEvent(()=>{let e=Z(H,D.renderUnit.scene,_.skeleton,u.worksheet,G);K.next(e)});this.disposeWithMe(x.subscribe(t=>{let n=Me({rotate:0,startX:t.startX,startY:0,endX:t.endX,endY:t.endY,width:i.width,height:i.height,absolute:{left:b.absolute.left,top:b.absolute.top}},i),s=new r.Rect((0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),{left:n.startX,top:0,width:i.width,height:i.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1}),c=Z(s,D.renderUnit.scene,_.skeleton,u.worksheet,G);K.next(c)}));let Y=(E=this._renderManagerService.getRenderUnitById(e))==null?void 0:E.with(c.SheetSkeletonManagerService);Y==null||Y.currentSkeleton$.subscribe(e=>{e&&h.sheetId!==e.sheetId&&this._removeDom(y,!0)}),U.add(()=>{this._canvasFloatDomService.removeFloatDom(l)}),J&&U.add(J),this._bindFloatDomScroll(U,G,D.renderUnit.scene,_.skeleton,u.worksheet),this._domLayerInfoMap.set(l,G)}return this._createFloatDomDisposable(y)}_createRangePositionObserver(e,n,r){let{startRow:i,startColumn:a}=e,o=je(i,a,r),l=new d.BehaviorSubject(o),u=je(e.endRow,e.endColumn,r),f=new d.BehaviorSubject(u),p=()=>{let t=je(i,a,r),n=je(e.endRow,e.endColumn,r);l.next(t),f.next(n)},m=new t.DisposableCollection;return m.add(n.engine.clientRect$.subscribe({next:()=>p(),error:()=>{}})),m.add(this._commandService.onCommandExecuted(e=>{if(e.id===s.SetWorksheetRowAutoHeightMutation.id&&e.params.rowsAutoHeightInfo.findIndex(e=>e.row===i)>-1){p();return}(s.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(e.id)>-1||e.id===c.SetScrollOperation.id||e.id===c.SetZoomRatioOperation.id)&&p()})),{position$:l.pipe((0,d.map)(t=>{let n=je(e.endRow,e.endColumn,r);return{rotate:0,width:n.right-t.left,height:n.bottom-t.top,absolute:{left:!0,top:!0},startX:t.left,startY:t.top,endX:n.right,endY:n.bottom}})),position:{rotate:0,width:u.right-o.left,height:u.bottom-o.top,absolute:{left:!0,top:!0},startX:o.left,startY:o.top,endX:u.right,endY:u.bottom},updateRowCol:(e,t)=>{i=e,a=t,p()},topLeftPos$:l,rightBottomPos$:f,disposable:m}}};Q=te=O([D(0,(0,t.Inject)(r.IRenderManagerService)),D(1,t.IUniverInstanceService),D(2,(0,t.Inject)(t.ICommandService)),D(3,o.IDrawingManagerService),D(4,(0,t.Inject)(l.CanvasFloatDomService)),D(5,n.ISheetDrawingService),D(6,(0,t.Inject)(t.LifecycleService)),D(7,(0,t.Optional)(l.CanvasFloatDomPreviewService))],Q);function je(e,t,n){let r=n.getCellWithCoordByIndex(e,t),i=r.isMergedMainCell?r.mergeInfo:r;return{left:i.startX,right:i.endX,top:i.startY,bottom:i.endY}}function Me(e,t,n){n??=1;let r=e.endX-e.startX,i=e.endY-e.startY,a=(t==null?void 0:t.width)??r,o=(t==null?void 0:t.height)??i,s=0,c=0;if(t){if(t.horizonOffsetAlign===`right`){let i=Ne(t.marginX,r*n);s=e.endX-i-a}else s=e.startX+Ne(t.marginX,r);if(t.verticalOffsetAlign===`bottom`){let r=Ne(t.marginY,i*n);c=e.endY-r-o}else c=e.startY+Ne(t.marginY,i)}return{rotate:0,startX:s,startY:c,endX:e.endX,endY:e.endY,width:a,height:o,absolute:{left:e.absolute.left,top:e.absolute.top}}}function Ne(e,t){return e===void 0?0:typeof e==`number`?e:t*Number.parseFloat(e)/100}let Pe=[[Q]];function Fe(e){e.has(Q)||(0,t.registerDependencies)(e,Pe),Le(e)}function Ie(e){(0,t.touchDependencies)(e,[[Q]])}function Le(e){if(!e.has(t.LifecycleService)){Ie(e);return}let n=e.get(t.LifecycleService);if(n.stage>=t.LifecycleStages.Ready){Ie(e);return}n.onStage(t.LifecycleStages.Ready).then(()=>{Ie(e)})}let Re=`sheet.menu.image`;function ze(e){return{id:Re,type:l.MenuItemType.SUBITEMS,icon:`AddImageIcon`,tooltip:`sheets-drawing-ui.title`,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,c.getCurrentRangeDisable$)(e,{workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission],rangeTypes:[s.RangeProtectionPermissionEditPoint]})}}function Be(e){return{id:M.id,title:`sheets-drawing-ui.upload.float`,type:l.MenuItemType.BUTTON,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}}function Ve(e){return{id:N.id,title:`sheets-drawing-ui.upload.cell`,type:l.MenuItemType.BUTTON,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}}function He(e,t){let n=e.getActiveSheet();if(!n)return!1;let r=n.getCellMatrix(),{startRow:i,endRow:a,startColumn:o,endColumn:c}=t;for(let e=i;e<=a;e++)for(let t=o;t<=c;t++){let n=r.getValue(e,t);if((0,s.isCellImage)(n==null?void 0:n.p))return!0}return!1}function Ue(){return`showDirectoryPicker`in window}function We(e){let n=e.get(t.IUniverInstanceService),r=e.get(s.SheetsSelectionsService),i=(0,d.combineLatest)([(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),n.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,d.switchMap)(e=>e?r.selectionMoveEnd$.pipe((0,d.map)(()=>{if(!Ue())return!0;let t=r.getCurrentSelections();if(!t||t.length===0)return!0;for(let n of t)if(He(e,n.range))return!1;return!0})):(0,d.of)(!0)))]).pipe((0,d.map)(([e,t])=>e||t));return{id:G.id,type:l.MenuItemType.BUTTON,icon:`DownloadImageIcon`,title:`sheets-drawing-ui.save.menuLabel`,hidden$:i}}let Ge={[l.RibbonInsertGroup.MEDIA]:{[Re]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,showLabel:!0},menuItemFactory:ze,[M.id]:{order:0,menuItemFactory:Be},[N.id]:{order:1,menuItemFactory:Ve}}},[l.ContextMenuPosition.MAIN_AREA]:{[l.ContextMenuGroup.OTHERS]:{[G.id]:{order:10,menuItemFactory:We}}},[l.ContextMenuPosition.COL_HEADER]:{[l.ContextMenuGroup.OTHERS]:{[G.id]:{order:10,menuItemFactory:We}}},[l.ContextMenuPosition.ROW_HEADER]:{[l.ContextMenuGroup.OTHERS]:{[G.id]:{order:10,menuItemFactory:We}}}};var Ke=`@univerjs/sheets-drawing-ui`,qe=`1.0.0-beta.1`;let Je={};function Ye(){let e=(0,l.useDependency)(t.LocaleService),n=(0,l.useDependency)(l.IDialogService),r=(0,l.useDependency)(I),[a,o]=(0,p.useState)([`cellAddress`]),[s,u]=(0,p.useState)(!1),[d,f]=(0,p.useState)(null),h=(0,p.useMemo)(()=>r.getCellImagesInSelection(),[r]),g=(0,p.useMemo)(()=>r.getDataColumns(),[r]),_=(0,p.useMemo)(()=>r.getSelectionRowRange(),[r]),v=g.length>0,y=(0,p.useMemo)(()=>g.map(e=>({label:e.label,value:String(e.index)})),[g]),[b,x]=(0,p.useState)(()=>y.length>0?y[0].value:`0`);(0,c.useHighlightRange)((0,p.useMemo)(()=>{if(!a.includes(`columnValue`)||!_)return[];let e=Number(b);return[{startRow:_.startRow,endRow:_.endRow,startColumn:e,endColumn:e}]},[a,b,_]));let S=(0,p.useCallback)(e=>{e.length!==0&&o(e)},[]),C=(0,p.useCallback)(e=>{x(String(e))},[]),w=(0,p.useCallback)(()=>{n.close(W)},[n]),T=(0,p.useCallback)(async()=>{if(h.length!==0){u(!0),f(null);try{await r.saveImages(h,{fileNameParts:a,columnIndex:a.includes(`columnValue`)?Number(b):void 0}),n.close(W)}catch(t){console.error(`Failed to save images:`,t),f(e.t(`sheets-drawing-ui.save.error`))}finally{u(!1)}}},[r,h,a,b,n,e]),E=a.includes(`columnValue`);return(0,m.jsxs)(`div`,{className:`univer-flex univer-flex-col`,children:[(0,m.jsx)(i.FormLayout,{label:e.t(`sheets-drawing-ui.save.imageCount`),children:(0,m.jsx)(`div`,{className:`univer-text-sm univer-text-gray-600`,children:h.length})}),(0,m.jsx)(i.FormLayout,{label:e.t(`sheets-drawing-ui.save.fileNameConfig`),children:(0,m.jsxs)(i.CheckboxGroup,{value:a,onChange:S,direction:`vertical`,children:[(0,m.jsx)(i.Checkbox,{value:`cellAddress`,disabled:!v,children:e.t(`sheets-drawing-ui.save.useRowCol`)}),v&&(0,m.jsx)(i.Checkbox,{value:`columnValue`,children:e.t(`sheets-drawing-ui.save.useColumnValue`)})]})}),E&&(0,m.jsx)(i.FormLayout,{label:e.t(`sheets-drawing-ui.save.selectColumn`),children:(0,m.jsx)(i.Select,{value:b,options:y,onChange:C})}),d&&(0,m.jsx)(`div`,{className:`univer-text-xs univer-text-red-500`,children:d}),(0,m.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-2 univer-border-t univer-border-gray-200 univer-pt-3`,children:[(0,m.jsx)(i.Button,{onClick:w,disabled:s,children:e.t(`sheets-drawing-ui.save.cancel`)}),(0,m.jsx)(i.Button,{variant:`primary`,onClick:T,disabled:s||h.length===0,children:s?e.t(`sheets-drawing-ui.save.saving`):e.t(`sheets-drawing-ui.save.confirm`)})]})]})}let Xe=e=>{let a=(0,l.useDependency)(t.ICommandService),s=(0,l.useDependency)(t.LocaleService),c=(0,l.useDependency)(o.IDrawingManagerService),u=(0,l.useDependency)(r.IRenderManagerService),{drawings:d}=e,f=Ze(d[0])?d[0]:void 0,h=f?u.getRenderUnitById(f.unitId):void 0,g=h==null?void 0:h.scene,_=g==null?void 0:g.getTransformerByCreate(),[v,y]=(0,p.useState)(!0),[b,x]=(0,p.useState)(f?(0,n.getSheetDrawingPlacement)(f).kind:n.SheetDrawingAnchorType.Position);function S(e,t){let n=[];return e.forEach(e=>{let{oKey:r}=e,i=t.getDrawingOKey(r);if(i==null||!Ze(i))return n.push(null),!0;let{unitId:a,subUnitId:o,drawingId:s,drawingType:c,anchorType:l,sheetTransform:u,axisAlignSheetTransform:d}=i;n.push({unitId:a,subUnitId:o,drawingId:s,anchorType:l,sheetTransform:u,drawingType:c,axisAlignSheetTransform:d})}),n}if((0,p.useEffect)(()=>{if(!_)return;let e=_.clearControl$.subscribe(e=>{e===!0&&y(!1)}),t=_.changeStart$.subscribe(e=>{let{objects:t}=e,r=S(t,c);if(r.length===0)y(!1);else if(r.length>=1){y(!0);let e=r[0];x(e?(0,n.getSheetDrawingPlacement)(e).kind:n.SheetDrawingAnchorType.Position)}});return()=>{t.unsubscribe(),e.unsubscribe()}},[c,_]),!f||!_)return null;function C(e){let t=Qe(e);if(!t)return;let r=c.getFocusDrawings();if(!r.length||!r.every(Ze))return;let{unitId:i,subUnitId:o}=r[0],s=[];for(let e of r){let{transform:n}=e,{left:r,top:i,width:a,height:o}=n??{};if(typeof r!=`number`||typeof i!=`number`||typeof a!=`number`||typeof o!=`number`||!Number.isFinite(r)||!Number.isFinite(i)||!Number.isFinite(a)||!Number.isFinite(o))return;s.push({drawingId:e.drawingId,placement:{kind:t,bounds:{left:r,top:i,width:a,height:o}}})}a.syncExecuteCommand(n.SetSheetDrawingPlacementCommand.id,{unitId:i,subUnitId:o,drawings:s})&&x(t)}return(0,m.jsxs)(`div`,{className:(0,i.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!v}),children:[(0,m.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,m.jsx)(`div`,{children:s.t(`sheets-drawing-ui.drawing-anchor.title`)})}),(0,m.jsx)(`div`,{children:(0,m.jsxs)(i.RadioGroup,{value:b,onChange:C,direction:`vertical`,children:[(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.Both,children:s.t(`sheets-drawing-ui.drawing-anchor.both`)}),(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.Position,children:s.t(`sheets-drawing-ui.drawing-anchor.position`)}),(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.None,children:s.t(`sheets-drawing-ui.drawing-anchor.none`)})]})})]})};function Ze(e){return!!(e&&`sheetTransform`in e&&`axisAlignSheetTransform`in e)}function Qe(e){return e===n.SheetDrawingAnchorType.Position||e===n.SheetDrawingAnchorType.Both||e===n.SheetDrawingAnchorType.None?e:null}let $e=()=>{let e=(0,l.useDependency)(o.IDrawingManagerService),t=(0,l.useObservable)(()=>e.focus$,e.getFocusDrawings(),!1,[e]);return!!(t!=null&&t.length)&&(0,m.jsxs)(`div`,{className:`univer-text-sm`,children:[(0,m.jsx)(u.DrawingCommonPanel,{drawings:t}),(0,m.jsx)(Xe,{drawings:t})]})},et=class extends t.Disposable{constructor(e){super(),this._componentManager=e,this._registerComponents()}_registerComponents(){this.disposeWithMe(this._componentManager.register(K,$e)),this.disposeWithMe(this._componentManager.register(W,Ye))}};et=O([D(0,(0,t.Inject)(l.ComponentManager))],et);let tt=(0,t.createIdentifier)(`sheets-drawing-ui.drawing-context-menu.service`);var nt=class extends t.Disposable{constructor(...e){super(...e),E(this,`_providers`,new Map)}registerProvider(e,n){return this._providers.set(e,n),(0,t.toDisposable)(()=>{this._providers.get(e)===n&&this._providers.delete(e)})}getContextMenuPosition(e){var t;return(t=this._providers.get(e.drawingType))==null?void 0:t.getContextMenuPosition(e)}};let rt=class extends t.RxDisposable{constructor(e,t,n,r,i){super(),this._drawingManagerService=e,this._contextMenuService=t,this._renderManagerService=n,this._univerInstanceService=r,this._drawingContextMenuService=i,this._init()}_init(){this._univerInstanceService.getAllUnitsForType(t.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._contextMenuListener(e))}_contextMenuListener(e){var t;if(!e)return;let n=(t=this._renderManagerService.getRenderUnitById(e.getUnitId()))==null?void 0:t.scene;if(!n)return;let r=n.getTransformerByCreate();r&&this.disposeWithMe(r.changeEnd$.subscribe(e=>{let{event:t}=e;if(t.button!==2)return;let n=r.getSelectedObjectMap();if(n.size===0)return;let i=[];for(let e of n.values()){let t=e.oKey,n=this._drawingManagerService.getDrawingOKey(t);if(!n)return;i.push(n)}this._contextMenuService.triggerContextMenu(t,this._getContextMenuPosition(i))}))}_getContextMenuPosition(e){if(e.length!==1)return l.ContextMenuPosition.DRAWING;let[t]=e;return this._drawingContextMenuService.getContextMenuPosition({unitId:t.unitId,subUnitId:t.subUnitId,drawingId:t.drawingId,drawingType:t.drawingType,drawing:t})??l.ContextMenuPosition.DRAWING}};rt=O([D(0,o.IDrawingManagerService),D(1,l.IContextMenuService),D(2,r.IRenderManagerService),D(3,t.IUniverInstanceService),D(4,tt)],rt);let it=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._context=e,this._hoverManagerService=t,this._selectionsService=n,this._drawingRenderService=r,this._sheetSkeletonManagerService=i,E(this,`_isSetCursor`,!1),this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe((0,d.throttleTime)(33)).subscribe(e=>{let t=[];if(e!==null&&(t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),(e==null?void 0:e.unitId)===this._context.unitId&&e!=null&&e.drawing&&t.length===1&&t[0].primary){let{row:n,col:i}=e,{actualRow:a,actualColumn:o,startRow:s,startColumn:c,endRow:l,endColumn:u,isMerged:d,isMergedMainCell:f}=t[0].primary;(d||f)&&n>=s&&n<=l&&i>=c&&i<=u||n===a&&i===o?(this._isSetCursor=!0,this._context.scene.setCursor(r.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}else this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(e=>{if(e!=null&&e.drawing&&this._isSetCursor){let t=e.drawing.drawing.drawingOrigin;this._previewImage(t)}}));let e=this._hoverManagerService.currentDbClickedCell$;e&&this.disposeWithMe(e.subscribe(({location:e})=>{var t,n,r;if(e.unitId!==this._context.unitId)return;let i=this._context.unit.getSheetBySheetId(e.subUnitId),a=i==null||(t=i.getCellRaw(e.row,e.col))==null?void 0:t.p,o=a==null||(n=a.drawingsOrder)==null?void 0:n[0],c=(0,s.isCellImage)(a)&&o?(r=a.drawings)==null?void 0:r[o]:void 0;c&&this._previewImage(c)}))}_previewImage(e){var t;if(this._disposed)return;let n=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap,r=n==null?void 0:n.getImage(e.imageSourceType,e.source,()=>this._previewImage(e));r&&(this._drawingRenderService.previewImage(`preview-cell-image`,r.src,r.width,r.height),this._context.scene.resetCursor(),this._isSetCursor=!1)}};it=O([D(1,(0,t.Inject)(c.HoverManagerService)),D(2,(0,t.Inject)(s.SheetsSelectionsService)),D(3,(0,t.Inject)(u.DrawingRenderService)),D(4,(0,t.Inject)(c.SheetSkeletonManagerService))],it);let at=class extends t.Disposable{constructor(e,t,n,r){super(),this._context=e,this._sheetDrawingService=t,this._drawingManagerService=n,this._sheetSkeletonService=r,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);let e=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(let r in e){let i=e[r];for(let e in i.data){let r=i.data[e],{unitId:a,subUnitId:o}=r,s=this._sheetSkeletonService.getSkeletonParam(a,o);if(s&&r.sheetTransform&&!r.groupId){let e=(0,n.drawingPositionToTransform)(r.sheetTransform,s);r.transform=e&&r.drawingType===t.DrawingTypeEnum.DRAWING_GROUP?{...e,left:(e.left??0)-s.skeleton.rowHeaderWidthAndMarginLeft,top:(e.top??0)-s.skeleton.columnHeaderHeightAndMarginTop}:e}}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};at=O([D(1,n.ISheetDrawingService),D(2,o.IDrawingManagerService),D(3,(0,t.Inject)(s.SheetSkeletonService))],at);function ot(e,t,n){var r,i;let a=n==null?void 0:n.p,o=(0,s.isCellImage)(a)&&(a==null||(r=a.drawingsOrder)==null?void 0:r.length)===1?a.drawingsOrder[0]:void 0,c=o?a==null||(i=a.drawings)==null?void 0:i[o]:void 0;if(c&&a){let n=A(e,{unitId:t.unitId,subUnitId:t.subUnitId,row:t.row,col:t.col},c.docTransform.size.width,c.docTransform.size.height,c.docTransform.angle);if(n)return c.transform.width=n.width,c.transform.height=n.height,c.docTransform.size.width=n.width,c.docTransform.size.height=n.height,c.transform.left=0,c.transform.top=0,c.docTransform.positionH.posOffset=0,c.docTransform.positionV.posOffset=0,a.documentStyle.pageSize.width=1/0,a.documentStyle.pageSize.height=1/0,!0}return!1}let st=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._sheetInterceptorService=e,this._injector=t,this._drawingManagerService=n,this._docDrawingController=r,this._editorBridgeService=i,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible?e.visible&&(this._drawingManagerService.removeDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(s.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,priority:s.InterceptCellContentPriority.CELL_IMAGE,handler:(e,t,n)=>(e&&(0,s.isCellImage)(e.p)&&(e===t.rawData&&(e={...t.rawData}),e.interceptorStyle||={},e.interceptorStyle.tr={a:0},ot(this._injector,{unitId:t.unitId,subUnitId:t.subUnitId,row:t.row,col:t.col},e)),n(e))}))}};st=O([D(0,(0,t.Inject)(s.SheetInterceptorService)),D(1,(0,t.Inject)(t.Injector)),D(2,o.IDrawingManagerService),D(3,(0,t.Inject)(f.DocDrawingController)),D(4,(0,t.Inject)(c.IEditorBridgeService))],st);let ct=class extends t.Disposable{constructor(e,t){super(),this._autoFillService=e,this._injector=t,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:`sheet-cell-image-autofill`,onBeforeSubmit:(e,n,r,i)=>{new t.ObjectMatrix(i).forValue((t,n,r)=>{ot(this._injector,{unitId:e.unitId,subUnitId:e.subUnitId,row:t,col:n},r)})}}))}};ct=O([D(0,(0,t.Inject)(s.IAutoFillService)),D(1,(0,t.Inject)(t.Injector))],ct);let lt=[t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,t.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY],ut=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._commandService=e,this._univerInstanceService=t,this._dialogService=n,this._renderManagerService=r,this._localeService=i,this._initDocImageCopyPasteHooks()}_setCellImage(e){var n;let i=(0,t.createDocumentModelWithStyle)(``,{}),a=(n=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(c.EditingRenderController),o=t.BuildTextUtils.drawing.add({documentDataModel:i,drawings:[e],selection:{collapsed:!0,startOffset:0,endOffset:0}});o&&(i.apply(o),a&&a.submitCellData(i))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===h.InnerPasteCommand.id){let{doc:r}=e.params,i=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(i==null||!Object.keys(r.drawings??{}).length)return;let a=i.getUnitId();if(lt.includes(a)){var n;let e=()=>{this._dialogService.close(`sheet-cell-image-copy-paste`),this._commandService.syncExecuteCommand(c.SetCellEditVisibleOperation.id,{visible:!1})};((n=i.getBody())==null?void 0:n.dataStream)===`\r
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets-drawing"),require("@univerjs/engine-render"),require("@univerjs/design"),require("@univerjs/docs"),require("@univerjs/drawing"),require("@univerjs/sheets"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("@univerjs/drawing-ui"),require("rxjs"),require("@univerjs/docs-drawing"),require("react"),require("react/jsx-runtime"),require("@univerjs/docs-ui")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-drawing`,`@univerjs/engine-render`,`@univerjs/design`,`@univerjs/docs`,`@univerjs/drawing`,`@univerjs/sheets`,`@univerjs/sheets-ui`,`@univerjs/ui`,`@univerjs/drawing-ui`,`rxjs`,`@univerjs/docs-drawing`,`react`,`react/jsx-runtime`,`@univerjs/docs-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDrawingUi={},e.UniverCore,e.UniverSheetsDrawing,e.UniverEngineRender,e.UniverDesign,e.UniverDocs,e.UniverDrawing,e.UniverSheets,e.UniverSheetsUi,e.UniverUi,e.UniverDrawingUi,e.rxjs,e.UniverDocsDrawing,e.React,e.React,e.UniverDocsUi))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let g={id:`sheet.command.delete-drawing`,type:t.CommandType.COMMAND,handler:e=>{let r=e.get(t.ICommandService),i=e.get(n.ISheetDrawingService).getFocusDrawings();if(i.length===0)return!1;let a=i[0].unitId,o=i.map(e=>{let{unitId:t,subUnitId:n,drawingId:r,drawingType:i}=e;return{unitId:t,subUnitId:n,drawingId:r,drawingType:i}});return r.executeCommand(n.RemoveSheetDrawingCommand.id,{unitId:a,drawings:o})}};function _(e){let n=[];return e.forEach(e=>{let{parent:i,children:a}=e,{unitId:o,subUnitId:s,drawingId:c}=i,l=(0,r.getGroupState)(0,0,a.map(e=>e.transform||{})),u=a.map(e=>{let t=e.transform||{left:0,top:0},{unitId:n,subUnitId:r,drawingId:i}=e;return{unitId:n,subUnitId:r,drawingId:i,transform:{...t,left:t.left,top:t.top},groupId:c}}),d={unitId:o,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_GROUP,groupBaseBound:{...i.groupBaseBound},transform:l};n.push({parent:d,children:u})}),n}function v(e){let n=[];return e.forEach(e=>{let{parent:i,children:a}=e,{unitId:o,subUnitId:s,drawingId:c,transform:l={width:0,height:0}}=i;if(l==null)return;let u=a.map(e=>{let{transform:t}=e,{unitId:n,subUnitId:a,drawingId:o}=e;return{unitId:n,subUnitId:a,drawingId:o,transform:(0,r.transformObjectOutOfGroup)(t||{},l,l.width||0,l.height||0,i.groupBaseBound),groupId:void 0}}),d={unitId:o,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:d,children:u})}),n}function y(e){var n;let r=new Map;(n=e.flatChildren)==null||n.forEach(e=>r.set(e.drawingId,(0,t.generateRandomId)(10))),e.groups.forEach(e=>r.set(e.drawingId,(0,t.generateRandomId)(10)));let i={};for(let[t,n]of Object.entries(e.nestedIdRecord)){var a;let e=r.get(t)??t;i[e]={drawingId:e,children:(a=n.children)==null?void 0:a.map(e=>r.get(e)??e)}}let o=[],s=[];for(let t of e.groups){let e=r.get(t.drawingId)??t.drawingId,n=t.groupId?r.get(t.groupId)??t.groupId:void 0;s.push(b(t,e,n))}for(let t of e.flatChildren||[]){let e=r.get(t.drawingId)??t.drawingId,n=t.groupId?r.get(t.groupId)??t.groupId:void 0;o.push(b(t,e,n))}return{cloned:{nestedIdRecord:i,flatChildren:o,groups:s},idMap:r}}function b(e,t,n){let r={...e};return t&&(r.drawingId=t),n?r.groupId=n:delete r.groupId,JSON.parse(JSON.stringify(r))}let x={id:`sheet.command.group-sheet-image`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(n.ISheetDrawingService);if(!r)return!1;let s=[];r.forEach(({parent:e,children:t})=>{s.push(e.unitId),t.forEach(e=>{s.push(e.unitId)})});let{unitId:c,subUnitId:l,undo:u,redo:d,objects:f}=o.getGroupDrawingOp(r);return i.syncExecuteCommand(n.SetDrawingApplyMutation.id,{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.GROUP})?(a.pushUndoRedo({unitID:c,undoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:v(f),type:n.DrawingApplyType.UNGROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}],redoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.GROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}]}),!0):!1}},S={id:`sheet.command.ungroup-sheet-image`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(n.ISheetDrawingService);if(!r)return!1;let s=[];r.forEach(({parent:e,children:t})=>{s.push(e.unitId),t.forEach(e=>{s.push(e.unitId)})});let{unitId:c,subUnitId:l,undo:u,redo:d,objects:f}=o.getUngroupDrawingOp(r);return i.syncExecuteCommand(n.SetDrawingApplyMutation.id,{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.UNGROUP})?(a.pushUndoRedo({unitID:c,undoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:_(f),type:n.DrawingApplyType.GROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}],redoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.UNGROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}]}),!0):!1}};function C(e){"@babel/helpers - typeof";return C=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},C(e)}function w(e,t){if(C(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(C(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function T(e){var t=w(e,`string`);return C(t)==`symbol`?t:t+``}function E(e,t,n){return(t=T(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function D(e,t){return function(n,r){t(n,r,e)}}function O(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 k(e,t,n){let r=n*Math.PI/180;return{rotatedWidth:Math.abs(e*Math.cos(r))+Math.abs(t*Math.sin(r)),rotatedHeight:Math.abs(e*Math.sin(r))+Math.abs(t*Math.cos(r))}}function A(e,t,n,i,a){var o;let{rotatedHeight:s,rotatedWidth:l}=k(n,i,a),u=e.get(r.IRenderManagerService).getRenderUnitById(t.unitId);if(!u)return!1;let d=(o=u.with(c.SheetSkeletonManagerService).getSkeletonParam(t.subUnitId))==null?void 0:o.skeleton;if(d==null)return!1;let f=d.getCellWithCoordByIndex(t.row,t.col),p=f.mergeInfo.endX-f.mergeInfo.startX-2,m=f.mergeInfo.endY-f.mergeInfo.startY-2,h=l/s,g=Math.ceil(Math.min(p,m*h))/l,_=!g||Number.isNaN(g)?.001:g;return{width:n*_,height:i*_}}let j=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m){super(),this._context=e,this._commandService=t,this._sheetInterceptorService=n,this._selectionRenderService=r,this._imageIoService=i,this._fileOpenerService=a,this._sheetDrawingService=o,this._drawingManagerService=s,this._contextService=c,this._messageService=l,this._localeService=u,this._sheetSkeletonService=f,this._injector=p,this._urlImageService=m,E(this,`_workbookSelections`,void 0),this._workbookSelections=d.getWorkbookSelections(this._context.unitId),this._updateDrawingListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){let e=await this._fileOpenerService.openFile({multiple:!0,accept:o.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace(`image/`,``)}`).join(`,`)}),t=e.length;return t>o.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxCount`,String(o.DRAWING_IMAGE_COUNT_LIMIT))}),!1):t===0?!1:(e.forEach(async e=>await this.insertFloatImageByFile(e)),!0)}async insertCellImage(){let e=(await this._fileOpenerService.openFile({multiple:!1,accept:o.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace(`image/`,``)}`).join(`,`)}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(e,t){return this._insertCellImage(e,t)}async insertFloatImageByFile(e){let r;try{r=await this._imageIoService.saveImage(e)}catch(e){let n=e.message;n===t.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxSize`,String((0,o.getDrawingImageAllowSize)()/(1024*1024)))}):n===t.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImageType`)}):n===t.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImage`)})}if(r==null)return;let{unitId:a,subUnitId:s}=this._getUnitInfo(),{imageId:c,imageSourceType:l,source:u,base64Cache:d}=r,{width:f,height:p,image:m}=await(0,o.getImageSize)(d||``),{width:h,height:g}=this._context.scene;this._imageIoService.addImageSourceCache(u,l,m);let _=1;if(f>o.DRAWING_IMAGE_WIDTH_LIMIT||p>o.DRAWING_IMAGE_HEIGHT_LIMIT){let e=o.DRAWING_IMAGE_WIDTH_LIMIT/f,t=o.DRAWING_IMAGE_HEIGHT_LIMIT/p;_=Math.max(e,t)}let v=this._sheetSkeletonService.getSkeletonParam(a,s);if(!v)return;let{skeleton:y}=v,b=this._getImagePosition(f*_,p*_,h,g,y);if(!b)return;let x=(0,n.drawingPositionToTransform)(b,v);if(!x)return;let S={unitId:a,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:u,transform:x,sheetTransform:b,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(x,y)??b};return this._commandService.executeCommand(n.InsertSheetDrawingCommand.id,{unitId:a,drawings:[S]})}async _insertCellImage(e,n){let r;try{r=await this._imageIoService.saveImage(e)}catch(e){let n=e.message;n===t.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxSize`,String((0,o.getDrawingImageAllowSize)()/(1024*1024)))}):n===t.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImageType`)}):n===t.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImage`)})}if(r==null)return!1;let{imageId:c,imageSourceType:l,source:u,base64Cache:d}=r,{width:f,height:p,image:m}=await(0,o.getImageSize)(d||``);this._imageIoService.addImageSourceCache(u,l,m);let h=this._workbookSelections.getCurrentLastSelection();if(!h)return!1;let g=h.primary.actualRow,_=h.primary.actualColumn;h.primary.isMerged&&(g=h.primary.startRow,_=h.primary.startColumn);let v=(0,t.createDocumentModelWithStyle)(``,{}),y=A(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:g,col:_},f,p,0);if(!y)return!1;let b=(0,a.buildDocTransform)(y.width,y.height),x={unitId:v.getUnitId(),subUnitId:v.getUnitId(),drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:u,transform:(0,a.docDrawingPositionToTransform)(b),docTransform:b,behindDoc:t.BooleanNumber.FALSE,title:``,description:``,layoutType:t.PositionedObjectLayoutType.INLINE,wrapText:t.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=t.BuildTextUtils.drawing.add({documentDataModel:v,drawings:[x],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(v.apply(S),this._commandService.syncExecuteCommand(s.SetRangeValuesCommand.id,{value:{[(n==null?void 0:n.row)??g]:{[(n==null?void 0:n.col)??_]:{p:v.getSnapshot(),t:1}}},unitId:n==null?void 0:n.unitId,subUnitId:n==null?void 0:n.subUnitId})):!1}async insertCellImageByUrl(e,n){let r=e;try{r=await this._urlImageService.getImage(e)}catch(t){console.error(`Failed to get image from URLImageService: ${e}`,t)}let{width:i,height:c,image:l}=await(0,o.getImageSize)(r||``);this._imageIoService.addImageSourceCache(e,t.ImageSourceType.URL,l);let u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;let d=(0,t.createDocumentModelWithStyle)(``,{}),f=A(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},i,c,0);if(!f)return!1;let p=(0,a.buildDocTransform)(f.width,f.height),m={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:(0,t.generateRandomId)(),drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t.ImageSourceType.URL,source:e,transform:(0,a.docDrawingPositionToTransform)(p),docTransform:p,behindDoc:t.BooleanNumber.FALSE,title:``,description:``,layoutType:t.PositionedObjectLayoutType.INLINE,wrapText:t.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},h=t.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[m],selection:{collapsed:!0,startOffset:0,endOffset:0}});return h?(d.apply(h),this._commandService.syncExecuteCommand(s.SetRangeValuesCommand.id,{value:{[(n==null?void 0:n.row)??u.primary.actualRow]:{[(n==null?void 0:n.col)??u.primary.actualColumn]:{p:d.getSnapshot(),t:1}}},unitId:n==null?void 0:n.unitId,subUnitId:n==null?void 0:n.subUnitId})):!1}_getUnitInfo(){let e=this._context.unit,t=e.getActiveSheet();return{unitId:e.getUnitId(),subUnitId:t.getSheetId()}}_getImagePosition(e,t,n,r,i){let a=this._workbookSelections.getCurrentSelections(),o={startRow:0,endRow:0,startColumn:0,endColumn:0};a&&a.length>0&&(o=a[a.length-1].range);let c=(0,s.attachRangeWithCoord)(i,o);if(c==null)return;let{startColumn:l,startRow:u,startX:d,startY:f}=c,p=!1;if(d+e>n&&(d=n-e,d<0&&(d=0,e=n),p=!0),f+t>r&&(f=r-t,f<0&&(f=0,t=r),p=!0),p){let e=this._selectionRenderService.getCellWithCoordByOffset(d,f);if(e==null)return;d=e.startX,f=e.startY,l=e.actualColumn,u=e.actualRow}let m={column:l,columnOffset:0,row:u,rowOffset:0},h=this._selectionRenderService.getCellWithCoordByOffset(d+e,f+t);if(h!=null)return{from:m,to:{column:h.actualColumn,columnOffset:d+e-h.startX,row:h.actualRow,rowOffset:f+t-h.startY}}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{let{unitId:t,subUnitId:r,drawingIds:i,arrangeType:a}=e;this._commandService.executeCommand(n.SetDrawingArrangeCommand.id,{unitId:t,subUnitId:r,drawingIds:i,arrangeType:a})}))}_updateDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{let t=[];e.length!==0&&(e.forEach(e=>{let{unitId:r,subUnitId:i,drawingId:a,transform:o}=e,s=this._sheetSkeletonService.getSkeletonParam(r,i);if(!o||!s)return;let{skeleton:c}=s,l=this._sheetDrawingService.getDrawingByParam({unitId:r,subUnitId:i,drawingId:a});if(l==null||l.unitId!==this._context.unitId)return;let u=(0,n.transformToDrawingPosition)({...l.transform,...o},c),d=(0,n.transformToAxisAlignPosition)({...l.transform,...o},c);if(u==null||d==null)return;let f={...e,transform:{...l.transform,...o,...(0,n.drawingPositionToTransform)(u,s)},sheetTransform:{...u},axisAlignSheetTransform:{...d}};t.push(f)}),t.length>0&&this._commandService.executeCommand(n.SetSheetDrawingCommand.id,{unitId:e[0].unitId,drawings:t}))}))}_getSheetTransformByParam(e,t){let{unitId:r,subUnitId:i,drawingId:a,transform:o}=e,s=this._sheetSkeletonService.getSkeleton(r,i);if(!o||!s)return null;let c=this._sheetDrawingService.getDrawingByParam({unitId:r,subUnitId:i,drawingId:a}),l=c==null?void 0:c.transform;if(t&&(l={}),!t&&(!c||c.unitId!==this._context.unitId))return null;let u=(0,n.transformToDrawingPosition)({...l,...o},s),d=(0,n.transformToAxisAlignPosition)({...l,...o},s);return!u||!d?null:{sheetTransform:u,axisAlignSheetTransform:d}}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{let t=[];for(let n of e){let e=n.parent,r=this._getSheetTransformByParam(e,!0),i=[];for(let e of n.children){let t=this._getSheetTransformByParam(e,!1);t!=null&&i.push({...e,sheetTransform:t.sheetTransform,axisAlignSheetTransform:t.axisAlignSheetTransform})}let a={parent:{...e,sheetTransform:r==null?void 0:r.sheetTransform,axisAlignSheetTransform:r==null?void 0:r.axisAlignSheetTransform},children:i};t.push(a)}if(t.length>0){this._commandService.executeCommand(x.id,t);let{unitId:n,subUnitId:r,drawingId:i}=e[0].parent;this._commandService.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:r,drawingId:i}])}})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{let t=[];for(let n of e){let{children:e}=n,r=[];for(let t of e){let e=this._getSheetTransformByParam(t,!1);e!=null&&r.push({...t,sheetTransform:e.sheetTransform,axisAlignSheetTransform:e.axisAlignSheetTransform})}t.push({...n,children:r})}this._commandService.executeCommand(S.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}};j=O([D(1,t.ICommandService),D(2,(0,t.Inject)(s.SheetInterceptorService)),D(3,c.ISheetSelectionRenderService),D(4,t.IImageIoService),D(5,l.ILocalFileService),D(6,n.ISheetDrawingService),D(7,o.IDrawingManagerService),D(8,t.IContextService),D(9,l.IMessageService),D(10,(0,t.Inject)(t.LocaleService)),D(11,(0,t.Inject)(s.SheetsSelectionsService)),D(12,(0,t.Inject)(s.SheetSkeletonService)),D(13,(0,t.Inject)(t.Injector)),D(14,t.IURLImageService)],j);let M={id:`sheet.command.insert-float-image`,type:t.CommandType.COMMAND,handler:async(e,n)=>{var i;let a=e.get(t.IUniverInstanceService),o=e.get(r.IRenderManagerService),s=(i=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,a,o))==null?void 0:i.with(j);if(!s)return!1;let c=n==null?void 0:n.files;if(c){let e=c.map(e=>s.insertFloatImageByFile(e));return(await Promise.all(e)).every(e=>e)}else return s.insertFloatImage()??!1}},N={id:`sheet.command.insert-cell-image`,type:t.CommandType.COMMAND,handler:e=>{var n;let i=e.get(t.IUniverInstanceService),a=e.get(r.IRenderManagerService);return((n=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,i,a))==null?void 0:n.with(j).insertCellImage())??!1}},P={id:`sheet.command.move-drawing`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(n.ISheetDrawingService),o=e.get(s.SheetSkeletonService),c=e.get(l.UndoRedoGroupService),{direction:u}=r,d=a.getFocusDrawings();if(d.length===0)return!1;let f=d[0].unitId,p=d.map(e=>{let{transform:r,unitId:i,subUnitId:a}=e,s=o.getSkeleton(i,a);if(!r||!s)return null;let c={...r},{left:l=0,top:d=0}=r;return u===t.Direction.UP?c.top=d-1:u===t.Direction.DOWN?c.top=d+1:u===t.Direction.LEFT?c.left=l-1:u===t.Direction.RIGHT&&(c.left=l+1),{...e,transform:c,sheetTransform:(0,n.transformToDrawingPosition)(c,s),axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(c,s)}}).filter(e=>e!=null);return c.runTimed(f,`sheet-drawing:nudge:${d[0].subUnitId}:${d.map(e=>e.drawingId).sort().join(`,`)}`,()=>i.syncExecuteCommand(n.SetSheetDrawingCommand.id,{unitId:f,drawings:p}))?(i.syncExecuteCommand(n.ClearSheetDrawingTransformerOperation.id,[f]),!0):!1}},F=function(e){return e.CELL_ADDRESS=`cellAddress`,e.COLUMN_VALUE=`columnValue`,e}({}),I=(0,t.createIdentifier)(`sheets-drawing-ui.batch-save-images.service`);function L(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function R(e,t){return`${L(t)}${e+1}`}function z(e){let t=R(e.startRow,e.startColumn),n=R(e.endRow,e.endColumn);return t===n?t:`${t}:${n}`}function B(e){var t;let n=e.p,r=n==null||(t=n.drawingsOrder)==null?void 0:t[0];if(!(0,s.isCellImage)(n)||!r||!(n!=null&&n.drawings))return null;let i=n.drawings[r];return!i||!(`source`in i)||!(`imageSourceType`in i)?null:i}function V(e,n){if(n===t.ImageSourceType.BASE64){let t=e.match(/^data:image\/(\w+);/);if(t)return t[1]===`jpeg`?`jpg`:t[1]}if(n===t.ImageSourceType.URL){let t=e.match(/\.(\w+)(?:\?|$)/);if(t)return t[1].toLowerCase()}return`png`}async function H(e,n){if(n===t.ImageSourceType.BASE64||n===t.ImageSourceType.URL)return(await fetch(e)).blob();throw Error(`UUID image type requires additional handling`)}let U=class extends t.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._selectionService=t,this._imageIoService=n,this._urlImageService=r}getCellImagesInSelection(){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return[];let n=e.getActiveSheet();if(!n)return[];let r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return[];let i=n.getCellMatrix(),a=[];for(let e of r){let{startRow:t,endRow:n,startColumn:r,endColumn:o}=e.range;for(let e=t;e<=n;e++)for(let t=r;t<=o;t++){let n=i.getValue(e,t);if((0,s.isCellImage)(n==null?void 0:n.p)){let r=B(n);r&&a.push({row:e,col:t,cellAddress:R(e,t),source:r.source,imageSourceType:r.imageSourceType,imageId:r.drawingId})}}}return a}getCellImagesFromRanges(e,n,r){let i=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!i)return[];let a=i.getSheetBySheetId(n);if(!a)return[];let o=a.getCellMatrix(),c=[];for(let e of r){let{startRow:t,endRow:n,startColumn:r,endColumn:i}=e;for(let e=t;e<=n;e++)for(let t=r;t<=i;t++){let n=o.getValue(e,t);if((0,s.isCellImage)(n==null?void 0:n.p)){let r=B(n);r&&c.push({row:e,col:t,cellAddress:R(e,t),source:r.source,imageSourceType:r.imageSourceType,imageId:r.drawingId})}}}return c}getDataColumns(){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return[];let n=e.getActiveSheet();if(!n)return[];let r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return[];let i=n.getCellMatrix(),a=i.getDataRange(),o=1/0,s=-1/0,c=new Set;for(let e of r){o=Math.min(o,e.range.startRow),s=Math.max(s,e.range.endRow);for(let t=e.range.startColumn;t<=e.range.endColumn;t++)c.add(t)}let l=new Set;for(let e=a.startColumn;e<=a.endColumn;e++)if(!c.has(e))for(let t=o;t<=s;t++){let n=i.getValue(t,e);if(n){var u,d;if((u=n.v)!=null&&u.toString()||(d=n.p)!=null&&(d=d.body)!=null&&(d=d.dataStream)!=null&&d.trim()){l.add(e);break}}}let f=[],p=Array.from(l).sort((e,t)=>e-t);for(let e of p)f.push({index:e,label:L(e)});return f}getDataColumnsForRanges(e,n,r){let i=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!i)return[];let a=i.getSheetBySheetId(n);if(!a)return[];let o=a.getCellMatrix(),s=o.getDataRange(),c=1/0,l=-1/0,u=new Set;for(let e of r){c=Math.min(c,e.startRow),l=Math.max(l,e.endRow);for(let t=e.startColumn;t<=e.endColumn;t++)u.add(t)}let d=new Set;for(let e=s.startColumn;e<=s.endColumn;e++)if(!u.has(e))for(let t=c;t<=l;t++){let n=o.getValue(t,e);if(n){var f,p;if((f=n.v)!=null&&f.toString()||(p=n.p)!=null&&(p=p.body)!=null&&(p=p.dataStream)!=null&&p.trim()){d.add(e);break}}}let m=[],h=Array.from(d).sort((e,t)=>e-t);for(let e of h)m.push({index:e,label:L(e)});return m}getSelectionRangeNotation(){let e=this._selectionService.getCurrentSelections();return!e||e.length===0?``:e.map(e=>z(e.range)).join(`, `)}getSelectionRowRange(){let e=this._selectionService.getCurrentSelections();if(!e||e.length===0)return null;let t=1/0,n=-1/0;for(let r of e)t=Math.min(t,r.range.startRow),n=Math.max(n,r.range.endRow);return{startRow:t,endRow:n}}getSelectionColumnIndices(){let e=this._selectionService.getCurrentSelections();if(!e||e.length===0)return new Set;let t=new Set;for(let n of e)for(let e=n.range.startColumn;e<=n.range.endColumn;e++)t.add(e);return t}generateFileName(e,n){let r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),i=V(e.source,e.imageSourceType),a=[];for(let t of n.fileNameParts)if(t===`cellAddress`)a.push(e.cellAddress);else if(t===`columnValue`&&n.columnIndex!==void 0){let t=r==null?void 0:r.getActiveSheet();if(t){let r=t.getCellMatrix().getValue(e.row,n.columnIndex);if(r){var o,s;let e=((o=r.v)==null?void 0:o.toString())||((s=r.p)==null||(s=s.body)==null||(s=s.dataStream)==null?void 0:s.trim())||``;if(e){let t=e.replace(/[<>:"/\\|?*]/g,`_`).trim();t&&a.push(t)}}}}return a.length===0?`${e.cellAddress}.${i}`:`${a.join(`_`)}.${i}`}generateFileNameWithContext(e,n,r,i){let a=this._univerInstanceService.getUnit(r,t.UniverInstanceType.UNIVER_SHEET),o=V(e.source,e.imageSourceType),s=[];for(let t of n.fileNameParts)if(t===`cellAddress`)s.push(e.cellAddress);else if(t===`columnValue`&&n.columnIndex!==void 0){let t=a==null?void 0:a.getSheetBySheetId(i);if(t){let r=t.getCellMatrix().getValue(e.row,n.columnIndex);if(r){var c,l;let e=((c=r.v)==null?void 0:c.toString())||((l=r.p)==null||(l=l.body)==null||(l=l.dataStream)==null?void 0:l.trim())||``;if(e){let t=e.replace(/[<>:"/\\|?*]/g,`_`).trim();t&&s.push(t)}}}}return s.length===0?`${e.cellAddress}.${o}`:`${s.join(`_`)}.${o}`}async saveImages(e,t){let n=await window.showDirectoryPicker({mode:`readwrite`}),r=new Map;for(let a of e){var i;let e=this.generateFileName(a,t),o=e.replace(/\.\w+$/,``),s=((i=e.match(/\.\w+$/))==null?void 0:i[0])||`.png`,c=r.get(o)||0;c>0&&(e=`${o}_${c}${s}`),r.set(o,c+1);try{let t=await this._getImageBlob(a),r=await(await n.getFileHandle(e,{create:!0})).createWritable();await r.write(t),await r.close()}catch(t){throw console.error(`Failed to save image ${e}:`,t),t}}}async saveImagesWithContext(e,t,n,r){let i=await window.showDirectoryPicker({mode:`readwrite`}),a=new Map;for(let s of e){var o;let e=this.generateFileNameWithContext(s,t,n,r),c=e.replace(/\.\w+$/,``),l=((o=e.match(/\.\w+$/))==null?void 0:o[0])||`.png`,u=a.get(c)||0;u>0&&(e=`${c}_${u}${l}`),a.set(c,u+1);try{let t=await this._getImageBlob(s),n=await(await i.getFileHandle(e,{create:!0})).createWritable();await n.write(t),await n.close()}catch(t){throw console.error(`Failed to save image ${e}:`,t),t}}}async downloadSingleImage(e){let t=V(e.source,e.imageSourceType),n=`${e.cellAddress}.${t}`;try{let t=await this._getImageBlob(e),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=n,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}catch(e){throw console.error(`Failed to download image ${n}:`,e),e}}async _getImageBlob(e){return e.imageSourceType===t.ImageSourceType.UUID?H(await this._imageIoService.getImage(e.source),t.ImageSourceType.URL):e.imageSourceType===t.ImageSourceType.URL?this._urlImageService.downloadImage(e.source):H(e.source,e.imageSourceType)}};U=O([D(0,t.IUniverInstanceService),D(1,(0,t.Inject)(s.SheetsSelectionsService)),D(2,t.IImageIoService),D(3,t.IURLImageService)],U);let W=`sheet.dialog.batch-save-images`,G={id:`sheet.command.save-cell-images`,type:t.CommandType.COMMAND,handler:async e=>{let n=e.get(l.IDialogService),r=e.get(I),i=r.getCellImagesInSelection();if(i.length===1)try{return await r.downloadSingleImage(i[0]),!0}catch(e){return console.error(`Failed to download image:`,e),!1}let a=e.get(t.LocaleService),o=r.getSelectionRangeNotation(),s=`${a.t(`sheets-drawing-ui.save.title`)} (${o})`;return n.open({id:W,draggable:!0,width:360,title:{title:s},children:{label:W},preservePositionOnDestroy:!0,onClose:()=>n.close(W)}),!0}},K=`COMPONENT_SHEET_DRAWING_PANEL`,q={id:`sidebar.operation.sheet-image`,type:t.CommandType.COMMAND,handler:async(e,n)=>{let r=e.get(l.ISidebarService),i=e.get(t.LocaleService),a=e.get(t.IUniverInstanceService),c=e.get(o.IDrawingManagerService),u=e.get(t.ICommandService);if(!(0,s.getSheetCommandTarget)(a))return!1;switch(n.value){case`open`:r.open({id:K,header:{title:i.t(`sheets-drawing-ui.panel.title`)},children:{label:K},onClose:()=>{let e=c.getFocusDrawings();e.length===1&&e[0].drawingType===t.DrawingTypeEnum.DRAWING_IMAGE&&u.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[])},width:360});break;default:r.close(K);break}return!0}},J={id:`sheet.operation.edit-sheet-image`,type:t.CommandType.OPERATION,handler:(e,n)=>{let r=e.get(t.ICommandService);return n==null?!1:(r.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[n]),r.executeCommand(q.id,{value:`open`}),!0)}},Y=[c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA],X=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._sheetClipboardService=e,this._renderManagerService=t,this._sheetSkeletonService=n,this._sheetDrawingService=r,this._drawingManagerService=i,E(this,`_featurePasteHooks`,[]),E(this,`_copyInfo`,void 0),this._initCopyPaste()}get _focusedDrawings(){return this._sheetDrawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:`SHEET_DRAWING_GROUP`,onBeforeCopy:(e,n)=>{this._copyInfo=null;let r=this._focusedDrawings;if(r.length===0)return;let i=r.find(e=>e.drawingType===t.DrawingTypeEnum.DRAWING_GROUP);if(!i)return;let a=this._drawingManagerService.getDrawingsByGroupNested({unitId:i.unitId,subUnitId:i.subUnitId,drawingId:i.drawingId});a&&(this._copyInfo={unitId:i.unitId,subUnitId:i.subUnitId,groupNestedParam:a})},onPasteCells:(e,t,n,r)=>{if(!this._copyInfo)return{redos:[],undos:[]};let{pasteType:i}=r;return Y.includes(i)?{redos:[],undos:[]}:this._generateGroupPasteMutations(t)},onPasteUnrecognized:e=>this._copyInfo?this._generateGroupPasteMutations(e):{redos:[],undos:[]}})}registerFeaturePasteHook(e){this._featurePasteHooks.push(e)}_getGroupFeaturePasteMutations(e){let t=[],n=[];for(let r of this._featurePasteHooks){let i=r(e);t.push(...i.redos),n.push(...i.undos)}return{redos:t,undos:n}}_generateGroupPasteMutations(e){if(!this._copyInfo)return{redos:[],undos:[]};let{unitId:t,subUnitId:r,range:i}=e,a=this._sheetSkeletonService.getSkeleton(t,r);if(!a)return{redos:[],undos:[]};let{groupNestedParam:o}=this._copyInfo,c=o.groups[o.groups.length-1],{cloned:l,idMap:u}=y(o),d=l.groups[l.groups.length-1].drawingId,f=(0,s.discreteRangeToRange)(i),p=(0,s.attachRangeWithCoord)(a,{startRow:f.startRow,endRow:f.endRow,startColumn:f.startColumn,endColumn:f.endColumn});if(!p)return{redos:[],undos:[]};let m={...c.transform,left:p.startX,top:p.startY},h=[...(l.flatChildren??[]).map(e=>({...e,unitId:t,subUnitId:r})),...l.groups.map(e=>e.drawingId===d?{...e,unitId:t,subUnitId:r,transform:m,sheetTransform:(0,n.transformToDrawingPosition)(m,a)??c.sheetTransform,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(m,a)??c.sheetTransform}:{...e,unitId:t,subUnitId:r})],{undo:g,redo:_,objects:v}=this._sheetDrawingService.getBatchAddOp(h),b=[{id:n.SetDrawingApplyMutation.id,params:{op:_,unitId:t,subUnitId:r,objects:v,type:n.DrawingApplyType.INSERT}}],x=[{id:n.SetDrawingApplyMutation.id,params:{op:g,unitId:t,subUnitId:r,objects:v,type:n.DrawingApplyType.REMOVE}}],S=this._getGroupFeaturePasteMutations({fromUnitId:this._copyInfo.unitId,fromSubUnitId:this._copyInfo.subUnitId,toUnitId:t,toSubUnitId:r,idMap:u,cloned:l});return b.push(...S.redos),x.push(...S.undos),{redos:b,undos:x}}dispose(){this._copyInfo=null,this._featurePasteHooks.length=0,super.dispose()}};X=O([D(0,c.ISheetClipboardService),D(1,r.IRenderManagerService),D(2,(0,t.Inject)(s.SheetSkeletonService)),D(3,n.ISheetDrawingService),D(4,o.IDrawingManagerService)],X);let ee=Object.freeze({borderEnabled:!1,paintFirst:`stroke`,radius:8,rotateEnabled:!1,strokeWidth:1});var te;let ne=`univer-sheet-float-dom-`;function re(e,t,n){let r=new WeakRef(e),i=!1;return{id:t,dispose(){if(i)return;i=!0;let e=r.deref();e&&n(e,t)}}}let ie={...r.DEFAULT_TRANSFORMER_CONFIG,rotateEnabled:!1,moveBoundaryEnabled:!1},ae={...r.DEFAULT_TRANSFORMER_CONFIG,rotateEnabled:!1,keepRatio:!1,moveBoundaryEnabled:!1},oe=-100,se=`univer:embed-float-drag-handle:pointerdown`;function ce(e,t){return t.hostAnchorId===e.id&&(t.hostUnitId==null||t.hostUnitId===e.unitId)&&(t.button==null||t.button===0)&&typeof t.clientX==`number`&&typeof t.clientY==`number`}function le(e,t){if(typeof t.clientX==`number`&&typeof t.clientY==`number`)return{pointerId:t.pointerId,startClientX:t.clientX,startClientY:t.clientY,startLeft:Number(e.rect.left??0),startTop:Number(e.rect.top??0)}}function ue(e,t,n){let{scaleX:r,scaleY:i}=n.getAncestorScale();return{left:e.startLeft+(t.clientX-e.startClientX)/(r||1),top:e.startTop+(t.clientY-e.startClientY)/(i||1)}}function de(e,t){let n=t.data;if(!n||typeof n!=`object`)return;let r=n;r.version===1&&typeof r.embedId==`string`&&(e.transformerConfig={...ie,keepRatio:r.resizeBehavior===`aspect-ratio`})}function fe(e){e.transformerConfig={...e.transformerConfig,...ae}}function pe(e){if(!me(e))return!1;let n=e.data;return n.hostType===t.UniverInstanceType.UNIVER_SHEET&&n.childType===t.UniverInstanceType.UNIVER_SHEET&&n.runtimeMountMode===`stage2`}function me(e){let t=e.data;if(!t||typeof t!=`object`)return!1;let n=t;return n.version===1&&typeof n.embedId==`string`}function he(e){if(!me(e))return!1;let n=e.data;return n.hostType===t.UniverInstanceType.UNIVER_SHEET&&n.childType!=null}function ge(e,t=`inactive`){return{autoMountRuntime:!pe(e),passThroughRuntimeEvents:!(he(e)&&t===`stage2`),preserveOnFocusChange:me(e),usePreviewObject:pe(e)}}function _e(e){return ge(e).autoMountRuntime}function ve(e){return ge(e).preserveOnFocusChange}function ye(e){return ge(e).usePreviewObject}function be(e,t=`inactive`){return ge(e,t).passThroughRuntimeEvents}function xe(e){return me(e)&&!_e(e)}function Se(e,t){var n,r;if(!he(e))return!0;let i=t.target,a=i==null||(n=i.closest)==null?void 0:n.call(i,`[data-embed-float-dom="true"]`);return(a==null||(r=a.dataset)==null?void 0:r.embedFloatStage)!==`stage2`}function Ce(e){return e!==`stage2`}function we(e,t,n){if(t){if(e===`stage1`){var r,i;(r=(i=t.scene).attachTransformerTo)==null||r.call(i,n);return}if(e===`stage2`&&n.oKey){var a,o,s;t.transformer.clearControlByIds([n.oKey]),(a=(o=t.scene).getTransformer)==null||(a=a.call(o))==null||(s=a.clearSelectedObjects)==null||s.call(a)}}}function Te(e,t){return e.domLayers.some(([e])=>e===t)}function Ee(e){return e===t.DrawingTypeEnum.DRAWING_DOM||e===t.DrawingTypeEnum.DRAWING_BLOCK||e===t.DrawingTypeEnum.DRAWING_CHART}function De(e,t){if(e.runtimeMounted||e.runtimeStage!==`stage1`)return!1;let{offsetX:n,offsetY:r}=t;if(typeof n!=`number`||typeof r!=`number`)return!1;let i=e.position$.getValue();if(n>=Math.min(i.startX,i.endX)&&n<=Math.max(i.startX,i.endX)&&r>=Math.min(i.startY,i.endY)&&r<=Math.max(i.startY,i.endY))return!0;let a=e.rect;if(typeof a.isHit==`function`)try{return a.isHit({x:n,y:r})}catch{}return n>=a.left&&n<=a.left+a.width&&r>=a.top&&r<=a.top+a.height}function Oe(e,t){if(!(t.type!==`pointerdown`||!De(e,t)))return{pointerId:t.pointerId,startOffsetX:t.offsetX,startOffsetY:t.offsetY,startedAt:Date.now()}}function ke(e,t,n){return!t||n.type!==`pointerup`||t.pointerId!=null&&n.pointerId!=null&&t.pointerId!==n.pointerId||!De(e,n)?!1:Math.hypot(n.offsetX-t.startOffsetX,n.offsetY-t.startOffsetY)<=4}function Ae(e,n,i,a,o,s=!1){let{scaleX:c,scaleY:l}=n.getAncestorScale(),u=n.getViewport(r.SHEET_VIEWPORT_KEY.VIEW_MAIN),{startColumn:d,startRow:f,xSplit:p,ySplit:m}=a.getFreeze(),h={left:!0,top:!0};if(!u)return{...e,absolute:h};let{left:g,right:_,top:v,bottom:y}=e,{top:b,left:x,viewportScrollX:S,viewportScrollY:C}=u,{boundsOfViewArea:w,scrollDirectionResponse:T}=o||{},{rowHeaderWidth:E,columnHeaderHeight:D}=i,O={top:s?0:D,left:s?0:E};w&&(t.Tools.isDefine(O.top)&&(O.top=w.top),t.Tools.isDefine(O.left)&&(O.left=w.left)),T===`HORIZONTAL`&&(C=0),T===`VERTICAL`&&(S=0);let k=0,A=0,j=i.rowStartY(f-m)+D,M=i.colStartX(d-p)+E,N=i.rowStartY(f)+D,P=i.colStartX(d)+E;if(p===0)h.left=!1,k=(g-S)*c,A=(_-S)*c;else{let e=g-(M-E),t=_-(M-E);_<P?(k=e*c,A=t*c):g<=P&&_>=P?(k=e*c,A=Math.max(x,(_-S)*c)):g>P&&(h.left=!1,k=Math.max((g-S)*c,x),A=Math.max((_-S)*c,x))}let F=0,I=0;if(m===0)h.top=!1,F=(v-C)*l,I=(y-C)*l;else{let e=v-(j-D),t=y-(j-D);y<N?(F=e*l,I=t*l):v<=N&&y>=N?(F=e*l,I=Math.max(b,(y-C)*l)):v>N&&(h.top=!1,F=Math.max((v-C)*l,b),I=Math.max((y-C)*l,b))}return k=Math.max(k,O.left),F=Math.max(F,O.top),A=Math.max(A,O.left),I=Math.max(I,O.top),{left:k,right:A,top:F,bottom:I,absolute:h}}let Z=(e,t,n,r,i)=>{let{left:a,top:o,width:s,height:c,angle:l}=e,u=Ae({left:a,right:a+s,top:o,bottom:o+c},t,n,r,i),{scaleX:d,scaleY:f}=t.getAncestorScale();return{startX:u.left,endX:u.right,startY:u.top,endY:u.bottom,rotate:l,width:s*d,height:c*f,absolute:u.absolute}},Q=te=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._renderManagerService=e,this._univerInstanceService=t,this._commandService=n,this._drawingManagerService=r,this._canvasFloatDomService=i,this._sheetDrawingService=a,this._lifecycleService=o,this._canvasFloatDomPreviewService=s,E(this,`_domLayerInfoMap`,new Map),E(this,`_transformChange$`,new d.Subject),E(this,`transformChange$`,this._transformChange$.asObservable()),E(this,`_add$`,new d.Subject),E(this,`add$`,this._add$.asObservable()),E(this,`_remove$`,new d.Subject),E(this,`remove$`,this._remove$.asObservable()),E(this,`_renderObjectFactories`,new Map),this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent(),this._bindEmbedFloatDragHandleEvent()}registerRenderObjectFactory(e,t){let n=this._renderObjectFactories.get(e)??[];return n.push(t),this._renderObjectFactories.set(e,n),{dispose:()=>{let n=this._renderObjectFactories.get(e);if(!n)return;let r=n.indexOf(t);r>=0&&n.splice(r,1),n.length===0&&this._renderObjectFactories.delete(e)}}}_createRenderObject(e){let t=this._renderObjectFactories.get(e.drawingType),n=t==null?void 0:t[t.length-1];return(n==null?void 0:n(e))??new r.Rect(e.key,e.config)}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe((0,d.filter)(e=>e===t.LifecycleStages.Rendered),(0,d.take)(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(e){return this._domLayerInfoMap.get(e)}getFloatDomsBySubUnitId(e,t){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===t&&n.unitId===e)}static _disposeExternalFloatDom(e,t){e._removeDom(t,!0)}_createFloatDomDisposable(e){return re(this,e,te._disposeExternalFloatDom)}_bindEmbedFloatDragHandleEvent(){if(typeof document>`u`)return;let e=e=>this._handleEmbedFloatDragHandlePointerDown(e);document.addEventListener(se,e),this.disposeWithMe(()=>document.removeEventListener(se,e))}_handleEmbedFloatDragHandlePointerDown(e){let t=e.detail;if(!(t!=null&&t.hostAnchorId))return;let n=this._domLayerInfoMap.get(t.hostAnchorId);if(!n||!ce(n,t))return;let r=le(n,t),i=this._getSceneAndTransformerByDrawingSearch(n.unitId);if(!r||!i)return;let{scene:a,transformer:o}=i;if(n.rect.oKey){var s;o.clearControlByIds([n.rect.oKey]),(s=a.getTransformer())==null||s.clearSelectedObjects()}let c=e=>{if(r.pointerId!=null&&e.pointerId!==r.pointerId)return;e.preventDefault();let t=ue(r,e,a);n.rect.transformByState(t)},l=e=>{if((r.pointerId==null||e.pointerId===r.pointerId)&&(window.removeEventListener(`pointermove`,c,!0),window.removeEventListener(`pointerup`,l,!0),window.removeEventListener(`pointercancel`,u,!0),e.preventDefault(),(n.rect.left!==r.startLeft||n.rect.top!==r.startTop)&&this._commitFloatDomMove(n),n.runtimeStage===`stage1`)){var t;(t=a.attachTransformerTo)==null||t.call(a,n.rect)}},u=e=>{if((r.pointerId==null||e.pointerId===r.pointerId)&&(window.removeEventListener(`pointermove`,c,!0),window.removeEventListener(`pointerup`,l,!0),window.removeEventListener(`pointercancel`,u,!0),n.rect.transformByState({left:r.startLeft,top:r.startTop}),n.runtimeStage===`stage1`)){var t;(t=a.attachTransformerTo)==null||t.call(a,n.rect)}};window.addEventListener(`pointermove`,c,!0),window.addEventListener(`pointerup`,l,!0),window.addEventListener(`pointercancel`,u,!0)}_commitFloatDomMove(e){var t;let r=(t=this._renderManagerService.getRenderUnitById(e.unitId))==null?void 0:t.with(c.SheetSkeletonManagerService).getSkeletonParam(e.subUnitId),i=this._sheetDrawingService.getDrawingByParam({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.id});if(!r||!(i!=null&&i.transform))return;let a={...i.transform,left:e.rect.left,top:e.rect.top,width:e.rect.width,height:e.rect.height,angle:e.rect.angle,flipX:e.rect.flipX,flipY:e.rect.flipY,skewX:e.rect.skewX,skewY:e.rect.skewY},o=(0,n.transformToDrawingPosition)(a,r.skeleton),s=(0,n.transformToAxisAlignPosition)(a,r.skeleton);!o||!s||this._commandService.syncExecuteCommand(n.SetSheetDrawingCommand.id,{unitId:e.unitId,drawings:[{...i,transform:a,sheetTransform:o,axisAlignSheetTransform:s}]})}isFloatDomRuntimeMounted(e){var t;return((t=this._domLayerInfoMap.get(e))==null?void 0:t.runtimeMounted)===!0}_getFloatDomPreviewObjectKey(e){return`${e}__preview`}_syncPreviewObjectTransform(e,t){e==null||e.transformByState({left:t.left,top:t.top,width:t.width,height:t.height,angle:t.angle,flipX:t.flipX,flipY:t.flipY,skewX:t.skewX,skewY:t.skewY})}_requestFloatDomPreview(e,t,n){this._canvasFloatDomPreviewService&&this._canvasFloatDomPreviewService.requestPreview({id:e,width:t.width,height:t.height,data:n})}_upsertFloatDomPreviewObject(e,t,n,i,a){var o;let s=(o=this._canvasFloatDomPreviewService)==null?void 0:o.getPreview(i);if(!(s!=null&&s.image)){this._requestFloatDomPreview(i,t,a);return}let c=this._getFloatDomPreviewObjectKey(n),l=e.getObject(c);if(l instanceof r.Image)return l.changeSource(s.image),this._syncPreviewObjectTransform(l,t),l;let u=new r.Image(c,{left:t.left,top:t.top,width:t.width,height:t.height,angle:t.angle,flipX:t.flipX,flipY:t.flipY,skewX:t.skewX,skewY:t.skewY,url:s.image,evented:!1,rotateEnabled:!1,resizeEnabled:!1});return e.addObject(u,r.DRAWING_OBJECT_LAYER_INDEX),u}mountFloatDomRuntime(e){let t=this._domLayerInfoMap.get(e);return t!=null&&t.floatDomConfig?t.runtimeMounted?!0:(Te(this._canvasFloatDomService,e)?this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:!1,props:{...t.floatDomConfig.props,initialStage:`stage2`,onRuntimeStageExit:()=>this.unmountFloatDomRuntime(e)}}):this._canvasFloatDomService.addFloatDom({...t.floatDomConfig,eventPassThrough:!1,props:{...t.floatDomConfig.props,initialStage:`stage2`,onRuntimeStageExit:()=>this.unmountFloatDomRuntime(e)}}),t.runtimeMounted=!0,t.runtimeStage=`stage2`,!0):!1}unmountFloatDomRuntime(e){let t=this._domLayerInfoMap.get(e);t!=null&&t.runtimeMounted&&(t.floatDomConfig&&!_e(t.floatDomConfig)?this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:be(t.floatDomConfig,`inactive`),props:t.floatDomConfig.props}):this._canvasFloatDomService.removeFloatDom(e),t.runtimeMounted=!1,t.runtimeStage=`inactive`)}_syncFloatDomVisibilityForActiveSheet(e,t){Array.from(this._domLayerInfoMap.values()).filter(t=>t.unitId===e&&t.floatDomConfig).forEach(e=>{let n=e.subUnitId===t,r=Te(this._canvasFloatDomService,e.id);if(!n){r&&this._canvasFloatDomService.removeFloatDom(e.id),e.runtimeMounted=!1,e.runtimeStage=`inactive`;return}if(r||!e.floatDomConfig)return;this._canvasFloatDomService.addFloatDom(e.floatDomConfig);let i=_e(e.floatDomConfig);e.runtimeMounted=i,e.runtimeStage=me(e.floatDomConfig)?`inactive`:i?`stage2`:`inactive`})}promoteFloatDomRuntimeStage(e){let t=this._domLayerInfoMap.get(e);if(!(t!=null&&t.floatDomConfig))return;let n=he(t.floatDomConfig);return t.runtimeMounted&&!n?(t.runtimeStage=`stage2`,`stage2`):t.runtimeStage===`stage1`?t.runtimeMounted?(t.runtimeStage=`stage2`,xe(t.floatDomConfig)&&this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:be(t.floatDomConfig,`stage2`)}),`stage2`):(this.mountFloatDomRuntime(e),`stage2`):(t.runtimeStage=`stage1`,xe(t.floatDomConfig)&&this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:be(t.floatDomConfig,`stage1`)}),`stage1`)}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderUnitById(e),n=t==null?void 0:t.scene;return t==null||n==null?null:{scene:n,transformer:n.getTransformerByCreate(),renderUnit:t,canvas:t.engine.getCanvasElement()}}_getDrawingZIndex(e,t,n){let r=this._drawingManagerService.getDrawingOrder(e,t),i=r.indexOf(n);return i<0?r.length-1:i}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(e=>{var n;let{unitId:i,subUnitId:a,drawingId:l}=e,f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:i,subUnitId:a}),p=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(i,t.UniverInstanceType.UNIVER_SHEET);if(!m)return;let h=m.getActiveSheet().getSheetId();if(!p||!f)return;let g=(n=this._renderManagerService.getRenderUnitById(i))==null?void 0:n.with(c.SheetSkeletonManagerService).getSkeletonParam(a);if(!g)return;let{transform:_,drawingType:v,data:y,hidden:b,groupId:x}=p;if(!Ee(v))return;let S=this._getSceneAndTransformerByDrawingSearch(i);if(S==null||b)return;let{scene:C,canvas:w}=S;if(_==null)return!0;if(h!==a)return;let{left:T,top:E,width:D,height:O,angle:k,flipX:A,flipY:j,skewX:M,skewY:N}=_,P=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:l}),F=x?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:x}):void 0,I=this._getObjectIncludingGroup(C,P,F);if(I!=null&&(this._removeTopLevelDuplicateIfGrouped(C,P,I),de(I,p),v===t.DrawingTypeEnum.DRAWING_CHART&&fe(I),I.transformByState({left:T,top:E,width:D,height:O,angle:k,flipX:A,flipY:j,skewX:M,skewY:N}),this._syncFloatDomRect(l,I),ye(p)&&(this._syncPreviewObjectTransform(C.getObject(this._getFloatDomPreviewObjectKey(P)),I),this._requestFloatDomPreview(l,I,y)),this._domLayerInfoMap.has(l)))return;let L={left:T,top:E,width:D,height:O,zIndex:this._getDrawingZIndex(i,a,l)},R=v===t.DrawingTypeEnum.DRAWING_CHART;if(R){let e=this._getChartDataBackground(y);e!==void 0&&(L.fill=e),y&&y.border&&(L.stroke=y.border),Object.assign(L,ee)}else L.rotateEnabled=!1;let z=I??this._createRenderObject({key:P,config:L,unitId:i,subUnitId:a,drawingId:l,drawingType:v,data:y});de(z,p),R&&fe(z),R?z.objectType=r.ObjectType.CHART:(v===t.DrawingTypeEnum.DRAWING_DOM||v===t.DrawingTypeEnum.DRAWING_BLOCK)&&(z.objectType=r.ObjectType.DRAWING_DOM),I||C.addObject(z,r.DRAWING_OBJECT_LAYER_INDEX),!I&&p.allowTransform!==!1&&C.attachTransformerTo(z),!I&&R&&x&&(0,u.insertGroupObject)({drawingId:x,unitId:i,subUnitId:a},z,C,this._drawingManagerService);let B=new t.DisposableCollection,V=ye(p),H=V?this._getFloatDomPreviewObjectKey(P):void 0;if(V){var U;this._upsertFloatDomPreviewObject(C,z,P,l,y);let e=(U=this._canvasFloatDomPreviewService)==null?void 0:U.previewUpdated$.subscribe(e=>{e.id===l&&this._upsertFloatDomPreviewObject(C,z,P,l,y)});e&&B.add(e)}let W=new d.BehaviorSubject(Z(z,S.renderUnit.scene,g.skeleton,f.worksheet)),G=`${ne}${(0,t.generateRandomId)(6)}`,K=_e(p),q=me(p),J,Y={position$:W,id:l,domId:G,componentKey:p.componentKey,eventPassThrough:be(p,`inactive`),preserveOnFocusChange:ve(p),onPointerDown:e=>{Se(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{Se(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{Se(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onWheel:e=>{Se(p,e)&&w.dispatchEvent(new WheelEvent(e.type,e))},data:y,props:q?{onRuntimeStageEnter:e=>{J&&(J.runtimeStage=e,J.runtimeMounted=K||e===`stage2`,xe(p)&&this._canvasFloatDomService.updateFloatDom(l,{eventPassThrough:be(p,e)})),we(e,this._getSceneAndTransformerByDrawingSearch(i),z)}}:void 0,unitId:i};if(J={dispose:B,rect:z,position$:W,unitId:i,subUnitId:a,id:l,domId:G,floatDomConfig:Y,runtimeMounted:K,runtimeStage:q?`inactive`:K?`stage2`:`inactive`,previewObjectKey:H},this._canvasFloatDomService.addFloatDom(Y),!K){let e,t=t=>{if(e&&(e.pointerId==null||t.pointerId==null||e.pointerId===t.pointerId)){if(typeof t.offsetX!=`number`||typeof t.offsetY!=`number`){e=void 0;return}Math.hypot(t.offsetX-e.startOffsetX,t.offsetY-e.startOffsetY)>4&&(e=void 0)}},n=z.onPointerDown$.subscribeEvent({priority:oe,next:([t,n])=>{if((J==null?void 0:J.runtimeStage)===`stage1`){e=Oe(J,t);return}let r=this.promoteFloatDomRuntimeStage(l);r===`stage2`&&(we(r,S,z),n.skipNextObservers=!0),Ce(r)||n.stopPropagation()}}),r=C.onPointerDown$.subscribeEvent({priority:oe,next:([t])=>{J&&(e=Oe(J,t))}}),i=C.onPointerMove$.subscribeEvent({priority:oe,next:([e])=>{t(e)}}),a=C.onPointerUp$.subscribeEvent({priority:oe,next:([t,n])=>{let r=J&&ke(J,e,t);if(e=void 0,!r)return;let i=this.promoteFloatDomRuntimeStage(l);i===`stage2`&&(we(i,S,z),n.stopPropagation(),n.skipNextObservers=!0)}});B.add(n),B.add(r),B.add(i),B.add(a)}let X=z.onTransformChange$.subscribeEvent(()=>{let e=Z(z,S.renderUnit.scene,g.skeleton,f.worksheet);W.next(e),H&&this._syncPreviewObjectTransform(C.getObject(H),z)});B.add(()=>{this._canvasFloatDomService.removeFloatDom(l),H&&C.removeObject(H)}),X&&B.add(X),this._bindFloatDomScroll(B,J,S.renderUnit.scene,g.skeleton,f.worksheet),this._domLayerInfoMap.set(l,J)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:n,drawingId:r}),a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let{transformer:s,scene:c}=a,l=this._getObjectIncludingGroup(c,i);if(l!=null&&l.oKey){var u;s.clearControlByIds([l==null?void 0:l.oKey]),(u=c.getTransformer())==null||u.clearSelectedObjects()}})}))}_scrollUpdateListener(){let e=(e,t)=>{var n;let r=this._getSceneAndTransformerByDrawingSearch(e),i=Array.from(this._domLayerInfoMap.keys()).map(e=>({id:e,...this._domLayerInfoMap.get(e)})).filter(n=>n.subUnitId===t&&n.unitId===e).map(e=>e.id),a=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:t}),o=(n=this._renderManagerService.getRenderUnitById(e))==null?void 0:n.with(c.SheetSkeletonManagerService).getSkeletonParam(t);!r||!a||!o||i.forEach(e=>{let t=this._domLayerInfoMap.get(e);if(t){let e=Z(t.rect,r.renderUnit.scene,o.skeleton,a.worksheet,t);t.position$.next(e)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,d.switchMap)(e=>e?e.activeSheet$:(0,d.of)(null))).subscribe(t=>{if(!t)return;let n=t.getUnitId(),r=t.getSheetId();this._syncFloatDomVisibilityForActiveSheet(n,r),e(n,r)})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===c.SetZoomRatioOperation.id){let{unitId:n}=t.params;new Set(Array.from(this._domLayerInfoMap.values()).filter(e=>e.unitId===n).map(e=>e.subUnitId)).forEach(t=>{e(n,t)})}else if(t.id===s.SetFrozenMutation.id){let{unitId:n,subUnitId:r}=t.params;e(n,r)}else if(t.id===s.SetSelectionsOperation.id){let{unitId:n,subUnitId:r}=t.params;e(n,r)}}))}_bindFloatDomScroll(e,n,i,a,o){let s=i.getViewport(r.SHEET_VIEWPORT_KEY.VIEW_MAIN);s&&e.add((0,t.fromEventSubject)(s.onScrollAfter$).subscribe(()=>{n.position$.next(Z(n.rect,i,a,o,n))}))}updateFloatDomProps(e,t,n,i){let a=this._domLayerInfoMap.get(n),s=this._getSceneAndTransformerByDrawingSearch(e);if(a&&s){let{scene:a}=s,c=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:n}),l=this._drawingManagerService.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n}),u=l!=null&&l.groupId?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:l.groupId}):void 0,d=this._getObjectIncludingGroup(a,c,u);d&&d instanceof r.Rect&&(this._removeTopLevelDuplicateIfGrouped(a,c,d),d.setProps(i),this._syncFloatDomRect(n,d))}}_getObjectIncludingGroup(e,t,n){var r;return this._getChildObjectFromGroup(e,t,n)??((r=e.getObjectIncludeInGroup)==null?void 0:r.call(e,t))??e.getObject(t)??null}_getChildObjectFromGroup(e,t,n){var r;if(!n)return null;let i=((r=e.getObjectIncludeInGroup)==null?void 0:r.call(e,n))??e.getObject(n);return this._findChildObject(i,t)}_findChildObject(e,t){if(!e)return null;let n=e.getObjects();for(let e of n){if(e.oKey===t)return e;let n=this._findChildObject(e,t);if(n)return n}return null}_removeTopLevelDuplicateIfGrouped(e,t,n){if(!n.isInGroup)return;let r=e.getObject(t);r&&r!==n&&e.removeObject(r)}_syncFloatDomRect(e,t){if(!(t instanceof r.Rect))return;let n=this._domLayerInfoMap.get(e);n&&(n.rect=t)}_getChartDataBackground(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e,n=t.backgroundColor??t.background;return typeof n==`string`?n:void 0}_getPosition(e,t){var n;let{startX:r,endX:i,startY:a,endY:o}=e,s=(n=this._renderManagerService.getRenderUnitById(t))==null?void 0:n.with(c.ISheetSelectionRenderService);if(s==null)return;let l=s.getCellWithCoordByOffset(r,a);if(l==null)return;let u={column:l.actualColumn,columnOffset:r-l.startX,row:l.actualRow,rowOffset:a-l.startY},d=s.getCellWithCoordByOffset(i,o);if(d!=null)return{from:u,to:{column:d.actualColumn,columnOffset:i-d.startX,row:d.actualRow,rowOffset:o-d.startY}}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let n=this._drawingManagerService.getDrawingByParam(e);if(!n||!Ee(n.drawingType))return;if(n.hidden){this._removeDom(e.drawingId);return}if(!this._domLayerInfoMap.has(e.drawingId)){this._drawingManagerService.addNotification([e]);return}let r={...n.transform};this._transformChange$.next({id:e.drawingId,value:r}),this._canvasFloatDomService.updateFloatDom(e.drawingId,{...n});let i=this._getSceneAndTransformerByDrawingSearch(e.unitId);if(i&&n.drawingType!==t.DrawingTypeEnum.DRAWING_CHART){let{scene:t}=i,r=this._domLayerInfoMap.get(e.drawingId);r!=null&&r.rect&&(n.allowTransform===!1?t.detachTransformerFrom(r.rect):t.attachTransformerTo(r.rect))}})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{this._removeDom(e.drawingId)})}))}addFloatDomToPosition(e,r){let i=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!i)throw Error(`cannot find current target!`);let{unitId:a,subUnitId:o}=i,{initPosition:c,componentKey:l,data:u,allowTransform:d=!0}=e,f=r??(0,t.generateRandomId)(),p=this._getPosition(c,a);if(p==null)return;let m={unitId:a,subUnitId:o,drawingId:f,drawingType:e.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:p,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},axisAlignSheetTransform:p,data:u,allowTransform:d};return this._commandService.executeCommand(n.InsertSheetDrawingCommand.id,{unitId:a,drawings:[m]}),this._add$.next({unitId:a,subUnitId:o,id:f}),this._createFloatDomDisposable(f)}_removeDom(e,t=!1){let r=this._domLayerInfoMap.get(e);if(!r)return;let{unitId:i,subUnitId:a}=r;this._domLayerInfoMap.delete(e),r.dispose.dispose();let o=this._getSceneAndTransformerByDrawingSearch(i);if(o){let{scene:t,transformer:n}=o;if((0,u.disposeDrawingRenderObject)(t,{unitId:i,subUnitId:a,drawingId:e})){var s;n.clearControlByIds([r.rect.oKey]),(s=t.getTransformer())==null||s.clearSelectedObjects()}}if(t){let t=this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:a,drawingId:e});if(!t)return;let{redo:r,objects:o}=this._sheetDrawingService.getBatchRemoveOp([t]);this._commandService.syncExecuteCommand(n.SetDrawingApplyMutation.id,{unitId:i,subUnitId:a,op:r,objects:o,type:n.DrawingApplyType.REMOVE})}}removeFloatDom(e,t=!0){this._removeDom(e,t)}addFloatDomToRange(e,n,i,a){var l;let f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!f)throw Error(`cannot find current target!`);let{unitId:p,subUnitId:m}=f,h=this._getSceneAndTransformerByDrawingSearch(p);if(!h)return;let g=this._renderManagerService.getRenderUnitById(p);if(!g)return;let _=(l=this._renderManagerService.getRenderUnitById(p))==null?void 0:l.with(c.SheetSkeletonManagerService).getSkeletonParam(m);if(!_)return;let{componentKey:v,data:y,allowTransform:b=!0}=n,x=a??(0,t.generateRandomId)(),{position:S,position$:C}=this._createRangePositionObserver(e,g,_.skeleton),w=this._getPosition(S,p);if(w==null)return;let{scaleX:T}=h.scene.getAncestorScale(),E=Me(S,i,T),D={unitId:p,subUnitId:m,drawingId:x,drawingType:n.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:v,sheetTransform:w,axisAlignSheetTransform:w,transform:{left:E.startX,top:E.startY,width:E.width,height:E.height},data:y,allowTransform:b};{var O,k;let{unitId:e,subUnitId:a,drawingId:l}=D,f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:a}),p=D,m=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!m)return;let h=m.getActiveSheet().getSheetId();if(!p||!f)return;let g=(O=this._renderManagerService.getRenderUnitById(e))==null?void 0:O.with(c.SheetSkeletonManagerService);if(!g)return;let _=g.getSkeletonParam(a);if(!_)return;let{transform:v,drawingType:y,data:b,groupId:w}=p;if(!Ee(y))return;let T=this._getSceneAndTransformerByDrawingSearch(e);if(T==null)return;let{scene:E,canvas:A}=T;if(v==null||h!==a)return;let{left:j,top:M,width:N,height:P,angle:F,flipX:I,flipY:L,skewX:R,skewY:z}=v,B=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),V=w?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:w}):void 0,H=this._getObjectIncludingGroup(E,B,V);if(H!=null){this._removeTopLevelDuplicateIfGrouped(E,B,H),y===t.DrawingTypeEnum.DRAWING_CHART&&fe(H),H.transformByState({left:j,top:M,width:N,height:P,angle:F,flipX:I,flipY:L,skewX:R,skewY:z}),this._syncFloatDomRect(l,H);return}let U={left:j,top:M,width:N,height:P,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1},W=y===t.DrawingTypeEnum.DRAWING_CHART;if(W){let e=this._getChartDataBackground(b);e!==void 0&&(U.fill=e),U.rotateEnabled=!1,b&&b.border&&(U.stroke=b.border),U.paintFirst=`stroke`,U.strokeWidth=1,U.radius=8}let G=this._createRenderObject({key:B,config:U,unitId:e,subUnitId:a,drawingId:l,drawingType:y,data:b});W&&(G.setObjectType(r.ObjectType.CHART),fe(G)),E.addObject(G,r.DRAWING_OBJECT_LAYER_INDEX),p.allowTransform!==!1&&E.attachTransformerTo(G),W&&w&&(0,u.insertGroupObject)({drawingId:w,unitId:e,subUnitId:a},G,E,this._drawingManagerService);let K=new t.DisposableCollection,q=E.getMainViewport(),{rowHeaderWidth:J,columnHeaderHeight:Y}=_.skeleton,X={dispose:K,rect:G,boundsOfViewArea:{top:Y,left:J,bottom:q.bottom,right:q.right},domAnchor:i,unitId:e,subUnitId:a,id:l},ee=new d.BehaviorSubject(Z(G,T.renderUnit.scene,_.skeleton,f.worksheet,X));X.position$=ee;let te={position$:ee,id:l,componentKey:p.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:e=>{A.dispatchEvent(new WheelEvent(e.type,e))},data:b,unitId:e};n.eventPassThrough&&(te={...te,onPointerDown:e=>{A.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{A.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{A.dispatchEvent(new PointerEvent(e.type,e))}}),this._canvasFloatDomService.addFloatDom(te),this.disposeWithMe(C.subscribe(t=>{let n=Me({rotate:0,startX:t.startX,startY:t.startY,endX:t.endX,endY:t.endY,width:i.width??t.width,height:i.height??t.height,absolute:{left:S.absolute.left,top:S.absolute.top}},i),s=new r.Rect((0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),{left:n.startX,top:n.startY,width:i.width??t.width,height:i.height??t.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1}),c=Z(s,T.renderUnit.scene,_.skeleton,f.worksheet,X);ee.next(c)}));let ne=(k=this._renderManagerService.getRenderUnitById(e))==null?void 0:k.with(c.SheetSkeletonManagerService),re=ne==null?void 0:ne.currentSkeleton$.subscribe(e=>{e&&_.sheetId!==e.sheetId&&this._removeDom(x,!0)});re&&K.add(re);let ie=G.onTransformChange$.subscribeEvent(()=>{let e=Z(G,T.renderUnit.scene,_.skeleton,f.worksheet,X);ee.next(e)});K.add(()=>{this._canvasFloatDomService.removeFloatDom(l)}),ie&&K.add(ie),this._bindFloatDomScroll(K,X,T.renderUnit.scene,_.skeleton,f.worksheet),this._domLayerInfoMap.set(l,X)}return this._createFloatDomDisposable(x)}addFloatDomToColumnHeader(e,n,i,a){var l;let u=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!u)throw Error(`cannot find current target!`);let{unitId:f,subUnitId:p}=u;if(!this._getSceneAndTransformerByDrawingSearch(f))return;let m=this._renderManagerService.getRenderUnitById(f);if(!m)return;let h=(l=this._renderManagerService.getRenderUnitById(f))==null?void 0:l.with(c.SheetSkeletonManagerService).getSkeletonParam(p);if(!h)return;let{componentKey:g,data:_,allowTransform:v=!0}=n,y=a??(0,t.generateRandomId)(),{position:b,position$:x}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:e,endColumn:e},m,h.skeleton),S=b;S.startY=0;let C=this._getPosition(b,f);if(C==null)return;let w={unitId:f,subUnitId:p,drawingId:y,drawingType:n.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:g,sheetTransform:C,axisAlignSheetTransform:C,transform:{left:S.startX,top:S.startY,width:S.width,height:S.height},data:_,allowTransform:v};{var T,E;let{unitId:e,subUnitId:a,drawingId:l}=w,u=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:a}),f=w,p=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!p)return;let m=p.getActiveSheet().getSheetId();if(!f||!u)return;let g=(T=this._renderManagerService.getRenderUnitById(e))==null?void 0:T.with(c.SheetSkeletonManagerService);if(!g)return;let _=g.getSkeletonParam(a);if(!_)return;let{transform:v,data:C}=f,D=this._getSceneAndTransformerByDrawingSearch(e);if(D==null)return;let{scene:O,canvas:k}=D;if(v==null||m!==a)return;let{left:A,top:j,width:M,height:N,angle:P,flipX:F,flipY:I,skewX:L,skewY:R}=v,z=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),B=this._getObjectIncludingGroup(O,z);if(B!=null){this._removeTopLevelDuplicateIfGrouped(O,z,B),B.transformByState({left:A,top:j,width:M,height:N,angle:P,flipX:F,flipY:I,skewX:L,skewY:R}),this._syncFloatDomRect(l,B);return}let V=Me({rotate:0,startX:S.startX,startY:0,endX:b.endX,endY:b.endY,width:i.width,height:i.height,absolute:{left:b.absolute.left,top:b.absolute.top}},i),H=new r.Rect(z,{left:V.startX,top:V.startY,width:V.width,height:V.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1});O.addObject(H,r.DRAWING_OBJECT_LAYER_INDEX),f.allowTransform!==!1&&O.attachTransformerTo(H);let U=new t.DisposableCollection,W=O.getMainViewport(),G={dispose:U,rect:H,unitId:e,subUnitId:a,id:l,boundsOfViewArea:{top:0,left:W.left,bottom:W.bottom,right:W.right},domAnchor:i,scrollDirectionResponse:`HORIZONTAL`},K=new d.BehaviorSubject(Z(H,D.renderUnit.scene,_.skeleton,u.worksheet,G));G.position$=K;let q={position$:K,id:l,componentKey:f.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:e=>{k.dispatchEvent(new WheelEvent(e.type,e))},data:C,unitId:e};n.eventPassThrough&&(q={...q,onPointerDown:e=>{k.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{k.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{k.dispatchEvent(new PointerEvent(e.type,e))}}),this._canvasFloatDomService.addFloatDom(q);let J=H.onTransformChange$.subscribeEvent(()=>{let e=Z(H,D.renderUnit.scene,_.skeleton,u.worksheet,G);K.next(e)});this.disposeWithMe(x.subscribe(t=>{let n=Me({rotate:0,startX:t.startX,startY:0,endX:t.endX,endY:t.endY,width:i.width,height:i.height,absolute:{left:b.absolute.left,top:b.absolute.top}},i),s=new r.Rect((0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),{left:n.startX,top:0,width:i.width,height:i.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1}),c=Z(s,D.renderUnit.scene,_.skeleton,u.worksheet,G);K.next(c)}));let Y=(E=this._renderManagerService.getRenderUnitById(e))==null?void 0:E.with(c.SheetSkeletonManagerService);Y==null||Y.currentSkeleton$.subscribe(e=>{e&&h.sheetId!==e.sheetId&&this._removeDom(y,!0)}),U.add(()=>{this._canvasFloatDomService.removeFloatDom(l)}),J&&U.add(J),this._bindFloatDomScroll(U,G,D.renderUnit.scene,_.skeleton,u.worksheet),this._domLayerInfoMap.set(l,G)}return this._createFloatDomDisposable(y)}_createRangePositionObserver(e,n,r){let{startRow:i,startColumn:a}=e,o=je(i,a,r),l=new d.BehaviorSubject(o),u=je(e.endRow,e.endColumn,r),f=new d.BehaviorSubject(u),p=()=>{let t=je(i,a,r),n=je(e.endRow,e.endColumn,r);l.next(t),f.next(n)},m=new t.DisposableCollection;return m.add(n.engine.clientRect$.subscribe({next:()=>p(),error:()=>{}})),m.add(this._commandService.onCommandExecuted(e=>{if(e.id===s.SetWorksheetRowAutoHeightMutation.id&&e.params.rowsAutoHeightInfo.findIndex(e=>e.row===i)>-1){p();return}(s.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(e.id)>-1||e.id===c.SetScrollOperation.id||e.id===c.SetZoomRatioOperation.id)&&p()})),{position$:l.pipe((0,d.map)(t=>{let n=je(e.endRow,e.endColumn,r);return{rotate:0,width:n.right-t.left,height:n.bottom-t.top,absolute:{left:!0,top:!0},startX:t.left,startY:t.top,endX:n.right,endY:n.bottom}})),position:{rotate:0,width:u.right-o.left,height:u.bottom-o.top,absolute:{left:!0,top:!0},startX:o.left,startY:o.top,endX:u.right,endY:u.bottom},updateRowCol:(e,t)=>{i=e,a=t,p()},topLeftPos$:l,rightBottomPos$:f,disposable:m}}};Q=te=O([D(0,(0,t.Inject)(r.IRenderManagerService)),D(1,t.IUniverInstanceService),D(2,(0,t.Inject)(t.ICommandService)),D(3,o.IDrawingManagerService),D(4,(0,t.Inject)(l.CanvasFloatDomService)),D(5,n.ISheetDrawingService),D(6,(0,t.Inject)(t.LifecycleService)),D(7,(0,t.Optional)(l.CanvasFloatDomPreviewService))],Q);function je(e,t,n){let r=n.getCellWithCoordByIndex(e,t),i=r.isMergedMainCell?r.mergeInfo:r;return{left:i.startX,right:i.endX,top:i.startY,bottom:i.endY}}function Me(e,t,n){n??=1;let r=e.endX-e.startX,i=e.endY-e.startY,a=(t==null?void 0:t.width)??r,o=(t==null?void 0:t.height)??i,s=0,c=0;if(t){if(t.horizonOffsetAlign===`right`){let i=Ne(t.marginX,r*n);s=e.endX-i-a}else s=e.startX+Ne(t.marginX,r);if(t.verticalOffsetAlign===`bottom`){let r=Ne(t.marginY,i*n);c=e.endY-r-o}else c=e.startY+Ne(t.marginY,i)}return{rotate:0,startX:s,startY:c,endX:e.endX,endY:e.endY,width:a,height:o,absolute:{left:e.absolute.left,top:e.absolute.top}}}function Ne(e,t){return e===void 0?0:typeof e==`number`?e:t*Number.parseFloat(e)/100}let Pe=[[Q]];function Fe(e){e.has(Q)||(0,t.registerDependencies)(e,Pe),Le(e)}function Ie(e){(0,t.touchDependencies)(e,[[Q]])}function Le(e){if(!e.has(t.LifecycleService)){Ie(e);return}let n=e.get(t.LifecycleService);if(n.stage>=t.LifecycleStages.Ready){Ie(e);return}n.onStage(t.LifecycleStages.Ready).then(()=>{Ie(e)})}let Re=`sheet.menu.image`;function ze(e){return{id:Re,type:l.MenuItemType.SUBITEMS,icon:`AddImageIcon`,tooltip:`sheets-drawing-ui.title`,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,c.getCurrentRangeDisable$)(e,{workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission],rangeTypes:[s.RangeProtectionPermissionEditPoint]})}}function Be(e){return{id:M.id,title:`sheets-drawing-ui.upload.float`,type:l.MenuItemType.BUTTON,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}}function Ve(e){return{id:N.id,title:`sheets-drawing-ui.upload.cell`,type:l.MenuItemType.BUTTON,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}}function He(e,t){let n=e.getActiveSheet();if(!n)return!1;let r=n.getCellMatrix(),{startRow:i,endRow:a,startColumn:o,endColumn:c}=t;for(let e=i;e<=a;e++)for(let t=o;t<=c;t++){let n=r.getValue(e,t);if((0,s.isCellImage)(n==null?void 0:n.p))return!0}return!1}function Ue(){return`showDirectoryPicker`in window}function We(e){let n=e.get(t.IUniverInstanceService),r=e.get(s.SheetsSelectionsService),i=(0,d.combineLatest)([(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),n.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,d.switchMap)(e=>e?r.selectionMoveEnd$.pipe((0,d.map)(()=>{if(!Ue())return!0;let t=r.getCurrentSelections();if(!t||t.length===0)return!0;for(let n of t)if(He(e,n.range))return!1;return!0})):(0,d.of)(!0)))]).pipe((0,d.map)(([e,t])=>e||t));return{id:G.id,type:l.MenuItemType.BUTTON,icon:`DownloadImageIcon`,title:`sheets-drawing-ui.save.menuLabel`,hidden$:i}}let Ge={[l.RibbonInsertGroup.MEDIA]:{[Re]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,showLabel:!0},menuItemFactory:ze,[M.id]:{order:0,menuItemFactory:Be},[N.id]:{order:1,menuItemFactory:Ve}}},[l.ContextMenuPosition.MAIN_AREA]:{[l.ContextMenuGroup.OTHERS]:{[G.id]:{order:10,menuItemFactory:We}}},[l.ContextMenuPosition.COL_HEADER]:{[l.ContextMenuGroup.OTHERS]:{[G.id]:{order:10,menuItemFactory:We}}},[l.ContextMenuPosition.ROW_HEADER]:{[l.ContextMenuGroup.OTHERS]:{[G.id]:{order:10,menuItemFactory:We}}}};var Ke=`@univerjs/sheets-drawing-ui`,qe=`1.0.0-beta.2`;let Je={};function Ye(){let e=(0,l.useDependency)(t.LocaleService),n=(0,l.useDependency)(l.IDialogService),r=(0,l.useDependency)(I),[a,o]=(0,p.useState)([`cellAddress`]),[s,u]=(0,p.useState)(!1),[d,f]=(0,p.useState)(null),h=(0,p.useMemo)(()=>r.getCellImagesInSelection(),[r]),g=(0,p.useMemo)(()=>r.getDataColumns(),[r]),_=(0,p.useMemo)(()=>r.getSelectionRowRange(),[r]),v=g.length>0,y=(0,p.useMemo)(()=>g.map(e=>({label:e.label,value:String(e.index)})),[g]),[b,x]=(0,p.useState)(()=>y.length>0?y[0].value:`0`);(0,c.useHighlightRange)((0,p.useMemo)(()=>{if(!a.includes(`columnValue`)||!_)return[];let e=Number(b);return[{startRow:_.startRow,endRow:_.endRow,startColumn:e,endColumn:e}]},[a,b,_]));let S=(0,p.useCallback)(e=>{e.length!==0&&o(e)},[]),C=(0,p.useCallback)(e=>{x(String(e))},[]),w=(0,p.useCallback)(()=>{n.close(W)},[n]),T=(0,p.useCallback)(async()=>{if(h.length!==0){u(!0),f(null);try{await r.saveImages(h,{fileNameParts:a,columnIndex:a.includes(`columnValue`)?Number(b):void 0}),n.close(W)}catch(t){console.error(`Failed to save images:`,t),f(e.t(`sheets-drawing-ui.save.error`))}finally{u(!1)}}},[r,h,a,b,n,e]),E=a.includes(`columnValue`);return(0,m.jsxs)(`div`,{className:`univer-flex univer-flex-col`,children:[(0,m.jsx)(i.FormLayout,{label:e.t(`sheets-drawing-ui.save.imageCount`),children:(0,m.jsx)(`div`,{className:`univer-text-sm univer-text-gray-600`,children:h.length})}),(0,m.jsx)(i.FormLayout,{label:e.t(`sheets-drawing-ui.save.fileNameConfig`),children:(0,m.jsxs)(i.CheckboxGroup,{value:a,onChange:S,direction:`vertical`,children:[(0,m.jsx)(i.Checkbox,{value:`cellAddress`,disabled:!v,children:e.t(`sheets-drawing-ui.save.useRowCol`)}),v&&(0,m.jsx)(i.Checkbox,{value:`columnValue`,children:e.t(`sheets-drawing-ui.save.useColumnValue`)})]})}),E&&(0,m.jsx)(i.FormLayout,{label:e.t(`sheets-drawing-ui.save.selectColumn`),children:(0,m.jsx)(i.Select,{value:b,options:y,onChange:C})}),d&&(0,m.jsx)(`div`,{className:`univer-text-xs univer-text-red-500`,children:d}),(0,m.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-2 univer-border-t univer-border-gray-200 univer-pt-3`,children:[(0,m.jsx)(i.Button,{onClick:w,disabled:s,children:e.t(`sheets-drawing-ui.save.cancel`)}),(0,m.jsx)(i.Button,{variant:`primary`,onClick:T,disabled:s||h.length===0,children:s?e.t(`sheets-drawing-ui.save.saving`):e.t(`sheets-drawing-ui.save.confirm`)})]})]})}let Xe=e=>{let a=(0,l.useDependency)(t.ICommandService),s=(0,l.useDependency)(t.LocaleService),c=(0,l.useDependency)(o.IDrawingManagerService),u=(0,l.useDependency)(r.IRenderManagerService),{drawings:d}=e,f=Ze(d[0])?d[0]:void 0,h=f?u.getRenderUnitById(f.unitId):void 0,g=h==null?void 0:h.scene,_=g==null?void 0:g.getTransformerByCreate(),[v,y]=(0,p.useState)(!0),[b,x]=(0,p.useState)(f?(0,n.getSheetDrawingPlacement)(f).kind:n.SheetDrawingAnchorType.Position);function S(e,t){let n=[];return e.forEach(e=>{let{oKey:r}=e,i=t.getDrawingOKey(r);if(i==null||!Ze(i))return n.push(null),!0;let{unitId:a,subUnitId:o,drawingId:s,drawingType:c,anchorType:l,sheetTransform:u,axisAlignSheetTransform:d}=i;n.push({unitId:a,subUnitId:o,drawingId:s,anchorType:l,sheetTransform:u,drawingType:c,axisAlignSheetTransform:d})}),n}if((0,p.useEffect)(()=>{if(!_)return;let e=_.clearControl$.subscribe(e=>{e===!0&&y(!1)}),t=_.changeStart$.subscribe(e=>{let{objects:t}=e,r=S(t,c);if(r.length===0)y(!1);else if(r.length>=1){y(!0);let e=r[0];x(e?(0,n.getSheetDrawingPlacement)(e).kind:n.SheetDrawingAnchorType.Position)}});return()=>{t.unsubscribe(),e.unsubscribe()}},[c,_]),!f||!_)return null;function C(e){let t=Qe(e);if(!t)return;let r=c.getFocusDrawings();if(!r.length||!r.every(Ze))return;let{unitId:i,subUnitId:o}=r[0],s=[];for(let e of r){let{transform:n}=e,{left:r,top:i,width:a,height:o}=n??{};if(typeof r!=`number`||typeof i!=`number`||typeof a!=`number`||typeof o!=`number`||!Number.isFinite(r)||!Number.isFinite(i)||!Number.isFinite(a)||!Number.isFinite(o))return;s.push({drawingId:e.drawingId,placement:{kind:t,bounds:{left:r,top:i,width:a,height:o}}})}a.syncExecuteCommand(n.SetSheetDrawingPlacementCommand.id,{unitId:i,subUnitId:o,drawings:s})&&x(t)}return(0,m.jsxs)(`div`,{className:(0,i.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!v}),children:[(0,m.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,m.jsx)(`div`,{children:s.t(`sheets-drawing-ui.drawing-anchor.title`)})}),(0,m.jsx)(`div`,{children:(0,m.jsxs)(i.RadioGroup,{value:b,onChange:C,direction:`vertical`,children:[(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.Both,children:s.t(`sheets-drawing-ui.drawing-anchor.both`)}),(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.Position,children:s.t(`sheets-drawing-ui.drawing-anchor.position`)}),(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.None,children:s.t(`sheets-drawing-ui.drawing-anchor.none`)})]})})]})};function Ze(e){return!!(e&&`sheetTransform`in e&&`axisAlignSheetTransform`in e)}function Qe(e){return e===n.SheetDrawingAnchorType.Position||e===n.SheetDrawingAnchorType.Both||e===n.SheetDrawingAnchorType.None?e:null}let $e=()=>{let e=(0,l.useDependency)(o.IDrawingManagerService),t=(0,l.useObservable)(()=>e.focus$,e.getFocusDrawings(),!1,[e]);return!!(t!=null&&t.length)&&(0,m.jsxs)(`div`,{className:`univer-text-sm`,children:[(0,m.jsx)(u.DrawingCommonPanel,{drawings:t}),(0,m.jsx)(Xe,{drawings:t})]})},et=class extends t.Disposable{constructor(e){super(),this._componentManager=e,this._registerComponents()}_registerComponents(){this.disposeWithMe(this._componentManager.register(K,$e)),this.disposeWithMe(this._componentManager.register(W,Ye))}};et=O([D(0,(0,t.Inject)(l.ComponentManager))],et);let tt=(0,t.createIdentifier)(`sheets-drawing-ui.drawing-context-menu.service`);var nt=class extends t.Disposable{constructor(...e){super(...e),E(this,`_providers`,new Map)}registerProvider(e,n){return this._providers.set(e,n),(0,t.toDisposable)(()=>{this._providers.get(e)===n&&this._providers.delete(e)})}getContextMenuPosition(e){var t;return(t=this._providers.get(e.drawingType))==null?void 0:t.getContextMenuPosition(e)}};let rt=class extends t.RxDisposable{constructor(e,t,n,r,i){super(),this._drawingManagerService=e,this._contextMenuService=t,this._renderManagerService=n,this._univerInstanceService=r,this._drawingContextMenuService=i,this._init()}_init(){this._univerInstanceService.getAllUnitsForType(t.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._contextMenuListener(e))}_contextMenuListener(e){var t;if(!e)return;let n=(t=this._renderManagerService.getRenderUnitById(e.getUnitId()))==null?void 0:t.scene;if(!n)return;let r=n.getTransformerByCreate();r&&this.disposeWithMe(r.changeEnd$.subscribe(e=>{let{event:t}=e;if(t.button!==2)return;let n=r.getSelectedObjectMap();if(n.size===0)return;let i=[];for(let e of n.values()){let t=e.oKey,n=this._drawingManagerService.getDrawingOKey(t);if(!n)return;i.push(n)}this._contextMenuService.triggerContextMenu(t,this._getContextMenuPosition(i))}))}_getContextMenuPosition(e){if(e.length!==1)return l.ContextMenuPosition.DRAWING;let[t]=e;return this._drawingContextMenuService.getContextMenuPosition({unitId:t.unitId,subUnitId:t.subUnitId,drawingId:t.drawingId,drawingType:t.drawingType,drawing:t})??l.ContextMenuPosition.DRAWING}};rt=O([D(0,o.IDrawingManagerService),D(1,l.IContextMenuService),D(2,r.IRenderManagerService),D(3,t.IUniverInstanceService),D(4,tt)],rt);let it=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._context=e,this._hoverManagerService=t,this._selectionsService=n,this._drawingRenderService=r,this._sheetSkeletonManagerService=i,E(this,`_isSetCursor`,!1),this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe((0,d.throttleTime)(33)).subscribe(e=>{let t=[];if(e!==null&&(t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),(e==null?void 0:e.unitId)===this._context.unitId&&e!=null&&e.drawing&&t.length===1&&t[0].primary){let{row:n,col:i}=e,{actualRow:a,actualColumn:o,startRow:s,startColumn:c,endRow:l,endColumn:u,isMerged:d,isMergedMainCell:f}=t[0].primary;(d||f)&&n>=s&&n<=l&&i>=c&&i<=u||n===a&&i===o?(this._isSetCursor=!0,this._context.scene.setCursor(r.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}else this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(e=>{if(e!=null&&e.drawing&&this._isSetCursor){let t=e.drawing.drawing.drawingOrigin;this._previewImage(t)}}));let e=this._hoverManagerService.currentDbClickedCell$;e&&this.disposeWithMe(e.subscribe(({location:e})=>{var t,n,r;if(e.unitId!==this._context.unitId)return;let i=this._context.unit.getSheetBySheetId(e.subUnitId),a=i==null||(t=i.getCellRaw(e.row,e.col))==null?void 0:t.p,o=a==null||(n=a.drawingsOrder)==null?void 0:n[0],c=(0,s.isCellImage)(a)&&o?(r=a.drawings)==null?void 0:r[o]:void 0;c&&this._previewImage(c)}))}_previewImage(e){var t;if(this._disposed)return;let n=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap,r=n==null?void 0:n.getImage(e.imageSourceType,e.source,()=>this._previewImage(e));r&&(this._drawingRenderService.previewImage(`preview-cell-image`,r.src,r.width,r.height),this._context.scene.resetCursor(),this._isSetCursor=!1)}};it=O([D(1,(0,t.Inject)(c.HoverManagerService)),D(2,(0,t.Inject)(s.SheetsSelectionsService)),D(3,(0,t.Inject)(u.DrawingRenderService)),D(4,(0,t.Inject)(c.SheetSkeletonManagerService))],it);let at=class extends t.Disposable{constructor(e,t,n,r){super(),this._context=e,this._sheetDrawingService=t,this._drawingManagerService=n,this._sheetSkeletonService=r,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);let e=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(let r in e){let i=e[r];for(let e in i.data){let r=i.data[e],{unitId:a,subUnitId:o}=r,s=this._sheetSkeletonService.getSkeletonParam(a,o);if(s&&r.sheetTransform&&!r.groupId){let e=(0,n.drawingPositionToTransform)(r.sheetTransform,s);r.transform=e&&r.drawingType===t.DrawingTypeEnum.DRAWING_GROUP?{...e,left:(e.left??0)-s.skeleton.rowHeaderWidthAndMarginLeft,top:(e.top??0)-s.skeleton.columnHeaderHeightAndMarginTop}:e}}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};at=O([D(1,n.ISheetDrawingService),D(2,o.IDrawingManagerService),D(3,(0,t.Inject)(s.SheetSkeletonService))],at);function ot(e,t,n){var r,i;let a=n==null?void 0:n.p,o=(0,s.isCellImage)(a)&&(a==null||(r=a.drawingsOrder)==null?void 0:r.length)===1?a.drawingsOrder[0]:void 0,c=o?a==null||(i=a.drawings)==null?void 0:i[o]:void 0;if(c&&a){let n=A(e,{unitId:t.unitId,subUnitId:t.subUnitId,row:t.row,col:t.col},c.docTransform.size.width,c.docTransform.size.height,c.docTransform.angle);if(n)return c.transform.width=n.width,c.transform.height=n.height,c.docTransform.size.width=n.width,c.docTransform.size.height=n.height,c.transform.left=0,c.transform.top=0,c.docTransform.positionH.posOffset=0,c.docTransform.positionV.posOffset=0,a.documentStyle.pageSize.width=1/0,a.documentStyle.pageSize.height=1/0,!0}return!1}let st=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._sheetInterceptorService=e,this._injector=t,this._drawingManagerService=n,this._docDrawingController=r,this._editorBridgeService=i,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible?e.visible&&(this._drawingManagerService.removeDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(s.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,priority:s.InterceptCellContentPriority.CELL_IMAGE,handler:(e,t,n)=>(e&&(0,s.isCellImage)(e.p)&&(e===t.rawData&&(e={...t.rawData}),e.interceptorStyle||={},e.interceptorStyle.tr={a:0},ot(this._injector,{unitId:t.unitId,subUnitId:t.subUnitId,row:t.row,col:t.col},e)),n(e))}))}};st=O([D(0,(0,t.Inject)(s.SheetInterceptorService)),D(1,(0,t.Inject)(t.Injector)),D(2,o.IDrawingManagerService),D(3,(0,t.Inject)(f.DocDrawingController)),D(4,(0,t.Inject)(c.IEditorBridgeService))],st);let ct=class extends t.Disposable{constructor(e,t){super(),this._autoFillService=e,this._injector=t,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:`sheet-cell-image-autofill`,onBeforeSubmit:(e,n,r,i)=>{new t.ObjectMatrix(i).forValue((t,n,r)=>{ot(this._injector,{unitId:e.unitId,subUnitId:e.subUnitId,row:t,col:n},r)})}}))}};ct=O([D(0,(0,t.Inject)(s.IAutoFillService)),D(1,(0,t.Inject)(t.Injector))],ct);let lt=[t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,t.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY],ut=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._commandService=e,this._univerInstanceService=t,this._dialogService=n,this._renderManagerService=r,this._localeService=i,this._initDocImageCopyPasteHooks()}_setCellImage(e){var n;let i=(0,t.createDocumentModelWithStyle)(``,{}),a=(n=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(c.EditingRenderController),o=t.BuildTextUtils.drawing.add({documentDataModel:i,drawings:[e],selection:{collapsed:!0,startOffset:0,endOffset:0}});o&&(i.apply(o),a&&a.submitCellData(i))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===h.InnerPasteCommand.id){let{doc:r}=e.params,i=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(i==null||!Object.keys(r.drawings??{}).length)return;let a=i.getUnitId();if(lt.includes(a)){var n;let e=()=>{this._dialogService.close(`sheet-cell-image-copy-paste`),this._commandService.syncExecuteCommand(c.SetCellEditVisibleOperation.id,{visible:!1})};((n=i.getBody())==null?void 0:n.dataStream)===`\r
2
2
  `?(this._commandService.syncExecuteCommand(c.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(r.drawings)[0])):this._dialogService.open({id:`sheet-cell-image-copy-paste`,title:{label:this._localeService.t(`sheets-drawing-ui.cell-image.pasteTitle`)},children:{label:this._localeService.t(`sheets-drawing-ui.cell-image.pasteContent`)},width:320,onClose:e,showOk:!0,showCancel:!0,onOk:()=>{e(),this._setCellImage(Object.values(r.drawings)[0])},onCancel:e})}}}))}};ut=O([D(0,t.ICommandService),D(1,t.IUniverInstanceService),D(2,l.IDialogService),D(3,r.IRenderManagerService),D(4,(0,t.Inject)(t.LocaleService))],ut);let dt=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._context=e,this._commandService=t,this._sheetSkeletonService=n,this._sheetDrawingService=r,this._drawingManagerService=i,this._commandListener()}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===s.SetWorksheetActiveOperation.id){let{unitId:t,subUnitId:n}=e.params;this._updateDrawings(t,n)}})),this.disposeWithMe(this._context.activated$.subscribe(e=>{let{unit:t,unitId:n}=this._context;e?this._updateDrawings(n,t.getActiveSheet().getSheetId()):this._clearDrawings(n)}))}_clearDrawings(e){setTimeout(()=>{let t=this._drawingManagerService.drawingManagerData,n=[];Object.keys(t??{}).forEach(r=>{let i=t[r]??{};Object.keys(i).forEach(t=>{var a;let o=((a=i[t])==null?void 0:a.data)??{};Object.keys(o).forEach(t=>{r===e&&n.push(o[t])})})}),this._sheetDrawingService.removeNotification(n),this._drawingManagerService.removeNotification(n)})}_updateDrawings(e,t){setTimeout(()=>{let r=this._sheetSkeletonService.getSkeletonParam(e,t),i=this._drawingManagerService.drawingManagerData,a=[],o=[];Object.keys(i??{}).forEach(s=>{if(s!==e)return;let c=i[s]??{};Object.keys(c).forEach(i=>{var l;let u=((l=c[i])==null?void 0:l.data)??{};Object.keys(u).forEach(c=>{if(s===e&&i===t){let e=u[c];e.sheetTransform&&(e.transform=(0,n.drawingPositionToTransform)(e.sheetTransform,r)),a.push(u[c])}else o.push(u[c])})})}),this._sheetDrawingService.removeNotification(o),this._sheetDrawingService.addNotification(a),this._drawingManagerService.removeNotification(o),this._drawingManagerService.addNotification(a)},0)}};dt=O([D(1,t.ICommandService),D(2,(0,t.Inject)(s.SheetSkeletonService)),D(3,n.ISheetDrawingService),D(4,o.IDrawingManagerService)],dt);let ft=`image/png`;function pt(e){let t=e.split(`,`),n=atob(t[1]),r=n.length,i=new Uint8Array(r);for(let e=0;e<r;e++)i[e]=n.charCodeAt(e);return new Blob([i],{type:ft})}function mt(e){let t=new ClipboardItem({[ft]:pt(e)});navigator.clipboard.write([t]).catch(e=>{console.error(`Could not copy image using clipboard API: `,e)})}function ht(){function e(){let e=document.createElement(`input`);return e.style.position=`absolute`,e.style.height=`1px`,e.style.width=`1px`,e.style.opacity=`0`,e}let t=document.activeElement,n=e();return document.body.appendChild(n),n.focus(),()=>{n.blur(),document.body.removeChild(n),t instanceof HTMLElement&&t.focus()}}let gt=[c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA],_t=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetClipboardService=e,this._renderManagerService=t,this._sheetSkeletonService=n,this._drawingService=r,this._clipboardInterfaceService=i,this._commandService=a,E(this,`_copyInfo`,void 0),this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:`SHEET_IMAGE_UI_PLUGIN`,onBeforeCopy:(e,r,i,a)=>{this._copyInfo=null;let o=this._focusedDrawings;if(o.length>0){let[r]=o;if(r.drawingType!==t.DrawingTypeEnum.DRAWING_IMAGE)return;if(a===c.COPY_TYPE.CUT){let t={unitId:e,drawings:[r]};this._commandService.executeCommand(n.RemoveSheetDrawingCommand.id,t)}setTimeout(()=>{let e=ht();r.drawingType===t.DrawingTypeEnum.DRAWING_IMAGE&&r.imageSourceType===t.ImageSourceType.BASE64?mt(r.source):this._clipboardInterfaceService.writeText(``),e()},200);let i={unitId:r.unitId,subUnitId:r.subUnitId,drawings:[r]};this._copyInfo=i}else{let t=this._createDrawingsCopyInfoByRange(e,r,i);this._copyInfo=t}},onPasteCells:(e,t,n,r)=>{if(!this._copyInfo)return{redos:[],undos:[]};let{copyType:i=c.COPY_TYPE.COPY,pasteType:a}=r,{range:o,unitId:s,subUnitId:l}=e||{},{range:u,unitId:d,subUnitId:f}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({unitId:d,subUnitId:f,pasteRange:u,pasteType:a},{unitId:s,subUnitId:l,copyType:i,copyRange:o}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:a},c.COPY_TYPE.COPY)},onPastePlainText:(e,t)=>({undos:[],redos:[]}),onPasteUnrecognized:e=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:e,pasteType:c.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},c.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(e,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:e,pasteType:c.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},c.COPY_TYPE.COPY);{let e=t.filter(e=>e.type.includes(`image`));if(e.length)return{undos:[],redos:[{id:M.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(e,r,i){let a=this._sheetSkeletonService.getSkeleton(e,r);if(!a)return;let o=(0,s.attachRangeWithCoord)(a,i);if(!o)return;let{startX:c,endX:l,startY:u,endY:d}=o,f=this._drawingService.getDrawingData(e,r),p=this._focusedDrawings.slice();if(Object.keys(f).forEach(e=>{let r=f[e];if(r.drawingType!==t.DrawingTypeEnum.DRAWING_IMAGE)return;let{transform:i}=r;if(r.anchorType!==n.SheetDrawingAnchorType.Both||!i)return;let{left:a=0,top:o=0,width:s=0,height:m=0}=i,{drawingStartX:h,drawingEndX:g,drawingStartY:_,drawingEndY:v}={drawingStartX:a,drawingEndX:a+s,drawingStartY:o,drawingEndY:o+m};c<=h&&g<=l&&u<=_&&v<=d&&p.push(r)}),p.length)return{copyRange:i,drawings:p,unitId:e,subUnitId:r}}_generateSingleDrawingPasteMutations(e,t){let{pasteType:r,pasteTo:i}=e;if(gt.includes(r))return{redos:[],undos:[]};let{unitId:a,subUnitId:o,range:l}=i,u=this._sheetSkeletonService.getSkeleton(a,o);if(!u)return{redos:[],undos:[]};let{drawings:d}=this._copyInfo,f=(0,s.discreteRangeToRange)(l);return this._generateMutations(d,{unitId:a,subUnitId:o,isCut:t===c.COPY_TYPE.CUT,getTransform:(e,t)=>{let r=(0,s.attachRangeWithCoord)(u,{startRow:f.startRow,endRow:f.endRow,startColumn:f.startColumn,endColumn:f.endColumn}),i={...e,left:r==null?void 0:r.startX,top:r==null?void 0:r.startY};return{transform:i,sheetTransform:(0,n.transformToDrawingPosition)(i,u)??t,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(i,u)??t}}})}_generateMutations(e,r){let{unitId:i,subUnitId:a,getTransform:o,isCut:s}=r,c=[],l=[],{_drawingService:u}=this;return e.forEach(e=>{let{transform:r,sheetTransform:d}=e;if(!r)return;let f=o(r,d),p={...e,unitId:i,subUnitId:a,drawingId:s?e.drawingId:(0,t.generateRandomId)(),transform:f.transform,sheetTransform:f.sheetTransform,axisAlignSheetTransform:f.axisAlignSheetTransform};if(s){let{undo:e,redo:t,objects:r}=u.getBatchUpdateOp([p]);c.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,type:n.DrawingApplyType.UPDATE,op:t,objects:r}}),l.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,type:n.DrawingApplyType.UPDATE,op:e,objects:r}})}else{let{undo:e,redo:t,objects:r}=u.getBatchAddOp([p]);c.push({id:n.SetDrawingApplyMutation.id,params:{op:t,unitId:i,subUnitId:a,objects:r,type:n.DrawingApplyType.INSERT}}),l.push({id:n.SetDrawingApplyMutation.id,params:{op:e,unitId:i,subUnitId:a,objects:r,type:n.DrawingApplyType.REMOVE}})}}),{redos:c,undos:l}}_generateRangeDrawingsPasteMutations(e,t){if(!this._copyInfo)return{redos:[],undos:[]};let{unitId:r,subUnitId:i,pasteRange:a,pasteType:o}=e,{unitId:l,subUnitId:u,copyRange:d,copyType:f}=t;if(gt.includes(o))return{redos:[],undos:[]};let p=this._sheetSkeletonService.getSkeleton(r,i);if(!p)return{redos:[],undos:[]};let{drawings:m}=this._copyInfo;if(!d)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:r,subUnitId:i,range:(0,s.discreteRangeToRange)(a)},pasteType:o},f);let h=this._sheetSkeletonService.getSkeleton(l,u);if(!h)return{redos:[],undos:[]};let{ranges:[g,_],mapFunc:v}=(0,c.virtualizeDiscreteRanges)([d,a]),{row:y,col:b}=v(g.startRow,g.startColumn),{row:x,col:S}=v(_.startRow,_.startColumn),C=(0,s.attachRangeWithCoord)(h,{startRow:y,endRow:y,startColumn:b,endColumn:b}),w=(0,s.attachRangeWithCoord)(p,{startRow:x,endRow:x,startColumn:S,endColumn:S});if(!C||!w)return{redos:[],undos:[]};let T=w.startX-C.startX,E=w.startY-C.startY,D=x-y,O=S-b;return this._generateMutations(m,{unitId:r,subUnitId:i,getTransform:(e,t)=>{let r={...e,left:((e==null?void 0:e.left)??0)+T,top:((e==null?void 0:e.top)??0)+E};return{transform:r,sheetTransform:{...t,to:{...t.to,row:t.to.row+D,column:t.to.column+O},from:{...t.from,row:t.from.row+D,column:t.from.column+O}},axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(r,p)??t}},isCut:f===c.COPY_TYPE.CUT})}};_t=O([D(0,c.ISheetClipboardService),D(1,r.IRenderManagerService),D(2,(0,t.Inject)(s.SheetSkeletonService)),D(3,o.IDrawingManagerService),D(4,l.IClipboardInterfaceService),D(5,t.ICommandService)],_t);let vt=[r.ObjectType.IMAGE,r.ObjectType.SHAPE,r.ObjectType.CHART,r.ObjectType.DRAWING_DOM],yt=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._commandService=e,this._localeService=t,this._renderManagerService=n,this._permissionService=r,this._univerInstanceService=i,this._userManagerService=a,this._sheetPermissionCheckController=o,this._sheetDrawingService=s,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange(),this._initCommandPermissionCheck()}_initDrawingVisible(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$,r=(0,d.combineLatest)([e,n]);this.disposeWithMe(r.pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.tap)(t=>{if(!t){this._sheetDrawingService.setDrawingVisible(!1);return}let n=e.getUnitId(),r=t.getSheetId();this._permissionService.composePermission([new s.WorkbookViewPermission(n).id,new s.WorksheetViewPermission(n,r).id]).every(e=>e.value)?this._sheetDrawingService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,t)})):(this._sheetDrawingService.setDrawingVisible(!1),d.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(e,t){this._sheetDrawingService.setDrawingVisible(!1);let n=e.getUnitId(),r=t.getSheetId(),i=this._sheetDrawingService.getDrawingData(n,r),a=Object.values(i),o=this._renderManagerService.getRenderUnitById(n),s=o==null?void 0:o.scene;s&&s.getAllObjectsByOrder().forEach(e=>{vt.includes(e.objectType)&&a.some(t=>e.oKey.includes(t.drawingId))&&s.removeObject(e)})}_initDrawingEditable(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$,r=(0,d.combineLatest)([e,n]);this.disposeWithMe(r.pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.tap)(t=>{if(!t){this._sheetDrawingService.setDrawingEditable(!1);return}let n=e.getUnitId(),r=t.getSheetId();this._permissionService.composePermission([new s.WorkbookEditablePermission(n).id,new s.WorksheetEditPermission(n,r).id]).every(e=>e.value)?this._sheetDrawingService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,t)})):(this._sheetDrawingService.setDrawingEditable(!1),d.EMPTY))).subscribe())}_handleDrawingEditableFalse(e,t){this._sheetDrawingService.setDrawingEditable(!1);let n=e.getUnitId(),r=t.getSheetId(),i=this._sheetDrawingService.getDrawingData(n,r),a=Object.values(i),o=this._renderManagerService.getRenderUnitById(n),s=o==null?void 0:o.scene;s&&s.getAllObjectsByOrder().forEach(e=>{vt.includes(e.objectType)&&a.some(t=>e.oKey.includes(t.drawingId))&&s.detachTransformerFrom(e)})}_initViewPermissionChange(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$;this.disposeWithMe((0,d.combineLatest)([e,n]).pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.switchMap)(t=>{if(!t)return d.EMPTY;let n=e.getUnitId(),r=t.getSheetId(),i=this._renderManagerService.getRenderUnitById(n),a=i==null?void 0:i.scene;if(!a)return d.EMPTY;let o=a.getTransformerByCreate();return this._permissionService.composePermission$([new s.WorkbookViewPermission(n).id,new s.WorksheetViewPermission(n,r).id]).pipe((0,d.map)(e=>e.every(e=>e.value)),(0,d.distinctUntilChanged)()).pipe((0,d.map)(e=>({permission:e,scene:a,transformer:o,unitId:n,subUnitId:r})))})):d.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:r,subUnitId:i})=>{this._sheetDrawingService.setDrawingVisible(e);let a=t.getAllObjectsByOrder(),o=this._sheetDrawingService.getDrawingData(r,i),s=Object.values(o);e?this._sheetDrawingService.addNotification(s):(a.forEach(e=>{vt.includes(e.objectType)&&s.some(t=>e.oKey.includes(t.drawingId))&&t.removeObject(e)}),n.clearSelectedObjects())},complete:()=>{this._sheetDrawingService.setDrawingVisible(!0);let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),n=e==null?void 0:e.getActiveSheet(),r=e==null?void 0:e.getUnitId(),i=n==null?void 0:n.getSheetId();if(!r||!i)return;let a=this._sheetDrawingService.getDrawingData(r,i),o=Object.values(a);this._sheetDrawingService.addNotification(o)}}))}_initEditPermissionChange(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$;this.disposeWithMe((0,d.combineLatest)([e,n]).pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.switchMap)(t=>{if(!t)return d.EMPTY;let n=e.getUnitId(),r=t.getSheetId(),i=this._renderManagerService.getRenderUnitById(n),a=i==null?void 0:i.scene;if(!a)return d.EMPTY;let o=a.getTransformerByCreate();return this._permissionService.composePermission$([new s.WorkbookEditablePermission(n).id,new s.WorksheetEditPermission(n,r).id]).pipe((0,d.map)(e=>e.every(e=>e.value)),(0,d.distinctUntilChanged)()).pipe((0,d.map)(e=>({permission:e,scene:a,transformer:o,unitId:n,subUnitId:r})))})):d.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:r,subUnitId:i})=>{this._sheetDrawingService.setDrawingEditable(e);let a=t.getAllObjectsByOrder(),o=this._sheetDrawingService.getDrawingData(r,i),s=Object.values(o);e?(a.forEach(e=>{vt.includes(e.objectType)&&s.some(t=>e.oKey.includes(t.drawingId))&&t.attachTransformerTo(e)}),this._sheetDrawingService.addNotification(s)):(a.forEach(e=>{vt.includes(e.objectType)&&s.some(t=>e.oKey.includes(t.drawingId))&&t.detachTransformerFrom(e)}),n.clearSelectedObjects())},complete:()=>{let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return;let n=e.getUnitId(),r=e.getActiveSheet();if(!r)return;let i=r.getSheetId(),a=this._renderManagerService.getRenderUnitById(n),o=a==null?void 0:a.scene;if(!o)return;let s=this._sheetDrawingService.getDrawingData(n,i),c=Object.values(s);this._sheetDrawingService.setDrawingEditable(!0),o.getAllObjectsByOrder().forEach(e=>{vt.includes(e.objectType)&&c.some(t=>e.oKey.includes(t.drawingId))&&o.detachTransformerFrom(e)})}}))}_initCommandPermissionCheck(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{let t,r;if(e.id===n.InsertSheetDrawingCommand.id||e.id===n.RemoveSheetDrawingCommand.id||e.id===n.SetSheetDrawingCommand.id){var i,a;let{drawings:n}=e.params;t=n==null||(i=n[0])==null?void 0:i.unitId,r=n==null||(a=n[0])==null?void 0:a.subUnitId}else if(e.id===n.SetSheetDrawingPlacementCommand.id){let n=bt(e.params);t=n.unitId,r=n.subUnitId}else if(e.id===n.SetDrawingArrangeCommand.id){let n=e.params;t=n.unitId,r=n.subUnitId}!t||!r||this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission]},t,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`sheets-drawing-ui.permission.dialog.editErr`))}))}};yt=O([D(0,(0,t.Inject)(t.ICommandService)),D(1,(0,t.Inject)(t.LocaleService)),D(2,r.IRenderManagerService),D(3,t.IPermissionService),D(4,t.IUniverInstanceService),D(5,(0,t.Inject)(t.UserManagerService)),D(6,(0,t.Inject)(s.SheetPermissionCheckController)),D(7,(0,t.Inject)(n.ISheetDrawingService))],yt);function bt(e){return e?{unitId:`unitId`in e&&typeof e.unitId==`string`?e.unitId:void 0,subUnitId:`subUnitId`in e&&typeof e.subUnitId==`string`?e.subUnitId:void 0}:{}}function xt(e,t,n,r){let{width:i,height:a,angle:o,left:s,top:c}=e.transform,l=Ae({left:s??0,right:(s??0)+(i??0),top:c??0,bottom:(c??0)+(a??0)},t,n,r,void 0,!0),{scaleX:u,scaleY:f}=t.getAncestorScale(),p={startX:l.left,endX:l.right,startY:l.top,endY:l.bottom,rotate:o,width:i*u,height:a*f,absolute:l.absolute},m={position$:new d.BehaviorSubject(p),position:p,id:e.drawingId,componentKey:e.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:e.unitId,data:e.data,props:e.props};return[e.drawingId,m]}let St=e=>{let{floatDomInfos:t,scene:n,skeleton:r,worksheet:i}=e;return(0,m.jsx)(`div`,{style:{position:`absolute`,top:0,left:0},children:(0,p.useMemo)(()=>t.map(e=>xt(e,n,r,i)),[t,n,r,i]).map(([e,t])=>(0,m.jsx)(l.PrintFloatDomSingle,{layer:t,id:e,position:t.position},e))})};function Ct(e,t,n){return(0,i.render)((0,m.jsx)((0,l.connectInjector)(St,n),{...e}),t),()=>(0,i.unmount)(t)}let wt=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetPrintInterceptorService=e,this._drawingRenderService=t,this._drawingManagerService=n,this._renderManagerService=r,this._componetManager=i,this._injector=a,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(e,n,r)=>{let{unitId:i,scene:a,subUnitId:o,resourceCollector:s}=n,c=this._drawingManagerService.getDrawingDataForUnit(i),l=c==null?void 0:c[o];return l&&l.order.forEach(e=>{let n=l.data[e];if(!n.hidden&&n.drawingType!==t.DrawingTypeEnum.DRAWING_CHART&&n.drawingType!==t.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==t.DrawingTypeEnum.DRAWING_BLOCK){let e=this._drawingRenderService.renderDrawing(n,a,{allowInactiveSheet:!0});e&&s.add(Promise.resolve(e))}}),r()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(e,n,r)=>{let{unitId:i,subUnitId:a}=n,o=this._renderManagerService.getRenderUnitById(i);if(!o)return r(e);let s=o.with(c.SheetSkeletonManagerService).getSkeletonParam(a);if(!s)return r(e);let l=this._drawingManagerService.getDrawingDataForUnit(i),u=l==null?void 0:l[n.subUnitId];if(!u)return r(e);let{scaleX:d,scaleY:f}=o.scene,p=e?{...e}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=u.order.map(e=>u.data[e]);return m.length?(m.forEach(e=>{if(!e.hidden&&!e.groupId&&e.transform&&t.Tools.isDefine(e.transform.left)&&t.Tools.isDefine(e.transform.top)&&t.Tools.isDefine(e.transform.width)&&t.Tools.isDefine(e.transform.height)){let t=s.skeleton.getCellIndexByOffset(e.transform.left,e.transform.top,d,f,{x:0,y:0}),n=s.skeleton.getCellIndexByOffset(e.transform.left+e.transform.width,e.transform.top+e.transform.height,d,f,{x:0,y:0});t.column<p.startColumn&&(p.startColumn=t.column),t.row<p.startRow&&(p.startRow=t.row),p.endRow<n.row&&(p.endRow=n.row),p.endColumn<n.column&&(p.endColumn=n.column)}}),r(p)):r(e)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(e,n,r)=>{let{unitId:i,subUnitId:a}=n,o=this._drawingManagerService.getDrawingDataForUnit(i),s=o==null?void 0:o[a];if(s){let i=s.order.map(e=>{let n=s.data[e];if(n.hidden)return null;if(n.drawingType===t.DrawingTypeEnum.DRAWING_DOM||n.drawingType===t.DrawingTypeEnum.DRAWING_BLOCK){let e=this._sheetPrintInterceptorService.getPrintComponent(n.componentKey);return{...n,componentKey:this._componetManager.get(e||n.componentKey)}}return null}).filter(Boolean),a=document.createElement(`div`);a.style.position=`absolute`,a.style.inset=`0`,n.root.appendChild(a);let o=Ct({floatDomInfos:i,scene:n.scene,skeleton:n.skeleton,worksheet:n.worksheet},a,this._injector);return e==null||e.add(()=>{a.remove(),queueMicrotask(o)}),r(e)}return r(e)}}))}};wt=O([D(0,(0,t.Inject)(c.SheetPrintInterceptorService)),D(1,(0,t.Inject)(u.DrawingRenderService)),D(2,o.IDrawingManagerService),D(3,r.IRenderManagerService),D(4,(0,t.Inject)(l.ComponentManager)),D(5,(0,t.Inject)(t.Injector))],wt);let Tt={id:`sheet.command.toggle-flip-drawings`,type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),c=e.get(n.ISheetDrawingService),l=e.get(s.SheetSkeletonService),{drawings:u}=r,d=r.flipH,f=r.flipV,p=[],m=[];for(let r of u){let{unitId:i,subUnitId:a,drawingId:s}=r;p.push(i);let u=c.getDrawingData(i,a),h=u==null?void 0:u[s];if(!h)continue;let g=l.getSkeleton(i,a);if(!g)continue;let _={...h.transform};d&&(_.flipX=!_.flipX),f&&(_.flipY=!_.flipY);let v=(0,n.transformToDrawingPosition)(_,g),y=(0,n.transformToAxisAlignPosition)(_,g),b={unitId:i,subUnitId:a,drawingType:h.drawingType,drawingId:s,transform:_,sheetTransform:v,axisAlignSheetTransform:y};if(h.drawingType===t.DrawingTypeEnum.DRAWING_IMAGE){let t=Et(e,i);if(t){let e=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:s}),n=t.getObject(e);if(n){let e=n.srcRect;if(e){let t,{left:n=0,top:r=0,right:i=0,bottom:a=0}=e;if(d){let e=n+(i-n)/2;t={left:e-(i-n)/2,top:r,right:e+(i-n)/2,bottom:a}}if(f){let e=r+(a-r)/2;t={left:n,top:e-(a-r)/2,right:i,bottom:e+(a-r)/2}}t&&(b.srcRect=t)}}}}m.push(b)}if(m.length===0)return!1;let{unitId:h,subUnitId:g,undo:_,redo:v,objects:y}=c.getBatchUpdateOp(m),b={id:n.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:g,op:v,objects:y,type:n.DrawingApplyType.UPDATE}},x={id:n.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:g,op:_,objects:y,type:n.DrawingApplyType.UPDATE}};return(0,t.sequenceExecute)([b],i).result?(a.pushUndoRedo({unitID:h,undoMutations:[x,{id:n.ClearSheetDrawingTransformerOperation.id,params:p}],redoMutations:[b,{id:n.ClearSheetDrawingTransformerOperation.id,params:p}]}),!0):!1}};function Et(e,t){let n=e.get(r.IRenderManagerService).getRenderUnitById(t);return n?n.scene:null}function Dt(e){return e.getContextValue(t.FOCUSING_SHEET)&&!e.getContextValue(t.FOCUSING_FX_BAR_EDITOR)&&!e.getContextValue(t.FOCUSING_PANEL_EDITOR)&&e.getContextValue(t.FOCUSING_COMMON_DRAWINGS)&&!e.getContextValue(t.FOCUSING_SHAPE_TEXT_EDITOR)}let Ot={id:P.id,description:`sheets-drawing-ui.shortcut.drawing-move-down`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_DOWN,priority:100,preconditions:Dt,staticParameters:{direction:t.Direction.DOWN}},kt={id:P.id,description:`sheets-drawing-ui.shortcut.drawing-move-up`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_UP,priority:100,preconditions:Dt,staticParameters:{direction:t.Direction.UP}},At={id:P.id,description:`sheets-drawing-ui.shortcut.drawing-move-left`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_LEFT,priority:100,preconditions:Dt,staticParameters:{direction:t.Direction.LEFT}},jt={id:P.id,description:`sheets-drawing-ui.shortcut.drawing-move-right`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_RIGHT,priority:100,preconditions:Dt,staticParameters:{direction:t.Direction.RIGHT}},Mt={id:g.id,description:`sheets-drawing-ui.shortcut.drawing-delete`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,priority:100,preconditions:Dt,binding:l.KeyCode.DELETE,mac:l.KeyCode.BACKSPACE},Nt=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._menuManagerService=e,this._commandService=t,this._shortcutService=n,this._drawingManagerService=r,this._sidebarService=i,this._init()}_initCustomComponents(){}_initMenus(){this._menuManagerService.mergeMenu(Ge)}_initCommands(){[M,N,q,J,x,S,P,g,G,Tt].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initShortcuts(){[Ot,kt,At,jt,Mt].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_initImagePanel(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{!this._sidebarService.visible||this._sidebarService.options.id!==`COMPONENT_SHEET_DRAWING_PANEL`||(e.length!==1||e[0].drawingType!==t.DrawingTypeEnum.DRAWING_IMAGE)&&this._sidebarService.close(K)}))}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts(),this._initImagePanel()}};Nt=O([D(0,l.IMenuManagerService),D(1,t.ICommandService),D(2,l.IShortcutService),D(3,o.IDrawingManagerService),D(4,(0,t.Inject)(l.ISidebarService))],Nt);let Pt=class extends t.RxDisposable{constructor(e,t,n,r,i,a,o,s,c,l){super(),this._injector=e,this._localeService=t,this._drawingManagerService=n,this._canvasPopManagerService=r,this._renderManagerService=i,this._univerInstanceService=a,this._messageService=o,this._contextService=s,this._ioService=c,this._commandService=l,E(this,`_initImagePopupMenu`,new Set),this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).subscribe(e=>this._create(e)),this._univerInstanceService.getTypeOfUnitDisposed$(t.UniverInstanceType.UNIVER_SHEET).subscribe(e=>this._dispose(e)),this._univerInstanceService.getAllUnitsForType(t.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._create(e)),this._setupLoadingStatus()}_setupLoadingStatus(){let e;this.disposeWithMe(this._ioService.change$.subscribe(t=>{t>0&&!e?e=this._messageService.show({id:`image-upload-loading`,type:i.MessageType.Loading,content:`${this._localeService.t(`sheets-drawing-ui.uploadLoading.loading`)}: ${t}`,duration:0}):t===0&&(e==null||e.dispose(),e=void 0)}))}_dispose(e){super.dispose();let t=e.getUnitId();this._renderManagerService.removeRender(t),this._initImagePopupMenu.delete(t)}_create(e){if(!e)return;let t=e.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(e){let t=e.getAllObjectsByOrder();for(let e of t)if(e instanceof u.ImageCropperObject)return!0;return!1}_popupMenuListener(e){var n;let r=(n=this._renderManagerService.getRenderUnitById(e))==null?void 0:n.scene;if(!r)return;let i=r.getTransformerByCreate();if(!i)return;let a;this.disposeWithMe(i.createControl$.subscribe(()=>{if(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(r))return;let e=i.getSelectedObjectMap();if(e.size>1){a==null||a.dispose();return}let n=e.values().next().value;if(!n)return;let o=n.oKey,s=this._drawingManagerService.getDrawingOKey(o);if(!s||s.drawingType===t.DrawingTypeEnum.DRAWING_SHAPE)return;let{unitId:c,subUnitId:l,drawingId:d,drawingType:f}=s,p=s.data;if(p&&(p.disablePopup||p.version===1&&typeof p.embedId==`string`))return;a==null||a.dispose();let m=this._canvasPopManagerService.getFeatureMenu(c,l,d,f);a=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(n,{componentKey:u.COMPONENT_IMAGE_POPUP_MENU,constrainToCanvas:!0,direction:this._localeService.getDirection()===`rtl`?`left`:`horizontal`,offset:[2,0],extraProps:{menuItems:m||this._getImageMenuItems(c,l,d,f)}}))})),this.disposeWithMe(i.clearControl$.subscribe(()=>{a==null||a.dispose(),this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(e=>{e[t.FOCUSING_COMMON_DRAWINGS]===!1&&(a==null||a.dispose())})),this.disposeWithMe(i.changing$.subscribe(()=>{a==null||a.dispose()}))}_getImageMenuItems(e,r,i,a){return[{label:`sheets-drawing-ui.image-popup.edit`,index:0,commandId:J.id,commandParams:{unitId:e,subUnitId:r,drawingId:i},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.delete`,index:1,commandId:n.RemoveSheetDrawingCommand.id,commandParams:{unitId:e,drawings:[{unitId:e,subUnitId:r,drawingId:i}]},disable:!1},{label:`sheets-drawing-ui.image-popup.crop`,index:2,commandId:u.OpenImageCropOperation.id,commandParams:{unitId:e,subUnitId:r,drawingId:i},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.flipH`,index:2,commandId:Tt.id,commandParams:{unitId:e,flipH:!0,drawings:[{unitId:e,subUnitId:r,drawingId:i}]},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.flipV`,index:2,commandId:Tt.id,commandParams:{unitId:e,flipV:!0,drawings:[{unitId:e,subUnitId:r,drawingId:i}]},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.reset`,index:3,commandId:u.ImageResetSizeOperation.id,commandParams:[{unitId:e,subUnitId:r,drawingId:i}],disable:a===t.DrawingTypeEnum.DRAWING_DOM}]}};Pt=O([D(0,(0,t.Inject)(t.Injector)),D(1,(0,t.Inject)(t.LocaleService)),D(2,o.IDrawingManagerService),D(3,(0,t.Inject)(c.SheetCanvasPopManagerService)),D(4,r.IRenderManagerService),D(5,t.IUniverInstanceService),D(6,l.IMessageService),D(7,t.IContextService),D(8,t.IImageIoService),D(9,t.ICommandService)],Pt);let Ft=class extends t.Disposable{constructor(e,t,n){super(),this._drawingManagerService=e,this._univerInstanceService=t,this._renderManagerService=n,E(this,`_onDoubleClick$`,new d.Subject),E(this,`onDoubleClick$`,this._onDoubleClick$.asObservable()),E(this,`_doubleClickDisposable`,null),E(this,`_boundRender`,null),E(this,`_boundScene`,null),this._init()}dispose(){this._disposeDoubleClickListener(),this._onDoubleClick$.complete(),super.dispose()}hitTestCurrentSheet(e,t){let n=this._getActiveSheetContext();return n?this.hitTest(n.unitId,n.subUnitId,e,t):null}hitTest(e,t,n,r){var i;let a=(i=this._renderManagerService.getRenderUnitById(e))==null?void 0:i.scene;return a?this._hitTestScene(a,e,t,n,r):null}_init(){this.disposeWithMe((0,t.toDisposable)(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).subscribe(()=>{this._bindDoubleClickListener()}))),this.disposeWithMe((0,t.toDisposable)(this._renderManagerService.created$.subscribe(e=>{let t=this._getActiveSheetContext();e.unitId===(t==null?void 0:t.unitId)&&this._bindDoubleClickListener()}))),this.disposeWithMe((0,t.toDisposable)(this._renderManagerService.disposed$.subscribe(e=>{var t;e===((t=this._boundRender)==null?void 0:t.unitId)&&this._disposeDoubleClickListener()}))),this._bindDoubleClickListener()}_bindDoubleClickListener(){let e=this._getActiveSheetContext();if(!e){this._disposeDoubleClickListener();return}let t=this._renderManagerService.getRenderUnitById(e.unitId),n=t==null?void 0:t.scene;if(!t||!n){this._disposeDoubleClickListener();return}if(this._boundRender===t&&this._boundScene===n&&this._doubleClickDisposable)return;this._disposeDoubleClickListener();let r=n.onDblclick$.subscribeEvent(t=>{let r=this._getActiveSheetContext();if(!r||r.unitId!==e.unitId)return;let i=this._hitTestScene(n,r.unitId,r.subUnitId,t.offsetX,t.offsetY);i&&this._onDoubleClick$.next({...i,nativeEvent:t})});this._doubleClickDisposable={dispose:()=>r.unsubscribe()},this._boundRender=t,this._boundScene=n}_disposeDoubleClickListener(){var e;(e=this._doubleClickDisposable)==null||e.dispose(),this._doubleClickDisposable=null,this._boundRender=null,this._boundScene=null}_hitTestScene(e,t,n,i,a){let o=e.pick(r.Vector2.FromArray([i,a])),s=typeof(o==null?void 0:o.oKey)==`string`?o.oKey:null;if(!s)return null;let c=this._drawingManagerService.getDrawingOKey(s);return!c||c.unitId!==t||c.subUnitId!==n?null:{drawing:c,oKey:s,offsetX:i,offsetY:a}}_getActiveSheetContext(){var e;let n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),r=n==null?void 0:n.getUnitId(),i=n==null||(e=n.getActiveSheet())==null?void 0:e.getSheetId();return!r||!i?null:{unitId:r,subUnitId:i}}};Ft=O([D(0,o.IDrawingManagerService),D(1,t.IUniverInstanceService),D(2,r.IRenderManagerService)],Ft);let $=class extends t.Plugin{constructor(e=Je,n,r,i){super(),this._config=e,this._injector=n,this._renderManagerService=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},Je,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(`sheets-drawing-ui.config`,o)}onStarting(){(0,t.registerDependencies)(this._injector,[[et],[Q],[Ft],[Nt],[Pt],[wt],[yt],[_t],[X],[st],[ct],[ut],[I,{useClass:U}],[tt,{useClass:nt}],[rt]]),Le(this._injector),this._injector.get(et)}onReady(){(0,t.touchDependencies)(this._injector,[[_t],[ut],[X]])}onRendered(){this._registerRenderModules(),(0,t.touchDependencies)(this._injector,[[yt],[wt],[Nt],[st],[ct]])}onSteady(){this._injector.get(Pt),this._injector.get(rt)}_registerRenderModules(){[[j],[dt],[at],[it]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,e))})}};E($,`type`,t.UniverInstanceType.UNIVER_SHEET),E($,`pluginName`,`SHEET_IMAGE_UI_PLUGIN`),E($,`packageName`,Ke),E($,`version`,qe),$=O([(0,t.DependentOn)(o.UniverDrawingPlugin,r.UniverRenderEnginePlugin,f.UniverDocsDrawingPlugin,s.UniverSheetsPlugin,n.UniverSheetsDrawingPlugin,u.UniverDrawingUIPlugin,c.UniverSheetsUIPlugin),D(1,(0,t.Inject)(t.Injector)),D(2,r.IRenderManagerService),D(3,t.IConfigService)],$),Object.defineProperty(e,"BatchSaveImagesService",{enumerable:!0,get:function(){return U}}),e.DeleteDrawingsCommand=g,e.DrawingContextMenuService=nt,e.EditSheetDrawingOperation=J,e.FileNamePart=F,e.GroupSheetDrawingCommand=x,e.IBatchSaveImagesService=I,e.IDrawingContextMenuService=tt,e.InsertFloatImageCommand=M,e.MoveDrawingsCommand=P,e.SHEETS_DRAWING_FLOATING_HOST_DEPENDENCIES=Pe,e.SHEETS_IMAGE_MENU_ID=Re,e.SHEET_CHART_RENDER_OBJECT_CONFIG=ee,e.SHEET_FLOAT_DOM_PREFIX=ne,e.SaveCellImagesCommand=G,Object.defineProperty(e,"SheetCanvasFloatDomManagerService",{enumerable:!0,get:function(){return Q}}),e.SheetDrawingAnchor=Xe,Object.defineProperty(e,"SheetDrawingHitTestService",{enumerable:!0,get:function(){return Ft}}),Object.defineProperty(e,"SheetDrawingUpdateController",{enumerable:!0,get:function(){return j}}),Object.defineProperty(e,"SheetsDrawingGroupCopyPasteController",{enumerable:!0,get:function(){return X}}),e.SheetsDrawingUIMenuSchema=Ge,e.SidebarSheetDrawingOperation=q,e.UngroupSheetDrawingCommand=S,Object.defineProperty(e,"UniverSheetsDrawingUIPlugin",{enumerable:!0,get:function(){return $}}),e.calcSheetFloatDomPosition=Z,e.registerSheetsDrawingFloatingHostCapability=Fe});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-drawing-ui",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "private": false,
5
5
  "description": "Drawing UI integration for Univer Sheets.",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -68,18 +68,18 @@
68
68
  "rxjs": ">=7.0.0"
69
69
  },
70
70
  "dependencies": {
71
- "@univerjs/core": "1.0.0-beta.1",
72
- "@univerjs/design": "1.0.0-beta.1",
73
- "@univerjs/docs": "1.0.0-beta.1",
74
- "@univerjs/docs-ui": "1.0.0-beta.1",
75
- "@univerjs/docs-drawing": "1.0.0-beta.1",
76
- "@univerjs/drawing": "1.0.0-beta.1",
77
- "@univerjs/drawing-ui": "1.0.0-beta.1",
78
- "@univerjs/engine-render": "1.0.0-beta.1",
79
- "@univerjs/sheets-drawing": "1.0.0-beta.1",
80
- "@univerjs/sheets": "1.0.0-beta.1",
81
- "@univerjs/sheets-ui": "1.0.0-beta.1",
82
- "@univerjs/ui": "1.0.0-beta.1"
71
+ "@univerjs/core": "1.0.0-beta.2",
72
+ "@univerjs/design": "1.0.0-beta.2",
73
+ "@univerjs/docs-ui": "1.0.0-beta.2",
74
+ "@univerjs/docs-drawing": "1.0.0-beta.2",
75
+ "@univerjs/drawing": "1.0.0-beta.2",
76
+ "@univerjs/sheets": "1.0.0-beta.2",
77
+ "@univerjs/sheets-drawing": "1.0.0-beta.2",
78
+ "@univerjs/drawing-ui": "1.0.0-beta.2",
79
+ "@univerjs/engine-render": "1.0.0-beta.2",
80
+ "@univerjs/docs": "1.0.0-beta.2",
81
+ "@univerjs/sheets-ui": "1.0.0-beta.2",
82
+ "@univerjs/ui": "1.0.0-beta.2"
83
83
  },
84
84
  "devDependencies": {
85
85
  "postcss": "^8.5.25",
@@ -88,7 +88,7 @@
88
88
  "tailwindcss": "3.4.18",
89
89
  "typescript": "^6.0.3",
90
90
  "vitest": "^4.1.10",
91
- "@univerjs-infra/shared": "1.0.0-beta.1"
91
+ "@univerjs-infra/shared": "1.0.0-beta.2"
92
92
  },
93
93
  "scripts": {
94
94
  "test": "vitest run",