@univerjs/sheets-drawing-ui 0.1.13-nightly.202406041140 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Disposable } from '@univerjs/core';
|
|
2
|
+
import { IDrawingManagerService } from '@univerjs/drawing';
|
|
3
|
+
import { DrawingRenderService } from '@univerjs/drawing-ui';
|
|
4
|
+
import { IRenderManagerService } from '@univerjs/engine-render';
|
|
5
|
+
import { SheetPrintInterceptorService } from '@univerjs/sheets-ui';
|
|
6
|
+
|
|
7
|
+
export declare class SheetDrawingPrintingController extends Disposable {
|
|
8
|
+
private readonly _sheetPrintInterceptorService;
|
|
9
|
+
private readonly _drawingRenderService;
|
|
10
|
+
private readonly _drawingManagerService;
|
|
11
|
+
private readonly _renderManagerService;
|
|
12
|
+
constructor(_sheetPrintInterceptorService: SheetPrintInterceptorService, _drawingRenderService: DrawingRenderService, _drawingManagerService: IDrawingManagerService, _renderManagerService: IRenderManagerService);
|
|
13
|
+
private _initPrinting;
|
|
14
|
+
}
|
|
@@ -2,7 +2,7 @@ import { IPosition, ITransformState, Worksheet, Disposable, ICommandService, IUn
|
|
|
2
2
|
import { IBoundRectNoAngle, Scene, SpreadsheetSkeleton, IRenderManagerService } from '@univerjs/engine-render';
|
|
3
3
|
import { CanvasFloatDomService } from '@univerjs/ui';
|
|
4
4
|
import { IDrawingManagerService } from '@univerjs/drawing';
|
|
5
|
-
import { ISelectionRenderService
|
|
5
|
+
import { ISelectionRenderService } from '@univerjs/sheets-ui';
|
|
6
6
|
import { ISheetDrawingService } from '@univerjs/sheets-drawing';
|
|
7
7
|
|
|
8
8
|
export interface ICanvasFloatDom {
|
|
@@ -25,7 +25,6 @@ export declare function transformBound2DOMBound(originBound: IBoundRectNoAngle,
|
|
|
25
25
|
export declare class SheetCanvasFloatDomManagerService extends Disposable {
|
|
26
26
|
private _renderManagerService;
|
|
27
27
|
private _univerInstanceService;
|
|
28
|
-
private _sheetSkeletonManagerService;
|
|
29
28
|
private _commandService;
|
|
30
29
|
private _drawingManagerService;
|
|
31
30
|
private readonly _selectionRenderService;
|
|
@@ -44,7 +43,7 @@ export declare class SheetCanvasFloatDomManagerService extends Disposable {
|
|
|
44
43
|
subUnitId: string;
|
|
45
44
|
id: string;
|
|
46
45
|
}>;
|
|
47
|
-
constructor(_renderManagerService: IRenderManagerService, _univerInstanceService: IUniverInstanceService,
|
|
46
|
+
constructor(_renderManagerService: IRenderManagerService, _univerInstanceService: IUniverInstanceService, _commandService: ICommandService, _drawingManagerService: IDrawingManagerService, _selectionRenderService: ISelectionRenderService, _canvasFloatDomService: CanvasFloatDomService, _sheetDrawingService: ISheetDrawingService);
|
|
48
47
|
private _ensureMap;
|
|
49
48
|
private _getSceneAndTransformerByDrawingSearch;
|
|
50
49
|
private _drawingAddListener;
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(A,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/drawing-ui"),require("@univerjs/sheets-drawing"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("rxjs"),require("@univerjs/ui"),require("@wendellhu/redi/react-bindings"),require("@univerjs/sheets"),require("react"),require("@univerjs/design"),require("clsx")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/drawing-ui","@univerjs/sheets-drawing","@univerjs/drawing","@univerjs/engine-render","@univerjs/sheets-ui","rxjs","@univerjs/ui","@wendellhu/redi/react-bindings","@univerjs/sheets","react","@univerjs/design","clsx"],h):(A=typeof globalThis<"u"?globalThis:A||self,h(A.UniverSheetsDrawingUi={},A.UniverCore,A["@wendellhu/redi"],A.UniverDrawingUi,A.UniverSheetsDrawing,A.UniverDrawing,A.UniverEngineRender,A.UniverSheetsUi,A.rxjs,A.UniverUi,A["@wendellhu/redi/react-bindings"],A.UniverSheets,A.React,A.UniverDesign,A.clsx))})(this,function(A,h,j,ee,m,E,F,X,te,k,$,C,b,q,se){"use strict";var gn=Object.defineProperty;var hn=(A,h,j)=>h in A?gn(A,h,{enumerable:!0,configurable:!0,writable:!0,value:j}):A[h]=j;var K=(A,h,j)=>(hn(A,typeof h!="symbol"?h+"":h,j),j);const L={id:"sheet.operation.clear-drawing-transformer",type:h.CommandType.MUTATION,handler:(e,t)=>{const n=e.get(F.IRenderManagerService);return t.forEach(i=>{var r,o;(o=(r=n.getRenderById(i))==null?void 0:r.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},fe={id:"sheet.command.remove-sheet-image",type:h.CommandType.COMMAND,handler:(e,t)=>{const n=e.get(h.ICommandService),i=e.get(h.IUndoRedoService),r=e.get(m.ISheetDrawingService);if(!t)return!1;const{drawings:o}=t,a=[];o.forEach(S=>{const{unitId:f}=S;a.push(f)});const s=r.getBatchRemoveOp(o),{unitId:c,subUnitId:u,undo:l,redo:d,objects:g}=s;return n.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:c,subUnitId:u,op:d,objects:g,type:m.DrawingApplyType.REMOVE})?(i.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:l,objects:g,type:m.DrawingApplyType.INSERT}},{id:L.id,params:a}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:d,objects:g,type:m.DrawingApplyType.REMOVE}},{id:L.id,params:a}]}),!0):!1}},we="COMPONENT_SHEET_DRAWING_PANEL",_e={id:"sidebar.operation.sheet-image",type:h.CommandType.COMMAND,handler:async(e,t)=>{const n=e.get(k.ISidebarService),i=e.get(h.LocaleService),r=e.get(h.IUniverInstanceService),o=e.get(E.IDrawingManagerService);if(!C.getSheetCommandTarget(r))return!1;switch(t.value){case"open":n.open({header:{title:i.t("sheetImage.panel.title")},children:{label:we},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:n.close();break}return!0}},Ce={id:"sheet.operation.edit-sheet-image",type:h.CommandType.OPERATION,handler:(e,t)=>{const n=e.get(E.IDrawingManagerService),i=e.get(h.ICommandService);return t==null?!1:(n.focusDrawing([t]),i.executeCommand(_e.id,{value:"open"}),!0)}},ce={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},Le=()=>{const e=$.useDependency(E.IImageIoService),t=$.useDependency(h.LocaleService),[n,i]=b.useState(0);return b.useEffect(()=>{const r=e.change$.subscribe(o=>{i(o)});return()=>{r.unsubscribe()}},[e]),b.createElement("div",{style:{display:n>0?"block":"none"},className:ce.uploadLoading},b.createElement("div",{className:ce.uploadLoadingBody},b.createElement("div",{className:ce.uploadLoadingBodyAnimation}),b.createElement("div",{className:ce.uploadLoadingBodyText},`${t.t("uploadLoading.loading")}: ${n}`)))};var We=(e,t,n,i)=>{for(var r=t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(r=a(r)||r);return r},Q=(e,t)=>(n,i)=>t(n,i,e);let le=class extends h.RxDisposable{constructor(t,n,i,r,o,a,s){super();K(this,"_initImagePopupMenu",new Set);this._injector=t,this._drawingManagerService=n,this._canvasPopManagerService=i,this._renderManagerService=r,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET).pipe(te.takeUntil(this.dispose$)).subscribe(t=>this._create(t)),this._univerInstanceService.getTypeOfUnitDisposed$(h.UniverInstanceType.UNIVER_SHEET).pipe(te.takeUntil(this.dispose$)).subscribe(t=>this._dispose(t)),this._univerInstanceService.getAllUnitsForType(h.UniverInstanceType.UNIVER_SHEET).forEach(t=>this._create(t)),this._uiPartsService.registerComponent(k.BuiltInUIPart.CONTENT,()=>$.connectInjector(Le,this._injector))}_dispose(t){const n=t.getUnitId();this._renderManagerService.removeRender(n)}_create(t){if(!t)return;const n=t.getUnitId();this._renderManagerService.has(n)&&!this._initImagePopupMenu.has(n)&&(this._popupMenuListener(n),this._initImagePopupMenu.add(n))}_hasCropObject(t){const n=t.getAllObjects();for(const i of n)if(i instanceof ee.ImageCropperObject)return!0;return!1}_popupMenuListener(t){var o;const n=(o=this._renderManagerService.getRenderById(t))==null?void 0:o.scene;if(!n)return;const i=n.getTransformerByCreate();if(!i)return;const r=[];this.disposeWithMe(h.toDisposable(i.onCreateControlObservable.add(()=>{if(this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(n))return;const a=i.getSelectedObjectMap();if(a.size>1){r.forEach(p=>p.dispose());return}const s=a.values().next().value;if(!s)return;const c=s.oKey,u=this._drawingManagerService.getDrawingOKey(c);if(!u)return;const{unitId:l,subUnitId:d,drawingId:g}=u;r.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:ee.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(l,d,g)}}))),this._drawingManagerService.focusDrawing([{unitId:l,subUnitId:d,drawingId:g}])}))),this.disposeWithMe(h.toDisposable(i.onClearControlObservable.add(()=>{r.forEach(a=>a.dispose()),this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}))),this.disposeWithMe(h.toDisposable(i.onChangingObservable.add(()=>{r.forEach(a=>a.dispose())})))}_getImageMenuItems(t,n,i){return[{label:"image-popup.edit",index:0,commandId:Ce.id,commandParams:{unitId:t,subUnitId:n,drawingId:i},disable:!1},{label:"image-popup.delete",index:1,commandId:fe.id,commandParams:{unitId:t,drawings:[{unitId:t,subUnitId:n,drawingId:i}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ee.OpenImageCropOperation.id,commandParams:{unitId:t,subUnitId:n,drawingId:i},disable:!1},{label:"image-popup.reset",index:3,commandId:ee.ImageResetSizeOperation.id,commandParams:[{unitId:t,subUnitId:n,drawingId:i}],disable:!1}]}};le=We([h.OnLifecycle(h.LifecycleStages.Steady,le),Q(0,j.Inject(j.Injector)),Q(1,E.IDrawingManagerService),Q(2,j.Inject(X.SheetCanvasPopManagerService)),Q(3,F.IRenderManagerService),Q(4,h.IUniverInstanceService),Q(5,h.IContextService),Q(6,j.Inject(k.IUIPartsService))],le);const de={id:"sheet.operation.insert-float-image",type:h.CommandType.OPERATION,handler:(e,t)=>!0},ue={id:"sheet.operation.insert-cell-image",type:h.CommandType.OPERATION,handler:(e,t)=>!0},Se={id:"sheet.command.insert-sheet-image",type:h.CommandType.COMMAND,handler:(e,t)=>{const n=e.get(h.ICommandService),i=e.get(h.IUndoRedoService),r=e.get(m.ISheetDrawingService);if(!t)return!1;const o=t.drawings,a=o.map(S=>S.unitId),s=r.getBatchAddOp(o),{unitId:c,subUnitId:u,undo:l,redo:d,objects:g}=s;return n.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:d,unitId:c,subUnitId:u,objects:g,type:m.DrawingApplyType.INSERT})?(i.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:u,objects:g,type:m.DrawingApplyType.REMOVE}},{id:L.id,params:a}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:u,objects:g,type:m.DrawingApplyType.INSERT}},{id:L.id,params:a}]}),!0):!1}},me={id:"sheet.command.set-sheet-image",type:h.CommandType.COMMAND,handler:(e,t)=>{const n=e.get(h.ICommandService),i=e.get(h.IUndoRedoService),r=e.get(m.ISheetDrawingService);if(!t)return!1;const{drawings:o}=t,a=r.getBatchUpdateOp(o),{unitId:s,subUnitId:c,undo:u,redo:l,objects:d}=a;return n.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:s,subUnitId:c,op:l,objects:d,type:m.DrawingApplyType.UPDATE})?(i.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:c,op:u,objects:d,type:m.DrawingApplyType.UPDATE}},{id:L.id,params:[s]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:c,op:l,objects:d,type:m.DrawingApplyType.UPDATE}},{id:L.id,params:[s]}]}),!0):!1}},Ie={id:"sheet.command.set-drawing-arrange",type:h.CommandType.COMMAND,handler:(e,t)=>{const n=e.get(h.ICommandService),i=e.get(h.IUndoRedoService);if(!t)return!1;const r=e.get(m.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:c}=t,u={unitId:o,subUnitId:a,drawingIds:s};let l;if(c===E.ArrangeTypeEnum.forward?l=r.getForwardDrawingsOp(u):c===E.ArrangeTypeEnum.backward?l=r.getBackwardDrawingOp(u):c===E.ArrangeTypeEnum.front?l=r.getFrontDrawingsOp(u):c===E.ArrangeTypeEnum.back&&(l=r.getBackDrawingsOp(u)),l==null)return!1;const{objects:d,redo:g,undo:p}=l;return n.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:g,unitId:o,subUnitId:a,objects:d,type:m.DrawingApplyType.ARRANGE})?(i.pushUndoRedo({unitID:o,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:o,subUnitId:a,objects:d,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:d,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}};function Ge(e){const t=[];return e.forEach(n=>{const{parent:i,children:r}=n,{unitId:o,subUnitId:a,drawingId:s}=i,c=F.getGroupState(0,0,r.map(d=>d.transform||{})),u=r.map(d=>{const g=d.transform||{left:0,top:0},{unitId:p,subUnitId:S,drawingId:f}=d;return{unitId:p,subUnitId:S,drawingId:f,transform:{...g,left:g.left-c.left,top:g.top-c.top},groupId:s}}),l={unitId:o,subUnitId:a,drawingId:s,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:c};t.push({parent:l,children:u})}),t}function ke(e){const t=[];return e.forEach(n=>{const{parent:i,children:r}=n,{unitId:o,subUnitId:a,drawingId:s,transform:c={width:0,height:0}}=i;if(c==null)return;const u=r.map(d=>{const{transform:g}=d,{unitId:p,subUnitId:S,drawingId:f}=d,_=F.transformObjectOutOfGroup(g||{},c,c.width||0,c.height||0);return{unitId:p,subUnitId:S,drawingId:f,transform:_,groupId:void 0}}),l={unitId:o,subUnitId:a,drawingId:s,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};t.push({parent:l,children:u})}),t}const ye={id:"sheet.command.group-sheet-image",type:h.CommandType.COMMAND,handler:(e,t)=>{const n=e.get(h.ICommandService),i=e.get(h.IUndoRedoService),r=e.get(m.ISheetDrawingService);if(!t)return!1;const o=[];t.forEach(({parent:p,children:S})=>{o.push(p.unitId),S.forEach(f=>{o.push(f.unitId)})});const a=r.getGroupDrawingOp(t),{unitId:s,subUnitId:c,undo:u,redo:l,objects:d}=a;return n.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:l,unitId:s,subUnitId:c,objects:d,type:m.DrawingApplyType.GROUP})?(i.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:c,objects:ke(d),type:m.DrawingApplyType.UNGROUP}},{id:L.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:l,unitId:s,subUnitId:c,objects:d,type:m.DrawingApplyType.GROUP}},{id:L.id,params:o}]}),!0):!1}},Me={id:"sheet.command.ungroup-sheet-image",type:h.CommandType.COMMAND,handler:(e,t)=>{const n=e.get(h.ICommandService),i=e.get(h.IUndoRedoService),r=e.get(m.ISheetDrawingService);if(!t)return!1;const o=[];t.forEach(({parent:p,children:S})=>{o.push(p.unitId),S.forEach(f=>{o.push(f.unitId)})});const a=r.getUngroupDrawingOp(t),{unitId:s,subUnitId:c,undo:u,redo:l,objects:d}=a;return n.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:l,unitId:s,subUnitId:c,objects:d,type:m.DrawingApplyType.UNGROUP})?(i.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:c,objects:Ge(d),type:m.DrawingApplyType.GROUP}},{id:L.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:l,unitId:s,subUnitId:c,objects:d,type:m.DrawingApplyType.UNGROUP}},{id:L.id,params:o}]}),!0):!1}};function x(e,t){const{from:n,to:i}=e,{column:r,columnOffset:o,row:a,rowOffset:s}=n,{column:c,columnOffset:u,row:l,rowOffset:d}=i,g=t.attachRangeWithCoord({startColumn:r,endColumn:r,startRow:a,endRow:a});if(g==null)return;const p=t.attachRangeWithCoord({startColumn:c,endColumn:c,startRow:l,endRow:l});if(p==null)return;const{startX:S,startY:f}=g,{startX:_,startY:R}=p,y=F.precisionTo(S+o,1),I=F.precisionTo(f+s,1);let T=F.precisionTo(_+u-y,1),w=F.precisionTo(R+d-I,1);return g.startX===p.endX&&(T=0),g.startY===p.endY&&(w=0),{left:y,top:I,width:T,height:w}}function W(e,t){const{left:n=0,top:i=0,width:r=0,height:o=0}=e,a=t.getSelectionCellByPosition(n,i);if(a==null)return;const s={column:a.actualColumn,columnOffset:F.precisionTo(n-a.startX,1),row:a.actualRow,rowOffset:F.precisionTo(i-a.startY,1)},c=t.getSelectionCellByPosition(n+r,i+o);if(c==null)return;const u={column:c.actualColumn,columnOffset:F.precisionTo(n+r-c.startX,1),row:c.actualRow,rowOffset:F.precisionTo(i+o-c.startY,1)};return{from:s,to:u}}var Be=(e,t,n,i)=>{for(var r=t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(r=a(r)||r);return r},Y=(e,t)=>(n,i)=>t(n,i,e);let pe=class extends h.Disposable{constructor(e,t,n,i,r,o,a,s,c,u,l){super(),this._commandService=e,this._univerInstanceService=t,this._selectionManagerService=n,this._selectionRenderService=i,this._imageIoService=r,this._sheetDrawingService=o,this._drawingManagerService=a,this._contextService=s,this._messageService=c,this._localeService=u,this._renderManagerService=l,this._init()}_init(){this._initCommandListeners(),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async e=>{if(e.id===ue.id||e.id===de.id){const t=e.params;if(t.files==null)return;const n=t.files.length;if(n>E.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(E.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(n),e.id===ue.id?t.files.forEach(async i=>{await this._insertCellImage(i)}):t.files.forEach(async i=>{await this._insertFloatImage(i)})}}))}async _insertCellImage(e){}async _insertFloatImage(e){let t;try{t=await this._imageIoService.saveImage(e)}catch(y){const I=y.message;I===E.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(E.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):I===E.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):I===E.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(t==null)return;const n=this._getUnitInfo();if(n==null)return;const{unitId:i,subUnitId:r}=n,{imageId:o,imageSourceType:a,source:s,base64Cache:c}=t,{width:u,height:l,image:d}=await E.getImageSize(c||""),g=this._renderManagerService.getRenderById(i);if(g==null)return;const{width:p,height:S}=g.scene;this._imageIoService.addImageSourceCache(s,a,d);let f=1;if(u>E.DRAWING_IMAGE_WIDTH_LIMIT||l>E.DRAWING_IMAGE_HEIGHT_LIMIT){const y=E.DRAWING_IMAGE_WIDTH_LIMIT/u,I=E.DRAWING_IMAGE_HEIGHT_LIMIT/l;f=Math.max(y,I)}const _=this._getImagePosition(u*f,l*f,p,S);if(_==null)return;const R={unitId:i,subUnitId:r,drawingId:o,drawingType:E.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:s,transform:x(_,this._selectionRenderService),sheetTransform:_};this._commandService.executeCommand(Se.id,{unitId:i,drawings:[R]})}_getUnitInfo(){const e=this._univerInstanceService.getCurrentUnitForType(h.UniverInstanceType.UNIVER_SHEET);if(e==null)return;const t=e.getActiveSheet();if(t==null)return;const n=e.getUnitId(),i=t.getSheetId();return{unitId:n,subUnitId:i}}_getImagePosition(e,t,n,i){const r=this._selectionManagerService.getSelections();let o={startRow:0,endRow:0,startColumn:0,endColumn:0};r&&r.length>0&&(o=r[r.length-1].range);const a=this._selectionRenderService.attachRangeWithCoord(o);if(a==null)return;let{startColumn:s,startRow:c,startX:u,startY:l}=a,d=!1;if(u+e>n&&(u=n-e,u<0&&(u=0,e=n),d=!0),l+t>i&&(l=i-t,l<0&&(l=0,t=i),d=!0),d){const f=this._selectionRenderService.getSelectionCellByPosition(u,l);if(f==null)return;u=f.startX,l=f.startY,s=f.actualColumn,c=f.actualRow}const g={column:s,columnOffset:0,row:c,rowOffset:0},p=this._selectionRenderService.getSelectionCellByPosition(u+e,l+t);if(p==null)return;const S={column:p.actualColumn,columnOffset:u+e-p.startX,row:p.actualRow,rowOffset:l+t-p.startY};return{from:g,to:S}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{const{unitId:t,subUnitId:n,drawingIds:i,arrangeType:r}=e;this._commandService.executeCommand(Ie.id,{unitId:t,subUnitId:n,drawingIds:i,arrangeType:r})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{const t=[];e.length!==0&&(e.forEach(n=>{const{unitId:i,subUnitId:r,drawingId:o,drawingType:a,transform:s}=n;if(s==null)return;const c=this._sheetDrawingService.getDrawingByParam({unitId:i,subUnitId:r,drawingId:o});if(c==null)return;const u=W({...c.transform,...s},this._selectionRenderService);if(u==null)return;const l={...n,transform:{...c.transform,...s,...x(u,this._selectionRenderService)},sheetTransform:{...u}};t.push(l)}),t.length>0&&this._commandService.executeCommand(me.id,{unitId:e[0].unitId,drawings:t}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{this._commandService.executeCommand(ye.id,e);const{unitId:t,subUnitId:n,drawingId:i}=e[0].parent;this._drawingManagerService.focusDrawing([{unitId:t,subUnitId:n,drawingId:i}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{this._commandService.executeCommand(Me.id,e)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}};pe=Be([h.OnLifecycle(h.LifecycleStages.Rendered,pe),Y(0,h.ICommandService),Y(1,h.IUniverInstanceService),Y(2,j.Inject(C.SelectionManagerService)),Y(3,X.ISelectionRenderService),Y(4,E.IImageIoService),Y(5,m.ISheetDrawingService),Y(6,E.IDrawingManagerService),Y(7,h.IContextService),Y(8,k.IMessageService),Y(9,j.Inject(h.LocaleService)),Y(10,F.IRenderManagerService)],pe);var H=function(){return H=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++){t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},H.apply(this,arguments)},Fe=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]]);return n},Te=b.forwardRef(function(e,t){var n=e.icon,i=e.id,r=e.className,o=e.extend,a=Fe(e,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(i," ").concat(r||"").trim(),c=b.useRef("_".concat(He()));return Re(n,"".concat(i),{defIds:n.defIds,idSuffix:c.current},H({ref:t,className:s},a),o)});function Re(e,t,n,i,r){return b.createElement(e.tag,H(H({key:t},xe(e,n,r)),i),(Ve(e,n).children||[]).map(function(o,a){return Re(o,"".concat(t,"-").concat(e.tag,"-").concat(a),n,void 0,r)}))}function xe(e,t,n){var i=H({},e.attrs);n!=null&&n.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=n.colorChannel1);var r=t.defIds;return!r||r.length===0||(e.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+t.idSuffix),Object.entries(i).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(i[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),i}function Ve(e,t){var n,i=t.defIds;return!i||i.length===0?e:e.tag==="defs"&&(!((n=e.children)===null||n===void 0)&&n.length)?H(H({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&i&&i.indexOf(r.attrs.id)>-1?H(H({},r),{attrs:H(H({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):e}function He(){return Math.random().toString(36).substring(2,8)}Te.displayName="UniverIcon";var Ye={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"}}]},De=b.forwardRef(function(e,t){return b.createElement(Te,Object.assign({},e,{id:"add-image-single",ref:t,icon:Ye}))});De.displayName="AddImageSingle";const Ae={uploadFileMenu:"univer-upload-file-menu",uploadFileMenuInput:"univer-upload-file-menu-input"},Oe="COMPONENT_UPLOAD_FILE_MENU";var ge=(e=>(e[e.cellImage=0]="cellImage",e[e.floatImage=1]="floatImage",e))(ge||{});const Xe=e=>{const{type:t}=e,n=$.useDependency(h.ICommandService),i=b.useRef(null),r=()=>{var s;(s=i.current)==null||s.click()},o=E.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(s=>`.${s.replace("image/","")}`).join(","),a=s=>{const c=s.target.files;if(c==null)return;const u=Array.from(c);t===ge.floatImage?n.executeCommand(de.id,{files:u}):t===ge.cellImage&&n.executeCommand(ue.id,{files:u}),i.current&&(i.current.value="")};return b.createElement("div",{onClick:r,className:Ae.uploadFileMenu},b.createElement("input",{type:"file",className:Ae.uploadFileMenuInput,ref:i,onChange:a,accept:o,multiple:!0}))},be="addition-and-subtraction-single",Ee="sheet.menu.image";function $e(e){return{id:Ee,type:k.MenuItemType.SUBITEMS,positions:[k.MenuPosition.TOOLBAR_START],group:k.MenuGroup.TOOLBAR_FORMULAS_INSERT,icon:be,tooltip:"sheetImage.title",hidden$:k.getMenuHiddenObservable(e,h.UniverInstanceType.UNIVER_SHEET)}}function ze(e){return{id:de.id,title:"sheetImage.upload.float",type:k.MenuItemType.SELECTOR,label:{name:Oe,props:{type:ge.floatImage}},positions:[Ee],hidden$:k.getMenuHiddenObservable(e,h.UniverInstanceType.UNIVER_SHEET)}}const J={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",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"},Ke=e=>{var I;const t=$.useDependency(h.ICommandService),n=$.useDependency(h.LocaleService),i=$.useDependency(E.IDrawingManagerService),r=$.useDependency(F.IRenderManagerService),{drawings:o}=e,a=o[0];if(a==null)return;const{unitId:s}=a,c=r.getRenderById(s),u=c==null?void 0:c.scene;if(u==null)return;const l=u.getTransformerByCreate(),[d,g]=b.useState(!0),p=(I=a.anchorType)!=null?I:m.SheetDrawingAnchorType.Position,[S,f]=b.useState(p);function _(T,w){const O=[];return T.forEach(v=>{const{oKey:N}=v,D=w.getDrawingOKey(N);if(D==null)return O.push(null),!0;const{unitId:B,subUnitId:P,drawingId:U,drawingType:M,anchorType:G,sheetTransform:z}=D;O.push({unitId:B,subUnitId:P,drawingId:U,anchorType:G,sheetTransform:z,drawingType:M})}),O}b.useEffect(()=>{const T=l.onClearControlObservable.add(O=>{O===!0&&g(!1)}),w=l.onChangeStartObservable.add(O=>{var D;const{objects:v}=O,N=_(v,i);if(N.length===0)g(!1);else if(N.length>=1){g(!0);const B=((D=N[0])==null?void 0:D.anchorType)||m.SheetDrawingAnchorType.Position;f(B)}});return()=>{w==null||w.dispose(),T==null||T.dispose()}},[]);function R(T){f(T);const w=i.getFocusDrawings();if(w.length===0)return;const O=w.map(v=>({unitId:v.unitId,subUnitId:v.subUnitId,drawingId:v.drawingId,anchorType:T}));t.executeCommand(me.id,{unitId:w[0].unitId,drawings:O})}const y=T=>T?"block":"none";return b.createElement("div",{className:se(J.imageCommonPanelGrid,J.imageCommonPanelBorder),style:{display:y(d)}},b.createElement("div",{className:J.imageCommonPanelRow},b.createElement("div",{className:se(J.imageCommonPanelColumn,J.imageCommonPanelTitle)},b.createElement("div",null,n.t("drawing-anchor.title")))),b.createElement("div",{className:se(J.imageCommonPanelRow)},b.createElement("div",{className:se(J.imageCommonPanelColumn)},b.createElement(q.RadioGroup,{value:S,onChange:R,direction:"vertical"},b.createElement(q.Radio,{value:m.SheetDrawingAnchorType.Both},n.t("drawing-anchor.both")),b.createElement(q.Radio,{value:m.SheetDrawingAnchorType.Position},n.t("drawing-anchor.position")),b.createElement(q.Radio,{value:m.SheetDrawingAnchorType.None},n.t("drawing-anchor.none"))))))},qe=()=>{const e=$.useDependency(E.IDrawingManagerService),t=e.getFocusDrawings();if(t==null||t.length===0)return;const[n,i]=b.useState(t);return b.useEffect(()=>{const r=e.focus$.subscribe(o=>{i(o)});return()=>{r.unsubscribe()}},[]),b.createElement("div",{className:J.imageCommonPanel},b.createElement(ee.DrawingCommonPanel,{drawings:n}),b.createElement(Ke,{drawings:n}))},ie={id:"sheet.command.move-drawing",type:h.CommandType.COMMAND,handler:(e,t)=>{const n=e.get(h.ICommandService),i=e.get(m.ISheetDrawingService),r=e.get(X.ISelectionRenderService),{direction:o}=t,a=i.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,c=a.map(l=>{const{transform:d}=l;if(d==null)return null;const g={...d},{left:p=0,top:S=0}=d;return o===h.Direction.UP?g.top=S-1:o===h.Direction.DOWN?g.top=S+1:o===h.Direction.LEFT?g.left=p-1:o===h.Direction.RIGHT&&(g.left=p+1),{...l,transform:g,sheetTransform:W(g,r)}}).filter(l=>l!=null);return n.syncExecuteCommand(me.id,{unitId:s,drawings:c})?(n.syncExecuteCommand(L.id,[s]),!0):!1}},Ue={id:"sheet.command.delete-drawing",type:h.CommandType.COMMAND,handler:e=>{const t=e.get(h.ICommandService),i=e.get(m.ISheetDrawingService).getFocusDrawings();if(i.length===0)return!1;const r=i[0].unitId,o=i.map(a=>{const{unitId:s,subUnitId:c,drawingId:u,drawingType:l}=a;return{unitId:s,subUnitId:c,drawingId:u,drawingType:l}});return t.executeCommand(fe.id,{unitId:r,drawings:o})}};function re(e){return!e.getContextValue(h.FOCUSING_FORMULA_EDITOR)&&!e.getContextValue(h.EDITOR_ACTIVATED)&&e.getContextValue(h.FOCUSING_COMMON_DRAWINGS)}const Je={id:ie.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_DOWN,priority:100,preconditions:re,staticParameters:{direction:h.Direction.DOWN}},Ze={id:ie.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_UP,priority:100,preconditions:re,staticParameters:{direction:h.Direction.UP}},Qe={id:ie.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_LEFT,priority:100,preconditions:re,staticParameters:{direction:h.Direction.LEFT}},en={id:ie.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_RIGHT,priority:100,preconditions:re,staticParameters:{direction:h.Direction.RIGHT}},nn={id:Ue.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:re,binding:k.KeyCode.DELETE,mac:k.KeyCode.BACKSPACE};var tn=(e,t,n,i)=>{for(var r=t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(r=a(r)||r);return r},oe=(e,t)=>(n,i)=>t(n,i,e);const rn={};let ae=class extends h.Disposable{constructor(e,t,n,i,r,o){super(),this._config=e,this._injector=t,this._componentManager=n,this._menuService=i,this._commandService=r,this._shortcutService=o,this._init()}_initCustomComponents(){const e=this._componentManager;this.disposeWithMe(e.register(be,De)),this.disposeWithMe(e.register(Oe,Xe)),this.disposeWithMe(e.register(we,qe))}_initMenus(){const{menu:e={}}=this._config;[$e,ze].forEach(t=>{this._menuService.addMenuItem(t(this._injector),e)})}_initCommands(){[de,ue,Se,fe,me,_e,L,Ce,ye,Me,ie,Ue,Ie].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initShortcuts(){[Je,Ze,Qe,en,nn].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};ae=tn([h.OnLifecycle(h.LifecycleStages.Rendered,ae),oe(1,j.Inject(j.Injector)),oe(2,j.Inject(k.ComponentManager)),oe(3,k.IMenuService),oe(4,h.ICommandService),oe(5,k.IShortcutService)],ae);var on=(e,t,n,i)=>{for(var r=t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(r=a(r)||r);return r},ne=(e,t)=>(n,i)=>t(n,i,e);const an=[C.InsertRowCommand.id,C.InsertColCommand.id,C.RemoveRowCommand.id,C.RemoveColCommand.id,C.DeleteRangeMoveLeftCommand.id,C.DeleteRangeMoveUpCommand.id,C.InsertRangeMoveDownCommand.id,C.InsertRangeMoveRightCommand.id,C.DeltaRowHeightCommand.id,C.SetRowHeightCommand.id,C.DeltaColumnWidthCommand.id,C.SetColWidthCommand.id,C.SetRowHiddenCommand.id,C.SetSpecificRowsVisibleCommand.id,C.SetSpecificColsVisibleCommand.id,C.SetColHiddenCommand.id],sn=[C.SetRowVisibleMutation.id,C.SetRowHiddenMutation.id,C.SetColVisibleMutation.id,C.SetColHiddenMutation.id,C.SetWorksheetRowHeightMutation.id,C.SetWorksheetColWidthMutation.id];let he=class extends h.Disposable{constructor(e,t,n,i,r,o){super(),this._commandService=e,this._sheetInterceptorService=t,this._sheetDrawingService=n,this._drawingManagerService=i,this._selectionRenderService=r,this._univerInstanceService=o,this._init()}_init(){this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(!an.includes(e.id))return{redos:[],undos:[]};if(e.params==null)return{redos:[],undos:[]};const t=e.id;if(t===C.InsertRowCommand.id)return this._moveRowInterceptor(e.params,"insert");if(t===C.InsertColCommand.id)return this._moveColInterceptor(e.params,"insert");if(t===C.RemoveRowCommand.id)return this._moveRowInterceptor(e.params,"remove");if(t===C.RemoveColCommand.id)return this._moveColInterceptor(e.params,"remove");if(t===C.DeleteRangeMoveLeftCommand.id){const{range:n}=e.params;return this._getRangeMoveUndo(n,0)}else if(t===C.DeleteRangeMoveUpCommand.id){const{range:n}=e.params;return this._getRangeMoveUndo(n,1)}else if(t===C.InsertRangeMoveDownCommand.id){const{range:n}=e.params;return this._getRangeMoveUndo(n,2)}else if(t===C.InsertRangeMoveRightCommand.id){const{range:n}=e.params;return this._getRangeMoveUndo(n,3)}else if(t===C.SetRowHiddenCommand.id||t===C.SetSpecificRowsVisibleCommand.id){const n=e.params,{unitId:i,subUnitId:r,ranges:o}=n;return this._getDrawingUndoForRowVisible(i,r,o)}else if(t===C.SetSpecificColsVisibleCommand.id||t===C.SetColHiddenCommand.id){const n=e.params,{unitId:i,subUnitId:r,ranges:o}=n;return this._getDrawingUndoForColVisible(i,r,o)}else if(t===C.DeltaRowHeightCommand.id||t===C.SetRowHeightCommand.id||t===C.DeltaColumnWidthCommand.id||t===C.SetColWidthCommand.id){const n=e.params,{unitId:i,subUnitId:r,ranges:o}=n,a=t===C.DeltaRowHeightCommand.id||t===C.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(i,r,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(e,t){const n=C.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const i=n.unitId,r=n.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(i,r),c=[],u=[];if(Object.keys(s).forEach(l=>{const d=s[l],{updateDrawings:g,deleteDrawings:p}=this._getUpdateOrDeleteDrawings(e,t,d);c.push(...g),u.push(...p)}),c.length===0&&u.length===0)return{redos:[],undos:[]};if(c.length>0){const l=this._sheetDrawingService.getBatchUpdateOp(c),{undo:d,redo:g,objects:p}=l;o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:g,objects:p,type:m.DrawingApplyType.UPDATE}}),a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:d,objects:p,type:m.DrawingApplyType.UPDATE}})}if(u.length>0){const l=this._sheetDrawingService.getBatchRemoveOp(u),d=l.undo,g=l.redo,p=l.objects;o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:g,objects:p,type:m.DrawingApplyType.REMOVE}}),a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:d,objects:p,type:m.DrawingApplyType.INSERT}})}return o.push({id:L.id,params:[i]}),a.push({id:L.id,params:[i]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(e,t,n){const i=[],r=[],{sheetTransform:o,anchorType:a=m.SheetDrawingAnchorType.Position,transform:s,unitId:c,subUnitId:u,drawingId:l}=n,{from:d,to:g}=o,{row:p,column:S}=d,{row:f,column:_}=g;if(o==null||s==null)return{updateDrawings:i,deleteDrawings:r};const{startRow:R,endRow:y,startColumn:I,endColumn:T}=e;let w=null,O=null;if(t===0&&p>=R&&f<=y)if(S>=I&&_<=T)r.push({unitId:c,subUnitId:u,drawingId:l});else{const v=this._shrinkCol(o,s,I,T,a);w=v==null?void 0:v.newSheetTransform,O=v==null?void 0:v.newTransform}else if(t===1&&S>=I&&_<=T)if(p>=R&&f<=y)r.push({unitId:c,subUnitId:u,drawingId:l});else{const v=this._shrinkRow(o,s,R,y,a);w=v==null?void 0:v.newSheetTransform,O=v==null?void 0:v.newTransform}else if(t===2){const v=this._expandRow(o,s,R,y,a);w=v==null?void 0:v.newSheetTransform,O=v==null?void 0:v.newTransform}else if(t===3){const v=this._expandCol(o,s,I,T,a);w=v==null?void 0:v.newSheetTransform,O=v==null?void 0:v.newTransform}if(w!=null&&O!=null){const v=x(w,this._selectionRenderService);i.push({...n,sheetTransform:w,transform:v})}return{updateDrawings:i,deleteDrawings:r}}_remainDrawingSize(e,t,n){const i=W({...e},this._selectionRenderService);i!=null&&t.push({...n,sheetTransform:i})}_getDrawingUndoForColVisible(e,t,n){const i=this._drawingManagerService.getDrawingData(e,t),r=[],o=[];if(Object.keys(i).forEach(l=>{const d=i[l],{sheetTransform:g,transform:p,anchorType:S=m.SheetDrawingAnchorType.Position}=d;if(S===m.SheetDrawingAnchorType.None)this._remainDrawingSize(p,r,d);else{const{from:f,to:_}=g,{row:R,column:y}=f,{row:I,column:T}=_;for(let w=0;w<n.length;w++){const O=n[w],{startRow:v,endRow:N,startColumn:D,endColumn:B}=O;if(T<D)continue;if(S===m.SheetDrawingAnchorType.Position){let M=null,G=null;if(y>=D&&y<=B){const z=this._selectionRenderService.attachRangeWithCoord({startColumn:y,endColumn:B,startRow:f.row,endRow:_.row});if(z==null)return;G={...p,left:z.startX}}if(G!=null&&(M=W(G,this._selectionRenderService),M!=null&&G!=null)){r.push({...d,sheetTransform:M,transform:G});break}this._remainDrawingSize(p,r,d);continue}if(y>=D&&T<=B)continue;let P=null,U=null;if(y>=D&&y<=B){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:y,endColumn:B,startRow:f.row,endRow:_.row});if(M==null)return;U={...p,left:(M==null?void 0:M.startX)||0,width:((p==null?void 0:p.width)||0)-M.endX+M.startX}}else if(T>=D&&T<=B){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:D,endColumn:T,startRow:f.row,endRow:_.row});if(M==null)return;U={...p,left:M.startX-((p==null?void 0:p.width)||0)}}else{const M=this._selectionRenderService.attachRangeWithCoord({startColumn:D,endColumn:B,startRow:f.row,endRow:_.row});if(M==null)return;if(U={...p,width:((p==null?void 0:p.width)||0)-M.endX+M.startX},P=W(U,this._selectionRenderService),P!=null&&U!=null){o.push({...d,sheetTransform:P,transform:U});break}}if(U!=null&&(P=W(U,this._selectionRenderService)),U!=null&&P!=null){r.push({...d,sheetTransform:P,transform:U});break}else this._remainDrawingSize(p,r,d)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(e,t,r),c=[],u=[];if(o.length>0){const{redos:l,undos:d}=this._createUndoAndRedoMutation(e,t,o);c.push(...l),u.push(...d)}return{redos:a,undos:s,preRedos:c,preUndos:u}}_createUndoAndRedoMutation(e,t,n){const i=this._sheetDrawingService.getBatchUpdateOp(n),{undo:r,redo:o,objects:a}=i,s=[{id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:o,objects:a,type:m.DrawingApplyType.UPDATE}},{id:L.id,params:[e]}],c=[{id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:r,objects:a,type:m.DrawingApplyType.UPDATE}},{id:L.id,params:[e]}];return{redos:s,undos:c}}_getDrawingUndoForRowVisible(e,t,n){const i=this._drawingManagerService.getDrawingData(e,t),r=[],o=[];if(Object.keys(i).forEach(l=>{const d=i[l],{sheetTransform:g,transform:p,anchorType:S=m.SheetDrawingAnchorType.Position}=d;if(S===m.SheetDrawingAnchorType.None)this._remainDrawingSize(p,r,d);else{const{from:f,to:_}=g,{row:R,column:y}=f,{row:I,column:T}=_;for(let w=0;w<n.length;w++){const O=n[w],{startRow:v,endRow:N,startColumn:D,endColumn:B}=O;if(I<v)continue;if(S===m.SheetDrawingAnchorType.Position){let M=null,G=null;if(R>=v&&R<=N){const z=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:R,endRow:N});if(z==null)return;G={...p,top:z.startY}}if(G!=null&&(M=W(G,this._selectionRenderService),M!=null&&G!=null)){r.push({...d,sheetTransform:M,transform:G});break}this._remainDrawingSize(p,r,d);continue}if(R>=v&&I<=N)continue;let P=null,U=null;if(R>=v&&R<=N){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:R,endRow:N});if(M==null)return;U={...p,top:(M==null?void 0:M.startY)||0,height:((p==null?void 0:p.height)||0)-M.endY+M.startY}}else if(I>=v&&I<=N){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:v,endRow:I});if(M==null)return;U={...p,top:M.startY-((p==null?void 0:p.height)||0)}}else{const M=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:v,endRow:N});if(M==null)return;if(U={...p,height:((p==null?void 0:p.height)||0)-M.endY+M.startY},P=W(U,this._selectionRenderService),P!=null&&U!=null){o.push({...d,sheetTransform:P,transform:U});break}}if(U!=null&&(P=W(U,this._selectionRenderService)),U!=null&&P!=null){r.push({...d,sheetTransform:P,transform:U});break}else this._remainDrawingSize(p,r,d)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(e,t,r),c=[],u=[];if(o.length>0){const{redos:l,undos:d}=this._createUndoAndRedoMutation(e,t,o);c.push(...l),u.push(...d)}return{redos:a,undos:s,preRedos:c,preUndos:u}}_getDrawingUndoForRowAndColSize(e,t,n,i){const r=this._drawingManagerService.getDrawingData(e,t),o=[];return Object.keys(r).forEach(a=>{const s=r[a],{sheetTransform:c,transform:u,anchorType:l=m.SheetDrawingAnchorType.Position}=s;if(l===m.SheetDrawingAnchorType.None)this._remainDrawingSize(u,o,s);else{const{from:d,to:g}=c,{row:p,column:S}=d,{row:f,column:_}=g;for(let R=0;R<n.length;R++){const y=n[R],{startRow:I,endRow:T,startColumn:w,endColumn:O}=y;if(f<I||_<w)continue;if(l===m.SheetDrawingAnchorType.Position&&(p<=I&&f>=T||S<=w&&_>=O)){this._remainDrawingSize(u,o,s);continue}const v=x({...c},this._selectionRenderService);if(v!=null){o.push({...s,transform:v});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(e,t,o)}_getUnitIdAndSubUnitId(e,t){let n,i;if(t==="insert")n=e.unitId,i=e.subUnitId;else{const r=C.getSheetCommandTarget(this._univerInstanceService);if(r==null)return;n=r.unitId,i=r.subUnitId}return{unitId:n,subUnitId:i}}_moveRowInterceptor(e,t){const n=this._getUnitIdAndSubUnitId(e,t);if(n==null)return{redos:[],undos:[]};const{unitId:i,subUnitId:r}=n,{range:o}=e,a=o.startRow,s=o.endRow,c=[],u=[],l=this._sheetDrawingService.getDrawingData(i,r),d=[],g=[];if(Object.keys(l).forEach(p=>{const S=l[p],{sheetTransform:f,transform:_,anchorType:R=m.SheetDrawingAnchorType.Position}=S;if(f==null||_==null)return;let y,I;if(t==="insert"){const w=this._expandRow(f,_,a,s,R);y=w==null?void 0:w.newSheetTransform,I=w==null?void 0:w.newTransform}else{const{from:w,to:O}=f,{row:v}=w,{row:N}=O;if(v>=a&&N<=s)g.push({unitId:i,subUnitId:r,drawingId:p});else{const D=this._shrinkRow(f,_,a,s,R);y=D==null?void 0:D.newSheetTransform,I=D==null?void 0:D.newTransform}}if(!y||!I)return;const T={unitId:i,subUnitId:r,drawingId:p,transform:I,sheetTransform:y};d.push(T)}),d.length===0&&g.length===0)return{redos:[],undos:[]};if(d.length>0){const p=this._sheetDrawingService.getBatchUpdateOp(d),{undo:S,redo:f,objects:_}=p;c.push({id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:f,objects:_,type:m.DrawingApplyType.UPDATE}}),u.push({id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:S,objects:_,type:m.DrawingApplyType.UPDATE}})}if(g.length>0){const p=this._sheetDrawingService.getBatchRemoveOp(g),S=p.undo,f=p.redo,_=p.objects;c.push({id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:f,objects:_,type:m.DrawingApplyType.REMOVE}}),u.push({id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:S,objects:_,type:m.DrawingApplyType.INSERT}})}return c.push({id:L.id,params:[i]}),u.push({id:L.id,params:[i]}),{redos:c,undos:u}}_moveColInterceptor(e,t){const n=this._getUnitIdAndSubUnitId(e,t);if(n==null)return{redos:[],undos:[]};const{unitId:i,subUnitId:r}=n,{range:o}=e,a=o.startColumn,s=o.endColumn,c=[],u=[],l=this._sheetDrawingService.getDrawingData(i,r),d=[],g=[];if(Object.keys(l).forEach(p=>{const S=l[p],{sheetTransform:f,transform:_,anchorType:R=m.SheetDrawingAnchorType.Position}=S;if(f==null||_==null)return;let y,I;if(t==="insert"){const w=this._expandCol(f,_,a,s,R);y=w==null?void 0:w.newSheetTransform,I=w==null?void 0:w.newTransform}else{const{from:w,to:O}=f,{column:v}=w,{column:N}=O;if(v>=a&&N<=s)g.push({unitId:i,subUnitId:r,drawingId:p});else{const D=this._shrinkCol(f,_,a,s,R);y=D==null?void 0:D.newSheetTransform,I=D==null?void 0:D.newTransform}}if(!y||!I)return;const T={unitId:i,subUnitId:r,drawingId:p,transform:I,sheetTransform:y};d.push(T)}),d.length===0&&g.length===0)return{redos:[],undos:[]};if(d.length>0){const p=this._sheetDrawingService.getBatchUpdateOp(d),{undo:S,redo:f,objects:_}=p;c.push({id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:f,objects:_,type:m.DrawingApplyType.UPDATE}}),u.push({id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:S,objects:_,type:m.DrawingApplyType.UPDATE}})}if(g.length>0){const p=this._sheetDrawingService.getBatchRemoveOp(g),S=p.undo,f=p.redo,_=p.objects;c.push({id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:f,objects:_,type:m.DrawingApplyType.REMOVE}}),u.push({id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:S,objects:_,type:m.DrawingApplyType.INSERT}})}return c.push({id:L.id,params:[i]}),u.push({id:L.id,params:[i]}),{redos:c,undos:u}}_expandCol(e,t,n,i,r=m.SheetDrawingAnchorType.Position){const o=i-n+1,{from:a,to:s}=e,{column:c}=a,{column:u}=s;if(r===m.SheetDrawingAnchorType.None)return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};let l=null,d=null;if(c>=n){const g=this._selectionRenderService.attachRangeWithCoord({startColumn:n,endColumn:i,startRow:a.row,endRow:s.row});if(g==null)return;d={...t,left:(t.left||0)+g.endX-g.startX},l=W(d,this._selectionRenderService)}else if(u>=i)if(r===m.SheetDrawingAnchorType.Both)l={from:{...a},to:{...s,column:u+o}},d=x(l,this._selectionRenderService);else return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};return l!=null&&d!=null?{newSheetTransform:l,newTransform:d}:null}_shrinkCol(e,t,n,i,r=m.SheetDrawingAnchorType.Position){const o=i-n+1,{from:a,to:s}=e,{column:c}=a,{column:u}=s;if(r===m.SheetDrawingAnchorType.None)return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};let l=null,d=null;if(c>i)l={from:{...a,column:c-o},to:{...s,column:u-o}},d=x(l,this._selectionRenderService);else{if(c>=n&&u<=i)return null;if(c<n&&u>i)if(r===m.SheetDrawingAnchorType.Both)l={from:{...a},to:{...s,column:u-o}},d=x(l,this._selectionRenderService);else return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};else if(c>=n&&c<=i){if(c===n)d={...t,left:(t.left||0)-e.from.columnOffset};else{const g=this._selectionRenderService.attachRangeWithCoord({startColumn:n,endColumn:c-1,startRow:a.row,endRow:s.row});if(g==null)return;d={...t,left:(t.left||0)-g.endX+g.startX-e.from.columnOffset}}l=W(d,this._selectionRenderService)}else if(u>=n&&u<=i&&r===m.SheetDrawingAnchorType.Both){const g=this._selectionRenderService.attachRangeWithCoord({startColumn:n-1,endColumn:n-1,startRow:a.row,endRow:s.row});if(g==null)return;l={from:{...a},to:{...s,column:n-1,columnOffset:g.endX-g.startX}},d=x(l,this._selectionRenderService)}}return l!=null&&d!=null?{newSheetTransform:l,newTransform:d}:null}_expandRow(e,t,n,i,r=m.SheetDrawingAnchorType.Position){const o=i-n+1,{from:a,to:s}=e,{row:c}=a,{row:u}=s;if(r===m.SheetDrawingAnchorType.None)return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};let l=null,d=null;if(c>=n){const g=this._selectionRenderService.attachRangeWithCoord({startRow:n,endRow:i,startColumn:a.column,endColumn:s.column});if(g==null)return;d={...t,top:(t.top||0)+g.endY-g.startY},l=W(d,this._selectionRenderService)}else if(u>=i)if(r===m.SheetDrawingAnchorType.Both)l={from:{...a},to:{...s,row:u+o}},d=x(l,this._selectionRenderService);else return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};return l!=null&&d!=null?{newSheetTransform:l,newTransform:d}:null}_shrinkRow(e,t,n,i,r=m.SheetDrawingAnchorType.Position){const o=i-n+1,{from:a,to:s}=e,{row:c}=a,{row:u}=s;if(r===m.SheetDrawingAnchorType.None)return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};let l=null,d=null;if(c>i)l={from:{...a,row:c-o},to:{...s,row:u-o}},d=x(l,this._selectionRenderService);else{if(c>=n&&u<=i)return null;if(c<n&&u>i)if(r===m.SheetDrawingAnchorType.Both)l={from:{...a},to:{...s,row:u-o}},d=x(l,this._selectionRenderService);else return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};else if(c>=n&&c<=i){if(c===n)d={...t,top:(t.top||0)-e.from.rowOffset};else{const g=this._selectionRenderService.attachRangeWithCoord({startRow:n,endRow:c-1,startColumn:a.column,endColumn:s.column});if(g==null)return;d={...t,top:(t.top||0)-g.endY+g.startY-e.from.rowOffset}}l=W(d,this._selectionRenderService)}else if(u>=n&&u<=i&&r===m.SheetDrawingAnchorType.Both){const g=this._selectionRenderService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:n-1,endRow:n-1});if(g==null)return;l={from:{...a},to:{...s,row:n-1,rowOffset:g.endY-g.startY}},d=x(l,this._selectionRenderService)}}return l!=null&&d!=null?{newSheetTransform:l,newTransform:d}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===C.SetWorksheetActiveOperation.id){const t=e.params,{unitId:n,subUnitId:i}=t,r=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(r).forEach(s=>{const c=r[s];Object.keys(c).forEach(u=>{const l=c[u].data;l!=null&&Object.keys(l).forEach(d=>{s===n&&u===i?o.push(l[d]):a.push(l[d])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)}}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{sn.includes(e.id)&&requestIdleCallback(()=>{const t=e.params,{unitId:n,subUnitId:i,ranges:r}=t;this._refreshDrawingTransform(n,i,r)})}))}_refreshDrawingTransform(e,t,n){const i=this._drawingManagerService.getDrawingData(e,t),r=[];Object.keys(i).forEach(o=>{const a=i[o],{sheetTransform:s,anchorType:c=m.SheetDrawingAnchorType.Position}=a;if(c===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:l}=s,{row:d,column:g}=u,{row:p,column:S}=l;for(let f=0;f<n.length;f++){const _=n[f],{startRow:R,endRow:y,startColumn:I,endColumn:T}=_;if(h.Rectangle.intersects({startRow:R,endRow:y,startColumn:I,endColumn:T},{startRow:d,endRow:p,startColumn:g,endColumn:S})||d>y||g>T){r.push({...a,transform:x(s,this._selectionRenderService)});break}}}),r.length!==0&&(this._drawingManagerService.refreshTransform(r),this._commandService.syncExecuteCommand(L.id,[e]))}};he=on([h.OnLifecycle(h.LifecycleStages.Rendered,he),ne(0,h.ICommandService),ne(1,j.Inject(C.SheetInterceptorService)),ne(2,m.ISheetDrawingService),ne(3,E.IDrawingManagerService),ne(4,X.ISelectionRenderService),ne(5,h.IUniverInstanceService)],he);var cn=(e,t,n,i)=>{for(var r=t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(r=a(r)||r);return r},Z=(e,t)=>(n,i)=>t(n,i,e);function ln(e,t,n,i){const{scaleX:r,scaleY:o}=t.getAncestorScale(),a=t.getViewport(X.VIEWPORT_KEY.VIEW_MAIN),s={left:!0,top:!0};if(!a)return{...e,absolute:s};const{left:c,right:u,top:l,bottom:d}=e,g=i.getFreeze(),{startColumn:p,startRow:S,xSplit:f,ySplit:_}=g,R=n.getNoMergeCellPositionByIndexWithNoHeader(S-_,p-f),y=n.getNoMergeCellPositionByIndexWithNoHeader(S,p),{rowHeaderWidth:I,columnHeaderHeight:T}=n,w=y.startX-R.startX,O=y.startY-R.startY,{top:v,left:N,viewportScrollX:D,viewportScrollY:B}=a;let P,U;c<N?(s.left=!0,P=(w+I+(c-N))*r,U=Math.max(Math.min((w+I+(u-N))*r,(w+I)*r),(u-D)*r)):(s.left=!1,P=Math.max((c-D)*r,(w+I)*r),U=Math.max((u-D)*r,(w+I)*r));let M,G;return l<v?(s.top=!0,M=(O+T+(l-v))*o,G=Math.max(Math.min((O+T+(u-v))*o,(O+T)*o),(d-B)*o)):(s.top=!1,M=Math.max((l-B)*o,(O+T)*o),G=Math.max((d-B)*o,(O+T)*o)),{left:P,right:U,top:M,bottom:G,absolute:s}}const ve=(e,t,n,i)=>{const{scene:r}=t,{left:o,top:a,width:s,height:c,angle:u}=e,l={left:o,right:o+s,top:a,bottom:a+c},d=ln(l,r,n,i);return{startX:d.left,endX:d.right,startY:d.top,endY:d.bottom,rotate:u,width:s,height:c,absolute:d.absolute}};A.SheetCanvasFloatDomManagerService=class extends h.Disposable{constructor(n,i,r,o,a,s,c,u){super();K(this,"_domLayerMap",new Map);K(this,"_domLayerInfoMap",new Map);K(this,"_transformChange$",new te.Subject);K(this,"transformChange$",this._transformChange$.asObservable());K(this,"_remove$",new te.Subject);K(this,"remove$",this._remove$.asObservable());this._renderManagerService=n,this._univerInstanceService=i,this._sheetSkeletonManagerService=r,this._commandService=o,this._drawingManagerService=a,this._selectionRenderService=s,this._canvasFloatDomService=c,this._sheetDrawingService=u,this._drawingAddListener(),this._scrollUpdateListener(),this._featureUpdateListener(),this._deleteListener()}_ensureMap(n,i){let r=this._domLayerMap.get(n);r||(r=new Map,this._domLayerMap.set(n,r));let o=r.get(i);return o||(o=new Map,r.set(i,o)),o}_getSceneAndTransformerByDrawingSearch(n){if(n==null)return;const i=this._renderManagerService.getRenderById(n),r=i==null?void 0:i.scene;if(i==null||r==null)return null;const o=r.getTransformerByCreate(),a=i.engine.getCanvasElement();return{scene:r,transformer:o,renderObject:i,canvas:a}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(n=>{n.forEach(i=>{const{unitId:r,subUnitId:o,drawingId:a}=i,s=C.getSheetCommandTarget(this._univerInstanceService,{unitId:r,subUnitId:o}),c=this._drawingManagerService.getDrawingByParam(i),u=this._sheetSkeletonManagerService.getUnitSkeleton(r,o);if(c==null||s==null||u==null)return;const{transform:l,drawingType:d}=c;if(d!==h.DrawingTypeEnum.DRAWING_DOM)return;const g=this._getSceneAndTransformerByDrawingSearch(r);if(g==null)return;const{scene:p,canvas:S}=g;if(l==null)return!0;const{left:f,top:_,width:R,height:y,angle:I,flipX:T,flipY:w,skewX:O,skewY:v}=l,N=E.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:o,drawingId:a}),D=p.getObject(N);if(D!=null){D.transformByState({left:f,top:_,width:R,height:y,angle:I,flipX:T,flipY:w,skewX:O,skewY:v});return}const B={left:f,top:_,width:R,height:y,zIndex:this._drawingManagerService.getDrawingOrder(r,o).length-1},P=new F.Rect(N,B);p.addObject(P,F.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(P);const U=new h.DisposableCollection,M=ve(P,g.renderObject,u.skeleton,s.worksheet),G=new te.BehaviorSubject(M),z={dispose:U,rect:P,position$:G,unitId:r,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:G,id:a,componentKey:c.componentKey,onPointerDown:V=>{S.dispatchEvent(new PointerEvent(V.type,V))},onPointerMove:V=>{S.dispatchEvent(new PointerEvent(V.type,V))},onPointerUp:V=>{S.dispatchEvent(new PointerEvent(V.type,V))},onWheel:V=>{S.dispatchEvent(new WheelEvent(V.type,V))}});const je=P.onTransformChangeObservable.add(()=>{const V=ve(P,g.renderObject,u.skeleton,s.worksheet);G.next(V)});U.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),je&&U.add(je),this._domLayerInfoMap.set(a,z)})}))}_scrollUpdateListener(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var r,o;const i=(a,s)=>{const c=this._getSceneAndTransformerByDrawingSearch(a),u=this._ensureMap(a,s),l=Array.from(u.keys()),d=C.getSheetCommandTarget(this._univerInstanceService,{unitId:a,subUnitId:s}),g=this._sheetSkeletonManagerService.getUnitSkeleton(a,s);!c||!d||!g||l.forEach(p=>{const S=this._domLayerInfoMap.get(p);if(S){const f=ve(S.rect,c.renderObject,g.skeleton,d.worksheet);S.position$.next(f)}})};if(n.id===X.SetScrollOperation.id){const a=n.params,{unitId:s,sheetId:c}=a;i(s,c)}else if(n.id===X.SetZoomRatioOperation.id){const a=n.params,{unitId:s}=a;Array.from((o=(r=this._domLayerMap.get(s))==null?void 0:r.keys())!=null?o:[]).forEach(u=>{i(s,u)})}else if(n.id===C.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=n.params;i(a,s)}}))}_getPosition(n){const{startX:i,endX:r,startY:o,endY:a}=n,s=this._selectionRenderService.getSelectionCellByPosition(i,o);if(s==null)return;const c={column:s.actualColumn,columnOffset:i-s.startX,row:s.actualRow,rowOffset:o-s.startY},u=this._selectionRenderService.getSelectionCellByPosition(r,a);if(u==null)return;const l={column:u.actualColumn,columnOffset:r-u.startX,row:u.actualRow,rowOffset:a-u.startY};return{from:c,to:l}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(i=>{const r=this._drawingManagerService.getDrawingByParam(i);if(!r||r.drawingType!==h.DrawingTypeEnum.DRAWING_DOM)return;const o={...r.transform};this._transformChange$.next({id:i.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(i=>{this._removeDom(i.drawingId)})}))}addFloatDomToPosition(n){const i=C.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!i)throw new Error("cannot find current target!");const{unitId:r,subUnitId:o}=i,{initPosition:a,componentKey:s}=n,c=h.Tools.generateRandomId(),u=this._getPosition(a);if(u==null)return;const l={unitId:r,subUnitId:o,drawingId:c,drawingType:h.DrawingTypeEnum.DRAWING_DOM,componentKey:s,sheetTransform:u,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY}};return this._commandService.executeCommand(Se.id,{unitId:r,drawings:[l]}),this._ensureMap(r,o).set(c,n),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(n,i=!1){const r=this._domLayerInfoMap.get(n);if(!r)return;const{unitId:o,subUnitId:a}=r,s=this._ensureMap(o,a);this._domLayerInfoMap.delete(n),s.delete(n),r.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(r.rect),i){const u=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:n});if(!u)return;const l=this._sheetDrawingService.getBatchRemoveOp([u]),{redo:d,objects:g}=l;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:d,objects:g,type:m.DrawingApplyType.REMOVE})}}},A.SheetCanvasFloatDomManagerService=cn([Z(0,j.Inject(F.IRenderManagerService)),Z(1,h.IUniverInstanceService),Z(2,j.Inject(X.SheetSkeletonManagerService)),Z(3,j.Inject(h.ICommandService)),Z(4,E.IDrawingManagerService),Z(5,X.ISelectionRenderService),Z(6,j.Inject(k.CanvasFloatDomService)),Z(7,m.ISheetDrawingService)],A.SheetCanvasFloatDomManagerService);var dn=Object.defineProperty,un=(e,t,n)=>t in e?dn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,mn=(e,t,n,i)=>{for(var r=t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(r=a(r)||r);return r},Pe=(e,t)=>(n,i)=>t(n,i,e),Ne=(e,t,n)=>(un(e,typeof t!="symbol"?t+"":t,n),n);const pn="SHEET_IMAGE_UI_PLUGIN";A.UniverSheetsDrawingUIPlugin=class extends h.Plugin{constructor(n={},i,r){super();K(this,"_pluginConfig");this._injector=i,this._localeService=r,this._pluginConfig=h.Tools.deepMerge({},rn,n)}onStarting(n){super.onStarting(n),this._initDependencies(n)}_initDependencies(n){[[A.SheetCanvasFloatDomManagerService],[ae,{useFactory:()=>this._injector.createInstance(ae,this._pluginConfig)}],[pe],[le],[he]].forEach(r=>n.add(r))}},Ne(A.UniverSheetsDrawingUIPlugin,"type",h.UniverInstanceType.UNIVER_SHEET),Ne(A.UniverSheetsDrawingUIPlugin,"pluginName",pn),A.UniverSheetsDrawingUIPlugin=mn([h.DependentOn(E.UniverDrawingPlugin,ee.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),Pe(1,j.Inject(j.Injector)),Pe(2,j.Inject(h.LocaleService))],A.UniverSheetsDrawingUIPlugin),Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(O,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/drawing-ui"),require("@univerjs/sheets-drawing"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("rxjs"),require("@univerjs/ui"),require("@wendellhu/redi/react-bindings"),require("@univerjs/sheets"),require("react"),require("@univerjs/design"),require("clsx")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/drawing-ui","@univerjs/sheets-drawing","@univerjs/drawing","@univerjs/engine-render","@univerjs/sheets-ui","rxjs","@univerjs/ui","@wendellhu/redi/react-bindings","@univerjs/sheets","react","@univerjs/design","clsx"],p):(O=typeof globalThis<"u"?globalThis:O||self,p(O.UniverSheetsDrawingUi={},O.UniverCore,O["@wendellhu/redi"],O.UniverDrawingUi,O.UniverSheetsDrawing,O.UniverDrawing,O.UniverEngineRender,O.UniverSheetsUi,O.rxjs,O.UniverUi,O["@wendellhu/redi/react-bindings"],O.UniverSheets,O.React,O.UniverDesign,O.clsx))})(this,function(O,p,j,Z,g,P,F,x,te,B,k,C,A,q,se){"use strict";var An=Object.defineProperty;var En=(O,p,j)=>p in O?An(O,p,{enumerable:!0,configurable:!0,writable:!0,value:j}):O[p]=j;var K=(O,p,j)=>(En(O,typeof p!="symbol"?p+"":p,j),j);const L={id:"sheet.operation.clear-drawing-transformer",type:p.CommandType.MUTATION,handler:(i,t)=>{const e=i.get(F.IRenderManagerService);return t.forEach(n=>{var r,o;(o=(r=e.getRenderById(n))==null?void 0:r.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},ve={id:"sheet.command.remove-sheet-image",type:p.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(p.ICommandService),n=i.get(p.IUndoRedoService),r=i.get(g.ISheetDrawingService);if(!t)return!1;const{drawings:o}=t,a=[];o.forEach(S=>{const{unitId:f}=S;a.push(f)});const s=r.getBatchRemoveOp(o),{unitId:c,subUnitId:u,undo:d,redo:l,objects:h}=s;return e.syncExecuteCommand(g.SetDrawingApplyMutation.id,{unitId:c,subUnitId:u,op:l,objects:h,type:g.DrawingApplyType.REMOVE})?(n.pushUndoRedo({unitID:c,undoMutations:[{id:g.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:d,objects:h,type:g.DrawingApplyType.INSERT}},{id:L.id,params:a}],redoMutations:[{id:g.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:l,objects:h,type:g.DrawingApplyType.REMOVE}},{id:L.id,params:a}]}),!0):!1}},Ce="COMPONENT_SHEET_DRAWING_PANEL",Ie={id:"sidebar.operation.sheet-image",type:p.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(B.ISidebarService),n=i.get(p.LocaleService),r=i.get(p.IUniverInstanceService),o=i.get(P.IDrawingManagerService);if(!C.getSheetCommandTarget(r))return!1;switch(t.value){case"open":e.open({header:{title:n.t("sheetImage.panel.title")},children:{label:Ce},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:e.close();break}return!0}},ye={id:"sheet.operation.edit-sheet-image",type:p.CommandType.OPERATION,handler:(i,t)=>{const e=i.get(P.IDrawingManagerService),n=i.get(p.ICommandService);return t==null?!1:(e.focusDrawing([t]),n.executeCommand(Ie.id,{value:"open"}),!0)}},ce={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},Fe=()=>{const i=k.useDependency(P.IImageIoService),t=k.useDependency(p.LocaleService),[e,n]=A.useState(0);return A.useEffect(()=>{const r=i.change$.subscribe(o=>{n(o)});return()=>{r.unsubscribe()}},[i]),A.createElement("div",{style:{display:e>0?"block":"none"},className:ce.uploadLoading},A.createElement("div",{className:ce.uploadLoadingBody},A.createElement("div",{className:ce.uploadLoadingBodyAnimation}),A.createElement("div",{className:ce.uploadLoadingBodyText},`${t.t("uploadLoading.loading")}: ${e}`)))};var $e=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,Ve=(i,t,e,n)=>{for(var r=n>1?void 0:n?xe(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&$e(t,e,r),r},Q=(i,t)=>(e,n)=>t(e,n,i);let le=class extends p.RxDisposable{constructor(t,e,n,r,o,a,s){super();K(this,"_initImagePopupMenu",new Set);this._injector=t,this._drawingManagerService=e,this._canvasPopManagerService=n,this._renderManagerService=r,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET).pipe(te.takeUntil(this.dispose$)).subscribe(t=>this._create(t)),this._univerInstanceService.getTypeOfUnitDisposed$(p.UniverInstanceType.UNIVER_SHEET).pipe(te.takeUntil(this.dispose$)).subscribe(t=>this._dispose(t)),this._univerInstanceService.getAllUnitsForType(p.UniverInstanceType.UNIVER_SHEET).forEach(t=>this._create(t)),this._uiPartsService.registerComponent(B.BuiltInUIPart.CONTENT,()=>k.connectInjector(Fe,this._injector))}_dispose(t){const e=t.getUnitId();this._renderManagerService.removeRender(e)}_create(t){if(!t)return;const e=t.getUnitId();this._renderManagerService.has(e)&&!this._initImagePopupMenu.has(e)&&(this._popupMenuListener(e),this._initImagePopupMenu.add(e))}_hasCropObject(t){const e=t.getAllObjects();for(const n of e)if(n instanceof Z.ImageCropperObject)return!0;return!1}_popupMenuListener(t){var o;const e=(o=this._renderManagerService.getRenderById(t))==null?void 0:o.scene;if(!e)return;const n=e.getTransformerByCreate();if(!n)return;const r=[];this.disposeWithMe(p.toDisposable(n.onCreateControlObservable.add(()=>{if(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(e))return;const a=n.getSelectedObjectMap();if(a.size>1){r.forEach(m=>m.dispose());return}const s=a.values().next().value;if(!s)return;const c=s.oKey,u=this._drawingManagerService.getDrawingOKey(c);if(!u)return;const{unitId:d,subUnitId:l,drawingId:h}=u;r.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:Z.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(d,l,h)}}))),this._drawingManagerService.focusDrawing([{unitId:d,subUnitId:l,drawingId:h}])}))),this.disposeWithMe(p.toDisposable(n.onClearControlObservable.add(()=>{r.forEach(a=>a.dispose()),this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}))),this.disposeWithMe(p.toDisposable(n.onChangingObservable.add(()=>{r.forEach(a=>a.dispose())})))}_getImageMenuItems(t,e,n){return[{label:"image-popup.edit",index:0,commandId:ye.id,commandParams:{unitId:t,subUnitId:e,drawingId:n},disable:!1},{label:"image-popup.delete",index:1,commandId:ve.id,commandParams:{unitId:t,drawings:[{unitId:t,subUnitId:e,drawingId:n}]},disable:!1},{label:"image-popup.crop",index:2,commandId:Z.OpenImageCropOperation.id,commandParams:{unitId:t,subUnitId:e,drawingId:n},disable:!1},{label:"image-popup.reset",index:3,commandId:Z.ImageResetSizeOperation.id,commandParams:[{unitId:t,subUnitId:e,drawingId:n}],disable:!1}]}};le=Ve([p.OnLifecycle(p.LifecycleStages.Steady,le),Q(0,j.Inject(j.Injector)),Q(1,P.IDrawingManagerService),Q(2,j.Inject(x.SheetCanvasPopManagerService)),Q(3,F.IRenderManagerService),Q(4,p.IUniverInstanceService),Q(5,p.IContextService),Q(6,j.Inject(B.IUIPartsService))],le);const de={id:"sheet.operation.insert-float-image",type:p.CommandType.OPERATION,handler:(i,t)=>!0},ue={id:"sheet.operation.insert-cell-image",type:p.CommandType.OPERATION,handler:(i,t)=>!0},we={id:"sheet.command.insert-sheet-image",type:p.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(p.ICommandService),n=i.get(p.IUndoRedoService),r=i.get(g.ISheetDrawingService);if(!t)return!1;const o=t.drawings,a=o.map(S=>S.unitId),s=r.getBatchAddOp(o),{unitId:c,subUnitId:u,undo:d,redo:l,objects:h}=s;return e.syncExecuteCommand(g.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:u,objects:h,type:g.DrawingApplyType.INSERT})?(n.pushUndoRedo({unitID:c,undoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:u,objects:h,type:g.DrawingApplyType.REMOVE}},{id:L.id,params:a}],redoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:u,objects:h,type:g.DrawingApplyType.INSERT}},{id:L.id,params:a}]}),!0):!1}},me={id:"sheet.command.set-sheet-image",type:p.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(p.ICommandService),n=i.get(p.IUndoRedoService),r=i.get(g.ISheetDrawingService);if(!t)return!1;const{drawings:o}=t,a=r.getBatchUpdateOp(o),{unitId:s,subUnitId:c,undo:u,redo:d,objects:l}=a;return e.syncExecuteCommand(g.SetDrawingApplyMutation.id,{unitId:s,subUnitId:c,op:d,objects:l,type:g.DrawingApplyType.UPDATE})?(n.pushUndoRedo({unitID:s,undoMutations:[{id:g.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:c,op:u,objects:l,type:g.DrawingApplyType.UPDATE}},{id:L.id,params:[s]}],redoMutations:[{id:g.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:c,op:d,objects:l,type:g.DrawingApplyType.UPDATE}},{id:L.id,params:[s]}]}),!0):!1}},Me={id:"sheet.command.set-drawing-arrange",type:p.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(p.ICommandService),n=i.get(p.IUndoRedoService);if(!t)return!1;const r=i.get(g.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:c}=t,u={unitId:o,subUnitId:a,drawingIds:s};let d;if(c===P.ArrangeTypeEnum.forward?d=r.getForwardDrawingsOp(u):c===P.ArrangeTypeEnum.backward?d=r.getBackwardDrawingOp(u):c===P.ArrangeTypeEnum.front?d=r.getFrontDrawingsOp(u):c===P.ArrangeTypeEnum.back&&(d=r.getBackDrawingsOp(u)),d==null)return!1;const{objects:l,redo:h,undo:m}=d;return e.syncExecuteCommand(g.SetDrawingApplyMutation.id,{op:h,unitId:o,subUnitId:a,objects:l,type:g.DrawingApplyType.ARRANGE})?(n.pushUndoRedo({unitID:o,undoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:a,objects:l,type:g.DrawingApplyType.ARRANGE}}],redoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:l,type:g.DrawingApplyType.ARRANGE}}]}),!0):!1}};function He(i){const t=[];return i.forEach(e=>{const{parent:n,children:r}=e,{unitId:o,subUnitId:a,drawingId:s}=n,c=F.getGroupState(0,0,r.map(l=>l.transform||{})),u=r.map(l=>{const h=l.transform||{left:0,top:0},{unitId:m,subUnitId:S,drawingId:f}=l;return{unitId:m,subUnitId:S,drawingId:f,transform:{...h,left:h.left-c.left,top:h.top-c.top},groupId:s}}),d={unitId:o,subUnitId:a,drawingId:s,drawingType:P.DrawingTypeEnum.DRAWING_GROUP,transform:c};t.push({parent:d,children:u})}),t}function Ye(i){const t=[];return i.forEach(e=>{const{parent:n,children:r}=e,{unitId:o,subUnitId:a,drawingId:s,transform:c={width:0,height:0}}=n;if(c==null)return;const u=r.map(l=>{const{transform:h}=l,{unitId:m,subUnitId:S,drawingId:f}=l,_=F.transformObjectOutOfGroup(h||{},c,c.width||0,c.height||0);return{unitId:m,subUnitId:S,drawingId:f,transform:_,groupId:void 0}}),d={unitId:o,subUnitId:a,drawingId:s,drawingType:P.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};t.push({parent:d,children:u})}),t}const De={id:"sheet.command.group-sheet-image",type:p.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(p.ICommandService),n=i.get(p.IUndoRedoService),r=i.get(g.ISheetDrawingService);if(!t)return!1;const o=[];t.forEach(({parent:m,children:S})=>{o.push(m.unitId),S.forEach(f=>{o.push(f.unitId)})});const a=r.getGroupDrawingOp(t),{unitId:s,subUnitId:c,undo:u,redo:d,objects:l}=a;return e.syncExecuteCommand(g.SetDrawingApplyMutation.id,{op:d,unitId:s,subUnitId:c,objects:l,type:g.DrawingApplyType.GROUP})?(n.pushUndoRedo({unitID:s,undoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:c,objects:Ye(l),type:g.DrawingApplyType.UNGROUP}},{id:L.id,params:o}],redoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:d,unitId:s,subUnitId:c,objects:l,type:g.DrawingApplyType.GROUP}},{id:L.id,params:o}]}),!0):!1}},Re={id:"sheet.command.ungroup-sheet-image",type:p.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(p.ICommandService),n=i.get(p.IUndoRedoService),r=i.get(g.ISheetDrawingService);if(!t)return!1;const o=[];t.forEach(({parent:m,children:S})=>{o.push(m.unitId),S.forEach(f=>{o.push(f.unitId)})});const a=r.getUngroupDrawingOp(t),{unitId:s,subUnitId:c,undo:u,redo:d,objects:l}=a;return e.syncExecuteCommand(g.SetDrawingApplyMutation.id,{op:d,unitId:s,subUnitId:c,objects:l,type:g.DrawingApplyType.UNGROUP})?(n.pushUndoRedo({unitID:s,undoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:c,objects:He(l),type:g.DrawingApplyType.GROUP}},{id:L.id,params:o}],redoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:d,unitId:s,subUnitId:c,objects:l,type:g.DrawingApplyType.UNGROUP}},{id:L.id,params:o}]}),!0):!1}};function V(i,t){const{from:e,to:n}=i,{column:r,columnOffset:o,row:a,rowOffset:s}=e,{column:c,columnOffset:u,row:d,rowOffset:l}=n,h=t.attachRangeWithCoord({startColumn:r,endColumn:r,startRow:a,endRow:a});if(h==null)return;const m=t.attachRangeWithCoord({startColumn:c,endColumn:c,startRow:d,endRow:d});if(m==null)return;const{startX:S,startY:f}=h,{startX:_,startY:R}=m,y=F.precisionTo(S+o,1),I=F.precisionTo(f+s,1);let D=F.precisionTo(_+u-y,1),w=F.precisionTo(R+l-I,1);return h.startX===m.endX&&(D=0),h.startY===m.endY&&(w=0),{left:y,top:I,width:D,height:w}}function W(i,t){const{left:e=0,top:n=0,width:r=0,height:o=0}=i,a=t.getSelectionCellByPosition(e,n);if(a==null)return;const s={column:a.actualColumn,columnOffset:F.precisionTo(e-a.startX,1),row:a.actualRow,rowOffset:F.precisionTo(n-a.startY,1)},c=t.getSelectionCellByPosition(e+r,n+o);if(c==null)return;const u={column:c.actualColumn,columnOffset:F.precisionTo(e+r-c.startX,1),row:c.actualRow,rowOffset:F.precisionTo(n+o-c.startY,1)};return{from:s,to:u}}var Xe=Object.defineProperty,ke=Object.getOwnPropertyDescriptor,ze=(i,t,e,n)=>{for(var r=n>1?void 0:n?ke(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Xe(t,e,r),r},X=(i,t)=>(e,n)=>t(e,n,i);let pe=class extends p.Disposable{constructor(i,t,e,n,r,o,a,s,c,u,d){super(),this._commandService=i,this._univerInstanceService=t,this._selectionManagerService=e,this._selectionRenderService=n,this._imageIoService=r,this._sheetDrawingService=o,this._drawingManagerService=a,this._contextService=s,this._messageService=c,this._localeService=u,this._renderManagerService=d,this._init()}_init(){this._initCommandListeners(),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async i=>{if(i.id===ue.id||i.id===de.id){const t=i.params;if(t.files==null)return;const e=t.files.length;if(e>P.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(P.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(e),i.id===ue.id?t.files.forEach(async n=>{await this._insertCellImage(n)}):t.files.forEach(async n=>{await this._insertFloatImage(n)})}}))}async _insertCellImage(i){}async _insertFloatImage(i){let t;try{t=await this._imageIoService.saveImage(i)}catch(y){const I=y.message;I===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):I===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):I===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(t==null)return;const e=this._getUnitInfo();if(e==null)return;const{unitId:n,subUnitId:r}=e,{imageId:o,imageSourceType:a,source:s,base64Cache:c}=t,{width:u,height:d,image:l}=await P.getImageSize(c||""),h=this._renderManagerService.getRenderById(n);if(h==null)return;const{width:m,height:S}=h.scene;this._imageIoService.addImageSourceCache(s,a,l);let f=1;if(u>P.DRAWING_IMAGE_WIDTH_LIMIT||d>P.DRAWING_IMAGE_HEIGHT_LIMIT){const y=P.DRAWING_IMAGE_WIDTH_LIMIT/u,I=P.DRAWING_IMAGE_HEIGHT_LIMIT/d;f=Math.max(y,I)}const _=this._getImagePosition(u*f,d*f,m,S);if(_==null)return;const R={unitId:n,subUnitId:r,drawingId:o,drawingType:P.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:s,transform:V(_,this._selectionRenderService),sheetTransform:_};this._commandService.executeCommand(we.id,{unitId:n,drawings:[R]})}_getUnitInfo(){const i=this._univerInstanceService.getCurrentUnitForType(p.UniverInstanceType.UNIVER_SHEET);if(i==null)return;const t=i.getActiveSheet();if(t==null)return;const e=i.getUnitId(),n=t.getSheetId();return{unitId:e,subUnitId:n}}_getImagePosition(i,t,e,n){const r=this._selectionManagerService.getSelections();let o={startRow:0,endRow:0,startColumn:0,endColumn:0};r&&r.length>0&&(o=r[r.length-1].range);const a=this._selectionRenderService.attachRangeWithCoord(o);if(a==null)return;let{startColumn:s,startRow:c,startX:u,startY:d}=a,l=!1;if(u+i>e&&(u=e-i,u<0&&(u=0,i=e),l=!0),d+t>n&&(d=n-t,d<0&&(d=0,t=n),l=!0),l){const f=this._selectionRenderService.getSelectionCellByPosition(u,d);if(f==null)return;u=f.startX,d=f.startY,s=f.actualColumn,c=f.actualRow}const h={column:s,columnOffset:0,row:c,rowOffset:0},m=this._selectionRenderService.getSelectionCellByPosition(u+i,d+t);if(m==null)return;const S={column:m.actualColumn,columnOffset:u+i-m.startX,row:m.actualRow,rowOffset:d+t-m.startY};return{from:h,to:S}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(i=>{const{unitId:t,subUnitId:e,drawingIds:n,arrangeType:r}=i;this._commandService.executeCommand(Me.id,{unitId:t,subUnitId:e,drawingIds:n,arrangeType:r})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(i=>{const t=[];i.length!==0&&(i.forEach(e=>{const{unitId:n,subUnitId:r,drawingId:o,drawingType:a,transform:s}=e;if(s==null)return;const c=this._sheetDrawingService.getDrawingByParam({unitId:n,subUnitId:r,drawingId:o});if(c==null)return;const u=W({...c.transform,...s},this._selectionRenderService);if(u==null)return;const d={...e,transform:{...c.transform,...s,...V(u,this._selectionRenderService)},sheetTransform:{...u}};t.push(d)}),t.length>0&&this._commandService.executeCommand(me.id,{unitId:i[0].unitId,drawings:t}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(i=>{this._commandService.executeCommand(De.id,i);const{unitId:t,subUnitId:e,drawingId:n}=i[0].parent;this._drawingManagerService.focusDrawing([{unitId:t,subUnitId:e,drawingId:n}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(i=>{this._commandService.executeCommand(Re.id,i)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(i=>{i==null||i.length===0?(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(i))}))}};pe=ze([p.OnLifecycle(p.LifecycleStages.Rendered,pe),X(0,p.ICommandService),X(1,p.IUniverInstanceService),X(2,j.Inject(C.SelectionManagerService)),X(3,x.ISelectionRenderService),X(4,P.IImageIoService),X(5,g.ISheetDrawingService),X(6,P.IDrawingManagerService),X(7,p.IContextService),X(8,B.IMessageService),X(9,j.Inject(p.LocaleService)),X(10,F.IRenderManagerService)],pe);var Y=function(){return Y=Object.assign||function(i){for(var t,e=1,n=arguments.length;e<n;e++){t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(i[r]=t[r])}return i},Y.apply(this,arguments)},Ke=function(i,t){var e={};for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&t.indexOf(n)<0&&(e[n]=i[n]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,n=Object.getOwnPropertySymbols(i);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(i,n[r])&&(e[n[r]]=i[n[r]]);return e},Te=A.forwardRef(function(i,t){var e=i.icon,n=i.id,r=i.className,o=i.extend,a=Ke(i,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(n," ").concat(r||"").trim(),c=A.useRef("_".concat(Ze()));return Oe(e,"".concat(n),{defIds:e.defIds,idSuffix:c.current},Y({ref:t,className:s},a),o)});function Oe(i,t,e,n,r){return A.createElement(i.tag,Y(Y({key:t},qe(i,e,r)),n),(Je(i,e).children||[]).map(function(o,a){return Oe(o,"".concat(t,"-").concat(i.tag,"-").concat(a),e,void 0,r)}))}function qe(i,t,e){var n=Y({},i.attrs);e!=null&&e.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=e.colorChannel1);var r=t.defIds;return!r||r.length===0||(i.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(n[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Je(i,t){var e,n=t.defIds;return!n||n.length===0?i:i.tag==="defs"&&(!((e=i.children)===null||e===void 0)&&e.length)?Y(Y({},i),{children:i.children.map(function(r){return typeof r.attrs.id=="string"&&n&&n.indexOf(r.attrs.id)>-1?Y(Y({},r),{attrs:Y(Y({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):i}function Ze(){return Math.random().toString(36).substring(2,8)}Te.displayName="UniverIcon";var Qe={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"}}]},Pe=A.forwardRef(function(i,t){return A.createElement(Te,Object.assign({},i,{id:"add-image-single",ref:t,icon:Qe}))});Pe.displayName="AddImageSingle";const be={uploadFileMenu:"univer-upload-file-menu",uploadFileMenuInput:"univer-upload-file-menu-input"},Ae="COMPONENT_UPLOAD_FILE_MENU";var ge=(i=>(i[i.cellImage=0]="cellImage",i[i.floatImage=1]="floatImage",i))(ge||{});const en=i=>{const{type:t}=i,e=k.useDependency(p.ICommandService),n=A.useRef(null),r=()=>{var s;(s=n.current)==null||s.click()},o=P.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(s=>`.${s.replace("image/","")}`).join(","),a=s=>{const c=s.target.files;if(c==null)return;const u=Array.from(c);t===ge.floatImage?e.executeCommand(de.id,{files:u}):t===ge.cellImage&&e.executeCommand(ue.id,{files:u}),n.current&&(n.current.value="")};return A.createElement("div",{onClick:r,className:be.uploadFileMenu},A.createElement("input",{type:"file",className:be.uploadFileMenuInput,ref:n,onChange:a,accept:o,multiple:!0}))},Ee="addition-and-subtraction-single",Ue="sheet.menu.image";function nn(i){return{id:Ue,type:B.MenuItemType.SUBITEMS,positions:[B.MenuPosition.TOOLBAR_START],group:B.MenuGroup.TOOLBAR_FORMULAS_INSERT,icon:Ee,tooltip:"sheetImage.title",hidden$:B.getMenuHiddenObservable(i,p.UniverInstanceType.UNIVER_SHEET),disabled$:x.getCurrentRangeDisable$(i,{workbookTypes:[C.WorkbookEditablePermission],worksheetTypes:[C.WorksheetEditPermission],rangeTypes:[C.RangeProtectionPermissionEditPoint]})}}function tn(i){return{id:de.id,title:"sheetImage.upload.float",type:B.MenuItemType.SELECTOR,label:{name:Ae,props:{type:ge.floatImage}},positions:[Ue],hidden$:B.getMenuHiddenObservable(i,p.UniverInstanceType.UNIVER_SHEET)}}const J={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",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"},rn=i=>{var I;const t=k.useDependency(p.ICommandService),e=k.useDependency(p.LocaleService),n=k.useDependency(P.IDrawingManagerService),r=k.useDependency(F.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:s}=a,c=r.getRenderById(s),u=c==null?void 0:c.scene;if(u==null)return;const d=u.getTransformerByCreate(),[l,h]=A.useState(!0),m=(I=a.anchorType)!=null?I:g.SheetDrawingAnchorType.Position,[S,f]=A.useState(m);function _(D,w){const b=[];return D.forEach(v=>{const{oKey:N}=v,T=w.getDrawingOKey(N);if(T==null)return b.push(null),!0;const{unitId:$,subUnitId:U,drawingId:E,drawingType:M,anchorType:G,sheetTransform:z}=T;b.push({unitId:$,subUnitId:U,drawingId:E,anchorType:G,sheetTransform:z,drawingType:M})}),b}A.useEffect(()=>{const D=d.onClearControlObservable.add(b=>{b===!0&&h(!1)}),w=d.onChangeStartObservable.add(b=>{var T;const{objects:v}=b,N=_(v,n);if(N.length===0)h(!1);else if(N.length>=1){h(!0);const $=((T=N[0])==null?void 0:T.anchorType)||g.SheetDrawingAnchorType.Position;f($)}});return()=>{w==null||w.dispose(),D==null||D.dispose()}},[]);function R(D){f(D);const w=n.getFocusDrawings();if(w.length===0)return;const b=w.map(v=>({unitId:v.unitId,subUnitId:v.subUnitId,drawingId:v.drawingId,anchorType:D}));t.executeCommand(me.id,{unitId:w[0].unitId,drawings:b})}const y=D=>D?"block":"none";return A.createElement("div",{className:se(J.imageCommonPanelGrid,J.imageCommonPanelBorder),style:{display:y(l)}},A.createElement("div",{className:J.imageCommonPanelRow},A.createElement("div",{className:se(J.imageCommonPanelColumn,J.imageCommonPanelTitle)},A.createElement("div",null,e.t("drawing-anchor.title")))),A.createElement("div",{className:se(J.imageCommonPanelRow)},A.createElement("div",{className:se(J.imageCommonPanelColumn)},A.createElement(q.RadioGroup,{value:S,onChange:R,direction:"vertical"},A.createElement(q.Radio,{value:g.SheetDrawingAnchorType.Both},e.t("drawing-anchor.both")),A.createElement(q.Radio,{value:g.SheetDrawingAnchorType.Position},e.t("drawing-anchor.position")),A.createElement(q.Radio,{value:g.SheetDrawingAnchorType.None},e.t("drawing-anchor.none"))))))},on=()=>{const i=k.useDependency(P.IDrawingManagerService),t=i.getFocusDrawings();if(t==null||t.length===0)return;const[e,n]=A.useState(t);return A.useEffect(()=>{const r=i.focus$.subscribe(o=>{n(o)});return()=>{r.unsubscribe()}},[]),A.createElement("div",{className:J.imageCommonPanel},A.createElement(Z.DrawingCommonPanel,{drawings:e}),A.createElement(rn,{drawings:e}))},re={id:"sheet.command.move-drawing",type:p.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(p.ICommandService),n=i.get(g.ISheetDrawingService),r=i.get(x.ISelectionRenderService),{direction:o}=t,a=n.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,c=a.map(d=>{const{transform:l}=d;if(l==null)return null;const h={...l},{left:m=0,top:S=0}=l;return o===p.Direction.UP?h.top=S-1:o===p.Direction.DOWN?h.top=S+1:o===p.Direction.LEFT?h.left=m-1:o===p.Direction.RIGHT&&(h.left=m+1),{...d,transform:h,sheetTransform:W(h,r)}}).filter(d=>d!=null);return e.syncExecuteCommand(me.id,{unitId:s,drawings:c})?(e.syncExecuteCommand(L.id,[s]),!0):!1}},Ne={id:"sheet.command.delete-drawing",type:p.CommandType.COMMAND,handler:i=>{const t=i.get(p.ICommandService),n=i.get(g.ISheetDrawingService).getFocusDrawings();if(n.length===0)return!1;const r=n[0].unitId,o=n.map(a=>{const{unitId:s,subUnitId:c,drawingId:u,drawingType:d}=a;return{unitId:s,subUnitId:c,drawingId:u,drawingType:d}});return t.executeCommand(ve.id,{unitId:r,drawings:o})}};function ie(i){return!i.getContextValue(p.FOCUSING_FORMULA_EDITOR)&&!i.getContextValue(p.EDITOR_ACTIVATED)&&i.getContextValue(p.FOCUSING_COMMON_DRAWINGS)}const an={id:re.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:B.KeyCode.ARROW_DOWN,priority:100,preconditions:ie,staticParameters:{direction:p.Direction.DOWN}},sn={id:re.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:B.KeyCode.ARROW_UP,priority:100,preconditions:ie,staticParameters:{direction:p.Direction.UP}},cn={id:re.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:B.KeyCode.ARROW_LEFT,priority:100,preconditions:ie,staticParameters:{direction:p.Direction.LEFT}},ln={id:re.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:B.KeyCode.ARROW_RIGHT,priority:100,preconditions:ie,staticParameters:{direction:p.Direction.RIGHT}},dn={id:Ne.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:ie,binding:B.KeyCode.DELETE,mac:B.KeyCode.BACKSPACE};var un=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,pn=(i,t,e,n)=>{for(var r=n>1?void 0:n?mn(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&un(t,e,r),r},oe=(i,t)=>(e,n)=>t(e,n,i);const gn={};let ae=class extends p.Disposable{constructor(i,t,e,n,r,o){super(),this._config=i,this._injector=t,this._componentManager=e,this._menuService=n,this._commandService=r,this._shortcutService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Ee,Pe)),this.disposeWithMe(i.register(Ae,en)),this.disposeWithMe(i.register(Ce,on))}_initMenus(){const{menu:i={}}=this._config;[nn,tn].forEach(t=>{this._menuService.addMenuItem(t(this._injector),i)})}_initCommands(){[de,ue,we,ve,me,Ie,L,ye,De,Re,re,Ne,Me].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[an,sn,cn,ln,dn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};ae=pn([p.OnLifecycle(p.LifecycleStages.Rendered,ae),oe(1,j.Inject(j.Injector)),oe(2,j.Inject(B.ComponentManager)),oe(3,B.IMenuService),oe(4,p.ICommandService),oe(5,B.IShortcutService)],ae);var hn=Object.defineProperty,fn=Object.getOwnPropertyDescriptor,Sn=(i,t,e,n)=>{for(var r=n>1?void 0:n?fn(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&hn(t,e,r),r},ne=(i,t)=>(e,n)=>t(e,n,i);const vn=[C.InsertRowCommand.id,C.InsertColCommand.id,C.RemoveRowCommand.id,C.RemoveColCommand.id,C.DeleteRangeMoveLeftCommand.id,C.DeleteRangeMoveUpCommand.id,C.InsertRangeMoveDownCommand.id,C.InsertRangeMoveRightCommand.id,C.DeltaRowHeightCommand.id,C.SetRowHeightCommand.id,C.DeltaColumnWidthCommand.id,C.SetColWidthCommand.id,C.SetRowHiddenCommand.id,C.SetSpecificRowsVisibleCommand.id,C.SetSpecificColsVisibleCommand.id,C.SetColHiddenCommand.id],wn=[C.SetRowVisibleMutation.id,C.SetRowHiddenMutation.id,C.SetColVisibleMutation.id,C.SetColHiddenMutation.id,C.SetWorksheetRowHeightMutation.id,C.SetWorksheetColWidthMutation.id];let he=class extends p.Disposable{constructor(i,t,e,n,r,o){super(),this._commandService=i,this._sheetInterceptorService=t,this._sheetDrawingService=e,this._drawingManagerService=n,this._selectionRenderService=r,this._univerInstanceService=o,this._init()}_init(){this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!vn.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const t=i.id;if(t===C.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if(t===C.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(t===C.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(t===C.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(t===C.DeleteRangeMoveLeftCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,0)}else if(t===C.DeleteRangeMoveUpCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,1)}else if(t===C.InsertRangeMoveDownCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,2)}else if(t===C.InsertRangeMoveRightCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,3)}else if(t===C.SetRowHiddenCommand.id||t===C.SetSpecificRowsVisibleCommand.id){const e=i.params,{unitId:n,subUnitId:r,ranges:o}=e;return this._getDrawingUndoForRowVisible(n,r,o)}else if(t===C.SetSpecificColsVisibleCommand.id||t===C.SetColHiddenCommand.id){const e=i.params,{unitId:n,subUnitId:r,ranges:o}=e;return this._getDrawingUndoForColVisible(n,r,o)}else if(t===C.DeltaRowHeightCommand.id||t===C.SetRowHeightCommand.id||t===C.DeltaColumnWidthCommand.id||t===C.SetColWidthCommand.id){const e=i.params,{unitId:n,subUnitId:r,ranges:o}=e,a=t===C.DeltaRowHeightCommand.id||t===C.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(n,r,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,t){const e=C.getSheetCommandTarget(this._univerInstanceService);if(e==null)return{redos:[],undos:[]};const n=e.unitId,r=e.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(n,r),c=[],u=[];if(Object.keys(s).forEach(d=>{const l=s[d],{updateDrawings:h,deleteDrawings:m}=this._getUpdateOrDeleteDrawings(i,t,l);c.push(...h),u.push(...m)}),c.length===0&&u.length===0)return{redos:[],undos:[]};if(c.length>0){const d=this._sheetDrawingService.getBatchUpdateOp(c),{undo:l,redo:h,objects:m}=d;o.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:h,objects:m,type:g.DrawingApplyType.UPDATE}}),a.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:l,objects:m,type:g.DrawingApplyType.UPDATE}})}if(u.length>0){const d=this._sheetDrawingService.getBatchRemoveOp(u),l=d.undo,h=d.redo,m=d.objects;o.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:h,objects:m,type:g.DrawingApplyType.REMOVE}}),a.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:l,objects:m,type:g.DrawingApplyType.INSERT}})}return o.push({id:L.id,params:[n]}),a.push({id:L.id,params:[n]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,t,e){const n=[],r=[],{sheetTransform:o,anchorType:a=g.SheetDrawingAnchorType.Position,transform:s,unitId:c,subUnitId:u,drawingId:d}=e,{from:l,to:h}=o,{row:m,column:S}=l,{row:f,column:_}=h;if(o==null||s==null)return{updateDrawings:n,deleteDrawings:r};const{startRow:R,endRow:y,startColumn:I,endColumn:D}=i;let w=null,b=null;if(t===0&&m>=R&&f<=y)if(S>=I&&_<=D)r.push({unitId:c,subUnitId:u,drawingId:d});else{const v=this._shrinkCol(o,s,I,D,a);w=v==null?void 0:v.newSheetTransform,b=v==null?void 0:v.newTransform}else if(t===1&&S>=I&&_<=D)if(m>=R&&f<=y)r.push({unitId:c,subUnitId:u,drawingId:d});else{const v=this._shrinkRow(o,s,R,y,a);w=v==null?void 0:v.newSheetTransform,b=v==null?void 0:v.newTransform}else if(t===2){const v=this._expandRow(o,s,R,y,a);w=v==null?void 0:v.newSheetTransform,b=v==null?void 0:v.newTransform}else if(t===3){const v=this._expandCol(o,s,I,D,a);w=v==null?void 0:v.newSheetTransform,b=v==null?void 0:v.newTransform}if(w!=null&&b!=null){const v=V(w,this._selectionRenderService);n.push({...e,sheetTransform:w,transform:v})}return{updateDrawings:n,deleteDrawings:r}}_remainDrawingSize(i,t,e){const n=W({...i},this._selectionRenderService);n!=null&&t.push({...e,sheetTransform:n})}_getDrawingUndoForColVisible(i,t,e){const n=this._drawingManagerService.getDrawingData(i,t),r=[],o=[];if(Object.keys(n).forEach(d=>{const l=n[d],{sheetTransform:h,transform:m,anchorType:S=g.SheetDrawingAnchorType.Position}=l;if(S===g.SheetDrawingAnchorType.None)this._remainDrawingSize(m,r,l);else{const{from:f,to:_}=h,{row:R,column:y}=f,{row:I,column:D}=_;for(let w=0;w<e.length;w++){const b=e[w],{startRow:v,endRow:N,startColumn:T,endColumn:$}=b;if(D<T)continue;if(S===g.SheetDrawingAnchorType.Position){let M=null,G=null;if(y>=T&&y<=$){const z=this._selectionRenderService.attachRangeWithCoord({startColumn:y,endColumn:$,startRow:f.row,endRow:_.row});if(z==null)return;G={...m,left:z.startX}}if(G!=null&&(M=W(G,this._selectionRenderService),M!=null&&G!=null)){r.push({...l,sheetTransform:M,transform:G});break}this._remainDrawingSize(m,r,l);continue}if(y>=T&&D<=$)continue;let U=null,E=null;if(y>=T&&y<=$){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:y,endColumn:$,startRow:f.row,endRow:_.row});if(M==null)return;E={...m,left:(M==null?void 0:M.startX)||0,width:((m==null?void 0:m.width)||0)-M.endX+M.startX}}else if(D>=T&&D<=$){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:T,endColumn:D,startRow:f.row,endRow:_.row});if(M==null)return;E={...m,left:M.startX-((m==null?void 0:m.width)||0)}}else{const M=this._selectionRenderService.attachRangeWithCoord({startColumn:T,endColumn:$,startRow:f.row,endRow:_.row});if(M==null)return;if(E={...m,width:((m==null?void 0:m.width)||0)-M.endX+M.startX},U=W(E,this._selectionRenderService),U!=null&&E!=null){o.push({...l,sheetTransform:U,transform:E});break}}if(E!=null&&(U=W(E,this._selectionRenderService)),E!=null&&U!=null){r.push({...l,sheetTransform:U,transform:E});break}else this._remainDrawingSize(m,r,l)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,t,r),c=[],u=[];if(o.length>0){const{redos:d,undos:l}=this._createUndoAndRedoMutation(i,t,o);c.push(...d),u.push(...l)}return{redos:a,undos:s,preRedos:c,preUndos:u}}_createUndoAndRedoMutation(i,t,e){const n=this._sheetDrawingService.getBatchUpdateOp(e),{undo:r,redo:o,objects:a}=n,s=[{id:g.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:t,op:o,objects:a,type:g.DrawingApplyType.UPDATE}},{id:L.id,params:[i]}],c=[{id:g.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:t,op:r,objects:a,type:g.DrawingApplyType.UPDATE}},{id:L.id,params:[i]}];return{redos:s,undos:c}}_getDrawingUndoForRowVisible(i,t,e){const n=this._drawingManagerService.getDrawingData(i,t),r=[],o=[];if(Object.keys(n).forEach(d=>{const l=n[d],{sheetTransform:h,transform:m,anchorType:S=g.SheetDrawingAnchorType.Position}=l;if(S===g.SheetDrawingAnchorType.None)this._remainDrawingSize(m,r,l);else{const{from:f,to:_}=h,{row:R,column:y}=f,{row:I,column:D}=_;for(let w=0;w<e.length;w++){const b=e[w],{startRow:v,endRow:N,startColumn:T,endColumn:$}=b;if(I<v)continue;if(S===g.SheetDrawingAnchorType.Position){let M=null,G=null;if(R>=v&&R<=N){const z=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:R,endRow:N});if(z==null)return;G={...m,top:z.startY}}if(G!=null&&(M=W(G,this._selectionRenderService),M!=null&&G!=null)){r.push({...l,sheetTransform:M,transform:G});break}this._remainDrawingSize(m,r,l);continue}if(R>=v&&I<=N)continue;let U=null,E=null;if(R>=v&&R<=N){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:R,endRow:N});if(M==null)return;E={...m,top:(M==null?void 0:M.startY)||0,height:((m==null?void 0:m.height)||0)-M.endY+M.startY}}else if(I>=v&&I<=N){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:v,endRow:I});if(M==null)return;E={...m,top:M.startY-((m==null?void 0:m.height)||0)}}else{const M=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:v,endRow:N});if(M==null)return;if(E={...m,height:((m==null?void 0:m.height)||0)-M.endY+M.startY},U=W(E,this._selectionRenderService),U!=null&&E!=null){o.push({...l,sheetTransform:U,transform:E});break}}if(E!=null&&(U=W(E,this._selectionRenderService)),E!=null&&U!=null){r.push({...l,sheetTransform:U,transform:E});break}else this._remainDrawingSize(m,r,l)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,t,r),c=[],u=[];if(o.length>0){const{redos:d,undos:l}=this._createUndoAndRedoMutation(i,t,o);c.push(...d),u.push(...l)}return{redos:a,undos:s,preRedos:c,preUndos:u}}_getDrawingUndoForRowAndColSize(i,t,e,n){const r=this._drawingManagerService.getDrawingData(i,t),o=[];return Object.keys(r).forEach(a=>{const s=r[a],{sheetTransform:c,transform:u,anchorType:d=g.SheetDrawingAnchorType.Position}=s;if(d===g.SheetDrawingAnchorType.None)this._remainDrawingSize(u,o,s);else{const{from:l,to:h}=c,{row:m,column:S}=l,{row:f,column:_}=h;for(let R=0;R<e.length;R++){const y=e[R],{startRow:I,endRow:D,startColumn:w,endColumn:b}=y;if(f<I||_<w)continue;if(d===g.SheetDrawingAnchorType.Position&&(m<=I&&f>=D||S<=w&&_>=b)){this._remainDrawingSize(u,o,s);continue}const v=V({...c},this._selectionRenderService);if(v!=null){o.push({...s,transform:v});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,t,o)}_getUnitIdAndSubUnitId(i,t){let e,n;if(t==="insert")e=i.unitId,n=i.subUnitId;else{const r=C.getSheetCommandTarget(this._univerInstanceService);if(r==null)return;e=r.unitId,n=r.subUnitId}return{unitId:e,subUnitId:n}}_moveRowInterceptor(i,t){const e=this._getUnitIdAndSubUnitId(i,t);if(e==null)return{redos:[],undos:[]};const{unitId:n,subUnitId:r}=e,{range:o}=i,a=o.startRow,s=o.endRow,c=[],u=[],d=this._sheetDrawingService.getDrawingData(n,r),l=[],h=[];if(Object.keys(d).forEach(m=>{const S=d[m],{sheetTransform:f,transform:_,anchorType:R=g.SheetDrawingAnchorType.Position}=S;if(f==null||_==null)return;let y,I;if(t==="insert"){const w=this._expandRow(f,_,a,s,R);y=w==null?void 0:w.newSheetTransform,I=w==null?void 0:w.newTransform}else{const{from:w,to:b}=f,{row:v}=w,{row:N}=b;if(v>=a&&N<=s)h.push({unitId:n,subUnitId:r,drawingId:m});else{const T=this._shrinkRow(f,_,a,s,R);y=T==null?void 0:T.newSheetTransform,I=T==null?void 0:T.newTransform}}if(!y||!I)return;const D={unitId:n,subUnitId:r,drawingId:m,transform:I,sheetTransform:y};l.push(D)}),l.length===0&&h.length===0)return{redos:[],undos:[]};if(l.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(l),{undo:S,redo:f,objects:_}=m;c.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:f,objects:_,type:g.DrawingApplyType.UPDATE}}),u.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:S,objects:_,type:g.DrawingApplyType.UPDATE}})}if(h.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(h),S=m.undo,f=m.redo,_=m.objects;c.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:f,objects:_,type:g.DrawingApplyType.REMOVE}}),u.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:S,objects:_,type:g.DrawingApplyType.INSERT}})}return c.push({id:L.id,params:[n]}),u.push({id:L.id,params:[n]}),{redos:c,undos:u}}_moveColInterceptor(i,t){const e=this._getUnitIdAndSubUnitId(i,t);if(e==null)return{redos:[],undos:[]};const{unitId:n,subUnitId:r}=e,{range:o}=i,a=o.startColumn,s=o.endColumn,c=[],u=[],d=this._sheetDrawingService.getDrawingData(n,r),l=[],h=[];if(Object.keys(d).forEach(m=>{const S=d[m],{sheetTransform:f,transform:_,anchorType:R=g.SheetDrawingAnchorType.Position}=S;if(f==null||_==null)return;let y,I;if(t==="insert"){const w=this._expandCol(f,_,a,s,R);y=w==null?void 0:w.newSheetTransform,I=w==null?void 0:w.newTransform}else{const{from:w,to:b}=f,{column:v}=w,{column:N}=b;if(v>=a&&N<=s)h.push({unitId:n,subUnitId:r,drawingId:m});else{const T=this._shrinkCol(f,_,a,s,R);y=T==null?void 0:T.newSheetTransform,I=T==null?void 0:T.newTransform}}if(!y||!I)return;const D={unitId:n,subUnitId:r,drawingId:m,transform:I,sheetTransform:y};l.push(D)}),l.length===0&&h.length===0)return{redos:[],undos:[]};if(l.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(l),{undo:S,redo:f,objects:_}=m;c.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:f,objects:_,type:g.DrawingApplyType.UPDATE}}),u.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:S,objects:_,type:g.DrawingApplyType.UPDATE}})}if(h.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(h),S=m.undo,f=m.redo,_=m.objects;c.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:f,objects:_,type:g.DrawingApplyType.REMOVE}}),u.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:r,op:S,objects:_,type:g.DrawingApplyType.INSERT}})}return c.push({id:L.id,params:[n]}),u.push({id:L.id,params:[n]}),{redos:c,undos:u}}_expandCol(i,t,e,n,r=g.SheetDrawingAnchorType.Position){const o=n-e+1,{from:a,to:s}=i,{column:c}=a,{column:u}=s;if(r===g.SheetDrawingAnchorType.None)return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};let d=null,l=null;if(c>=e){const h=this._selectionRenderService.attachRangeWithCoord({startColumn:e,endColumn:n,startRow:a.row,endRow:s.row});if(h==null)return;l={...t,left:(t.left||0)+h.endX-h.startX},d=W(l,this._selectionRenderService)}else if(u>=n)if(r===g.SheetDrawingAnchorType.Both)d={from:{...a},to:{...s,column:u+o}},l=V(d,this._selectionRenderService);else return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_shrinkCol(i,t,e,n,r=g.SheetDrawingAnchorType.Position){const o=n-e+1,{from:a,to:s}=i,{column:c}=a,{column:u}=s;if(r===g.SheetDrawingAnchorType.None)return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};let d=null,l=null;if(c>n)d={from:{...a,column:c-o},to:{...s,column:u-o}},l=V(d,this._selectionRenderService);else{if(c>=e&&u<=n)return null;if(c<e&&u>n)if(r===g.SheetDrawingAnchorType.Both)d={from:{...a},to:{...s,column:u-o}},l=V(d,this._selectionRenderService);else return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};else if(c>=e&&c<=n){if(c===e)l={...t,left:(t.left||0)-i.from.columnOffset};else{const h=this._selectionRenderService.attachRangeWithCoord({startColumn:e,endColumn:c-1,startRow:a.row,endRow:s.row});if(h==null)return;l={...t,left:(t.left||0)-h.endX+h.startX-i.from.columnOffset}}d=W(l,this._selectionRenderService)}else if(u>=e&&u<=n&&r===g.SheetDrawingAnchorType.Both){const h=this._selectionRenderService.attachRangeWithCoord({startColumn:e-1,endColumn:e-1,startRow:a.row,endRow:s.row});if(h==null)return;d={from:{...a},to:{...s,column:e-1,columnOffset:h.endX-h.startX}},l=V(d,this._selectionRenderService)}}return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_expandRow(i,t,e,n,r=g.SheetDrawingAnchorType.Position){const o=n-e+1,{from:a,to:s}=i,{row:c}=a,{row:u}=s;if(r===g.SheetDrawingAnchorType.None)return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};let d=null,l=null;if(c>=e){const h=this._selectionRenderService.attachRangeWithCoord({startRow:e,endRow:n,startColumn:a.column,endColumn:s.column});if(h==null)return;l={...t,top:(t.top||0)+h.endY-h.startY},d=W(l,this._selectionRenderService)}else if(u>=n)if(r===g.SheetDrawingAnchorType.Both)d={from:{...a},to:{...s,row:u+o}},l=V(d,this._selectionRenderService);else return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_shrinkRow(i,t,e,n,r=g.SheetDrawingAnchorType.Position){const o=n-e+1,{from:a,to:s}=i,{row:c}=a,{row:u}=s;if(r===g.SheetDrawingAnchorType.None)return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};let d=null,l=null;if(c>n)d={from:{...a,row:c-o},to:{...s,row:u-o}},l=V(d,this._selectionRenderService);else{if(c>=e&&u<=n)return null;if(c<e&&u>n)if(r===g.SheetDrawingAnchorType.Both)d={from:{...a},to:{...s,row:u-o}},l=V(d,this._selectionRenderService);else return{newSheetTransform:W({...t},this._selectionRenderService),newTransform:t};else if(c>=e&&c<=n){if(c===e)l={...t,top:(t.top||0)-i.from.rowOffset};else{const h=this._selectionRenderService.attachRangeWithCoord({startRow:e,endRow:c-1,startColumn:a.column,endColumn:s.column});if(h==null)return;l={...t,top:(t.top||0)-h.endY+h.startY-i.from.rowOffset}}d=W(l,this._selectionRenderService)}else if(u>=e&&u<=n&&r===g.SheetDrawingAnchorType.Both){const h=this._selectionRenderService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:e-1,endRow:e-1});if(h==null)return;d={from:{...a},to:{...s,row:e-1,rowOffset:h.endY-h.startY}},l=V(d,this._selectionRenderService)}}return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===C.SetWorksheetActiveOperation.id){const t=i.params,{unitId:e,subUnitId:n}=t,r=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(r).forEach(s=>{const c=r[s];Object.keys(c).forEach(u=>{const d=c[u].data;d!=null&&Object.keys(d).forEach(l=>{s===e&&u===n?o.push(d[l]):a.push(d[l])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)}}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{wn.includes(i.id)&&requestIdleCallback(()=>{const t=i.params,{unitId:e,subUnitId:n,ranges:r}=t;this._refreshDrawingTransform(e,n,r)})}))}_refreshDrawingTransform(i,t,e){const n=this._drawingManagerService.getDrawingData(i,t),r=[];Object.keys(n).forEach(o=>{const a=n[o],{sheetTransform:s,anchorType:c=g.SheetDrawingAnchorType.Position}=a;if(c===g.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=s,{row:l,column:h}=u,{row:m,column:S}=d;for(let f=0;f<e.length;f++){const _=e[f],{startRow:R,endRow:y,startColumn:I,endColumn:D}=_;if(p.Rectangle.intersects({startRow:R,endRow:y,startColumn:I,endColumn:D},{startRow:l,endRow:m,startColumn:h,endColumn:S})||l>y||h>D){r.push({...a,transform:V(s,this._selectionRenderService)});break}}}),r.length!==0&&(this._drawingManagerService.refreshTransform(r),this._commandService.syncExecuteCommand(L.id,[i]))}};he=Sn([p.OnLifecycle(p.LifecycleStages.Rendered,he),ne(0,p.ICommandService),ne(1,j.Inject(C.SheetInterceptorService)),ne(2,g.ISheetDrawingService),ne(3,P.IDrawingManagerService),ne(4,x.ISelectionRenderService),ne(5,p.IUniverInstanceService)],he);var _n=Object.defineProperty,Cn=Object.getOwnPropertyDescriptor,In=(i,t,e,n)=>{for(var r=n>1?void 0:n?Cn(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&_n(t,e,r),r},ee=(i,t)=>(e,n)=>t(e,n,i);function yn(i,t,e,n){const{scaleX:r,scaleY:o}=t.getAncestorScale(),a=t.getViewport(x.VIEWPORT_KEY.VIEW_MAIN),s={left:!0,top:!0};if(!a)return{...i,absolute:s};const{left:c,right:u,top:d,bottom:l}=i,h=n.getFreeze(),{startColumn:m,startRow:S,xSplit:f,ySplit:_}=h,R=e.getNoMergeCellPositionByIndexWithNoHeader(S-_,m-f),y=e.getNoMergeCellPositionByIndexWithNoHeader(S,m),{rowHeaderWidth:I,columnHeaderHeight:D}=e,w=y.startX-R.startX,b=y.startY-R.startY,{top:v,left:N,viewportScrollX:T,viewportScrollY:$}=a;let U,E;c<N?(s.left=!0,U=(w+I+(c-N))*r,E=Math.max(Math.min((w+I+(u-N))*r,(w+I)*r),(u-T)*r)):(s.left=!1,U=Math.max((c-T)*r,(w+I)*r),E=Math.max((u-T)*r,(w+I)*r));let M,G;return d<v?(s.top=!0,M=(b+D+(d-v))*o,G=Math.max(Math.min((b+D+(u-v))*o,(b+D)*o),(l-$)*o)):(s.top=!1,M=Math.max((d-$)*o,(b+D)*o),G=Math.max((l-$)*o,(b+D)*o)),{left:U,right:E,top:M,bottom:G,absolute:s}}const _e=(i,t,e,n)=>{const{scene:r}=t,{left:o,top:a,width:s,height:c,angle:u}=i,d={left:o,right:o+s,top:a,bottom:a+c},l=yn(d,r,e,n);return{startX:l.left,endX:l.right,startY:l.top,endY:l.bottom,rotate:u,width:s,height:c,absolute:l.absolute}};O.SheetCanvasFloatDomManagerService=class extends p.Disposable{constructor(e,n,r,o,a,s,c){super();K(this,"_domLayerMap",new Map);K(this,"_domLayerInfoMap",new Map);K(this,"_transformChange$",new te.Subject);K(this,"transformChange$",this._transformChange$.asObservable());K(this,"_remove$",new te.Subject);K(this,"remove$",this._remove$.asObservable());this._renderManagerService=e,this._univerInstanceService=n,this._commandService=r,this._drawingManagerService=o,this._selectionRenderService=a,this._canvasFloatDomService=s,this._sheetDrawingService=c,this._drawingAddListener(),this._scrollUpdateListener(),this._featureUpdateListener(),this._deleteListener()}_ensureMap(e,n){let r=this._domLayerMap.get(e);r||(r=new Map,this._domLayerMap.set(e,r));let o=r.get(n);return o||(o=new Map,r.set(n,o)),o}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;const n=this._renderManagerService.getRenderById(e),r=n==null?void 0:n.scene;if(n==null||r==null)return null;const o=r.getTransformerByCreate(),a=n.engine.getCanvasElement();return{scene:r,transformer:o,renderObject:n,canvas:a}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(n=>{var Be;const{unitId:r,subUnitId:o,drawingId:a}=n,s=C.getSheetCommandTarget(this._univerInstanceService,{unitId:r,subUnitId:o}),c=this._drawingManagerService.getDrawingByParam(n),u=(Be=this._renderManagerService.getRenderById(r))==null?void 0:Be.with(x.SheetSkeletonManagerService).getUnitSkeleton(r,o);if(c==null||s==null||u==null)return;const{transform:d,drawingType:l}=c;if(l!==p.DrawingTypeEnum.DRAWING_DOM)return;const h=this._getSceneAndTransformerByDrawingSearch(r);if(h==null)return;const{scene:m,canvas:S}=h;if(d==null)return!0;const{left:f,top:_,width:R,height:y,angle:I,flipX:D,flipY:w,skewX:b,skewY:v}=d,N=P.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:o,drawingId:a}),T=m.getObject(N);if(T!=null){T.transformByState({left:f,top:_,width:R,height:y,angle:I,flipX:D,flipY:w,skewX:b,skewY:v});return}const $={left:f,top:_,width:R,height:y,zIndex:this._drawingManagerService.getDrawingOrder(r,o).length-1},U=new F.Rect(N,$);m.addObject(U,F.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(U);const E=new p.DisposableCollection,M=_e(U,h.renderObject,u.skeleton,s.worksheet),G=new te.BehaviorSubject(M),z={dispose:E,rect:U,position$:G,unitId:r,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:G,id:a,componentKey:c.componentKey,onPointerDown:H=>{S.dispatchEvent(new PointerEvent(H.type,H))},onPointerMove:H=>{S.dispatchEvent(new PointerEvent(H.type,H))},onPointerUp:H=>{S.dispatchEvent(new PointerEvent(H.type,H))},onWheel:H=>{S.dispatchEvent(new WheelEvent(H.type,H))}});const Ge=U.onTransformChangeObservable.add(()=>{const H=_e(U,h.renderObject,u.skeleton,s.worksheet);G.next(H)});E.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),Ge&&E.add(Ge),this._domLayerInfoMap.set(a,z)})}))}_scrollUpdateListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var r,o;const n=(a,s)=>{var m;const c=this._getSceneAndTransformerByDrawingSearch(a),u=this._ensureMap(a,s),d=Array.from(u.keys()),l=C.getSheetCommandTarget(this._univerInstanceService,{unitId:a,subUnitId:s}),h=(m=this._renderManagerService.getRenderById(a))==null?void 0:m.with(x.SheetSkeletonManagerService).getUnitSkeleton(a,s);!c||!l||!h||d.forEach(S=>{const f=this._domLayerInfoMap.get(S);if(f){const _=_e(f.rect,c.renderObject,h.skeleton,l.worksheet);f.position$.next(_)}})};if(e.id===x.SetScrollOperation.id){const a=e.params,{unitId:s,sheetId:c}=a;n(s,c)}else if(e.id===x.SetZoomRatioOperation.id){const a=e.params,{unitId:s}=a;Array.from((o=(r=this._domLayerMap.get(s))==null?void 0:r.keys())!=null?o:[]).forEach(u=>{n(s,u)})}else if(e.id===C.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=e.params;n(a,s)}}))}_getPosition(e){const{startX:n,endX:r,startY:o,endY:a}=e,s=this._selectionRenderService.getSelectionCellByPosition(n,o);if(s==null)return;const c={column:s.actualColumn,columnOffset:n-s.startX,row:s.actualRow,rowOffset:o-s.startY},u=this._selectionRenderService.getSelectionCellByPosition(r,a);if(u==null)return;const d={column:u.actualColumn,columnOffset:r-u.startX,row:u.actualRow,rowOffset:a-u.startY};return{from:c,to:d}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(n=>{const r=this._drawingManagerService.getDrawingByParam(n);if(!r||r.drawingType!==p.DrawingTypeEnum.DRAWING_DOM)return;const o={...r.transform};this._transformChange$.next({id:n.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(n=>{this._removeDom(n.drawingId)})}))}addFloatDomToPosition(e){const n=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:r,subUnitId:o}=n,{initPosition:a,componentKey:s}=e,c=p.Tools.generateRandomId(),u=this._getPosition(a);if(u==null)return;const d={unitId:r,subUnitId:o,drawingId:c,drawingType:p.DrawingTypeEnum.DRAWING_DOM,componentKey:s,sheetTransform:u,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY}};return this._commandService.executeCommand(we.id,{unitId:r,drawings:[d]}),this._ensureMap(r,o).set(c,e),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(e,n=!1){const r=this._domLayerInfoMap.get(e);if(!r)return;const{unitId:o,subUnitId:a}=r,s=this._ensureMap(o,a);this._domLayerInfoMap.delete(e),s.delete(e),r.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(r.rect),n){const u=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:e});if(!u)return;const d=this._sheetDrawingService.getBatchRemoveOp([u]),{redo:l,objects:h}=d;this._commandService.syncExecuteCommand(g.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:l,objects:h,type:g.DrawingApplyType.REMOVE})}}},O.SheetCanvasFloatDomManagerService=In([ee(0,j.Inject(F.IRenderManagerService)),ee(1,p.IUniverInstanceService),ee(2,j.Inject(p.ICommandService)),ee(3,P.IDrawingManagerService),ee(4,x.ISelectionRenderService),ee(5,j.Inject(B.CanvasFloatDomService)),ee(6,g.ISheetDrawingService)],O.SheetCanvasFloatDomManagerService);var Mn=Object.defineProperty,Dn=Object.getOwnPropertyDescriptor,Rn=(i,t,e,n)=>{for(var r=n>1?void 0:n?Dn(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Mn(t,e,r),r},fe=(i,t)=>(e,n)=>t(e,n,i);let Se=class extends p.Disposable{constructor(i,t,e,n){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=t,this._drawingManagerService=e,this._renderManagerService=n,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,t,e)=>{const{unitId:n,scene:r,subUnitId:o}=t,a=this._drawingManagerService.getDrawingDataForUnit(n),s=a==null?void 0:a[o];return s&&s.order.forEach(c=>{this._drawingRenderService.renderDrawing(s.data[c],r)}),e()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,t,e)=>{const{unitId:n,subUnitId:r}=t,o=this._renderManagerService.getRenderById(n);if(!o)return e(i);const a=o.with(x.SheetSkeletonManagerService).getUnitSkeleton(n,r);if(!a)return e(i);const s=this._drawingManagerService.getDrawingDataForUnit(n),c=s==null?void 0:s[t.subUnitId];if(!c)return e(i);const{scaleX:u,scaleY:d}=o.scene,l=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},h=c.order.map(m=>c.data[m]).filter(m=>m.drawingType!==P.DrawingTypeEnum.DRAWING_DOM);return h.length?(h.forEach(m=>{if(!m.groupId&&m.transform&&p.Tools.isDefine(m.transform.left)&&p.Tools.isDefine(m.transform.top)&&p.Tools.isDefine(m.transform.width)&&p.Tools.isDefine(m.transform.height)){const S=a.skeleton.getCellPositionByOffset(m.transform.left,m.transform.top,u,d,{x:0,y:0}),f=a.skeleton.getCellPositionByOffset(m.transform.left+m.transform.width,m.transform.top+m.transform.height,u,d,{x:0,y:0});S.column<l.startColumn&&(l.startColumn=S.column),S.row<l.startRow&&(l.startRow=S.row),l.endRow<f.row&&(l.endRow=f.row),l.endColumn<f.column&&(l.endColumn=f.column)}}),e(l)):e(i)}}))}};Se=Rn([p.OnLifecycle(p.LifecycleStages.Rendered,Se),fe(0,j.Inject(x.SheetPrintInterceptorService)),fe(1,j.Inject(Z.DrawingRenderService)),fe(2,P.IDrawingManagerService),fe(3,F.IRenderManagerService)],Se);var je=Object.defineProperty,Tn=Object.getOwnPropertyDescriptor,On=(i,t,e)=>t in i?je(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Pn=(i,t,e,n)=>{for(var r=n>1?void 0:n?Tn(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&je(t,e,r),r},Le=(i,t)=>(e,n)=>t(e,n,i),We=(i,t,e)=>(On(i,typeof t!="symbol"?t+"":t,e),e);const bn="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends p.Plugin{constructor(e={},n,r){super();K(this,"_pluginConfig");this._injector=n,this._localeService=r,this._pluginConfig=p.Tools.deepMerge({},gn,e)}onStarting(e){super.onStarting(e),this._initDependencies(e)}_initDependencies(e){[[O.SheetCanvasFloatDomManagerService],[ae,{useFactory:()=>this._injector.createInstance(ae,this._pluginConfig)}],[pe],[le],[he],[Se]].forEach(r=>e.add(r))}},We(O.UniverSheetsDrawingUIPlugin,"type",p.UniverInstanceType.UNIVER_SHEET),We(O.UniverSheetsDrawingUIPlugin,"pluginName",bn),O.UniverSheetsDrawingUIPlugin=Pn([p.DependentOn(P.UniverDrawingPlugin,Z.UniverDrawingUIPlugin,g.UniverSheetsDrawingPlugin),Le(1,j.Inject(j.Injector)),Le(2,j.Inject(p.LocaleService))],O.UniverSheetsDrawingUIPlugin),Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-drawing-ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"require": "./lib/cjs/*",
|
|
33
33
|
"types": "./lib/types/index.d.ts"
|
|
34
34
|
},
|
|
35
|
-
"./
|
|
36
|
-
"./
|
|
35
|
+
"./lib/*": "./lib/*",
|
|
36
|
+
"./locale/*": "./lib/locale/*.json"
|
|
37
37
|
},
|
|
38
38
|
"main": "./lib/cjs/index.js",
|
|
39
39
|
"module": "./lib/es/index.js",
|
|
@@ -47,24 +47,20 @@
|
|
|
47
47
|
"files": [
|
|
48
48
|
"lib"
|
|
49
49
|
],
|
|
50
|
-
"engines": {
|
|
51
|
-
"node": ">=16.0.0",
|
|
52
|
-
"npm": ">=8.0.0"
|
|
53
|
-
},
|
|
54
50
|
"peerDependencies": {
|
|
55
51
|
"@wendellhu/redi": "0.15.2",
|
|
56
52
|
"clsx": ">=2.0.0",
|
|
57
53
|
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
|
58
54
|
"rxjs": ">=7.0.0",
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/
|
|
61
|
-
"@univerjs/drawing
|
|
62
|
-
"@univerjs/drawing": "0.1.
|
|
63
|
-
"@univerjs/engine-render": "0.1.
|
|
64
|
-
"@univerjs/sheets": "0.1.
|
|
65
|
-
"@univerjs/sheets-
|
|
66
|
-
"@univerjs/
|
|
67
|
-
"@univerjs/
|
|
55
|
+
"@univerjs/design": "0.1.14",
|
|
56
|
+
"@univerjs/core": "0.1.14",
|
|
57
|
+
"@univerjs/drawing": "0.1.14",
|
|
58
|
+
"@univerjs/drawing-ui": "0.1.14",
|
|
59
|
+
"@univerjs/engine-render": "0.1.14",
|
|
60
|
+
"@univerjs/sheets": "0.1.14",
|
|
61
|
+
"@univerjs/sheets-ui": "0.1.14",
|
|
62
|
+
"@univerjs/ui": "0.1.14",
|
|
63
|
+
"@univerjs/sheets-drawing": "0.1.14"
|
|
68
64
|
},
|
|
69
65
|
"dependencies": {
|
|
70
66
|
"@univerjs/icons": "^0.1.56"
|
|
@@ -78,16 +74,30 @@
|
|
|
78
74
|
"typescript": "^5.4.5",
|
|
79
75
|
"vite": "^5.2.12",
|
|
80
76
|
"vitest": "^1.6.0",
|
|
81
|
-
"@univerjs/
|
|
82
|
-
"@univerjs/
|
|
83
|
-
"@univerjs/
|
|
84
|
-
"@univerjs/
|
|
85
|
-
"@univerjs/
|
|
86
|
-
"@univerjs/
|
|
87
|
-
"@univerjs/sheets
|
|
88
|
-
"@univerjs/ui": "0.1.
|
|
89
|
-
"@univerjs/
|
|
90
|
-
"@univerjs/
|
|
77
|
+
"@univerjs/drawing-ui": "0.1.14",
|
|
78
|
+
"@univerjs/core": "0.1.14",
|
|
79
|
+
"@univerjs/engine-render": "0.1.14",
|
|
80
|
+
"@univerjs/drawing": "0.1.14",
|
|
81
|
+
"@univerjs/design": "0.1.14",
|
|
82
|
+
"@univerjs/shared": "0.1.14",
|
|
83
|
+
"@univerjs/sheets": "0.1.14",
|
|
84
|
+
"@univerjs/sheets-ui": "0.1.14",
|
|
85
|
+
"@univerjs/sheets-drawing": "0.1.14",
|
|
86
|
+
"@univerjs/ui": "0.1.14"
|
|
87
|
+
},
|
|
88
|
+
"univerSpace": {
|
|
89
|
+
".": {
|
|
90
|
+
"import": "./lib/es/index.js",
|
|
91
|
+
"require": "./lib/cjs/index.js",
|
|
92
|
+
"types": "./lib/types/index.d.ts"
|
|
93
|
+
},
|
|
94
|
+
"./*": {
|
|
95
|
+
"import": "./lib/es/*",
|
|
96
|
+
"require": "./lib/cjs/*",
|
|
97
|
+
"types": "./lib/types/index.d.ts"
|
|
98
|
+
},
|
|
99
|
+
"./lib/*": "./lib/*",
|
|
100
|
+
"./locale/*": "./lib/locale/*.json"
|
|
91
101
|
},
|
|
92
102
|
"scripts": {
|
|
93
103
|
"test": "vitest run",
|