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