@univerjs/sheets-drawing-ui 0.5.3-experimental.20250106-e3b7a39 → 0.5.3-experimental.20250107-3e6579c

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.
@@ -0,0 +1,13 @@
1
+ import { Injector, FUniver } from '@univerjs/core';
2
+ export declare class FUniverDrawingMixin extends FUniver {
3
+ _initialize(injector: Injector): void;
4
+ private _beforeOverGridImageInsert;
5
+ private _overGridImageInserted;
6
+ private _beforeOverGridImageRemove;
7
+ private _overGridImageRemoved;
8
+ private _beforeOverGridImageChange;
9
+ private _overGridImageChanged;
10
+ private _beforeOverGridImageSelect;
11
+ private _overGridImageSelected;
12
+ private _createFOverGridImage;
13
+ }
@@ -15,5 +15,11 @@
15
15
  */
16
16
  import './f-over-grid-image';
17
17
  import './f-worksheet';
18
+ import './f-enum';
19
+ import './f-event';
20
+ import './f-univer';
21
+ export type * from './f-enum';
22
+ export type * from './f-event';
18
23
  export type * from './f-over-grid-image';
24
+ export type * from './f-univer';
19
25
  export type * from './f-worksheet';
@@ -29,4 +29,4 @@ export { ClearSheetDrawingTransformerOperation } from './commands/operations/cle
29
29
  export { EditSheetDrawingOperation } from './commands/operations/edit-sheet-drawing.operation';
30
30
  export { type IInsertImageCommandParams, InsertFloatImageCommand } from './commands/commands/insert-image.command';
31
31
  export { SidebarSheetDrawingOperation } from './commands/operations/open-drawing-panel.operation';
