@univerjs/sheets-drawing-ui 0.2.4-alpha.0 → 0.2.5

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 +1 @@
1
- "use strict";var He=Object.defineProperty;var xe=(i,t,e)=>t in i?He(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var Y=(i,t,e)=>xe(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@univerjs/core"),Z=require("@univerjs/drawing-ui"),p=require("@univerjs/sheets-drawing"),P=require("@univerjs/drawing"),N=require("@univerjs/engine-render"),W=require("@univerjs/sheets-ui"),V=require("rxjs"),G=require("@univerjs/ui"),_=require("@univerjs/sheets"),U=require("react"),z=require("@univerjs/design"),de=require("clsx"),B={id:"sheet.operation.clear-drawing-transformer",type:m.CommandType.MUTATION,handler:(i,t)=>{const e=i.get(N.IRenderManagerService);return t.forEach(n=>{var r,o;(o=(r=e.getRenderById(n))==null?void 0:r.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},ve={id:"sheet.command.remove-sheet-image",type:m.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(m.ICommandService),n=i.get(m.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!t)return!1;const{drawings:o}=t,s=[];o.forEach(w=>{const{unitId:f}=w;s.push(f)});const a=r.getBatchRemoveOp(o),{unitId:d,subUnitId:u,undo:l,redo:c,objects:g}=a;return e.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:d,subUnitId:u,op:c,objects:g,type:p.DrawingApplyType.REMOVE})?(n.pushUndoRedo({unitID:d,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:d,subUnitId:u,op:l,objects:g,type:p.DrawingApplyType.INSERT}},{id:B.id,params:s}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:d,subUnitId:u,op:c,objects:g,type:p.DrawingApplyType.REMOVE}},{id:B.id,params:s}]}),!0):!1}},Le="COMPONENT_SHEET_DRAWING_PANEL",ye={id:"sidebar.operation.sheet-image",type:m.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(G.ISidebarService),n=i.get(m.LocaleService),r=i.get(m.IUniverInstanceService),o=i.get(P.IDrawingManagerService);if(!_.getSheetCommandTarget(r))return!1;switch(t.value){case"open":e.open({header:{title:n.t("sheetImage.panel.title")},children:{label:Le},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:e.close();break}return!0}},Me={id:"sheet.operation.edit-sheet-image",type:m.CommandType.OPERATION,handler:(i,t)=>{const e=i.get(P.IDrawingManagerService),n=i.get(m.ICommandService);return t==null?!1:(e.focusDrawing([t]),n.executeCommand(ye.id,{value:"open"}),!0)}},Ye="univer-upload-loading",Xe="univer-upload-loading-body",Ke="univer-upload-loading-body-animation",ze="univer-UniverCircleAnimation",qe="univer-upload-loading-body-text",le={uploadLoading:Ye,uploadLoadingBody:Xe,uploadLoadingBodyAnimation:Ke,univerCircleAnimation:ze,uploadLoadingBodyText:qe},Je=()=>{const i=m.useDependency(P.IImageIoService),t=m.useDependency(m.LocaleService),[e,n]=U.useState(0);return U.useEffect(()=>{const r=i.change$.subscribe(o=>{n(o)});return()=>{r.unsubscribe()}},[i]),U.createElement("div",{style:{display:e>0?"block":"none"},className:le.uploadLoading},U.createElement("div",{className:le.uploadLoadingBody},U.createElement("div",{className:le.uploadLoadingBodyAnimation}),U.createElement("div",{className:le.uploadLoadingBodyText},`${t.t("uploadLoading.loading")}: ${e}`)))};var Ze=Object.defineProperty,Qe=Object.getOwnPropertyDescriptor,et=(i,t,e,n)=>{for(var r=n>1?void 0:n?Qe(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&Ze(t,e,r),r},J=(i,t)=>(e,n)=>t(e,n,i);let ge=class extends m.RxDisposable{constructor(t,e,n,r,o,s,a){super();Y(this,"_initImagePopupMenu",new Set);this._injector=t,this._drawingManagerService=e,this._canvasPopManagerService=n,this._renderManagerService=r,this._univerInstanceService=o,this._contextService=s,this._uiPartsService=a,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET).pipe(V.takeUntil(this.dispose$)).subscribe(t=>this._create(t)),this._univerInstanceService.getTypeOfUnitDisposed$(m.UniverInstanceType.UNIVER_SHEET).pipe(V.takeUntil(this.dispose$)).subscribe(t=>this._dispose(t)),this._univerInstanceService.getAllUnitsForType(m.UniverInstanceType.UNIVER_SHEET).forEach(t=>this._create(t)),this._uiPartsService.registerComponent(G.BuiltInUIPart.CONTENT,()=>m.connectInjector(Je,this._injector))}_dispose(t){const e=t.getUnitId();this._renderManagerService.removeRender(e)}_create(t){if(!t)return;const e=t.getUnitId();this._renderManagerService.has(e)&&!this._initImagePopupMenu.has(e)&&(this._popupMenuListener(e),this._initImagePopupMenu.add(e))}_hasCropObject(t){const e=t.getAllObjects();for(const n of e)if(n instanceof Z.ImageCropperObject)return!0;return!1}_popupMenuListener(t){var o;const e=(o=this._renderManagerService.getRenderById(t))==null?void 0:o.scene;if(!e)return;const n=e.getTransformerByCreate();if(!n)return;let r;this.disposeWithMe(m.toDisposable(n.createControl$.subscribe(()=>{if(this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(e))return;const s=n.getSelectedObjectMap();if(s.size>1){r==null||r.dispose();return}const a=s.values().next().value;if(!a)return;const d=a.oKey,u=this._drawingManagerService.getDrawingOKey(d);if(!u)return;const{unitId:l,subUnitId:c,drawingId:g}=u;r==null||r.dispose(),r=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:Z.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(l,c,g)}})),this._drawingManagerService.focusDrawing([{unitId:l,subUnitId:c,drawingId:g}])}))),this.disposeWithMe(n.clearControl$.subscribe(()=>{r==null||r.dispose(),this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(n.changing$.subscribe(()=>{r==null||r.dispose()}))}_getImageMenuItems(t,e,n){return[{label:"image-popup.edit",index:0,commandId:Me.id,commandParams:{unitId:t,subUnitId:e,drawingId:n},disable:!1},{label:"image-popup.delete",index:1,commandId:ve.id,commandParams:{unitId:t,drawings:[{unitId:t,subUnitId:e,drawingId:n}]},disable:!1},{label:"image-popup.crop",index:2,commandId:Z.OpenImageCropOperation.id,commandParams:{unitId:t,subUnitId:e,drawingId:n},disable:!1},{label:"image-popup.reset",index:3,commandId:Z.ImageResetSizeOperation.id,commandParams:[{unitId:t,subUnitId:e,drawingId:n}],disable:!1}]}};ge=et([m.OnLifecycle(m.LifecycleStages.Steady,ge),J(0,m.Inject(m.Injector)),J(1,P.IDrawingManagerService),J(2,m.Inject(W.SheetCanvasPopManagerService)),J(3,N.IRenderManagerService),J(4,m.IUniverInstanceService),J(5,m.IContextService),J(6,m.Inject(G.IUIPartsService))],ge);const se={id:"sheet.operation.insert-float-image",type:m.CommandType.OPERATION,handler:(i,t)=>!0},oe={id:"sheet.operation.insert-cell-image",type:m.CommandType.OPERATION,handler:(i,t)=>!0},_e={id:"sheet.command.insert-sheet-image",type:m.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(m.ICommandService),n=i.get(m.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!t)return!1;const o=t.drawings,s=o.map(w=>w.unitId),a=r.getBatchAddOp(o),{unitId:d,subUnitId:u,undo:l,redo:c,objects:g}=a;return e.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:c,unitId:d,subUnitId:u,objects:g,type:p.DrawingApplyType.INSERT})?(n.pushUndoRedo({unitID:d,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:l,unitId:d,subUnitId:u,objects:g,type:p.DrawingApplyType.REMOVE}},{id:B.id,params:s}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:c,unitId:d,subUnitId:u,objects:g,type:p.DrawingApplyType.INSERT}},{id:B.id,params:s}]}),!0):!1}},ae={id:"sheet.command.set-sheet-image",type:m.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(m.ICommandService),n=i.get(m.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!t)return!1;const{drawings:o}=t,s=r.getBatchUpdateOp(o),{unitId:a,subUnitId:d,undo:u,redo:l,objects:c}=s;return e.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:a,subUnitId:d,op:l,objects:c,type:p.DrawingApplyType.UPDATE})?(n.pushUndoRedo({unitID:a,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:u,objects:c,type:p.DrawingApplyType.UPDATE}},{id:B.id,params:[a]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:l,objects:c,type:p.DrawingApplyType.UPDATE}},{id:B.id,params:[a]}]}),!0):!1}},Re={id:"sheet.command.set-drawing-arrange",type:m.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(m.ICommandService),n=i.get(m.IUndoRedoService);if(!t)return!1;const r=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:a,arrangeType:d}=t,u={unitId:o,subUnitId:s,drawingIds:a};let l;if(d===P.ArrangeTypeEnum.forward?l=r.getForwardDrawingsOp(u):d===P.ArrangeTypeEnum.backward?l=r.getBackwardDrawingOp(u):d===P.ArrangeTypeEnum.front?l=r.getFrontDrawingsOp(u):d===P.ArrangeTypeEnum.back&&(l=r.getBackDrawingsOp(u)),l==null)return!1;const{objects:c,redo:g,undo:h}=l;return e.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:g,unitId:o,subUnitId:s,objects:c,type:p.DrawingApplyType.ARRANGE})?(n.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:g,unitId:o,subUnitId:s,objects:c,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}};function tt(i){const t=[];return i.forEach(e=>{const{parent:n,children:r}=e,{unitId:o,subUnitId:s,drawingId:a}=n,d=N.getGroupState(0,0,r.map(c=>c.transform||{})),u=r.map(c=>{const g=c.transform||{left:0,top:0},{unitId:h,subUnitId:w,drawingId:f}=c;return{unitId:h,subUnitId:w,drawingId:f,transform:{...g,left:g.left-d.left,top:g.top-d.top},groupId:a}}),l={unitId:o,subUnitId:s,drawingId:a,drawingType:P.DrawingTypeEnum.DRAWING_GROUP,transform:d};t.push({parent:l,children:u})}),t}function nt(i){const t=[];return i.forEach(e=>{const{parent:n,children:r}=e,{unitId:o,subUnitId:s,drawingId:a,transform:d={width:0,height:0}}=n;if(d==null)return;const u=r.map(c=>{const{transform:g}=c,{unitId:h,subUnitId:w,drawingId:f}=c,S=N.transformObjectOutOfGroup(g||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:w,drawingId:f,transform:S,groupId:void 0}}),l={unitId:o,subUnitId:s,drawingId:a,drawingType:P.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};t.push({parent:l,children:u})}),t}const Te={id:"sheet.command.group-sheet-image",type:m.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(m.ICommandService),n=i.get(m.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!t)return!1;const o=[];t.forEach(({parent:h,children:w})=>{o.push(h.unitId),w.forEach(f=>{o.push(f.unitId)})});const s=r.getGroupDrawingOp(t),{unitId:a,subUnitId:d,undo:u,redo:l,objects:c}=s;return e.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:l,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.GROUP})?(n.pushUndoRedo({unitID:a,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:nt(c),type:p.DrawingApplyType.UNGROUP}},{id:B.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:l,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.GROUP}},{id:B.id,params:o}]}),!0):!1}},Ee={id:"sheet.command.ungroup-sheet-image",type:m.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(m.ICommandService),n=i.get(m.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!t)return!1;const o=[];t.forEach(({parent:h,children:w})=>{o.push(h.unitId),w.forEach(f=>{o.push(f.unitId)})});const s=r.getUngroupDrawingOp(t),{unitId:a,subUnitId:d,undo:u,redo:l,objects:c}=s;return e.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:l,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.UNGROUP})?(n.pushUndoRedo({unitID:a,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:tt(c),type:p.DrawingApplyType.GROUP}},{id:B.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:l,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.UNGROUP}},{id:B.id,params:o}]}),!0):!1}};function k(i,t,e){const{from:n,to:r,flipY:o=!1,flipX:s=!1,angle:a=0,skewX:d=0,skewY:u=0}=i,{column:l,columnOffset:c,row:g,rowOffset:h}=n,{column:w,columnOffset:f,row:S,rowOffset:C}=r,y=e.attachRangeWithCoord({startColumn:l,endColumn:l,startRow:g,endRow:g});if(y==null)return;const D=e.attachRangeWithCoord({startColumn:w,endColumn:w,startRow:S,endRow:S});if(D==null)return;const{startX:R,startY:I}=y,{startX:b,startY:v}=D;let A=N.precisionTo(R+c,1),T=N.precisionTo(I+h,1),L=N.precisionTo(b+f-A,1),O=N.precisionTo(v+C-T,1);y.startX===D.endX&&(L=0),y.startY===D.endY&&(O=0);const E=e.getCurrentSkeleton(),M=E.rowHeaderWidth+E.columnTotalWidth,j=E.columnHeaderHeight+E.rowTotalHeight;return A+L>M&&(A=M-L),T+O>j&&(T=j-O),{flipY:o,flipX:s,angle:a,skewX:d,skewY:u,left:A,top:T,width:L,height:O}}function $(i,t){const{left:e=0,top:n=0,width:r=0,height:o=0,flipY:s=!1,flipX:a=!1,angle:d=0,skewX:u=0,skewY:l=0}=i,c=t.getSelectionCellByPosition(e,n);if(c==null)return;const g={column:c.actualColumn,columnOffset:N.precisionTo(e-c.startX,1),row:c.actualRow,rowOffset:N.precisionTo(n-c.startY,1)},h=t.getSelectionCellByPosition(e+r,n+o);if(h==null)return;const w={column:h.actualColumn,columnOffset:N.precisionTo(e+r-h.startX,1),row:h.actualRow,rowOffset:N.precisionTo(n+o-h.startY,1)};return{flipY:s,flipX:a,angle:d,skewX:u,skewY:l,from:g,to:w}}var rt=Object.defineProperty,it=Object.getOwnPropertyDescriptor,ot=(i,t,e,n)=>{for(var r=n>1?void 0:n?it(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&rt(t,e,r),r},X=(i,t)=>(e,n)=>t(e,n,i);let he=class extends m.Disposable{constructor(i,t,e,n,r,o,s,a,d,u){super(),this._commandService=i,this._univerInstanceService=t,this._selectionManagerService=e,this._imageIoService=n,this._sheetDrawingService=r,this._drawingManagerService=o,this._contextService=s,this._messageService=a,this._localeService=d,this._renderManagerService=u,this._init()}get _selectionRenderService(){return this._renderManagerService.getRenderById(this._univerInstanceService.getCurrentUnitForType(m.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(W.ISheetSelectionRenderService)}get _skeletonManagerService(){return this._renderManagerService.getRenderById(this._univerInstanceService.getCurrentUnitForType(m.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(W.SheetSkeletonManagerService)}_init(){this._initCommandListeners(),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener(),this._drawingAddListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async i=>{if(i.id===oe.id||i.id===se.id){const t=i.params;if(t.files==null)return;const e=t.files.length;if(e>P.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(P.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(e),i.id===oe.id?t.files.forEach(async n=>{await this._insertCellImage(n)}):t.files.forEach(async n=>{await this._insertFloatImage(n)})}}))}async _insertCellImage(i){}async _insertFloatImage(i){let t;try{t=await this._imageIoService.saveImage(i)}catch(y){const D=y.message;D===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):D===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:z.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):D===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:z.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(t==null)return;const e=this._getUnitInfo();if(e==null)return;const{unitId:n,subUnitId:r}=e,{imageId:o,imageSourceType:s,source:a,base64Cache:d}=t,{width:u,height:l,image:c}=await P.getImageSize(d||""),g=this._renderManagerService.getRenderById(n);if(g==null)return;const{width:h,height:w}=g.scene;this._imageIoService.addImageSourceCache(a,s,c);let f=1;if(u>P.DRAWING_IMAGE_WIDTH_LIMIT||l>P.DRAWING_IMAGE_HEIGHT_LIMIT){const y=P.DRAWING_IMAGE_WIDTH_LIMIT/u,D=P.DRAWING_IMAGE_HEIGHT_LIMIT/l;f=Math.max(y,D)}const S=this._getImagePosition(u*f,l*f,h,w);if(S==null)return;const C={unitId:n,subUnitId:r,drawingId:o,drawingType:P.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:k(S,this._selectionRenderService,this._skeletonManagerService),sheetTransform:S};this._commandService.executeCommand(_e.id,{unitId:n,drawings:[C]})}_getUnitInfo(){const i=this._univerInstanceService.getCurrentUnitForType(m.UniverInstanceType.UNIVER_SHEET);if(i==null)return;const t=i.getActiveSheet();if(t==null)return;const e=i.getUnitId(),n=t.getSheetId();return{unitId:e,subUnitId:n}}_getImagePosition(i,t,e,n){const r=this._selectionManagerService.getCurrentSelections();let o={startRow:0,endRow:0,startColumn:0,endColumn:0};r&&r.length>0&&(o=r[r.length-1].range);const s=W.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,o);if(s==null)return;let{startColumn:a,startRow:d,startX:u,startY:l}=s,c=!1;if(u+i>e&&(u=e-i,u<0&&(u=0,i=e),c=!0),l+t>n&&(l=n-t,l<0&&(l=0,t=n),c=!0),c){const f=this._selectionRenderService.getSelectionCellByPosition(u,l);if(f==null)return;u=f.startX,l=f.startY,a=f.actualColumn,d=f.actualRow}const g={column:a,columnOffset:0,row:d,rowOffset:0},h=this._selectionRenderService.getSelectionCellByPosition(u+i,l+t);if(h==null)return;const w={column:h.actualColumn,columnOffset:u+i-h.startX,row:h.actualRow,rowOffset:l+t-h.startY};return{from:g,to:w}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(i=>{const{unitId:t,subUnitId:e,drawingIds:n,arrangeType:r}=i;this._commandService.executeCommand(Re.id,{unitId:t,subUnitId:e,drawingIds:n,arrangeType:r})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(i=>{const t=[];i.length!==0&&(i.forEach(e=>{const{unitId:n,subUnitId:r,drawingId:o,drawingType:s,transform:a}=e;if(a==null)return;const d=this._sheetDrawingService.getDrawingByParam({unitId:n,subUnitId:r,drawingId:o});if(d==null)return;const u=$({...d.transform,...a},this._selectionRenderService);if(u==null)return;const l={...e,transform:{...d.transform,...a,...k(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};t.push(l)}),t.length>0&&this._commandService.executeCommand(ae.id,{unitId:i[0].unitId,drawings:t}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(i=>{this._commandService.executeCommand(Te.id,i);const{unitId:t,subUnitId:e,drawingId:n}=i[0].parent;this._drawingManagerService.focusDrawing([{unitId:t,subUnitId:e,drawingId:n}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(i=>{this._commandService.executeCommand(Ee.id,i)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(i=>{i==null||i.length===0?(this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(i))}))}_drawingAddListener(){this.disposeWithMe(this._sheetDrawingService.add$.subscribe(i=>{this._registerDrawing(i)}))}_registerDrawing(i){i.forEach(e=>{const n=this._sheetDrawingService.getDrawingByParam(e);if(n==null)return;const{sheetTransform:r}=n;n.transform=k(r,this._selectionRenderService,this._skeletonManagerService)});const t=i[0].unitId;this._drawingManagerService.registerDrawingData(t,this._sheetDrawingService.getDrawingDataForUnit(t)),this._drawingManagerService.initializeNotification(t)}};he=ot([m.OnLifecycle(m.LifecycleStages.Rendered,he),X(0,m.ICommandService),X(1,m.IUniverInstanceService),X(2,m.Inject(_.SheetsSelectionsService)),X(3,P.IImageIoService),X(4,p.ISheetDrawingService),X(5,P.IDrawingManagerService),X(6,m.IContextService),X(7,G.IMessageService),X(8,m.Inject(m.LocaleService)),X(9,N.IRenderManagerService)],he);var x=function(){return x=Object.assign||function(i){for(var t,e=1,n=arguments.length;e<n;e++){t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(i[r]=t[r])}return i},x.apply(this,arguments)},st=function(i,t){var e={};for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&t.indexOf(n)<0&&(e[n]=i[n]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,n=Object.getOwnPropertySymbols(i);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(i,n[r])&&(e[n[r]]=i[n[r]]);return e},je=U.forwardRef(function(i,t){var e=i.icon,n=i.id,r=i.className,o=i.extend,s=st(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(n," ").concat(r||"").trim(),d=U.useRef("_".concat(dt()));return We(e,"".concat(n),{defIds:e.defIds,idSuffix:d.current},x({ref:t,className:a},s),o)});function We(i,t,e,n,r){return U.createElement(i.tag,x(x({key:t},at(i,e,r)),n),(ct(i,e).children||[]).map(function(o,s){return We(o,"".concat(t,"-").concat(i.tag,"-").concat(s),e,void 0,r)}))}function at(i,t,e){var n=x({},i.attrs);e!=null&&e.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=e.colorChannel1);var r=t.defIds;return!r||r.length===0||(i.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(o){var s=o[0],a=o[1];typeof a=="string"&&(n[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function ct(i,t){var e,n=t.defIds;return!n||n.length===0?i:i.tag==="defs"&&(!((e=i.children)===null||e===void 0)&&e.length)?x(x({},i),{children:i.children.map(function(r){return typeof r.attrs.id=="string"&&n&&n.indexOf(r.attrs.id)>-1?x(x({},r),{attrs:x(x({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):i}function dt(){return Math.random().toString(36).substring(2,8)}je.displayName="UniverIcon";var lt={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"}}]},Be=U.forwardRef(function(i,t){return U.createElement(je,Object.assign({},i,{id:"add-image-single",ref:t,icon:lt}))});Be.displayName="AddImageSingle";const ut="univer-upload-file-menu",gt="univer-upload-file-menu-input",Ne={uploadFileMenu:ut,uploadFileMenuInput:gt},$e="COMPONENT_UPLOAD_FILE_MENU";var Se=(i=>(i[i.cellImage=0]="cellImage",i[i.floatImage=1]="floatImage",i))(Se||{});const ht=i=>{const{type:t}=i,e=m.useDependency(m.ICommandService),n=U.useRef(null),r=()=>{var a;(a=n.current)==null||a.click()},o=P.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(a=>`.${a.replace("image/","")}`).join(","),s=a=>{const d=a.target.files;if(d==null)return;const u=Array.from(d);t===Se.floatImage?e.executeCommand(se.id,{files:u}):t===Se.cellImage&&e.executeCommand(oe.id,{files:u}),n.current&&(n.current.value="")};return U.createElement("div",{onClick:r,className:Ne.uploadFileMenu},U.createElement("input",{type:"file",className:Ne.uploadFileMenuInput,ref:n,onChange:s,accept:o,multiple:!0}))},Ge="addition-and-subtraction-single",Ve="sheet.menu.image";function mt(i){return{id:Ve,type:G.MenuItemType.SUBITEMS,positions:[G.MenuPosition.TOOLBAR_START],group:G.MenuGroup.TOOLBAR_FORMULAS_INSERT,icon:Ge,tooltip:"sheetImage.title",hidden$:G.getMenuHiddenObservable(i,m.UniverInstanceType.UNIVER_SHEET),disabled$:W.getCurrentRangeDisable$(i,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function pt(i){return{id:se.id,title:"sheetImage.upload.float",type:G.MenuItemType.SELECTOR,label:{name:$e,props:{type:Se.floatImage}},positions:[Ve],hidden$:G.getMenuHiddenObservable(i,m.UniverInstanceType.UNIVER_SHEET)}}const ft="univer-image-common-panel",wt="univer-image-common-panel-grid",St="univer-image-common-panel-border",vt="univer-image-common-panel-title",_t="univer-image-common-panel-subtitle",It="univer-image-common-panel-row",Dt="univer-image-common-panel-row-vertical",Ct="univer-image-common-panel-column",yt="univer-image-common-panel-column-center",Mt="univer-image-common-panel-inline",Rt="univer-image-common-panel-span2",Tt="univer-image-common-panel-span3",Et="univer-image-common-panel-input",bt="univer-sheet-image-menu",Ot="univer-sheet-image-menu-input",K={imageCommonPanel:ft,imageCommonPanelGrid:wt,imageCommonPanelBorder:St,imageCommonPanelTitle:vt,imageCommonPanelSubtitle:_t,imageCommonPanelRow:It,imageCommonPanelRowVertical:Dt,imageCommonPanelColumn:Ct,imageCommonPanelColumnCenter:yt,imageCommonPanelInline:Mt,imageCommonPanelSpan2:Rt,imageCommonPanelSpan3:Tt,imageCommonPanelInput:Et,sheetImageMenu:bt,sheetImageMenuInput:Ot},Pt=i=>{var D;const t=m.useDependency(m.ICommandService),e=m.useDependency(m.LocaleService),n=m.useDependency(P.IDrawingManagerService),r=m.useDependency(N.IRenderManagerService),{drawings:o}=i,s=o[0];if(s==null)return;const{unitId:a}=s,d=r.getRenderById(a),u=d==null?void 0:d.scene;if(u==null)return;const l=u.getTransformerByCreate(),[c,g]=U.useState(!0),h=(D=s.anchorType)!=null?D:p.SheetDrawingAnchorType.Position,[w,f]=U.useState(h);function S(R,I){const b=[];return R.forEach(v=>{const{oKey:A}=v,T=I.getDrawingOKey(A);if(T==null)return b.push(null),!0;const{unitId:L,subUnitId:O,drawingId:E,drawingType:M,anchorType:j,sheetTransform:F}=T;b.push({unitId:L,subUnitId:O,drawingId:E,anchorType:j,sheetTransform:F,drawingType:M})}),b}U.useEffect(()=>{const R=l.clearControl$.subscribe(b=>{b===!0&&g(!1)}),I=l.changeStart$.subscribe(b=>{var T;const{objects:v}=b,A=S(v,n);if(A.length===0)g(!1);else if(A.length>=1){g(!0);const L=((T=A[0])==null?void 0:T.anchorType)||p.SheetDrawingAnchorType.Position;f(L)}});return()=>{I.unsubscribe(),R.unsubscribe()}},[]);function C(R){f(R);const I=n.getFocusDrawings();if(I.length===0)return;const b=I.map(v=>({unitId:v.unitId,subUnitId:v.subUnitId,drawingId:v.drawingId,anchorType:R}));t.executeCommand(ae.id,{unitId:I[0].unitId,drawings:b})}const y=R=>R?"block":"none";return U.createElement("div",{className:de(K.imageCommonPanelGrid,K.imageCommonPanelBorder),style:{display:y(c)}},U.createElement("div",{className:K.imageCommonPanelRow},U.createElement("div",{className:de(K.imageCommonPanelColumn,K.imageCommonPanelTitle)},U.createElement("div",null,e.t("drawing-anchor.title")))),U.createElement("div",{className:de(K.imageCommonPanelRow)},U.createElement("div",{className:de(K.imageCommonPanelColumn)},U.createElement(z.RadioGroup,{value:w,onChange:C,direction:"vertical"},U.createElement(z.Radio,{value:p.SheetDrawingAnchorType.Both},e.t("drawing-anchor.both")),U.createElement(z.Radio,{value:p.SheetDrawingAnchorType.Position},e.t("drawing-anchor.position")),U.createElement(z.Radio,{value:p.SheetDrawingAnchorType.None},e.t("drawing-anchor.none"))))))},At=()=>{const i=m.useDependency(P.IDrawingManagerService),t=i.getFocusDrawings(),[e,n]=U.useState(t);return U.useEffect(()=>{const r=i.focus$.subscribe(o=>{n(o)});return()=>{r.unsubscribe()}},[]),!!(e!=null&&e.length)&&U.createElement("div",{className:K.imageCommonPanel},U.createElement(Z.DrawingCommonPanel,{drawings:e}),U.createElement(Pt,{drawings:e}))},te={id:"sheet.command.move-drawing",type:m.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(m.ICommandService),n=i.get(p.ISheetDrawingService),r=i.get(W.ISheetSelectionRenderService),{direction:o}=t,s=n.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,d=s.map(l=>{const{transform:c}=l;if(c==null)return null;const g={...c},{left:h=0,top:w=0}=c;return o===m.Direction.UP?g.top=w-1:o===m.Direction.DOWN?g.top=w+1:o===m.Direction.LEFT?g.left=h-1:o===m.Direction.RIGHT&&(g.left=h+1),{...l,transform:g,sheetTransform:$(g,r)}}).filter(l=>l!=null);return e.syncExecuteCommand(ae.id,{unitId:a,drawings:d})?(e.syncExecuteCommand(B.id,[a]),!0):!1}},be={id:"sheet.command.delete-drawing",type:m.CommandType.COMMAND,handler:i=>{const t=i.get(m.ICommandService),n=i.get(p.ISheetDrawingService).getFocusDrawings();if(n.length===0)return!1;const r=n[0].unitId,o=n.map(s=>{const{unitId:a,subUnitId:d,drawingId:u,drawingType:l}=s;return{unitId:a,subUnitId:d,drawingId:u,drawingType:l}});return t.executeCommand(ve.id,{unitId:r,drawings:o})}};function ce(i){return!i.getContextValue(m.FOCUSING_FORMULA_EDITOR)&&!i.getContextValue(m.EDITOR_ACTIVATED)&&i.getContextValue(m.FOCUSING_COMMON_DRAWINGS)}const Ut={id:te.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_DOWN,priority:100,preconditions:ce,staticParameters:{direction:m.Direction.DOWN}},Nt={id:te.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_UP,priority:100,preconditions:ce,staticParameters:{direction:m.Direction.UP}},Lt={id:te.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_LEFT,priority:100,preconditions:ce,staticParameters:{direction:m.Direction.LEFT}},jt={id:te.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_RIGHT,priority:100,preconditions:ce,staticParameters:{direction:m.Direction.RIGHT}},Wt={id:be.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:ce,binding:G.KeyCode.DELETE,mac:G.KeyCode.BACKSPACE};var Bt=Object.defineProperty,$t=Object.getOwnPropertyDescriptor,Gt=(i,t,e,n)=>{for(var r=n>1?void 0:n?$t(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&Bt(t,e,r),r},ne=(i,t)=>(e,n)=>t(e,n,i);const Vt={};let ie=class extends m.Disposable{constructor(i,t,e,n,r,o){super(),this._config=i,this._injector=t,this._componentManager=e,this._menuService=n,this._commandService=r,this._shortcutService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Ge,Be)),this.disposeWithMe(i.register($e,ht)),this.disposeWithMe(i.register(Le,At))}_initMenus(){const{menu:i={}}=this._config;[mt,pt].forEach(t=>{this._menuService.addMenuItem(t(this._injector),i)})}_initCommands(){[se,oe,_e,ve,ae,ye,B,Me,Te,Ee,te,be,Re].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[Ut,Nt,Lt,jt,Wt].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};ie=Gt([m.OnLifecycle(m.LifecycleStages.Rendered,ie),ne(1,m.Inject(m.Injector)),ne(2,m.Inject(G.ComponentManager)),ne(3,G.IMenuService),ne(4,m.ICommandService),ne(5,G.IShortcutService)],ie);var Ft=Object.defineProperty,kt=Object.getOwnPropertyDescriptor,Ht=(i,t,e,n)=>{for(var r=n>1?void 0:n?kt(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&Ft(t,e,r),r},Q=(i,t)=>(e,n)=>t(e,n,i);const xt=[_.InsertRowCommand.id,_.InsertColCommand.id,_.RemoveRowCommand.id,_.RemoveColCommand.id,_.DeleteRangeMoveLeftCommand.id,_.DeleteRangeMoveUpCommand.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id,_.DeltaRowHeightCommand.id,_.SetRowHeightCommand.id,_.DeltaColumnWidthCommand.id,_.SetColWidthCommand.id,_.SetRowHiddenCommand.id,_.SetSpecificRowsVisibleCommand.id,_.SetSpecificColsVisibleCommand.id,_.SetColHiddenCommand.id],Yt=[_.SetRowVisibleMutation.id,_.SetRowHiddenMutation.id,_.SetColVisibleMutation.id,_.SetColHiddenMutation.id,_.SetWorksheetRowHeightMutation.id,_.SetWorksheetColWidthMutation.id];let me=class extends m.Disposable{constructor(i,t,e,n,r,o){super(),this._commandService=i,this._sheetInterceptorService=t,this._renderManagerService=e,this._sheetDrawingService=n,this._drawingManagerService=r,this._univerInstanceService=o,this._init()}get _selectionRenderService(){return this._renderManagerService.getRenderById(this._univerInstanceService.getCurrentUnitForType(m.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(W.ISheetSelectionRenderService)}get _skeletonManagerService(){return this._renderManagerService.getRenderById(this._univerInstanceService.getCurrentUnitForType(m.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(W.SheetSkeletonManagerService)}_init(){this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!xt.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const t=i.id;if(t===_.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if(t===_.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(t===_.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(t===_.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(t===_.DeleteRangeMoveLeftCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,0)}else if(t===_.DeleteRangeMoveUpCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,1)}else if(t===_.InsertRangeMoveDownCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,2)}else if(t===_.InsertRangeMoveRightCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,3)}else if(t===_.SetRowHiddenCommand.id||t===_.SetSpecificRowsVisibleCommand.id){const e=i.params,{unitId:n,subUnitId:r,ranges:o}=e;return this._getDrawingUndoForRowVisible(n,r,o)}else if(t===_.SetSpecificColsVisibleCommand.id||t===_.SetColHiddenCommand.id){const e=i.params,{unitId:n,subUnitId:r,ranges:o}=e;return this._getDrawingUndoForColVisible(n,r,o)}else if(t===_.DeltaRowHeightCommand.id||t===_.SetRowHeightCommand.id||t===_.DeltaColumnWidthCommand.id||t===_.SetColWidthCommand.id){const e=i.params,{unitId:n,subUnitId:r,ranges:o}=e,s=t===_.DeltaRowHeightCommand.id||t===_.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(n,r,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,t){const e=_.getSheetCommandTarget(this._univerInstanceService);if(e==null)return{redos:[],undos:[]};const n=e.unitId,r=e.subUnitId,o=[],s=[],a=this._sheetDrawingService.getDrawingData(n,r),d=[],u=[];if(Object.keys(a).forEach(l=>{const c=a[l],{updateDrawings:g,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,t,c);d.push(...g),u.push(...h)}),d.length===0&&u.length===0)return{redos:[],undos:[]};if(d.length>0){const l=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:g,objects:h}=l;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:g,objects:h,type:p.DrawingApplyType.UPDATE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:c,objects:h,type:p.DrawingApplyType.UPDATE}})}if(u.length>0){const l=this._sheetDrawingService.getBatchRemoveOp(u),c=l.undo,g=l.redo,h=l.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:g,objects:h,type:p.DrawingApplyType.REMOVE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:c,objects:h,type:p.DrawingApplyType.INSERT}})}return o.push({id:B.id,params:[n]}),s.push({id:B.id,params:[n]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,t,e){const n=[],r=[],{sheetTransform:o,anchorType:s=p.SheetDrawingAnchorType.Position,transform:a,unitId:d,subUnitId:u,drawingId:l}=e,{from:c,to:g}=o,{row:h,column:w}=c,{row:f,column:S}=g;if(o==null||a==null)return{updateDrawings:n,deleteDrawings:r};const{startRow:C,endRow:y,startColumn:D,endColumn:R}=i;let I=null,b=null;if(t===0&&h>=C&&f<=y)if(w>=D&&S<=R)r.push({unitId:d,subUnitId:u,drawingId:l});else{const v=this._shrinkCol(o,a,D,R,s);I=v==null?void 0:v.newSheetTransform,b=v==null?void 0:v.newTransform}else if(t===1&&w>=D&&S<=R)if(h>=C&&f<=y)r.push({unitId:d,subUnitId:u,drawingId:l});else{const v=this._shrinkRow(o,a,C,y,s);I=v==null?void 0:v.newSheetTransform,b=v==null?void 0:v.newTransform}else if(t===2){const v=this._expandRow(o,a,C,y,s);I=v==null?void 0:v.newSheetTransform,b=v==null?void 0:v.newTransform}else if(t===3){const v=this._expandCol(o,a,D,R,s);I=v==null?void 0:v.newSheetTransform,b=v==null?void 0:v.newTransform}if(I!=null&&b!=null){const v=k(I,this._selectionRenderService,this._skeletonManagerService);n.push({...e,sheetTransform:I,transform:v})}return{updateDrawings:n,deleteDrawings:r}}_remainDrawingSize(i,t,e){const n=$({...i},this._selectionRenderService);n!=null&&t.push({...e,sheetTransform:n})}_getDrawingUndoForColVisible(i,t,e){const n=this._drawingManagerService.getDrawingData(i,t),r=[],o=[];if(Object.keys(n).forEach(l=>{const c=n[l],{sheetTransform:g,transform:h,anchorType:w=p.SheetDrawingAnchorType.Position}=c;if(w===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,r,c);else{const{from:f,to:S}=g,{row:C,column:y}=f,{row:D,column:R}=S;for(let I=0;I<e.length;I++){const b=e[I],{startRow:v,endRow:A,startColumn:T,endColumn:L}=b;if(R<T)continue;if(w===p.SheetDrawingAnchorType.Position){let M=null,j=null;if(y>=T&&y<=L){const F=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:L,startRow:f.row,endRow:S.row});if(F==null)return;j={...h,left:F.startX}}if(j!=null&&(M=$(j,this._selectionRenderService),M!=null&&j!=null)){r.push({...c,sheetTransform:M,transform:j});break}this._remainDrawingSize(h,r,c);continue}if(y>=T&&R<=L)continue;let O=null,E=null;if(y>=T&&y<=L){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:L,startRow:f.row,endRow:S.row});if(M==null)return;E={...h,left:(M==null?void 0:M.startX)||0,width:((h==null?void 0:h.width)||0)-M.endX+M.startX}}else if(R>=T&&R<=L){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:T,endColumn:R,startRow:f.row,endRow:S.row});if(M==null)return;E={...h,left:M.startX-((h==null?void 0:h.width)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:T,endColumn:L,startRow:f.row,endRow:S.row});if(M==null)return;if(E={...h,width:((h==null?void 0:h.width)||0)-M.endX+M.startX},O=$(E,this._selectionRenderService),O!=null&&E!=null){o.push({...c,sheetTransform:O,transform:E});break}}if(E!=null&&(O=$(E,this._selectionRenderService)),E!=null&&O!=null){r.push({...c,sheetTransform:O,transform:E});break}else this._remainDrawingSize(h,r,c)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,t,r),d=[],u=[];if(o.length>0){const{redos:l,undos:c}=this._createUndoAndRedoMutation(i,t,o);d.push(...l),u.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:u}}_createUndoAndRedoMutation(i,t,e){const n=this._sheetDrawingService.getBatchUpdateOp(e),{undo:r,redo:o,objects:s}=n,a=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:t,op:o,objects:s,type:p.DrawingApplyType.UPDATE}},{id:B.id,params:[i]}],d=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:t,op:r,objects:s,type:p.DrawingApplyType.UPDATE}},{id:B.id,params:[i]}];return{redos:a,undos:d}}_getDrawingUndoForRowVisible(i,t,e){const n=this._drawingManagerService.getDrawingData(i,t),r=[],o=[];if(Object.keys(n).forEach(l=>{const c=n[l],{sheetTransform:g,transform:h,anchorType:w=p.SheetDrawingAnchorType.Position}=c;if(w===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,r,c);else{const{from:f,to:S}=g,{row:C,column:y}=f,{row:D,column:R}=S;for(let I=0;I<e.length;I++){const b=e[I],{startRow:v,endRow:A,startColumn:T,endColumn:L}=b;if(D<v)continue;if(w===p.SheetDrawingAnchorType.Position){let M=null,j=null;if(C>=v&&C<=A){const F=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:C,endRow:A});if(F==null)return;j={...h,top:F.startY}}if(j!=null&&(M=$(j,this._selectionRenderService),M!=null&&j!=null)){r.push({...c,sheetTransform:M,transform:j});break}this._remainDrawingSize(h,r,c);continue}if(C>=v&&D<=A)continue;let O=null,E=null;if(C>=v&&C<=A){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:C,endRow:A});if(M==null)return;E={...h,top:(M==null?void 0:M.startY)||0,height:((h==null?void 0:h.height)||0)-M.endY+M.startY}}else if(D>=v&&D<=A){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:v,endRow:D});if(M==null)return;E={...h,top:M.startY-((h==null?void 0:h.height)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:v,endRow:A});if(M==null)return;if(E={...h,height:((h==null?void 0:h.height)||0)-M.endY+M.startY},O=$(E,this._selectionRenderService),O!=null&&E!=null){o.push({...c,sheetTransform:O,transform:E});break}}if(E!=null&&(O=$(E,this._selectionRenderService)),E!=null&&O!=null){r.push({...c,sheetTransform:O,transform:E});break}else this._remainDrawingSize(h,r,c)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,t,r),d=[],u=[];if(o.length>0){const{redos:l,undos:c}=this._createUndoAndRedoMutation(i,t,o);d.push(...l),u.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:u}}_getDrawingUndoForRowAndColSize(i,t,e,n){const r=this._drawingManagerService.getDrawingData(i,t),o=[];return Object.keys(r).forEach(s=>{const a=r[s],{sheetTransform:d,transform:u,anchorType:l=p.SheetDrawingAnchorType.Position}=a;if(l===p.SheetDrawingAnchorType.None)this._remainDrawingSize(u,o,a);else{const{from:c,to:g}=d,{row:h,column:w}=c,{row:f,column:S}=g;for(let C=0;C<e.length;C++){const y=e[C],{startRow:D,endRow:R,startColumn:I,endColumn:b}=y;if(f<D||S<I)continue;if(l===p.SheetDrawingAnchorType.Position&&(h<=D&&f>=R||w<=I&&S>=b)){this._remainDrawingSize(u,o,a);continue}const v=k({...d},this._selectionRenderService,this._skeletonManagerService);if(v!=null){o.push({...a,transform:v});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,t,o)}_getUnitIdAndSubUnitId(i,t){let e,n;if(t==="insert")e=i.unitId,n=i.subUnitId;else{const r=_.getSheetCommandTarget(this._univerInstanceService);if(r==null)return;e=r.unitId,n=r.subUnitId}return{unitId:e,subUnitId:n}}_moveRowInterceptor(i,t){const e=this._getUnitIdAndSubUnitId(i,t);if(e==null)return{redos:[],undos:[]};const{unitId:n,subUnitId:r}=e,{range:o}=i,s=o.startRow,a=o.endRow,d=[],u=[],l=this._sheetDrawingService.getDrawingData(n,r),c=[],g=[];if(Object.keys(l).forEach(h=>{const w=l[h],{sheetTransform:f,transform:S,anchorType:C=p.SheetDrawingAnchorType.Position}=w;if(f==null||S==null)return;let y,D;if(t==="insert"){const I=this._expandRow(f,S,s,a,C);y=I==null?void 0:I.newSheetTransform,D=I==null?void 0:I.newTransform}else{const{from:I,to:b}=f,{row:v}=I,{row:A}=b;if(v>=s&&A<=a)g.push({unitId:n,subUnitId:r,drawingId:h});else{const T=this._shrinkRow(f,S,s,a,C);y=T==null?void 0:T.newSheetTransform,D=T==null?void 0:T.newTransform}}if(!y||!D)return;const R={unitId:n,subUnitId:r,drawingId:h,transform:D,sheetTransform:y};c.push(R)}),c.length===0&&g.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:w,redo:f,objects:S}=h;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.UPDATE}}),u.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(g),w=h.undo,f=h.redo,S=h.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.REMOVE}}),u.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.INSERT}})}return d.push({id:B.id,params:[n]}),u.push({id:B.id,params:[n]}),{redos:d,undos:u}}_moveColInterceptor(i,t){const e=this._getUnitIdAndSubUnitId(i,t);if(e==null)return{redos:[],undos:[]};const{unitId:n,subUnitId:r}=e,{range:o}=i,s=o.startColumn,a=o.endColumn,d=[],u=[],l=this._sheetDrawingService.getDrawingData(n,r),c=[],g=[];if(Object.keys(l).forEach(h=>{const w=l[h],{sheetTransform:f,transform:S,anchorType:C=p.SheetDrawingAnchorType.Position}=w;if(f==null||S==null)return;let y,D;if(t==="insert"){const I=this._expandCol(f,S,s,a,C);y=I==null?void 0:I.newSheetTransform,D=I==null?void 0:I.newTransform}else{const{from:I,to:b}=f,{column:v}=I,{column:A}=b;if(v>=s&&A<=a)g.push({unitId:n,subUnitId:r,drawingId:h});else{const T=this._shrinkCol(f,S,s,a,C);y=T==null?void 0:T.newSheetTransform,D=T==null?void 0:T.newTransform}}if(!y||!D)return;const R={unitId:n,subUnitId:r,drawingId:h,transform:D,sheetTransform:y};c.push(R)}),c.length===0&&g.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:w,redo:f,objects:S}=h;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.UPDATE}}),u.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(g),w=h.undo,f=h.redo,S=h.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.REMOVE}}),u.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.INSERT}})}return d.push({id:B.id,params:[n]}),u.push({id:B.id,params:[n]}),{redos:d,undos:u}}_expandCol(i,t,e,n,r=p.SheetDrawingAnchorType.Position){const o=n-e+1,{from:s,to:a}=i,{column:d}=s,{column:u}=a;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};let l=null,c=null;if(d>=e){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:e,endColumn:n,startRow:s.row,endRow:a.row});if(g==null)return;c={...t,left:(t.left||0)+g.endX-g.startX},l=$(c,this._selectionRenderService)}else if(u>=n)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,column:u+o}},c=k(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};return l!=null&&c!=null?{newSheetTransform:l,newTransform:c}:null}_shrinkCol(i,t,e,n,r=p.SheetDrawingAnchorType.Position){const o=n-e+1,{from:s,to:a}=i,{column:d}=s,{column:u}=a;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};let l=null,c=null;if(d>n)l={from:{...s,column:d-o},to:{...a,column:u-o}},c=k(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=e&&u<=n)return null;if(d<e&&u>n)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,column:u-o}},c=k(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};else if(d>=e&&d<=n){if(d===e)c={...t,left:(t.left||0)-i.from.columnOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:e,endColumn:d-1,startRow:s.row,endRow:a.row});if(g==null)return;c={...t,left:(t.left||0)-g.endX+g.startX-i.from.columnOffset}}l=$(c,this._selectionRenderService)}else if(u>=e&&u<=n&&r===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:e-1,endColumn:e-1,startRow:s.row,endRow:a.row});if(g==null)return;l={from:{...s},to:{...a,column:e-1,columnOffset:g.endX-g.startX}},c=k(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&c!=null?{newSheetTransform:l,newTransform:c}:null}_expandRow(i,t,e,n,r=p.SheetDrawingAnchorType.Position){const o=n-e+1,{from:s,to:a}=i,{row:d}=s,{row:u}=a;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};let l=null,c=null;if(d>=e){const g=this._skeletonManagerService.attachRangeWithCoord({startRow:e,endRow:n,startColumn:s.column,endColumn:a.column});if(g==null)return;c={...t,top:(t.top||0)+g.endY-g.startY},l=$(c,this._selectionRenderService)}else if(u>=n)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,row:u+o}},c=k(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};return l!=null&&c!=null?{newSheetTransform:l,newTransform:c}:null}_shrinkRow(i,t,e,n,r=p.SheetDrawingAnchorType.Position){const o=n-e+1,{from:s,to:a}=i,{row:d}=s,{row:u}=a;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};let l=null,c=null;if(d>n)l={from:{...s,row:d-o},to:{...a,row:u-o}},c=k(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=e&&u<=n)return null;if(d<e&&u>n)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,row:u-o}},c=k(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};else if(d>=e&&d<=n){if(d===e)c={...t,top:(t.top||0)-i.from.rowOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startRow:e,endRow:d-1,startColumn:s.column,endColumn:a.column});if(g==null)return;c={...t,top:(t.top||0)-g.endY+g.startY-i.from.rowOffset}}l=$(c,this._selectionRenderService)}else if(u>=e&&u<=n&&r===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:e-1,endRow:e-1});if(g==null)return;l={from:{...s},to:{...a,row:e-1,rowOffset:g.endY-g.startY}},c=k(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&c!=null?{newSheetTransform:l,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===_.SetWorksheetActiveOperation.id&&setTimeout(()=>{const t=i.params,{unitId:e,subUnitId:n}=t,r=this._drawingManagerService.drawingManagerData,o=[],s=[];Object.keys(r).forEach(a=>{const d=r[a];Object.keys(d).forEach(u=>{const l=d[u].data;l!=null&&Object.keys(l).forEach(c=>{if(a===e&&u===n){const g=l[c];g.transform=k(g.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(l[c])}else s.push(l[c])})})}),this._drawingManagerService.removeNotification(s),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Yt.includes(i.id)&&requestIdleCallback(()=>{const t=i.params,{unitId:e,subUnitId:n,ranges:r}=t;this._refreshDrawingTransform(e,n,r)})}))}_refreshDrawingTransform(i,t,e){const n=this._drawingManagerService.getDrawingData(i,t),r=[];Object.keys(n).forEach(o=>{const s=n[o],{sheetTransform:a,anchorType:d=p.SheetDrawingAnchorType.Position}=s;if(d===p.SheetDrawingAnchorType.None)return!0;const{from:u,to:l}=a,{row:c,column:g}=u,{row:h,column:w}=l;for(let f=0;f<e.length;f++){const S=e[f],{startRow:C,endRow:y,startColumn:D,endColumn:R}=S;if(m.Rectangle.intersects({startRow:C,endRow:y,startColumn:D,endColumn:R},{startRow:c,endRow:h,startColumn:g,endColumn:w})||c>y||g>R){r.push({...s,transform:k(a,this._selectionRenderService,this._skeletonManagerService)});break}}}),r.length!==0&&(this._drawingManagerService.refreshTransform(r),this._commandService.syncExecuteCommand(B.id,[i]))}};me=Ht([m.OnLifecycle(m.LifecycleStages.Rendered,me),Q(0,m.ICommandService),Q(1,m.Inject(_.SheetInterceptorService)),Q(2,N.IRenderManagerService),Q(3,p.ISheetDrawingService),Q(4,P.IDrawingManagerService),Q(5,m.IUniverInstanceService)],me);var Xt=Object.defineProperty,Kt=Object.getOwnPropertyDescriptor,zt=(i,t,e,n)=>{for(var r=n>1?void 0:n?Kt(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&Xt(t,e,r),r},ee=(i,t)=>(e,n)=>t(e,n,i);function qt(i,t,e,n){const{scaleX:r,scaleY:o}=t.getAncestorScale(),s=t.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN),a={left:!0,top:!0};if(!s)return{...i,absolute:a};const{left:d,right:u,top:l,bottom:c}=i,g=n.getFreeze(),{startColumn:h,startRow:w,xSplit:f,ySplit:S}=g,C=e.getNoMergeCellPositionByIndexWithNoHeader(w-S,h-f),y=e.getNoMergeCellPositionByIndexWithNoHeader(w,h),{rowHeaderWidth:D,columnHeaderHeight:R}=e,I=y.startX-C.startX,b=y.startY-C.startY,{top:v,left:A,viewportScrollX:T,viewportScrollY:L}=s;let O,E;d<A?(a.left=!0,O=(I+D+(d-A))*r,E=Math.max(Math.min((I+D+(u-A))*r,(I+D)*r),(u-T)*r)):(a.left=!1,O=Math.max((d-T)*r,(I+D)*r),E=Math.max((u-T)*r,(I+D)*r));let M,j;return l<v?(a.top=!0,M=(b+R+(l-v))*o,j=Math.max(Math.min((b+R+(u-v))*o,(b+R)*o),(c-L)*o)):(a.top=!1,M=Math.max((l-L)*o,(b+R)*o),j=Math.max((c-L)*o,(b+R)*o)),{left:O,right:E,top:M,bottom:j,absolute:a}}const Ie=(i,t,e,n)=>{const{scene:r}=t,{left:o,top:s,width:a,height:d,angle:u}=i,l={left:o,right:o+a,top:s,bottom:s+d},c=qt(l,r,e,n);return{startX:c.left,endX:c.right,startY:c.top,endY:c.bottom,rotate:u,width:a,height:d,absolute:c.absolute}};exports.SheetCanvasFloatDomManagerService=class extends m.Disposable{constructor(e,n,r,o,s,a){super();Y(this,"_domLayerMap",new Map);Y(this,"_domLayerInfoMap",new Map);Y(this,"_transformChange$",new V.Subject);Y(this,"transformChange$",this._transformChange$.asObservable());Y(this,"_remove$",new V.Subject);Y(this,"remove$",this._remove$.asObservable());Y(this,"_hooks",[]);this._renderManagerService=e,this._univerInstanceService=n,this._commandService=r,this._drawingManagerService=o,this._canvasFloatDomService=s,this._sheetDrawingService=a,this._drawingAddListener(),this._scrollUpdateListener(),this._featureUpdateListener(),this._deleteListener()}_ensureMap(e,n){let r=this._domLayerMap.get(e);r||(r=new Map,this._domLayerMap.set(e,r));let o=r.get(n);return o||(o=new Map,r.set(n,o)),o}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;const n=this._renderManagerService.getRenderById(e),r=n==null?void 0:n.scene;if(n==null||r==null)return null;const o=r.getTransformerByCreate(),s=n.engine.getCanvasElement();return{scene:r,transformer:o,renderObject:n,canvas:s}}_getFloatDomProps(e){let n;return this._hooks.forEach(r=>{n=r.onGetFloatDomProps(e)}),n}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(n=>{var Pe,Ae,Ue;const{unitId:r,subUnitId:o,drawingId:s}=n,a=_.getSheetCommandTarget(this._univerInstanceService,{unitId:r,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(n),u=(Pe=this._renderManagerService.getRenderById(r))==null?void 0:Pe.with(W.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(d==null||a==null||u==null)return;const{transform:l,drawingType:c}=d;if(c!==m.DrawingTypeEnum.DRAWING_DOM)return;const g=this._getSceneAndTransformerByDrawingSearch(r);if(g==null)return;const{scene:h,canvas:w}=g;if(l==null)return!0;const{left:f,top:S,width:C,height:y,angle:D,flipX:R,flipY:I,skewX:b,skewY:v}=l,A=P.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:o,drawingId:s}),T=h.getObject(A);if(T!=null){T.transformByState({left:f,top:S,width:C,height:y,angle:D,flipX:R,flipY:I,skewX:b,skewY:v});return}const L={left:f,top:S,width:C,height:y,zIndex:this._drawingManagerService.getDrawingOrder(r,o).length-1},O=new N.Rect(A,L);h.addObject(O,N.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(O);const E=this._ensureMap(r,o),M=new m.DisposableCollection,j=Ie(O,g.renderObject,u.skeleton,a.worksheet),F=new V.BehaviorSubject(j),q={dispose:M,rect:O,position$:F,unitId:r,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:F,id:s,componentKey:d.componentKey,onPointerDown:H=>{w.dispatchEvent(new PointerEvent(H.type,H))},onPointerMove:H=>{w.dispatchEvent(new PointerEvent(H.type,H))},onPointerUp:H=>{w.dispatchEvent(new PointerEvent(H.type,H))},onWheel:H=>{w.dispatchEvent(new WheelEvent(H.type,H))},props:(Ue=(Ae=E.get(s))==null?void 0:Ae.props)!=null?Ue:this._getFloatDomProps(s)});const Oe=O.onTransformChange$.subscribeEvent(()=>{const H=Ie(O,g.renderObject,u.skeleton,a.worksheet);F.next(H)});M.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),Oe&&M.add(Oe),this._domLayerInfoMap.set(s,q)})}))}_scrollUpdateListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var r,o;const n=(s,a)=>{var h;const d=this._getSceneAndTransformerByDrawingSearch(s),u=this._ensureMap(s,a),l=Array.from(u.keys()),c=_.getSheetCommandTarget(this._univerInstanceService,{unitId:s,subUnitId:a}),g=(h=this._renderManagerService.getRenderById(s))==null?void 0:h.with(W.SheetSkeletonManagerService).getWorksheetSkeleton(a);!d||!c||!g||l.forEach(w=>{const f=this._domLayerInfoMap.get(w);if(f){const S=Ie(f.rect,d.renderObject,g.skeleton,c.worksheet);f.position$.next(S)}})};if(e.id===W.SetScrollOperation.id){const s=e.params,{unitId:a,sheetId:d}=s;n(a,d)}else if(e.id===W.SetZoomRatioOperation.id){const s=e.params,{unitId:a}=s;Array.from((o=(r=this._domLayerMap.get(a))==null?void 0:r.keys())!=null?o:[]).forEach(u=>{n(a,u)})}else if(e.id===_.SetFrozenMutation.id){const{unitId:s,subUnitId:a}=e.params;n(s,a)}}))}_getPosition(e,n){var h;const{startX:r,endX:o,startY:s,endY:a}=e,d=(h=this._renderManagerService.getRenderById(n))==null?void 0:h.with(W.ISheetSelectionRenderService);if(d==null)return;const u=d.getSelectionCellByPosition(r,s);if(u==null)return;const l={column:u.actualColumn,columnOffset:r-u.startX,row:u.actualRow,rowOffset:s-u.startY},c=d.getSelectionCellByPosition(o,a);if(c==null)return;const g={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:a-c.startY};return{from:l,to:g}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(n=>{const r=this._drawingManagerService.getDrawingByParam(n);if(!r||r.drawingType!==m.DrawingTypeEnum.DRAWING_DOM)return;const o={...r.transform};this._transformChange$.next({id:n.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(n=>{this._removeDom(n.drawingId)})}))}addFloatDomToPosition(e){const n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:r,subUnitId:o}=n,{initPosition:s,componentKey:a}=e,d=m.Tools.generateRandomId(),u=this._getPosition(s,r);if(u==null)return;this._ensureMap(r,o).set(d,e);const c={unitId:r,subUnitId:o,drawingId:d,drawingType:m.DrawingTypeEnum.DRAWING_DOM,componentKey:a,sheetTransform:u,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY}};return this._commandService.executeCommand(_e.id,{unitId:r,drawings:[c]}),{id:d,dispose:()=>{this._removeDom(d,!0)}}}_removeDom(e,n=!1){const r=this._domLayerInfoMap.get(e);if(!r)return;const{unitId:o,subUnitId:s}=r;this._domLayerInfoMap.delete(e),r.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(o);if(a&&a.scene.removeObject(r.rect),n){this._ensureMap(o,s).delete(e);const u=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:e});if(!u)return;const l=this._sheetDrawingService.getBatchRemoveOp([u]),{redo:c,objects:g}=l;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:c,objects:g,type:p.DrawingApplyType.REMOVE})}}addHook(e){return this._hooks.push(e),{dispose:()=>{const n=this._hooks.findIndex(r=>r===e);this._hooks.splice(n,1)}}}};exports.SheetCanvasFloatDomManagerService=zt([ee(0,m.Inject(N.IRenderManagerService)),ee(1,m.IUniverInstanceService),ee(2,m.Inject(m.ICommandService)),ee(3,P.IDrawingManagerService),ee(4,m.Inject(G.CanvasFloatDomService)),ee(5,p.ISheetDrawingService)],exports.SheetCanvasFloatDomManagerService);var Jt=Object.defineProperty,Zt=Object.getOwnPropertyDescriptor,Qt=(i,t,e,n)=>{for(var r=n>1?void 0:n?Zt(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&Jt(t,e,r),r},ue=(i,t)=>(e,n)=>t(e,n,i);let pe=class extends m.Disposable{constructor(i,t,e,n){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=t,this._drawingManagerService=e,this._renderManagerService=n,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,t,e)=>{const{unitId:n,scene:r,subUnitId:o}=t,s=this._drawingManagerService.getDrawingDataForUnit(n),a=s==null?void 0:s[o];return a&&a.order.forEach(d=>{this._drawingRenderService.renderDrawing(a.data[d],r)}),e()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,t,e)=>{const{unitId:n,subUnitId:r}=t,o=this._renderManagerService.getRenderById(n);if(!o)return e(i);const s=o.with(W.SheetSkeletonManagerService).getWorksheetSkeleton(r);if(!s)return e(i);const a=this._drawingManagerService.getDrawingDataForUnit(n),d=a==null?void 0:a[t.subUnitId];if(!d)return e(i);const{scaleX:u,scaleY:l}=o.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},g=d.order.map(h=>d.data[h]).filter(h=>h.drawingType!==P.DrawingTypeEnum.DRAWING_DOM);return g.length?(g.forEach(h=>{if(!h.groupId&&h.transform&&m.Tools.isDefine(h.transform.left)&&m.Tools.isDefine(h.transform.top)&&m.Tools.isDefine(h.transform.width)&&m.Tools.isDefine(h.transform.height)){const w=s.skeleton.getCellPositionByOffset(h.transform.left,h.transform.top,u,l,{x:0,y:0}),f=s.skeleton.getCellPositionByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,u,l,{x:0,y:0});w.column<c.startColumn&&(c.startColumn=w.column),w.row<c.startRow&&(c.startRow=w.row),c.endRow<f.row&&(c.endRow=f.row),c.endColumn<f.column&&(c.endColumn=f.column)}}),e(c)):e(i)}}))}};pe=Qt([m.OnLifecycle(m.LifecycleStages.Rendered,pe),ue(0,m.Inject(W.SheetPrintInterceptorService)),ue(1,m.Inject(Z.DrawingRenderService)),ue(2,P.IDrawingManagerService),ue(3,N.IRenderManagerService)],pe);var en=Object.defineProperty,tn=Object.getOwnPropertyDescriptor,nn=(i,t,e,n)=>{for(var r=n>1?void 0:n?tn(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&en(t,e,r),r},re=(i,t)=>(e,n)=>t(e,n,i);let fe=class extends m.Disposable{constructor(i,t,e,n,r){super(),this._drawingManagerService=i,this._renderManagerService=t,this._permissionService=e,this._univerInstanceService=n,this._userManagerService=r,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(V.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([t,e])=>{if(!t){this._drawingManagerService.setDrawingVisible(!1);return}t.activeSheet$.subscribe(n=>{if(!n){this._drawingManagerService.setDrawingVisible(!1);return}const r=t.getUnitId(),o=n.getSheetId();if(this._permissionService.composePermission([new _.WorkbookViewPermission(r).id,new _.WorksheetViewPermission(r,o).id]).every(a=>a.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const a=t.getUnitId(),d=n.getSheetId(),u=this._drawingManagerService.getDrawingData(a,d),l=Object.values(u),c=this._renderManagerService.getRenderById(a),g=c==null?void 0:c.scene;if(g==null)return;g.getAllObjects().forEach(w=>{w.classType===N.RENDER_CLASS_TYPE.IMAGE&&l.some(f=>w.oKey.includes(f.drawingId))&&g.removeObject(w)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(V.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([t,e])=>{if(!t){this._drawingManagerService.setDrawingEditable(!1);return}t.activeSheet$.subscribe(n=>{if(!n){this._drawingManagerService.setDrawingEditable(!1);return}const r=t.getUnitId(),o=n.getSheetId();if(this._permissionService.composePermission([new _.WorkbookEditablePermission(r).id,new _.WorksheetEditPermission(r,o).id]).every(a=>a.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const a=t.getUnitId(),d=n.getSheetId(),u=this._drawingManagerService.getDrawingData(a,d),l=Object.values(u),c=this._renderManagerService.getRenderById(a),g=c==null?void 0:c.scene;if(g==null)return;g.getAllObjects().forEach(w=>{w.classType===N.RENDER_CLASS_TYPE.IMAGE&&l.some(f=>w.oKey.includes(f.drawingId))&&g.detachTransformerFrom(w)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(V.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([t,e])=>{t&&t.activeSheet$.subscribe(n=>{var c;if(!n)return;const r=t.getUnitId(),o=n.getSheetId();let s=!0;const a=this._renderManagerService.getRenderById(r),d=a==null?void 0:a.scene;if(d==null)return;const u=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new _.WorkbookViewPermission(r).id,new _.WorksheetViewPermission(r,o).id]).pipe(V.map(g=>g.every(h=>h.value)));l==null||l.pipe(V.filter(g=>g!==s),V.distinctUntilChanged()).subscribe({next:g=>{s=g,this._drawingManagerService.setDrawingVisible(g);const h=d.getAllObjects(),w=this._drawingManagerService.getDrawingData(r,o),f=Object.values(w);g?this._drawingManagerService.addNotification(f):(h.forEach(S=>{S.classType===N.RENDER_CLASS_TYPE.IMAGE&&f.some(C=>S.oKey.includes(C.drawingId))&&d.removeObject(S)}),u.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(r,o).id))==null||c.pipe(V.filter(g=>g.value!==s),V.distinctUntilChanged()).subscribe({complete:()=>{s=!0,this._drawingManagerService.setDrawingVisible(!0);const g=this._drawingManagerService.getDrawingData(r,o),h=Object.values(g);this._drawingManagerService.addNotification(h)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(V.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([t,e])=>{t&&t.activeSheet$.subscribe(n=>{var c;if(!n)return;const r=t.getUnitId(),o=n.getSheetId();let s=!0;const a=this._renderManagerService.getRenderById(r),d=a==null?void 0:a.scene;if(d==null)return;const u=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new _.WorkbookEditablePermission(r).id,new _.WorksheetEditPermission(r,o).id]).pipe(V.map(g=>g.every(h=>h.value)));l==null||l.pipe(V.filter(g=>g!==s),V.distinctUntilChanged()).subscribe({next:g=>{s=g,this._drawingManagerService.setDrawingEditable(g);const h=d.getAllObjects(),w=this._drawingManagerService.getDrawingData(r,o),f=Object.values(w);g?(h.forEach(S=>{S.classType===N.RENDER_CLASS_TYPE.IMAGE&&f.some(C=>S.oKey.includes(C.drawingId))&&d.attachTransformerTo(S)}),this._drawingManagerService.addNotification(f)):(h.forEach(S=>{S.classType===N.RENDER_CLASS_TYPE.IMAGE&&f.some(C=>S.oKey.includes(C.drawingId))&&d.detachTransformerFrom(S)}),u.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(r,o).id))==null||c.pipe(V.filter(g=>g.value!==s),V.distinctUntilChanged()).subscribe({complete:()=>{s=!0;const g=t.getUnitId(),h=n.getSheetId(),w=this._drawingManagerService.getDrawingData(g,h),f=Object.values(w),S=this._renderManagerService.getRenderById(g),C=S==null?void 0:S.scene;if(C==null)return;this._drawingManagerService.setDrawingEditable(!0),C.getAllObjects().forEach(D=>{D.classType===N.RENDER_CLASS_TYPE.IMAGE&&f.some(R=>D.oKey.includes(R.drawingId))&&C.detachTransformerFrom(D)})}})})}))}};fe=nn([m.OnLifecycle(m.LifecycleStages.Rendered,fe),re(0,P.IDrawingManagerService),re(1,N.IRenderManagerService),re(2,m.IPermissionService),re(3,m.IUniverInstanceService),re(4,m.Inject(m.UserManagerService))],fe);var rn=Object.defineProperty,on=Object.getOwnPropertyDescriptor,sn=(i,t,e,n)=>{for(var r=n>1?void 0:n?on(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&rn(t,e,r),r},De=(i,t)=>(e,n)=>t(e,n,i);let we=class extends m.Disposable{constructor(t,e,n){super();Y(this,"_copyInfo");this._sheetClipboardService=t,this._renderManagerService=e,this._sheetDrawingService=n,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(t,e,n)=>this._collect(t,e,n),onPasteCells:(t,e,n,r)=>{const{copyType:o=W.COPY_TYPE.COPY,pasteType:s}=r,{range:a}=t||{},{range:d,unitId:u,subUnitId:l}=e;return this._generateMutations(d,{copyType:o,pasteType:s,copyRange:a,unitId:u,subUnitId:l})},onPastePlainText:(t,e)=>({undos:[],redos:[]})})}_collect(t,e,n){var g;const r=(g=this._renderManagerService.getRenderById(t))==null?void 0:g.with(W.SheetSkeletonManagerService);if(!r)return;const o=r.attachRangeWithCoord(n);if(!o)return;const{startX:s,endX:a,startY:d,endY:u}=o,l=this._sheetDrawingService.getDrawingData(t,e),c=[];Object.keys(l).forEach(h=>{const w=l[h],{transform:f}=w;if(w.anchorType!==p.SheetDrawingAnchorType.Both||!f)return;const{left:S=0,top:C=0,width:y=0,height:D=0}=f,{drawingStartX:R,drawingEndX:I,drawingStartY:b,drawingEndY:v}={drawingStartX:S,drawingEndX:S+y,drawingStartY:C,drawingEndY:C+D};s<=R&&I<=a&&d<=b&&v<=u&&c.push(w)}),c.length&&(this._copyInfo={drawings:c,unitId:t,subUnitId:e})}_generateMutations(t,e){var T;if(!this._copyInfo)return{redos:[],undos:[]};if([W.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,W.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,W.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,W.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(e.pasteType))return{redos:[],undos:[]};const{copyRange:n}=e;if(!n)return{redos:[],undos:[]};const{drawings:r,unitId:o,subUnitId:s}=this._copyInfo,{ranges:[a,d],mapFunc:u}=W.virtualizeDiscreteRanges([n,t]),{row:l,col:c}=u(a.startRow,a.startColumn),{row:g,col:h}=u(d.startRow,d.startColumn),w=(T=this._renderManagerService.getRenderById(o))==null?void 0:T.with(W.SheetSkeletonManagerService);if(!w)return{redos:[],undos:[]};const f=w.attachRangeWithCoord({startRow:l,endRow:l,startColumn:c,endColumn:c}),S=w.attachRangeWithCoord({startRow:g,endRow:g,startColumn:h,endColumn:h});if(!f||!S)return{redos:[],undos:[]};const C=[],y=[],D=S.startX-f.startX,R=S.startY-f.startY,I=g-l,b=h-c,v=e.copyType===W.COPY_TYPE.CUT,{_sheetDrawingService:A}=this;return r.forEach(L=>{const{transform:O,sheetTransform:E}=L;if(!O)return;const M={...L,unitId:o,subUnitId:s,drawingId:v?L.drawingId:m.Tools.generateRandomId(),transform:{...O,left:O.left+D,top:O.top+R},sheetTransform:{to:{...E.to,row:E.to.row+I,column:E.to.column+b},from:{...E.from,row:E.from.row+I,column:E.from.column+b}}};if(v){const{undo:j,redo:F,objects:q}=A.getBatchUpdateOp([M]);C.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:s,type:p.DrawingApplyType.UPDATE,op:F,objects:q}}),y.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:s,type:p.DrawingApplyType.UPDATE,op:j,objects:q}})}else{const{undo:j,redo:F,objects:q}=A.getBatchAddOp([M]);C.push({id:p.SetDrawingApplyMutation.id,params:{op:F,unitId:o,subUnitId:s,objects:q,type:p.DrawingApplyType.INSERT}}),y.push({id:p.SetDrawingApplyMutation.id,params:{op:j,unitId:o,subUnitId:s,objects:q,type:p.DrawingApplyType.REMOVE}})}}),{redos:C,undos:y}}};we=sn([m.OnLifecycle(m.LifecycleStages.Ready,we),De(0,W.ISheetClipboardService),De(1,N.IRenderManagerService),De(2,p.ISheetDrawingService)],we);var Fe=Object.defineProperty,an=Object.getOwnPropertyDescriptor,cn=(i,t,e)=>t in i?Fe(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,dn=(i,t,e,n)=>{for(var r=n>1?void 0:n?an(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&Fe(t,e,r),r},Ce=(i,t)=>(e,n)=>t(e,n,i),ke=(i,t,e)=>cn(i,typeof t!="symbol"?t+"":t,e);const ln="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends m.Plugin{constructor(e={},n,r,o){super();Y(this,"_pluginConfig");this._injector=n,this._localeService=r,this._renderManagerService=o,this._pluginConfig=m.Tools.deepMerge({},Vt,e)}onStarting(e){super.onStarting(e),this._initDependencies(e)}onRendered(){this._registerRenderModules()}_initDependencies(e){const n=[[exports.SheetCanvasFloatDomManagerService],[ie,{useFactory:()=>this._injector.createInstance(ie,this._pluginConfig)}],[ge],[pe],[fe]],r=[he,me];n.forEach(o=>e.add(o)),r.forEach(o=>this._renderManagerService.registerRenderModule(m.UniverInstanceType.UNIVER_SHEET,o))}_registerRenderModules(){[[we]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(m.UniverInstanceType.UNIVER_SHEET,e))})}};ke(exports.UniverSheetsDrawingUIPlugin,"type",m.UniverInstanceType.UNIVER_SHEET);ke(exports.UniverSheetsDrawingUIPlugin,"pluginName",ln);exports.UniverSheetsDrawingUIPlugin=dn([m.DependentOn(P.UniverDrawingPlugin,Z.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),Ce(1,m.Inject(m.Injector)),Ce(2,m.Inject(m.LocaleService)),Ce(3,N.IRenderManagerService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=B;exports.DeleteDrawingsCommand=be;exports.EditSheetDrawingOperation=Me;exports.GroupSheetDrawingCommand=Te;exports.InsertCellImageOperation=oe;exports.InsertFloatImageOperation=se;exports.InsertSheetDrawingCommand=_e;exports.MoveDrawingsCommand=te;exports.RemoveSheetDrawingCommand=ve;exports.SetDrawingArrangeCommand=Re;exports.SetSheetDrawingCommand=ae;exports.SidebarSheetDrawingOperation=ye;exports.UngroupSheetDrawingCommand=Ee;
1
+ "use strict";var xe=Object.defineProperty;var Ye=(i,t,e)=>t in i?xe(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var Y=(i,t,e)=>Ye(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@univerjs/core"),Z=require("@univerjs/drawing-ui"),p=require("@univerjs/sheets-drawing"),O=require("@univerjs/drawing"),N=require("@univerjs/engine-render"),W=require("@univerjs/sheets-ui"),V=require("rxjs"),G=require("@univerjs/ui"),_=require("@univerjs/sheets"),A=require("react"),q=require("@univerjs/design"),de=require("clsx"),B={id:"sheet.operation.clear-drawing-transformer",type:m.CommandType.MUTATION,handler:(i,t)=>{const e=i.get(N.IRenderManagerService);return t.forEach(n=>{var r,o;(o=(r=e.getRenderById(n))==null?void 0:r.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},ve={id:"sheet.command.remove-sheet-image",type:m.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(m.ICommandService),n=i.get(m.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!t)return!1;const{drawings:o}=t,s=[];o.forEach(w=>{const{unitId:f}=w;s.push(f)});const a=r.getBatchRemoveOp(o),{unitId:d,subUnitId:u,undo:l,redo:c,objects:g}=a;return e.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:d,subUnitId:u,op:c,objects:g,type:p.DrawingApplyType.REMOVE})?(n.pushUndoRedo({unitID:d,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:d,subUnitId:u,op:l,objects:g,type:p.DrawingApplyType.INSERT}},{id:B.id,params:s}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:d,subUnitId:u,op:c,objects:g,type:p.DrawingApplyType.REMOVE}},{id:B.id,params:s}]}),!0):!1}},Le="COMPONENT_SHEET_DRAWING_PANEL",ye={id:"sidebar.operation.sheet-image",type:m.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(G.ISidebarService),n=i.get(m.LocaleService),r=i.get(m.IUniverInstanceService),o=i.get(O.IDrawingManagerService);if(!_.getSheetCommandTarget(r))return!1;switch(t.value){case"open":e.open({header:{title:n.t("sheetImage.panel.title")},children:{label:Le},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:e.close();break}return!0}},Me={id:"sheet.operation.edit-sheet-image",type:m.CommandType.OPERATION,handler:(i,t)=>{const e=i.get(O.IDrawingManagerService),n=i.get(m.ICommandService);return t==null?!1:(e.focusDrawing([t]),n.executeCommand(ye.id,{value:"open"}),!0)}},Xe="univer-upload-loading",Ke="univer-upload-loading-body",ze="univer-upload-loading-body-animation",qe="univer-UniverCircleAnimation",Je="univer-upload-loading-body-text",le={uploadLoading:Xe,uploadLoadingBody:Ke,uploadLoadingBodyAnimation:ze,univerCircleAnimation:qe,uploadLoadingBodyText:Je},Ze=()=>{const i=m.useDependency(O.IImageIoService),t=m.useDependency(m.LocaleService),[e,n]=A.useState(0);return A.useEffect(()=>{const r=i.change$.subscribe(o=>{n(o)});return()=>{r.unsubscribe()}},[i]),A.createElement("div",{style:{display:e>0?"block":"none"},className:le.uploadLoading},A.createElement("div",{className:le.uploadLoadingBody},A.createElement("div",{className:le.uploadLoadingBodyAnimation}),A.createElement("div",{className:le.uploadLoadingBodyText},`${t.t("uploadLoading.loading")}: ${e}`)))};var Qe=Object.defineProperty,et=Object.getOwnPropertyDescriptor,tt=(i,t,e,n)=>{for(var r=n>1?void 0:n?et(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&Qe(t,e,r),r},J=(i,t)=>(e,n)=>t(e,n,i);let ge=class extends m.RxDisposable{constructor(t,e,n,r,o,s,a){super();Y(this,"_initImagePopupMenu",new Set);this._injector=t,this._drawingManagerService=e,this._canvasPopManagerService=n,this._renderManagerService=r,this._univerInstanceService=o,this._contextService=s,this._uiPartsService=a,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET).pipe(V.takeUntil(this.dispose$)).subscribe(t=>this._create(t)),this._univerInstanceService.getTypeOfUnitDisposed$(m.UniverInstanceType.UNIVER_SHEET).pipe(V.takeUntil(this.dispose$)).subscribe(t=>this._dispose(t)),this._univerInstanceService.getAllUnitsForType(m.UniverInstanceType.UNIVER_SHEET).forEach(t=>this._create(t)),this._uiPartsService.registerComponent(G.BuiltInUIPart.CONTENT,()=>m.connectInjector(Ze,this._injector))}_dispose(t){const e=t.getUnitId();this._renderManagerService.removeRender(e)}_create(t){if(!t)return;const e=t.getUnitId();this._renderManagerService.has(e)&&!this._initImagePopupMenu.has(e)&&(this._popupMenuListener(e),this._initImagePopupMenu.add(e))}_hasCropObject(t){const e=t.getAllObjects();for(const n of e)if(n instanceof Z.ImageCropperObject)return!0;return!1}_popupMenuListener(t){var o;const e=(o=this._renderManagerService.getRenderById(t))==null?void 0:o.scene;if(!e)return;const n=e.getTransformerByCreate();if(!n)return;let r;this.disposeWithMe(m.toDisposable(n.createControl$.subscribe(()=>{if(this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(e))return;const s=n.getSelectedObjectMap();if(s.size>1){r==null||r.dispose();return}const a=s.values().next().value;if(!a)return;const d=a.oKey,u=this._drawingManagerService.getDrawingOKey(d);if(!u)return;const{unitId:l,subUnitId:c,drawingId:g}=u;r==null||r.dispose(),r=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:Z.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(l,c,g)}})),this._drawingManagerService.focusDrawing([{unitId:l,subUnitId:c,drawingId:g}])}))),this.disposeWithMe(n.clearControl$.subscribe(()=>{r==null||r.dispose(),this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(n.changing$.subscribe(()=>{r==null||r.dispose()}))}_getImageMenuItems(t,e,n){return[{label:"image-popup.edit",index:0,commandId:Me.id,commandParams:{unitId:t,subUnitId:e,drawingId:n},disable:!1},{label:"image-popup.delete",index:1,commandId:ve.id,commandParams:{unitId:t,drawings:[{unitId:t,subUnitId:e,drawingId:n}]},disable:!1},{label:"image-popup.crop",index:2,commandId:Z.OpenImageCropOperation.id,commandParams:{unitId:t,subUnitId:e,drawingId:n},disable:!1},{label:"image-popup.reset",index:3,commandId:Z.ImageResetSizeOperation.id,commandParams:[{unitId:t,subUnitId:e,drawingId:n}],disable:!1}]}};ge=tt([m.OnLifecycle(m.LifecycleStages.Steady,ge),J(0,m.Inject(m.Injector)),J(1,O.IDrawingManagerService),J(2,m.Inject(W.SheetCanvasPopManagerService)),J(3,N.IRenderManagerService),J(4,m.IUniverInstanceService),J(5,m.IContextService),J(6,m.Inject(G.IUIPartsService))],ge);const se={id:"sheet.operation.insert-float-image",type:m.CommandType.OPERATION,handler:(i,t)=>!0},oe={id:"sheet.operation.insert-cell-image",type:m.CommandType.OPERATION,handler:(i,t)=>!0},_e={id:"sheet.command.insert-sheet-image",type:m.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(m.ICommandService),n=i.get(m.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!t)return!1;const o=t.drawings,s=o.map(w=>w.unitId),a=r.getBatchAddOp(o),{unitId:d,subUnitId:u,undo:l,redo:c,objects:g}=a;return e.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:c,unitId:d,subUnitId:u,objects:g,type:p.DrawingApplyType.INSERT})?(n.pushUndoRedo({unitID:d,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:l,unitId:d,subUnitId:u,objects:g,type:p.DrawingApplyType.REMOVE}},{id:B.id,params:s}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:c,unitId:d,subUnitId:u,objects:g,type:p.DrawingApplyType.INSERT}},{id:B.id,params:s}]}),!0):!1}},ae={id:"sheet.command.set-sheet-image",type:m.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(m.ICommandService),n=i.get(m.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!t)return!1;const{drawings:o}=t,s=r.getBatchUpdateOp(o),{unitId:a,subUnitId:d,undo:u,redo:l,objects:c}=s;return e.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:a,subUnitId:d,op:l,objects:c,type:p.DrawingApplyType.UPDATE})?(n.pushUndoRedo({unitID:a,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:u,objects:c,type:p.DrawingApplyType.UPDATE}},{id:B.id,params:[a]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:l,objects:c,type:p.DrawingApplyType.UPDATE}},{id:B.id,params:[a]}]}),!0):!1}},Re={id:"sheet.command.set-drawing-arrange",type:m.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(m.ICommandService),n=i.get(m.IUndoRedoService);if(!t)return!1;const r=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:a,arrangeType:d}=t,u={unitId:o,subUnitId:s,drawingIds:a};let l;if(d===O.ArrangeTypeEnum.forward?l=r.getForwardDrawingsOp(u):d===O.ArrangeTypeEnum.backward?l=r.getBackwardDrawingOp(u):d===O.ArrangeTypeEnum.front?l=r.getFrontDrawingsOp(u):d===O.ArrangeTypeEnum.back&&(l=r.getBackDrawingsOp(u)),l==null)return!1;const{objects:c,redo:g,undo:h}=l;return e.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:g,unitId:o,subUnitId:s,objects:c,type:p.DrawingApplyType.ARRANGE})?(n.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:g,unitId:o,subUnitId:s,objects:c,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}};function nt(i){const t=[];return i.forEach(e=>{const{parent:n,children:r}=e,{unitId:o,subUnitId:s,drawingId:a}=n,d=N.getGroupState(0,0,r.map(c=>c.transform||{})),u=r.map(c=>{const g=c.transform||{left:0,top:0},{unitId:h,subUnitId:w,drawingId:f}=c;return{unitId:h,subUnitId:w,drawingId:f,transform:{...g,left:g.left-d.left,top:g.top-d.top},groupId:a}}),l={unitId:o,subUnitId:s,drawingId:a,drawingType:O.DrawingTypeEnum.DRAWING_GROUP,transform:d};t.push({parent:l,children:u})}),t}function rt(i){const t=[];return i.forEach(e=>{const{parent:n,children:r}=e,{unitId:o,subUnitId:s,drawingId:a,transform:d={width:0,height:0}}=n;if(d==null)return;const u=r.map(c=>{const{transform:g}=c,{unitId:h,subUnitId:w,drawingId:f}=c,S=N.transformObjectOutOfGroup(g||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:w,drawingId:f,transform:S,groupId:void 0}}),l={unitId:o,subUnitId:s,drawingId:a,drawingType:O.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};t.push({parent:l,children:u})}),t}const Te={id:"sheet.command.group-sheet-image",type:m.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(m.ICommandService),n=i.get(m.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!t)return!1;const o=[];t.forEach(({parent:h,children:w})=>{o.push(h.unitId),w.forEach(f=>{o.push(f.unitId)})});const s=r.getGroupDrawingOp(t),{unitId:a,subUnitId:d,undo:u,redo:l,objects:c}=s;return e.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:l,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.GROUP})?(n.pushUndoRedo({unitID:a,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:rt(c),type:p.DrawingApplyType.UNGROUP}},{id:B.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:l,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.GROUP}},{id:B.id,params:o}]}),!0):!1}},Ee={id:"sheet.command.ungroup-sheet-image",type:m.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(m.ICommandService),n=i.get(m.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!t)return!1;const o=[];t.forEach(({parent:h,children:w})=>{o.push(h.unitId),w.forEach(f=>{o.push(f.unitId)})});const s=r.getUngroupDrawingOp(t),{unitId:a,subUnitId:d,undo:u,redo:l,objects:c}=s;return e.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:l,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.UNGROUP})?(n.pushUndoRedo({unitID:a,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:nt(c),type:p.DrawingApplyType.GROUP}},{id:B.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:l,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.UNGROUP}},{id:B.id,params:o}]}),!0):!1}};function F(i,t,e){const{from:n,to:r,flipY:o=!1,flipX:s=!1,angle:a=0,skewX:d=0,skewY:u=0}=i,{column:l,columnOffset:c,row:g,rowOffset:h}=n,{column:w,columnOffset:f,row:S,rowOffset:C}=r,y=e.attachRangeWithCoord({startColumn:l,endColumn:l,startRow:g,endRow:g});if(y==null)return;const D=e.attachRangeWithCoord({startColumn:w,endColumn:w,startRow:S,endRow:S});if(D==null)return;const{startX:T,startY:I}=y,{startX:b,startY:v}=D;let P=N.precisionTo(T+c,1),E=N.precisionTo(I+h,1),L=N.precisionTo(b+f-P,1),U=N.precisionTo(v+C-E,1);y.startX===D.endX&&(L=0),y.startY===D.endY&&(U=0);const R=e.getCurrentSkeleton(),M=R.rowHeaderWidth+R.columnTotalWidth,j=R.columnHeaderHeight+R.rowTotalHeight;return P+L>M&&(P=M-L),E+U>j&&(E=j-U),{flipY:o,flipX:s,angle:a,skewX:d,skewY:u,left:P,top:E,width:L,height:U}}function $(i,t){const{left:e=0,top:n=0,width:r=0,height:o=0,flipY:s=!1,flipX:a=!1,angle:d=0,skewX:u=0,skewY:l=0}=i,c=t.getSelectionCellByPosition(e,n);if(c==null)return;const g={column:c.actualColumn,columnOffset:N.precisionTo(e-c.startX,1),row:c.actualRow,rowOffset:N.precisionTo(n-c.startY,1)},h=t.getSelectionCellByPosition(e+r,n+o);if(h==null)return;const w={column:h.actualColumn,columnOffset:N.precisionTo(e+r-h.startX,1),row:h.actualRow,rowOffset:N.precisionTo(n+o-h.startY,1)};return{flipY:s,flipX:a,angle:d,skewX:u,skewY:l,from:g,to:w}}var it=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,st=(i,t,e,n)=>{for(var r=n>1?void 0:n?ot(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&it(t,e,r),r},X=(i,t)=>(e,n)=>t(e,n,i);let he=class extends m.Disposable{constructor(i,t,e,n,r,o,s,a,d,u){super(),this._commandService=i,this._univerInstanceService=t,this._selectionManagerService=e,this._imageIoService=n,this._sheetDrawingService=r,this._drawingManagerService=o,this._contextService=s,this._messageService=a,this._localeService=d,this._renderManagerService=u,this._init()}get _selectionRenderService(){return this._renderManagerService.getRenderById(this._univerInstanceService.getCurrentUnitForType(m.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(W.ISheetSelectionRenderService)}get _skeletonManagerService(){return this._renderManagerService.getRenderById(this._univerInstanceService.getCurrentUnitForType(m.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(W.SheetSkeletonManagerService)}_init(){this._initCommandListeners(),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener(),this._drawingAddListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async i=>{if(i.id===oe.id||i.id===se.id){const t=i.params;if(t.files==null)return;const e=t.files.length;if(e>O.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(O.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(e),i.id===oe.id?t.files.forEach(async n=>{await this._insertCellImage(n)}):t.files.forEach(async n=>{await this._insertFloatImage(n)})}}))}async _insertCellImage(i){}async _insertFloatImage(i){let t;try{t=await this._imageIoService.saveImage(i)}catch(y){const D=y.message;D===O.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(O.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):D===O.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):D===O.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(t==null)return;const e=this._getUnitInfo();if(e==null)return;const{unitId:n,subUnitId:r}=e,{imageId:o,imageSourceType:s,source:a,base64Cache:d}=t,{width:u,height:l,image:c}=await O.getImageSize(d||""),g=this._renderManagerService.getRenderById(n);if(g==null)return;const{width:h,height:w}=g.scene;this._imageIoService.addImageSourceCache(a,s,c);let f=1;if(u>O.DRAWING_IMAGE_WIDTH_LIMIT||l>O.DRAWING_IMAGE_HEIGHT_LIMIT){const y=O.DRAWING_IMAGE_WIDTH_LIMIT/u,D=O.DRAWING_IMAGE_HEIGHT_LIMIT/l;f=Math.max(y,D)}const S=this._getImagePosition(u*f,l*f,h,w);if(S==null)return;const C={unitId:n,subUnitId:r,drawingId:o,drawingType:O.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:F(S,this._selectionRenderService,this._skeletonManagerService),sheetTransform:S};this._commandService.executeCommand(_e.id,{unitId:n,drawings:[C]})}_getUnitInfo(){const i=this._univerInstanceService.getCurrentUnitForType(m.UniverInstanceType.UNIVER_SHEET);if(i==null)return;const t=i.getActiveSheet();if(t==null)return;const e=i.getUnitId(),n=t.getSheetId();return{unitId:e,subUnitId:n}}_getImagePosition(i,t,e,n){const r=this._selectionManagerService.getCurrentSelections();let o={startRow:0,endRow:0,startColumn:0,endColumn:0};r&&r.length>0&&(o=r[r.length-1].range);const s=W.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,o);if(s==null)return;let{startColumn:a,startRow:d,startX:u,startY:l}=s,c=!1;if(u+i>e&&(u=e-i,u<0&&(u=0,i=e),c=!0),l+t>n&&(l=n-t,l<0&&(l=0,t=n),c=!0),c){const f=this._selectionRenderService.getSelectionCellByPosition(u,l);if(f==null)return;u=f.startX,l=f.startY,a=f.actualColumn,d=f.actualRow}const g={column:a,columnOffset:0,row:d,rowOffset:0},h=this._selectionRenderService.getSelectionCellByPosition(u+i,l+t);if(h==null)return;const w={column:h.actualColumn,columnOffset:u+i-h.startX,row:h.actualRow,rowOffset:l+t-h.startY};return{from:g,to:w}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(i=>{const{unitId:t,subUnitId:e,drawingIds:n,arrangeType:r}=i;this._commandService.executeCommand(Re.id,{unitId:t,subUnitId:e,drawingIds:n,arrangeType:r})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(i=>{const t=[];i.length!==0&&(i.forEach(e=>{const{unitId:n,subUnitId:r,drawingId:o,drawingType:s,transform:a}=e;if(a==null)return;const d=this._sheetDrawingService.getDrawingByParam({unitId:n,subUnitId:r,drawingId:o});if(d==null)return;const u=$({...d.transform,...a},this._selectionRenderService);if(u==null)return;const l={...e,transform:{...d.transform,...a,...F(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};t.push(l)}),t.length>0&&this._commandService.executeCommand(ae.id,{unitId:i[0].unitId,drawings:t}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(i=>{this._commandService.executeCommand(Te.id,i);const{unitId:t,subUnitId:e,drawingId:n}=i[0].parent;this._drawingManagerService.focusDrawing([{unitId:t,subUnitId:e,drawingId:n}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(i=>{this._commandService.executeCommand(Ee.id,i)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(i=>{i==null||i.length===0?(this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(i))}))}_drawingAddListener(){this.disposeWithMe(this._sheetDrawingService.add$.subscribe(i=>{this._registerDrawing(i)}))}_registerDrawing(i){i.forEach(e=>{const n=this._sheetDrawingService.getDrawingByParam(e);if(n==null)return;const{sheetTransform:r}=n;n.transform=F(r,this._selectionRenderService,this._skeletonManagerService)});const t=i[0].unitId;this._drawingManagerService.registerDrawingData(t,this._sheetDrawingService.getDrawingDataForUnit(t)),this._drawingManagerService.initializeNotification(t)}};he=st([m.OnLifecycle(m.LifecycleStages.Rendered,he),X(0,m.ICommandService),X(1,m.IUniverInstanceService),X(2,m.Inject(_.SheetsSelectionsService)),X(3,O.IImageIoService),X(4,p.ISheetDrawingService),X(5,O.IDrawingManagerService),X(6,m.IContextService),X(7,G.IMessageService),X(8,m.Inject(m.LocaleService)),X(9,N.IRenderManagerService)],he);var x=function(){return x=Object.assign||function(i){for(var t,e=1,n=arguments.length;e<n;e++){t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(i[r]=t[r])}return i},x.apply(this,arguments)},at=function(i,t){var e={};for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&t.indexOf(n)<0&&(e[n]=i[n]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,n=Object.getOwnPropertySymbols(i);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(i,n[r])&&(e[n[r]]=i[n[r]]);return e},je=A.forwardRef(function(i,t){var e=i.icon,n=i.id,r=i.className,o=i.extend,s=at(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(n," ").concat(r||"").trim(),d=A.useRef("_".concat(lt()));return We(e,"".concat(n),{defIds:e.defIds,idSuffix:d.current},x({ref:t,className:a},s),o)});function We(i,t,e,n,r){return A.createElement(i.tag,x(x({key:t},ct(i,e,r)),n),(dt(i,e).children||[]).map(function(o,s){return We(o,"".concat(t,"-").concat(i.tag,"-").concat(s),e,void 0,r)}))}function ct(i,t,e){var n=x({},i.attrs);e!=null&&e.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=e.colorChannel1);var r=t.defIds;return!r||r.length===0||(i.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(o){var s=o[0],a=o[1];typeof a=="string"&&(n[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function dt(i,t){var e,n=t.defIds;return!n||n.length===0?i:i.tag==="defs"&&(!((e=i.children)===null||e===void 0)&&e.length)?x(x({},i),{children:i.children.map(function(r){return typeof r.attrs.id=="string"&&n&&n.indexOf(r.attrs.id)>-1?x(x({},r),{attrs:x(x({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):i}function lt(){return Math.random().toString(36).substring(2,8)}je.displayName="UniverIcon";var ut={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"}}]},Be=A.forwardRef(function(i,t){return A.createElement(je,Object.assign({},i,{id:"add-image-single",ref:t,icon:ut}))});Be.displayName="AddImageSingle";const gt="univer-upload-file-menu",ht="univer-upload-file-menu-input",Ne={uploadFileMenu:gt,uploadFileMenuInput:ht},$e="COMPONENT_UPLOAD_FILE_MENU";var Se=(i=>(i[i.cellImage=0]="cellImage",i[i.floatImage=1]="floatImage",i))(Se||{});const mt=i=>{const{type:t}=i,e=m.useDependency(m.ICommandService),n=A.useRef(null),r=()=>{var a;(a=n.current)==null||a.click()},o=O.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(a=>`.${a.replace("image/","")}`).join(","),s=a=>{const d=a.target.files;if(d==null)return;const u=Array.from(d);t===Se.floatImage?e.executeCommand(se.id,{files:u}):t===Se.cellImage&&e.executeCommand(oe.id,{files:u}),n.current&&(n.current.value="")};return A.createElement("div",{onClick:r,className:Ne.uploadFileMenu},A.createElement("input",{type:"file",className:Ne.uploadFileMenuInput,ref:n,onChange:s,accept:o,multiple:!0}))},Ge="addition-and-subtraction-single",Ve="sheet.menu.image";function pt(i){return{id:Ve,type:G.MenuItemType.SUBITEMS,positions:[G.MenuPosition.TOOLBAR_START],group:G.MenuGroup.TOOLBAR_FORMULAS_INSERT,icon:Ge,tooltip:"sheetImage.title",hidden$:G.getMenuHiddenObservable(i,m.UniverInstanceType.UNIVER_SHEET),disabled$:W.getCurrentRangeDisable$(i,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function ft(i){return{id:se.id,title:"sheetImage.upload.float",type:G.MenuItemType.SELECTOR,label:{name:$e,props:{type:Se.floatImage}},positions:[Ve],hidden$:G.getMenuHiddenObservable(i,m.UniverInstanceType.UNIVER_SHEET)}}const wt="univer-image-common-panel",St="univer-image-common-panel-grid",vt="univer-image-common-panel-border",_t="univer-image-common-panel-title",It="univer-image-common-panel-subtitle",Dt="univer-image-common-panel-row",Ct="univer-image-common-panel-row-vertical",yt="univer-image-common-panel-column",Mt="univer-image-common-panel-column-center",Rt="univer-image-common-panel-inline",Tt="univer-image-common-panel-span2",Et="univer-image-common-panel-span3",bt="univer-image-common-panel-input",Ot="univer-sheet-image-menu",Pt="univer-sheet-image-menu-input",z={imageCommonPanel:wt,imageCommonPanelGrid:St,imageCommonPanelBorder:vt,imageCommonPanelTitle:_t,imageCommonPanelSubtitle:It,imageCommonPanelRow:Dt,imageCommonPanelRowVertical:Ct,imageCommonPanelColumn:yt,imageCommonPanelColumnCenter:Mt,imageCommonPanelInline:Rt,imageCommonPanelSpan2:Tt,imageCommonPanelSpan3:Et,imageCommonPanelInput:bt,sheetImageMenu:Ot,sheetImageMenuInput:Pt},At=i=>{var D;const t=m.useDependency(m.ICommandService),e=m.useDependency(m.LocaleService),n=m.useDependency(O.IDrawingManagerService),r=m.useDependency(N.IRenderManagerService),{drawings:o}=i,s=o[0];if(s==null)return;const{unitId:a}=s,d=r.getRenderById(a),u=d==null?void 0:d.scene;if(u==null)return;const l=u.getTransformerByCreate(),[c,g]=A.useState(!0),h=(D=s.anchorType)!=null?D:p.SheetDrawingAnchorType.Position,[w,f]=A.useState(h);function S(T,I){const b=[];return T.forEach(v=>{const{oKey:P}=v,E=I.getDrawingOKey(P);if(E==null)return b.push(null),!0;const{unitId:L,subUnitId:U,drawingId:R,drawingType:M,anchorType:j,sheetTransform:k}=E;b.push({unitId:L,subUnitId:U,drawingId:R,anchorType:j,sheetTransform:k,drawingType:M})}),b}A.useEffect(()=>{const T=l.clearControl$.subscribe(b=>{b===!0&&g(!1)}),I=l.changeStart$.subscribe(b=>{var E;const{objects:v}=b,P=S(v,n);if(P.length===0)g(!1);else if(P.length>=1){g(!0);const L=((E=P[0])==null?void 0:E.anchorType)||p.SheetDrawingAnchorType.Position;f(L)}});return()=>{I.unsubscribe(),T.unsubscribe()}},[]);function C(T){f(T);const I=n.getFocusDrawings();if(I.length===0)return;const b=I.map(v=>({unitId:v.unitId,subUnitId:v.subUnitId,drawingId:v.drawingId,anchorType:T}));t.executeCommand(ae.id,{unitId:I[0].unitId,drawings:b})}const y=T=>T?"block":"none";return A.createElement("div",{className:de(z.imageCommonPanelGrid,z.imageCommonPanelBorder),style:{display:y(c)}},A.createElement("div",{className:z.imageCommonPanelRow},A.createElement("div",{className:de(z.imageCommonPanelColumn,z.imageCommonPanelTitle)},A.createElement("div",null,e.t("drawing-anchor.title")))),A.createElement("div",{className:de(z.imageCommonPanelRow)},A.createElement("div",{className:de(z.imageCommonPanelColumn)},A.createElement(q.RadioGroup,{value:w,onChange:C,direction:"vertical"},A.createElement(q.Radio,{value:p.SheetDrawingAnchorType.Both},e.t("drawing-anchor.both")),A.createElement(q.Radio,{value:p.SheetDrawingAnchorType.Position},e.t("drawing-anchor.position")),A.createElement(q.Radio,{value:p.SheetDrawingAnchorType.None},e.t("drawing-anchor.none"))))))},Ut=()=>{const i=m.useDependency(O.IDrawingManagerService),t=i.getFocusDrawings(),[e,n]=A.useState(t);return A.useEffect(()=>{const r=i.focus$.subscribe(o=>{n(o)});return()=>{r.unsubscribe()}},[]),!!(e!=null&&e.length)&&A.createElement("div",{className:z.imageCommonPanel},A.createElement(Z.DrawingCommonPanel,{drawings:e}),A.createElement(At,{drawings:e}))},te={id:"sheet.command.move-drawing",type:m.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(m.ICommandService),n=i.get(p.ISheetDrawingService),r=i.get(W.ISheetSelectionRenderService),{direction:o}=t,s=n.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,d=s.map(l=>{const{transform:c}=l;if(c==null)return null;const g={...c},{left:h=0,top:w=0}=c;return o===m.Direction.UP?g.top=w-1:o===m.Direction.DOWN?g.top=w+1:o===m.Direction.LEFT?g.left=h-1:o===m.Direction.RIGHT&&(g.left=h+1),{...l,transform:g,sheetTransform:$(g,r)}}).filter(l=>l!=null);return e.syncExecuteCommand(ae.id,{unitId:a,drawings:d})?(e.syncExecuteCommand(B.id,[a]),!0):!1}},be={id:"sheet.command.delete-drawing",type:m.CommandType.COMMAND,handler:i=>{const t=i.get(m.ICommandService),n=i.get(p.ISheetDrawingService).getFocusDrawings();if(n.length===0)return!1;const r=n[0].unitId,o=n.map(s=>{const{unitId:a,subUnitId:d,drawingId:u,drawingType:l}=s;return{unitId:a,subUnitId:d,drawingId:u,drawingType:l}});return t.executeCommand(ve.id,{unitId:r,drawings:o})}};function ce(i){return!i.getContextValue(m.FOCUSING_FORMULA_EDITOR)&&!i.getContextValue(m.EDITOR_ACTIVATED)&&i.getContextValue(m.FOCUSING_COMMON_DRAWINGS)}const Nt={id:te.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_DOWN,priority:100,preconditions:ce,staticParameters:{direction:m.Direction.DOWN}},Lt={id:te.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_UP,priority:100,preconditions:ce,staticParameters:{direction:m.Direction.UP}},jt={id:te.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_LEFT,priority:100,preconditions:ce,staticParameters:{direction:m.Direction.LEFT}},Wt={id:te.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_RIGHT,priority:100,preconditions:ce,staticParameters:{direction:m.Direction.RIGHT}},Bt={id:be.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:ce,binding:G.KeyCode.DELETE,mac:G.KeyCode.BACKSPACE};var $t=Object.defineProperty,Gt=Object.getOwnPropertyDescriptor,Vt=(i,t,e,n)=>{for(var r=n>1?void 0:n?Gt(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&$t(t,e,r),r},ne=(i,t)=>(e,n)=>t(e,n,i);const Ft={};let ie=class extends m.Disposable{constructor(i,t,e,n,r,o){super(),this._config=i,this._injector=t,this._componentManager=e,this._menuService=n,this._commandService=r,this._shortcutService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Ge,Be)),this.disposeWithMe(i.register($e,mt)),this.disposeWithMe(i.register(Le,Ut))}_initMenus(){const{menu:i={}}=this._config;[pt,ft].forEach(t=>{this._menuService.addMenuItem(t(this._injector),i)})}_initCommands(){[se,oe,_e,ve,ae,ye,B,Me,Te,Ee,te,be,Re].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[Nt,Lt,jt,Wt,Bt].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};ie=Vt([m.OnLifecycle(m.LifecycleStages.Rendered,ie),ne(1,m.Inject(m.Injector)),ne(2,m.Inject(G.ComponentManager)),ne(3,G.IMenuService),ne(4,m.ICommandService),ne(5,G.IShortcutService)],ie);var kt=Object.defineProperty,Ht=Object.getOwnPropertyDescriptor,xt=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ht(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&kt(t,e,r),r},Q=(i,t)=>(e,n)=>t(e,n,i);const Yt=[_.InsertRowCommand.id,_.InsertColCommand.id,_.RemoveRowCommand.id,_.RemoveColCommand.id,_.DeleteRangeMoveLeftCommand.id,_.DeleteRangeMoveUpCommand.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id,_.DeltaRowHeightCommand.id,_.SetRowHeightCommand.id,_.DeltaColumnWidthCommand.id,_.SetColWidthCommand.id,_.SetRowHiddenCommand.id,_.SetSpecificRowsVisibleCommand.id,_.SetSpecificColsVisibleCommand.id,_.SetColHiddenCommand.id],Xt=[_.SetRowVisibleMutation.id,_.SetRowHiddenMutation.id,_.SetColVisibleMutation.id,_.SetColHiddenMutation.id,_.SetWorksheetRowHeightMutation.id,_.SetWorksheetColWidthMutation.id];let me=class extends m.Disposable{constructor(i,t,e,n,r,o){super(),this._commandService=i,this._sheetInterceptorService=t,this._renderManagerService=e,this._sheetDrawingService=n,this._drawingManagerService=r,this._univerInstanceService=o,this._init()}get _selectionRenderService(){return this._renderManagerService.getRenderById(this._univerInstanceService.getCurrentUnitForType(m.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(W.ISheetSelectionRenderService)}get _skeletonManagerService(){return this._renderManagerService.getRenderById(this._univerInstanceService.getCurrentUnitForType(m.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(W.SheetSkeletonManagerService)}_init(){this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!Yt.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const t=i.id;if(t===_.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if(t===_.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(t===_.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(t===_.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(t===_.DeleteRangeMoveLeftCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,0)}else if(t===_.DeleteRangeMoveUpCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,1)}else if(t===_.InsertRangeMoveDownCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,2)}else if(t===_.InsertRangeMoveRightCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,3)}else if(t===_.SetRowHiddenCommand.id||t===_.SetSpecificRowsVisibleCommand.id){const e=i.params,{unitId:n,subUnitId:r,ranges:o}=e;return this._getDrawingUndoForRowVisible(n,r,o)}else if(t===_.SetSpecificColsVisibleCommand.id||t===_.SetColHiddenCommand.id){const e=i.params,{unitId:n,subUnitId:r,ranges:o}=e;return this._getDrawingUndoForColVisible(n,r,o)}else if(t===_.DeltaRowHeightCommand.id||t===_.SetRowHeightCommand.id||t===_.DeltaColumnWidthCommand.id||t===_.SetColWidthCommand.id){const e=i.params,{unitId:n,subUnitId:r,ranges:o}=e,s=t===_.DeltaRowHeightCommand.id||t===_.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(n,r,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,t){const e=_.getSheetCommandTarget(this._univerInstanceService);if(e==null)return{redos:[],undos:[]};const n=e.unitId,r=e.subUnitId,o=[],s=[],a=this._sheetDrawingService.getDrawingData(n,r),d=[],u=[];if(Object.keys(a).forEach(l=>{const c=a[l],{updateDrawings:g,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,t,c);d.push(...g),u.push(...h)}),d.length===0&&u.length===0)return{redos:[],undos:[]};if(d.length>0){const l=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:g,objects:h}=l;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:g,objects:h,type:p.DrawingApplyType.UPDATE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:c,objects:h,type:p.DrawingApplyType.UPDATE}})}if(u.length>0){const l=this._sheetDrawingService.getBatchRemoveOp(u),c=l.undo,g=l.redo,h=l.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:g,objects:h,type:p.DrawingApplyType.REMOVE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:c,objects:h,type:p.DrawingApplyType.INSERT}})}return o.push({id:B.id,params:[n]}),s.push({id:B.id,params:[n]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,t,e){const n=[],r=[],{sheetTransform:o,anchorType:s=p.SheetDrawingAnchorType.Position,transform:a,unitId:d,subUnitId:u,drawingId:l}=e,{from:c,to:g}=o,{row:h,column:w}=c,{row:f,column:S}=g;if(o==null||a==null)return{updateDrawings:n,deleteDrawings:r};const{startRow:C,endRow:y,startColumn:D,endColumn:T}=i;let I=null,b=null;if(t===0&&h>=C&&f<=y)if(w>=D&&S<=T)r.push({unitId:d,subUnitId:u,drawingId:l});else{const v=this._shrinkCol(o,a,D,T,s);I=v==null?void 0:v.newSheetTransform,b=v==null?void 0:v.newTransform}else if(t===1&&w>=D&&S<=T)if(h>=C&&f<=y)r.push({unitId:d,subUnitId:u,drawingId:l});else{const v=this._shrinkRow(o,a,C,y,s);I=v==null?void 0:v.newSheetTransform,b=v==null?void 0:v.newTransform}else if(t===2){const v=this._expandRow(o,a,C,y,s);I=v==null?void 0:v.newSheetTransform,b=v==null?void 0:v.newTransform}else if(t===3){const v=this._expandCol(o,a,D,T,s);I=v==null?void 0:v.newSheetTransform,b=v==null?void 0:v.newTransform}if(I!=null&&b!=null){const v=F(I,this._selectionRenderService,this._skeletonManagerService);n.push({...e,sheetTransform:I,transform:v})}return{updateDrawings:n,deleteDrawings:r}}_remainDrawingSize(i,t,e){const n=$({...i},this._selectionRenderService);n!=null&&t.push({...e,sheetTransform:n})}_getDrawingUndoForColVisible(i,t,e){const n=this._drawingManagerService.getDrawingData(i,t),r=[],o=[];if(Object.keys(n).forEach(l=>{const c=n[l],{sheetTransform:g,transform:h,anchorType:w=p.SheetDrawingAnchorType.Position}=c;if(w===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,r,c);else{const{from:f,to:S}=g,{row:C,column:y}=f,{row:D,column:T}=S;for(let I=0;I<e.length;I++){const b=e[I],{startRow:v,endRow:P,startColumn:E,endColumn:L}=b;if(T<E)continue;if(w===p.SheetDrawingAnchorType.Position){let M=null,j=null;if(y>=E&&y<=L){const k=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:L,startRow:f.row,endRow:S.row});if(k==null)return;j={...h,left:k.startX}}if(j!=null&&(M=$(j,this._selectionRenderService),M!=null&&j!=null)){r.push({...c,sheetTransform:M,transform:j});break}this._remainDrawingSize(h,r,c);continue}if(y>=E&&T<=L)continue;let U=null,R=null;if(y>=E&&y<=L){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:L,startRow:f.row,endRow:S.row});if(M==null)return;R={...h,left:(M==null?void 0:M.startX)||0,width:((h==null?void 0:h.width)||0)-M.endX+M.startX}}else if(T>=E&&T<=L){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:T,startRow:f.row,endRow:S.row});if(M==null)return;R={...h,left:M.startX-((h==null?void 0:h.width)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:L,startRow:f.row,endRow:S.row});if(M==null)return;if(R={...h,width:((h==null?void 0:h.width)||0)-M.endX+M.startX},U=$(R,this._selectionRenderService),U!=null&&R!=null){o.push({...c,sheetTransform:U,transform:R});break}}if(R!=null&&(U=$(R,this._selectionRenderService)),R!=null&&U!=null){r.push({...c,sheetTransform:U,transform:R});break}else this._remainDrawingSize(h,r,c)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,t,r),d=[],u=[];if(o.length>0){const{redos:l,undos:c}=this._createUndoAndRedoMutation(i,t,o);d.push(...l),u.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:u}}_createUndoAndRedoMutation(i,t,e){const n=this._sheetDrawingService.getBatchUpdateOp(e),{undo:r,redo:o,objects:s}=n,a=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:t,op:o,objects:s,type:p.DrawingApplyType.UPDATE}},{id:B.id,params:[i]}],d=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:t,op:r,objects:s,type:p.DrawingApplyType.UPDATE}},{id:B.id,params:[i]}];return{redos:a,undos:d}}_getDrawingUndoForRowVisible(i,t,e){const n=this._drawingManagerService.getDrawingData(i,t),r=[],o=[];if(Object.keys(n).forEach(l=>{const c=n[l],{sheetTransform:g,transform:h,anchorType:w=p.SheetDrawingAnchorType.Position}=c;if(w===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,r,c);else{const{from:f,to:S}=g,{row:C,column:y}=f,{row:D,column:T}=S;for(let I=0;I<e.length;I++){const b=e[I],{startRow:v,endRow:P,startColumn:E,endColumn:L}=b;if(D<v)continue;if(w===p.SheetDrawingAnchorType.Position){let M=null,j=null;if(C>=v&&C<=P){const k=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:C,endRow:P});if(k==null)return;j={...h,top:k.startY}}if(j!=null&&(M=$(j,this._selectionRenderService),M!=null&&j!=null)){r.push({...c,sheetTransform:M,transform:j});break}this._remainDrawingSize(h,r,c);continue}if(C>=v&&D<=P)continue;let U=null,R=null;if(C>=v&&C<=P){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:C,endRow:P});if(M==null)return;R={...h,top:(M==null?void 0:M.startY)||0,height:((h==null?void 0:h.height)||0)-M.endY+M.startY}}else if(D>=v&&D<=P){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:v,endRow:D});if(M==null)return;R={...h,top:M.startY-((h==null?void 0:h.height)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:v,endRow:P});if(M==null)return;if(R={...h,height:((h==null?void 0:h.height)||0)-M.endY+M.startY},U=$(R,this._selectionRenderService),U!=null&&R!=null){o.push({...c,sheetTransform:U,transform:R});break}}if(R!=null&&(U=$(R,this._selectionRenderService)),R!=null&&U!=null){r.push({...c,sheetTransform:U,transform:R});break}else this._remainDrawingSize(h,r,c)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,t,r),d=[],u=[];if(o.length>0){const{redos:l,undos:c}=this._createUndoAndRedoMutation(i,t,o);d.push(...l),u.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:u}}_getDrawingUndoForRowAndColSize(i,t,e,n){const r=this._drawingManagerService.getDrawingData(i,t),o=[];return Object.keys(r).forEach(s=>{const a=r[s],{sheetTransform:d,transform:u,anchorType:l=p.SheetDrawingAnchorType.Position}=a;if(l===p.SheetDrawingAnchorType.None)this._remainDrawingSize(u,o,a);else{const{from:c,to:g}=d,{row:h,column:w}=c,{row:f,column:S}=g;for(let C=0;C<e.length;C++){const y=e[C],{startRow:D,endRow:T,startColumn:I,endColumn:b}=y;if(f<D||S<I)continue;if(l===p.SheetDrawingAnchorType.Position&&(h<=D&&f>=T||w<=I&&S>=b)){this._remainDrawingSize(u,o,a);continue}const v=F({...d},this._selectionRenderService,this._skeletonManagerService);if(v!=null){o.push({...a,transform:v});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,t,o)}_getUnitIdAndSubUnitId(i,t){let e,n;if(t==="insert")e=i.unitId,n=i.subUnitId;else{const r=_.getSheetCommandTarget(this._univerInstanceService);if(r==null)return;e=r.unitId,n=r.subUnitId}return{unitId:e,subUnitId:n}}_moveRowInterceptor(i,t){const e=this._getUnitIdAndSubUnitId(i,t);if(e==null)return{redos:[],undos:[]};const{unitId:n,subUnitId:r}=e,{range:o}=i,s=o.startRow,a=o.endRow,d=[],u=[],l=this._sheetDrawingService.getDrawingData(n,r),c=[],g=[];if(Object.keys(l).forEach(h=>{const w=l[h],{sheetTransform:f,transform:S,anchorType:C=p.SheetDrawingAnchorType.Position}=w;if(f==null||S==null)return;let y,D;if(t==="insert"){const I=this._expandRow(f,S,s,a,C);y=I==null?void 0:I.newSheetTransform,D=I==null?void 0:I.newTransform}else{const{from:I,to:b}=f,{row:v}=I,{row:P}=b;if(v>=s&&P<=a)g.push({unitId:n,subUnitId:r,drawingId:h});else{const E=this._shrinkRow(f,S,s,a,C);y=E==null?void 0:E.newSheetTransform,D=E==null?void 0:E.newTransform}}if(!y||!D)return;const T={unitId:n,subUnitId:r,drawingId:h,transform:D,sheetTransform:y};c.push(T)}),c.length===0&&g.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:w,redo:f,objects:S}=h;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.UPDATE}}),u.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(g),w=h.undo,f=h.redo,S=h.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.REMOVE}}),u.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.INSERT}})}return d.push({id:B.id,params:[n]}),u.push({id:B.id,params:[n]}),{redos:d,undos:u}}_moveColInterceptor(i,t){const e=this._getUnitIdAndSubUnitId(i,t);if(e==null)return{redos:[],undos:[]};const{unitId:n,subUnitId:r}=e,{range:o}=i,s=o.startColumn,a=o.endColumn,d=[],u=[],l=this._sheetDrawingService.getDrawingData(n,r),c=[],g=[];if(Object.keys(l).forEach(h=>{const w=l[h],{sheetTransform:f,transform:S,anchorType:C=p.SheetDrawingAnchorType.Position}=w;if(f==null||S==null)return;let y,D;if(t==="insert"){const I=this._expandCol(f,S,s,a,C);y=I==null?void 0:I.newSheetTransform,D=I==null?void 0:I.newTransform}else{const{from:I,to:b}=f,{column:v}=I,{column:P}=b;if(v>=s&&P<=a)g.push({unitId:n,subUnitId:r,drawingId:h});else{const E=this._shrinkCol(f,S,s,a,C);y=E==null?void 0:E.newSheetTransform,D=E==null?void 0:E.newTransform}}if(!y||!D)return;const T={unitId:n,subUnitId:r,drawingId:h,transform:D,sheetTransform:y};c.push(T)}),c.length===0&&g.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:w,redo:f,objects:S}=h;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.UPDATE}}),u.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(g),w=h.undo,f=h.redo,S=h.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.REMOVE}}),u.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.INSERT}})}return d.push({id:B.id,params:[n]}),u.push({id:B.id,params:[n]}),{redos:d,undos:u}}_expandCol(i,t,e,n,r=p.SheetDrawingAnchorType.Position){const o=n-e+1,{from:s,to:a}=i,{column:d}=s,{column:u}=a;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};let l=null,c=null;if(d>=e){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:e,endColumn:n,startRow:s.row,endRow:a.row});if(g==null)return;c={...t,left:(t.left||0)+g.endX-g.startX},l=$(c,this._selectionRenderService)}else if(u>=n)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,column:u+o}},c=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};return l!=null&&c!=null?{newSheetTransform:l,newTransform:c}:null}_shrinkCol(i,t,e,n,r=p.SheetDrawingAnchorType.Position){const o=n-e+1,{from:s,to:a}=i,{column:d}=s,{column:u}=a;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};let l=null,c=null;if(d>n)l={from:{...s,column:d-o},to:{...a,column:u-o}},c=F(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=e&&u<=n)return null;if(d<e&&u>n)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,column:u-o}},c=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};else if(d>=e&&d<=n){if(d===e)c={...t,left:(t.left||0)-i.from.columnOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:e,endColumn:d-1,startRow:s.row,endRow:a.row});if(g==null)return;c={...t,left:(t.left||0)-g.endX+g.startX-i.from.columnOffset}}l=$(c,this._selectionRenderService)}else if(u>=e&&u<=n&&r===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:e-1,endColumn:e-1,startRow:s.row,endRow:a.row});if(g==null)return;l={from:{...s},to:{...a,column:e-1,columnOffset:g.endX-g.startX}},c=F(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&c!=null?{newSheetTransform:l,newTransform:c}:null}_expandRow(i,t,e,n,r=p.SheetDrawingAnchorType.Position){const o=n-e+1,{from:s,to:a}=i,{row:d}=s,{row:u}=a;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};let l=null,c=null;if(d>=e){const g=this._skeletonManagerService.attachRangeWithCoord({startRow:e,endRow:n,startColumn:s.column,endColumn:a.column});if(g==null)return;c={...t,top:(t.top||0)+g.endY-g.startY},l=$(c,this._selectionRenderService)}else if(u>=n)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,row:u+o}},c=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};return l!=null&&c!=null?{newSheetTransform:l,newTransform:c}:null}_shrinkRow(i,t,e,n,r=p.SheetDrawingAnchorType.Position){const o=n-e+1,{from:s,to:a}=i,{row:d}=s,{row:u}=a;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};let l=null,c=null;if(d>n)l={from:{...s,row:d-o},to:{...a,row:u-o}},c=F(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=e&&u<=n)return null;if(d<e&&u>n)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,row:u-o}},c=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};else if(d>=e&&d<=n){if(d===e)c={...t,top:(t.top||0)-i.from.rowOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startRow:e,endRow:d-1,startColumn:s.column,endColumn:a.column});if(g==null)return;c={...t,top:(t.top||0)-g.endY+g.startY-i.from.rowOffset}}l=$(c,this._selectionRenderService)}else if(u>=e&&u<=n&&r===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:e-1,endRow:e-1});if(g==null)return;l={from:{...s},to:{...a,row:e-1,rowOffset:g.endY-g.startY}},c=F(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&c!=null?{newSheetTransform:l,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===_.SetWorksheetActiveOperation.id&&setTimeout(()=>{const t=i.params,{unitId:e,subUnitId:n}=t,r=this._drawingManagerService.drawingManagerData,o=[],s=[];Object.keys(r).forEach(a=>{const d=r[a];Object.keys(d).forEach(u=>{const l=d[u].data;l!=null&&Object.keys(l).forEach(c=>{if(a===e&&u===n){const g=l[c];g.transform=F(g.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(l[c])}else s.push(l[c])})})}),this._drawingManagerService.removeNotification(s),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Xt.includes(i.id)&&requestIdleCallback(()=>{const t=i.params,{unitId:e,subUnitId:n,ranges:r}=t;this._refreshDrawingTransform(e,n,r)})}))}_refreshDrawingTransform(i,t,e){const n=this._drawingManagerService.getDrawingData(i,t),r=[];Object.keys(n).forEach(o=>{const s=n[o],{sheetTransform:a,anchorType:d=p.SheetDrawingAnchorType.Position}=s;if(d===p.SheetDrawingAnchorType.None)return!0;const{from:u,to:l}=a,{row:c,column:g}=u,{row:h,column:w}=l;for(let f=0;f<e.length;f++){const S=e[f],{startRow:C,endRow:y,startColumn:D,endColumn:T}=S;if(m.Rectangle.intersects({startRow:C,endRow:y,startColumn:D,endColumn:T},{startRow:c,endRow:h,startColumn:g,endColumn:w})||c>y||g>T){r.push({...s,transform:F(a,this._selectionRenderService,this._skeletonManagerService)});break}}}),r.length!==0&&(this._drawingManagerService.refreshTransform(r),this._commandService.syncExecuteCommand(B.id,[i]))}};me=xt([m.OnLifecycle(m.LifecycleStages.Rendered,me),Q(0,m.ICommandService),Q(1,m.Inject(_.SheetInterceptorService)),Q(2,N.IRenderManagerService),Q(3,p.ISheetDrawingService),Q(4,O.IDrawingManagerService),Q(5,m.IUniverInstanceService)],me);var Kt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,qt=(i,t,e,n)=>{for(var r=n>1?void 0:n?zt(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&Kt(t,e,r),r},ee=(i,t)=>(e,n)=>t(e,n,i);function Jt(i,t,e,n){const{scaleX:r,scaleY:o}=t.getAncestorScale(),s=t.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN),a={left:!0,top:!0};if(!s)return{...i,absolute:a};const{left:d,right:u,top:l,bottom:c}=i,g=n.getFreeze(),{startColumn:h,startRow:w,xSplit:f,ySplit:S}=g,C=e.getNoMergeCellPositionByIndexWithNoHeader(w-S,h-f),y=e.getNoMergeCellPositionByIndexWithNoHeader(w,h),{rowHeaderWidth:D,columnHeaderHeight:T}=e,I=y.startX-C.startX,b=y.startY-C.startY,{top:v,left:P,viewportScrollX:E,viewportScrollY:L}=s;let U,R;d<P?(a.left=!0,U=(I+D+(d-P))*r,R=Math.max(Math.min((I+D+(u-P))*r,(I+D)*r),(u-E)*r)):(a.left=!1,U=Math.max((d-E)*r,(I+D)*r),R=Math.max((u-E)*r,(I+D)*r));let M,j;return l<v?(a.top=!0,M=(b+T+(l-v))*o,j=Math.max(Math.min((b+T+(u-v))*o,(b+T)*o),(c-L)*o)):(a.top=!1,M=Math.max((l-L)*o,(b+T)*o),j=Math.max((c-L)*o,(b+T)*o)),{left:U,right:R,top:M,bottom:j,absolute:a}}const Ie=(i,t,e,n)=>{const{scene:r}=t,{left:o,top:s,width:a,height:d,angle:u}=i,l={left:o,right:o+a,top:s,bottom:s+d},c=Jt(l,r,e,n);return{startX:c.left,endX:c.right,startY:c.top,endY:c.bottom,rotate:u,width:a,height:d,absolute:c.absolute}};exports.SheetCanvasFloatDomManagerService=class extends m.Disposable{constructor(e,n,r,o,s,a){super();Y(this,"_domLayerMap",new Map);Y(this,"_domLayerInfoMap",new Map);Y(this,"_transformChange$",new V.Subject);Y(this,"transformChange$",this._transformChange$.asObservable());Y(this,"_remove$",new V.Subject);Y(this,"remove$",this._remove$.asObservable());Y(this,"_hooks",[]);this._renderManagerService=e,this._univerInstanceService=n,this._commandService=r,this._drawingManagerService=o,this._canvasFloatDomService=s,this._sheetDrawingService=a,this._drawingAddListener(),this._scrollUpdateListener(),this._featureUpdateListener(),this._deleteListener()}_ensureMap(e,n){let r=this._domLayerMap.get(e);r||(r=new Map,this._domLayerMap.set(e,r));let o=r.get(n);return o||(o=new Map,r.set(n,o)),o}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;const n=this._renderManagerService.getRenderById(e),r=n==null?void 0:n.scene;if(n==null||r==null)return null;const o=r.getTransformerByCreate(),s=n.engine.getCanvasElement();return{scene:r,transformer:o,renderObject:n,canvas:s}}_getFloatDomProps(e){let n;return this._hooks.forEach(r=>{n=r.onGetFloatDomProps(e)}),n}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(n=>{var Pe,Ae,Ue;const{unitId:r,subUnitId:o,drawingId:s}=n,a=_.getSheetCommandTarget(this._univerInstanceService,{unitId:r,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(n),u=(Pe=this._renderManagerService.getRenderById(r))==null?void 0:Pe.with(W.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(d==null||a==null||u==null)return;const{transform:l,drawingType:c,data:g}=d;if(c!==m.DrawingTypeEnum.DRAWING_DOM)return;const h=this._getSceneAndTransformerByDrawingSearch(r);if(h==null)return;const{scene:w,canvas:f}=h;if(l==null)return!0;const{left:S,top:C,width:y,height:D,angle:T,flipX:I,flipY:b,skewX:v,skewY:P}=l,E=O.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:o,drawingId:s}),L=w.getObject(E);if(L!=null){L.transformByState({left:S,top:C,width:y,height:D,angle:T,flipX:I,flipY:b,skewX:v,skewY:P});return}const U={left:S,top:C,width:y,height:D,zIndex:this._drawingManagerService.getDrawingOrder(r,o).length-1},R=new N.Rect(E,U);w.addObject(R,N.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(R);const M=this._ensureMap(r,o),j=new m.DisposableCollection,k=Ie(R,h.renderObject,u.skeleton,a.worksheet),K=new V.BehaviorSubject(k),He={dispose:j,rect:R,position$:K,unitId:r,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:K,id:s,componentKey:d.componentKey,onPointerDown:H=>{f.dispatchEvent(new PointerEvent(H.type,H))},onPointerMove:H=>{f.dispatchEvent(new PointerEvent(H.type,H))},onPointerUp:H=>{f.dispatchEvent(new PointerEvent(H.type,H))},onWheel:H=>{f.dispatchEvent(new WheelEvent(H.type,H))},props:(Ue=(Ae=M.get(s))==null?void 0:Ae.props)!=null?Ue:this._getFloatDomProps(s),data:g});const Oe=R.onTransformChange$.subscribeEvent(()=>{const H=Ie(R,h.renderObject,u.skeleton,a.worksheet);K.next(H)});j.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),Oe&&j.add(Oe),this._domLayerInfoMap.set(s,He),M.set(s,{})})}))}_scrollUpdateListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var r,o;const n=(s,a)=>{var h;const d=this._getSceneAndTransformerByDrawingSearch(s),u=this._ensureMap(s,a),l=Array.from(u.keys()),c=_.getSheetCommandTarget(this._univerInstanceService,{unitId:s,subUnitId:a}),g=(h=this._renderManagerService.getRenderById(s))==null?void 0:h.with(W.SheetSkeletonManagerService).getWorksheetSkeleton(a);!d||!c||!g||l.forEach(w=>{const f=this._domLayerInfoMap.get(w);if(f){const S=Ie(f.rect,d.renderObject,g.skeleton,c.worksheet);f.position$.next(S)}})};if(e.id===W.SetScrollOperation.id){const s=e.params,{unitId:a,sheetId:d}=s;n(a,d)}else if(e.id===W.SetZoomRatioOperation.id){const s=e.params,{unitId:a}=s;Array.from((o=(r=this._domLayerMap.get(a))==null?void 0:r.keys())!=null?o:[]).forEach(u=>{n(a,u)})}else if(e.id===_.SetFrozenMutation.id){const{unitId:s,subUnitId:a}=e.params;n(s,a)}}))}_getPosition(e,n){var h;const{startX:r,endX:o,startY:s,endY:a}=e,d=(h=this._renderManagerService.getRenderById(n))==null?void 0:h.with(W.ISheetSelectionRenderService);if(d==null)return;const u=d.getSelectionCellByPosition(r,s);if(u==null)return;const l={column:u.actualColumn,columnOffset:r-u.startX,row:u.actualRow,rowOffset:s-u.startY},c=d.getSelectionCellByPosition(o,a);if(c==null)return;const g={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:a-c.startY};return{from:l,to:g}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(n=>{const r=this._drawingManagerService.getDrawingByParam(n);if(!r||r.drawingType!==m.DrawingTypeEnum.DRAWING_DOM)return;const o={...r.transform};this._transformChange$.next({id:n.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(n=>{this._removeDom(n.drawingId)})}))}addFloatDomToPosition(e){const n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:r,subUnitId:o}=n,{initPosition:s,componentKey:a,data:d}=e,u=m.Tools.generateRandomId(),l=this._getPosition(s,r);if(l==null)return;this._ensureMap(r,o).set(u,e);const g={unitId:r,subUnitId:o,drawingId:u,drawingType:m.DrawingTypeEnum.DRAWING_DOM,componentKey:a,sheetTransform:l,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:d};return this._commandService.executeCommand(_e.id,{unitId:r,drawings:[g]}),{id:u,dispose:()=>{this._removeDom(u,!0)}}}_removeDom(e,n=!1){const r=this._domLayerInfoMap.get(e);if(!r)return;const{unitId:o,subUnitId:s}=r;this._domLayerInfoMap.delete(e),r.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(o);if(a&&a.scene.removeObject(r.rect),n){this._ensureMap(o,s).delete(e);const u=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:e});if(!u)return;const l=this._sheetDrawingService.getBatchRemoveOp([u]),{redo:c,objects:g}=l;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:c,objects:g,type:p.DrawingApplyType.REMOVE})}}addHook(e){return this._hooks.push(e),{dispose:()=>{const n=this._hooks.findIndex(r=>r===e);this._hooks.splice(n,1)}}}};exports.SheetCanvasFloatDomManagerService=qt([m.OnLifecycle(m.LifecycleStages.Starting,exports.SheetCanvasFloatDomManagerService),ee(0,m.Inject(N.IRenderManagerService)),ee(1,m.IUniverInstanceService),ee(2,m.Inject(m.ICommandService)),ee(3,O.IDrawingManagerService),ee(4,m.Inject(G.CanvasFloatDomService)),ee(5,p.ISheetDrawingService)],exports.SheetCanvasFloatDomManagerService);var Zt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,en=(i,t,e,n)=>{for(var r=n>1?void 0:n?Qt(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&Zt(t,e,r),r},ue=(i,t)=>(e,n)=>t(e,n,i);let pe=class extends m.Disposable{constructor(i,t,e,n){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=t,this._drawingManagerService=e,this._renderManagerService=n,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,t,e)=>{const{unitId:n,scene:r,subUnitId:o}=t,s=this._drawingManagerService.getDrawingDataForUnit(n),a=s==null?void 0:s[o];return a&&a.order.forEach(d=>{this._drawingRenderService.renderDrawing(a.data[d],r)}),e()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,t,e)=>{const{unitId:n,subUnitId:r}=t,o=this._renderManagerService.getRenderById(n);if(!o)return e(i);const s=o.with(W.SheetSkeletonManagerService).getWorksheetSkeleton(r);if(!s)return e(i);const a=this._drawingManagerService.getDrawingDataForUnit(n),d=a==null?void 0:a[t.subUnitId];if(!d)return e(i);const{scaleX:u,scaleY:l}=o.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},g=d.order.map(h=>d.data[h]).filter(h=>h.drawingType!==O.DrawingTypeEnum.DRAWING_DOM);return g.length?(g.forEach(h=>{if(!h.groupId&&h.transform&&m.Tools.isDefine(h.transform.left)&&m.Tools.isDefine(h.transform.top)&&m.Tools.isDefine(h.transform.width)&&m.Tools.isDefine(h.transform.height)){const w=s.skeleton.getCellPositionByOffset(h.transform.left,h.transform.top,u,l,{x:0,y:0}),f=s.skeleton.getCellPositionByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,u,l,{x:0,y:0});w.column<c.startColumn&&(c.startColumn=w.column),w.row<c.startRow&&(c.startRow=w.row),c.endRow<f.row&&(c.endRow=f.row),c.endColumn<f.column&&(c.endColumn=f.column)}}),e(c)):e(i)}}))}};pe=en([m.OnLifecycle(m.LifecycleStages.Rendered,pe),ue(0,m.Inject(W.SheetPrintInterceptorService)),ue(1,m.Inject(Z.DrawingRenderService)),ue(2,O.IDrawingManagerService),ue(3,N.IRenderManagerService)],pe);var tn=Object.defineProperty,nn=Object.getOwnPropertyDescriptor,rn=(i,t,e,n)=>{for(var r=n>1?void 0:n?nn(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&tn(t,e,r),r},re=(i,t)=>(e,n)=>t(e,n,i);let fe=class extends m.Disposable{constructor(i,t,e,n,r){super(),this._drawingManagerService=i,this._renderManagerService=t,this._permissionService=e,this._univerInstanceService=n,this._userManagerService=r,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(V.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([t,e])=>{if(!t){this._drawingManagerService.setDrawingVisible(!1);return}t.activeSheet$.subscribe(n=>{if(!n){this._drawingManagerService.setDrawingVisible(!1);return}const r=t.getUnitId(),o=n.getSheetId();if(this._permissionService.composePermission([new _.WorkbookViewPermission(r).id,new _.WorksheetViewPermission(r,o).id]).every(a=>a.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const a=t.getUnitId(),d=n.getSheetId(),u=this._drawingManagerService.getDrawingData(a,d),l=Object.values(u),c=this._renderManagerService.getRenderById(a),g=c==null?void 0:c.scene;if(g==null)return;g.getAllObjects().forEach(w=>{w.classType===N.RENDER_CLASS_TYPE.IMAGE&&l.some(f=>w.oKey.includes(f.drawingId))&&g.removeObject(w)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(V.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([t,e])=>{if(!t){this._drawingManagerService.setDrawingEditable(!1);return}t.activeSheet$.subscribe(n=>{if(!n){this._drawingManagerService.setDrawingEditable(!1);return}const r=t.getUnitId(),o=n.getSheetId();if(this._permissionService.composePermission([new _.WorkbookEditablePermission(r).id,new _.WorksheetEditPermission(r,o).id]).every(a=>a.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const a=t.getUnitId(),d=n.getSheetId(),u=this._drawingManagerService.getDrawingData(a,d),l=Object.values(u),c=this._renderManagerService.getRenderById(a),g=c==null?void 0:c.scene;if(g==null)return;g.getAllObjects().forEach(w=>{w.classType===N.RENDER_CLASS_TYPE.IMAGE&&l.some(f=>w.oKey.includes(f.drawingId))&&g.detachTransformerFrom(w)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(V.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([t,e])=>{t&&t.activeSheet$.subscribe(n=>{var c;if(!n)return;const r=t.getUnitId(),o=n.getSheetId();let s=!0;const a=this._renderManagerService.getRenderById(r),d=a==null?void 0:a.scene;if(d==null)return;const u=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new _.WorkbookViewPermission(r).id,new _.WorksheetViewPermission(r,o).id]).pipe(V.map(g=>g.every(h=>h.value)));l==null||l.pipe(V.filter(g=>g!==s),V.distinctUntilChanged()).subscribe({next:g=>{s=g,this._drawingManagerService.setDrawingVisible(g);const h=d.getAllObjects(),w=this._drawingManagerService.getDrawingData(r,o),f=Object.values(w);g?this._drawingManagerService.addNotification(f):(h.forEach(S=>{S.classType===N.RENDER_CLASS_TYPE.IMAGE&&f.some(C=>S.oKey.includes(C.drawingId))&&d.removeObject(S)}),u.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(r,o).id))==null||c.pipe(V.filter(g=>g.value!==s),V.distinctUntilChanged()).subscribe({complete:()=>{s=!0,this._drawingManagerService.setDrawingVisible(!0);const g=this._drawingManagerService.getDrawingData(r,o),h=Object.values(g);this._drawingManagerService.addNotification(h)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(V.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([t,e])=>{t&&t.activeSheet$.subscribe(n=>{var c;if(!n)return;const r=t.getUnitId(),o=n.getSheetId();let s=!0;const a=this._renderManagerService.getRenderById(r),d=a==null?void 0:a.scene;if(d==null)return;const u=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new _.WorkbookEditablePermission(r).id,new _.WorksheetEditPermission(r,o).id]).pipe(V.map(g=>g.every(h=>h.value)));l==null||l.pipe(V.filter(g=>g!==s),V.distinctUntilChanged()).subscribe({next:g=>{s=g,this._drawingManagerService.setDrawingEditable(g);const h=d.getAllObjects(),w=this._drawingManagerService.getDrawingData(r,o),f=Object.values(w);g?(h.forEach(S=>{S.classType===N.RENDER_CLASS_TYPE.IMAGE&&f.some(C=>S.oKey.includes(C.drawingId))&&d.attachTransformerTo(S)}),this._drawingManagerService.addNotification(f)):(h.forEach(S=>{S.classType===N.RENDER_CLASS_TYPE.IMAGE&&f.some(C=>S.oKey.includes(C.drawingId))&&d.detachTransformerFrom(S)}),u.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(r,o).id))==null||c.pipe(V.filter(g=>g.value!==s),V.distinctUntilChanged()).subscribe({complete:()=>{s=!0;const g=t.getUnitId(),h=n.getSheetId(),w=this._drawingManagerService.getDrawingData(g,h),f=Object.values(w),S=this._renderManagerService.getRenderById(g),C=S==null?void 0:S.scene;if(C==null)return;this._drawingManagerService.setDrawingEditable(!0),C.getAllObjects().forEach(D=>{D.classType===N.RENDER_CLASS_TYPE.IMAGE&&f.some(T=>D.oKey.includes(T.drawingId))&&C.detachTransformerFrom(D)})}})})}))}};fe=rn([m.OnLifecycle(m.LifecycleStages.Rendered,fe),re(0,O.IDrawingManagerService),re(1,N.IRenderManagerService),re(2,m.IPermissionService),re(3,m.IUniverInstanceService),re(4,m.Inject(m.UserManagerService))],fe);var on=Object.defineProperty,sn=Object.getOwnPropertyDescriptor,an=(i,t,e,n)=>{for(var r=n>1?void 0:n?sn(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&on(t,e,r),r},De=(i,t)=>(e,n)=>t(e,n,i);let we=class extends m.Disposable{constructor(t,e,n){super();Y(this,"_copyInfo");this._sheetClipboardService=t,this._renderManagerService=e,this._sheetDrawingService=n,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(t,e,n)=>this._collect(t,e,n),onPasteCells:(t,e,n,r)=>{const{copyType:o=W.COPY_TYPE.COPY,pasteType:s}=r,{range:a}=t||{},{range:d,unitId:u,subUnitId:l}=e;return this._generateMutations(d,{copyType:o,pasteType:s,copyRange:a,unitId:u,subUnitId:l})},onPastePlainText:(t,e)=>({undos:[],redos:[]})})}_collect(t,e,n){var g;const r=(g=this._renderManagerService.getRenderById(t))==null?void 0:g.with(W.SheetSkeletonManagerService);if(!r)return;const o=r.attachRangeWithCoord(n);if(!o)return;const{startX:s,endX:a,startY:d,endY:u}=o,l=this._sheetDrawingService.getDrawingData(t,e),c=[];Object.keys(l).forEach(h=>{const w=l[h],{transform:f}=w;if(w.anchorType!==p.SheetDrawingAnchorType.Both||!f)return;const{left:S=0,top:C=0,width:y=0,height:D=0}=f,{drawingStartX:T,drawingEndX:I,drawingStartY:b,drawingEndY:v}={drawingStartX:S,drawingEndX:S+y,drawingStartY:C,drawingEndY:C+D};s<=T&&I<=a&&d<=b&&v<=u&&c.push(w)}),c.length&&(this._copyInfo={drawings:c,unitId:t,subUnitId:e})}_generateMutations(t,e){var E;if(!this._copyInfo)return{redos:[],undos:[]};if([W.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,W.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,W.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,W.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(e.pasteType))return{redos:[],undos:[]};const{copyRange:n}=e;if(!n)return{redos:[],undos:[]};const{drawings:r,unitId:o,subUnitId:s}=this._copyInfo,{ranges:[a,d],mapFunc:u}=W.virtualizeDiscreteRanges([n,t]),{row:l,col:c}=u(a.startRow,a.startColumn),{row:g,col:h}=u(d.startRow,d.startColumn),w=(E=this._renderManagerService.getRenderById(o))==null?void 0:E.with(W.SheetSkeletonManagerService);if(!w)return{redos:[],undos:[]};const f=w.attachRangeWithCoord({startRow:l,endRow:l,startColumn:c,endColumn:c}),S=w.attachRangeWithCoord({startRow:g,endRow:g,startColumn:h,endColumn:h});if(!f||!S)return{redos:[],undos:[]};const C=[],y=[],D=S.startX-f.startX,T=S.startY-f.startY,I=g-l,b=h-c,v=e.copyType===W.COPY_TYPE.CUT,{_sheetDrawingService:P}=this;return r.forEach(L=>{const{transform:U,sheetTransform:R}=L;if(!U)return;const M={...L,unitId:o,subUnitId:s,drawingId:v?L.drawingId:m.Tools.generateRandomId(),transform:{...U,left:U.left+D,top:U.top+T},sheetTransform:{to:{...R.to,row:R.to.row+I,column:R.to.column+b},from:{...R.from,row:R.from.row+I,column:R.from.column+b}}};if(v){const{undo:j,redo:k,objects:K}=P.getBatchUpdateOp([M]);C.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:s,type:p.DrawingApplyType.UPDATE,op:k,objects:K}}),y.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:s,type:p.DrawingApplyType.UPDATE,op:j,objects:K}})}else{const{undo:j,redo:k,objects:K}=P.getBatchAddOp([M]);C.push({id:p.SetDrawingApplyMutation.id,params:{op:k,unitId:o,subUnitId:s,objects:K,type:p.DrawingApplyType.INSERT}}),y.push({id:p.SetDrawingApplyMutation.id,params:{op:j,unitId:o,subUnitId:s,objects:K,type:p.DrawingApplyType.REMOVE}})}}),{redos:C,undos:y}}};we=an([m.OnLifecycle(m.LifecycleStages.Ready,we),De(0,W.ISheetClipboardService),De(1,N.IRenderManagerService),De(2,p.ISheetDrawingService)],we);var Fe=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,dn=(i,t,e)=>t in i?Fe(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,ln=(i,t,e,n)=>{for(var r=n>1?void 0:n?cn(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&Fe(t,e,r),r},Ce=(i,t)=>(e,n)=>t(e,n,i),ke=(i,t,e)=>dn(i,typeof t!="symbol"?t+"":t,e);const un="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends m.Plugin{constructor(e={},n,r,o){super();Y(this,"_pluginConfig");this._injector=n,this._localeService=r,this._renderManagerService=o,this._pluginConfig=m.Tools.deepMerge({},Ft,e)}onStarting(e){super.onStarting(e),this._initDependencies(e)}onRendered(){this._registerRenderModules()}_initDependencies(e){const n=[[exports.SheetCanvasFloatDomManagerService],[ie,{useFactory:()=>this._injector.createInstance(ie,this._pluginConfig)}],[ge],[pe],[fe]],r=[he,me];n.forEach(o=>e.add(o)),r.forEach(o=>this._renderManagerService.registerRenderModule(m.UniverInstanceType.UNIVER_SHEET,o))}_registerRenderModules(){[[we]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(m.UniverInstanceType.UNIVER_SHEET,e))})}};ke(exports.UniverSheetsDrawingUIPlugin,"type",m.UniverInstanceType.UNIVER_SHEET);ke(exports.UniverSheetsDrawingUIPlugin,"pluginName",un);exports.UniverSheetsDrawingUIPlugin=ln([m.DependentOn(O.UniverDrawingPlugin,Z.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),Ce(1,m.Inject(m.Injector)),Ce(2,m.Inject(m.LocaleService)),Ce(3,N.IRenderManagerService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=B;exports.DeleteDrawingsCommand=be;exports.EditSheetDrawingOperation=Me;exports.GroupSheetDrawingCommand=Te;exports.InsertCellImageOperation=oe;exports.InsertFloatImageOperation=se;exports.InsertSheetDrawingCommand=_e;exports.MoveDrawingsCommand=te;exports.RemoveSheetDrawingCommand=ve;exports.SetDrawingArrangeCommand=Re;exports.SetSheetDrawingCommand=ae;exports.SidebarSheetDrawingOperation=ye;exports.UngroupSheetDrawingCommand=Ee;