@univerjs/sheets-drawing-ui 0.6.0-nightly.202502061605 → 0.6.0-nightly.202502081605

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