@univerjs/sheets-drawing-ui 0.15.0-insiders.20260107-3d1cfdf → 0.15.0-insiders.20260108-47c73e3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +1 -1
- package/lib/cjs/index.js +2 -2
- package/lib/es/facade.js +52 -52
- package/lib/es/index.js +895 -895
- package/lib/facade.js +52 -52
- package/lib/index.js +895 -895
- package/lib/types/controllers/sheet-drawing-update.controller.d.ts +3 -2
- package/lib/types/services/batch-save-images.service.d.ts +6 -3
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +13 -13
package/lib/umd/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(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,v,D,Y,$e,B,j,Ot,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 te=(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:a=!1,angle:s=0,skewX:c=0,skewY:g=0}=i,u=e.getCurrent();if(u==null)return;const d=b.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:t,to:n},e);let{left:m,top:h,width:p,height:f}=d;const S=e.getCurrentSkeleton(),w=S.rowHeaderWidth+S.columnTotalWidth,_=S.columnHeaderHeight+S.rowTotalHeight;return m+p>w&&(m=w-p),h+f>_&&(h=_-f),{flipY:o,flipX:a,angle:s,skewX:c,skewY:g,left:m,top:h,width:p,height:f}}function H(i,r){const{left:e=0,top:t=0,width:n=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:c=0,skewX:g=0,skewY:u=0}=i,d=r.getCellWithCoordByOffset(e,t);if(d==null)return;const m={column:d.actualColumn,columnOffset:A.precisionTo(e-d.startX,1),row:d.actualRow,rowOffset:A.precisionTo(t-d.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:a,flipX:s,angle:c,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 _,C,M;const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(D.SheetInterceptorService),o=i.get(v.ISheetDrawingService);if(!r)return!1;const{drawings:a}=r,s=[];a.forEach(I=>{const{unitId:T}=I;s.push(T)});const c=o.getBatchRemoveOp(a),{unitId:g,subUnitId:u,undo:d,redo:m,objects:h}=c,p=n.onCommandExecute({id:Se.id,params:r}),f={id:v.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:m,objects:h,type:v.DrawingApplyType.REMOVE}},S={id:v.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:d,objects:h,type:v.DrawingApplyType.INSERT}};return l.sequenceExecute([...(_=p.preRedos)!=null?_:[],f,...p.redos],e)?(t.pushUndoRedo({unitID:g,undoMutations:[...(C=p.preUndos)!=null?C:[],S,...p.undos,{id:V.id,params:s}],redoMutations:[...(M=p.preRedos)!=null?M:[],f,...p.redos,{id:V.id,params:s}]}),!0):!1}},lt={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),t=i.get(v.ISheetDrawingService).getFocusDrawings();if(t.length===0)return!1;const n=t[0].unitId,o=t.map(a=>{const{unitId:s,subUnitId:c,drawingId:g,drawingType:u}=a;return{unitId:s,subUnitId:c,drawingId:g,drawingType:u}});return r.executeCommand(Se.id,{unitId:n,drawings:o})}};function Kt(i){const r=[];return i.forEach(e=>{const{parent:t,children:n}=e,{unitId:o,subUnitId:a,drawingId:s}=t,c=A.getGroupState(0,0,n.map(d=>d.transform||{})),g=n.map(d=>{const m=d.transform||{left:0,top:0},{unitId:h,subUnitId:p,drawingId:f}=d;return{unitId:h,subUnitId:p,drawingId:f,transform:{...m,left:m.left-c.left,top:m.top-c.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:c};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:a,drawingId:s,transform:c={width:0,height:0}}=t;if(c==null)return;const g=n.map(d=>{const{transform:m}=d,{unitId:h,subUnitId:p,drawingId:f}=d,S=A.transformObjectOutOfGroup(m||{},c,c.width||0,c.height||0);return{unitId:h,subUnitId:p,drawingId:f,transform:S,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,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(v.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:p})=>{o.push(h.unitId),p.forEach(f=>{o.push(f.unitId)})});const a=n.getGroupDrawingOp(r),{unitId:s,subUnitId:c,undo:g,redo:u,objects:d}=a;return e.syncExecuteCommand(v.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:c,objects:d,type:v.DrawingApplyType.GROUP})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:v.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:c,objects:zt(d),type:v.DrawingApplyType.UNGROUP}},{id:V.id,params:o}],redoMutations:[{id:v.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:c,objects:d,type:v.DrawingApplyType.GROUP}},{id:V.id,params:o}]}),!0):!1}},Ee={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var _,C,M;const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(v.ISheetDrawingService),o=i.get(D.SheetInterceptorService);if(!r)return!1;const a=r.drawings,s=a.map(I=>I.unitId),c=n.getBatchAddOp(a),{unitId:g,subUnitId:u,undo:d,redo:m,objects:h}=c,p=o.onCommandExecute({id:Ee.id,params:r}),f={id:v.SetDrawingApplyMutation.id,params:{op:m,unitId:g,subUnitId:u,objects:h,type:v.DrawingApplyType.INSERT}},S={id:v.SetDrawingApplyMutation.id,params:{op:d,unitId:g,subUnitId:u,objects:h,type:v.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(_=p.preRedos)!=null?_:[],f,...p.redos],e)?(t.pushUndoRedo({unitID:g,undoMutations:[...(C=p.preUndos)!=null?C:[],S,...p.undos,{id:V.id,params:s}],redoMutations:[...(M=p.preRedos)!=null?M:[],f,...p.redos,{id:V.id,params:s}]}),!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(v.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:c}=r,g={unitId:o,subUnitId:a,drawingIds:s};let u;if(c===l.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):c===l.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):c===l.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):c===l.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:d,redo:m,undo:h}=u;return e.syncExecuteCommand(v.SetDrawingApplyMutation.id,{op:m,unitId:o,subUnitId:a,objects:d,type:v.DrawingApplyType.ARRANGE})?(t.pushUndoRedo({unitID:o,undoMutations:[{id:v.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:d,type:v.DrawingApplyType.ARRANGE}}],redoMutations:[{id:v.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:a,objects:d,type:v.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(v.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=n.getBatchUpdateOp(o),{unitId:s,subUnitId:c,undo:g,redo:u,objects:d}=a;return e.syncExecuteCommand(v.SetDrawingApplyMutation.id,{unitId:s,subUnitId:c,op:u,objects:d,type:v.DrawingApplyType.UPDATE})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:v.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:c,op:g,objects:d,type:v.DrawingApplyType.UPDATE}},{id:V.id,params:[s]}],redoMutations:[{id:v.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:c,op:u,objects:d,type:v.DrawingApplyType.UPDATE}},{id:V.id,params:[s]}]}),!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(v.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:p})=>{o.push(h.unitId),p.forEach(f=>{o.push(f.unitId)})});const a=n.getUngroupDrawingOp(r),{unitId:s,subUnitId:c,undo:g,redo:u,objects:d}=a;return e.syncExecuteCommand(v.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:c,objects:d,type:v.DrawingApplyType.UNGROUP})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:v.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:c,objects:Kt(d),type:v.DrawingApplyType.GROUP}},{id:V.id,params:o}],redoMutations:[{id:v.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:c,objects:d,type:v.DrawingApplyType.UNGROUP}},{id:V.id,params:o}]}),!0):!1}};var qt=Object.getOwnPropertyDescriptor,Zt=(i,r,e,t)=>{for(var n=t>1?void 0:t?qt(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},ne=(i,r)=>(e,t)=>r(e,t,i);function Jt(i,r,e){const t=e*Math.PI/180,n=Math.abs(i*Math.cos(t))+Math.abs(r*Math.sin(t)),o=Math.abs(i*Math.sin(t))+Math.abs(r*Math.cos(t));return{rotatedWidth:n,rotatedHeight:o}}function mt(i,r,e,t,n){var _;const{rotatedHeight:o,rotatedWidth:a}=Jt(e,t,n),c=i.get(A.IRenderManagerService).getRenderById(r.unitId);if(!c)return!1;const u=(_=c.with(b.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:_.skeleton;if(u==null)return!1;const d=u.getCellByIndex(r.row,r.col),m=d.mergeInfo.endX-d.mergeInfo.startX-2,h=d.mergeInfo.endY-d.mergeInfo.startY-2,p=a/o,S=Math.ceil(Math.min(m,h*p))/a,w=!S||Number.isNaN(S)?.001:S;return{width:e*w,height:t*w}}R.SheetDrawingUpdateController=class extends l.Disposable{constructor(e,t,n,o,a,s,c,g,u,d,m,h,p){super();te(this,"_workbookSelections");this._context=e,this._skeletonManagerService=t,this._commandService=n,this._selectionRenderService=o,this._imageIoService=a,this._fileOpenerService=s,this._sheetDrawingService=c,this._drawingManagerService=g,this._contextService=u,this._messageService=d,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(C){const M=C.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:a}=n,{imageId:s,imageSourceType:c,source:g,base64Cache:u}=t,{width:d,height:m,image:h}=await B.getImageSize(u||""),{width:p,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(g,c,h);let S=1;if(d>B.DRAWING_IMAGE_WIDTH_LIMIT||m>B.DRAWING_IMAGE_HEIGHT_LIMIT){const C=B.DRAWING_IMAGE_WIDTH_LIMIT/d,M=B.DRAWING_IMAGE_HEIGHT_LIMIT/m;S=Math.max(C,M)}const w=this._getImagePosition(d*S,m*S,p,f);if(w==null)return;const _={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c,source:g,transform:J(w,this._selectionRenderService,this._skeletonManagerService),sheetTransform:w};return this._commandService.executeCommand(Ee.id,{unitId:o,drawings:[_]})}async _insertCellImage(e,t){var M,I;let n;try{n=await this._imageIoService.saveImage(e)}catch(T){const y=T.message;y===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)))}):y===B.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===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:a,source:s,base64Cache:c}=n,{width:g,height:u,image:d}=await B.getImageSize(c||"");this._imageIoService.addImageSourceCache(s,a,d);const m=this._workbookSelections.getCurrentLastSelection();if(!m)return!1;let h=m.primary.actualRow,p=m.primary.actualColumn;m.primary.isMerged&&(h=m.primary.startRow,p=m.primary.startColumn);const f=l.createDocumentModelWithStyle("",{}),S=mt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:h,col:p},g,u,0);if(!S)return!1;const w={size:{width:S.width,height:S.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},_={unitId:f.getUnitId(),subUnitId:f.getUnitId(),drawingId:o,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:s,transform:$e.docDrawingPositionToTransform(w),docTransform:w,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},C=l.BuildTextUtils.drawing.add({documentDataModel:f,drawings:[_],selection:{collapsed:!0,startOffset:0,endOffset:0}});return C?(f.apply(C),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(M=t==null?void 0:t.row)!=null?M:h]:{[(I=t==null?void 0:t.col)!=null?I:p]:{p:f.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:a}=await B.getImageSize(e||"");this._imageIoService.addImageSourceCache(e,l.ImageSourceType.URL,a);const s=this._workbookSelections.getCurrentLastSelection();if(!s)return!1;const c=l.createDocumentModelWithStyle("",{}),g=mt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:s.primary.actualRow,col:s.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},d={unitId:c.getUnitId(),subUnitId:c.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:c,drawings:[d],selection:{collapsed:!0,startOffset:0,endOffset:0}});return m?(c.apply(m),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(h=t==null?void 0:t.row)!=null?h:s.primary.actualRow]:{[(p=t==null?void 0:t.col)!=null?p:s.primary.actualColumn]:{p:c.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 a=this._workbookSelections.getCurrentSelections();let s={startRow:0,endRow:0,startColumn:0,endColumn:0};a&&a.length>0&&(s=a[a.length-1].range);const c=b.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);if(c==null)return;let{startColumn:g,startRow:u,startX:d,startY:m}=c,h=!1;if(d+e>n&&(d=n-e,d<0&&(d=0,e=n),h=!0),m+t>o&&(m=o-t,m<0&&(m=0,t=o),h=!0),h){const w=this._selectionRenderService.getCellWithCoordByOffset(d,m);if(w==null)return;d=w.startX,m=w.startY,g=w.actualColumn,u=w.actualRow}const p={column:g,columnOffset:0,row:u,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(d+e,m+t);if(f==null)return;const S={column:f.actualColumn,columnOffset:d+e-f.startX,row:f.actualRow,rowOffset:m+t-f.startY};return{from:p,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{const{unitId:t,subUnitId:n,drawingIds:o,arrangeType:a}=e;this._commandService.executeCommand(gt.id,{unitId:t,subUnitId:n,drawingIds:o,arrangeType:a})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{const t=[];e.length!==0&&(e.forEach(n=>{const{unitId:o,subUnitId:a,drawingId:s,drawingType:c,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:s});if(u==null||u.unitId!==this._context.unitId)return;const d=H({...u.transform,...g},this._selectionRenderService);if(d==null)return;const m={...n,transform:{...u.transform,...g,...J(d,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...d}};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=Zt([ne(1,l.Inject(b.SheetSkeletonManagerService)),ne(2,l.ICommandService),ne(3,b.ISheetSelectionRenderService),ne(4,B.IImageIoService),ne(5,j.ILocalFileService),ne(6,v.ISheetDrawingService),ne(7,B.IDrawingManagerService),ne(8,l.IContextService),ne(9,j.IMessageService),ne(10,l.Inject(l.LocaleService)),ne(11,l.Inject(D.SheetsSelectionsService)),ne(12,l.Inject(l.Injector))],R.SheetDrawingUpdateController);const Oe={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{var a,s;const e=i.get(l.IUniverInstanceService),t=i.get(A.IRenderManagerService),n=(a=A.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,e,t))==null?void 0:a.with(R.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const c=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(c)).every(g=>g)}else return(s=n.insertFloatImage())!=null?s:!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(v.ISheetDrawingService),n=i.get(b.ISheetSelectionRenderService),{direction:o}=r,a=t.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,c=a.map(u=>{const{transform:d}=u;if(d==null)return null;const m={...d},{left:h=0,top:p=0}=d;return o===l.Direction.UP?m.top=p-1:o===l.Direction.DOWN?m.top=p+1:o===l.Direction.LEFT?m.left=h-1:o===l.Direction.RIGHT&&(m.left=h+1),{...u,transform:m,sheetTransform:H(m,n)}}).filter(u=>u!=null);return e.syncExecuteCommand(be.id,{unitId:s,drawings:c})?(e.syncExecuteCommand(V.id,[s]),!0):!1}};var Qt=Object.getOwnPropertyDescriptor,en=(i,r,e,t)=>{for(var n=t>1?void 0:t?Qt(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(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 tn(i){const r=Le(i.startRow,i.startColumn),e=Le(i.endRow,i.endColumn);return r===e?r:`${r}:${e}`}function At(i){var r,e,t,n;return!!((e=(r=i==null?void 0:i.p)==null?void 0:r.drawingsOrder)!=null&&e.length&&((n=(t=i==null?void 0:i.p)==null?void 0:t.drawingsOrder)==null?void 0:n.length)>0)}function Ut(i){var t,n,o;if(!((n=(t=i.p)==null?void 0:t.drawingsOrder)!=null&&n.length)||!((o=i.p)!=null&&o.drawings))return null;const r=i.p.drawingsOrder[0],e=i.p.drawings[r];return!e||!("source"in e)||!("imageSourceType"in e)?null:e}function 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 vt(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(e,t,n){super();te(this,"_urlImageDownloader",null);this._univerInstanceService=e,this._selectionService=t,this._imageIoService=n}registerURLImageDownloader(e){return this._urlImageDownloader=e,l.toDisposable(()=>{this._urlImageDownloader===e&&(this._urlImageDownloader=null)})}getCellImagesInSelection(){const e=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!e)return[];const t=e.getActiveSheet();if(!t)return[];const n=this._selectionService.getCurrentSelections();if(!n||n.length===0)return[];const o=t.getCellMatrix(),a=[];for(const s of n){const{startRow:c,endRow:g,startColumn:u,endColumn:d}=s.range;for(let m=c;m<=g;m++)for(let h=u;h<=d;h++){const p=o.getValue(m,h);if(At(p)){const f=Ut(p);f&&a.push({row:m,col:h,cellAddress:Le(m,h),source:f.source,imageSourceType:f.imageSourceType,imageId:f.drawingId})}}}return a}getCellImagesFromRanges(e,t,n){const o=this._univerInstanceService.getUnit(e,l.UniverInstanceType.UNIVER_SHEET);if(!o)return[];const a=o.getSheetBySheetId(t);if(!a)return[];const s=a.getCellMatrix(),c=[];for(const g of n){const{startRow:u,endRow:d,startColumn:m,endColumn:h}=g;for(let p=u;p<=d;p++)for(let f=m;f<=h;f++){const S=s.getValue(p,f);if(At(S)){const w=Ut(S);w&&c.push({row:p,col:f,cellAddress:Le(p,f),source:w.source,imageSourceType:w.imageSourceType,imageId:w.drawingId})}}}return c}getDataColumns(){var h,p,f,S;const e=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!e)return[];const t=e.getActiveSheet();if(!t)return[];const n=this._selectionService.getCurrentSelections();if(!n||n.length===0)return[];const o=t.getCellMatrix(),a=o.getDataRange();let s=1/0,c=-1/0;const g=new Set;for(const w of n){s=Math.min(s,w.range.startRow),c=Math.max(c,w.range.endRow);for(let _=w.range.startColumn;_<=w.range.endColumn;_++)g.add(_)}const u=new Set;for(let w=a.startColumn;w<=a.endColumn;w++)if(!g.has(w))for(let _=s;_<=c;_++){const C=o.getValue(_,w);if(C&&(((h=C.v)==null?void 0:h.toString())||((S=(f=(p=C.p)==null?void 0:p.body)==null?void 0:f.dataStream)==null?void 0:S.trim())||"")){u.add(w);break}}const d=[],m=Array.from(u).sort((w,_)=>w-_);for(const w of m)d.push({index:w,label:St(w)});return d}getDataColumnsForRanges(e,t,n){var f,S,w,_;const o=this._univerInstanceService.getUnit(e,l.UniverInstanceType.UNIVER_SHEET);if(!o)return[];const a=o.getSheetBySheetId(t);if(!a)return[];const s=a.getCellMatrix(),c=s.getDataRange();let g=1/0,u=-1/0;const d=new Set;for(const C of n){g=Math.min(g,C.startRow),u=Math.max(u,C.endRow);for(let M=C.startColumn;M<=C.endColumn;M++)d.add(M)}const m=new Set;for(let C=c.startColumn;C<=c.endColumn;C++)if(!d.has(C))for(let M=g;M<=u;M++){const I=s.getValue(M,C);if(I&&(((f=I.v)==null?void 0:f.toString())||((_=(w=(S=I.p)==null?void 0:S.body)==null?void 0:w.dataStream)==null?void 0:_.trim())||"")){m.add(C);break}}const h=[],p=Array.from(m).sort((C,M)=>C-M);for(const C of p)h.push({index:C,label:St(C)});return h}getSelectionRangeNotation(){const e=this._selectionService.getCurrentSelections();return!e||e.length===0?"":e.map(t=>tn(t.range)).join(", ")}getSelectionRowRange(){const e=this._selectionService.getCurrentSelections();if(!e||e.length===0)return null;let t=1/0,n=-1/0;for(const o of e)t=Math.min(t,o.range.startRow),n=Math.max(n,o.range.endRow);return{startRow:t,endRow:n}}getSelectionColumnIndices(){const e=this._selectionService.getCurrentSelections();if(!e||e.length===0)return new Set;const t=new Set;for(const n of e)for(let o=n.range.startColumn;o<=n.range.endColumn;o++)t.add(o);return t}generateFileName(e,t){var s,c,g,u;const n=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),o=wt(e.source,e.imageSourceType),a=[];for(const d of t.fileNameParts)if(d==="cellAddress")a.push(e.cellAddress);else if(d==="columnValue"&&t.columnIndex!==void 0){const m=n==null?void 0:n.getActiveSheet();if(m){const p=m.getCellMatrix().getValue(e.row,t.columnIndex);if(p){const f=((s=p.v)==null?void 0:s.toString())||((u=(g=(c=p.p)==null?void 0:c.body)==null?void 0:g.dataStream)==null?void 0:u.trim())||"";if(f){const S=f.replace(/[<>:"/\\|?*]/g,"_").trim();S&&a.push(S)}}}}return a.length===0?`${e.cellAddress}.${o}`:`${a.join("_")}.${o}`}generateFileNameWithContext(e,t,n,o){var g,u,d,m;const a=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET),s=wt(e.source,e.imageSourceType),c=[];for(const h of t.fileNameParts)if(h==="cellAddress")c.push(e.cellAddress);else if(h==="columnValue"&&t.columnIndex!==void 0){const p=a==null?void 0:a.getSheetBySheetId(o);if(p){const S=p.getCellMatrix().getValue(e.row,t.columnIndex);if(S){const w=((g=S.v)==null?void 0:g.toString())||((m=(d=(u=S.p)==null?void 0:u.body)==null?void 0:d.dataStream)==null?void 0:m.trim())||"";if(w){const _=w.replace(/[<>:"/\\|?*]/g,"_").trim();_&&c.push(_)}}}}return c.length===0?`${e.cellAddress}.${s}`:`${c.join("_")}.${s}`}async saveImages(e,t){var a;const n=await window.showDirectoryPicker({mode:"readwrite"}),o=new Map;for(const s of e){let c=this.generateFileName(s,t);const g=c.replace(/\.\w+$/,""),u=((a=c.match(/\.\w+$/))==null?void 0:a[0])||".png",d=o.get(g)||0;d>0&&(c=`${g}_${d}${u}`),o.set(g,d+1);try{const m=await this._getImageBlob(s),p=await(await n.getFileHandle(c,{create:!0})).createWritable();await p.write(m),await p.close()}catch(m){throw console.error(`Failed to save image ${c}:`,m),m}}}async saveImagesWithContext(e,t,n,o){var c;const a=await window.showDirectoryPicker({mode:"readwrite"}),s=new Map;for(const g of e){let u=this.generateFileNameWithContext(g,t,n,o);const d=u.replace(/\.\w+$/,""),m=((c=u.match(/\.\w+$/))==null?void 0:c[0])||".png",h=s.get(d)||0;h>0&&(u=`${d}_${h}${m}`),s.set(d,h+1);try{const p=await this._getImageBlob(g),S=await(await a.getFileHandle(u,{create:!0})).createWritable();await S.write(p),await S.close()}catch(p){throw console.error(`Failed to save image ${u}:`,p),p}}}async downloadSingleImage(e){const t=wt(e.source,e.imageSourceType),n=`${e.cellAddress}.${t}`;try{const o=await this._getImageBlob(e),a=URL.createObjectURL(o),s=document.createElement("a");s.href=a,s.download=n,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(a)}catch(o){throw console.error(`Failed to download image ${n}:`,o),o}}async _getImageBlob(e){if(e.imageSourceType===l.ImageSourceType.UUID){const t=await this._imageIoService.getImage(e.source);return vt(t,l.ImageSourceType.URL)}if(e.imageSourceType===l.ImageSourceType.URL&&this._urlImageDownloader)try{const t=await this._urlImageDownloader(e.source);return vt(t,l.ImageSourceType.BASE64)}catch(t){console.error(`Custom downloader failed for ${e.source}, falling back to default fetch:`,t)}return vt(e.source,e.imageSourceType)}},R.BatchSaveImagesService=en([ft(0,l.IUniverInstanceService),ft(1,l.Inject(D.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(s){return console.error("Failed to download image:",s),!1}const n=i.get(l.LocaleService),o=e.getSelectionRangeNotation(),a=`${n.t("sheetImage.save.title")} (${o})`;return r.open({id:ve,draggable:!0,width:360,title:{title:a},children:{label:ve},destroyOnClose:!0,preservePositionOnDestroy:!0,onClose:()=>r.close(ve)}),!0}},Pt="COMPONENT_SHEET_DRAWING_PANEL",_t={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{const e=i.get(j.ISidebarService),t=i.get(l.LocaleService),n=i.get(l.IUniverInstanceService),o=i.get(l.ICommandService);return D.getSheetCommandTarget(n)?(r.value==="open"?e.open({header:{title:t.t("sheetImage.panel.title")},children:{label:Pt},onClose:()=>{o.syncExecuteCommand(B.SetDrawingSelectedOperation.id,[])},width:360}):e.close(),!0):!1}},It={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(i,r)=>{const e=i.get(l.ICommandService);return r==null?!1:(e.syncExecuteCommand(B.SetDrawingSelectedOperation.id,[r]),e.executeCommand(_t.id,{value:"open"}),!0)}},nn="sheets-drawing-ui.config",Nt={};var rn=Object.getOwnPropertyDescriptor,on=(i,r,e,t)=>{for(var n=t>1?void 0:t?rn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},ae=(i,r)=>(e,t)=>r(e,t,i);let Ye=class extends l.RxDisposable{constructor(r,e,t,n,o,a,s,c,g,u){super();te(this,"_initImagePopupMenu",new Set);this._injector=r,this._localeService=e,this._drawingManagerService=t,this._canvasPopManagerService=n,this._renderManagerService=o,this._univerInstanceService=a,this._messageService=s,this._contextService=c,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 a=t.getSelectedObjectMap();if(a.size>1){n==null||n.dispose();return}const s=a.values().next().value;if(!s)return;const c=s.oKey,g=this._drawingManagerService.getDrawingOKey(c);if(!g)return;const{unitId:u,subUnitId:d,drawingId:m,drawingType:h}=g,p=g.data;if(p&&p.disablePopup)return;n==null||n.dispose();const f=this._canvasPopManagerService.getFeatureMenu(u,d,m,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:ge.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:f||this._getImageMenuItems(u,d,m,h)}}))})),this.disposeWithMe(t.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(B.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[l.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(t.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,e,t,n){return[{label:"image-popup.edit",index:0,commandId:It.id,commandParams:{unitId:r,subUnitId:e,drawingId:t},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId: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=on([ae(0,l.Inject(l.Injector)),ae(1,l.Inject(l.LocaleService)),ae(2,B.IDrawingManagerService),ae(3,l.Inject(b.SheetCanvasPopManagerService)),ae(4,A.IRenderManagerService),ae(5,l.IUniverInstanceService),ae(6,j.IMessageService),ae(7,l.IContextService),ae(8,l.IImageIoService),ae(9,l.ICommandService)],Ye);var an=Object.getOwnPropertyDescriptor,sn=(i,r,e,t)=>{for(var n=t>1?void 0:t?an(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ge=(i,r)=>(e,t)=>r(e,t,i);let yt=class extends l.Disposable{constructor(r,e,t,n,o){super();te(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}}))}};yt=sn([Ge(1,l.Inject(b.HoverManagerService)),Ge(2,l.Inject(D.SheetsSelectionsService)),Ge(3,l.Inject(ge.DrawingRenderService)),Ge(4,l.Inject(b.SheetSkeletonManagerService))],yt);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,a;o>=0;o--)(a=i[o])&&(n=a(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=dn([He(1,v.ISheetDrawingService),He(2,B.IDrawingManagerService),He(3,l.Inject(b.ISheetSelectionRenderService)),He(4,l.Inject(b.SheetSkeletonManagerService))],Ct);var ln=Object.getOwnPropertyDescriptor,un=(i,r,e,t)=>{for(var n=t>1?void 0:t?ln(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ie=(i,r)=>(e,t)=>r(e,t,i);function kt(i,r,e){var t,n,o,a;if(((n=(t=e==null?void 0:e.p)==null?void 0:t.body)==null?void 0:n.dataStream.length)===3&&((a=(o=e.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const s=e.p.drawings[e.p.drawingsOrder[0]],c=mt(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},s.docTransform.size.width,s.docTransform.size.height,s.docTransform.angle);if(c)return s.transform.width=c.width,s.transform.height=c.height,s.docTransform.size.width=c.width,s.docTransform.size.height=c.height,s.transform.left=0,s.transform.top=0,s.docTransform.positionH.posOffset=0,s.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(D.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:D.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=un([Ie(0,l.ICommandService),Ie(1,l.Inject(D.SheetInterceptorService)),Ie(2,l.Inject(l.Injector)),Ie(3,B.IDrawingManagerService),Ie(4,l.Inject(Ot.DocDrawingController)),Ie(5,l.Inject(b.IEditorBridgeService))],Ve);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,a;o>=0;o--)(a=i[o])&&(n=a(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,a)=>{kt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},a)})}}))}};Xe=hn([Wt(0,l.Inject(b.IAutoFillService)),Wt(1,l.Inject(l.Injector))],Xe);var mn=Object.getOwnPropertyDescriptor,pn=(i,r,e,t)=>{for(var n=t>1?void 0:t?mn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ae=(i,r)=>(e,t)=>r(e,t,i);const fn=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,l.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let 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 a=o.getUnitId();if(fn.includes(a)){if(a!==l.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const s=()=>{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
|
|
2
|
-
`?(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:s,showOk:!0,showCancel:!0,onOk:()=>{s(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:s})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};xe=pn([Ae(0,l.ICommandService),Ae(1,l.IUniverInstanceService),Ae(2,j.IDialogService),Ae(3,A.IRenderManagerService),Ae(4,l.Inject(l.LocaleService))],xe);var Sn=Object.getOwnPropertyDescriptor,wn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Sn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ue=(i,r)=>(e,t)=>r(e,t,i);const Bt="image/png";function vn(i){const r=i.split(","),e=atob(r[1]),t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return new Blob([n],{type:Bt})}function _n(i){const r=new ClipboardItem({[Bt]:vn(i)});navigator.clipboard.write([r]).catch(e=>{console.error("Could not copy image using clipboard API: ",e)})}function In(){function i(){const t=document.createElement("input");return t.style.position="absolute",t.style.height="1px",t.style.width="1px",t.style.opacity="0",t}const r=document.activeElement,e=i();return document.body.appendChild(e),e.focus(),()=>{e.blur(),document.body.removeChild(e),r instanceof HTMLElement&&r.focus()}}const jt=[b.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,b.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,b.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,b.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA];let Ke=class extends l.Disposable{constructor(r,e,t,n,o){super();te(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[a]=o;if(a.drawingType!==l.DrawingTypeEnum.DRAWING_IMAGE)return;if(n===b.COPY_TYPE.CUT){const c={unitId:r,drawings:[a]};this._commandService.executeCommand(Se.id,c)}setTimeout(()=>{const c=In();a.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&a.imageSourceType===B.ImageSourceType.BASE64?_n(a.source):this._clipboardInterfaceService.writeText(""),c()},200);const s={unitId:a.unitId,subUnitId:a.subUnitId,drawings:[a]};this._copyInfo=s}else{const a=this._createDrawingsCopyInfoByRange(r,e,t);this._copyInfo=a}},onPasteCells:(r,e,t,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=b.COPY_TYPE.COPY,pasteType:a}=n,{range:s}=r||{},{range:c,unitId:g,subUnitId:u}=e;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:a,unitId:g,subUnitId:u,pasteRange:c},{copyRange:s,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:e,pasteType:a},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:a,endX:s,startY:c,endY:g}=o,u=this._drawingService.getDrawingData(r,e),d=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const p=u[h];if(p.drawingType!==l.DrawingTypeEnum.DRAWING_IMAGE)return;const{transform:f}=p;if(p.anchorType!==v.SheetDrawingAnchorType.Both||!f)return;const{left:S=0,top:w=0,width:_=0,height:C=0}=f,{drawingStartX:M,drawingEndX:I,drawingStartY:T,drawingEndY:y}={drawingStartX:S,drawingEndX:S+_,drawingStartY:w,drawingEndY:w+C};a<=M&&I<=s&&c<=T&&y<=g&&d.push(p)}),d.length)return{copyRange:t,drawings:d,unitId:r,subUnitId:e}}_generateSingleDrawingPasteMutations(r,e){const{pasteType:t,pasteTo:n}=r;if(jt.includes(t))return{redos:[],undos:[]};const{unitId:o,subUnitId:a,range:s}=n,c=this._renderManagerService.getRenderById(o),g=c==null?void 0:c.with(b.SheetSkeletonManagerService),u=c==null?void 0:c.with(b.ISheetSelectionRenderService),d=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:m}=d,h=b.discreteRangeToRange(s);return this._generateMutations(m,{unitId:o,subUnitId:a,isCut:e===b.COPY_TYPE.CUT,getTransform:(p,f)=>{var _;const S=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),w={...p,left:S==null?void 0:S.startX,top:S==null?void 0:S.startY};return{transform:w,sheetTransform:(_=H(w,u))!=null?_:f}}})}_generateMutations(r,e){const{unitId:t,subUnitId:n,getTransform:o,isCut:a}=e,s=[],c=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:d,sheetTransform:m}=u;if(!d)return;const h=o(d,m),p={...u,unitId:t,subUnitId:n,drawingId:a?u.drawingId:l.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(a){const{undo:f,redo:S,objects:w}=g.getBatchUpdateOp([p]);s.push({id:v.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:v.DrawingApplyType.UPDATE,op:S,objects:w}}),c.push({id:v.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:v.DrawingApplyType.UPDATE,op:f,objects:w}})}else{const{undo:f,redo:S,objects:w}=g.getBatchAddOp([p]);s.push({id:v.SetDrawingApplyMutation.id,params:{op:S,unitId:t,subUnitId:n,objects:w,type:v.DrawingApplyType.INSERT}}),c.push({id:v.SetDrawingApplyMutation.id,params:{op:f,unitId:t,subUnitId:n,objects:w,type:v.DrawingApplyType.REMOVE}})}}),{redos:s,undos:c}}_generateRangeDrawingsPasteMutations(r,e){var N;const{unitId:t,subUnitId:n,pasteType:o,pasteRange:a}=r,{copyRange:s,copyType:c}=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(!s)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:t,subUnitId:n,range:b.discreteRangeToRange(a)},pasteType:o},c);const{ranges:[d,m],mapFunc:h}=b.virtualizeDiscreteRanges([s,a]),{row:p,col:f}=h(d.startRow,d.startColumn),{row:S,col:w}=h(m.startRow,m.startColumn),_=g.attachRangeWithCoord({startRow:p,endRow:p,startColumn:f,endColumn:f}),C=g.attachRangeWithCoord({startRow:S,endRow:S,startColumn:w,endColumn:w});if(!_||!C||!this._copyInfo)return{redos:[],undos:[]};const M=C.startX-_.startX,I=C.startY-_.startY,T=S-p,y=w-f;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)+I},sheetTransform:{...k,to:{...k.to,row:k.to.row+T,column:k.to.column+y},from:{...k.from,row:k.from.row+T,column:k.from.column+y}}}},isCut:c===b.COPY_TYPE.CUT})}};Ke=wn([Ue(0,b.ISheetClipboardService),Ue(1,A.IRenderManagerService),Ue(2,B.IDrawingManagerService),Ue(3,j.IClipboardInterfaceService),Ue(4,l.ICommandService)],Ke);var yn=Object.getOwnPropertyDescriptor,Cn=(i,r,e,t)=>{for(var n=t>1?void 0:t?yn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(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 a=t.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new D.WorkbookViewPermission(a).id,new D.WorksheetViewPermission(a,s).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),a=this._renderManagerService.getRenderById(e),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===A.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.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 a=t.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new D.WorkbookEditablePermission(a).id,new D.WorksheetEditPermission(a,s).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),a=this._renderManagerService.getRenderById(e),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===A.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.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(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),c=s==null?void 0:s.scene;if(!c)return U.EMPTY;const g=c.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookViewPermission(o).id,new D.WorksheetViewPermission(o,a).id]).pipe(U.map(d=>d.every(m=>m.value)),U.distinctUntilChanged()).pipe(U.map(d=>({permission:d,scene:c,transformer:g,unitId:o,subUnitId:a})))})):U.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingVisible(e);const s=t.getAllObjectsByOrder(),c=this._drawingManagerService.getDrawingData(o,a),g=Object.values(c);e?this._drawingManagerService.addNotification(g):(s.forEach(u=>{u.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&t.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const e=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),t=e==null?void 0:e.getActiveSheet(),n=e==null?void 0:e.getUnitId(),o=t==null?void 0:t.getSheetId();if(!n||!o)return;const a=this._drawingManagerService.getDrawingData(n,o),s=Object.values(a);this._drawingManagerService.addNotification(s)}}))}_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(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),c=s==null?void 0:s.scene;if(!c)return U.EMPTY;const g=c.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookEditablePermission(o).id,new D.WorksheetEditPermission(o,a).id]).pipe(U.map(d=>d.every(m=>m.value)),U.distinctUntilChanged()).pipe(U.map(d=>({permission:d,scene:c,transformer:g,unitId:o,subUnitId:a})))})):U.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingEditable(e);const s=t.getAllObjectsByOrder(),c=this._drawingManagerService.getDrawingData(o,a),g=Object.values(c);e?(s.forEach(u=>{u.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&t.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(s.forEach(u=>{u.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&t.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const e=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!e)return;const t=e.getUnitId(),n=e.getActiveSheet();if(!n)return;const o=n.getSheetId(),a=this._renderManagerService.getRenderById(t),s=a==null?void 0:a.scene;if(!s)return;const c=this._drawingManagerService.getDrawingData(t,o),g=Object.values(c);this._drawingManagerService.setDrawingEditable(!0),s.getAllObjectsByOrder().forEach(d=>{d.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(m=>d.oKey.includes(m.drawingId))&&s.detachTransformerFrom(d)})}}))}};ze=Cn([Pe(0,B.IDrawingManagerService),Pe(1,A.IRenderManagerService),Pe(2,l.IPermissionService),Pe(3,l.IUniverInstanceService),Pe(4,l.Inject(l.UserManagerService))],ze);var Dn=Object.getOwnPropertyDescriptor,Tn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Dn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(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:a,scaleY:s}=r.getAncestorScale(),c=r.getViewport(A.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=t.getFreeze(),{startColumn:u,startRow:d,xSplit:m,ySplit:h}=g,p={left:!0,top:!0};if(!c)return{...i,absolute:p};const{left:f,right:S,top:w,bottom:_}=i;let{top:C,left:M,viewportScrollX:I,viewportScrollY:T}=c;const{boundsOfViewArea:y,scrollDirectionResponse:N}=n||{},{rowHeaderWidth:O,columnHeaderHeight:k}=e,W={top:o?0:k,left:o?0:O};y&&(l.Tools.isDefine(W.top)&&(W.top=y.top),l.Tools.isDefine(W.left)&&(W.left=y.left)),N==="HORIZONTAL"&&(T=0),N==="VERTICAL"&&(I=0);let P=0,E=0;const $=e.rowStartY(d-h)+k,G=e.colStartX(u-m)+O,Q=e.rowStartY(d)+k,re=e.colStartX(u)+O;if(m===0)p.left=!1,P=(f-I)*a,E=(S-I)*a;else{const z=f-(G-O),ee=S-(G-O);S<re?(P=z*a,E=ee*a):f<=re&&S>=re?(P=z*a,E=Math.max(M,(S-I)*a)):f>re&&(p.left=!1,P=Math.max((f-I)*a,M),E=Math.max((S-I)*a,M))}let K=0,Z=0;if(h===0)p.top=!1,K=(w-T)*s,Z=(_-T)*s;else{const z=w-($-k),ee=_-($-k);_<Q?(K=z*s,Z=ee*s):w<=Q&&_>=Q?(K=z*s,Z=Math.max(C,(_-T)*s)):w>Q&&(p.top=!1,K=Math.max((w-T)*s,C),Z=Math.max((_-T)*s,C))}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 se=(i,r,e,t,n)=>{const{left:o,top:a,width:s,height:c,angle:g}=i,u={left:o,right:o+s,top:a,bottom:a+c},d=Ft(u,r,e,t,n),{scaleX:m,scaleY:h}=r.getAncestorScale();return{startX:d.left,endX:d.right,startY:d.top,endY:d.bottom,rotate:g,width:s*m,height:c*h,absolute:d.absolute}};R.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(e,t,n,o,a,s,c){super();te(this,"_domLayerInfoMap",new Map);te(this,"_transformChange$",new U.Subject);te(this,"transformChange$",this._transformChange$.asObservable());te(this,"_add$",new U.Subject);te(this,"add$",this._add$.asObservable());te(this,"_remove$",new U.Subject);te(this,"remove$",this._remove$.asObservable());this._renderManagerService=e,this._univerInstanceService=t,this._commandService=n,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=s,this._lifecycleService=c,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(),a=t.engine.getCanvasElement();return{scene:n,transformer:o,renderUnit:t,canvas:a}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(t=>{var ee;const{unitId:n,subUnitId:o,drawingId:a}=t,s=D.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),c=this._drawingManagerService.getDrawingByParam(t),g=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!c||!s)return;const d=(ee=this._renderManagerService.getRenderById(n))==null?void 0:ee.with(b.SheetSkeletonManagerService).getSkeletonParam(o);if(!d)return;const{transform:m,drawingType:h,data:p}=c;if(h!==l.DrawingTypeEnum.DRAWING_DOM&&h!==l.DrawingTypeEnum.DRAWING_CHART)return;const f=this._getSceneAndTransformerByDrawingSearch(n);if(f==null)return;const{scene:S,canvas:w}=f;if(m==null)return!0;if(u!==o)return;const{left:_,top:C,width:M,height:I,angle:T,flipX:y,flipY:N,skewX:O,skewY:k}=m,W=B.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),P=S.getObject(W);if(P!=null){P.transformByState({left:_,top:C,width:M,height:I,angle:T,flipX:y,flipY:N,skewX:O,skewY:k});return}const E={left:_,top:C,width:M,height:I,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),S.addObject(G,A.DRAWING_OBJECT_LAYER_INDEX),c.allowTransform!==!1&&S.attachTransformerTo(G);const Q=new l.DisposableCollection,re=se(G,f.renderUnit.scene,d.skeleton,s.worksheet),K=new U.BehaviorSubject(re),Z=`${$t}${l.generateRandomId(6)}`,oe={dispose:Q,rect:G,position$:K,unitId:n,subUnitId:o,id:a,domId:Z};this._canvasFloatDomService.addFloatDom({position$:K,id:a,domId:Z,componentKey:c.componentKey,onPointerDown:X=>{w.dispatchEvent(new PointerEvent(X.type,X))},onPointerMove:X=>{w.dispatchEvent(new PointerEvent(X.type,X))},onPointerUp:X=>{w.dispatchEvent(new PointerEvent(X.type,X))},onWheel:X=>{w.dispatchEvent(new WheelEvent(X.type,X))},data:p,unitId:n});const z=G.onTransformChange$.subscribeEvent(()=>{const X=se(G,f.renderUnit.scene,d.skeleton,s.worksheet);K.next(X)});Q.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),z&&Q.add(z),this._domLayerInfoMap.set(a,oe)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(t=>{var m;const{unitId:n,subUnitId:o,drawingId:a}=t,s=B.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),c=this._getSceneAndTransformerByDrawingSearch(n);if(c==null)return;const{transformer:g,scene:u}=c,d=u.getObject(s);d!=null&&d.oKey&&(g.clearControlByIds([d==null?void 0:d.oKey]),(m=u.getTransformer())==null||m.clearSelectedObjects())})}))}_scrollUpdateListener(){const e=(t,n)=>{var g;const o=this._getSceneAndTransformerByDrawingSearch(t),a=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),s=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:n}),c=(g=this._renderManagerService.getRenderById(t))==null?void 0:g.with(b.SheetSkeletonManagerService).getSkeletonParam(n);!o||!s||!c||a.forEach(u=>{const d=this._domLayerInfoMap.get(u);if(d){const m=se(d.rect,o.renderUnit.scene,c.skeleton,s.worksheet,d);d.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(s=>s.unitId===o).map(s=>s.subUnitId).forEach(s=>{e(o,s)})}else if(t.id===D.SetFrozenMutation.id){const{unitId:n,subUnitId:o}=t.params;e(n,o)}else if(t.id===D.SetSelectionsOperation.id){const{unitId:n,subUnitId:o}=t.params;e(n,o)}}))}updateFloatDomProps(e,t,n,o){const a=this._domLayerInfoMap.get(n),s=this._getSceneAndTransformerByDrawingSearch(e);if(a&&s){const{scene:c}=s,g=B.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:t,drawingId:n}),u=c.getObject(g);u&&u instanceof A.Rect&&u.setProps(o)}}_getPosition(e,t){var h;const{startX:n,endX:o,startY:a,endY:s}=e,c=(h=this._renderManagerService.getRenderById(t))==null?void 0:h.with(b.ISheetSelectionRenderService);if(c==null)return;const g=c.getCellWithCoordByOffset(n,a);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:a-g.startY},d=c.getCellWithCoordByOffset(o,s);if(d==null)return;const m={column:d.actualColumn,columnOffset:o-d.startX,row:d.actualRow,rowOffset:s-d.startY};return{from:u,to:m}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(t=>{const n=this._drawingManagerService.getDrawingByParam(t);if(!n||n.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const o={...n.transform};this._transformChange$.next({id:t.drawingId,value:o}),this._canvasFloatDomService.updateFloatDom(t.drawingId,{...n});const a=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(a&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART){const{scene:s}=a,c=this._domLayerInfoMap.get(t.drawingId);c!=null&&c.rect&&(n.allowTransform===!1?s.detachTransformerFrom(c.rect):s.attachTransformerTo(c.rect))}})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(t=>{this._removeDom(t.drawingId)})}))}addFloatDomToPosition(e,t){const n=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=n,{initPosition:s,componentKey:c,data:g,allowTransform:u=!0}=e,d=t!=null?t:l.generateRandomId(),m=this._getPosition(s,o);if(m==null)return;const h={unitId:o,subUnitId:a,drawingId:d,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:c,sheetTransform:m,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Ee.id,{unitId:o,drawings:[h]}),this._add$.next({unitId:o,subUnitId:a,id:d}),{id:d,dispose:()=>{this._removeDom(d,!0)}}}_removeDom(e,t=!1){const n=this._domLayerInfoMap.get(e);if(!n)return;const{unitId:o,subUnitId:a}=n;this._domLayerInfoMap.delete(e),n.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(n.rect),t){const c=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:e});if(!c)return;const g=this._sheetDrawingService.getBatchRemoveOp([c]),{redo:u,objects:d}=g;this._commandService.syncExecuteCommand(v.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:u,objects:d,type:v.DrawingApplyType.REMOVE})}}addFloatDomToRange(e,t,n,o){var y,N,O;const a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:c}=a,g=this._getSceneAndTransformerByDrawingSearch(s);if(!g)return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(y=this._renderManagerService.getRenderById(s))==null?void 0:y.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(c);if(!d)return;const{componentKey:m,data:h,allowTransform:p=!0}=t,f=o!=null?o:l.generateRandomId(),{position:S,position$:w}=this._createRangePositionObserver(e,u,d.skeleton);if(this._getPosition(S,s)==null)return;const C=g.scene,{scaleX:M}=C.getAncestorScale(),I=qe(S,n,M),T={unitId:s,subUnitId:c,drawingId:f,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:h,allowTransform:p};{const{unitId:k,subUnitId:W,drawingId:P}=T,E=D.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 re=(N=this._renderManagerService.getRenderById(k))==null?void 0:N.with(b.SheetSkeletonManagerService);if(!re)return;const K=re.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:Et,flipX:bt,flipY:it,skewX:ot,skewY:De}=Z,at=B.getDrawingShapeKeyByDrawingSearch({unitId:k,subUnitId:W,drawingId:P}),ce=X.getObject(at);if(ce!=null){ce.transformByState({left:et,top:tt,width:nt,height:rt,angle:Et,flipX:bt,flipY:it,skewX:ot,skewY:De});return}const ie={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";ie.fill=L,ie.rotateEnabled=!1,z&&z.border&&(ie.stroke=z.border),ie.paintFirst="stroke",ie.strokeWidth=1,ie.borderEnabled=!1,ie.radius=8}const de=new A.Rect(at,ie);Te&&de.setObjectType(A.ObjectType.CHART),X.addObject(de,A.DRAWING_OBJECT_LAYER_INDEX),$.allowTransform!==!1&&X.attachTransformerTo(de);const le=new l.DisposableCollection,st=X.getMainViewport(),{rowHeaderWidth:Me,columnHeaderHeight:We}=K.skeleton,ct={top:We,left:Me,bottom:st.bottom,right:st.right},ue={dispose:le,rect:de,boundsOfViewArea:ct,domAnchor:n,unitId:k,subUnitId:W},x=se(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(w.subscribe(L=>{var Ht,Vt,Xt,xt;const Gt=qe({startX:L.startX,startY:L.startY,endX:L.endX,endY:L.endY,width:(Ht=n.width)!=null?Ht:L.width,height:(Vt=n.height)!=null?Vt:L.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),er=B.getDrawingShapeKeyByDrawingSearch({unitId:k,subUnitId:W,drawingId:P}),tr=new A.Rect(er,{left:Gt.startX,top:Gt.startY,width:(Xt=n.width)!=null?Xt:L.width,height:(xt=n.height)!=null?xt:L.height,zIndex:this._drawingManagerService.getDrawingOrder(k,W).length-1}),nr=se(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(f,!0)});const dt=de.onTransformChange$.subscribeEvent(()=>{const L=se(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:f,dispose:()=>{this._removeDom(f,!0)}}}addFloatDomToColumnHeader(e,t,n,o){var I,T,y;const a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:c}=a;if(!this._getSceneAndTransformerByDrawingSearch(s))return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(I=this._renderManagerService.getRenderById(s))==null?void 0:I.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(c);if(!d)return;const{componentKey:m,data:h,allowTransform:p=!0}=t,f=o!=null?o:l.generateRandomId(),{position:S,position$:w}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:e,endColumn:e},u,d.skeleton),_=S;if(_.startY=0,this._getPosition(S,s)==null)return;const M={unitId:s,subUnitId:c,drawingId:f,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=D.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:re,data:K}=P,Z=this._getSceneAndTransformerByDrawingSearch(N);if(Z==null)return;const{scene:oe,canvas:z}=Z;if(re==null||$!==O)return;const{left:ee,top:X,width:Ce,height:et,angle:tt,flipX:nt,flipY:rt,skewX:Et,skewY:bt}=re,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:Et,skewY:bt});return}const De=qe({startX:_.startX,startY:0,endX:S.endX,endY:S.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),at={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,at);oe.addObject(ce,A.DRAWING_OBJECT_LAYER_INDEX),P.allowTransform!==!1&&oe.attachTransformerTo(ce);const ie=new l.DisposableCollection,Te=oe.getMainViewport(),de={top:0,left:Te.left,bottom:Te.bottom,right:Te.right},le={dispose:ie,rect:ce,unitId:N,subUnitId:O,boundsOfViewArea:de,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},st=se(ce,Z.renderUnit.scene,Q.skeleton,W.worksheet,le),Me=new U.BehaviorSubject(st);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=se(ce,Z.renderUnit.scene,Q.skeleton,W.worksheet,le);Me.next(x)});this.disposeWithMe(w.subscribe(x=>{const Re=qe({startX:x.startX,startY:0,endX:x.endX,endY:x.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.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=se(je,Z.renderUnit.scene,Q.skeleton,W.worksheet,le);Me.next(dt)}));const ue=(y=this._renderManagerService.getRenderById(N))==null?void 0:y.with(b.SheetSkeletonManagerService);ue==null||ue.currentSkeleton$.subscribe(x=>{x&&d.sheetId!==x.sheetId&&this._removeDom(f,!0)}),ie.add(()=>{this._canvasFloatDomService.removeFloatDom(k)}),ct&&ie.add(ct),this._domLayerInfoMap.set(k,le)}return{id:f,dispose:()=>{this._removeDom(f,!0)}}}_createRangePositionObserver(e,t,n){let{startRow:o,startColumn:a}=e;const s=Ne(o,a,n),c=new U.BehaviorSubject(s),g=Ne(e.endRow,e.endColumn,n),u=new U.BehaviorSubject(g),d=()=>{const w=Ne(o,a,n),_=Ne(e.endRow,e.endColumn,n);c.next(w),u.next(_)},m=new l.DisposableCollection;m.add(t.engine.clientRect$.subscribe(()=>d())),m.add(this._commandService.onCommandExecuted(w=>{if(w.id===D.SetWorksheetRowAutoHeightMutation.id&&w.params.rowsAutoHeightInfo.findIndex(C=>C.row===o)>-1){d();return}(D.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(w.id)>-1||w.id===b.SetScrollOperation.id||w.id===b.SetZoomRatioOperation.id)&&d()}));const h=(w,_)=>{o=w,a=_,d()},p=()=>({rotate:0,width:g.right-s.left,height:g.bottom-s.top,absolute:{left:!0,top:!0},startX:s.left,startY:s.top,endX:g.right,endY:g.bottom}),f=c.pipe(U.map(w=>{const _=Ne(e.endRow,e.endColumn,n);return{rotate:0,width:_.right-w.left,height:_.bottom-w.top,absolute:{left:!0,top:!0},startX:w.left,startY:w.top,endX:_.right,endY:_.bottom}})),S=p();return{position$:f,position:S,updateRowCol:h,topLeftPos$:c,rightBottomPos$:u,disposable:m}}},R.SheetCanvasFloatDomManagerService=Tn([pe(0,l.Inject(A.IRenderManagerService)),pe(1,l.IUniverInstanceService),pe(2,l.Inject(l.ICommandService)),pe(3,B.IDrawingManagerService),pe(4,l.Inject(j.CanvasFloatDomService)),pe(5,v.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,a=(u=r==null?void 0:r.height)!=null?u:n;let s=0,c=0;if(r){if(r.horizonOffsetAlign==="right"){const d=Ze(r.marginX,t*e);s=i.endX-d-o}else s=i.startX+Ze(r.marginX,t);if(r.verticalOffsetAlign==="bottom"){const d=Ze(r.marginY,n*e);c=i.endY-d-a}else c=i.startY+Ze(r.marginY,n)}return{rotate:0,startX:s,startY:c,endX:i.endX,endY:i.endY,width:o,height:a,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 Mn=i=>{const{floatDomInfos:r,scene:e,skeleton:t,worksheet:n}=i,o=q.useMemo(()=>r.map(a=>{const{width:s,height:c,angle:g,left:u,top:d}=a.transform,m=Ft({left:u!=null?u:0,right:(u!=null?u:0)+(s!=null?s:0),top:d!=null?d:0,bottom:(d!=null?d:0)+(c!=null?c:0)},e,t,n,void 0,!0),{scaleX:h,scaleY:p}=e.getAncestorScale(),f={startX:m.left,endX:m.right,startY:m.top,endY:m.bottom,rotate:g,width:s*h,height:c*p,absolute:m.absolute},S={position$:new U.BehaviorSubject(f),position:f,id:a.drawingId,componentKey:a.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:a.unitId,data:a.data};return[a.drawingId,S]}),[r,e,t,n]);return F.jsx("div",{style:{position:"absolute",top:0,left:0},children:o.map(([a,s])=>F.jsx(j.PrintFloatDomSingle,{layer:s,id:a,position:s.position},a))})};var Rn=Object.getOwnPropertyDescriptor,En=(i,r,e,t)=>{for(var n=t>1?void 0:t?Rn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(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,a){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=e,this._renderManagerService=t,this._canvasFloatDomManagerService=n,this._componetManager=o,this._injector=a,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,a=this._drawingManagerService.getDrawingDataForUnit(t),s=a==null?void 0:a[o];return s&&s.order.forEach(c=>{const g=s.data[c];g.drawingType!==l.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),e()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,e)=>{const{unitId:t,subUnitId:n}=r,o=this._renderManagerService.getRenderById(t);if(!o)return e(i);const a=o.with(b.SheetSkeletonManagerService).getSkeletonParam(n);if(!a)return e(i);const s=this._drawingManagerService.getDrawingDataForUnit(t),c=s==null?void 0:s[r.subUnitId];if(!c)return e(i);const{scaleX:g,scaleY:u}=o.scene,d=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=c.order.map(h=>c.data[h]);return m.length?(m.forEach(h=>{if(!h.groupId&&h.transform&&l.Tools.isDefine(h.transform.left)&&l.Tools.isDefine(h.transform.top)&&l.Tools.isDefine(h.transform.width)&&l.Tools.isDefine(h.transform.height)){const p=a.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),f=a.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});p.column<d.startColumn&&(d.startColumn=p.column),p.row<d.startRow&&(d.startRow=p.row),d.endRow<f.row&&(d.endRow=f.row),d.endColumn<f.column&&(d.endColumn=f.column)}}),e(d)):e(i)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(i,r,e)=>{const{unitId:t,subUnitId:n}=r,o=this._drawingManagerService.getDrawingDataForUnit(t),a=o==null?void 0:o[n];if(a){const s=a.order.map(g=>{const u=a.data[g];if(u.drawingType===l.DrawingTypeEnum.DRAWING_CHART)return{...u,componentKey:this._componetManager.get(l.PRINT_CHART_COMPONENT_KEY)};if(u.drawingType===l.DrawingTypeEnum.DRAWING_DOM){const d=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(d||u.componentKey)}}return null}).filter(Boolean),c=j.connectInjector(Mn,this._injector);return Y.render(F.jsx(c,{floatDomInfos:s,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),i==null||i.add(()=>{Y.unmount(r.root)}),e(i)}}}))}};Je=En([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 bn=Object.getOwnPropertyDescriptor,On=(i,r,e,t)=>{for(var n=t>1?void 0:t?bn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},me=(i,r)=>(e,t)=>r(e,t,i);const An=[D.InsertRowCommand.id,D.InsertColCommand.id,D.RemoveRowCommand.id,D.RemoveColCommand.id,D.DeleteRangeMoveLeftCommand.id,D.DeleteRangeMoveUpCommand.id,D.InsertRangeMoveDownCommand.id,D.InsertRangeMoveRightCommand.id,D.DeltaRowHeightCommand.id,D.SetRowHeightCommand.id,D.DeltaColumnWidthCommand.id,D.SetColWidthCommand.id,D.SetRowHiddenCommand.id,D.SetSpecificRowsVisibleCommand.id,D.SetSpecificColsVisibleCommand.id,D.SetColHiddenCommand.id,D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id],Un=[D.SetRowVisibleMutation.id,D.SetRowHiddenMutation.id,D.SetColVisibleMutation.id,D.SetColHiddenMutation.id,D.SetWorksheetRowHeightMutation.id,D.SetWorksheetRowAutoHeightMutation.id,D.SetWorksheetRowIsAutoHeightMutation.id,D.SetWorksheetColWidthMutation.id];let Dt=class extends l.Disposable{constructor(i,r,e,t,n,o,a,s,c){super(),this._context=i,this._renderManagerService=r,this._commandService=e,this._selectionRenderService=t,this._skeletonManagerService=n,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._univerInstanceService=c,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptAfterCommand({getMutations:i=>{if(!An.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===D.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===D.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===D.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===D.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===D.DeleteRangeMoveLeftCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,0)}else if(r===D.DeleteRangeMoveUpCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,1)}else if(r===D.InsertRangeMoveDownCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,2)}else if(r===D.InsertRangeMoveRightCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,3)}else if(r===D.SetRowHiddenCommand.id||r===D.SetSpecificRowsVisibleCommand.id){const e=i.params,{unitId:t,subUnitId:n,ranges:o}=e;return this._getDrawingUndoForRowVisible(t,n,o)}else if(r===D.SetSpecificColsVisibleCommand.id||r===D.SetColHiddenCommand.id){const e=i.params,{unitId:t,subUnitId:n,ranges:o}=e;return this._getDrawingUndoForColVisible(t,n,o)}else if(r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id||r===D.DeltaColumnWidthCommand.id||r===D.SetColWidthCommand.id){const e=i.params,{unitId:t,subUnitId:n,ranges:o}=e,a=r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(t,n,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const e=D.getSheetCommandTarget(this._univerInstanceService);if(e==null)return{redos:[],undos:[]};const t=e.unitId,n=e.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(t,n),c=[],g=[];if(Object.keys(s).forEach(u=>{const d=s[u],{updateDrawings:m,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,d);c.push(...m),g.push(...h)}),c.length===0&&g.length===0)return{redos:[],undos:[]};if(c.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(c),{undo:d,redo:m,objects:h}=u;o.push({id:v.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:m,objects:h,type:v.DrawingApplyType.UPDATE}}),a.push({id:v.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:d,objects:h,type:v.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),d=u.undo,m=u.redo,h=u.objects;o.push({id:v.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:m,objects:h,type:v.DrawingApplyType.REMOVE}}),a.push({id:v.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:d,objects:h,type:v.DrawingApplyType.INSERT}})}return o.push({id:V.id,params:[t]}),a.push({id:V.id,params:[t]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,r,e){const t=[],n=[],{sheetTransform:o,anchorType:a=v.SheetDrawingAnchorType.Position,transform:s,unitId:c,subUnitId:g,drawingId:u}=e,{from:d,to:m}=o,{row:h,column:p}=d,{row:f,column:S}=m;if(o==null||s==null)return{updateDrawings:t,deleteDrawings:n};const{startRow:w,endRow:_,startColumn:C,endColumn:M}=i;let I=null,T=null;if(r===0&&h>=w&&f<=_)if(p>=C&&S<=M)n.push({unitId:c,subUnitId:g,drawingId:u});else{const y=this._shrinkCol(o,s,C,M,a);I=y==null?void 0:y.newSheetTransform,T=y==null?void 0:y.newTransform}else if(r===1&&p>=C&&S<=M)if(h>=w&&f<=_)n.push({unitId:c,subUnitId:g,drawingId:u});else{const y=this._shrinkRow(o,s,w,_,a);I=y==null?void 0:y.newSheetTransform,T=y==null?void 0:y.newTransform}else if(r===2){const y=this._expandRow(o,s,w,_,a);I=y==null?void 0:y.newSheetTransform,T=y==null?void 0:y.newTransform}else if(r===3){const y=this._expandCol(o,s,C,M,a);I=y==null?void 0:y.newSheetTransform,T=y==null?void 0:y.newTransform}if(I!=null&&T!=null){const y=J(I,this._selectionRenderService,this._skeletonManagerService);t.push({...e,sheetTransform:I,transform:y})}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 d=t[u],{sheetTransform:m,transform:h,anchorType:p=v.SheetDrawingAnchorType.Position}=d;if(p===v.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:f,to:S}=m,{row:w,column:_}=f,{row:C,column:M}=S;for(let I=0;I<e.length;I++){const T=e[I],{startRow:y,endRow:N,startColumn:O,endColumn:k}=T;if(M<O)continue;if(p===v.SheetDrawingAnchorType.Position){let E=null,$=null;if(_>=O&&_<=k){const G=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:k,startRow:f.row,endRow:S.row});if(G==null)return;$={...h,left:G.startX}}if($!=null&&(E=H($,this._selectionRenderService),E!=null&&$!=null)){n.push({...d,sheetTransform:E,transform:$});break}this._remainDrawingSize(h,n,d);continue}if(_>=O&&M<=k)continue;let W=null,P=null;if(_>=O&&_<=k){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:k,startRow:f.row,endRow:S.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:f.row,endRow:S.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:f.row,endRow:S.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({...d,sheetTransform:W,transform:P});break}}if(P!=null&&(W=H(P,this._selectionRenderService)),P!=null&&W!=null){n.push({...d,sheetTransform:W,transform:P});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),c=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);c.push(...u),g.push(...d)}return{redos:a,undos:s,preRedos:c,preUndos:g}}_createUndoAndRedoMutation(i,r,e){const t=this._sheetDrawingService.getBatchUpdateOp(e),{undo:n,redo:o,objects:a}=t,s=[{id:v.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:v.DrawingApplyType.UPDATE}},{id:V.id,params:[i]}],c=[{id:v.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:a,type:v.DrawingApplyType.UPDATE}},{id:V.id,params:[i]}];return{redos:s,undos:c}}_getDrawingUndoForRowVisible(i,r,e){const t=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(t).forEach(u=>{const d=t[u],{sheetTransform:m,transform:h,anchorType:p=v.SheetDrawingAnchorType.Position}=d;if(p===v.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:f,to:S}=m,{row:w,column:_}=f,{row:C,column:M}=S;for(let I=0;I<e.length;I++){const T=e[I],{startRow:y,endRow:N,startColumn:O,endColumn:k}=T;if(C<y)continue;if(p===v.SheetDrawingAnchorType.Position){let E=null,$=null;if(w>=y&&w<=N){const G=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:w,endRow:N});if(G==null)return;$={...h,top:G.startY}}if($!=null&&(E=H($,this._selectionRenderService),E!=null&&$!=null)){n.push({...d,sheetTransform:E,transform:$});break}this._remainDrawingSize(h,n,d);continue}if(w>=y&&C<=N)continue;let W=null,P=null;if(w>=y&&w<=N){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:w,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(C>=y&&C<=N){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:y,endRow:C});if(E==null)return;P={...h,top:E.startY-((h==null?void 0:h.height)||0)}}else{const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:y,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({...d,sheetTransform:W,transform:P});break}}if(P!=null&&(W=H(P,this._selectionRenderService)),P!=null&&W!=null){n.push({...d,sheetTransform:W,transform:P});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),c=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);c.push(...u),g.push(...d)}return{redos:a,undos:s,preRedos:c,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,e,t){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(a=>{const s=n[a],{sheetTransform:c,transform:g,anchorType:u=v.SheetDrawingAnchorType.Position}=s;if(u===v.SheetDrawingAnchorType.None)this._remainDrawingSize(g,o,s);else{const{from:d,to:m}=c,{row:h,column:p}=d,{row:f,column:S}=m;for(let w=0;w<e.length;w++){const _=e[w],{startRow:C,endRow:M,startColumn:I,endColumn:T}=_;if(f<C||S<I)continue;if(u===v.SheetDrawingAnchorType.Position&&(h<=C&&f>=M||p<=I&&S>=T)){this._remainDrawingSize(g,o,s);continue}const y=J({...c},this._selectionRenderService,this._skeletonManagerService);if(y!=null){o.push({...s,transform:y});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=D.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;e=n.unitId,t=n.subUnitId}return{unitId:e,subUnitId:t}}_moveRangeInterceptor(i){var C,M;const{toRange:r,fromRange:e}=i,t=D.getSheetCommandTarget(this._univerInstanceService);if(!t)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=t,a=(M=(C=this._renderManagerService.getRenderById(n))==null?void 0:C.with(b.SheetSkeletonManagerService))==null?void 0:M.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=b.attachRangeWithCoord(a,e);if(!s)return{redos:[],undos:[]};const{startX:c,endX:g,startY:u,endY:d}=s,m=this._sheetDrawingService.getDrawingData(n,o),h=[];Object.keys(m).forEach(I=>{const T=m[I];if(T.anchorType!==v.SheetDrawingAnchorType.Both)return;const{transform:y}=T;if(!y)return;const{left:N=0,top:O=0,width:k=0,height:W=0}=y,{drawingStartX:P,drawingEndX:E,drawingStartY:$,drawingEndY:G}={drawingStartX:N,drawingEndX:N+k,drawingStartY:O,drawingEndY:O+W};c<=P&&E<=g&&u<=$&&G<=d&&h.push(T)});const p=[],f=[],S=r.startRow-e.startRow,w=r.startColumn-e.startColumn,_=h.map(I=>{const T=I.sheetTransform,y={to:{...T.to,row:T.to.row+S,column:T.to.column+w},from:{...T.from,row:T.from.row+S,column:T.from.column+w}},N=J(y,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:I.drawingId,transform:N,sheetTransform:y}});if(_.length){const I=this._sheetDrawingService.getBatchUpdateOp(_),{undo:T,redo:y,objects:N}=I;p.push({id:v.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:y,objects:N,type:v.DrawingApplyType.UPDATE}}),f.push({id:v.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:T,objects:N,type:v.DrawingApplyType.UPDATE}})}return{redos:p,undos:f}}_moveRowInterceptor(i,r){const e=this._getUnitIdAndSubUnitId(i,r);if(e==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=e,{range:o}=i,a=o.startRow,s=o.endRow,c=[],g=[],u=this._sheetDrawingService.getDrawingData(t,n),d=[],m=[];if(Object.keys(u).forEach(h=>{const p=u[h],{sheetTransform:f,transform:S,anchorType:w=v.SheetDrawingAnchorType.Position}=p;if(f==null||S==null)return;let _,C;if(r==="insert"){const I=this._expandRow(f,S,a,s,w);_=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:T}=f,{row:y}=I,{row:N}=T;if(w===v.SheetDrawingAnchorType.Both&&y>=a&&N<=s)m.push({unitId:t,subUnitId:n,drawingId:h});else{const O=this._shrinkRow(f,S,a,s,w);_=O==null?void 0:O.newSheetTransform,C=O==null?void 0:O.newTransform}}if(!_||!C)return;const M={unitId:t,subUnitId:n,drawingId:h,transform:C,sheetTransform:_};d.push(M)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:p,redo:f,objects:S}=h;c.push({id:v.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:S,type:v.DrawingApplyType.UPDATE}}),g.push({id:v.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:S,type:v.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),p=h.undo,f=h.redo,S=h.objects;c.push({id:v.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:S,type:v.DrawingApplyType.REMOVE}}),g.push({id:v.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:S,type:v.DrawingApplyType.INSERT}})}return c.push({id:V.id,params:[t]}),g.push({id:V.id,params:[t]}),{redos:c,undos:g}}_moveColInterceptor(i,r){const e=this._getUnitIdAndSubUnitId(i,r);if(e==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=e,{range:o}=i,a=o.startColumn,s=o.endColumn,c=[],g=[],u=this._sheetDrawingService.getDrawingData(t,n),d=[],m=[];if(Object.keys(u).forEach(h=>{const p=u[h],{sheetTransform:f,transform:S,anchorType:w=v.SheetDrawingAnchorType.Position}=p;if(f==null||S==null)return;let _,C;if(r==="insert"){const I=this._expandCol(f,S,a,s,w);_=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:T}=f,{column:y}=I,{column:N}=T;if(w===v.SheetDrawingAnchorType.Both&&y>=a&&N<=s)m.push({unitId:t,subUnitId:n,drawingId:h});else{const O=this._shrinkCol(f,S,a,s,w);_=O==null?void 0:O.newSheetTransform,C=O==null?void 0:O.newTransform}}if(!_||!C)return;const M={unitId:t,subUnitId:n,drawingId:h,transform:C,sheetTransform:_};d.push(M)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:p,redo:f,objects:S}=h;c.push({id:v.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:S,type:v.DrawingApplyType.UPDATE}}),g.push({id:v.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:S,type:v.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),p=h.undo,f=h.redo,S=h.objects;c.push({id:v.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:S,type:v.DrawingApplyType.REMOVE}}),g.push({id:v.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:S,type:v.DrawingApplyType.INSERT}})}return c.push({id:V.id,params:[t]}),g.push({id:V.id,params:[t]}),{redos:c,undos:g}}_expandCol(i,r,e,t,n=v.SheetDrawingAnchorType.Position){const o=t-e+1,{from:a,to:s}=i,{column:c}=a,{column:g}=s;if(n===v.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(c>=e){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:e,endColumn:t,startRow:a.row,endRow:s.row});if(m==null)return;d={...r,left:(r.left||0)+m.endX-m.startX},u=H(d,this._selectionRenderService)}else if(g>=t)if(n===v.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:g+o}},d=J(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkCol(i,r,e,t,n=v.SheetDrawingAnchorType.Position){const o=t-e+1,{from:a,to:s}=i,{column:c}=a,{column:g}=s;if(n===v.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(c>t)u={from:{...a,column:c-o},to:{...s,column:g-o}},d=J(u,this._selectionRenderService,this._skeletonManagerService);else{if(c>=e&&g<=t)return null;if(c<e&&g>t)if(n===v.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:g-o}},d=J(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(c>=e&&c<=t){if(c===e)d={...r,left:(r.left||0)-i.from.columnOffset};else{const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:e,endColumn:c-1,startRow:a.row,endRow:s.row});if(m==null)return;d={...r,left:(r.left||0)-m.endX+m.startX-i.from.columnOffset}}u=H(d,this._selectionRenderService)}else if(g>=e&&g<=t&&n===v.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:e-1,endColumn:e-1,startRow:a.row,endRow:s.row});if(m==null)return;u={from:{...a},to:{...s,column:e-1,columnOffset:m.endX-m.startX}},d=J(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_expandRow(i,r,e,t,n=v.SheetDrawingAnchorType.Position){const o=t-e+1,{from:a,to:s}=i,{row:c}=a,{row:g}=s;if(n===v.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(c>=e){const m=this._skeletonManagerService.attachRangeWithCoord({startRow:e,endRow:t,startColumn:a.column,endColumn:s.column});if(m==null)return;d={...r,top:(r.top||0)+m.endY-m.startY},u=H(d,this._selectionRenderService)}else if(g>=t)if(n===v.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:g+o}},d=J(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkRow(i,r,e,t,n=v.SheetDrawingAnchorType.Position){const o=t-e+1,{from:a,to:s}=i,{row:c}=a,{row:g}=s;if(n===v.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(c>t)u={from:{...a,row:c-o},to:{...s,row:g-o}},d=J(u,this._selectionRenderService,this._skeletonManagerService);else{if(c>=e&&g<=t)return null;if(c<e&&g>t)if(n===v.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:g-o}},d=J(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(c>=e&&c<=t){if(c===e)d={...r,top:(r.top||0)-i.from.rowOffset};else{const m=this._skeletonManagerService.attachRangeWithCoord({startRow:e,endRow:c-1,startColumn:a.column,endColumn:s.column});if(m==null)return;d={...r,top:(r.top||0)-m.endY+m.startY-i.from.rowOffset}}u=H(d,this._selectionRenderService)}else if(g>=e&&g<=t&&n===v.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:e-1,endRow:e-1});if(m==null)return;u={from:{...a},to:{...s,row:e-1,rowOffset:m.endY-m.startY}},d=J(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===D.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 a=n[o].data;a!=null&&Object.keys(a).forEach(s=>{t===i&&e.push(a[s])})})}),this._drawingManagerService.removeNotification(e)})}_updateDrawings(i,r){setTimeout(()=>{const e=this._drawingManagerService.drawingManagerData,t=[],n=[];Object.keys(e).forEach(o=>{const a=e[o];a!=null&&Object.keys(a).forEach(s=>{const c=a[s].data;c!=null&&Object.keys(c).forEach(g=>{if(o===i&&s===r){const u=c[g];u.transform=J(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),t.push(c[g])}else n.push(c[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(t)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Un.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,e=D.getSheetCommandTarget(this._univerInstanceService,r);if(!e)return;const{unitId:t,subUnitId:n,worksheet:o}=e;let a=[];"range"in r?a=r.range:"rowsAutoHeightInfo"in r&&(a=r.rowsAutoHeightInfo.map(s=>({startRow:s.row,endRow:s.row,startColumn:0,endColumn:o.getColumnCount()-1}))),this._refreshDrawingTransform(t,n,a)})}))}_refreshDrawingTransform(i,r,e){const t=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(t).forEach(o=>{const a=t[o],{sheetTransform:s,transform:c,anchorType:g=v.SheetDrawingAnchorType.Position}=a;if(g===v.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=s,{row:m,column:h}=u,{row:p,column:f}=d;for(let S=0;S<e.length;S++){const w=e[S],{startRow:_,endRow:C,startColumn:M,endColumn:I}=w;if(l.Rectangle.intersects({startRow:_,endRow:C,startColumn:M,endColumn:I},{startRow:m,endRow:p,startColumn:h,endColumn:f})||m>C||h>I){const T=g===v.SheetDrawingAnchorType.Position,y=J(s,this._selectionRenderService,this._skeletonManagerService);n.push({...a,transform:{...y,width:T?c==null?void 0:c.width:y==null?void 0:y.width,height:T?c==null?void 0:c.height:y==null?void 0:y.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(V.id,[i]))}};Dt=On([me(1,A.IRenderManagerService),me(2,l.ICommandService),me(3,b.ISheetSelectionRenderService),me(4,l.Inject(b.SheetSkeletonManagerService)),me(5,l.Inject(D.SheetInterceptorService)),me(6,v.ISheetDrawingService),me(7,B.IDrawingManagerService),me(8,l.IUniverInstanceService)],Dt);function Pn(){const i=j.useDependency(l.LocaleService),r=j.useDependency(j.IDialogService),e=j.useDependency(Fe),[t,n]=q.useState([he.CELL_ADDRESS]),[o,a]=q.useState(!1),[s,c]=q.useState(null),g=q.useMemo(()=>e.getCellImagesInSelection(),[e]),u=q.useMemo(()=>e.getDataColumns(),[e]),d=q.useMemo(()=>e.getSelectionRowRange(),[e]),m=u.length>0,h=q.useMemo(()=>u.map(T=>({label:T.label,value:String(T.index)})),[u]),[p,f]=q.useState(()=>h.length>0?h[0].value:"0"),S=q.useMemo(()=>{if(!t.includes(he.COLUMN_VALUE)||!d)return[];const y=Number(p);return[{startRow:d.startRow,endRow:d.endRow,startColumn:y,endColumn:y}]},[t,p,d]);b.useHighlightRange(S);const w=q.useCallback(T=>{T.length!==0&&n(T)},[]),_=q.useCallback(T=>{f(String(T))},[]),C=q.useCallback(()=>{r.close(ve)},[r]),M=q.useCallback(async()=>{if(g.length!==0){a(!0),c(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),c(i.t("sheetImage.save.error"))}finally{a(!1)}}},[e,g,t,p,r,i]),I=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:w,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")})]})}),I&&F.jsx(Y.FormLayout,{label:i.t("sheetImage.save.selectColumn"),children:F.jsx(Y.Select,{value:p,options:h,onChange:_})}),s&&F.jsx("div",{className:"univer-text-xs univer-text-red-500",children:s}),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:C,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 Lt=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,a=o[0];if(a==null)return;const{unitId:s}=a,c=n.getRenderById(s),g=c==null?void 0:c.scene;if(g==null)return;const u=g.getTransformerByCreate(),[d,m]=q.useState(!0),h=(_=a.anchorType)!=null?_:v.SheetDrawingAnchorType.Position,[p,f]=q.useState(h);function S(C,M){const I=[];return C.forEach(T=>{const{oKey:y}=T,N=M.getDrawingOKey(y);if(N==null)return I.push(null),!0;const{unitId:O,subUnitId:k,drawingId:W,drawingType:P,anchorType:E,sheetTransform:$}=N;I.push({unitId:O,subUnitId:k,drawingId:W,anchorType:E,sheetTransform:$,drawingType:P})}),I}q.useEffect(()=>{const C=u.clearControl$.subscribe(I=>{I===!0&&m(!1)}),M=u.changeStart$.subscribe(I=>{var N;const{objects:T}=I,y=S(T,t);if(y.length===0)m(!1);else if(y.length>=1){m(!0);const O=((N=y[0])==null?void 0:N.anchorType)||v.SheetDrawingAnchorType.Position;f(O)}});return()=>{M.unsubscribe(),C.unsubscribe()}},[]);function w(C){f(C);const M=t.getFocusDrawings();if(M.length===0)return;const I=M.map(T=>({unitId:T.unitId,subUnitId:T.subUnitId,drawingId:T.drawingId,anchorType:C}));r.executeCommand(be.id,{unitId:M[0].unitId,drawings:I})}return F.jsxs("div",{className:Y.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!d}),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:w,direction:"vertical",children:[F.jsx(Y.Radio,{value:v.SheetDrawingAnchorType.Both,children:e.t("drawing-anchor.both")}),F.jsx(Y.Radio,{value:v.SheetDrawingAnchorType.Position,children:e.t("drawing-anchor.position")}),F.jsx(Y.Radio,{value:v.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(Lt,{drawings:e})]})},Tt="sheet.menu.image";function kn(i){return{id:Tt,type:j.MenuItemType.SUBITEMS,icon:"AddImageIcon",tooltip:"sheetImage.title",hidden$:j.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),disabled$:b.getCurrentRangeDisable$(i,{workbookTypes:[D.WorkbookEditablePermission],worksheetTypes:[D.WorksheetEditPermission],rangeTypes:[D.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:a,endColumn:s}=r;for(let c=n;c<=o;c++)for(let g=a;g<=s;g++){const u=t.getValue(c,g);if(jn(u))return!0}return!1}function Fn(){return"showDirectoryPicker"in window}function Mt(i){const r=i.get(l.IUniverInstanceService),e=i.get(D.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 a of o)if($n(n,a.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]:{[Tt]:{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:Mt}}},[j.ContextMenuPosition.COL_HEADER]:{[j.ContextMenuGroup.OTHERS]:{[_e.id]:{order:10,menuItemFactory:Mt}}},[j.ContextMenuPosition.ROW_HEADER]:{[j.ContextMenuGroup.OTHERS]:{[_e.id]:{order:10,menuItemFactory:Mt}}}};function ke(i){return i.getContextValue(l.FOCUSING_SHEET)&&!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,a;o>=0;o--)(a=i[o])&&(n=a(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,Pn))}_initMenus(){this._menuManagerService.mergeMenu(Ln)}_initCommands(){[Oe,pt,Ee,Se,be,_t,V,It,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(D.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,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Rt=(i,r)=>(e,t)=>r(e,t,i),Yt=(i,r,e)=>Zn(i,typeof r!="symbol"?r+"":r,e);const Qn="SHEET_IMAGE_UI_PLUGIN";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,...a}=l.merge({},Nt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(nn,a)}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],[Dt],[Ct],[yt]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}},Yt(R.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),Yt(R.UniverSheetsDrawingUIPlugin,"pluginName",Qn),R.UniverSheetsDrawingUIPlugin=Jn([l.DependentOn(B.UniverDrawingPlugin,Ot.UniverDocsDrawingPlugin,ge.UniverDrawingUIPlugin,v.UniverSheetsDrawingPlugin),Rt(1,l.Inject(l.Injector)),Rt(2,A.IRenderManagerService),Rt(3,l.IConfigService)],R.UniverSheetsDrawingUIPlugin),R.ClearSheetDrawingTransformerOperation=V,R.DeleteDrawingsCommand=lt,R.EditSheetDrawingOperation=It,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=Tt,R.SHEET_FLOAT_DOM_PREFIX=$t,R.SaveCellImagesCommand=_e,R.SetDrawingArrangeCommand=gt,R.SetSheetDrawingCommand=be,R.SheetDrawingAnchor=Lt,R.SidebarSheetDrawingOperation=_t,R.UngroupSheetDrawingCommand=ht,R.calcSheetFloatDomPosition=se,R.drawingPositionToTransform=J,R.transformToDrawingPosition=H,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(M,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("@univerjs/core"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets"),require("@univerjs/design"),require("@univerjs/docs-ui"),require("@univerjs/drawing"),require("@univerjs/ui"),require("@univerjs/docs-drawing"),require("@univerjs/drawing-ui"),require("rxjs"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/engine-render","@univerjs/sheets-ui","@univerjs/core","@univerjs/sheets-drawing","@univerjs/sheets","@univerjs/design","@univerjs/docs-ui","@univerjs/drawing","@univerjs/ui","@univerjs/docs-drawing","@univerjs/drawing-ui","rxjs","react/jsx-runtime","react"],A):(M=typeof globalThis<"u"?globalThis:M||self,A(M.UniverSheetsDrawingUi={},M.UniverEngineRender,M.UniverSheetsUi,M.UniverCore,M.UniverSheetsDrawing,M.UniverSheets,M.UniverDesign,M.UniverDocsUi,M.UniverDrawing,M.UniverUi,M.UniverDocsDrawing,M.UniverDrawingUi,M.rxjs,M.React,M.React))})(this,(function(M,A,b,l,w,y,Y,$e,B,j,bt,ge,U,F,q){"use strict";var rr=Object.defineProperty;var ir=(M,A,b)=>A in M?rr(M,A,{enumerable:!0,configurable:!0,writable:!0,value:b}):M[A]=b;var ie=(M,A,b)=>ir(M,typeof A!="symbol"?A+"":A,b);function J(i,r,e){const{from:t,to:n,flipY:o=!1,flipX:a=!1,angle:s=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:f}=c;const S=e.getCurrentSkeleton(),v=S.rowHeaderWidth+S.columnTotalWidth,_=S.columnHeaderHeight+S.rowTotalHeight;return m+p>v&&(m=v-p),h+f>_&&(h=_-f),{flipY:o,flipX:a,angle:s,skewX:d,skewY:g,left:m,top:h,width:p,height:f}}function H(i,r){const{left:e=0,top:t=0,width:n=0,height:o=0,flipY:a=!1,flipX:s=!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:a,flipX:s,angle:d,skewX:g,skewY:u,from:m,to:p}}const V={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(i,r)=>{const e=i.get(A.IRenderManagerService);return r.forEach(t=>{var n,o;(o=(n=e.getRenderById(t))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},fe={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var _,D,R;const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(y.SheetInterceptorService),o=i.get(w.ISheetDrawingService);if(!r)return!1;const{drawings:a}=r,s=[];a.forEach(C=>{const{unitId:T}=C;s.push(T)});const d=o.getBatchRemoveOp(a),{unitId:g,subUnitId:u,undo:c,redo:m,objects:h}=d,p=n.onCommandExecute({id:fe.id,params:r}),f={id:w.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:m,objects:h,type:w.DrawingApplyType.REMOVE}},S={id:w.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:c,objects:h,type:w.DrawingApplyType.INSERT}};return l.sequenceExecute([...(_=p.preRedos)!=null?_:[],f,...p.redos],e)?(t.pushUndoRedo({unitID:g,undoMutations:[...(D=p.preUndos)!=null?D:[],S,...p.undos,{id:V.id,params:s}],redoMutations:[...(R=p.preRedos)!=null?R:[],f,...p.redos,{id:V.id,params:s}]}),!0):!1}},ut={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),t=i.get(w.ISheetDrawingService).getFocusDrawings();if(t.length===0)return!1;const n=t[0].unitId,o=t.map(a=>{const{unitId:s,subUnitId:d,drawingId:g,drawingType:u}=a;return{unitId:s,subUnitId:d,drawingId:g,drawingType:u}});return r.executeCommand(fe.id,{unitId:n,drawings:o})}};function Kt(i){const r=[];return i.forEach(e=>{const{parent:t,children:n}=e,{unitId:o,subUnitId:a,drawingId:s}=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:f}=c;return{unitId:h,subUnitId:p,drawingId:f,transform:{...m,left:m.left-d.left,top:m.top-d.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,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:a,drawingId:s,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:f}=c,S=A.transformObjectOutOfGroup(m||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:p,drawingId:f,transform:S,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const gt={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:p})=>{o.push(h.unitId),p.forEach(f=>{o.push(f.unitId)})});const a=n.getGroupDrawingOp(r),{unitId:s,subUnitId:d,undo:g,redo:u,objects:c}=a;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:d,objects:c,type:w.DrawingApplyType.GROUP})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:d,objects:zt(c),type:w.DrawingApplyType.UNGROUP}},{id:V.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:s,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,R;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 a=r.drawings,s=a.map(C=>C.unitId),d=n.getBatchAddOp(a),{unitId:g,subUnitId:u,undo:c,redo:m,objects:h}=d,p=o.onCommandExecute({id:Ee.id,params:r}),f={id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:g,subUnitId:u,objects:h,type:w.DrawingApplyType.INSERT}},S={id:w.SetDrawingApplyMutation.id,params:{op:c,unitId:g,subUnitId:u,objects:h,type:w.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(_=p.preRedos)!=null?_:[],f,...p.redos],e)?(t.pushUndoRedo({unitID:g,undoMutations:[...(D=p.preUndos)!=null?D:[],S,...p.undos,{id:V.id,params:s}],redoMutations:[...(R=p.preRedos)!=null?R:[],f,...p.redos,{id:V.id,params:s}]}),!0):!1}},ht={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService);if(!r)return!1;const n=i.get(w.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:d}=r,g={unitId:o,subUnitId:a,drawingIds:s};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:a,objects:c,type:w.DrawingApplyType.ARRANGE})?(t.pushUndoRedo({unitID:o,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:c,type:w.DrawingApplyType.ARRANGE}}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:a,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,a=n.getBatchUpdateOp(o),{unitId:s,subUnitId:d,undo:g,redo:u,objects:c}=a;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:s,subUnitId:d,op:u,objects:c,type:w.DrawingApplyType.UPDATE})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:d,op:g,objects:c,type:w.DrawingApplyType.UPDATE}},{id:V.id,params:[s]}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:d,op:u,objects:c,type:w.DrawingApplyType.UPDATE}},{id:V.id,params:[s]}]}),!0):!1}},mt={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:p})=>{o.push(h.unitId),p.forEach(f=>{o.push(f.unitId)})});const a=n.getUngroupDrawingOp(r),{unitId:s,subUnitId:d,undo:g,redo:u,objects:c}=a;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:d,objects:c,type:w.DrawingApplyType.UNGROUP})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:d,objects:Kt(c),type:w.DrawingApplyType.GROUP}},{id:V.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:d,objects:c,type:w.DrawingApplyType.UNGROUP}},{id:V.id,params:o}]}),!0):!1}};var qt=Object.getOwnPropertyDescriptor,Zt=(i,r,e,t)=>{for(var n=t>1?void 0:t?qt(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},te=(i,r)=>(e,t)=>r(e,t,i);function Jt(i,r,e){const t=e*Math.PI/180,n=Math.abs(i*Math.cos(t))+Math.abs(r*Math.sin(t)),o=Math.abs(i*Math.sin(t))+Math.abs(r*Math.cos(t));return{rotatedWidth:n,rotatedHeight:o}}function pt(i,r,e,t,n){var _;const{rotatedHeight:o,rotatedWidth:a}=Jt(e,t,n),d=i.get(A.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const u=(_=d.with(b.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:_.skeleton;if(u==null)return!1;const c=u.getCellByIndex(r.row,r.col),m=c.mergeInfo.endX-c.mergeInfo.startX-2,h=c.mergeInfo.endY-c.mergeInfo.startY-2,p=a/o,S=Math.ceil(Math.min(m,h*p))/a,v=!S||Number.isNaN(S)?.001:S;return{width:e*v,height:t*v}}M.SheetDrawingUpdateController=class extends l.Disposable{constructor(e,t,n,o,a,s,d,g,u,c,m,h,p,f){super();ie(this,"_workbookSelections");this._context=e,this._skeletonManagerService=t,this._commandService=n,this._selectionRenderService=o,this._imageIoService=a,this._fileOpenerService=s,this._sheetDrawingService=d,this._drawingManagerService=g,this._contextService=u,this._messageService=c,this._localeService=m,this._injector=p,this._urlImageService=f,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const e=await this._fileOpenerService.openFile({multiple:!0,accept:B.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),t=e.length;return t>B.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(B.DRAWING_IMAGE_COUNT_LIMIT))}),!1):t===0?!1:(e.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const t=(await this._fileOpenerService.openFile({multiple:!1,accept:B.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return t?(await this._insertCellImage(t),!0):!1}insertCellImageByFile(e,t){return this._insertCellImage(e,t)}async insertFloatImageByFile(e){let t;try{t=await this._imageIoService.saveImage(e)}catch(D){const R=D.message;R===B.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(B.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):R===B.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):R===B.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Y.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(t==null)return;const n=this._getUnitInfo(),{unitId:o,subUnitId:a}=n,{imageId:s,imageSourceType:d,source:g,base64Cache:u}=t,{width:c,height:m,image:h}=await B.getImageSize(u||""),{width:p,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(g,d,h);let S=1;if(c>B.DRAWING_IMAGE_WIDTH_LIMIT||m>B.DRAWING_IMAGE_HEIGHT_LIMIT){const D=B.DRAWING_IMAGE_WIDTH_LIMIT/c,R=B.DRAWING_IMAGE_HEIGHT_LIMIT/m;S=Math.max(D,R)}const v=this._getImagePosition(c*S,m*S,p,f);if(v==null)return;const _={unitId:o,subUnitId:a,drawingId:s,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 R,C;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:a,source:s,base64Cache:d}=n,{width:g,height:u,image:c}=await B.getImageSize(d||"");this._imageIoService.addImageSourceCache(s,a,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 f=l.createDocumentModelWithStyle("",{}),S=pt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:h,col:p},g,u,0);if(!S)return!1;const v={size:{width:S.width,height:S.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},_={unitId:f.getUnitId(),subUnitId:f.getUnitId(),drawingId:o,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:s,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:f,drawings:[_],selection:{collapsed:!0,startOffset:0,endOffset:0}});return D?(f.apply(D),this._commandService.syncExecuteCommand(y.SetRangeValuesCommand.id,{value:{[(R=t==null?void 0:t.row)!=null?R:h]:{[(C=t==null?void 0:t.col)!=null?C:p]:{p:f.getSnapshot(),t:1}}},unitId:t==null?void 0:t.unitId,subUnitId:t==null?void 0:t.subUnitId})):!1}async insertCellImageByUrl(e,t){var p,f;let n=e;try{n=await this._urlImageService.getImage(e)}catch(S){console.error(`Failed to get image from URLImageService: ${e}`,S)}const{width:o,height:a,image:s}=await B.getImageSize(n||"");this._imageIoService.addImageSourceCache(e,l.ImageSourceType.URL,s);const d=this._workbookSelections.getCurrentLastSelection();if(!d)return!1;const g=l.createDocumentModelWithStyle("",{}),u=pt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:d.primary.actualRow,col:d.primary.actualColumn},o,a,0);if(!u)return!1;const c={size:{width:u.width,height:u.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},m={unitId:g.getUnitId(),subUnitId:g.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:e,transform:$e.docDrawingPositionToTransform(c),docTransform:c,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},h=l.BuildTextUtils.drawing.add({documentDataModel:g,drawings:[m],selection:{collapsed:!0,startOffset:0,endOffset:0}});return h?(g.apply(h),this._commandService.syncExecuteCommand(y.SetRangeValuesCommand.id,{value:{[(p=t==null?void 0:t.row)!=null?p:d.primary.actualRow]:{[(f=t==null?void 0:t.col)!=null?f:d.primary.actualColumn]:{p:g.getSnapshot(),t:1}}},unitId:t==null?void 0:t.unitId,subUnitId:t==null?void 0:t.subUnitId})):!1}_getUnitInfo(){const e=this._context.unit,t=e.getActiveSheet(),n=e.getUnitId(),o=t.getSheetId();return{unitId:n,subUnitId:o}}_getImagePosition(e,t,n,o){const a=this._workbookSelections.getCurrentSelections();let s={startRow:0,endRow:0,startColumn:0,endColumn:0};a&&a.length>0&&(s=a[a.length-1].range);const d=b.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);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},f=this._selectionRenderService.getCellWithCoordByOffset(c+e,m+t);if(f==null)return;const S={column:f.actualColumn,columnOffset:c+e-f.startX,row:f.actualRow,rowOffset:m+t-f.startY};return{from:p,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{const{unitId:t,subUnitId:n,drawingIds:o,arrangeType:a}=e;this._commandService.executeCommand(ht.id,{unitId:t,subUnitId:n,drawingIds:o,arrangeType:a})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{const t=[];e.length!==0&&(e.forEach(n=>{const{unitId:o,subUnitId:a,drawingId:s,drawingType:d,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:s});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(gt.id,e);const{unitId:t,subUnitId:n,drawingId:o}=e[0].parent;this._commandService.syncExecuteCommand(B.SetDrawingSelectedOperation.id,[{unitId:t,subUnitId:n,drawingId:o}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{this._commandService.executeCommand(mt.id,e)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}},M.SheetDrawingUpdateController=Zt([te(1,l.Inject(b.SheetSkeletonManagerService)),te(2,l.ICommandService),te(3,b.ISheetSelectionRenderService),te(4,B.IImageIoService),te(5,j.ILocalFileService),te(6,w.ISheetDrawingService),te(7,B.IDrawingManagerService),te(8,l.IContextService),te(9,j.IMessageService),te(10,l.Inject(l.LocaleService)),te(11,l.Inject(y.SheetsSelectionsService)),te(12,l.Inject(l.Injector)),te(13,l.IURLImageService)],M.SheetDrawingUpdateController);const Oe={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{var a,s;const e=i.get(l.IUniverInstanceService),t=i.get(A.IRenderManagerService),n=(a=A.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,e,t))==null?void 0:a.with(M.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const d=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(d)).every(g=>g)}else return(s=n.insertFloatImage())!=null?s:!1}},St={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:i=>{var t,n;const r=i.get(l.IUniverInstanceService),e=i.get(A.IRenderManagerService);return(n=(t=A.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,r,e))==null?void 0:t.with(M.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}},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,a=t.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,d=a.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:s,drawings:d})?(e.syncExecuteCommand(V.id,[s]),!0):!1}};var Qt=Object.getOwnPropertyDescriptor,en=(i,r,e,t)=>{for(var n=t>1?void 0:t?Qt(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Fe=(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 ft(i){let r="",e=i;for(;e>=0;)r=String.fromCharCode(e%26+65)+r,e=Math.floor(e/26)-1;return r}function Ye(i,r){return`${ft(r)}${i+1}`}function tn(i){const r=Ye(i.startRow,i.startColumn),e=Ye(i.endRow,i.endColumn);return r===e?r:`${r}:${e}`}function Ot(i){var r,e,t,n;return!!((e=(r=i==null?void 0:i.p)==null?void 0:r.drawingsOrder)!=null&&e.length&&((n=(t=i==null?void 0:i.p)==null?void 0:t.drawingsOrder)==null?void 0:n.length)>0)}function At(i){var t,n,o;if(!((n=(t=i.p)==null?void 0:t.drawingsOrder)!=null&&n.length)||!((o=i.p)!=null&&o.drawings))return null;const r=i.p.drawingsOrder[0],e=i.p.drawings[r];return!e||!("source"in e)||!("imageSourceType"in e)?null:e}function wt(i,r){if(r===l.ImageSourceType.BASE64){const e=i.match(/^data:image\/(\w+);/);if(e)return e[1]==="jpeg"?"jpg":e[1]}if(r===l.ImageSourceType.URL){const e=i.match(/\.(\w+)(?:\?|$)/);if(e)return e[1].toLowerCase()}return"png"}async function Ut(i,r){if(r===l.ImageSourceType.BASE64)return(await fetch(i)).blob();if(r===l.ImageSourceType.URL)return(await fetch(i)).blob();throw new Error("UUID image type requires additional handling")}M.BatchSaveImagesService=class extends l.Disposable{constructor(r,e,t,n){super(),this._univerInstanceService=r,this._selectionService=e,this._imageIoService=t,this._urlImageService=n}registerURLImageDownloader(r){return this._urlImageService.registerURLImageDownloader(r)}getCellImagesInSelection(){const r=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!r)return[];const e=r.getActiveSheet();if(!e)return[];const t=this._selectionService.getCurrentSelections();if(!t||t.length===0)return[];const n=e.getCellMatrix(),o=[];for(const a of t){const{startRow:s,endRow:d,startColumn:g,endColumn:u}=a.range;for(let c=s;c<=d;c++)for(let m=g;m<=u;m++){const h=n.getValue(c,m);if(Ot(h)){const p=At(h);p&&o.push({row:c,col:m,cellAddress:Ye(c,m),source:p.source,imageSourceType:p.imageSourceType,imageId:p.drawingId})}}}return o}getCellImagesFromRanges(r,e,t){const n=this._univerInstanceService.getUnit(r,l.UniverInstanceType.UNIVER_SHEET);if(!n)return[];const o=n.getSheetBySheetId(e);if(!o)return[];const a=o.getCellMatrix(),s=[];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 f=a.getValue(h,p);if(Ot(f)){const S=At(f);S&&s.push({row:h,col:p,cellAddress:Ye(h,p),source:S.source,imageSourceType:S.imageSourceType,imageId:S.drawingId})}}}return s}getDataColumns(){var m,h,p,f;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 a=1/0,s=-1/0;const d=new Set;for(const S of t){a=Math.min(a,S.range.startRow),s=Math.max(s,S.range.endRow);for(let v=S.range.startColumn;v<=S.range.endColumn;v++)d.add(v)}const g=new Set;for(let S=o.startColumn;S<=o.endColumn;S++)if(!d.has(S))for(let v=a;v<=s;v++){const _=n.getValue(v,S);if(_&&(((m=_.v)==null?void 0:m.toString())||((f=(p=(h=_.p)==null?void 0:h.body)==null?void 0:p.dataStream)==null?void 0:f.trim())||"")){g.add(S);break}}const u=[],c=Array.from(g).sort((S,v)=>S-v);for(const S of c)u.push({index:S,label:ft(S)});return u}getDataColumnsForRanges(r,e,t){var p,f,S,v;const n=this._univerInstanceService.getUnit(r,l.UniverInstanceType.UNIVER_SHEET);if(!n)return[];const o=n.getSheetBySheetId(e);if(!o)return[];const a=o.getCellMatrix(),s=a.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 _=s.startColumn;_<=s.endColumn;_++)if(!u.has(_))for(let D=d;D<=g;D++){const R=a.getValue(D,_);if(R&&(((p=R.v)==null?void 0:p.toString())||((v=(S=(f=R.p)==null?void 0:f.body)==null?void 0:S.dataStream)==null?void 0:v.trim())||"")){c.add(_);break}}const m=[],h=Array.from(c).sort((_,D)=>_-D);for(const _ of h)m.push({index:_,label:ft(_)});return m}getSelectionRangeNotation(){const r=this._selectionService.getCurrentSelections();return!r||r.length===0?"":r.map(e=>tn(e.range)).join(", ")}getSelectionRowRange(){const r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return null;let e=1/0,t=-1/0;for(const n of r)e=Math.min(e,n.range.startRow),t=Math.max(t,n.range.endRow);return{startRow:e,endRow:t}}getSelectionColumnIndices(){const r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return new Set;const e=new Set;for(const t of r)for(let n=t.range.startColumn;n<=t.range.endColumn;n++)e.add(n);return e}generateFileName(r,e){var a,s,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=((a=h.v)==null?void 0:a.toString())||((g=(d=(s=h.p)==null?void 0:s.body)==null?void 0:d.dataStream)==null?void 0:g.trim())||"";if(p){const f=p.replace(/[<>:"/\\|?*]/g,"_").trim();f&&o.push(f)}}}}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),a=wt(r.source,r.imageSourceType),s=[];for(const m of e.fileNameParts)if(m==="cellAddress")s.push(r.cellAddress);else if(m==="columnValue"&&e.columnIndex!==void 0){const h=o==null?void 0:o.getSheetBySheetId(n);if(h){const f=h.getCellMatrix().getValue(r.row,e.columnIndex);if(f){const S=((d=f.v)==null?void 0:d.toString())||((c=(u=(g=f.p)==null?void 0:g.body)==null?void 0:u.dataStream)==null?void 0:c.trim())||"";if(S){const v=S.replace(/[<>:"/\\|?*]/g,"_").trim();v&&s.push(v)}}}}return s.length===0?`${r.cellAddress}.${a}`:`${s.join("_")}.${a}`}async saveImages(r,e){var o;const t=await window.showDirectoryPicker({mode:"readwrite"}),n=new Map;for(const a of r){let s=this.generateFileName(a,e);const d=s.replace(/\.\w+$/,""),g=((o=s.match(/\.\w+$/))==null?void 0:o[0])||".png",u=n.get(d)||0;u>0&&(s=`${d}_${u}${g}`),n.set(d,u+1);try{const c=await this._getImageBlob(a),h=await(await t.getFileHandle(s,{create:!0})).createWritable();await h.write(c),await h.close()}catch(c){throw console.error(`Failed to save image ${s}:`,c),c}}}async saveImagesWithContext(r,e,t,n){var s;const o=await window.showDirectoryPicker({mode:"readwrite"}),a=new Map;for(const d of r){let g=this.generateFileNameWithContext(d,e,t,n);const u=g.replace(/\.\w+$/,""),c=((s=g.match(/\.\w+$/))==null?void 0:s[0])||".png",m=a.get(u)||0;m>0&&(g=`${u}_${m}${c}`),a.set(u,m+1);try{const h=await this._getImageBlob(d),f=await(await o.getFileHandle(g,{create:!0})).createWritable();await f.write(h),await f.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),a=document.createElement("a");a.href=o,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(o)}catch(n){throw console.error(`Failed to download image ${t}:`,n),n}}async _getImageBlob(r){if(r.imageSourceType===l.ImageSourceType.UUID){const e=await this._imageIoService.getImage(r.source);return Ut(e,l.ImageSourceType.URL)}return r.imageSourceType===l.ImageSourceType.URL?this._urlImageService.downloadImage(r.source):Ut(r.source,r.imageSourceType)}},M.BatchSaveImagesService=en([Fe(0,l.IUniverInstanceService),Fe(1,l.Inject(y.SheetsSelectionsService)),Fe(2,l.IImageIoService),Fe(3,l.IURLImageService)],M.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(Le),t=e.getCellImagesInSelection();if(t.length===1)try{return await e.downloadSingleImage(t[0]),!0}catch(s){return console.error("Failed to download image:",s),!1}const n=i.get(l.LocaleService),o=e.getSelectionRangeNotation(),a=`${n.t("sheetImage.save.title")} (${o})`;return r.open({id:ve,draggable:!0,width:360,title:{title:a},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);return y.getSheetCommandTarget(n)?(r.value==="open"?e.open({header:{title:t.t("sheetImage.panel.title")},children:{label:Pt},onClose:()=>{o.syncExecuteCommand(B.SetDrawingSelectedOperation.id,[])},width:360}):e.close(),!0):!1}},_t={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(i,r)=>{const e=i.get(l.ICommandService);return r==null?!1:(e.syncExecuteCommand(B.SetDrawingSelectedOperation.id,[r]),e.executeCommand(vt.id,{value:"open"}),!0)}},nn="sheets-drawing-ui.config",Nt={};var rn=Object.getOwnPropertyDescriptor,on=(i,r,e,t)=>{for(var n=t>1?void 0:t?rn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},ae=(i,r)=>(e,t)=>r(e,t,i);let Ge=class extends l.RxDisposable{constructor(r,e,t,n,o,a,s,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=a,this._messageService=s,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 a=t.getSelectedObjectMap();if(a.size>1){n==null||n.dispose();return}const s=a.values().next().value;if(!s)return;const d=s.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 f=this._canvasPopManagerService.getFeatureMenu(u,c,m,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:ge.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:f||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(a=>{a[l.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(t.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,e,t,n){return[{label:"image-popup.edit",index:0,commandId:_t.id,commandParams:{unitId:r,subUnitId:e,drawingId:t},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:fe.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:e,drawingId:t}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ge.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:e,drawingId:t},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ge.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:e,drawingId:t}],disable:n===l.DrawingTypeEnum.DRAWING_DOM}]}};Ge=on([ae(0,l.Inject(l.Injector)),ae(1,l.Inject(l.LocaleService)),ae(2,B.IDrawingManagerService),ae(3,l.Inject(b.SheetCanvasPopManagerService)),ae(4,A.IRenderManagerService),ae(5,l.IUniverInstanceService),ae(6,j.IMessageService),ae(7,l.IContextService),ae(8,l.IImageIoService),ae(9,l.ICommandService)],Ge);var an=Object.getOwnPropertyDescriptor,sn=(i,r,e,t)=>{for(var n=t>1?void 0:t?an(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},He=(i,r)=>(e,t)=>r(e,t,i);let It=class extends l.Disposable{constructor(r,e,t,n,o){super();ie(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=e,this._selectionsService=t,this._drawingRenderService=n,this._sheetSkeletonManagerService=o,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(U.throttleTime(33)).subscribe(r=>{var t,n;let e=[];r!==null&&(e=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),e.length>0&&(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&e.length===1&&((t=e[0].primary)==null?void 0:t.actualRow)===r.row&&((n=e[0].primary)==null?void 0:n.actualColumn)===r.col?(this._isSetCursor=!0,this._context.scene.setCursor(A.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(r=>{var e;if(r!=null&&r.drawing&&this._isSetCursor){const t=r.drawing.drawing.drawingOrigin,n=(e=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:e.imageCacheMap.getImage(t.imageSourceType,t.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};It=sn([He(1,l.Inject(b.HoverManagerService)),He(2,l.Inject(y.SheetsSelectionsService)),He(3,l.Inject(ge.DrawingRenderService)),He(4,l.Inject(b.SheetSkeletonManagerService))],It);var cn=Object.getOwnPropertyDescriptor,dn=(i,r,e,t)=>{for(var n=t>1?void 0:t?cn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ve=(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=dn([Ve(1,w.ISheetDrawingService),Ve(2,B.IDrawingManagerService),Ve(3,l.Inject(b.ISheetSelectionRenderService)),Ve(4,l.Inject(b.SheetSkeletonManagerService))],yt);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,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ie=(i,r)=>(e,t)=>r(e,t,i);function kt(i,r,e){var t,n,o,a;if(((n=(t=e==null?void 0:e.p)==null?void 0:t.body)==null?void 0:n.dataStream.length)===3&&((a=(o=e.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const s=e.p.drawings[e.p.drawingsOrder[0]],d=pt(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},s.docTransform.size.width,s.docTransform.size.height,s.docTransform.angle);if(d)return s.transform.width=d.width,s.transform.height=d.height,s.docTransform.size.width=d.width,s.docTransform.size.height=d.height,s.transform.left=0,s.transform.top=0,s.docTransform.positionH.posOffset=0,s.docTransform.positionV.posOffset=0,e.p.documentStyle.pageSize.width=1/0,e.p.documentStyle.pageSize.height=1/0,!0}return!1}let Xe=class extends l.Disposable{constructor(i,r,e,t,n,o){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=e,this._drawingManagerService=t,this._docDrawingController=n,this._editorBridgeService=o,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===$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(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)}}))}};Xe=un([Ie(0,l.ICommandService),Ie(1,l.Inject(y.SheetInterceptorService)),Ie(2,l.Inject(l.Injector)),Ie(3,B.IDrawingManagerService),Ie(4,l.Inject(bt.DocDrawingController)),Ie(5,l.Inject(b.IEditorBridgeService))],Xe);var gn=Object.getOwnPropertyDescriptor,hn=(i,r,e,t)=>{for(var n=t>1?void 0:t?gn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(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,a)=>{kt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},a)})}}))}};xe=hn([Wt(0,l.Inject(b.IAutoFillService)),Wt(1,l.Inject(l.Injector))],xe);var mn=Object.getOwnPropertyDescriptor,pn=(i,r,e,t)=>{for(var n=t>1?void 0:t?mn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ae=(i,r)=>(e,t)=>r(e,t,i);const Sn=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,l.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let Ke=class extends l.Disposable{constructor(i,r,e,t,n){super(),this._commandService=i,this._univerInstanceService=r,this._dialogService=e,this._renderManagerService=t,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(i){var n;const r=l.createDocumentModelWithStyle("",{}),e=(n=A.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(b.EditingRenderController),t=l.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[i],selection:{collapsed:!0,startOffset:0,endOffset:0}});t&&(r.apply(t),e&&e.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(i=>{var r,e;if(i.id===$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 a=o.getUnitId();if(Sn.includes(a)){if(a!==l.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const s=()=>{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
|
|
2
|
+
`?(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:s,showOk:!0,showCancel:!0,onOk:()=>{s(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:s})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};Ke=pn([Ae(0,l.ICommandService),Ae(1,l.IUniverInstanceService),Ae(2,j.IDialogService),Ae(3,A.IRenderManagerService),Ae(4,l.Inject(l.LocaleService))],Ke);var fn=Object.getOwnPropertyDescriptor,wn=(i,r,e,t)=>{for(var n=t>1?void 0:t?fn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ue=(i,r)=>(e,t)=>r(e,t,i);const Bt="image/png";function vn(i){const r=i.split(","),e=atob(r[1]),t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return new Blob([n],{type:Bt})}function _n(i){const r=new ClipboardItem({[Bt]:vn(i)});navigator.clipboard.write([r]).catch(e=>{console.error("Could not copy image using clipboard API: ",e)})}function In(){function i(){const t=document.createElement("input");return t.style.position="absolute",t.style.height="1px",t.style.width="1px",t.style.opacity="0",t}const r=document.activeElement,e=i();return document.body.appendChild(e),e.focus(),()=>{e.blur(),document.body.removeChild(e),r instanceof HTMLElement&&r.focus()}}const jt=[b.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,b.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,b.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,b.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA];let ze=class extends l.Disposable{constructor(r,e,t,n,o){super();ie(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=e,this._drawingService=t,this._clipboardInterfaceService=n,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,e,t,n)=>{this._copyInfo=null;const o=this._focusedDrawings;if(o.length>0){const[a]=o;if(a.drawingType!==l.DrawingTypeEnum.DRAWING_IMAGE)return;if(n===b.COPY_TYPE.CUT){const d={unitId:r,drawings:[a]};this._commandService.executeCommand(fe.id,d)}setTimeout(()=>{const d=In();a.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&a.imageSourceType===B.ImageSourceType.BASE64?_n(a.source):this._clipboardInterfaceService.writeText(""),d()},200);const s={unitId:a.unitId,subUnitId:a.subUnitId,drawings:[a]};this._copyInfo=s}else{const a=this._createDrawingsCopyInfoByRange(r,e,t);this._copyInfo=a}},onPasteCells:(r,e,t,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=b.COPY_TYPE.COPY,pasteType:a}=n,{range:s}=r||{},{range:d,unitId:g,subUnitId:u}=e;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:a,unitId:g,subUnitId:u,pasteRange:d},{copyRange:s,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:e,pasteType:a},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:a,endX:s,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:f}=p;if(p.anchorType!==w.SheetDrawingAnchorType.Both||!f)return;const{left:S=0,top:v=0,width:_=0,height:D=0}=f,{drawingStartX:R,drawingEndX:C,drawingStartY:T,drawingEndY:I}={drawingStartX:S,drawingEndX:S+_,drawingStartY:v,drawingEndY:v+D};a<=R&&C<=s&&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:a,range:s}=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(s);return this._generateMutations(m,{unitId:o,subUnitId:a,isCut:e===b.COPY_TYPE.CUT,getTransform:(p,f)=>{var _;const S=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),v={...p,left:S==null?void 0:S.startX,top:S==null?void 0:S.startY};return{transform:v,sheetTransform:(_=H(v,u))!=null?_:f}}})}_generateMutations(r,e){const{unitId:t,subUnitId:n,getTransform:o,isCut:a}=e,s=[],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:a?u.drawingId:l.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(a){const{undo:f,redo:S,objects:v}=g.getBatchUpdateOp([p]);s.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:w.DrawingApplyType.UPDATE,op:S,objects:v}}),d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:w.DrawingApplyType.UPDATE,op:f,objects:v}})}else{const{undo:f,redo:S,objects:v}=g.getBatchAddOp([p]);s.push({id:w.SetDrawingApplyMutation.id,params:{op:S,unitId:t,subUnitId:n,objects:v,type:w.DrawingApplyType.INSERT}}),d.push({id:w.SetDrawingApplyMutation.id,params:{op:f,unitId:t,subUnitId:n,objects:v,type:w.DrawingApplyType.REMOVE}})}}),{redos:s,undos:d}}_generateRangeDrawingsPasteMutations(r,e){var N;const{unitId:t,subUnitId:n,pasteType:o,pasteRange:a}=r,{copyRange:s,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(!s)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:t,subUnitId:n,range:b.discreteRangeToRange(a)},pasteType:o},d);const{ranges:[c,m],mapFunc:h}=b.virtualizeDiscreteRanges([s,a]),{row:p,col:f}=h(c.startRow,c.startColumn),{row:S,col:v}=h(m.startRow,m.startColumn),_=g.attachRangeWithCoord({startRow:p,endRow:p,startColumn:f,endColumn:f}),D=g.attachRangeWithCoord({startRow:S,endRow:S,startColumn:v,endColumn:v});if(!_||!D||!this._copyInfo)return{redos:[],undos:[]};const R=D.startX-_.startX,C=D.startY-_.startY,T=S-p,I=v-f;return this._generateMutations(u,{unitId:t,subUnitId:n,getTransform:(O,k)=>{var W,P;return{transform:{...O,left:((W=O==null?void 0:O.left)!=null?W:0)+R,top:((P=O==null?void 0:O.top)!=null?P:0)+C},sheetTransform:{...k,to:{...k.to,row:k.to.row+T,column:k.to.column+I},from:{...k.from,row:k.from.row+T,column:k.from.column+I}}}},isCut:d===b.COPY_TYPE.CUT})}};ze=wn([Ue(0,b.ISheetClipboardService),Ue(1,A.IRenderManagerService),Ue(2,B.IDrawingManagerService),Ue(3,j.IClipboardInterfaceService),Ue(4,l.ICommandService)],ze);var yn=Object.getOwnPropertyDescriptor,Cn=(i,r,e,t)=>{for(var n=t>1?void 0:t?yn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Pe=(i,r)=>(e,t)=>r(e,t,i);let qe=class extends l.Disposable{constructor(i,r,e,t,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=e,this._univerInstanceService=t,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,e=U.combineLatest([i,r]);this.disposeWithMe(e.pipe(U.switchMap(([t,n])=>t?t.activeSheet$.pipe(U.tap(o=>{if(!o){this._drawingManagerService.setDrawingVisible(!1);return}const a=t.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new y.WorkbookViewPermission(a).id,new y.WorksheetViewPermission(a,s).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),a=this._renderManagerService.getRenderById(e),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===A.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.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 a=t.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new y.WorkbookEditablePermission(a).id,new y.WorksheetEditPermission(a,s).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),a=this._renderManagerService.getRenderById(e),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===A.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.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(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),d=s==null?void 0:s.scene;if(!d)return U.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookViewPermission(o).id,new y.WorksheetViewPermission(o,a).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:a})))})):U.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingVisible(e);const s=t.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(o,a),g=Object.values(d);e?this._drawingManagerService.addNotification(g):(s.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 a=this._drawingManagerService.getDrawingData(n,o),s=Object.values(a);this._drawingManagerService.addNotification(s)}}))}_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(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),d=s==null?void 0:s.scene;if(!d)return U.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookEditablePermission(o).id,new y.WorksheetEditPermission(o,a).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:a})))})):U.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingEditable(e);const s=t.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(o,a),g=Object.values(d);e?(s.forEach(u=>{u.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&t.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(s.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(),a=this._renderManagerService.getRenderById(t),s=a==null?void 0:a.scene;if(!s)return;const d=this._drawingManagerService.getDrawingData(t,o),g=Object.values(d);this._drawingManagerService.setDrawingEditable(!0),s.getAllObjectsByOrder().forEach(c=>{c.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(m=>c.oKey.includes(m.drawingId))&&s.detachTransformerFrom(c)})}}))}};qe=Cn([Pe(0,B.IDrawingManagerService),Pe(1,A.IRenderManagerService),Pe(2,l.IPermissionService),Pe(3,l.IUniverInstanceService),Pe(4,l.Inject(l.UserManagerService))],qe);var Dn=Object.getOwnPropertyDescriptor,Tn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Dn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(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:a,scaleY:s}=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:f,right:S,top:v,bottom:_}=i;let{top:D,left:R,viewportScrollX:C,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"&&(C=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=(f-C)*a,E=(S-C)*a;else{const z=f-(G-O),ee=S-(G-O);S<ne?(P=z*a,E=ee*a):f<=ne&&S>=ne?(P=z*a,E=Math.max(R,(S-C)*a)):f>ne&&(p.left=!1,P=Math.max((f-C)*a,R),E=Math.max((S-C)*a,R))}let K=0,Z=0;if(h===0)p.top=!1,K=(v-T)*s,Z=(_-T)*s;else{const z=v-($-k),ee=_-($-k);_<Q?(K=z*s,Z=ee*s):v<=Q&&_>=Q?(K=z*s,Z=Math.max(D,(_-T)*s)):v>Q&&(p.top=!1,K=Math.max((v-T)*s,D),Z=Math.max((_-T)*s,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 se=(i,r,e,t,n)=>{const{left:o,top:a,width:s,height:d,angle:g}=i,u={left:o,right:o+s,top:a,bottom:a+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:s*m,height:d*h,absolute:c.absolute}};M.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(e,t,n,o,a,s,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=a,this._sheetDrawingService=s,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(),a=t.engine.getCanvasElement();return{scene:n,transformer:o,renderUnit:t,canvas:a}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(t=>{var ee;const{unitId:n,subUnitId:o,drawingId:a}=t,s=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||!s)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 f=this._getSceneAndTransformerByDrawingSearch(n);if(f==null)return;const{scene:S,canvas:v}=f;if(m==null)return!0;if(u!==o)return;const{left:_,top:D,width:R,height:C,angle:T,flipX:I,flipY:N,skewX:O,skewY:k}=m,W=B.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),P=S.getObject(W);if(P!=null){P.transformByState({left:_,top:D,width:R,height:C,angle:T,flipX:I,flipY:N,skewX:O,skewY:k});return}const E={left:_,top:D,width:R,height:C,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),S.addObject(G,A.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo(G);const Q=new l.DisposableCollection,ne=se(G,f.renderUnit.scene,c.skeleton,s.worksheet),K=new U.BehaviorSubject(ne),Z=`${$t}${l.generateRandomId(6)}`,oe={dispose:Q,rect:G,position$:K,unitId:n,subUnitId:o,id:a,domId:Z};this._canvasFloatDomService.addFloatDom({position$:K,id:a,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=se(G,f.renderUnit.scene,c.skeleton,s.worksheet);K.next(X)});Q.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),z&&Q.add(z),this._domLayerInfoMap.set(a,oe)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(t=>{var m;const{unitId:n,subUnitId:o,drawingId:a}=t,s=B.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{transformer:g,scene:u}=d,c=u.getObject(s);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),a=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),s=y.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:n}),d=(g=this._renderManagerService.getRenderById(t))==null?void 0:g.with(b.SheetSkeletonManagerService).getSkeletonParam(n);!o||!s||!d||a.forEach(u=>{const c=this._domLayerInfoMap.get(u);if(c){const m=se(c.rect,o.renderUnit.scene,d.skeleton,s.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(s=>s.unitId===o).map(s=>s.subUnitId).forEach(s=>{e(o,s)})}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 a=this._domLayerInfoMap.get(n),s=this._getSceneAndTransformerByDrawingSearch(e);if(a&&s){const{scene:d}=s,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:a,endY:s}=e,d=(h=this._renderManagerService.getRenderById(t))==null?void 0:h.with(b.ISheetSelectionRenderService);if(d==null)return;const g=d.getCellWithCoordByOffset(n,a);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:a-g.startY},c=d.getCellWithCoordByOffset(o,s);if(c==null)return;const m={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:s-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 a=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(a&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART){const{scene:s}=a,d=this._domLayerInfoMap.get(t.drawingId);d!=null&&d.rect&&(n.allowTransform===!1?s.detachTransformerFrom(d.rect):s.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:a}=n,{initPosition:s,componentKey:d,data:g,allowTransform:u=!0}=e,c=t!=null?t:l.generateRandomId(),m=this._getPosition(s,o);if(m==null)return;const h={unitId:o,subUnitId:a,drawingId:c,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:m,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Ee.id,{unitId:o,drawings:[h]}),this._add$.next({unitId:o,subUnitId:a,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:a}=n;this._domLayerInfoMap.delete(e),n.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(n.rect),t){const d=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,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:a,op:u,objects:c,type:w.DrawingApplyType.REMOVE})}}addFloatDomToRange(e,t,n,o){var I,N,O;const a=y.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:d}=a,g=this._getSceneAndTransformerByDrawingSearch(s);if(!g)return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const c=(I=this._renderManagerService.getRenderById(s))==null?void 0:I.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:m,data:h,allowTransform:p=!0}=t,f=o!=null?o:l.generateRandomId(),{position:S,position$:v}=this._createRangePositionObserver(e,u,c.skeleton);if(this._getPosition(S,s)==null)return;const D=g.scene,{scaleX:R}=D.getAncestorScale(),C=Ze(S,n,R),T={unitId:s,subUnitId:d,drawingId:f,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}=T,E=y.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:tt,top:nt,width:rt,height:it,angle:Rt,flipX:Et,flipY:ot,skewX:at,skewY:De}=Z,st=B.getDrawingShapeKeyByDrawingSearch({unitId:k,subUnitId:W,drawingId:P}),ce=X.getObject(st);if(ce!=null){ce.transformByState({left:tt,top:nt,width:rt,height:it,angle:Rt,flipX:Et,flipY:ot,skewX:at,skewY:De});return}const re={left:tt,top:nt,width:rt,height:it,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,ct=X.getMainViewport(),{rowHeaderWidth:Me,columnHeaderHeight:We}=K.skeleton,dt={top:We,left:Me,bottom:ct.bottom,right:ct.right},ue={dispose:le,rect:de,boundsOfViewArea:dt,domAnchor:n,unitId:k,subUnitId:W},x=se(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 Ht,Vt,Xt,xt;const Gt=Ze({startX:L.startX,startY:L.startY,endX:L.endX,endY:L.endY,width:(Ht=n.width)!=null?Ht:L.width,height:(Vt=n.height)!=null?Vt:L.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),er=B.getDrawingShapeKeyByDrawingSearch({unitId:k,subUnitId:W,drawingId:P}),tr=new A.Rect(er,{left:Gt.startX,top:Gt.startY,width:(Xt=n.width)!=null?Xt:L.width,height:(xt=n.height)!=null?xt:L.height,zIndex:this._drawingManagerService.getDrawingOrder(k,W).length-1}),nr=se(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(f,!0)});const lt=de.onTransformChange$.subscribeEvent(()=>{const L=se(de,ee.renderUnit.scene,K.skeleton,E.worksheet,ue);Re.next(L)});le.add(()=>{this._canvasFloatDomService.removeFloatDom(P)}),lt&&le.add(lt),this._domLayerInfoMap.set(P,ue)}return{id:f,dispose:()=>{this._removeDom(f,!0)}}}addFloatDomToColumnHeader(e,t,n,o){var C,T,I;const a=y.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:d}=a;if(!this._getSceneAndTransformerByDrawingSearch(s))return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const c=(C=this._renderManagerService.getRenderById(s))==null?void 0:C.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:m,data:h,allowTransform:p=!0}=t,f=o!=null?o:l.generateRandomId(),{position:S,position$:v}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:e,endColumn:e},u,c.skeleton),_=S;if(_.startY=0,this._getPosition(S,s)==null)return;const R={unitId:s,subUnitId:d,drawingId:f,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:_.startX,top:_.startY,width:_.width,height:_.height},data:h,allowTransform:p};{const{unitId:N,subUnitId:O,drawingId:k}=R,W=y.getSheetCommandTarget(this._univerInstanceService,{unitId:N,subUnitId:O}),P=R,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:tt,angle:nt,flipX:rt,flipY:it,skewX:Rt,skewY:Et}=ne,ot=B.getDrawingShapeKeyByDrawingSearch({unitId:N,subUnitId:O,drawingId:k}),at=oe.getObject(ot);if(at!=null){at.transformByState({left:ee,top:X,width:Ce,height:tt,angle:nt,flipX:rt,flipY:it,skewX:Rt,skewY:Et});return}const De=Ze({startX:_.startX,startY:0,endX:S.endX,endY:S.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),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(ot,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"},ct=se(ce,Z.renderUnit.scene,Q.skeleton,W.worksheet,le),Me=new U.BehaviorSubject(ct);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 dt=ce.onTransformChange$.subscribeEvent(()=>{const x=se(ce,Z.renderUnit.scene,Q.skeleton,W.worksheet,le);Me.next(x)});this.disposeWithMe(v.subscribe(x=>{const Re=Ze({startX:x.startX,startY:0,endX:x.endX,endY:x.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.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}),lt=se(je,Z.renderUnit.scene,Q.skeleton,W.worksheet,le);Me.next(lt)}));const ue=(I=this._renderManagerService.getRenderById(N))==null?void 0:I.with(b.SheetSkeletonManagerService);ue==null||ue.currentSkeleton$.subscribe(x=>{x&&c.sheetId!==x.sheetId&&this._removeDom(f,!0)}),re.add(()=>{this._canvasFloatDomService.removeFloatDom(k)}),dt&&re.add(dt),this._domLayerInfoMap.set(k,le)}return{id:f,dispose:()=>{this._removeDom(f,!0)}}}_createRangePositionObserver(e,t,n){let{startRow:o,startColumn:a}=e;const s=Ne(o,a,n),d=new U.BehaviorSubject(s),g=Ne(e.endRow,e.endColumn,n),u=new U.BehaviorSubject(g),c=()=>{const v=Ne(o,a,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,a=_,c()},p=()=>({rotate:0,width:g.right-s.left,height:g.bottom-s.top,absolute:{left:!0,top:!0},startX:s.left,startY:s.top,endX:g.right,endY:g.bottom}),f=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}})),S=p();return{position$:f,position:S,updateRowCol:h,topLeftPos$:d,rightBottomPos$:u,disposable:m}}},M.SheetCanvasFloatDomManagerService=Tn([pe(0,l.Inject(A.IRenderManagerService)),pe(1,l.IUniverInstanceService),pe(2,l.Inject(l.ICommandService)),pe(3,B.IDrawingManagerService),pe(4,l.Inject(j.CanvasFloatDomService)),pe(5,w.ISheetDrawingService),pe(6,l.Inject(l.LifecycleService))],M.SheetCanvasFloatDomManagerService);function Ne(i,r,e){const t=e.getCellWithCoordByIndex(i,r),n=t.isMergedMainCell?t.mergeInfo:t;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Ze(i,r,e){var g,u;e=e!=null?e:1;const t=i.endX-i.startX,n=i.endY-i.startY,o=(g=r==null?void 0:r.width)!=null?g:t,a=(u=r==null?void 0:r.height)!=null?u:n;let s=0,d=0;if(r){if(r.horizonOffsetAlign==="right"){const c=Je(r.marginX,t*e);s=i.endX-c-o}else s=i.startX+Je(r.marginX,t);if(r.verticalOffsetAlign==="bottom"){const c=Je(r.marginY,n*e);d=i.endY-c-a}else d=i.startY+Je(r.marginY,n)}return{rotate:0,startX:s,startY:d,endX:i.endX,endY:i.endY,width:o,height:a,absolute:{left:i.absolute.left,top:i.absolute.top}}}function Je(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const e=Number.parseFloat(i);return r*e/100}const Mn=i=>{const{floatDomInfos:r,scene:e,skeleton:t,worksheet:n}=i,o=q.useMemo(()=>r.map(a=>{const{width:s,height:d,angle:g,left:u,top:c}=a.transform,m=Ft({left:u!=null?u:0,right:(u!=null?u:0)+(s!=null?s: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(),f={startX:m.left,endX:m.right,startY:m.top,endY:m.bottom,rotate:g,width:s*h,height:d*p,absolute:m.absolute},S={position$:new U.BehaviorSubject(f),position:f,id:a.drawingId,componentKey:a.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:a.unitId,data:a.data};return[a.drawingId,S]}),[r,e,t,n]);return F.jsx("div",{style:{position:"absolute",top:0,left:0},children:o.map(([a,s])=>F.jsx(j.PrintFloatDomSingle,{layer:s,id:a,position:s.position},a))})};var Rn=Object.getOwnPropertyDescriptor,En=(i,r,e,t)=>{for(var n=t>1?void 0:t?Rn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Se=(i,r)=>(e,t)=>r(e,t,i);let Qe=class extends l.Disposable{constructor(i,r,e,t,n,o,a){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=e,this._renderManagerService=t,this._canvasFloatDomManagerService=n,this._componetManager=o,this._injector=a,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,a=this._drawingManagerService.getDrawingDataForUnit(t),s=a==null?void 0:a[o];return s&&s.order.forEach(d=>{const g=s.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 a=o.with(b.SheetSkeletonManagerService).getSkeletonParam(n);if(!a)return e(i);const s=this._drawingManagerService.getDrawingDataForUnit(t),d=s==null?void 0:s[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=a.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),f=a.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<f.row&&(c.endRow=f.row),c.endColumn<f.column&&(c.endColumn=f.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),a=o==null?void 0:o[n];if(a){const s=a.order.map(g=>{const u=a.data[g];if(u.drawingType===l.DrawingTypeEnum.DRAWING_CHART)return{...u,componentKey:this._componetManager.get(l.PRINT_CHART_COMPONENT_KEY)};if(u.drawingType===l.DrawingTypeEnum.DRAWING_DOM){const c=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(c||u.componentKey)}}return null}).filter(Boolean),d=j.connectInjector(Mn,this._injector);return Y.render(F.jsx(d,{floatDomInfos:s,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),i==null||i.add(()=>{Y.unmount(r.root)}),e(i)}}}))}};Qe=En([Se(0,l.Inject(b.SheetPrintInterceptorService)),Se(1,l.Inject(ge.DrawingRenderService)),Se(2,B.IDrawingManagerService),Se(3,A.IRenderManagerService),Se(4,l.Inject(M.SheetCanvasFloatDomManagerService)),Se(5,l.Inject(j.ComponentManager)),Se(6,l.Inject(l.Injector))],Qe);var bn=Object.getOwnPropertyDescriptor,On=(i,r,e,t)=>{for(var n=t>1?void 0:t?bn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},me=(i,r)=>(e,t)=>r(e,t,i);const An=[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],Un=[y.SetRowVisibleMutation.id,y.SetRowHiddenMutation.id,y.SetColVisibleMutation.id,y.SetColHiddenMutation.id,y.SetWorksheetRowHeightMutation.id,y.SetWorksheetRowAutoHeightMutation.id,y.SetWorksheetRowIsAutoHeightMutation.id,y.SetWorksheetColWidthMutation.id];let Ct=class extends l.Disposable{constructor(i,r,e,t,n,o,a,s,d){super(),this._context=i,this._renderManagerService=r,this._commandService=e,this._selectionRenderService=t,this._skeletonManagerService=n,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptAfterCommand({getMutations:i=>{if(!An.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===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,a=r===y.DeltaRowHeightCommand.id||r===y.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(t,n,o,a)}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=[],a=[],s=this._sheetDrawingService.getDrawingData(t,n),d=[],g=[];if(Object.keys(s).forEach(u=>{const c=s[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}}),a.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}}),a.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]}),a.push({id:V.id,params:[t]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,r,e){const t=[],n=[],{sheetTransform:o,anchorType:a=w.SheetDrawingAnchorType.Position,transform:s,unitId:d,subUnitId:g,drawingId:u}=e,{from:c,to:m}=o,{row:h,column:p}=c,{row:f,column:S}=m;if(o==null||s==null)return{updateDrawings:t,deleteDrawings:n};const{startRow:v,endRow:_,startColumn:D,endColumn:R}=i;let C=null,T=null;if(r===0&&h>=v&&f<=_)if(p>=D&&S<=R)n.push({unitId:d,subUnitId:g,drawingId:u});else{const I=this._shrinkCol(o,s,D,R,a);C=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===1&&p>=D&&S<=R)if(h>=v&&f<=_)n.push({unitId:d,subUnitId:g,drawingId:u});else{const I=this._shrinkRow(o,s,v,_,a);C=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===2){const I=this._expandRow(o,s,v,_,a);C=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===3){const I=this._expandCol(o,s,D,R,a);C=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}if(C!=null&&T!=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=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:f,to:S}=m,{row:v,column:_}=f,{row:D,column:R}=S;for(let C=0;C<e.length;C++){const T=e[C],{startRow:I,endRow:N,startColumn:O,endColumn:k}=T;if(R<O)continue;if(p===w.SheetDrawingAnchorType.Position){let E=null,$=null;if(_>=O&&_<=k){const G=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:k,startRow:f.row,endRow:S.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&&R<=k)continue;let W=null,P=null;if(_>=O&&_<=k){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:k,startRow:f.row,endRow:S.row});if(E==null)return;P={...h,left:(E==null?void 0:E.startX)||0,width:((h==null?void 0:h.width)||0)-E.endX+E.startX}}else if(R>=O&&R<=k){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:R,startRow:f.row,endRow:S.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:f.row,endRow:S.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:a,undos:s}=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:a,undos:s,preRedos:d,preUndos:g}}_createUndoAndRedoMutation(i,r,e){const t=this._sheetDrawingService.getBatchUpdateOp(e),{undo:n,redo:o,objects:a}=t,s=[{id:w.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:w.DrawingApplyType.UPDATE}},{id:V.id,params:[i]}],d=[{id:w.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:a,type:w.DrawingApplyType.UPDATE}},{id:V.id,params:[i]}];return{redos:s,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:f,to:S}=m,{row:v,column:_}=f,{row:D,column:R}=S;for(let C=0;C<e.length;C++){const T=e[C],{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:f.column,endColumn:S.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:f.column,endColumn:S.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:f.column,endColumn:S.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:f.column,endColumn:S.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:a,undos:s}=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:a,undos:s,preRedos:d,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,e,t){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(a=>{const s=n[a],{sheetTransform:d,transform:g,anchorType:u=w.SheetDrawingAnchorType.Position}=s;if(u===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,o,s);else{const{from:c,to:m}=d,{row:h,column:p}=c,{row:f,column:S}=m;for(let v=0;v<e.length;v++){const _=e[v],{startRow:D,endRow:R,startColumn:C,endColumn:T}=_;if(f<D||S<C)continue;if(u===w.SheetDrawingAnchorType.Position&&(h<=D&&f>=R||p<=C&&S>=T)){this._remainDrawingSize(g,o,s);continue}const I=J({...d},this._selectionRenderService,this._skeletonManagerService);if(I!=null){o.push({...s,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,R;const{toRange:r,fromRange:e}=i,t=y.getSheetCommandTarget(this._univerInstanceService);if(!t)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=t,a=(R=(D=this._renderManagerService.getRenderById(n))==null?void 0:D.with(b.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=b.attachRangeWithCoord(a,e);if(!s)return{redos:[],undos:[]};const{startX:d,endX:g,startY:u,endY:c}=s,m=this._sheetDrawingService.getDrawingData(n,o),h=[];Object.keys(m).forEach(C=>{const T=m[C];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=[],f=[],S=r.startRow-e.startRow,v=r.startColumn-e.startColumn,_=h.map(C=>{const T=C.sheetTransform,I={to:{...T.to,row:T.to.row+S,column:T.to.column+v},from:{...T.from,row:T.from.row+S,column:T.from.column+v}},N=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:T,redo:I,objects:N}=C;p.push({id:w.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:I,objects:N,type:w.DrawingApplyType.UPDATE}}),f.push({id:w.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:T,objects:N,type:w.DrawingApplyType.UPDATE}})}return{redos:p,undos:f}}_moveRowInterceptor(i,r){const e=this._getUnitIdAndSubUnitId(i,r);if(e==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=e,{range:o}=i,a=o.startRow,s=o.endRow,d=[],g=[],u=this._sheetDrawingService.getDrawingData(t,n),c=[],m=[];if(Object.keys(u).forEach(h=>{const p=u[h],{sheetTransform:f,transform:S,anchorType:v=w.SheetDrawingAnchorType.Position}=p;if(f==null||S==null)return;let _,D;if(r==="insert"){const C=this._expandRow(f,S,a,s,v);_=C==null?void 0:C.newSheetTransform,D=C==null?void 0:C.newTransform}else{const{from:C,to:T}=f,{row:I}=C,{row:N}=T;if(v===w.SheetDrawingAnchorType.Both&&I>=a&&N<=s)m.push({unitId:t,subUnitId:n,drawingId:h});else{const O=this._shrinkRow(f,S,a,s,v);_=O==null?void 0:O.newSheetTransform,D=O==null?void 0:O.newTransform}}if(!_||!D)return;const R={unitId:t,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};c.push(R)}),c.length===0&&m.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:p,redo:f,objects:S}=h;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:S,type:w.DrawingApplyType.UPDATE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:S,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),p=h.undo,f=h.redo,S=h.objects;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:S,type:w.DrawingApplyType.REMOVE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:S,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,a=o.startColumn,s=o.endColumn,d=[],g=[],u=this._sheetDrawingService.getDrawingData(t,n),c=[],m=[];if(Object.keys(u).forEach(h=>{const p=u[h],{sheetTransform:f,transform:S,anchorType:v=w.SheetDrawingAnchorType.Position}=p;if(f==null||S==null)return;let _,D;if(r==="insert"){const C=this._expandCol(f,S,a,s,v);_=C==null?void 0:C.newSheetTransform,D=C==null?void 0:C.newTransform}else{const{from:C,to:T}=f,{column:I}=C,{column:N}=T;if(v===w.SheetDrawingAnchorType.Both&&I>=a&&N<=s)m.push({unitId:t,subUnitId:n,drawingId:h});else{const O=this._shrinkCol(f,S,a,s,v);_=O==null?void 0:O.newSheetTransform,D=O==null?void 0:O.newTransform}}if(!_||!D)return;const R={unitId:t,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};c.push(R)}),c.length===0&&m.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:p,redo:f,objects:S}=h;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:S,type:w.DrawingApplyType.UPDATE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:S,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),p=h.undo,f=h.redo,S=h.objects;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:S,type:w.DrawingApplyType.REMOVE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:S,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:a,to:s}=i,{column:d}=a,{column:g}=s;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:a.row,endRow:s.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:{...a},to:{...s,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:a,to:s}=i,{column:d}=a,{column:g}=s;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>t)u={from:{...a,column:d-o},to:{...s,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:{...a},to:{...s,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:a.row,endRow:s.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:a.row,endRow:s.row});if(m==null)return;u={from:{...a},to:{...s,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:a,to:s}=i,{row:d}=a,{row:g}=s;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:a.column,endColumn:s.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:{...a},to:{...s,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:a,to:s}=i,{row:d}=a,{row:g}=s;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>t)u={from:{...a,row:d-o},to:{...s,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:{...a},to:{...s,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:a.column,endColumn:s.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:a.column,endColumn:a.column,startRow:e-1,endRow:e-1});if(m==null)return;u={from:{...a},to:{...s,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 a=n[o].data;a!=null&&Object.keys(a).forEach(s=>{t===i&&e.push(a[s])})})}),this._drawingManagerService.removeNotification(e)})}_updateDrawings(i,r){setTimeout(()=>{const e=this._drawingManagerService.drawingManagerData,t=[],n=[];Object.keys(e).forEach(o=>{const a=e[o];a!=null&&Object.keys(a).forEach(s=>{const d=a[s].data;d!=null&&Object.keys(d).forEach(g=>{if(o===i&&s===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=>{Un.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,e=y.getSheetCommandTarget(this._univerInstanceService,r);if(!e)return;const{unitId:t,subUnitId:n,worksheet:o}=e;let a=[];"range"in r?a=r.range:"rowsAutoHeightInfo"in r&&(a=r.rowsAutoHeightInfo.map(s=>({startRow:s.row,endRow:s.row,startColumn:0,endColumn:o.getColumnCount()-1}))),this._refreshDrawingTransform(t,n,a)})}))}_refreshDrawingTransform(i,r,e){const t=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(t).forEach(o=>{const a=t[o],{sheetTransform:s,transform:d,anchorType:g=w.SheetDrawingAnchorType.Position}=a;if(g===w.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=s,{row:m,column:h}=u,{row:p,column:f}=c;for(let S=0;S<e.length;S++){const v=e[S],{startRow:_,endRow:D,startColumn:R,endColumn:C}=v;if(l.Rectangle.intersects({startRow:_,endRow:D,startColumn:R,endColumn:C},{startRow:m,endRow:p,startColumn:h,endColumn:f})||m>D||h>C){const T=g===w.SheetDrawingAnchorType.Position,I=J(s,this._selectionRenderService,this._skeletonManagerService);n.push({...a,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=On([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,B.IDrawingManagerService),me(8,l.IUniverInstanceService)],Ct);function Pn(){const i=j.useDependency(l.LocaleService),r=j.useDependency(j.IDialogService),e=j.useDependency(Le),[t,n]=q.useState([he.CELL_ADDRESS]),[o,a]=q.useState(!1),[s,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,f]=q.useState(()=>h.length>0?h[0].value:"0"),S=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(S);const v=q.useCallback(T=>{T.length!==0&&n(T)},[]),_=q.useCallback(T=>{f(String(T))},[]),D=q.useCallback(()=>{r.close(ve)},[r]),R=q.useCallback(async()=>{if(g.length!==0){a(!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{a(!1)}}},[e,g,t,p,r,i]),C=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")})]})}),C&&F.jsx(Y.FormLayout,{label:i.t("sheetImage.save.selectColumn"),children:F.jsx(Y.Select,{value:p,options:h,onChange:_})}),s&&F.jsx("div",{className:"univer-text-xs univer-text-red-500",children:s}),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:R,disabled:o||g.length===0,children:o?i.t("sheetImage.save.saving"):i.t("sheetImage.save.confirm")})]})]})}const Lt=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,a=o[0];if(a==null)return;const{unitId:s}=a,d=n.getRenderById(s),g=d==null?void 0:d.scene;if(g==null)return;const u=g.getTransformerByCreate(),[c,m]=q.useState(!0),h=(_=a.anchorType)!=null?_:w.SheetDrawingAnchorType.Position,[p,f]=q.useState(h);function S(D,R){const C=[];return D.forEach(T=>{const{oKey:I}=T,N=R.getDrawingOKey(I);if(N==null)return C.push(null),!0;const{unitId:O,subUnitId:k,drawingId:W,drawingType:P,anchorType:E,sheetTransform:$}=N;C.push({unitId:O,subUnitId:k,drawingId:W,anchorType:E,sheetTransform:$,drawingType:P})}),C}q.useEffect(()=>{const D=u.clearControl$.subscribe(C=>{C===!0&&m(!1)}),R=u.changeStart$.subscribe(C=>{var N;const{objects:T}=C,I=S(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;f(O)}});return()=>{R.unsubscribe(),D.unsubscribe()}},[]);function v(D){f(D);const R=t.getFocusDrawings();if(R.length===0)return;const C=R.map(T=>({unitId:T.unitId,subUnitId:T.subUnitId,drawingId:T.drawingId,anchorType:D}));r.executeCommand(be.id,{unitId:R[0].unitId,drawings:C})}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(Lt,{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:[y.WorkbookEditablePermission],worksheetTypes:[y.WorksheetEditPermission],rangeTypes:[y.RangeProtectionPermissionEditPoint]})}}function Wn(i){return{id:Oe.id,title:"sheetImage.upload.float",type:j.MenuItemType.BUTTON,hidden$:j.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function Bn(i){return{id:St.id,title:"sheetImage.upload.cell",type:j.MenuItemType.BUTTON,hidden$:j.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function jn(i){var r,e,t,n;return!!((e=(r=i==null?void 0:i.p)==null?void 0:r.drawingsOrder)!=null&&e.length&&((n=(t=i==null?void 0:i.p)==null?void 0:t.drawingsOrder)==null?void 0:n.length)>0)}function $n(i,r){const e=i.getActiveSheet();if(!e)return!1;const t=e.getCellMatrix(),{startRow:n,endRow:o,startColumn:a,endColumn:s}=r;for(let d=n;d<=o;d++)for(let g=a;g<=s;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(y.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 a of o)if($n(n,a.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},[St.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_SHEET)&&!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:ut.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,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},ye=(i,r)=>(e,t)=>r(e,t,i);let et=class extends l.Disposable{constructor(i,r,e,t,n,o){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=e,this._shortcutService=t,this._drawingManagerService=n,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Pt,Nn)),this.disposeWithMe(i.register(ve,Pn))}_initMenus(){this._menuManagerService.mergeMenu(Ln)}_initCommands(){[Oe,St,Ee,fe,be,vt,V,_t,gt,mt,we,ut,ht,_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()}};et=Kn([ye(0,l.Inject(j.ComponentManager)),ye(1,j.IMenuManagerService),ye(2,l.ICommandService),ye(3,j.IShortcutService),ye(4,B.IDrawingManagerService),ye(5,l.Inject(y.SheetsSelectionsService))],et);var zn=Object.defineProperty,qn=Object.getOwnPropertyDescriptor,Zn=(i,r,e)=>r in i?zn(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e,Jn=(i,r,e,t)=>{for(var n=t>1?void 0:t?qn(r,e):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Mt=(i,r)=>(e,t)=>r(e,t,i),Yt=(i,r,e)=>Zn(i,typeof r!="symbol"?r+"":r,e);const Qn="SHEET_IMAGE_UI_PLUGIN";M.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=Nt,e,t,n){super(),this._config=r,this._injector=e,this._renderManagerService=t,this._configService=n;const{menu:o,...a}=l.merge({},Nt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(nn,a)}onStarting(){l.registerDependencies(this._injector,[[M.SheetCanvasFloatDomManagerService],[et],[Ge],[Qe],[qe],[ze],[Xe],[xe],[Ke],[Le,{useClass:M.BatchSaveImagesService}]]),l.touchDependencies(this._injector,[[M.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[ze],[Ke]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[qe],[Qe],[et],[Xe],[xe]])}onSteady(){this._injector.get(Ge)}_registerRenderModules(){[[M.SheetDrawingUpdateController],[Ct],[yt],[It]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}},Yt(M.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),Yt(M.UniverSheetsDrawingUIPlugin,"pluginName",Qn),M.UniverSheetsDrawingUIPlugin=Jn([l.DependentOn(B.UniverDrawingPlugin,bt.UniverDocsDrawingPlugin,ge.UniverDrawingUIPlugin,w.UniverSheetsDrawingPlugin),Mt(1,l.Inject(l.Injector)),Mt(2,A.IRenderManagerService),Mt(3,l.IConfigService)],M.UniverSheetsDrawingUIPlugin),M.ClearSheetDrawingTransformerOperation=V,M.DeleteDrawingsCommand=ut,M.EditSheetDrawingOperation=_t,M.FileNamePart=he,M.GroupSheetDrawingCommand=gt,M.IBatchSaveImagesService=Le,M.InsertFloatImageCommand=Oe,M.InsertSheetDrawingCommand=Ee,M.MoveDrawingsCommand=we,M.RemoveSheetDrawingCommand=fe,M.SHEETS_IMAGE_MENU_ID=Dt,M.SHEET_FLOAT_DOM_PREFIX=$t,M.SaveCellImagesCommand=_e,M.SetDrawingArrangeCommand=ht,M.SetSheetDrawingCommand=be,M.SheetDrawingAnchor=Lt,M.SidebarSheetDrawingOperation=vt,M.UngroupSheetDrawingCommand=mt,M.calcSheetFloatDomPosition=se,M.drawingPositionToTransform=J,M.transformToDrawingPosition=H,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})}));
|