@univerjs/sheets-drawing-ui 0.5.0-nightly.202411281606 → 0.5.0-nightly.202411291606

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.
@@ -1,5 +1,4 @@
1
- import { Nullable } from '@univerjs/core';
2
- import { ITransformState } from '@univerjs/drawing';
1
+ import { ITransformState, Nullable } from '@univerjs/core';
3
2
  import { ISheetDrawingPosition } from '@univerjs/sheets-drawing';
4
3
  import { ISheetSelectionRenderService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
5
4
  export declare function drawingPositionToTransform(position: ISheetDrawingPosition, selectionRenderService: ISheetSelectionRenderService, sheetSkeletonManagerService: SheetSkeletonManagerService): Nullable<ITransformState>;
@@ -1,5 +1,5 @@
1
- import { ICommand } from '@univerjs/core';
2
- import { IDrawingOrderMapParam, ArrangeTypeEnum } from '@univerjs/drawing';
1
+ import { ICommand, ArrangeTypeEnum } from '@univerjs/core';
2
+ import { IDrawingOrderMapParam } from '@univerjs/drawing';
3
3
  export interface ISetDrawingArrangeCommandParams extends IDrawingOrderMapParam {
4
4
  arrangeType: ArrangeTypeEnum;
5
5
  }
@@ -1,3 +1,2 @@
1
- import { IOperation } from '@univerjs/core';
2
- import { IDrawingSearch } from '@univerjs/drawing';
1
+ import { IDrawingSearch, IOperation } from '@univerjs/core';
3
2
  export declare const EditSheetDrawingOperation: IOperation<IDrawingSearch>;
@@ -1,6 +1,6 @@
1
- import { MenuConfig } from '@univerjs/ui';
2
1
  import { DependencyOverride } from '@univerjs/core';
3
- export declare const PLUGIN_CONFIG_KEY = "sheets-drawing-ui.config";
2
+ import { MenuConfig } from '@univerjs/ui';
3
+ export declare const SHEETS_DRAWING_UI_PLUGIN_CONFIG_KEY = "sheets-drawing-ui.config";
4
4
  export declare const configSymbol: unique symbol;
5
5
  export interface IUniverSheetsDrawingUIConfig {
6
6
  menu?: MenuConfig;
@@ -1,9 +1,9 @@
1
1
  import { Workbook, Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
2
- import { ISheetSelectionRenderService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
3
2
  import { IDrawingManagerService } from '@univerjs/drawing';
3
+ import { IRenderContext, IRenderManagerService, IRenderModule } from '@univerjs/engine-render';
4
4
  import { SheetInterceptorService } from '@univerjs/sheets';
5
5
  import { ISheetDrawingService } from '@univerjs/sheets-drawing';
6
- import { IRenderContext, IRenderManagerService, IRenderModule } from '@univerjs/engine-render';
6
+ import { ISheetSelectionRenderService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
7
7
  export declare class SheetDrawingTransformAffectedController extends Disposable implements IRenderModule {
8
8
  private readonly _context;
9
9
  private readonly _renderManagerService;
@@ -16,7 +16,7 @@
16
16
  import './global.css';
17
17
  export { UniverSheetsDrawingUIPlugin } from './plugin';
18
18
  export { type ICanvasFloatDom, SheetCanvasFloatDomManagerService } from './services/canvas-float-dom-manager.service';
19
- export { IMAGE_MENU_ID } from './views/menu/image.menu';
19
+ export { SHEETS_IMAGE_MENU_ID } from './views/menu/image.menu';
20
20
  export { DeleteDrawingsCommand } from './commands/commands/delete-drawings.command';
21
21
  export { GroupSheetDrawingCommand } from './commands/commands/group-sheet-drawing.command';
22
22
  export { InsertSheetDrawingCommand } from './commands/commands/insert-sheet-drawing.command';
@@ -1,7 +1,7 @@
1
- import { IDisposable, IPosition, ITransformState, Serializable, Worksheet, Disposable, ICommandService, IUniverInstanceService, LifecycleService } from '@univerjs/core';
1
+ import { IDisposable, IPosition, ITransformState, Serializable, Worksheet, Disposable, DrawingTypeEnum, ICommandService, IUniverInstanceService, LifecycleService } from '@univerjs/core';
2
2
  import { IBoundRectNoAngle, Scene, SpreadsheetSkeleton, IRenderManagerService, Rect } from '@univerjs/engine-render';
3
3
  import { IFloatDomLayout, CanvasFloatDomService } from '@univerjs/ui';
4
- import { DrawingTypeEnum, IDrawingManagerService } from '@univerjs/drawing';
4
+ import { IDrawingManagerService } from '@univerjs/drawing';
5
5
  import { ISheetDrawingService } from '@univerjs/sheets-drawing';
6
6
  import { BehaviorSubject } from 'rxjs';
7
7
  export interface ICanvasFloatDom {
@@ -1,6 +1,6 @@
1
- import { IMenuItem } from '@univerjs/ui';
2
1
  import { IAccessor } from '@univerjs/core';
2
+ import { IMenuItem } from '@univerjs/ui';
3
3
  export declare const IMAGE_UPLOAD_ICON = "addition-and-subtraction-single";
4
- export declare const IMAGE_MENU_ID = "sheet.menu.image";
4
+ export declare const SHEETS_IMAGE_MENU_ID = "sheet.menu.image";
5
5
  export declare function ImageMenuFactory(accessor: IAccessor): IMenuItem;
6
6
  export declare function UploadFloatImageMenuFactory(_accessor: IAccessor): IMenuItem;
@@ -1,5 +1,5 @@
1
+ import { IDrawingParam } from '@univerjs/core';
1
2
  import { default as React } from 'react';
2
- import { IDrawingParam } from '@univerjs/drawing';
3
3
  export interface ISheetDrawingAnchorProps {
4
4
  drawings: IDrawingParam[];
5
5
  }
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(O,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("@univerjs/core"),require("@univerjs/drawing"),require("@univerjs/drawing-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("react"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","react","@univerjs/design"],p):(O=typeof globalThis<"u"?globalThis:O||self,p(O.UniverSheetsDrawingUi={},O.UniverCore,O.UniverDrawing,O.UniverDrawingUi,O.UniverEngineRender,O.UniverSheetsDrawing,O.UniverSheetsUi,O.UniverUi,O.rxjs,O.UniverSheets,O.React,O.UniverDesign))})(this,function(O,p,b,ee,N,h,j,F,W,I,x,q){"use strict";var tn=Object.defineProperty;var nn=(O,p,b)=>p in O?tn(O,p,{enumerable:!0,configurable:!0,writable:!0,value:b}):O[p]=b;var X=(O,p,b)=>nn(O,typeof p!="symbol"?p+"":p,b);const qe="sheets-drawing-ui.config",Ze={},G={id:"sheet.operation.clear-drawing-transformer",type:p.CommandType.MUTATION,handler:(i,r)=>{const n=i.get(N.IRenderManagerService);return r.forEach(e=>{var t,o;(o=(t=n.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},ie={id:"sheet.command.remove-sheet-image",type:p.CommandType.COMMAND,handler:(i,r)=>{var M,C,T;const n=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),t=i.get(I.SheetInterceptorService),o=i.get(h.ISheetDrawingService);if(!r)return!1;const{drawings:a}=r,c=[];a.forEach(_=>{const{unitId:D}=_;c.push(D)});const d=o.getBatchRemoveOp(a),{unitId:g,subUnitId:l,undo:s,redo:u,objects:m}=d,f=t.onCommandExecute({id:ie.id,params:r}),S={id:h.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:l,op:u,objects:m,type:h.DrawingApplyType.REMOVE}},v={id:h.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:l,op:s,objects:m,type:h.DrawingApplyType.INSERT}};return p.sequenceExecute([...(M=f.preRedos)!=null?M:[],S,...f.redos],n)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=f.preUndos)!=null?C:[],v,...f.undos,{id:G.id,params:c}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:c}]}),!0):!1}},Le="COMPONENT_SHEET_DRAWING_PANEL",Ce={id:"sidebar.operation.sheet-image",type:p.CommandType.COMMAND,handler:async(i,r)=>{const n=i.get(F.ISidebarService),e=i.get(p.LocaleService),t=i.get(p.IUniverInstanceService),o=i.get(b.IDrawingManagerService);if(!I.getSheetCommandTarget(t))return!1;switch(r.value){case"open":n.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Le},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:n.close();break}return!0}},ye={id:"sheet.operation.edit-sheet-image",type:p.CommandType.OPERATION,handler:(i,r)=>{const n=i.get(b.IDrawingManagerService),e=i.get(p.ICommandService);return r==null?!1:(n.focusDrawing([r]),e.executeCommand(Ce.id,{value:"open"}),!0)}};var Me={exports:{}},oe={};/**
1
+ (function(E,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("@univerjs/core"),require("@univerjs/drawing"),require("@univerjs/drawing-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("react"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","react","@univerjs/design"],g):(E=typeof globalThis<"u"?globalThis:E||self,g(E.UniverSheetsDrawingUi={},E.UniverCore,E.UniverDrawing,E.UniverDrawingUi,E.UniverEngineRender,E.UniverSheetsDrawing,E.UniverSheetsUi,E.UniverUi,E.rxjs,E.UniverSheets,E.React,E.UniverDesign))})(this,function(E,g,A,ee,N,h,j,F,W,I,H,q){"use strict";var tn=Object.defineProperty;var nn=(E,g,A)=>g in E?tn(E,g,{enumerable:!0,configurable:!0,writable:!0,value:A}):E[g]=A;var X=(E,g,A)=>nn(E,typeof g!="symbol"?g+"":g,A);const qe="sheets-drawing-ui.config",Ze={},G={id:"sheet.operation.clear-drawing-transformer",type:g.CommandType.MUTATION,handler:(i,r)=>{const n=i.get(N.IRenderManagerService);return r.forEach(e=>{var t,o;(o=(t=n.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},ie={id:"sheet.command.remove-sheet-image",type:g.CommandType.COMMAND,handler:(i,r)=>{var M,C,T;const n=i.get(g.ICommandService),e=i.get(g.IUndoRedoService),t=i.get(I.SheetInterceptorService),o=i.get(h.ISheetDrawingService);if(!r)return!1;const{drawings:a}=r,c=[];a.forEach(_=>{const{unitId:D}=_;c.push(D)});const d=o.getBatchRemoveOp(a),{unitId:p,subUnitId:l,undo:s,redo:u,objects:m}=d,f=t.onCommandExecute({id:ie.id,params:r}),S={id:h.SetDrawingApplyMutation.id,params:{unitId:p,subUnitId:l,op:u,objects:m,type:h.DrawingApplyType.REMOVE}},w={id:h.SetDrawingApplyMutation.id,params:{unitId:p,subUnitId:l,op:s,objects:m,type:h.DrawingApplyType.INSERT}};return g.sequenceExecute([...(M=f.preRedos)!=null?M:[],S,...f.redos],n)?(e.pushUndoRedo({unitID:p,undoMutations:[...(C=f.preUndos)!=null?C:[],w,...f.undos,{id:G.id,params:c}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:c}]}),!0):!1}},Le="COMPONENT_SHEET_DRAWING_PANEL",Ce={id:"sidebar.operation.sheet-image",type:g.CommandType.COMMAND,handler:async(i,r)=>{const n=i.get(F.ISidebarService),e=i.get(g.LocaleService),t=i.get(g.IUniverInstanceService),o=i.get(A.IDrawingManagerService);if(!I.getSheetCommandTarget(t))return!1;switch(r.value){case"open":n.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Le},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:n.close();break}return!0}},ye={id:"sheet.operation.edit-sheet-image",type:g.CommandType.OPERATION,handler:(i,r)=>{const n=i.get(A.IDrawingManagerService),e=i.get(g.ICommandService);return r==null?!1:(n.focusDrawing([r]),e.executeCommand(Ce.id,{value:"open"}),!0)}};var Me={exports:{}},oe={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,4 +6,4 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var Be;function Qe(){if(Be)return oe;Be=1;var i=x,r=Symbol.for("react.element"),n=Symbol.for("react.fragment"),e=Object.prototype.hasOwnProperty,t=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function a(c,d,g){var l,s={},u=null,m=null;g!==void 0&&(u=""+g),d.key!==void 0&&(u=""+d.key),d.ref!==void 0&&(m=d.ref);for(l in d)e.call(d,l)&&!o.hasOwnProperty(l)&&(s[l]=d[l]);if(c&&c.defaultProps)for(l in d=c.defaultProps,d)s[l]===void 0&&(s[l]=d[l]);return{$$typeof:r,type:c,key:u,ref:m,props:s,_owner:t.current}}return oe.Fragment=n,oe.jsx=a,oe.jsxs=a,oe}var Ge;function et(){return Ge||(Ge=1,Me.exports=Qe()),Me.exports}var $=et();const le={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},tt=()=>{const i=p.useDependency(b.IImageIoService),r=p.useDependency(p.LocaleService),[n,e]=x.useState(0);return x.useEffect(()=>{const t=i.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[i]),$.jsx("div",{style:{display:n>0?"block":"none"},className:le.uploadLoading,children:$.jsxs("div",{className:le.uploadLoadingBody,children:[$.jsx("div",{className:le.uploadLoadingBodyAnimation}),$.jsx("div",{className:le.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${n}`})]})})};var nt=Object.defineProperty,rt=Object.getOwnPropertyDescriptor,it=(i,r,n,e)=>{for(var t=e>1?void 0:e?rt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&nt(r,n,t),t},te=(i,r)=>(n,e)=>r(n,e,i);let ue=class extends p.RxDisposable{constructor(r,n,e,t,o,a,c){super();X(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=n,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=c,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(p.UniverInstanceType.UNIVER_SHEET).pipe(W.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,()=>p.connectInjector(tt,this._injector))}_dispose(r){const n=r.getUnitId();this._renderManagerService.removeRender(n)}_create(r){if(!r)return;const n=r.getUnitId();this._renderManagerService.has(n)&&!this._initImagePopupMenu.has(n)&&(this._popupMenuListener(n),this._initImagePopupMenu.add(n))}_hasCropObject(r){const n=r.getAllObjectsByOrder();for(const e of n)if(e instanceof ee.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const n=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!n)return;const e=n.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(p.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(n))return;const a=e.getSelectedObjectMap();if(a.size>1){t==null||t.dispose();return}const c=a.values().next().value;if(!c)return;const d=c.oKey,g=this._drawingManagerService.getDrawingOKey(d);if(!g)return;const{unitId:l,subUnitId:s,drawingId:u,drawingType:m}=g,f=g.data;if(f&&f.disablePopup)return;t==null||t.dispose();const S=this._canvasPopManagerService.getFeatureMenu(l,s,u,m);t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:ee.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(l,s,u,m)}})),this._drawingManagerService.focusDrawing([{unitId:l,subUnitId:s,drawingId:u}])}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.dispose(),this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(e.changing$.subscribe(()=>{t==null||t.dispose()}))}_getImageMenuItems(r,n,e,t){return[{label:"image-popup.edit",index:0,commandId:ye.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===b.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ie.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:n,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ee.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===b.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ee.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:n,drawingId:e}],disable:t===b.DrawingTypeEnum.DRAWING_DOM}]}};ue=it([te(0,p.Inject(p.Injector)),te(1,b.IDrawingManagerService),te(2,p.Inject(j.SheetCanvasPopManagerService)),te(3,N.IRenderManagerService),te(4,p.IUniverInstanceService),te(5,p.IContextService),te(6,p.Inject(F.IUIPartsService))],ue);function Y(i,r,n){const{from:e,to:t,flipY:o=!1,flipX:a=!1,angle:c=0,skewX:d=0,skewY:g=0}=i,{column:l,columnOffset:s,row:u,rowOffset:m}=e,{column:f,columnOffset:S,row:v,rowOffset:y}=t,M=n.getCurrentSkeleton(),C=j.attachRangeWithCoord(M,{startColumn:l,endColumn:l,startRow:u,endRow:u});if(C==null)return;const T=j.attachRangeWithCoord(M,{startColumn:f,endColumn:f,startRow:v,endRow:v});if(T==null)return;const{startX:_,startY:D}=C,{startX:w,startY:A}=T;let E=N.precisionTo(_+s,1),L=N.precisionTo(D+m,1),U=N.precisionTo(w+S-E,1),P=N.precisionTo(A+y-L,1);C.startX===T.endX&&(U=0),C.startY===T.endY&&(P=0);const R=M.rowHeaderWidth+M.columnTotalWidth,B=M.columnHeaderHeight+M.rowTotalHeight;return E+U>R&&(E=R-U),L+P>B&&(L=B-P),{flipY:o,flipX:a,angle:c,skewX:d,skewY:g,left:E,top:L,width:U,height:P}}function k(i,r){const{left:n=0,top:e=0,width:t=0,height:o=0,flipY:a=!1,flipX:c=!1,angle:d=0,skewX:g=0,skewY:l=0}=i,s=r.getCellWithCoordByOffset(n,e);if(s==null)return;const u={column:s.actualColumn,columnOffset:N.precisionTo(n-s.startX,1),row:s.actualRow,rowOffset:N.precisionTo(e-s.startY,1)},m=r.getCellWithCoordByOffset(n+t,e+o);if(m==null)return;const f={column:m.actualColumn,columnOffset:N.precisionTo(n+t-m.startX,1),row:m.actualRow,rowOffset:N.precisionTo(e+o-m.startY,1)};return{flipY:a,flipX:c,angle:d,skewX:g,skewY:l,from:u,to:f}}var ot=Object.defineProperty,at=Object.getOwnPropertyDescriptor,st=(i,r,n,e)=>{for(var t=e>1?void 0:e?at(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&ot(r,n,t),t},me=(i,r)=>(n,e)=>r(n,e,i);let De=class extends p.Disposable{constructor(i,r,n,e,t){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=n,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=t,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const n=i[r];for(const e in n.data){const t=n.data[e];t.transform=Y(t.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};De=st([me(1,h.ISheetDrawingService),me(2,b.IDrawingManagerService),me(3,p.Inject(j.ISheetSelectionRenderService)),me(4,p.Inject(j.SheetSkeletonManagerService))],De);var K=function(){return K=Object.assign||function(i){for(var r,n=1,e=arguments.length;n<e;n++){r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(i[t]=r[t])}return i},K.apply(this,arguments)},ct=function(i,r){var n={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(n[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(i);t<e.length;t++)r.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(i,e[t])&&(n[e[t]]=i[e[t]]);return n},ke=x.forwardRef(function(i,r){var n=i.icon,e=i.id,t=i.className,o=i.extend,a=ct(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),d=x.useRef("_".concat(ut()));return Ve(n,"".concat(e),{defIds:n.defIds,idSuffix:d.current},K({ref:r,className:c},a),o)});function Ve(i,r,n,e,t){return x.createElement(i.tag,K(K({key:r},dt(i,n,t)),e),(lt(i,n).children||[]).map(function(o,a){return Ve(o,"".concat(r,"-").concat(i.tag,"-").concat(a),n,void 0,t)}))}function dt(i,r,n){var e=K({},i.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var t=r.defIds;return!t||t.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],c=o[1];typeof c=="string"&&(e[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function lt(i,r){var n,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?K(K({},i),{children:i.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?K(K({},t),{attrs:K(K({},t.attrs),{id:t.attrs.id+r.idSuffix})}):t})}):i}function ut(){return Math.random().toString(36).substring(2,8)}ke.displayName="UniverIcon";var mt={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"}}]},Fe=x.forwardRef(function(i,r){return x.createElement(ke,Object.assign({},i,{id:"add-image-single",ref:r,icon:mt}))});Fe.displayName="AddImageSingle";const Re={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 t=e[0].unitId,o=e.map(a=>{const{unitId:c,subUnitId:d,drawingId:g,drawingType:l}=a;return{unitId:c,subUnitId:d,drawingId:g,drawingType:l}});return r.executeCommand(ie.id,{unitId:t,drawings:o})}};function gt(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:c}=e,d=N.getGroupState(0,0,t.map(s=>s.transform||{})),g=t.map(s=>{const u=s.transform||{left:0,top:0},{unitId:m,subUnitId:f,drawingId:S}=s;return{unitId:m,subUnitId:f,drawingId:S,transform:{...u,left:u.left-d.left,top:u.top-d.top},groupId:c}}),l={unitId:o,subUnitId:a,drawingId:c,drawingType:b.DrawingTypeEnum.DRAWING_GROUP,transform:d};r.push({parent:l,children:g})}),r}function pt(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:c,transform:d={width:0,height:0}}=e;if(d==null)return;const g=t.map(s=>{const{transform:u}=s,{unitId:m,subUnitId:f,drawingId:S}=s,v=N.transformObjectOutOfGroup(u||{},d,d.width||0,d.height||0);return{unitId:m,subUnitId:f,drawingId:S,transform:v,groupId:void 0}}),l={unitId:o,subUnitId:a,drawingId:c,drawingType:b.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:l,children:g})}),r}const Te={id:"sheet.command.group-sheet-image",type:p.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),t=i.get(h.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:m,children:f})=>{o.push(m.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getGroupDrawingOp(r),{unitId:c,subUnitId:d,undo:g,redo:l,objects:s}=a;return n.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:s,type:h.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:g,unitId:c,subUnitId:d,objects:pt(s),type:h.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:s,type:h.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!0):!1}},ae={id:"sheet.command.insert-sheet-image",type:p.CommandType.COMMAND,handler:(i,r)=>{var M,C,T;const n=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),t=i.get(h.ISheetDrawingService),o=i.get(I.SheetInterceptorService);if(!r)return!1;const a=r.drawings,c=a.map(_=>_.unitId),d=t.getBatchAddOp(a),{unitId:g,subUnitId:l,undo:s,redo:u,objects:m}=d,f=o.onCommandExecute({id:ae.id,params:r}),S={id:h.SetDrawingApplyMutation.id,params:{op:u,unitId:g,subUnitId:l,objects:m,type:h.DrawingApplyType.INSERT}},v={id:h.SetDrawingApplyMutation.id,params:{op:s,unitId:g,subUnitId:l,objects:m,type:h.DrawingApplyType.REMOVE}};return p.sequenceExecute([...(M=f.preRedos)!=null?M:[],S,...f.redos],n)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=f.preUndos)!=null?C:[],v,...f.undos,{id:G.id,params:c}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:c}]}),!0):!1}},be={id:"sheet.command.set-drawing-arrange",type:p.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(p.ICommandService),e=i.get(p.IUndoRedoService);if(!r)return!1;const t=i.get(h.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:c,arrangeType:d}=r,g={unitId:o,subUnitId:a,drawingIds:c};let l;if(d===b.ArrangeTypeEnum.forward?l=t.getForwardDrawingsOp(g):d===b.ArrangeTypeEnum.backward?l=t.getBackwardDrawingOp(g):d===b.ArrangeTypeEnum.front?l=t.getFrontDrawingsOp(g):d===b.ArrangeTypeEnum.back&&(l=t.getBackDrawingsOp(g)),l==null)return!1;const{objects:s,redo:u,undo:m}=l;return n.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:u,unitId:o,subUnitId:a,objects:s,type:h.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:a,objects:s,type:h.DrawingApplyType.ARRANGE}}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:u,unitId:o,subUnitId:a,objects:s,type:h.DrawingApplyType.ARRANGE}}]}),!0):!1}},se={id:"sheet.command.set-sheet-image",type:p.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),t=i.get(h.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=t.getBatchUpdateOp(o),{unitId:c,subUnitId:d,undo:g,redo:l,objects:s}=a;return n.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:c,subUnitId:d,op:l,objects:s,type:h.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:g,objects:s,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[c]}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:l,objects:s,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[c]}]}),!0):!1}},Ee={id:"sheet.command.ungroup-sheet-image",type:p.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),t=i.get(h.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:m,children:f})=>{o.push(m.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getUngroupDrawingOp(r),{unitId:c,subUnitId:d,undo:g,redo:l,objects:s}=a;return n.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:s,type:h.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:g,unitId:c,subUnitId:d,objects:gt(s),type:h.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:s,type:h.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};var ht=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,St=(i,r,n,e)=>{for(var t=e>1?void 0:e?ft(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&ht(r,n,t),t},z=(i,r)=>(n,e)=>r(n,e,i);let ge=class extends p.Disposable{constructor(r,n,e,t,o,a,c,d,g,l,s,u){super();X(this,"_workbookSelections");this._context=r,this._skeletonManagerService=n,this._commandService=e,this._selectionRenderService=t,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=c,this._drawingManagerService=d,this._contextService=g,this._messageService=l,this._localeService=s,this._workbookSelections=u.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const r=await this._fileOpenerService.openFile({multiple:!0,accept:b.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),n=r.length;return n>b.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(b.DRAWING_IMAGE_COUNT_LIMIT))}),!1):n===0?!1:(r.forEach(async e=>await this._insertFloatImage(e)),!0)}async _insertFloatImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(M){const C=M.message;C===b.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(b.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===b.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===b.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:c,source:d,base64Cache:g}=n,{width:l,height:s,image:u}=await b.getImageSize(g||""),{width:m,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(d,c,u);let S=1;if(l>b.DRAWING_IMAGE_WIDTH_LIMIT||s>b.DRAWING_IMAGE_HEIGHT_LIMIT){const M=b.DRAWING_IMAGE_WIDTH_LIMIT/l,C=b.DRAWING_IMAGE_HEIGHT_LIMIT/s;S=Math.max(M,C)}const v=this._getImagePosition(l*S,s*S,m,f);if(v==null)return;const y={unitId:t,subUnitId:o,drawingId:a,drawingType:b.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c,source:d,transform:Y(v,this._selectionRenderService,this._skeletonManagerService),sheetTransform:v};this._commandService.executeCommand(ae.id,{unitId:t,drawings:[y]})}_getUnitInfo(){const r=this._context.unit,n=r.getActiveSheet(),e=r.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(r,n,e,t){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const c=j.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(c==null)return;let{startColumn:d,startRow:g,startX:l,startY:s}=c,u=!1;if(l+r>e&&(l=e-r,l<0&&(l=0,r=e),u=!0),s+n>t&&(s=t-n,s<0&&(s=0,n=t),u=!0),u){const v=this._selectionRenderService.getCellWithCoordByOffset(l,s);if(v==null)return;l=v.startX,s=v.startY,d=v.actualColumn,g=v.actualRow}const m={column:d,columnOffset:0,row:g,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(l+r,s+n);if(f==null)return;const S={column:f.actualColumn,columnOffset:l+r-f.startX,row:f.actualRow,rowOffset:s+n-f.startY};return{from:m,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(r=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o}=r;this._commandService.executeCommand(be.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(r=>{const n=[];r.length!==0&&(r.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a,drawingType:c,transform:d}=e;if(d==null)return;const g=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:a});if(g==null||g.unitId!==this._context.unitId)return;const l=k({...g.transform,...d},this._selectionRenderService);if(l==null)return;const s={...e,transform:{...g.transform,...d,...Y(l,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...l}};n.push(s)}),n.length>0&&this._commandService.executeCommand(se.id,{unitId:r[0].unitId,drawings:n}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Te.id,r);const{unitId:n,subUnitId:e,drawingId:t}=r[0].parent;this._drawingManagerService.focusDrawing([{unitId:n,subUnitId:e,drawingId:t}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Ee.id,r)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(r=>{r==null||r.length===0?(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(r))}))}};ge=St([z(1,p.Inject(j.SheetSkeletonManagerService)),z(2,p.ICommandService),z(3,j.ISheetSelectionRenderService),z(4,b.IImageIoService),z(5,F.ILocalFileService),z(6,h.ISheetDrawingService),z(7,b.IDrawingManagerService),z(8,p.IContextService),z(9,F.IMessageService),z(10,p.Inject(p.LocaleService)),z(11,p.Inject(I.SheetsSelectionsService))],ge);const pe={id:"sheet.command.insert-float-image",type:p.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(N.IRenderManagerService).getCurrentTypeOfRenderer(p.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(ge).insertFloatImage())!=null?e:!1}},re={id:"sheet.command.move-drawing",type:p.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(p.ICommandService),e=i.get(h.ISheetDrawingService),t=i.get(j.ISheetSelectionRenderService),{direction:o}=r,a=e.getFocusDrawings();if(a.length===0)return!1;const c=a[0].unitId,d=a.map(l=>{const{transform:s}=l;if(s==null)return null;const u={...s},{left:m=0,top:f=0}=s;return o===p.Direction.UP?u.top=f-1:o===p.Direction.DOWN?u.top=f+1:o===p.Direction.LEFT?u.left=m-1:o===p.Direction.RIGHT&&(u.left=m+1),{...l,transform:u,sheetTransform:k(u,t)}}).filter(l=>l!=null);return n.syncExecuteCommand(se.id,{unitId:c,drawings:d})?(n.syncExecuteCommand(G.id,[c]),!0):!1}},$e="addition-and-subtraction-single",Oe="sheet.menu.image";function vt(i){return{id:Oe,type:F.MenuItemType.SUBITEMS,icon:$e,tooltip:"sheetImage.title",hidden$:F.getMenuHiddenObservable(i,p.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(i,{workbookTypes:[I.WorkbookEditablePermission],worksheetTypes:[I.WorksheetEditPermission],rangeTypes:[I.RangeProtectionPermissionEditPoint]})}}function wt(i){return{id:pe.id,title:"sheetImage.upload.float",type:F.MenuItemType.BUTTON,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"};function Ye(i){var r,n,e="";if(typeof i=="string"||typeof i=="number")e+=i;else if(typeof i=="object")if(Array.isArray(i)){var t=i.length;for(r=0;r<t;r++)i[r]&&(n=Ye(i[r]))&&(e&&(e+=" "),e+=n)}else for(n in i)i[n]&&(e&&(e+=" "),e+=n);return e}function he(){for(var i,r,n=0,e="",t=arguments.length;n<t;n++)(i=arguments[n])&&(r=Ye(i))&&(e&&(e+=" "),e+=r);return e}const _t=i=>{var C;const r=p.useDependency(p.ICommandService),n=p.useDependency(p.LocaleService),e=p.useDependency(b.IDrawingManagerService),t=p.useDependency(N.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:c}=a,d=t.getRenderById(c),g=d==null?void 0:d.scene;if(g==null)return;const l=g.getTransformerByCreate(),[s,u]=x.useState(!0),m=(C=a.anchorType)!=null?C:h.SheetDrawingAnchorType.Position,[f,S]=x.useState(m);function v(T,_){const D=[];return T.forEach(w=>{const{oKey:A}=w,E=_.getDrawingOKey(A);if(E==null)return D.push(null),!0;const{unitId:L,subUnitId:U,drawingId:P,drawingType:R,anchorType:B,sheetTransform:V}=E;D.push({unitId:L,subUnitId:U,drawingId:P,anchorType:B,sheetTransform:V,drawingType:R})}),D}x.useEffect(()=>{const T=l.clearControl$.subscribe(D=>{D===!0&&u(!1)}),_=l.changeStart$.subscribe(D=>{var E;const{objects:w}=D,A=v(w,e);if(A.length===0)u(!1);else if(A.length>=1){u(!0);const L=((E=A[0])==null?void 0:E.anchorType)||h.SheetDrawingAnchorType.Position;S(L)}});return()=>{_.unsubscribe(),T.unsubscribe()}},[]);function y(T){S(T);const _=e.getFocusDrawings();if(_.length===0)return;const D=_.map(w=>({unitId:w.unitId,subUnitId:w.subUnitId,drawingId:w.drawingId,anchorType:T}));r.executeCommand(se.id,{unitId:_[0].unitId,drawings:D})}const M=T=>T?"block":"none";return $.jsxs("div",{className:he(Z.imageCommonPanelGrid,Z.imageCommonPanelBorder),style:{display:M(s)},children:[$.jsx("div",{className:Z.imageCommonPanelRow,children:$.jsx("div",{className:he(Z.imageCommonPanelColumn,Z.imageCommonPanelTitle),children:$.jsx("div",{children:n.t("drawing-anchor.title")})})}),$.jsx("div",{className:he(Z.imageCommonPanelRow),children:$.jsx("div",{className:he(Z.imageCommonPanelColumn),children:$.jsxs(q.RadioGroup,{value:f,onChange:y,direction:"vertical",children:[$.jsx(q.Radio,{value:h.SheetDrawingAnchorType.Both,children:n.t("drawing-anchor.both")}),$.jsx(q.Radio,{value:h.SheetDrawingAnchorType.Position,children:n.t("drawing-anchor.position")}),$.jsx(q.Radio,{value:h.SheetDrawingAnchorType.None,children:n.t("drawing-anchor.none")})]})})})]})},It=()=>{const i=p.useDependency(b.IDrawingManagerService),r=i.getFocusDrawings(),[n,e]=x.useState(r);return x.useEffect(()=>{const t=i.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(n!=null&&n.length)&&$.jsxs("div",{className:Z.imageCommonPanel,children:[$.jsx(ee.DrawingCommonPanel,{drawings:n}),$.jsx(_t,{drawings:n})]})},Ct={[F.RibbonStartGroup.FORMULAS_INSERT]:{[Oe]:{order:3,menuItemFactory:vt,[pe.id]:{order:0,menuItemFactory:wt}}}};function ce(i){return!i.getContextValue(p.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(p.EDITOR_ACTIVATED)&&!i.getContextValue(p.FOCUSING_PANEL_EDITOR)&&i.getContextValue(p.FOCUSING_COMMON_DRAWINGS)}const yt={id:re.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}},Mt={id:re.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}},Dt={id:re.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}},Rt={id:re.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}},Tt={id:Re.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:ce,binding:F.KeyCode.DELETE,mac:F.KeyCode.BACKSPACE};var bt=Object.defineProperty,Et=Object.getOwnPropertyDescriptor,Ot=(i,r,n,e)=>{for(var t=e>1?void 0:e?Et(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&bt(r,n,t),t},fe=(i,r)=>(n,e)=>r(n,e,i);let Se=class extends p.Disposable{constructor(i,r,n,e){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=n,this._shortcutService=e,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register($e,Fe)),this.disposeWithMe(i.register(Le,It))}_initMenus(){this._menuManagerService.mergeMenu(Ct)}_initCommands(){[pe,ae,ie,se,Ce,G,ye,Te,Ee,re,Re,be].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[yt,Mt,Dt,Rt,Tt].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Se=Ot([fe(0,p.Inject(F.ComponentManager)),fe(1,F.IMenuManagerService),fe(2,p.ICommandService),fe(3,F.IShortcutService)],Se);var Pt=Object.defineProperty,At=Object.getOwnPropertyDescriptor,Ut=(i,r,n,e)=>{for(var t=e>1?void 0:e?At(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Pt(r,n,t),t},Pe=(i,r)=>(n,e)=>r(n,e,i);let ve=class extends p.Disposable{constructor(r,n,e){super();X(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=n,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,n,e)=>this._collect(r,n,e),onPasteCells:(r,n,e,t)=>{const{copyType:o=j.COPY_TYPE.COPY,pasteType:a}=t,{range:c}=r||{},{range:d,unitId:g,subUnitId:l}=n;return this._generateMutations(d,{copyType:o,pasteType:a,copyRange:c,unitId:g,subUnitId:l})},onPastePlainText:(r,n)=>({undos:[],redos:[]})})}_collect(r,n,e){var u;const t=(u=this._renderManagerService.getRenderById(r))==null?void 0:u.with(j.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:c,startY:d,endY:g}=o,l=this._sheetDrawingService.getDrawingData(r,n),s=[];Object.keys(l).forEach(m=>{const f=l[m],{transform:S}=f;if(f.anchorType!==h.SheetDrawingAnchorType.Both||!S)return;const{left:v=0,top:y=0,width:M=0,height:C=0}=S,{drawingStartX:T,drawingEndX:_,drawingStartY:D,drawingEndY:w}={drawingStartX:v,drawingEndX:v+M,drawingStartY:y,drawingEndY:y+C};a<=T&&_<=c&&d<=D&&w<=g&&s.push(f)}),s.length&&(this._copyInfo={drawings:s,unitId:r,subUnitId:n})}_generateMutations(r,n){var E;if(!this._copyInfo)return{redos:[],undos:[]};if([j.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,j.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,j.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,j.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(n.pasteType))return{redos:[],undos:[]};const{copyRange:e}=n;if(!e)return{redos:[],undos:[]};const{drawings:t,unitId:o,subUnitId:a}=this._copyInfo,{ranges:[c,d],mapFunc:g}=j.virtualizeDiscreteRanges([e,r]),{row:l,col:s}=g(c.startRow,c.startColumn),{row:u,col:m}=g(d.startRow,d.startColumn),f=(E=this._renderManagerService.getRenderById(o))==null?void 0:E.with(j.SheetSkeletonManagerService);if(!f)return{redos:[],undos:[]};const S=f.attachRangeWithCoord({startRow:l,endRow:l,startColumn:s,endColumn:s}),v=f.attachRangeWithCoord({startRow:u,endRow:u,startColumn:m,endColumn:m});if(!S||!v)return{redos:[],undos:[]};const y=[],M=[],C=v.startX-S.startX,T=v.startY-S.startY,_=u-l,D=m-s,w=n.copyType===j.COPY_TYPE.CUT,{_sheetDrawingService:A}=this;return t.forEach(L=>{const{transform:U,sheetTransform:P}=L;if(!U)return;const R={...L,unitId:o,subUnitId:a,drawingId:w?L.drawingId:p.Tools.generateRandomId(),transform:{...U,left:U.left+C,top:U.top+T},sheetTransform:{to:{...P.to,row:P.to.row+_,column:P.to.column+D},from:{...P.from,row:P.from.row+_,column:P.from.column+D}}};if(w){const{undo:B,redo:V,objects:J}=A.getBatchUpdateOp([R]);y.push({id:h.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:h.DrawingApplyType.UPDATE,op:V,objects:J}}),M.push({id:h.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:h.DrawingApplyType.UPDATE,op:B,objects:J}})}else{const{undo:B,redo:V,objects:J}=A.getBatchAddOp([R]);y.push({id:h.SetDrawingApplyMutation.id,params:{op:V,unitId:o,subUnitId:a,objects:J,type:h.DrawingApplyType.INSERT}}),M.push({id:h.SetDrawingApplyMutation.id,params:{op:B,unitId:o,subUnitId:a,objects:J,type:h.DrawingApplyType.REMOVE}})}}),{redos:y,undos:M}}};ve=Ut([Pe(0,j.ISheetClipboardService),Pe(1,N.IRenderManagerService),Pe(2,h.ISheetDrawingService)],ve);var Nt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,Wt=(i,r,n,e)=>{for(var t=e>1?void 0:e?jt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Nt(r,n,t),t},de=(i,r)=>(n,e)=>r(n,e,i);let we=class extends p.Disposable{constructor(i,r,n,e,t){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=n,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingVisible(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new I.WorkbookViewPermission(t).id,new I.WorksheetViewPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const c=r.getUnitId(),d=e.getSheetId(),g=this._drawingManagerService.getDrawingData(c,d),l=Object.values(g),s=this._renderManagerService.getRenderById(c),u=s==null?void 0:s.scene;if(u==null)return;u.getAllObjectsByOrder().forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&l.some(S=>f.oKey.includes(S.drawingId))&&u.removeObject(f)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingEditable(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new I.WorkbookEditablePermission(t).id,new I.WorksheetEditPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const c=r.getUnitId(),d=e.getSheetId(),g=this._drawingManagerService.getDrawingData(c,d),l=Object.values(g),s=this._renderManagerService.getRenderById(c),u=s==null?void 0:s.scene;if(u==null)return;u.getAllObjectsByOrder().forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&l.some(S=>f.oKey.includes(S.drawingId))&&u.detachTransformerFrom(f)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const c=this._renderManagerService.getRenderById(t),d=c==null?void 0:c.scene;if(d==null)return;const g=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new I.WorkbookViewPermission(t).id,new I.WorksheetViewPermission(t,o).id]).pipe(W.map(u=>u.every(m=>m.value)));l==null||l.pipe(W.filter(u=>u!==a),W.distinctUntilChanged()).subscribe({next:u=>{a=u,this._drawingManagerService.setDrawingVisible(u);const m=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);u?this._drawingManagerService.addNotification(S):(m.forEach(v=>{v.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(y=>v.oKey.includes(y.drawingId))&&d.removeObject(v)}),g.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new I.WorksheetViewPermission(t,o).id))==null||s.pipe(W.filter(u=>u.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const u=this._drawingManagerService.getDrawingData(t,o),m=Object.values(u);this._drawingManagerService.addNotification(m)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const c=this._renderManagerService.getRenderById(t),d=c==null?void 0:c.scene;if(d==null)return;const g=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new I.WorkbookEditablePermission(t).id,new I.WorksheetEditPermission(t,o).id]).pipe(W.map(u=>u.every(m=>m.value)));l==null||l.pipe(W.filter(u=>u!==a),W.distinctUntilChanged()).subscribe({next:u=>{a=u,this._drawingManagerService.setDrawingEditable(u);const m=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);u?(m.forEach(v=>{v.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(y=>v.oKey.includes(y.drawingId))&&d.attachTransformerTo(v)}),this._drawingManagerService.addNotification(S)):(m.forEach(v=>{v.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(y=>v.oKey.includes(y.drawingId))&&d.detachTransformerFrom(v)}),g.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new I.WorksheetEditPermission(t,o).id))==null||s.pipe(W.filter(u=>u.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const u=r.getUnitId(),m=e.getSheetId(),f=this._drawingManagerService.getDrawingData(u,m),S=Object.values(f),v=this._renderManagerService.getRenderById(u),y=v==null?void 0:v.scene;if(y==null)return;this._drawingManagerService.setDrawingEditable(!0),y.getAllObjectsByOrder().forEach(C=>{C.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(T=>C.oKey.includes(T.drawingId))&&y.detachTransformerFrom(C)})}})})}))}};we=Wt([de(0,b.IDrawingManagerService),de(1,N.IRenderManagerService),de(2,p.IPermissionService),de(3,p.IUniverInstanceService),de(4,p.Inject(p.UserManagerService))],we);var Lt=Object.defineProperty,Bt=Object.getOwnPropertyDescriptor,Gt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Bt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Lt(r,n,t),t},_e=(i,r)=>(n,e)=>r(n,e,i);let Ie=class extends p.Disposable{constructor(i,r,n,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=n,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,n)=>{const{unitId:e,scene:t,subUnitId:o}=r,a=this._drawingManagerService.getDrawingDataForUnit(e),c=a==null?void 0:a[o];return c&&c.order.forEach(d=>{this._drawingRenderService.renderDrawing(c.data[d],t)}),n()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,n)=>{const{unitId:e,subUnitId:t}=r,o=this._renderManagerService.getRenderById(e);if(!o)return n(i);const a=o.with(j.SheetSkeletonManagerService).getWorksheetSkeleton(t);if(!a)return n(i);const c=this._drawingManagerService.getDrawingDataForUnit(e),d=c==null?void 0:c[r.subUnitId];if(!d)return n(i);const{scaleX:g,scaleY:l}=o.scene,s=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},u=d.order.map(m=>d.data[m]).filter(m=>m.drawingType!==b.DrawingTypeEnum.DRAWING_DOM);return u.length?(u.forEach(m=>{if(!m.groupId&&m.transform&&p.Tools.isDefine(m.transform.left)&&p.Tools.isDefine(m.transform.top)&&p.Tools.isDefine(m.transform.width)&&p.Tools.isDefine(m.transform.height)){const f=a.skeleton.getCellIndexByOffset(m.transform.left,m.transform.top,g,l,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(m.transform.left+m.transform.width,m.transform.top+m.transform.height,g,l,{x:0,y:0});f.column<s.startColumn&&(s.startColumn=f.column),f.row<s.startRow&&(s.startRow=f.row),s.endRow<S.row&&(s.endRow=S.row),s.endColumn<S.column&&(s.endColumn=S.column)}}),n(s)):n(i)}}))}};Ie=Gt([_e(0,p.Inject(j.SheetPrintInterceptorService)),_e(1,p.Inject(ee.DrawingRenderService)),_e(2,b.IDrawingManagerService),_e(3,N.IRenderManagerService)],Ie);var kt=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,Ft=(i,r,n,e)=>{for(var t=e>1?void 0:e?Vt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&kt(r,n,t),t},Q=(i,r)=>(n,e)=>r(n,e,i);const $t=[I.InsertRowCommand.id,I.InsertColCommand.id,I.RemoveRowCommand.id,I.RemoveColCommand.id,I.DeleteRangeMoveLeftCommand.id,I.DeleteRangeMoveUpCommand.id,I.InsertRangeMoveDownCommand.id,I.InsertRangeMoveRightCommand.id,I.DeltaRowHeightCommand.id,I.SetRowHeightCommand.id,I.DeltaColumnWidthCommand.id,I.SetColWidthCommand.id,I.SetRowHiddenCommand.id,I.SetSpecificRowsVisibleCommand.id,I.SetSpecificColsVisibleCommand.id,I.SetColHiddenCommand.id,I.MoveColsCommand.id,I.MoveRowsCommand.id,I.MoveRangeCommand.id],Yt=[I.SetRowVisibleMutation.id,I.SetRowHiddenMutation.id,I.SetColVisibleMutation.id,I.SetColHiddenMutation.id,I.SetWorksheetRowHeightMutation.id,I.SetWorksheetColWidthMutation.id];let Ae=class extends p.Disposable{constructor(i,r,n,e,t,o,a,c,d){super(),this._context=i,this._renderManagerService=r,this._commandService=n,this._selectionRenderService=e,this._skeletonManagerService=t,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=c,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!$t.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===I.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([I.MoveColsCommand.id,I.MoveRowsCommand.id,I.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===I.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===I.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===I.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===I.DeleteRangeMoveLeftCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,0)}else if(r===I.DeleteRangeMoveUpCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,1)}else if(r===I.InsertRangeMoveDownCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,2)}else if(r===I.InsertRangeMoveRightCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,3)}else if(r===I.SetRowHiddenCommand.id||r===I.SetSpecificRowsVisibleCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForRowVisible(e,t,o)}else if(r===I.SetSpecificColsVisibleCommand.id||r===I.SetColHiddenCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForColVisible(e,t,o)}else if(r===I.DeltaRowHeightCommand.id||r===I.SetRowHeightCommand.id||r===I.DeltaColumnWidthCommand.id||r===I.SetColWidthCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n,a=r===I.DeltaRowHeightCommand.id||r===I.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const n=I.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const e=n.unitId,t=n.subUnitId,o=[],a=[],c=this._sheetDrawingService.getDrawingData(e,t),d=[],g=[];if(Object.keys(c).forEach(l=>{const s=c[l],{updateDrawings:u,deleteDrawings:m}=this._getUpdateOrDeleteDrawings(i,r,s);d.push(...u),g.push(...m)}),d.length===0&&g.length===0)return{redos:[],undos:[]};if(d.length>0){const l=this._sheetDrawingService.getBatchUpdateOp(d),{undo:s,redo:u,objects:m}=l;o.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:u,objects:m,type:h.DrawingApplyType.UPDATE}}),a.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:s,objects:m,type:h.DrawingApplyType.UPDATE}})}if(g.length>0){const l=this._sheetDrawingService.getBatchRemoveOp(g),s=l.undo,u=l.redo,m=l.objects;o.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:u,objects:m,type:h.DrawingApplyType.REMOVE}}),a.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:s,objects:m,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,n){const e=[],t=[],{sheetTransform:o,anchorType:a=h.SheetDrawingAnchorType.Position,transform:c,unitId:d,subUnitId:g,drawingId:l}=n,{from:s,to:u}=o,{row:m,column:f}=s,{row:S,column:v}=u;if(o==null||c==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:y,endRow:M,startColumn:C,endColumn:T}=i;let _=null,D=null;if(r===0&&m>=y&&S<=M)if(f>=C&&v<=T)t.push({unitId:d,subUnitId:g,drawingId:l});else{const w=this._shrinkCol(o,c,C,T,a);_=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(r===1&&f>=C&&v<=T)if(m>=y&&S<=M)t.push({unitId:d,subUnitId:g,drawingId:l});else{const w=this._shrinkRow(o,c,y,M,a);_=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(r===2){const w=this._expandRow(o,c,y,M,a);_=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(r===3){const w=this._expandCol(o,c,C,T,a);_=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}if(_!=null&&D!=null){const w=Y(_,this._selectionRenderService,this._skeletonManagerService);e.push({...n,sheetTransform:_,transform:w})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(i,r,n){const e=k({...i},this._selectionRenderService);e!=null&&r.push({...n,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(l=>{const s=e[l],{sheetTransform:u,transform:m,anchorType:f=h.SheetDrawingAnchorType.Position}=s;if(f===h.SheetDrawingAnchorType.None)this._remainDrawingSize(m,t,s);else{const{from:S,to:v}=u,{row:y,column:M}=S,{row:C,column:T}=v;for(let _=0;_<n.length;_++){const D=n[_],{startRow:w,endRow:A,startColumn:E,endColumn:L}=D;if(T<E)continue;if(f===h.SheetDrawingAnchorType.Position){let R=null,B=null;if(M>=E&&M<=L){const V=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:L,startRow:S.row,endRow:v.row});if(V==null)return;B={...m,left:V.startX}}if(B!=null&&(R=k(B,this._selectionRenderService),R!=null&&B!=null)){t.push({...s,sheetTransform:R,transform:B});break}this._remainDrawingSize(m,t,s);continue}if(M>=E&&T<=L)continue;let U=null,P=null;if(M>=E&&M<=L){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:L,startRow:S.row,endRow:v.row});if(R==null)return;P={...m,left:(R==null?void 0:R.startX)||0,width:((m==null?void 0:m.width)||0)-R.endX+R.startX}}else if(T>=E&&T<=L){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:T,startRow:S.row,endRow:v.row});if(R==null)return;P={...m,left:R.startX-((m==null?void 0:m.width)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:L,startRow:S.row,endRow:v.row});if(R==null)return;if(P={...m,width:((m==null?void 0:m.width)||0)-R.endX+R.startX},U=k(P,this._selectionRenderService),U!=null&&P!=null){o.push({...s,sheetTransform:U,transform:P});break}}if(P!=null&&(U=k(P,this._selectionRenderService)),P!=null&&U!=null){t.push({...s,sheetTransform:U,transform:P});break}else this._remainDrawingSize(m,t,s)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:c}=this._createUndoAndRedoMutation(i,r,t),d=[],g=[];if(o.length>0){const{redos:l,undos:s}=this._createUndoAndRedoMutation(i,r,o);d.push(...l),g.push(...s)}return{redos:a,undos:c,preRedos:d,preUndos:g}}_createUndoAndRedoMutation(i,r,n){const e=this._sheetDrawingService.getBatchUpdateOp(n),{undo:t,redo:o,objects:a}=e,c=[{id:h.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],d=[{id:h.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:t,objects:a,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:c,undos:d}}_getDrawingUndoForRowVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(l=>{const s=e[l],{sheetTransform:u,transform:m,anchorType:f=h.SheetDrawingAnchorType.Position}=s;if(f===h.SheetDrawingAnchorType.None)this._remainDrawingSize(m,t,s);else{const{from:S,to:v}=u,{row:y,column:M}=S,{row:C,column:T}=v;for(let _=0;_<n.length;_++){const D=n[_],{startRow:w,endRow:A,startColumn:E,endColumn:L}=D;if(C<w)continue;if(f===h.SheetDrawingAnchorType.Position){let R=null,B=null;if(y>=w&&y<=A){const V=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:y,endRow:A});if(V==null)return;B={...m,top:V.startY}}if(B!=null&&(R=k(B,this._selectionRenderService),R!=null&&B!=null)){t.push({...s,sheetTransform:R,transform:B});break}this._remainDrawingSize(m,t,s);continue}if(y>=w&&C<=A)continue;let U=null,P=null;if(y>=w&&y<=A){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:y,endRow:A});if(R==null)return;P={...m,top:(R==null?void 0:R.startY)||0,height:((m==null?void 0:m.height)||0)-R.endY+R.startY}}else if(C>=w&&C<=A){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:w,endRow:C});if(R==null)return;P={...m,top:R.startY-((m==null?void 0:m.height)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:w,endRow:A});if(R==null)return;if(P={...m,height:((m==null?void 0:m.height)||0)-R.endY+R.startY},U=k(P,this._selectionRenderService),U!=null&&P!=null){o.push({...s,sheetTransform:U,transform:P});break}}if(P!=null&&(U=k(P,this._selectionRenderService)),P!=null&&U!=null){t.push({...s,sheetTransform:U,transform:P});break}else this._remainDrawingSize(m,t,s)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:c}=this._createUndoAndRedoMutation(i,r,t),d=[],g=[];if(o.length>0){const{redos:l,undos:s}=this._createUndoAndRedoMutation(i,r,o);d.push(...l),g.push(...s)}return{redos:a,undos:c,preRedos:d,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,n,e){const t=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(t).forEach(a=>{const c=t[a],{sheetTransform:d,transform:g,anchorType:l=h.SheetDrawingAnchorType.Position}=c;if(l===h.SheetDrawingAnchorType.None)this._remainDrawingSize(g,o,c);else{const{from:s,to:u}=d,{row:m,column:f}=s,{row:S,column:v}=u;for(let y=0;y<n.length;y++){const M=n[y],{startRow:C,endRow:T,startColumn:_,endColumn:D}=M;if(S<C||v<_)continue;if(l===h.SheetDrawingAnchorType.Position&&(m<=C&&S>=T||f<=_&&v>=D)){this._remainDrawingSize(g,o,c);continue}const w=Y({...d},this._selectionRenderService,this._skeletonManagerService);if(w!=null){o.push({...c,transform:w});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let n,e;if(r==="insert")n=i.unitId,e=i.subUnitId;else{const t=I.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;n=t.unitId,e=t.subUnitId}return{unitId:n,subUnitId:e}}_moveRangeInterceptor(i){var C,T;const{toRange:r,fromRange:n}=i,e=I.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,a=(T=(C=this._renderManagerService.getRenderById(t))==null?void 0:C.with(j.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const c=j.attachRangeWithCoord(a,n);if(!c)return{redos:[],undos:[]};const{startX:d,endX:g,startY:l,endY:s}=c,u=this._sheetDrawingService.getDrawingData(t,o),m=[];Object.keys(u).forEach(_=>{const D=u[_];if(D.anchorType!==h.SheetDrawingAnchorType.Both)return;const{transform:w}=D;if(!w)return;const{left:A=0,top:E=0,width:L=0,height:U=0}=w,{drawingStartX:P,drawingEndX:R,drawingStartY:B,drawingEndY:V}={drawingStartX:A,drawingEndX:A+L,drawingStartY:E,drawingEndY:E+U};d<=P&&R<=g&&l<=B&&V<=s&&m.push(D)});const f=[],S=[],v=r.startRow-n.startRow,y=r.startColumn-n.startColumn,M=m.map(_=>{const D=_.sheetTransform,w={to:{...D.to,row:D.to.row+v,column:D.to.column+y},from:{...D.from,row:D.from.row+v,column:D.from.column+y}},A=Y(w,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:_.drawingId,transform:A,sheetTransform:w}});if(M.length){const _=this._sheetDrawingService.getBatchUpdateOp(M),{undo:D,redo:w,objects:A}=_;f.push({id:h.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:w,objects:A,type:h.DrawingApplyType.UPDATE}}),S.push({id:h.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:D,objects:A,type:h.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startRow,c=o.endRow,d=[],g=[],l=this._sheetDrawingService.getDrawingData(e,t),s=[],u=[];if(Object.keys(l).forEach(m=>{const f=l[m],{sheetTransform:S,transform:v,anchorType:y=h.SheetDrawingAnchorType.Position}=f;if(S==null||v==null)return;let M,C;if(r==="insert"){const _=this._expandRow(S,v,a,c,y);M=_==null?void 0:_.newSheetTransform,C=_==null?void 0:_.newTransform}else{const{from:_,to:D}=S,{row:w}=_,{row:A}=D;if(y===h.SheetDrawingAnchorType.Both&&w>=a&&A<=c)u.push({unitId:e,subUnitId:t,drawingId:m});else{const E=this._shrinkRow(S,v,a,c,y);M=E==null?void 0:E.newSheetTransform,C=E==null?void 0:E.newTransform}}if(!M||!C)return;const T={unitId:e,subUnitId:t,drawingId:m,transform:C,sheetTransform:M};s.push(T)}),s.length===0&&u.length===0)return{redos:[],undos:[]};if(s.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(s),{undo:f,redo:S,objects:v}=m;d.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.UPDATE}}),g.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.UPDATE}})}if(u.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(u),f=m.undo,S=m.redo,v=m.objects;d.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.REMOVE}}),g.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_moveColInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startColumn,c=o.endColumn,d=[],g=[],l=this._sheetDrawingService.getDrawingData(e,t),s=[],u=[];if(Object.keys(l).forEach(m=>{const f=l[m],{sheetTransform:S,transform:v,anchorType:y=h.SheetDrawingAnchorType.Position}=f;if(S==null||v==null)return;let M,C;if(r==="insert"){const _=this._expandCol(S,v,a,c,y);M=_==null?void 0:_.newSheetTransform,C=_==null?void 0:_.newTransform}else{const{from:_,to:D}=S,{column:w}=_,{column:A}=D;if(y===h.SheetDrawingAnchorType.Both&&w>=a&&A<=c)u.push({unitId:e,subUnitId:t,drawingId:m});else{const E=this._shrinkCol(S,v,a,c,y);M=E==null?void 0:E.newSheetTransform,C=E==null?void 0:E.newTransform}}if(!M||!C)return;const T={unitId:e,subUnitId:t,drawingId:m,transform:C,sheetTransform:M};s.push(T)}),s.length===0&&u.length===0)return{redos:[],undos:[]};if(s.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(s),{undo:f,redo:S,objects:v}=m;d.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.UPDATE}}),g.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.UPDATE}})}if(u.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(u),f=m.undo,S=m.redo,v=m.objects;d.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.REMOVE}}),g.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_expandCol(i,r,n,e,t=h.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{column:d}=a,{column:g}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};let l=null,s=null;if(d>=n){const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:e,startRow:a.row,endRow:c.row});if(u==null)return;s={...r,left:(r.left||0)+u.endX-u.startX},l=k(s,this._selectionRenderService)}else if(g>=e)if(t===h.SheetDrawingAnchorType.Both)l={from:{...a},to:{...c,column:g+o}},s=Y(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};return l!=null&&s!=null?{newSheetTransform:l,newTransform:s}:null}_shrinkCol(i,r,n,e,t=h.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{column:d}=a,{column:g}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};let l=null,s=null;if(d>e)l={from:{...a,column:d-o},to:{...c,column:g-o}},s=Y(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=n&&g<=e)return null;if(d<n&&g>e)if(t===h.SheetDrawingAnchorType.Both)l={from:{...a},to:{...c,column:g-o}},s=Y(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};else if(d>=n&&d<=e){if(d===n)s={...r,left:(r.left||0)-i.from.columnOffset};else{const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:d-1,startRow:a.row,endRow:c.row});if(u==null)return;s={...r,left:(r.left||0)-u.endX+u.startX-i.from.columnOffset}}l=k(s,this._selectionRenderService)}else if(g>=n&&g<=e&&t===h.SheetDrawingAnchorType.Both){const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:n-1,endColumn:n-1,startRow:a.row,endRow:c.row});if(u==null)return;l={from:{...a},to:{...c,column:n-1,columnOffset:u.endX-u.startX}},s=Y(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&s!=null?{newSheetTransform:l,newTransform:s}:null}_expandRow(i,r,n,e,t=h.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{row:d}=a,{row:g}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};let l=null,s=null;if(d>=n){const u=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:e,startColumn:a.column,endColumn:c.column});if(u==null)return;s={...r,top:(r.top||0)+u.endY-u.startY},l=k(s,this._selectionRenderService)}else if(g>=e)if(t===h.SheetDrawingAnchorType.Both)l={from:{...a},to:{...c,row:g+o}},s=Y(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};return l!=null&&s!=null?{newSheetTransform:l,newTransform:s}:null}_shrinkRow(i,r,n,e,t=h.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{row:d}=a,{row:g}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};let l=null,s=null;if(d>e)l={from:{...a,row:d-o},to:{...c,row:g-o}},s=Y(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=n&&g<=e)return null;if(d<n&&g>e)if(t===h.SheetDrawingAnchorType.Both)l={from:{...a},to:{...c,row:g-o}},s=Y(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};else if(d>=n&&d<=e){if(d===n)s={...r,top:(r.top||0)-i.from.rowOffset};else{const u=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:d-1,startColumn:a.column,endColumn:c.column});if(u==null)return;s={...r,top:(r.top||0)-u.endY+u.startY-i.from.rowOffset}}l=k(s,this._selectionRenderService)}else if(g>=n&&g<=e&&t===h.SheetDrawingAnchorType.Both){const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:n-1,endRow:n-1});if(u==null)return;l={from:{...a},to:{...c,row:n-1,rowOffset:u.endY-u.startY}},s=Y(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&s!=null?{newSheetTransform:l,newTransform:s}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===I.SetWorksheetActiveOperation.id&&setTimeout(()=>{const r=i.params,{unitId:n,subUnitId:e}=r,t=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(t).forEach(c=>{const d=t[c];d!=null&&Object.keys(d).forEach(g=>{const l=d[g].data;l!=null&&Object.keys(l).forEach(s=>{if(c===n&&g===e){const u=l[s];u.transform=Y(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(l[s])}else a.push(l[s])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Yt.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:n,subUnitId:e,ranges:t}=r;this._refreshDrawingTransform(n,e,t)})}))}_refreshDrawingTransform(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:c,transform:d,anchorType:g=h.SheetDrawingAnchorType.Position}=a;if(g===h.SheetDrawingAnchorType.None)return!0;const{from:l,to:s}=c,{row:u,column:m}=l,{row:f,column:S}=s;for(let v=0;v<n.length;v++){const y=n[v],{startRow:M,endRow:C,startColumn:T,endColumn:_}=y;if(p.Rectangle.intersects({startRow:M,endRow:C,startColumn:T,endColumn:_},{startRow:u,endRow:f,startColumn:m,endColumn:S})||u>C||m>_){const D=g===h.SheetDrawingAnchorType.Position,w=Y(c,this._selectionRenderService,this._skeletonManagerService);t.push({...a,transform:{...w,width:D?d==null?void 0:d.width:w==null?void 0:w.width,height:D?d==null?void 0:d.height:w==null?void 0:w.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(G.id,[i]))}};Ae=Ft([Q(1,N.IRenderManagerService),Q(2,p.ICommandService),Q(3,j.ISheetSelectionRenderService),Q(4,p.Inject(j.SheetSkeletonManagerService)),Q(5,p.Inject(I.SheetInterceptorService)),Q(6,h.ISheetDrawingService),Q(7,b.IDrawingManagerService),Q(8,p.IUniverInstanceService)],Ae);var xt=Object.defineProperty,Ht=Object.getOwnPropertyDescriptor,Xt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Ht(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&xt(r,n,t),t},ne=(i,r)=>(n,e)=>r(n,e,i);function Kt(i,r,n,e){const{scaleX:t,scaleY:o}=r.getAncestorScale(),a=r.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN),c={left:!0,top:!0};if(!a)return{...i,absolute:c};const{left:d,right:g,top:l,bottom:s}=i,u=e.getFreeze(),{startColumn:m,startRow:f,xSplit:S,ySplit:v}=u,y=n.getNoMergeCellPositionByIndexWithNoHeader(f-v,m-S),M=n.getNoMergeCellPositionByIndexWithNoHeader(f,m),{rowHeaderWidth:C,columnHeaderHeight:T}=n,_=M.startX-y.startX,D=M.startY-y.startY,{top:w,left:A,viewportScrollX:E,viewportScrollY:L}=a;let U,P;d<A?(c.left=!0,U=(_+C+(d-A))*t,P=Math.max(Math.min((_+C+(g-A))*t,(_+C)*t),(g-E)*t)):(c.left=!1,U=Math.max((d-E)*t,(_+C)*t),P=Math.max((g-E)*t,(_+C)*t));let R,B;return l<w?(c.top=!0,R=(D+T+(l-w))*o,B=Math.max(Math.min((D+T+(g-w))*o,(D+T)*o),(s-L)*o)):(c.top=!1,R=Math.max((l-L)*o,(D+T)*o),B=Math.max((s-L)*o,(D+T)*o)),{left:U,right:P,top:R,bottom:B,absolute:c}}const Ue=(i,r,n,e)=>{const{scene:t}=r,{left:o,top:a,width:c,height:d,angle:g}=i,l={left:o,right:o+c,top:a,bottom:a+d},s=Kt(l,t,n,e),{scaleX:u,scaleY:m}=t.getAncestorScale();return{startX:s.left,endX:s.right,startY:s.top,endY:s.bottom,rotate:g,width:c*u,height:d*m,absolute:s.absolute}};O.SheetCanvasFloatDomManagerService=class extends p.Disposable{constructor(n,e,t,o,a,c,d){super();X(this,"_domLayerMap",new Map);X(this,"_domLayerInfoMap",new Map);X(this,"_transformChange$",new W.Subject);X(this,"transformChange$",this._transformChange$.asObservable());X(this,"_add$",new W.Subject);X(this,"add$",this._add$.asObservable());X(this,"_remove$",new W.Subject);X(this,"remove$",this._remove$.asObservable());X(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=c,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(W.filter(n=>n===p.LifecycleStages.Rendered),W.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(n,e){let t=this._domLayerMap.get(n);t||(t=new Map,this._domLayerMap.set(n,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(n){return this._domLayerInfoMap.get(n)}_getSceneAndTransformerByDrawingSearch(n){if(n==null)return;const e=this._renderManagerService.getRenderById(n),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:t,transformer:o,renderObject:e,canvas:a}}_getFloatDomProps(n){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(n)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(n=>{n.forEach(e=>{var Ke,ze,Je;const{unitId:t,subUnitId:o,drawingId:a}=e,c=I.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(t);if(!g)return;const l=g.getActiveSheet().getSheetId();if(!d||!c)return;const s=(Ke=this._renderManagerService.getRenderById(t))==null?void 0:Ke.with(j.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!s)return;const{transform:u,drawingType:m,data:f}=d;if(m!==b.DrawingTypeEnum.DRAWING_DOM&&m!==b.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(t);if(S==null)return;const{scene:v,canvas:y}=S;if(u==null)return!0;if(l!==o)return;const{left:M,top:C,width:T,height:_,angle:D,flipX:w,flipY:A,skewX:E,skewY:L}=u,U=b.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),P=v.getObject(U);if(P!=null){P.transformByState({left:M,top:C,width:T,height:_,angle:D,flipX:w,flipY:A,skewX:E,skewY:L});return}const R={left:M,top:C,width:T,height:_,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},B=m===b.DrawingTypeEnum.DRAWING_CHART;B&&(R.fill="white",R.rotateEnabled=!1,f&&f.border&&(R.stroke=f.border),R.paintFirst="stroke",R.strokeWidth=1,R.borderEnabled=!1,R.radius=8);const V=new N.Rect(U,R);B&&V.setObjectType(N.ObjectType.CHART),v.addObject(V,N.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&v.attachTransformerTo(V);const J=this._ensureMap(t,o),je=new p.DisposableCollection,Qt=Ue(V,S.renderObject,s.skeleton,c.worksheet),We=new W.BehaviorSubject(Qt),en={dispose:je,rect:V,position$:We,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:We,id:a,componentKey:d.componentKey,onPointerDown:H=>{y.dispatchEvent(new PointerEvent(H.type,H))},onPointerMove:H=>{y.dispatchEvent(new PointerEvent(H.type,H))},onPointerUp:H=>{y.dispatchEvent(new PointerEvent(H.type,H))},onWheel:H=>{y.dispatchEvent(new WheelEvent(H.type,H))},props:(Je=(ze=J.get(a))==null?void 0:ze.props)!=null?Je:this._getFloatDomProps(a),data:f,unitId:t});const Xe=V.onTransformChange$.subscribeEvent(()=>{const H=Ue(V,S.renderObject,s.skeleton,c.worksheet);We.next(H)});je.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),Xe&&je.add(Xe),this._domLayerInfoMap.set(a,en),J.set(a,{...J.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a}=e,c=b.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),d=this._getSceneAndTransformerByDrawingSearch(t);if(d==null)return;const{transformer:g,scene:l}=d,s=l.getObject(c);s!=null&&s.oKey&&g.clearControlByIds([s==null?void 0:s.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var l;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,t),c=Array.from(a.keys()),d=I.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),g=(l=this._renderManagerService.getRenderById(e))==null?void 0:l.with(j.SheetSkeletonManagerService).getWorksheetSkeleton(t);!o||!d||!g||c.forEach(s=>{const u=this._domLayerInfoMap.get(s);if(u){const m=Ue(u.rect,o.renderObject,g.skeleton,d.worksheet);u.position$.next(m)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET).pipe(W.filter(e=>!!e),W.switchMap(e=>e.activeSheet$),W.filter(e=>!!e),W.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),W.filter(e=>!!e),W.switchMap(e=>p.fromEventSubject(e.render.scene.getViewport(j.VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(W.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{n(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===j.SetZoomRatioOperation.id){const a=e.params,{unitId:c}=a;Array.from((o=(t=this._domLayerMap.get(c))==null?void 0:t.keys())!=null?o:[]).forEach(g=>{n(c,g)})}else if(e.id===I.SetFrozenMutation.id){const{unitId:a,subUnitId:c}=e.params;n(a,c)}}))}_getPosition(n,e){var m;const{startX:t,endX:o,startY:a,endY:c}=n,d=(m=this._renderManagerService.getRenderById(e))==null?void 0:m.with(j.ISheetSelectionRenderService);if(d==null)return;const g=d.getCellWithCoordByOffset(t,a);if(g==null)return;const l={column:g.actualColumn,columnOffset:t-g.startX,row:g.actualRow,rowOffset:a-g.startY},s=d.getCellWithCoordByOffset(o,c);if(s==null)return;const u={column:s.actualColumn,columnOffset:o-s.startX,row:s.actualRow,rowOffset:c-s.startY};return{from:l,to:u}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==b.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==b.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(n,e,t,o){const a=this._domLayerInfoMap.get(t),c=this._getSceneAndTransformerByDrawingSearch(n);if(a&&c){const{scene:d}=c,g=b.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),l=d.getObject(g);l&&l instanceof N.Rect&&l.setProps(o)}}addFloatDomToPosition(n,e){const t=I.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=t,{initPosition:c,componentKey:d,data:g,allowTransform:l=!0}=n,s=e!=null?e:p.generateRandomId(),u=this._getPosition(c,o);if(u==null)return;this._ensureMap(o,a).set(s,n);const f={unitId:o,subUnitId:a,drawingId:s,drawingType:n.type||b.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:u,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},data:g,allowTransform:l};return this._commandService.executeCommand(ae.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:a,id:s}),{id:s,dispose:()=>{this._removeDom(s,!0)}}}_removeDom(n,e=!1){const t=this._domLayerInfoMap.get(n);if(!t)return;const{unitId:o,subUnitId:a}=t;this._domLayerInfoMap.delete(n),t.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(t.rect),e){this._ensureMap(o,a).delete(n);const g=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:n});if(!g)return;const l=this._sheetDrawingService.getBatchRemoveOp([g]),{redo:s,objects:u}=l;this._commandService.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:s,objects:u,type:h.DrawingApplyType.REMOVE})}}addHook(n){return this._hooks.push(n),{dispose:()=>{const e=this._hooks.findIndex(t=>t===n);this._hooks.splice(e,1)}}}},O.SheetCanvasFloatDomManagerService=Xt([ne(0,p.Inject(N.IRenderManagerService)),ne(1,p.IUniverInstanceService),ne(2,p.Inject(p.ICommandService)),ne(3,b.IDrawingManagerService),ne(4,p.Inject(F.CanvasFloatDomService)),ne(5,h.ISheetDrawingService),ne(6,p.Inject(p.LifecycleService))],O.SheetCanvasFloatDomManagerService);var xe=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Jt=(i,r,n)=>r in i?xe(i,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[r]=n,qt=(i,r,n,e)=>{for(var t=e>1?void 0:e?zt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&xe(r,n,t),t},Ne=(i,r)=>(n,e)=>r(n,e,i),He=(i,r,n)=>Jt(i,typeof r!="symbol"?r+"":r,n);const Zt="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends p.Plugin{constructor(r=Ze,n,e,t){super(),this._config=r,this._injector=n,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=this._config;o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(qe,a)}onStarting(){p.registerDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService],[Se],[ue],[Ie],[we],[ve]]),p.touchDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService]])}onReady(){p.touchDependencies(this._injector,[[ve]])}onRendered(){this._registerRenderModules(),p.touchDependencies(this._injector,[[we],[Ie],[Se]])}onSteady(){this._injector.get(ue)}_registerRenderModules(){[[ge],[Ae],[De]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(p.UniverInstanceType.UNIVER_SHEET,r))})}},He(O.UniverSheetsDrawingUIPlugin,"type",p.UniverInstanceType.UNIVER_SHEET),He(O.UniverSheetsDrawingUIPlugin,"pluginName",Zt),O.UniverSheetsDrawingUIPlugin=qt([p.DependentOn(b.UniverDrawingPlugin,ee.UniverDrawingUIPlugin,h.UniverSheetsDrawingPlugin),Ne(1,p.Inject(p.Injector)),Ne(2,N.IRenderManagerService),Ne(3,p.IConfigService)],O.UniverSheetsDrawingUIPlugin),O.ClearSheetDrawingTransformerOperation=G,O.DeleteDrawingsCommand=Re,O.EditSheetDrawingOperation=ye,O.GroupSheetDrawingCommand=Te,O.IMAGE_MENU_ID=Oe,O.InsertFloatImageCommand=pe,O.InsertSheetDrawingCommand=ae,O.MoveDrawingsCommand=re,O.RemoveSheetDrawingCommand=ie,O.SetDrawingArrangeCommand=be,O.SetSheetDrawingCommand=se,O.SidebarSheetDrawingOperation=Ce,O.UngroupSheetDrawingCommand=Ee,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
9
+ */var Be;function Qe(){if(Be)return oe;Be=1;var i=H,r=Symbol.for("react.element"),n=Symbol.for("react.fragment"),e=Object.prototype.hasOwnProperty,t=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function a(c,d,p){var l,s={},u=null,m=null;p!==void 0&&(u=""+p),d.key!==void 0&&(u=""+d.key),d.ref!==void 0&&(m=d.ref);for(l in d)e.call(d,l)&&!o.hasOwnProperty(l)&&(s[l]=d[l]);if(c&&c.defaultProps)for(l in d=c.defaultProps,d)s[l]===void 0&&(s[l]=d[l]);return{$$typeof:r,type:c,key:u,ref:m,props:s,_owner:t.current}}return oe.Fragment=n,oe.jsx=a,oe.jsxs=a,oe}var Ge;function et(){return Ge||(Ge=1,Me.exports=Qe()),Me.exports}var $=et();const le={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},tt=()=>{const i=g.useDependency(A.IImageIoService),r=g.useDependency(g.LocaleService),[n,e]=H.useState(0);return H.useEffect(()=>{const t=i.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[i]),$.jsx("div",{style:{display:n>0?"block":"none"},className:le.uploadLoading,children:$.jsxs("div",{className:le.uploadLoadingBody,children:[$.jsx("div",{className:le.uploadLoadingBodyAnimation}),$.jsx("div",{className:le.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${n}`})]})})};var nt=Object.defineProperty,rt=Object.getOwnPropertyDescriptor,it=(i,r,n,e)=>{for(var t=e>1?void 0:e?rt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&nt(r,n,t),t},te=(i,r)=>(n,e)=>r(n,e,i);let ue=class extends g.RxDisposable{constructor(r,n,e,t,o,a,c){super();X(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=n,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=c,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(g.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(g.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(F.BuiltInUIPart.CONTENT,()=>g.connectInjector(tt,this._injector))}_dispose(r){const n=r.getUnitId();this._renderManagerService.removeRender(n)}_create(r){if(!r)return;const n=r.getUnitId();this._renderManagerService.has(n)&&!this._initImagePopupMenu.has(n)&&(this._popupMenuListener(n),this._initImagePopupMenu.add(n))}_hasCropObject(r){const n=r.getAllObjectsByOrder();for(const e of n)if(e instanceof ee.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const n=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!n)return;const e=n.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(g.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(n))return;const a=e.getSelectedObjectMap();if(a.size>1){t==null||t.dispose();return}const c=a.values().next().value;if(!c)return;const d=c.oKey,p=this._drawingManagerService.getDrawingOKey(d);if(!p)return;const{unitId:l,subUnitId:s,drawingId:u,drawingType:m}=p,f=p.data;if(f&&f.disablePopup)return;t==null||t.dispose();const S=this._canvasPopManagerService.getFeatureMenu(l,s,u,m);t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:ee.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(l,s,u,m)}})),this._drawingManagerService.focusDrawing([{unitId:l,subUnitId:s,drawingId:u}])}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.dispose(),this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(e.changing$.subscribe(()=>{t==null||t.dispose()}))}_getImageMenuItems(r,n,e,t){return[{label:"image-popup.edit",index:0,commandId:ye.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===g.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ie.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:n,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ee.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===g.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ee.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:n,drawingId:e}],disable:t===g.DrawingTypeEnum.DRAWING_DOM}]}};ue=it([te(0,g.Inject(g.Injector)),te(1,A.IDrawingManagerService),te(2,g.Inject(j.SheetCanvasPopManagerService)),te(3,N.IRenderManagerService),te(4,g.IUniverInstanceService),te(5,g.IContextService),te(6,g.Inject(F.IUIPartsService))],ue);function Y(i,r,n){const{from:e,to:t,flipY:o=!1,flipX:a=!1,angle:c=0,skewX:d=0,skewY:p=0}=i,{column:l,columnOffset:s,row:u,rowOffset:m}=e,{column:f,columnOffset:S,row:w,rowOffset:y}=t,M=n.getCurrentSkeleton(),C=j.attachRangeWithCoord(M,{startColumn:l,endColumn:l,startRow:u,endRow:u});if(C==null)return;const T=j.attachRangeWithCoord(M,{startColumn:f,endColumn:f,startRow:w,endRow:w});if(T==null)return;const{startX:_,startY:D}=C,{startX:v,startY:P}=T;let b=N.precisionTo(_+s,1),L=N.precisionTo(D+m,1),U=N.precisionTo(v+S-b,1),O=N.precisionTo(P+y-L,1);C.startX===T.endX&&(U=0),C.startY===T.endY&&(O=0);const R=M.rowHeaderWidth+M.columnTotalWidth,B=M.columnHeaderHeight+M.rowTotalHeight;return b+U>R&&(b=R-U),L+O>B&&(L=B-O),{flipY:o,flipX:a,angle:c,skewX:d,skewY:p,left:b,top:L,width:U,height:O}}function k(i,r){const{left:n=0,top:e=0,width:t=0,height:o=0,flipY:a=!1,flipX:c=!1,angle:d=0,skewX:p=0,skewY:l=0}=i,s=r.getCellWithCoordByOffset(n,e);if(s==null)return;const u={column:s.actualColumn,columnOffset:N.precisionTo(n-s.startX,1),row:s.actualRow,rowOffset:N.precisionTo(e-s.startY,1)},m=r.getCellWithCoordByOffset(n+t,e+o);if(m==null)return;const f={column:m.actualColumn,columnOffset:N.precisionTo(n+t-m.startX,1),row:m.actualRow,rowOffset:N.precisionTo(e+o-m.startY,1)};return{flipY:a,flipX:c,angle:d,skewX:p,skewY:l,from:u,to:f}}var ot=Object.defineProperty,at=Object.getOwnPropertyDescriptor,st=(i,r,n,e)=>{for(var t=e>1?void 0:e?at(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&ot(r,n,t),t},me=(i,r)=>(n,e)=>r(n,e,i);let De=class extends g.Disposable{constructor(i,r,n,e,t){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=n,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=t,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const n=i[r];for(const e in n.data){const t=n.data[e];t.transform=Y(t.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};De=st([me(1,h.ISheetDrawingService),me(2,A.IDrawingManagerService),me(3,g.Inject(j.ISheetSelectionRenderService)),me(4,g.Inject(j.SheetSkeletonManagerService))],De);var ct=Object.defineProperty,dt=Object.getOwnPropertyDescriptor,lt=(i,r,n,e)=>{for(var t=e>1?void 0:e?dt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&ct(r,n,t),t},Re=(i,r)=>(n,e)=>r(n,e,i);let ge=class extends g.Disposable{constructor(r,n,e){super();X(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=n,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,n,e)=>this._collect(r,n,e),onPasteCells:(r,n,e,t)=>{const{copyType:o=j.COPY_TYPE.COPY,pasteType:a}=t,{range:c}=r||{},{range:d,unitId:p,subUnitId:l}=n;return this._generateMutations(d,{copyType:o,pasteType:a,copyRange:c,unitId:p,subUnitId:l})},onPastePlainText:(r,n)=>({undos:[],redos:[]})})}_collect(r,n,e){var u;const t=(u=this._renderManagerService.getRenderById(r))==null?void 0:u.with(j.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:c,startY:d,endY:p}=o,l=this._sheetDrawingService.getDrawingData(r,n),s=[];Object.keys(l).forEach(m=>{const f=l[m],{transform:S}=f;if(f.anchorType!==h.SheetDrawingAnchorType.Both||!S)return;const{left:w=0,top:y=0,width:M=0,height:C=0}=S,{drawingStartX:T,drawingEndX:_,drawingStartY:D,drawingEndY:v}={drawingStartX:w,drawingEndX:w+M,drawingStartY:y,drawingEndY:y+C};a<=T&&_<=c&&d<=D&&v<=p&&s.push(f)}),s.length&&(this._copyInfo={drawings:s,unitId:r,subUnitId:n})}_generateMutations(r,n){var b;if(!this._copyInfo)return{redos:[],undos:[]};if([j.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,j.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,j.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,j.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(n.pasteType))return{redos:[],undos:[]};const{copyRange:e}=n;if(!e)return{redos:[],undos:[]};const{drawings:t,unitId:o,subUnitId:a}=this._copyInfo,{ranges:[c,d],mapFunc:p}=j.virtualizeDiscreteRanges([e,r]),{row:l,col:s}=p(c.startRow,c.startColumn),{row:u,col:m}=p(d.startRow,d.startColumn),f=(b=this._renderManagerService.getRenderById(o))==null?void 0:b.with(j.SheetSkeletonManagerService);if(!f)return{redos:[],undos:[]};const S=f.attachRangeWithCoord({startRow:l,endRow:l,startColumn:s,endColumn:s}),w=f.attachRangeWithCoord({startRow:u,endRow:u,startColumn:m,endColumn:m});if(!S||!w)return{redos:[],undos:[]};const y=[],M=[],C=w.startX-S.startX,T=w.startY-S.startY,_=u-l,D=m-s,v=n.copyType===j.COPY_TYPE.CUT,{_sheetDrawingService:P}=this;return t.forEach(L=>{const{transform:U,sheetTransform:O}=L;if(!U)return;const R={...L,unitId:o,subUnitId:a,drawingId:v?L.drawingId:g.Tools.generateRandomId(),transform:{...U,left:U.left+C,top:U.top+T},sheetTransform:{to:{...O.to,row:O.to.row+_,column:O.to.column+D},from:{...O.from,row:O.from.row+_,column:O.from.column+D}}};if(v){const{undo:B,redo:V,objects:J}=P.getBatchUpdateOp([R]);y.push({id:h.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:h.DrawingApplyType.UPDATE,op:V,objects:J}}),M.push({id:h.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:h.DrawingApplyType.UPDATE,op:B,objects:J}})}else{const{undo:B,redo:V,objects:J}=P.getBatchAddOp([R]);y.push({id:h.SetDrawingApplyMutation.id,params:{op:V,unitId:o,subUnitId:a,objects:J,type:h.DrawingApplyType.INSERT}}),M.push({id:h.SetDrawingApplyMutation.id,params:{op:B,unitId:o,subUnitId:a,objects:J,type:h.DrawingApplyType.REMOVE}})}}),{redos:y,undos:M}}};ge=lt([Re(0,j.ISheetClipboardService),Re(1,N.IRenderManagerService),Re(2,h.ISheetDrawingService)],ge);var ut=Object.defineProperty,mt=Object.getOwnPropertyDescriptor,gt=(i,r,n,e)=>{for(var t=e>1?void 0:e?mt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&ut(r,n,t),t},ae=(i,r)=>(n,e)=>r(n,e,i);let pe=class extends g.Disposable{constructor(i,r,n,e,t){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=n,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingVisible(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new I.WorkbookViewPermission(t).id,new I.WorksheetViewPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const c=r.getUnitId(),d=e.getSheetId(),p=this._drawingManagerService.getDrawingData(c,d),l=Object.values(p),s=this._renderManagerService.getRenderById(c),u=s==null?void 0:s.scene;if(u==null)return;u.getAllObjectsByOrder().forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&l.some(S=>f.oKey.includes(S.drawingId))&&u.removeObject(f)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingEditable(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new I.WorkbookEditablePermission(t).id,new I.WorksheetEditPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const c=r.getUnitId(),d=e.getSheetId(),p=this._drawingManagerService.getDrawingData(c,d),l=Object.values(p),s=this._renderManagerService.getRenderById(c),u=s==null?void 0:s.scene;if(u==null)return;u.getAllObjectsByOrder().forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&l.some(S=>f.oKey.includes(S.drawingId))&&u.detachTransformerFrom(f)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const c=this._renderManagerService.getRenderById(t),d=c==null?void 0:c.scene;if(d==null)return;const p=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new I.WorkbookViewPermission(t).id,new I.WorksheetViewPermission(t,o).id]).pipe(W.map(u=>u.every(m=>m.value)));l==null||l.pipe(W.filter(u=>u!==a),W.distinctUntilChanged()).subscribe({next:u=>{a=u,this._drawingManagerService.setDrawingVisible(u);const m=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);u?this._drawingManagerService.addNotification(S):(m.forEach(w=>{w.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(y=>w.oKey.includes(y.drawingId))&&d.removeObject(w)}),p.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new I.WorksheetViewPermission(t,o).id))==null||s.pipe(W.filter(u=>u.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const u=this._drawingManagerService.getDrawingData(t,o),m=Object.values(u);this._drawingManagerService.addNotification(m)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const c=this._renderManagerService.getRenderById(t),d=c==null?void 0:c.scene;if(d==null)return;const p=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new I.WorkbookEditablePermission(t).id,new I.WorksheetEditPermission(t,o).id]).pipe(W.map(u=>u.every(m=>m.value)));l==null||l.pipe(W.filter(u=>u!==a),W.distinctUntilChanged()).subscribe({next:u=>{a=u,this._drawingManagerService.setDrawingEditable(u);const m=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);u?(m.forEach(w=>{w.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(y=>w.oKey.includes(y.drawingId))&&d.attachTransformerTo(w)}),this._drawingManagerService.addNotification(S)):(m.forEach(w=>{w.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(y=>w.oKey.includes(y.drawingId))&&d.detachTransformerFrom(w)}),p.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new I.WorksheetEditPermission(t,o).id))==null||s.pipe(W.filter(u=>u.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const u=r.getUnitId(),m=e.getSheetId(),f=this._drawingManagerService.getDrawingData(u,m),S=Object.values(f),w=this._renderManagerService.getRenderById(u),y=w==null?void 0:w.scene;if(y==null)return;this._drawingManagerService.setDrawingEditable(!0),y.getAllObjectsByOrder().forEach(C=>{C.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(T=>C.oKey.includes(T.drawingId))&&y.detachTransformerFrom(C)})}})})}))}};pe=gt([ae(0,A.IDrawingManagerService),ae(1,N.IRenderManagerService),ae(2,g.IPermissionService),ae(3,g.IUniverInstanceService),ae(4,g.Inject(g.UserManagerService))],pe);var pt=Object.defineProperty,ht=Object.getOwnPropertyDescriptor,ft=(i,r,n,e)=>{for(var t=e>1?void 0:e?ht(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&pt(r,n,t),t},he=(i,r)=>(n,e)=>r(n,e,i);let fe=class extends g.Disposable{constructor(i,r,n,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=n,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,n)=>{const{unitId:e,scene:t,subUnitId:o}=r,a=this._drawingManagerService.getDrawingDataForUnit(e),c=a==null?void 0:a[o];return c&&c.order.forEach(d=>{this._drawingRenderService.renderDrawing(c.data[d],t)}),n()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,n)=>{const{unitId:e,subUnitId:t}=r,o=this._renderManagerService.getRenderById(e);if(!o)return n(i);const a=o.with(j.SheetSkeletonManagerService).getWorksheetSkeleton(t);if(!a)return n(i);const c=this._drawingManagerService.getDrawingDataForUnit(e),d=c==null?void 0:c[r.subUnitId];if(!d)return n(i);const{scaleX:p,scaleY:l}=o.scene,s=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},u=d.order.map(m=>d.data[m]).filter(m=>m.drawingType!==g.DrawingTypeEnum.DRAWING_DOM);return u.length?(u.forEach(m=>{if(!m.groupId&&m.transform&&g.Tools.isDefine(m.transform.left)&&g.Tools.isDefine(m.transform.top)&&g.Tools.isDefine(m.transform.width)&&g.Tools.isDefine(m.transform.height)){const f=a.skeleton.getCellIndexByOffset(m.transform.left,m.transform.top,p,l,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(m.transform.left+m.transform.width,m.transform.top+m.transform.height,p,l,{x:0,y:0});f.column<s.startColumn&&(s.startColumn=f.column),f.row<s.startRow&&(s.startRow=f.row),s.endRow<S.row&&(s.endRow=S.row),s.endColumn<S.column&&(s.endColumn=S.column)}}),n(s)):n(i)}}))}};fe=ft([he(0,g.Inject(j.SheetPrintInterceptorService)),he(1,g.Inject(ee.DrawingRenderService)),he(2,A.IDrawingManagerService),he(3,N.IRenderManagerService)],fe);var St=Object.defineProperty,wt=Object.getOwnPropertyDescriptor,vt=(i,r,n,e)=>{for(var t=e>1?void 0:e?wt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&St(r,n,t),t},Z=(i,r)=>(n,e)=>r(n,e,i);const _t=[I.InsertRowCommand.id,I.InsertColCommand.id,I.RemoveRowCommand.id,I.RemoveColCommand.id,I.DeleteRangeMoveLeftCommand.id,I.DeleteRangeMoveUpCommand.id,I.InsertRangeMoveDownCommand.id,I.InsertRangeMoveRightCommand.id,I.DeltaRowHeightCommand.id,I.SetRowHeightCommand.id,I.DeltaColumnWidthCommand.id,I.SetColWidthCommand.id,I.SetRowHiddenCommand.id,I.SetSpecificRowsVisibleCommand.id,I.SetSpecificColsVisibleCommand.id,I.SetColHiddenCommand.id,I.MoveColsCommand.id,I.MoveRowsCommand.id,I.MoveRangeCommand.id],It=[I.SetRowVisibleMutation.id,I.SetRowHiddenMutation.id,I.SetColVisibleMutation.id,I.SetColHiddenMutation.id,I.SetWorksheetRowHeightMutation.id,I.SetWorksheetColWidthMutation.id];let Te=class extends g.Disposable{constructor(i,r,n,e,t,o,a,c,d){super(),this._context=i,this._renderManagerService=r,this._commandService=n,this._selectionRenderService=e,this._skeletonManagerService=t,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=c,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!_t.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===I.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([I.MoveColsCommand.id,I.MoveRowsCommand.id,I.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===I.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===I.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===I.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===I.DeleteRangeMoveLeftCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,0)}else if(r===I.DeleteRangeMoveUpCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,1)}else if(r===I.InsertRangeMoveDownCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,2)}else if(r===I.InsertRangeMoveRightCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,3)}else if(r===I.SetRowHiddenCommand.id||r===I.SetSpecificRowsVisibleCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForRowVisible(e,t,o)}else if(r===I.SetSpecificColsVisibleCommand.id||r===I.SetColHiddenCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForColVisible(e,t,o)}else if(r===I.DeltaRowHeightCommand.id||r===I.SetRowHeightCommand.id||r===I.DeltaColumnWidthCommand.id||r===I.SetColWidthCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n,a=r===I.DeltaRowHeightCommand.id||r===I.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const n=I.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const e=n.unitId,t=n.subUnitId,o=[],a=[],c=this._sheetDrawingService.getDrawingData(e,t),d=[],p=[];if(Object.keys(c).forEach(l=>{const s=c[l],{updateDrawings:u,deleteDrawings:m}=this._getUpdateOrDeleteDrawings(i,r,s);d.push(...u),p.push(...m)}),d.length===0&&p.length===0)return{redos:[],undos:[]};if(d.length>0){const l=this._sheetDrawingService.getBatchUpdateOp(d),{undo:s,redo:u,objects:m}=l;o.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:u,objects:m,type:h.DrawingApplyType.UPDATE}}),a.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:s,objects:m,type:h.DrawingApplyType.UPDATE}})}if(p.length>0){const l=this._sheetDrawingService.getBatchRemoveOp(p),s=l.undo,u=l.redo,m=l.objects;o.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:u,objects:m,type:h.DrawingApplyType.REMOVE}}),a.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:s,objects:m,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,n){const e=[],t=[],{sheetTransform:o,anchorType:a=h.SheetDrawingAnchorType.Position,transform:c,unitId:d,subUnitId:p,drawingId:l}=n,{from:s,to:u}=o,{row:m,column:f}=s,{row:S,column:w}=u;if(o==null||c==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:y,endRow:M,startColumn:C,endColumn:T}=i;let _=null,D=null;if(r===0&&m>=y&&S<=M)if(f>=C&&w<=T)t.push({unitId:d,subUnitId:p,drawingId:l});else{const v=this._shrinkCol(o,c,C,T,a);_=v==null?void 0:v.newSheetTransform,D=v==null?void 0:v.newTransform}else if(r===1&&f>=C&&w<=T)if(m>=y&&S<=M)t.push({unitId:d,subUnitId:p,drawingId:l});else{const v=this._shrinkRow(o,c,y,M,a);_=v==null?void 0:v.newSheetTransform,D=v==null?void 0:v.newTransform}else if(r===2){const v=this._expandRow(o,c,y,M,a);_=v==null?void 0:v.newSheetTransform,D=v==null?void 0:v.newTransform}else if(r===3){const v=this._expandCol(o,c,C,T,a);_=v==null?void 0:v.newSheetTransform,D=v==null?void 0:v.newTransform}if(_!=null&&D!=null){const v=Y(_,this._selectionRenderService,this._skeletonManagerService);e.push({...n,sheetTransform:_,transform:v})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(i,r,n){const e=k({...i},this._selectionRenderService);e!=null&&r.push({...n,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(l=>{const s=e[l],{sheetTransform:u,transform:m,anchorType:f=h.SheetDrawingAnchorType.Position}=s;if(f===h.SheetDrawingAnchorType.None)this._remainDrawingSize(m,t,s);else{const{from:S,to:w}=u,{row:y,column:M}=S,{row:C,column:T}=w;for(let _=0;_<n.length;_++){const D=n[_],{startRow:v,endRow:P,startColumn:b,endColumn:L}=D;if(T<b)continue;if(f===h.SheetDrawingAnchorType.Position){let R=null,B=null;if(M>=b&&M<=L){const V=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:L,startRow:S.row,endRow:w.row});if(V==null)return;B={...m,left:V.startX}}if(B!=null&&(R=k(B,this._selectionRenderService),R!=null&&B!=null)){t.push({...s,sheetTransform:R,transform:B});break}this._remainDrawingSize(m,t,s);continue}if(M>=b&&T<=L)continue;let U=null,O=null;if(M>=b&&M<=L){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:L,startRow:S.row,endRow:w.row});if(R==null)return;O={...m,left:(R==null?void 0:R.startX)||0,width:((m==null?void 0:m.width)||0)-R.endX+R.startX}}else if(T>=b&&T<=L){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:T,startRow:S.row,endRow:w.row});if(R==null)return;O={...m,left:R.startX-((m==null?void 0:m.width)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:L,startRow:S.row,endRow:w.row});if(R==null)return;if(O={...m,width:((m==null?void 0:m.width)||0)-R.endX+R.startX},U=k(O,this._selectionRenderService),U!=null&&O!=null){o.push({...s,sheetTransform:U,transform:O});break}}if(O!=null&&(U=k(O,this._selectionRenderService)),O!=null&&U!=null){t.push({...s,sheetTransform:U,transform:O});break}else this._remainDrawingSize(m,t,s)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:c}=this._createUndoAndRedoMutation(i,r,t),d=[],p=[];if(o.length>0){const{redos:l,undos:s}=this._createUndoAndRedoMutation(i,r,o);d.push(...l),p.push(...s)}return{redos:a,undos:c,preRedos:d,preUndos:p}}_createUndoAndRedoMutation(i,r,n){const e=this._sheetDrawingService.getBatchUpdateOp(n),{undo:t,redo:o,objects:a}=e,c=[{id:h.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],d=[{id:h.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:t,objects:a,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:c,undos:d}}_getDrawingUndoForRowVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(l=>{const s=e[l],{sheetTransform:u,transform:m,anchorType:f=h.SheetDrawingAnchorType.Position}=s;if(f===h.SheetDrawingAnchorType.None)this._remainDrawingSize(m,t,s);else{const{from:S,to:w}=u,{row:y,column:M}=S,{row:C,column:T}=w;for(let _=0;_<n.length;_++){const D=n[_],{startRow:v,endRow:P,startColumn:b,endColumn:L}=D;if(C<v)continue;if(f===h.SheetDrawingAnchorType.Position){let R=null,B=null;if(y>=v&&y<=P){const V=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:y,endRow:P});if(V==null)return;B={...m,top:V.startY}}if(B!=null&&(R=k(B,this._selectionRenderService),R!=null&&B!=null)){t.push({...s,sheetTransform:R,transform:B});break}this._remainDrawingSize(m,t,s);continue}if(y>=v&&C<=P)continue;let U=null,O=null;if(y>=v&&y<=P){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:y,endRow:P});if(R==null)return;O={...m,top:(R==null?void 0:R.startY)||0,height:((m==null?void 0:m.height)||0)-R.endY+R.startY}}else if(C>=v&&C<=P){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:C});if(R==null)return;O={...m,top:R.startY-((m==null?void 0:m.height)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:P});if(R==null)return;if(O={...m,height:((m==null?void 0:m.height)||0)-R.endY+R.startY},U=k(O,this._selectionRenderService),U!=null&&O!=null){o.push({...s,sheetTransform:U,transform:O});break}}if(O!=null&&(U=k(O,this._selectionRenderService)),O!=null&&U!=null){t.push({...s,sheetTransform:U,transform:O});break}else this._remainDrawingSize(m,t,s)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:c}=this._createUndoAndRedoMutation(i,r,t),d=[],p=[];if(o.length>0){const{redos:l,undos:s}=this._createUndoAndRedoMutation(i,r,o);d.push(...l),p.push(...s)}return{redos:a,undos:c,preRedos:d,preUndos:p}}_getDrawingUndoForRowAndColSize(i,r,n,e){const t=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(t).forEach(a=>{const c=t[a],{sheetTransform:d,transform:p,anchorType:l=h.SheetDrawingAnchorType.Position}=c;if(l===h.SheetDrawingAnchorType.None)this._remainDrawingSize(p,o,c);else{const{from:s,to:u}=d,{row:m,column:f}=s,{row:S,column:w}=u;for(let y=0;y<n.length;y++){const M=n[y],{startRow:C,endRow:T,startColumn:_,endColumn:D}=M;if(S<C||w<_)continue;if(l===h.SheetDrawingAnchorType.Position&&(m<=C&&S>=T||f<=_&&w>=D)){this._remainDrawingSize(p,o,c);continue}const v=Y({...d},this._selectionRenderService,this._skeletonManagerService);if(v!=null){o.push({...c,transform:v});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let n,e;if(r==="insert")n=i.unitId,e=i.subUnitId;else{const t=I.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;n=t.unitId,e=t.subUnitId}return{unitId:n,subUnitId:e}}_moveRangeInterceptor(i){var C,T;const{toRange:r,fromRange:n}=i,e=I.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,a=(T=(C=this._renderManagerService.getRenderById(t))==null?void 0:C.with(j.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const c=j.attachRangeWithCoord(a,n);if(!c)return{redos:[],undos:[]};const{startX:d,endX:p,startY:l,endY:s}=c,u=this._sheetDrawingService.getDrawingData(t,o),m=[];Object.keys(u).forEach(_=>{const D=u[_];if(D.anchorType!==h.SheetDrawingAnchorType.Both)return;const{transform:v}=D;if(!v)return;const{left:P=0,top:b=0,width:L=0,height:U=0}=v,{drawingStartX:O,drawingEndX:R,drawingStartY:B,drawingEndY:V}={drawingStartX:P,drawingEndX:P+L,drawingStartY:b,drawingEndY:b+U};d<=O&&R<=p&&l<=B&&V<=s&&m.push(D)});const f=[],S=[],w=r.startRow-n.startRow,y=r.startColumn-n.startColumn,M=m.map(_=>{const D=_.sheetTransform,v={to:{...D.to,row:D.to.row+w,column:D.to.column+y},from:{...D.from,row:D.from.row+w,column:D.from.column+y}},P=Y(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:_.drawingId,transform:P,sheetTransform:v}});if(M.length){const _=this._sheetDrawingService.getBatchUpdateOp(M),{undo:D,redo:v,objects:P}=_;f.push({id:h.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:v,objects:P,type:h.DrawingApplyType.UPDATE}}),S.push({id:h.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:D,objects:P,type:h.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startRow,c=o.endRow,d=[],p=[],l=this._sheetDrawingService.getDrawingData(e,t),s=[],u=[];if(Object.keys(l).forEach(m=>{const f=l[m],{sheetTransform:S,transform:w,anchorType:y=h.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let M,C;if(r==="insert"){const _=this._expandRow(S,w,a,c,y);M=_==null?void 0:_.newSheetTransform,C=_==null?void 0:_.newTransform}else{const{from:_,to:D}=S,{row:v}=_,{row:P}=D;if(y===h.SheetDrawingAnchorType.Both&&v>=a&&P<=c)u.push({unitId:e,subUnitId:t,drawingId:m});else{const b=this._shrinkRow(S,w,a,c,y);M=b==null?void 0:b.newSheetTransform,C=b==null?void 0:b.newTransform}}if(!M||!C)return;const T={unitId:e,subUnitId:t,drawingId:m,transform:C,sheetTransform:M};s.push(T)}),s.length===0&&u.length===0)return{redos:[],undos:[]};if(s.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(s),{undo:f,redo:S,objects:w}=m;d.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:w,type:h.DrawingApplyType.UPDATE}}),p.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:w,type:h.DrawingApplyType.UPDATE}})}if(u.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(u),f=m.undo,S=m.redo,w=m.objects;d.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:w,type:h.DrawingApplyType.REMOVE}}),p.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:w,type:h.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),p.push({id:G.id,params:[e]}),{redos:d,undos:p}}_moveColInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startColumn,c=o.endColumn,d=[],p=[],l=this._sheetDrawingService.getDrawingData(e,t),s=[],u=[];if(Object.keys(l).forEach(m=>{const f=l[m],{sheetTransform:S,transform:w,anchorType:y=h.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let M,C;if(r==="insert"){const _=this._expandCol(S,w,a,c,y);M=_==null?void 0:_.newSheetTransform,C=_==null?void 0:_.newTransform}else{const{from:_,to:D}=S,{column:v}=_,{column:P}=D;if(y===h.SheetDrawingAnchorType.Both&&v>=a&&P<=c)u.push({unitId:e,subUnitId:t,drawingId:m});else{const b=this._shrinkCol(S,w,a,c,y);M=b==null?void 0:b.newSheetTransform,C=b==null?void 0:b.newTransform}}if(!M||!C)return;const T={unitId:e,subUnitId:t,drawingId:m,transform:C,sheetTransform:M};s.push(T)}),s.length===0&&u.length===0)return{redos:[],undos:[]};if(s.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(s),{undo:f,redo:S,objects:w}=m;d.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:w,type:h.DrawingApplyType.UPDATE}}),p.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:w,type:h.DrawingApplyType.UPDATE}})}if(u.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(u),f=m.undo,S=m.redo,w=m.objects;d.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:w,type:h.DrawingApplyType.REMOVE}}),p.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:w,type:h.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),p.push({id:G.id,params:[e]}),{redos:d,undos:p}}_expandCol(i,r,n,e,t=h.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{column:d}=a,{column:p}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};let l=null,s=null;if(d>=n){const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:e,startRow:a.row,endRow:c.row});if(u==null)return;s={...r,left:(r.left||0)+u.endX-u.startX},l=k(s,this._selectionRenderService)}else if(p>=e)if(t===h.SheetDrawingAnchorType.Both)l={from:{...a},to:{...c,column:p+o}},s=Y(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};return l!=null&&s!=null?{newSheetTransform:l,newTransform:s}:null}_shrinkCol(i,r,n,e,t=h.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{column:d}=a,{column:p}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};let l=null,s=null;if(d>e)l={from:{...a,column:d-o},to:{...c,column:p-o}},s=Y(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=n&&p<=e)return null;if(d<n&&p>e)if(t===h.SheetDrawingAnchorType.Both)l={from:{...a},to:{...c,column:p-o}},s=Y(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};else if(d>=n&&d<=e){if(d===n)s={...r,left:(r.left||0)-i.from.columnOffset};else{const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:d-1,startRow:a.row,endRow:c.row});if(u==null)return;s={...r,left:(r.left||0)-u.endX+u.startX-i.from.columnOffset}}l=k(s,this._selectionRenderService)}else if(p>=n&&p<=e&&t===h.SheetDrawingAnchorType.Both){const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:n-1,endColumn:n-1,startRow:a.row,endRow:c.row});if(u==null)return;l={from:{...a},to:{...c,column:n-1,columnOffset:u.endX-u.startX}},s=Y(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&s!=null?{newSheetTransform:l,newTransform:s}:null}_expandRow(i,r,n,e,t=h.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{row:d}=a,{row:p}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};let l=null,s=null;if(d>=n){const u=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:e,startColumn:a.column,endColumn:c.column});if(u==null)return;s={...r,top:(r.top||0)+u.endY-u.startY},l=k(s,this._selectionRenderService)}else if(p>=e)if(t===h.SheetDrawingAnchorType.Both)l={from:{...a},to:{...c,row:p+o}},s=Y(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};return l!=null&&s!=null?{newSheetTransform:l,newTransform:s}:null}_shrinkRow(i,r,n,e,t=h.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{row:d}=a,{row:p}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};let l=null,s=null;if(d>e)l={from:{...a,row:d-o},to:{...c,row:p-o}},s=Y(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=n&&p<=e)return null;if(d<n&&p>e)if(t===h.SheetDrawingAnchorType.Both)l={from:{...a},to:{...c,row:p-o}},s=Y(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:k({...r},this._selectionRenderService),newTransform:r};else if(d>=n&&d<=e){if(d===n)s={...r,top:(r.top||0)-i.from.rowOffset};else{const u=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:d-1,startColumn:a.column,endColumn:c.column});if(u==null)return;s={...r,top:(r.top||0)-u.endY+u.startY-i.from.rowOffset}}l=k(s,this._selectionRenderService)}else if(p>=n&&p<=e&&t===h.SheetDrawingAnchorType.Both){const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:n-1,endRow:n-1});if(u==null)return;l={from:{...a},to:{...c,row:n-1,rowOffset:u.endY-u.startY}},s=Y(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&s!=null?{newSheetTransform:l,newTransform:s}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===I.SetWorksheetActiveOperation.id&&setTimeout(()=>{const r=i.params,{unitId:n,subUnitId:e}=r,t=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(t).forEach(c=>{const d=t[c];d!=null&&Object.keys(d).forEach(p=>{const l=d[p].data;l!=null&&Object.keys(l).forEach(s=>{if(c===n&&p===e){const u=l[s];u.transform=Y(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(l[s])}else a.push(l[s])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{It.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:n,subUnitId:e,ranges:t}=r;this._refreshDrawingTransform(n,e,t)})}))}_refreshDrawingTransform(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:c,transform:d,anchorType:p=h.SheetDrawingAnchorType.Position}=a;if(p===h.SheetDrawingAnchorType.None)return!0;const{from:l,to:s}=c,{row:u,column:m}=l,{row:f,column:S}=s;for(let w=0;w<n.length;w++){const y=n[w],{startRow:M,endRow:C,startColumn:T,endColumn:_}=y;if(g.Rectangle.intersects({startRow:M,endRow:C,startColumn:T,endColumn:_},{startRow:u,endRow:f,startColumn:m,endColumn:S})||u>C||m>_){const D=p===h.SheetDrawingAnchorType.Position,v=Y(c,this._selectionRenderService,this._skeletonManagerService);t.push({...a,transform:{...v,width:D?d==null?void 0:d.width:v==null?void 0:v.width,height:D?d==null?void 0:d.height:v==null?void 0:v.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(G.id,[i]))}};Te=vt([Z(1,N.IRenderManagerService),Z(2,g.ICommandService),Z(3,j.ISheetSelectionRenderService),Z(4,g.Inject(j.SheetSkeletonManagerService)),Z(5,g.Inject(I.SheetInterceptorService)),Z(6,h.ISheetDrawingService),Z(7,A.IDrawingManagerService),Z(8,g.IUniverInstanceService)],Te);function Ct(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:c}=e,d=N.getGroupState(0,0,t.map(s=>s.transform||{})),p=t.map(s=>{const u=s.transform||{left:0,top:0},{unitId:m,subUnitId:f,drawingId:S}=s;return{unitId:m,subUnitId:f,drawingId:S,transform:{...u,left:u.left-d.left,top:u.top-d.top},groupId:c}}),l={unitId:o,subUnitId:a,drawingId:c,drawingType:g.DrawingTypeEnum.DRAWING_GROUP,transform:d};r.push({parent:l,children:p})}),r}function yt(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:c,transform:d={width:0,height:0}}=e;if(d==null)return;const p=t.map(s=>{const{transform:u}=s,{unitId:m,subUnitId:f,drawingId:S}=s,w=N.transformObjectOutOfGroup(u||{},d,d.width||0,d.height||0);return{unitId:m,subUnitId:f,drawingId:S,transform:w,groupId:void 0}}),l={unitId:o,subUnitId:a,drawingId:c,drawingType:g.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:l,children:p})}),r}const be={id:"sheet.command.group-sheet-image",type:g.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(g.ICommandService),e=i.get(g.IUndoRedoService),t=i.get(h.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:m,children:f})=>{o.push(m.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getGroupDrawingOp(r),{unitId:c,subUnitId:d,undo:p,redo:l,objects:s}=a;return n.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:s,type:h.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:p,unitId:c,subUnitId:d,objects:yt(s),type:h.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:s,type:h.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!0):!1}},se={id:"sheet.command.insert-sheet-image",type:g.CommandType.COMMAND,handler:(i,r)=>{var M,C,T;const n=i.get(g.ICommandService),e=i.get(g.IUndoRedoService),t=i.get(h.ISheetDrawingService),o=i.get(I.SheetInterceptorService);if(!r)return!1;const a=r.drawings,c=a.map(_=>_.unitId),d=t.getBatchAddOp(a),{unitId:p,subUnitId:l,undo:s,redo:u,objects:m}=d,f=o.onCommandExecute({id:se.id,params:r}),S={id:h.SetDrawingApplyMutation.id,params:{op:u,unitId:p,subUnitId:l,objects:m,type:h.DrawingApplyType.INSERT}},w={id:h.SetDrawingApplyMutation.id,params:{op:s,unitId:p,subUnitId:l,objects:m,type:h.DrawingApplyType.REMOVE}};return g.sequenceExecute([...(M=f.preRedos)!=null?M:[],S,...f.redos],n)?(e.pushUndoRedo({unitID:p,undoMutations:[...(C=f.preUndos)!=null?C:[],w,...f.undos,{id:G.id,params:c}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:c}]}),!0):!1}},Ee={id:"sheet.command.set-drawing-arrange",type:g.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(g.ICommandService),e=i.get(g.IUndoRedoService);if(!r)return!1;const t=i.get(h.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:c,arrangeType:d}=r,p={unitId:o,subUnitId:a,drawingIds:c};let l;if(d===g.ArrangeTypeEnum.forward?l=t.getForwardDrawingsOp(p):d===g.ArrangeTypeEnum.backward?l=t.getBackwardDrawingOp(p):d===g.ArrangeTypeEnum.front?l=t.getFrontDrawingsOp(p):d===g.ArrangeTypeEnum.back&&(l=t.getBackDrawingsOp(p)),l==null)return!1;const{objects:s,redo:u,undo:m}=l;return n.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:u,unitId:o,subUnitId:a,objects:s,type:h.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:a,objects:s,type:h.DrawingApplyType.ARRANGE}}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:u,unitId:o,subUnitId:a,objects:s,type:h.DrawingApplyType.ARRANGE}}]}),!0):!1}},ce={id:"sheet.command.set-sheet-image",type:g.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(g.ICommandService),e=i.get(g.IUndoRedoService),t=i.get(h.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=t.getBatchUpdateOp(o),{unitId:c,subUnitId:d,undo:p,redo:l,objects:s}=a;return n.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:c,subUnitId:d,op:l,objects:s,type:h.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:p,objects:s,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[c]}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:l,objects:s,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[c]}]}),!0):!1}},Oe={id:"sheet.command.ungroup-sheet-image",type:g.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(g.ICommandService),e=i.get(g.IUndoRedoService),t=i.get(h.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:m,children:f})=>{o.push(m.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getUngroupDrawingOp(r),{unitId:c,subUnitId:d,undo:p,redo:l,objects:s}=a;return n.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:s,type:h.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:p,unitId:c,subUnitId:d,objects:Ct(s),type:h.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:s,type:h.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};var Mt=Object.defineProperty,Dt=Object.getOwnPropertyDescriptor,Rt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Dt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Mt(r,n,t),t},z=(i,r)=>(n,e)=>r(n,e,i);let Se=class extends g.Disposable{constructor(r,n,e,t,o,a,c,d,p,l,s,u){super();X(this,"_workbookSelections");this._context=r,this._skeletonManagerService=n,this._commandService=e,this._selectionRenderService=t,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=c,this._drawingManagerService=d,this._contextService=p,this._messageService=l,this._localeService=s,this._workbookSelections=u.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const r=await this._fileOpenerService.openFile({multiple:!0,accept:A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),n=r.length;return n>A.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(A.DRAWING_IMAGE_COUNT_LIMIT))}),!1):n===0?!1:(r.forEach(async e=>await this._insertFloatImage(e)),!0)}async _insertFloatImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(M){const C=M.message;C===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.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:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===A.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:c,source:d,base64Cache:p}=n,{width:l,height:s,image:u}=await A.getImageSize(p||""),{width:m,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(d,c,u);let S=1;if(l>A.DRAWING_IMAGE_WIDTH_LIMIT||s>A.DRAWING_IMAGE_HEIGHT_LIMIT){const M=A.DRAWING_IMAGE_WIDTH_LIMIT/l,C=A.DRAWING_IMAGE_HEIGHT_LIMIT/s;S=Math.max(M,C)}const w=this._getImagePosition(l*S,s*S,m,f);if(w==null)return;const y={unitId:t,subUnitId:o,drawingId:a,drawingType:g.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c,source:d,transform:Y(w,this._selectionRenderService,this._skeletonManagerService),sheetTransform:w};this._commandService.executeCommand(se.id,{unitId:t,drawings:[y]})}_getUnitInfo(){const r=this._context.unit,n=r.getActiveSheet(),e=r.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(r,n,e,t){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const c=j.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(c==null)return;let{startColumn:d,startRow:p,startX:l,startY:s}=c,u=!1;if(l+r>e&&(l=e-r,l<0&&(l=0,r=e),u=!0),s+n>t&&(s=t-n,s<0&&(s=0,n=t),u=!0),u){const w=this._selectionRenderService.getCellWithCoordByOffset(l,s);if(w==null)return;l=w.startX,s=w.startY,d=w.actualColumn,p=w.actualRow}const m={column:d,columnOffset:0,row:p,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(l+r,s+n);if(f==null)return;const S={column:f.actualColumn,columnOffset:l+r-f.startX,row:f.actualRow,rowOffset:s+n-f.startY};return{from:m,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(r=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o}=r;this._commandService.executeCommand(Ee.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(r=>{const n=[];r.length!==0&&(r.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a,drawingType:c,transform:d}=e;if(d==null)return;const p=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:a});if(p==null||p.unitId!==this._context.unitId)return;const l=k({...p.transform,...d},this._selectionRenderService);if(l==null)return;const s={...e,transform:{...p.transform,...d,...Y(l,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...l}};n.push(s)}),n.length>0&&this._commandService.executeCommand(ce.id,{unitId:r[0].unitId,drawings:n}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(r=>{this._commandService.executeCommand(be.id,r);const{unitId:n,subUnitId:e,drawingId:t}=r[0].parent;this._drawingManagerService.focusDrawing([{unitId:n,subUnitId:e,drawingId:t}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Oe.id,r)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(r=>{r==null||r.length===0?(this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(r))}))}};Se=Rt([z(1,g.Inject(j.SheetSkeletonManagerService)),z(2,g.ICommandService),z(3,j.ISheetSelectionRenderService),z(4,A.IImageIoService),z(5,F.ILocalFileService),z(6,h.ISheetDrawingService),z(7,A.IDrawingManagerService),z(8,g.IContextService),z(9,F.IMessageService),z(10,g.Inject(g.LocaleService)),z(11,g.Inject(I.SheetsSelectionsService))],Se);var K=function(){return K=Object.assign||function(i){for(var r,n=1,e=arguments.length;n<e;n++){r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(i[t]=r[t])}return i},K.apply(this,arguments)},Tt=function(i,r){var n={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(n[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(i);t<e.length;t++)r.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(i,e[t])&&(n[e[t]]=i[e[t]]);return n},ke=H.forwardRef(function(i,r){var n=i.icon,e=i.id,t=i.className,o=i.extend,a=Tt(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),d=H.useRef("_".concat(Ot()));return Ve(n,"".concat(e),{defIds:n.defIds,idSuffix:d.current},K({ref:r,className:c},a),o)});function Ve(i,r,n,e,t){return H.createElement(i.tag,K(K({key:r},bt(i,n,t)),e),(Et(i,n).children||[]).map(function(o,a){return Ve(o,"".concat(r,"-").concat(i.tag,"-").concat(a),n,void 0,t)}))}function bt(i,r,n){var e=K({},i.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var t=r.defIds;return!t||t.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],c=o[1];typeof c=="string"&&(e[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Et(i,r){var n,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?K(K({},i),{children:i.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?K(K({},t),{attrs:K(K({},t.attrs),{id:t.attrs.id+r.idSuffix})}):t})}):i}function Ot(){return Math.random().toString(36).substring(2,8)}ke.displayName="UniverIcon";var Pt={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"}}]},Fe=H.forwardRef(function(i,r){return H.createElement(ke,Object.assign({},i,{id:"add-image-single",ref:r,icon:Pt}))});Fe.displayName="AddImageSingle";const Pe={id:"sheet.command.delete-drawing",type:g.CommandType.COMMAND,handler:i=>{const r=i.get(g.ICommandService),e=i.get(h.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(a=>{const{unitId:c,subUnitId:d,drawingId:p,drawingType:l}=a;return{unitId:c,subUnitId:d,drawingId:p,drawingType:l}});return r.executeCommand(ie.id,{unitId:t,drawings:o})}},we={id:"sheet.command.insert-float-image",type:g.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(N.IRenderManagerService).getCurrentTypeOfRenderer(g.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(Se).insertFloatImage())!=null?e:!1}},re={id:"sheet.command.move-drawing",type:g.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(g.ICommandService),e=i.get(h.ISheetDrawingService),t=i.get(j.ISheetSelectionRenderService),{direction:o}=r,a=e.getFocusDrawings();if(a.length===0)return!1;const c=a[0].unitId,d=a.map(l=>{const{transform:s}=l;if(s==null)return null;const u={...s},{left:m=0,top:f=0}=s;return o===g.Direction.UP?u.top=f-1:o===g.Direction.DOWN?u.top=f+1:o===g.Direction.LEFT?u.left=m-1:o===g.Direction.RIGHT&&(u.left=m+1),{...l,transform:u,sheetTransform:k(u,t)}}).filter(l=>l!=null);return n.syncExecuteCommand(ce.id,{unitId:c,drawings:d})?(n.syncExecuteCommand(G.id,[c]),!0):!1}},$e="addition-and-subtraction-single",Ae="sheet.menu.image";function At(i){return{id:Ae,type:F.MenuItemType.SUBITEMS,icon:$e,tooltip:"sheetImage.title",hidden$:F.getMenuHiddenObservable(i,g.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(i,{workbookTypes:[I.WorkbookEditablePermission],worksheetTypes:[I.WorksheetEditPermission],rangeTypes:[I.RangeProtectionPermissionEditPoint]})}}function Ut(i){return{id:we.id,title:"sheetImage.upload.float",type:F.MenuItemType.BUTTON,hidden$:F.getMenuHiddenObservable(i,g.UniverInstanceType.UNIVER_SHEET)}}const Q={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelSubtitle:"univer-image-common-panel-subtitle",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"};function Ye(i){var r,n,e="";if(typeof i=="string"||typeof i=="number")e+=i;else if(typeof i=="object")if(Array.isArray(i)){var t=i.length;for(r=0;r<t;r++)i[r]&&(n=Ye(i[r]))&&(e&&(e+=" "),e+=n)}else for(n in i)i[n]&&(e&&(e+=" "),e+=n);return e}function ve(){for(var i,r,n=0,e="",t=arguments.length;n<t;n++)(i=arguments[n])&&(r=Ye(i))&&(e&&(e+=" "),e+=r);return e}const Nt=i=>{var C;const r=g.useDependency(g.ICommandService),n=g.useDependency(g.LocaleService),e=g.useDependency(A.IDrawingManagerService),t=g.useDependency(N.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:c}=a,d=t.getRenderById(c),p=d==null?void 0:d.scene;if(p==null)return;const l=p.getTransformerByCreate(),[s,u]=H.useState(!0),m=(C=a.anchorType)!=null?C:h.SheetDrawingAnchorType.Position,[f,S]=H.useState(m);function w(T,_){const D=[];return T.forEach(v=>{const{oKey:P}=v,b=_.getDrawingOKey(P);if(b==null)return D.push(null),!0;const{unitId:L,subUnitId:U,drawingId:O,drawingType:R,anchorType:B,sheetTransform:V}=b;D.push({unitId:L,subUnitId:U,drawingId:O,anchorType:B,sheetTransform:V,drawingType:R})}),D}H.useEffect(()=>{const T=l.clearControl$.subscribe(D=>{D===!0&&u(!1)}),_=l.changeStart$.subscribe(D=>{var b;const{objects:v}=D,P=w(v,e);if(P.length===0)u(!1);else if(P.length>=1){u(!0);const L=((b=P[0])==null?void 0:b.anchorType)||h.SheetDrawingAnchorType.Position;S(L)}});return()=>{_.unsubscribe(),T.unsubscribe()}},[]);function y(T){S(T);const _=e.getFocusDrawings();if(_.length===0)return;const D=_.map(v=>({unitId:v.unitId,subUnitId:v.subUnitId,drawingId:v.drawingId,anchorType:T}));r.executeCommand(ce.id,{unitId:_[0].unitId,drawings:D})}const M=T=>T?"block":"none";return $.jsxs("div",{className:ve(Q.imageCommonPanelGrid,Q.imageCommonPanelBorder),style:{display:M(s)},children:[$.jsx("div",{className:Q.imageCommonPanelRow,children:$.jsx("div",{className:ve(Q.imageCommonPanelColumn,Q.imageCommonPanelTitle),children:$.jsx("div",{children:n.t("drawing-anchor.title")})})}),$.jsx("div",{className:ve(Q.imageCommonPanelRow),children:$.jsx("div",{className:ve(Q.imageCommonPanelColumn),children:$.jsxs(q.RadioGroup,{value:f,onChange:y,direction:"vertical",children:[$.jsx(q.Radio,{value:h.SheetDrawingAnchorType.Both,children:n.t("drawing-anchor.both")}),$.jsx(q.Radio,{value:h.SheetDrawingAnchorType.Position,children:n.t("drawing-anchor.position")}),$.jsx(q.Radio,{value:h.SheetDrawingAnchorType.None,children:n.t("drawing-anchor.none")})]})})})]})},jt=()=>{const i=g.useDependency(A.IDrawingManagerService),r=i.getFocusDrawings(),[n,e]=H.useState(r);return H.useEffect(()=>{const t=i.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(n!=null&&n.length)&&$.jsxs("div",{className:Q.imageCommonPanel,children:[$.jsx(ee.DrawingCommonPanel,{drawings:n}),$.jsx(Nt,{drawings:n})]})},Wt={[F.RibbonStartGroup.FORMULAS_INSERT]:{[Ae]:{order:3,menuItemFactory:At,[we.id]:{order:0,menuItemFactory:Ut}}}};function de(i){return!i.getContextValue(g.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(g.EDITOR_ACTIVATED)&&!i.getContextValue(g.FOCUSING_PANEL_EDITOR)&&i.getContextValue(g.FOCUSING_COMMON_DRAWINGS)}const Lt={id:re.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_DOWN,priority:100,preconditions:de,staticParameters:{direction:g.Direction.DOWN}},Bt={id:re.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_UP,priority:100,preconditions:de,staticParameters:{direction:g.Direction.UP}},Gt={id:re.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_LEFT,priority:100,preconditions:de,staticParameters:{direction:g.Direction.LEFT}},kt={id:re.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_RIGHT,priority:100,preconditions:de,staticParameters:{direction:g.Direction.RIGHT}},Vt={id:Pe.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:de,binding:F.KeyCode.DELETE,mac:F.KeyCode.BACKSPACE};var Ft=Object.defineProperty,$t=Object.getOwnPropertyDescriptor,Yt=(i,r,n,e)=>{for(var t=e>1?void 0:e?$t(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Ft(r,n,t),t},_e=(i,r)=>(n,e)=>r(n,e,i);let Ie=class extends g.Disposable{constructor(i,r,n,e){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=n,this._shortcutService=e,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register($e,Fe)),this.disposeWithMe(i.register(Le,jt))}_initMenus(){this._menuManagerService.mergeMenu(Wt)}_initCommands(){[we,se,ie,ce,Ce,G,ye,be,Oe,re,Pe,Ee].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[Lt,Bt,Gt,kt,Vt].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Ie=Yt([_e(0,g.Inject(F.ComponentManager)),_e(1,F.IMenuManagerService),_e(2,g.ICommandService),_e(3,F.IShortcutService)],Ie);var Ht=Object.defineProperty,xt=Object.getOwnPropertyDescriptor,Xt=(i,r,n,e)=>{for(var t=e>1?void 0:e?xt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Ht(r,n,t),t},ne=(i,r)=>(n,e)=>r(n,e,i);function Kt(i,r,n,e){const{scaleX:t,scaleY:o}=r.getAncestorScale(),a=r.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN),c={left:!0,top:!0};if(!a)return{...i,absolute:c};const{left:d,right:p,top:l,bottom:s}=i,u=e.getFreeze(),{startColumn:m,startRow:f,xSplit:S,ySplit:w}=u,y=n.getNoMergeCellPositionByIndexWithNoHeader(f-w,m-S),M=n.getNoMergeCellPositionByIndexWithNoHeader(f,m),{rowHeaderWidth:C,columnHeaderHeight:T}=n,_=M.startX-y.startX,D=M.startY-y.startY,{top:v,left:P,viewportScrollX:b,viewportScrollY:L}=a;let U,O;d<P?(c.left=!0,U=(_+C+(d-P))*t,O=Math.max(Math.min((_+C+(p-P))*t,(_+C)*t),(p-b)*t)):(c.left=!1,U=Math.max((d-b)*t,(_+C)*t),O=Math.max((p-b)*t,(_+C)*t));let R,B;return l<v?(c.top=!0,R=(D+T+(l-v))*o,B=Math.max(Math.min((D+T+(p-v))*o,(D+T)*o),(s-L)*o)):(c.top=!1,R=Math.max((l-L)*o,(D+T)*o),B=Math.max((s-L)*o,(D+T)*o)),{left:U,right:O,top:R,bottom:B,absolute:c}}const Ue=(i,r,n,e)=>{const{scene:t}=r,{left:o,top:a,width:c,height:d,angle:p}=i,l={left:o,right:o+c,top:a,bottom:a+d},s=Kt(l,t,n,e),{scaleX:u,scaleY:m}=t.getAncestorScale();return{startX:s.left,endX:s.right,startY:s.top,endY:s.bottom,rotate:p,width:c*u,height:d*m,absolute:s.absolute}};E.SheetCanvasFloatDomManagerService=class extends g.Disposable{constructor(n,e,t,o,a,c,d){super();X(this,"_domLayerMap",new Map);X(this,"_domLayerInfoMap",new Map);X(this,"_transformChange$",new W.Subject);X(this,"transformChange$",this._transformChange$.asObservable());X(this,"_add$",new W.Subject);X(this,"add$",this._add$.asObservable());X(this,"_remove$",new W.Subject);X(this,"remove$",this._remove$.asObservable());X(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=c,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(W.filter(n=>n===g.LifecycleStages.Rendered),W.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(n,e){let t=this._domLayerMap.get(n);t||(t=new Map,this._domLayerMap.set(n,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(n){return this._domLayerInfoMap.get(n)}_getSceneAndTransformerByDrawingSearch(n){if(n==null)return;const e=this._renderManagerService.getRenderById(n),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:t,transformer:o,renderObject:e,canvas:a}}_getFloatDomProps(n){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(n)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(n=>{n.forEach(e=>{var Ke,ze,Je;const{unitId:t,subUnitId:o,drawingId:a}=e,c=I.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e),p=this._univerInstanceService.getUnit(t);if(!p)return;const l=p.getActiveSheet().getSheetId();if(!d||!c)return;const s=(Ke=this._renderManagerService.getRenderById(t))==null?void 0:Ke.with(j.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!s)return;const{transform:u,drawingType:m,data:f}=d;if(m!==g.DrawingTypeEnum.DRAWING_DOM&&m!==g.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(t);if(S==null)return;const{scene:w,canvas:y}=S;if(u==null)return!0;if(l!==o)return;const{left:M,top:C,width:T,height:_,angle:D,flipX:v,flipY:P,skewX:b,skewY:L}=u,U=A.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),O=w.getObject(U);if(O!=null){O.transformByState({left:M,top:C,width:T,height:_,angle:D,flipX:v,flipY:P,skewX:b,skewY:L});return}const R={left:M,top:C,width:T,height:_,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},B=m===g.DrawingTypeEnum.DRAWING_CHART;B&&(R.fill="white",R.rotateEnabled=!1,f&&f.border&&(R.stroke=f.border),R.paintFirst="stroke",R.strokeWidth=1,R.borderEnabled=!1,R.radius=8);const V=new N.Rect(U,R);B&&V.setObjectType(N.ObjectType.CHART),w.addObject(V,N.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&w.attachTransformerTo(V);const J=this._ensureMap(t,o),je=new g.DisposableCollection,Qt=Ue(V,S.renderObject,s.skeleton,c.worksheet),We=new W.BehaviorSubject(Qt),en={dispose:je,rect:V,position$:We,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:We,id:a,componentKey:d.componentKey,onPointerDown:x=>{y.dispatchEvent(new PointerEvent(x.type,x))},onPointerMove:x=>{y.dispatchEvent(new PointerEvent(x.type,x))},onPointerUp:x=>{y.dispatchEvent(new PointerEvent(x.type,x))},onWheel:x=>{y.dispatchEvent(new WheelEvent(x.type,x))},props:(Je=(ze=J.get(a))==null?void 0:ze.props)!=null?Je:this._getFloatDomProps(a),data:f,unitId:t});const Xe=V.onTransformChange$.subscribeEvent(()=>{const x=Ue(V,S.renderObject,s.skeleton,c.worksheet);We.next(x)});je.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),Xe&&je.add(Xe),this._domLayerInfoMap.set(a,en),J.set(a,{...J.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a}=e,c=A.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),d=this._getSceneAndTransformerByDrawingSearch(t);if(d==null)return;const{transformer:p,scene:l}=d,s=l.getObject(c);s!=null&&s.oKey&&p.clearControlByIds([s==null?void 0:s.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var l;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,t),c=Array.from(a.keys()),d=I.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),p=(l=this._renderManagerService.getRenderById(e))==null?void 0:l.with(j.SheetSkeletonManagerService).getWorksheetSkeleton(t);!o||!d||!p||c.forEach(s=>{const u=this._domLayerInfoMap.get(s);if(u){const m=Ue(u.rect,o.renderObject,p.skeleton,d.worksheet);u.position$.next(m)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET).pipe(W.filter(e=>!!e),W.switchMap(e=>e.activeSheet$),W.filter(e=>!!e),W.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),W.filter(e=>!!e),W.switchMap(e=>g.fromEventSubject(e.render.scene.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(W.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{n(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===j.SetZoomRatioOperation.id){const a=e.params,{unitId:c}=a;Array.from((o=(t=this._domLayerMap.get(c))==null?void 0:t.keys())!=null?o:[]).forEach(p=>{n(c,p)})}else if(e.id===I.SetFrozenMutation.id){const{unitId:a,subUnitId:c}=e.params;n(a,c)}}))}_getPosition(n,e){var m;const{startX:t,endX:o,startY:a,endY:c}=n,d=(m=this._renderManagerService.getRenderById(e))==null?void 0:m.with(j.ISheetSelectionRenderService);if(d==null)return;const p=d.getCellWithCoordByOffset(t,a);if(p==null)return;const l={column:p.actualColumn,columnOffset:t-p.startX,row:p.actualRow,rowOffset:a-p.startY},s=d.getCellWithCoordByOffset(o,c);if(s==null)return;const u={column:s.actualColumn,columnOffset:o-s.startX,row:s.actualRow,rowOffset:c-s.startY};return{from:l,to:u}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==g.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==g.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(n,e,t,o){const a=this._domLayerInfoMap.get(t),c=this._getSceneAndTransformerByDrawingSearch(n);if(a&&c){const{scene:d}=c,p=A.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),l=d.getObject(p);l&&l instanceof N.Rect&&l.setProps(o)}}addFloatDomToPosition(n,e){const t=I.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=t,{initPosition:c,componentKey:d,data:p,allowTransform:l=!0}=n,s=e!=null?e:g.generateRandomId(),u=this._getPosition(c,o);if(u==null)return;this._ensureMap(o,a).set(s,n);const f={unitId:o,subUnitId:a,drawingId:s,drawingType:n.type||g.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:u,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},data:p,allowTransform:l};return this._commandService.executeCommand(se.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:a,id:s}),{id:s,dispose:()=>{this._removeDom(s,!0)}}}_removeDom(n,e=!1){const t=this._domLayerInfoMap.get(n);if(!t)return;const{unitId:o,subUnitId:a}=t;this._domLayerInfoMap.delete(n),t.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(t.rect),e){this._ensureMap(o,a).delete(n);const p=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:n});if(!p)return;const l=this._sheetDrawingService.getBatchRemoveOp([p]),{redo:s,objects:u}=l;this._commandService.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:s,objects:u,type:h.DrawingApplyType.REMOVE})}}addHook(n){return this._hooks.push(n),{dispose:()=>{const e=this._hooks.findIndex(t=>t===n);this._hooks.splice(e,1)}}}},E.SheetCanvasFloatDomManagerService=Xt([ne(0,g.Inject(N.IRenderManagerService)),ne(1,g.IUniverInstanceService),ne(2,g.Inject(g.ICommandService)),ne(3,A.IDrawingManagerService),ne(4,g.Inject(F.CanvasFloatDomService)),ne(5,h.ISheetDrawingService),ne(6,g.Inject(g.LifecycleService))],E.SheetCanvasFloatDomManagerService);var He=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Jt=(i,r,n)=>r in i?He(i,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[r]=n,qt=(i,r,n,e)=>{for(var t=e>1?void 0:e?zt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&He(r,n,t),t},Ne=(i,r)=>(n,e)=>r(n,e,i),xe=(i,r,n)=>Jt(i,typeof r!="symbol"?r+"":r,n);const Zt="SHEET_IMAGE_UI_PLUGIN";E.UniverSheetsDrawingUIPlugin=class extends g.Plugin{constructor(r=Ze,n,e,t){super(),this._config=r,this._injector=n,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=this._config;o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(qe,a)}onStarting(){g.registerDependencies(this._injector,[[E.SheetCanvasFloatDomManagerService],[Ie],[ue],[fe],[pe],[ge]]),g.touchDependencies(this._injector,[[E.SheetCanvasFloatDomManagerService]])}onReady(){g.touchDependencies(this._injector,[[ge]])}onRendered(){this._registerRenderModules(),g.touchDependencies(this._injector,[[pe],[fe],[Ie]])}onSteady(){this._injector.get(ue)}_registerRenderModules(){[[Se],[Te],[De]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(g.UniverInstanceType.UNIVER_SHEET,r))})}},xe(E.UniverSheetsDrawingUIPlugin,"type",g.UniverInstanceType.UNIVER_SHEET),xe(E.UniverSheetsDrawingUIPlugin,"pluginName",Zt),E.UniverSheetsDrawingUIPlugin=qt([g.DependentOn(A.UniverDrawingPlugin,ee.UniverDrawingUIPlugin,h.UniverSheetsDrawingPlugin),Ne(1,g.Inject(g.Injector)),Ne(2,N.IRenderManagerService),Ne(3,g.IConfigService)],E.UniverSheetsDrawingUIPlugin),E.ClearSheetDrawingTransformerOperation=G,E.DeleteDrawingsCommand=Pe,E.EditSheetDrawingOperation=ye,E.GroupSheetDrawingCommand=be,E.InsertFloatImageCommand=we,E.InsertSheetDrawingCommand=se,E.MoveDrawingsCommand=re,E.RemoveSheetDrawingCommand=ie,E.SHEETS_IMAGE_MENU_ID=Ae,E.SetDrawingArrangeCommand=Ee,E.SetSheetDrawingCommand=ce,E.SidebarSheetDrawingOperation=Ce,E.UngroupSheetDrawingCommand=Oe,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-drawing-ui",
3
- "version": "0.5.0-nightly.202411281606",
3
+ "version": "0.5.0-nightly.202411291606",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -59,15 +59,15 @@
59
59
  "dependencies": {
60
60
  "@univerjs/icons": "^0.2.7",
61
61
  "clsx": "^2.1.1",
62
- "@univerjs/core": "0.5.0-nightly.202411281606",
63
- "@univerjs/design": "0.5.0-nightly.202411281606",
64
- "@univerjs/engine-render": "0.5.0-nightly.202411281606",
65
- "@univerjs/drawing-ui": "0.5.0-nightly.202411281606",
66
- "@univerjs/sheets-drawing": "0.5.0-nightly.202411281606",
67
- "@univerjs/sheets": "0.5.0-nightly.202411281606",
68
- "@univerjs/sheets-ui": "0.5.0-nightly.202411281606",
69
- "@univerjs/drawing": "0.5.0-nightly.202411281606",
70
- "@univerjs/ui": "0.5.0-nightly.202411281606"
62
+ "@univerjs/core": "0.5.0-nightly.202411291606",
63
+ "@univerjs/design": "0.5.0-nightly.202411291606",
64
+ "@univerjs/drawing": "0.5.0-nightly.202411291606",
65
+ "@univerjs/drawing-ui": "0.5.0-nightly.202411291606",
66
+ "@univerjs/engine-render": "0.5.0-nightly.202411291606",
67
+ "@univerjs/sheets": "0.5.0-nightly.202411291606",
68
+ "@univerjs/ui": "0.5.0-nightly.202411291606",
69
+ "@univerjs/sheets-drawing": "0.5.0-nightly.202411291606",
70
+ "@univerjs/sheets-ui": "0.5.0-nightly.202411291606"
71
71
  },
72
72
  "devDependencies": {
73
73
  "less": "^4.2.1",