@univerjs/sheets-drawing-ui 0.4.2-nightly.202410311606 → 0.4.2-nightly.202411021605

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.
@@ -24,17 +24,20 @@ const ClearSheetDrawingTransformerOperation = {
24
24
  id: "sheet.command.insert-sheet-image",
25
25
  type: CommandType.COMMAND,
26
26
  handler: /* @__PURE__ */ __name((accessor, params) => {
27
+ var _a2, _b, _c;
27
28
  const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), sheetDrawingService = accessor.get(ISheetDrawingService), sheetInterceptorService = accessor.get(SheetInterceptorService);
28
29
  if (!params) return !1;
29
30
  const drawings = params.drawings, unitIds = drawings.map((param) => param.unitId), jsonOp = sheetDrawingService.getBatchAddOp(drawings), { unitId, subUnitId, undo, redo, objects } = jsonOp, intercepted = sheetInterceptorService.onCommandExecute({ id: InsertSheetDrawingCommand.id, params }), insertMutation = { id: SetDrawingApplyMutation.id, params: { op: redo, unitId, subUnitId, objects, type: DrawingApplyType.INSERT } }, undoInsertMutation = { id: SetDrawingApplyMutation.id, params: { op: undo, unitId, subUnitId, objects, type: DrawingApplyType.REMOVE } };
30
- return sequenceExecute([insertMutation, ...intercepted.redos], commandService) ? (undoRedoService.pushUndoRedo({
31
+ return sequenceExecute([...(_a2 = intercepted.preRedos) != null ? _a2 : [], insertMutation, ...intercepted.redos], commandService) ? (undoRedoService.pushUndoRedo({
31
32
  unitID: unitId,
32
33
  undoMutations: [
33
- ...intercepted.undos,
34
+ ...(_b = intercepted.preUndos) != null ? _b : [],
34
35
  undoInsertMutation,
36
+ ...intercepted.undos,
35
37
  { id: ClearSheetDrawingTransformerOperation.id, params: unitIds }
36
38
  ],
37
39
  redoMutations: [
40
+ ...(_c = intercepted.preRedos) != null ? _c : [],
38
41
  insertMutation,
39
42
  ...intercepted.redos,
40
43
  { id: ClearSheetDrawingTransformerOperation.id, params: unitIds }
@@ -330,7 +333,7 @@ let SheetCanvasFloatDomManagerService = (_a = class extends Disposable {
330
333
  rectShape && rectShape instanceof Rect && rectShape.setProps(props);
331
334
  }
332
335
  }
333
- addFloatDomToPosition(layer, propId, executeCommand = !0) {
336
+ addFloatDomToPosition(layer, propId) {
334
337
  const target = getSheetCommandTarget(this._univerInstanceService, {
335
338
  unitId: layer.unitId,
336
339
  subUnitId: layer.subUnitId
@@ -357,15 +360,14 @@ let SheetCanvasFloatDomManagerService = (_a = class extends Disposable {
357
360
  data,
358
361
  allowTransform
359
362
  };
360
- return executeCommand && this._commandService.executeCommand(InsertSheetDrawingCommand.id, {
363
+ return this._commandService.executeCommand(InsertSheetDrawingCommand.id, {
361
364
  unitId,
362
365
  drawings: [sheetDrawingParam]
363
366
  }), this._add$.next({ unitId, subUnitId, id }), {
364
367
  id,
365
368
  dispose: /* @__PURE__ */ __name(() => {
366
369
  this._removeDom(id, !0);
367
- }, "dispose"),
368
- sheetDrawingParam
370
+ }, "dispose")
369
371
  };
370
372
  }
371
373
  _removeDom(id, removeDrawing = !1) {
package/lib/es/facade.js CHANGED
@@ -3,7 +3,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
3
3
  import { FWorksheet } from "@univerjs/sheets/facade";
4
4
  import { transformComponentKey } from "@univerjs/sheets-ui/facade";
5
5
  import { ComponentManager } from "@univerjs/ui";
6
- import { S as SheetCanvasFloatDomManagerService } from "../canvas-float-dom-manager.service-DT1kY3QQ.mjs";
6
+ import { S as SheetCanvasFloatDomManagerService } from "../canvas-float-dom-manager.service-DKCX6W5w.mjs";
7
7
  const _FWorksheetLegacy = class _FWorksheetLegacy extends FWorksheet {
8
8
  addFloatDomToPosition(layer, id) {
9
9
  const unitId = this._workbook.getUnitId(), subUnitId = this._worksheet.getSheetId(), { key, disposableCollection } = transformComponentKey(layer, this._injector.get(ComponentManager)), res = this._injector.get(SheetCanvasFloatDomManagerService).addFloatDomToPosition({ ...layer, componentKey: key, unitId, subUnitId }, id);
package/lib/es/index.js CHANGED
@@ -11,13 +11,14 @@ import { SheetCanvasPopManagerService, attachRangeWithCoord, ISheetSelectionRend
11
11
  import { ISidebarService, IUIPartsService, BuiltInUIPart, ILocalFileService, IMessageService, MenuItemType, getMenuHiddenObservable, RibbonStartGroup, KeyCode, ComponentManager, IMenuManagerService, IShortcutService } from "@univerjs/ui";
12
12
  import { takeUntil, combineLatest, map, filter, distinctUntilChanged } from "rxjs";
13
13
  import { SheetInterceptorService, getSheetCommandTarget, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, RangeProtectionPermissionEditPoint, WorkbookViewPermission, WorksheetViewPermission, InsertRowCommand, InsertColCommand, RemoveRowCommand, RemoveColCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, DeltaRowHeightCommand, SetRowHeightCommand, DeltaColumnWidthCommand, SetColWidthCommand, SetRowHiddenCommand, SetSpecificRowsVisibleCommand, SetSpecificColsVisibleCommand, SetColHiddenCommand, MoveColsCommand, MoveRowsCommand, MoveRangeCommand, SetRowVisibleMutation, SetRowHiddenMutation, SetColVisibleMutation, SetColHiddenMutation, SetWorksheetRowHeightMutation, SetWorksheetColWidthMutation, SetWorksheetActiveOperation } from "@univerjs/sheets";
14
- import { C as ClearSheetDrawingTransformerOperation, I as InsertSheetDrawingCommand, S as SheetCanvasFloatDomManagerService } from "../canvas-float-dom-manager.service-DT1kY3QQ.mjs";
14
+ import { C as ClearSheetDrawingTransformerOperation, I as InsertSheetDrawingCommand, S as SheetCanvasFloatDomManagerService } from "../canvas-float-dom-manager.service-DKCX6W5w.mjs";
15
15
  import React, { useEffect, forwardRef, useRef, createElement, useState } from "react";
16
16
  import { MessageType, RadioGroup, Radio } from "@univerjs/design";
17
17
  const PLUGIN_CONFIG_KEY = "sheets-drawing-ui.config", defaultPluginConfig = {}, RemoveSheetDrawingCommand = {
18
18
  id: "sheet.command.remove-sheet-image",
19
19
  type: CommandType.COMMAND,
20
20
  handler: /* @__PURE__ */ __name((accessor, params) => {
21
+ var _a10, _b, _c;
21
22
  const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), sheetInterceptorService = accessor.get(SheetInterceptorService), sheetDrawingService = accessor.get(ISheetDrawingService);
22
23
  if (!params) return !1;
23
24
  const { drawings } = params, unitIds = [];
@@ -26,14 +27,16 @@ const PLUGIN_CONFIG_KEY = "sheets-drawing-ui.config", defaultPluginConfig = {},
26
27
  unitIds.push(unitId2);
27
28
  });
28
29
  const jsonOp = sheetDrawingService.getBatchRemoveOp(drawings), { unitId, subUnitId, undo, redo, objects } = jsonOp, intercepted = sheetInterceptorService.onCommandExecute({ id: RemoveSheetDrawingCommand.id, params }), removeMutation = { id: SetDrawingApplyMutation.id, params: { unitId, subUnitId, op: redo, objects, type: DrawingApplyType.REMOVE } }, undoRemoveMutation = { id: SetDrawingApplyMutation.id, params: { unitId, subUnitId, op: undo, objects, type: DrawingApplyType.INSERT } };
29
- return sequenceExecute([removeMutation, ...intercepted.redos], commandService) ? (undoRedoService.pushUndoRedo({
30
+ return sequenceExecute([...(_a10 = intercepted.preRedos) != null ? _a10 : [], removeMutation, ...intercepted.redos], commandService) ? (undoRedoService.pushUndoRedo({
30
31
  unitID: unitId,
31
32
  undoMutations: [
32
- ...intercepted.undos,
33
+ ...(_b = intercepted.preUndos) != null ? _b : [],
33
34
  undoRemoveMutation,
35
+ ...intercepted.undos,
34
36
  { id: ClearSheetDrawingTransformerOperation.id, params: unitIds }
35
37
  ],
36
38
  redoMutations: [
39
+ ...(_c = intercepted.preRedos) != null ? _c : [],
37
40
  removeMutation,
38
41
  ...intercepted.redos,
39
42
  { id: ClearSheetDrawingTransformerOperation.id, params: unitIds }
@@ -1,8 +1,8 @@
1
1
  import { IDisposable, IPosition, ITransformState, Serializable, Worksheet, Disposable, ICommandService, IUniverInstanceService, LifecycleService } from '@univerjs/core';
2
2
  import { IBoundRectNoAngle, Scene, SpreadsheetSkeleton, IRenderManagerService, Rect } from '@univerjs/engine-render';
3
- import { ISheetFloatDom, ISheetDrawingService } from '@univerjs/sheets-drawing';
4
3
  import { IFloatDomLayout, CanvasFloatDomService } from '@univerjs/ui';
5
4
  import { DrawingTypeEnum, IDrawingManagerService } from '@univerjs/drawing';
5
+ import { ISheetDrawingService } from '@univerjs/sheets-drawing';
6
6
  import { BehaviorSubject } from 'rxjs';
7
7
  export interface ICanvasFloatDom {
8
8
  /**
@@ -96,10 +96,9 @@ export declare class SheetCanvasFloatDomManagerService extends Disposable {
96
96
  private _featureUpdateListener;
97
97
  private _deleteListener;
98
98
  updateFloatDomProps(unitId: string, subUnitId: string, id: string, props: Record<string, any>): void;
99
- addFloatDomToPosition(layer: ICanvasFloatDom, propId?: string, executeCommand?: boolean): {
99
+ addFloatDomToPosition(layer: ICanvasFloatDom, propId?: string): {
100
100
  id: string;
101
101
  dispose: () => void;
102
- sheetDrawingParam: ISheetFloatDom;
103
102
  } | undefined;
104
103
  private _removeDom;
105
104
  addHook(hook: ISheetCanvasFloatDomHook): IDisposable;
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(u,m){typeof exports=="object"&&typeof module<"u"?m(require("@univerjs/sheets/facade"),require("@univerjs/sheets-ui/facade"),require("@univerjs/ui"),require("@univerjs/core"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("rxjs")):typeof define=="function"&&define.amd?define(["@univerjs/sheets/facade","@univerjs/sheets-ui/facade","@univerjs/ui","@univerjs/core","@univerjs/drawing","@univerjs/engine-render","@univerjs/sheets","@univerjs/sheets-drawing","@univerjs/sheets-ui","rxjs"],m):(u=typeof globalThis<"u"?globalThis:u||self,m(u["UniverSheets/facade"],u["UniverSheetsUi/facade"],u.UniverUi,u.UniverCore,u.UniverDrawing,u.UniverEngineRender,u.UniverSheets,u.UniverSheetsDrawing,u.UniverSheetsUi,u.rxjs))})(this,function(u,m,b,l,I,T,Y,D,x,_){"use strict";var oe=Object.defineProperty;var ae=(u,m,b)=>m in u?oe(u,m,{enumerable:!0,configurable:!0,writable:!0,value:b}):u[m]=b;var M=(u,m,b)=>ae(u,typeof m!="symbol"?m+"":m,b);const V={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(p,n)=>{const e=p.get(T.IRenderManagerService);return n.forEach(t=>{var r,i;(i=(r=e.getRenderById(t))==null?void 0:r.scene.getTransformer())==null||i.debounceRefreshControls()}),!0}},q={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(p,n)=>{const e=p.get(l.ICommandService),t=p.get(l.IUndoRedoService),r=p.get(D.ISheetDrawingService),i=p.get(Y.SheetInterceptorService);if(!n)return!1;const s=n.drawings,o=s.map(O=>O.unitId),a=r.getBatchAddOp(s),{unitId:h,subUnitId:c,undo:d,redo:f,objects:S}=a,g=i.onCommandExecute({id:q.id,params:n}),C={id:D.SetDrawingApplyMutation.id,params:{op:f,unitId:h,subUnitId:c,objects:S,type:D.DrawingApplyType.INSERT}},W={id:D.SetDrawingApplyMutation.id,params:{op:d,unitId:h,subUnitId:c,objects:S,type:D.DrawingApplyType.REMOVE}};return l.sequenceExecute([C,...g.redos],e)?(t.pushUndoRedo({unitID:h,undoMutations:[...g.undos,W,{id:V.id,params:o}],redoMutations:[C,...g.redos,{id:V.id,params:o}]}),!0):!1}};var Q=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,te=(p,n,e,t)=>{for(var r=t>1?void 0:t?ee(n,e):n,i=p.length-1,s;i>=0;i--)(s=p[i])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&Q(n,e,r),r},E=(p,n)=>(e,t)=>n(e,t,p);function ne(p,n,e,t){const{scaleX:r,scaleY:i}=n.getAncestorScale(),s=n.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN),o={left:!0,top:!0};if(!s)return{...p,absolute:o};const{left:a,right:h,top:c,bottom:d}=p,f=t.getFreeze(),{startColumn:S,startRow:g,xSplit:C,ySplit:W}=f,k=e.getNoMergeCellPositionByIndexWithNoHeader(g-W,S-C),O=e.getNoMergeCellPositionByIndexWithNoHeader(g,S),{rowHeaderWidth:j,columnHeaderHeight:A}=e,R=O.startX-k.startX,P=O.startY-k.startY,{top:N,left:L,viewportScrollX:F,viewportScrollY:w}=s;let $,y;a<L?(o.left=!0,$=(R+j+(a-L))*r,y=Math.max(Math.min((R+j+(h-L))*r,(R+j)*r),(h-F)*r)):(o.left=!1,$=Math.max((a-F)*r,(R+j)*r),y=Math.max((h-F)*r,(R+j)*r));let U,B;return c<N?(o.top=!0,U=(P+A+(c-N))*i,B=Math.max(Math.min((P+A+(h-N))*i,(P+A)*i),(d-w)*i)):(o.top=!1,U=Math.max((c-w)*i,(P+A)*i),B=Math.max((d-w)*i,(P+A)*i)),{left:$,right:y,top:U,bottom:B,absolute:o}}const X=(p,n,e,t)=>{const{scene:r}=n,{left:i,top:s,width:o,height:a,angle:h}=p,c={left:i,right:i+o,top:s,bottom:s+a},d=ne(c,r,e,t),{scaleX:f,scaleY:S}=r.getAncestorScale();return{startX:d.left,endX:d.right,startY:d.top,endY:d.bottom,rotate:h,width:o*f,height:a*S,absolute:d.absolute}};let K=class extends l.Disposable{constructor(n,e,t,r,i,s,o){super();M(this,"_domLayerMap",new Map);M(this,"_domLayerInfoMap",new Map);M(this,"_transformChange$",new _.Subject);M(this,"transformChange$",this._transformChange$.asObservable());M(this,"_add$",new _.Subject);M(this,"add$",this._add$.asObservable());M(this,"_remove$",new _.Subject);M(this,"remove$",this._remove$.asObservable());M(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=r,this._canvasFloatDomService=i,this._sheetDrawingService=s,this._lifecycleService=o,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(_.filter(n=>n===l.LifecycleStages.Rendered),_.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(n,e){let t=this._domLayerMap.get(n);t||(t=new Map,this._domLayerMap.set(n,t));let r=t.get(e);return r||(r=new Map,t.set(e,r)),r}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 r=t.getTransformerByCreate(),i=e.engine.getCanvasElement();return{scene:t,transformer:r,renderObject:e,canvas:i}}_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 G,J,Z;const{unitId:t,subUnitId:r,drawingId:i}=e,s=Y.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:r}),o=this._drawingManagerService.getDrawingByParam(e);if(!o||!s)return;const a=(G=this._renderManagerService.getRenderById(t))==null?void 0:G.with(x.SheetSkeletonManagerService).getWorksheetSkeleton(r);if(!a)return;const{transform:h,drawingType:c,data:d}=o;if(c!==I.DrawingTypeEnum.DRAWING_DOM&&c!==I.DrawingTypeEnum.DRAWING_CHART)return;const f=this._getSceneAndTransformerByDrawingSearch(t);if(f==null)return;const{scene:S,canvas:g}=f;if(h==null)return!0;const{left:C,top:W,width:k,height:O,angle:j,flipX:A,flipY:R,skewX:P,skewY:N}=h,L=I.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:r,drawingId:i}),F=S.getObject(L);if(F!=null){F.transformByState({left:C,top:W,width:k,height:O,angle:j,flipX:A,flipY:R,skewX:P,skewY:N});return}const w={left:C,top:W,width:k,height:O,zIndex:this._drawingManagerService.getDrawingOrder(t,r).length-1},$=c===I.DrawingTypeEnum.DRAWING_CHART;$&&(w.fill="white",w.rotateEnabled=!1,d&&d.border&&(w.stroke=d.border),w.paintFirst="stroke",w.strokeWidth=1,w.borderEnabled=!1);const y=new T.Rect(L,w);$&&y.setObjectType(T.ObjectType.CHART),S.addObject(y,T.DRAWING_OBJECT_LAYER_INDEX),o.allowTransform!==!1&&S.attachTransformerTo(y);const U=this._ensureMap(t,r),B=new l.DisposableCollection,ie=X(y,f.renderObject,a.skeleton,s.worksheet),H=new _.BehaviorSubject(ie),se={dispose:B,rect:y,position$:H,unitId:t,subUnitId:r};this._canvasFloatDomService.addFloatDom({position$:H,id:i,componentKey:o.componentKey,onPointerDown:v=>{g.dispatchEvent(new PointerEvent(v.type,v))},onPointerMove:v=>{g.dispatchEvent(new PointerEvent(v.type,v))},onPointerUp:v=>{g.dispatchEvent(new PointerEvent(v.type,v))},onWheel:v=>{g.dispatchEvent(new WheelEvent(v.type,v))},props:(Z=(J=U.get(i))==null?void 0:J.props)!=null?Z:this._getFloatDomProps(i),data:d,unitId:t});const z=y.onTransformChange$.subscribeEvent(()=>{const v=X(y,f.renderObject,a.skeleton,s.worksheet);H.next(v)});B.add(()=>{this._canvasFloatDomService.removeFloatDom(i)}),z&&B.add(z),this._domLayerInfoMap.set(i,se),U.set(i,{...U.get(i)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:r,drawingId:i}=e,s=I.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:r,drawingId:i}),o=this._getSceneAndTransformerByDrawingSearch(t);if(o==null)return;const{transformer:a,scene:h}=o,c=h.getObject(s);c!=null&&c.oKey&&a.clearControlByIds([c==null?void 0:c.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var h;const r=this._getSceneAndTransformerByDrawingSearch(e),i=this._ensureMap(e,t),s=Array.from(i.keys()),o=Y.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),a=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(x.SheetSkeletonManagerService).getWorksheetSkeleton(t);!r||!o||!a||s.forEach(c=>{const d=this._domLayerInfoMap.get(c);if(d){const f=X(d.rect,r.renderObject,a.skeleton,o.worksheet);d.position$.next(f)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(_.filter(e=>!!e),_.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getActiveSheet().getSheetId()}:null}),_.filter(e=>!!e),_.switchMap(e=>l.fromEventSubject(e.render.scene.getViewport(x.VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(_.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{n(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,r;if(e.id===x.SetZoomRatioOperation.id){const i=e.params,{unitId:s}=i;Array.from((r=(t=this._domLayerMap.get(s))==null?void 0:t.keys())!=null?r:[]).forEach(a=>{n(s,a)})}else if(e.id===Y.SetFrozenMutation.id){const{unitId:i,subUnitId:s}=e.params;n(i,s)}}))}_getPosition(n,e){var f;const{startX:t,endX:r,startY:i,endY:s}=n,o=(f=this._renderManagerService.getRenderById(e))==null?void 0:f.with(x.ISheetSelectionRenderService);if(o==null)return;const a=o.getSelectionCellByPosition(t,i);if(a==null)return;const h={column:a.actualColumn,columnOffset:t-a.startX,row:a.actualRow,rowOffset:i-a.startY},c=o.getSelectionCellByPosition(r,s);if(c==null)return;const d={column:c.actualColumn,columnOffset:r-c.startX,row:c.actualRow,rowOffset:s-c.startY};return{from:h,to:d}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==I.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==I.DrawingTypeEnum.DRAWING_CHART)return;const r={...t.transform};this._transformChange$.next({id:e.drawingId,value:r})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(n,e,t,r){const i=this._domLayerInfoMap.get(t),s=this._getSceneAndTransformerByDrawingSearch(n);if(i&&s){const{scene:o}=s,a=I.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),h=o.getObject(a);h&&h instanceof T.Rect&&h.setProps(r)}}addFloatDomToPosition(n,e,t=!0){const r=Y.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!r)throw new Error("cannot find current target!");const{unitId:i,subUnitId:s}=r,{initPosition:o,componentKey:a,data:h,allowTransform:c=!0}=n,d=e!=null?e:l.generateRandomId(),f=this._getPosition(o,i);if(f==null)return;this._ensureMap(i,s).set(d,n);const g={unitId:i,subUnitId:s,drawingId:d,drawingType:n.type||I.DrawingTypeEnum.DRAWING_DOM,componentKey:a,sheetTransform:f,transform:{left:o.startX,top:o.startY,width:o.endX-o.startX,height:o.endY-o.startY},data:h,allowTransform:c};return t&&this._commandService.executeCommand(q.id,{unitId:i,drawings:[g]}),this._add$.next({unitId:i,subUnitId:s,id:d}),{id:d,dispose:()=>{this._removeDom(d,!0)},sheetDrawingParam:g}}_removeDom(n,e=!1){const t=this._domLayerInfoMap.get(n);if(!t)return;const{unitId:r,subUnitId:i}=t;this._domLayerInfoMap.delete(n),t.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(r);if(s&&s.scene.removeObject(t.rect),e){this._ensureMap(r,i).delete(n);const a=this._drawingManagerService.getDrawingByParam({unitId:r,subUnitId:i,drawingId:n});if(!a)return;const h=this._sheetDrawingService.getBatchRemoveOp([a]),{redo:c,objects:d}=h;this._commandService.syncExecuteCommand(D.SetDrawingApplyMutation.id,{unitId:r,subUnitId:i,op:c,objects:d,type:D.DrawingApplyType.REMOVE})}}addHook(n){return this._hooks.push(n),{dispose:()=>{const e=this._hooks.findIndex(t=>t===n);this._hooks.splice(e,1)}}}};K=te([E(0,l.Inject(T.IRenderManagerService)),E(1,l.IUniverInstanceService),E(2,l.Inject(l.ICommandService)),E(3,I.IDrawingManagerService),E(4,l.Inject(b.CanvasFloatDomService)),E(5,D.ISheetDrawingService),E(6,l.Inject(l.LifecycleService))],K);class re extends u.FWorksheet{addFloatDomToPosition(n,e){const t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),{key:i,disposableCollection:s}=m.transformComponentKey(n,this._injector.get(b.ComponentManager)),a=this._injector.get(K).addFloatDomToPosition({...n,componentKey:i,unitId:t,subUnitId:r},e);return a?(s.add(a.dispose),{id:a.id,dispose:()=>{s.dispose(),a.dispose()}}):(s.dispose(),null)}}u.FWorksheet.extend(re)});
1
+ (function(u,m){typeof exports=="object"&&typeof module<"u"?m(require("@univerjs/sheets/facade"),require("@univerjs/sheets-ui/facade"),require("@univerjs/ui"),require("@univerjs/core"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("rxjs")):typeof define=="function"&&define.amd?define(["@univerjs/sheets/facade","@univerjs/sheets-ui/facade","@univerjs/ui","@univerjs/core","@univerjs/drawing","@univerjs/engine-render","@univerjs/sheets","@univerjs/sheets-drawing","@univerjs/sheets-ui","rxjs"],m):(u=typeof globalThis<"u"?globalThis:u||self,m(u["UniverSheets/facade"],u["UniverSheetsUi/facade"],u.UniverUi,u.UniverCore,u.UniverDrawing,u.UniverEngineRender,u.UniverSheets,u.UniverSheetsDrawing,u.UniverSheetsUi,u.rxjs))})(this,function(u,m,O,l,I,j,Y,E,x,_){"use strict";var oe=Object.defineProperty;var ae=(u,m,O)=>m in u?oe(u,m,{enumerable:!0,configurable:!0,writable:!0,value:O}):u[m]=O;var b=(u,m,O)=>ae(u,typeof m!="symbol"?m+"":m,O);const V={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(p,r)=>{const e=p.get(j.IRenderManagerService);return r.forEach(t=>{var n,i;(i=(n=e.getRenderById(t))==null?void 0:n.scene.getTransformer())==null||i.debounceRefreshControls()}),!0}},q={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(p,r)=>{var C,M,D;const e=p.get(l.ICommandService),t=p.get(l.IUndoRedoService),n=p.get(E.ISheetDrawingService),i=p.get(Y.SheetInterceptorService);if(!r)return!1;const s=r.drawings,a=s.map(T=>T.unitId),o=n.getBatchAddOp(s),{unitId:d,subUnitId:c,undo:h,redo:f,objects:v}=o,g=i.onCommandExecute({id:q.id,params:r}),A={id:E.SetDrawingApplyMutation.id,params:{op:f,unitId:d,subUnitId:c,objects:v,type:E.DrawingApplyType.INSERT}},W={id:E.SetDrawingApplyMutation.id,params:{op:h,unitId:d,subUnitId:c,objects:v,type:E.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(C=g.preRedos)!=null?C:[],A,...g.redos],e)?(t.pushUndoRedo({unitID:d,undoMutations:[...(M=g.preUndos)!=null?M:[],W,...g.undos,{id:V.id,params:a}],redoMutations:[...(D=g.preRedos)!=null?D:[],A,...g.redos,{id:V.id,params:a}]}),!0):!1}};var Q=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,te=(p,r,e,t)=>{for(var n=t>1?void 0:t?ee(r,e):r,i=p.length-1,s;i>=0;i--)(s=p[i])&&(n=(t?s(r,e,n):s(n))||n);return t&&n&&Q(r,e,n),n},R=(p,r)=>(e,t)=>r(e,t,p);function ne(p,r,e,t){const{scaleX:n,scaleY:i}=r.getAncestorScale(),s=r.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN),a={left:!0,top:!0};if(!s)return{...p,absolute:a};const{left:o,right:d,top:c,bottom:h}=p,f=t.getFreeze(),{startColumn:v,startRow:g,xSplit:A,ySplit:W}=f,k=e.getNoMergeCellPositionByIndexWithNoHeader(g-W,v-A),C=e.getNoMergeCellPositionByIndexWithNoHeader(g,v),{rowHeaderWidth:M,columnHeaderHeight:D}=e,T=C.startX-k.startX,P=C.startY-k.startY,{top:N,left:L,viewportScrollX:F,viewportScrollY:w}=s;let $,y;o<L?(a.left=!0,$=(T+M+(o-L))*n,y=Math.max(Math.min((T+M+(d-L))*n,(T+M)*n),(d-F)*n)):(a.left=!1,$=Math.max((o-F)*n,(T+M)*n),y=Math.max((d-F)*n,(T+M)*n));let U,B;return c<N?(a.top=!0,U=(P+D+(c-N))*i,B=Math.max(Math.min((P+D+(d-N))*i,(P+D)*i),(h-w)*i)):(a.top=!1,U=Math.max((c-w)*i,(P+D)*i),B=Math.max((h-w)*i,(P+D)*i)),{left:$,right:y,top:U,bottom:B,absolute:a}}const X=(p,r,e,t)=>{const{scene:n}=r,{left:i,top:s,width:a,height:o,angle:d}=p,c={left:i,right:i+a,top:s,bottom:s+o},h=ne(c,n,e,t),{scaleX:f,scaleY:v}=n.getAncestorScale();return{startX:h.left,endX:h.right,startY:h.top,endY:h.bottom,rotate:d,width:a*f,height:o*v,absolute:h.absolute}};let K=class extends l.Disposable{constructor(r,e,t,n,i,s,a){super();b(this,"_domLayerMap",new Map);b(this,"_domLayerInfoMap",new Map);b(this,"_transformChange$",new _.Subject);b(this,"transformChange$",this._transformChange$.asObservable());b(this,"_add$",new _.Subject);b(this,"add$",this._add$.asObservable());b(this,"_remove$",new _.Subject);b(this,"remove$",this._remove$.asObservable());b(this,"_hooks",[]);this._renderManagerService=r,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=n,this._canvasFloatDomService=i,this._sheetDrawingService=s,this._lifecycleService=a,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(_.filter(r=>r===l.LifecycleStages.Rendered),_.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(r,e){let t=this._domLayerMap.get(r);t||(t=new Map,this._domLayerMap.set(r,t));let n=t.get(e);return n||(n=new Map,t.set(e,n)),n}getFloatDomInfo(r){return this._domLayerInfoMap.get(r)}_getSceneAndTransformerByDrawingSearch(r){if(r==null)return;const e=this._renderManagerService.getRenderById(r),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const n=t.getTransformerByCreate(),i=e.engine.getCanvasElement();return{scene:t,transformer:n,renderObject:e,canvas:i}}_getFloatDomProps(r){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(r)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(r=>{r.forEach(e=>{var G,J,Z;const{unitId:t,subUnitId:n,drawingId:i}=e,s=Y.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:n}),a=this._drawingManagerService.getDrawingByParam(e);if(!a||!s)return;const o=(G=this._renderManagerService.getRenderById(t))==null?void 0:G.with(x.SheetSkeletonManagerService).getWorksheetSkeleton(n);if(!o)return;const{transform:d,drawingType:c,data:h}=a;if(c!==I.DrawingTypeEnum.DRAWING_DOM&&c!==I.DrawingTypeEnum.DRAWING_CHART)return;const f=this._getSceneAndTransformerByDrawingSearch(t);if(f==null)return;const{scene:v,canvas:g}=f;if(d==null)return!0;const{left:A,top:W,width:k,height:C,angle:M,flipX:D,flipY:T,skewX:P,skewY:N}=d,L=I.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:n,drawingId:i}),F=v.getObject(L);if(F!=null){F.transformByState({left:A,top:W,width:k,height:C,angle:M,flipX:D,flipY:T,skewX:P,skewY:N});return}const w={left:A,top:W,width:k,height:C,zIndex:this._drawingManagerService.getDrawingOrder(t,n).length-1},$=c===I.DrawingTypeEnum.DRAWING_CHART;$&&(w.fill="white",w.rotateEnabled=!1,h&&h.border&&(w.stroke=h.border),w.paintFirst="stroke",w.strokeWidth=1,w.borderEnabled=!1);const y=new j.Rect(L,w);$&&y.setObjectType(j.ObjectType.CHART),v.addObject(y,j.DRAWING_OBJECT_LAYER_INDEX),a.allowTransform!==!1&&v.attachTransformerTo(y);const U=this._ensureMap(t,n),B=new l.DisposableCollection,ie=X(y,f.renderObject,o.skeleton,s.worksheet),H=new _.BehaviorSubject(ie),se={dispose:B,rect:y,position$:H,unitId:t,subUnitId:n};this._canvasFloatDomService.addFloatDom({position$:H,id:i,componentKey:a.componentKey,onPointerDown:S=>{g.dispatchEvent(new PointerEvent(S.type,S))},onPointerMove:S=>{g.dispatchEvent(new PointerEvent(S.type,S))},onPointerUp:S=>{g.dispatchEvent(new PointerEvent(S.type,S))},onWheel:S=>{g.dispatchEvent(new WheelEvent(S.type,S))},props:(Z=(J=U.get(i))==null?void 0:J.props)!=null?Z:this._getFloatDomProps(i),data:h,unitId:t});const z=y.onTransformChange$.subscribeEvent(()=>{const S=X(y,f.renderObject,o.skeleton,s.worksheet);H.next(S)});B.add(()=>{this._canvasFloatDomService.removeFloatDom(i)}),z&&B.add(z),this._domLayerInfoMap.set(i,se),U.set(i,{...U.get(i)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(r=>{r.forEach(e=>{const{unitId:t,subUnitId:n,drawingId:i}=e,s=I.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:n,drawingId:i}),a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;const{transformer:o,scene:d}=a,c=d.getObject(s);c!=null&&c.oKey&&o.clearControlByIds([c==null?void 0:c.oKey])})}))}_scrollUpdateListener(){const r=(e,t)=>{var d;const n=this._getSceneAndTransformerByDrawingSearch(e),i=this._ensureMap(e,t),s=Array.from(i.keys()),a=Y.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),o=(d=this._renderManagerService.getRenderById(e))==null?void 0:d.with(x.SheetSkeletonManagerService).getWorksheetSkeleton(t);!n||!a||!o||s.forEach(c=>{const h=this._domLayerInfoMap.get(c);if(h){const f=X(h.rect,n.renderObject,o.skeleton,a.worksheet);h.position$.next(f)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(_.filter(e=>!!e),_.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getActiveSheet().getSheetId()}:null}),_.filter(e=>!!e),_.switchMap(e=>l.fromEventSubject(e.render.scene.getViewport(x.VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(_.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{r(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,n;if(e.id===x.SetZoomRatioOperation.id){const i=e.params,{unitId:s}=i;Array.from((n=(t=this._domLayerMap.get(s))==null?void 0:t.keys())!=null?n:[]).forEach(o=>{r(s,o)})}else if(e.id===Y.SetFrozenMutation.id){const{unitId:i,subUnitId:s}=e.params;r(i,s)}}))}_getPosition(r,e){var f;const{startX:t,endX:n,startY:i,endY:s}=r,a=(f=this._renderManagerService.getRenderById(e))==null?void 0:f.with(x.ISheetSelectionRenderService);if(a==null)return;const o=a.getSelectionCellByPosition(t,i);if(o==null)return;const d={column:o.actualColumn,columnOffset:t-o.startX,row:o.actualRow,rowOffset:i-o.startY},c=a.getSelectionCellByPosition(n,s);if(c==null)return;const h={column:c.actualColumn,columnOffset:n-c.startX,row:c.actualRow,rowOffset:s-c.startY};return{from:d,to:h}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(r=>{r.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==I.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==I.DrawingTypeEnum.DRAWING_CHART)return;const n={...t.transform};this._transformChange$.next({id:e.drawingId,value:n})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(r=>{r.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(r,e,t,n){const i=this._domLayerInfoMap.get(t),s=this._getSceneAndTransformerByDrawingSearch(r);if(i&&s){const{scene:a}=s,o=I.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:e,drawingId:t}),d=a.getObject(o);d&&d instanceof j.Rect&&d.setProps(n)}}addFloatDomToPosition(r,e){const t=Y.getSheetCommandTarget(this._univerInstanceService,{unitId:r.unitId,subUnitId:r.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:n,subUnitId:i}=t,{initPosition:s,componentKey:a,data:o,allowTransform:d=!0}=r,c=e!=null?e:l.generateRandomId(),h=this._getPosition(s,n);if(h==null)return;this._ensureMap(n,i).set(c,r);const v={unitId:n,subUnitId:i,drawingId:c,drawingType:r.type||I.DrawingTypeEnum.DRAWING_DOM,componentKey:a,sheetTransform:h,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:o,allowTransform:d};return this._commandService.executeCommand(q.id,{unitId:n,drawings:[v]}),this._add$.next({unitId:n,subUnitId:i,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(r,e=!1){const t=this._domLayerInfoMap.get(r);if(!t)return;const{unitId:n,subUnitId:i}=t;this._domLayerInfoMap.delete(r),t.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(n);if(s&&s.scene.removeObject(t.rect),e){this._ensureMap(n,i).delete(r);const o=this._drawingManagerService.getDrawingByParam({unitId:n,subUnitId:i,drawingId:r});if(!o)return;const d=this._sheetDrawingService.getBatchRemoveOp([o]),{redo:c,objects:h}=d;this._commandService.syncExecuteCommand(E.SetDrawingApplyMutation.id,{unitId:n,subUnitId:i,op:c,objects:h,type:E.DrawingApplyType.REMOVE})}}addHook(r){return this._hooks.push(r),{dispose:()=>{const e=this._hooks.findIndex(t=>t===r);this._hooks.splice(e,1)}}}};K=te([R(0,l.Inject(j.IRenderManagerService)),R(1,l.IUniverInstanceService),R(2,l.Inject(l.ICommandService)),R(3,I.IDrawingManagerService),R(4,l.Inject(O.CanvasFloatDomService)),R(5,E.ISheetDrawingService),R(6,l.Inject(l.LifecycleService))],K);class re extends u.FWorksheet{addFloatDomToPosition(r,e){const t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),{key:i,disposableCollection:s}=m.transformComponentKey(r,this._injector.get(O.ComponentManager)),o=this._injector.get(K).addFloatDomToPosition({...r,componentKey:i,unitId:t,subUnitId:n},e);return o?(s.add(o.dispose),{id:o.id,dispose:()=>{s.dispose(),o.dispose()}}):(s.dispose(),null)}}u.FWorksheet.extend(re)});
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,T,Q,N,h,j,V,B,_,H,J){"use strict";var nn=Object.defineProperty;var rn=(O,p,T)=>p in O?nn(O,p,{enumerable:!0,configurable:!0,writable:!0,value:T}):O[p]=T;var X=(O,p,T)=>rn(O,typeof p!="symbol"?p+"":p,T);const ze="sheets-drawing-ui.config",Je={},G={id:"sheet.operation.clear-drawing-transformer",type:p.CommandType.MUTATION,handler:(i,n)=>{const r=i.get(N.IRenderManagerService);return n.forEach(e=>{var t,o;(o=(t=r.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,n)=>{const r=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),t=i.get(_.SheetInterceptorService),o=i.get(h.ISheetDrawingService);if(!n)return!1;const{drawings:a}=n,c=[];a.forEach(M=>{const{unitId:C}=M;c.push(C)});const d=o.getBatchRemoveOp(a),{unitId:g,subUnitId:l,undo:s,redo:u,objects:m}=d,S=t.onCommandExecute({id:ie.id,params:n}),f={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([f,...S.redos],r)?(e.pushUndoRedo({unitID:g,undoMutations:[...S.undos,v,{id:G.id,params:c}],redoMutations:[f,...S.redos,{id:G.id,params:c}]}),!0):!1}},je="COMPONENT_SHEET_DRAWING_PANEL",Ce={id:"sidebar.operation.sheet-image",type:p.CommandType.COMMAND,handler:async(i,n)=>{const r=i.get(V.ISidebarService),e=i.get(p.LocaleService),t=i.get(p.IUniverInstanceService),o=i.get(T.IDrawingManagerService);if(!_.getSheetCommandTarget(t))return!1;switch(n.value){case"open":r.open({header:{title:e.t("sheetImage.panel.title")},children:{label:je},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:r.close();break}return!0}},ye={id:"sheet.operation.edit-sheet-image",type:p.CommandType.OPERATION,handler:(i,n)=>{const r=i.get(T.IDrawingManagerService),e=i.get(p.ICommandService);return n==null?!1:(r.focusDrawing([n]),e.executeCommand(Ce.id,{value:"open"}),!0)}};var Le={exports:{}},de={};/**
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,Q,N,h,j,V,B,I,H,J){"use strict";var nn=Object.defineProperty;var rn=(O,p,b)=>p in O?nn(O,p,{enumerable:!0,configurable:!0,writable:!0,value:b}):O[p]=b;var X=(O,p,b)=>rn(O,typeof p!="symbol"?p+"":p,b);const ze="sheets-drawing-ui.config",Je={},G={id:"sheet.operation.clear-drawing-transformer",type:p.CommandType.MUTATION,handler:(i,n)=>{const r=i.get(N.IRenderManagerService);return n.forEach(e=>{var t,o;(o=(t=r.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,n)=>{var y,C,T;const r=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),t=i.get(I.SheetInterceptorService),o=i.get(h.ISheetDrawingService);if(!n)return!1;const{drawings:a}=n,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:n}),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([...(y=f.preRedos)!=null?y:[],S,...f.redos],r)?(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}},je="COMPONENT_SHEET_DRAWING_PANEL",Ce={id:"sidebar.operation.sheet-image",type:p.CommandType.COMMAND,handler:async(i,n)=>{const r=i.get(V.ISidebarService),e=i.get(p.LocaleService),t=i.get(p.IUniverInstanceService),o=i.get(b.IDrawingManagerService);if(!I.getSheetCommandTarget(t))return!1;switch(n.value){case"open":r.open({header:{title:e.t("sheetImage.panel.title")},children:{label:je},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:r.close();break}return!0}},ye={id:"sheet.operation.edit-sheet-image",type:p.CommandType.OPERATION,handler:(i,n)=>{const r=i.get(b.IDrawingManagerService),e=i.get(p.ICommandService);return n==null?!1:(r.focusDrawing([n]),e.executeCommand(Ce.id,{value:"open"}),!0)}};var Le={exports:{}},de={};/**
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 Ze=H,qe=Symbol.for("react.element"),Qe=Symbol.for("react.fragment"),et=Object.prototype.hasOwnProperty,tt=Ze.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,nt={key:!0,ref:!0,__self:!0,__source:!0};function We(i,n,r){var e,t={},o=null,a=null;r!==void 0&&(o=""+r),n.key!==void 0&&(o=""+n.key),n.ref!==void 0&&(a=n.ref);for(e in n)et.call(n,e)&&!nt.hasOwnProperty(e)&&(t[e]=n[e]);if(i&&i.defaultProps)for(e in n=i.defaultProps,n)t[e]===void 0&&(t[e]=n[e]);return{$$typeof:qe,type:i,key:o,ref:a,props:t,_owner:tt.current}}de.Fragment=Qe,de.jsx=We,de.jsxs=We,Le.exports=de;var $=Le.exports;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"},rt=()=>{const i=p.useDependency(T.IImageIoService),n=p.useDependency(p.LocaleService),[r,e]=H.useState(0);return H.useEffect(()=>{const t=i.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[i]),$.jsx("div",{style:{display:r>0?"block":"none"},className:le.uploadLoading,children:$.jsxs("div",{className:le.uploadLoadingBody,children:[$.jsx("div",{className:le.uploadLoadingBodyAnimation}),$.jsx("div",{className:le.uploadLoadingBodyText,children:`${n.t("uploadLoading.loading")}: ${r}`})]})})};var it=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,at=(i,n,r,e)=>{for(var t=e>1?void 0:e?ot(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&it(n,r,t),t},ee=(i,n)=>(r,e)=>n(r,e,i);let ue=class extends p.RxDisposable{constructor(n,r,e,t,o,a,c){super();X(this,"_initImagePopupMenu",new Set);this._injector=n,this._drawingManagerService=r,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(B.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(p.UniverInstanceType.UNIVER_SHEET).pipe(B.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(p.UniverInstanceType.UNIVER_SHEET).forEach(n=>this._create(n)),this._uiPartsService.registerComponent(V.BuiltInUIPart.CONTENT,()=>p.connectInjector(rt,this._injector))}_dispose(n){const r=n.getUnitId();this._renderManagerService.removeRender(r)}_create(n){if(!n)return;const r=n.getUnitId();this._renderManagerService.has(r)&&!this._initImagePopupMenu.has(r)&&(this._popupMenuListener(r),this._initImagePopupMenu.add(r))}_hasCropObject(n){const r=n.getAllObjectsByOrder();for(const e of r)if(e instanceof Q.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const r=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!r)return;const e=r.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(p.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(r))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;t==null||t.dispose(),t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:Q.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems: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(n,r,e,t){return[{label:"image-popup.edit",index:0,commandId:ye.id,commandParams:{unitId:n,subUnitId:r,drawingId:e},disable:t===T.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ie.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:r,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:Q.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:r,drawingId:e},disable:t===T.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:Q.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:r,drawingId:e}],disable:t===T.DrawingTypeEnum.DRAWING_DOM}]}};ue=at([ee(0,p.Inject(p.Injector)),ee(1,T.IDrawingManagerService),ee(2,p.Inject(j.SheetCanvasPopManagerService)),ee(3,N.IRenderManagerService),ee(4,p.IUniverInstanceService),ee(5,p.IContextService),ee(6,p.Inject(V.IUIPartsService))],ue);function Y(i,n,r){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:S,columnOffset:f,row:v,rowOffset:y}=t,M=r.getCurrentSkeleton(),C=j.attachRangeWithCoord(M,{startColumn:l,endColumn:l,startRow:u,endRow:u});if(C==null)return;const b=j.attachRangeWithCoord(M,{startColumn:S,endColumn:S,startRow:v,endRow:v});if(b==null)return;const{startX:I,startY:R}=C,{startX:w,startY:U}=b;let E=N.precisionTo(I+s,1),L=N.precisionTo(R+m,1),A=N.precisionTo(w+f-E,1),P=N.precisionTo(U+y-L,1);C.startX===b.endX&&(A=0),C.startY===b.endY&&(P=0);const D=M.rowHeaderWidth+M.columnTotalWidth,W=M.columnHeaderHeight+M.rowTotalHeight;return E+A>D&&(E=D-A),L+P>W&&(L=W-P),{flipY:o,flipX:a,angle:c,skewX:d,skewY:g,left:E,top:L,width:A,height:P}}function k(i,n){const{left:r=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=n.getSelectionCellByPosition(r,e);if(s==null)return;const u={column:s.actualColumn,columnOffset:N.precisionTo(r-s.startX,1),row:s.actualRow,rowOffset:N.precisionTo(e-s.startY,1)},m=n.getSelectionCellByPosition(r+t,e+o);if(m==null)return;const S={column:m.actualColumn,columnOffset:N.precisionTo(r+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:S}}var st=Object.defineProperty,ct=Object.getOwnPropertyDescriptor,dt=(i,n,r,e)=>{for(var t=e>1?void 0:e?ct(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&st(n,r,t),t},me=(i,n)=>(r,e)=>n(r,e,i);let Me=class extends p.Disposable{constructor(i,n,r,e,t){super(),this._context=i,this._sheetDrawingService=n,this._drawingManagerService=r,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 n in i){const r=i[n];for(const e in r.data){const t=r.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)}};Me=dt([me(1,h.ISheetDrawingService),me(2,T.IDrawingManagerService),me(3,p.Inject(j.ISheetSelectionRenderService)),me(4,p.Inject(j.SheetSkeletonManagerService))],Me);var K=function(){return K=Object.assign||function(i){for(var n,r=1,e=arguments.length;r<e;r++){n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(i[t]=n[t])}return i},K.apply(this,arguments)},lt=function(i,n){var r={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&n.indexOf(e)<0&&(r[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(i);t<e.length;t++)n.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(i,e[t])&&(r[e[t]]=i[e[t]]);return r},Be=H.forwardRef(function(i,n){var r=i.icon,e=i.id,t=i.className,o=i.extend,a=lt(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),d=H.useRef("_".concat(gt()));return Ge(r,"".concat(e),{defIds:r.defIds,idSuffix:d.current},K({ref:n,className:c},a),o)});function Ge(i,n,r,e,t){return H.createElement(i.tag,K(K({key:n},ut(i,r,t)),e),(mt(i,r).children||[]).map(function(o,a){return Ge(o,"".concat(n,"-").concat(i.tag,"-").concat(a),r,void 0,t)}))}function ut(i,n,r){var e=K({},i.attrs);r!=null&&r.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=r.colorChannel1);var t=n.defIds;return!t||t.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+n.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(n.idSuffix,")")))})),e}function mt(i,n){var r,e=n.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((r=i.children)===null||r===void 0)&&r.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+n.idSuffix})}):t})}):i}function gt(){return Math.random().toString(36).substring(2,8)}Be.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"}}]},ke=H.forwardRef(function(i,n){return H.createElement(Be,Object.assign({},i,{id:"add-image-single",ref:n,icon:pt}))});ke.displayName="AddImageSingle";const De={id:"sheet.command.delete-drawing",type:p.CommandType.COMMAND,handler:i=>{const n=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 n.executeCommand(ie.id,{unitId:t,drawings:o})}};function ht(i){const n=[];return i.forEach(r=>{const{parent:e,children:t}=r,{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:S,drawingId:f}=s;return{unitId:m,subUnitId:S,drawingId:f,transform:{...u,left:u.left-d.left,top:u.top-d.top},groupId:c}}),l={unitId:o,subUnitId:a,drawingId:c,drawingType:T.DrawingTypeEnum.DRAWING_GROUP,transform:d};n.push({parent:l,children:g})}),n}function ft(i){const n=[];return i.forEach(r=>{const{parent:e,children:t}=r,{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:S,drawingId:f}=s,v=N.transformObjectOutOfGroup(u||{},d,d.width||0,d.height||0);return{unitId:m,subUnitId:S,drawingId:f,transform:v,groupId:void 0}}),l={unitId:o,subUnitId:a,drawingId:c,drawingType:T.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:l,children:g})}),n}const Re={id:"sheet.command.group-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),t=i.get(h.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:m,children:S})=>{o.push(m.unitId),S.forEach(f=>{o.push(f.unitId)})});const a=t.getGroupDrawingOp(n),{unitId:c,subUnitId:d,undo:g,redo:l,objects:s}=a;return r.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:ft(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}},oe={id:"sheet.command.insert-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),t=i.get(h.ISheetDrawingService),o=i.get(_.SheetInterceptorService);if(!n)return!1;const a=n.drawings,c=a.map(M=>M.unitId),d=t.getBatchAddOp(a),{unitId:g,subUnitId:l,undo:s,redo:u,objects:m}=d,S=o.onCommandExecute({id:oe.id,params:n}),f={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([f,...S.redos],r)?(e.pushUndoRedo({unitID:g,undoMutations:[...S.undos,v,{id:G.id,params:c}],redoMutations:[f,...S.redos,{id:G.id,params:c}]}),!0):!1}},Te={id:"sheet.command.set-drawing-arrange",type:p.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(p.ICommandService),e=i.get(p.IUndoRedoService);if(!n)return!1;const t=i.get(h.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:c,arrangeType:d}=n,g={unitId:o,subUnitId:a,drawingIds:c};let l;if(d===T.ArrangeTypeEnum.forward?l=t.getForwardDrawingsOp(g):d===T.ArrangeTypeEnum.backward?l=t.getBackwardDrawingOp(g):d===T.ArrangeTypeEnum.front?l=t.getFrontDrawingsOp(g):d===T.ArrangeTypeEnum.back&&(l=t.getBackDrawingsOp(g)),l==null)return!1;const{objects:s,redo:u,undo:m}=l;return r.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}},ae={id:"sheet.command.set-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),t=i.get(h.ISheetDrawingService);if(!n)return!1;const{drawings:o}=n,a=t.getBatchUpdateOp(o),{unitId:c,subUnitId:d,undo:g,redo:l,objects:s}=a;return r.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}},be={id:"sheet.command.ungroup-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),t=i.get(h.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:m,children:S})=>{o.push(m.unitId),S.forEach(f=>{o.push(f.unitId)})});const a=t.getUngroupDrawingOp(n),{unitId:c,subUnitId:d,undo:g,redo:l,objects:s}=a;return r.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:ht(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 St=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,wt=(i,n,r,e)=>{for(var t=e>1?void 0:e?vt(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&St(n,r,t),t},z=(i,n)=>(r,e)=>n(r,e,i);let ge=class extends p.Disposable{constructor(n,r,e,t,o,a,c,d,g,l,s,u){super();X(this,"_workbookSelections");this._context=n,this._skeletonManagerService=r,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 n=await this._fileOpenerService.openFile({multiple:!0,accept:T.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),r=n.length;return r>T.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(T.DRAWING_IMAGE_COUNT_LIMIT))}),!1):r===0?!1:(n.forEach(async e=>await this._insertFloatImage(e)),!0)}async _insertFloatImage(n){let r;try{r=await this._imageIoService.saveImage(n)}catch(M){const C=M.message;C===T.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(T.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===T.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===T.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(r==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:c,source:d,base64Cache:g}=r,{width:l,height:s,image:u}=await T.getImageSize(g||""),{width:m,height:S}=this._context.scene;this._imageIoService.addImageSourceCache(d,c,u);let f=1;if(l>T.DRAWING_IMAGE_WIDTH_LIMIT||s>T.DRAWING_IMAGE_HEIGHT_LIMIT){const M=T.DRAWING_IMAGE_WIDTH_LIMIT/l,C=T.DRAWING_IMAGE_HEIGHT_LIMIT/s;f=Math.max(M,C)}const v=this._getImagePosition(l*f,s*f,m,S);if(v==null)return;const y={unitId:t,subUnitId:o,drawingId:a,drawingType:T.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c,source:d,transform:Y(v,this._selectionRenderService,this._skeletonManagerService),sheetTransform:v};this._commandService.executeCommand(oe.id,{unitId:t,drawings:[y]})}_getUnitInfo(){const n=this._context.unit,r=n.getActiveSheet(),e=n.getUnitId(),t=r.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(n,r,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+n>e&&(l=e-n,l<0&&(l=0,n=e),u=!0),s+r>t&&(s=t-r,s<0&&(s=0,r=t),u=!0),u){const v=this._selectionRenderService.getSelectionCellByPosition(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},S=this._selectionRenderService.getSelectionCellByPosition(l+n,s+r);if(S==null)return;const f={column:S.actualColumn,columnOffset:l+n-S.startX,row:S.actualRow,rowOffset:s+r-S.startY};return{from:m,to:f}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(n=>{const{unitId:r,subUnitId:e,drawingIds:t,arrangeType:o}=n;this._commandService.executeCommand(Te.id,{unitId:r,subUnitId:e,drawingIds:t,arrangeType:o})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(n=>{const r=[];n.length!==0&&(n.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}};r.push(s)}),r.length>0&&this._commandService.executeCommand(ae.id,{unitId:n[0].unitId,drawings:r}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(n=>{this._commandService.executeCommand(Re.id,n);const{unitId:r,subUnitId:e,drawingId:t}=n[0].parent;this._drawingManagerService.focusDrawing([{unitId:r,subUnitId:e,drawingId:t}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(n=>{this._commandService.executeCommand(be.id,n)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(n=>{n==null||n.length===0?(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(n))}))}};ge=wt([z(1,p.Inject(j.SheetSkeletonManagerService)),z(2,p.ICommandService),z(3,j.ISheetSelectionRenderService),z(4,T.IImageIoService),z(5,V.ILocalFileService),z(6,h.ISheetDrawingService),z(7,T.IDrawingManagerService),z(8,p.IContextService),z(9,V.IMessageService),z(10,p.Inject(p.LocaleService)),z(11,p.Inject(_.SheetsSelectionsService))],ge);const pe={id:"sheet.command.insert-float-image",type:p.CommandType.COMMAND,handler:i=>{var r,e;return(e=(r=i.get(N.IRenderManagerService).getCurrentTypeOfRenderer(p.UniverInstanceType.UNIVER_SHEET))==null?void 0:r.with(ge).insertFloatImage())!=null?e:!1}},re={id:"sheet.command.move-drawing",type:p.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(p.ICommandService),e=i.get(h.ISheetDrawingService),t=i.get(j.ISheetSelectionRenderService),{direction:o}=n,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:S=0}=s;return o===p.Direction.UP?u.top=S-1:o===p.Direction.DOWN?u.top=S+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 r.syncExecuteCommand(ae.id,{unitId:c,drawings:d})?(r.syncExecuteCommand(G.id,[c]),!0):!1}},Ve="addition-and-subtraction-single",Ee="sheet.menu.image";function _t(i){return{id:Ee,type:V.MenuItemType.SUBITEMS,icon:Ve,tooltip:"sheetImage.title",hidden$:V.getMenuHiddenObservable(i,p.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(i,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function It(i){return{id:pe.id,title:"sheetImage.upload.float",type:V.MenuItemType.BUTTON,hidden$:V.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 $e(i){var n,r,e="";if(typeof i=="string"||typeof i=="number")e+=i;else if(typeof i=="object")if(Array.isArray(i)){var t=i.length;for(n=0;n<t;n++)i[n]&&(r=$e(i[n]))&&(e&&(e+=" "),e+=r)}else for(r in i)i[r]&&(e&&(e+=" "),e+=r);return e}function he(){for(var i,n,r=0,e="",t=arguments.length;r<t;r++)(i=arguments[r])&&(n=$e(i))&&(e&&(e+=" "),e+=n);return e}const Ct=i=>{var C;const n=p.useDependency(p.ICommandService),r=p.useDependency(p.LocaleService),e=p.useDependency(T.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]=H.useState(!0),m=(C=a.anchorType)!=null?C:h.SheetDrawingAnchorType.Position,[S,f]=H.useState(m);function v(b,I){const R=[];return b.forEach(w=>{const{oKey:U}=w,E=I.getDrawingOKey(U);if(E==null)return R.push(null),!0;const{unitId:L,subUnitId:A,drawingId:P,drawingType:D,anchorType:W,sheetTransform:F}=E;R.push({unitId:L,subUnitId:A,drawingId:P,anchorType:W,sheetTransform:F,drawingType:D})}),R}H.useEffect(()=>{const b=l.clearControl$.subscribe(R=>{R===!0&&u(!1)}),I=l.changeStart$.subscribe(R=>{var E;const{objects:w}=R,U=v(w,e);if(U.length===0)u(!1);else if(U.length>=1){u(!0);const L=((E=U[0])==null?void 0:E.anchorType)||h.SheetDrawingAnchorType.Position;f(L)}});return()=>{I.unsubscribe(),b.unsubscribe()}},[]);function y(b){f(b);const I=e.getFocusDrawings();if(I.length===0)return;const R=I.map(w=>({unitId:w.unitId,subUnitId:w.subUnitId,drawingId:w.drawingId,anchorType:b}));n.executeCommand(ae.id,{unitId:I[0].unitId,drawings:R})}const M=b=>b?"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:r.t("drawing-anchor.title")})})}),$.jsx("div",{className:he(Z.imageCommonPanelRow),children:$.jsx("div",{className:he(Z.imageCommonPanelColumn),children:$.jsxs(J.RadioGroup,{value:S,onChange:y,direction:"vertical",children:[$.jsx(J.Radio,{value:h.SheetDrawingAnchorType.Both,children:r.t("drawing-anchor.both")}),$.jsx(J.Radio,{value:h.SheetDrawingAnchorType.Position,children:r.t("drawing-anchor.position")}),$.jsx(J.Radio,{value:h.SheetDrawingAnchorType.None,children:r.t("drawing-anchor.none")})]})})})]})},yt=()=>{const i=p.useDependency(T.IDrawingManagerService),n=i.getFocusDrawings(),[r,e]=H.useState(n);return H.useEffect(()=>{const t=i.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(r!=null&&r.length)&&$.jsxs("div",{className:Z.imageCommonPanel,children:[$.jsx(Q.DrawingCommonPanel,{drawings:r}),$.jsx(Ct,{drawings:r})]})},Mt={[V.RibbonStartGroup.FORMULAS_INSERT]:{[Ee]:{order:3,menuItemFactory:_t,[pe.id]:{order:0,menuItemFactory:It}}}};function se(i){return!i.getContextValue(p.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(p.EDITOR_ACTIVATED)&&i.getContextValue(p.FOCUSING_COMMON_DRAWINGS)}const Dt={id:re.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:V.KeyCode.ARROW_DOWN,priority:100,preconditions:se,staticParameters:{direction:p.Direction.DOWN}},Rt={id:re.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:V.KeyCode.ARROW_UP,priority:100,preconditions:se,staticParameters:{direction:p.Direction.UP}},Tt={id:re.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:V.KeyCode.ARROW_LEFT,priority:100,preconditions:se,staticParameters:{direction:p.Direction.LEFT}},bt={id:re.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:V.KeyCode.ARROW_RIGHT,priority:100,preconditions:se,staticParameters:{direction:p.Direction.RIGHT}},Et={id:De.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:se,binding:V.KeyCode.DELETE,mac:V.KeyCode.BACKSPACE};var Ot=Object.defineProperty,Pt=Object.getOwnPropertyDescriptor,At=(i,n,r,e)=>{for(var t=e>1?void 0:e?Pt(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&Ot(n,r,t),t},fe=(i,n)=>(r,e)=>n(r,e,i);let Se=class extends p.Disposable{constructor(i,n,r,e){super(),this._componentManager=i,this._menuManagerService=n,this._commandService=r,this._shortcutService=e,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Ve,ke)),this.disposeWithMe(i.register(je,yt))}_initMenus(){this._menuManagerService.mergeMenu(Mt)}_initCommands(){[pe,oe,ie,ae,Ce,G,ye,Re,be,re,De,Te].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[Dt,Rt,Tt,bt,Et].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Se=At([fe(0,p.Inject(V.ComponentManager)),fe(1,V.IMenuManagerService),fe(2,p.ICommandService),fe(3,V.IShortcutService)],Se);var Ut=Object.defineProperty,Nt=Object.getOwnPropertyDescriptor,jt=(i,n,r,e)=>{for(var t=e>1?void 0:e?Nt(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&Ut(n,r,t),t},Oe=(i,n)=>(r,e)=>n(r,e,i);let ve=class extends p.Disposable{constructor(n,r,e){super();X(this,"_copyInfo");this._sheetClipboardService=n,this._renderManagerService=r,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(n,r,e)=>this._collect(n,r,e),onPasteCells:(n,r,e,t)=>{const{copyType:o=j.COPY_TYPE.COPY,pasteType:a}=t,{range:c}=n||{},{range:d,unitId:g,subUnitId:l}=r;return this._generateMutations(d,{copyType:o,pasteType:a,copyRange:c,unitId:g,subUnitId:l})},onPastePlainText:(n,r)=>({undos:[],redos:[]})})}_collect(n,r,e){var u;const t=(u=this._renderManagerService.getRenderById(n))==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(n,r),s=[];Object.keys(l).forEach(m=>{const S=l[m],{transform:f}=S;if(S.anchorType!==h.SheetDrawingAnchorType.Both||!f)return;const{left:v=0,top:y=0,width:M=0,height:C=0}=f,{drawingStartX:b,drawingEndX:I,drawingStartY:R,drawingEndY:w}={drawingStartX:v,drawingEndX:v+M,drawingStartY:y,drawingEndY:y+C};a<=b&&I<=c&&d<=R&&w<=g&&s.push(S)}),s.length&&(this._copyInfo={drawings:s,unitId:n,subUnitId:r})}_generateMutations(n,r){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(r.pasteType))return{redos:[],undos:[]};const{copyRange:e}=r;if(!e)return{redos:[],undos:[]};const{drawings:t,unitId:o,subUnitId:a}=this._copyInfo,{ranges:[c,d],mapFunc:g}=j.virtualizeDiscreteRanges([e,n]),{row:l,col:s}=g(c.startRow,c.startColumn),{row:u,col:m}=g(d.startRow,d.startColumn),S=(E=this._renderManagerService.getRenderById(o))==null?void 0:E.with(j.SheetSkeletonManagerService);if(!S)return{redos:[],undos:[]};const f=S.attachRangeWithCoord({startRow:l,endRow:l,startColumn:s,endColumn:s}),v=S.attachRangeWithCoord({startRow:u,endRow:u,startColumn:m,endColumn:m});if(!f||!v)return{redos:[],undos:[]};const y=[],M=[],C=v.startX-f.startX,b=v.startY-f.startY,I=u-l,R=m-s,w=r.copyType===j.COPY_TYPE.CUT,{_sheetDrawingService:U}=this;return t.forEach(L=>{const{transform:A,sheetTransform:P}=L;if(!A)return;const D={...L,unitId:o,subUnitId:a,drawingId:w?L.drawingId:p.Tools.generateRandomId(),transform:{...A,left:A.left+C,top:A.top+b},sheetTransform:{to:{...P.to,row:P.to.row+I,column:P.to.column+R},from:{...P.from,row:P.from.row+I,column:P.from.column+R}}};if(w){const{undo:W,redo:F,objects:ne}=U.getBatchUpdateOp([D]);y.push({id:h.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:h.DrawingApplyType.UPDATE,op:F,objects:ne}}),M.push({id:h.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:h.DrawingApplyType.UPDATE,op:W,objects:ne}})}else{const{undo:W,redo:F,objects:ne}=U.getBatchAddOp([D]);y.push({id:h.SetDrawingApplyMutation.id,params:{op:F,unitId:o,subUnitId:a,objects:ne,type:h.DrawingApplyType.INSERT}}),M.push({id:h.SetDrawingApplyMutation.id,params:{op:W,unitId:o,subUnitId:a,objects:ne,type:h.DrawingApplyType.REMOVE}})}}),{redos:y,undos:M}}};ve=jt([Oe(0,j.ISheetClipboardService),Oe(1,N.IRenderManagerService),Oe(2,h.ISheetDrawingService)],ve);var Lt=Object.defineProperty,Wt=Object.getOwnPropertyDescriptor,Bt=(i,n,r,e)=>{for(var t=e>1?void 0:e?Wt(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&Lt(n,r,t),t},ce=(i,n)=>(r,e)=>n(r,e,i);let we=class extends p.Disposable{constructor(i,n,r,e,t){super(),this._drawingManagerService=i,this._renderManagerService=n,this._permissionService=r,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(B.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,r])=>{if(!n){this._drawingManagerService.setDrawingVisible(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const c=n.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(S=>{S.classType===N.RENDER_CLASS_TYPE.IMAGE&&l.some(f=>S.oKey.includes(f.drawingId))&&u.removeObject(S)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(B.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,r])=>{if(!n){this._drawingManagerService.setDrawingEditable(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const c=n.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(S=>{S.classType===N.RENDER_CLASS_TYPE.IMAGE&&l.some(f=>S.oKey.includes(f.drawingId))&&u.detachTransformerFrom(S)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(B.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,r])=>{n&&n.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=n.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 _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).pipe(B.map(u=>u.every(m=>m.value)));l==null||l.pipe(B.filter(u=>u!==a),B.distinctUntilChanged()).subscribe({next:u=>{a=u,this._drawingManagerService.setDrawingVisible(u);const m=d.getAllObjectsByOrder(),S=this._drawingManagerService.getDrawingData(t,o),f=Object.values(S);u?this._drawingManagerService.addNotification(f):(m.forEach(v=>{v.classType===N.RENDER_CLASS_TYPE.IMAGE&&f.some(y=>v.oKey.includes(y.drawingId))&&d.removeObject(v)}),g.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(t,o).id))==null||s.pipe(B.filter(u=>u.value!==a),B.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(B.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,r])=>{n&&n.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=n.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 _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).pipe(B.map(u=>u.every(m=>m.value)));l==null||l.pipe(B.filter(u=>u!==a),B.distinctUntilChanged()).subscribe({next:u=>{a=u,this._drawingManagerService.setDrawingEditable(u);const m=d.getAllObjectsByOrder(),S=this._drawingManagerService.getDrawingData(t,o),f=Object.values(S);u?(m.forEach(v=>{v.classType===N.RENDER_CLASS_TYPE.IMAGE&&f.some(y=>v.oKey.includes(y.drawingId))&&d.attachTransformerTo(v)}),this._drawingManagerService.addNotification(f)):(m.forEach(v=>{v.classType===N.RENDER_CLASS_TYPE.IMAGE&&f.some(y=>v.oKey.includes(y.drawingId))&&d.detachTransformerFrom(v)}),g.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(t,o).id))==null||s.pipe(B.filter(u=>u.value!==a),B.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const u=n.getUnitId(),m=e.getSheetId(),S=this._drawingManagerService.getDrawingData(u,m),f=Object.values(S),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&&f.some(b=>C.oKey.includes(b.drawingId))&&y.detachTransformerFrom(C)})}})})}))}};we=Bt([ce(0,T.IDrawingManagerService),ce(1,N.IRenderManagerService),ce(2,p.IPermissionService),ce(3,p.IUniverInstanceService),ce(4,p.Inject(p.UserManagerService))],we);var Gt=Object.defineProperty,kt=Object.getOwnPropertyDescriptor,Vt=(i,n,r,e)=>{for(var t=e>1?void 0:e?kt(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&Gt(n,r,t),t},_e=(i,n)=>(r,e)=>n(r,e,i);let Ie=class extends p.Disposable{constructor(i,n,r,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=n,this._drawingManagerService=r,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,n,r)=>{const{unitId:e,scene:t,subUnitId:o}=n,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)}),r()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,n,r)=>{const{unitId:e,subUnitId:t}=n,o=this._renderManagerService.getRenderById(e);if(!o)return r(i);const a=o.with(j.SheetSkeletonManagerService).getWorksheetSkeleton(t);if(!a)return r(i);const c=this._drawingManagerService.getDrawingDataForUnit(e),d=c==null?void 0:c[n.subUnitId];if(!d)return r(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!==T.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 S=a.skeleton.getCellPositionByOffset(m.transform.left,m.transform.top,g,l,{x:0,y:0}),f=a.skeleton.getCellPositionByOffset(m.transform.left+m.transform.width,m.transform.top+m.transform.height,g,l,{x:0,y:0});S.column<s.startColumn&&(s.startColumn=S.column),S.row<s.startRow&&(s.startRow=S.row),s.endRow<f.row&&(s.endRow=f.row),s.endColumn<f.column&&(s.endColumn=f.column)}}),r(s)):r(i)}}))}};Ie=Vt([_e(0,p.Inject(j.SheetPrintInterceptorService)),_e(1,p.Inject(Q.DrawingRenderService)),_e(2,T.IDrawingManagerService),_e(3,N.IRenderManagerService)],Ie);var $t=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,Yt=(i,n,r,e)=>{for(var t=e>1?void 0:e?Ft(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&$t(n,r,t),t},q=(i,n)=>(r,e)=>n(r,e,i);const Ht=[_.InsertRowCommand.id,_.InsertColCommand.id,_.RemoveRowCommand.id,_.RemoveColCommand.id,_.DeleteRangeMoveLeftCommand.id,_.DeleteRangeMoveUpCommand.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id,_.DeltaRowHeightCommand.id,_.SetRowHeightCommand.id,_.DeltaColumnWidthCommand.id,_.SetColWidthCommand.id,_.SetRowHiddenCommand.id,_.SetSpecificRowsVisibleCommand.id,_.SetSpecificColsVisibleCommand.id,_.SetColHiddenCommand.id,_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id],xt=[_.SetRowVisibleMutation.id,_.SetRowHiddenMutation.id,_.SetColVisibleMutation.id,_.SetColHiddenMutation.id,_.SetWorksheetRowHeightMutation.id,_.SetWorksheetColWidthMutation.id];let Pe=class extends p.Disposable{constructor(i,n,r,e,t,o,a,c,d){super(),this._context=i,this._renderManagerService=n,this._commandService=r,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(!Ht.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const n=i.id;if(n===_.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id].includes(n))return this._moveRangeInterceptor(i.params);if(n===_.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(n===_.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(n===_.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(n===_.DeleteRangeMoveLeftCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,0)}else if(n===_.DeleteRangeMoveUpCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,1)}else if(n===_.InsertRangeMoveDownCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,2)}else if(n===_.InsertRangeMoveRightCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,3)}else if(n===_.SetRowHiddenCommand.id||n===_.SetSpecificRowsVisibleCommand.id){const r=i.params,{unitId:e,subUnitId:t,ranges:o}=r;return this._getDrawingUndoForRowVisible(e,t,o)}else if(n===_.SetSpecificColsVisibleCommand.id||n===_.SetColHiddenCommand.id){const r=i.params,{unitId:e,subUnitId:t,ranges:o}=r;return this._getDrawingUndoForColVisible(e,t,o)}else if(n===_.DeltaRowHeightCommand.id||n===_.SetRowHeightCommand.id||n===_.DeltaColumnWidthCommand.id||n===_.SetColWidthCommand.id){const r=i.params,{unitId:e,subUnitId:t,ranges:o}=r,a=n===_.DeltaRowHeightCommand.id||n===_.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,n){const r=_.getSheetCommandTarget(this._univerInstanceService);if(r==null)return{redos:[],undos:[]};const e=r.unitId,t=r.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,n,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,n,r){const e=[],t=[],{sheetTransform:o,anchorType:a=h.SheetDrawingAnchorType.Position,transform:c,unitId:d,subUnitId:g,drawingId:l}=r,{from:s,to:u}=o,{row:m,column:S}=s,{row:f,column:v}=u;if(o==null||c==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:y,endRow:M,startColumn:C,endColumn:b}=i;let I=null,R=null;if(n===0&&m>=y&&f<=M)if(S>=C&&v<=b)t.push({unitId:d,subUnitId:g,drawingId:l});else{const w=this._shrinkCol(o,c,C,b,a);I=w==null?void 0:w.newSheetTransform,R=w==null?void 0:w.newTransform}else if(n===1&&S>=C&&v<=b)if(m>=y&&f<=M)t.push({unitId:d,subUnitId:g,drawingId:l});else{const w=this._shrinkRow(o,c,y,M,a);I=w==null?void 0:w.newSheetTransform,R=w==null?void 0:w.newTransform}else if(n===2){const w=this._expandRow(o,c,y,M,a);I=w==null?void 0:w.newSheetTransform,R=w==null?void 0:w.newTransform}else if(n===3){const w=this._expandCol(o,c,C,b,a);I=w==null?void 0:w.newSheetTransform,R=w==null?void 0:w.newTransform}if(I!=null&&R!=null){const w=Y(I,this._selectionRenderService,this._skeletonManagerService);e.push({...r,sheetTransform:I,transform:w})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(i,n,r){const e=k({...i},this._selectionRenderService);e!=null&&n.push({...r,sheetTransform:e})}_getDrawingUndoForColVisible(i,n,r){const e=this._drawingManagerService.getDrawingData(i,n),t=[],o=[];if(Object.keys(e).forEach(l=>{const s=e[l],{sheetTransform:u,transform:m,anchorType:S=h.SheetDrawingAnchorType.Position}=s;if(S===h.SheetDrawingAnchorType.None)this._remainDrawingSize(m,t,s);else{const{from:f,to:v}=u,{row:y,column:M}=f,{row:C,column:b}=v;for(let I=0;I<r.length;I++){const R=r[I],{startRow:w,endRow:U,startColumn:E,endColumn:L}=R;if(b<E)continue;if(S===h.SheetDrawingAnchorType.Position){let D=null,W=null;if(M>=E&&M<=L){const F=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:L,startRow:f.row,endRow:v.row});if(F==null)return;W={...m,left:F.startX}}if(W!=null&&(D=k(W,this._selectionRenderService),D!=null&&W!=null)){t.push({...s,sheetTransform:D,transform:W});break}this._remainDrawingSize(m,t,s);continue}if(M>=E&&b<=L)continue;let A=null,P=null;if(M>=E&&M<=L){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:L,startRow:f.row,endRow:v.row});if(D==null)return;P={...m,left:(D==null?void 0:D.startX)||0,width:((m==null?void 0:m.width)||0)-D.endX+D.startX}}else if(b>=E&&b<=L){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:b,startRow:f.row,endRow:v.row});if(D==null)return;P={...m,left:D.startX-((m==null?void 0:m.width)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:L,startRow:f.row,endRow:v.row});if(D==null)return;if(P={...m,width:((m==null?void 0:m.width)||0)-D.endX+D.startX},A=k(P,this._selectionRenderService),A!=null&&P!=null){o.push({...s,sheetTransform:A,transform:P});break}}if(P!=null&&(A=k(P,this._selectionRenderService)),P!=null&&A!=null){t.push({...s,sheetTransform:A,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,n,t),d=[],g=[];if(o.length>0){const{redos:l,undos:s}=this._createUndoAndRedoMutation(i,n,o);d.push(...l),g.push(...s)}return{redos:a,undos:c,preRedos:d,preUndos:g}}_createUndoAndRedoMutation(i,n,r){const e=this._sheetDrawingService.getBatchUpdateOp(r),{undo:t,redo:o,objects:a}=e,c=[{id:h.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:n,op:o,objects:a,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],d=[{id:h.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:n,op:t,objects:a,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:c,undos:d}}_getDrawingUndoForRowVisible(i,n,r){const e=this._drawingManagerService.getDrawingData(i,n),t=[],o=[];if(Object.keys(e).forEach(l=>{const s=e[l],{sheetTransform:u,transform:m,anchorType:S=h.SheetDrawingAnchorType.Position}=s;if(S===h.SheetDrawingAnchorType.None)this._remainDrawingSize(m,t,s);else{const{from:f,to:v}=u,{row:y,column:M}=f,{row:C,column:b}=v;for(let I=0;I<r.length;I++){const R=r[I],{startRow:w,endRow:U,startColumn:E,endColumn:L}=R;if(C<w)continue;if(S===h.SheetDrawingAnchorType.Position){let D=null,W=null;if(y>=w&&y<=U){const F=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:y,endRow:U});if(F==null)return;W={...m,top:F.startY}}if(W!=null&&(D=k(W,this._selectionRenderService),D!=null&&W!=null)){t.push({...s,sheetTransform:D,transform:W});break}this._remainDrawingSize(m,t,s);continue}if(y>=w&&C<=U)continue;let A=null,P=null;if(y>=w&&y<=U){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:y,endRow:U});if(D==null)return;P={...m,top:(D==null?void 0:D.startY)||0,height:((m==null?void 0:m.height)||0)-D.endY+D.startY}}else if(C>=w&&C<=U){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:w,endRow:C});if(D==null)return;P={...m,top:D.startY-((m==null?void 0:m.height)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:w,endRow:U});if(D==null)return;if(P={...m,height:((m==null?void 0:m.height)||0)-D.endY+D.startY},A=k(P,this._selectionRenderService),A!=null&&P!=null){o.push({...s,sheetTransform:A,transform:P});break}}if(P!=null&&(A=k(P,this._selectionRenderService)),P!=null&&A!=null){t.push({...s,sheetTransform:A,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,n,t),d=[],g=[];if(o.length>0){const{redos:l,undos:s}=this._createUndoAndRedoMutation(i,n,o);d.push(...l),g.push(...s)}return{redos:a,undos:c,preRedos:d,preUndos:g}}_getDrawingUndoForRowAndColSize(i,n,r,e){const t=this._drawingManagerService.getDrawingData(i,n),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:S}=s,{row:f,column:v}=u;for(let y=0;y<r.length;y++){const M=r[y],{startRow:C,endRow:b,startColumn:I,endColumn:R}=M;if(f<C||v<I)continue;if(l===h.SheetDrawingAnchorType.Position&&(m<=C&&f>=b||S<=I&&v>=R)){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,n,o)}_getUnitIdAndSubUnitId(i,n){let r,e;if(n==="insert")r=i.unitId,e=i.subUnitId;else{const t=_.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;r=t.unitId,e=t.subUnitId}return{unitId:r,subUnitId:e}}_moveRangeInterceptor(i){var C,b;const{toRange:n,fromRange:r}=i,e=_.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,a=(b=(C=this._renderManagerService.getRenderById(t))==null?void 0:C.with(j.SheetSkeletonManagerService))==null?void 0:b.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const c=j.attachRangeWithCoord(a,r);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(I=>{const R=u[I];if(R.anchorType!==h.SheetDrawingAnchorType.Both)return;const{transform:w}=R;if(!w)return;const{left:U=0,top:E=0,width:L=0,height:A=0}=w,{drawingStartX:P,drawingEndX:D,drawingStartY:W,drawingEndY:F}={drawingStartX:U,drawingEndX:U+L,drawingStartY:E,drawingEndY:E+A};d<=P&&D<=g&&l<=W&&F<=s&&m.push(R)});const S=[],f=[],v=n.startRow-r.startRow,y=n.startColumn-r.startColumn,M=m.map(I=>{const R=I.sheetTransform,w={to:{...R.to,row:R.to.row+v,column:R.to.column+y},from:{...R.from,row:R.from.row+v,column:R.from.column+y}},U=Y(w,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:I.drawingId,transform:U,sheetTransform:w}});if(M.length){const I=this._sheetDrawingService.getBatchUpdateOp(M),{undo:R,redo:w,objects:U}=I;S.push({id:h.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:w,objects:U,type:h.DrawingApplyType.UPDATE}}),f.push({id:h.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:R,objects:U,type:h.DrawingApplyType.UPDATE}})}return{redos:S,undos:f}}_moveRowInterceptor(i,n){const r=this._getUnitIdAndSubUnitId(i,n);if(r==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=r,{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 S=l[m],{sheetTransform:f,transform:v,anchorType:y=h.SheetDrawingAnchorType.Position}=S;if(f==null||v==null)return;let M,C;if(n==="insert"){const I=this._expandRow(f,v,a,c,y);M=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:R}=f,{row:w}=I,{row:U}=R;if(y===h.SheetDrawingAnchorType.Both&&w>=a&&U<=c)u.push({unitId:e,subUnitId:t,drawingId:m});else{const E=this._shrinkRow(f,v,a,c,y);M=E==null?void 0:E.newSheetTransform,C=E==null?void 0:E.newTransform}}if(!M||!C)return;const b={unitId:e,subUnitId:t,drawingId:m,transform:C,sheetTransform:M};s.push(b)}),s.length===0&&u.length===0)return{redos:[],undos:[]};if(s.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(s),{undo:S,redo:f,objects:v}=m;d.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.UPDATE}}),g.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.UPDATE}})}if(u.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(u),S=m.undo,f=m.redo,v=m.objects;d.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.REMOVE}}),g.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,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,n){const r=this._getUnitIdAndSubUnitId(i,n);if(r==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=r,{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 S=l[m],{sheetTransform:f,transform:v,anchorType:y=h.SheetDrawingAnchorType.Position}=S;if(f==null||v==null)return;let M,C;if(n==="insert"){const I=this._expandCol(f,v,a,c,y);M=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:R}=f,{column:w}=I,{column:U}=R;if(y===h.SheetDrawingAnchorType.Both&&w>=a&&U<=c)u.push({unitId:e,subUnitId:t,drawingId:m});else{const E=this._shrinkCol(f,v,a,c,y);M=E==null?void 0:E.newSheetTransform,C=E==null?void 0:E.newTransform}}if(!M||!C)return;const b={unitId:e,subUnitId:t,drawingId:m,transform:C,sheetTransform:M};s.push(b)}),s.length===0&&u.length===0)return{redos:[],undos:[]};if(s.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(s),{undo:S,redo:f,objects:v}=m;d.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.UPDATE}}),g.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.UPDATE}})}if(u.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(u),S=m.undo,f=m.redo,v=m.objects;d.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.REMOVE}}),g.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,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,n,r,e,t=h.SheetDrawingAnchorType.Position){const o=e-r+1,{from:a,to:c}=i,{column:d}=a,{column:g}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...n},this._selectionRenderService),newTransform:n};let l=null,s=null;if(d>=r){const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:r,endColumn:e,startRow:a.row,endRow:c.row});if(u==null)return;s={...n,left:(n.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({...n},this._selectionRenderService),newTransform:n};return l!=null&&s!=null?{newSheetTransform:l,newTransform:s}:null}_shrinkCol(i,n,r,e,t=h.SheetDrawingAnchorType.Position){const o=e-r+1,{from:a,to:c}=i,{column:d}=a,{column:g}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...n},this._selectionRenderService),newTransform:n};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>=r&&g<=e)return null;if(d<r&&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({...n},this._selectionRenderService),newTransform:n};else if(d>=r&&d<=e){if(d===r)s={...n,left:(n.left||0)-i.from.columnOffset};else{const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:r,endColumn:d-1,startRow:a.row,endRow:c.row});if(u==null)return;s={...n,left:(n.left||0)-u.endX+u.startX-i.from.columnOffset}}l=k(s,this._selectionRenderService)}else if(g>=r&&g<=e&&t===h.SheetDrawingAnchorType.Both){const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:r-1,endColumn:r-1,startRow:a.row,endRow:c.row});if(u==null)return;l={from:{...a},to:{...c,column:r-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,n,r,e,t=h.SheetDrawingAnchorType.Position){const o=e-r+1,{from:a,to:c}=i,{row:d}=a,{row:g}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...n},this._selectionRenderService),newTransform:n};let l=null,s=null;if(d>=r){const u=this._skeletonManagerService.attachRangeWithCoord({startRow:r,endRow:e,startColumn:a.column,endColumn:c.column});if(u==null)return;s={...n,top:(n.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({...n},this._selectionRenderService),newTransform:n};return l!=null&&s!=null?{newSheetTransform:l,newTransform:s}:null}_shrinkRow(i,n,r,e,t=h.SheetDrawingAnchorType.Position){const o=e-r+1,{from:a,to:c}=i,{row:d}=a,{row:g}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...n},this._selectionRenderService),newTransform:n};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>=r&&g<=e)return null;if(d<r&&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({...n},this._selectionRenderService),newTransform:n};else if(d>=r&&d<=e){if(d===r)s={...n,top:(n.top||0)-i.from.rowOffset};else{const u=this._skeletonManagerService.attachRangeWithCoord({startRow:r,endRow:d-1,startColumn:a.column,endColumn:c.column});if(u==null)return;s={...n,top:(n.top||0)-u.endY+u.startY-i.from.rowOffset}}l=k(s,this._selectionRenderService)}else if(g>=r&&g<=e&&t===h.SheetDrawingAnchorType.Both){const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:r-1,endRow:r-1});if(u==null)return;l={from:{...a},to:{...c,row:r-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===_.SetWorksheetActiveOperation.id&&setTimeout(()=>{const n=i.params,{unitId:r,subUnitId:e}=n,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===r&&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=>{xt.includes(i.id)&&requestIdleCallback(()=>{const n=i.params,{unitId:r,subUnitId:e,ranges:t}=n;this._refreshDrawingTransform(r,e,t)})}))}_refreshDrawingTransform(i,n,r){const e=this._drawingManagerService.getDrawingData(i,n),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:S,column:f}=s;for(let v=0;v<r.length;v++){const y=r[v],{startRow:M,endRow:C,startColumn:b,endColumn:I}=y;if(p.Rectangle.intersects({startRow:M,endRow:C,startColumn:b,endColumn:I},{startRow:u,endRow:S,startColumn:m,endColumn:f})||u>C||m>I){const R=g===h.SheetDrawingAnchorType.Position,w=Y(c,this._selectionRenderService,this._skeletonManagerService);t.push({...a,transform:{...w,width:R?d==null?void 0:d.width:w==null?void 0:w.width,height:R?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]))}};Pe=Yt([q(1,N.IRenderManagerService),q(2,p.ICommandService),q(3,j.ISheetSelectionRenderService),q(4,p.Inject(j.SheetSkeletonManagerService)),q(5,p.Inject(_.SheetInterceptorService)),q(6,h.ISheetDrawingService),q(7,T.IDrawingManagerService),q(8,p.IUniverInstanceService)],Pe);var Xt=Object.defineProperty,Kt=Object.getOwnPropertyDescriptor,zt=(i,n,r,e)=>{for(var t=e>1?void 0:e?Kt(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&Xt(n,r,t),t},te=(i,n)=>(r,e)=>n(r,e,i);function Jt(i,n,r,e){const{scaleX:t,scaleY:o}=n.getAncestorScale(),a=n.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:S,xSplit:f,ySplit:v}=u,y=r.getNoMergeCellPositionByIndexWithNoHeader(S-v,m-f),M=r.getNoMergeCellPositionByIndexWithNoHeader(S,m),{rowHeaderWidth:C,columnHeaderHeight:b}=r,I=M.startX-y.startX,R=M.startY-y.startY,{top:w,left:U,viewportScrollX:E,viewportScrollY:L}=a;let A,P;d<U?(c.left=!0,A=(I+C+(d-U))*t,P=Math.max(Math.min((I+C+(g-U))*t,(I+C)*t),(g-E)*t)):(c.left=!1,A=Math.max((d-E)*t,(I+C)*t),P=Math.max((g-E)*t,(I+C)*t));let D,W;return l<w?(c.top=!0,D=(R+b+(l-w))*o,W=Math.max(Math.min((R+b+(g-w))*o,(R+b)*o),(s-L)*o)):(c.top=!1,D=Math.max((l-L)*o,(R+b)*o),W=Math.max((s-L)*o,(R+b)*o)),{left:A,right:P,top:D,bottom:W,absolute:c}}const Ae=(i,n,r,e)=>{const{scene:t}=n,{left:o,top:a,width:c,height:d,angle:g}=i,l={left:o,right:o+c,top:a,bottom:a+d},s=Jt(l,t,r,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(r,e,t,o,a,c,d){super();X(this,"_domLayerMap",new Map);X(this,"_domLayerInfoMap",new Map);X(this,"_transformChange$",new B.Subject);X(this,"transformChange$",this._transformChange$.asObservable());X(this,"_add$",new B.Subject);X(this,"add$",this._add$.asObservable());X(this,"_remove$",new B.Subject);X(this,"remove$",this._remove$.asObservable());X(this,"_hooks",[]);this._renderManagerService=r,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(B.filter(r=>r===p.LifecycleStages.Rendered),B.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(r,e){let t=this._domLayerMap.get(r);t||(t=new Map,this._domLayerMap.set(r,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(r){return this._domLayerInfoMap.get(r)}_getSceneAndTransformerByDrawingSearch(r){if(r==null)return;const e=this._renderManagerService.getRenderById(r),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(r){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(r)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(r=>{r.forEach(e=>{var xe,Xe,Ke;const{unitId:t,subUnitId:o,drawingId:a}=e,c=_.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e);if(!d||!c)return;const g=(xe=this._renderManagerService.getRenderById(t))==null?void 0:xe.with(j.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!g)return;const{transform:l,drawingType:s,data:u}=d;if(s!==T.DrawingTypeEnum.DRAWING_DOM&&s!==T.DrawingTypeEnum.DRAWING_CHART)return;const m=this._getSceneAndTransformerByDrawingSearch(t);if(m==null)return;const{scene:S,canvas:f}=m;if(l==null)return!0;const{left:v,top:y,width:M,height:C,angle:b,flipX:I,flipY:R,skewX:w,skewY:U}=l,E=T.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),L=S.getObject(E);if(L!=null){L.transformByState({left:v,top:y,width:M,height:C,angle:b,flipX:I,flipY:R,skewX:w,skewY:U});return}const A={left:v,top:y,width:M,height:C,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},P=s===T.DrawingTypeEnum.DRAWING_CHART;P&&(A.fill="white",A.rotateEnabled=!1,u&&u.border&&(A.stroke=u.border),A.paintFirst="stroke",A.strokeWidth=1,A.borderEnabled=!1);const D=new N.Rect(E,A);P&&D.setObjectType(N.ObjectType.CHART),S.addObject(D,N.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo(D);const W=this._ensureMap(t,o),F=new p.DisposableCollection,ne=Ae(D,m.renderObject,g.skeleton,c.worksheet),Ne=new B.BehaviorSubject(ne),tn={dispose:F,rect:D,position$:Ne,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:Ne,id:a,componentKey:d.componentKey,onPointerDown:x=>{f.dispatchEvent(new PointerEvent(x.type,x))},onPointerMove:x=>{f.dispatchEvent(new PointerEvent(x.type,x))},onPointerUp:x=>{f.dispatchEvent(new PointerEvent(x.type,x))},onWheel:x=>{f.dispatchEvent(new WheelEvent(x.type,x))},props:(Ke=(Xe=W.get(a))==null?void 0:Xe.props)!=null?Ke:this._getFloatDomProps(a),data:u,unitId:t});const He=D.onTransformChange$.subscribeEvent(()=>{const x=Ae(D,m.renderObject,g.skeleton,c.worksheet);Ne.next(x)});F.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),He&&F.add(He),this._domLayerInfoMap.set(a,tn),W.set(a,{...W.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(r=>{r.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a}=e,c=T.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 r=(e,t)=>{var l;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,t),c=Array.from(a.keys()),d=_.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=Ae(u.rect,o.renderObject,g.skeleton,d.worksheet);u.position$.next(m)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET).pipe(B.filter(e=>!!e),B.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getActiveSheet().getSheetId()}:null}),B.filter(e=>!!e),B.switchMap(e=>p.fromEventSubject(e.render.scene.getViewport(j.VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(B.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{r(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=>{r(c,g)})}else if(e.id===_.SetFrozenMutation.id){const{unitId:a,subUnitId:c}=e.params;r(a,c)}}))}_getPosition(r,e){var m;const{startX:t,endX:o,startY:a,endY:c}=r,d=(m=this._renderManagerService.getRenderById(e))==null?void 0:m.with(j.ISheetSelectionRenderService);if(d==null)return;const g=d.getSelectionCellByPosition(t,a);if(g==null)return;const l={column:g.actualColumn,columnOffset:t-g.startX,row:g.actualRow,rowOffset:a-g.startY},s=d.getSelectionCellByPosition(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(r=>{r.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==T.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==T.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(r=>{r.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(r,e,t,o){const a=this._domLayerInfoMap.get(t),c=this._getSceneAndTransformerByDrawingSearch(r);if(a&&c){const{scene:d}=c,g=T.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:e,drawingId:t}),l=d.getObject(g);l&&l instanceof N.Rect&&l.setProps(o)}}addFloatDomToPosition(r,e,t=!0){const o=_.getSheetCommandTarget(this._univerInstanceService,{unitId:r.unitId,subUnitId:r.subUnitId});if(!o)throw new Error("cannot find current target!");const{unitId:a,subUnitId:c}=o,{initPosition:d,componentKey:g,data:l,allowTransform:s=!0}=r,u=e!=null?e:p.generateRandomId(),m=this._getPosition(d,a);if(m==null)return;this._ensureMap(a,c).set(u,r);const f={unitId:a,subUnitId:c,drawingId:u,drawingType:r.type||T.DrawingTypeEnum.DRAWING_DOM,componentKey:g,sheetTransform:m,transform:{left:d.startX,top:d.startY,width:d.endX-d.startX,height:d.endY-d.startY},data:l,allowTransform:s};return t&&this._commandService.executeCommand(oe.id,{unitId:a,drawings:[f]}),this._add$.next({unitId:a,subUnitId:c,id:u}),{id:u,dispose:()=>{this._removeDom(u,!0)},sheetDrawingParam:f}}_removeDom(r,e=!1){const t=this._domLayerInfoMap.get(r);if(!t)return;const{unitId:o,subUnitId:a}=t;this._domLayerInfoMap.delete(r),t.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(t.rect),e){this._ensureMap(o,a).delete(r);const g=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:r});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(r){return this._hooks.push(r),{dispose:()=>{const e=this._hooks.findIndex(t=>t===r);this._hooks.splice(e,1)}}}},O.SheetCanvasFloatDomManagerService=zt([te(0,p.Inject(N.IRenderManagerService)),te(1,p.IUniverInstanceService),te(2,p.Inject(p.ICommandService)),te(3,T.IDrawingManagerService),te(4,p.Inject(V.CanvasFloatDomService)),te(5,h.ISheetDrawingService),te(6,p.Inject(p.LifecycleService))],O.SheetCanvasFloatDomManagerService);var Fe=Object.defineProperty,Zt=Object.getOwnPropertyDescriptor,qt=(i,n,r)=>n in i?Fe(i,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[n]=r,Qt=(i,n,r,e)=>{for(var t=e>1?void 0:e?Zt(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&Fe(n,r,t),t},Ue=(i,n)=>(r,e)=>n(r,e,i),Ye=(i,n,r)=>qt(i,typeof n!="symbol"?n+"":n,r);const en="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends p.Plugin{constructor(n=Je,r,e,t){super(),this._config=n,this._injector=r,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=this._config;o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(ze,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],[Pe],[Me]].forEach(n=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(p.UniverInstanceType.UNIVER_SHEET,n))})}},Ye(O.UniverSheetsDrawingUIPlugin,"type",p.UniverInstanceType.UNIVER_SHEET),Ye(O.UniverSheetsDrawingUIPlugin,"pluginName",en),O.UniverSheetsDrawingUIPlugin=Qt([p.DependentOn(T.UniverDrawingPlugin,Q.UniverDrawingUIPlugin,h.UniverSheetsDrawingPlugin),Ue(1,p.Inject(p.Injector)),Ue(2,N.IRenderManagerService),Ue(3,p.IConfigService)],O.UniverSheetsDrawingUIPlugin),O.ClearSheetDrawingTransformerOperation=G,O.DeleteDrawingsCommand=De,O.EditSheetDrawingOperation=ye,O.GroupSheetDrawingCommand=Re,O.IMAGE_MENU_ID=Ee,O.InsertFloatImageCommand=pe,O.InsertSheetDrawingCommand=oe,O.MoveDrawingsCommand=re,O.RemoveSheetDrawingCommand=ie,O.SetDrawingArrangeCommand=Te,O.SetSheetDrawingCommand=ae,O.SidebarSheetDrawingOperation=Ce,O.UngroupSheetDrawingCommand=be,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
9
+ */var Ze=H,qe=Symbol.for("react.element"),Qe=Symbol.for("react.fragment"),et=Object.prototype.hasOwnProperty,tt=Ze.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,nt={key:!0,ref:!0,__self:!0,__source:!0};function We(i,n,r){var e,t={},o=null,a=null;r!==void 0&&(o=""+r),n.key!==void 0&&(o=""+n.key),n.ref!==void 0&&(a=n.ref);for(e in n)et.call(n,e)&&!nt.hasOwnProperty(e)&&(t[e]=n[e]);if(i&&i.defaultProps)for(e in n=i.defaultProps,n)t[e]===void 0&&(t[e]=n[e]);return{$$typeof:qe,type:i,key:o,ref:a,props:t,_owner:tt.current}}de.Fragment=Qe,de.jsx=We,de.jsxs=We,Le.exports=de;var $=Le.exports;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"},rt=()=>{const i=p.useDependency(b.IImageIoService),n=p.useDependency(p.LocaleService),[r,e]=H.useState(0);return H.useEffect(()=>{const t=i.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[i]),$.jsx("div",{style:{display:r>0?"block":"none"},className:le.uploadLoading,children:$.jsxs("div",{className:le.uploadLoadingBody,children:[$.jsx("div",{className:le.uploadLoadingBodyAnimation}),$.jsx("div",{className:le.uploadLoadingBodyText,children:`${n.t("uploadLoading.loading")}: ${r}`})]})})};var it=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,at=(i,n,r,e)=>{for(var t=e>1?void 0:e?ot(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&it(n,r,t),t},ee=(i,n)=>(r,e)=>n(r,e,i);let ue=class extends p.RxDisposable{constructor(n,r,e,t,o,a,c){super();X(this,"_initImagePopupMenu",new Set);this._injector=n,this._drawingManagerService=r,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(B.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(p.UniverInstanceType.UNIVER_SHEET).pipe(B.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(p.UniverInstanceType.UNIVER_SHEET).forEach(n=>this._create(n)),this._uiPartsService.registerComponent(V.BuiltInUIPart.CONTENT,()=>p.connectInjector(rt,this._injector))}_dispose(n){const r=n.getUnitId();this._renderManagerService.removeRender(r)}_create(n){if(!n)return;const r=n.getUnitId();this._renderManagerService.has(r)&&!this._initImagePopupMenu.has(r)&&(this._popupMenuListener(r),this._initImagePopupMenu.add(r))}_hasCropObject(n){const r=n.getAllObjectsByOrder();for(const e of r)if(e instanceof Q.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const r=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!r)return;const e=r.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(p.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(r))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;t==null||t.dispose(),t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:Q.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems: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(n,r,e,t){return[{label:"image-popup.edit",index:0,commandId:ye.id,commandParams:{unitId:n,subUnitId:r,drawingId:e},disable:t===b.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ie.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:r,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:Q.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:r,drawingId:e},disable:t===b.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:Q.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:r,drawingId:e}],disable:t===b.DrawingTypeEnum.DRAWING_DOM}]}};ue=at([ee(0,p.Inject(p.Injector)),ee(1,b.IDrawingManagerService),ee(2,p.Inject(j.SheetCanvasPopManagerService)),ee(3,N.IRenderManagerService),ee(4,p.IUniverInstanceService),ee(5,p.IContextService),ee(6,p.Inject(V.IUIPartsService))],ue);function Y(i,n,r){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:M}=t,y=r.getCurrentSkeleton(),C=j.attachRangeWithCoord(y,{startColumn:l,endColumn:l,startRow:u,endRow:u});if(C==null)return;const T=j.attachRangeWithCoord(y,{startColumn:f,endColumn:f,startRow:v,endRow:v});if(T==null)return;const{startX:_,startY:D}=C,{startX:w,startY:U}=T;let E=N.precisionTo(_+s,1),L=N.precisionTo(D+m,1),A=N.precisionTo(w+S-E,1),P=N.precisionTo(U+M-L,1);C.startX===T.endX&&(A=0),C.startY===T.endY&&(P=0);const R=y.rowHeaderWidth+y.columnTotalWidth,W=y.columnHeaderHeight+y.rowTotalHeight;return E+A>R&&(E=R-A),L+P>W&&(L=W-P),{flipY:o,flipX:a,angle:c,skewX:d,skewY:g,left:E,top:L,width:A,height:P}}function k(i,n){const{left:r=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=n.getSelectionCellByPosition(r,e);if(s==null)return;const u={column:s.actualColumn,columnOffset:N.precisionTo(r-s.startX,1),row:s.actualRow,rowOffset:N.precisionTo(e-s.startY,1)},m=n.getSelectionCellByPosition(r+t,e+o);if(m==null)return;const f={column:m.actualColumn,columnOffset:N.precisionTo(r+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 st=Object.defineProperty,ct=Object.getOwnPropertyDescriptor,dt=(i,n,r,e)=>{for(var t=e>1?void 0:e?ct(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&st(n,r,t),t},me=(i,n)=>(r,e)=>n(r,e,i);let Me=class extends p.Disposable{constructor(i,n,r,e,t){super(),this._context=i,this._sheetDrawingService=n,this._drawingManagerService=r,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 n in i){const r=i[n];for(const e in r.data){const t=r.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)}};Me=dt([me(1,h.ISheetDrawingService),me(2,b.IDrawingManagerService),me(3,p.Inject(j.ISheetSelectionRenderService)),me(4,p.Inject(j.SheetSkeletonManagerService))],Me);var K=function(){return K=Object.assign||function(i){for(var n,r=1,e=arguments.length;r<e;r++){n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(i[t]=n[t])}return i},K.apply(this,arguments)},lt=function(i,n){var r={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&n.indexOf(e)<0&&(r[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(i);t<e.length;t++)n.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(i,e[t])&&(r[e[t]]=i[e[t]]);return r},Be=H.forwardRef(function(i,n){var r=i.icon,e=i.id,t=i.className,o=i.extend,a=lt(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),d=H.useRef("_".concat(gt()));return Ge(r,"".concat(e),{defIds:r.defIds,idSuffix:d.current},K({ref:n,className:c},a),o)});function Ge(i,n,r,e,t){return H.createElement(i.tag,K(K({key:n},ut(i,r,t)),e),(mt(i,r).children||[]).map(function(o,a){return Ge(o,"".concat(n,"-").concat(i.tag,"-").concat(a),r,void 0,t)}))}function ut(i,n,r){var e=K({},i.attrs);r!=null&&r.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=r.colorChannel1);var t=n.defIds;return!t||t.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+n.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(n.idSuffix,")")))})),e}function mt(i,n){var r,e=n.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((r=i.children)===null||r===void 0)&&r.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+n.idSuffix})}):t})}):i}function gt(){return Math.random().toString(36).substring(2,8)}Be.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"}}]},ke=H.forwardRef(function(i,n){return H.createElement(Be,Object.assign({},i,{id:"add-image-single",ref:n,icon:pt}))});ke.displayName="AddImageSingle";const De={id:"sheet.command.delete-drawing",type:p.CommandType.COMMAND,handler:i=>{const n=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 n.executeCommand(ie.id,{unitId:t,drawings:o})}};function ht(i){const n=[];return i.forEach(r=>{const{parent:e,children:t}=r,{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};n.push({parent:l,children:g})}),n}function ft(i){const n=[];return i.forEach(r=>{const{parent:e,children:t}=r,{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}};n.push({parent:l,children:g})}),n}const Re={id:"sheet.command.group-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),t=i.get(h.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:m,children:f})=>{o.push(m.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getGroupDrawingOp(n),{unitId:c,subUnitId:d,undo:g,redo:l,objects:s}=a;return r.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:ft(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}},oe={id:"sheet.command.insert-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{var y,C,T;const r=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),t=i.get(h.ISheetDrawingService),o=i.get(I.SheetInterceptorService);if(!n)return!1;const a=n.drawings,c=a.map(_=>_.unitId),d=t.getBatchAddOp(a),{unitId:g,subUnitId:l,undo:s,redo:u,objects:m}=d,f=o.onCommandExecute({id:oe.id,params:n}),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([...(y=f.preRedos)!=null?y:[],S,...f.redos],r)?(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}},Te={id:"sheet.command.set-drawing-arrange",type:p.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(p.ICommandService),e=i.get(p.IUndoRedoService);if(!n)return!1;const t=i.get(h.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:c,arrangeType:d}=n,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 r.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}},ae={id:"sheet.command.set-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),t=i.get(h.ISheetDrawingService);if(!n)return!1;const{drawings:o}=n,a=t.getBatchUpdateOp(o),{unitId:c,subUnitId:d,undo:g,redo:l,objects:s}=a;return r.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}},be={id:"sheet.command.ungroup-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(p.ICommandService),e=i.get(p.IUndoRedoService),t=i.get(h.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:m,children:f})=>{o.push(m.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getUngroupDrawingOp(n),{unitId:c,subUnitId:d,undo:g,redo:l,objects:s}=a;return r.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:ht(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 St=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,wt=(i,n,r,e)=>{for(var t=e>1?void 0:e?vt(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&St(n,r,t),t},z=(i,n)=>(r,e)=>n(r,e,i);let ge=class extends p.Disposable{constructor(n,r,e,t,o,a,c,d,g,l,s,u){super();X(this,"_workbookSelections");this._context=n,this._skeletonManagerService=r,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 n=await this._fileOpenerService.openFile({multiple:!0,accept:b.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),r=n.length;return r>b.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(b.DRAWING_IMAGE_COUNT_LIMIT))}),!1):r===0?!1:(n.forEach(async e=>await this._insertFloatImage(e)),!0)}async _insertFloatImage(n){let r;try{r=await this._imageIoService.saveImage(n)}catch(y){const C=y.message;C===b.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.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:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===b.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(r==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:c,source:d,base64Cache:g}=r,{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 y=b.DRAWING_IMAGE_WIDTH_LIMIT/l,C=b.DRAWING_IMAGE_HEIGHT_LIMIT/s;S=Math.max(y,C)}const v=this._getImagePosition(l*S,s*S,m,f);if(v==null)return;const M={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(oe.id,{unitId:t,drawings:[M]})}_getUnitInfo(){const n=this._context.unit,r=n.getActiveSheet(),e=n.getUnitId(),t=r.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(n,r,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+n>e&&(l=e-n,l<0&&(l=0,n=e),u=!0),s+r>t&&(s=t-r,s<0&&(s=0,r=t),u=!0),u){const v=this._selectionRenderService.getSelectionCellByPosition(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.getSelectionCellByPosition(l+n,s+r);if(f==null)return;const S={column:f.actualColumn,columnOffset:l+n-f.startX,row:f.actualRow,rowOffset:s+r-f.startY};return{from:m,to:S}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(n=>{const{unitId:r,subUnitId:e,drawingIds:t,arrangeType:o}=n;this._commandService.executeCommand(Te.id,{unitId:r,subUnitId:e,drawingIds:t,arrangeType:o})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(n=>{const r=[];n.length!==0&&(n.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}};r.push(s)}),r.length>0&&this._commandService.executeCommand(ae.id,{unitId:n[0].unitId,drawings:r}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(n=>{this._commandService.executeCommand(Re.id,n);const{unitId:r,subUnitId:e,drawingId:t}=n[0].parent;this._drawingManagerService.focusDrawing([{unitId:r,subUnitId:e,drawingId:t}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(n=>{this._commandService.executeCommand(be.id,n)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(n=>{n==null||n.length===0?(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(n))}))}};ge=wt([z(1,p.Inject(j.SheetSkeletonManagerService)),z(2,p.ICommandService),z(3,j.ISheetSelectionRenderService),z(4,b.IImageIoService),z(5,V.ILocalFileService),z(6,h.ISheetDrawingService),z(7,b.IDrawingManagerService),z(8,p.IContextService),z(9,V.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 r,e;return(e=(r=i.get(N.IRenderManagerService).getCurrentTypeOfRenderer(p.UniverInstanceType.UNIVER_SHEET))==null?void 0:r.with(ge).insertFloatImage())!=null?e:!1}},re={id:"sheet.command.move-drawing",type:p.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(p.ICommandService),e=i.get(h.ISheetDrawingService),t=i.get(j.ISheetSelectionRenderService),{direction:o}=n,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 r.syncExecuteCommand(ae.id,{unitId:c,drawings:d})?(r.syncExecuteCommand(G.id,[c]),!0):!1}},Ve="addition-and-subtraction-single",Ee="sheet.menu.image";function _t(i){return{id:Ee,type:V.MenuItemType.SUBITEMS,icon:Ve,tooltip:"sheetImage.title",hidden$:V.getMenuHiddenObservable(i,p.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(i,{workbookTypes:[I.WorkbookEditablePermission],worksheetTypes:[I.WorksheetEditPermission],rangeTypes:[I.RangeProtectionPermissionEditPoint]})}}function It(i){return{id:pe.id,title:"sheetImage.upload.float",type:V.MenuItemType.BUTTON,hidden$:V.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 $e(i){var n,r,e="";if(typeof i=="string"||typeof i=="number")e+=i;else if(typeof i=="object")if(Array.isArray(i)){var t=i.length;for(n=0;n<t;n++)i[n]&&(r=$e(i[n]))&&(e&&(e+=" "),e+=r)}else for(r in i)i[r]&&(e&&(e+=" "),e+=r);return e}function he(){for(var i,n,r=0,e="",t=arguments.length;r<t;r++)(i=arguments[r])&&(n=$e(i))&&(e&&(e+=" "),e+=n);return e}const Ct=i=>{var C;const n=p.useDependency(p.ICommandService),r=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]=H.useState(!0),m=(C=a.anchorType)!=null?C:h.SheetDrawingAnchorType.Position,[f,S]=H.useState(m);function v(T,_){const D=[];return T.forEach(w=>{const{oKey:U}=w,E=_.getDrawingOKey(U);if(E==null)return D.push(null),!0;const{unitId:L,subUnitId:A,drawingId:P,drawingType:R,anchorType:W,sheetTransform:F}=E;D.push({unitId:L,subUnitId:A,drawingId:P,anchorType:W,sheetTransform:F,drawingType:R})}),D}H.useEffect(()=>{const T=l.clearControl$.subscribe(D=>{D===!0&&u(!1)}),_=l.changeStart$.subscribe(D=>{var E;const{objects:w}=D,U=v(w,e);if(U.length===0)u(!1);else if(U.length>=1){u(!0);const L=((E=U[0])==null?void 0:E.anchorType)||h.SheetDrawingAnchorType.Position;S(L)}});return()=>{_.unsubscribe(),T.unsubscribe()}},[]);function M(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}));n.executeCommand(ae.id,{unitId:_[0].unitId,drawings:D})}const y=T=>T?"block":"none";return $.jsxs("div",{className:he(Z.imageCommonPanelGrid,Z.imageCommonPanelBorder),style:{display:y(s)},children:[$.jsx("div",{className:Z.imageCommonPanelRow,children:$.jsx("div",{className:he(Z.imageCommonPanelColumn,Z.imageCommonPanelTitle),children:$.jsx("div",{children:r.t("drawing-anchor.title")})})}),$.jsx("div",{className:he(Z.imageCommonPanelRow),children:$.jsx("div",{className:he(Z.imageCommonPanelColumn),children:$.jsxs(J.RadioGroup,{value:f,onChange:M,direction:"vertical",children:[$.jsx(J.Radio,{value:h.SheetDrawingAnchorType.Both,children:r.t("drawing-anchor.both")}),$.jsx(J.Radio,{value:h.SheetDrawingAnchorType.Position,children:r.t("drawing-anchor.position")}),$.jsx(J.Radio,{value:h.SheetDrawingAnchorType.None,children:r.t("drawing-anchor.none")})]})})})]})},yt=()=>{const i=p.useDependency(b.IDrawingManagerService),n=i.getFocusDrawings(),[r,e]=H.useState(n);return H.useEffect(()=>{const t=i.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(r!=null&&r.length)&&$.jsxs("div",{className:Z.imageCommonPanel,children:[$.jsx(Q.DrawingCommonPanel,{drawings:r}),$.jsx(Ct,{drawings:r})]})},Mt={[V.RibbonStartGroup.FORMULAS_INSERT]:{[Ee]:{order:3,menuItemFactory:_t,[pe.id]:{order:0,menuItemFactory:It}}}};function se(i){return!i.getContextValue(p.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(p.EDITOR_ACTIVATED)&&i.getContextValue(p.FOCUSING_COMMON_DRAWINGS)}const Dt={id:re.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:V.KeyCode.ARROW_DOWN,priority:100,preconditions:se,staticParameters:{direction:p.Direction.DOWN}},Rt={id:re.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:V.KeyCode.ARROW_UP,priority:100,preconditions:se,staticParameters:{direction:p.Direction.UP}},Tt={id:re.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:V.KeyCode.ARROW_LEFT,priority:100,preconditions:se,staticParameters:{direction:p.Direction.LEFT}},bt={id:re.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:V.KeyCode.ARROW_RIGHT,priority:100,preconditions:se,staticParameters:{direction:p.Direction.RIGHT}},Et={id:De.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:se,binding:V.KeyCode.DELETE,mac:V.KeyCode.BACKSPACE};var Ot=Object.defineProperty,Pt=Object.getOwnPropertyDescriptor,At=(i,n,r,e)=>{for(var t=e>1?void 0:e?Pt(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&Ot(n,r,t),t},fe=(i,n)=>(r,e)=>n(r,e,i);let Se=class extends p.Disposable{constructor(i,n,r,e){super(),this._componentManager=i,this._menuManagerService=n,this._commandService=r,this._shortcutService=e,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Ve,ke)),this.disposeWithMe(i.register(je,yt))}_initMenus(){this._menuManagerService.mergeMenu(Mt)}_initCommands(){[pe,oe,ie,ae,Ce,G,ye,Re,be,re,De,Te].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[Dt,Rt,Tt,bt,Et].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Se=At([fe(0,p.Inject(V.ComponentManager)),fe(1,V.IMenuManagerService),fe(2,p.ICommandService),fe(3,V.IShortcutService)],Se);var Ut=Object.defineProperty,Nt=Object.getOwnPropertyDescriptor,jt=(i,n,r,e)=>{for(var t=e>1?void 0:e?Nt(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&Ut(n,r,t),t},Oe=(i,n)=>(r,e)=>n(r,e,i);let ve=class extends p.Disposable{constructor(n,r,e){super();X(this,"_copyInfo");this._sheetClipboardService=n,this._renderManagerService=r,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(n,r,e)=>this._collect(n,r,e),onPasteCells:(n,r,e,t)=>{const{copyType:o=j.COPY_TYPE.COPY,pasteType:a}=t,{range:c}=n||{},{range:d,unitId:g,subUnitId:l}=r;return this._generateMutations(d,{copyType:o,pasteType:a,copyRange:c,unitId:g,subUnitId:l})},onPastePlainText:(n,r)=>({undos:[],redos:[]})})}_collect(n,r,e){var u;const t=(u=this._renderManagerService.getRenderById(n))==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(n,r),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:M=0,width:y=0,height:C=0}=S,{drawingStartX:T,drawingEndX:_,drawingStartY:D,drawingEndY:w}={drawingStartX:v,drawingEndX:v+y,drawingStartY:M,drawingEndY:M+C};a<=T&&_<=c&&d<=D&&w<=g&&s.push(f)}),s.length&&(this._copyInfo={drawings:s,unitId:n,subUnitId:r})}_generateMutations(n,r){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(r.pasteType))return{redos:[],undos:[]};const{copyRange:e}=r;if(!e)return{redos:[],undos:[]};const{drawings:t,unitId:o,subUnitId:a}=this._copyInfo,{ranges:[c,d],mapFunc:g}=j.virtualizeDiscreteRanges([e,n]),{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 M=[],y=[],C=v.startX-S.startX,T=v.startY-S.startY,_=u-l,D=m-s,w=r.copyType===j.COPY_TYPE.CUT,{_sheetDrawingService:U}=this;return t.forEach(L=>{const{transform:A,sheetTransform:P}=L;if(!A)return;const R={...L,unitId:o,subUnitId:a,drawingId:w?L.drawingId:p.Tools.generateRandomId(),transform:{...A,left:A.left+C,top:A.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:W,redo:F,objects:ne}=U.getBatchUpdateOp([R]);M.push({id:h.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:h.DrawingApplyType.UPDATE,op:F,objects:ne}}),y.push({id:h.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:h.DrawingApplyType.UPDATE,op:W,objects:ne}})}else{const{undo:W,redo:F,objects:ne}=U.getBatchAddOp([R]);M.push({id:h.SetDrawingApplyMutation.id,params:{op:F,unitId:o,subUnitId:a,objects:ne,type:h.DrawingApplyType.INSERT}}),y.push({id:h.SetDrawingApplyMutation.id,params:{op:W,unitId:o,subUnitId:a,objects:ne,type:h.DrawingApplyType.REMOVE}})}}),{redos:M,undos:y}}};ve=jt([Oe(0,j.ISheetClipboardService),Oe(1,N.IRenderManagerService),Oe(2,h.ISheetDrawingService)],ve);var Lt=Object.defineProperty,Wt=Object.getOwnPropertyDescriptor,Bt=(i,n,r,e)=>{for(var t=e>1?void 0:e?Wt(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&Lt(n,r,t),t},ce=(i,n)=>(r,e)=>n(r,e,i);let we=class extends p.Disposable{constructor(i,n,r,e,t){super(),this._drawingManagerService=i,this._renderManagerService=n,this._permissionService=r,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(B.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,r])=>{if(!n){this._drawingManagerService.setDrawingVisible(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new 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=n.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(B.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,r])=>{if(!n){this._drawingManagerService.setDrawingEditable(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new 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=n.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(B.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,r])=>{n&&n.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=n.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(B.map(u=>u.every(m=>m.value)));l==null||l.pipe(B.filter(u=>u!==a),B.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(M=>v.oKey.includes(M.drawingId))&&d.removeObject(v)}),g.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new I.WorksheetViewPermission(t,o).id))==null||s.pipe(B.filter(u=>u.value!==a),B.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(B.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,r])=>{n&&n.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=n.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(B.map(u=>u.every(m=>m.value)));l==null||l.pipe(B.filter(u=>u!==a),B.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(M=>v.oKey.includes(M.drawingId))&&d.attachTransformerTo(v)}),this._drawingManagerService.addNotification(S)):(m.forEach(v=>{v.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(M=>v.oKey.includes(M.drawingId))&&d.detachTransformerFrom(v)}),g.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new I.WorksheetEditPermission(t,o).id))==null||s.pipe(B.filter(u=>u.value!==a),B.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const u=n.getUnitId(),m=e.getSheetId(),f=this._drawingManagerService.getDrawingData(u,m),S=Object.values(f),v=this._renderManagerService.getRenderById(u),M=v==null?void 0:v.scene;if(M==null)return;this._drawingManagerService.setDrawingEditable(!0),M.getAllObjectsByOrder().forEach(C=>{C.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(T=>C.oKey.includes(T.drawingId))&&M.detachTransformerFrom(C)})}})})}))}};we=Bt([ce(0,b.IDrawingManagerService),ce(1,N.IRenderManagerService),ce(2,p.IPermissionService),ce(3,p.IUniverInstanceService),ce(4,p.Inject(p.UserManagerService))],we);var Gt=Object.defineProperty,kt=Object.getOwnPropertyDescriptor,Vt=(i,n,r,e)=>{for(var t=e>1?void 0:e?kt(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&Gt(n,r,t),t},_e=(i,n)=>(r,e)=>n(r,e,i);let Ie=class extends p.Disposable{constructor(i,n,r,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=n,this._drawingManagerService=r,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,n,r)=>{const{unitId:e,scene:t,subUnitId:o}=n,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)}),r()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,n,r)=>{const{unitId:e,subUnitId:t}=n,o=this._renderManagerService.getRenderById(e);if(!o)return r(i);const a=o.with(j.SheetSkeletonManagerService).getWorksheetSkeleton(t);if(!a)return r(i);const c=this._drawingManagerService.getDrawingDataForUnit(e),d=c==null?void 0:c[n.subUnitId];if(!d)return r(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.getCellPositionByOffset(m.transform.left,m.transform.top,g,l,{x:0,y:0}),S=a.skeleton.getCellPositionByOffset(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)}}),r(s)):r(i)}}))}};Ie=Vt([_e(0,p.Inject(j.SheetPrintInterceptorService)),_e(1,p.Inject(Q.DrawingRenderService)),_e(2,b.IDrawingManagerService),_e(3,N.IRenderManagerService)],Ie);var $t=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,Yt=(i,n,r,e)=>{for(var t=e>1?void 0:e?Ft(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&$t(n,r,t),t},q=(i,n)=>(r,e)=>n(r,e,i);const Ht=[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],xt=[I.SetRowVisibleMutation.id,I.SetRowHiddenMutation.id,I.SetColVisibleMutation.id,I.SetColHiddenMutation.id,I.SetWorksheetRowHeightMutation.id,I.SetWorksheetColWidthMutation.id];let Pe=class extends p.Disposable{constructor(i,n,r,e,t,o,a,c,d){super(),this._context=i,this._renderManagerService=n,this._commandService=r,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(!Ht.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const n=i.id;if(n===I.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([I.MoveColsCommand.id,I.MoveRowsCommand.id,I.MoveRangeCommand.id].includes(n))return this._moveRangeInterceptor(i.params);if(n===I.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(n===I.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(n===I.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(n===I.DeleteRangeMoveLeftCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,0)}else if(n===I.DeleteRangeMoveUpCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,1)}else if(n===I.InsertRangeMoveDownCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,2)}else if(n===I.InsertRangeMoveRightCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,3)}else if(n===I.SetRowHiddenCommand.id||n===I.SetSpecificRowsVisibleCommand.id){const r=i.params,{unitId:e,subUnitId:t,ranges:o}=r;return this._getDrawingUndoForRowVisible(e,t,o)}else if(n===I.SetSpecificColsVisibleCommand.id||n===I.SetColHiddenCommand.id){const r=i.params,{unitId:e,subUnitId:t,ranges:o}=r;return this._getDrawingUndoForColVisible(e,t,o)}else if(n===I.DeltaRowHeightCommand.id||n===I.SetRowHeightCommand.id||n===I.DeltaColumnWidthCommand.id||n===I.SetColWidthCommand.id){const r=i.params,{unitId:e,subUnitId:t,ranges:o}=r,a=n===I.DeltaRowHeightCommand.id||n===I.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,n){const r=I.getSheetCommandTarget(this._univerInstanceService);if(r==null)return{redos:[],undos:[]};const e=r.unitId,t=r.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,n,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,n,r){const e=[],t=[],{sheetTransform:o,anchorType:a=h.SheetDrawingAnchorType.Position,transform:c,unitId:d,subUnitId:g,drawingId:l}=r,{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:M,endRow:y,startColumn:C,endColumn:T}=i;let _=null,D=null;if(n===0&&m>=M&&S<=y)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(n===1&&f>=C&&v<=T)if(m>=M&&S<=y)t.push({unitId:d,subUnitId:g,drawingId:l});else{const w=this._shrinkRow(o,c,M,y,a);_=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(n===2){const w=this._expandRow(o,c,M,y,a);_=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(n===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({...r,sheetTransform:_,transform:w})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(i,n,r){const e=k({...i},this._selectionRenderService);e!=null&&n.push({...r,sheetTransform:e})}_getDrawingUndoForColVisible(i,n,r){const e=this._drawingManagerService.getDrawingData(i,n),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:M,column:y}=S,{row:C,column:T}=v;for(let _=0;_<r.length;_++){const D=r[_],{startRow:w,endRow:U,startColumn:E,endColumn:L}=D;if(T<E)continue;if(f===h.SheetDrawingAnchorType.Position){let R=null,W=null;if(y>=E&&y<=L){const F=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:L,startRow:S.row,endRow:v.row});if(F==null)return;W={...m,left:F.startX}}if(W!=null&&(R=k(W,this._selectionRenderService),R!=null&&W!=null)){t.push({...s,sheetTransform:R,transform:W});break}this._remainDrawingSize(m,t,s);continue}if(y>=E&&T<=L)continue;let A=null,P=null;if(y>=E&&y<=L){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,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},A=k(P,this._selectionRenderService),A!=null&&P!=null){o.push({...s,sheetTransform:A,transform:P});break}}if(P!=null&&(A=k(P,this._selectionRenderService)),P!=null&&A!=null){t.push({...s,sheetTransform:A,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,n,t),d=[],g=[];if(o.length>0){const{redos:l,undos:s}=this._createUndoAndRedoMutation(i,n,o);d.push(...l),g.push(...s)}return{redos:a,undos:c,preRedos:d,preUndos:g}}_createUndoAndRedoMutation(i,n,r){const e=this._sheetDrawingService.getBatchUpdateOp(r),{undo:t,redo:o,objects:a}=e,c=[{id:h.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:n,op:o,objects:a,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],d=[{id:h.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:n,op:t,objects:a,type:h.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:c,undos:d}}_getDrawingUndoForRowVisible(i,n,r){const e=this._drawingManagerService.getDrawingData(i,n),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:M,column:y}=S,{row:C,column:T}=v;for(let _=0;_<r.length;_++){const D=r[_],{startRow:w,endRow:U,startColumn:E,endColumn:L}=D;if(C<w)continue;if(f===h.SheetDrawingAnchorType.Position){let R=null,W=null;if(M>=w&&M<=U){const F=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:M,endRow:U});if(F==null)return;W={...m,top:F.startY}}if(W!=null&&(R=k(W,this._selectionRenderService),R!=null&&W!=null)){t.push({...s,sheetTransform:R,transform:W});break}this._remainDrawingSize(m,t,s);continue}if(M>=w&&C<=U)continue;let A=null,P=null;if(M>=w&&M<=U){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:M,endRow:U});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<=U){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:U});if(R==null)return;if(P={...m,height:((m==null?void 0:m.height)||0)-R.endY+R.startY},A=k(P,this._selectionRenderService),A!=null&&P!=null){o.push({...s,sheetTransform:A,transform:P});break}}if(P!=null&&(A=k(P,this._selectionRenderService)),P!=null&&A!=null){t.push({...s,sheetTransform:A,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,n,t),d=[],g=[];if(o.length>0){const{redos:l,undos:s}=this._createUndoAndRedoMutation(i,n,o);d.push(...l),g.push(...s)}return{redos:a,undos:c,preRedos:d,preUndos:g}}_getDrawingUndoForRowAndColSize(i,n,r,e){const t=this._drawingManagerService.getDrawingData(i,n),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 M=0;M<r.length;M++){const y=r[M],{startRow:C,endRow:T,startColumn:_,endColumn:D}=y;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,n,o)}_getUnitIdAndSubUnitId(i,n){let r,e;if(n==="insert")r=i.unitId,e=i.subUnitId;else{const t=I.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;r=t.unitId,e=t.subUnitId}return{unitId:r,subUnitId:e}}_moveRangeInterceptor(i){var C,T;const{toRange:n,fromRange:r}=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,r);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:U=0,top:E=0,width:L=0,height:A=0}=w,{drawingStartX:P,drawingEndX:R,drawingStartY:W,drawingEndY:F}={drawingStartX:U,drawingEndX:U+L,drawingStartY:E,drawingEndY:E+A};d<=P&&R<=g&&l<=W&&F<=s&&m.push(D)});const f=[],S=[],v=n.startRow-r.startRow,M=n.startColumn-r.startColumn,y=m.map(_=>{const D=_.sheetTransform,w={to:{...D.to,row:D.to.row+v,column:D.to.column+M},from:{...D.from,row:D.from.row+v,column:D.from.column+M}},U=Y(w,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:_.drawingId,transform:U,sheetTransform:w}});if(y.length){const _=this._sheetDrawingService.getBatchUpdateOp(y),{undo:D,redo:w,objects:U}=_;f.push({id:h.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:w,objects:U,type:h.DrawingApplyType.UPDATE}}),S.push({id:h.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:D,objects:U,type:h.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(i,n){const r=this._getUnitIdAndSubUnitId(i,n);if(r==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=r,{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:M=h.SheetDrawingAnchorType.Position}=f;if(S==null||v==null)return;let y,C;if(n==="insert"){const _=this._expandRow(S,v,a,c,M);y=_==null?void 0:_.newSheetTransform,C=_==null?void 0:_.newTransform}else{const{from:_,to:D}=S,{row:w}=_,{row:U}=D;if(M===h.SheetDrawingAnchorType.Both&&w>=a&&U<=c)u.push({unitId:e,subUnitId:t,drawingId:m});else{const E=this._shrinkRow(S,v,a,c,M);y=E==null?void 0:E.newSheetTransform,C=E==null?void 0:E.newTransform}}if(!y||!C)return;const T={unitId:e,subUnitId:t,drawingId:m,transform:C,sheetTransform:y};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,n){const r=this._getUnitIdAndSubUnitId(i,n);if(r==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=r,{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:M=h.SheetDrawingAnchorType.Position}=f;if(S==null||v==null)return;let y,C;if(n==="insert"){const _=this._expandCol(S,v,a,c,M);y=_==null?void 0:_.newSheetTransform,C=_==null?void 0:_.newTransform}else{const{from:_,to:D}=S,{column:w}=_,{column:U}=D;if(M===h.SheetDrawingAnchorType.Both&&w>=a&&U<=c)u.push({unitId:e,subUnitId:t,drawingId:m});else{const E=this._shrinkCol(S,v,a,c,M);y=E==null?void 0:E.newSheetTransform,C=E==null?void 0:E.newTransform}}if(!y||!C)return;const T={unitId:e,subUnitId:t,drawingId:m,transform:C,sheetTransform:y};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,n,r,e,t=h.SheetDrawingAnchorType.Position){const o=e-r+1,{from:a,to:c}=i,{column:d}=a,{column:g}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...n},this._selectionRenderService),newTransform:n};let l=null,s=null;if(d>=r){const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:r,endColumn:e,startRow:a.row,endRow:c.row});if(u==null)return;s={...n,left:(n.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({...n},this._selectionRenderService),newTransform:n};return l!=null&&s!=null?{newSheetTransform:l,newTransform:s}:null}_shrinkCol(i,n,r,e,t=h.SheetDrawingAnchorType.Position){const o=e-r+1,{from:a,to:c}=i,{column:d}=a,{column:g}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...n},this._selectionRenderService),newTransform:n};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>=r&&g<=e)return null;if(d<r&&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({...n},this._selectionRenderService),newTransform:n};else if(d>=r&&d<=e){if(d===r)s={...n,left:(n.left||0)-i.from.columnOffset};else{const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:r,endColumn:d-1,startRow:a.row,endRow:c.row});if(u==null)return;s={...n,left:(n.left||0)-u.endX+u.startX-i.from.columnOffset}}l=k(s,this._selectionRenderService)}else if(g>=r&&g<=e&&t===h.SheetDrawingAnchorType.Both){const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:r-1,endColumn:r-1,startRow:a.row,endRow:c.row});if(u==null)return;l={from:{...a},to:{...c,column:r-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,n,r,e,t=h.SheetDrawingAnchorType.Position){const o=e-r+1,{from:a,to:c}=i,{row:d}=a,{row:g}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...n},this._selectionRenderService),newTransform:n};let l=null,s=null;if(d>=r){const u=this._skeletonManagerService.attachRangeWithCoord({startRow:r,endRow:e,startColumn:a.column,endColumn:c.column});if(u==null)return;s={...n,top:(n.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({...n},this._selectionRenderService),newTransform:n};return l!=null&&s!=null?{newSheetTransform:l,newTransform:s}:null}_shrinkRow(i,n,r,e,t=h.SheetDrawingAnchorType.Position){const o=e-r+1,{from:a,to:c}=i,{row:d}=a,{row:g}=c;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:k({...n},this._selectionRenderService),newTransform:n};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>=r&&g<=e)return null;if(d<r&&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({...n},this._selectionRenderService),newTransform:n};else if(d>=r&&d<=e){if(d===r)s={...n,top:(n.top||0)-i.from.rowOffset};else{const u=this._skeletonManagerService.attachRangeWithCoord({startRow:r,endRow:d-1,startColumn:a.column,endColumn:c.column});if(u==null)return;s={...n,top:(n.top||0)-u.endY+u.startY-i.from.rowOffset}}l=k(s,this._selectionRenderService)}else if(g>=r&&g<=e&&t===h.SheetDrawingAnchorType.Both){const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:r-1,endRow:r-1});if(u==null)return;l={from:{...a},to:{...c,row:r-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 n=i.params,{unitId:r,subUnitId:e}=n,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===r&&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=>{xt.includes(i.id)&&requestIdleCallback(()=>{const n=i.params,{unitId:r,subUnitId:e,ranges:t}=n;this._refreshDrawingTransform(r,e,t)})}))}_refreshDrawingTransform(i,n,r){const e=this._drawingManagerService.getDrawingData(i,n),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<r.length;v++){const M=r[v],{startRow:y,endRow:C,startColumn:T,endColumn:_}=M;if(p.Rectangle.intersects({startRow:y,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]))}};Pe=Yt([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)],Pe);var Xt=Object.defineProperty,Kt=Object.getOwnPropertyDescriptor,zt=(i,n,r,e)=>{for(var t=e>1?void 0:e?Kt(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&Xt(n,r,t),t},te=(i,n)=>(r,e)=>n(r,e,i);function Jt(i,n,r,e){const{scaleX:t,scaleY:o}=n.getAncestorScale(),a=n.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,M=r.getNoMergeCellPositionByIndexWithNoHeader(f-v,m-S),y=r.getNoMergeCellPositionByIndexWithNoHeader(f,m),{rowHeaderWidth:C,columnHeaderHeight:T}=r,_=y.startX-M.startX,D=y.startY-M.startY,{top:w,left:U,viewportScrollX:E,viewportScrollY:L}=a;let A,P;d<U?(c.left=!0,A=(_+C+(d-U))*t,P=Math.max(Math.min((_+C+(g-U))*t,(_+C)*t),(g-E)*t)):(c.left=!1,A=Math.max((d-E)*t,(_+C)*t),P=Math.max((g-E)*t,(_+C)*t));let R,W;return l<w?(c.top=!0,R=(D+T+(l-w))*o,W=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),W=Math.max((s-L)*o,(D+T)*o)),{left:A,right:P,top:R,bottom:W,absolute:c}}const Ae=(i,n,r,e)=>{const{scene:t}=n,{left:o,top:a,width:c,height:d,angle:g}=i,l={left:o,right:o+c,top:a,bottom:a+d},s=Jt(l,t,r,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(r,e,t,o,a,c,d){super();X(this,"_domLayerMap",new Map);X(this,"_domLayerInfoMap",new Map);X(this,"_transformChange$",new B.Subject);X(this,"transformChange$",this._transformChange$.asObservable());X(this,"_add$",new B.Subject);X(this,"add$",this._add$.asObservable());X(this,"_remove$",new B.Subject);X(this,"remove$",this._remove$.asObservable());X(this,"_hooks",[]);this._renderManagerService=r,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(B.filter(r=>r===p.LifecycleStages.Rendered),B.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(r,e){let t=this._domLayerMap.get(r);t||(t=new Map,this._domLayerMap.set(r,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(r){return this._domLayerInfoMap.get(r)}_getSceneAndTransformerByDrawingSearch(r){if(r==null)return;const e=this._renderManagerService.getRenderById(r),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(r){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(r)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(r=>{r.forEach(e=>{var xe,Xe,Ke;const{unitId:t,subUnitId:o,drawingId:a}=e,c=I.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e);if(!d||!c)return;const g=(xe=this._renderManagerService.getRenderById(t))==null?void 0:xe.with(j.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!g)return;const{transform:l,drawingType:s,data:u}=d;if(s!==b.DrawingTypeEnum.DRAWING_DOM&&s!==b.DrawingTypeEnum.DRAWING_CHART)return;const m=this._getSceneAndTransformerByDrawingSearch(t);if(m==null)return;const{scene:f,canvas:S}=m;if(l==null)return!0;const{left:v,top:M,width:y,height:C,angle:T,flipX:_,flipY:D,skewX:w,skewY:U}=l,E=b.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),L=f.getObject(E);if(L!=null){L.transformByState({left:v,top:M,width:y,height:C,angle:T,flipX:_,flipY:D,skewX:w,skewY:U});return}const A={left:v,top:M,width:y,height:C,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},P=s===b.DrawingTypeEnum.DRAWING_CHART;P&&(A.fill="white",A.rotateEnabled=!1,u&&u.border&&(A.stroke=u.border),A.paintFirst="stroke",A.strokeWidth=1,A.borderEnabled=!1);const R=new N.Rect(E,A);P&&R.setObjectType(N.ObjectType.CHART),f.addObject(R,N.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&f.attachTransformerTo(R);const W=this._ensureMap(t,o),F=new p.DisposableCollection,ne=Ae(R,m.renderObject,g.skeleton,c.worksheet),Ne=new B.BehaviorSubject(ne),tn={dispose:F,rect:R,position$:Ne,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:Ne,id:a,componentKey:d.componentKey,onPointerDown:x=>{S.dispatchEvent(new PointerEvent(x.type,x))},onPointerMove:x=>{S.dispatchEvent(new PointerEvent(x.type,x))},onPointerUp:x=>{S.dispatchEvent(new PointerEvent(x.type,x))},onWheel:x=>{S.dispatchEvent(new WheelEvent(x.type,x))},props:(Ke=(Xe=W.get(a))==null?void 0:Xe.props)!=null?Ke:this._getFloatDomProps(a),data:u,unitId:t});const He=R.onTransformChange$.subscribeEvent(()=>{const x=Ae(R,m.renderObject,g.skeleton,c.worksheet);Ne.next(x)});F.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),He&&F.add(He),this._domLayerInfoMap.set(a,tn),W.set(a,{...W.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(r=>{r.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 r=(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=Ae(u.rect,o.renderObject,g.skeleton,d.worksheet);u.position$.next(m)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET).pipe(B.filter(e=>!!e),B.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getActiveSheet().getSheetId()}:null}),B.filter(e=>!!e),B.switchMap(e=>p.fromEventSubject(e.render.scene.getViewport(j.VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(B.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{r(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=>{r(c,g)})}else if(e.id===I.SetFrozenMutation.id){const{unitId:a,subUnitId:c}=e.params;r(a,c)}}))}_getPosition(r,e){var m;const{startX:t,endX:o,startY:a,endY:c}=r,d=(m=this._renderManagerService.getRenderById(e))==null?void 0:m.with(j.ISheetSelectionRenderService);if(d==null)return;const g=d.getSelectionCellByPosition(t,a);if(g==null)return;const l={column:g.actualColumn,columnOffset:t-g.startX,row:g.actualRow,rowOffset:a-g.startY},s=d.getSelectionCellByPosition(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(r=>{r.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(r=>{r.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(r,e,t,o){const a=this._domLayerInfoMap.get(t),c=this._getSceneAndTransformerByDrawingSearch(r);if(a&&c){const{scene:d}=c,g=b.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:e,drawingId:t}),l=d.getObject(g);l&&l instanceof N.Rect&&l.setProps(o)}}addFloatDomToPosition(r,e){const t=I.getSheetCommandTarget(this._univerInstanceService,{unitId:r.unitId,subUnitId:r.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}=r,s=e!=null?e:p.generateRandomId(),u=this._getPosition(c,o);if(u==null)return;this._ensureMap(o,a).set(s,r);const f={unitId:o,subUnitId:a,drawingId:s,drawingType:r.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(oe.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:a,id:s}),{id:s,dispose:()=>{this._removeDom(s,!0)}}}_removeDom(r,e=!1){const t=this._domLayerInfoMap.get(r);if(!t)return;const{unitId:o,subUnitId:a}=t;this._domLayerInfoMap.delete(r),t.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(t.rect),e){this._ensureMap(o,a).delete(r);const g=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:r});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(r){return this._hooks.push(r),{dispose:()=>{const e=this._hooks.findIndex(t=>t===r);this._hooks.splice(e,1)}}}},O.SheetCanvasFloatDomManagerService=zt([te(0,p.Inject(N.IRenderManagerService)),te(1,p.IUniverInstanceService),te(2,p.Inject(p.ICommandService)),te(3,b.IDrawingManagerService),te(4,p.Inject(V.CanvasFloatDomService)),te(5,h.ISheetDrawingService),te(6,p.Inject(p.LifecycleService))],O.SheetCanvasFloatDomManagerService);var Fe=Object.defineProperty,Zt=Object.getOwnPropertyDescriptor,qt=(i,n,r)=>n in i?Fe(i,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[n]=r,Qt=(i,n,r,e)=>{for(var t=e>1?void 0:e?Zt(n,r):n,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(n,r,t):a(t))||t);return e&&t&&Fe(n,r,t),t},Ue=(i,n)=>(r,e)=>n(r,e,i),Ye=(i,n,r)=>qt(i,typeof n!="symbol"?n+"":n,r);const en="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends p.Plugin{constructor(n=Je,r,e,t){super(),this._config=n,this._injector=r,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=this._config;o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(ze,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],[Pe],[Me]].forEach(n=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(p.UniverInstanceType.UNIVER_SHEET,n))})}},Ye(O.UniverSheetsDrawingUIPlugin,"type",p.UniverInstanceType.UNIVER_SHEET),Ye(O.UniverSheetsDrawingUIPlugin,"pluginName",en),O.UniverSheetsDrawingUIPlugin=Qt([p.DependentOn(b.UniverDrawingPlugin,Q.UniverDrawingUIPlugin,h.UniverSheetsDrawingPlugin),Ue(1,p.Inject(p.Injector)),Ue(2,N.IRenderManagerService),Ue(3,p.IConfigService)],O.UniverSheetsDrawingUIPlugin),O.ClearSheetDrawingTransformerOperation=G,O.DeleteDrawingsCommand=De,O.EditSheetDrawingOperation=ye,O.GroupSheetDrawingCommand=Re,O.IMAGE_MENU_ID=Ee,O.InsertFloatImageCommand=pe,O.InsertSheetDrawingCommand=oe,O.MoveDrawingsCommand=re,O.RemoveSheetDrawingCommand=ie,O.SetDrawingArrangeCommand=Te,O.SetSheetDrawingCommand=ae,O.SidebarSheetDrawingOperation=Ce,O.UngroupSheetDrawingCommand=be,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-drawing-ui",
3
- "version": "0.4.2-nightly.202410311606",
3
+ "version": "0.4.2-nightly.202411021605",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -55,15 +55,15 @@
55
55
  "dependencies": {
56
56
  "@univerjs/icons": "^0.2.2",
57
57
  "clsx": "^2.1.1",
58
- "@univerjs/core": "0.4.2-nightly.202410311606",
59
- "@univerjs/design": "0.4.2-nightly.202410311606",
60
- "@univerjs/drawing-ui": "0.4.2-nightly.202410311606",
61
- "@univerjs/drawing": "0.4.2-nightly.202410311606",
62
- "@univerjs/sheets": "0.4.2-nightly.202410311606",
63
- "@univerjs/engine-render": "0.4.2-nightly.202410311606",
64
- "@univerjs/sheets-drawing": "0.4.2-nightly.202410311606",
65
- "@univerjs/sheets-ui": "0.4.2-nightly.202410311606",
66
- "@univerjs/ui": "0.4.2-nightly.202410311606"
58
+ "@univerjs/core": "0.4.2-nightly.202411021605",
59
+ "@univerjs/drawing": "0.4.2-nightly.202411021605",
60
+ "@univerjs/design": "0.4.2-nightly.202411021605",
61
+ "@univerjs/drawing-ui": "0.4.2-nightly.202411021605",
62
+ "@univerjs/engine-render": "0.4.2-nightly.202411021605",
63
+ "@univerjs/sheets": "0.4.2-nightly.202411021605",
64
+ "@univerjs/sheets-drawing": "0.4.2-nightly.202411021605",
65
+ "@univerjs/ui": "0.4.2-nightly.202411021605",
66
+ "@univerjs/sheets-ui": "0.4.2-nightly.202411021605"
67
67
  },
68
68
  "devDependencies": {
69
69
  "less": "^4.2.0",