@univerjs/sheets-drawing-ui 0.7.0-nightly.202505081607 → 0.7.0-nightly.202505101606

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1,9 +1,2 @@
1
- "use strict";var Lt=Object.defineProperty;var Ft=(i,r,t)=>r in i?Lt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t;var te=(i,r,t)=>Ft(i,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),bt=require("@univerjs/docs-drawing"),j=require("@univerjs/drawing"),ge=require("@univerjs/drawing-ui"),k=require("@univerjs/engine-render"),m=require("@univerjs/sheets-drawing"),q=require("@univerjs/design"),E=require("@univerjs/sheets-ui"),W=require("@univerjs/ui"),P=require("rxjs"),y=require("@univerjs/sheets"),Ze=require("@univerjs/docs-ui"),z=require("react/jsx-runtime"),ie=require("react"),$t="sheets-drawing-ui.config",Mt={},G={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(i,r)=>{const t=i.get(k.IRenderManagerService);return r.forEach(e=>{var n,s;(s=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||s.debounceRefreshControls()}),!0}},ye={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var v,C,R;const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(y.SheetInterceptorService),s=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=[];o.forEach(D=>{const{unitId:T}=D;a.push(T)});const d=s.getBatchRemoveOp(o),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,f=n.onCommandExecute({id:ye.id,params:r}),w={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:p,objects:h,type:m.DrawingApplyType.REMOVE}},S={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:c,objects:h,type:m.DrawingApplyType.INSERT}};return l.sequenceExecute([...(v=f.preRedos)!=null?v:[],w,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=f.preUndos)!=null?C:[],S,...f.undos,{id:G.id,params:a}],redoMutations:[...(R=f.preRedos)!=null?R:[],w,...f.redos,{id:G.id,params:a}]}),!0):!1}},Et="COMPONENT_SHEET_DRAWING_PANEL",gt={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{const t=i.get(W.ISidebarService),e=i.get(l.LocaleService),n=i.get(l.IUniverInstanceService),s=i.get(l.ICommandService);if(!y.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Et},onClose:()=>{s.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},ht={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(i,r)=>{const t=i.get(l.ICommandService);return r==null?!1:(t.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[r]),t.executeCommand(gt.id,{value:"open"}),!0)}};var Gt=Object.getOwnPropertyDescriptor,Ht=(i,r,t,e)=>{for(var n=e>1?void 0:e?Gt(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},se=(i,r)=>(t,e)=>r(t,e,i);let qe=class extends l.RxDisposable{constructor(r,t,e,n,s,o,a,d,g,u){super();te(this,"_initImagePopupMenu",new Set);this._injector=r,this._localeService=t,this._drawingManagerService=e,this._canvasPopManagerService=n,this._renderManagerService=s,this._univerInstanceService=o,this._messageService=a,this._contextService=d,this._ioService=g,this._commandService=u,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(P.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(P.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._setupLoadingStatus()}_setupLoadingStatus(){const r="image-upload-loading";let t;this.disposeWithMe(this._ioService.change$.subscribe(e=>{e>0&&!t?t=this._messageService.show({id:r,type:q.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 s;const t=(s=this._renderManagerService.getRenderById(r))==null?void 0:s.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const o=e.getSelectedObjectMap();if(o.size>1){n==null||n.dispose();return}const a=o.values().next().value;if(!a)return;const d=a.oKey,g=this._drawingManagerService.getDrawingOKey(d);if(!g)return;const{unitId:u,subUnitId:c,drawingId:p,drawingType:h}=g,f=g.data;if(f&&f.disablePopup)return;n==null||n.dispose();const w=this._canvasPopManagerService.getFeatureMenu(u,c,p,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:ge.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:w||this._getImageMenuItems(u,c,p,h)}}))})),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(o=>{o[l.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:ht.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ye.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===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ge.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===l.DrawingTypeEnum.DRAWING_DOM}]}};qe=Ht([se(0,l.Inject(l.Injector)),se(1,l.Inject(l.LocaleService)),se(2,j.IDrawingManagerService),se(3,l.Inject(E.SheetCanvasPopManagerService)),se(4,k.IRenderManagerService),se(5,l.IUniverInstanceService),se(6,W.IMessageService),se(7,l.IContextService),se(8,l.IImageIoService),se(9,l.ICommandService)],qe);var Vt=Object.getOwnPropertyDescriptor,Xt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Vt(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Ve=(i,r)=>(t,e)=>r(t,e,i);let ct=class extends l.Disposable{constructor(r,t,e,n,s){super();te(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=t,this._selectionsService=e,this._drawingRenderService=n,this._sheetSkeletonManagerService=s,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(k.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}}))}};ct=Xt([Ve(1,l.Inject(E.HoverManagerService)),Ve(2,l.Inject(y.SheetsSelectionsService)),Ve(3,l.Inject(ge.DrawingRenderService)),Ve(4,l.Inject(E.SheetSkeletonManagerService))],ct);function K(i,r,t){const{from:e,to:n,flipY:s=!1,flipX:o=!1,angle:a=0,skewX:d=0,skewY:g=0}=i,u=t.getCurrent();if(u==null)return;const c=E.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:p,top:h,width:f,height:w}=c;const S=t.getCurrentSkeleton(),_=S.rowHeaderWidth+S.columnTotalWidth,v=S.columnHeaderHeight+S.rowTotalHeight;return p+f>_&&(p=_-f),h+w>v&&(h=v-w),{flipY:s,flipX:o,angle:a,skewX:d,skewY:g,left:p,top:h,width:f,height:w}}function $(i,r){const{left:t=0,top:e=0,width:n=0,height:s=0,flipY:o=!1,flipX:a=!1,angle:d=0,skewX:g=0,skewY:u=0}=i,c=r.getCellWithCoordByOffset(t,e);if(c==null)return;const p={column:c.actualColumn,columnOffset:k.precisionTo(t-c.startX,1),row:c.actualRow,rowOffset:k.precisionTo(e-c.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+s);if(h==null)return;const f={column:h.actualColumn,columnOffset:k.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:k.precisionTo(e+s-h.startY,1)};return{flipY:o,flipX:a,angle:d,skewX:g,skewY:u,from:p,to:f}}var Kt=Object.getOwnPropertyDescriptor,zt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Kt(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Xe=(i,r)=>(t,e)=>r(t,e,i);let dt=class extends l.Disposable{constructor(i,r,t,e,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const t=i[r];for(const e in t.data){const n=t.data[e];n.transform=K(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};dt=zt([Xe(1,m.ISheetDrawingService),Xe(2,j.IDrawingManagerService),Xe(3,l.Inject(E.ISheetSelectionRenderService)),Xe(4,l.Inject(E.SheetSkeletonManagerService))],dt);function Zt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:s,subUnitId:o,drawingId:a}=e,d=k.getGroupState(0,0,n.map(c=>c.transform||{})),g=n.map(c=>{const p=c.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:w}=c;return{unitId:h,subUnitId:f,drawingId:w,transform:{...p,left:p.left-d.left,top:p.top-d.top},groupId:a}}),u={unitId:s,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:d};r.push({parent:u,children:g})}),r}function qt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:s,subUnitId:o,drawingId:a,transform:d={width:0,height:0}}=e;if(d==null)return;const g=n.map(c=>{const{transform:p}=c,{unitId:h,subUnitId:f,drawingId:w}=c,S=k.transformObjectOutOfGroup(p||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:f,drawingId:w,transform:S,groupId:void 0}}),u={unitId:s,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const pt={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const s=[];r.forEach(({parent:h,children:f})=>{s.push(h.unitId),f.forEach(w=>{s.push(w.unitId)})});const o=n.getGroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=o;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:qt(c),type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:s}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP}},{id:G.id,params:s}]}),!0):!1}},Ae={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var v,C,R;const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService),s=i.get(y.SheetInterceptorService);if(!r)return!1;const o=r.drawings,a=o.map(D=>D.unitId),d=n.getBatchAddOp(o),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,f=s.onCommandExecute({id:Ae.id,params:r}),w={id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT}},S={id:m.SetDrawingApplyMutation.id,params:{op:c,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(v=f.preRedos)!=null?v:[],w,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=f.preUndos)!=null?C:[],S,...f.undos,{id:G.id,params:a}],redoMutations:[...(R=f.preRedos)!=null?R:[],w,...f.redos,{id:G.id,params:a}]}),!0):!1}},mt={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService);if(!r)return!1;const n=i.get(m.ISheetDrawingService),{unitId:s,subUnitId:o,drawingIds:a,arrangeType:d}=r,g={unitId:s,subUnitId:o,drawingIds:a};let u;if(d===l.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):d===l.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):d===l.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):d===l.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:c,redo:p,undo:h}=u;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:p,unitId:s,subUnitId:o,objects:c,type:m.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:s,subUnitId:o,objects:c,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:s,subUnitId:o,objects:c,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}},Pe={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,o=n.getBatchUpdateOp(s),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=o;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:a,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:g,objects:c,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}]}),!0):!1}},ft={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const s=[];r.forEach(({parent:h,children:f})=>{s.push(h.unitId),f.forEach(w=>{s.push(w.unitId)})});const o=n.getUngroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=o;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:Zt(c),type:m.DrawingApplyType.GROUP}},{id:G.id,params:s}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:s}]}),!0):!1}};var Jt=Object.getOwnPropertyDescriptor,Qt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Jt(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},ne=(i,r)=>(t,e)=>r(t,e,i);function en(i,r,t){const e=t*Math.PI/180,n=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),s=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:s}}function lt(i,r,t,e,n){var v;const{rotatedHeight:s,rotatedWidth:o}=en(t,e,n),d=i.get(k.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const u=(v=d.with(E.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:v.skeleton;if(u==null)return!1;const c=u.getCellByIndex(r.row,r.col),p=c.mergeInfo.endX-c.mergeInfo.startX-2,h=c.mergeInfo.endY-c.mergeInfo.startY-2,f=o/s,S=Math.ceil(Math.min(p,h*f))/o,_=!S||Number.isNaN(S)?.001:S;return{width:t*_,height:e*_}}exports.SheetDrawingUpdateController=class extends l.Disposable{constructor(t,e,n,s,o,a,d,g,u,c,p,h,f){super();te(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=s,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=d,this._drawingManagerService=g,this._contextService=u,this._messageService=c,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:q.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(C){const R=C.message;R===j.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.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:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):R===j.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const n=this._getUnitInfo(),{unitId:s,subUnitId:o}=n,{imageId:a,imageSourceType:d,source:g,base64Cache:u}=e,{width:c,height:p,image:h}=await j.getImageSize(u||""),{width:f,height:w}=this._context.scene;this._imageIoService.addImageSourceCache(g,d,h);let S=1;if(c>j.DRAWING_IMAGE_WIDTH_LIMIT||p>j.DRAWING_IMAGE_HEIGHT_LIMIT){const C=j.DRAWING_IMAGE_WIDTH_LIMIT/c,R=j.DRAWING_IMAGE_HEIGHT_LIMIT/p;S=Math.max(C,R)}const _=this._getImagePosition(c*S,p*S,f,w);if(_==null)return;const v={unitId:s,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:d,source:g,transform:K(_,this._selectionRenderService,this._skeletonManagerService),sheetTransform:_};return this._commandService.executeCommand(Ae.id,{unitId:s,drawings:[v]})}async _insertCellImage(t,e){var v,C;let n;try{n=await this._imageIoService.saveImage(t)}catch(R){const D=R.message;D===j.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(j.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):D===j.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):D===j.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:s,imageSourceType:o,source:a,base64Cache:d}=n,{width:g,height:u,image:c}=await j.getImageSize(d||"");this._imageIoService.addImageSourceCache(a,o,c);const p=this._workbookSelections.getCurrentLastSelection();if(!p)return!1;const h=l.createDocumentModelWithStyle("",{}),f=lt(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 w={size:{width:f.width,height:f.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},S={unitId:h.getUnitId(),subUnitId:h.getUnitId(),drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:o,source:a,transform:Ze.docDrawingPositionToTransform(w),docTransform:w,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},_=l.BuildTextUtils.drawing.add({documentDataModel:h,drawings:[S],selection:{collapsed:!0,startOffset:0,endOffset:0}});return _?(h.apply(_),this._commandService.syncExecuteCommand(y.SetRangeValuesCommand.id,{value:{[(v=e==null?void 0:e.row)!=null?v:p.primary.actualRow]:{[(C=e==null?void 0:e.col)!=null?C: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:s,image:o}=await j.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,l.ImageSourceType.URL,o);const a=this._workbookSelections.getCurrentLastSelection();if(!a)return!1;const d=l.createDocumentModelWithStyle("",{}),g=lt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:a.primary.actualRow,col:a.primary.actualColumn},n,s,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},c={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:t,transform:Ze.docDrawingPositionToTransform(u),docTransform:u,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},p=l.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[c],selection:{collapsed:!0,startOffset:0,endOffset:0}});return p?(d.apply(p),this._commandService.syncExecuteCommand(y.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:d.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(),s=e.getSheetId();return{unitId:n,subUnitId:s}}_getImagePosition(t,e,n,s){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const d=E.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(d==null)return;let{startColumn:g,startRow:u,startX:c,startY:p}=d,h=!1;if(c+t>n&&(c=n-t,c<0&&(c=0,t=n),h=!0),p+e>s&&(p=s-e,p<0&&(p=0,e=s),h=!0),h){const _=this._selectionRenderService.getCellWithCoordByOffset(c,p);if(_==null)return;c=_.startX,p=_.startY,g=_.actualColumn,u=_.actualRow}const f={column:g,columnOffset:0,row:u,rowOffset:0},w=this._selectionRenderService.getCellWithCoordByOffset(c+t,p+e);if(w==null)return;const S={column:w.actualColumn,columnOffset:c+t-w.startX,row:w.actualRow,rowOffset:p+e-w.startY};return{from:f,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:s,arrangeType:o}=t;this._commandService.executeCommand(mt.id,{unitId:e,subUnitId:n,drawingIds:s,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:s,subUnitId:o,drawingId:a,drawingType:d,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:s,subUnitId:o,drawingId:a});if(u==null||u.unitId!==this._context.unitId)return;const c=$({...u.transform,...g},this._selectionRenderService);if(c==null)return;const p={...n,transform:{...u.transform,...g,...K(c,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...c}};e.push(p)}),e.length>0&&this._commandService.executeCommand(Pe.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(pt.id,t);const{unitId:e,subUnitId:n,drawingId:s}=t[0].parent;this._commandService.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:s}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(ft.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}};exports.SheetDrawingUpdateController=Qt([ne(1,l.Inject(E.SheetSkeletonManagerService)),ne(2,l.ICommandService),ne(3,E.ISheetSelectionRenderService),ne(4,j.IImageIoService),ne(5,W.ILocalFileService),ne(6,m.ISheetDrawingService),ne(7,j.IDrawingManagerService),ne(8,l.IContextService),ne(9,W.IMessageService),ne(10,l.Inject(l.LocaleService)),ne(11,l.Inject(y.SheetsSelectionsService)),ne(12,l.Inject(l.Injector))],exports.SheetDrawingUpdateController);var tn=Object.getOwnPropertyDescriptor,nn=(i,r,t,e)=>{for(var n=e>1?void 0:e?tn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Ie=(i,r)=>(t,e)=>r(t,e,i);function Ot(i,r,t){var e,n,s,o;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((o=(s=t.p)==null?void 0:s.drawingsOrder)==null?void 0:o.length)===1){const a=t.p.drawings[t.p.drawingsOrder[0]],d=lt(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},a.docTransform.size.width,a.docTransform.size.height,a.docTransform.angle);if(d)return a.transform.width=d.width,a.transform.height=d.height,a.docTransform.size.width=d.width,a.docTransform.size.height=d.height,a.transform.left=0,a.transform.top=0,a.docTransform.positionH.posOffset=0,a.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let Je=class extends l.Disposable{constructor(i,r,t,e,n,s){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=s,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===Ze.ReplaceSnapshotCommand.id&&i.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(y.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:y.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,t)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0},Ot(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),t(i)}}))}};Je=nn([Ie(0,l.ICommandService),Ie(1,l.Inject(y.SheetInterceptorService)),Ie(2,l.Inject(l.Injector)),Ie(3,j.IDrawingManagerService),Ie(4,l.Inject(bt.DocDrawingController)),Ie(5,l.Inject(E.IEditorBridgeService))],Je);var rn=Object.getOwnPropertyDescriptor,sn=(i,r,t,e)=>{for(var n=e>1?void 0:e?rn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Tt=(i,r)=>(t,e)=>r(t,e,i);let Qe=class extends l.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,t,e)=>{new l.ObjectMatrix(e).forValue((n,s,o)=>{Ot(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:s},o)})}}))}};Qe=sn([Tt(0,l.Inject(E.IAutoFillService)),Tt(1,l.Inject(l.Injector))],Qe);var on=Object.getOwnPropertyDescriptor,an=(i,r,t,e)=>{for(var n=e>1?void 0:e?on(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},be=(i,r)=>(t,e)=>r(t,e,i);const cn=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,l.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let et=class extends l.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=l.createDocumentModelWithStyle("",{}),t=(n=k.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(E.EditingRenderController),e=l.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===Ze.InnerPasteCommand.id){const e=i.params,{doc:n}=e,s=this._univerInstanceService.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_DOC);if(s==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const o=s.getUnitId();if(cn.includes(o)){if(o!==l.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const a=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(E.SetCellEditVisibleOperation.id,{visible:!1})};((t=s.getBody())==null?void 0:t.dataStream)===`\r
2
- `?(this._commandService.syncExecuteCommand(E.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")}}}))}};et=an([be(0,l.ICommandService),be(1,l.IUniverInstanceService),be(2,W.IDialogService),be(3,k.IRenderManagerService),be(4,l.Inject(l.LocaleService))],et);const Ne={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{var o,a;const t=i.get(l.IUniverInstanceService),e=i.get(k.IRenderManagerService),n=(o=k.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:o.with(exports.SheetDrawingUpdateController);if(!n)return!1;const s=r==null?void 0:r.files;if(s){const d=s.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(d)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},wt={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:i=>{var e,n;const r=i.get(l.IUniverInstanceService),t=i.get(k.IRenderManagerService);return(n=(e=k.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,r,t))==null?void 0:e.with(exports.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}};var dn=Object.getOwnPropertyDescriptor,ln=(i,r,t,e)=>{for(var n=e>1?void 0:e?dn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Ee=(i,r)=>(t,e)=>r(t,e,i);const Ut="image/png";function un(i){const r=i.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);return new Blob([n],{type:Ut})}function gn(i){const r=new ClipboardItem({[Ut]:un(i)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function hn(){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=[E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let tt=class extends l.Disposable{constructor(r,t,e,n,s){super();te(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=s,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const s=this._focusedDrawings;if(s.length>0){const[o]=s;if(n===E.COPY_TYPE.CUT){const d={unitId:r,drawings:[o]};this._commandService.executeCommand(ye.id,d)}setTimeout(()=>{const d=hn();o.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&o.imageSourceType===j.ImageSourceType.BASE64?gn(o.source):this._clipboardInterfaceService.writeText(""),d()},200);const a={unitId:o.unitId,subUnitId:o.subUnitId,drawings:[o]};this._copyInfo=a}else{const o=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=o}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:s=E.COPY_TYPE.COPY,pasteType:o}=n,{range:a}=r||{},{range:d,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:o,unitId:g,subUnitId:u,pasteRange:d},{copyRange:a,copyType:s}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:o},E.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:E.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},E.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:E.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},E.COPY_TYPE.COPY);{const e=t.filter(n=>n.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Ne.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(E.SheetSkeletonManagerService);if(!n)return;const s=n.attachRangeWithCoord(e);if(!s)return;const{startX:o,endX:a,startY:d,endY:g}=s,u=this._drawingService.getDrawingData(r,t),c=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const f=u[h],{transform:w}=f;if(f.anchorType!==m.SheetDrawingAnchorType.Both||!w)return;const{left:S=0,top:_=0,width:v=0,height:C=0}=w,{drawingStartX:R,drawingEndX:D,drawingStartY:T,drawingEndY:I}={drawingStartX:S,drawingEndX:S+v,drawingStartY:_,drawingEndY:_+C};o<=R&&D<=a&&d<=T&&I<=g&&c.push(f)}),c.length)return{copyRange:e,drawings:c,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Rt.includes(e))return{redos:[],undos:[]};const{unitId:s,subUnitId:o,range:a}=n,d=this._renderManagerService.getRenderById(s),g=d==null?void 0:d.with(E.SheetSkeletonManagerService),u=d==null?void 0:d.with(E.ISheetSelectionRenderService),c=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:p}=c,h=E.discreteRangeToRange(a);return this._generateMutations(p,{unitId:s,subUnitId:o,isCut:t===E.COPY_TYPE.CUT,getTransform:(f,w)=>{var v;const S=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),_={...f,left:S==null?void 0:S.startX,top:S==null?void 0:S.startY};return{transform:_,sheetTransform:(v=$(_,u))!=null?v:w}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:s,isCut:o}=t,a=[],d=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:c,sheetTransform:p}=u;if(!c)return;const h=s(c,p),f={...u,unitId:e,subUnitId:n,drawingId:o?u.drawingId:l.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(o){const{undo:w,redo:S,objects:_}=g.getBatchUpdateOp([f]);a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:S,objects:_}}),d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:w,objects:_}})}else{const{undo:w,redo:S,objects:_}=g.getBatchAddOp([f]);a.push({id:m.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.INSERT}}),d.push({id:m.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.REMOVE}})}}),{redos:a,undos:d}}_generateRangeDrawingsPasteMutations(r,t){var U;const{unitId:e,subUnitId:n,pasteType:s,pasteRange:o}=r,{copyRange:a,copyType:d}=t;if(Rt.includes(s))return{redos:[],undos:[]};const g=(U=this._renderManagerService.getRenderById(e))==null?void 0:U.with(E.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:E.discreteRangeToRange(o)},pasteType:s},d);const{ranges:[c,p],mapFunc:h}=E.virtualizeDiscreteRanges([a,o]),{row:f,col:w}=h(c.startRow,c.startColumn),{row:S,col:_}=h(p.startRow,p.startColumn),v=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:w,endColumn:w}),C=g.attachRangeWithCoord({startRow:S,endRow:S,startColumn:_,endColumn:_});if(!v||!C||!this._copyInfo)return{redos:[],undos:[]};const R=C.startX-v.startX,D=C.startY-v.startY,T=S-f,I=_-w;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(b,A)=>{var N,O;return{transform:{...b,left:((N=b==null?void 0:b.left)!=null?N:0)+R,top:((O=b==null?void 0:b.top)!=null?O:0)+D},sheetTransform:{...A,to:{...A.to,row:A.to.row+T,column:A.to.column+I},from:{...A.from,row:A.from.row+T,column:A.from.column+I}}}},isCut:d===E.COPY_TYPE.CUT})}};tt=ln([Ee(0,E.ISheetClipboardService),Ee(1,k.IRenderManagerService),Ee(2,j.IDrawingManagerService),Ee(3,W.IClipboardInterfaceService),Ee(4,l.ICommandService)],tt);var pn=Object.getOwnPropertyDescriptor,mn=(i,r,t,e)=>{for(var n=e>1?void 0:e?pn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Oe=(i,r)=>(t,e)=>r(t,e,i);let nt=class extends l.Disposable{constructor(i,r,t,e,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=P.combineLatest([i,r]);this.disposeWithMe(t.pipe(P.switchMap(([e,n])=>e?e.activeSheet$.pipe(P.tap(s=>{if(!s){this._drawingManagerService.setDrawingVisible(!1);return}const o=e.getUnitId(),a=s.getSheetId();this._permissionService.composePermission([new y.WorkbookViewPermission(o).id,new y.WorksheetViewPermission(o,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,s)})):(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),s=Object.values(n),o=this._renderManagerService.getRenderById(t),a=o==null?void 0:o.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===k.RENDER_CLASS_TYPE.IMAGE&&s.some(u=>g.oKey.includes(u.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=P.combineLatest([i,r]);this.disposeWithMe(t.pipe(P.switchMap(([e,n])=>e?e.activeSheet$.pipe(P.tap(s=>{if(!s){this._drawingManagerService.setDrawingEditable(!1);return}const o=e.getUnitId(),a=s.getSheetId();this._permissionService.composePermission([new y.WorkbookEditablePermission(o).id,new y.WorksheetEditPermission(o,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,s)})):(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),s=Object.values(n),o=this._renderManagerService.getRenderById(t),a=o==null?void 0:o.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===k.RENDER_CLASS_TYPE.IMAGE&&s.some(u=>g.oKey.includes(u.drawingId))&&a.detachTransformerFrom(g)})}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(P.combineLatest([i,r]).pipe(P.switchMap(([t,e])=>t?t.activeSheet$.pipe(P.switchMap(n=>{if(!n)return P.EMPTY;const s=t.getUnitId(),o=n.getSheetId(),a=this._renderManagerService.getRenderById(s),d=a==null?void 0:a.scene;if(!d)return P.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookViewPermission(s).id,new y.WorksheetViewPermission(s,o).id]).pipe(P.map(c=>c.every(p=>p.value)),P.distinctUntilChanged()).pipe(P.map(c=>({permission:c,scene:d,transformer:g,unitId:s,subUnitId:o})))})):P.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:s,subUnitId:o})=>{this._drawingManagerService.setDrawingVisible(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(s,o),g=Object.values(d);t?this._drawingManagerService.addNotification(g):(a.forEach(u=>{u.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),s=e==null?void 0:e.getSheetId();if(!n||!s)return;const o=this._drawingManagerService.getDrawingData(n,s),a=Object.values(o);this._drawingManagerService.addNotification(a)}}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.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 s=t.getUnitId(),o=n.getSheetId(),a=this._renderManagerService.getRenderById(s),d=a==null?void 0:a.scene;if(!d)return P.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookEditablePermission(s).id,new y.WorksheetEditPermission(s,o).id]).pipe(P.map(c=>c.every(p=>p.value)),P.distinctUntilChanged()).pipe(P.map(c=>({permission:c,scene:d,transformer:g,unitId:s,subUnitId:o})))})):P.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:s,subUnitId:o})=>{this._drawingManagerService.setDrawingEditable(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(s,o),g=Object.values(d);t?(a.forEach(u=>{u.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(a.forEach(u=>{u.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const s=n.getSheetId(),o=this._renderManagerService.getRenderById(e),a=o==null?void 0:o.scene;if(!a)return;const d=this._drawingManagerService.getDrawingData(e,s),g=Object.values(d);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(c=>{c.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(p=>c.oKey.includes(p.drawingId))&&a.detachTransformerFrom(c)})}}))}};nt=mn([Oe(0,j.IDrawingManagerService),Oe(1,k.IRenderManagerService),Oe(2,l.IPermissionService),Oe(3,l.IUniverInstanceService),Oe(4,l.Inject(l.UserManagerService))],nt);var fn=Object.getOwnPropertyDescriptor,wn=(i,r,t,e)=>{for(var n=e>1?void 0:e?fn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},he=(i,r)=>(t,e)=>r(t,e,i);function At(i,r,t,e,n,s=!1){const{scaleX:o,scaleY:a}=r.getAncestorScale(),d=r.getViewport(k.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=e.getFreeze(),{startColumn:u,startRow:c,xSplit:p,ySplit:h}=g,f={left:!0,top:!0};if(!d)return{...i,absolute:f};const{left:w,right:S,top:_,bottom:v}=i;let{top:C,left:R,viewportScrollX:D,viewportScrollY:T}=d;const{boundsOfViewArea:I,scrollDirectionResponse:U}=n||{},{rowHeaderWidth:b,columnHeaderHeight:A}=t,N={top:s?0:A,left:s?0:b};I&&(l.Tools.isDefine(N.top)&&(N.top=I.top),l.Tools.isDefine(N.left)&&(N.left=I.left)),U==="HORIZONTAL"&&(T=0),U==="VERTICAL"&&(D=0);let O=0,M=0;const B=t.rowStartY(c-h)+A,L=t.colStartX(u-p)+b,Z=t.rowStartY(c)+A,J=t.colStartX(u)+b;if(p===0)f.left=!1,O=(w-D)*o,M=(S-D)*o;else{const V=w-(L-b),x=S-(L-b);S<J?(O=V*o,M=x*o):w<=J&&S>=J?(O=V*o,M=Math.max(R,(S-D)*o)):w>J&&(f.left=!1,O=Math.max((w-D)*o,R),M=Math.max((S-D)*o,R))}let H=0,X=0;if(h===0)f.top=!1,H=(_-T)*a,X=(v-T)*a;else{const V=_-(B-A),x=v-(B-A);v<Z?(H=V*a,X=x*a):_<=Z&&v>=Z?(H=V*a,X=Math.max(C,(v-T)*a)):_>Z&&(f.top=!1,H=Math.max((_-T)*a,C),X=Math.max((v-T)*a,C))}return O=Math.max(O,N.left),H=Math.max(H,N.top),M=Math.max(M,N.left),X=Math.max(X,N.top),{left:O,right:M,top:H,bottom:X,absolute:f}}const le=(i,r,t,e,n)=>{const{left:s,top:o,width:a,height:d,angle:g}=i,u={left:s,right:s+a,top:o,bottom:o+d},c=At(u,r,t,e,n),{scaleX:p,scaleY:h}=r.getAncestorScale();return{startX:c.left,endX:c.right,startY:c.top,endY:c.bottom,rotate:g,width:a*p,height:d*h,absolute:c.absolute}};exports.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(t,e,n,s,o,a,d){super();te(this,"_domLayerInfoMap",new Map);te(this,"_transformChange$",new P.Subject);te(this,"transformChange$",this._transformChange$.asObservable());te(this,"_add$",new P.Subject);te(this,"add$",this._add$.asObservable());te(this,"_remove$",new P.Subject);te(this,"remove$",this._remove$.asObservable());this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=s,this._canvasFloatDomService=o,this._sheetDrawingService=a,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(P.filter(t=>t===l.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 s=n.getTransformerByCreate(),o=e.engine.getCanvasElement();return{scene:n,transformer:s,renderUnit:e,canvas:o}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var V;const{unitId:n,subUnitId:s,drawingId:o}=e,a=y.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:s}),d=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!d||!a)return;const c=(V=this._renderManagerService.getRenderById(n))==null?void 0:V.with(E.SheetSkeletonManagerService).getSkeletonParam(s);if(!c)return;const{transform:p,drawingType:h,data:f}=d;if(h!==l.DrawingTypeEnum.DRAWING_DOM&&h!==l.DrawingTypeEnum.DRAWING_CHART)return;const w=this._getSceneAndTransformerByDrawingSearch(n);if(w==null)return;const{scene:S,canvas:_}=w;if(p==null)return!0;if(u!==s)return;const{left:v,top:C,width:R,height:D,angle:T,flipX:I,flipY:U,skewX:b,skewY:A}=p,N=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:s,drawingId:o}),O=S.getObject(N);if(O!=null){O.transformByState({left:v,top:C,width:R,height:D,angle:T,flipX:I,flipY:U,skewX:b,skewY:A});return}const M={left:v,top:C,width:R,height:D,zIndex:this._drawingManagerService.getDrawingOrder(n,s).length-1},B=h===l.DrawingTypeEnum.DRAWING_CHART;if(M.rotateEnabled=!1,B){const x=f?f.backgroundColor:"white";M.fill=x,f&&f.border&&(M.stroke=f.border),M.paintFirst="stroke",M.strokeWidth=1,M.borderEnabled=!1,M.radius=8}const L=new k.Rect(N,M);B&&L.setObjectType(k.ObjectType.CHART),S.addObject(L,k.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo(L);const Z=new l.DisposableCollection,J=le(L,w.renderUnit.scene,c.skeleton,a.worksheet),H=new P.BehaviorSubject(J),X={dispose:Z,rect:L,position$:H,unitId:n,subUnitId:s,id:o};this._canvasFloatDomService.addFloatDom({position$:H,id:o,componentKey:d.componentKey,onPointerDown:x=>{_.dispatchEvent(new PointerEvent(x.type,x))},onPointerMove:x=>{_.dispatchEvent(new PointerEvent(x.type,x))},onPointerUp:x=>{_.dispatchEvent(new PointerEvent(x.type,x))},onWheel:x=>{_.dispatchEvent(new WheelEvent(x.type,x))},data:f,unitId:n});const Q=L.onTransformChange$.subscribeEvent(()=>{const x=le(L,w.renderUnit.scene,c.skeleton,a.worksheet);H.next(x)});Z.add(()=>{this._canvasFloatDomService.removeFloatDom(o)}),Q&&Z.add(Q),this._domLayerInfoMap.set(o,X)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{var p;const{unitId:n,subUnitId:s,drawingId:o}=e,a=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:s,drawingId:o}),d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{transformer:g,scene:u}=d,c=u.getObject(a);c!=null&&c.oKey&&(g.clearControlByIds([c==null?void 0:c.oKey]),(p=u.getTransformer())==null||p.clearSelectedObjects())})}))}_scrollUpdateListener(){const t=(e,n)=>{var g;const s=this._getSceneAndTransformerByDrawingSearch(e),o=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=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(E.SheetSkeletonManagerService).getSkeletonParam(n);!s||!a||!d||o.forEach(u=>{const c=this._domLayerInfoMap.get(u);if(c){const p=le(c.rect,s.renderUnit.scene,d.skeleton,a.worksheet,c);c.position$.next(p)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(P.switchMap(e=>e?e.activeSheet$:P.of(null)),P.map(e=>{if(!e)return null;const n=e.getUnitId(),s=this._renderManagerService.getRenderById(n);return s?{render:s,unitId:n,subUnitId:e.getSheetId()}:null}),P.switchMap(e=>e?l.fromEventSubject(e.render.scene.getViewport(k.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:s}=e;t(n,s)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===E.SetZoomRatioOperation.id){const n=e.params,{unitId:s}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===s).map(a=>a.subUnitId).forEach(a=>{t(s,a)})}else if(e.id===y.SetFrozenMutation.id){const{unitId:n,subUnitId:s}=e.params;t(n,s)}}))}_getPosition(t,e){var h;const{startX:n,endX:s,startY:o,endY:a}=t,d=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(E.ISheetSelectionRenderService);if(d==null)return;const g=d.getCellWithCoordByOffset(n,o);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:o-g.startY},c=d.getCellWithCoordByOffset(s,a);if(c==null)return;const p={column:c.actualColumn,columnOffset:s-c.startX,row:c.actualRow,rowOffset:a-c.startY};return{from:u,to:p}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const s={...n.transform};this._transformChange$.next({id:e.drawingId,value:s})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,s){const o=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(t);if(o&&a){const{scene:d}=a,g=j.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=d.getObject(g);u&&u instanceof k.Rect&&u.setProps(s)}}addFloatDomToPosition(t,e){const n=y.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:s,subUnitId:o}=n,{initPosition:a,componentKey:d,data:g,allowTransform:u=!0}=t,c=e!=null?e:l.generateRandomId(),p=this._getPosition(a,s);if(p==null)return;const h={unitId:s,subUnitId:o,drawingId:c,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:p,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Ae.id,{unitId:s,drawings:[h]}),this._add$.next({unitId:s,subUnitId:o,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:s,subUnitId:o}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(s);if(a&&a.scene.removeObject(n.rect),e){const d=this._drawingManagerService.getDrawingByParam({unitId:s,subUnitId:o,drawingId:t});if(!d)return;const g=this._sheetDrawingService.getBatchRemoveOp([d]),{redo:u,objects:c}=g;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:s,subUnitId:o,op:u,objects:c,type:m.DrawingApplyType.REMOVE})}}addFloatDomToRange(t,e,n,s){var I,U,b;const o=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!o)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=o,g=this._getSceneAndTransformerByDrawingSearch(a);if(!g)return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(I=this._renderManagerService.getRenderById(a))==null?void 0:I.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,w=s!=null?s:l.generateRandomId(),{position:S,position$:_}=this._createRangePositionObserver(t,u,c.skeleton);if(this._getPosition(S,a)==null)return;const C=g.scene,{scaleX:R}=C.getAncestorScale(),D=Ke(S,n,R),T={unitId:a,subUnitId:d,drawingId:w,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:D.startX,top:D.startY,width:D.width,height:D.height},data:h,allowTransform:f};{const{unitId:A,subUnitId:N,drawingId:O}=T,M=y.getSheetCommandTarget(this._univerInstanceService,{unitId:A,subUnitId:N}),B=T,L=this._univerInstanceService.getUnit(A,l.UniverInstanceType.UNIVER_SHEET);if(!L)return;const Z=L.getActiveSheet().getSheetId();if(!B||!M)return;const J=(U=this._renderManagerService.getRenderById(A))==null?void 0:U.with(E.SheetSkeletonManagerService);if(!J)return;const H=J.getWorksheetSkeleton(N);if(!H)return;const{transform:X,drawingType:Q,data:V}=B;if(Q!==l.DrawingTypeEnum.DRAWING_DOM&&Q!==l.DrawingTypeEnum.DRAWING_CHART)return;const x=this._getSceneAndTransformerByDrawingSearch(A);if(x==null)return;const{scene:me,canvas:fe}=x;if(X==null||Z!==N)return;const{left:ke,top:We,width:Be,height:xe,angle:st,flipX:ot,flipY:Ye,skewX:Le,skewY:we}=X,Fe=j.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:N,drawingId:O}),oe=me.getObject(Fe);if(oe!=null){oe.transformByState({left:ke,top:We,width:Be,height:xe,angle:st,flipX:ot,flipY:Ye,skewX:Le,skewY:we});return}const ee={left:ke,top:We,width:Be,height:xe,zIndex:this._drawingManagerService.getDrawingOrder(A,N).length-1},Se=Q===l.DrawingTypeEnum.DRAWING_CHART;if(Se){const Y=V?V.backgroundColor:"white";ee.fill=Y,ee.rotateEnabled=!1,V&&V.border&&(ee.stroke=V.border),ee.paintFirst="stroke",ee.strokeWidth=1,ee.borderEnabled=!1,ee.radius=8}const ae=new k.Rect(Fe,ee);Se&&ae.setObjectType(k.ObjectType.CHART),me.addObject(ae,k.DRAWING_OBJECT_LAYER_INDEX),B.allowTransform!==!1&&me.attachTransformerTo(ae);const ce=new l.DisposableCollection,$e=me.getMainViewport(),{rowHeaderWidth:_e,columnHeaderHeight:Me}=H.skeleton,Ge={top:Me,left:_e,bottom:$e.bottom,right:$e.right},de={dispose:ce,rect:ae,boundsOfViewArea:Ge,domAnchor:n,unitId:A,subUnitId:N},F=le(ae,x.renderUnit.scene,H.skeleton,M.worksheet,de),ve=new P.BehaviorSubject(F);de.position$=ve;let Te={position$:ve,id:O,componentKey:B.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:Y=>{fe.dispatchEvent(new WheelEvent(Y.type,Y))},data:V,unitId:A};e.eventPassThrough&&(Te={...Te,onPointerDown:Y=>{fe.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{fe.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{fe.dispatchEvent(new PointerEvent(Y.type,Y))}}),this._canvasFloatDomService.addFloatDom(Te),this.disposeWithMe(_.subscribe(Y=>{var It,Dt,yt,Ct;const vt=Ke({startX:Y.startX,startY:Y.startY,endX:Y.endX,endY:Y.endY,width:(It=n.width)!=null?It:Y.width,height:(Dt=n.height)!=null?Dt:Y.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Bt=j.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:N,drawingId:O}),xt=new k.Rect(Bt,{left:vt.startX,top:vt.startY,width:(yt=n.width)!=null?yt:Y.width,height:(Ct=n.height)!=null?Ct:Y.height,zIndex:this._drawingManagerService.getDrawingOrder(A,N).length-1}),Yt=le(xt,x.renderUnit.scene,H.skeleton,M.worksheet,de);ve.next(Yt)}));const Re=(b=this._renderManagerService.getRenderById(A))==null?void 0:b.with(E.SheetSkeletonManagerService);Re==null||Re.currentSkeleton$.subscribe(Y=>{Y&&H.sheetId!==Y.sheetId&&this._removeDom(w,!0)});const He=ae.onTransformChange$.subscribeEvent(()=>{const Y=le(ae,x.renderUnit.scene,H.skeleton,M.worksheet,de);ve.next(Y)});ce.add(()=>{this._canvasFloatDomService.removeFloatDom(O)}),He&&ce.add(He),this._domLayerInfoMap.set(O,de)}return{id:w,dispose:()=>{this._removeDom(w,!0)}}}addFloatDomToColumnHeader(t,e,n,s){var D,T,I;const o=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!o)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=o;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(D=this._renderManagerService.getRenderById(a))==null?void 0:D.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,w=s!=null?s:l.generateRandomId(),{position:S,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,c.skeleton),v=S;if(v.startY=0,this._getPosition(S,a)==null)return;const R={unitId:a,subUnitId:d,drawingId:w,drawingType:e.type||l.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:b,drawingId:A}=R,N=y.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:b}),O=R,M=this._univerInstanceService.getUnit(U,l.UniverInstanceType.UNIVER_SHEET);if(!M)return;const B=M.getActiveSheet().getSheetId();if(!O||!N)return;const L=(T=this._renderManagerService.getRenderById(U))==null?void 0:T.with(E.SheetSkeletonManagerService);if(!L)return;const Z=L.getWorksheetSkeleton(b);if(!Z)return;const{transform:J,data:H}=O,X=this._getSceneAndTransformerByDrawingSearch(U);if(X==null)return;const{scene:Q,canvas:V}=X;if(J==null||B!==b)return;const{left:x,top:me,width:fe,height:ke,angle:We,flipX:Be,flipY:xe,skewX:st,skewY:ot}=J,Ye=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:b,drawingId:A}),Le=Q.getObject(Ye);if(Le!=null){Le.transformByState({left:x,top:me,width:fe,height:ke,angle:We,flipX:Be,flipY:xe,skewX:st,skewY:ot});return}const we=Ke({startX:v.startX,startY:0,endX:S.endX,endY:S.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Fe={left:we.startX,top:we.startY,width:we.width,height:we.height,zIndex:this._drawingManagerService.getDrawingOrder(U,b).length-1},oe=new k.Rect(Ye,Fe);Q.addObject(oe,k.DRAWING_OBJECT_LAYER_INDEX),O.allowTransform!==!1&&Q.attachTransformerTo(oe);const ee=new l.DisposableCollection,Se=Q.getMainViewport(),ae={top:0,left:Se.left,bottom:Se.bottom,right:Se.right},ce={dispose:ee,rect:oe,unitId:U,subUnitId:b,boundsOfViewArea:ae,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},$e=le(oe,X.renderUnit.scene,Z.skeleton,N.worksheet,ce),_e=new P.BehaviorSubject($e);ce.position$=_e;let Me={position$:_e,id:A,componentKey:O.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:F=>{V.dispatchEvent(new WheelEvent(F.type,F))},data:H,unitId:U};e.eventPassThrough&&(Me={...Me,onPointerDown:F=>{V.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{V.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{V.dispatchEvent(new PointerEvent(F.type,F))}}),this._canvasFloatDomService.addFloatDom(Me);const Ge=oe.onTransformChange$.subscribeEvent(()=>{const F=le(oe,X.renderUnit.scene,Z.skeleton,N.worksheet,ce);_e.next(F)});this.disposeWithMe(_.subscribe(F=>{const ve=Ke({startX:F.startX,startY:0,endX:F.endX,endY:F.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Te=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:b,drawingId:A}),Re=new k.Rect(Te,{left:ve.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(U,b).length-1}),He=le(Re,X.renderUnit.scene,Z.skeleton,N.worksheet,ce);_e.next(He)}));const de=(I=this._renderManagerService.getRenderById(U))==null?void 0:I.with(E.SheetSkeletonManagerService);de==null||de.currentSkeleton$.subscribe(F=>{F&&c.sheetId!==F.sheetId&&this._removeDom(w,!0)}),ee.add(()=>{this._canvasFloatDomService.removeFloatDom(A)}),Ge&&ee.add(Ge),this._domLayerInfoMap.set(A,ce)}return{id:w,dispose:()=>{this._removeDom(w,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:s,startColumn:o}=t;const a=Ue(s,o,n),d=new P.BehaviorSubject(a),g=Ue(t.endRow,t.endColumn,n),u=new P.BehaviorSubject(g),c=()=>{const _=Ue(s,o,n),v=Ue(t.endRow,t.endColumn,n);d.next(_),u.next(v)},p=new l.DisposableCollection;p.add(e.engine.clientRect$.subscribe(()=>c())),p.add(this._commandService.onCommandExecuted(_=>{if(_.id===y.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(C=>C.row===s)>-1){c();return}(y.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===E.SetScrollOperation.id||_.id===E.SetZoomRatioOperation.id)&&c()}));const h=(_,v)=>{s=_,o=v,c()},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}),w=d.pipe(P.map(_=>{const v=Ue(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}})),S=f();return{position$:w,position:S,updateRowCol:h,topLeftPos$:d,rightBottomPos$:u,disposable:p}}};exports.SheetCanvasFloatDomManagerService=wn([he(0,l.Inject(k.IRenderManagerService)),he(1,l.IUniverInstanceService),he(2,l.Inject(l.ICommandService)),he(3,j.IDrawingManagerService),he(4,l.Inject(W.CanvasFloatDomService)),he(5,m.ISheetDrawingService),he(6,l.Inject(l.LifecycleService))],exports.SheetCanvasFloatDomManagerService);function Ue(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,s=(g=r==null?void 0:r.width)!=null?g:e,o=(u=r==null?void 0:r.height)!=null?u:n;let a=0,d=0;if(r){if(r.horizonOffsetAlign==="right"){const c=ze(r.marginX,e*t);a=i.endX-c-s}else a=i.startX+ze(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const c=ze(r.marginY,n*t);d=i.endY-c-o}else d=i.startY+ze(r.marginY,n)}return{rotate:0,startX:a,startY:d,endX:i.endX,endY:i.endY,width:s,height:o,absolute:{left:i.absolute.left,top:i.absolute.top}}}function ze(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const t=Number.parseFloat(i);return r*t/100}const Sn=i=>{const{floatDomInfos:r,scene:t,skeleton:e,worksheet:n}=i,s=ie.useMemo(()=>r.map(o=>{const{width:a,height:d,angle:g,left:u,top:c}=o.transform,p=At({left:u!=null?u:0,right:(u!=null?u:0)+(a!=null?a:0),top:c!=null?c:0,bottom:(c!=null?c:0)+(d!=null?d:0)},t,e,n,void 0,!0),{scaleX:h,scaleY:f}=t.getAncestorScale(),w={startX:p.left,endX:p.right,startY:p.top,endY:p.bottom,rotate:g,width:a*h,height:d*f,absolute:p.absolute},S={position$:new P.BehaviorSubject(w),position:w,id:o.drawingId,componentKey:o.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:o.unitId,data:o.data};return[o.drawingId,S]}),[r,t,e,n]);return z.jsx("div",{style:{position:"absolute",top:0,left:0},children:s.map(([o,a])=>z.jsx(W.PrintFloatDomSingle,{layer:a,id:o,position:a.position},o))})};var _n=Object.getOwnPropertyDescriptor,vn=(i,r,t,e)=>{for(var n=e>1?void 0:e?_n(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},pe=(i,r)=>(t,e)=>r(t,e,i);let rt=class extends l.Disposable{constructor(i,r,t,e,n,s,o){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._canvasFloatDomManagerService=n,this._componetManager=s,this._injector=o,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:s}=r,o=this._drawingManagerService.getDrawingDataForUnit(e),a=o==null?void 0:o[s];return a&&a.order.forEach(d=>{const g=a.data[d];g.drawingType!==l.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,s=this._renderManagerService.getRenderById(e);if(!s)return t(i);const o=s.with(E.SheetSkeletonManagerService).getSkeletonParam(n);if(!o)return t(i);const a=this._drawingManagerService.getDrawingDataForUnit(e),d=a==null?void 0:a[r.subUnitId];if(!d)return t(i);const{scaleX:g,scaleY:u}=s.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},p=d.order.map(h=>d.data[h]);return p.length?(p.forEach(h=>{if(!h.groupId&&h.transform&&l.Tools.isDefine(h.transform.left)&&l.Tools.isDefine(h.transform.top)&&l.Tools.isDefine(h.transform.width)&&l.Tools.isDefine(h.transform.height)){const f=o.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),w=o.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});f.column<c.startColumn&&(c.startColumn=f.column),f.row<c.startRow&&(c.startRow=f.row),c.endRow<w.row&&(c.endRow=w.row),c.endColumn<w.column&&(c.endColumn=w.column)}}),t(c)):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,s=this._drawingManagerService.getDrawingDataForUnit(e),o=s==null?void 0:s[n];if(o){const a=o.order.map(g=>{const u=o.data[g];if(u.drawingType===l.DrawingTypeEnum.DRAWING_CHART)return{...u,componentKey:this._componetManager.get(l.PRINT_CHART_COMPONENT_KEY)};if(u.drawingType===l.DrawingTypeEnum.DRAWING_DOM){const c=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(c||u.componentKey)}}return null}).filter(Boolean),d=W.connectInjector(Sn,this._injector);return q.render(z.jsx(d,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),i==null||i.add(()=>{q.unmount(r.root)}),t(i)}}}))}};rt=vn([pe(0,l.Inject(E.SheetPrintInterceptorService)),pe(1,l.Inject(ge.DrawingRenderService)),pe(2,j.IDrawingManagerService),pe(3,k.IRenderManagerService),pe(4,l.Inject(exports.SheetCanvasFloatDomManagerService)),pe(5,l.Inject(W.ComponentManager)),pe(6,l.Inject(l.Injector))],rt);var In=Object.getOwnPropertyDescriptor,Dn=(i,r,t,e)=>{for(var n=e>1?void 0:e?In(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},ue=(i,r)=>(t,e)=>r(t,e,i);const yn=[y.InsertRowCommand.id,y.InsertColCommand.id,y.RemoveRowCommand.id,y.RemoveColCommand.id,y.DeleteRangeMoveLeftCommand.id,y.DeleteRangeMoveUpCommand.id,y.InsertRangeMoveDownCommand.id,y.InsertRangeMoveRightCommand.id,y.DeltaRowHeightCommand.id,y.SetRowHeightCommand.id,y.DeltaColumnWidthCommand.id,y.SetColWidthCommand.id,y.SetRowHiddenCommand.id,y.SetSpecificRowsVisibleCommand.id,y.SetSpecificColsVisibleCommand.id,y.SetColHiddenCommand.id,y.MoveColsCommand.id,y.MoveRowsCommand.id,y.MoveRangeCommand.id],Cn=[y.SetRowVisibleMutation.id,y.SetRowHiddenMutation.id,y.SetColVisibleMutation.id,y.SetColHiddenMutation.id,y.SetWorksheetRowHeightMutation.id,y.SetWorksheetColWidthMutation.id];let ut=class extends l.Disposable{constructor(i,r,t,e,n,s,o,a,d){super(),this._context=i,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=s,this._sheetDrawingService=o,this._drawingManagerService=a,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!yn.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===y.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([y.MoveColsCommand.id,y.MoveRowsCommand.id,y.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===y.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===y.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===y.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===y.DeleteRangeMoveLeftCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,0)}else if(r===y.DeleteRangeMoveUpCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,1)}else if(r===y.InsertRangeMoveDownCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,2)}else if(r===y.InsertRangeMoveRightCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,3)}else if(r===y.SetRowHiddenCommand.id||r===y.SetSpecificRowsVisibleCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:s}=t;return this._getDrawingUndoForRowVisible(e,n,s)}else if(r===y.SetSpecificColsVisibleCommand.id||r===y.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:s}=t;return this._getDrawingUndoForColVisible(e,n,s)}else if(r===y.DeltaRowHeightCommand.id||r===y.SetRowHeightCommand.id||r===y.DeltaColumnWidthCommand.id||r===y.SetColWidthCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:s}=t,o=r===y.DeltaRowHeightCommand.id||r===y.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,s,o)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const t=y.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,s=[],o=[],a=this._sheetDrawingService.getDrawingData(e,n),d=[],g=[];if(Object.keys(a).forEach(u=>{const c=a[u],{updateDrawings:p,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,c);d.push(...p),g.push(...h)}),d.length===0&&g.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:p,objects:h}=u;s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.UPDATE}}),o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),c=u.undo,p=u.redo,h=u.objects;s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.REMOVE}}),o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.INSERT}})}return s.push({id:G.id,params:[e]}),o.push({id:G.id,params:[e]}),{redos:s,undos:o}}_getUpdateOrDeleteDrawings(i,r,t){const e=[],n=[],{sheetTransform:s,anchorType:o=m.SheetDrawingAnchorType.Position,transform:a,unitId:d,subUnitId:g,drawingId:u}=t,{from:c,to:p}=s,{row:h,column:f}=c,{row:w,column:S}=p;if(s==null||a==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:_,endRow:v,startColumn:C,endColumn:R}=i;let D=null,T=null;if(r===0&&h>=_&&w<=v)if(f>=C&&S<=R)n.push({unitId:d,subUnitId:g,drawingId:u});else{const I=this._shrinkCol(s,a,C,R,o);D=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===1&&f>=C&&S<=R)if(h>=_&&w<=v)n.push({unitId:d,subUnitId:g,drawingId:u});else{const I=this._shrinkRow(s,a,_,v,o);D=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===2){const I=this._expandRow(s,a,_,v,o);D=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===3){const I=this._expandCol(s,a,C,R,o);D=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}if(D!=null&&T!=null){const I=K(D,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:D,transform:I})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(i,r,t){const e=$({...i},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],s=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=c;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:w,to:S}=p,{row:_,column:v}=w,{row:C,column:R}=S;for(let D=0;D<t.length;D++){const T=t[D],{startRow:I,endRow:U,startColumn:b,endColumn:A}=T;if(R<b)continue;if(f===m.SheetDrawingAnchorType.Position){let M=null,B=null;if(v>=b&&v<=A){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:v,endColumn:A,startRow:w.row,endRow:S.row});if(L==null)return;B={...h,left:L.startX}}if(B!=null&&(M=$(B,this._selectionRenderService),M!=null&&B!=null)){n.push({...c,sheetTransform:M,transform:B});break}this._remainDrawingSize(h,n,c);continue}if(v>=b&&R<=A)continue;let N=null,O=null;if(v>=b&&v<=A){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:v,endColumn:A,startRow:w.row,endRow:S.row});if(M==null)return;O={...h,left:(M==null?void 0:M.startX)||0,width:((h==null?void 0:h.width)||0)-M.endX+M.startX}}else if(R>=b&&R<=A){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:R,startRow:w.row,endRow:S.row});if(M==null)return;O={...h,left:M.startX-((h==null?void 0:h.width)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:A,startRow:w.row,endRow:S.row});if(M==null)return;if(O={...h,width:((h==null?void 0:h.width)||0)-M.endX+M.startX},N=$(O,this._selectionRenderService),N!=null&&O!=null){s.push({...c,sheetTransform:N,transform:O});break}}if(O!=null&&(N=$(O,this._selectionRenderService)),O!=null&&N!=null){n.push({...c,sheetTransform:N,transform:O});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&s.length===0)return{redos:[],undos:[]};const{redos:o,undos:a}=this._createUndoAndRedoMutation(i,r,n),d=[],g=[];if(s.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,s);d.push(...u),g.push(...c)}return{redos:o,undos:a,preRedos:d,preUndos:g}}_createUndoAndRedoMutation(i,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:s,objects:o}=e,a=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:s,objects:o,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],d=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:o,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:a,undos:d}}_getDrawingUndoForRowVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],s=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=c;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:w,to:S}=p,{row:_,column:v}=w,{row:C,column:R}=S;for(let D=0;D<t.length;D++){const T=t[D],{startRow:I,endRow:U,startColumn:b,endColumn:A}=T;if(C<I)continue;if(f===m.SheetDrawingAnchorType.Position){let M=null,B=null;if(_>=I&&_<=U){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:_,endRow:U});if(L==null)return;B={...h,top:L.startY}}if(B!=null&&(M=$(B,this._selectionRenderService),M!=null&&B!=null)){n.push({...c,sheetTransform:M,transform:B});break}this._remainDrawingSize(h,n,c);continue}if(_>=I&&C<=U)continue;let N=null,O=null;if(_>=I&&_<=U){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:_,endRow:U});if(M==null)return;O={...h,top:(M==null?void 0:M.startY)||0,height:((h==null?void 0:h.height)||0)-M.endY+M.startY}}else if(C>=I&&C<=U){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:I,endRow:C});if(M==null)return;O={...h,top:M.startY-((h==null?void 0:h.height)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:I,endRow:U});if(M==null)return;if(O={...h,height:((h==null?void 0:h.height)||0)-M.endY+M.startY},N=$(O,this._selectionRenderService),N!=null&&O!=null){s.push({...c,sheetTransform:N,transform:O});break}}if(O!=null&&(N=$(O,this._selectionRenderService)),O!=null&&N!=null){n.push({...c,sheetTransform:N,transform:O});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&s.length===0)return{redos:[],undos:[]};const{redos:o,undos:a}=this._createUndoAndRedoMutation(i,r,n),d=[],g=[];if(s.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,s);d.push(...u),g.push(...c)}return{redos:o,undos:a,preRedos:d,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,t,e){const n=this._drawingManagerService.getDrawingData(i,r),s=[];return Object.keys(n).forEach(o=>{const a=n[o],{sheetTransform:d,transform:g,anchorType:u=m.SheetDrawingAnchorType.Position}=a;if(u===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,s,a);else{const{from:c,to:p}=d,{row:h,column:f}=c,{row:w,column:S}=p;for(let _=0;_<t.length;_++){const v=t[_],{startRow:C,endRow:R,startColumn:D,endColumn:T}=v;if(w<C||S<D)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=C&&w>=R||f<=D&&S>=T)){this._remainDrawingSize(g,s,a);continue}const I=K({...d},this._selectionRenderService,this._skeletonManagerService);if(I!=null){s.push({...a,transform:I});break}}}}),s.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,s)}_getUnitIdAndSubUnitId(i,r){let t,e;if(r==="insert")t=i.unitId,e=i.subUnitId;else{const n=y.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(i){var C,R;const{toRange:r,fromRange:t}=i,e=y.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:s}=e,o=(R=(C=this._renderManagerService.getRenderById(n))==null?void 0:C.with(E.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!o)return{redos:[],undos:[]};const a=E.attachRangeWithCoord(o,t);if(!a)return{redos:[],undos:[]};const{startX:d,endX:g,startY:u,endY:c}=a,p=this._sheetDrawingService.getDrawingData(n,s),h=[];Object.keys(p).forEach(D=>{const T=p[D];if(T.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:I}=T;if(!I)return;const{left:U=0,top:b=0,width:A=0,height:N=0}=I,{drawingStartX:O,drawingEndX:M,drawingStartY:B,drawingEndY:L}={drawingStartX:U,drawingEndX:U+A,drawingStartY:b,drawingEndY:b+N};d<=O&&M<=g&&u<=B&&L<=c&&h.push(T)});const f=[],w=[],S=r.startRow-t.startRow,_=r.startColumn-t.startColumn,v=h.map(D=>{const T=D.sheetTransform,I={to:{...T.to,row:T.to.row+S,column:T.to.column+_},from:{...T.from,row:T.from.row+S,column:T.from.column+_}},U=K(I,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:s,drawingId:D.drawingId,transform:U,sheetTransform:I}});if(v.length){const D=this._sheetDrawingService.getBatchUpdateOp(v),{undo:T,redo:I,objects:U}=D;f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:s,op:I,objects:U,type:m.DrawingApplyType.UPDATE}}),w.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:s,op:T,objects:U,type:m.DrawingApplyType.UPDATE}})}return{redos:f,undos:w}}_moveRowInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:s}=i,o=s.startRow,a=s.endRow,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:w,transform:S,anchorType:_=m.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let v,C;if(r==="insert"){const D=this._expandRow(w,S,o,a,_);v=D==null?void 0:D.newSheetTransform,C=D==null?void 0:D.newTransform}else{const{from:D,to:T}=w,{row:I}=D,{row:U}=T;if(_===m.SheetDrawingAnchorType.Both&&I>=o&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkRow(w,S,o,a,_);v=b==null?void 0:b.newSheetTransform,C=b==null?void 0:b.newTransform}}if(!v||!C)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:v};c.push(R)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:w,objects:S}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,w=h.redo,S=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_moveColInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:s}=i,o=s.startColumn,a=s.endColumn,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:w,transform:S,anchorType:_=m.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let v,C;if(r==="insert"){const D=this._expandCol(w,S,o,a,_);v=D==null?void 0:D.newSheetTransform,C=D==null?void 0:D.newTransform}else{const{from:D,to:T}=w,{column:I}=D,{column:U}=T;if(_===m.SheetDrawingAnchorType.Both&&I>=o&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkCol(w,S,o,a,_);v=b==null?void 0:b.newSheetTransform,C=b==null?void 0:b.newTransform}}if(!v||!C)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:v};c.push(R)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:w,objects:S}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,w=h.redo,S=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_expandCol(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const s=e-t+1,{from:o,to:a}=i,{column:d}=o,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:o.row,endRow:a.row});if(p==null)return;c={...r,left:(r.left||0)+p.endX-p.startX},u=$(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,column:g+s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const s=e-t+1,{from:o,to:a}=i,{column:d}=o,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...o,column:d-s},to:{...a,column:g-s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,column:g-s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,left:(r.left||0)-i.from.columnOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:o.row,endRow:a.row});if(p==null)return;c={...r,left:(r.left||0)-p.endX+p.startX-i.from.columnOffset}}u=$(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:o.row,endRow:a.row});if(p==null)return;u={from:{...o},to:{...a,column:t-1,columnOffset:p.endX-p.startX}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const s=e-t+1,{from:o,to:a}=i,{row:d}=o,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:o.column,endColumn:a.column});if(p==null)return;c={...r,top:(r.top||0)+p.endY-p.startY},u=$(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,row:g+s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const s=e-t+1,{from:o,to:a}=i,{row:d}=o,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...o,row:d-s},to:{...a,row:g-s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,row:g-s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,top:(r.top||0)-i.from.rowOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:o.column,endColumn:a.column});if(p==null)return;c={...r,top:(r.top||0)-p.endY+p.startY-i.from.rowOffset}}u=$(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:o.column,endColumn:o.column,startRow:t-1,endRow:t-1});if(p==null)return;u={from:{...o},to:{...a,row:t-1,rowOffset:p.endY-p.startY}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===y.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(s=>{const o=n[s].data;o!=null&&Object.keys(o).forEach(a=>{e===i&&t.push(o[a])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(i,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(s=>{const o=t[s];o!=null&&Object.keys(o).forEach(a=>{const d=o[a].data;d!=null&&Object.keys(d).forEach(g=>{if(s===i&&a===r){const u=d[g];u.transform=K(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(d[g])}else n.push(d[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Cn.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(s=>{const o=e[s],{sheetTransform:a,transform:d,anchorType:g=m.SheetDrawingAnchorType.Position}=o;if(g===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=a,{row:p,column:h}=u,{row:f,column:w}=c;for(let S=0;S<t.length;S++){const _=t[S],{startRow:v,endRow:C,startColumn:R,endColumn:D}=_;if(l.Rectangle.intersects({startRow:v,endRow:C,startColumn:R,endColumn:D},{startRow:p,endRow:f,startColumn:h,endColumn:w})||p>C||h>D){const T=g===m.SheetDrawingAnchorType.Position,I=K(a,this._selectionRenderService,this._skeletonManagerService);n.push({...o,transform:{...I,width:T?d==null?void 0:d.width:I==null?void 0:I.width,height:T?d==null?void 0:d.height:I==null?void 0:I.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[i]))}};ut=Dn([ue(1,k.IRenderManagerService),ue(2,l.ICommandService),ue(3,E.ISheetSelectionRenderService),ue(4,l.Inject(E.SheetSkeletonManagerService)),ue(5,l.Inject(y.SheetInterceptorService)),ue(6,m.ISheetDrawingService),ue(7,j.IDrawingManagerService),ue(8,l.IUniverInstanceService)],ut);var re=function(){return re=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},re.apply(this,arguments)},Mn=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},Pt=ie.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,s=i.extend,o=Mn(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),d=ie.useRef("_".concat(bn()));return Nt(t,"".concat(e),{defIds:t.defIds,idSuffix:d.current},re({ref:r,className:a},o),s)});function Nt(i,r,t,e,n){return ie.createElement(i.tag,re(re({key:r},Tn(i,t,n)),e),(Rn(i,t).children||[]).map(function(s,o){return Nt(s,"".concat(r,"-").concat(i.tag,"-").concat(o),t,void 0,n)}))}function Tn(i,r,t){var e=re({},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(s){var o=s[0],a=s[1];o==="mask"&&typeof a=="string"&&(e[o]=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(s){var o=s[0],a=s[1];typeof a=="string"&&(e[o]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Rn(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)?re(re({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?re(re({},n),{attrs:re(re({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function bn(){return Math.random().toString(36).substring(2,8)}Pt.displayName="UniverIcon";var En={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"}}]},jt=ie.forwardRef(function(i,r){return ie.createElement(Pt,Object.assign({},i,{id:"add-image-single",ref:r,icon:En}))});jt.displayName="AddImageSingle";const St={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),e=i.get(m.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,s=e.map(o=>{const{unitId:a,subUnitId:d,drawingId:g,drawingType:u}=o;return{unitId:a,subUnitId:d,drawingId:g,drawingType:u}});return r.executeCommand(ye.id,{unitId:n,drawings:s})}},Ce={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(m.ISheetDrawingService),n=i.get(E.ISheetSelectionRenderService),{direction:s}=r,o=e.getFocusDrawings();if(o.length===0)return!1;const a=o[0].unitId,d=o.map(u=>{const{transform:c}=u;if(c==null)return null;const p={...c},{left:h=0,top:f=0}=c;return s===l.Direction.UP?p.top=f-1:s===l.Direction.DOWN?p.top=f+1:s===l.Direction.LEFT?p.left=h-1:s===l.Direction.RIGHT&&(p.left=h+1),{...u,transform:p,sheetTransform:$(p,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(Pe.id,{unitId:a,drawings:d})?(t.syncExecuteCommand(G.id,[a]),!0):!1}},kt="addition-and-subtraction-single",_t="sheet.menu.image";function On(i){return{id:_t,type:W.MenuItemType.SUBITEMS,icon:kt,tooltip:"sheetImage.title",hidden$:W.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(i,{workbookTypes:[y.WorkbookEditablePermission],worksheetTypes:[y.WorksheetEditPermission],rangeTypes:[y.RangeProtectionPermissionEditPoint]})}}function Un(i){return{id:Ne.id,title:"sheetImage.upload.float",type:W.MenuItemType.BUTTON,hidden$:W.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function An(i){return{id:wt.id,title:"sheetImage.upload.cell",type:W.MenuItemType.BUTTON,hidden$:W.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}const Pn=i=>{var C;const r=W.useDependency(l.ICommandService),t=W.useDependency(l.LocaleService),e=W.useDependency(j.IDrawingManagerService),n=W.useDependency(k.IRenderManagerService),{drawings:s}=i,o=s[0];if(o==null)return;const{unitId:a}=o,d=n.getRenderById(a),g=d==null?void 0:d.scene;if(g==null)return;const u=g.getTransformerByCreate(),[c,p]=ie.useState(!0),h=(C=o.anchorType)!=null?C:m.SheetDrawingAnchorType.Position,[f,w]=ie.useState(h);function S(R,D){const T=[];return R.forEach(I=>{const{oKey:U}=I,b=D.getDrawingOKey(U);if(b==null)return T.push(null),!0;const{unitId:A,subUnitId:N,drawingId:O,drawingType:M,anchorType:B,sheetTransform:L}=b;T.push({unitId:A,subUnitId:N,drawingId:O,anchorType:B,sheetTransform:L,drawingType:M})}),T}ie.useEffect(()=>{const R=u.clearControl$.subscribe(T=>{T===!0&&p(!1)}),D=u.changeStart$.subscribe(T=>{var b;const{objects:I}=T,U=S(I,e);if(U.length===0)p(!1);else if(U.length>=1){p(!0);const A=((b=U[0])==null?void 0:b.anchorType)||m.SheetDrawingAnchorType.Position;w(A)}});return()=>{D.unsubscribe(),R.unsubscribe()}},[]);function _(R){w(R);const D=e.getFocusDrawings();if(D.length===0)return;const T=D.map(I=>({unitId:I.unitId,subUnitId:I.subUnitId,drawingId:I.drawingId,anchorType:R}));r.executeCommand(Pe.id,{unitId:D[0].unitId,drawings:T})}const v=R=>R?"block":"none";return z.jsxs("div",{className:`
3
- univer-relative univer-mt-5 univer-w-full univer-border-b-0 univer-border-l-0 univer-border-r-0
4
- univer-border-t univer-border-solid univer-border-gray-200
5
- `,style:{display:v(c)},children:[z.jsx("div",{className:`
6
- univer-relative univer-mt-2.5 univer-flex univer-h-full univer-items-start univer-justify-start
7
- `,children:z.jsx("div",{className:"univer-w-full univer-text-left univer-text-gray-400",children:z.jsx("div",{children:t.t("drawing-anchor.title")})})}),z.jsx("div",{className:`
8
- univer-relative univer-mt-2.5 univer-flex univer-h-full univer-items-start univer-justify-start
9
- `,children:z.jsx("div",{className:"univer-flex univer-items-center univer-gap-1",children:z.jsxs(q.RadioGroup,{value:f,onChange:_,direction:"vertical",children:[z.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),z.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),z.jsx(q.Radio,{value:m.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})})]})},Nn=()=>{const i=W.useDependency(j.IDrawingManagerService),r=i.getFocusDrawings(),[t,e]=ie.useState(r);return ie.useEffect(()=>{const n=i.focus$.subscribe(s=>{e(s)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&z.jsxs("div",{className:"univer-p-2 univer-text-center univer-text-sm",children:[z.jsx(ge.DrawingCommonPanel,{drawings:t}),z.jsx(Pn,{drawings:t})]})},jn={[W.RibbonStartGroup.FORMULAS_INSERT]:{[_t]:{order:3,menuItemFactory:On,[Ne.id]:{order:0,menuItemFactory:Un},[wt.id]:{order:1,menuItemFactory:An}}}};function je(i){return!i.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(l.EDITOR_ACTIVATED)&&!i.getContextValue(l.FOCUSING_PANEL_EDITOR)&&i.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const kn={id:Ce.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:W.KeyCode.ARROW_DOWN,priority:100,preconditions:je,staticParameters:{direction:l.Direction.DOWN}},Wn={id:Ce.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:W.KeyCode.ARROW_UP,priority:100,preconditions:je,staticParameters:{direction:l.Direction.UP}},Bn={id:Ce.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:W.KeyCode.ARROW_LEFT,priority:100,preconditions:je,staticParameters:{direction:l.Direction.LEFT}},xn={id:Ce.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:W.KeyCode.ARROW_RIGHT,priority:100,preconditions:je,staticParameters:{direction:l.Direction.RIGHT}},Yn={id:St.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:je,binding:W.KeyCode.DELETE,mac:W.KeyCode.BACKSPACE};var Ln=Object.getOwnPropertyDescriptor,Fn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Ln(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},De=(i,r)=>(t,e)=>r(t,e,i);let it=class extends l.Disposable{constructor(i,r,t,e,n,s){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=s,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(kt,jt)),this.disposeWithMe(i.register(Et,Nn))}_initMenus(){this._menuManagerService.mergeMenu(jn)}_initCommands(){[Ne,wt,Ae,ye,Pe,gt,G,ht,pt,ft,Ce,St,mt].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[kn,Wn,Bn,xn,Yn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};it=Fn([De(0,l.Inject(W.ComponentManager)),De(1,W.IMenuManagerService),De(2,l.ICommandService),De(3,W.IShortcutService),De(4,j.IDrawingManagerService),De(5,l.Inject(y.SheetsSelectionsService))],it);var $n=Object.defineProperty,Gn=Object.getOwnPropertyDescriptor,Hn=(i,r,t)=>r in i?$n(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,Vn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Gn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},at=(i,r)=>(t,e)=>r(t,e,i),Wt=(i,r,t)=>Hn(i,typeof r!="symbol"?r+"":r,t);const Xn="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=Mt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:s,...o}=l.merge({},Mt,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig($t,o)}onStarting(){l.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[it],[qe],[rt],[nt],[tt],[Je],[Qe],[et]]),l.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[tt],[et]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[nt],[rt],[it],[Je],[Qe]])}onSteady(){this._injector.get(qe)}_registerRenderModules(){[[exports.SheetDrawingUpdateController],[ut],[dt],[ct]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}};Wt(exports.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);Wt(exports.UniverSheetsDrawingUIPlugin,"pluginName",Xn);exports.UniverSheetsDrawingUIPlugin=Vn([l.DependentOn(j.UniverDrawingPlugin,bt.UniverDocsDrawingPlugin,ge.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),at(1,l.Inject(l.Injector)),at(2,k.IRenderManagerService),at(3,l.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=G;exports.DeleteDrawingsCommand=St;exports.EditSheetDrawingOperation=ht;exports.GroupSheetDrawingCommand=pt;exports.InsertFloatImageCommand=Ne;exports.InsertSheetDrawingCommand=Ae;exports.MoveDrawingsCommand=Ce;exports.RemoveSheetDrawingCommand=ye;exports.SHEETS_IMAGE_MENU_ID=_t;exports.SetDrawingArrangeCommand=mt;exports.SetSheetDrawingCommand=Pe;exports.SidebarSheetDrawingOperation=gt;exports.UngroupSheetDrawingCommand=ft;
1
+ "use strict";var Lt=Object.defineProperty;var Ft=(i,r,t)=>r in i?Lt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t;var te=(i,r,t)=>Ft(i,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),bt=require("@univerjs/docs-drawing"),j=require("@univerjs/drawing"),ge=require("@univerjs/drawing-ui"),k=require("@univerjs/engine-render"),m=require("@univerjs/sheets-drawing"),Z=require("@univerjs/design"),E=require("@univerjs/sheets-ui"),W=require("@univerjs/ui"),A=require("rxjs"),y=require("@univerjs/sheets"),Ze=require("@univerjs/docs-ui"),z=require("react/jsx-runtime"),ie=require("react"),$t="sheets-drawing-ui.config",Mt={},G={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(i,r)=>{const t=i.get(k.IRenderManagerService);return r.forEach(e=>{var n,s;(s=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||s.debounceRefreshControls()}),!0}},ye={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var v,C,R;const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(y.SheetInterceptorService),s=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=[];o.forEach(I=>{const{unitId:T}=I;a.push(T)});const d=s.getBatchRemoveOp(o),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,f=n.onCommandExecute({id:ye.id,params:r}),w={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:p,objects:h,type:m.DrawingApplyType.REMOVE}},S={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:c,objects:h,type:m.DrawingApplyType.INSERT}};return l.sequenceExecute([...(v=f.preRedos)!=null?v:[],w,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=f.preUndos)!=null?C:[],S,...f.undos,{id:G.id,params:a}],redoMutations:[...(R=f.preRedos)!=null?R:[],w,...f.redos,{id:G.id,params:a}]}),!0):!1}},Et="COMPONENT_SHEET_DRAWING_PANEL",gt={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{const t=i.get(W.ISidebarService),e=i.get(l.LocaleService),n=i.get(l.IUniverInstanceService),s=i.get(l.ICommandService);if(!y.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Et},onClose:()=>{s.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},ht={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(i,r)=>{const t=i.get(l.ICommandService);return r==null?!1:(t.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[r]),t.executeCommand(gt.id,{value:"open"}),!0)}};var Gt=Object.getOwnPropertyDescriptor,Ht=(i,r,t,e)=>{for(var n=e>1?void 0:e?Gt(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},se=(i,r)=>(t,e)=>r(t,e,i);let qe=class extends l.RxDisposable{constructor(r,t,e,n,s,o,a,d,g,u){super();te(this,"_initImagePopupMenu",new Set);this._injector=r,this._localeService=t,this._drawingManagerService=e,this._canvasPopManagerService=n,this._renderManagerService=s,this._univerInstanceService=o,this._messageService=a,this._contextService=d,this._ioService=g,this._commandService=u,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(A.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(A.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._setupLoadingStatus()}_setupLoadingStatus(){const r="image-upload-loading";let 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 s;const t=(s=this._renderManagerService.getRenderById(r))==null?void 0:s.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const o=e.getSelectedObjectMap();if(o.size>1){n==null||n.dispose();return}const a=o.values().next().value;if(!a)return;const d=a.oKey,g=this._drawingManagerService.getDrawingOKey(d);if(!g)return;const{unitId:u,subUnitId:c,drawingId:p,drawingType:h}=g,f=g.data;if(f&&f.disablePopup)return;n==null||n.dispose();const w=this._canvasPopManagerService.getFeatureMenu(u,c,p,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:ge.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:w||this._getImageMenuItems(u,c,p,h)}}))})),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(o=>{o[l.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:ht.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ye.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===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ge.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===l.DrawingTypeEnum.DRAWING_DOM}]}};qe=Ht([se(0,l.Inject(l.Injector)),se(1,l.Inject(l.LocaleService)),se(2,j.IDrawingManagerService),se(3,l.Inject(E.SheetCanvasPopManagerService)),se(4,k.IRenderManagerService),se(5,l.IUniverInstanceService),se(6,W.IMessageService),se(7,l.IContextService),se(8,l.IImageIoService),se(9,l.ICommandService)],qe);var Vt=Object.getOwnPropertyDescriptor,Xt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Vt(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Ve=(i,r)=>(t,e)=>r(t,e,i);let ct=class extends l.Disposable{constructor(r,t,e,n,s){super();te(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=t,this._selectionsService=e,this._drawingRenderService=n,this._sheetSkeletonManagerService=s,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(A.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(k.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}}))}};ct=Xt([Ve(1,l.Inject(E.HoverManagerService)),Ve(2,l.Inject(y.SheetsSelectionsService)),Ve(3,l.Inject(ge.DrawingRenderService)),Ve(4,l.Inject(E.SheetSkeletonManagerService))],ct);function K(i,r,t){const{from:e,to:n,flipY:s=!1,flipX:o=!1,angle:a=0,skewX:d=0,skewY:g=0}=i,u=t.getCurrent();if(u==null)return;const c=E.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:p,top:h,width:f,height:w}=c;const S=t.getCurrentSkeleton(),_=S.rowHeaderWidth+S.columnTotalWidth,v=S.columnHeaderHeight+S.rowTotalHeight;return p+f>_&&(p=_-f),h+w>v&&(h=v-w),{flipY:s,flipX:o,angle:a,skewX:d,skewY:g,left:p,top:h,width:f,height:w}}function $(i,r){const{left:t=0,top:e=0,width:n=0,height:s=0,flipY:o=!1,flipX:a=!1,angle:d=0,skewX:g=0,skewY:u=0}=i,c=r.getCellWithCoordByOffset(t,e);if(c==null)return;const p={column:c.actualColumn,columnOffset:k.precisionTo(t-c.startX,1),row:c.actualRow,rowOffset:k.precisionTo(e-c.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+s);if(h==null)return;const f={column:h.actualColumn,columnOffset:k.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:k.precisionTo(e+s-h.startY,1)};return{flipY:o,flipX:a,angle:d,skewX:g,skewY:u,from:p,to:f}}var Kt=Object.getOwnPropertyDescriptor,zt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Kt(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Xe=(i,r)=>(t,e)=>r(t,e,i);let dt=class extends l.Disposable{constructor(i,r,t,e,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const t=i[r];for(const e in t.data){const n=t.data[e];n.sheetTransform&&(n.transform=K(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService))}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};dt=zt([Xe(1,m.ISheetDrawingService),Xe(2,j.IDrawingManagerService),Xe(3,l.Inject(E.ISheetSelectionRenderService)),Xe(4,l.Inject(E.SheetSkeletonManagerService))],dt);function Zt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:s,subUnitId:o,drawingId:a}=e,d=k.getGroupState(0,0,n.map(c=>c.transform||{})),g=n.map(c=>{const p=c.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:w}=c;return{unitId:h,subUnitId:f,drawingId:w,transform:{...p,left:p.left-d.left,top:p.top-d.top},groupId:a}}),u={unitId:s,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:d};r.push({parent:u,children:g})}),r}function qt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:s,subUnitId:o,drawingId:a,transform:d={width:0,height:0}}=e;if(d==null)return;const g=n.map(c=>{const{transform:p}=c,{unitId:h,subUnitId:f,drawingId:w}=c,S=k.transformObjectOutOfGroup(p||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:f,drawingId:w,transform:S,groupId:void 0}}),u={unitId:s,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const pt={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const s=[];r.forEach(({parent:h,children:f})=>{s.push(h.unitId),f.forEach(w=>{s.push(w.unitId)})});const o=n.getGroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=o;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:qt(c),type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:s}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP}},{id:G.id,params:s}]}),!0):!1}},Ae={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var v,C,R;const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService),s=i.get(y.SheetInterceptorService);if(!r)return!1;const o=r.drawings,a=o.map(I=>I.unitId),d=n.getBatchAddOp(o),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,f=s.onCommandExecute({id:Ae.id,params:r}),w={id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT}},S={id:m.SetDrawingApplyMutation.id,params:{op:c,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(v=f.preRedos)!=null?v:[],w,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=f.preUndos)!=null?C:[],S,...f.undos,{id:G.id,params:a}],redoMutations:[...(R=f.preRedos)!=null?R:[],w,...f.redos,{id:G.id,params:a}]}),!0):!1}},mt={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService);if(!r)return!1;const n=i.get(m.ISheetDrawingService),{unitId:s,subUnitId:o,drawingIds:a,arrangeType:d}=r,g={unitId:s,subUnitId:o,drawingIds:a};let u;if(d===l.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):d===l.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):d===l.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):d===l.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:c,redo:p,undo:h}=u;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:p,unitId:s,subUnitId:o,objects:c,type:m.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:s,subUnitId:o,objects:c,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:s,subUnitId:o,objects:c,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}},Pe={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,o=n.getBatchUpdateOp(s),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=o;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:a,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:g,objects:c,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}]}),!0):!1}},ft={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const s=[];r.forEach(({parent:h,children:f})=>{s.push(h.unitId),f.forEach(w=>{s.push(w.unitId)})});const o=n.getUngroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=o;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:Zt(c),type:m.DrawingApplyType.GROUP}},{id:G.id,params:s}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:s}]}),!0):!1}};var Jt=Object.getOwnPropertyDescriptor,Qt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Jt(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},ne=(i,r)=>(t,e)=>r(t,e,i);function en(i,r,t){const e=t*Math.PI/180,n=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),s=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:s}}function lt(i,r,t,e,n){var v;const{rotatedHeight:s,rotatedWidth:o}=en(t,e,n),d=i.get(k.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const u=(v=d.with(E.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:v.skeleton;if(u==null)return!1;const c=u.getCellByIndex(r.row,r.col),p=c.mergeInfo.endX-c.mergeInfo.startX-2,h=c.mergeInfo.endY-c.mergeInfo.startY-2,f=o/s,S=Math.ceil(Math.min(p,h*f))/o,_=!S||Number.isNaN(S)?.001:S;return{width:t*_,height:e*_}}exports.SheetDrawingUpdateController=class extends l.Disposable{constructor(t,e,n,s,o,a,d,g,u,c,p,h,f){super();te(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=s,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=d,this._drawingManagerService=g,this._contextService=u,this._messageService=c,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(C){const R=C.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:s,subUnitId:o}=n,{imageId:a,imageSourceType:d,source:g,base64Cache:u}=e,{width:c,height:p,image:h}=await j.getImageSize(u||""),{width:f,height:w}=this._context.scene;this._imageIoService.addImageSourceCache(g,d,h);let S=1;if(c>j.DRAWING_IMAGE_WIDTH_LIMIT||p>j.DRAWING_IMAGE_HEIGHT_LIMIT){const C=j.DRAWING_IMAGE_WIDTH_LIMIT/c,R=j.DRAWING_IMAGE_HEIGHT_LIMIT/p;S=Math.max(C,R)}const _=this._getImagePosition(c*S,p*S,f,w);if(_==null)return;const v={unitId:s,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:d,source:g,transform:K(_,this._selectionRenderService,this._skeletonManagerService),sheetTransform:_};return this._commandService.executeCommand(Ae.id,{unitId:s,drawings:[v]})}async _insertCellImage(t,e){var v,C;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:s,imageSourceType:o,source:a,base64Cache:d}=n,{width:g,height:u,image:c}=await j.getImageSize(d||"");this._imageIoService.addImageSourceCache(a,o,c);const p=this._workbookSelections.getCurrentLastSelection();if(!p)return!1;const h=l.createDocumentModelWithStyle("",{}),f=lt(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 w={size:{width:f.width,height:f.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},S={unitId:h.getUnitId(),subUnitId:h.getUnitId(),drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:o,source:a,transform:Ze.docDrawingPositionToTransform(w),docTransform:w,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},_=l.BuildTextUtils.drawing.add({documentDataModel:h,drawings:[S],selection:{collapsed:!0,startOffset:0,endOffset:0}});return _?(h.apply(_),this._commandService.syncExecuteCommand(y.SetRangeValuesCommand.id,{value:{[(v=e==null?void 0:e.row)!=null?v:p.primary.actualRow]:{[(C=e==null?void 0:e.col)!=null?C: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:s,image:o}=await j.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,l.ImageSourceType.URL,o);const a=this._workbookSelections.getCurrentLastSelection();if(!a)return!1;const d=l.createDocumentModelWithStyle("",{}),g=lt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:a.primary.actualRow,col:a.primary.actualColumn},n,s,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},c={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:t,transform:Ze.docDrawingPositionToTransform(u),docTransform:u,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},p=l.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[c],selection:{collapsed:!0,startOffset:0,endOffset:0}});return p?(d.apply(p),this._commandService.syncExecuteCommand(y.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:d.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(),s=e.getSheetId();return{unitId:n,subUnitId:s}}_getImagePosition(t,e,n,s){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const d=E.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(d==null)return;let{startColumn:g,startRow:u,startX:c,startY:p}=d,h=!1;if(c+t>n&&(c=n-t,c<0&&(c=0,t=n),h=!0),p+e>s&&(p=s-e,p<0&&(p=0,e=s),h=!0),h){const _=this._selectionRenderService.getCellWithCoordByOffset(c,p);if(_==null)return;c=_.startX,p=_.startY,g=_.actualColumn,u=_.actualRow}const f={column:g,columnOffset:0,row:u,rowOffset:0},w=this._selectionRenderService.getCellWithCoordByOffset(c+t,p+e);if(w==null)return;const S={column:w.actualColumn,columnOffset:c+t-w.startX,row:w.actualRow,rowOffset:p+e-w.startY};return{from:f,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:s,arrangeType:o}=t;this._commandService.executeCommand(mt.id,{unitId:e,subUnitId:n,drawingIds:s,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:s,subUnitId:o,drawingId:a,drawingType:d,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:s,subUnitId:o,drawingId:a});if(u==null||u.unitId!==this._context.unitId)return;const c=$({...u.transform,...g},this._selectionRenderService);if(c==null)return;const p={...n,transform:{...u.transform,...g,...K(c,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...c}};e.push(p)}),e.length>0&&this._commandService.executeCommand(Pe.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(pt.id,t);const{unitId:e,subUnitId:n,drawingId:s}=t[0].parent;this._commandService.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:s}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(ft.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}};exports.SheetDrawingUpdateController=Qt([ne(1,l.Inject(E.SheetSkeletonManagerService)),ne(2,l.ICommandService),ne(3,E.ISheetSelectionRenderService),ne(4,j.IImageIoService),ne(5,W.ILocalFileService),ne(6,m.ISheetDrawingService),ne(7,j.IDrawingManagerService),ne(8,l.IContextService),ne(9,W.IMessageService),ne(10,l.Inject(l.LocaleService)),ne(11,l.Inject(y.SheetsSelectionsService)),ne(12,l.Inject(l.Injector))],exports.SheetDrawingUpdateController);var tn=Object.getOwnPropertyDescriptor,nn=(i,r,t,e)=>{for(var n=e>1?void 0:e?tn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Ie=(i,r)=>(t,e)=>r(t,e,i);function Ot(i,r,t){var e,n,s,o;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((o=(s=t.p)==null?void 0:s.drawingsOrder)==null?void 0:o.length)===1){const a=t.p.drawings[t.p.drawingsOrder[0]],d=lt(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},a.docTransform.size.width,a.docTransform.size.height,a.docTransform.angle);if(d)return a.transform.width=d.width,a.transform.height=d.height,a.docTransform.size.width=d.width,a.docTransform.size.height=d.height,a.transform.left=0,a.transform.top=0,a.docTransform.positionH.posOffset=0,a.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let Je=class extends l.Disposable{constructor(i,r,t,e,n,s){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=s,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===Ze.ReplaceSnapshotCommand.id&&i.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(y.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:y.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,t)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0},Ot(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),t(i)}}))}};Je=nn([Ie(0,l.ICommandService),Ie(1,l.Inject(y.SheetInterceptorService)),Ie(2,l.Inject(l.Injector)),Ie(3,j.IDrawingManagerService),Ie(4,l.Inject(bt.DocDrawingController)),Ie(5,l.Inject(E.IEditorBridgeService))],Je);var rn=Object.getOwnPropertyDescriptor,sn=(i,r,t,e)=>{for(var n=e>1?void 0:e?rn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Tt=(i,r)=>(t,e)=>r(t,e,i);let Qe=class extends l.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,t,e)=>{new l.ObjectMatrix(e).forValue((n,s,o)=>{Ot(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:s},o)})}}))}};Qe=sn([Tt(0,l.Inject(E.IAutoFillService)),Tt(1,l.Inject(l.Injector))],Qe);var on=Object.getOwnPropertyDescriptor,an=(i,r,t,e)=>{for(var n=e>1?void 0:e?on(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},be=(i,r)=>(t,e)=>r(t,e,i);const cn=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,l.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let et=class extends l.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=l.createDocumentModelWithStyle("",{}),t=(n=k.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(E.EditingRenderController),e=l.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===Ze.InnerPasteCommand.id){const e=i.params,{doc:n}=e,s=this._univerInstanceService.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_DOC);if(s==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const o=s.getUnitId();if(cn.includes(o)){if(o!==l.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const a=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(E.SetCellEditVisibleOperation.id,{visible:!1})};((t=s.getBody())==null?void 0:t.dataStream)===`\r
2
+ `?(this._commandService.syncExecuteCommand(E.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")}}}))}};et=an([be(0,l.ICommandService),be(1,l.IUniverInstanceService),be(2,W.IDialogService),be(3,k.IRenderManagerService),be(4,l.Inject(l.LocaleService))],et);const Ne={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{var o,a;const t=i.get(l.IUniverInstanceService),e=i.get(k.IRenderManagerService),n=(o=k.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:o.with(exports.SheetDrawingUpdateController);if(!n)return!1;const s=r==null?void 0:r.files;if(s){const d=s.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(d)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},wt={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:i=>{var e,n;const r=i.get(l.IUniverInstanceService),t=i.get(k.IRenderManagerService);return(n=(e=k.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,r,t))==null?void 0:e.with(exports.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}};var dn=Object.getOwnPropertyDescriptor,ln=(i,r,t,e)=>{for(var n=e>1?void 0:e?dn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Ee=(i,r)=>(t,e)=>r(t,e,i);const Ut="image/png";function un(i){const r=i.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);return new Blob([n],{type:Ut})}function gn(i){const r=new ClipboardItem({[Ut]:un(i)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function hn(){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=[E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let tt=class extends l.Disposable{constructor(r,t,e,n,s){super();te(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=s,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const s=this._focusedDrawings;if(s.length>0){const[o]=s;if(n===E.COPY_TYPE.CUT){const d={unitId:r,drawings:[o]};this._commandService.executeCommand(ye.id,d)}setTimeout(()=>{const d=hn();o.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&o.imageSourceType===j.ImageSourceType.BASE64?gn(o.source):this._clipboardInterfaceService.writeText(""),d()},200);const a={unitId:o.unitId,subUnitId:o.subUnitId,drawings:[o]};this._copyInfo=a}else{const o=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=o}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:s=E.COPY_TYPE.COPY,pasteType:o}=n,{range:a}=r||{},{range:d,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:o,unitId:g,subUnitId:u,pasteRange:d},{copyRange:a,copyType:s}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:o},E.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:E.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},E.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:E.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},E.COPY_TYPE.COPY);{const e=t.filter(n=>n.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Ne.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(E.SheetSkeletonManagerService);if(!n)return;const s=n.attachRangeWithCoord(e);if(!s)return;const{startX:o,endX:a,startY:d,endY:g}=s,u=this._drawingService.getDrawingData(r,t),c=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const f=u[h],{transform:w}=f;if(f.anchorType!==m.SheetDrawingAnchorType.Both||!w)return;const{left:S=0,top:_=0,width:v=0,height:C=0}=w,{drawingStartX:R,drawingEndX:I,drawingStartY:T,drawingEndY:D}={drawingStartX:S,drawingEndX:S+v,drawingStartY:_,drawingEndY:_+C};o<=R&&I<=a&&d<=T&&D<=g&&c.push(f)}),c.length)return{copyRange:e,drawings:c,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Rt.includes(e))return{redos:[],undos:[]};const{unitId:s,subUnitId:o,range:a}=n,d=this._renderManagerService.getRenderById(s),g=d==null?void 0:d.with(E.SheetSkeletonManagerService),u=d==null?void 0:d.with(E.ISheetSelectionRenderService),c=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:p}=c,h=E.discreteRangeToRange(a);return this._generateMutations(p,{unitId:s,subUnitId:o,isCut:t===E.COPY_TYPE.CUT,getTransform:(f,w)=>{var v;const S=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),_={...f,left:S==null?void 0:S.startX,top:S==null?void 0:S.startY};return{transform:_,sheetTransform:(v=$(_,u))!=null?v:w}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:s,isCut:o}=t,a=[],d=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:c,sheetTransform:p}=u;if(!c)return;const h=s(c,p),f={...u,unitId:e,subUnitId:n,drawingId:o?u.drawingId:l.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(o){const{undo:w,redo:S,objects:_}=g.getBatchUpdateOp([f]);a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:S,objects:_}}),d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:w,objects:_}})}else{const{undo:w,redo:S,objects:_}=g.getBatchAddOp([f]);a.push({id:m.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.INSERT}}),d.push({id:m.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.REMOVE}})}}),{redos:a,undos:d}}_generateRangeDrawingsPasteMutations(r,t){var U;const{unitId:e,subUnitId:n,pasteType:s,pasteRange:o}=r,{copyRange:a,copyType:d}=t;if(Rt.includes(s))return{redos:[],undos:[]};const g=(U=this._renderManagerService.getRenderById(e))==null?void 0:U.with(E.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:E.discreteRangeToRange(o)},pasteType:s},d);const{ranges:[c,p],mapFunc:h}=E.virtualizeDiscreteRanges([a,o]),{row:f,col:w}=h(c.startRow,c.startColumn),{row:S,col:_}=h(p.startRow,p.startColumn),v=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:w,endColumn:w}),C=g.attachRangeWithCoord({startRow:S,endRow:S,startColumn:_,endColumn:_});if(!v||!C||!this._copyInfo)return{redos:[],undos:[]};const R=C.startX-v.startX,I=C.startY-v.startY,T=S-f,D=_-w;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(b,P)=>{var N,O;return{transform:{...b,left:((N=b==null?void 0:b.left)!=null?N:0)+R,top:((O=b==null?void 0:b.top)!=null?O:0)+I},sheetTransform:{...P,to:{...P.to,row:P.to.row+T,column:P.to.column+D},from:{...P.from,row:P.from.row+T,column:P.from.column+D}}}},isCut:d===E.COPY_TYPE.CUT})}};tt=ln([Ee(0,E.ISheetClipboardService),Ee(1,k.IRenderManagerService),Ee(2,j.IDrawingManagerService),Ee(3,W.IClipboardInterfaceService),Ee(4,l.ICommandService)],tt);var pn=Object.getOwnPropertyDescriptor,mn=(i,r,t,e)=>{for(var n=e>1?void 0:e?pn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Oe=(i,r)=>(t,e)=>r(t,e,i);let nt=class extends l.Disposable{constructor(i,r,t,e,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=A.combineLatest([i,r]);this.disposeWithMe(t.pipe(A.switchMap(([e,n])=>e?e.activeSheet$.pipe(A.tap(s=>{if(!s){this._drawingManagerService.setDrawingVisible(!1);return}const o=e.getUnitId(),a=s.getSheetId();this._permissionService.composePermission([new y.WorkbookViewPermission(o).id,new y.WorksheetViewPermission(o,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,s)})):(this._drawingManagerService.setDrawingVisible(!1),A.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(i,r){this._drawingManagerService.setDrawingVisible(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),s=Object.values(n),o=this._renderManagerService.getRenderById(t),a=o==null?void 0:o.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===k.RENDER_CLASS_TYPE.IMAGE&&s.some(u=>g.oKey.includes(u.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=A.combineLatest([i,r]);this.disposeWithMe(t.pipe(A.switchMap(([e,n])=>e?e.activeSheet$.pipe(A.tap(s=>{if(!s){this._drawingManagerService.setDrawingEditable(!1);return}const o=e.getUnitId(),a=s.getSheetId();this._permissionService.composePermission([new y.WorkbookEditablePermission(o).id,new y.WorksheetEditPermission(o,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,s)})):(this._drawingManagerService.setDrawingEditable(!1),A.EMPTY))).subscribe())}_handleDrawingEditableFalse(i,r){this._drawingManagerService.setDrawingEditable(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),s=Object.values(n),o=this._renderManagerService.getRenderById(t),a=o==null?void 0:o.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===k.RENDER_CLASS_TYPE.IMAGE&&s.some(u=>g.oKey.includes(u.drawingId))&&a.detachTransformerFrom(g)})}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(A.combineLatest([i,r]).pipe(A.switchMap(([t,e])=>t?t.activeSheet$.pipe(A.switchMap(n=>{if(!n)return A.EMPTY;const s=t.getUnitId(),o=n.getSheetId(),a=this._renderManagerService.getRenderById(s),d=a==null?void 0:a.scene;if(!d)return A.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookViewPermission(s).id,new y.WorksheetViewPermission(s,o).id]).pipe(A.map(c=>c.every(p=>p.value)),A.distinctUntilChanged()).pipe(A.map(c=>({permission:c,scene:d,transformer:g,unitId:s,subUnitId:o})))})):A.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:s,subUnitId:o})=>{this._drawingManagerService.setDrawingVisible(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(s,o),g=Object.values(d);t?this._drawingManagerService.addNotification(g):(a.forEach(u=>{u.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),s=e==null?void 0:e.getSheetId();if(!n||!s)return;const o=this._drawingManagerService.getDrawingData(n,s),a=Object.values(o);this._drawingManagerService.addNotification(a)}}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(A.combineLatest([i,r]).pipe(A.switchMap(([t,e])=>t?t.activeSheet$.pipe(A.switchMap(n=>{if(!n)return A.EMPTY;const s=t.getUnitId(),o=n.getSheetId(),a=this._renderManagerService.getRenderById(s),d=a==null?void 0:a.scene;if(!d)return A.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookEditablePermission(s).id,new y.WorksheetEditPermission(s,o).id]).pipe(A.map(c=>c.every(p=>p.value)),A.distinctUntilChanged()).pipe(A.map(c=>({permission:c,scene:d,transformer:g,unitId:s,subUnitId:o})))})):A.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:s,subUnitId:o})=>{this._drawingManagerService.setDrawingEditable(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(s,o),g=Object.values(d);t?(a.forEach(u=>{u.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(a.forEach(u=>{u.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const s=n.getSheetId(),o=this._renderManagerService.getRenderById(e),a=o==null?void 0:o.scene;if(!a)return;const d=this._drawingManagerService.getDrawingData(e,s),g=Object.values(d);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(c=>{c.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(p=>c.oKey.includes(p.drawingId))&&a.detachTransformerFrom(c)})}}))}};nt=mn([Oe(0,j.IDrawingManagerService),Oe(1,k.IRenderManagerService),Oe(2,l.IPermissionService),Oe(3,l.IUniverInstanceService),Oe(4,l.Inject(l.UserManagerService))],nt);var fn=Object.getOwnPropertyDescriptor,wn=(i,r,t,e)=>{for(var n=e>1?void 0:e?fn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},he=(i,r)=>(t,e)=>r(t,e,i);function At(i,r,t,e,n,s=!1){const{scaleX:o,scaleY:a}=r.getAncestorScale(),d=r.getViewport(k.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=e.getFreeze(),{startColumn:u,startRow:c,xSplit:p,ySplit:h}=g,f={left:!0,top:!0};if(!d)return{...i,absolute:f};const{left:w,right:S,top:_,bottom:v}=i;let{top:C,left:R,viewportScrollX:I,viewportScrollY:T}=d;const{boundsOfViewArea:D,scrollDirectionResponse:U}=n||{},{rowHeaderWidth:b,columnHeaderHeight:P}=t,N={top:s?0:P,left:s?0:b};D&&(l.Tools.isDefine(N.top)&&(N.top=D.top),l.Tools.isDefine(N.left)&&(N.left=D.left)),U==="HORIZONTAL"&&(T=0),U==="VERTICAL"&&(I=0);let O=0,M=0;const B=t.rowStartY(c-h)+P,L=t.colStartX(u-p)+b,q=t.rowStartY(c)+P,J=t.colStartX(u)+b;if(p===0)f.left=!1,O=(w-I)*o,M=(S-I)*o;else{const V=w-(L-b),x=S-(L-b);S<J?(O=V*o,M=x*o):w<=J&&S>=J?(O=V*o,M=Math.max(R,(S-I)*o)):w>J&&(f.left=!1,O=Math.max((w-I)*o,R),M=Math.max((S-I)*o,R))}let H=0,X=0;if(h===0)f.top=!1,H=(_-T)*a,X=(v-T)*a;else{const V=_-(B-P),x=v-(B-P);v<q?(H=V*a,X=x*a):_<=q&&v>=q?(H=V*a,X=Math.max(C,(v-T)*a)):_>q&&(f.top=!1,H=Math.max((_-T)*a,C),X=Math.max((v-T)*a,C))}return O=Math.max(O,N.left),H=Math.max(H,N.top),M=Math.max(M,N.left),X=Math.max(X,N.top),{left:O,right:M,top:H,bottom:X,absolute:f}}const le=(i,r,t,e,n)=>{const{left:s,top:o,width:a,height:d,angle:g}=i,u={left:s,right:s+a,top:o,bottom:o+d},c=At(u,r,t,e,n),{scaleX:p,scaleY:h}=r.getAncestorScale();return{startX:c.left,endX:c.right,startY:c.top,endY:c.bottom,rotate:g,width:a*p,height:d*h,absolute:c.absolute}};exports.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(t,e,n,s,o,a,d){super();te(this,"_domLayerInfoMap",new Map);te(this,"_transformChange$",new A.Subject);te(this,"transformChange$",this._transformChange$.asObservable());te(this,"_add$",new A.Subject);te(this,"add$",this._add$.asObservable());te(this,"_remove$",new A.Subject);te(this,"remove$",this._remove$.asObservable());this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=s,this._canvasFloatDomService=o,this._sheetDrawingService=a,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(A.filter(t=>t===l.LifecycleStages.Rendered),A.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 s=n.getTransformerByCreate(),o=e.engine.getCanvasElement();return{scene:n,transformer:s,renderUnit:e,canvas:o}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var V;const{unitId:n,subUnitId:s,drawingId:o}=e,a=y.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:s}),d=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!d||!a)return;const c=(V=this._renderManagerService.getRenderById(n))==null?void 0:V.with(E.SheetSkeletonManagerService).getSkeletonParam(s);if(!c)return;const{transform:p,drawingType:h,data:f}=d;if(h!==l.DrawingTypeEnum.DRAWING_DOM&&h!==l.DrawingTypeEnum.DRAWING_CHART)return;const w=this._getSceneAndTransformerByDrawingSearch(n);if(w==null)return;const{scene:S,canvas:_}=w;if(p==null)return!0;if(u!==s)return;const{left:v,top:C,width:R,height:I,angle:T,flipX:D,flipY:U,skewX:b,skewY:P}=p,N=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:s,drawingId:o}),O=S.getObject(N);if(O!=null){O.transformByState({left:v,top:C,width:R,height:I,angle:T,flipX:D,flipY:U,skewX:b,skewY:P});return}const M={left:v,top:C,width:R,height:I,zIndex:this._drawingManagerService.getDrawingOrder(n,s).length-1},B=h===l.DrawingTypeEnum.DRAWING_CHART;if(M.rotateEnabled=!1,B){const x=f?f.backgroundColor:"white";M.fill=x,f&&f.border&&(M.stroke=f.border),M.paintFirst="stroke",M.strokeWidth=1,M.borderEnabled=!1,M.radius=8}const L=new k.Rect(N,M);B&&L.setObjectType(k.ObjectType.CHART),S.addObject(L,k.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo(L);const q=new l.DisposableCollection,J=le(L,w.renderUnit.scene,c.skeleton,a.worksheet),H=new A.BehaviorSubject(J),X={dispose:q,rect:L,position$:H,unitId:n,subUnitId:s,id:o};this._canvasFloatDomService.addFloatDom({position$:H,id:o,componentKey:d.componentKey,onPointerDown:x=>{_.dispatchEvent(new PointerEvent(x.type,x))},onPointerMove:x=>{_.dispatchEvent(new PointerEvent(x.type,x))},onPointerUp:x=>{_.dispatchEvent(new PointerEvent(x.type,x))},onWheel:x=>{_.dispatchEvent(new WheelEvent(x.type,x))},data:f,unitId:n});const Q=L.onTransformChange$.subscribeEvent(()=>{const x=le(L,w.renderUnit.scene,c.skeleton,a.worksheet);H.next(x)});q.add(()=>{this._canvasFloatDomService.removeFloatDom(o)}),Q&&q.add(Q),this._domLayerInfoMap.set(o,X)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{var p;const{unitId:n,subUnitId:s,drawingId:o}=e,a=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:s,drawingId:o}),d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{transformer:g,scene:u}=d,c=u.getObject(a);c!=null&&c.oKey&&(g.clearControlByIds([c==null?void 0:c.oKey]),(p=u.getTransformer())==null||p.clearSelectedObjects())})}))}_scrollUpdateListener(){const t=(e,n)=>{var g;const s=this._getSceneAndTransformerByDrawingSearch(e),o=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=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(E.SheetSkeletonManagerService).getSkeletonParam(n);!s||!a||!d||o.forEach(u=>{const c=this._domLayerInfoMap.get(u);if(c){const p=le(c.rect,s.renderUnit.scene,d.skeleton,a.worksheet,c);c.position$.next(p)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(A.switchMap(e=>e?e.activeSheet$:A.of(null)),A.map(e=>{if(!e)return null;const n=e.getUnitId(),s=this._renderManagerService.getRenderById(n);return s?{render:s,unitId:n,subUnitId:e.getSheetId()}:null}),A.switchMap(e=>e?l.fromEventSubject(e.render.scene.getViewport(k.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(A.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):A.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:s}=e;t(n,s)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===E.SetZoomRatioOperation.id){const n=e.params,{unitId:s}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===s).map(a=>a.subUnitId).forEach(a=>{t(s,a)})}else if(e.id===y.SetFrozenMutation.id){const{unitId:n,subUnitId:s}=e.params;t(n,s)}}))}_getPosition(t,e){var h;const{startX:n,endX:s,startY:o,endY:a}=t,d=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(E.ISheetSelectionRenderService);if(d==null)return;const g=d.getCellWithCoordByOffset(n,o);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:o-g.startY},c=d.getCellWithCoordByOffset(s,a);if(c==null)return;const p={column:c.actualColumn,columnOffset:s-c.startX,row:c.actualRow,rowOffset:a-c.startY};return{from:u,to:p}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const s={...n.transform};this._transformChange$.next({id:e.drawingId,value:s})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,s){const o=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(t);if(o&&a){const{scene:d}=a,g=j.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=d.getObject(g);u&&u instanceof k.Rect&&u.setProps(s)}}addFloatDomToPosition(t,e){const n=y.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:s,subUnitId:o}=n,{initPosition:a,componentKey:d,data:g,allowTransform:u=!0}=t,c=e!=null?e:l.generateRandomId(),p=this._getPosition(a,s);if(p==null)return;const h={unitId:s,subUnitId:o,drawingId:c,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:p,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Ae.id,{unitId:s,drawings:[h]}),this._add$.next({unitId:s,subUnitId:o,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:s,subUnitId:o}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(s);if(a&&a.scene.removeObject(n.rect),e){const d=this._drawingManagerService.getDrawingByParam({unitId:s,subUnitId:o,drawingId:t});if(!d)return;const g=this._sheetDrawingService.getBatchRemoveOp([d]),{redo:u,objects:c}=g;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:s,subUnitId:o,op:u,objects:c,type:m.DrawingApplyType.REMOVE})}}addFloatDomToRange(t,e,n,s){var D,U,b;const o=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!o)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=o,g=this._getSceneAndTransformerByDrawingSearch(a);if(!g)return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(D=this._renderManagerService.getRenderById(a))==null?void 0:D.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,w=s!=null?s:l.generateRandomId(),{position:S,position$:_}=this._createRangePositionObserver(t,u,c.skeleton);if(this._getPosition(S,a)==null)return;const C=g.scene,{scaleX:R}=C.getAncestorScale(),I=Ke(S,n,R),T={unitId:a,subUnitId:d,drawingId:w,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:h,allowTransform:f};{const{unitId:P,subUnitId:N,drawingId:O}=T,M=y.getSheetCommandTarget(this._univerInstanceService,{unitId:P,subUnitId:N}),B=T,L=this._univerInstanceService.getUnit(P,l.UniverInstanceType.UNIVER_SHEET);if(!L)return;const q=L.getActiveSheet().getSheetId();if(!B||!M)return;const J=(U=this._renderManagerService.getRenderById(P))==null?void 0:U.with(E.SheetSkeletonManagerService);if(!J)return;const H=J.getWorksheetSkeleton(N);if(!H)return;const{transform:X,drawingType:Q,data:V}=B;if(Q!==l.DrawingTypeEnum.DRAWING_DOM&&Q!==l.DrawingTypeEnum.DRAWING_CHART)return;const x=this._getSceneAndTransformerByDrawingSearch(P);if(x==null)return;const{scene:me,canvas:fe}=x;if(X==null||q!==N)return;const{left:ke,top:We,width:Be,height:xe,angle:st,flipX:ot,flipY:Ye,skewX:Le,skewY:we}=X,Fe=j.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:N,drawingId:O}),oe=me.getObject(Fe);if(oe!=null){oe.transformByState({left:ke,top:We,width:Be,height:xe,angle:st,flipX:ot,flipY:Ye,skewX:Le,skewY:we});return}const ee={left:ke,top:We,width:Be,height:xe,zIndex:this._drawingManagerService.getDrawingOrder(P,N).length-1},Se=Q===l.DrawingTypeEnum.DRAWING_CHART;if(Se){const Y=V?V.backgroundColor:"white";ee.fill=Y,ee.rotateEnabled=!1,V&&V.border&&(ee.stroke=V.border),ee.paintFirst="stroke",ee.strokeWidth=1,ee.borderEnabled=!1,ee.radius=8}const ae=new k.Rect(Fe,ee);Se&&ae.setObjectType(k.ObjectType.CHART),me.addObject(ae,k.DRAWING_OBJECT_LAYER_INDEX),B.allowTransform!==!1&&me.attachTransformerTo(ae);const ce=new l.DisposableCollection,$e=me.getMainViewport(),{rowHeaderWidth:_e,columnHeaderHeight:Me}=H.skeleton,Ge={top:Me,left:_e,bottom:$e.bottom,right:$e.right},de={dispose:ce,rect:ae,boundsOfViewArea:Ge,domAnchor:n,unitId:P,subUnitId:N},F=le(ae,x.renderUnit.scene,H.skeleton,M.worksheet,de),ve=new A.BehaviorSubject(F);de.position$=ve;let Te={position$:ve,id:O,componentKey:B.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:Y=>{fe.dispatchEvent(new WheelEvent(Y.type,Y))},data:V,unitId:P};e.eventPassThrough&&(Te={...Te,onPointerDown:Y=>{fe.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{fe.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{fe.dispatchEvent(new PointerEvent(Y.type,Y))}}),this._canvasFloatDomService.addFloatDom(Te),this.disposeWithMe(_.subscribe(Y=>{var It,Dt,yt,Ct;const vt=Ke({startX:Y.startX,startY:Y.startY,endX:Y.endX,endY:Y.endY,width:(It=n.width)!=null?It:Y.width,height:(Dt=n.height)!=null?Dt:Y.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Bt=j.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:N,drawingId:O}),xt=new k.Rect(Bt,{left:vt.startX,top:vt.startY,width:(yt=n.width)!=null?yt:Y.width,height:(Ct=n.height)!=null?Ct:Y.height,zIndex:this._drawingManagerService.getDrawingOrder(P,N).length-1}),Yt=le(xt,x.renderUnit.scene,H.skeleton,M.worksheet,de);ve.next(Yt)}));const Re=(b=this._renderManagerService.getRenderById(P))==null?void 0:b.with(E.SheetSkeletonManagerService);Re==null||Re.currentSkeleton$.subscribe(Y=>{Y&&H.sheetId!==Y.sheetId&&this._removeDom(w,!0)});const He=ae.onTransformChange$.subscribeEvent(()=>{const Y=le(ae,x.renderUnit.scene,H.skeleton,M.worksheet,de);ve.next(Y)});ce.add(()=>{this._canvasFloatDomService.removeFloatDom(O)}),He&&ce.add(He),this._domLayerInfoMap.set(O,de)}return{id:w,dispose:()=>{this._removeDom(w,!0)}}}addFloatDomToColumnHeader(t,e,n,s){var I,T,D;const o=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!o)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=o;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(I=this._renderManagerService.getRenderById(a))==null?void 0:I.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,w=s!=null?s:l.generateRandomId(),{position:S,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,c.skeleton),v=S;if(v.startY=0,this._getPosition(S,a)==null)return;const R={unitId:a,subUnitId:d,drawingId:w,drawingType:e.type||l.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:b,drawingId:P}=R,N=y.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:b}),O=R,M=this._univerInstanceService.getUnit(U,l.UniverInstanceType.UNIVER_SHEET);if(!M)return;const B=M.getActiveSheet().getSheetId();if(!O||!N)return;const L=(T=this._renderManagerService.getRenderById(U))==null?void 0:T.with(E.SheetSkeletonManagerService);if(!L)return;const q=L.getWorksheetSkeleton(b);if(!q)return;const{transform:J,data:H}=O,X=this._getSceneAndTransformerByDrawingSearch(U);if(X==null)return;const{scene:Q,canvas:V}=X;if(J==null||B!==b)return;const{left:x,top:me,width:fe,height:ke,angle:We,flipX:Be,flipY:xe,skewX:st,skewY:ot}=J,Ye=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:b,drawingId:P}),Le=Q.getObject(Ye);if(Le!=null){Le.transformByState({left:x,top:me,width:fe,height:ke,angle:We,flipX:Be,flipY:xe,skewX:st,skewY:ot});return}const we=Ke({startX:v.startX,startY:0,endX:S.endX,endY:S.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Fe={left:we.startX,top:we.startY,width:we.width,height:we.height,zIndex:this._drawingManagerService.getDrawingOrder(U,b).length-1},oe=new k.Rect(Ye,Fe);Q.addObject(oe,k.DRAWING_OBJECT_LAYER_INDEX),O.allowTransform!==!1&&Q.attachTransformerTo(oe);const ee=new l.DisposableCollection,Se=Q.getMainViewport(),ae={top:0,left:Se.left,bottom:Se.bottom,right:Se.right},ce={dispose:ee,rect:oe,unitId:U,subUnitId:b,boundsOfViewArea:ae,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},$e=le(oe,X.renderUnit.scene,q.skeleton,N.worksheet,ce),_e=new A.BehaviorSubject($e);ce.position$=_e;let Me={position$:_e,id:P,componentKey:O.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:F=>{V.dispatchEvent(new WheelEvent(F.type,F))},data:H,unitId:U};e.eventPassThrough&&(Me={...Me,onPointerDown:F=>{V.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{V.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{V.dispatchEvent(new PointerEvent(F.type,F))}}),this._canvasFloatDomService.addFloatDom(Me);const Ge=oe.onTransformChange$.subscribeEvent(()=>{const F=le(oe,X.renderUnit.scene,q.skeleton,N.worksheet,ce);_e.next(F)});this.disposeWithMe(_.subscribe(F=>{const ve=Ke({startX:F.startX,startY:0,endX:F.endX,endY:F.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Te=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:b,drawingId:P}),Re=new k.Rect(Te,{left:ve.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(U,b).length-1}),He=le(Re,X.renderUnit.scene,q.skeleton,N.worksheet,ce);_e.next(He)}));const de=(D=this._renderManagerService.getRenderById(U))==null?void 0:D.with(E.SheetSkeletonManagerService);de==null||de.currentSkeleton$.subscribe(F=>{F&&c.sheetId!==F.sheetId&&this._removeDom(w,!0)}),ee.add(()=>{this._canvasFloatDomService.removeFloatDom(P)}),Ge&&ee.add(Ge),this._domLayerInfoMap.set(P,ce)}return{id:w,dispose:()=>{this._removeDom(w,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:s,startColumn:o}=t;const a=Ue(s,o,n),d=new A.BehaviorSubject(a),g=Ue(t.endRow,t.endColumn,n),u=new A.BehaviorSubject(g),c=()=>{const _=Ue(s,o,n),v=Ue(t.endRow,t.endColumn,n);d.next(_),u.next(v)},p=new l.DisposableCollection;p.add(e.engine.clientRect$.subscribe(()=>c())),p.add(this._commandService.onCommandExecuted(_=>{if(_.id===y.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(C=>C.row===s)>-1){c();return}(y.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===E.SetScrollOperation.id||_.id===E.SetZoomRatioOperation.id)&&c()}));const h=(_,v)=>{s=_,o=v,c()},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}),w=d.pipe(A.map(_=>{const v=Ue(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}})),S=f();return{position$:w,position:S,updateRowCol:h,topLeftPos$:d,rightBottomPos$:u,disposable:p}}};exports.SheetCanvasFloatDomManagerService=wn([he(0,l.Inject(k.IRenderManagerService)),he(1,l.IUniverInstanceService),he(2,l.Inject(l.ICommandService)),he(3,j.IDrawingManagerService),he(4,l.Inject(W.CanvasFloatDomService)),he(5,m.ISheetDrawingService),he(6,l.Inject(l.LifecycleService))],exports.SheetCanvasFloatDomManagerService);function Ue(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,s=(g=r==null?void 0:r.width)!=null?g:e,o=(u=r==null?void 0:r.height)!=null?u:n;let a=0,d=0;if(r){if(r.horizonOffsetAlign==="right"){const c=ze(r.marginX,e*t);a=i.endX-c-s}else a=i.startX+ze(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const c=ze(r.marginY,n*t);d=i.endY-c-o}else d=i.startY+ze(r.marginY,n)}return{rotate:0,startX:a,startY:d,endX:i.endX,endY:i.endY,width:s,height:o,absolute:{left:i.absolute.left,top:i.absolute.top}}}function ze(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const t=Number.parseFloat(i);return r*t/100}const Sn=i=>{const{floatDomInfos:r,scene:t,skeleton:e,worksheet:n}=i,s=ie.useMemo(()=>r.map(o=>{const{width:a,height:d,angle:g,left:u,top:c}=o.transform,p=At({left:u!=null?u:0,right:(u!=null?u:0)+(a!=null?a:0),top:c!=null?c:0,bottom:(c!=null?c:0)+(d!=null?d:0)},t,e,n,void 0,!0),{scaleX:h,scaleY:f}=t.getAncestorScale(),w={startX:p.left,endX:p.right,startY:p.top,endY:p.bottom,rotate:g,width:a*h,height:d*f,absolute:p.absolute},S={position$:new A.BehaviorSubject(w),position:w,id:o.drawingId,componentKey:o.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:o.unitId,data:o.data};return[o.drawingId,S]}),[r,t,e,n]);return z.jsx("div",{style:{position:"absolute",top:0,left:0},children:s.map(([o,a])=>z.jsx(W.PrintFloatDomSingle,{layer:a,id:o,position:a.position},o))})};var _n=Object.getOwnPropertyDescriptor,vn=(i,r,t,e)=>{for(var n=e>1?void 0:e?_n(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},pe=(i,r)=>(t,e)=>r(t,e,i);let rt=class extends l.Disposable{constructor(i,r,t,e,n,s,o){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._canvasFloatDomManagerService=n,this._componetManager=s,this._injector=o,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:s}=r,o=this._drawingManagerService.getDrawingDataForUnit(e),a=o==null?void 0:o[s];return a&&a.order.forEach(d=>{const g=a.data[d];g.drawingType!==l.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,s=this._renderManagerService.getRenderById(e);if(!s)return t(i);const o=s.with(E.SheetSkeletonManagerService).getSkeletonParam(n);if(!o)return t(i);const a=this._drawingManagerService.getDrawingDataForUnit(e),d=a==null?void 0:a[r.subUnitId];if(!d)return t(i);const{scaleX:g,scaleY:u}=s.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},p=d.order.map(h=>d.data[h]);return p.length?(p.forEach(h=>{if(!h.groupId&&h.transform&&l.Tools.isDefine(h.transform.left)&&l.Tools.isDefine(h.transform.top)&&l.Tools.isDefine(h.transform.width)&&l.Tools.isDefine(h.transform.height)){const f=o.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),w=o.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});f.column<c.startColumn&&(c.startColumn=f.column),f.row<c.startRow&&(c.startRow=f.row),c.endRow<w.row&&(c.endRow=w.row),c.endColumn<w.column&&(c.endColumn=w.column)}}),t(c)):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,s=this._drawingManagerService.getDrawingDataForUnit(e),o=s==null?void 0:s[n];if(o){const a=o.order.map(g=>{const u=o.data[g];if(u.drawingType===l.DrawingTypeEnum.DRAWING_CHART)return{...u,componentKey:this._componetManager.get(l.PRINT_CHART_COMPONENT_KEY)};if(u.drawingType===l.DrawingTypeEnum.DRAWING_DOM){const c=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(c||u.componentKey)}}return null}).filter(Boolean),d=W.connectInjector(Sn,this._injector);return Z.render(z.jsx(d,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),i==null||i.add(()=>{Z.unmount(r.root)}),t(i)}}}))}};rt=vn([pe(0,l.Inject(E.SheetPrintInterceptorService)),pe(1,l.Inject(ge.DrawingRenderService)),pe(2,j.IDrawingManagerService),pe(3,k.IRenderManagerService),pe(4,l.Inject(exports.SheetCanvasFloatDomManagerService)),pe(5,l.Inject(W.ComponentManager)),pe(6,l.Inject(l.Injector))],rt);var In=Object.getOwnPropertyDescriptor,Dn=(i,r,t,e)=>{for(var n=e>1?void 0:e?In(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},ue=(i,r)=>(t,e)=>r(t,e,i);const yn=[y.InsertRowCommand.id,y.InsertColCommand.id,y.RemoveRowCommand.id,y.RemoveColCommand.id,y.DeleteRangeMoveLeftCommand.id,y.DeleteRangeMoveUpCommand.id,y.InsertRangeMoveDownCommand.id,y.InsertRangeMoveRightCommand.id,y.DeltaRowHeightCommand.id,y.SetRowHeightCommand.id,y.DeltaColumnWidthCommand.id,y.SetColWidthCommand.id,y.SetRowHiddenCommand.id,y.SetSpecificRowsVisibleCommand.id,y.SetSpecificColsVisibleCommand.id,y.SetColHiddenCommand.id,y.MoveColsCommand.id,y.MoveRowsCommand.id,y.MoveRangeCommand.id],Cn=[y.SetRowVisibleMutation.id,y.SetRowHiddenMutation.id,y.SetColVisibleMutation.id,y.SetColHiddenMutation.id,y.SetWorksheetRowHeightMutation.id,y.SetWorksheetColWidthMutation.id];let ut=class extends l.Disposable{constructor(i,r,t,e,n,s,o,a,d){super(),this._context=i,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=s,this._sheetDrawingService=o,this._drawingManagerService=a,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!yn.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===y.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([y.MoveColsCommand.id,y.MoveRowsCommand.id,y.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===y.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===y.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===y.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===y.DeleteRangeMoveLeftCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,0)}else if(r===y.DeleteRangeMoveUpCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,1)}else if(r===y.InsertRangeMoveDownCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,2)}else if(r===y.InsertRangeMoveRightCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,3)}else if(r===y.SetRowHiddenCommand.id||r===y.SetSpecificRowsVisibleCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:s}=t;return this._getDrawingUndoForRowVisible(e,n,s)}else if(r===y.SetSpecificColsVisibleCommand.id||r===y.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:s}=t;return this._getDrawingUndoForColVisible(e,n,s)}else if(r===y.DeltaRowHeightCommand.id||r===y.SetRowHeightCommand.id||r===y.DeltaColumnWidthCommand.id||r===y.SetColWidthCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:s}=t,o=r===y.DeltaRowHeightCommand.id||r===y.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,s,o)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const t=y.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,s=[],o=[],a=this._sheetDrawingService.getDrawingData(e,n),d=[],g=[];if(Object.keys(a).forEach(u=>{const c=a[u],{updateDrawings:p,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,c);d.push(...p),g.push(...h)}),d.length===0&&g.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:p,objects:h}=u;s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.UPDATE}}),o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),c=u.undo,p=u.redo,h=u.objects;s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.REMOVE}}),o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.INSERT}})}return s.push({id:G.id,params:[e]}),o.push({id:G.id,params:[e]}),{redos:s,undos:o}}_getUpdateOrDeleteDrawings(i,r,t){const e=[],n=[],{sheetTransform:s,anchorType:o=m.SheetDrawingAnchorType.Position,transform:a,unitId:d,subUnitId:g,drawingId:u}=t,{from:c,to:p}=s,{row:h,column:f}=c,{row:w,column:S}=p;if(s==null||a==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:_,endRow:v,startColumn:C,endColumn:R}=i;let I=null,T=null;if(r===0&&h>=_&&w<=v)if(f>=C&&S<=R)n.push({unitId:d,subUnitId:g,drawingId:u});else{const D=this._shrinkCol(s,a,C,R,o);I=D==null?void 0:D.newSheetTransform,T=D==null?void 0:D.newTransform}else if(r===1&&f>=C&&S<=R)if(h>=_&&w<=v)n.push({unitId:d,subUnitId:g,drawingId:u});else{const D=this._shrinkRow(s,a,_,v,o);I=D==null?void 0:D.newSheetTransform,T=D==null?void 0:D.newTransform}else if(r===2){const D=this._expandRow(s,a,_,v,o);I=D==null?void 0:D.newSheetTransform,T=D==null?void 0:D.newTransform}else if(r===3){const D=this._expandCol(s,a,C,R,o);I=D==null?void 0:D.newSheetTransform,T=D==null?void 0:D.newTransform}if(I!=null&&T!=null){const D=K(I,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:I,transform:D})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(i,r,t){const e=$({...i},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],s=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=c;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:w,to:S}=p,{row:_,column:v}=w,{row:C,column:R}=S;for(let I=0;I<t.length;I++){const T=t[I],{startRow:D,endRow:U,startColumn:b,endColumn:P}=T;if(R<b)continue;if(f===m.SheetDrawingAnchorType.Position){let M=null,B=null;if(v>=b&&v<=P){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:v,endColumn:P,startRow:w.row,endRow:S.row});if(L==null)return;B={...h,left:L.startX}}if(B!=null&&(M=$(B,this._selectionRenderService),M!=null&&B!=null)){n.push({...c,sheetTransform:M,transform:B});break}this._remainDrawingSize(h,n,c);continue}if(v>=b&&R<=P)continue;let N=null,O=null;if(v>=b&&v<=P){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:v,endColumn:P,startRow:w.row,endRow:S.row});if(M==null)return;O={...h,left:(M==null?void 0:M.startX)||0,width:((h==null?void 0:h.width)||0)-M.endX+M.startX}}else if(R>=b&&R<=P){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:R,startRow:w.row,endRow:S.row});if(M==null)return;O={...h,left:M.startX-((h==null?void 0:h.width)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:P,startRow:w.row,endRow:S.row});if(M==null)return;if(O={...h,width:((h==null?void 0:h.width)||0)-M.endX+M.startX},N=$(O,this._selectionRenderService),N!=null&&O!=null){s.push({...c,sheetTransform:N,transform:O});break}}if(O!=null&&(N=$(O,this._selectionRenderService)),O!=null&&N!=null){n.push({...c,sheetTransform:N,transform:O});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&s.length===0)return{redos:[],undos:[]};const{redos:o,undos:a}=this._createUndoAndRedoMutation(i,r,n),d=[],g=[];if(s.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,s);d.push(...u),g.push(...c)}return{redos:o,undos:a,preRedos:d,preUndos:g}}_createUndoAndRedoMutation(i,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:s,objects:o}=e,a=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:s,objects:o,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],d=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:o,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:a,undos:d}}_getDrawingUndoForRowVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],s=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=c;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:w,to:S}=p,{row:_,column:v}=w,{row:C,column:R}=S;for(let I=0;I<t.length;I++){const T=t[I],{startRow:D,endRow:U,startColumn:b,endColumn:P}=T;if(C<D)continue;if(f===m.SheetDrawingAnchorType.Position){let M=null,B=null;if(_>=D&&_<=U){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:_,endRow:U});if(L==null)return;B={...h,top:L.startY}}if(B!=null&&(M=$(B,this._selectionRenderService),M!=null&&B!=null)){n.push({...c,sheetTransform:M,transform:B});break}this._remainDrawingSize(h,n,c);continue}if(_>=D&&C<=U)continue;let N=null,O=null;if(_>=D&&_<=U){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:_,endRow:U});if(M==null)return;O={...h,top:(M==null?void 0:M.startY)||0,height:((h==null?void 0:h.height)||0)-M.endY+M.startY}}else if(C>=D&&C<=U){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:D,endRow:C});if(M==null)return;O={...h,top:M.startY-((h==null?void 0:h.height)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:D,endRow:U});if(M==null)return;if(O={...h,height:((h==null?void 0:h.height)||0)-M.endY+M.startY},N=$(O,this._selectionRenderService),N!=null&&O!=null){s.push({...c,sheetTransform:N,transform:O});break}}if(O!=null&&(N=$(O,this._selectionRenderService)),O!=null&&N!=null){n.push({...c,sheetTransform:N,transform:O});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&s.length===0)return{redos:[],undos:[]};const{redos:o,undos:a}=this._createUndoAndRedoMutation(i,r,n),d=[],g=[];if(s.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,s);d.push(...u),g.push(...c)}return{redos:o,undos:a,preRedos:d,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,t,e){const n=this._drawingManagerService.getDrawingData(i,r),s=[];return Object.keys(n).forEach(o=>{const a=n[o],{sheetTransform:d,transform:g,anchorType:u=m.SheetDrawingAnchorType.Position}=a;if(u===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,s,a);else{const{from:c,to:p}=d,{row:h,column:f}=c,{row:w,column:S}=p;for(let _=0;_<t.length;_++){const v=t[_],{startRow:C,endRow:R,startColumn:I,endColumn:T}=v;if(w<C||S<I)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=C&&w>=R||f<=I&&S>=T)){this._remainDrawingSize(g,s,a);continue}const D=K({...d},this._selectionRenderService,this._skeletonManagerService);if(D!=null){s.push({...a,transform:D});break}}}}),s.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,s)}_getUnitIdAndSubUnitId(i,r){let t,e;if(r==="insert")t=i.unitId,e=i.subUnitId;else{const n=y.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(i){var C,R;const{toRange:r,fromRange:t}=i,e=y.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:s}=e,o=(R=(C=this._renderManagerService.getRenderById(n))==null?void 0:C.with(E.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!o)return{redos:[],undos:[]};const a=E.attachRangeWithCoord(o,t);if(!a)return{redos:[],undos:[]};const{startX:d,endX:g,startY:u,endY:c}=a,p=this._sheetDrawingService.getDrawingData(n,s),h=[];Object.keys(p).forEach(I=>{const T=p[I];if(T.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:D}=T;if(!D)return;const{left:U=0,top:b=0,width:P=0,height:N=0}=D,{drawingStartX:O,drawingEndX:M,drawingStartY:B,drawingEndY:L}={drawingStartX:U,drawingEndX:U+P,drawingStartY:b,drawingEndY:b+N};d<=O&&M<=g&&u<=B&&L<=c&&h.push(T)});const f=[],w=[],S=r.startRow-t.startRow,_=r.startColumn-t.startColumn,v=h.map(I=>{const T=I.sheetTransform,D={to:{...T.to,row:T.to.row+S,column:T.to.column+_},from:{...T.from,row:T.from.row+S,column:T.from.column+_}},U=K(D,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:s,drawingId:I.drawingId,transform:U,sheetTransform:D}});if(v.length){const I=this._sheetDrawingService.getBatchUpdateOp(v),{undo:T,redo:D,objects:U}=I;f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:s,op:D,objects:U,type:m.DrawingApplyType.UPDATE}}),w.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:s,op:T,objects:U,type:m.DrawingApplyType.UPDATE}})}return{redos:f,undos:w}}_moveRowInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:s}=i,o=s.startRow,a=s.endRow,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:w,transform:S,anchorType:_=m.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let v,C;if(r==="insert"){const I=this._expandRow(w,S,o,a,_);v=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:T}=w,{row:D}=I,{row:U}=T;if(_===m.SheetDrawingAnchorType.Both&&D>=o&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkRow(w,S,o,a,_);v=b==null?void 0:b.newSheetTransform,C=b==null?void 0:b.newTransform}}if(!v||!C)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:v};c.push(R)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:w,objects:S}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,w=h.redo,S=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_moveColInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:s}=i,o=s.startColumn,a=s.endColumn,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:w,transform:S,anchorType:_=m.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let v,C;if(r==="insert"){const I=this._expandCol(w,S,o,a,_);v=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:T}=w,{column:D}=I,{column:U}=T;if(_===m.SheetDrawingAnchorType.Both&&D>=o&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkCol(w,S,o,a,_);v=b==null?void 0:b.newSheetTransform,C=b==null?void 0:b.newTransform}}if(!v||!C)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:v};c.push(R)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:w,objects:S}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,w=h.redo,S=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_expandCol(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const s=e-t+1,{from:o,to:a}=i,{column:d}=o,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:o.row,endRow:a.row});if(p==null)return;c={...r,left:(r.left||0)+p.endX-p.startX},u=$(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,column:g+s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const s=e-t+1,{from:o,to:a}=i,{column:d}=o,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...o,column:d-s},to:{...a,column:g-s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,column:g-s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,left:(r.left||0)-i.from.columnOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:o.row,endRow:a.row});if(p==null)return;c={...r,left:(r.left||0)-p.endX+p.startX-i.from.columnOffset}}u=$(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:o.row,endRow:a.row});if(p==null)return;u={from:{...o},to:{...a,column:t-1,columnOffset:p.endX-p.startX}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const s=e-t+1,{from:o,to:a}=i,{row:d}=o,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:o.column,endColumn:a.column});if(p==null)return;c={...r,top:(r.top||0)+p.endY-p.startY},u=$(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,row:g+s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const s=e-t+1,{from:o,to:a}=i,{row:d}=o,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...o,row:d-s},to:{...a,row:g-s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,row:g-s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,top:(r.top||0)-i.from.rowOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:o.column,endColumn:a.column});if(p==null)return;c={...r,top:(r.top||0)-p.endY+p.startY-i.from.rowOffset}}u=$(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:o.column,endColumn:o.column,startRow:t-1,endRow:t-1});if(p==null)return;u={from:{...o},to:{...a,row:t-1,rowOffset:p.endY-p.startY}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===y.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(s=>{const o=n[s].data;o!=null&&Object.keys(o).forEach(a=>{e===i&&t.push(o[a])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(i,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(s=>{const o=t[s];o!=null&&Object.keys(o).forEach(a=>{const d=o[a].data;d!=null&&Object.keys(d).forEach(g=>{if(s===i&&a===r){const u=d[g];u.transform=K(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(d[g])}else n.push(d[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Cn.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(s=>{const o=e[s],{sheetTransform:a,transform:d,anchorType:g=m.SheetDrawingAnchorType.Position}=o;if(g===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=a,{row:p,column:h}=u,{row:f,column:w}=c;for(let S=0;S<t.length;S++){const _=t[S],{startRow:v,endRow:C,startColumn:R,endColumn:I}=_;if(l.Rectangle.intersects({startRow:v,endRow:C,startColumn:R,endColumn:I},{startRow:p,endRow:f,startColumn:h,endColumn:w})||p>C||h>I){const T=g===m.SheetDrawingAnchorType.Position,D=K(a,this._selectionRenderService,this._skeletonManagerService);n.push({...o,transform:{...D,width:T?d==null?void 0:d.width:D==null?void 0:D.width,height:T?d==null?void 0:d.height:D==null?void 0:D.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[i]))}};ut=Dn([ue(1,k.IRenderManagerService),ue(2,l.ICommandService),ue(3,E.ISheetSelectionRenderService),ue(4,l.Inject(E.SheetSkeletonManagerService)),ue(5,l.Inject(y.SheetInterceptorService)),ue(6,m.ISheetDrawingService),ue(7,j.IDrawingManagerService),ue(8,l.IUniverInstanceService)],ut);var re=function(){return re=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},re.apply(this,arguments)},Mn=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},Pt=ie.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,s=i.extend,o=Mn(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),d=ie.useRef("_".concat(bn()));return Nt(t,"".concat(e),{defIds:t.defIds,idSuffix:d.current},re({ref:r,className:a},o),s)});function Nt(i,r,t,e,n){return ie.createElement(i.tag,re(re({key:r},Tn(i,t,n)),e),(Rn(i,t).children||[]).map(function(s,o){return Nt(s,"".concat(r,"-").concat(i.tag,"-").concat(o),t,void 0,n)}))}function Tn(i,r,t){var e=re({},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(s){var o=s[0],a=s[1];o==="mask"&&typeof a=="string"&&(e[o]=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(s){var o=s[0],a=s[1];typeof a=="string"&&(e[o]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Rn(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)?re(re({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?re(re({},n),{attrs:re(re({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function bn(){return Math.random().toString(36).substring(2,8)}Pt.displayName="UniverIcon";var En={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"}}]},jt=ie.forwardRef(function(i,r){return ie.createElement(Pt,Object.assign({},i,{id:"add-image-single",ref:r,icon:En}))});jt.displayName="AddImageSingle";const St={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),e=i.get(m.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,s=e.map(o=>{const{unitId:a,subUnitId:d,drawingId:g,drawingType:u}=o;return{unitId:a,subUnitId:d,drawingId:g,drawingType:u}});return r.executeCommand(ye.id,{unitId:n,drawings:s})}},Ce={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(m.ISheetDrawingService),n=i.get(E.ISheetSelectionRenderService),{direction:s}=r,o=e.getFocusDrawings();if(o.length===0)return!1;const a=o[0].unitId,d=o.map(u=>{const{transform:c}=u;if(c==null)return null;const p={...c},{left:h=0,top:f=0}=c;return s===l.Direction.UP?p.top=f-1:s===l.Direction.DOWN?p.top=f+1:s===l.Direction.LEFT?p.left=h-1:s===l.Direction.RIGHT&&(p.left=h+1),{...u,transform:p,sheetTransform:$(p,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(Pe.id,{unitId:a,drawings:d})?(t.syncExecuteCommand(G.id,[a]),!0):!1}},kt="addition-and-subtraction-single",_t="sheet.menu.image";function On(i){return{id:_t,type:W.MenuItemType.SUBITEMS,icon:kt,tooltip:"sheetImage.title",hidden$:W.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(i,{workbookTypes:[y.WorkbookEditablePermission],worksheetTypes:[y.WorksheetEditPermission],rangeTypes:[y.RangeProtectionPermissionEditPoint]})}}function Un(i){return{id:Ne.id,title:"sheetImage.upload.float",type:W.MenuItemType.BUTTON,hidden$:W.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function An(i){return{id:wt.id,title:"sheetImage.upload.cell",type:W.MenuItemType.BUTTON,hidden$:W.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}const Pn=i=>{var v;const r=W.useDependency(l.ICommandService),t=W.useDependency(l.LocaleService),e=W.useDependency(j.IDrawingManagerService),n=W.useDependency(k.IRenderManagerService),{drawings:s}=i,o=s[0];if(o==null)return;const{unitId:a}=o,d=n.getRenderById(a),g=d==null?void 0:d.scene;if(g==null)return;const u=g.getTransformerByCreate(),[c,p]=ie.useState(!0),h=(v=o.anchorType)!=null?v:m.SheetDrawingAnchorType.Position,[f,w]=ie.useState(h);function S(C,R){const I=[];return C.forEach(T=>{const{oKey:D}=T,U=R.getDrawingOKey(D);if(U==null)return I.push(null),!0;const{unitId:b,subUnitId:P,drawingId:N,drawingType:O,anchorType:M,sheetTransform:B}=U;I.push({unitId:b,subUnitId:P,drawingId:N,anchorType:M,sheetTransform:B,drawingType:O})}),I}ie.useEffect(()=>{const C=u.clearControl$.subscribe(I=>{I===!0&&p(!1)}),R=u.changeStart$.subscribe(I=>{var U;const{objects:T}=I,D=S(T,e);if(D.length===0)p(!1);else if(D.length>=1){p(!0);const b=((U=D[0])==null?void 0:U.anchorType)||m.SheetDrawingAnchorType.Position;w(b)}});return()=>{R.unsubscribe(),C.unsubscribe()}},[]);function _(C){w(C);const R=e.getFocusDrawings();if(R.length===0)return;const I=R.map(T=>({unitId:T.unitId,subUnitId:T.subUnitId,drawingId:T.drawingId,anchorType:C}));r.executeCommand(Pe.id,{unitId:R[0].unitId,drawings:I})}return z.jsxs("div",{className:Z.clsx("univer-relative univer-mt-5 univer-w-full",Z.borderTopClassName,{"univer-hidden":!c}),children:[z.jsx("div",{className:"univer-relative univer-mt-2.5 univer-flex univer-h-full",children:z.jsx("div",{className:"univer-w-full univer-text-left univer-text-gray-400",children:z.jsx("div",{children:t.t("drawing-anchor.title")})})}),z.jsx("div",{className:"univer-relative univer-mt-2.5 univer-flex univer-h-full",children:z.jsx("div",{className:"univer-flex univer-items-center univer-gap-1",children:z.jsxs(Z.RadioGroup,{value:f,onChange:_,direction:"vertical",children:[z.jsx(Z.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),z.jsx(Z.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),z.jsx(Z.Radio,{value:m.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})})]})},Nn=()=>{const i=W.useDependency(j.IDrawingManagerService),r=i.getFocusDrawings(),[t,e]=ie.useState(r);return ie.useEffect(()=>{const n=i.focus$.subscribe(s=>{e(s)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&z.jsxs("div",{className:"univer-p-2 univer-text-center univer-text-sm",children:[z.jsx(ge.DrawingCommonPanel,{drawings:t}),z.jsx(Pn,{drawings:t})]})},jn={[W.RibbonStartGroup.FORMULAS_INSERT]:{[_t]:{order:3,menuItemFactory:On,[Ne.id]:{order:0,menuItemFactory:Un},[wt.id]:{order:1,menuItemFactory:An}}}};function je(i){return!i.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(l.EDITOR_ACTIVATED)&&!i.getContextValue(l.FOCUSING_PANEL_EDITOR)&&i.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const kn={id:Ce.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:W.KeyCode.ARROW_DOWN,priority:100,preconditions:je,staticParameters:{direction:l.Direction.DOWN}},Wn={id:Ce.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:W.KeyCode.ARROW_UP,priority:100,preconditions:je,staticParameters:{direction:l.Direction.UP}},Bn={id:Ce.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:W.KeyCode.ARROW_LEFT,priority:100,preconditions:je,staticParameters:{direction:l.Direction.LEFT}},xn={id:Ce.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:W.KeyCode.ARROW_RIGHT,priority:100,preconditions:je,staticParameters:{direction:l.Direction.RIGHT}},Yn={id:St.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:je,binding:W.KeyCode.DELETE,mac:W.KeyCode.BACKSPACE};var Ln=Object.getOwnPropertyDescriptor,Fn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Ln(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},De=(i,r)=>(t,e)=>r(t,e,i);let it=class extends l.Disposable{constructor(i,r,t,e,n,s){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=s,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(kt,jt)),this.disposeWithMe(i.register(Et,Nn))}_initMenus(){this._menuManagerService.mergeMenu(jn)}_initCommands(){[Ne,wt,Ae,ye,Pe,gt,G,ht,pt,ft,Ce,St,mt].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[kn,Wn,Bn,xn,Yn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};it=Fn([De(0,l.Inject(W.ComponentManager)),De(1,W.IMenuManagerService),De(2,l.ICommandService),De(3,W.IShortcutService),De(4,j.IDrawingManagerService),De(5,l.Inject(y.SheetsSelectionsService))],it);var $n=Object.defineProperty,Gn=Object.getOwnPropertyDescriptor,Hn=(i,r,t)=>r in i?$n(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,Vn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Gn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},at=(i,r)=>(t,e)=>r(t,e,i),Wt=(i,r,t)=>Hn(i,typeof r!="symbol"?r+"":r,t);const Xn="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=Mt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:s,...o}=l.merge({},Mt,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig($t,o)}onStarting(){l.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[it],[qe],[rt],[nt],[tt],[Je],[Qe],[et]]),l.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[tt],[et]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[nt],[rt],[it],[Je],[Qe]])}onSteady(){this._injector.get(qe)}_registerRenderModules(){[[exports.SheetDrawingUpdateController],[ut],[dt],[ct]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}};Wt(exports.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);Wt(exports.UniverSheetsDrawingUIPlugin,"pluginName",Xn);exports.UniverSheetsDrawingUIPlugin=Vn([l.DependentOn(j.UniverDrawingPlugin,bt.UniverDocsDrawingPlugin,ge.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),at(1,l.Inject(l.Injector)),at(2,k.IRenderManagerService),at(3,l.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=G;exports.DeleteDrawingsCommand=St;exports.EditSheetDrawingOperation=ht;exports.GroupSheetDrawingCommand=pt;exports.InsertFloatImageCommand=Ne;exports.InsertSheetDrawingCommand=Ae;exports.MoveDrawingsCommand=Ce;exports.RemoveSheetDrawingCommand=ye;exports.SHEETS_IMAGE_MENU_ID=_t;exports.SetDrawingArrangeCommand=mt;exports.SetSheetDrawingCommand=Pe;exports.SidebarSheetDrawingOperation=gt;exports.UngroupSheetDrawingCommand=ft;