@univerjs/sheets-drawing-ui 0.5.5-nightly.202501210404 → 0.5.5-nightly.202501210734

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.
@@ -1,14 +1,20 @@
1
- import { Disposable } from '@univerjs/core';
1
+ import { Disposable, ICommandService } from '@univerjs/core';
2
+ import { IDrawingManagerService } from '@univerjs/drawing';
2
3
  import { IRenderManagerService } from '@univerjs/engine-render';
3
- import { ISheetDrawingService } from '@univerjs/sheets-drawing';
4
4
  import { ISheetClipboardService } from '@univerjs/sheets-ui';
5
+ import { IClipboardInterfaceService } from '@univerjs/ui';
5
6
  export declare class SheetsDrawingCopyPasteController extends Disposable {
6
7
  private _sheetClipboardService;
7
8
  private readonly _renderManagerService;
8
- private readonly _sheetDrawingService;
9
+ private readonly _drawingService;
10
+ private readonly _clipboardInterfaceService;
11
+ private readonly _commandService;
9
12
  private _copyInfo;
10
- constructor(_sheetClipboardService: ISheetClipboardService, _renderManagerService: IRenderManagerService, _sheetDrawingService: ISheetDrawingService);
13
+ constructor(_sheetClipboardService: ISheetClipboardService, _renderManagerService: IRenderManagerService, _drawingService: IDrawingManagerService, _clipboardInterfaceService: IClipboardInterfaceService, _commandService: ICommandService);
14
+ private get _focusedDrawings();
11
15
  private _initCopyPaste;
12
- private _collect;
16
+ private _createDrawingsCopyInfoByRange;
17
+ private _generateSingleDrawingPasteMutations;
13
18
  private _generateMutations;
19
+ private _generateRangeDrawingsPasteMutations;
14
20
  }
@@ -1,7 +1,7 @@
1
1
  import { IAccessor, Workbook, Disposable, ICommandService, IContextService, Injector, LocaleService } from '@univerjs/core';
2
+ import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
2
3
  import { ISheetLocationBase, SheetsSelectionsService } from '@univerjs/sheets';
3
4
  import { IDrawingManagerService, IImageIoService } from '@univerjs/drawing';
4
- import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
5
5
  import { ISheetDrawingService } from '@univerjs/sheets-drawing';
