@univerjs/sheets-drawing-ui 0.6.0-nightly.202502071606 → 0.6.0-nightly.202502091605

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
  }
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
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,W,w,E,G,k,_,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 Vt="sheets-drawing-ui.config",Rt={},F={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(r,i)=>{const n=r.get(W.IRenderManagerService);return i.forEach(e=>{var t,o;(o=(t=n.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},Ie={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(_.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 d=o.getBatchRemoveOp(a),{unitId:m,subUnitId:u,undo:c,redo:h,objects:g}=d,f=t.onCommandExecute({id:Ie.id,params:i}),S={id:w.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:h,objects:g,type:w.DrawingApplyType.REMOVE}},p={id:w.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:c,objects:g,type:w.DrawingApplyType.INSERT}};return l.sequenceExecute([...(I=f.preRedos)!=null?I:[],S,...f.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(M=f.preUndos)!=null?M:[],p,...f.undos,{id:F.id,params:s}],redoMutations:[...(b=f.preRedos)!=null?b:[],S,...f.redos,{id:F.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 n=r.get(G.ISidebarService),e=r.get(l.LocaleService),t=r.get(l.IUniverInstanceService),o=r.get(l.ICommandService);if(!_.getSheetCommandTarget(t))return!1;switch(i.value){case"open":n.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Et},onClose:()=>{o.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:n.close();break}return!0}},mt={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(U.SetDrawingSelectedOperation.id,[i]),n.executeCommand(ht.id,{value:"open"}),!0)}},Ge={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},xt=()=>{const r=l.useDependency(U.IImageIoService),i=l.useDependency(l.LocaleService),[n,e]=te.useState(0);return te.useEffect(()=>{const t=r.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[r]),x.jsx("div",{style:{display:n>0?"block":"none"},className:Ge.uploadLoading,children:x.jsxs("div",{className:Ge.uploadLoadingBody,children:[x.jsx("div",{className:Ge.uploadLoadingBodyAnimation}),x.jsx("div",{className:Ge.uploadLoadingBodyText,children:`${i.t("uploadLoading.loading")}: ${n}`})]})})};var Kt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,qt=(r,i,n,e)=>{for(var t=e>1?void 0:e?zt(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},pe=(r,i)=>(n,e)=>i(n,e,r);let Fe=class extends l.RxDisposable{constructor(i,n,e,t,o,a,s,d){super();Q(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=d,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(k.takeUntil(this.dispose$)).subscribe(i=>this._create(i)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(k.takeUntil(this.dispose$)).subscribe(i=>this._dispose(i)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(i=>this._create(i)),this._uiPartsService.registerComponent(G.BuiltInUIPart.CONTENT,()=>l.connectInjector(xt,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 me.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 d=s.oKey,m=this._drawingManagerService.getDrawingOKey(d);if(!m)return;const{unitId:u,subUnitId:c,drawingId:h,drawingType:g}=m,f=m.data;if(f&&f.disablePopup)return;t==null||t.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,c,h,g);t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:me.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,c,h,g)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.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&&(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:mt.id,commandParams:{unitId:i,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Ie.id,commandParams:{unitId:i,drawings:[{unitId:i,subUnitId:n,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:me.OpenImageCropOperation.id,commandParams:{unitId:i,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:me.ImageResetSizeOperation.id,commandParams:[{unitId:i,subUnitId:n,drawingId:e}],disable:t===l.DrawingTypeEnum.DRAWING_DOM}]}};Fe=qt([pe(0,l.Inject(l.Injector)),pe(1,U.IDrawingManagerService),pe(2,l.Inject(E.SheetCanvasPopManagerService)),pe(3,W.IRenderManagerService),pe(4,l.IUniverInstanceService),pe(5,l.IContextService),pe(6,l.Inject(G.IUIPartsService)),pe(7,l.ICommandService)],Fe);function K(r,i,n){const{from:e,to:t,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:d=0,skewY:m=0}=r,u=n.getCurrent();if(u==null)return;const c=E.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:t},n);let{left:h,top:g,width:f,height:S}=c;const p=n.getCurrentSkeleton(),v=p.rowHeaderWidth+p.columnTotalWidth,I=p.columnHeaderHeight+p.rowTotalHeight;return h+f>v&&(h=v-f),g+S>I&&(g=I-S),{flipY:o,flipX:a,angle:s,skewX:d,skewY:m,left:h,top:g,width:f,height:S}}function H(r,i){const{left:n=0,top:e=0,width:t=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:d=0,skewX:m=0,skewY:u=0}=r,c=i.getCellWithCoordByOffset(n,e);if(c==null)return;const h={column:c.actualColumn,columnOffset:W.precisionTo(n-c.startX,1),row:c.actualRow,rowOffset:W.precisionTo(e-c.startY,1)},g=i.getCellWithCoordByOffset(n+t,e+o);if(g==null)return;const f={column:g.actualColumn,columnOffset:W.precisionTo(n+t-g.startX,1),row:g.actualRow,rowOffset:W.precisionTo(e+o-g.startY,1)};return{flipY:a,flipX:s,angle:d,skewX:m,skewY:u,from:h,to:f}}var Zt=Object.defineProperty,Jt=Object.getOwnPropertyDescriptor,Qt=(r,i,n,e)=>{for(var t=e>1?void 0:e?Jt(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},He=(r,i)=>(n,e)=>i(n,e,r);let pt=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=K(t.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,w.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(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s}=e,d=W.getGroupState(0,0,t.map(c=>c.transform||{})),m=t.map(c=>{const h=c.transform||{left:0,top:0},{unitId:g,subUnitId:f,drawingId:S}=c;return{unitId:g,subUnitId:f,drawingId:S,transform:{...h,left:h.left-d.left,top:h.top-d.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:d};i.push({parent:u,children:m})}),i}function tn(r){const i=[];return r.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s,transform:d={width:0,height:0}}=e;if(d==null)return;const m=t.map(c=>{const{transform:h}=c,{unitId:g,subUnitId:f,drawingId:S}=c,p=W.transformObjectOutOfGroup(h||{},d,d.width||0,d.height||0);return{unitId:g,subUnitId:f,drawingId:S,transform:p,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 ft={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:f})=>{o.push(g.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getGroupDrawingOp(i),{unitId:s,subUnitId:d,undo:m,redo:u,objects:c}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:d,objects:c,type:w.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:d,objects:tn(c),type:w.DrawingApplyType.UNGROUP}},{id:F.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:d,objects:c,type:w.DrawingApplyType.GROUP}},{id:F.id,params:o}]}),!0):!1}},Oe={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(_.SheetInterceptorService);if(!i)return!1;const a=i.drawings,s=a.map(y=>y.unitId),d=t.getBatchAddOp(a),{unitId:m,subUnitId:u,undo:c,redo:h,objects:g}=d,f=o.onCommandExecute({id:Oe.id,params:i}),S={id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:m,subUnitId:u,objects:g,type:w.DrawingApplyType.INSERT}},p={id:w.SetDrawingApplyMutation.id,params:{op:c,unitId:m,subUnitId:u,objects:g,type:w.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(I=f.preRedos)!=null?I:[],S,...f.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(M=f.preUndos)!=null?M:[],p,...f.undos,{id:F.id,params:s}],redoMutations:[...(b=f.preRedos)!=null?b:[],S,...f.redos,{id:F.id,params:s}]}),!0):!1}},St={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:d}=i,m={unitId:o,subUnitId:a,drawingIds:s};let u;if(d===l.ArrangeTypeEnum.forward?u=t.getForwardDrawingsOp(m):d===l.ArrangeTypeEnum.backward?u=t.getBackwardDrawingOp(m):d===l.ArrangeTypeEnum.front?u=t.getFrontDrawingsOp(m):d===l.ArrangeTypeEnum.back&&(u=t.getBackDrawingsOp(m)),u==null)return!1;const{objects:c,redo:h,undo:g}=u;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:h,unitId:o,subUnitId:a,objects:c,type:w.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:c,type:w.DrawingApplyType.ARRANGE}}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:c,type:w.DrawingApplyType.ARRANGE}}]}),!0):!1}},Pe={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:d,undo:m,redo:u,objects:c}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:s,subUnitId:d,op:u,objects:c,type:w.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:d,op:m,objects:c,type:w.DrawingApplyType.UPDATE}},{id:F.id,params:[s]}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:d,op:u,objects:c,type:w.DrawingApplyType.UPDATE}},{id:F.id,params:[s]}]}),!0):!1}},wt={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:f})=>{o.push(g.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getUngroupDrawingOp(i),{unitId:s,subUnitId:d,undo:m,redo:u,objects:c}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:d,objects:c,type:w.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:d,objects:en(c),type:w.DrawingApplyType.GROUP}},{id:F.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:d,objects:c,type:w.DrawingApplyType.UNGROUP}},{id:F.id,params:o}]}),!0):!1}};var nn=Object.defineProperty,rn=Object.getOwnPropertyDescriptor,on=(r,i,n,e)=>{for(var t=e>1?void 0:e?rn(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&&nn(i,n,t),t},ne=(r,i)=>(n,e)=>i(n,e,r);function an(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 Ot(r,i,n,e,t){var I;const{rotatedHeight:o,rotatedWidth:a}=an(n,e,t),d=r.get(W.IRenderManagerService).getRenderById(i.unitId);if(!d)return!1;const u=(I=d.with(E.SheetSkeletonManagerService).getSkeletonParam(i.subUnitId))==null?void 0:I.skeleton;if(u==null)return!1;const c=u.getCellByIndex(i.row,i.col),h=c.mergeInfo.endX-c.mergeInfo.startX-2,g=c.mergeInfo.endY-c.mergeInfo.startY-2,f=a/o,p=Math.ceil(Math.min(h,g*f))/a,v=!p||Number.isNaN(p)?.001:p;return{width:n*v,height:e*v}}let Ae=class extends l.Disposable{constructor(i,n,e,t,o,a,s,d,m,u,c,h,g){super();Q(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=d,this._contextService=m,this._messageService=u,this._localeService=c,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:U.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),n=i.length;return n>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):n===0?!1:(i.forEach(async e=>await this.insertFloatImageByFile(e)),!0)}async insertCellImage(){const n=(await this._fileOpenerService.openFile({multiple:!1,accept:U.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===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(n==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:s,source:d,base64Cache:m}=n,{width:u,height:c,image:h}=await U.getImageSize(m||""),{width:g,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(d,s,h);let S=1;if(u>U.DRAWING_IMAGE_WIDTH_LIMIT||c>U.DRAWING_IMAGE_HEIGHT_LIMIT){const I=U.DRAWING_IMAGE_WIDTH_LIMIT/u,M=U.DRAWING_IMAGE_HEIGHT_LIMIT/c;S=Math.max(I,M)}const p=this._getImagePosition(u*S,c*S,g,f);if(p==null)return;const v={unitId:t,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:d,transform:K(p,this._selectionRenderService,this._skeletonManagerService),sheetTransform:p};return this._commandService.executeCommand(Oe.id,{unitId:t,drawings:[v]})}async _insertCellImage(i){let n;try{n=await this._imageIoService.saveImage(i)}catch(p){const v=p.message;v===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)))}):v===U.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:oe.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):v===U.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:oe.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:d,image:m}=await U.getImageSize(a||"");this._imageIoService.addImageSourceCache(o,t,m);const u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;const c=l.createDocumentModelWithStyle("",{}),h=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(!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},f={unitId:c.getUnitId(),subUnitId:c.getUnitId(),drawingId:e,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t,source:o,transform:bt.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:c,drawings:[f],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(c.apply(S),this._commandService.syncExecuteCommand(_.SetRangeValuesCommand.id,{value:{[u.primary.actualRow]:{[u.primary.actualColumn]:{p:c.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=E.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(s==null)return;let{startColumn:d,startRow:m,startX:u,startY:c}=s,h=!1;if(u+i>e&&(u=e-i,u<0&&(u=0,i=e),h=!0),c+n>t&&(c=t-n,c<0&&(c=0,n=t),h=!0),h){const p=this._selectionRenderService.getCellWithCoordByOffset(u,c);if(p==null)return;u=p.startX,c=p.startY,d=p.actualColumn,m=p.actualRow}const g={column:d,columnOffset:0,row:m,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(u+i,c+n);if(f==null)return;const S={column:f.actualColumn,columnOffset:u+i-f.startX,row:f.actualRow,rowOffset:c+n-f.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(St.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:d}=e;if(d==null)return;const m=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:a});if(m==null||m.unitId!==this._context.unitId)return;const u=H({...m.transform,...d},this._selectionRenderService);if(u==null)return;const c={...e,transform:{...m.transform,...d,...K(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};n.push(c)}),n.length>0&&this._commandService.executeCommand(Pe.id,{unitId:i[0].unitId,drawings:n}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(i=>{this._commandService.executeCommand(ft.id,i);const{unitId:n,subUnitId:e,drawingId:t}=i[0].parent;this._commandService.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:e,drawingId:t}])})),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,G.ILocalFileService),ne(6,w.ISheetDrawingService),ne(7,U.IDrawingManagerService),ne(8,l.IContextService),ne(9,G.IMessageService),ne(10,l.Inject(l.LocaleService)),ne(11,l.Inject(_.SheetsSelectionsService)),ne(12,l.Inject(l.Injector))],Ae);var sn=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,dn=(r,i,n,e)=>{for(var t=e>1?void 0:e?cn(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&&sn(i,n,t),t},ve=(r,i)=>(n,e)=>i(n,e,r);function vt(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]],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,n.p.documentStyle.pageSize.width=1/0,n.p.documentStyle.pageSize.height=1/0,!0}return!1}let Xe=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===_.SetWorksheetRowHeightMutation.id){const e=r.params;n=e.ranges,i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===_.SetWorksheetColWidthMutation.id){const e=r.params;n=e.ranges,i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===_.SetWorksheetRowIsAutoHeightMutation.id){const e=r.params;n=e.ranges,i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===_.SetWorksheetRowAutoHeightMutation.id){const e=r.params;i=_.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===_.AddWorksheetMergeMutation.id){const e=r.params;n=e.ranges,i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===_.RemoveWorksheetMergeMutation.id){const e=r.params;n=e.ranges,i=_.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++)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(_.AFTER_CELL_EDIT,{priority:9999,handler:(r,i,n)=>(vt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:i.row,col:i.col},r),n(r))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:_.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)}}))}};Xe=dn([ve(0,l.ICommandService),ve(1,l.Inject(_.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))],Xe);var ln=Object.defineProperty,un=Object.getOwnPropertyDescriptor,gn=(r,i,n,e)=>{for(var t=e>1?void 0:e?un(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&&ln(i,n,t),t},Pt=(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)=>{vt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:t,col:o},a)})}}))}};Ve=gn([Pt(0,l.Inject(E.IAutoFillService)),Pt(1,l.Inject(l.Injector))],Ve);var hn=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,pn=(r,i,n,e)=>{for(var t=e>1?void 0:e?mn(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&&hn(i,n,t),t},xe=(r,i)=>(n,e)=>i(n,e,r);let Ke=class extends l.Disposable{constructor(i,n,e,t){super();Q(this,"_isSetCursor",!1);this._hoverManagerService=i,this._renderManagerService=n,this._selectionsService=e,this._drawingRenderService=t}_initHover(){}_initImageClick(){}};Ke=pn([xe(0,l.Inject(E.HoverManagerService)),xe(1,l.Inject(W.IRenderManagerService)),xe(2,l.Inject(_.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(W.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:o.with(Ae);if(!e)return!1;const t=i==null?void 0:i.files;if(t){const s=t.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 n,e;return(e=(n=r.get(W.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(Ae).insertCellImage())!=null?e:!1}};var fn=Object.defineProperty,Sn=Object.getOwnPropertyDescriptor,wn=(r,i,n,e)=>{for(var t=e>1?void 0:e?Sn(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&&fn(i,n,t),t},Ne=(r,i)=>(n,e)=>i(n,e,r);const At="image/png";function vn(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:At})}function _n(r){const i=new ClipboardItem({[At]:vn(r)});navigator.clipboard.write([i]).catch(n=>{console.error("Could not copy image using clipboard API: ",n)})}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,n=r();return document.body.appendChild(n),n.focus(),()=>{n.blur(),document.body.removeChild(n),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,n,e,t,o){super();Q(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===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,n,e);this._copyInfo=a}},onPasteCells:(i,n,e,t)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=E.COPY_TYPE.COPY,pasteType:a}=t,{range:s}=i||{},{range:d,unitId:m,subUnitId:u}=n;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:a,unitId:m,subUnitId:u,pasteRange:d},{copyRange:s,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:n,pasteType:a},E.COPY_TYPE.COPY)},onPastePlainText:(i,n)=>({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,n)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:i,pasteType:E.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},E.COPY_TYPE.COPY);{const e=n.filter(t=>t.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Ue.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(E.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:s,startY:d,endY:m}=o,u=this._drawingService.getDrawingData(i,n),c=this._focusedDrawings.slice();if(Object.keys(u).forEach(g=>{const f=u[g],{transform:S}=f;if(f.anchorType!==w.SheetDrawingAnchorType.Both||!S)return;const{left:p=0,top:v=0,width:I=0,height:M=0}=S,{drawingStartX:b,drawingEndX:y,drawingStartY:T,drawingEndY:C}={drawingStartX:p,drawingEndX:p+I,drawingStartY:v,drawingEndY:v+M};a<=b&&y<=s&&d<=T&&C<=m&&c.push(f)}),c.length)return{copyRange:e,drawings:c,unitId:i,subUnitId:n}}_generateSingleDrawingPasteMutations(i,n){const{pasteType:e,pasteTo:t}=i;if(Ut.includes(e))return{redos:[],undos:[]};const{unitId:o,subUnitId:a,range:s}=t,d=this._renderManagerService.getRenderById(o),m=d==null?void 0:d.with(E.SheetSkeletonManagerService),u=d==null?void 0:d.with(E.ISheetSelectionRenderService),c=this._copyInfo;if(!m||!u)return{redos:[],undos:[]};const{drawings:h}=c,g=E.discreteRangeToRange(s);return this._generateMutations(h,{unitId:o,subUnitId:a,isCut:n===E.COPY_TYPE.CUT,getTransform:(f,S)=>{var I;const p=m.attachRangeWithCoord({startRow:g.startRow,endRow:g.endRow,startColumn:g.startColumn,endColumn:g.endColumn}),v={...f,left:p==null?void 0:p.startX,top:p==null?void 0:p.startY};return{transform:v,sheetTransform:(I=H(v,u))!=null?I:S}}})}_generateMutations(i,n){const{unitId:e,subUnitId:t,getTransform:o,isCut:a}=n,s=[],d=[],{_drawingService:m}=this;return i.forEach(u=>{const{transform:c,sheetTransform:h}=u;if(!c)return;const g=o(c,h),f={...u,unitId:e,subUnitId:t,drawingId:a?u.drawingId:l.Tools.generateRandomId(),transform:g.transform,sheetTransform:g.sheetTransform};if(a){const{undo:S,redo:p,objects:v}=m.getBatchUpdateOp([f]);s.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,type:w.DrawingApplyType.UPDATE,op:p,objects:v}}),d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,type:w.DrawingApplyType.UPDATE,op:S,objects:v}})}else{const{undo:S,redo:p,objects:v}=m.getBatchAddOp([f]);s.push({id:w.SetDrawingApplyMutation.id,params:{op:p,unitId:e,subUnitId:t,objects:v,type:w.DrawingApplyType.INSERT}}),d.push({id:w.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:t,objects:v,type:w.DrawingApplyType.REMOVE}})}}),{redos:s,undos:d}}_generateRangeDrawingsPasteMutations(i,n){var N;const{unitId:e,subUnitId:t,pasteType:o,pasteRange:a}=i,{copyRange:s,copyType:d}=n;if(Ut.includes(o))return{redos:[],undos:[]};const m=(N=this._renderManagerService.getRenderById(e))==null?void 0:N.with(E.SheetSkeletonManagerService);if(!m||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!s)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:t,range:E.discreteRangeToRange(a)},pasteType:o},d);const{ranges:[c,h],mapFunc:g}=E.virtualizeDiscreteRanges([s,a]),{row:f,col:S}=g(c.startRow,c.startColumn),{row:p,col:v}=g(h.startRow,h.startColumn),I=m.attachRangeWithCoord({startRow:f,endRow:f,startColumn:S,endColumn:S}),M=m.attachRangeWithCoord({startRow:p,endRow:p,startColumn:v,endColumn:v});if(!I||!M||!this._copyInfo)return{redos:[],undos:[]};const b=M.startX-I.startX,y=M.startY-I.startY,T=p-f,C=v-S;return this._generateMutations(u,{unitId:e,subUnitId:t,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+C},from:{...j.from,row:j.from.row+T,column:j.from.column+C}}}},isCut:d===E.COPY_TYPE.CUT})}};ze=wn([Ne(0,E.ISheetClipboardService),Ne(1,W.IRenderManagerService),Ne(2,U.IDrawingManagerService),Ne(3,G.IClipboardInterfaceService),Ne(4,l.ICommandService)],ze);var Cn=Object.defineProperty,yn=Object.getOwnPropertyDescriptor,Dn=(r,i,n,e)=>{for(var t=e>1?void 0:e?yn(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},je=(r,i)=>(n,e)=>i(n,e,r);let qe=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(k.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 _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const s=i.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(s,d),u=Object.values(m),c=this._renderManagerService.getRenderById(s),h=c==null?void 0:c.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(f=>{f.classType===W.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>f.oKey.includes(S.drawingId))&&h.removeObject(f)})}})}))}_initDrawingEditable(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(k.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 _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const s=i.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(s,d),u=Object.values(m),c=this._renderManagerService.getRenderById(s),h=c==null?void 0:c.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(f=>{f.classType===W.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>f.oKey.includes(S.drawingId))&&h.detachTransformerFrom(f)})}})}))}_initViewPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(k.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{i&&i.activeSheet$.subscribe(e=>{var c;if(!e)return;const t=i.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),d=s==null?void 0:s.scene;if(d==null)return;const m=d.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).pipe(k.map(h=>h.every(g=>g.value)));u==null||u.pipe(k.filter(h=>h!==a),k.distinctUntilChanged()).subscribe({next:h=>{a=h,this._drawingManagerService.setDrawingVisible(h);const g=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);h?this._drawingManagerService.addNotification(S):(g.forEach(p=>{p.classType===W.RENDER_CLASS_TYPE.IMAGE&&S.some(v=>p.oKey.includes(v.drawingId))&&d.removeObject(p)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(t,o).id))==null||c.pipe(k.filter(h=>h.value!==a),k.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(k.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{i&&i.activeSheet$.subscribe(e=>{var c;if(!e)return;const t=i.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),d=s==null?void 0:s.scene;if(d==null)return;const m=d.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).pipe(k.map(h=>h.every(g=>g.value)));u==null||u.pipe(k.filter(h=>h!==a),k.distinctUntilChanged()).subscribe({next:h=>{a=h,this._drawingManagerService.setDrawingEditable(h);const g=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);h?(g.forEach(p=>{p.classType===W.RENDER_CLASS_TYPE.IMAGE&&S.some(v=>p.oKey.includes(v.drawingId))&&d.attachTransformerTo(p)}),this._drawingManagerService.addNotification(S)):(g.forEach(p=>{p.classType===W.RENDER_CLASS_TYPE.IMAGE&&S.some(v=>p.oKey.includes(v.drawingId))&&d.detachTransformerFrom(p)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(t,o).id))==null||c.pipe(k.filter(h=>h.value!==a),k.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const h=i.getUnitId(),g=e.getSheetId(),f=this._drawingManagerService.getDrawingData(h,g),S=Object.values(f),p=this._renderManagerService.getRenderById(h),v=p==null?void 0:p.scene;if(v==null)return;this._drawingManagerService.setDrawingEditable(!0),v.getAllObjectsByOrder().forEach(M=>{M.classType===W.RENDER_CLASS_TYPE.IMAGE&&S.some(b=>M.oKey.includes(b.drawingId))&&v.detachTransformerFrom(M)})}})})}))}};qe=Dn([je(0,U.IDrawingManagerService),je(1,W.IRenderManagerService),je(2,l.IPermissionService),je(3,l.IUniverInstanceService),je(4,l.Inject(l.UserManagerService))],qe);var Mn=Object.defineProperty,Tn=Object.getOwnPropertyDescriptor,bn=(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&&Mn(i,n,t),t},Ze=(r,i)=>(n,e)=>i(n,e,r);let Je=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(d=>{this._drawingRenderService.renderDrawing(s.data[d],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(E.SheetSkeletonManagerService).getSkeletonParam(t);if(!a)return n(r);const s=this._drawingManagerService.getDrawingDataForUnit(e),d=s==null?void 0:s[i.subUnitId];if(!d)return n(r);const{scaleX:m,scaleY:u}=o.scene,c=r?{...r}:{startColumn:0,endColumn:0,endRow:0,startRow:0},h=d.order.map(g=>d.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 f=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});f.column<c.startColumn&&(c.startColumn=f.column),f.row<c.startRow&&(c.startRow=f.row),c.endRow<S.row&&(c.endRow=S.row),c.endColumn<S.column&&(c.endColumn=S.column)}}),n(c)):n(r)}}))}};Je=bn([Ze(0,l.Inject(E.SheetPrintInterceptorService)),Ze(1,l.Inject(me.DrawingRenderService)),Ze(2,U.IDrawingManagerService),Ze(3,W.IRenderManagerService)],Je);var Rn=Object.defineProperty,En=Object.getOwnPropertyDescriptor,On=(r,i,n,e)=>{for(var t=e>1?void 0:e?En(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&&Rn(i,n,t),t},fe=(r,i)=>(n,e)=>i(n,e,r);const Pn=[_.InsertRowCommand.id,_.InsertColCommand.id,_.RemoveRowCommand.id,_.RemoveColCommand.id,_.DeleteRangeMoveLeftCommand.id,_.DeleteRangeMoveUpCommand.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id,_.DeltaRowHeightCommand.id,_.SetRowHeightCommand.id,_.DeltaColumnWidthCommand.id,_.SetColWidthCommand.id,_.SetRowHiddenCommand.id,_.SetSpecificRowsVisibleCommand.id,_.SetSpecificColsVisibleCommand.id,_.SetColHiddenCommand.id,_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id],An=[_.SetRowVisibleMutation.id,_.SetRowHiddenMutation.id,_.SetColVisibleMutation.id,_.SetColHiddenMutation.id,_.SetWorksheetRowHeightMutation.id,_.SetWorksheetColWidthMutation.id];let It=class extends l.Disposable{constructor(r,i,n,e,t,o,a,s,d){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=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===_.InsertRowCommand.id)return this._moveRowInterceptor(r.params,"insert");if([_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id].includes(i))return this._moveRangeInterceptor(r.params);if(i===_.InsertColCommand.id)return this._moveColInterceptor(r.params,"insert");if(i===_.RemoveRowCommand.id)return this._moveRowInterceptor(r.params,"remove");if(i===_.RemoveColCommand.id)return this._moveColInterceptor(r.params,"remove");if(i===_.DeleteRangeMoveLeftCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,0)}else if(i===_.DeleteRangeMoveUpCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,1)}else if(i===_.InsertRangeMoveDownCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,2)}else if(i===_.InsertRangeMoveRightCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,3)}else if(i===_.SetRowHiddenCommand.id||i===_.SetSpecificRowsVisibleCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForRowVisible(e,t,o)}else if(i===_.SetSpecificColsVisibleCommand.id||i===_.SetColHiddenCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForColVisible(e,t,o)}else if(i===_.DeltaRowHeightCommand.id||i===_.SetRowHeightCommand.id||i===_.DeltaColumnWidthCommand.id||i===_.SetColWidthCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n,a=i===_.DeltaRowHeightCommand.id||i===_.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(r,i){const n=_.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const e=n.unitId,t=n.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(e,t),d=[],m=[];if(Object.keys(s).forEach(u=>{const c=s[u],{updateDrawings:h,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(r,i,c);d.push(...h),m.push(...g)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,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:c,objects:g,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(m),c=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:c,objects:g,type:w.DrawingApplyType.INSERT}})}return o.push({id:F.id,params:[e]}),a.push({id:F.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(r,i,n){const e=[],t=[],{sheetTransform:o,anchorType:a=w.SheetDrawingAnchorType.Position,transform:s,unitId:d,subUnitId:m,drawingId:u}=n,{from:c,to:h}=o,{row:g,column:f}=c,{row:S,column:p}=h;if(o==null||s==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:v,endRow:I,startColumn:M,endColumn:b}=r;let y=null,T=null;if(i===0&&g>=v&&S<=I)if(f>=M&&p<=b)t.push({unitId:d,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&&f>=M&&p<=b)if(g>=v&&S<=I)t.push({unitId:d,subUnitId:m,drawingId:u});else{const C=this._shrinkRow(o,s,v,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,v,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=K(y,this._selectionRenderService,this._skeletonManagerService);e.push({...n,sheetTransform:y,transform:C})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(r,i,n){const e=H({...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 c=e[u],{sheetTransform:h,transform:g,anchorType:f=w.SheetDrawingAnchorType.Position}=c;if(f===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,c);else{const{from:S,to:p}=h,{row:v,column:I}=S,{row:M,column:b}=p;for(let y=0;y<n.length;y++){const T=n[y],{startRow:C,endRow:N,startColumn:R,endColumn:j}=T;if(b<R)continue;if(f===w.SheetDrawingAnchorType.Position){let D=null,L=null;if(I>=R&&I<=j){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:j,startRow:S.row,endRow:p.row});if(B==null)return;L={...g,left:B.startX}}if(L!=null&&(D=H(L,this._selectionRenderService),D!=null&&L!=null)){t.push({...c,sheetTransform:D,transform:L});break}this._remainDrawingSize(g,t,c);continue}if(I>=R&&b<=j)continue;let A=null,O=null;if(I>=R&&I<=j){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:j,startRow:S.row,endRow:p.row});if(D==null)return;O={...g,left:(D==null?void 0:D.startX)||0,width:((g==null?void 0:g.width)||0)-D.endX+D.startX}}else if(b>=R&&b<=j){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:R,endColumn:b,startRow:S.row,endRow:p.row});if(D==null)return;O={...g,left:D.startX-((g==null?void 0:g.width)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:R,endColumn:j,startRow:S.row,endRow:p.row});if(D==null)return;if(O={...g,width:((g==null?void 0:g.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){t.push({...c,sheetTransform:A,transform:O});break}else this._remainDrawingSize(g,t,c)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(r,i,t),d=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(r,i,o);d.push(...u),m.push(...c)}return{redos:a,undos:s,preRedos:d,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:F.id,params:[r]}],d=[{id:w.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,op:t,objects:a,type:w.DrawingApplyType.UPDATE}},{id:F.id,params:[r]}];return{redos:s,undos:d}}_getDrawingUndoForRowVisible(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:h,transform:g,anchorType:f=w.SheetDrawingAnchorType.Position}=c;if(f===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,c);else{const{from:S,to:p}=h,{row:v,column:I}=S,{row:M,column:b}=p;for(let y=0;y<n.length;y++){const T=n[y],{startRow:C,endRow:N,startColumn:R,endColumn:j}=T;if(M<C)continue;if(f===w.SheetDrawingAnchorType.Position){let D=null,L=null;if(v>=C&&v<=N){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:p.column,startRow:v,endRow:N});if(B==null)return;L={...g,top:B.startY}}if(L!=null&&(D=H(L,this._selectionRenderService),D!=null&&L!=null)){t.push({...c,sheetTransform:D,transform:L});break}this._remainDrawingSize(g,t,c);continue}if(v>=C&&M<=N)continue;let A=null,O=null;if(v>=C&&v<=N){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:p.column,startRow:v,endRow:N});if(D==null)return;O={...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<=N){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:p.column,startRow:C,endRow:M});if(D==null)return;O={...g,top:D.startY-((g==null?void 0:g.height)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:p.column,startRow:C,endRow:N});if(D==null)return;if(O={...g,height:((g==null?void 0:g.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){t.push({...c,sheetTransform:A,transform:O});break}else this._remainDrawingSize(g,t,c)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(r,i,t),d=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(r,i,o);d.push(...u),m.push(...c)}return{redos:a,undos:s,preRedos:d,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:d,transform:m,anchorType:u=w.SheetDrawingAnchorType.Position}=s;if(u===w.SheetDrawingAnchorType.None)this._remainDrawingSize(m,o,s);else{const{from:c,to:h}=d,{row:g,column:f}=c,{row:S,column:p}=h;for(let v=0;v<n.length;v++){const I=n[v],{startRow:M,endRow:b,startColumn:y,endColumn:T}=I;if(S<M||p<y)continue;if(u===w.SheetDrawingAnchorType.Position&&(g<=M&&S>=b||f<=y&&p>=T)){this._remainDrawingSize(m,o,s);continue}const C=K({...d},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=_.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=_.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(E.SheetSkeletonManagerService))==null?void 0:b.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=E.attachRangeWithCoord(a,n);if(!s)return{redos:[],undos:[]};const{startX:d,endX:m,startY:u,endY:c}=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:N=0,top:R=0,width:j=0,height:A=0}=C,{drawingStartX:O,drawingEndX:D,drawingStartY:L,drawingEndY:B}={drawingStartX:N,drawingEndX:N+j,drawingStartY:R,drawingEndY:R+A};d<=O&&D<=m&&u<=L&&B<=c&&g.push(T)});const f=[],S=[],p=i.startRow-n.startRow,v=i.startColumn-n.startColumn,I=g.map(y=>{const T=y.sheetTransform,C={to:{...T.to,row:T.to.row+p,column:T.to.column+v},from:{...T.from,row:T.from.row+p,column:T.from.column+v}},N=K(C,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:y.drawingId,transform:N,sheetTransform:C}});if(I.length){const y=this._sheetDrawingService.getBatchUpdateOp(I),{undo:T,redo:C,objects:N}=y;f.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:C,objects:N,type:w.DrawingApplyType.UPDATE}}),S.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:T,objects:N,type:w.DrawingApplyType.UPDATE}})}return{redos:f,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,d=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),c=[],h=[];if(Object.keys(u).forEach(g=>{const f=u[g],{sheetTransform:S,transform:p,anchorType:v=w.SheetDrawingAnchorType.Position}=f;if(S==null||p==null)return;let I,M;if(i==="insert"){const y=this._expandRow(S,p,a,s,v);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:N}=T;if(v===w.SheetDrawingAnchorType.Both&&C>=a&&N<=s)h.push({unitId:e,subUnitId:t,drawingId:g});else{const R=this._shrinkRow(S,p,a,s,v);I=R==null?void 0:R.newSheetTransform,M=R==null?void 0:R.newTransform}}if(!I||!M)return;const b={unitId:e,subUnitId:t,drawingId:g,transform:M,sheetTransform:I};c.push(b)}),c.length===0&&h.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:S,objects:p}=g;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:p,type:w.DrawingApplyType.UPDATE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:p,type:w.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),f=g.undo,S=g.redo,p=g.objects;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:p,type:w.DrawingApplyType.REMOVE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:p,type:w.DrawingApplyType.INSERT}})}return d.push({id:F.id,params:[e]}),m.push({id:F.id,params:[e]}),{redos:d,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,d=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),c=[],h=[];if(Object.keys(u).forEach(g=>{const f=u[g],{sheetTransform:S,transform:p,anchorType:v=w.SheetDrawingAnchorType.Position}=f;if(S==null||p==null)return;let I,M;if(i==="insert"){const y=this._expandCol(S,p,a,s,v);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:N}=T;if(v===w.SheetDrawingAnchorType.Both&&C>=a&&N<=s)h.push({unitId:e,subUnitId:t,drawingId:g});else{const R=this._shrinkCol(S,p,a,s,v);I=R==null?void 0:R.newSheetTransform,M=R==null?void 0:R.newTransform}}if(!I||!M)return;const b={unitId:e,subUnitId:t,drawingId:g,transform:M,sheetTransform:I};c.push(b)}),c.length===0&&h.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:S,objects:p}=g;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:p,type:w.DrawingApplyType.UPDATE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:p,type:w.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),f=g.undo,S=g.redo,p=g.objects;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:p,type:w.DrawingApplyType.REMOVE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:p,type:w.DrawingApplyType.INSERT}})}return d.push({id:F.id,params:[e]}),m.push({id:F.id,params:[e]}),{redos:d,undos:m}}_expandCol(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{column:d}=a,{column:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:H({...i},this._selectionRenderService),newTransform:i};let u=null,c=null;if(d>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:e,startRow:a.row,endRow:s.row});if(h==null)return;c={...i,left:(i.left||0)+h.endX-h.startX},u=H(c,this._selectionRenderService)}else if(m>=e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m+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,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{column:d}=a,{column:m}=s;if(t===w.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:m-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=n&&m<=e)return null;if(d<n&&m>e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...i},this._selectionRenderService),newTransform:i};else if(d>=n&&d<=e){if(d===n)c={...i,left:(i.left||0)-r.from.columnOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:d-1,startRow:a.row,endRow:s.row});if(h==null)return;c={...i,left:(i.left||0)-h.endX+h.startX-r.from.columnOffset}}u=H(c,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}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{row:d}=a,{row:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:H({...i},this._selectionRenderService),newTransform:i};let u=null,c=null;if(d>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:e,startColumn:a.column,endColumn:s.column});if(h==null)return;c={...i,top:(i.top||0)+h.endY-h.startY},u=H(c,this._selectionRenderService)}else if(m>=e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m+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,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{row:d}=a,{row:m}=s;if(t===w.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:m-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=n&&m<=e)return null;if(d<n&&m>e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...i},this._selectionRenderService),newTransform:i};else if(d>=n&&d<=e){if(d===n)c={...i,top:(i.top||0)-r.from.rowOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:d-1,startColumn:a.column,endColumn:s.column});if(h==null)return;c={...i,top:(i.top||0)-h.endY+h.startY-r.from.rowOffset}}u=H(c,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}},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===_.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 d=a[s].data;d!=null&&Object.keys(d).forEach(m=>{if(o===r&&s===i){const u=d[m];u.transform=K(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(d[m])}else t.push(d[m])})})}),this._drawingManagerService.removeNotification(t),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{An.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:d,anchorType:m=w.SheetDrawingAnchorType.Position}=a;if(m===w.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=s,{row:h,column:g}=u,{row:f,column:S}=c;for(let p=0;p<n.length;p++){const v=n[p],{startRow:I,endRow:M,startColumn:b,endColumn:y}=v;if(l.Rectangle.intersects({startRow:I,endRow:M,startColumn:b,endColumn:y},{startRow:h,endRow:f,startColumn:g,endColumn:S})||h>M||g>y){const T=m===w.SheetDrawingAnchorType.Position,C=K(s,this._selectionRenderService,this._skeletonManagerService);t.push({...a,transform:{...C,width:T?d==null?void 0:d.width:C==null?void 0:C.width,height:T?d==null?void 0:d.height:C==null?void 0:C.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(F.id,[r]))}};It=On([fe(1,W.IRenderManagerService),fe(2,l.ICommandService),fe(3,E.ISheetSelectionRenderService),fe(4,l.Inject(E.SheetSkeletonManagerService)),fe(5,l.Inject(_.SheetInterceptorService)),fe(6,w.ISheetDrawingService),fe(7,U.IDrawingManagerService),fe(8,l.IUniverInstanceService)],It);var ie=function(){return ie=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},ie.apply(this,arguments)},Un=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},Nt=te.forwardRef(function(r,i){var n=r.icon,e=r.id,t=r.className,o=r.extend,a=Un(r,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),d=te.useRef("_".concat(Wn()));return jt(n,"".concat(e),{defIds:n.defIds,idSuffix:d.current},ie({ref:i,className:s},a),o)});function jt(r,i,n,e,t){return te.createElement(r.tag,ie(ie({key:i},Nn(r,n,t)),e),(jn(r,n).children||[]).map(function(o,a){return jt(o,"".concat(i,"-").concat(r.tag,"-").concat(a),n,void 0,t)}))}function Nn(r,i,n){var e=ie({},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 jn(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)?ie(ie({},r),{children:r.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?ie(ie({},t),{attrs:ie(ie({},t.attrs),{id:t.attrs.id+i.idSuffix})}):t})}):r}function Wn(){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"}}]},Wt=te.forwardRef(function(r,i){return te.createElement(Nt,Object.assign({},r,{id:"add-image-single",ref:i,icon:Bn}))});Wt.displayName="AddImageSingle";const Ct={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:d,drawingId:m,drawingType:u}=a;return{unitId:s,subUnitId:d,drawingId:m,drawingType:u}});return i.executeCommand(Ie.id,{unitId:t,drawings:o})}},Ce={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(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 h={...c},{left:g=0,top:f=0}=c;return o===l.Direction.UP?h.top=f-1:o===l.Direction.DOWN?h.top=f+1:o===l.Direction.LEFT?h.left=g-1:o===l.Direction.RIGHT&&(h.left=g+1),{...u,transform:h,sheetTransform:H(h,t)}}).filter(u=>u!=null);return n.syncExecuteCommand(Pe.id,{unitId:s,drawings:d})?(n.syncExecuteCommand(F.id,[s]),!0):!1}},Bt="addition-and-subtraction-single",yt="sheet.menu.image";function Ln(r){return{id:yt,type:G.MenuItemType.SUBITEMS,icon:Bt,tooltip:"sheetImage.title",hidden$:G.getMenuHiddenObservable(r,l.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(r,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function kn(r){return{id:Ue.id,title:"sheetImage.upload.float",type:G.MenuItemType.BUTTON,hidden$:G.getMenuHiddenObservable(r,l.UniverInstanceType.UNIVER_SHEET)}}function $n(r){return{id:_t.id,title:"sheetImage.upload.cell",type:G.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,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=Lt(r[i]))&&(e&&(e+=" "),e+=n)}else for(n in r)r[n]&&(e&&(e+=" "),e+=n);return e}function Qe(){for(var r,i,n=0,e="",t=arguments.length;n<t;n++)(r=arguments[n])&&(i=Lt(r))&&(e&&(e+=" "),e+=i);return e}const Yn=r=>{var M;const i=l.useDependency(l.ICommandService),n=l.useDependency(l.LocaleService),e=l.useDependency(U.IDrawingManagerService),t=l.useDependency(W.IRenderManagerService),{drawings:o}=r,a=o[0];if(a==null)return;const{unitId:s}=a,d=t.getRenderById(s),m=d==null?void 0:d.scene;if(m==null)return;const u=m.getTransformerByCreate(),[c,h]=te.useState(!0),g=(M=a.anchorType)!=null?M:w.SheetDrawingAnchorType.Position,[f,S]=te.useState(g);function p(b,y){const T=[];return b.forEach(C=>{const{oKey:N}=C,R=y.getDrawingOKey(N);if(R==null)return T.push(null),!0;const{unitId:j,subUnitId:A,drawingId:O,drawingType:D,anchorType:L,sheetTransform:B}=R;T.push({unitId:j,subUnitId:A,drawingId:O,anchorType:L,sheetTransform:B,drawingType:D})}),T}te.useEffect(()=>{const b=u.clearControl$.subscribe(T=>{T===!0&&h(!1)}),y=u.changeStart$.subscribe(T=>{var R;const{objects:C}=T,N=p(C,e);if(N.length===0)h(!1);else if(N.length>=1){h(!0);const j=((R=N[0])==null?void 0:R.anchorType)||w.SheetDrawingAnchorType.Position;S(j)}});return()=>{y.unsubscribe(),b.unsubscribe()}},[]);function v(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(Pe.id,{unitId:y[0].unitId,drawings:T})}const I=b=>b?"block":"none";return x.jsxs("div",{className:Qe(Se.imageCommonPanelGrid,Se.imageCommonPanelBorder),style:{display:I(c)},children:[x.jsx("div",{className:Se.imageCommonPanelRow,children:x.jsx("div",{className:Qe(Se.imageCommonPanelColumn,Se.imageCommonPanelTitle),children:x.jsx("div",{children:n.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:f,onChange:v,direction:"vertical",children:[x.jsx(oe.Radio,{value:w.SheetDrawingAnchorType.Both,children:n.t("drawing-anchor.both")}),x.jsx(oe.Radio,{value:w.SheetDrawingAnchorType.Position,children:n.t("drawing-anchor.position")}),x.jsx(oe.Radio,{value:w.SheetDrawingAnchorType.None,children:n.t("drawing-anchor.none")})]})})})]})},Gn=()=>{const r=l.useDependency(U.IDrawingManagerService),i=r.getFocusDrawings(),[n,e]=te.useState(i);return te.useEffect(()=>{const t=r.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(n!=null&&n.length)&&x.jsxs("div",{className:Se.imageCommonPanel,children:[x.jsx(me.DrawingCommonPanel,{drawings:n}),x.jsx(Yn,{drawings:n})]})},Fn={[G.RibbonStartGroup.FORMULAS_INSERT]:{[yt]:{order:3,menuItemFactory:Ln,[Ue.id]:{order:0,menuItemFactory:kn},[_t.id]:{order:1,menuItemFactory:$n}}}};function We(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:G.KeyCode.ARROW_DOWN,priority:100,preconditions:We,staticParameters:{direction:l.Direction.DOWN}},Xn={id:Ce.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_UP,priority:100,preconditions:We,staticParameters:{direction:l.Direction.UP}},Vn={id:Ce.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_LEFT,priority:100,preconditions:We,staticParameters:{direction:l.Direction.LEFT}},xn={id:Ce.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_RIGHT,priority:100,preconditions:We,staticParameters:{direction:l.Direction.RIGHT}},Kn={id:Ct.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:We,binding:G.KeyCode.DELETE,mac:G.KeyCode.BACKSPACE};var zn=Object.defineProperty,qn=Object.getOwnPropertyDescriptor,Zn=(r,i,n,e)=>{for(var t=e>1?void 0:e?qn(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&&zn(i,n,t),t},ye=(r,i)=>(n,e)=>i(n,e,r);let et=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(Bt,Wt)),this.disposeWithMe(r.register(Et,Gn))}_initMenus(){this._menuManagerService.mergeMenu(Fn)}_initCommands(){[Ue,_t,Oe,Ie,Pe,ht,F,mt,ft,wt,Ce,Ct,St].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_initShortcuts(){[Hn,Xn,Vn,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(G.ComponentManager)),ye(1,G.IMenuManagerService),ye(2,l.ICommandService),ye(3,G.IShortcutService),ye(4,U.IDrawingManagerService),ye(5,l.Inject(_.SheetsSelectionsService))],et);var Jn=Object.defineProperty,Qn=Object.getOwnPropertyDescriptor,ei=(r,i,n,e)=>{for(var t=e>1?void 0:e?Qn(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&&Jn(i,n,t),t},_e=(r,i)=>(n,e)=>i(n,e,r);function ti(r,i,n,e,t){const{scaleX:o,scaleY:a}=i.getAncestorScale(),s=i.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN),d=e.getFreeze(),{startColumn:m,startRow:u,xSplit:c,ySplit:h}=d,g={left:!0,top:!0};if(!s)return{...r,absolute:g};const{left:f,right:S,top:p,bottom:v}=r;let{top:I,left:M,viewportScrollX:b,viewportScrollY:y}=s;const{boundsOfViewArea:T,scrollDirectionResponse:C}=t||{},{rowHeaderWidth:N,columnHeaderHeight:R}=n,j={top:R,left:N};T&&(l.Tools.isDefine(j.top)&&(j.top=T.top),l.Tools.isDefine(j.left)&&(j.left=T.left)),C==="HORIZONTAL"&&(y=0),C==="VERTICAL"&&(b=0);let A=0,O=0;const D=n.rowStartY(u-h)+R,L=n.colStartX(m-c)+N,B=n.rowStartY(u)+R,z=n.colStartX(m)+N;if(c===0)g.left=!1,A=(f-b)*o,O=(S-b)*o;else{const ee=f-(L-N),Z=S-(L-N);S<z?(A=ee*o,O=Z*o):f<=z&&S>=z?(A=ee*o,O=Math.max(M,(S-b)*o)):f>z&&(g.left=!1,A=Math.max((f-b)*o,M),O=Math.max((S-b)*o,M))}let V=0,q=0;if(h===0)g.top=!1,V=(p-y)*a,q=(v-y)*a;else{const ee=p-(D-R),Z=v-(D-R);v<B?(V=ee*a,q=Z*a):p<=B&&v>=B?(V=ee*a,q=Math.max(I,(v-y)*a)):p>B&&(g.top=!1,V=Math.max((p-y)*a,I),q=Math.max((v-y)*a,I))}return A=Math.max(A,j.left),V=Math.max(V,j.top),O=Math.max(O,j.left),q=Math.max(q,j.top),{left:A,right:O,top:V,bottom:q,absolute:g}}const le=(r,i,n,e,t)=>{const{scene:o}=i,{left:a,top:s,width:d,height:m,angle:u}=r,c={left:a,right:a+d,top:s,bottom:s+m},h=ti(c,o,n,e,t),{scaleX:g,scaleY:f}=o.getAncestorScale();return{startX:h.left,endX:h.right,startY:h.top,endY:h.bottom,rotate:u,width:d*g,height:m*f,absolute:h.absolute}};P.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(n,e,t,o,a,s,d){super();Q(this,"_domLayerMap",new Map);Q(this,"_domLayerInfoMap",new Map);Q(this,"_transformChange$",new k.Subject);Q(this,"transformChange$",this._transformChange$.asObservable());Q(this,"_add$",new k.Subject);Q(this,"add$",this._add$.asObservable());Q(this,"_remove$",new k.Subject);Q(this,"remove$",this._remove$.asObservable());Q(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,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(k.filter(n=>n===l.LifecycleStages.Rendered),k.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 se,ce,J;const{unitId:t,subUnitId:o,drawingId:a}=e,s=_.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(t,l.UniverInstanceType.UNIVER_SHEET);if(!m)return;const u=m.getActiveSheet().getSheetId();if(!d||!s)return;const c=(se=this._renderManagerService.getRenderById(t))==null?void 0:se.with(E.SheetSkeletonManagerService).getSkeletonParam(o);if(!c)return;const{transform:h,drawingType:g,data:f}=d;if(g!==l.DrawingTypeEnum.DRAWING_DOM&&g!==l.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(t);if(S==null)return;const{scene:p,canvas:v}=S;if(h==null)return!0;if(u!==o)return;const{left:I,top:M,width:b,height:y,angle:T,flipX:C,flipY:N,skewX:R,skewY:j}=h,A=U.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),O=p.getObject(A);if(O!=null){O.transformByState({left:I,top:M,width:b,height:y,angle:T,flipX:C,flipY:N,skewX:R,skewY:j});return}const D={left:I,top:M,width:b,height:y,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},L=g===l.DrawingTypeEnum.DRAWING_CHART;if(L){const Y=f?f.backgroundColor:"white";D.fill=Y,D.rotateEnabled=!1,f&&f.border&&(D.stroke=f.border),D.paintFirst="stroke",D.strokeWidth=1,D.borderEnabled=!1,D.radius=8}const B=new W.Rect(A,D);L&&B.setObjectType(W.ObjectType.CHART),p.addObject(B,W.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&p.attachTransformerTo(B);const z=this._ensureMap(t,o),V=new l.DisposableCollection,q=le(B,S.renderUnit,c.skeleton,s.worksheet),ae=new k.BehaviorSubject(q),ee={dispose:V,rect:B,position$:ae,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:ae,id:a,componentKey:d.componentKey,onPointerDown:Y=>{v.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{v.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{v.dispatchEvent(new PointerEvent(Y.type,Y))},onWheel:Y=>{v.dispatchEvent(new WheelEvent(Y.type,Y))},props:(J=(ce=z.get(a))==null?void 0:ce.props)!=null?J:this._getFloatDomProps(a),data:f,unitId:t});const Z=B.onTransformChange$.subscribeEvent(()=>{const Y=le(B,S.renderUnit,c.skeleton,s.worksheet);ae.next(Y)});V.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),Z&&V.add(Z),this._domLayerInfoMap.set(a,ee),z.set(a,{...z.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a}=e,s=U.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),d=this._getSceneAndTransformerByDrawingSearch(t);if(d==null)return;const{transformer:m,scene:u}=d,c=u.getObject(s);c!=null&&c.oKey&&m.clearControlByIds([c==null?void 0:c.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,t),s=Array.from(a.keys()),d=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),m=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(E.SheetSkeletonManagerService).getSkeletonParam(t);!o||!d||!m||s.forEach(c=>{const h=this._domLayerInfoMap.get(c);if(h){const g=le(h.rect,o.renderUnit,m.skeleton,d.worksheet,h);h.position$.next(g)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(k.switchMap(e=>e?e.activeSheet$:k.of(null)),k.map(e=>{if(!e)return null;const t=e.getUnitId(),o=this._renderManagerService.getRenderById(t);return o?{render:o,unitId:t,subUnitId:e.getSheetId()}:null}),k.switchMap(e=>e?l.fromEventSubject(e.render.scene.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(k.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):k.of(null))).subscribe(e=>{if(!e)return;const{unitId:t,subUnitId:o}=e;n(t,o)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===E.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===_.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,d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(E.ISheetSelectionRenderService);if(d==null)return;const m=d.getCellWithCoordByOffset(t,a);if(m==null)return;const u={column:m.actualColumn,columnOffset:t-m.startX,row:m.actualRow,rowOffset:a-m.startY},c=d.getCellWithCoordByOffset(o,s);if(c==null)return;const h={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:s-c.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:d}=s,m=U.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),u=d.getObject(m);u&&u instanceof W.Rect&&u.setProps(o)}}addFloatDomToPosition(n,e){const t=_.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=t,{initPosition:s,componentKey:d,data:m,allowTransform:u=!0}=n,c=e!=null?e:l.generateRandomId(),h=this._getPosition(s,o);if(h==null)return;this._ensureMap(o,a).set(c,n);const f={unitId:o,subUnitId:a,drawingId:c,drawingType:n.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,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(Oe.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:a,id:c}),{id:c,dispose:()=>{this._removeDom(c,!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:c,objects:h}=u;this._commandService.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:c,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 N,R,j,A,O;const a=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:d}=a,m=this._getSceneAndTransformerByDrawingSearch(s);if(!m)return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const c=(N=this._renderManagerService.getRenderById(s))==null?void 0:N.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:h,data:g,allowTransform:f=!0}=e,S=o!=null?o:l.generateRandomId(),{position:p,position$:v}=this._createRangePositionObserver(n,u,c.skeleton),I=this._getPosition(p,s);if(I==null)return;this._ensureMap(s,d).set(S,e);const b=m.scene,{scaleX:y}=b.getAncestorScale(),T=tt(p,t,y),C={unitId:s,subUnitId:d,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:f};{const{unitId:D,subUnitId:L,drawingId:B}=C,z=_.getSheetCommandTarget(this._univerInstanceService,{unitId:D,subUnitId:L}),V=C,q=this._univerInstanceService.getUnit(D,l.UniverInstanceType.UNIVER_SHEET);if(!q)return;const ae=q.getActiveSheet().getSheetId();if(!V||!z)return;const ee=(R=this._renderManagerService.getRenderById(D))==null?void 0:R.with(E.SheetSkeletonManagerService);if(!ee)return;const Z=ee.getWorksheetSkeleton(L);if(!Z)return;const{transform:se,drawingType:ce,data:J}=V;if(ce!==l.DrawingTypeEnum.DRAWING_DOM&&ce!==l.DrawingTypeEnum.DRAWING_CHART)return;const Y=this._getSceneAndTransformerByDrawingSearch(D);if(Y==null)return;const{scene:De,canvas:Me}=Y;if(se==null||ae!==L)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:L,drawingId:B}),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,L).length-1},be=ce===l.DrawingTypeEnum.DRAWING_CHART;if(be){const $=J?J.backgroundColor:"white";re.fill=$,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 W.Rect(dt,re);be&&de.setObjectType(W.ObjectType.CHART),De.addObject(de,W.DRAWING_OBJECT_LAYER_INDEX),V.allowTransform!==!1&&De.attachTransformerTo(de);const Le=this._ensureMap(D,L),ge=new l.DisposableCollection,lt=De.getMainViewport(),{rowHeaderWidth:Re,columnHeaderHeight:ke}=Z.skeleton,ut={top:ke,left:Re,bottom:lt.bottom,right:lt.right},he={dispose:ge,rect:de,boundsOfViewArea:ut,domAnchor:t,unitId:D,subUnitId:L},X=le(de,Y.renderUnit,Z.skeleton,z.worksheet,he),Ee=new k.BehaviorSubject(X);he.position$=Ee;let $e={position$:Ee,id:B,componentKey:V.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{Me.dispatchEvent(new WheelEvent($.type,$))},props:(A=(j=Le.get(B))==null?void 0:j.props)!=null?A:this._getFloatDomProps(B),data:J,unitId:D};e.eventPassThrough&&($e={...$e,onPointerDown:$=>{Me.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{Me.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{Me.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom($e),this.disposeWithMe(v.subscribe($=>{var Gt,Ft,Ht,Xt;const Yt=tt({rotate:0,startX:$.startX,startY:$.startY,endX:$.endX,endY:$.endY,width:(Gt=t.width)!=null?Gt:$.width,height:(Ft=t.height)!=null?Ft:$.height,absolute:{left:p.absolute.left,top:p.absolute.top}},t),ai=U.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:L,drawingId:B}),si=new W.Rect(ai,{left:Yt.startX,top:Yt.startY,width:(Ht=t.width)!=null?Ht:$.width,height:(Xt=t.height)!=null?Xt:$.height,zIndex:this._drawingManagerService.getDrawingOrder(D,L).length-1}),ci=le(si,Y.renderUnit,Z.skeleton,z.worksheet,he);Ee.next(ci)}));const Ye=(O=this._renderManagerService.getRenderById(D))==null?void 0:O.with(E.SheetSkeletonManagerService);Ye==null||Ye.currentSkeleton$.subscribe($=>{$&&Z.sheetId!==$.sheetId&&this._removeDom(S,!0)});const gt=de.onTransformChange$.subscribeEvent(()=>{const $=le(de,Y.renderUnit,Z.skeleton,z.worksheet,he);Ee.next($)});ge.add(()=>{this._canvasFloatDomService.removeFloatDom(B)}),gt&&ge.add(gt),this._domLayerInfoMap.set(B,he),Le.set(B,{...Le.get(B)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(n,e,t,o){var T,C,N,R,j;const a=_.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:h,data:g,allowTransform:f=!0}=e,S=o!=null?o:l.generateRandomId(),{position:p,position$:v}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:n,endColumn:n},u,c.skeleton),I=p;I.startY=0;const M=this._getPosition(p,s);if(M==null)return;this._ensureMap(s,d).set(S,e);const y={unitId:s,subUnitId:d,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:f};{const{unitId:A,subUnitId:O,drawingId:D}=y,L=_.getSheetCommandTarget(this._univerInstanceService,{unitId:A,subUnitId:O}),B=y,z=this._univerInstanceService.getUnit(A,l.UniverInstanceType.UNIVER_SHEET);if(!z)return;const V=z.getActiveSheet().getSheetId();if(!B||!L)return;const q=(C=this._renderManagerService.getRenderById(A))==null?void 0:C.with(E.SheetSkeletonManagerService);if(!q)return;const ae=q.getWorksheetSkeleton(O);if(!ae)return;const{transform:ee,data:Z}=B,se=this._getSceneAndTransformerByDrawingSearch(A);if(se==null)return;const{scene:ce,canvas:J}=se;if(ee==null||V!==O)return;const{left:Y,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:Y,top:De,width:Me,height:it,angle:rt,flipX:ot,flipY:at,skewX:Mt,skewY:Tt});return}const Te=tt({rotate:0,startX:I.startX,startY:0,endX:p.endX,endY:p.endY,width:t.width,height:t.height,absolute:{left:p.absolute.left,top:p.absolute.top}},t),dt={left:Te.startX,top:Te.startY,width:Te.width,height:Te.height,zIndex:this._drawingManagerService.getDrawingOrder(A,O).length-1},ue=new W.Rect(st,dt);ce.addObject(ue,W.DRAWING_OBJECT_LAYER_INDEX),B.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:t,scrollDirectionResponse:"HORIZONTAL"},lt=le(ue,se.renderUnit,ae.skeleton,L.worksheet,ge),Re=new k.BehaviorSubject(lt);ge.position$=Re;let ke={position$:Re,id:D,componentKey:B.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:X=>{J.dispatchEvent(new WheelEvent(X.type,X))},props:(R=(N=re.get(D))==null?void 0:N.props)!=null?R:this._getFloatDomProps(D),data:Z,unitId:A};e.eventPassThrough&&(ke={...ke,onPointerDown:X=>{J.dispatchEvent(new PointerEvent(X.type,X))},onPointerMove:X=>{J.dispatchEvent(new PointerEvent(X.type,X))},onPointerUp:X=>{J.dispatchEvent(new PointerEvent(X.type,X))}}),this._canvasFloatDomService.addFloatDom(ke);const ut=ue.onTransformChange$.subscribeEvent(()=>{const X=le(ue,se.renderUnit,ae.skeleton,L.worksheet,ge);Re.next(X)});this.disposeWithMe(v.subscribe(X=>{const Ee=tt({rotate:0,startX:X.startX,startY:0,endX:X.endX,endY:X.endY,width:t.width,height:t.height,absolute:{left:p.absolute.left,top:p.absolute.top}},t),$e=U.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:O,drawingId:D}),Ye=new W.Rect($e,{left:Ee.startX,top:0,width:t.width,height:t.height,zIndex:this._drawingManagerService.getDrawingOrder(A,O).length-1}),gt=le(Ye,se.renderUnit,ae.skeleton,L.worksheet,ge);Re.next(gt)}));const he=(j=this._renderManagerService.getRenderById(A))==null?void 0:j.with(E.SheetSkeletonManagerService);he==null||he.currentSkeleton$.subscribe(X=>{X&&c.sheetId!==X.sheetId&&this._removeDom(S,!0)}),be.add(()=>{this._canvasFloatDomService.removeFloatDom(D)}),ut&&be.add(ut),this._domLayerInfoMap.set(D,ge),re.set(D,{...re.get(D)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(n,e,t){let{startRow:o,startColumn:a}=n;const s=Be(o,a,t),d=new k.BehaviorSubject(s),m=Be(n.endRow,n.endColumn,t),u=new k.BehaviorSubject(m),c=()=>{const v=Be(o,a,t),I=Be(n.endRow,n.endColumn,t);d.next(v),u.next(I)},h=new l.DisposableCollection;h.add(e.engine.clientRect$.subscribe(()=>c())),h.add(this._commandService.onCommandExecuted(v=>{if(v.id===_.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(M=>M.row===o)>-1){c();return}(_.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(v.id)>-1||v.id===E.SetScrollOperation.id||v.id===E.SetZoomRatioOperation.id)&&c()}));const g=(v,I)=>{o=v,a=I,c()},f=()=>({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=d.pipe(k.map(v=>{const I=Be(n.endRow,n.endColumn,t);return{rotate:0,width:I.right-v.left,height:I.bottom-v.top,absolute:{left:!0,top:!0},startX:v.left,startY:v.top,endX:I.right,endY:I.bottom}})),p=f();return{position$:S,position:p,updateRowCol:g,topLeftPos$:d,rightBottomPos$:u,disposable:h}}},P.SheetCanvasFloatDomManagerService=ei([_e(0,l.Inject(W.IRenderManagerService)),_e(1,l.IUniverInstanceService),_e(2,l.Inject(l.ICommandService)),_e(3,U.IDrawingManagerService),_e(4,l.Inject(G.CanvasFloatDomService)),_e(5,w.ISheetDrawingService),_e(6,l.Inject(l.LifecycleService))],P.SheetCanvasFloatDomManagerService);function Be(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 tt(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,d=0;if(i){if(i.horizonOffsetAlign==="right"){const c=nt(i.marginX,e*n);s=r.endX-c-o}else s=r.startX+nt(i.marginX,e);if(i.verticalOffsetAlign==="bottom"){const c=nt(i.marginY,t*n);d=r.endY-c-a}else d=r.startY+nt(i.marginY,t)}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 n=Number.parseFloat(r);return i*n/100}var kt=Object.defineProperty,ni=Object.getOwnPropertyDescriptor,ii=(r,i,n)=>i in r?kt(r,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[i]=n,ri=(r,i,n,e)=>{for(var t=e>1?void 0:e?ni(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},Dt=(r,i)=>(n,e)=>i(n,e,r),$t=(r,i,n)=>ii(r,typeof i!="symbol"?i+"":i,n);const oi="SHEET_IMAGE_UI_PLUGIN";P.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(i=Rt,n,e,t){super(),this._config=i,this._injector=n,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=l.merge({},Rt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Vt,a)}onStarting(){l.registerDependencies(this._injector,[[P.SheetCanvasFloatDomManagerService],[et],[Fe],[Je],[qe],[ze],[Xe],[Ke],[Ve]]),l.touchDependencies(this._injector,[[P.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[ze]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[qe],[Je],[et],[Xe],[Ke],[Ve]])}onSteady(){this._injector.get(Fe)}_registerRenderModules(){[[Ae],[It],[pt]].forEach(i=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,i))})}},$t(P.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),$t(P.UniverSheetsDrawingUIPlugin,"pluginName",oi),P.UniverSheetsDrawingUIPlugin=ri([l.DependentOn(U.UniverDrawingPlugin,we.UniverDocsDrawingPlugin,me.UniverDrawingUIPlugin,w.UniverSheetsDrawingPlugin),Dt(1,l.Inject(l.Injector)),Dt(2,W.IRenderManagerService),Dt(3,l.IConfigService)],P.UniverSheetsDrawingUIPlugin),P.ClearSheetDrawingTransformerOperation=F,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"})});
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.202502071606",
3
+ "version": "0.6.0-nightly.202502091605",
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.202502071606",
63
- "@univerjs/docs-drawing": "0.6.0-nightly.202502071606",
64
- "@univerjs/design": "0.6.0-nightly.202502071606",
65
- "@univerjs/drawing": "0.6.0-nightly.202502071606",
66
- "@univerjs/docs-ui": "0.6.0-nightly.202502071606",
67
- "@univerjs/drawing-ui": "0.6.0-nightly.202502071606",
68
- "@univerjs/sheets": "0.6.0-nightly.202502071606",
69
- "@univerjs/sheets-drawing": "0.6.0-nightly.202502071606",
70
- "@univerjs/engine-render": "0.6.0-nightly.202502071606",
71
- "@univerjs/sheets-ui": "0.6.0-nightly.202502071606",
72
- "@univerjs/ui": "0.6.0-nightly.202502071606"
62
+ "@univerjs/core": "0.6.0-nightly.202502091605",
63
+ "@univerjs/design": "0.6.0-nightly.202502091605",
64
+ "@univerjs/docs-drawing": "0.6.0-nightly.202502091605",
65
+ "@univerjs/docs-ui": "0.6.0-nightly.202502091605",
66
+ "@univerjs/drawing": "0.6.0-nightly.202502091605",
67
+ "@univerjs/engine-render": "0.6.0-nightly.202502091605",
68
+ "@univerjs/sheets": "0.6.0-nightly.202502091605",
69
+ "@univerjs/sheets-drawing": "0.6.0-nightly.202502091605",
70
+ "@univerjs/ui": "0.6.0-nightly.202502091605",
71
+ "@univerjs/drawing-ui": "0.6.0-nightly.202502091605",
72
+ "@univerjs/sheets-ui": "0.6.0-nightly.202502091605"
73
73
  },
74
74
  "devDependencies": {
75
75
  "less": "^4.2.2",