32
- export type { IDeleteDrawingCommandParams, IInsertDrawingCommandParams } from './commands/commands/interfaces';
32
+ export type { IDeleteDrawingCommandParams, IInsertDrawingCommandParams, ISetDrawingCommandParams } from './commands/commands/interfaces';
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(s,c){typeof exports=="object"&&typeof module<"u"?c(require("@univerjs/core"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing-ui"),require("@univerjs/sheets-ui"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui/facade"),require("@univerjs/sheets/facade"),require("@univerjs/ui")):typeof define=="function"&&define.amd?define(["@univerjs/core","@univerjs/drawing","@univerjs/engine-render","@univerjs/sheets-drawing-ui","@univerjs/sheets-ui","@univerjs/sheets-drawing","@univerjs/sheets-ui/facade","@univerjs/sheets/facade","@univerjs/ui"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.UniverCore,s.UniverDrawing,s.UniverEngineRender,s.UniverSheetsDrawingUi,s.UniverSheetsUi,s.UniverSheetsDrawing,s.UniverSheetsUiFacade,s.UniverSheetsFacade,s.UniverUi))})(this,function(s,c,m,d,S,f,k,R,T){"use strict";var U=Object.defineProperty;var M=(s,c,m)=>c in s?U(s,c,{enumerable:!0,configurable:!0,writable:!0,value:m}):s[c]=m;var O=(s,c,m)=>M(s,typeof c!="symbol"?c+"":c,m);var B=Object.defineProperty,E=Object.getOwnPropertyDescriptor,b=(e,i,t,n)=>{for(var r=n>1?void 0:n?E(i,t):i,a=e.length-1,o;a>=0;a--)(o=e[a])&&(r=(n?o(i,t,r):o(r))||r);return n&&r&&B(i,t,r),r},v=(e,i)=>(t,n)=>i(t,n,e);function P(e,i){const{from:t,to:n,flipY:r=!1,flipX:a=!1,angle:o=0,skewX:g=0,skewY:h=0}=e.sheetTransform,{column:I,columnOffset:w,row:l,rowOffset:p}=t,C=S.convertPositionSheetOverGridToAbsolute(e.unitId,e.subUnitId,{from:t,to:n},i),{left:y,top:D,width:j,height:F}=C;return{...e,column:I,columnOffset:w,row:l,rowOffset:p,width:j,height:F,flipY:r,flipX:a,angle:o,skewX:g,skewY:h}}function W(e,i,t){const{column:n,columnOffset:r,row:a,rowOffset:o,flipY:g=!1,flipX:h=!1,angle:I=0,skewX:w=0,skewY:l=0,width:p,height:C}=e,y=S.convertPositionCellToSheetOverGrid(e.unitId,e.subUnitId,{column:n,columnOffset:r,row:a,rowOffset:o},p,C,i,t),{sheetTransform:D,transform:j}=y;return{...e,sheetTransform:{...D,flipY:g,flipX:h,angle:I,skewX:w,skewY:l},transform:{...j,flipY:g,flipX:h,angle:I,skewX:w,skewY:l}}}let _=class{constructor(e,i,t){O(this,"_image");this._injector=t,this._image={drawingId:s.generateRandomId(6),drawingType:s.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s.ImageSourceType.BASE64,source:"",unitId:e,subUnitId:i,column:0,columnOffset:0,row:0,rowOffset:0,width:0,height:0}}setImage(e){const t=this._injector.get(m.IRenderManagerService).getRenderById(e.unitId);if(!t)throw new Error(`Render Unit with unitId ${e.unitId} not found`);const n=t.with(S.SheetSkeletonManagerService);return this._image=P(e,n),this}setSource(e,i){const t=i!=null?i:s.ImageSourceType.URL;return this._image.source=e,this._image.imageSourceType=t,this}getsource(){return this._image.source}getSourceType(){return this._image.imageSourceType}setColumn(e){return this._image.column=e,this}setRow(e){return this._image.row=e,this}setColumnOffset(e){return this._image.columnOffset=e,this}setRowOffset(e){return this._image.rowOffset=e,this}setWidth(e){return this._image.width=e,this}setHeight(e){return this._image.height=e,this}setAnchorType(e){return this._image.anchorType=e,this}setCropTop(e){return this._initializeSrcRect(),this._image.srcRect.top=e,this}setCropLeft(e){return this._initializeSrcRect(),this._image.srcRect.left=e,this}setCropBottom(e){return this._initializeSrcRect(),this._image.srcRect.bottom=e,this}setCropRight(e){return this._initializeSrcRect(),this._image.srcRect.right=e,this}_initializeSrcRect(){this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0})}setRotate(e){return this._image.angle=e,this}setUnitId(e){return this._image.unitId=e,this}setSubUnitId(e){return this._image.subUnitId=e,this}async build(){const i=this._injector.get(m.IRenderManagerService).getRenderById(this._image.unitId);if(!i)throw new Error(`Render Unit with unitId ${this._image.unitId} not found`);const t=i.with(S.ISheetSelectionRenderService),n=i.with(S.SheetSkeletonManagerService);if(this._image.width===0||this._image.height===0){const r=await c.getImageSize(this._image.source),a=r.width,o=r.height;this._image.width===0&&(this._image.width=a),this._image.height===0&&(this._image.height=o)}return W(this._image,t,n)}};_=b([v(2,s.Inject(s.Injector))],_);let u=class extends s.FBase{constructor(e,i,t){super(),this._image=e,this._commandService=i,this._injector=t}getId(){return this._image.drawingId}getType(){return this._image.drawingType}remove(){return this._commandService.syncExecuteCommand(d.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}toBuilder(){const e=this._injector.createInstance(_);return e.setImage(this._image),e}setSource(e,i){const t=i!=null?i:s.ImageSourceType.URL;return this._image.source=e,this._image.imageSourceType=t,this._commandService.syncExecuteCommand(d.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}setPosition(e,i,t,n){const r=this.toBuilder();return r.setColumn(i),r.setRow(e),t!=null&&r.setRowOffset(t),n!=null&&r.setColumnOffset(n),this._commandService.syncExecuteCommand(d.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[r.build()]})}setSize(e,i){const t=this.toBuilder();return t.setWidth(e),t.setHeight(i),this._commandService.syncExecuteCommand(d.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[t.build()]})}setCrop(e,i,t,n){return this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0}),e!=null&&(this._image.srcRect.top=e),i!=null&&(this._image.srcRect.left=i),t!=null&&(this._image.srcRect.bottom=t),n!=null&&(this._image.srcRect.right=n),this._commandService.syncExecuteCommand(d.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}setRotate(e){return this._image.sheetTransform.angle=e,this._commandService.syncExecuteCommand(d.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}};u=b([v(1,s.ICommandService),v(2,s.Inject(s.Injector))],u);class x extends R.FWorksheet{addFloatDomToPosition(i,t){const n=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),{key:a,disposableCollection:o}=k.transformComponentKey(i,this._injector.get(T.ComponentManager)),h=this._injector.get(d.SheetCanvasFloatDomManagerService).addFloatDomToPosition({...i,componentKey:a,unitId:n,subUnitId:r},t);return h?(o.add(h.dispose),{id:h.id,dispose:()=>{o.dispose(),h.dispose()}}):(o.dispose(),null)}async insertImage(i,t,n,r,a){const o=this.newOverGridImage();if(typeof i=="string")o.setSource(i);else{const I=await i.getBlob().getDataAsString();o.setSource(I,s.ImageSourceType.BASE64)}t!==void 0?o.setColumn(t):o.setColumn(0),n!==void 0?o.setRow(n):o.setRow(0),r!==void 0?o.setColumnOffset(r):o.setColumnOffset(0),a!==void 0?o.setRowOffset(a):o.setRowOffset(0);const g=await o.build();return this._commandService.syncExecuteCommand(d.InsertSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:[g]})}insertImages(i){const t=i.map(n=>(n.unitId=this._fWorkbook.getId(),n.subUnitId=this.getSheetId(),n));return this._commandService.syncExecuteCommand(d.InsertSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}deleteImages(i){const t=i.map(n=>({unitId:this._fWorkbook.getId(),drawingId:n.getId(),subUnitId:this.getSheetId(),drawingType:n.getType()}));return this._commandService.syncExecuteCommand(d.RemoveSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}getImages(){const t=this._injector.get(f.ISheetDrawingService).getDrawingData(this._fWorkbook.getId(),this.getSheetId()),n=[];for(const r in t){const a=t[r];n.push(this._injector.createInstance(u,a))}return n}getImageById(i){const n=this._injector.get(f.ISheetDrawingService).getDrawingByParam({unitId:this._fWorkbook.getId(),subUnitId:this.getSheetId(),drawingId:i});return n?this._injector.createInstance(u,n):null}getActiveImages(){const t=this._injector.get(f.ISheetDrawingService).getFocusDrawings(),n=[];for(const r in t){const a=t[r];n.push(this._injector.createInstance(u,a))}return n}updateImages(i){return this._commandService.syncExecuteCommand(d.SetSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:i}),this}onImageInserted(i){const t=this._injector.get(f.ISheetDrawingService);return s.toDisposable(t.add$.subscribe(n=>{const r=n.map(a=>this._injector.createInstance(u,t.getDrawingByParam(a)));i(r)}))}onImageDeleted(i){const t=this._injector.get(f.ISheetDrawingService);return s.toDisposable(t.remove$.subscribe(n=>{const r=n.map(a=>this._injector.createInstance(u,t.getDrawingByParam(a)));i(r)}))}onImageChanged(i){const t=this._injector.get(f.ISheetDrawingService);return s.toDisposable(t.update$.subscribe(n=>{const r=n.map(a=>this._injector.createInstance(u,t.getDrawingByParam(a)));i(r)}))}newOverGridImage(){const i=this._fWorkbook.getId(),t=this.getSheetId();return this._injector.createInstance(_,i,t)}}R.FWorksheet.extend(x)});
1
+ (function(s,c){typeof exports=="object"&&typeof module<"u"?c(require("@univerjs/core"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing-ui"),require("@univerjs/sheets-ui"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui/facade"),require("@univerjs/sheets/facade"),require("@univerjs/ui")):typeof define=="function"&&define.amd?define(["@univerjs/core","@univerjs/drawing","@univerjs/engine-render","@univerjs/sheets-drawing-ui","@univerjs/sheets-ui","@univerjs/sheets-drawing","@univerjs/sheets-ui/facade","@univerjs/sheets/facade","@univerjs/ui"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.UniverCore,s.UniverDrawing,s.UniverEngineRender,s.UniverSheetsDrawingUi,s.UniverSheetsUi,s.UniverSheetsDrawing,s.UniverSheetsUiFacade,s.UniverSheetsFacade,s.UniverUi))})(this,function(s,c,u,d,f,v,D,O,R){"use strict";var W=Object.defineProperty;var q=(s,c,u)=>c in s?W(s,c,{enumerable:!0,configurable:!0,writable:!0,value:u}):s[c]=u;var k=(s,c,u)=>q(s,typeof c!="symbol"?c+"":c,u);var j=Object.defineProperty,B=Object.getOwnPropertyDescriptor,y=(i,t,e,r)=>{for(var n=r>1?void 0:r?B(t,e):t,a=i.length-1,o;a>=0;a--)(o=i[a])&&(n=(r?o(t,e,n):o(n))||n);return r&&n&&j(t,e,n),n},_=(i,t)=>(e,r)=>t(e,r,i);function T(i,t){const{from:e,to:r,flipY:n=!1,flipX:a=!1,angle:o=0,skewX:g=0,skewY:m=0}=i.sheetTransform,{column:I,columnOffset:w,row:S,rowOffset:p}=e,b=f.convertPositionSheetOverGridToAbsolute(i.unitId,i.subUnitId,{from:e,to:r},t),{left:E,top:G,width:C,height:U}=b;return{...i,column:I,columnOffset:w,row:S,rowOffset:p,width:C,height:U,flipY:n,flipX:a,angle:o,skewX:g,skewY:m}}function A(i,t,e){const{column:r,columnOffset:n,row:a,rowOffset:o,flipY:g=!1,flipX:m=!1,angle:I=0,skewX:w=0,skewY:S=0,width:p,height:b}=i,E=f.convertPositionCellToSheetOverGrid(i.unitId,i.subUnitId,{column:r,columnOffset:n,row:a,rowOffset:o},p,b,t,e),{sheetTransform:G,transform:C}=E;return{...i,sheetTransform:{...G,flipY:g,flipX:m,angle:I,skewX:w,skewY:S},transform:{...C,flipY:g,flipX:m,angle:I,skewX:w,skewY:S}}}let l=class{constructor(i,t,e){k(this,"_image");this._injector=e,this._image={drawingId:s.generateRandomId(6),drawingType:s.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s.ImageSourceType.BASE64,source:"",unitId:i,subUnitId:t,column:0,columnOffset:0,row:0,rowOffset:0,width:0,height:0}}setImage(i){const e=this._injector.get(u.IRenderManagerService).getRenderById(i.unitId);if(!e)throw new Error(`Render Unit with unitId ${i.unitId} not found`);const r=e.with(f.SheetSkeletonManagerService);return i.sheetTransform==null&&(i.sheetTransform={from:{column:0,columnOffset:0,row:0,rowOffset:0},to:{column:0,columnOffset:0,row:0,rowOffset:0}}),this._image=T(i,r),this}setSource(i,t){const e=t!=null?t:s.ImageSourceType.URL;return this._image.source=i,this._image.imageSourceType=e,this}getsource(){return this._image.source}getSourceType(){return this._image.imageSourceType}setColumn(i){return this._image.column=i,this}setRow(i){return this._image.row=i,this}setColumnOffset(i){return this._image.columnOffset=i,this}setRowOffset(i){return this._image.rowOffset=i,this}setWidth(i){return this._image.width=i,this}setHeight(i){return this._image.height=i,this}setAnchorType(i){return this._image.anchorType=i,this}setCropTop(i){return this._initializeSrcRect(),this._image.srcRect.top=i,this}setCropLeft(i){return this._initializeSrcRect(),this._image.srcRect.left=i,this}setCropBottom(i){return this._initializeSrcRect(),this._image.srcRect.bottom=i,this}setCropRight(i){return this._initializeSrcRect(),this._image.srcRect.right=i,this}_initializeSrcRect(){this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0})}setRotate(i){return this._image.angle=i,this}setUnitId(i){return this._image.unitId=i,this}setSubUnitId(i){return this._image.subUnitId=i,this}async buildAsync(){const t=this._injector.get(u.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),r=t.with(f.SheetSkeletonManagerService);if(this._image.width===0||this._image.height===0){const n=await c.getImageSize(this._image.source),a=n.width,o=n.height;this._image.width===0&&(this._image.width=a),this._image.height===0&&(this._image.height=o)}return A(this._image,e,r)}};l=y([_(2,s.Inject(s.Injector))],l);let h=class extends s.FBase{constructor(i,t,e){super(),this._image=i,this._commandService=t,this._injector=e}getId(){return this._image.drawingId}getType(){return this._image.drawingType}remove(){return this._commandService.syncExecuteCommand(d.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}toBuilder(){const i=this._injector.createInstance(l);return i.setImage(this._image),i}setSource(i,t){const e=t!=null?t:s.ImageSourceType.URL;return this._image.source=i,this._image.imageSourceType=e,this._commandService.syncExecuteCommand(d.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}async setPositionAsync(i,t,e,r){const n=this.toBuilder();n.setColumn(t),n.setRow(i),e!=null&&n.setRowOffset(e),r!=null&&n.setColumnOffset(r);const a=await n.buildAsync();return this._commandService.syncExecuteCommand(d.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[a]})}async setSizeAsync(i,t){const e=this.toBuilder();e.setWidth(i),e.setHeight(t);const r=await e.buildAsync();return this._commandService.syncExecuteCommand(d.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[r]})}setCrop(i,t,e,r){return this._image.srcRect==null&&(this._image.srcRect={top:0,left:0,bottom:0,right:0}),i!=null&&(this._image.srcRect.top=i),t!=null&&(this._image.srcRect.left=t),e!=null&&(this._image.srcRect.bottom=e),r!=null&&(this._image.srcRect.right=r),this._commandService.syncExecuteCommand(d.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}setRotate(i){return this._image.sheetTransform.angle=i,this._commandService.syncExecuteCommand(d.SetSheetDrawingCommand.id,{unitId:this._image.unitId,drawings:[this._image]})}setForward(){return this._commandService.syncExecuteCommand(d.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:s.ArrangeTypeEnum.forward})}setBackward(){return this._commandService.syncExecuteCommand(d.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:s.ArrangeTypeEnum.backward})}setBack(){return this._commandService.syncExecuteCommand(d.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:s.ArrangeTypeEnum.back})}setFront(){return this._commandService.syncExecuteCommand(d.SetDrawingArrangeCommand.id,{unitId:this._image.unitId,subUnitId:this._image.subUnitId,drawingIds:[this._image.drawingId],arrangeType:s.ArrangeTypeEnum.front})}};h=y([_(1,s.ICommandService),_(2,s.Inject(s.Injector))],h);class F extends O.FWorksheet{addFloatDomToPosition(t,e){const r=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),{key:a,disposableCollection:o}=D.transformComponentKey(t,this._injector.get(R.ComponentManager)),m=this._injector.get(d.SheetCanvasFloatDomManagerService).addFloatDomToPosition({...t,componentKey:a,unitId:r,subUnitId:n},e);return m?(o.add(m.dispose),{id:m.id,dispose:()=>{o.dispose(),m.dispose()}}):(o.dispose(),null)}async insertImage(t,e,r,n,a){const o=this.newOverGridImage();if(typeof t=="string")o.setSource(t);else{const I=await t.getBlob().getDataAsString();o.setSource(I,s.ImageSourceType.BASE64)}e!==void 0?o.setColumn(e):o.setColumn(0),r!==void 0?o.setRow(r):o.setRow(0),n!==void 0?o.setColumnOffset(n):o.setColumnOffset(0),a!==void 0?o.setRowOffset(a):o.setRowOffset(0);const g=await o.buildAsync();return this._commandService.syncExecuteCommand(d.InsertSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:[g]})}insertImages(t){const e=t.map(r=>(r.unitId=this._fWorkbook.getId(),r.subUnitId=this.getSheetId(),r));return this._commandService.syncExecuteCommand(d.InsertSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:e}),this}deleteImages(t){const e=t.map(r=>({unitId:this._fWorkbook.getId(),drawingId:r.getId(),subUnitId:this.getSheetId(),drawingType:r.getType()}));return this._commandService.syncExecuteCommand(d.RemoveSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:e}),this}getImages(){const e=this._injector.get(v.ISheetDrawingService).getDrawingData(this._fWorkbook.getId(),this.getSheetId()),r=[];for(const n in e){const a=e[n];a.drawingType===s.DrawingTypeEnum.DRAWING_IMAGE&&r.push(this._injector.createInstance(h,a))}return r}getImageById(t){const r=this._injector.get(v.ISheetDrawingService).getDrawingByParam({unitId:this._fWorkbook.getId(),subUnitId:this.getSheetId(),drawingId:t});return r&&r.drawingType===s.DrawingTypeEnum.DRAWING_IMAGE?this._injector.createInstance(h,r):null}getActiveImages(){const e=this._injector.get(v.ISheetDrawingService).getFocusDrawings(),r=[];for(const n in e){const a=e[n];r.push(this._injector.createInstance(h,a))}return r}updateImages(t){return this._commandService.syncExecuteCommand(d.SetSheetDrawingCommand.id,{unitId:this._fWorkbook.getId(),drawings:t}),this}onImageInserted(t){const e=this._injector.get(v.ISheetDrawingService);return s.toDisposable(e.add$.subscribe(r=>{const n=r.map(a=>this._injector.createInstance(h,e.getDrawingByParam(a)));t(n)}))}onImageDeleted(t){const e=this._injector.get(v.ISheetDrawingService);return s.toDisposable(e.remove$.subscribe(r=>{const n=r.map(a=>this._injector.createInstance(h,e.getDrawingByParam(a)));t(n)}))}onImageChanged(t){const e=this._injector.get(v.ISheetDrawingService);return s.toDisposable(e.update$.subscribe(r=>{const n=r.map(a=>this._injector.createInstance(h,e.getDrawingByParam(a)));t(n)}))}newOverGridImage(){const t=this._fWorkbook.getId(),e=this.getSheetId();return this._injector.createInstance(l,t,e)}}O.FWorksheet.extend(F);class M extends s.FEnum{get DrawingType(){return s.DrawingTypeEnum}get ImageSourceType(){return s.ImageSourceType}get SheetDrawingAnchorType(){return v.SheetDrawingAnchorType}}s.FEnum.extend(M);class x extends s.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"}}s.FEventName.extend(x);class P extends s.FUniver{_initialize(t){const e=t.get(s.ICommandService);this.disposeWithMe(e.beforeCommandExecuted(r=>{switch(r.id){case d.InsertSheetDrawingCommand.id:this._beforeOverGridImageInsert(r.params);break;case d.RemoveSheetDrawingCommand.id:this._beforeOverGridImageRemove(r.params);break;case d.SetSheetDrawingCommand.id:this._beforeOverGridImageChange(r.params);break;case c.SetDrawingSelectedOperation.id:this._beforeOverGridImageSelect(r.params);break}})),this.disposeWithMe(e.onCommandExecuted(r=>{switch(r.id){case d.InsertSheetDrawingCommand.id:this._overGridImageInserted(r.params);break;case d.RemoveSheetDrawingCommand.id:this._overGridImageRemoved(r.params);break;case d.SetSheetDrawingCommand.id:this._overGridImageChanged(r.params);break;case c.SetDrawingSelectedOperation.id:this._overGridImageSelected(r.params);break}}))}_beforeOverGridImageInsert(t){if(!this.hasEventCallback(this.Event.BeforeOverGridImageInsert))return;const e=this.getActiveUniverSheet();if(e==null||t==null)return;const{drawings:r}=t,n={workbook:e,insertImageParams:r};if(this.fireEvent(this.Event.BeforeOverGridImageInsert,n),n.cancel)throw new Error("Canceled by BeforeOverGridImageInsert event")}_overGridImageInserted(t){if(!this.hasEventCallback(this.Event.OverGridImageInserted))return;const e=this.getActiveUniverSheet();if(e==null||t==null)return;const{drawings:r}=t;this.fireEvent(this.Event.OverGridImageInserted,{workbook:e,images:this._createFOverGridImage(r)})}_beforeOverGridImageRemove(t){if(!this.hasEventCallback(this.Event.BeforeOverGridImageRemove))return;const e=this.getActiveUniverSheet();if(e==null||t==null)return;const{drawings:r}=t,n=this._injector.get(c.IDrawingManagerService),a=r.map(g=>n.getDrawingByParam(g)),o={workbook:e,images:this._createFOverGridImage(a)};if(this.fireEvent(this.Event.BeforeOverGridImageRemove,o),o.cancel)throw new Error("Canceled by BeforeOverGridImageRemove event")}_overGridImageRemoved(t){if(!this.hasEventCallback(this.Event.OverGridImageRemoved))return;const e=this.getActiveUniverSheet();if(e==null||t==null)return;const{drawings:r}=t;this.fireEvent(this.Event.OverGridImageRemoved,{workbook:e,removeImageParams:r})}_beforeOverGridImageChange(t){if(!this.hasEventCallback(this.Event.BeforeOverGridImageChange))return;const e=this.getActiveUniverSheet();if(e==null||t==null)return;const{drawings:r}=t,n=this._injector.get(c.IDrawingManagerService),a=[];r.forEach(g=>{const m=n.getDrawingByParam(g);m!=null&&a.push({changeParam:g,image:this._injector.createInstance(h,m)})});const o={workbook:e,images:a};if(this.fireEvent(this.Event.BeforeOverGridImageChange,o),o.cancel)throw n.updateNotification(r),new Error("Canceled by BeforeOverGridImageChange event")}_overGridImageChanged(t){if(!this.hasEventCallback(this.Event.OverGridImageChanged))return;const e=this.getActiveUniverSheet();if(e==null||t==null)return;const{drawings:r}=t,n=this._injector.get(c.IDrawingManagerService),a=r.map(o=>this._injector.createInstance(h,n.getDrawingByParam(o)));this.fireEvent(this.Event.OverGridImageChanged,{workbook:e,images:a})}_beforeOverGridImageSelect(t){if(!this.hasEventCallback(this.Event.BeforeOverGridImageSelect))return;const e=this._injector.get(c.IDrawingManagerService),r=this.getActiveUniverSheet();if(r==null)return;const n=e.getFocusDrawings(),a=t.map(g=>e.getDrawingByParam(g)),o={workbook:r,selectedImages:this._createFOverGridImage(a),oldSelectedImages:this._createFOverGridImage(n)};if(this.fireEvent(this.Event.BeforeOverGridImageSelect,o),o.cancel)throw new Error("Canceled by BeforeOverGridImageSelect event")}_overGridImageSelected(t){if(!this.hasEventCallback(this.Event.OverGridImageSelected))return;const e=this.getActiveUniverSheet(),r=this._injector.get(c.IDrawingManagerService);if(e==null)return;const n=t.map(a=>r.getDrawingByParam(a));this.fireEvent(this.Event.OverGridImageSelected,{workbook:e,selectedImages:this._createFOverGridImage(n)})}_createFOverGridImage(t){return t.map(e=>this._injector.createInstance(h,e))}}s.FUniver.extend(P)});
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(b,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@univerjs/core"),require("@univerjs/docs-drawing"),require("@univerjs/drawing"),require("@univerjs/drawing-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("react"),require("@univerjs/docs-ui"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-drawing","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","react","@univerjs/docs-ui","@univerjs/design"],d):(b=typeof globalThis<"u"?globalThis:b||self,d(b.UniverSheetsDrawingUi={},b.UniverCore,b.UniverDocsDrawing,b.UniverDrawing,b.UniverDrawingUi,b.UniverEngineRender,b.UniverSheetsDrawing,b.UniverSheetsUi,b.UniverUi,b.rxjs,b.UniverSheets,b.React,b.UniverDocsUi,b.UniverDesign))})(this,function(b,d,te,P,q,N,p,U,k,j,_,X,xe,J){"use strict";var Mn=Object.defineProperty;var Dn=(b,d,te)=>d in b?Mn(b,d,{enumerable:!0,configurable:!0,writable:!0,value:te}):b[d]=te;var Y=(b,d,te)=>Dn(b,typeof d!="symbol"?d+"":d,te);const dt="sheets-drawing-ui.config",Ye={},G={id:"sheet.operation.clear-drawing-transformer",type:d.CommandType.MUTATION,handler:(i,r)=>{const n=i.get(N.IRenderManagerService);return r.forEach(e=>{var t,o;(o=(t=n.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},ae={id:"sheet.command.remove-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{var M,y,R;const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(_.SheetInterceptorService),o=i.get(p.ISheetDrawingService);if(!r)return!1;const{drawings:a}=r,c=[];a.forEach(I=>{const{unitId:D}=I;c.push(D)});const l=o.getBatchRemoveOp(a),{unitId:h,subUnitId:u,undo:s,redo:m,objects:g}=l,f=t.onCommandExecute({id:ae.id,params:r}),S={id:p.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:u,op:m,objects:g,type:p.DrawingApplyType.REMOVE}},v={id:p.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:u,op:s,objects:g,type:p.DrawingApplyType.INSERT}};return d.sequenceExecute([...(M=f.preRedos)!=null?M:[],S,...f.redos],n)?(e.pushUndoRedo({unitID:h,undoMutations:[...(y=f.preUndos)!=null?y:[],v,...f.undos,{id:G.id,params:c}],redoMutations:[...(R=f.preRedos)!=null?R:[],S,...f.redos,{id:G.id,params:c}]}),!0):!1}},Xe="COMPONENT_SHEET_DRAWING_PANEL",be={id:"sidebar.operation.sheet-image",type:d.CommandType.COMMAND,handler:async(i,r)=>{const n=i.get(k.ISidebarService),e=i.get(d.LocaleService),t=i.get(d.IUniverInstanceService),o=i.get(P.IDrawingManagerService);if(!_.getSheetCommandTarget(t))return!1;switch(r.value){case"open":n.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Xe},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:n.close();break}return!0}},Ee={id:"sheet.operation.edit-sheet-image",type:d.CommandType.OPERATION,handler:(i,r)=>{const n=i.get(P.IDrawingManagerService),e=i.get(d.ICommandService);return r==null?!1:(n.focusDrawing([r]),e.executeCommand(be.id,{value:"open"}),!0)}};var Oe={exports:{}},se={};/**
1
+ (function(b,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@univerjs/core"),require("@univerjs/docs-drawing"),require("@univerjs/drawing"),require("@univerjs/drawing-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("react"),require("@univerjs/docs-ui"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-drawing","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","react","@univerjs/docs-ui","@univerjs/design"],d):(b=typeof globalThis<"u"?globalThis:b||self,d(b.UniverSheetsDrawingUi={},b.UniverCore,b.UniverDocsDrawing,b.UniverDrawing,b.UniverDrawingUi,b.UniverEngineRender,b.UniverSheetsDrawing,b.UniverSheetsUi,b.UniverUi,b.rxjs,b.UniverSheets,b.React,b.UniverDocsUi,b.UniverDesign))})(this,function(b,d,ne,P,q,N,p,U,k,j,_,X,xe,J){"use strict";var Mn=Object.defineProperty;var Dn=(b,d,ne)=>d in b?Mn(b,d,{enumerable:!0,configurable:!0,writable:!0,value:ne}):b[d]=ne;var Y=(b,d,ne)=>Dn(b,typeof d!="symbol"?d+"":d,ne);const dt="sheets-drawing-ui.config",Ye={},G={id:"sheet.operation.clear-drawing-transformer",type:d.CommandType.MUTATION,handler:(i,r)=>{const n=i.get(N.IRenderManagerService);return r.forEach(e=>{var t,o;(o=(t=n.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},ae={id:"sheet.command.remove-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{var M,y,R;const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(_.SheetInterceptorService),o=i.get(p.ISheetDrawingService);if(!r)return!1;const{drawings:a}=r,c=[];a.forEach(I=>{const{unitId:D}=I;c.push(D)});const l=o.getBatchRemoveOp(a),{unitId:h,subUnitId:u,undo:s,redo:g,objects:m}=l,f=t.onCommandExecute({id:ae.id,params:r}),S={id:p.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:u,op:g,objects:m,type:p.DrawingApplyType.REMOVE}},v={id:p.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:u,op:s,objects:m,type:p.DrawingApplyType.INSERT}};return d.sequenceExecute([...(M=f.preRedos)!=null?M:[],S,...f.redos],n)?(e.pushUndoRedo({unitID:h,undoMutations:[...(y=f.preUndos)!=null?y:[],v,...f.undos,{id:G.id,params:c}],redoMutations:[...(R=f.preRedos)!=null?R:[],S,...f.redos,{id:G.id,params:c}]}),!0):!1}},Xe="COMPONENT_SHEET_DRAWING_PANEL",be={id:"sidebar.operation.sheet-image",type:d.CommandType.COMMAND,handler:async(i,r)=>{const n=i.get(k.ISidebarService),e=i.get(d.LocaleService),t=i.get(d.IUniverInstanceService),o=i.get(d.ICommandService);if(!_.getSheetCommandTarget(t))return!1;switch(r.value){case"open":n.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Xe},onClose:()=>{o.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:n.close();break}return!0}},Ee={id:"sheet.operation.edit-sheet-image",type:d.CommandType.OPERATION,handler:(i,r)=>{const n=i.get(d.ICommandService);return r==null?!1:(n.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[r]),n.executeCommand(be.id,{value:"open"}),!0)}};var Oe={exports:{}},se={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,4 +6,4 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var ze;function lt(){if(ze)return se;ze=1;var i=X,r=Symbol.for("react.element"),n=Symbol.for("react.fragment"),e=Object.prototype.hasOwnProperty,t=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function a(c,l,h){var u,s={},m=null,g=null;h!==void 0&&(m=""+h),l.key!==void 0&&(m=""+l.key),l.ref!==void 0&&(g=l.ref);for(u in l)e.call(l,u)&&!o.hasOwnProperty(u)&&(s[u]=l[u]);if(c&&c.defaultProps)for(u in l=c.defaultProps,l)s[u]===void 0&&(s[u]=l[u]);return{$$typeof:r,type:c,key:m,ref:g,props:s,_owner:t.current}}return se.Fragment=n,se.jsx=a,se.jsxs=a,se}var Ke;function ut(){return Ke||(Ke=1,Oe.exports=lt()),Oe.exports}var H=ut();const me={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},gt=()=>{const i=d.useDependency(P.IImageIoService),r=d.useDependency(d.LocaleService),[n,e]=X.useState(0);return X.useEffect(()=>{const t=i.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[i]),H.jsx("div",{style:{display:n>0?"block":"none"},className:me.uploadLoading,children:H.jsxs("div",{className:me.uploadLoadingBody,children:[H.jsx("div",{className:me.uploadLoadingBodyAnimation}),H.jsx("div",{className:me.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${n}`})]})})};var mt=Object.defineProperty,ht=Object.getOwnPropertyDescriptor,pt=(i,r,n,e)=>{for(var t=e>1?void 0:e?ht(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&mt(r,n,t),t},ne=(i,r)=>(n,e)=>r(n,e,i);let he=class extends d.RxDisposable{constructor(r,n,e,t,o,a,c){super();Y(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=n,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=c,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(j.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(d.UniverInstanceType.UNIVER_SHEET).pipe(j.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(d.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(k.BuiltInUIPart.CONTENT,()=>d.connectInjector(gt,this._injector))}_dispose(r){const n=r.getUnitId();this._renderManagerService.removeRender(n)}_create(r){if(!r)return;const n=r.getUnitId();this._renderManagerService.has(n)&&!this._initImagePopupMenu.has(n)&&(this._popupMenuListener(n),this._initImagePopupMenu.add(n))}_hasCropObject(r){const n=r.getAllObjectsByOrder();for(const e of n)if(e instanceof q.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const n=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!n)return;const e=n.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(d.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(n))return;const a=e.getSelectedObjectMap();if(a.size>1){t==null||t.dispose();return}const c=a.values().next().value;if(!c)return;const l=c.oKey,h=this._drawingManagerService.getDrawingOKey(l);if(!h)return;const{unitId:u,subUnitId:s,drawingId:m,drawingType:g}=h,f=h.data;if(f&&f.disablePopup)return;t==null||t.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,s,m,g);t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:q.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,s,m,g)}})),this._drawingManagerService.focusDrawing([{unitId:u,subUnitId:s,drawingId:m}])}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.dispose(),this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[d.FOCUSING_COMMON_DRAWINGS]===!1&&(t==null||t.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{t==null||t.dispose()}))}_getImageMenuItems(r,n,e,t){return[{label:"image-popup.edit",index:0,commandId:Ee.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===d.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ae.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:n,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:q.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===d.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:q.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:n,drawingId:e}],disable:t===d.DrawingTypeEnum.DRAWING_DOM}]}};he=pt([ne(0,d.Inject(d.Injector)),ne(1,P.IDrawingManagerService),ne(2,d.Inject(U.SheetCanvasPopManagerService)),ne(3,N.IRenderManagerService),ne(4,d.IUniverInstanceService),ne(5,d.IContextService),ne(6,d.Inject(k.IUIPartsService))],he);function V(i,r,n){const{from:e,to:t,flipY:o=!1,flipX:a=!1,angle:c=0,skewX:l=0,skewY:h=0}=i,u=n.getCurrent();if(u==null)return;const s=U.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:t},n);let{left:m,top:g,width:f,height:S}=s;const v=n.getCurrentSkeleton(),C=v.rowHeaderWidth+v.columnTotalWidth,M=v.columnHeaderHeight+v.rowTotalHeight;return m+f>C&&(m=C-f),g+S>M&&(g=M-S),{flipY:o,flipX:a,angle:c,skewX:l,skewY:h,left:m,top:g,width:f,height:S}}function F(i,r){const{left:n=0,top:e=0,width:t=0,height:o=0,flipY:a=!1,flipX:c=!1,angle:l=0,skewX:h=0,skewY:u=0}=i,s=r.getCellWithCoordByOffset(n,e);if(s==null)return;const m={column:s.actualColumn,columnOffset:N.precisionTo(n-s.startX,1),row:s.actualRow,rowOffset:N.precisionTo(e-s.startY,1)},g=r.getCellWithCoordByOffset(n+t,e+o);if(g==null)return;const f={column:g.actualColumn,columnOffset:N.precisionTo(n+t-g.startX,1),row:g.actualRow,rowOffset:N.precisionTo(e+o-g.startY,1)};return{flipY:a,flipX:c,angle:l,skewX:h,skewY:u,from:m,to:f}}var ft=Object.defineProperty,St=Object.getOwnPropertyDescriptor,vt=(i,r,n,e)=>{for(var t=e>1?void 0:e?St(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&ft(r,n,t),t},pe=(i,r)=>(n,e)=>r(n,e,i);let Pe=class extends d.Disposable{constructor(i,r,n,e,t){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=n,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=t,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 n=i[r];for(const e in n.data){const t=n.data[e];t.transform=V(t.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};Pe=vt([pe(1,p.ISheetDrawingService),pe(2,P.IDrawingManagerService),pe(3,d.Inject(U.ISheetSelectionRenderService)),pe(4,d.Inject(U.SheetSkeletonManagerService))],Pe);function _t(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:c}=e,l=N.getGroupState(0,0,t.map(s=>s.transform||{})),h=t.map(s=>{const m=s.transform||{left:0,top:0},{unitId:g,subUnitId:f,drawingId:S}=s;return{unitId:g,subUnitId:f,drawingId:S,transform:{...m,left:m.left-l.left,top:m.top-l.top},groupId:c}}),u={unitId:o,subUnitId:a,drawingId:c,drawingType:d.DrawingTypeEnum.DRAWING_GROUP,transform:l};r.push({parent:u,children:h})}),r}function wt(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:c,transform:l={width:0,height:0}}=e;if(l==null)return;const h=t.map(s=>{const{transform:m}=s,{unitId:g,subUnitId:f,drawingId:S}=s,v=N.transformObjectOutOfGroup(m||{},l,l.width||0,l.height||0);return{unitId:g,subUnitId:f,drawingId:S,transform:v,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:c,drawingType:d.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:h})}),r}const Ae={id:"sheet.command.group-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:g,children:f})=>{o.push(g.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getGroupDrawingOp(r),{unitId:c,subUnitId:l,undo:h,redo:u,objects:s}=a;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:c,subUnitId:l,objects:wt(s),type:p.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!0):!1}},ce={id:"sheet.command.insert-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{var M,y,R;const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService),o=i.get(_.SheetInterceptorService);if(!r)return!1;const a=r.drawings,c=a.map(I=>I.unitId),l=t.getBatchAddOp(a),{unitId:h,subUnitId:u,undo:s,redo:m,objects:g}=l,f=o.onCommandExecute({id:ce.id,params:r}),S={id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:h,subUnitId:u,objects:g,type:p.DrawingApplyType.INSERT}},v={id:p.SetDrawingApplyMutation.id,params:{op:s,unitId:h,subUnitId:u,objects:g,type:p.DrawingApplyType.REMOVE}};return d.sequenceExecute([...(M=f.preRedos)!=null?M:[],S,...f.redos],n)?(e.pushUndoRedo({unitID:h,undoMutations:[...(y=f.preUndos)!=null?y:[],v,...f.undos,{id:G.id,params:c}],redoMutations:[...(R=f.preRedos)!=null?R:[],S,...f.redos,{id:G.id,params:c}]}),!0):!1}},Ue={id:"sheet.command.set-drawing-arrange",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService);if(!r)return!1;const t=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:c,arrangeType:l}=r,h={unitId:o,subUnitId:a,drawingIds:c};let u;if(l===d.ArrangeTypeEnum.forward?u=t.getForwardDrawingsOp(h):l===d.ArrangeTypeEnum.backward?u=t.getBackwardDrawingOp(h):l===d.ArrangeTypeEnum.front?u=t.getFrontDrawingsOp(h):l===d.ArrangeTypeEnum.back&&(u=t.getBackDrawingsOp(h)),u==null)return!1;const{objects:s,redo:m,undo:g}=u;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:m,unitId:o,subUnitId:a,objects:s,type:p.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:s,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:a,objects:s,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}},de={id:"sheet.command.set-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=t.getBatchUpdateOp(o),{unitId:c,subUnitId:l,undo:h,redo:u,objects:s}=a;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:c,subUnitId:l,op:u,objects:s,type:p.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:l,op:h,objects:s,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[c]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:l,op:u,objects:s,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[c]}]}),!0):!1}},Ne={id:"sheet.command.ungroup-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:g,children:f})=>{o.push(g.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getUngroupDrawingOp(r),{unitId:c,subUnitId:l,undo:h,redo:u,objects:s}=a;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:c,subUnitId:l,objects:_t(s),type:p.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};var It=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,yt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Ct(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&It(r,n,t),t},z=(i,r)=>(n,e)=>r(n,e,i);function Mt(i,r,n){const e=n*Math.PI/180,t=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:t,rotatedHeight:o}}function Je(i,r,n,e,t){var M;const{rotatedHeight:o,rotatedWidth:a}=Mt(n,e,t),l=i.get(N.IRenderManagerService).getRenderById(r.unitId);if(!l)return!1;const u=(M=l.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(r.subUnitId))==null?void 0:M.skeleton;if(u==null)return!1;const s=u.getCellByIndex(r.row,r.col),m=s.mergeInfo.endX-s.mergeInfo.startX-2,g=s.mergeInfo.endY-s.mergeInfo.startY-2,f=a/o,v=Math.ceil(Math.min(m,g*f))/a,C=!v||Number.isNaN(v)?.001:v;return{width:n*C,height:e*C}}let le=class extends d.Disposable{constructor(r,n,e,t,o,a,c,l,h,u,s,m,g){super();Y(this,"_workbookSelections");this._context=r,this._skeletonManagerService=n,this._commandService=e,this._selectionRenderService=t,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=c,this._drawingManagerService=l,this._contextService=h,this._messageService=u,this._localeService=s,this._injector=g,this._workbookSelections=m.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(",")}),n=r.length;return n>P.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(P.DRAWING_IMAGE_COUNT_LIMIT))}),!1):n===0?!1:(r.forEach(async e=>await this._insertFloatImage(e)),!0)}async insertCellImage(){const n=(await this._fileOpenerService.openFile({multiple:!1,accept:P.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}))[0];return n?(await this._insertCellImage(n),!0):!1}async _insertFloatImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(M){const y=M.message;y===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:c,source:l,base64Cache:h}=n,{width:u,height:s,image:m}=await P.getImageSize(h||""),{width:g,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(l,c,m);let S=1;if(u>P.DRAWING_IMAGE_WIDTH_LIMIT||s>P.DRAWING_IMAGE_HEIGHT_LIMIT){const M=P.DRAWING_IMAGE_WIDTH_LIMIT/u,y=P.DRAWING_IMAGE_HEIGHT_LIMIT/s;S=Math.max(M,y)}const v=this._getImagePosition(u*S,s*S,g,f);if(v==null)return;const C={unitId:t,subUnitId:o,drawingId:a,drawingType:d.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c,source:l,transform:V(v,this._selectionRenderService,this._skeletonManagerService),sheetTransform:v};this._commandService.executeCommand(ce.id,{unitId:t,drawings:[C]})}async _insertCellImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(v){const C=v.message;C===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const{imageId:e,imageSourceType:t,source:o,base64Cache:a}=n,{width:c,height:l,image:h}=await P.getImageSize(a||"");this._imageIoService.addImageSourceCache(o,t,h);const u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;const s=d.createDocumentModelWithStyle("",{}),m=Je(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},c,l,0);if(!m)return!1;const g={size:{width:m.width,height:m.height},positionH:{relativeFrom:d.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:d.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},f={unitId:s.getUnitId(),subUnitId:s.getUnitId(),drawingId:e,drawingType:d.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t,source:o,transform:xe.docDrawingPositionToTransform(g),docTransform:g,behindDoc:d.BooleanNumber.FALSE,title:"",description:"",layoutType:d.PositionedObjectLayoutType.INLINE,wrapText:d.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=d.BuildTextUtils.drawing.add({documentDataModel:s,drawings:[f],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(s.apply(S),this._commandService.syncExecuteCommand(_.SetRangeValuesCommand.id,{value:{[u.primary.actualRow]:{[u.primary.actualColumn]:{p:s.getSnapshot(),t:1}}}})):!1}_getUnitInfo(){const r=this._context.unit,n=r.getActiveSheet(),e=r.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(r,n,e,t){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const c=U.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(c==null)return;let{startColumn:l,startRow:h,startX:u,startY:s}=c,m=!1;if(u+r>e&&(u=e-r,u<0&&(u=0,r=e),m=!0),s+n>t&&(s=t-n,s<0&&(s=0,n=t),m=!0),m){const v=this._selectionRenderService.getCellWithCoordByOffset(u,s);if(v==null)return;u=v.startX,s=v.startY,l=v.actualColumn,h=v.actualRow}const g={column:l,columnOffset:0,row:h,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(u+r,s+n);if(f==null)return;const S={column:f.actualColumn,columnOffset:u+r-f.startX,row:f.actualRow,rowOffset:s+n-f.startY};return{from:g,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(r=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o}=r;this._commandService.executeCommand(Ue.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(r=>{const n=[];r.length!==0&&(r.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a,drawingType:c,transform:l}=e;if(l==null)return;const h=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:a});if(h==null||h.unitId!==this._context.unitId)return;const u=F({...h.transform,...l},this._selectionRenderService);if(u==null)return;const s={...e,transform:{...h.transform,...l,...V(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};n.push(s)}),n.length>0&&this._commandService.executeCommand(de.id,{unitId:r[0].unitId,drawings:n}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Ae.id,r);const{unitId:n,subUnitId:e,drawingId:t}=r[0].parent;this._drawingManagerService.focusDrawing([{unitId:n,subUnitId:e,drawingId:t}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Ne.id,r)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(r=>{r==null||r.length===0?(this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(r))}))}};le=yt([z(1,d.Inject(U.SheetSkeletonManagerService)),z(2,d.ICommandService),z(3,U.ISheetSelectionRenderService),z(4,P.IImageIoService),z(5,k.ILocalFileService),z(6,p.ISheetDrawingService),z(7,P.IDrawingManagerService),z(8,d.IContextService),z(9,k.IMessageService),z(10,d.Inject(d.LocaleService)),z(11,d.Inject(_.SheetsSelectionsService)),z(12,d.Inject(d.Injector))],le);var Dt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,Rt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Tt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Dt(r,n,t),t},re=(i,r)=>(n,e)=>r(n,e,i);function je(i,r,n){var e,t,o,a;if(((t=(e=n==null?void 0:n.p)==null?void 0:e.body)==null?void 0:t.dataStream.length)===3&&((a=(o=n.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const c=n.p.drawings[n.p.drawingsOrder[0]],l=Je(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},c.docTransform.size.width,c.docTransform.size.height,c.docTransform.angle);if(l)return c.transform.width=l.width,c.transform.height=l.height,c.docTransform.size.width=l.width,c.docTransform.size.height=l.height,c.transform.left=0,c.transform.top=0,c.docTransform.positionH.posOffset=0,c.docTransform.positionV.posOffset=0,n.p.documentStyle.pageSize.width=1/0,n.p.documentStyle.pageSize.height=1/0,!0}return!1}let fe=class extends d.Disposable{constructor(i,r,n,e,t,o,a){super(),this._commandService=i,this._sheetInterceptorService=r,this._univerInstanceService=n,this._injector=e,this._drawingManagerService=t,this._docDrawingController=o,this._editorBridgeService=a,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{let r,n=[];if(i.id===_.SetWorksheetRowHeightMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetColWidthMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetRowIsAutoHeightMutation.id){const e=i.params;n=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}),n=e.rowsAutoHeightInfo.map(t=>({startRow:t.row,endRow:t.row,startColumn:0,endColumn:9999}))}else if(i.id===_.AddWorksheetMergeMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.RemoveWorksheetMergeMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}r&&n.length&&n.forEach(e=>{const t=d.Range.transformRange(e,r.worksheet);for(let o=t.startRow;o<=t.endRow;o++)for(let a=t.startColumn;a<=t.endColumn;a++)je(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:o,col:a},r.worksheet.getCellRaw(o,a))})}))}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===xe.ReplaceSnapshotCommand.id&&i.params.unitId===d.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(d.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(d.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(d.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(_.AFTER_CELL_EDIT,{priority:9999,handler:(i,r,n)=>(je(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i),n(i))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.CELL_CONTENT,{effect:d.InterceptorEffectEnum.Style,priority:_.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,n)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0}),n(i)}}))}};fe=Rt([re(0,d.ICommandService),re(1,d.Inject(_.SheetInterceptorService)),re(2,d.IUniverInstanceService),re(3,d.Inject(d.Injector)),re(4,P.IDrawingManagerService),re(5,d.Inject(te.DocDrawingController)),re(6,d.Inject(U.IEditorBridgeService))],fe);var bt=Object.defineProperty,Et=Object.getOwnPropertyDescriptor,Ot=(i,r,n,e)=>{for(var t=e>1?void 0:e?Et(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&bt(r,n,t),t},Ze=(i,r)=>(n,e)=>r(n,e,i);let Se=class extends d.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,n,e)=>{new d.ObjectMatrix(e).forValue((t,o,a)=>{je(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:t,col:o},a)})}}))}};Se=Ot([Ze(0,d.Inject(U.IAutoFillService)),Ze(1,d.Inject(d.Injector))],Se);var Pt=Object.defineProperty,At=Object.getOwnPropertyDescriptor,Ut=(i,r,n,e)=>{for(var t=e>1?void 0:e?At(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Pt(r,n,t),t},ve=(i,r)=>(n,e)=>r(n,e,i);let _e=class extends d.Disposable{constructor(r,n,e,t){super();Y(this,"_isSetCursor",!1);this._hoverManagerService=r,this._renderManagerService=n,this._selectionsService=e,this._drawingRenderService=t}_initHover(){}_initImageClick(){}};_e=Ut([ve(0,d.Inject(U.HoverManagerService)),ve(1,d.Inject(N.IRenderManagerService)),ve(2,d.Inject(_.SheetsSelectionsService)),ve(3,d.Inject(q.DrawingRenderService))],_e);var Nt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,Wt=(i,r,n,e)=>{for(var t=e>1?void 0:e?jt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Nt(r,n,t),t},We=(i,r)=>(n,e)=>r(n,e,i);let we=class extends d.Disposable{constructor(r,n,e){super();Y(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=n,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,n,e)=>this._collect(r,n,e),onPasteCells:(r,n,e,t)=>{const{copyType:o=U.COPY_TYPE.COPY,pasteType:a}=t,{range:c}=r||{},{range:l,unitId:h,subUnitId:u}=n;return this._generateMutations(l,{copyType:o,pasteType:a,copyRange:c,unitId:h,subUnitId:u})},onPastePlainText:(r,n)=>({undos:[],redos:[]})})}_collect(r,n,e){var m;const t=(m=this._renderManagerService.getRenderById(r))==null?void 0:m.with(U.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:c,startY:l,endY:h}=o,u=this._sheetDrawingService.getDrawingData(r,n),s=[];Object.keys(u).forEach(g=>{const f=u[g],{transform:S}=f;if(f.anchorType!==p.SheetDrawingAnchorType.Both||!S)return;const{left:v=0,top:C=0,width:M=0,height:y=0}=S,{drawingStartX:R,drawingEndX:I,drawingStartY:D,drawingEndY:w}={drawingStartX:v,drawingEndX:v+M,drawingStartY:C,drawingEndY:C+y};a<=R&&I<=c&&l<=D&&w<=h&&s.push(f)}),s.length&&(this._copyInfo={drawings:s,unitId:r,subUnitId:n})}_generateMutations(r,n){var E;if(!this._copyInfo)return{redos:[],undos:[]};if([U.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,U.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,U.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,U.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(n.pasteType))return{redos:[],undos:[]};const{copyRange:e}=n;if(!e)return{redos:[],undos:[]};const{drawings:t,unitId:o,subUnitId:a}=this._copyInfo,{ranges:[c,l],mapFunc:h}=U.virtualizeDiscreteRanges([e,r]),{row:u,col:s}=h(c.startRow,c.startColumn),{row:m,col:g}=h(l.startRow,l.startColumn),f=(E=this._renderManagerService.getRenderById(o))==null?void 0:E.with(U.SheetSkeletonManagerService);if(!f)return{redos:[],undos:[]};const S=f.attachRangeWithCoord({startRow:u,endRow:u,startColumn:s,endColumn:s}),v=f.attachRangeWithCoord({startRow:m,endRow:m,startColumn:g,endColumn:g});if(!S||!v)return{redos:[],undos:[]};const C=[],M=[],y=v.startX-S.startX,R=v.startY-S.startY,I=m-u,D=g-s,w=n.copyType===U.COPY_TYPE.CUT,{_sheetDrawingService:A}=this;return t.forEach(B=>{const{transform:W,sheetTransform:O}=B;if(!W)return;const T={...B,unitId:o,subUnitId:a,drawingId:w?B.drawingId:d.Tools.generateRandomId(),transform:{...W,left:W.left+y,top:W.top+R},sheetTransform:{to:{...O.to,row:O.to.row+I,column:O.to.column+D},from:{...O.from,row:O.from.row+I,column:O.from.column+D}}};if(w){const{undo:L,redo:$,objects:Z}=A.getBatchUpdateOp([T]);C.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:$,objects:Z}}),M.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:L,objects:Z}})}else{const{undo:L,redo:$,objects:Z}=A.getBatchAddOp([T]);C.push({id:p.SetDrawingApplyMutation.id,params:{op:$,unitId:o,subUnitId:a,objects:Z,type:p.DrawingApplyType.INSERT}}),M.push({id:p.SetDrawingApplyMutation.id,params:{op:L,unitId:o,subUnitId:a,objects:Z,type:p.DrawingApplyType.REMOVE}})}}),{redos:C,undos:M}}};we=Wt([We(0,U.ISheetClipboardService),We(1,N.IRenderManagerService),We(2,p.ISheetDrawingService)],we);var Lt=Object.defineProperty,Bt=Object.getOwnPropertyDescriptor,Gt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Bt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Lt(r,n,t),t},ue=(i,r)=>(n,e)=>r(n,e,i);let Ie=class extends d.Disposable{constructor(i,r,n,e,t){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=n,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(j.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingVisible(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const c=r.getUnitId(),l=e.getSheetId(),h=this._drawingManagerService.getDrawingData(c,l),u=Object.values(h),s=this._renderManagerService.getRenderById(c),m=s==null?void 0:s.scene;if(m==null)return;m.getAllObjectsByOrder().forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>f.oKey.includes(S.drawingId))&&m.removeObject(f)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(j.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingEditable(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const c=r.getUnitId(),l=e.getSheetId(),h=this._drawingManagerService.getDrawingData(c,l),u=Object.values(h),s=this._renderManagerService.getRenderById(c),m=s==null?void 0:s.scene;if(m==null)return;m.getAllObjectsByOrder().forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>f.oKey.includes(S.drawingId))&&m.detachTransformerFrom(f)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(j.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const c=this._renderManagerService.getRenderById(t),l=c==null?void 0:c.scene;if(l==null)return;const h=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).pipe(j.map(m=>m.every(g=>g.value)));u==null||u.pipe(j.filter(m=>m!==a),j.distinctUntilChanged()).subscribe({next:m=>{a=m,this._drawingManagerService.setDrawingVisible(m);const g=l.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);m?this._drawingManagerService.addNotification(S):(g.forEach(v=>{v.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(C=>v.oKey.includes(C.drawingId))&&l.removeObject(v)}),h.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(t,o).id))==null||s.pipe(j.filter(m=>m.value!==a),j.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const m=this._drawingManagerService.getDrawingData(t,o),g=Object.values(m);this._drawingManagerService.addNotification(g)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(j.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const c=this._renderManagerService.getRenderById(t),l=c==null?void 0:c.scene;if(l==null)return;const h=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).pipe(j.map(m=>m.every(g=>g.value)));u==null||u.pipe(j.filter(m=>m!==a),j.distinctUntilChanged()).subscribe({next:m=>{a=m,this._drawingManagerService.setDrawingEditable(m);const g=l.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);m?(g.forEach(v=>{v.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(C=>v.oKey.includes(C.drawingId))&&l.attachTransformerTo(v)}),this._drawingManagerService.addNotification(S)):(g.forEach(v=>{v.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(C=>v.oKey.includes(C.drawingId))&&l.detachTransformerFrom(v)}),h.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(t,o).id))==null||s.pipe(j.filter(m=>m.value!==a),j.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const m=r.getUnitId(),g=e.getSheetId(),f=this._drawingManagerService.getDrawingData(m,g),S=Object.values(f),v=this._renderManagerService.getRenderById(m),C=v==null?void 0:v.scene;if(C==null)return;this._drawingManagerService.setDrawingEditable(!0),C.getAllObjectsByOrder().forEach(y=>{y.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(R=>y.oKey.includes(R.drawingId))&&C.detachTransformerFrom(y)})}})})}))}};Ie=Gt([ue(0,P.IDrawingManagerService),ue(1,N.IRenderManagerService),ue(2,d.IPermissionService),ue(3,d.IUniverInstanceService),ue(4,d.Inject(d.UserManagerService))],Ie);var kt=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,$t=(i,r,n,e)=>{for(var t=e>1?void 0:e?Ft(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&kt(r,n,t),t},Ce=(i,r)=>(n,e)=>r(n,e,i);let ye=class extends d.Disposable{constructor(i,r,n,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=n,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,n)=>{const{unitId:e,scene:t,subUnitId:o}=r,a=this._drawingManagerService.getDrawingDataForUnit(e),c=a==null?void 0:a[o];return c&&c.order.forEach(l=>{this._drawingRenderService.renderDrawing(c.data[l],t)}),n()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,n)=>{const{unitId:e,subUnitId:t}=r,o=this._renderManagerService.getRenderById(e);if(!o)return n(i);const a=o.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(t);if(!a)return n(i);const c=this._drawingManagerService.getDrawingDataForUnit(e),l=c==null?void 0:c[r.subUnitId];if(!l)return n(i);const{scaleX:h,scaleY:u}=o.scene,s=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=l.order.map(g=>l.data[g]).filter(g=>g.drawingType!==d.DrawingTypeEnum.DRAWING_DOM);return m.length?(m.forEach(g=>{if(!g.groupId&&g.transform&&d.Tools.isDefine(g.transform.left)&&d.Tools.isDefine(g.transform.top)&&d.Tools.isDefine(g.transform.width)&&d.Tools.isDefine(g.transform.height)){const f=a.skeleton.getCellIndexByOffset(g.transform.left,g.transform.top,h,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(g.transform.left+g.transform.width,g.transform.top+g.transform.height,h,u,{x:0,y:0});f.column<s.startColumn&&(s.startColumn=f.column),f.row<s.startRow&&(s.startRow=f.row),s.endRow<S.row&&(s.endRow=S.row),s.endColumn<S.column&&(s.endColumn=S.column)}}),n(s)):n(i)}}))}};ye=$t([Ce(0,d.Inject(U.SheetPrintInterceptorService)),Ce(1,d.Inject(q.DrawingRenderService)),Ce(2,P.IDrawingManagerService),Ce(3,N.IRenderManagerService)],ye);var Ht=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,xt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Vt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Ht(r,n,t),t},Q=(i,r)=>(n,e)=>r(n,e,i);const Yt=[_.InsertRowCommand.id,_.InsertColCommand.id,_.RemoveRowCommand.id,_.RemoveColCommand.id,_.DeleteRangeMoveLeftCommand.id,_.DeleteRangeMoveUpCommand.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id,_.DeltaRowHeightCommand.id,_.SetRowHeightCommand.id,_.DeltaColumnWidthCommand.id,_.SetColWidthCommand.id,_.SetRowHiddenCommand.id,_.SetSpecificRowsVisibleCommand.id,_.SetSpecificColsVisibleCommand.id,_.SetColHiddenCommand.id,_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id],Xt=[_.SetRowVisibleMutation.id,_.SetRowHiddenMutation.id,_.SetColVisibleMutation.id,_.SetColHiddenMutation.id,_.SetWorksheetRowHeightMutation.id,_.SetWorksheetColWidthMutation.id];let Le=class extends d.Disposable{constructor(i,r,n,e,t,o,a,c,l){super(),this._context=i,this._renderManagerService=r,this._commandService=n,this._selectionRenderService=e,this._skeletonManagerService=t,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=c,this._univerInstanceService=l,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!Yt.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const 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:n}=i.params;return this._getRangeMoveUndo(n,0)}else if(r===_.DeleteRangeMoveUpCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,1)}else if(r===_.InsertRangeMoveDownCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,2)}else if(r===_.InsertRangeMoveRightCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,3)}else if(r===_.SetRowHiddenCommand.id||r===_.SetSpecificRowsVisibleCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForRowVisible(e,t,o)}else if(r===_.SetSpecificColsVisibleCommand.id||r===_.SetColHiddenCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForColVisible(e,t,o)}else if(r===_.DeltaRowHeightCommand.id||r===_.SetRowHeightCommand.id||r===_.DeltaColumnWidthCommand.id||r===_.SetColWidthCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n,a=r===_.DeltaRowHeightCommand.id||r===_.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const n=_.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const e=n.unitId,t=n.subUnitId,o=[],a=[],c=this._sheetDrawingService.getDrawingData(e,t),l=[],h=[];if(Object.keys(c).forEach(u=>{const s=c[u],{updateDrawings:m,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(i,r,s);l.push(...m),h.push(...g)}),l.length===0&&h.length===0)return{redos:[],undos:[]};if(l.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(l),{undo:s,redo:m,objects:g}=u;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:m,objects:g,type:p.DrawingApplyType.UPDATE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:s,objects:g,type:p.DrawingApplyType.UPDATE}})}if(h.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(h),s=u.undo,m=u.redo,g=u.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:m,objects:g,type:p.DrawingApplyType.REMOVE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:s,objects:g,type:p.DrawingApplyType.INSERT}})}return o.push({id:G.id,params:[e]}),a.push({id:G.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,r,n){const e=[],t=[],{sheetTransform:o,anchorType:a=p.SheetDrawingAnchorType.Position,transform:c,unitId:l,subUnitId:h,drawingId:u}=n,{from:s,to:m}=o,{row:g,column:f}=s,{row:S,column:v}=m;if(o==null||c==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:C,endRow:M,startColumn:y,endColumn:R}=i;let I=null,D=null;if(r===0&&g>=C&&S<=M)if(f>=y&&v<=R)t.push({unitId:l,subUnitId:h,drawingId:u});else{const w=this._shrinkCol(o,c,y,R,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(r===1&&f>=y&&v<=R)if(g>=C&&S<=M)t.push({unitId:l,subUnitId:h,drawingId:u});else{const w=this._shrinkRow(o,c,C,M,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(r===2){const w=this._expandRow(o,c,C,M,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(r===3){const w=this._expandCol(o,c,y,R,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}if(I!=null&&D!=null){const w=V(I,this._selectionRenderService,this._skeletonManagerService);e.push({...n,sheetTransform:I,transform:w})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(i,r,n){const e=F({...i},this._selectionRenderService);e!=null&&r.push({...n,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(u=>{const s=e[u],{sheetTransform:m,transform:g,anchorType:f=p.SheetDrawingAnchorType.Position}=s;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,s);else{const{from:S,to:v}=m,{row:C,column:M}=S,{row:y,column:R}=v;for(let I=0;I<n.length;I++){const D=n[I],{startRow:w,endRow:A,startColumn:E,endColumn:B}=D;if(R<E)continue;if(f===p.SheetDrawingAnchorType.Position){let T=null,L=null;if(M>=E&&M<=B){const $=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:B,startRow:S.row,endRow:v.row});if($==null)return;L={...g,left:$.startX}}if(L!=null&&(T=F(L,this._selectionRenderService),T!=null&&L!=null)){t.push({...s,sheetTransform:T,transform:L});break}this._remainDrawingSize(g,t,s);continue}if(M>=E&&R<=B)continue;let W=null,O=null;if(M>=E&&M<=B){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:B,startRow:S.row,endRow:v.row});if(T==null)return;O={...g,left:(T==null?void 0:T.startX)||0,width:((g==null?void 0:g.width)||0)-T.endX+T.startX}}else if(R>=E&&R<=B){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:R,startRow:S.row,endRow:v.row});if(T==null)return;O={...g,left:T.startX-((g==null?void 0:g.width)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:B,startRow:S.row,endRow:v.row});if(T==null)return;if(O={...g,width:((g==null?void 0:g.width)||0)-T.endX+T.startX},W=F(O,this._selectionRenderService),W!=null&&O!=null){o.push({...s,sheetTransform:W,transform:O});break}}if(O!=null&&(W=F(O,this._selectionRenderService)),O!=null&&W!=null){t.push({...s,sheetTransform:W,transform:O});break}else this._remainDrawingSize(g,t,s)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:c}=this._createUndoAndRedoMutation(i,r,t),l=[],h=[];if(o.length>0){const{redos:u,undos:s}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),h.push(...s)}return{redos:a,undos:c,preRedos:l,preUndos:h}}_createUndoAndRedoMutation(i,r,n){const e=this._sheetDrawingService.getBatchUpdateOp(n),{undo:t,redo:o,objects:a}=e,c=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],l=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:t,objects:a,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:c,undos:l}}_getDrawingUndoForRowVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(u=>{const s=e[u],{sheetTransform:m,transform:g,anchorType:f=p.SheetDrawingAnchorType.Position}=s;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,s);else{const{from:S,to:v}=m,{row:C,column:M}=S,{row:y,column:R}=v;for(let I=0;I<n.length;I++){const D=n[I],{startRow:w,endRow:A,startColumn:E,endColumn:B}=D;if(y<w)continue;if(f===p.SheetDrawingAnchorType.Position){let T=null,L=null;if(C>=w&&C<=A){const $=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:C,endRow:A});if($==null)return;L={...g,top:$.startY}}if(L!=null&&(T=F(L,this._selectionRenderService),T!=null&&L!=null)){t.push({...s,sheetTransform:T,transform:L});break}this._remainDrawingSize(g,t,s);continue}if(C>=w&&y<=A)continue;let W=null,O=null;if(C>=w&&C<=A){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:C,endRow:A});if(T==null)return;O={...g,top:(T==null?void 0:T.startY)||0,height:((g==null?void 0:g.height)||0)-T.endY+T.startY}}else if(y>=w&&y<=A){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:w,endRow:y});if(T==null)return;O={...g,top:T.startY-((g==null?void 0:g.height)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:w,endRow:A});if(T==null)return;if(O={...g,height:((g==null?void 0:g.height)||0)-T.endY+T.startY},W=F(O,this._selectionRenderService),W!=null&&O!=null){o.push({...s,sheetTransform:W,transform:O});break}}if(O!=null&&(W=F(O,this._selectionRenderService)),O!=null&&W!=null){t.push({...s,sheetTransform:W,transform:O});break}else this._remainDrawingSize(g,t,s)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:c}=this._createUndoAndRedoMutation(i,r,t),l=[],h=[];if(o.length>0){const{redos:u,undos:s}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),h.push(...s)}return{redos:a,undos:c,preRedos:l,preUndos:h}}_getDrawingUndoForRowAndColSize(i,r,n,e){const t=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(t).forEach(a=>{const c=t[a],{sheetTransform:l,transform:h,anchorType:u=p.SheetDrawingAnchorType.Position}=c;if(u===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,o,c);else{const{from:s,to:m}=l,{row:g,column:f}=s,{row:S,column:v}=m;for(let C=0;C<n.length;C++){const M=n[C],{startRow:y,endRow:R,startColumn:I,endColumn:D}=M;if(S<y||v<I)continue;if(u===p.SheetDrawingAnchorType.Position&&(g<=y&&S>=R||f<=I&&v>=D)){this._remainDrawingSize(h,o,c);continue}const w=V({...l},this._selectionRenderService,this._skeletonManagerService);if(w!=null){o.push({...c,transform:w});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let n,e;if(r==="insert")n=i.unitId,e=i.subUnitId;else{const t=_.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;n=t.unitId,e=t.subUnitId}return{unitId:n,subUnitId:e}}_moveRangeInterceptor(i){var y,R;const{toRange:r,fromRange:n}=i,e=_.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,a=(R=(y=this._renderManagerService.getRenderById(t))==null?void 0:y.with(U.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const c=U.attachRangeWithCoord(a,n);if(!c)return{redos:[],undos:[]};const{startX:l,endX:h,startY:u,endY:s}=c,m=this._sheetDrawingService.getDrawingData(t,o),g=[];Object.keys(m).forEach(I=>{const D=m[I];if(D.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:w}=D;if(!w)return;const{left:A=0,top:E=0,width:B=0,height:W=0}=w,{drawingStartX:O,drawingEndX:T,drawingStartY:L,drawingEndY:$}={drawingStartX:A,drawingEndX:A+B,drawingStartY:E,drawingEndY:E+W};l<=O&&T<=h&&u<=L&&$<=s&&g.push(D)});const f=[],S=[],v=r.startRow-n.startRow,C=r.startColumn-n.startColumn,M=g.map(I=>{const D=I.sheetTransform,w={to:{...D.to,row:D.to.row+v,column:D.to.column+C},from:{...D.from,row:D.from.row+v,column:D.from.column+C}},A=V(w,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:I.drawingId,transform:A,sheetTransform:w}});if(M.length){const I=this._sheetDrawingService.getBatchUpdateOp(M),{undo:D,redo:w,objects:A}=I;f.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:w,objects:A,type:p.DrawingApplyType.UPDATE}}),S.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:D,objects:A,type:p.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startRow,c=o.endRow,l=[],h=[],u=this._sheetDrawingService.getDrawingData(e,t),s=[],m=[];if(Object.keys(u).forEach(g=>{const f=u[g],{sheetTransform:S,transform:v,anchorType:C=p.SheetDrawingAnchorType.Position}=f;if(S==null||v==null)return;let M,y;if(r==="insert"){const I=this._expandRow(S,v,a,c,C);M=I==null?void 0:I.newSheetTransform,y=I==null?void 0:I.newTransform}else{const{from:I,to:D}=S,{row:w}=I,{row:A}=D;if(C===p.SheetDrawingAnchorType.Both&&w>=a&&A<=c)m.push({unitId:e,subUnitId:t,drawingId:g});else{const E=this._shrinkRow(S,v,a,c,C);M=E==null?void 0:E.newSheetTransform,y=E==null?void 0:E.newTransform}}if(!M||!y)return;const R={unitId:e,subUnitId:t,drawingId:g,transform:y,sheetTransform:M};s.push(R)}),s.length===0&&m.length===0)return{redos:[],undos:[]};if(s.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(s),{undo:f,redo:S,objects:v}=g;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.UPDATE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(m),f=g.undo,S=g.redo,v=g.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.REMOVE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),h.push({id:G.id,params:[e]}),{redos:l,undos:h}}_moveColInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startColumn,c=o.endColumn,l=[],h=[],u=this._sheetDrawingService.getDrawingData(e,t),s=[],m=[];if(Object.keys(u).forEach(g=>{const f=u[g],{sheetTransform:S,transform:v,anchorType:C=p.SheetDrawingAnchorType.Position}=f;if(S==null||v==null)return;let M,y;if(r==="insert"){const I=this._expandCol(S,v,a,c,C);M=I==null?void 0:I.newSheetTransform,y=I==null?void 0:I.newTransform}else{const{from:I,to:D}=S,{column:w}=I,{column:A}=D;if(C===p.SheetDrawingAnchorType.Both&&w>=a&&A<=c)m.push({unitId:e,subUnitId:t,drawingId:g});else{const E=this._shrinkCol(S,v,a,c,C);M=E==null?void 0:E.newSheetTransform,y=E==null?void 0:E.newTransform}}if(!M||!y)return;const R={unitId:e,subUnitId:t,drawingId:g,transform:y,sheetTransform:M};s.push(R)}),s.length===0&&m.length===0)return{redos:[],undos:[]};if(s.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(s),{undo:f,redo:S,objects:v}=g;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.UPDATE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(m),f=g.undo,S=g.redo,v=g.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.REMOVE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),h.push({id:G.id,params:[e]}),{redos:l,undos:h}}_expandCol(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{column:l}=a,{column:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>=n){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:e,startRow:a.row,endRow:c.row});if(m==null)return;s={...r,left:(r.left||0)+m.endX-m.startX},u=F(s,this._selectionRenderService)}else if(h>=e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,column:h+o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_shrinkCol(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{column:l}=a,{column:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>e)u={from:{...a,column:l-o},to:{...c,column:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=n&&h<=e)return null;if(l<n&&h>e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,column:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};else if(l>=n&&l<=e){if(l===n)s={...r,left:(r.left||0)-i.from.columnOffset};else{const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:l-1,startRow:a.row,endRow:c.row});if(m==null)return;s={...r,left:(r.left||0)-m.endX+m.startX-i.from.columnOffset}}u=F(s,this._selectionRenderService)}else if(h>=n&&h<=e&&t===p.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:n-1,endColumn:n-1,startRow:a.row,endRow:c.row});if(m==null)return;u={from:{...a},to:{...c,column:n-1,columnOffset:m.endX-m.startX}},s=V(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_expandRow(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{row:l}=a,{row:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>=n){const m=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:e,startColumn:a.column,endColumn:c.column});if(m==null)return;s={...r,top:(r.top||0)+m.endY-m.startY},u=F(s,this._selectionRenderService)}else if(h>=e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,row:h+o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_shrinkRow(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{row:l}=a,{row:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>e)u={from:{...a,row:l-o},to:{...c,row:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=n&&h<=e)return null;if(l<n&&h>e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,row:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};else if(l>=n&&l<=e){if(l===n)s={...r,top:(r.top||0)-i.from.rowOffset};else{const m=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:l-1,startColumn:a.column,endColumn:c.column});if(m==null)return;s={...r,top:(r.top||0)-m.endY+m.startY-i.from.rowOffset}}u=F(s,this._selectionRenderService)}else if(h>=n&&h<=e&&t===p.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:n-1,endRow:n-1});if(m==null)return;u={from:{...a},to:{...c,row:n-1,rowOffset:m.endY-m.startY}},s=V(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===_.SetWorksheetActiveOperation.id&&setTimeout(()=>{const r=i.params,{unitId:n,subUnitId:e}=r,t=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(t).forEach(c=>{const l=t[c];l!=null&&Object.keys(l).forEach(h=>{const u=l[h].data;u!=null&&Object.keys(u).forEach(s=>{if(c===n&&h===e){const m=u[s];m.transform=V(m.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(u[s])}else a.push(u[s])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Xt.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:n,subUnitId:e,ranges:t}=r;this._refreshDrawingTransform(n,e,t)})}))}_refreshDrawingTransform(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:c,transform:l,anchorType:h=p.SheetDrawingAnchorType.Position}=a;if(h===p.SheetDrawingAnchorType.None)return!0;const{from:u,to:s}=c,{row:m,column:g}=u,{row:f,column:S}=s;for(let v=0;v<n.length;v++){const C=n[v],{startRow:M,endRow:y,startColumn:R,endColumn:I}=C;if(d.Rectangle.intersects({startRow:M,endRow:y,startColumn:R,endColumn:I},{startRow:m,endRow:f,startColumn:g,endColumn:S})||m>y||g>I){const D=h===p.SheetDrawingAnchorType.Position,w=V(c,this._selectionRenderService,this._skeletonManagerService);t.push({...a,transform:{...w,width:D?l==null?void 0:l.width:w==null?void 0:w.width,height:D?l==null?void 0:l.height:w==null?void 0:w.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(G.id,[i]))}};Le=xt([Q(1,N.IRenderManagerService),Q(2,d.ICommandService),Q(3,U.ISheetSelectionRenderService),Q(4,d.Inject(U.SheetSkeletonManagerService)),Q(5,d.Inject(_.SheetInterceptorService)),Q(6,p.ISheetDrawingService),Q(7,P.IDrawingManagerService),Q(8,d.IUniverInstanceService)],Le);var K=function(){return K=Object.assign||function(i){for(var r,n=1,e=arguments.length;n<e;n++){r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(i[t]=r[t])}return i},K.apply(this,arguments)},zt=function(i,r){var n={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(n[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(i);t<e.length;t++)r.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(i,e[t])&&(n[e[t]]=i[e[t]]);return n},qe=X.forwardRef(function(i,r){var n=i.icon,e=i.id,t=i.className,o=i.extend,a=zt(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),l=X.useRef("_".concat(Zt()));return Qe(n,"".concat(e),{defIds:n.defIds,idSuffix:l.current},K({ref:r,className:c},a),o)});function Qe(i,r,n,e,t){return X.createElement(i.tag,K(K({key:r},Kt(i,n,t)),e),(Jt(i,n).children||[]).map(function(o,a){return Qe(o,"".concat(r,"-").concat(i.tag,"-").concat(a),n,void 0,t)}))}function Kt(i,r,n){var e=K({},i.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var t=r.defIds;return!t||t.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],c=o[1];typeof c=="string"&&(e[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Jt(i,r){var n,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?K(K({},i),{children:i.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?K(K({},t),{attrs:K(K({},t.attrs),{id:t.attrs.id+r.idSuffix})}):t})}):i}function Zt(){return Math.random().toString(36).substring(2,8)}qe.displayName="UniverIcon";var qt={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"}}]},et=X.forwardRef(function(i,r){return X.createElement(qe,Object.assign({},i,{id:"add-image-single",ref:r,icon:qt}))});et.displayName="AddImageSingle";const Be={id:"sheet.command.delete-drawing",type:d.CommandType.COMMAND,handler:i=>{const r=i.get(d.ICommandService),e=i.get(p.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(a=>{const{unitId:c,subUnitId:l,drawingId:h,drawingType:u}=a;return{unitId:c,subUnitId:l,drawingId:h,drawingType:u}});return r.executeCommand(ae.id,{unitId:t,drawings:o})}},Me={id:"sheet.command.insert-float-image",type:d.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(N.IRenderManagerService).getCurrentTypeOfRenderer(d.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(le).insertFloatImage())!=null?e:!1}},Ge={id:"sheet.command.insert-cell-image",type:d.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(N.IRenderManagerService).getCurrentTypeOfRenderer(d.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(le).insertCellImage())!=null?e:!1}},oe={id:"sheet.command.move-drawing",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(p.ISheetDrawingService),t=i.get(U.ISheetSelectionRenderService),{direction:o}=r,a=e.getFocusDrawings();if(a.length===0)return!1;const c=a[0].unitId,l=a.map(u=>{const{transform:s}=u;if(s==null)return null;const m={...s},{left:g=0,top:f=0}=s;return o===d.Direction.UP?m.top=f-1:o===d.Direction.DOWN?m.top=f+1:o===d.Direction.LEFT?m.left=g-1:o===d.Direction.RIGHT&&(m.left=g+1),{...u,transform:m,sheetTransform:F(m,t)}}).filter(u=>u!=null);return n.syncExecuteCommand(de.id,{unitId:c,drawings:l})?(n.syncExecuteCommand(G.id,[c]),!0):!1}},tt="addition-and-subtraction-single",ke="sheet.menu.image";function Qt(i){return{id:ke,type:k.MenuItemType.SUBITEMS,icon:tt,tooltip:"sheetImage.title",hidden$:k.getMenuHiddenObservable(i,d.UniverInstanceType.UNIVER_SHEET),disabled$:U.getCurrentRangeDisable$(i,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function en(i){return{id:Me.id,title:"sheetImage.upload.float",type:k.MenuItemType.BUTTON,hidden$:k.getMenuHiddenObservable(i,d.UniverInstanceType.UNIVER_SHEET)}}function tn(i){return{id:Ge.id,title:"sheetImage.upload.cell",type:k.MenuItemType.BUTTON}}const ee={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelSubtitle:"univer-image-common-panel-subtitle",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"};function nt(i){var r,n,e="";if(typeof i=="string"||typeof i=="number")e+=i;else if(typeof i=="object")if(Array.isArray(i)){var t=i.length;for(r=0;r<t;r++)i[r]&&(n=nt(i[r]))&&(e&&(e+=" "),e+=n)}else for(n in i)i[n]&&(e&&(e+=" "),e+=n);return e}function De(){for(var i,r,n=0,e="",t=arguments.length;n<t;n++)(i=arguments[n])&&(r=nt(i))&&(e&&(e+=" "),e+=r);return e}const nn=i=>{var y;const r=d.useDependency(d.ICommandService),n=d.useDependency(d.LocaleService),e=d.useDependency(P.IDrawingManagerService),t=d.useDependency(N.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:c}=a,l=t.getRenderById(c),h=l==null?void 0:l.scene;if(h==null)return;const u=h.getTransformerByCreate(),[s,m]=X.useState(!0),g=(y=a.anchorType)!=null?y:p.SheetDrawingAnchorType.Position,[f,S]=X.useState(g);function v(R,I){const D=[];return R.forEach(w=>{const{oKey:A}=w,E=I.getDrawingOKey(A);if(E==null)return D.push(null),!0;const{unitId:B,subUnitId:W,drawingId:O,drawingType:T,anchorType:L,sheetTransform:$}=E;D.push({unitId:B,subUnitId:W,drawingId:O,anchorType:L,sheetTransform:$,drawingType:T})}),D}X.useEffect(()=>{const R=u.clearControl$.subscribe(D=>{D===!0&&m(!1)}),I=u.changeStart$.subscribe(D=>{var E;const{objects:w}=D,A=v(w,e);if(A.length===0)m(!1);else if(A.length>=1){m(!0);const B=((E=A[0])==null?void 0:E.anchorType)||p.SheetDrawingAnchorType.Position;S(B)}});return()=>{I.unsubscribe(),R.unsubscribe()}},[]);function C(R){S(R);const I=e.getFocusDrawings();if(I.length===0)return;const D=I.map(w=>({unitId:w.unitId,subUnitId:w.subUnitId,drawingId:w.drawingId,anchorType:R}));r.executeCommand(de.id,{unitId:I[0].unitId,drawings:D})}const M=R=>R?"block":"none";return H.jsxs("div",{className:De(ee.imageCommonPanelGrid,ee.imageCommonPanelBorder),style:{display:M(s)},children:[H.jsx("div",{className:ee.imageCommonPanelRow,children:H.jsx("div",{className:De(ee.imageCommonPanelColumn,ee.imageCommonPanelTitle),children:H.jsx("div",{children:n.t("drawing-anchor.title")})})}),H.jsx("div",{className:De(ee.imageCommonPanelRow),children:H.jsx("div",{className:De(ee.imageCommonPanelColumn),children:H.jsxs(J.RadioGroup,{value:f,onChange:C,direction:"vertical",children:[H.jsx(J.Radio,{value:p.SheetDrawingAnchorType.Both,children:n.t("drawing-anchor.both")}),H.jsx(J.Radio,{value:p.SheetDrawingAnchorType.Position,children:n.t("drawing-anchor.position")}),H.jsx(J.Radio,{value:p.SheetDrawingAnchorType.None,children:n.t("drawing-anchor.none")})]})})})]})},rn=()=>{const i=d.useDependency(P.IDrawingManagerService),r=i.getFocusDrawings(),[n,e]=X.useState(r);return X.useEffect(()=>{const t=i.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(n!=null&&n.length)&&H.jsxs("div",{className:ee.imageCommonPanel,children:[H.jsx(q.DrawingCommonPanel,{drawings:n}),H.jsx(nn,{drawings:n})]})},on={[k.RibbonStartGroup.FORMULAS_INSERT]:{[ke]:{order:3,menuItemFactory:Qt,[Me.id]:{order:0,menuItemFactory:en},[Ge.id]:{order:1,menuItemFactory:tn}}}};function ge(i){return!i.getContextValue(d.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(d.EDITOR_ACTIVATED)&&!i.getContextValue(d.FOCUSING_PANEL_EDITOR)&&i.getContextValue(d.FOCUSING_COMMON_DRAWINGS)}const an={id:oe.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_DOWN,priority:100,preconditions:ge,staticParameters:{direction:d.Direction.DOWN}},sn={id:oe.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_UP,priority:100,preconditions:ge,staticParameters:{direction:d.Direction.UP}},cn={id:oe.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_LEFT,priority:100,preconditions:ge,staticParameters:{direction:d.Direction.LEFT}},dn={id:oe.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_RIGHT,priority:100,preconditions:ge,staticParameters:{direction:d.Direction.RIGHT}},ln={id:Be.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:ge,binding:k.KeyCode.DELETE,mac:k.KeyCode.BACKSPACE};var un=Object.defineProperty,gn=Object.getOwnPropertyDescriptor,mn=(i,r,n,e)=>{for(var t=e>1?void 0:e?gn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&un(r,n,t),t},Te=(i,r)=>(n,e)=>r(n,e,i);let Re=class extends d.Disposable{constructor(i,r,n,e){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=n,this._shortcutService=e,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(tt,et)),this.disposeWithMe(i.register(Xe,rn))}_initMenus(){this._menuManagerService.mergeMenu(on)}_initCommands(){[Me,Ge,ce,ae,de,be,G,Ee,Ae,Ne,oe,Be,Ue].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[an,sn,cn,dn,ln].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Re=mn([Te(0,d.Inject(k.ComponentManager)),Te(1,k.IMenuManagerService),Te(2,d.ICommandService),Te(3,k.IShortcutService)],Re);var hn=Object.defineProperty,pn=Object.getOwnPropertyDescriptor,fn=(i,r,n,e)=>{for(var t=e>1?void 0:e?pn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&hn(r,n,t),t},ie=(i,r)=>(n,e)=>r(n,e,i);function Sn(i,r,n,e){const{scaleX:t,scaleY:o}=r.getAncestorScale(),a=r.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN),c={left:!0,top:!0};if(!a)return{...i,absolute:c};const{left:l,right:h,top:u,bottom:s}=i,m=e.getFreeze(),{startColumn:g,startRow:f,xSplit:S,ySplit:v}=m,C=n.getNoMergeCellPositionByIndexWithNoHeader(f-v,g-S),M=n.getNoMergeCellPositionByIndexWithNoHeader(f,g),{rowHeaderWidth:y,columnHeaderHeight:R}=n,I=M.startX-C.startX,D=M.startY-C.startY,{top:w,left:A,viewportScrollX:E,viewportScrollY:B}=a;let W,O;l<A?(c.left=!0,W=(I+y+(l-A))*t,O=Math.max(Math.min((I+y+(h-A))*t,(I+y)*t),(h-E)*t)):(c.left=!1,W=Math.max((l-E)*t,(I+y)*t),O=Math.max((h-E)*t,(I+y)*t));let T,L;return u<w?(c.top=!0,T=(D+R+(u-w))*o,L=Math.max(Math.min((D+R+(h-w))*o,(D+R)*o),(s-B)*o)):(c.top=!1,T=Math.max((u-B)*o,(D+R)*o),L=Math.max((s-B)*o,(D+R)*o)),{left:W,right:O,top:T,bottom:L,absolute:c}}const Fe=(i,r,n,e)=>{const{scene:t}=r,{left:o,top:a,width:c,height:l,angle:h}=i,u={left:o,right:o+c,top:a,bottom:a+l},s=Sn(u,t,n,e),{scaleX:m,scaleY:g}=t.getAncestorScale();return{startX:s.left,endX:s.right,startY:s.top,endY:s.bottom,rotate:h,width:c*m,height:l*g,absolute:s.absolute}};b.SheetCanvasFloatDomManagerService=class extends d.Disposable{constructor(n,e,t,o,a,c,l){super();Y(this,"_domLayerMap",new Map);Y(this,"_domLayerInfoMap",new Map);Y(this,"_transformChange$",new j.Subject);Y(this,"transformChange$",this._transformChange$.asObservable());Y(this,"_add$",new j.Subject);Y(this,"add$",this._add$.asObservable());Y(this,"_remove$",new j.Subject);Y(this,"remove$",this._remove$.asObservable());Y(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=c,this._lifecycleService=l,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(j.filter(n=>n===d.LifecycleStages.Rendered),j.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(n,e){let t=this._domLayerMap.get(n);t||(t=new Map,this._domLayerMap.set(n,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(n){return this._domLayerInfoMap.get(n)}_getSceneAndTransformerByDrawingSearch(n){if(n==null)return;const e=this._renderManagerService.getRenderById(n),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:t,transformer:o,renderObject:e,canvas:a}}_getFloatDomProps(n){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(n)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(n=>{n.forEach(e=>{var at,st,ct;const{unitId:t,subUnitId:o,drawingId:a}=e,c=_.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),l=this._drawingManagerService.getDrawingByParam(e),h=this._univerInstanceService.getUnit(t,d.UniverInstanceType.UNIVER_SHEET);if(!h)return;const u=h.getActiveSheet().getSheetId();if(!l||!c)return;const s=(at=this._renderManagerService.getRenderById(t))==null?void 0:at.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!s)return;const{transform:m,drawingType:g,data:f}=l;if(g!==d.DrawingTypeEnum.DRAWING_DOM&&g!==d.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(t);if(S==null)return;const{scene:v,canvas:C}=S;if(m==null)return!0;if(u!==o)return;const{left:M,top:y,width:R,height:I,angle:D,flipX:w,flipY:A,skewX:E,skewY:B}=m,W=P.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),O=v.getObject(W);if(O!=null){O.transformByState({left:M,top:y,width:R,height:I,angle:D,flipX:w,flipY:A,skewX:E,skewY:B});return}const T={left:M,top:y,width:R,height:I,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},L=g===d.DrawingTypeEnum.DRAWING_CHART;if(L){const x=f?f.backgroundColor:"white";T.fill=x,T.rotateEnabled=!1,f&&f.border&&(T.stroke=f.border),T.paintFirst="stroke",T.strokeWidth=1,T.borderEnabled=!1,T.radius=8}const $=new N.Rect(W,T);L&&$.setObjectType(N.ObjectType.CHART),v.addObject($,N.DRAWING_OBJECT_LAYER_INDEX),l.allowTransform!==!1&&v.attachTransformerTo($);const Z=this._ensureMap(t,o),He=new d.DisposableCollection,Cn=Fe($,S.renderObject,s.skeleton,c.worksheet),Ve=new j.BehaviorSubject(Cn),yn={dispose:He,rect:$,position$:Ve,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:Ve,id:a,componentKey:l.componentKey,onPointerDown:x=>{C.dispatchEvent(new PointerEvent(x.type,x))},onPointerMove:x=>{C.dispatchEvent(new PointerEvent(x.type,x))},onPointerUp:x=>{C.dispatchEvent(new PointerEvent(x.type,x))},onWheel:x=>{C.dispatchEvent(new WheelEvent(x.type,x))},props:(ct=(st=Z.get(a))==null?void 0:st.props)!=null?ct:this._getFloatDomProps(a),data:f,unitId:t});const ot=$.onTransformChange$.subscribeEvent(()=>{const x=Fe($,S.renderObject,s.skeleton,c.worksheet);Ve.next(x)});He.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),ot&&He.add(ot),this._domLayerInfoMap.set(a,yn),Z.set(a,{...Z.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a}=e,c=P.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),l=this._getSceneAndTransformerByDrawingSearch(t);if(l==null)return;const{transformer:h,scene:u}=l,s=u.getObject(c);s!=null&&s.oKey&&h.clearControlByIds([s==null?void 0:s.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,t),c=Array.from(a.keys()),l=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),h=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(t);!o||!l||!h||c.forEach(s=>{const m=this._domLayerInfoMap.get(s);if(m){const g=Fe(m.rect,o.renderObject,h.skeleton,l.worksheet);m.position$.next(g)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(j.filter(e=>!!e),j.switchMap(e=>e.activeSheet$),j.filter(e=>!!e),j.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),j.filter(e=>!!e),j.switchMap(e=>d.fromEventSubject(e.render.scene.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(j.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{n(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===U.SetZoomRatioOperation.id){const a=e.params,{unitId:c}=a;Array.from((o=(t=this._domLayerMap.get(c))==null?void 0:t.keys())!=null?o:[]).forEach(h=>{n(c,h)})}else if(e.id===_.SetFrozenMutation.id){const{unitId:a,subUnitId:c}=e.params;n(a,c)}}))}_getPosition(n,e){var g;const{startX:t,endX:o,startY:a,endY:c}=n,l=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(U.ISheetSelectionRenderService);if(l==null)return;const h=l.getCellWithCoordByOffset(t,a);if(h==null)return;const u={column:h.actualColumn,columnOffset:t-h.startX,row:h.actualRow,rowOffset:a-h.startY},s=l.getCellWithCoordByOffset(o,c);if(s==null)return;const m={column:s.actualColumn,columnOffset:o-s.startX,row:s.actualRow,rowOffset:c-s.startY};return{from:u,to:m}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==d.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==d.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(n,e,t,o){const a=this._domLayerInfoMap.get(t),c=this._getSceneAndTransformerByDrawingSearch(n);if(a&&c){const{scene:l}=c,h=P.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),u=l.getObject(h);u&&u instanceof N.Rect&&u.setProps(o)}}addFloatDomToPosition(n,e){const t=_.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=t,{initPosition:c,componentKey:l,data:h,allowTransform:u=!0}=n,s=e!=null?e:d.generateRandomId(),m=this._getPosition(c,o);if(m==null)return;this._ensureMap(o,a).set(s,n);const f={unitId:o,subUnitId:a,drawingId:s,drawingType:n.type||d.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:m,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},data:h,allowTransform:u};return this._commandService.executeCommand(ce.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:a,id:s}),{id:s,dispose:()=>{this._removeDom(s,!0)}}}_removeDom(n,e=!1){const t=this._domLayerInfoMap.get(n);if(!t)return;const{unitId:o,subUnitId:a}=t;this._domLayerInfoMap.delete(n),t.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(t.rect),e){this._ensureMap(o,a).delete(n);const h=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:n});if(!h)return;const u=this._sheetDrawingService.getBatchRemoveOp([h]),{redo:s,objects:m}=u;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:s,objects:m,type:p.DrawingApplyType.REMOVE})}}addHook(n){return this._hooks.push(n),{dispose:()=>{const e=this._hooks.findIndex(t=>t===n);this._hooks.splice(e,1)}}}},b.SheetCanvasFloatDomManagerService=fn([ie(0,d.Inject(N.IRenderManagerService)),ie(1,d.IUniverInstanceService),ie(2,d.Inject(d.ICommandService)),ie(3,P.IDrawingManagerService),ie(4,d.Inject(k.CanvasFloatDomService)),ie(5,p.ISheetDrawingService),ie(6,d.Inject(d.LifecycleService))],b.SheetCanvasFloatDomManagerService);var rt=Object.defineProperty,vn=Object.getOwnPropertyDescriptor,_n=(i,r,n)=>r in i?rt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[r]=n,wn=(i,r,n,e)=>{for(var t=e>1?void 0:e?vn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&rt(r,n,t),t},$e=(i,r)=>(n,e)=>r(n,e,i),it=(i,r,n)=>_n(i,typeof r!="symbol"?r+"":r,n);const In="SHEET_IMAGE_UI_PLUGIN";b.UniverSheetsDrawingUIPlugin=class extends d.Plugin{constructor(r=Ye,n,e,t){super(),this._config=r,this._injector=n,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=d.merge({},Ye,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(dt,a)}onStarting(){d.registerDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService],[Re],[he],[ye],[Ie],[we],[fe],[_e],[Se]]),d.touchDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService]])}onReady(){d.touchDependencies(this._injector,[[we]])}onRendered(){this._registerRenderModules(),d.touchDependencies(this._injector,[[Ie],[ye],[Re],[fe],[_e],[Se]])}onSteady(){this._injector.get(he)}_registerRenderModules(){[[le],[Le],[Pe]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(d.UniverInstanceType.UNIVER_SHEET,r))})}},it(b.UniverSheetsDrawingUIPlugin,"type",d.UniverInstanceType.UNIVER_SHEET),it(b.UniverSheetsDrawingUIPlugin,"pluginName",In),b.UniverSheetsDrawingUIPlugin=wn([d.DependentOn(P.UniverDrawingPlugin,te.UniverDocsDrawingPlugin,q.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),$e(1,d.Inject(d.Injector)),$e(2,N.IRenderManagerService),$e(3,d.IConfigService)],b.UniverSheetsDrawingUIPlugin),b.ClearSheetDrawingTransformerOperation=G,b.DeleteDrawingsCommand=Be,b.EditSheetDrawingOperation=Ee,b.GroupSheetDrawingCommand=Ae,b.InsertFloatImageCommand=Me,b.InsertSheetDrawingCommand=ce,b.MoveDrawingsCommand=oe,b.RemoveSheetDrawingCommand=ae,b.SHEETS_IMAGE_MENU_ID=ke,b.SetDrawingArrangeCommand=Ue,b.SetSheetDrawingCommand=de,b.SidebarSheetDrawingOperation=be,b.UngroupSheetDrawingCommand=Ne,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
9
+ */var ze;function lt(){if(ze)return se;ze=1;var i=X,r=Symbol.for("react.element"),n=Symbol.for("react.fragment"),e=Object.prototype.hasOwnProperty,t=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function a(c,l,h){var u,s={},g=null,m=null;h!==void 0&&(g=""+h),l.key!==void 0&&(g=""+l.key),l.ref!==void 0&&(m=l.ref);for(u in l)e.call(l,u)&&!o.hasOwnProperty(u)&&(s[u]=l[u]);if(c&&c.defaultProps)for(u in l=c.defaultProps,l)s[u]===void 0&&(s[u]=l[u]);return{$$typeof:r,type:c,key:g,ref:m,props:s,_owner:t.current}}return se.Fragment=n,se.jsx=a,se.jsxs=a,se}var Ke;function ut(){return Ke||(Ke=1,Oe.exports=lt()),Oe.exports}var H=ut();const ge={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},mt=()=>{const i=d.useDependency(P.IImageIoService),r=d.useDependency(d.LocaleService),[n,e]=X.useState(0);return X.useEffect(()=>{const t=i.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[i]),H.jsx("div",{style:{display:n>0?"block":"none"},className:ge.uploadLoading,children:H.jsxs("div",{className:ge.uploadLoadingBody,children:[H.jsx("div",{className:ge.uploadLoadingBodyAnimation}),H.jsx("div",{className:ge.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${n}`})]})})};var gt=Object.defineProperty,ht=Object.getOwnPropertyDescriptor,pt=(i,r,n,e)=>{for(var t=e>1?void 0:e?ht(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&gt(r,n,t),t},Q=(i,r)=>(n,e)=>r(n,e,i);let he=class extends d.RxDisposable{constructor(r,n,e,t,o,a,c,l){super();Y(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=n,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=c,this._commandService=l,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(j.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(d.UniverInstanceType.UNIVER_SHEET).pipe(j.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(d.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(k.BuiltInUIPart.CONTENT,()=>d.connectInjector(mt,this._injector))}_dispose(r){const n=r.getUnitId();this._renderManagerService.removeRender(n)}_create(r){if(!r)return;const n=r.getUnitId();this._renderManagerService.has(n)&&!this._initImagePopupMenu.has(n)&&(this._popupMenuListener(n),this._initImagePopupMenu.add(n))}_hasCropObject(r){const n=r.getAllObjectsByOrder();for(const e of n)if(e instanceof q.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const n=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!n)return;const e=n.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(d.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(n))return;const a=e.getSelectedObjectMap();if(a.size>1){t==null||t.dispose();return}const c=a.values().next().value;if(!c)return;const l=c.oKey,h=this._drawingManagerService.getDrawingOKey(l);if(!h)return;const{unitId:u,subUnitId:s,drawingId:g,drawingType:m}=h,f=h.data;if(f&&f.disablePopup)return;t==null||t.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,s,g,m);t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:q.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,s,g,m)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.dispose(),this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[d.FOCUSING_COMMON_DRAWINGS]===!1&&(t==null||t.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{t==null||t.dispose()}))}_getImageMenuItems(r,n,e,t){return[{label:"image-popup.edit",index:0,commandId:Ee.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===d.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ae.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:n,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:q.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===d.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:q.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:n,drawingId:e}],disable:t===d.DrawingTypeEnum.DRAWING_DOM}]}};he=pt([Q(0,d.Inject(d.Injector)),Q(1,P.IDrawingManagerService),Q(2,d.Inject(U.SheetCanvasPopManagerService)),Q(3,N.IRenderManagerService),Q(4,d.IUniverInstanceService),Q(5,d.IContextService),Q(6,d.Inject(k.IUIPartsService)),Q(7,d.ICommandService)],he);function V(i,r,n){const{from:e,to:t,flipY:o=!1,flipX:a=!1,angle:c=0,skewX:l=0,skewY:h=0}=i,u=n.getCurrent();if(u==null)return;const s=U.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:t},n);let{left:g,top:m,width:f,height:S}=s;const v=n.getCurrentSkeleton(),C=v.rowHeaderWidth+v.columnTotalWidth,M=v.columnHeaderHeight+v.rowTotalHeight;return g+f>C&&(g=C-f),m+S>M&&(m=M-S),{flipY:o,flipX:a,angle:c,skewX:l,skewY:h,left:g,top:m,width:f,height:S}}function F(i,r){const{left:n=0,top:e=0,width:t=0,height:o=0,flipY:a=!1,flipX:c=!1,angle:l=0,skewX:h=0,skewY:u=0}=i,s=r.getCellWithCoordByOffset(n,e);if(s==null)return;const g={column:s.actualColumn,columnOffset:N.precisionTo(n-s.startX,1),row:s.actualRow,rowOffset:N.precisionTo(e-s.startY,1)},m=r.getCellWithCoordByOffset(n+t,e+o);if(m==null)return;const f={column:m.actualColumn,columnOffset:N.precisionTo(n+t-m.startX,1),row:m.actualRow,rowOffset:N.precisionTo(e+o-m.startY,1)};return{flipY:a,flipX:c,angle:l,skewX:h,skewY:u,from:g,to:f}}var ft=Object.defineProperty,St=Object.getOwnPropertyDescriptor,vt=(i,r,n,e)=>{for(var t=e>1?void 0:e?St(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&ft(r,n,t),t},pe=(i,r)=>(n,e)=>r(n,e,i);let Pe=class extends d.Disposable{constructor(i,r,n,e,t){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=n,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=t,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 n=i[r];for(const e in n.data){const t=n.data[e];t.transform=V(t.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};Pe=vt([pe(1,p.ISheetDrawingService),pe(2,P.IDrawingManagerService),pe(3,d.Inject(U.ISheetSelectionRenderService)),pe(4,d.Inject(U.SheetSkeletonManagerService))],Pe);function _t(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:c}=e,l=N.getGroupState(0,0,t.map(s=>s.transform||{})),h=t.map(s=>{const g=s.transform||{left:0,top:0},{unitId:m,subUnitId:f,drawingId:S}=s;return{unitId:m,subUnitId:f,drawingId:S,transform:{...g,left:g.left-l.left,top:g.top-l.top},groupId:c}}),u={unitId:o,subUnitId:a,drawingId:c,drawingType:d.DrawingTypeEnum.DRAWING_GROUP,transform:l};r.push({parent:u,children:h})}),r}function wt(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:c,transform:l={width:0,height:0}}=e;if(l==null)return;const h=t.map(s=>{const{transform:g}=s,{unitId:m,subUnitId:f,drawingId:S}=s,v=N.transformObjectOutOfGroup(g||{},l,l.width||0,l.height||0);return{unitId:m,subUnitId:f,drawingId:S,transform:v,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:c,drawingType:d.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:h})}),r}const Ae={id:"sheet.command.group-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:m,children:f})=>{o.push(m.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getGroupDrawingOp(r),{unitId:c,subUnitId:l,undo:h,redo:u,objects:s}=a;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:c,subUnitId:l,objects:wt(s),type:p.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!0):!1}},ce={id:"sheet.command.insert-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{var M,y,R;const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService),o=i.get(_.SheetInterceptorService);if(!r)return!1;const a=r.drawings,c=a.map(I=>I.unitId),l=t.getBatchAddOp(a),{unitId:h,subUnitId:u,undo:s,redo:g,objects:m}=l,f=o.onCommandExecute({id:ce.id,params:r}),S={id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:h,subUnitId:u,objects:m,type:p.DrawingApplyType.INSERT}},v={id:p.SetDrawingApplyMutation.id,params:{op:s,unitId:h,subUnitId:u,objects:m,type:p.DrawingApplyType.REMOVE}};return d.sequenceExecute([...(M=f.preRedos)!=null?M:[],S,...f.redos],n)?(e.pushUndoRedo({unitID:h,undoMutations:[...(y=f.preUndos)!=null?y:[],v,...f.undos,{id:G.id,params:c}],redoMutations:[...(R=f.preRedos)!=null?R:[],S,...f.redos,{id:G.id,params:c}]}),!0):!1}},Ue={id:"sheet.command.set-drawing-arrange",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService);if(!r)return!1;const t=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:c,arrangeType:l}=r,h={unitId:o,subUnitId:a,drawingIds:c};let u;if(l===d.ArrangeTypeEnum.forward?u=t.getForwardDrawingsOp(h):l===d.ArrangeTypeEnum.backward?u=t.getBackwardDrawingOp(h):l===d.ArrangeTypeEnum.front?u=t.getFrontDrawingsOp(h):l===d.ArrangeTypeEnum.back&&(u=t.getBackDrawingsOp(h)),u==null)return!1;const{objects:s,redo:g,undo:m}=u;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:g,unitId:o,subUnitId:a,objects:s,type:p.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:a,objects:s,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:s,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}},de={id:"sheet.command.set-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=t.getBatchUpdateOp(o),{unitId:c,subUnitId:l,undo:h,redo:u,objects:s}=a;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:c,subUnitId:l,op:u,objects:s,type:p.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:l,op:h,objects:s,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[c]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:l,op:u,objects:s,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[c]}]}),!0):!1}},Ne={id:"sheet.command.ungroup-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:m,children:f})=>{o.push(m.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getUngroupDrawingOp(r),{unitId:c,subUnitId:l,undo:h,redo:u,objects:s}=a;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:c,subUnitId:l,objects:_t(s),type:p.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};var It=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,yt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Ct(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&It(r,n,t),t},z=(i,r)=>(n,e)=>r(n,e,i);function Mt(i,r,n){const e=n*Math.PI/180,t=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:t,rotatedHeight:o}}function Je(i,r,n,e,t){var M;const{rotatedHeight:o,rotatedWidth:a}=Mt(n,e,t),l=i.get(N.IRenderManagerService).getRenderById(r.unitId);if(!l)return!1;const u=(M=l.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(r.subUnitId))==null?void 0:M.skeleton;if(u==null)return!1;const s=u.getCellByIndex(r.row,r.col),g=s.mergeInfo.endX-s.mergeInfo.startX-2,m=s.mergeInfo.endY-s.mergeInfo.startY-2,f=a/o,v=Math.ceil(Math.min(g,m*f))/a,C=!v||Number.isNaN(v)?.001:v;return{width:n*C,height:e*C}}let le=class extends d.Disposable{constructor(r,n,e,t,o,a,c,l,h,u,s,g,m){super();Y(this,"_workbookSelections");this._context=r,this._skeletonManagerService=n,this._commandService=e,this._selectionRenderService=t,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=c,this._drawingManagerService=l,this._contextService=h,this._messageService=u,this._localeService=s,this._injector=m,this._workbookSelections=g.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(",")}),n=r.length;return n>P.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(P.DRAWING_IMAGE_COUNT_LIMIT))}),!1):n===0?!1:(r.forEach(async e=>await this._insertFloatImage(e)),!0)}async insertCellImage(){const n=(await this._fileOpenerService.openFile({multiple:!1,accept:P.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}))[0];return n?(await this._insertCellImage(n),!0):!1}async _insertFloatImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(M){const y=M.message;y===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:c,source:l,base64Cache:h}=n,{width:u,height:s,image:g}=await P.getImageSize(h||""),{width:m,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(l,c,g);let S=1;if(u>P.DRAWING_IMAGE_WIDTH_LIMIT||s>P.DRAWING_IMAGE_HEIGHT_LIMIT){const M=P.DRAWING_IMAGE_WIDTH_LIMIT/u,y=P.DRAWING_IMAGE_HEIGHT_LIMIT/s;S=Math.max(M,y)}const v=this._getImagePosition(u*S,s*S,m,f);if(v==null)return;const C={unitId:t,subUnitId:o,drawingId:a,drawingType:d.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c,source:l,transform:V(v,this._selectionRenderService,this._skeletonManagerService),sheetTransform:v};this._commandService.executeCommand(ce.id,{unitId:t,drawings:[C]})}async _insertCellImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(v){const C=v.message;C===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const{imageId:e,imageSourceType:t,source:o,base64Cache:a}=n,{width:c,height:l,image:h}=await P.getImageSize(a||"");this._imageIoService.addImageSourceCache(o,t,h);const u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;const s=d.createDocumentModelWithStyle("",{}),g=Je(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},c,l,0);if(!g)return!1;const m={size:{width:g.width,height:g.height},positionH:{relativeFrom:d.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:d.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},f={unitId:s.getUnitId(),subUnitId:s.getUnitId(),drawingId:e,drawingType:d.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t,source:o,transform:xe.docDrawingPositionToTransform(m),docTransform:m,behindDoc:d.BooleanNumber.FALSE,title:"",description:"",layoutType:d.PositionedObjectLayoutType.INLINE,wrapText:d.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=d.BuildTextUtils.drawing.add({documentDataModel:s,drawings:[f],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(s.apply(S),this._commandService.syncExecuteCommand(_.SetRangeValuesCommand.id,{value:{[u.primary.actualRow]:{[u.primary.actualColumn]:{p:s.getSnapshot(),t:1}}}})):!1}_getUnitInfo(){const r=this._context.unit,n=r.getActiveSheet(),e=r.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(r,n,e,t){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const c=U.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(c==null)return;let{startColumn:l,startRow:h,startX:u,startY:s}=c,g=!1;if(u+r>e&&(u=e-r,u<0&&(u=0,r=e),g=!0),s+n>t&&(s=t-n,s<0&&(s=0,n=t),g=!0),g){const v=this._selectionRenderService.getCellWithCoordByOffset(u,s);if(v==null)return;u=v.startX,s=v.startY,l=v.actualColumn,h=v.actualRow}const m={column:l,columnOffset:0,row:h,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(u+r,s+n);if(f==null)return;const S={column:f.actualColumn,columnOffset:u+r-f.startX,row:f.actualRow,rowOffset:s+n-f.startY};return{from:m,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(r=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o}=r;this._commandService.executeCommand(Ue.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(r=>{const n=[];r.length!==0&&(r.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a,drawingType:c,transform:l}=e;if(l==null)return;const h=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:a});if(h==null||h.unitId!==this._context.unitId)return;const u=F({...h.transform,...l},this._selectionRenderService);if(u==null)return;const s={...e,transform:{...h.transform,...l,...V(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};n.push(s)}),n.length>0&&this._commandService.executeCommand(de.id,{unitId:r[0].unitId,drawings:n}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Ae.id,r);const{unitId:n,subUnitId:e,drawingId:t}=r[0].parent;this._commandService.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:e,drawingId:t}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Ne.id,r)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(r=>{r==null||r.length===0?(this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(r))}))}};le=yt([z(1,d.Inject(U.SheetSkeletonManagerService)),z(2,d.ICommandService),z(3,U.ISheetSelectionRenderService),z(4,P.IImageIoService),z(5,k.ILocalFileService),z(6,p.ISheetDrawingService),z(7,P.IDrawingManagerService),z(8,d.IContextService),z(9,k.IMessageService),z(10,d.Inject(d.LocaleService)),z(11,d.Inject(_.SheetsSelectionsService)),z(12,d.Inject(d.Injector))],le);var Dt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,Rt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Tt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Dt(r,n,t),t},re=(i,r)=>(n,e)=>r(n,e,i);function je(i,r,n){var e,t,o,a;if(((t=(e=n==null?void 0:n.p)==null?void 0:e.body)==null?void 0:t.dataStream.length)===3&&((a=(o=n.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const c=n.p.drawings[n.p.drawingsOrder[0]],l=Je(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},c.docTransform.size.width,c.docTransform.size.height,c.docTransform.angle);if(l)return c.transform.width=l.width,c.transform.height=l.height,c.docTransform.size.width=l.width,c.docTransform.size.height=l.height,c.transform.left=0,c.transform.top=0,c.docTransform.positionH.posOffset=0,c.docTransform.positionV.posOffset=0,n.p.documentStyle.pageSize.width=1/0,n.p.documentStyle.pageSize.height=1/0,!0}return!1}let fe=class extends d.Disposable{constructor(i,r,n,e,t,o,a){super(),this._commandService=i,this._sheetInterceptorService=r,this._univerInstanceService=n,this._injector=e,this._drawingManagerService=t,this._docDrawingController=o,this._editorBridgeService=a,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{let r,n=[];if(i.id===_.SetWorksheetRowHeightMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetColWidthMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetRowIsAutoHeightMutation.id){const e=i.params;n=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}),n=e.rowsAutoHeightInfo.map(t=>({startRow:t.row,endRow:t.row,startColumn:0,endColumn:9999}))}else if(i.id===_.AddWorksheetMergeMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.RemoveWorksheetMergeMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}r&&n.length&&n.forEach(e=>{const t=d.Range.transformRange(e,r.worksheet);for(let o=t.startRow;o<=t.endRow;o++)for(let a=t.startColumn;a<=t.endColumn;a++)je(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:o,col:a},r.worksheet.getCellRaw(o,a))})}))}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===xe.ReplaceSnapshotCommand.id&&i.params.unitId===d.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(d.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(d.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(d.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(_.AFTER_CELL_EDIT,{priority:9999,handler:(i,r,n)=>(je(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i),n(i))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.CELL_CONTENT,{effect:d.InterceptorEffectEnum.Style,priority:_.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,n)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0}),n(i)}}))}};fe=Rt([re(0,d.ICommandService),re(1,d.Inject(_.SheetInterceptorService)),re(2,d.IUniverInstanceService),re(3,d.Inject(d.Injector)),re(4,P.IDrawingManagerService),re(5,d.Inject(ne.DocDrawingController)),re(6,d.Inject(U.IEditorBridgeService))],fe);var bt=Object.defineProperty,Et=Object.getOwnPropertyDescriptor,Ot=(i,r,n,e)=>{for(var t=e>1?void 0:e?Et(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&bt(r,n,t),t},Ze=(i,r)=>(n,e)=>r(n,e,i);let Se=class extends d.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,n,e)=>{new d.ObjectMatrix(e).forValue((t,o,a)=>{je(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:t,col:o},a)})}}))}};Se=Ot([Ze(0,d.Inject(U.IAutoFillService)),Ze(1,d.Inject(d.Injector))],Se);var Pt=Object.defineProperty,At=Object.getOwnPropertyDescriptor,Ut=(i,r,n,e)=>{for(var t=e>1?void 0:e?At(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Pt(r,n,t),t},ve=(i,r)=>(n,e)=>r(n,e,i);let _e=class extends d.Disposable{constructor(r,n,e,t){super();Y(this,"_isSetCursor",!1);this._hoverManagerService=r,this._renderManagerService=n,this._selectionsService=e,this._drawingRenderService=t}_initHover(){}_initImageClick(){}};_e=Ut([ve(0,d.Inject(U.HoverManagerService)),ve(1,d.Inject(N.IRenderManagerService)),ve(2,d.Inject(_.SheetsSelectionsService)),ve(3,d.Inject(q.DrawingRenderService))],_e);var Nt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,Wt=(i,r,n,e)=>{for(var t=e>1?void 0:e?jt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Nt(r,n,t),t},We=(i,r)=>(n,e)=>r(n,e,i);let we=class extends d.Disposable{constructor(r,n,e){super();Y(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=n,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,n,e)=>this._collect(r,n,e),onPasteCells:(r,n,e,t)=>{const{copyType:o=U.COPY_TYPE.COPY,pasteType:a}=t,{range:c}=r||{},{range:l,unitId:h,subUnitId:u}=n;return this._generateMutations(l,{copyType:o,pasteType:a,copyRange:c,unitId:h,subUnitId:u})},onPastePlainText:(r,n)=>({undos:[],redos:[]})})}_collect(r,n,e){var g;const t=(g=this._renderManagerService.getRenderById(r))==null?void 0:g.with(U.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:c,startY:l,endY:h}=o,u=this._sheetDrawingService.getDrawingData(r,n),s=[];Object.keys(u).forEach(m=>{const f=u[m],{transform:S}=f;if(f.anchorType!==p.SheetDrawingAnchorType.Both||!S)return;const{left:v=0,top:C=0,width:M=0,height:y=0}=S,{drawingStartX:R,drawingEndX:I,drawingStartY:D,drawingEndY:w}={drawingStartX:v,drawingEndX:v+M,drawingStartY:C,drawingEndY:C+y};a<=R&&I<=c&&l<=D&&w<=h&&s.push(f)}),s.length&&(this._copyInfo={drawings:s,unitId:r,subUnitId:n})}_generateMutations(r,n){var E;if(!this._copyInfo)return{redos:[],undos:[]};if([U.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,U.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,U.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,U.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(n.pasteType))return{redos:[],undos:[]};const{copyRange:e}=n;if(!e)return{redos:[],undos:[]};const{drawings:t,unitId:o,subUnitId:a}=this._copyInfo,{ranges:[c,l],mapFunc:h}=U.virtualizeDiscreteRanges([e,r]),{row:u,col:s}=h(c.startRow,c.startColumn),{row:g,col:m}=h(l.startRow,l.startColumn),f=(E=this._renderManagerService.getRenderById(o))==null?void 0:E.with(U.SheetSkeletonManagerService);if(!f)return{redos:[],undos:[]};const S=f.attachRangeWithCoord({startRow:u,endRow:u,startColumn:s,endColumn:s}),v=f.attachRangeWithCoord({startRow:g,endRow:g,startColumn:m,endColumn:m});if(!S||!v)return{redos:[],undos:[]};const C=[],M=[],y=v.startX-S.startX,R=v.startY-S.startY,I=g-u,D=m-s,w=n.copyType===U.COPY_TYPE.CUT,{_sheetDrawingService:A}=this;return t.forEach(B=>{const{transform:W,sheetTransform:O}=B;if(!W)return;const T={...B,unitId:o,subUnitId:a,drawingId:w?B.drawingId:d.Tools.generateRandomId(),transform:{...W,left:W.left+y,top:W.top+R},sheetTransform:{to:{...O.to,row:O.to.row+I,column:O.to.column+D},from:{...O.from,row:O.from.row+I,column:O.from.column+D}}};if(w){const{undo:L,redo:$,objects:Z}=A.getBatchUpdateOp([T]);C.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:$,objects:Z}}),M.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:L,objects:Z}})}else{const{undo:L,redo:$,objects:Z}=A.getBatchAddOp([T]);C.push({id:p.SetDrawingApplyMutation.id,params:{op:$,unitId:o,subUnitId:a,objects:Z,type:p.DrawingApplyType.INSERT}}),M.push({id:p.SetDrawingApplyMutation.id,params:{op:L,unitId:o,subUnitId:a,objects:Z,type:p.DrawingApplyType.REMOVE}})}}),{redos:C,undos:M}}};we=Wt([We(0,U.ISheetClipboardService),We(1,N.IRenderManagerService),We(2,p.ISheetDrawingService)],we);var Lt=Object.defineProperty,Bt=Object.getOwnPropertyDescriptor,Gt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Bt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Lt(r,n,t),t},ue=(i,r)=>(n,e)=>r(n,e,i);let Ie=class extends d.Disposable{constructor(i,r,n,e,t){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=n,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(j.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingVisible(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const c=r.getUnitId(),l=e.getSheetId(),h=this._drawingManagerService.getDrawingData(c,l),u=Object.values(h),s=this._renderManagerService.getRenderById(c),g=s==null?void 0:s.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>f.oKey.includes(S.drawingId))&&g.removeObject(f)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(j.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingEditable(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const c=r.getUnitId(),l=e.getSheetId(),h=this._drawingManagerService.getDrawingData(c,l),u=Object.values(h),s=this._renderManagerService.getRenderById(c),g=s==null?void 0:s.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>f.oKey.includes(S.drawingId))&&g.detachTransformerFrom(f)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(j.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const c=this._renderManagerService.getRenderById(t),l=c==null?void 0:c.scene;if(l==null)return;const h=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).pipe(j.map(g=>g.every(m=>m.value)));u==null||u.pipe(j.filter(g=>g!==a),j.distinctUntilChanged()).subscribe({next:g=>{a=g,this._drawingManagerService.setDrawingVisible(g);const m=l.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);g?this._drawingManagerService.addNotification(S):(m.forEach(v=>{v.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(C=>v.oKey.includes(C.drawingId))&&l.removeObject(v)}),h.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(t,o).id))==null||s.pipe(j.filter(g=>g.value!==a),j.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const g=this._drawingManagerService.getDrawingData(t,o),m=Object.values(g);this._drawingManagerService.addNotification(m)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(j.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const c=this._renderManagerService.getRenderById(t),l=c==null?void 0:c.scene;if(l==null)return;const h=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).pipe(j.map(g=>g.every(m=>m.value)));u==null||u.pipe(j.filter(g=>g!==a),j.distinctUntilChanged()).subscribe({next:g=>{a=g,this._drawingManagerService.setDrawingEditable(g);const m=l.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);g?(m.forEach(v=>{v.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(C=>v.oKey.includes(C.drawingId))&&l.attachTransformerTo(v)}),this._drawingManagerService.addNotification(S)):(m.forEach(v=>{v.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(C=>v.oKey.includes(C.drawingId))&&l.detachTransformerFrom(v)}),h.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(t,o).id))==null||s.pipe(j.filter(g=>g.value!==a),j.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const g=r.getUnitId(),m=e.getSheetId(),f=this._drawingManagerService.getDrawingData(g,m),S=Object.values(f),v=this._renderManagerService.getRenderById(g),C=v==null?void 0:v.scene;if(C==null)return;this._drawingManagerService.setDrawingEditable(!0),C.getAllObjectsByOrder().forEach(y=>{y.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(R=>y.oKey.includes(R.drawingId))&&C.detachTransformerFrom(y)})}})})}))}};Ie=Gt([ue(0,P.IDrawingManagerService),ue(1,N.IRenderManagerService),ue(2,d.IPermissionService),ue(3,d.IUniverInstanceService),ue(4,d.Inject(d.UserManagerService))],Ie);var kt=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,$t=(i,r,n,e)=>{for(var t=e>1?void 0:e?Ft(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&kt(r,n,t),t},Ce=(i,r)=>(n,e)=>r(n,e,i);let ye=class extends d.Disposable{constructor(i,r,n,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=n,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,n)=>{const{unitId:e,scene:t,subUnitId:o}=r,a=this._drawingManagerService.getDrawingDataForUnit(e),c=a==null?void 0:a[o];return c&&c.order.forEach(l=>{this._drawingRenderService.renderDrawing(c.data[l],t)}),n()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,n)=>{const{unitId:e,subUnitId:t}=r,o=this._renderManagerService.getRenderById(e);if(!o)return n(i);const a=o.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(t);if(!a)return n(i);const c=this._drawingManagerService.getDrawingDataForUnit(e),l=c==null?void 0:c[r.subUnitId];if(!l)return n(i);const{scaleX:h,scaleY:u}=o.scene,s=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},g=l.order.map(m=>l.data[m]).filter(m=>m.drawingType!==d.DrawingTypeEnum.DRAWING_DOM);return g.length?(g.forEach(m=>{if(!m.groupId&&m.transform&&d.Tools.isDefine(m.transform.left)&&d.Tools.isDefine(m.transform.top)&&d.Tools.isDefine(m.transform.width)&&d.Tools.isDefine(m.transform.height)){const f=a.skeleton.getCellIndexByOffset(m.transform.left,m.transform.top,h,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(m.transform.left+m.transform.width,m.transform.top+m.transform.height,h,u,{x:0,y:0});f.column<s.startColumn&&(s.startColumn=f.column),f.row<s.startRow&&(s.startRow=f.row),s.endRow<S.row&&(s.endRow=S.row),s.endColumn<S.column&&(s.endColumn=S.column)}}),n(s)):n(i)}}))}};ye=$t([Ce(0,d.Inject(U.SheetPrintInterceptorService)),Ce(1,d.Inject(q.DrawingRenderService)),Ce(2,P.IDrawingManagerService),Ce(3,N.IRenderManagerService)],ye);var Ht=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,xt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Vt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Ht(r,n,t),t},ee=(i,r)=>(n,e)=>r(n,e,i);const Yt=[_.InsertRowCommand.id,_.InsertColCommand.id,_.RemoveRowCommand.id,_.RemoveColCommand.id,_.DeleteRangeMoveLeftCommand.id,_.DeleteRangeMoveUpCommand.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id,_.DeltaRowHeightCommand.id,_.SetRowHeightCommand.id,_.DeltaColumnWidthCommand.id,_.SetColWidthCommand.id,_.SetRowHiddenCommand.id,_.SetSpecificRowsVisibleCommand.id,_.SetSpecificColsVisibleCommand.id,_.SetColHiddenCommand.id,_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id],Xt=[_.SetRowVisibleMutation.id,_.SetRowHiddenMutation.id,_.SetColVisibleMutation.id,_.SetColHiddenMutation.id,_.SetWorksheetRowHeightMutation.id,_.SetWorksheetColWidthMutation.id];let Le=class extends d.Disposable{constructor(i,r,n,e,t,o,a,c,l){super(),this._context=i,this._renderManagerService=r,this._commandService=n,this._selectionRenderService=e,this._skeletonManagerService=t,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=c,this._univerInstanceService=l,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!Yt.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const 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:n}=i.params;return this._getRangeMoveUndo(n,0)}else if(r===_.DeleteRangeMoveUpCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,1)}else if(r===_.InsertRangeMoveDownCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,2)}else if(r===_.InsertRangeMoveRightCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,3)}else if(r===_.SetRowHiddenCommand.id||r===_.SetSpecificRowsVisibleCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForRowVisible(e,t,o)}else if(r===_.SetSpecificColsVisibleCommand.id||r===_.SetColHiddenCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForColVisible(e,t,o)}else if(r===_.DeltaRowHeightCommand.id||r===_.SetRowHeightCommand.id||r===_.DeltaColumnWidthCommand.id||r===_.SetColWidthCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n,a=r===_.DeltaRowHeightCommand.id||r===_.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const n=_.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const e=n.unitId,t=n.subUnitId,o=[],a=[],c=this._sheetDrawingService.getDrawingData(e,t),l=[],h=[];if(Object.keys(c).forEach(u=>{const s=c[u],{updateDrawings:g,deleteDrawings:m}=this._getUpdateOrDeleteDrawings(i,r,s);l.push(...g),h.push(...m)}),l.length===0&&h.length===0)return{redos:[],undos:[]};if(l.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(l),{undo:s,redo:g,objects:m}=u;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:g,objects:m,type:p.DrawingApplyType.UPDATE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:s,objects:m,type:p.DrawingApplyType.UPDATE}})}if(h.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(h),s=u.undo,g=u.redo,m=u.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:g,objects:m,type:p.DrawingApplyType.REMOVE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:s,objects:m,type:p.DrawingApplyType.INSERT}})}return o.push({id:G.id,params:[e]}),a.push({id:G.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,r,n){const e=[],t=[],{sheetTransform:o,anchorType:a=p.SheetDrawingAnchorType.Position,transform:c,unitId:l,subUnitId:h,drawingId:u}=n,{from:s,to:g}=o,{row:m,column:f}=s,{row:S,column:v}=g;if(o==null||c==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:C,endRow:M,startColumn:y,endColumn:R}=i;let I=null,D=null;if(r===0&&m>=C&&S<=M)if(f>=y&&v<=R)t.push({unitId:l,subUnitId:h,drawingId:u});else{const w=this._shrinkCol(o,c,y,R,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(r===1&&f>=y&&v<=R)if(m>=C&&S<=M)t.push({unitId:l,subUnitId:h,drawingId:u});else{const w=this._shrinkRow(o,c,C,M,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(r===2){const w=this._expandRow(o,c,C,M,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(r===3){const w=this._expandCol(o,c,y,R,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}if(I!=null&&D!=null){const w=V(I,this._selectionRenderService,this._skeletonManagerService);e.push({...n,sheetTransform:I,transform:w})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(i,r,n){const e=F({...i},this._selectionRenderService);e!=null&&r.push({...n,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(u=>{const s=e[u],{sheetTransform:g,transform:m,anchorType:f=p.SheetDrawingAnchorType.Position}=s;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(m,t,s);else{const{from:S,to:v}=g,{row:C,column:M}=S,{row:y,column:R}=v;for(let I=0;I<n.length;I++){const D=n[I],{startRow:w,endRow:A,startColumn:E,endColumn:B}=D;if(R<E)continue;if(f===p.SheetDrawingAnchorType.Position){let T=null,L=null;if(M>=E&&M<=B){const $=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:B,startRow:S.row,endRow:v.row});if($==null)return;L={...m,left:$.startX}}if(L!=null&&(T=F(L,this._selectionRenderService),T!=null&&L!=null)){t.push({...s,sheetTransform:T,transform:L});break}this._remainDrawingSize(m,t,s);continue}if(M>=E&&R<=B)continue;let W=null,O=null;if(M>=E&&M<=B){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:B,startRow:S.row,endRow:v.row});if(T==null)return;O={...m,left:(T==null?void 0:T.startX)||0,width:((m==null?void 0:m.width)||0)-T.endX+T.startX}}else if(R>=E&&R<=B){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:R,startRow:S.row,endRow:v.row});if(T==null)return;O={...m,left:T.startX-((m==null?void 0:m.width)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:B,startRow:S.row,endRow:v.row});if(T==null)return;if(O={...m,width:((m==null?void 0:m.width)||0)-T.endX+T.startX},W=F(O,this._selectionRenderService),W!=null&&O!=null){o.push({...s,sheetTransform:W,transform:O});break}}if(O!=null&&(W=F(O,this._selectionRenderService)),O!=null&&W!=null){t.push({...s,sheetTransform:W,transform:O});break}else this._remainDrawingSize(m,t,s)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:c}=this._createUndoAndRedoMutation(i,r,t),l=[],h=[];if(o.length>0){const{redos:u,undos:s}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),h.push(...s)}return{redos:a,undos:c,preRedos:l,preUndos:h}}_createUndoAndRedoMutation(i,r,n){const e=this._sheetDrawingService.getBatchUpdateOp(n),{undo:t,redo:o,objects:a}=e,c=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],l=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:t,objects:a,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:c,undos:l}}_getDrawingUndoForRowVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(u=>{const s=e[u],{sheetTransform:g,transform:m,anchorType:f=p.SheetDrawingAnchorType.Position}=s;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(m,t,s);else{const{from:S,to:v}=g,{row:C,column:M}=S,{row:y,column:R}=v;for(let I=0;I<n.length;I++){const D=n[I],{startRow:w,endRow:A,startColumn:E,endColumn:B}=D;if(y<w)continue;if(f===p.SheetDrawingAnchorType.Position){let T=null,L=null;if(C>=w&&C<=A){const $=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:C,endRow:A});if($==null)return;L={...m,top:$.startY}}if(L!=null&&(T=F(L,this._selectionRenderService),T!=null&&L!=null)){t.push({...s,sheetTransform:T,transform:L});break}this._remainDrawingSize(m,t,s);continue}if(C>=w&&y<=A)continue;let W=null,O=null;if(C>=w&&C<=A){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:C,endRow:A});if(T==null)return;O={...m,top:(T==null?void 0:T.startY)||0,height:((m==null?void 0:m.height)||0)-T.endY+T.startY}}else if(y>=w&&y<=A){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:w,endRow:y});if(T==null)return;O={...m,top:T.startY-((m==null?void 0:m.height)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:w,endRow:A});if(T==null)return;if(O={...m,height:((m==null?void 0:m.height)||0)-T.endY+T.startY},W=F(O,this._selectionRenderService),W!=null&&O!=null){o.push({...s,sheetTransform:W,transform:O});break}}if(O!=null&&(W=F(O,this._selectionRenderService)),O!=null&&W!=null){t.push({...s,sheetTransform:W,transform:O});break}else this._remainDrawingSize(m,t,s)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:c}=this._createUndoAndRedoMutation(i,r,t),l=[],h=[];if(o.length>0){const{redos:u,undos:s}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),h.push(...s)}return{redos:a,undos:c,preRedos:l,preUndos:h}}_getDrawingUndoForRowAndColSize(i,r,n,e){const t=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(t).forEach(a=>{const c=t[a],{sheetTransform:l,transform:h,anchorType:u=p.SheetDrawingAnchorType.Position}=c;if(u===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,o,c);else{const{from:s,to:g}=l,{row:m,column:f}=s,{row:S,column:v}=g;for(let C=0;C<n.length;C++){const M=n[C],{startRow:y,endRow:R,startColumn:I,endColumn:D}=M;if(S<y||v<I)continue;if(u===p.SheetDrawingAnchorType.Position&&(m<=y&&S>=R||f<=I&&v>=D)){this._remainDrawingSize(h,o,c);continue}const w=V({...l},this._selectionRenderService,this._skeletonManagerService);if(w!=null){o.push({...c,transform:w});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let n,e;if(r==="insert")n=i.unitId,e=i.subUnitId;else{const t=_.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;n=t.unitId,e=t.subUnitId}return{unitId:n,subUnitId:e}}_moveRangeInterceptor(i){var y,R;const{toRange:r,fromRange:n}=i,e=_.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,a=(R=(y=this._renderManagerService.getRenderById(t))==null?void 0:y.with(U.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const c=U.attachRangeWithCoord(a,n);if(!c)return{redos:[],undos:[]};const{startX:l,endX:h,startY:u,endY:s}=c,g=this._sheetDrawingService.getDrawingData(t,o),m=[];Object.keys(g).forEach(I=>{const D=g[I];if(D.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:w}=D;if(!w)return;const{left:A=0,top:E=0,width:B=0,height:W=0}=w,{drawingStartX:O,drawingEndX:T,drawingStartY:L,drawingEndY:$}={drawingStartX:A,drawingEndX:A+B,drawingStartY:E,drawingEndY:E+W};l<=O&&T<=h&&u<=L&&$<=s&&m.push(D)});const f=[],S=[],v=r.startRow-n.startRow,C=r.startColumn-n.startColumn,M=m.map(I=>{const D=I.sheetTransform,w={to:{...D.to,row:D.to.row+v,column:D.to.column+C},from:{...D.from,row:D.from.row+v,column:D.from.column+C}},A=V(w,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:I.drawingId,transform:A,sheetTransform:w}});if(M.length){const I=this._sheetDrawingService.getBatchUpdateOp(M),{undo:D,redo:w,objects:A}=I;f.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:w,objects:A,type:p.DrawingApplyType.UPDATE}}),S.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:D,objects:A,type:p.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startRow,c=o.endRow,l=[],h=[],u=this._sheetDrawingService.getDrawingData(e,t),s=[],g=[];if(Object.keys(u).forEach(m=>{const f=u[m],{sheetTransform:S,transform:v,anchorType:C=p.SheetDrawingAnchorType.Position}=f;if(S==null||v==null)return;let M,y;if(r==="insert"){const I=this._expandRow(S,v,a,c,C);M=I==null?void 0:I.newSheetTransform,y=I==null?void 0:I.newTransform}else{const{from:I,to:D}=S,{row:w}=I,{row:A}=D;if(C===p.SheetDrawingAnchorType.Both&&w>=a&&A<=c)g.push({unitId:e,subUnitId:t,drawingId:m});else{const E=this._shrinkRow(S,v,a,c,C);M=E==null?void 0:E.newSheetTransform,y=E==null?void 0:E.newTransform}}if(!M||!y)return;const R={unitId:e,subUnitId:t,drawingId:m,transform:y,sheetTransform:M};s.push(R)}),s.length===0&&g.length===0)return{redos:[],undos:[]};if(s.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(s),{undo:f,redo:S,objects:v}=m;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.UPDATE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(g),f=m.undo,S=m.redo,v=m.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.REMOVE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),h.push({id:G.id,params:[e]}),{redos:l,undos:h}}_moveColInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startColumn,c=o.endColumn,l=[],h=[],u=this._sheetDrawingService.getDrawingData(e,t),s=[],g=[];if(Object.keys(u).forEach(m=>{const f=u[m],{sheetTransform:S,transform:v,anchorType:C=p.SheetDrawingAnchorType.Position}=f;if(S==null||v==null)return;let M,y;if(r==="insert"){const I=this._expandCol(S,v,a,c,C);M=I==null?void 0:I.newSheetTransform,y=I==null?void 0:I.newTransform}else{const{from:I,to:D}=S,{column:w}=I,{column:A}=D;if(C===p.SheetDrawingAnchorType.Both&&w>=a&&A<=c)g.push({unitId:e,subUnitId:t,drawingId:m});else{const E=this._shrinkCol(S,v,a,c,C);M=E==null?void 0:E.newSheetTransform,y=E==null?void 0:E.newTransform}}if(!M||!y)return;const R={unitId:e,subUnitId:t,drawingId:m,transform:y,sheetTransform:M};s.push(R)}),s.length===0&&g.length===0)return{redos:[],undos:[]};if(s.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(s),{undo:f,redo:S,objects:v}=m;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.UPDATE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(g),f=m.undo,S=m.redo,v=m.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.REMOVE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),h.push({id:G.id,params:[e]}),{redos:l,undos:h}}_expandCol(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{column:l}=a,{column:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>=n){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:e,startRow:a.row,endRow:c.row});if(g==null)return;s={...r,left:(r.left||0)+g.endX-g.startX},u=F(s,this._selectionRenderService)}else if(h>=e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,column:h+o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_shrinkCol(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{column:l}=a,{column:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>e)u={from:{...a,column:l-o},to:{...c,column:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=n&&h<=e)return null;if(l<n&&h>e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,column:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};else if(l>=n&&l<=e){if(l===n)s={...r,left:(r.left||0)-i.from.columnOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:l-1,startRow:a.row,endRow:c.row});if(g==null)return;s={...r,left:(r.left||0)-g.endX+g.startX-i.from.columnOffset}}u=F(s,this._selectionRenderService)}else if(h>=n&&h<=e&&t===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:n-1,endColumn:n-1,startRow:a.row,endRow:c.row});if(g==null)return;u={from:{...a},to:{...c,column:n-1,columnOffset:g.endX-g.startX}},s=V(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_expandRow(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{row:l}=a,{row:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>=n){const g=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:e,startColumn:a.column,endColumn:c.column});if(g==null)return;s={...r,top:(r.top||0)+g.endY-g.startY},u=F(s,this._selectionRenderService)}else if(h>=e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,row:h+o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_shrinkRow(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{row:l}=a,{row:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>e)u={from:{...a,row:l-o},to:{...c,row:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=n&&h<=e)return null;if(l<n&&h>e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,row:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};else if(l>=n&&l<=e){if(l===n)s={...r,top:(r.top||0)-i.from.rowOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:l-1,startColumn:a.column,endColumn:c.column});if(g==null)return;s={...r,top:(r.top||0)-g.endY+g.startY-i.from.rowOffset}}u=F(s,this._selectionRenderService)}else if(h>=n&&h<=e&&t===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:n-1,endRow:n-1});if(g==null)return;u={from:{...a},to:{...c,row:n-1,rowOffset:g.endY-g.startY}},s=V(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===_.SetWorksheetActiveOperation.id&&setTimeout(()=>{const r=i.params,{unitId:n,subUnitId:e}=r,t=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(t).forEach(c=>{const l=t[c];l!=null&&Object.keys(l).forEach(h=>{const u=l[h].data;u!=null&&Object.keys(u).forEach(s=>{if(c===n&&h===e){const g=u[s];g.transform=V(g.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(u[s])}else a.push(u[s])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Xt.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:n,subUnitId:e,ranges:t}=r;this._refreshDrawingTransform(n,e,t)})}))}_refreshDrawingTransform(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:c,transform:l,anchorType:h=p.SheetDrawingAnchorType.Position}=a;if(h===p.SheetDrawingAnchorType.None)return!0;const{from:u,to:s}=c,{row:g,column:m}=u,{row:f,column:S}=s;for(let v=0;v<n.length;v++){const C=n[v],{startRow:M,endRow:y,startColumn:R,endColumn:I}=C;if(d.Rectangle.intersects({startRow:M,endRow:y,startColumn:R,endColumn:I},{startRow:g,endRow:f,startColumn:m,endColumn:S})||g>y||m>I){const D=h===p.SheetDrawingAnchorType.Position,w=V(c,this._selectionRenderService,this._skeletonManagerService);t.push({...a,transform:{...w,width:D?l==null?void 0:l.width:w==null?void 0:w.width,height:D?l==null?void 0:l.height:w==null?void 0:w.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(G.id,[i]))}};Le=xt([ee(1,N.IRenderManagerService),ee(2,d.ICommandService),ee(3,U.ISheetSelectionRenderService),ee(4,d.Inject(U.SheetSkeletonManagerService)),ee(5,d.Inject(_.SheetInterceptorService)),ee(6,p.ISheetDrawingService),ee(7,P.IDrawingManagerService),ee(8,d.IUniverInstanceService)],Le);var K=function(){return K=Object.assign||function(i){for(var r,n=1,e=arguments.length;n<e;n++){r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(i[t]=r[t])}return i},K.apply(this,arguments)},zt=function(i,r){var n={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(n[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(i);t<e.length;t++)r.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(i,e[t])&&(n[e[t]]=i[e[t]]);return n},qe=X.forwardRef(function(i,r){var n=i.icon,e=i.id,t=i.className,o=i.extend,a=zt(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),l=X.useRef("_".concat(Zt()));return Qe(n,"".concat(e),{defIds:n.defIds,idSuffix:l.current},K({ref:r,className:c},a),o)});function Qe(i,r,n,e,t){return X.createElement(i.tag,K(K({key:r},Kt(i,n,t)),e),(Jt(i,n).children||[]).map(function(o,a){return Qe(o,"".concat(r,"-").concat(i.tag,"-").concat(a),n,void 0,t)}))}function Kt(i,r,n){var e=K({},i.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var t=r.defIds;return!t||t.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],c=o[1];typeof c=="string"&&(e[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Jt(i,r){var n,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?K(K({},i),{children:i.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?K(K({},t),{attrs:K(K({},t.attrs),{id:t.attrs.id+r.idSuffix})}):t})}):i}function Zt(){return Math.random().toString(36).substring(2,8)}qe.displayName="UniverIcon";var qt={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"}}]},et=X.forwardRef(function(i,r){return X.createElement(qe,Object.assign({},i,{id:"add-image-single",ref:r,icon:qt}))});et.displayName="AddImageSingle";const Be={id:"sheet.command.delete-drawing",type:d.CommandType.COMMAND,handler:i=>{const r=i.get(d.ICommandService),e=i.get(p.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(a=>{const{unitId:c,subUnitId:l,drawingId:h,drawingType:u}=a;return{unitId:c,subUnitId:l,drawingId:h,drawingType:u}});return r.executeCommand(ae.id,{unitId:t,drawings:o})}},Me={id:"sheet.command.insert-float-image",type:d.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(N.IRenderManagerService).getCurrentTypeOfRenderer(d.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(le).insertFloatImage())!=null?e:!1}},Ge={id:"sheet.command.insert-cell-image",type:d.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(N.IRenderManagerService).getCurrentTypeOfRenderer(d.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(le).insertCellImage())!=null?e:!1}},oe={id:"sheet.command.move-drawing",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(p.ISheetDrawingService),t=i.get(U.ISheetSelectionRenderService),{direction:o}=r,a=e.getFocusDrawings();if(a.length===0)return!1;const c=a[0].unitId,l=a.map(u=>{const{transform:s}=u;if(s==null)return null;const g={...s},{left:m=0,top:f=0}=s;return o===d.Direction.UP?g.top=f-1:o===d.Direction.DOWN?g.top=f+1:o===d.Direction.LEFT?g.left=m-1:o===d.Direction.RIGHT&&(g.left=m+1),{...u,transform:g,sheetTransform:F(g,t)}}).filter(u=>u!=null);return n.syncExecuteCommand(de.id,{unitId:c,drawings:l})?(n.syncExecuteCommand(G.id,[c]),!0):!1}},tt="addition-and-subtraction-single",ke="sheet.menu.image";function Qt(i){return{id:ke,type:k.MenuItemType.SUBITEMS,icon:tt,tooltip:"sheetImage.title",hidden$:k.getMenuHiddenObservable(i,d.UniverInstanceType.UNIVER_SHEET),disabled$:U.getCurrentRangeDisable$(i,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function en(i){return{id:Me.id,title:"sheetImage.upload.float",type:k.MenuItemType.BUTTON,hidden$:k.getMenuHiddenObservable(i,d.UniverInstanceType.UNIVER_SHEET)}}function tn(i){return{id:Ge.id,title:"sheetImage.upload.cell",type:k.MenuItemType.BUTTON}}const te={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelSubtitle:"univer-image-common-panel-subtitle",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"};function nt(i){var r,n,e="";if(typeof i=="string"||typeof i=="number")e+=i;else if(typeof i=="object")if(Array.isArray(i)){var t=i.length;for(r=0;r<t;r++)i[r]&&(n=nt(i[r]))&&(e&&(e+=" "),e+=n)}else for(n in i)i[n]&&(e&&(e+=" "),e+=n);return e}function De(){for(var i,r,n=0,e="",t=arguments.length;n<t;n++)(i=arguments[n])&&(r=nt(i))&&(e&&(e+=" "),e+=r);return e}const nn=i=>{var y;const r=d.useDependency(d.ICommandService),n=d.useDependency(d.LocaleService),e=d.useDependency(P.IDrawingManagerService),t=d.useDependency(N.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:c}=a,l=t.getRenderById(c),h=l==null?void 0:l.scene;if(h==null)return;const u=h.getTransformerByCreate(),[s,g]=X.useState(!0),m=(y=a.anchorType)!=null?y:p.SheetDrawingAnchorType.Position,[f,S]=X.useState(m);function v(R,I){const D=[];return R.forEach(w=>{const{oKey:A}=w,E=I.getDrawingOKey(A);if(E==null)return D.push(null),!0;const{unitId:B,subUnitId:W,drawingId:O,drawingType:T,anchorType:L,sheetTransform:$}=E;D.push({unitId:B,subUnitId:W,drawingId:O,anchorType:L,sheetTransform:$,drawingType:T})}),D}X.useEffect(()=>{const R=u.clearControl$.subscribe(D=>{D===!0&&g(!1)}),I=u.changeStart$.subscribe(D=>{var E;const{objects:w}=D,A=v(w,e);if(A.length===0)g(!1);else if(A.length>=1){g(!0);const B=((E=A[0])==null?void 0:E.anchorType)||p.SheetDrawingAnchorType.Position;S(B)}});return()=>{I.unsubscribe(),R.unsubscribe()}},[]);function C(R){S(R);const I=e.getFocusDrawings();if(I.length===0)return;const D=I.map(w=>({unitId:w.unitId,subUnitId:w.subUnitId,drawingId:w.drawingId,anchorType:R}));r.executeCommand(de.id,{unitId:I[0].unitId,drawings:D})}const M=R=>R?"block":"none";return H.jsxs("div",{className:De(te.imageCommonPanelGrid,te.imageCommonPanelBorder),style:{display:M(s)},children:[H.jsx("div",{className:te.imageCommonPanelRow,children:H.jsx("div",{className:De(te.imageCommonPanelColumn,te.imageCommonPanelTitle),children:H.jsx("div",{children:n.t("drawing-anchor.title")})})}),H.jsx("div",{className:De(te.imageCommonPanelRow),children:H.jsx("div",{className:De(te.imageCommonPanelColumn),children:H.jsxs(J.RadioGroup,{value:f,onChange:C,direction:"vertical",children:[H.jsx(J.Radio,{value:p.SheetDrawingAnchorType.Both,children:n.t("drawing-anchor.both")}),H.jsx(J.Radio,{value:p.SheetDrawingAnchorType.Position,children:n.t("drawing-anchor.position")}),H.jsx(J.Radio,{value:p.SheetDrawingAnchorType.None,children:n.t("drawing-anchor.none")})]})})})]})},rn=()=>{const i=d.useDependency(P.IDrawingManagerService),r=i.getFocusDrawings(),[n,e]=X.useState(r);return X.useEffect(()=>{const t=i.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(n!=null&&n.length)&&H.jsxs("div",{className:te.imageCommonPanel,children:[H.jsx(q.DrawingCommonPanel,{drawings:n}),H.jsx(nn,{drawings:n})]})},on={[k.RibbonStartGroup.FORMULAS_INSERT]:{[ke]:{order:3,menuItemFactory:Qt,[Me.id]:{order:0,menuItemFactory:en},[Ge.id]:{order:1,menuItemFactory:tn}}}};function me(i){return!i.getContextValue(d.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(d.EDITOR_ACTIVATED)&&!i.getContextValue(d.FOCUSING_PANEL_EDITOR)&&i.getContextValue(d.FOCUSING_COMMON_DRAWINGS)}const an={id:oe.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_DOWN,priority:100,preconditions:me,staticParameters:{direction:d.Direction.DOWN}},sn={id:oe.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_UP,priority:100,preconditions:me,staticParameters:{direction:d.Direction.UP}},cn={id:oe.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_LEFT,priority:100,preconditions:me,staticParameters:{direction:d.Direction.LEFT}},dn={id:oe.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_RIGHT,priority:100,preconditions:me,staticParameters:{direction:d.Direction.RIGHT}},ln={id:Be.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:me,binding:k.KeyCode.DELETE,mac:k.KeyCode.BACKSPACE};var un=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,gn=(i,r,n,e)=>{for(var t=e>1?void 0:e?mn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&un(r,n,t),t},Te=(i,r)=>(n,e)=>r(n,e,i);let Re=class extends d.Disposable{constructor(i,r,n,e){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=n,this._shortcutService=e,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(tt,et)),this.disposeWithMe(i.register(Xe,rn))}_initMenus(){this._menuManagerService.mergeMenu(on)}_initCommands(){[Me,Ge,ce,ae,de,be,G,Ee,Ae,Ne,oe,Be,Ue].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[an,sn,cn,dn,ln].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Re=gn([Te(0,d.Inject(k.ComponentManager)),Te(1,k.IMenuManagerService),Te(2,d.ICommandService),Te(3,k.IShortcutService)],Re);var hn=Object.defineProperty,pn=Object.getOwnPropertyDescriptor,fn=(i,r,n,e)=>{for(var t=e>1?void 0:e?pn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&hn(r,n,t),t},ie=(i,r)=>(n,e)=>r(n,e,i);function Sn(i,r,n,e){const{scaleX:t,scaleY:o}=r.getAncestorScale(),a=r.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN),c={left:!0,top:!0};if(!a)return{...i,absolute:c};const{left:l,right:h,top:u,bottom:s}=i,g=e.getFreeze(),{startColumn:m,startRow:f,xSplit:S,ySplit:v}=g,C=n.getNoMergeCellPositionByIndexWithNoHeader(f-v,m-S),M=n.getNoMergeCellPositionByIndexWithNoHeader(f,m),{rowHeaderWidth:y,columnHeaderHeight:R}=n,I=M.startX-C.startX,D=M.startY-C.startY,{top:w,left:A,viewportScrollX:E,viewportScrollY:B}=a;let W,O;l<A?(c.left=!0,W=(I+y+(l-A))*t,O=Math.max(Math.min((I+y+(h-A))*t,(I+y)*t),(h-E)*t)):(c.left=!1,W=Math.max((l-E)*t,(I+y)*t),O=Math.max((h-E)*t,(I+y)*t));let T,L;return u<w?(c.top=!0,T=(D+R+(u-w))*o,L=Math.max(Math.min((D+R+(h-w))*o,(D+R)*o),(s-B)*o)):(c.top=!1,T=Math.max((u-B)*o,(D+R)*o),L=Math.max((s-B)*o,(D+R)*o)),{left:W,right:O,top:T,bottom:L,absolute:c}}const Fe=(i,r,n,e)=>{const{scene:t}=r,{left:o,top:a,width:c,height:l,angle:h}=i,u={left:o,right:o+c,top:a,bottom:a+l},s=Sn(u,t,n,e),{scaleX:g,scaleY:m}=t.getAncestorScale();return{startX:s.left,endX:s.right,startY:s.top,endY:s.bottom,rotate:h,width:c*g,height:l*m,absolute:s.absolute}};b.SheetCanvasFloatDomManagerService=class extends d.Disposable{constructor(n,e,t,o,a,c,l){super();Y(this,"_domLayerMap",new Map);Y(this,"_domLayerInfoMap",new Map);Y(this,"_transformChange$",new j.Subject);Y(this,"transformChange$",this._transformChange$.asObservable());Y(this,"_add$",new j.Subject);Y(this,"add$",this._add$.asObservable());Y(this,"_remove$",new j.Subject);Y(this,"remove$",this._remove$.asObservable());Y(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=c,this._lifecycleService=l,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(j.filter(n=>n===d.LifecycleStages.Rendered),j.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(n,e){let t=this._domLayerMap.get(n);t||(t=new Map,this._domLayerMap.set(n,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(n){return this._domLayerInfoMap.get(n)}_getSceneAndTransformerByDrawingSearch(n){if(n==null)return;const e=this._renderManagerService.getRenderById(n),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:t,transformer:o,renderObject:e,canvas:a}}_getFloatDomProps(n){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(n)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(n=>{n.forEach(e=>{var at,st,ct;const{unitId:t,subUnitId:o,drawingId:a}=e,c=_.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),l=this._drawingManagerService.getDrawingByParam(e),h=this._univerInstanceService.getUnit(t,d.UniverInstanceType.UNIVER_SHEET);if(!h)return;const u=h.getActiveSheet().getSheetId();if(!l||!c)return;const s=(at=this._renderManagerService.getRenderById(t))==null?void 0:at.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!s)return;const{transform:g,drawingType:m,data:f}=l;if(m!==d.DrawingTypeEnum.DRAWING_DOM&&m!==d.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(t);if(S==null)return;const{scene:v,canvas:C}=S;if(g==null)return!0;if(u!==o)return;const{left:M,top:y,width:R,height:I,angle:D,flipX:w,flipY:A,skewX:E,skewY:B}=g,W=P.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),O=v.getObject(W);if(O!=null){O.transformByState({left:M,top:y,width:R,height:I,angle:D,flipX:w,flipY:A,skewX:E,skewY:B});return}const T={left:M,top:y,width:R,height:I,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},L=m===d.DrawingTypeEnum.DRAWING_CHART;if(L){const x=f?f.backgroundColor:"white";T.fill=x,T.rotateEnabled=!1,f&&f.border&&(T.stroke=f.border),T.paintFirst="stroke",T.strokeWidth=1,T.borderEnabled=!1,T.radius=8}const $=new N.Rect(W,T);L&&$.setObjectType(N.ObjectType.CHART),v.addObject($,N.DRAWING_OBJECT_LAYER_INDEX),l.allowTransform!==!1&&v.attachTransformerTo($);const Z=this._ensureMap(t,o),He=new d.DisposableCollection,Cn=Fe($,S.renderObject,s.skeleton,c.worksheet),Ve=new j.BehaviorSubject(Cn),yn={dispose:He,rect:$,position$:Ve,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:Ve,id:a,componentKey:l.componentKey,onPointerDown:x=>{C.dispatchEvent(new PointerEvent(x.type,x))},onPointerMove:x=>{C.dispatchEvent(new PointerEvent(x.type,x))},onPointerUp:x=>{C.dispatchEvent(new PointerEvent(x.type,x))},onWheel:x=>{C.dispatchEvent(new WheelEvent(x.type,x))},props:(ct=(st=Z.get(a))==null?void 0:st.props)!=null?ct:this._getFloatDomProps(a),data:f,unitId:t});const ot=$.onTransformChange$.subscribeEvent(()=>{const x=Fe($,S.renderObject,s.skeleton,c.worksheet);Ve.next(x)});He.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),ot&&He.add(ot),this._domLayerInfoMap.set(a,yn),Z.set(a,{...Z.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a}=e,c=P.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),l=this._getSceneAndTransformerByDrawingSearch(t);if(l==null)return;const{transformer:h,scene:u}=l,s=u.getObject(c);s!=null&&s.oKey&&h.clearControlByIds([s==null?void 0:s.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,t),c=Array.from(a.keys()),l=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),h=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(t);!o||!l||!h||c.forEach(s=>{const g=this._domLayerInfoMap.get(s);if(g){const m=Fe(g.rect,o.renderObject,h.skeleton,l.worksheet);g.position$.next(m)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(j.filter(e=>!!e),j.switchMap(e=>e.activeSheet$),j.filter(e=>!!e),j.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),j.filter(e=>!!e),j.switchMap(e=>d.fromEventSubject(e.render.scene.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(j.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{n(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===U.SetZoomRatioOperation.id){const a=e.params,{unitId:c}=a;Array.from((o=(t=this._domLayerMap.get(c))==null?void 0:t.keys())!=null?o:[]).forEach(h=>{n(c,h)})}else if(e.id===_.SetFrozenMutation.id){const{unitId:a,subUnitId:c}=e.params;n(a,c)}}))}_getPosition(n,e){var m;const{startX:t,endX:o,startY:a,endY:c}=n,l=(m=this._renderManagerService.getRenderById(e))==null?void 0:m.with(U.ISheetSelectionRenderService);if(l==null)return;const h=l.getCellWithCoordByOffset(t,a);if(h==null)return;const u={column:h.actualColumn,columnOffset:t-h.startX,row:h.actualRow,rowOffset:a-h.startY},s=l.getCellWithCoordByOffset(o,c);if(s==null)return;const g={column:s.actualColumn,columnOffset:o-s.startX,row:s.actualRow,rowOffset:c-s.startY};return{from:u,to:g}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==d.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==d.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(n,e,t,o){const a=this._domLayerInfoMap.get(t),c=this._getSceneAndTransformerByDrawingSearch(n);if(a&&c){const{scene:l}=c,h=P.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),u=l.getObject(h);u&&u instanceof N.Rect&&u.setProps(o)}}addFloatDomToPosition(n,e){const t=_.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=t,{initPosition:c,componentKey:l,data:h,allowTransform:u=!0}=n,s=e!=null?e:d.generateRandomId(),g=this._getPosition(c,o);if(g==null)return;this._ensureMap(o,a).set(s,n);const f={unitId:o,subUnitId:a,drawingId:s,drawingType:n.type||d.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:g,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},data:h,allowTransform:u};return this._commandService.executeCommand(ce.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:a,id:s}),{id:s,dispose:()=>{this._removeDom(s,!0)}}}_removeDom(n,e=!1){const t=this._domLayerInfoMap.get(n);if(!t)return;const{unitId:o,subUnitId:a}=t;this._domLayerInfoMap.delete(n),t.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(t.rect),e){this._ensureMap(o,a).delete(n);const h=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:n});if(!h)return;const u=this._sheetDrawingService.getBatchRemoveOp([h]),{redo:s,objects:g}=u;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:s,objects:g,type:p.DrawingApplyType.REMOVE})}}addHook(n){return this._hooks.push(n),{dispose:()=>{const e=this._hooks.findIndex(t=>t===n);this._hooks.splice(e,1)}}}},b.SheetCanvasFloatDomManagerService=fn([ie(0,d.Inject(N.IRenderManagerService)),ie(1,d.IUniverInstanceService),ie(2,d.Inject(d.ICommandService)),ie(3,P.IDrawingManagerService),ie(4,d.Inject(k.CanvasFloatDomService)),ie(5,p.ISheetDrawingService),ie(6,d.Inject(d.LifecycleService))],b.SheetCanvasFloatDomManagerService);var rt=Object.defineProperty,vn=Object.getOwnPropertyDescriptor,_n=(i,r,n)=>r in i?rt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[r]=n,wn=(i,r,n,e)=>{for(var t=e>1?void 0:e?vn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&rt(r,n,t),t},$e=(i,r)=>(n,e)=>r(n,e,i),it=(i,r,n)=>_n(i,typeof r!="symbol"?r+"":r,n);const In="SHEET_IMAGE_UI_PLUGIN";b.UniverSheetsDrawingUIPlugin=class extends d.Plugin{constructor(r=Ye,n,e,t){super(),this._config=r,this._injector=n,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=d.merge({},Ye,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(dt,a)}onStarting(){d.registerDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService],[Re],[he],[ye],[Ie],[we],[fe],[_e],[Se]]),d.touchDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService]])}onReady(){d.touchDependencies(this._injector,[[we]])}onRendered(){this._registerRenderModules(),d.touchDependencies(this._injector,[[Ie],[ye],[Re],[fe],[_e],[Se]])}onSteady(){this._injector.get(he)}_registerRenderModules(){[[le],[Le],[Pe]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(d.UniverInstanceType.UNIVER_SHEET,r))})}},it(b.UniverSheetsDrawingUIPlugin,"type",d.UniverInstanceType.UNIVER_SHEET),it(b.UniverSheetsDrawingUIPlugin,"pluginName",In),b.UniverSheetsDrawingUIPlugin=wn([d.DependentOn(P.UniverDrawingPlugin,ne.UniverDocsDrawingPlugin,q.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),$e(1,d.Inject(d.Injector)),$e(2,N.IRenderManagerService),$e(3,d.IConfigService)],b.UniverSheetsDrawingUIPlugin),b.ClearSheetDrawingTransformerOperation=G,b.DeleteDrawingsCommand=Be,b.EditSheetDrawingOperation=Ee,b.GroupSheetDrawingCommand=Ae,b.InsertFloatImageCommand=Me,b.InsertSheetDrawingCommand=ce,b.MoveDrawingsCommand=oe,b.RemoveSheetDrawingCommand=ae,b.SHEETS_IMAGE_MENU_ID=ke,b.SetDrawingArrangeCommand=Ue,b.SetSheetDrawingCommand=de,b.SidebarSheetDrawingOperation=be,b.UngroupSheetDrawingCommand=Ne,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-drawing-ui",
3
- "version": "0.5.3-experimental.20250106-e3b7a39",
3
+ "version": "0.5.3-experimental.20250107-3e6579c",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -57,19 +57,19 @@
57
57
  "rxjs": ">=7.0.0"
58
58
  },
59
59
  "dependencies": {
60
- "@univerjs/icons": "^0.2.10",
60
+ "@univerjs/icons": "^0.2.11",
61
61
  "clsx": "^2.1.1",
62
- "@univerjs/core": "0.5.3-experimental.20250106-e3b7a39",
63
- "@univerjs/design": "0.5.3-experimental.20250106-e3b7a39",
64
- "@univerjs/docs-ui": "0.5.3-experimental.20250106-e3b7a39",
65
- "@univerjs/docs-drawing": "0.5.3-experimental.20250106-e3b7a39",
66
- "@univerjs/drawing": "0.5.3-experimental.20250106-e3b7a39",
67
- "@univerjs/engine-render": "0.5.3-experimental.20250106-e3b7a39",
68
- "@univerjs/drawing-ui": "0.5.3-experimental.20250106-e3b7a39",
69
- "@univerjs/sheets": "0.5.3-experimental.20250106-e3b7a39",
70
- "@univerjs/ui": "0.5.3-experimental.20250106-e3b7a39",
71
- "@univerjs/sheets-drawing": "0.5.3-experimental.20250106-e3b7a39",
72
- "@univerjs/sheets-ui": "0.5.3-experimental.20250106-e3b7a39"
62
+ "@univerjs/core": "0.5.3-experimental.20250107-3e6579c",
63
+ "@univerjs/design": "0.5.3-experimental.20250107-3e6579c",
64
+ "@univerjs/docs-drawing": "0.5.3-experimental.20250107-3e6579c",
65
+ "@univerjs/drawing": "0.5.3-experimental.20250107-3e6579c",
66
+ "@univerjs/drawing-ui": "0.5.3-experimental.20250107-3e6579c",
67
+ "@univerjs/docs-ui": "0.5.3-experimental.20250107-3e6579c",
68
+ "@univerjs/sheets": "0.5.3-experimental.20250107-3e6579c",
69
+ "@univerjs/engine-render": "0.5.3-experimental.20250107-3e6579c",
70
+ "@univerjs/sheets-drawing": "0.5.3-experimental.20250107-3e6579c",
71
+ "@univerjs/ui": "0.5.3-experimental.20250107-3e6579c",
72
+ "@univerjs/sheets-ui": "0.5.3-experimental.20250107-3e6579c"
73
73
  },
74
74
  "devDependencies": {
75
75
  "less": "^4.2.1",