6
6
  import { ISheetSelectionRenderService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
7
7
  import { ILocalFileService, IMessageService } from '@univerjs/ui';
@@ -35,7 +35,7 @@ export declare class SheetDrawingUpdateController extends Disposable implements
35
35
  constructor(_context: IRenderContext<Workbook>, _skeletonManagerService: SheetSkeletonManagerService, _commandService: ICommandService, _selectionRenderService: ISheetSelectionRenderService, _imageIoService: IImageIoService, _fileOpenerService: ILocalFileService, _sheetDrawingService: ISheetDrawingService, _drawingManagerService: IDrawingManagerService, _contextService: IContextService, _messageService: IMessageService, _localeService: LocaleService, selectionManagerService: SheetsSelectionsService, _injector: Injector);
36
36
  insertFloatImage(): Promise<boolean>;
37
37
  insertCellImage(): Promise<boolean>;
38
- private _insertFloatImage;
38
+ insertFloatImageByFile(file: File): Promise<boolean | undefined>;
39
39
  private _insertCellImage;
40
40
  private _getUnitInfo;
41
41
  private _getImagePosition;
@@ -1,11 +1,15 @@
1
1
  import { Disposable, ICommandService } from '@univerjs/core';
2
+ import { IDrawingManagerService } from '@univerjs/drawing';
3
+ import { SheetsSelectionsService } from '@univerjs/sheets';
2
4
  import { ComponentManager, IMenuManagerService, IShortcutService } from '@univerjs/ui';
3
5
  export declare class SheetDrawingUIController extends Disposable {
4
6
  private readonly _componentManager;
5
7
  private readonly _menuManagerService;
6
8
  private readonly _commandService;
7
9
  private readonly _shortcutService;
8
- constructor(_componentManager: ComponentManager, _menuManagerService: IMenuManagerService, _commandService: ICommandService, _shortcutService: IShortcutService);
10
+ private readonly _drawingManagerService;
11
+ private readonly _sheetsSelectionsService;
12
+ constructor(_componentManager: ComponentManager, _menuManagerService: IMenuManagerService, _commandService: ICommandService, _shortcutService: IShortcutService, _drawingManagerService: IDrawingManagerService, _sheetsSelectionsService: SheetsSelectionsService);
9
13
  private _initCustomComponents;
10
14
  private _initMenus;
11
15
  private _initCommands;
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(b,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("@univerjs/core"),require("@univerjs/docs-drawing"),require("@univerjs/drawing"),require("@univerjs/drawing-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("react"),require("@univerjs/docs-ui"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-drawing","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","react","@univerjs/docs-ui","@univerjs/design"],l):(b=typeof globalThis<"u"?globalThis:b||self,l(b.UniverSheetsDrawingUi={},b.UniverCore,b.UniverDocsDrawing,b.UniverDrawing,b.UniverDrawingUi,b.UniverEngineRender,b.UniverSheetsDrawing,b.UniverSheetsUi,b.UniverUi,b.rxjs,b.UniverSheets,b.React,b.UniverDocsUi,b.UniverDesign))})(this,function(b,l,Se,P,ge,N,f,A,V,k,v,q,bt,ne){"use strict";var cr=Object.defineProperty;var dr=(b,l,Se)=>l in b?cr(b,l,{enumerable:!0,configurable:!0,writable:!0,value:Se}):b[l]=Se;var Z=(b,l,Se)=>dr(b,typeof l!="symbol"?l+"":l,Se);const Xt="sheets-drawing-ui.config",Et={},$={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(i,r)=>{const n=i.get(N.IRenderManagerService);return r.forEach(e=>{var t,o;(o=(t=n.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},Ee={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var C,M,R;const n=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),t=i.get(v.SheetInterceptorService),o=i.get(f.ISheetDrawingService);if(!r)return!1;const{drawings:a}=r,s=[];a.forEach(D=>{const{unitId:T}=D;s.push(T)});const d=o.getBatchRemoveOp(a),{unitId:m,subUnitId:u,undo:c,redo:h,objects:g}=d,p=t.onCommandExecute({id:Ee.id,params:r}),S={id:f.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:h,objects:g,type:f.DrawingApplyType.REMOVE}},w={id:f.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:c,objects:g,type:f.DrawingApplyType.INSERT}};return l.sequenceExecute([...(C=p.preRedos)!=null?C:[],S,...p.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(M=p.preUndos)!=null?M:[],w,...p.undos,{id:$.id,params:s}],redoMutations:[...(R=p.preRedos)!=null?R:[],S,...p.redos,{id:$.id,params:s}]}),!0):!1}},Ot="COMPONENT_SHEET_DRAWING_PANEL",gt={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{const n=i.get(V.ISidebarService),e=i.get(l.LocaleService),t=i.get(l.IUniverInstanceService),o=i.get(l.ICommandService);if(!v.getSheetCommandTarget(t))return!1;switch(r.value){case"open":n.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Ot},onClose:()=>{o.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:n.close();break}return!0}},ht={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(i,r)=>{const n=i.get(l.ICommandService);return r==null?!1:(n.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[r]),n.executeCommand(gt.id,{value:"open"}),!0)}};var mt={exports:{}},Oe={};/**
1
+ (function(O,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("@univerjs/core"),require("@univerjs/docs-drawing"),require("@univerjs/drawing"),require("@univerjs/drawing-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("react"),require("@univerjs/docs-ui"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-drawing","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","react","@univerjs/docs-ui","@univerjs/design"],l):(O=typeof globalThis<"u"?globalThis:O||self,l(O.UniverSheetsDrawingUi={},O.UniverCore,O.UniverDocsDrawing,O.UniverDrawing,O.UniverDrawingUi,O.UniverEngineRender,O.UniverSheetsDrawing,O.UniverSheetsUi,O.UniverUi,O.rxjs,O.UniverSheets,O.React,O.UniverDocsUi,O.UniverDesign))})(this,function(O,l,Se,P,ge,N,w,b,$,W,v,J,bt,ee){"use strict";var hi=Object.defineProperty;var mi=(O,l,Se)=>l in O?hi(O,l,{enumerable:!0,configurable:!0,writable:!0,value:Se}):O[l]=Se;var z=(O,l,Se)=>mi(O,typeof l!="symbol"?l+"":l,Se);const Kt="sheets-drawing-ui.config",Et={},H={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(r,i)=>{const n=r.get(N.IRenderManagerService);return i.forEach(e=>{var t,o;(o=(t=n.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},Ce={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{var I,M,R;const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(v.SheetInterceptorService),o=r.get(w.ISheetDrawingService);if(!i)return!1;const{drawings:a}=i,s=[];a.forEach(y=>{const{unitId:T}=y;s.push(T)});const c=o.getBatchRemoveOp(a),{unitId:m,subUnitId:u,undo:d,redo:h,objects:g}=c,p=t.onCommandExecute({id:Ce.id,params:i}),S={id:w.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:h,objects:g,type:w.DrawingApplyType.REMOVE}},f={id:w.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:d,objects:g,type:w.DrawingApplyType.INSERT}};return l.sequenceExecute([...(I=p.preRedos)!=null?I:[],S,...p.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(M=p.preUndos)!=null?M:[],f,...p.undos,{id:H.id,params:s}],redoMutations:[...(R=p.preRedos)!=null?R:[],S,...p.redos,{id:H.id,params:s}]}),!0):!1}},Ot="COMPONENT_SHEET_DRAWING_PANEL",ht={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(r,i)=>{const n=r.get($.ISidebarService),e=r.get(l.LocaleService),t=r.get(l.IUniverInstanceService),o=r.get(l.ICommandService);if(!v.getSheetCommandTarget(t))return!1;switch(i.value){case"open":n.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Ot},onClose:()=>{o.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:n.close();break}return!0}},mt={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(r,i)=>{const n=r.get(l.ICommandService);return i==null?!1:(n.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[i]),n.executeCommand(ht.id,{value:"open"}),!0)}};var pt={exports:{}},Pe={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,4 +6,4 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var Pt;function xt(){if(Pt)return Oe;Pt=1;var i=q,r=Symbol.for("react.element"),n=Symbol.for("react.fragment"),e=Object.prototype.hasOwnProperty,t=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function a(s,d,m){var u,c={},h=null,g=null;m!==void 0&&(h=""+m),d.key!==void 0&&(h=""+d.key),d.ref!==void 0&&(g=d.ref);for(u in d)e.call(d,u)&&!o.hasOwnProperty(u)&&(c[u]=d[u]);if(s&&s.defaultProps)for(u in d=s.defaultProps,d)c[u]===void 0&&(c[u]=d[u]);return{$$typeof:r,type:s,key:h,ref:g,props:c,_owner:t.current}}return Oe.Fragment=n,Oe.jsx=a,Oe.jsxs=a,Oe}var At;function Kt(){return At||(At=1,mt.exports=xt()),mt.exports}var X=Kt();const Le={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},zt=()=>{const i=l.useDependency(P.IImageIoService),r=l.useDependency(l.LocaleService),[n,e]=q.useState(0);return q.useEffect(()=>{const t=i.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[i]),X.jsx("div",{style:{display:n>0?"block":"none"},className:Le.uploadLoading,children:X.jsxs("div",{className:Le.uploadLoadingBody,children:[X.jsx("div",{className:Le.uploadLoadingBodyAnimation}),X.jsx("div",{className:Le.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${n}`})]})})};var Jt=Object.defineProperty,Zt=Object.getOwnPropertyDescriptor,qt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Zt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Jt(r,n,t),t},he=(i,r)=>(n,e)=>r(n,e,i);let Ge=class extends l.RxDisposable{constructor(r,n,e,t,o,a,s,d){super();Z(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=n,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._commandService=d,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(k.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(k.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(V.BuiltInUIPart.CONTENT,()=>l.connectInjector(zt,this._injector))}_dispose(r){const n=r.getUnitId();this._renderManagerService.removeRender(n)}_create(r){if(!r)return;const n=r.getUnitId();this._renderManagerService.has(n)&&!this._initImagePopupMenu.has(n)&&(this._popupMenuListener(n),this._initImagePopupMenu.add(n))}_hasCropObject(r){const n=r.getAllObjectsByOrder();for(const e of n)if(e instanceof ge.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const n=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!n)return;const e=n.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(l.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(n))return;const a=e.getSelectedObjectMap();if(a.size>1){t==null||t.dispose();return}const s=a.values().next().value;if(!s)return;const d=s.oKey,m=this._drawingManagerService.getDrawingOKey(d);if(!m)return;const{unitId:u,subUnitId:c,drawingId:h,drawingType:g}=m,p=m.data;if(p&&p.disablePopup)return;t==null||t.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,c,h,g);t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:ge.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,c,h,g)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[l.FOCUSING_COMMON_DRAWINGS]===!1&&(t==null||t.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{t==null||t.dispose()}))}_getImageMenuItems(r,n,e,t){return[{label:"image-popup.edit",index:0,commandId:ht.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Ee.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:n,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ge.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ge.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:n,drawingId:e}],disable:t===l.DrawingTypeEnum.DRAWING_DOM}]}};Ge=qt([he(0,l.Inject(l.Injector)),he(1,P.IDrawingManagerService),he(2,l.Inject(A.SheetCanvasPopManagerService)),he(3,N.IRenderManagerService),he(4,l.IUniverInstanceService),he(5,l.IContextService),he(6,l.Inject(V.IUIPartsService)),he(7,l.ICommandService)],Ge);function x(i,r,n){const{from:e,to:t,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:d=0,skewY:m=0}=i,u=n.getCurrent();if(u==null)return;const c=A.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:t},n);let{left:h,top:g,width:p,height:S}=c;const w=n.getCurrentSkeleton(),_=w.rowHeaderWidth+w.columnTotalWidth,C=w.columnHeaderHeight+w.rowTotalHeight;return h+p>_&&(h=_-p),g+S>C&&(g=C-S),{flipY:o,flipX:a,angle:s,skewX:d,skewY:m,left:h,top:g,width:p,height:S}}function H(i,r){const{left:n=0,top:e=0,width:t=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:d=0,skewX:m=0,skewY:u=0}=i,c=r.getCellWithCoordByOffset(n,e);if(c==null)return;const h={column:c.actualColumn,columnOffset:N.precisionTo(n-c.startX,1),row:c.actualRow,rowOffset:N.precisionTo(e-c.startY,1)},g=r.getCellWithCoordByOffset(n+t,e+o);if(g==null)return;const p={column:g.actualColumn,columnOffset:N.precisionTo(n+t-g.startX,1),row:g.actualRow,rowOffset:N.precisionTo(e+o-g.startY,1)};return{flipY:a,flipX:s,angle:d,skewX:m,skewY:u,from:h,to:p}}var Qt=Object.defineProperty,en=Object.getOwnPropertyDescriptor,tn=(i,r,n,e)=>{for(var t=e>1?void 0:e?en(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Qt(r,n,t),t},Ye=(i,r)=>(n,e)=>r(n,e,i);let pt=class extends l.Disposable{constructor(i,r,n,e,t){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=n,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=t,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const n=i[r];for(const e in n.data){const t=n.data[e];t.transform=x(t.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};pt=tn([Ye(1,f.ISheetDrawingService),Ye(2,P.IDrawingManagerService),Ye(3,l.Inject(A.ISheetSelectionRenderService)),Ye(4,l.Inject(A.SheetSkeletonManagerService))],pt);function nn(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s}=e,d=N.getGroupState(0,0,t.map(c=>c.transform||{})),m=t.map(c=>{const h=c.transform||{left:0,top:0},{unitId:g,subUnitId:p,drawingId:S}=c;return{unitId:g,subUnitId:p,drawingId:S,transform:{...h,left:h.left-d.left,top:h.top-d.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:d};r.push({parent:u,children:m})}),r}function rn(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s,transform:d={width:0,height:0}}=e;if(d==null)return;const m=t.map(c=>{const{transform:h}=c,{unitId:g,subUnitId:p,drawingId:S}=c,w=N.transformObjectOutOfGroup(h||{},d,d.width||0,d.height||0);return{unitId:g,subUnitId:p,drawingId:S,transform:w,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:m})}),r}const ft={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),t=i.get(f.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:g,children:p})=>{o.push(g.unitId),p.forEach(S=>{o.push(S.unitId)})});const a=t.getGroupDrawingOp(r),{unitId:s,subUnitId:d,undo:m,redo:u,objects:c}=a;return n.syncExecuteCommand(f.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:d,objects:c,type:f.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:d,objects:rn(c),type:f.DrawingApplyType.UNGROUP}},{id:$.id,params:o}],redoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:d,objects:c,type:f.DrawingApplyType.GROUP}},{id:$.id,params:o}]}),!0):!1}},Pe={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var C,M,R;const n=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),t=i.get(f.ISheetDrawingService),o=i.get(v.SheetInterceptorService);if(!r)return!1;const a=r.drawings,s=a.map(D=>D.unitId),d=t.getBatchAddOp(a),{unitId:m,subUnitId:u,undo:c,redo:h,objects:g}=d,p=o.onCommandExecute({id:Pe.id,params:r}),S={id:f.SetDrawingApplyMutation.id,params:{op:h,unitId:m,subUnitId:u,objects:g,type:f.DrawingApplyType.INSERT}},w={id:f.SetDrawingApplyMutation.id,params:{op:c,unitId:m,subUnitId:u,objects:g,type:f.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(C=p.preRedos)!=null?C:[],S,...p.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(M=p.preUndos)!=null?M:[],w,...p.undos,{id:$.id,params:s}],redoMutations:[...(R=p.preRedos)!=null?R:[],S,...p.redos,{id:$.id,params:s}]}),!0):!1}},St={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(l.ICommandService),e=i.get(l.IUndoRedoService);if(!r)return!1;const t=i.get(f.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:d}=r,m={unitId:o,subUnitId:a,drawingIds:s};let u;if(d===l.ArrangeTypeEnum.forward?u=t.getForwardDrawingsOp(m):d===l.ArrangeTypeEnum.backward?u=t.getBackwardDrawingOp(m):d===l.ArrangeTypeEnum.front?u=t.getFrontDrawingsOp(m):d===l.ArrangeTypeEnum.back&&(u=t.getBackDrawingsOp(m)),u==null)return!1;const{objects:c,redo:h,undo:g}=u;return n.syncExecuteCommand(f.SetDrawingApplyMutation.id,{op:h,unitId:o,subUnitId:a,objects:c,type:f.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:c,type:f.DrawingApplyType.ARRANGE}}],redoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:c,type:f.DrawingApplyType.ARRANGE}}]}),!0):!1}},Ae={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),t=i.get(f.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=t.getBatchUpdateOp(o),{unitId:s,subUnitId:d,undo:m,redo:u,objects:c}=a;return n.syncExecuteCommand(f.SetDrawingApplyMutation.id,{unitId:s,subUnitId:d,op:u,objects:c,type:f.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:f.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:d,op:m,objects:c,type:f.DrawingApplyType.UPDATE}},{id:$.id,params:[s]}],redoMutations:[{id:f.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:d,op:u,objects:c,type:f.DrawingApplyType.UPDATE}},{id:$.id,params:[s]}]}),!0):!1}},wt={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),t=i.get(f.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:g,children:p})=>{o.push(g.unitId),p.forEach(S=>{o.push(S.unitId)})});const a=t.getUngroupDrawingOp(r),{unitId:s,subUnitId:d,undo:m,redo:u,objects:c}=a;return n.syncExecuteCommand(f.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:d,objects:c,type:f.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:d,objects:nn(c),type:f.DrawingApplyType.GROUP}},{id:$.id,params:o}],redoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:d,objects:c,type:f.DrawingApplyType.UNGROUP}},{id:$.id,params:o}]}),!0):!1}};var on=Object.defineProperty,an=Object.getOwnPropertyDescriptor,sn=(i,r,n,e)=>{for(var t=e>1?void 0:e?an(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&on(r,n,t),t},Q=(i,r)=>(n,e)=>r(n,e,i);function cn(i,r,n){const e=n*Math.PI/180,t=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),o=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:t,rotatedHeight:o}}function Ut(i,r,n,e,t){var C;const{rotatedHeight:o,rotatedWidth:a}=cn(n,e,t),d=i.get(N.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const u=(C=d.with(A.SheetSkeletonManagerService).getWorksheetSkeleton(r.subUnitId))==null?void 0:C.skeleton;if(u==null)return!1;const c=u.getCellByIndex(r.row,r.col),h=c.mergeInfo.endX-c.mergeInfo.startX-2,g=c.mergeInfo.endY-c.mergeInfo.startY-2,p=a/o,w=Math.ceil(Math.min(h,g*p))/a,_=!w||Number.isNaN(w)?.001:w;return{width:n*_,height:e*_}}let Ue=class extends l.Disposable{constructor(r,n,e,t,o,a,s,d,m,u,c,h,g){super();Z(this,"_workbookSelections");this._context=r,this._skeletonManagerService=n,this._commandService=e,this._selectionRenderService=t,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=s,this._drawingManagerService=d,this._contextService=m,this._messageService=u,this._localeService=c,this._injector=g,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const r=await this._fileOpenerService.openFile({multiple:!0,accept:P.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),n=r.length;return n>P.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(P.DRAWING_IMAGE_COUNT_LIMIT))}),!1):n===0?!1:(r.forEach(async e=>await this._insertFloatImage(e)),!0)}async insertCellImage(){const n=(await this._fileOpenerService.openFile({multiple:!1,accept:P.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}))[0];return n?(await this._insertCellImage(n),!0):!1}async _insertFloatImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(C){const M=C.message;M===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):M===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):M===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:s,source:d,base64Cache:m}=n,{width:u,height:c,image:h}=await P.getImageSize(m||""),{width:g,height:p}=this._context.scene;this._imageIoService.addImageSourceCache(d,s,h);let S=1;if(u>P.DRAWING_IMAGE_WIDTH_LIMIT||c>P.DRAWING_IMAGE_HEIGHT_LIMIT){const C=P.DRAWING_IMAGE_WIDTH_LIMIT/u,M=P.DRAWING_IMAGE_HEIGHT_LIMIT/c;S=Math.max(C,M)}const w=this._getImagePosition(u*S,c*S,g,p);if(w==null)return;const _={unitId:t,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:d,transform:x(w,this._selectionRenderService,this._skeletonManagerService),sheetTransform:w};this._commandService.executeCommand(Pe.id,{unitId:t,drawings:[_]})}async _insertCellImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(w){const _=w.message;_===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):_===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):_===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const{imageId:e,imageSourceType:t,source:o,base64Cache:a}=n,{width:s,height:d,image:m}=await P.getImageSize(a||"");this._imageIoService.addImageSourceCache(o,t,m);const u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;const c=l.createDocumentModelWithStyle("",{}),h=Ut(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},s,d,0);if(!h)return!1;const g={size:{width:h.width,height:h.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},p={unitId:c.getUnitId(),subUnitId:c.getUnitId(),drawingId:e,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t,source:o,transform:bt.docDrawingPositionToTransform(g),docTransform:g,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=l.BuildTextUtils.drawing.add({documentDataModel:c,drawings:[p],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(c.apply(S),this._commandService.syncExecuteCommand(v.SetRangeValuesCommand.id,{value:{[u.primary.actualRow]:{[u.primary.actualColumn]:{p:c.getSnapshot(),t:1}}}})):!1}_getUnitInfo(){const r=this._context.unit,n=r.getActiveSheet(),e=r.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(r,n,e,t){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const s=A.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(s==null)return;let{startColumn:d,startRow:m,startX:u,startY:c}=s,h=!1;if(u+r>e&&(u=e-r,u<0&&(u=0,r=e),h=!0),c+n>t&&(c=t-n,c<0&&(c=0,n=t),h=!0),h){const w=this._selectionRenderService.getCellWithCoordByOffset(u,c);if(w==null)return;u=w.startX,c=w.startY,d=w.actualColumn,m=w.actualRow}const g={column:d,columnOffset:0,row:m,rowOffset:0},p=this._selectionRenderService.getCellWithCoordByOffset(u+r,c+n);if(p==null)return;const S={column:p.actualColumn,columnOffset:u+r-p.startX,row:p.actualRow,rowOffset:c+n-p.startY};return{from:g,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(r=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o}=r;this._commandService.executeCommand(St.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(r=>{const n=[];r.length!==0&&(r.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a,drawingType:s,transform:d}=e;if(d==null)return;const m=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:a});if(m==null||m.unitId!==this._context.unitId)return;const u=H({...m.transform,...d},this._selectionRenderService);if(u==null)return;const c={...e,transform:{...m.transform,...d,...x(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};n.push(c)}),n.length>0&&this._commandService.executeCommand(Ae.id,{unitId:r[0].unitId,drawings:n}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(r=>{this._commandService.executeCommand(ft.id,r);const{unitId:n,subUnitId:e,drawingId:t}=r[0].parent;this._commandService.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:e,drawingId:t}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(r=>{this._commandService.executeCommand(wt.id,r)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(r=>{r==null||r.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(r))}))}};Ue=sn([Q(1,l.Inject(A.SheetSkeletonManagerService)),Q(2,l.ICommandService),Q(3,A.ISheetSelectionRenderService),Q(4,P.IImageIoService),Q(5,V.ILocalFileService),Q(6,f.ISheetDrawingService),Q(7,P.IDrawingManagerService),Q(8,l.IContextService),Q(9,V.IMessageService),Q(10,l.Inject(l.LocaleService)),Q(11,l.Inject(v.SheetsSelectionsService)),Q(12,l.Inject(l.Injector))],Ue);var dn=Object.defineProperty,ln=Object.getOwnPropertyDescriptor,un=(i,r,n,e)=>{for(var t=e>1?void 0:e?ln(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&dn(r,n,t),t},we=(i,r)=>(n,e)=>r(n,e,i);function vt(i,r,n){var e,t,o,a;if(((t=(e=n==null?void 0:n.p)==null?void 0:e.body)==null?void 0:t.dataStream.length)===3&&((a=(o=n.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const s=n.p.drawings[n.p.drawingsOrder[0]],d=Ut(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},s.docTransform.size.width,s.docTransform.size.height,s.docTransform.angle);if(d)return s.transform.width=d.width,s.transform.height=d.height,s.docTransform.size.width=d.width,s.docTransform.size.height=d.height,s.transform.left=0,s.transform.top=0,s.docTransform.positionH.posOffset=0,s.docTransform.positionV.posOffset=0,n.p.documentStyle.pageSize.width=1/0,n.p.documentStyle.pageSize.height=1/0,!0}return!1}let Fe=class extends l.Disposable{constructor(i,r,n,e,t,o,a){super(),this._commandService=i,this._sheetInterceptorService=r,this._univerInstanceService=n,this._injector=e,this._drawingManagerService=t,this._docDrawingController=o,this._editorBridgeService=a,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{let r,n=[];if(i.id===v.SetWorksheetRowHeightMutation.id){const e=i.params;n=e.ranges,r=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===v.SetWorksheetColWidthMutation.id){const e=i.params;n=e.ranges,r=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===v.SetWorksheetRowIsAutoHeightMutation.id){const e=i.params;n=e.ranges,r=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===v.SetWorksheetRowAutoHeightMutation.id){const e=i.params;r=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId}),n=e.rowsAutoHeightInfo.map(t=>({startRow:t.row,endRow:t.row,startColumn:0,endColumn:9999}))}else if(i.id===v.AddWorksheetMergeMutation.id){const e=i.params;n=e.ranges,r=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===v.RemoveWorksheetMergeMutation.id){const e=i.params;n=e.ranges,r=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}r&&n.length&&n.forEach(e=>{const t=l.Range.transformRange(e,r.worksheet);for(let o=t.startRow;o<=t.endRow;o++)for(let a=t.startColumn;a<=t.endColumn;a++)vt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:o,col:a},r.worksheet.getCellRaw(o,a))})}))}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===bt.ReplaceSnapshotCommand.id&&i.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(v.AFTER_CELL_EDIT,{priority:9999,handler:(i,r,n)=>(vt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i),n(i))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(v.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:v.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,n)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0}),n(i)}}))}};Fe=un([we(0,l.ICommandService),we(1,l.Inject(v.SheetInterceptorService)),we(2,l.IUniverInstanceService),we(3,l.Inject(l.Injector)),we(4,P.IDrawingManagerService),we(5,l.Inject(Se.DocDrawingController)),we(6,l.Inject(A.IEditorBridgeService))],Fe);var gn=Object.defineProperty,hn=Object.getOwnPropertyDescriptor,mn=(i,r,n,e)=>{for(var t=e>1?void 0:e?hn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&gn(r,n,t),t},Nt=(i,r)=>(n,e)=>r(n,e,i);let $e=class extends l.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,n,e)=>{new l.ObjectMatrix(e).forValue((t,o,a)=>{vt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:t,col:o},a)})}}))}};$e=mn([Nt(0,l.Inject(A.IAutoFillService)),Nt(1,l.Inject(l.Injector))],$e);var pn=Object.defineProperty,fn=Object.getOwnPropertyDescriptor,Sn=(i,r,n,e)=>{for(var t=e>1?void 0:e?fn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&pn(r,n,t),t},Ve=(i,r)=>(n,e)=>r(n,e,i);let He=class extends l.Disposable{constructor(r,n,e,t){super();Z(this,"_isSetCursor",!1);this._hoverManagerService=r,this._renderManagerService=n,this._selectionsService=e,this._drawingRenderService=t}_initHover(){}_initImageClick(){}};He=Sn([Ve(0,l.Inject(A.HoverManagerService)),Ve(1,l.Inject(N.IRenderManagerService)),Ve(2,l.Inject(v.SheetsSelectionsService)),Ve(3,l.Inject(ge.DrawingRenderService))],He);var wn=Object.defineProperty,vn=Object.getOwnPropertyDescriptor,_n=(i,r,n,e)=>{for(var t=e>1?void 0:e?vn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&wn(r,n,t),t},_t=(i,r)=>(n,e)=>r(n,e,i);let Xe=class extends l.Disposable{constructor(r,n,e){super();Z(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=n,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,n,e)=>this._collect(r,n,e),onPasteCells:(r,n,e,t)=>{const{copyType:o=A.COPY_TYPE.COPY,pasteType:a}=t,{range:s}=r||{},{range:d,unitId:m,subUnitId:u}=n;return this._generateMutations(d,{copyType:o,pasteType:a,copyRange:s,unitId:m,subUnitId:u})},onPastePlainText:(r,n)=>({undos:[],redos:[]})})}_collect(r,n,e){var h;const t=(h=this._renderManagerService.getRenderById(r))==null?void 0:h.with(A.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:s,startY:d,endY:m}=o,u=this._sheetDrawingService.getDrawingData(r,n),c=[];Object.keys(u).forEach(g=>{const p=u[g],{transform:S}=p;if(p.anchorType!==f.SheetDrawingAnchorType.Both||!S)return;const{left:w=0,top:_=0,width:C=0,height:M=0}=S,{drawingStartX:R,drawingEndX:D,drawingStartY:T,drawingEndY:I}={drawingStartX:w,drawingEndX:w+C,drawingStartY:_,drawingEndY:_+M};a<=R&&D<=s&&d<=T&&I<=m&&c.push(p)}),c.length&&(this._copyInfo={drawings:c,unitId:r,subUnitId:n})}_generateMutations(r,n){var G;if(!this._copyInfo)return{redos:[],undos:[]};if([A.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,A.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,A.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,A.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(n.pasteType))return{redos:[],undos:[]};const{copyRange:t}=n;if(!t)return{redos:[],undos:[]};const{drawings:o,unitId:a,subUnitId:s}=this._copyInfo,{ranges:[d,m],mapFunc:u}=A.virtualizeDiscreteRanges([t,r]),{row:c,col:h}=u(d.startRow,d.startColumn),{row:g,col:p}=u(m.startRow,m.startColumn),S=(G=this._renderManagerService.getRenderById(a))==null?void 0:G.with(A.SheetSkeletonManagerService);if(!S)return{redos:[],undos:[]};const w=S.attachRangeWithCoord({startRow:c,endRow:c,startColumn:h,endColumn:h}),_=S.attachRangeWithCoord({startRow:g,endRow:g,startColumn:p,endColumn:p});if(!w||!_)return{redos:[],undos:[]};const C=[],M=[],R=_.startX-w.startX,D=_.startY-w.startY,T=g-c,I=p-h,j=n.copyType===A.COPY_TYPE.CUT,{_sheetDrawingService:O}=this;return o.forEach(U=>{const{transform:E,sheetTransform:y}=U;if(!E)return;const W={...U,unitId:a,subUnitId:s,drawingId:j?U.drawingId:l.Tools.generateRandomId(),transform:{...E,left:E.left+R,top:E.top+D},sheetTransform:{to:{...y.to,row:y.to.row+T,column:y.to.column+I},from:{...y.from,row:y.from.row+T,column:y.from.column+I}}};if(j){const{undo:B,redo:z,objects:K}=O.getBatchUpdateOp([W]);C.push({id:f.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:s,type:f.DrawingApplyType.UPDATE,op:z,objects:K}}),M.push({id:f.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:s,type:f.DrawingApplyType.UPDATE,op:B,objects:K}})}else{const{undo:B,redo:z,objects:K}=O.getBatchAddOp([W]);C.push({id:f.SetDrawingApplyMutation.id,params:{op:z,unitId:a,subUnitId:s,objects:K,type:f.DrawingApplyType.INSERT}}),M.push({id:f.SetDrawingApplyMutation.id,params:{op:B,unitId:a,subUnitId:s,objects:K,type:f.DrawingApplyType.REMOVE}})}}),{redos:C,undos:M}}};Xe=_n([_t(0,A.ISheetClipboardService),_t(1,N.IRenderManagerService),_t(2,f.ISheetDrawingService)],Xe);var In=Object.defineProperty,Cn=Object.getOwnPropertyDescriptor,yn=(i,r,n,e)=>{for(var t=e>1?void 0:e?Cn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&In(r,n,t),t},Ne=(i,r)=>(n,e)=>r(n,e,i);let xe=class extends l.Disposable{constructor(i,r,n,e,t){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=n,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(k.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingVisible(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new v.WorkbookViewPermission(t).id,new v.WorksheetViewPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const s=r.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(s,d),u=Object.values(m),c=this._renderManagerService.getRenderById(s),h=c==null?void 0:c.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(p=>{p.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>p.oKey.includes(S.drawingId))&&h.removeObject(p)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(k.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingEditable(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new v.WorkbookEditablePermission(t).id,new v.WorksheetEditPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const s=r.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(s,d),u=Object.values(m),c=this._renderManagerService.getRenderById(s),h=c==null?void 0:c.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(p=>{p.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>p.oKey.includes(S.drawingId))&&h.detachTransformerFrom(p)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(k.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var c;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),d=s==null?void 0:s.scene;if(d==null)return;const m=d.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookViewPermission(t).id,new v.WorksheetViewPermission(t,o).id]).pipe(k.map(h=>h.every(g=>g.value)));u==null||u.pipe(k.filter(h=>h!==a),k.distinctUntilChanged()).subscribe({next:h=>{a=h,this._drawingManagerService.setDrawingVisible(h);const g=d.getAllObjectsByOrder(),p=this._drawingManagerService.getDrawingData(t,o),S=Object.values(p);h?this._drawingManagerService.addNotification(S):(g.forEach(w=>{w.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(_=>w.oKey.includes(_.drawingId))&&d.removeObject(w)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new v.WorksheetViewPermission(t,o).id))==null||c.pipe(k.filter(h=>h.value!==a),k.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const h=this._drawingManagerService.getDrawingData(t,o),g=Object.values(h);this._drawingManagerService.addNotification(g)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(k.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var c;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),d=s==null?void 0:s.scene;if(d==null)return;const m=d.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookEditablePermission(t).id,new v.WorksheetEditPermission(t,o).id]).pipe(k.map(h=>h.every(g=>g.value)));u==null||u.pipe(k.filter(h=>h!==a),k.distinctUntilChanged()).subscribe({next:h=>{a=h,this._drawingManagerService.setDrawingEditable(h);const g=d.getAllObjectsByOrder(),p=this._drawingManagerService.getDrawingData(t,o),S=Object.values(p);h?(g.forEach(w=>{w.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(_=>w.oKey.includes(_.drawingId))&&d.attachTransformerTo(w)}),this._drawingManagerService.addNotification(S)):(g.forEach(w=>{w.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(_=>w.oKey.includes(_.drawingId))&&d.detachTransformerFrom(w)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new v.WorksheetEditPermission(t,o).id))==null||c.pipe(k.filter(h=>h.value!==a),k.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const h=r.getUnitId(),g=e.getSheetId(),p=this._drawingManagerService.getDrawingData(h,g),S=Object.values(p),w=this._renderManagerService.getRenderById(h),_=w==null?void 0:w.scene;if(_==null)return;this._drawingManagerService.setDrawingEditable(!0),_.getAllObjectsByOrder().forEach(M=>{M.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(R=>M.oKey.includes(R.drawingId))&&_.detachTransformerFrom(M)})}})})}))}};xe=yn([Ne(0,P.IDrawingManagerService),Ne(1,N.IRenderManagerService),Ne(2,l.IPermissionService),Ne(3,l.IUniverInstanceService),Ne(4,l.Inject(l.UserManagerService))],xe);var Dn=Object.defineProperty,Mn=Object.getOwnPropertyDescriptor,Tn=(i,r,n,e)=>{for(var t=e>1?void 0:e?Mn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Dn(r,n,t),t},Ke=(i,r)=>(n,e)=>r(n,e,i);let ze=class extends l.Disposable{constructor(i,r,n,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=n,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,n)=>{const{unitId:e,scene:t,subUnitId:o}=r,a=this._drawingManagerService.getDrawingDataForUnit(e),s=a==null?void 0:a[o];return s&&s.order.forEach(d=>{this._drawingRenderService.renderDrawing(s.data[d],t)}),n()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,n)=>{const{unitId:e,subUnitId:t}=r,o=this._renderManagerService.getRenderById(e);if(!o)return n(i);const a=o.with(A.SheetSkeletonManagerService).getWorksheetSkeleton(t);if(!a)return n(i);const s=this._drawingManagerService.getDrawingDataForUnit(e),d=s==null?void 0:s[r.subUnitId];if(!d)return n(i);const{scaleX:m,scaleY:u}=o.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},h=d.order.map(g=>d.data[g]).filter(g=>g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM);return h.length?(h.forEach(g=>{if(!g.groupId&&g.transform&&l.Tools.isDefine(g.transform.left)&&l.Tools.isDefine(g.transform.top)&&l.Tools.isDefine(g.transform.width)&&l.Tools.isDefine(g.transform.height)){const p=a.skeleton.getCellIndexByOffset(g.transform.left,g.transform.top,m,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(g.transform.left+g.transform.width,g.transform.top+g.transform.height,m,u,{x:0,y:0});p.column<c.startColumn&&(c.startColumn=p.column),p.row<c.startRow&&(c.startRow=p.row),c.endRow<S.row&&(c.endRow=S.row),c.endColumn<S.column&&(c.endColumn=S.column)}}),n(c)):n(i)}}))}};ze=Tn([Ke(0,l.Inject(A.SheetPrintInterceptorService)),Ke(1,l.Inject(ge.DrawingRenderService)),Ke(2,P.IDrawingManagerService),Ke(3,N.IRenderManagerService)],ze);var Rn=Object.defineProperty,bn=Object.getOwnPropertyDescriptor,En=(i,r,n,e)=>{for(var t=e>1?void 0:e?bn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Rn(r,n,t),t},me=(i,r)=>(n,e)=>r(n,e,i);const On=[v.InsertRowCommand.id,v.InsertColCommand.id,v.RemoveRowCommand.id,v.RemoveColCommand.id,v.DeleteRangeMoveLeftCommand.id,v.DeleteRangeMoveUpCommand.id,v.InsertRangeMoveDownCommand.id,v.InsertRangeMoveRightCommand.id,v.DeltaRowHeightCommand.id,v.SetRowHeightCommand.id,v.DeltaColumnWidthCommand.id,v.SetColWidthCommand.id,v.SetRowHiddenCommand.id,v.SetSpecificRowsVisibleCommand.id,v.SetSpecificColsVisibleCommand.id,v.SetColHiddenCommand.id,v.MoveColsCommand.id,v.MoveRowsCommand.id,v.MoveRangeCommand.id],Pn=[v.SetRowVisibleMutation.id,v.SetRowHiddenMutation.id,v.SetColVisibleMutation.id,v.SetColHiddenMutation.id,v.SetWorksheetRowHeightMutation.id,v.SetWorksheetColWidthMutation.id];let It=class extends l.Disposable{constructor(i,r,n,e,t,o,a,s,d){super(),this._context=i,this._renderManagerService=r,this._commandService=n,this._selectionRenderService=e,this._skeletonManagerService=t,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!On.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===v.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([v.MoveColsCommand.id,v.MoveRowsCommand.id,v.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===v.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===v.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===v.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===v.DeleteRangeMoveLeftCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,0)}else if(r===v.DeleteRangeMoveUpCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,1)}else if(r===v.InsertRangeMoveDownCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,2)}else if(r===v.InsertRangeMoveRightCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,3)}else if(r===v.SetRowHiddenCommand.id||r===v.SetSpecificRowsVisibleCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForRowVisible(e,t,o)}else if(r===v.SetSpecificColsVisibleCommand.id||r===v.SetColHiddenCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForColVisible(e,t,o)}else if(r===v.DeltaRowHeightCommand.id||r===v.SetRowHeightCommand.id||r===v.DeltaColumnWidthCommand.id||r===v.SetColWidthCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n,a=r===v.DeltaRowHeightCommand.id||r===v.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const n=v.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const e=n.unitId,t=n.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(e,t),d=[],m=[];if(Object.keys(s).forEach(u=>{const c=s[u],{updateDrawings:h,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(i,r,c);d.push(...h),m.push(...g)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:h,objects:g}=u;o.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:h,objects:g,type:f.DrawingApplyType.UPDATE}}),a.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:c,objects:g,type:f.DrawingApplyType.UPDATE}})}if(m.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(m),c=u.undo,h=u.redo,g=u.objects;o.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:h,objects:g,type:f.DrawingApplyType.REMOVE}}),a.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:c,objects:g,type:f.DrawingApplyType.INSERT}})}return o.push({id:$.id,params:[e]}),a.push({id:$.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,r,n){const e=[],t=[],{sheetTransform:o,anchorType:a=f.SheetDrawingAnchorType.Position,transform:s,unitId:d,subUnitId:m,drawingId:u}=n,{from:c,to:h}=o,{row:g,column:p}=c,{row:S,column:w}=h;if(o==null||s==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:_,endRow:C,startColumn:M,endColumn:R}=i;let D=null,T=null;if(r===0&&g>=_&&S<=C)if(p>=M&&w<=R)t.push({unitId:d,subUnitId:m,drawingId:u});else{const I=this._shrinkCol(o,s,M,R,a);D=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===1&&p>=M&&w<=R)if(g>=_&&S<=C)t.push({unitId:d,subUnitId:m,drawingId:u});else{const I=this._shrinkRow(o,s,_,C,a);D=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===2){const I=this._expandRow(o,s,_,C,a);D=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===3){const I=this._expandCol(o,s,M,R,a);D=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}if(D!=null&&T!=null){const I=x(D,this._selectionRenderService,this._skeletonManagerService);e.push({...n,sheetTransform:D,transform:I})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(i,r,n){const e=H({...i},this._selectionRenderService);e!=null&&r.push({...n,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:h,transform:g,anchorType:p=f.SheetDrawingAnchorType.Position}=c;if(p===f.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,c);else{const{from:S,to:w}=h,{row:_,column:C}=S,{row:M,column:R}=w;for(let D=0;D<n.length;D++){const T=n[D],{startRow:I,endRow:j,startColumn:O,endColumn:G}=T;if(R<O)continue;if(p===f.SheetDrawingAnchorType.Position){let y=null,W=null;if(C>=O&&C<=G){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:C,endColumn:G,startRow:S.row,endRow:w.row});if(B==null)return;W={...g,left:B.startX}}if(W!=null&&(y=H(W,this._selectionRenderService),y!=null&&W!=null)){t.push({...c,sheetTransform:y,transform:W});break}this._remainDrawingSize(g,t,c);continue}if(C>=O&&R<=G)continue;let U=null,E=null;if(C>=O&&C<=G){const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:C,endColumn:G,startRow:S.row,endRow:w.row});if(y==null)return;E={...g,left:(y==null?void 0:y.startX)||0,width:((g==null?void 0:g.width)||0)-y.endX+y.startX}}else if(R>=O&&R<=G){const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:R,startRow:S.row,endRow:w.row});if(y==null)return;E={...g,left:y.startX-((g==null?void 0:g.width)||0)}}else{const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:G,startRow:S.row,endRow:w.row});if(y==null)return;if(E={...g,width:((g==null?void 0:g.width)||0)-y.endX+y.startX},U=H(E,this._selectionRenderService),U!=null&&E!=null){o.push({...c,sheetTransform:U,transform:E});break}}if(E!=null&&(U=H(E,this._selectionRenderService)),E!=null&&U!=null){t.push({...c,sheetTransform:U,transform:E});break}else this._remainDrawingSize(g,t,c)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,t),d=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);d.push(...u),m.push(...c)}return{redos:a,undos:s,preRedos:d,preUndos:m}}_createUndoAndRedoMutation(i,r,n){const e=this._sheetDrawingService.getBatchUpdateOp(n),{undo:t,redo:o,objects:a}=e,s=[{id:f.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:f.DrawingApplyType.UPDATE}},{id:$.id,params:[i]}],d=[{id:f.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:t,objects:a,type:f.DrawingApplyType.UPDATE}},{id:$.id,params:[i]}];return{redos:s,undos:d}}_getDrawingUndoForRowVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:h,transform:g,anchorType:p=f.SheetDrawingAnchorType.Position}=c;if(p===f.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,c);else{const{from:S,to:w}=h,{row:_,column:C}=S,{row:M,column:R}=w;for(let D=0;D<n.length;D++){const T=n[D],{startRow:I,endRow:j,startColumn:O,endColumn:G}=T;if(M<I)continue;if(p===f.SheetDrawingAnchorType.Position){let y=null,W=null;if(_>=I&&_<=j){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:_,endRow:j});if(B==null)return;W={...g,top:B.startY}}if(W!=null&&(y=H(W,this._selectionRenderService),y!=null&&W!=null)){t.push({...c,sheetTransform:y,transform:W});break}this._remainDrawingSize(g,t,c);continue}if(_>=I&&M<=j)continue;let U=null,E=null;if(_>=I&&_<=j){const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:_,endRow:j});if(y==null)return;E={...g,top:(y==null?void 0:y.startY)||0,height:((g==null?void 0:g.height)||0)-y.endY+y.startY}}else if(M>=I&&M<=j){const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:M});if(y==null)return;E={...g,top:y.startY-((g==null?void 0:g.height)||0)}}else{const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:j});if(y==null)return;if(E={...g,height:((g==null?void 0:g.height)||0)-y.endY+y.startY},U=H(E,this._selectionRenderService),U!=null&&E!=null){o.push({...c,sheetTransform:U,transform:E});break}}if(E!=null&&(U=H(E,this._selectionRenderService)),E!=null&&U!=null){t.push({...c,sheetTransform:U,transform:E});break}else this._remainDrawingSize(g,t,c)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,t),d=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);d.push(...u),m.push(...c)}return{redos:a,undos:s,preRedos:d,preUndos:m}}_getDrawingUndoForRowAndColSize(i,r,n,e){const t=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(t).forEach(a=>{const s=t[a],{sheetTransform:d,transform:m,anchorType:u=f.SheetDrawingAnchorType.Position}=s;if(u===f.SheetDrawingAnchorType.None)this._remainDrawingSize(m,o,s);else{const{from:c,to:h}=d,{row:g,column:p}=c,{row:S,column:w}=h;for(let _=0;_<n.length;_++){const C=n[_],{startRow:M,endRow:R,startColumn:D,endColumn:T}=C;if(S<M||w<D)continue;if(u===f.SheetDrawingAnchorType.Position&&(g<=M&&S>=R||p<=D&&w>=T)){this._remainDrawingSize(m,o,s);continue}const I=x({...d},this._selectionRenderService,this._skeletonManagerService);if(I!=null){o.push({...s,transform:I});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let n,e;if(r==="insert")n=i.unitId,e=i.subUnitId;else{const t=v.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;n=t.unitId,e=t.subUnitId}return{unitId:n,subUnitId:e}}_moveRangeInterceptor(i){var M,R;const{toRange:r,fromRange:n}=i,e=v.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,a=(R=(M=this._renderManagerService.getRenderById(t))==null?void 0:M.with(A.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=A.attachRangeWithCoord(a,n);if(!s)return{redos:[],undos:[]};const{startX:d,endX:m,startY:u,endY:c}=s,h=this._sheetDrawingService.getDrawingData(t,o),g=[];Object.keys(h).forEach(D=>{const T=h[D];if(T.anchorType!==f.SheetDrawingAnchorType.Both)return;const{transform:I}=T;if(!I)return;const{left:j=0,top:O=0,width:G=0,height:U=0}=I,{drawingStartX:E,drawingEndX:y,drawingStartY:W,drawingEndY:B}={drawingStartX:j,drawingEndX:j+G,drawingStartY:O,drawingEndY:O+U};d<=E&&y<=m&&u<=W&&B<=c&&g.push(T)});const p=[],S=[],w=r.startRow-n.startRow,_=r.startColumn-n.startColumn,C=g.map(D=>{const T=D.sheetTransform,I={to:{...T.to,row:T.to.row+w,column:T.to.column+_},from:{...T.from,row:T.from.row+w,column:T.from.column+_}},j=x(I,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:D.drawingId,transform:j,sheetTransform:I}});if(C.length){const D=this._sheetDrawingService.getBatchUpdateOp(C),{undo:T,redo:I,objects:j}=D;p.push({id:f.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:I,objects:j,type:f.DrawingApplyType.UPDATE}}),S.push({id:f.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:T,objects:j,type:f.DrawingApplyType.UPDATE}})}return{redos:p,undos:S}}_moveRowInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startRow,s=o.endRow,d=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),c=[],h=[];if(Object.keys(u).forEach(g=>{const p=u[g],{sheetTransform:S,transform:w,anchorType:_=f.SheetDrawingAnchorType.Position}=p;if(S==null||w==null)return;let C,M;if(r==="insert"){const D=this._expandRow(S,w,a,s,_);C=D==null?void 0:D.newSheetTransform,M=D==null?void 0:D.newTransform}else{const{from:D,to:T}=S,{row:I}=D,{row:j}=T;if(_===f.SheetDrawingAnchorType.Both&&I>=a&&j<=s)h.push({unitId:e,subUnitId:t,drawingId:g});else{const O=this._shrinkRow(S,w,a,s,_);C=O==null?void 0:O.newSheetTransform,M=O==null?void 0:O.newTransform}}if(!C||!M)return;const R={unitId:e,subUnitId:t,drawingId:g,transform:M,sheetTransform:C};c.push(R)}),c.length===0&&h.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:p,redo:S,objects:w}=g;d.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:w,type:f.DrawingApplyType.UPDATE}}),m.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:w,type:f.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),p=g.undo,S=g.redo,w=g.objects;d.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:w,type:f.DrawingApplyType.REMOVE}}),m.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:w,type:f.DrawingApplyType.INSERT}})}return d.push({id:$.id,params:[e]}),m.push({id:$.id,params:[e]}),{redos:d,undos:m}}_moveColInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startColumn,s=o.endColumn,d=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),c=[],h=[];if(Object.keys(u).forEach(g=>{const p=u[g],{sheetTransform:S,transform:w,anchorType:_=f.SheetDrawingAnchorType.Position}=p;if(S==null||w==null)return;let C,M;if(r==="insert"){const D=this._expandCol(S,w,a,s,_);C=D==null?void 0:D.newSheetTransform,M=D==null?void 0:D.newTransform}else{const{from:D,to:T}=S,{column:I}=D,{column:j}=T;if(_===f.SheetDrawingAnchorType.Both&&I>=a&&j<=s)h.push({unitId:e,subUnitId:t,drawingId:g});else{const O=this._shrinkCol(S,w,a,s,_);C=O==null?void 0:O.newSheetTransform,M=O==null?void 0:O.newTransform}}if(!C||!M)return;const R={unitId:e,subUnitId:t,drawingId:g,transform:M,sheetTransform:C};c.push(R)}),c.length===0&&h.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:p,redo:S,objects:w}=g;d.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:w,type:f.DrawingApplyType.UPDATE}}),m.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:w,type:f.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),p=g.undo,S=g.redo,w=g.objects;d.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:w,type:f.DrawingApplyType.REMOVE}}),m.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:w,type:f.DrawingApplyType.INSERT}})}return d.push({id:$.id,params:[e]}),m.push({id:$.id,params:[e]}),{redos:d,undos:m}}_expandCol(i,r,n,e,t=f.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=i,{column:d}=a,{column:m}=s;if(t===f.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:e,startRow:a.row,endRow:s.row});if(h==null)return;c={...r,left:(r.left||0)+h.endX-h.startX},u=H(c,this._selectionRenderService)}else if(m>=e)if(t===f.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m+o}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(i,r,n,e,t=f.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=i,{column:d}=a,{column:m}=s;if(t===f.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...a,column:d-o},to:{...s,column:m-o}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=n&&m<=e)return null;if(d<n&&m>e)if(t===f.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m-o}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(d>=n&&d<=e){if(d===n)c={...r,left:(r.left||0)-i.from.columnOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:d-1,startRow:a.row,endRow:s.row});if(h==null)return;c={...r,left:(r.left||0)-h.endX+h.startX-i.from.columnOffset}}u=H(c,this._selectionRenderService)}else if(m>=n&&m<=e&&t===f.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n-1,endColumn:n-1,startRow:a.row,endRow:s.row});if(h==null)return;u={from:{...a},to:{...s,column:n-1,columnOffset:h.endX-h.startX}},c=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(i,r,n,e,t=f.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=i,{row:d}=a,{row:m}=s;if(t===f.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:e,startColumn:a.column,endColumn:s.column});if(h==null)return;c={...r,top:(r.top||0)+h.endY-h.startY},u=H(c,this._selectionRenderService)}else if(m>=e)if(t===f.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m+o}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(i,r,n,e,t=f.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=i,{row:d}=a,{row:m}=s;if(t===f.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...a,row:d-o},to:{...s,row:m-o}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=n&&m<=e)return null;if(d<n&&m>e)if(t===f.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m-o}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(d>=n&&d<=e){if(d===n)c={...r,top:(r.top||0)-i.from.rowOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:d-1,startColumn:a.column,endColumn:s.column});if(h==null)return;c={...r,top:(r.top||0)-h.endY+h.startY-i.from.rowOffset}}u=H(c,this._selectionRenderService)}else if(m>=n&&m<=e&&t===f.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:n-1,endRow:n-1});if(h==null)return;u={from:{...a},to:{...s,row:n-1,rowOffset:h.endY-h.startY}},c=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===v.SetWorksheetActiveOperation.id&&setTimeout(()=>{const r=i.params,{unitId:n,subUnitId:e}=r,t=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(t).forEach(s=>{const d=t[s];d!=null&&Object.keys(d).forEach(m=>{const u=d[m].data;u!=null&&Object.keys(u).forEach(c=>{if(s===n&&m===e){const h=u[c];h.transform=x(h.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(u[c])}else a.push(u[c])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Pn.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:n,subUnitId:e,ranges:t}=r;this._refreshDrawingTransform(n,e,t)})}))}_refreshDrawingTransform(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:s,transform:d,anchorType:m=f.SheetDrawingAnchorType.Position}=a;if(m===f.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=s,{row:h,column:g}=u,{row:p,column:S}=c;for(let w=0;w<n.length;w++){const _=n[w],{startRow:C,endRow:M,startColumn:R,endColumn:D}=_;if(l.Rectangle.intersects({startRow:C,endRow:M,startColumn:R,endColumn:D},{startRow:h,endRow:p,startColumn:g,endColumn:S})||h>M||g>D){const T=m===f.SheetDrawingAnchorType.Position,I=x(s,this._selectionRenderService,this._skeletonManagerService);t.push({...a,transform:{...I,width:T?d==null?void 0:d.width:I==null?void 0:I.width,height:T?d==null?void 0:d.height:I==null?void 0:I.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand($.id,[i]))}};It=En([me(1,N.IRenderManagerService),me(2,l.ICommandService),me(3,A.ISheetSelectionRenderService),me(4,l.Inject(A.SheetSkeletonManagerService)),me(5,l.Inject(v.SheetInterceptorService)),me(6,f.ISheetDrawingService),me(7,P.IDrawingManagerService),me(8,l.IUniverInstanceService)],It);var ee=function(){return ee=Object.assign||function(i){for(var r,n=1,e=arguments.length;n<e;n++){r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(i[t]=r[t])}return i},ee.apply(this,arguments)},An=function(i,r){var n={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(n[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(i);t<e.length;t++)r.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(i,e[t])&&(n[e[t]]=i[e[t]]);return n},jt=q.forwardRef(function(i,r){var n=i.icon,e=i.id,t=i.className,o=i.extend,a=An(i,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),d=q.useRef("_".concat(jn()));return Wt(n,"".concat(e),{defIds:n.defIds,idSuffix:d.current},ee({ref:r,className:s},a),o)});function Wt(i,r,n,e,t){return q.createElement(i.tag,ee(ee({key:r},Un(i,n,t)),e),(Nn(i,n).children||[]).map(function(o,a){return Wt(o,"".concat(r,"-").concat(i.tag,"-").concat(a),n,void 0,t)}))}function Un(i,r,n){var e=ee({},i.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var t=r.defIds;return!t||t.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Nn(i,r){var n,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?ee(ee({},i),{children:i.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?ee(ee({},t),{attrs:ee(ee({},t.attrs),{id:t.attrs.id+r.idSuffix})}):t})}):i}function jn(){return Math.random().toString(36).substring(2,8)}jt.displayName="UniverIcon";var Wn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z"}}]},Bt=q.forwardRef(function(i,r){return q.createElement(jt,Object.assign({},i,{id:"add-image-single",ref:r,icon:Wn}))});Bt.displayName="AddImageSingle";const Ct={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),e=i.get(f.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(a=>{const{unitId:s,subUnitId:d,drawingId:m,drawingType:u}=a;return{unitId:s,subUnitId:d,drawingId:m,drawingType:u}});return r.executeCommand(Ee.id,{unitId:t,drawings:o})}},Je={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(N.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(Ue).insertFloatImage())!=null?e:!1}},yt={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(N.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(Ue).insertCellImage())!=null?e:!1}},Ce={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(l.ICommandService),e=i.get(f.ISheetDrawingService),t=i.get(A.ISheetSelectionRenderService),{direction:o}=r,a=e.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,d=a.map(u=>{const{transform:c}=u;if(c==null)return null;const h={...c},{left:g=0,top:p=0}=c;return o===l.Direction.UP?h.top=p-1:o===l.Direction.DOWN?h.top=p+1:o===l.Direction.LEFT?h.left=g-1:o===l.Direction.RIGHT&&(h.left=g+1),{...u,transform:h,sheetTransform:H(h,t)}}).filter(u=>u!=null);return n.syncExecuteCommand(Ae.id,{unitId:s,drawings:d})?(n.syncExecuteCommand($.id,[s]),!0):!1}},kt="addition-and-subtraction-single",Dt="sheet.menu.image";function Bn(i){return{id:Dt,type:V.MenuItemType.SUBITEMS,icon:kt,tooltip:"sheetImage.title",hidden$:V.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),disabled$:A.getCurrentRangeDisable$(i,{workbookTypes:[v.WorkbookEditablePermission],worksheetTypes:[v.WorksheetEditPermission],rangeTypes:[v.RangeProtectionPermissionEditPoint]})}}function kn(i){return{id:Je.id,title:"sheetImage.upload.float",type:V.MenuItemType.BUTTON,hidden$:V.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function Ln(i){return{id:yt.id,title:"sheetImage.upload.cell",type:V.MenuItemType.BUTTON}}const pe={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelSubtitle:"univer-image-common-panel-subtitle",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"};function Lt(i){var r,n,e="";if(typeof i=="string"||typeof i=="number")e+=i;else if(typeof i=="object")if(Array.isArray(i)){var t=i.length;for(r=0;r<t;r++)i[r]&&(n=Lt(i[r]))&&(e&&(e+=" "),e+=n)}else for(n in i)i[n]&&(e&&(e+=" "),e+=n);return e}function Ze(){for(var i,r,n=0,e="",t=arguments.length;n<t;n++)(i=arguments[n])&&(r=Lt(i))&&(e&&(e+=" "),e+=r);return e}const Gn=i=>{var M;const r=l.useDependency(l.ICommandService),n=l.useDependency(l.LocaleService),e=l.useDependency(P.IDrawingManagerService),t=l.useDependency(N.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:s}=a,d=t.getRenderById(s),m=d==null?void 0:d.scene;if(m==null)return;const u=m.getTransformerByCreate(),[c,h]=q.useState(!0),g=(M=a.anchorType)!=null?M:f.SheetDrawingAnchorType.Position,[p,S]=q.useState(g);function w(R,D){const T=[];return R.forEach(I=>{const{oKey:j}=I,O=D.getDrawingOKey(j);if(O==null)return T.push(null),!0;const{unitId:G,subUnitId:U,drawingId:E,drawingType:y,anchorType:W,sheetTransform:B}=O;T.push({unitId:G,subUnitId:U,drawingId:E,anchorType:W,sheetTransform:B,drawingType:y})}),T}q.useEffect(()=>{const R=u.clearControl$.subscribe(T=>{T===!0&&h(!1)}),D=u.changeStart$.subscribe(T=>{var O;const{objects:I}=T,j=w(I,e);if(j.length===0)h(!1);else if(j.length>=1){h(!0);const G=((O=j[0])==null?void 0:O.anchorType)||f.SheetDrawingAnchorType.Position;S(G)}});return()=>{D.unsubscribe(),R.unsubscribe()}},[]);function _(R){S(R);const D=e.getFocusDrawings();if(D.length===0)return;const T=D.map(I=>({unitId:I.unitId,subUnitId:I.subUnitId,drawingId:I.drawingId,anchorType:R}));r.executeCommand(Ae.id,{unitId:D[0].unitId,drawings:T})}const C=R=>R?"block":"none";return X.jsxs("div",{className:Ze(pe.imageCommonPanelGrid,pe.imageCommonPanelBorder),style:{display:C(c)},children:[X.jsx("div",{className:pe.imageCommonPanelRow,children:X.jsx("div",{className:Ze(pe.imageCommonPanelColumn,pe.imageCommonPanelTitle),children:X.jsx("div",{children:n.t("drawing-anchor.title")})})}),X.jsx("div",{className:Ze(pe.imageCommonPanelRow),children:X.jsx("div",{className:Ze(pe.imageCommonPanelColumn),children:X.jsxs(ne.RadioGroup,{value:p,onChange:_,direction:"vertical",children:[X.jsx(ne.Radio,{value:f.SheetDrawingAnchorType.Both,children:n.t("drawing-anchor.both")}),X.jsx(ne.Radio,{value:f.SheetDrawingAnchorType.Position,children:n.t("drawing-anchor.position")}),X.jsx(ne.Radio,{value:f.SheetDrawingAnchorType.None,children:n.t("drawing-anchor.none")})]})})})]})},Yn=()=>{const i=l.useDependency(P.IDrawingManagerService),r=i.getFocusDrawings(),[n,e]=q.useState(r);return q.useEffect(()=>{const t=i.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(n!=null&&n.length)&&X.jsxs("div",{className:pe.imageCommonPanel,children:[X.jsx(ge.DrawingCommonPanel,{drawings:n}),X.jsx(Gn,{drawings:n})]})},Fn={[V.RibbonStartGroup.FORMULAS_INSERT]:{[Dt]:{order:3,menuItemFactory:Bn,[Je.id]:{order:0,menuItemFactory:kn},[yt.id]:{order:1,menuItemFactory:Ln}}}};function je(i){return!i.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(l.EDITOR_ACTIVATED)&&!i.getContextValue(l.FOCUSING_PANEL_EDITOR)&&i.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const $n={id:Ce.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:V.KeyCode.ARROW_DOWN,priority:100,preconditions:je,staticParameters:{direction:l.Direction.DOWN}},Vn={id:Ce.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:V.KeyCode.ARROW_UP,priority:100,preconditions:je,staticParameters:{direction:l.Direction.UP}},Hn={id:Ce.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:V.KeyCode.ARROW_LEFT,priority:100,preconditions:je,staticParameters:{direction:l.Direction.LEFT}},Xn={id:Ce.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:V.KeyCode.ARROW_RIGHT,priority:100,preconditions:je,staticParameters:{direction:l.Direction.RIGHT}},xn={id:Ct.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:je,binding:V.KeyCode.DELETE,mac:V.KeyCode.BACKSPACE};var Kn=Object.defineProperty,zn=Object.getOwnPropertyDescriptor,Jn=(i,r,n,e)=>{for(var t=e>1?void 0:e?zn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Kn(r,n,t),t},qe=(i,r)=>(n,e)=>r(n,e,i);let Qe=class extends l.Disposable{constructor(i,r,n,e){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=n,this._shortcutService=e,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(kt,Bt)),this.disposeWithMe(i.register(Ot,Yn))}_initMenus(){this._menuManagerService.mergeMenu(Fn)}_initCommands(){[Je,yt,Pe,Ee,Ae,gt,$,ht,ft,wt,Ce,Ct,St].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[$n,Vn,Hn,Xn,xn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Qe=Jn([qe(0,l.Inject(V.ComponentManager)),qe(1,V.IMenuManagerService),qe(2,l.ICommandService),qe(3,V.IShortcutService)],Qe);var Zn=Object.defineProperty,qn=Object.getOwnPropertyDescriptor,Qn=(i,r,n,e)=>{for(var t=e>1?void 0:e?qn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Zn(r,n,t),t},ve=(i,r)=>(n,e)=>r(n,e,i);function er(i,r,n,e,t){const{scaleX:o,scaleY:a}=r.getAncestorScale(),s=r.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN),d={left:!0,top:!0};if(!s)return{...i,absolute:d};const{left:m,right:u,top:c,bottom:h}=i;let{top:g,left:p,viewportScrollX:S,viewportScrollY:w}=s;const{boundsOfViewArea:_,scrollDirectionResponse:C}=t||{};_&&(l.Tools.isDefine(_.top)&&(g=_.top),l.Tools.isDefine(_.left)&&(p=_.left)),C==="HORIZONTAL"&&(w=0),C==="VERTICAL"&&(S=0);let M,R;m<p?(d.left=!0,M=(p+(m-p))*o,R=Math.max(Math.min((p+(u-p))*o,p*o),(u-S)*o)):(d.left=!1,M=Math.max((m-S)*o,p*o),R=Math.max((u-S)*o,p*o));let D,T;return c<g?(d.top=!0,D=(g+(c-g))*a,T=Math.max(Math.min((g+(u-g))*a,g*a),(h-w)*a)):(d.top=!1,D=Math.max((c-w)*a,g*a),T=Math.max((h-w)*a,g*a)),{left:M,right:R,top:D,bottom:T,absolute:d}}const se=(i,r,n,e,t)=>{const{scene:o}=r,{left:a,top:s,width:d,height:m,angle:u}=i,c={left:a,right:a+d,top:s,bottom:s+m},h=er(c,o,n,e,t),{scaleX:g,scaleY:p}=o.getAncestorScale();return{startX:h.left,endX:h.right,startY:h.top,endY:h.bottom,rotate:u,width:d*g,height:m*p,absolute:h.absolute}};b.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(n,e,t,o,a,s,d){super();Z(this,"_domLayerMap",new Map);Z(this,"_domLayerInfoMap",new Map);Z(this,"_transformChange$",new k.Subject);Z(this,"transformChange$",this._transformChange$.asObservable());Z(this,"_add$",new k.Subject);Z(this,"add$",this._add$.asObservable());Z(this,"_remove$",new k.Subject);Z(this,"remove$",this._remove$.asObservable());Z(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=s,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(k.filter(n=>n===l.LifecycleStages.Rendered),k.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(n,e){let t=this._domLayerMap.get(n);t||(t=new Map,this._domLayerMap.set(n,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(n){return this._domLayerInfoMap.get(n)}_getSceneAndTransformerByDrawingSearch(n){if(n==null)return;const e=this._renderManagerService.getRenderById(n),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:t,transformer:o,renderUnit:e,canvas:a}}_getFloatDomProps(n){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(n)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(n=>{n.forEach(e=>{var re,ie,J;const{unitId:t,subUnitId:o,drawingId:a}=e,s=v.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(t,l.UniverInstanceType.UNIVER_SHEET);if(!m)return;const u=m.getActiveSheet().getSheetId();if(!d||!s)return;const c=(re=this._renderManagerService.getRenderById(t))==null?void 0:re.with(A.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!c)return;const{transform:h,drawingType:g,data:p}=d;if(g!==l.DrawingTypeEnum.DRAWING_DOM&&g!==l.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(t);if(S==null)return;const{scene:w,canvas:_}=S;if(h==null)return!0;if(u!==o)return;const{left:C,top:M,width:R,height:D,angle:T,flipX:I,flipY:j,skewX:O,skewY:G}=h,U=P.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),E=w.getObject(U);if(E!=null){E.transformByState({left:C,top:M,width:R,height:D,angle:T,flipX:I,flipY:j,skewX:O,skewY:G});return}const y={left:C,top:M,width:R,height:D,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},W=g===l.DrawingTypeEnum.DRAWING_CHART;if(W){const F=p?p.backgroundColor:"white";y.fill=F,y.rotateEnabled=!1,p&&p.border&&(y.stroke=p.border),y.paintFirst="stroke",y.strokeWidth=1,y.borderEnabled=!1,y.radius=8}const B=new N.Rect(U,y);W&&B.setObjectType(N.ObjectType.CHART),w.addObject(B,N.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&w.attachTransformerTo(B);const z=this._ensureMap(t,o),K=new l.DisposableCollection,_e=se(B,S.renderUnit,c.skeleton,s.worksheet),ae=new k.BehaviorSubject(_e),Ie={dispose:K,rect:B,position$:ae,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:ae,id:a,componentKey:d.componentKey,onPointerDown:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onWheel:F=>{_.dispatchEvent(new WheelEvent(F.type,F))},props:(J=(ie=z.get(a))==null?void 0:ie.props)!=null?J:this._getFloatDomProps(a),data:p,unitId:t});const ce=B.onTransformChange$.subscribeEvent(()=>{const F=se(B,S.renderUnit,c.skeleton,s.worksheet);ae.next(F)});K.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),ce&&K.add(ce),this._domLayerInfoMap.set(a,Ie),z.set(a,{...z.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a}=e,s=P.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),d=this._getSceneAndTransformerByDrawingSearch(t);if(d==null)return;const{transformer:m,scene:u}=d,c=u.getObject(s);c!=null&&c.oKey&&m.clearControlByIds([c==null?void 0:c.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,t),s=Array.from(a.keys()),d=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),m=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(A.SheetSkeletonManagerService).getWorksheetSkeleton(t);!o||!d||!m||s.forEach(c=>{const h=this._domLayerInfoMap.get(c);if(h){const g=se(h.rect,o.renderUnit,m.skeleton,d.worksheet,h);h.position$.next(g)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(k.filter(e=>!!e),k.switchMap(e=>e.activeSheet$),k.filter(e=>!!e),k.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),k.filter(e=>!!e),k.switchMap(e=>l.fromEventSubject(e.render.scene.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(k.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{n(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===A.SetZoomRatioOperation.id){const a=e.params,{unitId:s}=a;Array.from((o=(t=this._domLayerMap.get(s))==null?void 0:t.keys())!=null?o:[]).forEach(m=>{n(s,m)})}else if(e.id===v.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=e.params;n(a,s)}}))}_getPosition(n,e){var g;const{startX:t,endX:o,startY:a,endY:s}=n,d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(A.ISheetSelectionRenderService);if(d==null)return;const m=d.getCellWithCoordByOffset(t,a);if(m==null)return;const u={column:m.actualColumn,columnOffset:t-m.startX,row:m.actualRow,rowOffset:a-m.startY},c=d.getCellWithCoordByOffset(o,s);if(c==null)return;const h={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:s-c.startY};return{from:u,to:h}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(n,e,t,o){const a=this._domLayerInfoMap.get(t),s=this._getSceneAndTransformerByDrawingSearch(n);if(a&&s){const{scene:d}=s,m=P.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),u=d.getObject(m);u&&u instanceof N.Rect&&u.setProps(o)}}addFloatDomToPosition(n,e){const t=v.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=t,{initPosition:s,componentKey:d,data:m,allowTransform:u=!0}=n,c=e!=null?e:l.generateRandomId(),h=this._getPosition(s,o);if(h==null)return;this._ensureMap(o,a).set(c,n);const p={unitId:o,subUnitId:a,drawingId:c,drawingType:n.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:h,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:m,allowTransform:u};return this._commandService.executeCommand(Pe.id,{unitId:o,drawings:[p]}),this._add$.next({unitId:o,subUnitId:a,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(n,e=!1){const t=this._domLayerInfoMap.get(n);if(!t)return;const{unitId:o,subUnitId:a}=t;this._domLayerInfoMap.delete(n),t.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(t.rect),e){this._ensureMap(o,a).delete(n);const m=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:n});if(!m)return;const u=this._sheetDrawingService.getBatchRemoveOp([m]),{redo:c,objects:h}=u;this._commandService.syncExecuteCommand(f.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:c,objects:h,type:f.DrawingApplyType.REMOVE})}}addHook(n){return this._hooks.push(n),{dispose:()=>{const e=this._hooks.findIndex(t=>t===n);this._hooks.splice(e,1)}}}addFloatDomToRange(n,e,t,o){var j,O,G,U,E;const a=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:d}=a,m=this._getSceneAndTransformerByDrawingSearch(s);if(!m)return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const c=(j=this._renderManagerService.getRenderById(s))==null?void 0:j.with(A.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:h,data:g,allowTransform:p=!0}=e,S=o!=null?o:l.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver(n,u,c.skeleton),C=this._getPosition(w,s);if(C==null)return;this._ensureMap(s,d).set(S,e);const R=m.scene,{scaleX:D}=R.getAncestorScale(),T=et(w,t,D),I={unitId:s,subUnitId:d,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:h,sheetTransform:C,transform:{left:T.startX,top:T.startY,width:T.width,height:T.height},data:g,allowTransform:p};{const{unitId:y,subUnitId:W,drawingId:B}=I,z=v.getSheetCommandTarget(this._univerInstanceService,{unitId:y,subUnitId:W}),K=I,_e=this._univerInstanceService.getUnit(y,l.UniverInstanceType.UNIVER_SHEET);if(!_e)return;const ae=_e.getActiveSheet().getSheetId();if(!K||!z)return;const Ie=(O=this._renderManagerService.getRenderById(y))==null?void 0:O.with(A.SheetSkeletonManagerService);if(!Ie)return;const ce=Ie.getWorksheetSkeleton(W);if(!ce)return;const{transform:re,drawingType:ie,data:J}=K;if(ie!==l.DrawingTypeEnum.DRAWING_DOM&&ie!==l.DrawingTypeEnum.DRAWING_CHART)return;const F=this._getSceneAndTransformerByDrawingSearch(y);if(F==null)return;const{scene:ye,canvas:De}=F;if(re==null||ae!==W)return;const{left:nt,top:rt,width:it,height:ot,angle:Tt,flipX:Rt,flipY:at,skewX:st,skewY:Me}=re,ct=P.getDrawingShapeKeyByDrawingSearch({unitId:y,subUnitId:W,drawingId:B}),de=ye.getObject(ct);if(de!=null){de.transformByState({left:nt,top:rt,width:it,height:ot,angle:Tt,flipX:Rt,flipY:at,skewX:st,skewY:Me});return}const te={left:nt,top:rt,width:it,height:ot,zIndex:this._drawingManagerService.getDrawingOrder(y,W).length-1},Te=ie===l.DrawingTypeEnum.DRAWING_CHART;if(Te){const L=J?J.backgroundColor:"white";te.fill=L,te.rotateEnabled=!1,J&&J.border&&(te.stroke=J.border),te.paintFirst="stroke",te.strokeWidth=1,te.borderEnabled=!1,te.radius=8}const oe=new N.Rect(ct,te);Te&&oe.setObjectType(N.ObjectType.CHART),ye.addObject(oe,N.DRAWING_OBJECT_LAYER_INDEX),K.allowTransform!==!1&&ye.attachTransformerTo(oe);const Be=this._ensureMap(y,W),le=new l.DisposableCollection,Re=ye.getMainViewport(),be={top:Re.top,left:Re.left,bottom:Re.bottom,right:Re.right},ue={dispose:le,rect:oe,boundsOfViewArea:be,domAnchor:t,unitId:y,subUnitId:W},dt=se(oe,F.renderUnit,ce.skeleton,z.worksheet,ue),fe=new k.BehaviorSubject(dt);ue.position$=fe;let Y={position$:fe,id:B,componentKey:K.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:L=>{De.dispatchEvent(new WheelEvent(L.type,L))},props:(U=(G=Be.get(B))==null?void 0:G.props)!=null?U:this._getFloatDomProps(B),data:J,unitId:y};e.eventPassThrough&&(Y={...Y,onPointerDown:L=>{De.dispatchEvent(new PointerEvent(L.type,L))},onPointerMove:L=>{De.dispatchEvent(new PointerEvent(L.type,L))},onPointerUp:L=>{De.dispatchEvent(new PointerEvent(L.type,L))}}),this._canvasFloatDomService.addFloatDom(Y),this.disposeWithMe(_.subscribe(L=>{var Ft,$t,Vt,Ht;const ut=et({rotate:0,startX:L.startX,startY:L.startY,endX:L.endX,endY:L.endY,width:(Ft=t.width)!=null?Ft:L.width,height:($t=t.height)!=null?$t:L.height,absolute:{left:w.absolute.left,top:w.absolute.top}},t),or=P.getDrawingShapeKeyByDrawingSearch({unitId:y,subUnitId:W,drawingId:B}),ar=new N.Rect(or,{left:ut.startX,top:ut.startY,width:(Vt=t.width)!=null?Vt:L.width,height:(Ht=t.height)!=null?Ht:L.height,zIndex:this._drawingManagerService.getDrawingOrder(y,W).length-1}),sr=se(ar,F.renderUnit,ce.skeleton,z.worksheet,ue);fe.next(sr)}));const ke=(E=this._renderManagerService.getRenderById(y))==null?void 0:E.with(A.SheetSkeletonManagerService);ke==null||ke.currentSkeleton$.subscribe(L=>{L&&c.sheetId!==L.sheetId&&this._removeDom(S,!0)});const lt=oe.onTransformChange$.subscribeEvent(()=>{const L=se(oe,F.renderUnit,ce.skeleton,z.worksheet,ue);fe.next(L)});le.add(()=>{this._canvasFloatDomService.removeFloatDom(B)}),lt&&le.add(lt),this._domLayerInfoMap.set(B,ue),Be.set(B,{...Be.get(B)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(n,e,t,o){var T,I,j,O,G;const a=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:d}=a;if(!this._getSceneAndTransformerByDrawingSearch(s))return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const c=(T=this._renderManagerService.getRenderById(s))==null?void 0:T.with(A.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:h,data:g,allowTransform:p=!0}=e,S=o!=null?o:l.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:n,endColumn:n},u,c.skeleton),C=w;C.startY=0;const M=this._getPosition(w,s);if(M==null)return;this._ensureMap(s,d).set(S,e);const D={unitId:s,subUnitId:d,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:h,sheetTransform:M,transform:{left:C.startX,top:C.startY,width:C.width,height:C.height},data:g,allowTransform:p};{const{unitId:U,subUnitId:E,drawingId:y}=D,W=v.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:E}),B=D,z=this._univerInstanceService.getUnit(U,l.UniverInstanceType.UNIVER_SHEET);if(!z)return;const K=z.getActiveSheet().getSheetId();if(!B||!W)return;const _e=(I=this._renderManagerService.getRenderById(U))==null?void 0:I.with(A.SheetSkeletonManagerService);if(!_e)return;const ae=_e.getWorksheetSkeleton(E);if(!ae)return;const{transform:Ie,data:ce}=B,re=this._getSceneAndTransformerByDrawingSearch(U);if(re==null)return;const{scene:ie,canvas:J}=re;if(Ie==null||K!==E)return;const{left:F,top:ye,width:De,height:nt,angle:rt,flipX:it,flipY:ot,skewX:Tt,skewY:Rt}=Ie,at=P.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:E,drawingId:y}),st=ie.getObject(at);if(st!=null){st.transformByState({left:F,top:ye,width:De,height:nt,angle:rt,flipX:it,flipY:ot,skewX:Tt,skewY:Rt});return}const Me=et({rotate:0,startX:C.startX,startY:0,endX:w.endX,endY:w.endY,width:t.width,height:t.height,absolute:{left:w.absolute.left,top:w.absolute.top}},t),ct={left:Me.startX,top:Me.startY,width:Me.width,height:Me.height,zIndex:this._drawingManagerService.getDrawingOrder(U,E).length-1},de=new N.Rect(at,ct);ie.addObject(de,N.DRAWING_OBJECT_LAYER_INDEX),B.allowTransform!==!1&&ie.attachTransformerTo(de);const te=this._ensureMap(U,E),Te=new l.DisposableCollection,oe=ie.getMainViewport(),Be={top:0,left:oe.left,bottom:oe.bottom,right:oe.right},le={dispose:Te,rect:de,unitId:U,subUnitId:E,boundsOfViewArea:Be,domAnchor:t,scrollDirectionResponse:"HORIZONTAL"},Re=se(de,re.renderUnit,ae.skeleton,W.worksheet,le),be=new k.BehaviorSubject(Re);le.position$=be;let ue={position$:be,id:y,componentKey:B.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:Y=>{J.dispatchEvent(new WheelEvent(Y.type,Y))},props:(O=(j=te.get(y))==null?void 0:j.props)!=null?O:this._getFloatDomProps(y),data:ce,unitId:U};e.eventPassThrough&&(ue={...ue,onPointerDown:Y=>{J.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{J.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{J.dispatchEvent(new PointerEvent(Y.type,Y))}}),this._canvasFloatDomService.addFloatDom(ue);const dt=de.onTransformChange$.subscribeEvent(()=>{const Y=se(de,re.renderUnit,ae.skeleton,W.worksheet,le);be.next(Y)});this.disposeWithMe(_.subscribe(Y=>{const ke=et({rotate:0,startX:Y.startX,startY:0,endX:Y.endX,endY:Y.endY,width:t.width,height:t.height,absolute:{left:w.absolute.left,top:w.absolute.top}},t),lt=P.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:E,drawingId:y}),L=new N.Rect(lt,{left:ke.startX,top:0,width:t.width,height:t.height,zIndex:this._drawingManagerService.getDrawingOrder(U,E).length-1}),ut=se(L,re.renderUnit,ae.skeleton,W.worksheet,le);be.next(ut)}));const fe=(G=this._renderManagerService.getRenderById(U))==null?void 0:G.with(A.SheetSkeletonManagerService);fe==null||fe.currentSkeleton$.subscribe(Y=>{Y&&c.sheetId!==Y.sheetId&&this._removeDom(S,!0)}),Te.add(()=>{this._canvasFloatDomService.removeFloatDom(y)}),dt&&Te.add(dt),this._domLayerInfoMap.set(y,le),te.set(y,{...te.get(y)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(n,e,t){let{startRow:o,startColumn:a}=n;const s=We(o,a,t),d=new k.BehaviorSubject(s),m=We(n.endRow,n.endColumn,t),u=new k.BehaviorSubject(m),c=()=>{const _=We(o,a,t),C=We(n.endRow,n.endColumn,t);d.next(_),u.next(C)},h=new l.DisposableCollection;h.add(e.engine.clientRect$.subscribe(()=>c())),h.add(this._commandService.onCommandExecuted(_=>{if(_.id===v.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(M=>M.row===o)>-1){c();return}(v.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===A.SetScrollOperation.id||_.id===A.SetZoomRatioOperation.id)&&c()}));const g=(_,C)=>{o=_,a=C,c()},p=()=>({rotate:0,width:m.right-s.left,height:m.bottom-s.top,absolute:{left:!0,top:!0},startX:s.left,startY:s.top,endX:m.right,endY:m.bottom}),S=d.pipe(k.map(_=>{const C=We(n.endRow,n.endColumn,t);return{rotate:0,width:C.right-_.left,height:C.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:C.right,endY:C.bottom}})),w=p();return{position$:S,position:w,updateRowCol:g,topLeftPos$:d,rightBottomPos$:u,disposable:h}}},b.SheetCanvasFloatDomManagerService=Qn([ve(0,l.Inject(N.IRenderManagerService)),ve(1,l.IUniverInstanceService),ve(2,l.Inject(l.ICommandService)),ve(3,P.IDrawingManagerService),ve(4,l.Inject(V.CanvasFloatDomService)),ve(5,f.ISheetDrawingService),ve(6,l.Inject(l.LifecycleService))],b.SheetCanvasFloatDomManagerService);function We(i,r,n){const e=n.getCellWithCoordByIndex(i,r),t=e.isMergedMainCell?e.mergeInfo:e;return{left:t.startX,right:t.endX,top:t.startY,bottom:t.endY}}function et(i,r,n){var m,u;n=n!=null?n:1;const e=i.endX-i.startX,t=i.endY-i.startY,o=(m=r==null?void 0:r.width)!=null?m:e,a=(u=r==null?void 0:r.height)!=null?u:t;let s=0,d=0;if(r){if(r.horizonOffsetAlign==="right"){const c=tt(r.marginX,e*n);s=i.endX-c-o}else s=i.startX+tt(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const c=tt(r.marginY,t*n);d=i.endY-c-a}else d=i.startY+tt(r.marginY,t)}return{rotate:0,startX:s,startY:d,endX:i.endX,endY:i.endY,width:o,height:a,absolute:{left:i.absolute.left,top:i.absolute.top}}}function tt(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const n=Number.parseFloat(i);return r*n/100}var Gt=Object.defineProperty,tr=Object.getOwnPropertyDescriptor,nr=(i,r,n)=>r in i?Gt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[r]=n,rr=(i,r,n,e)=>{for(var t=e>1?void 0:e?tr(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Gt(r,n,t),t},Mt=(i,r)=>(n,e)=>r(n,e,i),Yt=(i,r,n)=>nr(i,typeof r!="symbol"?r+"":r,n);const ir="SHEET_IMAGE_UI_PLUGIN";b.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=Et,n,e,t){super(),this._config=r,this._injector=n,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=l.merge({},Et,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Xt,a)}onStarting(){l.registerDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService],[Qe],[Ge],[ze],[xe],[Xe],[Fe],[He],[$e]]),l.touchDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[Xe]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[xe],[ze],[Qe],[Fe],[He],[$e]])}onSteady(){this._injector.get(Ge)}_registerRenderModules(){[[Ue],[It],[pt]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}},Yt(b.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),Yt(b.UniverSheetsDrawingUIPlugin,"pluginName",ir),b.UniverSheetsDrawingUIPlugin=rr([l.DependentOn(P.UniverDrawingPlugin,Se.UniverDocsDrawingPlugin,ge.UniverDrawingUIPlugin,f.UniverSheetsDrawingPlugin),Mt(1,l.Inject(l.Injector)),Mt(2,N.IRenderManagerService),Mt(3,l.IConfigService)],b.UniverSheetsDrawingUIPlugin),b.ClearSheetDrawingTransformerOperation=$,b.DeleteDrawingsCommand=Ct,b.EditSheetDrawingOperation=ht,b.GroupSheetDrawingCommand=ft,b.InsertFloatImageCommand=Je,b.InsertSheetDrawingCommand=Pe,b.MoveDrawingsCommand=Ce,b.RemoveSheetDrawingCommand=Ee,b.SHEETS_IMAGE_MENU_ID=Dt,b.SetDrawingArrangeCommand=St,b.SetSheetDrawingCommand=Ae,b.SidebarSheetDrawingOperation=gt,b.UngroupSheetDrawingCommand=wt,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
9
+ */var Pt;function zt(){if(Pt)return Pe;Pt=1;var r=J,i=Symbol.for("react.element"),n=Symbol.for("react.fragment"),e=Object.prototype.hasOwnProperty,t=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function a(s,c,m){var u,d={},h=null,g=null;m!==void 0&&(h=""+m),c.key!==void 0&&(h=""+c.key),c.ref!==void 0&&(g=c.ref);for(u in c)e.call(c,u)&&!o.hasOwnProperty(u)&&(d[u]=c[u]);if(s&&s.defaultProps)for(u in c=s.defaultProps,c)d[u]===void 0&&(d[u]=c[u]);return{$$typeof:i,type:s,key:h,ref:g,props:d,_owner:t.current}}return Pe.Fragment=n,Pe.jsx=a,Pe.jsxs=a,Pe}var At;function Jt(){return At||(At=1,pt.exports=zt()),pt.exports}var x=Jt();const Fe={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},Zt=()=>{const r=l.useDependency(P.IImageIoService),i=l.useDependency(l.LocaleService),[n,e]=J.useState(0);return J.useEffect(()=>{const t=r.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[r]),x.jsx("div",{style:{display:n>0?"block":"none"},className:Fe.uploadLoading,children:x.jsxs("div",{className:Fe.uploadLoadingBody,children:[x.jsx("div",{className:Fe.uploadLoadingBodyAnimation}),x.jsx("div",{className:Fe.uploadLoadingBodyText,children:`${i.t("uploadLoading.loading")}: ${n}`})]})})};var qt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,en=(r,i,n,e)=>{for(var t=e>1?void 0:e?Qt(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&qt(i,n,t),t},he=(r,i)=>(n,e)=>i(n,e,r);let $e=class extends l.RxDisposable{constructor(i,n,e,t,o,a,s,c){super();z(this,"_initImagePopupMenu",new Set);this._injector=i,this._drawingManagerService=n,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._commandService=c,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(i=>this._create(i)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(i=>this._dispose(i)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(i=>this._create(i)),this._uiPartsService.registerComponent($.BuiltInUIPart.CONTENT,()=>l.connectInjector(Zt,this._injector))}_dispose(i){const n=i.getUnitId();this._renderManagerService.removeRender(n)}_create(i){if(!i)return;const n=i.getUnitId();this._renderManagerService.has(n)&&!this._initImagePopupMenu.has(n)&&(this._popupMenuListener(n),this._initImagePopupMenu.add(n))}_hasCropObject(i){const n=i.getAllObjectsByOrder();for(const e of n)if(e instanceof ge.ImageCropperObject)return!0;return!1}_popupMenuListener(i){var o;const n=(o=this._renderManagerService.getRenderById(i))==null?void 0:o.scene;if(!n)return;const e=n.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(l.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(n))return;const a=e.getSelectedObjectMap();if(a.size>1){t==null||t.dispose();return}const s=a.values().next().value;if(!s)return;const c=s.oKey,m=this._drawingManagerService.getDrawingOKey(c);if(!m)return;const{unitId:u,subUnitId:d,drawingId:h,drawingType:g}=m,p=m.data;if(p&&p.disablePopup)return;t==null||t.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,d,h,g);t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:ge.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,d,h,g)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[l.FOCUSING_COMMON_DRAWINGS]===!1&&(t==null||t.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{t==null||t.dispose()}))}_getImageMenuItems(i,n,e,t){return[{label:"image-popup.edit",index:0,commandId:mt.id,commandParams:{unitId:i,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Ce.id,commandParams:{unitId:i,drawings:[{unitId:i,subUnitId:n,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ge.OpenImageCropOperation.id,commandParams:{unitId:i,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ge.ImageResetSizeOperation.id,commandParams:[{unitId:i,subUnitId:n,drawingId:e}],disable:t===l.DrawingTypeEnum.DRAWING_DOM}]}};$e=en([he(0,l.Inject(l.Injector)),he(1,P.IDrawingManagerService),he(2,l.Inject(b.SheetCanvasPopManagerService)),he(3,N.IRenderManagerService),he(4,l.IUniverInstanceService),he(5,l.IContextService),he(6,l.Inject($.IUIPartsService)),he(7,l.ICommandService)],$e);function X(r,i,n){const{from:e,to:t,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:c=0,skewY:m=0}=r,u=n.getCurrent();if(u==null)return;const d=b.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:t},n);let{left:h,top:g,width:p,height:S}=d;const f=n.getCurrentSkeleton(),_=f.rowHeaderWidth+f.columnTotalWidth,I=f.columnHeaderHeight+f.rowTotalHeight;return h+p>_&&(h=_-p),g+S>I&&(g=I-S),{flipY:o,flipX:a,angle:s,skewX:c,skewY:m,left:h,top:g,width:p,height:S}}function V(r,i){const{left:n=0,top:e=0,width:t=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:c=0,skewX:m=0,skewY:u=0}=r,d=i.getCellWithCoordByOffset(n,e);if(d==null)return;const h={column:d.actualColumn,columnOffset:N.precisionTo(n-d.startX,1),row:d.actualRow,rowOffset:N.precisionTo(e-d.startY,1)},g=i.getCellWithCoordByOffset(n+t,e+o);if(g==null)return;const p={column:g.actualColumn,columnOffset:N.precisionTo(n+t-g.startX,1),row:g.actualRow,rowOffset:N.precisionTo(e+o-g.startY,1)};return{flipY:a,flipX:s,angle:c,skewX:m,skewY:u,from:h,to:p}}var tn=Object.defineProperty,nn=Object.getOwnPropertyDescriptor,rn=(r,i,n,e)=>{for(var t=e>1?void 0:e?nn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&tn(i,n,t),t},He=(r,i)=>(n,e)=>i(n,e,r);let ft=class extends l.Disposable{constructor(r,i,n,e,t){super(),this._context=r,this._sheetDrawingService=i,this._drawingManagerService=n,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=t,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const r=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const i in r){const n=r[i];for(const e in n.data){const t=n.data[e];t.transform=X(t.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};ft=rn([He(1,w.ISheetDrawingService),He(2,P.IDrawingManagerService),He(3,l.Inject(b.ISheetSelectionRenderService)),He(4,l.Inject(b.SheetSkeletonManagerService))],ft);function on(r){const i=[];return r.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s}=e,c=N.getGroupState(0,0,t.map(d=>d.transform||{})),m=t.map(d=>{const h=d.transform||{left:0,top:0},{unitId:g,subUnitId:p,drawingId:S}=d;return{unitId:g,subUnitId:p,drawingId:S,transform:{...h,left:h.left-c.left,top:h.top-c.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:c};i.push({parent:u,children:m})}),i}function an(r){const i=[];return r.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s,transform:c={width:0,height:0}}=e;if(c==null)return;const m=t.map(d=>{const{transform:h}=d,{unitId:g,subUnitId:p,drawingId:S}=d,f=N.transformObjectOutOfGroup(h||{},c,c.width||0,c.height||0);return{unitId:g,subUnitId:p,drawingId:S,transform:f,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};i.push({parent:u,children:m})}),i}const St={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService);if(!i)return!1;const o=[];i.forEach(({parent:g,children:p})=>{o.push(g.unitId),p.forEach(S=>{o.push(S.unitId)})});const a=t.getGroupDrawingOp(i),{unitId:s,subUnitId:c,undo:m,redo:u,objects:d}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:c,objects:d,type:w.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:c,objects:an(d),type:w.DrawingApplyType.UNGROUP}},{id:H.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:c,objects:d,type:w.DrawingApplyType.GROUP}},{id:H.id,params:o}]}),!0):!1}},Ae={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{var I,M,R;const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService),o=r.get(v.SheetInterceptorService);if(!i)return!1;const a=i.drawings,s=a.map(y=>y.unitId),c=t.getBatchAddOp(a),{unitId:m,subUnitId:u,undo:d,redo:h,objects:g}=c,p=o.onCommandExecute({id:Ae.id,params:i}),S={id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:m,subUnitId:u,objects:g,type:w.DrawingApplyType.INSERT}},f={id:w.SetDrawingApplyMutation.id,params:{op:d,unitId:m,subUnitId:u,objects:g,type:w.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(I=p.preRedos)!=null?I:[],S,...p.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(M=p.preUndos)!=null?M:[],f,...p.undos,{id:H.id,params:s}],redoMutations:[...(R=p.preRedos)!=null?R:[],S,...p.redos,{id:H.id,params:s}]}),!0):!1}},wt={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService);if(!i)return!1;const t=r.get(w.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:c}=i,m={unitId:o,subUnitId:a,drawingIds:s};let u;if(c===l.ArrangeTypeEnum.forward?u=t.getForwardDrawingsOp(m):c===l.ArrangeTypeEnum.backward?u=t.getBackwardDrawingOp(m):c===l.ArrangeTypeEnum.front?u=t.getFrontDrawingsOp(m):c===l.ArrangeTypeEnum.back&&(u=t.getBackDrawingsOp(m)),u==null)return!1;const{objects:d,redo:h,undo:g}=u;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:h,unitId:o,subUnitId:a,objects:d,type:w.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:d,type:w.DrawingApplyType.ARRANGE}}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:d,type:w.DrawingApplyType.ARRANGE}}]}),!0):!1}},Ue={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService);if(!i)return!1;const{drawings:o}=i,a=t.getBatchUpdateOp(o),{unitId:s,subUnitId:c,undo:m,redo:u,objects:d}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:s,subUnitId:c,op:u,objects:d,type:w.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:c,op:m,objects:d,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[s]}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:c,op:u,objects:d,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[s]}]}),!0):!1}},_t={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService);if(!i)return!1;const o=[];i.forEach(({parent:g,children:p})=>{o.push(g.unitId),p.forEach(S=>{o.push(S.unitId)})});const a=t.getUngroupDrawingOp(i),{unitId:s,subUnitId:c,undo:m,redo:u,objects:d}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:c,objects:d,type:w.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:c,objects:on(d),type:w.DrawingApplyType.GROUP}},{id:H.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:c,objects:d,type:w.DrawingApplyType.UNGROUP}},{id:H.id,params:o}]}),!0):!1}};var sn=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,dn=(r,i,n,e)=>{for(var t=e>1?void 0:e?cn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&sn(i,n,t),t},Z=(r,i)=>(n,e)=>i(n,e,r);function ln(r,i,n){const e=n*Math.PI/180,t=Math.abs(r*Math.cos(e))+Math.abs(i*Math.sin(e)),o=Math.abs(r*Math.sin(e))+Math.abs(i*Math.cos(e));return{rotatedWidth:t,rotatedHeight:o}}function Ut(r,i,n,e,t){var I;const{rotatedHeight:o,rotatedWidth:a}=ln(n,e,t),c=r.get(N.IRenderManagerService).getRenderById(i.unitId);if(!c)return!1;const u=(I=c.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(i.subUnitId))==null?void 0:I.skeleton;if(u==null)return!1;const d=u.getCellByIndex(i.row,i.col),h=d.mergeInfo.endX-d.mergeInfo.startX-2,g=d.mergeInfo.endY-d.mergeInfo.startY-2,p=a/o,f=Math.ceil(Math.min(h,g*p))/a,_=!f||Number.isNaN(f)?.001:f;return{width:n*_,height:e*_}}let Ne=class extends l.Disposable{constructor(i,n,e,t,o,a,s,c,m,u,d,h,g){super();z(this,"_workbookSelections");this._context=i,this._skeletonManagerService=n,this._commandService=e,this._selectionRenderService=t,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=s,this._drawingManagerService=c,this._contextService=m,this._messageService=u,this._localeService=d,this._injector=g,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const i=await this._fileOpenerService.openFile({multiple:!0,accept:P.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),n=i.length;return n>P.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(P.DRAWING_IMAGE_COUNT_LIMIT))}),!1):n===0?!1:(i.forEach(async e=>await this.insertFloatImageByFile(e)),!0)}async insertCellImage(){const n=(await this._fileOpenerService.openFile({multiple:!1,accept:P.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}))[0];return n?(await this._insertCellImage(n),!0):!1}async insertFloatImageByFile(i){let n;try{n=await this._imageIoService.saveImage(i)}catch(I){const M=I.message;M===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):M===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):M===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:s,source:c,base64Cache:m}=n,{width:u,height:d,image:h}=await P.getImageSize(m||""),{width:g,height:p}=this._context.scene;this._imageIoService.addImageSourceCache(c,s,h);let S=1;if(u>P.DRAWING_IMAGE_WIDTH_LIMIT||d>P.DRAWING_IMAGE_HEIGHT_LIMIT){const I=P.DRAWING_IMAGE_WIDTH_LIMIT/u,M=P.DRAWING_IMAGE_HEIGHT_LIMIT/d;S=Math.max(I,M)}const f=this._getImagePosition(u*S,d*S,g,p);if(f==null)return;const _={unitId:t,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:c,transform:X(f,this._selectionRenderService,this._skeletonManagerService),sheetTransform:f};return this._commandService.executeCommand(Ae.id,{unitId:t,drawings:[_]})}async _insertCellImage(i){let n;try{n=await this._imageIoService.saveImage(i)}catch(f){const _=f.message;_===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):_===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):_===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const{imageId:e,imageSourceType:t,source:o,base64Cache:a}=n,{width:s,height:c,image:m}=await P.getImageSize(a||"");this._imageIoService.addImageSourceCache(o,t,m);const u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;const d=l.createDocumentModelWithStyle("",{}),h=Ut(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},s,c,0);if(!h)return!1;const g={size:{width:h.width,height:h.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},p={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:e,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t,source:o,transform:bt.docDrawingPositionToTransform(g),docTransform:g,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=l.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[p],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(d.apply(S),this._commandService.syncExecuteCommand(v.SetRangeValuesCommand.id,{value:{[u.primary.actualRow]:{[u.primary.actualColumn]:{p:d.getSnapshot(),t:1}}}})):!1}_getUnitInfo(){const i=this._context.unit,n=i.getActiveSheet(),e=i.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(i,n,e,t){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const s=b.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(s==null)return;let{startColumn:c,startRow:m,startX:u,startY:d}=s,h=!1;if(u+i>e&&(u=e-i,u<0&&(u=0,i=e),h=!0),d+n>t&&(d=t-n,d<0&&(d=0,n=t),h=!0),h){const f=this._selectionRenderService.getCellWithCoordByOffset(u,d);if(f==null)return;u=f.startX,d=f.startY,c=f.actualColumn,m=f.actualRow}const g={column:c,columnOffset:0,row:m,rowOffset:0},p=this._selectionRenderService.getCellWithCoordByOffset(u+i,d+n);if(p==null)return;const S={column:p.actualColumn,columnOffset:u+i-p.startX,row:p.actualRow,rowOffset:d+n-p.startY};return{from:g,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(i=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o}=i;this._commandService.executeCommand(wt.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(i=>{const n=[];i.length!==0&&(i.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a,drawingType:s,transform:c}=e;if(c==null)return;const m=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:a});if(m==null||m.unitId!==this._context.unitId)return;const u=V({...m.transform,...c},this._selectionRenderService);if(u==null)return;const d={...e,transform:{...m.transform,...c,...X(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};n.push(d)}),n.length>0&&this._commandService.executeCommand(Ue.id,{unitId:i[0].unitId,drawings:n}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(i=>{this._commandService.executeCommand(St.id,i);const{unitId:n,subUnitId:e,drawingId:t}=i[0].parent;this._commandService.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:e,drawingId:t}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(i=>{this._commandService.executeCommand(_t.id,i)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(i=>{i==null||i.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(i))}))}};Ne=dn([Z(1,l.Inject(b.SheetSkeletonManagerService)),Z(2,l.ICommandService),Z(3,b.ISheetSelectionRenderService),Z(4,P.IImageIoService),Z(5,$.ILocalFileService),Z(6,w.ISheetDrawingService),Z(7,P.IDrawingManagerService),Z(8,l.IContextService),Z(9,$.IMessageService),Z(10,l.Inject(l.LocaleService)),Z(11,l.Inject(v.SheetsSelectionsService)),Z(12,l.Inject(l.Injector))],Ne);var un=Object.defineProperty,gn=Object.getOwnPropertyDescriptor,hn=(r,i,n,e)=>{for(var t=e>1?void 0:e?gn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&un(i,n,t),t},we=(r,i)=>(n,e)=>i(n,e,r);function vt(r,i,n){var e,t,o,a;if(((t=(e=n==null?void 0:n.p)==null?void 0:e.body)==null?void 0:t.dataStream.length)===3&&((a=(o=n.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const s=n.p.drawings[n.p.drawingsOrder[0]],c=Ut(r,{unitId:i.unitId,subUnitId:i.subUnitId,row:i.row,col:i.col},s.docTransform.size.width,s.docTransform.size.height,s.docTransform.angle);if(c)return s.transform.width=c.width,s.transform.height=c.height,s.docTransform.size.width=c.width,s.docTransform.size.height=c.height,s.transform.left=0,s.transform.top=0,s.docTransform.positionH.posOffset=0,s.docTransform.positionV.posOffset=0,n.p.documentStyle.pageSize.width=1/0,n.p.documentStyle.pageSize.height=1/0,!0}return!1}let Ve=class extends l.Disposable{constructor(r,i,n,e,t,o,a){super(),this._commandService=r,this._sheetInterceptorService=i,this._univerInstanceService=n,this._injector=e,this._drawingManagerService=t,this._docDrawingController=o,this._editorBridgeService=a,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{let i,n=[];if(r.id===v.SetWorksheetRowHeightMutation.id){const e=r.params;n=e.ranges,i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===v.SetWorksheetColWidthMutation.id){const e=r.params;n=e.ranges,i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===v.SetWorksheetRowIsAutoHeightMutation.id){const e=r.params;n=e.ranges,i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===v.SetWorksheetRowAutoHeightMutation.id){const e=r.params;i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId}),n=e.rowsAutoHeightInfo.map(t=>({startRow:t.row,endRow:t.row,startColumn:0,endColumn:9999}))}else if(r.id===v.AddWorksheetMergeMutation.id){const e=r.params;n=e.ranges,i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===v.RemoveWorksheetMergeMutation.id){const e=r.params;n=e.ranges,i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}i&&n.length&&n.forEach(e=>{const t=l.Range.transformRange(e,i.worksheet);for(let o=t.startRow;o<=t.endRow;o++)for(let a=t.startColumn;a<=t.endColumn;a++)vt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:o,col:a},i.worksheet.getCellRaw(o,a))})}))}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(r=>{r.visible?r.visible&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{r.id===bt.ReplaceSnapshotCommand.id&&r.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(v.AFTER_CELL_EDIT,{priority:9999,handler:(r,i,n)=>(vt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:i.row,col:i.col},r),n(r))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(v.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:v.InterceptCellContentPriority.CELL_IMAGE,handler:(r,i,n)=>{var e;return r!=null&&r.p&&((e=r.p.drawingsOrder)!=null&&e.length)&&(r.interceptorStyle||(r.interceptorStyle={}),r.interceptorStyle.tr={a:0}),n(r)}}))}};Ve=hn([we(0,l.ICommandService),we(1,l.Inject(v.SheetInterceptorService)),we(2,l.IUniverInstanceService),we(3,l.Inject(l.Injector)),we(4,P.IDrawingManagerService),we(5,l.Inject(Se.DocDrawingController)),we(6,l.Inject(b.IEditorBridgeService))],Ve);var mn=Object.defineProperty,pn=Object.getOwnPropertyDescriptor,fn=(r,i,n,e)=>{for(var t=e>1?void 0:e?pn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&mn(i,n,t),t},Nt=(r,i)=>(n,e)=>i(n,e,r);let xe=class extends l.Disposable{constructor(r,i){super(),this._autoFillService=r,this._injector=i,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(r,i,n,e)=>{new l.ObjectMatrix(e).forValue((t,o,a)=>{vt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:t,col:o},a)})}}))}};xe=fn([Nt(0,l.Inject(b.IAutoFillService)),Nt(1,l.Inject(l.Injector))],xe);var Sn=Object.defineProperty,wn=Object.getOwnPropertyDescriptor,_n=(r,i,n,e)=>{for(var t=e>1?void 0:e?wn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Sn(i,n,t),t},Xe=(r,i)=>(n,e)=>i(n,e,r);let Ke=class extends l.Disposable{constructor(i,n,e,t){super();z(this,"_isSetCursor",!1);this._hoverManagerService=i,this._renderManagerService=n,this._selectionsService=e,this._drawingRenderService=t}_initHover(){}_initImageClick(){}};Ke=_n([Xe(0,l.Inject(b.HoverManagerService)),Xe(1,l.Inject(N.IRenderManagerService)),Xe(2,l.Inject(v.SheetsSelectionsService)),Xe(3,l.Inject(ge.DrawingRenderService))],Ke);const je={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(r,i)=>{var o,a;const e=(o=r.get(N.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:o.with(Ne);if(!e)return!1;const t=i==null?void 0:i.files;if(t){const s=t.map(c=>e.insertFloatImageByFile(c));return(await Promise.all(s)).every(c=>c)}else return(a=e.insertFloatImage())!=null?a:!1}},It={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:r=>{var n,e;return(e=(n=r.get(N.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(Ne).insertCellImage())!=null?e:!1}};var vn=Object.defineProperty,In=Object.getOwnPropertyDescriptor,Cn=(r,i,n,e)=>{for(var t=e>1?void 0:e?In(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&vn(i,n,t),t},We=(r,i)=>(n,e)=>i(n,e,r);const jt="image/png";function yn(r){const i=r.split(","),n=atob(i[1]),e=n.length,t=new Uint8Array(e);for(let o=0;o<e;o++)t[o]=n.charCodeAt(o);return new Blob([t],{type:jt})}function Dn(r){const i=new ClipboardItem({[jt]:yn(r)});navigator.clipboard.write([i]).catch(n=>{console.error("Could not copy image using clipboard API: ",n)})}function Mn(){function r(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const i=document.activeElement,n=r();return document.body.appendChild(n),n.focus(),()=>{n.blur(),document.body.removeChild(n),i instanceof HTMLElement&&i.focus()}}const Wt=[b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let ze=class extends l.Disposable{constructor(i,n,e,t,o){super();z(this,"_copyInfo");this._sheetClipboardService=i,this._renderManagerService=n,this._drawingService=e,this._clipboardInterfaceService=t,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(i,n,e,t)=>{const o=this._focusedDrawings;if(o.length>0){const[a]=o;if(t===b.COPY_TYPE.CUT){const c={unitId:i,drawings:[a]};this._commandService.executeCommand(Ce.id,c)}setTimeout(()=>{const c=Mn();a.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&a.imageSourceType===P.ImageSourceType.BASE64?Dn(a.source):this._clipboardInterfaceService.writeText(""),c()},200);const s={unitId:a.unitId,subUnitId:a.subUnitId,drawings:[a]};this._copyInfo=s}else{const a=this._createDrawingsCopyInfoByRange(i,n,e);this._copyInfo=a}},onPasteCells:(i,n,e,t)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=b.COPY_TYPE.COPY,pasteType:a}=t,{range:s}=i||{},{range:c,unitId:m,subUnitId:u}=n;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:a,unitId:m,subUnitId:u,pasteRange:c},{copyRange:s,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:n,pasteType:a},b.COPY_TYPE.COPY)},onPastePlainText:(i,n)=>({undos:[],redos:[]}),onPasteUnrecognized:i=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:i,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(i,n)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:i,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.COPY_TYPE.COPY);{const e=n.filter(t=>t.type.includes("image"));if(e.length)return{undos:[],redos:[{id:je.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(i,n,e){var h;const t=(h=this._renderManagerService.getRenderById(i))==null?void 0:h.with(b.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:s,startY:c,endY:m}=o,u=this._drawingService.getDrawingData(i,n),d=this._focusedDrawings.slice();if(Object.keys(u).forEach(g=>{const p=u[g],{transform:S}=p;if(p.anchorType!==w.SheetDrawingAnchorType.Both||!S)return;const{left:f=0,top:_=0,width:I=0,height:M=0}=S,{drawingStartX:R,drawingEndX:y,drawingStartY:T,drawingEndY:C}={drawingStartX:f,drawingEndX:f+I,drawingStartY:_,drawingEndY:_+M};a<=R&&y<=s&&c<=T&&C<=m&&d.push(p)}),d.length)return{copyRange:e,drawings:d,unitId:i,subUnitId:n}}_generateSingleDrawingPasteMutations(i,n){const{pasteType:e,pasteTo:t}=i;if(Wt.includes(e))return{redos:[],undos:[]};const{unitId:o,subUnitId:a,range:s}=t,c=this._renderManagerService.getRenderById(o),m=c==null?void 0:c.with(b.SheetSkeletonManagerService),u=c==null?void 0:c.with(b.ISheetSelectionRenderService),d=this._copyInfo;if(!m||!u)return{redos:[],undos:[]};const{drawings:h}=d,g=b.discreteRangeToRange(s);return this._generateMutations(h,{unitId:o,subUnitId:a,isCut:n===b.COPY_TYPE.CUT,getTransform:(p,S)=>{var I;const f=m.attachRangeWithCoord({startRow:g.startRow,endRow:g.endRow,startColumn:g.startColumn,endColumn:g.endColumn}),_={...p,left:f==null?void 0:f.startX,top:f==null?void 0:f.startY};return{transform:_,sheetTransform:(I=V(_,u))!=null?I:S}}})}_generateMutations(i,n){const{unitId:e,subUnitId:t,getTransform:o,isCut:a}=n,s=[],c=[],{_drawingService:m}=this;return i.forEach(u=>{const{transform:d,sheetTransform:h}=u;if(!d)return;const g=o(d,h),p={...u,unitId:e,subUnitId:t,drawingId:a?u.drawingId:l.Tools.generateRandomId(),transform:g.transform,sheetTransform:g.sheetTransform};if(a){const{undo:S,redo:f,objects:_}=m.getBatchUpdateOp([p]);s.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,type:w.DrawingApplyType.UPDATE,op:f,objects:_}}),c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,type:w.DrawingApplyType.UPDATE,op:S,objects:_}})}else{const{undo:S,redo:f,objects:_}=m.getBatchAddOp([p]);s.push({id:w.SetDrawingApplyMutation.id,params:{op:f,unitId:e,subUnitId:t,objects:_,type:w.DrawingApplyType.INSERT}}),c.push({id:w.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:t,objects:_,type:w.DrawingApplyType.REMOVE}})}}),{redos:s,undos:c}}_generateRangeDrawingsPasteMutations(i,n){var j;const{unitId:e,subUnitId:t,pasteType:o,pasteRange:a}=i,{copyRange:s,copyType:c}=n;if(Wt.includes(o))return{redos:[],undos:[]};const m=(j=this._renderManagerService.getRenderById(e))==null?void 0:j.with(b.SheetSkeletonManagerService);if(!m||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!s)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:t,range:b.discreteRangeToRange(a)},pasteType:o},c);const{ranges:[d,h],mapFunc:g}=b.virtualizeDiscreteRanges([s,a]),{row:p,col:S}=g(d.startRow,d.startColumn),{row:f,col:_}=g(h.startRow,h.startColumn),I=m.attachRangeWithCoord({startRow:p,endRow:p,startColumn:S,endColumn:S}),M=m.attachRangeWithCoord({startRow:f,endRow:f,startColumn:_,endColumn:_});if(!I||!M||!this._copyInfo)return{redos:[],undos:[]};const R=M.startX-I.startX,y=M.startY-I.startY,T=f-p,C=_-S;return this._generateMutations(u,{unitId:e,subUnitId:t,getTransform:(E,L)=>{var U,A;return{transform:{...E,left:((U=E==null?void 0:E.left)!=null?U:0)+R,top:((A=E==null?void 0:E.top)!=null?A:0)+y},sheetTransform:{...L,to:{...L.to,row:L.to.row+T,column:L.to.column+C},from:{...L.from,row:L.from.row+T,column:L.from.column+C}}}},isCut:c===b.COPY_TYPE.CUT})}};ze=Cn([We(0,b.ISheetClipboardService),We(1,N.IRenderManagerService),We(2,P.IDrawingManagerService),We(3,$.IClipboardInterfaceService),We(4,l.ICommandService)],ze);var Tn=Object.defineProperty,Rn=Object.getOwnPropertyDescriptor,bn=(r,i,n,e)=>{for(var t=e>1?void 0:e?Rn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Tn(i,n,t),t},Be=(r,i)=>(n,e)=>i(n,e,r);let Je=class extends l.Disposable{constructor(r,i,n,e,t){super(),this._drawingManagerService=r,this._renderManagerService=i,this._permissionService=n,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{if(!i){this._drawingManagerService.setDrawingVisible(!1);return}i.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=i.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new v.WorkbookViewPermission(t).id,new v.WorksheetViewPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const s=i.getUnitId(),c=e.getSheetId(),m=this._drawingManagerService.getDrawingData(s,c),u=Object.values(m),d=this._renderManagerService.getRenderById(s),h=d==null?void 0:d.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(p=>{p.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>p.oKey.includes(S.drawingId))&&h.removeObject(p)})}})}))}_initDrawingEditable(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{if(!i){this._drawingManagerService.setDrawingEditable(!1);return}i.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=i.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new v.WorkbookEditablePermission(t).id,new v.WorksheetEditPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const s=i.getUnitId(),c=e.getSheetId(),m=this._drawingManagerService.getDrawingData(s,c),u=Object.values(m),d=this._renderManagerService.getRenderById(s),h=d==null?void 0:d.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(p=>{p.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>p.oKey.includes(S.drawingId))&&h.detachTransformerFrom(p)})}})}))}_initViewPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{i&&i.activeSheet$.subscribe(e=>{var d;if(!e)return;const t=i.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),c=s==null?void 0:s.scene;if(c==null)return;const m=c.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookViewPermission(t).id,new v.WorksheetViewPermission(t,o).id]).pipe(W.map(h=>h.every(g=>g.value)));u==null||u.pipe(W.filter(h=>h!==a),W.distinctUntilChanged()).subscribe({next:h=>{a=h,this._drawingManagerService.setDrawingVisible(h);const g=c.getAllObjectsByOrder(),p=this._drawingManagerService.getDrawingData(t,o),S=Object.values(p);h?this._drawingManagerService.addNotification(S):(g.forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(_=>f.oKey.includes(_.drawingId))&&c.removeObject(f)}),m.clearSelectedObjects())}}),(d=this._permissionService.getPermissionPoint$(new v.WorksheetViewPermission(t,o).id))==null||d.pipe(W.filter(h=>h.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const h=this._drawingManagerService.getDrawingData(t,o),g=Object.values(h);this._drawingManagerService.addNotification(g)}})})}))}_initEditPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{i&&i.activeSheet$.subscribe(e=>{var d;if(!e)return;const t=i.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),c=s==null?void 0:s.scene;if(c==null)return;const m=c.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookEditablePermission(t).id,new v.WorksheetEditPermission(t,o).id]).pipe(W.map(h=>h.every(g=>g.value)));u==null||u.pipe(W.filter(h=>h!==a),W.distinctUntilChanged()).subscribe({next:h=>{a=h,this._drawingManagerService.setDrawingEditable(h);const g=c.getAllObjectsByOrder(),p=this._drawingManagerService.getDrawingData(t,o),S=Object.values(p);h?(g.forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(_=>f.oKey.includes(_.drawingId))&&c.attachTransformerTo(f)}),this._drawingManagerService.addNotification(S)):(g.forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(_=>f.oKey.includes(_.drawingId))&&c.detachTransformerFrom(f)}),m.clearSelectedObjects())}}),(d=this._permissionService.getPermissionPoint$(new v.WorksheetEditPermission(t,o).id))==null||d.pipe(W.filter(h=>h.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const h=i.getUnitId(),g=e.getSheetId(),p=this._drawingManagerService.getDrawingData(h,g),S=Object.values(p),f=this._renderManagerService.getRenderById(h),_=f==null?void 0:f.scene;if(_==null)return;this._drawingManagerService.setDrawingEditable(!0),_.getAllObjectsByOrder().forEach(M=>{M.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(R=>M.oKey.includes(R.drawingId))&&_.detachTransformerFrom(M)})}})})}))}};Je=bn([Be(0,P.IDrawingManagerService),Be(1,N.IRenderManagerService),Be(2,l.IPermissionService),Be(3,l.IUniverInstanceService),Be(4,l.Inject(l.UserManagerService))],Je);var En=Object.defineProperty,On=Object.getOwnPropertyDescriptor,Pn=(r,i,n,e)=>{for(var t=e>1?void 0:e?On(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&En(i,n,t),t},Ze=(r,i)=>(n,e)=>i(n,e,r);let qe=class extends l.Disposable{constructor(r,i,n,e){super(),this._sheetPrintInterceptorService=r,this._drawingRenderService=i,this._drawingManagerService=n,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(r,i,n)=>{const{unitId:e,scene:t,subUnitId:o}=i,a=this._drawingManagerService.getDrawingDataForUnit(e),s=a==null?void 0:a[o];return s&&s.order.forEach(c=>{this._drawingRenderService.renderDrawing(s.data[c],t)}),n()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(r,i,n)=>{const{unitId:e,subUnitId:t}=i,o=this._renderManagerService.getRenderById(e);if(!o)return n(r);const a=o.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(t);if(!a)return n(r);const s=this._drawingManagerService.getDrawingDataForUnit(e),c=s==null?void 0:s[i.subUnitId];if(!c)return n(r);const{scaleX:m,scaleY:u}=o.scene,d=r?{...r}:{startColumn:0,endColumn:0,endRow:0,startRow:0},h=c.order.map(g=>c.data[g]).filter(g=>g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM);return h.length?(h.forEach(g=>{if(!g.groupId&&g.transform&&l.Tools.isDefine(g.transform.left)&&l.Tools.isDefine(g.transform.top)&&l.Tools.isDefine(g.transform.width)&&l.Tools.isDefine(g.transform.height)){const p=a.skeleton.getCellIndexByOffset(g.transform.left,g.transform.top,m,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(g.transform.left+g.transform.width,g.transform.top+g.transform.height,m,u,{x:0,y:0});p.column<d.startColumn&&(d.startColumn=p.column),p.row<d.startRow&&(d.startRow=p.row),d.endRow<S.row&&(d.endRow=S.row),d.endColumn<S.column&&(d.endColumn=S.column)}}),n(d)):n(r)}}))}};qe=Pn([Ze(0,l.Inject(b.SheetPrintInterceptorService)),Ze(1,l.Inject(ge.DrawingRenderService)),Ze(2,P.IDrawingManagerService),Ze(3,N.IRenderManagerService)],qe);var An=Object.defineProperty,Un=Object.getOwnPropertyDescriptor,Nn=(r,i,n,e)=>{for(var t=e>1?void 0:e?Un(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&An(i,n,t),t},me=(r,i)=>(n,e)=>i(n,e,r);const jn=[v.InsertRowCommand.id,v.InsertColCommand.id,v.RemoveRowCommand.id,v.RemoveColCommand.id,v.DeleteRangeMoveLeftCommand.id,v.DeleteRangeMoveUpCommand.id,v.InsertRangeMoveDownCommand.id,v.InsertRangeMoveRightCommand.id,v.DeltaRowHeightCommand.id,v.SetRowHeightCommand.id,v.DeltaColumnWidthCommand.id,v.SetColWidthCommand.id,v.SetRowHiddenCommand.id,v.SetSpecificRowsVisibleCommand.id,v.SetSpecificColsVisibleCommand.id,v.SetColHiddenCommand.id,v.MoveColsCommand.id,v.MoveRowsCommand.id,v.MoveRangeCommand.id],Wn=[v.SetRowVisibleMutation.id,v.SetRowHiddenMutation.id,v.SetColVisibleMutation.id,v.SetColHiddenMutation.id,v.SetWorksheetRowHeightMutation.id,v.SetWorksheetColWidthMutation.id];let Ct=class extends l.Disposable{constructor(r,i,n,e,t,o,a,s,c){super(),this._context=r,this._renderManagerService=i,this._commandService=n,this._selectionRenderService=e,this._skeletonManagerService=t,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._univerInstanceService=c,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(!jn.includes(r.id))return{redos:[],undos:[]};if(r.params==null)return{redos:[],undos:[]};const i=r.id;if(i===v.InsertRowCommand.id)return this._moveRowInterceptor(r.params,"insert");if([v.MoveColsCommand.id,v.MoveRowsCommand.id,v.MoveRangeCommand.id].includes(i))return this._moveRangeInterceptor(r.params);if(i===v.InsertColCommand.id)return this._moveColInterceptor(r.params,"insert");if(i===v.RemoveRowCommand.id)return this._moveRowInterceptor(r.params,"remove");if(i===v.RemoveColCommand.id)return this._moveColInterceptor(r.params,"remove");if(i===v.DeleteRangeMoveLeftCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,0)}else if(i===v.DeleteRangeMoveUpCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,1)}else if(i===v.InsertRangeMoveDownCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,2)}else if(i===v.InsertRangeMoveRightCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,3)}else if(i===v.SetRowHiddenCommand.id||i===v.SetSpecificRowsVisibleCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForRowVisible(e,t,o)}else if(i===v.SetSpecificColsVisibleCommand.id||i===v.SetColHiddenCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForColVisible(e,t,o)}else if(i===v.DeltaRowHeightCommand.id||i===v.SetRowHeightCommand.id||i===v.DeltaColumnWidthCommand.id||i===v.SetColWidthCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n,a=i===v.DeltaRowHeightCommand.id||i===v.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(r,i){const n=v.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const e=n.unitId,t=n.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(e,t),c=[],m=[];if(Object.keys(s).forEach(u=>{const d=s[u],{updateDrawings:h,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(r,i,d);c.push(...h),m.push(...g)}),c.length===0&&m.length===0)return{redos:[],undos:[]};if(c.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(c),{undo:d,redo:h,objects:g}=u;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:h,objects:g,type:w.DrawingApplyType.UPDATE}}),a.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:d,objects:g,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(m),d=u.undo,h=u.redo,g=u.objects;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:h,objects:g,type:w.DrawingApplyType.REMOVE}}),a.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:d,objects:g,type:w.DrawingApplyType.INSERT}})}return o.push({id:H.id,params:[e]}),a.push({id:H.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(r,i,n){const e=[],t=[],{sheetTransform:o,anchorType:a=w.SheetDrawingAnchorType.Position,transform:s,unitId:c,subUnitId:m,drawingId:u}=n,{from:d,to:h}=o,{row:g,column:p}=d,{row:S,column:f}=h;if(o==null||s==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:_,endRow:I,startColumn:M,endColumn:R}=r;let y=null,T=null;if(i===0&&g>=_&&S<=I)if(p>=M&&f<=R)t.push({unitId:c,subUnitId:m,drawingId:u});else{const C=this._shrinkCol(o,s,M,R,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}else if(i===1&&p>=M&&f<=R)if(g>=_&&S<=I)t.push({unitId:c,subUnitId:m,drawingId:u});else{const C=this._shrinkRow(o,s,_,I,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}else if(i===2){const C=this._expandRow(o,s,_,I,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}else if(i===3){const C=this._expandCol(o,s,M,R,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}if(y!=null&&T!=null){const C=X(y,this._selectionRenderService,this._skeletonManagerService);e.push({...n,sheetTransform:y,transform:C})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(r,i,n){const e=V({...r},this._selectionRenderService);e!=null&&i.push({...n,sheetTransform:e})}_getDrawingUndoForColVisible(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:h,transform:g,anchorType:p=w.SheetDrawingAnchorType.Position}=d;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,d);else{const{from:S,to:f}=h,{row:_,column:I}=S,{row:M,column:R}=f;for(let y=0;y<n.length;y++){const T=n[y],{startRow:C,endRow:j,startColumn:E,endColumn:L}=T;if(R<E)continue;if(p===w.SheetDrawingAnchorType.Position){let D=null,B=null;if(I>=E&&I<=L){const k=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:L,startRow:S.row,endRow:f.row});if(k==null)return;B={...g,left:k.startX}}if(B!=null&&(D=V(B,this._selectionRenderService),D!=null&&B!=null)){t.push({...d,sheetTransform:D,transform:B});break}this._remainDrawingSize(g,t,d);continue}if(I>=E&&R<=L)continue;let U=null,A=null;if(I>=E&&I<=L){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:L,startRow:S.row,endRow:f.row});if(D==null)return;A={...g,left:(D==null?void 0:D.startX)||0,width:((g==null?void 0:g.width)||0)-D.endX+D.startX}}else if(R>=E&&R<=L){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:R,startRow:S.row,endRow:f.row});if(D==null)return;A={...g,left:D.startX-((g==null?void 0:g.width)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:L,startRow:S.row,endRow:f.row});if(D==null)return;if(A={...g,width:((g==null?void 0:g.width)||0)-D.endX+D.startX},U=V(A,this._selectionRenderService),U!=null&&A!=null){o.push({...d,sheetTransform:U,transform:A});break}}if(A!=null&&(U=V(A,this._selectionRenderService)),A!=null&&U!=null){t.push({...d,sheetTransform:U,transform:A});break}else this._remainDrawingSize(g,t,d)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(r,i,t),c=[],m=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(r,i,o);c.push(...u),m.push(...d)}return{redos:a,undos:s,preRedos:c,preUndos:m}}_createUndoAndRedoMutation(r,i,n){const e=this._sheetDrawingService.getBatchUpdateOp(n),{undo:t,redo:o,objects:a}=e,s=[{id:w.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,op:o,objects:a,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[r]}],c=[{id:w.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,op:t,objects:a,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[r]}];return{redos:s,undos:c}}_getDrawingUndoForRowVisible(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:h,transform:g,anchorType:p=w.SheetDrawingAnchorType.Position}=d;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,d);else{const{from:S,to:f}=h,{row:_,column:I}=S,{row:M,column:R}=f;for(let y=0;y<n.length;y++){const T=n[y],{startRow:C,endRow:j,startColumn:E,endColumn:L}=T;if(M<C)continue;if(p===w.SheetDrawingAnchorType.Position){let D=null,B=null;if(_>=C&&_<=j){const k=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:_,endRow:j});if(k==null)return;B={...g,top:k.startY}}if(B!=null&&(D=V(B,this._selectionRenderService),D!=null&&B!=null)){t.push({...d,sheetTransform:D,transform:B});break}this._remainDrawingSize(g,t,d);continue}if(_>=C&&M<=j)continue;let U=null,A=null;if(_>=C&&_<=j){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:_,endRow:j});if(D==null)return;A={...g,top:(D==null?void 0:D.startY)||0,height:((g==null?void 0:g.height)||0)-D.endY+D.startY}}else if(M>=C&&M<=j){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:C,endRow:M});if(D==null)return;A={...g,top:D.startY-((g==null?void 0:g.height)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:C,endRow:j});if(D==null)return;if(A={...g,height:((g==null?void 0:g.height)||0)-D.endY+D.startY},U=V(A,this._selectionRenderService),U!=null&&A!=null){o.push({...d,sheetTransform:U,transform:A});break}}if(A!=null&&(U=V(A,this._selectionRenderService)),A!=null&&U!=null){t.push({...d,sheetTransform:U,transform:A});break}else this._remainDrawingSize(g,t,d)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(r,i,t),c=[],m=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(r,i,o);c.push(...u),m.push(...d)}return{redos:a,undos:s,preRedos:c,preUndos:m}}_getDrawingUndoForRowAndColSize(r,i,n,e){const t=this._drawingManagerService.getDrawingData(r,i),o=[];return Object.keys(t).forEach(a=>{const s=t[a],{sheetTransform:c,transform:m,anchorType:u=w.SheetDrawingAnchorType.Position}=s;if(u===w.SheetDrawingAnchorType.None)this._remainDrawingSize(m,o,s);else{const{from:d,to:h}=c,{row:g,column:p}=d,{row:S,column:f}=h;for(let _=0;_<n.length;_++){const I=n[_],{startRow:M,endRow:R,startColumn:y,endColumn:T}=I;if(S<M||f<y)continue;if(u===w.SheetDrawingAnchorType.Position&&(g<=M&&S>=R||p<=y&&f>=T)){this._remainDrawingSize(m,o,s);continue}const C=X({...c},this._selectionRenderService,this._skeletonManagerService);if(C!=null){o.push({...s,transform:C});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(r,i,o)}_getUnitIdAndSubUnitId(r,i){let n,e;if(i==="insert")n=r.unitId,e=r.subUnitId;else{const t=v.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;n=t.unitId,e=t.subUnitId}return{unitId:n,subUnitId:e}}_moveRangeInterceptor(r){var M,R;const{toRange:i,fromRange:n}=r,e=v.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,a=(R=(M=this._renderManagerService.getRenderById(t))==null?void 0:M.with(b.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=b.attachRangeWithCoord(a,n);if(!s)return{redos:[],undos:[]};const{startX:c,endX:m,startY:u,endY:d}=s,h=this._sheetDrawingService.getDrawingData(t,o),g=[];Object.keys(h).forEach(y=>{const T=h[y];if(T.anchorType!==w.SheetDrawingAnchorType.Both)return;const{transform:C}=T;if(!C)return;const{left:j=0,top:E=0,width:L=0,height:U=0}=C,{drawingStartX:A,drawingEndX:D,drawingStartY:B,drawingEndY:k}={drawingStartX:j,drawingEndX:j+L,drawingStartY:E,drawingEndY:E+U};c<=A&&D<=m&&u<=B&&k<=d&&g.push(T)});const p=[],S=[],f=i.startRow-n.startRow,_=i.startColumn-n.startColumn,I=g.map(y=>{const T=y.sheetTransform,C={to:{...T.to,row:T.to.row+f,column:T.to.column+_},from:{...T.from,row:T.from.row+f,column:T.from.column+_}},j=X(C,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:y.drawingId,transform:j,sheetTransform:C}});if(I.length){const y=this._sheetDrawingService.getBatchUpdateOp(I),{undo:T,redo:C,objects:j}=y;p.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:C,objects:j,type:w.DrawingApplyType.UPDATE}}),S.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:T,objects:j,type:w.DrawingApplyType.UPDATE}})}return{redos:p,undos:S}}_moveRowInterceptor(r,i){const n=this._getUnitIdAndSubUnitId(r,i);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=r,a=o.startRow,s=o.endRow,c=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),d=[],h=[];if(Object.keys(u).forEach(g=>{const p=u[g],{sheetTransform:S,transform:f,anchorType:_=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let I,M;if(i==="insert"){const y=this._expandRow(S,f,a,s,_);I=y==null?void 0:y.newSheetTransform,M=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{row:C}=y,{row:j}=T;if(_===w.SheetDrawingAnchorType.Both&&C>=a&&j<=s)h.push({unitId:e,subUnitId:t,drawingId:g});else{const E=this._shrinkRow(S,f,a,s,_);I=E==null?void 0:E.newSheetTransform,M=E==null?void 0:E.newTransform}}if(!I||!M)return;const R={unitId:e,subUnitId:t,drawingId:g,transform:M,sheetTransform:I};d.push(R)}),d.length===0&&h.length===0)return{redos:[],undos:[]};if(d.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(d),{undo:p,redo:S,objects:f}=g;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),p=g.undo,S=g.redo,f=g.objects;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return c.push({id:H.id,params:[e]}),m.push({id:H.id,params:[e]}),{redos:c,undos:m}}_moveColInterceptor(r,i){const n=this._getUnitIdAndSubUnitId(r,i);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=r,a=o.startColumn,s=o.endColumn,c=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),d=[],h=[];if(Object.keys(u).forEach(g=>{const p=u[g],{sheetTransform:S,transform:f,anchorType:_=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let I,M;if(i==="insert"){const y=this._expandCol(S,f,a,s,_);I=y==null?void 0:y.newSheetTransform,M=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{column:C}=y,{column:j}=T;if(_===w.SheetDrawingAnchorType.Both&&C>=a&&j<=s)h.push({unitId:e,subUnitId:t,drawingId:g});else{const E=this._shrinkCol(S,f,a,s,_);I=E==null?void 0:E.newSheetTransform,M=E==null?void 0:E.newTransform}}if(!I||!M)return;const R={unitId:e,subUnitId:t,drawingId:g,transform:M,sheetTransform:I};d.push(R)}),d.length===0&&h.length===0)return{redos:[],undos:[]};if(d.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(d),{undo:p,redo:S,objects:f}=g;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),p=g.undo,S=g.redo,f=g.objects;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return c.push({id:H.id,params:[e]}),m.push({id:H.id,params:[e]}),{redos:c,undos:m}}_expandCol(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{column:c}=a,{column:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,d=null;if(c>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:e,startRow:a.row,endRow:s.row});if(h==null)return;d={...i,left:(i.left||0)+h.endX-h.startX},u=V(d,this._selectionRenderService)}else if(m>=e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m+o}},d=X(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkCol(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{column:c}=a,{column:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,d=null;if(c>e)u={from:{...a,column:c-o},to:{...s,column:m-o}},d=X(u,this._selectionRenderService,this._skeletonManagerService);else{if(c>=n&&m<=e)return null;if(c<n&&m>e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m-o}},d=X(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};else if(c>=n&&c<=e){if(c===n)d={...i,left:(i.left||0)-r.from.columnOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:c-1,startRow:a.row,endRow:s.row});if(h==null)return;d={...i,left:(i.left||0)-h.endX+h.startX-r.from.columnOffset}}u=V(d,this._selectionRenderService)}else if(m>=n&&m<=e&&t===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n-1,endColumn:n-1,startRow:a.row,endRow:s.row});if(h==null)return;u={from:{...a},to:{...s,column:n-1,columnOffset:h.endX-h.startX}},d=X(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_expandRow(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{row:c}=a,{row:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,d=null;if(c>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:e,startColumn:a.column,endColumn:s.column});if(h==null)return;d={...i,top:(i.top||0)+h.endY-h.startY},u=V(d,this._selectionRenderService)}else if(m>=e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m+o}},d=X(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkRow(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{row:c}=a,{row:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,d=null;if(c>e)u={from:{...a,row:c-o},to:{...s,row:m-o}},d=X(u,this._selectionRenderService,this._skeletonManagerService);else{if(c>=n&&m<=e)return null;if(c<n&&m>e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m-o}},d=X(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};else if(c>=n&&c<=e){if(c===n)d={...i,top:(i.top||0)-r.from.rowOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:c-1,startColumn:a.column,endColumn:s.column});if(h==null)return;d={...i,top:(i.top||0)-h.endY+h.startY-r.from.rowOffset}}u=V(d,this._selectionRenderService)}else if(m>=n&&m<=e&&t===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:n-1,endRow:n-1});if(h==null)return;u={from:{...a},to:{...s,row:n-1,rowOffset:h.endY-h.startY}},d=X(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{r.id===v.SetWorksheetActiveOperation.id&&setTimeout(()=>{const i=r.params,{unitId:n,subUnitId:e}=i,t=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(t).forEach(s=>{const c=t[s];c!=null&&Object.keys(c).forEach(m=>{const u=c[m].data;u!=null&&Object.keys(u).forEach(d=>{if(s===n&&m===e){const h=u[d];h.transform=X(h.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(u[d])}else a.push(u[d])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{Wn.includes(r.id)&&requestIdleCallback(()=>{const i=r.params,{unitId:n,subUnitId:e,ranges:t}=i;this._refreshDrawingTransform(n,e,t)})}))}_refreshDrawingTransform(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:s,transform:c,anchorType:m=w.SheetDrawingAnchorType.Position}=a;if(m===w.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=s,{row:h,column:g}=u,{row:p,column:S}=d;for(let f=0;f<n.length;f++){const _=n[f],{startRow:I,endRow:M,startColumn:R,endColumn:y}=_;if(l.Rectangle.intersects({startRow:I,endRow:M,startColumn:R,endColumn:y},{startRow:h,endRow:p,startColumn:g,endColumn:S})||h>M||g>y){const T=m===w.SheetDrawingAnchorType.Position,C=X(s,this._selectionRenderService,this._skeletonManagerService);t.push({...a,transform:{...C,width:T?c==null?void 0:c.width:C==null?void 0:C.width,height:T?c==null?void 0:c.height:C==null?void 0:C.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(H.id,[r]))}};Ct=Nn([me(1,N.IRenderManagerService),me(2,l.ICommandService),me(3,b.ISheetSelectionRenderService),me(4,l.Inject(b.SheetSkeletonManagerService)),me(5,l.Inject(v.SheetInterceptorService)),me(6,w.ISheetDrawingService),me(7,P.IDrawingManagerService),me(8,l.IUniverInstanceService)],Ct);var q=function(){return q=Object.assign||function(r){for(var i,n=1,e=arguments.length;n<e;n++){i=arguments[n];for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&(r[t]=i[t])}return r},q.apply(this,arguments)},Bn=function(r,i){var n={};for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&i.indexOf(e)<0&&(n[e]=r[e]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(r);t<e.length;t++)i.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(r,e[t])&&(n[e[t]]=r[e[t]]);return n},Bt=J.forwardRef(function(r,i){var n=r.icon,e=r.id,t=r.className,o=r.extend,a=Bn(r,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),c=J.useRef("_".concat(Yn()));return kt(n,"".concat(e),{defIds:n.defIds,idSuffix:c.current},q({ref:i,className:s},a),o)});function kt(r,i,n,e,t){return J.createElement(r.tag,q(q({key:i},kn(r,n,t)),e),(Ln(r,n).children||[]).map(function(o,a){return kt(o,"".concat(i,"-").concat(r.tag,"-").concat(a),n,void 0,t)}))}function kn(r,i,n){var e=q({},r.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var t=i.defIds;return!t||t.length===0||(r.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+i.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(i.idSuffix,")")))})),e}function Ln(r,i){var n,e=i.defIds;return!e||e.length===0?r:r.tag==="defs"&&(!((n=r.children)===null||n===void 0)&&n.length)?q(q({},r),{children:r.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?q(q({},t),{attrs:q(q({},t.attrs),{id:t.attrs.id+i.idSuffix})}):t})}):r}function Yn(){return Math.random().toString(36).substring(2,8)}Bt.displayName="UniverIcon";var Gn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z"}}]},Lt=J.forwardRef(function(r,i){return J.createElement(Bt,Object.assign({},r,{id:"add-image-single",ref:i,icon:Gn}))});Lt.displayName="AddImageSingle";const yt={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:r=>{const i=r.get(l.ICommandService),e=r.get(w.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(a=>{const{unitId:s,subUnitId:c,drawingId:m,drawingType:u}=a;return{unitId:s,subUnitId:c,drawingId:m,drawingType:u}});return i.executeCommand(Ce.id,{unitId:t,drawings:o})}},ye={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(w.ISheetDrawingService),t=r.get(b.ISheetSelectionRenderService),{direction:o}=i,a=e.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,c=a.map(u=>{const{transform:d}=u;if(d==null)return null;const h={...d},{left:g=0,top:p=0}=d;return o===l.Direction.UP?h.top=p-1:o===l.Direction.DOWN?h.top=p+1:o===l.Direction.LEFT?h.left=g-1:o===l.Direction.RIGHT&&(h.left=g+1),{...u,transform:h,sheetTransform:V(h,t)}}).filter(u=>u!=null);return n.syncExecuteCommand(Ue.id,{unitId:s,drawings:c})?(n.syncExecuteCommand(H.id,[s]),!0):!1}},Yt="addition-and-subtraction-single",Dt="sheet.menu.image";function Fn(r){return{id:Dt,type:$.MenuItemType.SUBITEMS,icon:Yt,tooltip:"sheetImage.title",hidden$:$.getMenuHiddenObservable(r,l.UniverInstanceType.UNIVER_SHEET),disabled$:b.getCurrentRangeDisable$(r,{workbookTypes:[v.WorkbookEditablePermission],worksheetTypes:[v.WorksheetEditPermission],rangeTypes:[v.RangeProtectionPermissionEditPoint]})}}function $n(r){return{id:je.id,title:"sheetImage.upload.float",type:$.MenuItemType.BUTTON,hidden$:$.getMenuHiddenObservable(r,l.UniverInstanceType.UNIVER_SHEET)}}function Hn(r){return{id:It.id,title:"sheetImage.upload.cell",type:$.MenuItemType.BUTTON}}const pe={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelSubtitle:"univer-image-common-panel-subtitle",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"};function Gt(r){var i,n,e="";if(typeof r=="string"||typeof r=="number")e+=r;else if(typeof r=="object")if(Array.isArray(r)){var t=r.length;for(i=0;i<t;i++)r[i]&&(n=Gt(r[i]))&&(e&&(e+=" "),e+=n)}else for(n in r)r[n]&&(e&&(e+=" "),e+=n);return e}function Qe(){for(var r,i,n=0,e="",t=arguments.length;n<t;n++)(r=arguments[n])&&(i=Gt(r))&&(e&&(e+=" "),e+=i);return e}const Vn=r=>{var M;const i=l.useDependency(l.ICommandService),n=l.useDependency(l.LocaleService),e=l.useDependency(P.IDrawingManagerService),t=l.useDependency(N.IRenderManagerService),{drawings:o}=r,a=o[0];if(a==null)return;const{unitId:s}=a,c=t.getRenderById(s),m=c==null?void 0:c.scene;if(m==null)return;const u=m.getTransformerByCreate(),[d,h]=J.useState(!0),g=(M=a.anchorType)!=null?M:w.SheetDrawingAnchorType.Position,[p,S]=J.useState(g);function f(R,y){const T=[];return R.forEach(C=>{const{oKey:j}=C,E=y.getDrawingOKey(j);if(E==null)return T.push(null),!0;const{unitId:L,subUnitId:U,drawingId:A,drawingType:D,anchorType:B,sheetTransform:k}=E;T.push({unitId:L,subUnitId:U,drawingId:A,anchorType:B,sheetTransform:k,drawingType:D})}),T}J.useEffect(()=>{const R=u.clearControl$.subscribe(T=>{T===!0&&h(!1)}),y=u.changeStart$.subscribe(T=>{var E;const{objects:C}=T,j=f(C,e);if(j.length===0)h(!1);else if(j.length>=1){h(!0);const L=((E=j[0])==null?void 0:E.anchorType)||w.SheetDrawingAnchorType.Position;S(L)}});return()=>{y.unsubscribe(),R.unsubscribe()}},[]);function _(R){S(R);const y=e.getFocusDrawings();if(y.length===0)return;const T=y.map(C=>({unitId:C.unitId,subUnitId:C.subUnitId,drawingId:C.drawingId,anchorType:R}));i.executeCommand(Ue.id,{unitId:y[0].unitId,drawings:T})}const I=R=>R?"block":"none";return x.jsxs("div",{className:Qe(pe.imageCommonPanelGrid,pe.imageCommonPanelBorder),style:{display:I(d)},children:[x.jsx("div",{className:pe.imageCommonPanelRow,children:x.jsx("div",{className:Qe(pe.imageCommonPanelColumn,pe.imageCommonPanelTitle),children:x.jsx("div",{children:n.t("drawing-anchor.title")})})}),x.jsx("div",{className:Qe(pe.imageCommonPanelRow),children:x.jsx("div",{className:Qe(pe.imageCommonPanelColumn),children:x.jsxs(ee.RadioGroup,{value:p,onChange:_,direction:"vertical",children:[x.jsx(ee.Radio,{value:w.SheetDrawingAnchorType.Both,children:n.t("drawing-anchor.both")}),x.jsx(ee.Radio,{value:w.SheetDrawingAnchorType.Position,children:n.t("drawing-anchor.position")}),x.jsx(ee.Radio,{value:w.SheetDrawingAnchorType.None,children:n.t("drawing-anchor.none")})]})})})]})},xn=()=>{const r=l.useDependency(P.IDrawingManagerService),i=r.getFocusDrawings(),[n,e]=J.useState(i);return J.useEffect(()=>{const t=r.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(n!=null&&n.length)&&x.jsxs("div",{className:pe.imageCommonPanel,children:[x.jsx(ge.DrawingCommonPanel,{drawings:n}),x.jsx(Vn,{drawings:n})]})},Xn={[$.RibbonStartGroup.FORMULAS_INSERT]:{[Dt]:{order:3,menuItemFactory:Fn,[je.id]:{order:0,menuItemFactory:$n},[It.id]:{order:1,menuItemFactory:Hn}}}};function ke(r){return!r.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!r.getContextValue(l.EDITOR_ACTIVATED)&&!r.getContextValue(l.FOCUSING_PANEL_EDITOR)&&r.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const Kn={id:ye.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_DOWN,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.DOWN}},zn={id:ye.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_UP,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.UP}},Jn={id:ye.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_LEFT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.LEFT}},Zn={id:ye.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_RIGHT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.RIGHT}},qn={id:yt.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:ke,binding:$.KeyCode.DELETE,mac:$.KeyCode.BACKSPACE};var Qn=Object.defineProperty,ei=Object.getOwnPropertyDescriptor,ti=(r,i,n,e)=>{for(var t=e>1?void 0:e?ei(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Qn(i,n,t),t},De=(r,i)=>(n,e)=>i(n,e,r);let et=class extends l.Disposable{constructor(r,i,n,e,t,o){super(),this._componentManager=r,this._menuManagerService=i,this._commandService=n,this._shortcutService=e,this._drawingManagerService=t,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const r=this._componentManager;this.disposeWithMe(r.register(Yt,Lt)),this.disposeWithMe(r.register(Ot,xn))}_initMenus(){this._menuManagerService.mergeMenu(Xn)}_initCommands(){[je,It,Ae,Ce,Ue,ht,H,mt,St,_t,ye,yt,wt].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_initShortcuts(){[Kn,zn,Jn,Zn,qn].forEach(r=>{this.disposeWithMe(this._shortcutService.registerShortcut(r))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};et=ti([De(0,l.Inject($.ComponentManager)),De(1,$.IMenuManagerService),De(2,l.ICommandService),De(3,$.IShortcutService),De(4,P.IDrawingManagerService),De(5,l.Inject(v.SheetsSelectionsService))],et);var ni=Object.defineProperty,ii=Object.getOwnPropertyDescriptor,ri=(r,i,n,e)=>{for(var t=e>1?void 0:e?ii(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&ni(i,n,t),t},_e=(r,i)=>(n,e)=>i(n,e,r);function oi(r,i,n,e,t){const{scaleX:o,scaleY:a}=i.getAncestorScale(),s=i.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN),c={left:!0,top:!0};if(!s)return{...r,absolute:c};const{left:m,right:u,top:d,bottom:h}=r;let{top:g,left:p,viewportScrollX:S,viewportScrollY:f}=s;const{boundsOfViewArea:_,scrollDirectionResponse:I}=t||{};_&&(l.Tools.isDefine(_.top)&&(g=_.top),l.Tools.isDefine(_.left)&&(p=_.left)),I==="HORIZONTAL"&&(f=0),I==="VERTICAL"&&(S=0);let M,R;m<p?(c.left=!0,M=(p+(m-p))*o,R=Math.max(Math.min((p+(u-p))*o,p*o),(u-S)*o)):(c.left=!1,M=Math.max((m-S)*o,p*o),R=Math.max((u-S)*o,p*o));let y,T;return d<g?(c.top=!0,y=(g+(d-g))*a,T=Math.max(Math.min((g+(u-g))*a,g*a),(h-f)*a)):(c.top=!1,y=Math.max((d-f)*a,g*a),T=Math.max((h-f)*a,g*a)),{left:M,right:R,top:y,bottom:T,absolute:c}}const se=(r,i,n,e,t)=>{const{scene:o}=i,{left:a,top:s,width:c,height:m,angle:u}=r,d={left:a,right:a+c,top:s,bottom:s+m},h=oi(d,o,n,e,t),{scaleX:g,scaleY:p}=o.getAncestorScale();return{startX:h.left,endX:h.right,startY:h.top,endY:h.bottom,rotate:u,width:c*g,height:m*p,absolute:h.absolute}};O.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(n,e,t,o,a,s,c){super();z(this,"_domLayerMap",new Map);z(this,"_domLayerInfoMap",new Map);z(this,"_transformChange$",new W.Subject);z(this,"transformChange$",this._transformChange$.asObservable());z(this,"_add$",new W.Subject);z(this,"add$",this._add$.asObservable());z(this,"_remove$",new W.Subject);z(this,"remove$",this._remove$.asObservable());z(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=s,this._lifecycleService=c,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(W.filter(n=>n===l.LifecycleStages.Rendered),W.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(n,e){let t=this._domLayerMap.get(n);t||(t=new Map,this._domLayerMap.set(n,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(n){return this._domLayerInfoMap.get(n)}_getSceneAndTransformerByDrawingSearch(n){if(n==null)return;const e=this._renderManagerService.getRenderById(n),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:t,transformer:o,renderUnit:e,canvas:a}}_getFloatDomProps(n){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(n)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(n=>{n.forEach(e=>{var ne,ie,K;const{unitId:t,subUnitId:o,drawingId:a}=e,s=v.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),c=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(t,l.UniverInstanceType.UNIVER_SHEET);if(!m)return;const u=m.getActiveSheet().getSheetId();if(!c||!s)return;const d=(ne=this._renderManagerService.getRenderById(t))==null?void 0:ne.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!d)return;const{transform:h,drawingType:g,data:p}=c;if(g!==l.DrawingTypeEnum.DRAWING_DOM&&g!==l.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(t);if(S==null)return;const{scene:f,canvas:_}=S;if(h==null)return!0;if(u!==o)return;const{left:I,top:M,width:R,height:y,angle:T,flipX:C,flipY:j,skewX:E,skewY:L}=h,U=P.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),A=f.getObject(U);if(A!=null){A.transformByState({left:I,top:M,width:R,height:y,angle:T,flipX:C,flipY:j,skewX:E,skewY:L});return}const D={left:I,top:M,width:R,height:y,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},B=g===l.DrawingTypeEnum.DRAWING_CHART;if(B){const F=p?p.backgroundColor:"white";D.fill=F,D.rotateEnabled=!1,p&&p.border&&(D.stroke=p.border),D.paintFirst="stroke",D.strokeWidth=1,D.borderEnabled=!1,D.radius=8}const k=new N.Rect(U,D);B&&k.setObjectType(N.ObjectType.CHART),f.addObject(k,N.DRAWING_OBJECT_LAYER_INDEX),c.allowTransform!==!1&&f.attachTransformerTo(k);const te=this._ensureMap(t,o),oe=new l.DisposableCollection,ve=se(k,S.renderUnit,d.skeleton,s.worksheet),ae=new W.BehaviorSubject(ve),Ie={dispose:oe,rect:k,position$:ae,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:ae,id:a,componentKey:c.componentKey,onPointerDown:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onWheel:F=>{_.dispatchEvent(new WheelEvent(F.type,F))},props:(K=(ie=te.get(a))==null?void 0:ie.props)!=null?K:this._getFloatDomProps(a),data:p,unitId:t});const ce=k.onTransformChange$.subscribeEvent(()=>{const F=se(k,S.renderUnit,d.skeleton,s.worksheet);ae.next(F)});oe.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),ce&&oe.add(ce),this._domLayerInfoMap.set(a,Ie),te.set(a,{...te.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a}=e,s=P.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),c=this._getSceneAndTransformerByDrawingSearch(t);if(c==null)return;const{transformer:m,scene:u}=c,d=u.getObject(s);d!=null&&d.oKey&&m.clearControlByIds([d==null?void 0:d.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,t),s=Array.from(a.keys()),c=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),m=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(t);!o||!c||!m||s.forEach(d=>{const h=this._domLayerInfoMap.get(d);if(h){const g=se(h.rect,o.renderUnit,m.skeleton,c.worksheet,h);h.position$.next(g)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.filter(e=>!!e),W.switchMap(e=>e.activeSheet$),W.filter(e=>!!e),W.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),W.filter(e=>!!e),W.switchMap(e=>l.fromEventSubject(e.render.scene.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(W.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{n(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===b.SetZoomRatioOperation.id){const a=e.params,{unitId:s}=a;Array.from((o=(t=this._domLayerMap.get(s))==null?void 0:t.keys())!=null?o:[]).forEach(m=>{n(s,m)})}else if(e.id===v.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=e.params;n(a,s)}}))}_getPosition(n,e){var g;const{startX:t,endX:o,startY:a,endY:s}=n,c=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(b.ISheetSelectionRenderService);if(c==null)return;const m=c.getCellWithCoordByOffset(t,a);if(m==null)return;const u={column:m.actualColumn,columnOffset:t-m.startX,row:m.actualRow,rowOffset:a-m.startY},d=c.getCellWithCoordByOffset(o,s);if(d==null)return;const h={column:d.actualColumn,columnOffset:o-d.startX,row:d.actualRow,rowOffset:s-d.startY};return{from:u,to:h}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(n,e,t,o){const a=this._domLayerInfoMap.get(t),s=this._getSceneAndTransformerByDrawingSearch(n);if(a&&s){const{scene:c}=s,m=P.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),u=c.getObject(m);u&&u instanceof N.Rect&&u.setProps(o)}}addFloatDomToPosition(n,e){const t=v.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=t,{initPosition:s,componentKey:c,data:m,allowTransform:u=!0}=n,d=e!=null?e:l.generateRandomId(),h=this._getPosition(s,o);if(h==null)return;this._ensureMap(o,a).set(d,n);const p={unitId:o,subUnitId:a,drawingId:d,drawingType:n.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:c,sheetTransform:h,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:m,allowTransform:u};return this._commandService.executeCommand(Ae.id,{unitId:o,drawings:[p]}),this._add$.next({unitId:o,subUnitId:a,id:d}),{id:d,dispose:()=>{this._removeDom(d,!0)}}}_removeDom(n,e=!1){const t=this._domLayerInfoMap.get(n);if(!t)return;const{unitId:o,subUnitId:a}=t;this._domLayerInfoMap.delete(n),t.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(t.rect),e){this._ensureMap(o,a).delete(n);const m=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:n});if(!m)return;const u=this._sheetDrawingService.getBatchRemoveOp([m]),{redo:d,objects:h}=u;this._commandService.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:d,objects:h,type:w.DrawingApplyType.REMOVE})}}addHook(n){return this._hooks.push(n),{dispose:()=>{const e=this._hooks.findIndex(t=>t===n);this._hooks.splice(e,1)}}}addFloatDomToRange(n,e,t,o){var j,E,L,U,A;const a=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:c}=a,m=this._getSceneAndTransformerByDrawingSearch(s);if(!m)return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(j=this._renderManagerService.getRenderById(s))==null?void 0:j.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(c);if(!d)return;const{componentKey:h,data:g,allowTransform:p=!0}=e,S=o!=null?o:l.generateRandomId(),{position:f,position$:_}=this._createRangePositionObserver(n,u,d.skeleton),I=this._getPosition(f,s);if(I==null)return;this._ensureMap(s,c).set(S,e);const R=m.scene,{scaleX:y}=R.getAncestorScale(),T=tt(f,t,y),C={unitId:s,subUnitId:c,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:h,sheetTransform:I,transform:{left:T.startX,top:T.startY,width:T.width,height:T.height},data:g,allowTransform:p};{const{unitId:D,subUnitId:B,drawingId:k}=C,te=v.getSheetCommandTarget(this._univerInstanceService,{unitId:D,subUnitId:B}),oe=C,ve=this._univerInstanceService.getUnit(D,l.UniverInstanceType.UNIVER_SHEET);if(!ve)return;const ae=ve.getActiveSheet().getSheetId();if(!oe||!te)return;const Ie=(E=this._renderManagerService.getRenderById(D))==null?void 0:E.with(b.SheetSkeletonManagerService);if(!Ie)return;const ce=Ie.getWorksheetSkeleton(B);if(!ce)return;const{transform:ne,drawingType:ie,data:K}=oe;if(ie!==l.DrawingTypeEnum.DRAWING_DOM&&ie!==l.DrawingTypeEnum.DRAWING_CHART)return;const F=this._getSceneAndTransformerByDrawingSearch(D);if(F==null)return;const{scene:Me,canvas:Te}=F;if(ne==null||ae!==B)return;const{left:it,top:rt,width:ot,height:at,angle:Tt,flipX:Rt,flipY:st,skewX:ct,skewY:Re}=ne,dt=P.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:B,drawingId:k}),de=Me.getObject(dt);if(de!=null){de.transformByState({left:it,top:rt,width:ot,height:at,angle:Tt,flipX:Rt,flipY:st,skewX:ct,skewY:Re});return}const Q={left:it,top:rt,width:ot,height:at,zIndex:this._drawingManagerService.getDrawingOrder(D,B).length-1},be=ie===l.DrawingTypeEnum.DRAWING_CHART;if(be){const Y=K?K.backgroundColor:"white";Q.fill=Y,Q.rotateEnabled=!1,K&&K.border&&(Q.stroke=K.border),Q.paintFirst="stroke",Q.strokeWidth=1,Q.borderEnabled=!1,Q.radius=8}const re=new N.Rect(dt,Q);be&&re.setObjectType(N.ObjectType.CHART),Me.addObject(re,N.DRAWING_OBJECT_LAYER_INDEX),oe.allowTransform!==!1&&Me.attachTransformerTo(re);const Ye=this._ensureMap(D,B),le=new l.DisposableCollection,Ee=Me.getMainViewport(),Oe={top:Ee.top,left:Ee.left,bottom:Ee.bottom,right:Ee.right},ue={dispose:le,rect:re,boundsOfViewArea:Oe,domAnchor:t,unitId:D,subUnitId:B},lt=se(re,F.renderUnit,ce.skeleton,te.worksheet,ue),fe=new W.BehaviorSubject(lt);ue.position$=fe;let G={position$:fe,id:k,componentKey:oe.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:Y=>{Te.dispatchEvent(new WheelEvent(Y.type,Y))},props:(U=(L=Ye.get(k))==null?void 0:L.props)!=null?U:this._getFloatDomProps(k),data:K,unitId:D};e.eventPassThrough&&(G={...G,onPointerDown:Y=>{Te.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{Te.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{Te.dispatchEvent(new PointerEvent(Y.type,Y))}}),this._canvasFloatDomService.addFloatDom(G),this.disposeWithMe(_.subscribe(Y=>{var Ht,Vt,xt,Xt;const gt=tt({rotate:0,startX:Y.startX,startY:Y.startY,endX:Y.endX,endY:Y.endY,width:(Ht=t.width)!=null?Ht:Y.width,height:(Vt=t.height)!=null?Vt:Y.height,absolute:{left:f.absolute.left,top:f.absolute.top}},t),li=P.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:B,drawingId:k}),ui=new N.Rect(li,{left:gt.startX,top:gt.startY,width:(xt=t.width)!=null?xt:Y.width,height:(Xt=t.height)!=null?Xt:Y.height,zIndex:this._drawingManagerService.getDrawingOrder(D,B).length-1}),gi=se(ui,F.renderUnit,ce.skeleton,te.worksheet,ue);fe.next(gi)}));const Ge=(A=this._renderManagerService.getRenderById(D))==null?void 0:A.with(b.SheetSkeletonManagerService);Ge==null||Ge.currentSkeleton$.subscribe(Y=>{Y&&d.sheetId!==Y.sheetId&&this._removeDom(S,!0)});const ut=re.onTransformChange$.subscribeEvent(()=>{const Y=se(re,F.renderUnit,ce.skeleton,te.worksheet,ue);fe.next(Y)});le.add(()=>{this._canvasFloatDomService.removeFloatDom(k)}),ut&&le.add(ut),this._domLayerInfoMap.set(k,ue),Ye.set(k,{...Ye.get(k)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(n,e,t,o){var T,C,j,E,L;const a=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:c}=a;if(!this._getSceneAndTransformerByDrawingSearch(s))return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(T=this._renderManagerService.getRenderById(s))==null?void 0:T.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(c);if(!d)return;const{componentKey:h,data:g,allowTransform:p=!0}=e,S=o!=null?o:l.generateRandomId(),{position:f,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:n,endColumn:n},u,d.skeleton),I=f;I.startY=0;const M=this._getPosition(f,s);if(M==null)return;this._ensureMap(s,c).set(S,e);const y={unitId:s,subUnitId:c,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:h,sheetTransform:M,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:g,allowTransform:p};{const{unitId:U,subUnitId:A,drawingId:D}=y,B=v.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:A}),k=y,te=this._univerInstanceService.getUnit(U,l.UniverInstanceType.UNIVER_SHEET);if(!te)return;const oe=te.getActiveSheet().getSheetId();if(!k||!B)return;const ve=(C=this._renderManagerService.getRenderById(U))==null?void 0:C.with(b.SheetSkeletonManagerService);if(!ve)return;const ae=ve.getWorksheetSkeleton(A);if(!ae)return;const{transform:Ie,data:ce}=k,ne=this._getSceneAndTransformerByDrawingSearch(U);if(ne==null)return;const{scene:ie,canvas:K}=ne;if(Ie==null||oe!==A)return;const{left:F,top:Me,width:Te,height:it,angle:rt,flipX:ot,flipY:at,skewX:Tt,skewY:Rt}=Ie,st=P.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:A,drawingId:D}),ct=ie.getObject(st);if(ct!=null){ct.transformByState({left:F,top:Me,width:Te,height:it,angle:rt,flipX:ot,flipY:at,skewX:Tt,skewY:Rt});return}const Re=tt({rotate:0,startX:I.startX,startY:0,endX:f.endX,endY:f.endY,width:t.width,height:t.height,absolute:{left:f.absolute.left,top:f.absolute.top}},t),dt={left:Re.startX,top:Re.startY,width:Re.width,height:Re.height,zIndex:this._drawingManagerService.getDrawingOrder(U,A).length-1},de=new N.Rect(st,dt);ie.addObject(de,N.DRAWING_OBJECT_LAYER_INDEX),k.allowTransform!==!1&&ie.attachTransformerTo(de);const Q=this._ensureMap(U,A),be=new l.DisposableCollection,re=ie.getMainViewport(),Ye={top:0,left:re.left,bottom:re.bottom,right:re.right},le={dispose:be,rect:de,unitId:U,subUnitId:A,boundsOfViewArea:Ye,domAnchor:t,scrollDirectionResponse:"HORIZONTAL"},Ee=se(de,ne.renderUnit,ae.skeleton,B.worksheet,le),Oe=new W.BehaviorSubject(Ee);le.position$=Oe;let ue={position$:Oe,id:D,componentKey:k.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:G=>{K.dispatchEvent(new WheelEvent(G.type,G))},props:(E=(j=Q.get(D))==null?void 0:j.props)!=null?E:this._getFloatDomProps(D),data:ce,unitId:U};e.eventPassThrough&&(ue={...ue,onPointerDown:G=>{K.dispatchEvent(new PointerEvent(G.type,G))},onPointerMove:G=>{K.dispatchEvent(new PointerEvent(G.type,G))},onPointerUp:G=>{K.dispatchEvent(new PointerEvent(G.type,G))}}),this._canvasFloatDomService.addFloatDom(ue);const lt=de.onTransformChange$.subscribeEvent(()=>{const G=se(de,ne.renderUnit,ae.skeleton,B.worksheet,le);Oe.next(G)});this.disposeWithMe(_.subscribe(G=>{const Ge=tt({rotate:0,startX:G.startX,startY:0,endX:G.endX,endY:G.endY,width:t.width,height:t.height,absolute:{left:f.absolute.left,top:f.absolute.top}},t),ut=P.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:A,drawingId:D}),Y=new N.Rect(ut,{left:Ge.startX,top:0,width:t.width,height:t.height,zIndex:this._drawingManagerService.getDrawingOrder(U,A).length-1}),gt=se(Y,ne.renderUnit,ae.skeleton,B.worksheet,le);Oe.next(gt)}));const fe=(L=this._renderManagerService.getRenderById(U))==null?void 0:L.with(b.SheetSkeletonManagerService);fe==null||fe.currentSkeleton$.subscribe(G=>{G&&d.sheetId!==G.sheetId&&this._removeDom(S,!0)}),be.add(()=>{this._canvasFloatDomService.removeFloatDom(D)}),lt&&be.add(lt),this._domLayerInfoMap.set(D,le),Q.set(D,{...Q.get(D)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(n,e,t){let{startRow:o,startColumn:a}=n;const s=Le(o,a,t),c=new W.BehaviorSubject(s),m=Le(n.endRow,n.endColumn,t),u=new W.BehaviorSubject(m),d=()=>{const _=Le(o,a,t),I=Le(n.endRow,n.endColumn,t);c.next(_),u.next(I)},h=new l.DisposableCollection;h.add(e.engine.clientRect$.subscribe(()=>d())),h.add(this._commandService.onCommandExecuted(_=>{if(_.id===v.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(M=>M.row===o)>-1){d();return}(v.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===b.SetScrollOperation.id||_.id===b.SetZoomRatioOperation.id)&&d()}));const g=(_,I)=>{o=_,a=I,d()},p=()=>({rotate:0,width:m.right-s.left,height:m.bottom-s.top,absolute:{left:!0,top:!0},startX:s.left,startY:s.top,endX:m.right,endY:m.bottom}),S=c.pipe(W.map(_=>{const I=Le(n.endRow,n.endColumn,t);return{rotate:0,width:I.right-_.left,height:I.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:I.right,endY:I.bottom}})),f=p();return{position$:S,position:f,updateRowCol:g,topLeftPos$:c,rightBottomPos$:u,disposable:h}}},O.SheetCanvasFloatDomManagerService=ri([_e(0,l.Inject(N.IRenderManagerService)),_e(1,l.IUniverInstanceService),_e(2,l.Inject(l.ICommandService)),_e(3,P.IDrawingManagerService),_e(4,l.Inject($.CanvasFloatDomService)),_e(5,w.ISheetDrawingService),_e(6,l.Inject(l.LifecycleService))],O.SheetCanvasFloatDomManagerService);function Le(r,i,n){const e=n.getCellWithCoordByIndex(r,i),t=e.isMergedMainCell?e.mergeInfo:e;return{left:t.startX,right:t.endX,top:t.startY,bottom:t.endY}}function tt(r,i,n){var m,u;n=n!=null?n:1;const e=r.endX-r.startX,t=r.endY-r.startY,o=(m=i==null?void 0:i.width)!=null?m:e,a=(u=i==null?void 0:i.height)!=null?u:t;let s=0,c=0;if(i){if(i.horizonOffsetAlign==="right"){const d=nt(i.marginX,e*n);s=r.endX-d-o}else s=r.startX+nt(i.marginX,e);if(i.verticalOffsetAlign==="bottom"){const d=nt(i.marginY,t*n);c=r.endY-d-a}else c=r.startY+nt(i.marginY,t)}return{rotate:0,startX:s,startY:c,endX:r.endX,endY:r.endY,width:o,height:a,absolute:{left:r.absolute.left,top:r.absolute.top}}}function nt(r,i){if(r===void 0)return 0;if(typeof r=="number")return r;const n=Number.parseFloat(r);return i*n/100}var Ft=Object.defineProperty,ai=Object.getOwnPropertyDescriptor,si=(r,i,n)=>i in r?Ft(r,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[i]=n,ci=(r,i,n,e)=>{for(var t=e>1?void 0:e?ai(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Ft(i,n,t),t},Mt=(r,i)=>(n,e)=>i(n,e,r),$t=(r,i,n)=>si(r,typeof i!="symbol"?i+"":i,n);const di="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(i=Et,n,e,t){super(),this._config=i,this._injector=n,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=l.merge({},Et,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Kt,a)}onStarting(){l.registerDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService],[et],[$e],[qe],[Je],[ze],[Ve],[Ke],[xe]]),l.touchDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[ze]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[Je],[qe],[et],[Ve],[Ke],[xe]])}onSteady(){this._injector.get($e)}_registerRenderModules(){[[Ne],[Ct],[ft]].forEach(i=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,i))})}},$t(O.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),$t(O.UniverSheetsDrawingUIPlugin,"pluginName",di),O.UniverSheetsDrawingUIPlugin=ci([l.DependentOn(P.UniverDrawingPlugin,Se.UniverDocsDrawingPlugin,ge.UniverDrawingUIPlugin,w.UniverSheetsDrawingPlugin),Mt(1,l.Inject(l.Injector)),Mt(2,N.IRenderManagerService),Mt(3,l.IConfigService)],O.UniverSheetsDrawingUIPlugin),O.ClearSheetDrawingTransformerOperation=H,O.DeleteDrawingsCommand=yt,O.EditSheetDrawingOperation=mt,O.GroupSheetDrawingCommand=St,O.InsertFloatImageCommand=je,O.InsertSheetDrawingCommand=Ae,O.MoveDrawingsCommand=ye,O.RemoveSheetDrawingCommand=Ce,O.SHEETS_IMAGE_MENU_ID=Dt,O.SetDrawingArrangeCommand=wt,O.SetSheetDrawingCommand=Ue,O.SidebarSheetDrawingOperation=ht,O.UngroupSheetDrawingCommand=_t,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});