@univerjs/sheets-drawing-ui 0.1.16 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +1441 -1181
- package/lib/types/basics/transform-position.d.ts +4 -3
- package/lib/types/controllers/sheet-drawing-copy-paste.controller.d.ts +16 -0
- package/lib/types/controllers/sheet-drawing-transform-affected.controller.d.ts +8 -4
- package/lib/types/controllers/sheet-drawing-update.controller.d.ts +9 -5
- package/lib/types/index.d.ts +12 -0
- package/lib/types/plugin.d.ts +3 -1
- package/lib/types/views/sheet-image-panel/SheetDrawingPanel.d.ts +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +25 -25
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Nullable } from '@univerjs/core';
|
|
2
|
+
import { ITransformState } from '@univerjs/drawing';
|
|
2
3
|
import { ISheetDrawingPosition } from '@univerjs/sheets-drawing';
|
|
3
|
-
import { ISelectionRenderService } from '@univerjs/sheets-ui';
|
|
4
|
+
import { ISelectionRenderService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
|
|
4
5
|
|
|
5
|
-
export declare function drawingPositionToTransform(position: ISheetDrawingPosition, selectionRenderService: ISelectionRenderService): Nullable<ITransformState>;
|
|
6
|
+
export declare function drawingPositionToTransform(position: ISheetDrawingPosition, selectionRenderService: ISelectionRenderService, sheetSkeletonManagerService: SheetSkeletonManagerService): Nullable<ITransformState>;
|
|
6
7
|
export declare function transformToDrawingPosition(transform: ITransformState, selectionRenderService: ISelectionRenderService): Nullable<ISheetDrawingPosition>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Disposable } from '@univerjs/core';
|
|
2
|
+
import { ISelectionRenderService, ISheetClipboardService } from '@univerjs/sheets-ui';
|
|
3
|
+
import { Injector } from '@wendellhu/redi';
|
|
4
|
+
import { ISheetDrawingService } from '@univerjs/sheets-drawing';
|
|
5
|
+
|
|
6
|
+
export declare class SheetsDrawingCopyPasteController extends Disposable {
|
|
7
|
+
private _sheetClipboardService;
|
|
8
|
+
private readonly _selectionRenderService;
|
|
9
|
+
private readonly _sheetDrawingService;
|
|
10
|
+
private _injector;
|
|
11
|
+
private _copyInfo;
|
|
12
|
+
constructor(_sheetClipboardService: ISheetClipboardService, _selectionRenderService: ISelectionRenderService, _sheetDrawingService: ISheetDrawingService, _injector: Injector);
|
|
13
|
+
private _initCopyPaste;
|
|
14
|
+
private _collect;
|
|
15
|
+
private _generateMutations;
|
|
16
|
+
}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
2
|
-
import { ISelectionRenderService } from '@univerjs/sheets-ui';
|
|
1
|
+
import { Workbook, Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
2
|
+
import { ISelectionRenderService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
|
|
3
3
|
import { IDrawingManagerService } from '@univerjs/drawing';
|
|
4
4
|
import { SheetInterceptorService } from '@univerjs/sheets';
|
|
5
5
|
import { ISheetDrawingService } from '@univerjs/sheets-drawing';
|
|
6
|
+
import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
|
|
6
7
|
|
|
7
|
-
export declare class SheetDrawingTransformAffectedController extends Disposable {
|
|
8
|
+
export declare class SheetDrawingTransformAffectedController extends Disposable implements IRenderModule {
|
|
9
|
+
private readonly _context;
|
|
8
10
|
private readonly _commandService;
|
|
9
11
|
private readonly _sheetInterceptorService;
|
|
10
12
|
private readonly _sheetDrawingService;
|
|
11
13
|
private readonly _drawingManagerService;
|
|
12
14
|
private readonly _selectionRenderService;
|
|
13
15
|
private readonly _univerInstanceService;
|
|
14
|
-
|
|
16
|
+
private readonly _sheetSkeletonManagerService;
|
|
17
|
+
constructor(_context: IRenderContext<Workbook>, _commandService: ICommandService, _sheetInterceptorService: SheetInterceptorService, _sheetDrawingService: ISheetDrawingService, _drawingManagerService: IDrawingManagerService, _selectionRenderService: ISelectionRenderService, _univerInstanceService: IUniverInstanceService, _sheetSkeletonManagerService: SheetSkeletonManagerService);
|
|
15
18
|
private _init;
|
|
16
19
|
private _sheetInterceptorListener;
|
|
17
20
|
private _getRangeMoveUndo;
|
|
@@ -23,6 +26,7 @@ export declare class SheetDrawingTransformAffectedController extends Disposable
|
|
|
23
26
|
private _getDrawingUndoForRowAndColSize;
|
|
24
27
|
private _getUnitIdAndSubUnitId;
|
|
25
28
|
private _moveRowInterceptor;
|
|
29
|
+
private _moveRangeInterceptor;
|
|
26
30
|
private _moveColInterceptor;
|
|
27
31
|
private _expandCol;
|
|
28
32
|
private _shrinkCol;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Disposable, ICommandService, IContextService, IUniverInstanceService, LocaleService } from '@univerjs/core';
|
|
1
|
+
import { Workbook, Disposable, ICommandService, IContextService, IUniverInstanceService, LocaleService } from '@univerjs/core';
|
|
2
2
|
import { IDrawingManagerService, IImageIoService } from '@univerjs/drawing';
|
|
3
3
|
import { ISheetDrawingService } from '@univerjs/sheets-drawing';
|
|
4
4
|
import { SelectionManagerService } from '@univerjs/sheets';
|
|
5
|
-
import { ISelectionRenderService } from '@univerjs/sheets-ui';
|
|
5
|
+
import { ISelectionRenderService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
|
|
6
6
|
import { IMessageService } from '@univerjs/ui';
|
|
7
|
-
import { IRenderManagerService } from '@univerjs/engine-render';
|
|
7
|
+
import { IRenderContext, IRenderModule, IRenderManagerService } from '@univerjs/engine-render';
|
|
8
8
|
|
|
9
|
-
export declare class SheetDrawingUpdateController extends Disposable {
|
|
9
|
+
export declare class SheetDrawingUpdateController extends Disposable implements IRenderModule {
|
|
10
|
+
private readonly _context;
|
|
10
11
|
private readonly _commandService;
|
|
11
12
|
private readonly _univerInstanceService;
|
|
12
13
|
private readonly _selectionManagerService;
|
|
@@ -18,7 +19,8 @@ export declare class SheetDrawingUpdateController extends Disposable {
|
|
|
18
19
|
private readonly _messageService;
|
|
19
20
|
private readonly _localeService;
|
|
20
21
|
private readonly _renderManagerService;
|
|
21
|
-
|
|
22
|
+
private readonly _sheetSkeletonManagerService;
|
|
23
|
+
constructor(_context: IRenderContext<Workbook>, _commandService: ICommandService, _univerInstanceService: IUniverInstanceService, _selectionManagerService: SelectionManagerService, _selectionRenderService: ISelectionRenderService, _imageIoService: IImageIoService, _sheetDrawingService: ISheetDrawingService, _drawingManagerService: IDrawingManagerService, _contextService: IContextService, _messageService: IMessageService, _localeService: LocaleService, _renderManagerService: IRenderManagerService, _sheetSkeletonManagerService: SheetSkeletonManagerService);
|
|
22
24
|
private _init;
|
|
23
25
|
/**
|
|
24
26
|
* Upload image to cell or float image
|
|
@@ -32,4 +34,6 @@ export declare class SheetDrawingUpdateController extends Disposable {
|
|
|
32
34
|
private _updateImageListener;
|
|
33
35
|
private _groupDrawingListener;
|
|
34
36
|
private _focusDrawingListener;
|
|
37
|
+
private _drawingAddListener;
|
|
38
|
+
private _registerDrawing;
|
|
35
39
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -15,3 +15,15 @@
|
|
|
15
15
|
*/
|
|
16
16
|
export { UniverSheetsDrawingUIPlugin } from './plugin';
|
|
17
17
|
export { SheetCanvasFloatDomManagerService, type ICanvasFloatDom } from './services/canvas-float-dom-manager.service';
|
|
18
|
+
export { DeleteDrawingsCommand } from './commands/commands/delete-drawings.command';
|
|
19
|
+
export { GroupSheetDrawingCommand } from './commands/commands/group-sheet-drawing.command';
|
|
20
|
+
export { InsertSheetDrawingCommand } from './commands/commands/insert-sheet-drawing.command';
|
|
21
|
+
export { MoveDrawingsCommand } from './commands/commands/move-drawings.command';
|
|
22
|
+
export { RemoveSheetDrawingCommand } from './commands/commands/remove-sheet-drawing.command';
|
|
23
|
+
export { SetDrawingArrangeCommand } from './commands/commands/set-drawing-arrange.command';
|
|
24
|
+
export { SetSheetDrawingCommand } from './commands/commands/set-sheet-drawing.command';
|
|
25
|
+
export { UngroupSheetDrawingCommand } from './commands/commands/ungroup-sheet-drawing.command';
|
|
26
|
+
export { ClearSheetDrawingTransformerOperation } from './commands/operations/clear-drawing-transformer.operation';
|
|
27
|
+
export { EditSheetDrawingOperation } from './commands/operations/edit-sheet-drawing.operation';
|
|
28
|
+
export { InsertFloatImageOperation, InsertCellImageOperation } from './commands/operations/insert-image.operation';
|
|
29
|
+
export { SidebarSheetDrawingOperation } from './commands/operations/open-drawing-panel.operation';
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { LocaleService, Plugin, UniverInstanceType } from '@univerjs/core';
|
|
2
2
|
import { Injector } from '@wendellhu/redi';
|
|
3
|
+
import { IRenderManagerService } from '@univerjs/engine-render';
|
|
3
4
|
import { IUniverSheetsDrawingConfig } from './controllers/sheet-drawing.controller';
|
|
4
5
|
|
|
5
6
|
export declare class UniverSheetsDrawingUIPlugin extends Plugin {
|
|
6
7
|
protected _injector: Injector;
|
|
7
8
|
private readonly _localeService;
|
|
9
|
+
private readonly _renderManagerService;
|
|
8
10
|
static type: UniverInstanceType;
|
|
9
11
|
static pluginName: string;
|
|
10
12
|
private _pluginConfig;
|
|
11
|
-
constructor(config: Partial<IUniverSheetsDrawingConfig> | undefined, _injector: Injector, _localeService: LocaleService);
|
|
13
|
+
constructor(config: Partial<IUniverSheetsDrawingConfig> | undefined, _injector: Injector, _localeService: LocaleService, _renderManagerService: IRenderManagerService);
|
|
12
14
|
onStarting(_injector: Injector): void;
|
|
13
15
|
private _initDependencies;
|
|
14
16
|
}
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(b,g){typeof exports=="object"&&typeof module<"u"?g(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"],g):(b=typeof globalThis<"u"?globalThis:b||self,g(b.UniverSheetsDrawingUi={},b.UniverCore,b["@wendellhu/redi"],b.UniverDrawingUi,b.UniverSheetsDrawing,b.UniverDrawing,b.UniverEngineRender,b.UniverSheetsUi,b.rxjs,b.UniverUi,b["@wendellhu/redi/react-bindings"],b.UniverSheets,b.React,b.UniverDesign,b.clsx))})(this,function(b,g,j,Q,h,E,U,X,B,$,z,w,O,J,ce){"use strict";var Gn=Object.defineProperty;var $n=(b,g,j)=>g in b?Gn(b,g,{enumerable:!0,configurable:!0,writable:!0,value:j}):b[g]=j;var q=(b,g,j)=>$n(b,typeof g!="symbol"?g+"":g,j);const W={id:"sheet.operation.clear-drawing-transformer",type:g.CommandType.MUTATION,handler:(r,n)=>{const i=r.get(U.IRenderManagerService);return n.forEach(e=>{var t,o;(o=(t=i.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},_e={id:"sheet.command.remove-sheet-image",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService),t=r.get(h.ISheetDrawingService);if(!n)return!1;const{drawings:o}=n,s=[];o.forEach(S=>{const{unitId:f}=S;s.push(f)});const a=t.getBatchRemoveOp(o),{unitId:c,subUnitId:u,undo:d,redo:l,objects:m}=a;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:c,subUnitId:u,op:l,objects:m,type:h.DrawingApplyType.REMOVE})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:d,objects:m,type:h.DrawingApplyType.INSERT}},{id:W.id,params:s}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:l,objects:m,type:h.DrawingApplyType.REMOVE}},{id:W.id,params:s}]}),!0):!1}},ye="COMPONENT_SHEET_DRAWING_PANEL",De={id:"sidebar.operation.sheet-image",type:g.CommandType.COMMAND,handler:async(r,n)=>{const i=r.get($.ISidebarService),e=r.get(g.LocaleService),t=r.get(g.IUniverInstanceService),o=r.get(E.IDrawingManagerService);if(!w.getSheetCommandTarget(t))return!1;switch(n.value){case"open":i.open({header:{title:e.t("sheetImage.panel.title")},children:{label:ye},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:i.close();break}return!0}},Me={id:"sheet.operation.edit-sheet-image",type:g.CommandType.OPERATION,handler:(r,n)=>{const i=r.get(E.IDrawingManagerService),e=r.get(g.ICommandService);return n==null?!1:(i.focusDrawing([n]),e.executeCommand(De.id,{value:"open"}),!0)}},le={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},He=()=>{const r=z.useDependency(E.IImageIoService),n=z.useDependency(g.LocaleService),[i,e]=O.useState(0);return O.useEffect(()=>{const t=r.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[r]),O.createElement("div",{style:{display:i>0?"block":"none"},className:le.uploadLoading},O.createElement("div",{className:le.uploadLoadingBody},O.createElement("div",{className:le.uploadLoadingBodyAnimation}),O.createElement("div",{className:le.uploadLoadingBodyText},`${n.t("uploadLoading.loading")}: ${i}`)))};var Ye=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,xe=(r,n,i,e)=>{for(var t=e>1?void 0:e?Xe(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&Ye(n,i,t),t},ee=(r,n)=>(i,e)=>n(i,e,r);let de=class extends g.RxDisposable{constructor(n,i,e,t,o,s,a){super();q(this,"_initImagePopupMenu",new Set);this._injector=n,this._drawingManagerService=i,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=s,this._uiPartsService=a,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET).pipe(B.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(g.UniverInstanceType.UNIVER_SHEET).pipe(B.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(g.UniverInstanceType.UNIVER_SHEET).forEach(n=>this._create(n)),this._uiPartsService.registerComponent($.BuiltInUIPart.CONTENT,()=>z.connectInjector(He,this._injector))}_dispose(n){const i=n.getUnitId();this._renderManagerService.removeRender(i)}_create(n){if(!n)return;const i=n.getUnitId();this._renderManagerService.has(i)&&!this._initImagePopupMenu.has(i)&&(this._popupMenuListener(i),this._initImagePopupMenu.add(i))}_hasCropObject(n){const i=n.getAllObjects();for(const e of i)if(e instanceof Q.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const i=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!i)return;const e=i.getTransformerByCreate();if(!e)return;const t=[];this.disposeWithMe(g.toDisposable(e.onCreateControlObservable.add(()=>{if(this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(i))return;const s=e.getSelectedObjectMap();if(s.size>1){t.forEach(p=>p.dispose());return}const a=s.values().next().value;if(!a)return;const c=a.oKey,u=this._drawingManagerService.getDrawingOKey(c);if(!u)return;const{unitId:d,subUnitId:l,drawingId:m}=u;t.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:Q.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(d,l,m)}}))),this._drawingManagerService.focusDrawing([{unitId:d,subUnitId:l,drawingId:m}])}))),this.disposeWithMe(g.toDisposable(e.onClearControlObservable.add(()=>{t.forEach(s=>s.dispose()),this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}))),this.disposeWithMe(g.toDisposable(e.onChangingObservable.add(()=>{t.forEach(s=>s.dispose())})))}_getImageMenuItems(n,i,e){return[{label:"image-popup.edit",index:0,commandId:Me.id,commandParams:{unitId:n,subUnitId:i,drawingId:e},disable:!1},{label:"image-popup.delete",index:1,commandId:_e.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:i,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:Q.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:i,drawingId:e},disable:!1},{label:"image-popup.reset",index:3,commandId:Q.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:i,drawingId:e}],disable:!1}]}};de=xe([g.OnLifecycle(g.LifecycleStages.Steady,de),ee(0,j.Inject(j.Injector)),ee(1,E.IDrawingManagerService),ee(2,j.Inject(X.SheetCanvasPopManagerService)),ee(3,U.IRenderManagerService),ee(4,g.IUniverInstanceService),ee(5,g.IContextService),ee(6,j.Inject($.IUIPartsService))],de);const ue={id:"sheet.operation.insert-float-image",type:g.CommandType.OPERATION,handler:(r,n)=>!0},me={id:"sheet.operation.insert-cell-image",type:g.CommandType.OPERATION,handler:(r,n)=>!0},Ie={id:"sheet.command.insert-sheet-image",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService),t=r.get(h.ISheetDrawingService);if(!n)return!1;const o=n.drawings,s=o.map(S=>S.unitId),a=t.getBatchAddOp(o),{unitId:c,subUnitId:u,undo:d,redo:l,objects:m}=a;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:u,objects:m,type:h.DrawingApplyType.INSERT})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:u,objects:m,type:h.DrawingApplyType.REMOVE}},{id:W.id,params:s}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:u,objects:m,type:h.DrawingApplyType.INSERT}},{id:W.id,params:s}]}),!0):!1}},pe={id:"sheet.command.set-sheet-image",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService),t=r.get(h.ISheetDrawingService);if(!n)return!1;const{drawings:o}=n,s=t.getBatchUpdateOp(o),{unitId:a,subUnitId:c,undo:u,redo:d,objects:l}=s;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:a,subUnitId:c,op:d,objects:l,type:h.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:c,op:u,objects:l,type:h.DrawingApplyType.UPDATE}},{id:W.id,params:[a]}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:c,op:d,objects:l,type:h.DrawingApplyType.UPDATE}},{id:W.id,params:[a]}]}),!0):!1}},Te={id:"sheet.command.set-drawing-arrange",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService);if(!n)return!1;const t=r.get(h.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:a,arrangeType:c}=n,u={unitId:o,subUnitId:s,drawingIds:a};let d;if(c===E.ArrangeTypeEnum.forward?d=t.getForwardDrawingsOp(u):c===E.ArrangeTypeEnum.backward?d=t.getBackwardDrawingOp(u):c===E.ArrangeTypeEnum.front?d=t.getFrontDrawingsOp(u):c===E.ArrangeTypeEnum.back&&(d=t.getBackDrawingsOp(u)),d==null)return!1;const{objects:l,redo:m,undo:p}=d;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:m,unitId:o,subUnitId:s,objects:l,type:h.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:p,unitId:o,subUnitId:s,objects:l,type:h.DrawingApplyType.ARRANGE}}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:s,objects:l,type:h.DrawingApplyType.ARRANGE}}]}),!0):!1}};function ke(r){const n=[];return r.forEach(i=>{const{parent:e,children:t}=i,{unitId:o,subUnitId:s,drawingId:a}=e,c=U.getGroupState(0,0,t.map(l=>l.transform||{})),u=t.map(l=>{const m=l.transform||{left:0,top:0},{unitId:p,subUnitId:S,drawingId:f}=l;return{unitId:p,subUnitId:S,drawingId:f,transform:{...m,left:m.left-c.left,top:m.top-c.top},groupId:a}}),d={unitId:o,subUnitId:s,drawingId:a,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:c};n.push({parent:d,children:u})}),n}function Ke(r){const n=[];return r.forEach(i=>{const{parent:e,children:t}=i,{unitId:o,subUnitId:s,drawingId:a,transform:c={width:0,height:0}}=e;if(c==null)return;const u=t.map(l=>{const{transform:m}=l,{unitId:p,subUnitId:S,drawingId:f}=l,v=U.transformObjectOutOfGroup(m||{},c,c.width||0,c.height||0);return{unitId:p,subUnitId:S,drawingId:f,transform:v,groupId:void 0}}),d={unitId:o,subUnitId:s,drawingId:a,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:d,children:u})}),n}const Re={id:"sheet.command.group-sheet-image",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService),t=r.get(h.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:p,children:S})=>{o.push(p.unitId),S.forEach(f=>{o.push(f.unitId)})});const s=t.getGroupDrawingOp(n),{unitId:a,subUnitId:c,undo:u,redo:d,objects:l}=s;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:d,unitId:a,subUnitId:c,objects:l,type:h.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:Ke(l),type:h.DrawingApplyType.UNGROUP}},{id:W.id,params:o}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:d,unitId:a,subUnitId:c,objects:l,type:h.DrawingApplyType.GROUP}},{id:W.id,params:o}]}),!0):!1}},be={id:"sheet.command.ungroup-sheet-image",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService),t=r.get(h.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:p,children:S})=>{o.push(p.unitId),S.forEach(f=>{o.push(f.unitId)})});const s=t.getUngroupDrawingOp(n),{unitId:a,subUnitId:c,undo:u,redo:d,objects:l}=s;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:d,unitId:a,subUnitId:c,objects:l,type:h.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:ke(l),type:h.DrawingApplyType.GROUP}},{id:W.id,params:o}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:d,unitId:a,subUnitId:c,objects:l,type:h.DrawingApplyType.UNGROUP}},{id:W.id,params:o}]}),!0):!1}};function H(r,n){const{from:i,to:e}=r,{column:t,columnOffset:o,row:s,rowOffset:a}=i,{column:c,columnOffset:u,row:d,rowOffset:l}=e,m=n.attachRangeWithCoord({startColumn:t,endColumn:t,startRow:s,endRow:s});if(m==null)return;const p=n.attachRangeWithCoord({startColumn:c,endColumn:c,startRow:d,endRow:d});if(p==null)return;const{startX:S,startY:f}=m,{startX:v,startY:y}=p,M=U.precisionTo(S+o,1),C=U.precisionTo(f+a,1);let T=U.precisionTo(v+u-M,1),I=U.precisionTo(y+l-C,1);return m.startX===p.endX&&(T=0),m.startY===p.endY&&(I=0),{left:M,top:C,width:T,height:I}}function G(r,n){const{left:i=0,top:e=0,width:t=0,height:o=0}=r,s=n.getSelectionCellByPosition(i,e);if(s==null)return;const a={column:s.actualColumn,columnOffset:U.precisionTo(i-s.startX,1),row:s.actualRow,rowOffset:U.precisionTo(e-s.startY,1)},c=n.getSelectionCellByPosition(i+t,e+o);if(c==null)return;const u={column:c.actualColumn,columnOffset:U.precisionTo(i+t-c.startX,1),row:c.actualRow,rowOffset:U.precisionTo(e+o-c.startY,1)};return{from:a,to:u}}var ze=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Je=(r,n,i,e)=>{for(var t=e>1?void 0:e?qe(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&ze(n,i,t),t},k=(r,n)=>(i,e)=>n(i,e,r);let ge=class extends g.Disposable{constructor(r,n,i,e,t,o,s,a,c,u,d){super(),this._commandService=r,this._univerInstanceService=n,this._selectionManagerService=i,this._selectionRenderService=e,this._imageIoService=t,this._sheetDrawingService=o,this._drawingManagerService=s,this._contextService=a,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 r=>{if(r.id===me.id||r.id===ue.id){const n=r.params;if(n.files==null)return;const i=n.files.length;if(i>E.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(E.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(i),r.id===me.id?n.files.forEach(async e=>{await this._insertCellImage(e)}):n.files.forEach(async e=>{await this._insertFloatImage(e)})}}))}async _insertCellImage(r){}async _insertFloatImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(M){const C=M.message;C===E.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(E.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===E.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===E.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const i=this._getUnitInfo();if(i==null)return;const{unitId:e,subUnitId:t}=i,{imageId:o,imageSourceType:s,source:a,base64Cache:c}=n,{width:u,height:d,image:l}=await E.getImageSize(c||""),m=this._renderManagerService.getRenderById(e);if(m==null)return;const{width:p,height:S}=m.scene;this._imageIoService.addImageSourceCache(a,s,l);let f=1;if(u>E.DRAWING_IMAGE_WIDTH_LIMIT||d>E.DRAWING_IMAGE_HEIGHT_LIMIT){const M=E.DRAWING_IMAGE_WIDTH_LIMIT/u,C=E.DRAWING_IMAGE_HEIGHT_LIMIT/d;f=Math.max(M,C)}const v=this._getImagePosition(u*f,d*f,p,S);if(v==null)return;const y={unitId:e,subUnitId:t,drawingId:o,drawingType:E.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:H(v,this._selectionRenderService),sheetTransform:v};this._commandService.executeCommand(Ie.id,{unitId:e,drawings:[y]})}_getUnitInfo(){const r=this._univerInstanceService.getCurrentUnitForType(g.UniverInstanceType.UNIVER_SHEET);if(r==null)return;const n=r.getActiveSheet();if(n==null)return;const i=r.getUnitId(),e=n.getSheetId();return{unitId:i,subUnitId:e}}_getImagePosition(r,n,i,e){const t=this._selectionManagerService.getSelections();let o={startRow:0,endRow:0,startColumn:0,endColumn:0};t&&t.length>0&&(o=t[t.length-1].range);const s=this._selectionRenderService.attachRangeWithCoord(o);if(s==null)return;let{startColumn:a,startRow:c,startX:u,startY:d}=s,l=!1;if(u+r>i&&(u=i-r,u<0&&(u=0,r=i),l=!0),d+n>e&&(d=e-n,d<0&&(d=0,n=e),l=!0),l){const f=this._selectionRenderService.getSelectionCellByPosition(u,d);if(f==null)return;u=f.startX,d=f.startY,a=f.actualColumn,c=f.actualRow}const m={column:a,columnOffset:0,row:c,rowOffset:0},p=this._selectionRenderService.getSelectionCellByPosition(u+r,d+n);if(p==null)return;const S={column:p.actualColumn,columnOffset:u+r-p.startX,row:p.actualRow,rowOffset:d+n-p.startY};return{from:m,to:S}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(r=>{const{unitId:n,subUnitId:i,drawingIds:e,arrangeType:t}=r;this._commandService.executeCommand(Te.id,{unitId:n,subUnitId:i,drawingIds:e,arrangeType:t})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(r=>{const n=[];r.length!==0&&(r.forEach(i=>{const{unitId:e,subUnitId:t,drawingId:o,drawingType:s,transform:a}=i;if(a==null)return;const c=this._sheetDrawingService.getDrawingByParam({unitId:e,subUnitId:t,drawingId:o});if(c==null)return;const u=G({...c.transform,...a},this._selectionRenderService);if(u==null)return;const d={...i,transform:{...c.transform,...a,...H(u,this._selectionRenderService)},sheetTransform:{...u}};n.push(d)}),n.length>0&&this._commandService.executeCommand(pe.id,{unitId:r[0].unitId,drawings:n}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Re.id,r);const{unitId:n,subUnitId:i,drawingId:e}=r[0].parent;this._drawingManagerService.focusDrawing([{unitId:n,subUnitId:i,drawingId:e}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(r=>{this._commandService.executeCommand(be.id,r)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(r=>{r==null||r.length===0?(this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(r))}))}};ge=Je([g.OnLifecycle(g.LifecycleStages.Rendered,ge),k(0,g.ICommandService),k(1,g.IUniverInstanceService),k(2,j.Inject(w.SelectionManagerService)),k(3,X.ISelectionRenderService),k(4,E.IImageIoService),k(5,h.ISheetDrawingService),k(6,E.IDrawingManagerService),k(7,g.IContextService),k(8,$.IMessageService),k(9,j.Inject(g.LocaleService)),k(10,U.IRenderManagerService)],ge);var x=function(){return x=Object.assign||function(r){for(var n,i=1,e=arguments.length;i<e;i++){n=arguments[i];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},x.apply(this,arguments)},Ze=function(r,n){var i={};for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&n.indexOf(e)<0&&(i[e]=r[e]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(r);t<e.length;t++)n.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(r,e[t])&&(i[e[t]]=r[e[t]]);return i},Ee=O.forwardRef(function(r,n){var i=r.icon,e=r.id,t=r.className,o=r.extend,s=Ze(r,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),c=O.useRef("_".concat(nn()));return Pe(i,"".concat(e),{defIds:i.defIds,idSuffix:c.current},x({ref:n,className:a},s),o)});function Pe(r,n,i,e,t){return O.createElement(r.tag,x(x({key:n},Qe(r,i,t)),e),(en(r,i).children||[]).map(function(o,s){return Pe(o,"".concat(n,"-").concat(r.tag,"-").concat(s),i,void 0,t)}))}function Qe(r,n,i){var e=x({},r.attrs);i!=null&&i.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=i.colorChannel1);var t=n.defIds;return!t||t.length===0||(r.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+n.idSuffix),Object.entries(e).forEach(function(o){var s=o[0],a=o[1];typeof a=="string"&&(e[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),e}function en(r,n){var i,e=n.defIds;return!e||e.length===0?r:r.tag==="defs"&&(!((i=r.children)===null||i===void 0)&&i.length)?x(x({},r),{children:r.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?x(x({},t),{attrs:x(x({},t.attrs),{id:t.attrs.id+n.idSuffix})}):t})}):r}function nn(){return Math.random().toString(36).substring(2,8)}Ee.displayName="UniverIcon";var tn={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"}}]},Oe=O.forwardRef(function(r,n){return O.createElement(Ee,Object.assign({},r,{id:"add-image-single",ref:n,icon:tn}))});Oe.displayName="AddImageSingle";const Ae={uploadFileMenu:"univer-upload-file-menu",uploadFileMenuInput:"univer-upload-file-menu-input"},Ue="COMPONENT_UPLOAD_FILE_MENU";var he=(r=>(r[r.cellImage=0]="cellImage",r[r.floatImage=1]="floatImage",r))(he||{});const rn=r=>{const{type:n}=r,i=z.useDependency(g.ICommandService),e=O.useRef(null),t=()=>{var a;(a=e.current)==null||a.click()},o=E.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(a=>`.${a.replace("image/","")}`).join(","),s=a=>{const c=a.target.files;if(c==null)return;const u=Array.from(c);n===he.floatImage?i.executeCommand(ue.id,{files:u}):n===he.cellImage&&i.executeCommand(me.id,{files:u}),e.current&&(e.current.value="")};return O.createElement("div",{onClick:t,className:Ae.uploadFileMenu},O.createElement("input",{type:"file",className:Ae.uploadFileMenuInput,ref:e,onChange:s,accept:o,multiple:!0}))},Ne="addition-and-subtraction-single",Le="sheet.menu.image";function on(r){return{id:Le,type:$.MenuItemType.SUBITEMS,positions:[$.MenuPosition.TOOLBAR_START],group:$.MenuGroup.TOOLBAR_FORMULAS_INSERT,icon:Ne,tooltip:"sheetImage.title",hidden$:$.getMenuHiddenObservable(r,g.UniverInstanceType.UNIVER_SHEET),disabled$:X.getCurrentRangeDisable$(r,{workbookTypes:[w.WorkbookEditablePermission],worksheetTypes:[w.WorksheetEditPermission],rangeTypes:[w.RangeProtectionPermissionEditPoint]})}}function sn(r){return{id:ue.id,title:"sheetImage.upload.float",type:$.MenuItemType.SELECTOR,label:{name:Ue,props:{type:he.floatImage}},positions:[Le],hidden$:$.getMenuHiddenObservable(r,g.UniverInstanceType.UNIVER_SHEET)}}const Z={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"},an=r=>{var C;const n=z.useDependency(g.ICommandService),i=z.useDependency(g.LocaleService),e=z.useDependency(E.IDrawingManagerService),t=z.useDependency(U.IRenderManagerService),{drawings:o}=r,s=o[0];if(s==null)return;const{unitId:a}=s,c=t.getRenderById(a),u=c==null?void 0:c.scene;if(u==null)return;const d=u.getTransformerByCreate(),[l,m]=O.useState(!0),p=(C=s.anchorType)!=null?C:h.SheetDrawingAnchorType.Position,[S,f]=O.useState(p);function v(T,I){const P=[];return T.forEach(_=>{const{oKey:L}=_,R=I.getDrawingOKey(L);if(R==null)return P.push(null),!0;const{unitId:F,subUnitId:N,drawingId:A,drawingType:D,anchorType:V,sheetTransform:K}=R;P.push({unitId:F,subUnitId:N,drawingId:A,anchorType:V,sheetTransform:K,drawingType:D})}),P}O.useEffect(()=>{const T=d.onClearControlObservable.add(P=>{P===!0&&m(!1)}),I=d.onChangeStartObservable.add(P=>{var R;const{objects:_}=P,L=v(_,e);if(L.length===0)m(!1);else if(L.length>=1){m(!0);const F=((R=L[0])==null?void 0:R.anchorType)||h.SheetDrawingAnchorType.Position;f(F)}});return()=>{I==null||I.dispose(),T==null||T.dispose()}},[]);function y(T){f(T);const I=e.getFocusDrawings();if(I.length===0)return;const P=I.map(_=>({unitId:_.unitId,subUnitId:_.subUnitId,drawingId:_.drawingId,anchorType:T}));n.executeCommand(pe.id,{unitId:I[0].unitId,drawings:P})}const M=T=>T?"block":"none";return O.createElement("div",{className:ce(Z.imageCommonPanelGrid,Z.imageCommonPanelBorder),style:{display:M(l)}},O.createElement("div",{className:Z.imageCommonPanelRow},O.createElement("div",{className:ce(Z.imageCommonPanelColumn,Z.imageCommonPanelTitle)},O.createElement("div",null,i.t("drawing-anchor.title")))),O.createElement("div",{className:ce(Z.imageCommonPanelRow)},O.createElement("div",{className:ce(Z.imageCommonPanelColumn)},O.createElement(J.RadioGroup,{value:S,onChange:y,direction:"vertical"},O.createElement(J.Radio,{value:h.SheetDrawingAnchorType.Both},i.t("drawing-anchor.both")),O.createElement(J.Radio,{value:h.SheetDrawingAnchorType.Position},i.t("drawing-anchor.position")),O.createElement(J.Radio,{value:h.SheetDrawingAnchorType.None},i.t("drawing-anchor.none"))))))},cn=()=>{const r=z.useDependency(E.IDrawingManagerService),n=r.getFocusDrawings();if(n==null||n.length===0)return;const[i,e]=O.useState(n);return O.useEffect(()=>{const t=r.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),O.createElement("div",{className:Z.imageCommonPanel},O.createElement(Q.DrawingCommonPanel,{drawings:i}),O.createElement(an,{drawings:i}))},ie={id:"sheet.command.move-drawing",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(h.ISheetDrawingService),t=r.get(X.ISelectionRenderService),{direction:o}=n,s=e.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,c=s.map(d=>{const{transform:l}=d;if(l==null)return null;const m={...l},{left:p=0,top:S=0}=l;return o===g.Direction.UP?m.top=S-1:o===g.Direction.DOWN?m.top=S+1:o===g.Direction.LEFT?m.left=p-1:o===g.Direction.RIGHT&&(m.left=p+1),{...d,transform:m,sheetTransform:G(m,t)}}).filter(d=>d!=null);return i.syncExecuteCommand(pe.id,{unitId:a,drawings:c})?(i.syncExecuteCommand(W.id,[a]),!0):!1}},je={id:"sheet.command.delete-drawing",type:g.CommandType.COMMAND,handler:r=>{const n=r.get(g.ICommandService),e=r.get(h.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(s=>{const{unitId:a,subUnitId:c,drawingId:u,drawingType:d}=s;return{unitId:a,subUnitId:c,drawingId:u,drawingType:d}});return n.executeCommand(_e.id,{unitId:t,drawings:o})}};function re(r){return!r.getContextValue(g.FOCUSING_FORMULA_EDITOR)&&!r.getContextValue(g.EDITOR_ACTIVATED)&&r.getContextValue(g.FOCUSING_COMMON_DRAWINGS)}const ln={id:ie.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_DOWN,priority:100,preconditions:re,staticParameters:{direction:g.Direction.DOWN}},dn={id:ie.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_UP,priority:100,preconditions:re,staticParameters:{direction:g.Direction.UP}},un={id:ie.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_LEFT,priority:100,preconditions:re,staticParameters:{direction:g.Direction.LEFT}},mn={id:ie.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_RIGHT,priority:100,preconditions:re,staticParameters:{direction:g.Direction.RIGHT}},pn={id:je.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:re,binding:$.KeyCode.DELETE,mac:$.KeyCode.BACKSPACE};var gn=Object.defineProperty,hn=Object.getOwnPropertyDescriptor,fn=(r,n,i,e)=>{for(var t=e>1?void 0:e?hn(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&gn(n,i,t),t},oe=(r,n)=>(i,e)=>n(i,e,r);const Sn={};let se=class extends g.Disposable{constructor(r,n,i,e,t,o){super(),this._config=r,this._injector=n,this._componentManager=i,this._menuService=e,this._commandService=t,this._shortcutService=o,this._init()}_initCustomComponents(){const r=this._componentManager;this.disposeWithMe(r.register(Ne,Oe)),this.disposeWithMe(r.register(Ue,rn)),this.disposeWithMe(r.register(ye,cn))}_initMenus(){const{menu:r={}}=this._config;[on,sn].forEach(n=>{this._menuService.addMenuItem(n(this._injector),r)})}_initCommands(){[ue,me,Ie,_e,pe,De,W,Me,Re,be,ie,je,Te].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_initShortcuts(){[ln,dn,un,mn,pn].forEach(r=>{this.disposeWithMe(this._shortcutService.registerShortcut(r))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};se=fn([g.OnLifecycle(g.LifecycleStages.Rendered,se),oe(1,j.Inject(j.Injector)),oe(2,j.Inject($.ComponentManager)),oe(3,$.IMenuService),oe(4,g.ICommandService),oe(5,$.IShortcutService)],se);var vn=Object.defineProperty,wn=Object.getOwnPropertyDescriptor,_n=(r,n,i,e)=>{for(var t=e>1?void 0:e?wn(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&vn(n,i,t),t},te=(r,n)=>(i,e)=>n(i,e,r);const In=[w.InsertRowCommand.id,w.InsertColCommand.id,w.RemoveRowCommand.id,w.RemoveColCommand.id,w.DeleteRangeMoveLeftCommand.id,w.DeleteRangeMoveUpCommand.id,w.InsertRangeMoveDownCommand.id,w.InsertRangeMoveRightCommand.id,w.DeltaRowHeightCommand.id,w.SetRowHeightCommand.id,w.DeltaColumnWidthCommand.id,w.SetColWidthCommand.id,w.SetRowHiddenCommand.id,w.SetSpecificRowsVisibleCommand.id,w.SetSpecificColsVisibleCommand.id,w.SetColHiddenCommand.id],Cn=[w.SetRowVisibleMutation.id,w.SetRowHiddenMutation.id,w.SetColVisibleMutation.id,w.SetColHiddenMutation.id,w.SetWorksheetRowHeightMutation.id,w.SetWorksheetColWidthMutation.id];let fe=class extends g.Disposable{constructor(r,n,i,e,t,o){super(),this._commandService=r,this._sheetInterceptorService=n,this._sheetDrawingService=i,this._drawingManagerService=e,this._selectionRenderService=t,this._univerInstanceService=o,this._init()}_init(){this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(!In.includes(r.id))return{redos:[],undos:[]};if(r.params==null)return{redos:[],undos:[]};const n=r.id;if(n===w.InsertRowCommand.id)return this._moveRowInterceptor(r.params,"insert");if(n===w.InsertColCommand.id)return this._moveColInterceptor(r.params,"insert");if(n===w.RemoveRowCommand.id)return this._moveRowInterceptor(r.params,"remove");if(n===w.RemoveColCommand.id)return this._moveColInterceptor(r.params,"remove");if(n===w.DeleteRangeMoveLeftCommand.id){const{range:i}=r.params;return this._getRangeMoveUndo(i,0)}else if(n===w.DeleteRangeMoveUpCommand.id){const{range:i}=r.params;return this._getRangeMoveUndo(i,1)}else if(n===w.InsertRangeMoveDownCommand.id){const{range:i}=r.params;return this._getRangeMoveUndo(i,2)}else if(n===w.InsertRangeMoveRightCommand.id){const{range:i}=r.params;return this._getRangeMoveUndo(i,3)}else if(n===w.SetRowHiddenCommand.id||n===w.SetSpecificRowsVisibleCommand.id){const i=r.params,{unitId:e,subUnitId:t,ranges:o}=i;return this._getDrawingUndoForRowVisible(e,t,o)}else if(n===w.SetSpecificColsVisibleCommand.id||n===w.SetColHiddenCommand.id){const i=r.params,{unitId:e,subUnitId:t,ranges:o}=i;return this._getDrawingUndoForColVisible(e,t,o)}else if(n===w.DeltaRowHeightCommand.id||n===w.SetRowHeightCommand.id||n===w.DeltaColumnWidthCommand.id||n===w.SetColWidthCommand.id){const i=r.params,{unitId:e,subUnitId:t,ranges:o}=i,s=n===w.DeltaRowHeightCommand.id||n===w.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(r,n){const i=w.getSheetCommandTarget(this._univerInstanceService);if(i==null)return{redos:[],undos:[]};const e=i.unitId,t=i.subUnitId,o=[],s=[],a=this._sheetDrawingService.getDrawingData(e,t),c=[],u=[];if(Object.keys(a).forEach(d=>{const l=a[d],{updateDrawings:m,deleteDrawings:p}=this._getUpdateOrDeleteDrawings(r,n,l);c.push(...m),u.push(...p)}),c.length===0&&u.length===0)return{redos:[],undos:[]};if(c.length>0){const d=this._sheetDrawingService.getBatchUpdateOp(c),{undo:l,redo:m,objects:p}=d;o.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:m,objects:p,type:h.DrawingApplyType.UPDATE}}),s.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:l,objects:p,type:h.DrawingApplyType.UPDATE}})}if(u.length>0){const d=this._sheetDrawingService.getBatchRemoveOp(u),l=d.undo,m=d.redo,p=d.objects;o.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:m,objects:p,type:h.DrawingApplyType.REMOVE}}),s.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:l,objects:p,type:h.DrawingApplyType.INSERT}})}return o.push({id:W.id,params:[e]}),s.push({id:W.id,params:[e]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(r,n,i){const e=[],t=[],{sheetTransform:o,anchorType:s=h.SheetDrawingAnchorType.Position,transform:a,unitId:c,subUnitId:u,drawingId:d}=i,{from:l,to:m}=o,{row:p,column:S}=l,{row:f,column:v}=m;if(o==null||a==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:y,endRow:M,startColumn:C,endColumn:T}=r;let I=null,P=null;if(n===0&&p>=y&&f<=M)if(S>=C&&v<=T)t.push({unitId:c,subUnitId:u,drawingId:d});else{const _=this._shrinkCol(o,a,C,T,s);I=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(n===1&&S>=C&&v<=T)if(p>=y&&f<=M)t.push({unitId:c,subUnitId:u,drawingId:d});else{const _=this._shrinkRow(o,a,y,M,s);I=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(n===2){const _=this._expandRow(o,a,y,M,s);I=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(n===3){const _=this._expandCol(o,a,C,T,s);I=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}if(I!=null&&P!=null){const _=H(I,this._selectionRenderService);e.push({...i,sheetTransform:I,transform:_})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(r,n,i){const e=G({...r},this._selectionRenderService);e!=null&&n.push({...i,sheetTransform:e})}_getDrawingUndoForColVisible(r,n,i){const e=this._drawingManagerService.getDrawingData(r,n),t=[],o=[];if(Object.keys(e).forEach(d=>{const l=e[d],{sheetTransform:m,transform:p,anchorType:S=h.SheetDrawingAnchorType.Position}=l;if(S===h.SheetDrawingAnchorType.None)this._remainDrawingSize(p,t,l);else{const{from:f,to:v}=m,{row:y,column:M}=f,{row:C,column:T}=v;for(let I=0;I<i.length;I++){const P=i[I],{startRow:_,endRow:L,startColumn:R,endColumn:F}=P;if(T<R)continue;if(S===h.SheetDrawingAnchorType.Position){let D=null,V=null;if(M>=R&&M<=F){const K=this._selectionRenderService.attachRangeWithCoord({startColumn:M,endColumn:F,startRow:f.row,endRow:v.row});if(K==null)return;V={...p,left:K.startX}}if(V!=null&&(D=G(V,this._selectionRenderService),D!=null&&V!=null)){t.push({...l,sheetTransform:D,transform:V});break}this._remainDrawingSize(p,t,l);continue}if(M>=R&&T<=F)continue;let N=null,A=null;if(M>=R&&M<=F){const D=this._selectionRenderService.attachRangeWithCoord({startColumn:M,endColumn:F,startRow:f.row,endRow:v.row});if(D==null)return;A={...p,left:(D==null?void 0:D.startX)||0,width:((p==null?void 0:p.width)||0)-D.endX+D.startX}}else if(T>=R&&T<=F){const D=this._selectionRenderService.attachRangeWithCoord({startColumn:R,endColumn:T,startRow:f.row,endRow:v.row});if(D==null)return;A={...p,left:D.startX-((p==null?void 0:p.width)||0)}}else{const D=this._selectionRenderService.attachRangeWithCoord({startColumn:R,endColumn:F,startRow:f.row,endRow:v.row});if(D==null)return;if(A={...p,width:((p==null?void 0:p.width)||0)-D.endX+D.startX},N=G(A,this._selectionRenderService),N!=null&&A!=null){o.push({...l,sheetTransform:N,transform:A});break}}if(A!=null&&(N=G(A,this._selectionRenderService)),A!=null&&N!=null){t.push({...l,sheetTransform:N,transform:A});break}else this._remainDrawingSize(p,t,l)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(r,n,t),c=[],u=[];if(o.length>0){const{redos:d,undos:l}=this._createUndoAndRedoMutation(r,n,o);c.push(...d),u.push(...l)}return{redos:s,undos:a,preRedos:c,preUndos:u}}_createUndoAndRedoMutation(r,n,i){const e=this._sheetDrawingService.getBatchUpdateOp(i),{undo:t,redo:o,objects:s}=e,a=[{id:h.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:n,op:o,objects:s,type:h.DrawingApplyType.UPDATE}},{id:W.id,params:[r]}],c=[{id:h.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:n,op:t,objects:s,type:h.DrawingApplyType.UPDATE}},{id:W.id,params:[r]}];return{redos:a,undos:c}}_getDrawingUndoForRowVisible(r,n,i){const e=this._drawingManagerService.getDrawingData(r,n),t=[],o=[];if(Object.keys(e).forEach(d=>{const l=e[d],{sheetTransform:m,transform:p,anchorType:S=h.SheetDrawingAnchorType.Position}=l;if(S===h.SheetDrawingAnchorType.None)this._remainDrawingSize(p,t,l);else{const{from:f,to:v}=m,{row:y,column:M}=f,{row:C,column:T}=v;for(let I=0;I<i.length;I++){const P=i[I],{startRow:_,endRow:L,startColumn:R,endColumn:F}=P;if(C<_)continue;if(S===h.SheetDrawingAnchorType.Position){let D=null,V=null;if(y>=_&&y<=L){const K=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:y,endRow:L});if(K==null)return;V={...p,top:K.startY}}if(V!=null&&(D=G(V,this._selectionRenderService),D!=null&&V!=null)){t.push({...l,sheetTransform:D,transform:V});break}this._remainDrawingSize(p,t,l);continue}if(y>=_&&C<=L)continue;let N=null,A=null;if(y>=_&&y<=L){const D=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:y,endRow:L});if(D==null)return;A={...p,top:(D==null?void 0:D.startY)||0,height:((p==null?void 0:p.height)||0)-D.endY+D.startY}}else if(C>=_&&C<=L){const D=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:_,endRow:C});if(D==null)return;A={...p,top:D.startY-((p==null?void 0:p.height)||0)}}else{const D=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:_,endRow:L});if(D==null)return;if(A={...p,height:((p==null?void 0:p.height)||0)-D.endY+D.startY},N=G(A,this._selectionRenderService),N!=null&&A!=null){o.push({...l,sheetTransform:N,transform:A});break}}if(A!=null&&(N=G(A,this._selectionRenderService)),A!=null&&N!=null){t.push({...l,sheetTransform:N,transform:A});break}else this._remainDrawingSize(p,t,l)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(r,n,t),c=[],u=[];if(o.length>0){const{redos:d,undos:l}=this._createUndoAndRedoMutation(r,n,o);c.push(...d),u.push(...l)}return{redos:s,undos:a,preRedos:c,preUndos:u}}_getDrawingUndoForRowAndColSize(r,n,i,e){const t=this._drawingManagerService.getDrawingData(r,n),o=[];return Object.keys(t).forEach(s=>{const a=t[s],{sheetTransform:c,transform:u,anchorType:d=h.SheetDrawingAnchorType.Position}=a;if(d===h.SheetDrawingAnchorType.None)this._remainDrawingSize(u,o,a);else{const{from:l,to:m}=c,{row:p,column:S}=l,{row:f,column:v}=m;for(let y=0;y<i.length;y++){const M=i[y],{startRow:C,endRow:T,startColumn:I,endColumn:P}=M;if(f<C||v<I)continue;if(d===h.SheetDrawingAnchorType.Position&&(p<=C&&f>=T||S<=I&&v>=P)){this._remainDrawingSize(u,o,a);continue}const _=H({...c},this._selectionRenderService);if(_!=null){o.push({...a,transform:_});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(r,n,o)}_getUnitIdAndSubUnitId(r,n){let i,e;if(n==="insert")i=r.unitId,e=r.subUnitId;else{const t=w.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;i=t.unitId,e=t.subUnitId}return{unitId:i,subUnitId:e}}_moveRowInterceptor(r,n){const i=this._getUnitIdAndSubUnitId(r,n);if(i==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=i,{range:o}=r,s=o.startRow,a=o.endRow,c=[],u=[],d=this._sheetDrawingService.getDrawingData(e,t),l=[],m=[];if(Object.keys(d).forEach(p=>{const S=d[p],{sheetTransform:f,transform:v,anchorType:y=h.SheetDrawingAnchorType.Position}=S;if(f==null||v==null)return;let M,C;if(n==="insert"){const I=this._expandRow(f,v,s,a,y);M=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:P}=f,{row:_}=I,{row:L}=P;if(_>=s&&L<=a)m.push({unitId:e,subUnitId:t,drawingId:p});else{const R=this._shrinkRow(f,v,s,a,y);M=R==null?void 0:R.newSheetTransform,C=R==null?void 0:R.newTransform}}if(!M||!C)return;const T={unitId:e,subUnitId:t,drawingId:p,transform:C,sheetTransform:M};l.push(T)}),l.length===0&&m.length===0)return{redos:[],undos:[]};if(l.length>0){const p=this._sheetDrawingService.getBatchUpdateOp(l),{undo:S,redo:f,objects:v}=p;c.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.UPDATE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.UPDATE}})}if(m.length>0){const p=this._sheetDrawingService.getBatchRemoveOp(m),S=p.undo,f=p.redo,v=p.objects;c.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.REMOVE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.INSERT}})}return c.push({id:W.id,params:[e]}),u.push({id:W.id,params:[e]}),{redos:c,undos:u}}_moveColInterceptor(r,n){const i=this._getUnitIdAndSubUnitId(r,n);if(i==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=i,{range:o}=r,s=o.startColumn,a=o.endColumn,c=[],u=[],d=this._sheetDrawingService.getDrawingData(e,t),l=[],m=[];if(Object.keys(d).forEach(p=>{const S=d[p],{sheetTransform:f,transform:v,anchorType:y=h.SheetDrawingAnchorType.Position}=S;if(f==null||v==null)return;let M,C;if(n==="insert"){const I=this._expandCol(f,v,s,a,y);M=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:P}=f,{column:_}=I,{column:L}=P;if(_>=s&&L<=a)m.push({unitId:e,subUnitId:t,drawingId:p});else{const R=this._shrinkCol(f,v,s,a,y);M=R==null?void 0:R.newSheetTransform,C=R==null?void 0:R.newTransform}}if(!M||!C)return;const T={unitId:e,subUnitId:t,drawingId:p,transform:C,sheetTransform:M};l.push(T)}),l.length===0&&m.length===0)return{redos:[],undos:[]};if(l.length>0){const p=this._sheetDrawingService.getBatchUpdateOp(l),{undo:S,redo:f,objects:v}=p;c.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.UPDATE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.UPDATE}})}if(m.length>0){const p=this._sheetDrawingService.getBatchRemoveOp(m),S=p.undo,f=p.redo,v=p.objects;c.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.REMOVE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.INSERT}})}return c.push({id:W.id,params:[e]}),u.push({id:W.id,params:[e]}),{redos:c,undos:u}}_expandCol(r,n,i,e,t=h.SheetDrawingAnchorType.Position){const o=e-i+1,{from:s,to:a}=r,{column:c}=s,{column:u}=a;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};let d=null,l=null;if(c>=i){const m=this._selectionRenderService.attachRangeWithCoord({startColumn:i,endColumn:e,startRow:s.row,endRow:a.row});if(m==null)return;l={...n,left:(n.left||0)+m.endX-m.startX},d=G(l,this._selectionRenderService)}else if(u>=e)if(t===h.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,column:u+o}},l=H(d,this._selectionRenderService);else return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_shrinkCol(r,n,i,e,t=h.SheetDrawingAnchorType.Position){const o=e-i+1,{from:s,to:a}=r,{column:c}=s,{column:u}=a;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};let d=null,l=null;if(c>e)d={from:{...s,column:c-o},to:{...a,column:u-o}},l=H(d,this._selectionRenderService);else{if(c>=i&&u<=e)return null;if(c<i&&u>e)if(t===h.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,column:u-o}},l=H(d,this._selectionRenderService);else return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};else if(c>=i&&c<=e){if(c===i)l={...n,left:(n.left||0)-r.from.columnOffset};else{const m=this._selectionRenderService.attachRangeWithCoord({startColumn:i,endColumn:c-1,startRow:s.row,endRow:a.row});if(m==null)return;l={...n,left:(n.left||0)-m.endX+m.startX-r.from.columnOffset}}d=G(l,this._selectionRenderService)}else if(u>=i&&u<=e&&t===h.SheetDrawingAnchorType.Both){const m=this._selectionRenderService.attachRangeWithCoord({startColumn:i-1,endColumn:i-1,startRow:s.row,endRow:a.row});if(m==null)return;d={from:{...s},to:{...a,column:i-1,columnOffset:m.endX-m.startX}},l=H(d,this._selectionRenderService)}}return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_expandRow(r,n,i,e,t=h.SheetDrawingAnchorType.Position){const o=e-i+1,{from:s,to:a}=r,{row:c}=s,{row:u}=a;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};let d=null,l=null;if(c>=i){const m=this._selectionRenderService.attachRangeWithCoord({startRow:i,endRow:e,startColumn:s.column,endColumn:a.column});if(m==null)return;l={...n,top:(n.top||0)+m.endY-m.startY},d=G(l,this._selectionRenderService)}else if(u>=e)if(t===h.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,row:u+o}},l=H(d,this._selectionRenderService);else return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_shrinkRow(r,n,i,e,t=h.SheetDrawingAnchorType.Position){const o=e-i+1,{from:s,to:a}=r,{row:c}=s,{row:u}=a;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};let d=null,l=null;if(c>e)d={from:{...s,row:c-o},to:{...a,row:u-o}},l=H(d,this._selectionRenderService);else{if(c>=i&&u<=e)return null;if(c<i&&u>e)if(t===h.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,row:u-o}},l=H(d,this._selectionRenderService);else return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};else if(c>=i&&c<=e){if(c===i)l={...n,top:(n.top||0)-r.from.rowOffset};else{const m=this._selectionRenderService.attachRangeWithCoord({startRow:i,endRow:c-1,startColumn:s.column,endColumn:a.column});if(m==null)return;l={...n,top:(n.top||0)-m.endY+m.startY-r.from.rowOffset}}d=G(l,this._selectionRenderService)}else if(u>=i&&u<=e&&t===h.SheetDrawingAnchorType.Both){const m=this._selectionRenderService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:i-1,endRow:i-1});if(m==null)return;d={from:{...s},to:{...a,row:i-1,rowOffset:m.endY-m.startY}},l=H(d,this._selectionRenderService)}}return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===w.SetWorksheetActiveOperation.id){const n=r.params,{unitId:i,subUnitId:e}=n,t=this._drawingManagerService.drawingManagerData,o=[],s=[];Object.keys(t).forEach(a=>{const c=t[a];Object.keys(c).forEach(u=>{const d=c[u].data;d!=null&&Object.keys(d).forEach(l=>{a===i&&u===e?o.push(d[l]):s.push(d[l])})})}),this._drawingManagerService.removeNotification(s),this._drawingManagerService.addNotification(o)}}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{Cn.includes(r.id)&&requestIdleCallback(()=>{const n=r.params,{unitId:i,subUnitId:e,ranges:t}=n;this._refreshDrawingTransform(i,e,t)})}))}_refreshDrawingTransform(r,n,i){const e=this._drawingManagerService.getDrawingData(r,n),t=[];Object.keys(e).forEach(o=>{const s=e[o],{sheetTransform:a,anchorType:c=h.SheetDrawingAnchorType.Position}=s;if(c===h.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=a,{row:l,column:m}=u,{row:p,column:S}=d;for(let f=0;f<i.length;f++){const v=i[f],{startRow:y,endRow:M,startColumn:C,endColumn:T}=v;if(g.Rectangle.intersects({startRow:y,endRow:M,startColumn:C,endColumn:T},{startRow:l,endRow:p,startColumn:m,endColumn:S})||l>M||m>T){t.push({...s,transform:H(a,this._selectionRenderService)});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(W.id,[r]))}};fe=_n([g.OnLifecycle(g.LifecycleStages.Rendered,fe),te(0,g.ICommandService),te(1,j.Inject(w.SheetInterceptorService)),te(2,h.ISheetDrawingService),te(3,E.IDrawingManagerService),te(4,X.ISelectionRenderService),te(5,g.IUniverInstanceService)],fe);var yn=Object.defineProperty,Dn=Object.getOwnPropertyDescriptor,Mn=(r,n,i,e)=>{for(var t=e>1?void 0:e?Dn(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&yn(n,i,t),t},ne=(r,n)=>(i,e)=>n(i,e,r);function Tn(r,n,i,e){const{scaleX:t,scaleY:o}=n.getAncestorScale(),s=n.getViewport(U.SHEET_VIEWPORT_KEY.VIEW_MAIN),a={left:!0,top:!0};if(!s)return{...r,absolute:a};const{left:c,right:u,top:d,bottom:l}=r,m=e.getFreeze(),{startColumn:p,startRow:S,xSplit:f,ySplit:v}=m,y=i.getNoMergeCellPositionByIndexWithNoHeader(S-v,p-f),M=i.getNoMergeCellPositionByIndexWithNoHeader(S,p),{rowHeaderWidth:C,columnHeaderHeight:T}=i,I=M.startX-y.startX,P=M.startY-y.startY,{top:_,left:L,viewportScrollX:R,viewportScrollY:F}=s;let N,A;c<L?(a.left=!0,N=(I+C+(c-L))*t,A=Math.max(Math.min((I+C+(u-L))*t,(I+C)*t),(u-R)*t)):(a.left=!1,N=Math.max((c-R)*t,(I+C)*t),A=Math.max((u-R)*t,(I+C)*t));let D,V;return d<_?(a.top=!0,D=(P+T+(d-_))*o,V=Math.max(Math.min((P+T+(u-_))*o,(P+T)*o),(l-F)*o)):(a.top=!1,D=Math.max((d-F)*o,(P+T)*o),V=Math.max((l-F)*o,(P+T)*o)),{left:N,right:A,top:D,bottom:V,absolute:a}}const Ce=(r,n,i,e)=>{const{scene:t}=n,{left:o,top:s,width:a,height:c,angle:u}=r,d={left:o,right:o+a,top:s,bottom:s+c},l=Tn(d,t,i,e);return{startX:l.left,endX:l.right,startY:l.top,endY:l.bottom,rotate:u,width:a,height:c,absolute:l.absolute}};b.SheetCanvasFloatDomManagerService=class extends g.Disposable{constructor(i,e,t,o,s,a,c){super();q(this,"_domLayerMap",new Map);q(this,"_domLayerInfoMap",new Map);q(this,"_transformChange$",new B.Subject);q(this,"transformChange$",this._transformChange$.asObservable());q(this,"_remove$",new B.Subject);q(this,"remove$",this._remove$.asObservable());this._renderManagerService=i,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._selectionRenderService=s,this._canvasFloatDomService=a,this._sheetDrawingService=c,this._drawingAddListener(),this._scrollUpdateListener(),this._featureUpdateListener(),this._deleteListener()}_ensureMap(i,e){let t=this._domLayerMap.get(i);t||(t=new Map,this._domLayerMap.set(i,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}_getSceneAndTransformerByDrawingSearch(i){if(i==null)return;const e=this._renderManagerService.getRenderById(i),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:t,transformer:o,renderObject:e,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(i=>{i.forEach(e=>{var Ve,Fe;const{unitId:t,subUnitId:o,drawingId:s}=e,a=w.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),c=this._drawingManagerService.getDrawingByParam(e),u=(Ve=this._renderManagerService.getRenderById(t))==null?void 0:Ve.with(X.SheetSkeletonManagerService).getUnitSkeleton(t,o);if(c==null||a==null||u==null)return;const{transform:d,drawingType:l}=c;if(l!==g.DrawingTypeEnum.DRAWING_DOM)return;const m=this._getSceneAndTransformerByDrawingSearch(t);if(m==null)return;const{scene:p,canvas:S}=m;if(d==null)return!0;const{left:f,top:v,width:y,height:M,angle:C,flipX:T,flipY:I,skewX:P,skewY:_}=d,L=E.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:s}),R=p.getObject(L);if(R!=null){R.transformByState({left:f,top:v,width:y,height:M,angle:C,flipX:T,flipY:I,skewX:P,skewY:_});return}const F={left:f,top:v,width:y,height:M,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},N=new U.Rect(L,F);p.addObject(N,U.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(N);const A=this._ensureMap(t,o),D=new g.DisposableCollection,V=Ce(N,m.renderObject,u.skeleton,a.worksheet),K=new B.BehaviorSubject(V),Wn={dispose:D,rect:N,position$:K,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:K,id:s,componentKey:c.componentKey,onPointerDown:Y=>{S.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{S.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{S.dispatchEvent(new PointerEvent(Y.type,Y))},onWheel:Y=>{S.dispatchEvent(new WheelEvent(Y.type,Y))},props:(Fe=A.get(s))==null?void 0:Fe.props});const Be=N.onTransformChangeObservable.add(()=>{const Y=Ce(N,m.renderObject,u.skeleton,a.worksheet);K.next(Y)});D.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),Be&&D.add(Be),this._domLayerInfoMap.set(s,Wn)})}))}_scrollUpdateListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{var t,o;const e=(s,a)=>{var p;const c=this._getSceneAndTransformerByDrawingSearch(s),u=this._ensureMap(s,a),d=Array.from(u.keys()),l=w.getSheetCommandTarget(this._univerInstanceService,{unitId:s,subUnitId:a}),m=(p=this._renderManagerService.getRenderById(s))==null?void 0:p.with(X.SheetSkeletonManagerService).getUnitSkeleton(s,a);!c||!l||!m||d.forEach(S=>{const f=this._domLayerInfoMap.get(S);if(f){const v=Ce(f.rect,c.renderObject,m.skeleton,l.worksheet);f.position$.next(v)}})};if(i.id===X.SetScrollOperation.id){const s=i.params,{unitId:a,sheetId:c}=s;e(a,c)}else if(i.id===X.SetZoomRatioOperation.id){const s=i.params,{unitId:a}=s;Array.from((o=(t=this._domLayerMap.get(a))==null?void 0:t.keys())!=null?o:[]).forEach(u=>{e(a,u)})}else if(i.id===w.SetFrozenMutation.id){const{unitId:s,subUnitId:a}=i.params;e(s,a)}}))}_getPosition(i){const{startX:e,endX:t,startY:o,endY:s}=i,a=this._selectionRenderService.getSelectionCellByPosition(e,o);if(a==null)return;const c={column:a.actualColumn,columnOffset:e-a.startX,row:a.actualRow,rowOffset:o-a.startY},u=this._selectionRenderService.getSelectionCellByPosition(t,s);if(u==null)return;const d={column:u.actualColumn,columnOffset:t-u.startX,row:u.actualRow,rowOffset:s-u.startY};return{from:c,to:d}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(i=>{i.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==g.DrawingTypeEnum.DRAWING_DOM)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(i=>{i.forEach(e=>{this._removeDom(e.drawingId)})}))}addFloatDomToPosition(i){const e=w.getSheetCommandTarget(this._univerInstanceService,{unitId:i.unitId,subUnitId:i.subUnitId});if(!e)throw new Error("cannot find current target!");const{unitId:t,subUnitId:o}=e,{initPosition:s,componentKey:a}=i,c=g.Tools.generateRandomId(),u=this._getPosition(s);if(u==null)return;this._ensureMap(t,o).set(c,i);const l={unitId:t,subUnitId:o,drawingId:c,drawingType:g.DrawingTypeEnum.DRAWING_DOM,componentKey:a,sheetTransform:u,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY}};return this._commandService.executeCommand(Ie.id,{unitId:t,drawings:[l]}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(i,e=!1){const t=this._domLayerInfoMap.get(i);if(!t)return;const{unitId:o,subUnitId:s}=t;this._domLayerInfoMap.delete(i),t.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(o);if(a&&a.scene.removeObject(t.rect),e){this._ensureMap(o,s).delete(i);const u=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:i});if(!u)return;const d=this._sheetDrawingService.getBatchRemoveOp([u]),{redo:l,objects:m}=d;this._commandService.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:l,objects:m,type:h.DrawingApplyType.REMOVE})}}},b.SheetCanvasFloatDomManagerService=Mn([ne(0,j.Inject(U.IRenderManagerService)),ne(1,g.IUniverInstanceService),ne(2,j.Inject(g.ICommandService)),ne(3,E.IDrawingManagerService),ne(4,X.ISelectionRenderService),ne(5,j.Inject($.CanvasFloatDomService)),ne(6,h.ISheetDrawingService)],b.SheetCanvasFloatDomManagerService);var Rn=Object.defineProperty,bn=Object.getOwnPropertyDescriptor,En=(r,n,i,e)=>{for(var t=e>1?void 0:e?bn(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&Rn(n,i,t),t},Se=(r,n)=>(i,e)=>n(i,e,r);let ve=class extends g.Disposable{constructor(r,n,i,e){super(),this._sheetPrintInterceptorService=r,this._drawingRenderService=n,this._drawingManagerService=i,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(r,n,i)=>{const{unitId:e,scene:t,subUnitId:o}=n,s=this._drawingManagerService.getDrawingDataForUnit(e),a=s==null?void 0:s[o];return a&&a.order.forEach(c=>{this._drawingRenderService.renderDrawing(a.data[c],t)}),i()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(r,n,i)=>{const{unitId:e,subUnitId:t}=n,o=this._renderManagerService.getRenderById(e);if(!o)return i(r);const s=o.with(X.SheetSkeletonManagerService).getUnitSkeleton(e,t);if(!s)return i(r);const a=this._drawingManagerService.getDrawingDataForUnit(e),c=a==null?void 0:a[n.subUnitId];if(!c)return i(r);const{scaleX:u,scaleY:d}=o.scene,l=r?{...r}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=c.order.map(p=>c.data[p]).filter(p=>p.drawingType!==E.DrawingTypeEnum.DRAWING_DOM);return m.length?(m.forEach(p=>{if(!p.groupId&&p.transform&&g.Tools.isDefine(p.transform.left)&&g.Tools.isDefine(p.transform.top)&&g.Tools.isDefine(p.transform.width)&&g.Tools.isDefine(p.transform.height)){const S=s.skeleton.getCellPositionByOffset(p.transform.left,p.transform.top,u,d,{x:0,y:0}),f=s.skeleton.getCellPositionByOffset(p.transform.left+p.transform.width,p.transform.top+p.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)}}),i(l)):i(r)}}))}};ve=En([g.OnLifecycle(g.LifecycleStages.Rendered,ve),Se(0,j.Inject(X.SheetPrintInterceptorService)),Se(1,j.Inject(Q.DrawingRenderService)),Se(2,E.IDrawingManagerService),Se(3,U.IRenderManagerService)],ve);var Pn=Object.defineProperty,On=Object.getOwnPropertyDescriptor,An=(r,n,i,e)=>{for(var t=e>1?void 0:e?On(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&Pn(n,i,t),t},ae=(r,n)=>(i,e)=>n(i,e,r);let we=class extends g.Disposable{constructor(r,n,i,e,t){super(),this._drawingManagerService=r,this._renderManagerService=n,this._permissionService=i,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(B.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([n,i])=>{if(!n){this._drawingManagerService.setDrawingVisible(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new w.WorkbookViewPermission(t).id,new w.WorksheetViewPermission(t,o).id]).every(a=>a.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const a=n.getUnitId(),c=e.getSheetId(),u=this._drawingManagerService.getDrawingData(a,c),d=Object.values(u),l=this._renderManagerService.getRenderById(a),m=l==null?void 0:l.scene;if(m==null)return;m.getAllObjects().forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&d.some(f=>S.oKey.includes(f.drawingId))&&m.removeObject(S)})}})}))}_initDrawingEditable(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(B.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([n,i])=>{if(!n){this._drawingManagerService.setDrawingEditable(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new w.WorkbookEditablePermission(t).id,new w.WorksheetEditPermission(t,o).id]).every(a=>a.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const a=n.getUnitId(),c=e.getSheetId(),u=this._drawingManagerService.getDrawingData(a,c),d=Object.values(u),l=this._renderManagerService.getRenderById(a),m=l==null?void 0:l.scene;if(m==null)return;m.getAllObjects().forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&d.some(f=>S.oKey.includes(f.drawingId))&&m.detachTransformerFrom(S)})}})}))}_initViewPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(B.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([n,i])=>{n&&n.activeSheet$.subscribe(e=>{var l;if(!e)return;const t=n.getUnitId(),o=e.getSheetId();let s=!0;const a=this._renderManagerService.getRenderById(t),c=a==null?void 0:a.scene;if(c==null)return;const u=c.getTransformerByCreate(),d=this._permissionService.composePermission$([new w.WorkbookViewPermission(t).id,new w.WorksheetViewPermission(t,o).id]).pipe(B.map(m=>m.every(p=>p.value)));d==null||d.pipe(B.filter(m=>m!==s),B.distinctUntilChanged()).subscribe({next:m=>{s=m,this._drawingManagerService.setDrawingVisible(m);const p=c.getAllObjects(),S=this._drawingManagerService.getDrawingData(t,o),f=Object.values(S);m?this._drawingManagerService.addNotification(f):(p.forEach(v=>{v.classType===U.RENDER_CLASS_TYPE.IMAGE&&f.some(y=>v.oKey.includes(y.drawingId))&&c.removeObject(v)}),u.clearSelectedObjects())}}),(l=this._permissionService.getPermissionPoint$(new w.WorksheetViewPermission(t,o).id))==null||l.pipe(B.filter(m=>m.value!==s),B.distinctUntilChanged()).subscribe({complete:()=>{s=!0,this._drawingManagerService.setDrawingVisible(!0);const m=this._drawingManagerService.getDrawingData(t,o),p=Object.values(m);this._drawingManagerService.addNotification(p)}})})}))}_initEditPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(B.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([n,i])=>{n&&n.activeSheet$.subscribe(e=>{var l;if(!e)return;const t=n.getUnitId(),o=e.getSheetId();let s=!0;const a=this._renderManagerService.getRenderById(t),c=a==null?void 0:a.scene;if(c==null)return;const u=c.getTransformerByCreate(),d=this._permissionService.composePermission$([new w.WorkbookEditablePermission(t).id,new w.WorksheetEditPermission(t,o).id]).pipe(B.map(m=>m.every(p=>p.value)));d==null||d.pipe(B.filter(m=>m!==s),B.distinctUntilChanged()).subscribe({next:m=>{s=m,this._drawingManagerService.setDrawingEditable(m);const p=c.getAllObjects(),S=this._drawingManagerService.getDrawingData(t,o),f=Object.values(S);m?(p.forEach(v=>{v.classType===U.RENDER_CLASS_TYPE.IMAGE&&f.some(y=>v.oKey.includes(y.drawingId))&&c.attachTransformerTo(v)}),this._drawingManagerService.addNotification(f)):(p.forEach(v=>{v.classType===U.RENDER_CLASS_TYPE.IMAGE&&f.some(y=>v.oKey.includes(y.drawingId))&&c.detachTransformerFrom(v)}),u.clearSelectedObjects())}}),(l=this._permissionService.getPermissionPoint$(new w.WorksheetEditPermission(t,o).id))==null||l.pipe(B.filter(m=>m.value!==s),B.distinctUntilChanged()).subscribe({complete:()=>{s=!0;const m=n.getUnitId(),p=e.getSheetId(),S=this._drawingManagerService.getDrawingData(m,p),f=Object.values(S),v=this._renderManagerService.getRenderById(m),y=v==null?void 0:v.scene;if(y==null)return;this._drawingManagerService.setDrawingEditable(!0),y.getAllObjects().forEach(C=>{C.classType===U.RENDER_CLASS_TYPE.IMAGE&&f.some(T=>C.oKey.includes(T.drawingId))&&y.detachTransformerFrom(C)})}})})}))}};we=An([g.OnLifecycle(g.LifecycleStages.Rendered,we),ae(0,E.IDrawingManagerService),ae(1,U.IRenderManagerService),ae(2,g.IPermissionService),ae(3,g.IUniverInstanceService),ae(4,j.Inject(g.UserManagerService))],we);var We=Object.defineProperty,Un=Object.getOwnPropertyDescriptor,Nn=(r,n,i)=>n in r?We(r,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[n]=i,Ln=(r,n,i,e)=>{for(var t=e>1?void 0:e?Un(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&We(n,i,t),t},Ge=(r,n)=>(i,e)=>n(i,e,r),$e=(r,n,i)=>Nn(r,typeof n!="symbol"?n+"":n,i);const jn="SHEET_IMAGE_UI_PLUGIN";b.UniverSheetsDrawingUIPlugin=class extends g.Plugin{constructor(i={},e,t){super();q(this,"_pluginConfig");this._injector=e,this._localeService=t,this._pluginConfig=g.Tools.deepMerge({},Sn,i)}onStarting(i){super.onStarting(i),this._initDependencies(i)}_initDependencies(i){[[b.SheetCanvasFloatDomManagerService],[se,{useFactory:()=>this._injector.createInstance(se,this._pluginConfig)}],[ge],[de],[fe],[ve],[we]].forEach(t=>i.add(t))}},$e(b.UniverSheetsDrawingUIPlugin,"type",g.UniverInstanceType.UNIVER_SHEET),$e(b.UniverSheetsDrawingUIPlugin,"pluginName",jn),b.UniverSheetsDrawingUIPlugin=Ln([g.DependentOn(E.UniverDrawingPlugin,Q.UniverDrawingUIPlugin,h.UniverSheetsDrawingPlugin),Ge(1,j.Inject(j.Injector)),Ge(2,j.Inject(g.LocaleService))],b.UniverSheetsDrawingUIPlugin),Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(O,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):(O=typeof globalThis<"u"?globalThis:O||self,h(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,h,W,te,p,N,$,B,F,Y,Z,v,j,Q,pe){"use strict";var Yt=Object.defineProperty;var Ft=(O,h,W)=>h in O?Yt(O,h,{enumerable:!0,configurable:!0,writable:!0,value:W}):O[h]=W;var J=(O,h,W)=>Ft(O,typeof h!="symbol"?h+"":h,W);const V={id:"sheet.operation.clear-drawing-transformer",type:h.CommandType.MUTATION,handler:(i,e)=>{const r=i.get($.IRenderManagerService);return e.forEach(t=>{var n,o;(o=(n=r.getRenderById(t))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},he={id:"sheet.command.remove-sheet-image",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!e)return!1;const{drawings:o}=e,a=[];o.forEach(S=>{const{unitId:f}=S;a.push(f)});const s=n.getBatchRemoveOp(o),{unitId:l,subUnitId:m,undo:u,redo:c,objects:d}=s;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:l,subUnitId:m,op:c,objects:d,type:p.DrawingApplyType.REMOVE})?(t.pushUndoRedo({unitID:l,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:l,subUnitId:m,op:u,objects:d,type:p.DrawingApplyType.INSERT}},{id:V.id,params:a}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:l,subUnitId:m,op:c,objects:d,type:p.DrawingApplyType.REMOVE}},{id:V.id,params:a}]}),!0):!1}},je="COMPONENT_SHEET_DRAWING_PANEL",Te={id:"sidebar.operation.sheet-image",type:h.CommandType.COMMAND,handler:async(i,e)=>{const r=i.get(Y.ISidebarService),t=i.get(h.LocaleService),n=i.get(h.IUniverInstanceService),o=i.get(N.IDrawingManagerService);if(!v.getSheetCommandTarget(n))return!1;switch(e.value){case"open":r.open({header:{title:t.t("sheetImage.panel.title")},children:{label:je},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:r.close();break}return!0}},Oe={id:"sheet.operation.edit-sheet-image",type:h.CommandType.OPERATION,handler:(i,e)=>{const r=i.get(N.IDrawingManagerService),t=i.get(h.ICommandService);return e==null?!1:(r.focusDrawing([e]),t.executeCommand(Te.id,{value:"open"}),!0)}},fe={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},ke=()=>{const i=Z.useDependency(N.IImageIoService),e=Z.useDependency(h.LocaleService),[r,t]=j.useState(0);return j.useEffect(()=>{const n=i.change$.subscribe(o=>{t(o)});return()=>{n.unsubscribe()}},[i]),j.createElement("div",{style:{display:r>0?"block":"none"},className:fe.uploadLoading},j.createElement("div",{className:fe.uploadLoadingBody},j.createElement("div",{className:fe.uploadLoadingBodyAnimation}),j.createElement("div",{className:fe.uploadLoadingBodyText},`${e.t("uploadLoading.loading")}: ${r}`)))};var Ke=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,ze=(i,e,r,t)=>{for(var n=t>1?void 0:t?xe(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Ke(e,r,n),n},ne=(i,e)=>(r,t)=>e(r,t,i);let Se=class extends h.RxDisposable{constructor(e,r,t,n,o,a,s){super();J(this,"_initImagePopupMenu",new Set);this._injector=e,this._drawingManagerService=r,this._canvasPopManagerService=t,this._renderManagerService=n,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET).pipe(F.takeUntil(this.dispose$)).subscribe(e=>this._create(e)),this._univerInstanceService.getTypeOfUnitDisposed$(h.UniverInstanceType.UNIVER_SHEET).pipe(F.takeUntil(this.dispose$)).subscribe(e=>this._dispose(e)),this._univerInstanceService.getAllUnitsForType(h.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._create(e)),this._uiPartsService.registerComponent(Y.BuiltInUIPart.CONTENT,()=>Z.connectInjector(ke,this._injector))}_dispose(e){const r=e.getUnitId();this._renderManagerService.removeRender(r)}_create(e){if(!e)return;const r=e.getUnitId();this._renderManagerService.has(r)&&!this._initImagePopupMenu.has(r)&&(this._popupMenuListener(r),this._initImagePopupMenu.add(r))}_hasCropObject(e){const r=e.getAllObjects();for(const t of r)if(t instanceof te.ImageCropperObject)return!0;return!1}_popupMenuListener(e){var o;const r=(o=this._renderManagerService.getRenderById(e))==null?void 0:o.scene;if(!r)return;const t=r.getTransformerByCreate();if(!t)return;let n;this.disposeWithMe(h.toDisposable(t.createControl$.subscribe(()=>{if(this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(r))return;const a=t.getSelectedObjectMap();if(a.size>1){n==null||n.dispose();return}const s=a.values().next().value;if(!s)return;const l=s.oKey,m=this._drawingManagerService.getDrawingOKey(l);if(!m)return;const{unitId:u,subUnitId:c,drawingId:d}=m;n==null||n.dispose(),n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:te.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(u,c,d)}})),this._drawingManagerService.focusDrawing([{unitId:u,subUnitId:c,drawingId:d}])}))),this.disposeWithMe(t.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(t.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(e,r,t){return[{label:"image-popup.edit",index:0,commandId:Oe.id,commandParams:{unitId:e,subUnitId:r,drawingId:t},disable:!1},{label:"image-popup.delete",index:1,commandId:he.id,commandParams:{unitId:e,drawings:[{unitId:e,subUnitId:r,drawingId:t}]},disable:!1},{label:"image-popup.crop",index:2,commandId:te.OpenImageCropOperation.id,commandParams:{unitId:e,subUnitId:r,drawingId:t},disable:!1},{label:"image-popup.reset",index:3,commandId:te.ImageResetSizeOperation.id,commandParams:[{unitId:e,subUnitId:r,drawingId:t}],disable:!1}]}};Se=ze([h.OnLifecycle(h.LifecycleStages.Steady,Se),ne(0,W.Inject(W.Injector)),ne(1,N.IDrawingManagerService),ne(2,W.Inject(B.SheetCanvasPopManagerService)),ne(3,$.IRenderManagerService),ne(4,h.IUniverInstanceService),ne(5,h.IContextService),ne(6,W.Inject(Y.IUIPartsService))],Se);const ae={id:"sheet.operation.insert-float-image",type:h.CommandType.OPERATION,handler:(i,e)=>!0},se={id:"sheet.operation.insert-cell-image",type:h.CommandType.OPERATION,handler:(i,e)=>!0},we={id:"sheet.command.insert-sheet-image",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!e)return!1;const o=e.drawings,a=o.map(S=>S.unitId),s=n.getBatchAddOp(o),{unitId:l,subUnitId:m,undo:u,redo:c,objects:d}=s;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:c,unitId:l,subUnitId:m,objects:d,type:p.DrawingApplyType.INSERT})?(t.pushUndoRedo({unitID:l,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:l,subUnitId:m,objects:d,type:p.DrawingApplyType.REMOVE}},{id:V.id,params:a}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:c,unitId:l,subUnitId:m,objects:d,type:p.DrawingApplyType.INSERT}},{id:V.id,params:a}]}),!0):!1}},ce={id:"sheet.command.set-sheet-image",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!e)return!1;const{drawings:o}=e,a=n.getBatchUpdateOp(o),{unitId:s,subUnitId:l,undo:m,redo:u,objects:c}=a;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:s,subUnitId:l,op:u,objects:c,type:p.DrawingApplyType.UPDATE})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:m,objects:c,type:p.DrawingApplyType.UPDATE}},{id:V.id,params:[s]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:u,objects:c,type:p.DrawingApplyType.UPDATE}},{id:V.id,params:[s]}]}),!0):!1}},Ee={id:"sheet.command.set-drawing-arrange",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService);if(!e)return!1;const n=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:l}=e,m={unitId:o,subUnitId:a,drawingIds:s};let u;if(l===N.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(m):l===N.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(m):l===N.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(m):l===N.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(m)),u==null)return!1;const{objects:c,redo:d,undo:g}=u;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:d,unitId:o,subUnitId:a,objects:c,type:p.DrawingApplyType.ARRANGE})?(t.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:c,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:d,unitId:o,subUnitId:a,objects:c,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}};function qe(i){const e=[];return i.forEach(r=>{const{parent:t,children:n}=r,{unitId:o,subUnitId:a,drawingId:s}=t,l=$.getGroupState(0,0,n.map(c=>c.transform||{})),m=n.map(c=>{const d=c.transform||{left:0,top:0},{unitId:g,subUnitId:S,drawingId:f}=c;return{unitId:g,subUnitId:S,drawingId:f,transform:{...d,left:d.left-l.left,top:d.top-l.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:N.DrawingTypeEnum.DRAWING_GROUP,transform:l};e.push({parent:u,children:m})}),e}function Je(i){const e=[];return i.forEach(r=>{const{parent:t,children:n}=r,{unitId:o,subUnitId:a,drawingId:s,transform:l={width:0,height:0}}=t;if(l==null)return;const m=n.map(c=>{const{transform:d}=c,{unitId:g,subUnitId:S,drawingId:f}=c,w=$.transformObjectOutOfGroup(d||{},l,l.width||0,l.height||0);return{unitId:g,subUnitId:S,drawingId:f,transform:w,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:N.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};e.push({parent:u,children:m})}),e}const be={id:"sheet.command.group-sheet-image",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!e)return!1;const o=[];e.forEach(({parent:g,children:S})=>{o.push(g.unitId),S.forEach(f=>{o.push(f.unitId)})});const a=n.getGroupDrawingOp(e),{unitId:s,subUnitId:l,undo:m,redo:u,objects:c}=a;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:c,type:p.DrawingApplyType.GROUP})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:l,objects:Je(c),type:p.DrawingApplyType.UNGROUP}},{id:V.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:c,type:p.DrawingApplyType.GROUP}},{id:V.id,params:o}]}),!0):!1}},Pe={id:"sheet.command.ungroup-sheet-image",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(h.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!e)return!1;const o=[];e.forEach(({parent:g,children:S})=>{o.push(g.unitId),S.forEach(f=>{o.push(f.unitId)})});const a=n.getUngroupDrawingOp(e),{unitId:s,subUnitId:l,undo:m,redo:u,objects:c}=a;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:c,type:p.DrawingApplyType.UNGROUP})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:l,objects:qe(c),type:p.DrawingApplyType.GROUP}},{id:V.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:c,type:p.DrawingApplyType.UNGROUP}},{id:V.id,params:o}]}),!0):!1}};function H(i,e,r){const{from:t,to:n,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:l=0,skewY:m=0}=i,{column:u,columnOffset:c,row:d,rowOffset:g}=t,{column:S,columnOffset:f,row:w,rowOffset:I}=n,R=e.attachRangeWithCoord({startColumn:u,endColumn:u,startRow:d,endRow:d});if(R==null)return;const y=e.attachRangeWithCoord({startColumn:S,endColumn:S,startRow:w,endRow:w});if(y==null)return;const{startX:D,startY:C}=R,{startX:P,startY:_}=y;let U=$.precisionTo(D+c,1),A=$.precisionTo(C+g,1),T=$.precisionTo(P+f-U,1),b=$.precisionTo(_+I-A,1);R.startX===y.endX&&(T=0),R.startY===y.endY&&(b=0);const E=r.getCurrentSkeleton(),M=E.rowHeaderWidth+E.columnTotalWidth,L=E.columnHeaderHeight+E.rowTotalHeight;return U+T>M&&(U=M-T),A+b>L&&(A=L-b),{flipY:o,flipX:a,angle:s,skewX:l,skewY:m,left:U,top:A,width:T,height:b}}function G(i,e){const{left:r=0,top:t=0,width:n=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:l=0,skewX:m=0,skewY:u=0}=i,c=e.getSelectionCellByPosition(r,t);if(c==null)return;const d={column:c.actualColumn,columnOffset:$.precisionTo(r-c.startX,1),row:c.actualRow,rowOffset:$.precisionTo(t-c.startY,1)},g=e.getSelectionCellByPosition(r+n,t+o);if(g==null)return;const S={column:g.actualColumn,columnOffset:$.precisionTo(r+n-g.startX,1),row:g.actualRow,rowOffset:$.precisionTo(t+o-g.startY,1)};return{flipY:a,flipX:s,angle:l,skewX:m,skewY:u,from:d,to:S}}var Ze=Object.defineProperty,Qe=Object.getOwnPropertyDescriptor,et=(i,e,r,t)=>{for(var n=t>1?void 0:t?Qe(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Ze(e,r,n),n},K=(i,e)=>(r,t)=>e(r,t,i);let ve=class extends h.Disposable{constructor(i,e,r,t,n,o,a,s,l,m,u,c,d){super(),this._context=i,this._commandService=e,this._univerInstanceService=r,this._selectionManagerService=t,this._selectionRenderService=n,this._imageIoService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._contextService=l,this._messageService=m,this._localeService=u,this._renderManagerService=c,this._sheetSkeletonManagerService=d,this._init()}_init(){this._initCommandListeners(),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener(),this._drawingAddListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async i=>{if(i.id===se.id||i.id===ae.id){const e=i.params;if(e.files==null)return;const r=e.files.length;if(r>N.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:Q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(N.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(r),i.id===se.id?e.files.forEach(async t=>{await this._insertCellImage(t)}):e.files.forEach(async t=>{await this._insertFloatImage(t)})}}))}async _insertCellImage(i){}async _insertFloatImage(i){let e;try{e=await this._imageIoService.saveImage(i)}catch(R){const y=R.message;y===N.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(N.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===N.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===N.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const r=this._getUnitInfo();if(r==null)return;const{unitId:t,subUnitId:n}=r,{imageId:o,imageSourceType:a,source:s,base64Cache:l}=e,{width:m,height:u,image:c}=await N.getImageSize(l||""),d=this._renderManagerService.getRenderById(t);if(d==null)return;const{width:g,height:S}=d.scene;this._imageIoService.addImageSourceCache(s,a,c);let f=1;if(m>N.DRAWING_IMAGE_WIDTH_LIMIT||u>N.DRAWING_IMAGE_HEIGHT_LIMIT){const R=N.DRAWING_IMAGE_WIDTH_LIMIT/m,y=N.DRAWING_IMAGE_HEIGHT_LIMIT/u;f=Math.max(R,y)}const w=this._getImagePosition(m*f,u*f,g,S);if(w==null)return;const I={unitId:t,subUnitId:n,drawingId:o,drawingType:N.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:s,transform:H(w,this._selectionRenderService,this._sheetSkeletonManagerService),sheetTransform:w};this._commandService.executeCommand(we.id,{unitId:t,drawings:[I]})}_getUnitInfo(){const i=this._univerInstanceService.getCurrentUnitForType(h.UniverInstanceType.UNIVER_SHEET);if(i==null)return;const e=i.getActiveSheet();if(e==null)return;const r=i.getUnitId(),t=e.getSheetId();return{unitId:r,subUnitId:t}}_getImagePosition(i,e,r,t){const n=this._selectionManagerService.getSelections();let o={startRow:0,endRow:0,startColumn:0,endColumn:0};n&&n.length>0&&(o=n[n.length-1].range);const a=this._selectionRenderService.attachRangeWithCoord(o);if(a==null)return;let{startColumn:s,startRow:l,startX:m,startY:u}=a,c=!1;if(m+i>r&&(m=r-i,m<0&&(m=0,i=r),c=!0),u+e>t&&(u=t-e,u<0&&(u=0,e=t),c=!0),c){const f=this._selectionRenderService.getSelectionCellByPosition(m,u);if(f==null)return;m=f.startX,u=f.startY,s=f.actualColumn,l=f.actualRow}const d={column:s,columnOffset:0,row:l,rowOffset:0},g=this._selectionRenderService.getSelectionCellByPosition(m+i,u+e);if(g==null)return;const S={column:g.actualColumn,columnOffset:m+i-g.startX,row:g.actualRow,rowOffset:u+e-g.startY};return{from:d,to:S}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(i=>{const{unitId:e,subUnitId:r,drawingIds:t,arrangeType:n}=i;this._commandService.executeCommand(Ee.id,{unitId:e,subUnitId:r,drawingIds:t,arrangeType:n})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(i=>{const e=[];i.length!==0&&(i.forEach(r=>{const{unitId:t,subUnitId:n,drawingId:o,drawingType:a,transform:s}=r;if(s==null)return;const l=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:n,drawingId:o});if(l==null)return;const m=G({...l.transform,...s},this._selectionRenderService);if(m==null)return;const u={...r,transform:{...l.transform,...s,...H(m,this._selectionRenderService,this._sheetSkeletonManagerService)},sheetTransform:{...m}};e.push(u)}),e.length>0&&this._commandService.executeCommand(ce.id,{unitId:i[0].unitId,drawings:e}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(i=>{this._commandService.executeCommand(be.id,i);const{unitId:e,subUnitId:r,drawingId:t}=i[0].parent;this._drawingManagerService.focusDrawing([{unitId:e,subUnitId:r,drawingId:t}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(i=>{this._commandService.executeCommand(Pe.id,i)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(i=>{i==null||i.length===0?(this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(h.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(i))}))}_drawingAddListener(){this.disposeWithMe(this._sheetDrawingService.add$.subscribe(i=>{this._registerDrawing(i)}))}_registerDrawing(i){i.forEach(r=>{const t=this._sheetDrawingService.getDrawingByParam(r);if(t==null)return;const{sheetTransform:n}=t;t.transform=H(n,this._selectionRenderService,this._sheetSkeletonManagerService)});const e=i[0].unitId;this._drawingManagerService.registerDrawingData(e,this._sheetDrawingService.getDrawingDataForUnit(e)),this._drawingManagerService.initializeNotification(e)}};ve=et([h.OnLifecycle(h.LifecycleStages.Rendered,ve),K(1,h.ICommandService),K(2,h.IUniverInstanceService),K(3,W.Inject(v.SelectionManagerService)),K(4,B.ISelectionRenderService),K(5,N.IImageIoService),K(6,p.ISheetDrawingService),K(7,N.IDrawingManagerService),K(8,h.IContextService),K(9,Y.IMessageService),K(10,W.Inject(h.LocaleService)),K(11,$.IRenderManagerService),K(12,W.Inject(B.SheetSkeletonManagerService))],ve);var x=function(){return x=Object.assign||function(i){for(var e,r=1,t=arguments.length;r<t;r++){e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(i[n]=e[n])}return i},x.apply(this,arguments)},tt=function(i,e){var r={};for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&e.indexOf(t)<0&&(r[t]=i[t]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,t=Object.getOwnPropertySymbols(i);n<t.length;n++)e.indexOf(t[n])<0&&Object.prototype.propertyIsEnumerable.call(i,t[n])&&(r[t[n]]=i[t[n]]);return r},We=j.forwardRef(function(i,e){var r=i.icon,t=i.id,n=i.className,o=i.extend,a=tt(i,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(t," ").concat(n||"").trim(),l=j.useRef("_".concat(it()));return $e(r,"".concat(t),{defIds:r.defIds,idSuffix:l.current},x({ref:e,className:s},a),o)});function $e(i,e,r,t,n){return j.createElement(i.tag,x(x({key:e},nt(i,r,n)),t),(rt(i,r).children||[]).map(function(o,a){return $e(o,"".concat(e,"-").concat(i.tag,"-").concat(a),r,void 0,n)}))}function nt(i,e,r){var t=x({},i.attrs);r!=null&&r.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=r.colorChannel1);var n=e.defIds;return!n||n.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(t[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function rt(i,e){var r,t=e.defIds;return!t||t.length===0?i:i.tag==="defs"&&(!((r=i.children)===null||r===void 0)&&r.length)?x(x({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&t&&t.indexOf(n.attrs.id)>-1?x(x({},n),{attrs:x(x({},n.attrs),{id:n.attrs.id+e.idSuffix})}):n})}):i}function it(){return Math.random().toString(36).substring(2,8)}We.displayName="UniverIcon";var ot={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"}}]},Be=j.forwardRef(function(i,e){return j.createElement(We,Object.assign({},i,{id:"add-image-single",ref:e,icon:ot}))});Be.displayName="AddImageSingle";const Ge={uploadFileMenu:"univer-upload-file-menu",uploadFileMenuInput:"univer-upload-file-menu-input"},Ve="COMPONENT_UPLOAD_FILE_MENU";var _e=(i=>(i[i.cellImage=0]="cellImage",i[i.floatImage=1]="floatImage",i))(_e||{});const at=i=>{const{type:e}=i,r=Z.useDependency(h.ICommandService),t=j.useRef(null),n=()=>{var s;(s=t.current)==null||s.click()},o=N.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(s=>`.${s.replace("image/","")}`).join(","),a=s=>{const l=s.target.files;if(l==null)return;const m=Array.from(l);e===_e.floatImage?r.executeCommand(ae.id,{files:m}):e===_e.cellImage&&r.executeCommand(se.id,{files:m}),t.current&&(t.current.value="")};return j.createElement("div",{onClick:n,className:Ge.uploadFileMenu},j.createElement("input",{type:"file",className:Ge.uploadFileMenuInput,ref:t,onChange:a,accept:o,multiple:!0}))},Ye="addition-and-subtraction-single",Fe="sheet.menu.image";function st(i){return{id:Fe,type:Y.MenuItemType.SUBITEMS,positions:[Y.MenuPosition.TOOLBAR_START,Y.MenuPosition.TOOLBAR_INSERT],group:Y.MenuGroup.TOOLBAR_FORMULAS_INSERT,icon:Ye,tooltip:"sheetImage.title",hidden$:Y.getMenuHiddenObservable(i,h.UniverInstanceType.UNIVER_SHEET),disabled$:B.getCurrentRangeDisable$(i,{workbookTypes:[v.WorkbookEditablePermission],worksheetTypes:[v.WorksheetEditPermission],rangeTypes:[v.RangeProtectionPermissionEditPoint]})}}function ct(i){return{id:ae.id,title:"sheetImage.upload.float",type:Y.MenuItemType.SELECTOR,label:{name:Ve,props:{type:_e.floatImage}},positions:[Fe],hidden$:Y.getMenuHiddenObservable(i,h.UniverInstanceType.UNIVER_SHEET)}}const ee={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",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"},lt=i=>{var y;const e=Z.useDependency(h.ICommandService),r=Z.useDependency(h.LocaleService),t=Z.useDependency(N.IDrawingManagerService),n=Z.useDependency($.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:s}=a,l=n.getRenderById(s),m=l==null?void 0:l.scene;if(m==null)return;const u=m.getTransformerByCreate(),[c,d]=j.useState(!0),g=(y=a.anchorType)!=null?y:p.SheetDrawingAnchorType.Position,[S,f]=j.useState(g);function w(D,C){const P=[];return D.forEach(_=>{const{oKey:U}=_,A=C.getDrawingOKey(U);if(A==null)return P.push(null),!0;const{unitId:T,subUnitId:b,drawingId:E,drawingType:M,anchorType:L,sheetTransform:X}=A;P.push({unitId:T,subUnitId:b,drawingId:E,anchorType:L,sheetTransform:X,drawingType:M})}),P}j.useEffect(()=>{const D=u.clearControl$.subscribe(P=>{P===!0&&d(!1)}),C=u.changeStart$.subscribe(P=>{var A;const{objects:_}=P,U=w(_,t);if(U.length===0)d(!1);else if(U.length>=1){d(!0);const T=((A=U[0])==null?void 0:A.anchorType)||p.SheetDrawingAnchorType.Position;f(T)}});return()=>{C.unsubscribe(),D.unsubscribe()}},[]);function I(D){f(D);const C=t.getFocusDrawings();if(C.length===0)return;const P=C.map(_=>({unitId:_.unitId,subUnitId:_.subUnitId,drawingId:_.drawingId,anchorType:D}));e.executeCommand(ce.id,{unitId:C[0].unitId,drawings:P})}const R=D=>D?"block":"none";return j.createElement("div",{className:pe(ee.imageCommonPanelGrid,ee.imageCommonPanelBorder),style:{display:R(c)}},j.createElement("div",{className:ee.imageCommonPanelRow},j.createElement("div",{className:pe(ee.imageCommonPanelColumn,ee.imageCommonPanelTitle)},j.createElement("div",null,r.t("drawing-anchor.title")))),j.createElement("div",{className:pe(ee.imageCommonPanelRow)},j.createElement("div",{className:pe(ee.imageCommonPanelColumn)},j.createElement(Q.RadioGroup,{value:S,onChange:I,direction:"vertical"},j.createElement(Q.Radio,{value:p.SheetDrawingAnchorType.Both},r.t("drawing-anchor.both")),j.createElement(Q.Radio,{value:p.SheetDrawingAnchorType.Position},r.t("drawing-anchor.position")),j.createElement(Q.Radio,{value:p.SheetDrawingAnchorType.None},r.t("drawing-anchor.none"))))))},dt=()=>{const i=Z.useDependency(N.IDrawingManagerService),e=i.getFocusDrawings(),[r,t]=j.useState(e);return j.useEffect(()=>{const n=i.focus$.subscribe(o=>{t(o)});return()=>{n.unsubscribe()}},[]),!!(r!=null&&r.length)&&j.createElement("div",{className:ee.imageCommonPanel},j.createElement(te.DrawingCommonPanel,{drawings:r}),j.createElement(lt,{drawings:r}))},oe={id:"sheet.command.move-drawing",type:h.CommandType.COMMAND,handler:(i,e)=>{const r=i.get(h.ICommandService),t=i.get(p.ISheetDrawingService),n=i.get(B.ISelectionRenderService),{direction:o}=e,a=t.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,l=a.map(u=>{const{transform:c}=u;if(c==null)return null;const d={...c},{left:g=0,top:S=0}=c;return o===h.Direction.UP?d.top=S-1:o===h.Direction.DOWN?d.top=S+1:o===h.Direction.LEFT?d.left=g-1:o===h.Direction.RIGHT&&(d.left=g+1),{...u,transform:d,sheetTransform:G(d,n)}}).filter(u=>u!=null);return r.syncExecuteCommand(ce.id,{unitId:s,drawings:l})?(r.syncExecuteCommand(V.id,[s]),!0):!1}},Ae={id:"sheet.command.delete-drawing",type:h.CommandType.COMMAND,handler:i=>{const e=i.get(h.ICommandService),t=i.get(p.ISheetDrawingService).getFocusDrawings();if(t.length===0)return!1;const n=t[0].unitId,o=t.map(a=>{const{unitId:s,subUnitId:l,drawingId:m,drawingType:u}=a;return{unitId:s,subUnitId:l,drawingId:m,drawingType:u}});return e.executeCommand(he.id,{unitId:n,drawings:o})}};function le(i){return!i.getContextValue(h.FOCUSING_FORMULA_EDITOR)&&!i.getContextValue(h.EDITOR_ACTIVATED)&&i.getContextValue(h.FOCUSING_COMMON_DRAWINGS)}const ut={id:oe.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_DOWN,priority:100,preconditions:le,staticParameters:{direction:h.Direction.DOWN}},mt={id:oe.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_UP,priority:100,preconditions:le,staticParameters:{direction:h.Direction.UP}},gt={id:oe.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_LEFT,priority:100,preconditions:le,staticParameters:{direction:h.Direction.LEFT}},pt={id:oe.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_RIGHT,priority:100,preconditions:le,staticParameters:{direction:h.Direction.RIGHT}},ht={id:Ae.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:le,binding:Y.KeyCode.DELETE,mac:Y.KeyCode.BACKSPACE};var ft=Object.defineProperty,St=Object.getOwnPropertyDescriptor,wt=(i,e,r,t)=>{for(var n=t>1?void 0:t?St(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&ft(e,r,n),n},de=(i,e)=>(r,t)=>e(r,t,i);const vt={};let ue=class extends h.Disposable{constructor(i,e,r,t,n,o){super(),this._config=i,this._injector=e,this._componentManager=r,this._menuService=t,this._commandService=n,this._shortcutService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Ye,Be)),this.disposeWithMe(i.register(Ve,at)),this.disposeWithMe(i.register(je,dt))}_initMenus(){const{menu:i={}}=this._config;[st,ct].forEach(e=>{this._menuService.addMenuItem(e(this._injector),i)})}_initCommands(){[ae,se,we,he,ce,Te,V,Oe,be,Pe,oe,Ae,Ee].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[ut,mt,gt,pt,ht].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};ue=wt([h.OnLifecycle(h.LifecycleStages.Rendered,ue),de(1,W.Inject(W.Injector)),de(2,W.Inject(Y.ComponentManager)),de(3,Y.IMenuService),de(4,h.ICommandService),de(5,Y.IShortcutService)],ue);var _t=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,It=(i,e,r,t)=>{for(var n=t>1?void 0:t?Ct(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&_t(e,r,n),n},re=(i,e)=>(r,t)=>e(r,t,i);const yt=[v.InsertRowCommand.id,v.InsertColCommand.id,v.RemoveRowCommand.id,v.RemoveColCommand.id,v.DeleteRangeMoveLeftCommand.id,v.DeleteRangeMoveUpCommand.id,v.InsertRangeMoveDownCommand.id,v.InsertRangeMoveRightCommand.id,v.DeltaRowHeightCommand.id,v.SetRowHeightCommand.id,v.DeltaColumnWidthCommand.id,v.SetColWidthCommand.id,v.SetRowHiddenCommand.id,v.SetSpecificRowsVisibleCommand.id,v.SetSpecificColsVisibleCommand.id,v.SetColHiddenCommand.id,v.MoveRangeCommand.id],Mt=[v.SetRowVisibleMutation.id,v.SetRowHiddenMutation.id,v.SetColVisibleMutation.id,v.SetColHiddenMutation.id,v.SetWorksheetRowHeightMutation.id,v.SetWorksheetColWidthMutation.id];let Ce=class extends h.Disposable{constructor(i,e,r,t,n,o,a,s){super(),this._context=i,this._commandService=e,this._sheetInterceptorService=r,this._sheetDrawingService=t,this._drawingManagerService=n,this._selectionRenderService=o,this._univerInstanceService=a,this._sheetSkeletonManagerService=s,this._init()}_init(){this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!yt.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const e=i.id;if(e===v.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if(e===v.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(e===v.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(e===v.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(e===v.MoveRangeCommand.id)return this._moveRangeInterceptor(i.params);if(e===v.DeleteRangeMoveLeftCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,0)}else if(e===v.DeleteRangeMoveUpCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,1)}else if(e===v.InsertRangeMoveDownCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,2)}else if(e===v.InsertRangeMoveRightCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,3)}else if(e===v.SetRowHiddenCommand.id||e===v.SetSpecificRowsVisibleCommand.id){const r=i.params,{unitId:t,subUnitId:n,ranges:o}=r;return this._getDrawingUndoForRowVisible(t,n,o)}else if(e===v.SetSpecificColsVisibleCommand.id||e===v.SetColHiddenCommand.id){const r=i.params,{unitId:t,subUnitId:n,ranges:o}=r;return this._getDrawingUndoForColVisible(t,n,o)}else if(e===v.DeltaRowHeightCommand.id||e===v.SetRowHeightCommand.id||e===v.DeltaColumnWidthCommand.id||e===v.SetColWidthCommand.id){const r=i.params,{unitId:t,subUnitId:n,ranges:o}=r,a=e===v.DeltaRowHeightCommand.id||e===v.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(t,n,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,e){const r=v.getSheetCommandTarget(this._univerInstanceService);if(r==null)return{redos:[],undos:[]};const t=r.unitId,n=r.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(t,n),l=[],m=[];if(Object.keys(s).forEach(u=>{const c=s[u],{updateDrawings:d,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(i,e,c);l.push(...d),m.push(...g)}),l.length===0&&m.length===0)return{redos:[],undos:[]};if(l.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(l),{undo:c,redo:d,objects:g}=u;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:d,objects:g,type:p.DrawingApplyType.UPDATE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:c,objects:g,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(m),c=u.undo,d=u.redo,g=u.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:d,objects:g,type:p.DrawingApplyType.REMOVE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:c,objects:g,type:p.DrawingApplyType.INSERT}})}return o.push({id:V.id,params:[t]}),a.push({id:V.id,params:[t]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,e,r){const t=[],n=[],{sheetTransform:o,anchorType:a=p.SheetDrawingAnchorType.Position,transform:s,unitId:l,subUnitId:m,drawingId:u}=r,{from:c,to:d}=o,{row:g,column:S}=c,{row:f,column:w}=d;if(o==null||s==null)return{updateDrawings:t,deleteDrawings:n};const{startRow:I,endRow:R,startColumn:y,endColumn:D}=i;let C=null,P=null;if(e===0&&g>=I&&f<=R)if(S>=y&&w<=D)n.push({unitId:l,subUnitId:m,drawingId:u});else{const _=this._shrinkCol(o,s,y,D,a);C=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(e===1&&S>=y&&w<=D)if(g>=I&&f<=R)n.push({unitId:l,subUnitId:m,drawingId:u});else{const _=this._shrinkRow(o,s,I,R,a);C=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(e===2){const _=this._expandRow(o,s,I,R,a);C=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(e===3){const _=this._expandCol(o,s,y,D,a);C=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}if(C!=null&&P!=null){const _=H(C,this._selectionRenderService,this._sheetSkeletonManagerService);t.push({...r,sheetTransform:C,transform:_})}return{updateDrawings:t,deleteDrawings:n}}_remainDrawingSize(i,e,r){const t=G({...i},this._selectionRenderService);t!=null&&e.push({...r,sheetTransform:t})}_getDrawingUndoForColVisible(i,e,r){const t=this._drawingManagerService.getDrawingData(i,e),n=[],o=[];if(Object.keys(t).forEach(u=>{const c=t[u],{sheetTransform:d,transform:g,anchorType:S=p.SheetDrawingAnchorType.Position}=c;if(S===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,n,c);else{const{from:f,to:w}=d,{row:I,column:R}=f,{row:y,column:D}=w;for(let C=0;C<r.length;C++){const P=r[C],{startRow:_,endRow:U,startColumn:A,endColumn:T}=P;if(D<A)continue;if(S===p.SheetDrawingAnchorType.Position){let M=null,L=null;if(R>=A&&R<=T){const X=this._selectionRenderService.attachRangeWithCoord({startColumn:R,endColumn:T,startRow:f.row,endRow:w.row});if(X==null)return;L={...g,left:X.startX}}if(L!=null&&(M=G(L,this._selectionRenderService),M!=null&&L!=null)){n.push({...c,sheetTransform:M,transform:L});break}this._remainDrawingSize(g,n,c);continue}if(R>=A&&D<=T)continue;let b=null,E=null;if(R>=A&&R<=T){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:R,endColumn:T,startRow:f.row,endRow:w.row});if(M==null)return;E={...g,left:(M==null?void 0:M.startX)||0,width:((g==null?void 0:g.width)||0)-M.endX+M.startX}}else if(D>=A&&D<=T){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:A,endColumn:D,startRow:f.row,endRow:w.row});if(M==null)return;E={...g,left:M.startX-((g==null?void 0:g.width)||0)}}else{const M=this._selectionRenderService.attachRangeWithCoord({startColumn:A,endColumn:T,startRow:f.row,endRow:w.row});if(M==null)return;if(E={...g,width:((g==null?void 0:g.width)||0)-M.endX+M.startX},b=G(E,this._selectionRenderService),b!=null&&E!=null){o.push({...c,sheetTransform:b,transform:E});break}}if(E!=null&&(b=G(E,this._selectionRenderService)),E!=null&&b!=null){n.push({...c,sheetTransform:b,transform:E});break}else this._remainDrawingSize(g,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,e,n),l=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,e,o);l.push(...u),m.push(...c)}return{redos:a,undos:s,preRedos:l,preUndos:m}}_createUndoAndRedoMutation(i,e,r){const t=this._sheetDrawingService.getBatchUpdateOp(r),{undo:n,redo:o,objects:a}=t,s=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:e,op:o,objects:a,type:p.DrawingApplyType.UPDATE}},{id:V.id,params:[i]}],l=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:e,op:n,objects:a,type:p.DrawingApplyType.UPDATE}},{id:V.id,params:[i]}];return{redos:s,undos:l}}_getDrawingUndoForRowVisible(i,e,r){const t=this._drawingManagerService.getDrawingData(i,e),n=[],o=[];if(Object.keys(t).forEach(u=>{const c=t[u],{sheetTransform:d,transform:g,anchorType:S=p.SheetDrawingAnchorType.Position}=c;if(S===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,n,c);else{const{from:f,to:w}=d,{row:I,column:R}=f,{row:y,column:D}=w;for(let C=0;C<r.length;C++){const P=r[C],{startRow:_,endRow:U,startColumn:A,endColumn:T}=P;if(y<_)continue;if(S===p.SheetDrawingAnchorType.Position){let M=null,L=null;if(I>=_&&I<=U){const X=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:I,endRow:U});if(X==null)return;L={...g,top:X.startY}}if(L!=null&&(M=G(L,this._selectionRenderService),M!=null&&L!=null)){n.push({...c,sheetTransform:M,transform:L});break}this._remainDrawingSize(g,n,c);continue}if(I>=_&&y<=U)continue;let b=null,E=null;if(I>=_&&I<=U){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:I,endRow:U});if(M==null)return;E={...g,top:(M==null?void 0:M.startY)||0,height:((g==null?void 0:g.height)||0)-M.endY+M.startY}}else if(y>=_&&y<=U){const M=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:y});if(M==null)return;E={...g,top:M.startY-((g==null?void 0:g.height)||0)}}else{const M=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:U});if(M==null)return;if(E={...g,height:((g==null?void 0:g.height)||0)-M.endY+M.startY},b=G(E,this._selectionRenderService),b!=null&&E!=null){o.push({...c,sheetTransform:b,transform:E});break}}if(E!=null&&(b=G(E,this._selectionRenderService)),E!=null&&b!=null){n.push({...c,sheetTransform:b,transform:E});break}else this._remainDrawingSize(g,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,e,n),l=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,e,o);l.push(...u),m.push(...c)}return{redos:a,undos:s,preRedos:l,preUndos:m}}_getDrawingUndoForRowAndColSize(i,e,r,t){const n=this._drawingManagerService.getDrawingData(i,e),o=[];return Object.keys(n).forEach(a=>{const s=n[a],{sheetTransform:l,transform:m,anchorType:u=p.SheetDrawingAnchorType.Position}=s;if(u===p.SheetDrawingAnchorType.None)this._remainDrawingSize(m,o,s);else{const{from:c,to:d}=l,{row:g,column:S}=c,{row:f,column:w}=d;for(let I=0;I<r.length;I++){const R=r[I],{startRow:y,endRow:D,startColumn:C,endColumn:P}=R;if(f<y||w<C)continue;if(u===p.SheetDrawingAnchorType.Position&&(g<=y&&f>=D||S<=C&&w>=P)){this._remainDrawingSize(m,o,s);continue}const _=H({...l},this._selectionRenderService,this._sheetSkeletonManagerService);if(_!=null){o.push({...s,transform:_});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,e,o)}_getUnitIdAndSubUnitId(i,e){let r,t;if(e==="insert")r=i.unitId,t=i.subUnitId;else{const n=v.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;r=n.unitId,t=n.subUnitId}return{unitId:r,subUnitId:t}}_moveRowInterceptor(i,e){const r=this._getUnitIdAndSubUnitId(i,e);if(r==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=r,{range:o}=i,a=o.startRow,s=o.endRow,l=[],m=[],u=this._sheetDrawingService.getDrawingData(t,n),c=[],d=[];if(Object.keys(u).forEach(g=>{const S=u[g],{sheetTransform:f,transform:w,anchorType:I=p.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let R,y;if(e==="insert"){const C=this._expandRow(f,w,a,s,I);R=C==null?void 0:C.newSheetTransform,y=C==null?void 0:C.newTransform}else{const{from:C,to:P}=f,{row:_}=C,{row:U}=P;if(I===p.SheetDrawingAnchorType.Both&&_>=a&&U<=s)d.push({unitId:t,subUnitId:n,drawingId:g});else{const A=this._shrinkRow(f,w,a,s,I);R=A==null?void 0:A.newSheetTransform,y=A==null?void 0:A.newTransform}}if(!R||!y)return;const D={unitId:t,subUnitId:n,drawingId:g,transform:y,sheetTransform:R};c.push(D)}),c.length===0&&d.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:S,redo:f,objects:w}=g;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.UPDATE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.UPDATE}})}if(d.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(d),S=g.undo,f=g.redo,w=g.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.REMOVE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.INSERT}})}return l.push({id:V.id,params:[t]}),m.push({id:V.id,params:[t]}),{redos:l,undos:m}}_moveRangeInterceptor(i){const{fromRange:e,toRange:r}=i,t=v.getSheetCommandTarget(this._univerInstanceService);if(!t)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=t,a=this._sheetDrawingService.getDrawingData(n,o),s=[],l=this._selectionRenderService.attachRangeWithCoord(e),m=this._selectionRenderService.attachRangeWithCoord(r);if(!l||!m)return{redos:[],undos:[]};Object.keys(a).forEach(d=>{const g=a[d],{sheetTransform:S,transform:f,anchorType:w=p.SheetDrawingAnchorType.Position}=g;if(!S||!f||w===p.SheetDrawingAnchorType.None)return;const{left:I=0,top:R=0,width:y=0,height:D=0}=f,{drawingStartX:C,drawingEndX:P,drawingStartY:_,drawingEndY:U}={drawingStartX:I,drawingEndX:I+y,drawingStartY:R,drawingEndY:R+D};if(!(l.startX<=C&&P<=l.endX&&l.startY<=U&&_<=l.endY))return;const{to:T,from:b}=S,E=r.startRow-e.startRow,M=r.startColumn-e.startColumn;let L,X;if(w===p.SheetDrawingAnchorType.Both){const z=this._selectionRenderService.attachRangeWithCoord({startRow:T.row,endRow:b.row,startColumn:T.column,endColumn:b.column}),q=this._selectionRenderService.attachRangeWithCoord({startRow:T.row+E,endRow:b.row+E,startColumn:T.column+M,endColumn:b.column+M});if(!q||!z)return;const ge=q.endX-q.startX-(z.endX-z.startX),k=q.endY-q.startY-(z.endY-z.startY);L={to:{...T,row:T.row+E,column:T.column+M,columnOffset:T.columnOffset+ge},from:{...b,row:b.row+E,column:b.column+M,columnOffset:T.columnOffset+ge,rowOffset:T.rowOffset+k}},X=H(L,this._selectionRenderService,this._sheetSkeletonManagerService)}else{const z=m.startX-l.startX,q=m.startY-l.startY;X={...f,left:I+z,top:R+q},L=G(X,this._selectionRenderService)}if(!L||!X)return;const Le={unitId:n,subUnitId:o,drawingId:d,transform:X,sheetTransform:L};s.push(Le)});const u=[],c=[];if(s.length>0){const d=this._sheetDrawingService.getBatchUpdateOp(s),{undo:g,redo:S,objects:f}=d;u.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:S,objects:f,type:p.DrawingApplyType.UPDATE}}),c.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:g,objects:f,type:p.DrawingApplyType.UPDATE}})}return{redos:u,undos:c}}_moveColInterceptor(i,e){const r=this._getUnitIdAndSubUnitId(i,e);if(r==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=r,{range:o}=i,a=o.startColumn,s=o.endColumn,l=[],m=[],u=this._sheetDrawingService.getDrawingData(t,n),c=[],d=[];if(Object.keys(u).forEach(g=>{const S=u[g],{sheetTransform:f,transform:w,anchorType:I=p.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let R,y;if(e==="insert"){const C=this._expandCol(f,w,a,s,I);R=C==null?void 0:C.newSheetTransform,y=C==null?void 0:C.newTransform}else{const{from:C,to:P}=f,{column:_}=C,{column:U}=P;if(_>=a&&U<=s&&I===p.SheetDrawingAnchorType.Both)d.push({unitId:t,subUnitId:n,drawingId:g});else{const T=this._shrinkCol(f,w,a,s,I);R=T==null?void 0:T.newSheetTransform,y=T==null?void 0:T.newTransform}}if(!R||!y)return;const D={unitId:t,subUnitId:n,drawingId:g,transform:y,sheetTransform:R};c.push(D)}),c.length===0&&d.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:S,redo:f,objects:w}=g;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.UPDATE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.UPDATE}})}if(d.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(d),S=g.undo,f=g.redo,w=g.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.REMOVE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.INSERT}})}return l.push({id:V.id,params:[t]}),m.push({id:V.id,params:[t]}),{redos:l,undos:m}}_expandCol(i,e,r,t,n=p.SheetDrawingAnchorType.Position){const o=t-r+1,{from:a,to:s}=i,{column:l}=a,{column:m}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};let u=null,c=null;if(l>=r){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:r,endColumn:t,startRow:a.row,endRow:s.row});if(d==null)return;c={...e,left:(e.left||0)+d.endX-d.startX},u=G(c,this._selectionRenderService)}else if(m>=t)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m+o}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService);else return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(i,e,r,t,n=p.SheetDrawingAnchorType.Position){const o=t-r+1,{from:a,to:s}=i,{column:l}=a,{column:m}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};let u=null,c=null;if(l>t){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:r,endColumn:t,startRow:a.row,endRow:s.row});if(d==null)return;c={...e,left:(e.left||0)-(d.endX-d.startX)},u=G(c,this._selectionRenderService)}else if(l>=r&&m<=t){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:r,endColumn:t,startRow:0,endRow:0});u={from:{...a,columnOffset:0},to:{...s,columnOffset:s.columnOffset-a.columnOffset}},c={...e,left:d==null?void 0:d.startX}}else if(l<r&&m>t)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m-o}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService);else return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};else if(l>=r&&l<=t){if(l===r)c={...e,left:(e.left||0)-i.from.columnOffset};else{const d=this._selectionRenderService.attachRangeWithCoord({startColumn:r,endColumn:l-1,startRow:a.row,endRow:s.row});if(d==null)return;c={...e,left:(e.left||0)-d.endX+d.startX-i.from.columnOffset}}u=G(c,this._selectionRenderService)}else if(m>=r&&m<=t&&n===p.SheetDrawingAnchorType.Both){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:r-1,endColumn:r-1,startRow:a.row,endRow:s.row});if(d==null)return;u={from:{...a},to:{...s,column:r-1,columnOffset:d.endX-d.startX}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService)}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(i,e,r,t,n=p.SheetDrawingAnchorType.Position){const o=t-r+1,{from:a,to:s}=i,{row:l}=a,{row:m}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};let u=null,c=null;if(l>=r){const d=this._selectionRenderService.attachRangeWithCoord({startRow:r,endRow:t,startColumn:a.column,endColumn:s.column});if(d==null)return;c={...e,top:(e.top||0)+d.endY-d.startY},u=G(c,this._selectionRenderService)}else if(m>=t)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m+o}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService);else return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(i,e,r,t,n=p.SheetDrawingAnchorType.Position){const o=t-r+1,{from:a,to:s}=i,{row:l}=a,{row:m}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};let u=null,c=null;if(l>t)u={from:{...a,row:l-o},to:{...s,row:m-o}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService);else if(l>=r&&m<=t){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:0,endColumn:0,startRow:r,endRow:t});u={from:{...a,rowOffset:0},to:{...s,rowOffset:s.rowOffset-a.rowOffset}},c={...e,top:d==null?void 0:d.startY}}else if(l<r&&m>t)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m-o}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService);else return{newSheetTransform:G({...e},this._selectionRenderService),newTransform:e};else if(l>=r&&l<=t){if(l===r)c={...e,top:(e.top||0)-i.from.rowOffset};else{const d=this._selectionRenderService.attachRangeWithCoord({startRow:r,endRow:l-1,startColumn:a.column,endColumn:s.column});if(d==null)return;c={...e,top:(e.top||0)-d.endY+d.startY-i.from.rowOffset}}u=G(c,this._selectionRenderService)}else if(m>=r&&m<=t&&n===p.SheetDrawingAnchorType.Both){const d=this._selectionRenderService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:r-1,endRow:r-1});if(d==null)return;u={from:{...a},to:{...s,row:r-1,rowOffset:d.endY-d.startY}},c=H(u,this._selectionRenderService,this._sheetSkeletonManagerService)}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===v.SetWorksheetActiveOperation.id&&setTimeout(()=>{const e=i.params,{unitId:r,subUnitId:t}=e,n=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(n).forEach(s=>{const l=n[s];Object.keys(l).forEach(m=>{const u=l[m].data;u!=null&&Object.keys(u).forEach(c=>{if(s===r&&m===t){const d=u[c];d.transform=H(d.sheetTransform,this._selectionRenderService,this._sheetSkeletonManagerService),o.push(u[c])}else a.push(u[c])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Mt.includes(i.id)&&requestIdleCallback(()=>{const e=i.params,{unitId:r,subUnitId:t,ranges:n}=e;this._refreshDrawingTransform(r,t,n)})}))}_refreshDrawingTransform(i,e,r){const t=this._drawingManagerService.getDrawingData(i,e),n=[];Object.keys(t).forEach(o=>{const a=t[o],{sheetTransform:s,anchorType:l=p.SheetDrawingAnchorType.Position}=a;if(l===p.SheetDrawingAnchorType.None)return!0;const{from:m,to:u}=s,{row:c,column:d}=m,{row:g,column:S}=u;for(let f=0;f<r.length;f++){const w=r[f],{startRow:I,endRow:R,startColumn:y,endColumn:D}=w;if(h.Rectangle.intersects({startRow:I,endRow:R,startColumn:y,endColumn:D},{startRow:c,endRow:g,startColumn:d,endColumn:S})||c>R||d>D){n.push({...a,transform:H(s,this._selectionRenderService,this._sheetSkeletonManagerService)});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(V.id,[i]))}};Ce=It([h.OnLifecycle(h.LifecycleStages.Rendered,Ce),re(1,h.ICommandService),re(2,W.Inject(v.SheetInterceptorService)),re(3,p.ISheetDrawingService),re(4,N.IDrawingManagerService),re(5,B.ISelectionRenderService),re(6,h.IUniverInstanceService),re(7,W.Inject(B.SheetSkeletonManagerService))],Ce);var Rt=Object.defineProperty,Dt=Object.getOwnPropertyDescriptor,Tt=(i,e,r,t)=>{for(var n=t>1?void 0:t?Dt(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Rt(e,r,n),n},ie=(i,e)=>(r,t)=>e(r,t,i);function Ot(i,e,r,t){const{scaleX:n,scaleY:o}=e.getAncestorScale(),a=e.getViewport($.SHEET_VIEWPORT_KEY.VIEW_MAIN),s={left:!0,top:!0};if(!a)return{...i,absolute:s};const{left:l,right:m,top:u,bottom:c}=i,d=t.getFreeze(),{startColumn:g,startRow:S,xSplit:f,ySplit:w}=d,I=r.getNoMergeCellPositionByIndexWithNoHeader(S-w,g-f),R=r.getNoMergeCellPositionByIndexWithNoHeader(S,g),{rowHeaderWidth:y,columnHeaderHeight:D}=r,C=R.startX-I.startX,P=R.startY-I.startY,{top:_,left:U,viewportScrollX:A,viewportScrollY:T}=a;let b,E;l<U?(s.left=!0,b=(C+y+(l-U))*n,E=Math.max(Math.min((C+y+(m-U))*n,(C+y)*n),(m-A)*n)):(s.left=!1,b=Math.max((l-A)*n,(C+y)*n),E=Math.max((m-A)*n,(C+y)*n));let M,L;return u<_?(s.top=!0,M=(P+D+(u-_))*o,L=Math.max(Math.min((P+D+(m-_))*o,(P+D)*o),(c-T)*o)):(s.top=!1,M=Math.max((u-T)*o,(P+D)*o),L=Math.max((c-T)*o,(P+D)*o)),{left:b,right:E,top:M,bottom:L,absolute:s}}const Ue=(i,e,r,t)=>{const{scene:n}=e,{left:o,top:a,width:s,height:l,angle:m}=i,u={left:o,right:o+s,top:a,bottom:a+l},c=Ot(u,n,r,t);return{startX:c.left,endX:c.right,startY:c.top,endY:c.bottom,rotate:m,width:s,height:l,absolute:c.absolute}};O.SheetCanvasFloatDomManagerService=class extends h.Disposable{constructor(r,t,n,o,a,s,l){super();J(this,"_domLayerMap",new Map);J(this,"_domLayerInfoMap",new Map);J(this,"_transformChange$",new F.Subject);J(this,"transformChange$",this._transformChange$.asObservable());J(this,"_remove$",new F.Subject);J(this,"remove$",this._remove$.asObservable());this._renderManagerService=r,this._univerInstanceService=t,this._commandService=n,this._drawingManagerService=o,this._selectionRenderService=a,this._canvasFloatDomService=s,this._sheetDrawingService=l,this._drawingAddListener(),this._scrollUpdateListener(),this._featureUpdateListener(),this._deleteListener()}_ensureMap(r,t){let n=this._domLayerMap.get(r);n||(n=new Map,this._domLayerMap.set(r,n));let o=n.get(t);return o||(o=new Map,n.set(t,o)),o}_getSceneAndTransformerByDrawingSearch(r){if(r==null)return;const t=this._renderManagerService.getRenderById(r),n=t==null?void 0:t.scene;if(t==null||n==null)return null;const o=n.getTransformerByCreate(),a=t.engine.getCanvasElement();return{scene:n,transformer:o,renderObject:t,canvas:a}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(r=>{r.forEach(t=>{var q,ge;const{unitId:n,subUnitId:o,drawingId:a}=t,s=v.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),l=this._drawingManagerService.getDrawingByParam(t),m=(q=this._renderManagerService.getRenderById(n))==null?void 0:q.with(B.SheetSkeletonManagerService).getUnitSkeleton(n,o);if(l==null||s==null||m==null)return;const{transform:u,drawingType:c}=l;if(c!==h.DrawingTypeEnum.DRAWING_DOM)return;const d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{scene:g,canvas:S}=d;if(u==null)return!0;const{left:f,top:w,width:I,height:R,angle:y,flipX:D,flipY:C,skewX:P,skewY:_}=u,U=N.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),A=g.getObject(U);if(A!=null){A.transformByState({left:f,top:w,width:I,height:R,angle:y,flipX:D,flipY:C,skewX:P,skewY:_});return}const T={left:f,top:w,width:I,height:R,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},b=new $.Rect(U,T);g.addObject(b,$.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(b);const E=this._ensureMap(n,o),M=new h.DisposableCollection,L=Ue(b,d.renderObject,m.skeleton,s.worksheet),X=new F.BehaviorSubject(L),Le={dispose:M,rect:b,position$:X,unitId:n,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:X,id:a,componentKey:l.componentKey,onPointerDown:k=>{S.dispatchEvent(new PointerEvent(k.type,k))},onPointerMove:k=>{S.dispatchEvent(new PointerEvent(k.type,k))},onPointerUp:k=>{S.dispatchEvent(new PointerEvent(k.type,k))},onWheel:k=>{S.dispatchEvent(new WheelEvent(k.type,k))},props:(ge=E.get(a))==null?void 0:ge.props});const z=b.onTransformChange$.subscribeEvent(()=>{const k=Ue(b,d.renderObject,m.skeleton,s.worksheet);X.next(k)});M.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),z&&M.add(z),this._domLayerInfoMap.set(a,Le)})}))}_scrollUpdateListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{var n,o;const t=(a,s)=>{var g;const l=this._getSceneAndTransformerByDrawingSearch(a),m=this._ensureMap(a,s),u=Array.from(m.keys()),c=v.getSheetCommandTarget(this._univerInstanceService,{unitId:a,subUnitId:s}),d=(g=this._renderManagerService.getRenderById(a))==null?void 0:g.with(B.SheetSkeletonManagerService).getUnitSkeleton(a,s);!l||!c||!d||u.forEach(S=>{const f=this._domLayerInfoMap.get(S);if(f){const w=Ue(f.rect,l.renderObject,d.skeleton,c.worksheet);f.position$.next(w)}})};if(r.id===B.SetScrollOperation.id){const a=r.params,{unitId:s,sheetId:l}=a;t(s,l)}else if(r.id===B.SetZoomRatioOperation.id){const a=r.params,{unitId:s}=a;Array.from((o=(n=this._domLayerMap.get(s))==null?void 0:n.keys())!=null?o:[]).forEach(m=>{t(s,m)})}else if(r.id===v.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=r.params;t(a,s)}}))}_getPosition(r){const{startX:t,endX:n,startY:o,endY:a}=r,s=this._selectionRenderService.getSelectionCellByPosition(t,o);if(s==null)return;const l={column:s.actualColumn,columnOffset:t-s.startX,row:s.actualRow,rowOffset:o-s.startY},m=this._selectionRenderService.getSelectionCellByPosition(n,a);if(m==null)return;const u={column:m.actualColumn,columnOffset:n-m.startX,row:m.actualRow,rowOffset:a-m.startY};return{from:l,to:u}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(r=>{r.forEach(t=>{const n=this._drawingManagerService.getDrawingByParam(t);if(!n||n.drawingType!==h.DrawingTypeEnum.DRAWING_DOM)return;const o={...n.transform};this._transformChange$.next({id:t.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(r=>{r.forEach(t=>{this._removeDom(t.drawingId)})}))}addFloatDomToPosition(r){const t=v.getSheetCommandTarget(this._univerInstanceService,{unitId:r.unitId,subUnitId:r.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:n,subUnitId:o}=t,{initPosition:a,componentKey:s}=r,l=h.Tools.generateRandomId(),m=this._getPosition(a);if(m==null)return;this._ensureMap(n,o).set(l,r);const c={unitId:n,subUnitId:o,drawingId:l,drawingType:h.DrawingTypeEnum.DRAWING_DOM,componentKey:s,sheetTransform:m,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY}};return this._commandService.executeCommand(we.id,{unitId:n,drawings:[c]}),{id:l,dispose:()=>{this._removeDom(l,!0)}}}_removeDom(r,t=!1){const n=this._domLayerInfoMap.get(r);if(!n)return;const{unitId:o,subUnitId:a}=n;this._domLayerInfoMap.delete(r),n.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(n.rect),t){this._ensureMap(o,a).delete(r);const m=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:r});if(!m)return;const u=this._sheetDrawingService.getBatchRemoveOp([m]),{redo:c,objects:d}=u;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:c,objects:d,type:p.DrawingApplyType.REMOVE})}}},O.SheetCanvasFloatDomManagerService=Tt([ie(0,W.Inject($.IRenderManagerService)),ie(1,h.IUniverInstanceService),ie(2,W.Inject(h.ICommandService)),ie(3,N.IDrawingManagerService),ie(4,B.ISelectionRenderService),ie(5,W.Inject(Y.CanvasFloatDomService)),ie(6,p.ISheetDrawingService)],O.SheetCanvasFloatDomManagerService);var Et=Object.defineProperty,bt=Object.getOwnPropertyDescriptor,Pt=(i,e,r,t)=>{for(var n=t>1?void 0:t?bt(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Et(e,r,n),n},Ie=(i,e)=>(r,t)=>e(r,t,i);let ye=class extends h.Disposable{constructor(i,e,r,t){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=e,this._drawingManagerService=r,this._renderManagerService=t,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,e,r)=>{const{unitId:t,scene:n,subUnitId:o}=e,a=this._drawingManagerService.getDrawingDataForUnit(t),s=a==null?void 0:a[o];return s&&s.order.forEach(l=>{this._drawingRenderService.renderDrawing(s.data[l],n)}),r()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,e,r)=>{const{unitId:t,subUnitId:n}=e,o=this._renderManagerService.getRenderById(t);if(!o)return r(i);const a=o.with(B.SheetSkeletonManagerService).getUnitSkeleton(t,n);if(!a)return r(i);const s=this._drawingManagerService.getDrawingDataForUnit(t),l=s==null?void 0:s[e.subUnitId];if(!l)return r(i);const{scaleX:m,scaleY:u}=o.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},d=l.order.map(g=>l.data[g]).filter(g=>g.drawingType!==N.DrawingTypeEnum.DRAWING_DOM);return d.length?(d.forEach(g=>{if(!g.groupId&&g.transform&&h.Tools.isDefine(g.transform.left)&&h.Tools.isDefine(g.transform.top)&&h.Tools.isDefine(g.transform.width)&&h.Tools.isDefine(g.transform.height)){const S=a.skeleton.getCellPositionByOffset(g.transform.left,g.transform.top,m,u,{x:0,y:0}),f=a.skeleton.getCellPositionByOffset(g.transform.left+g.transform.width,g.transform.top+g.transform.height,m,u,{x:0,y:0});S.column<c.startColumn&&(c.startColumn=S.column),S.row<c.startRow&&(c.startRow=S.row),c.endRow<f.row&&(c.endRow=f.row),c.endColumn<f.column&&(c.endColumn=f.column)}}),r(c)):r(i)}}))}};ye=Pt([h.OnLifecycle(h.LifecycleStages.Rendered,ye),Ie(0,W.Inject(B.SheetPrintInterceptorService)),Ie(1,W.Inject(te.DrawingRenderService)),Ie(2,N.IDrawingManagerService),Ie(3,$.IRenderManagerService)],ye);var At=Object.defineProperty,Ut=Object.getOwnPropertyDescriptor,Nt=(i,e,r,t)=>{for(var n=t>1?void 0:t?Ut(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&At(e,r,n),n},me=(i,e)=>(r,t)=>e(r,t,i);let Me=class extends h.Disposable{constructor(i,e,r,t,n){super(),this._drawingManagerService=i,this._renderManagerService=e,this._permissionService=r,this._univerInstanceService=t,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(F.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([e,r])=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}e.activeSheet$.subscribe(t=>{if(!t){this._drawingManagerService.setDrawingVisible(!1);return}const n=e.getUnitId(),o=t.getSheetId();if(this._permissionService.composePermission([new v.WorkbookViewPermission(n).id,new v.WorksheetViewPermission(n,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const s=e.getUnitId(),l=t.getSheetId(),m=this._drawingManagerService.getDrawingData(s,l),u=Object.values(m),c=this._renderManagerService.getRenderById(s),d=c==null?void 0:c.scene;if(d==null)return;d.getAllObjects().forEach(S=>{S.classType===$.RENDER_CLASS_TYPE.IMAGE&&u.some(f=>S.oKey.includes(f.drawingId))&&d.removeObject(S)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(F.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([e,r])=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}e.activeSheet$.subscribe(t=>{if(!t){this._drawingManagerService.setDrawingEditable(!1);return}const n=e.getUnitId(),o=t.getSheetId();if(this._permissionService.composePermission([new v.WorkbookEditablePermission(n).id,new v.WorksheetEditPermission(n,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const s=e.getUnitId(),l=t.getSheetId(),m=this._drawingManagerService.getDrawingData(s,l),u=Object.values(m),c=this._renderManagerService.getRenderById(s),d=c==null?void 0:c.scene;if(d==null)return;d.getAllObjects().forEach(S=>{S.classType===$.RENDER_CLASS_TYPE.IMAGE&&u.some(f=>S.oKey.includes(f.drawingId))&&d.detachTransformerFrom(S)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(F.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([e,r])=>{e&&e.activeSheet$.subscribe(t=>{var c;if(!t)return;const n=e.getUnitId(),o=t.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(n),l=s==null?void 0:s.scene;if(l==null)return;const m=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookViewPermission(n).id,new v.WorksheetViewPermission(n,o).id]).pipe(F.map(d=>d.every(g=>g.value)));u==null||u.pipe(F.filter(d=>d!==a),F.distinctUntilChanged()).subscribe({next:d=>{a=d,this._drawingManagerService.setDrawingVisible(d);const g=l.getAllObjects(),S=this._drawingManagerService.getDrawingData(n,o),f=Object.values(S);d?this._drawingManagerService.addNotification(f):(g.forEach(w=>{w.classType===$.RENDER_CLASS_TYPE.IMAGE&&f.some(I=>w.oKey.includes(I.drawingId))&&l.removeObject(w)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new v.WorksheetViewPermission(n,o).id))==null||c.pipe(F.filter(d=>d.value!==a),F.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const d=this._drawingManagerService.getDrawingData(n,o),g=Object.values(d);this._drawingManagerService.addNotification(g)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(F.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([e,r])=>{e&&e.activeSheet$.subscribe(t=>{var c;if(!t)return;const n=e.getUnitId(),o=t.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(n),l=s==null?void 0:s.scene;if(l==null)return;const m=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookEditablePermission(n).id,new v.WorksheetEditPermission(n,o).id]).pipe(F.map(d=>d.every(g=>g.value)));u==null||u.pipe(F.filter(d=>d!==a),F.distinctUntilChanged()).subscribe({next:d=>{a=d,this._drawingManagerService.setDrawingEditable(d);const g=l.getAllObjects(),S=this._drawingManagerService.getDrawingData(n,o),f=Object.values(S);d?(g.forEach(w=>{w.classType===$.RENDER_CLASS_TYPE.IMAGE&&f.some(I=>w.oKey.includes(I.drawingId))&&l.attachTransformerTo(w)}),this._drawingManagerService.addNotification(f)):(g.forEach(w=>{w.classType===$.RENDER_CLASS_TYPE.IMAGE&&f.some(I=>w.oKey.includes(I.drawingId))&&l.detachTransformerFrom(w)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new v.WorksheetEditPermission(n,o).id))==null||c.pipe(F.filter(d=>d.value!==a),F.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const d=e.getUnitId(),g=t.getSheetId(),S=this._drawingManagerService.getDrawingData(d,g),f=Object.values(S),w=this._renderManagerService.getRenderById(d),I=w==null?void 0:w.scene;if(I==null)return;this._drawingManagerService.setDrawingEditable(!0),I.getAllObjects().forEach(y=>{y.classType===$.RENDER_CLASS_TYPE.IMAGE&&f.some(D=>y.oKey.includes(D.drawingId))&&I.detachTransformerFrom(y)})}})})}))}};Me=Nt([h.OnLifecycle(h.LifecycleStages.Rendered,Me),me(0,N.IDrawingManagerService),me(1,$.IRenderManagerService),me(2,h.IPermissionService),me(3,h.IUniverInstanceService),me(4,W.Inject(h.UserManagerService))],Me);var Lt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,Wt=(i,e,r,t)=>{for(var n=t>1?void 0:t?jt(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Lt(e,r,n),n},Re=(i,e)=>(r,t)=>e(r,t,i);let De=class extends h.Disposable{constructor(e,r,t,n){super();J(this,"_copyInfo");this._sheetClipboardService=e,this._selectionRenderService=r,this._sheetDrawingService=t,this._injector=n,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(e,r,t)=>this._collect(e,r,t),onPasteCells:(e,r,t,n)=>{const{copyType:o=B.COPY_TYPE.COPY,pasteType:a}=n,{range:s}=e||{},{range:l,unitId:m,subUnitId:u}=r;return this._generateMutations(l,{copyType:o,pasteType:a,copyRange:s,unitId:m,subUnitId:u})},onPastePlainText:(e,r)=>({undos:[],redos:[]})})}_collect(e,r,t){const n=this._selectionRenderService.attachRangeWithCoord(t);if(!n)return;const{startX:o,endX:a,startY:s,endY:l}=n,m=this._sheetDrawingService.getDrawingData(e,r),u=[];Object.keys(m).forEach(c=>{const d=m[c],{transform:g}=d;if(d.anchorType!==p.SheetDrawingAnchorType.Both||!g)return;const{left:S=0,top:f=0,width:w=0,height:I=0}=g,{drawingStartX:R,drawingEndX:y,drawingStartY:D,drawingEndY:C}={drawingStartX:S,drawingEndX:S+w,drawingStartY:f,drawingEndY:f+I};o<=R&&y<=a&&s<=D&&C<=l&&u.push(d)}),u.length&&(this._copyInfo={drawings:u,unitId:e,subUnitId:r})}_generateMutations(e,r){if(!this._copyInfo)return{redos:[],undos:[]};if([B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(r.pasteType))return{redos:[],undos:[]};const{copyRange:t}=r;if(!t)return{redos:[],undos:[]};const{drawings:n,unitId:o,subUnitId:a}=this._copyInfo,{ranges:[s,l],mapFunc:m}=B.virtualizeDiscreteRanges([t,e]),{row:u,col:c}=m(s.startRow,s.startColumn),{row:d,col:g}=m(l.startRow,l.startColumn),S=this._selectionRenderService.attachRangeWithCoord({startRow:u,endRow:u,startColumn:c,endColumn:c}),f=this._selectionRenderService.attachRangeWithCoord({startRow:d,endRow:d,startColumn:g,endColumn:g});if(!S||!f)return{redos:[],undos:[]};const w=[],I=[],R=f.startX-S.startX,y=f.startY-S.startY,D=d-u,C=g-c,P=r.copyType===B.COPY_TYPE.CUT,{_sheetDrawingService:_}=this;return n.forEach(U=>{const{transform:A,sheetTransform:T}=U;if(!A)return;const b={...U,unitId:o,subUnitId:a,drawingId:P?U.drawingId:h.Tools.generateRandomId(),transform:{...A,left:A.left+R,top:A.top+y},sheetTransform:{to:{...T.to,row:T.to.row+D,column:T.to.column+C},from:{...T.from,row:T.from.row+D,column:T.from.column+C}}};if(P){const{undo:E,redo:M,objects:L}=_.getBatchUpdateOp([b]);w.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:M,objects:L}}),I.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:E,objects:L}})}else{const{undo:E,redo:M,objects:L}=_.getBatchAddOp([b]);w.push({id:p.SetDrawingApplyMutation.id,params:{op:M,unitId:o,subUnitId:a,objects:L,type:p.DrawingApplyType.INSERT}}),I.push({id:p.SetDrawingApplyMutation.id,params:{op:E,unitId:o,subUnitId:a,objects:L,type:p.DrawingApplyType.REMOVE}})}}),{redos:w,undos:I}}};De=Wt([h.OnLifecycle(h.LifecycleStages.Ready,De),Re(0,B.ISheetClipboardService),Re(1,B.ISelectionRenderService),Re(2,p.ISheetDrawingService),Re(3,W.Inject(W.Injector))],De);var Xe=Object.defineProperty,$t=Object.getOwnPropertyDescriptor,Bt=(i,e,r)=>e in i?Xe(i,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[e]=r,Gt=(i,e,r,t)=>{for(var n=t>1?void 0:t?$t(e,r):e,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(t?a(e,r,n):a(n))||n);return t&&n&&Xe(e,r,n),n},Ne=(i,e)=>(r,t)=>e(r,t,i),He=(i,e,r)=>Bt(i,typeof e!="symbol"?e+"":e,r);const Vt="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends h.Plugin{constructor(r={},t,n,o){super();J(this,"_pluginConfig");this._injector=t,this._localeService=n,this._renderManagerService=o,this._pluginConfig=h.Tools.deepMerge({},vt,r)}onStarting(r){super.onStarting(r),this._initDependencies(r)}_initDependencies(r){const t=[[O.SheetCanvasFloatDomManagerService],[ue,{useFactory:()=>this._injector.createInstance(ue,this._pluginConfig)}],[Se],[ye],[Me],[De]],n=[ve,Ce];t.forEach(o=>r.add(o)),n.forEach(o=>this._renderManagerService.registerRenderModule(h.UniverInstanceType.UNIVER_SHEET,o))}},He(O.UniverSheetsDrawingUIPlugin,"type",h.UniverInstanceType.UNIVER_SHEET),He(O.UniverSheetsDrawingUIPlugin,"pluginName",Vt),O.UniverSheetsDrawingUIPlugin=Gt([h.DependentOn(N.UniverDrawingPlugin,te.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),Ne(1,W.Inject(W.Injector)),Ne(2,W.Inject(h.LocaleService)),Ne(3,$.IRenderManagerService)],O.UniverSheetsDrawingUIPlugin),O.ClearSheetDrawingTransformerOperation=V,O.DeleteDrawingsCommand=Ae,O.EditSheetDrawingOperation=Oe,O.GroupSheetDrawingCommand=be,O.InsertCellImageOperation=se,O.InsertFloatImageOperation=ae,O.InsertSheetDrawingCommand=we,O.MoveDrawingsCommand=oe,O.RemoveSheetDrawingCommand=he,O.SetDrawingArrangeCommand=Ee,O.SetSheetDrawingCommand=ce,O.SidebarSheetDrawingOperation=Te,O.UngroupSheetDrawingCommand=Pe,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.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -48,42 +48,42 @@
|
|
|
48
48
|
"lib"
|
|
49
49
|
],
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@wendellhu/redi": "0.15.
|
|
51
|
+
"@wendellhu/redi": "0.15.5",
|
|
52
52
|
"clsx": ">=2.0.0",
|
|
53
53
|
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
|
54
54
|
"rxjs": ">=7.0.0",
|
|
55
|
-
"@univerjs/core": "0.
|
|
56
|
-
"@univerjs/design": "0.
|
|
57
|
-
"@univerjs/drawing": "0.
|
|
58
|
-
"@univerjs/drawing-ui": "0.
|
|
59
|
-
"@univerjs/engine-render": "0.
|
|
60
|
-
"@univerjs/sheets": "0.
|
|
61
|
-
"@univerjs/sheets-
|
|
62
|
-
"@univerjs/ui": "0.
|
|
63
|
-
"@univerjs/
|
|
55
|
+
"@univerjs/core": "0.2.0",
|
|
56
|
+
"@univerjs/design": "0.2.0",
|
|
57
|
+
"@univerjs/drawing": "0.2.0",
|
|
58
|
+
"@univerjs/drawing-ui": "0.2.0",
|
|
59
|
+
"@univerjs/engine-render": "0.2.0",
|
|
60
|
+
"@univerjs/sheets": "0.2.0",
|
|
61
|
+
"@univerjs/sheets-drawing": "0.2.0",
|
|
62
|
+
"@univerjs/sheets-ui": "0.2.0",
|
|
63
|
+
"@univerjs/ui": "0.2.0"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@univerjs/icons": "^0.1.
|
|
66
|
+
"@univerjs/icons": "^0.1.58"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@wendellhu/redi": "0.15.
|
|
69
|
+
"@wendellhu/redi": "0.15.5",
|
|
70
70
|
"clsx": "^2.1.1",
|
|
71
71
|
"less": "^4.2.0",
|
|
72
72
|
"react": "18.3.1",
|
|
73
73
|
"rxjs": "^7.8.1",
|
|
74
|
-
"typescript": "^5.
|
|
75
|
-
"vite": "^5.3.
|
|
74
|
+
"typescript": "^5.5.3",
|
|
75
|
+
"vite": "^5.3.3",
|
|
76
76
|
"vitest": "^1.6.0",
|
|
77
|
-
"@univerjs/core": "0.
|
|
78
|
-
"@univerjs/
|
|
79
|
-
"@univerjs/drawing": "0.
|
|
80
|
-
"@univerjs/
|
|
81
|
-
"@univerjs/
|
|
82
|
-
"@univerjs/
|
|
83
|
-
"@univerjs/
|
|
84
|
-
"@univerjs/sheets-drawing": "0.
|
|
85
|
-
"@univerjs/sheets-ui": "0.
|
|
86
|
-
"@univerjs/ui": "0.
|
|
77
|
+
"@univerjs/core": "0.2.0",
|
|
78
|
+
"@univerjs/drawing": "0.2.0",
|
|
79
|
+
"@univerjs/drawing-ui": "0.2.0",
|
|
80
|
+
"@univerjs/design": "0.2.0",
|
|
81
|
+
"@univerjs/engine-render": "0.2.0",
|
|
82
|
+
"@univerjs/shared": "0.2.0",
|
|
83
|
+
"@univerjs/sheets": "0.2.0",
|
|
84
|
+
"@univerjs/sheets-drawing": "0.2.0",
|
|
85
|
+
"@univerjs/sheets-ui": "0.2.0",
|
|
86
|
+
"@univerjs/ui": "0.2.0"
|
|
87
87
|
},
|
|
88
88
|
"univerSpace": {
|
|
89
89
|
".": {
|