@univerjs/preset-sheets-drawing 0.12.4 → 0.13.0-insiders.20251215-64041bb

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 +2 -2
  2. package/package.json +8 -8
package/lib/umd/index.js CHANGED
@@ -11,8 +11,8 @@
11
11
 
12
12
 
13
13
  // @univerjs/sheets-drawing-ui/index
14
- (function(R,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):(R=typeof globalThis<"u"?globalThis:R||self,A(R.UniverSheetsDrawingUi={},R.UniverEngineRender,R.UniverSheetsUi,R.UniverCore,R.UniverSheetsDrawing,R.UniverSheets,R.UniverDesign,R.UniverDocsUi,R.UniverDrawing,R.UniverUi,R.UniverDocsDrawing,R.UniverDrawingUi,R.rxjs,R.React,R.React))})(this,(function(R,A,b,l,w,y,Y,je,$,B,bt,ge,U,L,H){"use strict";var lr=Object.defineProperty;var ur=(R,A,b)=>A in R?lr(R,A,{enumerable:!0,configurable:!0,writable:!0,value:b}):R[A]=b;var ie=(R,A,b)=>ur(R,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 V(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 X={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}},Se={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var _,D,T;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(C=>{const{unitId:M}=C;a.push(M)});const d=o.getBatchRemoveOp(s),{unitId:g,subUnitId:u,undo:c,redo:m,objects:h}=d,p=n.onCommandExecute({id:Se.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:X.id,params:a}],redoMutations:[...(T=p.preRedos)!=null?T:[],S,...p.redos,{id:X.id,params:a}]}),!0):!1}},lt={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(Se.id,{unitId:n,drawings:o})}};function qt(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 ut={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:X.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:w.DrawingApplyType.GROUP}},{id:X.id,params:o}]}),!0):!1}},Ee={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var _,D,T;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(C=>C.unitId),d=n.getBatchAddOp(s),{unitId:g,subUnitId:u,undo:c,redo:m,objects:h}=d,p=o.onCommandExecute({id:Ee.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:X.id,params:a}],redoMutations:[...(T=p.preRedos)!=null?T:[],S,...p.redos,{id:X.id,params:a}]}),!0):!1}},gt={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}},be={id:"sheet.command.set-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{drawings:o}=r,s=n.getBatchUpdateOp(o),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=s;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:a,subUnitId:d,op:u,objects:c,type:w.DrawingApplyType.UPDATE})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:g,objects:c,type:w.DrawingApplyType.UPDATE}},{id:X.id,params:[a]}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:u,objects:c,type:w.DrawingApplyType.UPDATE}},{id:X.id,params:[a]}]}),!0):!1}},ht={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:qt(c),type:w.DrawingApplyType.GROUP}},{id:X.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:w.DrawingApplyType.UNGROUP}},{id:X.id,params:o}]}),!0):!1}};var Jt=Object.getOwnPropertyDescriptor,Qt=(i,r,e,t)=>{for(var n=t>1?void 0:t?Jt(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 en(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 mt(i,r,e,t,n){var _;const{rotatedHeight:o,rotatedWidth:s}=en(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}}R.SheetDrawingUpdateController=class extends l.Disposable{constructor(e,t,n,o,s,a,d,g,u,c,m,h,p){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._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:$.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),t=e.length;return t>$.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String($.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:$.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 T=D.message;T===$.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String($.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):T===$.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):T===$.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 $.getImageSize(u||""),{width:p,height:S}=this._context.scene;this._imageIoService.addImageSourceCache(g,d,h);let f=1;if(c>$.DRAWING_IMAGE_WIDTH_LIMIT||m>$.DRAWING_IMAGE_HEIGHT_LIMIT){const D=$.DRAWING_IMAGE_WIDTH_LIMIT/c,T=$.DRAWING_IMAGE_HEIGHT_LIMIT/m;f=Math.max(D,T)}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(Ee.id,{unitId:o,drawings:[_]})}async _insertCellImage(e,t){var T,C;let n;try{n=await this._imageIoService.saveImage(e)}catch(M){const I=M.message;I===$.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String($.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):I===$.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):I===$.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 $.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=mt(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:je.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(y.SetRangeValuesCommand.id,{value:{[(T=t==null?void 0:t.row)!=null?T:h]:{[(C=t==null?void 0:t.col)!=null?C: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 h,p;const{width:n,height:o,image:s}=await $.getImageSize(e||"");this._imageIoService.addImageSourceCache(e,l.ImageSourceType.URL,s);const a=this._workbookSelections.getCurrentLastSelection();if(!a)return!1;const d=l.createDocumentModelWithStyle("",{}),g=mt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:a.primary.actualRow,col:a.primary.actualColumn},n,o,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},c={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:e,transform:je.docDrawingPositionToTransform(u),docTransform:u,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},m=l.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[c],selection:{collapsed:!0,startOffset:0,endOffset:0}});return m?(d.apply(m),this._commandService.syncExecuteCommand(y.SetRangeValuesCommand.id,{value:{[(h=t==null?void 0:t.row)!=null?h:a.primary.actualRow]:{[(p=t==null?void 0:t.col)!=null?p:a.primary.actualColumn]:{p:d.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(gt.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=V({...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(be.id,{unitId:e[0].unitId,drawings:t}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{this._commandService.executeCommand(ut.id,e);const{unitId:t,subUnitId:n,drawingId:o}=e[0].parent;this._commandService.syncExecuteCommand($.SetDrawingSelectedOperation.id,[{unitId:t,subUnitId:n,drawingId:o}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{this._commandService.executeCommand(ht.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))}))}},R.SheetDrawingUpdateController=Qt([te(1,l.Inject(b.SheetSkeletonManagerService)),te(2,l.ICommandService),te(3,b.ISheetSelectionRenderService),te(4,$.IImageIoService),te(5,B.ILocalFileService),te(6,w.ISheetDrawingService),te(7,$.IDrawingManagerService),te(8,l.IContextService),te(9,B.IMessageService),te(10,l.Inject(l.LocaleService)),te(11,l.Inject(y.SheetsSelectionsService)),te(12,l.Inject(l.Injector))],R.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(R.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const d=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(d)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},pt={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(R.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}},we={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:V(m,n)}}).filter(u=>u!=null);return e.syncExecuteCommand(be.id,{unitId:a,drawings:d})?(e.syncExecuteCommand(X.id,[a]),!0):!1}};var tn=Object.getOwnPropertyDescriptor,nn=(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},ft=(i,r)=>(e,t)=>r(e,t,i),he=(i=>(i.CELL_ADDRESS="cellAddress",i.COLUMN_VALUE="columnValue",i))(he||{});const Le=l.createIdentifier("sheets-drawing-ui.batch-save-images.service");function St(i){let r="",e=i;for(;e>=0;)r=String.fromCharCode(e%26+65)+r,e=Math.floor(e/26)-1;return r}function Fe(i,r){return`${St(r)}${i+1}`}function rn(i){const r=Fe(i.startRow,i.startColumn),e=Fe(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")}R.BatchSaveImagesService=class extends l.Disposable{constructor(r,e,t){super(),this._univerInstanceService=r,this._selectionService=e,this._imageIoService=t}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:Fe(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:Fe(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:St(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 T=s.getValue(D,_);if(T&&(((p=T.v)==null?void 0:p.toString())||((v=(f=(S=T.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:St(_)});return m}getSelectionRangeNotation(){const r=this._selectionService.getCurrentSelections();return!r||r.length===0?"":r.map(e=>rn(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 Ut(r.source,r.imageSourceType)}},R.BatchSaveImagesService=nn([ft(0,l.IUniverInstanceService),ft(1,l.Inject(y.SheetsSelectionsService)),ft(2,l.IImageIoService)],R.BatchSaveImagesService);const ve="sheet.dialog.batch-save-images",_e={id:"sheet.command.save-cell-images",type:l.CommandType.COMMAND,handler:async i=>{const r=i.get(B.IDialogService),e=i.get(Le),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:ve,draggable:!0,width:360,title:{title:s},children:{label:ve},destroyOnClose:!0,preservePositionOnDestroy:!0,onClose:()=>r.close(ve)}),!0}},Pt="COMPONENT_SHEET_DRAWING_PANEL",vt={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{const e=i.get(B.ISidebarService),t=i.get(l.LocaleService),n=i.get(l.IUniverInstanceService),o=i.get(l.ICommandService);if(!y.getSheetCommandTarget(n))return!1;switch(r.value){case"open":e.open({header:{title:t.t("sheetImage.panel.title")},children:{label:Pt},onClose:()=>{o.syncExecuteCommand($.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:e.close();break}return!0}},_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($.SetDrawingSelectedOperation.id,[r]),e.executeCommand(vt.id,{value:"open"}),!0)}},on="sheets-drawing-ui.config",Nt={};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},se=(i,r)=>(e,t)=>r(e,t,i);let Ye=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).pipe(U.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(U.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._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)}_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($.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:Se.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}]}};Ye=an([se(0,l.Inject(l.Injector)),se(1,l.Inject(l.LocaleService)),se(2,$.IDrawingManagerService),se(3,l.Inject(b.SheetCanvasPopManagerService)),se(4,A.IRenderManagerService),se(5,l.IUniverInstanceService),se(6,B.IMessageService),se(7,l.IContextService),se(8,l.IImageIoService),se(9,l.ICommandService)],Ye);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},Ge=(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=dn([Ge(1,l.Inject(b.HoverManagerService)),Ge(2,l.Inject(y.SheetsSelectionsService)),Ge(3,l.Inject(ge.DrawingRenderService)),Ge(4,l.Inject(b.SheetSkeletonManagerService))],It);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},He=(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=un([He(1,w.ISheetDrawingService),He(2,$.IDrawingManagerService),He(3,l.Inject(b.ISheetSelectionRenderService)),He(4,l.Inject(b.SheetSkeletonManagerService))],Ct);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},Ie=(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=mt(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 Ve=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===je.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},kt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),e(i)}}))}};Ve=hn([Ie(0,l.ICommandService),Ie(1,l.Inject(y.SheetInterceptorService)),Ie(2,l.Inject(l.Injector)),Ie(3,$.IDrawingManagerService),Ie(4,l.Inject(bt.DocDrawingController)),Ie(5,l.Inject(b.IEditorBridgeService))],Ve);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},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=pn([Wt(0,l.Inject(b.IAutoFillService)),Wt(1,l.Inject(l.Injector))],Xe);var fn=Object.getOwnPropertyDescriptor,Sn=(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},Ae=(i,r)=>(e,t)=>r(e,t,i);const wn=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,l.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let xe=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===je.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(wn.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")}}}))}};xe=Sn([Ae(0,l.ICommandService),Ae(1,l.IUniverInstanceService),Ae(2,B.IDialogService),Ae(3,A.IRenderManagerService),Ae(4,l.Inject(l.LocaleService))],xe);var vn=Object.getOwnPropertyDescriptor,_n=(i,r,e,t)=>{for(var n=t>1?void 0:t?vn(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 $t="image/png";function In(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:$t})}function Cn(i){const r=new ClipboardItem({[$t]:In(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 Bt=[b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let Ke=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(Se.id,d)}setTimeout(()=>{const d=yn();s.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&s.imageSourceType===$.ImageSourceType.BASE64?Cn(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.DEFAULT_PASTE},b.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,e)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:b.PREDEFINED_HOOK_NAME.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:T,drawingEndX:C,drawingStartY:M,drawingEndY:I}={drawingStartX:f,drawingEndX:f+_,drawingStartY:v,drawingEndY:v+D};s<=T&&C<=a&&d<=M&&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(Bt.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:(_=V(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(Bt.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 T=D.startX-_.startX,C=D.startY-_.startY,M=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)+T,top:((P=O==null?void 0:O.top)!=null?P:0)+C},sheetTransform:{...k,to:{...k.to,row:k.to.row+M,column:k.to.column+I},from:{...k.from,row:k.from.row+M,column:k.from.column+I}}}},isCut:d===b.COPY_TYPE.CUT})}};Ke=_n([Ue(0,b.ISheetClipboardService),Ue(1,A.IRenderManagerService),Ue(2,$.IDrawingManagerService),Ue(3,B.IClipboardInterfaceService),Ue(4,l.ICommandService)],Ke);var Dn=Object.getOwnPropertyDescriptor,Mn=(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);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=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 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),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 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),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 y.WorkbookViewPermission(o).id,new y.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 y.WorkbookEditablePermission(o).id,new y.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)})}}))}};ze=Mn([Pe(0,$.IDrawingManagerService),Pe(1,A.IRenderManagerService),Pe(2,l.IPermissionService),Pe(3,l.IUniverInstanceService),Pe(4,l.Inject(l.UserManagerService))],ze);var Tn=Object.getOwnPropertyDescriptor,Rn=(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},pe=(i,r)=>(e,t)=>r(e,t,i);const jt="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:T,viewportScrollX:C,viewportScrollY:M}=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"&&(M=0),N==="VERTICAL"&&(C=0);let P=0,E=0;const j=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-C)*s,E=(f-C)*s;else{const q=S-(G-O),ee=f-(G-O);f<ne?(P=q*s,E=ee*s):S<=ne&&f>=ne?(P=q*s,E=Math.max(T,(f-C)*s)):S>ne&&(p.left=!1,P=Math.max((S-C)*s,T),E=Math.max((f-C)*s,T))}let z=0,Z=0;if(h===0)p.top=!1,z=(v-M)*a,Z=(_-M)*a;else{const q=v-(j-k),ee=_-(j-k);_<Q?(z=q*a,Z=ee*a):v<=Q&&_>=Q?(z=q*a,Z=Math.max(D,(_-M)*a)):v>Q&&(p.top=!1,z=Math.max((v-M)*a,D),Z=Math.max((_-M)*a,D))}return P=Math.max(P,W.left),z=Math.max(z,W.top),E=Math.max(E,W.left),Z=Math.max(Z,W.top),{left:P,right:E,top:z,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}};R.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=y.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:T,height:C,angle:M,flipX:I,flipY:N,skewX:O,skewY:k}=m,W=$.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),P=f.getObject(W);if(P!=null){P.transformByState({left:_,top:D,width:T,height:C,angle:M,flipX:I,flipY:N,skewX:O,skewY:k});return}const E={left:_,top:D,width:T,height:C,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},j=h===l.DrawingTypeEnum.DRAWING_CHART;if(E.rotateEnabled=!1,j){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);j&&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),z=new U.BehaviorSubject(ne),Z=`${jt}${l.generateRandomId(6)}`,oe={dispose:Q,rect:G,position$:z,unitId:n,subUnitId:o,id:s,domId:Z};this._canvasFloatDomService.addFloatDom({position$:z,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 q=G.onTransformChange$.subscribeEvent(()=>{const x=ae(G,S.renderUnit.scene,c.skeleton,a.worksheet);z.next(x)});Q.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),q&&Q.add(q),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=$.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=y.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===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:d}=a,g=$.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=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: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(Ee.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=y.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:T}=D.getAncestorScale(),C=qe(f,n,T),M={unitId:a,subUnitId:d,drawingId:S,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:C.startX,top:C.startY,width:C.width,height:C.height},data:h,allowTransform:p};{const{unitId:k,subUnitId:W,drawingId:P}=M,E=y.getSheetCommandTarget(this._univerInstanceService,{unitId:k,subUnitId:W}),j=M,G=this._univerInstanceService.getUnit(k,l.UniverInstanceType.UNIVER_SHEET);if(!G)return;const Q=G.getActiveSheet().getSheetId();if(!j||!E)return;const ne=(N=this._renderManagerService.getRenderById(k))==null?void 0:N.with(b.SheetSkeletonManagerService);if(!ne)return;const z=ne.getWorksheetSkeleton(W);if(!z)return;const{transform:Z,drawingType:oe,data:q}=j;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:ye}=ee;if(Z==null||Q!==W)return;const{left:et,top:tt,width:nt,height:rt,angle:Rt,flipX:Et,flipY:it,skewX:ot,skewY:De}=Z,st=$.getDrawingShapeKeyByDrawingSearch({unitId:k,subUnitId:W,drawingId:P}),ce=x.getObject(st);if(ce!=null){ce.transformByState({left:et,top:tt,width:nt,height:rt,angle:Rt,flipX:Et,flipY:it,skewX:ot,skewY:De});return}const re={left:et,top:tt,width:nt,height:rt,zIndex:this._drawingManagerService.getDrawingOrder(k,W).length-1},Me=oe===l.DrawingTypeEnum.DRAWING_CHART;if(Me){const F=q?q.backgroundColor:"white";re.fill=F,re.rotateEnabled=!1,q&&q.border&&(re.stroke=q.border),re.paintFirst="stroke",re.strokeWidth=1,re.borderEnabled=!1,re.radius=8}const de=new A.Rect(st,re);Me&&de.setObjectType(A.ObjectType.CHART),x.addObject(de,A.DRAWING_OBJECT_LAYER_INDEX),j.allowTransform!==!1&&x.attachTransformerTo(de);const le=new l.DisposableCollection,at=x.getMainViewport(),{rowHeaderWidth:Te,columnHeaderHeight:We}=z.skeleton,ct={top:We,left:Te,bottom:at.bottom,right:at.right},ue={dispose:le,rect:de,boundsOfViewArea:ct,domAnchor:n,unitId:k,subUnitId:W},K=ae(de,ee.renderUnit.scene,z.skeleton,E.worksheet,ue),Re=new U.BehaviorSubject(K);ue.position$=Re;let $e={position$:Re,id:P,componentKey:j.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:F=>{ye.dispatchEvent(new WheelEvent(F.type,F))},data:q,unitId:k};t.eventPassThrough&&($e={...$e,onPointerDown:F=>{ye.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{ye.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{ye.dispatchEvent(new PointerEvent(F.type,F))}}),this._canvasFloatDomService.addFloatDom($e),this.disposeWithMe(v.subscribe(F=>{var Xt,xt,Kt,zt;const Vt=qe({startX:F.startX,startY:F.startY,endX:F.endX,endY:F.endY,width:(Xt=n.width)!=null?Xt:F.width,height:(xt=n.height)!=null?xt:F.height,absolute:{left:f.absolute.left,top:f.absolute.top}},n),ar=$.getDrawingShapeKeyByDrawingSearch({unitId:k,subUnitId:W,drawingId:P}),cr=new A.Rect(ar,{left:Vt.startX,top:Vt.startY,width:(Kt=n.width)!=null?Kt:F.width,height:(zt=n.height)!=null?zt:F.height,zIndex:this._drawingManagerService.getDrawingOrder(k,W).length-1}),dr=ae(cr,ee.renderUnit.scene,z.skeleton,E.worksheet,ue);Re.next(dr)}));const Be=(O=this._renderManagerService.getRenderById(k))==null?void 0:O.with(b.SheetSkeletonManagerService);Be==null||Be.currentSkeleton$.subscribe(F=>{F&&z.sheetId!==F.sheetId&&this._removeDom(S,!0)});const dt=de.onTransformChange$.subscribeEvent(()=>{const F=ae(de,ee.renderUnit.scene,z.skeleton,E.worksheet,ue);Re.next(F)});le.add(()=>{this._canvasFloatDomService.removeFloatDom(P)}),dt&&le.add(dt),this._domLayerInfoMap.set(P,ue)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(e,t,n,o){var C,M,I;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:d}=s;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(C=this._renderManagerService.getRenderById(a))==null?void 0:C.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 T={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}=T,W=y.getSheetCommandTarget(this._univerInstanceService,{unitId:N,subUnitId:O}),P=T,E=this._univerInstanceService.getUnit(N,l.UniverInstanceType.UNIVER_SHEET);if(!E)return;const j=E.getActiveSheet().getSheetId();if(!P||!W)return;const G=(M=this._renderManagerService.getRenderById(N))==null?void 0:M.with(b.SheetSkeletonManagerService);if(!G)return;const Q=G.getWorksheetSkeleton(O);if(!Q)return;const{transform:ne,data:z}=P,Z=this._getSceneAndTransformerByDrawingSearch(N);if(Z==null)return;const{scene:oe,canvas:q}=Z;if(ne==null||j!==O)return;const{left:ee,top:x,width:ye,height:et,angle:tt,flipX:nt,flipY:rt,skewX:Rt,skewY:Et}=ne,it=$.getDrawingShapeKeyByDrawingSearch({unitId:N,subUnitId:O,drawingId:k}),ot=oe.getObject(it);if(ot!=null){ot.transformByState({left:ee,top:x,width:ye,height:et,angle:tt,flipX:nt,flipY:rt,skewX:Rt,skewY:Et});return}const De=qe({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),st={left:De.startX,top:De.startY,width:De.width,height:De.height,zIndex:this._drawingManagerService.getDrawingOrder(N,O).length-1},ce=new A.Rect(it,st);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"},at=ae(ce,Z.renderUnit.scene,Q.skeleton,W.worksheet,le),Te=new U.BehaviorSubject(at);le.position$=Te;let We={position$:Te,id:k,componentKey:P.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:K=>{q.dispatchEvent(new WheelEvent(K.type,K))},data:z,unitId:N};t.eventPassThrough&&(We={...We,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(We);const ct=ce.onTransformChange$.subscribeEvent(()=>{const K=ae(ce,Z.renderUnit.scene,Q.skeleton,W.worksheet,le);Te.next(K)});this.disposeWithMe(v.subscribe(K=>{const Re=qe({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),$e=$.getDrawingShapeKeyByDrawingSearch({unitId:N,subUnitId:O,drawingId:k}),Be=new A.Rect($e,{left:Re.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(N,O).length-1}),dt=ae(Be,Z.renderUnit.scene,Q.skeleton,W.worksheet,le);Te.next(dt)}));const ue=(I=this._renderManagerService.getRenderById(N))==null?void 0:I.with(b.SheetSkeletonManagerService);ue==null||ue.currentSkeleton$.subscribe(K=>{K&&c.sheetId!==K.sheetId&&this._removeDom(S,!0)}),re.add(()=>{this._canvasFloatDomService.removeFloatDom(k)}),ct&&re.add(ct),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===y.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(D=>D.row===o)>-1){c();return}(y.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}}},R.SheetCanvasFloatDomManagerService=Rn([pe(0,l.Inject(A.IRenderManagerService)),pe(1,l.IUniverInstanceService),pe(2,l.Inject(l.ICommandService)),pe(3,$.IDrawingManagerService),pe(4,l.Inject(B.CanvasFloatDomService)),pe(5,w.ISheetDrawingService),pe(6,l.Inject(l.LifecycleService))],R.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 qe(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=Ze(r.marginX,t*e);a=i.endX-c-o}else a=i.startX+Ze(r.marginX,t);if(r.verticalOffsetAlign==="bottom"){const c=Ze(r.marginY,n*e);d=i.endY-c-s}else d=i.startY+Ze(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 Ze(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const e=Number.parseFloat(i);return r*e/100}const En=i=>{const{floatDomInfos:r,scene:e,skeleton:t,worksheet:n}=i,o=H.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(B.PrintFloatDomSingle,{layer:a,id:s,position:a.position},s))})};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},fe=(i,r)=>(e,t)=>r(e,t,i);let Je=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=B.connectInjector(En,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)}}}))}};Je=On([fe(0,l.Inject(b.SheetPrintInterceptorService)),fe(1,l.Inject(ge.DrawingRenderService)),fe(2,$.IDrawingManagerService),fe(3,A.IRenderManagerService),fe(4,l.Inject(R.SheetCanvasFloatDomManagerService)),fe(5,l.Inject(B.ComponentManager)),fe(6,l.Inject(l.Injector))],Je);var An=Object.getOwnPropertyDescriptor,Un=(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},me=(i,r)=>(e,t)=>r(e,t,i);const Pn=[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],Nn=[y.SetRowVisibleMutation.id,y.SetRowHiddenMutation.id,y.SetColVisibleMutation.id,y.SetColHiddenMutation.id,y.SetWorksheetRowHeightMutation.id,y.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(!Pn.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),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:X.id,params:[t]}),s.push({id:X.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:T}=i;let C=null,M=null;if(r===0&&h>=v&&S<=_)if(p>=D&&f<=T)n.push({unitId:d,subUnitId:g,drawingId:u});else{const I=this._shrinkCol(o,a,D,T,s);C=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}else if(r===1&&p>=D&&f<=T)if(h>=v&&S<=_)n.push({unitId:d,subUnitId:g,drawingId:u});else{const I=this._shrinkRow(o,a,v,_,s);C=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}else if(r===2){const I=this._expandRow(o,a,v,_,s);C=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}else if(r===3){const I=this._expandCol(o,a,D,T,s);C=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}if(C!=null&&M!=null){const I=J(C,this._selectionRenderService,this._skeletonManagerService);t.push({...e,sheetTransform:C,transform:I})}return{updateDrawings:t,deleteDrawings:n}}_remainDrawingSize(i,r,e){const t=V({...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:T}=f;for(let C=0;C<e.length;C++){const M=e[C],{startRow:I,endRow:N,startColumn:O,endColumn:k}=M;if(T<O)continue;if(p===w.SheetDrawingAnchorType.Position){let E=null,j=null;if(_>=O&&_<=k){const G=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:k,startRow:S.row,endRow:f.row});if(G==null)return;j={...h,left:G.startX}}if(j!=null&&(E=V(j,this._selectionRenderService),E!=null&&j!=null)){n.push({...c,sheetTransform:E,transform:j});break}this._remainDrawingSize(h,n,c);continue}if(_>=O&&T<=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(T>=O&&T<=k){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:T,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=V(P,this._selectionRenderService),W!=null&&P!=null){o.push({...c,sheetTransform:W,transform:P});break}}if(P!=null&&(W=V(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:X.id,params:[i]}],d=[{id:w.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:s,type:w.DrawingApplyType.UPDATE}},{id:X.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:T}=f;for(let C=0;C<e.length;C++){const M=e[C],{startRow:I,endRow:N,startColumn:O,endColumn:k}=M;if(D<I)continue;if(p===w.SheetDrawingAnchorType.Position){let E=null,j=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;j={...h,top:G.startY}}if(j!=null&&(E=V(j,this._selectionRenderService),E!=null&&j!=null)){n.push({...c,sheetTransform:E,transform:j});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=V(P,this._selectionRenderService),W!=null&&P!=null){o.push({...c,sheetTransform:W,transform:P});break}}if(P!=null&&(W=V(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:T,startColumn:C,endColumn:M}=_;if(S<D||f<C)continue;if(u===w.SheetDrawingAnchorType.Position&&(h<=D&&S>=T||p<=C&&f>=M)){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=y.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;e=n.unitId,t=n.subUnitId}return{unitId:e,subUnitId:t}}_moveRangeInterceptor(i){var D,T;const{toRange:r,fromRange:e}=i,t=y.getSheetCommandTarget(this._univerInstanceService);if(!t)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=t,s=(T=(D=this._renderManagerService.getRenderById(n))==null?void 0:D.with(b.SheetSkeletonManagerService))==null?void 0:T.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(C=>{const M=m[C];if(M.anchorType!==w.SheetDrawingAnchorType.Both)return;const{transform:I}=M;if(!I)return;const{left:N=0,top:O=0,width:k=0,height:W=0}=I,{drawingStartX:P,drawingEndX:E,drawingStartY:j,drawingEndY:G}={drawingStartX:N,drawingEndX:N+k,drawingStartY:O,drawingEndY:O+W};d<=P&&E<=g&&u<=j&&G<=c&&h.push(M)});const p=[],S=[],f=r.startRow-e.startRow,v=r.startColumn-e.startColumn,_=h.map(C=>{const M=C.sheetTransform,I={to:{...M.to,row:M.to.row+f,column:M.to.column+v},from:{...M.from,row:M.from.row+f,column:M.from.column+v}},N=J(I,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:C.drawingId,transform:N,sheetTransform:I}});if(_.length){const C=this._sheetDrawingService.getBatchUpdateOp(_),{undo:M,redo:I,objects:N}=C;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:M,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 C=this._expandRow(S,f,s,a,v);_=C==null?void 0:C.newSheetTransform,D=C==null?void 0:C.newTransform}else{const{from:C,to:M}=S,{row:I}=C,{row:N}=M;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 T={unitId:t,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};c.push(T)}),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:X.id,params:[t]}),g.push({id:X.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 C=this._expandCol(S,f,s,a,v);_=C==null?void 0:C.newSheetTransform,D=C==null?void 0:C.newTransform}else{const{from:C,to:M}=S,{column:I}=C,{column:N}=M;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 T={unitId:t,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};c.push(T)}),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:X.id,params:[t]}),g.push({id:X.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:V({...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=V(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:V({...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:V({...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:V({...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=V(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:V({...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=V(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:V({...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:V({...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:V({...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=V(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===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._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._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(t)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Nn.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:e,subUnitId:t,ranges:n}=r;this._refreshDrawingTransform(e,t,n)})}))}_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:T,endColumn:C}=v;if(l.Rectangle.intersects({startRow:_,endRow:D,startColumn:T,endColumn:C},{startRow:m,endRow:p,startColumn:h,endColumn:S})||m>D||h>C){const M=g===w.SheetDrawingAnchorType.Position,I=J(a,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...I,width:M?d==null?void 0:d.width:I==null?void 0:I.width,height:M?d==null?void 0:d.height:I==null?void 0:I.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(X.id,[i]))}};yt=Un([me(1,A.IRenderManagerService),me(2,l.ICommandService),me(3,b.ISheetSelectionRenderService),me(4,l.Inject(b.SheetSkeletonManagerService)),me(5,l.Inject(y.SheetInterceptorService)),me(6,w.ISheetDrawingService),me(7,$.IDrawingManagerService),me(8,l.IUniverInstanceService)],yt);function Ft({ref:i,...r}){const{icon:e,id:t,className:n,extend:o,...s}=r,a=`univerjs-icon univerjs-icon-${t} ${n||""}`.trim(),d=H.useRef(`_${$n()}`);return Yt(e,`${t}`,{defIds:e.defIds,idSuffix:d.current},{ref:i,className:a,...s},o)}function Yt(i,r,e,t,n){return H.createElement(i.tag,{key:r,...kn(i,e,n),...t},(Wn(i,e).children||[]).map((o,s)=>Yt(o,`${r}-${i.tag}-${s}`,e,void 0,n)))}function kn(i,r,e){const t={...i.attrs};e!=null&&e.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=e.colorChannel1),i.tag==="mask"&&t.id&&(t.id=t.id+r.idSuffix),Object.entries(t).forEach(([o,s])=>{o==="mask"&&typeof s=="string"&&(t[o]=s.replace(/url\(#(.*)\)/,`url(#$1${r.idSuffix})`))});const{defIds:n}=r;return!n||n.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+r.idSuffix),Object.entries(t).forEach(([o,s])=>{typeof s=="string"&&(t[o]=s.replace(/url\(#(.*)\)/,`url(#$1${r.idSuffix})`))})),t}function Wn(i,r){var t;const{defIds:e}=r;return!e||e.length===0?i:i.tag==="defs"&&((t=i.children)!=null&&t.length)?{...i,children:i.children.map(n=>typeof n.attrs.id=="string"&&e&&e.includes(n.attrs.id)?{...n,attrs:{...n.attrs,id:n.attrs.id+r.idSuffix}}:n)}:i}function $n(){return Math.random().toString(36).substring(2,8)}Ft.displayName="UniverIcon";const Bn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.35381 3.65517C2.35381 2.88198 2.98061 2.25518 3.75381 2.25518H8.10381C8.43518 2.25518 8.70381 1.98655 8.70381 1.65518C8.70381 1.3238 8.43518 1.05518 8.10381 1.05518H3.75381C2.31787 1.05518 1.15381 2.21923 1.15381 3.65517V12.3552C1.15381 13.7911 2.31787 14.9552 3.75381 14.9552H12.4538C13.8897 14.9552 15.0538 13.7911 15.0538 12.3552V8.00518C15.0538 7.6738 14.7852 7.40518 14.4538 7.40518C14.1224 7.40518 13.8538 7.6738 13.8538 8.00518V9.24469L12.3428 8.11143C11.8294 7.72642 11.1111 7.77744 10.6573 8.23119L9.11281 9.77567L6.84342 7.83047C6.34812 7.40592 5.61375 7.41815 5.13289 7.85896L2.35381 10.4064V3.65517ZM2.35381 12.0343V12.3552C2.35381 13.1284 2.98061 13.7552 3.75381 13.7552H12.4538C13.227 13.7552 13.8538 13.1284 13.8538 12.3552V10.7447L11.6228 9.07144C11.5871 9.04469 11.5373 9.04827 11.5058 9.07971L10.0266 10.5589L11.2057 11.5696C11.4573 11.7853 11.4865 12.164 11.2708 12.4156C11.0552 12.6672 10.6764 12.6964 10.4248 12.4807L6.06245 8.74157C6.02809 8.71212 5.97713 8.71296 5.94377 8.74353L2.35381 12.0343Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M10.3911 3.84419C10.6254 3.60988 11.0053 3.60988 11.2396 3.84419L11.8818 4.48643V1.93496C11.8818 1.60359 12.1505 1.33496 12.4818 1.33496C12.8132 1.33496 13.0818 1.60359 13.0818 1.93496V4.48676L13.7244 3.84419C13.9587 3.60988 14.3386 3.60988 14.5729 3.84419C14.8072 4.07851 14.8072 4.45841 14.5729 4.69272L12.9063 6.35939C12.6719 6.5937 12.292 6.5937 12.0577 6.35939L10.3911 4.69272C10.1568 4.45841 10.1568 4.07851 10.3911 3.84419Z"}}]},Gt=H.forwardRef(function(r,e){return H.createElement(Ft,Object.assign({},r,{id:"download-image-icon",ref:e,icon:Bn}))});Gt.displayName="DownloadImageIcon";function jn(){const i=B.useDependency(l.LocaleService),r=B.useDependency(B.IDialogService),e=B.useDependency(Le),[t,n]=H.useState([he.CELL_ADDRESS]),[o,s]=H.useState(!1),[a,d]=H.useState(null),g=H.useMemo(()=>e.getCellImagesInSelection(),[e]),u=H.useMemo(()=>e.getDataColumns(),[e]),c=H.useMemo(()=>e.getSelectionRowRange(),[e]),m=u.length>0,h=H.useMemo(()=>u.map(M=>({label:M.label,value:String(M.index)})),[u]),[p,S]=H.useState(()=>h.length>0?h[0].value:"0"),f=H.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=H.useCallback(M=>{M.length!==0&&n(M)},[]),_=H.useCallback(M=>{S(String(M))},[]),D=H.useCallback(()=>{r.close(ve)},[r]),T=H.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(ve)}catch(M){console.error("Failed to save images:",M),d(i.t("sheetImage.save.error"))}finally{s(!1)}}},[e,g,t,p,r,i]),C=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")})]})}),C&&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:T,disabled:o||g.length===0,children:o?i.t("sheetImage.save.saving"):i.t("sheetImage.save.confirm")})]})]})}const Ln=i=>{var _;const r=B.useDependency(l.ICommandService),e=B.useDependency(l.LocaleService),t=B.useDependency($.IDrawingManagerService),n=B.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]=H.useState(!0),h=(_=s.anchorType)!=null?_:w.SheetDrawingAnchorType.Position,[p,S]=H.useState(h);function f(D,T){const C=[];return D.forEach(M=>{const{oKey:I}=M,N=T.getDrawingOKey(I);if(N==null)return C.push(null),!0;const{unitId:O,subUnitId:k,drawingId:W,drawingType:P,anchorType:E,sheetTransform:j}=N;C.push({unitId:O,subUnitId:k,drawingId:W,anchorType:E,sheetTransform:j,drawingType:P})}),C}H.useEffect(()=>{const D=u.clearControl$.subscribe(C=>{C===!0&&m(!1)}),T=u.changeStart$.subscribe(C=>{var N;const{objects:M}=C,I=f(M,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()=>{T.unsubscribe(),D.unsubscribe()}},[]);function v(D){S(D);const T=t.getFocusDrawings();if(T.length===0)return;const C=T.map(M=>({unitId:M.unitId,subUnitId:M.subUnitId,drawingId:M.drawingId,anchorType:D}));r.executeCommand(be.id,{unitId:T[0].unitId,drawings:C})}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")})]})})]})},Fn=()=>{const i=B.useDependency($.IDrawingManagerService),r=i.getFocusDrawings(),[e,t]=H.useState(r);return H.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(Ln,{drawings:e})]})},Dt="sheet.menu.image";function Yn(i){return{id:Dt,type:B.MenuItemType.SUBITEMS,icon:"AddImageIcon",tooltip:"sheetImage.title",hidden$:B.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),disabled$:b.getCurrentRangeDisable$(i,{workbookTypes:[y.WorkbookEditablePermission],worksheetTypes:[y.WorksheetEditPermission],rangeTypes:[y.RangeProtectionPermissionEditPoint]})}}function Gn(i){return{id:Oe.id,title:"sheetImage.upload.float",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function Hn(i){return{id:pt.id,title:"sheetImage.upload.cell",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function Vn(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 Xn(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(Vn(u))return!0}return!1}function xn(){return"showDirectoryPicker"in window}function Mt(i){const r=i.get(l.IUniverInstanceService),e=i.get(y.SheetsSelectionsService),t=U.combineLatest([B.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),r.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(U.switchMap(n=>n?e.selectionMoveEnd$.pipe(U.map(()=>{if(!xn())return!0;const o=e.getCurrentSelections();if(!o||o.length===0)return!0;for(const s of o)if(Xn(n,s.range))return!1;return!0})):U.of(!0)))]).pipe(U.map(([n,o])=>n||o));return{id:_e.id,type:B.MenuItemType.BUTTON,icon:"DownloadImageIcon",title:"sheetImage.save.menuLabel",hidden$:t}}const Kn={[B.RibbonInsertGroup.MEDIA]:{[Dt]:{order:0,menuItemFactory:Yn,[Oe.id]:{order:0,menuItemFactory:Gn},[pt.id]:{order:1,menuItemFactory:Hn}}},[B.ContextMenuPosition.MAIN_AREA]:{[B.ContextMenuGroup.OTHERS]:{[_e.id]:{order:10,menuItemFactory:Mt}}},[B.ContextMenuPosition.COL_HEADER]:{[B.ContextMenuGroup.OTHERS]:{[_e.id]:{order:10,menuItemFactory:Mt}}},[B.ContextMenuPosition.ROW_HEADER]:{[B.ContextMenuGroup.OTHERS]:{[_e.id]:{order:10,menuItemFactory:Mt}}}};function ke(i){return!i.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(l.EDITOR_ACTIVATED)&&!i.getContextValue(l.FOCUSING_PANEL_EDITOR)&&i.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const zn={id:we.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:B.KeyCode.ARROW_DOWN,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.DOWN}},qn={id:we.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:B.KeyCode.ARROW_UP,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.UP}},Zn={id:we.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:B.KeyCode.ARROW_LEFT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.LEFT}},Jn={id:we.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:B.KeyCode.ARROW_RIGHT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.RIGHT}},Qn={id:lt.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:ke,binding:B.KeyCode.DELETE,mac:B.KeyCode.BACKSPACE};var er=Object.getOwnPropertyDescriptor,tr=(i,r,e,t)=>{for(var n=t>1?void 0:t?er(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);let Qe=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,Fn)),this.disposeWithMe(i.register(ve,jn)),this.disposeWithMe(i.register("DownloadImageIcon",Gt))}_initMenus(){this._menuManagerService.mergeMenu(Kn)}_initCommands(){[Oe,pt,Ee,Se,be,vt,X,_t,ut,ht,we,lt,gt,_e].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[zn,qn,Zn,Jn,Qn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Qe=tr([Ce(0,l.Inject(B.ComponentManager)),Ce(1,B.IMenuManagerService),Ce(2,l.ICommandService),Ce(3,B.IShortcutService),Ce(4,$.IDrawingManagerService),Ce(5,l.Inject(y.SheetsSelectionsService))],Qe);var nr=Object.defineProperty,rr=Object.getOwnPropertyDescriptor,ir=(i,r,e)=>r in i?nr(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e,or=(i,r,e,t)=>{for(var n=t>1?void 0:t?rr(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Tt=(i,r)=>(e,t)=>r(e,t,i),Ht=(i,r,e)=>ir(i,typeof r!="symbol"?r+"":r,e);const sr="SHEET_IMAGE_UI_PLUGIN";R.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(on,s)}onStarting(){l.registerDependencies(this._injector,[[R.SheetCanvasFloatDomManagerService],[Qe],[Ye],[Je],[ze],[Ke],[Ve],[Xe],[xe],[Le,{useClass:R.BatchSaveImagesService}]]),l.touchDependencies(this._injector,[[R.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[Ke],[xe]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[ze],[Je],[Qe],[Ve],[Xe]])}onSteady(){this._injector.get(Ye)}_registerRenderModules(){[[R.SheetDrawingUpdateController],[yt],[Ct],[It]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}},Ht(R.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),Ht(R.UniverSheetsDrawingUIPlugin,"pluginName",sr),R.UniverSheetsDrawingUIPlugin=or([l.DependentOn($.UniverDrawingPlugin,bt.UniverDocsDrawingPlugin,ge.UniverDrawingUIPlugin,w.UniverSheetsDrawingPlugin),Tt(1,l.Inject(l.Injector)),Tt(2,A.IRenderManagerService),Tt(3,l.IConfigService)],R.UniverSheetsDrawingUIPlugin),R.ClearSheetDrawingTransformerOperation=X,R.DeleteDrawingsCommand=lt,R.EditSheetDrawingOperation=_t,R.FileNamePart=he,R.GroupSheetDrawingCommand=ut,R.IBatchSaveImagesService=Le,R.InsertFloatImageCommand=Oe,R.InsertSheetDrawingCommand=Ee,R.MoveDrawingsCommand=we,R.RemoveSheetDrawingCommand=Se,R.SHEETS_IMAGE_MENU_ID=Dt,R.SHEET_FLOAT_DOM_PREFIX=jt,R.SaveCellImagesCommand=_e,R.SetDrawingArrangeCommand=gt,R.SetSheetDrawingCommand=be,R.SidebarSheetDrawingOperation=vt,R.UngroupSheetDrawingCommand=ht,R.calcSheetFloatDomPosition=ae,R.drawingPositionToTransform=J,R.transformToDrawingPosition=V,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})}));
14
+ (function(R,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):(R=typeof globalThis<"u"?globalThis:R||self,A(R.UniverSheetsDrawingUi={},R.UniverEngineRender,R.UniverSheetsUi,R.UniverCore,R.UniverSheetsDrawing,R.UniverSheets,R.UniverDesign,R.UniverDocsUi,R.UniverDrawing,R.UniverUi,R.UniverDocsDrawing,R.UniverDrawingUi,R.rxjs,R.React,R.React))})(this,(function(R,A,b,l,w,C,Y,$e,B,j,bt,ge,U,F,q){"use strict";var rr=Object.defineProperty;var ir=(R,A,b)=>A in R?rr(R,A,{enumerable:!0,configurable:!0,writable:!0,value:b}):R[A]=b;var ie=(R,A,b)=>ir(R,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}},Se={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var _,D,M;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:Se.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:[...(M=p.preRedos)!=null?M:[],S,...p.redos,{id:V.id,params:a}]}),!0):!1}},lt={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(Se.id,{unitId:n,drawings:o})}};function xt(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 Kt(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 ut={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:Kt(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}},Ee={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var _,D,M;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:Ee.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:[...(M=p.preRedos)!=null?M:[],S,...p.redos,{id:V.id,params:a}]}),!0):!1}},gt={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}},be={id:"sheet.command.set-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{drawings:o}=r,s=n.getBatchUpdateOp(o),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=s;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:a,subUnitId:d,op:u,objects:c,type:w.DrawingApplyType.UPDATE})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:g,objects:c,type:w.DrawingApplyType.UPDATE}},{id:V.id,params:[a]}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:u,objects:c,type:w.DrawingApplyType.UPDATE}},{id:V.id,params:[a]}]}),!0):!1}},ht={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:xt(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 zt=Object.getOwnPropertyDescriptor,qt=(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},te=(i,r)=>(e,t)=>r(e,t,i);function Zt(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 mt(i,r,e,t,n){var _;const{rotatedHeight:o,rotatedWidth:s}=Zt(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}}R.SheetDrawingUpdateController=class extends l.Disposable{constructor(e,t,n,o,s,a,d,g,u,c,m,h,p){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._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 M=D.message;M===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)))}):M===B.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):M===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,M=B.DRAWING_IMAGE_HEIGHT_LIMIT/m;f=Math.max(D,M)}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(Ee.id,{unitId:o,drawings:[_]})}async _insertCellImage(e,t){var M,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=mt(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:$e.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:{[(M=t==null?void 0:t.row)!=null?M: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 h,p;const{width:n,height:o,image:s}=await B.getImageSize(e||"");this._imageIoService.addImageSourceCache(e,l.ImageSourceType.URL,s);const a=this._workbookSelections.getCurrentLastSelection();if(!a)return!1;const d=l.createDocumentModelWithStyle("",{}),g=mt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:a.primary.actualRow,col:a.primary.actualColumn},n,o,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},c={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:e,transform:$e.docDrawingPositionToTransform(u),docTransform:u,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},m=l.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[c],selection:{collapsed:!0,startOffset:0,endOffset:0}});return m?(d.apply(m),this._commandService.syncExecuteCommand(C.SetRangeValuesCommand.id,{value:{[(h=t==null?void 0:t.row)!=null?h:a.primary.actualRow]:{[(p=t==null?void 0:t.col)!=null?p:a.primary.actualColumn]:{p:d.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(gt.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(be.id,{unitId:e[0].unitId,drawings:t}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{this._commandService.executeCommand(ut.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(ht.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))}))}},R.SheetDrawingUpdateController=qt([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))],R.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(R.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const d=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(d)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},pt={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(R.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}},we={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(be.id,{unitId:a,drawings:d})?(e.syncExecuteCommand(V.id,[a]),!0):!1}};var Jt=Object.getOwnPropertyDescriptor,Qt=(i,r,e,t)=>{for(var n=t>1?void 0:t?Jt(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},ft=(i,r)=>(e,t)=>r(e,t,i),he=(i=>(i.CELL_ADDRESS="cellAddress",i.COLUMN_VALUE="columnValue",i))(he||{});const Fe=l.createIdentifier("sheets-drawing-ui.batch-save-images.service");function St(i){let r="",e=i;for(;e>=0;)r=String.fromCharCode(e%26+65)+r,e=Math.floor(e/26)-1;return r}function Le(i,r){return`${St(r)}${i+1}`}function en(i){const r=Le(i.startRow,i.startColumn),e=Le(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")}R.BatchSaveImagesService=class extends l.Disposable{constructor(r,e,t){super(),this._univerInstanceService=r,this._selectionService=e,this._imageIoService=t}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:Le(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:Le(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:St(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 M=s.getValue(D,_);if(M&&(((p=M.v)==null?void 0:p.toString())||((v=(f=(S=M.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:St(_)});return m}getSelectionRangeNotation(){const r=this._selectionService.getCurrentSelections();return!r||r.length===0?"":r.map(e=>en(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 Ut(r.source,r.imageSourceType)}},R.BatchSaveImagesService=Qt([ft(0,l.IUniverInstanceService),ft(1,l.Inject(C.SheetsSelectionsService)),ft(2,l.IImageIoService)],R.BatchSaveImagesService);const ve="sheet.dialog.batch-save-images",_e={id:"sheet.command.save-cell-images",type:l.CommandType.COMMAND,handler:async i=>{const r=i.get(j.IDialogService),e=i.get(Fe),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:ve,draggable:!0,width:360,title:{title:s},children:{label:ve},destroyOnClose:!0,preservePositionOnDestroy:!0,onClose:()=>r.close(ve)}),!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);if(!C.getSheetCommandTarget(n))return!1;switch(r.value){case"open":e.open({header:{title:t.t("sheetImage.panel.title")},children:{label:Pt},onClose:()=>{o.syncExecuteCommand(B.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:e.close();break}return!0}},_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)}},tn="sheets-drawing-ui.config",Nt={};var nn=Object.getOwnPropertyDescriptor,rn=(i,r,e,t)=>{for(var n=t>1?void 0:t?nn(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 Ye=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).pipe(U.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(U.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._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)}_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:Se.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}]}};Ye=rn([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)],Ye);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},Ge=(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=sn([Ge(1,l.Inject(b.HoverManagerService)),Ge(2,l.Inject(C.SheetsSelectionsService)),Ge(3,l.Inject(ge.DrawingRenderService)),Ge(4,l.Inject(b.SheetSkeletonManagerService))],It);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(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)}};yt=cn([He(1,w.ISheetDrawingService),He(2,B.IDrawingManagerService),He(3,l.Inject(b.ISheetSelectionRenderService)),He(4,l.Inject(b.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},Ie=(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=mt(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 Ve=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===$e.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)}}))}};Ve=ln([Ie(0,l.ICommandService),Ie(1,l.Inject(C.SheetInterceptorService)),Ie(2,l.Inject(l.Injector)),Ie(3,B.IDrawingManagerService),Ie(4,l.Inject(bt.DocDrawingController)),Ie(5,l.Inject(b.IEditorBridgeService))],Ve);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},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=gn([Wt(0,l.Inject(b.IAutoFillService)),Wt(1,l.Inject(l.Injector))],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},Ae=(i,r)=>(e,t)=>r(e,t,i);const pn=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,l.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let xe=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===$e.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(pn.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")}}}))}};xe=mn([Ae(0,l.ICommandService),Ae(1,l.IUniverInstanceService),Ae(2,j.IDialogService),Ae(3,A.IRenderManagerService),Ae(4,l.Inject(l.LocaleService))],xe);var fn=Object.getOwnPropertyDescriptor,Sn=(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 wn(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 vn(i){const r=new ClipboardItem({[Bt]:wn(i)});navigator.clipboard.write([r]).catch(e=>{console.error("Could not copy image using clipboard API: ",e)})}function _n(){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 Ke=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(Se.id,d)}setTimeout(()=>{const d=_n();s.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&s.imageSourceType===B.ImageSourceType.BASE64?vn(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:M,drawingEndX:y,drawingStartY:T,drawingEndY:I}={drawingStartX:f,drawingEndX:f+_,drawingStartY:v,drawingEndY:v+D};s<=M&&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 M=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)+M,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})}};Ke=Sn([Ue(0,b.ISheetClipboardService),Ue(1,A.IRenderManagerService),Ue(2,B.IDrawingManagerService),Ue(3,j.IClipboardInterfaceService),Ue(4,l.ICommandService)],Ke);var In=Object.getOwnPropertyDescriptor,yn=(i,r,e,t)=>{for(var n=t>1?void 0:t?In(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 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=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)})}}))}};ze=yn([Pe(0,B.IDrawingManagerService),Pe(1,A.IRenderManagerService),Pe(2,l.IPermissionService),Pe(3,l.IUniverInstanceService),Pe(4,l.Inject(l.UserManagerService))],ze);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},pe=(i,r)=>(e,t)=>r(e,t,i);const $t="univer-sheet-float-dom-";function Ft(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:M,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 $=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(M,(f-y)*s)):S>ne&&(p.left=!1,P=Math.max((S-y)*s,M),E=Math.max((f-y)*s,M))}let K=0,Z=0;if(h===0)p.top=!1,K=(v-T)*a,Z=(_-T)*a;else{const z=v-($-k),ee=_-($-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=Ft(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}};R.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:M,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:M,height:y,angle:T,flipX:I,flipY:N,skewX:O,skewY:k});return}const E={left:_,top:D,width:M,height:y,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},$=h===l.DrawingTypeEnum.DRAWING_CHART;if(E.rotateEnabled=!1,$){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);$&&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=`${$t}${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(Ee.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:M}=D.getAncestorScale(),y=qe(f,n,M),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}),$=T,G=this._univerInstanceService.getUnit(k,l.UniverInstanceType.UNIVER_SHEET);if(!G)return;const Q=G.getActiveSheet().getSheetId();if(!$||!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}=$;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:Ce}=ee;if(Z==null||Q!==W)return;const{left:et,top:tt,width:nt,height:rt,angle:Rt,flipX:Et,flipY:it,skewX:ot,skewY:De}=Z,st=B.getDrawingShapeKeyByDrawingSearch({unitId:k,subUnitId:W,drawingId:P}),ce=X.getObject(st);if(ce!=null){ce.transformByState({left:et,top:tt,width:nt,height:rt,angle:Rt,flipX:Et,flipY:it,skewX:ot,skewY:De});return}const re={left:et,top:tt,width:nt,height:rt,zIndex:this._drawingManagerService.getDrawingOrder(k,W).length-1},Te=oe===l.DrawingTypeEnum.DRAWING_CHART;if(Te){const L=z?z.backgroundColor:"white";re.fill=L,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(st,re);Te&&de.setObjectType(A.ObjectType.CHART),X.addObject(de,A.DRAWING_OBJECT_LAYER_INDEX),$.allowTransform!==!1&&X.attachTransformerTo(de);const le=new l.DisposableCollection,at=X.getMainViewport(),{rowHeaderWidth:Me,columnHeaderHeight:We}=K.skeleton,ct={top:We,left:Me,bottom:at.bottom,right:at.right},ue={dispose:le,rect:de,boundsOfViewArea:ct,domAnchor:n,unitId:k,subUnitId:W},x=ae(de,ee.renderUnit.scene,K.skeleton,E.worksheet,ue),Re=new U.BehaviorSubject(x);ue.position$=Re;let Be={position$:Re,id:P,componentKey:$.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:L=>{Ce.dispatchEvent(new WheelEvent(L.type,L))},data:z,unitId:k};t.eventPassThrough&&(Be={...Be,onPointerDown:L=>{Ce.dispatchEvent(new PointerEvent(L.type,L))},onPointerMove:L=>{Ce.dispatchEvent(new PointerEvent(L.type,L))},onPointerUp:L=>{Ce.dispatchEvent(new PointerEvent(L.type,L))}}),this._canvasFloatDomService.addFloatDom(Be),this.disposeWithMe(v.subscribe(L=>{var Gt,Ht,Vt,Xt;const Yt=qe({startX:L.startX,startY:L.startY,endX:L.endX,endY:L.endY,width:(Gt=n.width)!=null?Gt:L.width,height:(Ht=n.height)!=null?Ht:L.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:Yt.startX,top:Yt.startY,width:(Vt=n.width)!=null?Vt:L.width,height:(Xt=n.height)!=null?Xt:L.height,zIndex:this._drawingManagerService.getDrawingOrder(k,W).length-1}),nr=ae(tr,ee.renderUnit.scene,K.skeleton,E.worksheet,ue);Re.next(nr)}));const je=(O=this._renderManagerService.getRenderById(k))==null?void 0:O.with(b.SheetSkeletonManagerService);je==null||je.currentSkeleton$.subscribe(L=>{L&&K.sheetId!==L.sheetId&&this._removeDom(S,!0)});const dt=de.onTransformChange$.subscribeEvent(()=>{const L=ae(de,ee.renderUnit.scene,K.skeleton,E.worksheet,ue);Re.next(L)});le.add(()=>{this._canvasFloatDomService.removeFloatDom(P)}),dt&&le.add(dt),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 M={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}=M,W=C.getSheetCommandTarget(this._univerInstanceService,{unitId:N,subUnitId:O}),P=M,E=this._univerInstanceService.getUnit(N,l.UniverInstanceType.UNIVER_SHEET);if(!E)return;const $=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||$!==O)return;const{left:ee,top:X,width:Ce,height:et,angle:tt,flipX:nt,flipY:rt,skewX:Rt,skewY:Et}=ne,it=B.getDrawingShapeKeyByDrawingSearch({unitId:N,subUnitId:O,drawingId:k}),ot=oe.getObject(it);if(ot!=null){ot.transformByState({left:ee,top:X,width:Ce,height:et,angle:tt,flipX:nt,flipY:rt,skewX:Rt,skewY:Et});return}const De=qe({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),st={left:De.startX,top:De.startY,width:De.width,height:De.height,zIndex:this._drawingManagerService.getDrawingOrder(N,O).length-1},ce=new A.Rect(it,st);oe.addObject(ce,A.DRAWING_OBJECT_LAYER_INDEX),P.allowTransform!==!1&&oe.attachTransformerTo(ce);const re=new l.DisposableCollection,Te=oe.getMainViewport(),de={top:0,left:Te.left,bottom:Te.bottom,right:Te.right},le={dispose:re,rect:ce,unitId:N,subUnitId:O,boundsOfViewArea:de,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},at=ae(ce,Z.renderUnit.scene,Q.skeleton,W.worksheet,le),Me=new U.BehaviorSubject(at);le.position$=Me;let We={position$:Me,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 ct=ce.onTransformChange$.subscribeEvent(()=>{const x=ae(ce,Z.renderUnit.scene,Q.skeleton,W.worksheet,le);Me.next(x)});this.disposeWithMe(v.subscribe(x=>{const Re=qe({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:Re.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(N,O).length-1}),dt=ae(je,Z.renderUnit.scene,Q.skeleton,W.worksheet,le);Me.next(dt)}));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)}),ct&&re.add(ct),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}}},R.SheetCanvasFloatDomManagerService=Dn([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))],R.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 qe(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=Ze(r.marginX,t*e);a=i.endX-c-o}else a=i.startX+Ze(r.marginX,t);if(r.verticalOffsetAlign==="bottom"){const c=Ze(r.marginY,n*e);d=i.endY-c-s}else d=i.startY+Ze(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 Ze(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const e=Number.parseFloat(i);return r*e/100}const Tn=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=Ft({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 F.jsx("div",{style:{position:"absolute",top:0,left:0},children:o.map(([s,a])=>F.jsx(j.PrintFloatDomSingle,{layer:a,id:s,position:a.position},s))})};var Mn=Object.getOwnPropertyDescriptor,Rn=(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},fe=(i,r)=>(e,t)=>r(e,t,i);let Je=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(Tn,this._injector);return Y.render(F.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)}}}))}};Je=Rn([fe(0,l.Inject(b.SheetPrintInterceptorService)),fe(1,l.Inject(ge.DrawingRenderService)),fe(2,B.IDrawingManagerService),fe(3,A.IRenderManagerService),fe(4,l.Inject(R.SheetCanvasFloatDomManagerService)),fe(5,l.Inject(j.ComponentManager)),fe(6,l.Inject(l.Injector))],Je);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},me=(i,r)=>(e,t)=>r(e,t,i);const On=[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],An=[C.SetRowVisibleMutation.id,C.SetRowHiddenMutation.id,C.SetColVisibleMutation.id,C.SetColHiddenMutation.id,C.SetWorksheetRowHeightMutation.id,C.SetWorksheetColWidthMutation.id];let Ct=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(!On.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:M}=i;let y=null,T=null;if(r===0&&h>=v&&S<=_)if(p>=D&&f<=M)n.push({unitId:d,subUnitId:g,drawingId:u});else{const I=this._shrinkCol(o,a,D,M,s);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===1&&p>=D&&f<=M)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,M,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:M}=f;for(let y=0;y<e.length;y++){const T=e[y],{startRow:I,endRow:N,startColumn:O,endColumn:k}=T;if(M<O)continue;if(p===w.SheetDrawingAnchorType.Position){let E=null,$=null;if(_>=O&&_<=k){const G=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:k,startRow:S.row,endRow:f.row});if(G==null)return;$={...h,left:G.startX}}if($!=null&&(E=H($,this._selectionRenderService),E!=null&&$!=null)){n.push({...c,sheetTransform:E,transform:$});break}this._remainDrawingSize(h,n,c);continue}if(_>=O&&M<=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(M>=O&&M<=k){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:M,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:M}=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,$=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;$={...h,top:G.startY}}if($!=null&&(E=H($,this._selectionRenderService),E!=null&&$!=null)){n.push({...c,sheetTransform:E,transform:$});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:M,startColumn:y,endColumn:T}=_;if(S<D||f<y)continue;if(u===w.SheetDrawingAnchorType.Position&&(h<=D&&S>=M||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,M;const{toRange:r,fromRange:e}=i,t=C.getSheetCommandTarget(this._univerInstanceService);if(!t)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=t,s=(M=(D=this._renderManagerService.getRenderById(n))==null?void 0:D.with(b.SheetSkeletonManagerService))==null?void 0:M.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:$,drawingEndY:G}={drawingStartX:N,drawingEndX:N+k,drawingStartY:O,drawingEndY:O+W};d<=P&&E<=g&&u<=$&&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 M={unitId:t,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};c.push(M)}),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 M={unitId:t,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};c.push(M)}),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._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._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(t)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{An.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:e,subUnitId:t,ranges:n}=r;this._refreshDrawingTransform(e,t,n)})}))}_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:M,endColumn:y}=v;if(l.Rectangle.intersects({startRow:_,endRow:D,startColumn:M,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._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(V.id,[i]))}};Ct=bn([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)],Ct);function Un(){const i=j.useDependency(l.LocaleService),r=j.useDependency(j.IDialogService),e=j.useDependency(Fe),[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(ve)},[r]),M=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(ve)}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 F.jsxs("div",{className:"univer-flex univer-flex-col",children:[F.jsx(Y.FormLayout,{label:i.t("sheetImage.save.imageCount"),children:F.jsx("div",{className:"univer-text-sm univer-text-gray-600",children:g.length})}),F.jsx(Y.FormLayout,{label:i.t("sheetImage.save.fileNameConfig"),children:F.jsxs(Y.CheckboxGroup,{value:t,onChange:v,direction:"vertical",children:[F.jsx(Y.Checkbox,{value:he.CELL_ADDRESS,disabled:!m,children:i.t("sheetImage.save.useRowCol")}),m&&F.jsx(Y.Checkbox,{value:he.COLUMN_VALUE,children:i.t("sheetImage.save.useColumnValue")})]})}),y&&F.jsx(Y.FormLayout,{label:i.t("sheetImage.save.selectColumn"),children:F.jsx(Y.Select,{value:p,options:h,onChange:_})}),a&&F.jsx("div",{className:"univer-text-xs univer-text-red-500",children:a}),F.jsxs("div",{className:"univer-flex univer-justify-end univer-gap-2 univer-border-t univer-border-gray-200 univer-pt-3",children:[F.jsx(Y.Button,{onClick:D,disabled:o,children:i.t("sheetImage.save.cancel")}),F.jsx(Y.Button,{variant:"primary",onClick:M,disabled:o||g.length===0,children:o?i.t("sheetImage.save.saving"):i.t("sheetImage.save.confirm")})]})]})}const Pn=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,M){const y=[];return D.forEach(T=>{const{oKey:I}=T,N=M.getDrawingOKey(I);if(N==null)return y.push(null),!0;const{unitId:O,subUnitId:k,drawingId:W,drawingType:P,anchorType:E,sheetTransform:$}=N;y.push({unitId:O,subUnitId:k,drawingId:W,anchorType:E,sheetTransform:$,drawingType:P})}),y}q.useEffect(()=>{const D=u.clearControl$.subscribe(y=>{y===!0&&m(!1)}),M=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()=>{M.unsubscribe(),D.unsubscribe()}},[]);function v(D){S(D);const M=t.getFocusDrawings();if(M.length===0)return;const y=M.map(T=>({unitId:T.unitId,subUnitId:T.subUnitId,drawingId:T.drawingId,anchorType:D}));r.executeCommand(be.id,{unitId:M[0].unitId,drawings:y})}return F.jsxs("div",{className:Y.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!c}),children:[F.jsx("header",{className:"univer-text-gray-600 dark:!univer-text-gray-200",children:F.jsx("div",{children:e.t("drawing-anchor.title")})}),F.jsx("div",{children:F.jsxs(Y.RadioGroup,{value:p,onChange:v,direction:"vertical",children:[F.jsx(Y.Radio,{value:w.SheetDrawingAnchorType.Both,children:e.t("drawing-anchor.both")}),F.jsx(Y.Radio,{value:w.SheetDrawingAnchorType.Position,children:e.t("drawing-anchor.position")}),F.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)&&F.jsxs("div",{className:"univer-text-sm",children:[F.jsx(ge.DrawingCommonPanel,{drawings:e}),F.jsx(Pn,{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:pt.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 $n(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 Fn(){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(!Fn())return!0;const o=e.getCurrentSelections();if(!o||o.length===0)return!0;for(const s of o)if($n(n,s.range))return!1;return!0})):U.of(!0)))]).pipe(U.map(([n,o])=>n||o));return{id:_e.id,type:j.MenuItemType.BUTTON,icon:"DownloadImageIcon",title:"sheetImage.save.menuLabel",hidden$:t}}const Ln={[j.RibbonInsertGroup.MEDIA]:{[Dt]:{order:0,menuItemFactory:kn,[Oe.id]:{order:0,menuItemFactory:Wn},[pt.id]:{order:1,menuItemFactory:Bn}}},[j.ContextMenuPosition.MAIN_AREA]:{[j.ContextMenuGroup.OTHERS]:{[_e.id]:{order:10,menuItemFactory:Tt}}},[j.ContextMenuPosition.COL_HEADER]:{[j.ContextMenuGroup.OTHERS]:{[_e.id]:{order:10,menuItemFactory:Tt}}},[j.ContextMenuPosition.ROW_HEADER]:{[j.ContextMenuGroup.OTHERS]:{[_e.id]:{order:10,menuItemFactory:Tt}}}};function ke(i){return!i.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(l.EDITOR_ACTIVATED)&&!i.getContextValue(l.FOCUSING_PANEL_EDITOR)&&i.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const Yn={id:we.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:we.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:we.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:we.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:lt.id,description:"shortcut.drawing-delete",group:"4_drawing-view",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 Qe=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(ve,Un))}_initMenus(){this._menuManagerService.mergeMenu(Ln)}_initCommands(){[Oe,pt,Ee,Se,be,vt,V,_t,ut,ht,we,lt,gt,_e].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()}};Qe=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))],Qe);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),Lt=(i,r,e)=>Zn(i,typeof r!="symbol"?r+"":r,e);const Qn="SHEET_IMAGE_UI_PLUGIN";R.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(tn,s)}onStarting(){l.registerDependencies(this._injector,[[R.SheetCanvasFloatDomManagerService],[Qe],[Ye],[Je],[ze],[Ke],[Ve],[Xe],[xe],[Fe,{useClass:R.BatchSaveImagesService}]]),l.touchDependencies(this._injector,[[R.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[Ke],[xe]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[ze],[Je],[Qe],[Ve],[Xe]])}onSteady(){this._injector.get(Ye)}_registerRenderModules(){[[R.SheetDrawingUpdateController],[Ct],[yt],[It]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}},Lt(R.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),Lt(R.UniverSheetsDrawingUIPlugin,"pluginName",Qn),R.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)],R.UniverSheetsDrawingUIPlugin),R.ClearSheetDrawingTransformerOperation=V,R.DeleteDrawingsCommand=lt,R.EditSheetDrawingOperation=_t,R.FileNamePart=he,R.GroupSheetDrawingCommand=ut,R.IBatchSaveImagesService=Fe,R.InsertFloatImageCommand=Oe,R.InsertSheetDrawingCommand=Ee,R.MoveDrawingsCommand=we,R.RemoveSheetDrawingCommand=Se,R.SHEETS_IMAGE_MENU_ID=Dt,R.SHEET_FLOAT_DOM_PREFIX=$t,R.SaveCellImagesCommand=_e,R.SetDrawingArrangeCommand=gt,R.SetSheetDrawingCommand=be,R.SidebarSheetDrawingOperation=vt,R.UngroupSheetDrawingCommand=ht,R.calcSheetFloatDomPosition=ae,R.drawingPositionToTransform=J,R.transformToDrawingPosition=H,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})}));
16
16
 
17
17
 
18
18
  // @univerjs/sheets-drawing-ui/facade
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/preset-sheets-drawing",
3
- "version": "0.12.4",
3
+ "version": "0.13.0-insiders.20251215-64041bb",
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.12.4",
62
- "@univerjs/drawing": "0.12.4",
63
- "@univerjs/drawing-ui": "0.12.4",
64
- "@univerjs/sheets-drawing": "0.12.4",
65
- "@univerjs/sheets-drawing-ui": "0.12.4"
61
+ "@univerjs/docs-drawing": "0.13.0-insiders.20251215-64041bb",
62
+ "@univerjs/drawing": "0.13.0-insiders.20251215-64041bb",
63
+ "@univerjs/drawing-ui": "0.13.0-insiders.20251215-64041bb",
64
+ "@univerjs/sheets-drawing": "0.13.0-insiders.20251215-64041bb",
65
+ "@univerjs/sheets-drawing-ui": "0.13.0-insiders.20251215-64041bb"
66
66
  },
67
67
  "devDependencies": {
68
- "@univerjs/core": "0.12.4",
68
+ "@univerjs/core": "0.13.0-insiders.20251215-64041bb",
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.12.4"
73
+ "@univerjs-infra/shared": "0.13.0"
74
74
  },
75
75
  "scripts": {
76
76
  "prebuild:preset": "tsx prepare.ts",