@univerjs/preset-sheets-drawing 0.15.4 → 0.15.5

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.
Files changed (2) hide show
  1. package/lib/umd/index.js +3 -3
  2. package/package.json +8 -8
package/lib/umd/index.js CHANGED
@@ -11,12 +11,12 @@
11
11
 
12
12
 
13
13
  // @univerjs/sheets-drawing-ui/index
14
- (function(M,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("@univerjs/core"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets"),require("@univerjs/design"),require("@univerjs/docs-ui"),require("@univerjs/drawing"),require("@univerjs/ui"),require("@univerjs/docs-drawing"),require("@univerjs/drawing-ui"),require("rxjs"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/engine-render","@univerjs/sheets-ui","@univerjs/core","@univerjs/sheets-drawing","@univerjs/sheets","@univerjs/design","@univerjs/docs-ui","@univerjs/drawing","@univerjs/ui","@univerjs/docs-drawing","@univerjs/drawing-ui","rxjs","react/jsx-runtime","react"],A):(M=typeof globalThis<"u"?globalThis:M||self,A(M.UniverSheetsDrawingUi={},M.UniverEngineRender,M.UniverSheetsUi,M.UniverCore,M.UniverSheetsDrawing,M.UniverSheets,M.UniverDesign,M.UniverDocsUi,M.UniverDrawing,M.UniverUi,M.UniverDocsDrawing,M.UniverDrawingUi,M.rxjs,M.React,M.React))})(this,(function(M,A,b,l,w,C,Y,Fe,B,j,bt,ge,U,L,q){"use strict";var rr=Object.defineProperty;var ir=(M,A,b)=>A in M?rr(M,A,{enumerable:!0,configurable:!0,writable:!0,value:b}):M[A]=b;var ie=(M,A,b)=>ir(M,typeof A!="symbol"?A+"":A,b);function J(i,r,e){const{from:t,to:n,flipY:o=!1,flipX:s=!1,angle:a=0,skewX:d=0,skewY:g=0}=i,u=e.getCurrent();if(u==null)return;const c=b.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:t,to:n},e);let{left:m,top:h,width:p,height:S}=c;const f=e.getCurrentSkeleton(),v=f.rowHeaderWidth+f.columnTotalWidth,_=f.columnHeaderHeight+f.rowTotalHeight;return m+p>v&&(m=v-p),h+S>_&&(h=_-S),{flipY:o,flipX:s,angle:a,skewX:d,skewY:g,left:m,top:h,width:p,height:S}}function H(i,r){const{left:e=0,top:t=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(e,t);if(c==null)return;const m={column:c.actualColumn,columnOffset:A.precisionTo(e-c.startX,1),row:c.actualRow,rowOffset:A.precisionTo(t-c.startY,1)},h=r.getCellWithCoordByOffset(e+n,t+o);if(h==null)return;const p={column:h.actualColumn,columnOffset:A.precisionTo(e+n-h.startX,1),row:h.actualRow,rowOffset:A.precisionTo(t+o-h.startY,1)};return{flipY:s,flipX:a,angle:d,skewX:g,skewY:u,from:m,to:p}}const V={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(i,r)=>{const e=i.get(A.IRenderManagerService);return r.forEach(t=>{var n,o;(o=(n=e.getRenderById(t))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},fe={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var _,D,R;const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(C.SheetInterceptorService),o=i.get(w.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,a=[];s.forEach(y=>{const{unitId:T}=y;a.push(T)});const d=o.getBatchRemoveOp(s),{unitId:g,subUnitId:u,undo:c,redo:m,objects:h}=d,p=n.onCommandExecute({id:fe.id,params:r}),S={id:w.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:m,objects:h,type:w.DrawingApplyType.REMOVE}},f={id:w.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:c,objects:h,type:w.DrawingApplyType.INSERT}};return l.sequenceExecute([...(_=p.preRedos)!=null?_:[],S,...p.redos],e)?(t.pushUndoRedo({unitID:g,undoMutations:[...(D=p.preUndos)!=null?D:[],f,...p.undos,{id:V.id,params:a}],redoMutations:[...(R=p.preRedos)!=null?R:[],S,...p.redos,{id:V.id,params:a}]}),!0):!1}},ut={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),t=i.get(w.ISheetDrawingService).getFocusDrawings();if(t.length===0)return!1;const n=t[0].unitId,o=t.map(s=>{const{unitId:a,subUnitId:d,drawingId:g,drawingType:u}=s;return{unitId:a,subUnitId:d,drawingId:g,drawingType:u}});return r.executeCommand(fe.id,{unitId:n,drawings:o})}};function Kt(i){const r=[];return i.forEach(e=>{const{parent:t,children:n}=e,{unitId:o,subUnitId:s,drawingId:a}=t,d=A.getGroupState(0,0,n.map(c=>c.transform||{})),g=n.map(c=>{const m=c.transform||{left:0,top:0},{unitId:h,subUnitId:p,drawingId:S}=c;return{unitId:h,subUnitId:p,drawingId:S,transform:{...m,left:m.left-d.left,top:m.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 zt(i){const r=[];return i.forEach(e=>{const{parent:t,children:n}=e,{unitId:o,subUnitId:s,drawingId:a,transform:d={width:0,height:0}}=t;if(d==null)return;const g=n.map(c=>{const{transform:m}=c,{unitId:h,subUnitId:p,drawingId:S}=c,f=A.transformObjectOutOfGroup(m||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:p,drawingId:S,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:g})}),r}const gt={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:p})=>{o.push(h.unitId),p.forEach(S=>{o.push(S.unitId)})});const s=n.getGroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=s;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:w.DrawingApplyType.GROUP})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:zt(c),type:w.DrawingApplyType.UNGROUP}},{id:V.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:w.DrawingApplyType.GROUP}},{id:V.id,params:o}]}),!0):!1}},be={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var _,D,R;const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService),o=i.get(C.SheetInterceptorService);if(!r)return!1;const s=r.drawings,a=s.map(y=>y.unitId),d=n.getBatchAddOp(s),{unitId:g,subUnitId:u,undo:c,redo:m,objects:h}=d,p=o.onCommandExecute({id:be.id,params:r}),S={id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:g,subUnitId:u,objects:h,type:w.DrawingApplyType.INSERT}},f={id:w.SetDrawingApplyMutation.id,params:{op:c,unitId:g,subUnitId:u,objects:h,type:w.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(_=p.preRedos)!=null?_:[],S,...p.redos],e)?(t.pushUndoRedo({unitID:g,undoMutations:[...(D=p.preUndos)!=null?D:[],f,...p.undos,{id:V.id,params:a}],redoMutations:[...(R=p.preRedos)!=null?R:[],S,...p.redos,{id:V.id,params:a}]}),!0):!1}},ht={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService);if(!r)return!1;const n=i.get(w.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:m,undo:h}=u;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:m,unitId:o,subUnitId:s,objects:c,type:w.DrawingApplyType.ARRANGE})?(t.pushUndoRedo({unitID:o,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:s,objects:c,type:w.DrawingApplyType.ARRANGE}}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:s,objects:c,type:w.DrawingApplyType.ARRANGE}}]}),!0):!1}},we={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var v,_;const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService),o=i.get(C.SheetInterceptorService);if(!r)return!1;const{drawings:s}=r,a=n.getBatchUpdateOp(s),{unitId:d,subUnitId:g,undo:u,redo:c,objects:m}=a,h=o.onCommandExecute({id:we.id,params:r}),p=[...(v=h.preRedos)!=null?v:[],{id:w.SetDrawingApplyMutation.id,params:{unitId:d,subUnitId:g,op:c,objects:m,type:w.DrawingApplyType.UPDATE}},...h.redos,{id:V.id,params:[d]}],S=[...(_=h.preUndos)!=null?_:[],{id:w.SetDrawingApplyMutation.id,params:{unitId:d,subUnitId:g,op:u,objects:m,type:w.DrawingApplyType.UPDATE}},...h.undos,{id:V.id,params:[d]}];return l.sequenceExecute(p,e)?(t.pushUndoRedo({unitID:d,undoMutations:S,redoMutations:p}),!0):!1}},mt={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:p})=>{o.push(h.unitId),p.forEach(S=>{o.push(S.unitId)})});const s=n.getUngroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=s;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:w.DrawingApplyType.UNGROUP})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:Kt(c),type:w.DrawingApplyType.GROUP}},{id:V.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:w.DrawingApplyType.UNGROUP}},{id:V.id,params:o}]}),!0):!1}};var qt=Object.getOwnPropertyDescriptor,Zt=(i,r,e,t)=>{for(var n=t>1?void 0:t?qt(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},te=(i,r)=>(e,t)=>r(e,t,i);function Jt(i,r,e){const t=e*Math.PI/180,n=Math.abs(i*Math.cos(t))+Math.abs(r*Math.sin(t)),o=Math.abs(i*Math.sin(t))+Math.abs(r*Math.cos(t));return{rotatedWidth:n,rotatedHeight:o}}function pt(i,r,e,t,n){var _;const{rotatedHeight:o,rotatedWidth:s}=Jt(e,t,n),d=i.get(A.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const u=(_=d.with(b.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:_.skeleton;if(u==null)return!1;const c=u.getCellByIndex(r.row,r.col),m=c.mergeInfo.endX-c.mergeInfo.startX-2,h=c.mergeInfo.endY-c.mergeInfo.startY-2,p=s/o,f=Math.ceil(Math.min(m,h*p))/s,v=!f||Number.isNaN(f)?.001:f;return{width:e*v,height:t*v}}M.SheetDrawingUpdateController=class extends l.Disposable{constructor(e,t,n,o,s,a,d,g,u,c,m,h,p,S){super();ie(this,"_workbookSelections");this._context=e,this._skeletonManagerService=t,this._commandService=n,this._selectionRenderService=o,this._imageIoService=s,this._fileOpenerService=a,this._sheetDrawingService=d,this._drawingManagerService=g,this._contextService=u,this._messageService=c,this._localeService=m,this._injector=p,this._urlImageService=S,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const e=await this._fileOpenerService.openFile({multiple:!0,accept:B.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),t=e.length;return t>B.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(B.DRAWING_IMAGE_COUNT_LIMIT))}),!1):t===0?!1:(e.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const t=(await this._fileOpenerService.openFile({multiple:!1,accept:B.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return t?(await this._insertCellImage(t),!0):!1}insertCellImageByFile(e,t){return this._insertCellImage(e,t)}async insertFloatImageByFile(e){let t;try{t=await this._imageIoService.saveImage(e)}catch(D){const R=D.message;R===B.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(B.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):R===B.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):R===B.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(t==null)return;const n=this._getUnitInfo(),{unitId:o,subUnitId:s}=n,{imageId:a,imageSourceType:d,source:g,base64Cache:u}=t,{width:c,height:m,image:h}=await B.getImageSize(u||""),{width:p,height:S}=this._context.scene;this._imageIoService.addImageSourceCache(g,d,h);let f=1;if(c>B.DRAWING_IMAGE_WIDTH_LIMIT||m>B.DRAWING_IMAGE_HEIGHT_LIMIT){const D=B.DRAWING_IMAGE_WIDTH_LIMIT/c,R=B.DRAWING_IMAGE_HEIGHT_LIMIT/m;f=Math.max(D,R)}const v=this._getImagePosition(c*f,m*f,p,S);if(v==null)return;const _={unitId:o,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:d,source:g,transform:J(v,this._selectionRenderService,this._skeletonManagerService),sheetTransform:v};return this._commandService.executeCommand(be.id,{unitId:o,drawings:[_]})}async _insertCellImage(e,t){var R,y;let n;try{n=await this._imageIoService.saveImage(e)}catch(T){const I=T.message;I===B.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(B.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):I===B.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):I===B.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:o,imageSourceType:s,source:a,base64Cache:d}=n,{width:g,height:u,image:c}=await B.getImageSize(d||"");this._imageIoService.addImageSourceCache(a,s,c);const m=this._workbookSelections.getCurrentLastSelection();if(!m)return!1;let h=m.primary.actualRow,p=m.primary.actualColumn;m.primary.isMerged&&(h=m.primary.startRow,p=m.primary.startColumn);const S=l.createDocumentModelWithStyle("",{}),f=pt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:h,col:p},g,u,0);if(!f)return!1;const v={size:{width:f.width,height:f.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},_={unitId:S.getUnitId(),subUnitId:S.getUnitId(),drawingId:o,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:Fe.docDrawingPositionToTransform(v),docTransform:v,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},D=l.BuildTextUtils.drawing.add({documentDataModel:S,drawings:[_],selection:{collapsed:!0,startOffset:0,endOffset:0}});return D?(S.apply(D),this._commandService.syncExecuteCommand(C.SetRangeValuesCommand.id,{value:{[(R=t==null?void 0:t.row)!=null?R:h]:{[(y=t==null?void 0:t.col)!=null?y:p]:{p:S.getSnapshot(),t:1}}},unitId:t==null?void 0:t.unitId,subUnitId:t==null?void 0:t.subUnitId})):!1}async insertCellImageByUrl(e,t){var p,S;let n=e;try{n=await this._urlImageService.getImage(e)}catch(f){console.error(`Failed to get image from URLImageService: ${e}`,f)}const{width:o,height:s,image:a}=await B.getImageSize(n||"");this._imageIoService.addImageSourceCache(e,l.ImageSourceType.URL,a);const d=this._workbookSelections.getCurrentLastSelection();if(!d)return!1;const g=l.createDocumentModelWithStyle("",{}),u=pt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:d.primary.actualRow,col:d.primary.actualColumn},o,s,0);if(!u)return!1;const c={size:{width:u.width,height:u.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},m={unitId:g.getUnitId(),subUnitId:g.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:e,transform:Fe.docDrawingPositionToTransform(c),docTransform:c,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},h=l.BuildTextUtils.drawing.add({documentDataModel:g,drawings:[m],selection:{collapsed:!0,startOffset:0,endOffset:0}});return h?(g.apply(h),this._commandService.syncExecuteCommand(C.SetRangeValuesCommand.id,{value:{[(p=t==null?void 0:t.row)!=null?p:d.primary.actualRow]:{[(S=t==null?void 0:t.col)!=null?S:d.primary.actualColumn]:{p:g.getSnapshot(),t:1}}},unitId:t==null?void 0:t.unitId,subUnitId:t==null?void 0:t.subUnitId})):!1}_getUnitInfo(){const e=this._context.unit,t=e.getActiveSheet(),n=e.getUnitId(),o=t.getSheetId();return{unitId:n,subUnitId:o}}_getImagePosition(e,t,n,o){const s=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};s&&s.length>0&&(a=s[s.length-1].range);const d=b.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(d==null)return;let{startColumn:g,startRow:u,startX:c,startY:m}=d,h=!1;if(c+e>n&&(c=n-e,c<0&&(c=0,e=n),h=!0),m+t>o&&(m=o-t,m<0&&(m=0,t=o),h=!0),h){const v=this._selectionRenderService.getCellWithCoordByOffset(c,m);if(v==null)return;c=v.startX,m=v.startY,g=v.actualColumn,u=v.actualRow}const p={column:g,columnOffset:0,row:u,rowOffset:0},S=this._selectionRenderService.getCellWithCoordByOffset(c+e,m+t);if(S==null)return;const f={column:S.actualColumn,columnOffset:c+e-S.startX,row:S.actualRow,rowOffset:m+t-S.startY};return{from:p,to:f}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{const{unitId:t,subUnitId:n,drawingIds:o,arrangeType:s}=e;this._commandService.executeCommand(ht.id,{unitId:t,subUnitId:n,drawingIds:o,arrangeType:s})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{const t=[];e.length!==0&&(e.forEach(n=>{const{unitId:o,subUnitId:s,drawingId:a,drawingType:d,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:a});if(u==null||u.unitId!==this._context.unitId)return;const c=H({...u.transform,...g},this._selectionRenderService);if(c==null)return;const m={...n,transform:{...u.transform,...g,...J(c,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...c}};t.push(m)}),t.length>0&&this._commandService.executeCommand(we.id,{unitId:e[0].unitId,drawings:t}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{this._commandService.executeCommand(gt.id,e);const{unitId:t,subUnitId:n,drawingId:o}=e[0].parent;this._commandService.syncExecuteCommand(B.SetDrawingSelectedOperation.id,[{unitId:t,subUnitId:n,drawingId:o}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{this._commandService.executeCommand(mt.id,e)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}},M.SheetDrawingUpdateController=Zt([te(1,l.Inject(b.SheetSkeletonManagerService)),te(2,l.ICommandService),te(3,b.ISheetSelectionRenderService),te(4,B.IImageIoService),te(5,j.ILocalFileService),te(6,w.ISheetDrawingService),te(7,B.IDrawingManagerService),te(8,l.IContextService),te(9,j.IMessageService),te(10,l.Inject(l.LocaleService)),te(11,l.Inject(C.SheetsSelectionsService)),te(12,l.Inject(l.Injector)),te(13,l.IURLImageService)],M.SheetDrawingUpdateController);const Oe={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{var s,a;const e=i.get(l.IUniverInstanceService),t=i.get(A.IRenderManagerService),n=(s=A.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,e,t))==null?void 0:s.with(M.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const d=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(d)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},St={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:i=>{var t,n;const r=i.get(l.IUniverInstanceService),e=i.get(A.IRenderManagerService);return(n=(t=A.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,r,e))==null?void 0:t.with(M.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}},ve={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(w.ISheetDrawingService),n=i.get(b.ISheetSelectionRenderService),{direction:o}=r,s=t.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,d=s.map(u=>{const{transform:c}=u;if(c==null)return null;const m={...c},{left:h=0,top:p=0}=c;return o===l.Direction.UP?m.top=p-1:o===l.Direction.DOWN?m.top=p+1:o===l.Direction.LEFT?m.left=h-1:o===l.Direction.RIGHT&&(m.left=h+1),{...u,transform:m,sheetTransform:H(m,n)}}).filter(u=>u!=null);return e.syncExecuteCommand(we.id,{unitId:a,drawings:d})?(e.syncExecuteCommand(V.id,[a]),!0):!1}};var Qt=Object.getOwnPropertyDescriptor,en=(i,r,e,t)=>{for(var n=t>1?void 0:t?Qt(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Le=(i,r)=>(e,t)=>r(e,t,i),he=(i=>(i.CELL_ADDRESS="cellAddress",i.COLUMN_VALUE="columnValue",i))(he||{});const $e=l.createIdentifier("sheets-drawing-ui.batch-save-images.service");function ft(i){let r="",e=i;for(;e>=0;)r=String.fromCharCode(e%26+65)+r,e=Math.floor(e/26)-1;return r}function Ye(i,r){return`${ft(r)}${i+1}`}function tn(i){const r=Ye(i.startRow,i.startColumn),e=Ye(i.endRow,i.endColumn);return r===e?r:`${r}:${e}`}function Ot(i){var r,e,t,n;return!!((e=(r=i==null?void 0:i.p)==null?void 0:r.drawingsOrder)!=null&&e.length&&((n=(t=i==null?void 0:i.p)==null?void 0:t.drawingsOrder)==null?void 0:n.length)>0)}function At(i){var t,n,o;if(!((n=(t=i.p)==null?void 0:t.drawingsOrder)!=null&&n.length)||!((o=i.p)!=null&&o.drawings))return null;const r=i.p.drawingsOrder[0],e=i.p.drawings[r];return!e||!("source"in e)||!("imageSourceType"in e)?null:e}function wt(i,r){if(r===l.ImageSourceType.BASE64){const e=i.match(/^data:image\/(\w+);/);if(e)return e[1]==="jpeg"?"jpg":e[1]}if(r===l.ImageSourceType.URL){const e=i.match(/\.(\w+)(?:\?|$)/);if(e)return e[1].toLowerCase()}return"png"}async function Ut(i,r){if(r===l.ImageSourceType.BASE64)return(await fetch(i)).blob();if(r===l.ImageSourceType.URL)return(await fetch(i)).blob();throw new Error("UUID image type requires additional handling")}M.BatchSaveImagesService=class extends l.Disposable{constructor(r,e,t,n){super(),this._univerInstanceService=r,this._selectionService=e,this._imageIoService=t,this._urlImageService=n}registerURLImageDownloader(r){return this._urlImageService.registerURLImageDownloader(r)}getCellImagesInSelection(){const r=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!r)return[];const e=r.getActiveSheet();if(!e)return[];const t=this._selectionService.getCurrentSelections();if(!t||t.length===0)return[];const n=e.getCellMatrix(),o=[];for(const s of t){const{startRow:a,endRow:d,startColumn:g,endColumn:u}=s.range;for(let c=a;c<=d;c++)for(let m=g;m<=u;m++){const h=n.getValue(c,m);if(Ot(h)){const p=At(h);p&&o.push({row:c,col:m,cellAddress:Ye(c,m),source:p.source,imageSourceType:p.imageSourceType,imageId:p.drawingId})}}}return o}getCellImagesFromRanges(r,e,t){const n=this._univerInstanceService.getUnit(r,l.UniverInstanceType.UNIVER_SHEET);if(!n)return[];const o=n.getSheetBySheetId(e);if(!o)return[];const s=o.getCellMatrix(),a=[];for(const d of t){const{startRow:g,endRow:u,startColumn:c,endColumn:m}=d;for(let h=g;h<=u;h++)for(let p=c;p<=m;p++){const S=s.getValue(h,p);if(Ot(S)){const f=At(S);f&&a.push({row:h,col:p,cellAddress:Ye(h,p),source:f.source,imageSourceType:f.imageSourceType,imageId:f.drawingId})}}}return a}getDataColumns(){var m,h,p,S;const r=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!r)return[];const e=r.getActiveSheet();if(!e)return[];const t=this._selectionService.getCurrentSelections();if(!t||t.length===0)return[];const n=e.getCellMatrix(),o=n.getDataRange();let s=1/0,a=-1/0;const d=new Set;for(const f of t){s=Math.min(s,f.range.startRow),a=Math.max(a,f.range.endRow);for(let v=f.range.startColumn;v<=f.range.endColumn;v++)d.add(v)}const g=new Set;for(let f=o.startColumn;f<=o.endColumn;f++)if(!d.has(f))for(let v=s;v<=a;v++){const _=n.getValue(v,f);if(_&&(((m=_.v)==null?void 0:m.toString())||((S=(p=(h=_.p)==null?void 0:h.body)==null?void 0:p.dataStream)==null?void 0:S.trim())||"")){g.add(f);break}}const u=[],c=Array.from(g).sort((f,v)=>f-v);for(const f of c)u.push({index:f,label:ft(f)});return u}getDataColumnsForRanges(r,e,t){var p,S,f,v;const n=this._univerInstanceService.getUnit(r,l.UniverInstanceType.UNIVER_SHEET);if(!n)return[];const o=n.getSheetBySheetId(e);if(!o)return[];const s=o.getCellMatrix(),a=s.getDataRange();let d=1/0,g=-1/0;const u=new Set;for(const _ of t){d=Math.min(d,_.startRow),g=Math.max(g,_.endRow);for(let D=_.startColumn;D<=_.endColumn;D++)u.add(D)}const c=new Set;for(let _=a.startColumn;_<=a.endColumn;_++)if(!u.has(_))for(let D=d;D<=g;D++){const R=s.getValue(D,_);if(R&&(((p=R.v)==null?void 0:p.toString())||((v=(f=(S=R.p)==null?void 0:S.body)==null?void 0:f.dataStream)==null?void 0:v.trim())||"")){c.add(_);break}}const m=[],h=Array.from(c).sort((_,D)=>_-D);for(const _ of h)m.push({index:_,label:ft(_)});return m}getSelectionRangeNotation(){const r=this._selectionService.getCurrentSelections();return!r||r.length===0?"":r.map(e=>tn(e.range)).join(", ")}getSelectionRowRange(){const r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return null;let e=1/0,t=-1/0;for(const n of r)e=Math.min(e,n.range.startRow),t=Math.max(t,n.range.endRow);return{startRow:e,endRow:t}}getSelectionColumnIndices(){const r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return new Set;const e=new Set;for(const t of r)for(let n=t.range.startColumn;n<=t.range.endColumn;n++)e.add(n);return e}generateFileName(r,e){var s,a,d,g;const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),n=wt(r.source,r.imageSourceType),o=[];for(const u of e.fileNameParts)if(u==="cellAddress")o.push(r.cellAddress);else if(u==="columnValue"&&e.columnIndex!==void 0){const c=t==null?void 0:t.getActiveSheet();if(c){const h=c.getCellMatrix().getValue(r.row,e.columnIndex);if(h){const p=((s=h.v)==null?void 0:s.toString())||((g=(d=(a=h.p)==null?void 0:a.body)==null?void 0:d.dataStream)==null?void 0:g.trim())||"";if(p){const S=p.replace(/[<>:"/\\|?*]/g,"_").trim();S&&o.push(S)}}}}return o.length===0?`${r.cellAddress}.${n}`:`${o.join("_")}.${n}`}generateFileNameWithContext(r,e,t,n){var d,g,u,c;const o=this._univerInstanceService.getUnit(t,l.UniverInstanceType.UNIVER_SHEET),s=wt(r.source,r.imageSourceType),a=[];for(const m of e.fileNameParts)if(m==="cellAddress")a.push(r.cellAddress);else if(m==="columnValue"&&e.columnIndex!==void 0){const h=o==null?void 0:o.getSheetBySheetId(n);if(h){const S=h.getCellMatrix().getValue(r.row,e.columnIndex);if(S){const f=((d=S.v)==null?void 0:d.toString())||((c=(u=(g=S.p)==null?void 0:g.body)==null?void 0:u.dataStream)==null?void 0:c.trim())||"";if(f){const v=f.replace(/[<>:"/\\|?*]/g,"_").trim();v&&a.push(v)}}}}return a.length===0?`${r.cellAddress}.${s}`:`${a.join("_")}.${s}`}async saveImages(r,e){var o;const t=await window.showDirectoryPicker({mode:"readwrite"}),n=new Map;for(const s of r){let a=this.generateFileName(s,e);const d=a.replace(/\.\w+$/,""),g=((o=a.match(/\.\w+$/))==null?void 0:o[0])||".png",u=n.get(d)||0;u>0&&(a=`${d}_${u}${g}`),n.set(d,u+1);try{const c=await this._getImageBlob(s),h=await(await t.getFileHandle(a,{create:!0})).createWritable();await h.write(c),await h.close()}catch(c){throw console.error(`Failed to save image ${a}:`,c),c}}}async saveImagesWithContext(r,e,t,n){var a;const o=await window.showDirectoryPicker({mode:"readwrite"}),s=new Map;for(const d of r){let g=this.generateFileNameWithContext(d,e,t,n);const u=g.replace(/\.\w+$/,""),c=((a=g.match(/\.\w+$/))==null?void 0:a[0])||".png",m=s.get(u)||0;m>0&&(g=`${u}_${m}${c}`),s.set(u,m+1);try{const h=await this._getImageBlob(d),S=await(await o.getFileHandle(g,{create:!0})).createWritable();await S.write(h),await S.close()}catch(h){throw console.error(`Failed to save image ${g}:`,h),h}}}async downloadSingleImage(r){const e=wt(r.source,r.imageSourceType),t=`${r.cellAddress}.${e}`;try{const n=await this._getImageBlob(r),o=URL.createObjectURL(n),s=document.createElement("a");s.href=o,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(o)}catch(n){throw console.error(`Failed to download image ${t}:`,n),n}}async _getImageBlob(r){if(r.imageSourceType===l.ImageSourceType.UUID){const e=await this._imageIoService.getImage(r.source);return Ut(e,l.ImageSourceType.URL)}return r.imageSourceType===l.ImageSourceType.URL?this._urlImageService.downloadImage(r.source):Ut(r.source,r.imageSourceType)}},M.BatchSaveImagesService=en([Le(0,l.IUniverInstanceService),Le(1,l.Inject(C.SheetsSelectionsService)),Le(2,l.IImageIoService),Le(3,l.IURLImageService)],M.BatchSaveImagesService);const _e="sheet.dialog.batch-save-images",Ie={id:"sheet.command.save-cell-images",type:l.CommandType.COMMAND,handler:async i=>{const r=i.get(j.IDialogService),e=i.get($e),t=e.getCellImagesInSelection();if(t.length===1)try{return await e.downloadSingleImage(t[0]),!0}catch(a){return console.error("Failed to download image:",a),!1}const n=i.get(l.LocaleService),o=e.getSelectionRangeNotation(),s=`${n.t("sheetImage.save.title")} (${o})`;return r.open({id:_e,draggable:!0,width:360,title:{title:s},children:{label:_e},destroyOnClose:!0,preservePositionOnDestroy:!0,onClose:()=>r.close(_e)}),!0}},Pt="COMPONENT_SHEET_DRAWING_PANEL",vt={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{const e=i.get(j.ISidebarService),t=i.get(l.LocaleService),n=i.get(l.IUniverInstanceService),o=i.get(l.ICommandService);return C.getSheetCommandTarget(n)?(r.value==="open"?e.open({header:{title:t.t("sheetImage.panel.title")},children:{label:Pt},onClose:()=>{o.syncExecuteCommand(B.SetDrawingSelectedOperation.id,[])},width:360}):e.close(),!0):!1}},_t={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(i,r)=>{const e=i.get(l.ICommandService);return r==null?!1:(e.syncExecuteCommand(B.SetDrawingSelectedOperation.id,[r]),e.executeCommand(vt.id,{value:"open"}),!0)}},nn="sheets-drawing-ui.config",Nt={};var rn=Object.getOwnPropertyDescriptor,on=(i,r,e,t)=>{for(var n=t>1?void 0:t?rn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},se=(i,r)=>(e,t)=>r(e,t,i);let Ge=class extends l.RxDisposable{constructor(r,e,t,n,o,s,a,d,g,u){super();ie(this,"_initImagePopupMenu",new Set);this._injector=r,this._localeService=e,this._drawingManagerService=t,this._canvasPopManagerService=n,this._renderManagerService=o,this._univerInstanceService=s,this._messageService=a,this._contextService=d,this._ioService=g,this._commandService=u,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._setupLoadingStatus()}_setupLoadingStatus(){const r="image-upload-loading";let e;this.disposeWithMe(this._ioService.change$.subscribe(t=>{t>0&&!e?e=this._messageService.show({id:r,type:Y.MessageType.Loading,content:`${this._localeService.t("uploadLoading.loading")}: ${t}`,duration:0}):t===0&&(e==null||e.dispose(),e=void 0)}))}_dispose(r){super.dispose();const e=r.getUnitId();this._renderManagerService.removeRender(e),this._initImagePopupMenu.delete(e)}_create(r){if(!r)return;const e=r.getUnitId();this._renderManagerService.has(e)&&!this._initImagePopupMenu.has(e)&&(this._popupMenuListener(e),this._initImagePopupMenu.add(e))}_hasCropObject(r){const e=r.getAllObjectsByOrder();for(const t of e)if(t instanceof ge.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const e=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!e)return;const t=e.getTransformerByCreate();if(!t)return;let n;this.disposeWithMe(t.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(e))return;const s=t.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:m,drawingType:h}=g,p=g.data;if(p&&p.disablePopup)return;n==null||n.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,c,m,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:ge.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,c,m,h)}}))})),this.disposeWithMe(t.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(B.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(s=>{s[l.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(t.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,e,t,n){return[{label:"image-popup.edit",index:0,commandId:_t.id,commandParams:{unitId:r,subUnitId:e,drawingId:t},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:fe.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:e,drawingId:t}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ge.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:e,drawingId:t},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ge.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:e,drawingId:t}],disable:n===l.DrawingTypeEnum.DRAWING_DOM}]}};Ge=on([se(0,l.Inject(l.Injector)),se(1,l.Inject(l.LocaleService)),se(2,B.IDrawingManagerService),se(3,l.Inject(b.SheetCanvasPopManagerService)),se(4,A.IRenderManagerService),se(5,l.IUniverInstanceService),se(6,j.IMessageService),se(7,l.IContextService),se(8,l.IImageIoService),se(9,l.ICommandService)],Ge);var sn=Object.getOwnPropertyDescriptor,an=(i,r,e,t)=>{for(var n=t>1?void 0:t?sn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},He=(i,r)=>(e,t)=>r(e,t,i);let It=class extends l.Disposable{constructor(r,e,t,n,o){super();ie(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=e,this._selectionsService=t,this._drawingRenderService=n,this._sheetSkeletonManagerService=o,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(U.throttleTime(33)).subscribe(r=>{var t,n;let e=[];r!==null&&(e=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),e.length>0&&(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&e.length===1&&((t=e[0].primary)==null?void 0:t.actualRow)===r.row&&((n=e[0].primary)==null?void 0:n.actualColumn)===r.col?(this._isSetCursor=!0,this._context.scene.setCursor(A.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(r=>{var e;if(r!=null&&r.drawing&&this._isSetCursor){const t=r.drawing.drawing.drawingOrigin,n=(e=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:e.imageCacheMap.getImage(t.imageSourceType,t.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};It=an([He(1,l.Inject(b.HoverManagerService)),He(2,l.Inject(C.SheetsSelectionsService)),He(3,l.Inject(ge.DrawingRenderService)),He(4,l.Inject(b.SheetSkeletonManagerService))],It);var cn=Object.getOwnPropertyDescriptor,dn=(i,r,e,t)=>{for(var n=t>1?void 0:t?cn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ve=(i,r)=>(e,t)=>r(e,t,i);let Ct=class extends l.Disposable{constructor(i,r,e,t,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=e,this._sheetSelectionRenderService=t,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 e=i[r];for(const t in e.data){const n=e.data[t];n.sheetTransform&&(n.transform=J(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService))}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};Ct=dn([Ve(1,w.ISheetDrawingService),Ve(2,B.IDrawingManagerService),Ve(3,l.Inject(b.ISheetSelectionRenderService)),Ve(4,l.Inject(b.SheetSkeletonManagerService))],Ct);var ln=Object.getOwnPropertyDescriptor,un=(i,r,e,t)=>{for(var n=t>1?void 0:t?ln(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ce=(i,r)=>(e,t)=>r(e,t,i);function kt(i,r,e){var t,n,o,s;if(((n=(t=e==null?void 0:e.p)==null?void 0:t.body)==null?void 0:n.dataStream.length)===3&&((s=(o=e.p)==null?void 0:o.drawingsOrder)==null?void 0:s.length)===1){const a=e.p.drawings[e.p.drawingsOrder[0]],d=pt(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,e.p.documentStyle.pageSize.width=1/0,e.p.documentStyle.pageSize.height=1/0,!0}return!1}let Xe=class extends l.Disposable{constructor(i,r,e,t,n,o){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=e,this._drawingManagerService=t,this._docDrawingController=n,this._editorBridgeService=o,this._handleInitEditor(),this._initCellContentInterceptor()}_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===Fe.ReplaceSnapshotCommand.id&&i.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(C.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:C.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,e)=>{var t;return i!=null&&i.p&&((t=i.p.drawingsOrder)!=null&&t.length)&&(i===r.rawData&&(i={...r.rawData}),i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0},kt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),e(i)}}))}};Xe=un([Ce(0,l.ICommandService),Ce(1,l.Inject(C.SheetInterceptorService)),Ce(2,l.Inject(l.Injector)),Ce(3,B.IDrawingManagerService),Ce(4,l.Inject(bt.DocDrawingController)),Ce(5,l.Inject(b.IEditorBridgeService))],Xe);var gn=Object.getOwnPropertyDescriptor,hn=(i,r,e,t)=>{for(var n=t>1?void 0:t?gn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Wt=(i,r)=>(e,t)=>r(e,t,i);let xe=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,e,t)=>{new l.ObjectMatrix(t).forValue((n,o,s)=>{kt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},s)})}}))}};xe=hn([Wt(0,l.Inject(b.IAutoFillService)),Wt(1,l.Inject(l.Injector))],xe);var mn=Object.getOwnPropertyDescriptor,pn=(i,r,e,t)=>{for(var n=t>1?void 0:t?mn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ae=(i,r)=>(e,t)=>r(e,t,i);const Sn=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,l.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let Ke=class extends l.Disposable{constructor(i,r,e,t,n){super(),this._commandService=i,this._univerInstanceService=r,this._dialogService=e,this._renderManagerService=t,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(i){var n;const r=l.createDocumentModelWithStyle("",{}),e=(n=A.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(b.EditingRenderController),t=l.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[i],selection:{collapsed:!0,startOffset:0,endOffset:0}});t&&(r.apply(t),e&&e.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(i=>{var r,e;if(i.id===Fe.InnerPasteCommand.id){const t=i.params,{doc:n}=t,o=this._univerInstanceService.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_DOC);if(o==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const s=o.getUnitId();if(Sn.includes(s)){if(s!==l.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const a=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(b.SetCellEditVisibleOperation.id,{visible:!1})};((e=o.getBody())==null?void 0:e.dataStream)===`\r
15
- `?(this._commandService.syncExecuteCommand(b.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(n.drawings)[0])):this._dialogService.open({id:"sheet-cell-image-copy-paste",title:{label:this._localeService.t("cell-image.pasteTitle")},children:{label:this._localeService.t("cell-image.pasteContent")},width:320,destroyOnClose:!0,onClose:a,showOk:!0,showCancel:!0,onOk:()=>{a(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:a})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};Ke=pn([Ae(0,l.ICommandService),Ae(1,l.IUniverInstanceService),Ae(2,j.IDialogService),Ae(3,A.IRenderManagerService),Ae(4,l.Inject(l.LocaleService))],Ke);var fn=Object.getOwnPropertyDescriptor,wn=(i,r,e,t)=>{for(var n=t>1?void 0:t?fn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ue=(i,r)=>(e,t)=>r(e,t,i);const Bt="image/png";function vn(i){const r=i.split(","),e=atob(r[1]),t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return new Blob([n],{type:Bt})}function _n(i){const r=new ClipboardItem({[Bt]:vn(i)});navigator.clipboard.write([r]).catch(e=>{console.error("Could not copy image using clipboard API: ",e)})}function In(){function i(){const t=document.createElement("input");return t.style.position="absolute",t.style.height="1px",t.style.width="1px",t.style.opacity="0",t}const r=document.activeElement,e=i();return document.body.appendChild(e),e.focus(),()=>{e.blur(),document.body.removeChild(e),r instanceof HTMLElement&&r.focus()}}const jt=[b.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,b.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,b.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,b.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA];let ze=class extends l.Disposable{constructor(r,e,t,n,o){super();ie(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=e,this._drawingService=t,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,e,t,n)=>{this._copyInfo=null;const o=this._focusedDrawings;if(o.length>0){const[s]=o;if(s.drawingType!==l.DrawingTypeEnum.DRAWING_IMAGE)return;if(n===b.COPY_TYPE.CUT){const d={unitId:r,drawings:[s]};this._commandService.executeCommand(fe.id,d)}setTimeout(()=>{const d=In();s.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&s.imageSourceType===B.ImageSourceType.BASE64?_n(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,e,t);this._copyInfo=s}},onPasteCells:(r,e,t,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=b.COPY_TYPE.COPY,pasteType:s}=n,{range:a}=r||{},{range:d,unitId:g,subUnitId:u}=e;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:s,unitId:g,subUnitId:u,pasteRange:d},{copyRange:a,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:e,pasteType:s},b.COPY_TYPE.COPY)},onPastePlainText:(r,e)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:b.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},b.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,e)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:b.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},b.COPY_TYPE.COPY);{const t=e.filter(n=>n.type.includes("image"));if(t.length)return{undos:[],redos:[{id:Oe.id,params:{files:t}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,e,t){var m;const n=(m=this._renderManagerService.getRenderById(r))==null?void 0:m.with(b.SheetSkeletonManagerService);if(!n)return;const o=n.attachRangeWithCoord(t);if(!o)return;const{startX:s,endX:a,startY:d,endY:g}=o,u=this._drawingService.getDrawingData(r,e),c=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const p=u[h];if(p.drawingType!==l.DrawingTypeEnum.DRAWING_IMAGE)return;const{transform:S}=p;if(p.anchorType!==w.SheetDrawingAnchorType.Both||!S)return;const{left:f=0,top:v=0,width:_=0,height:D=0}=S,{drawingStartX:R,drawingEndX:y,drawingStartY:T,drawingEndY:I}={drawingStartX:f,drawingEndX:f+_,drawingStartY:v,drawingEndY:v+D};s<=R&&y<=a&&d<=T&&I<=g&&c.push(p)}),c.length)return{copyRange:t,drawings:c,unitId:r,subUnitId:e}}_generateSingleDrawingPasteMutations(r,e){const{pasteType:t,pasteTo:n}=r;if(jt.includes(t))return{redos:[],undos:[]};const{unitId:o,subUnitId:s,range:a}=n,d=this._renderManagerService.getRenderById(o),g=d==null?void 0:d.with(b.SheetSkeletonManagerService),u=d==null?void 0:d.with(b.ISheetSelectionRenderService),c=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:m}=c,h=b.discreteRangeToRange(a);return this._generateMutations(m,{unitId:o,subUnitId:s,isCut:e===b.COPY_TYPE.CUT,getTransform:(p,S)=>{var _;const f=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),v={...p,left:f==null?void 0:f.startX,top:f==null?void 0:f.startY};return{transform:v,sheetTransform:(_=H(v,u))!=null?_:S}}})}_generateMutations(r,e){const{unitId:t,subUnitId:n,getTransform:o,isCut:s}=e,a=[],d=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:c,sheetTransform:m}=u;if(!c)return;const h=o(c,m),p={...u,unitId:t,subUnitId:n,drawingId:s?u.drawingId:l.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(s){const{undo:S,redo:f,objects:v}=g.getBatchUpdateOp([p]);a.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:w.DrawingApplyType.UPDATE,op:f,objects:v}}),d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:w.DrawingApplyType.UPDATE,op:S,objects:v}})}else{const{undo:S,redo:f,objects:v}=g.getBatchAddOp([p]);a.push({id:w.SetDrawingApplyMutation.id,params:{op:f,unitId:t,subUnitId:n,objects:v,type:w.DrawingApplyType.INSERT}}),d.push({id:w.SetDrawingApplyMutation.id,params:{op:S,unitId:t,subUnitId:n,objects:v,type:w.DrawingApplyType.REMOVE}})}}),{redos:a,undos:d}}_generateRangeDrawingsPasteMutations(r,e){var N;const{unitId:t,subUnitId:n,pasteType:o,pasteRange:s}=r,{copyRange:a,copyType:d}=e;if(jt.includes(o))return{redos:[],undos:[]};const g=(N=this._renderManagerService.getRenderById(t))==null?void 0:N.with(b.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:t,subUnitId:n,range:b.discreteRangeToRange(s)},pasteType:o},d);const{ranges:[c,m],mapFunc:h}=b.virtualizeDiscreteRanges([a,s]),{row:p,col:S}=h(c.startRow,c.startColumn),{row:f,col:v}=h(m.startRow,m.startColumn),_=g.attachRangeWithCoord({startRow:p,endRow:p,startColumn:S,endColumn:S}),D=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:v,endColumn:v});if(!_||!D||!this._copyInfo)return{redos:[],undos:[]};const R=D.startX-_.startX,y=D.startY-_.startY,T=f-p,I=v-S;return this._generateMutations(u,{unitId:t,subUnitId:n,getTransform:(O,k)=>{var W,P;return{transform:{...O,left:((W=O==null?void 0:O.left)!=null?W:0)+R,top:((P=O==null?void 0:O.top)!=null?P:0)+y},sheetTransform:{...k,to:{...k.to,row:k.to.row+T,column:k.to.column+I},from:{...k.from,row:k.from.row+T,column:k.from.column+I}}}},isCut:d===b.COPY_TYPE.CUT})}};ze=wn([Ue(0,b.ISheetClipboardService),Ue(1,A.IRenderManagerService),Ue(2,B.IDrawingManagerService),Ue(3,j.IClipboardInterfaceService),Ue(4,l.ICommandService)],ze);var Cn=Object.getOwnPropertyDescriptor,yn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Cn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Pe=(i,r)=>(e,t)=>r(e,t,i);let qe=class extends l.Disposable{constructor(i,r,e,t,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=e,this._univerInstanceService=t,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$,e=U.combineLatest([i,r]);this.disposeWithMe(e.pipe(U.switchMap(([t,n])=>t?t.activeSheet$.pipe(U.tap(o=>{if(!o){this._drawingManagerService.setDrawingVisible(!1);return}const s=t.getUnitId(),a=o.getSheetId();this._permissionService.composePermission([new C.WorkbookViewPermission(s).id,new C.WorksheetViewPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(t,o)})):(this._drawingManagerService.setDrawingVisible(!1),U.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(i,r){this._drawingManagerService.setDrawingVisible(!1);const e=i.getUnitId(),t=r.getSheetId(),n=this._drawingManagerService.getDrawingData(e,t),o=Object.values(n),s=this._renderManagerService.getRenderById(e),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===A.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$,e=U.combineLatest([i,r]);this.disposeWithMe(e.pipe(U.switchMap(([t,n])=>t?t.activeSheet$.pipe(U.tap(o=>{if(!o){this._drawingManagerService.setDrawingEditable(!1);return}const s=t.getUnitId(),a=o.getSheetId();this._permissionService.composePermission([new C.WorkbookEditablePermission(s).id,new C.WorksheetEditPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(t,o)})):(this._drawingManagerService.setDrawingEditable(!1),U.EMPTY))).subscribe())}_handleDrawingEditableFalse(i,r){this._drawingManagerService.setDrawingEditable(!1);const e=i.getUnitId(),t=r.getSheetId(),n=this._drawingManagerService.getDrawingData(e,t),o=Object.values(n),s=this._renderManagerService.getRenderById(e),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===A.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(([e,t])=>e?e.activeSheet$.pipe(U.switchMap(n=>{if(!n)return U.EMPTY;const o=e.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 C.WorkbookViewPermission(o).id,new C.WorksheetViewPermission(o,s).id]).pipe(U.map(c=>c.every(m=>m.value)),U.distinctUntilChanged()).pipe(U.map(c=>({permission:c,scene:d,transformer:g,unitId:o,subUnitId:s})))})):U.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:o,subUnitId:s})=>{this._drawingManagerService.setDrawingVisible(e);const a=t.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(o,s),g=Object.values(d);e?this._drawingManagerService.addNotification(g):(a.forEach(u=>{u.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&t.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const e=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),t=e==null?void 0:e.getActiveSheet(),n=e==null?void 0:e.getUnitId(),o=t==null?void 0:t.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(([e,t])=>e?e.activeSheet$.pipe(U.switchMap(n=>{if(!n)return U.EMPTY;const o=e.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 C.WorkbookEditablePermission(o).id,new C.WorksheetEditPermission(o,s).id]).pipe(U.map(c=>c.every(m=>m.value)),U.distinctUntilChanged()).pipe(U.map(c=>({permission:c,scene:d,transformer:g,unitId:o,subUnitId:s})))})):U.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:o,subUnitId:s})=>{this._drawingManagerService.setDrawingEditable(e);const a=t.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(o,s),g=Object.values(d);e?(a.forEach(u=>{u.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&t.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(a.forEach(u=>{u.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&t.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const e=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!e)return;const t=e.getUnitId(),n=e.getActiveSheet();if(!n)return;const o=n.getSheetId(),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;const d=this._drawingManagerService.getDrawingData(t,o),g=Object.values(d);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(c=>{c.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(m=>c.oKey.includes(m.drawingId))&&a.detachTransformerFrom(c)})}}))}};qe=yn([Pe(0,B.IDrawingManagerService),Pe(1,A.IRenderManagerService),Pe(2,l.IPermissionService),Pe(3,l.IUniverInstanceService),Pe(4,l.Inject(l.UserManagerService))],qe);var Dn=Object.getOwnPropertyDescriptor,Tn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Dn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},pe=(i,r)=>(e,t)=>r(e,t,i);const Ft="univer-sheet-float-dom-";function Lt(i,r,e,t,n,o=!1){const{scaleX:s,scaleY:a}=r.getAncestorScale(),d=r.getViewport(A.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=t.getFreeze(),{startColumn:u,startRow:c,xSplit:m,ySplit:h}=g,p={left:!0,top:!0};if(!d)return{...i,absolute:p};const{left:S,right:f,top:v,bottom:_}=i;let{top:D,left:R,viewportScrollX:y,viewportScrollY:T}=d;const{boundsOfViewArea:I,scrollDirectionResponse:N}=n||{},{rowHeaderWidth:O,columnHeaderHeight:k}=e,W={top:o?0:k,left:o?0:O};I&&(l.Tools.isDefine(W.top)&&(W.top=I.top),l.Tools.isDefine(W.left)&&(W.left=I.left)),N==="HORIZONTAL"&&(T=0),N==="VERTICAL"&&(y=0);let P=0,E=0;const F=e.rowStartY(c-h)+k,G=e.colStartX(u-m)+O,Q=e.rowStartY(c)+k,ne=e.colStartX(u)+O;if(m===0)p.left=!1,P=(S-y)*s,E=(f-y)*s;else{const z=S-(G-O),ee=f-(G-O);f<ne?(P=z*s,E=ee*s):S<=ne&&f>=ne?(P=z*s,E=Math.max(R,(f-y)*s)):S>ne&&(p.left=!1,P=Math.max((S-y)*s,R),E=Math.max((f-y)*s,R))}let K=0,Z=0;if(h===0)p.top=!1,K=(v-T)*a,Z=(_-T)*a;else{const z=v-(F-k),ee=_-(F-k);_<Q?(K=z*a,Z=ee*a):v<=Q&&_>=Q?(K=z*a,Z=Math.max(D,(_-T)*a)):v>Q&&(p.top=!1,K=Math.max((v-T)*a,D),Z=Math.max((_-T)*a,D))}return P=Math.max(P,W.left),K=Math.max(K,W.top),E=Math.max(E,W.left),Z=Math.max(Z,W.top),{left:P,right:E,top:K,bottom:Z,absolute:p}}const ae=(i,r,e,t,n)=>{const{left:o,top:s,width:a,height:d,angle:g}=i,u={left:o,right:o+a,top:s,bottom:s+d},c=Lt(u,r,e,t,n),{scaleX:m,scaleY:h}=r.getAncestorScale();return{startX:c.left,endX:c.right,startY:c.top,endY:c.bottom,rotate:g,width:a*m,height:d*h,absolute:c.absolute}};M.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(e,t,n,o,s,a,d){super();ie(this,"_domLayerInfoMap",new Map);ie(this,"_transformChange$",new U.Subject);ie(this,"transformChange$",this._transformChange$.asObservable());ie(this,"_add$",new U.Subject);ie(this,"add$",this._add$.asObservable());ie(this,"_remove$",new U.Subject);ie(this,"remove$",this._remove$.asObservable());this._renderManagerService=e,this._univerInstanceService=t,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(e=>e===l.LifecycleStages.Rendered),U.take(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(e){return this._domLayerInfoMap.get(e)}getFloatDomsBySubUnitId(e,t){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===t&&n.unitId===e)}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;const t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;if(t==null||n==null)return null;const o=n.getTransformerByCreate(),s=t.engine.getCanvasElement();return{scene:n,transformer:o,renderUnit:t,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(t=>{var ee;const{unitId:n,subUnitId:o,drawingId:s}=t,a=C.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(t),g=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!d||!a)return;const c=(ee=this._renderManagerService.getRenderById(n))==null?void 0:ee.with(b.SheetSkeletonManagerService).getSkeletonParam(o);if(!c)return;const{transform:m,drawingType:h,data:p}=d;if(h!==l.DrawingTypeEnum.DRAWING_DOM&&h!==l.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(n);if(S==null)return;const{scene:f,canvas:v}=S;if(m==null)return!0;if(u!==o)return;const{left:_,top:D,width:R,height:y,angle:T,flipX:I,flipY:N,skewX:O,skewY:k}=m,W=B.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),P=f.getObject(W);if(P!=null){P.transformByState({left:_,top:D,width:R,height:y,angle:T,flipX:I,flipY:N,skewX:O,skewY:k});return}const E={left:_,top:D,width:R,height:y,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},F=h===l.DrawingTypeEnum.DRAWING_CHART;if(E.rotateEnabled=!1,F){const X=p?p.backgroundColor:"white";E.fill=X,p&&p.border&&(E.stroke=p.border),E.paintFirst="stroke",E.strokeWidth=1,E.borderEnabled=!1,E.radius=8}const G=new A.Rect(W,E);F&&G.setObjectType(A.ObjectType.CHART),f.addObject(G,A.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&f.attachTransformerTo(G);const Q=new l.DisposableCollection,ne=ae(G,S.renderUnit.scene,c.skeleton,a.worksheet),K=new U.BehaviorSubject(ne),Z=`${Ft}${l.generateRandomId(6)}`,oe={dispose:Q,rect:G,position$:K,unitId:n,subUnitId:o,id:s,domId:Z};this._canvasFloatDomService.addFloatDom({position$:K,id:s,domId:Z,componentKey:d.componentKey,onPointerDown:X=>{v.dispatchEvent(new PointerEvent(X.type,X))},onPointerMove:X=>{v.dispatchEvent(new PointerEvent(X.type,X))},onPointerUp:X=>{v.dispatchEvent(new PointerEvent(X.type,X))},onWheel:X=>{v.dispatchEvent(new WheelEvent(X.type,X))},data:p,unitId:n});const z=G.onTransformChange$.subscribeEvent(()=>{const X=ae(G,S.renderUnit.scene,c.skeleton,a.worksheet);K.next(X)});Q.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),z&&Q.add(z),this._domLayerInfoMap.set(s,oe)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(t=>{var m;const{unitId:n,subUnitId:o,drawingId:s}=t,a=B.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]),(m=u.getTransformer())==null||m.clearSelectedObjects())})}))}_scrollUpdateListener(){const e=(t,n)=>{var g;const o=this._getSceneAndTransformerByDrawingSearch(t),s=Array.from(this._domLayerInfoMap.keys()).map(u=>({id:u,...this._domLayerInfoMap.get(u)})).filter(u=>u.subUnitId===n&&u.unitId===t).map(u=>u.id),a=C.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:n}),d=(g=this._renderManagerService.getRenderById(t))==null?void 0:g.with(b.SheetSkeletonManagerService).getSkeletonParam(n);!o||!a||!d||s.forEach(u=>{const c=this._domLayerInfoMap.get(u);if(c){const m=ae(c.rect,o.renderUnit.scene,d.skeleton,a.worksheet,c);c.position$.next(m)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(U.switchMap(t=>t?t.activeSheet$:U.of(null)),U.map(t=>{if(!t)return null;const n=t.getUnitId(),o=this._renderManagerService.getRenderById(n);return o?{render:o,unitId:n,subUnitId:t.getSheetId()}:null}),U.switchMap(t=>t?l.fromEventSubject(t.render.scene.getViewport(A.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(U.map(()=>({unitId:t.unitId,subUnitId:t.subUnitId}))):U.of(null))).subscribe(t=>{if(!t)return;const{unitId:n,subUnitId:o}=t;e(n,o)})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===b.SetZoomRatioOperation.id){const n=t.params,{unitId:o}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===o).map(a=>a.subUnitId).forEach(a=>{e(o,a)})}else if(t.id===C.SetFrozenMutation.id){const{unitId:n,subUnitId:o}=t.params;e(n,o)}else if(t.id===C.SetSelectionsOperation.id){const{unitId:n,subUnitId:o}=t.params;e(n,o)}}))}updateFloatDomProps(e,t,n,o){const s=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(e);if(s&&a){const{scene:d}=a,g=B.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:t,drawingId:n}),u=d.getObject(g);u&&u instanceof A.Rect&&u.setProps(o)}}_getPosition(e,t){var h;const{startX:n,endX:o,startY:s,endY:a}=e,d=(h=this._renderManagerService.getRenderById(t))==null?void 0:h.with(b.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 m={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:a-c.startY};return{from:u,to:m}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(t=>{const n=this._drawingManagerService.getDrawingByParam(t);if(!n||n.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const o={...n.transform};this._transformChange$.next({id:t.drawingId,value:o}),this._canvasFloatDomService.updateFloatDom(t.drawingId,{...n});const s=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(s&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART){const{scene:a}=s,d=this._domLayerInfoMap.get(t.drawingId);d!=null&&d.rect&&(n.allowTransform===!1?a.detachTransformerFrom(d.rect):a.attachTransformerTo(d.rect))}})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(t=>{this._removeDom(t.drawingId)})}))}addFloatDomToPosition(e,t){const n=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.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}=e,c=t!=null?t:l.generateRandomId(),m=this._getPosition(a,o);if(m==null)return;const h={unitId:o,subUnitId:s,drawingId:c,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:m,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(be.id,{unitId:o,drawings:[h]}),this._add$.next({unitId:o,subUnitId:s,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(e,t=!1){const n=this._domLayerInfoMap.get(e);if(!n)return;const{unitId:o,subUnitId:s}=n;this._domLayerInfoMap.delete(e),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(o);if(a&&a.scene.removeObject(n.rect),t){const d=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:e});if(!d)return;const g=this._sheetDrawingService.getBatchRemoveOp([d]),{redo:u,objects:c}=g;this._commandService.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:u,objects:c,type:w.DrawingApplyType.REMOVE})}}addFloatDomToRange(e,t,n,o){var I,N,O;const s=C.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.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=(I=this._renderManagerService.getRenderById(a))==null?void 0:I.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:m,data:h,allowTransform:p=!0}=t,S=o!=null?o:l.generateRandomId(),{position:f,position$:v}=this._createRangePositionObserver(e,u,c.skeleton);if(this._getPosition(f,a)==null)return;const D=g.scene,{scaleX:R}=D.getAncestorScale(),y=Ze(f,n,R),T={unitId:a,subUnitId:d,drawingId:S,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:y.startX,top:y.startY,width:y.width,height:y.height},data:h,allowTransform:p};{const{unitId:k,subUnitId:W,drawingId:P}=T,E=C.getSheetCommandTarget(this._univerInstanceService,{unitId:k,subUnitId:W}),F=T,G=this._univerInstanceService.getUnit(k,l.UniverInstanceType.UNIVER_SHEET);if(!G)return;const Q=G.getActiveSheet().getSheetId();if(!F||!E)return;const ne=(N=this._renderManagerService.getRenderById(k))==null?void 0:N.with(b.SheetSkeletonManagerService);if(!ne)return;const K=ne.getWorksheetSkeleton(W);if(!K)return;const{transform:Z,drawingType:oe,data:z}=F;if(oe!==l.DrawingTypeEnum.DRAWING_DOM&&oe!==l.DrawingTypeEnum.DRAWING_CHART)return;const ee=this._getSceneAndTransformerByDrawingSearch(k);if(ee==null)return;const{scene:X,canvas:De}=ee;if(Z==null||Q!==W)return;const{left:tt,top:nt,width:rt,height:it,angle:Rt,flipX:Et,flipY:ot,skewX:st,skewY:Te}=Z,at=B.getDrawingShapeKeyByDrawingSearch({unitId:k,subUnitId:W,drawingId:P}),ce=X.getObject(at);if(ce!=null){ce.transformByState({left:tt,top:nt,width:rt,height:it,angle:Rt,flipX:Et,flipY:ot,skewX:st,skewY:Te});return}const re={left:tt,top:nt,width:rt,height:it,zIndex:this._drawingManagerService.getDrawingOrder(k,W).length-1},Me=oe===l.DrawingTypeEnum.DRAWING_CHART;if(Me){const $=z?z.backgroundColor:"white";re.fill=$,re.rotateEnabled=!1,z&&z.border&&(re.stroke=z.border),re.paintFirst="stroke",re.strokeWidth=1,re.borderEnabled=!1,re.radius=8}const de=new A.Rect(at,re);Me&&de.setObjectType(A.ObjectType.CHART),X.addObject(de,A.DRAWING_OBJECT_LAYER_INDEX),F.allowTransform!==!1&&X.attachTransformerTo(de);const le=new l.DisposableCollection,ct=X.getMainViewport(),{rowHeaderWidth:Re,columnHeaderHeight:We}=K.skeleton,dt={top:We,left:Re,bottom:ct.bottom,right:ct.right},ue={dispose:le,rect:de,boundsOfViewArea:dt,domAnchor:n,unitId:k,subUnitId:W},x=ae(de,ee.renderUnit.scene,K.skeleton,E.worksheet,ue),Ee=new U.BehaviorSubject(x);ue.position$=Ee;let Be={position$:Ee,id:P,componentKey:F.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{De.dispatchEvent(new WheelEvent($.type,$))},data:z,unitId:k};t.eventPassThrough&&(Be={...Be,onPointerDown:$=>{De.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{De.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{De.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(Be),this.disposeWithMe(v.subscribe($=>{var Ht,Vt,Xt,xt;const Gt=Ze({startX:$.startX,startY:$.startY,endX:$.endX,endY:$.endY,width:(Ht=n.width)!=null?Ht:$.width,height:(Vt=n.height)!=null?Vt:$.height,absolute:{left:f.absolute.left,top:f.absolute.top}},n),er=B.getDrawingShapeKeyByDrawingSearch({unitId:k,subUnitId:W,drawingId:P}),tr=new A.Rect(er,{left:Gt.startX,top:Gt.startY,width:(Xt=n.width)!=null?Xt:$.width,height:(xt=n.height)!=null?xt:$.height,zIndex:this._drawingManagerService.getDrawingOrder(k,W).length-1}),nr=ae(tr,ee.renderUnit.scene,K.skeleton,E.worksheet,ue);Ee.next(nr)}));const je=(O=this._renderManagerService.getRenderById(k))==null?void 0:O.with(b.SheetSkeletonManagerService);je==null||je.currentSkeleton$.subscribe($=>{$&&K.sheetId!==$.sheetId&&this._removeDom(S,!0)});const lt=de.onTransformChange$.subscribeEvent(()=>{const $=ae(de,ee.renderUnit.scene,K.skeleton,E.worksheet,ue);Ee.next($)});le.add(()=>{this._canvasFloatDomService.removeFloatDom(P)}),lt&&le.add(lt),this._domLayerInfoMap.set(P,ue)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(e,t,n,o){var y,T,I;const s=C.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.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=(y=this._renderManagerService.getRenderById(a))==null?void 0:y.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:m,data:h,allowTransform:p=!0}=t,S=o!=null?o:l.generateRandomId(),{position:f,position$:v}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:e,endColumn:e},u,c.skeleton),_=f;if(_.startY=0,this._getPosition(f,a)==null)return;const R={unitId:a,subUnitId:d,drawingId:S,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:_.startX,top:_.startY,width:_.width,height:_.height},data:h,allowTransform:p};{const{unitId:N,subUnitId:O,drawingId:k}=R,W=C.getSheetCommandTarget(this._univerInstanceService,{unitId:N,subUnitId:O}),P=R,E=this._univerInstanceService.getUnit(N,l.UniverInstanceType.UNIVER_SHEET);if(!E)return;const F=E.getActiveSheet().getSheetId();if(!P||!W)return;const G=(T=this._renderManagerService.getRenderById(N))==null?void 0:T.with(b.SheetSkeletonManagerService);if(!G)return;const Q=G.getWorksheetSkeleton(O);if(!Q)return;const{transform:ne,data:K}=P,Z=this._getSceneAndTransformerByDrawingSearch(N);if(Z==null)return;const{scene:oe,canvas:z}=Z;if(ne==null||F!==O)return;const{left:ee,top:X,width:De,height:tt,angle:nt,flipX:rt,flipY:it,skewX:Rt,skewY:Et}=ne,ot=B.getDrawingShapeKeyByDrawingSearch({unitId:N,subUnitId:O,drawingId:k}),st=oe.getObject(ot);if(st!=null){st.transformByState({left:ee,top:X,width:De,height:tt,angle:nt,flipX:rt,flipY:it,skewX:Rt,skewY:Et});return}const Te=Ze({startX:_.startX,startY:0,endX:f.endX,endY:f.endY,width:n.width,height:n.height,absolute:{left:f.absolute.left,top:f.absolute.top}},n),at={left:Te.startX,top:Te.startY,width:Te.width,height:Te.height,zIndex:this._drawingManagerService.getDrawingOrder(N,O).length-1},ce=new A.Rect(ot,at);oe.addObject(ce,A.DRAWING_OBJECT_LAYER_INDEX),P.allowTransform!==!1&&oe.attachTransformerTo(ce);const re=new l.DisposableCollection,Me=oe.getMainViewport(),de={top:0,left:Me.left,bottom:Me.bottom,right:Me.right},le={dispose:re,rect:ce,unitId:N,subUnitId:O,boundsOfViewArea:de,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},ct=ae(ce,Z.renderUnit.scene,Q.skeleton,W.worksheet,le),Re=new U.BehaviorSubject(ct);le.position$=Re;let We={position$:Re,id:k,componentKey:P.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:x=>{z.dispatchEvent(new WheelEvent(x.type,x))},data:K,unitId:N};t.eventPassThrough&&(We={...We,onPointerDown:x=>{z.dispatchEvent(new PointerEvent(x.type,x))},onPointerMove:x=>{z.dispatchEvent(new PointerEvent(x.type,x))},onPointerUp:x=>{z.dispatchEvent(new PointerEvent(x.type,x))}}),this._canvasFloatDomService.addFloatDom(We);const dt=ce.onTransformChange$.subscribeEvent(()=>{const x=ae(ce,Z.renderUnit.scene,Q.skeleton,W.worksheet,le);Re.next(x)});this.disposeWithMe(v.subscribe(x=>{const Ee=Ze({startX:x.startX,startY:0,endX:x.endX,endY:x.endY,width:n.width,height:n.height,absolute:{left:f.absolute.left,top:f.absolute.top}},n),Be=B.getDrawingShapeKeyByDrawingSearch({unitId:N,subUnitId:O,drawingId:k}),je=new A.Rect(Be,{left:Ee.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(N,O).length-1}),lt=ae(je,Z.renderUnit.scene,Q.skeleton,W.worksheet,le);Re.next(lt)}));const ue=(I=this._renderManagerService.getRenderById(N))==null?void 0:I.with(b.SheetSkeletonManagerService);ue==null||ue.currentSkeleton$.subscribe(x=>{x&&c.sheetId!==x.sheetId&&this._removeDom(S,!0)}),re.add(()=>{this._canvasFloatDomService.removeFloatDom(k)}),dt&&re.add(dt),this._domLayerInfoMap.set(k,le)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(e,t,n){let{startRow:o,startColumn:s}=e;const a=Ne(o,s,n),d=new U.BehaviorSubject(a),g=Ne(e.endRow,e.endColumn,n),u=new U.BehaviorSubject(g),c=()=>{const v=Ne(o,s,n),_=Ne(e.endRow,e.endColumn,n);d.next(v),u.next(_)},m=new l.DisposableCollection;m.add(t.engine.clientRect$.subscribe(()=>c())),m.add(this._commandService.onCommandExecuted(v=>{if(v.id===C.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(D=>D.row===o)>-1){c();return}(C.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(v.id)>-1||v.id===b.SetScrollOperation.id||v.id===b.SetZoomRatioOperation.id)&&c()}));const h=(v,_)=>{o=v,s=_,c()},p=()=>({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}),S=d.pipe(U.map(v=>{const _=Ne(e.endRow,e.endColumn,n);return{rotate:0,width:_.right-v.left,height:_.bottom-v.top,absolute:{left:!0,top:!0},startX:v.left,startY:v.top,endX:_.right,endY:_.bottom}})),f=p();return{position$:S,position:f,updateRowCol:h,topLeftPos$:d,rightBottomPos$:u,disposable:m}}},M.SheetCanvasFloatDomManagerService=Tn([pe(0,l.Inject(A.IRenderManagerService)),pe(1,l.IUniverInstanceService),pe(2,l.Inject(l.ICommandService)),pe(3,B.IDrawingManagerService),pe(4,l.Inject(j.CanvasFloatDomService)),pe(5,w.ISheetDrawingService),pe(6,l.Inject(l.LifecycleService))],M.SheetCanvasFloatDomManagerService);function Ne(i,r,e){const t=e.getCellWithCoordByIndex(i,r),n=t.isMergedMainCell?t.mergeInfo:t;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Ze(i,r,e){var g,u;e=e!=null?e:1;const t=i.endX-i.startX,n=i.endY-i.startY,o=(g=r==null?void 0:r.width)!=null?g:t,s=(u=r==null?void 0:r.height)!=null?u:n;let a=0,d=0;if(r){if(r.horizonOffsetAlign==="right"){const c=Je(r.marginX,t*e);a=i.endX-c-o}else a=i.startX+Je(r.marginX,t);if(r.verticalOffsetAlign==="bottom"){const c=Je(r.marginY,n*e);d=i.endY-c-s}else d=i.startY+Je(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 Je(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const e=Number.parseFloat(i);return r*e/100}const Mn=i=>{const{floatDomInfos:r,scene:e,skeleton:t,worksheet:n}=i,o=q.useMemo(()=>r.map(s=>{const{width:a,height:d,angle:g,left:u,top:c}=s.transform,m=Lt({left:u!=null?u:0,right:(u!=null?u:0)+(a!=null?a:0),top:c!=null?c:0,bottom:(c!=null?c:0)+(d!=null?d:0)},e,t,n,void 0,!0),{scaleX:h,scaleY:p}=e.getAncestorScale(),S={startX:m.left,endX:m.right,startY:m.top,endY:m.bottom,rotate:g,width:a*h,height:d*p,absolute:m.absolute},f={position$:new U.BehaviorSubject(S),position:S,id:s.drawingId,componentKey:s.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:s.unitId,data:s.data};return[s.drawingId,f]}),[r,e,t,n]);return L.jsx("div",{style:{position:"absolute",top:0,left:0},children:o.map(([s,a])=>L.jsx(j.PrintFloatDomSingle,{layer:a,id:s,position:a.position},s))})};var Rn=Object.getOwnPropertyDescriptor,En=(i,r,e,t)=>{for(var n=t>1?void 0:t?Rn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Se=(i,r)=>(e,t)=>r(e,t,i);let Qe=class extends l.Disposable{constructor(i,r,e,t,n,o,s){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=e,this._renderManagerService=t,this._canvasFloatDomManagerService=n,this._componetManager=o,this._injector=s,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,e)=>{const{unitId:t,scene:n,subUnitId:o}=r,s=this._drawingManagerService.getDrawingDataForUnit(t),a=s==null?void 0:s[o];return a&&a.order.forEach(d=>{const g=a.data[d];g.drawingType!==l.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),e()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,e)=>{const{unitId:t,subUnitId:n}=r,o=this._renderManagerService.getRenderById(t);if(!o)return e(i);const s=o.with(b.SheetSkeletonManagerService).getSkeletonParam(n);if(!s)return e(i);const a=this._drawingManagerService.getDrawingDataForUnit(t),d=a==null?void 0:a[r.subUnitId];if(!d)return e(i);const{scaleX:g,scaleY:u}=o.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=d.order.map(h=>d.data[h]);return m.length?(m.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 p=s.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),S=s.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});p.column<c.startColumn&&(c.startColumn=p.column),p.row<c.startRow&&(c.startRow=p.row),c.endRow<S.row&&(c.endRow=S.row),c.endColumn<S.column&&(c.endColumn=S.column)}}),e(c)):e(i)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(i,r,e)=>{const{unitId:t,subUnitId:n}=r,o=this._drawingManagerService.getDrawingDataForUnit(t),s=o==null?void 0:o[n];if(s){const a=s.order.map(g=>{const u=s.data[g];if(u.drawingType===l.DrawingTypeEnum.DRAWING_CHART)return{...u,componentKey:this._componetManager.get(l.PRINT_CHART_COMPONENT_KEY)};if(u.drawingType===l.DrawingTypeEnum.DRAWING_DOM){const c=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(c||u.componentKey)}}return null}).filter(Boolean),d=j.connectInjector(Mn,this._injector);return Y.render(L.jsx(d,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),i==null||i.add(()=>{Y.unmount(r.root)}),e(i)}}}))}};Qe=En([Se(0,l.Inject(b.SheetPrintInterceptorService)),Se(1,l.Inject(ge.DrawingRenderService)),Se(2,B.IDrawingManagerService),Se(3,A.IRenderManagerService),Se(4,l.Inject(M.SheetCanvasFloatDomManagerService)),Se(5,l.Inject(j.ComponentManager)),Se(6,l.Inject(l.Injector))],Qe);var bn=Object.getOwnPropertyDescriptor,On=(i,r,e,t)=>{for(var n=t>1?void 0:t?bn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},me=(i,r)=>(e,t)=>r(e,t,i);const An=[C.InsertRowCommand.id,C.InsertColCommand.id,C.RemoveRowCommand.id,C.RemoveColCommand.id,C.DeleteRangeMoveLeftCommand.id,C.DeleteRangeMoveUpCommand.id,C.InsertRangeMoveDownCommand.id,C.InsertRangeMoveRightCommand.id,C.DeltaRowHeightCommand.id,C.SetRowHeightCommand.id,C.DeltaColumnWidthCommand.id,C.SetColWidthCommand.id,C.SetRowHiddenCommand.id,C.SetSpecificRowsVisibleCommand.id,C.SetSpecificColsVisibleCommand.id,C.SetColHiddenCommand.id,C.MoveColsCommand.id,C.MoveRowsCommand.id,C.MoveRangeCommand.id],Un=[C.SetRowVisibleMutation.id,C.SetRowHiddenMutation.id,C.SetColVisibleMutation.id,C.SetColHiddenMutation.id,C.SetWorksheetRowHeightMutation.id,C.SetWorksheetRowAutoHeightMutation.id,C.SetWorksheetRowIsAutoHeightMutation.id,C.SetWorksheetColWidthMutation.id];let yt=class extends l.Disposable{constructor(i,r,e,t,n,o,s,a,d){super(),this._context=i,this._renderManagerService=r,this._commandService=e,this._selectionRenderService=t,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.interceptAfterCommand({getMutations:i=>{if(!An.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===C.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([C.MoveColsCommand.id,C.MoveRowsCommand.id,C.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===C.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===C.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===C.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===C.DeleteRangeMoveLeftCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,0)}else if(r===C.DeleteRangeMoveUpCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,1)}else if(r===C.InsertRangeMoveDownCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,2)}else if(r===C.InsertRangeMoveRightCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,3)}else if(r===C.SetRowHiddenCommand.id||r===C.SetSpecificRowsVisibleCommand.id){const e=i.params,{unitId:t,subUnitId:n,ranges:o}=e;return this._getDrawingUndoForRowVisible(t,n,o)}else if(r===C.SetSpecificColsVisibleCommand.id||r===C.SetColHiddenCommand.id){const e=i.params,{unitId:t,subUnitId:n,ranges:o}=e;return this._getDrawingUndoForColVisible(t,n,o)}else if(r===C.DeltaRowHeightCommand.id||r===C.SetRowHeightCommand.id||r===C.DeltaColumnWidthCommand.id||r===C.SetColWidthCommand.id){const e=i.params,{unitId:t,subUnitId:n,ranges:o}=e,s=r===C.DeltaRowHeightCommand.id||r===C.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(t,n,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const e=C.getSheetCommandTarget(this._univerInstanceService);if(e==null)return{redos:[],undos:[]};const t=e.unitId,n=e.subUnitId,o=[],s=[],a=this._sheetDrawingService.getDrawingData(t,n),d=[],g=[];if(Object.keys(a).forEach(u=>{const c=a[u],{updateDrawings:m,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,c);d.push(...m),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:m,objects:h}=u;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:m,objects:h,type:w.DrawingApplyType.UPDATE}}),s.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:c,objects:h,type:w.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),c=u.undo,m=u.redo,h=u.objects;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:m,objects:h,type:w.DrawingApplyType.REMOVE}}),s.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:c,objects:h,type:w.DrawingApplyType.INSERT}})}return o.push({id:V.id,params:[t]}),s.push({id:V.id,params:[t]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,r,e){const t=[],n=[],{sheetTransform:o,anchorType:s=w.SheetDrawingAnchorType.Position,transform:a,unitId:d,subUnitId:g,drawingId:u}=e,{from:c,to:m}=o,{row:h,column:p}=c,{row:S,column:f}=m;if(o==null||a==null)return{updateDrawings:t,deleteDrawings:n};const{startRow:v,endRow:_,startColumn:D,endColumn:R}=i;let y=null,T=null;if(r===0&&h>=v&&S<=_)if(p>=D&&f<=R)n.push({unitId:d,subUnitId:g,drawingId:u});else{const I=this._shrinkCol(o,a,D,R,s);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===1&&p>=D&&f<=R)if(h>=v&&S<=_)n.push({unitId:d,subUnitId:g,drawingId:u});else{const I=this._shrinkRow(o,a,v,_,s);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===2){const I=this._expandRow(o,a,v,_,s);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===3){const I=this._expandCol(o,a,D,R,s);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}if(y!=null&&T!=null){const I=J(y,this._selectionRenderService,this._skeletonManagerService);t.push({...e,sheetTransform:y,transform:I})}return{updateDrawings:t,deleteDrawings:n}}_remainDrawingSize(i,r,e){const t=H({...i},this._selectionRenderService);t!=null&&r.push({...e,sheetTransform:t})}_getDrawingUndoForColVisible(i,r,e){const t=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(t).forEach(u=>{const c=t[u],{sheetTransform:m,transform:h,anchorType:p=w.SheetDrawingAnchorType.Position}=c;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:S,to:f}=m,{row:v,column:_}=S,{row:D,column:R}=f;for(let y=0;y<e.length;y++){const T=e[y],{startRow:I,endRow:N,startColumn:O,endColumn:k}=T;if(R<O)continue;if(p===w.SheetDrawingAnchorType.Position){let E=null,F=null;if(_>=O&&_<=k){const G=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:k,startRow:S.row,endRow:f.row});if(G==null)return;F={...h,left:G.startX}}if(F!=null&&(E=H(F,this._selectionRenderService),E!=null&&F!=null)){n.push({...c,sheetTransform:E,transform:F});break}this._remainDrawingSize(h,n,c);continue}if(_>=O&&R<=k)continue;let W=null,P=null;if(_>=O&&_<=k){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:k,startRow:S.row,endRow:f.row});if(E==null)return;P={...h,left:(E==null?void 0:E.startX)||0,width:((h==null?void 0:h.width)||0)-E.endX+E.startX}}else if(R>=O&&R<=k){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:R,startRow:S.row,endRow:f.row});if(E==null)return;P={...h,left:E.startX-((h==null?void 0:h.width)||0)}}else{const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:k,startRow:S.row,endRow:f.row});if(E==null)return;if(P={...h,width:((h==null?void 0:h.width)||0)-E.endX+E.startX},W=H(P,this._selectionRenderService),W!=null&&P!=null){o.push({...c,sheetTransform:W,transform:P});break}}if(P!=null&&(W=H(P,this._selectionRenderService)),P!=null&&W!=null){n.push({...c,sheetTransform:W,transform:P});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,e){const t=this._sheetDrawingService.getBatchUpdateOp(e),{undo:n,redo:o,objects:s}=t,a=[{id:w.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:s,type:w.DrawingApplyType.UPDATE}},{id:V.id,params:[i]}],d=[{id:w.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:s,type:w.DrawingApplyType.UPDATE}},{id:V.id,params:[i]}];return{redos:a,undos:d}}_getDrawingUndoForRowVisible(i,r,e){const t=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(t).forEach(u=>{const c=t[u],{sheetTransform:m,transform:h,anchorType:p=w.SheetDrawingAnchorType.Position}=c;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:S,to:f}=m,{row:v,column:_}=S,{row:D,column:R}=f;for(let y=0;y<e.length;y++){const T=e[y],{startRow:I,endRow:N,startColumn:O,endColumn:k}=T;if(D<I)continue;if(p===w.SheetDrawingAnchorType.Position){let E=null,F=null;if(v>=I&&v<=N){const G=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:v,endRow:N});if(G==null)return;F={...h,top:G.startY}}if(F!=null&&(E=H(F,this._selectionRenderService),E!=null&&F!=null)){n.push({...c,sheetTransform:E,transform:F});break}this._remainDrawingSize(h,n,c);continue}if(v>=I&&D<=N)continue;let W=null,P=null;if(v>=I&&v<=N){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:v,endRow:N});if(E==null)return;P={...h,top:(E==null?void 0:E.startY)||0,height:((h==null?void 0:h.height)||0)-E.endY+E.startY}}else if(D>=I&&D<=N){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:I,endRow:D});if(E==null)return;P={...h,top:E.startY-((h==null?void 0:h.height)||0)}}else{const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:I,endRow:N});if(E==null)return;if(P={...h,height:((h==null?void 0:h.height)||0)-E.endY+E.startY},W=H(P,this._selectionRenderService),W!=null&&P!=null){o.push({...c,sheetTransform:W,transform:P});break}}if(P!=null&&(W=H(P,this._selectionRenderService)),P!=null&&W!=null){n.push({...c,sheetTransform:W,transform:P});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,e,t){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(s=>{const a=n[s],{sheetTransform:d,transform:g,anchorType:u=w.SheetDrawingAnchorType.Position}=a;if(u===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,o,a);else{const{from:c,to:m}=d,{row:h,column:p}=c,{row:S,column:f}=m;for(let v=0;v<e.length;v++){const _=e[v],{startRow:D,endRow:R,startColumn:y,endColumn:T}=_;if(S<D||f<y)continue;if(u===w.SheetDrawingAnchorType.Position&&(h<=D&&S>=R||p<=y&&f>=T)){this._remainDrawingSize(g,o,a);continue}const I=J({...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 e,t;if(r==="insert")e=i.unitId,t=i.subUnitId;else{const n=C.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;e=n.unitId,t=n.subUnitId}return{unitId:e,subUnitId:t}}_moveRangeInterceptor(i){var D,R;const{toRange:r,fromRange:e}=i,t=C.getSheetCommandTarget(this._univerInstanceService);if(!t)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=t,s=(R=(D=this._renderManagerService.getRenderById(n))==null?void 0:D.with(b.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const a=b.attachRangeWithCoord(s,e);if(!a)return{redos:[],undos:[]};const{startX:d,endX:g,startY:u,endY:c}=a,m=this._sheetDrawingService.getDrawingData(n,o),h=[];Object.keys(m).forEach(y=>{const T=m[y];if(T.anchorType!==w.SheetDrawingAnchorType.Both)return;const{transform:I}=T;if(!I)return;const{left:N=0,top:O=0,width:k=0,height:W=0}=I,{drawingStartX:P,drawingEndX:E,drawingStartY:F,drawingEndY:G}={drawingStartX:N,drawingEndX:N+k,drawingStartY:O,drawingEndY:O+W};d<=P&&E<=g&&u<=F&&G<=c&&h.push(T)});const p=[],S=[],f=r.startRow-e.startRow,v=r.startColumn-e.startColumn,_=h.map(y=>{const T=y.sheetTransform,I={to:{...T.to,row:T.to.row+f,column:T.to.column+v},from:{...T.from,row:T.from.row+f,column:T.from.column+v}},N=J(I,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:y.drawingId,transform:N,sheetTransform:I}});if(_.length){const y=this._sheetDrawingService.getBatchUpdateOp(_),{undo:T,redo:I,objects:N}=y;p.push({id:w.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:I,objects:N,type:w.DrawingApplyType.UPDATE}}),S.push({id:w.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:T,objects:N,type:w.DrawingApplyType.UPDATE}})}return{redos:p,undos:S}}_moveRowInterceptor(i,r){const e=this._getUnitIdAndSubUnitId(i,r);if(e==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=e,{range:o}=i,s=o.startRow,a=o.endRow,d=[],g=[],u=this._sheetDrawingService.getDrawingData(t,n),c=[],m=[];if(Object.keys(u).forEach(h=>{const p=u[h],{sheetTransform:S,transform:f,anchorType:v=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let _,D;if(r==="insert"){const y=this._expandRow(S,f,s,a,v);_=y==null?void 0:y.newSheetTransform,D=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{row:I}=y,{row:N}=T;if(v===w.SheetDrawingAnchorType.Both&&I>=s&&N<=a)m.push({unitId:t,subUnitId:n,drawingId:h});else{const O=this._shrinkRow(S,f,s,a,v);_=O==null?void 0:O.newSheetTransform,D=O==null?void 0:O.newTransform}}if(!_||!D)return;const R={unitId:t,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};c.push(R)}),c.length===0&&m.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:p,redo:S,objects:f}=h;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),p=h.undo,S=h.redo,f=h.objects;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return d.push({id:V.id,params:[t]}),g.push({id:V.id,params:[t]}),{redos:d,undos:g}}_moveColInterceptor(i,r){const e=this._getUnitIdAndSubUnitId(i,r);if(e==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=e,{range:o}=i,s=o.startColumn,a=o.endColumn,d=[],g=[],u=this._sheetDrawingService.getDrawingData(t,n),c=[],m=[];if(Object.keys(u).forEach(h=>{const p=u[h],{sheetTransform:S,transform:f,anchorType:v=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let _,D;if(r==="insert"){const y=this._expandCol(S,f,s,a,v);_=y==null?void 0:y.newSheetTransform,D=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{column:I}=y,{column:N}=T;if(v===w.SheetDrawingAnchorType.Both&&I>=s&&N<=a)m.push({unitId:t,subUnitId:n,drawingId:h});else{const O=this._shrinkCol(S,f,s,a,v);_=O==null?void 0:O.newSheetTransform,D=O==null?void 0:O.newTransform}}if(!_||!D)return;const R={unitId:t,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};c.push(R)}),c.length===0&&m.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:p,redo:S,objects:f}=h;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),p=h.undo,S=h.redo,f=h.objects;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return d.push({id:V.id,params:[t]}),g.push({id:V.id,params:[t]}),{redos:d,undos:g}}_expandCol(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{column:d}=s,{column:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=e){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:e,endColumn:t,startRow:s.row,endRow:a.row});if(m==null)return;c={...r,left:(r.left||0)+m.endX-m.startX},u=H(c,this._selectionRenderService)}else if(g>=t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g+o}},c=J(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{column:d}=s,{column:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>t)u={from:{...s,column:d-o},to:{...a,column:g-o}},c=J(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=e&&g<=t)return null;if(d<e&&g>t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g-o}},c=J(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(d>=e&&d<=t){if(d===e)c={...r,left:(r.left||0)-i.from.columnOffset};else{const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:e,endColumn:d-1,startRow:s.row,endRow:a.row});if(m==null)return;c={...r,left:(r.left||0)-m.endX+m.startX-i.from.columnOffset}}u=H(c,this._selectionRenderService)}else if(g>=e&&g<=t&&n===w.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:e-1,endColumn:e-1,startRow:s.row,endRow:a.row});if(m==null)return;u={from:{...s},to:{...a,column:e-1,columnOffset:m.endX-m.startX}},c=J(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{row:d}=s,{row:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=e){const m=this._skeletonManagerService.attachRangeWithCoord({startRow:e,endRow:t,startColumn:s.column,endColumn:a.column});if(m==null)return;c={...r,top:(r.top||0)+m.endY-m.startY},u=H(c,this._selectionRenderService)}else if(g>=t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g+o}},c=J(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{row:d}=s,{row:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>t)u={from:{...s,row:d-o},to:{...a,row:g-o}},c=J(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=e&&g<=t)return null;if(d<e&&g>t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g-o}},c=J(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(d>=e&&d<=t){if(d===e)c={...r,top:(r.top||0)-i.from.rowOffset};else{const m=this._skeletonManagerService.attachRangeWithCoord({startRow:e,endRow:d-1,startColumn:s.column,endColumn:a.column});if(m==null)return;c={...r,top:(r.top||0)-m.endY+m.startY-i.from.rowOffset}}u=H(c,this._selectionRenderService)}else if(g>=e&&g<=t&&n===w.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:e-1,endRow:e-1});if(m==null)return;u={from:{...s},to:{...a,row:e-1,rowOffset:m.endY-m.startY}},c=J(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===C.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:e}=i.params;this._updateDrawings(r,e)}})),this.disposeWithMe(this._context.activated$.subscribe(i=>{const{unit:r,unitId:e}=this._context;if(i){const t=r.getActiveSheet().getSheetId();this._updateDrawings(e,t)}else this._clearDrawings(e)}))}_clearDrawings(i){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,e=[];Object.keys(r).forEach(t=>{const n=r[t];n!=null&&Object.keys(n).forEach(o=>{const s=n[o].data;s!=null&&Object.keys(s).forEach(a=>{t===i&&e.push(s[a])})})}),this._sheetDrawingService.removeNotification(e),this._drawingManagerService.removeNotification(e)})}_updateDrawings(i,r){setTimeout(()=>{const e=this._drawingManagerService.drawingManagerData,t=[],n=[];Object.keys(e).forEach(o=>{const s=e[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=J(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),t.push(d[g])}else n.push(d[g])})})}),this._sheetDrawingService.removeNotification(n),this._sheetDrawingService.addNotification(t),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(t)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Un.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,e=C.getSheetCommandTarget(this._univerInstanceService,r);if(!e)return;const{unitId:t,subUnitId:n,worksheet:o}=e;let s=[];"ranges"in r?s=r.ranges:"rowsAutoHeightInfo"in r&&(s=r.rowsAutoHeightInfo.map(a=>({startRow:a.row,endRow:a.row,startColumn:0,endColumn:o.getColumnCount()-1}))),this._refreshDrawingTransform(t,n,s)})}))}_refreshDrawingTransform(i,r,e){const t=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(t).forEach(o=>{const s=t[o],{sheetTransform:a,transform:d,anchorType:g=w.SheetDrawingAnchorType.Position}=s;if(g===w.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=a,{row:m,column:h}=u,{row:p,column:S}=c;for(let f=0;f<e.length;f++){const v=e[f],{startRow:_,endRow:D,startColumn:R,endColumn:y}=v;if(l.Rectangle.intersects({startRow:_,endRow:D,startColumn:R,endColumn:y},{startRow:m,endRow:p,startColumn:h,endColumn:S})||m>D||h>y){const T=g===w.SheetDrawingAnchorType.Position,I=J(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._sheetDrawingService.refreshTransform(n),this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(V.id,[i]))}};yt=On([me(1,A.IRenderManagerService),me(2,l.ICommandService),me(3,b.ISheetSelectionRenderService),me(4,l.Inject(b.SheetSkeletonManagerService)),me(5,l.Inject(C.SheetInterceptorService)),me(6,w.ISheetDrawingService),me(7,B.IDrawingManagerService),me(8,l.IUniverInstanceService)],yt);function Pn(){const i=j.useDependency(l.LocaleService),r=j.useDependency(j.IDialogService),e=j.useDependency($e),[t,n]=q.useState([he.CELL_ADDRESS]),[o,s]=q.useState(!1),[a,d]=q.useState(null),g=q.useMemo(()=>e.getCellImagesInSelection(),[e]),u=q.useMemo(()=>e.getDataColumns(),[e]),c=q.useMemo(()=>e.getSelectionRowRange(),[e]),m=u.length>0,h=q.useMemo(()=>u.map(T=>({label:T.label,value:String(T.index)})),[u]),[p,S]=q.useState(()=>h.length>0?h[0].value:"0"),f=q.useMemo(()=>{if(!t.includes(he.COLUMN_VALUE)||!c)return[];const I=Number(p);return[{startRow:c.startRow,endRow:c.endRow,startColumn:I,endColumn:I}]},[t,p,c]);b.useHighlightRange(f);const v=q.useCallback(T=>{T.length!==0&&n(T)},[]),_=q.useCallback(T=>{S(String(T))},[]),D=q.useCallback(()=>{r.close(_e)},[r]),R=q.useCallback(async()=>{if(g.length!==0){s(!0),d(null);try{await e.saveImages(g,{fileNameParts:t,columnIndex:t.includes(he.COLUMN_VALUE)?Number(p):void 0}),r.close(_e)}catch(T){console.error("Failed to save images:",T),d(i.t("sheetImage.save.error"))}finally{s(!1)}}},[e,g,t,p,r,i]),y=t.includes(he.COLUMN_VALUE);return L.jsxs("div",{className:"univer-flex univer-flex-col",children:[L.jsx(Y.FormLayout,{label:i.t("sheetImage.save.imageCount"),children:L.jsx("div",{className:"univer-text-sm univer-text-gray-600",children:g.length})}),L.jsx(Y.FormLayout,{label:i.t("sheetImage.save.fileNameConfig"),children:L.jsxs(Y.CheckboxGroup,{value:t,onChange:v,direction:"vertical",children:[L.jsx(Y.Checkbox,{value:he.CELL_ADDRESS,disabled:!m,children:i.t("sheetImage.save.useRowCol")}),m&&L.jsx(Y.Checkbox,{value:he.COLUMN_VALUE,children:i.t("sheetImage.save.useColumnValue")})]})}),y&&L.jsx(Y.FormLayout,{label:i.t("sheetImage.save.selectColumn"),children:L.jsx(Y.Select,{value:p,options:h,onChange:_})}),a&&L.jsx("div",{className:"univer-text-xs univer-text-red-500",children:a}),L.jsxs("div",{className:"univer-flex univer-justify-end univer-gap-2 univer-border-t univer-border-gray-200 univer-pt-3",children:[L.jsx(Y.Button,{onClick:D,disabled:o,children:i.t("sheetImage.save.cancel")}),L.jsx(Y.Button,{variant:"primary",onClick:R,disabled:o||g.length===0,children:o?i.t("sheetImage.save.saving"):i.t("sheetImage.save.confirm")})]})]})}const $t=i=>{var _;const r=j.useDependency(l.ICommandService),e=j.useDependency(l.LocaleService),t=j.useDependency(B.IDrawingManagerService),n=j.useDependency(A.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,m]=q.useState(!0),h=(_=s.anchorType)!=null?_:w.SheetDrawingAnchorType.Position,[p,S]=q.useState(h);function f(D,R){const y=[];return D.forEach(T=>{const{oKey:I}=T,N=R.getDrawingOKey(I);if(N==null)return y.push(null),!0;const{unitId:O,subUnitId:k,drawingId:W,drawingType:P,anchorType:E,sheetTransform:F}=N;y.push({unitId:O,subUnitId:k,drawingId:W,anchorType:E,sheetTransform:F,drawingType:P})}),y}q.useEffect(()=>{const D=u.clearControl$.subscribe(y=>{y===!0&&m(!1)}),R=u.changeStart$.subscribe(y=>{var N;const{objects:T}=y,I=f(T,t);if(I.length===0)m(!1);else if(I.length>=1){m(!0);const O=((N=I[0])==null?void 0:N.anchorType)||w.SheetDrawingAnchorType.Position;S(O)}});return()=>{R.unsubscribe(),D.unsubscribe()}},[]);function v(D){S(D);const R=t.getFocusDrawings();if(R.length===0)return;const y=R.map(T=>({unitId:T.unitId,subUnitId:T.subUnitId,drawingId:T.drawingId,anchorType:D}));r.executeCommand(we.id,{unitId:R[0].unitId,drawings:y})}return L.jsxs("div",{className:Y.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!c}),children:[L.jsx("header",{className:"univer-text-gray-600 dark:!univer-text-gray-200",children:L.jsx("div",{children:e.t("drawing-anchor.title")})}),L.jsx("div",{children:L.jsxs(Y.RadioGroup,{value:p,onChange:v,direction:"vertical",children:[L.jsx(Y.Radio,{value:w.SheetDrawingAnchorType.Both,children:e.t("drawing-anchor.both")}),L.jsx(Y.Radio,{value:w.SheetDrawingAnchorType.Position,children:e.t("drawing-anchor.position")}),L.jsx(Y.Radio,{value:w.SheetDrawingAnchorType.None,children:e.t("drawing-anchor.none")})]})})]})},Nn=()=>{const i=j.useDependency(B.IDrawingManagerService),r=i.getFocusDrawings(),[e,t]=q.useState(r);return q.useEffect(()=>{const n=i.focus$.subscribe(o=>{t(o)});return()=>{n.unsubscribe()}},[]),!!(e!=null&&e.length)&&L.jsxs("div",{className:"univer-text-sm",children:[L.jsx(ge.DrawingCommonPanel,{drawings:e}),L.jsx($t,{drawings:e})]})},Dt="sheet.menu.image";function kn(i){return{id:Dt,type:j.MenuItemType.SUBITEMS,icon:"AddImageIcon",tooltip:"sheetImage.title",hidden$:j.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),disabled$:b.getCurrentRangeDisable$(i,{workbookTypes:[C.WorkbookEditablePermission],worksheetTypes:[C.WorksheetEditPermission],rangeTypes:[C.RangeProtectionPermissionEditPoint]})}}function Wn(i){return{id:Oe.id,title:"sheetImage.upload.float",type:j.MenuItemType.BUTTON,hidden$:j.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function Bn(i){return{id:St.id,title:"sheetImage.upload.cell",type:j.MenuItemType.BUTTON,hidden$:j.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function jn(i){var r,e,t,n;return!!((e=(r=i==null?void 0:i.p)==null?void 0:r.drawingsOrder)!=null&&e.length&&((n=(t=i==null?void 0:i.p)==null?void 0:t.drawingsOrder)==null?void 0:n.length)>0)}function Fn(i,r){const e=i.getActiveSheet();if(!e)return!1;const t=e.getCellMatrix(),{startRow:n,endRow:o,startColumn:s,endColumn:a}=r;for(let d=n;d<=o;d++)for(let g=s;g<=a;g++){const u=t.getValue(d,g);if(jn(u))return!0}return!1}function Ln(){return"showDirectoryPicker"in window}function Tt(i){const r=i.get(l.IUniverInstanceService),e=i.get(C.SheetsSelectionsService),t=U.combineLatest([j.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),r.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(U.switchMap(n=>n?e.selectionMoveEnd$.pipe(U.map(()=>{if(!Ln())return!0;const o=e.getCurrentSelections();if(!o||o.length===0)return!0;for(const s of o)if(Fn(n,s.range))return!1;return!0})):U.of(!0)))]).pipe(U.map(([n,o])=>n||o));return{id:Ie.id,type:j.MenuItemType.BUTTON,icon:"DownloadImageIcon",title:"sheetImage.save.menuLabel",hidden$:t}}const $n={[j.RibbonInsertGroup.MEDIA]:{[Dt]:{order:0,menuItemFactory:kn,[Oe.id]:{order:0,menuItemFactory:Wn},[St.id]:{order:1,menuItemFactory:Bn}}},[j.ContextMenuPosition.MAIN_AREA]:{[j.ContextMenuGroup.OTHERS]:{[Ie.id]:{order:10,menuItemFactory:Tt}}},[j.ContextMenuPosition.COL_HEADER]:{[j.ContextMenuGroup.OTHERS]:{[Ie.id]:{order:10,menuItemFactory:Tt}}},[j.ContextMenuPosition.ROW_HEADER]:{[j.ContextMenuGroup.OTHERS]:{[Ie.id]:{order:10,menuItemFactory:Tt}}}};function ke(i){return i.getContextValue(l.FOCUSING_SHEET)&&!i.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(l.FOCUSING_PANEL_EDITOR)&&i.getContextValue(l.FOCUSING_COMMON_DRAWINGS)&&!i.getContextValue(l.FOCUSING_SHAPE_TEXT_EDITOR)}const Yn={id:ve.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:j.KeyCode.ARROW_DOWN,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.DOWN}},Gn={id:ve.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:j.KeyCode.ARROW_UP,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.UP}},Hn={id:ve.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:j.KeyCode.ARROW_LEFT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.LEFT}},Vn={id:ve.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:j.KeyCode.ARROW_RIGHT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.RIGHT}},Xn={id:ut.id,description:"shortcut.drawing-delete",group:"4_drawing-view",priority:100,preconditions:ke,binding:j.KeyCode.DELETE,mac:j.KeyCode.BACKSPACE};var xn=Object.getOwnPropertyDescriptor,Kn=(i,r,e,t)=>{for(var n=t>1?void 0:t?xn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},ye=(i,r)=>(e,t)=>r(e,t,i);let et=class extends l.Disposable{constructor(i,r,e,t,n,o){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=e,this._shortcutService=t,this._drawingManagerService=n,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Pt,Nn)),this.disposeWithMe(i.register(_e,Pn))}_initMenus(){this._menuManagerService.mergeMenu($n)}_initCommands(){[Oe,St,be,fe,we,vt,V,_t,gt,mt,ve,ut,ht,Ie].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[Yn,Gn,Hn,Vn,Xn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};et=Kn([ye(0,l.Inject(j.ComponentManager)),ye(1,j.IMenuManagerService),ye(2,l.ICommandService),ye(3,j.IShortcutService),ye(4,B.IDrawingManagerService),ye(5,l.Inject(C.SheetsSelectionsService))],et);var zn=Object.defineProperty,qn=Object.getOwnPropertyDescriptor,Zn=(i,r,e)=>r in i?zn(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e,Jn=(i,r,e,t)=>{for(var n=t>1?void 0:t?qn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Mt=(i,r)=>(e,t)=>r(e,t,i),Yt=(i,r,e)=>Zn(i,typeof r!="symbol"?r+"":r,e);const Qn="SHEET_IMAGE_UI_PLUGIN";M.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=Nt,e,t,n){super(),this._config=r,this._injector=e,this._renderManagerService=t,this._configService=n;const{menu:o,...s}=l.merge({},Nt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(nn,s)}onStarting(){l.registerDependencies(this._injector,[[M.SheetCanvasFloatDomManagerService],[et],[Ge],[Qe],[qe],[ze],[Xe],[xe],[Ke],[$e,{useClass:M.BatchSaveImagesService}]]),l.touchDependencies(this._injector,[[M.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[ze],[Ke]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[qe],[Qe],[et],[Xe],[xe]])}onSteady(){this._injector.get(Ge)}_registerRenderModules(){[[M.SheetDrawingUpdateController],[yt],[Ct],[It]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}},Yt(M.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),Yt(M.UniverSheetsDrawingUIPlugin,"pluginName",Qn),M.UniverSheetsDrawingUIPlugin=Jn([l.DependentOn(B.UniverDrawingPlugin,bt.UniverDocsDrawingPlugin,ge.UniverDrawingUIPlugin,w.UniverSheetsDrawingPlugin),Mt(1,l.Inject(l.Injector)),Mt(2,A.IRenderManagerService),Mt(3,l.IConfigService)],M.UniverSheetsDrawingUIPlugin),M.ClearSheetDrawingTransformerOperation=V,M.DeleteDrawingsCommand=ut,M.EditSheetDrawingOperation=_t,M.FileNamePart=he,M.GroupSheetDrawingCommand=gt,M.IBatchSaveImagesService=$e,M.InsertFloatImageCommand=Oe,M.InsertSheetDrawingCommand=be,M.MoveDrawingsCommand=ve,M.RemoveSheetDrawingCommand=fe,M.SHEETS_IMAGE_MENU_ID=Dt,M.SHEET_FLOAT_DOM_PREFIX=Ft,M.SaveCellImagesCommand=Ie,M.SetDrawingArrangeCommand=ht,M.SetSheetDrawingCommand=we,M.SheetDrawingAnchor=$t,M.SidebarSheetDrawingOperation=vt,M.UngroupSheetDrawingCommand=mt,M.calcSheetFloatDomPosition=ae,M.drawingPositionToTransform=J,M.transformToDrawingPosition=H,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})}));
14
+ (function(b,P){typeof exports=="object"&&typeof module<"u"?P(exports,require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("@univerjs/core"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets"),require("@univerjs/design"),require("@univerjs/docs-ui"),require("@univerjs/drawing"),require("@univerjs/ui"),require("@univerjs/docs-drawing"),require("@univerjs/drawing-ui"),require("rxjs"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/engine-render","@univerjs/sheets-ui","@univerjs/core","@univerjs/sheets-drawing","@univerjs/sheets","@univerjs/design","@univerjs/docs-ui","@univerjs/drawing","@univerjs/ui","@univerjs/docs-drawing","@univerjs/drawing-ui","rxjs","react/jsx-runtime","react"],P):(b=typeof globalThis<"u"?globalThis:b||self,P(b.UniverSheetsDrawingUi={},b.UniverEngineRender,b.UniverSheetsUi,b.UniverCore,b.UniverSheetsDrawing,b.UniverSheets,b.UniverDesign,b.UniverDocsUi,b.UniverDrawing,b.UniverUi,b.UniverDocsDrawing,b.UniverDrawingUi,b.rxjs,b.React,b.React))})(this,(function(b,P,U,l,w,y,H,Le,B,j,Ot,he,W,$,Z){"use strict";var ir=Object.defineProperty;var or=(b,P,U)=>P in b?ir(b,P,{enumerable:!0,configurable:!0,writable:!0,value:U}):b[P]=U;var oe=(b,P,U)=>or(b,typeof P!="symbol"?P+"":P,U);function ee(i,r,e){const{from:t,to:n,flipY:o=!1,flipX:s=!1,angle:a=0,skewX:c=0,skewY:g=0}=i,u=e.getCurrent();if(u==null)return;const d=U.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:t,to:n},e);let{left:m,top:h,width:p,height:S}=d;const f=e.getCurrentSkeleton(),v=f.rowHeaderWidth+f.columnTotalWidth,I=f.columnHeaderHeight+f.rowTotalHeight;return m+p>v&&(m=v-p),h+S>I&&(h=I-S),{flipY:o,flipX:s,angle:a,skewX:c,skewY:g,left:m,top:h,width:p,height:S}}function x(i,r){const{left:e=0,top:t=0,width:n=0,height:o=0,flipY:s=!1,flipX:a=!1,angle:c=0,skewX:g=0,skewY:u=0}=i,d=r.getCellWithCoordByOffset(e,t);if(d==null)return;const m={column:d.actualColumn,columnOffset:P.precisionTo(e-d.startX,1),row:d.actualRow,rowOffset:P.precisionTo(t-d.startY,1)},h=r.getCellWithCoordByOffset(e+n,t+o);if(h==null)return;const p={column:h.actualColumn,columnOffset:P.precisionTo(e+n-h.startX,1),row:h.actualRow,rowOffset:P.precisionTo(t+o-h.startY,1)};return{flipY:s,flipX:a,angle:c,skewX:g,skewY:u,from:m,to:p}}function G(i,r){const{left:e=0,top:t=0,width:n=0,height:o=0,angle:s=0}=i,a=(s%360+360)%360;if(!(a>=45&&a<135||a>=225&&a<315))return x(i,r);const g={...i,left:e+n/2-o/2,top:t+o/2-n/2,width:o,height:n};return x(g,r)}const V={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(i,r)=>{const e=i.get(P.IRenderManagerService);return r.forEach(t=>{var n,o;(o=(n=e.getRenderById(t))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},we={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var I,D,O;const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(y.SheetInterceptorService),o=i.get(w.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,a=[];s.forEach(T=>{const{unitId:C}=T;a.push(C)});const c=o.getBatchRemoveOp(s),{unitId:g,subUnitId:u,undo:d,redo:m,objects:h}=c,p=n.onCommandExecute({id:we.id,params:r}),S={id:w.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:m,objects:h,type:w.DrawingApplyType.REMOVE}},f={id:w.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:d,objects:h,type:w.DrawingApplyType.INSERT}};return l.sequenceExecute([...(I=p.preRedos)!=null?I:[],S,...p.redos],e)?(t.pushUndoRedo({unitID:g,undoMutations:[...(D=p.preUndos)!=null?D:[],f,...p.undos,{id:V.id,params:a}],redoMutations:[...(O=p.preRedos)!=null?O:[],S,...p.redos,{id:V.id,params:a}]}),!0):!1}},gt={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),t=i.get(w.ISheetDrawingService).getFocusDrawings();if(t.length===0)return!1;const n=t[0].unitId,o=t.map(s=>{const{unitId:a,subUnitId:c,drawingId:g,drawingType:u}=s;return{unitId:a,subUnitId:c,drawingId:g,drawingType:u}});return r.executeCommand(we.id,{unitId:n,drawings:o})}};function zt(i){const r=[];return i.forEach(e=>{const{parent:t,children:n}=e,{unitId:o,subUnitId:s,drawingId:a}=t,c=P.getGroupState(0,0,n.map(d=>d.transform||{})),g=n.map(d=>{const m=d.transform||{left:0,top:0},{unitId:h,subUnitId:p,drawingId:S}=d;return{unitId:h,subUnitId:p,drawingId:S,transform:{...m,left:m.left-c.left,top:m.top-c.top},groupId:a}}),u={unitId:o,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:c};r.push({parent:u,children:g})}),r}function qt(i){const r=[];return i.forEach(e=>{const{parent:t,children:n}=e,{unitId:o,subUnitId:s,drawingId:a,transform:c={width:0,height:0}}=t;if(c==null)return;const g=n.map(d=>{const{transform:m}=d,{unitId:h,subUnitId:p,drawingId:S}=d,f=P.transformObjectOutOfGroup(m||{},c,c.width||0,c.height||0);return{unitId:h,subUnitId:p,drawingId:S,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:g})}),r}const ht={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:p})=>{o.push(h.unitId),p.forEach(S=>{o.push(S.unitId)})});const s=n.getGroupDrawingOp(r),{unitId:a,subUnitId:c,undo:g,redo:u,objects:d}=s;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:c,objects:d,type:w.DrawingApplyType.GROUP})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:c,objects:qt(d),type:w.DrawingApplyType.UNGROUP}},{id:V.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:d,type:w.DrawingApplyType.GROUP}},{id:V.id,params:o}]}),!0):!1}},Oe={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var I,D,O;const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService),o=i.get(y.SheetInterceptorService);if(!r)return!1;const s=r.drawings,a=s.map(T=>T.unitId),c=n.getBatchAddOp(s),{unitId:g,subUnitId:u,undo:d,redo:m,objects:h}=c,p=o.onCommandExecute({id:Oe.id,params:r}),S={id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:g,subUnitId:u,objects:h,type:w.DrawingApplyType.INSERT}},f={id:w.SetDrawingApplyMutation.id,params:{op:d,unitId:g,subUnitId:u,objects:h,type:w.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(I=p.preRedos)!=null?I:[],S,...p.redos],e)?(t.pushUndoRedo({unitID:g,undoMutations:[...(D=p.preUndos)!=null?D:[],f,...p.undos,{id:V.id,params:a}],redoMutations:[...(O=p.preRedos)!=null?O:[],S,...p.redos,{id:V.id,params:a}]}),!0):!1}},mt={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService);if(!r)return!1;const n=i.get(w.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:a,arrangeType:c}=r,g={unitId:o,subUnitId:s,drawingIds:a};let u;if(c===l.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):c===l.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):c===l.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):c===l.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:d,redo:m,undo:h}=u;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:m,unitId:o,subUnitId:s,objects:d,type:w.DrawingApplyType.ARRANGE})?(t.pushUndoRedo({unitID:o,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:s,objects:d,type:w.DrawingApplyType.ARRANGE}}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:s,objects:d,type:w.DrawingApplyType.ARRANGE}}]}),!0):!1}},ve={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var v,I;const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService),o=i.get(y.SheetInterceptorService);if(!r)return!1;const{drawings:s}=r,a=n.getBatchUpdateOp(s),{unitId:c,subUnitId:g,undo:u,redo:d,objects:m}=a,h=o.onCommandExecute({id:ve.id,params:r}),p=[...(v=h.preRedos)!=null?v:[],{id:w.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:g,op:d,objects:m,type:w.DrawingApplyType.UPDATE}},...h.redos,{id:V.id,params:[c]}],S=[...(I=h.preUndos)!=null?I:[],{id:w.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:g,op:u,objects:m,type:w.DrawingApplyType.UPDATE}},...h.undos,{id:V.id,params:[c]}];return l.sequenceExecute(p,e)?(t.pushUndoRedo({unitID:c,undoMutations:S,redoMutations:p}),!0):!1}},pt={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:p})=>{o.push(h.unitId),p.forEach(S=>{o.push(S.unitId)})});const s=n.getUngroupDrawingOp(r),{unitId:a,subUnitId:c,undo:g,redo:u,objects:d}=s;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:c,objects:d,type:w.DrawingApplyType.UNGROUP})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:c,objects:zt(d),type:w.DrawingApplyType.GROUP}},{id:V.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:d,type:w.DrawingApplyType.UNGROUP}},{id:V.id,params:o}]}),!0):!1}};var Zt=Object.getOwnPropertyDescriptor,Jt=(i,r,e,t)=>{for(var n=t>1?void 0:t?Zt(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},ne=(i,r)=>(e,t)=>r(e,t,i);function Qt(i,r,e){const t=e*Math.PI/180,n=Math.abs(i*Math.cos(t))+Math.abs(r*Math.sin(t)),o=Math.abs(i*Math.sin(t))+Math.abs(r*Math.cos(t));return{rotatedWidth:n,rotatedHeight:o}}function St(i,r,e,t,n){var I;const{rotatedHeight:o,rotatedWidth:s}=Qt(e,t,n),c=i.get(P.IRenderManagerService).getRenderById(r.unitId);if(!c)return!1;const u=(I=c.with(U.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:I.skeleton;if(u==null)return!1;const d=u.getCellByIndex(r.row,r.col),m=d.mergeInfo.endX-d.mergeInfo.startX-2,h=d.mergeInfo.endY-d.mergeInfo.startY-2,p=s/o,f=Math.ceil(Math.min(m,h*p))/s,v=!f||Number.isNaN(f)?.001:f;return{width:e*v,height:t*v}}b.SheetDrawingUpdateController=class extends l.Disposable{constructor(e,t,n,o,s,a,c,g,u,d,m,h,p,S){super();oe(this,"_workbookSelections");this._context=e,this._skeletonManagerService=t,this._commandService=n,this._selectionRenderService=o,this._imageIoService=s,this._fileOpenerService=a,this._sheetDrawingService=c,this._drawingManagerService=g,this._contextService=u,this._messageService=d,this._localeService=m,this._injector=p,this._urlImageService=S,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const e=await this._fileOpenerService.openFile({multiple:!0,accept:B.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),t=e.length;return t>B.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:H.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(B.DRAWING_IMAGE_COUNT_LIMIT))}),!1):t===0?!1:(e.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const t=(await this._fileOpenerService.openFile({multiple:!1,accept:B.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return t?(await this._insertCellImage(t),!0):!1}insertCellImageByFile(e,t){return this._insertCellImage(e,t)}async insertFloatImageByFile(e){var O;let t;try{t=await this._imageIoService.saveImage(e)}catch(T){const C=T.message;C===B.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:H.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(B.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===B.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:H.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===B.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:H.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(t==null)return;const n=this._getUnitInfo(),{unitId:o,subUnitId:s}=n,{imageId:a,imageSourceType:c,source:g,base64Cache:u}=t,{width:d,height:m,image:h}=await B.getImageSize(u||""),{width:p,height:S}=this._context.scene;this._imageIoService.addImageSourceCache(g,c,h);let f=1;if(d>B.DRAWING_IMAGE_WIDTH_LIMIT||m>B.DRAWING_IMAGE_HEIGHT_LIMIT){const T=B.DRAWING_IMAGE_WIDTH_LIMIT/d,C=B.DRAWING_IMAGE_HEIGHT_LIMIT/m;f=Math.max(T,C)}const v=this._getImagePosition(d*f,m*f,p,S);if(v==null)return;const I=ee(v,this._selectionRenderService,this._skeletonManagerService),D={unitId:o,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c,source:g,transform:I,sheetTransform:v,axisAlignSheetTransform:(O=G(I,this._selectionRenderService))!=null?O:v};return this._commandService.executeCommand(Oe.id,{unitId:o,drawings:[D]})}async _insertCellImage(e,t){var O,T;let n;try{n=await this._imageIoService.saveImage(e)}catch(C){const M=C.message;M===B.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:H.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(B.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):M===B.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:H.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):M===B.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:H.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:o,imageSourceType:s,source:a,base64Cache:c}=n,{width:g,height:u,image:d}=await B.getImageSize(c||"");this._imageIoService.addImageSourceCache(a,s,d);const m=this._workbookSelections.getCurrentLastSelection();if(!m)return!1;let h=m.primary.actualRow,p=m.primary.actualColumn;m.primary.isMerged&&(h=m.primary.startRow,p=m.primary.startColumn);const S=l.createDocumentModelWithStyle("",{}),f=St(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:h,col:p},g,u,0);if(!f)return!1;const v={size:{width:f.width,height:f.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},I={unitId:S.getUnitId(),subUnitId:S.getUnitId(),drawingId:o,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:Le.docDrawingPositionToTransform(v),docTransform:v,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},D=l.BuildTextUtils.drawing.add({documentDataModel:S,drawings:[I],selection:{collapsed:!0,startOffset:0,endOffset:0}});return D?(S.apply(D),this._commandService.syncExecuteCommand(y.SetRangeValuesCommand.id,{value:{[(O=t==null?void 0:t.row)!=null?O:h]:{[(T=t==null?void 0:t.col)!=null?T:p]:{p:S.getSnapshot(),t:1}}},unitId:t==null?void 0:t.unitId,subUnitId:t==null?void 0:t.subUnitId})):!1}async insertCellImageByUrl(e,t){var p,S;let n=e;try{n=await this._urlImageService.getImage(e)}catch(f){console.error(`Failed to get image from URLImageService: ${e}`,f)}const{width:o,height:s,image:a}=await B.getImageSize(n||"");this._imageIoService.addImageSourceCache(e,l.ImageSourceType.URL,a);const c=this._workbookSelections.getCurrentLastSelection();if(!c)return!1;const g=l.createDocumentModelWithStyle("",{}),u=St(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:c.primary.actualRow,col:c.primary.actualColumn},o,s,0);if(!u)return!1;const d={size:{width:u.width,height:u.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},m={unitId:g.getUnitId(),subUnitId:g.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:e,transform:Le.docDrawingPositionToTransform(d),docTransform:d,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},h=l.BuildTextUtils.drawing.add({documentDataModel:g,drawings:[m],selection:{collapsed:!0,startOffset:0,endOffset:0}});return h?(g.apply(h),this._commandService.syncExecuteCommand(y.SetRangeValuesCommand.id,{value:{[(p=t==null?void 0:t.row)!=null?p:c.primary.actualRow]:{[(S=t==null?void 0:t.col)!=null?S:c.primary.actualColumn]:{p:g.getSnapshot(),t:1}}},unitId:t==null?void 0:t.unitId,subUnitId:t==null?void 0:t.subUnitId})):!1}_getUnitInfo(){const e=this._context.unit,t=e.getActiveSheet(),n=e.getUnitId(),o=t.getSheetId();return{unitId:n,subUnitId:o}}_getImagePosition(e,t,n,o){const s=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};s&&s.length>0&&(a=s[s.length-1].range);const c=U.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(c==null)return;let{startColumn:g,startRow:u,startX:d,startY:m}=c,h=!1;if(d+e>n&&(d=n-e,d<0&&(d=0,e=n),h=!0),m+t>o&&(m=o-t,m<0&&(m=0,t=o),h=!0),h){const v=this._selectionRenderService.getCellWithCoordByOffset(d,m);if(v==null)return;d=v.startX,m=v.startY,g=v.actualColumn,u=v.actualRow}const p={column:g,columnOffset:0,row:u,rowOffset:0},S=this._selectionRenderService.getCellWithCoordByOffset(d+e,m+t);if(S==null)return;const f={column:S.actualColumn,columnOffset:d+e-S.startX,row:S.actualRow,rowOffset:m+t-S.startY};return{from:p,to:f}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{const{unitId:t,subUnitId:n,drawingIds:o,arrangeType:s}=e;this._commandService.executeCommand(mt.id,{unitId:t,subUnitId:n,drawingIds:o,arrangeType:s})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{const t=[];e.length!==0&&(e.forEach(n=>{const{unitId:o,subUnitId:s,drawingId:a,drawingType:c,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:a});if(u==null||u.unitId!==this._context.unitId)return;const d=x({...u.transform,...g},this._selectionRenderService),m=G({...u.transform,...g},this._selectionRenderService);if(d==null||m==null)return;const h={...n,transform:{...u.transform,...g,...ee(d,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...d},axisAlignSheetTransform:{...m}};t.push(h)}),t.length>0&&this._commandService.executeCommand(ve.id,{unitId:e[0].unitId,drawings:t}))}))}_getSheetTransformByParam(e){const{unitId:t,subUnitId:n,drawingId:o,transform:s}=e;if(s==null)return null;const a=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:n,drawingId:o});if(a==null||a.unitId!==this._context.unitId)return null;const c=x({...a.transform,...s},this._selectionRenderService),g=G({...a.transform,...s},this._selectionRenderService);return c==null||g==null?null:{sheetTransform:c,axisAlignSheetTransform:g}}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{const t=[];for(const n of e){const o=this._getSheetTransformByParam(n.parent),s=[];for(const c of n.children){const g=this._getSheetTransformByParam(c);g!=null&&s.push({...c,sheetTransform:g.sheetTransform,axisAlignSheetTransform:g.axisAlignSheetTransform})}const a={parent:{...n.parent,sheetTransform:o},children:s};t.push(a)}if(t.length>0){this._commandService.executeCommand(ht.id,t);const{unitId:n,subUnitId:o,drawingId:s}=e[0].parent;this._commandService.syncExecuteCommand(B.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:o,drawingId:s}])}})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{const t=[];for(const n of e){const{children:o}=n,s=[];for(const a of o){const c=this._getSheetTransformByParam(a);c!=null&&s.push({...a,sheetTransform:c})}t.push({...n,children:s})}this._commandService.executeCommand(pt.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}},b.SheetDrawingUpdateController=Jt([ne(1,l.Inject(U.SheetSkeletonManagerService)),ne(2,l.ICommandService),ne(3,U.ISheetSelectionRenderService),ne(4,B.IImageIoService),ne(5,j.ILocalFileService),ne(6,w.ISheetDrawingService),ne(7,B.IDrawingManagerService),ne(8,l.IContextService),ne(9,j.IMessageService),ne(10,l.Inject(l.LocaleService)),ne(11,l.Inject(y.SheetsSelectionsService)),ne(12,l.Inject(l.Injector)),ne(13,l.IURLImageService)],b.SheetDrawingUpdateController);const Ae={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{var s,a;const e=i.get(l.IUniverInstanceService),t=i.get(P.IRenderManagerService),n=(s=P.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,e,t))==null?void 0:s.with(b.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const c=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(c)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},ft={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:i=>{var t,n;const r=i.get(l.IUniverInstanceService),e=i.get(P.IRenderManagerService);return(n=(t=P.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,r,e))==null?void 0:t.with(b.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}},_e={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(w.ISheetDrawingService),n=i.get(U.ISheetSelectionRenderService),{direction:o}=r,s=t.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 m={...d},{left:h=0,top:p=0}=d;return o===l.Direction.UP?m.top=p-1:o===l.Direction.DOWN?m.top=p+1:o===l.Direction.LEFT?m.left=h-1:o===l.Direction.RIGHT&&(m.left=h+1),{...u,transform:m,sheetTransform:x(m,n),axisAlignSheetTransform:G(m,n)}}).filter(u=>u!=null);return e.syncExecuteCommand(ve.id,{unitId:a,drawings:c})?(e.syncExecuteCommand(V.id,[a]),!0):!1}};var en=Object.getOwnPropertyDescriptor,tn=(i,r,e,t)=>{for(var n=t>1?void 0:t?en(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},$e=(i,r)=>(e,t)=>r(e,t,i),me=(i=>(i.CELL_ADDRESS="cellAddress",i.COLUMN_VALUE="columnValue",i))(me||{});const Ye=l.createIdentifier("sheets-drawing-ui.batch-save-images.service");function wt(i){let r="",e=i;for(;e>=0;)r=String.fromCharCode(e%26+65)+r,e=Math.floor(e/26)-1;return r}function xe(i,r){return`${wt(r)}${i+1}`}function nn(i){const r=xe(i.startRow,i.startColumn),e=xe(i.endRow,i.endColumn);return r===e?r:`${r}:${e}`}function At(i){var r,e,t,n;return!!((e=(r=i==null?void 0:i.p)==null?void 0:r.drawingsOrder)!=null&&e.length&&((n=(t=i==null?void 0:i.p)==null?void 0:t.drawingsOrder)==null?void 0:n.length)>0)}function Ut(i){var t,n,o;if(!((n=(t=i.p)==null?void 0:t.drawingsOrder)!=null&&n.length)||!((o=i.p)!=null&&o.drawings))return null;const r=i.p.drawingsOrder[0],e=i.p.drawings[r];return!e||!("source"in e)||!("imageSourceType"in e)?null:e}function vt(i,r){if(r===l.ImageSourceType.BASE64){const e=i.match(/^data:image\/(\w+);/);if(e)return e[1]==="jpeg"?"jpg":e[1]}if(r===l.ImageSourceType.URL){const e=i.match(/\.(\w+)(?:\?|$)/);if(e)return e[1].toLowerCase()}return"png"}async function Pt(i,r){if(r===l.ImageSourceType.BASE64)return(await fetch(i)).blob();if(r===l.ImageSourceType.URL)return(await fetch(i)).blob();throw new Error("UUID image type requires additional handling")}b.BatchSaveImagesService=class extends l.Disposable{constructor(r,e,t,n){super(),this._univerInstanceService=r,this._selectionService=e,this._imageIoService=t,this._urlImageService=n}registerURLImageDownloader(r){return this._urlImageService.registerURLImageDownloader(r)}getCellImagesInSelection(){const r=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!r)return[];const e=r.getActiveSheet();if(!e)return[];const t=this._selectionService.getCurrentSelections();if(!t||t.length===0)return[];const n=e.getCellMatrix(),o=[];for(const s of t){const{startRow:a,endRow:c,startColumn:g,endColumn:u}=s.range;for(let d=a;d<=c;d++)for(let m=g;m<=u;m++){const h=n.getValue(d,m);if(At(h)){const p=Ut(h);p&&o.push({row:d,col:m,cellAddress:xe(d,m),source:p.source,imageSourceType:p.imageSourceType,imageId:p.drawingId})}}}return o}getCellImagesFromRanges(r,e,t){const n=this._univerInstanceService.getUnit(r,l.UniverInstanceType.UNIVER_SHEET);if(!n)return[];const o=n.getSheetBySheetId(e);if(!o)return[];const s=o.getCellMatrix(),a=[];for(const c of t){const{startRow:g,endRow:u,startColumn:d,endColumn:m}=c;for(let h=g;h<=u;h++)for(let p=d;p<=m;p++){const S=s.getValue(h,p);if(At(S)){const f=Ut(S);f&&a.push({row:h,col:p,cellAddress:xe(h,p),source:f.source,imageSourceType:f.imageSourceType,imageId:f.drawingId})}}}return a}getDataColumns(){var m,h,p,S;const r=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!r)return[];const e=r.getActiveSheet();if(!e)return[];const t=this._selectionService.getCurrentSelections();if(!t||t.length===0)return[];const n=e.getCellMatrix(),o=n.getDataRange();let s=1/0,a=-1/0;const c=new Set;for(const f of t){s=Math.min(s,f.range.startRow),a=Math.max(a,f.range.endRow);for(let v=f.range.startColumn;v<=f.range.endColumn;v++)c.add(v)}const g=new Set;for(let f=o.startColumn;f<=o.endColumn;f++)if(!c.has(f))for(let v=s;v<=a;v++){const I=n.getValue(v,f);if(I&&(((m=I.v)==null?void 0:m.toString())||((S=(p=(h=I.p)==null?void 0:h.body)==null?void 0:p.dataStream)==null?void 0:S.trim())||"")){g.add(f);break}}const u=[],d=Array.from(g).sort((f,v)=>f-v);for(const f of d)u.push({index:f,label:wt(f)});return u}getDataColumnsForRanges(r,e,t){var p,S,f,v;const n=this._univerInstanceService.getUnit(r,l.UniverInstanceType.UNIVER_SHEET);if(!n)return[];const o=n.getSheetBySheetId(e);if(!o)return[];const s=o.getCellMatrix(),a=s.getDataRange();let c=1/0,g=-1/0;const u=new Set;for(const I of t){c=Math.min(c,I.startRow),g=Math.max(g,I.endRow);for(let D=I.startColumn;D<=I.endColumn;D++)u.add(D)}const d=new Set;for(let I=a.startColumn;I<=a.endColumn;I++)if(!u.has(I))for(let D=c;D<=g;D++){const O=s.getValue(D,I);if(O&&(((p=O.v)==null?void 0:p.toString())||((v=(f=(S=O.p)==null?void 0:S.body)==null?void 0:f.dataStream)==null?void 0:v.trim())||"")){d.add(I);break}}const m=[],h=Array.from(d).sort((I,D)=>I-D);for(const I of h)m.push({index:I,label:wt(I)});return m}getSelectionRangeNotation(){const r=this._selectionService.getCurrentSelections();return!r||r.length===0?"":r.map(e=>nn(e.range)).join(", ")}getSelectionRowRange(){const r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return null;let e=1/0,t=-1/0;for(const n of r)e=Math.min(e,n.range.startRow),t=Math.max(t,n.range.endRow);return{startRow:e,endRow:t}}getSelectionColumnIndices(){const r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return new Set;const e=new Set;for(const t of r)for(let n=t.range.startColumn;n<=t.range.endColumn;n++)e.add(n);return e}generateFileName(r,e){var s,a,c,g;const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),n=vt(r.source,r.imageSourceType),o=[];for(const u of e.fileNameParts)if(u==="cellAddress")o.push(r.cellAddress);else if(u==="columnValue"&&e.columnIndex!==void 0){const d=t==null?void 0:t.getActiveSheet();if(d){const h=d.getCellMatrix().getValue(r.row,e.columnIndex);if(h){const p=((s=h.v)==null?void 0:s.toString())||((g=(c=(a=h.p)==null?void 0:a.body)==null?void 0:c.dataStream)==null?void 0:g.trim())||"";if(p){const S=p.replace(/[<>:"/\\|?*]/g,"_").trim();S&&o.push(S)}}}}return o.length===0?`${r.cellAddress}.${n}`:`${o.join("_")}.${n}`}generateFileNameWithContext(r,e,t,n){var c,g,u,d;const o=this._univerInstanceService.getUnit(t,l.UniverInstanceType.UNIVER_SHEET),s=vt(r.source,r.imageSourceType),a=[];for(const m of e.fileNameParts)if(m==="cellAddress")a.push(r.cellAddress);else if(m==="columnValue"&&e.columnIndex!==void 0){const h=o==null?void 0:o.getSheetBySheetId(n);if(h){const S=h.getCellMatrix().getValue(r.row,e.columnIndex);if(S){const f=((c=S.v)==null?void 0:c.toString())||((d=(u=(g=S.p)==null?void 0:g.body)==null?void 0:u.dataStream)==null?void 0:d.trim())||"";if(f){const v=f.replace(/[<>:"/\\|?*]/g,"_").trim();v&&a.push(v)}}}}return a.length===0?`${r.cellAddress}.${s}`:`${a.join("_")}.${s}`}async saveImages(r,e){var o;const t=await window.showDirectoryPicker({mode:"readwrite"}),n=new Map;for(const s of r){let a=this.generateFileName(s,e);const c=a.replace(/\.\w+$/,""),g=((o=a.match(/\.\w+$/))==null?void 0:o[0])||".png",u=n.get(c)||0;u>0&&(a=`${c}_${u}${g}`),n.set(c,u+1);try{const d=await this._getImageBlob(s),h=await(await t.getFileHandle(a,{create:!0})).createWritable();await h.write(d),await h.close()}catch(d){throw console.error(`Failed to save image ${a}:`,d),d}}}async saveImagesWithContext(r,e,t,n){var a;const o=await window.showDirectoryPicker({mode:"readwrite"}),s=new Map;for(const c of r){let g=this.generateFileNameWithContext(c,e,t,n);const u=g.replace(/\.\w+$/,""),d=((a=g.match(/\.\w+$/))==null?void 0:a[0])||".png",m=s.get(u)||0;m>0&&(g=`${u}_${m}${d}`),s.set(u,m+1);try{const h=await this._getImageBlob(c),S=await(await o.getFileHandle(g,{create:!0})).createWritable();await S.write(h),await S.close()}catch(h){throw console.error(`Failed to save image ${g}:`,h),h}}}async downloadSingleImage(r){const e=vt(r.source,r.imageSourceType),t=`${r.cellAddress}.${e}`;try{const n=await this._getImageBlob(r),o=URL.createObjectURL(n),s=document.createElement("a");s.href=o,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(o)}catch(n){throw console.error(`Failed to download image ${t}:`,n),n}}async _getImageBlob(r){if(r.imageSourceType===l.ImageSourceType.UUID){const e=await this._imageIoService.getImage(r.source);return Pt(e,l.ImageSourceType.URL)}return r.imageSourceType===l.ImageSourceType.URL?this._urlImageService.downloadImage(r.source):Pt(r.source,r.imageSourceType)}},b.BatchSaveImagesService=tn([$e(0,l.IUniverInstanceService),$e(1,l.Inject(y.SheetsSelectionsService)),$e(2,l.IImageIoService),$e(3,l.IURLImageService)],b.BatchSaveImagesService);const Ie="sheet.dialog.batch-save-images",ye={id:"sheet.command.save-cell-images",type:l.CommandType.COMMAND,handler:async i=>{const r=i.get(j.IDialogService),e=i.get(Ye),t=e.getCellImagesInSelection();if(t.length===1)try{return await e.downloadSingleImage(t[0]),!0}catch(a){return console.error("Failed to download image:",a),!1}const n=i.get(l.LocaleService),o=e.getSelectionRangeNotation(),s=`${n.t("sheetImage.save.title")} (${o})`;return r.open({id:Ie,draggable:!0,width:360,title:{title:s},children:{label:Ie},destroyOnClose:!0,preservePositionOnDestroy:!0,onClose:()=>r.close(Ie)}),!0}},Nt="COMPONENT_SHEET_DRAWING_PANEL",_t={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{const e=i.get(j.ISidebarService),t=i.get(l.LocaleService),n=i.get(l.IUniverInstanceService),o=i.get(l.ICommandService);return y.getSheetCommandTarget(n)?(r.value==="open"?e.open({header:{title:t.t("sheetImage.panel.title")},children:{label:Nt},onClose:()=>{o.syncExecuteCommand(B.SetDrawingSelectedOperation.id,[])},width:360}):e.close(),!0):!1}},It={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(i,r)=>{const e=i.get(l.ICommandService);return r==null?!1:(e.syncExecuteCommand(B.SetDrawingSelectedOperation.id,[r]),e.executeCommand(_t.id,{value:"open"}),!0)}},rn="sheets-drawing-ui.config",kt={};var on=Object.getOwnPropertyDescriptor,sn=(i,r,e,t)=>{for(var n=t>1?void 0:t?on(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},ae=(i,r)=>(e,t)=>r(e,t,i);let Ge=class extends l.RxDisposable{constructor(r,e,t,n,o,s,a,c,g,u){super();oe(this,"_initImagePopupMenu",new Set);this._injector=r,this._localeService=e,this._drawingManagerService=t,this._canvasPopManagerService=n,this._renderManagerService=o,this._univerInstanceService=s,this._messageService=a,this._contextService=c,this._ioService=g,this._commandService=u,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._setupLoadingStatus()}_setupLoadingStatus(){const r="image-upload-loading";let e;this.disposeWithMe(this._ioService.change$.subscribe(t=>{t>0&&!e?e=this._messageService.show({id:r,type:H.MessageType.Loading,content:`${this._localeService.t("uploadLoading.loading")}: ${t}`,duration:0}):t===0&&(e==null||e.dispose(),e=void 0)}))}_dispose(r){super.dispose();const e=r.getUnitId();this._renderManagerService.removeRender(e),this._initImagePopupMenu.delete(e)}_create(r){if(!r)return;const e=r.getUnitId();this._renderManagerService.has(e)&&!this._initImagePopupMenu.has(e)&&(this._popupMenuListener(e),this._initImagePopupMenu.add(e))}_hasCropObject(r){const e=r.getAllObjectsByOrder();for(const t of e)if(t instanceof he.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const e=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!e)return;const t=e.getTransformerByCreate();if(!t)return;let n;this.disposeWithMe(t.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(e))return;const s=t.getSelectedObjectMap();if(s.size>1){n==null||n.dispose();return}const a=s.values().next().value;if(!a)return;const c=a.oKey,g=this._drawingManagerService.getDrawingOKey(c);if(!g)return;const{unitId:u,subUnitId:d,drawingId:m,drawingType:h}=g,p=g.data;if(p&&p.disablePopup)return;n==null||n.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,d,m,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:he.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,d,m,h)}}))})),this.disposeWithMe(t.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(B.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(s=>{s[l.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(t.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,e,t,n){return[{label:"image-popup.edit",index:0,commandId:It.id,commandParams:{unitId:r,subUnitId:e,drawingId:t},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:we.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:e,drawingId:t}]},disable:!1},{label:"image-popup.crop",index:2,commandId:he.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:e,drawingId:t},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:he.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:e,drawingId:t}],disable:n===l.DrawingTypeEnum.DRAWING_DOM}]}};Ge=sn([ae(0,l.Inject(l.Injector)),ae(1,l.Inject(l.LocaleService)),ae(2,B.IDrawingManagerService),ae(3,l.Inject(U.SheetCanvasPopManagerService)),ae(4,P.IRenderManagerService),ae(5,l.IUniverInstanceService),ae(6,j.IMessageService),ae(7,l.IContextService),ae(8,l.IImageIoService),ae(9,l.ICommandService)],Ge);var an=Object.getOwnPropertyDescriptor,cn=(i,r,e,t)=>{for(var n=t>1?void 0:t?an(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},He=(i,r)=>(e,t)=>r(e,t,i);let yt=class extends l.Disposable{constructor(r,e,t,n,o){super();oe(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=e,this._selectionsService=t,this._drawingRenderService=n,this._sheetSkeletonManagerService=o,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(W.throttleTime(33)).subscribe(r=>{var t,n;let e=[];r!==null&&(e=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),e.length>0&&(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&e.length===1&&((t=e[0].primary)==null?void 0:t.actualRow)===r.row&&((n=e[0].primary)==null?void 0:n.actualColumn)===r.col?(this._isSetCursor=!0,this._context.scene.setCursor(P.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(r=>{var e;if(r!=null&&r.drawing&&this._isSetCursor){const t=r.drawing.drawing.drawingOrigin,n=(e=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:e.imageCacheMap.getImage(t.imageSourceType,t.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};yt=cn([He(1,l.Inject(U.HoverManagerService)),He(2,l.Inject(y.SheetsSelectionsService)),He(3,l.Inject(he.DrawingRenderService)),He(4,l.Inject(U.SheetSkeletonManagerService))],yt);var dn=Object.getOwnPropertyDescriptor,ln=(i,r,e,t)=>{for(var n=t>1?void 0:t?dn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ve=(i,r)=>(e,t)=>r(e,t,i);let Ct=class extends l.Disposable{constructor(i,r,e,t,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=e,this._sheetSelectionRenderService=t,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 e=i[r];for(const t in e.data){const n=e.data[t];n.sheetTransform&&(n.transform=ee(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService))}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};Ct=ln([Ve(1,w.ISheetDrawingService),Ve(2,B.IDrawingManagerService),Ve(3,l.Inject(U.ISheetSelectionRenderService)),Ve(4,l.Inject(U.SheetSkeletonManagerService))],Ct);var un=Object.getOwnPropertyDescriptor,gn=(i,r,e,t)=>{for(var n=t>1?void 0:t?un(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ce=(i,r)=>(e,t)=>r(e,t,i);function Wt(i,r,e){var t,n,o,s;if(((n=(t=e==null?void 0:e.p)==null?void 0:t.body)==null?void 0:n.dataStream.length)===3&&((s=(o=e.p)==null?void 0:o.drawingsOrder)==null?void 0:s.length)===1){const a=e.p.drawings[e.p.drawingsOrder[0]],c=St(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,e.p.documentStyle.pageSize.width=1/0,e.p.documentStyle.pageSize.height=1/0,!0}return!1}let Xe=class extends l.Disposable{constructor(i,r,e,t,n,o){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=e,this._drawingManagerService=t,this._docDrawingController=n,this._editorBridgeService=o,this._handleInitEditor(),this._initCellContentInterceptor()}_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===Le.ReplaceSnapshotCommand.id&&i.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(y.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:y.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,e)=>{var t;return i!=null&&i.p&&((t=i.p.drawingsOrder)!=null&&t.length)&&(i===r.rawData&&(i={...r.rawData}),i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0},Wt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),e(i)}}))}};Xe=gn([Ce(0,l.ICommandService),Ce(1,l.Inject(y.SheetInterceptorService)),Ce(2,l.Inject(l.Injector)),Ce(3,B.IDrawingManagerService),Ce(4,l.Inject(Ot.DocDrawingController)),Ce(5,l.Inject(U.IEditorBridgeService))],Xe);var hn=Object.getOwnPropertyDescriptor,mn=(i,r,e,t)=>{for(var n=t>1?void 0:t?hn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Bt=(i,r)=>(e,t)=>r(e,t,i);let Ke=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,e,t)=>{new l.ObjectMatrix(t).forValue((n,o,s)=>{Wt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},s)})}}))}};Ke=mn([Bt(0,l.Inject(y.IAutoFillService)),Bt(1,l.Inject(l.Injector))],Ke);var pn=Object.getOwnPropertyDescriptor,Sn=(i,r,e,t)=>{for(var n=t>1?void 0:t?pn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ue=(i,r)=>(e,t)=>r(e,t,i);const fn=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,l.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let ze=class extends l.Disposable{constructor(i,r,e,t,n){super(),this._commandService=i,this._univerInstanceService=r,this._dialogService=e,this._renderManagerService=t,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(i){var n;const r=l.createDocumentModelWithStyle("",{}),e=(n=P.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(U.EditingRenderController),t=l.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[i],selection:{collapsed:!0,startOffset:0,endOffset:0}});t&&(r.apply(t),e&&e.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(i=>{var r,e;if(i.id===Le.InnerPasteCommand.id){const t=i.params,{doc:n}=t,o=this._univerInstanceService.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_DOC);if(o==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const s=o.getUnitId();if(fn.includes(s)){if(s!==l.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const a=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(U.SetCellEditVisibleOperation.id,{visible:!1})};((e=o.getBody())==null?void 0:e.dataStream)===`\r
15
+ `?(this._commandService.syncExecuteCommand(U.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(n.drawings)[0])):this._dialogService.open({id:"sheet-cell-image-copy-paste",title:{label:this._localeService.t("cell-image.pasteTitle")},children:{label:this._localeService.t("cell-image.pasteContent")},width:320,destroyOnClose:!0,onClose:a,showOk:!0,showCancel:!0,onOk:()=>{a(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:a})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};ze=Sn([Ue(0,l.ICommandService),Ue(1,l.IUniverInstanceService),Ue(2,j.IDialogService),Ue(3,P.IRenderManagerService),Ue(4,l.Inject(l.LocaleService))],ze);var wn=Object.getOwnPropertyDescriptor,vn=(i,r,e,t)=>{for(var n=t>1?void 0:t?wn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Pe=(i,r)=>(e,t)=>r(e,t,i);const jt="image/png";function _n(i){const r=i.split(","),e=atob(r[1]),t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return new Blob([n],{type:jt})}function In(i){const r=new ClipboardItem({[jt]:_n(i)});navigator.clipboard.write([r]).catch(e=>{console.error("Could not copy image using clipboard API: ",e)})}function yn(){function i(){const t=document.createElement("input");return t.style.position="absolute",t.style.height="1px",t.style.width="1px",t.style.opacity="0",t}const r=document.activeElement,e=i();return document.body.appendChild(e),e.focus(),()=>{e.blur(),document.body.removeChild(e),r instanceof HTMLElement&&r.focus()}}const Ft=[U.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,U.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,U.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,U.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA];let qe=class extends l.Disposable{constructor(r,e,t,n,o){super();oe(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=e,this._drawingService=t,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,e,t,n)=>{this._copyInfo=null;const o=this._focusedDrawings;if(o.length>0){const[s]=o;if(s.drawingType!==l.DrawingTypeEnum.DRAWING_IMAGE)return;if(n===U.COPY_TYPE.CUT){const c={unitId:r,drawings:[s]};this._commandService.executeCommand(we.id,c)}setTimeout(()=>{const c=yn();s.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&s.imageSourceType===B.ImageSourceType.BASE64?In(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,e,t);this._copyInfo=s}},onPasteCells:(r,e,t,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=U.COPY_TYPE.COPY,pasteType:s}=n,{range:a}=r||{},{range:c,unitId:g,subUnitId:u}=e;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:s,unitId:g,subUnitId:u,pasteRange:c},{copyRange:a,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:e,pasteType:s},U.COPY_TYPE.COPY)},onPastePlainText:(r,e)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:U.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},U.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,e)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:U.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},U.COPY_TYPE.COPY);{const t=e.filter(n=>n.type.includes("image"));if(t.length)return{undos:[],redos:[{id:Ae.id,params:{files:t}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,e,t){var m;const n=(m=this._renderManagerService.getRenderById(r))==null?void 0:m.with(U.SheetSkeletonManagerService);if(!n)return;const o=n.attachRangeWithCoord(t);if(!o)return;const{startX:s,endX:a,startY:c,endY:g}=o,u=this._drawingService.getDrawingData(r,e),d=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const p=u[h];if(p.drawingType!==l.DrawingTypeEnum.DRAWING_IMAGE)return;const{transform:S}=p;if(p.anchorType!==w.SheetDrawingAnchorType.Both||!S)return;const{left:f=0,top:v=0,width:I=0,height:D=0}=S,{drawingStartX:O,drawingEndX:T,drawingStartY:C,drawingEndY:M}={drawingStartX:f,drawingEndX:f+I,drawingStartY:v,drawingEndY:v+D};s<=O&&T<=a&&c<=C&&M<=g&&d.push(p)}),d.length)return{copyRange:t,drawings:d,unitId:r,subUnitId:e}}_generateSingleDrawingPasteMutations(r,e){const{pasteType:t,pasteTo:n}=r;if(Ft.includes(t))return{redos:[],undos:[]};const{unitId:o,subUnitId:s,range:a}=n,c=this._renderManagerService.getRenderById(o),g=c==null?void 0:c.with(U.SheetSkeletonManagerService),u=c==null?void 0:c.with(U.ISheetSelectionRenderService),d=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:m}=d,h=y.discreteRangeToRange(a);return this._generateMutations(m,{unitId:o,subUnitId:s,isCut:e===U.COPY_TYPE.CUT,getTransform:(p,S)=>{var I,D;const f=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),v={...p,left:f==null?void 0:f.startX,top:f==null?void 0:f.startY};return{transform:v,sheetTransform:(I=x(v,u))!=null?I:S,axisAlignSheetTransform:(D=G(v,u))!=null?D:S}}})}_generateMutations(r,e){const{unitId:t,subUnitId:n,getTransform:o,isCut:s}=e,a=[],c=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:d,sheetTransform:m}=u;if(!d)return;const h=o(d,m),p={...u,unitId:t,subUnitId:n,drawingId:s?u.drawingId:l.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform,axisAlignSheetTransform:h.axisAlignSheetTransform};if(s){const{undo:S,redo:f,objects:v}=g.getBatchUpdateOp([p]);a.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:w.DrawingApplyType.UPDATE,op:f,objects:v}}),c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:w.DrawingApplyType.UPDATE,op:S,objects:v}})}else{const{undo:S,redo:f,objects:v}=g.getBatchAddOp([p]);a.push({id:w.SetDrawingApplyMutation.id,params:{op:f,unitId:t,subUnitId:n,objects:v,type:w.DrawingApplyType.INSERT}}),c.push({id:w.SetDrawingApplyMutation.id,params:{op:S,unitId:t,subUnitId:n,objects:v,type:w.DrawingApplyType.REMOVE}})}}),{redos:a,undos:c}}_generateRangeDrawingsPasteMutations(r,e){var R;const{unitId:t,subUnitId:n,pasteType:o,pasteRange:s}=r,{copyRange:a,copyType:c}=e;if(Ft.includes(o))return{redos:[],undos:[]};const g=(R=this._renderManagerService.getRenderById(t))==null?void 0:R.with(U.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:t,subUnitId:n,range:y.discreteRangeToRange(s)},pasteType:o},c);const{ranges:[d,m],mapFunc:h}=U.virtualizeDiscreteRanges([a,s]),{row:p,col:S}=h(d.startRow,d.startColumn),{row:f,col:v}=h(m.startRow,m.startColumn),I=g.attachRangeWithCoord({startRow:p,endRow:p,startColumn:S,endColumn:S}),D=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:v,endColumn:v});if(!I||!D||!this._copyInfo)return{redos:[],undos:[]};const O=D.startX-I.startX,T=D.startY-I.startY,C=f-p,M=v-S;return this._generateMutations(u,{unitId:t,subUnitId:n,getTransform:(k,A)=>{var F,L,Q;const N={...k,left:((F=k==null?void 0:k.left)!=null?F:0)+O,top:((L=k==null?void 0:k.top)!=null?L:0)+T},_=this._renderManagerService.getRenderById(t),E=_==null?void 0:_.with(U.ISheetSelectionRenderService);return E?{transform:N,sheetTransform:{...A,to:{...A.to,row:A.to.row+C,column:A.to.column+M},from:{...A.from,row:A.from.row+C,column:A.from.column+M}},axisAlignSheetTransform:(Q=G(N,E))!=null?Q:A}:{transform:N,sheetTransform:{...A,to:{...A.to,row:A.to.row+C,column:A.to.column+M},from:{...A.from,row:A.from.row+C,column:A.from.column+M}},axisAlignSheetTransform:{...A,to:{...A.to,row:A.to.row+C,column:A.to.column+M},from:{...A.from,row:A.from.row+C,column:A.from.column+M}}}},isCut:c===U.COPY_TYPE.CUT})}};qe=vn([Pe(0,U.ISheetClipboardService),Pe(1,P.IRenderManagerService),Pe(2,B.IDrawingManagerService),Pe(3,j.IClipboardInterfaceService),Pe(4,l.ICommandService)],qe);var Cn=Object.getOwnPropertyDescriptor,Dn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Cn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ne=(i,r)=>(e,t)=>r(e,t,i);let Ze=class extends l.Disposable{constructor(i,r,e,t,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=e,this._univerInstanceService=t,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$,e=W.combineLatest([i,r]);this.disposeWithMe(e.pipe(W.switchMap(([t,n])=>t?t.activeSheet$.pipe(W.tap(o=>{if(!o){this._drawingManagerService.setDrawingVisible(!1);return}const s=t.getUnitId(),a=o.getSheetId();this._permissionService.composePermission([new y.WorkbookViewPermission(s).id,new y.WorksheetViewPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(t,o)})):(this._drawingManagerService.setDrawingVisible(!1),W.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(i,r){this._drawingManagerService.setDrawingVisible(!1);const e=i.getUnitId(),t=r.getSheetId(),n=this._drawingManagerService.getDrawingData(e,t),o=Object.values(n),s=this._renderManagerService.getRenderById(e),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===P.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$,e=W.combineLatest([i,r]);this.disposeWithMe(e.pipe(W.switchMap(([t,n])=>t?t.activeSheet$.pipe(W.tap(o=>{if(!o){this._drawingManagerService.setDrawingEditable(!1);return}const s=t.getUnitId(),a=o.getSheetId();this._permissionService.composePermission([new y.WorkbookEditablePermission(s).id,new y.WorksheetEditPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(t,o)})):(this._drawingManagerService.setDrawingEditable(!1),W.EMPTY))).subscribe())}_handleDrawingEditableFalse(i,r){this._drawingManagerService.setDrawingEditable(!1);const e=i.getUnitId(),t=r.getSheetId(),n=this._drawingManagerService.getDrawingData(e,t),o=Object.values(n),s=this._renderManagerService.getRenderById(e),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===P.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(W.combineLatest([i,r]).pipe(W.switchMap(([e,t])=>e?e.activeSheet$.pipe(W.switchMap(n=>{if(!n)return W.EMPTY;const o=e.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),c=a==null?void 0:a.scene;if(!c)return W.EMPTY;const g=c.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookViewPermission(o).id,new y.WorksheetViewPermission(o,s).id]).pipe(W.map(d=>d.every(m=>m.value)),W.distinctUntilChanged()).pipe(W.map(d=>({permission:d,scene:c,transformer:g,unitId:o,subUnitId:s})))})):W.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:o,subUnitId:s})=>{this._drawingManagerService.setDrawingVisible(e);const a=t.getAllObjectsByOrder(),c=this._drawingManagerService.getDrawingData(o,s),g=Object.values(c);e?this._drawingManagerService.addNotification(g):(a.forEach(u=>{u.classType===P.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&t.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const e=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),t=e==null?void 0:e.getActiveSheet(),n=e==null?void 0:e.getUnitId(),o=t==null?void 0:t.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(W.combineLatest([i,r]).pipe(W.switchMap(([e,t])=>e?e.activeSheet$.pipe(W.switchMap(n=>{if(!n)return W.EMPTY;const o=e.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),c=a==null?void 0:a.scene;if(!c)return W.EMPTY;const g=c.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookEditablePermission(o).id,new y.WorksheetEditPermission(o,s).id]).pipe(W.map(d=>d.every(m=>m.value)),W.distinctUntilChanged()).pipe(W.map(d=>({permission:d,scene:c,transformer:g,unitId:o,subUnitId:s})))})):W.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:o,subUnitId:s})=>{this._drawingManagerService.setDrawingEditable(e);const a=t.getAllObjectsByOrder(),c=this._drawingManagerService.getDrawingData(o,s),g=Object.values(c);e?(a.forEach(u=>{u.classType===P.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&t.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(a.forEach(u=>{u.classType===P.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&t.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const e=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!e)return;const t=e.getUnitId(),n=e.getActiveSheet();if(!n)return;const o=n.getSheetId(),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;const c=this._drawingManagerService.getDrawingData(t,o),g=Object.values(c);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(d=>{d.classType===P.RENDER_CLASS_TYPE.IMAGE&&g.some(m=>d.oKey.includes(m.drawingId))&&a.detachTransformerFrom(d)})}}))}};Ze=Dn([Ne(0,B.IDrawingManagerService),Ne(1,P.IRenderManagerService),Ne(2,l.IPermissionService),Ne(3,l.IUniverInstanceService),Ne(4,l.Inject(l.UserManagerService))],Ze);var Tn=Object.getOwnPropertyDescriptor,Mn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Tn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Se=(i,r)=>(e,t)=>r(e,t,i);const Lt="univer-sheet-float-dom-";function $t(i,r,e,t,n,o=!1){const{scaleX:s,scaleY:a}=r.getAncestorScale(),c=r.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=t.getFreeze(),{startColumn:u,startRow:d,xSplit:m,ySplit:h}=g,p={left:!0,top:!0};if(!c)return{...i,absolute:p};const{left:S,right:f,top:v,bottom:I}=i;let{top:D,left:O,viewportScrollX:T,viewportScrollY:C}=c;const{boundsOfViewArea:M,scrollDirectionResponse:R}=n||{},{rowHeaderWidth:k,columnHeaderHeight:A}=e,N={top:o?0:A,left:o?0:k};M&&(l.Tools.isDefine(N.top)&&(N.top=M.top),l.Tools.isDefine(N.left)&&(N.left=M.left)),R==="HORIZONTAL"&&(C=0),R==="VERTICAL"&&(T=0);let _=0,E=0;const F=e.rowStartY(d-h)+A,L=e.colStartX(u-m)+k,Q=e.rowStartY(d)+A,re=e.colStartX(u)+k;if(m===0)p.left=!1,_=(S-T)*s,E=(f-T)*s;else{const q=S-(L-k),te=f-(L-k);f<re?(_=q*s,E=te*s):S<=re&&f>=re?(_=q*s,E=Math.max(O,(f-T)*s)):S>re&&(p.left=!1,_=Math.max((S-T)*s,O),E=Math.max((f-T)*s,O))}let z=0,J=0;if(h===0)p.top=!1,z=(v-C)*a,J=(I-C)*a;else{const q=v-(F-A),te=I-(F-A);I<Q?(z=q*a,J=te*a):v<=Q&&I>=Q?(z=q*a,J=Math.max(D,(I-C)*a)):v>Q&&(p.top=!1,z=Math.max((v-C)*a,D),J=Math.max((I-C)*a,D))}return _=Math.max(_,N.left),z=Math.max(z,N.top),E=Math.max(E,N.left),J=Math.max(J,N.top),{left:_,right:E,top:z,bottom:J,absolute:p}}const ce=(i,r,e,t,n)=>{const{left:o,top:s,width:a,height:c,angle:g}=i,u={left:o,right:o+a,top:s,bottom:s+c},d=$t(u,r,e,t,n),{scaleX:m,scaleY:h}=r.getAncestorScale();return{startX:d.left,endX:d.right,startY:d.top,endY:d.bottom,rotate:g,width:a*m,height:c*h,absolute:d.absolute}};b.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(e,t,n,o,s,a,c){super();oe(this,"_domLayerInfoMap",new Map);oe(this,"_transformChange$",new W.Subject);oe(this,"transformChange$",this._transformChange$.asObservable());oe(this,"_add$",new W.Subject);oe(this,"add$",this._add$.asObservable());oe(this,"_remove$",new W.Subject);oe(this,"remove$",this._remove$.asObservable());this._renderManagerService=e,this._univerInstanceService=t,this._commandService=n,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(W.filter(e=>e===l.LifecycleStages.Rendered),W.take(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(e){return this._domLayerInfoMap.get(e)}getFloatDomsBySubUnitId(e,t){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===t&&n.unitId===e)}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;const t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;if(t==null||n==null)return null;const o=n.getTransformerByCreate(),s=t.engine.getCanvasElement();return{scene:n,transformer:o,renderUnit:t,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(t=>{var te;const{unitId:n,subUnitId:o,drawingId:s}=t,a=y.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),c=this._drawingManagerService.getDrawingByParam(t),g=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!c||!a)return;const d=(te=this._renderManagerService.getRenderById(n))==null?void 0:te.with(U.SheetSkeletonManagerService).getSkeletonParam(o);if(!d)return;const{transform:m,drawingType:h,data:p}=c;if(h!==l.DrawingTypeEnum.DRAWING_DOM&&h!==l.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(n);if(S==null)return;const{scene:f,canvas:v}=S;if(m==null)return!0;if(u!==o)return;const{left:I,top:D,width:O,height:T,angle:C,flipX:M,flipY:R,skewX:k,skewY:A}=m,N=B.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),_=f.getObject(N);if(_!=null){_.transformByState({left:I,top:D,width:O,height:T,angle:C,flipX:M,flipY:R,skewX:k,skewY:A});return}const E={left:I,top:D,width:O,height:T,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},F=h===l.DrawingTypeEnum.DRAWING_CHART;if(E.rotateEnabled=!1,F){const X=p?p.backgroundColor:"white";E.fill=X,p&&p.border&&(E.stroke=p.border),E.paintFirst="stroke",E.strokeWidth=1,E.borderEnabled=!1,E.radius=8}const L=new P.Rect(N,E);F&&L.setObjectType(P.ObjectType.CHART),f.addObject(L,P.DRAWING_OBJECT_LAYER_INDEX),c.allowTransform!==!1&&f.attachTransformerTo(L);const Q=new l.DisposableCollection,re=ce(L,S.renderUnit.scene,d.skeleton,a.worksheet),z=new W.BehaviorSubject(re),J=`${Lt}${l.generateRandomId(6)}`,se={dispose:Q,rect:L,position$:z,unitId:n,subUnitId:o,id:s,domId:J};this._canvasFloatDomService.addFloatDom({position$:z,id:s,domId:J,componentKey:c.componentKey,onPointerDown:X=>{v.dispatchEvent(new PointerEvent(X.type,X))},onPointerMove:X=>{v.dispatchEvent(new PointerEvent(X.type,X))},onPointerUp:X=>{v.dispatchEvent(new PointerEvent(X.type,X))},onWheel:X=>{v.dispatchEvent(new WheelEvent(X.type,X))},data:p,unitId:n});const q=L.onTransformChange$.subscribeEvent(()=>{const X=ce(L,S.renderUnit.scene,d.skeleton,a.worksheet);z.next(X)});Q.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),q&&Q.add(q),this._domLayerInfoMap.set(s,se)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(t=>{var m;const{unitId:n,subUnitId:o,drawingId:s}=t,a=B.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),c=this._getSceneAndTransformerByDrawingSearch(n);if(c==null)return;const{transformer:g,scene:u}=c,d=u.getObject(a);d!=null&&d.oKey&&(g.clearControlByIds([d==null?void 0:d.oKey]),(m=u.getTransformer())==null||m.clearSelectedObjects())})}))}_scrollUpdateListener(){const e=(t,n)=>{var g;const o=this._getSceneAndTransformerByDrawingSearch(t),s=Array.from(this._domLayerInfoMap.keys()).map(u=>({id:u,...this._domLayerInfoMap.get(u)})).filter(u=>u.subUnitId===n&&u.unitId===t).map(u=>u.id),a=y.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:n}),c=(g=this._renderManagerService.getRenderById(t))==null?void 0:g.with(U.SheetSkeletonManagerService).getSkeletonParam(n);!o||!a||!c||s.forEach(u=>{const d=this._domLayerInfoMap.get(u);if(d){const m=ce(d.rect,o.renderUnit.scene,c.skeleton,a.worksheet,d);d.position$.next(m)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.switchMap(t=>t?t.activeSheet$:W.of(null)),W.map(t=>{if(!t)return null;const n=t.getUnitId(),o=this._renderManagerService.getRenderById(n);return o?{render:o,unitId:n,subUnitId:t.getSheetId()}:null}),W.switchMap(t=>t?l.fromEventSubject(t.render.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(W.map(()=>({unitId:t.unitId,subUnitId:t.subUnitId}))):W.of(null))).subscribe(t=>{if(!t)return;const{unitId:n,subUnitId:o}=t;e(n,o)})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===U.SetZoomRatioOperation.id){const n=t.params,{unitId:o}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===o).map(a=>a.subUnitId).forEach(a=>{e(o,a)})}else if(t.id===y.SetFrozenMutation.id){const{unitId:n,subUnitId:o}=t.params;e(n,o)}else if(t.id===y.SetSelectionsOperation.id){const{unitId:n,subUnitId:o}=t.params;e(n,o)}}))}updateFloatDomProps(e,t,n,o){const s=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(e);if(s&&a){const{scene:c}=a,g=B.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:t,drawingId:n}),u=c.getObject(g);u&&u instanceof P.Rect&&u.setProps(o)}}_getPosition(e,t){var h;const{startX:n,endX:o,startY:s,endY:a}=e,c=(h=this._renderManagerService.getRenderById(t))==null?void 0:h.with(U.ISheetSelectionRenderService);if(c==null)return;const g=c.getCellWithCoordByOffset(n,s);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:s-g.startY},d=c.getCellWithCoordByOffset(o,a);if(d==null)return;const m={column:d.actualColumn,columnOffset:o-d.startX,row:d.actualRow,rowOffset:a-d.startY};return{from:u,to:m}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(t=>{const n=this._drawingManagerService.getDrawingByParam(t);if(!n||n.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const o={...n.transform};this._transformChange$.next({id:t.drawingId,value:o}),this._canvasFloatDomService.updateFloatDom(t.drawingId,{...n});const s=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(s&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART){const{scene:a}=s,c=this._domLayerInfoMap.get(t.drawingId);c!=null&&c.rect&&(n.allowTransform===!1?a.detachTransformerFrom(c.rect):a.attachTransformerTo(c.rect))}})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(t=>{this._removeDom(t.drawingId)})}))}addFloatDomToPosition(e,t){const n=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:o,subUnitId:s}=n,{initPosition:a,componentKey:c,data:g,allowTransform:u=!0}=e,d=t!=null?t:l.generateRandomId(),m=this._getPosition(a,o);if(m==null)return;const h={unitId:o,subUnitId:s,drawingId:d,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:c,sheetTransform:m,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},axisAlignSheetTransform:m,data:g,allowTransform:u};return this._commandService.executeCommand(Oe.id,{unitId:o,drawings:[h]}),this._add$.next({unitId:o,subUnitId:s,id:d}),{id:d,dispose:()=>{this._removeDom(d,!0)}}}_removeDom(e,t=!1){const n=this._domLayerInfoMap.get(e);if(!n)return;const{unitId:o,subUnitId:s}=n;this._domLayerInfoMap.delete(e),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(o);if(a&&a.scene.removeObject(n.rect),t){const c=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:e});if(!c)return;const g=this._sheetDrawingService.getBatchRemoveOp([c]),{redo:u,objects:d}=g;this._commandService.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:u,objects:d,type:w.DrawingApplyType.REMOVE})}}addFloatDomToRange(e,t,n,o){var M,R,k;const s=y.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:c}=s,g=this._getSceneAndTransformerByDrawingSearch(a);if(!g)return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const d=(M=this._renderManagerService.getRenderById(a))==null?void 0:M.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(c);if(!d)return;const{componentKey:m,data:h,allowTransform:p=!0}=t,S=o!=null?o:l.generateRandomId(),{position:f,position$:v}=this._createRangePositionObserver(e,u,d.skeleton);if(this._getPosition(f,a)==null)return;const D=g.scene,{scaleX:O}=D.getAncestorScale(),T=Je(f,n,O),C={unitId:a,subUnitId:c,drawingId:S,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:T.startX,top:T.startY,width:T.width,height:T.height},data:h,allowTransform:p};{const{unitId:A,subUnitId:N,drawingId:_}=C,E=y.getSheetCommandTarget(this._univerInstanceService,{unitId:A,subUnitId:N}),F=C,L=this._univerInstanceService.getUnit(A,l.UniverInstanceType.UNIVER_SHEET);if(!L)return;const Q=L.getActiveSheet().getSheetId();if(!F||!E)return;const re=(R=this._renderManagerService.getRenderById(A))==null?void 0:R.with(U.SheetSkeletonManagerService);if(!re)return;const z=re.getWorksheetSkeleton(N);if(!z)return;const{transform:J,drawingType:se,data:q}=F;if(se!==l.DrawingTypeEnum.DRAWING_DOM&&se!==l.DrawingTypeEnum.DRAWING_CHART)return;const te=this._getSceneAndTransformerByDrawingSearch(A);if(te==null)return;const{scene:X,canvas:Te}=te;if(J==null||Q!==N)return;const{left:nt,top:rt,width:it,height:ot,angle:Et,flipX:bt,flipY:st,skewX:at,skewY:Me}=J,ct=B.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:N,drawingId:_}),de=X.getObject(ct);if(de!=null){de.transformByState({left:nt,top:rt,width:it,height:ot,angle:Et,flipX:bt,flipY:st,skewX:at,skewY:Me});return}const ie={left:nt,top:rt,width:it,height:ot,zIndex:this._drawingManagerService.getDrawingOrder(A,N).length-1},Re=se===l.DrawingTypeEnum.DRAWING_CHART;if(Re){const Y=q?q.backgroundColor:"white";ie.fill=Y,ie.rotateEnabled=!1,q&&q.border&&(ie.stroke=q.border),ie.paintFirst="stroke",ie.strokeWidth=1,ie.borderEnabled=!1,ie.radius=8}const le=new P.Rect(ct,ie);Re&&le.setObjectType(P.ObjectType.CHART),X.addObject(le,P.DRAWING_OBJECT_LAYER_INDEX),F.allowTransform!==!1&&X.attachTransformerTo(le);const ue=new l.DisposableCollection,dt=X.getMainViewport(),{rowHeaderWidth:Ee,columnHeaderHeight:Be}=z.skeleton,lt={top:Be,left:Ee,bottom:dt.bottom,right:dt.right},ge={dispose:ue,rect:le,boundsOfViewArea:lt,domAnchor:n,unitId:A,subUnitId:N},K=ce(le,te.renderUnit.scene,z.skeleton,E.worksheet,ge),be=new W.BehaviorSubject(K);ge.position$=be;let je={position$:be,id:_,componentKey:F.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:Y=>{Te.dispatchEvent(new WheelEvent(Y.type,Y))},data:q,unitId:A};t.eventPassThrough&&(je={...je,onPointerDown:Y=>{Te.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{Te.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{Te.dispatchEvent(new PointerEvent(Y.type,Y))}}),this._canvasFloatDomService.addFloatDom(je),this.disposeWithMe(v.subscribe(Y=>{var Ht,Vt,Xt,Kt;const Gt=Je({startX:Y.startX,startY:Y.startY,endX:Y.endX,endY:Y.endY,width:(Ht=n.width)!=null?Ht:Y.width,height:(Vt=n.height)!=null?Vt:Y.height,absolute:{left:f.absolute.left,top:f.absolute.top}},n),tr=B.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:N,drawingId:_}),nr=new P.Rect(tr,{left:Gt.startX,top:Gt.startY,width:(Xt=n.width)!=null?Xt:Y.width,height:(Kt=n.height)!=null?Kt:Y.height,zIndex:this._drawingManagerService.getDrawingOrder(A,N).length-1}),rr=ce(nr,te.renderUnit.scene,z.skeleton,E.worksheet,ge);be.next(rr)}));const Fe=(k=this._renderManagerService.getRenderById(A))==null?void 0:k.with(U.SheetSkeletonManagerService);Fe==null||Fe.currentSkeleton$.subscribe(Y=>{Y&&z.sheetId!==Y.sheetId&&this._removeDom(S,!0)});const ut=le.onTransformChange$.subscribeEvent(()=>{const Y=ce(le,te.renderUnit.scene,z.skeleton,E.worksheet,ge);be.next(Y)});ue.add(()=>{this._canvasFloatDomService.removeFloatDom(_)}),ut&&ue.add(ut),this._domLayerInfoMap.set(_,ge)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(e,t,n,o){var T,C,M;const s=y.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.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=(T=this._renderManagerService.getRenderById(a))==null?void 0:T.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(c);if(!d)return;const{componentKey:m,data:h,allowTransform:p=!0}=t,S=o!=null?o:l.generateRandomId(),{position:f,position$:v}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:e,endColumn:e},u,d.skeleton),I=f;if(I.startY=0,this._getPosition(f,a)==null)return;const O={unitId:a,subUnitId:c,drawingId:S,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:h,allowTransform:p};{const{unitId:R,subUnitId:k,drawingId:A}=O,N=y.getSheetCommandTarget(this._univerInstanceService,{unitId:R,subUnitId:k}),_=O,E=this._univerInstanceService.getUnit(R,l.UniverInstanceType.UNIVER_SHEET);if(!E)return;const F=E.getActiveSheet().getSheetId();if(!_||!N)return;const L=(C=this._renderManagerService.getRenderById(R))==null?void 0:C.with(U.SheetSkeletonManagerService);if(!L)return;const Q=L.getWorksheetSkeleton(k);if(!Q)return;const{transform:re,data:z}=_,J=this._getSceneAndTransformerByDrawingSearch(R);if(J==null)return;const{scene:se,canvas:q}=J;if(re==null||F!==k)return;const{left:te,top:X,width:Te,height:nt,angle:rt,flipX:it,flipY:ot,skewX:Et,skewY:bt}=re,st=B.getDrawingShapeKeyByDrawingSearch({unitId:R,subUnitId:k,drawingId:A}),at=se.getObject(st);if(at!=null){at.transformByState({left:te,top:X,width:Te,height:nt,angle:rt,flipX:it,flipY:ot,skewX:Et,skewY:bt});return}const Me=Je({startX:I.startX,startY:0,endX:f.endX,endY:f.endY,width:n.width,height:n.height,absolute:{left:f.absolute.left,top:f.absolute.top}},n),ct={left:Me.startX,top:Me.startY,width:Me.width,height:Me.height,zIndex:this._drawingManagerService.getDrawingOrder(R,k).length-1},de=new P.Rect(st,ct);se.addObject(de,P.DRAWING_OBJECT_LAYER_INDEX),_.allowTransform!==!1&&se.attachTransformerTo(de);const ie=new l.DisposableCollection,Re=se.getMainViewport(),le={top:0,left:Re.left,bottom:Re.bottom,right:Re.right},ue={dispose:ie,rect:de,unitId:R,subUnitId:k,boundsOfViewArea:le,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},dt=ce(de,J.renderUnit.scene,Q.skeleton,N.worksheet,ue),Ee=new W.BehaviorSubject(dt);ue.position$=Ee;let Be={position$:Ee,id:A,componentKey:_.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:K=>{q.dispatchEvent(new WheelEvent(K.type,K))},data:z,unitId:R};t.eventPassThrough&&(Be={...Be,onPointerDown:K=>{q.dispatchEvent(new PointerEvent(K.type,K))},onPointerMove:K=>{q.dispatchEvent(new PointerEvent(K.type,K))},onPointerUp:K=>{q.dispatchEvent(new PointerEvent(K.type,K))}}),this._canvasFloatDomService.addFloatDom(Be);const lt=de.onTransformChange$.subscribeEvent(()=>{const K=ce(de,J.renderUnit.scene,Q.skeleton,N.worksheet,ue);Ee.next(K)});this.disposeWithMe(v.subscribe(K=>{const be=Je({startX:K.startX,startY:0,endX:K.endX,endY:K.endY,width:n.width,height:n.height,absolute:{left:f.absolute.left,top:f.absolute.top}},n),je=B.getDrawingShapeKeyByDrawingSearch({unitId:R,subUnitId:k,drawingId:A}),Fe=new P.Rect(je,{left:be.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(R,k).length-1}),ut=ce(Fe,J.renderUnit.scene,Q.skeleton,N.worksheet,ue);Ee.next(ut)}));const ge=(M=this._renderManagerService.getRenderById(R))==null?void 0:M.with(U.SheetSkeletonManagerService);ge==null||ge.currentSkeleton$.subscribe(K=>{K&&d.sheetId!==K.sheetId&&this._removeDom(S,!0)}),ie.add(()=>{this._canvasFloatDomService.removeFloatDom(A)}),lt&&ie.add(lt),this._domLayerInfoMap.set(A,ue)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(e,t,n){let{startRow:o,startColumn:s}=e;const a=ke(o,s,n),c=new W.BehaviorSubject(a),g=ke(e.endRow,e.endColumn,n),u=new W.BehaviorSubject(g),d=()=>{const v=ke(o,s,n),I=ke(e.endRow,e.endColumn,n);c.next(v),u.next(I)},m=new l.DisposableCollection;m.add(t.engine.clientRect$.subscribe(()=>d())),m.add(this._commandService.onCommandExecuted(v=>{if(v.id===y.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(D=>D.row===o)>-1){d();return}(y.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(v.id)>-1||v.id===U.SetScrollOperation.id||v.id===U.SetZoomRatioOperation.id)&&d()}));const h=(v,I)=>{o=v,s=I,d()},p=()=>({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}),S=c.pipe(W.map(v=>{const I=ke(e.endRow,e.endColumn,n);return{rotate:0,width:I.right-v.left,height:I.bottom-v.top,absolute:{left:!0,top:!0},startX:v.left,startY:v.top,endX:I.right,endY:I.bottom}})),f=p();return{position$:S,position:f,updateRowCol:h,topLeftPos$:c,rightBottomPos$:u,disposable:m}}},b.SheetCanvasFloatDomManagerService=Mn([Se(0,l.Inject(P.IRenderManagerService)),Se(1,l.IUniverInstanceService),Se(2,l.Inject(l.ICommandService)),Se(3,B.IDrawingManagerService),Se(4,l.Inject(j.CanvasFloatDomService)),Se(5,w.ISheetDrawingService),Se(6,l.Inject(l.LifecycleService))],b.SheetCanvasFloatDomManagerService);function ke(i,r,e){const t=e.getCellWithCoordByIndex(i,r),n=t.isMergedMainCell?t.mergeInfo:t;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Je(i,r,e){var g,u;e=e!=null?e:1;const t=i.endX-i.startX,n=i.endY-i.startY,o=(g=r==null?void 0:r.width)!=null?g:t,s=(u=r==null?void 0:r.height)!=null?u:n;let a=0,c=0;if(r){if(r.horizonOffsetAlign==="right"){const d=Qe(r.marginX,t*e);a=i.endX-d-o}else a=i.startX+Qe(r.marginX,t);if(r.verticalOffsetAlign==="bottom"){const d=Qe(r.marginY,n*e);c=i.endY-d-s}else c=i.startY+Qe(r.marginY,n)}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 Qe(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const e=Number.parseFloat(i);return r*e/100}const Rn=i=>{const{floatDomInfos:r,scene:e,skeleton:t,worksheet:n}=i,o=Z.useMemo(()=>r.map(s=>{const{width:a,height:c,angle:g,left:u,top:d}=s.transform,m=$t({left:u!=null?u:0,right:(u!=null?u:0)+(a!=null?a:0),top:d!=null?d:0,bottom:(d!=null?d:0)+(c!=null?c:0)},e,t,n,void 0,!0),{scaleX:h,scaleY:p}=e.getAncestorScale(),S={startX:m.left,endX:m.right,startY:m.top,endY:m.bottom,rotate:g,width:a*h,height:c*p,absolute:m.absolute},f={position$:new W.BehaviorSubject(S),position:S,id:s.drawingId,componentKey:s.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:s.unitId,data:s.data};return[s.drawingId,f]}),[r,e,t,n]);return $.jsx("div",{style:{position:"absolute",top:0,left:0},children:o.map(([s,a])=>$.jsx(j.PrintFloatDomSingle,{layer:a,id:s,position:a.position},s))})};var En=Object.getOwnPropertyDescriptor,bn=(i,r,e,t)=>{for(var n=t>1?void 0:t?En(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},fe=(i,r)=>(e,t)=>r(e,t,i);let et=class extends l.Disposable{constructor(i,r,e,t,n,o,s){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=e,this._renderManagerService=t,this._canvasFloatDomManagerService=n,this._componetManager=o,this._injector=s,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,e)=>{const{unitId:t,scene:n,subUnitId:o}=r,s=this._drawingManagerService.getDrawingDataForUnit(t),a=s==null?void 0:s[o];return a&&a.order.forEach(c=>{const g=a.data[c];g.drawingType!==l.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),e()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,e)=>{const{unitId:t,subUnitId:n}=r,o=this._renderManagerService.getRenderById(t);if(!o)return e(i);const s=o.with(U.SheetSkeletonManagerService).getSkeletonParam(n);if(!s)return e(i);const a=this._drawingManagerService.getDrawingDataForUnit(t),c=a==null?void 0:a[r.subUnitId];if(!c)return e(i);const{scaleX:g,scaleY:u}=o.scene,d=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=c.order.map(h=>c.data[h]);return m.length?(m.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 p=s.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),S=s.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});p.column<d.startColumn&&(d.startColumn=p.column),p.row<d.startRow&&(d.startRow=p.row),d.endRow<S.row&&(d.endRow=S.row),d.endColumn<S.column&&(d.endColumn=S.column)}}),e(d)):e(i)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(i,r,e)=>{const{unitId:t,subUnitId:n}=r,o=this._drawingManagerService.getDrawingDataForUnit(t),s=o==null?void 0:o[n];if(s){const a=s.order.map(g=>{const u=s.data[g];if(u.drawingType===l.DrawingTypeEnum.DRAWING_CHART)return{...u,componentKey:this._componetManager.get(l.PRINT_CHART_COMPONENT_KEY)};if(u.drawingType===l.DrawingTypeEnum.DRAWING_DOM){const d=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(d||u.componentKey)}}return null}).filter(Boolean),c=j.connectInjector(Rn,this._injector);return H.render($.jsx(c,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),i==null||i.add(()=>{H.unmount(r.root)}),e(i)}}}))}};et=bn([fe(0,l.Inject(U.SheetPrintInterceptorService)),fe(1,l.Inject(he.DrawingRenderService)),fe(2,B.IDrawingManagerService),fe(3,P.IRenderManagerService),fe(4,l.Inject(b.SheetCanvasFloatDomManagerService)),fe(5,l.Inject(j.ComponentManager)),fe(6,l.Inject(l.Injector))],et);var On=Object.getOwnPropertyDescriptor,An=(i,r,e,t)=>{for(var n=t>1?void 0:t?On(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},pe=(i,r)=>(e,t)=>r(e,t,i);const Un=[y.InsertRowCommand.id,y.InsertColCommand.id,y.RemoveRowCommand.id,y.RemoveColCommand.id,y.DeleteRangeMoveLeftCommand.id,y.DeleteRangeMoveUpCommand.id,y.InsertRangeMoveDownCommand.id,y.InsertRangeMoveRightCommand.id,y.DeltaRowHeightCommand.id,y.SetRowHeightCommand.id,y.DeltaColumnWidthCommand.id,y.SetColWidthCommand.id,y.SetRowHiddenCommand.id,y.SetSpecificRowsVisibleCommand.id,y.SetSpecificColsVisibleCommand.id,y.SetColHiddenCommand.id,y.MoveColsCommand.id,y.MoveRowsCommand.id,y.MoveRangeCommand.id],Pn=[y.SetRowVisibleMutation.id,y.SetRowHiddenMutation.id,y.SetColVisibleMutation.id,y.SetColHiddenMutation.id,y.SetWorksheetRowHeightMutation.id,y.SetWorksheetRowAutoHeightMutation.id,y.SetWorksheetRowIsAutoHeightMutation.id,y.SetWorksheetColWidthMutation.id];let Dt=class extends l.Disposable{constructor(i,r,e,t,n,o,s,a,c){super(),this._context=i,this._renderManagerService=r,this._commandService=e,this._selectionRenderService=t,this._skeletonManagerService=n,this._sheetInterceptorService=o,this._sheetDrawingService=s,this._drawingManagerService=a,this._univerInstanceService=c,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptAfterCommand({getMutations:i=>{if(!Un.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===y.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([y.MoveColsCommand.id,y.MoveRowsCommand.id,y.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===y.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===y.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===y.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===y.DeleteRangeMoveLeftCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,0)}else if(r===y.DeleteRangeMoveUpCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,1)}else if(r===y.InsertRangeMoveDownCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,2)}else if(r===y.InsertRangeMoveRightCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,3)}else if(r===y.SetRowHiddenCommand.id||r===y.SetSpecificRowsVisibleCommand.id){const e=i.params,{unitId:t,subUnitId:n,ranges:o}=e;return this._getDrawingUndoForRowVisible(t,n,o)}else if(r===y.SetSpecificColsVisibleCommand.id||r===y.SetColHiddenCommand.id){const e=i.params,{unitId:t,subUnitId:n,ranges:o}=e;return this._getDrawingUndoForColVisible(t,n,o)}else if(r===y.DeltaRowHeightCommand.id||r===y.SetRowHeightCommand.id||r===y.DeltaColumnWidthCommand.id||r===y.SetColWidthCommand.id){const e=i.params,{unitId:t,subUnitId:n,ranges:o}=e,s=r===y.DeltaRowHeightCommand.id||r===y.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(t,n,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const e=y.getSheetCommandTarget(this._univerInstanceService);if(e==null)return{redos:[],undos:[]};const t=e.unitId,n=e.subUnitId,o=[],s=[],a=this._sheetDrawingService.getDrawingData(t,n),c=[],g=[];if(Object.keys(a).forEach(u=>{const d=a[u],{updateDrawings:m,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,d);c.push(...m),g.push(...h)}),c.length===0&&g.length===0)return{redos:[],undos:[]};if(c.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(c),{undo:d,redo:m,objects:h}=u;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:m,objects:h,type:w.DrawingApplyType.UPDATE}}),s.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:d,objects:h,type:w.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),d=u.undo,m=u.redo,h=u.objects;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:m,objects:h,type:w.DrawingApplyType.REMOVE}}),s.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:d,objects:h,type:w.DrawingApplyType.INSERT}})}return o.push({id:V.id,params:[t]}),s.push({id:V.id,params:[t]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,r,e){var R,k,A,N;const t=[],n=[],{sheetTransform:o,anchorType:s=w.SheetDrawingAnchorType.Position,transform:a,unitId:c,subUnitId:g,drawingId:u}=e,{from:d,to:m}=o,{row:h,column:p}=d,{row:S,column:f}=m;if(o==null||a==null)return{updateDrawings:t,deleteDrawings:n};const{startRow:v,endRow:I,startColumn:D,endColumn:O}=i;let T=null,C=null,M;if(r===0&&h>=v&&S<=I)if(p>=D&&f<=O)n.push({unitId:c,subUnitId:g,drawingId:u});else{const _=this._shrinkCol(o,a,D,O,s);T=_==null?void 0:_.newSheetTransform,C=_==null?void 0:_.newTransform,M=(R=_==null?void 0:_.axisAlignSheetTransform)!=null?R:void 0}else if(r===1&&p>=D&&f<=O)if(h>=v&&S<=I)n.push({unitId:c,subUnitId:g,drawingId:u});else{const _=this._shrinkRow(o,a,v,I,s);T=_==null?void 0:_.newSheetTransform,C=_==null?void 0:_.newTransform,M=(k=_==null?void 0:_.axisAlignSheetTransform)!=null?k:void 0}else if(r===2){const _=this._expandRow(o,a,v,I,s);T=_==null?void 0:_.newSheetTransform,C=_==null?void 0:_.newTransform,M=(A=_==null?void 0:_.axisAlignSheetTransform)!=null?A:void 0}else if(r===3){const _=this._expandCol(o,a,D,O,s);T=_==null?void 0:_.newSheetTransform,C=_==null?void 0:_.newTransform,M=(N=_==null?void 0:_.axisAlignSheetTransform)!=null?N:void 0}if(T!=null&&C!=null){const _=ee(T,this._selectionRenderService,this._skeletonManagerService);t.push({...e,sheetTransform:T,transform:_,axisAlignSheetTransform:M})}return{updateDrawings:t,deleteDrawings:n}}_remainDrawingSize(i,r,e){const t=x({...i},this._selectionRenderService);if(t!=null){const n=G({...i},this._selectionRenderService);r.push({...e,sheetTransform:t,axisAlignSheetTransform:n})}}_getDrawingUndoForColVisible(i,r,e){const t=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(t).forEach(u=>{const d=t[u],{sheetTransform:m,transform:h,anchorType:p=w.SheetDrawingAnchorType.Position}=d;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:f}=m,{row:v,column:I}=S,{row:D,column:O}=f;for(let T=0;T<e.length;T++){const C=e[T],{startRow:M,endRow:R,startColumn:k,endColumn:A}=C;if(O<k)continue;if(p===w.SheetDrawingAnchorType.Position){let E=null,F=null;if(I>=k&&I<=A){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:A,startRow:S.row,endRow:f.row});if(L==null)return;F={...h,left:L.startX}}if(F!=null){E=x(F,this._selectionRenderService);const L=G(F,this._selectionRenderService);if(E!=null&&F!=null){n.push({...d,sheetTransform:E,transform:F,axisAlignSheetTransform:L});break}}this._remainDrawingSize(h,n,d);continue}if(I>=k&&O<=A)continue;let N=null,_=null;if(I>=k&&I<=A){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:A,startRow:S.row,endRow:f.row});if(E==null)return;_={...h,left:(E==null?void 0:E.startX)||0,width:((h==null?void 0:h.width)||0)-E.endX+E.startX}}else if(O>=k&&O<=A){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:k,endColumn:O,startRow:S.row,endRow:f.row});if(E==null)return;_={...h,left:E.startX-((h==null?void 0:h.width)||0)}}else{const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:k,endColumn:A,startRow:S.row,endRow:f.row});if(E==null)return;if(_={...h,width:((h==null?void 0:h.width)||0)-E.endX+E.startX},N=x(_,this._selectionRenderService),N!=null&&_!=null){const F=G(_,this._selectionRenderService);o.push({...d,sheetTransform:N,transform:_,axisAlignSheetTransform:F});break}}if(_!=null&&(N=x(_,this._selectionRenderService)),_!=null&&N!=null){const E=G(_,this._selectionRenderService);n.push({...d,sheetTransform:N,transform:_,axisAlignSheetTransform:E});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,r,n),c=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);c.push(...u),g.push(...d)}return{redos:s,undos:a,preRedos:c,preUndos:g}}_createUndoAndRedoMutation(i,r,e){const t=this._sheetDrawingService.getBatchUpdateOp(e),{undo:n,redo:o,objects:s}=t,a=[{id:w.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:s,type:w.DrawingApplyType.UPDATE}},{id:V.id,params:[i]}],c=[{id:w.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:s,type:w.DrawingApplyType.UPDATE}},{id:V.id,params:[i]}];return{redos:a,undos:c}}_getDrawingUndoForRowVisible(i,r,e){const t=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(t).forEach(u=>{const d=t[u],{sheetTransform:m,transform:h,anchorType:p=w.SheetDrawingAnchorType.Position}=d;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:f}=m,{row:v,column:I}=S,{row:D,column:O}=f;for(let T=0;T<e.length;T++){const C=e[T],{startRow:M,endRow:R,startColumn:k,endColumn:A}=C;if(D<M)continue;if(p===w.SheetDrawingAnchorType.Position){let E=null,F=null;if(v>=M&&v<=R){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:v,endRow:R});if(L==null)return;F={...h,top:L.startY}}if(F!=null){E=x(F,this._selectionRenderService);const L=G(F,this._selectionRenderService);if(E!=null&&F!=null){n.push({...d,sheetTransform:E,transform:F,axisAlignSheetTransform:L});break}}this._remainDrawingSize(h,n,d);continue}if(v>=M&&D<=R)continue;let N=null,_=null;if(v>=M&&v<=R){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:v,endRow:R});if(E==null)return;_={...h,top:(E==null?void 0:E.startY)||0,height:((h==null?void 0:h.height)||0)-E.endY+E.startY}}else if(D>=M&&D<=R){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:M,endRow:D});if(E==null)return;_={...h,top:E.startY-((h==null?void 0:h.height)||0)}}else{const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:M,endRow:R});if(E==null)return;if(_={...h,height:((h==null?void 0:h.height)||0)-E.endY+E.startY},N=x(_,this._selectionRenderService),N!=null&&_!=null){const F=G(_,this._selectionRenderService);o.push({...d,sheetTransform:N,transform:_,axisAlignSheetTransform:F});break}}if(_!=null&&(N=x(_,this._selectionRenderService)),_!=null&&N!=null){const E=G(_,this._selectionRenderService);n.push({...d,sheetTransform:N,transform:_,axisAlignSheetTransform:E});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,r,n),c=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);c.push(...u),g.push(...d)}return{redos:s,undos:a,preRedos:c,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,e,t){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(s=>{const a=n[s],{sheetTransform:c,transform:g,anchorType:u=w.SheetDrawingAnchorType.Position}=a;if(u===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,o,a);else{const{from:d,to:m}=c,{row:h,column:p}=d,{row:S,column:f}=m;for(let v=0;v<e.length;v++){const I=e[v],{startRow:D,endRow:O,startColumn:T,endColumn:C}=I;if(S<D||f<T)continue;if(u===w.SheetDrawingAnchorType.Position&&(h<=D&&S>=O||p<=T&&f>=C)){this._remainDrawingSize(g,o,a);continue}const M=ee({...c},this._selectionRenderService,this._skeletonManagerService);if(M!=null){o.push({...a,transform:M});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let e,t;if(r==="insert")e=i.unitId,t=i.subUnitId;else{const n=y.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;e=n.unitId,t=n.subUnitId}return{unitId:e,subUnitId:t}}_moveRangeInterceptor(i){var D,O;const{toRange:r,fromRange:e}=i,t=y.getSheetCommandTarget(this._univerInstanceService);if(!t)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=t,s=(O=(D=this._renderManagerService.getRenderById(n))==null?void 0:D.with(U.SheetSkeletonManagerService))==null?void 0:O.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const a=U.attachRangeWithCoord(s,e);if(!a)return{redos:[],undos:[]};const{startX:c,endX:g,startY:u,endY:d}=a,m=this._sheetDrawingService.getDrawingData(n,o),h=[];Object.keys(m).forEach(T=>{const C=m[T];if(C.anchorType!==w.SheetDrawingAnchorType.Both)return;const{transform:M}=C;if(!M)return;const{left:R=0,top:k=0,width:A=0,height:N=0}=M,{drawingStartX:_,drawingEndX:E,drawingStartY:F,drawingEndY:L}={drawingStartX:R,drawingEndX:R+A,drawingStartY:k,drawingEndY:k+N};c<=_&&E<=g&&u<=F&&L<=d&&h.push(C)});const p=[],S=[],f=r.startRow-e.startRow,v=r.startColumn-e.startColumn,I=h.map(T=>{const C=T.sheetTransform,M={to:{...C.to,row:C.to.row+f,column:C.to.column+v},from:{...C.from,row:C.from.row+f,column:C.from.column+v}},R=ee(M,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:T.drawingId,transform:R,sheetTransform:M}});if(I.length){const T=this._sheetDrawingService.getBatchUpdateOp(I),{undo:C,redo:M,objects:R}=T;p.push({id:w.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:M,objects:R,type:w.DrawingApplyType.UPDATE}}),S.push({id:w.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:C,objects:R,type:w.DrawingApplyType.UPDATE}})}return{redos:p,undos:S}}_moveRowInterceptor(i,r){const e=this._getUnitIdAndSubUnitId(i,r);if(e==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=e,{range:o}=i,s=o.startRow,a=o.endRow,c=[],g=[],u=this._sheetDrawingService.getDrawingData(t,n),d=[],m=[];if(Object.keys(u).forEach(h=>{var C,M;const p=u[h],{sheetTransform:S,transform:f,anchorType:v=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let I,D,O;if(r==="insert"){const R=this._expandRow(S,f,s,a,v);I=R==null?void 0:R.newSheetTransform,D=R==null?void 0:R.newTransform,O=(C=R==null?void 0:R.axisAlignSheetTransform)!=null?C:void 0}else{const{from:R,to:k}=S,{row:A}=R,{row:N}=k;if(v===w.SheetDrawingAnchorType.Both&&A>=s&&N<=a)m.push({unitId:t,subUnitId:n,drawingId:h});else{const _=this._shrinkRow(S,f,s,a,v);I=_==null?void 0:_.newSheetTransform,D=_==null?void 0:_.newTransform,O=(M=_==null?void 0:_.axisAlignSheetTransform)!=null?M:void 0}}if(!I||!D)return;const T={unitId:t,subUnitId:n,drawingId:h,transform:D,sheetTransform:I,axisAlignSheetTransform:O};d.push(T)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:p,redo:S,objects:f}=h;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),p=h.undo,S=h.redo,f=h.objects;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return c.push({id:V.id,params:[t]}),g.push({id:V.id,params:[t]}),{redos:c,undos:g}}_moveColInterceptor(i,r){const e=this._getUnitIdAndSubUnitId(i,r);if(e==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=e,{range:o}=i,s=o.startColumn,a=o.endColumn,c=[],g=[],u=this._sheetDrawingService.getDrawingData(t,n),d=[],m=[];if(Object.keys(u).forEach(h=>{var C,M;const p=u[h],{sheetTransform:S,transform:f,anchorType:v=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let I,D,O;if(r==="insert"){const R=this._expandCol(S,f,s,a,v);I=R==null?void 0:R.newSheetTransform,D=R==null?void 0:R.newTransform,O=(C=R==null?void 0:R.axisAlignSheetTransform)!=null?C:void 0}else{const{from:R,to:k}=S,{column:A}=R,{column:N}=k;if(v===w.SheetDrawingAnchorType.Both&&A>=s&&N<=a)m.push({unitId:t,subUnitId:n,drawingId:h});else{const _=this._shrinkCol(S,f,s,a,v);I=_==null?void 0:_.newSheetTransform,D=_==null?void 0:_.newTransform,O=(M=_==null?void 0:_.axisAlignSheetTransform)!=null?M:void 0}}if(!I||!D)return;const T={unitId:t,subUnitId:n,drawingId:h,transform:D,sheetTransform:I,axisAlignSheetTransform:O};d.push(T)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:p,redo:S,objects:f}=h;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),p=h.undo,S=h.redo,f=h.objects;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return c.push({id:V.id,params:[t]}),g.push({id:V.id,params:[t]}),{redos:c,undos:g}}_expandCol(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{column:c}=s,{column:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:G({...r},this._selectionRenderService)};let u=null,d=null,m=null;if(c>=e){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:e,endColumn:t,startRow:s.row,endRow:a.row});if(h==null)return;d={...r,left:(r.left||0)+h.endX-h.startX},u=x(d,this._selectionRenderService),m=G(d,this._selectionRenderService)}else if(g>=t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g+o}},d=ee(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:G({...r},this._selectionRenderService)};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d,axisAlignSheetTransform:m}:null}_shrinkCol(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{column:c}=s,{column:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:G({...r},this._selectionRenderService)};let u=null,d=null,m=null;if(c>t)u={from:{...s,column:c-o},to:{...a,column:g-o}},d=ee(u,this._selectionRenderService,this._skeletonManagerService);else{if(c>=e&&g<=t)return null;if(c<e&&g>t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g-o}},d=ee(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:G({...r},this._selectionRenderService)};else if(c>=e&&c<=t){if(c===e)d={...r,left:(r.left||0)-i.from.columnOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:e,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=x(d,this._selectionRenderService),m=G(d,this._selectionRenderService)}else if(g>=e&&g<=t&&n===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:e-1,endColumn:e-1,startRow:s.row,endRow:a.row});if(h==null)return;u={from:{...s},to:{...a,column:e-1,columnOffset:h.endX-h.startX}},d=ee(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d,axisAlignSheetTransform:m}:null}_expandRow(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{row:c}=s,{row:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:G({...r},this._selectionRenderService)};let u=null,d=null,m=null;if(c>=e){const h=this._skeletonManagerService.attachRangeWithCoord({startRow:e,endRow:t,startColumn:s.column,endColumn:a.column});if(h==null)return;d={...r,top:(r.top||0)+h.endY-h.startY},u=x(d,this._selectionRenderService),m=G(d,this._selectionRenderService)}else if(g>=t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g+o}},d=ee(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:G({...r},this._selectionRenderService)};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d,axisAlignSheetTransform:m}:null}_shrinkRow(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{row:c}=s,{row:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:G({...r},this._selectionRenderService)};let u=null,d=null,m=null;if(c>t)u={from:{...s,row:c-o},to:{...a,row:g-o}},d=ee(u,this._selectionRenderService,this._skeletonManagerService);else{if(c>=e&&g<=t)return null;if(c<e&&g>t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g-o}},d=ee(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:G({...r},this._selectionRenderService)};else if(c>=e&&c<=t){if(c===e)d={...r,top:(r.top||0)-i.from.rowOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startRow:e,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=x(d,this._selectionRenderService),m=G(d,this._selectionRenderService)}else if(g>=e&&g<=t&&n===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:e-1,endRow:e-1});if(h==null)return;u={from:{...s},to:{...a,row:e-1,rowOffset:h.endY-h.startY}},d=ee(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d,axisAlignSheetTransform:m}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===y.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:e}=i.params;this._updateDrawings(r,e)}})),this.disposeWithMe(this._context.activated$.subscribe(i=>{const{unit:r,unitId:e}=this._context;if(i){const t=r.getActiveSheet().getSheetId();this._updateDrawings(e,t)}else this._clearDrawings(e)}))}_clearDrawings(i){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,e=[];Object.keys(r).forEach(t=>{const n=r[t];n!=null&&Object.keys(n).forEach(o=>{const s=n[o].data;s!=null&&Object.keys(s).forEach(a=>{t===i&&e.push(s[a])})})}),this._sheetDrawingService.removeNotification(e),this._drawingManagerService.removeNotification(e)})}_updateDrawings(i,r){setTimeout(()=>{const e=this._drawingManagerService.drawingManagerData,t=[],n=[];Object.keys(e).forEach(o=>{const s=e[o];s!=null&&Object.keys(s).forEach(a=>{const c=s[a].data;c!=null&&Object.keys(c).forEach(g=>{if(o===i&&a===r){const u=c[g];u.transform=ee(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),t.push(c[g])}else n.push(c[g])})})}),this._sheetDrawingService.removeNotification(n),this._sheetDrawingService.addNotification(t),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(t)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Pn.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,e=y.getSheetCommandTarget(this._univerInstanceService,r);if(!e)return;const{unitId:t,subUnitId:n,worksheet:o}=e;let s=[];"ranges"in r?s=r.ranges:"rowsAutoHeightInfo"in r&&(s=r.rowsAutoHeightInfo.map(a=>({startRow:a.row,endRow:a.row,startColumn:0,endColumn:o.getColumnCount()-1}))),this._refreshDrawingTransform(t,n,s)})}))}_refreshDrawingTransform(i,r,e){const t=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(t).forEach(o=>{const s=t[o],{sheetTransform:a,transform:c,anchorType:g=w.SheetDrawingAnchorType.Position}=s;if(g===w.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=a,{row:m,column:h}=u,{row:p,column:S}=d;for(let f=0;f<e.length;f++){const v=e[f],{startRow:I,endRow:D,startColumn:O,endColumn:T}=v;if(l.Rectangle.intersects({startRow:I,endRow:D,startColumn:O,endColumn:T},{startRow:m,endRow:p,startColumn:h,endColumn:S})||m>D||h>T){const C=g===w.SheetDrawingAnchorType.Position,M=ee(a,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...M,width:C?c==null?void 0:c.width:M==null?void 0:M.width,height:C?c==null?void 0:c.height:M==null?void 0:M.height}});break}}}),n.length!==0&&(this._sheetDrawingService.refreshTransform(n),this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(V.id,[i]))}};Dt=An([pe(1,P.IRenderManagerService),pe(2,l.ICommandService),pe(3,U.ISheetSelectionRenderService),pe(4,l.Inject(U.SheetSkeletonManagerService)),pe(5,l.Inject(y.SheetInterceptorService)),pe(6,w.ISheetDrawingService),pe(7,B.IDrawingManagerService),pe(8,l.IUniverInstanceService)],Dt);function Nn(){const i=j.useDependency(l.LocaleService),r=j.useDependency(j.IDialogService),e=j.useDependency(Ye),[t,n]=Z.useState([me.CELL_ADDRESS]),[o,s]=Z.useState(!1),[a,c]=Z.useState(null),g=Z.useMemo(()=>e.getCellImagesInSelection(),[e]),u=Z.useMemo(()=>e.getDataColumns(),[e]),d=Z.useMemo(()=>e.getSelectionRowRange(),[e]),m=u.length>0,h=Z.useMemo(()=>u.map(C=>({label:C.label,value:String(C.index)})),[u]),[p,S]=Z.useState(()=>h.length>0?h[0].value:"0"),f=Z.useMemo(()=>{if(!t.includes(me.COLUMN_VALUE)||!d)return[];const M=Number(p);return[{startRow:d.startRow,endRow:d.endRow,startColumn:M,endColumn:M}]},[t,p,d]);U.useHighlightRange(f);const v=Z.useCallback(C=>{C.length!==0&&n(C)},[]),I=Z.useCallback(C=>{S(String(C))},[]),D=Z.useCallback(()=>{r.close(Ie)},[r]),O=Z.useCallback(async()=>{if(g.length!==0){s(!0),c(null);try{await e.saveImages(g,{fileNameParts:t,columnIndex:t.includes(me.COLUMN_VALUE)?Number(p):void 0}),r.close(Ie)}catch(C){console.error("Failed to save images:",C),c(i.t("sheetImage.save.error"))}finally{s(!1)}}},[e,g,t,p,r,i]),T=t.includes(me.COLUMN_VALUE);return $.jsxs("div",{className:"univer-flex univer-flex-col",children:[$.jsx(H.FormLayout,{label:i.t("sheetImage.save.imageCount"),children:$.jsx("div",{className:"univer-text-sm univer-text-gray-600",children:g.length})}),$.jsx(H.FormLayout,{label:i.t("sheetImage.save.fileNameConfig"),children:$.jsxs(H.CheckboxGroup,{value:t,onChange:v,direction:"vertical",children:[$.jsx(H.Checkbox,{value:me.CELL_ADDRESS,disabled:!m,children:i.t("sheetImage.save.useRowCol")}),m&&$.jsx(H.Checkbox,{value:me.COLUMN_VALUE,children:i.t("sheetImage.save.useColumnValue")})]})}),T&&$.jsx(H.FormLayout,{label:i.t("sheetImage.save.selectColumn"),children:$.jsx(H.Select,{value:p,options:h,onChange:I})}),a&&$.jsx("div",{className:"univer-text-xs univer-text-red-500",children:a}),$.jsxs("div",{className:"univer-flex univer-justify-end univer-gap-2 univer-border-t univer-border-gray-200 univer-pt-3",children:[$.jsx(H.Button,{onClick:D,disabled:o,children:i.t("sheetImage.save.cancel")}),$.jsx(H.Button,{variant:"primary",onClick:O,disabled:o||g.length===0,children:o?i.t("sheetImage.save.saving"):i.t("sheetImage.save.confirm")})]})]})}const Yt=i=>{var I;const r=j.useDependency(l.ICommandService),e=j.useDependency(l.LocaleService),t=j.useDependency(B.IDrawingManagerService),n=j.useDependency(P.IRenderManagerService),{drawings:o}=i,s=o[0];if(s==null)return;const{unitId:a}=s,c=n.getRenderById(a),g=c==null?void 0:c.scene;if(g==null)return;const u=g.getTransformerByCreate(),[d,m]=Z.useState(!0),h=(I=s.anchorType)!=null?I:w.SheetDrawingAnchorType.Position,[p,S]=Z.useState(h);function f(D,O){const T=[];return D.forEach(C=>{const{oKey:M}=C,R=O.getDrawingOKey(M);if(R==null)return T.push(null),!0;const{unitId:k,subUnitId:A,drawingId:N,drawingType:_,anchorType:E,sheetTransform:F,axisAlignSheetTransform:L}=R;T.push({unitId:k,subUnitId:A,drawingId:N,anchorType:E,sheetTransform:F,drawingType:_,axisAlignSheetTransform:L})}),T}Z.useEffect(()=>{const D=u.clearControl$.subscribe(T=>{T===!0&&m(!1)}),O=u.changeStart$.subscribe(T=>{var R;const{objects:C}=T,M=f(C,t);if(M.length===0)m(!1);else if(M.length>=1){m(!0);const k=((R=M[0])==null?void 0:R.anchorType)||w.SheetDrawingAnchorType.Position;S(k)}});return()=>{O.unsubscribe(),D.unsubscribe()}},[]);function v(D){S(D);const O=t.getFocusDrawings();if(O.length===0)return;const T=O.map(C=>({unitId:C.unitId,subUnitId:C.subUnitId,drawingId:C.drawingId,anchorType:D}));r.executeCommand(ve.id,{unitId:O[0].unitId,drawings:T})}return $.jsxs("div",{className:H.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!d}),children:[$.jsx("header",{className:"univer-text-gray-600 dark:!univer-text-gray-200",children:$.jsx("div",{children:e.t("drawing-anchor.title")})}),$.jsx("div",{children:$.jsxs(H.RadioGroup,{value:p,onChange:v,direction:"vertical",children:[$.jsx(H.Radio,{value:w.SheetDrawingAnchorType.Both,children:e.t("drawing-anchor.both")}),$.jsx(H.Radio,{value:w.SheetDrawingAnchorType.Position,children:e.t("drawing-anchor.position")}),$.jsx(H.Radio,{value:w.SheetDrawingAnchorType.None,children:e.t("drawing-anchor.none")})]})})]})},kn=()=>{const i=j.useDependency(B.IDrawingManagerService),r=i.getFocusDrawings(),[e,t]=Z.useState(r);return Z.useEffect(()=>{const n=i.focus$.subscribe(o=>{t(o)});return()=>{n.unsubscribe()}},[]),!!(e!=null&&e.length)&&$.jsxs("div",{className:"univer-text-sm",children:[$.jsx(he.DrawingCommonPanel,{drawings:e}),$.jsx(Yt,{drawings:e})]})},Tt="sheet.menu.image";function Wn(i){return{id:Tt,type:j.MenuItemType.SUBITEMS,icon:"AddImageIcon",tooltip:"sheetImage.title",hidden$:j.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),disabled$:U.getCurrentRangeDisable$(i,{workbookTypes:[y.WorkbookEditablePermission],worksheetTypes:[y.WorksheetEditPermission],rangeTypes:[y.RangeProtectionPermissionEditPoint]})}}function Bn(i){return{id:Ae.id,title:"sheetImage.upload.float",type:j.MenuItemType.BUTTON,hidden$:j.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function jn(i){return{id:ft.id,title:"sheetImage.upload.cell",type:j.MenuItemType.BUTTON,hidden$:j.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function Fn(i){var r,e,t,n;return!!((e=(r=i==null?void 0:i.p)==null?void 0:r.drawingsOrder)!=null&&e.length&&((n=(t=i==null?void 0:i.p)==null?void 0:t.drawingsOrder)==null?void 0:n.length)>0)}function Ln(i,r){const e=i.getActiveSheet();if(!e)return!1;const t=e.getCellMatrix(),{startRow:n,endRow:o,startColumn:s,endColumn:a}=r;for(let c=n;c<=o;c++)for(let g=s;g<=a;g++){const u=t.getValue(c,g);if(Fn(u))return!0}return!1}function $n(){return"showDirectoryPicker"in window}function Mt(i){const r=i.get(l.IUniverInstanceService),e=i.get(y.SheetsSelectionsService),t=W.combineLatest([j.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),r.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.switchMap(n=>n?e.selectionMoveEnd$.pipe(W.map(()=>{if(!$n())return!0;const o=e.getCurrentSelections();if(!o||o.length===0)return!0;for(const s of o)if(Ln(n,s.range))return!1;return!0})):W.of(!0)))]).pipe(W.map(([n,o])=>n||o));return{id:ye.id,type:j.MenuItemType.BUTTON,icon:"DownloadImageIcon",title:"sheetImage.save.menuLabel",hidden$:t}}const Yn={[j.RibbonInsertGroup.MEDIA]:{[Tt]:{order:0,menuItemFactory:Wn,[Ae.id]:{order:0,menuItemFactory:Bn},[ft.id]:{order:1,menuItemFactory:jn}}},[j.ContextMenuPosition.MAIN_AREA]:{[j.ContextMenuGroup.OTHERS]:{[ye.id]:{order:10,menuItemFactory:Mt}}},[j.ContextMenuPosition.COL_HEADER]:{[j.ContextMenuGroup.OTHERS]:{[ye.id]:{order:10,menuItemFactory:Mt}}},[j.ContextMenuPosition.ROW_HEADER]:{[j.ContextMenuGroup.OTHERS]:{[ye.id]:{order:10,menuItemFactory:Mt}}}};function We(i){return i.getContextValue(l.FOCUSING_SHEET)&&!i.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(l.FOCUSING_PANEL_EDITOR)&&i.getContextValue(l.FOCUSING_COMMON_DRAWINGS)&&!i.getContextValue(l.FOCUSING_SHAPE_TEXT_EDITOR)}const xn={id:_e.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:j.KeyCode.ARROW_DOWN,priority:100,preconditions:We,staticParameters:{direction:l.Direction.DOWN}},Gn={id:_e.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:j.KeyCode.ARROW_UP,priority:100,preconditions:We,staticParameters:{direction:l.Direction.UP}},Hn={id:_e.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:j.KeyCode.ARROW_LEFT,priority:100,preconditions:We,staticParameters:{direction:l.Direction.LEFT}},Vn={id:_e.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:j.KeyCode.ARROW_RIGHT,priority:100,preconditions:We,staticParameters:{direction:l.Direction.RIGHT}},Xn={id:gt.id,description:"shortcut.drawing-delete",group:"4_drawing-view",priority:100,preconditions:We,binding:j.KeyCode.DELETE,mac:j.KeyCode.BACKSPACE};var Kn=Object.getOwnPropertyDescriptor,zn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Kn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},De=(i,r)=>(e,t)=>r(e,t,i);let tt=class extends l.Disposable{constructor(i,r,e,t,n,o){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=e,this._shortcutService=t,this._drawingManagerService=n,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Nt,kn)),this.disposeWithMe(i.register(Ie,Nn))}_initMenus(){this._menuManagerService.mergeMenu(Yn)}_initCommands(){[Ae,ft,Oe,we,ve,_t,V,It,ht,pt,_e,gt,mt,ye].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[xn,Gn,Hn,Vn,Xn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};tt=zn([De(0,l.Inject(j.ComponentManager)),De(1,j.IMenuManagerService),De(2,l.ICommandService),De(3,j.IShortcutService),De(4,B.IDrawingManagerService),De(5,l.Inject(y.SheetsSelectionsService))],tt);var qn=Object.defineProperty,Zn=Object.getOwnPropertyDescriptor,Jn=(i,r,e)=>r in i?qn(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e,Qn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Zn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Rt=(i,r)=>(e,t)=>r(e,t,i),xt=(i,r,e)=>Jn(i,typeof r!="symbol"?r+"":r,e);const er="SHEET_IMAGE_UI_PLUGIN";b.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=kt,e,t,n){super(),this._config=r,this._injector=e,this._renderManagerService=t,this._configService=n;const{menu:o,...s}=l.merge({},kt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(rn,s)}onStarting(){l.registerDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService],[tt],[Ge],[et],[Ze],[qe],[Xe],[Ke],[ze],[Ye,{useClass:b.BatchSaveImagesService}]]),l.touchDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[qe],[ze]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[Ze],[et],[tt],[Xe],[Ke]])}onSteady(){this._injector.get(Ge)}_registerRenderModules(){[[b.SheetDrawingUpdateController],[Dt],[Ct],[yt]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}},xt(b.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),xt(b.UniverSheetsDrawingUIPlugin,"pluginName",er),b.UniverSheetsDrawingUIPlugin=Qn([l.DependentOn(B.UniverDrawingPlugin,Ot.UniverDocsDrawingPlugin,he.UniverDrawingUIPlugin,w.UniverSheetsDrawingPlugin),Rt(1,l.Inject(l.Injector)),Rt(2,P.IRenderManagerService),Rt(3,l.IConfigService)],b.UniverSheetsDrawingUIPlugin),b.ClearSheetDrawingTransformerOperation=V,b.DeleteDrawingsCommand=gt,b.EditSheetDrawingOperation=It,b.FileNamePart=me,b.GroupSheetDrawingCommand=ht,b.IBatchSaveImagesService=Ye,b.InsertFloatImageCommand=Ae,b.InsertSheetDrawingCommand=Oe,b.MoveDrawingsCommand=_e,b.RemoveSheetDrawingCommand=we,b.SHEETS_IMAGE_MENU_ID=Tt,b.SHEET_FLOAT_DOM_PREFIX=Lt,b.SaveCellImagesCommand=ye,b.SetDrawingArrangeCommand=mt,b.SetSheetDrawingCommand=ve,b.SheetDrawingAnchor=Yt,b.SidebarSheetDrawingOperation=_t,b.UngroupSheetDrawingCommand=pt,b.calcSheetFloatDomPosition=ce,b.drawingPositionToTransform=ee,b.transformToAxisAlignPosition=G,b.transformToDrawingPosition=x,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
16
16
 
