@univerjs/sheets-drawing-ui 0.6.10-experimental.20250428-2b6408c → 0.6.10-experimental.20250428-8c74c87

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,2 +1,2 @@
1
1
  "use strict";var Ft=Object.defineProperty;var Gt=(i,r,t)=>r in i?Ft(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t;var ne=(i,r,t)=>Gt(i,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),Ot=require("@univerjs/docs-drawing"),j=require("@univerjs/drawing"),he=require("@univerjs/drawing-ui"),k=require("@univerjs/engine-render"),p=require("@univerjs/sheets-drawing"),E=require("@univerjs/sheets-ui"),W=require("@univerjs/ui"),A=require("rxjs"),y=require("@univerjs/sheets"),X=require("react/jsx-runtime"),J=require("react"),Je=require("@univerjs/docs-ui"),z=require("@univerjs/design"),Ht="sheets-drawing-ui.config",Rt={},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,o;(o=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},Ce={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),o=i.get(p.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,a=[];s.forEach(D=>{const{unitId:T}=D;a.push(T)});const d=o.getBatchRemoveOp(s),{unitId:g,subUnitId:u,undo:c,redo:m,objects:h}=d,f=n.onCommandExecute({id:Ce.id,params:r}),w={id:p.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:m,objects:h,type:p.DrawingApplyType.REMOVE}},S={id:p.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:c,objects:h,type:p.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}},Ut="COMPONENT_SHEET_DRAWING_PANEL",mt={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),o=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:Ut},onClose:()=>{o.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},pt={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(mt.id,{value:"open"}),!0)}},Vt="univer-upload-loading",Xt="univer-upload-loading-body",Kt="univer-upload-loading-body-animation",zt="univer-upload-loading-body-text",Xe={uploadLoading:Vt,uploadLoadingBody:Xt,uploadLoadingBodyAnimation:Kt,uploadLoadingBodyText:zt},Zt=()=>{const i=W.useDependency(j.IImageIoService),r=W.useDependency(l.LocaleService),[t,e]=J.useState(0);return J.useEffect(()=>{const n=i.change$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[i]),X.jsx("div",{style:{display:t>0?"block":"none"},className:Xe.uploadLoading,children:X.jsxs("div",{className:Xe.uploadLoadingBody,children:[X.jsx("div",{className:Xe.uploadLoadingBodyAnimation}),X.jsx("div",{className:Xe.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${t}`})]})})};var qt=Object.getOwnPropertyDescriptor,Jt=(i,r,t,e)=>{for(var n=e>1?void 0:e?qt(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},le=(i,r)=>(t,e)=>r(t,e,i);let Qe=class extends l.RxDisposable{constructor(r,t,e,n,o,s,a,d){super();ne(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=t,this._canvasPopManagerService=e,this._renderManagerService=n,this._univerInstanceService=o,this._contextService=s,this._uiPartsService=a,this._commandService=d,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._uiPartsService.registerComponent(W.BuiltInUIPart.CONTENT,()=>W.connectInjector(Zt,this._injector))}_dispose(r){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 he.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const t=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(l.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const s=e.getSelectedObjectMap();if(s.size>1){n==null||n.dispose();return}const a=s.values().next().value;if(!a)return;const d=a.oKey,g=this._drawingManagerService.getDrawingOKey(d);if(!g)return;const{unitId:u,subUnitId:c,drawingId:m,drawingType:h}=g,f=g.data;if(f&&f.disablePopup)return;n==null||n.dispose();const w=this._canvasPopManagerService.getFeatureMenu(u,c,m,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:he.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:w||this._getImageMenuItems(u,c,m,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(s=>{s[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:pt.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Ce.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:he.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:he.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===l.DrawingTypeEnum.DRAWING_DOM}]}};Qe=Jt([le(0,l.Inject(l.Injector)),le(1,j.IDrawingManagerService),le(2,l.Inject(E.SheetCanvasPopManagerService)),le(3,k.IRenderManagerService),le(4,l.IUniverInstanceService),le(5,l.IContextService),le(6,l.Inject(W.IUIPartsService)),le(7,l.ICommandService)],Qe);var Qt=Object.getOwnPropertyDescriptor,en=(i,r,t,e)=>{for(var n=e>1?void 0:e?Qt(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ke=(i,r)=>(t,e)=>r(t,e,i);let lt=class extends l.Disposable{constructor(r,t,e,n,o){super();ne(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=t,this._selectionsService=e,this._drawingRenderService=n,this._sheetSkeletonManagerService=o,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(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}}))}};lt=en([Ke(1,l.Inject(E.HoverManagerService)),Ke(2,l.Inject(y.SheetsSelectionsService)),Ke(3,l.Inject(he.DrawingRenderService)),Ke(4,l.Inject(E.SheetSkeletonManagerService))],lt);function Z(i,r,t){const{from:e,to:n,flipY:o=!1,flipX:s=!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:m,top:h,width:f,height:w}=c;const S=t.getCurrentSkeleton(),_=S.rowHeaderWidth+S.columnTotalWidth,v=S.columnHeaderHeight+S.rowTotalHeight;return m+f>_&&(m=_-f),h+w>v&&(h=v-w),{flipY:o,flipX:s,angle:a,skewX:d,skewY:g,left:m,top:h,width:f,height:w}}function F(i,r){const{left:t=0,top:e=0,width:n=0,height:o=0,flipY:s=!1,flipX:a=!1,angle:d=0,skewX:g=0,skewY:u=0}=i,c=r.getCellWithCoordByOffset(t,e);if(c==null)return;const m={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+o);if(h==null)return;const f={column:h.actualColumn,columnOffset:k.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:k.precisionTo(e+o-h.startY,1)};return{flipY:s,flipX:a,angle:d,skewX:g,skewY:u,from:m,to:f}}var tn=Object.getOwnPropertyDescriptor,nn=(i,r,t,e)=>{for(var n=e>1?void 0:e?tn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},ze=(i,r)=>(t,e)=>r(t,e,i);let ut=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=Z(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};ut=nn([ze(1,p.ISheetDrawingService),ze(2,j.IDrawingManagerService),ze(3,l.Inject(E.ISheetSelectionRenderService)),ze(4,l.Inject(E.SheetSkeletonManagerService))],ut);function rn(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:s,drawingId:a}=e,d=k.getGroupState(0,0,n.map(c=>c.transform||{})),g=n.map(c=>{const m=c.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:w}=c;return{unitId:h,subUnitId:f,drawingId:w,transform:{...m,left:m.left-d.left,top:m.top-d.top},groupId:a}}),u={unitId:o,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:d};r.push({parent:u,children:g})}),r}function on(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:s,drawingId:a,transform:d={width:0,height:0}}=e;if(d==null)return;const g=n.map(c=>{const{transform:m}=c,{unitId:h,subUnitId:f,drawingId:w}=c,S=k.transformObjectOutOfGroup(m||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:f,drawingId:w,transform:S,groupId:void 0}}),u={unitId:o,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const ft={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(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(w=>{o.push(w.unitId)})});const s=n.getGroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=s;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:on(c),type:p.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!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(p.ISheetDrawingService),o=i.get(y.SheetInterceptorService);if(!r)return!1;const s=r.drawings,a=s.map(D=>D.unitId),d=n.getBatchAddOp(s),{unitId:g,subUnitId:u,undo:c,redo:m,objects:h}=d,f=o.onCommandExecute({id:Ae.id,params:r}),w={id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:g,subUnitId:u,objects:h,type:p.DrawingApplyType.INSERT}},S={id:p.SetDrawingApplyMutation.id,params:{op:c,unitId:g,subUnitId:u,objects:h,type:p.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}},wt={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(p.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:a,arrangeType:d}=r,g={unitId:o,subUnitId:s,drawingIds:a};let u;if(d===l.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):d===l.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):d===l.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):d===l.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:c,redo:m,undo:h}=u;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:m,unitId:o,subUnitId:s,objects:c,type:p.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:s,objects:c,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:s,objects:c,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}},Ne={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(p.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,s=n.getBatchUpdateOp(o),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=s;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:a,subUnitId:d,op:u,objects:c,type:p.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:g,objects:c,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:u,objects:c,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}]}),!0):!1}},St={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(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(w=>{o.push(w.unitId)})});const s=n.getUngroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=s;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:rn(c),type:p.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};var sn=Object.getOwnPropertyDescriptor,an=(i,r,t,e)=>{for(var n=e>1?void 0:e?sn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},re=(i,r)=>(t,e)=>r(t,e,i);function cn(i,r,t){const e=t*Math.PI/180,n=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),o=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:o}}function gt(i,r,t,e,n){var v;const{rotatedHeight:o,rotatedWidth:s}=cn(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),m=c.mergeInfo.endX-c.mergeInfo.startX-2,h=c.mergeInfo.endY-c.mergeInfo.startY-2,f=s/o,S=Math.ceil(Math.min(m,h*f))/s,_=!S||Number.isNaN(S)?.001:S;return{width:t*_,height:e*_}}exports.SheetDrawingUpdateController=class extends l.Disposable{constructor(t,e,n,o,s,a,d,g,u,c,m,h,f){super();ne(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=o,this._imageIoService=s,this._fileOpenerService=a,this._sheetDrawingService=d,this._drawingManagerService=g,this._contextService=u,this._messageService=c,this._localeService=m,this._injector=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:o,subUnitId:s}=n,{imageId:a,imageSourceType:d,source:g,base64Cache:u}=e,{width:c,height:m,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||m>j.DRAWING_IMAGE_HEIGHT_LIMIT){const C=j.DRAWING_IMAGE_WIDTH_LIMIT/c,R=j.DRAWING_IMAGE_HEIGHT_LIMIT/m;S=Math.max(C,R)}const _=this._getImagePosition(c*S,m*S,f,w);if(_==null)return;const v={unitId:o,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:d,source:g,transform:Z(_,this._selectionRenderService,this._skeletonManagerService),sheetTransform:_};return this._commandService.executeCommand(Ae.id,{unitId:o,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:z.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:z.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):D===j.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:z.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:o,imageSourceType:s,source:a,base64Cache:d}=n,{width:g,height:u,image:c}=await j.getImageSize(d||"");this._imageIoService.addImageSourceCache(a,s,c);const m=this._workbookSelections.getCurrentLastSelection();if(!m)return!1;const h=l.createDocumentModelWithStyle("",{}),f=gt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:m.primary.actualRow,col:m.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:o,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:Je.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:m.primary.actualRow]:{[(C=e==null?void 0:e.col)!=null?C:m.primary.actualColumn]:{p:h.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,f;const{width:n,height:o,image:s}=await j.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,l.ImageSourceType.URL,s);const a=this._workbookSelections.getCurrentLastSelection();if(!a)return!1;const d=l.createDocumentModelWithStyle("",{}),g=gt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:a.primary.actualRow,col:a.primary.actualColumn},n,o,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},c={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:t,transform:Je.docDrawingPositionToTransform(u),docTransform:u,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},m=l.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[c],selection:{collapsed:!0,startOffset:0,endOffset:0}});return m?(d.apply(m),this._commandService.syncExecuteCommand(y.SetRangeValuesCommand.id,{value:{[(h=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(),o=e.getSheetId();return{unitId:n,subUnitId:o}}_getImagePosition(t,e,n,o){const s=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};s&&s.length>0&&(a=s[s.length-1].range);const d=E.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(d==null)return;let{startColumn:g,startRow:u,startX:c,startY:m}=d,h=!1;if(c+t>n&&(c=n-t,c<0&&(c=0,t=n),h=!0),m+e>o&&(m=o-e,m<0&&(m=0,e=o),h=!0),h){const _=this._selectionRenderService.getCellWithCoordByOffset(c,m);if(_==null)return;c=_.startX,m=_.startY,g=_.actualColumn,u=_.actualRow}const f={column:g,columnOffset:0,row:u,rowOffset:0},w=this._selectionRenderService.getCellWithCoordByOffset(c+t,m+e);if(w==null)return;const S={column:w.actualColumn,columnOffset:c+t-w.startX,row:w.actualRow,rowOffset:m+e-w.startY};return{from:f,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:o,arrangeType:s}=t;this._commandService.executeCommand(wt.id,{unitId:e,subUnitId:n,drawingIds:o,arrangeType:s})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:o,subUnitId:s,drawingId:a,drawingType:d,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:a});if(u==null||u.unitId!==this._context.unitId)return;const c=F({...u.transform,...g},this._selectionRenderService);if(c==null)return;const m={...n,transform:{...u.transform,...g,...Z(c,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...c}};e.push(m)}),e.length>0&&this._commandService.executeCommand(Ne.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(ft.id,t);const{unitId:e,subUnitId:n,drawingId:o}=t[0].parent;this._commandService.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:o}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(St.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=an([re(1,l.Inject(E.SheetSkeletonManagerService)),re(2,l.ICommandService),re(3,E.ISheetSelectionRenderService),re(4,j.IImageIoService),re(5,W.ILocalFileService),re(6,p.ISheetDrawingService),re(7,j.IDrawingManagerService),re(8,l.IContextService),re(9,W.IMessageService),re(10,l.Inject(l.LocaleService)),re(11,l.Inject(y.SheetsSelectionsService)),re(12,l.Inject(l.Injector))],exports.SheetDrawingUpdateController);var dn=Object.getOwnPropertyDescriptor,ln=(i,r,t,e)=>{for(var n=e>1?void 0:e?dn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},De=(i,r)=>(t,e)=>r(t,e,i);function Pt(i,r,t){var e,n,o,s;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((s=(o=t.p)==null?void 0:o.drawingsOrder)==null?void 0:s.length)===1){const a=t.p.drawings[t.p.drawingsOrder[0]],d=gt(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 et=class extends l.Disposable{constructor(i,r,t,e,n,o){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=o,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===Je.ReplaceSnapshotCommand.id&&i.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(y.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:y.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,t)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0},Pt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),t(i)}}))}};et=ln([De(0,l.ICommandService),De(1,l.Inject(y.SheetInterceptorService)),De(2,l.Inject(l.Injector)),De(3,j.IDrawingManagerService),De(4,l.Inject(Ot.DocDrawingController)),De(5,l.Inject(E.IEditorBridgeService))],et);var un=Object.getOwnPropertyDescriptor,gn=(i,r,t,e)=>{for(var n=e>1?void 0:e?un(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},bt=(i,r)=>(t,e)=>r(t,e,i);let tt=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,o,s)=>{Pt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},s)})}}))}};tt=gn([bt(0,l.Inject(E.IAutoFillService)),bt(1,l.Inject(l.Injector))],tt);var hn=Object.getOwnPropertyDescriptor,mn=(i,r,t,e)=>{for(var n=e>1?void 0:e?hn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ee=(i,r)=>(t,e)=>r(t,e,i);const pn=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,l.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let nt=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===Je.InnerPasteCommand.id){const e=i.params,{doc:n}=e,o=this._univerInstanceService.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_DOC);if(o==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const s=o.getUnitId();if(pn.includes(s)){if(s!==l.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const a=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(E.SetCellEditVisibleOperation.id,{visible:!1})};((t=o.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")}}}))}};nt=mn([Ee(0,l.ICommandService),Ee(1,l.IUniverInstanceService),Ee(2,W.IDialogService),Ee(3,k.IRenderManagerService),Ee(4,l.Inject(l.LocaleService))],nt);const je={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{var s,a;const t=i.get(l.IUniverInstanceService),e=i.get(k.IRenderManagerService),n=(s=k.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:s.with(exports.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const d=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(d)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},_t={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 fn=Object.getOwnPropertyDescriptor,wn=(i,r,t,e)=>{for(var n=e>1?void 0:e?fn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Oe=(i,r)=>(t,e)=>r(t,e,i);const At="image/png";function Sn(i){const r=i.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=t.charCodeAt(o);return new Blob([n],{type:At})}function _n(i){const r=new ClipboardItem({[At]:Sn(i)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function vn(){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 Et=[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 rt=class extends l.Disposable{constructor(r,t,e,n,o){super();ne(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const o=this._focusedDrawings;if(o.length>0){const[s]=o;if(n===E.COPY_TYPE.CUT){const d={unitId:r,drawings:[s]};this._commandService.executeCommand(Ce.id,d)}setTimeout(()=>{const d=vn();s.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&s.imageSourceType===j.ImageSourceType.BASE64?_n(s.source):this._clipboardInterfaceService.writeText(""),d()},200);const a={unitId:s.unitId,subUnitId:s.subUnitId,drawings:[s]};this._copyInfo=a}else{const s=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=s}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=E.COPY_TYPE.COPY,pasteType:s}=n,{range:a}=r||{},{range:d,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:s,unitId:g,subUnitId:u,pasteRange:d},{copyRange:a,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:s},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:je.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var m;const n=(m=this._renderManagerService.getRenderById(r))==null?void 0:m.with(E.SheetSkeletonManagerService);if(!n)return;const o=n.attachRangeWithCoord(e);if(!o)return;const{startX:s,endX:a,startY:d,endY:g}=o,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!==p.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};s<=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(Et.includes(e))return{redos:[],undos:[]};const{unitId:o,subUnitId:s,range:a}=n,d=this._renderManagerService.getRenderById(o),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:m}=c,h=E.discreteRangeToRange(a);return this._generateMutations(m,{unitId:o,subUnitId:s,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=F(_,u))!=null?v:w}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:o,isCut:s}=t,a=[],d=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:c,sheetTransform:m}=u;if(!c)return;const h=o(c,m),f={...u,unitId:e,subUnitId:n,drawingId:s?u.drawingId:l.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(s){const{undo:w,redo:S,objects:_}=g.getBatchUpdateOp([f]);a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:p.DrawingApplyType.UPDATE,op:S,objects:_}}),d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:p.DrawingApplyType.UPDATE,op:w,objects:_}})}else{const{undo:w,redo:S,objects:_}=g.getBatchAddOp([f]);a.push({id:p.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:n,objects:_,type:p.DrawingApplyType.INSERT}}),d.push({id:p.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:_,type:p.DrawingApplyType.REMOVE}})}}),{redos:a,undos:d}}_generateRangeDrawingsPasteMutations(r,t){var U;const{unitId:e,subUnitId:n,pasteType:o,pasteRange:s}=r,{copyRange:a,copyType:d}=t;if(Et.includes(o))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(s)},pasteType:o},d);const{ranges:[c,m],mapFunc:h}=E.virtualizeDiscreteRanges([a,s]),{row:f,col:w}=h(c.startRow,c.startColumn),{row:S,col:_}=h(m.startRow,m.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,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)+D},sheetTransform:{...P,to:{...P.to,row:P.to.row+T,column:P.to.column+I},from:{...P.from,row:P.from.row+T,column:P.from.column+I}}}},isCut:d===E.COPY_TYPE.CUT})}};rt=wn([Oe(0,E.ISheetClipboardService),Oe(1,k.IRenderManagerService),Oe(2,j.IDrawingManagerService),Oe(3,W.IClipboardInterfaceService),Oe(4,l.ICommandService)],rt);var In=Object.getOwnPropertyDescriptor,Dn=(i,r,t,e)=>{for(var n=e>1?void 0:e?In(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ue=(i,r)=>(t,e)=>r(t,e,i);let it=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(o=>{if(!o){this._drawingManagerService.setDrawingVisible(!1);return}const s=e.getUnitId(),a=o.getSheetId();this._permissionService.composePermission([new y.WorkbookViewPermission(s).id,new y.WorksheetViewPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,o)})):(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),o=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===k.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=A.combineLatest([i,r]);this.disposeWithMe(t.pipe(A.switchMap(([e,n])=>e?e.activeSheet$.pipe(A.tap(o=>{if(!o){this._drawingManagerService.setDrawingEditable(!1);return}const s=e.getUnitId(),a=o.getSheetId();this._permissionService.composePermission([new y.WorkbookEditablePermission(s).id,new y.WorksheetEditPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,o)})):(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),o=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===k.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&a.detachTransformerFrom(g)})}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(A.combineLatest([i,r]).pipe(A.switchMap(([t,e])=>t?t.activeSheet$.pipe(A.switchMap(n=>{if(!n)return A.EMPTY;const o=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),d=a==null?void 0:a.scene;if(!d)return A.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookViewPermission(o).id,new y.WorksheetViewPermission(o,s).id]).pipe(A.map(c=>c.every(m=>m.value)),A.distinctUntilChanged()).pipe(A.map(c=>({permission:c,scene:d,transformer:g,unitId:o,subUnitId:s})))})):A.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:s})=>{this._drawingManagerService.setDrawingVisible(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(o,s),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(),o=e==null?void 0:e.getSheetId();if(!n||!o)return;const s=this._drawingManagerService.getDrawingData(n,o),a=Object.values(s);this._drawingManagerService.addNotification(a)}}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(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 o=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),d=a==null?void 0:a.scene;if(!d)return A.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookEditablePermission(o).id,new y.WorksheetEditPermission(o,s).id]).pipe(A.map(c=>c.every(m=>m.value)),A.distinctUntilChanged()).pipe(A.map(c=>({permission:c,scene:d,transformer:g,unitId:o,subUnitId:s})))})):A.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:s})=>{this._drawingManagerService.setDrawingEditable(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(o,s),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 o=n.getSheetId(),s=this._renderManagerService.getRenderById(e),a=s==null?void 0:s.scene;if(!a)return;const d=this._drawingManagerService.getDrawingData(e,o),g=Object.values(d);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(c=>{c.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(m=>c.oKey.includes(m.drawingId))&&a.detachTransformerFrom(c)})}}))}};it=Dn([Ue(0,j.IDrawingManagerService),Ue(1,k.IRenderManagerService),Ue(2,l.IPermissionService),Ue(3,l.IUniverInstanceService),Ue(4,l.Inject(l.UserManagerService))],it);var yn=Object.getOwnPropertyDescriptor,Cn=(i,r,t,e)=>{for(var n=e>1?void 0:e?yn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},me=(i,r)=>(t,e)=>r(t,e,i);function Nt(i,r,t,e,n,o=!1){const{scaleX:s,scaleY:a}=r.getAncestorScale(),d=r.getViewport(k.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=e.getFreeze(),{startColumn:u,startRow:c,xSplit:m,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:P}=t,N={top:o?0:P,left:o?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)+P,Y=t.colStartX(u-m)+b,q=t.rowStartY(c)+P,Q=t.colStartX(u)+b;if(m===0)f.left=!1,O=(w-D)*s,M=(S-D)*s;else{const V=w-(Y-b),x=S-(Y-b);S<Q?(O=V*s,M=x*s):w<=Q&&S>=Q?(O=V*s,M=Math.max(R,(S-D)*s)):w>Q&&(f.left=!1,O=Math.max((w-D)*s,R),M=Math.max((S-D)*s,R))}let H=0,K=0;if(h===0)f.top=!1,H=(_-T)*a,K=(v-T)*a;else{const V=_-(B-P),x=v-(B-P);v<q?(H=V*a,K=x*a):_<=q&&v>=q?(H=V*a,K=Math.max(C,(v-T)*a)):_>q&&(f.top=!1,H=Math.max((_-T)*a,C),K=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),K=Math.max(K,N.top),{left:O,right:M,top:H,bottom:K,absolute:f}}const de=(i,r,t,e,n)=>{const{left:o,top:s,width:a,height:d,angle:g}=i,u={left:o,right:o+a,top:s,bottom:s+d},c=Nt(u,r,t,e,n),{scaleX:m,scaleY:h}=r.getAncestorScale();return{startX:c.left,endX:c.right,startY:c.top,endY:c.bottom,rotate:g,width:a*m,height:d*h,absolute:c.absolute}};exports.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(t,e,n,o,s,a,d){super();ne(this,"_domLayerInfoMap",new Map);ne(this,"_transformChange$",new A.Subject);ne(this,"transformChange$",this._transformChange$.asObservable());ne(this,"_add$",new A.Subject);ne(this,"add$",this._add$.asObservable());ne(this,"_remove$",new A.Subject);ne(this,"remove$",this._remove$.asObservable());this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=o,this._canvasFloatDomService=s,this._sheetDrawingService=a,this._lifecycleService=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 o=n.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:n,transformer:o,renderUnit:e,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var V;const{unitId:n,subUnitId:o,drawingId:s}=e,a=y.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),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(o);if(!c)return;const{transform:m,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(m==null)return!0;if(u!==o)return;const{left:v,top:C,width:R,height:D,angle:T,flipX:I,flipY:U,skewX:b,skewY:P}=m,N=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),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:P});return}const M={left:v,top:C,width:R,height:D,zIndex:this._drawingManagerService.getDrawingOrder(n,o).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 Y=new k.Rect(N,M);B&&Y.setObjectType(k.ObjectType.CHART),S.addObject(Y,k.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo(Y);const q=new l.DisposableCollection,Q=de(Y,w.renderUnit.scene,c.skeleton,a.worksheet),H=new A.BehaviorSubject(Q),K={dispose:q,rect:Y,position$:H,unitId:n,subUnitId:o,id:s};this._canvasFloatDomService.addFloatDom({position$:H,id:s,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 ee=Y.onTransformChange$.subscribeEvent(()=>{const x=de(Y,w.renderUnit.scene,c.skeleton,a.worksheet);H.next(x)});q.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),ee&&q.add(ee),this._domLayerInfoMap.set(s,K)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{const{unitId:n,subUnitId:o,drawingId:s}=e,a=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{transformer:g,scene:u}=d,c=u.getObject(a);c!=null&&c.oKey&&g.clearControlByIds([c==null?void 0:c.oKey])})}))}_scrollUpdateListener(){const t=(e,n)=>{var g;const o=this._getSceneAndTransformerByDrawingSearch(e),s=Array.from(this._domLayerInfoMap.keys()).map(u=>({id:u,...this._domLayerInfoMap.get(u)})).filter(u=>u.subUnitId===n&&u.unitId===e).map(u=>u.id),a=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(E.SheetSkeletonManagerService).getSkeletonParam(n);!o||!a||!d||s.forEach(u=>{const c=this._domLayerInfoMap.get(u);if(c){const m=de(c.rect,o.renderUnit.scene,d.skeleton,a.worksheet,c);c.position$.next(m)}})};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(),o=this._renderManagerService.getRenderById(n);return o?{render:o,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:o}=e;t(n,o)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===E.SetZoomRatioOperation.id){const n=e.params,{unitId:o}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===o).map(a=>a.subUnitId).forEach(a=>{t(o,a)})}else if(e.id===y.SetFrozenMutation.id){const{unitId:n,subUnitId:o}=e.params;t(n,o)}}))}_getPosition(t,e){var h;const{startX:n,endX:o,startY:s,endY:a}=t,d=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(E.ISheetSelectionRenderService);if(d==null)return;const g=d.getCellWithCoordByOffset(n,s);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:s-g.startY},c=d.getCellWithCoordByOffset(o,a);if(c==null)return;const m={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:a-c.startY};return{from:u,to:m}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(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 o={...n.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,o){const s=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(t);if(s&&a){const{scene:d}=a,g=j.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=d.getObject(g);u&&u instanceof k.Rect&&u.setProps(o)}}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:o,subUnitId:s}=n,{initPosition:a,componentKey:d,data:g,allowTransform:u=!0}=t,c=e!=null?e:l.generateRandomId(),m=this._getPosition(a,o);if(m==null)return;const h={unitId:o,subUnitId:s,drawingId:c,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:m,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Ae.id,{unitId:o,drawings:[h]}),this._add$.next({unitId:o,subUnitId:s,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:o,subUnitId:s}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(o);if(a&&a.scene.removeObject(n.rect),e){const d=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:t});if(!d)return;const g=this._sheetDrawingService.getBatchRemoveOp([d]),{redo:u,objects:c}=g;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:u,objects:c,type:p.DrawingApplyType.REMOVE})}}addFloatDomToRange(t,e,n,o){var I,U,b;const s=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=s,g=this._getSceneAndTransformerByDrawingSearch(a);if(!g)return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(I=this._renderManagerService.getRenderById(a))==null?void 0:I.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:m,data:h,allowTransform:f=!0}=e,w=o!=null?o: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=Ze(S,n,R),T={unitId:a,subUnitId:d,drawingId:w,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:D.startX,top:D.startY,width:D.width,height:D.height},data:h,allowTransform:f};{const{unitId:P,subUnitId:N,drawingId:O}=T,M=y.getSheetCommandTarget(this._univerInstanceService,{unitId:P,subUnitId:N}),B=T,Y=this._univerInstanceService.getUnit(P,l.UniverInstanceType.UNIVER_SHEET);if(!Y)return;const q=Y.getActiveSheet().getSheetId();if(!B||!M)return;const Q=(U=this._renderManagerService.getRenderById(P))==null?void 0:U.with(E.SheetSkeletonManagerService);if(!Q)return;const H=Q.getWorksheetSkeleton(N);if(!H)return;const{transform:K,drawingType:ee,data:V}=B;if(ee!==l.DrawingTypeEnum.DRAWING_DOM&&ee!==l.DrawingTypeEnum.DRAWING_CHART)return;const x=this._getSceneAndTransformerByDrawingSearch(P);if(x==null)return;const{scene:fe,canvas:we}=x;if(K==null||q!==N)return;const{left:We,top:Be,width:xe,height:Le,angle:at,flipX:ct,flipY:Ye,skewX:$e,skewY:Se}=K,Fe=j.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:N,drawingId:O}),oe=fe.getObject(Fe);if(oe!=null){oe.transformByState({left:We,top:Be,width:xe,height:Le,angle:at,flipX:ct,flipY:Ye,skewX:$e,skewY:Se});return}const te={left:We,top:Be,width:xe,height:Le,zIndex:this._drawingManagerService.getDrawingOrder(P,N).length-1},_e=ee===l.DrawingTypeEnum.DRAWING_CHART;if(_e){const L=V?V.backgroundColor:"white";te.fill=L,te.rotateEnabled=!1,V&&V.border&&(te.stroke=V.border),te.paintFirst="stroke",te.strokeWidth=1,te.borderEnabled=!1,te.radius=8}const se=new k.Rect(Fe,te);_e&&se.setObjectType(k.ObjectType.CHART),fe.addObject(se,k.DRAWING_OBJECT_LAYER_INDEX),B.allowTransform!==!1&&fe.attachTransformerTo(se);const ae=new l.DisposableCollection,Ge=fe.getMainViewport(),{rowHeaderWidth:ve,columnHeaderHeight:Te}=H.skeleton,He={top:Te,left:ve,bottom:Ge.bottom,right:Ge.right},ce={dispose:ae,rect:se,boundsOfViewArea:He,domAnchor:n,unitId:P,subUnitId:N},$=de(se,x.renderUnit.scene,H.skeleton,M.worksheet,ce),Ie=new A.BehaviorSubject($);ce.position$=Ie;let Re={position$:Ie,id:O,componentKey:B.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:L=>{we.dispatchEvent(new WheelEvent(L.type,L))},data:V,unitId:P};e.eventPassThrough&&(Re={...Re,onPointerDown:L=>{we.dispatchEvent(new PointerEvent(L.type,L))},onPointerMove:L=>{we.dispatchEvent(new PointerEvent(L.type,L))},onPointerUp:L=>{we.dispatchEvent(new PointerEvent(L.type,L))}}),this._canvasFloatDomService.addFloatDom(Re),this.disposeWithMe(_.subscribe(L=>{var yt,Ct,Mt,Tt;const Dt=Ze({startX:L.startX,startY:L.startY,endX:L.endX,endY:L.endY,width:(yt=n.width)!=null?yt:L.width,height:(Ct=n.height)!=null?Ct:L.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Lt=j.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:N,drawingId:O}),Yt=new k.Rect(Lt,{left:Dt.startX,top:Dt.startY,width:(Mt=n.width)!=null?Mt:L.width,height:(Tt=n.height)!=null?Tt:L.height,zIndex:this._drawingManagerService.getDrawingOrder(P,N).length-1}),$t=de(Yt,x.renderUnit.scene,H.skeleton,M.worksheet,ce);Ie.next($t)}));const be=(b=this._renderManagerService.getRenderById(P))==null?void 0:b.with(E.SheetSkeletonManagerService);be==null||be.currentSkeleton$.subscribe(L=>{L&&H.sheetId!==L.sheetId&&this._removeDom(w,!0)});const Ve=se.onTransformChange$.subscribeEvent(()=>{const L=de(se,x.renderUnit.scene,H.skeleton,M.worksheet,ce);Ie.next(L)});ae.add(()=>{this._canvasFloatDomService.removeFloatDom(O)}),Ve&&ae.add(Ve),this._domLayerInfoMap.set(O,ce)}return{id:w,dispose:()=>{this._removeDom(w,!0)}}}addFloatDomToColumnHeader(t,e,n,o){var D,T,I;const s=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=s;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(D=this._renderManagerService.getRenderById(a))==null?void 0:D.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:m,data:h,allowTransform:f=!0}=e,w=o!=null?o: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:m,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 Y=(T=this._renderManagerService.getRenderById(U))==null?void 0:T.with(E.SheetSkeletonManagerService);if(!Y)return;const q=Y.getWorksheetSkeleton(b);if(!q)return;const{transform:Q,data:H}=O,K=this._getSceneAndTransformerByDrawingSearch(U);if(K==null)return;const{scene:ee,canvas:V}=K;if(Q==null||B!==b)return;const{left:x,top:fe,width:we,height:We,angle:Be,flipX:xe,flipY:Le,skewX:at,skewY:ct}=Q,Ye=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:b,drawingId:P}),$e=ee.getObject(Ye);if($e!=null){$e.transformByState({left:x,top:fe,width:we,height:We,angle:Be,flipX:xe,flipY:Le,skewX:at,skewY:ct});return}const Se=Ze({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:Se.startX,top:Se.startY,width:Se.width,height:Se.height,zIndex:this._drawingManagerService.getDrawingOrder(U,b).length-1},oe=new k.Rect(Ye,Fe);ee.addObject(oe,k.DRAWING_OBJECT_LAYER_INDEX),O.allowTransform!==!1&&ee.attachTransformerTo(oe);const te=new l.DisposableCollection,_e=ee.getMainViewport(),se={top:0,left:_e.left,bottom:_e.bottom,right:_e.right},ae={dispose:te,rect:oe,unitId:U,subUnitId:b,boundsOfViewArea:se,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},Ge=de(oe,K.renderUnit.scene,q.skeleton,N.worksheet,ae),ve=new A.BehaviorSubject(Ge);ae.position$=ve;let Te={position$:ve,id:P,componentKey:O.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{V.dispatchEvent(new WheelEvent($.type,$))},data:H,unitId:U};e.eventPassThrough&&(Te={...Te,onPointerDown:$=>{V.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{V.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{V.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(Te);const He=oe.onTransformChange$.subscribeEvent(()=>{const $=de(oe,K.renderUnit.scene,q.skeleton,N.worksheet,ae);ve.next($)});this.disposeWithMe(_.subscribe($=>{const Ie=Ze({startX:$.startX,startY:0,endX:$.endX,endY:$.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Re=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:b,drawingId:P}),be=new k.Rect(Re,{left:Ie.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(U,b).length-1}),Ve=de(be,K.renderUnit.scene,q.skeleton,N.worksheet,ae);ve.next(Ve)}));const ce=(I=this._renderManagerService.getRenderById(U))==null?void 0:I.with(E.SheetSkeletonManagerService);ce==null||ce.currentSkeleton$.subscribe($=>{$&&c.sheetId!==$.sheetId&&this._removeDom(w,!0)}),te.add(()=>{this._canvasFloatDomService.removeFloatDom(P)}),He&&te.add(He),this._domLayerInfoMap.set(P,ae)}return{id:w,dispose:()=>{this._removeDom(w,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:o,startColumn:s}=t;const a=Pe(o,s,n),d=new A.BehaviorSubject(a),g=Pe(t.endRow,t.endColumn,n),u=new A.BehaviorSubject(g),c=()=>{const _=Pe(o,s,n),v=Pe(t.endRow,t.endColumn,n);d.next(_),u.next(v)},m=new l.DisposableCollection;m.add(e.engine.clientRect$.subscribe(()=>c())),m.add(this._commandService.onCommandExecuted(_=>{if(_.id===y.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(C=>C.row===o)>-1){c();return}(y.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===E.SetScrollOperation.id||_.id===E.SetZoomRatioOperation.id)&&c()}));const h=(_,v)=>{o=_,s=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=Pe(t.endRow,t.endColumn,n);return{rotate:0,width:v.right-_.left,height:v.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:v.right,endY:v.bottom}})),S=f();return{position$:w,position:S,updateRowCol:h,topLeftPos$:d,rightBottomPos$:u,disposable:m}}};exports.SheetCanvasFloatDomManagerService=Cn([me(0,l.Inject(k.IRenderManagerService)),me(1,l.IUniverInstanceService),me(2,l.Inject(l.ICommandService)),me(3,j.IDrawingManagerService),me(4,l.Inject(W.CanvasFloatDomService)),me(5,p.ISheetDrawingService),me(6,l.Inject(l.LifecycleService))],exports.SheetCanvasFloatDomManagerService);function Pe(i,r,t){const e=t.getCellWithCoordByIndex(i,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Ze(i,r,t){var g,u;t=t!=null?t:1;const e=i.endX-i.startX,n=i.endY-i.startY,o=(g=r==null?void 0:r.width)!=null?g:e,s=(u=r==null?void 0:r.height)!=null?u:n;let a=0,d=0;if(r){if(r.horizonOffsetAlign==="right"){const c=qe(r.marginX,e*t);a=i.endX-c-o}else a=i.startX+qe(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const c=qe(r.marginY,n*t);d=i.endY-c-s}else d=i.startY+qe(r.marginY,n)}return{rotate:0,startX:a,startY:d,endX:i.endX,endY:i.endY,width:o,height:s,absolute:{left:i.absolute.left,top:i.absolute.top}}}function qe(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const t=Number.parseFloat(i);return r*t/100}const Mn=i=>{const{floatDomInfos:r,scene:t,skeleton:e,worksheet:n}=i,o=J.useMemo(()=>r.map(s=>{const{width:a,height:d,angle:g,left:u,top:c}=s.transform,m=Nt({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:m.left,endX:m.right,startY:m.top,endY:m.bottom,rotate:g,width:a*h,height:d*f,absolute:m.absolute},S={position$:new A.BehaviorSubject(w),position:w,id:s.drawingId,componentKey:s.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:s.unitId};return[s.drawingId,S]}),[r,t,e,n]);return X.jsx("div",{style:{position:"absolute",top:0,left:0},children:o.map(([s,a])=>X.jsx(W.PrintFloatDomSingle,{layer:a,id:s,position:a.position},s))})};var Tn=Object.getOwnPropertyDescriptor,Rn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Tn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},pe=(i,r)=>(t,e)=>r(t,e,i);let ot=class extends l.Disposable{constructor(i,r,t,e,n,o,s){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._canvasFloatDomManagerService=n,this._componetManager=o,this._injector=s,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,t)=>{const{unitId:e,scene:n,subUnitId:o}=r,s=this._drawingManagerService.getDrawingDataForUnit(e),a=s==null?void 0:s[o];return a&&a.order.forEach(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,o=this._renderManagerService.getRenderById(e);if(!o)return t(i);const s=o.with(E.SheetSkeletonManagerService).getSkeletonParam(n);if(!s)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}=o.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=d.order.map(h=>d.data[h]);return m.length?(m.forEach(h=>{if(!h.groupId&&h.transform&&l.Tools.isDefine(h.transform.left)&&l.Tools.isDefine(h.transform.top)&&l.Tools.isDefine(h.transform.width)&&l.Tools.isDefine(h.transform.height)){const f=s.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),w=s.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,o=this._drawingManagerService.getDrawingDataForUnit(e),s=o==null?void 0:o[n];if(s){const a=s.order.map(g=>{const u=s.data[g];return u.drawingType===l.DrawingTypeEnum.DRAWING_CHART?{...u,componentKey:this._componetManager.get(l.PRINT_CHART_COMPONENT_KEY)}:u.drawingType===l.DrawingTypeEnum.DRAWING_DOM?{...u,componentKey:this._componetManager.get(u.componentKey)}:null}).filter(Boolean),d=W.connectInjector(Mn,this._injector);return z.render(X.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)}}}))}};ot=Rn([pe(0,l.Inject(E.SheetPrintInterceptorService)),pe(1,l.Inject(he.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))],ot);var bn=Object.getOwnPropertyDescriptor,En=(i,r,t,e)=>{for(var n=e>1?void 0:e?bn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},ue=(i,r)=>(t,e)=>r(t,e,i);const On=[y.InsertRowCommand.id,y.InsertColCommand.id,y.RemoveRowCommand.id,y.RemoveColCommand.id,y.DeleteRangeMoveLeftCommand.id,y.DeleteRangeMoveUpCommand.id,y.InsertRangeMoveDownCommand.id,y.InsertRangeMoveRightCommand.id,y.DeltaRowHeightCommand.id,y.SetRowHeightCommand.id,y.DeltaColumnWidthCommand.id,y.SetColWidthCommand.id,y.SetRowHiddenCommand.id,y.SetSpecificRowsVisibleCommand.id,y.SetSpecificColsVisibleCommand.id,y.SetColHiddenCommand.id,y.MoveColsCommand.id,y.MoveRowsCommand.id,y.MoveRangeCommand.id],Un=[y.SetRowVisibleMutation.id,y.SetRowHiddenMutation.id,y.SetColVisibleMutation.id,y.SetColHiddenMutation.id,y.SetWorksheetRowHeightMutation.id,y.SetWorksheetColWidthMutation.id];let ht=class extends l.Disposable{constructor(i,r,t,e,n,o,s,a,d){super(),this._context=i,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=o,this._sheetDrawingService=s,this._drawingManagerService=a,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!On.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:o}=t;return this._getDrawingUndoForRowVisible(e,n,o)}else if(r===y.SetSpecificColsVisibleCommand.id||r===y.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForColVisible(e,n,o)}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:o}=t,s=r===y.DeltaRowHeightCommand.id||r===y.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,o,s)}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,o=[],s=[],a=this._sheetDrawingService.getDrawingData(e,n),d=[],g=[];if(Object.keys(a).forEach(u=>{const c=a[u],{updateDrawings:m,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,c);d.push(...m),g.push(...h)}),d.length===0&&g.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:m,objects:h}=u;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:m,objects:h,type:p.DrawingApplyType.UPDATE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),c=u.undo,m=u.redo,h=u.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:m,objects:h,type:p.DrawingApplyType.REMOVE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:p.DrawingApplyType.INSERT}})}return o.push({id:G.id,params:[e]}),s.push({id:G.id,params:[e]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,r,t){const e=[],n=[],{sheetTransform:o,anchorType:s=p.SheetDrawingAnchorType.Position,transform:a,unitId:d,subUnitId:g,drawingId:u}=t,{from:c,to:m}=o,{row:h,column:f}=c,{row:w,column:S}=m;if(o==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(o,a,C,R,s);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(o,a,_,v,s);D=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===2){const I=this._expandRow(o,a,_,v,s);D=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===3){const I=this._expandCol(o,a,C,R,s);D=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}if(D!=null&&T!=null){const I=Z(D,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:D,transform:I})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(i,r,t){const e=F({...i},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:m,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=c;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:w,to:S}=m,{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:P}=T;if(R<b)continue;if(f===p.SheetDrawingAnchorType.Position){let M=null,B=null;if(v>=b&&v<=P){const Y=this._skeletonManagerService.attachRangeWithCoord({startColumn:v,endColumn:P,startRow:w.row,endRow:S.row});if(Y==null)return;B={...h,left:Y.startX}}if(B!=null&&(M=F(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=F(O,this._selectionRenderService),N!=null&&O!=null){o.push({...c,sheetTransform:N,transform:O});break}}if(O!=null&&(N=F(O,this._selectionRenderService)),O!=null&&N!=null){n.push({...c,sheetTransform:N,transform:O});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,r,n),d=[],g=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);d.push(...u),g.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:g}}_createUndoAndRedoMutation(i,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:o,objects:s}=e,a=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:s,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],d=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:s,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:a,undos:d}}_getDrawingUndoForRowVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:m,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=c;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:w,to:S}=m,{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:P}=T;if(C<I)continue;if(f===p.SheetDrawingAnchorType.Position){let M=null,B=null;if(_>=I&&_<=U){const Y=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:_,endRow:U});if(Y==null)return;B={...h,top:Y.startY}}if(B!=null&&(M=F(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=F(O,this._selectionRenderService),N!=null&&O!=null){o.push({...c,sheetTransform:N,transform:O});break}}if(O!=null&&(N=F(O,this._selectionRenderService)),O!=null&&N!=null){n.push({...c,sheetTransform:N,transform:O});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,r,n),d=[],g=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);d.push(...u),g.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,t,e){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(s=>{const a=n[s],{sheetTransform:d,transform:g,anchorType:u=p.SheetDrawingAnchorType.Position}=a;if(u===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,o,a);else{const{from:c,to:m}=d,{row:h,column:f}=c,{row:w,column:S}=m;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===p.SheetDrawingAnchorType.Position&&(h<=C&&w>=R||f<=D&&S>=T)){this._remainDrawingSize(g,o,a);continue}const I=Z({...d},this._selectionRenderService,this._skeletonManagerService);if(I!=null){o.push({...a,transform:I});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let 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:o}=e,s=(R=(C=this._renderManagerService.getRenderById(n))==null?void 0:C.with(E.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const a=E.attachRangeWithCoord(s,t);if(!a)return{redos:[],undos:[]};const{startX:d,endX:g,startY:u,endY:c}=a,m=this._sheetDrawingService.getDrawingData(n,o),h=[];Object.keys(m).forEach(D=>{const T=m[D];if(T.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:I}=T;if(!I)return;const{left:U=0,top:b=0,width:P=0,height:N=0}=I,{drawingStartX:O,drawingEndX:M,drawingStartY:B,drawingEndY:Y}={drawingStartX:U,drawingEndX:U+P,drawingStartY:b,drawingEndY:b+N};d<=O&&M<=g&&u<=B&&Y<=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=Z(I,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,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:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:I,objects:U,type:p.DrawingApplyType.UPDATE}}),w.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:T,objects:U,type:p.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:o}=i,s=o.startRow,a=o.endRow,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],m=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:w,transform:S,anchorType:_=p.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let v,C;if(r==="insert"){const D=this._expandRow(w,S,s,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(_===p.SheetDrawingAnchorType.Both&&I>=s&&U<=a)m.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkRow(w,S,s,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&&m.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:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:p.DrawingApplyType.UPDATE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),f=h.undo,w=h.redo,S=h.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:p.DrawingApplyType.REMOVE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:p.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:o}=i,s=o.startColumn,a=o.endColumn,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],m=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:w,transform:S,anchorType:_=p.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let v,C;if(r==="insert"){const D=this._expandCol(w,S,s,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(_===p.SheetDrawingAnchorType.Both&&I>=s&&U<=a)m.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkCol(w,S,s,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&&m.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:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:p.DrawingApplyType.UPDATE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),f=h.undo,w=h.redo,S=h.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:p.DrawingApplyType.REMOVE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:p.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=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{column:d}=s,{column:g}=a;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:s.row,endRow:a.row});if(m==null)return;c={...r,left:(r.left||0)+m.endX-m.startX},u=F(c,this._selectionRenderService)}else if(g>=e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g+o}},c=Z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{column:d}=s,{column:g}=a;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...s,column:d-o},to:{...a,column:g-o}},c=Z(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g-o}},c=Z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...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 m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:s.row,endRow:a.row});if(m==null)return;c={...r,left:(r.left||0)-m.endX+m.startX-i.from.columnOffset}}u=F(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===p.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:s.row,endRow:a.row});if(m==null)return;u={from:{...s},to:{...a,column:t-1,columnOffset:m.endX-m.startX}},c=Z(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{row:d}=s,{row:g}=a;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const m=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:s.column,endColumn:a.column});if(m==null)return;c={...r,top:(r.top||0)+m.endY-m.startY},u=F(c,this._selectionRenderService)}else if(g>=e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g+o}},c=Z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{row:d}=s,{row:g}=a;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...s,row:d-o},to:{...a,row:g-o}},c=Z(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g-o}},c=Z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...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 m=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:s.column,endColumn:a.column});if(m==null)return;c={...r,top:(r.top||0)-m.endY+m.startY-i.from.rowOffset}}u=F(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===p.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:t-1,endRow:t-1});if(m==null)return;u={from:{...s},to:{...a,row:t-1,rowOffset:m.endY-m.startY}},c=Z(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(o=>{const s=n[o].data;s!=null&&Object.keys(s).forEach(a=>{e===i&&t.push(s[a])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(i,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(o=>{const s=t[o];s!=null&&Object.keys(s).forEach(a=>{const d=s[a].data;d!=null&&Object.keys(d).forEach(g=>{if(o===i&&a===r){const u=d[g];u.transform=Z(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=>{Un.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(e).forEach(o=>{const s=e[o],{sheetTransform:a,transform:d,anchorType:g=p.SheetDrawingAnchorType.Position}=s;if(g===p.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=a,{row:m,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:m,endRow:f,startColumn:h,endColumn:w})||m>C||h>D){const T=g===p.SheetDrawingAnchorType.Position,I=Z(a,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...I,width:T?d==null?void 0:d.width:I==null?void 0:I.width,height:T?d==null?void 0:d.height:I==null?void 0:I.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[i]))}};ht=En([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,p.ISheetDrawingService),ue(7,j.IDrawingManagerService),ue(8,l.IUniverInstanceService)],ht);var ie=function(){return ie=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},ie.apply(this,arguments)},Pn=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},jt=J.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,o=i.extend,s=Pn(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),d=J.useRef("_".concat(jn()));return kt(t,"".concat(e),{defIds:t.defIds,idSuffix:d.current},ie({ref:r,className:a},s),o)});function kt(i,r,t,e,n){return J.createElement(i.tag,ie(ie({key:r},An(i,t,n)),e),(Nn(i,t).children||[]).map(function(o,s){return kt(o,"".concat(r,"-").concat(i.tag,"-").concat(s),t,void 0,n)}))}function An(i,r,t){var e=ie({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1),i.tag==="mask"&&e.id&&(e.id=e.id+r.idSuffix),Object.entries(e).forEach(function(o){var s=o[0],a=o[1];s==="mask"&&typeof a=="string"&&(e[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))});var n=r.defIds;return!n||n.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var s=o[0],a=o[1];typeof a=="string"&&(e[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Nn(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)?ie(ie({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?ie(ie({},n),{attrs:ie(ie({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function jn(){return Math.random().toString(36).substring(2,8)}jt.displayName="UniverIcon";var kn={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"}}]},Wt=J.forwardRef(function(i,r){return J.createElement(jt,Object.assign({},i,{id:"add-image-single",ref:r,icon:kn}))});Wt.displayName="AddImageSingle";const vt={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),e=i.get(p.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,o=e.map(s=>{const{unitId:a,subUnitId:d,drawingId:g,drawingType:u}=s;return{unitId:a,subUnitId:d,drawingId:g,drawingType:u}});return r.executeCommand(Ce.id,{unitId:n,drawings:o})}},Me={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(p.ISheetDrawingService),n=i.get(E.ISheetSelectionRenderService),{direction:o}=r,s=e.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,d=s.map(u=>{const{transform:c}=u;if(c==null)return null;const m={...c},{left:h=0,top:f=0}=c;return o===l.Direction.UP?m.top=f-1:o===l.Direction.DOWN?m.top=f+1:o===l.Direction.LEFT?m.left=h-1:o===l.Direction.RIGHT&&(m.left=h+1),{...u,transform:m,sheetTransform:F(m,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(Ne.id,{unitId:a,drawings:d})?(t.syncExecuteCommand(G.id,[a]),!0):!1}},Bt="addition-and-subtraction-single",It="sheet.menu.image";function Wn(i){return{id:It,type:W.MenuItemType.SUBITEMS,icon:Bt,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 Bn(i){return{id:je.id,title:"sheetImage.upload.float",type:W.MenuItemType.BUTTON,hidden$:W.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function xn(i){return{id:_t.id,title:"sheetImage.upload.cell",type:W.MenuItemType.BUTTON,hidden$:W.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}const Ln="univer-image-common-panel",Yn="univer-image-common-panel-grid",$n="univer-image-common-panel-border",Fn="univer-image-common-panel-title",Gn="univer-image-common-panel-row",Hn="univer-image-common-panel-column",ge={imageCommonPanel:Ln,imageCommonPanelGrid:Yn,imageCommonPanelBorder:$n,imageCommonPanelTitle:Fn,imageCommonPanelRow:Gn,imageCommonPanelColumn:Hn},Vn=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:o}=i,s=o[0];if(s==null)return;const{unitId:a}=s,d=n.getRenderById(a),g=d==null?void 0:d.scene;if(g==null)return;const u=g.getTransformerByCreate(),[c,m]=J.useState(!0),h=(C=s.anchorType)!=null?C:p.SheetDrawingAnchorType.Position,[f,w]=J.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:P,subUnitId:N,drawingId:O,drawingType:M,anchorType:B,sheetTransform:Y}=b;T.push({unitId:P,subUnitId:N,drawingId:O,anchorType:B,sheetTransform:Y,drawingType:M})}),T}J.useEffect(()=>{const R=u.clearControl$.subscribe(T=>{T===!0&&m(!1)}),D=u.changeStart$.subscribe(T=>{var b;const{objects:I}=T,U=S(I,e);if(U.length===0)m(!1);else if(U.length>=1){m(!0);const P=((b=U[0])==null?void 0:b.anchorType)||p.SheetDrawingAnchorType.Position;w(P)}});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(Ne.id,{unitId:D[0].unitId,drawings:T})}const v=R=>R?"block":"none";return X.jsxs("div",{className:z.clsx(ge.imageCommonPanelGrid,ge.imageCommonPanelBorder),style:{display:v(c)},children:[X.jsx("div",{className:ge.imageCommonPanelRow,children:X.jsx("div",{className:z.clsx(ge.imageCommonPanelColumn,ge.imageCommonPanelTitle),children:X.jsx("div",{children:t.t("drawing-anchor.title")})})}),X.jsx("div",{className:z.clsx(ge.imageCommonPanelRow),children:X.jsx("div",{className:z.clsx(ge.imageCommonPanelColumn),children:X.jsxs(z.RadioGroup,{value:f,onChange:_,direction:"vertical",children:[X.jsx(z.Radio,{value:p.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),X.jsx(z.Radio,{value:p.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),X.jsx(z.Radio,{value:p.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})})]})},Xn=()=>{const i=W.useDependency(j.IDrawingManagerService),r=i.getFocusDrawings(),[t,e]=J.useState(r);return J.useEffect(()=>{const n=i.focus$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&X.jsxs("div",{className:ge.imageCommonPanel,children:[X.jsx(he.DrawingCommonPanel,{drawings:t}),X.jsx(Vn,{drawings:t})]})},Kn={[W.RibbonStartGroup.FORMULAS_INSERT]:{[It]:{order:3,menuItemFactory:Wn,[je.id]:{order:0,menuItemFactory:Bn},[_t.id]:{order:1,menuItemFactory:xn}}}};function ke(i){return!i.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(l.EDITOR_ACTIVATED)&&!i.getContextValue(l.FOCUSING_PANEL_EDITOR)&&i.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const zn={id:Me.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:W.KeyCode.ARROW_DOWN,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.DOWN}},Zn={id:Me.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:W.KeyCode.ARROW_UP,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.UP}},qn={id:Me.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:W.KeyCode.ARROW_LEFT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.LEFT}},Jn={id:Me.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:W.KeyCode.ARROW_RIGHT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.RIGHT}},Qn={id:vt.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:ke,binding:W.KeyCode.DELETE,mac:W.KeyCode.BACKSPACE};var er=Object.getOwnPropertyDescriptor,tr=(i,r,t,e)=>{for(var n=e>1?void 0:e?er(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},ye=(i,r)=>(t,e)=>r(t,e,i);let st=class extends l.Disposable{constructor(i,r,t,e,n,o){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Bt,Wt)),this.disposeWithMe(i.register(Ut,Xn))}_initMenus(){this._menuManagerService.mergeMenu(Kn)}_initCommands(){[je,_t,Ae,Ce,Ne,mt,G,pt,ft,St,Me,vt,wt].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[zn,Zn,qn,Jn,Qn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};st=tr([ye(0,l.Inject(W.ComponentManager)),ye(1,W.IMenuManagerService),ye(2,l.ICommandService),ye(3,W.IShortcutService),ye(4,j.IDrawingManagerService),ye(5,l.Inject(y.SheetsSelectionsService))],st);var nr=Object.defineProperty,rr=Object.getOwnPropertyDescriptor,ir=(i,r,t)=>r in i?nr(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,or=(i,r,t,e)=>{for(var n=e>1?void 0:e?rr(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},dt=(i,r)=>(t,e)=>r(t,e,i),xt=(i,r,t)=>ir(i,typeof r!="symbol"?r+"":r,t);const sr="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=Rt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:o,...s}=l.merge({},Rt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Ht,s)}onStarting(){l.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[st],[Qe],[ot],[it],[rt],[et],[tt],[nt]]),l.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[rt],[nt]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[it],[ot],[st],[et],[tt]])}onSteady(){this._injector.get(Qe)}_registerRenderModules(){[[exports.SheetDrawingUpdateController],[ht],[ut],[lt]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}};xt(exports.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);xt(exports.UniverSheetsDrawingUIPlugin,"pluginName",sr);exports.UniverSheetsDrawingUIPlugin=or([l.DependentOn(j.UniverDrawingPlugin,Ot.UniverDocsDrawingPlugin,he.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),dt(1,l.Inject(l.Injector)),dt(2,k.IRenderManagerService),dt(3,l.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=G;exports.DeleteDrawingsCommand=vt;exports.EditSheetDrawingOperation=pt;exports.GroupSheetDrawingCommand=ft;exports.InsertFloatImageCommand=je;exports.InsertSheetDrawingCommand=Ae;exports.MoveDrawingsCommand=Me;exports.RemoveSheetDrawingCommand=Ce;exports.SHEETS_IMAGE_MENU_ID=It;exports.SetDrawingArrangeCommand=wt;exports.SetSheetDrawingCommand=Ne;exports.SidebarSheetDrawingOperation=mt;exports.UngroupSheetDrawingCommand=St;
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")}}}))}};nt=mn([Ee(0,l.ICommandService),Ee(1,l.IUniverInstanceService),Ee(2,W.IDialogService),Ee(3,k.IRenderManagerService),Ee(4,l.Inject(l.LocaleService))],nt);const je={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{var s,a;const t=i.get(l.IUniverInstanceService),e=i.get(k.IRenderManagerService),n=(s=k.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:s.with(exports.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const d=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(d)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},_t={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 fn=Object.getOwnPropertyDescriptor,wn=(i,r,t,e)=>{for(var n=e>1?void 0:e?fn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Oe=(i,r)=>(t,e)=>r(t,e,i);const At="image/png";function Sn(i){const r=i.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=t.charCodeAt(o);return new Blob([n],{type:At})}function _n(i){const r=new ClipboardItem({[At]:Sn(i)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function vn(){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 Et=[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 rt=class extends l.Disposable{constructor(r,t,e,n,o){super();ne(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const o=this._focusedDrawings;if(o.length>0){const[s]=o;if(n===E.COPY_TYPE.CUT){const d={unitId:r,drawings:[s]};this._commandService.executeCommand(Ce.id,d)}setTimeout(()=>{const d=vn();s.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&s.imageSourceType===j.ImageSourceType.BASE64?_n(s.source):this._clipboardInterfaceService.writeText(""),d()},200);const a={unitId:s.unitId,subUnitId:s.subUnitId,drawings:[s]};this._copyInfo=a}else{const s=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=s}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=E.COPY_TYPE.COPY,pasteType:s}=n,{range:a}=r||{},{range:d,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:s,unitId:g,subUnitId:u,pasteRange:d},{copyRange:a,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:s},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:je.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var m;const n=(m=this._renderManagerService.getRenderById(r))==null?void 0:m.with(E.SheetSkeletonManagerService);if(!n)return;const o=n.attachRangeWithCoord(e);if(!o)return;const{startX:s,endX:a,startY:d,endY:g}=o,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!==p.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};s<=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(Et.includes(e))return{redos:[],undos:[]};const{unitId:o,subUnitId:s,range:a}=n,d=this._renderManagerService.getRenderById(o),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:m}=c,h=E.discreteRangeToRange(a);return this._generateMutations(m,{unitId:o,subUnitId:s,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=F(_,u))!=null?v:w}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:o,isCut:s}=t,a=[],d=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:c,sheetTransform:m}=u;if(!c)return;const h=o(c,m),f={...u,unitId:e,subUnitId:n,drawingId:s?u.drawingId:l.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(s){const{undo:w,redo:S,objects:_}=g.getBatchUpdateOp([f]);a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:p.DrawingApplyType.UPDATE,op:S,objects:_}}),d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:p.DrawingApplyType.UPDATE,op:w,objects:_}})}else{const{undo:w,redo:S,objects:_}=g.getBatchAddOp([f]);a.push({id:p.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:n,objects:_,type:p.DrawingApplyType.INSERT}}),d.push({id:p.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:_,type:p.DrawingApplyType.REMOVE}})}}),{redos:a,undos:d}}_generateRangeDrawingsPasteMutations(r,t){var U;const{unitId:e,subUnitId:n,pasteType:o,pasteRange:s}=r,{copyRange:a,copyType:d}=t;if(Et.includes(o))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(s)},pasteType:o},d);const{ranges:[c,m],mapFunc:h}=E.virtualizeDiscreteRanges([a,s]),{row:f,col:w}=h(c.startRow,c.startColumn),{row:S,col:_}=h(m.startRow,m.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,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)+D},sheetTransform:{...P,to:{...P.to,row:P.to.row+T,column:P.to.column+I},from:{...P.from,row:P.from.row+T,column:P.from.column+I}}}},isCut:d===E.COPY_TYPE.CUT})}};rt=wn([Oe(0,E.ISheetClipboardService),Oe(1,k.IRenderManagerService),Oe(2,j.IDrawingManagerService),Oe(3,W.IClipboardInterfaceService),Oe(4,l.ICommandService)],rt);var In=Object.getOwnPropertyDescriptor,Dn=(i,r,t,e)=>{for(var n=e>1?void 0:e?In(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ue=(i,r)=>(t,e)=>r(t,e,i);let it=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(o=>{if(!o){this._drawingManagerService.setDrawingVisible(!1);return}const s=e.getUnitId(),a=o.getSheetId();this._permissionService.composePermission([new y.WorkbookViewPermission(s).id,new y.WorksheetViewPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,o)})):(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),o=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===k.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=A.combineLatest([i,r]);this.disposeWithMe(t.pipe(A.switchMap(([e,n])=>e?e.activeSheet$.pipe(A.tap(o=>{if(!o){this._drawingManagerService.setDrawingEditable(!1);return}const s=e.getUnitId(),a=o.getSheetId();this._permissionService.composePermission([new y.WorkbookEditablePermission(s).id,new y.WorksheetEditPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,o)})):(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),o=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===k.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&a.detachTransformerFrom(g)})}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(A.combineLatest([i,r]).pipe(A.switchMap(([t,e])=>t?t.activeSheet$.pipe(A.switchMap(n=>{if(!n)return A.EMPTY;const o=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),d=a==null?void 0:a.scene;if(!d)return A.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookViewPermission(o).id,new y.WorksheetViewPermission(o,s).id]).pipe(A.map(c=>c.every(m=>m.value)),A.distinctUntilChanged()).pipe(A.map(c=>({permission:c,scene:d,transformer:g,unitId:o,subUnitId:s})))})):A.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:s})=>{this._drawingManagerService.setDrawingVisible(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(o,s),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(),o=e==null?void 0:e.getSheetId();if(!n||!o)return;const s=this._drawingManagerService.getDrawingData(n,o),a=Object.values(s);this._drawingManagerService.addNotification(a)}}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(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 o=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),d=a==null?void 0:a.scene;if(!d)return A.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookEditablePermission(o).id,new y.WorksheetEditPermission(o,s).id]).pipe(A.map(c=>c.every(m=>m.value)),A.distinctUntilChanged()).pipe(A.map(c=>({permission:c,scene:d,transformer:g,unitId:o,subUnitId:s})))})):A.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:s})=>{this._drawingManagerService.setDrawingEditable(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(o,s),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 o=n.getSheetId(),s=this._renderManagerService.getRenderById(e),a=s==null?void 0:s.scene;if(!a)return;const d=this._drawingManagerService.getDrawingData(e,o),g=Object.values(d);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(c=>{c.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(m=>c.oKey.includes(m.drawingId))&&a.detachTransformerFrom(c)})}}))}};it=Dn([Ue(0,j.IDrawingManagerService),Ue(1,k.IRenderManagerService),Ue(2,l.IPermissionService),Ue(3,l.IUniverInstanceService),Ue(4,l.Inject(l.UserManagerService))],it);var yn=Object.getOwnPropertyDescriptor,Cn=(i,r,t,e)=>{for(var n=e>1?void 0:e?yn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},me=(i,r)=>(t,e)=>r(t,e,i);function Nt(i,r,t,e,n,o=!1){const{scaleX:s,scaleY:a}=r.getAncestorScale(),d=r.getViewport(k.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=e.getFreeze(),{startColumn:u,startRow:c,xSplit:m,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:P}=t,N={top:o?0:P,left:o?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)+P,Y=t.colStartX(u-m)+b,q=t.rowStartY(c)+P,Q=t.colStartX(u)+b;if(m===0)f.left=!1,O=(w-D)*s,M=(S-D)*s;else{const V=w-(Y-b),x=S-(Y-b);S<Q?(O=V*s,M=x*s):w<=Q&&S>=Q?(O=V*s,M=Math.max(R,(S-D)*s)):w>Q&&(f.left=!1,O=Math.max((w-D)*s,R),M=Math.max((S-D)*s,R))}let H=0,K=0;if(h===0)f.top=!1,H=(_-T)*a,K=(v-T)*a;else{const V=_-(B-P),x=v-(B-P);v<q?(H=V*a,K=x*a):_<=q&&v>=q?(H=V*a,K=Math.max(C,(v-T)*a)):_>q&&(f.top=!1,H=Math.max((_-T)*a,C),K=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),K=Math.max(K,N.top),{left:O,right:M,top:H,bottom:K,absolute:f}}const de=(i,r,t,e,n)=>{const{left:o,top:s,width:a,height:d,angle:g}=i,u={left:o,right:o+a,top:s,bottom:s+d},c=Nt(u,r,t,e,n),{scaleX:m,scaleY:h}=r.getAncestorScale();return{startX:c.left,endX:c.right,startY:c.top,endY:c.bottom,rotate:g,width:a*m,height:d*h,absolute:c.absolute}};exports.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(t,e,n,o,s,a,d){super();ne(this,"_domLayerInfoMap",new Map);ne(this,"_transformChange$",new A.Subject);ne(this,"transformChange$",this._transformChange$.asObservable());ne(this,"_add$",new A.Subject);ne(this,"add$",this._add$.asObservable());ne(this,"_remove$",new A.Subject);ne(this,"remove$",this._remove$.asObservable());this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=o,this._canvasFloatDomService=s,this._sheetDrawingService=a,this._lifecycleService=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 o=n.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:n,transformer:o,renderUnit:e,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var V;const{unitId:n,subUnitId:o,drawingId:s}=e,a=y.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),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(o);if(!c)return;const{transform:m,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(m==null)return!0;if(u!==o)return;const{left:v,top:C,width:R,height:D,angle:T,flipX:I,flipY:U,skewX:b,skewY:P}=m,N=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),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:P});return}const M={left:v,top:C,width:R,height:D,zIndex:this._drawingManagerService.getDrawingOrder(n,o).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 Y=new k.Rect(N,M);B&&Y.setObjectType(k.ObjectType.CHART),S.addObject(Y,k.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo(Y);const q=new l.DisposableCollection,Q=de(Y,w.renderUnit.scene,c.skeleton,a.worksheet),H=new A.BehaviorSubject(Q),K={dispose:q,rect:Y,position$:H,unitId:n,subUnitId:o,id:s};this._canvasFloatDomService.addFloatDom({position$:H,id:s,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 ee=Y.onTransformChange$.subscribeEvent(()=>{const x=de(Y,w.renderUnit.scene,c.skeleton,a.worksheet);H.next(x)});q.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),ee&&q.add(ee),this._domLayerInfoMap.set(s,K)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{const{unitId:n,subUnitId:o,drawingId:s}=e,a=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{transformer:g,scene:u}=d,c=u.getObject(a);c!=null&&c.oKey&&g.clearControlByIds([c==null?void 0:c.oKey])})}))}_scrollUpdateListener(){const t=(e,n)=>{var g;const o=this._getSceneAndTransformerByDrawingSearch(e),s=Array.from(this._domLayerInfoMap.keys()).map(u=>({id:u,...this._domLayerInfoMap.get(u)})).filter(u=>u.subUnitId===n&&u.unitId===e).map(u=>u.id),a=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(E.SheetSkeletonManagerService).getSkeletonParam(n);!o||!a||!d||s.forEach(u=>{const c=this._domLayerInfoMap.get(u);if(c){const m=de(c.rect,o.renderUnit.scene,d.skeleton,a.worksheet,c);c.position$.next(m)}})};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(),o=this._renderManagerService.getRenderById(n);return o?{render:o,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:o}=e;t(n,o)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===E.SetZoomRatioOperation.id){const n=e.params,{unitId:o}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===o).map(a=>a.subUnitId).forEach(a=>{t(o,a)})}else if(e.id===y.SetFrozenMutation.id){const{unitId:n,subUnitId:o}=e.params;t(n,o)}}))}_getPosition(t,e){var h;const{startX:n,endX:o,startY:s,endY:a}=t,d=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(E.ISheetSelectionRenderService);if(d==null)return;const g=d.getCellWithCoordByOffset(n,s);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:s-g.startY},c=d.getCellWithCoordByOffset(o,a);if(c==null)return;const m={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:a-c.startY};return{from:u,to:m}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(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 o={...n.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,o){const s=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(t);if(s&&a){const{scene:d}=a,g=j.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=d.getObject(g);u&&u instanceof k.Rect&&u.setProps(o)}}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:o,subUnitId:s}=n,{initPosition:a,componentKey:d,data:g,allowTransform:u=!0}=t,c=e!=null?e:l.generateRandomId(),m=this._getPosition(a,o);if(m==null)return;const h={unitId:o,subUnitId:s,drawingId:c,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:m,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Ae.id,{unitId:o,drawings:[h]}),this._add$.next({unitId:o,subUnitId:s,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:o,subUnitId:s}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(o);if(a&&a.scene.removeObject(n.rect),e){const d=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:t});if(!d)return;const g=this._sheetDrawingService.getBatchRemoveOp([d]),{redo:u,objects:c}=g;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:u,objects:c,type:p.DrawingApplyType.REMOVE})}}addFloatDomToRange(t,e,n,o){var I,U,b;const s=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=s,g=this._getSceneAndTransformerByDrawingSearch(a);if(!g)return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(I=this._renderManagerService.getRenderById(a))==null?void 0:I.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:m,data:h,allowTransform:f=!0}=e,w=o!=null?o: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=Ze(S,n,R),T={unitId:a,subUnitId:d,drawingId:w,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:D.startX,top:D.startY,width:D.width,height:D.height},data:h,allowTransform:f};{const{unitId:P,subUnitId:N,drawingId:O}=T,M=y.getSheetCommandTarget(this._univerInstanceService,{unitId:P,subUnitId:N}),B=T,Y=this._univerInstanceService.getUnit(P,l.UniverInstanceType.UNIVER_SHEET);if(!Y)return;const q=Y.getActiveSheet().getSheetId();if(!B||!M)return;const Q=(U=this._renderManagerService.getRenderById(P))==null?void 0:U.with(E.SheetSkeletonManagerService);if(!Q)return;const H=Q.getWorksheetSkeleton(N);if(!H)return;const{transform:K,drawingType:ee,data:V}=B;if(ee!==l.DrawingTypeEnum.DRAWING_DOM&&ee!==l.DrawingTypeEnum.DRAWING_CHART)return;const x=this._getSceneAndTransformerByDrawingSearch(P);if(x==null)return;const{scene:fe,canvas:we}=x;if(K==null||q!==N)return;const{left:We,top:Be,width:xe,height:Le,angle:at,flipX:ct,flipY:Ye,skewX:$e,skewY:Se}=K,Fe=j.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:N,drawingId:O}),oe=fe.getObject(Fe);if(oe!=null){oe.transformByState({left:We,top:Be,width:xe,height:Le,angle:at,flipX:ct,flipY:Ye,skewX:$e,skewY:Se});return}const te={left:We,top:Be,width:xe,height:Le,zIndex:this._drawingManagerService.getDrawingOrder(P,N).length-1},_e=ee===l.DrawingTypeEnum.DRAWING_CHART;if(_e){const L=V?V.backgroundColor:"white";te.fill=L,te.rotateEnabled=!1,V&&V.border&&(te.stroke=V.border),te.paintFirst="stroke",te.strokeWidth=1,te.borderEnabled=!1,te.radius=8}const se=new k.Rect(Fe,te);_e&&se.setObjectType(k.ObjectType.CHART),fe.addObject(se,k.DRAWING_OBJECT_LAYER_INDEX),B.allowTransform!==!1&&fe.attachTransformerTo(se);const ae=new l.DisposableCollection,Ge=fe.getMainViewport(),{rowHeaderWidth:ve,columnHeaderHeight:Te}=H.skeleton,He={top:Te,left:ve,bottom:Ge.bottom,right:Ge.right},ce={dispose:ae,rect:se,boundsOfViewArea:He,domAnchor:n,unitId:P,subUnitId:N},$=de(se,x.renderUnit.scene,H.skeleton,M.worksheet,ce),Ie=new A.BehaviorSubject($);ce.position$=Ie;let Re={position$:Ie,id:O,componentKey:B.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:L=>{we.dispatchEvent(new WheelEvent(L.type,L))},data:V,unitId:P};e.eventPassThrough&&(Re={...Re,onPointerDown:L=>{we.dispatchEvent(new PointerEvent(L.type,L))},onPointerMove:L=>{we.dispatchEvent(new PointerEvent(L.type,L))},onPointerUp:L=>{we.dispatchEvent(new PointerEvent(L.type,L))}}),this._canvasFloatDomService.addFloatDom(Re),this.disposeWithMe(_.subscribe(L=>{var yt,Ct,Mt,Tt;const Dt=Ze({startX:L.startX,startY:L.startY,endX:L.endX,endY:L.endY,width:(yt=n.width)!=null?yt:L.width,height:(Ct=n.height)!=null?Ct:L.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Lt=j.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:N,drawingId:O}),Yt=new k.Rect(Lt,{left:Dt.startX,top:Dt.startY,width:(Mt=n.width)!=null?Mt:L.width,height:(Tt=n.height)!=null?Tt:L.height,zIndex:this._drawingManagerService.getDrawingOrder(P,N).length-1}),$t=de(Yt,x.renderUnit.scene,H.skeleton,M.worksheet,ce);Ie.next($t)}));const be=(b=this._renderManagerService.getRenderById(P))==null?void 0:b.with(E.SheetSkeletonManagerService);be==null||be.currentSkeleton$.subscribe(L=>{L&&H.sheetId!==L.sheetId&&this._removeDom(w,!0)});const Ve=se.onTransformChange$.subscribeEvent(()=>{const L=de(se,x.renderUnit.scene,H.skeleton,M.worksheet,ce);Ie.next(L)});ae.add(()=>{this._canvasFloatDomService.removeFloatDom(O)}),Ve&&ae.add(Ve),this._domLayerInfoMap.set(O,ce)}return{id:w,dispose:()=>{this._removeDom(w,!0)}}}addFloatDomToColumnHeader(t,e,n,o){var D,T,I;const s=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=s;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(D=this._renderManagerService.getRenderById(a))==null?void 0:D.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:m,data:h,allowTransform:f=!0}=e,w=o!=null?o: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:m,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 Y=(T=this._renderManagerService.getRenderById(U))==null?void 0:T.with(E.SheetSkeletonManagerService);if(!Y)return;const q=Y.getWorksheetSkeleton(b);if(!q)return;const{transform:Q,data:H}=O,K=this._getSceneAndTransformerByDrawingSearch(U);if(K==null)return;const{scene:ee,canvas:V}=K;if(Q==null||B!==b)return;const{left:x,top:fe,width:we,height:We,angle:Be,flipX:xe,flipY:Le,skewX:at,skewY:ct}=Q,Ye=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:b,drawingId:P}),$e=ee.getObject(Ye);if($e!=null){$e.transformByState({left:x,top:fe,width:we,height:We,angle:Be,flipX:xe,flipY:Le,skewX:at,skewY:ct});return}const Se=Ze({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:Se.startX,top:Se.startY,width:Se.width,height:Se.height,zIndex:this._drawingManagerService.getDrawingOrder(U,b).length-1},oe=new k.Rect(Ye,Fe);ee.addObject(oe,k.DRAWING_OBJECT_LAYER_INDEX),O.allowTransform!==!1&&ee.attachTransformerTo(oe);const te=new l.DisposableCollection,_e=ee.getMainViewport(),se={top:0,left:_e.left,bottom:_e.bottom,right:_e.right},ae={dispose:te,rect:oe,unitId:U,subUnitId:b,boundsOfViewArea:se,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},Ge=de(oe,K.renderUnit.scene,q.skeleton,N.worksheet,ae),ve=new A.BehaviorSubject(Ge);ae.position$=ve;let Te={position$:ve,id:P,componentKey:O.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{V.dispatchEvent(new WheelEvent($.type,$))},data:H,unitId:U};e.eventPassThrough&&(Te={...Te,onPointerDown:$=>{V.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{V.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{V.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(Te);const He=oe.onTransformChange$.subscribeEvent(()=>{const $=de(oe,K.renderUnit.scene,q.skeleton,N.worksheet,ae);ve.next($)});this.disposeWithMe(_.subscribe($=>{const Ie=Ze({startX:$.startX,startY:0,endX:$.endX,endY:$.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Re=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:b,drawingId:P}),be=new k.Rect(Re,{left:Ie.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(U,b).length-1}),Ve=de(be,K.renderUnit.scene,q.skeleton,N.worksheet,ae);ve.next(Ve)}));const ce=(I=this._renderManagerService.getRenderById(U))==null?void 0:I.with(E.SheetSkeletonManagerService);ce==null||ce.currentSkeleton$.subscribe($=>{$&&c.sheetId!==$.sheetId&&this._removeDom(w,!0)}),te.add(()=>{this._canvasFloatDomService.removeFloatDom(P)}),He&&te.add(He),this._domLayerInfoMap.set(P,ae)}return{id:w,dispose:()=>{this._removeDom(w,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:o,startColumn:s}=t;const a=Pe(o,s,n),d=new A.BehaviorSubject(a),g=Pe(t.endRow,t.endColumn,n),u=new A.BehaviorSubject(g),c=()=>{const _=Pe(o,s,n),v=Pe(t.endRow,t.endColumn,n);d.next(_),u.next(v)},m=new l.DisposableCollection;m.add(e.engine.clientRect$.subscribe(()=>c())),m.add(this._commandService.onCommandExecuted(_=>{if(_.id===y.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(C=>C.row===o)>-1){c();return}(y.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===E.SetScrollOperation.id||_.id===E.SetZoomRatioOperation.id)&&c()}));const h=(_,v)=>{o=_,s=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=Pe(t.endRow,t.endColumn,n);return{rotate:0,width:v.right-_.left,height:v.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:v.right,endY:v.bottom}})),S=f();return{position$:w,position:S,updateRowCol:h,topLeftPos$:d,rightBottomPos$:u,disposable:m}}};exports.SheetCanvasFloatDomManagerService=Cn([me(0,l.Inject(k.IRenderManagerService)),me(1,l.IUniverInstanceService),me(2,l.Inject(l.ICommandService)),me(3,j.IDrawingManagerService),me(4,l.Inject(W.CanvasFloatDomService)),me(5,p.ISheetDrawingService),me(6,l.Inject(l.LifecycleService))],exports.SheetCanvasFloatDomManagerService);function Pe(i,r,t){const e=t.getCellWithCoordByIndex(i,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Ze(i,r,t){var g,u;t=t!=null?t:1;const e=i.endX-i.startX,n=i.endY-i.startY,o=(g=r==null?void 0:r.width)!=null?g:e,s=(u=r==null?void 0:r.height)!=null?u:n;let a=0,d=0;if(r){if(r.horizonOffsetAlign==="right"){const c=qe(r.marginX,e*t);a=i.endX-c-o}else a=i.startX+qe(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const c=qe(r.marginY,n*t);d=i.endY-c-s}else d=i.startY+qe(r.marginY,n)}return{rotate:0,startX:a,startY:d,endX:i.endX,endY:i.endY,width:o,height:s,absolute:{left:i.absolute.left,top:i.absolute.top}}}function qe(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const t=Number.parseFloat(i);return r*t/100}const Mn=i=>{const{floatDomInfos:r,scene:t,skeleton:e,worksheet:n}=i,o=J.useMemo(()=>r.map(s=>{const{width:a,height:d,angle:g,left:u,top:c}=s.transform,m=Nt({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:m.left,endX:m.right,startY:m.top,endY:m.bottom,rotate:g,width:a*h,height:d*f,absolute:m.absolute},S={position$:new A.BehaviorSubject(w),position:w,id:s.drawingId,componentKey:s.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:s.unitId,data:s.data};return[s.drawingId,S]}),[r,t,e,n]);return X.jsx("div",{style:{position:"absolute",top:0,left:0},children:o.map(([s,a])=>X.jsx(W.PrintFloatDomSingle,{layer:a,id:s,position:a.position},s))})};var Tn=Object.getOwnPropertyDescriptor,Rn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Tn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},pe=(i,r)=>(t,e)=>r(t,e,i);let ot=class extends l.Disposable{constructor(i,r,t,e,n,o,s){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._canvasFloatDomManagerService=n,this._componetManager=o,this._injector=s,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,t)=>{const{unitId:e,scene:n,subUnitId:o}=r,s=this._drawingManagerService.getDrawingDataForUnit(e),a=s==null?void 0:s[o];return a&&a.order.forEach(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,o=this._renderManagerService.getRenderById(e);if(!o)return t(i);const s=o.with(E.SheetSkeletonManagerService).getSkeletonParam(n);if(!s)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}=o.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=d.order.map(h=>d.data[h]);return m.length?(m.forEach(h=>{if(!h.groupId&&h.transform&&l.Tools.isDefine(h.transform.left)&&l.Tools.isDefine(h.transform.top)&&l.Tools.isDefine(h.transform.width)&&l.Tools.isDefine(h.transform.height)){const f=s.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),w=s.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,o=this._drawingManagerService.getDrawingDataForUnit(e),s=o==null?void 0:o[n];if(s){const a=s.order.map(g=>{const u=s.data[g];if(u.drawingType===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(Mn,this._injector);return z.render(X.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)}}}))}};ot=Rn([pe(0,l.Inject(E.SheetPrintInterceptorService)),pe(1,l.Inject(he.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))],ot);var bn=Object.getOwnPropertyDescriptor,En=(i,r,t,e)=>{for(var n=e>1?void 0:e?bn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},ue=(i,r)=>(t,e)=>r(t,e,i);const On=[y.InsertRowCommand.id,y.InsertColCommand.id,y.RemoveRowCommand.id,y.RemoveColCommand.id,y.DeleteRangeMoveLeftCommand.id,y.DeleteRangeMoveUpCommand.id,y.InsertRangeMoveDownCommand.id,y.InsertRangeMoveRightCommand.id,y.DeltaRowHeightCommand.id,y.SetRowHeightCommand.id,y.DeltaColumnWidthCommand.id,y.SetColWidthCommand.id,y.SetRowHiddenCommand.id,y.SetSpecificRowsVisibleCommand.id,y.SetSpecificColsVisibleCommand.id,y.SetColHiddenCommand.id,y.MoveColsCommand.id,y.MoveRowsCommand.id,y.MoveRangeCommand.id],Un=[y.SetRowVisibleMutation.id,y.SetRowHiddenMutation.id,y.SetColVisibleMutation.id,y.SetColHiddenMutation.id,y.SetWorksheetRowHeightMutation.id,y.SetWorksheetColWidthMutation.id];let ht=class extends l.Disposable{constructor(i,r,t,e,n,o,s,a,d){super(),this._context=i,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=o,this._sheetDrawingService=s,this._drawingManagerService=a,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!On.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:o}=t;return this._getDrawingUndoForRowVisible(e,n,o)}else if(r===y.SetSpecificColsVisibleCommand.id||r===y.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForColVisible(e,n,o)}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:o}=t,s=r===y.DeltaRowHeightCommand.id||r===y.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,o,s)}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,o=[],s=[],a=this._sheetDrawingService.getDrawingData(e,n),d=[],g=[];if(Object.keys(a).forEach(u=>{const c=a[u],{updateDrawings:m,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,c);d.push(...m),g.push(...h)}),d.length===0&&g.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:m,objects:h}=u;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:m,objects:h,type:p.DrawingApplyType.UPDATE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),c=u.undo,m=u.redo,h=u.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:m,objects:h,type:p.DrawingApplyType.REMOVE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:p.DrawingApplyType.INSERT}})}return o.push({id:G.id,params:[e]}),s.push({id:G.id,params:[e]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,r,t){const e=[],n=[],{sheetTransform:o,anchorType:s=p.SheetDrawingAnchorType.Position,transform:a,unitId:d,subUnitId:g,drawingId:u}=t,{from:c,to:m}=o,{row:h,column:f}=c,{row:w,column:S}=m;if(o==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(o,a,C,R,s);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(o,a,_,v,s);D=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===2){const I=this._expandRow(o,a,_,v,s);D=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===3){const I=this._expandCol(o,a,C,R,s);D=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}if(D!=null&&T!=null){const I=Z(D,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:D,transform:I})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(i,r,t){const e=F({...i},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:m,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=c;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:w,to:S}=m,{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:P}=T;if(R<b)continue;if(f===p.SheetDrawingAnchorType.Position){let M=null,B=null;if(v>=b&&v<=P){const Y=this._skeletonManagerService.attachRangeWithCoord({startColumn:v,endColumn:P,startRow:w.row,endRow:S.row});if(Y==null)return;B={...h,left:Y.startX}}if(B!=null&&(M=F(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=F(O,this._selectionRenderService),N!=null&&O!=null){o.push({...c,sheetTransform:N,transform:O});break}}if(O!=null&&(N=F(O,this._selectionRenderService)),O!=null&&N!=null){n.push({...c,sheetTransform:N,transform:O});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,r,n),d=[],g=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);d.push(...u),g.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:g}}_createUndoAndRedoMutation(i,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:o,objects:s}=e,a=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:s,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],d=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:s,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:a,undos:d}}_getDrawingUndoForRowVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:m,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=c;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:w,to:S}=m,{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:P}=T;if(C<I)continue;if(f===p.SheetDrawingAnchorType.Position){let M=null,B=null;if(_>=I&&_<=U){const Y=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:_,endRow:U});if(Y==null)return;B={...h,top:Y.startY}}if(B!=null&&(M=F(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=F(O,this._selectionRenderService),N!=null&&O!=null){o.push({...c,sheetTransform:N,transform:O});break}}if(O!=null&&(N=F(O,this._selectionRenderService)),O!=null&&N!=null){n.push({...c,sheetTransform:N,transform:O});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,r,n),d=[],g=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);d.push(...u),g.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,t,e){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(s=>{const a=n[s],{sheetTransform:d,transform:g,anchorType:u=p.SheetDrawingAnchorType.Position}=a;if(u===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,o,a);else{const{from:c,to:m}=d,{row:h,column:f}=c,{row:w,column:S}=m;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===p.SheetDrawingAnchorType.Position&&(h<=C&&w>=R||f<=D&&S>=T)){this._remainDrawingSize(g,o,a);continue}const I=Z({...d},this._selectionRenderService,this._skeletonManagerService);if(I!=null){o.push({...a,transform:I});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let 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:o}=e,s=(R=(C=this._renderManagerService.getRenderById(n))==null?void 0:C.with(E.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const a=E.attachRangeWithCoord(s,t);if(!a)return{redos:[],undos:[]};const{startX:d,endX:g,startY:u,endY:c}=a,m=this._sheetDrawingService.getDrawingData(n,o),h=[];Object.keys(m).forEach(D=>{const T=m[D];if(T.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:I}=T;if(!I)return;const{left:U=0,top:b=0,width:P=0,height:N=0}=I,{drawingStartX:O,drawingEndX:M,drawingStartY:B,drawingEndY:Y}={drawingStartX:U,drawingEndX:U+P,drawingStartY:b,drawingEndY:b+N};d<=O&&M<=g&&u<=B&&Y<=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=Z(I,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,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:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:I,objects:U,type:p.DrawingApplyType.UPDATE}}),w.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:T,objects:U,type:p.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:o}=i,s=o.startRow,a=o.endRow,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],m=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:w,transform:S,anchorType:_=p.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let v,C;if(r==="insert"){const D=this._expandRow(w,S,s,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(_===p.SheetDrawingAnchorType.Both&&I>=s&&U<=a)m.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkRow(w,S,s,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&&m.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:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:p.DrawingApplyType.UPDATE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),f=h.undo,w=h.redo,S=h.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:p.DrawingApplyType.REMOVE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:p.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:o}=i,s=o.startColumn,a=o.endColumn,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],m=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:w,transform:S,anchorType:_=p.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let v,C;if(r==="insert"){const D=this._expandCol(w,S,s,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(_===p.SheetDrawingAnchorType.Both&&I>=s&&U<=a)m.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkCol(w,S,s,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&&m.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:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:p.DrawingApplyType.UPDATE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),f=h.undo,w=h.redo,S=h.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:p.DrawingApplyType.REMOVE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:p.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=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{column:d}=s,{column:g}=a;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:s.row,endRow:a.row});if(m==null)return;c={...r,left:(r.left||0)+m.endX-m.startX},u=F(c,this._selectionRenderService)}else if(g>=e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g+o}},c=Z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{column:d}=s,{column:g}=a;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...s,column:d-o},to:{...a,column:g-o}},c=Z(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g-o}},c=Z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...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 m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:s.row,endRow:a.row});if(m==null)return;c={...r,left:(r.left||0)-m.endX+m.startX-i.from.columnOffset}}u=F(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===p.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:s.row,endRow:a.row});if(m==null)return;u={from:{...s},to:{...a,column:t-1,columnOffset:m.endX-m.startX}},c=Z(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{row:d}=s,{row:g}=a;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const m=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:s.column,endColumn:a.column});if(m==null)return;c={...r,top:(r.top||0)+m.endY-m.startY},u=F(c,this._selectionRenderService)}else if(g>=e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g+o}},c=Z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{row:d}=s,{row:g}=a;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...s,row:d-o},to:{...a,row:g-o}},c=Z(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g-o}},c=Z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...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 m=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:s.column,endColumn:a.column});if(m==null)return;c={...r,top:(r.top||0)-m.endY+m.startY-i.from.rowOffset}}u=F(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===p.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:t-1,endRow:t-1});if(m==null)return;u={from:{...s},to:{...a,row:t-1,rowOffset:m.endY-m.startY}},c=Z(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(o=>{const s=n[o].data;s!=null&&Object.keys(s).forEach(a=>{e===i&&t.push(s[a])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(i,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(o=>{const s=t[o];s!=null&&Object.keys(s).forEach(a=>{const d=s[a].data;d!=null&&Object.keys(d).forEach(g=>{if(o===i&&a===r){const u=d[g];u.transform=Z(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=>{Un.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(e).forEach(o=>{const s=e[o],{sheetTransform:a,transform:d,anchorType:g=p.SheetDrawingAnchorType.Position}=s;if(g===p.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=a,{row:m,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:m,endRow:f,startColumn:h,endColumn:w})||m>C||h>D){const T=g===p.SheetDrawingAnchorType.Position,I=Z(a,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...I,width:T?d==null?void 0:d.width:I==null?void 0:I.width,height:T?d==null?void 0:d.height:I==null?void 0:I.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[i]))}};ht=En([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,p.ISheetDrawingService),ue(7,j.IDrawingManagerService),ue(8,l.IUniverInstanceService)],ht);var ie=function(){return ie=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},ie.apply(this,arguments)},Pn=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},jt=J.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,o=i.extend,s=Pn(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),d=J.useRef("_".concat(jn()));return kt(t,"".concat(e),{defIds:t.defIds,idSuffix:d.current},ie({ref:r,className:a},s),o)});function kt(i,r,t,e,n){return J.createElement(i.tag,ie(ie({key:r},An(i,t,n)),e),(Nn(i,t).children||[]).map(function(o,s){return kt(o,"".concat(r,"-").concat(i.tag,"-").concat(s),t,void 0,n)}))}function An(i,r,t){var e=ie({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1),i.tag==="mask"&&e.id&&(e.id=e.id+r.idSuffix),Object.entries(e).forEach(function(o){var s=o[0],a=o[1];s==="mask"&&typeof a=="string"&&(e[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))});var n=r.defIds;return!n||n.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var s=o[0],a=o[1];typeof a=="string"&&(e[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Nn(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)?ie(ie({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?ie(ie({},n),{attrs:ie(ie({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function jn(){return Math.random().toString(36).substring(2,8)}jt.displayName="UniverIcon";var kn={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"}}]},Wt=J.forwardRef(function(i,r){return J.createElement(jt,Object.assign({},i,{id:"add-image-single",ref:r,icon:kn}))});Wt.displayName="AddImageSingle";const vt={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),e=i.get(p.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,o=e.map(s=>{const{unitId:a,subUnitId:d,drawingId:g,drawingType:u}=s;return{unitId:a,subUnitId:d,drawingId:g,drawingType:u}});return r.executeCommand(Ce.id,{unitId:n,drawings:o})}},Me={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(p.ISheetDrawingService),n=i.get(E.ISheetSelectionRenderService),{direction:o}=r,s=e.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,d=s.map(u=>{const{transform:c}=u;if(c==null)return null;const m={...c},{left:h=0,top:f=0}=c;return o===l.Direction.UP?m.top=f-1:o===l.Direction.DOWN?m.top=f+1:o===l.Direction.LEFT?m.left=h-1:o===l.Direction.RIGHT&&(m.left=h+1),{...u,transform:m,sheetTransform:F(m,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(Ne.id,{unitId:a,drawings:d})?(t.syncExecuteCommand(G.id,[a]),!0):!1}},Bt="addition-and-subtraction-single",It="sheet.menu.image";function Wn(i){return{id:It,type:W.MenuItemType.SUBITEMS,icon:Bt,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 Bn(i){return{id:je.id,title:"sheetImage.upload.float",type:W.MenuItemType.BUTTON,hidden$:W.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function xn(i){return{id:_t.id,title:"sheetImage.upload.cell",type:W.MenuItemType.BUTTON,hidden$:W.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}const Ln="univer-image-common-panel",Yn="univer-image-common-panel-grid",$n="univer-image-common-panel-border",Fn="univer-image-common-panel-title",Gn="univer-image-common-panel-row",Hn="univer-image-common-panel-column",ge={imageCommonPanel:Ln,imageCommonPanelGrid:Yn,imageCommonPanelBorder:$n,imageCommonPanelTitle:Fn,imageCommonPanelRow:Gn,imageCommonPanelColumn:Hn},Vn=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:o}=i,s=o[0];if(s==null)return;const{unitId:a}=s,d=n.getRenderById(a),g=d==null?void 0:d.scene;if(g==null)return;const u=g.getTransformerByCreate(),[c,m]=J.useState(!0),h=(C=s.anchorType)!=null?C:p.SheetDrawingAnchorType.Position,[f,w]=J.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:P,subUnitId:N,drawingId:O,drawingType:M,anchorType:B,sheetTransform:Y}=b;T.push({unitId:P,subUnitId:N,drawingId:O,anchorType:B,sheetTransform:Y,drawingType:M})}),T}J.useEffect(()=>{const R=u.clearControl$.subscribe(T=>{T===!0&&m(!1)}),D=u.changeStart$.subscribe(T=>{var b;const{objects:I}=T,U=S(I,e);if(U.length===0)m(!1);else if(U.length>=1){m(!0);const P=((b=U[0])==null?void 0:b.anchorType)||p.SheetDrawingAnchorType.Position;w(P)}});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(Ne.id,{unitId:D[0].unitId,drawings:T})}const v=R=>R?"block":"none";return X.jsxs("div",{className:z.clsx(ge.imageCommonPanelGrid,ge.imageCommonPanelBorder),style:{display:v(c)},children:[X.jsx("div",{className:ge.imageCommonPanelRow,children:X.jsx("div",{className:z.clsx(ge.imageCommonPanelColumn,ge.imageCommonPanelTitle),children:X.jsx("div",{children:t.t("drawing-anchor.title")})})}),X.jsx("div",{className:z.clsx(ge.imageCommonPanelRow),children:X.jsx("div",{className:z.clsx(ge.imageCommonPanelColumn),children:X.jsxs(z.RadioGroup,{value:f,onChange:_,direction:"vertical",children:[X.jsx(z.Radio,{value:p.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),X.jsx(z.Radio,{value:p.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),X.jsx(z.Radio,{value:p.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})})]})},Xn=()=>{const i=W.useDependency(j.IDrawingManagerService),r=i.getFocusDrawings(),[t,e]=J.useState(r);return J.useEffect(()=>{const n=i.focus$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&X.jsxs("div",{className:ge.imageCommonPanel,children:[X.jsx(he.DrawingCommonPanel,{drawings:t}),X.jsx(Vn,{drawings:t})]})},Kn={[W.RibbonStartGroup.FORMULAS_INSERT]:{[It]:{order:3,menuItemFactory:Wn,[je.id]:{order:0,menuItemFactory:Bn},[_t.id]:{order:1,menuItemFactory:xn}}}};function ke(i){return!i.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(l.EDITOR_ACTIVATED)&&!i.getContextValue(l.FOCUSING_PANEL_EDITOR)&&i.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const zn={id:Me.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:W.KeyCode.ARROW_DOWN,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.DOWN}},Zn={id:Me.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:W.KeyCode.ARROW_UP,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.UP}},qn={id:Me.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:W.KeyCode.ARROW_LEFT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.LEFT}},Jn={id:Me.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:W.KeyCode.ARROW_RIGHT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.RIGHT}},Qn={id:vt.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:ke,binding:W.KeyCode.DELETE,mac:W.KeyCode.BACKSPACE};var er=Object.getOwnPropertyDescriptor,tr=(i,r,t,e)=>{for(var n=e>1?void 0:e?er(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},ye=(i,r)=>(t,e)=>r(t,e,i);let st=class extends l.Disposable{constructor(i,r,t,e,n,o){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Bt,Wt)),this.disposeWithMe(i.register(Ut,Xn))}_initMenus(){this._menuManagerService.mergeMenu(Kn)}_initCommands(){[je,_t,Ae,Ce,Ne,mt,G,pt,ft,St,Me,vt,wt].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[zn,Zn,qn,Jn,Qn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};st=tr([ye(0,l.Inject(W.ComponentManager)),ye(1,W.IMenuManagerService),ye(2,l.ICommandService),ye(3,W.IShortcutService),ye(4,j.IDrawingManagerService),ye(5,l.Inject(y.SheetsSelectionsService))],st);var nr=Object.defineProperty,rr=Object.getOwnPropertyDescriptor,ir=(i,r,t)=>r in i?nr(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,or=(i,r,t,e)=>{for(var n=e>1?void 0:e?rr(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},dt=(i,r)=>(t,e)=>r(t,e,i),xt=(i,r,t)=>ir(i,typeof r!="symbol"?r+"":r,t);const sr="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=Rt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:o,...s}=l.merge({},Rt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Ht,s)}onStarting(){l.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[st],[Qe],[ot],[it],[rt],[et],[tt],[nt]]),l.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[rt],[nt]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[it],[ot],[st],[et],[tt]])}onSteady(){this._injector.get(Qe)}_registerRenderModules(){[[exports.SheetDrawingUpdateController],[ht],[ut],[lt]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}};xt(exports.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);xt(exports.UniverSheetsDrawingUIPlugin,"pluginName",sr);exports.UniverSheetsDrawingUIPlugin=or([l.DependentOn(j.UniverDrawingPlugin,Ot.UniverDocsDrawingPlugin,he.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),dt(1,l.Inject(l.Injector)),dt(2,k.IRenderManagerService),dt(3,l.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=G;exports.DeleteDrawingsCommand=vt;exports.EditSheetDrawingOperation=pt;exports.GroupSheetDrawingCommand=ft;exports.InsertFloatImageCommand=je;exports.InsertSheetDrawingCommand=Ae;exports.MoveDrawingsCommand=Me;exports.RemoveSheetDrawingCommand=Ce;exports.SHEETS_IMAGE_MENU_ID=It;exports.SetDrawingArrangeCommand=wt;exports.SetSheetDrawingCommand=Ne;exports.SidebarSheetDrawingOperation=mt;exports.UngroupSheetDrawingCommand=St;
package/lib/es/index.js CHANGED
@@ -2385,7 +2385,8 @@ const Vs = (i) => {
2385
2385
  },
2386
2386
  onWheel: () => {
2387
2387
  },
2388
- unitId: o.unitId
2388
+ unitId: o.unitId,
2389
+ data: o.data
2389
2390
  };
2390
2391
  return [o.drawingId, m];
2391
2392
  }), [t, e, n, r]);
@@ -2450,13 +2451,19 @@ let kt = class extends ie {
2450
2451
  if (o) {
2451
2452
  const a = o.order.map((u) => {
2452
2453
  const d = o.data[u];
2453
- return d.drawingType === W.DRAWING_CHART ? {
2454
- ...d,
2455
- componentKey: this._componetManager.get(Zr)
2456
- } : d.drawingType === W.DRAWING_DOM ? {
2457
- ...d,
2458
- componentKey: this._componetManager.get(d.componentKey)
2459
- } : null;
2454
+ if (d.drawingType === W.DRAWING_CHART)
2455
+ return {
2456
+ ...d,
2457
+ componentKey: this._componetManager.get(Zr)
2458
+ };
2459
+ if (d.drawingType === W.DRAWING_DOM) {
2460
+ const l = this._sheetPrintInterceptorService.getPrintComponent(d.componentKey);
2461
+ return {
2462
+ ...d,
2463
+ componentKey: this._componetManager.get(l || d.componentKey)
2464
+ };
2465
+ }
2466
+ return null;
2460
2467
  }).filter(Boolean), c = qn(Vs, this._injector);
2461
2468
  return ls(
2462
2469
  /* @__PURE__ */ K(c, { floatDomInfos: a, scene: t.scene, skeleton: t.skeleton, worksheet: t.worksheet }),
package/lib/index.js CHANGED
@@ -2385,7 +2385,8 @@ const Vs = (i) => {
2385
2385
  },
2386
2386
  onWheel: () => {
2387
2387
  },
2388
- unitId: o.unitId
2388
+ unitId: o.unitId,
2389
+ data: o.data
2389
2390
  };
2390
2391
  return [o.drawingId, m];
2391
2392
  }), [t, e, n, r]);
@@ -2450,13 +2451,19 @@ let kt = class extends ie {
2450
2451
  if (o) {
2451
2452
  const a = o.order.map((u) => {
2452
2453
  const d = o.data[u];
2453
- return d.drawingType === W.DRAWING_CHART ? {
2454
- ...d,
2455
- componentKey: this._componetManager.get(Zr)
2456
- } : d.drawingType === W.DRAWING_DOM ? {
2457
- ...d,
2458
- componentKey: this._componetManager.get(d.componentKey)
2459
- } : null;
2454
+ if (d.drawingType === W.DRAWING_CHART)
2455
+ return {
2456
+ ...d,
2457
+ componentKey: this._componetManager.get(Zr)
2458
+ };
2459
+ if (d.drawingType === W.DRAWING_DOM) {
2460
+ const l = this._sheetPrintInterceptorService.getPrintComponent(d.componentKey);
2461
+ return {
2462
+ ...d,
2463
+ componentKey: this._componetManager.get(l || d.componentKey)
2464
+ };
2465
+ }
2466
+ return null;
2460
2467
  }).filter(Boolean), c = qn(Vs, this._injector);
2461
2468
  return ls(
2462
2469
  /* @__PURE__ */ K(c, { floatDomInfos: a, scene: t.scene, skeleton: t.skeleton, worksheet: t.worksheet }),
package/lib/umd/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  (function(O,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("@univerjs/docs-drawing"),require("@univerjs/drawing"),require("@univerjs/drawing-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("react/jsx-runtime"),require("react"),require("@univerjs/docs-ui"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-drawing","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","react/jsx-runtime","react","@univerjs/docs-ui","@univerjs/design"],c):(O=typeof globalThis<"u"?globalThis:O||self,c(O.UniverSheetsDrawingUi={},O.UniverCore,O.UniverDocsDrawing,O.UniverDrawing,O.UniverDrawingUi,O.UniverEngineRender,O.UniverSheetsDrawing,O.UniverSheetsUi,O.UniverUi,O.rxjs,O.UniverSheets,O.React,O.React,O.UniverDocsUi,O.UniverDesign))})(this,function(O,c,pe,k,ue,W,p,E,B,N,C,X,Q,Le,Z){"use strict";var Zn=Object.defineProperty;var qn=(O,c,pe)=>c in O?Zn(O,c,{enumerable:!0,configurable:!0,writable:!0,value:pe}):O[c]=pe;var oe=(O,c,pe)=>qn(O,typeof c!="symbol"?c+"":c,pe);const $t="sheets-drawing-ui.config",Dt={},G={id:"sheet.operation.clear-drawing-transformer",type:c.CommandType.MUTATION,handler:(i,r)=>{const t=i.get(W.IRenderManagerService);return r.forEach(e=>{var n,o;(o=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},we={id:"sheet.command.remove-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{var _,D,b;const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(C.SheetInterceptorService),o=i.get(p.ISheetDrawingService);if(!r)return!1;const{drawings:a}=r,s=[];a.forEach(y=>{const{unitId:M}=y;s.push(M)});const l=o.getBatchRemoveOp(a),{unitId:g,subUnitId:u,undo:d,redo:m,objects:h}=l,f=n.onCommandExecute({id:we.id,params:r}),S={id:p.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:m,objects:h,type:p.DrawingApplyType.REMOVE}},w={id:p.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:d,objects:h,type:p.DrawingApplyType.INSERT}};return c.sequenceExecute([...(_=f.preRedos)!=null?_:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(D=f.preUndos)!=null?D:[],w,...f.undos,{id:G.id,params:s}],redoMutations:[...(b=f.preRedos)!=null?b:[],S,...f.redos,{id:G.id,params:s}]}),!0):!1}},Tt="COMPONENT_SHEET_DRAWING_PANEL",dt={id:"sidebar.operation.sheet-image",type:c.CommandType.COMMAND,handler:async(i,r)=>{const t=i.get(B.ISidebarService),e=i.get(c.LocaleService),n=i.get(c.IUniverInstanceService),o=i.get(c.ICommandService);if(!C.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Tt},onClose:()=>{o.syncExecuteCommand(k.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},lt={id:"sheet.operation.edit-sheet-image",type:c.CommandType.OPERATION,handler:(i,r)=>{const t=i.get(c.ICommandService);return r==null?!1:(t.syncExecuteCommand(k.SetDrawingSelectedOperation.id,[r]),t.executeCommand(dt.id,{value:"open"}),!0)}},Ye={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",uploadLoadingBodyText:"univer-upload-loading-body-text"},Ft=()=>{const i=B.useDependency(k.IImageIoService),r=B.useDependency(c.LocaleService),[t,e]=Q.useState(0);return Q.useEffect(()=>{const n=i.change$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[i]),X.jsx("div",{style:{display:t>0?"block":"none"},className:Ye.uploadLoading,children:X.jsxs("div",{className:Ye.uploadLoadingBody,children:[X.jsx("div",{className:Ye.uploadLoadingBodyAnimation}),X.jsx("div",{className:Ye.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${t}`})]})})};var Gt=Object.getOwnPropertyDescriptor,Ht=(i,r,t,e)=>{for(var n=e>1?void 0:e?Gt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},ge=(i,r)=>(t,e)=>r(t,e,i);let $e=class extends c.RxDisposable{constructor(r,t,e,n,o,a,s,l){super();oe(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=t,this._canvasPopManagerService=e,this._renderManagerService=n,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._commandService=l,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(c.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(c.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(B.BuiltInUIPart.CONTENT,()=>B.connectInjector(Ft,this._injector))}_dispose(r){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 ue.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const t=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(c.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const a=e.getSelectedObjectMap();if(a.size>1){n==null||n.dispose();return}const s=a.values().next().value;if(!s)return;const l=s.oKey,g=this._drawingManagerService.getDrawingOKey(l);if(!g)return;const{unitId:u,subUnitId:d,drawingId:m,drawingType:h}=g,f=g.data;if(f&&f.disablePopup)return;n==null||n.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,d,m,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:ue.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,d,m,h)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(k.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[c.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:lt.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:we.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ue.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ue.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===c.DrawingTypeEnum.DRAWING_DOM}]}};$e=Ht([ge(0,c.Inject(c.Injector)),ge(1,k.IDrawingManagerService),ge(2,c.Inject(E.SheetCanvasPopManagerService)),ge(3,W.IRenderManagerService),ge(4,c.IUniverInstanceService),ge(5,c.IContextService),ge(6,c.Inject(B.IUIPartsService)),ge(7,c.ICommandService)],$e);var Vt=Object.getOwnPropertyDescriptor,Xt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Vt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Fe=(i,r)=>(t,e)=>r(t,e,i);let ut=class extends c.Disposable{constructor(r,t,e,n,o){super();oe(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=t,this._selectionsService=e,this._drawingRenderService=n,this._sheetSkeletonManagerService=o,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(N.throttleTime(33)).subscribe(r=>{var e,n;let t=[];r!==null&&(t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),t.length>0&&(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&t.length===1&&((e=t[0].primary)==null?void 0:e.actualRow)===r.row&&((n=t[0].primary)==null?void 0:n.actualColumn)===r.col?(this._isSetCursor=!0,this._context.scene.setCursor(W.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(r=>{var t;if(r!=null&&r.drawing&&this._isSetCursor){const e=r.drawing.drawing.drawingOrigin,n=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap.getImage(e.imageSourceType,e.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};ut=Xt([Fe(1,c.Inject(E.HoverManagerService)),Fe(2,c.Inject(C.SheetsSelectionsService)),Fe(3,c.Inject(ue.DrawingRenderService)),Fe(4,c.Inject(E.SheetSkeletonManagerService))],ut);function q(i,r,t){const{from:e,to:n,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:l=0,skewY:g=0}=i,u=t.getCurrent();if(u==null)return;const d=E.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:m,top:h,width:f,height:S}=d;const w=t.getCurrentSkeleton(),v=w.rowHeaderWidth+w.columnTotalWidth,_=w.columnHeaderHeight+w.rowTotalHeight;return m+f>v&&(m=v-f),h+S>_&&(h=_-S),{flipY:o,flipX:a,angle:s,skewX:l,skewY:g,left:m,top:h,width:f,height:S}}function H(i,r){const{left:t=0,top:e=0,width:n=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:l=0,skewX:g=0,skewY:u=0}=i,d=r.getCellWithCoordByOffset(t,e);if(d==null)return;const m={column:d.actualColumn,columnOffset:W.precisionTo(t-d.startX,1),row:d.actualRow,rowOffset:W.precisionTo(e-d.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+o);if(h==null)return;const f={column:h.actualColumn,columnOffset:W.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:W.precisionTo(e+o-h.startY,1)};return{flipY:a,flipX:s,angle:l,skewX:g,skewY:u,from:m,to:f}}var Kt=Object.getOwnPropertyDescriptor,xt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Kt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ge=(i,r)=>(t,e)=>r(t,e,i);let gt=class extends c.Disposable{constructor(i,r,t,e,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const t=i[r];for(const e in t.data){const n=t.data[e];n.transform=q(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};gt=xt([Ge(1,p.ISheetDrawingService),Ge(2,k.IDrawingManagerService),Ge(3,c.Inject(E.ISheetSelectionRenderService)),Ge(4,c.Inject(E.SheetSkeletonManagerService))],gt);function zt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:a,drawingId:s}=e,l=W.getGroupState(0,0,n.map(d=>d.transform||{})),g=n.map(d=>{const m=d.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:S}=d;return{unitId:h,subUnitId:f,drawingId:S,transform:{...m,left:m.left-l.left,top:m.top-l.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:l};r.push({parent:u,children:g})}),r}function Zt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:a,drawingId:s,transform:l={width:0,height:0}}=e;if(l==null)return;const g=n.map(d=>{const{transform:m}=d,{unitId:h,subUnitId:f,drawingId:S}=d,w=W.transformObjectOutOfGroup(m||{},l,l.width||0,l.height||0);return{unitId:h,subUnitId:f,drawingId:S,transform:w,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const ht={id:"sheet.command.group-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=n.getGroupDrawingOp(r),{unitId:s,subUnitId:l,undo:g,redo:u,objects:d}=a;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:d,type:p.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:l,objects:Zt(d),type:p.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:d,type:p.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!0):!1}},Re={id:"sheet.command.insert-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{var _,D,b;const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(p.ISheetDrawingService),o=i.get(C.SheetInterceptorService);if(!r)return!1;const a=r.drawings,s=a.map(y=>y.unitId),l=n.getBatchAddOp(a),{unitId:g,subUnitId:u,undo:d,redo:m,objects:h}=l,f=o.onCommandExecute({id:Re.id,params:r}),S={id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:g,subUnitId:u,objects:h,type:p.DrawingApplyType.INSERT}},w={id:p.SetDrawingApplyMutation.id,params:{op:d,unitId:g,subUnitId:u,objects:h,type:p.DrawingApplyType.REMOVE}};return c.sequenceExecute([...(_=f.preRedos)!=null?_:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(D=f.preUndos)!=null?D:[],w,...f.undos,{id:G.id,params:s}],redoMutations:[...(b=f.preRedos)!=null?b:[],S,...f.redos,{id:G.id,params:s}]}),!0):!1}},mt={id:"sheet.command.set-drawing-arrange",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService);if(!r)return!1;const n=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:l}=r,g={unitId:o,subUnitId:a,drawingIds:s};let u;if(l===c.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):l===c.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):l===c.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):l===c.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:d,redo:m,undo:h}=u;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:m,unitId:o,subUnitId:a,objects:d,type:p.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:d,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:a,objects:d,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}},Ee={id:"sheet.command.set-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=n.getBatchUpdateOp(o),{unitId:s,subUnitId:l,undo:g,redo:u,objects:d}=a;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:s,subUnitId:l,op:u,objects:d,type:p.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:g,objects:d,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:u,objects:d,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}]}),!0):!1}},pt={id:"sheet.command.ungroup-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=n.getUngroupDrawingOp(r),{unitId:s,subUnitId:l,undo:g,redo:u,objects:d}=a;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:d,type:p.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:l,objects:zt(d),type:p.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:d,type:p.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};var qt=Object.getOwnPropertyDescriptor,Jt=(i,r,t,e)=>{for(var n=e>1?void 0:e?qt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},ee=(i,r)=>(t,e)=>r(t,e,i);function Qt(i,r,t){const e=t*Math.PI/180,n=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),o=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:o}}function ft(i,r,t,e,n){var _;const{rotatedHeight:o,rotatedWidth:a}=Qt(t,e,n),l=i.get(W.IRenderManagerService).getRenderById(r.unitId);if(!l)return!1;const u=(_=l.with(E.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:_.skeleton;if(u==null)return!1;const d=u.getCellByIndex(r.row,r.col),m=d.mergeInfo.endX-d.mergeInfo.startX-2,h=d.mergeInfo.endY-d.mergeInfo.startY-2,f=a/o,w=Math.ceil(Math.min(m,h*f))/a,v=!w||Number.isNaN(w)?.001:w;return{width:t*v,height:e*v}}O.SheetDrawingUpdateController=class extends c.Disposable{constructor(t,e,n,o,a,s,l,g,u,d,m,h,f){super();oe(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=o,this._imageIoService=a,this._fileOpenerService=s,this._sheetDrawingService=l,this._drawingManagerService=g,this._contextService=u,this._messageService=d,this._localeService=m,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:k.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),e=t.length;return e>k.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(k.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:k.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(t,e){return this._insertCellImage(t,e)}async insertFloatImageByFile(t){let e;try{e=await this._imageIoService.saveImage(t)}catch(D){const b=D.message;b===k.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(k.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):b===k.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):b===k.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const n=this._getUnitInfo(),{unitId:o,subUnitId:a}=n,{imageId:s,imageSourceType:l,source:g,base64Cache:u}=e,{width:d,height:m,image:h}=await k.getImageSize(u||""),{width:f,height:S}=this._context.scene;this._imageIoService.addImageSourceCache(g,l,h);let w=1;if(d>k.DRAWING_IMAGE_WIDTH_LIMIT||m>k.DRAWING_IMAGE_HEIGHT_LIMIT){const D=k.DRAWING_IMAGE_WIDTH_LIMIT/d,b=k.DRAWING_IMAGE_HEIGHT_LIMIT/m;w=Math.max(D,b)}const v=this._getImagePosition(d*w,m*w,f,S);if(v==null)return;const _={unitId:o,subUnitId:a,drawingId:s,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:g,transform:q(v,this._selectionRenderService,this._skeletonManagerService),sheetTransform:v};return this._commandService.executeCommand(Re.id,{unitId:o,drawings:[_]})}async _insertCellImage(t,e){var _,D;let n;try{n=await this._imageIoService.saveImage(t)}catch(b){const y=b.message;y===k.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(k.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===k.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===k.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:o,imageSourceType:a,source:s,base64Cache:l}=n,{width:g,height:u,image:d}=await k.getImageSize(l||"");this._imageIoService.addImageSourceCache(s,a,d);const m=this._workbookSelections.getCurrentLastSelection();if(!m)return!1;const h=c.createDocumentModelWithStyle("",{}),f=ft(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:m.primary.actualRow,col:m.primary.actualColumn},g,u,0);if(!f)return!1;const S={size:{width:f.width,height:f.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},w={unitId:h.getUnitId(),subUnitId:h.getUnitId(),drawingId:o,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:s,transform:Le.docDrawingPositionToTransform(S),docTransform:S,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},v=c.BuildTextUtils.drawing.add({documentDataModel:h,drawings:[w],selection:{collapsed:!0,startOffset:0,endOffset:0}});return v?(h.apply(v),this._commandService.syncExecuteCommand(C.SetRangeValuesCommand.id,{value:{[(_=e==null?void 0:e.row)!=null?_:m.primary.actualRow]:{[(D=e==null?void 0:e.col)!=null?D:m.primary.actualColumn]:{p:h.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,f;const{width:n,height:o,image:a}=await k.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,c.ImageSourceType.URL,a);const s=this._workbookSelections.getCurrentLastSelection();if(!s)return!1;const l=c.createDocumentModelWithStyle("",{}),g=ft(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:s.primary.actualRow,col:s.primary.actualColumn},n,o,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},d={unitId:l.getUnitId(),subUnitId:l.getUnitId(),drawingId:c.generateRandomId(),drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c.ImageSourceType.URL,source:t,transform:Le.docDrawingPositionToTransform(u),docTransform:u,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},m=c.BuildTextUtils.drawing.add({documentDataModel:l,drawings:[d],selection:{collapsed:!0,startOffset:0,endOffset:0}});return m?(l.apply(m),this._commandService.syncExecuteCommand(C.SetRangeValuesCommand.id,{value:{[(h=e==null?void 0:e.row)!=null?h:s.primary.actualRow]:{[(f=e==null?void 0:e.col)!=null?f:s.primary.actualColumn]:{p:l.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}_getUnitInfo(){const t=this._context.unit,e=t.getActiveSheet(),n=t.getUnitId(),o=e.getSheetId();return{unitId:n,subUnitId:o}}_getImagePosition(t,e,n,o){const a=this._workbookSelections.getCurrentSelections();let s={startRow:0,endRow:0,startColumn:0,endColumn:0};a&&a.length>0&&(s=a[a.length-1].range);const l=E.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);if(l==null)return;let{startColumn:g,startRow:u,startX:d,startY:m}=l,h=!1;if(d+t>n&&(d=n-t,d<0&&(d=0,t=n),h=!0),m+e>o&&(m=o-e,m<0&&(m=0,e=o),h=!0),h){const v=this._selectionRenderService.getCellWithCoordByOffset(d,m);if(v==null)return;d=v.startX,m=v.startY,g=v.actualColumn,u=v.actualRow}const f={column:g,columnOffset:0,row:u,rowOffset:0},S=this._selectionRenderService.getCellWithCoordByOffset(d+t,m+e);if(S==null)return;const w={column:S.actualColumn,columnOffset:d+t-S.startX,row:S.actualRow,rowOffset:m+e-S.startY};return{from:f,to:w}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:o,arrangeType:a}=t;this._commandService.executeCommand(mt.id,{unitId:e,subUnitId:n,drawingIds:o,arrangeType:a})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:o,subUnitId:a,drawingId:s,drawingType:l,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:s});if(u==null||u.unitId!==this._context.unitId)return;const d=H({...u.transform,...g},this._selectionRenderService);if(d==null)return;const m={...n,transform:{...u.transform,...g,...q(d,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...d}};e.push(m)}),e.length>0&&this._commandService.executeCommand(Ee.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(ht.id,t);const{unitId:e,subUnitId:n,drawingId:o}=t[0].parent;this._commandService.syncExecuteCommand(k.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:o}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(pt.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}},O.SheetDrawingUpdateController=Jt([ee(1,c.Inject(E.SheetSkeletonManagerService)),ee(2,c.ICommandService),ee(3,E.ISheetSelectionRenderService),ee(4,k.IImageIoService),ee(5,B.ILocalFileService),ee(6,p.ISheetDrawingService),ee(7,k.IDrawingManagerService),ee(8,c.IContextService),ee(9,B.IMessageService),ee(10,c.Inject(c.LocaleService)),ee(11,c.Inject(C.SheetsSelectionsService)),ee(12,c.Inject(c.Injector))],O.SheetDrawingUpdateController);var en=Object.getOwnPropertyDescriptor,tn=(i,r,t,e)=>{for(var n=e>1?void 0:e?en(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},ve=(i,r)=>(t,e)=>r(t,e,i);function Mt(i,r,t){var e,n,o,a;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((a=(o=t.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const s=t.p.drawings[t.p.drawingsOrder[0]],l=ft(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},s.docTransform.size.width,s.docTransform.size.height,s.docTransform.angle);if(l)return s.transform.width=l.width,s.transform.height=l.height,s.docTransform.size.width=l.width,s.docTransform.size.height=l.height,s.transform.left=0,s.transform.top=0,s.docTransform.positionH.posOffset=0,s.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let He=class extends c.Disposable{constructor(i,r,t,e,n,o){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=o,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===Le.ReplaceSnapshotCommand.id&&i.params.unitId===c.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(C.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:C.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,t)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0},Mt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),t(i)}}))}};He=tn([ve(0,c.ICommandService),ve(1,c.Inject(C.SheetInterceptorService)),ve(2,c.Inject(c.Injector)),ve(3,k.IDrawingManagerService),ve(4,c.Inject(pe.DocDrawingController)),ve(5,c.Inject(E.IEditorBridgeService))],He);var nn=Object.getOwnPropertyDescriptor,rn=(i,r,t,e)=>{for(var n=e>1?void 0:e?nn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},bt=(i,r)=>(t,e)=>r(t,e,i);let Ve=class extends c.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,t,e)=>{new c.ObjectMatrix(e).forValue((n,o,a)=>{Mt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},a)})}}))}};Ve=rn([bt(0,c.Inject(E.IAutoFillService)),bt(1,c.Inject(c.Injector))],Ve);var on=Object.getOwnPropertyDescriptor,an=(i,r,t,e)=>{for(var n=e>1?void 0:e?on(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Oe=(i,r)=>(t,e)=>r(t,e,i);const sn=[c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,c.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,c.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let Xe=class extends c.Disposable{constructor(i,r,t,e,n){super(),this._commandService=i,this._univerInstanceService=r,this._dialogService=t,this._renderManagerService=e,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(i){var n;const r=c.createDocumentModelWithStyle("",{}),t=(n=W.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(E.EditingRenderController),e=c.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[i],selection:{collapsed:!0,startOffset:0,endOffset:0}});e&&(r.apply(e),t&&t.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(i=>{var r,t;if(i.id===Le.InnerPasteCommand.id){const e=i.params,{doc:n}=e,o=this._univerInstanceService.getCurrentUnitOfType(c.UniverInstanceType.UNIVER_DOC);if(o==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const a=o.getUnitId();if(sn.includes(a)){if(a!==c.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const s=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(E.SetCellEditVisibleOperation.id,{visible:!1})};((t=o.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:s,showOk:!0,showCancel:!0,onOk:()=>{s(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:s})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};Xe=an([Oe(0,c.ICommandService),Oe(1,c.IUniverInstanceService),Oe(2,B.IDialogService),Oe(3,W.IRenderManagerService),Oe(4,c.Inject(c.LocaleService))],Xe);const Pe={id:"sheet.command.insert-float-image",type:c.CommandType.COMMAND,handler:async(i,r)=>{var a,s;const t=i.get(c.IUniverInstanceService),e=i.get(W.IRenderManagerService),n=(a=W.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:a.with(O.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const l=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(l)).every(g=>g)}else return(s=n.insertFloatImage())!=null?s:!1}},St={id:"sheet.command.insert-cell-image",type:c.CommandType.COMMAND,handler:i=>{var e,n;const r=i.get(c.IUniverInstanceService),t=i.get(W.IRenderManagerService);return(n=(e=W.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,r,t))==null?void 0:e.with(O.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}};var cn=Object.getOwnPropertyDescriptor,dn=(i,r,t,e)=>{for(var n=e>1?void 0:e?cn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ae=(i,r)=>(t,e)=>r(t,e,i);const Rt="image/png";function ln(i){const r=i.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=t.charCodeAt(o);return new Blob([n],{type:Rt})}function un(i){const r=new ClipboardItem({[Rt]:ln(i)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function gn(){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 Et=[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 Ke=class extends c.Disposable{constructor(r,t,e,n,o){super();oe(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const o=this._focusedDrawings;if(o.length>0){const[a]=o;if(n===E.COPY_TYPE.CUT){const l={unitId:r,drawings:[a]};this._commandService.executeCommand(we.id,l)}setTimeout(()=>{const l=gn();a.drawingType===c.DrawingTypeEnum.DRAWING_IMAGE&&a.imageSourceType===k.ImageSourceType.BASE64?un(a.source):this._clipboardInterfaceService.writeText(""),l()},200);const s={unitId:a.unitId,subUnitId:a.subUnitId,drawings:[a]};this._copyInfo=s}else{const a=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=a}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=E.COPY_TYPE.COPY,pasteType:a}=n,{range:s}=r||{},{range:l,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:a,unitId:g,subUnitId:u,pasteRange:l},{copyRange:s,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:a},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:Pe.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var m;const n=(m=this._renderManagerService.getRenderById(r))==null?void 0:m.with(E.SheetSkeletonManagerService);if(!n)return;const o=n.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:s,startY:l,endY:g}=o,u=this._drawingService.getDrawingData(r,t),d=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const f=u[h],{transform:S}=f;if(f.anchorType!==p.SheetDrawingAnchorType.Both||!S)return;const{left:w=0,top:v=0,width:_=0,height:D=0}=S,{drawingStartX:b,drawingEndX:y,drawingStartY:M,drawingEndY:I}={drawingStartX:w,drawingEndX:w+_,drawingStartY:v,drawingEndY:v+D};a<=b&&y<=s&&l<=M&&I<=g&&d.push(f)}),d.length)return{copyRange:e,drawings:d,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Et.includes(e))return{redos:[],undos:[]};const{unitId:o,subUnitId:a,range:s}=n,l=this._renderManagerService.getRenderById(o),g=l==null?void 0:l.with(E.SheetSkeletonManagerService),u=l==null?void 0:l.with(E.ISheetSelectionRenderService),d=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:m}=d,h=E.discreteRangeToRange(s);return this._generateMutations(m,{unitId:o,subUnitId:a,isCut:t===E.COPY_TYPE.CUT,getTransform:(f,S)=>{var _;const w=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),v={...f,left:w==null?void 0:w.startX,top:w==null?void 0:w.startY};return{transform:v,sheetTransform:(_=H(v,u))!=null?_:S}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:o,isCut:a}=t,s=[],l=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:d,sheetTransform:m}=u;if(!d)return;const h=o(d,m),f={...u,unitId:e,subUnitId:n,drawingId:a?u.drawingId:c.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(a){const{undo:S,redo:w,objects:v}=g.getBatchUpdateOp([f]);s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:p.DrawingApplyType.UPDATE,op:w,objects:v}}),l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:p.DrawingApplyType.UPDATE,op:S,objects:v}})}else{const{undo:S,redo:w,objects:v}=g.getBatchAddOp([f]);s.push({id:p.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:v,type:p.DrawingApplyType.INSERT}}),l.push({id:p.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:n,objects:v,type:p.DrawingApplyType.REMOVE}})}}),{redos:s,undos:l}}_generateRangeDrawingsPasteMutations(r,t){var A;const{unitId:e,subUnitId:n,pasteType:o,pasteRange:a}=r,{copyRange:s,copyType:l}=t;if(Et.includes(o))return{redos:[],undos:[]};const g=(A=this._renderManagerService.getRenderById(e))==null?void 0:A.with(E.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!s)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:E.discreteRangeToRange(a)},pasteType:o},l);const{ranges:[d,m],mapFunc:h}=E.virtualizeDiscreteRanges([s,a]),{row:f,col:S}=h(d.startRow,d.startColumn),{row:w,col:v}=h(m.startRow,m.startColumn),_=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:S,endColumn:S}),D=g.attachRangeWithCoord({startRow:w,endRow:w,startColumn:v,endColumn:v});if(!_||!D||!this._copyInfo)return{redos:[],undos:[]};const b=D.startX-_.startX,y=D.startY-_.startY,M=w-f,I=v-S;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(R,U)=>{var j,P;return{transform:{...R,left:((j=R==null?void 0:R.left)!=null?j:0)+b,top:((P=R==null?void 0:R.top)!=null?P:0)+y},sheetTransform:{...U,to:{...U.to,row:U.to.row+M,column:U.to.column+I},from:{...U.from,row:U.from.row+M,column:U.from.column+I}}}},isCut:l===E.COPY_TYPE.CUT})}};Ke=dn([Ae(0,E.ISheetClipboardService),Ae(1,W.IRenderManagerService),Ae(2,k.IDrawingManagerService),Ae(3,B.IClipboardInterfaceService),Ae(4,c.ICommandService)],Ke);var hn=Object.getOwnPropertyDescriptor,mn=(i,r,t,e)=>{for(var n=e>1?void 0:e?hn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ue=(i,r)=>(t,e)=>r(t,e,i);let xe=class extends c.Disposable{constructor(i,r,t,e,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([i,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingVisible(!1);return}const a=e.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new C.WorkbookViewPermission(a).id,new C.WorksheetViewPermission(a,s).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,o)})):(this._drawingManagerService.setDrawingVisible(!1),N.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(i,r){this._drawingManagerService.setDrawingVisible(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),a=this._renderManagerService.getRenderById(t),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===W.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.removeObject(g)})}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([i,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingEditable(!1);return}const a=e.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new C.WorkbookEditablePermission(a).id,new C.WorksheetEditPermission(a,s).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,o)})):(this._drawingManagerService.setDrawingEditable(!1),N.EMPTY))).subscribe())}_handleDrawingEditableFalse(i,r){this._drawingManagerService.setDrawingEditable(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),a=this._renderManagerService.getRenderById(t),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===W.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.detachTransformerFrom(g)})}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=t.getUnitId(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),l=s==null?void 0:s.scene;if(!l)return N.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new C.WorkbookViewPermission(o).id,new C.WorksheetViewPermission(o,a).id]).pipe(N.map(d=>d.every(m=>m.value)),N.distinctUntilChanged()).pipe(N.map(d=>({permission:d,scene:l,transformer:g,unitId:o,subUnitId:a})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingVisible(t);const s=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(o,a),g=Object.values(l);t?this._drawingManagerService.addNotification(g):(s.forEach(u=>{u.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),o=e==null?void 0:e.getSheetId();if(!n||!o)return;const a=this._drawingManagerService.getDrawingData(n,o),s=Object.values(a);this._drawingManagerService.addNotification(s)}}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=t.getUnitId(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),l=s==null?void 0:s.scene;if(!l)return N.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new C.WorkbookEditablePermission(o).id,new C.WorksheetEditPermission(o,a).id]).pipe(N.map(d=>d.every(m=>m.value)),N.distinctUntilChanged()).pipe(N.map(d=>({permission:d,scene:l,transformer:g,unitId:o,subUnitId:a})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingEditable(t);const s=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(o,a),g=Object.values(l);t?(s.forEach(u=>{u.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(s.forEach(u=>{u.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const o=n.getSheetId(),a=this._renderManagerService.getRenderById(e),s=a==null?void 0:a.scene;if(!s)return;const l=this._drawingManagerService.getDrawingData(e,o),g=Object.values(l);this._drawingManagerService.setDrawingEditable(!0),s.getAllObjectsByOrder().forEach(d=>{d.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(m=>d.oKey.includes(m.drawingId))&&s.detachTransformerFrom(d)})}}))}};xe=mn([Ue(0,k.IDrawingManagerService),Ue(1,W.IRenderManagerService),Ue(2,c.IPermissionService),Ue(3,c.IUniverInstanceService),Ue(4,c.Inject(c.UserManagerService))],xe);var pn=Object.getOwnPropertyDescriptor,fn=(i,r,t,e)=>{for(var n=e>1?void 0:e?pn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},fe=(i,r)=>(t,e)=>r(t,e,i);function Ot(i,r,t,e,n,o=!1){const{scaleX:a,scaleY:s}=r.getAncestorScale(),l=r.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=e.getFreeze(),{startColumn:u,startRow:d,xSplit:m,ySplit:h}=g,f={left:!0,top:!0};if(!l)return{...i,absolute:f};const{left:S,right:w,top:v,bottom:_}=i;let{top:D,left:b,viewportScrollX:y,viewportScrollY:M}=l;const{boundsOfViewArea:I,scrollDirectionResponse:A}=n||{},{rowHeaderWidth:R,columnHeaderHeight:U}=t,j={top:o?0:U,left:o?0:R};I&&(c.Tools.isDefine(j.top)&&(j.top=I.top),c.Tools.isDefine(j.left)&&(j.left=I.left)),A==="HORIZONTAL"&&(M=0),A==="VERTICAL"&&(y=0);let P=0,T=0;const L=t.rowStartY(d-h)+U,F=t.colStartX(u-m)+R,J=t.rowStartY(d)+U,ne=t.colStartX(u)+R;if(m===0)f.left=!1,P=(S-y)*a,T=(w-y)*a;else{const x=S-(F-R),Y=w-(F-R);w<ne?(P=x*a,T=Y*a):S<=ne&&w>=ne?(P=x*a,T=Math.max(b,(w-y)*a)):S>ne&&(f.left=!1,P=Math.max((S-y)*a,b),T=Math.max((w-y)*a,b))}let K=0,z=0;if(h===0)f.top=!1,K=(v-M)*s,z=(_-M)*s;else{const x=v-(L-U),Y=_-(L-U);_<J?(K=x*s,z=Y*s):v<=J&&_>=J?(K=x*s,z=Math.max(D,(_-M)*s)):v>J&&(f.top=!1,K=Math.max((v-M)*s,D),z=Math.max((_-M)*s,D))}return P=Math.max(P,j.left),K=Math.max(K,j.top),T=Math.max(T,j.left),z=Math.max(z,j.top),{left:P,right:T,top:K,bottom:z,absolute:f}}const ae=(i,r,t,e,n)=>{const{left:o,top:a,width:s,height:l,angle:g}=i,u={left:o,right:o+s,top:a,bottom:a+l},d=Ot(u,r,t,e,n),{scaleX:m,scaleY:h}=r.getAncestorScale();return{startX:d.left,endX:d.right,startY:d.top,endY:d.bottom,rotate:g,width:s*m,height:l*h,absolute:d.absolute}};O.SheetCanvasFloatDomManagerService=class extends c.Disposable{constructor(t,e,n,o,a,s,l){super();oe(this,"_domLayerInfoMap",new Map);oe(this,"_transformChange$",new N.Subject);oe(this,"transformChange$",this._transformChange$.asObservable());oe(this,"_add$",new N.Subject);oe(this,"add$",this._add$.asObservable());oe(this,"_remove$",new N.Subject);oe(this,"remove$",this._remove$.asObservable());this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=s,this._lifecycleService=l,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(N.filter(t=>t===c.LifecycleStages.Rendered),N.take(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}getFloatDomsBySubUnitId(t,e){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===e&&n.unitId===t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const o=n.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:n,transformer:o,renderUnit:e,canvas:a}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var x;const{unitId:n,subUnitId:o,drawingId:a}=e,s=C.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),l=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,c.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!l||!s)return;const d=(x=this._renderManagerService.getRenderById(n))==null?void 0:x.with(E.SheetSkeletonManagerService).getSkeletonParam(o);if(!d)return;const{transform:m,drawingType:h,data:f}=l;if(h!==c.DrawingTypeEnum.DRAWING_DOM&&h!==c.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(n);if(S==null)return;const{scene:w,canvas:v}=S;if(m==null)return!0;if(u!==o)return;const{left:_,top:D,width:b,height:y,angle:M,flipX:I,flipY:A,skewX:R,skewY:U}=m,j=k.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),P=w.getObject(j);if(P!=null){P.transformByState({left:_,top:D,width:b,height:y,angle:M,flipX:I,flipY:A,skewX:R,skewY:U});return}const T={left:_,top:D,width:b,height:y,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},L=h===c.DrawingTypeEnum.DRAWING_CHART;if(T.rotateEnabled=!1,L){const Y=f?f.backgroundColor:"white";T.fill=Y,f&&f.border&&(T.stroke=f.border),T.paintFirst="stroke",T.strokeWidth=1,T.borderEnabled=!1,T.radius=8}const F=new W.Rect(j,T);L&&F.setObjectType(W.ObjectType.CHART),w.addObject(F,W.DRAWING_OBJECT_LAYER_INDEX),l.allowTransform!==!1&&w.attachTransformerTo(F);const J=new c.DisposableCollection,ne=ae(F,S.renderUnit.scene,d.skeleton,s.worksheet),K=new N.BehaviorSubject(ne),z={dispose:J,rect:F,position$:K,unitId:n,subUnitId:o,id:a};this._canvasFloatDomService.addFloatDom({position$:K,id:a,componentKey:l.componentKey,onPointerDown:Y=>{v.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{v.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{v.dispatchEvent(new PointerEvent(Y.type,Y))},onWheel:Y=>{v.dispatchEvent(new WheelEvent(Y.type,Y))},data:f,unitId:n});const re=F.onTransformChange$.subscribeEvent(()=>{const Y=ae(F,S.renderUnit.scene,d.skeleton,s.worksheet);K.next(Y)});J.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),re&&J.add(re),this._domLayerInfoMap.set(a,z)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{const{unitId:n,subUnitId:o,drawingId:a}=e,s=k.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),l=this._getSceneAndTransformerByDrawingSearch(n);if(l==null)return;const{transformer:g,scene:u}=l,d=u.getObject(s);d!=null&&d.oKey&&g.clearControlByIds([d==null?void 0:d.oKey])})}))}_scrollUpdateListener(){const t=(e,n)=>{var g;const o=this._getSceneAndTransformerByDrawingSearch(e),a=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),s=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),l=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(E.SheetSkeletonManagerService).getSkeletonParam(n);!o||!s||!l||a.forEach(u=>{const d=this._domLayerInfoMap.get(u);if(d){const m=ae(d.rect,o.renderUnit.scene,l.skeleton,s.worksheet,d);d.position$.next(m)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(e=>e?e.activeSheet$:N.of(null)),N.map(e=>{if(!e)return null;const n=e.getUnitId(),o=this._renderManagerService.getRenderById(n);return o?{render:o,unitId:n,subUnitId:e.getSheetId()}:null}),N.switchMap(e=>e?c.fromEventSubject(e.render.scene.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(N.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):N.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:o}=e;t(n,o)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===E.SetZoomRatioOperation.id){const n=e.params,{unitId:o}=n;Array.from(this._domLayerInfoMap.values()).filter(s=>s.unitId===o).map(s=>s.subUnitId).forEach(s=>{t(o,s)})}else if(e.id===C.SetFrozenMutation.id){const{unitId:n,subUnitId:o}=e.params;t(n,o)}}))}_getPosition(t,e){var h;const{startX:n,endX:o,startY:a,endY:s}=t,l=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(E.ISheetSelectionRenderService);if(l==null)return;const g=l.getCellWithCoordByOffset(n,a);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:a-g.startY},d=l.getCellWithCoordByOffset(o,s);if(d==null)return;const m={column:d.actualColumn,columnOffset:o-d.startX,row:d.actualRow,rowOffset:s-d.startY};return{from:u,to:m}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==c.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==c.DrawingTypeEnum.DRAWING_CHART)return;const o={...n.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,o){const a=this._domLayerInfoMap.get(n),s=this._getSceneAndTransformerByDrawingSearch(t);if(a&&s){const{scene:l}=s,g=k.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=l.getObject(g);u&&u instanceof W.Rect&&u.setProps(o)}}addFloatDomToPosition(t,e){const n=C.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=n,{initPosition:s,componentKey:l,data:g,allowTransform:u=!0}=t,d=e!=null?e:c.generateRandomId(),m=this._getPosition(s,o);if(m==null)return;const h={unitId:o,subUnitId:a,drawingId:d,drawingType:t.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:m,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Re.id,{unitId:o,drawings:[h]}),this._add$.next({unitId:o,subUnitId:a,id:d}),{id:d,dispose:()=>{this._removeDom(d,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:o,subUnitId:a}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(n.rect),e){const l=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:t});if(!l)return;const g=this._sheetDrawingService.getBatchRemoveOp([l]),{redo:u,objects:d}=g;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:u,objects:d,type:p.DrawingApplyType.REMOVE})}}addFloatDomToRange(t,e,n,o){var I,A,R;const a=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:l}=a,g=this._getSceneAndTransformerByDrawingSearch(s);if(!g)return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(I=this._renderManagerService.getRenderById(s))==null?void 0:I.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:m,data:h,allowTransform:f=!0}=e,S=o!=null?o:c.generateRandomId(),{position:w,position$:v}=this._createRangePositionObserver(t,u,d.skeleton);if(this._getPosition(w,s)==null)return;const D=g.scene,{scaleX:b}=D.getAncestorScale(),y=ze(w,n,b),M={unitId:s,subUnitId:l,drawingId:S,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:y.startX,top:y.startY,width:y.width,height:y.height},data:h,allowTransform:f};{const{unitId:U,subUnitId:j,drawingId:P}=M,T=C.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:j}),L=M,F=this._univerInstanceService.getUnit(U,c.UniverInstanceType.UNIVER_SHEET);if(!F)return;const J=F.getActiveSheet().getSheetId();if(!L||!T)return;const ne=(A=this._renderManagerService.getRenderById(U))==null?void 0:A.with(E.SheetSkeletonManagerService);if(!ne)return;const K=ne.getWorksheetSkeleton(j);if(!K)return;const{transform:z,drawingType:re,data:x}=L;if(re!==c.DrawingTypeEnum.DRAWING_DOM&&re!==c.DrawingTypeEnum.DRAWING_CHART)return;const Y=this._getSceneAndTransformerByDrawingSearch(U);if(Y==null)return;const{scene:ye,canvas:Ce}=Y;if(z==null||J!==j)return;const{left:Qe,top:et,width:tt,height:nt,angle:yt,flipX:Ct,flipY:rt,skewX:it,skewY:De}=z,ot=k.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:j,drawingId:P}),se=ye.getObject(ot);if(se!=null){se.transformByState({left:Qe,top:et,width:tt,height:nt,angle:yt,flipX:Ct,flipY:rt,skewX:it,skewY:De});return}const ie={left:Qe,top:et,width:tt,height:nt,zIndex:this._drawingManagerService.getDrawingOrder(U,j).length-1},Te=re===c.DrawingTypeEnum.DRAWING_CHART;if(Te){const $=x?x.backgroundColor:"white";ie.fill=$,ie.rotateEnabled=!1,x&&x.border&&(ie.stroke=x.border),ie.paintFirst="stroke",ie.strokeWidth=1,ie.borderEnabled=!1,ie.radius=8}const ce=new W.Rect(ot,ie);Te&&ce.setObjectType(W.ObjectType.CHART),ye.addObject(ce,W.DRAWING_OBJECT_LAYER_INDEX),L.allowTransform!==!1&&ye.attachTransformerTo(ce);const de=new c.DisposableCollection,at=ye.getMainViewport(),{rowHeaderWidth:Me,columnHeaderHeight:je}=K.skeleton,st={top:je,left:Me,bottom:at.bottom,right:at.right},le={dispose:de,rect:ce,boundsOfViewArea:st,domAnchor:n,unitId:U,subUnitId:j},V=ae(ce,Y.renderUnit.scene,K.skeleton,T.worksheet,le),be=new N.BehaviorSubject(V);le.position$=be;let We={position$:be,id:P,componentKey:L.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{Ce.dispatchEvent(new WheelEvent($.type,$))},data:x,unitId:U};e.eventPassThrough&&(We={...We,onPointerDown:$=>{Ce.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{Ce.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{Ce.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(We),this.disposeWithMe(v.subscribe($=>{var Wt,Bt,Lt,Yt;const jt=ze({startX:$.startX,startY:$.startY,endX:$.endX,endY:$.endY,width:(Wt=n.width)!=null?Wt:$.width,height:(Bt=n.height)!=null?Bt:$.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Kn=k.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:j,drawingId:P}),xn=new W.Rect(Kn,{left:jt.startX,top:jt.startY,width:(Lt=n.width)!=null?Lt:$.width,height:(Yt=n.height)!=null?Yt:$.height,zIndex:this._drawingManagerService.getDrawingOrder(U,j).length-1}),zn=ae(xn,Y.renderUnit.scene,K.skeleton,T.worksheet,le);be.next(zn)}));const Be=(R=this._renderManagerService.getRenderById(U))==null?void 0:R.with(E.SheetSkeletonManagerService);Be==null||Be.currentSkeleton$.subscribe($=>{$&&K.sheetId!==$.sheetId&&this._removeDom(S,!0)});const ct=ce.onTransformChange$.subscribeEvent(()=>{const $=ae(ce,Y.renderUnit.scene,K.skeleton,T.worksheet,le);be.next($)});de.add(()=>{this._canvasFloatDomService.removeFloatDom(P)}),ct&&de.add(ct),this._domLayerInfoMap.set(P,le)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(t,e,n,o){var y,M,I;const a=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:l}=a;if(!this._getSceneAndTransformerByDrawingSearch(s))return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(y=this._renderManagerService.getRenderById(s))==null?void 0:y.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:m,data:h,allowTransform:f=!0}=e,S=o!=null?o:c.generateRandomId(),{position:w,position$:v}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,d.skeleton),_=w;if(_.startY=0,this._getPosition(w,s)==null)return;const b={unitId:s,subUnitId:l,drawingId:S,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:_.startX,top:_.startY,width:_.width,height:_.height},data:h,allowTransform:f};{const{unitId:A,subUnitId:R,drawingId:U}=b,j=C.getSheetCommandTarget(this._univerInstanceService,{unitId:A,subUnitId:R}),P=b,T=this._univerInstanceService.getUnit(A,c.UniverInstanceType.UNIVER_SHEET);if(!T)return;const L=T.getActiveSheet().getSheetId();if(!P||!j)return;const F=(M=this._renderManagerService.getRenderById(A))==null?void 0:M.with(E.SheetSkeletonManagerService);if(!F)return;const J=F.getWorksheetSkeleton(R);if(!J)return;const{transform:ne,data:K}=P,z=this._getSceneAndTransformerByDrawingSearch(A);if(z==null)return;const{scene:re,canvas:x}=z;if(ne==null||L!==R)return;const{left:Y,top:ye,width:Ce,height:Qe,angle:et,flipX:tt,flipY:nt,skewX:yt,skewY:Ct}=ne,rt=k.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:R,drawingId:U}),it=re.getObject(rt);if(it!=null){it.transformByState({left:Y,top:ye,width:Ce,height:Qe,angle:et,flipX:tt,flipY:nt,skewX:yt,skewY:Ct});return}const De=ze({startX:_.startX,startY:0,endX:w.endX,endY:w.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),ot={left:De.startX,top:De.startY,width:De.width,height:De.height,zIndex:this._drawingManagerService.getDrawingOrder(A,R).length-1},se=new W.Rect(rt,ot);re.addObject(se,W.DRAWING_OBJECT_LAYER_INDEX),P.allowTransform!==!1&&re.attachTransformerTo(se);const ie=new c.DisposableCollection,Te=re.getMainViewport(),ce={top:0,left:Te.left,bottom:Te.bottom,right:Te.right},de={dispose:ie,rect:se,unitId:A,subUnitId:R,boundsOfViewArea:ce,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},at=ae(se,z.renderUnit.scene,J.skeleton,j.worksheet,de),Me=new N.BehaviorSubject(at);de.position$=Me;let je={position$:Me,id:U,componentKey:P.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:V=>{x.dispatchEvent(new WheelEvent(V.type,V))},data:K,unitId:A};e.eventPassThrough&&(je={...je,onPointerDown:V=>{x.dispatchEvent(new PointerEvent(V.type,V))},onPointerMove:V=>{x.dispatchEvent(new PointerEvent(V.type,V))},onPointerUp:V=>{x.dispatchEvent(new PointerEvent(V.type,V))}}),this._canvasFloatDomService.addFloatDom(je);const st=se.onTransformChange$.subscribeEvent(()=>{const V=ae(se,z.renderUnit.scene,J.skeleton,j.worksheet,de);Me.next(V)});this.disposeWithMe(v.subscribe(V=>{const be=ze({startX:V.startX,startY:0,endX:V.endX,endY:V.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),We=k.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:R,drawingId:U}),Be=new W.Rect(We,{left:be.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(A,R).length-1}),ct=ae(Be,z.renderUnit.scene,J.skeleton,j.worksheet,de);Me.next(ct)}));const le=(I=this._renderManagerService.getRenderById(A))==null?void 0:I.with(E.SheetSkeletonManagerService);le==null||le.currentSkeleton$.subscribe(V=>{V&&d.sheetId!==V.sheetId&&this._removeDom(S,!0)}),ie.add(()=>{this._canvasFloatDomService.removeFloatDom(U)}),st&&ie.add(st),this._domLayerInfoMap.set(U,de)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:o,startColumn:a}=t;const s=Ne(o,a,n),l=new N.BehaviorSubject(s),g=Ne(t.endRow,t.endColumn,n),u=new N.BehaviorSubject(g),d=()=>{const v=Ne(o,a,n),_=Ne(t.endRow,t.endColumn,n);l.next(v),u.next(_)},m=new c.DisposableCollection;m.add(e.engine.clientRect$.subscribe(()=>d())),m.add(this._commandService.onCommandExecuted(v=>{if(v.id===C.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(D=>D.row===o)>-1){d();return}(C.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(v.id)>-1||v.id===E.SetScrollOperation.id||v.id===E.SetZoomRatioOperation.id)&&d()}));const h=(v,_)=>{o=v,a=_,d()},f=()=>({rotate:0,width:g.right-s.left,height:g.bottom-s.top,absolute:{left:!0,top:!0},startX:s.left,startY:s.top,endX:g.right,endY:g.bottom}),S=l.pipe(N.map(v=>{const _=Ne(t.endRow,t.endColumn,n);return{rotate:0,width:_.right-v.left,height:_.bottom-v.top,absolute:{left:!0,top:!0},startX:v.left,startY:v.top,endX:_.right,endY:_.bottom}})),w=f();return{position$:S,position:w,updateRowCol:h,topLeftPos$:l,rightBottomPos$:u,disposable:m}}},O.SheetCanvasFloatDomManagerService=fn([fe(0,c.Inject(W.IRenderManagerService)),fe(1,c.IUniverInstanceService),fe(2,c.Inject(c.ICommandService)),fe(3,k.IDrawingManagerService),fe(4,c.Inject(B.CanvasFloatDomService)),fe(5,p.ISheetDrawingService),fe(6,c.Inject(c.LifecycleService))],O.SheetCanvasFloatDomManagerService);function Ne(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 ze(i,r,t){var g,u;t=t!=null?t:1;const e=i.endX-i.startX,n=i.endY-i.startY,o=(g=r==null?void 0:r.width)!=null?g:e,a=(u=r==null?void 0:r.height)!=null?u:n;let s=0,l=0;if(r){if(r.horizonOffsetAlign==="right"){const d=Ze(r.marginX,e*t);s=i.endX-d-o}else s=i.startX+Ze(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const d=Ze(r.marginY,n*t);l=i.endY-d-a}else l=i.startY+Ze(r.marginY,n)}return{rotate:0,startX:s,startY:l,endX:i.endX,endY:i.endY,width:o,height:a,absolute:{left:i.absolute.left,top:i.absolute.top}}}function Ze(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const t=Number.parseFloat(i);return r*t/100}const Sn=i=>{const{floatDomInfos:r,scene:t,skeleton:e,worksheet:n}=i,o=Q.useMemo(()=>r.map(a=>{const{width:s,height:l,angle:g,left:u,top:d}=a.transform,m=Ot({left:u!=null?u:0,right:(u!=null?u:0)+(s!=null?s:0),top:d!=null?d:0,bottom:(d!=null?d:0)+(l!=null?l:0)},t,e,n,void 0,!0),{scaleX:h,scaleY:f}=t.getAncestorScale(),S={startX:m.left,endX:m.right,startY:m.top,endY:m.bottom,rotate:g,width:s*h,height:l*f,absolute:m.absolute},w={position$:new N.BehaviorSubject(S),position:S,id:a.drawingId,componentKey:a.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:a.unitId};return[a.drawingId,w]}),[r,t,e,n]);return X.jsx("div",{style:{position:"absolute",top:0,left:0},children:o.map(([a,s])=>X.jsx(B.PrintFloatDomSingle,{layer:s,id:a,position:s.position},a))})};var wn=Object.getOwnPropertyDescriptor,vn=(i,r,t,e)=>{for(var n=e>1?void 0:e?wn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Se=(i,r)=>(t,e)=>r(t,e,i);let qe=class extends c.Disposable{constructor(i,r,t,e,n,o,a){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._canvasFloatDomManagerService=n,this._componetManager=o,this._injector=a,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,t)=>{const{unitId:e,scene:n,subUnitId:o}=r,a=this._drawingManagerService.getDrawingDataForUnit(e),s=a==null?void 0:a[o];return s&&s.order.forEach(l=>{const g=s.data[l];g.drawingType!==c.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==c.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,o=this._renderManagerService.getRenderById(e);if(!o)return t(i);const a=o.with(E.SheetSkeletonManagerService).getSkeletonParam(n);if(!a)return t(i);const s=this._drawingManagerService.getDrawingDataForUnit(e),l=s==null?void 0:s[r.subUnitId];if(!l)return t(i);const{scaleX:g,scaleY:u}=o.scene,d=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=l.order.map(h=>l.data[h]);return m.length?(m.forEach(h=>{if(!h.groupId&&h.transform&&c.Tools.isDefine(h.transform.left)&&c.Tools.isDefine(h.transform.top)&&c.Tools.isDefine(h.transform.width)&&c.Tools.isDefine(h.transform.height)){const f=a.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});f.column<d.startColumn&&(d.startColumn=f.column),f.row<d.startRow&&(d.startRow=f.row),d.endRow<S.row&&(d.endRow=S.row),d.endColumn<S.column&&(d.endColumn=S.column)}}),t(d)):t(i)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,o=this._drawingManagerService.getDrawingDataForUnit(e),a=o==null?void 0:o[n];if(a){const s=a.order.map(g=>{const u=a.data[g];return u.drawingType===c.DrawingTypeEnum.DRAWING_CHART?{...u,componentKey:this._componetManager.get(c.PRINT_CHART_COMPONENT_KEY)}:u.drawingType===c.DrawingTypeEnum.DRAWING_DOM?{...u,componentKey:this._componetManager.get(u.componentKey)}:null}).filter(Boolean),l=B.connectInjector(Sn,this._injector);return Z.render(X.jsx(l,{floatDomInfos:s,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),i==null||i.add(()=>{Z.unmount(r.root)}),t(i)}}}))}};qe=vn([Se(0,c.Inject(E.SheetPrintInterceptorService)),Se(1,c.Inject(ue.DrawingRenderService)),Se(2,k.IDrawingManagerService),Se(3,W.IRenderManagerService),Se(4,c.Inject(O.SheetCanvasFloatDomManagerService)),Se(5,c.Inject(B.ComponentManager)),Se(6,c.Inject(c.Injector))],qe);var _n=Object.getOwnPropertyDescriptor,In=(i,r,t,e)=>{for(var n=e>1?void 0:e?_n(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},he=(i,r)=>(t,e)=>r(t,e,i);const yn=[C.InsertRowCommand.id,C.InsertColCommand.id,C.RemoveRowCommand.id,C.RemoveColCommand.id,C.DeleteRangeMoveLeftCommand.id,C.DeleteRangeMoveUpCommand.id,C.InsertRangeMoveDownCommand.id,C.InsertRangeMoveRightCommand.id,C.DeltaRowHeightCommand.id,C.SetRowHeightCommand.id,C.DeltaColumnWidthCommand.id,C.SetColWidthCommand.id,C.SetRowHiddenCommand.id,C.SetSpecificRowsVisibleCommand.id,C.SetSpecificColsVisibleCommand.id,C.SetColHiddenCommand.id,C.MoveColsCommand.id,C.MoveRowsCommand.id,C.MoveRangeCommand.id],Cn=[C.SetRowVisibleMutation.id,C.SetRowHiddenMutation.id,C.SetColVisibleMutation.id,C.SetColHiddenMutation.id,C.SetWorksheetRowHeightMutation.id,C.SetWorksheetColWidthMutation.id];let wt=class extends c.Disposable{constructor(i,r,t,e,n,o,a,s,l){super(),this._context=i,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._univerInstanceService=l,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===C.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([C.MoveColsCommand.id,C.MoveRowsCommand.id,C.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===C.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===C.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===C.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===C.DeleteRangeMoveLeftCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,0)}else if(r===C.DeleteRangeMoveUpCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,1)}else if(r===C.InsertRangeMoveDownCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,2)}else if(r===C.InsertRangeMoveRightCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,3)}else if(r===C.SetRowHiddenCommand.id||r===C.SetSpecificRowsVisibleCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForRowVisible(e,n,o)}else if(r===C.SetSpecificColsVisibleCommand.id||r===C.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForColVisible(e,n,o)}else if(r===C.DeltaRowHeightCommand.id||r===C.SetRowHeightCommand.id||r===C.DeltaColumnWidthCommand.id||r===C.SetColWidthCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t,a=r===C.DeltaRowHeightCommand.id||r===C.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const t=C.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(e,n),l=[],g=[];if(Object.keys(s).forEach(u=>{const d=s[u],{updateDrawings:m,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,d);l.push(...m),g.push(...h)}),l.length===0&&g.length===0)return{redos:[],undos:[]};if(l.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(l),{undo:d,redo:m,objects:h}=u;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:m,objects:h,type:p.DrawingApplyType.UPDATE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:d,objects:h,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),d=u.undo,m=u.redo,h=u.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:m,objects:h,type:p.DrawingApplyType.REMOVE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:d,objects:h,type:p.DrawingApplyType.INSERT}})}return o.push({id:G.id,params:[e]}),a.push({id:G.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,r,t){const e=[],n=[],{sheetTransform:o,anchorType:a=p.SheetDrawingAnchorType.Position,transform:s,unitId:l,subUnitId:g,drawingId:u}=t,{from:d,to:m}=o,{row:h,column:f}=d,{row:S,column:w}=m;if(o==null||s==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:v,endRow:_,startColumn:D,endColumn:b}=i;let y=null,M=null;if(r===0&&h>=v&&S<=_)if(f>=D&&w<=b)n.push({unitId:l,subUnitId:g,drawingId:u});else{const I=this._shrinkCol(o,s,D,b,a);y=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}else if(r===1&&f>=D&&w<=b)if(h>=v&&S<=_)n.push({unitId:l,subUnitId:g,drawingId:u});else{const I=this._shrinkRow(o,s,v,_,a);y=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}else if(r===2){const I=this._expandRow(o,s,v,_,a);y=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}else if(r===3){const I=this._expandCol(o,s,D,b,a);y=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}if(y!=null&&M!=null){const I=q(y,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:y,transform:I})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(i,r,t){const e=H({...i},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:m,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=d;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:w}=m,{row:v,column:_}=S,{row:D,column:b}=w;for(let y=0;y<t.length;y++){const M=t[y],{startRow:I,endRow:A,startColumn:R,endColumn:U}=M;if(b<R)continue;if(f===p.SheetDrawingAnchorType.Position){let T=null,L=null;if(_>=R&&_<=U){const F=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:U,startRow:S.row,endRow:w.row});if(F==null)return;L={...h,left:F.startX}}if(L!=null&&(T=H(L,this._selectionRenderService),T!=null&&L!=null)){n.push({...d,sheetTransform:T,transform:L});break}this._remainDrawingSize(h,n,d);continue}if(_>=R&&b<=U)continue;let j=null,P=null;if(_>=R&&_<=U){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:U,startRow:S.row,endRow:w.row});if(T==null)return;P={...h,left:(T==null?void 0:T.startX)||0,width:((h==null?void 0:h.width)||0)-T.endX+T.startX}}else if(b>=R&&b<=U){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:R,endColumn:b,startRow:S.row,endRow:w.row});if(T==null)return;P={...h,left:T.startX-((h==null?void 0:h.width)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:R,endColumn:U,startRow:S.row,endRow:w.row});if(T==null)return;if(P={...h,width:((h==null?void 0:h.width)||0)-T.endX+T.startX},j=H(P,this._selectionRenderService),j!=null&&P!=null){o.push({...d,sheetTransform:j,transform:P});break}}if(P!=null&&(j=H(P,this._selectionRenderService)),P!=null&&j!=null){n.push({...d,sheetTransform:j,transform:P});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),l=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),g.push(...d)}return{redos:a,undos:s,preRedos:l,preUndos:g}}_createUndoAndRedoMutation(i,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:o,objects:a}=e,s=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],l=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:a,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:s,undos:l}}_getDrawingUndoForRowVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:m,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=d;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:w}=m,{row:v,column:_}=S,{row:D,column:b}=w;for(let y=0;y<t.length;y++){const M=t[y],{startRow:I,endRow:A,startColumn:R,endColumn:U}=M;if(D<I)continue;if(f===p.SheetDrawingAnchorType.Position){let T=null,L=null;if(v>=I&&v<=A){const F=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:A});if(F==null)return;L={...h,top:F.startY}}if(L!=null&&(T=H(L,this._selectionRenderService),T!=null&&L!=null)){n.push({...d,sheetTransform:T,transform:L});break}this._remainDrawingSize(h,n,d);continue}if(v>=I&&D<=A)continue;let j=null,P=null;if(v>=I&&v<=A){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:A});if(T==null)return;P={...h,top:(T==null?void 0:T.startY)||0,height:((h==null?void 0:h.height)||0)-T.endY+T.startY}}else if(D>=I&&D<=A){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:D});if(T==null)return;P={...h,top:T.startY-((h==null?void 0:h.height)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:A});if(T==null)return;if(P={...h,height:((h==null?void 0:h.height)||0)-T.endY+T.startY},j=H(P,this._selectionRenderService),j!=null&&P!=null){o.push({...d,sheetTransform:j,transform:P});break}}if(P!=null&&(j=H(P,this._selectionRenderService)),P!=null&&j!=null){n.push({...d,sheetTransform:j,transform:P});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),l=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),g.push(...d)}return{redos:a,undos:s,preRedos:l,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,t,e){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(a=>{const s=n[a],{sheetTransform:l,transform:g,anchorType:u=p.SheetDrawingAnchorType.Position}=s;if(u===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,o,s);else{const{from:d,to:m}=l,{row:h,column:f}=d,{row:S,column:w}=m;for(let v=0;v<t.length;v++){const _=t[v],{startRow:D,endRow:b,startColumn:y,endColumn:M}=_;if(S<D||w<y)continue;if(u===p.SheetDrawingAnchorType.Position&&(h<=D&&S>=b||f<=y&&w>=M)){this._remainDrawingSize(g,o,s);continue}const I=q({...l},this._selectionRenderService,this._skeletonManagerService);if(I!=null){o.push({...s,transform:I});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let t,e;if(r==="insert")t=i.unitId,e=i.subUnitId;else{const n=C.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(i){var D,b;const{toRange:r,fromRange:t}=i,e=C.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=e,a=(b=(D=this._renderManagerService.getRenderById(n))==null?void 0:D.with(E.SheetSkeletonManagerService))==null?void 0:b.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=E.attachRangeWithCoord(a,t);if(!s)return{redos:[],undos:[]};const{startX:l,endX:g,startY:u,endY:d}=s,m=this._sheetDrawingService.getDrawingData(n,o),h=[];Object.keys(m).forEach(y=>{const M=m[y];if(M.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:I}=M;if(!I)return;const{left:A=0,top:R=0,width:U=0,height:j=0}=I,{drawingStartX:P,drawingEndX:T,drawingStartY:L,drawingEndY:F}={drawingStartX:A,drawingEndX:A+U,drawingStartY:R,drawingEndY:R+j};l<=P&&T<=g&&u<=L&&F<=d&&h.push(M)});const f=[],S=[],w=r.startRow-t.startRow,v=r.startColumn-t.startColumn,_=h.map(y=>{const M=y.sheetTransform,I={to:{...M.to,row:M.to.row+w,column:M.to.column+v},from:{...M.from,row:M.from.row+w,column:M.from.column+v}},A=q(I,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:y.drawingId,transform:A,sheetTransform:I}});if(_.length){const y=this._sheetDrawingService.getBatchUpdateOp(_),{undo:M,redo:I,objects:A}=y;f.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:I,objects:A,type:p.DrawingApplyType.UPDATE}}),S.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:M,objects:A,type:p.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,a=o.startRow,s=o.endRow,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],m=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:v=p.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let _,D;if(r==="insert"){const y=this._expandRow(S,w,a,s,v);_=y==null?void 0:y.newSheetTransform,D=y==null?void 0:y.newTransform}else{const{from:y,to:M}=S,{row:I}=y,{row:A}=M;if(v===p.SheetDrawingAnchorType.Both&&I>=a&&A<=s)m.push({unitId:e,subUnitId:n,drawingId:h});else{const R=this._shrinkRow(S,w,a,s,v);_=R==null?void 0:R.newSheetTransform,D=R==null?void 0:R.newTransform}}if(!_||!D)return;const b={unitId:e,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};d.push(b)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:f,redo:S,objects:w}=h;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.UPDATE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),f=h.undo,S=h.redo,w=h.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.REMOVE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:l,undos:g}}_moveColInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,a=o.startColumn,s=o.endColumn,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],m=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:v=p.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let _,D;if(r==="insert"){const y=this._expandCol(S,w,a,s,v);_=y==null?void 0:y.newSheetTransform,D=y==null?void 0:y.newTransform}else{const{from:y,to:M}=S,{column:I}=y,{column:A}=M;if(v===p.SheetDrawingAnchorType.Both&&I>=a&&A<=s)m.push({unitId:e,subUnitId:n,drawingId:h});else{const R=this._shrinkCol(S,w,a,s,v);_=R==null?void 0:R.newSheetTransform,D=R==null?void 0:R.newTransform}}if(!_||!D)return;const b={unitId:e,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};d.push(b)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:f,redo:S,objects:w}=h;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.UPDATE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),f=h.undo,S=h.redo,w=h.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.REMOVE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:l,undos:g}}_expandCol(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{column:l}=a,{column:g}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>=t){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:a.row,endRow:s.row});if(m==null)return;d={...r,left:(r.left||0)+m.endX-m.startX},u=H(d,this._selectionRenderService)}else if(g>=e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:g+o}},d=q(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkCol(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{column:l}=a,{column:g}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>e)u={from:{...a,column:l-o},to:{...s,column:g-o}},d=q(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&g<=e)return null;if(l<t&&g>e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:g-o}},d=q(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)d={...r,left:(r.left||0)-i.from.columnOffset};else{const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:l-1,startRow:a.row,endRow:s.row});if(m==null)return;d={...r,left:(r.left||0)-m.endX+m.startX-i.from.columnOffset}}u=H(d,this._selectionRenderService)}else if(g>=t&&g<=e&&n===p.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:a.row,endRow:s.row});if(m==null)return;u={from:{...a},to:{...s,column:t-1,columnOffset:m.endX-m.startX}},d=q(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_expandRow(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{row:l}=a,{row:g}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>=t){const m=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:a.column,endColumn:s.column});if(m==null)return;d={...r,top:(r.top||0)+m.endY-m.startY},u=H(d,this._selectionRenderService)}else if(g>=e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:g+o}},d=q(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkRow(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{row:l}=a,{row:g}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>e)u={from:{...a,row:l-o},to:{...s,row:g-o}},d=q(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&g<=e)return null;if(l<t&&g>e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:g-o}},d=q(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)d={...r,top:(r.top||0)-i.from.rowOffset};else{const m=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:l-1,startColumn:a.column,endColumn:s.column});if(m==null)return;d={...r,top:(r.top||0)-m.endY+m.startY-i.from.rowOffset}}u=H(d,this._selectionRenderService)}else if(g>=t&&g<=e&&n===p.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:t-1,endRow:t-1});if(m==null)return;u={from:{...a},to:{...s,row:t-1,rowOffset:m.endY-m.startY}},d=q(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===C.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:t}=i.params;this._updateDrawings(r,t)}})),this.disposeWithMe(this._context.activated$.subscribe(i=>{const{unit:r,unitId:t}=this._context;if(i){const e=r.getActiveSheet().getSheetId();this._updateDrawings(t,e)}else this._clearDrawings(t)}))}_clearDrawings(i){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,t=[];Object.keys(r).forEach(e=>{const n=r[e];n!=null&&Object.keys(n).forEach(o=>{const a=n[o].data;a!=null&&Object.keys(a).forEach(s=>{e===i&&t.push(a[s])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(i,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(o=>{const a=t[o];a!=null&&Object.keys(a).forEach(s=>{const l=a[s].data;l!=null&&Object.keys(l).forEach(g=>{if(o===i&&s===r){const u=l[g];u.transform=q(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(l[g])}else n.push(l[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{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(o=>{const a=e[o],{sheetTransform:s,transform:l,anchorType:g=p.SheetDrawingAnchorType.Position}=a;if(g===p.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=s,{row:m,column:h}=u,{row:f,column:S}=d;for(let w=0;w<t.length;w++){const v=t[w],{startRow:_,endRow:D,startColumn:b,endColumn:y}=v;if(c.Rectangle.intersects({startRow:_,endRow:D,startColumn:b,endColumn:y},{startRow:m,endRow:f,startColumn:h,endColumn:S})||m>D||h>y){const M=g===p.SheetDrawingAnchorType.Position,I=q(s,this._selectionRenderService,this._skeletonManagerService);n.push({...a,transform:{...I,width:M?l==null?void 0:l.width:I==null?void 0:I.width,height:M?l==null?void 0:l.height:I==null?void 0:I.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[i]))}};wt=In([he(1,W.IRenderManagerService),he(2,c.ICommandService),he(3,E.ISheetSelectionRenderService),he(4,c.Inject(E.SheetSkeletonManagerService)),he(5,c.Inject(C.SheetInterceptorService)),he(6,p.ISheetDrawingService),he(7,k.IDrawingManagerService),he(8,c.IUniverInstanceService)],wt);var te=function(){return te=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},te.apply(this,arguments)},Dn=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=Q.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,o=i.extend,a=Dn(i,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),l=Q.useRef("_".concat(bn()));return At(t,"".concat(e),{defIds:t.defIds,idSuffix:l.current},te({ref:r,className:s},a),o)});function At(i,r,t,e,n){return Q.createElement(i.tag,te(te({key:r},Tn(i,t,n)),e),(Mn(i,t).children||[]).map(function(o,a){return At(o,"".concat(r,"-").concat(i.tag,"-").concat(a),t,void 0,n)}))}function Tn(i,r,t){var e=te({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1),i.tag==="mask"&&e.id&&(e.id=e.id+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];a==="mask"&&typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))});var n=r.defIds;return!n||n.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Mn(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)?te(te({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?te(te({},n),{attrs:te(te({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function bn(){return Math.random().toString(36).substring(2,8)}Pt.displayName="UniverIcon";var Rn={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"}}]},Ut=Q.forwardRef(function(i,r){return Q.createElement(Pt,Object.assign({},i,{id:"add-image-single",ref:r,icon:Rn}))});Ut.displayName="AddImageSingle";const vt={id:"sheet.command.delete-drawing",type:c.CommandType.COMMAND,handler:i=>{const r=i.get(c.ICommandService),e=i.get(p.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,o=e.map(a=>{const{unitId:s,subUnitId:l,drawingId:g,drawingType:u}=a;return{unitId:s,subUnitId:l,drawingId:g,drawingType:u}});return r.executeCommand(we.id,{unitId:n,drawings:o})}},_e={id:"sheet.command.move-drawing",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(p.ISheetDrawingService),n=i.get(E.ISheetSelectionRenderService),{direction:o}=r,a=e.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,l=a.map(u=>{const{transform:d}=u;if(d==null)return null;const m={...d},{left:h=0,top:f=0}=d;return o===c.Direction.UP?m.top=f-1:o===c.Direction.DOWN?m.top=f+1:o===c.Direction.LEFT?m.left=h-1:o===c.Direction.RIGHT&&(m.left=h+1),{...u,transform:m,sheetTransform:H(m,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(Ee.id,{unitId:s,drawings:l})?(t.syncExecuteCommand(G.id,[s]),!0):!1}},Nt="addition-and-subtraction-single",_t="sheet.menu.image";function En(i){return{id:_t,type:B.MenuItemType.SUBITEMS,icon:Nt,tooltip:"sheetImage.title",hidden$:B.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(i,{workbookTypes:[C.WorkbookEditablePermission],worksheetTypes:[C.WorksheetEditPermission],rangeTypes:[C.RangeProtectionPermissionEditPoint]})}}function On(i){return{id:Pe.id,title:"sheetImage.upload.float",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET)}}function Pn(i){return{id:St.id,title:"sheetImage.upload.cell",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET)}}const me={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelColumn:"univer-image-common-panel-column"},An=i=>{var D;const r=B.useDependency(c.ICommandService),t=B.useDependency(c.LocaleService),e=B.useDependency(k.IDrawingManagerService),n=B.useDependency(W.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:s}=a,l=n.getRenderById(s),g=l==null?void 0:l.scene;if(g==null)return;const u=g.getTransformerByCreate(),[d,m]=Q.useState(!0),h=(D=a.anchorType)!=null?D:p.SheetDrawingAnchorType.Position,[f,S]=Q.useState(h);function w(b,y){const M=[];return b.forEach(I=>{const{oKey:A}=I,R=y.getDrawingOKey(A);if(R==null)return M.push(null),!0;const{unitId:U,subUnitId:j,drawingId:P,drawingType:T,anchorType:L,sheetTransform:F}=R;M.push({unitId:U,subUnitId:j,drawingId:P,anchorType:L,sheetTransform:F,drawingType:T})}),M}Q.useEffect(()=>{const b=u.clearControl$.subscribe(M=>{M===!0&&m(!1)}),y=u.changeStart$.subscribe(M=>{var R;const{objects:I}=M,A=w(I,e);if(A.length===0)m(!1);else if(A.length>=1){m(!0);const U=((R=A[0])==null?void 0:R.anchorType)||p.SheetDrawingAnchorType.Position;S(U)}});return()=>{y.unsubscribe(),b.unsubscribe()}},[]);function v(b){S(b);const y=e.getFocusDrawings();if(y.length===0)return;const M=y.map(I=>({unitId:I.unitId,subUnitId:I.subUnitId,drawingId:I.drawingId,anchorType:b}));r.executeCommand(Ee.id,{unitId:y[0].unitId,drawings:M})}const _=b=>b?"block":"none";return X.jsxs("div",{className:Z.clsx(me.imageCommonPanelGrid,me.imageCommonPanelBorder),style:{display:_(d)},children:[X.jsx("div",{className:me.imageCommonPanelRow,children:X.jsx("div",{className:Z.clsx(me.imageCommonPanelColumn,me.imageCommonPanelTitle),children:X.jsx("div",{children:t.t("drawing-anchor.title")})})}),X.jsx("div",{className:Z.clsx(me.imageCommonPanelRow),children:X.jsx("div",{className:Z.clsx(me.imageCommonPanelColumn),children:X.jsxs(Z.RadioGroup,{value:f,onChange:v,direction:"vertical",children:[X.jsx(Z.Radio,{value:p.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),X.jsx(Z.Radio,{value:p.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),X.jsx(Z.Radio,{value:p.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})})]})},Un=()=>{const i=B.useDependency(k.IDrawingManagerService),r=i.getFocusDrawings(),[t,e]=Q.useState(r);return Q.useEffect(()=>{const n=i.focus$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&X.jsxs("div",{className:me.imageCommonPanel,children:[X.jsx(ue.DrawingCommonPanel,{drawings:t}),X.jsx(An,{drawings:t})]})},Nn={[B.RibbonStartGroup.FORMULAS_INSERT]:{[_t]:{order:3,menuItemFactory:En,[Pe.id]:{order:0,menuItemFactory:On},[St.id]:{order:1,menuItemFactory:Pn}}}};function ke(i){return!i.getContextValue(c.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(c.EDITOR_ACTIVATED)&&!i.getContextValue(c.FOCUSING_PANEL_EDITOR)&&i.getContextValue(c.FOCUSING_COMMON_DRAWINGS)}const kn={id:_e.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:B.KeyCode.ARROW_DOWN,priority:100,preconditions:ke,staticParameters:{direction:c.Direction.DOWN}},jn={id:_e.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:B.KeyCode.ARROW_UP,priority:100,preconditions:ke,staticParameters:{direction:c.Direction.UP}},Wn={id:_e.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:B.KeyCode.ARROW_LEFT,priority:100,preconditions:ke,staticParameters:{direction:c.Direction.LEFT}},Bn={id:_e.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:B.KeyCode.ARROW_RIGHT,priority:100,preconditions:ke,staticParameters:{direction:c.Direction.RIGHT}},Ln={id:vt.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:ke,binding:B.KeyCode.DELETE,mac:B.KeyCode.BACKSPACE};var Yn=Object.getOwnPropertyDescriptor,$n=(i,r,t,e)=>{for(var n=e>1?void 0:e?Yn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ie=(i,r)=>(t,e)=>r(t,e,i);let Je=class extends c.Disposable{constructor(i,r,t,e,n,o){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Nt,Ut)),this.disposeWithMe(i.register(Tt,Un))}_initMenus(){this._menuManagerService.mergeMenu(Nn)}_initCommands(){[Pe,St,Re,we,Ee,dt,G,lt,ht,pt,_e,vt,mt].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[kn,jn,Wn,Bn,Ln].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Je=$n([Ie(0,c.Inject(B.ComponentManager)),Ie(1,B.IMenuManagerService),Ie(2,c.ICommandService),Ie(3,B.IShortcutService),Ie(4,k.IDrawingManagerService),Ie(5,c.Inject(C.SheetsSelectionsService))],Je);var Fn=Object.defineProperty,Gn=Object.getOwnPropertyDescriptor,Hn=(i,r,t)=>r in i?Fn(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,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},It=(i,r)=>(t,e)=>r(t,e,i),kt=(i,r,t)=>Hn(i,typeof r!="symbol"?r+"":r,t);const Xn="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends c.Plugin{constructor(r=Dt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:o,...a}=c.merge({},Dt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig($t,a)}onStarting(){c.registerDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService],[Je],[$e],[qe],[xe],[Ke],[He],[Ve],[Xe]]),c.touchDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService]])}onReady(){c.touchDependencies(this._injector,[[Ke],[Xe]])}onRendered(){this._registerRenderModules(),c.touchDependencies(this._injector,[[xe],[qe],[Je],[He],[Ve]])}onSteady(){this._injector.get($e)}_registerRenderModules(){[[O.SheetDrawingUpdateController],[wt],[gt],[ut]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(c.UniverInstanceType.UNIVER_SHEET,r))})}},kt(O.UniverSheetsDrawingUIPlugin,"type",c.UniverInstanceType.UNIVER_SHEET),kt(O.UniverSheetsDrawingUIPlugin,"pluginName",Xn),O.UniverSheetsDrawingUIPlugin=Vn([c.DependentOn(k.UniverDrawingPlugin,pe.UniverDocsDrawingPlugin,ue.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),It(1,c.Inject(c.Injector)),It(2,W.IRenderManagerService),It(3,c.IConfigService)],O.UniverSheetsDrawingUIPlugin),O.ClearSheetDrawingTransformerOperation=G,O.DeleteDrawingsCommand=vt,O.EditSheetDrawingOperation=lt,O.GroupSheetDrawingCommand=ht,O.InsertFloatImageCommand=Pe,O.InsertSheetDrawingCommand=Re,O.MoveDrawingsCommand=_e,O.RemoveSheetDrawingCommand=we,O.SHEETS_IMAGE_MENU_ID=_t,O.SetDrawingArrangeCommand=mt,O.SetSheetDrawingCommand=Ee,O.SidebarSheetDrawingOperation=dt,O.UngroupSheetDrawingCommand=pt,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
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:s,showOk:!0,showCancel:!0,onOk:()=>{s(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:s})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};Xe=an([Oe(0,c.ICommandService),Oe(1,c.IUniverInstanceService),Oe(2,B.IDialogService),Oe(3,W.IRenderManagerService),Oe(4,c.Inject(c.LocaleService))],Xe);const Pe={id:"sheet.command.insert-float-image",type:c.CommandType.COMMAND,handler:async(i,r)=>{var a,s;const t=i.get(c.IUniverInstanceService),e=i.get(W.IRenderManagerService),n=(a=W.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:a.with(O.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const l=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(l)).every(g=>g)}else return(s=n.insertFloatImage())!=null?s:!1}},St={id:"sheet.command.insert-cell-image",type:c.CommandType.COMMAND,handler:i=>{var e,n;const r=i.get(c.IUniverInstanceService),t=i.get(W.IRenderManagerService);return(n=(e=W.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,r,t))==null?void 0:e.with(O.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}};var cn=Object.getOwnPropertyDescriptor,dn=(i,r,t,e)=>{for(var n=e>1?void 0:e?cn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ae=(i,r)=>(t,e)=>r(t,e,i);const Rt="image/png";function ln(i){const r=i.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=t.charCodeAt(o);return new Blob([n],{type:Rt})}function un(i){const r=new ClipboardItem({[Rt]:ln(i)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function gn(){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 Et=[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 Ke=class extends c.Disposable{constructor(r,t,e,n,o){super();oe(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const o=this._focusedDrawings;if(o.length>0){const[a]=o;if(n===E.COPY_TYPE.CUT){const l={unitId:r,drawings:[a]};this._commandService.executeCommand(we.id,l)}setTimeout(()=>{const l=gn();a.drawingType===c.DrawingTypeEnum.DRAWING_IMAGE&&a.imageSourceType===k.ImageSourceType.BASE64?un(a.source):this._clipboardInterfaceService.writeText(""),l()},200);const s={unitId:a.unitId,subUnitId:a.subUnitId,drawings:[a]};this._copyInfo=s}else{const a=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=a}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=E.COPY_TYPE.COPY,pasteType:a}=n,{range:s}=r||{},{range:l,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:a,unitId:g,subUnitId:u,pasteRange:l},{copyRange:s,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:a},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:Pe.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var m;const n=(m=this._renderManagerService.getRenderById(r))==null?void 0:m.with(E.SheetSkeletonManagerService);if(!n)return;const o=n.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:s,startY:l,endY:g}=o,u=this._drawingService.getDrawingData(r,t),d=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const f=u[h],{transform:S}=f;if(f.anchorType!==p.SheetDrawingAnchorType.Both||!S)return;const{left:w=0,top:v=0,width:_=0,height:D=0}=S,{drawingStartX:b,drawingEndX:y,drawingStartY:M,drawingEndY:I}={drawingStartX:w,drawingEndX:w+_,drawingStartY:v,drawingEndY:v+D};a<=b&&y<=s&&l<=M&&I<=g&&d.push(f)}),d.length)return{copyRange:e,drawings:d,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Et.includes(e))return{redos:[],undos:[]};const{unitId:o,subUnitId:a,range:s}=n,l=this._renderManagerService.getRenderById(o),g=l==null?void 0:l.with(E.SheetSkeletonManagerService),u=l==null?void 0:l.with(E.ISheetSelectionRenderService),d=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:m}=d,h=E.discreteRangeToRange(s);return this._generateMutations(m,{unitId:o,subUnitId:a,isCut:t===E.COPY_TYPE.CUT,getTransform:(f,S)=>{var _;const w=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),v={...f,left:w==null?void 0:w.startX,top:w==null?void 0:w.startY};return{transform:v,sheetTransform:(_=H(v,u))!=null?_:S}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:o,isCut:a}=t,s=[],l=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:d,sheetTransform:m}=u;if(!d)return;const h=o(d,m),f={...u,unitId:e,subUnitId:n,drawingId:a?u.drawingId:c.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(a){const{undo:S,redo:w,objects:v}=g.getBatchUpdateOp([f]);s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:p.DrawingApplyType.UPDATE,op:w,objects:v}}),l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:p.DrawingApplyType.UPDATE,op:S,objects:v}})}else{const{undo:S,redo:w,objects:v}=g.getBatchAddOp([f]);s.push({id:p.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:v,type:p.DrawingApplyType.INSERT}}),l.push({id:p.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:n,objects:v,type:p.DrawingApplyType.REMOVE}})}}),{redos:s,undos:l}}_generateRangeDrawingsPasteMutations(r,t){var A;const{unitId:e,subUnitId:n,pasteType:o,pasteRange:a}=r,{copyRange:s,copyType:l}=t;if(Et.includes(o))return{redos:[],undos:[]};const g=(A=this._renderManagerService.getRenderById(e))==null?void 0:A.with(E.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!s)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:E.discreteRangeToRange(a)},pasteType:o},l);const{ranges:[d,m],mapFunc:h}=E.virtualizeDiscreteRanges([s,a]),{row:f,col:S}=h(d.startRow,d.startColumn),{row:w,col:v}=h(m.startRow,m.startColumn),_=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:S,endColumn:S}),D=g.attachRangeWithCoord({startRow:w,endRow:w,startColumn:v,endColumn:v});if(!_||!D||!this._copyInfo)return{redos:[],undos:[]};const b=D.startX-_.startX,y=D.startY-_.startY,M=w-f,I=v-S;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(R,U)=>{var j,P;return{transform:{...R,left:((j=R==null?void 0:R.left)!=null?j:0)+b,top:((P=R==null?void 0:R.top)!=null?P:0)+y},sheetTransform:{...U,to:{...U.to,row:U.to.row+M,column:U.to.column+I},from:{...U.from,row:U.from.row+M,column:U.from.column+I}}}},isCut:l===E.COPY_TYPE.CUT})}};Ke=dn([Ae(0,E.ISheetClipboardService),Ae(1,W.IRenderManagerService),Ae(2,k.IDrawingManagerService),Ae(3,B.IClipboardInterfaceService),Ae(4,c.ICommandService)],Ke);var hn=Object.getOwnPropertyDescriptor,mn=(i,r,t,e)=>{for(var n=e>1?void 0:e?hn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ue=(i,r)=>(t,e)=>r(t,e,i);let xe=class extends c.Disposable{constructor(i,r,t,e,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([i,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingVisible(!1);return}const a=e.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new C.WorkbookViewPermission(a).id,new C.WorksheetViewPermission(a,s).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,o)})):(this._drawingManagerService.setDrawingVisible(!1),N.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(i,r){this._drawingManagerService.setDrawingVisible(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),a=this._renderManagerService.getRenderById(t),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===W.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.removeObject(g)})}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([i,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingEditable(!1);return}const a=e.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new C.WorkbookEditablePermission(a).id,new C.WorksheetEditPermission(a,s).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,o)})):(this._drawingManagerService.setDrawingEditable(!1),N.EMPTY))).subscribe())}_handleDrawingEditableFalse(i,r){this._drawingManagerService.setDrawingEditable(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),a=this._renderManagerService.getRenderById(t),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===W.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.detachTransformerFrom(g)})}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=t.getUnitId(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),l=s==null?void 0:s.scene;if(!l)return N.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new C.WorkbookViewPermission(o).id,new C.WorksheetViewPermission(o,a).id]).pipe(N.map(d=>d.every(m=>m.value)),N.distinctUntilChanged()).pipe(N.map(d=>({permission:d,scene:l,transformer:g,unitId:o,subUnitId:a})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingVisible(t);const s=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(o,a),g=Object.values(l);t?this._drawingManagerService.addNotification(g):(s.forEach(u=>{u.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),o=e==null?void 0:e.getSheetId();if(!n||!o)return;const a=this._drawingManagerService.getDrawingData(n,o),s=Object.values(a);this._drawingManagerService.addNotification(s)}}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=t.getUnitId(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),l=s==null?void 0:s.scene;if(!l)return N.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new C.WorkbookEditablePermission(o).id,new C.WorksheetEditPermission(o,a).id]).pipe(N.map(d=>d.every(m=>m.value)),N.distinctUntilChanged()).pipe(N.map(d=>({permission:d,scene:l,transformer:g,unitId:o,subUnitId:a})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingEditable(t);const s=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(o,a),g=Object.values(l);t?(s.forEach(u=>{u.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(s.forEach(u=>{u.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const o=n.getSheetId(),a=this._renderManagerService.getRenderById(e),s=a==null?void 0:a.scene;if(!s)return;const l=this._drawingManagerService.getDrawingData(e,o),g=Object.values(l);this._drawingManagerService.setDrawingEditable(!0),s.getAllObjectsByOrder().forEach(d=>{d.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(m=>d.oKey.includes(m.drawingId))&&s.detachTransformerFrom(d)})}}))}};xe=mn([Ue(0,k.IDrawingManagerService),Ue(1,W.IRenderManagerService),Ue(2,c.IPermissionService),Ue(3,c.IUniverInstanceService),Ue(4,c.Inject(c.UserManagerService))],xe);var pn=Object.getOwnPropertyDescriptor,fn=(i,r,t,e)=>{for(var n=e>1?void 0:e?pn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},fe=(i,r)=>(t,e)=>r(t,e,i);function Ot(i,r,t,e,n,o=!1){const{scaleX:a,scaleY:s}=r.getAncestorScale(),l=r.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=e.getFreeze(),{startColumn:u,startRow:d,xSplit:m,ySplit:h}=g,f={left:!0,top:!0};if(!l)return{...i,absolute:f};const{left:S,right:w,top:v,bottom:_}=i;let{top:D,left:b,viewportScrollX:y,viewportScrollY:M}=l;const{boundsOfViewArea:I,scrollDirectionResponse:A}=n||{},{rowHeaderWidth:R,columnHeaderHeight:U}=t,j={top:o?0:U,left:o?0:R};I&&(c.Tools.isDefine(j.top)&&(j.top=I.top),c.Tools.isDefine(j.left)&&(j.left=I.left)),A==="HORIZONTAL"&&(M=0),A==="VERTICAL"&&(y=0);let P=0,T=0;const L=t.rowStartY(d-h)+U,F=t.colStartX(u-m)+R,J=t.rowStartY(d)+U,ne=t.colStartX(u)+R;if(m===0)f.left=!1,P=(S-y)*a,T=(w-y)*a;else{const x=S-(F-R),Y=w-(F-R);w<ne?(P=x*a,T=Y*a):S<=ne&&w>=ne?(P=x*a,T=Math.max(b,(w-y)*a)):S>ne&&(f.left=!1,P=Math.max((S-y)*a,b),T=Math.max((w-y)*a,b))}let K=0,z=0;if(h===0)f.top=!1,K=(v-M)*s,z=(_-M)*s;else{const x=v-(L-U),Y=_-(L-U);_<J?(K=x*s,z=Y*s):v<=J&&_>=J?(K=x*s,z=Math.max(D,(_-M)*s)):v>J&&(f.top=!1,K=Math.max((v-M)*s,D),z=Math.max((_-M)*s,D))}return P=Math.max(P,j.left),K=Math.max(K,j.top),T=Math.max(T,j.left),z=Math.max(z,j.top),{left:P,right:T,top:K,bottom:z,absolute:f}}const ae=(i,r,t,e,n)=>{const{left:o,top:a,width:s,height:l,angle:g}=i,u={left:o,right:o+s,top:a,bottom:a+l},d=Ot(u,r,t,e,n),{scaleX:m,scaleY:h}=r.getAncestorScale();return{startX:d.left,endX:d.right,startY:d.top,endY:d.bottom,rotate:g,width:s*m,height:l*h,absolute:d.absolute}};O.SheetCanvasFloatDomManagerService=class extends c.Disposable{constructor(t,e,n,o,a,s,l){super();oe(this,"_domLayerInfoMap",new Map);oe(this,"_transformChange$",new N.Subject);oe(this,"transformChange$",this._transformChange$.asObservable());oe(this,"_add$",new N.Subject);oe(this,"add$",this._add$.asObservable());oe(this,"_remove$",new N.Subject);oe(this,"remove$",this._remove$.asObservable());this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=s,this._lifecycleService=l,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(N.filter(t=>t===c.LifecycleStages.Rendered),N.take(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}getFloatDomsBySubUnitId(t,e){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===e&&n.unitId===t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const o=n.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:n,transformer:o,renderUnit:e,canvas:a}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var x;const{unitId:n,subUnitId:o,drawingId:a}=e,s=C.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),l=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,c.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!l||!s)return;const d=(x=this._renderManagerService.getRenderById(n))==null?void 0:x.with(E.SheetSkeletonManagerService).getSkeletonParam(o);if(!d)return;const{transform:m,drawingType:h,data:f}=l;if(h!==c.DrawingTypeEnum.DRAWING_DOM&&h!==c.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(n);if(S==null)return;const{scene:w,canvas:v}=S;if(m==null)return!0;if(u!==o)return;const{left:_,top:D,width:b,height:y,angle:M,flipX:I,flipY:A,skewX:R,skewY:U}=m,j=k.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),P=w.getObject(j);if(P!=null){P.transformByState({left:_,top:D,width:b,height:y,angle:M,flipX:I,flipY:A,skewX:R,skewY:U});return}const T={left:_,top:D,width:b,height:y,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},L=h===c.DrawingTypeEnum.DRAWING_CHART;if(T.rotateEnabled=!1,L){const Y=f?f.backgroundColor:"white";T.fill=Y,f&&f.border&&(T.stroke=f.border),T.paintFirst="stroke",T.strokeWidth=1,T.borderEnabled=!1,T.radius=8}const F=new W.Rect(j,T);L&&F.setObjectType(W.ObjectType.CHART),w.addObject(F,W.DRAWING_OBJECT_LAYER_INDEX),l.allowTransform!==!1&&w.attachTransformerTo(F);const J=new c.DisposableCollection,ne=ae(F,S.renderUnit.scene,d.skeleton,s.worksheet),K=new N.BehaviorSubject(ne),z={dispose:J,rect:F,position$:K,unitId:n,subUnitId:o,id:a};this._canvasFloatDomService.addFloatDom({position$:K,id:a,componentKey:l.componentKey,onPointerDown:Y=>{v.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{v.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{v.dispatchEvent(new PointerEvent(Y.type,Y))},onWheel:Y=>{v.dispatchEvent(new WheelEvent(Y.type,Y))},data:f,unitId:n});const re=F.onTransformChange$.subscribeEvent(()=>{const Y=ae(F,S.renderUnit.scene,d.skeleton,s.worksheet);K.next(Y)});J.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),re&&J.add(re),this._domLayerInfoMap.set(a,z)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{const{unitId:n,subUnitId:o,drawingId:a}=e,s=k.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),l=this._getSceneAndTransformerByDrawingSearch(n);if(l==null)return;const{transformer:g,scene:u}=l,d=u.getObject(s);d!=null&&d.oKey&&g.clearControlByIds([d==null?void 0:d.oKey])})}))}_scrollUpdateListener(){const t=(e,n)=>{var g;const o=this._getSceneAndTransformerByDrawingSearch(e),a=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),s=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),l=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(E.SheetSkeletonManagerService).getSkeletonParam(n);!o||!s||!l||a.forEach(u=>{const d=this._domLayerInfoMap.get(u);if(d){const m=ae(d.rect,o.renderUnit.scene,l.skeleton,s.worksheet,d);d.position$.next(m)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(e=>e?e.activeSheet$:N.of(null)),N.map(e=>{if(!e)return null;const n=e.getUnitId(),o=this._renderManagerService.getRenderById(n);return o?{render:o,unitId:n,subUnitId:e.getSheetId()}:null}),N.switchMap(e=>e?c.fromEventSubject(e.render.scene.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(N.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):N.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:o}=e;t(n,o)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===E.SetZoomRatioOperation.id){const n=e.params,{unitId:o}=n;Array.from(this._domLayerInfoMap.values()).filter(s=>s.unitId===o).map(s=>s.subUnitId).forEach(s=>{t(o,s)})}else if(e.id===C.SetFrozenMutation.id){const{unitId:n,subUnitId:o}=e.params;t(n,o)}}))}_getPosition(t,e){var h;const{startX:n,endX:o,startY:a,endY:s}=t,l=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(E.ISheetSelectionRenderService);if(l==null)return;const g=l.getCellWithCoordByOffset(n,a);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:a-g.startY},d=l.getCellWithCoordByOffset(o,s);if(d==null)return;const m={column:d.actualColumn,columnOffset:o-d.startX,row:d.actualRow,rowOffset:s-d.startY};return{from:u,to:m}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==c.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==c.DrawingTypeEnum.DRAWING_CHART)return;const o={...n.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,o){const a=this._domLayerInfoMap.get(n),s=this._getSceneAndTransformerByDrawingSearch(t);if(a&&s){const{scene:l}=s,g=k.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=l.getObject(g);u&&u instanceof W.Rect&&u.setProps(o)}}addFloatDomToPosition(t,e){const n=C.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=n,{initPosition:s,componentKey:l,data:g,allowTransform:u=!0}=t,d=e!=null?e:c.generateRandomId(),m=this._getPosition(s,o);if(m==null)return;const h={unitId:o,subUnitId:a,drawingId:d,drawingType:t.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:m,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Re.id,{unitId:o,drawings:[h]}),this._add$.next({unitId:o,subUnitId:a,id:d}),{id:d,dispose:()=>{this._removeDom(d,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:o,subUnitId:a}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(n.rect),e){const l=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:t});if(!l)return;const g=this._sheetDrawingService.getBatchRemoveOp([l]),{redo:u,objects:d}=g;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:u,objects:d,type:p.DrawingApplyType.REMOVE})}}addFloatDomToRange(t,e,n,o){var I,A,R;const a=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:l}=a,g=this._getSceneAndTransformerByDrawingSearch(s);if(!g)return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(I=this._renderManagerService.getRenderById(s))==null?void 0:I.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:m,data:h,allowTransform:f=!0}=e,S=o!=null?o:c.generateRandomId(),{position:w,position$:v}=this._createRangePositionObserver(t,u,d.skeleton);if(this._getPosition(w,s)==null)return;const D=g.scene,{scaleX:b}=D.getAncestorScale(),y=ze(w,n,b),M={unitId:s,subUnitId:l,drawingId:S,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:y.startX,top:y.startY,width:y.width,height:y.height},data:h,allowTransform:f};{const{unitId:U,subUnitId:j,drawingId:P}=M,T=C.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:j}),L=M,F=this._univerInstanceService.getUnit(U,c.UniverInstanceType.UNIVER_SHEET);if(!F)return;const J=F.getActiveSheet().getSheetId();if(!L||!T)return;const ne=(A=this._renderManagerService.getRenderById(U))==null?void 0:A.with(E.SheetSkeletonManagerService);if(!ne)return;const K=ne.getWorksheetSkeleton(j);if(!K)return;const{transform:z,drawingType:re,data:x}=L;if(re!==c.DrawingTypeEnum.DRAWING_DOM&&re!==c.DrawingTypeEnum.DRAWING_CHART)return;const Y=this._getSceneAndTransformerByDrawingSearch(U);if(Y==null)return;const{scene:ye,canvas:Ce}=Y;if(z==null||J!==j)return;const{left:Qe,top:et,width:tt,height:nt,angle:yt,flipX:Ct,flipY:rt,skewX:it,skewY:De}=z,ot=k.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:j,drawingId:P}),se=ye.getObject(ot);if(se!=null){se.transformByState({left:Qe,top:et,width:tt,height:nt,angle:yt,flipX:Ct,flipY:rt,skewX:it,skewY:De});return}const ie={left:Qe,top:et,width:tt,height:nt,zIndex:this._drawingManagerService.getDrawingOrder(U,j).length-1},Te=re===c.DrawingTypeEnum.DRAWING_CHART;if(Te){const $=x?x.backgroundColor:"white";ie.fill=$,ie.rotateEnabled=!1,x&&x.border&&(ie.stroke=x.border),ie.paintFirst="stroke",ie.strokeWidth=1,ie.borderEnabled=!1,ie.radius=8}const ce=new W.Rect(ot,ie);Te&&ce.setObjectType(W.ObjectType.CHART),ye.addObject(ce,W.DRAWING_OBJECT_LAYER_INDEX),L.allowTransform!==!1&&ye.attachTransformerTo(ce);const de=new c.DisposableCollection,at=ye.getMainViewport(),{rowHeaderWidth:Me,columnHeaderHeight:je}=K.skeleton,st={top:je,left:Me,bottom:at.bottom,right:at.right},le={dispose:de,rect:ce,boundsOfViewArea:st,domAnchor:n,unitId:U,subUnitId:j},V=ae(ce,Y.renderUnit.scene,K.skeleton,T.worksheet,le),be=new N.BehaviorSubject(V);le.position$=be;let We={position$:be,id:P,componentKey:L.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{Ce.dispatchEvent(new WheelEvent($.type,$))},data:x,unitId:U};e.eventPassThrough&&(We={...We,onPointerDown:$=>{Ce.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{Ce.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{Ce.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(We),this.disposeWithMe(v.subscribe($=>{var Wt,Bt,Lt,Yt;const jt=ze({startX:$.startX,startY:$.startY,endX:$.endX,endY:$.endY,width:(Wt=n.width)!=null?Wt:$.width,height:(Bt=n.height)!=null?Bt:$.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Kn=k.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:j,drawingId:P}),xn=new W.Rect(Kn,{left:jt.startX,top:jt.startY,width:(Lt=n.width)!=null?Lt:$.width,height:(Yt=n.height)!=null?Yt:$.height,zIndex:this._drawingManagerService.getDrawingOrder(U,j).length-1}),zn=ae(xn,Y.renderUnit.scene,K.skeleton,T.worksheet,le);be.next(zn)}));const Be=(R=this._renderManagerService.getRenderById(U))==null?void 0:R.with(E.SheetSkeletonManagerService);Be==null||Be.currentSkeleton$.subscribe($=>{$&&K.sheetId!==$.sheetId&&this._removeDom(S,!0)});const ct=ce.onTransformChange$.subscribeEvent(()=>{const $=ae(ce,Y.renderUnit.scene,K.skeleton,T.worksheet,le);be.next($)});de.add(()=>{this._canvasFloatDomService.removeFloatDom(P)}),ct&&de.add(ct),this._domLayerInfoMap.set(P,le)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(t,e,n,o){var y,M,I;const a=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:l}=a;if(!this._getSceneAndTransformerByDrawingSearch(s))return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(y=this._renderManagerService.getRenderById(s))==null?void 0:y.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:m,data:h,allowTransform:f=!0}=e,S=o!=null?o:c.generateRandomId(),{position:w,position$:v}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,d.skeleton),_=w;if(_.startY=0,this._getPosition(w,s)==null)return;const b={unitId:s,subUnitId:l,drawingId:S,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:_.startX,top:_.startY,width:_.width,height:_.height},data:h,allowTransform:f};{const{unitId:A,subUnitId:R,drawingId:U}=b,j=C.getSheetCommandTarget(this._univerInstanceService,{unitId:A,subUnitId:R}),P=b,T=this._univerInstanceService.getUnit(A,c.UniverInstanceType.UNIVER_SHEET);if(!T)return;const L=T.getActiveSheet().getSheetId();if(!P||!j)return;const F=(M=this._renderManagerService.getRenderById(A))==null?void 0:M.with(E.SheetSkeletonManagerService);if(!F)return;const J=F.getWorksheetSkeleton(R);if(!J)return;const{transform:ne,data:K}=P,z=this._getSceneAndTransformerByDrawingSearch(A);if(z==null)return;const{scene:re,canvas:x}=z;if(ne==null||L!==R)return;const{left:Y,top:ye,width:Ce,height:Qe,angle:et,flipX:tt,flipY:nt,skewX:yt,skewY:Ct}=ne,rt=k.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:R,drawingId:U}),it=re.getObject(rt);if(it!=null){it.transformByState({left:Y,top:ye,width:Ce,height:Qe,angle:et,flipX:tt,flipY:nt,skewX:yt,skewY:Ct});return}const De=ze({startX:_.startX,startY:0,endX:w.endX,endY:w.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),ot={left:De.startX,top:De.startY,width:De.width,height:De.height,zIndex:this._drawingManagerService.getDrawingOrder(A,R).length-1},se=new W.Rect(rt,ot);re.addObject(se,W.DRAWING_OBJECT_LAYER_INDEX),P.allowTransform!==!1&&re.attachTransformerTo(se);const ie=new c.DisposableCollection,Te=re.getMainViewport(),ce={top:0,left:Te.left,bottom:Te.bottom,right:Te.right},de={dispose:ie,rect:se,unitId:A,subUnitId:R,boundsOfViewArea:ce,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},at=ae(se,z.renderUnit.scene,J.skeleton,j.worksheet,de),Me=new N.BehaviorSubject(at);de.position$=Me;let je={position$:Me,id:U,componentKey:P.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:V=>{x.dispatchEvent(new WheelEvent(V.type,V))},data:K,unitId:A};e.eventPassThrough&&(je={...je,onPointerDown:V=>{x.dispatchEvent(new PointerEvent(V.type,V))},onPointerMove:V=>{x.dispatchEvent(new PointerEvent(V.type,V))},onPointerUp:V=>{x.dispatchEvent(new PointerEvent(V.type,V))}}),this._canvasFloatDomService.addFloatDom(je);const st=se.onTransformChange$.subscribeEvent(()=>{const V=ae(se,z.renderUnit.scene,J.skeleton,j.worksheet,de);Me.next(V)});this.disposeWithMe(v.subscribe(V=>{const be=ze({startX:V.startX,startY:0,endX:V.endX,endY:V.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),We=k.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:R,drawingId:U}),Be=new W.Rect(We,{left:be.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(A,R).length-1}),ct=ae(Be,z.renderUnit.scene,J.skeleton,j.worksheet,de);Me.next(ct)}));const le=(I=this._renderManagerService.getRenderById(A))==null?void 0:I.with(E.SheetSkeletonManagerService);le==null||le.currentSkeleton$.subscribe(V=>{V&&d.sheetId!==V.sheetId&&this._removeDom(S,!0)}),ie.add(()=>{this._canvasFloatDomService.removeFloatDom(U)}),st&&ie.add(st),this._domLayerInfoMap.set(U,de)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:o,startColumn:a}=t;const s=Ne(o,a,n),l=new N.BehaviorSubject(s),g=Ne(t.endRow,t.endColumn,n),u=new N.BehaviorSubject(g),d=()=>{const v=Ne(o,a,n),_=Ne(t.endRow,t.endColumn,n);l.next(v),u.next(_)},m=new c.DisposableCollection;m.add(e.engine.clientRect$.subscribe(()=>d())),m.add(this._commandService.onCommandExecuted(v=>{if(v.id===C.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(D=>D.row===o)>-1){d();return}(C.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(v.id)>-1||v.id===E.SetScrollOperation.id||v.id===E.SetZoomRatioOperation.id)&&d()}));const h=(v,_)=>{o=v,a=_,d()},f=()=>({rotate:0,width:g.right-s.left,height:g.bottom-s.top,absolute:{left:!0,top:!0},startX:s.left,startY:s.top,endX:g.right,endY:g.bottom}),S=l.pipe(N.map(v=>{const _=Ne(t.endRow,t.endColumn,n);return{rotate:0,width:_.right-v.left,height:_.bottom-v.top,absolute:{left:!0,top:!0},startX:v.left,startY:v.top,endX:_.right,endY:_.bottom}})),w=f();return{position$:S,position:w,updateRowCol:h,topLeftPos$:l,rightBottomPos$:u,disposable:m}}},O.SheetCanvasFloatDomManagerService=fn([fe(0,c.Inject(W.IRenderManagerService)),fe(1,c.IUniverInstanceService),fe(2,c.Inject(c.ICommandService)),fe(3,k.IDrawingManagerService),fe(4,c.Inject(B.CanvasFloatDomService)),fe(5,p.ISheetDrawingService),fe(6,c.Inject(c.LifecycleService))],O.SheetCanvasFloatDomManagerService);function Ne(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 ze(i,r,t){var g,u;t=t!=null?t:1;const e=i.endX-i.startX,n=i.endY-i.startY,o=(g=r==null?void 0:r.width)!=null?g:e,a=(u=r==null?void 0:r.height)!=null?u:n;let s=0,l=0;if(r){if(r.horizonOffsetAlign==="right"){const d=Ze(r.marginX,e*t);s=i.endX-d-o}else s=i.startX+Ze(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const d=Ze(r.marginY,n*t);l=i.endY-d-a}else l=i.startY+Ze(r.marginY,n)}return{rotate:0,startX:s,startY:l,endX:i.endX,endY:i.endY,width:o,height:a,absolute:{left:i.absolute.left,top:i.absolute.top}}}function Ze(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const t=Number.parseFloat(i);return r*t/100}const Sn=i=>{const{floatDomInfos:r,scene:t,skeleton:e,worksheet:n}=i,o=Q.useMemo(()=>r.map(a=>{const{width:s,height:l,angle:g,left:u,top:d}=a.transform,m=Ot({left:u!=null?u:0,right:(u!=null?u:0)+(s!=null?s:0),top:d!=null?d:0,bottom:(d!=null?d:0)+(l!=null?l:0)},t,e,n,void 0,!0),{scaleX:h,scaleY:f}=t.getAncestorScale(),S={startX:m.left,endX:m.right,startY:m.top,endY:m.bottom,rotate:g,width:s*h,height:l*f,absolute:m.absolute},w={position$:new N.BehaviorSubject(S),position:S,id:a.drawingId,componentKey:a.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:a.unitId,data:a.data};return[a.drawingId,w]}),[r,t,e,n]);return X.jsx("div",{style:{position:"absolute",top:0,left:0},children:o.map(([a,s])=>X.jsx(B.PrintFloatDomSingle,{layer:s,id:a,position:s.position},a))})};var wn=Object.getOwnPropertyDescriptor,vn=(i,r,t,e)=>{for(var n=e>1?void 0:e?wn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Se=(i,r)=>(t,e)=>r(t,e,i);let qe=class extends c.Disposable{constructor(i,r,t,e,n,o,a){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._canvasFloatDomManagerService=n,this._componetManager=o,this._injector=a,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,t)=>{const{unitId:e,scene:n,subUnitId:o}=r,a=this._drawingManagerService.getDrawingDataForUnit(e),s=a==null?void 0:a[o];return s&&s.order.forEach(l=>{const g=s.data[l];g.drawingType!==c.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==c.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,o=this._renderManagerService.getRenderById(e);if(!o)return t(i);const a=o.with(E.SheetSkeletonManagerService).getSkeletonParam(n);if(!a)return t(i);const s=this._drawingManagerService.getDrawingDataForUnit(e),l=s==null?void 0:s[r.subUnitId];if(!l)return t(i);const{scaleX:g,scaleY:u}=o.scene,d=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=l.order.map(h=>l.data[h]);return m.length?(m.forEach(h=>{if(!h.groupId&&h.transform&&c.Tools.isDefine(h.transform.left)&&c.Tools.isDefine(h.transform.top)&&c.Tools.isDefine(h.transform.width)&&c.Tools.isDefine(h.transform.height)){const f=a.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});f.column<d.startColumn&&(d.startColumn=f.column),f.row<d.startRow&&(d.startRow=f.row),d.endRow<S.row&&(d.endRow=S.row),d.endColumn<S.column&&(d.endColumn=S.column)}}),t(d)):t(i)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,o=this._drawingManagerService.getDrawingDataForUnit(e),a=o==null?void 0:o[n];if(a){const s=a.order.map(g=>{const u=a.data[g];if(u.drawingType===c.DrawingTypeEnum.DRAWING_CHART)return{...u,componentKey:this._componetManager.get(c.PRINT_CHART_COMPONENT_KEY)};if(u.drawingType===c.DrawingTypeEnum.DRAWING_DOM){const d=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(d||u.componentKey)}}return null}).filter(Boolean),l=B.connectInjector(Sn,this._injector);return Z.render(X.jsx(l,{floatDomInfos:s,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),i==null||i.add(()=>{Z.unmount(r.root)}),t(i)}}}))}};qe=vn([Se(0,c.Inject(E.SheetPrintInterceptorService)),Se(1,c.Inject(ue.DrawingRenderService)),Se(2,k.IDrawingManagerService),Se(3,W.IRenderManagerService),Se(4,c.Inject(O.SheetCanvasFloatDomManagerService)),Se(5,c.Inject(B.ComponentManager)),Se(6,c.Inject(c.Injector))],qe);var _n=Object.getOwnPropertyDescriptor,In=(i,r,t,e)=>{for(var n=e>1?void 0:e?_n(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},he=(i,r)=>(t,e)=>r(t,e,i);const yn=[C.InsertRowCommand.id,C.InsertColCommand.id,C.RemoveRowCommand.id,C.RemoveColCommand.id,C.DeleteRangeMoveLeftCommand.id,C.DeleteRangeMoveUpCommand.id,C.InsertRangeMoveDownCommand.id,C.InsertRangeMoveRightCommand.id,C.DeltaRowHeightCommand.id,C.SetRowHeightCommand.id,C.DeltaColumnWidthCommand.id,C.SetColWidthCommand.id,C.SetRowHiddenCommand.id,C.SetSpecificRowsVisibleCommand.id,C.SetSpecificColsVisibleCommand.id,C.SetColHiddenCommand.id,C.MoveColsCommand.id,C.MoveRowsCommand.id,C.MoveRangeCommand.id],Cn=[C.SetRowVisibleMutation.id,C.SetRowHiddenMutation.id,C.SetColVisibleMutation.id,C.SetColHiddenMutation.id,C.SetWorksheetRowHeightMutation.id,C.SetWorksheetColWidthMutation.id];let wt=class extends c.Disposable{constructor(i,r,t,e,n,o,a,s,l){super(),this._context=i,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._univerInstanceService=l,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===C.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([C.MoveColsCommand.id,C.MoveRowsCommand.id,C.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===C.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===C.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===C.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===C.DeleteRangeMoveLeftCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,0)}else if(r===C.DeleteRangeMoveUpCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,1)}else if(r===C.InsertRangeMoveDownCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,2)}else if(r===C.InsertRangeMoveRightCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,3)}else if(r===C.SetRowHiddenCommand.id||r===C.SetSpecificRowsVisibleCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForRowVisible(e,n,o)}else if(r===C.SetSpecificColsVisibleCommand.id||r===C.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForColVisible(e,n,o)}else if(r===C.DeltaRowHeightCommand.id||r===C.SetRowHeightCommand.id||r===C.DeltaColumnWidthCommand.id||r===C.SetColWidthCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t,a=r===C.DeltaRowHeightCommand.id||r===C.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const t=C.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(e,n),l=[],g=[];if(Object.keys(s).forEach(u=>{const d=s[u],{updateDrawings:m,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,d);l.push(...m),g.push(...h)}),l.length===0&&g.length===0)return{redos:[],undos:[]};if(l.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(l),{undo:d,redo:m,objects:h}=u;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:m,objects:h,type:p.DrawingApplyType.UPDATE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:d,objects:h,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),d=u.undo,m=u.redo,h=u.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:m,objects:h,type:p.DrawingApplyType.REMOVE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:d,objects:h,type:p.DrawingApplyType.INSERT}})}return o.push({id:G.id,params:[e]}),a.push({id:G.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,r,t){const e=[],n=[],{sheetTransform:o,anchorType:a=p.SheetDrawingAnchorType.Position,transform:s,unitId:l,subUnitId:g,drawingId:u}=t,{from:d,to:m}=o,{row:h,column:f}=d,{row:S,column:w}=m;if(o==null||s==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:v,endRow:_,startColumn:D,endColumn:b}=i;let y=null,M=null;if(r===0&&h>=v&&S<=_)if(f>=D&&w<=b)n.push({unitId:l,subUnitId:g,drawingId:u});else{const I=this._shrinkCol(o,s,D,b,a);y=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}else if(r===1&&f>=D&&w<=b)if(h>=v&&S<=_)n.push({unitId:l,subUnitId:g,drawingId:u});else{const I=this._shrinkRow(o,s,v,_,a);y=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}else if(r===2){const I=this._expandRow(o,s,v,_,a);y=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}else if(r===3){const I=this._expandCol(o,s,D,b,a);y=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}if(y!=null&&M!=null){const I=q(y,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:y,transform:I})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(i,r,t){const e=H({...i},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:m,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=d;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:w}=m,{row:v,column:_}=S,{row:D,column:b}=w;for(let y=0;y<t.length;y++){const M=t[y],{startRow:I,endRow:A,startColumn:R,endColumn:U}=M;if(b<R)continue;if(f===p.SheetDrawingAnchorType.Position){let T=null,L=null;if(_>=R&&_<=U){const F=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:U,startRow:S.row,endRow:w.row});if(F==null)return;L={...h,left:F.startX}}if(L!=null&&(T=H(L,this._selectionRenderService),T!=null&&L!=null)){n.push({...d,sheetTransform:T,transform:L});break}this._remainDrawingSize(h,n,d);continue}if(_>=R&&b<=U)continue;let j=null,P=null;if(_>=R&&_<=U){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:U,startRow:S.row,endRow:w.row});if(T==null)return;P={...h,left:(T==null?void 0:T.startX)||0,width:((h==null?void 0:h.width)||0)-T.endX+T.startX}}else if(b>=R&&b<=U){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:R,endColumn:b,startRow:S.row,endRow:w.row});if(T==null)return;P={...h,left:T.startX-((h==null?void 0:h.width)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:R,endColumn:U,startRow:S.row,endRow:w.row});if(T==null)return;if(P={...h,width:((h==null?void 0:h.width)||0)-T.endX+T.startX},j=H(P,this._selectionRenderService),j!=null&&P!=null){o.push({...d,sheetTransform:j,transform:P});break}}if(P!=null&&(j=H(P,this._selectionRenderService)),P!=null&&j!=null){n.push({...d,sheetTransform:j,transform:P});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),l=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),g.push(...d)}return{redos:a,undos:s,preRedos:l,preUndos:g}}_createUndoAndRedoMutation(i,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:o,objects:a}=e,s=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],l=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:a,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:s,undos:l}}_getDrawingUndoForRowVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:m,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=d;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:w}=m,{row:v,column:_}=S,{row:D,column:b}=w;for(let y=0;y<t.length;y++){const M=t[y],{startRow:I,endRow:A,startColumn:R,endColumn:U}=M;if(D<I)continue;if(f===p.SheetDrawingAnchorType.Position){let T=null,L=null;if(v>=I&&v<=A){const F=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:A});if(F==null)return;L={...h,top:F.startY}}if(L!=null&&(T=H(L,this._selectionRenderService),T!=null&&L!=null)){n.push({...d,sheetTransform:T,transform:L});break}this._remainDrawingSize(h,n,d);continue}if(v>=I&&D<=A)continue;let j=null,P=null;if(v>=I&&v<=A){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:A});if(T==null)return;P={...h,top:(T==null?void 0:T.startY)||0,height:((h==null?void 0:h.height)||0)-T.endY+T.startY}}else if(D>=I&&D<=A){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:D});if(T==null)return;P={...h,top:T.startY-((h==null?void 0:h.height)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:A});if(T==null)return;if(P={...h,height:((h==null?void 0:h.height)||0)-T.endY+T.startY},j=H(P,this._selectionRenderService),j!=null&&P!=null){o.push({...d,sheetTransform:j,transform:P});break}}if(P!=null&&(j=H(P,this._selectionRenderService)),P!=null&&j!=null){n.push({...d,sheetTransform:j,transform:P});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),l=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),g.push(...d)}return{redos:a,undos:s,preRedos:l,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,t,e){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(a=>{const s=n[a],{sheetTransform:l,transform:g,anchorType:u=p.SheetDrawingAnchorType.Position}=s;if(u===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,o,s);else{const{from:d,to:m}=l,{row:h,column:f}=d,{row:S,column:w}=m;for(let v=0;v<t.length;v++){const _=t[v],{startRow:D,endRow:b,startColumn:y,endColumn:M}=_;if(S<D||w<y)continue;if(u===p.SheetDrawingAnchorType.Position&&(h<=D&&S>=b||f<=y&&w>=M)){this._remainDrawingSize(g,o,s);continue}const I=q({...l},this._selectionRenderService,this._skeletonManagerService);if(I!=null){o.push({...s,transform:I});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let t,e;if(r==="insert")t=i.unitId,e=i.subUnitId;else{const n=C.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(i){var D,b;const{toRange:r,fromRange:t}=i,e=C.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=e,a=(b=(D=this._renderManagerService.getRenderById(n))==null?void 0:D.with(E.SheetSkeletonManagerService))==null?void 0:b.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=E.attachRangeWithCoord(a,t);if(!s)return{redos:[],undos:[]};const{startX:l,endX:g,startY:u,endY:d}=s,m=this._sheetDrawingService.getDrawingData(n,o),h=[];Object.keys(m).forEach(y=>{const M=m[y];if(M.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:I}=M;if(!I)return;const{left:A=0,top:R=0,width:U=0,height:j=0}=I,{drawingStartX:P,drawingEndX:T,drawingStartY:L,drawingEndY:F}={drawingStartX:A,drawingEndX:A+U,drawingStartY:R,drawingEndY:R+j};l<=P&&T<=g&&u<=L&&F<=d&&h.push(M)});const f=[],S=[],w=r.startRow-t.startRow,v=r.startColumn-t.startColumn,_=h.map(y=>{const M=y.sheetTransform,I={to:{...M.to,row:M.to.row+w,column:M.to.column+v},from:{...M.from,row:M.from.row+w,column:M.from.column+v}},A=q(I,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:y.drawingId,transform:A,sheetTransform:I}});if(_.length){const y=this._sheetDrawingService.getBatchUpdateOp(_),{undo:M,redo:I,objects:A}=y;f.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:I,objects:A,type:p.DrawingApplyType.UPDATE}}),S.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:M,objects:A,type:p.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,a=o.startRow,s=o.endRow,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],m=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:v=p.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let _,D;if(r==="insert"){const y=this._expandRow(S,w,a,s,v);_=y==null?void 0:y.newSheetTransform,D=y==null?void 0:y.newTransform}else{const{from:y,to:M}=S,{row:I}=y,{row:A}=M;if(v===p.SheetDrawingAnchorType.Both&&I>=a&&A<=s)m.push({unitId:e,subUnitId:n,drawingId:h});else{const R=this._shrinkRow(S,w,a,s,v);_=R==null?void 0:R.newSheetTransform,D=R==null?void 0:R.newTransform}}if(!_||!D)return;const b={unitId:e,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};d.push(b)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:f,redo:S,objects:w}=h;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.UPDATE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),f=h.undo,S=h.redo,w=h.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.REMOVE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:l,undos:g}}_moveColInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,a=o.startColumn,s=o.endColumn,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],m=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:v=p.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let _,D;if(r==="insert"){const y=this._expandCol(S,w,a,s,v);_=y==null?void 0:y.newSheetTransform,D=y==null?void 0:y.newTransform}else{const{from:y,to:M}=S,{column:I}=y,{column:A}=M;if(v===p.SheetDrawingAnchorType.Both&&I>=a&&A<=s)m.push({unitId:e,subUnitId:n,drawingId:h});else{const R=this._shrinkCol(S,w,a,s,v);_=R==null?void 0:R.newSheetTransform,D=R==null?void 0:R.newTransform}}if(!_||!D)return;const b={unitId:e,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};d.push(b)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:f,redo:S,objects:w}=h;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.UPDATE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),f=h.undo,S=h.redo,w=h.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.REMOVE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:l,undos:g}}_expandCol(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{column:l}=a,{column:g}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>=t){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:a.row,endRow:s.row});if(m==null)return;d={...r,left:(r.left||0)+m.endX-m.startX},u=H(d,this._selectionRenderService)}else if(g>=e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:g+o}},d=q(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkCol(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{column:l}=a,{column:g}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>e)u={from:{...a,column:l-o},to:{...s,column:g-o}},d=q(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&g<=e)return null;if(l<t&&g>e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:g-o}},d=q(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)d={...r,left:(r.left||0)-i.from.columnOffset};else{const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:l-1,startRow:a.row,endRow:s.row});if(m==null)return;d={...r,left:(r.left||0)-m.endX+m.startX-i.from.columnOffset}}u=H(d,this._selectionRenderService)}else if(g>=t&&g<=e&&n===p.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:a.row,endRow:s.row});if(m==null)return;u={from:{...a},to:{...s,column:t-1,columnOffset:m.endX-m.startX}},d=q(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_expandRow(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{row:l}=a,{row:g}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>=t){const m=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:a.column,endColumn:s.column});if(m==null)return;d={...r,top:(r.top||0)+m.endY-m.startY},u=H(d,this._selectionRenderService)}else if(g>=e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:g+o}},d=q(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkRow(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{row:l}=a,{row:g}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>e)u={from:{...a,row:l-o},to:{...s,row:g-o}},d=q(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&g<=e)return null;if(l<t&&g>e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:g-o}},d=q(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)d={...r,top:(r.top||0)-i.from.rowOffset};else{const m=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:l-1,startColumn:a.column,endColumn:s.column});if(m==null)return;d={...r,top:(r.top||0)-m.endY+m.startY-i.from.rowOffset}}u=H(d,this._selectionRenderService)}else if(g>=t&&g<=e&&n===p.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:t-1,endRow:t-1});if(m==null)return;u={from:{...a},to:{...s,row:t-1,rowOffset:m.endY-m.startY}},d=q(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===C.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:t}=i.params;this._updateDrawings(r,t)}})),this.disposeWithMe(this._context.activated$.subscribe(i=>{const{unit:r,unitId:t}=this._context;if(i){const e=r.getActiveSheet().getSheetId();this._updateDrawings(t,e)}else this._clearDrawings(t)}))}_clearDrawings(i){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,t=[];Object.keys(r).forEach(e=>{const n=r[e];n!=null&&Object.keys(n).forEach(o=>{const a=n[o].data;a!=null&&Object.keys(a).forEach(s=>{e===i&&t.push(a[s])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(i,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(o=>{const a=t[o];a!=null&&Object.keys(a).forEach(s=>{const l=a[s].data;l!=null&&Object.keys(l).forEach(g=>{if(o===i&&s===r){const u=l[g];u.transform=q(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(l[g])}else n.push(l[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{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(o=>{const a=e[o],{sheetTransform:s,transform:l,anchorType:g=p.SheetDrawingAnchorType.Position}=a;if(g===p.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=s,{row:m,column:h}=u,{row:f,column:S}=d;for(let w=0;w<t.length;w++){const v=t[w],{startRow:_,endRow:D,startColumn:b,endColumn:y}=v;if(c.Rectangle.intersects({startRow:_,endRow:D,startColumn:b,endColumn:y},{startRow:m,endRow:f,startColumn:h,endColumn:S})||m>D||h>y){const M=g===p.SheetDrawingAnchorType.Position,I=q(s,this._selectionRenderService,this._skeletonManagerService);n.push({...a,transform:{...I,width:M?l==null?void 0:l.width:I==null?void 0:I.width,height:M?l==null?void 0:l.height:I==null?void 0:I.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[i]))}};wt=In([he(1,W.IRenderManagerService),he(2,c.ICommandService),he(3,E.ISheetSelectionRenderService),he(4,c.Inject(E.SheetSkeletonManagerService)),he(5,c.Inject(C.SheetInterceptorService)),he(6,p.ISheetDrawingService),he(7,k.IDrawingManagerService),he(8,c.IUniverInstanceService)],wt);var te=function(){return te=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},te.apply(this,arguments)},Dn=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=Q.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,o=i.extend,a=Dn(i,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),l=Q.useRef("_".concat(bn()));return At(t,"".concat(e),{defIds:t.defIds,idSuffix:l.current},te({ref:r,className:s},a),o)});function At(i,r,t,e,n){return Q.createElement(i.tag,te(te({key:r},Tn(i,t,n)),e),(Mn(i,t).children||[]).map(function(o,a){return At(o,"".concat(r,"-").concat(i.tag,"-").concat(a),t,void 0,n)}))}function Tn(i,r,t){var e=te({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1),i.tag==="mask"&&e.id&&(e.id=e.id+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];a==="mask"&&typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))});var n=r.defIds;return!n||n.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Mn(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)?te(te({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?te(te({},n),{attrs:te(te({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function bn(){return Math.random().toString(36).substring(2,8)}Pt.displayName="UniverIcon";var Rn={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"}}]},Ut=Q.forwardRef(function(i,r){return Q.createElement(Pt,Object.assign({},i,{id:"add-image-single",ref:r,icon:Rn}))});Ut.displayName="AddImageSingle";const vt={id:"sheet.command.delete-drawing",type:c.CommandType.COMMAND,handler:i=>{const r=i.get(c.ICommandService),e=i.get(p.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,o=e.map(a=>{const{unitId:s,subUnitId:l,drawingId:g,drawingType:u}=a;return{unitId:s,subUnitId:l,drawingId:g,drawingType:u}});return r.executeCommand(we.id,{unitId:n,drawings:o})}},_e={id:"sheet.command.move-drawing",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(p.ISheetDrawingService),n=i.get(E.ISheetSelectionRenderService),{direction:o}=r,a=e.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,l=a.map(u=>{const{transform:d}=u;if(d==null)return null;const m={...d},{left:h=0,top:f=0}=d;return o===c.Direction.UP?m.top=f-1:o===c.Direction.DOWN?m.top=f+1:o===c.Direction.LEFT?m.left=h-1:o===c.Direction.RIGHT&&(m.left=h+1),{...u,transform:m,sheetTransform:H(m,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(Ee.id,{unitId:s,drawings:l})?(t.syncExecuteCommand(G.id,[s]),!0):!1}},Nt="addition-and-subtraction-single",_t="sheet.menu.image";function En(i){return{id:_t,type:B.MenuItemType.SUBITEMS,icon:Nt,tooltip:"sheetImage.title",hidden$:B.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(i,{workbookTypes:[C.WorkbookEditablePermission],worksheetTypes:[C.WorksheetEditPermission],rangeTypes:[C.RangeProtectionPermissionEditPoint]})}}function On(i){return{id:Pe.id,title:"sheetImage.upload.float",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET)}}function Pn(i){return{id:St.id,title:"sheetImage.upload.cell",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET)}}const me={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelColumn:"univer-image-common-panel-column"},An=i=>{var D;const r=B.useDependency(c.ICommandService),t=B.useDependency(c.LocaleService),e=B.useDependency(k.IDrawingManagerService),n=B.useDependency(W.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:s}=a,l=n.getRenderById(s),g=l==null?void 0:l.scene;if(g==null)return;const u=g.getTransformerByCreate(),[d,m]=Q.useState(!0),h=(D=a.anchorType)!=null?D:p.SheetDrawingAnchorType.Position,[f,S]=Q.useState(h);function w(b,y){const M=[];return b.forEach(I=>{const{oKey:A}=I,R=y.getDrawingOKey(A);if(R==null)return M.push(null),!0;const{unitId:U,subUnitId:j,drawingId:P,drawingType:T,anchorType:L,sheetTransform:F}=R;M.push({unitId:U,subUnitId:j,drawingId:P,anchorType:L,sheetTransform:F,drawingType:T})}),M}Q.useEffect(()=>{const b=u.clearControl$.subscribe(M=>{M===!0&&m(!1)}),y=u.changeStart$.subscribe(M=>{var R;const{objects:I}=M,A=w(I,e);if(A.length===0)m(!1);else if(A.length>=1){m(!0);const U=((R=A[0])==null?void 0:R.anchorType)||p.SheetDrawingAnchorType.Position;S(U)}});return()=>{y.unsubscribe(),b.unsubscribe()}},[]);function v(b){S(b);const y=e.getFocusDrawings();if(y.length===0)return;const M=y.map(I=>({unitId:I.unitId,subUnitId:I.subUnitId,drawingId:I.drawingId,anchorType:b}));r.executeCommand(Ee.id,{unitId:y[0].unitId,drawings:M})}const _=b=>b?"block":"none";return X.jsxs("div",{className:Z.clsx(me.imageCommonPanelGrid,me.imageCommonPanelBorder),style:{display:_(d)},children:[X.jsx("div",{className:me.imageCommonPanelRow,children:X.jsx("div",{className:Z.clsx(me.imageCommonPanelColumn,me.imageCommonPanelTitle),children:X.jsx("div",{children:t.t("drawing-anchor.title")})})}),X.jsx("div",{className:Z.clsx(me.imageCommonPanelRow),children:X.jsx("div",{className:Z.clsx(me.imageCommonPanelColumn),children:X.jsxs(Z.RadioGroup,{value:f,onChange:v,direction:"vertical",children:[X.jsx(Z.Radio,{value:p.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),X.jsx(Z.Radio,{value:p.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),X.jsx(Z.Radio,{value:p.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})})]})},Un=()=>{const i=B.useDependency(k.IDrawingManagerService),r=i.getFocusDrawings(),[t,e]=Q.useState(r);return Q.useEffect(()=>{const n=i.focus$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&X.jsxs("div",{className:me.imageCommonPanel,children:[X.jsx(ue.DrawingCommonPanel,{drawings:t}),X.jsx(An,{drawings:t})]})},Nn={[B.RibbonStartGroup.FORMULAS_INSERT]:{[_t]:{order:3,menuItemFactory:En,[Pe.id]:{order:0,menuItemFactory:On},[St.id]:{order:1,menuItemFactory:Pn}}}};function ke(i){return!i.getContextValue(c.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(c.EDITOR_ACTIVATED)&&!i.getContextValue(c.FOCUSING_PANEL_EDITOR)&&i.getContextValue(c.FOCUSING_COMMON_DRAWINGS)}const kn={id:_e.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:B.KeyCode.ARROW_DOWN,priority:100,preconditions:ke,staticParameters:{direction:c.Direction.DOWN}},jn={id:_e.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:B.KeyCode.ARROW_UP,priority:100,preconditions:ke,staticParameters:{direction:c.Direction.UP}},Wn={id:_e.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:B.KeyCode.ARROW_LEFT,priority:100,preconditions:ke,staticParameters:{direction:c.Direction.LEFT}},Bn={id:_e.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:B.KeyCode.ARROW_RIGHT,priority:100,preconditions:ke,staticParameters:{direction:c.Direction.RIGHT}},Ln={id:vt.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:ke,binding:B.KeyCode.DELETE,mac:B.KeyCode.BACKSPACE};var Yn=Object.getOwnPropertyDescriptor,$n=(i,r,t,e)=>{for(var n=e>1?void 0:e?Yn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ie=(i,r)=>(t,e)=>r(t,e,i);let Je=class extends c.Disposable{constructor(i,r,t,e,n,o){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Nt,Ut)),this.disposeWithMe(i.register(Tt,Un))}_initMenus(){this._menuManagerService.mergeMenu(Nn)}_initCommands(){[Pe,St,Re,we,Ee,dt,G,lt,ht,pt,_e,vt,mt].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[kn,jn,Wn,Bn,Ln].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Je=$n([Ie(0,c.Inject(B.ComponentManager)),Ie(1,B.IMenuManagerService),Ie(2,c.ICommandService),Ie(3,B.IShortcutService),Ie(4,k.IDrawingManagerService),Ie(5,c.Inject(C.SheetsSelectionsService))],Je);var Fn=Object.defineProperty,Gn=Object.getOwnPropertyDescriptor,Hn=(i,r,t)=>r in i?Fn(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,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},It=(i,r)=>(t,e)=>r(t,e,i),kt=(i,r,t)=>Hn(i,typeof r!="symbol"?r+"":r,t);const Xn="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends c.Plugin{constructor(r=Dt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:o,...a}=c.merge({},Dt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig($t,a)}onStarting(){c.registerDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService],[Je],[$e],[qe],[xe],[Ke],[He],[Ve],[Xe]]),c.touchDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService]])}onReady(){c.touchDependencies(this._injector,[[Ke],[Xe]])}onRendered(){this._registerRenderModules(),c.touchDependencies(this._injector,[[xe],[qe],[Je],[He],[Ve]])}onSteady(){this._injector.get($e)}_registerRenderModules(){[[O.SheetDrawingUpdateController],[wt],[gt],[ut]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(c.UniverInstanceType.UNIVER_SHEET,r))})}},kt(O.UniverSheetsDrawingUIPlugin,"type",c.UniverInstanceType.UNIVER_SHEET),kt(O.UniverSheetsDrawingUIPlugin,"pluginName",Xn),O.UniverSheetsDrawingUIPlugin=Vn([c.DependentOn(k.UniverDrawingPlugin,pe.UniverDocsDrawingPlugin,ue.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),It(1,c.Inject(c.Injector)),It(2,W.IRenderManagerService),It(3,c.IConfigService)],O.UniverSheetsDrawingUIPlugin),O.ClearSheetDrawingTransformerOperation=G,O.DeleteDrawingsCommand=vt,O.EditSheetDrawingOperation=lt,O.GroupSheetDrawingCommand=ht,O.InsertFloatImageCommand=Pe,O.InsertSheetDrawingCommand=Re,O.MoveDrawingsCommand=_e,O.RemoveSheetDrawingCommand=we,O.SHEETS_IMAGE_MENU_ID=_t,O.SetDrawingArrangeCommand=mt,O.SetSheetDrawingCommand=Ee,O.SidebarSheetDrawingOperation=dt,O.UngroupSheetDrawingCommand=pt,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-drawing-ui",
3
- "version": "0.6.10-experimental.20250428-2b6408c",
3
+ "version": "0.6.10-experimental.20250428-8c74c87",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -63,17 +63,17 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@univerjs/icons": "^0.3.22",
66
- "@univerjs/core": "0.6.10-experimental.20250428-2b6408c",
67
- "@univerjs/docs-drawing": "0.6.10-experimental.20250428-2b6408c",
68
- "@univerjs/design": "0.6.10-experimental.20250428-2b6408c",
69
- "@univerjs/docs-ui": "0.6.10-experimental.20250428-2b6408c",
70
- "@univerjs/drawing-ui": "0.6.10-experimental.20250428-2b6408c",
71
- "@univerjs/sheets": "0.6.10-experimental.20250428-2b6408c",
72
- "@univerjs/engine-render": "0.6.10-experimental.20250428-2b6408c",
73
- "@univerjs/sheets-drawing": "0.6.10-experimental.20250428-2b6408c",
74
- "@univerjs/drawing": "0.6.10-experimental.20250428-2b6408c",
75
- "@univerjs/ui": "0.6.10-experimental.20250428-2b6408c",
76
- "@univerjs/sheets-ui": "0.6.10-experimental.20250428-2b6408c"
66
+ "@univerjs/core": "0.6.10-experimental.20250428-8c74c87",
67
+ "@univerjs/design": "0.6.10-experimental.20250428-8c74c87",
68
+ "@univerjs/docs-drawing": "0.6.10-experimental.20250428-8c74c87",
69
+ "@univerjs/docs-ui": "0.6.10-experimental.20250428-8c74c87",
70
+ "@univerjs/drawing-ui": "0.6.10-experimental.20250428-8c74c87",
71
+ "@univerjs/drawing": "0.6.10-experimental.20250428-8c74c87",
72
+ "@univerjs/engine-render": "0.6.10-experimental.20250428-8c74c87",
73
+ "@univerjs/sheets": "0.6.10-experimental.20250428-8c74c87",
74
+ "@univerjs/sheets-drawing": "0.6.10-experimental.20250428-8c74c87",
75
+ "@univerjs/sheets-ui": "0.6.10-experimental.20250428-8c74c87",
76
+ "@univerjs/ui": "0.6.10-experimental.20250428-8c74c87"
77
77
  },
78
78
  "devDependencies": {
79
79
  "less": "^4.3.0",