@univerjs/sheets-drawing-ui 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(O,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/drawing-ui"),require("@univerjs/sheets-drawing"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("rxjs"),require("@univerjs/ui"),require("@wendellhu/redi/react-bindings"),require("@univerjs/sheets"),require("react"),require("@univerjs/design"),require("clsx")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/drawing-ui","@univerjs/sheets-drawing","@univerjs/drawing","@univerjs/engine-render","@univerjs/sheets-ui","rxjs","@univerjs/ui","@wendellhu/redi/react-bindings","@univerjs/sheets","react","@univerjs/design","clsx"],h):(O=typeof globalThis<"u"?globalThis:O||self,h(O.UniverSheetsDrawingUi={},O.UniverCore,O["@wendellhu/redi"],O.UniverDrawingUi,O.UniverSheetsDrawing,O.UniverDrawing,O.UniverEngineRender,O.UniverSheetsUi,O.rxjs,O.UniverUi,O["@wendellhu/redi/react-bindings"],O.UniverSheets,O.React,O.UniverDesign,O.clsx))})(this,function(O,h,W,te,p,N,$,B,F,Y,Z,v,j,Q,pe){"use strict";var Yt=Object.defineProperty;var Ft=(O,h,W)=>h in O?Yt(O,h,{enumerable:!0,configurable:!0,writable:!0,value:W}):O[h]=W;var J=(O,h,W)=>Ft(O,typeof h!="symbol"?h+"":h,W);const V={id:"sheet.operation.clear-drawing-transformer",type:h.CommandType.MUTATION,handler:(i,e)=>{const r=i.get($.IRenderManagerService);return e.forEach(t=>{var n,o;(o=(n=r.getRenderById(t))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},he={id:"sheet.command.remove-sheet-image",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!e)return!1;const{drawings:o}=e,a=[];o.forEach(S=>{const{unitId:f}=S;a.push(f)});const s=n.getBatchRemoveOp(o),{unitId:l,subUnitId:m,undo:u,redo:c,objects:d}=s;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:l,subUnitId:m,op:c,objects:d,type:p.DrawingApplyType.REMOVE})?(t.pushUndoRedo({unitID:l,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:l,subUnitId:m,op:u,objects:d,type:p.DrawingApplyType.INSERT}},{id:V.id,params:a}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:l,subUnitId:m,op:c,objects:d,type:p.DrawingApplyType.REMOVE}},{id:V.id,params:a}]}),!0):!1}},je="COMPONENT_SHEET_DRAWING_PANEL",Te={id:"sidebar.operation.sheet-image",type:h.CommandType.COMMAND,handler:async(i,e)=>{const r=i.get(Y.ISidebarService),t=i.get(h.LocaleService),n=i.get(h.IUniverInstanceService),o=i.get(N.IDrawingManagerService);if(!v.getSheetCommandTarget(n))return!1;switch(e.value){case"open":r.open({header:{title:t.t("sheetImage.panel.title")},children:{label:je},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:r.close();break}return!0}},Oe={id:"sheet.operation.edit-sheet-image",type:h.CommandType.OPERATION,handler:(i,e)=>{const r=i.get(N.IDrawingManagerService),t=i.get(h.ICommandService);return e==null?!1:(r.focusDrawing([e]),t.executeCommand(Te.id,{value:"open"}),!0)}},fe={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},ke=()=>{const i=Z.useDependency(N.IImageIoService),e=Z.useDependency(h.LocaleService),[r,t]=j.useState(0);return j.useEffect(()=>{const n=i.change$.subscribe(o=>{t(o)});return()=>{n.unsubscribe()}},[i]),j.createElement("div",{style:{display:r>0?"block":"none"},className:fe.uploadLoading},j.createElement("div",{className:fe.uploadLoadingBody},j.createElement("div",{className:fe.uploadLoadingBodyAnimation}),j.createElement("div",{className:fe.uploadLoadingBodyText},`${e.t("uploadLoading.loading")}: ${r}`)))};var Ke=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,ze=(i,e,r,t)=>{for(var n=t>1?void 0:t?xe(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Ke(e,r,n),n},ne=(i,e)=>(r,t)=>e(r,t,i);let Se=class extends h.RxDisposable{constructor(e,r,t,n,o,a,s){super();J(this,"_initImagePopupMenu",new Set);this._injector=e,this._drawingManagerService=r,this._canvasPopManagerService=t,this._renderManagerService=n,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET).pipe(F.takeUntil(this.dispose$)).subscribe(e=>this._create(e)),this._univerInstanceService.getTypeOfUnitDisposed$(h.UniverInstanceType.UNIVER_SHEET).pipe(F.takeUntil(this.dispose$)).subscribe(e=>this._dispose(e)),this._univerInstanceService.getAllUnitsForType(h.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._create(e)),this._uiPartsService.registerComponent(Y.BuiltInUIPart.CONTENT,()=>Z.connectInjector(ke,this._injector))}_dispose(e){const r=e.getUnitId();this._renderManagerService.removeRender(r)}_create(e){if(!e)return;const r=e.getUnitId();this._renderManagerService.has(r)&&!this._initImagePopupMenu.has(r)&&(this._popupMenuListener(r),this._initImagePopupMenu.add(r))}_hasCropObject(e){const r=e.getAllObjects();for(const t of r)if(t instanceof te.ImageCropperObject)return!0;return!1}_popupMenuListener(e){var o;const r=(o=this._renderManagerService.getRenderById(e))==null?void 0:o.scene;if(!r)return;const t=r.getTransformerByCreate();if(!t)return;let n;this.disposeWithMe(h.toDisposable(t.createControl$.subscribe(()=>{if(this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(r))return;const a=t.getSelectedObjectMap();if(a.size>1){n==null||n.dispose();return}const s=a.values().next().value;if(!s)return;const l=s.oKey,m=this._drawingManagerService.getDrawingOKey(l);if(!m)return;const{unitId:u,subUnitId:c,drawingId:d}=m;n==null||n.dispose(),n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:te.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(u,c,d)}})),this._drawingManagerService.focusDrawing([{unitId:u,subUnitId:c,drawingId:d}])}))),this.disposeWithMe(t.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(t.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(e,r,t){return[{label:"image-popup.edit",index:0,commandId:Oe.id,commandParams:{unitId:e,subUnitId:r,drawingId:t},disable:!1},{label:"image-popup.delete",index:1,commandId:he.id,commandParams:{unitId:e,drawings:[{unitId:e,subUnitId:r,drawingId:t}]},disable:!1},{label:"image-popup.crop",index:2,commandId:te.OpenImageCropOperation.id,commandParams:{unitId:e,subUnitId:r,drawingId:t},disable:!1},{label:"image-popup.reset",index:3,commandId:te.ImageResetSizeOperation.id,commandParams:[{unitId:e,subUnitId:r,drawingId:t}],disable:!1}]}};Se=ze([h.OnLifecycle(h.LifecycleStages.Steady,Se),ne(0,W.Inject(W.Injector)),ne(1,N.IDrawingManagerService),ne(2,W.Inject(B.SheetCanvasPopManagerService)),ne(3,$.IRenderManagerService),ne(4,h.IUniverInstanceService),ne(5,h.IContextService),ne(6,W.Inject(Y.IUIPartsService))],Se);const ae={id:"sheet.operation.insert-float-image",type:h.CommandType.OPERATION,handler:(i,e)=>!0},se={id:"sheet.operation.insert-cell-image",type:h.CommandType.OPERATION,handler:(i,e)=>!0},we={id:"sheet.command.insert-sheet-image",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!e)return!1;const o=e.drawings,a=o.map(S=>S.unitId),s=n.getBatchAddOp(o),{unitId:l,subUnitId:m,undo:u,redo:c,objects:d}=s;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:c,unitId:l,subUnitId:m,objects:d,type:p.DrawingApplyType.INSERT})?(t.pushUndoRedo({unitID:l,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:l,subUnitId:m,objects:d,type:p.DrawingApplyType.REMOVE}},{id:V.id,params:a}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:c,unitId:l,subUnitId:m,objects:d,type:p.DrawingApplyType.INSERT}},{id:V.id,params:a}]}),!0):!1}},ce={id:"sheet.command.set-sheet-image",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!e)return!1;const{drawings:o}=e,a=n.getBatchUpdateOp(o),{unitId:s,subUnitId:l,undo:m,redo:u,objects:c}=a;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:s,subUnitId:l,op:u,objects:c,type:p.DrawingApplyType.UPDATE})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:m,objects:c,type:p.DrawingApplyType.UPDATE}},{id:V.id,params:[s]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:u,objects:c,type:p.DrawingApplyType.UPDATE}},{id:V.id,params:[s]}]}),!0):!1}},Ee={id:"sheet.command.set-drawing-arrange",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService);if(!e)return!1;const n=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:l}=e,m={unitId:o,subUnitId:a,drawingIds:s};let u;if(l===N.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(m):l===N.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(m):l===N.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(m):l===N.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(m)),u==null)return!1;const{objects:c,redo:d,undo:g}=u;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:d,unitId:o,subUnitId:a,objects:c,type:p.DrawingApplyType.ARRANGE})?(t.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:c,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:d,unitId:o,subUnitId:a,objects:c,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}};function qe(i){const e=[];return i.forEach(r=>{const{parent:t,children:n}=r,{unitId:o,subUnitId:a,drawingId:s}=t,l=$.getGroupState(0,0,n.map(c=>c.transform||{})),m=n.map(c=>{const d=c.transform||{left:0,top:0},{unitId:g,subUnitId:S,drawingId:f}=c;return{unitId:g,subUnitId:S,drawingId:f,transform:{...d,left:d.left-l.left,top:d.top-l.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:N.DrawingTypeEnum.DRAWING_GROUP,transform:l};e.push({parent:u,children:m})}),e}function Je(i){const e=[];return i.forEach(r=>{const{parent:t,children:n}=r,{unitId:o,subUnitId:a,drawingId:s,transform:l={width:0,height:0}}=t;if(l==null)return;const m=n.map(c=>{const{transform:d}=c,{unitId:g,subUnitId:S,drawingId:f}=c,w=$.transformObjectOutOfGroup(d||{},l,l.width||0,l.height||0);return{unitId:g,subUnitId:S,drawingId:f,transform:w,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:N.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};e.push({parent:u,children:m})}),e}const be={id:"sheet.command.group-sheet-image",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!e)return!1;const o=[];e.forEach(({parent:g,children:S})=>{o.push(g.unitId),S.forEach(f=>{o.push(f.unitId)})});const a=n.getGroupDrawingOp(e),{unitId:s,subUnitId:l,undo:m,redo:u,objects:c}=a;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:c,type:p.DrawingApplyType.GROUP})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:l,objects:Je(c),type:p.DrawingApplyType.UNGROUP}},{id:V.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:c,type:p.DrawingApplyType.GROUP}},{id:V.id,params:o}]}),!0):!1}},Pe={id:"sheet.command.ungroup-sheet-image",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!e)return!1;const o=[];e.forEach(({parent:g,children:S})=>{o.push(g.unitId),S.forEach(f=>{o.push(f.unitId)})});const a=n.getUngroupDrawingOp(e),{unitId:s,subUnitId:l,undo:m,redo:u,objects:c}=a;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:c,type:p.DrawingApplyType.UNGROUP})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:l,objects:qe(c),type:p.DrawingApplyType.GROUP}},{id:V.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:c,type:p.DrawingApplyType.UNGROUP}},{id:V.id,params:o}]}),!0):!1}};function H(i,e,r){const{from:t,to:n,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:l=0,skewY:m=0}=i,{column:u,columnOffset:c,row:d,rowOffset:g}=t,{column:S,columnOffset:f,row:w,rowOffset:I}=n,R=e.attachRangeWithCoord({startColumn:u,endColumn:u,startRow:d,endRow:d});if(R==null)return;const y=e.attachRangeWithCoord({startColumn:S,endColumn:S,startRow:w,endRow:w});if(y==null)return;const{startX:D,startY:C}=R,{startX:P,startY:_}=y;let U=$.precisionTo(D+c,1),A=$.precisionTo(C+g,1),T=$.precisionTo(P+f-U,1),b=$.precisionTo(_+I-A,1);R.startX===y.endX&&(T=0),R.startY===y.endY&&(b=0);const E=r.getCurrentSkeleton(),M=E.rowHeaderWidth+E.columnTotalWidth,L=E.columnHeaderHeight+E.rowTotalHeight;return U+T>M&&(U=M-T),A+b>L&&(A=L-b),{flipY:o,flipX:a,angle:s,skewX:l,skewY:m,left:U,top:A,width:T,height:b}}function G(i,e){const{left:r=0,top:t=0,width:n=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:l=0,skewX:m=0,skewY:u=0}=i,c=e.getSelectionCellByPosition(r,t);if(c==null)return;const d={column:c.actualColumn,columnOffset:$.precisionTo(r-c.startX,1),row:c.actualRow,rowOffset:$.precisionTo(t-c.startY,1)},g=e.getSelectionCellByPosition(r+n,t+o);if(g==null)return;const S={column:g.actualColumn,columnOffset:$.precisionTo(r+n-g.startX,1),row:g.actualRow,rowOffset:$.precisionTo(t+o-g.startY,1)};return{flipY:a,flipX:s,angle:l,skewX:m,skewY:u,from:d,to:S}}var Ze=Object.defineProperty,Qe=Object.getOwnPropertyDescriptor,et=(i,e,r,t)=>{for(var n=t>1?void 0:t?Qe(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Ze(e,r,n),n},K=(i,e)=>(r,t)=>e(r,t,i);let ve=class extends h.Disposable{constructor(i,e,r,t,n,o,a,s,l,m,u,c,d){super(),this._context=i,this._commandService=e,this._univerInstanceService=r,this._selectionManagerService=t,this._selectionRenderService=n,this._imageIoService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._contextService=l,this._messageService=m,this._localeService=u,this._renderManagerService=c,this._sheetSkeletonManagerService=d,this._init()}_init(){this._initCommandListeners(),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener(),this._drawingAddListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async i=>{if(i.id===se.id||i.id===ae.id){const e=i.params;if(e.files==null)return;const r=e.files.length;if(r>N.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:Q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(N.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(r),i.id===se.id?e.files.forEach(async t=>{await this._insertCellImage(t)}):e.files.forEach(async t=>{await this._insertFloatImage(t)})}}))}async _insertCellImage(i){}async _insertFloatImage(i){let e;try{e=await this._imageIoService.saveImage(i)}catch(R){const y=R.message;y===N.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(N.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===N.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===N.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const r=this._getUnitInfo();if(r==null)return;const{unitId:t,subUnitId:n}=r,{imageId:o,imageSourceType:a,source:s,base64Cache:l}=e,{width:m,height:u,image:c}=await N.getImageSize(l||""),d=this._renderManagerService.getRenderById(t);if(d==null)return;const{width:g,height:S}=d.scene;this._imageIoService.addImageSourceCache(s,a,c);let f=1;if(m>N.DRAWING_IMAGE_WIDTH_LIMIT||u>N.DRAWING_IMAGE_HEIGHT_LIMIT){const R=N.DRAWING_IMAGE_WIDTH_LIMIT/m,y=N.DRAWING_IMAGE_HEIGHT_LIMIT/u;f=Math.max(R,y)}const w=this._getImagePosition(m*f,u*f,g,S);if(w==null)return;const I={unitId:t,subUnitId:n,drawingId:o,drawingType:N.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:s,transform:H(w,this._selectionRenderService,this._sheetSkeletonManagerService),sheetTransform:w};this._commandService.executeCommand(we.id,{unitId:t,drawings:[I]})}_getUnitInfo(){const i=this._univerInstanceService.getCurrentUnitForType(h.UniverInstanceType.UNIVER_SHEET);if(i==null)return;const e=i.getActiveSheet();if(e==null)return;const r=i.getUnitId(),t=e.getSheetId();return{unitId:r,subUnitId:t}}_getImagePosition(i,e,r,t){const n=this._selectionManagerService.getSelections();let o={startRow:0,endRow:0,startColumn:0,endColumn:0};n&&n.length>0&&(o=n[n.length-1].range);const a=this._selectionRenderService.attachRangeWithCoord(o);if(a==null)return;let{startColumn:s,startRow:l,startX:m,startY:u}=a,c=!1;if(m+i>r&&(m=r-i,m<0&&(m=0,i=r),c=!0),u+e>t&&(u=t-e,u<0&&(u=0,e=t),c=!0),c){const f=this._selectionRenderService.getSelectionCellByPosition(m,u);if(f==null)return;m=f.startX,u=f.startY,s=f.actualColumn,l=f.actualRow}const d={column:s,columnOffset:0,row:l,rowOffset:0},g=this._selectionRenderService.getSelectionCellByPosition(m+i,u+e);if(g==null)return;const S={column:g.actualColumn,columnOffset:m+i-g.startX,row:g.actualRow,rowOffset:u+e-g.startY};return{from:d,to:S}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(i=>{const{unitId:e,subUnitId:r,drawingIds:t,arrangeType:n}=i;this._commandService.executeCommand(Ee.id,{unitId:e,subUnitId:r,drawingIds:t,arrangeType:n})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(i=>{const e=[];i.length!==0&&(i.forEach(r=>{const{unitId:t,subUnitId:n,drawingId:o,drawingType:a,transform:s}=r;if(s==null)return;const l=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:n,drawingId:o});if(l==null)return;const m=G({...l.transform,...s},this._selectionRenderService);if(m==null)return;const u={...r,transform:{...l.transform,...s,...H(m,this._selectionRenderService,this._sheetSkeletonManagerService)},sheetTransform:{...m}};e.push(u)}),e.length>0&&this._commandService.executeCommand(ce.id,{unitId:i[0].unitId,drawings:e}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(i=>{this._commandService.executeCommand(be.id,i);const{unitId:e,subUnitId:r,drawingId:t}=i[0].parent;this._drawingManagerService.focusDrawing([{unitId:e,subUnitId:r,drawingId:t}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(i=>{this._commandService.executeCommand(Pe.id,i)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(i=>{i==null||i.length===0?(this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(i))}))}_drawingAddListener(){this.disposeWithMe(this._sheetDrawingService.add$.subscribe(i=>{this._registerDrawing(i)}))}_registerDrawing(i){i.forEach(r=>{const t=this._sheetDrawingService.getDrawingByParam(r);if(t==null)return;const{sheetTransform:n}=t;t.transform=H(n,this._selectionRenderService,this._sheetSkeletonManagerService)});const e=i[0].unitId;this._drawingManagerService.registerDrawingData(e,this._sheetDrawingService.getDrawingDataForUnit(e)),this._drawingManagerService.initializeNotification(e)}};ve=et([h.OnLifecycle(h.LifecycleStages.Rendered,ve),K(1,h.ICommandService),K(2,h.IUniverInstanceService),K(3,W.Inject(v.SelectionManagerService)),K(4,B.ISelectionRenderService),K(5,N.IImageIoService),K(6,p.ISheetDrawingService),K(7,N.IDrawingManagerService),K(8,h.IContextService),K(9,Y.IMessageService),K(10,W.Inject(h.LocaleService)),K(11,$.IRenderManagerService),K(12,W.Inject(B.SheetSkeletonManagerService))],ve);var x=function(){return x=Object.assign||function(i){for(var e,r=1,t=arguments.length;r<t;r++){e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(i[n]=e[n])}return i},x.apply(this,arguments)},tt=function(i,e){var r={};for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&e.indexOf(t)<0&&(r[t]=i[t]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,t=Object.getOwnPropertySymbols(i);n<t.length;n++)e.indexOf(t[n])<0&&Object.prototype.propertyIsEnumerable.call(i,t[n])&&(r[t[n]]=i[t[n]]);return r},We=j.forwardRef(function(i,e){var r=i.icon,t=i.id,n=i.className,o=i.extend,a=tt(i,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(t," ").concat(n||"").trim(),l=j.useRef("_".concat(it()));return $e(r,"".concat(t),{defIds:r.defIds,idSuffix:l.current},x({ref:e,className:s},a),o)});function $e(i,e,r,t,n){return j.createElement(i.tag,x(x({key:e},nt(i,r,n)),t),(rt(i,r).children||[]).map(function(o,a){return $e(o,"".concat(e,"-").concat(i.tag,"-").concat(a),r,void 0,n)}))}function nt(i,e,r){var t=x({},i.attrs);r!=null&&r.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=r.colorChannel1);var n=e.defIds;return!n||n.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(t[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function rt(i,e){var r,t=e.defIds;return!t||t.length===0?i:i.tag==="defs"&&(!((r=i.children)===null||r===void 0)&&r.length)?x(x({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&t&&t.indexOf(n.attrs.id)>-1?x(x({},n),{attrs:x(x({},n.attrs),{id:n.attrs.id+e.idSuffix})}):n})}):i}function it(){return Math.random().toString(36).substring(2,8)}We.displayName="UniverIcon";var ot={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"}}]},Be=j.forwardRef(function(i,e){return j.createElement(We,Object.assign({},i,{id:"add-image-single",ref:e,icon:ot}))});Be.displayName="AddImageSingle";const Ge={uploadFileMenu:"univer-upload-file-menu",uploadFileMenuInput:"univer-upload-file-menu-input"},Ve="COMPONENT_UPLOAD_FILE_MENU";var _e=(i=>(i[i.cellImage=0]="cellImage",i[i.floatImage=1]="floatImage",i))(_e||{});const at=i=>{const{type:e}=i,r=Z.useDependency(h.ICommandService),t=j.useRef(null),n=()=>{var s;(s=t.current)==null||s.click()},o=N.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(s=>`.${s.replace("image/","")}`).join(","),a=s=>{const l=s.target.files;if(l==null)return;const m=Array.from(l);e===_e.floatImage?r.executeCommand(ae.id,{files:m}):e===_e.cellImage&&r.executeCommand(se.id,{files:m}),t.current&&(t.current.value="")};return j.createElement("div",{onClick:n,className:Ge.uploadFileMenu},j.createElement("input",{type:"file",className:Ge.uploadFileMenuInput,ref:t,onChange:a,accept:o,multiple:!0}))},Ye="addition-and-subtraction-single",Fe="sheet.menu.image";function st(i){return{id:Fe,type:Y.MenuItemType.SUBITEMS,positions:[Y.MenuPosition.TOOLBAR_START,Y.MenuPosition.TOOLBAR_INSERT],group:Y.MenuGroup.TOOLBAR_FORMULAS_INSERT,icon:Ye,tooltip:"sheetImage.title",hidden$:Y.getMenuHiddenObservable(i,h.UniverInstanceType.UNIVER_SHEET),disabled$:B.getCurrentRangeDisable$(i,{workbookTypes:[v.WorkbookEditablePermission],worksheetTypes:[v.WorksheetEditPermission],rangeTypes:[v.RangeProtectionPermissionEditPoint]})}}function ct(i){return{id:ae.id,title:"sheetImage.upload.float",type:Y.MenuItemType.SELECTOR,label:{name:Ve,props:{type:_e.floatImage}},positions:[Fe],hidden$:Y.getMenuHiddenObservable(i,h.UniverInstanceType.UNIVER_SHEET)}}const ee={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",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"},lt=i=>{var y;const e=Z.useDependency(h.ICommandService),r=Z.useDependency(h.LocaleService),t=Z.useDependency(N.IDrawingManagerService),n=Z.useDependency($.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:s}=a,l=n.getRenderById(s),m=l==null?void 0:l.scene;if(m==null)return;const u=m.getTransformerByCreate(),[c,d]=j.useState(!0),g=(y=a.anchorType)!=null?y:p.SheetDrawingAnchorType.Position,[S,f]=j.useState(g);function w(D,C){const P=[];return D.forEach(_=>{const{oKey:U}=_,A=C.getDrawingOKey(U);if(A==null)return P.push(null),!0;const{unitId:T,subUnitId:b,drawingId:E,drawingType:M,anchorType:L,sheetTransform:X}=A;P.push({unitId:T,subUnitId:b,drawingId:E,anchorType:L,sheetTransform:X,drawingType:M})}),P}j.useEffect(()=>{const D=u.clearControl$.subscribe(P=>{P===!0&&d(!1)}),C=u.changeStart$.subscribe(P=>{var A;const{objects:_}=P,U=w(_,t);if(U.length===0)d(!1);else if(U.length>=1){d(!0);const T=((A=U[0])==null?void 0:A.anchorType)||p.SheetDrawingAnchorType.Position;f(T)}});return()=>{C.unsubscribe(),D.unsubscribe()}},[]);function I(D){f(D);const C=t.getFocusDrawings();if(C.length===0)return;const P=C.map(_=>({unitId:_.unitId,subUnitId:_.subUnitId,drawingId:_.drawingId,anchorType:D}));e.executeCommand(ce.id,{unitId:C[0].unitId,drawings:P})}const R=D=>D?"block":"none";return j.createElement("div",{className:pe(ee.imageCommonPanelGrid,ee.imageCommonPanelBorder),style:{display:R(c)}},j.createElement("div",{className:ee.imageCommonPanelRow},j.createElement("div",{className:pe(ee.imageCommonPanelColumn,ee.imageCommonPanelTitle)},j.createElement("div",null,r.t("drawing-anchor.title")))),j.createElement("div",{className:pe(ee.imageCommonPanelRow)},j.createElement("div",{className:pe(ee.imageCommonPanelColumn)},j.createElement(Q.RadioGroup,{value:S,onChange:I,direction:"vertical"},j.createElement(Q.Radio,{value:p.SheetDrawingAnchorType.Both},r.t("drawing-anchor.both")),j.createElement(Q.Radio,{value:p.SheetDrawingAnchorType.Position},r.t("drawing-anchor.position")),j.createElement(Q.Radio,{value:p.SheetDrawingAnchorType.None},r.t("drawing-anchor.none"))))))},dt=()=>{const i=Z.useDependency(N.IDrawingManagerService),e=i.getFocusDrawings(),[r,t]=j.useState(e);return j.useEffect(()=>{const n=i.focus$.subscribe(o=>{t(o)});return()=>{n.unsubscribe()}},[]),!!(r!=null&&r.length)&&j.createElement("div",{className:ee.imageCommonPanel},j.createElement(te.DrawingCommonPanel,{drawings:r}),j.createElement(lt,{drawings:r}))},oe={id:"sheet.command.move-drawing",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(p.ISheetDrawingService),n=i.get(B.ISelectionRenderService),{direction:o}=e,a=t.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,l=a.map(u=>{const{transform:c}=u;if(c==null)return null;const d={...c},{left:g=0,top:S=0}=c;return o===h.Direction.UP?d.top=S-1:o===h.Direction.DOWN?d.top=S+1:o===h.Direction.LEFT?d.left=g-1:o===h.Direction.RIGHT&&(d.left=g+1),{...u,transform:d,sheetTransform:G(d,n)}}).filter(u=>u!=null);return r.syncExecuteCommand(ce.id,{unitId:s,drawings:l})?(r.syncExecuteCommand(V.id,[s]),!0):!1}},Ae={id:"sheet.command.delete-drawing",type:h.CommandType.COMMAND,handler:i=>{const e=i.get(h.ICommandService),t=i.get(p.ISheetDrawingService).getFocusDrawings();if(t.length===0)return!1;const n=t[0].unitId,o=t.map(a=>{const{unitId:s,subUnitId:l,drawingId:m,drawingType:u}=a;return{unitId:s,subUnitId:l,drawingId:m,drawingType:u}});return e.executeCommand(he.id,{unitId:n,drawings:o})}};function le(i){return!i.getContextValue(h.FOCUSING_FORMULA_EDITOR)&&!i.getContextValue(h.EDITOR_ACTIVATED)&&i.getContextValue(h.FOCUSING_COMMON_DRAWINGS)}const ut={id:oe.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_DOWN,priority:100,preconditions:le,staticParameters:{direction:h.Direction.DOWN}},mt={id:oe.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_UP,priority:100,preconditions:le,staticParameters:{direction:h.Direction.UP}},gt={id:oe.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_LEFT,priority:100,preconditions:le,staticParameters:{direction:h.Direction.LEFT}},pt={id:oe.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_RIGHT,priority:100,preconditions:le,staticParameters:{direction:h.Direction.RIGHT}},ht={id:Ae.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:le,binding:Y.KeyCode.DELETE,mac:Y.KeyCode.BACKSPACE};var ft=Object.defineProperty,St=Object.getOwnPropertyDescriptor,wt=(i,e,r,t)=>{for(var n=t>1?void 0:t?St(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&ft(e,r,n),n},de=(i,e)=>(r,t)=>e(r,t,i);const vt={};let ue=class extends h.Disposable{constructor(i,e,r,t,n,o){super(),this._config=i,this._injector=e,this._componentManager=r,this._menuService=t,this._commandService=n,this._shortcutService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Ye,Be)),this.disposeWithMe(i.register(Ve,at)),this.disposeWithMe(i.register(je,dt))}_initMenus(){const{menu:i={}}=this._config;[st,ct].forEach(e=>{this._menuService.addMenuItem(e(this._injector),i)})}_initCommands(){[ae,se,we,he,ce,Te,V,Oe,be,Pe,oe,Ae,Ee].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[ut,mt,gt,pt,ht].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};ue=wt([h.OnLifecycle(h.LifecycleStages.Rendered,ue),de(1,W.Inject(W.Injector)),de(2,W.Inject(Y.ComponentManager)),de(3,Y.IMenuService),de(4,h.ICommandService),de(5,Y.IShortcutService)],ue);var _t=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,It=(i,e,r,t)=>{for(var n=t>1?void 0:t?Ct(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&_t(e,r,n),n},re=(i,e)=>(r,t)=>e(r,t,i);const yt=[v.InsertRowCommand.id,v.InsertColCommand.id,v.RemoveRowCommand.id,v.RemoveColCommand.id,v.DeleteRangeMoveLeftCommand.id,v.DeleteRangeMoveUpCommand.id,v.InsertRangeMoveDownCommand.id,v.InsertRangeMoveRightCommand.id,v.DeltaRowHeightCommand.id,v.SetRowHeightCommand.id,v.DeltaColumnWidthCommand.id,v.SetColWidthCommand.id,v.SetRowHiddenCommand.id,v.SetSpecificRowsVisibleCommand.id,v.SetSpecificColsVisibleCommand.id,v.SetColHiddenCommand.id,v.MoveRangeCommand.id],Mt=[v.SetRowVisibleMutation.id,v.SetRowHiddenMutation.id,v.SetColVisibleMutation.id,v.SetColHiddenMutation.id,v.SetWorksheetRowHeightMutation.id,v.SetWorksheetColWidthMutation.id];let Ce=class extends h.Disposable{constructor(i,e,r,t,n,o,a,s){super(),this._context=i,this._commandService=e,this._sheetInterceptorService=r,this._sheetDrawingService=t,this._drawingManagerService=n,this._selectionRenderService=o,this._univerInstanceService=a,this._sheetSkeletonManagerService=s,this._init()}_init(){this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!yt.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const e=i.id;if(e===v.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if(e===v.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(e===v.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(e===v.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(e===v.MoveRangeCommand.id)return this._moveRangeInterceptor(i.params);if(e===v.DeleteRangeMoveLeftCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,0)}else if(e===v.DeleteRangeMoveUpCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,1)}else if(e===v.InsertRangeMoveDownCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,2)}else if(e===v.InsertRangeMoveRightCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,3)}else if(e===v.SetRowHiddenCommand.id||e===v.SetSpecificRowsVisibleCommand.id){const r=i.params,{unitId:t,subUnitId:n,ranges:o}=r;return this._getDrawingUndoForRowVisible(t,n,o)}else if(e===v.SetSpecificColsVisibleCommand.id||e===v.SetColHiddenCommand.id){const r=i.params,{unitId:t,subUnitId:n,ranges:o}=r;return this._getDrawingUndoForColVisible(t,n,o)}else if(e===v.DeltaRowHeightCommand.id||e===v.SetRowHeightCommand.id||e===v.DeltaColumnWidthCommand.id||e===v.SetColWidthCommand.id){const r=i.params,{unitId:t,subUnitId:n,ranges:o}=r,a=e===v.DeltaRowHeightCommand.id||e===v.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(t,n,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,e){const r=v.getSheetCommandTarget(this._univerInstanceService);if(r==null)return{redos:[],undos:[]};const t=r.unitId,n=r.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(t,n),l=[],m=[];if(Object.keys(s).forEach(u=>{const c=s[u],{updateDrawings:d,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(i,e,c);l.push(...d),m.push(...g)}),l.length===0&&m.length===0)return{redos:[],undos:[]};if(l.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(l),{undo:c,redo:d,objects:g}=u;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:d,objects:g,type:p.DrawingApplyType.UPDATE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:c,objects:g,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(m),c=u.undo,d=u.redo,g=u.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:d,objects:g,type:p.DrawingApplyType.REMOVE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:c,objects:g,type:p.DrawingApplyType.INSERT}})}return o.push({id:V.id,params:[t]}),a.push({id:V.id,params:[t]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,e,r){const t=[],n=[],{sheetTransform:o,anchorType:a=p.SheetDrawingAnchorType.Position,transform:s,unitId:l,subUnitId:m,drawingId:u}=r,{from:c,to:d}=o,{row:g,column:S}=c,{row:f,column:w}=d;if(o==null||s==null)return{updateDrawings:t,deleteDrawings:n};const{startRow:I,endRow:R,startColumn:y,endColumn:D}=i;let C=null,P=null;if(e===0&&g>=I&&f<=R)if(S>=y&&w<=D)n.push({unitId:l,subUnitId:m,drawingId:u});else{const _=this._shrinkCol(o,s,y,D,a);C=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(e===1&&S>=y&&w<=D)if(g>=I&&f<=R)n.push({unitId:l,subUnitId:m,drawingId:u});else{const _=this._shrinkRow(o,s,I,R,a);C=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(e===2){const _=this._expandRow(o,s,I,R,a);C=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(e===3){const _=this._expandCol(o,s,y,D,a);C=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}if(C!=null&&P!=null){const _=H(C,this._selectionRenderService,this._sheetSkeletonManagerService);t.push({...r,sheetTransform:C,transform:_})}return{updateDrawings:t,deleteDrawings:n}}_remainDrawingSize(i,e,r){const t=G({...i},this._selectionRenderService);t!=null&&e.push({...r,sheetTransform:t})}_getDrawingUndoForColVisible(i,e,r){const t=this._drawingManagerService.getDrawingData(i,e),n=[],o=[];if(Object.keys(t).forEach(u=>{const c=t[u],{sheetTransform:d,transform:g,anchorType:S=p.SheetDrawingAnchorType.Position}=c;if(S===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,n,c);else{const{from:f,to:w}=d,{row:I,column:R}=f,{row:y,column:D}=w;for(let C=0;C<r.length;C++){const P=r[C],{startRow:_,endRow:U,startColumn:A,endColumn:T}=P;if(D<A)continue;if(S===p.SheetDrawingAnchorType.Position){let M=null,L=null;if(R>=A&&R<=T){const X=this._selectionRenderService.attachRangeWithCoord({startColumn:R,endColumn:T,startRow:f.row,endRow:w.row});if(X==null)return;L={...g,left:X.startX}}if(L!=null&&(M=G(L,this._selectionRenderService),M!=null&&L!=null)){n.push({...c,sheetTransform:M,transform:L});break}this._remainDrawingSize(g,n,c);continue}if(R>=A&&D<=T)continue;let b=null,E=null;if(R>=A&&R<=T){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:R,endColumn:T,startRow:f.row,endRow:w.row});if(M==null)return;E={...g,left:(M==null?void 0:M.startX)||0,width:((g==null?void 0:g.width)||0)-M.endX+M.startX}}else if(D>=A&&D<=T){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:A,endColumn:D,startRow:f.row,endRow:w.row});if(M==null)return;E={...g,left:M.startX-((g==null?void 0:g.width)||0)}}else{const M=this._selectionRenderService.attachRangeWithCoord({startColumn:A,endColumn:T,startRow:f.row,endRow:w.row});if(M==null)return;if(E={...g,width:((g==null?void 0:g.width)||0)-M.endX+M.startX},b=G(E,this._selectionRenderService),b!=null&&E!=null){o.push({...c,sheetTransform:b,transform:E});break}}if(E!=null&&(b=G(E,this._selectionRenderService)),E!=null&&b!=null){n.push({...c,sheetTransform:b,transform:E});break}else this._remainDrawingSize(g,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,e,n),l=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,e,o);l.push(...u),m.push(...c)}return{redos:a,undos:s,preRedos:l,preUndos:m}}_createUndoAndRedoMutation(i,e,r){const t=this._sheetDrawingService.getBatchUpdateOp(r),{undo:n,redo:o,objects:a}=t,s=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:e,op:o,objects:a,type:p.DrawingApplyType.UPDATE}},{id:V.id,params:[i]}],l=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:e,op:n,objects:a,type:p.DrawingApplyType.UPDATE}},{id:V.id,params:[i]}];return{redos:s,undos:l}}_getDrawingUndoForRowVisible(i,e,r){const t=this._drawingManagerService.getDrawingData(i,e),n=[],o=[];if(Object.keys(t).forEach(u=>{const c=t[u],{sheetTransform:d,transform:g,anchorType:S=p.SheetDrawingAnchorType.Position}=c;if(S===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,n,c);else{const{from:f,to:w}=d,{row:I,column:R}=f,{row:y,column:D}=w;for(let C=0;C<r.length;C++){const P=r[C],{startRow:_,endRow:U,startColumn:A,endColumn:T}=P;if(y<_)continue;if(S===p.SheetDrawingAnchorType.Position){let M=null,L=null;if(I>=_&&I<=U){const X=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:I,endRow:U});if(X==null)return;L={...g,top:X.startY}}if(L!=null&&(M=G(L,this._selectionRenderService),M!=null&&L!=null)){n.push({...c,sheetTransform:M,transform:L});break}this._remainDrawingSize(g,n,c);continue}if(I>=_&&y<=U)continue;let b=null,E=null;if(I>=_&&I<=U){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:I,endRow:U});if(M==null)return;E={...g,top:(M==null?void 0:M.startY)||0,height:((g==null?void 0:g.height)||0)-M.endY+M.startY}}else if(y>=_&&y<=U){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:y});if(M==null)return;E={...g,top:M.startY-((g==null?void 0:g.height)||0)}}else{const M=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:U});if(M==null)return;if(E={...g,height:((g==null?void 0:g.height)||0)-M.endY+M.startY},b=G(E,this._selectionRenderService),b!=null&&E!=null){o.push({...c,sheetTransform:b,transform:E});break}}if(E!=null&&(b=G(E,this._selectionRenderService)),E!=null&&b!=null){n.push({...c,sheetTransform:b,transform:E});break}else this._remainDrawingSize(g,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,e,n),l=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,e,o);l.push(...u),m.push(...c)}return{redos:a,undos:s,preRedos:l,preUndos:m}}_getDrawingUndoForRowAndColSize(i,e,r,t){const n=this._drawingManagerService.getDrawingData(i,e),o=[];return Object.keys(n).forEach(a=>{const s=n[a],{sheetTransform:l,transform:m,anchorType:u=p.SheetDrawingAnchorType.Position}=s;if(u===p.SheetDrawingAnchorType.None)this._remainDrawingSize(m,o,s);else{const{from:c,to:d}=l,{row:g,column:S}=c,{row:f,column:w}=d;for(let I=0;I<r.length;I++){const R=r[I],{startRow:y,endRow:D,startColumn:C,endColumn:P}=R;if(f<y||w<C)continue;if(u===p.SheetDrawingAnchorType.Position&&(g<=y&&f>=D||S<=C&&w>=P)){this._remainDrawingSize(m,o,s);continue}const _=H({...l},this._selectionRenderService,this._sheetSkeletonManagerService);if(_!=null){o.push({...s,transform:_});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,e,o)}_getUnitIdAndSubUnitId(i,e){let r,t;if(e==="insert")r=i.unitId,t=i.subUnitId;else{const n=v.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;r=n.unitId,t=n.subUnitId}return{unitId:r,subUnitId:t}}_moveRowInterceptor(i,e){const r=this._getUnitIdAndSubUnitId(i,e);if(r==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=r,{range:o}=i,a=o.startRow,s=o.endRow,l=[],m=[],u=this._sheetDrawingService.getDrawingData(t,n),c=[],d=[];if(Object.keys(u).forEach(g=>{const S=u[g],{sheetTransform:f,transform:w,anchorType:I=p.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let R,y;if(e==="insert"){const C=this._expandRow(f,w,a,s,I);R=C==null?void 0:C.newSheetTransform,y=C==null?void 0:C.newTransform}else{const{from:C,to:P}=f,{row:_}=C,{row:U}=P;if(I===p.SheetDrawingAnchorType.Both&&_>=a&&U<=s)d.push({unitId:t,subUnitId:n,drawingId:g});else{const A=this._shrinkRow(f,w,a,s,I);R=A==null?void 0:A.newSheetTransform,y=A==null?void 0:A.newTransform}}if(!R||!y)return;const D={unitId:t,subUnitId:n,drawingId:g,transform:y,sheetTransform:R};c.push(D)}),c.length===0&&d.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:S,redo:f,objects:w}=g;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.UPDATE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.UPDATE}})}if(d.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(d),S=g.undo,f=g.redo,w=g.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.REMOVE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.INSERT}})}return l.push({id:V.id,params:[t]}),m.push({id:V.id,params:[t]}),{redos:l,undos:m}}_moveRangeInterceptor(i){const{fromRange:e,toRange:r}=i,t=v.getSheetCommandTarget(this._univerInstanceService);if(!t)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=t,a=this._sheetDrawingService.getDrawingData(n,o),s=[],l=this._selectionRenderService.attachRangeWithCoord(e),m=this._selectionRenderService.attachRangeWithCoord(r);if(!l||!m)return{redos:[],undos:[]};Object.keys(a).forEach(d=>{const g=a[d],{sheetTransform:S,transform:f,anchorType:w=p.SheetDrawingAnchorType.Position}=g;if(!S||!f||w===p.SheetDrawingAnchorType.None)return;const{left:I=0,top:R=0,width:y=0,height:D=0}=f,{drawingStartX:C,drawingEndX:P,drawingStartY:_,drawingEndY:U}={drawingStartX:I,drawingEndX:I+y,drawingStartY:R,drawingEndY:R+D};if(!(l.startX<=C&&P<=l.endX&&l.startY<=U&&_<=l.endY))return;const{to:T,from:b}=S,E=r.startRow-e.startRow,M=r.startColumn-e.startColumn;let L,X;if(w===p.SheetDrawingAnchorType.Both){const z=this._selectionRenderService.attachRangeWithCoord({startRow:T.row,endRow:b.row,startColumn:T.column,endColumn:b.column}),q=this._selectionRenderService.attachRangeWithCoord({startRow:T.row+E,endRow:b.row+E,startColumn:T.column+M,endColumn:b.column+M});if(!q||!z)return;const ge=q.endX-q.startX-(z.endX-z.startX),k=q.endY-q.startY-(z.endY-z.startY);L={to:{...T,row:T.row+E,column:T.column+M,columnOffset:T.columnOffset+ge},from:{...b,row:b.row+E,column:b.column+M,columnOffset:T.columnOffset+ge,rowOffset:T.rowOffset+k}},X=H(L,this._selectionRenderService,this._sheetSkeletonManagerService)}else{const z=m.startX-l.startX,q=m.startY-l.startY;X={...f,left:I+z,top:R+q},L=G(X,this._selectionRenderService)}if(!L||!X)return;const Le={unitId:n,subUnitId:o,drawingId:d,transform:X,sheetTransform:L};s.push(Le)});const u=[],c=[];if(s.length>0){const d=this._sheetDrawingService.getBatchUpdateOp(s),{undo:g,redo:S,objects:f}=d;u.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:S,objects:f,type:p.DrawingApplyType.UPDATE}}),c.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:g,objects:f,type:p.DrawingApplyType.UPDATE}})}return{redos:u,undos:c}}_moveColInterceptor(i,e){const r=this._getUnitIdAndSubUnitId(i,e);if(r==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=r,{range:o}=i,a=o.startColumn,s=o.endColumn,l=[],m=[],u=this._sheetDrawingService.getDrawingData(t,n),c=[],d=[];if(Object.keys(u).forEach(g=>{const S=u[g],{sheetTransform:f,transform:w,anchorType:I=p.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let R,y;if(e==="insert"){const C=this._expandCol(f,w,a,s,I);R=C==null?void 0:C.newSheetTransform,y=C==null?void 0:C.newTransform}else{const{from:C,to:P}=f,{column:_}=C,{column:U}=P;if(_>=a&&U<=s&&I===p.SheetDrawingAnchorType.Both)d.push({unitId:t,subUnitId:n,drawingId:g});else{const T=this._shrinkCol(f,w,a,s,I);R=T==null?void 0:T.newSheetTransform,y=T==null?void 0:T.newTransform}}if(!R||!y)return;const D={unitId:t,subUnitId:n,drawingId:g,transform:y,sheetTransform:R};c.push(D)}),c.length===0&&d.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:S,redo:f,objects:w}=g;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.UPDATE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.UPDATE}})}if(d.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(d),S=g.undo,f=g.redo,w=g.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.REMOVE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.INSERT}})}return l.push({id:V.id,params:[t]}),m.push({id:V.id,params:[t]}),{redos:l,undos:m}}_expandCol(i,e,r,t,n=p.SheetDrawingAnchorType.Position){const o=t-r+1,{from:a,to:s}=i,{column:l}=a,{column:m}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};let u=null,c=null;if(l>=r){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:r,endColumn:t,startRow:a.row,endRow:s.row});if(d==null)return;c={...e,left:(e.left||0)+d.endX-d.startX},u=G(c,this._selectionRenderService)}else if(m>=t)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m+o}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService);else return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(i,e,r,t,n=p.SheetDrawingAnchorType.Position){const o=t-r+1,{from:a,to:s}=i,{column:l}=a,{column:m}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};let u=null,c=null;if(l>t){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:r,endColumn:t,startRow:a.row,endRow:s.row});if(d==null)return;c={...e,left:(e.left||0)-(d.endX-d.startX)},u=G(c,this._selectionRenderService)}else if(l>=r&&m<=t){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:r,endColumn:t,startRow:0,endRow:0});u={from:{...a,columnOffset:0},to:{...s,columnOffset:s.columnOffset-a.columnOffset}},c={...e,left:d==null?void 0:d.startX}}else if(l<r&&m>t)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m-o}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService);else return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};else if(l>=r&&l<=t){if(l===r)c={...e,left:(e.left||0)-i.from.columnOffset};else{const d=this._selectionRenderService.attachRangeWithCoord({startColumn:r,endColumn:l-1,startRow:a.row,endRow:s.row});if(d==null)return;c={...e,left:(e.left||0)-d.endX+d.startX-i.from.columnOffset}}u=G(c,this._selectionRenderService)}else if(m>=r&&m<=t&&n===p.SheetDrawingAnchorType.Both){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:r-1,endColumn:r-1,startRow:a.row,endRow:s.row});if(d==null)return;u={from:{...a},to:{...s,column:r-1,columnOffset:d.endX-d.startX}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService)}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(i,e,r,t,n=p.SheetDrawingAnchorType.Position){const o=t-r+1,{from:a,to:s}=i,{row:l}=a,{row:m}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};let u=null,c=null;if(l>=r){const d=this._selectionRenderService.attachRangeWithCoord({startRow:r,endRow:t,startColumn:a.column,endColumn:s.column});if(d==null)return;c={...e,top:(e.top||0)+d.endY-d.startY},u=G(c,this._selectionRenderService)}else if(m>=t)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m+o}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService);else return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(i,e,r,t,n=p.SheetDrawingAnchorType.Position){const o=t-r+1,{from:a,to:s}=i,{row:l}=a,{row:m}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};let u=null,c=null;if(l>t)u={from:{...a,row:l-o},to:{...s,row:m-o}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService);else if(l>=r&&m<=t){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:0,endColumn:0,startRow:r,endRow:t});u={from:{...a,rowOffset:0},to:{...s,rowOffset:s.rowOffset-a.rowOffset}},c={...e,top:d==null?void 0:d.startY}}else if(l<r&&m>t)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m-o}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService);else return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};else if(l>=r&&l<=t){if(l===r)c={...e,top:(e.top||0)-i.from.rowOffset};else{const d=this._selectionRenderService.attachRangeWithCoord({startRow:r,endRow:l-1,startColumn:a.column,endColumn:s.column});if(d==null)return;c={...e,top:(e.top||0)-d.endY+d.startY-i.from.rowOffset}}u=G(c,this._selectionRenderService)}else if(m>=r&&m<=t&&n===p.SheetDrawingAnchorType.Both){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:r-1,endRow:r-1});if(d==null)return;u={from:{...a},to:{...s,row:r-1,rowOffset:d.endY-d.startY}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService)}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===v.SetWorksheetActiveOperation.id&&setTimeout(()=>{const e=i.params,{unitId:r,subUnitId:t}=e,n=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(n).forEach(s=>{const l=n[s];Object.keys(l).forEach(m=>{const u=l[m].data;u!=null&&Object.keys(u).forEach(c=>{if(s===r&&m===t){const d=u[c];d.transform=H(d.sheetTransform,this._selectionRenderService,this._sheetSkeletonManagerService),o.push(u[c])}else a.push(u[c])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Mt.includes(i.id)&&requestIdleCallback(()=>{const e=i.params,{unitId:r,subUnitId:t,ranges:n}=e;this._refreshDrawingTransform(r,t,n)})}))}_refreshDrawingTransform(i,e,r){const t=this._drawingManagerService.getDrawingData(i,e),n=[];Object.keys(t).forEach(o=>{const a=t[o],{sheetTransform:s,anchorType:l=p.SheetDrawingAnchorType.Position}=a;if(l===p.SheetDrawingAnchorType.None)return!0;const{from:m,to:u}=s,{row:c,column:d}=m,{row:g,column:S}=u;for(let f=0;f<r.length;f++){const w=r[f],{startRow:I,endRow:R,startColumn:y,endColumn:D}=w;if(h.Rectangle.intersects({startRow:I,endRow:R,startColumn:y,endColumn:D},{startRow:c,endRow:g,startColumn:d,endColumn:S})||c>R||d>D){n.push({...a,transform:H(s,this._selectionRenderService,this._sheetSkeletonManagerService)});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(V.id,[i]))}};Ce=It([h.OnLifecycle(h.LifecycleStages.Rendered,Ce),re(1,h.ICommandService),re(2,W.Inject(v.SheetInterceptorService)),re(3,p.ISheetDrawingService),re(4,N.IDrawingManagerService),re(5,B.ISelectionRenderService),re(6,h.IUniverInstanceService),re(7,W.Inject(B.SheetSkeletonManagerService))],Ce);var Rt=Object.defineProperty,Dt=Object.getOwnPropertyDescriptor,Tt=(i,e,r,t)=>{for(var n=t>1?void 0:t?Dt(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Rt(e,r,n),n},ie=(i,e)=>(r,t)=>e(r,t,i);function Ot(i,e,r,t){const{scaleX:n,scaleY:o}=e.getAncestorScale(),a=e.getViewport($.SHEET_VIEWPORT_KEY.VIEW_MAIN),s={left:!0,top:!0};if(!a)return{...i,absolute:s};const{left:l,right:m,top:u,bottom:c}=i,d=t.getFreeze(),{startColumn:g,startRow:S,xSplit:f,ySplit:w}=d,I=r.getNoMergeCellPositionByIndexWithNoHeader(S-w,g-f),R=r.getNoMergeCellPositionByIndexWithNoHeader(S,g),{rowHeaderWidth:y,columnHeaderHeight:D}=r,C=R.startX-I.startX,P=R.startY-I.startY,{top:_,left:U,viewportScrollX:A,viewportScrollY:T}=a;let b,E;l<U?(s.left=!0,b=(C+y+(l-U))*n,E=Math.max(Math.min((C+y+(m-U))*n,(C+y)*n),(m-A)*n)):(s.left=!1,b=Math.max((l-A)*n,(C+y)*n),E=Math.max((m-A)*n,(C+y)*n));let M,L;return u<_?(s.top=!0,M=(P+D+(u-_))*o,L=Math.max(Math.min((P+D+(m-_))*o,(P+D)*o),(c-T)*o)):(s.top=!1,M=Math.max((u-T)*o,(P+D)*o),L=Math.max((c-T)*o,(P+D)*o)),{left:b,right:E,top:M,bottom:L,absolute:s}}const Ue=(i,e,r,t)=>{const{scene:n}=e,{left:o,top:a,width:s,height:l,angle:m}=i,u={left:o,right:o+s,top:a,bottom:a+l},c=Ot(u,n,r,t);return{startX:c.left,endX:c.right,startY:c.top,endY:c.bottom,rotate:m,width:s,height:l,absolute:c.absolute}};O.SheetCanvasFloatDomManagerService=class extends h.Disposable{constructor(r,t,n,o,a,s,l){super();J(this,"_domLayerMap",new Map);J(this,"_domLayerInfoMap",new Map);J(this,"_transformChange$",new F.Subject);J(this,"transformChange$",this._transformChange$.asObservable());J(this,"_remove$",new F.Subject);J(this,"remove$",this._remove$.asObservable());this._renderManagerService=r,this._univerInstanceService=t,this._commandService=n,this._drawingManagerService=o,this._selectionRenderService=a,this._canvasFloatDomService=s,this._sheetDrawingService=l,this._drawingAddListener(),this._scrollUpdateListener(),this._featureUpdateListener(),this._deleteListener()}_ensureMap(r,t){let n=this._domLayerMap.get(r);n||(n=new Map,this._domLayerMap.set(r,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}_getSceneAndTransformerByDrawingSearch(r){if(r==null)return;const t=this._renderManagerService.getRenderById(r),n=t==null?void 0:t.scene;if(t==null||n==null)return null;const o=n.getTransformerByCreate(),a=t.engine.getCanvasElement();return{scene:n,transformer:o,renderObject:t,canvas:a}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(r=>{r.forEach(t=>{var q,ge;const{unitId:n,subUnitId:o,drawingId:a}=t,s=v.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),l=this._drawingManagerService.getDrawingByParam(t),m=(q=this._renderManagerService.getRenderById(n))==null?void 0:q.with(B.SheetSkeletonManagerService).getUnitSkeleton(n,o);if(l==null||s==null||m==null)return;const{transform:u,drawingType:c}=l;if(c!==h.DrawingTypeEnum.DRAWING_DOM)return;const d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{scene:g,canvas:S}=d;if(u==null)return!0;const{left:f,top:w,width:I,height:R,angle:y,flipX:D,flipY:C,skewX:P,skewY:_}=u,U=N.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),A=g.getObject(U);if(A!=null){A.transformByState({left:f,top:w,width:I,height:R,angle:y,flipX:D,flipY:C,skewX:P,skewY:_});return}const T={left:f,top:w,width:I,height:R,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},b=new $.Rect(U,T);g.addObject(b,$.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(b);const E=this._ensureMap(n,o),M=new h.DisposableCollection,L=Ue(b,d.renderObject,m.skeleton,s.worksheet),X=new F.BehaviorSubject(L),Le={dispose:M,rect:b,position$:X,unitId:n,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:X,id:a,componentKey:l.componentKey,onPointerDown:k=>{S.dispatchEvent(new PointerEvent(k.type,k))},onPointerMove:k=>{S.dispatchEvent(new PointerEvent(k.type,k))},onPointerUp:k=>{S.dispatchEvent(new PointerEvent(k.type,k))},onWheel:k=>{S.dispatchEvent(new WheelEvent(k.type,k))},props:(ge=E.get(a))==null?void 0:ge.props});const z=b.onTransformChange$.subscribeEvent(()=>{const k=Ue(b,d.renderObject,m.skeleton,s.worksheet);X.next(k)});M.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),z&&M.add(z),this._domLayerInfoMap.set(a,Le)})}))}_scrollUpdateListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{var n,o;const t=(a,s)=>{var g;const l=this._getSceneAndTransformerByDrawingSearch(a),m=this._ensureMap(a,s),u=Array.from(m.keys()),c=v.getSheetCommandTarget(this._univerInstanceService,{unitId:a,subUnitId:s}),d=(g=this._renderManagerService.getRenderById(a))==null?void 0:g.with(B.SheetSkeletonManagerService).getUnitSkeleton(a,s);!l||!c||!d||u.forEach(S=>{const f=this._domLayerInfoMap.get(S);if(f){const w=Ue(f.rect,l.renderObject,d.skeleton,c.worksheet);f.position$.next(w)}})};if(r.id===B.SetScrollOperation.id){const a=r.params,{unitId:s,sheetId:l}=a;t(s,l)}else if(r.id===B.SetZoomRatioOperation.id){const a=r.params,{unitId:s}=a;Array.from((o=(n=this._domLayerMap.get(s))==null?void 0:n.keys())!=null?o:[]).forEach(m=>{t(s,m)})}else if(r.id===v.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=r.params;t(a,s)}}))}_getPosition(r){const{startX:t,endX:n,startY:o,endY:a}=r,s=this._selectionRenderService.getSelectionCellByPosition(t,o);if(s==null)return;const l={column:s.actualColumn,columnOffset:t-s.startX,row:s.actualRow,rowOffset:o-s.startY},m=this._selectionRenderService.getSelectionCellByPosition(n,a);if(m==null)return;const u={column:m.actualColumn,columnOffset:n-m.startX,row:m.actualRow,rowOffset:a-m.startY};return{from:l,to:u}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(r=>{r.forEach(t=>{const n=this._drawingManagerService.getDrawingByParam(t);if(!n||n.drawingType!==h.DrawingTypeEnum.DRAWING_DOM)return;const o={...n.transform};this._transformChange$.next({id:t.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(r=>{r.forEach(t=>{this._removeDom(t.drawingId)})}))}addFloatDomToPosition(r){const t=v.getSheetCommandTarget(this._univerInstanceService,{unitId:r.unitId,subUnitId:r.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:n,subUnitId:o}=t,{initPosition:a,componentKey:s}=r,l=h.Tools.generateRandomId(),m=this._getPosition(a);if(m==null)return;this._ensureMap(n,o).set(l,r);const c={unitId:n,subUnitId:o,drawingId:l,drawingType:h.DrawingTypeEnum.DRAWING_DOM,componentKey:s,sheetTransform:m,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY}};return this._commandService.executeCommand(we.id,{unitId:n,drawings:[c]}),{id:l,dispose:()=>{this._removeDom(l,!0)}}}_removeDom(r,t=!1){const n=this._domLayerInfoMap.get(r);if(!n)return;const{unitId:o,subUnitId:a}=n;this._domLayerInfoMap.delete(r),n.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(n.rect),t){this._ensureMap(o,a).delete(r);const m=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:r});if(!m)return;const u=this._sheetDrawingService.getBatchRemoveOp([m]),{redo:c,objects:d}=u;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:c,objects:d,type:p.DrawingApplyType.REMOVE})}}},O.SheetCanvasFloatDomManagerService=Tt([ie(0,W.Inject($.IRenderManagerService)),ie(1,h.IUniverInstanceService),ie(2,W.Inject(h.ICommandService)),ie(3,N.IDrawingManagerService),ie(4,B.ISelectionRenderService),ie(5,W.Inject(Y.CanvasFloatDomService)),ie(6,p.ISheetDrawingService)],O.SheetCanvasFloatDomManagerService);var Et=Object.defineProperty,bt=Object.getOwnPropertyDescriptor,Pt=(i,e,r,t)=>{for(var n=t>1?void 0:t?bt(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Et(e,r,n),n},Ie=(i,e)=>(r,t)=>e(r,t,i);let ye=class extends h.Disposable{constructor(i,e,r,t){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=e,this._drawingManagerService=r,this._renderManagerService=t,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,e,r)=>{const{unitId:t,scene:n,subUnitId:o}=e,a=this._drawingManagerService.getDrawingDataForUnit(t),s=a==null?void 0:a[o];return s&&s.order.forEach(l=>{this._drawingRenderService.renderDrawing(s.data[l],n)}),r()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,e,r)=>{const{unitId:t,subUnitId:n}=e,o=this._renderManagerService.getRenderById(t);if(!o)return r(i);const a=o.with(B.SheetSkeletonManagerService).getUnitSkeleton(t,n);if(!a)return r(i);const s=this._drawingManagerService.getDrawingDataForUnit(t),l=s==null?void 0:s[e.subUnitId];if(!l)return r(i);const{scaleX:m,scaleY:u}=o.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},d=l.order.map(g=>l.data[g]).filter(g=>g.drawingType!==N.DrawingTypeEnum.DRAWING_DOM);return d.length?(d.forEach(g=>{if(!g.groupId&&g.transform&&h.Tools.isDefine(g.transform.left)&&h.Tools.isDefine(g.transform.top)&&h.Tools.isDefine(g.transform.width)&&h.Tools.isDefine(g.transform.height)){const S=a.skeleton.getCellPositionByOffset(g.transform.left,g.transform.top,m,u,{x:0,y:0}),f=a.skeleton.getCellPositionByOffset(g.transform.left+g.transform.width,g.transform.top+g.transform.height,m,u,{x:0,y:0});S.column<c.startColumn&&(c.startColumn=S.column),S.row<c.startRow&&(c.startRow=S.row),c.endRow<f.row&&(c.endRow=f.row),c.endColumn<f.column&&(c.endColumn=f.column)}}),r(c)):r(i)}}))}};ye=Pt([h.OnLifecycle(h.LifecycleStages.Rendered,ye),Ie(0,W.Inject(B.SheetPrintInterceptorService)),Ie(1,W.Inject(te.DrawingRenderService)),Ie(2,N.IDrawingManagerService),Ie(3,$.IRenderManagerService)],ye);var At=Object.defineProperty,Ut=Object.getOwnPropertyDescriptor,Nt=(i,e,r,t)=>{for(var n=t>1?void 0:t?Ut(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&At(e,r,n),n},me=(i,e)=>(r,t)=>e(r,t,i);let Me=class extends h.Disposable{constructor(i,e,r,t,n){super(),this._drawingManagerService=i,this._renderManagerService=e,this._permissionService=r,this._univerInstanceService=t,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(F.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([e,r])=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}e.activeSheet$.subscribe(t=>{if(!t){this._drawingManagerService.setDrawingVisible(!1);return}const n=e.getUnitId(),o=t.getSheetId();if(this._permissionService.composePermission([new v.WorkbookViewPermission(n).id,new v.WorksheetViewPermission(n,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const s=e.getUnitId(),l=t.getSheetId(),m=this._drawingManagerService.getDrawingData(s,l),u=Object.values(m),c=this._renderManagerService.getRenderById(s),d=c==null?void 0:c.scene;if(d==null)return;d.getAllObjects().forEach(S=>{S.classType===$.RENDER_CLASS_TYPE.IMAGE&&u.some(f=>S.oKey.includes(f.drawingId))&&d.removeObject(S)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(F.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([e,r])=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}e.activeSheet$.subscribe(t=>{if(!t){this._drawingManagerService.setDrawingEditable(!1);return}const n=e.getUnitId(),o=t.getSheetId();if(this._permissionService.composePermission([new v.WorkbookEditablePermission(n).id,new v.WorksheetEditPermission(n,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const s=e.getUnitId(),l=t.getSheetId(),m=this._drawingManagerService.getDrawingData(s,l),u=Object.values(m),c=this._renderManagerService.getRenderById(s),d=c==null?void 0:c.scene;if(d==null)return;d.getAllObjects().forEach(S=>{S.classType===$.RENDER_CLASS_TYPE.IMAGE&&u.some(f=>S.oKey.includes(f.drawingId))&&d.detachTransformerFrom(S)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(F.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([e,r])=>{e&&e.activeSheet$.subscribe(t=>{var c;if(!t)return;const n=e.getUnitId(),o=t.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(n),l=s==null?void 0:s.scene;if(l==null)return;const m=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookViewPermission(n).id,new v.WorksheetViewPermission(n,o).id]).pipe(F.map(d=>d.every(g=>g.value)));u==null||u.pipe(F.filter(d=>d!==a),F.distinctUntilChanged()).subscribe({next:d=>{a=d,this._drawingManagerService.setDrawingVisible(d);const g=l.getAllObjects(),S=this._drawingManagerService.getDrawingData(n,o),f=Object.values(S);d?this._drawingManagerService.addNotification(f):(g.forEach(w=>{w.classType===$.RENDER_CLASS_TYPE.IMAGE&&f.some(I=>w.oKey.includes(I.drawingId))&&l.removeObject(w)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new v.WorksheetViewPermission(n,o).id))==null||c.pipe(F.filter(d=>d.value!==a),F.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const d=this._drawingManagerService.getDrawingData(n,o),g=Object.values(d);this._drawingManagerService.addNotification(g)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(F.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([e,r])=>{e&&e.activeSheet$.subscribe(t=>{var c;if(!t)return;const n=e.getUnitId(),o=t.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(n),l=s==null?void 0:s.scene;if(l==null)return;const m=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookEditablePermission(n).id,new v.WorksheetEditPermission(n,o).id]).pipe(F.map(d=>d.every(g=>g.value)));u==null||u.pipe(F.filter(d=>d!==a),F.distinctUntilChanged()).subscribe({next:d=>{a=d,this._drawingManagerService.setDrawingEditable(d);const g=l.getAllObjects(),S=this._drawingManagerService.getDrawingData(n,o),f=Object.values(S);d?(g.forEach(w=>{w.classType===$.RENDER_CLASS_TYPE.IMAGE&&f.some(I=>w.oKey.includes(I.drawingId))&&l.attachTransformerTo(w)}),this._drawingManagerService.addNotification(f)):(g.forEach(w=>{w.classType===$.RENDER_CLASS_TYPE.IMAGE&&f.some(I=>w.oKey.includes(I.drawingId))&&l.detachTransformerFrom(w)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new v.WorksheetEditPermission(n,o).id))==null||c.pipe(F.filter(d=>d.value!==a),F.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const d=e.getUnitId(),g=t.getSheetId(),S=this._drawingManagerService.getDrawingData(d,g),f=Object.values(S),w=this._renderManagerService.getRenderById(d),I=w==null?void 0:w.scene;if(I==null)return;this._drawingManagerService.setDrawingEditable(!0),I.getAllObjects().forEach(y=>{y.classType===$.RENDER_CLASS_TYPE.IMAGE&&f.some(D=>y.oKey.includes(D.drawingId))&&I.detachTransformerFrom(y)})}})})}))}};Me=Nt([h.OnLifecycle(h.LifecycleStages.Rendered,Me),me(0,N.IDrawingManagerService),me(1,$.IRenderManagerService),me(2,h.IPermissionService),me(3,h.IUniverInstanceService),me(4,W.Inject(h.UserManagerService))],Me);var Lt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,Wt=(i,e,r,t)=>{for(var n=t>1?void 0:t?jt(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Lt(e,r,n),n},Re=(i,e)=>(r,t)=>e(r,t,i);let De=class extends h.Disposable{constructor(e,r,t,n){super();J(this,"_copyInfo");this._sheetClipboardService=e,this._selectionRenderService=r,this._sheetDrawingService=t,this._injector=n,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(e,r,t)=>this._collect(e,r,t),onPasteCells:(e,r,t,n)=>{const{copyType:o=B.COPY_TYPE.COPY,pasteType:a}=n,{range:s}=e||{},{range:l,unitId:m,subUnitId:u}=r;return this._generateMutations(l,{copyType:o,pasteType:a,copyRange:s,unitId:m,subUnitId:u})},onPastePlainText:(e,r)=>({undos:[],redos:[]})})}_collect(e,r,t){const n=this._selectionRenderService.attachRangeWithCoord(t);if(!n)return;const{startX:o,endX:a,startY:s,endY:l}=n,m=this._sheetDrawingService.getDrawingData(e,r),u=[];Object.keys(m).forEach(c=>{const d=m[c],{transform:g}=d;if(d.anchorType!==p.SheetDrawingAnchorType.Both||!g)return;const{left:S=0,top:f=0,width:w=0,height:I=0}=g,{drawingStartX:R,drawingEndX:y,drawingStartY:D,drawingEndY:C}={drawingStartX:S,drawingEndX:S+w,drawingStartY:f,drawingEndY:f+I};o<=R&&y<=a&&s<=D&&C<=l&&u.push(d)}),u.length&&(this._copyInfo={drawings:u,unitId:e,subUnitId:r})}_generateMutations(e,r){if(!this._copyInfo)return{redos:[],undos:[]};if([B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(r.pasteType))return{redos:[],undos:[]};const{copyRange:t}=r;if(!t)return{redos:[],undos:[]};const{drawings:n,unitId:o,subUnitId:a}=this._copyInfo,{ranges:[s,l],mapFunc:m}=B.virtualizeDiscreteRanges([t,e]),{row:u,col:c}=m(s.startRow,s.startColumn),{row:d,col:g}=m(l.startRow,l.startColumn),S=this._selectionRenderService.attachRangeWithCoord({startRow:u,endRow:u,startColumn:c,endColumn:c}),f=this._selectionRenderService.attachRangeWithCoord({startRow:d,endRow:d,startColumn:g,endColumn:g});if(!S||!f)return{redos:[],undos:[]};const w=[],I=[],R=f.startX-S.startX,y=f.startY-S.startY,D=d-u,C=g-c,P=r.copyType===B.COPY_TYPE.CUT,{_sheetDrawingService:_}=this;return n.forEach(U=>{const{transform:A,sheetTransform:T}=U;if(!A)return;const b={...U,unitId:o,subUnitId:a,drawingId:P?U.drawingId:h.Tools.generateRandomId(),transform:{...A,left:A.left+R,top:A.top+y},sheetTransform:{to:{...T.to,row:T.to.row+D,column:T.to.column+C},from:{...T.from,row:T.from.row+D,column:T.from.column+C}}};if(P){const{undo:E,redo:M,objects:L}=_.getBatchUpdateOp([b]);w.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:M,objects:L}}),I.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:E,objects:L}})}else{const{undo:E,redo:M,objects:L}=_.getBatchAddOp([b]);w.push({id:p.SetDrawingApplyMutation.id,params:{op:M,unitId:o,subUnitId:a,objects:L,type:p.DrawingApplyType.INSERT}}),I.push({id:p.SetDrawingApplyMutation.id,params:{op:E,unitId:o,subUnitId:a,objects:L,type:p.DrawingApplyType.REMOVE}})}}),{redos:w,undos:I}}};De=Wt([h.OnLifecycle(h.LifecycleStages.Ready,De),Re(0,B.ISheetClipboardService),Re(1,B.ISelectionRenderService),Re(2,p.ISheetDrawingService),Re(3,W.Inject(W.Injector))],De);var Xe=Object.defineProperty,$t=Object.getOwnPropertyDescriptor,Bt=(i,e,r)=>e in i?Xe(i,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[e]=r,Gt=(i,e,r,t)=>{for(var n=t>1?void 0:t?$t(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Xe(e,r,n),n},Ne=(i,e)=>(r,t)=>e(r,t,i),He=(i,e,r)=>Bt(i,typeof e!="symbol"?e+"":e,r);const Vt="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends h.Plugin{constructor(r={},t,n,o){super();J(this,"_pluginConfig");this._injector=t,this._localeService=n,this._renderManagerService=o,this._pluginConfig=h.Tools.deepMerge({},vt,r)}onStarting(r){super.onStarting(r),this._initDependencies(r)}_initDependencies(r){const t=[[O.SheetCanvasFloatDomManagerService],[ue,{useFactory:()=>this._injector.createInstance(ue,this._pluginConfig)}],[Se],[ye],[Me],[De]],n=[ve,Ce];t.forEach(o=>r.add(o)),n.forEach(o=>this._renderManagerService.registerRenderModule(h.UniverInstanceType.UNIVER_SHEET,o))}},He(O.UniverSheetsDrawingUIPlugin,"type",h.UniverInstanceType.UNIVER_SHEET),He(O.UniverSheetsDrawingUIPlugin,"pluginName",Vt),O.UniverSheetsDrawingUIPlugin=Gt([h.DependentOn(N.UniverDrawingPlugin,te.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),Ne(1,W.Inject(W.Injector)),Ne(2,W.Inject(h.LocaleService)),Ne(3,$.IRenderManagerService)],O.UniverSheetsDrawingUIPlugin),O.ClearSheetDrawingTransformerOperation=V,O.DeleteDrawingsCommand=Ae,O.EditSheetDrawingOperation=Oe,O.GroupSheetDrawingCommand=be,O.InsertCellImageOperation=se,O.InsertFloatImageOperation=ae,O.InsertSheetDrawingCommand=we,O.MoveDrawingsCommand=oe,O.RemoveSheetDrawingCommand=he,O.SetDrawingArrangeCommand=Ee,O.SetSheetDrawingCommand=ce,O.SidebarSheetDrawingOperation=Te,O.UngroupSheetDrawingCommand=Pe,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
1
+ (function(O,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/drawing-ui"),require("@univerjs/sheets-drawing"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("rxjs"),require("@univerjs/ui"),require("@wendellhu/redi/react-bindings"),require("@univerjs/sheets"),require("react"),require("@univerjs/design"),require("clsx")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/drawing-ui","@univerjs/sheets-drawing","@univerjs/drawing","@univerjs/engine-render","@univerjs/sheets-ui","rxjs","@univerjs/ui","@wendellhu/redi/react-bindings","@univerjs/sheets","react","@univerjs/design","clsx"],h):(O=typeof globalThis<"u"?globalThis:O||self,h(O.UniverSheetsDrawingUi={},O.UniverCore,O["@wendellhu/redi"],O.UniverDrawingUi,O.UniverSheetsDrawing,O.UniverDrawing,O.UniverEngineRender,O.UniverSheetsUi,O.rxjs,O.UniverUi,O["@wendellhu/redi/react-bindings"],O.UniverSheets,O.React,O.UniverDesign,O.clsx))})(this,function(O,h,W,te,p,N,$,G,F,Y,Z,v,j,Q,pe){"use strict";var Yt=Object.defineProperty;var Ft=(O,h,W)=>h in O?Yt(O,h,{enumerable:!0,configurable:!0,writable:!0,value:W}):O[h]=W;var J=(O,h,W)=>Ft(O,typeof h!="symbol"?h+"":h,W);const V={id:"sheet.operation.clear-drawing-transformer",type:h.CommandType.MUTATION,handler:(i,e)=>{const r=i.get($.IRenderManagerService);return e.forEach(t=>{var n,o;(o=(n=r.getRenderById(t))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},he={id:"sheet.command.remove-sheet-image",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!e)return!1;const{drawings:o}=e,a=[];o.forEach(S=>{const{unitId:f}=S;a.push(f)});const s=n.getBatchRemoveOp(o),{unitId:l,subUnitId:m,undo:u,redo:c,objects:d}=s;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:l,subUnitId:m,op:c,objects:d,type:p.DrawingApplyType.REMOVE})?(t.pushUndoRedo({unitID:l,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:l,subUnitId:m,op:u,objects:d,type:p.DrawingApplyType.INSERT}},{id:V.id,params:a}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:l,subUnitId:m,op:c,objects:d,type:p.DrawingApplyType.REMOVE}},{id:V.id,params:a}]}),!0):!1}},je="COMPONENT_SHEET_DRAWING_PANEL",Te={id:"sidebar.operation.sheet-image",type:h.CommandType.COMMAND,handler:async(i,e)=>{const r=i.get(Y.ISidebarService),t=i.get(h.LocaleService),n=i.get(h.IUniverInstanceService),o=i.get(N.IDrawingManagerService);if(!v.getSheetCommandTarget(n))return!1;switch(e.value){case"open":r.open({header:{title:t.t("sheetImage.panel.title")},children:{label:je},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:r.close();break}return!0}},Oe={id:"sheet.operation.edit-sheet-image",type:h.CommandType.OPERATION,handler:(i,e)=>{const r=i.get(N.IDrawingManagerService),t=i.get(h.ICommandService);return e==null?!1:(r.focusDrawing([e]),t.executeCommand(Te.id,{value:"open"}),!0)}},fe={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},ke=()=>{const i=Z.useDependency(N.IImageIoService),e=Z.useDependency(h.LocaleService),[r,t]=j.useState(0);return j.useEffect(()=>{const n=i.change$.subscribe(o=>{t(o)});return()=>{n.unsubscribe()}},[i]),j.createElement("div",{style:{display:r>0?"block":"none"},className:fe.uploadLoading},j.createElement("div",{className:fe.uploadLoadingBody},j.createElement("div",{className:fe.uploadLoadingBodyAnimation}),j.createElement("div",{className:fe.uploadLoadingBodyText},`${e.t("uploadLoading.loading")}: ${r}`)))};var Ke=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,ze=(i,e,r,t)=>{for(var n=t>1?void 0:t?xe(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Ke(e,r,n),n},ne=(i,e)=>(r,t)=>e(r,t,i);let Se=class extends h.RxDisposable{constructor(e,r,t,n,o,a,s){super();J(this,"_initImagePopupMenu",new Set);this._injector=e,this._drawingManagerService=r,this._canvasPopManagerService=t,this._renderManagerService=n,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET).pipe(F.takeUntil(this.dispose$)).subscribe(e=>this._create(e)),this._univerInstanceService.getTypeOfUnitDisposed$(h.UniverInstanceType.UNIVER_SHEET).pipe(F.takeUntil(this.dispose$)).subscribe(e=>this._dispose(e)),this._univerInstanceService.getAllUnitsForType(h.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._create(e)),this._uiPartsService.registerComponent(Y.BuiltInUIPart.CONTENT,()=>Z.connectInjector(ke,this._injector))}_dispose(e){const r=e.getUnitId();this._renderManagerService.removeRender(r)}_create(e){if(!e)return;const r=e.getUnitId();this._renderManagerService.has(r)&&!this._initImagePopupMenu.has(r)&&(this._popupMenuListener(r),this._initImagePopupMenu.add(r))}_hasCropObject(e){const r=e.getAllObjects();for(const t of r)if(t instanceof te.ImageCropperObject)return!0;return!1}_popupMenuListener(e){var o;const r=(o=this._renderManagerService.getRenderById(e))==null?void 0:o.scene;if(!r)return;const t=r.getTransformerByCreate();if(!t)return;let n;this.disposeWithMe(h.toDisposable(t.createControl$.subscribe(()=>{if(this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(r))return;const a=t.getSelectedObjectMap();if(a.size>1){n==null||n.dispose();return}const s=a.values().next().value;if(!s)return;const l=s.oKey,m=this._drawingManagerService.getDrawingOKey(l);if(!m)return;const{unitId:u,subUnitId:c,drawingId:d}=m;n==null||n.dispose(),n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:te.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(u,c,d)}})),this._drawingManagerService.focusDrawing([{unitId:u,subUnitId:c,drawingId:d}])}))),this.disposeWithMe(t.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(t.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(e,r,t){return[{label:"image-popup.edit",index:0,commandId:Oe.id,commandParams:{unitId:e,subUnitId:r,drawingId:t},disable:!1},{label:"image-popup.delete",index:1,commandId:he.id,commandParams:{unitId:e,drawings:[{unitId:e,subUnitId:r,drawingId:t}]},disable:!1},{label:"image-popup.crop",index:2,commandId:te.OpenImageCropOperation.id,commandParams:{unitId:e,subUnitId:r,drawingId:t},disable:!1},{label:"image-popup.reset",index:3,commandId:te.ImageResetSizeOperation.id,commandParams:[{unitId:e,subUnitId:r,drawingId:t}],disable:!1}]}};Se=ze([h.OnLifecycle(h.LifecycleStages.Steady,Se),ne(0,W.Inject(W.Injector)),ne(1,N.IDrawingManagerService),ne(2,W.Inject(G.SheetCanvasPopManagerService)),ne(3,$.IRenderManagerService),ne(4,h.IUniverInstanceService),ne(5,h.IContextService),ne(6,W.Inject(Y.IUIPartsService))],Se);const ae={id:"sheet.operation.insert-float-image",type:h.CommandType.OPERATION,handler:(i,e)=>!0},se={id:"sheet.operation.insert-cell-image",type:h.CommandType.OPERATION,handler:(i,e)=>!0},we={id:"sheet.command.insert-sheet-image",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!e)return!1;const o=e.drawings,a=o.map(S=>S.unitId),s=n.getBatchAddOp(o),{unitId:l,subUnitId:m,undo:u,redo:c,objects:d}=s;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:c,unitId:l,subUnitId:m,objects:d,type:p.DrawingApplyType.INSERT})?(t.pushUndoRedo({unitID:l,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:l,subUnitId:m,objects:d,type:p.DrawingApplyType.REMOVE}},{id:V.id,params:a}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:c,unitId:l,subUnitId:m,objects:d,type:p.DrawingApplyType.INSERT}},{id:V.id,params:a}]}),!0):!1}},ce={id:"sheet.command.set-sheet-image",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!e)return!1;const{drawings:o}=e,a=n.getBatchUpdateOp(o),{unitId:s,subUnitId:l,undo:m,redo:u,objects:c}=a;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:s,subUnitId:l,op:u,objects:c,type:p.DrawingApplyType.UPDATE})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:m,objects:c,type:p.DrawingApplyType.UPDATE}},{id:V.id,params:[s]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:u,objects:c,type:p.DrawingApplyType.UPDATE}},{id:V.id,params:[s]}]}),!0):!1}},Ee={id:"sheet.command.set-drawing-arrange",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService);if(!e)return!1;const n=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:l}=e,m={unitId:o,subUnitId:a,drawingIds:s};let u;if(l===N.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(m):l===N.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(m):l===N.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(m):l===N.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(m)),u==null)return!1;const{objects:c,redo:d,undo:g}=u;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:d,unitId:o,subUnitId:a,objects:c,type:p.DrawingApplyType.ARRANGE})?(t.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:c,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:d,unitId:o,subUnitId:a,objects:c,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}};function qe(i){const e=[];return i.forEach(r=>{const{parent:t,children:n}=r,{unitId:o,subUnitId:a,drawingId:s}=t,l=$.getGroupState(0,0,n.map(c=>c.transform||{})),m=n.map(c=>{const d=c.transform||{left:0,top:0},{unitId:g,subUnitId:S,drawingId:f}=c;return{unitId:g,subUnitId:S,drawingId:f,transform:{...d,left:d.left-l.left,top:d.top-l.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:N.DrawingTypeEnum.DRAWING_GROUP,transform:l};e.push({parent:u,children:m})}),e}function Je(i){const e=[];return i.forEach(r=>{const{parent:t,children:n}=r,{unitId:o,subUnitId:a,drawingId:s,transform:l={width:0,height:0}}=t;if(l==null)return;const m=n.map(c=>{const{transform:d}=c,{unitId:g,subUnitId:S,drawingId:f}=c,w=$.transformObjectOutOfGroup(d||{},l,l.width||0,l.height||0);return{unitId:g,subUnitId:S,drawingId:f,transform:w,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:N.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};e.push({parent:u,children:m})}),e}const be={id:"sheet.command.group-sheet-image",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!e)return!1;const o=[];e.forEach(({parent:g,children:S})=>{o.push(g.unitId),S.forEach(f=>{o.push(f.unitId)})});const a=n.getGroupDrawingOp(e),{unitId:s,subUnitId:l,undo:m,redo:u,objects:c}=a;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:c,type:p.DrawingApplyType.GROUP})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:l,objects:Je(c),type:p.DrawingApplyType.UNGROUP}},{id:V.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:c,type:p.DrawingApplyType.GROUP}},{id:V.id,params:o}]}),!0):!1}},Pe={id:"sheet.command.ungroup-sheet-image",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!e)return!1;const o=[];e.forEach(({parent:g,children:S})=>{o.push(g.unitId),S.forEach(f=>{o.push(f.unitId)})});const a=n.getUngroupDrawingOp(e),{unitId:s,subUnitId:l,undo:m,redo:u,objects:c}=a;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:c,type:p.DrawingApplyType.UNGROUP})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:l,objects:qe(c),type:p.DrawingApplyType.GROUP}},{id:V.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:c,type:p.DrawingApplyType.UNGROUP}},{id:V.id,params:o}]}),!0):!1}};function H(i,e,r){const{from:t,to:n,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:l=0,skewY:m=0}=i,{column:u,columnOffset:c,row:d,rowOffset:g}=t,{column:S,columnOffset:f,row:w,rowOffset:I}=n,D=e.attachRangeWithCoord({startColumn:u,endColumn:u,startRow:d,endRow:d});if(D==null)return;const y=e.attachRangeWithCoord({startColumn:S,endColumn:S,startRow:w,endRow:w});if(y==null)return;const{startX:R,startY:C}=D,{startX:P,startY:_}=y;let U=$.precisionTo(R+c,1),A=$.precisionTo(C+g,1),T=$.precisionTo(P+f-U,1),b=$.precisionTo(_+I-A,1);D.startX===y.endX&&(T=0),D.startY===y.endY&&(b=0);const E=r.getCurrentSkeleton(),M=E.rowHeaderWidth+E.columnTotalWidth,L=E.columnHeaderHeight+E.rowTotalHeight;return U+T>M&&(U=M-T),A+b>L&&(A=L-b),{flipY:o,flipX:a,angle:s,skewX:l,skewY:m,left:U,top:A,width:T,height:b}}function B(i,e){const{left:r=0,top:t=0,width:n=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:l=0,skewX:m=0,skewY:u=0}=i,c=e.getSelectionCellByPosition(r,t);if(c==null)return;const d={column:c.actualColumn,columnOffset:$.precisionTo(r-c.startX,1),row:c.actualRow,rowOffset:$.precisionTo(t-c.startY,1)},g=e.getSelectionCellByPosition(r+n,t+o);if(g==null)return;const S={column:g.actualColumn,columnOffset:$.precisionTo(r+n-g.startX,1),row:g.actualRow,rowOffset:$.precisionTo(t+o-g.startY,1)};return{flipY:a,flipX:s,angle:l,skewX:m,skewY:u,from:d,to:S}}var Ze=Object.defineProperty,Qe=Object.getOwnPropertyDescriptor,et=(i,e,r,t)=>{for(var n=t>1?void 0:t?Qe(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Ze(e,r,n),n},K=(i,e)=>(r,t)=>e(r,t,i);let ve=class extends h.Disposable{constructor(i,e,r,t,n,o,a,s,l,m,u,c,d){super(),this._context=i,this._commandService=e,this._univerInstanceService=r,this._selectionManagerService=t,this._selectionRenderService=n,this._imageIoService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._contextService=l,this._messageService=m,this._localeService=u,this._renderManagerService=c,this._sheetSkeletonManagerService=d,this._init()}_init(){this._initCommandListeners(),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener(),this._drawingAddListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async i=>{if(i.id===se.id||i.id===ae.id){const e=i.params;if(e.files==null)return;const r=e.files.length;if(r>N.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:Q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(N.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(r),i.id===se.id?e.files.forEach(async t=>{await this._insertCellImage(t)}):e.files.forEach(async t=>{await this._insertFloatImage(t)})}}))}async _insertCellImage(i){}async _insertFloatImage(i){let e;try{e=await this._imageIoService.saveImage(i)}catch(D){const y=D.message;y===N.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(N.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===N.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===N.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const r=this._getUnitInfo();if(r==null)return;const{unitId:t,subUnitId:n}=r,{imageId:o,imageSourceType:a,source:s,base64Cache:l}=e,{width:m,height:u,image:c}=await N.getImageSize(l||""),d=this._renderManagerService.getRenderById(t);if(d==null)return;const{width:g,height:S}=d.scene;this._imageIoService.addImageSourceCache(s,a,c);let f=1;if(m>N.DRAWING_IMAGE_WIDTH_LIMIT||u>N.DRAWING_IMAGE_HEIGHT_LIMIT){const D=N.DRAWING_IMAGE_WIDTH_LIMIT/m,y=N.DRAWING_IMAGE_HEIGHT_LIMIT/u;f=Math.max(D,y)}const w=this._getImagePosition(m*f,u*f,g,S);if(w==null)return;const I={unitId:t,subUnitId:n,drawingId:o,drawingType:N.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:s,transform:H(w,this._selectionRenderService,this._sheetSkeletonManagerService),sheetTransform:w};this._commandService.executeCommand(we.id,{unitId:t,drawings:[I]})}_getUnitInfo(){const i=this._univerInstanceService.getCurrentUnitForType(h.UniverInstanceType.UNIVER_SHEET);if(i==null)return;const e=i.getActiveSheet();if(e==null)return;const r=i.getUnitId(),t=e.getSheetId();return{unitId:r,subUnitId:t}}_getImagePosition(i,e,r,t){const n=this._selectionManagerService.getSelections();let o={startRow:0,endRow:0,startColumn:0,endColumn:0};n&&n.length>0&&(o=n[n.length-1].range);const a=this._selectionRenderService.attachRangeWithCoord(o);if(a==null)return;let{startColumn:s,startRow:l,startX:m,startY:u}=a,c=!1;if(m+i>r&&(m=r-i,m<0&&(m=0,i=r),c=!0),u+e>t&&(u=t-e,u<0&&(u=0,e=t),c=!0),c){const f=this._selectionRenderService.getSelectionCellByPosition(m,u);if(f==null)return;m=f.startX,u=f.startY,s=f.actualColumn,l=f.actualRow}const d={column:s,columnOffset:0,row:l,rowOffset:0},g=this._selectionRenderService.getSelectionCellByPosition(m+i,u+e);if(g==null)return;const S={column:g.actualColumn,columnOffset:m+i-g.startX,row:g.actualRow,rowOffset:u+e-g.startY};return{from:d,to:S}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(i=>{const{unitId:e,subUnitId:r,drawingIds:t,arrangeType:n}=i;this._commandService.executeCommand(Ee.id,{unitId:e,subUnitId:r,drawingIds:t,arrangeType:n})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(i=>{const e=[];i.length!==0&&(i.forEach(r=>{const{unitId:t,subUnitId:n,drawingId:o,drawingType:a,transform:s}=r;if(s==null)return;const l=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:n,drawingId:o});if(l==null)return;const m=B({...l.transform,...s},this._selectionRenderService);if(m==null)return;const u={...r,transform:{...l.transform,...s,...H(m,this._selectionRenderService,this._sheetSkeletonManagerService)},sheetTransform:{...m}};e.push(u)}),e.length>0&&this._commandService.executeCommand(ce.id,{unitId:i[0].unitId,drawings:e}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(i=>{this._commandService.executeCommand(be.id,i);const{unitId:e,subUnitId:r,drawingId:t}=i[0].parent;this._drawingManagerService.focusDrawing([{unitId:e,subUnitId:r,drawingId:t}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(i=>{this._commandService.executeCommand(Pe.id,i)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(i=>{i==null||i.length===0?(this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(i))}))}_drawingAddListener(){this.disposeWithMe(this._sheetDrawingService.add$.subscribe(i=>{this._registerDrawing(i)}))}_registerDrawing(i){i.forEach(r=>{const t=this._sheetDrawingService.getDrawingByParam(r);if(t==null)return;const{sheetTransform:n}=t;t.transform=H(n,this._selectionRenderService,this._sheetSkeletonManagerService)});const e=i[0].unitId;this._drawingManagerService.registerDrawingData(e,this._sheetDrawingService.getDrawingDataForUnit(e)),this._drawingManagerService.initializeNotification(e)}};ve=et([h.OnLifecycle(h.LifecycleStages.Rendered,ve),K(1,h.ICommandService),K(2,h.IUniverInstanceService),K(3,W.Inject(v.SelectionManagerService)),K(4,G.ISelectionRenderService),K(5,N.IImageIoService),K(6,p.ISheetDrawingService),K(7,N.IDrawingManagerService),K(8,h.IContextService),K(9,Y.IMessageService),K(10,W.Inject(h.LocaleService)),K(11,$.IRenderManagerService),K(12,W.Inject(G.SheetSkeletonManagerService))],ve);var x=function(){return x=Object.assign||function(i){for(var e,r=1,t=arguments.length;r<t;r++){e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(i[n]=e[n])}return i},x.apply(this,arguments)},tt=function(i,e){var r={};for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&e.indexOf(t)<0&&(r[t]=i[t]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,t=Object.getOwnPropertySymbols(i);n<t.length;n++)e.indexOf(t[n])<0&&Object.prototype.propertyIsEnumerable.call(i,t[n])&&(r[t[n]]=i[t[n]]);return r},We=j.forwardRef(function(i,e){var r=i.icon,t=i.id,n=i.className,o=i.extend,a=tt(i,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(t," ").concat(n||"").trim(),l=j.useRef("_".concat(it()));return $e(r,"".concat(t),{defIds:r.defIds,idSuffix:l.current},x({ref:e,className:s},a),o)});function $e(i,e,r,t,n){return j.createElement(i.tag,x(x({key:e},nt(i,r,n)),t),(rt(i,r).children||[]).map(function(o,a){return $e(o,"".concat(e,"-").concat(i.tag,"-").concat(a),r,void 0,n)}))}function nt(i,e,r){var t=x({},i.attrs);r!=null&&r.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=r.colorChannel1);var n=e.defIds;return!n||n.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(t[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function rt(i,e){var r,t=e.defIds;return!t||t.length===0?i:i.tag==="defs"&&(!((r=i.children)===null||r===void 0)&&r.length)?x(x({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&t&&t.indexOf(n.attrs.id)>-1?x(x({},n),{attrs:x(x({},n.attrs),{id:n.attrs.id+e.idSuffix})}):n})}):i}function it(){return Math.random().toString(36).substring(2,8)}We.displayName="UniverIcon";var ot={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"}}]},Ge=j.forwardRef(function(i,e){return j.createElement(We,Object.assign({},i,{id:"add-image-single",ref:e,icon:ot}))});Ge.displayName="AddImageSingle";const Be={uploadFileMenu:"univer-upload-file-menu",uploadFileMenuInput:"univer-upload-file-menu-input"},Ve="COMPONENT_UPLOAD_FILE_MENU";var _e=(i=>(i[i.cellImage=0]="cellImage",i[i.floatImage=1]="floatImage",i))(_e||{});const at=i=>{const{type:e}=i,r=Z.useDependency(h.ICommandService),t=j.useRef(null),n=()=>{var s;(s=t.current)==null||s.click()},o=N.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(s=>`.${s.replace("image/","")}`).join(","),a=s=>{const l=s.target.files;if(l==null)return;const m=Array.from(l);e===_e.floatImage?r.executeCommand(ae.id,{files:m}):e===_e.cellImage&&r.executeCommand(se.id,{files:m}),t.current&&(t.current.value="")};return j.createElement("div",{onClick:n,className:Be.uploadFileMenu},j.createElement("input",{type:"file",className:Be.uploadFileMenuInput,ref:t,onChange:a,accept:o,multiple:!0}))},Ye="addition-and-subtraction-single",Fe="sheet.menu.image";function st(i){return{id:Fe,type:Y.MenuItemType.SUBITEMS,positions:[Y.MenuPosition.TOOLBAR_START],group:Y.MenuGroup.TOOLBAR_FORMULAS_INSERT,icon:Ye,tooltip:"sheetImage.title",hidden$:Y.getMenuHiddenObservable(i,h.UniverInstanceType.UNIVER_SHEET),disabled$:G.getCurrentRangeDisable$(i,{workbookTypes:[v.WorkbookEditablePermission],worksheetTypes:[v.WorksheetEditPermission],rangeTypes:[v.RangeProtectionPermissionEditPoint]})}}function ct(i){return{id:ae.id,title:"sheetImage.upload.float",type:Y.MenuItemType.SELECTOR,label:{name:Ve,props:{type:_e.floatImage}},positions:[Fe],hidden$:Y.getMenuHiddenObservable(i,h.UniverInstanceType.UNIVER_SHEET)}}const ee={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",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"},lt=i=>{var y;const e=Z.useDependency(h.ICommandService),r=Z.useDependency(h.LocaleService),t=Z.useDependency(N.IDrawingManagerService),n=Z.useDependency($.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:s}=a,l=n.getRenderById(s),m=l==null?void 0:l.scene;if(m==null)return;const u=m.getTransformerByCreate(),[c,d]=j.useState(!0),g=(y=a.anchorType)!=null?y:p.SheetDrawingAnchorType.Position,[S,f]=j.useState(g);function w(R,C){const P=[];return R.forEach(_=>{const{oKey:U}=_,A=C.getDrawingOKey(U);if(A==null)return P.push(null),!0;const{unitId:T,subUnitId:b,drawingId:E,drawingType:M,anchorType:L,sheetTransform:X}=A;P.push({unitId:T,subUnitId:b,drawingId:E,anchorType:L,sheetTransform:X,drawingType:M})}),P}j.useEffect(()=>{const R=u.clearControl$.subscribe(P=>{P===!0&&d(!1)}),C=u.changeStart$.subscribe(P=>{var A;const{objects:_}=P,U=w(_,t);if(U.length===0)d(!1);else if(U.length>=1){d(!0);const T=((A=U[0])==null?void 0:A.anchorType)||p.SheetDrawingAnchorType.Position;f(T)}});return()=>{C.unsubscribe(),R.unsubscribe()}},[]);function I(R){f(R);const C=t.getFocusDrawings();if(C.length===0)return;const P=C.map(_=>({unitId:_.unitId,subUnitId:_.subUnitId,drawingId:_.drawingId,anchorType:R}));e.executeCommand(ce.id,{unitId:C[0].unitId,drawings:P})}const D=R=>R?"block":"none";return j.createElement("div",{className:pe(ee.imageCommonPanelGrid,ee.imageCommonPanelBorder),style:{display:D(c)}},j.createElement("div",{className:ee.imageCommonPanelRow},j.createElement("div",{className:pe(ee.imageCommonPanelColumn,ee.imageCommonPanelTitle)},j.createElement("div",null,r.t("drawing-anchor.title")))),j.createElement("div",{className:pe(ee.imageCommonPanelRow)},j.createElement("div",{className:pe(ee.imageCommonPanelColumn)},j.createElement(Q.RadioGroup,{value:S,onChange:I,direction:"vertical"},j.createElement(Q.Radio,{value:p.SheetDrawingAnchorType.Both},r.t("drawing-anchor.both")),j.createElement(Q.Radio,{value:p.SheetDrawingAnchorType.Position},r.t("drawing-anchor.position")),j.createElement(Q.Radio,{value:p.SheetDrawingAnchorType.None},r.t("drawing-anchor.none"))))))},dt=()=>{const i=Z.useDependency(N.IDrawingManagerService),e=i.getFocusDrawings(),[r,t]=j.useState(e);return j.useEffect(()=>{const n=i.focus$.subscribe(o=>{t(o)});return()=>{n.unsubscribe()}},[]),!!(r!=null&&r.length)&&j.createElement("div",{className:ee.imageCommonPanel},j.createElement(te.DrawingCommonPanel,{drawings:r}),j.createElement(lt,{drawings:r}))},oe={id:"sheet.command.move-drawing",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(p.ISheetDrawingService),n=i.get(G.ISelectionRenderService),{direction:o}=e,a=t.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,l=a.map(u=>{const{transform:c}=u;if(c==null)return null;const d={...c},{left:g=0,top:S=0}=c;return o===h.Direction.UP?d.top=S-1:o===h.Direction.DOWN?d.top=S+1:o===h.Direction.LEFT?d.left=g-1:o===h.Direction.RIGHT&&(d.left=g+1),{...u,transform:d,sheetTransform:B(d,n)}}).filter(u=>u!=null);return r.syncExecuteCommand(ce.id,{unitId:s,drawings:l})?(r.syncExecuteCommand(V.id,[s]),!0):!1}},Ae={id:"sheet.command.delete-drawing",type:h.CommandType.COMMAND,handler:i=>{const e=i.get(h.ICommandService),t=i.get(p.ISheetDrawingService).getFocusDrawings();if(t.length===0)return!1;const n=t[0].unitId,o=t.map(a=>{const{unitId:s,subUnitId:l,drawingId:m,drawingType:u}=a;return{unitId:s,subUnitId:l,drawingId:m,drawingType:u}});return e.executeCommand(he.id,{unitId:n,drawings:o})}};function le(i){return!i.getContextValue(h.FOCUSING_FORMULA_EDITOR)&&!i.getContextValue(h.EDITOR_ACTIVATED)&&i.getContextValue(h.FOCUSING_COMMON_DRAWINGS)}const ut={id:oe.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_DOWN,priority:100,preconditions:le,staticParameters:{direction:h.Direction.DOWN}},mt={id:oe.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_UP,priority:100,preconditions:le,staticParameters:{direction:h.Direction.UP}},gt={id:oe.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_LEFT,priority:100,preconditions:le,staticParameters:{direction:h.Direction.LEFT}},pt={id:oe.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_RIGHT,priority:100,preconditions:le,staticParameters:{direction:h.Direction.RIGHT}},ht={id:Ae.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:le,binding:Y.KeyCode.DELETE,mac:Y.KeyCode.BACKSPACE};var ft=Object.defineProperty,St=Object.getOwnPropertyDescriptor,wt=(i,e,r,t)=>{for(var n=t>1?void 0:t?St(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&ft(e,r,n),n},de=(i,e)=>(r,t)=>e(r,t,i);const vt={};let ue=class extends h.Disposable{constructor(i,e,r,t,n,o){super(),this._config=i,this._injector=e,this._componentManager=r,this._menuService=t,this._commandService=n,this._shortcutService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Ye,Ge)),this.disposeWithMe(i.register(Ve,at)),this.disposeWithMe(i.register(je,dt))}_initMenus(){const{menu:i={}}=this._config;[st,ct].forEach(e=>{this._menuService.addMenuItem(e(this._injector),i)})}_initCommands(){[ae,se,we,he,ce,Te,V,Oe,be,Pe,oe,Ae,Ee].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[ut,mt,gt,pt,ht].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};ue=wt([h.OnLifecycle(h.LifecycleStages.Rendered,ue),de(1,W.Inject(W.Injector)),de(2,W.Inject(Y.ComponentManager)),de(3,Y.IMenuService),de(4,h.ICommandService),de(5,Y.IShortcutService)],ue);var _t=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,It=(i,e,r,t)=>{for(var n=t>1?void 0:t?Ct(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&_t(e,r,n),n},re=(i,e)=>(r,t)=>e(r,t,i);const yt=[v.InsertRowCommand.id,v.InsertColCommand.id,v.RemoveRowCommand.id,v.RemoveColCommand.id,v.DeleteRangeMoveLeftCommand.id,v.DeleteRangeMoveUpCommand.id,v.InsertRangeMoveDownCommand.id,v.InsertRangeMoveRightCommand.id,v.DeltaRowHeightCommand.id,v.SetRowHeightCommand.id,v.DeltaColumnWidthCommand.id,v.SetColWidthCommand.id,v.SetRowHiddenCommand.id,v.SetSpecificRowsVisibleCommand.id,v.SetSpecificColsVisibleCommand.id,v.SetColHiddenCommand.id,v.MoveRangeCommand.id],Mt=[v.SetRowVisibleMutation.id,v.SetRowHiddenMutation.id,v.SetColVisibleMutation.id,v.SetColHiddenMutation.id,v.SetWorksheetRowHeightMutation.id,v.SetWorksheetColWidthMutation.id];let Ce=class extends h.Disposable{constructor(i,e,r,t,n,o,a,s){super(),this._context=i,this._commandService=e,this._sheetInterceptorService=r,this._sheetDrawingService=t,this._drawingManagerService=n,this._selectionRenderService=o,this._univerInstanceService=a,this._sheetSkeletonManagerService=s,this._init()}_init(){this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!yt.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const e=i.id;if(e===v.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if(e===v.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(e===v.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(e===v.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(e===v.MoveRangeCommand.id)return this._moveRangeInterceptor(i.params);if(e===v.DeleteRangeMoveLeftCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,0)}else if(e===v.DeleteRangeMoveUpCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,1)}else if(e===v.InsertRangeMoveDownCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,2)}else if(e===v.InsertRangeMoveRightCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,3)}else if(e===v.SetRowHiddenCommand.id||e===v.SetSpecificRowsVisibleCommand.id){const r=i.params,{unitId:t,subUnitId:n,ranges:o}=r;return this._getDrawingUndoForRowVisible(t,n,o)}else if(e===v.SetSpecificColsVisibleCommand.id||e===v.SetColHiddenCommand.id){const r=i.params,{unitId:t,subUnitId:n,ranges:o}=r;return this._getDrawingUndoForColVisible(t,n,o)}else if(e===v.DeltaRowHeightCommand.id||e===v.SetRowHeightCommand.id||e===v.DeltaColumnWidthCommand.id||e===v.SetColWidthCommand.id){const r=i.params,{unitId:t,subUnitId:n,ranges:o}=r,a=e===v.DeltaRowHeightCommand.id||e===v.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(t,n,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,e){const r=v.getSheetCommandTarget(this._univerInstanceService);if(r==null)return{redos:[],undos:[]};const t=r.unitId,n=r.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(t,n),l=[],m=[];if(Object.keys(s).forEach(u=>{const c=s[u],{updateDrawings:d,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(i,e,c);l.push(...d),m.push(...g)}),l.length===0&&m.length===0)return{redos:[],undos:[]};if(l.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(l),{undo:c,redo:d,objects:g}=u;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:d,objects:g,type:p.DrawingApplyType.UPDATE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:c,objects:g,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(m),c=u.undo,d=u.redo,g=u.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:d,objects:g,type:p.DrawingApplyType.REMOVE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:c,objects:g,type:p.DrawingApplyType.INSERT}})}return o.push({id:V.id,params:[t]}),a.push({id:V.id,params:[t]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,e,r){const t=[],n=[],{sheetTransform:o,anchorType:a=p.SheetDrawingAnchorType.Position,transform:s,unitId:l,subUnitId:m,drawingId:u}=r,{from:c,to:d}=o,{row:g,column:S}=c,{row:f,column:w}=d;if(o==null||s==null)return{updateDrawings:t,deleteDrawings:n};const{startRow:I,endRow:D,startColumn:y,endColumn:R}=i;let C=null,P=null;if(e===0&&g>=I&&f<=D)if(S>=y&&w<=R)n.push({unitId:l,subUnitId:m,drawingId:u});else{const _=this._shrinkCol(o,s,y,R,a);C=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(e===1&&S>=y&&w<=R)if(g>=I&&f<=D)n.push({unitId:l,subUnitId:m,drawingId:u});else{const _=this._shrinkRow(o,s,I,D,a);C=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(e===2){const _=this._expandRow(o,s,I,D,a);C=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(e===3){const _=this._expandCol(o,s,y,R,a);C=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}if(C!=null&&P!=null){const _=H(C,this._selectionRenderService,this._sheetSkeletonManagerService);t.push({...r,sheetTransform:C,transform:_})}return{updateDrawings:t,deleteDrawings:n}}_remainDrawingSize(i,e,r){const t=B({...i},this._selectionRenderService);t!=null&&e.push({...r,sheetTransform:t})}_getDrawingUndoForColVisible(i,e,r){const t=this._drawingManagerService.getDrawingData(i,e),n=[],o=[];if(Object.keys(t).forEach(u=>{const c=t[u],{sheetTransform:d,transform:g,anchorType:S=p.SheetDrawingAnchorType.Position}=c;if(S===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,n,c);else{const{from:f,to:w}=d,{row:I,column:D}=f,{row:y,column:R}=w;for(let C=0;C<r.length;C++){const P=r[C],{startRow:_,endRow:U,startColumn:A,endColumn:T}=P;if(R<A)continue;if(S===p.SheetDrawingAnchorType.Position){let M=null,L=null;if(D>=A&&D<=T){const X=this._selectionRenderService.attachRangeWithCoord({startColumn:D,endColumn:T,startRow:f.row,endRow:w.row});if(X==null)return;L={...g,left:X.startX}}if(L!=null&&(M=B(L,this._selectionRenderService),M!=null&&L!=null)){n.push({...c,sheetTransform:M,transform:L});break}this._remainDrawingSize(g,n,c);continue}if(D>=A&&R<=T)continue;let b=null,E=null;if(D>=A&&D<=T){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:D,endColumn:T,startRow:f.row,endRow:w.row});if(M==null)return;E={...g,left:(M==null?void 0:M.startX)||0,width:((g==null?void 0:g.width)||0)-M.endX+M.startX}}else if(R>=A&&R<=T){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:A,endColumn:R,startRow:f.row,endRow:w.row});if(M==null)return;E={...g,left:M.startX-((g==null?void 0:g.width)||0)}}else{const M=this._selectionRenderService.attachRangeWithCoord({startColumn:A,endColumn:T,startRow:f.row,endRow:w.row});if(M==null)return;if(E={...g,width:((g==null?void 0:g.width)||0)-M.endX+M.startX},b=B(E,this._selectionRenderService),b!=null&&E!=null){o.push({...c,sheetTransform:b,transform:E});break}}if(E!=null&&(b=B(E,this._selectionRenderService)),E!=null&&b!=null){n.push({...c,sheetTransform:b,transform:E});break}else this._remainDrawingSize(g,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,e,n),l=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,e,o);l.push(...u),m.push(...c)}return{redos:a,undos:s,preRedos:l,preUndos:m}}_createUndoAndRedoMutation(i,e,r){const t=this._sheetDrawingService.getBatchUpdateOp(r),{undo:n,redo:o,objects:a}=t,s=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:e,op:o,objects:a,type:p.DrawingApplyType.UPDATE}},{id:V.id,params:[i]}],l=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:e,op:n,objects:a,type:p.DrawingApplyType.UPDATE}},{id:V.id,params:[i]}];return{redos:s,undos:l}}_getDrawingUndoForRowVisible(i,e,r){const t=this._drawingManagerService.getDrawingData(i,e),n=[],o=[];if(Object.keys(t).forEach(u=>{const c=t[u],{sheetTransform:d,transform:g,anchorType:S=p.SheetDrawingAnchorType.Position}=c;if(S===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,n,c);else{const{from:f,to:w}=d,{row:I,column:D}=f,{row:y,column:R}=w;for(let C=0;C<r.length;C++){const P=r[C],{startRow:_,endRow:U,startColumn:A,endColumn:T}=P;if(y<_)continue;if(S===p.SheetDrawingAnchorType.Position){let M=null,L=null;if(I>=_&&I<=U){const X=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:I,endRow:U});if(X==null)return;L={...g,top:X.startY}}if(L!=null&&(M=B(L,this._selectionRenderService),M!=null&&L!=null)){n.push({...c,sheetTransform:M,transform:L});break}this._remainDrawingSize(g,n,c);continue}if(I>=_&&y<=U)continue;let b=null,E=null;if(I>=_&&I<=U){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:I,endRow:U});if(M==null)return;E={...g,top:(M==null?void 0:M.startY)||0,height:((g==null?void 0:g.height)||0)-M.endY+M.startY}}else if(y>=_&&y<=U){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:y});if(M==null)return;E={...g,top:M.startY-((g==null?void 0:g.height)||0)}}else{const M=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:U});if(M==null)return;if(E={...g,height:((g==null?void 0:g.height)||0)-M.endY+M.startY},b=B(E,this._selectionRenderService),b!=null&&E!=null){o.push({...c,sheetTransform:b,transform:E});break}}if(E!=null&&(b=B(E,this._selectionRenderService)),E!=null&&b!=null){n.push({...c,sheetTransform:b,transform:E});break}else this._remainDrawingSize(g,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,e,n),l=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,e,o);l.push(...u),m.push(...c)}return{redos:a,undos:s,preRedos:l,preUndos:m}}_getDrawingUndoForRowAndColSize(i,e,r,t){const n=this._drawingManagerService.getDrawingData(i,e),o=[];return Object.keys(n).forEach(a=>{const s=n[a],{sheetTransform:l,transform:m,anchorType:u=p.SheetDrawingAnchorType.Position}=s;if(u===p.SheetDrawingAnchorType.None)this._remainDrawingSize(m,o,s);else{const{from:c,to:d}=l,{row:g,column:S}=c,{row:f,column:w}=d;for(let I=0;I<r.length;I++){const D=r[I],{startRow:y,endRow:R,startColumn:C,endColumn:P}=D;if(f<y||w<C)continue;if(u===p.SheetDrawingAnchorType.Position&&(g<=y&&f>=R||S<=C&&w>=P)){this._remainDrawingSize(m,o,s);continue}const _=H({...l},this._selectionRenderService,this._sheetSkeletonManagerService);if(_!=null){o.push({...s,transform:_});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,e,o)}_getUnitIdAndSubUnitId(i,e){let r,t;if(e==="insert")r=i.unitId,t=i.subUnitId;else{const n=v.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;r=n.unitId,t=n.subUnitId}return{unitId:r,subUnitId:t}}_moveRowInterceptor(i,e){const r=this._getUnitIdAndSubUnitId(i,e);if(r==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=r,{range:o}=i,a=o.startRow,s=o.endRow,l=[],m=[],u=this._sheetDrawingService.getDrawingData(t,n),c=[],d=[];if(Object.keys(u).forEach(g=>{const S=u[g],{sheetTransform:f,transform:w,anchorType:I=p.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let D,y;if(e==="insert"){const C=this._expandRow(f,w,a,s,I);D=C==null?void 0:C.newSheetTransform,y=C==null?void 0:C.newTransform}else{const{from:C,to:P}=f,{row:_}=C,{row:U}=P;if(I===p.SheetDrawingAnchorType.Both&&_>=a&&U<=s)d.push({unitId:t,subUnitId:n,drawingId:g});else{const A=this._shrinkRow(f,w,a,s,I);D=A==null?void 0:A.newSheetTransform,y=A==null?void 0:A.newTransform}}if(!D||!y)return;const R={unitId:t,subUnitId:n,drawingId:g,transform:y,sheetTransform:D};c.push(R)}),c.length===0&&d.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:S,redo:f,objects:w}=g;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.UPDATE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.UPDATE}})}if(d.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(d),S=g.undo,f=g.redo,w=g.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.REMOVE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.INSERT}})}return l.push({id:V.id,params:[t]}),m.push({id:V.id,params:[t]}),{redos:l,undos:m}}_moveRangeInterceptor(i){const{fromRange:e,toRange:r}=i,t=v.getSheetCommandTarget(this._univerInstanceService);if(!t)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=t,a=this._sheetDrawingService.getDrawingData(n,o),s=[],l=this._selectionRenderService.attachRangeWithCoord(e),m=this._selectionRenderService.attachRangeWithCoord(r);if(!l||!m)return{redos:[],undos:[]};Object.keys(a).forEach(d=>{const g=a[d],{sheetTransform:S,transform:f,anchorType:w=p.SheetDrawingAnchorType.Position}=g;if(!S||!f||w===p.SheetDrawingAnchorType.None)return;const{left:I=0,top:D=0,width:y=0,height:R=0}=f,{drawingStartX:C,drawingEndX:P,drawingStartY:_,drawingEndY:U}={drawingStartX:I,drawingEndX:I+y,drawingStartY:D,drawingEndY:D+R};if(!(l.startX<=C&&P<=l.endX&&l.startY<=U&&_<=l.endY))return;const{to:T,from:b}=S,E=r.startRow-e.startRow,M=r.startColumn-e.startColumn;let L,X;if(w===p.SheetDrawingAnchorType.Both){const z=this._selectionRenderService.attachRangeWithCoord({startRow:T.row,endRow:b.row,startColumn:T.column,endColumn:b.column}),q=this._selectionRenderService.attachRangeWithCoord({startRow:T.row+E,endRow:b.row+E,startColumn:T.column+M,endColumn:b.column+M});if(!q||!z)return;const ge=q.endX-q.startX-(z.endX-z.startX),k=q.endY-q.startY-(z.endY-z.startY);L={to:{...T,row:T.row+E,column:T.column+M,columnOffset:T.columnOffset+ge},from:{...b,row:b.row+E,column:b.column+M,columnOffset:T.columnOffset+ge,rowOffset:T.rowOffset+k}},X=H(L,this._selectionRenderService,this._sheetSkeletonManagerService)}else{const z=m.startX-l.startX,q=m.startY-l.startY;X={...f,left:I+z,top:D+q},L=B(X,this._selectionRenderService)}if(!L||!X)return;const Le={unitId:n,subUnitId:o,drawingId:d,transform:X,sheetTransform:L};s.push(Le)});const u=[],c=[];if(s.length>0){const d=this._sheetDrawingService.getBatchUpdateOp(s),{undo:g,redo:S,objects:f}=d;u.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:S,objects:f,type:p.DrawingApplyType.UPDATE}}),c.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:g,objects:f,type:p.DrawingApplyType.UPDATE}})}return{redos:u,undos:c}}_moveColInterceptor(i,e){const r=this._getUnitIdAndSubUnitId(i,e);if(r==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=r,{range:o}=i,a=o.startColumn,s=o.endColumn,l=[],m=[],u=this._sheetDrawingService.getDrawingData(t,n),c=[],d=[];if(Object.keys(u).forEach(g=>{const S=u[g],{sheetTransform:f,transform:w,anchorType:I=p.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let D,y;if(e==="insert"){const C=this._expandCol(f,w,a,s,I);D=C==null?void 0:C.newSheetTransform,y=C==null?void 0:C.newTransform}else{const{from:C,to:P}=f,{column:_}=C,{column:U}=P;if(_>=a&&U<=s&&I===p.SheetDrawingAnchorType.Both)d.push({unitId:t,subUnitId:n,drawingId:g});else{const T=this._shrinkCol(f,w,a,s,I);D=T==null?void 0:T.newSheetTransform,y=T==null?void 0:T.newTransform}}if(!D||!y)return;const R={unitId:t,subUnitId:n,drawingId:g,transform:y,sheetTransform:D};c.push(R)}),c.length===0&&d.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:S,redo:f,objects:w}=g;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.UPDATE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.UPDATE}})}if(d.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(d),S=g.undo,f=g.redo,w=g.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.REMOVE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.INSERT}})}return l.push({id:V.id,params:[t]}),m.push({id:V.id,params:[t]}),{redos:l,undos:m}}_expandCol(i,e,r,t,n=p.SheetDrawingAnchorType.Position){const o=t-r+1,{from:a,to:s}=i,{column:l}=a,{column:m}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:B({...e},this._selectionRenderService),newTransform:e};let u=null,c=null;if(l>=r){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:r,endColumn:t,startRow:a.row,endRow:s.row});if(d==null)return;c={...e,left:(e.left||0)+d.endX-d.startX},u=B(c,this._selectionRenderService)}else if(m>=t)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m+o}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService);else return{newSheetTransform:B({...e},this._selectionRenderService),newTransform:e};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(i,e,r,t,n=p.SheetDrawingAnchorType.Position){const o=t-r+1,{from:a,to:s}=i,{column:l}=a,{column:m}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:B({...e},this._selectionRenderService),newTransform:e};let u=null,c=null;if(l>t){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:r,endColumn:t,startRow:a.row,endRow:s.row});if(d==null)return;c={...e,left:(e.left||0)-(d.endX-d.startX)},u=B(c,this._selectionRenderService)}else if(l>=r&&m<=t){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:r,endColumn:t,startRow:0,endRow:0});u={from:{...a,columnOffset:0},to:{...s,columnOffset:s.columnOffset-a.columnOffset}},c={...e,left:d==null?void 0:d.startX}}else if(l<r&&m>t)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m-o}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService);else return{newSheetTransform:B({...e},this._selectionRenderService),newTransform:e};else if(l>=r&&l<=t){if(l===r)c={...e,left:(e.left||0)-i.from.columnOffset};else{const d=this._selectionRenderService.attachRangeWithCoord({startColumn:r,endColumn:l-1,startRow:a.row,endRow:s.row});if(d==null)return;c={...e,left:(e.left||0)-d.endX+d.startX-i.from.columnOffset}}u=B(c,this._selectionRenderService)}else if(m>=r&&m<=t&&n===p.SheetDrawingAnchorType.Both){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:r-1,endColumn:r-1,startRow:a.row,endRow:s.row});if(d==null)return;u={from:{...a},to:{...s,column:r-1,columnOffset:d.endX-d.startX}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService)}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(i,e,r,t,n=p.SheetDrawingAnchorType.Position){const o=t-r+1,{from:a,to:s}=i,{row:l}=a,{row:m}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:B({...e},this._selectionRenderService),newTransform:e};let u=null,c=null;if(l>=r){const d=this._selectionRenderService.attachRangeWithCoord({startRow:r,endRow:t,startColumn:a.column,endColumn:s.column});if(d==null)return;c={...e,top:(e.top||0)+d.endY-d.startY},u=B(c,this._selectionRenderService)}else if(m>=t)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m+o}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService);else return{newSheetTransform:B({...e},this._selectionRenderService),newTransform:e};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(i,e,r,t,n=p.SheetDrawingAnchorType.Position){const o=t-r+1,{from:a,to:s}=i,{row:l}=a,{row:m}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:B({...e},this._selectionRenderService),newTransform:e};let u=null,c=null;if(l>t)u={from:{...a,row:l-o},to:{...s,row:m-o}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService);else if(l>=r&&m<=t){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:0,endColumn:0,startRow:r,endRow:t});u={from:{...a,rowOffset:0},to:{...s,rowOffset:s.rowOffset-a.rowOffset}},c={...e,top:d==null?void 0:d.startY}}else if(l<r&&m>t)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m-o}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService);else return{newSheetTransform:B({...e},this._selectionRenderService),newTransform:e};else if(l>=r&&l<=t){if(l===r)c={...e,top:(e.top||0)-i.from.rowOffset};else{const d=this._selectionRenderService.attachRangeWithCoord({startRow:r,endRow:l-1,startColumn:a.column,endColumn:s.column});if(d==null)return;c={...e,top:(e.top||0)-d.endY+d.startY-i.from.rowOffset}}u=B(c,this._selectionRenderService)}else if(m>=r&&m<=t&&n===p.SheetDrawingAnchorType.Both){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:r-1,endRow:r-1});if(d==null)return;u={from:{...a},to:{...s,row:r-1,rowOffset:d.endY-d.startY}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService)}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===v.SetWorksheetActiveOperation.id&&setTimeout(()=>{const e=i.params,{unitId:r,subUnitId:t}=e,n=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(n).forEach(s=>{const l=n[s];Object.keys(l).forEach(m=>{const u=l[m].data;u!=null&&Object.keys(u).forEach(c=>{if(s===r&&m===t){const d=u[c];d.transform=H(d.sheetTransform,this._selectionRenderService,this._sheetSkeletonManagerService),o.push(u[c])}else a.push(u[c])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Mt.includes(i.id)&&requestIdleCallback(()=>{const e=i.params,{unitId:r,subUnitId:t,ranges:n}=e;this._refreshDrawingTransform(r,t,n)})}))}_refreshDrawingTransform(i,e,r){const t=this._drawingManagerService.getDrawingData(i,e),n=[];Object.keys(t).forEach(o=>{const a=t[o],{sheetTransform:s,anchorType:l=p.SheetDrawingAnchorType.Position}=a;if(l===p.SheetDrawingAnchorType.None)return!0;const{from:m,to:u}=s,{row:c,column:d}=m,{row:g,column:S}=u;for(let f=0;f<r.length;f++){const w=r[f],{startRow:I,endRow:D,startColumn:y,endColumn:R}=w;if(h.Rectangle.intersects({startRow:I,endRow:D,startColumn:y,endColumn:R},{startRow:c,endRow:g,startColumn:d,endColumn:S})||c>D||d>R){n.push({...a,transform:H(s,this._selectionRenderService,this._sheetSkeletonManagerService)});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(V.id,[i]))}};Ce=It([h.OnLifecycle(h.LifecycleStages.Rendered,Ce),re(1,h.ICommandService),re(2,W.Inject(v.SheetInterceptorService)),re(3,p.ISheetDrawingService),re(4,N.IDrawingManagerService),re(5,G.ISelectionRenderService),re(6,h.IUniverInstanceService),re(7,W.Inject(G.SheetSkeletonManagerService))],Ce);var Dt=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,Tt=(i,e,r,t)=>{for(var n=t>1?void 0:t?Rt(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Dt(e,r,n),n},ie=(i,e)=>(r,t)=>e(r,t,i);function Ot(i,e,r,t){const{scaleX:n,scaleY:o}=e.getAncestorScale(),a=e.getViewport($.SHEET_VIEWPORT_KEY.VIEW_MAIN),s={left:!0,top:!0};if(!a)return{...i,absolute:s};const{left:l,right:m,top:u,bottom:c}=i,d=t.getFreeze(),{startColumn:g,startRow:S,xSplit:f,ySplit:w}=d,I=r.getNoMergeCellPositionByIndexWithNoHeader(S-w,g-f),D=r.getNoMergeCellPositionByIndexWithNoHeader(S,g),{rowHeaderWidth:y,columnHeaderHeight:R}=r,C=D.startX-I.startX,P=D.startY-I.startY,{top:_,left:U,viewportScrollX:A,viewportScrollY:T}=a;let b,E;l<U?(s.left=!0,b=(C+y+(l-U))*n,E=Math.max(Math.min((C+y+(m-U))*n,(C+y)*n),(m-A)*n)):(s.left=!1,b=Math.max((l-A)*n,(C+y)*n),E=Math.max((m-A)*n,(C+y)*n));let M,L;return u<_?(s.top=!0,M=(P+R+(u-_))*o,L=Math.max(Math.min((P+R+(m-_))*o,(P+R)*o),(c-T)*o)):(s.top=!1,M=Math.max((u-T)*o,(P+R)*o),L=Math.max((c-T)*o,(P+R)*o)),{left:b,right:E,top:M,bottom:L,absolute:s}}const Ue=(i,e,r,t)=>{const{scene:n}=e,{left:o,top:a,width:s,height:l,angle:m}=i,u={left:o,right:o+s,top:a,bottom:a+l},c=Ot(u,n,r,t);return{startX:c.left,endX:c.right,startY:c.top,endY:c.bottom,rotate:m,width:s,height:l,absolute:c.absolute}};O.SheetCanvasFloatDomManagerService=class extends h.Disposable{constructor(r,t,n,o,a,s,l){super();J(this,"_domLayerMap",new Map);J(this,"_domLayerInfoMap",new Map);J(this,"_transformChange$",new F.Subject);J(this,"transformChange$",this._transformChange$.asObservable());J(this,"_remove$",new F.Subject);J(this,"remove$",this._remove$.asObservable());this._renderManagerService=r,this._univerInstanceService=t,this._commandService=n,this._drawingManagerService=o,this._selectionRenderService=a,this._canvasFloatDomService=s,this._sheetDrawingService=l,this._drawingAddListener(),this._scrollUpdateListener(),this._featureUpdateListener(),this._deleteListener()}_ensureMap(r,t){let n=this._domLayerMap.get(r);n||(n=new Map,this._domLayerMap.set(r,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}_getSceneAndTransformerByDrawingSearch(r){if(r==null)return;const t=this._renderManagerService.getRenderById(r),n=t==null?void 0:t.scene;if(t==null||n==null)return null;const o=n.getTransformerByCreate(),a=t.engine.getCanvasElement();return{scene:n,transformer:o,renderObject:t,canvas:a}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(r=>{r.forEach(t=>{var q,ge;const{unitId:n,subUnitId:o,drawingId:a}=t,s=v.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),l=this._drawingManagerService.getDrawingByParam(t),m=(q=this._renderManagerService.getRenderById(n))==null?void 0:q.with(G.SheetSkeletonManagerService).getUnitSkeleton(n,o);if(l==null||s==null||m==null)return;const{transform:u,drawingType:c}=l;if(c!==h.DrawingTypeEnum.DRAWING_DOM)return;const d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{scene:g,canvas:S}=d;if(u==null)return!0;const{left:f,top:w,width:I,height:D,angle:y,flipX:R,flipY:C,skewX:P,skewY:_}=u,U=N.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),A=g.getObject(U);if(A!=null){A.transformByState({left:f,top:w,width:I,height:D,angle:y,flipX:R,flipY:C,skewX:P,skewY:_});return}const T={left:f,top:w,width:I,height:D,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},b=new $.Rect(U,T);g.addObject(b,$.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(b);const E=this._ensureMap(n,o),M=new h.DisposableCollection,L=Ue(b,d.renderObject,m.skeleton,s.worksheet),X=new F.BehaviorSubject(L),Le={dispose:M,rect:b,position$:X,unitId:n,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:X,id:a,componentKey:l.componentKey,onPointerDown:k=>{S.dispatchEvent(new PointerEvent(k.type,k))},onPointerMove:k=>{S.dispatchEvent(new PointerEvent(k.type,k))},onPointerUp:k=>{S.dispatchEvent(new PointerEvent(k.type,k))},onWheel:k=>{S.dispatchEvent(new WheelEvent(k.type,k))},props:(ge=E.get(a))==null?void 0:ge.props});const z=b.onTransformChange$.subscribeEvent(()=>{const k=Ue(b,d.renderObject,m.skeleton,s.worksheet);X.next(k)});M.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),z&&M.add(z),this._domLayerInfoMap.set(a,Le)})}))}_scrollUpdateListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{var n,o;const t=(a,s)=>{var g;const l=this._getSceneAndTransformerByDrawingSearch(a),m=this._ensureMap(a,s),u=Array.from(m.keys()),c=v.getSheetCommandTarget(this._univerInstanceService,{unitId:a,subUnitId:s}),d=(g=this._renderManagerService.getRenderById(a))==null?void 0:g.with(G.SheetSkeletonManagerService).getUnitSkeleton(a,s);!l||!c||!d||u.forEach(S=>{const f=this._domLayerInfoMap.get(S);if(f){const w=Ue(f.rect,l.renderObject,d.skeleton,c.worksheet);f.position$.next(w)}})};if(r.id===G.SetScrollOperation.id){const a=r.params,{unitId:s,sheetId:l}=a;t(s,l)}else if(r.id===G.SetZoomRatioOperation.id){const a=r.params,{unitId:s}=a;Array.from((o=(n=this._domLayerMap.get(s))==null?void 0:n.keys())!=null?o:[]).forEach(m=>{t(s,m)})}else if(r.id===v.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=r.params;t(a,s)}}))}_getPosition(r){const{startX:t,endX:n,startY:o,endY:a}=r,s=this._selectionRenderService.getSelectionCellByPosition(t,o);if(s==null)return;const l={column:s.actualColumn,columnOffset:t-s.startX,row:s.actualRow,rowOffset:o-s.startY},m=this._selectionRenderService.getSelectionCellByPosition(n,a);if(m==null)return;const u={column:m.actualColumn,columnOffset:n-m.startX,row:m.actualRow,rowOffset:a-m.startY};return{from:l,to:u}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(r=>{r.forEach(t=>{const n=this._drawingManagerService.getDrawingByParam(t);if(!n||n.drawingType!==h.DrawingTypeEnum.DRAWING_DOM)return;const o={...n.transform};this._transformChange$.next({id:t.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(r=>{r.forEach(t=>{this._removeDom(t.drawingId)})}))}addFloatDomToPosition(r){const t=v.getSheetCommandTarget(this._univerInstanceService,{unitId:r.unitId,subUnitId:r.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:n,subUnitId:o}=t,{initPosition:a,componentKey:s}=r,l=h.Tools.generateRandomId(),m=this._getPosition(a);if(m==null)return;this._ensureMap(n,o).set(l,r);const c={unitId:n,subUnitId:o,drawingId:l,drawingType:h.DrawingTypeEnum.DRAWING_DOM,componentKey:s,sheetTransform:m,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY}};return this._commandService.executeCommand(we.id,{unitId:n,drawings:[c]}),{id:l,dispose:()=>{this._removeDom(l,!0)}}}_removeDom(r,t=!1){const n=this._domLayerInfoMap.get(r);if(!n)return;const{unitId:o,subUnitId:a}=n;this._domLayerInfoMap.delete(r),n.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(n.rect),t){this._ensureMap(o,a).delete(r);const m=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:r});if(!m)return;const u=this._sheetDrawingService.getBatchRemoveOp([m]),{redo:c,objects:d}=u;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:c,objects:d,type:p.DrawingApplyType.REMOVE})}}},O.SheetCanvasFloatDomManagerService=Tt([ie(0,W.Inject($.IRenderManagerService)),ie(1,h.IUniverInstanceService),ie(2,W.Inject(h.ICommandService)),ie(3,N.IDrawingManagerService),ie(4,G.ISelectionRenderService),ie(5,W.Inject(Y.CanvasFloatDomService)),ie(6,p.ISheetDrawingService)],O.SheetCanvasFloatDomManagerService);var Et=Object.defineProperty,bt=Object.getOwnPropertyDescriptor,Pt=(i,e,r,t)=>{for(var n=t>1?void 0:t?bt(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Et(e,r,n),n},Ie=(i,e)=>(r,t)=>e(r,t,i);let ye=class extends h.Disposable{constructor(i,e,r,t){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=e,this._drawingManagerService=r,this._renderManagerService=t,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,e,r)=>{const{unitId:t,scene:n,subUnitId:o}=e,a=this._drawingManagerService.getDrawingDataForUnit(t),s=a==null?void 0:a[o];return s&&s.order.forEach(l=>{this._drawingRenderService.renderDrawing(s.data[l],n)}),r()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,e,r)=>{const{unitId:t,subUnitId:n}=e,o=this._renderManagerService.getRenderById(t);if(!o)return r(i);const a=o.with(G.SheetSkeletonManagerService).getUnitSkeleton(t,n);if(!a)return r(i);const s=this._drawingManagerService.getDrawingDataForUnit(t),l=s==null?void 0:s[e.subUnitId];if(!l)return r(i);const{scaleX:m,scaleY:u}=o.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},d=l.order.map(g=>l.data[g]).filter(g=>g.drawingType!==N.DrawingTypeEnum.DRAWING_DOM);return d.length?(d.forEach(g=>{if(!g.groupId&&g.transform&&h.Tools.isDefine(g.transform.left)&&h.Tools.isDefine(g.transform.top)&&h.Tools.isDefine(g.transform.width)&&h.Tools.isDefine(g.transform.height)){const S=a.skeleton.getCellPositionByOffset(g.transform.left,g.transform.top,m,u,{x:0,y:0}),f=a.skeleton.getCellPositionByOffset(g.transform.left+g.transform.width,g.transform.top+g.transform.height,m,u,{x:0,y:0});S.column<c.startColumn&&(c.startColumn=S.column),S.row<c.startRow&&(c.startRow=S.row),c.endRow<f.row&&(c.endRow=f.row),c.endColumn<f.column&&(c.endColumn=f.column)}}),r(c)):r(i)}}))}};ye=Pt([h.OnLifecycle(h.LifecycleStages.Rendered,ye),Ie(0,W.Inject(G.SheetPrintInterceptorService)),Ie(1,W.Inject(te.DrawingRenderService)),Ie(2,N.IDrawingManagerService),Ie(3,$.IRenderManagerService)],ye);var At=Object.defineProperty,Ut=Object.getOwnPropertyDescriptor,Nt=(i,e,r,t)=>{for(var n=t>1?void 0:t?Ut(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&At(e,r,n),n},me=(i,e)=>(r,t)=>e(r,t,i);let Me=class extends h.Disposable{constructor(i,e,r,t,n){super(),this._drawingManagerService=i,this._renderManagerService=e,this._permissionService=r,this._univerInstanceService=t,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(F.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([e,r])=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}e.activeSheet$.subscribe(t=>{if(!t){this._drawingManagerService.setDrawingVisible(!1);return}const n=e.getUnitId(),o=t.getSheetId();if(this._permissionService.composePermission([new v.WorkbookViewPermission(n).id,new v.WorksheetViewPermission(n,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const s=e.getUnitId(),l=t.getSheetId(),m=this._drawingManagerService.getDrawingData(s,l),u=Object.values(m),c=this._renderManagerService.getRenderById(s),d=c==null?void 0:c.scene;if(d==null)return;d.getAllObjects().forEach(S=>{S.classType===$.RENDER_CLASS_TYPE.IMAGE&&u.some(f=>S.oKey.includes(f.drawingId))&&d.removeObject(S)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(F.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([e,r])=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}e.activeSheet$.subscribe(t=>{if(!t){this._drawingManagerService.setDrawingEditable(!1);return}const n=e.getUnitId(),o=t.getSheetId();if(this._permissionService.composePermission([new v.WorkbookEditablePermission(n).id,new v.WorksheetEditPermission(n,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const s=e.getUnitId(),l=t.getSheetId(),m=this._drawingManagerService.getDrawingData(s,l),u=Object.values(m),c=this._renderManagerService.getRenderById(s),d=c==null?void 0:c.scene;if(d==null)return;d.getAllObjects().forEach(S=>{S.classType===$.RENDER_CLASS_TYPE.IMAGE&&u.some(f=>S.oKey.includes(f.drawingId))&&d.detachTransformerFrom(S)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(F.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([e,r])=>{e&&e.activeSheet$.subscribe(t=>{var c;if(!t)return;const n=e.getUnitId(),o=t.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(n),l=s==null?void 0:s.scene;if(l==null)return;const m=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookViewPermission(n).id,new v.WorksheetViewPermission(n,o).id]).pipe(F.map(d=>d.every(g=>g.value)));u==null||u.pipe(F.filter(d=>d!==a),F.distinctUntilChanged()).subscribe({next:d=>{a=d,this._drawingManagerService.setDrawingVisible(d);const g=l.getAllObjects(),S=this._drawingManagerService.getDrawingData(n,o),f=Object.values(S);d?this._drawingManagerService.addNotification(f):(g.forEach(w=>{w.classType===$.RENDER_CLASS_TYPE.IMAGE&&f.some(I=>w.oKey.includes(I.drawingId))&&l.removeObject(w)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new v.WorksheetViewPermission(n,o).id))==null||c.pipe(F.filter(d=>d.value!==a),F.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const d=this._drawingManagerService.getDrawingData(n,o),g=Object.values(d);this._drawingManagerService.addNotification(g)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(F.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([e,r])=>{e&&e.activeSheet$.subscribe(t=>{var c;if(!t)return;const n=e.getUnitId(),o=t.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(n),l=s==null?void 0:s.scene;if(l==null)return;const m=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookEditablePermission(n).id,new v.WorksheetEditPermission(n,o).id]).pipe(F.map(d=>d.every(g=>g.value)));u==null||u.pipe(F.filter(d=>d!==a),F.distinctUntilChanged()).subscribe({next:d=>{a=d,this._drawingManagerService.setDrawingEditable(d);const g=l.getAllObjects(),S=this._drawingManagerService.getDrawingData(n,o),f=Object.values(S);d?(g.forEach(w=>{w.classType===$.RENDER_CLASS_TYPE.IMAGE&&f.some(I=>w.oKey.includes(I.drawingId))&&l.attachTransformerTo(w)}),this._drawingManagerService.addNotification(f)):(g.forEach(w=>{w.classType===$.RENDER_CLASS_TYPE.IMAGE&&f.some(I=>w.oKey.includes(I.drawingId))&&l.detachTransformerFrom(w)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new v.WorksheetEditPermission(n,o).id))==null||c.pipe(F.filter(d=>d.value!==a),F.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const d=e.getUnitId(),g=t.getSheetId(),S=this._drawingManagerService.getDrawingData(d,g),f=Object.values(S),w=this._renderManagerService.getRenderById(d),I=w==null?void 0:w.scene;if(I==null)return;this._drawingManagerService.setDrawingEditable(!0),I.getAllObjects().forEach(y=>{y.classType===$.RENDER_CLASS_TYPE.IMAGE&&f.some(R=>y.oKey.includes(R.drawingId))&&I.detachTransformerFrom(y)})}})})}))}};Me=Nt([h.OnLifecycle(h.LifecycleStages.Rendered,Me),me(0,N.IDrawingManagerService),me(1,$.IRenderManagerService),me(2,h.IPermissionService),me(3,h.IUniverInstanceService),me(4,W.Inject(h.UserManagerService))],Me);var Lt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,Wt=(i,e,r,t)=>{for(var n=t>1?void 0:t?jt(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Lt(e,r,n),n},De=(i,e)=>(r,t)=>e(r,t,i);let Re=class extends h.Disposable{constructor(e,r,t,n){super();J(this,"_copyInfo");this._sheetClipboardService=e,this._selectionRenderService=r,this._sheetDrawingService=t,this._injector=n,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(e,r,t)=>this._collect(e,r,t),onPasteCells:(e,r,t,n)=>{const{copyType:o=G.COPY_TYPE.COPY,pasteType:a}=n,{range:s}=e||{},{range:l,unitId:m,subUnitId:u}=r;return this._generateMutations(l,{copyType:o,pasteType:a,copyRange:s,unitId:m,subUnitId:u})},onPastePlainText:(e,r)=>({undos:[],redos:[]})})}_collect(e,r,t){const n=this._selectionRenderService.attachRangeWithCoord(t);if(!n)return;const{startX:o,endX:a,startY:s,endY:l}=n,m=this._sheetDrawingService.getDrawingData(e,r),u=[];Object.keys(m).forEach(c=>{const d=m[c],{transform:g}=d;if(d.anchorType!==p.SheetDrawingAnchorType.Both||!g)return;const{left:S=0,top:f=0,width:w=0,height:I=0}=g,{drawingStartX:D,drawingEndX:y,drawingStartY:R,drawingEndY:C}={drawingStartX:S,drawingEndX:S+w,drawingStartY:f,drawingEndY:f+I};o<=D&&y<=a&&s<=R&&C<=l&&u.push(d)}),u.length&&(this._copyInfo={drawings:u,unitId:e,subUnitId:r})}_generateMutations(e,r){if(!this._copyInfo)return{redos:[],undos:[]};if([G.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,G.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,G.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,G.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(r.pasteType))return{redos:[],undos:[]};const{copyRange:t}=r;if(!t)return{redos:[],undos:[]};const{drawings:n,unitId:o,subUnitId:a}=this._copyInfo,{ranges:[s,l],mapFunc:m}=G.virtualizeDiscreteRanges([t,e]),{row:u,col:c}=m(s.startRow,s.startColumn),{row:d,col:g}=m(l.startRow,l.startColumn),S=this._selectionRenderService.attachRangeWithCoord({startRow:u,endRow:u,startColumn:c,endColumn:c}),f=this._selectionRenderService.attachRangeWithCoord({startRow:d,endRow:d,startColumn:g,endColumn:g});if(!S||!f)return{redos:[],undos:[]};const w=[],I=[],D=f.startX-S.startX,y=f.startY-S.startY,R=d-u,C=g-c,P=r.copyType===G.COPY_TYPE.CUT,{_sheetDrawingService:_}=this;return n.forEach(U=>{const{transform:A,sheetTransform:T}=U;if(!A)return;const b={...U,unitId:o,subUnitId:a,drawingId:P?U.drawingId:h.Tools.generateRandomId(),transform:{...A,left:A.left+D,top:A.top+y},sheetTransform:{to:{...T.to,row:T.to.row+R,column:T.to.column+C},from:{...T.from,row:T.from.row+R,column:T.from.column+C}}};if(P){const{undo:E,redo:M,objects:L}=_.getBatchUpdateOp([b]);w.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:M,objects:L}}),I.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:E,objects:L}})}else{const{undo:E,redo:M,objects:L}=_.getBatchAddOp([b]);w.push({id:p.SetDrawingApplyMutation.id,params:{op:M,unitId:o,subUnitId:a,objects:L,type:p.DrawingApplyType.INSERT}}),I.push({id:p.SetDrawingApplyMutation.id,params:{op:E,unitId:o,subUnitId:a,objects:L,type:p.DrawingApplyType.REMOVE}})}}),{redos:w,undos:I}}};Re=Wt([h.OnLifecycle(h.LifecycleStages.Ready,Re),De(0,G.ISheetClipboardService),De(1,G.ISelectionRenderService),De(2,p.ISheetDrawingService),De(3,W.Inject(W.Injector))],Re);var Xe=Object.defineProperty,$t=Object.getOwnPropertyDescriptor,Gt=(i,e,r)=>e in i?Xe(i,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[e]=r,Bt=(i,e,r,t)=>{for(var n=t>1?void 0:t?$t(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Xe(e,r,n),n},Ne=(i,e)=>(r,t)=>e(r,t,i),He=(i,e,r)=>Gt(i,typeof e!="symbol"?e+"":e,r);const Vt="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends h.Plugin{constructor(r={},t,n,o){super();J(this,"_pluginConfig");this._injector=t,this._localeService=n,this._renderManagerService=o,this._pluginConfig=h.Tools.deepMerge({},vt,r)}onStarting(r){super.onStarting(r),this._initDependencies(r)}_initDependencies(r){const t=[[O.SheetCanvasFloatDomManagerService],[ue,{useFactory:()=>this._injector.createInstance(ue,this._pluginConfig)}],[Se],[ye],[Me],[Re]],n=[ve,Ce];t.forEach(o=>r.add(o)),n.forEach(o=>this._renderManagerService.registerRenderModule(h.UniverInstanceType.UNIVER_SHEET,o))}},He(O.UniverSheetsDrawingUIPlugin,"type",h.UniverInstanceType.UNIVER_SHEET),He(O.UniverSheetsDrawingUIPlugin,"pluginName",Vt),O.UniverSheetsDrawingUIPlugin=Bt([h.DependentOn(N.UniverDrawingPlugin,te.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),Ne(1,W.Inject(W.Injector)),Ne(2,W.Inject(h.LocaleService)),Ne(3,$.IRenderManagerService)],O.UniverSheetsDrawingUIPlugin),O.ClearSheetDrawingTransformerOperation=V,O.DeleteDrawingsCommand=Ae,O.EditSheetDrawingOperation=Oe,O.GroupSheetDrawingCommand=be,O.InsertCellImageOperation=se,O.InsertFloatImageOperation=ae,O.InsertSheetDrawingCommand=we,O.MoveDrawingsCommand=oe,O.RemoveSheetDrawingCommand=he,O.SetDrawingArrangeCommand=Ee,O.SetSheetDrawingCommand=ce,O.SidebarSheetDrawingOperation=Te,O.UngroupSheetDrawingCommand=Pe,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-drawing-ui",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -52,15 +52,15 @@
52
52
  "clsx": ">=2.0.0",
53
53
  "react": "^16.9.0 || ^17.0.0 || ^18.0.0",
54
54
  "rxjs": ">=7.0.0",
55
- "@univerjs/core": "0.2.0",
56
- "@univerjs/design": "0.2.0",
57
- "@univerjs/drawing": "0.2.0",
58
- "@univerjs/drawing-ui": "0.2.0",
59
- "@univerjs/engine-render": "0.2.0",
60
- "@univerjs/sheets": "0.2.0",
61
- "@univerjs/sheets-drawing": "0.2.0",
62
- "@univerjs/sheets-ui": "0.2.0",
63
- "@univerjs/ui": "0.2.0"
55
+ "@univerjs/core": "0.2.1",
56
+ "@univerjs/design": "0.2.1",
57
+ "@univerjs/drawing": "0.2.1",
58
+ "@univerjs/drawing-ui": "0.2.1",
59
+ "@univerjs/engine-render": "0.2.1",
60
+ "@univerjs/sheets": "0.2.1",
61
+ "@univerjs/sheets-drawing": "0.2.1",
62
+ "@univerjs/sheets-ui": "0.2.1",
63
+ "@univerjs/ui": "0.2.1"
64
64
  },
65
65
  "dependencies": {
66
66
  "@univerjs/icons": "^0.1.58"
@@ -74,16 +74,16 @@
74
74
  "typescript": "^5.5.3",
75
75
  "vite": "^5.3.3",
76
76
  "vitest": "^1.6.0",
77
- "@univerjs/core": "0.2.0",
78
- "@univerjs/drawing": "0.2.0",
79
- "@univerjs/drawing-ui": "0.2.0",
80
- "@univerjs/design": "0.2.0",
81
- "@univerjs/engine-render": "0.2.0",
82
- "@univerjs/shared": "0.2.0",
83
- "@univerjs/sheets": "0.2.0",
84
- "@univerjs/sheets-drawing": "0.2.0",
85
- "@univerjs/sheets-ui": "0.2.0",
86
- "@univerjs/ui": "0.2.0"
77
+ "@univerjs/core": "0.2.1",
78
+ "@univerjs/design": "0.2.1",
79
+ "@univerjs/drawing": "0.2.1",
80
+ "@univerjs/shared": "0.2.1",
81
+ "@univerjs/drawing-ui": "0.2.1",
82
+ "@univerjs/sheets": "0.2.1",
83
+ "@univerjs/engine-render": "0.2.1",
84
+ "@univerjs/sheets-drawing": "0.2.1",
85
+ "@univerjs/sheets-ui": "0.2.1",
86
+ "@univerjs/ui": "0.2.1"
87
87
  },
88
88
  "univerSpace": {
89
89
  ".": {