@univerjs/sheets-drawing-ui 0.7.0 → 0.8.0-beta.0

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