@univerjs/sheets-drawing-ui 0.6.1 → 0.6.2

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