@univerjs/sheets-drawing-ui 0.6.4-nightly.202503101606 → 0.6.4-nightly.202503111607

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,4 +1,4 @@
1
- import { ICellData, Nullable, Disposable, ICommandService, Injector, IUniverInstanceService } from '@univerjs/core';
1
+ import { ICellData, Nullable, Disposable, ICommandService, Injector } from '@univerjs/core';
2
2
  import { ISheetLocationBase, SheetInterceptorService } from '@univerjs/sheets';
3
3
  import { DocDrawingController } from '@univerjs/docs-drawing';
4
4
  import { IDrawingManagerService } from '@univerjs/drawing';
@@ -7,15 +7,12 @@ export declare function resizeImageByCell(injector: Injector, location: ISheetLo
7
7
  export declare class SheetCellImageController extends Disposable {
8
8
  private readonly _commandService;
9
9
  private readonly _sheetInterceptorService;
10
- private readonly _univerInstanceService;
11
10
  private readonly _injector;
12
11
  private readonly _drawingManagerService;
13
12
  private readonly _docDrawingController;
14
13
  private readonly _editorBridgeService;
15
- constructor(_commandService: ICommandService, _sheetInterceptorService: SheetInterceptorService, _univerInstanceService: IUniverInstanceService, _injector: Injector, _drawingManagerService: IDrawingManagerService, _docDrawingController: DocDrawingController, _editorBridgeService: IEditorBridgeService);
14
+ constructor(_commandService: ICommandService, _sheetInterceptorService: SheetInterceptorService, _injector: Injector, _drawingManagerService: IDrawingManagerService, _docDrawingController: DocDrawingController, _editorBridgeService: IEditorBridgeService);
16
15
  private _initDisableEdit;
17
- private _initHandleResize;
18
16
  private _handleInitEditor;
19
- private _handleWriteCell;
20
17
  private _initCellContentInterceptor;
21
18
  }
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(R,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/jsx-runtime"),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/jsx-runtime","react","@univerjs/docs-ui","@univerjs/design"],l):(R=typeof globalThis<"u"?globalThis:R||self,l(R.UniverSheetsDrawingUi={},R.UniverCore,R.UniverDocsDrawing,R.UniverDrawing,R.UniverDrawingUi,R.UniverEngineRender,R.UniverSheetsDrawing,R.UniverSheetsUi,R.UniverUi,R.rxjs,R.UniverSheets,R.React,R.React,R.UniverDocsUi,R.UniverDesign))})(this,function(R,l,we,U,pe,W,m,O,Y,N,_,x,ne,ut,q){"use strict";var Kn=Object.defineProperty;var zn=(R,l,we)=>l in R?Kn(R,l,{enumerable:!0,configurable:!0,writable:!0,value:we}):R[l]=we;var ee=(R,l,we)=>zn(R,typeof l!="symbol"?l+"":l,we);const $t="sheets-drawing-ui.config",bt={},G={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(i,r)=>{const t=i.get(W.IRenderManagerService);return r.forEach(e=>{var n,o;(o=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},Ie={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var C,M,T;const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(_.SheetInterceptorService),o=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:a}=r,s=[];a.forEach(y=>{const{unitId:b}=y;s.push(b)});const d=o.getBatchRemoveOp(a),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,f=n.onCommandExecute({id:Ie.id,params:r}),S={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:p,objects:h,type:m.DrawingApplyType.REMOVE}},w={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:c,objects:h,type:m.DrawingApplyType.INSERT}};return l.sequenceExecute([...(C=f.preRedos)!=null?C:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(M=f.preUndos)!=null?M:[],w,...f.undos,{id:G.id,params:s}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:s}]}),!0):!1}},Rt="COMPONENT_SHEET_DRAWING_PANEL",gt={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{const t=i.get(Y.ISidebarService),e=i.get(l.LocaleService),n=i.get(l.IUniverInstanceService),o=i.get(l.ICommandService);if(!_.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Rt},onClose:()=>{o.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},ht={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(i,r)=>{const t=i.get(l.ICommandService);return r==null?!1:(t.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[r]),t.executeCommand(gt.id,{value:"open"}),!0)}},Fe={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",uploadLoadingBodyText:"univer-upload-loading-body-text"},Gt=()=>{const i=Y.useDependency(U.IImageIoService),r=Y.useDependency(l.LocaleService),[t,e]=ne.useState(0);return ne.useEffect(()=>{const n=i.change$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[i]),x.jsx("div",{style:{display:t>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:`${r.t("uploadLoading.loading")}: ${t}`})]})})};var Ht=Object.getOwnPropertyDescriptor,Vt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Ht(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},me=(i,r)=>(t,e)=>r(t,e,i);let $e=class extends l.RxDisposable{constructor(r,t,e,n,o,a,s,d){super();ee(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=t,this._canvasPopManagerService=e,this._renderManagerService=n,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._commandService=d,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(Y.BuiltInUIPart.CONTENT,()=>Y.connectInjector(Gt,this._injector))}_dispose(r){const t=r.getUnitId();this._renderManagerService.removeRender(t)}_create(r){if(!r)return;const t=r.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(r){const t=r.getAllObjectsByOrder();for(const e of t)if(e instanceof pe.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const t=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(l.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const a=e.getSelectedObjectMap();if(a.size>1){n==null||n.dispose();return}const s=a.values().next().value;if(!s)return;const d=s.oKey,g=this._drawingManagerService.getDrawingOKey(d);if(!g)return;const{unitId:u,subUnitId:c,drawingId:p,drawingType:h}=g,f=g.data;if(f&&f.disablePopup)return;n==null||n.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,c,p,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:pe.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,c,p,h)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[l.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:ht.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Ie.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:pe.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:pe.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===l.DrawingTypeEnum.DRAWING_DOM}]}};$e=Vt([me(0,l.Inject(l.Injector)),me(1,U.IDrawingManagerService),me(2,l.Inject(O.SheetCanvasPopManagerService)),me(3,W.IRenderManagerService),me(4,l.IUniverInstanceService),me(5,l.IContextService),me(6,l.Inject(Y.IUIPartsService)),me(7,l.ICommandService)],$e);function K(i,r,t){const{from:e,to:n,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:d=0,skewY:g=0}=i,u=t.getCurrent();if(u==null)return;const c=O.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:p,top:h,width:f,height:S}=c;const w=t.getCurrentSkeleton(),v=w.rowHeaderWidth+w.columnTotalWidth,C=w.columnHeaderHeight+w.rowTotalHeight;return p+f>v&&(p=v-f),h+S>C&&(h=C-S),{flipY:o,flipX:a,angle:s,skewX:d,skewY:g,left:p,top:h,width:f,height:S}}function H(i,r){const{left:t=0,top:e=0,width:n=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:d=0,skewX:g=0,skewY:u=0}=i,c=r.getCellWithCoordByOffset(t,e);if(c==null)return;const p={column:c.actualColumn,columnOffset:W.precisionTo(t-c.startX,1),row:c.actualRow,rowOffset:W.precisionTo(e-c.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+o);if(h==null)return;const f={column:h.actualColumn,columnOffset:W.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:W.precisionTo(e+o-h.startY,1)};return{flipY:a,flipX:s,angle:d,skewX:g,skewY:u,from:p,to:f}}var Xt=Object.getOwnPropertyDescriptor,xt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Xt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ge=(i,r)=>(t,e)=>r(t,e,i);let pt=class extends l.Disposable{constructor(i,r,t,e,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,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 t=i[r];for(const e in t.data){const n=t.data[e];n.transform=K(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};pt=xt([Ge(1,m.ISheetDrawingService),Ge(2,U.IDrawingManagerService),Ge(3,l.Inject(O.ISheetSelectionRenderService)),Ge(4,l.Inject(O.SheetSkeletonManagerService))],pt);function Kt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:a,drawingId:s}=e,d=W.getGroupState(0,0,n.map(c=>c.transform||{})),g=n.map(c=>{const p=c.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:S}=c;return{unitId:h,subUnitId:f,drawingId:S,transform:{...p,left:p.left-d.left,top:p.top-d.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:d};r.push({parent:u,children:g})}),r}function zt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:a,drawingId:s,transform:d={width:0,height:0}}=e;if(d==null)return;const g=n.map(c=>{const{transform:p}=c,{unitId:h,subUnitId:f,drawingId:S}=c,w=W.transformObjectOutOfGroup(p||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:f,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:g})}),r}const mt={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=n.getGroupDrawingOp(r),{unitId:s,subUnitId:d,undo:g,redo:u,objects:c}=a;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:d,objects:zt(c),type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!0):!1}},Oe={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var C,M,T;const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService),o=i.get(_.SheetInterceptorService);if(!r)return!1;const a=r.drawings,s=a.map(y=>y.unitId),d=n.getBatchAddOp(a),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,f=o.onCommandExecute({id:Oe.id,params:r}),S={id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT}},w={id:m.SetDrawingApplyMutation.id,params:{op:c,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(C=f.preRedos)!=null?C:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(M=f.preUndos)!=null?M:[],w,...f.undos,{id:G.id,params:s}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:s}]}),!0):!1}},ft={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService);if(!r)return!1;const n=i.get(m.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:d}=r,g={unitId:o,subUnitId:a,drawingIds:s};let u;if(d===l.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):d===l.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):d===l.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):d===l.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:c,redo:p,undo:h}=u;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:p,unitId:o,subUnitId:a,objects:c,type:m.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:c,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:o,subUnitId:a,objects:c,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}},Pe={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=n.getBatchUpdateOp(o),{unitId:s,subUnitId:d,undo:g,redo:u,objects:c}=a;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:s,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:d,op:g,objects:c,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}]}),!0):!1}},St={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=n.getUngroupDrawingOp(r),{unitId:s,subUnitId:d,undo:g,redo:u,objects:c}=a;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:d,objects:Kt(c),type:m.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};var qt=Object.getOwnPropertyDescriptor,Zt=(i,r,t,e)=>{for(var n=e>1?void 0:e?qt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},re=(i,r)=>(t,e)=>r(t,e,i);function Jt(i,r,t){const e=t*Math.PI/180,n=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:n,rotatedHeight:o}}function wt(i,r,t,e,n){var C;const{rotatedHeight:o,rotatedWidth:a}=Jt(t,e,n),d=i.get(W.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const u=(C=d.with(O.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:C.skeleton;if(u==null)return!1;const c=u.getCellByIndex(r.row,r.col),p=c.mergeInfo.endX-c.mergeInfo.startX-2,h=c.mergeInfo.endY-c.mergeInfo.startY-2,f=a/o,w=Math.ceil(Math.min(p,h*f))/a,v=!w||Number.isNaN(w)?.001:w;return{width:t*v,height:e*v}}R.SheetDrawingUpdateController=class extends l.Disposable{constructor(t,e,n,o,a,s,d,g,u,c,p,h,f){super();ee(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=o,this._imageIoService=a,this._fileOpenerService=s,this._sheetDrawingService=d,this._drawingManagerService=g,this._contextService=u,this._messageService=c,this._localeService=p,this._injector=f,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const t=await this._fileOpenerService.openFile({multiple:!0,accept:U.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),e=t.length;return e>U.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(U.DRAWING_IMAGE_COUNT_LIMIT))}),!1):e===0?!1:(t.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const e=(await this._fileOpenerService.openFile({multiple:!1,accept:U.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(t,e){return this._insertCellImage(t,e)}async insertFloatImageByFile(t){let e;try{e=await this._imageIoService.saveImage(t)}catch(M){const T=M.message;T===U.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(U.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):T===U.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):T===U.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const n=this._getUnitInfo(),{unitId:o,subUnitId:a}=n,{imageId:s,imageSourceType:d,source:g,base64Cache:u}=e,{width:c,height:p,image:h}=await U.getImageSize(u||""),{width:f,height:S}=this._context.scene;this._imageIoService.addImageSourceCache(g,d,h);let w=1;if(c>U.DRAWING_IMAGE_WIDTH_LIMIT||p>U.DRAWING_IMAGE_HEIGHT_LIMIT){const M=U.DRAWING_IMAGE_WIDTH_LIMIT/c,T=U.DRAWING_IMAGE_HEIGHT_LIMIT/p;w=Math.max(M,T)}const v=this._getImagePosition(c*w,p*w,f,S);if(v==null)return;const C={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:d,source:g,transform:K(v,this._selectionRenderService,this._skeletonManagerService),sheetTransform:v};return this._commandService.executeCommand(Oe.id,{unitId:o,drawings:[C]})}async _insertCellImage(t,e){var C,M;let n;try{n=await this._imageIoService.saveImage(t)}catch(T){const y=T.message;y===U.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(U.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===U.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===U.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:o,imageSourceType:a,source:s,base64Cache:d}=n,{width:g,height:u,image:c}=await U.getImageSize(d||"");this._imageIoService.addImageSourceCache(s,a,c);const p=this._workbookSelections.getCurrentLastSelection();if(!p)return!1;const h=l.createDocumentModelWithStyle("",{}),f=wt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:p.primary.actualRow,col:p.primary.actualColumn},g,u,0);if(!f)return!1;const S={size:{width:f.width,height:f.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},w={unitId:h.getUnitId(),subUnitId:h.getUnitId(),drawingId:o,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:s,transform:ut.docDrawingPositionToTransform(S),docTransform:S,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},v=l.BuildTextUtils.drawing.add({documentDataModel:h,drawings:[w],selection:{collapsed:!0,startOffset:0,endOffset:0}});return v?(h.apply(v),this._commandService.syncExecuteCommand(_.SetRangeValuesCommand.id,{value:{[(C=e==null?void 0:e.row)!=null?C:p.primary.actualRow]:{[(M=e==null?void 0:e.col)!=null?M:p.primary.actualColumn]:{p:h.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,f;const{width:n,height:o,image:a}=await U.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,l.ImageSourceType.URL,a);const s=this._workbookSelections.getCurrentLastSelection();if(!s)return!1;const d=l.createDocumentModelWithStyle("",{}),g=wt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:s.primary.actualRow,col:s.primary.actualColumn},n,o,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},c={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:t,transform:ut.docDrawingPositionToTransform(u),docTransform:u,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},p=l.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[c],selection:{collapsed:!0,startOffset:0,endOffset:0}});return p?(d.apply(p),this._commandService.syncExecuteCommand(_.SetRangeValuesCommand.id,{value:{[(h=e==null?void 0:e.row)!=null?h:s.primary.actualRow]:{[(f=e==null?void 0:e.col)!=null?f:s.primary.actualColumn]:{p:d.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}_getUnitInfo(){const t=this._context.unit,e=t.getActiveSheet(),n=t.getUnitId(),o=e.getSheetId();return{unitId:n,subUnitId:o}}_getImagePosition(t,e,n,o){const a=this._workbookSelections.getCurrentSelections();let s={startRow:0,endRow:0,startColumn:0,endColumn:0};a&&a.length>0&&(s=a[a.length-1].range);const d=O.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);if(d==null)return;let{startColumn:g,startRow:u,startX:c,startY:p}=d,h=!1;if(c+t>n&&(c=n-t,c<0&&(c=0,t=n),h=!0),p+e>o&&(p=o-e,p<0&&(p=0,e=o),h=!0),h){const v=this._selectionRenderService.getCellWithCoordByOffset(c,p);if(v==null)return;c=v.startX,p=v.startY,g=v.actualColumn,u=v.actualRow}const f={column:g,columnOffset:0,row:u,rowOffset:0},S=this._selectionRenderService.getCellWithCoordByOffset(c+t,p+e);if(S==null)return;const w={column:S.actualColumn,columnOffset:c+t-S.startX,row:S.actualRow,rowOffset:p+e-S.startY};return{from:f,to:w}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:o,arrangeType:a}=t;this._commandService.executeCommand(ft.id,{unitId:e,subUnitId:n,drawingIds:o,arrangeType:a})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:o,subUnitId:a,drawingId:s,drawingType:d,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:s});if(u==null||u.unitId!==this._context.unitId)return;const c=H({...u.transform,...g},this._selectionRenderService);if(c==null)return;const p={...n,transform:{...u.transform,...g,...K(c,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...c}};e.push(p)}),e.length>0&&this._commandService.executeCommand(Pe.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(mt.id,t);const{unitId:e,subUnitId:n,drawingId:o}=t[0].parent;this._commandService.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:o}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(St.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}},R.SheetDrawingUpdateController=Zt([re(1,l.Inject(O.SheetSkeletonManagerService)),re(2,l.ICommandService),re(3,O.ISheetSelectionRenderService),re(4,U.IImageIoService),re(5,Y.ILocalFileService),re(6,m.ISheetDrawingService),re(7,U.IDrawingManagerService),re(8,l.IContextService),re(9,Y.IMessageService),re(10,l.Inject(l.LocaleService)),re(11,l.Inject(_.SheetsSelectionsService)),re(12,l.Inject(l.Injector))],R.SheetDrawingUpdateController);var Qt=Object.getOwnPropertyDescriptor,en=(i,r,t,e)=>{for(var n=e>1?void 0:e?Qt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},ve=(i,r)=>(t,e)=>r(t,e,i);function vt(i,r,t){var e,n,o,a;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((a=(o=t.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const s=t.p.drawings[t.p.drawingsOrder[0]],d=wt(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,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let He=class extends l.Disposable{constructor(i,r,t,e,n,o,a){super(),this._commandService=i,this._sheetInterceptorService=r,this._univerInstanceService=t,this._injector=e,this._drawingManagerService=n,this._docDrawingController=o,this._editorBridgeService=a,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor(),this._initDisableEdit()}_initDisableEdit(){this.disposeWithMe(this._commandService.beforeCommandExecuted(i=>{var r,t,e;if(i.id===O.SetCellEditVisibleOperation.id){const n=i.params,{visible:o,eventType:a}=n;if(o&&a===W.DeviceInputEventType.Dblclick){const s=this._editorBridgeService.getEditCellState();if(((e=(t=(r=s==null?void 0:s.documentLayoutObject.documentModel)==null?void 0:r.getDrawingsOrder())==null?void 0:t.length)!=null?e:0)>0)throw new Error("Can not edit when there are drawings.")}}}))}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{let r,t=[];if(i.id===_.SetWorksheetRowHeightMutation.id){const e=i.params;t=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetColWidthMutation.id){const e=i.params;t=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetRowIsAutoHeightMutation.id){const e=i.params;t=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetRowAutoHeightMutation.id){const e=i.params;r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId}),t=e.rowsAutoHeightInfo.map(n=>({startRow:n.row,endRow:n.row,startColumn:0,endColumn:9999}))}else if(i.id===_.AddWorksheetMergeMutation.id){const e=i.params;t=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.RemoveWorksheetMergeMutation.id){const e=i.params;t=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}r&&t.length&&t.forEach(e=>{const n=l.Range.transformRange(e,r.worksheet);for(let o=n.startRow;o<=n.endRow;o++)for(let a=n.startColumn;a<=n.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===ut.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(_.AFTER_CELL_EDIT,{priority:9999,handler:(i,r,t)=>(vt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i),t(i))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:_.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,t)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0}),t(i)}}))}};He=en([ve(0,l.ICommandService),ve(1,l.Inject(_.SheetInterceptorService)),ve(2,l.IUniverInstanceService),ve(3,l.Inject(l.Injector)),ve(4,U.IDrawingManagerService),ve(5,l.Inject(we.DocDrawingController)),ve(6,l.Inject(O.IEditorBridgeService))],He);var tn=Object.getOwnPropertyDescriptor,nn=(i,r,t,e)=>{for(var n=e>1?void 0:e?tn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Et=(i,r)=>(t,e)=>r(t,e,i);let Ve=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,t,e)=>{new l.ObjectMatrix(e).forValue((n,o,a)=>{vt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},a)})}}))}};Ve=nn([Et(0,l.Inject(O.IAutoFillService)),Et(1,l.Inject(l.Injector))],Ve);var rn=Object.getOwnPropertyDescriptor,on=(i,r,t,e)=>{for(var n=e>1?void 0:e?rn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Xe=(i,r)=>(t,e)=>r(t,e,i);let xe=class extends l.Disposable{constructor(r,t,e,n){super();ee(this,"_isSetCursor",!1);this._hoverManagerService=r,this._renderManagerService=t,this._selectionsService=e,this._drawingRenderService=n}_initHover(){}_initImageClick(){}};xe=on([Xe(0,l.Inject(O.HoverManagerService)),Xe(1,l.Inject(W.IRenderManagerService)),Xe(2,l.Inject(_.SheetsSelectionsService)),Xe(3,l.Inject(pe.DrawingRenderService))],xe);const Ae={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{var a,s;const t=i.get(l.IUniverInstanceService),e=i.get(W.IRenderManagerService),n=(a=W.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:a.with(R.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const d=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(d)).every(g=>g)}else return(s=n.insertFloatImage())!=null?s:!1}},_t={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:i=>{var e,n;const r=i.get(l.IUniverInstanceService),t=i.get(W.IRenderManagerService);return(n=(e=W.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,r,t))==null?void 0:e.with(R.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}};var an=Object.getOwnPropertyDescriptor,sn=(i,r,t,e)=>{for(var n=e>1?void 0:e?an(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ue=(i,r)=>(t,e)=>r(t,e,i);const Ot="image/png";function cn(i){const r=i.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=t.charCodeAt(o);return new Blob([n],{type:Ot})}function dn(i){const r=new ClipboardItem({[Ot]:cn(i)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function ln(){function i(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const r=document.activeElement,t=i();return document.body.appendChild(t),t.focus(),()=>{t.blur(),document.body.removeChild(t),r instanceof HTMLElement&&r.focus()}}const Pt=[O.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,O.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,O.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,O.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let Ke=class extends l.Disposable{constructor(r,t,e,n,o){super();ee(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const o=this._focusedDrawings;if(o.length>0){const[a]=o;if(n===O.COPY_TYPE.CUT){const d={unitId:r,drawings:[a]};this._commandService.executeCommand(Ie.id,d)}setTimeout(()=>{const d=ln();a.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&a.imageSourceType===U.ImageSourceType.BASE64?dn(a.source):this._clipboardInterfaceService.writeText(""),d()},200);const s={unitId:a.unitId,subUnitId:a.subUnitId,drawings:[a]};this._copyInfo=s}else{const a=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=a}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=O.COPY_TYPE.COPY,pasteType:a}=n,{range:s}=r||{},{range:d,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:a,unitId:g,subUnitId:u,pasteRange:d},{copyRange:s,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:a},O.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:O.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},O.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:O.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},O.COPY_TYPE.COPY);{const e=t.filter(n=>n.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Ae.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var p;const n=(p=this._renderManagerService.getRenderById(r))==null?void 0:p.with(O.SheetSkeletonManagerService);if(!n)return;const o=n.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:s,startY:d,endY:g}=o,u=this._drawingService.getDrawingData(r,t),c=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const f=u[h],{transform:S}=f;if(f.anchorType!==m.SheetDrawingAnchorType.Both||!S)return;const{left:w=0,top:v=0,width:C=0,height:M=0}=S,{drawingStartX:T,drawingEndX:y,drawingStartY:b,drawingEndY:I}={drawingStartX:w,drawingEndX:w+C,drawingStartY:v,drawingEndY:v+M};a<=T&&y<=s&&d<=b&&I<=g&&c.push(f)}),c.length)return{copyRange:e,drawings:c,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Pt.includes(e))return{redos:[],undos:[]};const{unitId:o,subUnitId:a,range:s}=n,d=this._renderManagerService.getRenderById(o),g=d==null?void 0:d.with(O.SheetSkeletonManagerService),u=d==null?void 0:d.with(O.ISheetSelectionRenderService),c=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:p}=c,h=O.discreteRangeToRange(s);return this._generateMutations(p,{unitId:o,subUnitId:a,isCut:t===O.COPY_TYPE.CUT,getTransform:(f,S)=>{var C;const w=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),v={...f,left:w==null?void 0:w.startX,top:w==null?void 0:w.startY};return{transform:v,sheetTransform:(C=H(v,u))!=null?C:S}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:o,isCut:a}=t,s=[],d=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:c,sheetTransform:p}=u;if(!c)return;const h=o(c,p),f={...u,unitId:e,subUnitId:n,drawingId:a?u.drawingId:l.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(a){const{undo:S,redo:w,objects:v}=g.getBatchUpdateOp([f]);s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:w,objects:v}}),d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:S,objects:v}})}else{const{undo:S,redo:w,objects:v}=g.getBatchAddOp([f]);s.push({id:m.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:v,type:m.DrawingApplyType.INSERT}}),d.push({id:m.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:n,objects:v,type:m.DrawingApplyType.REMOVE}})}}),{redos:s,undos:d}}_generateRangeDrawingsPasteMutations(r,t){var k;const{unitId:e,subUnitId:n,pasteType:o,pasteRange:a}=r,{copyRange:s,copyType:d}=t;if(Pt.includes(o))return{redos:[],undos:[]};const g=(k=this._renderManagerService.getRenderById(e))==null?void 0:k.with(O.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!s)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:O.discreteRangeToRange(a)},pasteType:o},d);const{ranges:[c,p],mapFunc:h}=O.virtualizeDiscreteRanges([s,a]),{row:f,col:S}=h(c.startRow,c.startColumn),{row:w,col:v}=h(p.startRow,p.startColumn),C=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:S,endColumn:S}),M=g.attachRangeWithCoord({startRow:w,endRow:w,startColumn:v,endColumn:v});if(!C||!M||!this._copyInfo)return{redos:[],undos:[]};const T=M.startX-C.startX,y=M.startY-C.startY,b=w-f,I=v-S;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(E,B)=>{var A,P;return{transform:{...E,left:((A=E==null?void 0:E.left)!=null?A:0)+T,top:((P=E==null?void 0:E.top)!=null?P:0)+y},sheetTransform:{...B,to:{...B.to,row:B.to.row+b,column:B.to.column+I},from:{...B.from,row:B.from.row+b,column:B.from.column+I}}}},isCut:d===O.COPY_TYPE.CUT})}};Ke=sn([Ue(0,O.ISheetClipboardService),Ue(1,W.IRenderManagerService),Ue(2,U.IDrawingManagerService),Ue(3,Y.IClipboardInterfaceService),Ue(4,l.ICommandService)],Ke);var un=Object.getOwnPropertyDescriptor,gn=(i,r,t,e)=>{for(var n=e>1?void 0:e?un(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ne=(i,r)=>(t,e)=>r(t,e,i);let ze=class extends l.Disposable{constructor(i,r,t,e,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([i,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingVisible(!1);return}const a=e.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new _.WorkbookViewPermission(a).id,new _.WorksheetViewPermission(a,s).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,o)})):(this._drawingManagerService.setDrawingVisible(!1),N.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(i,r){this._drawingManagerService.setDrawingVisible(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),a=this._renderManagerService.getRenderById(t),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===W.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.removeObject(g)})}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([i,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingEditable(!1);return}const a=e.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new _.WorkbookEditablePermission(a).id,new _.WorksheetEditPermission(a,s).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,o)})):(this._drawingManagerService.setDrawingEditable(!1),N.EMPTY))).subscribe())}_handleDrawingEditableFalse(i,r){this._drawingManagerService.setDrawingEditable(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),a=this._renderManagerService.getRenderById(t),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===W.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.detachTransformerFrom(g)})}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=t.getUnitId(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),d=s==null?void 0:s.scene;if(!d)return N.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new _.WorkbookViewPermission(o).id,new _.WorksheetViewPermission(o,a).id]).pipe(N.map(c=>c.every(p=>p.value)),N.distinctUntilChanged()).pipe(N.map(c=>({permission:c,scene:d,transformer:g,unitId:o,subUnitId:a})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingVisible(t);const s=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(o,a),g=Object.values(d);t?this._drawingManagerService.addNotification(g):(s.forEach(u=>{u.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),o=e==null?void 0:e.getSheetId();if(!n||!o)return;const a=this._drawingManagerService.getDrawingData(n,o),s=Object.values(a);this._drawingManagerService.addNotification(s)}}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=t.getUnitId(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),d=s==null?void 0:s.scene;if(!d)return N.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new _.WorkbookEditablePermission(o).id,new _.WorksheetEditPermission(o,a).id]).pipe(N.map(c=>c.every(p=>p.value)),N.distinctUntilChanged()).pipe(N.map(c=>({permission:c,scene:d,transformer:g,unitId:o,subUnitId:a})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingEditable(t);const s=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(o,a),g=Object.values(d);t?(s.forEach(u=>{u.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(s.forEach(u=>{u.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const o=n.getSheetId(),a=this._renderManagerService.getRenderById(e),s=a==null?void 0:a.scene;if(!s)return;const d=this._drawingManagerService.getDrawingData(e,o),g=Object.values(d);this._drawingManagerService.setDrawingEditable(!0),s.getAllObjectsByOrder().forEach(c=>{c.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(p=>c.oKey.includes(p.drawingId))&&s.detachTransformerFrom(c)})}}))}};ze=gn([Ne(0,U.IDrawingManagerService),Ne(1,W.IRenderManagerService),Ne(2,l.IPermissionService),Ne(3,l.IUniverInstanceService),Ne(4,l.Inject(l.UserManagerService))],ze);var hn=Object.getOwnPropertyDescriptor,pn=(i,r,t,e)=>{for(var n=e>1?void 0:e?hn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},qe=(i,r)=>(t,e)=>r(t,e,i);let Ze=class extends l.Disposable{constructor(i,r,t,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,t)=>{const{unitId:e,scene:n,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],n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,o=this._renderManagerService.getRenderById(e);if(!o)return t(i);const a=o.with(O.SheetSkeletonManagerService).getSkeletonParam(n);if(!a)return t(i);const s=this._drawingManagerService.getDrawingDataForUnit(e),d=s==null?void 0:s[r.subUnitId];if(!d)return t(i);const{scaleX:g,scaleY:u}=o.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},p=d.order.map(h=>d.data[h]).filter(h=>h.drawingType!==l.DrawingTypeEnum.DRAWING_DOM);return p.length?(p.forEach(h=>{if(!h.groupId&&h.transform&&l.Tools.isDefine(h.transform.left)&&l.Tools.isDefine(h.transform.top)&&l.Tools.isDefine(h.transform.width)&&l.Tools.isDefine(h.transform.height)){const f=a.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});f.column<c.startColumn&&(c.startColumn=f.column),f.row<c.startRow&&(c.startRow=f.row),c.endRow<S.row&&(c.endRow=S.row),c.endColumn<S.column&&(c.endColumn=S.column)}}),t(c)):t(i)}}))}};Ze=pn([qe(0,l.Inject(O.SheetPrintInterceptorService)),qe(1,l.Inject(pe.DrawingRenderService)),qe(2,U.IDrawingManagerService),qe(3,W.IRenderManagerService)],Ze);var mn=Object.getOwnPropertyDescriptor,fn=(i,r,t,e)=>{for(var n=e>1?void 0:e?mn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},fe=(i,r)=>(t,e)=>r(t,e,i);const Sn=[_.InsertRowCommand.id,_.InsertColCommand.id,_.RemoveRowCommand.id,_.RemoveColCommand.id,_.DeleteRangeMoveLeftCommand.id,_.DeleteRangeMoveUpCommand.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id,_.DeltaRowHeightCommand.id,_.SetRowHeightCommand.id,_.DeltaColumnWidthCommand.id,_.SetColWidthCommand.id,_.SetRowHiddenCommand.id,_.SetSpecificRowsVisibleCommand.id,_.SetSpecificColsVisibleCommand.id,_.SetColHiddenCommand.id,_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id],wn=[_.SetRowVisibleMutation.id,_.SetRowHiddenMutation.id,_.SetColVisibleMutation.id,_.SetColHiddenMutation.id,_.SetWorksheetRowHeightMutation.id,_.SetWorksheetColWidthMutation.id];let It=class extends l.Disposable{constructor(i,r,t,e,n,o,a,s,d){super(),this._context=i,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,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(!Sn.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===_.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===_.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===_.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===_.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===_.DeleteRangeMoveLeftCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,0)}else if(r===_.DeleteRangeMoveUpCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,1)}else if(r===_.InsertRangeMoveDownCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,2)}else if(r===_.InsertRangeMoveRightCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,3)}else if(r===_.SetRowHiddenCommand.id||r===_.SetSpecificRowsVisibleCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForRowVisible(e,n,o)}else if(r===_.SetSpecificColsVisibleCommand.id||r===_.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForColVisible(e,n,o)}else if(r===_.DeltaRowHeightCommand.id||r===_.SetRowHeightCommand.id||r===_.DeltaColumnWidthCommand.id||r===_.SetColWidthCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t,a=r===_.DeltaRowHeightCommand.id||r===_.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const t=_.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(e,n),d=[],g=[];if(Object.keys(s).forEach(u=>{const c=s[u],{updateDrawings:p,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,c);d.push(...p),g.push(...h)}),d.length===0&&g.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:p,objects:h}=u;o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.UPDATE}}),a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),c=u.undo,p=u.redo,h=u.objects;o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.REMOVE}}),a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.INSERT}})}return o.push({id:G.id,params:[e]}),a.push({id:G.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,r,t){const e=[],n=[],{sheetTransform:o,anchorType:a=m.SheetDrawingAnchorType.Position,transform:s,unitId:d,subUnitId:g,drawingId:u}=t,{from:c,to:p}=o,{row:h,column:f}=c,{row:S,column:w}=p;if(o==null||s==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:v,endRow:C,startColumn:M,endColumn:T}=i;let y=null,b=null;if(r===0&&h>=v&&S<=C)if(f>=M&&w<=T)n.push({unitId:d,subUnitId:g,drawingId:u});else{const I=this._shrinkCol(o,s,M,T,a);y=I==null?void 0:I.newSheetTransform,b=I==null?void 0:I.newTransform}else if(r===1&&f>=M&&w<=T)if(h>=v&&S<=C)n.push({unitId:d,subUnitId:g,drawingId:u});else{const I=this._shrinkRow(o,s,v,C,a);y=I==null?void 0:I.newSheetTransform,b=I==null?void 0:I.newTransform}else if(r===2){const I=this._expandRow(o,s,v,C,a);y=I==null?void 0:I.newSheetTransform,b=I==null?void 0:I.newTransform}else if(r===3){const I=this._expandCol(o,s,M,T,a);y=I==null?void 0:I.newSheetTransform,b=I==null?void 0:I.newTransform}if(y!=null&&b!=null){const I=K(y,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:y,transform:I})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(i,r,t){const e=H({...i},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=c;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:S,to:w}=p,{row:v,column:C}=S,{row:M,column:T}=w;for(let y=0;y<t.length;y++){const b=t[y],{startRow:I,endRow:k,startColumn:E,endColumn:B}=b;if(T<E)continue;if(f===m.SheetDrawingAnchorType.Position){let D=null,L=null;if(C>=E&&C<=B){const j=this._skeletonManagerService.attachRangeWithCoord({startColumn:C,endColumn:B,startRow:S.row,endRow:w.row});if(j==null)return;L={...h,left:j.startX}}if(L!=null&&(D=H(L,this._selectionRenderService),D!=null&&L!=null)){n.push({...c,sheetTransform:D,transform:L});break}this._remainDrawingSize(h,n,c);continue}if(C>=E&&T<=B)continue;let A=null,P=null;if(C>=E&&C<=B){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:C,endColumn:B,startRow:S.row,endRow:w.row});if(D==null)return;P={...h,left:(D==null?void 0:D.startX)||0,width:((h==null?void 0:h.width)||0)-D.endX+D.startX}}else if(T>=E&&T<=B){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:T,startRow:S.row,endRow:w.row});if(D==null)return;P={...h,left:D.startX-((h==null?void 0:h.width)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:B,startRow:S.row,endRow:w.row});if(D==null)return;if(P={...h,width:((h==null?void 0:h.width)||0)-D.endX+D.startX},A=H(P,this._selectionRenderService),A!=null&&P!=null){o.push({...c,sheetTransform:A,transform:P});break}}if(P!=null&&(A=H(P,this._selectionRenderService)),P!=null&&A!=null){n.push({...c,sheetTransform:A,transform:P});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),d=[],g=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);d.push(...u),g.push(...c)}return{redos:a,undos:s,preRedos:d,preUndos:g}}_createUndoAndRedoMutation(i,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:o,objects:a}=e,s=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],d=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:a,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:s,undos:d}}_getDrawingUndoForRowVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=c;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:S,to:w}=p,{row:v,column:C}=S,{row:M,column:T}=w;for(let y=0;y<t.length;y++){const b=t[y],{startRow:I,endRow:k,startColumn:E,endColumn:B}=b;if(M<I)continue;if(f===m.SheetDrawingAnchorType.Position){let D=null,L=null;if(v>=I&&v<=k){const j=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:k});if(j==null)return;L={...h,top:j.startY}}if(L!=null&&(D=H(L,this._selectionRenderService),D!=null&&L!=null)){n.push({...c,sheetTransform:D,transform:L});break}this._remainDrawingSize(h,n,c);continue}if(v>=I&&M<=k)continue;let A=null,P=null;if(v>=I&&v<=k){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:k});if(D==null)return;P={...h,top:(D==null?void 0:D.startY)||0,height:((h==null?void 0:h.height)||0)-D.endY+D.startY}}else if(M>=I&&M<=k){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:M});if(D==null)return;P={...h,top:D.startY-((h==null?void 0:h.height)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:k});if(D==null)return;if(P={...h,height:((h==null?void 0:h.height)||0)-D.endY+D.startY},A=H(P,this._selectionRenderService),A!=null&&P!=null){o.push({...c,sheetTransform:A,transform:P});break}}if(P!=null&&(A=H(P,this._selectionRenderService)),P!=null&&A!=null){n.push({...c,sheetTransform:A,transform:P});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),d=[],g=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);d.push(...u),g.push(...c)}return{redos:a,undos:s,preRedos:d,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,t,e){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(a=>{const s=n[a],{sheetTransform:d,transform:g,anchorType:u=m.SheetDrawingAnchorType.Position}=s;if(u===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,o,s);else{const{from:c,to:p}=d,{row:h,column:f}=c,{row:S,column:w}=p;for(let v=0;v<t.length;v++){const C=t[v],{startRow:M,endRow:T,startColumn:y,endColumn:b}=C;if(S<M||w<y)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=M&&S>=T||f<=y&&w>=b)){this._remainDrawingSize(g,o,s);continue}const I=K({...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 t,e;if(r==="insert")t=i.unitId,e=i.subUnitId;else{const n=_.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(i){var M,T;const{toRange:r,fromRange:t}=i,e=_.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=e,a=(T=(M=this._renderManagerService.getRenderById(n))==null?void 0:M.with(O.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=O.attachRangeWithCoord(a,t);if(!s)return{redos:[],undos:[]};const{startX:d,endX:g,startY:u,endY:c}=s,p=this._sheetDrawingService.getDrawingData(n,o),h=[];Object.keys(p).forEach(y=>{const b=p[y];if(b.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:I}=b;if(!I)return;const{left:k=0,top:E=0,width:B=0,height:A=0}=I,{drawingStartX:P,drawingEndX:D,drawingStartY:L,drawingEndY:j}={drawingStartX:k,drawingEndX:k+B,drawingStartY:E,drawingEndY:E+A};d<=P&&D<=g&&u<=L&&j<=c&&h.push(b)});const f=[],S=[],w=r.startRow-t.startRow,v=r.startColumn-t.startColumn,C=h.map(y=>{const b=y.sheetTransform,I={to:{...b.to,row:b.to.row+w,column:b.to.column+v},from:{...b.from,row:b.from.row+w,column:b.from.column+v}},k=K(I,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:y.drawingId,transform:k,sheetTransform:I}});if(C.length){const y=this._sheetDrawingService.getBatchUpdateOp(C),{undo:b,redo:I,objects:k}=y;f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:I,objects:k,type:m.DrawingApplyType.UPDATE}}),S.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:b,objects:k,type:m.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,a=o.startRow,s=o.endRow,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:v=m.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let C,M;if(r==="insert"){const y=this._expandRow(S,w,a,s,v);C=y==null?void 0:y.newSheetTransform,M=y==null?void 0:y.newTransform}else{const{from:y,to:b}=S,{row:I}=y,{row:k}=b;if(v===m.SheetDrawingAnchorType.Both&&I>=a&&k<=s)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkRow(S,w,a,s,v);C=E==null?void 0:E.newSheetTransform,M=E==null?void 0:E.newTransform}}if(!C||!M)return;const T={unitId:e,subUnitId:n,drawingId:h,transform:M,sheetTransform:C};c.push(T)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:S,objects:w}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,S=h.redo,w=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_moveColInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,a=o.startColumn,s=o.endColumn,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:v=m.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let C,M;if(r==="insert"){const y=this._expandCol(S,w,a,s,v);C=y==null?void 0:y.newSheetTransform,M=y==null?void 0:y.newTransform}else{const{from:y,to:b}=S,{column:I}=y,{column:k}=b;if(v===m.SheetDrawingAnchorType.Both&&I>=a&&k<=s)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkCol(S,w,a,s,v);C=E==null?void 0:E.newSheetTransform,M=E==null?void 0:E.newTransform}}if(!C||!M)return;const T={unitId:e,subUnitId:n,drawingId:h,transform:M,sheetTransform:C};c.push(T)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:S,objects:w}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,S=h.redo,w=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_expandCol(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{column:d}=a,{column:g}=s;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:a.row,endRow:s.row});if(p==null)return;c={...r,left:(r.left||0)+p.endX-p.startX},u=H(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:g+o}},c=K(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,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{column:d}=a,{column:g}=s;if(n===m.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:g-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:g-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,left:(r.left||0)-i.from.columnOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:a.row,endRow:s.row});if(p==null)return;c={...r,left:(r.left||0)-p.endX+p.startX-i.from.columnOffset}}u=H(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:a.row,endRow:s.row});if(p==null)return;u={from:{...a},to:{...s,column:t-1,columnOffset:p.endX-p.startX}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{row:d}=a,{row:g}=s;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:a.column,endColumn:s.column});if(p==null)return;c={...r,top:(r.top||0)+p.endY-p.startY},u=H(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:g+o}},c=K(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,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{row:d}=a,{row:g}=s;if(n===m.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:g-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:g-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,top:(r.top||0)-i.from.rowOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:a.column,endColumn:s.column});if(p==null)return;c={...r,top:(r.top||0)-p.endY+p.startY-i.from.rowOffset}}u=H(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:t-1,endRow:t-1});if(p==null)return;u={from:{...a},to:{...s,row:t-1,rowOffset:p.endY-p.startY}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===_.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:t}=i.params;this._updateDrawings(r,t)}})),this.disposeWithMe(this._context.activated$.subscribe(i=>{const{unit:r,unitId:t}=this._context;if(i){const e=r.getActiveSheet().getSheetId();this._updateDrawings(t,e)}else this._clearDrawings(t)}))}_clearDrawings(i){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,t=[];Object.keys(r).forEach(e=>{const n=r[e];n!=null&&Object.keys(n).forEach(o=>{const a=n[o].data;a!=null&&Object.keys(a).forEach(s=>{e===i&&t.push(a[s])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(i,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(o=>{const a=t[o];a!=null&&Object.keys(a).forEach(s=>{const d=a[s].data;d!=null&&Object.keys(d).forEach(g=>{if(o===i&&s===r){const u=d[g];u.transform=K(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(d[g])}else n.push(d[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{wn.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:s,transform:d,anchorType:g=m.SheetDrawingAnchorType.Position}=a;if(g===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=s,{row:p,column:h}=u,{row:f,column:S}=c;for(let w=0;w<t.length;w++){const v=t[w],{startRow:C,endRow:M,startColumn:T,endColumn:y}=v;if(l.Rectangle.intersects({startRow:C,endRow:M,startColumn:T,endColumn:y},{startRow:p,endRow:f,startColumn:h,endColumn:S})||p>M||h>y){const b=g===m.SheetDrawingAnchorType.Position,I=K(s,this._selectionRenderService,this._skeletonManagerService);n.push({...a,transform:{...I,width:b?d==null?void 0:d.width:I==null?void 0:I.width,height:b?d==null?void 0:d.height:I==null?void 0:I.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[i]))}};It=fn([fe(1,W.IRenderManagerService),fe(2,l.ICommandService),fe(3,O.ISheetSelectionRenderService),fe(4,l.Inject(O.SheetSkeletonManagerService)),fe(5,l.Inject(_.SheetInterceptorService)),fe(6,m.ISheetDrawingService),fe(7,U.IDrawingManagerService),fe(8,l.IUniverInstanceService)],It);var ie=function(){return ie=Object.assign||function(i){for(var r,t=1,e=arguments.length;t<e;t++){r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(i[n]=r[n])}return i},ie.apply(this,arguments)},vn=function(i,r){var t={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(t[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,e=Object.getOwnPropertySymbols(i);n<e.length;n++)r.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(i,e[n])&&(t[e[n]]=i[e[n]]);return t},At=ne.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,o=i.extend,a=vn(i,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),d=ne.useRef("_".concat(Cn()));return Ut(t,"".concat(e),{defIds:t.defIds,idSuffix:d.current},ie({ref:r,className:s},a),o)});function Ut(i,r,t,e,n){return ne.createElement(i.tag,ie(ie({key:r},_n(i,t,n)),e),(In(i,t).children||[]).map(function(o,a){return Ut(o,"".concat(r,"-").concat(i.tag,"-").concat(a),t,void 0,n)}))}function _n(i,r,t){var e=ie({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1),i.tag==="mask"&&e.id&&(e.id=e.id+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];a==="mask"&&typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))});var n=r.defIds;return!n||n.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 In(i,r){var t,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((t=i.children)===null||t===void 0)&&t.length)?ie(ie({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?ie(ie({},n),{attrs:ie(ie({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function Cn(){return Math.random().toString(36).substring(2,8)}At.displayName="UniverIcon";var yn={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"}}]},Nt=ne.forwardRef(function(i,r){return ne.createElement(At,Object.assign({},i,{id:"add-image-single",ref:r,icon:yn}))});Nt.displayName="AddImageSingle";const Ct={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),e=i.get(m.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,o=e.map(a=>{const{unitId:s,subUnitId:d,drawingId:g,drawingType:u}=a;return{unitId:s,subUnitId:d,drawingId:g,drawingType:u}});return r.executeCommand(Ie.id,{unitId:n,drawings:o})}},Ce={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(m.ISheetDrawingService),n=i.get(O.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 p={...c},{left:h=0,top:f=0}=c;return o===l.Direction.UP?p.top=f-1:o===l.Direction.DOWN?p.top=f+1:o===l.Direction.LEFT?p.left=h-1:o===l.Direction.RIGHT&&(p.left=h+1),{...u,transform:p,sheetTransform:H(p,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(Pe.id,{unitId:s,drawings:d})?(t.syncExecuteCommand(G.id,[s]),!0):!1}},kt="addition-and-subtraction-single",yt="sheet.menu.image";function Dn(i){return{id:yt,type:Y.MenuItemType.SUBITEMS,icon:kt,tooltip:"sheetImage.title",hidden$:Y.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),disabled$:O.getCurrentRangeDisable$(i,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function Mn(i){return{id:Ae.id,title:"sheetImage.upload.float",type:Y.MenuItemType.BUTTON,hidden$:Y.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function Tn(i){return{id:_t.id,title:"sheetImage.upload.cell",type:Y.MenuItemType.BUTTON,hidden$:Y.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}const Se={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelColumn:"univer-image-common-panel-column"},bn=i=>{var M;const r=Y.useDependency(l.ICommandService),t=Y.useDependency(l.LocaleService),e=Y.useDependency(U.IDrawingManagerService),n=Y.useDependency(W.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:s}=a,d=n.getRenderById(s),g=d==null?void 0:d.scene;if(g==null)return;const u=g.getTransformerByCreate(),[c,p]=ne.useState(!0),h=(M=a.anchorType)!=null?M:m.SheetDrawingAnchorType.Position,[f,S]=ne.useState(h);function w(T,y){const b=[];return T.forEach(I=>{const{oKey:k}=I,E=y.getDrawingOKey(k);if(E==null)return b.push(null),!0;const{unitId:B,subUnitId:A,drawingId:P,drawingType:D,anchorType:L,sheetTransform:j}=E;b.push({unitId:B,subUnitId:A,drawingId:P,anchorType:L,sheetTransform:j,drawingType:D})}),b}ne.useEffect(()=>{const T=u.clearControl$.subscribe(b=>{b===!0&&p(!1)}),y=u.changeStart$.subscribe(b=>{var E;const{objects:I}=b,k=w(I,e);if(k.length===0)p(!1);else if(k.length>=1){p(!0);const B=((E=k[0])==null?void 0:E.anchorType)||m.SheetDrawingAnchorType.Position;S(B)}});return()=>{y.unsubscribe(),T.unsubscribe()}},[]);function v(T){S(T);const y=e.getFocusDrawings();if(y.length===0)return;const b=y.map(I=>({unitId:I.unitId,subUnitId:I.subUnitId,drawingId:I.drawingId,anchorType:T}));r.executeCommand(Pe.id,{unitId:y[0].unitId,drawings:b})}const C=T=>T?"block":"none";return x.jsxs("div",{className:q.clsx(Se.imageCommonPanelGrid,Se.imageCommonPanelBorder),style:{display:C(c)},children:[x.jsx("div",{className:Se.imageCommonPanelRow,children:x.jsx("div",{className:q.clsx(Se.imageCommonPanelColumn,Se.imageCommonPanelTitle),children:x.jsx("div",{children:t.t("drawing-anchor.title")})})}),x.jsx("div",{className:q.clsx(Se.imageCommonPanelRow),children:x.jsx("div",{className:q.clsx(Se.imageCommonPanelColumn),children:x.jsxs(q.RadioGroup,{value:f,onChange:v,direction:"vertical",children:[x.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),x.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),x.jsx(q.Radio,{value:m.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})})]})},Rn=()=>{const i=Y.useDependency(U.IDrawingManagerService),r=i.getFocusDrawings(),[t,e]=ne.useState(r);return ne.useEffect(()=>{const n=i.focus$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&x.jsxs("div",{className:Se.imageCommonPanel,children:[x.jsx(pe.DrawingCommonPanel,{drawings:t}),x.jsx(bn,{drawings:t})]})},En={[Y.RibbonStartGroup.FORMULAS_INSERT]:{[yt]:{order:3,menuItemFactory:Dn,[Ae.id]:{order:0,menuItemFactory:Mn},[_t.id]:{order:1,menuItemFactory:Tn}}}};function ke(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 On={id:Ce.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_DOWN,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.DOWN}},Pn={id:Ce.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_UP,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.UP}},An={id:Ce.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_LEFT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.LEFT}},Un={id:Ce.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_RIGHT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.RIGHT}},Nn={id:Ct.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:ke,binding:Y.KeyCode.DELETE,mac:Y.KeyCode.BACKSPACE};var kn=Object.getOwnPropertyDescriptor,Wn=(i,r,t,e)=>{for(var n=e>1?void 0:e?kn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},ye=(i,r)=>(t,e)=>r(t,e,i);let Je=class extends l.Disposable{constructor(i,r,t,e,n,o){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(kt,Nt)),this.disposeWithMe(i.register(Rt,Rn))}_initMenus(){this._menuManagerService.mergeMenu(En)}_initCommands(){[Ae,_t,Oe,Ie,Pe,gt,G,ht,mt,St,Ce,Ct,ft].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[On,Pn,An,Un,Nn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Je=Wn([ye(0,l.Inject(Y.ComponentManager)),ye(1,Y.IMenuManagerService),ye(2,l.ICommandService),ye(3,Y.IShortcutService),ye(4,U.IDrawingManagerService),ye(5,l.Inject(_.SheetsSelectionsService))],Je);var Bn=Object.getOwnPropertyDescriptor,jn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Bn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},_e=(i,r)=>(t,e)=>r(t,e,i);function Ln(i,r,t,e,n){const{scaleX:o,scaleY:a}=r.getAncestorScale(),s=r.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN),d=e.getFreeze(),{startColumn:g,startRow:u,xSplit:c,ySplit:p}=d,h={left:!0,top:!0};if(!s)return{...i,absolute:h};const{left:f,right:S,top:w,bottom:v}=i;let{top:C,left:M,viewportScrollX:T,viewportScrollY:y}=s;const{boundsOfViewArea:b,scrollDirectionResponse:I}=n||{},{rowHeaderWidth:k,columnHeaderHeight:E}=t,B={top:E,left:k};b&&(l.Tools.isDefine(B.top)&&(B.top=b.top),l.Tools.isDefine(B.left)&&(B.left=b.left)),I==="HORIZONTAL"&&(y=0),I==="VERTICAL"&&(T=0);let A=0,P=0;const D=t.rowStartY(u-p)+E,L=t.colStartX(g-c)+k,j=t.rowStartY(u)+E,z=t.colStartX(g)+k;if(c===0)h.left=!1,A=(f-T)*o,P=(S-T)*o;else{const te=f-(L-k),J=S-(L-k);S<z?(A=te*o,P=J*o):f<=z&&S>=z?(A=te*o,P=Math.max(M,(S-T)*o)):f>z&&(h.left=!1,A=Math.max((f-T)*o,M),P=Math.max((S-T)*o,M))}let X=0,Z=0;if(p===0)h.top=!1,X=(w-y)*a,Z=(v-y)*a;else{const te=w-(D-E),J=v-(D-E);v<j?(X=te*a,Z=J*a):w<=j&&v>=j?(X=te*a,Z=Math.max(C,(v-y)*a)):w>j&&(h.top=!1,X=Math.max((w-y)*a,C),Z=Math.max((v-y)*a,C))}return A=Math.max(A,B.left),X=Math.max(X,B.top),P=Math.max(P,B.left),Z=Math.max(Z,B.top),{left:A,right:P,top:X,bottom:Z,absolute:h}}const le=(i,r,t,e,n)=>{const{scene:o}=r,{left:a,top:s,width:d,height:g,angle:u}=i,c={left:a,right:a+d,top:s,bottom:s+g},p=Ln(c,o,t,e,n),{scaleX:h,scaleY:f}=o.getAncestorScale();return{startX:p.left,endX:p.right,startY:p.top,endY:p.bottom,rotate:u,width:d*h,height:g*f,absolute:p.absolute}};R.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(t,e,n,o,a,s,d){super();ee(this,"_domLayerMap",new Map);ee(this,"_domLayerInfoMap",new Map);ee(this,"_transformChange$",new N.Subject);ee(this,"transformChange$",this._transformChange$.asObservable());ee(this,"_add$",new N.Subject);ee(this,"add$",this._add$.asObservable());ee(this,"_remove$",new N.Subject);ee(this,"remove$",this._remove$.asObservable());ee(this,"_hooks",[]);this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,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(N.filter(t=>t===l.LifecycleStages.Rendered),N.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(t,e){let n=this._domLayerMap.get(t);n||(n=new Map,this._domLayerMap.set(t,n));let o=n.get(e);return o||(o=new Map,n.set(e,o)),o}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const o=n.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:n,transformer:o,renderUnit:e,canvas:a}}_getFloatDomProps(t){let e;return this._hooks.forEach(n=>{e=n.onGetFloatDomProps(t)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var se,ce,Q;const{unitId:n,subUnitId:o,drawingId:a}=e,s=_.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!d||!s)return;const c=(se=this._renderManagerService.getRenderById(n))==null?void 0:se.with(O.SheetSkeletonManagerService).getSkeletonParam(o);if(!c)return;const{transform:p,drawingType:h,data:f}=d;if(h!==l.DrawingTypeEnum.DRAWING_DOM&&h!==l.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(n);if(S==null)return;const{scene:w,canvas:v}=S;if(p==null)return!0;if(u!==o)return;const{left:C,top:M,width:T,height:y,angle:b,flipX:I,flipY:k,skewX:E,skewY:B}=p,A=U.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),P=w.getObject(A);if(P!=null){P.transformByState({left:C,top:M,width:T,height:y,angle:b,flipX:I,flipY:k,skewX:E,skewY:B});return}const D={left:C,top:M,width:T,height:y,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},L=h===l.DrawingTypeEnum.DRAWING_CHART;if(L){const $=f?f.backgroundColor:"white";D.fill=$,D.rotateEnabled=!1,f&&f.border&&(D.stroke=f.border),D.paintFirst="stroke",D.strokeWidth=1,D.borderEnabled=!1,D.radius=8}const j=new W.Rect(A,D);L&&j.setObjectType(W.ObjectType.CHART),w.addObject(j,W.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&w.attachTransformerTo(j);const z=this._ensureMap(n,o),X=new l.DisposableCollection,Z=le(j,S.renderUnit,c.skeleton,s.worksheet),ae=new N.BehaviorSubject(Z),te={dispose:X,rect:j,position$:ae,unitId:n,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:ae,id:a,componentKey:d.componentKey,onPointerDown:$=>{v.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{v.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{v.dispatchEvent(new PointerEvent($.type,$))},onWheel:$=>{v.dispatchEvent(new WheelEvent($.type,$))},props:(Q=(ce=z.get(a))==null?void 0:ce.props)!=null?Q:this._getFloatDomProps(a),data:f,unitId:n});const J=j.onTransformChange$.subscribeEvent(()=>{const $=le(j,S.renderUnit,c.skeleton,s.worksheet);ae.next($)});X.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),J&&X.add(J),this._domLayerInfoMap.set(a,te),z.set(a,{...z.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{const{unitId:n,subUnitId:o,drawingId:a}=e,s=U.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{transformer:g,scene:u}=d,c=u.getObject(s);c!=null&&c.oKey&&g.clearControlByIds([c==null?void 0:c.oKey])})}))}_scrollUpdateListener(){const t=(e,n)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,n),s=Array.from(a.keys()),d=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),g=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(O.SheetSkeletonManagerService).getSkeletonParam(n);!o||!d||!g||s.forEach(c=>{const p=this._domLayerInfoMap.get(c);if(p){const h=le(p.rect,o.renderUnit,g.skeleton,d.worksheet,p);p.position$.next(h)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(e=>e?e.activeSheet$:N.of(null)),N.map(e=>{if(!e)return null;const n=e.getUnitId(),o=this._renderManagerService.getRenderById(n);return o?{render:o,unitId:n,subUnitId:e.getSheetId()}:null}),N.switchMap(e=>e?l.fromEventSubject(e.render.scene.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(N.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):N.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:o}=e;t(n,o)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n,o;if(e.id===O.SetZoomRatioOperation.id){const a=e.params,{unitId:s}=a;Array.from((o=(n=this._domLayerMap.get(s))==null?void 0:n.keys())!=null?o:[]).forEach(g=>{t(s,g)})}else if(e.id===_.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=e.params;t(a,s)}}))}_getPosition(t,e){var h;const{startX:n,endX:o,startY:a,endY:s}=t,d=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(O.ISheetSelectionRenderService);if(d==null)return;const g=d.getCellWithCoordByOffset(n,a);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:a-g.startY},c=d.getCellWithCoordByOffset(o,s);if(c==null)return;const p={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:s-c.startY};return{from:u,to:p}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const o={...n.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,o){const a=this._domLayerInfoMap.get(n),s=this._getSceneAndTransformerByDrawingSearch(t);if(a&&s){const{scene:d}=s,g=U.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=d.getObject(g);u&&u instanceof W.Rect&&u.setProps(o)}}addFloatDomToPosition(t,e){const n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=n,{initPosition:s,componentKey:d,data:g,allowTransform:u=!0}=t,c=e!=null?e:l.generateRandomId(),p=this._getPosition(s,o);if(p==null)return;this._ensureMap(o,a).set(c,t);const f={unitId:o,subUnitId:a,drawingId:c,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:p,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Oe.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:a,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:o,subUnitId:a}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(n.rect),e){this._ensureMap(o,a).delete(t);const g=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:t});if(!g)return;const u=this._sheetDrawingService.getBatchRemoveOp([g]),{redo:c,objects:p}=u;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:c,objects:p,type:m.DrawingApplyType.REMOVE})}}addHook(t){return this._hooks.push(t),{dispose:()=>{const e=this._hooks.findIndex(n=>n===t);this._hooks.splice(e,1)}}}addFloatDomToRange(t,e,n,o){var k,E,B,A,P;const a=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:d}=a,g=this._getSceneAndTransformerByDrawingSearch(s);if(!g)return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const c=(k=this._renderManagerService.getRenderById(s))==null?void 0:k.with(O.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,S=o!=null?o:l.generateRandomId(),{position:w,position$:v}=this._createRangePositionObserver(t,u,c.skeleton);if(this._getPosition(w,s)==null)return;this._ensureMap(s,d).set(S,e);const T=g.scene,{scaleX:y}=T.getAncestorScale(),b=Qe(w,n,y),I={unitId:s,subUnitId:d,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:b.startX,top:b.startY,width:b.width,height:b.height},data:h,allowTransform:f};{const{unitId:D,subUnitId:L,drawingId:j}=I,z=_.getSheetCommandTarget(this._univerInstanceService,{unitId:D,subUnitId:L}),X=I,Z=this._univerInstanceService.getUnit(D,l.UniverInstanceType.UNIVER_SHEET);if(!Z)return;const ae=Z.getActiveSheet().getSheetId();if(!X||!z)return;const te=(E=this._renderManagerService.getRenderById(D))==null?void 0:E.with(O.SheetSkeletonManagerService);if(!te)return;const J=te.getWorksheetSkeleton(L);if(!J)return;const{transform:se,drawingType:ce,data:Q}=X;if(ce!==l.DrawingTypeEnum.DRAWING_DOM&&ce!==l.DrawingTypeEnum.DRAWING_CHART)return;const $=this._getSceneAndTransformerByDrawingSearch(D);if($==null)return;const{scene:De,canvas:Me}=$;if(se==null||ae!==L)return;const{left:tt,top:nt,width:rt,height:it,angle:Mt,flipX:Tt,flipY:ot,skewX:at,skewY:Te}=se,st=U.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:L,drawingId:j}),ue=De.getObject(st);if(ue!=null){ue.transformByState({left:tt,top:nt,width:rt,height:it,angle:Mt,flipX:Tt,flipY:ot,skewX:at,skewY:Te});return}const oe={left:tt,top:nt,width:rt,height:it,zIndex:this._drawingManagerService.getDrawingOrder(D,L).length-1},be=ce===l.DrawingTypeEnum.DRAWING_CHART;if(be){const F=Q?Q.backgroundColor:"white";oe.fill=F,oe.rotateEnabled=!1,Q&&Q.border&&(oe.stroke=Q.border),oe.paintFirst="stroke",oe.strokeWidth=1,oe.borderEnabled=!1,oe.radius=8}const de=new W.Rect(st,oe);be&&de.setObjectType(W.ObjectType.CHART),De.addObject(de,W.DRAWING_OBJECT_LAYER_INDEX),X.allowTransform!==!1&&De.attachTransformerTo(de);const Be=this._ensureMap(D,L),ge=new l.DisposableCollection,ct=De.getMainViewport(),{rowHeaderWidth:Re,columnHeaderHeight:je}=J.skeleton,dt={top:je,left:Re,bottom:ct.bottom,right:ct.right},he={dispose:ge,rect:de,boundsOfViewArea:dt,domAnchor:n,unitId:D,subUnitId:L},V=le(de,$.renderUnit,J.skeleton,z.worksheet,he),Ee=new N.BehaviorSubject(V);he.position$=Ee;let Le={position$:Ee,id:j,componentKey:X.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:F=>{Me.dispatchEvent(new WheelEvent(F.type,F))},props:(A=(B=Be.get(j))==null?void 0:B.props)!=null?A:this._getFloatDomProps(j),data:Q,unitId:D};e.eventPassThrough&&(Le={...Le,onPointerDown:F=>{Me.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{Me.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{Me.dispatchEvent(new PointerEvent(F.type,F))}}),this._canvasFloatDomService.addFloatDom(Le),this.disposeWithMe(v.subscribe(F=>{var jt,Lt,Yt,Ft;const Bt=Qe({startX:F.startX,startY:F.startY,endX:F.endX,endY:F.endY,width:(jt=n.width)!=null?jt:F.width,height:(Lt=n.height)!=null?Lt:F.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Vn=U.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:L,drawingId:j}),Xn=new W.Rect(Vn,{left:Bt.startX,top:Bt.startY,width:(Yt=n.width)!=null?Yt:F.width,height:(Ft=n.height)!=null?Ft:F.height,zIndex:this._drawingManagerService.getDrawingOrder(D,L).length-1}),xn=le(Xn,$.renderUnit,J.skeleton,z.worksheet,he);Ee.next(xn)}));const Ye=(P=this._renderManagerService.getRenderById(D))==null?void 0:P.with(O.SheetSkeletonManagerService);Ye==null||Ye.currentSkeleton$.subscribe(F=>{F&&J.sheetId!==F.sheetId&&this._removeDom(S,!0)});const lt=de.onTransformChange$.subscribeEvent(()=>{const F=le(de,$.renderUnit,J.skeleton,z.worksheet,he);Ee.next(F)});ge.add(()=>{this._canvasFloatDomService.removeFloatDom(j)}),lt&&ge.add(lt),this._domLayerInfoMap.set(j,he),Be.set(j,{...Be.get(j)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(t,e,n,o){var b,I,k,E,B;const a=_.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=(b=this._renderManagerService.getRenderById(s))==null?void 0:b.with(O.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,S=o!=null?o:l.generateRandomId(),{position:w,position$:v}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,c.skeleton),C=w;if(C.startY=0,this._getPosition(w,s)==null)return;this._ensureMap(s,d).set(S,e);const y={unitId:s,subUnitId:d,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:C.startX,top:C.startY,width:C.width,height:C.height},data:h,allowTransform:f};{const{unitId:A,subUnitId:P,drawingId:D}=y,L=_.getSheetCommandTarget(this._univerInstanceService,{unitId:A,subUnitId:P}),j=y,z=this._univerInstanceService.getUnit(A,l.UniverInstanceType.UNIVER_SHEET);if(!z)return;const X=z.getActiveSheet().getSheetId();if(!j||!L)return;const Z=(I=this._renderManagerService.getRenderById(A))==null?void 0:I.with(O.SheetSkeletonManagerService);if(!Z)return;const ae=Z.getWorksheetSkeleton(P);if(!ae)return;const{transform:te,data:J}=j,se=this._getSceneAndTransformerByDrawingSearch(A);if(se==null)return;const{scene:ce,canvas:Q}=se;if(te==null||X!==P)return;const{left:$,top:De,width:Me,height:tt,angle:nt,flipX:rt,flipY:it,skewX:Mt,skewY:Tt}=te,ot=U.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:P,drawingId:D}),at=ce.getObject(ot);if(at!=null){at.transformByState({left:$,top:De,width:Me,height:tt,angle:nt,flipX:rt,flipY:it,skewX:Mt,skewY:Tt});return}const Te=Qe({startX:C.startX,startY:0,endX:w.endX,endY:w.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),st={left:Te.startX,top:Te.startY,width:Te.width,height:Te.height,zIndex:this._drawingManagerService.getDrawingOrder(A,P).length-1},ue=new W.Rect(ot,st);ce.addObject(ue,W.DRAWING_OBJECT_LAYER_INDEX),j.allowTransform!==!1&&ce.attachTransformerTo(ue);const oe=this._ensureMap(A,P),be=new l.DisposableCollection,de=ce.getMainViewport(),Be={top:0,left:de.left,bottom:de.bottom,right:de.right},ge={dispose:be,rect:ue,unitId:A,subUnitId:P,boundsOfViewArea:Be,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},ct=le(ue,se.renderUnit,ae.skeleton,L.worksheet,ge),Re=new N.BehaviorSubject(ct);ge.position$=Re;let je={position$:Re,id:D,componentKey:j.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:V=>{Q.dispatchEvent(new WheelEvent(V.type,V))},props:(E=(k=oe.get(D))==null?void 0:k.props)!=null?E:this._getFloatDomProps(D),data:J,unitId:A};e.eventPassThrough&&(je={...je,onPointerDown:V=>{Q.dispatchEvent(new PointerEvent(V.type,V))},onPointerMove:V=>{Q.dispatchEvent(new PointerEvent(V.type,V))},onPointerUp:V=>{Q.dispatchEvent(new PointerEvent(V.type,V))}}),this._canvasFloatDomService.addFloatDom(je);const dt=ue.onTransformChange$.subscribeEvent(()=>{const V=le(ue,se.renderUnit,ae.skeleton,L.worksheet,ge);Re.next(V)});this.disposeWithMe(v.subscribe(V=>{const Ee=Qe({startX:V.startX,startY:0,endX:V.endX,endY:V.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Le=U.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:P,drawingId:D}),Ye=new W.Rect(Le,{left:Ee.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(A,P).length-1}),lt=le(Ye,se.renderUnit,ae.skeleton,L.worksheet,ge);Re.next(lt)}));const he=(B=this._renderManagerService.getRenderById(A))==null?void 0:B.with(O.SheetSkeletonManagerService);he==null||he.currentSkeleton$.subscribe(V=>{V&&c.sheetId!==V.sheetId&&this._removeDom(S,!0)}),be.add(()=>{this._canvasFloatDomService.removeFloatDom(D)}),dt&&be.add(dt),this._domLayerInfoMap.set(D,ge),oe.set(D,{...oe.get(D)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:o,startColumn:a}=t;const s=We(o,a,n),d=new N.BehaviorSubject(s),g=We(t.endRow,t.endColumn,n),u=new N.BehaviorSubject(g),c=()=>{const v=We(o,a,n),C=We(t.endRow,t.endColumn,n);d.next(v),u.next(C)},p=new l.DisposableCollection;p.add(e.engine.clientRect$.subscribe(()=>c())),p.add(this._commandService.onCommandExecuted(v=>{if(v.id===_.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(M=>M.row===o)>-1){c();return}(_.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(v.id)>-1||v.id===O.SetScrollOperation.id||v.id===O.SetZoomRatioOperation.id)&&c()}));const h=(v,C)=>{o=v,a=C,c()},f=()=>({rotate:0,width:g.right-s.left,height:g.bottom-s.top,absolute:{left:!0,top:!0},startX:s.left,startY:s.top,endX:g.right,endY:g.bottom}),S=d.pipe(N.map(v=>{const C=We(t.endRow,t.endColumn,n);return{rotate:0,width:C.right-v.left,height:C.bottom-v.top,absolute:{left:!0,top:!0},startX:v.left,startY:v.top,endX:C.right,endY:C.bottom}})),w=f();return{position$:S,position:w,updateRowCol:h,topLeftPos$:d,rightBottomPos$:u,disposable:p}}},R.SheetCanvasFloatDomManagerService=jn([_e(0,l.Inject(W.IRenderManagerService)),_e(1,l.IUniverInstanceService),_e(2,l.Inject(l.ICommandService)),_e(3,U.IDrawingManagerService),_e(4,l.Inject(Y.CanvasFloatDomService)),_e(5,m.ISheetDrawingService),_e(6,l.Inject(l.LifecycleService))],R.SheetCanvasFloatDomManagerService);function We(i,r,t){const e=t.getCellWithCoordByIndex(i,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Qe(i,r,t){var g,u;t=t!=null?t:1;const e=i.endX-i.startX,n=i.endY-i.startY,o=(g=r==null?void 0:r.width)!=null?g:e,a=(u=r==null?void 0:r.height)!=null?u:n;let s=0,d=0;if(r){if(r.horizonOffsetAlign==="right"){const c=et(r.marginX,e*t);s=i.endX-c-o}else s=i.startX+et(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const c=et(r.marginY,n*t);d=i.endY-c-a}else d=i.startY+et(r.marginY,n)}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 et(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const t=Number.parseFloat(i);return r*t/100}var Yn=Object.defineProperty,Fn=Object.getOwnPropertyDescriptor,$n=(i,r,t)=>r in i?Yn(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,Gn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Fn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Dt=(i,r)=>(t,e)=>r(t,e,i),Wt=(i,r,t)=>$n(i,typeof r!="symbol"?r+"":r,t);const Hn="SHEET_IMAGE_UI_PLUGIN";R.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=bt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:o,...a}=l.merge({},bt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig($t,a)}onStarting(){l.registerDependencies(this._injector,[[R.SheetCanvasFloatDomManagerService],[Je],[$e],[Ze],[ze],[Ke],[He],[xe],[Ve]]),l.touchDependencies(this._injector,[[R.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[Ke]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[ze],[Ze],[Je],[He],[xe],[Ve]])}onSteady(){this._injector.get($e)}_registerRenderModules(){[[R.SheetDrawingUpdateController],[It],[pt]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}},Wt(R.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),Wt(R.UniverSheetsDrawingUIPlugin,"pluginName",Hn),R.UniverSheetsDrawingUIPlugin=Gn([l.DependentOn(U.UniverDrawingPlugin,we.UniverDocsDrawingPlugin,pe.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),Dt(1,l.Inject(l.Injector)),Dt(2,W.IRenderManagerService),Dt(3,l.IConfigService)],R.UniverSheetsDrawingUIPlugin),R.ClearSheetDrawingTransformerOperation=G,R.DeleteDrawingsCommand=Ct,R.EditSheetDrawingOperation=ht,R.GroupSheetDrawingCommand=mt,R.InsertFloatImageCommand=Ae,R.InsertSheetDrawingCommand=Oe,R.MoveDrawingsCommand=Ce,R.RemoveSheetDrawingCommand=Ie,R.SHEETS_IMAGE_MENU_ID=yt,R.SetDrawingArrangeCommand=ft,R.SetSheetDrawingCommand=Pe,R.SidebarSheetDrawingOperation=gt,R.UngroupSheetDrawingCommand=St,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})});
1
+ (function(R,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/jsx-runtime"),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/jsx-runtime","react","@univerjs/docs-ui","@univerjs/design"],l):(R=typeof globalThis<"u"?globalThis:R||self,l(R.UniverSheetsDrawingUi={},R.UniverCore,R.UniverDocsDrawing,R.UniverDrawing,R.UniverDrawingUi,R.UniverEngineRender,R.UniverSheetsDrawing,R.UniverSheetsUi,R.UniverUi,R.rxjs,R.UniverSheets,R.React,R.React,R.UniverDocsUi,R.UniverDesign))})(this,function(R,l,we,U,pe,B,m,O,Y,N,I,x,ne,ut,q){"use strict";var Kn=Object.defineProperty;var zn=(R,l,we)=>l in R?Kn(R,l,{enumerable:!0,configurable:!0,writable:!0,value:we}):R[l]=we;var ee=(R,l,we)=>zn(R,typeof l!="symbol"?l+"":l,we);const $t="sheets-drawing-ui.config",Tt={},G={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(i,r)=>{const t=i.get(B.IRenderManagerService);return r.forEach(e=>{var n,o;(o=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},_e={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var y,M,T;const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(I.SheetInterceptorService),o=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:a}=r,s=[];a.forEach(C=>{const{unitId:b}=C;s.push(b)});const d=o.getBatchRemoveOp(a),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,f=n.onCommandExecute({id:_e.id,params:r}),S={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:p,objects:h,type:m.DrawingApplyType.REMOVE}},w={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:c,objects:h,type:m.DrawingApplyType.INSERT}};return l.sequenceExecute([...(y=f.preRedos)!=null?y:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(M=f.preUndos)!=null?M:[],w,...f.undos,{id:G.id,params:s}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:s}]}),!0):!1}},bt="COMPONENT_SHEET_DRAWING_PANEL",gt={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{const t=i.get(Y.ISidebarService),e=i.get(l.LocaleService),n=i.get(l.IUniverInstanceService),o=i.get(l.ICommandService);if(!I.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:bt},onClose:()=>{o.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},ht={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(i,r)=>{const t=i.get(l.ICommandService);return r==null?!1:(t.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[r]),t.executeCommand(gt.id,{value:"open"}),!0)}},Fe={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",uploadLoadingBodyText:"univer-upload-loading-body-text"},Gt=()=>{const i=Y.useDependency(U.IImageIoService),r=Y.useDependency(l.LocaleService),[t,e]=ne.useState(0);return ne.useEffect(()=>{const n=i.change$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[i]),x.jsx("div",{style:{display:t>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:`${r.t("uploadLoading.loading")}: ${t}`})]})})};var Ht=Object.getOwnPropertyDescriptor,Vt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Ht(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},me=(i,r)=>(t,e)=>r(t,e,i);let $e=class extends l.RxDisposable{constructor(r,t,e,n,o,a,s,d){super();ee(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=t,this._canvasPopManagerService=e,this._renderManagerService=n,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._commandService=d,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(Y.BuiltInUIPart.CONTENT,()=>Y.connectInjector(Gt,this._injector))}_dispose(r){const t=r.getUnitId();this._renderManagerService.removeRender(t)}_create(r){if(!r)return;const t=r.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(r){const t=r.getAllObjectsByOrder();for(const e of t)if(e instanceof pe.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const t=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(l.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const a=e.getSelectedObjectMap();if(a.size>1){n==null||n.dispose();return}const s=a.values().next().value;if(!s)return;const d=s.oKey,g=this._drawingManagerService.getDrawingOKey(d);if(!g)return;const{unitId:u,subUnitId:c,drawingId:p,drawingType:h}=g,f=g.data;if(f&&f.disablePopup)return;n==null||n.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,c,p,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:pe.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,c,p,h)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[l.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:ht.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:_e.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:pe.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:pe.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===l.DrawingTypeEnum.DRAWING_DOM}]}};$e=Vt([me(0,l.Inject(l.Injector)),me(1,U.IDrawingManagerService),me(2,l.Inject(O.SheetCanvasPopManagerService)),me(3,B.IRenderManagerService),me(4,l.IUniverInstanceService),me(5,l.IContextService),me(6,l.Inject(Y.IUIPartsService)),me(7,l.ICommandService)],$e);function K(i,r,t){const{from:e,to:n,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:d=0,skewY:g=0}=i,u=t.getCurrent();if(u==null)return;const c=O.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:p,top:h,width:f,height:S}=c;const w=t.getCurrentSkeleton(),v=w.rowHeaderWidth+w.columnTotalWidth,y=w.columnHeaderHeight+w.rowTotalHeight;return p+f>v&&(p=v-f),h+S>y&&(h=y-S),{flipY:o,flipX:a,angle:s,skewX:d,skewY:g,left:p,top:h,width:f,height:S}}function H(i,r){const{left:t=0,top:e=0,width:n=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:d=0,skewX:g=0,skewY:u=0}=i,c=r.getCellWithCoordByOffset(t,e);if(c==null)return;const p={column:c.actualColumn,columnOffset:B.precisionTo(t-c.startX,1),row:c.actualRow,rowOffset:B.precisionTo(e-c.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+o);if(h==null)return;const f={column:h.actualColumn,columnOffset:B.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:B.precisionTo(e+o-h.startY,1)};return{flipY:a,flipX:s,angle:d,skewX:g,skewY:u,from:p,to:f}}var Xt=Object.getOwnPropertyDescriptor,xt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Xt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ge=(i,r)=>(t,e)=>r(t,e,i);let pt=class extends l.Disposable{constructor(i,r,t,e,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,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 t=i[r];for(const e in t.data){const n=t.data[e];n.transform=K(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};pt=xt([Ge(1,m.ISheetDrawingService),Ge(2,U.IDrawingManagerService),Ge(3,l.Inject(O.ISheetSelectionRenderService)),Ge(4,l.Inject(O.SheetSkeletonManagerService))],pt);function Kt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:a,drawingId:s}=e,d=B.getGroupState(0,0,n.map(c=>c.transform||{})),g=n.map(c=>{const p=c.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:S}=c;return{unitId:h,subUnitId:f,drawingId:S,transform:{...p,left:p.left-d.left,top:p.top-d.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:d};r.push({parent:u,children:g})}),r}function zt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:a,drawingId:s,transform:d={width:0,height:0}}=e;if(d==null)return;const g=n.map(c=>{const{transform:p}=c,{unitId:h,subUnitId:f,drawingId:S}=c,w=B.transformObjectOutOfGroup(p||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:f,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:g})}),r}const mt={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=n.getGroupDrawingOp(r),{unitId:s,subUnitId:d,undo:g,redo:u,objects:c}=a;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:d,objects:zt(c),type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!0):!1}},Oe={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var y,M,T;const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService),o=i.get(I.SheetInterceptorService);if(!r)return!1;const a=r.drawings,s=a.map(C=>C.unitId),d=n.getBatchAddOp(a),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,f=o.onCommandExecute({id:Oe.id,params:r}),S={id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT}},w={id:m.SetDrawingApplyMutation.id,params:{op:c,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(y=f.preRedos)!=null?y:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(M=f.preUndos)!=null?M:[],w,...f.undos,{id:G.id,params:s}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:s}]}),!0):!1}},ft={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService);if(!r)return!1;const n=i.get(m.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:d}=r,g={unitId:o,subUnitId:a,drawingIds:s};let u;if(d===l.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):d===l.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):d===l.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):d===l.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:c,redo:p,undo:h}=u;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:p,unitId:o,subUnitId:a,objects:c,type:m.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:c,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:o,subUnitId:a,objects:c,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}},Pe={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=n.getBatchUpdateOp(o),{unitId:s,subUnitId:d,undo:g,redo:u,objects:c}=a;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:s,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:d,op:g,objects:c,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}]}),!0):!1}},St={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=n.getUngroupDrawingOp(r),{unitId:s,subUnitId:d,undo:g,redo:u,objects:c}=a;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:d,objects:Kt(c),type:m.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};var qt=Object.getOwnPropertyDescriptor,Zt=(i,r,t,e)=>{for(var n=e>1?void 0:e?qt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},re=(i,r)=>(t,e)=>r(t,e,i);function Jt(i,r,t){const e=t*Math.PI/180,n=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:n,rotatedHeight:o}}function wt(i,r,t,e,n){var y;const{rotatedHeight:o,rotatedWidth:a}=Jt(t,e,n),d=i.get(B.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const u=(y=d.with(O.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:y.skeleton;if(u==null)return!1;const c=u.getCellByIndex(r.row,r.col),p=c.mergeInfo.endX-c.mergeInfo.startX-2,h=c.mergeInfo.endY-c.mergeInfo.startY-2,f=a/o,w=Math.ceil(Math.min(p,h*f))/a,v=!w||Number.isNaN(w)?.001:w;return{width:t*v,height:e*v}}R.SheetDrawingUpdateController=class extends l.Disposable{constructor(t,e,n,o,a,s,d,g,u,c,p,h,f){super();ee(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=o,this._imageIoService=a,this._fileOpenerService=s,this._sheetDrawingService=d,this._drawingManagerService=g,this._contextService=u,this._messageService=c,this._localeService=p,this._injector=f,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const t=await this._fileOpenerService.openFile({multiple:!0,accept:U.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),e=t.length;return e>U.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(U.DRAWING_IMAGE_COUNT_LIMIT))}),!1):e===0?!1:(t.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const e=(await this._fileOpenerService.openFile({multiple:!1,accept:U.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(t,e){return this._insertCellImage(t,e)}async insertFloatImageByFile(t){let e;try{e=await this._imageIoService.saveImage(t)}catch(M){const T=M.message;T===U.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(U.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):T===U.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):T===U.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const n=this._getUnitInfo(),{unitId:o,subUnitId:a}=n,{imageId:s,imageSourceType:d,source:g,base64Cache:u}=e,{width:c,height:p,image:h}=await U.getImageSize(u||""),{width:f,height:S}=this._context.scene;this._imageIoService.addImageSourceCache(g,d,h);let w=1;if(c>U.DRAWING_IMAGE_WIDTH_LIMIT||p>U.DRAWING_IMAGE_HEIGHT_LIMIT){const M=U.DRAWING_IMAGE_WIDTH_LIMIT/c,T=U.DRAWING_IMAGE_HEIGHT_LIMIT/p;w=Math.max(M,T)}const v=this._getImagePosition(c*w,p*w,f,S);if(v==null)return;const y={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:d,source:g,transform:K(v,this._selectionRenderService,this._skeletonManagerService),sheetTransform:v};return this._commandService.executeCommand(Oe.id,{unitId:o,drawings:[y]})}async _insertCellImage(t,e){var y,M;let n;try{n=await this._imageIoService.saveImage(t)}catch(T){const C=T.message;C===U.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(U.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===U.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===U.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:o,imageSourceType:a,source:s,base64Cache:d}=n,{width:g,height:u,image:c}=await U.getImageSize(d||"");this._imageIoService.addImageSourceCache(s,a,c);const p=this._workbookSelections.getCurrentLastSelection();if(!p)return!1;const h=l.createDocumentModelWithStyle("",{}),f=wt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:p.primary.actualRow,col:p.primary.actualColumn},g,u,0);if(!f)return!1;const S={size:{width:f.width,height:f.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},w={unitId:h.getUnitId(),subUnitId:h.getUnitId(),drawingId:o,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:s,transform:ut.docDrawingPositionToTransform(S),docTransform:S,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},v=l.BuildTextUtils.drawing.add({documentDataModel:h,drawings:[w],selection:{collapsed:!0,startOffset:0,endOffset:0}});return v?(h.apply(v),this._commandService.syncExecuteCommand(I.SetRangeValuesCommand.id,{value:{[(y=e==null?void 0:e.row)!=null?y:p.primary.actualRow]:{[(M=e==null?void 0:e.col)!=null?M:p.primary.actualColumn]:{p:h.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,f;const{width:n,height:o,image:a}=await U.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,l.ImageSourceType.URL,a);const s=this._workbookSelections.getCurrentLastSelection();if(!s)return!1;const d=l.createDocumentModelWithStyle("",{}),g=wt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:s.primary.actualRow,col:s.primary.actualColumn},n,o,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},c={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:t,transform:ut.docDrawingPositionToTransform(u),docTransform:u,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},p=l.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[c],selection:{collapsed:!0,startOffset:0,endOffset:0}});return p?(d.apply(p),this._commandService.syncExecuteCommand(I.SetRangeValuesCommand.id,{value:{[(h=e==null?void 0:e.row)!=null?h:s.primary.actualRow]:{[(f=e==null?void 0:e.col)!=null?f:s.primary.actualColumn]:{p:d.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}_getUnitInfo(){const t=this._context.unit,e=t.getActiveSheet(),n=t.getUnitId(),o=e.getSheetId();return{unitId:n,subUnitId:o}}_getImagePosition(t,e,n,o){const a=this._workbookSelections.getCurrentSelections();let s={startRow:0,endRow:0,startColumn:0,endColumn:0};a&&a.length>0&&(s=a[a.length-1].range);const d=O.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);if(d==null)return;let{startColumn:g,startRow:u,startX:c,startY:p}=d,h=!1;if(c+t>n&&(c=n-t,c<0&&(c=0,t=n),h=!0),p+e>o&&(p=o-e,p<0&&(p=0,e=o),h=!0),h){const v=this._selectionRenderService.getCellWithCoordByOffset(c,p);if(v==null)return;c=v.startX,p=v.startY,g=v.actualColumn,u=v.actualRow}const f={column:g,columnOffset:0,row:u,rowOffset:0},S=this._selectionRenderService.getCellWithCoordByOffset(c+t,p+e);if(S==null)return;const w={column:S.actualColumn,columnOffset:c+t-S.startX,row:S.actualRow,rowOffset:p+e-S.startY};return{from:f,to:w}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:o,arrangeType:a}=t;this._commandService.executeCommand(ft.id,{unitId:e,subUnitId:n,drawingIds:o,arrangeType:a})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:o,subUnitId:a,drawingId:s,drawingType:d,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:s});if(u==null||u.unitId!==this._context.unitId)return;const c=H({...u.transform,...g},this._selectionRenderService);if(c==null)return;const p={...n,transform:{...u.transform,...g,...K(c,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...c}};e.push(p)}),e.length>0&&this._commandService.executeCommand(Pe.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(mt.id,t);const{unitId:e,subUnitId:n,drawingId:o}=t[0].parent;this._commandService.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:o}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(St.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}},R.SheetDrawingUpdateController=Zt([re(1,l.Inject(O.SheetSkeletonManagerService)),re(2,l.ICommandService),re(3,O.ISheetSelectionRenderService),re(4,U.IImageIoService),re(5,Y.ILocalFileService),re(6,m.ISheetDrawingService),re(7,U.IDrawingManagerService),re(8,l.IContextService),re(9,Y.IMessageService),re(10,l.Inject(l.LocaleService)),re(11,l.Inject(I.SheetsSelectionsService)),re(12,l.Inject(l.Injector))],R.SheetDrawingUpdateController);var Qt=Object.getOwnPropertyDescriptor,en=(i,r,t,e)=>{for(var n=e>1?void 0:e?Qt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ie=(i,r)=>(t,e)=>r(t,e,i);function Rt(i,r,t){var e,n,o,a;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((a=(o=t.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const s=t.p.drawings[t.p.drawingsOrder[0]],d=wt(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,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let He=class extends l.Disposable{constructor(i,r,t,e,n,o){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=o,this._handleInitEditor(),this._initCellContentInterceptor(),this._initDisableEdit()}_initDisableEdit(){this.disposeWithMe(this._commandService.beforeCommandExecuted(i=>{var r,t,e;if(i.id===O.SetCellEditVisibleOperation.id){const n=i.params,{visible:o,eventType:a}=n;if(o&&a===B.DeviceInputEventType.Dblclick){const s=this._editorBridgeService.getEditCellState();if(((e=(t=(r=s==null?void 0:s.documentLayoutObject.documentModel)==null?void 0:r.getDrawingsOrder())==null?void 0:t.length)!=null?e:0)>0)throw new Error("Can not edit when there are drawings.")}}}))}_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===ut.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))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(I.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:I.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,t)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0},Rt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),t(i)}}))}};He=en([Ie(0,l.ICommandService),Ie(1,l.Inject(I.SheetInterceptorService)),Ie(2,l.Inject(l.Injector)),Ie(3,U.IDrawingManagerService),Ie(4,l.Inject(we.DocDrawingController)),Ie(5,l.Inject(O.IEditorBridgeService))],He);var tn=Object.getOwnPropertyDescriptor,nn=(i,r,t,e)=>{for(var n=e>1?void 0:e?tn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Et=(i,r)=>(t,e)=>r(t,e,i);let Ve=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,t,e)=>{new l.ObjectMatrix(e).forValue((n,o,a)=>{Rt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},a)})}}))}};Ve=nn([Et(0,l.Inject(O.IAutoFillService)),Et(1,l.Inject(l.Injector))],Ve);var rn=Object.getOwnPropertyDescriptor,on=(i,r,t,e)=>{for(var n=e>1?void 0:e?rn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Xe=(i,r)=>(t,e)=>r(t,e,i);let xe=class extends l.Disposable{constructor(r,t,e,n){super();ee(this,"_isSetCursor",!1);this._hoverManagerService=r,this._renderManagerService=t,this._selectionsService=e,this._drawingRenderService=n}_initHover(){}_initImageClick(){}};xe=on([Xe(0,l.Inject(O.HoverManagerService)),Xe(1,l.Inject(B.IRenderManagerService)),Xe(2,l.Inject(I.SheetsSelectionsService)),Xe(3,l.Inject(pe.DrawingRenderService))],xe);const Ae={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{var a,s;const t=i.get(l.IUniverInstanceService),e=i.get(B.IRenderManagerService),n=(a=B.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:a.with(R.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const d=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(d)).every(g=>g)}else return(s=n.insertFloatImage())!=null?s:!1}},vt={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:i=>{var e,n;const r=i.get(l.IUniverInstanceService),t=i.get(B.IRenderManagerService);return(n=(e=B.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,r,t))==null?void 0:e.with(R.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}};var an=Object.getOwnPropertyDescriptor,sn=(i,r,t,e)=>{for(var n=e>1?void 0:e?an(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ue=(i,r)=>(t,e)=>r(t,e,i);const Ot="image/png";function cn(i){const r=i.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=t.charCodeAt(o);return new Blob([n],{type:Ot})}function dn(i){const r=new ClipboardItem({[Ot]:cn(i)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function ln(){function i(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const r=document.activeElement,t=i();return document.body.appendChild(t),t.focus(),()=>{t.blur(),document.body.removeChild(t),r instanceof HTMLElement&&r.focus()}}const Pt=[O.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,O.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,O.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,O.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let Ke=class extends l.Disposable{constructor(r,t,e,n,o){super();ee(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const o=this._focusedDrawings;if(o.length>0){const[a]=o;if(n===O.COPY_TYPE.CUT){const d={unitId:r,drawings:[a]};this._commandService.executeCommand(_e.id,d)}setTimeout(()=>{const d=ln();a.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&a.imageSourceType===U.ImageSourceType.BASE64?dn(a.source):this._clipboardInterfaceService.writeText(""),d()},200);const s={unitId:a.unitId,subUnitId:a.subUnitId,drawings:[a]};this._copyInfo=s}else{const a=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=a}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=O.COPY_TYPE.COPY,pasteType:a}=n,{range:s}=r||{},{range:d,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:a,unitId:g,subUnitId:u,pasteRange:d},{copyRange:s,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:a},O.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:O.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},O.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:O.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},O.COPY_TYPE.COPY);{const e=t.filter(n=>n.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Ae.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var p;const n=(p=this._renderManagerService.getRenderById(r))==null?void 0:p.with(O.SheetSkeletonManagerService);if(!n)return;const o=n.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:s,startY:d,endY:g}=o,u=this._drawingService.getDrawingData(r,t),c=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const f=u[h],{transform:S}=f;if(f.anchorType!==m.SheetDrawingAnchorType.Both||!S)return;const{left:w=0,top:v=0,width:y=0,height:M=0}=S,{drawingStartX:T,drawingEndX:C,drawingStartY:b,drawingEndY:_}={drawingStartX:w,drawingEndX:w+y,drawingStartY:v,drawingEndY:v+M};a<=T&&C<=s&&d<=b&&_<=g&&c.push(f)}),c.length)return{copyRange:e,drawings:c,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Pt.includes(e))return{redos:[],undos:[]};const{unitId:o,subUnitId:a,range:s}=n,d=this._renderManagerService.getRenderById(o),g=d==null?void 0:d.with(O.SheetSkeletonManagerService),u=d==null?void 0:d.with(O.ISheetSelectionRenderService),c=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:p}=c,h=O.discreteRangeToRange(s);return this._generateMutations(p,{unitId:o,subUnitId:a,isCut:t===O.COPY_TYPE.CUT,getTransform:(f,S)=>{var y;const w=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),v={...f,left:w==null?void 0:w.startX,top:w==null?void 0:w.startY};return{transform:v,sheetTransform:(y=H(v,u))!=null?y:S}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:o,isCut:a}=t,s=[],d=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:c,sheetTransform:p}=u;if(!c)return;const h=o(c,p),f={...u,unitId:e,subUnitId:n,drawingId:a?u.drawingId:l.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(a){const{undo:S,redo:w,objects:v}=g.getBatchUpdateOp([f]);s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:w,objects:v}}),d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:S,objects:v}})}else{const{undo:S,redo:w,objects:v}=g.getBatchAddOp([f]);s.push({id:m.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:v,type:m.DrawingApplyType.INSERT}}),d.push({id:m.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:n,objects:v,type:m.DrawingApplyType.REMOVE}})}}),{redos:s,undos:d}}_generateRangeDrawingsPasteMutations(r,t){var k;const{unitId:e,subUnitId:n,pasteType:o,pasteRange:a}=r,{copyRange:s,copyType:d}=t;if(Pt.includes(o))return{redos:[],undos:[]};const g=(k=this._renderManagerService.getRenderById(e))==null?void 0:k.with(O.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!s)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:O.discreteRangeToRange(a)},pasteType:o},d);const{ranges:[c,p],mapFunc:h}=O.virtualizeDiscreteRanges([s,a]),{row:f,col:S}=h(c.startRow,c.startColumn),{row:w,col:v}=h(p.startRow,p.startColumn),y=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:S,endColumn:S}),M=g.attachRangeWithCoord({startRow:w,endRow:w,startColumn:v,endColumn:v});if(!y||!M||!this._copyInfo)return{redos:[],undos:[]};const T=M.startX-y.startX,C=M.startY-y.startY,b=w-f,_=v-S;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(E,W)=>{var A,P;return{transform:{...E,left:((A=E==null?void 0:E.left)!=null?A:0)+T,top:((P=E==null?void 0:E.top)!=null?P:0)+C},sheetTransform:{...W,to:{...W.to,row:W.to.row+b,column:W.to.column+_},from:{...W.from,row:W.from.row+b,column:W.from.column+_}}}},isCut:d===O.COPY_TYPE.CUT})}};Ke=sn([Ue(0,O.ISheetClipboardService),Ue(1,B.IRenderManagerService),Ue(2,U.IDrawingManagerService),Ue(3,Y.IClipboardInterfaceService),Ue(4,l.ICommandService)],Ke);var un=Object.getOwnPropertyDescriptor,gn=(i,r,t,e)=>{for(var n=e>1?void 0:e?un(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ne=(i,r)=>(t,e)=>r(t,e,i);let ze=class extends l.Disposable{constructor(i,r,t,e,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([i,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingVisible(!1);return}const a=e.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new I.WorkbookViewPermission(a).id,new I.WorksheetViewPermission(a,s).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,o)})):(this._drawingManagerService.setDrawingVisible(!1),N.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(i,r){this._drawingManagerService.setDrawingVisible(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),a=this._renderManagerService.getRenderById(t),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===B.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.removeObject(g)})}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([i,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingEditable(!1);return}const a=e.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new I.WorkbookEditablePermission(a).id,new I.WorksheetEditPermission(a,s).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,o)})):(this._drawingManagerService.setDrawingEditable(!1),N.EMPTY))).subscribe())}_handleDrawingEditableFalse(i,r){this._drawingManagerService.setDrawingEditable(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),a=this._renderManagerService.getRenderById(t),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===B.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.detachTransformerFrom(g)})}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=t.getUnitId(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),d=s==null?void 0:s.scene;if(!d)return N.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new I.WorkbookViewPermission(o).id,new I.WorksheetViewPermission(o,a).id]).pipe(N.map(c=>c.every(p=>p.value)),N.distinctUntilChanged()).pipe(N.map(c=>({permission:c,scene:d,transformer:g,unitId:o,subUnitId:a})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingVisible(t);const s=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(o,a),g=Object.values(d);t?this._drawingManagerService.addNotification(g):(s.forEach(u=>{u.classType===B.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),o=e==null?void 0:e.getSheetId();if(!n||!o)return;const a=this._drawingManagerService.getDrawingData(n,o),s=Object.values(a);this._drawingManagerService.addNotification(s)}}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=t.getUnitId(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),d=s==null?void 0:s.scene;if(!d)return N.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new I.WorkbookEditablePermission(o).id,new I.WorksheetEditPermission(o,a).id]).pipe(N.map(c=>c.every(p=>p.value)),N.distinctUntilChanged()).pipe(N.map(c=>({permission:c,scene:d,transformer:g,unitId:o,subUnitId:a})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingEditable(t);const s=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(o,a),g=Object.values(d);t?(s.forEach(u=>{u.classType===B.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(s.forEach(u=>{u.classType===B.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const o=n.getSheetId(),a=this._renderManagerService.getRenderById(e),s=a==null?void 0:a.scene;if(!s)return;const d=this._drawingManagerService.getDrawingData(e,o),g=Object.values(d);this._drawingManagerService.setDrawingEditable(!0),s.getAllObjectsByOrder().forEach(c=>{c.classType===B.RENDER_CLASS_TYPE.IMAGE&&g.some(p=>c.oKey.includes(p.drawingId))&&s.detachTransformerFrom(c)})}}))}};ze=gn([Ne(0,U.IDrawingManagerService),Ne(1,B.IRenderManagerService),Ne(2,l.IPermissionService),Ne(3,l.IUniverInstanceService),Ne(4,l.Inject(l.UserManagerService))],ze);var hn=Object.getOwnPropertyDescriptor,pn=(i,r,t,e)=>{for(var n=e>1?void 0:e?hn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},qe=(i,r)=>(t,e)=>r(t,e,i);let Ze=class extends l.Disposable{constructor(i,r,t,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,t)=>{const{unitId:e,scene:n,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],n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,o=this._renderManagerService.getRenderById(e);if(!o)return t(i);const a=o.with(O.SheetSkeletonManagerService).getSkeletonParam(n);if(!a)return t(i);const s=this._drawingManagerService.getDrawingDataForUnit(e),d=s==null?void 0:s[r.subUnitId];if(!d)return t(i);const{scaleX:g,scaleY:u}=o.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},p=d.order.map(h=>d.data[h]).filter(h=>h.drawingType!==l.DrawingTypeEnum.DRAWING_DOM);return p.length?(p.forEach(h=>{if(!h.groupId&&h.transform&&l.Tools.isDefine(h.transform.left)&&l.Tools.isDefine(h.transform.top)&&l.Tools.isDefine(h.transform.width)&&l.Tools.isDefine(h.transform.height)){const f=a.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});f.column<c.startColumn&&(c.startColumn=f.column),f.row<c.startRow&&(c.startRow=f.row),c.endRow<S.row&&(c.endRow=S.row),c.endColumn<S.column&&(c.endColumn=S.column)}}),t(c)):t(i)}}))}};Ze=pn([qe(0,l.Inject(O.SheetPrintInterceptorService)),qe(1,l.Inject(pe.DrawingRenderService)),qe(2,U.IDrawingManagerService),qe(3,B.IRenderManagerService)],Ze);var mn=Object.getOwnPropertyDescriptor,fn=(i,r,t,e)=>{for(var n=e>1?void 0:e?mn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},fe=(i,r)=>(t,e)=>r(t,e,i);const Sn=[I.InsertRowCommand.id,I.InsertColCommand.id,I.RemoveRowCommand.id,I.RemoveColCommand.id,I.DeleteRangeMoveLeftCommand.id,I.DeleteRangeMoveUpCommand.id,I.InsertRangeMoveDownCommand.id,I.InsertRangeMoveRightCommand.id,I.DeltaRowHeightCommand.id,I.SetRowHeightCommand.id,I.DeltaColumnWidthCommand.id,I.SetColWidthCommand.id,I.SetRowHiddenCommand.id,I.SetSpecificRowsVisibleCommand.id,I.SetSpecificColsVisibleCommand.id,I.SetColHiddenCommand.id,I.MoveColsCommand.id,I.MoveRowsCommand.id,I.MoveRangeCommand.id],wn=[I.SetRowVisibleMutation.id,I.SetRowHiddenMutation.id,I.SetColVisibleMutation.id,I.SetColHiddenMutation.id,I.SetWorksheetRowHeightMutation.id,I.SetWorksheetColWidthMutation.id];let _t=class extends l.Disposable{constructor(i,r,t,e,n,o,a,s,d){super(),this._context=i,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,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(!Sn.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===I.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([I.MoveColsCommand.id,I.MoveRowsCommand.id,I.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===I.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===I.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===I.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===I.DeleteRangeMoveLeftCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,0)}else if(r===I.DeleteRangeMoveUpCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,1)}else if(r===I.InsertRangeMoveDownCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,2)}else if(r===I.InsertRangeMoveRightCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,3)}else if(r===I.SetRowHiddenCommand.id||r===I.SetSpecificRowsVisibleCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForRowVisible(e,n,o)}else if(r===I.SetSpecificColsVisibleCommand.id||r===I.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForColVisible(e,n,o)}else if(r===I.DeltaRowHeightCommand.id||r===I.SetRowHeightCommand.id||r===I.DeltaColumnWidthCommand.id||r===I.SetColWidthCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t,a=r===I.DeltaRowHeightCommand.id||r===I.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const t=I.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(e,n),d=[],g=[];if(Object.keys(s).forEach(u=>{const c=s[u],{updateDrawings:p,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,c);d.push(...p),g.push(...h)}),d.length===0&&g.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:p,objects:h}=u;o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.UPDATE}}),a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),c=u.undo,p=u.redo,h=u.objects;o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.REMOVE}}),a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.INSERT}})}return o.push({id:G.id,params:[e]}),a.push({id:G.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,r,t){const e=[],n=[],{sheetTransform:o,anchorType:a=m.SheetDrawingAnchorType.Position,transform:s,unitId:d,subUnitId:g,drawingId:u}=t,{from:c,to:p}=o,{row:h,column:f}=c,{row:S,column:w}=p;if(o==null||s==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:v,endRow:y,startColumn:M,endColumn:T}=i;let C=null,b=null;if(r===0&&h>=v&&S<=y)if(f>=M&&w<=T)n.push({unitId:d,subUnitId:g,drawingId:u});else{const _=this._shrinkCol(o,s,M,T,a);C=_==null?void 0:_.newSheetTransform,b=_==null?void 0:_.newTransform}else if(r===1&&f>=M&&w<=T)if(h>=v&&S<=y)n.push({unitId:d,subUnitId:g,drawingId:u});else{const _=this._shrinkRow(o,s,v,y,a);C=_==null?void 0:_.newSheetTransform,b=_==null?void 0:_.newTransform}else if(r===2){const _=this._expandRow(o,s,v,y,a);C=_==null?void 0:_.newSheetTransform,b=_==null?void 0:_.newTransform}else if(r===3){const _=this._expandCol(o,s,M,T,a);C=_==null?void 0:_.newSheetTransform,b=_==null?void 0:_.newTransform}if(C!=null&&b!=null){const _=K(C,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:C,transform:_})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(i,r,t){const e=H({...i},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=c;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:S,to:w}=p,{row:v,column:y}=S,{row:M,column:T}=w;for(let C=0;C<t.length;C++){const b=t[C],{startRow:_,endRow:k,startColumn:E,endColumn:W}=b;if(T<E)continue;if(f===m.SheetDrawingAnchorType.Position){let D=null,L=null;if(y>=E&&y<=W){const j=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:W,startRow:S.row,endRow:w.row});if(j==null)return;L={...h,left:j.startX}}if(L!=null&&(D=H(L,this._selectionRenderService),D!=null&&L!=null)){n.push({...c,sheetTransform:D,transform:L});break}this._remainDrawingSize(h,n,c);continue}if(y>=E&&T<=W)continue;let A=null,P=null;if(y>=E&&y<=W){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:W,startRow:S.row,endRow:w.row});if(D==null)return;P={...h,left:(D==null?void 0:D.startX)||0,width:((h==null?void 0:h.width)||0)-D.endX+D.startX}}else if(T>=E&&T<=W){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:T,startRow:S.row,endRow:w.row});if(D==null)return;P={...h,left:D.startX-((h==null?void 0:h.width)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:W,startRow:S.row,endRow:w.row});if(D==null)return;if(P={...h,width:((h==null?void 0:h.width)||0)-D.endX+D.startX},A=H(P,this._selectionRenderService),A!=null&&P!=null){o.push({...c,sheetTransform:A,transform:P});break}}if(P!=null&&(A=H(P,this._selectionRenderService)),P!=null&&A!=null){n.push({...c,sheetTransform:A,transform:P});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),d=[],g=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);d.push(...u),g.push(...c)}return{redos:a,undos:s,preRedos:d,preUndos:g}}_createUndoAndRedoMutation(i,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:o,objects:a}=e,s=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],d=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:a,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:s,undos:d}}_getDrawingUndoForRowVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=c;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:S,to:w}=p,{row:v,column:y}=S,{row:M,column:T}=w;for(let C=0;C<t.length;C++){const b=t[C],{startRow:_,endRow:k,startColumn:E,endColumn:W}=b;if(M<_)continue;if(f===m.SheetDrawingAnchorType.Position){let D=null,L=null;if(v>=_&&v<=k){const j=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:k});if(j==null)return;L={...h,top:j.startY}}if(L!=null&&(D=H(L,this._selectionRenderService),D!=null&&L!=null)){n.push({...c,sheetTransform:D,transform:L});break}this._remainDrawingSize(h,n,c);continue}if(v>=_&&M<=k)continue;let A=null,P=null;if(v>=_&&v<=k){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:k});if(D==null)return;P={...h,top:(D==null?void 0:D.startY)||0,height:((h==null?void 0:h.height)||0)-D.endY+D.startY}}else if(M>=_&&M<=k){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:_,endRow:M});if(D==null)return;P={...h,top:D.startY-((h==null?void 0:h.height)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:_,endRow:k});if(D==null)return;if(P={...h,height:((h==null?void 0:h.height)||0)-D.endY+D.startY},A=H(P,this._selectionRenderService),A!=null&&P!=null){o.push({...c,sheetTransform:A,transform:P});break}}if(P!=null&&(A=H(P,this._selectionRenderService)),P!=null&&A!=null){n.push({...c,sheetTransform:A,transform:P});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),d=[],g=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);d.push(...u),g.push(...c)}return{redos:a,undos:s,preRedos:d,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,t,e){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(a=>{const s=n[a],{sheetTransform:d,transform:g,anchorType:u=m.SheetDrawingAnchorType.Position}=s;if(u===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,o,s);else{const{from:c,to:p}=d,{row:h,column:f}=c,{row:S,column:w}=p;for(let v=0;v<t.length;v++){const y=t[v],{startRow:M,endRow:T,startColumn:C,endColumn:b}=y;if(S<M||w<C)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=M&&S>=T||f<=C&&w>=b)){this._remainDrawingSize(g,o,s);continue}const _=K({...d},this._selectionRenderService,this._skeletonManagerService);if(_!=null){o.push({...s,transform:_});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let t,e;if(r==="insert")t=i.unitId,e=i.subUnitId;else{const n=I.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(i){var M,T;const{toRange:r,fromRange:t}=i,e=I.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=e,a=(T=(M=this._renderManagerService.getRenderById(n))==null?void 0:M.with(O.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=O.attachRangeWithCoord(a,t);if(!s)return{redos:[],undos:[]};const{startX:d,endX:g,startY:u,endY:c}=s,p=this._sheetDrawingService.getDrawingData(n,o),h=[];Object.keys(p).forEach(C=>{const b=p[C];if(b.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:_}=b;if(!_)return;const{left:k=0,top:E=0,width:W=0,height:A=0}=_,{drawingStartX:P,drawingEndX:D,drawingStartY:L,drawingEndY:j}={drawingStartX:k,drawingEndX:k+W,drawingStartY:E,drawingEndY:E+A};d<=P&&D<=g&&u<=L&&j<=c&&h.push(b)});const f=[],S=[],w=r.startRow-t.startRow,v=r.startColumn-t.startColumn,y=h.map(C=>{const b=C.sheetTransform,_={to:{...b.to,row:b.to.row+w,column:b.to.column+v},from:{...b.from,row:b.from.row+w,column:b.from.column+v}},k=K(_,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:C.drawingId,transform:k,sheetTransform:_}});if(y.length){const C=this._sheetDrawingService.getBatchUpdateOp(y),{undo:b,redo:_,objects:k}=C;f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:_,objects:k,type:m.DrawingApplyType.UPDATE}}),S.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:b,objects:k,type:m.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,a=o.startRow,s=o.endRow,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:v=m.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let y,M;if(r==="insert"){const C=this._expandRow(S,w,a,s,v);y=C==null?void 0:C.newSheetTransform,M=C==null?void 0:C.newTransform}else{const{from:C,to:b}=S,{row:_}=C,{row:k}=b;if(v===m.SheetDrawingAnchorType.Both&&_>=a&&k<=s)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkRow(S,w,a,s,v);y=E==null?void 0:E.newSheetTransform,M=E==null?void 0:E.newTransform}}if(!y||!M)return;const T={unitId:e,subUnitId:n,drawingId:h,transform:M,sheetTransform:y};c.push(T)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:S,objects:w}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,S=h.redo,w=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_moveColInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,a=o.startColumn,s=o.endColumn,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:v=m.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let y,M;if(r==="insert"){const C=this._expandCol(S,w,a,s,v);y=C==null?void 0:C.newSheetTransform,M=C==null?void 0:C.newTransform}else{const{from:C,to:b}=S,{column:_}=C,{column:k}=b;if(v===m.SheetDrawingAnchorType.Both&&_>=a&&k<=s)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkCol(S,w,a,s,v);y=E==null?void 0:E.newSheetTransform,M=E==null?void 0:E.newTransform}}if(!y||!M)return;const T={unitId:e,subUnitId:n,drawingId:h,transform:M,sheetTransform:y};c.push(T)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:S,objects:w}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,S=h.redo,w=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_expandCol(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{column:d}=a,{column:g}=s;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:a.row,endRow:s.row});if(p==null)return;c={...r,left:(r.left||0)+p.endX-p.startX},u=H(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:g+o}},c=K(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,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{column:d}=a,{column:g}=s;if(n===m.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:g-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:g-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,left:(r.left||0)-i.from.columnOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:a.row,endRow:s.row});if(p==null)return;c={...r,left:(r.left||0)-p.endX+p.startX-i.from.columnOffset}}u=H(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:a.row,endRow:s.row});if(p==null)return;u={from:{...a},to:{...s,column:t-1,columnOffset:p.endX-p.startX}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{row:d}=a,{row:g}=s;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:a.column,endColumn:s.column});if(p==null)return;c={...r,top:(r.top||0)+p.endY-p.startY},u=H(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:g+o}},c=K(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,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{row:d}=a,{row:g}=s;if(n===m.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:g-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:g-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,top:(r.top||0)-i.from.rowOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:a.column,endColumn:s.column});if(p==null)return;c={...r,top:(r.top||0)-p.endY+p.startY-i.from.rowOffset}}u=H(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:t-1,endRow:t-1});if(p==null)return;u={from:{...a},to:{...s,row:t-1,rowOffset:p.endY-p.startY}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===I.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:t}=i.params;this._updateDrawings(r,t)}})),this.disposeWithMe(this._context.activated$.subscribe(i=>{const{unit:r,unitId:t}=this._context;if(i){const e=r.getActiveSheet().getSheetId();this._updateDrawings(t,e)}else this._clearDrawings(t)}))}_clearDrawings(i){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,t=[];Object.keys(r).forEach(e=>{const n=r[e];n!=null&&Object.keys(n).forEach(o=>{const a=n[o].data;a!=null&&Object.keys(a).forEach(s=>{e===i&&t.push(a[s])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(i,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(o=>{const a=t[o];a!=null&&Object.keys(a).forEach(s=>{const d=a[s].data;d!=null&&Object.keys(d).forEach(g=>{if(o===i&&s===r){const u=d[g];u.transform=K(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(d[g])}else n.push(d[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{wn.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:s,transform:d,anchorType:g=m.SheetDrawingAnchorType.Position}=a;if(g===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=s,{row:p,column:h}=u,{row:f,column:S}=c;for(let w=0;w<t.length;w++){const v=t[w],{startRow:y,endRow:M,startColumn:T,endColumn:C}=v;if(l.Rectangle.intersects({startRow:y,endRow:M,startColumn:T,endColumn:C},{startRow:p,endRow:f,startColumn:h,endColumn:S})||p>M||h>C){const b=g===m.SheetDrawingAnchorType.Position,_=K(s,this._selectionRenderService,this._skeletonManagerService);n.push({...a,transform:{..._,width:b?d==null?void 0:d.width:_==null?void 0:_.width,height:b?d==null?void 0:d.height:_==null?void 0:_.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[i]))}};_t=fn([fe(1,B.IRenderManagerService),fe(2,l.ICommandService),fe(3,O.ISheetSelectionRenderService),fe(4,l.Inject(O.SheetSkeletonManagerService)),fe(5,l.Inject(I.SheetInterceptorService)),fe(6,m.ISheetDrawingService),fe(7,U.IDrawingManagerService),fe(8,l.IUniverInstanceService)],_t);var ie=function(){return ie=Object.assign||function(i){for(var r,t=1,e=arguments.length;t<e;t++){r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(i[n]=r[n])}return i},ie.apply(this,arguments)},vn=function(i,r){var t={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(t[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,e=Object.getOwnPropertySymbols(i);n<e.length;n++)r.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(i,e[n])&&(t[e[n]]=i[e[n]]);return t},At=ne.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,o=i.extend,a=vn(i,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),d=ne.useRef("_".concat(yn()));return Ut(t,"".concat(e),{defIds:t.defIds,idSuffix:d.current},ie({ref:r,className:s},a),o)});function Ut(i,r,t,e,n){return ne.createElement(i.tag,ie(ie({key:r},_n(i,t,n)),e),(In(i,t).children||[]).map(function(o,a){return Ut(o,"".concat(r,"-").concat(i.tag,"-").concat(a),t,void 0,n)}))}function _n(i,r,t){var e=ie({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1),i.tag==="mask"&&e.id&&(e.id=e.id+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];a==="mask"&&typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))});var n=r.defIds;return!n||n.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 In(i,r){var t,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((t=i.children)===null||t===void 0)&&t.length)?ie(ie({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?ie(ie({},n),{attrs:ie(ie({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function yn(){return Math.random().toString(36).substring(2,8)}At.displayName="UniverIcon";var Cn={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"}}]},Nt=ne.forwardRef(function(i,r){return ne.createElement(At,Object.assign({},i,{id:"add-image-single",ref:r,icon:Cn}))});Nt.displayName="AddImageSingle";const It={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),e=i.get(m.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,o=e.map(a=>{const{unitId:s,subUnitId:d,drawingId:g,drawingType:u}=a;return{unitId:s,subUnitId:d,drawingId:g,drawingType:u}});return r.executeCommand(_e.id,{unitId:n,drawings:o})}},ye={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(m.ISheetDrawingService),n=i.get(O.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 p={...c},{left:h=0,top:f=0}=c;return o===l.Direction.UP?p.top=f-1:o===l.Direction.DOWN?p.top=f+1:o===l.Direction.LEFT?p.left=h-1:o===l.Direction.RIGHT&&(p.left=h+1),{...u,transform:p,sheetTransform:H(p,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(Pe.id,{unitId:s,drawings:d})?(t.syncExecuteCommand(G.id,[s]),!0):!1}},kt="addition-and-subtraction-single",yt="sheet.menu.image";function Dn(i){return{id:yt,type:Y.MenuItemType.SUBITEMS,icon:kt,tooltip:"sheetImage.title",hidden$:Y.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),disabled$:O.getCurrentRangeDisable$(i,{workbookTypes:[I.WorkbookEditablePermission],worksheetTypes:[I.WorksheetEditPermission],rangeTypes:[I.RangeProtectionPermissionEditPoint]})}}function Mn(i){return{id:Ae.id,title:"sheetImage.upload.float",type:Y.MenuItemType.BUTTON,hidden$:Y.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function Tn(i){return{id:vt.id,title:"sheetImage.upload.cell",type:Y.MenuItemType.BUTTON,hidden$:Y.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}const Se={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelColumn:"univer-image-common-panel-column"},bn=i=>{var M;const r=Y.useDependency(l.ICommandService),t=Y.useDependency(l.LocaleService),e=Y.useDependency(U.IDrawingManagerService),n=Y.useDependency(B.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:s}=a,d=n.getRenderById(s),g=d==null?void 0:d.scene;if(g==null)return;const u=g.getTransformerByCreate(),[c,p]=ne.useState(!0),h=(M=a.anchorType)!=null?M:m.SheetDrawingAnchorType.Position,[f,S]=ne.useState(h);function w(T,C){const b=[];return T.forEach(_=>{const{oKey:k}=_,E=C.getDrawingOKey(k);if(E==null)return b.push(null),!0;const{unitId:W,subUnitId:A,drawingId:P,drawingType:D,anchorType:L,sheetTransform:j}=E;b.push({unitId:W,subUnitId:A,drawingId:P,anchorType:L,sheetTransform:j,drawingType:D})}),b}ne.useEffect(()=>{const T=u.clearControl$.subscribe(b=>{b===!0&&p(!1)}),C=u.changeStart$.subscribe(b=>{var E;const{objects:_}=b,k=w(_,e);if(k.length===0)p(!1);else if(k.length>=1){p(!0);const W=((E=k[0])==null?void 0:E.anchorType)||m.SheetDrawingAnchorType.Position;S(W)}});return()=>{C.unsubscribe(),T.unsubscribe()}},[]);function v(T){S(T);const C=e.getFocusDrawings();if(C.length===0)return;const b=C.map(_=>({unitId:_.unitId,subUnitId:_.subUnitId,drawingId:_.drawingId,anchorType:T}));r.executeCommand(Pe.id,{unitId:C[0].unitId,drawings:b})}const y=T=>T?"block":"none";return x.jsxs("div",{className:q.clsx(Se.imageCommonPanelGrid,Se.imageCommonPanelBorder),style:{display:y(c)},children:[x.jsx("div",{className:Se.imageCommonPanelRow,children:x.jsx("div",{className:q.clsx(Se.imageCommonPanelColumn,Se.imageCommonPanelTitle),children:x.jsx("div",{children:t.t("drawing-anchor.title")})})}),x.jsx("div",{className:q.clsx(Se.imageCommonPanelRow),children:x.jsx("div",{className:q.clsx(Se.imageCommonPanelColumn),children:x.jsxs(q.RadioGroup,{value:f,onChange:v,direction:"vertical",children:[x.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),x.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),x.jsx(q.Radio,{value:m.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})})]})},Rn=()=>{const i=Y.useDependency(U.IDrawingManagerService),r=i.getFocusDrawings(),[t,e]=ne.useState(r);return ne.useEffect(()=>{const n=i.focus$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&x.jsxs("div",{className:Se.imageCommonPanel,children:[x.jsx(pe.DrawingCommonPanel,{drawings:t}),x.jsx(bn,{drawings:t})]})},En={[Y.RibbonStartGroup.FORMULAS_INSERT]:{[yt]:{order:3,menuItemFactory:Dn,[Ae.id]:{order:0,menuItemFactory:Mn},[vt.id]:{order:1,menuItemFactory:Tn}}}};function ke(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 On={id:ye.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_DOWN,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.DOWN}},Pn={id:ye.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_UP,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.UP}},An={id:ye.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_LEFT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.LEFT}},Un={id:ye.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_RIGHT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.RIGHT}},Nn={id:It.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:ke,binding:Y.KeyCode.DELETE,mac:Y.KeyCode.BACKSPACE};var kn=Object.getOwnPropertyDescriptor,Bn=(i,r,t,e)=>{for(var n=e>1?void 0:e?kn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ce=(i,r)=>(t,e)=>r(t,e,i);let Je=class extends l.Disposable{constructor(i,r,t,e,n,o){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(kt,Nt)),this.disposeWithMe(i.register(bt,Rn))}_initMenus(){this._menuManagerService.mergeMenu(En)}_initCommands(){[Ae,vt,Oe,_e,Pe,gt,G,ht,mt,St,ye,It,ft].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[On,Pn,An,Un,Nn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Je=Bn([Ce(0,l.Inject(Y.ComponentManager)),Ce(1,Y.IMenuManagerService),Ce(2,l.ICommandService),Ce(3,Y.IShortcutService),Ce(4,U.IDrawingManagerService),Ce(5,l.Inject(I.SheetsSelectionsService))],Je);var Wn=Object.getOwnPropertyDescriptor,jn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Wn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},ve=(i,r)=>(t,e)=>r(t,e,i);function Ln(i,r,t,e,n){const{scaleX:o,scaleY:a}=r.getAncestorScale(),s=r.getViewport(B.SHEET_VIEWPORT_KEY.VIEW_MAIN),d=e.getFreeze(),{startColumn:g,startRow:u,xSplit:c,ySplit:p}=d,h={left:!0,top:!0};if(!s)return{...i,absolute:h};const{left:f,right:S,top:w,bottom:v}=i;let{top:y,left:M,viewportScrollX:T,viewportScrollY:C}=s;const{boundsOfViewArea:b,scrollDirectionResponse:_}=n||{},{rowHeaderWidth:k,columnHeaderHeight:E}=t,W={top:E,left:k};b&&(l.Tools.isDefine(W.top)&&(W.top=b.top),l.Tools.isDefine(W.left)&&(W.left=b.left)),_==="HORIZONTAL"&&(C=0),_==="VERTICAL"&&(T=0);let A=0,P=0;const D=t.rowStartY(u-p)+E,L=t.colStartX(g-c)+k,j=t.rowStartY(u)+E,z=t.colStartX(g)+k;if(c===0)h.left=!1,A=(f-T)*o,P=(S-T)*o;else{const te=f-(L-k),J=S-(L-k);S<z?(A=te*o,P=J*o):f<=z&&S>=z?(A=te*o,P=Math.max(M,(S-T)*o)):f>z&&(h.left=!1,A=Math.max((f-T)*o,M),P=Math.max((S-T)*o,M))}let X=0,Z=0;if(p===0)h.top=!1,X=(w-C)*a,Z=(v-C)*a;else{const te=w-(D-E),J=v-(D-E);v<j?(X=te*a,Z=J*a):w<=j&&v>=j?(X=te*a,Z=Math.max(y,(v-C)*a)):w>j&&(h.top=!1,X=Math.max((w-C)*a,y),Z=Math.max((v-C)*a,y))}return A=Math.max(A,W.left),X=Math.max(X,W.top),P=Math.max(P,W.left),Z=Math.max(Z,W.top),{left:A,right:P,top:X,bottom:Z,absolute:h}}const le=(i,r,t,e,n)=>{const{scene:o}=r,{left:a,top:s,width:d,height:g,angle:u}=i,c={left:a,right:a+d,top:s,bottom:s+g},p=Ln(c,o,t,e,n),{scaleX:h,scaleY:f}=o.getAncestorScale();return{startX:p.left,endX:p.right,startY:p.top,endY:p.bottom,rotate:u,width:d*h,height:g*f,absolute:p.absolute}};R.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(t,e,n,o,a,s,d){super();ee(this,"_domLayerMap",new Map);ee(this,"_domLayerInfoMap",new Map);ee(this,"_transformChange$",new N.Subject);ee(this,"transformChange$",this._transformChange$.asObservable());ee(this,"_add$",new N.Subject);ee(this,"add$",this._add$.asObservable());ee(this,"_remove$",new N.Subject);ee(this,"remove$",this._remove$.asObservable());ee(this,"_hooks",[]);this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,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(N.filter(t=>t===l.LifecycleStages.Rendered),N.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(t,e){let n=this._domLayerMap.get(t);n||(n=new Map,this._domLayerMap.set(t,n));let o=n.get(e);return o||(o=new Map,n.set(e,o)),o}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const o=n.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:n,transformer:o,renderUnit:e,canvas:a}}_getFloatDomProps(t){let e;return this._hooks.forEach(n=>{e=n.onGetFloatDomProps(t)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var se,ce,Q;const{unitId:n,subUnitId:o,drawingId:a}=e,s=I.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!d||!s)return;const c=(se=this._renderManagerService.getRenderById(n))==null?void 0:se.with(O.SheetSkeletonManagerService).getSkeletonParam(o);if(!c)return;const{transform:p,drawingType:h,data:f}=d;if(h!==l.DrawingTypeEnum.DRAWING_DOM&&h!==l.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(n);if(S==null)return;const{scene:w,canvas:v}=S;if(p==null)return!0;if(u!==o)return;const{left:y,top:M,width:T,height:C,angle:b,flipX:_,flipY:k,skewX:E,skewY:W}=p,A=U.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),P=w.getObject(A);if(P!=null){P.transformByState({left:y,top:M,width:T,height:C,angle:b,flipX:_,flipY:k,skewX:E,skewY:W});return}const D={left:y,top:M,width:T,height:C,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},L=h===l.DrawingTypeEnum.DRAWING_CHART;if(L){const $=f?f.backgroundColor:"white";D.fill=$,D.rotateEnabled=!1,f&&f.border&&(D.stroke=f.border),D.paintFirst="stroke",D.strokeWidth=1,D.borderEnabled=!1,D.radius=8}const j=new B.Rect(A,D);L&&j.setObjectType(B.ObjectType.CHART),w.addObject(j,B.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&w.attachTransformerTo(j);const z=this._ensureMap(n,o),X=new l.DisposableCollection,Z=le(j,S.renderUnit,c.skeleton,s.worksheet),ae=new N.BehaviorSubject(Z),te={dispose:X,rect:j,position$:ae,unitId:n,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:ae,id:a,componentKey:d.componentKey,onPointerDown:$=>{v.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{v.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{v.dispatchEvent(new PointerEvent($.type,$))},onWheel:$=>{v.dispatchEvent(new WheelEvent($.type,$))},props:(Q=(ce=z.get(a))==null?void 0:ce.props)!=null?Q:this._getFloatDomProps(a),data:f,unitId:n});const J=j.onTransformChange$.subscribeEvent(()=>{const $=le(j,S.renderUnit,c.skeleton,s.worksheet);ae.next($)});X.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),J&&X.add(J),this._domLayerInfoMap.set(a,te),z.set(a,{...z.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{const{unitId:n,subUnitId:o,drawingId:a}=e,s=U.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{transformer:g,scene:u}=d,c=u.getObject(s);c!=null&&c.oKey&&g.clearControlByIds([c==null?void 0:c.oKey])})}))}_scrollUpdateListener(){const t=(e,n)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,n),s=Array.from(a.keys()),d=I.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),g=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(O.SheetSkeletonManagerService).getSkeletonParam(n);!o||!d||!g||s.forEach(c=>{const p=this._domLayerInfoMap.get(c);if(p){const h=le(p.rect,o.renderUnit,g.skeleton,d.worksheet,p);p.position$.next(h)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(e=>e?e.activeSheet$:N.of(null)),N.map(e=>{if(!e)return null;const n=e.getUnitId(),o=this._renderManagerService.getRenderById(n);return o?{render:o,unitId:n,subUnitId:e.getSheetId()}:null}),N.switchMap(e=>e?l.fromEventSubject(e.render.scene.getViewport(B.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(N.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):N.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:o}=e;t(n,o)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n,o;if(e.id===O.SetZoomRatioOperation.id){const a=e.params,{unitId:s}=a;Array.from((o=(n=this._domLayerMap.get(s))==null?void 0:n.keys())!=null?o:[]).forEach(g=>{t(s,g)})}else if(e.id===I.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=e.params;t(a,s)}}))}_getPosition(t,e){var h;const{startX:n,endX:o,startY:a,endY:s}=t,d=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(O.ISheetSelectionRenderService);if(d==null)return;const g=d.getCellWithCoordByOffset(n,a);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:a-g.startY},c=d.getCellWithCoordByOffset(o,s);if(c==null)return;const p={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:s-c.startY};return{from:u,to:p}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const o={...n.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,o){const a=this._domLayerInfoMap.get(n),s=this._getSceneAndTransformerByDrawingSearch(t);if(a&&s){const{scene:d}=s,g=U.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=d.getObject(g);u&&u instanceof B.Rect&&u.setProps(o)}}addFloatDomToPosition(t,e){const n=I.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=n,{initPosition:s,componentKey:d,data:g,allowTransform:u=!0}=t,c=e!=null?e:l.generateRandomId(),p=this._getPosition(s,o);if(p==null)return;this._ensureMap(o,a).set(c,t);const f={unitId:o,subUnitId:a,drawingId:c,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:p,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Oe.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:a,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:o,subUnitId:a}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(n.rect),e){this._ensureMap(o,a).delete(t);const g=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:t});if(!g)return;const u=this._sheetDrawingService.getBatchRemoveOp([g]),{redo:c,objects:p}=u;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:c,objects:p,type:m.DrawingApplyType.REMOVE})}}addHook(t){return this._hooks.push(t),{dispose:()=>{const e=this._hooks.findIndex(n=>n===t);this._hooks.splice(e,1)}}}addFloatDomToRange(t,e,n,o){var k,E,W,A,P;const a=I.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:d}=a,g=this._getSceneAndTransformerByDrawingSearch(s);if(!g)return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const c=(k=this._renderManagerService.getRenderById(s))==null?void 0:k.with(O.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,S=o!=null?o:l.generateRandomId(),{position:w,position$:v}=this._createRangePositionObserver(t,u,c.skeleton);if(this._getPosition(w,s)==null)return;this._ensureMap(s,d).set(S,e);const T=g.scene,{scaleX:C}=T.getAncestorScale(),b=Qe(w,n,C),_={unitId:s,subUnitId:d,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:b.startX,top:b.startY,width:b.width,height:b.height},data:h,allowTransform:f};{const{unitId:D,subUnitId:L,drawingId:j}=_,z=I.getSheetCommandTarget(this._univerInstanceService,{unitId:D,subUnitId:L}),X=_,Z=this._univerInstanceService.getUnit(D,l.UniverInstanceType.UNIVER_SHEET);if(!Z)return;const ae=Z.getActiveSheet().getSheetId();if(!X||!z)return;const te=(E=this._renderManagerService.getRenderById(D))==null?void 0:E.with(O.SheetSkeletonManagerService);if(!te)return;const J=te.getWorksheetSkeleton(L);if(!J)return;const{transform:se,drawingType:ce,data:Q}=X;if(ce!==l.DrawingTypeEnum.DRAWING_DOM&&ce!==l.DrawingTypeEnum.DRAWING_CHART)return;const $=this._getSceneAndTransformerByDrawingSearch(D);if($==null)return;const{scene:De,canvas:Me}=$;if(se==null||ae!==L)return;const{left:tt,top:nt,width:rt,height:it,angle:Dt,flipX:Mt,flipY:ot,skewX:at,skewY:Te}=se,st=U.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:L,drawingId:j}),ue=De.getObject(st);if(ue!=null){ue.transformByState({left:tt,top:nt,width:rt,height:it,angle:Dt,flipX:Mt,flipY:ot,skewX:at,skewY:Te});return}const oe={left:tt,top:nt,width:rt,height:it,zIndex:this._drawingManagerService.getDrawingOrder(D,L).length-1},be=ce===l.DrawingTypeEnum.DRAWING_CHART;if(be){const F=Q?Q.backgroundColor:"white";oe.fill=F,oe.rotateEnabled=!1,Q&&Q.border&&(oe.stroke=Q.border),oe.paintFirst="stroke",oe.strokeWidth=1,oe.borderEnabled=!1,oe.radius=8}const de=new B.Rect(st,oe);be&&de.setObjectType(B.ObjectType.CHART),De.addObject(de,B.DRAWING_OBJECT_LAYER_INDEX),X.allowTransform!==!1&&De.attachTransformerTo(de);const We=this._ensureMap(D,L),ge=new l.DisposableCollection,ct=De.getMainViewport(),{rowHeaderWidth:Re,columnHeaderHeight:je}=J.skeleton,dt={top:je,left:Re,bottom:ct.bottom,right:ct.right},he={dispose:ge,rect:de,boundsOfViewArea:dt,domAnchor:n,unitId:D,subUnitId:L},V=le(de,$.renderUnit,J.skeleton,z.worksheet,he),Ee=new N.BehaviorSubject(V);he.position$=Ee;let Le={position$:Ee,id:j,componentKey:X.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:F=>{Me.dispatchEvent(new WheelEvent(F.type,F))},props:(A=(W=We.get(j))==null?void 0:W.props)!=null?A:this._getFloatDomProps(j),data:Q,unitId:D};e.eventPassThrough&&(Le={...Le,onPointerDown:F=>{Me.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{Me.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{Me.dispatchEvent(new PointerEvent(F.type,F))}}),this._canvasFloatDomService.addFloatDom(Le),this.disposeWithMe(v.subscribe(F=>{var jt,Lt,Yt,Ft;const Wt=Qe({startX:F.startX,startY:F.startY,endX:F.endX,endY:F.endY,width:(jt=n.width)!=null?jt:F.width,height:(Lt=n.height)!=null?Lt:F.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Vn=U.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:L,drawingId:j}),Xn=new B.Rect(Vn,{left:Wt.startX,top:Wt.startY,width:(Yt=n.width)!=null?Yt:F.width,height:(Ft=n.height)!=null?Ft:F.height,zIndex:this._drawingManagerService.getDrawingOrder(D,L).length-1}),xn=le(Xn,$.renderUnit,J.skeleton,z.worksheet,he);Ee.next(xn)}));const Ye=(P=this._renderManagerService.getRenderById(D))==null?void 0:P.with(O.SheetSkeletonManagerService);Ye==null||Ye.currentSkeleton$.subscribe(F=>{F&&J.sheetId!==F.sheetId&&this._removeDom(S,!0)});const lt=de.onTransformChange$.subscribeEvent(()=>{const F=le(de,$.renderUnit,J.skeleton,z.worksheet,he);Ee.next(F)});ge.add(()=>{this._canvasFloatDomService.removeFloatDom(j)}),lt&&ge.add(lt),this._domLayerInfoMap.set(j,he),We.set(j,{...We.get(j)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(t,e,n,o){var b,_,k,E,W;const a=I.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=(b=this._renderManagerService.getRenderById(s))==null?void 0:b.with(O.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,S=o!=null?o:l.generateRandomId(),{position:w,position$:v}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,c.skeleton),y=w;if(y.startY=0,this._getPosition(w,s)==null)return;this._ensureMap(s,d).set(S,e);const C={unitId:s,subUnitId:d,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:y.startX,top:y.startY,width:y.width,height:y.height},data:h,allowTransform:f};{const{unitId:A,subUnitId:P,drawingId:D}=C,L=I.getSheetCommandTarget(this._univerInstanceService,{unitId:A,subUnitId:P}),j=C,z=this._univerInstanceService.getUnit(A,l.UniverInstanceType.UNIVER_SHEET);if(!z)return;const X=z.getActiveSheet().getSheetId();if(!j||!L)return;const Z=(_=this._renderManagerService.getRenderById(A))==null?void 0:_.with(O.SheetSkeletonManagerService);if(!Z)return;const ae=Z.getWorksheetSkeleton(P);if(!ae)return;const{transform:te,data:J}=j,se=this._getSceneAndTransformerByDrawingSearch(A);if(se==null)return;const{scene:ce,canvas:Q}=se;if(te==null||X!==P)return;const{left:$,top:De,width:Me,height:tt,angle:nt,flipX:rt,flipY:it,skewX:Dt,skewY:Mt}=te,ot=U.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:P,drawingId:D}),at=ce.getObject(ot);if(at!=null){at.transformByState({left:$,top:De,width:Me,height:tt,angle:nt,flipX:rt,flipY:it,skewX:Dt,skewY:Mt});return}const Te=Qe({startX:y.startX,startY:0,endX:w.endX,endY:w.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),st={left:Te.startX,top:Te.startY,width:Te.width,height:Te.height,zIndex:this._drawingManagerService.getDrawingOrder(A,P).length-1},ue=new B.Rect(ot,st);ce.addObject(ue,B.DRAWING_OBJECT_LAYER_INDEX),j.allowTransform!==!1&&ce.attachTransformerTo(ue);const oe=this._ensureMap(A,P),be=new l.DisposableCollection,de=ce.getMainViewport(),We={top:0,left:de.left,bottom:de.bottom,right:de.right},ge={dispose:be,rect:ue,unitId:A,subUnitId:P,boundsOfViewArea:We,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},ct=le(ue,se.renderUnit,ae.skeleton,L.worksheet,ge),Re=new N.BehaviorSubject(ct);ge.position$=Re;let je={position$:Re,id:D,componentKey:j.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:V=>{Q.dispatchEvent(new WheelEvent(V.type,V))},props:(E=(k=oe.get(D))==null?void 0:k.props)!=null?E:this._getFloatDomProps(D),data:J,unitId:A};e.eventPassThrough&&(je={...je,onPointerDown:V=>{Q.dispatchEvent(new PointerEvent(V.type,V))},onPointerMove:V=>{Q.dispatchEvent(new PointerEvent(V.type,V))},onPointerUp:V=>{Q.dispatchEvent(new PointerEvent(V.type,V))}}),this._canvasFloatDomService.addFloatDom(je);const dt=ue.onTransformChange$.subscribeEvent(()=>{const V=le(ue,se.renderUnit,ae.skeleton,L.worksheet,ge);Re.next(V)});this.disposeWithMe(v.subscribe(V=>{const Ee=Qe({startX:V.startX,startY:0,endX:V.endX,endY:V.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Le=U.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:P,drawingId:D}),Ye=new B.Rect(Le,{left:Ee.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(A,P).length-1}),lt=le(Ye,se.renderUnit,ae.skeleton,L.worksheet,ge);Re.next(lt)}));const he=(W=this._renderManagerService.getRenderById(A))==null?void 0:W.with(O.SheetSkeletonManagerService);he==null||he.currentSkeleton$.subscribe(V=>{V&&c.sheetId!==V.sheetId&&this._removeDom(S,!0)}),be.add(()=>{this._canvasFloatDomService.removeFloatDom(D)}),dt&&be.add(dt),this._domLayerInfoMap.set(D,ge),oe.set(D,{...oe.get(D)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:o,startColumn:a}=t;const s=Be(o,a,n),d=new N.BehaviorSubject(s),g=Be(t.endRow,t.endColumn,n),u=new N.BehaviorSubject(g),c=()=>{const v=Be(o,a,n),y=Be(t.endRow,t.endColumn,n);d.next(v),u.next(y)},p=new l.DisposableCollection;p.add(e.engine.clientRect$.subscribe(()=>c())),p.add(this._commandService.onCommandExecuted(v=>{if(v.id===I.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(M=>M.row===o)>-1){c();return}(I.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(v.id)>-1||v.id===O.SetScrollOperation.id||v.id===O.SetZoomRatioOperation.id)&&c()}));const h=(v,y)=>{o=v,a=y,c()},f=()=>({rotate:0,width:g.right-s.left,height:g.bottom-s.top,absolute:{left:!0,top:!0},startX:s.left,startY:s.top,endX:g.right,endY:g.bottom}),S=d.pipe(N.map(v=>{const y=Be(t.endRow,t.endColumn,n);return{rotate:0,width:y.right-v.left,height:y.bottom-v.top,absolute:{left:!0,top:!0},startX:v.left,startY:v.top,endX:y.right,endY:y.bottom}})),w=f();return{position$:S,position:w,updateRowCol:h,topLeftPos$:d,rightBottomPos$:u,disposable:p}}},R.SheetCanvasFloatDomManagerService=jn([ve(0,l.Inject(B.IRenderManagerService)),ve(1,l.IUniverInstanceService),ve(2,l.Inject(l.ICommandService)),ve(3,U.IDrawingManagerService),ve(4,l.Inject(Y.CanvasFloatDomService)),ve(5,m.ISheetDrawingService),ve(6,l.Inject(l.LifecycleService))],R.SheetCanvasFloatDomManagerService);function Be(i,r,t){const e=t.getCellWithCoordByIndex(i,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Qe(i,r,t){var g,u;t=t!=null?t:1;const e=i.endX-i.startX,n=i.endY-i.startY,o=(g=r==null?void 0:r.width)!=null?g:e,a=(u=r==null?void 0:r.height)!=null?u:n;let s=0,d=0;if(r){if(r.horizonOffsetAlign==="right"){const c=et(r.marginX,e*t);s=i.endX-c-o}else s=i.startX+et(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const c=et(r.marginY,n*t);d=i.endY-c-a}else d=i.startY+et(r.marginY,n)}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 et(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const t=Number.parseFloat(i);return r*t/100}var Yn=Object.defineProperty,Fn=Object.getOwnPropertyDescriptor,$n=(i,r,t)=>r in i?Yn(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,Gn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Fn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ct=(i,r)=>(t,e)=>r(t,e,i),Bt=(i,r,t)=>$n(i,typeof r!="symbol"?r+"":r,t);const Hn="SHEET_IMAGE_UI_PLUGIN";R.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=Tt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:o,...a}=l.merge({},Tt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig($t,a)}onStarting(){l.registerDependencies(this._injector,[[R.SheetCanvasFloatDomManagerService],[Je],[$e],[Ze],[ze],[Ke],[He],[xe],[Ve]]),l.touchDependencies(this._injector,[[R.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[Ke]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[ze],[Ze],[Je],[He],[xe],[Ve]])}onSteady(){this._injector.get($e)}_registerRenderModules(){[[R.SheetDrawingUpdateController],[_t],[pt]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}},Bt(R.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),Bt(R.UniverSheetsDrawingUIPlugin,"pluginName",Hn),R.UniverSheetsDrawingUIPlugin=Gn([l.DependentOn(U.UniverDrawingPlugin,we.UniverDocsDrawingPlugin,pe.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),Ct(1,l.Inject(l.Injector)),Ct(2,B.IRenderManagerService),Ct(3,l.IConfigService)],R.UniverSheetsDrawingUIPlugin),R.ClearSheetDrawingTransformerOperation=G,R.DeleteDrawingsCommand=It,R.EditSheetDrawingOperation=ht,R.GroupSheetDrawingCommand=mt,R.InsertFloatImageCommand=Ae,R.InsertSheetDrawingCommand=Oe,R.MoveDrawingsCommand=ye,R.RemoveSheetDrawingCommand=_e,R.SHEETS_IMAGE_MENU_ID=yt,R.SetDrawingArrangeCommand=ft,R.SetSheetDrawingCommand=Pe,R.SidebarSheetDrawingOperation=gt,R.UngroupSheetDrawingCommand=St,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-drawing-ui",
3
- "version": "0.6.4-nightly.202503101606",
3
+ "version": "0.6.4-nightly.202503111607",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -58,17 +58,17 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "@univerjs/icons": "^0.2.21",
61
- "@univerjs/core": "0.6.4-nightly.202503101606",
62
- "@univerjs/design": "0.6.4-nightly.202503101606",
63
- "@univerjs/docs-drawing": "0.6.4-nightly.202503101606",
64
- "@univerjs/docs-ui": "0.6.4-nightly.202503101606",
65
- "@univerjs/drawing": "0.6.4-nightly.202503101606",
66
- "@univerjs/drawing-ui": "0.6.4-nightly.202503101606",
67
- "@univerjs/sheets": "0.6.4-nightly.202503101606",
68
- "@univerjs/sheets-ui": "0.6.4-nightly.202503101606",
69
- "@univerjs/ui": "0.6.4-nightly.202503101606",
70
- "@univerjs/sheets-drawing": "0.6.4-nightly.202503101606",
71
- "@univerjs/engine-render": "0.6.4-nightly.202503101606"
61
+ "@univerjs/core": "0.6.4-nightly.202503111607",
62
+ "@univerjs/design": "0.6.4-nightly.202503111607",
63
+ "@univerjs/docs-drawing": "0.6.4-nightly.202503111607",
64
+ "@univerjs/drawing": "0.6.4-nightly.202503111607",
65
+ "@univerjs/engine-render": "0.6.4-nightly.202503111607",
66
+ "@univerjs/drawing-ui": "0.6.4-nightly.202503111607",
67
+ "@univerjs/sheets": "0.6.4-nightly.202503111607",
68
+ "@univerjs/sheets-ui": "0.6.4-nightly.202503111607",
69
+ "@univerjs/docs-ui": "0.6.4-nightly.202503111607",
70
+ "@univerjs/sheets-drawing": "0.6.4-nightly.202503111607",
71
+ "@univerjs/ui": "0.6.4-nightly.202503111607"
72
72
  },
73
73
  "devDependencies": {
74
74
  "less": "^4.2.2",