@univerjs/sheets-drawing-ui 0.6.0-nightly.202502061605 → 0.6.0-nightly.202502081605

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