@univerjs/sheets-drawing-ui 0.6.0-nightly.202502141606 → 0.6.0-nightly.202502151605

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 A=Object.defineProperty;var F=(t,r,e)=>r in t?A(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e;var k=(t,r,e)=>F(t,typeof r!="symbol"?r+"":r,e);const g=require("@univerjs/core"),v=require("@univerjs/core/facade"),l=require("@univerjs/drawing"),R=require("@univerjs/engine-render"),c=require("@univerjs/sheets-drawing-ui"),f=require("@univerjs/sheets-ui"),w=require("@univerjs/sheets-drawing"),C=require("@univerjs/sheets-ui/facade"),G=require("@univerjs/sheets/facade"),b=require("@univerjs/ui");var x=Object.getOwnPropertyDescriptor,T=(t,r,e,i)=>{for(var n=i>1?void 0:i?x(r,e):r,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=a(n)||n);return n},E=(t,r)=>(e,i)=>r(e,i,t);function M(t,r){const{from:e,to:i,flipY:n=!1,flipX:s=!1,angle:a=0,skewX:d=0,skewY:o=0}=t.sheetTransform,{column:h,columnOffset:m,row:I,rowOffset:_}=e,p=f.convertPositionSheetOverGridToAbsolute(t.unitId,t.subUnitId,{from:e,to:i},r),{left:y,top:O,width:D,height:B}=p;return{...t,column:h,columnOffset:m,row:I,rowOffset:_,width:D,height:B,flipY:n,flipX:s,angle:a,skewX:d,skewY:o}}function U(t,r,e){const{column:i,columnOffset:n,row:s,rowOffset:a,flipY:d=!1,flipX:o=!1,angle:h=0,skewX:m=0,skewY:I=0,width:_,height:p}=t,y=f.convertPositionCellToSheetOverGrid(t.unitId,t.subUnitId,{column:i,columnOffset:n,row:s,rowOffset:a},_,p,r,e),{sheetTransform:O,transform:D}=y;return{...t,sheetTransform:{...O,flipY:d,flipX:o,angle:h,skewX:m,skewY:I},transform:{...D,flipY:d,flipX:o,angle:h,skewX:m,skewY:I}}}let S=class{constructor(t,r,e){k(this,"_image");this._injector=e,this._image={drawingId:g.generateRandomId(6),drawingType:g.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:g.ImageSourceType.BASE64,source:"",unitId:t,subUnitId:r,column:0,columnOffset:0,row:0,rowOffset:0,width:0,height:0}}setImage(t){const e=this._injector.get(R.IRenderManagerService).getRenderById(t.unitId);if(!e)throw new Error(`Render Unit with unitId ${t.unitId} not found`);const i=e.with(f.SheetSkeletonManagerService);return t.sheetTransform==null&&(t.sheetTransform={from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}),this._image=M(t,i),this}setSource(t,r){const e=r!=null?r:g.ImageSourceType.URL;return this._image.source=t,this._image.imageSourceType=e,this}getsource(){return this._image.source}getSourceType(){return this._image.imageSourceType}setColumn(t){return this._image.column=t,this}setRow(t){return this._image.row=t,this}setColumnOffset(t){return this._image.columnOffset=t,this}setRowOffset(t){return this._image.rowOffset=t,this}setWidth(t){return this._image.width=t,this}setHeight(t){return this._image.height=t,this}setAnchorType(t){return this._image.anchorType=t,this}setCropTop(t){return this._initializeSrcRect(),this._image.srcRect.top=t,this}setCropLeft(t){return this._initializeSrcRect(),this._image.srcRect.left=t,this}setCropBottom(t){return this._initializeSrcRect(),this._image.srcRect.bottom=t,this}setCropRight(t){return this._initializeSrcRect(),this._image.srcRect.right=t,this}_initializeSrcRect(){this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0})}setRotate(t){return this._image.angle=t,this}setUnitId(t){return this._image.unitId=t,this}setSubUnitId(t){return this._image.subUnitId=t,this}async buildAsync(){const r=this._injector.get(R.IRenderManagerService).getRenderById(this._image.unitId);if(!r)throw new Error(`Render Unit with unitId ${this._image.unitId} not found`);const e=r.with(f.ISheetSelectionRenderService),i=r.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 U(this._image,e,i)}};S=T([E(2,g.Inject(g.Injector))],S);let u=class extends v.FBase{constructor(t,r,e){super(),this._image=t,this._commandService=r,this._injector=e}getId(){return this._image.drawingId}getType(){return this._image.drawingType}remove(){return this._commandService.syncExecuteCommand(c.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}toBuilder(){const t=this._injector.createInstance(S);return t.setImage(this._image),t}setSource(t,r){const e=r!=null?r:g.ImageSourceType.URL;return this._image.source=t,this._image.imageSourceType=e,this._commandService.syncExecuteCommand(c.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}async setPositionAsync(t,r,e,i){const n=this.toBuilder();n.setColumn(r),n.setRow(t),e!=null&&n.setRowOffset(e),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(t,r){const e=this.toBuilder();e.setWidth(t),e.setHeight(r);const i=await e.buildAsync();return this._commandService.syncExecuteCommand(c.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[i]})}setCrop(t,r,e,i){return this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0}),t!=null&&(this._image.srcRect.top=t),r!=null&&(this._image.srcRect.left=r),e!=null&&(this._image.srcRect.bottom=e),i!=null&&(this._image.srcRect.right=i),this._commandService.syncExecuteCommand(c.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}setRotate(t){return this._image.sheetTransform.angle=t,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=T([E(1,g.ICommandService),E(2,g.Inject(g.Injector))],u);class j extends G.FWorksheet{addFloatDomToPosition(r,e){const i=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),{key:s,disposableCollection:a}=C.transformComponentKey(r,this._injector.get(b.ComponentManager)),o=this._injector.get(c.SheetCanvasFloatDomManagerService).addFloatDomToPosition({...r,componentKey:s,unitId:i,subUnitId:n},e);return o?(a.add(o.dispose),{id:o.id,dispose:()=>{a.dispose(),o.dispose()}}):(a.dispose(),null)}addFloatDomToRange(r,e,i,n){const s=this._workbook.getUnitId(),a=this._worksheet.getSheetId(),{key:d,disposableCollection:o}=C.transformComponentKey(e,this._injector.get(b.ComponentManager)),m=this._injector.get(c.SheetCanvasFloatDomManagerService).addFloatDomToRange(r.getRange(),{...e,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,e,i,n){const s=this._workbook.getUnitId(),a=this._worksheet.getSheetId(),{key:d,disposableCollection:o}=C.transformComponentKey(e,this._injector.get(b.ComponentManager)),m=this._injector.get(c.SheetCanvasFloatDomManagerService).addFloatDomToColumnHeader(r,{...e,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,e,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)}e!==void 0?a.setColumn(e):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 e=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:e}),this}deleteImages(r){const e=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:e}),this}getImages(){const e=this._injector.get(w.ISheetDrawingService).getDrawingData(this._fWorkbook.getId(),this.getSheetId()),i=[];for(const n in e){const s=e[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 e=this._injector.get(w.ISheetDrawingService).getFocusDrawings(),i=[];for(const n in e){const s=e[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 e=this._injector.get(w.ISheetDrawingService);return g.toDisposable(e.add$.subscribe(i=>{const n=i.map(s=>this._injector.createInstance(u,e.getDrawingByParam(s)));r(n)}))}onImageDeleted(r){const e=this._injector.get(w.ISheetDrawingService);return g.toDisposable(e.remove$.subscribe(i=>{const n=i.map(s=>this._injector.createInstance(u,e.getDrawingByParam(s)));r(n)}))}onImageChanged(r){const e=this._injector.get(w.ISheetDrawingService);return g.toDisposable(e.update$.subscribe(i=>{const n=i.map(s=>this._injector.createInstance(u,e.getDrawingByParam(s)));r(n)}))}newOverGridImage(){const r=this._fWorkbook.getId(),e=this.getSheetId();return this._injector.createInstance(S,r,e)}}G.FWorksheet.extend(j);class P extends v.FEnum{get DrawingType(){return g.DrawingTypeEnum}get ImageSourceType(){return g.ImageSourceType}get SheetDrawingAnchorType(){return w.SheetDrawingAnchorType}}v.FEnum.extend(P);class W 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(W);class H extends v.FUniver{_initialize(r){const e=r.get(g.ICommandService);this.registerEventHandler(this.Event.BeforeOverGridImageInsert,()=>e.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,()=>e.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(l.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,()=>e.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(l.IDrawingManagerService),o=[];a.forEach(m=>{const I=d.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 d.updateNotification(a),new Error("Canceled by BeforeOverGridImageChange event")})),this.registerEventHandler(this.Event.BeforeOverGridImageSelect,()=>e.beforeCommandExecuted(i=>{if(i.id!==l.SetDrawingSelectedOperation.id)return;const n=i.params,s=this.getActiveWorkbook();if(s==null)return;const a=r.get(l.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,()=>e.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,()=>e.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,()=>e.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(l.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,()=>e.onCommandExecuted(i=>{if(i.id!==l.SetDrawingSelectedOperation.id)return;const n=i.params,s=this.getActiveWorkbook();if(s==null)return;const a=r.get(l.IDrawingManagerService),d=n.map(o=>a.getDrawingByParam(o));this.fireEvent(this.Event.OverGridImageSelected,{workbook:s,selectedImages:this._createFOverGridImage(d)})}))}_createFOverGridImage(r){return r.map(e=>this._injector.createInstance(u,e))}}v.FUniver.extend(H);
1
+ "use strict";var A=Object.defineProperty;var F=(r,t,e)=>t in r?A(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var k=(r,t,e)=>F(r,typeof t!="symbol"?t+"":t,e);const g=require("@univerjs/core"),v=require("@univerjs/core/facade"),l=require("@univerjs/drawing"),R=require("@univerjs/engine-render"),c=require("@univerjs/sheets-drawing-ui"),f=require("@univerjs/sheets-ui"),w=require("@univerjs/sheets-drawing"),C=require("@univerjs/sheets-ui/facade"),G=require("@univerjs/sheets/facade"),b=require("@univerjs/ui");var x=Object.defineProperty,M=Object.getOwnPropertyDescriptor,T=(r,t,e,i)=>{for(var n=i>1?void 0:i?M(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&x(t,e,n),n},E=(r,t)=>(e,i)=>t(e,i,r);function U(r,t){const{from:e,to:i,flipY:n=!1,flipX:s=!1,angle:a=0,skewX:d=0,skewY:o=0}=r.sheetTransform,{column:h,columnOffset:m,row:I,rowOffset:_}=e,p=f.convertPositionSheetOverGridToAbsolute(r.unitId,r.subUnitId,{from:e,to:i},t),{left:O,top:y,width:D,height:B}=p;return{...r,column:h,columnOffset:m,row:I,rowOffset:_,width:D,height:B,flipY:n,flipX:s,angle:a,skewX:d,skewY:o}}function j(r,t,e){const{column:i,columnOffset:n,row:s,rowOffset:a,flipY:d=!1,flipX:o=!1,angle:h=0,skewX:m=0,skewY:I=0,width:_,height:p}=r,O=f.convertPositionCellToSheetOverGrid(r.unitId,r.subUnitId,{column:i,columnOffset:n,row:s,rowOffset:a},_,p,t,e),{sheetTransform:y,transform:D}=O;return{...r,sheetTransform:{...y,flipY:d,flipX:o,angle:h,skewX:m,skewY:I},transform:{...D,flipY:d,flipX:o,angle:h,skewX:m,skewY:I}}}let S=class{constructor(r,t,e){k(this,"_image");this._injector=e,this._image={drawingId:g.generateRandomId(6),drawingType:g.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:g.ImageSourceType.BASE64,source:"",unitId:r,subUnitId:t,column:0,columnOffset:0,row:0,rowOffset:0,width:0,height:0}}setImage(r){const e=this._injector.get(R.IRenderManagerService).getRenderById(r.unitId);if(!e)throw new Error(`Render Unit with unitId ${r.unitId} not found`);const i=e.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=U(r,i),this}setSource(r,t){const e=t!=null?t:g.ImageSourceType.URL;return this._image.source=r,this._image.imageSourceType=e,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 t=this._injector.get(R.IRenderManagerService).getRenderById(this._image.unitId);if(!t)throw new Error(`Render Unit with unitId ${this._image.unitId} not found`);const e=t.with(f.ISheetSelectionRenderService),i=t.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 j(this._image,e,i)}};S=T([E(2,g.Inject(g.Injector))],S);let u=class extends v.FBase{constructor(r,t,e){super(),this._image=r,this._commandService=t,this._injector=e}getId(){return this._image.drawingId}getType(){return this._image.drawingType}remove(){return this._commandService.syncExecuteCommand(c.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}toBuilder(){const r=this._injector.createInstance(S);return r.setImage(this._image),r}setSource(r,t){const e=t!=null?t:g.ImageSourceType.URL;return this._image.source=r,this._image.imageSourceType=e,this._commandService.syncExecuteCommand(c.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}async setPositionAsync(r,t,e,i){const n=this.toBuilder();n.setColumn(t),n.setRow(r),e!=null&&n.setRowOffset(e),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(r,t){const e=this.toBuilder();e.setWidth(r),e.setHeight(t);const i=await e.buildAsync();return this._commandService.syncExecuteCommand(c.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[i]})}setCrop(r,t,e,i){return this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0}),r!=null&&(this._image.srcRect.top=r),t!=null&&(this._image.srcRect.left=t),e!=null&&(this._image.srcRect.bottom=e),i!=null&&(this._image.srcRect.right=i),this._commandService.syncExecuteCommand(c.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}setRotate(r){return this._image.sheetTransform.angle=r,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=T([E(1,g.ICommandService),E(2,g.Inject(g.Injector))],u);class P extends G.FWorksheet{addFloatDomToPosition(t,e){const i=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),{key:s,disposableCollection:a}=C.transformComponentKey(t,this._injector.get(b.ComponentManager)),o=this._injector.get(c.SheetCanvasFloatDomManagerService).addFloatDomToPosition({...t,componentKey:s,unitId:i,subUnitId:n},e);return o?(a.add(o.dispose),{id:o.id,dispose:()=>{a.dispose(),o.dispose()}}):(a.dispose(),null)}addFloatDomToRange(t,e,i,n){const s=this._workbook.getUnitId(),a=this._worksheet.getSheetId(),{key:d,disposableCollection:o}=C.transformComponentKey(e,this._injector.get(b.ComponentManager)),m=this._injector.get(c.SheetCanvasFloatDomManagerService).addFloatDomToRange(t.getRange(),{...e,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(t,e,i,n){const s=this._workbook.getUnitId(),a=this._worksheet.getSheetId(),{key:d,disposableCollection:o}=C.transformComponentKey(e,this._injector.get(b.ComponentManager)),m=this._injector.get(c.SheetCanvasFloatDomManagerService).addFloatDomToColumnHeader(t,{...e,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(t,e,i,n,s){const a=this.newOverGridImage();if(typeof t=="string")a.setSource(t);else{const h=await t.getBlob().getDataAsString();a.setSource(h,g.ImageSourceType.BASE64)}e!==void 0?a.setColumn(e):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(t){const e=t.map(i=>(i.unitId=this._fWorkbook.getId(),i.subUnitId=this.getSheetId(),i));return this._commandService.syncExecuteCommand(c.InsertSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:e}),this}deleteImages(t){const e=t.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:e}),this}getImages(){const e=this._injector.get(w.ISheetDrawingService).getDrawingData(this._fWorkbook.getId(),this.getSheetId()),i=[];for(const n in e){const s=e[n];s.drawingType===g.DrawingTypeEnum.DRAWING_IMAGE&&i.push(this._injector.createInstance(u,s))}return i}getImageById(t){const i=this._injector.get(w.ISheetDrawingService).getDrawingByParam({unitId:this._fWorkbook.getId(),subUnitId:this.getSheetId(),drawingId:t});return i&&i.drawingType===g.DrawingTypeEnum.DRAWING_IMAGE?this._injector.createInstance(u,i):null}getActiveImages(){const e=this._injector.get(w.ISheetDrawingService).getFocusDrawings(),i=[];for(const n in e){const s=e[n];i.push(this._injector.createInstance(u,s))}return i}updateImages(t){return this._commandService.syncExecuteCommand(c.SetSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}onImageInserted(t){const e=this._injector.get(w.ISheetDrawingService);return g.toDisposable(e.add$.subscribe(i=>{const n=i.map(s=>this._injector.createInstance(u,e.getDrawingByParam(s)));t(n)}))}onImageDeleted(t){const e=this._injector.get(w.ISheetDrawingService);return g.toDisposable(e.remove$.subscribe(i=>{const n=i.map(s=>this._injector.createInstance(u,e.getDrawingByParam(s)));t(n)}))}onImageChanged(t){const e=this._injector.get(w.ISheetDrawingService);return g.toDisposable(e.update$.subscribe(i=>{const n=i.map(s=>this._injector.createInstance(u,e.getDrawingByParam(s)));t(n)}))}newOverGridImage(){const t=this._fWorkbook.getId(),e=this.getSheetId();return this._injector.createInstance(S,t,e)}}G.FWorksheet.extend(P);class W extends v.FEnum{get DrawingType(){return g.DrawingTypeEnum}get ImageSourceType(){return g.ImageSourceType}get SheetDrawingAnchorType(){return w.SheetDrawingAnchorType}}v.FEnum.extend(W);class H 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(H);class q extends v.FUniver{_initialize(t){const e=t.get(g.ICommandService);this.registerEventHandler(this.Event.BeforeOverGridImageInsert,()=>e.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,()=>e.beforeCommandExecuted(i=>{if(i.id!==c.RemoveSheetDrawingCommand.id)return;const n=i.params,s=this.getActiveWorkbook();if(s==null||n==null)return;const a=t.get(l.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,()=>e.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=t.get(l.IDrawingManagerService),o=[];a.forEach(m=>{const I=d.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 d.updateNotification(a),new Error("Canceled by BeforeOverGridImageChange event")})),this.registerEventHandler(this.Event.BeforeOverGridImageSelect,()=>e.beforeCommandExecuted(i=>{if(i.id!==l.SetDrawingSelectedOperation.id)return;const n=i.params,s=this.getActiveWorkbook();if(s==null)return;const a=t.get(l.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,()=>e.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,()=>e.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,()=>e.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=t.get(l.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,()=>e.onCommandExecuted(i=>{if(i.id!==l.SetDrawingSelectedOperation.id)return;const n=i.params,s=this.getActiveWorkbook();if(s==null)return;const a=t.get(l.IDrawingManagerService),d=n.map(o=>a.getDrawingByParam(o));this.fireEvent(this.Event.OverGridImageSelected,{workbook:s,selectedImages:this._createFOverGridImage(d)})}))}_createFOverGridImage(t){return t.map(e=>this._injector.createInstance(u,e))}}v.FUniver.extend(q);
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);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 Kt=Object.defineProperty;var zt=(i,r,t)=>r in i?Kt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t;var J=(i,r,t)=>zt(i,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@univerjs/core"),At=require("@univerjs/docs-drawing"),A=require("@univerjs/drawing"),fe=require("@univerjs/drawing-ui"),W=require("@univerjs/engine-render"),m=require("@univerjs/sheets-drawing"),O=require("@univerjs/sheets-ui"),x=require("@univerjs/ui"),U=require("rxjs"),_=require("@univerjs/sheets"),V=require("react/jsx-runtime"),re=require("react"),Nt=require("@univerjs/docs-ui"),ce=require("@univerjs/design"),qt="sheets-drawing-ui.config",Ot={},G={id:"sheet.operation.clear-drawing-transformer",type:u.CommandType.MUTATION,handler:(i,r)=>{const t=i.get(W.IRenderManagerService);return r.forEach(e=>{var n,o;(o=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},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(C=>{const{unitId:T}=C;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(A.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(A.SetDrawingSelectedOperation.id,[r]),t.executeCommand(wt.id,{value:"open"}),!0)}},Zt="univer-upload-loading",Jt="univer-upload-loading-body",Qt="univer-upload-loading-body-animation",en="univer-UniverCircleAnimation",tn="univer-upload-loading-body-text",qe={uploadLoading:Zt,uploadLoadingBody:Jt,uploadLoadingBodyAnimation:Qt,univerCircleAnimation:en,uploadLoadingBodyText:tn},nn=()=>{const i=x.useDependency(A.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 rn=Object.defineProperty,on=Object.getOwnPropertyDescriptor,sn=(i,r,t,e)=>{for(var n=e>1?void 0:e?on(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&rn(r,t,n),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(U.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(u.UniverInstanceType.UNIVER_SHEET).pipe(U.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(nn,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(A.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=sn([he(0,u.Inject(u.Injector)),he(1,A.IDrawingManagerService),he(2,u.Inject(O.SheetCanvasPopManagerService)),he(3,W.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:W.precisionTo(t-c.startX,1),row:c.actualRow,rowOffset:W.precisionTo(e-c.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+o);if(h==null)return;const w={column:h.actualColumn,columnOffset:W.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:W.precisionTo(e+o-h.startY,1)};return{flipY:s,flipX:a,angle:d,skewX:g,skewY:l,from:p,to:w}}var an=Object.defineProperty,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=(e?s(r,t,n):s(n))||n);return e&&n&&an(r,t,n),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=dn([Ze(1,m.ISheetDrawingService),Ze(2,A.IDrawingManagerService),Ze(3,u.Inject(O.ISheetSelectionRenderService)),Ze(4,u.Inject(O.SheetSkeletonManagerService))],pt);function ln(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:s,drawingId:a}=e,d=W.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 un(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=W.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:un(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}},We={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(C=>C.unitId),d=n.getBatchAddOp(s),{unitId:g,subUnitId:l,undo:c,redo:p,objects:h}=d,w=o.onCommandExecute({id:We.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}},Be={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:ln(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 gn=Object.defineProperty,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=(e?s(r,t,n):s(n))||n);return e&&n&&gn(r,t,n),n},te=(i,r)=>(t,e)=>r(t,e,i);function mn(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 Wt(i,r,t,e,n){var D;const{rotatedHeight:o,rotatedWidth:s}=mn(t,e,n),d=i.get(W.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:A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),t=r.length;return t>A.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:ce.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(A.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:A.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===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ce.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(A.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):M===A.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ce.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):M===A.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 A.getImageSize(g||""),{width:h,height:w}=this._context.scene;this._imageIoService.addImageSourceCache(d,a,p);let f=1;if(l>A.DRAWING_IMAGE_WIDTH_LIMIT||c>A.DRAWING_IMAGE_HEIGHT_LIMIT){const D=A.DRAWING_IMAGE_WIDTH_LIMIT/l,M=A.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(We.id,{unitId:n,drawings:[v]})}async _insertCellImage(r){let t;try{t=await this._imageIoService.saveImage(r)}catch(S){const v=S.message;v===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ce.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(A.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):v===A.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ce.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):v===A.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 A.getImageSize(s||"");this._imageIoService.addImageSourceCache(o,n,g);const l=this._workbookSelections.getCurrentLastSelection();if(!l)return!1;const c=u.createDocumentModelWithStyle("",{}),p=Wt(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(Be.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(A.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=pn([te(1,u.Inject(O.SheetSkeletonManagerService)),te(2,u.ICommandService),te(3,O.ISheetSelectionRenderService),te(4,A.IImageIoService),te(5,x.ILocalFileService),te(6,m.ISheetDrawingService),te(7,A.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 fn=Object.defineProperty,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=(e?s(r,t,n):s(n))||n);return e&&n&&fn(r,t,n),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=Wt(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=Sn([we(0,u.ICommandService),we(1,u.Inject(_.SheetInterceptorService)),we(2,u.IUniverInstanceService),we(3,u.Inject(u.Injector)),we(4,A.IDrawingManagerService),we(5,u.Inject(At.DocDrawingController)),we(6,u.Inject(O.IEditorBridgeService))],it);var _n=Object.defineProperty,vn=Object.getOwnPropertyDescriptor,In=(i,r,t,e)=>{for(var n=e>1?void 0:e?vn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&_n(r,t,n),n},Pt=(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=In([Pt(0,u.Inject(O.IAutoFillService)),Pt(1,u.Inject(u.Injector))],ot);var Dn=Object.defineProperty,Cn=Object.getOwnPropertyDescriptor,yn=(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=(e?s(r,t,n):s(n))||n);return e&&n&&Dn(r,t,n),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=yn([Je(0,u.Inject(O.HoverManagerService)),Je(1,u.Inject(W.IRenderManagerService)),Je(2,u.Inject(_.SheetsSelectionsService)),Je(3,u.Inject(fe.DrawingRenderService))],st);const $e={id:"sheet.command.insert-float-image",type:u.CommandType.COMMAND,handler:async(i,r)=>{var o,s;const e=(o=i.get(W.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(W.IRenderManagerService).getCurrentTypeOfRenderer(u.UniverInstanceType.UNIVER_SHEET))==null?void 0:t.with(je).insertCellImage())!=null?e:!1}};var Mn=Object.defineProperty,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=(e?s(r,t,n):s(n))||n);return e&&n&&Mn(r,t,n),n},Ue=(i,r)=>(t,e)=>r(t,e,i);const Bt="image/png";function bn(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:Bt})}function En(i){const r=new ClipboardItem({[Bt]:bn(i)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function On(){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 Ut=[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=On();s.drawingType===u.DrawingTypeEnum.DRAWING_IMAGE&&s.imageSourceType===A.ImageSourceType.BASE64?En(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:$e.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:C,drawingStartY:T,drawingEndY:I}={drawingStartX:S,drawingEndX:S+D,drawingStartY:v,drawingEndY:v+M};s<=R&&C<=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(Ut.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(Ut.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,C=M.startY-D.startY,T=S-w,I=v-f;return this._generateMutations(l,{unitId:e,subUnitId:n,getTransform:(b,j)=>{var P,E;return{transform:{...b,left:((P=b==null?void 0:b.left)!=null?P:0)+R,top:((E=b==null?void 0:b.top)!=null?E:0)+C},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=Rn([Ue(0,O.ISheetClipboardService),Ue(1,W.IRenderManagerService),Ue(2,A.IDrawingManagerService),Ue(3,x.IClipboardInterfaceService),Ue(4,u.ICommandService)],at);var Pn=Object.defineProperty,Un=Object.getOwnPropertyDescriptor,An=(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=(e?s(r,t,n):s(n))||n);return e&&n&&Pn(r,t,n),n},Ae=(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=U.combineLatest([i,r]);this.disposeWithMe(t.pipe(U.switchMap(([e,n])=>e?e.activeSheet$.pipe(U.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),U.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(i,r){this._drawingManagerService.setDrawingVisible(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===W.RENDER_CLASS_TYPE.IMAGE&&o.some(l=>g.oKey.includes(l.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=U.combineLatest([i,r]);this.disposeWithMe(t.pipe(U.switchMap(([e,n])=>e?e.activeSheet$.pipe(U.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),U.EMPTY))).subscribe())}_handleDrawingEditableFalse(i,r){this._drawingManagerService.setDrawingEditable(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===W.RENDER_CLASS_TYPE.IMAGE&&o.some(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(U.combineLatest([i,r]).pipe(U.switchMap(([t,e])=>t?t.activeSheet$.pipe(U.switchMap(n=>{if(!n)return U.EMPTY;const o=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),d=a==null?void 0:a.scene;if(!d)return U.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new _.WorkbookViewPermission(o).id,new _.WorksheetViewPermission(o,s).id]).pipe(U.map(c=>c.every(p=>p.value)),U.distinctUntilChanged()).pipe(U.map(c=>({permission:c,scene:d,transformer:g,unitId:o,subUnitId:s})))})):U.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===W.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(U.combineLatest([i,r]).pipe(U.switchMap(([t,e])=>t?t.activeSheet$.pipe(U.switchMap(n=>{if(!n)return U.EMPTY;const o=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),d=a==null?void 0:a.scene;if(!d)return U.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new _.WorkbookEditablePermission(o).id,new _.WorksheetEditPermission(o,s).id]).pipe(U.map(c=>c.every(p=>p.value)),U.distinctUntilChanged()).pipe(U.map(c=>({permission:c,scene:d,transformer:g,unitId:o,subUnitId:s})))})):U.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===W.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>l.oKey.includes(c.drawingId))&&e.attachTransformerTo(l)}),this._drawingManagerService.addNotification(g)):(a.forEach(l=>{l.classType===W.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===W.RENDER_CLASS_TYPE.IMAGE&&g.some(p=>c.oKey.includes(p.drawingId))&&a.detachTransformerFrom(c)})}}))}};ct=An([Ae(0,A.IDrawingManagerService),Ae(1,W.IRenderManagerService),Ae(2,u.IPermissionService),Ae(3,u.IUniverInstanceService),Ae(4,u.Inject(u.UserManagerService))],ct);var Nn=Object.defineProperty,jn=Object.getOwnPropertyDescriptor,Wn=(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=(e?s(r,t,n):s(n))||n);return e&&n&&Nn(r,t,n),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=Wn([Qe(0,u.Inject(O.SheetPrintInterceptorService)),Qe(1,u.Inject(fe.DrawingRenderService)),Qe(2,A.IDrawingManagerService),Qe(3,W.IRenderManagerService)],dt);var Bn=Object.defineProperty,$n=Object.getOwnPropertyDescriptor,xn=(i,r,t,e)=>{for(var n=e>1?void 0:e?$n(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&Bn(r,t,n),n},pe=(i,r)=>(t,e)=>r(t,e,i);const Ln=[_.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],Yn=[_.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(!Ln.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 C=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);C=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);C=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);C=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);C=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}if(C!=null&&T!=null){const I=K(C,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:C,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 C=0;C<t.length;C++){const T=t[C],{startRow:I,endRow:N,startColumn:b,endColumn:j}=T;if(R<b)continue;if(w===m.SheetDrawingAnchorType.Position){let y=null,$=null;if(D>=b&&D<=j){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:D,endColumn:j,startRow:f.row,endRow:S.row});if(B==null)return;$={...h,left:B.startX}}if($!=null&&(y=F($,this._selectionRenderService),y!=null&&$!=null)){n.push({...c,sheetTransform:y,transform:$});break}this._remainDrawingSize(h,n,c);continue}if(D>=b&&R<=j)continue;let P=null,E=null;if(D>=b&&D<=j){const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:D,endColumn:j,startRow:f.row,endRow:S.row});if(y==null)return;E={...h,left:(y==null?void 0:y.startX)||0,width:((h==null?void 0:h.width)||0)-y.endX+y.startX}}else if(R>=b&&R<=j){const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:R,startRow:f.row,endRow:S.row});if(y==null)return;E={...h,left:y.startX-((h==null?void 0:h.width)||0)}}else{const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:j,startRow:f.row,endRow:S.row});if(y==null)return;if(E={...h,width:((h==null?void 0:h.width)||0)-y.endX+y.startX},P=F(E,this._selectionRenderService),P!=null&&E!=null){o.push({...c,sheetTransform:P,transform:E});break}}if(E!=null&&(P=F(E,this._selectionRenderService)),E!=null&&P!=null){n.push({...c,sheetTransform:P,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 C=0;C<t.length;C++){const T=t[C],{startRow:I,endRow:N,startColumn:b,endColumn:j}=T;if(M<I)continue;if(w===m.SheetDrawingAnchorType.Position){let y=null,$=null;if(v>=I&&v<=N){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:v,endRow:N});if(B==null)return;$={...h,top:B.startY}}if($!=null&&(y=F($,this._selectionRenderService),y!=null&&$!=null)){n.push({...c,sheetTransform:y,transform:$});break}this._remainDrawingSize(h,n,c);continue}if(v>=I&&M<=N)continue;let P=null,E=null;if(v>=I&&v<=N){const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:v,endRow:N});if(y==null)return;E={...h,top:(y==null?void 0:y.startY)||0,height:((h==null?void 0:h.height)||0)-y.endY+y.startY}}else if(M>=I&&M<=N){const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:I,endRow:M});if(y==null)return;E={...h,top:y.startY-((h==null?void 0:h.height)||0)}}else{const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:S.column,startRow:I,endRow:N});if(y==null)return;if(E={...h,height:((h==null?void 0:h.height)||0)-y.endY+y.startY},P=F(E,this._selectionRenderService),P!=null&&E!=null){o.push({...c,sheetTransform:P,transform:E});break}}if(E!=null&&(P=F(E,this._selectionRenderService)),E!=null&&P!=null){n.push({...c,sheetTransform:P,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:C,endColumn:T}=D;if(f<M||S<C)continue;if(l===m.SheetDrawingAnchorType.Position&&(h<=M&&f>=R||w<=C&&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(C=>{const T=p[C];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:P=0}=I,{drawingStartX:E,drawingEndX:y,drawingStartY:$,drawingEndY:B}={drawingStartX:N,drawingEndX:N+j,drawingStartY:b,drawingEndY:b+P};d<=E&&y<=g&&l<=$&&B<=c&&h.push(T)});const w=[],f=[],S=r.startRow-t.startRow,v=r.startColumn-t.startColumn,D=h.map(C=>{const T=C.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:C.drawingId,transform:N,sheetTransform:I}});if(D.length){const C=this._sheetDrawingService.getBatchUpdateOp(D),{undo:T,redo:I,objects:N}=C;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 C=this._expandRow(f,S,s,a,v);D=C==null?void 0:C.newSheetTransform,M=C==null?void 0:C.newTransform}else{const{from:C,to:T}=f,{row:I}=C,{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 C=this._expandCol(f,S,s,a,v);D=C==null?void 0:C.newSheetTransform,M=C==null?void 0:C.newTransform}else{const{from:C,to:T}=f,{column:I}=C,{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=>{Yn.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:C}=v;if(u.Rectangle.intersects({startRow:D,endRow:M,startColumn:R,endColumn:C},{startRow:p,endRow:w,startColumn:h,endColumn:f})||p>M||h>C){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=xn([pe(1,W.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,A.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)},kn=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},$t=re.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,o=i.extend,s=kn(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),d=re.useRef("_".concat(Hn()));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},Fn(i,t,n)),e),(Gn(i,t).children||[]).map(function(o,s){return xt(o,"".concat(r,"-").concat(i.tag,"-").concat(s),t,void 0,n)}))}function Fn(i,r,t){var e=ne({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1);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 Gn(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 Hn(){return Math.random().toString(36).substring(2,8)}$t.displayName="UniverIcon";var Vn={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($t,Object.assign({},i,{id:"add-image-single",ref:r,icon:Vn}))});Lt.displayName="AddImageSingle";const Ct={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(Be.id,{unitId:a,drawings:d})?(t.syncExecuteCommand(G.id,[a]),!0):!1}},Yt="addition-and-subtraction-single",yt="sheet.menu.image";function Xn(i){return{id:yt,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:$e.id,title:"sheetImage.upload.float",type:x.MenuItemType.BUTTON,hidden$:x.getMenuHiddenObservable(i,u.UniverInstanceType.UNIVER_SHEET)}}function zn(i){return{id:Dt.id,title:"sheetImage.upload.cell",type:x.MenuItemType.BUTTON}}const qn="univer-image-common-panel",Zn="univer-image-common-panel-grid",Jn="univer-image-common-panel-border",Qn="univer-image-common-panel-title",er="univer-image-common-panel-subtitle",tr="univer-image-common-panel-row",nr="univer-image-common-panel-row-vertical",rr="univer-image-common-panel-column",ir="univer-image-common-panel-column-center",or="univer-image-common-panel-inline",sr="univer-image-common-panel-span2",ar="univer-image-common-panel-span3",cr="univer-image-common-panel-input",dr="univer-sheet-image-menu",lr="univer-sheet-image-menu-input",me={imageCommonPanel:qn,imageCommonPanelGrid:Zn,imageCommonPanelBorder:Jn,imageCommonPanelTitle:Qn,imageCommonPanelSubtitle:er,imageCommonPanelRow:tr,imageCommonPanelRowVertical:nr,imageCommonPanelColumn:rr,imageCommonPanelColumnCenter:ir,imageCommonPanelInline:or,imageCommonPanelSpan2:sr,imageCommonPanelSpan3:ar,imageCommonPanelInput:cr,sheetImageMenu:dr,sheetImageMenuInput:lr};function kt(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=kt(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=kt(i))&&(e&&(e+=" "),e+=r);return e}const ur=i=>{var M;const r=x.useDependency(u.ICommandService),t=x.useDependency(u.LocaleService),e=x.useDependency(A.IDrawingManagerService),n=x.useDependency(W.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,C){const T=[];return R.forEach(I=>{const{oKey:N}=I,b=C.getDrawingOKey(N);if(b==null)return T.push(null),!0;const{unitId:j,subUnitId:P,drawingId:E,drawingType:y,anchorType:$,sheetTransform:B}=b;T.push({unitId:j,subUnitId:P,drawingId:E,anchorType:$,sheetTransform:B,drawingType:y})}),T}re.useEffect(()=>{const R=l.clearControl$.subscribe(T=>{T===!0&&p(!1)}),C=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()=>{C.unsubscribe(),R.unsubscribe()}},[]);function v(R){f(R);const C=e.getFocusDrawings();if(C.length===0)return;const T=C.map(I=>({unitId:I.unitId,subUnitId:I.subUnitId,drawingId:I.drawingId,anchorType:R}));r.executeCommand(Be.id,{unitId:C[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")})]})})})]})},gr=()=>{const i=x.useDependency(A.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(ur,{drawings:t})]})},hr={[x.RibbonStartGroup.FORMULAS_INSERT]:{[yt]:{order:3,menuItemFactory:Xn,[$e.id]:{order:0,menuItemFactory:Kn},[Dt.id]:{order:1,menuItemFactory:zn}}}};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 pr={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}},mr={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}},fr={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}},wr={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}},Sr={id:Ct.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:xe,binding:x.KeyCode.DELETE,mac:x.KeyCode.BACKSPACE};var _r=Object.defineProperty,vr=Object.getOwnPropertyDescriptor,Ir=(i,r,t,e)=>{for(var n=e>1?void 0:e?vr(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&_r(r,t,n),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,gr))}_initMenus(){this._menuManagerService.mergeMenu(hr)}_initCommands(){[$e,Dt,We,Te,Be,wt,G,St,_t,It,Re,Ct,vt].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[pr,mr,fr,wr,Sr].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};lt=Ir([Me(0,u.Inject(x.ComponentManager)),Me(1,x.IMenuManagerService),Me(2,u.ICommandService),Me(3,x.IShortcutService),Me(4,A.IDrawingManagerService),Me(5,u.Inject(_.SheetsSelectionsService))],lt);var Dr=Object.defineProperty,Cr=Object.getOwnPropertyDescriptor,yr=(i,r,t,e)=>{for(var n=e>1?void 0:e?Cr(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&Dr(r,t,n),n},Se=(i,r)=>(t,e)=>r(t,e,i);function Mr(i,r,t,e,n){const{scaleX:o,scaleY:s}=r.getAncestorScale(),a=r.getViewport(W.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:C}=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"&&(C=0),I==="VERTICAL"&&(R=0);let P=0,E=0;const y=t.rowStartY(l-p)+b,$=t.colStartX(g-c)+N,B=t.rowStartY(l)+b,X=t.colStartX(g)+N;if(c===0)h.left=!1,P=(w-R)*o,E=(f-R)*o;else{const Q=w-($-N),q=f-($-N);f<X?(P=Q*o,E=q*o):w<=X&&f>=X?(P=Q*o,E=Math.max(M,(f-R)*o)):w>X&&(h.left=!1,P=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-C)*s,z=(v-C)*s;else{const Q=S-(y-b),q=v-(y-b);v<B?(H=Q*s,z=q*s):S<=B&&v>=B?(H=Q*s,z=Math.max(D,(v-C)*s)):S>B&&(h.top=!1,H=Math.max((S-C)*s,D),z=Math.max((v-C)*s,D))}return P=Math.max(P,j.left),H=Math.max(H,j.top),E=Math.max(E,j.left),z=Math.max(z,j.top),{left:P,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=Mr(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 U.Subject);J(this,"transformChange$",this._transformChange$.asObservable());J(this,"_add$",new U.Subject);J(this,"add$",this._add$.asObservable());J(this,"_remove$",new U.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(U.filter(t=>t===u.LifecycleStages.Rendered),U.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:C,angle:T,flipX:I,flipY:N,skewX:b,skewY:j}=p,P=A.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),E=S.getObject(P);if(E!=null){E.transformByState({left:D,top:M,width:R,height:C,angle:T,flipX:I,flipY:N,skewX:b,skewY:j});return}const y={left:D,top:M,width:R,height:C,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},$=h===u.DrawingTypeEnum.DRAWING_CHART;if($){const Y=w?w.backgroundColor:"white";y.fill=Y,y.rotateEnabled=!1,w&&w.border&&(y.stroke=w.border),y.paintFirst="stroke",y.strokeWidth=1,y.borderEnabled=!1,y.radius=8}const B=new W.Rect(P,y);$&&B.setObjectType(W.ObjectType.CHART),S.addObject(B,W.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo(B);const X=this._ensureMap(n,o),H=new u.DisposableCollection,z=ge(B,f.renderUnit,c.skeleton,a.worksheet),ie=new U.BehaviorSubject(z),Q={dispose:H,rect:B,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=B.onTransformChange$.subscribeEvent(()=>{const Y=ge(B,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=A.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(U.switchMap(e=>e?e.activeSheet$:U.of(null)),U.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}),U.switchMap(e=>e?u.fromEventSubject(e.render.scene.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(U.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):U.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=A.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),l=d.getObject(g);l&&l instanceof W.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(We.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,P,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),D=this._getPosition(S,a);if(D==null)return;this._ensureMap(a,d).set(f,e);const R=g.scene,{scaleX:C}=R.getAncestorScale(),T=tt(S,n,C),I={unitId:a,subUnitId:d,drawingId:f,drawingType:e.type||u.DrawingTypeEnum.DRAWING_DOM,componentKey:p,sheetTransform:D,transform:{left:T.startX,top:T.startY,width:T.width,height:T.height},data:h,allowTransform:w};{const{unitId:y,subUnitId:$,drawingId:B}=I,X=_.getSheetCommandTarget(this._univerInstanceService,{unitId:y,subUnitId:$}),H=I,z=this._univerInstanceService.getUnit(y,u.UniverInstanceType.UNIVER_SHEET);if(!z)return;const ie=z.getActiveSheet().getSheetId();if(!H||!X)return;const Q=(b=this._renderManagerService.getRenderById(y))==null?void 0:b.with(O.SheetSkeletonManagerService);if(!Q)return;const q=Q.getWorksheetSkeleton($);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(y);if(Y==null)return;const{scene:_e,canvas:ve}=Y;if(oe==null||ie!==$)return;const{left:Le,top:Ye,width:ke,height:Fe,angle:ut,flipX:gt,flipY:Ge,skewX:He,skewY:Ie}=oe,Ve=A.getDrawingShapeKeyByDrawingSearch({unitId:y,subUnitId:$,drawingId:B}),de=_e.getObject(Ve);if(de!=null){de.transformByState({left:Le,top:Ye,width:ke,height:Fe,angle:ut,flipX:gt,flipY:Ge,skewX:He,skewY:Ie});return}const ee={left:Le,top:Ye,width:ke,height:Fe,zIndex:this._drawingManagerService.getDrawingOrder(y,$).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 W.Rect(Ve,ee);De&&ae.setObjectType(W.ObjectType.CHART),_e.addObject(ae,W.DRAWING_OBJECT_LAYER_INDEX),H.allowTransform!==!1&&_e.attachTransformerTo(ae);const be=this._ensureMap(y,$),le=new u.DisposableCollection,Xe=_e.getMainViewport(),{rowHeaderWidth:Ce,columnHeaderHeight:Ee}=q.skeleton,Ke={top:Ee,left:Ce,bottom:Xe.bottom,right:Xe.right},ue={dispose:le,rect:ae,boundsOfViewArea:Ke,domAnchor:n,unitId:y,subUnitId:$},k=ge(ae,Y.renderUnit,q.skeleton,X.worksheet,ue),ye=new U.BehaviorSubject(k);ue.position$=ye;let Oe={position$:ye,id:B,componentKey:H.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:L=>{ve.dispatchEvent(new WheelEvent(L.type,L))},props:(P=(j=be.get(B))==null?void 0:j.props)!=null?P:this._getFloatDomProps(B),data:Z,unitId:y};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({rotate:0,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),Ht=A.getDrawingShapeKeyByDrawingSearch({unitId:y,subUnitId:$,drawingId:B}),Vt=new W.Rect(Ht,{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(y,$).length-1}),Xt=ge(Vt,Y.renderUnit,q.skeleton,X.worksheet,ue);ye.next(Xt)}));const Pe=(E=this._renderManagerService.getRenderById(y))==null?void 0:E.with(O.SheetSkeletonManagerService);Pe==null||Pe.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);ye.next(L)});le.add(()=>{this._canvasFloatDomService.removeFloatDom(B)}),ze&&le.add(ze),this._domLayerInfoMap.set(B,ue),be.set(B,{...be.get(B)})}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;D.startY=0;const M=this._getPosition(S,a);if(M==null)return;this._ensureMap(a,d).set(f,e);const C={unitId:a,subUnitId:d,drawingId:f,drawingType:e.type||u.DrawingTypeEnum.DRAWING_DOM,componentKey:p,sheetTransform:M,transform:{left:D.startX,top:D.startY,width:D.width,height:D.height},data:h,allowTransform:w};{const{unitId:P,subUnitId:E,drawingId:y}=C,$=_.getSheetCommandTarget(this._univerInstanceService,{unitId:P,subUnitId:E}),B=C,X=this._univerInstanceService.getUnit(P,u.UniverInstanceType.UNIVER_SHEET);if(!X)return;const H=X.getActiveSheet().getSheetId();if(!B||!$)return;const z=(I=this._renderManagerService.getRenderById(P))==null?void 0:I.with(O.SheetSkeletonManagerService);if(!z)return;const ie=z.getWorksheetSkeleton(E);if(!ie)return;const{transform:Q,data:q}=B,oe=this._getSceneAndTransformerByDrawingSearch(P);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:ke,flipY:Fe,skewX:ut,skewY:gt}=Q,Ge=A.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:E,drawingId:y}),He=se.getObject(Ge);if(He!=null){He.transformByState({left:Y,top:_e,width:ve,height:Le,angle:Ye,flipX:ke,flipY:Fe,skewX:ut,skewY:gt});return}const Ie=tt({rotate:0,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(P,E).length-1},de=new W.Rect(Ge,Ve);se.addObject(de,W.DRAWING_OBJECT_LAYER_INDEX),B.allowTransform!==!1&&se.attachTransformerTo(de);const ee=this._ensureMap(P,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:P,subUnitId:E,boundsOfViewArea:be,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},Xe=ge(de,oe.renderUnit,ie.skeleton,$.worksheet,le),Ce=new U.BehaviorSubject(Xe);le.position$=Ce;let Ee={position$:Ce,id:y,componentKey:B.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:k=>{Z.dispatchEvent(new WheelEvent(k.type,k))},props:(b=(N=ee.get(y))==null?void 0:N.props)!=null?b:this._getFloatDomProps(y),data:q,unitId:P};e.eventPassThrough&&(Ee={...Ee,onPointerDown:k=>{Z.dispatchEvent(new PointerEvent(k.type,k))},onPointerMove:k=>{Z.dispatchEvent(new PointerEvent(k.type,k))},onPointerUp:k=>{Z.dispatchEvent(new PointerEvent(k.type,k))}}),this._canvasFloatDomService.addFloatDom(Ee);const Ke=de.onTransformChange$.subscribeEvent(()=>{const k=ge(de,oe.renderUnit,ie.skeleton,$.worksheet,le);Ce.next(k)});this.disposeWithMe(v.subscribe(k=>{const ye=tt({rotate:0,startX:k.startX,startY:0,endX:k.endX,endY:k.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Oe=A.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:E,drawingId:y}),Pe=new W.Rect(Oe,{left:ye.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(P,E).length-1}),ze=ge(Pe,oe.renderUnit,ie.skeleton,$.worksheet,le);Ce.next(ze)}));const ue=(j=this._renderManagerService.getRenderById(P))==null?void 0:j.with(O.SheetSkeletonManagerService);ue==null||ue.currentSkeleton$.subscribe(k=>{k&&c.sheetId!==k.sheetId&&this._removeDom(f,!0)}),De.add(()=>{this._canvasFloatDomService.removeFloatDom(y)}),Ke&&De.add(Ke),this._domLayerInfoMap.set(y,le),ee.set(y,{...ee.get(y)})}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 U.BehaviorSubject(a),g=Ne(t.endRow,t.endColumn,n),l=new U.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(U.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=yr([Se(0,u.Inject(W.IRenderManagerService)),Se(1,u.IUniverInstanceService),Se(2,u.Inject(u.ICommandService)),Se(3,A.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 Ft=Object.defineProperty,Tr=Object.getOwnPropertyDescriptor,Rr=(i,r,t)=>r in i?Ft(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,br=(i,r,t,e)=>{for(var n=e>1?void 0:e?Tr(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&Ft(r,t,n),n},ht=(i,r)=>(t,e)=>r(t,e,i),Gt=(i,r,t)=>Rr(i,typeof r!="symbol"?r+"":r,t);const Er="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(qt,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))})}};Gt(exports.UniverSheetsDrawingUIPlugin,"type",u.UniverInstanceType.UNIVER_SHEET);Gt(exports.UniverSheetsDrawingUIPlugin,"pluginName",Er);exports.UniverSheetsDrawingUIPlugin=br([u.DependentOn(A.UniverDrawingPlugin,At.UniverDocsDrawingPlugin,fe.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),ht(1,u.Inject(u.Injector)),ht(2,W.IRenderManagerService),ht(3,u.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=G;exports.DeleteDrawingsCommand=Ct;exports.EditSheetDrawingOperation=St;exports.GroupSheetDrawingCommand=_t;exports.InsertFloatImageCommand=$e;exports.InsertSheetDrawingCommand=We;exports.MoveDrawingsCommand=Re;exports.RemoveSheetDrawingCommand=Te;exports.SHEETS_IMAGE_MENU_ID=yt;exports.SetDrawingArrangeCommand=vt;exports.SetSheetDrawingCommand=Be;exports.SidebarSheetDrawingOperation=wt;exports.UngroupSheetDrawingCommand=It;