@univerjs/sheets-drawing-ui 0.2.4 → 0.2.6
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 +1732 -1756
- package/lib/types/controllers/drawing-popup-menu.controller.d.ts +1 -2
- package/lib/types/controllers/sheet-drawing-transform-affected.controller.d.ts +8 -8
- package/lib/types/controllers/sheet-drawing-update.controller.d.ts +8 -9
- package/lib/types/controllers/sheet-drawing.controller.d.ts +1 -2
- package/lib/types/plugin.d.ts +2 -3
- package/lib/types/services/canvas-float-dom-manager.service.d.ts +8 -2
- package/lib/types/views/menu/image.menu.d.ts +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +24 -26
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { IContextService, IUniverInstanceService, RxDisposable } from '@univerjs/core';
|
|
2
|
-
import { Injector } from '@wendellhu/redi';
|
|
1
|
+
import { IContextService, Injector, IUniverInstanceService, RxDisposable } from '@univerjs/core';
|
|
3
2
|
import { IRenderManagerService } from '@univerjs/engine-render';
|
|
4
3
|
import { SheetCanvasPopManagerService } from '@univerjs/sheets-ui';
|
|
5
4
|
import { IDrawingManagerService } from '@univerjs/drawing';
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
1
|
+
import { Workbook, Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
2
|
+
import { ISheetSelectionRenderService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
|
|
2
3
|
import { IDrawingManagerService } from '@univerjs/drawing';
|
|
3
4
|
import { SheetInterceptorService } from '@univerjs/sheets';
|
|
4
5
|
import { ISheetDrawingService } from '@univerjs/sheets-drawing';
|
|
5
|
-
import {
|
|
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;
|
|
11
|
+
private readonly _selectionRenderService;
|
|
12
|
+
private readonly _skeletonManagerService;
|
|
9
13
|
private readonly _sheetInterceptorService;
|
|
10
|
-
private readonly _renderManagerService;
|
|
11
14
|
private readonly _sheetDrawingService;
|
|
12
15
|
private readonly _drawingManagerService;
|
|
13
16
|
private readonly _univerInstanceService;
|
|
14
|
-
|
|
15
|
-
private get _skeletonManagerService();
|
|
16
|
-
constructor(_commandService: ICommandService, _sheetInterceptorService: SheetInterceptorService, _renderManagerService: IRenderManagerService, _sheetDrawingService: ISheetDrawingService, _drawingManagerService: IDrawingManagerService, _univerInstanceService: IUniverInstanceService);
|
|
17
|
-
private _init;
|
|
17
|
+
constructor(_context: IRenderContext<Workbook>, _commandService: ICommandService, _selectionRenderService: ISheetSelectionRenderService, _skeletonManagerService: SheetSkeletonManagerService, _sheetInterceptorService: SheetInterceptorService, _sheetDrawingService: ISheetDrawingService, _drawingManagerService: IDrawingManagerService, _univerInstanceService: IUniverInstanceService);
|
|
18
18
|
private _sheetInterceptorListener;
|
|
19
19
|
private _getRangeMoveUndo;
|
|
20
20
|
private _getUpdateOrDeleteDrawings;
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
import { Disposable, ICommandService, IContextService,
|
|
1
|
+
import { Workbook, Disposable, ICommandService, IContextService, LocaleService } from '@univerjs/core';
|
|
2
2
|
import { IDrawingManagerService, IImageIoService } from '@univerjs/drawing';
|
|
3
3
|
import { ISheetDrawingService } from '@univerjs/sheets-drawing';
|
|
4
4
|
import { SheetsSelectionsService } from '@univerjs/sheets';
|
|
5
|
+
import { ISheetSelectionRenderService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
|
|
5
6
|
import { IMessageService } from '@univerjs/ui';
|
|
6
|
-
import {
|
|
7
|
+
import { IRenderContext } from '@univerjs/engine-render';
|
|
7
8
|
|
|
8
9
|
export declare class SheetDrawingUpdateController extends Disposable {
|
|
10
|
+
private readonly _context;
|
|
11
|
+
private readonly _skeletonManagerService;
|
|
9
12
|
private readonly _commandService;
|
|
10
|
-
private readonly
|
|
11
|
-
private readonly _selectionManagerService;
|
|
13
|
+
private readonly _selectionRenderService;
|
|
12
14
|
private readonly _imageIoService;
|
|
13
15
|
private readonly _sheetDrawingService;
|
|
14
16
|
private readonly _drawingManagerService;
|
|
15
17
|
private readonly _contextService;
|
|
16
18
|
private readonly _messageService;
|
|
17
19
|
private readonly _localeService;
|
|
18
|
-
private readonly
|
|
19
|
-
|
|
20
|
-
private get _skeletonManagerService();
|
|
21
|
-
constructor(_commandService: ICommandService, _univerInstanceService: IUniverInstanceService, _selectionManagerService: SheetsSelectionsService, _imageIoService: IImageIoService, _sheetDrawingService: ISheetDrawingService, _drawingManagerService: IDrawingManagerService, _contextService: IContextService, _messageService: IMessageService, _localeService: LocaleService, _renderManagerService: IRenderManagerService);
|
|
22
|
-
private _init;
|
|
20
|
+
private readonly _workbookSelections;
|
|
21
|
+
constructor(_context: IRenderContext<Workbook>, _skeletonManagerService: SheetSkeletonManagerService, _commandService: ICommandService, _selectionRenderService: ISheetSelectionRenderService, _imageIoService: IImageIoService, _sheetDrawingService: ISheetDrawingService, _drawingManagerService: IDrawingManagerService, _contextService: IContextService, _messageService: IMessageService, _localeService: LocaleService, selectionManagerService: SheetsSelectionsService);
|
|
23
22
|
/**
|
|
24
23
|
* Upload image to cell or float image
|
|
25
24
|
*/
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { DependencyOverride, Disposable, ICommandService } from '@univerjs/core';
|
|
1
|
+
import { DependencyOverride, Disposable, ICommandService, Injector } from '@univerjs/core';
|
|
2
2
|
import { MenuConfig, ComponentManager, IMenuService, IShortcutService } from '@univerjs/ui';
|
|
3
|
-
import { Injector } from '@wendellhu/redi';
|
|
4
3
|
|
|
5
4
|
export interface IUniverSheetsDrawingConfig {
|
|
6
5
|
menu?: MenuConfig;
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { LocaleService, Plugin, UniverInstanceType } from '@univerjs/core';
|
|
2
|
-
import { Injector } from '@wendellhu/redi';
|
|
1
|
+
import { Injector, LocaleService, Plugin, UniverInstanceType } from '@univerjs/core';
|
|
3
2
|
import { IRenderManagerService } from '@univerjs/engine-render';
|
|
4
3
|
import { IUniverSheetsDrawingConfig } from './controllers/sheet-drawing.controller';
|
|
5
4
|
|
|
@@ -11,7 +10,7 @@ export declare class UniverSheetsDrawingUIPlugin extends Plugin {
|
|
|
11
10
|
static pluginName: string;
|
|
12
11
|
private _pluginConfig;
|
|
13
12
|
constructor(config: Partial<IUniverSheetsDrawingConfig> | undefined, _injector: Injector, _localeService: LocaleService, _renderManagerService: IRenderManagerService);
|
|
14
|
-
onStarting(
|
|
13
|
+
onStarting(): void;
|
|
15
14
|
onRendered(): void;
|
|
16
15
|
private _initDependencies;
|
|
17
16
|
private _registerRenderModules;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { IPosition, ITransformState, Worksheet, Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
1
|
+
import { IDisposable, IPosition, ITransformState, Serializable, Worksheet, Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
2
2
|
import { IDrawingManagerService } from '@univerjs/drawing';
|
|
3
3
|
import { IBoundRectNoAngle, Scene, SpreadsheetSkeleton, IRenderManagerService } from '@univerjs/engine-render';
|
|
4
4
|
import { ISheetDrawingService } from '@univerjs/sheets-drawing';
|
|
5
5
|
import { CanvasFloatDomService } from '@univerjs/ui';
|
|
6
|
-
import { IDisposable } from '@wendellhu/redi';
|
|
7
6
|
|
|
8
7
|
export interface ICanvasFloatDom {
|
|
9
8
|
allowTransform: boolean;
|
|
@@ -11,7 +10,14 @@ export interface ICanvasFloatDom {
|
|
|
11
10
|
componentKey: string;
|
|
12
11
|
unitId?: string;
|
|
13
12
|
subUnitId?: string;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Please use `data`. for saving to disk, everything add to float-dom must be serializable.
|
|
15
|
+
*/
|
|
14
16
|
props?: Record<string, any>;
|
|
17
|
+
/**
|
|
18
|
+
* data of component, will save to snapshot, json-like data
|
|
19
|
+
*/
|
|
20
|
+
data?: Serializable;
|
|
15
21
|
}
|
|
16
22
|
export declare function transformBound2DOMBound(originBound: IBoundRectNoAngle, scene: Scene, skeleton: SpreadsheetSkeleton, worksheet: Worksheet): {
|
|
17
23
|
absolute: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IMenuItem } from '@univerjs/ui';
|
|
2
|
-
import { IAccessor } from '@
|
|
2
|
+
import { IAccessor } from '@univerjs/core';
|
|
3
3
|
|
|
4
4
|
export declare const IMAGE_UPLOAD_ICON = "addition-and-subtraction-single";
|
|
5
5
|
export declare function ImageMenuFactory(accessor: IAccessor): IMenuItem;
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(T,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/drawing-ui"),require("@univerjs/sheets-drawing"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("rxjs"),require("@univerjs/ui"),require("@wendellhu/redi/react-bindings"),require("@univerjs/sheets"),require("react"),require("@univerjs/design"),require("clsx")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/drawing-ui","@univerjs/sheets-drawing","@univerjs/drawing","@univerjs/engine-render","@univerjs/sheets-ui","rxjs","@univerjs/ui","@wendellhu/redi/react-bindings","@univerjs/sheets","react","@univerjs/design","clsx"],p):(T=typeof globalThis<"u"?globalThis:T||self,p(T.UniverSheetsDrawingUi={},T.UniverCore,T["@wendellhu/redi"],T.UniverDrawingUi,T.UniverSheetsDrawing,T.UniverDrawing,T.UniverEngineRender,T.UniverSheetsUi,T.rxjs,T.UniverUi,T["@wendellhu/redi/react-bindings"],T.UniverSheets,T.React,T.UniverDesign,T.clsx))})(this,function(T,p,$,Q,h,A,L,B,k,F,q,_,N,J,me){"use strict";var kt=Object.defineProperty;var Ht=(T,p,$)=>p in T?kt(T,p,{enumerable:!0,configurable:!0,writable:!0,value:$}):T[p]=$;var K=(T,p,$)=>Ht(T,typeof p!="symbol"?p+"":p,$);const G={id:"sheet.operation.clear-drawing-transformer",type:p.CommandType.MUTATION,handler:(i,r)=>{const t=i.get(L.IRenderManagerService);return r.forEach(e=>{var n,o;(o=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},ge={id:"sheet.command.remove-sheet-image",type:p.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),n=i.get(h.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=[];o.forEach(S=>{const{unitId:f}=S;a.push(f)});const s=n.getBatchRemoveOp(o),{unitId:l,subUnitId:u,undo:d,redo:c,objects:m}=s;return t.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:l,subUnitId:u,op:c,objects:m,type:h.DrawingApplyType.REMOVE})?(e.pushUndoRedo({unitID:l,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:l,subUnitId:u,op:d,objects:m,type:h.DrawingApplyType.INSERT}},{id:G.id,params:a}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:l,subUnitId:u,op:c,objects:m,type:h.DrawingApplyType.REMOVE}},{id:G.id,params:a}]}),!0):!1}},Ue="COMPONENT_SHEET_DRAWING_PANEL",Me={id:"sidebar.operation.sheet-image",type:p.CommandType.COMMAND,handler:async(i,r)=>{const t=i.get(F.ISidebarService),e=i.get(p.LocaleService),n=i.get(p.IUniverInstanceService),o=i.get(A.IDrawingManagerService);if(!_.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Ue},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:t.close();break}return!0}},De={id:"sheet.operation.edit-sheet-image",type:p.CommandType.OPERATION,handler:(i,r)=>{const t=i.get(A.IDrawingManagerService),e=i.get(p.ICommandService);return r==null?!1:(t.focusDrawing([r]),e.executeCommand(Me.id,{value:"open"}),!0)}},pe={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},xe=()=>{const i=q.useDependency(A.IImageIoService),r=q.useDependency(p.LocaleService),[t,e]=N.useState(0);return N.useEffect(()=>{const n=i.change$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[i]),N.createElement("div",{style:{display:t>0?"block":"none"},className:pe.uploadLoading},N.createElement("div",{className:pe.uploadLoadingBody},N.createElement("div",{className:pe.uploadLoadingBodyAnimation}),N.createElement("div",{className:pe.uploadLoadingBodyText},`${r.t("uploadLoading.loading")}: ${t}`)))};var Ke=Object.defineProperty,ze=Object.getOwnPropertyDescriptor,qe=(i,r,t,e)=>{for(var n=e>1?void 0:e?ze(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(e?a(r,t,n):a(n))||n);return e&&n&&Ke(r,t,n),n},ee=(i,r)=>(t,e)=>r(t,e,i);let he=class extends p.RxDisposable{constructor(r,t,e,n,o,a,s){super();K(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=t,this._canvasPopManagerService=e,this._renderManagerService=n,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET).pipe(k.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(p.UniverInstanceType.UNIVER_SHEET).pipe(k.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(p.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(F.BuiltInUIPart.CONTENT,()=>q.connectInjector(xe,this._injector))}_dispose(r){const t=r.getUnitId();this._renderManagerService.removeRender(t)}_create(r){if(!r)return;const t=r.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(r){const t=r.getAllObjects();for(const e of t)if(e instanceof Q.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const t=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(p.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const a=e.getSelectedObjectMap();if(a.size>1){n==null||n.dispose();return}const s=a.values().next().value;if(!s)return;const l=s.oKey,u=this._drawingManagerService.getDrawingOKey(l);if(!u)return;const{unitId:d,subUnitId:c,drawingId:m}=u;n==null||n.dispose(),n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:Q.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(d,c,m)}})),this._drawingManagerService.focusDrawing([{unitId:d,subUnitId:c,drawingId:m}])}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e){return[{label:"image-popup.edit",index:0,commandId:De.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:!1},{label:"image-popup.delete",index:1,commandId:ge.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:Q.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:!1},{label:"image-popup.reset",index:3,commandId:Q.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:!1}]}};he=qe([p.OnLifecycle(p.LifecycleStages.Steady,he),ee(0,$.Inject($.Injector)),ee(1,A.IDrawingManagerService),ee(2,$.Inject(B.SheetCanvasPopManagerService)),ee(3,L.IRenderManagerService),ee(4,p.IUniverInstanceService),ee(5,p.IContextService),ee(6,$.Inject(F.IUIPartsService))],he);const oe={id:"sheet.operation.insert-float-image",type:p.CommandType.OPERATION,handler:(i,r)=>!0},ae={id:"sheet.operation.insert-cell-image",type:p.CommandType.OPERATION,handler:(i,r)=>!0},fe={id:"sheet.command.insert-sheet-image",type:p.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),n=i.get(h.ISheetDrawingService);if(!r)return!1;const o=r.drawings,a=o.map(S=>S.unitId),s=n.getBatchAddOp(o),{unitId:l,subUnitId:u,undo:d,redo:c,objects:m}=s;return t.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:c,unitId:l,subUnitId:u,objects:m,type:h.DrawingApplyType.INSERT})?(e.pushUndoRedo({unitID:l,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:d,unitId:l,subUnitId:u,objects:m,type:h.DrawingApplyType.REMOVE}},{id:G.id,params:a}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:c,unitId:l,subUnitId:u,objects:m,type:h.DrawingApplyType.INSERT}},{id:G.id,params:a}]}),!0):!1}},se={id:"sheet.command.set-sheet-image",type:p.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),n=i.get(h.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=n.getBatchUpdateOp(o),{unitId:s,subUnitId:l,undo:u,redo:d,objects:c}=a;return t.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:s,subUnitId:l,op:d,objects:c,type:h.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:u,objects:c,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:d,objects:c,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}]}),!0):!1}},Te={id:"sheet.command.set-drawing-arrange",type:p.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(p.ICommandService),e=i.get(p.IUndoRedoService);if(!r)return!1;const n=i.get(h.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:l}=r,u={unitId:o,subUnitId:a,drawingIds:s};let d;if(l===A.ArrangeTypeEnum.forward?d=n.getForwardDrawingsOp(u):l===A.ArrangeTypeEnum.backward?d=n.getBackwardDrawingOp(u):l===A.ArrangeTypeEnum.front?d=n.getFrontDrawingsOp(u):l===A.ArrangeTypeEnum.back&&(d=n.getBackDrawingsOp(u)),d==null)return!1;const{objects:c,redo:m,undo:g}=d;return t.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:m,unitId:o,subUnitId:a,objects:c,type:h.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:c,type:h.DrawingApplyType.ARRANGE}}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:a,objects:c,type:h.DrawingApplyType.ARRANGE}}]}),!0):!1}};function Je(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:a,drawingId:s}=e,l=L.getGroupState(0,0,n.map(c=>c.transform||{})),u=n.map(c=>{const m=c.transform||{left:0,top:0},{unitId:g,subUnitId:S,drawingId:f}=c;return{unitId:g,subUnitId:S,drawingId:f,transform:{...m,left:m.left-l.left,top:m.top-l.top},groupId:s}}),d={unitId:o,subUnitId:a,drawingId:s,drawingType:A.DrawingTypeEnum.DRAWING_GROUP,transform:l};r.push({parent:d,children:u})}),r}function Ze(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:a,drawingId:s,transform:l={width:0,height:0}}=e;if(l==null)return;const u=n.map(c=>{const{transform:m}=c,{unitId:g,subUnitId:S,drawingId:f}=c,v=L.transformObjectOutOfGroup(m||{},l,l.width||0,l.height||0);return{unitId:g,subUnitId:S,drawingId:f,transform:v,groupId:void 0}}),d={unitId:o,subUnitId:a,drawingId:s,drawingType:A.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:d,children:u})}),r}const Re={id:"sheet.command.group-sheet-image",type:p.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),n=i.get(h.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:g,children:S})=>{o.push(g.unitId),S.forEach(f=>{o.push(f.unitId)})});const a=n.getGroupDrawingOp(r),{unitId:s,subUnitId:l,undo:u,redo:d,objects:c}=a;return t.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:d,unitId:s,subUnitId:l,objects:c,type:h.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:Ze(c),type:h.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:d,unitId:s,subUnitId:l,objects:c,type:h.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!0):!1}},Ee={id:"sheet.command.ungroup-sheet-image",type:p.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),n=i.get(h.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:g,children:S})=>{o.push(g.unitId),S.forEach(f=>{o.push(f.unitId)})});const a=n.getUngroupDrawingOp(r),{unitId:s,subUnitId:l,undo:u,redo:d,objects:c}=a;return t.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:d,unitId:s,subUnitId:l,objects:c,type:h.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:Je(c),type:h.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:d,unitId:s,subUnitId:l,objects:c,type:h.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};function H(i,r,t){const{from:e,to:n,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:l=0,skewY:u=0}=i,{column:d,columnOffset:c,row:m,rowOffset:g}=e,{column:S,columnOffset:f,row:v,rowOffset:y}=n,M=t.attachRangeWithCoord({startColumn:d,endColumn:d,startRow:m,endRow:m});if(M==null)return;const C=t.attachRangeWithCoord({startColumn:S,endColumn:S,startRow:v,endRow:v});if(C==null)return;const{startX:R,startY:I}=M,{startX:P,startY:w}=C;let U=L.precisionTo(R+c,1),E=L.precisionTo(I+g,1),j=L.precisionTo(P+f-U,1),O=L.precisionTo(w+y-E,1);M.startX===C.endX&&(j=0),M.startY===C.endY&&(O=0);const b=t.getCurrentSkeleton(),D=b.rowHeaderWidth+b.columnTotalWidth,W=b.columnHeaderHeight+b.rowTotalHeight;return U+j>D&&(U=D-j),E+O>W&&(E=W-O),{flipY:o,flipX:a,angle:s,skewX:l,skewY:u,left:U,top:E,width:j,height:O}}function V(i,r){const{left:t=0,top:e=0,width:n=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:l=0,skewX:u=0,skewY:d=0}=i,c=r.getSelectionCellByPosition(t,e);if(c==null)return;const m={column:c.actualColumn,columnOffset:L.precisionTo(t-c.startX,1),row:c.actualRow,rowOffset:L.precisionTo(e-c.startY,1)},g=r.getSelectionCellByPosition(t+n,e+o);if(g==null)return;const S={column:g.actualColumn,columnOffset:L.precisionTo(t+n-g.startX,1),row:g.actualRow,rowOffset:L.precisionTo(e+o-g.startY,1)};return{flipY:a,flipX:s,angle:l,skewX:u,skewY:d,from:m,to:S}}var Qe=Object.defineProperty,et=Object.getOwnPropertyDescriptor,tt=(i,r,t,e)=>{for(var n=e>1?void 0:e?et(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(e?a(r,t,n):a(n))||n);return e&&n&&Qe(r,t,n),n},z=(i,r)=>(t,e)=>r(t,e,i);let Se=class extends p.Disposable{constructor(i,r,t,e,n,o,a,s,l,u){super(),this._commandService=i,this._univerInstanceService=r,this._selectionManagerService=t,this._imageIoService=e,this._sheetDrawingService=n,this._drawingManagerService=o,this._contextService=a,this._messageService=s,this._localeService=l,this._renderManagerService=u,this._init()}get _selectionRenderService(){return this._renderManagerService.getRenderById(this._univerInstanceService.getCurrentUnitForType(p.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(B.ISheetSelectionRenderService)}get _skeletonManagerService(){return this._renderManagerService.getRenderById(this._univerInstanceService.getCurrentUnitForType(p.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(B.SheetSkeletonManagerService)}_init(){this._initCommandListeners(),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener(),this._drawingAddListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async i=>{if(i.id===ae.id||i.id===oe.id){const r=i.params;if(r.files==null)return;const t=r.files.length;if(t>A.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(A.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(t),i.id===ae.id?r.files.forEach(async e=>{await this._insertCellImage(e)}):r.files.forEach(async e=>{await this._insertFloatImage(e)})}}))}async _insertCellImage(i){}async _insertFloatImage(i){let r;try{r=await this._imageIoService.saveImage(i)}catch(M){const C=M.message;C===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(A.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===A.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===A.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(r==null)return;const t=this._getUnitInfo();if(t==null)return;const{unitId:e,subUnitId:n}=t,{imageId:o,imageSourceType:a,source:s,base64Cache:l}=r,{width:u,height:d,image:c}=await A.getImageSize(l||""),m=this._renderManagerService.getRenderById(e);if(m==null)return;const{width:g,height:S}=m.scene;this._imageIoService.addImageSourceCache(s,a,c);let f=1;if(u>A.DRAWING_IMAGE_WIDTH_LIMIT||d>A.DRAWING_IMAGE_HEIGHT_LIMIT){const M=A.DRAWING_IMAGE_WIDTH_LIMIT/u,C=A.DRAWING_IMAGE_HEIGHT_LIMIT/d;f=Math.max(M,C)}const v=this._getImagePosition(u*f,d*f,g,S);if(v==null)return;const y={unitId:e,subUnitId:n,drawingId:o,drawingType:A.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:s,transform:H(v,this._selectionRenderService,this._skeletonManagerService),sheetTransform:v};this._commandService.executeCommand(fe.id,{unitId:e,drawings:[y]})}_getUnitInfo(){const i=this._univerInstanceService.getCurrentUnitForType(p.UniverInstanceType.UNIVER_SHEET);if(i==null)return;const r=i.getActiveSheet();if(r==null)return;const t=i.getUnitId(),e=r.getSheetId();return{unitId:t,subUnitId:e}}_getImagePosition(i,r,t,e){const n=this._selectionManagerService.getCurrentSelections();let o={startRow:0,endRow:0,startColumn:0,endColumn:0};n&&n.length>0&&(o=n[n.length-1].range);const a=B.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,o);if(a==null)return;let{startColumn:s,startRow:l,startX:u,startY:d}=a,c=!1;if(u+i>t&&(u=t-i,u<0&&(u=0,i=t),c=!0),d+r>e&&(d=e-r,d<0&&(d=0,r=e),c=!0),c){const f=this._selectionRenderService.getSelectionCellByPosition(u,d);if(f==null)return;u=f.startX,d=f.startY,s=f.actualColumn,l=f.actualRow}const m={column:s,columnOffset:0,row:l,rowOffset:0},g=this._selectionRenderService.getSelectionCellByPosition(u+i,d+r);if(g==null)return;const S={column:g.actualColumn,columnOffset:u+i-g.startX,row:g.actualRow,rowOffset:d+r-g.startY};return{from:m,to:S}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(i=>{const{unitId:r,subUnitId:t,drawingIds:e,arrangeType:n}=i;this._commandService.executeCommand(Te.id,{unitId:r,subUnitId:t,drawingIds:e,arrangeType:n})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(i=>{const r=[];i.length!==0&&(i.forEach(t=>{const{unitId:e,subUnitId:n,drawingId:o,drawingType:a,transform:s}=t;if(s==null)return;const l=this._sheetDrawingService.getDrawingByParam({unitId:e,subUnitId:n,drawingId:o});if(l==null)return;const u=V({...l.transform,...s},this._selectionRenderService);if(u==null)return;const d={...t,transform:{...l.transform,...s,...H(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};r.push(d)}),r.length>0&&this._commandService.executeCommand(se.id,{unitId:i[0].unitId,drawings:r}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(i=>{this._commandService.executeCommand(Re.id,i);const{unitId:r,subUnitId:t,drawingId:e}=i[0].parent;this._drawingManagerService.focusDrawing([{unitId:r,subUnitId:t,drawingId:e}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(i=>{this._commandService.executeCommand(Ee.id,i)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(i=>{i==null||i.length===0?(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(i))}))}_drawingAddListener(){this.disposeWithMe(this._sheetDrawingService.add$.subscribe(i=>{this._registerDrawing(i)}))}_registerDrawing(i){i.forEach(t=>{const e=this._sheetDrawingService.getDrawingByParam(t);if(e==null)return;const{sheetTransform:n}=e;e.transform=H(n,this._selectionRenderService,this._skeletonManagerService)});const r=i[0].unitId;this._drawingManagerService.registerDrawingData(r,this._sheetDrawingService.getDrawingDataForUnit(r)),this._drawingManagerService.initializeNotification(r)}};Se=tt([p.OnLifecycle(p.LifecycleStages.Rendered,Se),z(0,p.ICommandService),z(1,p.IUniverInstanceService),z(2,$.Inject(_.SheetsSelectionsService)),z(3,A.IImageIoService),z(4,h.ISheetDrawingService),z(5,A.IDrawingManagerService),z(6,p.IContextService),z(7,F.IMessageService),z(8,$.Inject(p.LocaleService)),z(9,L.IRenderManagerService)],Se);var x=function(){return x=Object.assign||function(i){for(var r,t=1,e=arguments.length;t<e;t++){r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(i[n]=r[n])}return i},x.apply(this,arguments)},nt=function(i,r){var t={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(t[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,e=Object.getOwnPropertySymbols(i);n<e.length;n++)r.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(i,e[n])&&(t[e[n]]=i[e[n]]);return t},Ne=N.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,o=i.extend,a=nt(i,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),l=N.useRef("_".concat(ot()));return Le(t,"".concat(e),{defIds:t.defIds,idSuffix:l.current},x({ref:r,className:s},a),o)});function Le(i,r,t,e,n){return N.createElement(i.tag,x(x({key:r},rt(i,t,n)),e),(it(i,t).children||[]).map(function(o,a){return Le(o,"".concat(r,"-").concat(i.tag,"-").concat(a),t,void 0,n)}))}function rt(i,r,t){var e=x({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1);var n=r.defIds;return!n||n.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function it(i,r){var t,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((t=i.children)===null||t===void 0)&&t.length)?x(x({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?x(x({},n),{attrs:x(x({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function ot(){return Math.random().toString(36).substring(2,8)}Ne.displayName="UniverIcon";var at={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"}}]},je=N.forwardRef(function(i,r){return N.createElement(Ne,Object.assign({},i,{id:"add-image-single",ref:r,icon:at}))});je.displayName="AddImageSingle";const We={uploadFileMenu:"univer-upload-file-menu",uploadFileMenuInput:"univer-upload-file-menu-input"},Be="COMPONENT_UPLOAD_FILE_MENU";var ve=(i=>(i[i.cellImage=0]="cellImage",i[i.floatImage=1]="floatImage",i))(ve||{});const st=i=>{const{type:r}=i,t=q.useDependency(p.ICommandService),e=N.useRef(null),n=()=>{var s;(s=e.current)==null||s.click()},o=A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(s=>`.${s.replace("image/","")}`).join(","),a=s=>{const l=s.target.files;if(l==null)return;const u=Array.from(l);r===ve.floatImage?t.executeCommand(oe.id,{files:u}):r===ve.cellImage&&t.executeCommand(ae.id,{files:u}),e.current&&(e.current.value="")};return N.createElement("div",{onClick:n,className:We.uploadFileMenu},N.createElement("input",{type:"file",className:We.uploadFileMenuInput,ref:e,onChange:a,accept:o,multiple:!0}))},$e="addition-and-subtraction-single",Ge="sheet.menu.image";function ct(i){return{id:Ge,type:F.MenuItemType.SUBITEMS,positions:[F.MenuPosition.TOOLBAR_START],group:F.MenuGroup.TOOLBAR_FORMULAS_INSERT,icon:$e,tooltip:"sheetImage.title",hidden$:F.getMenuHiddenObservable(i,p.UniverInstanceType.UNIVER_SHEET),disabled$:B.getCurrentRangeDisable$(i,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function lt(i){return{id:oe.id,title:"sheetImage.upload.float",type:F.MenuItemType.SELECTOR,label:{name:Be,props:{type:ve.floatImage}},positions:[Ge],hidden$:F.getMenuHiddenObservable(i,p.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",imageCommonPanelSubtitle:"univer-image-common-panel-subtitle",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"},dt=i=>{var C;const r=q.useDependency(p.ICommandService),t=q.useDependency(p.LocaleService),e=q.useDependency(A.IDrawingManagerService),n=q.useDependency(L.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:s}=a,l=n.getRenderById(s),u=l==null?void 0:l.scene;if(u==null)return;const d=u.getTransformerByCreate(),[c,m]=N.useState(!0),g=(C=a.anchorType)!=null?C:h.SheetDrawingAnchorType.Position,[S,f]=N.useState(g);function v(R,I){const P=[];return R.forEach(w=>{const{oKey:U}=w,E=I.getDrawingOKey(U);if(E==null)return P.push(null),!0;const{unitId:j,subUnitId:O,drawingId:b,drawingType:D,anchorType:W,sheetTransform:Y}=E;P.push({unitId:j,subUnitId:O,drawingId:b,anchorType:W,sheetTransform:Y,drawingType:D})}),P}N.useEffect(()=>{const R=d.clearControl$.subscribe(P=>{P===!0&&m(!1)}),I=d.changeStart$.subscribe(P=>{var E;const{objects:w}=P,U=v(w,e);if(U.length===0)m(!1);else if(U.length>=1){m(!0);const j=((E=U[0])==null?void 0:E.anchorType)||h.SheetDrawingAnchorType.Position;f(j)}});return()=>{I.unsubscribe(),R.unsubscribe()}},[]);function y(R){f(R);const I=e.getFocusDrawings();if(I.length===0)return;const P=I.map(w=>({unitId:w.unitId,subUnitId:w.subUnitId,drawingId:w.drawingId,anchorType:R}));r.executeCommand(se.id,{unitId:I[0].unitId,drawings:P})}const M=R=>R?"block":"none";return N.createElement("div",{className:me(Z.imageCommonPanelGrid,Z.imageCommonPanelBorder),style:{display:M(c)}},N.createElement("div",{className:Z.imageCommonPanelRow},N.createElement("div",{className:me(Z.imageCommonPanelColumn,Z.imageCommonPanelTitle)},N.createElement("div",null,t.t("drawing-anchor.title")))),N.createElement("div",{className:me(Z.imageCommonPanelRow)},N.createElement("div",{className:me(Z.imageCommonPanelColumn)},N.createElement(J.RadioGroup,{value:S,onChange:y,direction:"vertical"},N.createElement(J.Radio,{value:h.SheetDrawingAnchorType.Both},t.t("drawing-anchor.both")),N.createElement(J.Radio,{value:h.SheetDrawingAnchorType.Position},t.t("drawing-anchor.position")),N.createElement(J.Radio,{value:h.SheetDrawingAnchorType.None},t.t("drawing-anchor.none"))))))},ut=()=>{const i=q.useDependency(A.IDrawingManagerService),r=i.getFocusDrawings(),[t,e]=N.useState(r);return N.useEffect(()=>{const n=i.focus$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&N.createElement("div",{className:Z.imageCommonPanel},N.createElement(Q.DrawingCommonPanel,{drawings:t}),N.createElement(dt,{drawings:t}))},ne={id:"sheet.command.move-drawing",type:p.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(p.ICommandService),e=i.get(h.ISheetDrawingService),n=i.get(B.ISheetSelectionRenderService),{direction:o}=r,a=e.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,l=a.map(d=>{const{transform:c}=d;if(c==null)return null;const m={...c},{left:g=0,top:S=0}=c;return o===p.Direction.UP?m.top=S-1:o===p.Direction.DOWN?m.top=S+1:o===p.Direction.LEFT?m.left=g-1:o===p.Direction.RIGHT&&(m.left=g+1),{...d,transform:m,sheetTransform:V(m,n)}}).filter(d=>d!=null);return t.syncExecuteCommand(se.id,{unitId:s,drawings:l})?(t.syncExecuteCommand(G.id,[s]),!0):!1}},be={id:"sheet.command.delete-drawing",type:p.CommandType.COMMAND,handler:i=>{const r=i.get(p.ICommandService),e=i.get(h.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,o=e.map(a=>{const{unitId:s,subUnitId:l,drawingId:u,drawingType:d}=a;return{unitId:s,subUnitId:l,drawingId:u,drawingType:d}});return r.executeCommand(ge.id,{unitId:n,drawings:o})}};function ce(i){return!i.getContextValue(p.FOCUSING_FORMULA_EDITOR)&&!i.getContextValue(p.EDITOR_ACTIVATED)&&i.getContextValue(p.FOCUSING_COMMON_DRAWINGS)}const mt={id:ne.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_DOWN,priority:100,preconditions:ce,staticParameters:{direction:p.Direction.DOWN}},gt={id:ne.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_UP,priority:100,preconditions:ce,staticParameters:{direction:p.Direction.UP}},pt={id:ne.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_LEFT,priority:100,preconditions:ce,staticParameters:{direction:p.Direction.LEFT}},ht={id:ne.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_RIGHT,priority:100,preconditions:ce,staticParameters:{direction:p.Direction.RIGHT}},ft={id:be.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:ce,binding:F.KeyCode.DELETE,mac:F.KeyCode.BACKSPACE};var St=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,wt=(i,r,t,e)=>{for(var n=e>1?void 0:e?vt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(e?a(r,t,n):a(n))||n);return e&&n&&St(r,t,n),n},le=(i,r)=>(t,e)=>r(t,e,i);const _t={};let de=class extends p.Disposable{constructor(i,r,t,e,n,o){super(),this._config=i,this._injector=r,this._componentManager=t,this._menuService=e,this._commandService=n,this._shortcutService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register($e,je)),this.disposeWithMe(i.register(Be,st)),this.disposeWithMe(i.register(Ue,ut))}_initMenus(){const{menu:i={}}=this._config;[ct,lt].forEach(r=>{this._menuService.addMenuItem(r(this._injector),i)})}_initCommands(){[oe,ae,fe,ge,se,Me,G,De,Re,Ee,ne,be,Te].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[mt,gt,pt,ht,ft].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};de=wt([p.OnLifecycle(p.LifecycleStages.Rendered,de),le(1,$.Inject($.Injector)),le(2,$.Inject(F.ComponentManager)),le(3,F.IMenuService),le(4,p.ICommandService),le(5,F.IShortcutService)],de);var It=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,yt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Ct(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(e?a(r,t,n):a(n))||n);return e&&n&&It(r,t,n),n},re=(i,r)=>(t,e)=>r(t,e,i);const Mt=[_.InsertRowCommand.id,_.InsertColCommand.id,_.RemoveRowCommand.id,_.RemoveColCommand.id,_.DeleteRangeMoveLeftCommand.id,_.DeleteRangeMoveUpCommand.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id,_.DeltaRowHeightCommand.id,_.SetRowHeightCommand.id,_.DeltaColumnWidthCommand.id,_.SetColWidthCommand.id,_.SetRowHiddenCommand.id,_.SetSpecificRowsVisibleCommand.id,_.SetSpecificColsVisibleCommand.id,_.SetColHiddenCommand.id],Dt=[_.SetRowVisibleMutation.id,_.SetRowHiddenMutation.id,_.SetColVisibleMutation.id,_.SetColHiddenMutation.id,_.SetWorksheetRowHeightMutation.id,_.SetWorksheetColWidthMutation.id];let we=class extends p.Disposable{constructor(i,r,t,e,n,o){super(),this._commandService=i,this._sheetInterceptorService=r,this._renderManagerService=t,this._sheetDrawingService=e,this._drawingManagerService=n,this._univerInstanceService=o,this._init()}get _selectionRenderService(){return this._renderManagerService.getRenderById(this._univerInstanceService.getCurrentUnitForType(p.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(B.ISheetSelectionRenderService)}get _skeletonManagerService(){return this._renderManagerService.getRenderById(this._univerInstanceService.getCurrentUnitForType(p.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(B.SheetSkeletonManagerService)}_init(){this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!Mt.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===_.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if(r===_.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===_.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===_.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===_.DeleteRangeMoveLeftCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,0)}else if(r===_.DeleteRangeMoveUpCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,1)}else if(r===_.InsertRangeMoveDownCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,2)}else if(r===_.InsertRangeMoveRightCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,3)}else if(r===_.SetRowHiddenCommand.id||r===_.SetSpecificRowsVisibleCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForRowVisible(e,n,o)}else if(r===_.SetSpecificColsVisibleCommand.id||r===_.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForColVisible(e,n,o)}else if(r===_.DeltaRowHeightCommand.id||r===_.SetRowHeightCommand.id||r===_.DeltaColumnWidthCommand.id||r===_.SetColWidthCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t,a=r===_.DeltaRowHeightCommand.id||r===_.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const t=_.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(e,n),l=[],u=[];if(Object.keys(s).forEach(d=>{const c=s[d],{updateDrawings:m,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(i,r,c);l.push(...m),u.push(...g)}),l.length===0&&u.length===0)return{redos:[],undos:[]};if(l.length>0){const d=this._sheetDrawingService.getBatchUpdateOp(l),{undo:c,redo:m,objects:g}=d;o.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:m,objects:g,type:h.DrawingApplyType.UPDATE}}),a.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:g,type:h.DrawingApplyType.UPDATE}})}if(u.length>0){const d=this._sheetDrawingService.getBatchRemoveOp(u),c=d.undo,m=d.redo,g=d.objects;o.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:m,objects:g,type:h.DrawingApplyType.REMOVE}}),a.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:g,type:h.DrawingApplyType.INSERT}})}return o.push({id:G.id,params:[e]}),a.push({id:G.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,r,t){const e=[],n=[],{sheetTransform:o,anchorType:a=h.SheetDrawingAnchorType.Position,transform:s,unitId:l,subUnitId:u,drawingId:d}=t,{from:c,to:m}=o,{row:g,column:S}=c,{row:f,column:v}=m;if(o==null||s==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:y,endRow:M,startColumn:C,endColumn:R}=i;let I=null,P=null;if(r===0&&g>=y&&f<=M)if(S>=C&&v<=R)n.push({unitId:l,subUnitId:u,drawingId:d});else{const w=this._shrinkCol(o,s,C,R,a);I=w==null?void 0:w.newSheetTransform,P=w==null?void 0:w.newTransform}else if(r===1&&S>=C&&v<=R)if(g>=y&&f<=M)n.push({unitId:l,subUnitId:u,drawingId:d});else{const w=this._shrinkRow(o,s,y,M,a);I=w==null?void 0:w.newSheetTransform,P=w==null?void 0:w.newTransform}else if(r===2){const w=this._expandRow(o,s,y,M,a);I=w==null?void 0:w.newSheetTransform,P=w==null?void 0:w.newTransform}else if(r===3){const w=this._expandCol(o,s,C,R,a);I=w==null?void 0:w.newSheetTransform,P=w==null?void 0:w.newTransform}if(I!=null&&P!=null){const w=H(I,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:I,transform:w})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(i,r,t){const e=V({...i},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(d=>{const c=e[d],{sheetTransform:m,transform:g,anchorType:S=h.SheetDrawingAnchorType.Position}=c;if(S===h.SheetDrawingAnchorType.None)this._remainDrawingSize(g,n,c);else{const{from:f,to:v}=m,{row:y,column:M}=f,{row:C,column:R}=v;for(let I=0;I<t.length;I++){const P=t[I],{startRow:w,endRow:U,startColumn:E,endColumn:j}=P;if(R<E)continue;if(S===h.SheetDrawingAnchorType.Position){let D=null,W=null;if(M>=E&&M<=j){const Y=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:j,startRow:f.row,endRow:v.row});if(Y==null)return;W={...g,left:Y.startX}}if(W!=null&&(D=V(W,this._selectionRenderService),D!=null&&W!=null)){n.push({...c,sheetTransform:D,transform:W});break}this._remainDrawingSize(g,n,c);continue}if(M>=E&&R<=j)continue;let O=null,b=null;if(M>=E&&M<=j){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:j,startRow:f.row,endRow:v.row});if(D==null)return;b={...g,left:(D==null?void 0:D.startX)||0,width:((g==null?void 0:g.width)||0)-D.endX+D.startX}}else if(R>=E&&R<=j){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:R,startRow:f.row,endRow:v.row});if(D==null)return;b={...g,left:D.startX-((g==null?void 0:g.width)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:j,startRow:f.row,endRow:v.row});if(D==null)return;if(b={...g,width:((g==null?void 0:g.width)||0)-D.endX+D.startX},O=V(b,this._selectionRenderService),O!=null&&b!=null){o.push({...c,sheetTransform:O,transform:b});break}}if(b!=null&&(O=V(b,this._selectionRenderService)),b!=null&&O!=null){n.push({...c,sheetTransform:O,transform:b});break}else this._remainDrawingSize(g,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),l=[],u=[];if(o.length>0){const{redos:d,undos:c}=this._createUndoAndRedoMutation(i,r,o);l.push(...d),u.push(...c)}return{redos:a,undos:s,preRedos:l,preUndos:u}}_createUndoAndRedoMutation(i,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:o,objects:a}=e,s=[{id:h.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],l=[{id:h.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:a,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:s,undos:l}}_getDrawingUndoForRowVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(d=>{const c=e[d],{sheetTransform:m,transform:g,anchorType:S=h.SheetDrawingAnchorType.Position}=c;if(S===h.SheetDrawingAnchorType.None)this._remainDrawingSize(g,n,c);else{const{from:f,to:v}=m,{row:y,column:M}=f,{row:C,column:R}=v;for(let I=0;I<t.length;I++){const P=t[I],{startRow:w,endRow:U,startColumn:E,endColumn:j}=P;if(C<w)continue;if(S===h.SheetDrawingAnchorType.Position){let D=null,W=null;if(y>=w&&y<=U){const Y=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:y,endRow:U});if(Y==null)return;W={...g,top:Y.startY}}if(W!=null&&(D=V(W,this._selectionRenderService),D!=null&&W!=null)){n.push({...c,sheetTransform:D,transform:W});break}this._remainDrawingSize(g,n,c);continue}if(y>=w&&C<=U)continue;let O=null,b=null;if(y>=w&&y<=U){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:y,endRow:U});if(D==null)return;b={...g,top:(D==null?void 0:D.startY)||0,height:((g==null?void 0:g.height)||0)-D.endY+D.startY}}else if(C>=w&&C<=U){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:w,endRow:C});if(D==null)return;b={...g,top:D.startY-((g==null?void 0:g.height)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:w,endRow:U});if(D==null)return;if(b={...g,height:((g==null?void 0:g.height)||0)-D.endY+D.startY},O=V(b,this._selectionRenderService),O!=null&&b!=null){o.push({...c,sheetTransform:O,transform:b});break}}if(b!=null&&(O=V(b,this._selectionRenderService)),b!=null&&O!=null){n.push({...c,sheetTransform:O,transform:b});break}else this._remainDrawingSize(g,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),l=[],u=[];if(o.length>0){const{redos:d,undos:c}=this._createUndoAndRedoMutation(i,r,o);l.push(...d),u.push(...c)}return{redos:a,undos:s,preRedos:l,preUndos:u}}_getDrawingUndoForRowAndColSize(i,r,t,e){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(a=>{const s=n[a],{sheetTransform:l,transform:u,anchorType:d=h.SheetDrawingAnchorType.Position}=s;if(d===h.SheetDrawingAnchorType.None)this._remainDrawingSize(u,o,s);else{const{from:c,to:m}=l,{row:g,column:S}=c,{row:f,column:v}=m;for(let y=0;y<t.length;y++){const M=t[y],{startRow:C,endRow:R,startColumn:I,endColumn:P}=M;if(f<C||v<I)continue;if(d===h.SheetDrawingAnchorType.Position&&(g<=C&&f>=R||S<=I&&v>=P)){this._remainDrawingSize(u,o,s);continue}const w=H({...l},this._selectionRenderService,this._skeletonManagerService);if(w!=null){o.push({...s,transform:w});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let t,e;if(r==="insert")t=i.unitId,e=i.subUnitId;else{const n=_.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRowInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,a=o.startRow,s=o.endRow,l=[],u=[],d=this._sheetDrawingService.getDrawingData(e,n),c=[],m=[];if(Object.keys(d).forEach(g=>{const S=d[g],{sheetTransform:f,transform:v,anchorType:y=h.SheetDrawingAnchorType.Position}=S;if(f==null||v==null)return;let M,C;if(r==="insert"){const I=this._expandRow(f,v,a,s,y);M=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:P}=f,{row:w}=I,{row:U}=P;if(w>=a&&U<=s)m.push({unitId:e,subUnitId:n,drawingId:g});else{const E=this._shrinkRow(f,v,a,s,y);M=E==null?void 0:E.newSheetTransform,C=E==null?void 0:E.newTransform}}if(!M||!C)return;const R={unitId:e,subUnitId:n,drawingId:g,transform:C,sheetTransform:M};c.push(R)}),c.length===0&&m.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:S,redo:f,objects:v}=g;l.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:v,type:h.DrawingApplyType.UPDATE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:v,type:h.DrawingApplyType.UPDATE}})}if(m.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(m),S=g.undo,f=g.redo,v=g.objects;l.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:v,type:h.DrawingApplyType.REMOVE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:v,type:h.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),u.push({id:G.id,params:[e]}),{redos:l,undos:u}}_moveColInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,a=o.startColumn,s=o.endColumn,l=[],u=[],d=this._sheetDrawingService.getDrawingData(e,n),c=[],m=[];if(Object.keys(d).forEach(g=>{const S=d[g],{sheetTransform:f,transform:v,anchorType:y=h.SheetDrawingAnchorType.Position}=S;if(f==null||v==null)return;let M,C;if(r==="insert"){const I=this._expandCol(f,v,a,s,y);M=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:P}=f,{column:w}=I,{column:U}=P;if(w>=a&&U<=s)m.push({unitId:e,subUnitId:n,drawingId:g});else{const E=this._shrinkCol(f,v,a,s,y);M=E==null?void 0:E.newSheetTransform,C=E==null?void 0:E.newTransform}}if(!M||!C)return;const R={unitId:e,subUnitId:n,drawingId:g,transform:C,sheetTransform:M};c.push(R)}),c.length===0&&m.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:S,redo:f,objects:v}=g;l.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:v,type:h.DrawingApplyType.UPDATE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:v,type:h.DrawingApplyType.UPDATE}})}if(m.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(m),S=g.undo,f=g.redo,v=g.objects;l.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:v,type:h.DrawingApplyType.REMOVE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:v,type:h.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),u.push({id:G.id,params:[e]}),{redos:l,undos:u}}_expandCol(i,r,t,e,n=h.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{column:l}=a,{column:u}=s;if(n===h.SheetDrawingAnchorType.None)return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};let d=null,c=null;if(l>=t){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:a.row,endRow:s.row});if(m==null)return;c={...r,left:(r.left||0)+m.endX-m.startX},d=V(c,this._selectionRenderService)}else if(u>=e)if(n===h.SheetDrawingAnchorType.Both)d={from:{...a},to:{...s,column:u+o}},c=H(d,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};return d!=null&&c!=null?{newSheetTransform:d,newTransform:c}:null}_shrinkCol(i,r,t,e,n=h.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{column:l}=a,{column:u}=s;if(n===h.SheetDrawingAnchorType.None)return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};let d=null,c=null;if(l>e)d={from:{...a,column:l-o},to:{...s,column:u-o}},c=H(d,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&u<=e)return null;if(l<t&&u>e)if(n===h.SheetDrawingAnchorType.Both)d={from:{...a},to:{...s,column:u-o}},c=H(d,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)c={...r,left:(r.left||0)-i.from.columnOffset};else{const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:l-1,startRow:a.row,endRow:s.row});if(m==null)return;c={...r,left:(r.left||0)-m.endX+m.startX-i.from.columnOffset}}d=V(c,this._selectionRenderService)}else if(u>=t&&u<=e&&n===h.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:a.row,endRow:s.row});if(m==null)return;d={from:{...a},to:{...s,column:t-1,columnOffset:m.endX-m.startX}},c=H(d,this._selectionRenderService,this._skeletonManagerService)}}return d!=null&&c!=null?{newSheetTransform:d,newTransform:c}:null}_expandRow(i,r,t,e,n=h.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{row:l}=a,{row:u}=s;if(n===h.SheetDrawingAnchorType.None)return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};let d=null,c=null;if(l>=t){const m=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:a.column,endColumn:s.column});if(m==null)return;c={...r,top:(r.top||0)+m.endY-m.startY},d=V(c,this._selectionRenderService)}else if(u>=e)if(n===h.SheetDrawingAnchorType.Both)d={from:{...a},to:{...s,row:u+o}},c=H(d,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};return d!=null&&c!=null?{newSheetTransform:d,newTransform:c}:null}_shrinkRow(i,r,t,e,n=h.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{row:l}=a,{row:u}=s;if(n===h.SheetDrawingAnchorType.None)return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};let d=null,c=null;if(l>e)d={from:{...a,row:l-o},to:{...s,row:u-o}},c=H(d,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&u<=e)return null;if(l<t&&u>e)if(n===h.SheetDrawingAnchorType.Both)d={from:{...a},to:{...s,row:u-o}},c=H(d,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)c={...r,top:(r.top||0)-i.from.rowOffset};else{const m=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:l-1,startColumn:a.column,endColumn:s.column});if(m==null)return;c={...r,top:(r.top||0)-m.endY+m.startY-i.from.rowOffset}}d=V(c,this._selectionRenderService)}else if(u>=t&&u<=e&&n===h.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:t-1,endRow:t-1});if(m==null)return;d={from:{...a},to:{...s,row:t-1,rowOffset:m.endY-m.startY}},c=H(d,this._selectionRenderService,this._skeletonManagerService)}}return d!=null&&c!=null?{newSheetTransform:d,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===_.SetWorksheetActiveOperation.id&&setTimeout(()=>{const r=i.params,{unitId:t,subUnitId:e}=r,n=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(n).forEach(s=>{const l=n[s];Object.keys(l).forEach(u=>{const d=l[u].data;d!=null&&Object.keys(d).forEach(c=>{if(s===t&&u===e){const m=d[c];m.transform=H(m.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(d[c])}else a.push(d[c])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Dt.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:s,anchorType:l=h.SheetDrawingAnchorType.Position}=a;if(l===h.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=s,{row:c,column:m}=u,{row:g,column:S}=d;for(let f=0;f<t.length;f++){const v=t[f],{startRow:y,endRow:M,startColumn:C,endColumn:R}=v;if(p.Rectangle.intersects({startRow:y,endRow:M,startColumn:C,endColumn:R},{startRow:c,endRow:g,startColumn:m,endColumn:S})||c>M||m>R){n.push({...a,transform:H(s,this._selectionRenderService,this._skeletonManagerService)});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[i]))}};we=yt([p.OnLifecycle(p.LifecycleStages.Rendered,we),re(0,p.ICommandService),re(1,$.Inject(_.SheetInterceptorService)),re(2,L.IRenderManagerService),re(3,h.ISheetDrawingService),re(4,A.IDrawingManagerService),re(5,p.IUniverInstanceService)],we);var Tt=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,Et=(i,r,t,e)=>{for(var n=e>1?void 0:e?Rt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(e?a(r,t,n):a(n))||n);return e&&n&&Tt(r,t,n),n},ie=(i,r)=>(t,e)=>r(t,e,i);function bt(i,r,t,e){const{scaleX:n,scaleY:o}=r.getAncestorScale(),a=r.getViewport(L.SHEET_VIEWPORT_KEY.VIEW_MAIN),s={left:!0,top:!0};if(!a)return{...i,absolute:s};const{left:l,right:u,top:d,bottom:c}=i,m=e.getFreeze(),{startColumn:g,startRow:S,xSplit:f,ySplit:v}=m,y=t.getNoMergeCellPositionByIndexWithNoHeader(S-v,g-f),M=t.getNoMergeCellPositionByIndexWithNoHeader(S,g),{rowHeaderWidth:C,columnHeaderHeight:R}=t,I=M.startX-y.startX,P=M.startY-y.startY,{top:w,left:U,viewportScrollX:E,viewportScrollY:j}=a;let O,b;l<U?(s.left=!0,O=(I+C+(l-U))*n,b=Math.max(Math.min((I+C+(u-U))*n,(I+C)*n),(u-E)*n)):(s.left=!1,O=Math.max((l-E)*n,(I+C)*n),b=Math.max((u-E)*n,(I+C)*n));let D,W;return d<w?(s.top=!0,D=(P+R+(d-w))*o,W=Math.max(Math.min((P+R+(u-w))*o,(P+R)*o),(c-j)*o)):(s.top=!1,D=Math.max((d-j)*o,(P+R)*o),W=Math.max((c-j)*o,(P+R)*o)),{left:O,right:b,top:D,bottom:W,absolute:s}}const Pe=(i,r,t,e)=>{const{scene:n}=r,{left:o,top:a,width:s,height:l,angle:u}=i,d={left:o,right:o+s,top:a,bottom:a+l},c=bt(d,n,t,e);return{startX:c.left,endX:c.right,startY:c.top,endY:c.bottom,rotate:u,width:s,height:l,absolute:c.absolute}};T.SheetCanvasFloatDomManagerService=class extends p.Disposable{constructor(t,e,n,o,a,s){super();K(this,"_domLayerMap",new Map);K(this,"_domLayerInfoMap",new Map);K(this,"_transformChange$",new k.Subject);K(this,"transformChange$",this._transformChange$.asObservable());K(this,"_remove$",new k.Subject);K(this,"remove$",this._remove$.asObservable());K(this,"_hooks",[]);this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=s,this._drawingAddListener(),this._scrollUpdateListener(),this._featureUpdateListener(),this._deleteListener()}_ensureMap(t,e){let n=this._domLayerMap.get(t);n||(n=new Map,this._domLayerMap.set(t,n));let o=n.get(e);return o||(o=new Map,n.set(e,o)),o}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const o=n.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:n,transformer:o,renderObject:e,canvas:a}}_getFloatDomProps(t){let e;return this._hooks.forEach(n=>{e=n.onGetFloatDomProps(t)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var He,Ye,Xe;const{unitId:n,subUnitId:o,drawingId:a}=e,s=_.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),l=this._drawingManagerService.getDrawingByParam(e),u=(He=this._renderManagerService.getRenderById(n))==null?void 0:He.with(B.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(l==null||s==null||u==null)return;const{transform:d,drawingType:c}=l;if(c!==p.DrawingTypeEnum.DRAWING_DOM)return;const m=this._getSceneAndTransformerByDrawingSearch(n);if(m==null)return;const{scene:g,canvas:S}=m;if(d==null)return!0;const{left:f,top:v,width:y,height:M,angle:C,flipX:R,flipY:I,skewX:P,skewY:w}=d,U=A.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),E=g.getObject(U);if(E!=null){E.transformByState({left:f,top:v,width:y,height:M,angle:C,flipX:R,flipY:I,skewX:P,skewY:w});return}const j={left:f,top:v,width:y,height:M,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},O=new L.Rect(U,j);g.addObject(O,L.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(O);const b=this._ensureMap(n,o),D=new p.DisposableCollection,W=Pe(O,m.renderObject,u.skeleton,s.worksheet),Y=new k.BehaviorSubject(W),te={dispose:D,rect:O,position$:Y,unitId:n,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:Y,id:a,componentKey:l.componentKey,onPointerDown:X=>{S.dispatchEvent(new PointerEvent(X.type,X))},onPointerMove:X=>{S.dispatchEvent(new PointerEvent(X.type,X))},onPointerUp:X=>{S.dispatchEvent(new PointerEvent(X.type,X))},onWheel:X=>{S.dispatchEvent(new WheelEvent(X.type,X))},props:(Xe=(Ye=b.get(a))==null?void 0:Ye.props)!=null?Xe:this._getFloatDomProps(a)});const ke=O.onTransformChange$.subscribeEvent(()=>{const X=Pe(O,m.renderObject,u.skeleton,s.worksheet);Y.next(X)});D.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),ke&&D.add(ke),this._domLayerInfoMap.set(a,te)})}))}_scrollUpdateListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n,o;const e=(a,s)=>{var g;const l=this._getSceneAndTransformerByDrawingSearch(a),u=this._ensureMap(a,s),d=Array.from(u.keys()),c=_.getSheetCommandTarget(this._univerInstanceService,{unitId:a,subUnitId:s}),m=(g=this._renderManagerService.getRenderById(a))==null?void 0:g.with(B.SheetSkeletonManagerService).getWorksheetSkeleton(s);!l||!c||!m||d.forEach(S=>{const f=this._domLayerInfoMap.get(S);if(f){const v=Pe(f.rect,l.renderObject,m.skeleton,c.worksheet);f.position$.next(v)}})};if(t.id===B.SetScrollOperation.id){const a=t.params,{unitId:s,sheetId:l}=a;e(s,l)}else if(t.id===B.SetZoomRatioOperation.id){const a=t.params,{unitId:s}=a;Array.from((o=(n=this._domLayerMap.get(s))==null?void 0:n.keys())!=null?o:[]).forEach(u=>{e(s,u)})}else if(t.id===_.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=t.params;e(a,s)}}))}_getPosition(t,e){var g;const{startX:n,endX:o,startY:a,endY:s}=t,l=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(B.ISheetSelectionRenderService);if(l==null)return;const u=l.getSelectionCellByPosition(n,a);if(u==null)return;const d={column:u.actualColumn,columnOffset:n-u.startX,row:u.actualRow,rowOffset:a-u.startY},c=l.getSelectionCellByPosition(o,s);if(c==null)return;const m={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:s-c.startY};return{from:d,to:m}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==p.DrawingTypeEnum.DRAWING_DOM)return;const o={...n.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}addFloatDomToPosition(t){const e=_.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!e)throw new Error("cannot find current target!");const{unitId:n,subUnitId:o}=e,{initPosition:a,componentKey:s}=t,l=p.Tools.generateRandomId(),u=this._getPosition(a,n);if(u==null)return;this._ensureMap(n,o).set(l,t);const c={unitId:n,subUnitId:o,drawingId:l,drawingType:p.DrawingTypeEnum.DRAWING_DOM,componentKey:s,sheetTransform:u,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY}};return this._commandService.executeCommand(fe.id,{unitId:n,drawings:[c]}),{id:l,dispose:()=>{this._removeDom(l,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:o,subUnitId:a}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(n.rect),e){this._ensureMap(o,a).delete(t);const u=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:t});if(!u)return;const d=this._sheetDrawingService.getBatchRemoveOp([u]),{redo:c,objects:m}=d;this._commandService.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:c,objects:m,type:h.DrawingApplyType.REMOVE})}}addHook(t){return this._hooks.push(t),{dispose:()=>{const e=this._hooks.findIndex(n=>n===t);this._hooks.splice(e,1)}}}},T.SheetCanvasFloatDomManagerService=Et([ie(0,$.Inject(L.IRenderManagerService)),ie(1,p.IUniverInstanceService),ie(2,$.Inject(p.ICommandService)),ie(3,A.IDrawingManagerService),ie(4,$.Inject(F.CanvasFloatDomService)),ie(5,h.ISheetDrawingService)],T.SheetCanvasFloatDomManagerService);var Pt=Object.defineProperty,Ot=Object.getOwnPropertyDescriptor,At=(i,r,t,e)=>{for(var n=e>1?void 0:e?Ot(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(e?a(r,t,n):a(n))||n);return e&&n&&Pt(r,t,n),n},_e=(i,r)=>(t,e)=>r(t,e,i);let Ie=class extends p.Disposable{constructor(i,r,t,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,t)=>{const{unitId:e,scene:n,subUnitId:o}=r,a=this._drawingManagerService.getDrawingDataForUnit(e),s=a==null?void 0:a[o];return s&&s.order.forEach(l=>{this._drawingRenderService.renderDrawing(s.data[l],n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,o=this._renderManagerService.getRenderById(e);if(!o)return t(i);const a=o.with(B.SheetSkeletonManagerService).getWorksheetSkeleton(n);if(!a)return t(i);const s=this._drawingManagerService.getDrawingDataForUnit(e),l=s==null?void 0:s[r.subUnitId];if(!l)return t(i);const{scaleX:u,scaleY:d}=o.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=l.order.map(g=>l.data[g]).filter(g=>g.drawingType!==A.DrawingTypeEnum.DRAWING_DOM);return m.length?(m.forEach(g=>{if(!g.groupId&&g.transform&&p.Tools.isDefine(g.transform.left)&&p.Tools.isDefine(g.transform.top)&&p.Tools.isDefine(g.transform.width)&&p.Tools.isDefine(g.transform.height)){const S=a.skeleton.getCellPositionByOffset(g.transform.left,g.transform.top,u,d,{x:0,y:0}),f=a.skeleton.getCellPositionByOffset(g.transform.left+g.transform.width,g.transform.top+g.transform.height,u,d,{x:0,y:0});S.column<c.startColumn&&(c.startColumn=S.column),S.row<c.startRow&&(c.startRow=S.row),c.endRow<f.row&&(c.endRow=f.row),c.endColumn<f.column&&(c.endColumn=f.column)}}),t(c)):t(i)}}))}};Ie=At([p.OnLifecycle(p.LifecycleStages.Rendered,Ie),_e(0,$.Inject(B.SheetPrintInterceptorService)),_e(1,$.Inject(Q.DrawingRenderService)),_e(2,A.IDrawingManagerService),_e(3,L.IRenderManagerService)],Ie);var Ut=Object.defineProperty,Nt=Object.getOwnPropertyDescriptor,Lt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Nt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(e?a(r,t,n):a(n))||n);return e&&n&&Ut(r,t,n),n},ue=(i,r)=>(t,e)=>r(t,e,i);let Ce=class extends p.Disposable{constructor(i,r,t,e,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(k.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,t])=>{if(!r){this._drawingManagerService.setDrawingVisible(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const n=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookViewPermission(n).id,new _.WorksheetViewPermission(n,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const s=r.getUnitId(),l=e.getSheetId(),u=this._drawingManagerService.getDrawingData(s,l),d=Object.values(u),c=this._renderManagerService.getRenderById(s),m=c==null?void 0:c.scene;if(m==null)return;m.getAllObjects().forEach(S=>{S.classType===L.RENDER_CLASS_TYPE.IMAGE&&d.some(f=>S.oKey.includes(f.drawingId))&&m.removeObject(S)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(k.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,t])=>{if(!r){this._drawingManagerService.setDrawingEditable(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const n=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookEditablePermission(n).id,new _.WorksheetEditPermission(n,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const s=r.getUnitId(),l=e.getSheetId(),u=this._drawingManagerService.getDrawingData(s,l),d=Object.values(u),c=this._renderManagerService.getRenderById(s),m=c==null?void 0:c.scene;if(m==null)return;m.getAllObjects().forEach(S=>{S.classType===L.RENDER_CLASS_TYPE.IMAGE&&d.some(f=>S.oKey.includes(f.drawingId))&&m.detachTransformerFrom(S)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(k.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,t])=>{r&&r.activeSheet$.subscribe(e=>{var c;if(!e)return;const n=r.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(n),l=s==null?void 0:s.scene;if(l==null)return;const u=l.getTransformerByCreate(),d=this._permissionService.composePermission$([new _.WorkbookViewPermission(n).id,new _.WorksheetViewPermission(n,o).id]).pipe(k.map(m=>m.every(g=>g.value)));d==null||d.pipe(k.filter(m=>m!==a),k.distinctUntilChanged()).subscribe({next:m=>{a=m,this._drawingManagerService.setDrawingVisible(m);const g=l.getAllObjects(),S=this._drawingManagerService.getDrawingData(n,o),f=Object.values(S);m?this._drawingManagerService.addNotification(f):(g.forEach(v=>{v.classType===L.RENDER_CLASS_TYPE.IMAGE&&f.some(y=>v.oKey.includes(y.drawingId))&&l.removeObject(v)}),u.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(n,o).id))==null||c.pipe(k.filter(m=>m.value!==a),k.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const m=this._drawingManagerService.getDrawingData(n,o),g=Object.values(m);this._drawingManagerService.addNotification(g)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(k.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,t])=>{r&&r.activeSheet$.subscribe(e=>{var c;if(!e)return;const n=r.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(n),l=s==null?void 0:s.scene;if(l==null)return;const u=l.getTransformerByCreate(),d=this._permissionService.composePermission$([new _.WorkbookEditablePermission(n).id,new _.WorksheetEditPermission(n,o).id]).pipe(k.map(m=>m.every(g=>g.value)));d==null||d.pipe(k.filter(m=>m!==a),k.distinctUntilChanged()).subscribe({next:m=>{a=m,this._drawingManagerService.setDrawingEditable(m);const g=l.getAllObjects(),S=this._drawingManagerService.getDrawingData(n,o),f=Object.values(S);m?(g.forEach(v=>{v.classType===L.RENDER_CLASS_TYPE.IMAGE&&f.some(y=>v.oKey.includes(y.drawingId))&&l.attachTransformerTo(v)}),this._drawingManagerService.addNotification(f)):(g.forEach(v=>{v.classType===L.RENDER_CLASS_TYPE.IMAGE&&f.some(y=>v.oKey.includes(y.drawingId))&&l.detachTransformerFrom(v)}),u.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(n,o).id))==null||c.pipe(k.filter(m=>m.value!==a),k.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const m=r.getUnitId(),g=e.getSheetId(),S=this._drawingManagerService.getDrawingData(m,g),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===L.RENDER_CLASS_TYPE.IMAGE&&f.some(R=>C.oKey.includes(R.drawingId))&&y.detachTransformerFrom(C)})}})})}))}};Ce=Lt([p.OnLifecycle(p.LifecycleStages.Rendered,Ce),ue(0,A.IDrawingManagerService),ue(1,L.IRenderManagerService),ue(2,p.IPermissionService),ue(3,p.IUniverInstanceService),ue(4,$.Inject(p.UserManagerService))],Ce);var jt=Object.defineProperty,Wt=Object.getOwnPropertyDescriptor,Bt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Wt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(e?a(r,t,n):a(n))||n);return e&&n&&jt(r,t,n),n},Oe=(i,r)=>(t,e)=>r(t,e,i);let ye=class extends p.Disposable{constructor(r,t,e){super();K(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e)=>this._collect(r,t,e),onPasteCells:(r,t,e,n)=>{const{copyType:o=B.COPY_TYPE.COPY,pasteType:a}=n,{range:s}=r||{},{range:l,unitId:u,subUnitId:d}=t;return this._generateMutations(l,{copyType:o,pasteType:a,copyRange:s,unitId:u,subUnitId:d})},onPastePlainText:(r,t)=>({undos:[],redos:[]})})}_collect(r,t,e){var m;const n=(m=this._renderManagerService.getRenderById(r))==null?void 0:m.with(B.SheetSkeletonManagerService);if(!n)return;const o=n.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:s,startY:l,endY:u}=o,d=this._sheetDrawingService.getDrawingData(r,t),c=[];Object.keys(d).forEach(g=>{const S=d[g],{transform:f}=S;if(S.anchorType!==h.SheetDrawingAnchorType.Both||!f)return;const{left:v=0,top:y=0,width:M=0,height:C=0}=f,{drawingStartX:R,drawingEndX:I,drawingStartY:P,drawingEndY:w}={drawingStartX:v,drawingEndX:v+M,drawingStartY:y,drawingEndY:y+C};a<=R&&I<=s&&l<=P&&w<=u&&c.push(S)}),c.length&&(this._copyInfo={drawings:c,unitId:r,subUnitId:t})}_generateMutations(r,t){var E;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(t.pasteType))return{redos:[],undos:[]};const{copyRange:e}=t;if(!e)return{redos:[],undos:[]};const{drawings:n,unitId:o,subUnitId:a}=this._copyInfo,{ranges:[s,l],mapFunc:u}=B.virtualizeDiscreteRanges([e,r]),{row:d,col:c}=u(s.startRow,s.startColumn),{row:m,col:g}=u(l.startRow,l.startColumn),S=(E=this._renderManagerService.getRenderById(o))==null?void 0:E.with(B.SheetSkeletonManagerService);if(!S)return{redos:[],undos:[]};const f=S.attachRangeWithCoord({startRow:d,endRow:d,startColumn:c,endColumn:c}),v=S.attachRangeWithCoord({startRow:m,endRow:m,startColumn:g,endColumn:g});if(!f||!v)return{redos:[],undos:[]};const y=[],M=[],C=v.startX-f.startX,R=v.startY-f.startY,I=m-d,P=g-c,w=t.copyType===B.COPY_TYPE.CUT,{_sheetDrawingService:U}=this;return n.forEach(j=>{const{transform:O,sheetTransform:b}=j;if(!O)return;const D={...j,unitId:o,subUnitId:a,drawingId:w?j.drawingId:p.Tools.generateRandomId(),transform:{...O,left:O.left+C,top:O.top+R},sheetTransform:{to:{...b.to,row:b.to.row+I,column:b.to.column+P},from:{...b.from,row:b.from.row+I,column:b.from.column+P}}};if(w){const{undo:W,redo:Y,objects:te}=U.getBatchUpdateOp([D]);y.push({id:h.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:h.DrawingApplyType.UPDATE,op:Y,objects:te}}),M.push({id:h.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:h.DrawingApplyType.UPDATE,op:W,objects:te}})}else{const{undo:W,redo:Y,objects:te}=U.getBatchAddOp([D]);y.push({id:h.SetDrawingApplyMutation.id,params:{op:Y,unitId:o,subUnitId:a,objects:te,type:h.DrawingApplyType.INSERT}}),M.push({id:h.SetDrawingApplyMutation.id,params:{op:W,unitId:o,subUnitId:a,objects:te,type:h.DrawingApplyType.REMOVE}})}}),{redos:y,undos:M}}};ye=Bt([p.OnLifecycle(p.LifecycleStages.Ready,ye),Oe(0,B.ISheetClipboardService),Oe(1,L.IRenderManagerService),Oe(2,h.ISheetDrawingService)],ye);var Ve=Object.defineProperty,$t=Object.getOwnPropertyDescriptor,Gt=(i,r,t)=>r in i?Ve(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,Vt=(i,r,t,e)=>{for(var n=e>1?void 0:e?$t(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=(e?a(r,t,n):a(n))||n);return e&&n&&Ve(r,t,n),n},Ae=(i,r)=>(t,e)=>r(t,e,i),Fe=(i,r,t)=>Gt(i,typeof r!="symbol"?r+"":r,t);const Ft="SHEET_IMAGE_UI_PLUGIN";T.UniverSheetsDrawingUIPlugin=class extends p.Plugin{constructor(t={},e,n,o){super();K(this,"_pluginConfig");this._injector=e,this._localeService=n,this._renderManagerService=o,this._pluginConfig=p.Tools.deepMerge({},_t,t)}onStarting(t){super.onStarting(t),this._initDependencies(t)}onRendered(){this._registerRenderModules()}_initDependencies(t){const e=[[T.SheetCanvasFloatDomManagerService],[de,{useFactory:()=>this._injector.createInstance(de,this._pluginConfig)}],[he],[Ie],[Ce]],n=[Se,we];e.forEach(o=>t.add(o)),n.forEach(o=>this._renderManagerService.registerRenderModule(p.UniverInstanceType.UNIVER_SHEET,o))}_registerRenderModules(){[[ye]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(p.UniverInstanceType.UNIVER_SHEET,t))})}},Fe(T.UniverSheetsDrawingUIPlugin,"type",p.UniverInstanceType.UNIVER_SHEET),Fe(T.UniverSheetsDrawingUIPlugin,"pluginName",Ft),T.UniverSheetsDrawingUIPlugin=Vt([p.DependentOn(A.UniverDrawingPlugin,Q.UniverDrawingUIPlugin,h.UniverSheetsDrawingPlugin),Ae(1,$.Inject($.Injector)),Ae(2,$.Inject(p.LocaleService)),Ae(3,L.IRenderManagerService)],T.UniverSheetsDrawingUIPlugin),T.ClearSheetDrawingTransformerOperation=G,T.DeleteDrawingsCommand=be,T.EditSheetDrawingOperation=De,T.GroupSheetDrawingCommand=Re,T.InsertCellImageOperation=ae,T.InsertFloatImageOperation=oe,T.InsertSheetDrawingCommand=fe,T.MoveDrawingsCommand=ne,T.RemoveSheetDrawingCommand=ge,T.SetDrawingArrangeCommand=Te,T.SetSheetDrawingCommand=se,T.SidebarSheetDrawingOperation=Me,T.UngroupSheetDrawingCommand=Ee,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),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("@univerjs/sheets"),require("react"),require("@univerjs/design"),require("clsx")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/drawing-ui","@univerjs/sheets-drawing","@univerjs/drawing","@univerjs/engine-render","@univerjs/sheets-ui","rxjs","@univerjs/ui","@univerjs/sheets","react","@univerjs/design","clsx"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverSheetsDrawingUi={},global.UniverCore,global.UniverDrawingUi,global.UniverSheetsDrawing,global.UniverDrawing,global.UniverEngineRender,global.UniverSheetsUi,global.rxjs,global.UniverUi,global.UniverSheets,global.React,global.UniverDesign,global.clsx))})(this,function(exports2,core,drawingUi,sheetsDrawing,drawing,engineRender,sheetsUi,rxjs,ui,sheets,React,design,clsx){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c,_d,_e,_f,_g,_h,_i;const ClearSheetDrawingTransformerOperation={id:"sheet.operation.clear-drawing-transformer",type:core.CommandType.MUTATION,handler:__name((accessor,params)=>{const renderManagerService=accessor.get(engineRender.IRenderManagerService);return params.forEach(unitId=>{var _a2,_b2;(_b2=(_a2=renderManagerService.getRenderById(unitId))==null?void 0:_a2.scene.getTransformer())==null||_b2.debounceRefreshControls()}),!0},"handler")},RemoveSheetDrawingCommand={id:"sheet.command.remove-sheet-image",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),sheetDrawingService=accessor.get(sheetsDrawing.ISheetDrawingService);if(!params)return!1;const{drawings}=params,unitIds=[];drawings.forEach(param=>{const{unitId:unitId2}=param;unitIds.push(unitId2)});const jsonOp=sheetDrawingService.getBatchRemoveOp(drawings),{unitId,subUnitId,undo,redo,objects}=jsonOp;return commandService.syncExecuteCommand(sheetsDrawing.SetDrawingApplyMutation.id,{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.REMOVE})?(undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:undo,objects,type:sheetsDrawing.DrawingApplyType.INSERT}},{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}],redoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.REMOVE}},{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}]}),!0):!1},"handler")},COMPONENT_SHEET_DRAWING_PANEL="COMPONENT_SHEET_DRAWING_PANEL",SidebarSheetDrawingOperation={id:"sidebar.operation.sheet-image",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const sidebarService=accessor.get(ui.ISidebarService),localeService=accessor.get(core.LocaleService),univerInstanceService=accessor.get(core.IUniverInstanceService),drawingManagerService=accessor.get(drawing.IDrawingManagerService);if(!sheets.getSheetCommandTarget(univerInstanceService))return!1;switch(params.value){case"open":sidebarService.open({header:{title:localeService.t("sheetImage.panel.title")},children:{label:COMPONENT_SHEET_DRAWING_PANEL},onClose:__name(()=>{drawingManagerService.focusDrawing(null)},"onClose"),width:360});break;case"close":default:sidebarService.close();break}return!0},"handler")},EditSheetDrawingOperation={id:"sheet.operation.edit-sheet-image",type:core.CommandType.OPERATION,handler:__name((accessor,params)=>{const drawingManagerService=accessor.get(drawing.IDrawingManagerService),commandService=accessor.get(core.ICommandService);return params==null?!1:(drawingManagerService.focusDrawing([params]),commandService.executeCommand(SidebarSheetDrawingOperation.id,{value:"open"}),!0)},"handler")},styles$2={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},UploadLoading=__name(()=>{const imageIoService=core.useDependency(drawing.IImageIoService),localeService=core.useDependency(core.LocaleService),[remain,setRemain]=React.useState(0);return React.useEffect(()=>{const sub=imageIoService.change$.subscribe(count=>{setRemain(count)});return()=>{sub.unsubscribe()}},[imageIoService]),React.createElement("div",{style:{display:remain>0?"block":"none"},className:styles$2.uploadLoading},React.createElement("div",{className:styles$2.uploadLoadingBody},React.createElement("div",{className:styles$2.uploadLoadingBodyAnimation}),React.createElement("div",{className:styles$2.uploadLoadingBodyText},`${localeService.t("uploadLoading.loading")}: ${remain}`)))},"UploadLoading");var __defProp$8=Object.defineProperty,__getOwnPropDesc$8=Object.getOwnPropertyDescriptor,__decorateClass$8=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$8(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$8(target,key,result),result},"__decorateClass$8"),__decorateParam$8=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$8");let DrawingPopupMenuController=(_a=class extends core.RxDisposable{constructor(_injector,_drawingManagerService,_canvasPopManagerService,_renderManagerService,_univerInstanceService,_contextService,_uiPartsService){super();__publicField(this,"_initImagePopupMenu",new Set);this._injector=_injector,this._drawingManagerService=_drawingManagerService,this._canvasPopManagerService=_canvasPopManagerService,this._renderManagerService=_renderManagerService,this._univerInstanceService=_univerInstanceService,this._contextService=_contextService,this._uiPartsService=_uiPartsService,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET).pipe(rxjs.takeUntil(this.dispose$)).subscribe(workbook=>this._create(workbook)),this._univerInstanceService.getTypeOfUnitDisposed$(core.UniverInstanceType.UNIVER_SHEET).pipe(rxjs.takeUntil(this.dispose$)).subscribe(workbook=>this._dispose(workbook)),this._univerInstanceService.getAllUnitsForType(core.UniverInstanceType.UNIVER_SHEET).forEach(workbook=>this._create(workbook)),this._uiPartsService.registerComponent(ui.BuiltInUIPart.CONTENT,()=>core.connectInjector(UploadLoading,this._injector))}_dispose(workbook){const unitId=workbook.getUnitId();this._renderManagerService.removeRender(unitId)}_create(workbook){if(!workbook)return;const unitId=workbook.getUnitId();this._renderManagerService.has(unitId)&&!this._initImagePopupMenu.has(unitId)&&(this._popupMenuListener(unitId),this._initImagePopupMenu.add(unitId))}_hasCropObject(scene){const objects=scene.getAllObjects();for(const object of objects)if(object instanceof drawingUi.ImageCropperObject)return!0;return!1}_popupMenuListener(unitId){var _a2;const scene=(_a2=this._renderManagerService.getRenderById(unitId))==null?void 0:_a2.scene;if(!scene)return;const transformer=scene.getTransformerByCreate();if(!transformer)return;let singletonPopupDisposer;this.disposeWithMe(core.toDisposable(transformer.createControl$.subscribe(()=>{if(this._contextService.setContextValue(core.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(scene))return;const selectedObjects=transformer.getSelectedObjectMap();if(selectedObjects.size>1){singletonPopupDisposer==null||singletonPopupDisposer.dispose();return}const object=selectedObjects.values().next().value;if(!object)return;const oKey=object.oKey,drawingParam=this._drawingManagerService.getDrawingOKey(oKey);if(!drawingParam)return;const{unitId:unitId2,subUnitId,drawingId}=drawingParam;singletonPopupDisposer==null||singletonPopupDisposer.dispose(),singletonPopupDisposer=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(object,{componentKey:drawingUi.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(unitId2,subUnitId,drawingId)}})),this._drawingManagerService.focusDrawing([{unitId:unitId2,subUnitId,drawingId}])}))),this.disposeWithMe(transformer.clearControl$.subscribe(()=>{singletonPopupDisposer==null||singletonPopupDisposer.dispose(),this._contextService.setContextValue(core.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(transformer.changing$.subscribe(()=>{singletonPopupDisposer==null||singletonPopupDisposer.dispose()}))}_getImageMenuItems(unitId,subUnitId,drawingId){return[{label:"image-popup.edit",index:0,commandId:EditSheetDrawingOperation.id,commandParams:{unitId,subUnitId,drawingId},disable:!1},{label:"image-popup.delete",index:1,commandId:RemoveSheetDrawingCommand.id,commandParams:{unitId,drawings:[{unitId,subUnitId,drawingId}]},disable:!1},{label:"image-popup.crop",index:2,commandId:drawingUi.OpenImageCropOperation.id,commandParams:{unitId,subUnitId,drawingId},disable:!1},{label:"image-popup.reset",index:3,commandId:drawingUi.ImageResetSizeOperation.id,commandParams:[{unitId,subUnitId,drawingId}],disable:!1}]}},__name(_a,"DrawingPopupMenuController"),_a);DrawingPopupMenuController=__decorateClass$8([core.OnLifecycle(core.LifecycleStages.Steady,DrawingPopupMenuController),__decorateParam$8(0,core.Inject(core.Injector)),__decorateParam$8(1,drawing.IDrawingManagerService),__decorateParam$8(2,core.Inject(sheetsUi.SheetCanvasPopManagerService)),__decorateParam$8(3,engineRender.IRenderManagerService),__decorateParam$8(4,core.IUniverInstanceService),__decorateParam$8(5,core.IContextService),__decorateParam$8(6,core.Inject(ui.IUIPartsService))],DrawingPopupMenuController);const InsertFloatImageOperation={id:"sheet.operation.insert-float-image",type:core.CommandType.OPERATION,handler:__name((accessor,params)=>!0,"handler")},InsertCellImageOperation={id:"sheet.operation.insert-cell-image",type:core.CommandType.OPERATION,handler:__name((accessor,params)=>!0,"handler")},InsertSheetDrawingCommand={id:"sheet.command.insert-sheet-image",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),sheetDrawingService=accessor.get(sheetsDrawing.ISheetDrawingService);if(!params)return!1;const drawings=params.drawings,unitIds=drawings.map(param=>param.unitId),jsonOp=sheetDrawingService.getBatchAddOp(drawings),{unitId,subUnitId,undo,redo,objects}=jsonOp;return commandService.syncExecuteCommand(sheetsDrawing.SetDrawingApplyMutation.id,{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.INSERT})?(undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:undo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.REMOVE}},{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}],redoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.INSERT}},{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}]}),!0):!1},"handler")},SetSheetDrawingCommand={id:"sheet.command.set-sheet-image",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),sheetDrawingService=accessor.get(sheetsDrawing.ISheetDrawingService);if(!params)return!1;const{drawings}=params,jsonOp=sheetDrawingService.getBatchUpdateOp(drawings),{unitId,subUnitId,undo,redo,objects}=jsonOp;return commandService.syncExecuteCommand(sheetsDrawing.SetDrawingApplyMutation.id,{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE})?(undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:undo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}},{id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}],redoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}},{id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}]}),!0):!1},"handler")},SetDrawingArrangeCommand={id:"sheet.command.set-drawing-arrange",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService);if(!params)return!1;const sheetDrawingService=accessor.get(sheetsDrawing.ISheetDrawingService),{unitId,subUnitId,drawingIds,arrangeType}=params,drawingOrderMapParam={unitId,subUnitId,drawingIds};let jsonOp;if(arrangeType===drawing.ArrangeTypeEnum.forward?jsonOp=sheetDrawingService.getForwardDrawingsOp(drawingOrderMapParam):arrangeType===drawing.ArrangeTypeEnum.backward?jsonOp=sheetDrawingService.getBackwardDrawingOp(drawingOrderMapParam):arrangeType===drawing.ArrangeTypeEnum.front?jsonOp=sheetDrawingService.getFrontDrawingsOp(drawingOrderMapParam):arrangeType===drawing.ArrangeTypeEnum.back&&(jsonOp=sheetDrawingService.getBackDrawingsOp(drawingOrderMapParam)),jsonOp==null)return!1;const{objects,redo,undo}=jsonOp;return commandService.syncExecuteCommand(sheetsDrawing.SetDrawingApplyMutation.id,{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.ARRANGE})?(undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:undo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.ARRANGE}}],redoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.ARRANGE}}]}),!0):!1},"handler")};function ungroupToGroup(ungroupParams){const newGroupParams=[];return ungroupParams.forEach(ungroupParam=>{const{parent,children}=ungroupParam,{unitId,subUnitId,drawingId:groupId}=parent,groupTransform=engineRender.getGroupState(0,0,children.map(o=>o.transform||{})),newChildren=children.map(drawing2=>{const transform=drawing2.transform||{left:0,top:0},{unitId:unitId2,subUnitId:subUnitId2,drawingId}=drawing2;return{unitId:unitId2,subUnitId:subUnitId2,drawingId,transform:{...transform,left:transform.left-groupTransform.left,top:transform.top-groupTransform.top},groupId}}),groupParam={unitId,subUnitId,drawingId:groupId,drawingType:drawing.DrawingTypeEnum.DRAWING_GROUP,transform:groupTransform};newGroupParams.push({parent:groupParam,children:newChildren})}),newGroupParams}__name(ungroupToGroup,"ungroupToGroup");function groupToUngroup(groupParams){const newGroupParams=[];return groupParams.forEach(groupParam=>{const{parent,children}=groupParam,{unitId,subUnitId,drawingId:groupId,transform:groupTransform={width:0,height:0}}=parent;if(groupTransform==null)return;const newChildren=children.map(object=>{const{transform}=object,{unitId:unitId2,subUnitId:subUnitId2,drawingId}=object,newTransform=engineRender.transformObjectOutOfGroup(transform||{},groupTransform,groupTransform.width||0,groupTransform.height||0);return{unitId:unitId2,subUnitId:subUnitId2,drawingId,transform:newTransform,groupId:void 0}}),ungroupParam={unitId,subUnitId,drawingId:groupId,drawingType:drawing.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};newGroupParams.push({parent:ungroupParam,children:newChildren})}),newGroupParams}__name(groupToUngroup,"groupToUngroup");const GroupSheetDrawingCommand={id:"sheet.command.group-sheet-image",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),sheetDrawingService=accessor.get(sheetsDrawing.ISheetDrawingService);if(!params)return!1;const unitIds=[];params.forEach(({parent,children})=>{unitIds.push(parent.unitId),children.forEach(child=>{unitIds.push(child.unitId)})});const jsonOp=sheetDrawingService.getGroupDrawingOp(params),{unitId,subUnitId,undo,redo,objects}=jsonOp;return commandService.syncExecuteCommand(sheetsDrawing.SetDrawingApplyMutation.id,{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.GROUP})?(undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:undo,unitId,subUnitId,objects:groupToUngroup(objects),type:sheetsDrawing.DrawingApplyType.UNGROUP}},{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}],redoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.GROUP}},{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}]}),!0):!1},"handler")},UngroupSheetDrawingCommand={id:"sheet.command.ungroup-sheet-image",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),sheetDrawingService=accessor.get(sheetsDrawing.ISheetDrawingService);if(!params)return!1;const unitIds=[];params.forEach(({parent,children})=>{unitIds.push(parent.unitId),children.forEach(child=>{unitIds.push(child.unitId)})});const jsonOp=sheetDrawingService.getUngroupDrawingOp(params),{unitId,subUnitId,undo,redo,objects}=jsonOp;return commandService.syncExecuteCommand(sheetsDrawing.SetDrawingApplyMutation.id,{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.UNGROUP})?(undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:undo,unitId,subUnitId,objects:ungroupToGroup(objects),type:sheetsDrawing.DrawingApplyType.GROUP}},{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}],redoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.UNGROUP}},{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}]}),!0):!1},"handler")};function drawingPositionToTransform(position,selectionRenderService,sheetSkeletonManagerService){const{from,to,flipY=!1,flipX=!1,angle=0,skewX=0,skewY=0}=position,{column:fromColumn,columnOffset:fromColumnOffset,row:fromRow,rowOffset:fromRowOffset}=from,{column:toColumn,columnOffset:toColumnOffset,row:toRow,rowOffset:toRowOffset}=to,startSelectionCell=sheetSkeletonManagerService.attachRangeWithCoord({startColumn:fromColumn,endColumn:fromColumn,startRow:fromRow,endRow:fromRow});if(startSelectionCell==null)return;const endSelectionCell=sheetSkeletonManagerService.attachRangeWithCoord({startColumn:toColumn,endColumn:toColumn,startRow:toRow,endRow:toRow});if(endSelectionCell==null)return;const{startX:startSelectionX,startY:startSelectionY}=startSelectionCell,{startX:endSelectionX,startY:endSelectionY}=endSelectionCell;let left=engineRender.precisionTo(startSelectionX+fromColumnOffset,1),top=engineRender.precisionTo(startSelectionY+fromRowOffset,1),width=engineRender.precisionTo(endSelectionX+toColumnOffset-left,1),height=engineRender.precisionTo(endSelectionY+toRowOffset-top,1);startSelectionCell.startX===endSelectionCell.endX&&(width=0),startSelectionCell.startY===endSelectionCell.endY&&(height=0);const skeleton=sheetSkeletonManagerService.getCurrentSkeleton(),sheetWidth=skeleton.rowHeaderWidth+skeleton.columnTotalWidth,sheetHeight=skeleton.columnHeaderHeight+skeleton.rowTotalHeight;return left+width>sheetWidth&&(left=sheetWidth-width),top+height>sheetHeight&&(top=sheetHeight-height),{flipY,flipX,angle,skewX,skewY,left,top,width,height}}__name(drawingPositionToTransform,"drawingPositionToTransform");function transformToDrawingPosition(transform,selectionRenderService){const{left=0,top=0,width=0,height=0,flipY=!1,flipX=!1,angle=0,skewX=0,skewY=0}=transform,startSelectionCell=selectionRenderService.getSelectionCellByPosition(left,top);if(startSelectionCell==null)return;const from={column:startSelectionCell.actualColumn,columnOffset:engineRender.precisionTo(left-startSelectionCell.startX,1),row:startSelectionCell.actualRow,rowOffset:engineRender.precisionTo(top-startSelectionCell.startY,1)},endSelectionCell=selectionRenderService.getSelectionCellByPosition(left+width,top+height);if(endSelectionCell==null)return;const to={column:endSelectionCell.actualColumn,columnOffset:engineRender.precisionTo(left+width-endSelectionCell.startX,1),row:endSelectionCell.actualRow,rowOffset:engineRender.precisionTo(top+height-endSelectionCell.startY,1)};return{flipY,flipX,angle,skewX,skewY,from,to}}__name(transformToDrawingPosition,"transformToDrawingPosition");var __defProp$7=Object.defineProperty,__getOwnPropDesc$7=Object.getOwnPropertyDescriptor,__decorateClass$7=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$7(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$7(target,key,result),result},"__decorateClass$7"),__decorateParam$7=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$7");let SheetDrawingUpdateController=(_b=class extends core.Disposable{constructor(_context,_skeletonManagerService,_commandService,_selectionRenderService,_imageIoService,_sheetDrawingService,_drawingManagerService,_contextService,_messageService,_localeService,selectionManagerService){super();__publicField(this,"_workbookSelections");this._context=_context,this._skeletonManagerService=_skeletonManagerService,this._commandService=_commandService,this._selectionRenderService=_selectionRenderService,this._imageIoService=_imageIoService,this._sheetDrawingService=_sheetDrawingService,this._drawingManagerService=_drawingManagerService,this._contextService=_contextService,this._messageService=_messageService,this._localeService=_localeService,this._workbookSelections=selectionManagerService.getWorkbookSelections(this._context.unitId),this._initCommandListeners(),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener(),this._drawingAddListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async command=>{if(command.id===InsertCellImageOperation.id||command.id===InsertFloatImageOperation.id){const params=command.params;if(params.files==null)return;const fileLength=params.files.length;if(fileLength>drawing.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:design.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(drawing.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(fileLength),command.id===InsertCellImageOperation.id?params.files.forEach(async file=>{await this._insertCellImage(file)}):params.files.forEach(async file=>{await this._insertFloatImage(file)})}}))}async _insertCellImage(file){}async _insertFloatImage(file){let imageParam;try{imageParam=await this._imageIoService.saveImage(file)}catch(error){const type=error.message;type===drawing.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:design.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(drawing.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):type===drawing.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:design.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):type===drawing.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:design.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(imageParam==null)return;const info=this._getUnitInfo();if(info==null)return;const{unitId,subUnitId}=info,{imageId,imageSourceType,source,base64Cache}=imageParam,{width,height,image}=await drawing.getImageSize(base64Cache||""),{width:sceneWidth,height:sceneHeight}=this._context.scene;this._imageIoService.addImageSourceCache(source,imageSourceType,image);let scale=1;if(width>drawing.DRAWING_IMAGE_WIDTH_LIMIT||height>drawing.DRAWING_IMAGE_HEIGHT_LIMIT){const scaleWidth=drawing.DRAWING_IMAGE_WIDTH_LIMIT/width,scaleHeight=drawing.DRAWING_IMAGE_HEIGHT_LIMIT/height;scale=Math.max(scaleWidth,scaleHeight)}const sheetTransform=this._getImagePosition(width*scale,height*scale,sceneWidth,sceneHeight);if(sheetTransform==null)return;const sheetDrawingParam={unitId,subUnitId,drawingId:imageId,drawingType:drawing.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType,source,transform:drawingPositionToTransform(sheetTransform,this._selectionRenderService,this._skeletonManagerService),sheetTransform};this._commandService.executeCommand(InsertSheetDrawingCommand.id,{unitId,drawings:[sheetDrawingParam]})}_getUnitInfo(){const workbook=this._context.unit,worksheet=workbook.getActiveSheet(),unitId=workbook.getUnitId(),subUnitId=worksheet.getSheetId();return{unitId,subUnitId}}_getImagePosition(imageWidth,imageHeight,sceneWidth,sceneHeight){const selections=this._workbookSelections.getCurrentSelections();let range={startRow:0,endRow:0,startColumn:0,endColumn:0};selections&&selections.length>0&&(range=selections[selections.length-1].range);const rangeWithCoord=sheetsUi.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,range);if(rangeWithCoord==null)return;let{startColumn,startRow,startX,startY}=rangeWithCoord,isChangeStart=!1;if(startX+imageWidth>sceneWidth&&(startX=sceneWidth-imageWidth,startX<0&&(startX=0,imageWidth=sceneWidth),isChangeStart=!0),startY+imageHeight>sceneHeight&&(startY=sceneHeight-imageHeight,startY<0&&(startY=0,imageHeight=sceneHeight),isChangeStart=!0),isChangeStart){const newCoord=this._selectionRenderService.getSelectionCellByPosition(startX,startY);if(newCoord==null)return;startX=newCoord.startX,startY=newCoord.startY,startColumn=newCoord.actualColumn,startRow=newCoord.actualRow}const from={column:startColumn,columnOffset:0,row:startRow,rowOffset:0},endSelectionCell=this._selectionRenderService.getSelectionCellByPosition(startX+imageWidth,startY+imageHeight);if(endSelectionCell==null)return;const to={column:endSelectionCell.actualColumn,columnOffset:startX+imageWidth-endSelectionCell.startX,row:endSelectionCell.actualRow,rowOffset:startY+imageHeight-endSelectionCell.startY};return{from,to}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(params=>{const{unitId,subUnitId,drawingIds,arrangeType}=params;this._commandService.executeCommand(SetDrawingArrangeCommand.id,{unitId,subUnitId,drawingIds,arrangeType})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(params=>{const drawings=[];params.length!==0&&(params.forEach(param=>{const{unitId,subUnitId,drawingId,drawingType,transform}=param;if(transform==null)return;const sheetDrawing=this._sheetDrawingService.getDrawingByParam({unitId,subUnitId,drawingId});if(sheetDrawing==null)return;const sheetTransform=transformToDrawingPosition({...sheetDrawing.transform,...transform},this._selectionRenderService);if(sheetTransform==null)return;const newDrawing={...param,transform:{...sheetDrawing.transform,...transform,...drawingPositionToTransform(sheetTransform,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...sheetTransform}};drawings.push(newDrawing)}),drawings.length>0&&this._commandService.executeCommand(SetSheetDrawingCommand.id,{unitId:params[0].unitId,drawings}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(params=>{this._commandService.executeCommand(GroupSheetDrawingCommand.id,params);const{unitId,subUnitId,drawingId}=params[0].parent;this._drawingManagerService.focusDrawing([{unitId,subUnitId,drawingId}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(params=>{this._commandService.executeCommand(UngroupSheetDrawingCommand.id,params)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(params=>{params==null||params.length===0?(this._contextService.setContextValue(core.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(core.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(params))}))}_drawingAddListener(){this.disposeWithMe(this._sheetDrawingService.add$.subscribe(params=>{this._registerDrawing(params)}))}_registerDrawing(params){params.forEach(param=>{const drawingParam=this._sheetDrawingService.getDrawingByParam(param);if(drawingParam==null)return;const{sheetTransform}=drawingParam;drawingParam.transform=drawingPositionToTransform(sheetTransform,this._selectionRenderService,this._skeletonManagerService)});const unitId=params[0].unitId;this._drawingManagerService.registerDrawingData(unitId,this._sheetDrawingService.getDrawingDataForUnit(unitId)),this._drawingManagerService.initializeNotification(unitId)}},__name(_b,"SheetDrawingUpdateController"),_b);SheetDrawingUpdateController=__decorateClass$7([__decorateParam$7(1,core.Inject(sheetsUi.SheetSkeletonManagerService)),__decorateParam$7(2,core.ICommandService),__decorateParam$7(3,sheetsUi.ISheetSelectionRenderService),__decorateParam$7(4,drawing.IImageIoService),__decorateParam$7(5,sheetsDrawing.ISheetDrawingService),__decorateParam$7(6,drawing.IDrawingManagerService),__decorateParam$7(7,core.IContextService),__decorateParam$7(8,ui.IMessageService),__decorateParam$7(9,core.Inject(core.LocaleService)),__decorateParam$7(10,core.Inject(sheets.SheetsSelectionsService))],SheetDrawingUpdateController);var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++){s=arguments[i];for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p])}return t},__assign.apply(this,arguments)},__rest=function(s,e){var t={};for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&e.indexOf(p)<0&&(t[p]=s[p]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,p=Object.getOwnPropertySymbols(s);i<p.length;i++)e.indexOf(p[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p[i])&&(t[p[i]]=s[p[i]]);return t},IconBase=React.forwardRef(function(props,ref){var icon=props.icon,id=props.id,className=props.className,extend=props.extend,restProps=__rest(props,["icon","id","className","extend"]),cls="univerjs-icon univerjs-icon-".concat(id," ").concat(className||"").trim(),idSuffix=React.useRef("_".concat(generateShortUuid()));return render(icon,"".concat(id),{defIds:icon.defIds,idSuffix:idSuffix.current},__assign({ref,className:cls},restProps),extend)});function render(node,id,runtimeProps,rootProps,extend){return React.createElement(node.tag,__assign(__assign({key:id},replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend)),rootProps),(replaceRuntimeIdsInDefs(node,runtimeProps).children||[]).map(function(child,index){return render(child,"".concat(id,"-").concat(node.tag,"-").concat(index),runtimeProps,void 0,extend)}))}__name(render,"render");function replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend){var attrs=__assign({},node.attrs);extend!=null&&extend.colorChannel1&&attrs.fill==="colorChannel1"&&(attrs.fill=extend.colorChannel1);var defIds=runtimeProps.defIds;return!defIds||defIds.length===0||(node.tag==="use"&&attrs["xlink:href"]&&(attrs["xlink:href"]=attrs["xlink:href"]+runtimeProps.idSuffix),Object.entries(attrs).forEach(function(_a2){var key=_a2[0],value=_a2[1];typeof value=="string"&&(attrs[key]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a2,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a2=node.children)===null||_a2===void 0)&&_a2.length)?__assign(__assign({},node),{children:node.children.map(function(child){return typeof child.attrs.id=="string"&&defIds&&defIds.indexOf(child.attrs.id)>-1?__assign(__assign({},child),{attrs:__assign(__assign({},child.attrs),{id:child.attrs.id+runtimeProps.idSuffix})}):child})}):node}__name(replaceRuntimeIdsInDefs,"replaceRuntimeIdsInDefs");function generateShortUuid(){return Math.random().toString(36).substring(2,8)}__name(generateShortUuid,"generateShortUuid"),IconBase.displayName="UniverIcon";var element={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"}}]},AddImageSingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"add-image-single",ref,icon:element}))});AddImageSingle.displayName="AddImageSingle";const styles$1={uploadFileMenu:"univer-upload-file-menu",uploadFileMenuInput:"univer-upload-file-menu-input"},COMPONENT_UPLOAD_FILE_MENU="COMPONENT_UPLOAD_FILE_MENU";var UploadFileType=(UploadFileType2=>(UploadFileType2[UploadFileType2.cellImage=0]="cellImage",UploadFileType2[UploadFileType2.floatImage=1]="floatImage",UploadFileType2))(UploadFileType||{});const UploadFileMenu=__name(props=>{const{type}=props,commandService=core.useDependency(core.ICommandService),fileInputRef=React.useRef(null),handleButtonClick=__name(()=>{var _a2;(_a2=fileInputRef.current)==null||_a2.click()},"handleButtonClick"),imageAccept=drawing.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(image=>`.${image.replace("image/","")}`).join(","),handleFileChange=__name(event=>{const fileList=event.target.files;if(fileList==null)return;const files=Array.from(fileList);type===UploadFileType.floatImage?commandService.executeCommand(InsertFloatImageOperation.id,{files}):type===UploadFileType.cellImage&&commandService.executeCommand(InsertCellImageOperation.id,{files}),fileInputRef.current&&(fileInputRef.current.value="")},"handleFileChange");return React.createElement("div",{onClick:handleButtonClick,className:styles$1.uploadFileMenu},React.createElement("input",{type:"file",className:styles$1.uploadFileMenuInput,ref:fileInputRef,onChange:handleFileChange,accept:imageAccept,multiple:!0}))},"UploadFileMenu"),IMAGE_UPLOAD_ICON="addition-and-subtraction-single",IMAGE_MENU_ID="sheet.menu.image";function ImageMenuFactory(accessor){return{id:IMAGE_MENU_ID,type:ui.MenuItemType.SUBITEMS,positions:[ui.MenuPosition.TOOLBAR_START],group:ui.MenuGroup.TOOLBAR_FORMULAS_INSERT,icon:IMAGE_UPLOAD_ICON,tooltip:"sheetImage.title",hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:sheetsUi.getCurrentRangeDisable$(accessor,{workbookTypes:[sheets.WorkbookEditablePermission],worksheetTypes:[sheets.WorksheetEditPermission],rangeTypes:[sheets.RangeProtectionPermissionEditPoint]})}}__name(ImageMenuFactory,"ImageMenuFactory");function UploadFloatImageMenuFactory(_accessor){return{id:InsertFloatImageOperation.id,title:"sheetImage.upload.float",type:ui.MenuItemType.SELECTOR,label:{name:COMPONENT_UPLOAD_FILE_MENU,props:{type:UploadFileType.floatImage}},positions:[IMAGE_MENU_ID],hidden$:ui.getMenuHiddenObservable(_accessor,core.UniverInstanceType.UNIVER_SHEET)}}__name(UploadFloatImageMenuFactory,"UploadFloatImageMenuFactory");const styles={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelSubtitle:"univer-image-common-panel-subtitle",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"},SheetDrawingAnchor=__name(props=>{var _a2;const commandService=core.useDependency(core.ICommandService),localeService=core.useDependency(core.LocaleService),drawingManagerService=core.useDependency(drawing.IDrawingManagerService),renderManagerService=core.useDependency(engineRender.IRenderManagerService),{drawings}=props,drawingParam=drawings[0];if(drawingParam==null)return;const{unitId}=drawingParam,renderObject=renderManagerService.getRenderById(unitId),scene=renderObject==null?void 0:renderObject.scene;if(scene==null)return;const transformer=scene.getTransformerByCreate(),[anchorShow,setAnchorShow]=React.useState(!0),type=(_a2=drawingParam.anchorType)!=null?_a2:sheetsDrawing.SheetDrawingAnchorType.Position,[value,setValue]=React.useState(type);function getUpdateParams(objects,drawingManagerService2){const params=[];return objects.forEach(object=>{const{oKey}=object,searchParam=drawingManagerService2.getDrawingOKey(oKey);if(searchParam==null)return params.push(null),!0;const{unitId:unitId2,subUnitId,drawingId,drawingType,anchorType,sheetTransform}=searchParam;params.push({unitId:unitId2,subUnitId,drawingId,anchorType,sheetTransform,drawingType})}),params}__name(getUpdateParams,"getUpdateParams"),React.useEffect(()=>{const onClearControlObserver=transformer.clearControl$.subscribe(changeSelf=>{changeSelf===!0&&setAnchorShow(!1)}),onChangeStartObserver=transformer.changeStart$.subscribe(state=>{var _a3;const{objects}=state,params=getUpdateParams(objects,drawingManagerService);if(params.length===0)setAnchorShow(!1);else if(params.length>=1){setAnchorShow(!0);const anchorType=((_a3=params[0])==null?void 0:_a3.anchorType)||sheetsDrawing.SheetDrawingAnchorType.Position;setValue(anchorType)}});return()=>{onChangeStartObserver.unsubscribe(),onClearControlObserver.unsubscribe()}},[]);function handleChange(value2){setValue(value2);const focusDrawings=drawingManagerService.getFocusDrawings();if(focusDrawings.length===0)return;const updateParams=focusDrawings.map(drawing2=>({unitId:drawing2.unitId,subUnitId:drawing2.subUnitId,drawingId:drawing2.drawingId,anchorType:value2}));commandService.executeCommand(SetSheetDrawingCommand.id,{unitId:focusDrawings[0].unitId,drawings:updateParams})}__name(handleChange,"handleChange");const gridDisplay=__name(isShow=>isShow?"block":"none","gridDisplay");return React.createElement("div",{className:clsx(styles.imageCommonPanelGrid,styles.imageCommonPanelBorder),style:{display:gridDisplay(anchorShow)}},React.createElement("div",{className:styles.imageCommonPanelRow},React.createElement("div",{className:clsx(styles.imageCommonPanelColumn,styles.imageCommonPanelTitle)},React.createElement("div",null,localeService.t("drawing-anchor.title")))),React.createElement("div",{className:clsx(styles.imageCommonPanelRow)},React.createElement("div",{className:clsx(styles.imageCommonPanelColumn)},React.createElement(design.RadioGroup,{value,onChange:handleChange,direction:"vertical"},React.createElement(design.Radio,{value:sheetsDrawing.SheetDrawingAnchorType.Both},localeService.t("drawing-anchor.both")),React.createElement(design.Radio,{value:sheetsDrawing.SheetDrawingAnchorType.Position},localeService.t("drawing-anchor.position")),React.createElement(design.Radio,{value:sheetsDrawing.SheetDrawingAnchorType.None},localeService.t("drawing-anchor.none"))))))},"SheetDrawingAnchor"),SheetDrawingPanel=__name(()=>{const drawingManagerService=core.useDependency(drawing.IDrawingManagerService),focusDrawings=drawingManagerService.getFocusDrawings(),[drawings,setDrawings]=React.useState(focusDrawings);return React.useEffect(()=>{const focusDispose=drawingManagerService.focus$.subscribe(drawings2=>{setDrawings(drawings2)});return()=>{focusDispose.unsubscribe()}},[]),!!(drawings!=null&&drawings.length)&&React.createElement("div",{className:styles.imageCommonPanel},React.createElement(drawingUi.DrawingCommonPanel,{drawings}),React.createElement(SheetDrawingAnchor,{drawings}))},"SheetDrawingPanel"),MoveDrawingsCommand={id:"sheet.command.move-drawing",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{const commandService=accessor.get(core.ICommandService),drawingManagerService=accessor.get(sheetsDrawing.ISheetDrawingService),selectionRenderService=accessor.get(sheetsUi.ISheetSelectionRenderService),{direction}=params,drawings=drawingManagerService.getFocusDrawings();if(drawings.length===0)return!1;const unitId=drawings[0].unitId,newDrawings=drawings.map(drawing2=>{const{transform}=drawing2;if(transform==null)return null;const newTransform={...transform},{left=0,top=0}=transform;return direction===core.Direction.UP?newTransform.top=top-1:direction===core.Direction.DOWN?newTransform.top=top+1:direction===core.Direction.LEFT?newTransform.left=left-1:direction===core.Direction.RIGHT&&(newTransform.left=left+1),{...drawing2,transform:newTransform,sheetTransform:transformToDrawingPosition(newTransform,selectionRenderService)}}).filter(drawing2=>drawing2!=null);return commandService.syncExecuteCommand(SetSheetDrawingCommand.id,{unitId,drawings:newDrawings})?(commandService.syncExecuteCommand(ClearSheetDrawingTransformerOperation.id,[unitId]),!0):!1},"handler")},DeleteDrawingsCommand={id:"sheet.command.delete-drawing",type:core.CommandType.COMMAND,handler:__name(accessor=>{const commandService=accessor.get(core.ICommandService),drawings=accessor.get(sheetsDrawing.ISheetDrawingService).getFocusDrawings();if(drawings.length===0)return!1;const unitId=drawings[0].unitId,newDrawings=drawings.map(drawing2=>{const{unitId:unitId2,subUnitId,drawingId,drawingType}=drawing2;return{unitId:unitId2,subUnitId,drawingId,drawingType}});return commandService.executeCommand(RemoveSheetDrawingCommand.id,{unitId,drawings:newDrawings})},"handler")};function whenSheetDrawingFocused(contextService){return!contextService.getContextValue(core.FOCUSING_FORMULA_EDITOR)&&!contextService.getContextValue(core.EDITOR_ACTIVATED)&&contextService.getContextValue(core.FOCUSING_COMMON_DRAWINGS)}__name(whenSheetDrawingFocused,"whenSheetDrawingFocused");const MoveDrawingDownShortcutItem={id:MoveDrawingsCommand.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:ui.KeyCode.ARROW_DOWN,priority:100,preconditions:whenSheetDrawingFocused,staticParameters:{direction:core.Direction.DOWN}},MoveDrawingUpShortcutItem={id:MoveDrawingsCommand.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:ui.KeyCode.ARROW_UP,priority:100,preconditions:whenSheetDrawingFocused,staticParameters:{direction:core.Direction.UP}},MoveDrawingLeftShortcutItem={id:MoveDrawingsCommand.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:ui.KeyCode.ARROW_LEFT,priority:100,preconditions:whenSheetDrawingFocused,staticParameters:{direction:core.Direction.LEFT}},MoveDrawingRightShortcutItem={id:MoveDrawingsCommand.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:ui.KeyCode.ARROW_RIGHT,priority:100,preconditions:whenSheetDrawingFocused,staticParameters:{direction:core.Direction.RIGHT}},DeleteDrawingsShortcutItem={id:DeleteDrawingsCommand.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:whenSheetDrawingFocused,binding:ui.KeyCode.DELETE,mac:ui.KeyCode.BACKSPACE};var __defProp$6=Object.defineProperty,__getOwnPropDesc$6=Object.getOwnPropertyDescriptor,__decorateClass$6=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$6(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$6(target,key,result),result},"__decorateClass$6"),__decorateParam$6=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$6");const DefaultSheetsDrawingConfig={};let SheetDrawingUIController=(_c=class extends core.Disposable{constructor(_config,_injector,_componentManager,_menuService,_commandService,_shortcutService){super(),this._config=_config,this._injector=_injector,this._componentManager=_componentManager,this._menuService=_menuService,this._commandService=_commandService,this._shortcutService=_shortcutService,this._init()}_initCustomComponents(){const componentManager=this._componentManager;this.disposeWithMe(componentManager.register(IMAGE_UPLOAD_ICON,AddImageSingle)),this.disposeWithMe(componentManager.register(COMPONENT_UPLOAD_FILE_MENU,UploadFileMenu)),this.disposeWithMe(componentManager.register(COMPONENT_SHEET_DRAWING_PANEL,SheetDrawingPanel))}_initMenus(){const{menu={}}=this._config;[ImageMenuFactory,UploadFloatImageMenuFactory].forEach(menuFactory=>{this._menuService.addMenuItem(menuFactory(this._injector),menu)})}_initCommands(){[InsertFloatImageOperation,InsertCellImageOperation,InsertSheetDrawingCommand,RemoveSheetDrawingCommand,SetSheetDrawingCommand,SidebarSheetDrawingOperation,ClearSheetDrawingTransformerOperation,EditSheetDrawingOperation,GroupSheetDrawingCommand,UngroupSheetDrawingCommand,MoveDrawingsCommand,DeleteDrawingsCommand,SetDrawingArrangeCommand].forEach(command=>this.disposeWithMe(this._commandService.registerCommand(command)))}_initShortcuts(){[MoveDrawingDownShortcutItem,MoveDrawingUpShortcutItem,MoveDrawingLeftShortcutItem,MoveDrawingRightShortcutItem,DeleteDrawingsShortcutItem].forEach(item=>{this.disposeWithMe(this._shortcutService.registerShortcut(item))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}},__name(_c,"SheetDrawingUIController"),_c);SheetDrawingUIController=__decorateClass$6([core.OnLifecycle(core.LifecycleStages.Rendered,SheetDrawingUIController),__decorateParam$6(1,core.Inject(core.Injector)),__decorateParam$6(2,core.Inject(ui.ComponentManager)),__decorateParam$6(3,ui.IMenuService),__decorateParam$6(4,core.ICommandService),__decorateParam$6(5,ui.IShortcutService)],SheetDrawingUIController);var __defProp$5=Object.defineProperty,__getOwnPropDesc$5=Object.getOwnPropertyDescriptor,__decorateClass$5=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$5(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$5(target,key,result),result},"__decorateClass$5"),__decorateParam$5=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$5");const UPDATE_COMMANDS=[sheets.InsertRowCommand.id,sheets.InsertColCommand.id,sheets.RemoveRowCommand.id,sheets.RemoveColCommand.id,sheets.DeleteRangeMoveLeftCommand.id,sheets.DeleteRangeMoveUpCommand.id,sheets.InsertRangeMoveDownCommand.id,sheets.InsertRangeMoveRightCommand.id,sheets.DeltaRowHeightCommand.id,sheets.SetRowHeightCommand.id,sheets.DeltaColumnWidthCommand.id,sheets.SetColWidthCommand.id,sheets.SetRowHiddenCommand.id,sheets.SetSpecificRowsVisibleCommand.id,sheets.SetSpecificColsVisibleCommand.id,sheets.SetColHiddenCommand.id],REFRESH_MUTATIONS=[sheets.SetRowVisibleMutation.id,sheets.SetRowHiddenMutation.id,sheets.SetColVisibleMutation.id,sheets.SetColHiddenMutation.id,sheets.SetWorksheetRowHeightMutation.id,sheets.SetWorksheetColWidthMutation.id];let SheetDrawingTransformAffectedController=(_d=class extends core.Disposable{constructor(_context,_commandService,_selectionRenderService,_skeletonManagerService,_sheetInterceptorService,_sheetDrawingService,_drawingManagerService,_univerInstanceService){super(),this._context=_context,this._commandService=_commandService,this._selectionRenderService=_selectionRenderService,this._skeletonManagerService=_skeletonManagerService,this._sheetInterceptorService=_sheetInterceptorService,this._sheetDrawingService=_sheetDrawingService,this._drawingManagerService=_drawingManagerService,this._univerInstanceService=_univerInstanceService,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:__name(commandInfo=>{if(!UPDATE_COMMANDS.includes(commandInfo.id))return{redos:[],undos:[]};if(commandInfo.params==null)return{redos:[],undos:[]};const cId=commandInfo.id;if(cId===sheets.InsertRowCommand.id)return this._moveRowInterceptor(commandInfo.params,"insert");if(cId===sheets.InsertColCommand.id)return this._moveColInterceptor(commandInfo.params,"insert");if(cId===sheets.RemoveRowCommand.id)return this._moveRowInterceptor(commandInfo.params,"remove");if(cId===sheets.RemoveColCommand.id)return this._moveColInterceptor(commandInfo.params,"remove");if(cId===sheets.DeleteRangeMoveLeftCommand.id){const{range}=commandInfo.params;return this._getRangeMoveUndo(range,0)}else if(cId===sheets.DeleteRangeMoveUpCommand.id){const{range}=commandInfo.params;return this._getRangeMoveUndo(range,1)}else if(cId===sheets.InsertRangeMoveDownCommand.id){const{range}=commandInfo.params;return this._getRangeMoveUndo(range,2)}else if(cId===sheets.InsertRangeMoveRightCommand.id){const{range}=commandInfo.params;return this._getRangeMoveUndo(range,3)}else if(cId===sheets.SetRowHiddenCommand.id||cId===sheets.SetSpecificRowsVisibleCommand.id){const params=commandInfo.params,{unitId,subUnitId,ranges}=params;return this._getDrawingUndoForRowVisible(unitId,subUnitId,ranges)}else if(cId===sheets.SetSpecificColsVisibleCommand.id||cId===sheets.SetColHiddenCommand.id){const params=commandInfo.params,{unitId,subUnitId,ranges}=params;return this._getDrawingUndoForColVisible(unitId,subUnitId,ranges)}else if(cId===sheets.DeltaRowHeightCommand.id||cId===sheets.SetRowHeightCommand.id||cId===sheets.DeltaColumnWidthCommand.id||cId===sheets.SetColWidthCommand.id){const params=commandInfo.params,{unitId,subUnitId,ranges}=params,isRow=cId===sheets.DeltaRowHeightCommand.id||cId===sheets.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(unitId,subUnitId,ranges,isRow)}return{redos:[],undos:[]}},"getMutations")}))}_getRangeMoveUndo(range,type){const newParams=sheets.getSheetCommandTarget(this._univerInstanceService);if(newParams==null)return{redos:[],undos:[]};const unitId=newParams.unitId,subUnitId=newParams.subUnitId,redos=[],undos=[],drawingData=this._sheetDrawingService.getDrawingData(unitId,subUnitId),updateDrawings=[],deleteDrawings=[];if(Object.keys(drawingData).forEach(drawingId=>{const drawing2=drawingData[drawingId],{updateDrawings:updateDrawingsPart,deleteDrawings:deleteDrawingsPart}=this._getUpdateOrDeleteDrawings(range,type,drawing2);updateDrawings.push(...updateDrawingsPart),deleteDrawings.push(...deleteDrawingsPart)}),updateDrawings.length===0&&deleteDrawings.length===0)return{redos:[],undos:[]};if(updateDrawings.length>0){const updateJsonOp=this._sheetDrawingService.getBatchUpdateOp(updateDrawings),{undo,redo,objects}=updateJsonOp;redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:undo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}})}if(deleteDrawings.length>0){const deleteJsonOp=this._sheetDrawingService.getBatchRemoveOp(deleteDrawings),deleteUndo=deleteJsonOp.undo,deleteRedo=deleteJsonOp.redo,deleteObjects=deleteJsonOp.objects;redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:deleteRedo,objects:deleteObjects,type:sheetsDrawing.DrawingApplyType.REMOVE}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:deleteUndo,objects:deleteObjects,type:sheetsDrawing.DrawingApplyType.INSERT}})}return redos.push({id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}),undos.push({id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}),{redos,undos}}_getUpdateOrDeleteDrawings(range,type,drawing2){const updateDrawings=[],deleteDrawings=[],{sheetTransform,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position,transform,unitId,subUnitId,drawingId}=drawing2,{from,to}=sheetTransform,{row:fromRow,column:fromColumn}=from,{row:toRow,column:toColumn}=to;if(sheetTransform==null||transform==null)return{updateDrawings,deleteDrawings};const{startRow,endRow,startColumn,endColumn}=range;let newSheetTransform=null,newTransform=null;if(type===0&&fromRow>=startRow&&toRow<=endRow)if(fromColumn>=startColumn&&toColumn<=endColumn)deleteDrawings.push({unitId,subUnitId,drawingId});else{const param=this._shrinkCol(sheetTransform,transform,startColumn,endColumn,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}else if(type===1&&fromColumn>=startColumn&&toColumn<=endColumn)if(fromRow>=startRow&&toRow<=endRow)deleteDrawings.push({unitId,subUnitId,drawingId});else{const param=this._shrinkRow(sheetTransform,transform,startRow,endRow,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}else if(type===2){const param=this._expandRow(sheetTransform,transform,startRow,endRow,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}else if(type===3){const param=this._expandCol(sheetTransform,transform,startColumn,endColumn,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}if(newSheetTransform!=null&&newTransform!=null){const newTransform2=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService);updateDrawings.push({...drawing2,sheetTransform:newSheetTransform,transform:newTransform2})}return{updateDrawings,deleteDrawings}}_remainDrawingSize(transform,updateDrawings,drawing2){const newSheetTransform=transformToDrawingPosition({...transform},this._selectionRenderService);newSheetTransform!=null&&updateDrawings.push({...drawing2,sheetTransform:newSheetTransform})}_getDrawingUndoForColVisible(unitId,subUnitId,ranges){const drawingData=this._drawingManagerService.getDrawingData(unitId,subUnitId),updateDrawings=[],preUpdateDrawings=[];if(Object.keys(drawingData).forEach(drawingId=>{const drawing2=drawingData[drawingId],{sheetTransform,transform,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position}=drawing2;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)this._remainDrawingSize(transform,updateDrawings,drawing2);else{const{from,to}=sheetTransform,{row:fromRow,column:fromColumn}=from,{row:toRow,column:toColumn}=to;for(let i=0;i<ranges.length;i++){const range=ranges[i],{startRow,endRow,startColumn,endColumn}=range;if(toColumn<startColumn)continue;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Position){let newSheetTransform2=null,newTransform2=null;if(fromColumn>=startColumn&&fromColumn<=endColumn){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:fromColumn,endColumn,startRow:from.row,endRow:to.row});if(selectionCell==null)return;newTransform2={...transform,left:selectionCell.startX}}if(newTransform2!=null&&(newSheetTransform2=transformToDrawingPosition(newTransform2,this._selectionRenderService),newSheetTransform2!=null&&newTransform2!=null)){updateDrawings.push({...drawing2,sheetTransform:newSheetTransform2,transform:newTransform2});break}this._remainDrawingSize(transform,updateDrawings,drawing2);continue}if(fromColumn>=startColumn&&toColumn<=endColumn)continue;let newSheetTransform=null,newTransform=null;if(fromColumn>=startColumn&&fromColumn<=endColumn){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:fromColumn,endColumn,startRow:from.row,endRow:to.row});if(selectionCell==null)return;newTransform={...transform,left:(selectionCell==null?void 0:selectionCell.startX)||0,width:((transform==null?void 0:transform.width)||0)-selectionCell.endX+selectionCell.startX}}else if(toColumn>=startColumn&&toColumn<=endColumn){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn,endColumn:toColumn,startRow:from.row,endRow:to.row});if(selectionCell==null)return;newTransform={...transform,left:selectionCell.startX-((transform==null?void 0:transform.width)||0)}}else{const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn,endColumn,startRow:from.row,endRow:to.row});if(selectionCell==null)return;if(newTransform={...transform,width:((transform==null?void 0:transform.width)||0)-selectionCell.endX+selectionCell.startX},newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService),newSheetTransform!=null&&newTransform!=null){preUpdateDrawings.push({...drawing2,sheetTransform:newSheetTransform,transform:newTransform});break}}if(newTransform!=null&&(newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService)),newTransform!=null&&newSheetTransform!=null){updateDrawings.push({...drawing2,sheetTransform:newSheetTransform,transform:newTransform});break}else this._remainDrawingSize(transform,updateDrawings,drawing2)}}}),updateDrawings.length===0&&preUpdateDrawings.length===0)return{redos:[],undos:[]};const{redos,undos}=this._createUndoAndRedoMutation(unitId,subUnitId,updateDrawings),preRedos=[],preUndos=[];if(preUpdateDrawings.length>0){const{redos:redos2,undos:undos2}=this._createUndoAndRedoMutation(unitId,subUnitId,preUpdateDrawings);preRedos.push(...redos2),preUndos.push(...undos2)}return{redos,undos,preRedos,preUndos}}_createUndoAndRedoMutation(unitId,subUnitId,updateDrawings){const updateJsonOp=this._sheetDrawingService.getBatchUpdateOp(updateDrawings),{undo,redo,objects}=updateJsonOp,redos=[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}},{id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}],undos=[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:undo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}},{id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}];return{redos,undos}}_getDrawingUndoForRowVisible(unitId,subUnitId,ranges){const drawingData=this._drawingManagerService.getDrawingData(unitId,subUnitId),updateDrawings=[],preUpdateDrawings=[];if(Object.keys(drawingData).forEach(drawingId=>{const drawing2=drawingData[drawingId],{sheetTransform,transform,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position}=drawing2;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)this._remainDrawingSize(transform,updateDrawings,drawing2);else{const{from,to}=sheetTransform,{row:fromRow,column:fromColumn}=from,{row:toRow,column:toColumn}=to;for(let i=0;i<ranges.length;i++){const range=ranges[i],{startRow,endRow,startColumn,endColumn}=range;if(toRow<startRow)continue;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Position){let newSheetTransform2=null,newTransform2=null;if(fromRow>=startRow&&fromRow<=endRow){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:from.column,endColumn:to.column,startRow:fromRow,endRow});if(selectionCell==null)return;newTransform2={...transform,top:selectionCell.startY}}if(newTransform2!=null&&(newSheetTransform2=transformToDrawingPosition(newTransform2,this._selectionRenderService),newSheetTransform2!=null&&newTransform2!=null)){updateDrawings.push({...drawing2,sheetTransform:newSheetTransform2,transform:newTransform2});break}this._remainDrawingSize(transform,updateDrawings,drawing2);continue}if(fromRow>=startRow&&toRow<=endRow)continue;let newSheetTransform=null,newTransform=null;if(fromRow>=startRow&&fromRow<=endRow){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:from.column,endColumn:to.column,startRow:fromRow,endRow});if(selectionCell==null)return;newTransform={...transform,top:(selectionCell==null?void 0:selectionCell.startY)||0,height:((transform==null?void 0:transform.height)||0)-selectionCell.endY+selectionCell.startY}}else if(toRow>=startRow&&toRow<=endRow){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:from.column,endColumn:to.column,startRow,endRow:toRow});if(selectionCell==null)return;newTransform={...transform,top:selectionCell.startY-((transform==null?void 0:transform.height)||0)}}else{const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:from.column,endColumn:to.column,startRow,endRow});if(selectionCell==null)return;if(newTransform={...transform,height:((transform==null?void 0:transform.height)||0)-selectionCell.endY+selectionCell.startY},newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService),newSheetTransform!=null&&newTransform!=null){preUpdateDrawings.push({...drawing2,sheetTransform:newSheetTransform,transform:newTransform});break}}if(newTransform!=null&&(newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService)),newTransform!=null&&newSheetTransform!=null){updateDrawings.push({...drawing2,sheetTransform:newSheetTransform,transform:newTransform});break}else this._remainDrawingSize(transform,updateDrawings,drawing2)}}}),updateDrawings.length===0&&preUpdateDrawings.length===0)return{redos:[],undos:[]};const{redos,undos}=this._createUndoAndRedoMutation(unitId,subUnitId,updateDrawings),preRedos=[],preUndos=[];if(preUpdateDrawings.length>0){const{redos:redos2,undos:undos2}=this._createUndoAndRedoMutation(unitId,subUnitId,preUpdateDrawings);preRedos.push(...redos2),preUndos.push(...undos2)}return{redos,undos,preRedos,preUndos}}_getDrawingUndoForRowAndColSize(unitId,subUnitId,ranges,isRow){const drawingData=this._drawingManagerService.getDrawingData(unitId,subUnitId),updateDrawings=[];return Object.keys(drawingData).forEach(drawingId=>{const drawing2=drawingData[drawingId],{sheetTransform,transform,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position}=drawing2;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)this._remainDrawingSize(transform,updateDrawings,drawing2);else{const{from,to}=sheetTransform,{row:fromRow,column:fromColumn}=from,{row:toRow,column:toColumn}=to;for(let i=0;i<ranges.length;i++){const range=ranges[i],{startRow,endRow,startColumn,endColumn}=range;if(toRow<startRow||toColumn<startColumn)continue;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Position&&(fromRow<=startRow&&toRow>=endRow||fromColumn<=startColumn&&toColumn>=endColumn)){this._remainDrawingSize(transform,updateDrawings,drawing2);continue}const newTransform=drawingPositionToTransform({...sheetTransform},this._selectionRenderService,this._skeletonManagerService);if(newTransform!=null){updateDrawings.push({...drawing2,transform:newTransform});break}}}}),updateDrawings.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(unitId,subUnitId,updateDrawings)}_getUnitIdAndSubUnitId(params,type){let unitId,subUnitId;if(type==="insert")unitId=params.unitId,subUnitId=params.subUnitId;else{const newParams=sheets.getSheetCommandTarget(this._univerInstanceService);if(newParams==null)return;unitId=newParams.unitId,subUnitId=newParams.subUnitId}return{unitId,subUnitId}}_moveRowInterceptor(params,type){const ids=this._getUnitIdAndSubUnitId(params,type);if(ids==null)return{redos:[],undos:[]};const{unitId,subUnitId}=ids,{range}=params,rowStartIndex=range.startRow,rowEndIndex=range.endRow,redos=[],undos=[],data=this._sheetDrawingService.getDrawingData(unitId,subUnitId),updateDrawings=[],deleteDrawings=[];if(Object.keys(data).forEach(drawingId=>{const drawing2=data[drawingId],{sheetTransform,transform,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position}=drawing2;if(sheetTransform==null||transform==null)return;let newSheetTransform,newTransform;if(type==="insert"){const param=this._expandRow(sheetTransform,transform,rowStartIndex,rowEndIndex,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}else{const{from,to}=sheetTransform,{row:fromRow}=from,{row:toRow}=to;if(fromRow>=rowStartIndex&&toRow<=rowEndIndex)deleteDrawings.push({unitId,subUnitId,drawingId});else{const param=this._shrinkRow(sheetTransform,transform,rowStartIndex,rowEndIndex,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}}if(!newSheetTransform||!newTransform)return;const params2={unitId,subUnitId,drawingId,transform:newTransform,sheetTransform:newSheetTransform};updateDrawings.push(params2)}),updateDrawings.length===0&&deleteDrawings.length===0)return{redos:[],undos:[]};if(updateDrawings.length>0){const updateJsonOp=this._sheetDrawingService.getBatchUpdateOp(updateDrawings),{undo,redo,objects}=updateJsonOp;redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:undo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}})}if(deleteDrawings.length>0){const deleteJsonOp=this._sheetDrawingService.getBatchRemoveOp(deleteDrawings),deleteUndo=deleteJsonOp.undo,deleteRedo=deleteJsonOp.redo,deleteObjects=deleteJsonOp.objects;redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:deleteRedo,objects:deleteObjects,type:sheetsDrawing.DrawingApplyType.REMOVE}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:deleteUndo,objects:deleteObjects,type:sheetsDrawing.DrawingApplyType.INSERT}})}return redos.push({id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}),undos.push({id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}),{redos,undos}}_moveColInterceptor(params,type){const ids=this._getUnitIdAndSubUnitId(params,type);if(ids==null)return{redos:[],undos:[]};const{unitId,subUnitId}=ids,{range}=params,colStartIndex=range.startColumn,colEndIndex=range.endColumn,redos=[],undos=[],data=this._sheetDrawingService.getDrawingData(unitId,subUnitId),updateDrawings=[],deleteDrawings=[];if(Object.keys(data).forEach(drawingId=>{const drawing2=data[drawingId],{sheetTransform,transform,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position}=drawing2;if(sheetTransform==null||transform==null)return;let newSheetTransform,newTransform;if(type==="insert"){const param=this._expandCol(sheetTransform,transform,colStartIndex,colEndIndex,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}else{const{from,to}=sheetTransform,{column:fromColumn}=from,{column:toColumn}=to;if(fromColumn>=colStartIndex&&toColumn<=colEndIndex)deleteDrawings.push({unitId,subUnitId,drawingId});else{const param=this._shrinkCol(sheetTransform,transform,colStartIndex,colEndIndex,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}}if(!newSheetTransform||!newTransform)return;const params2={unitId,subUnitId,drawingId,transform:newTransform,sheetTransform:newSheetTransform};updateDrawings.push(params2)}),updateDrawings.length===0&&deleteDrawings.length===0)return{redos:[],undos:[]};if(updateDrawings.length>0){const updateJsonOp=this._sheetDrawingService.getBatchUpdateOp(updateDrawings),{undo,redo,objects}=updateJsonOp;redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:undo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}})}if(deleteDrawings.length>0){const deleteJsonOp=this._sheetDrawingService.getBatchRemoveOp(deleteDrawings),deleteUndo=deleteJsonOp.undo,deleteRedo=deleteJsonOp.redo,deleteObjects=deleteJsonOp.objects;redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:deleteRedo,objects:deleteObjects,type:sheetsDrawing.DrawingApplyType.REMOVE}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:deleteUndo,objects:deleteObjects,type:sheetsDrawing.DrawingApplyType.INSERT}})}return redos.push({id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}),undos.push({id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}),{redos,undos}}_expandCol(sheetTransform,transform,colStartIndex,colEndIndex,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position){const colCount=colEndIndex-colStartIndex+1,{from,to}=sheetTransform,{column:fromColumn}=from,{column:toColumn}=to;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};let newSheetTransform=null,newTransform=null;if(fromColumn>=colStartIndex){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:colStartIndex,endColumn:colEndIndex,startRow:from.row,endRow:to.row});if(selectionCell==null)return;newTransform={...transform,left:(transform.left||0)+selectionCell.endX-selectionCell.startX},newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService)}else if(toColumn>=colEndIndex)if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Both)newSheetTransform={from:{...from},to:{...to,column:toColumn+colCount}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};return newSheetTransform!=null&&newTransform!=null?{newSheetTransform,newTransform}:null}_shrinkCol(sheetTransform,transform,colStartIndex,colEndIndex,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position){const colCount=colEndIndex-colStartIndex+1,{from,to}=sheetTransform,{column:fromColumn}=from,{column:toColumn}=to;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};let newSheetTransform=null,newTransform=null;if(fromColumn>colEndIndex)newSheetTransform={from:{...from,column:fromColumn-colCount},to:{...to,column:toColumn-colCount}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService);else{if(fromColumn>=colStartIndex&&toColumn<=colEndIndex)return null;if(fromColumn<colStartIndex&&toColumn>colEndIndex)if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Both)newSheetTransform={from:{...from},to:{...to,column:toColumn-colCount}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};else if(fromColumn>=colStartIndex&&fromColumn<=colEndIndex){if(fromColumn===colStartIndex)newTransform={...transform,left:(transform.left||0)-sheetTransform.from.columnOffset};else{const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:colStartIndex,endColumn:fromColumn-1,startRow:from.row,endRow:to.row});if(selectionCell==null)return;newTransform={...transform,left:(transform.left||0)-selectionCell.endX+selectionCell.startX-sheetTransform.from.columnOffset}}newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService)}else if(toColumn>=colStartIndex&&toColumn<=colEndIndex&&anchorType===sheetsDrawing.SheetDrawingAnchorType.Both){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:colStartIndex-1,endColumn:colStartIndex-1,startRow:from.row,endRow:to.row});if(selectionCell==null)return;newSheetTransform={from:{...from},to:{...to,column:colStartIndex-1,columnOffset:selectionCell.endX-selectionCell.startX}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService)}}return newSheetTransform!=null&&newTransform!=null?{newSheetTransform,newTransform}:null}_expandRow(sheetTransform,transform,rowStartIndex,rowEndIndex,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position){const rowCount=rowEndIndex-rowStartIndex+1,{from,to}=sheetTransform,{row:fromRow}=from,{row:toRow}=to;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};let newSheetTransform=null,newTransform=null;if(fromRow>=rowStartIndex){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startRow:rowStartIndex,endRow:rowEndIndex,startColumn:from.column,endColumn:to.column});if(selectionCell==null)return;newTransform={...transform,top:(transform.top||0)+selectionCell.endY-selectionCell.startY},newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService)}else if(toRow>=rowEndIndex)if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Both)newSheetTransform={from:{...from},to:{...to,row:toRow+rowCount}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};return newSheetTransform!=null&&newTransform!=null?{newSheetTransform,newTransform}:null}_shrinkRow(sheetTransform,transform,rowStartIndex,rowEndIndex,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position){const rowCount=rowEndIndex-rowStartIndex+1,{from,to}=sheetTransform,{row:fromRow}=from,{row:toRow}=to;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};let newSheetTransform=null,newTransform=null;if(fromRow>rowEndIndex)newSheetTransform={from:{...from,row:fromRow-rowCount},to:{...to,row:toRow-rowCount}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService);else{if(fromRow>=rowStartIndex&&toRow<=rowEndIndex)return null;if(fromRow<rowStartIndex&&toRow>rowEndIndex)if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Both)newSheetTransform={from:{...from},to:{...to,row:toRow-rowCount}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};else if(fromRow>=rowStartIndex&&fromRow<=rowEndIndex){if(fromRow===rowStartIndex)newTransform={...transform,top:(transform.top||0)-sheetTransform.from.rowOffset};else{const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startRow:rowStartIndex,endRow:fromRow-1,startColumn:from.column,endColumn:to.column});if(selectionCell==null)return;newTransform={...transform,top:(transform.top||0)-selectionCell.endY+selectionCell.startY-sheetTransform.from.rowOffset}}newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService)}else if(toRow>=rowStartIndex&&toRow<=rowEndIndex&&anchorType===sheetsDrawing.SheetDrawingAnchorType.Both){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:from.column,endColumn:from.column,startRow:rowStartIndex-1,endRow:rowStartIndex-1});if(selectionCell==null)return;newSheetTransform={from:{...from},to:{...to,row:rowStartIndex-1,rowOffset:selectionCell.endY-selectionCell.startY}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService)}}return newSheetTransform!=null&&newTransform!=null?{newSheetTransform,newTransform}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(command=>{command.id===sheets.SetWorksheetActiveOperation.id&&setTimeout(()=>{const params=command.params,{unitId:showUnitId,subUnitId:showSubunitId}=params,drawingMap=this._drawingManagerService.drawingManagerData,insertDrawings=[],removeDrawings=[];Object.keys(drawingMap).forEach(unitId=>{const subUnitMap=drawingMap[unitId];Object.keys(subUnitMap).forEach(subUnitId=>{const drawingData=subUnitMap[subUnitId].data;drawingData!=null&&Object.keys(drawingData).forEach(drawingId=>{if(unitId===showUnitId&&subUnitId===showSubunitId){const drawing2=drawingData[drawingId];drawing2.transform=drawingPositionToTransform(drawing2.sheetTransform,this._selectionRenderService,this._skeletonManagerService),insertDrawings.push(drawingData[drawingId])}else removeDrawings.push(drawingData[drawingId])})})}),this._drawingManagerService.removeNotification(removeDrawings),this._drawingManagerService.addNotification(insertDrawings)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(command=>{REFRESH_MUTATIONS.includes(command.id)&&requestIdleCallback(()=>{const params=command.params,{unitId,subUnitId,ranges}=params;this._refreshDrawingTransform(unitId,subUnitId,ranges)})}))}_refreshDrawingTransform(unitId,subUnitId,ranges){const drawingData=this._drawingManagerService.getDrawingData(unitId,subUnitId),updateDrawings=[];Object.keys(drawingData).forEach(drawingId=>{const drawing2=drawingData[drawingId],{sheetTransform,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position}=drawing2;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)return!0;const{from,to}=sheetTransform,{row:fromRow,column:fromColumn}=from,{row:toRow,column:toColumn}=to;for(let i=0;i<ranges.length;i++){const range=ranges[i],{startRow,endRow,startColumn,endColumn}=range;if(core.Rectangle.intersects({startRow,endRow,startColumn,endColumn},{startRow:fromRow,endRow:toRow,startColumn:fromColumn,endColumn:toColumn})||fromRow>endRow||fromColumn>endColumn){updateDrawings.push({...drawing2,transform:drawingPositionToTransform(sheetTransform,this._selectionRenderService,this._skeletonManagerService)});break}}}),updateDrawings.length!==0&&(this._drawingManagerService.refreshTransform(updateDrawings),this._commandService.syncExecuteCommand(ClearSheetDrawingTransformerOperation.id,[unitId]))}},__name(_d,"SheetDrawingTransformAffectedController"),_d);SheetDrawingTransformAffectedController=__decorateClass$5([__decorateParam$5(1,core.ICommandService),__decorateParam$5(2,sheetsUi.ISheetSelectionRenderService),__decorateParam$5(3,core.Inject(sheetsUi.SheetSkeletonManagerService)),__decorateParam$5(4,core.Inject(sheets.SheetInterceptorService)),__decorateParam$5(5,sheetsDrawing.ISheetDrawingService),__decorateParam$5(6,drawing.IDrawingManagerService),__decorateParam$5(7,core.IUniverInstanceService)],SheetDrawingTransformAffectedController);var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4");function transformBound2DOMBound(originBound,scene,skeleton,worksheet){const{scaleX,scaleY}=scene.getAncestorScale(),viewMain=scene.getViewport(engineRender.SHEET_VIEWPORT_KEY.VIEW_MAIN),absolute={left:!0,top:!0};if(!viewMain)return{...originBound,absolute};const{left,right,top,bottom}=originBound,freeze=worksheet.getFreeze(),{startColumn,startRow,xSplit,ySplit}=freeze,startSheetView=skeleton.getNoMergeCellPositionByIndexWithNoHeader(startRow-ySplit,startColumn-xSplit),endSheetView=skeleton.getNoMergeCellPositionByIndexWithNoHeader(startRow,startColumn),{rowHeaderWidth,columnHeaderHeight}=skeleton,freezeWidth=endSheetView.startX-startSheetView.startX,freezeHeight=endSheetView.startY-startSheetView.startY,{top:freezeTop,left:freezeLeft,viewportScrollX:actualScrollX,viewportScrollY:actualScrollY}=viewMain;let offsetLeft,offsetRight;left<freezeLeft?(absolute.left=!0,offsetLeft=(freezeWidth+rowHeaderWidth+(left-freezeLeft))*scaleX,offsetRight=Math.max(Math.min((freezeWidth+rowHeaderWidth+(right-freezeLeft))*scaleX,(freezeWidth+rowHeaderWidth)*scaleX),(right-actualScrollX)*scaleX)):(absolute.left=!1,offsetLeft=Math.max((left-actualScrollX)*scaleX,(freezeWidth+rowHeaderWidth)*scaleX),offsetRight=Math.max((right-actualScrollX)*scaleX,(freezeWidth+rowHeaderWidth)*scaleX));let offsetTop,offsetBottom;return top<freezeTop?(absolute.top=!0,offsetTop=(freezeHeight+columnHeaderHeight+(top-freezeTop))*scaleY,offsetBottom=Math.max(Math.min((freezeHeight+columnHeaderHeight+(right-freezeTop))*scaleY,(freezeHeight+columnHeaderHeight)*scaleY),(bottom-actualScrollY)*scaleY)):(absolute.top=!1,offsetTop=Math.max((top-actualScrollY)*scaleY,(freezeHeight+columnHeaderHeight)*scaleY),offsetBottom=Math.max((bottom-actualScrollY)*scaleY,(freezeHeight+columnHeaderHeight)*scaleY)),{left:offsetLeft,right:offsetRight,top:offsetTop,bottom:offsetBottom,absolute}}__name(transformBound2DOMBound,"transformBound2DOMBound");const calcPosition=__name((targetObject,currentRender,skeleton,worksheet)=>{const{scene}=currentRender,{left,top,width,height,angle}=targetObject,bound={left,right:left+width,top,bottom:top+height},offsetBound=transformBound2DOMBound(bound,scene,skeleton,worksheet);return{startX:offsetBound.left,endX:offsetBound.right,startY:offsetBound.top,endY:offsetBound.bottom,rotate:angle,width,height,absolute:offsetBound.absolute}},"calcPosition");exports2.SheetCanvasFloatDomManagerService=(_e=class extends core.Disposable{constructor(_renderManagerService,_univerInstanceService,_commandService,_drawingManagerService,_canvasFloatDomService,_sheetDrawingService){super();__publicField(this,"_domLayerMap",new Map);__publicField(this,"_domLayerInfoMap",new Map);__publicField(this,"_transformChange$",new rxjs.Subject);__publicField(this,"transformChange$",this._transformChange$.asObservable());__publicField(this,"_remove$",new rxjs.Subject);__publicField(this,"remove$",this._remove$.asObservable());__publicField(this,"_hooks",[]);this._renderManagerService=_renderManagerService,this._univerInstanceService=_univerInstanceService,this._commandService=_commandService,this._drawingManagerService=_drawingManagerService,this._canvasFloatDomService=_canvasFloatDomService,this._sheetDrawingService=_sheetDrawingService,this._drawingAddListener(),this._scrollUpdateListener(),this._featureUpdateListener(),this._deleteListener()}_ensureMap(unitId,subUnitId){let unitMap=this._domLayerMap.get(unitId);unitMap||(unitMap=new Map,this._domLayerMap.set(unitId,unitMap));let subUnitMap=unitMap.get(subUnitId);return subUnitMap||(subUnitMap=new Map,unitMap.set(subUnitId,subUnitMap)),subUnitMap}_getSceneAndTransformerByDrawingSearch(unitId){if(unitId==null)return;const renderObject=this._renderManagerService.getRenderById(unitId),scene=renderObject==null?void 0:renderObject.scene;if(renderObject==null||scene==null)return null;const transformer=scene.getTransformerByCreate(),canvas=renderObject.engine.getCanvasElement();return{scene,transformer,renderObject,canvas}}_getFloatDomProps(id){let props;return this._hooks.forEach(hook=>{props=hook.onGetFloatDomProps(id)}),props}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(params=>{params.forEach(param=>{var _a2,_b2,_c2;const{unitId,subUnitId,drawingId}=param,target=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId,subUnitId}),floatDomParam=this._drawingManagerService.getDrawingByParam(param),skeleton=(_a2=this._renderManagerService.getRenderById(unitId))==null?void 0:_a2.with(sheetsUi.SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId);if(floatDomParam==null||target==null||skeleton==null)return;const{transform,drawingType,data}=floatDomParam;if(drawingType!==core.DrawingTypeEnum.DRAWING_DOM)return;const renderObject=this._getSceneAndTransformerByDrawingSearch(unitId);if(renderObject==null)return;const{scene,canvas}=renderObject;if(transform==null)return!0;const{left,top,width,height,angle,flipX,flipY,skewX,skewY}=transform,rectShapeKey=drawing.getDrawingShapeKeyByDrawingSearch({unitId,subUnitId,drawingId}),rectShape=scene.getObject(rectShapeKey);if(rectShape!=null){rectShape.transformByState({left,top,width,height,angle,flipX,flipY,skewX,skewY});return}const imageConfig={left,top,width,height,zIndex:this._drawingManagerService.getDrawingOrder(unitId,subUnitId).length-1},rect=new engineRender.Rect(rectShapeKey,imageConfig);scene.addObject(rect,engineRender.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(rect);const map=this._ensureMap(unitId,subUnitId),disposableCollection=new core.DisposableCollection,initPosition=calcPosition(rect,renderObject.renderObject,skeleton.skeleton,target.worksheet),position$=new rxjs.BehaviorSubject(initPosition),info={dispose:disposableCollection,rect,position$,unitId,subUnitId};this._canvasFloatDomService.addFloatDom({position$,id:drawingId,componentKey:floatDomParam.componentKey,onPointerDown:__name(evt=>{canvas.dispatchEvent(new PointerEvent(evt.type,evt))},"onPointerDown"),onPointerMove:__name(evt=>{canvas.dispatchEvent(new PointerEvent(evt.type,evt))},"onPointerMove"),onPointerUp:__name(evt=>{canvas.dispatchEvent(new PointerEvent(evt.type,evt))},"onPointerUp"),onWheel:__name(evt=>{canvas.dispatchEvent(new WheelEvent(evt.type,evt))},"onWheel"),props:(_c2=(_b2=map.get(drawingId))==null?void 0:_b2.props)!=null?_c2:this._getFloatDomProps(drawingId),data});const listener=rect.onTransformChange$.subscribeEvent(()=>{const newPosition=calcPosition(rect,renderObject.renderObject,skeleton.skeleton,target.worksheet);position$.next(newPosition)});disposableCollection.add(()=>{this._canvasFloatDomService.removeFloatDom(drawingId)}),listener&&disposableCollection.add(listener),this._domLayerInfoMap.set(drawingId,info),map.set(drawingId,{...map.get(drawingId)})})}))}_scrollUpdateListener(){this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{var _a2,_b2;const updateSheet=__name((unitId,subUnitId)=>{var _a3;const renderObject=this._getSceneAndTransformerByDrawingSearch(unitId),map=this._ensureMap(unitId,subUnitId),ids=Array.from(map.keys()),target=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId,subUnitId}),skeleton=(_a3=this._renderManagerService.getRenderById(unitId))==null?void 0:_a3.with(sheetsUi.SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId);!renderObject||!target||!skeleton||ids.forEach(id=>{const info=this._domLayerInfoMap.get(id);if(info){const position=calcPosition(info.rect,renderObject.renderObject,skeleton.skeleton,target.worksheet);info.position$.next(position)}})},"updateSheet");if(commandInfo.id===sheetsUi.SetScrollOperation.id){const params=commandInfo.params,{unitId,sheetId}=params;updateSheet(unitId,sheetId)}else if(commandInfo.id===sheetsUi.SetZoomRatioOperation.id){const params=commandInfo.params,{unitId}=params;Array.from((_b2=(_a2=this._domLayerMap.get(unitId))==null?void 0:_a2.keys())!=null?_b2:[]).forEach(subUnitId=>{updateSheet(unitId,subUnitId)})}else if(commandInfo.id===sheets.SetFrozenMutation.id){const{unitId,subUnitId}=commandInfo.params;updateSheet(unitId,subUnitId)}}))}_getPosition(position,unitId){var _a2;const{startX,endX,startY,endY}=position,selectionRenderService=(_a2=this._renderManagerService.getRenderById(unitId))==null?void 0:_a2.with(sheetsUi.ISheetSelectionRenderService);if(selectionRenderService==null)return;const start=selectionRenderService.getSelectionCellByPosition(startX,startY);if(start==null)return;const from={column:start.actualColumn,columnOffset:startX-start.startX,row:start.actualRow,rowOffset:startY-start.startY},end=selectionRenderService.getSelectionCellByPosition(endX,endY);if(end==null)return;const to={column:end.actualColumn,columnOffset:endX-end.startX,row:end.actualRow,rowOffset:endY-end.startY};return{from,to}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(params=>{params.forEach(data=>{const sheetDrawing=this._drawingManagerService.getDrawingByParam(data);if(!sheetDrawing||sheetDrawing.drawingType!==core.DrawingTypeEnum.DRAWING_DOM)return;const newValue={...sheetDrawing.transform};this._transformChange$.next({id:data.drawingId,value:newValue})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(params=>{params.forEach(param=>{this._removeDom(param.drawingId)})}))}addFloatDomToPosition(layer){const target=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId:layer.unitId,subUnitId:layer.subUnitId});if(!target)throw new Error("cannot find current target!");const{unitId,subUnitId}=target,{initPosition,componentKey,data}=layer,id=core.Tools.generateRandomId(),sheetTransform=this._getPosition(initPosition,unitId);if(sheetTransform==null)return;this._ensureMap(unitId,subUnitId).set(id,layer);const sheetDrawingParam={unitId,subUnitId,drawingId:id,drawingType:core.DrawingTypeEnum.DRAWING_DOM,componentKey,sheetTransform,transform:{left:initPosition.startX,top:initPosition.startY,width:initPosition.endX-initPosition.startX,height:initPosition.endY-initPosition.startY},data};return this._commandService.executeCommand(InsertSheetDrawingCommand.id,{unitId,drawings:[sheetDrawingParam]}),{id,dispose:__name(()=>{this._removeDom(id,!0)},"dispose")}}_removeDom(id,removeDrawing=!1){const info=this._domLayerInfoMap.get(id);if(!info)return;const{unitId,subUnitId}=info;this._domLayerInfoMap.delete(id),info.dispose.dispose();const renderObject=this._getSceneAndTransformerByDrawingSearch(unitId);if(renderObject&&renderObject.scene.removeObject(info.rect),removeDrawing){this._ensureMap(unitId,subUnitId).delete(id);const param=this._drawingManagerService.getDrawingByParam({unitId,subUnitId,drawingId:id});if(!param)return;const jsonOp=this._sheetDrawingService.getBatchRemoveOp([param]),{redo,objects}=jsonOp;this._commandService.syncExecuteCommand(sheetsDrawing.SetDrawingApplyMutation.id,{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.REMOVE})}}addHook(hook){return this._hooks.push(hook),{dispose:__name(()=>{const index=this._hooks.findIndex(h=>h===hook);this._hooks.splice(index,1)},"dispose")}}},__name(_e,"SheetCanvasFloatDomManagerService"),_e),exports2.SheetCanvasFloatDomManagerService=__decorateClass$4([core.OnLifecycle(core.LifecycleStages.Starting,exports2.SheetCanvasFloatDomManagerService),__decorateParam$4(0,core.Inject(engineRender.IRenderManagerService)),__decorateParam$4(1,core.IUniverInstanceService),__decorateParam$4(2,core.Inject(core.ICommandService)),__decorateParam$4(3,drawing.IDrawingManagerService),__decorateParam$4(4,core.Inject(ui.CanvasFloatDomService)),__decorateParam$4(5,sheetsDrawing.ISheetDrawingService)],exports2.SheetCanvasFloatDomManagerService);var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3");let SheetDrawingPrintingController=(_f=class extends core.Disposable{constructor(_sheetPrintInterceptorService,_drawingRenderService,_drawingManagerService,_renderManagerService){super(),this._sheetPrintInterceptorService=_sheetPrintInterceptorService,this._drawingRenderService=_drawingRenderService,this._drawingManagerService=_drawingManagerService,this._renderManagerService=_renderManagerService,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:__name((_param,pos,next)=>{const{unitId,scene,subUnitId}=pos,unitData=this._drawingManagerService.getDrawingDataForUnit(unitId),subUnitData=unitData==null?void 0:unitData[subUnitId];return subUnitData&&subUnitData.order.forEach(id=>{this._drawingRenderService.renderDrawing(subUnitData.data[id],scene)}),next()},"handler")})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:__name((range,pos,next)=>{const{unitId,subUnitId}=pos,renderer=this._renderManagerService.getRenderById(unitId);if(!renderer)return next(range);const skeleton=renderer.with(sheetsUi.SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId);if(!skeleton)return next(range);const unitData=this._drawingManagerService.getDrawingDataForUnit(unitId),subUnitData=unitData==null?void 0:unitData[pos.subUnitId];if(!subUnitData)return next(range);const{scaleX,scaleY}=renderer.scene,newRange=range?{...range}:{startColumn:0,endColumn:0,endRow:0,startRow:0},data=subUnitData.order.map(key=>subUnitData.data[key]).filter(item=>item.drawingType!==drawing.DrawingTypeEnum.DRAWING_DOM);return data.length?(data.forEach(param=>{if(!param.groupId&¶m.transform&&core.Tools.isDefine(param.transform.left)&&core.Tools.isDefine(param.transform.top)&&core.Tools.isDefine(param.transform.width)&&core.Tools.isDefine(param.transform.height)){const start=skeleton.skeleton.getCellPositionByOffset(param.transform.left,param.transform.top,scaleX,scaleY,{x:0,y:0}),end=skeleton.skeleton.getCellPositionByOffset(param.transform.left+param.transform.width,param.transform.top+param.transform.height,scaleX,scaleY,{x:0,y:0});start.column<newRange.startColumn&&(newRange.startColumn=start.column),start.row<newRange.startRow&&(newRange.startRow=start.row),newRange.endRow<end.row&&(newRange.endRow=end.row),newRange.endColumn<end.column&&(newRange.endColumn=end.column)}}),next(newRange)):next(range)},"handler")}))}},__name(_f,"SheetDrawingPrintingController"),_f);SheetDrawingPrintingController=__decorateClass$3([core.OnLifecycle(core.LifecycleStages.Rendered,SheetDrawingPrintingController),__decorateParam$3(0,core.Inject(sheetsUi.SheetPrintInterceptorService)),__decorateParam$3(1,core.Inject(drawingUi.DrawingRenderService)),__decorateParam$3(2,drawing.IDrawingManagerService),__decorateParam$3(3,engineRender.IRenderManagerService)],SheetDrawingPrintingController);var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");let SheetDrawingPermissionController=(_g=class extends core.Disposable{constructor(_drawingManagerService,_renderManagerService,_permissionService,_univerInstanceService,_userManagerService){super(),this._drawingManagerService=_drawingManagerService,this._renderManagerService=_renderManagerService,this._permissionService=_permissionService,this._univerInstanceService=_univerInstanceService,this._userManagerService=_userManagerService,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const workbook$=this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(rxjs.combineLatest([workbook$,this._userManagerService.currentUser$]).subscribe(([workbook,_])=>{if(!workbook){this._drawingManagerService.setDrawingVisible(!1);return}workbook.activeSheet$.subscribe(sheet=>{if(!sheet){this._drawingManagerService.setDrawingVisible(!1);return}const unitId=workbook.getUnitId(),subUnitId=sheet.getSheetId();if(this._permissionService.composePermission([new sheets.WorkbookViewPermission(unitId).id,new sheets.WorksheetViewPermission(unitId,subUnitId).id]).every(permission=>permission.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const unitId2=workbook.getUnitId(),subUnitId2=sheet.getSheetId(),drawingData=this._drawingManagerService.getDrawingData(unitId2,subUnitId2),drawingDataValues=Object.values(drawingData),renderObject=this._renderManagerService.getRenderById(unitId2),scene=renderObject==null?void 0:renderObject.scene;if(scene==null)return;scene.getAllObjects().forEach(object=>{object.classType===engineRender.RENDER_CLASS_TYPE.IMAGE&&drawingDataValues.some(item=>object.oKey.includes(item.drawingId))&&scene.removeObject(object)})}})}))}_initDrawingEditable(){const workbook$=this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(rxjs.combineLatest([workbook$,this._userManagerService.currentUser$]).subscribe(([workbook,_])=>{if(!workbook){this._drawingManagerService.setDrawingEditable(!1);return}workbook.activeSheet$.subscribe(sheet=>{if(!sheet){this._drawingManagerService.setDrawingEditable(!1);return}const unitId=workbook.getUnitId(),subUnitId=sheet.getSheetId();if(this._permissionService.composePermission([new sheets.WorkbookEditablePermission(unitId).id,new sheets.WorksheetEditPermission(unitId,subUnitId).id]).every(permission=>permission.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const unitId2=workbook.getUnitId(),subUnitId2=sheet.getSheetId(),drawingData=this._drawingManagerService.getDrawingData(unitId2,subUnitId2),drawingDataValues=Object.values(drawingData),renderObject=this._renderManagerService.getRenderById(unitId2),scene=renderObject==null?void 0:renderObject.scene;if(scene==null)return;scene.getAllObjects().forEach(object=>{object.classType===engineRender.RENDER_CLASS_TYPE.IMAGE&&drawingDataValues.some(item=>object.oKey.includes(item.drawingId))&&scene.detachTransformerFrom(object)})}})}))}_initViewPermissionChange(){const workbook$=this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(rxjs.combineLatest([workbook$,this._userManagerService.currentUser$]).subscribe(([workbook,_])=>{workbook&&workbook.activeSheet$.subscribe(sheet=>{var _a2;if(!sheet)return;const unitId=workbook.getUnitId(),subUnitId=sheet.getSheetId();let initialViewPermission=!0;const renderObject=this._renderManagerService.getRenderById(unitId),scene=renderObject==null?void 0:renderObject.scene;if(scene==null)return;const transformer=scene.getTransformerByCreate(),worksheetViewPermission$=this._permissionService.composePermission$([new sheets.WorkbookViewPermission(unitId).id,new sheets.WorksheetViewPermission(unitId,subUnitId).id]).pipe(rxjs.map(permissions=>permissions.every(item=>item.value)));worksheetViewPermission$==null||worksheetViewPermission$.pipe(rxjs.filter(permission=>permission!==initialViewPermission),rxjs.distinctUntilChanged()).subscribe({next:__name(permission=>{initialViewPermission=permission,this._drawingManagerService.setDrawingVisible(permission);const objects=scene.getAllObjects(),drawingData=this._drawingManagerService.getDrawingData(unitId,subUnitId),drawingDataValues=Object.values(drawingData);permission?this._drawingManagerService.addNotification(drawingDataValues):(objects.forEach(object=>{object.classType===engineRender.RENDER_CLASS_TYPE.IMAGE&&drawingDataValues.some(item=>object.oKey.includes(item.drawingId))&&scene.removeObject(object)}),transformer.clearSelectedObjects())},"next")}),(_a2=this._permissionService.getPermissionPoint$(new sheets.WorksheetViewPermission(unitId,subUnitId).id))==null||_a2.pipe(rxjs.filter(permission=>permission.value!==initialViewPermission),rxjs.distinctUntilChanged()).subscribe({complete:__name(()=>{initialViewPermission=!0,this._drawingManagerService.setDrawingVisible(!0);const drawingData=this._drawingManagerService.getDrawingData(unitId,subUnitId),drawingDataValues=Object.values(drawingData);this._drawingManagerService.addNotification(drawingDataValues)},"complete")})})}))}_initEditPermissionChange(){const workbook$=this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(rxjs.combineLatest([workbook$,this._userManagerService.currentUser$]).subscribe(([workbook,_])=>{workbook&&workbook.activeSheet$.subscribe(sheet=>{var _a2;if(!sheet)return;const unitId=workbook.getUnitId(),subUnitId=sheet.getSheetId();let initialEditPermission=!0;const renderObject=this._renderManagerService.getRenderById(unitId),scene=renderObject==null?void 0:renderObject.scene;if(scene==null)return;const transformer=scene.getTransformerByCreate(),composeWorksheetEditPermission=this._permissionService.composePermission$([new sheets.WorkbookEditablePermission(unitId).id,new sheets.WorksheetEditPermission(unitId,subUnitId).id]).pipe(rxjs.map(permissions=>permissions.every(item=>item.value)));composeWorksheetEditPermission==null||composeWorksheetEditPermission.pipe(rxjs.filter(permission=>permission!==initialEditPermission),rxjs.distinctUntilChanged()).subscribe({next:__name(permission=>{initialEditPermission=permission,this._drawingManagerService.setDrawingEditable(permission);const objects=scene.getAllObjects(),drawingData=this._drawingManagerService.getDrawingData(unitId,subUnitId),drawingDataValues=Object.values(drawingData);permission?(objects.forEach(object=>{object.classType===engineRender.RENDER_CLASS_TYPE.IMAGE&&drawingDataValues.some(item=>object.oKey.includes(item.drawingId))&&scene.attachTransformerTo(object)}),this._drawingManagerService.addNotification(drawingDataValues)):(objects.forEach(object=>{object.classType===engineRender.RENDER_CLASS_TYPE.IMAGE&&drawingDataValues.some(item=>object.oKey.includes(item.drawingId))&&scene.detachTransformerFrom(object)}),transformer.clearSelectedObjects())},"next")}),(_a2=this._permissionService.getPermissionPoint$(new sheets.WorksheetEditPermission(unitId,subUnitId).id))==null||_a2.pipe(rxjs.filter(permission=>permission.value!==initialEditPermission),rxjs.distinctUntilChanged()).subscribe({complete:__name(()=>{initialEditPermission=!0;const unitId2=workbook.getUnitId(),subUnitId2=sheet.getSheetId(),drawingData=this._drawingManagerService.getDrawingData(unitId2,subUnitId2),drawingDataValues=Object.values(drawingData),renderObject2=this._renderManagerService.getRenderById(unitId2),scene2=renderObject2==null?void 0:renderObject2.scene;if(scene2==null)return;this._drawingManagerService.setDrawingEditable(!0),scene2.getAllObjects().forEach(object=>{object.classType===engineRender.RENDER_CLASS_TYPE.IMAGE&&drawingDataValues.some(item=>object.oKey.includes(item.drawingId))&&scene2.detachTransformerFrom(object)})},"complete")})})}))}},__name(_g,"SheetDrawingPermissionController"),_g);SheetDrawingPermissionController=__decorateClass$2([core.OnLifecycle(core.LifecycleStages.Rendered,SheetDrawingPermissionController),__decorateParam$2(0,drawing.IDrawingManagerService),__decorateParam$2(1,engineRender.IRenderManagerService),__decorateParam$2(2,core.IPermissionService),__decorateParam$2(3,core.IUniverInstanceService),__decorateParam$2(4,core.Inject(core.UserManagerService))],SheetDrawingPermissionController);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");let SheetsDrawingCopyPasteController=(_h=class extends core.Disposable{constructor(_sheetClipboardService,_renderManagerService,_sheetDrawingService){super();__publicField(this,"_copyInfo");this._sheetClipboardService=_sheetClipboardService,this._renderManagerService=_renderManagerService,this._sheetDrawingService=_sheetDrawingService,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:__name((unitId,subUnitId,range)=>this._collect(unitId,subUnitId,range),"onBeforeCopy"),onPasteCells:__name((pasteFrom,pasteTo,data,payload)=>{const{copyType=sheetsUi.COPY_TYPE.COPY,pasteType}=payload,{range:copyRange}=pasteFrom||{},{range:pastedRange,unitId,subUnitId}=pasteTo;return this._generateMutations(pastedRange,{copyType,pasteType,copyRange,unitId,subUnitId})},"onPasteCells"),onPastePlainText:__name((pasteTo,clipText)=>({undos:[],redos:[]}),"onPastePlainText")})}_collect(unitId,subUnitId,range){var _a2;const skeletonManagetService=(_a2=this._renderManagerService.getRenderById(unitId))==null?void 0:_a2.with(sheetsUi.SheetSkeletonManagerService);if(!skeletonManagetService)return;const selectionRect=skeletonManagetService.attachRangeWithCoord(range);if(!selectionRect)return;const{startX,endX,startY,endY}=selectionRect,drawings=this._sheetDrawingService.getDrawingData(unitId,subUnitId),containedDrawings=[];Object.keys(drawings).forEach(drawingId=>{const drawing2=drawings[drawingId],{transform}=drawing2;if(drawing2.anchorType!==sheetsDrawing.SheetDrawingAnchorType.Both||!transform)return;const{left=0,top=0,width=0,height=0}=transform,{drawingStartX,drawingEndX,drawingStartY,drawingEndY}={drawingStartX:left,drawingEndX:left+width,drawingStartY:top,drawingEndY:top+height};startX<=drawingStartX&&drawingEndX<=endX&&startY<=drawingStartY&&drawingEndY<=endY&&containedDrawings.push(drawing2)}),containedDrawings.length&&(this._copyInfo={drawings:containedDrawings,unitId,subUnitId})}_generateMutations(pastedRange,copyInfo){var _a2;if(!this._copyInfo)return{redos:[],undos:[]};if([sheetsUi.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,sheetsUi.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,sheetsUi.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,sheetsUi.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(copyInfo.pasteType))return{redos:[],undos:[]};const{copyRange}=copyInfo;if(!copyRange)return{redos:[],undos:[]};const{drawings,unitId,subUnitId}=this._copyInfo,{ranges:[vCopyRange,vPastedRange],mapFunc}=sheetsUi.virtualizeDiscreteRanges([copyRange,pastedRange]),{row:copyRow,col:copyCol}=mapFunc(vCopyRange.startRow,vCopyRange.startColumn),{row:pasteRow,col:pasteCol}=mapFunc(vPastedRange.startRow,vPastedRange.startColumn),skeletonManagetService=(_a2=this._renderManagerService.getRenderById(unitId))==null?void 0:_a2.with(sheetsUi.SheetSkeletonManagerService);if(!skeletonManagetService)return{redos:[],undos:[]};const copyRect=skeletonManagetService.attachRangeWithCoord({startRow:copyRow,endRow:copyRow,startColumn:copyCol,endColumn:copyCol}),pasteRect=skeletonManagetService.attachRangeWithCoord({startRow:pasteRow,endRow:pasteRow,startColumn:pasteCol,endColumn:pasteCol});if(!copyRect||!pasteRect)return{redos:[],undos:[]};const redos=[],undos=[],leftOffset=pasteRect.startX-copyRect.startX,topOffset=pasteRect.startY-copyRect.startY,rowOffset=pasteRow-copyRow,columnOffset=pasteCol-copyCol,isCut=copyInfo.copyType===sheetsUi.COPY_TYPE.CUT,{_sheetDrawingService}=this;return drawings.forEach(drawing2=>{const{transform,sheetTransform}=drawing2;if(!transform)return;const drawingObject={...drawing2,unitId,subUnitId,drawingId:isCut?drawing2.drawingId:core.Tools.generateRandomId(),transform:{...transform,left:transform.left+leftOffset,top:transform.top+topOffset},sheetTransform:{to:{...sheetTransform.to,row:sheetTransform.to.row+rowOffset,column:sheetTransform.to.column+columnOffset},from:{...sheetTransform.from,row:sheetTransform.from.row+rowOffset,column:sheetTransform.from.column+columnOffset}}};if(isCut){const{undo,redo,objects}=_sheetDrawingService.getBatchUpdateOp([drawingObject]);redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,type:sheetsDrawing.DrawingApplyType.UPDATE,op:redo,objects}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,type:sheetsDrawing.DrawingApplyType.UPDATE,op:undo,objects}})}else{const{undo,redo,objects}=_sheetDrawingService.getBatchAddOp([drawingObject]);redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.INSERT}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:undo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.REMOVE}})}}),{redos,undos}}},__name(_h,"SheetsDrawingCopyPasteController"),_h);SheetsDrawingCopyPasteController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Ready,SheetsDrawingCopyPasteController),__decorateParam$1(0,sheetsUi.ISheetClipboardService),__decorateParam$1(1,engineRender.IRenderManagerService),__decorateParam$1(2,sheetsDrawing.ISheetDrawingService)],SheetsDrawingCopyPasteController);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField");const PLUGIN_NAME="SHEET_IMAGE_UI_PLUGIN";exports2.UniverSheetsDrawingUIPlugin=(_i=class extends core.Plugin{constructor(config={},_injector,_localeService,_renderManagerService){super();__publicField(this,"_pluginConfig");this._injector=_injector,this._localeService=_localeService,this._renderManagerService=_renderManagerService,this._pluginConfig=core.Tools.deepMerge({},DefaultSheetsDrawingConfig,config)}onStarting(){this._initDependencies()}onRendered(){this._registerRenderModules()}_initDependencies(){[[exports2.SheetCanvasFloatDomManagerService],[SheetDrawingUIController,{useFactory:__name(()=>this._injector.createInstance(SheetDrawingUIController,this._pluginConfig),"useFactory")}],[DrawingPopupMenuController],[SheetDrawingPrintingController],[SheetDrawingPermissionController]].forEach(dependency=>this._injector.add(dependency))}_registerRenderModules(){[[SheetDrawingUpdateController],[SheetDrawingTransformAffectedController],[SheetsDrawingCopyPasteController]].forEach(m=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(core.UniverInstanceType.UNIVER_SHEET,m))})}},__name(_i,"UniverSheetsDrawingUIPlugin"),_i),__publicField2(exports2.UniverSheetsDrawingUIPlugin,"type",core.UniverInstanceType.UNIVER_SHEET),__publicField2(exports2.UniverSheetsDrawingUIPlugin,"pluginName",PLUGIN_NAME),exports2.UniverSheetsDrawingUIPlugin=__decorateClass([core.DependentOn(drawing.UniverDrawingPlugin,drawingUi.UniverDrawingUIPlugin,sheetsDrawing.UniverSheetsDrawingPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.Inject(core.LocaleService)),__decorateParam(3,engineRender.IRenderManagerService)],exports2.UniverSheetsDrawingUIPlugin),exports2.ClearSheetDrawingTransformerOperation=ClearSheetDrawingTransformerOperation,exports2.DeleteDrawingsCommand=DeleteDrawingsCommand,exports2.EditSheetDrawingOperation=EditSheetDrawingOperation,exports2.GroupSheetDrawingCommand=GroupSheetDrawingCommand,exports2.InsertCellImageOperation=InsertCellImageOperation,exports2.InsertFloatImageOperation=InsertFloatImageOperation,exports2.InsertSheetDrawingCommand=InsertSheetDrawingCommand,exports2.MoveDrawingsCommand=MoveDrawingsCommand,exports2.RemoveSheetDrawingCommand=RemoveSheetDrawingCommand,exports2.SetDrawingArrangeCommand=SetDrawingArrangeCommand,exports2.SetSheetDrawingCommand=SetSheetDrawingCommand,exports2.SidebarSheetDrawingOperation=SidebarSheetDrawingOperation,exports2.UngroupSheetDrawingCommand=UngroupSheetDrawingCommand,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
|