17
17
 
18
18
  // @univerjs/sheets-drawing-ui/facade
19
- (function(c,l){typeof exports=="object"&&typeof module<"u"?l(require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing-ui"),require("@univerjs/sheets-ui"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui/facade"),require("@univerjs/sheets/facade"),require("@univerjs/ui")):typeof define=="function"&&define.amd?define(["@univerjs/core","@univerjs/core/facade","@univerjs/drawing","@univerjs/engine-render","@univerjs/sheets-drawing-ui","@univerjs/sheets-ui","@univerjs/sheets-drawing","@univerjs/sheets-ui/facade","@univerjs/sheets/facade","@univerjs/ui"],l):(c=typeof globalThis<"u"?globalThis:c||self,l(c.UniverCore,c.UniverCoreFacade,c.UniverDrawing,c.UniverEngineRender,c.UniverSheetsDrawingUi,c.UniverSheetsUi,c.UniverSheetsDrawing,c.UniverSheetsUiFacade,c.UniverSheetsFacade,c.UniverUi))})(this,(function(c,l,f,C,m,D,w,b,E,F){"use strict";var N=Object.defineProperty;var H=(c,l,f)=>l in c?N(c,l,{enumerable:!0,configurable:!0,writable:!0,value:f}):c[l]=f;var M=(c,l,f)=>H(c,typeof l!="symbol"?l+"":l,f);var A=Object.getOwnPropertyDescriptor,T=(s,r,t,e)=>{for(var n=e>1?void 0:e?A(r,t):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=a(n)||n);return n},R=(s,r)=>(t,e)=>r(t,e,s);function B(s,r){const{from:t,to:e,flipY:n=!1,flipX:i=!1,angle:a=0,skewX:o=0,skewY:d=0}=s.sheetTransform,{column:h,columnOffset:g,row:u,rowOffset:v}=t,_=D.convertPositionSheetOverGridToAbsolute(s.unitId,s.subUnitId,{from:t,to:e},r),{width:I,height:S}=_;return{...s,column:h,columnOffset:g,row:u,rowOffset:v,width:I,height:S,flipY:n,flipX:i,angle:a,skewX:o,skewY:d}}function j(s,r,t){const{column:e,columnOffset:n,row:i,rowOffset:a,flipY:o=!1,flipX:d=!1,angle:h=0,skewX:g=0,skewY:u=0,width:v,height:_}=s,I=D.convertPositionCellToSheetOverGrid(s.unitId,s.subUnitId,{column:e,columnOffset:n,row:i,rowOffset:a},v,_,r,t),{sheetTransform:S,transform:O}=I;return{...s,sheetTransform:{...S,flipY:o,flipX:d,angle:h,skewX:g,skewY:u},transform:{...O,flipY:o,flipX:d,angle:h,skewX:g,skewY:u}}}let y=class{constructor(s,r,t){M(this,"_image");this._injector=t,this._image={drawingId:c.generateRandomId(6),drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c.ImageSourceType.BASE64,source:"",unitId:s,subUnitId:r,column:0,columnOffset:0,row:0,rowOffset:0,width:0,height:0}}setImage(s){const t=this._injector.get(C.IRenderManagerService).getRenderById(s.unitId);if(!t)throw new Error(`Render Unit with unitId ${s.unitId} not found`);const e=t.with(D.SheetSkeletonManagerService);return s.sheetTransform==null&&(s.sheetTransform={from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}),this._image=B(s,e),this}setSource(s,r){const t=r!=null?r:c.ImageSourceType.URL;return this._image.source=s,this._image.imageSourceType=t,this}getSource(){return this._image.source}getSourceType(){return this._image.imageSourceType}setColumn(s){return this._image.column=s,this}setRow(s){return this._image.row=s,this}setColumnOffset(s){return this._image.columnOffset=s,this}setRowOffset(s){return this._image.rowOffset=s,this}setWidth(s){return this._image.width=s,this}setHeight(s){return this._image.height=s,this}setAnchorType(s){return this._image.anchorType=s,this}setCropTop(s){return this._initializeSrcRect(),this._image.srcRect.top=s,this}setCropLeft(s){return this._initializeSrcRect(),this._image.srcRect.left=s,this}setCropBottom(s){return this._initializeSrcRect(),this._image.srcRect.bottom=s,this}setCropRight(s){return this._initializeSrcRect(),this._image.srcRect.right=s,this}_initializeSrcRect(){this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0})}setRotate(s){return this._image.angle=s,this}setUnitId(s){return this._image.unitId=s,this}setSubUnitId(s){return this._image.subUnitId=s,this}async buildAsync(){const r=this._injector.get(C.IRenderManagerService).getRenderById(this._image.unitId);if(!r)throw new Error(`Render Unit with unitId ${this._image.unitId} not found`);const t=r.with(D.ISheetSelectionRenderService),e=r.with(D.SheetSkeletonManagerService);if(this._image.width===0||this._image.height===0){const n=await f.getImageSize(this._image.source),i=n.width,a=n.height;this._image.width===0&&(this._image.width=i),this._image.height===0&&(this._image.height=a)}return j(this._image,t,e)}};y=T([R(2,c.Inject(c.Injector))],y);let p=class extends l.FBase{constructor(s,r,t){super(),this._image=s,this._commandService=r,this._injector=t}getId(){return this._image.drawingId}getType(){return this._image.drawingType}remove(){return this._commandService.syncExecuteCommand(m.RemoveSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}toBuilder(){const s=this._injector.createInstance(y);return s.setImage(this._image),s}setSource(s,r){const t=r!=null?r:c.ImageSourceType.URL;return this._image.source=s,this._image.imageSourceType=t,this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}async setPositionAsync(s,r,t,e){const n=this.toBuilder();n.setColumn(r),n.setRow(s),t!=null&&n.setRowOffset(t),e!=null&&n.setColumnOffset(e);const i=await n.buildAsync();return this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[i]})}async setSizeAsync(s,r){const t=this.toBuilder();t.setWidth(s),t.setHeight(r);const e=await t.buildAsync();return this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[e]})}setCrop(s,r,t,e){return this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0}),s!=null&&(this._image.srcRect.top=s),r!=null&&(this._image.srcRect.left=r),t!=null&&(this._image.srcRect.bottom=t),e!=null&&(this._image.srcRect.right=e),this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}setRotate(s){return this._image.sheetTransform.angle=s,this._image.transform&&(this._image.transform.angle=s),this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}setForward(){return this._commandService.syncExecuteCommand(m.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:c.ArrangeTypeEnum.forward})}setBackward(){return this._commandService.syncExecuteCommand(m.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:c.ArrangeTypeEnum.backward})}setBack(){return this._commandService.syncExecuteCommand(m.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:c.ArrangeTypeEnum.back})}setFront(){return this._commandService.syncExecuteCommand(m.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:c.ArrangeTypeEnum.front})}};p=T([R(1,c.ICommandService),R(2,c.Inject(c.Injector))],p);class x extends E.FWorksheet{getFloatDomById(r){const e=this._injector.get(m.SheetCanvasFloatDomManagerService).getFloatDomInfo(r);if(!e)return null;const{unitId:n,subUnitId:i}=e,{rect:a}=e,o=a.getState(),{left:d=0,top:h=0,width:g=0,height:u=0,flipX:v=!1,flipY:_=!1,angle:I=0,skewX:S=0,skewY:O=0}=o,k=this._injector.get(w.ISheetDrawingService).getDrawingByParam({drawingId:e.id,unitId:n,subUnitId:i});return k?{position:{left:d,top:h,width:g,height:u,flipX:v,flipY:_,angle:I,skewX:S,skewY:O},componentKey:k.componentKey,allowTransform:k.allowTransform,data:k.data,id:e.id}:null}getAllFloatDoms(){const r=this._injector.get(m.SheetCanvasFloatDomManagerService),t=this._workbook.getUnitId(),e=this._worksheet.getSheetId();return Array.from(r.getFloatDomsBySubUnitId(t,e).values()).map(n=>{const{rect:i}=n,a=this._injector.get(w.ISheetDrawingService).getDrawingByParam({drawingId:n.id,unitId:t,subUnitId:e}),{left:o,top:d,width:h,height:g,flipX:u,flipY:v,angle:_,skewX:I,skewY:S}=i.getState();return{position:{left:o,top:d,width:h,height:g,flipX:u,flipY:v,angle:_,skewX:I,skewY:S},componentKey:a.componentKey,allowTransform:a.allowTransform,data:a.data,id:n.id}})}updateFloatDom(r,t){var I,S;const n=this._injector.get(m.SheetCanvasFloatDomManagerService).getFloatDomInfo(r);if(!n)return this;const{unitId:i,subUnitId:a}=n,o=this._injector.get(w.ISheetDrawingService).getDrawingByParam({unitId:i,subUnitId:a,drawingId:r}),d=this._injector.get(C.IRenderManagerService);if(!d.getRenderById(i))return this;if(!this.getSkeleton())return this;const u=(I=d.getRenderById(this.getWorkbook().getUnitId()))==null?void 0:I.with(D.ISheetSelectionRenderService);if(!u)return this;const v={...o,componentKey:t.componentKey||o.componentKey,allowTransform:t.allowTransform!==void 0?t.allowTransform:o.allowTransform,data:t.data||o.data,sheetTransform:t.position&&(S=m.transformToDrawingPosition(t.position,u))!=null?S:o.sheetTransform,transform:{...o.transform,...t.position}};if(!this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:i,subUnitId:a,drawings:[v]}))throw new Error("updateFloatDom failed");return this}batchUpdateFloatDoms(r){var a;const t=this._injector.get(m.SheetCanvasFloatDomManagerService),e=this._injector.get(w.ISheetDrawingService),n=this._injector.get(C.IRenderManagerService),i=[];for(const o of r){const d=t.getFloatDomInfo(o.id);if(!d)continue;const{unitId:h,subUnitId:g}=d,u=e.getDrawingByParam({unitId:h,subUnitId:g,drawingId:o.id});if(!u)continue;const v=n.getRenderById(h);if(!v||!this.getSkeleton())continue;const I=v.with(D.ISheetSelectionRenderService);if(!I)return this;const S={...u,componentKey:o.config.componentKey||u.componentKey,allowTransform:o.config.allowTransform!==void 0?o.config.allowTransform:u.allowTransform,data:o.config.data||u.data,sheetTransform:o.config.position&&(a=m.transformToDrawingPosition(o.config.position,I))!=null?a:u.sheetTransform,transform:{...u.transform,...o.config.position}};i.push(S)}if(i.length>0){const o=this._workbook.getUnitId(),d=this._worksheet.getSheetId();if(!this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:o,subUnitId:d,drawings:i}))throw new Error("batchUpdateFloatDoms failed")}return this}removeFloatDom(r){const e=this._injector.get(m.SheetCanvasFloatDomManagerService).getFloatDomInfo(r);if(!e)return this;const{unitId:n,subUnitId:i}=e,o=this._injector.get(w.ISheetDrawingService).getDrawingByParam({unitId:n,subUnitId:i,drawingId:r});if(!o)return this;if(!this._commandService.syncExecuteCommand(m.RemoveSheetDrawingCommand.id,{unitId:n,drawings:[o]}))throw new Error("removeFloatDom failed");return this}addFloatDomToPosition(r,t){const e=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),{key:i,disposableCollection:a}=b.transformComponentKey(r,this._injector.get(F.ComponentManager)),d=this._injector.get(m.SheetCanvasFloatDomManagerService).addFloatDomToPosition({...r,componentKey:i,unitId:e,subUnitId:n},t);return d?(a.add(d.dispose),{id:d.id,dispose:()=>{a.dispose(),d.dispose()}}):(a.dispose(),null)}addFloatDomToRange(r,t,e,n){const i=this._workbook.getUnitId(),a=this._worksheet.getSheetId(),{key:o,disposableCollection:d}=b.transformComponentKey(t,this._injector.get(F.ComponentManager)),g=this._injector.get(m.SheetCanvasFloatDomManagerService).addFloatDomToRange(r.getRange(),{...t,componentKey:o,unitId:i,subUnitId:a},e,n);return g?(d.add(g.dispose),{id:g.id,dispose:()=>{d.dispose(),g.dispose()}}):(d.dispose(),null)}addFloatDomToColumnHeader(r,t,e,n){const i=this._workbook.getUnitId(),a=this._worksheet.getSheetId(),{key:o,disposableCollection:d}=b.transformComponentKey(t,this._injector.get(F.ComponentManager)),g=this._injector.get(m.SheetCanvasFloatDomManagerService).addFloatDomToColumnHeader(r,{...t,componentKey:o,unitId:i,subUnitId:a},e,n);return g?(d.add(g.dispose),{id:g.id,dispose:()=>{d.dispose(),g.dispose()}}):(d.dispose(),null)}async insertImage(r,t,e,n,i){const a=this.newOverGridImage();if(typeof r=="string")a.setSource(r);else{const h=await r.getBlob().getDataAsString();a.setSource(h,c.ImageSourceType.BASE64)}t!==void 0?a.setColumn(t):a.setColumn(0),e!==void 0?a.setRow(e):a.setRow(0),n!==void 0?a.setColumnOffset(n):a.setColumnOffset(0),i!==void 0?a.setRowOffset(i):a.setRowOffset(0);const o=await a.buildAsync();return this._commandService.syncExecuteCommand(m.InsertSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:[o]})}insertImages(r){const t=r.map(e=>(e.unitId=this._fWorkbook.getId(),e.subUnitId=this.getSheetId(),e));return this._commandService.syncExecuteCommand(m.InsertSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}deleteImages(r){const t=r.map(e=>({unitId:this._fWorkbook.getId(),drawingId:e.getId(),subUnitId:this.getSheetId(),drawingType:e.getType()}));return this._commandService.syncExecuteCommand(m.RemoveSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}getImages(){const t=this._injector.get(w.ISheetDrawingService).getDrawingData(this._fWorkbook.getId(),this.getSheetId()),e=[];for(const n in t){const i=t[n];i.drawingType===c.DrawingTypeEnum.DRAWING_IMAGE&&e.push(this._injector.createInstance(p,i))}return e}getImageById(r){const e=this._injector.get(w.ISheetDrawingService).getDrawingByParam({unitId:this._fWorkbook.getId(),subUnitId:this.getSheetId(),drawingId:r});return e&&e.drawingType===c.DrawingTypeEnum.DRAWING_IMAGE?this._injector.createInstance(p,e):null}getActiveImages(){const t=this._injector.get(w.ISheetDrawingService).getFocusDrawings(),e=[];for(const n in t){const i=t[n];e.push(this._injector.createInstance(p,i))}return e}updateImages(r){return this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:r}),this}onImageInserted(r){const t=this._injector.get(w.ISheetDrawingService);return c.toDisposable(t.add$.subscribe(e=>{const n=e.map(i=>this._injector.createInstance(p,t.getDrawingByParam(i)));r(n)}))}onImageDeleted(r){const t=this._injector.get(w.ISheetDrawingService);return c.toDisposable(t.remove$.subscribe(e=>{const n=e.map(i=>this._injector.createInstance(p,t.getDrawingByParam(i)));r(n)}))}onImageChanged(r){const t=this._injector.get(w.ISheetDrawingService);return c.toDisposable(t.update$.subscribe(e=>{const n=e.map(i=>this._injector.createInstance(p,t.getDrawingByParam(i)));r(n)}))}newOverGridImage(){const r=this._fWorkbook.getId(),t=this.getSheetId();return this._injector.createInstance(y,r,t)}async saveCellImagesAsync(r,t){var u;const e=this._injector.get(m.IBatchSaveImagesService),n=this._fWorkbook.getId(),i=this.getSheetId(),a=t?t.map(v=>v.getRange()):[this._worksheet.getCellMatrix().getDataRange()],o=e.getCellImagesFromRanges(n,i,a);if(o.length===0)return!1;if(o.length===1)try{return await e.downloadSingleImage(o[0]),!0}catch(v){return console.error("Failed to download image:",v),!1}const d=[],h=(u=r==null?void 0:r.useCellAddress)!=null?u:!0,g=r==null?void 0:r.useColumnIndex;h&&d.push(m.FileNamePart.CELL_ADDRESS),g!==void 0&&d.push(m.FileNamePart.COLUMN_VALUE),d.length===0&&d.push(m.FileNamePart.CELL_ADDRESS);try{return await e.saveImagesWithContext(o,{fileNameParts:d,columnIndex:g},n,i),!0}catch(v){return console.error("Failed to save images:",v),!1}}}E.FWorksheet.extend(x);class G extends l.FEnum{get DrawingType(){return c.DrawingTypeEnum}get ImageSourceType(){return c.ImageSourceType}get SheetDrawingAnchorType(){return w.SheetDrawingAnchorType}}l.FEnum.extend(G);class W extends l.FEventName{get BeforeFloatDomAdd(){return"BeforeFloatDomAdd"}get FloatDomAdded(){return"FloatDomAdded"}get BeforeFloatDomUpdate(){return"BeforeFloatDomUpdate"}get FloatDomUpdated(){return"FloatDomUpdated"}get BeforeFloatDomDelete(){return"BeforeFloatDomDelete"}get FloatDomDeleted(){return"FloatDomDeleted"}get BeforeOverGridImageChange(){return"BeforeOverGridImageChange"}get OverGridImageChanged(){return"OverGridImageChanged"}get BeforeOverGridImageInsert(){return"BeforeOverGridImageInsert"}get OverGridImageInserted(){return"OverGridImageInserted"}get BeforeOverGridImageRemove(){return"BeforeOverGridImageRemove"}get OverGridImageRemoved(){return"OverGridImageRemoved"}get BeforeOverGridImageSelect(){return"BeforeOverGridImageSelect"}get OverGridImageSelected(){return"OverGridImageSelected"}}l.FEventName.extend(W);class P extends l.FUniver{_initialize(r){const t=r.get(c.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.BeforeFloatDomAdd,()=>t.beforeCommandExecuted(e=>{if(e.id!==m.InsertSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:a}=n,o=a.filter(h=>h.drawingType===c.DrawingTypeEnum.DRAWING_DOM);if(o.length===0)return;const d={workbook:i,drawings:o};if(this.fireEvent(this.Event.BeforeFloatDomAdd,d),d.cancel)throw new c.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.FloatDomAdded,()=>t.onCommandExecuted(e=>{if(e.id!==m.InsertSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:a}=n,o=a.filter(d=>d.drawingType===c.DrawingTypeEnum.DRAWING_DOM);o.length!==0&&this.fireEvent(this.Event.FloatDomAdded,{workbook:i,drawings:o})}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageInsert,()=>t.beforeCommandExecuted(e=>{if(e.id!==m.InsertSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:a}=n,o={workbook:i,insertImageParams:a};if(this.fireEvent(this.Event.BeforeOverGridImageInsert,o),o.cancel)throw new c.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageRemove,()=>t.beforeCommandExecuted(e=>{if(e.id!==m.RemoveSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const a=r.get(f.IDrawingManagerService),{drawings:o}=n,d=o.map(g=>a.getDrawingByParam(g)),h={workbook:i,images:this._createFOverGridImage(d)};if(this.fireEvent(this.Event.BeforeOverGridImageRemove,h),h.cancel)throw new c.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageChange,()=>t.beforeCommandExecuted(e=>{if(e.id!==m.SetSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:a}=n,o=r.get(f.IDrawingManagerService),d=[];a.forEach(g=>{const u=o.getDrawingByParam(g);u!=null&&d.push({changeParam:g,image:this._injector.createInstance(p,u)})});const h={workbook:i,images:d};if(this.fireEvent(this.Event.BeforeOverGridImageChange,h),h.cancel)throw o.updateNotification(a),new c.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeFloatDomUpdate,()=>t.beforeCommandExecuted(e=>{if(e.id!==m.SetSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:a}=n,o=r.get(f.IDrawingManagerService),d=[];if(a.forEach(g=>{const u=o.getDrawingByParam(g);(u==null?void 0:u.drawingType)===c.DrawingTypeEnum.DRAWING_DOM&&d.push(u)}),d.length===0)return;const h={workbook:i,drawings:d};if(this.fireEvent(this.Event.BeforeFloatDomUpdate,h),h.cancel)throw o.updateNotification(a),new c.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.FloatDomUpdated,()=>t.onCommandExecuted(e=>{if(e.id!==m.SetSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:a}=n,o=r.get(f.IDrawingManagerService),d=[];a.forEach(h=>{const g=o.getDrawingByParam(h);(g==null?void 0:g.drawingType)===c.DrawingTypeEnum.DRAWING_DOM&&d.push(g)}),d.length!==0&&this.fireEvent(this.Event.FloatDomUpdated,{workbook:i,drawings:d})}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeFloatDomDelete,()=>t.beforeCommandExecuted(e=>{if(e.id!==m.RemoveSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const a=r.get(f.IDrawingManagerService),{drawings:o}=n,d=o.map(g=>a.getDrawingByParam(g)).filter(g=>(g==null?void 0:g.drawingType)===c.DrawingTypeEnum.DRAWING_DOM);if(d.length===0)return;const h={workbook:i,drawings:d};if(this.fireEvent(this.Event.BeforeFloatDomDelete,h),h.cancel)throw new c.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.FloatDomDeleted,()=>t.onCommandExecuted(e=>{if(e.id!==m.RemoveSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:a}=n;this.fireEvent(this.Event.FloatDomDeleted,{workbook:i,drawings:a.filter(o=>o.drawingType===c.DrawingTypeEnum.DRAWING_DOM).map(o=>o.drawingId)})}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageSelect,()=>t.beforeCommandExecuted(e=>{if(e.id!==f.SetDrawingSelectedOperation.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null)return;const a=r.get(f.IDrawingManagerService),o=a.getFocusDrawings(),d=n.map(g=>a.getDrawingByParam(g)),h={workbook:i,selectedImages:this._createFOverGridImage(d),oldSelectedImages:this._createFOverGridImage(o)};if(this.fireEvent(this.Event.BeforeOverGridImageSelect,h),h.cancel)throw new c.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageInserted,()=>t.onCommandExecuted(e=>{if(e.id!==m.InsertSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:a}=n;this.fireEvent(this.Event.OverGridImageInserted,{workbook:i,images:this._createFOverGridImage(a)})}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageRemoved,()=>t.onCommandExecuted(e=>{if(e.id!==m.RemoveSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:a}=n;this.fireEvent(this.Event.OverGridImageRemoved,{workbook:i,removeImageParams:a})}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageChanged,()=>t.onCommandExecuted(e=>{if(e.id!==m.SetSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:a}=n,o=r.get(f.IDrawingManagerService),d=a.map(h=>this._injector.createInstance(p,o.getDrawingByParam(h)));this.fireEvent(this.Event.OverGridImageChanged,{workbook:i,images:d})}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageSelected,()=>t.onCommandExecuted(e=>{if(e.id!==f.SetDrawingSelectedOperation.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null)return;const a=r.get(f.IDrawingManagerService),o=n.map(d=>a.getDrawingByParam(d));this.fireEvent(this.Event.OverGridImageSelected,{workbook:i,selectedImages:this._createFOverGridImage(o)})})))}_createFOverGridImage(r){return r.map(t=>this._injector.createInstance(p,t))}registerURLImageDownloader(r){return this._injector.get(c.IURLImageService).registerURLImageDownloader(r)}}l.FUniver.extend(P);class U extends E.FRange{async insertCellImageAsync(r){var i;const t=this._injector.get(C.IRenderManagerService),e=(i=C.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,this._injector.get(c.IUniverInstanceService),t))==null?void 0:i.with(m.SheetDrawingUpdateController);if(!e)return!1;const n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this.getRow(),col:this.getColumn()};return typeof r=="string"?e.insertCellImageByUrl(r,n):e.insertCellImageByFile(r,n)}async saveCellImagesAsync(r){var g;const t=this._injector.get(m.IBatchSaveImagesService),e=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i=this.getRange(),a=t.getCellImagesFromRanges(e,n,[i]);if(a.length===0)return!1;if(a.length===1)try{return await t.downloadSingleImage(a[0]),!0}catch(u){return console.error("Failed to download image:",u),!1}const o=[],d=(g=r==null?void 0:r.useCellAddress)!=null?g:!0,h=r==null?void 0:r.useColumnIndex;d&&o.push(m.FileNamePart.CELL_ADDRESS),h!==void 0&&o.push(m.FileNamePart.COLUMN_VALUE),o.length===0&&o.push(m.FileNamePart.CELL_ADDRESS);try{return await t.saveImagesWithContext(a,{fileNameParts:o,columnIndex:h},e,n),!0}catch(u){return console.error("Failed to save images:",u),!1}}}E.FRange.extend(U)}));
19
+ (function(c,f){typeof exports=="object"&&typeof module<"u"?f(require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing-ui"),require("@univerjs/sheets-ui"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui/facade"),require("@univerjs/sheets/facade"),require("@univerjs/ui")):typeof define=="function"&&define.amd?define(["@univerjs/core","@univerjs/core/facade","@univerjs/drawing","@univerjs/engine-render","@univerjs/sheets-drawing-ui","@univerjs/sheets-ui","@univerjs/sheets-drawing","@univerjs/sheets-ui/facade","@univerjs/sheets/facade","@univerjs/ui"],f):(c=typeof globalThis<"u"?globalThis:c||self,f(c.UniverCore,c.UniverCoreFacade,c.UniverDrawing,c.UniverEngineRender,c.UniverSheetsDrawingUi,c.UniverSheetsUi,c.UniverSheetsDrawing,c.UniverSheetsUiFacade,c.UniverSheetsFacade,c.UniverUi))})(this,(function(c,f,v,E,m,C,w,R,y,T){"use strict";var N=Object.defineProperty;var H=(c,f,v)=>f in c?N(c,f,{enumerable:!0,configurable:!0,writable:!0,value:v}):c[f]=v;var A=(c,f,v)=>H(c,typeof f!="symbol"?f+"":f,v);var M=Object.getOwnPropertyDescriptor,O=(s,r,t,e)=>{for(var n=e>1?void 0:e?M(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},F=(s,r)=>(t,e)=>r(t,e,s);function B(s,r){const{from:t,to:e,flipY:n=!1,flipX:i=!1,angle:o=0,skewX:d=0,skewY:a=0}=s.sheetTransform,{column:h,columnOffset:g,row:u,rowOffset:l}=t,p=C.convertPositionSheetOverGridToAbsolute(s.unitId,s.subUnitId,{from:t,to:e},r),{width:_,height:I}=p;return{...s,column:h,columnOffset:g,row:u,rowOffset:l,width:_,height:I,flipY:n,flipX:i,angle:o,skewX:d,skewY:a}}function x(s,r,t){const{column:e,columnOffset:n,row:i,rowOffset:o,flipY:d=!1,flipX:a=!1,angle:h=0,skewX:g=0,skewY:u=0,width:l,height:p}=s,_=C.convertPositionCellToSheetOverGrid(s.unitId,s.subUnitId,{column:e,columnOffset:n,row:i,rowOffset:o},l,p,r,t),{sheetTransform:I,transform:D}=_;return{...s,sheetTransform:{...I,flipY:d,flipX:a,angle:h,skewX:g,skewY:u},transform:{...D,flipY:d,flipX:a,angle:h,skewX:g,skewY:u},axisAlignSheetTransform:m.transformToAxisAlignPosition(D,r)}}let k=class{constructor(s,r,t){A(this,"_image");this._injector=t,this._image={drawingId:c.generateRandomId(6),drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c.ImageSourceType.BASE64,source:"",unitId:s,subUnitId:r,column:0,columnOffset:0,row:0,rowOffset:0,width:0,height:0,axisAlignSheetTransform:{from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}}}setImage(s){const t=this._injector.get(E.IRenderManagerService).getRenderById(s.unitId);if(!t)throw new Error(`Render Unit with unitId ${s.unitId} not found`);const e=t.with(C.SheetSkeletonManagerService);return s.sheetTransform==null&&(s.sheetTransform={from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}),s.axisAlignSheetTransform==null&&(s.axisAlignSheetTransform={from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}),this._image=B(s,e),this}setSource(s,r){const t=r!=null?r:c.ImageSourceType.URL;return this._image.source=s,this._image.imageSourceType=t,this}getSource(){return this._image.source}getSourceType(){return this._image.imageSourceType}setColumn(s){return this._image.column=s,this}setRow(s){return this._image.row=s,this}setColumnOffset(s){return this._image.columnOffset=s,this}setRowOffset(s){return this._image.rowOffset=s,this}setWidth(s){return this._image.width=s,this}setHeight(s){return this._image.height=s,this}setAnchorType(s){return this._image.anchorType=s,this}setCropTop(s){return this._initializeSrcRect(),this._image.srcRect.top=s,this}setCropLeft(s){return this._initializeSrcRect(),this._image.srcRect.left=s,this}setCropBottom(s){return this._initializeSrcRect(),this._image.srcRect.bottom=s,this}setCropRight(s){return this._initializeSrcRect(),this._image.srcRect.right=s,this}_initializeSrcRect(){this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0})}setRotate(s){return this._image.angle=s,this}setUnitId(s){return this._image.unitId=s,this}setSubUnitId(s){return this._image.subUnitId=s,this}async buildAsync(){const r=this._injector.get(E.IRenderManagerService).getRenderById(this._image.unitId);if(!r)throw new Error(`Render Unit with unitId ${this._image.unitId} not found`);const t=r.with(C.ISheetSelectionRenderService),e=r.with(C.SheetSkeletonManagerService);if(this._image.width===0||this._image.height===0){const n=await v.getImageSize(this._image.source),i=n.width,o=n.height;this._image.width===0&&(this._image.width=i),this._image.height===0&&(this._image.height=o)}return x(this._image,t,e)}};k=O([F(2,c.Inject(c.Injector))],k);let S=class extends f.FBase{constructor(s,r,t){super(),this._image=s,this._commandService=r,this._injector=t}getId(){return this._image.drawingId}getType(){return this._image.drawingType}remove(){return this._commandService.syncExecuteCommand(m.RemoveSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}toBuilder(){const s=this._injector.createInstance(k);return s.setImage(this._image),s}setSource(s,r){const t=r!=null?r:c.ImageSourceType.URL;return this._image.source=s,this._image.imageSourceType=t,this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}async setPositionAsync(s,r,t,e){const n=this.toBuilder();n.setColumn(r),n.setRow(s),t!=null&&n.setRowOffset(t),e!=null&&n.setColumnOffset(e);const i=await n.buildAsync();return this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[i]})}async setSizeAsync(s,r){const t=this.toBuilder();t.setWidth(s),t.setHeight(r);const e=await t.buildAsync();return this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[e]})}setCrop(s,r,t,e){return this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0}),s!=null&&(this._image.srcRect.top=s),r!=null&&(this._image.srcRect.left=r),t!=null&&(this._image.srcRect.bottom=t),e!=null&&(this._image.srcRect.right=e),this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}setRotate(s){if(this._image.sheetTransform.angle=s,this._image.transform&&(this._image.transform.angle=s),this._image.transform){const t=this._injector.get(E.IRenderManagerService).getRenderById(this._image.unitId);if(!t)throw new Error(`Render Unit with unitId ${this._image.unitId} not found`);const e=t.with(C.ISheetSelectionRenderService);this._image.axisAlignSheetTransform&&(this._image.axisAlignSheetTransform=m.transformToAxisAlignPosition(this._image.transform,e))}return this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}setForward(){return this._commandService.syncExecuteCommand(m.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:c.ArrangeTypeEnum.forward})}setBackward(){return this._commandService.syncExecuteCommand(m.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:c.ArrangeTypeEnum.backward})}setBack(){return this._commandService.syncExecuteCommand(m.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:c.ArrangeTypeEnum.back})}setFront(){return this._commandService.syncExecuteCommand(m.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:c.ArrangeTypeEnum.front})}};S=O([F(1,c.ICommandService),F(2,c.Inject(c.Injector))],S);class j extends y.FWorksheet{getFloatDomById(r){const e=this._injector.get(m.SheetCanvasFloatDomManagerService).getFloatDomInfo(r);if(!e)return null;const{unitId:n,subUnitId:i}=e,{rect:o}=e,d=o.getState(),{left:a=0,top:h=0,width:g=0,height:u=0,flipX:l=!1,flipY:p=!1,angle:_=0,skewX:I=0,skewY:D=0}=d,b=this._injector.get(w.ISheetDrawingService).getDrawingByParam({drawingId:e.id,unitId:n,subUnitId:i});return b?{position:{left:a,top:h,width:g,height:u,flipX:l,flipY:p,angle:_,skewX:I,skewY:D},componentKey:b.componentKey,allowTransform:b.allowTransform,data:b.data,id:e.id}:null}getAllFloatDoms(){const r=this._injector.get(m.SheetCanvasFloatDomManagerService),t=this._workbook.getUnitId(),e=this._worksheet.getSheetId();return Array.from(r.getFloatDomsBySubUnitId(t,e).values()).map(n=>{const{rect:i}=n,o=this._injector.get(w.ISheetDrawingService).getDrawingByParam({drawingId:n.id,unitId:t,subUnitId:e}),{left:d,top:a,width:h,height:g,flipX:u,flipY:l,angle:p,skewX:_,skewY:I}=i.getState();return{position:{left:d,top:a,width:h,height:g,flipX:u,flipY:l,angle:p,skewX:_,skewY:I},componentKey:o.componentKey,allowTransform:o.allowTransform,data:o.data,id:n.id}})}updateFloatDom(r,t){var _,I,D;const n=this._injector.get(m.SheetCanvasFloatDomManagerService).getFloatDomInfo(r);if(!n)return this;const{unitId:i,subUnitId:o}=n,d=this._injector.get(w.ISheetDrawingService).getDrawingByParam({unitId:i,subUnitId:o,drawingId:r}),a=this._injector.get(E.IRenderManagerService);if(!a.getRenderById(i))return this;if(!this.getSkeleton())return this;const u=(_=a.getRenderById(this.getWorkbook().getUnitId()))==null?void 0:_.with(C.ISheetSelectionRenderService);if(!u)return this;const l={...d,componentKey:t.componentKey||d.componentKey,allowTransform:t.allowTransform!==void 0?t.allowTransform:d.allowTransform,data:t.data||d.data,sheetTransform:t.position&&(I=m.transformToDrawingPosition(t.position,u))!=null?I:d.sheetTransform,transform:{...d.transform,...t.position},axisAlignSheetTransform:t.position&&(D=m.transformToAxisAlignPosition(t.position,u))!=null?D:d.sheetTransform};if(!this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:i,subUnitId:o,drawings:[l]}))throw new Error("updateFloatDom failed");return this}batchUpdateFloatDoms(r){var o,d;const t=this._injector.get(m.SheetCanvasFloatDomManagerService),e=this._injector.get(w.ISheetDrawingService),n=this._injector.get(E.IRenderManagerService),i=[];for(const a of r){const h=t.getFloatDomInfo(a.id);if(!h)continue;const{unitId:g,subUnitId:u}=h,l=e.getDrawingByParam({unitId:g,subUnitId:u,drawingId:a.id});if(!l)continue;const p=n.getRenderById(g);if(!p||!this.getSkeleton())continue;const I=p.with(C.ISheetSelectionRenderService);if(!I)return this;const D={...l,componentKey:a.config.componentKey||l.componentKey,allowTransform:a.config.allowTransform!==void 0?a.config.allowTransform:l.allowTransform,data:a.config.data||l.data,sheetTransform:a.config.position&&(o=m.transformToDrawingPosition(a.config.position,I))!=null?o:l.sheetTransform,transform:{...l.transform,...a.config.position},axisAlignSheetTransform:a.config.position&&(d=m.transformToAxisAlignPosition(a.config.position,I))!=null?d:l.sheetTransform};i.push(D)}if(i.length>0){const a=this._workbook.getUnitId(),h=this._worksheet.getSheetId();if(!this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:a,subUnitId:h,drawings:i}))throw new Error("batchUpdateFloatDoms failed")}return this}removeFloatDom(r){const e=this._injector.get(m.SheetCanvasFloatDomManagerService).getFloatDomInfo(r);if(!e)return this;const{unitId:n,subUnitId:i}=e,d=this._injector.get(w.ISheetDrawingService).getDrawingByParam({unitId:n,subUnitId:i,drawingId:r});if(!d)return this;if(!this._commandService.syncExecuteCommand(m.RemoveSheetDrawingCommand.id,{unitId:n,drawings:[d]}))throw new Error("removeFloatDom failed");return this}addFloatDomToPosition(r,t){const e=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),{key:i,disposableCollection:o}=R.transformComponentKey(r,this._injector.get(T.ComponentManager)),a=this._injector.get(m.SheetCanvasFloatDomManagerService).addFloatDomToPosition({...r,componentKey:i,unitId:e,subUnitId:n},t);return a?(o.add(a.dispose),{id:a.id,dispose:()=>{o.dispose(),a.dispose()}}):(o.dispose(),null)}addFloatDomToRange(r,t,e,n){const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),{key:d,disposableCollection:a}=R.transformComponentKey(t,this._injector.get(T.ComponentManager)),g=this._injector.get(m.SheetCanvasFloatDomManagerService).addFloatDomToRange(r.getRange(),{...t,componentKey:d,unitId:i,subUnitId:o},e,n);return g?(a.add(g.dispose),{id:g.id,dispose:()=>{a.dispose(),g.dispose()}}):(a.dispose(),null)}addFloatDomToColumnHeader(r,t,e,n){const i=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),{key:d,disposableCollection:a}=R.transformComponentKey(t,this._injector.get(T.ComponentManager)),g=this._injector.get(m.SheetCanvasFloatDomManagerService).addFloatDomToColumnHeader(r,{...t,componentKey:d,unitId:i,subUnitId:o},e,n);return g?(a.add(g.dispose),{id:g.id,dispose:()=>{a.dispose(),g.dispose()}}):(a.dispose(),null)}async insertImage(r,t,e,n,i){const o=this.newOverGridImage();if(typeof r=="string")o.setSource(r);else{const h=await r.getBlob().getDataAsString();o.setSource(h,c.ImageSourceType.BASE64)}t!==void 0?o.setColumn(t):o.setColumn(0),e!==void 0?o.setRow(e):o.setRow(0),n!==void 0?o.setColumnOffset(n):o.setColumnOffset(0),i!==void 0?o.setRowOffset(i):o.setRowOffset(0);const d=await o.buildAsync();return this._commandService.syncExecuteCommand(m.InsertSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:[d]})}insertImages(r){const t=r.map(e=>(e.unitId=this._fWorkbook.getId(),e.subUnitId=this.getSheetId(),e));return this._commandService.syncExecuteCommand(m.InsertSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}deleteImages(r){const t=r.map(e=>({unitId:this._fWorkbook.getId(),drawingId:e.getId(),subUnitId:this.getSheetId(),drawingType:e.getType()}));return this._commandService.syncExecuteCommand(m.RemoveSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}getImages(){const t=this._injector.get(w.ISheetDrawingService).getDrawingData(this._fWorkbook.getId(),this.getSheetId()),e=[];for(const n in t){const i=t[n];i.drawingType===c.DrawingTypeEnum.DRAWING_IMAGE&&e.push(this._injector.createInstance(S,i))}return e}getImageById(r){const e=this._injector.get(w.ISheetDrawingService).getDrawingByParam({unitId:this._fWorkbook.getId(),subUnitId:this.getSheetId(),drawingId:r});return e&&e.drawingType===c.DrawingTypeEnum.DRAWING_IMAGE?this._injector.createInstance(S,e):null}getActiveImages(){const t=this._injector.get(w.ISheetDrawingService).getFocusDrawings(),e=[];for(const n in t){const i=t[n];e.push(this._injector.createInstance(S,i))}return e}updateImages(r){return this._commandService.syncExecuteCommand(m.SetSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:r}),this}onImageInserted(r){const t=this._injector.get(w.ISheetDrawingService);return c.toDisposable(t.add$.subscribe(e=>{const n=e.map(i=>this._injector.createInstance(S,t.getDrawingByParam(i)));r(n)}))}onImageDeleted(r){const t=this._injector.get(w.ISheetDrawingService);return c.toDisposable(t.remove$.subscribe(e=>{const n=e.map(i=>this._injector.createInstance(S,t.getDrawingByParam(i)));r(n)}))}onImageChanged(r){const t=this._injector.get(w.ISheetDrawingService);return c.toDisposable(t.update$.subscribe(e=>{const n=e.map(i=>this._injector.createInstance(S,t.getDrawingByParam(i)));r(n)}))}newOverGridImage(){const r=this._fWorkbook.getId(),t=this.getSheetId();return this._injector.createInstance(k,r,t)}async saveCellImagesAsync(r,t){var u;const e=this._injector.get(m.IBatchSaveImagesService),n=this._fWorkbook.getId(),i=this.getSheetId(),o=t?t.map(l=>l.getRange()):[this._worksheet.getCellMatrix().getDataRange()],d=e.getCellImagesFromRanges(n,i,o);if(d.length===0)return!1;if(d.length===1)try{return await e.downloadSingleImage(d[0]),!0}catch(l){return console.error("Failed to download image:",l),!1}const a=[],h=(u=r==null?void 0:r.useCellAddress)!=null?u:!0,g=r==null?void 0:r.useColumnIndex;h&&a.push(m.FileNamePart.CELL_ADDRESS),g!==void 0&&a.push(m.FileNamePart.COLUMN_VALUE),a.length===0&&a.push(m.FileNamePart.CELL_ADDRESS);try{return await e.saveImagesWithContext(d,{fileNameParts:a,columnIndex:g},n,i),!0}catch(l){return console.error("Failed to save images:",l),!1}}}y.FWorksheet.extend(j);class P extends f.FEnum{get DrawingType(){return c.DrawingTypeEnum}get ImageSourceType(){return c.ImageSourceType}get SheetDrawingAnchorType(){return w.SheetDrawingAnchorType}}f.FEnum.extend(P);class G extends f.FEventName{get BeforeFloatDomAdd(){return"BeforeFloatDomAdd"}get FloatDomAdded(){return"FloatDomAdded"}get BeforeFloatDomUpdate(){return"BeforeFloatDomUpdate"}get FloatDomUpdated(){return"FloatDomUpdated"}get BeforeFloatDomDelete(){return"BeforeFloatDomDelete"}get FloatDomDeleted(){return"FloatDomDeleted"}get BeforeOverGridImageChange(){return"BeforeOverGridImageChange"}get OverGridImageChanged(){return"OverGridImageChanged"}get BeforeOverGridImageInsert(){return"BeforeOverGridImageInsert"}get OverGridImageInserted(){return"OverGridImageInserted"}get BeforeOverGridImageRemove(){return"BeforeOverGridImageRemove"}get OverGridImageRemoved(){return"OverGridImageRemoved"}get BeforeOverGridImageSelect(){return"BeforeOverGridImageSelect"}get OverGridImageSelected(){return"OverGridImageSelected"}}f.FEventName.extend(G);class W extends f.FUniver{_initialize(r){const t=r.get(c.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.BeforeFloatDomAdd,()=>t.beforeCommandExecuted(e=>{if(e.id!==m.InsertSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:o}=n,d=o.filter(h=>h.drawingType===c.DrawingTypeEnum.DRAWING_DOM);if(d.length===0)return;const a={workbook:i,drawings:d};if(this.fireEvent(this.Event.BeforeFloatDomAdd,a),a.cancel)throw new c.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.FloatDomAdded,()=>t.onCommandExecuted(e=>{if(e.id!==m.InsertSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:o}=n,d=o.filter(a=>a.drawingType===c.DrawingTypeEnum.DRAWING_DOM);d.length!==0&&this.fireEvent(this.Event.FloatDomAdded,{workbook:i,drawings:d})}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageInsert,()=>t.beforeCommandExecuted(e=>{if(e.id!==m.InsertSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:o}=n,d={workbook:i,insertImageParams:o};if(this.fireEvent(this.Event.BeforeOverGridImageInsert,d),d.cancel)throw new c.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageRemove,()=>t.beforeCommandExecuted(e=>{if(e.id!==m.RemoveSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const o=r.get(v.IDrawingManagerService),{drawings:d}=n,a=d.map(g=>o.getDrawingByParam(g)),h={workbook:i,images:this._createFOverGridImage(a)};if(this.fireEvent(this.Event.BeforeOverGridImageRemove,h),h.cancel)throw new c.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageChange,()=>t.beforeCommandExecuted(e=>{if(e.id!==m.SetSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:o}=n,d=r.get(v.IDrawingManagerService),a=[];o.forEach(g=>{const u=d.getDrawingByParam(g);u!=null&&a.push({changeParam:g,image:this._injector.createInstance(S,u)})});const h={workbook:i,images:a};if(this.fireEvent(this.Event.BeforeOverGridImageChange,h),h.cancel)throw d.updateNotification(o),new c.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeFloatDomUpdate,()=>t.beforeCommandExecuted(e=>{if(e.id!==m.SetSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:o}=n,d=r.get(v.IDrawingManagerService),a=[];if(o.forEach(g=>{const u=d.getDrawingByParam(g);(u==null?void 0:u.drawingType)===c.DrawingTypeEnum.DRAWING_DOM&&a.push(u)}),a.length===0)return;const h={workbook:i,drawings:a};if(this.fireEvent(this.Event.BeforeFloatDomUpdate,h),h.cancel)throw d.updateNotification(o),new c.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.FloatDomUpdated,()=>t.onCommandExecuted(e=>{if(e.id!==m.SetSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:o}=n,d=r.get(v.IDrawingManagerService),a=[];o.forEach(h=>{const g=d.getDrawingByParam(h);(g==null?void 0:g.drawingType)===c.DrawingTypeEnum.DRAWING_DOM&&a.push(g)}),a.length!==0&&this.fireEvent(this.Event.FloatDomUpdated,{workbook:i,drawings:a})}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeFloatDomDelete,()=>t.beforeCommandExecuted(e=>{if(e.id!==m.RemoveSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const o=r.get(v.IDrawingManagerService),{drawings:d}=n,a=d.map(g=>o.getDrawingByParam(g)).filter(g=>(g==null?void 0:g.drawingType)===c.DrawingTypeEnum.DRAWING_DOM);if(a.length===0)return;const h={workbook:i,drawings:a};if(this.fireEvent(this.Event.BeforeFloatDomDelete,h),h.cancel)throw new c.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.FloatDomDeleted,()=>t.onCommandExecuted(e=>{if(e.id!==m.RemoveSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:o}=n;this.fireEvent(this.Event.FloatDomDeleted,{workbook:i,drawings:o.filter(d=>d.drawingType===c.DrawingTypeEnum.DRAWING_DOM).map(d=>d.drawingId)})}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeOverGridImageSelect,()=>t.beforeCommandExecuted(e=>{if(e.id!==v.SetDrawingSelectedOperation.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null)return;const o=r.get(v.IDrawingManagerService),d=o.getFocusDrawings(),a=n.map(g=>o.getDrawingByParam(g)),h={workbook:i,selectedImages:this._createFOverGridImage(a),oldSelectedImages:this._createFOverGridImage(d)};if(this.fireEvent(this.Event.BeforeOverGridImageSelect,h),h.cancel)throw new c.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageInserted,()=>t.onCommandExecuted(e=>{if(e.id!==m.InsertSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:o}=n;this.fireEvent(this.Event.OverGridImageInserted,{workbook:i,images:this._createFOverGridImage(o)})}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageRemoved,()=>t.onCommandExecuted(e=>{if(e.id!==m.RemoveSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:o}=n;this.fireEvent(this.Event.OverGridImageRemoved,{workbook:i,removeImageParams:o})}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageChanged,()=>t.onCommandExecuted(e=>{if(e.id!==m.SetSheetDrawingCommand.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null||n==null)return;const{drawings:o}=n,d=r.get(v.IDrawingManagerService),a=o.map(h=>this._injector.createInstance(S,d.getDrawingByParam(h)));this.fireEvent(this.Event.OverGridImageChanged,{workbook:i,images:a})}))),this.disposeWithMe(this.registerEventHandler(this.Event.OverGridImageSelected,()=>t.onCommandExecuted(e=>{if(e.id!==v.SetDrawingSelectedOperation.id)return;const n=e.params,i=this.getActiveWorkbook();if(i==null)return;const o=r.get(v.IDrawingManagerService),d=n.map(a=>o.getDrawingByParam(a));this.fireEvent(this.Event.OverGridImageSelected,{workbook:i,selectedImages:this._createFOverGridImage(d)})})))}_createFOverGridImage(r){return r.map(t=>this._injector.createInstance(S,t))}registerURLImageDownloader(r){return this._injector.get(c.IURLImageService).registerURLImageDownloader(r)}}f.FUniver.extend(W);class U extends y.FRange{async insertCellImageAsync(r){var i;const t=this._injector.get(E.IRenderManagerService),e=(i=E.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,this._injector.get(c.IUniverInstanceService),t))==null?void 0:i.with(m.SheetDrawingUpdateController);if(!e)return!1;const n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this.getRow(),col:this.getColumn()};return typeof r=="string"?e.insertCellImageByUrl(r,n):e.insertCellImageByFile(r,n)}async saveCellImagesAsync(r){var g;const t=this._injector.get(m.IBatchSaveImagesService),e=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),i=this.getRange(),o=t.getCellImagesFromRanges(e,n,[i]);if(o.length===0)return!1;if(o.length===1)try{return await t.downloadSingleImage(o[0]),!0}catch(u){return console.error("Failed to download image:",u),!1}const d=[],a=(g=r==null?void 0:r.useCellAddress)!=null?g:!0,h=r==null?void 0:r.useColumnIndex;a&&d.push(m.FileNamePart.CELL_ADDRESS),h!==void 0&&d.push(m.FileNamePart.COLUMN_VALUE),d.length===0&&d.push(m.FileNamePart.CELL_ADDRESS);try{return await t.saveImagesWithContext(o,{fileNameParts:d,columnIndex:h},e,n),!0}catch(u){return console.error("Failed to save images:",u),!1}}}y.FRange.extend(U)}));
20
20
 
21
21
 
22
22
  // index
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/preset-sheets-drawing",
3
- "version": "0.15.4",
3
+ "version": "0.15.5",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -58,19 +58,19 @@
58
58
  "rxjs": ">=7.0.0"
59
59
  },
60
60
  "dependencies": {
61
- "@univerjs/docs-drawing": "0.15.4",
62
- "@univerjs/drawing": "0.15.4",
63
- "@univerjs/drawing-ui": "0.15.4",
64
- "@univerjs/sheets-drawing": "0.15.4",
65
- "@univerjs/sheets-drawing-ui": "0.15.4"
61
+ "@univerjs/docs-drawing": "0.15.5",
62
+ "@univerjs/drawing": "0.15.5",
63
+ "@univerjs/drawing-ui": "0.15.5",
64
+ "@univerjs/sheets-drawing": "0.15.5",
65
+ "@univerjs/sheets-drawing-ui": "0.15.5"
66
66
  },
67
67
  "devDependencies": {
68
- "@univerjs/core": "0.15.4",
68
+ "@univerjs/core": "0.15.5",
69
69
  "react": "18.3.1",
70
70
  "react-dom": "18.3.1",
71
71
  "rxjs": "7.8.2",
72
72
  "typescript": "^5.9.3",
73
- "@univerjs-infra/shared": "0.15.4"
73
+ "@univerjs-infra/shared": "0.15.5"
74
74
  },
75
75
  "scripts": {
76
76
  "prebuild:preset": "tsx prepare.ts",