@univerjs/sheets-drawing-ui 0.8.2-nightly.202506261607 → 0.8.3-nightly.202506271607

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.
@@ -14,13 +14,11 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import './global.css';
17
- export { UniverSheetsDrawingUIPlugin } from './plugin';
18
- export { type ICanvasFloatDom, type IDOMAnchor, SheetCanvasFloatDomManagerService } from './services/canvas-float-dom-manager.service';
19
- export { SHEETS_IMAGE_MENU_ID } from './views/menu/image.menu';
20
- export { SheetDrawingUpdateController } from './controllers/sheet-drawing-update.controller';
21
17
  export { DeleteDrawingsCommand } from './commands/commands/delete-drawings.command';
22
18
  export { GroupSheetDrawingCommand } from './commands/commands/group-sheet-drawing.command';
19
+ export { type IInsertImageCommandParams, InsertFloatImageCommand } from './commands/commands/insert-image.command';
23
20
  export { InsertSheetDrawingCommand } from './commands/commands/insert-sheet-drawing.command';
21
+ export type { IDeleteDrawingCommandParams, IInsertDrawingCommandParams, ISetDrawingCommandParams } from './commands/commands/interfaces';
24
22
  export { MoveDrawingsCommand } from './commands/commands/move-drawings.command';
25
23
  export { RemoveSheetDrawingCommand } from './commands/commands/remove-sheet-drawing.command';
26
24
  export { SetDrawingArrangeCommand } from './commands/commands/set-drawing-arrange.command';
@@ -28,6 +26,9 @@ export { SetSheetDrawingCommand } from './commands/commands/set-sheet-drawing.co
28
26
  export { UngroupSheetDrawingCommand } from './commands/commands/ungroup-sheet-drawing.command';
29
27
  export { ClearSheetDrawingTransformerOperation } from './commands/operations/clear-drawing-transformer.operation';
30
28
  export { EditSheetDrawingOperation } from './commands/operations/edit-sheet-drawing.operation';
31
- export { type IInsertImageCommandParams, InsertFloatImageCommand } from './commands/commands/insert-image.command';
32
29
  export { SidebarSheetDrawingOperation } from './commands/operations/open-drawing-panel.operation';
33
- export type { IDeleteDrawingCommandParams, IInsertDrawingCommandParams, ISetDrawingCommandParams } from './commands/commands/interfaces';
30
+ export type { IUniverSheetsDrawingUIConfig } from './controllers/config.schema';
31
+ export { SheetDrawingUpdateController } from './controllers/sheet-drawing-update.controller';
32
+ export { UniverSheetsDrawingUIPlugin } from './plugin';
33
+ export { type ICanvasFloatDom, type IDOMAnchor, SheetCanvasFloatDomManagerService } from './services/canvas-float-dom-manager.service';
34
+ export { SHEETS_IMAGE_MENU_ID } from './views/menu/image.menu';
package/lib/umd/index.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(O,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("@univerjs/docs-drawing"),require("@univerjs/drawing"),require("@univerjs/drawing-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing"),require("@univerjs/design"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/docs-ui"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-drawing","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/design","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","@univerjs/docs-ui","react/jsx-runtime","react"],c):(O=typeof globalThis<"u"?globalThis:O||self,c(O.UniverSheetsDrawingUi={},O.UniverCore,O.UniverDocsDrawing,O.UniverDrawing,O.UniverDrawingUi,O.UniverEngineRender,O.UniverSheetsDrawing,O.UniverDesign,O.UniverSheetsUi,O.UniverUi,O.rxjs,O.UniverSheets,O.UniverDocsUi,O.React,O.React))})(this,function(O,c,ge,W,le,j,m,q,b,B,U,D,je,J,me){"use strict";var jn=Object.defineProperty;var Bn=(O,c,ge)=>c in O?jn(O,c,{enumerable:!0,configurable:!0,writable:!0,value:ge}):O[c]=ge;var re=(O,c,ge)=>Bn(O,typeof c!="symbol"?c+"":c,ge);const Nt="sheets-drawing-ui.config",It={},G={id:"sheet.operation.clear-drawing-transformer",type:c.CommandType.MUTATION,handler:(o,r)=>{const t=o.get(j.IRenderManagerService);return r.forEach(e=>{var n,i;(i=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||i.debounceRefreshControls()}),!0}},fe={id:"sheet.command.remove-sheet-image",type:c.CommandType.COMMAND,handler:(o,r)=>{var I,C,R;const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService),n=o.get(D.SheetInterceptorService),i=o.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,a=[];s.forEach(y=>{const{unitId:T}=y;a.push(T)});const l=i.getBatchRemoveOp(s),{unitId:g,subUnitId:u,undo:d,redo:p,objects:h}=l,S=n.onCommandExecute({id:fe.id,params:r}),f={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:p,objects:h,type:m.DrawingApplyType.REMOVE}},w={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:d,objects:h,type:m.DrawingApplyType.INSERT}};return c.sequenceExecute([...(I=S.preRedos)!=null?I:[],f,...S.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=S.preUndos)!=null?C:[],w,...S.undos,{id:G.id,params:a}],redoMutations:[...(R=S.preRedos)!=null?R:[],f,...S.redos,{id:G.id,params:a}]}),!0):!1}},yt="COMPONENT_SHEET_DRAWING_PANEL",st={id:"sidebar.operation.sheet-image",type:c.CommandType.COMMAND,handler:async(o,r)=>{const t=o.get(B.ISidebarService),e=o.get(c.LocaleService),n=o.get(c.IUniverInstanceService),i=o.get(c.ICommandService);if(!D.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:yt},onClose:()=>{i.syncExecuteCommand(W.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},at={id:"sheet.operation.edit-sheet-image",type:c.CommandType.OPERATION,handler:(o,r)=>{const t=o.get(c.ICommandService);return r==null?!1:(t.syncExecuteCommand(W.SetDrawingSelectedOperation.id,[r]),t.executeCommand(st.id,{value:"open"}),!0)}};var kt=Object.getOwnPropertyDescriptor,Wt=(o,r,t,e)=>{for(var n=e>1?void 0:e?kt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},ie=(o,r)=>(t,e)=>r(t,e,o);let Be=class extends c.RxDisposable{constructor(r,t,e,n,i,s,a,l,g,u){super();re(this,"_initImagePopupMenu",new Set);this._injector=r,this._localeService=t,this._drawingManagerService=e,this._canvasPopManagerService=n,this._renderManagerService=i,this._univerInstanceService=s,this._messageService=a,this._contextService=l,this._ioService=g,this._commandService=u,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(U.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(c.UniverInstanceType.UNIVER_SHEET).pipe(U.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(c.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._setupLoadingStatus()}_setupLoadingStatus(){const r="image-upload-loading";let t;this.disposeWithMe(this._ioService.change$.subscribe(e=>{e>0&&!t?t=this._messageService.show({id:r,type:q.MessageType.Loading,content:`${this._localeService.t("uploadLoading.loading")}: ${e}`,duration:0}):e===0&&(t==null||t.dispose(),t=void 0)}))}_dispose(r){super.dispose();const t=r.getUnitId();this._renderManagerService.removeRender(t)}_create(r){if(!r)return;const t=r.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(r){const t=r.getAllObjectsByOrder();for(const e of t)if(e instanceof le.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var i;const t=(i=this._renderManagerService.getRenderById(r))==null?void 0:i.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const s=e.getSelectedObjectMap();if(s.size>1){n==null||n.dispose();return}const a=s.values().next().value;if(!a)return;const l=a.oKey,g=this._drawingManagerService.getDrawingOKey(l);if(!g)return;const{unitId:u,subUnitId:d,drawingId:p,drawingType:h}=g,S=g.data;if(S&&S.disablePopup)return;n==null||n.dispose();const f=this._canvasPopManagerService.getFeatureMenu(u,d,p,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:le.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:f||this._getImageMenuItems(u,d,p,h)}}))})),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(W.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(s=>{s[c.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:at.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:fe.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:le.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:le.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===c.DrawingTypeEnum.DRAWING_DOM}]}};Be=Wt([ie(0,c.Inject(c.Injector)),ie(1,c.Inject(c.LocaleService)),ie(2,W.IDrawingManagerService),ie(3,c.Inject(b.SheetCanvasPopManagerService)),ie(4,j.IRenderManagerService),ie(5,c.IUniverInstanceService),ie(6,B.IMessageService),ie(7,c.IContextService),ie(8,c.IImageIoService),ie(9,c.ICommandService)],Be);var jt=Object.getOwnPropertyDescriptor,Bt=(o,r,t,e)=>{for(var n=e>1?void 0:e?jt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Ye=(o,r)=>(t,e)=>r(t,e,o);let ct=class extends c.Disposable{constructor(r,t,e,n,i){super();re(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=t,this._selectionsService=e,this._drawingRenderService=n,this._sheetSkeletonManagerService=i,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(U.throttleTime(33)).subscribe(r=>{var e,n;let t=[];r!==null&&(t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),t.length>0&&(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&t.length===1&&((e=t[0].primary)==null?void 0:e.actualRow)===r.row&&((n=t[0].primary)==null?void 0:n.actualColumn)===r.col?(this._isSetCursor=!0,this._context.scene.setCursor(j.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(r=>{var t;if(r!=null&&r.drawing&&this._isSetCursor){const e=r.drawing.drawing.drawingOrigin,n=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap.getImage(e.imageSourceType,e.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};ct=Bt([Ye(1,c.Inject(b.HoverManagerService)),Ye(2,c.Inject(D.SheetsSelectionsService)),Ye(3,c.Inject(le.DrawingRenderService)),Ye(4,c.Inject(b.SheetSkeletonManagerService))],ct);function x(o,r,t){const{from:e,to:n,flipY:i=!1,flipX:s=!1,angle:a=0,skewX:l=0,skewY:g=0}=o,u=t.getCurrent();if(u==null)return;const d=b.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:p,top:h,width:S,height:f}=d;const w=t.getCurrentSkeleton(),_=w.rowHeaderWidth+w.columnTotalWidth,I=w.columnHeaderHeight+w.rowTotalHeight;return p+S>_&&(p=_-S),h+f>I&&(h=I-f),{flipY:i,flipX:s,angle:a,skewX:l,skewY:g,left:p,top:h,width:S,height:f}}function H(o,r){const{left:t=0,top:e=0,width:n=0,height:i=0,flipY:s=!1,flipX:a=!1,angle:l=0,skewX:g=0,skewY:u=0}=o,d=r.getCellWithCoordByOffset(t,e);if(d==null)return;const p={column:d.actualColumn,columnOffset:j.precisionTo(t-d.startX,1),row:d.actualRow,rowOffset:j.precisionTo(e-d.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+i);if(h==null)return;const S={column:h.actualColumn,columnOffset:j.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:j.precisionTo(e+i-h.startY,1)};return{flipY:s,flipX:a,angle:l,skewX:g,skewY:u,from:p,to:S}}var Yt=Object.getOwnPropertyDescriptor,Ft=(o,r,t,e)=>{for(var n=e>1?void 0:e?Yt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Fe=(o,r)=>(t,e)=>r(t,e,o);let dt=class extends c.Disposable{constructor(o,r,t,e,n){super(),this._context=o,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const o=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in o){const t=o[r];for(const e in t.data){const n=t.data[e];n.sheetTransform&&(n.transform=x(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService))}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};dt=Ft([Fe(1,m.ISheetDrawingService),Fe(2,W.IDrawingManagerService),Fe(3,c.Inject(b.ISheetSelectionRenderService)),Fe(4,c.Inject(b.SheetSkeletonManagerService))],dt);function $t(o){const r=[];return o.forEach(t=>{const{parent:e,children:n}=t,{unitId:i,subUnitId:s,drawingId:a}=e,l=j.getGroupState(0,0,n.map(d=>d.transform||{})),g=n.map(d=>{const p=d.transform||{left:0,top:0},{unitId:h,subUnitId:S,drawingId:f}=d;return{unitId:h,subUnitId:S,drawingId:f,transform:{...p,left:p.left-l.left,top:p.top-l.top},groupId:a}}),u={unitId:i,subUnitId:s,drawingId:a,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:l};r.push({parent:u,children:g})}),r}function Lt(o){const r=[];return o.forEach(t=>{const{parent:e,children:n}=t,{unitId:i,subUnitId:s,drawingId:a,transform:l={width:0,height:0}}=e;if(l==null)return;const g=n.map(d=>{const{transform:p}=d,{unitId:h,subUnitId:S,drawingId:f}=d,w=j.transformObjectOutOfGroup(p||{},l,l.width||0,l.height||0);return{unitId:h,subUnitId:S,drawingId:f,transform:w,groupId:void 0}}),u={unitId:i,subUnitId:s,drawingId:a,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const lt={id:"sheet.command.group-sheet-image",type:c.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService),n=o.get(m.ISheetDrawingService);if(!r)return!1;const i=[];r.forEach(({parent:h,children:S})=>{i.push(h.unitId),S.forEach(f=>{i.push(f.unitId)})});const s=n.getGroupDrawingOp(r),{unitId:a,subUnitId:l,undo:g,redo:u,objects:d}=s;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:l,objects:d,type:m.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:l,objects:Lt(d),type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:i}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:l,objects:d,type:m.DrawingApplyType.GROUP}},{id:G.id,params:i}]}),!0):!1}},Te={id:"sheet.command.insert-sheet-image",type:c.CommandType.COMMAND,handler:(o,r)=>{var I,C,R;const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService),n=o.get(m.ISheetDrawingService),i=o.get(D.SheetInterceptorService);if(!r)return!1;const s=r.drawings,a=s.map(y=>y.unitId),l=n.getBatchAddOp(s),{unitId:g,subUnitId:u,undo:d,redo:p,objects:h}=l,S=i.onCommandExecute({id:Te.id,params:r}),f={id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT}},w={id:m.SetDrawingApplyMutation.id,params:{op:d,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.REMOVE}};return c.sequenceExecute([...(I=S.preRedos)!=null?I:[],f,...S.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=S.preUndos)!=null?C:[],w,...S.undos,{id:G.id,params:a}],redoMutations:[...(R=S.preRedos)!=null?R:[],f,...S.redos,{id:G.id,params:a}]}),!0):!1}},ut={id:"sheet.command.set-drawing-arrange",type:c.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService);if(!r)return!1;const n=o.get(m.ISheetDrawingService),{unitId:i,subUnitId:s,drawingIds:a,arrangeType:l}=r,g={unitId:i,subUnitId:s,drawingIds:a};let u;if(l===c.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):l===c.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):l===c.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):l===c.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:d,redo:p,undo:h}=u;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:p,unitId:i,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:i,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:i,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:i,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}},Re={id:"sheet.command.set-sheet-image",type:c.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService),n=o.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:i}=r,s=n.getBatchUpdateOp(i),{unitId:a,subUnitId:l,undo:g,redo:u,objects:d}=s;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:a,subUnitId:l,op:u,objects:d,type:m.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:l,op:g,objects:d,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:l,op:u,objects:d,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}]}),!0):!1}},gt={id:"sheet.command.ungroup-sheet-image",type:c.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService),n=o.get(m.ISheetDrawingService);if(!r)return!1;const i=[];r.forEach(({parent:h,children:S})=>{i.push(h.unitId),S.forEach(f=>{i.push(f.unitId)})});const s=n.getUngroupDrawingOp(r),{unitId:a,subUnitId:l,undo:g,redo:u,objects:d}=s;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:l,objects:d,type:m.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:l,objects:$t(d),type:m.DrawingApplyType.GROUP}},{id:G.id,params:i}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:l,objects:d,type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:i}]}),!0):!1}};var Gt=Object.getOwnPropertyDescriptor,Ht=(o,r,t,e)=>{for(var n=e>1?void 0:e?Gt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Q=(o,r)=>(t,e)=>r(t,e,o);function Xt(o,r,t){const e=t*Math.PI/180,n=Math.abs(o*Math.cos(e))+Math.abs(r*Math.sin(e)),i=Math.abs(o*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:i}}function ht(o,r,t,e,n){var I;const{rotatedHeight:i,rotatedWidth:s}=Xt(t,e,n),l=o.get(j.IRenderManagerService).getRenderById(r.unitId);if(!l)return!1;const u=(I=l.with(b.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:I.skeleton;if(u==null)return!1;const d=u.getCellByIndex(r.row,r.col),p=d.mergeInfo.endX-d.mergeInfo.startX-2,h=d.mergeInfo.endY-d.mergeInfo.startY-2,S=s/i,w=Math.ceil(Math.min(p,h*S))/s,_=!w||Number.isNaN(w)?.001:w;return{width:t*_,height:e*_}}O.SheetDrawingUpdateController=class extends c.Disposable{constructor(t,e,n,i,s,a,l,g,u,d,p,h,S){super();re(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=i,this._imageIoService=s,this._fileOpenerService=a,this._sheetDrawingService=l,this._drawingManagerService=g,this._contextService=u,this._messageService=d,this._localeService=p,this._injector=S,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const t=await this._fileOpenerService.openFile({multiple:!0,accept:W.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),e=t.length;return e>W.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(W.DRAWING_IMAGE_COUNT_LIMIT))}),!1):e===0?!1:(t.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const e=(await this._fileOpenerService.openFile({multiple:!1,accept:W.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(t,e){return this._insertCellImage(t,e)}async insertFloatImageByFile(t){let e;try{e=await this._imageIoService.saveImage(t)}catch(C){const R=C.message;R===W.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(W.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):R===W.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):R===W.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const n=this._getUnitInfo(),{unitId:i,subUnitId:s}=n,{imageId:a,imageSourceType:l,source:g,base64Cache:u}=e,{width:d,height:p,image:h}=await W.getImageSize(u||""),{width:S,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(g,l,h);let w=1;if(d>W.DRAWING_IMAGE_WIDTH_LIMIT||p>W.DRAWING_IMAGE_HEIGHT_LIMIT){const C=W.DRAWING_IMAGE_WIDTH_LIMIT/d,R=W.DRAWING_IMAGE_HEIGHT_LIMIT/p;w=Math.max(C,R)}const _=this._getImagePosition(d*w,p*w,S,f);if(_==null)return;const I={unitId:i,subUnitId:s,drawingId:a,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:g,transform:x(_,this._selectionRenderService,this._skeletonManagerService),sheetTransform:_};return this._commandService.executeCommand(Te.id,{unitId:i,drawings:[I]})}async _insertCellImage(t,e){var R,y;let n;try{n=await this._imageIoService.saveImage(t)}catch(T){const v=T.message;v===W.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(W.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):v===W.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):v===W.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:i,imageSourceType:s,source:a,base64Cache:l}=n,{width:g,height:u,image:d}=await W.getImageSize(l||"");this._imageIoService.addImageSourceCache(a,s,d);const p=this._workbookSelections.getCurrentLastSelection();if(!p)return!1;let h=p.primary.actualRow,S=p.primary.actualColumn;p.primary.isMerged&&(h=p.primary.startRow,S=p.primary.startColumn);const f=c.createDocumentModelWithStyle("",{}),w=ht(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:h,col:S},g,u,0);if(!w)return!1;const _={size:{width:w.width,height:w.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},I={unitId:f.getUnitId(),subUnitId:f.getUnitId(),drawingId:i,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:je.docDrawingPositionToTransform(_),docTransform:_,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},C=c.BuildTextUtils.drawing.add({documentDataModel:f,drawings:[I],selection:{collapsed:!0,startOffset:0,endOffset:0}});return C?(f.apply(C),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(R=e==null?void 0:e.row)!=null?R:h]:{[(y=e==null?void 0:e.col)!=null?y:S]:{p:f.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,S;const{width:n,height:i,image:s}=await W.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,c.ImageSourceType.URL,s);const a=this._workbookSelections.getCurrentLastSelection();if(!a)return!1;const l=c.createDocumentModelWithStyle("",{}),g=ht(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:a.primary.actualRow,col:a.primary.actualColumn},n,i,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},d={unitId:l.getUnitId(),subUnitId:l.getUnitId(),drawingId:c.generateRandomId(),drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c.ImageSourceType.URL,source:t,transform:je.docDrawingPositionToTransform(u),docTransform:u,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},p=c.BuildTextUtils.drawing.add({documentDataModel:l,drawings:[d],selection:{collapsed:!0,startOffset:0,endOffset:0}});return p?(l.apply(p),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(h=e==null?void 0:e.row)!=null?h:a.primary.actualRow]:{[(S=e==null?void 0:e.col)!=null?S:a.primary.actualColumn]:{p:l.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}_getUnitInfo(){const t=this._context.unit,e=t.getActiveSheet(),n=t.getUnitId(),i=e.getSheetId();return{unitId:n,subUnitId:i}}_getImagePosition(t,e,n,i){const s=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};s&&s.length>0&&(a=s[s.length-1].range);const l=b.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(l==null)return;let{startColumn:g,startRow:u,startX:d,startY:p}=l,h=!1;if(d+t>n&&(d=n-t,d<0&&(d=0,t=n),h=!0),p+e>i&&(p=i-e,p<0&&(p=0,e=i),h=!0),h){const _=this._selectionRenderService.getCellWithCoordByOffset(d,p);if(_==null)return;d=_.startX,p=_.startY,g=_.actualColumn,u=_.actualRow}const S={column:g,columnOffset:0,row:u,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(d+t,p+e);if(f==null)return;const w={column:f.actualColumn,columnOffset:d+t-f.startX,row:f.actualRow,rowOffset:p+e-f.startY};return{from:S,to:w}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:i,arrangeType:s}=t;this._commandService.executeCommand(ut.id,{unitId:e,subUnitId:n,drawingIds:i,arrangeType:s})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:i,subUnitId:s,drawingId:a,drawingType:l,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:i,subUnitId:s,drawingId:a});if(u==null||u.unitId!==this._context.unitId)return;const d=H({...u.transform,...g},this._selectionRenderService);if(d==null)return;const p={...n,transform:{...u.transform,...g,...x(d,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...d}};e.push(p)}),e.length>0&&this._commandService.executeCommand(Re.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(lt.id,t);const{unitId:e,subUnitId:n,drawingId:i}=t[0].parent;this._commandService.syncExecuteCommand(W.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:i}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(gt.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}},O.SheetDrawingUpdateController=Ht([Q(1,c.Inject(b.SheetSkeletonManagerService)),Q(2,c.ICommandService),Q(3,b.ISheetSelectionRenderService),Q(4,W.IImageIoService),Q(5,B.ILocalFileService),Q(6,m.ISheetDrawingService),Q(7,W.IDrawingManagerService),Q(8,c.IContextService),Q(9,B.IMessageService),Q(10,c.Inject(c.LocaleService)),Q(11,c.Inject(D.SheetsSelectionsService)),Q(12,c.Inject(c.Injector))],O.SheetDrawingUpdateController);var Vt=Object.getOwnPropertyDescriptor,Kt=(o,r,t,e)=>{for(var n=e>1?void 0:e?Vt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Se=(o,r)=>(t,e)=>r(t,e,o);function Dt(o,r,t){var e,n,i,s;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((s=(i=t.p)==null?void 0:i.drawingsOrder)==null?void 0:s.length)===1){const a=t.p.drawings[t.p.drawingsOrder[0]],l=ht(o,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},a.docTransform.size.width,a.docTransform.size.height,a.docTransform.angle);if(l)return a.transform.width=l.width,a.transform.height=l.height,a.docTransform.size.width=l.width,a.docTransform.size.height=l.height,a.transform.left=0,a.transform.top=0,a.docTransform.positionH.posOffset=0,a.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let $e=class extends c.Disposable{constructor(o,r,t,e,n,i){super(),this._commandService=o,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=i,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(o=>{o.visible?o.visible&&(this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(o=>{o.id===je.ReplaceSnapshotCommand.id&&o.params.unitId===c.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(D.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:D.InterceptCellContentPriority.CELL_IMAGE,handler:(o,r,t)=>{var e;return o!=null&&o.p&&((e=o.p.drawingsOrder)!=null&&e.length)&&(o===r.rawData&&(o={...r.rawData}),o.interceptorStyle||(o.interceptorStyle={}),o.interceptorStyle.tr={a:0},Dt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},o)),t(o)}}))}};$e=Kt([Se(0,c.ICommandService),Se(1,c.Inject(D.SheetInterceptorService)),Se(2,c.Inject(c.Injector)),Se(3,W.IDrawingManagerService),Se(4,c.Inject(ge.DocDrawingController)),Se(5,c.Inject(b.IEditorBridgeService))],$e);var zt=Object.getOwnPropertyDescriptor,xt=(o,r,t,e)=>{for(var n=e>1?void 0:e?zt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Ct=(o,r)=>(t,e)=>r(t,e,o);let Le=class extends c.Disposable{constructor(o,r){super(),this._autoFillService=o,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(o,r,t,e)=>{new c.ObjectMatrix(e).forValue((n,i,s)=>{Dt(this._injector,{unitId:o.unitId,subUnitId:o.subUnitId,row:n,col:i},s)})}}))}};Le=xt([Ct(0,c.Inject(b.IAutoFillService)),Ct(1,c.Inject(c.Injector))],Le);var qt=Object.getOwnPropertyDescriptor,Zt=(o,r,t,e)=>{for(var n=e>1?void 0:e?qt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Ee=(o,r)=>(t,e)=>r(t,e,o);const Jt=[c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,c.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,c.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let Ge=class extends c.Disposable{constructor(o,r,t,e,n){super(),this._commandService=o,this._univerInstanceService=r,this._dialogService=t,this._renderManagerService=e,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(o){var n;const r=c.createDocumentModelWithStyle("",{}),t=(n=j.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(b.EditingRenderController),e=c.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[o],selection:{collapsed:!0,startOffset:0,endOffset:0}});e&&(r.apply(e),t&&t.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(o=>{var r,t;if(o.id===je.InnerPasteCommand.id){const e=o.params,{doc:n}=e,i=this._univerInstanceService.getCurrentUnitOfType(c.UniverInstanceType.UNIVER_DOC);if(i==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const s=i.getUnitId();if(Jt.includes(s)){if(s!==c.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const a=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(b.SetCellEditVisibleOperation.id,{visible:!1})};((t=i.getBody())==null?void 0:t.dataStream)===`\r
2
- `?(this._commandService.syncExecuteCommand(b.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(n.drawings)[0])):this._dialogService.open({id:"sheet-cell-image-copy-paste",title:{label:this._localeService.t("cell-image.pasteTitle")},children:{label:this._localeService.t("cell-image.pasteContent")},width:320,destroyOnClose:!0,onClose:a,showOk:!0,showCancel:!0,onOk:()=>{a(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:a})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};Ge=Zt([Ee(0,c.ICommandService),Ee(1,c.IUniverInstanceService),Ee(2,B.IDialogService),Ee(3,j.IRenderManagerService),Ee(4,c.Inject(c.LocaleService))],Ge);const be={id:"sheet.command.insert-float-image",type:c.CommandType.COMMAND,handler:async(o,r)=>{var s,a;const t=o.get(c.IUniverInstanceService),e=o.get(j.IRenderManagerService),n=(s=j.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:s.with(O.SheetDrawingUpdateController);if(!n)return!1;const i=r==null?void 0:r.files;if(i){const l=i.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(l)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},pt={id:"sheet.command.insert-cell-image",type:c.CommandType.COMMAND,handler:o=>{var e,n;const r=o.get(c.IUniverInstanceService),t=o.get(j.IRenderManagerService);return(n=(e=j.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,r,t))==null?void 0:e.with(O.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}};var Qt=Object.getOwnPropertyDescriptor,en=(o,r,t,e)=>{for(var n=e>1?void 0:e?Qt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Oe=(o,r)=>(t,e)=>r(t,e,o);const Mt="image/png";function tn(o){const r=o.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let i=0;i<e;i++)n[i]=t.charCodeAt(i);return new Blob([n],{type:Mt})}function nn(o){const r=new ClipboardItem({[Mt]:tn(o)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function rn(){function o(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const r=document.activeElement,t=o();return document.body.appendChild(t),t.focus(),()=>{t.blur(),document.body.removeChild(t),r instanceof HTMLElement&&r.focus()}}const Tt=[b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let He=class extends c.Disposable{constructor(r,t,e,n,i){super();re(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=i,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const i=this._focusedDrawings;if(i.length>0){const[s]=i;if(n===b.COPY_TYPE.CUT){const l={unitId:r,drawings:[s]};this._commandService.executeCommand(fe.id,l)}setTimeout(()=>{const l=rn();s.drawingType===c.DrawingTypeEnum.DRAWING_IMAGE&&s.imageSourceType===W.ImageSourceType.BASE64?nn(s.source):this._clipboardInterfaceService.writeText(""),l()},200);const a={unitId:s.unitId,subUnitId:s.subUnitId,drawings:[s]};this._copyInfo=a}else{const s=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=s}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:i=b.COPY_TYPE.COPY,pasteType:s}=n,{range:a}=r||{},{range:l,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:s,unitId:g,subUnitId:u,pasteRange:l},{copyRange:a,copyType:i}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:s},b.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.COPY_TYPE.COPY);{const e=t.filter(n=>n.type.includes("image"));if(e.length)return{undos:[],redos:[{id:be.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var p;const n=(p=this._renderManagerService.getRenderById(r))==null?void 0:p.with(b.SheetSkeletonManagerService);if(!n)return;const i=n.attachRangeWithCoord(e);if(!i)return;const{startX:s,endX:a,startY:l,endY:g}=i,u=this._drawingService.getDrawingData(r,t),d=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const S=u[h],{transform:f}=S;if(S.anchorType!==m.SheetDrawingAnchorType.Both||!f)return;const{left:w=0,top:_=0,width:I=0,height:C=0}=f,{drawingStartX:R,drawingEndX:y,drawingStartY:T,drawingEndY:v}={drawingStartX:w,drawingEndX:w+I,drawingStartY:_,drawingEndY:_+C};s<=R&&y<=a&&l<=T&&v<=g&&d.push(S)}),d.length)return{copyRange:e,drawings:d,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Tt.includes(e))return{redos:[],undos:[]};const{unitId:i,subUnitId:s,range:a}=n,l=this._renderManagerService.getRenderById(i),g=l==null?void 0:l.with(b.SheetSkeletonManagerService),u=l==null?void 0:l.with(b.ISheetSelectionRenderService),d=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:p}=d,h=b.discreteRangeToRange(a);return this._generateMutations(p,{unitId:i,subUnitId:s,isCut:t===b.COPY_TYPE.CUT,getTransform:(S,f)=>{var I;const w=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),_={...S,left:w==null?void 0:w.startX,top:w==null?void 0:w.startY};return{transform:_,sheetTransform:(I=H(_,u))!=null?I:f}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:i,isCut:s}=t,a=[],l=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:d,sheetTransform:p}=u;if(!d)return;const h=i(d,p),S={...u,unitId:e,subUnitId:n,drawingId:s?u.drawingId:c.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(s){const{undo:f,redo:w,objects:_}=g.getBatchUpdateOp([S]);a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:w,objects:_}}),l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:f,objects:_}})}else{const{undo:f,redo:w,objects:_}=g.getBatchAddOp([S]);a.push({id:m.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.INSERT}}),l.push({id:m.SetDrawingApplyMutation.id,params:{op:f,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.REMOVE}})}}),{redos:a,undos:l}}_generateRangeDrawingsPasteMutations(r,t){var P;const{unitId:e,subUnitId:n,pasteType:i,pasteRange:s}=r,{copyRange:a,copyType:l}=t;if(Tt.includes(i))return{redos:[],undos:[]};const g=(P=this._renderManagerService.getRenderById(e))==null?void 0:P.with(b.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:b.discreteRangeToRange(s)},pasteType:i},l);const{ranges:[d,p],mapFunc:h}=b.virtualizeDiscreteRanges([a,s]),{row:S,col:f}=h(d.startRow,d.startColumn),{row:w,col:_}=h(p.startRow,p.startColumn),I=g.attachRangeWithCoord({startRow:S,endRow:S,startColumn:f,endColumn:f}),C=g.attachRangeWithCoord({startRow:w,endRow:w,startColumn:_,endColumn:_});if(!I||!C||!this._copyInfo)return{redos:[],undos:[]};const R=C.startX-I.startX,y=C.startY-I.startY,T=w-S,v=_-f;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(E,N)=>{var k,A;return{transform:{...E,left:((k=E==null?void 0:E.left)!=null?k:0)+R,top:((A=E==null?void 0:E.top)!=null?A:0)+y},sheetTransform:{...N,to:{...N.to,row:N.to.row+T,column:N.to.column+v},from:{...N.from,row:N.from.row+T,column:N.from.column+v}}}},isCut:l===b.COPY_TYPE.CUT})}};He=en([Oe(0,b.ISheetClipboardService),Oe(1,j.IRenderManagerService),Oe(2,W.IDrawingManagerService),Oe(3,B.IClipboardInterfaceService),Oe(4,c.ICommandService)],He);var on=Object.getOwnPropertyDescriptor,sn=(o,r,t,e)=>{for(var n=e>1?void 0:e?on(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Ae=(o,r)=>(t,e)=>r(t,e,o);let Xe=class extends c.Disposable{constructor(o,r,t,e,n){super(),this._drawingManagerService=o,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=U.combineLatest([o,r]);this.disposeWithMe(t.pipe(U.switchMap(([e,n])=>e?e.activeSheet$.pipe(U.tap(i=>{if(!i){this._drawingManagerService.setDrawingVisible(!1);return}const s=e.getUnitId(),a=i.getSheetId();this._permissionService.composePermission([new D.WorkbookViewPermission(s).id,new D.WorksheetViewPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,i)})):(this._drawingManagerService.setDrawingVisible(!1),U.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(o,r){this._drawingManagerService.setDrawingVisible(!1);const t=o.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),i=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===j.RENDER_CLASS_TYPE.IMAGE&&i.some(u=>g.oKey.includes(u.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=U.combineLatest([o,r]);this.disposeWithMe(t.pipe(U.switchMap(([e,n])=>e?e.activeSheet$.pipe(U.tap(i=>{if(!i){this._drawingManagerService.setDrawingEditable(!1);return}const s=e.getUnitId(),a=i.getSheetId();this._permissionService.composePermission([new D.WorkbookEditablePermission(s).id,new D.WorksheetEditPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,i)})):(this._drawingManagerService.setDrawingEditable(!1),U.EMPTY))).subscribe())}_handleDrawingEditableFalse(o,r){this._drawingManagerService.setDrawingEditable(!1);const t=o.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),i=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===j.RENDER_CLASS_TYPE.IMAGE&&i.some(u=>g.oKey.includes(u.drawingId))&&a.detachTransformerFrom(g)})}_initViewPermissionChange(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(U.combineLatest([o,r]).pipe(U.switchMap(([t,e])=>t?t.activeSheet$.pipe(U.switchMap(n=>{if(!n)return U.EMPTY;const i=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(i),l=a==null?void 0:a.scene;if(!l)return U.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookViewPermission(i).id,new D.WorksheetViewPermission(i,s).id]).pipe(U.map(d=>d.every(p=>p.value)),U.distinctUntilChanged()).pipe(U.map(d=>({permission:d,scene:l,transformer:g,unitId:i,subUnitId:s})))})):U.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:i,subUnitId:s})=>{this._drawingManagerService.setDrawingVisible(t);const a=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(i,s),g=Object.values(l);t?this._drawingManagerService.addNotification(g):(a.forEach(u=>{u.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),i=e==null?void 0:e.getSheetId();if(!n||!i)return;const s=this._drawingManagerService.getDrawingData(n,i),a=Object.values(s);this._drawingManagerService.addNotification(a)}}))}_initEditPermissionChange(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(U.combineLatest([o,r]).pipe(U.switchMap(([t,e])=>t?t.activeSheet$.pipe(U.switchMap(n=>{if(!n)return U.EMPTY;const i=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(i),l=a==null?void 0:a.scene;if(!l)return U.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookEditablePermission(i).id,new D.WorksheetEditPermission(i,s).id]).pipe(U.map(d=>d.every(p=>p.value)),U.distinctUntilChanged()).pipe(U.map(d=>({permission:d,scene:l,transformer:g,unitId:i,subUnitId:s})))})):U.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:i,subUnitId:s})=>{this._drawingManagerService.setDrawingEditable(t);const a=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(i,s),g=Object.values(l);t?(a.forEach(u=>{u.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(a.forEach(u=>{u.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const i=n.getSheetId(),s=this._renderManagerService.getRenderById(e),a=s==null?void 0:s.scene;if(!a)return;const l=this._drawingManagerService.getDrawingData(e,i),g=Object.values(l);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(d=>{d.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(p=>d.oKey.includes(p.drawingId))&&a.detachTransformerFrom(d)})}}))}};Xe=sn([Ae(0,W.IDrawingManagerService),Ae(1,j.IRenderManagerService),Ae(2,c.IPermissionService),Ae(3,c.IUniverInstanceService),Ae(4,c.Inject(c.UserManagerService))],Xe);var an=Object.getOwnPropertyDescriptor,cn=(o,r,t,e)=>{for(var n=e>1?void 0:e?an(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},he=(o,r)=>(t,e)=>r(t,e,o);function Rt(o,r,t,e,n,i=!1){const{scaleX:s,scaleY:a}=r.getAncestorScale(),l=r.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=e.getFreeze(),{startColumn:u,startRow:d,xSplit:p,ySplit:h}=g,S={left:!0,top:!0};if(!l)return{...o,absolute:S};const{left:f,right:w,top:_,bottom:I}=o;let{top:C,left:R,viewportScrollX:y,viewportScrollY:T}=l;const{boundsOfViewArea:v,scrollDirectionResponse:P}=n||{},{rowHeaderWidth:E,columnHeaderHeight:N}=t,k={top:i?0:N,left:i?0:E};v&&(c.Tools.isDefine(k.top)&&(k.top=v.top),c.Tools.isDefine(k.left)&&(k.left=v.left)),P==="HORIZONTAL"&&(T=0),P==="VERTICAL"&&(y=0);let A=0,M=0;const Y=t.rowStartY(d-h)+N,L=t.colStartX(u-p)+E,Z=t.rowStartY(d)+N,ee=t.colStartX(u)+E;if(p===0)S.left=!1,A=(f-y)*s,M=(w-y)*s;else{const K=f-(L-E),F=w-(L-E);w<ee?(A=K*s,M=F*s):f<=ee&&w>=ee?(A=K*s,M=Math.max(R,(w-y)*s)):f>ee&&(S.left=!1,A=Math.max((f-y)*s,R),M=Math.max((w-y)*s,R))}let V=0,z=0;if(h===0)S.top=!1,V=(_-T)*a,z=(I-T)*a;else{const K=_-(Y-N),F=I-(Y-N);I<Z?(V=K*a,z=F*a):_<=Z&&I>=Z?(V=K*a,z=Math.max(C,(I-T)*a)):_>Z&&(S.top=!1,V=Math.max((_-T)*a,C),z=Math.max((I-T)*a,C))}return A=Math.max(A,k.left),V=Math.max(V,k.top),M=Math.max(M,k.left),z=Math.max(z,k.top),{left:A,right:M,top:V,bottom:z,absolute:S}}const oe=(o,r,t,e,n)=>{const{left:i,top:s,width:a,height:l,angle:g}=o,u={left:i,right:i+a,top:s,bottom:s+l},d=Rt(u,r,t,e,n),{scaleX:p,scaleY:h}=r.getAncestorScale();return{startX:d.left,endX:d.right,startY:d.top,endY:d.bottom,rotate:g,width:a*p,height:l*h,absolute:d.absolute}};O.SheetCanvasFloatDomManagerService=class extends c.Disposable{constructor(t,e,n,i,s,a,l){super();re(this,"_domLayerInfoMap",new Map);re(this,"_transformChange$",new U.Subject);re(this,"transformChange$",this._transformChange$.asObservable());re(this,"_add$",new U.Subject);re(this,"add$",this._add$.asObservable());re(this,"_remove$",new U.Subject);re(this,"remove$",this._remove$.asObservable());this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=i,this._canvasFloatDomService=s,this._sheetDrawingService=a,this._lifecycleService=l,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(U.filter(t=>t===c.LifecycleStages.Rendered),U.take(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}getFloatDomsBySubUnitId(t,e){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===e&&n.unitId===t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const i=n.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:n,transformer:i,renderUnit:e,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var K;const{unitId:n,subUnitId:i,drawingId:s}=e,a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,c.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!l||!a)return;const d=(K=this._renderManagerService.getRenderById(n))==null?void 0:K.with(b.SheetSkeletonManagerService).getSkeletonParam(i);if(!d)return;const{transform:p,drawingType:h,data:S}=l;if(h!==c.DrawingTypeEnum.DRAWING_DOM&&h!==c.DrawingTypeEnum.DRAWING_CHART)return;const f=this._getSceneAndTransformerByDrawingSearch(n);if(f==null)return;const{scene:w,canvas:_}=f;if(p==null)return!0;if(u!==i)return;const{left:I,top:C,width:R,height:y,angle:T,flipX:v,flipY:P,skewX:E,skewY:N}=p,k=W.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:i,drawingId:s}),A=w.getObject(k);if(A!=null){A.transformByState({left:I,top:C,width:R,height:y,angle:T,flipX:v,flipY:P,skewX:E,skewY:N});return}const M={left:I,top:C,width:R,height:y,zIndex:this._drawingManagerService.getDrawingOrder(n,i).length-1},Y=h===c.DrawingTypeEnum.DRAWING_CHART;if(M.rotateEnabled=!1,Y){const F=S?S.backgroundColor:"white";M.fill=F,S&&S.border&&(M.stroke=S.border),M.paintFirst="stroke",M.strokeWidth=1,M.borderEnabled=!1,M.radius=8}const L=new j.Rect(k,M);Y&&L.setObjectType(j.ObjectType.CHART),w.addObject(L,j.DRAWING_OBJECT_LAYER_INDEX),l.allowTransform!==!1&&w.attachTransformerTo(L);const Z=new c.DisposableCollection,ee=oe(L,f.renderUnit.scene,d.skeleton,a.worksheet),V=new U.BehaviorSubject(ee),z={dispose:Z,rect:L,position$:V,unitId:n,subUnitId:i,id:s};this._canvasFloatDomService.addFloatDom({position$:V,id:s,componentKey:l.componentKey,onPointerDown:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onWheel:F=>{_.dispatchEvent(new WheelEvent(F.type,F))},data:S,unitId:n});const te=L.onTransformChange$.subscribeEvent(()=>{const F=oe(L,f.renderUnit.scene,d.skeleton,a.worksheet);V.next(F)});Z.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),te&&Z.add(te),this._domLayerInfoMap.set(s,z)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{var p;const{unitId:n,subUnitId:i,drawingId:s}=e,a=W.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:i,drawingId:s}),l=this._getSceneAndTransformerByDrawingSearch(n);if(l==null)return;const{transformer:g,scene:u}=l,d=u.getObject(a);d!=null&&d.oKey&&(g.clearControlByIds([d==null?void 0:d.oKey]),(p=u.getTransformer())==null||p.clearSelectedObjects())})}))}_scrollUpdateListener(){const t=(e,n)=>{var g;const i=this._getSceneAndTransformerByDrawingSearch(e),s=Array.from(this._domLayerInfoMap.keys()).map(u=>({id:u,...this._domLayerInfoMap.get(u)})).filter(u=>u.subUnitId===n&&u.unitId===e).map(u=>u.id),a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),l=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(b.SheetSkeletonManagerService).getSkeletonParam(n);!i||!a||!l||s.forEach(u=>{const d=this._domLayerInfoMap.get(u);if(d){const p=oe(d.rect,i.renderUnit.scene,l.skeleton,a.worksheet,d);d.position$.next(p)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(U.switchMap(e=>e?e.activeSheet$:U.of(null)),U.map(e=>{if(!e)return null;const n=e.getUnitId(),i=this._renderManagerService.getRenderById(n);return i?{render:i,unitId:n,subUnitId:e.getSheetId()}:null}),U.switchMap(e=>e?c.fromEventSubject(e.render.scene.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(U.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):U.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:i}=e;t(n,i)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===b.SetZoomRatioOperation.id){const n=e.params,{unitId:i}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===i).map(a=>a.subUnitId).forEach(a=>{t(i,a)})}else if(e.id===D.SetFrozenMutation.id){const{unitId:n,subUnitId:i}=e.params;t(n,i)}}))}_getPosition(t,e){var h;const{startX:n,endX:i,startY:s,endY:a}=t,l=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(b.ISheetSelectionRenderService);if(l==null)return;const g=l.getCellWithCoordByOffset(n,s);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:s-g.startY},d=l.getCellWithCoordByOffset(i,a);if(d==null)return;const p={column:d.actualColumn,columnOffset:i-d.startX,row:d.actualRow,rowOffset:a-d.startY};return{from:u,to:p}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==c.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==c.DrawingTypeEnum.DRAWING_CHART)return;const i={...n.transform};this._transformChange$.next({id:e.drawingId,value:i})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,i){const s=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(t);if(s&&a){const{scene:l}=a,g=W.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=l.getObject(g);u&&u instanceof j.Rect&&u.setProps(i)}}addFloatDomToPosition(t,e){const n=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:i,subUnitId:s}=n,{initPosition:a,componentKey:l,data:g,allowTransform:u=!0}=t,d=e!=null?e:c.generateRandomId(),p=this._getPosition(a,i);if(p==null)return;const h={unitId:i,subUnitId:s,drawingId:d,drawingType:t.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:p,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Te.id,{unitId:i,drawings:[h]}),this._add$.next({unitId:i,subUnitId:s,id:d}),{id:d,dispose:()=>{this._removeDom(d,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:i,subUnitId:s}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(i);if(a&&a.scene.removeObject(n.rect),e){const l=this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:s,drawingId:t});if(!l)return;const g=this._sheetDrawingService.getBatchRemoveOp([l]),{redo:u,objects:d}=g;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:i,subUnitId:s,op:u,objects:d,type:m.DrawingApplyType.REMOVE})}}addFloatDomToRange(t,e,n,i){var v,P,E;const s=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:l}=s,g=this._getSceneAndTransformerByDrawingSearch(a);if(!g)return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const d=(v=this._renderManagerService.getRenderById(a))==null?void 0:v.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:p,data:h,allowTransform:S=!0}=e,f=i!=null?i:c.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver(t,u,d.skeleton);if(this._getPosition(w,a)==null)return;const C=g.scene,{scaleX:R}=C.getAncestorScale(),y=Ve(w,n,R),T={unitId:a,subUnitId:l,drawingId:f,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:y.startX,top:y.startY,width:y.width,height:y.height},data:h,allowTransform:S};{const{unitId:N,subUnitId:k,drawingId:A}=T,M=D.getSheetCommandTarget(this._univerInstanceService,{unitId:N,subUnitId:k}),Y=T,L=this._univerInstanceService.getUnit(N,c.UniverInstanceType.UNIVER_SHEET);if(!L)return;const Z=L.getActiveSheet().getSheetId();if(!Y||!M)return;const ee=(P=this._renderManagerService.getRenderById(N))==null?void 0:P.with(b.SheetSkeletonManagerService);if(!ee)return;const V=ee.getWorksheetSkeleton(k);if(!V)return;const{transform:z,drawingType:te,data:K}=Y;if(te!==c.DrawingTypeEnum.DRAWING_DOM&&te!==c.DrawingTypeEnum.DRAWING_CHART)return;const F=this._getSceneAndTransformerByDrawingSearch(N);if(F==null)return;const{scene:ve,canvas:Ie}=F;if(z==null||Z!==k)return;const{left:qe,top:Ze,width:Je,height:Qe,angle:_t,flipX:vt,flipY:et,skewX:tt,skewY:ye}=z,nt=W.getDrawingShapeKeyByDrawingSearch({unitId:N,subUnitId:k,drawingId:A}),se=ve.getObject(nt);if(se!=null){se.transformByState({left:qe,top:Ze,width:Je,height:Qe,angle:_t,flipX:vt,flipY:et,skewX:tt,skewY:ye});return}const ne={left:qe,top:Ze,width:Je,height:Qe,zIndex:this._drawingManagerService.getDrawingOrder(N,k).length-1},De=te===c.DrawingTypeEnum.DRAWING_CHART;if(De){const $=K?K.backgroundColor:"white";ne.fill=$,ne.rotateEnabled=!1,K&&K.border&&(ne.stroke=K.border),ne.paintFirst="stroke",ne.strokeWidth=1,ne.borderEnabled=!1,ne.radius=8}const ae=new j.Rect(nt,ne);De&&ae.setObjectType(j.ObjectType.CHART),ve.addObject(ae,j.DRAWING_OBJECT_LAYER_INDEX),Y.allowTransform!==!1&&ve.attachTransformerTo(ae);const ce=new c.DisposableCollection,rt=ve.getMainViewport(),{rowHeaderWidth:Ce,columnHeaderHeight:Ne}=V.skeleton,it={top:Ne,left:Ce,bottom:rt.bottom,right:rt.right},de={dispose:ce,rect:ae,boundsOfViewArea:it,domAnchor:n,unitId:N,subUnitId:k},X=oe(ae,F.renderUnit.scene,V.skeleton,M.worksheet,de),Me=new U.BehaviorSubject(X);de.position$=Me;let ke={position$:Me,id:A,componentKey:Y.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{Ie.dispatchEvent(new WheelEvent($.type,$))},data:K,unitId:N};e.eventPassThrough&&(ke={...ke,onPointerDown:$=>{Ie.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{Ie.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{Ie.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(ke),this.disposeWithMe(_.subscribe($=>{var Ot,At,Pt,Ut;const bt=Ve({startX:$.startX,startY:$.startY,endX:$.endX,endY:$.endY,width:(Ot=n.width)!=null?Ot:$.width,height:(At=n.height)!=null?At:$.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Nn=W.getDrawingShapeKeyByDrawingSearch({unitId:N,subUnitId:k,drawingId:A}),kn=new j.Rect(Nn,{left:bt.startX,top:bt.startY,width:(Pt=n.width)!=null?Pt:$.width,height:(Ut=n.height)!=null?Ut:$.height,zIndex:this._drawingManagerService.getDrawingOrder(N,k).length-1}),Wn=oe(kn,F.renderUnit.scene,V.skeleton,M.worksheet,de);Me.next(Wn)}));const We=(E=this._renderManagerService.getRenderById(N))==null?void 0:E.with(b.SheetSkeletonManagerService);We==null||We.currentSkeleton$.subscribe($=>{$&&V.sheetId!==$.sheetId&&this._removeDom(f,!0)});const ot=ae.onTransformChange$.subscribeEvent(()=>{const $=oe(ae,F.renderUnit.scene,V.skeleton,M.worksheet,de);Me.next($)});ce.add(()=>{this._canvasFloatDomService.removeFloatDom(A)}),ot&&ce.add(ot),this._domLayerInfoMap.set(A,de)}return{id:f,dispose:()=>{this._removeDom(f,!0)}}}addFloatDomToColumnHeader(t,e,n,i){var y,T,v;const s=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:l}=s;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const d=(y=this._renderManagerService.getRenderById(a))==null?void 0:y.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:p,data:h,allowTransform:S=!0}=e,f=i!=null?i:c.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,d.skeleton),I=w;if(I.startY=0,this._getPosition(w,a)==null)return;const R={unitId:a,subUnitId:l,drawingId:f,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:h,allowTransform:S};{const{unitId:P,subUnitId:E,drawingId:N}=R,k=D.getSheetCommandTarget(this._univerInstanceService,{unitId:P,subUnitId:E}),A=R,M=this._univerInstanceService.getUnit(P,c.UniverInstanceType.UNIVER_SHEET);if(!M)return;const Y=M.getActiveSheet().getSheetId();if(!A||!k)return;const L=(T=this._renderManagerService.getRenderById(P))==null?void 0:T.with(b.SheetSkeletonManagerService);if(!L)return;const Z=L.getWorksheetSkeleton(E);if(!Z)return;const{transform:ee,data:V}=A,z=this._getSceneAndTransformerByDrawingSearch(P);if(z==null)return;const{scene:te,canvas:K}=z;if(ee==null||Y!==E)return;const{left:F,top:ve,width:Ie,height:qe,angle:Ze,flipX:Je,flipY:Qe,skewX:_t,skewY:vt}=ee,et=W.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:E,drawingId:N}),tt=te.getObject(et);if(tt!=null){tt.transformByState({left:F,top:ve,width:Ie,height:qe,angle:Ze,flipX:Je,flipY:Qe,skewX:_t,skewY:vt});return}const ye=Ve({startX:I.startX,startY:0,endX:w.endX,endY:w.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),nt={left:ye.startX,top:ye.startY,width:ye.width,height:ye.height,zIndex:this._drawingManagerService.getDrawingOrder(P,E).length-1},se=new j.Rect(et,nt);te.addObject(se,j.DRAWING_OBJECT_LAYER_INDEX),A.allowTransform!==!1&&te.attachTransformerTo(se);const ne=new c.DisposableCollection,De=te.getMainViewport(),ae={top:0,left:De.left,bottom:De.bottom,right:De.right},ce={dispose:ne,rect:se,unitId:P,subUnitId:E,boundsOfViewArea:ae,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},rt=oe(se,z.renderUnit.scene,Z.skeleton,k.worksheet,ce),Ce=new U.BehaviorSubject(rt);ce.position$=Ce;let Ne={position$:Ce,id:N,componentKey:A.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:X=>{K.dispatchEvent(new WheelEvent(X.type,X))},data:V,unitId:P};e.eventPassThrough&&(Ne={...Ne,onPointerDown:X=>{K.dispatchEvent(new PointerEvent(X.type,X))},onPointerMove:X=>{K.dispatchEvent(new PointerEvent(X.type,X))},onPointerUp:X=>{K.dispatchEvent(new PointerEvent(X.type,X))}}),this._canvasFloatDomService.addFloatDom(Ne);const it=se.onTransformChange$.subscribeEvent(()=>{const X=oe(se,z.renderUnit.scene,Z.skeleton,k.worksheet,ce);Ce.next(X)});this.disposeWithMe(_.subscribe(X=>{const Me=Ve({startX:X.startX,startY:0,endX:X.endX,endY:X.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),ke=W.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:E,drawingId:N}),We=new j.Rect(ke,{left:Me.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(P,E).length-1}),ot=oe(We,z.renderUnit.scene,Z.skeleton,k.worksheet,ce);Ce.next(ot)}));const de=(v=this._renderManagerService.getRenderById(P))==null?void 0:v.with(b.SheetSkeletonManagerService);de==null||de.currentSkeleton$.subscribe(X=>{X&&d.sheetId!==X.sheetId&&this._removeDom(f,!0)}),ne.add(()=>{this._canvasFloatDomService.removeFloatDom(N)}),it&&ne.add(it),this._domLayerInfoMap.set(N,ce)}return{id:f,dispose:()=>{this._removeDom(f,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:i,startColumn:s}=t;const a=Pe(i,s,n),l=new U.BehaviorSubject(a),g=Pe(t.endRow,t.endColumn,n),u=new U.BehaviorSubject(g),d=()=>{const _=Pe(i,s,n),I=Pe(t.endRow,t.endColumn,n);l.next(_),u.next(I)},p=new c.DisposableCollection;p.add(e.engine.clientRect$.subscribe(()=>d())),p.add(this._commandService.onCommandExecuted(_=>{if(_.id===D.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(C=>C.row===i)>-1){d();return}(D.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===b.SetScrollOperation.id||_.id===b.SetZoomRatioOperation.id)&&d()}));const h=(_,I)=>{i=_,s=I,d()},S=()=>({rotate:0,width:g.right-a.left,height:g.bottom-a.top,absolute:{left:!0,top:!0},startX:a.left,startY:a.top,endX:g.right,endY:g.bottom}),f=l.pipe(U.map(_=>{const I=Pe(t.endRow,t.endColumn,n);return{rotate:0,width:I.right-_.left,height:I.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:I.right,endY:I.bottom}})),w=S();return{position$:f,position:w,updateRowCol:h,topLeftPos$:l,rightBottomPos$:u,disposable:p}}},O.SheetCanvasFloatDomManagerService=cn([he(0,c.Inject(j.IRenderManagerService)),he(1,c.IUniverInstanceService),he(2,c.Inject(c.ICommandService)),he(3,W.IDrawingManagerService),he(4,c.Inject(B.CanvasFloatDomService)),he(5,m.ISheetDrawingService),he(6,c.Inject(c.LifecycleService))],O.SheetCanvasFloatDomManagerService);function Pe(o,r,t){const e=t.getCellWithCoordByIndex(o,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Ve(o,r,t){var g,u;t=t!=null?t:1;const e=o.endX-o.startX,n=o.endY-o.startY,i=(g=r==null?void 0:r.width)!=null?g:e,s=(u=r==null?void 0:r.height)!=null?u:n;let a=0,l=0;if(r){if(r.horizonOffsetAlign==="right"){const d=Ke(r.marginX,e*t);a=o.endX-d-i}else a=o.startX+Ke(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const d=Ke(r.marginY,n*t);l=o.endY-d-s}else l=o.startY+Ke(r.marginY,n)}return{rotate:0,startX:a,startY:l,endX:o.endX,endY:o.endY,width:i,height:s,absolute:{left:o.absolute.left,top:o.absolute.top}}}function Ke(o,r){if(o===void 0)return 0;if(typeof o=="number")return o;const t=Number.parseFloat(o);return r*t/100}const dn=o=>{const{floatDomInfos:r,scene:t,skeleton:e,worksheet:n}=o,i=me.useMemo(()=>r.map(s=>{const{width:a,height:l,angle:g,left:u,top:d}=s.transform,p=Rt({left:u!=null?u:0,right:(u!=null?u:0)+(a!=null?a:0),top:d!=null?d:0,bottom:(d!=null?d:0)+(l!=null?l:0)},t,e,n,void 0,!0),{scaleX:h,scaleY:S}=t.getAncestorScale(),f={startX:p.left,endX:p.right,startY:p.top,endY:p.bottom,rotate:g,width:a*h,height:l*S,absolute:p.absolute},w={position$:new U.BehaviorSubject(f),position:f,id:s.drawingId,componentKey:s.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:s.unitId,data:s.data};return[s.drawingId,w]}),[r,t,e,n]);return J.jsx("div",{style:{position:"absolute",top:0,left:0},children:i.map(([s,a])=>J.jsx(B.PrintFloatDomSingle,{layer:a,id:s,position:a.position},s))})};var ln=Object.getOwnPropertyDescriptor,un=(o,r,t,e)=>{for(var n=e>1?void 0:e?ln(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},pe=(o,r)=>(t,e)=>r(t,e,o);let ze=class extends c.Disposable{constructor(o,r,t,e,n,i,s){super(),this._sheetPrintInterceptorService=o,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._canvasFloatDomManagerService=n,this._componetManager=i,this._injector=s,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(o,r,t)=>{const{unitId:e,scene:n,subUnitId:i}=r,s=this._drawingManagerService.getDrawingDataForUnit(e),a=s==null?void 0:s[i];return a&&a.order.forEach(l=>{const g=a.data[l];g.drawingType!==c.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==c.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(o,r,t)=>{const{unitId:e,subUnitId:n}=r,i=this._renderManagerService.getRenderById(e);if(!i)return t(o);const s=i.with(b.SheetSkeletonManagerService).getSkeletonParam(n);if(!s)return t(o);const a=this._drawingManagerService.getDrawingDataForUnit(e),l=a==null?void 0:a[r.subUnitId];if(!l)return t(o);const{scaleX:g,scaleY:u}=i.scene,d=o?{...o}:{startColumn:0,endColumn:0,endRow:0,startRow:0},p=l.order.map(h=>l.data[h]);return p.length?(p.forEach(h=>{if(!h.groupId&&h.transform&&c.Tools.isDefine(h.transform.left)&&c.Tools.isDefine(h.transform.top)&&c.Tools.isDefine(h.transform.width)&&c.Tools.isDefine(h.transform.height)){const S=s.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),f=s.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});S.column<d.startColumn&&(d.startColumn=S.column),S.row<d.startRow&&(d.startRow=S.row),d.endRow<f.row&&(d.endRow=f.row),d.endColumn<f.column&&(d.endColumn=f.column)}}),t(d)):t(o)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(o,r,t)=>{const{unitId:e,subUnitId:n}=r,i=this._drawingManagerService.getDrawingDataForUnit(e),s=i==null?void 0:i[n];if(s){const a=s.order.map(g=>{const u=s.data[g];if(u.drawingType===c.DrawingTypeEnum.DRAWING_CHART)return{...u,componentKey:this._componetManager.get(c.PRINT_CHART_COMPONENT_KEY)};if(u.drawingType===c.DrawingTypeEnum.DRAWING_DOM){const d=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(d||u.componentKey)}}return null}).filter(Boolean),l=B.connectInjector(dn,this._injector);return q.render(J.jsx(l,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),o==null||o.add(()=>{q.unmount(r.root)}),t(o)}}}))}};ze=un([pe(0,c.Inject(b.SheetPrintInterceptorService)),pe(1,c.Inject(le.DrawingRenderService)),pe(2,W.IDrawingManagerService),pe(3,j.IRenderManagerService),pe(4,c.Inject(O.SheetCanvasFloatDomManagerService)),pe(5,c.Inject(B.ComponentManager)),pe(6,c.Inject(c.Injector))],ze);var gn=Object.getOwnPropertyDescriptor,hn=(o,r,t,e)=>{for(var n=e>1?void 0:e?gn(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},ue=(o,r)=>(t,e)=>r(t,e,o);const pn=[D.InsertRowCommand.id,D.InsertColCommand.id,D.RemoveRowCommand.id,D.RemoveColCommand.id,D.DeleteRangeMoveLeftCommand.id,D.DeleteRangeMoveUpCommand.id,D.InsertRangeMoveDownCommand.id,D.InsertRangeMoveRightCommand.id,D.DeltaRowHeightCommand.id,D.SetRowHeightCommand.id,D.DeltaColumnWidthCommand.id,D.SetColWidthCommand.id,D.SetRowHiddenCommand.id,D.SetSpecificRowsVisibleCommand.id,D.SetSpecificColsVisibleCommand.id,D.SetColHiddenCommand.id,D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id],mn=[D.SetRowVisibleMutation.id,D.SetRowHiddenMutation.id,D.SetColVisibleMutation.id,D.SetColHiddenMutation.id,D.SetWorksheetRowHeightMutation.id,D.SetWorksheetColWidthMutation.id];let mt=class extends c.Disposable{constructor(o,r,t,e,n,i,s,a,l){super(),this._context=o,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=i,this._sheetDrawingService=s,this._drawingManagerService=a,this._univerInstanceService=l,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:o=>{if(!pn.includes(o.id))return{redos:[],undos:[]};if(o.params==null)return{redos:[],undos:[]};const r=o.id;if(r===D.InsertRowCommand.id)return this._moveRowInterceptor(o.params,"insert");if([D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(o.params);if(r===D.InsertColCommand.id)return this._moveColInterceptor(o.params,"insert");if(r===D.RemoveRowCommand.id)return this._moveRowInterceptor(o.params,"remove");if(r===D.RemoveColCommand.id)return this._moveColInterceptor(o.params,"remove");if(r===D.DeleteRangeMoveLeftCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,0)}else if(r===D.DeleteRangeMoveUpCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,1)}else if(r===D.InsertRangeMoveDownCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,2)}else if(r===D.InsertRangeMoveRightCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,3)}else if(r===D.SetRowHiddenCommand.id||r===D.SetSpecificRowsVisibleCommand.id){const t=o.params,{unitId:e,subUnitId:n,ranges:i}=t;return this._getDrawingUndoForRowVisible(e,n,i)}else if(r===D.SetSpecificColsVisibleCommand.id||r===D.SetColHiddenCommand.id){const t=o.params,{unitId:e,subUnitId:n,ranges:i}=t;return this._getDrawingUndoForColVisible(e,n,i)}else if(r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id||r===D.DeltaColumnWidthCommand.id||r===D.SetColWidthCommand.id){const t=o.params,{unitId:e,subUnitId:n,ranges:i}=t,s=r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,i,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(o,r){const t=D.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,i=[],s=[],a=this._sheetDrawingService.getDrawingData(e,n),l=[],g=[];if(Object.keys(a).forEach(u=>{const d=a[u],{updateDrawings:p,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(o,r,d);l.push(...p),g.push(...h)}),l.length===0&&g.length===0)return{redos:[],undos:[]};if(l.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(l),{undo:d,redo:p,objects:h}=u;i.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.UPDATE}}),s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:d,objects:h,type:m.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),d=u.undo,p=u.redo,h=u.objects;i.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.REMOVE}}),s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:d,objects:h,type:m.DrawingApplyType.INSERT}})}return i.push({id:G.id,params:[e]}),s.push({id:G.id,params:[e]}),{redos:i,undos:s}}_getUpdateOrDeleteDrawings(o,r,t){const e=[],n=[],{sheetTransform:i,anchorType:s=m.SheetDrawingAnchorType.Position,transform:a,unitId:l,subUnitId:g,drawingId:u}=t,{from:d,to:p}=i,{row:h,column:S}=d,{row:f,column:w}=p;if(i==null||a==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:_,endRow:I,startColumn:C,endColumn:R}=o;let y=null,T=null;if(r===0&&h>=_&&f<=I)if(S>=C&&w<=R)n.push({unitId:l,subUnitId:g,drawingId:u});else{const v=this._shrinkCol(i,a,C,R,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}else if(r===1&&S>=C&&w<=R)if(h>=_&&f<=I)n.push({unitId:l,subUnitId:g,drawingId:u});else{const v=this._shrinkRow(i,a,_,I,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}else if(r===2){const v=this._expandRow(i,a,_,I,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}else if(r===3){const v=this._expandCol(i,a,C,R,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}if(y!=null&&T!=null){const v=x(y,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:y,transform:v})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(o,r,t){const e=H({...o},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(o,r,t){const e=this._drawingManagerService.getDrawingData(o,r),n=[],i=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:p,transform:h,anchorType:S=m.SheetDrawingAnchorType.Position}=d;if(S===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:f,to:w}=p,{row:_,column:I}=f,{row:C,column:R}=w;for(let y=0;y<t.length;y++){const T=t[y],{startRow:v,endRow:P,startColumn:E,endColumn:N}=T;if(R<E)continue;if(S===m.SheetDrawingAnchorType.Position){let M=null,Y=null;if(I>=E&&I<=N){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:N,startRow:f.row,endRow:w.row});if(L==null)return;Y={...h,left:L.startX}}if(Y!=null&&(M=H(Y,this._selectionRenderService),M!=null&&Y!=null)){n.push({...d,sheetTransform:M,transform:Y});break}this._remainDrawingSize(h,n,d);continue}if(I>=E&&R<=N)continue;let k=null,A=null;if(I>=E&&I<=N){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:N,startRow:f.row,endRow:w.row});if(M==null)return;A={...h,left:(M==null?void 0:M.startX)||0,width:((h==null?void 0:h.width)||0)-M.endX+M.startX}}else if(R>=E&&R<=N){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:R,startRow:f.row,endRow:w.row});if(M==null)return;A={...h,left:M.startX-((h==null?void 0:h.width)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:N,startRow:f.row,endRow:w.row});if(M==null)return;if(A={...h,width:((h==null?void 0:h.width)||0)-M.endX+M.startX},k=H(A,this._selectionRenderService),k!=null&&A!=null){i.push({...d,sheetTransform:k,transform:A});break}}if(A!=null&&(k=H(A,this._selectionRenderService)),A!=null&&k!=null){n.push({...d,sheetTransform:k,transform:A});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&i.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(o,r,n),l=[],g=[];if(i.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(o,r,i);l.push(...u),g.push(...d)}return{redos:s,undos:a,preRedos:l,preUndos:g}}_createUndoAndRedoMutation(o,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:i,objects:s}=e,a=[{id:m.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:r,op:i,objects:s,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[o]}],l=[{id:m.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:r,op:n,objects:s,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[o]}];return{redos:a,undos:l}}_getDrawingUndoForRowVisible(o,r,t){const e=this._drawingManagerService.getDrawingData(o,r),n=[],i=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:p,transform:h,anchorType:S=m.SheetDrawingAnchorType.Position}=d;if(S===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:f,to:w}=p,{row:_,column:I}=f,{row:C,column:R}=w;for(let y=0;y<t.length;y++){const T=t[y],{startRow:v,endRow:P,startColumn:E,endColumn:N}=T;if(C<v)continue;if(S===m.SheetDrawingAnchorType.Position){let M=null,Y=null;if(_>=v&&_<=P){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:P});if(L==null)return;Y={...h,top:L.startY}}if(Y!=null&&(M=H(Y,this._selectionRenderService),M!=null&&Y!=null)){n.push({...d,sheetTransform:M,transform:Y});break}this._remainDrawingSize(h,n,d);continue}if(_>=v&&C<=P)continue;let k=null,A=null;if(_>=v&&_<=P){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:P});if(M==null)return;A={...h,top:(M==null?void 0:M.startY)||0,height:((h==null?void 0:h.height)||0)-M.endY+M.startY}}else if(C>=v&&C<=P){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:v,endRow:C});if(M==null)return;A={...h,top:M.startY-((h==null?void 0:h.height)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:v,endRow:P});if(M==null)return;if(A={...h,height:((h==null?void 0:h.height)||0)-M.endY+M.startY},k=H(A,this._selectionRenderService),k!=null&&A!=null){i.push({...d,sheetTransform:k,transform:A});break}}if(A!=null&&(k=H(A,this._selectionRenderService)),A!=null&&k!=null){n.push({...d,sheetTransform:k,transform:A});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&i.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(o,r,n),l=[],g=[];if(i.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(o,r,i);l.push(...u),g.push(...d)}return{redos:s,undos:a,preRedos:l,preUndos:g}}_getDrawingUndoForRowAndColSize(o,r,t,e){const n=this._drawingManagerService.getDrawingData(o,r),i=[];return Object.keys(n).forEach(s=>{const a=n[s],{sheetTransform:l,transform:g,anchorType:u=m.SheetDrawingAnchorType.Position}=a;if(u===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,i,a);else{const{from:d,to:p}=l,{row:h,column:S}=d,{row:f,column:w}=p;for(let _=0;_<t.length;_++){const I=t[_],{startRow:C,endRow:R,startColumn:y,endColumn:T}=I;if(f<C||w<y)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=C&&f>=R||S<=y&&w>=T)){this._remainDrawingSize(g,i,a);continue}const v=x({...l},this._selectionRenderService,this._skeletonManagerService);if(v!=null){i.push({...a,transform:v});break}}}}),i.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(o,r,i)}_getUnitIdAndSubUnitId(o,r){let t,e;if(r==="insert")t=o.unitId,e=o.subUnitId;else{const n=D.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(o){var C,R;const{toRange:r,fromRange:t}=o,e=D.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:i}=e,s=(R=(C=this._renderManagerService.getRenderById(n))==null?void 0:C.with(b.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const a=b.attachRangeWithCoord(s,t);if(!a)return{redos:[],undos:[]};const{startX:l,endX:g,startY:u,endY:d}=a,p=this._sheetDrawingService.getDrawingData(n,i),h=[];Object.keys(p).forEach(y=>{const T=p[y];if(T.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:v}=T;if(!v)return;const{left:P=0,top:E=0,width:N=0,height:k=0}=v,{drawingStartX:A,drawingEndX:M,drawingStartY:Y,drawingEndY:L}={drawingStartX:P,drawingEndX:P+N,drawingStartY:E,drawingEndY:E+k};l<=A&&M<=g&&u<=Y&&L<=d&&h.push(T)});const S=[],f=[],w=r.startRow-t.startRow,_=r.startColumn-t.startColumn,I=h.map(y=>{const T=y.sheetTransform,v={to:{...T.to,row:T.to.row+w,column:T.to.column+_},from:{...T.from,row:T.from.row+w,column:T.from.column+_}},P=x(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:i,drawingId:y.drawingId,transform:P,sheetTransform:v}});if(I.length){const y=this._sheetDrawingService.getBatchUpdateOp(I),{undo:T,redo:v,objects:P}=y;S.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:v,objects:P,type:m.DrawingApplyType.UPDATE}}),f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:T,objects:P,type:m.DrawingApplyType.UPDATE}})}return{redos:S,undos:f}}_moveRowInterceptor(o,r){const t=this._getUnitIdAndSubUnitId(o,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:i}=o,s=i.startRow,a=i.endRow,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],p=[];if(Object.keys(u).forEach(h=>{const S=u[h],{sheetTransform:f,transform:w,anchorType:_=m.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let I,C;if(r==="insert"){const y=this._expandRow(f,w,s,a,_);I=y==null?void 0:y.newSheetTransform,C=y==null?void 0:y.newTransform}else{const{from:y,to:T}=f,{row:v}=y,{row:P}=T;if(_===m.SheetDrawingAnchorType.Both&&v>=s&&P<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkRow(f,w,s,a,_);I=E==null?void 0:E.newSheetTransform,C=E==null?void 0:E.newTransform}}if(!I||!C)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:I};d.push(R)}),d.length===0&&p.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:S,redo:f,objects:w}=h;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),S=h.undo,f=h.redo,w=h.objects;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:l,undos:g}}_moveColInterceptor(o,r){const t=this._getUnitIdAndSubUnitId(o,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:i}=o,s=i.startColumn,a=i.endColumn,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],p=[];if(Object.keys(u).forEach(h=>{const S=u[h],{sheetTransform:f,transform:w,anchorType:_=m.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let I,C;if(r==="insert"){const y=this._expandCol(f,w,s,a,_);I=y==null?void 0:y.newSheetTransform,C=y==null?void 0:y.newTransform}else{const{from:y,to:T}=f,{column:v}=y,{column:P}=T;if(_===m.SheetDrawingAnchorType.Both&&v>=s&&P<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkCol(f,w,s,a,_);I=E==null?void 0:E.newSheetTransform,C=E==null?void 0:E.newTransform}}if(!I||!C)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:I};d.push(R)}),d.length===0&&p.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:S,redo:f,objects:w}=h;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),S=h.undo,f=h.redo,w=h.objects;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:l,undos:g}}_expandCol(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{column:l}=s,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:s.row,endRow:a.row});if(p==null)return;d={...r,left:(r.left||0)+p.endX-p.startX},u=H(d,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g+i}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkCol(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{column:l}=s,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>e)u={from:{...s,column:l-i},to:{...a,column:g-i}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&g<=e)return null;if(l<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g-i}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)d={...r,left:(r.left||0)-o.from.columnOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:l-1,startRow:s.row,endRow:a.row});if(p==null)return;d={...r,left:(r.left||0)-p.endX+p.startX-o.from.columnOffset}}u=H(d,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:s.row,endRow:a.row});if(p==null)return;u={from:{...s},to:{...a,column:t-1,columnOffset:p.endX-p.startX}},d=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_expandRow(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{row:l}=s,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:s.column,endColumn:a.column});if(p==null)return;d={...r,top:(r.top||0)+p.endY-p.startY},u=H(d,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g+i}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkRow(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{row:l}=s,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>e)u={from:{...s,row:l-i},to:{...a,row:g-i}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&g<=e)return null;if(l<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g-i}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)d={...r,top:(r.top||0)-o.from.rowOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:l-1,startColumn:s.column,endColumn:a.column});if(p==null)return;d={...r,top:(r.top||0)-p.endY+p.startY-o.from.rowOffset}}u=H(d,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:t-1,endRow:t-1});if(p==null)return;u={from:{...s},to:{...a,row:t-1,rowOffset:p.endY-p.startY}},d=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{if(o.id===D.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:t}=o.params;this._updateDrawings(r,t)}})),this.disposeWithMe(this._context.activated$.subscribe(o=>{const{unit:r,unitId:t}=this._context;if(o){const e=r.getActiveSheet().getSheetId();this._updateDrawings(t,e)}else this._clearDrawings(t)}))}_clearDrawings(o){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,t=[];Object.keys(r).forEach(e=>{const n=r[e];n!=null&&Object.keys(n).forEach(i=>{const s=n[i].data;s!=null&&Object.keys(s).forEach(a=>{e===o&&t.push(s[a])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(o,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(i=>{const s=t[i];s!=null&&Object.keys(s).forEach(a=>{const l=s[a].data;l!=null&&Object.keys(l).forEach(g=>{if(i===o&&a===r){const u=l[g];u.transform=x(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(l[g])}else n.push(l[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{mn.includes(o.id)&&requestIdleCallback(()=>{const r=o.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(o,r,t){const e=this._drawingManagerService.getDrawingData(o,r),n=[];Object.keys(e).forEach(i=>{const s=e[i],{sheetTransform:a,transform:l,anchorType:g=m.SheetDrawingAnchorType.Position}=s;if(g===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=a,{row:p,column:h}=u,{row:S,column:f}=d;for(let w=0;w<t.length;w++){const _=t[w],{startRow:I,endRow:C,startColumn:R,endColumn:y}=_;if(c.Rectangle.intersects({startRow:I,endRow:C,startColumn:R,endColumn:y},{startRow:p,endRow:S,startColumn:h,endColumn:f})||p>C||h>y){const T=g===m.SheetDrawingAnchorType.Position,v=x(a,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...v,width:T?l==null?void 0:l.width:v==null?void 0:v.width,height:T?l==null?void 0:l.height:v==null?void 0:v.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[o]))}};mt=hn([ue(1,j.IRenderManagerService),ue(2,c.ICommandService),ue(3,b.ISheetSelectionRenderService),ue(4,c.Inject(b.SheetSkeletonManagerService)),ue(5,c.Inject(D.SheetInterceptorService)),ue(6,m.ISheetDrawingService),ue(7,W.IDrawingManagerService),ue(8,c.IUniverInstanceService)],mt);const ft={id:"sheet.command.delete-drawing",type:c.CommandType.COMMAND,handler:o=>{const r=o.get(c.ICommandService),e=o.get(m.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,i=e.map(s=>{const{unitId:a,subUnitId:l,drawingId:g,drawingType:u}=s;return{unitId:a,subUnitId:l,drawingId:g,drawingType:u}});return r.executeCommand(fe.id,{unitId:n,drawings:i})}},we={id:"sheet.command.move-drawing",type:c.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(c.ICommandService),e=o.get(m.ISheetDrawingService),n=o.get(b.ISheetSelectionRenderService),{direction:i}=r,s=e.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,l=s.map(u=>{const{transform:d}=u;if(d==null)return null;const p={...d},{left:h=0,top:S=0}=d;return i===c.Direction.UP?p.top=S-1:i===c.Direction.DOWN?p.top=S+1:i===c.Direction.LEFT?p.left=h-1:i===c.Direction.RIGHT&&(p.left=h+1),{...u,transform:p,sheetTransform:H(p,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(Re.id,{unitId:a,drawings:l})?(t.syncExecuteCommand(G.id,[a]),!0):!1}},fn=o=>{var I;const r=B.useDependency(c.ICommandService),t=B.useDependency(c.LocaleService),e=B.useDependency(W.IDrawingManagerService),n=B.useDependency(j.IRenderManagerService),{drawings:i}=o,s=i[0];if(s==null)return;const{unitId:a}=s,l=n.getRenderById(a),g=l==null?void 0:l.scene;if(g==null)return;const u=g.getTransformerByCreate(),[d,p]=me.useState(!0),h=(I=s.anchorType)!=null?I:m.SheetDrawingAnchorType.Position,[S,f]=me.useState(h);function w(C,R){const y=[];return C.forEach(T=>{const{oKey:v}=T,P=R.getDrawingOKey(v);if(P==null)return y.push(null),!0;const{unitId:E,subUnitId:N,drawingId:k,drawingType:A,anchorType:M,sheetTransform:Y}=P;y.push({unitId:E,subUnitId:N,drawingId:k,anchorType:M,sheetTransform:Y,drawingType:A})}),y}me.useEffect(()=>{const C=u.clearControl$.subscribe(y=>{y===!0&&p(!1)}),R=u.changeStart$.subscribe(y=>{var P;const{objects:T}=y,v=w(T,e);if(v.length===0)p(!1);else if(v.length>=1){p(!0);const E=((P=v[0])==null?void 0:P.anchorType)||m.SheetDrawingAnchorType.Position;f(E)}});return()=>{R.unsubscribe(),C.unsubscribe()}},[]);function _(C){f(C);const R=e.getFocusDrawings();if(R.length===0)return;const y=R.map(T=>({unitId:T.unitId,subUnitId:T.subUnitId,drawingId:T.drawingId,anchorType:C}));r.executeCommand(Re.id,{unitId:R[0].unitId,drawings:y})}return J.jsxs("div",{className:q.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!d}),children:[J.jsx("header",{className:"univer-text-gray-600 dark:!univer-text-gray-200",children:J.jsx("div",{children:t.t("drawing-anchor.title")})}),J.jsx("div",{children:J.jsxs(q.RadioGroup,{value:S,onChange:_,direction:"vertical",children:[J.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),J.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),J.jsx(q.Radio,{value:m.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})]})},Sn=()=>{const o=B.useDependency(W.IDrawingManagerService),r=o.getFocusDrawings(),[t,e]=me.useState(r);return me.useEffect(()=>{const n=o.focus$.subscribe(i=>{e(i)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&J.jsxs("div",{className:"univer-text-sm",children:[J.jsx(le.DrawingCommonPanel,{drawings:t}),J.jsx(fn,{drawings:t})]})},St="sheet.menu.image";function wn(o){return{id:St,type:B.MenuItemType.SUBITEMS,icon:"AddImageIcon",tooltip:"sheetImage.title",hidden$:B.getMenuHiddenObservable(o,c.UniverInstanceType.UNIVER_SHEET),disabled$:b.getCurrentRangeDisable$(o,{workbookTypes:[D.WorkbookEditablePermission],worksheetTypes:[D.WorksheetEditPermission],rangeTypes:[D.RangeProtectionPermissionEditPoint]})}}function _n(o){return{id:be.id,title:"sheetImage.upload.float",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(o,c.UniverInstanceType.UNIVER_SHEET)}}function vn(o){return{id:pt.id,title:"sheetImage.upload.cell",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(o,c.UniverInstanceType.UNIVER_SHEET)}}const In={[B.RibbonInsertGroup.MEDIA]:{[St]:{order:0,menuItemFactory:wn,[be.id]:{order:0,menuItemFactory:_n},[pt.id]:{order:1,menuItemFactory:vn}}}};function Ue(o){return!o.getContextValue(c.FOCUSING_FX_BAR_EDITOR)&&!o.getContextValue(c.EDITOR_ACTIVATED)&&!o.getContextValue(c.FOCUSING_PANEL_EDITOR)&&o.getContextValue(c.FOCUSING_COMMON_DRAWINGS)}const yn={id:we.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:B.KeyCode.ARROW_DOWN,priority:100,preconditions:Ue,staticParameters:{direction:c.Direction.DOWN}},Dn={id:we.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:B.KeyCode.ARROW_UP,priority:100,preconditions:Ue,staticParameters:{direction:c.Direction.UP}},Cn={id:we.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:B.KeyCode.ARROW_LEFT,priority:100,preconditions:Ue,staticParameters:{direction:c.Direction.LEFT}},Mn={id:we.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:B.KeyCode.ARROW_RIGHT,priority:100,preconditions:Ue,staticParameters:{direction:c.Direction.RIGHT}},Tn={id:ft.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:Ue,binding:B.KeyCode.DELETE,mac:B.KeyCode.BACKSPACE};var Rn=Object.getOwnPropertyDescriptor,En=(o,r,t,e)=>{for(var n=e>1?void 0:e?Rn(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},_e=(o,r)=>(t,e)=>r(t,e,o);let xe=class extends c.Disposable{constructor(o,r,t,e,n,i){super(),this._componentManager=o,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=i,this._init()}_initCustomComponents(){const o=this._componentManager;this.disposeWithMe(o.register(yt,Sn))}_initMenus(){this._menuManagerService.mergeMenu(In)}_initCommands(){[be,pt,Te,fe,Re,st,G,at,lt,gt,we,ft,ut].forEach(o=>this.disposeWithMe(this._commandService.registerCommand(o)))}_initShortcuts(){[yn,Dn,Cn,Mn,Tn].forEach(o=>{this.disposeWithMe(this._shortcutService.registerShortcut(o))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};xe=En([_e(0,c.Inject(B.ComponentManager)),_e(1,B.IMenuManagerService),_e(2,c.ICommandService),_e(3,B.IShortcutService),_e(4,W.IDrawingManagerService),_e(5,c.Inject(D.SheetsSelectionsService))],xe);var bn=Object.defineProperty,On=Object.getOwnPropertyDescriptor,An=(o,r,t)=>r in o?bn(o,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[r]=t,Pn=(o,r,t,e)=>{for(var n=e>1?void 0:e?On(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},wt=(o,r)=>(t,e)=>r(t,e,o),Et=(o,r,t)=>An(o,typeof r!="symbol"?r+"":r,t);const Un="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends c.Plugin{constructor(r=It,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:i,...s}=c.merge({},It,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Nt,s)}onStarting(){c.registerDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService],[xe],[Be],[ze],[Xe],[He],[$e],[Le],[Ge]]),c.touchDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService]])}onReady(){c.touchDependencies(this._injector,[[He],[Ge]])}onRendered(){this._registerRenderModules(),c.touchDependencies(this._injector,[[Xe],[ze],[xe],[$e],[Le]])}onSteady(){this._injector.get(Be)}_registerRenderModules(){[[O.SheetDrawingUpdateController],[mt],[dt],[ct]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(c.UniverInstanceType.UNIVER_SHEET,r))})}},Et(O.UniverSheetsDrawingUIPlugin,"type",c.UniverInstanceType.UNIVER_SHEET),Et(O.UniverSheetsDrawingUIPlugin,"pluginName",Un),O.UniverSheetsDrawingUIPlugin=Pn([c.DependentOn(W.UniverDrawingPlugin,ge.UniverDocsDrawingPlugin,le.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),wt(1,c.Inject(c.Injector)),wt(2,j.IRenderManagerService),wt(3,c.IConfigService)],O.UniverSheetsDrawingUIPlugin),O.ClearSheetDrawingTransformerOperation=G,O.DeleteDrawingsCommand=ft,O.EditSheetDrawingOperation=at,O.GroupSheetDrawingCommand=lt,O.InsertFloatImageCommand=be,O.InsertSheetDrawingCommand=Te,O.MoveDrawingsCommand=we,O.RemoveSheetDrawingCommand=fe,O.SHEETS_IMAGE_MENU_ID=St,O.SetDrawingArrangeCommand=ut,O.SetSheetDrawingCommand=Re,O.SidebarSheetDrawingOperation=st,O.UngroupSheetDrawingCommand=gt,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
1
+ (function(O,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets"),require("@univerjs/engine-render"),require("@univerjs/design"),require("@univerjs/docs-ui"),require("@univerjs/drawing"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("@univerjs/docs-drawing"),require("@univerjs/drawing-ui"),require("rxjs"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-drawing","@univerjs/sheets","@univerjs/engine-render","@univerjs/design","@univerjs/docs-ui","@univerjs/drawing","@univerjs/sheets-ui","@univerjs/ui","@univerjs/docs-drawing","@univerjs/drawing-ui","rxjs","react/jsx-runtime","react"],c):(O=typeof globalThis<"u"?globalThis:O||self,c(O.UniverSheetsDrawingUi={},O.UniverCore,O.UniverSheetsDrawing,O.UniverSheets,O.UniverEngineRender,O.UniverDesign,O.UniverDocsUi,O.UniverDrawing,O.UniverSheetsUi,O.UniverUi,O.UniverDocsDrawing,O.UniverDrawingUi,O.rxjs,O.React,O.React))})(this,function(O,c,m,D,j,q,We,W,b,B,vt,le,U,J,pe){"use strict";var jn=Object.defineProperty;var Bn=(O,c,m)=>c in O?jn(O,c,{enumerable:!0,configurable:!0,writable:!0,value:m}):O[c]=m;var re=(O,c,m)=>Bn(O,typeof c!="symbol"?c+"":c,m);const G={id:"sheet.operation.clear-drawing-transformer",type:c.CommandType.MUTATION,handler:(o,r)=>{const t=o.get(j.IRenderManagerService);return r.forEach(e=>{var n,i;(i=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||i.debounceRefreshControls()}),!0}},me={id:"sheet.command.remove-sheet-image",type:c.CommandType.COMMAND,handler:(o,r)=>{var I,C,R;const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService),n=o.get(D.SheetInterceptorService),i=o.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,a=[];s.forEach(y=>{const{unitId:T}=y;a.push(T)});const l=i.getBatchRemoveOp(s),{unitId:g,subUnitId:u,undo:d,redo:p,objects:h}=l,S=n.onCommandExecute({id:me.id,params:r}),f={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:p,objects:h,type:m.DrawingApplyType.REMOVE}},w={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:d,objects:h,type:m.DrawingApplyType.INSERT}};return c.sequenceExecute([...(I=S.preRedos)!=null?I:[],f,...S.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=S.preUndos)!=null?C:[],w,...S.undos,{id:G.id,params:a}],redoMutations:[...(R=S.preRedos)!=null?R:[],f,...S.redos,{id:G.id,params:a}]}),!0):!1}},ot={id:"sheet.command.delete-drawing",type:c.CommandType.COMMAND,handler:o=>{const r=o.get(c.ICommandService),e=o.get(m.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,i=e.map(s=>{const{unitId:a,subUnitId:l,drawingId:g,drawingType:u}=s;return{unitId:a,subUnitId:l,drawingId:g,drawingType:u}});return r.executeCommand(me.id,{unitId:n,drawings:i})}};function Nt(o){const r=[];return o.forEach(t=>{const{parent:e,children:n}=t,{unitId:i,subUnitId:s,drawingId:a}=e,l=j.getGroupState(0,0,n.map(d=>d.transform||{})),g=n.map(d=>{const p=d.transform||{left:0,top:0},{unitId:h,subUnitId:S,drawingId:f}=d;return{unitId:h,subUnitId:S,drawingId:f,transform:{...p,left:p.left-l.left,top:p.top-l.top},groupId:a}}),u={unitId:i,subUnitId:s,drawingId:a,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:l};r.push({parent:u,children:g})}),r}function kt(o){const r=[];return o.forEach(t=>{const{parent:e,children:n}=t,{unitId:i,subUnitId:s,drawingId:a,transform:l={width:0,height:0}}=e;if(l==null)return;const g=n.map(d=>{const{transform:p}=d,{unitId:h,subUnitId:S,drawingId:f}=d,w=j.transformObjectOutOfGroup(p||{},l,l.width||0,l.height||0);return{unitId:h,subUnitId:S,drawingId:f,transform:w,groupId:void 0}}),u={unitId:i,subUnitId:s,drawingId:a,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const st={id:"sheet.command.group-sheet-image",type:c.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService),n=o.get(m.ISheetDrawingService);if(!r)return!1;const i=[];r.forEach(({parent:h,children:S})=>{i.push(h.unitId),S.forEach(f=>{i.push(f.unitId)})});const s=n.getGroupDrawingOp(r),{unitId:a,subUnitId:l,undo:g,redo:u,objects:d}=s;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:l,objects:d,type:m.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:l,objects:kt(d),type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:i}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:l,objects:d,type:m.DrawingApplyType.GROUP}},{id:G.id,params:i}]}),!0):!1}};function x(o,r,t){const{from:e,to:n,flipY:i=!1,flipX:s=!1,angle:a=0,skewX:l=0,skewY:g=0}=o,u=t.getCurrent();if(u==null)return;const d=b.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:p,top:h,width:S,height:f}=d;const w=t.getCurrentSkeleton(),_=w.rowHeaderWidth+w.columnTotalWidth,I=w.columnHeaderHeight+w.rowTotalHeight;return p+S>_&&(p=_-S),h+f>I&&(h=I-f),{flipY:i,flipX:s,angle:a,skewX:l,skewY:g,left:p,top:h,width:S,height:f}}function H(o,r){const{left:t=0,top:e=0,width:n=0,height:i=0,flipY:s=!1,flipX:a=!1,angle:l=0,skewX:g=0,skewY:u=0}=o,d=r.getCellWithCoordByOffset(t,e);if(d==null)return;const p={column:d.actualColumn,columnOffset:j.precisionTo(t-d.startX,1),row:d.actualRow,rowOffset:j.precisionTo(e-d.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+i);if(h==null)return;const S={column:h.actualColumn,columnOffset:j.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:j.precisionTo(e+i-h.startY,1)};return{flipY:s,flipX:a,angle:l,skewX:g,skewY:u,from:p,to:S}}const Me={id:"sheet.command.insert-sheet-image",type:c.CommandType.COMMAND,handler:(o,r)=>{var I,C,R;const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService),n=o.get(m.ISheetDrawingService),i=o.get(D.SheetInterceptorService);if(!r)return!1;const s=r.drawings,a=s.map(y=>y.unitId),l=n.getBatchAddOp(s),{unitId:g,subUnitId:u,undo:d,redo:p,objects:h}=l,S=i.onCommandExecute({id:Me.id,params:r}),f={id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT}},w={id:m.SetDrawingApplyMutation.id,params:{op:d,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.REMOVE}};return c.sequenceExecute([...(I=S.preRedos)!=null?I:[],f,...S.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=S.preUndos)!=null?C:[],w,...S.undos,{id:G.id,params:a}],redoMutations:[...(R=S.preRedos)!=null?R:[],f,...S.redos,{id:G.id,params:a}]}),!0):!1}},at={id:"sheet.command.set-drawing-arrange",type:c.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService);if(!r)return!1;const n=o.get(m.ISheetDrawingService),{unitId:i,subUnitId:s,drawingIds:a,arrangeType:l}=r,g={unitId:i,subUnitId:s,drawingIds:a};let u;if(l===c.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):l===c.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):l===c.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):l===c.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:d,redo:p,undo:h}=u;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:p,unitId:i,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:i,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:i,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:i,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}},Te={id:"sheet.command.set-sheet-image",type:c.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService),n=o.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:i}=r,s=n.getBatchUpdateOp(i),{unitId:a,subUnitId:l,undo:g,redo:u,objects:d}=s;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:a,subUnitId:l,op:u,objects:d,type:m.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:l,op:g,objects:d,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:l,op:u,objects:d,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}]}),!0):!1}},ct={id:"sheet.command.ungroup-sheet-image",type:c.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService),n=o.get(m.ISheetDrawingService);if(!r)return!1;const i=[];r.forEach(({parent:h,children:S})=>{i.push(h.unitId),S.forEach(f=>{i.push(f.unitId)})});const s=n.getUngroupDrawingOp(r),{unitId:a,subUnitId:l,undo:g,redo:u,objects:d}=s;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:l,objects:d,type:m.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:l,objects:Nt(d),type:m.DrawingApplyType.GROUP}},{id:G.id,params:i}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:l,objects:d,type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:i}]}),!0):!1}};var Wt=Object.getOwnPropertyDescriptor,jt=(o,r,t,e)=>{for(var n=e>1?void 0:e?Wt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Q=(o,r)=>(t,e)=>r(t,e,o);function Bt(o,r,t){const e=t*Math.PI/180,n=Math.abs(o*Math.cos(e))+Math.abs(r*Math.sin(e)),i=Math.abs(o*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:i}}function dt(o,r,t,e,n){var I;const{rotatedHeight:i,rotatedWidth:s}=Bt(t,e,n),l=o.get(j.IRenderManagerService).getRenderById(r.unitId);if(!l)return!1;const u=(I=l.with(b.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:I.skeleton;if(u==null)return!1;const d=u.getCellByIndex(r.row,r.col),p=d.mergeInfo.endX-d.mergeInfo.startX-2,h=d.mergeInfo.endY-d.mergeInfo.startY-2,S=s/i,w=Math.ceil(Math.min(p,h*S))/s,_=!w||Number.isNaN(w)?.001:w;return{width:t*_,height:e*_}}O.SheetDrawingUpdateController=class extends c.Disposable{constructor(t,e,n,i,s,a,l,g,u,d,p,h,S){super();re(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=i,this._imageIoService=s,this._fileOpenerService=a,this._sheetDrawingService=l,this._drawingManagerService=g,this._contextService=u,this._messageService=d,this._localeService=p,this._injector=S,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const t=await this._fileOpenerService.openFile({multiple:!0,accept:W.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),e=t.length;return e>W.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(W.DRAWING_IMAGE_COUNT_LIMIT))}),!1):e===0?!1:(t.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const e=(await this._fileOpenerService.openFile({multiple:!1,accept:W.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(t,e){return this._insertCellImage(t,e)}async insertFloatImageByFile(t){let e;try{e=await this._imageIoService.saveImage(t)}catch(C){const R=C.message;R===W.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(W.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):R===W.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):R===W.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const n=this._getUnitInfo(),{unitId:i,subUnitId:s}=n,{imageId:a,imageSourceType:l,source:g,base64Cache:u}=e,{width:d,height:p,image:h}=await W.getImageSize(u||""),{width:S,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(g,l,h);let w=1;if(d>W.DRAWING_IMAGE_WIDTH_LIMIT||p>W.DRAWING_IMAGE_HEIGHT_LIMIT){const C=W.DRAWING_IMAGE_WIDTH_LIMIT/d,R=W.DRAWING_IMAGE_HEIGHT_LIMIT/p;w=Math.max(C,R)}const _=this._getImagePosition(d*w,p*w,S,f);if(_==null)return;const I={unitId:i,subUnitId:s,drawingId:a,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:g,transform:x(_,this._selectionRenderService,this._skeletonManagerService),sheetTransform:_};return this._commandService.executeCommand(Me.id,{unitId:i,drawings:[I]})}async _insertCellImage(t,e){var R,y;let n;try{n=await this._imageIoService.saveImage(t)}catch(T){const v=T.message;v===W.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(W.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):v===W.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):v===W.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:i,imageSourceType:s,source:a,base64Cache:l}=n,{width:g,height:u,image:d}=await W.getImageSize(l||"");this._imageIoService.addImageSourceCache(a,s,d);const p=this._workbookSelections.getCurrentLastSelection();if(!p)return!1;let h=p.primary.actualRow,S=p.primary.actualColumn;p.primary.isMerged&&(h=p.primary.startRow,S=p.primary.startColumn);const f=c.createDocumentModelWithStyle("",{}),w=dt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:h,col:S},g,u,0);if(!w)return!1;const _={size:{width:w.width,height:w.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},I={unitId:f.getUnitId(),subUnitId:f.getUnitId(),drawingId:i,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:We.docDrawingPositionToTransform(_),docTransform:_,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},C=c.BuildTextUtils.drawing.add({documentDataModel:f,drawings:[I],selection:{collapsed:!0,startOffset:0,endOffset:0}});return C?(f.apply(C),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(R=e==null?void 0:e.row)!=null?R:h]:{[(y=e==null?void 0:e.col)!=null?y:S]:{p:f.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,S;const{width:n,height:i,image:s}=await W.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,c.ImageSourceType.URL,s);const a=this._workbookSelections.getCurrentLastSelection();if(!a)return!1;const l=c.createDocumentModelWithStyle("",{}),g=dt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:a.primary.actualRow,col:a.primary.actualColumn},n,i,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},d={unitId:l.getUnitId(),subUnitId:l.getUnitId(),drawingId:c.generateRandomId(),drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c.ImageSourceType.URL,source:t,transform:We.docDrawingPositionToTransform(u),docTransform:u,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},p=c.BuildTextUtils.drawing.add({documentDataModel:l,drawings:[d],selection:{collapsed:!0,startOffset:0,endOffset:0}});return p?(l.apply(p),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(h=e==null?void 0:e.row)!=null?h:a.primary.actualRow]:{[(S=e==null?void 0:e.col)!=null?S:a.primary.actualColumn]:{p:l.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}_getUnitInfo(){const t=this._context.unit,e=t.getActiveSheet(),n=t.getUnitId(),i=e.getSheetId();return{unitId:n,subUnitId:i}}_getImagePosition(t,e,n,i){const s=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};s&&s.length>0&&(a=s[s.length-1].range);const l=b.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(l==null)return;let{startColumn:g,startRow:u,startX:d,startY:p}=l,h=!1;if(d+t>n&&(d=n-t,d<0&&(d=0,t=n),h=!0),p+e>i&&(p=i-e,p<0&&(p=0,e=i),h=!0),h){const _=this._selectionRenderService.getCellWithCoordByOffset(d,p);if(_==null)return;d=_.startX,p=_.startY,g=_.actualColumn,u=_.actualRow}const S={column:g,columnOffset:0,row:u,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(d+t,p+e);if(f==null)return;const w={column:f.actualColumn,columnOffset:d+t-f.startX,row:f.actualRow,rowOffset:p+e-f.startY};return{from:S,to:w}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:i,arrangeType:s}=t;this._commandService.executeCommand(at.id,{unitId:e,subUnitId:n,drawingIds:i,arrangeType:s})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:i,subUnitId:s,drawingId:a,drawingType:l,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:i,subUnitId:s,drawingId:a});if(u==null||u.unitId!==this._context.unitId)return;const d=H({...u.transform,...g},this._selectionRenderService);if(d==null)return;const p={...n,transform:{...u.transform,...g,...x(d,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...d}};e.push(p)}),e.length>0&&this._commandService.executeCommand(Te.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(st.id,t);const{unitId:e,subUnitId:n,drawingId:i}=t[0].parent;this._commandService.syncExecuteCommand(W.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:i}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(ct.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}},O.SheetDrawingUpdateController=jt([Q(1,c.Inject(b.SheetSkeletonManagerService)),Q(2,c.ICommandService),Q(3,b.ISheetSelectionRenderService),Q(4,W.IImageIoService),Q(5,B.ILocalFileService),Q(6,m.ISheetDrawingService),Q(7,W.IDrawingManagerService),Q(8,c.IContextService),Q(9,B.IMessageService),Q(10,c.Inject(c.LocaleService)),Q(11,c.Inject(D.SheetsSelectionsService)),Q(12,c.Inject(c.Injector))],O.SheetDrawingUpdateController);const Re={id:"sheet.command.insert-float-image",type:c.CommandType.COMMAND,handler:async(o,r)=>{var s,a;const t=o.get(c.IUniverInstanceService),e=o.get(j.IRenderManagerService),n=(s=j.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:s.with(O.SheetDrawingUpdateController);if(!n)return!1;const i=r==null?void 0:r.files;if(i){const l=i.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(l)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},lt={id:"sheet.command.insert-cell-image",type:c.CommandType.COMMAND,handler:o=>{var e,n;const r=o.get(c.IUniverInstanceService),t=o.get(j.IRenderManagerService);return(n=(e=j.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,r,t))==null?void 0:e.with(O.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}},fe={id:"sheet.command.move-drawing",type:c.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(c.ICommandService),e=o.get(m.ISheetDrawingService),n=o.get(b.ISheetSelectionRenderService),{direction:i}=r,s=e.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,l=s.map(u=>{const{transform:d}=u;if(d==null)return null;const p={...d},{left:h=0,top:S=0}=d;return i===c.Direction.UP?p.top=S-1:i===c.Direction.DOWN?p.top=S+1:i===c.Direction.LEFT?p.left=h-1:i===c.Direction.RIGHT&&(p.left=h+1),{...u,transform:p,sheetTransform:H(p,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(Te.id,{unitId:a,drawings:l})?(t.syncExecuteCommand(G.id,[a]),!0):!1}},It="COMPONENT_SHEET_DRAWING_PANEL",ut={id:"sidebar.operation.sheet-image",type:c.CommandType.COMMAND,handler:async(o,r)=>{const t=o.get(B.ISidebarService),e=o.get(c.LocaleService),n=o.get(c.IUniverInstanceService),i=o.get(c.ICommandService);if(!D.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:It},onClose:()=>{i.syncExecuteCommand(W.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},gt={id:"sheet.operation.edit-sheet-image",type:c.CommandType.OPERATION,handler:(o,r)=>{const t=o.get(c.ICommandService);return r==null?!1:(t.syncExecuteCommand(W.SetDrawingSelectedOperation.id,[r]),t.executeCommand(ut.id,{value:"open"}),!0)}},Yt="sheets-drawing-ui.config",yt={};var Ft=Object.getOwnPropertyDescriptor,$t=(o,r,t,e)=>{for(var n=e>1?void 0:e?Ft(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},ie=(o,r)=>(t,e)=>r(t,e,o);let je=class extends c.RxDisposable{constructor(r,t,e,n,i,s,a,l,g,u){super();re(this,"_initImagePopupMenu",new Set);this._injector=r,this._localeService=t,this._drawingManagerService=e,this._canvasPopManagerService=n,this._renderManagerService=i,this._univerInstanceService=s,this._messageService=a,this._contextService=l,this._ioService=g,this._commandService=u,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(U.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(c.UniverInstanceType.UNIVER_SHEET).pipe(U.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(c.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._setupLoadingStatus()}_setupLoadingStatus(){const r="image-upload-loading";let t;this.disposeWithMe(this._ioService.change$.subscribe(e=>{e>0&&!t?t=this._messageService.show({id:r,type:q.MessageType.Loading,content:`${this._localeService.t("uploadLoading.loading")}: ${e}`,duration:0}):e===0&&(t==null||t.dispose(),t=void 0)}))}_dispose(r){super.dispose();const t=r.getUnitId();this._renderManagerService.removeRender(t)}_create(r){if(!r)return;const t=r.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(r){const t=r.getAllObjectsByOrder();for(const e of t)if(e instanceof le.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var i;const t=(i=this._renderManagerService.getRenderById(r))==null?void 0:i.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const s=e.getSelectedObjectMap();if(s.size>1){n==null||n.dispose();return}const a=s.values().next().value;if(!a)return;const l=a.oKey,g=this._drawingManagerService.getDrawingOKey(l);if(!g)return;const{unitId:u,subUnitId:d,drawingId:p,drawingType:h}=g,S=g.data;if(S&&S.disablePopup)return;n==null||n.dispose();const f=this._canvasPopManagerService.getFeatureMenu(u,d,p,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:le.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:f||this._getImageMenuItems(u,d,p,h)}}))})),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(W.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(s=>{s[c.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:gt.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:me.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:le.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:le.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===c.DrawingTypeEnum.DRAWING_DOM}]}};je=$t([ie(0,c.Inject(c.Injector)),ie(1,c.Inject(c.LocaleService)),ie(2,W.IDrawingManagerService),ie(3,c.Inject(b.SheetCanvasPopManagerService)),ie(4,j.IRenderManagerService),ie(5,c.IUniverInstanceService),ie(6,B.IMessageService),ie(7,c.IContextService),ie(8,c.IImageIoService),ie(9,c.ICommandService)],je);var Lt=Object.getOwnPropertyDescriptor,Gt=(o,r,t,e)=>{for(var n=e>1?void 0:e?Lt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Be=(o,r)=>(t,e)=>r(t,e,o);let ht=class extends c.Disposable{constructor(r,t,e,n,i){super();re(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=t,this._selectionsService=e,this._drawingRenderService=n,this._sheetSkeletonManagerService=i,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(U.throttleTime(33)).subscribe(r=>{var e,n;let t=[];r!==null&&(t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),t.length>0&&(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&t.length===1&&((e=t[0].primary)==null?void 0:e.actualRow)===r.row&&((n=t[0].primary)==null?void 0:n.actualColumn)===r.col?(this._isSetCursor=!0,this._context.scene.setCursor(j.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(r=>{var t;if(r!=null&&r.drawing&&this._isSetCursor){const e=r.drawing.drawing.drawingOrigin,n=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap.getImage(e.imageSourceType,e.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};ht=Gt([Be(1,c.Inject(b.HoverManagerService)),Be(2,c.Inject(D.SheetsSelectionsService)),Be(3,c.Inject(le.DrawingRenderService)),Be(4,c.Inject(b.SheetSkeletonManagerService))],ht);var Ht=Object.getOwnPropertyDescriptor,Xt=(o,r,t,e)=>{for(var n=e>1?void 0:e?Ht(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Ye=(o,r)=>(t,e)=>r(t,e,o);let pt=class extends c.Disposable{constructor(o,r,t,e,n){super(),this._context=o,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const o=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in o){const t=o[r];for(const e in t.data){const n=t.data[e];n.sheetTransform&&(n.transform=x(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService))}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};pt=Xt([Ye(1,m.ISheetDrawingService),Ye(2,W.IDrawingManagerService),Ye(3,c.Inject(b.ISheetSelectionRenderService)),Ye(4,c.Inject(b.SheetSkeletonManagerService))],pt);var Vt=Object.getOwnPropertyDescriptor,Kt=(o,r,t,e)=>{for(var n=e>1?void 0:e?Vt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Se=(o,r)=>(t,e)=>r(t,e,o);function Dt(o,r,t){var e,n,i,s;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((s=(i=t.p)==null?void 0:i.drawingsOrder)==null?void 0:s.length)===1){const a=t.p.drawings[t.p.drawingsOrder[0]],l=dt(o,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},a.docTransform.size.width,a.docTransform.size.height,a.docTransform.angle);if(l)return a.transform.width=l.width,a.transform.height=l.height,a.docTransform.size.width=l.width,a.docTransform.size.height=l.height,a.transform.left=0,a.transform.top=0,a.docTransform.positionH.posOffset=0,a.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let Fe=class extends c.Disposable{constructor(o,r,t,e,n,i){super(),this._commandService=o,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=i,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(o=>{o.visible?o.visible&&(this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(o=>{o.id===We.ReplaceSnapshotCommand.id&&o.params.unitId===c.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(D.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:D.InterceptCellContentPriority.CELL_IMAGE,handler:(o,r,t)=>{var e;return o!=null&&o.p&&((e=o.p.drawingsOrder)!=null&&e.length)&&(o===r.rawData&&(o={...r.rawData}),o.interceptorStyle||(o.interceptorStyle={}),o.interceptorStyle.tr={a:0},Dt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},o)),t(o)}}))}};Fe=Kt([Se(0,c.ICommandService),Se(1,c.Inject(D.SheetInterceptorService)),Se(2,c.Inject(c.Injector)),Se(3,W.IDrawingManagerService),Se(4,c.Inject(vt.DocDrawingController)),Se(5,c.Inject(b.IEditorBridgeService))],Fe);var zt=Object.getOwnPropertyDescriptor,xt=(o,r,t,e)=>{for(var n=e>1?void 0:e?zt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Ct=(o,r)=>(t,e)=>r(t,e,o);let $e=class extends c.Disposable{constructor(o,r){super(),this._autoFillService=o,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(o,r,t,e)=>{new c.ObjectMatrix(e).forValue((n,i,s)=>{Dt(this._injector,{unitId:o.unitId,subUnitId:o.subUnitId,row:n,col:i},s)})}}))}};$e=xt([Ct(0,c.Inject(b.IAutoFillService)),Ct(1,c.Inject(c.Injector))],$e);var qt=Object.getOwnPropertyDescriptor,Zt=(o,r,t,e)=>{for(var n=e>1?void 0:e?qt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Ee=(o,r)=>(t,e)=>r(t,e,o);const Jt=[c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,c.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,c.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let Le=class extends c.Disposable{constructor(o,r,t,e,n){super(),this._commandService=o,this._univerInstanceService=r,this._dialogService=t,this._renderManagerService=e,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(o){var n;const r=c.createDocumentModelWithStyle("",{}),t=(n=j.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(b.EditingRenderController),e=c.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[o],selection:{collapsed:!0,startOffset:0,endOffset:0}});e&&(r.apply(e),t&&t.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(o=>{var r,t;if(o.id===We.InnerPasteCommand.id){const e=o.params,{doc:n}=e,i=this._univerInstanceService.getCurrentUnitOfType(c.UniverInstanceType.UNIVER_DOC);if(i==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const s=i.getUnitId();if(Jt.includes(s)){if(s!==c.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const a=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(b.SetCellEditVisibleOperation.id,{visible:!1})};((t=i.getBody())==null?void 0:t.dataStream)===`\r
2
+ `?(this._commandService.syncExecuteCommand(b.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(n.drawings)[0])):this._dialogService.open({id:"sheet-cell-image-copy-paste",title:{label:this._localeService.t("cell-image.pasteTitle")},children:{label:this._localeService.t("cell-image.pasteContent")},width:320,destroyOnClose:!0,onClose:a,showOk:!0,showCancel:!0,onOk:()=>{a(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:a})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};Le=Zt([Ee(0,c.ICommandService),Ee(1,c.IUniverInstanceService),Ee(2,B.IDialogService),Ee(3,j.IRenderManagerService),Ee(4,c.Inject(c.LocaleService))],Le);var Qt=Object.getOwnPropertyDescriptor,en=(o,r,t,e)=>{for(var n=e>1?void 0:e?Qt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},be=(o,r)=>(t,e)=>r(t,e,o);const Mt="image/png";function tn(o){const r=o.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let i=0;i<e;i++)n[i]=t.charCodeAt(i);return new Blob([n],{type:Mt})}function nn(o){const r=new ClipboardItem({[Mt]:tn(o)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function rn(){function o(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const r=document.activeElement,t=o();return document.body.appendChild(t),t.focus(),()=>{t.blur(),document.body.removeChild(t),r instanceof HTMLElement&&r.focus()}}const Tt=[b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let Ge=class extends c.Disposable{constructor(r,t,e,n,i){super();re(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=i,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const i=this._focusedDrawings;if(i.length>0){const[s]=i;if(n===b.COPY_TYPE.CUT){const l={unitId:r,drawings:[s]};this._commandService.executeCommand(me.id,l)}setTimeout(()=>{const l=rn();s.drawingType===c.DrawingTypeEnum.DRAWING_IMAGE&&s.imageSourceType===W.ImageSourceType.BASE64?nn(s.source):this._clipboardInterfaceService.writeText(""),l()},200);const a={unitId:s.unitId,subUnitId:s.subUnitId,drawings:[s]};this._copyInfo=a}else{const s=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=s}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:i=b.COPY_TYPE.COPY,pasteType:s}=n,{range:a}=r||{},{range:l,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:s,unitId:g,subUnitId:u,pasteRange:l},{copyRange:a,copyType:i}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:s},b.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.COPY_TYPE.COPY);{const e=t.filter(n=>n.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Re.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var p;const n=(p=this._renderManagerService.getRenderById(r))==null?void 0:p.with(b.SheetSkeletonManagerService);if(!n)return;const i=n.attachRangeWithCoord(e);if(!i)return;const{startX:s,endX:a,startY:l,endY:g}=i,u=this._drawingService.getDrawingData(r,t),d=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const S=u[h],{transform:f}=S;if(S.anchorType!==m.SheetDrawingAnchorType.Both||!f)return;const{left:w=0,top:_=0,width:I=0,height:C=0}=f,{drawingStartX:R,drawingEndX:y,drawingStartY:T,drawingEndY:v}={drawingStartX:w,drawingEndX:w+I,drawingStartY:_,drawingEndY:_+C};s<=R&&y<=a&&l<=T&&v<=g&&d.push(S)}),d.length)return{copyRange:e,drawings:d,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Tt.includes(e))return{redos:[],undos:[]};const{unitId:i,subUnitId:s,range:a}=n,l=this._renderManagerService.getRenderById(i),g=l==null?void 0:l.with(b.SheetSkeletonManagerService),u=l==null?void 0:l.with(b.ISheetSelectionRenderService),d=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:p}=d,h=b.discreteRangeToRange(a);return this._generateMutations(p,{unitId:i,subUnitId:s,isCut:t===b.COPY_TYPE.CUT,getTransform:(S,f)=>{var I;const w=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),_={...S,left:w==null?void 0:w.startX,top:w==null?void 0:w.startY};return{transform:_,sheetTransform:(I=H(_,u))!=null?I:f}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:i,isCut:s}=t,a=[],l=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:d,sheetTransform:p}=u;if(!d)return;const h=i(d,p),S={...u,unitId:e,subUnitId:n,drawingId:s?u.drawingId:c.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(s){const{undo:f,redo:w,objects:_}=g.getBatchUpdateOp([S]);a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:w,objects:_}}),l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:f,objects:_}})}else{const{undo:f,redo:w,objects:_}=g.getBatchAddOp([S]);a.push({id:m.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.INSERT}}),l.push({id:m.SetDrawingApplyMutation.id,params:{op:f,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.REMOVE}})}}),{redos:a,undos:l}}_generateRangeDrawingsPasteMutations(r,t){var P;const{unitId:e,subUnitId:n,pasteType:i,pasteRange:s}=r,{copyRange:a,copyType:l}=t;if(Tt.includes(i))return{redos:[],undos:[]};const g=(P=this._renderManagerService.getRenderById(e))==null?void 0:P.with(b.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:b.discreteRangeToRange(s)},pasteType:i},l);const{ranges:[d,p],mapFunc:h}=b.virtualizeDiscreteRanges([a,s]),{row:S,col:f}=h(d.startRow,d.startColumn),{row:w,col:_}=h(p.startRow,p.startColumn),I=g.attachRangeWithCoord({startRow:S,endRow:S,startColumn:f,endColumn:f}),C=g.attachRangeWithCoord({startRow:w,endRow:w,startColumn:_,endColumn:_});if(!I||!C||!this._copyInfo)return{redos:[],undos:[]};const R=C.startX-I.startX,y=C.startY-I.startY,T=w-S,v=_-f;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(E,N)=>{var k,A;return{transform:{...E,left:((k=E==null?void 0:E.left)!=null?k:0)+R,top:((A=E==null?void 0:E.top)!=null?A:0)+y},sheetTransform:{...N,to:{...N.to,row:N.to.row+T,column:N.to.column+v},from:{...N.from,row:N.from.row+T,column:N.from.column+v}}}},isCut:l===b.COPY_TYPE.CUT})}};Ge=en([be(0,b.ISheetClipboardService),be(1,j.IRenderManagerService),be(2,W.IDrawingManagerService),be(3,B.IClipboardInterfaceService),be(4,c.ICommandService)],Ge);var on=Object.getOwnPropertyDescriptor,sn=(o,r,t,e)=>{for(var n=e>1?void 0:e?on(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Oe=(o,r)=>(t,e)=>r(t,e,o);let He=class extends c.Disposable{constructor(o,r,t,e,n){super(),this._drawingManagerService=o,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=U.combineLatest([o,r]);this.disposeWithMe(t.pipe(U.switchMap(([e,n])=>e?e.activeSheet$.pipe(U.tap(i=>{if(!i){this._drawingManagerService.setDrawingVisible(!1);return}const s=e.getUnitId(),a=i.getSheetId();this._permissionService.composePermission([new D.WorkbookViewPermission(s).id,new D.WorksheetViewPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,i)})):(this._drawingManagerService.setDrawingVisible(!1),U.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(o,r){this._drawingManagerService.setDrawingVisible(!1);const t=o.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),i=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===j.RENDER_CLASS_TYPE.IMAGE&&i.some(u=>g.oKey.includes(u.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=U.combineLatest([o,r]);this.disposeWithMe(t.pipe(U.switchMap(([e,n])=>e?e.activeSheet$.pipe(U.tap(i=>{if(!i){this._drawingManagerService.setDrawingEditable(!1);return}const s=e.getUnitId(),a=i.getSheetId();this._permissionService.composePermission([new D.WorkbookEditablePermission(s).id,new D.WorksheetEditPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,i)})):(this._drawingManagerService.setDrawingEditable(!1),U.EMPTY))).subscribe())}_handleDrawingEditableFalse(o,r){this._drawingManagerService.setDrawingEditable(!1);const t=o.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),i=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===j.RENDER_CLASS_TYPE.IMAGE&&i.some(u=>g.oKey.includes(u.drawingId))&&a.detachTransformerFrom(g)})}_initViewPermissionChange(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(U.combineLatest([o,r]).pipe(U.switchMap(([t,e])=>t?t.activeSheet$.pipe(U.switchMap(n=>{if(!n)return U.EMPTY;const i=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(i),l=a==null?void 0:a.scene;if(!l)return U.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookViewPermission(i).id,new D.WorksheetViewPermission(i,s).id]).pipe(U.map(d=>d.every(p=>p.value)),U.distinctUntilChanged()).pipe(U.map(d=>({permission:d,scene:l,transformer:g,unitId:i,subUnitId:s})))})):U.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:i,subUnitId:s})=>{this._drawingManagerService.setDrawingVisible(t);const a=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(i,s),g=Object.values(l);t?this._drawingManagerService.addNotification(g):(a.forEach(u=>{u.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),i=e==null?void 0:e.getSheetId();if(!n||!i)return;const s=this._drawingManagerService.getDrawingData(n,i),a=Object.values(s);this._drawingManagerService.addNotification(a)}}))}_initEditPermissionChange(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(U.combineLatest([o,r]).pipe(U.switchMap(([t,e])=>t?t.activeSheet$.pipe(U.switchMap(n=>{if(!n)return U.EMPTY;const i=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(i),l=a==null?void 0:a.scene;if(!l)return U.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookEditablePermission(i).id,new D.WorksheetEditPermission(i,s).id]).pipe(U.map(d=>d.every(p=>p.value)),U.distinctUntilChanged()).pipe(U.map(d=>({permission:d,scene:l,transformer:g,unitId:i,subUnitId:s})))})):U.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:i,subUnitId:s})=>{this._drawingManagerService.setDrawingEditable(t);const a=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(i,s),g=Object.values(l);t?(a.forEach(u=>{u.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(a.forEach(u=>{u.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const i=n.getSheetId(),s=this._renderManagerService.getRenderById(e),a=s==null?void 0:s.scene;if(!a)return;const l=this._drawingManagerService.getDrawingData(e,i),g=Object.values(l);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(d=>{d.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(p=>d.oKey.includes(p.drawingId))&&a.detachTransformerFrom(d)})}}))}};He=sn([Oe(0,W.IDrawingManagerService),Oe(1,j.IRenderManagerService),Oe(2,c.IPermissionService),Oe(3,c.IUniverInstanceService),Oe(4,c.Inject(c.UserManagerService))],He);var an=Object.getOwnPropertyDescriptor,cn=(o,r,t,e)=>{for(var n=e>1?void 0:e?an(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},ge=(o,r)=>(t,e)=>r(t,e,o);function Rt(o,r,t,e,n,i=!1){const{scaleX:s,scaleY:a}=r.getAncestorScale(),l=r.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=e.getFreeze(),{startColumn:u,startRow:d,xSplit:p,ySplit:h}=g,S={left:!0,top:!0};if(!l)return{...o,absolute:S};const{left:f,right:w,top:_,bottom:I}=o;let{top:C,left:R,viewportScrollX:y,viewportScrollY:T}=l;const{boundsOfViewArea:v,scrollDirectionResponse:P}=n||{},{rowHeaderWidth:E,columnHeaderHeight:N}=t,k={top:i?0:N,left:i?0:E};v&&(c.Tools.isDefine(k.top)&&(k.top=v.top),c.Tools.isDefine(k.left)&&(k.left=v.left)),P==="HORIZONTAL"&&(T=0),P==="VERTICAL"&&(y=0);let A=0,M=0;const Y=t.rowStartY(d-h)+N,L=t.colStartX(u-p)+E,Z=t.rowStartY(d)+N,ee=t.colStartX(u)+E;if(p===0)S.left=!1,A=(f-y)*s,M=(w-y)*s;else{const K=f-(L-E),F=w-(L-E);w<ee?(A=K*s,M=F*s):f<=ee&&w>=ee?(A=K*s,M=Math.max(R,(w-y)*s)):f>ee&&(S.left=!1,A=Math.max((f-y)*s,R),M=Math.max((w-y)*s,R))}let V=0,z=0;if(h===0)S.top=!1,V=(_-T)*a,z=(I-T)*a;else{const K=_-(Y-N),F=I-(Y-N);I<Z?(V=K*a,z=F*a):_<=Z&&I>=Z?(V=K*a,z=Math.max(C,(I-T)*a)):_>Z&&(S.top=!1,V=Math.max((_-T)*a,C),z=Math.max((I-T)*a,C))}return A=Math.max(A,k.left),V=Math.max(V,k.top),M=Math.max(M,k.left),z=Math.max(z,k.top),{left:A,right:M,top:V,bottom:z,absolute:S}}const oe=(o,r,t,e,n)=>{const{left:i,top:s,width:a,height:l,angle:g}=o,u={left:i,right:i+a,top:s,bottom:s+l},d=Rt(u,r,t,e,n),{scaleX:p,scaleY:h}=r.getAncestorScale();return{startX:d.left,endX:d.right,startY:d.top,endY:d.bottom,rotate:g,width:a*p,height:l*h,absolute:d.absolute}};O.SheetCanvasFloatDomManagerService=class extends c.Disposable{constructor(t,e,n,i,s,a,l){super();re(this,"_domLayerInfoMap",new Map);re(this,"_transformChange$",new U.Subject);re(this,"transformChange$",this._transformChange$.asObservable());re(this,"_add$",new U.Subject);re(this,"add$",this._add$.asObservable());re(this,"_remove$",new U.Subject);re(this,"remove$",this._remove$.asObservable());this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=i,this._canvasFloatDomService=s,this._sheetDrawingService=a,this._lifecycleService=l,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(U.filter(t=>t===c.LifecycleStages.Rendered),U.take(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}getFloatDomsBySubUnitId(t,e){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===e&&n.unitId===t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const i=n.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:n,transformer:i,renderUnit:e,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var K;const{unitId:n,subUnitId:i,drawingId:s}=e,a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,c.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!l||!a)return;const d=(K=this._renderManagerService.getRenderById(n))==null?void 0:K.with(b.SheetSkeletonManagerService).getSkeletonParam(i);if(!d)return;const{transform:p,drawingType:h,data:S}=l;if(h!==c.DrawingTypeEnum.DRAWING_DOM&&h!==c.DrawingTypeEnum.DRAWING_CHART)return;const f=this._getSceneAndTransformerByDrawingSearch(n);if(f==null)return;const{scene:w,canvas:_}=f;if(p==null)return!0;if(u!==i)return;const{left:I,top:C,width:R,height:y,angle:T,flipX:v,flipY:P,skewX:E,skewY:N}=p,k=W.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:i,drawingId:s}),A=w.getObject(k);if(A!=null){A.transformByState({left:I,top:C,width:R,height:y,angle:T,flipX:v,flipY:P,skewX:E,skewY:N});return}const M={left:I,top:C,width:R,height:y,zIndex:this._drawingManagerService.getDrawingOrder(n,i).length-1},Y=h===c.DrawingTypeEnum.DRAWING_CHART;if(M.rotateEnabled=!1,Y){const F=S?S.backgroundColor:"white";M.fill=F,S&&S.border&&(M.stroke=S.border),M.paintFirst="stroke",M.strokeWidth=1,M.borderEnabled=!1,M.radius=8}const L=new j.Rect(k,M);Y&&L.setObjectType(j.ObjectType.CHART),w.addObject(L,j.DRAWING_OBJECT_LAYER_INDEX),l.allowTransform!==!1&&w.attachTransformerTo(L);const Z=new c.DisposableCollection,ee=oe(L,f.renderUnit.scene,d.skeleton,a.worksheet),V=new U.BehaviorSubject(ee),z={dispose:Z,rect:L,position$:V,unitId:n,subUnitId:i,id:s};this._canvasFloatDomService.addFloatDom({position$:V,id:s,componentKey:l.componentKey,onPointerDown:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onWheel:F=>{_.dispatchEvent(new WheelEvent(F.type,F))},data:S,unitId:n});const te=L.onTransformChange$.subscribeEvent(()=>{const F=oe(L,f.renderUnit.scene,d.skeleton,a.worksheet);V.next(F)});Z.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),te&&Z.add(te),this._domLayerInfoMap.set(s,z)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{var p;const{unitId:n,subUnitId:i,drawingId:s}=e,a=W.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:i,drawingId:s}),l=this._getSceneAndTransformerByDrawingSearch(n);if(l==null)return;const{transformer:g,scene:u}=l,d=u.getObject(a);d!=null&&d.oKey&&(g.clearControlByIds([d==null?void 0:d.oKey]),(p=u.getTransformer())==null||p.clearSelectedObjects())})}))}_scrollUpdateListener(){const t=(e,n)=>{var g;const i=this._getSceneAndTransformerByDrawingSearch(e),s=Array.from(this._domLayerInfoMap.keys()).map(u=>({id:u,...this._domLayerInfoMap.get(u)})).filter(u=>u.subUnitId===n&&u.unitId===e).map(u=>u.id),a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),l=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(b.SheetSkeletonManagerService).getSkeletonParam(n);!i||!a||!l||s.forEach(u=>{const d=this._domLayerInfoMap.get(u);if(d){const p=oe(d.rect,i.renderUnit.scene,l.skeleton,a.worksheet,d);d.position$.next(p)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(U.switchMap(e=>e?e.activeSheet$:U.of(null)),U.map(e=>{if(!e)return null;const n=e.getUnitId(),i=this._renderManagerService.getRenderById(n);return i?{render:i,unitId:n,subUnitId:e.getSheetId()}:null}),U.switchMap(e=>e?c.fromEventSubject(e.render.scene.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(U.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):U.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:i}=e;t(n,i)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===b.SetZoomRatioOperation.id){const n=e.params,{unitId:i}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===i).map(a=>a.subUnitId).forEach(a=>{t(i,a)})}else if(e.id===D.SetFrozenMutation.id){const{unitId:n,subUnitId:i}=e.params;t(n,i)}}))}_getPosition(t,e){var h;const{startX:n,endX:i,startY:s,endY:a}=t,l=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(b.ISheetSelectionRenderService);if(l==null)return;const g=l.getCellWithCoordByOffset(n,s);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:s-g.startY},d=l.getCellWithCoordByOffset(i,a);if(d==null)return;const p={column:d.actualColumn,columnOffset:i-d.startX,row:d.actualRow,rowOffset:a-d.startY};return{from:u,to:p}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==c.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==c.DrawingTypeEnum.DRAWING_CHART)return;const i={...n.transform};this._transformChange$.next({id:e.drawingId,value:i})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,i){const s=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(t);if(s&&a){const{scene:l}=a,g=W.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=l.getObject(g);u&&u instanceof j.Rect&&u.setProps(i)}}addFloatDomToPosition(t,e){const n=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:i,subUnitId:s}=n,{initPosition:a,componentKey:l,data:g,allowTransform:u=!0}=t,d=e!=null?e:c.generateRandomId(),p=this._getPosition(a,i);if(p==null)return;const h={unitId:i,subUnitId:s,drawingId:d,drawingType:t.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:p,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Me.id,{unitId:i,drawings:[h]}),this._add$.next({unitId:i,subUnitId:s,id:d}),{id:d,dispose:()=>{this._removeDom(d,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:i,subUnitId:s}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(i);if(a&&a.scene.removeObject(n.rect),e){const l=this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:s,drawingId:t});if(!l)return;const g=this._sheetDrawingService.getBatchRemoveOp([l]),{redo:u,objects:d}=g;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:i,subUnitId:s,op:u,objects:d,type:m.DrawingApplyType.REMOVE})}}addFloatDomToRange(t,e,n,i){var v,P,E;const s=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:l}=s,g=this._getSceneAndTransformerByDrawingSearch(a);if(!g)return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const d=(v=this._renderManagerService.getRenderById(a))==null?void 0:v.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:p,data:h,allowTransform:S=!0}=e,f=i!=null?i:c.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver(t,u,d.skeleton);if(this._getPosition(w,a)==null)return;const C=g.scene,{scaleX:R}=C.getAncestorScale(),y=Xe(w,n,R),T={unitId:a,subUnitId:l,drawingId:f,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:y.startX,top:y.startY,width:y.width,height:y.height},data:h,allowTransform:S};{const{unitId:N,subUnitId:k,drawingId:A}=T,M=D.getSheetCommandTarget(this._univerInstanceService,{unitId:N,subUnitId:k}),Y=T,L=this._univerInstanceService.getUnit(N,c.UniverInstanceType.UNIVER_SHEET);if(!L)return;const Z=L.getActiveSheet().getSheetId();if(!Y||!M)return;const ee=(P=this._renderManagerService.getRenderById(N))==null?void 0:P.with(b.SheetSkeletonManagerService);if(!ee)return;const V=ee.getWorksheetSkeleton(k);if(!V)return;const{transform:z,drawingType:te,data:K}=Y;if(te!==c.DrawingTypeEnum.DRAWING_DOM&&te!==c.DrawingTypeEnum.DRAWING_CHART)return;const F=this._getSceneAndTransformerByDrawingSearch(N);if(F==null)return;const{scene:_e,canvas:ve}=F;if(z==null||Z!==k)return;const{left:xe,top:qe,width:Ze,height:Je,angle:wt,flipX:_t,flipY:Qe,skewX:et,skewY:Ie}=z,tt=W.getDrawingShapeKeyByDrawingSearch({unitId:N,subUnitId:k,drawingId:A}),se=_e.getObject(tt);if(se!=null){se.transformByState({left:xe,top:qe,width:Ze,height:Je,angle:wt,flipX:_t,flipY:Qe,skewX:et,skewY:Ie});return}const ne={left:xe,top:qe,width:Ze,height:Je,zIndex:this._drawingManagerService.getDrawingOrder(N,k).length-1},ye=te===c.DrawingTypeEnum.DRAWING_CHART;if(ye){const $=K?K.backgroundColor:"white";ne.fill=$,ne.rotateEnabled=!1,K&&K.border&&(ne.stroke=K.border),ne.paintFirst="stroke",ne.strokeWidth=1,ne.borderEnabled=!1,ne.radius=8}const ae=new j.Rect(tt,ne);ye&&ae.setObjectType(j.ObjectType.CHART),_e.addObject(ae,j.DRAWING_OBJECT_LAYER_INDEX),Y.allowTransform!==!1&&_e.attachTransformerTo(ae);const ce=new c.DisposableCollection,nt=_e.getMainViewport(),{rowHeaderWidth:De,columnHeaderHeight:Ue}=V.skeleton,rt={top:Ue,left:De,bottom:nt.bottom,right:nt.right},de={dispose:ce,rect:ae,boundsOfViewArea:rt,domAnchor:n,unitId:N,subUnitId:k},X=oe(ae,F.renderUnit.scene,V.skeleton,M.worksheet,de),Ce=new U.BehaviorSubject(X);de.position$=Ce;let Ne={position$:Ce,id:A,componentKey:Y.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{ve.dispatchEvent(new WheelEvent($.type,$))},data:K,unitId:N};e.eventPassThrough&&(Ne={...Ne,onPointerDown:$=>{ve.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{ve.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{ve.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(Ne),this.disposeWithMe(_.subscribe($=>{var Ot,At,Pt,Ut;const bt=Xe({startX:$.startX,startY:$.startY,endX:$.endX,endY:$.endY,width:(Ot=n.width)!=null?Ot:$.width,height:(At=n.height)!=null?At:$.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Nn=W.getDrawingShapeKeyByDrawingSearch({unitId:N,subUnitId:k,drawingId:A}),kn=new j.Rect(Nn,{left:bt.startX,top:bt.startY,width:(Pt=n.width)!=null?Pt:$.width,height:(Ut=n.height)!=null?Ut:$.height,zIndex:this._drawingManagerService.getDrawingOrder(N,k).length-1}),Wn=oe(kn,F.renderUnit.scene,V.skeleton,M.worksheet,de);Ce.next(Wn)}));const ke=(E=this._renderManagerService.getRenderById(N))==null?void 0:E.with(b.SheetSkeletonManagerService);ke==null||ke.currentSkeleton$.subscribe($=>{$&&V.sheetId!==$.sheetId&&this._removeDom(f,!0)});const it=ae.onTransformChange$.subscribeEvent(()=>{const $=oe(ae,F.renderUnit.scene,V.skeleton,M.worksheet,de);Ce.next($)});ce.add(()=>{this._canvasFloatDomService.removeFloatDom(A)}),it&&ce.add(it),this._domLayerInfoMap.set(A,de)}return{id:f,dispose:()=>{this._removeDom(f,!0)}}}addFloatDomToColumnHeader(t,e,n,i){var y,T,v;const s=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:l}=s;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const d=(y=this._renderManagerService.getRenderById(a))==null?void 0:y.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:p,data:h,allowTransform:S=!0}=e,f=i!=null?i:c.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,d.skeleton),I=w;if(I.startY=0,this._getPosition(w,a)==null)return;const R={unitId:a,subUnitId:l,drawingId:f,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:h,allowTransform:S};{const{unitId:P,subUnitId:E,drawingId:N}=R,k=D.getSheetCommandTarget(this._univerInstanceService,{unitId:P,subUnitId:E}),A=R,M=this._univerInstanceService.getUnit(P,c.UniverInstanceType.UNIVER_SHEET);if(!M)return;const Y=M.getActiveSheet().getSheetId();if(!A||!k)return;const L=(T=this._renderManagerService.getRenderById(P))==null?void 0:T.with(b.SheetSkeletonManagerService);if(!L)return;const Z=L.getWorksheetSkeleton(E);if(!Z)return;const{transform:ee,data:V}=A,z=this._getSceneAndTransformerByDrawingSearch(P);if(z==null)return;const{scene:te,canvas:K}=z;if(ee==null||Y!==E)return;const{left:F,top:_e,width:ve,height:xe,angle:qe,flipX:Ze,flipY:Je,skewX:wt,skewY:_t}=ee,Qe=W.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:E,drawingId:N}),et=te.getObject(Qe);if(et!=null){et.transformByState({left:F,top:_e,width:ve,height:xe,angle:qe,flipX:Ze,flipY:Je,skewX:wt,skewY:_t});return}const Ie=Xe({startX:I.startX,startY:0,endX:w.endX,endY:w.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),tt={left:Ie.startX,top:Ie.startY,width:Ie.width,height:Ie.height,zIndex:this._drawingManagerService.getDrawingOrder(P,E).length-1},se=new j.Rect(Qe,tt);te.addObject(se,j.DRAWING_OBJECT_LAYER_INDEX),A.allowTransform!==!1&&te.attachTransformerTo(se);const ne=new c.DisposableCollection,ye=te.getMainViewport(),ae={top:0,left:ye.left,bottom:ye.bottom,right:ye.right},ce={dispose:ne,rect:se,unitId:P,subUnitId:E,boundsOfViewArea:ae,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},nt=oe(se,z.renderUnit.scene,Z.skeleton,k.worksheet,ce),De=new U.BehaviorSubject(nt);ce.position$=De;let Ue={position$:De,id:N,componentKey:A.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:X=>{K.dispatchEvent(new WheelEvent(X.type,X))},data:V,unitId:P};e.eventPassThrough&&(Ue={...Ue,onPointerDown:X=>{K.dispatchEvent(new PointerEvent(X.type,X))},onPointerMove:X=>{K.dispatchEvent(new PointerEvent(X.type,X))},onPointerUp:X=>{K.dispatchEvent(new PointerEvent(X.type,X))}}),this._canvasFloatDomService.addFloatDom(Ue);const rt=se.onTransformChange$.subscribeEvent(()=>{const X=oe(se,z.renderUnit.scene,Z.skeleton,k.worksheet,ce);De.next(X)});this.disposeWithMe(_.subscribe(X=>{const Ce=Xe({startX:X.startX,startY:0,endX:X.endX,endY:X.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Ne=W.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:E,drawingId:N}),ke=new j.Rect(Ne,{left:Ce.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(P,E).length-1}),it=oe(ke,z.renderUnit.scene,Z.skeleton,k.worksheet,ce);De.next(it)}));const de=(v=this._renderManagerService.getRenderById(P))==null?void 0:v.with(b.SheetSkeletonManagerService);de==null||de.currentSkeleton$.subscribe(X=>{X&&d.sheetId!==X.sheetId&&this._removeDom(f,!0)}),ne.add(()=>{this._canvasFloatDomService.removeFloatDom(N)}),rt&&ne.add(rt),this._domLayerInfoMap.set(N,ce)}return{id:f,dispose:()=>{this._removeDom(f,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:i,startColumn:s}=t;const a=Ae(i,s,n),l=new U.BehaviorSubject(a),g=Ae(t.endRow,t.endColumn,n),u=new U.BehaviorSubject(g),d=()=>{const _=Ae(i,s,n),I=Ae(t.endRow,t.endColumn,n);l.next(_),u.next(I)},p=new c.DisposableCollection;p.add(e.engine.clientRect$.subscribe(()=>d())),p.add(this._commandService.onCommandExecuted(_=>{if(_.id===D.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(C=>C.row===i)>-1){d();return}(D.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===b.SetScrollOperation.id||_.id===b.SetZoomRatioOperation.id)&&d()}));const h=(_,I)=>{i=_,s=I,d()},S=()=>({rotate:0,width:g.right-a.left,height:g.bottom-a.top,absolute:{left:!0,top:!0},startX:a.left,startY:a.top,endX:g.right,endY:g.bottom}),f=l.pipe(U.map(_=>{const I=Ae(t.endRow,t.endColumn,n);return{rotate:0,width:I.right-_.left,height:I.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:I.right,endY:I.bottom}})),w=S();return{position$:f,position:w,updateRowCol:h,topLeftPos$:l,rightBottomPos$:u,disposable:p}}},O.SheetCanvasFloatDomManagerService=cn([ge(0,c.Inject(j.IRenderManagerService)),ge(1,c.IUniverInstanceService),ge(2,c.Inject(c.ICommandService)),ge(3,W.IDrawingManagerService),ge(4,c.Inject(B.CanvasFloatDomService)),ge(5,m.ISheetDrawingService),ge(6,c.Inject(c.LifecycleService))],O.SheetCanvasFloatDomManagerService);function Ae(o,r,t){const e=t.getCellWithCoordByIndex(o,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Xe(o,r,t){var g,u;t=t!=null?t:1;const e=o.endX-o.startX,n=o.endY-o.startY,i=(g=r==null?void 0:r.width)!=null?g:e,s=(u=r==null?void 0:r.height)!=null?u:n;let a=0,l=0;if(r){if(r.horizonOffsetAlign==="right"){const d=Ve(r.marginX,e*t);a=o.endX-d-i}else a=o.startX+Ve(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const d=Ve(r.marginY,n*t);l=o.endY-d-s}else l=o.startY+Ve(r.marginY,n)}return{rotate:0,startX:a,startY:l,endX:o.endX,endY:o.endY,width:i,height:s,absolute:{left:o.absolute.left,top:o.absolute.top}}}function Ve(o,r){if(o===void 0)return 0;if(typeof o=="number")return o;const t=Number.parseFloat(o);return r*t/100}const dn=o=>{const{floatDomInfos:r,scene:t,skeleton:e,worksheet:n}=o,i=pe.useMemo(()=>r.map(s=>{const{width:a,height:l,angle:g,left:u,top:d}=s.transform,p=Rt({left:u!=null?u:0,right:(u!=null?u:0)+(a!=null?a:0),top:d!=null?d:0,bottom:(d!=null?d:0)+(l!=null?l:0)},t,e,n,void 0,!0),{scaleX:h,scaleY:S}=t.getAncestorScale(),f={startX:p.left,endX:p.right,startY:p.top,endY:p.bottom,rotate:g,width:a*h,height:l*S,absolute:p.absolute},w={position$:new U.BehaviorSubject(f),position:f,id:s.drawingId,componentKey:s.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:s.unitId,data:s.data};return[s.drawingId,w]}),[r,t,e,n]);return J.jsx("div",{style:{position:"absolute",top:0,left:0},children:i.map(([s,a])=>J.jsx(B.PrintFloatDomSingle,{layer:a,id:s,position:a.position},s))})};var ln=Object.getOwnPropertyDescriptor,un=(o,r,t,e)=>{for(var n=e>1?void 0:e?ln(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},he=(o,r)=>(t,e)=>r(t,e,o);let Ke=class extends c.Disposable{constructor(o,r,t,e,n,i,s){super(),this._sheetPrintInterceptorService=o,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._canvasFloatDomManagerService=n,this._componetManager=i,this._injector=s,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(o,r,t)=>{const{unitId:e,scene:n,subUnitId:i}=r,s=this._drawingManagerService.getDrawingDataForUnit(e),a=s==null?void 0:s[i];return a&&a.order.forEach(l=>{const g=a.data[l];g.drawingType!==c.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==c.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(o,r,t)=>{const{unitId:e,subUnitId:n}=r,i=this._renderManagerService.getRenderById(e);if(!i)return t(o);const s=i.with(b.SheetSkeletonManagerService).getSkeletonParam(n);if(!s)return t(o);const a=this._drawingManagerService.getDrawingDataForUnit(e),l=a==null?void 0:a[r.subUnitId];if(!l)return t(o);const{scaleX:g,scaleY:u}=i.scene,d=o?{...o}:{startColumn:0,endColumn:0,endRow:0,startRow:0},p=l.order.map(h=>l.data[h]);return p.length?(p.forEach(h=>{if(!h.groupId&&h.transform&&c.Tools.isDefine(h.transform.left)&&c.Tools.isDefine(h.transform.top)&&c.Tools.isDefine(h.transform.width)&&c.Tools.isDefine(h.transform.height)){const S=s.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),f=s.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});S.column<d.startColumn&&(d.startColumn=S.column),S.row<d.startRow&&(d.startRow=S.row),d.endRow<f.row&&(d.endRow=f.row),d.endColumn<f.column&&(d.endColumn=f.column)}}),t(d)):t(o)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(o,r,t)=>{const{unitId:e,subUnitId:n}=r,i=this._drawingManagerService.getDrawingDataForUnit(e),s=i==null?void 0:i[n];if(s){const a=s.order.map(g=>{const u=s.data[g];if(u.drawingType===c.DrawingTypeEnum.DRAWING_CHART)return{...u,componentKey:this._componetManager.get(c.PRINT_CHART_COMPONENT_KEY)};if(u.drawingType===c.DrawingTypeEnum.DRAWING_DOM){const d=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(d||u.componentKey)}}return null}).filter(Boolean),l=B.connectInjector(dn,this._injector);return q.render(J.jsx(l,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),o==null||o.add(()=>{q.unmount(r.root)}),t(o)}}}))}};Ke=un([he(0,c.Inject(b.SheetPrintInterceptorService)),he(1,c.Inject(le.DrawingRenderService)),he(2,W.IDrawingManagerService),he(3,j.IRenderManagerService),he(4,c.Inject(O.SheetCanvasFloatDomManagerService)),he(5,c.Inject(B.ComponentManager)),he(6,c.Inject(c.Injector))],Ke);var gn=Object.getOwnPropertyDescriptor,hn=(o,r,t,e)=>{for(var n=e>1?void 0:e?gn(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},ue=(o,r)=>(t,e)=>r(t,e,o);const pn=[D.InsertRowCommand.id,D.InsertColCommand.id,D.RemoveRowCommand.id,D.RemoveColCommand.id,D.DeleteRangeMoveLeftCommand.id,D.DeleteRangeMoveUpCommand.id,D.InsertRangeMoveDownCommand.id,D.InsertRangeMoveRightCommand.id,D.DeltaRowHeightCommand.id,D.SetRowHeightCommand.id,D.DeltaColumnWidthCommand.id,D.SetColWidthCommand.id,D.SetRowHiddenCommand.id,D.SetSpecificRowsVisibleCommand.id,D.SetSpecificColsVisibleCommand.id,D.SetColHiddenCommand.id,D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id],mn=[D.SetRowVisibleMutation.id,D.SetRowHiddenMutation.id,D.SetColVisibleMutation.id,D.SetColHiddenMutation.id,D.SetWorksheetRowHeightMutation.id,D.SetWorksheetColWidthMutation.id];let mt=class extends c.Disposable{constructor(o,r,t,e,n,i,s,a,l){super(),this._context=o,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=i,this._sheetDrawingService=s,this._drawingManagerService=a,this._univerInstanceService=l,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:o=>{if(!pn.includes(o.id))return{redos:[],undos:[]};if(o.params==null)return{redos:[],undos:[]};const r=o.id;if(r===D.InsertRowCommand.id)return this._moveRowInterceptor(o.params,"insert");if([D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(o.params);if(r===D.InsertColCommand.id)return this._moveColInterceptor(o.params,"insert");if(r===D.RemoveRowCommand.id)return this._moveRowInterceptor(o.params,"remove");if(r===D.RemoveColCommand.id)return this._moveColInterceptor(o.params,"remove");if(r===D.DeleteRangeMoveLeftCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,0)}else if(r===D.DeleteRangeMoveUpCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,1)}else if(r===D.InsertRangeMoveDownCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,2)}else if(r===D.InsertRangeMoveRightCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,3)}else if(r===D.SetRowHiddenCommand.id||r===D.SetSpecificRowsVisibleCommand.id){const t=o.params,{unitId:e,subUnitId:n,ranges:i}=t;return this._getDrawingUndoForRowVisible(e,n,i)}else if(r===D.SetSpecificColsVisibleCommand.id||r===D.SetColHiddenCommand.id){const t=o.params,{unitId:e,subUnitId:n,ranges:i}=t;return this._getDrawingUndoForColVisible(e,n,i)}else if(r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id||r===D.DeltaColumnWidthCommand.id||r===D.SetColWidthCommand.id){const t=o.params,{unitId:e,subUnitId:n,ranges:i}=t,s=r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,i,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(o,r){const t=D.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,i=[],s=[],a=this._sheetDrawingService.getDrawingData(e,n),l=[],g=[];if(Object.keys(a).forEach(u=>{const d=a[u],{updateDrawings:p,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(o,r,d);l.push(...p),g.push(...h)}),l.length===0&&g.length===0)return{redos:[],undos:[]};if(l.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(l),{undo:d,redo:p,objects:h}=u;i.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.UPDATE}}),s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:d,objects:h,type:m.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),d=u.undo,p=u.redo,h=u.objects;i.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.REMOVE}}),s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:d,objects:h,type:m.DrawingApplyType.INSERT}})}return i.push({id:G.id,params:[e]}),s.push({id:G.id,params:[e]}),{redos:i,undos:s}}_getUpdateOrDeleteDrawings(o,r,t){const e=[],n=[],{sheetTransform:i,anchorType:s=m.SheetDrawingAnchorType.Position,transform:a,unitId:l,subUnitId:g,drawingId:u}=t,{from:d,to:p}=i,{row:h,column:S}=d,{row:f,column:w}=p;if(i==null||a==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:_,endRow:I,startColumn:C,endColumn:R}=o;let y=null,T=null;if(r===0&&h>=_&&f<=I)if(S>=C&&w<=R)n.push({unitId:l,subUnitId:g,drawingId:u});else{const v=this._shrinkCol(i,a,C,R,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}else if(r===1&&S>=C&&w<=R)if(h>=_&&f<=I)n.push({unitId:l,subUnitId:g,drawingId:u});else{const v=this._shrinkRow(i,a,_,I,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}else if(r===2){const v=this._expandRow(i,a,_,I,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}else if(r===3){const v=this._expandCol(i,a,C,R,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}if(y!=null&&T!=null){const v=x(y,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:y,transform:v})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(o,r,t){const e=H({...o},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(o,r,t){const e=this._drawingManagerService.getDrawingData(o,r),n=[],i=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:p,transform:h,anchorType:S=m.SheetDrawingAnchorType.Position}=d;if(S===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:f,to:w}=p,{row:_,column:I}=f,{row:C,column:R}=w;for(let y=0;y<t.length;y++){const T=t[y],{startRow:v,endRow:P,startColumn:E,endColumn:N}=T;if(R<E)continue;if(S===m.SheetDrawingAnchorType.Position){let M=null,Y=null;if(I>=E&&I<=N){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:N,startRow:f.row,endRow:w.row});if(L==null)return;Y={...h,left:L.startX}}if(Y!=null&&(M=H(Y,this._selectionRenderService),M!=null&&Y!=null)){n.push({...d,sheetTransform:M,transform:Y});break}this._remainDrawingSize(h,n,d);continue}if(I>=E&&R<=N)continue;let k=null,A=null;if(I>=E&&I<=N){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:N,startRow:f.row,endRow:w.row});if(M==null)return;A={...h,left:(M==null?void 0:M.startX)||0,width:((h==null?void 0:h.width)||0)-M.endX+M.startX}}else if(R>=E&&R<=N){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:R,startRow:f.row,endRow:w.row});if(M==null)return;A={...h,left:M.startX-((h==null?void 0:h.width)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:N,startRow:f.row,endRow:w.row});if(M==null)return;if(A={...h,width:((h==null?void 0:h.width)||0)-M.endX+M.startX},k=H(A,this._selectionRenderService),k!=null&&A!=null){i.push({...d,sheetTransform:k,transform:A});break}}if(A!=null&&(k=H(A,this._selectionRenderService)),A!=null&&k!=null){n.push({...d,sheetTransform:k,transform:A});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&i.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(o,r,n),l=[],g=[];if(i.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(o,r,i);l.push(...u),g.push(...d)}return{redos:s,undos:a,preRedos:l,preUndos:g}}_createUndoAndRedoMutation(o,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:i,objects:s}=e,a=[{id:m.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:r,op:i,objects:s,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[o]}],l=[{id:m.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:r,op:n,objects:s,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[o]}];return{redos:a,undos:l}}_getDrawingUndoForRowVisible(o,r,t){const e=this._drawingManagerService.getDrawingData(o,r),n=[],i=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:p,transform:h,anchorType:S=m.SheetDrawingAnchorType.Position}=d;if(S===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:f,to:w}=p,{row:_,column:I}=f,{row:C,column:R}=w;for(let y=0;y<t.length;y++){const T=t[y],{startRow:v,endRow:P,startColumn:E,endColumn:N}=T;if(C<v)continue;if(S===m.SheetDrawingAnchorType.Position){let M=null,Y=null;if(_>=v&&_<=P){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:P});if(L==null)return;Y={...h,top:L.startY}}if(Y!=null&&(M=H(Y,this._selectionRenderService),M!=null&&Y!=null)){n.push({...d,sheetTransform:M,transform:Y});break}this._remainDrawingSize(h,n,d);continue}if(_>=v&&C<=P)continue;let k=null,A=null;if(_>=v&&_<=P){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:P});if(M==null)return;A={...h,top:(M==null?void 0:M.startY)||0,height:((h==null?void 0:h.height)||0)-M.endY+M.startY}}else if(C>=v&&C<=P){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:v,endRow:C});if(M==null)return;A={...h,top:M.startY-((h==null?void 0:h.height)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:v,endRow:P});if(M==null)return;if(A={...h,height:((h==null?void 0:h.height)||0)-M.endY+M.startY},k=H(A,this._selectionRenderService),k!=null&&A!=null){i.push({...d,sheetTransform:k,transform:A});break}}if(A!=null&&(k=H(A,this._selectionRenderService)),A!=null&&k!=null){n.push({...d,sheetTransform:k,transform:A});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&i.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(o,r,n),l=[],g=[];if(i.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(o,r,i);l.push(...u),g.push(...d)}return{redos:s,undos:a,preRedos:l,preUndos:g}}_getDrawingUndoForRowAndColSize(o,r,t,e){const n=this._drawingManagerService.getDrawingData(o,r),i=[];return Object.keys(n).forEach(s=>{const a=n[s],{sheetTransform:l,transform:g,anchorType:u=m.SheetDrawingAnchorType.Position}=a;if(u===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,i,a);else{const{from:d,to:p}=l,{row:h,column:S}=d,{row:f,column:w}=p;for(let _=0;_<t.length;_++){const I=t[_],{startRow:C,endRow:R,startColumn:y,endColumn:T}=I;if(f<C||w<y)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=C&&f>=R||S<=y&&w>=T)){this._remainDrawingSize(g,i,a);continue}const v=x({...l},this._selectionRenderService,this._skeletonManagerService);if(v!=null){i.push({...a,transform:v});break}}}}),i.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(o,r,i)}_getUnitIdAndSubUnitId(o,r){let t,e;if(r==="insert")t=o.unitId,e=o.subUnitId;else{const n=D.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(o){var C,R;const{toRange:r,fromRange:t}=o,e=D.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:i}=e,s=(R=(C=this._renderManagerService.getRenderById(n))==null?void 0:C.with(b.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const a=b.attachRangeWithCoord(s,t);if(!a)return{redos:[],undos:[]};const{startX:l,endX:g,startY:u,endY:d}=a,p=this._sheetDrawingService.getDrawingData(n,i),h=[];Object.keys(p).forEach(y=>{const T=p[y];if(T.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:v}=T;if(!v)return;const{left:P=0,top:E=0,width:N=0,height:k=0}=v,{drawingStartX:A,drawingEndX:M,drawingStartY:Y,drawingEndY:L}={drawingStartX:P,drawingEndX:P+N,drawingStartY:E,drawingEndY:E+k};l<=A&&M<=g&&u<=Y&&L<=d&&h.push(T)});const S=[],f=[],w=r.startRow-t.startRow,_=r.startColumn-t.startColumn,I=h.map(y=>{const T=y.sheetTransform,v={to:{...T.to,row:T.to.row+w,column:T.to.column+_},from:{...T.from,row:T.from.row+w,column:T.from.column+_}},P=x(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:i,drawingId:y.drawingId,transform:P,sheetTransform:v}});if(I.length){const y=this._sheetDrawingService.getBatchUpdateOp(I),{undo:T,redo:v,objects:P}=y;S.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:v,objects:P,type:m.DrawingApplyType.UPDATE}}),f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:T,objects:P,type:m.DrawingApplyType.UPDATE}})}return{redos:S,undos:f}}_moveRowInterceptor(o,r){const t=this._getUnitIdAndSubUnitId(o,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:i}=o,s=i.startRow,a=i.endRow,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],p=[];if(Object.keys(u).forEach(h=>{const S=u[h],{sheetTransform:f,transform:w,anchorType:_=m.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let I,C;if(r==="insert"){const y=this._expandRow(f,w,s,a,_);I=y==null?void 0:y.newSheetTransform,C=y==null?void 0:y.newTransform}else{const{from:y,to:T}=f,{row:v}=y,{row:P}=T;if(_===m.SheetDrawingAnchorType.Both&&v>=s&&P<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkRow(f,w,s,a,_);I=E==null?void 0:E.newSheetTransform,C=E==null?void 0:E.newTransform}}if(!I||!C)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:I};d.push(R)}),d.length===0&&p.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:S,redo:f,objects:w}=h;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),S=h.undo,f=h.redo,w=h.objects;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:l,undos:g}}_moveColInterceptor(o,r){const t=this._getUnitIdAndSubUnitId(o,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:i}=o,s=i.startColumn,a=i.endColumn,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],p=[];if(Object.keys(u).forEach(h=>{const S=u[h],{sheetTransform:f,transform:w,anchorType:_=m.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let I,C;if(r==="insert"){const y=this._expandCol(f,w,s,a,_);I=y==null?void 0:y.newSheetTransform,C=y==null?void 0:y.newTransform}else{const{from:y,to:T}=f,{column:v}=y,{column:P}=T;if(_===m.SheetDrawingAnchorType.Both&&v>=s&&P<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkCol(f,w,s,a,_);I=E==null?void 0:E.newSheetTransform,C=E==null?void 0:E.newTransform}}if(!I||!C)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:I};d.push(R)}),d.length===0&&p.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:S,redo:f,objects:w}=h;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),S=h.undo,f=h.redo,w=h.objects;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:l,undos:g}}_expandCol(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{column:l}=s,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:s.row,endRow:a.row});if(p==null)return;d={...r,left:(r.left||0)+p.endX-p.startX},u=H(d,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g+i}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkCol(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{column:l}=s,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>e)u={from:{...s,column:l-i},to:{...a,column:g-i}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&g<=e)return null;if(l<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g-i}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)d={...r,left:(r.left||0)-o.from.columnOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:l-1,startRow:s.row,endRow:a.row});if(p==null)return;d={...r,left:(r.left||0)-p.endX+p.startX-o.from.columnOffset}}u=H(d,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:s.row,endRow:a.row});if(p==null)return;u={from:{...s},to:{...a,column:t-1,columnOffset:p.endX-p.startX}},d=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_expandRow(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{row:l}=s,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:s.column,endColumn:a.column});if(p==null)return;d={...r,top:(r.top||0)+p.endY-p.startY},u=H(d,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g+i}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkRow(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{row:l}=s,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>e)u={from:{...s,row:l-i},to:{...a,row:g-i}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&g<=e)return null;if(l<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g-i}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)d={...r,top:(r.top||0)-o.from.rowOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:l-1,startColumn:s.column,endColumn:a.column});if(p==null)return;d={...r,top:(r.top||0)-p.endY+p.startY-o.from.rowOffset}}u=H(d,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:t-1,endRow:t-1});if(p==null)return;u={from:{...s},to:{...a,row:t-1,rowOffset:p.endY-p.startY}},d=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{if(o.id===D.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:t}=o.params;this._updateDrawings(r,t)}})),this.disposeWithMe(this._context.activated$.subscribe(o=>{const{unit:r,unitId:t}=this._context;if(o){const e=r.getActiveSheet().getSheetId();this._updateDrawings(t,e)}else this._clearDrawings(t)}))}_clearDrawings(o){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,t=[];Object.keys(r).forEach(e=>{const n=r[e];n!=null&&Object.keys(n).forEach(i=>{const s=n[i].data;s!=null&&Object.keys(s).forEach(a=>{e===o&&t.push(s[a])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(o,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(i=>{const s=t[i];s!=null&&Object.keys(s).forEach(a=>{const l=s[a].data;l!=null&&Object.keys(l).forEach(g=>{if(i===o&&a===r){const u=l[g];u.transform=x(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(l[g])}else n.push(l[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{mn.includes(o.id)&&requestIdleCallback(()=>{const r=o.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(o,r,t){const e=this._drawingManagerService.getDrawingData(o,r),n=[];Object.keys(e).forEach(i=>{const s=e[i],{sheetTransform:a,transform:l,anchorType:g=m.SheetDrawingAnchorType.Position}=s;if(g===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=a,{row:p,column:h}=u,{row:S,column:f}=d;for(let w=0;w<t.length;w++){const _=t[w],{startRow:I,endRow:C,startColumn:R,endColumn:y}=_;if(c.Rectangle.intersects({startRow:I,endRow:C,startColumn:R,endColumn:y},{startRow:p,endRow:S,startColumn:h,endColumn:f})||p>C||h>y){const T=g===m.SheetDrawingAnchorType.Position,v=x(a,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...v,width:T?l==null?void 0:l.width:v==null?void 0:v.width,height:T?l==null?void 0:l.height:v==null?void 0:v.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[o]))}};mt=hn([ue(1,j.IRenderManagerService),ue(2,c.ICommandService),ue(3,b.ISheetSelectionRenderService),ue(4,c.Inject(b.SheetSkeletonManagerService)),ue(5,c.Inject(D.SheetInterceptorService)),ue(6,m.ISheetDrawingService),ue(7,W.IDrawingManagerService),ue(8,c.IUniverInstanceService)],mt);const fn=o=>{var I;const r=B.useDependency(c.ICommandService),t=B.useDependency(c.LocaleService),e=B.useDependency(W.IDrawingManagerService),n=B.useDependency(j.IRenderManagerService),{drawings:i}=o,s=i[0];if(s==null)return;const{unitId:a}=s,l=n.getRenderById(a),g=l==null?void 0:l.scene;if(g==null)return;const u=g.getTransformerByCreate(),[d,p]=pe.useState(!0),h=(I=s.anchorType)!=null?I:m.SheetDrawingAnchorType.Position,[S,f]=pe.useState(h);function w(C,R){const y=[];return C.forEach(T=>{const{oKey:v}=T,P=R.getDrawingOKey(v);if(P==null)return y.push(null),!0;const{unitId:E,subUnitId:N,drawingId:k,drawingType:A,anchorType:M,sheetTransform:Y}=P;y.push({unitId:E,subUnitId:N,drawingId:k,anchorType:M,sheetTransform:Y,drawingType:A})}),y}pe.useEffect(()=>{const C=u.clearControl$.subscribe(y=>{y===!0&&p(!1)}),R=u.changeStart$.subscribe(y=>{var P;const{objects:T}=y,v=w(T,e);if(v.length===0)p(!1);else if(v.length>=1){p(!0);const E=((P=v[0])==null?void 0:P.anchorType)||m.SheetDrawingAnchorType.Position;f(E)}});return()=>{R.unsubscribe(),C.unsubscribe()}},[]);function _(C){f(C);const R=e.getFocusDrawings();if(R.length===0)return;const y=R.map(T=>({unitId:T.unitId,subUnitId:T.subUnitId,drawingId:T.drawingId,anchorType:C}));r.executeCommand(Te.id,{unitId:R[0].unitId,drawings:y})}return J.jsxs("div",{className:q.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!d}),children:[J.jsx("header",{className:"univer-text-gray-600 dark:!univer-text-gray-200",children:J.jsx("div",{children:t.t("drawing-anchor.title")})}),J.jsx("div",{children:J.jsxs(q.RadioGroup,{value:S,onChange:_,direction:"vertical",children:[J.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),J.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),J.jsx(q.Radio,{value:m.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})]})},Sn=()=>{const o=B.useDependency(W.IDrawingManagerService),r=o.getFocusDrawings(),[t,e]=pe.useState(r);return pe.useEffect(()=>{const n=o.focus$.subscribe(i=>{e(i)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&J.jsxs("div",{className:"univer-text-sm",children:[J.jsx(le.DrawingCommonPanel,{drawings:t}),J.jsx(fn,{drawings:t})]})},ft="sheet.menu.image";function wn(o){return{id:ft,type:B.MenuItemType.SUBITEMS,icon:"AddImageIcon",tooltip:"sheetImage.title",hidden$:B.getMenuHiddenObservable(o,c.UniverInstanceType.UNIVER_SHEET),disabled$:b.getCurrentRangeDisable$(o,{workbookTypes:[D.WorkbookEditablePermission],worksheetTypes:[D.WorksheetEditPermission],rangeTypes:[D.RangeProtectionPermissionEditPoint]})}}function _n(o){return{id:Re.id,title:"sheetImage.upload.float",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(o,c.UniverInstanceType.UNIVER_SHEET)}}function vn(o){return{id:lt.id,title:"sheetImage.upload.cell",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(o,c.UniverInstanceType.UNIVER_SHEET)}}const In={[B.RibbonInsertGroup.MEDIA]:{[ft]:{order:0,menuItemFactory:wn,[Re.id]:{order:0,menuItemFactory:_n},[lt.id]:{order:1,menuItemFactory:vn}}}};function Pe(o){return!o.getContextValue(c.FOCUSING_FX_BAR_EDITOR)&&!o.getContextValue(c.EDITOR_ACTIVATED)&&!o.getContextValue(c.FOCUSING_PANEL_EDITOR)&&o.getContextValue(c.FOCUSING_COMMON_DRAWINGS)}const yn={id:fe.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:B.KeyCode.ARROW_DOWN,priority:100,preconditions:Pe,staticParameters:{direction:c.Direction.DOWN}},Dn={id:fe.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:B.KeyCode.ARROW_UP,priority:100,preconditions:Pe,staticParameters:{direction:c.Direction.UP}},Cn={id:fe.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:B.KeyCode.ARROW_LEFT,priority:100,preconditions:Pe,staticParameters:{direction:c.Direction.LEFT}},Mn={id:fe.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:B.KeyCode.ARROW_RIGHT,priority:100,preconditions:Pe,staticParameters:{direction:c.Direction.RIGHT}},Tn={id:ot.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:Pe,binding:B.KeyCode.DELETE,mac:B.KeyCode.BACKSPACE};var Rn=Object.getOwnPropertyDescriptor,En=(o,r,t,e)=>{for(var n=e>1?void 0:e?Rn(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},we=(o,r)=>(t,e)=>r(t,e,o);let ze=class extends c.Disposable{constructor(o,r,t,e,n,i){super(),this._componentManager=o,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=i,this._init()}_initCustomComponents(){const o=this._componentManager;this.disposeWithMe(o.register(It,Sn))}_initMenus(){this._menuManagerService.mergeMenu(In)}_initCommands(){[Re,lt,Me,me,Te,ut,G,gt,st,ct,fe,ot,at].forEach(o=>this.disposeWithMe(this._commandService.registerCommand(o)))}_initShortcuts(){[yn,Dn,Cn,Mn,Tn].forEach(o=>{this.disposeWithMe(this._shortcutService.registerShortcut(o))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};ze=En([we(0,c.Inject(B.ComponentManager)),we(1,B.IMenuManagerService),we(2,c.ICommandService),we(3,B.IShortcutService),we(4,W.IDrawingManagerService),we(5,c.Inject(D.SheetsSelectionsService))],ze);var bn=Object.defineProperty,On=Object.getOwnPropertyDescriptor,An=(o,r,t)=>r in o?bn(o,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[r]=t,Pn=(o,r,t,e)=>{for(var n=e>1?void 0:e?On(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},St=(o,r)=>(t,e)=>r(t,e,o),Et=(o,r,t)=>An(o,typeof r!="symbol"?r+"":r,t);const Un="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends c.Plugin{constructor(r=yt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:i,...s}=c.merge({},yt,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Yt,s)}onStarting(){c.registerDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService],[ze],[je],[Ke],[He],[Ge],[Fe],[$e],[Le]]),c.touchDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService]])}onReady(){c.touchDependencies(this._injector,[[Ge],[Le]])}onRendered(){this._registerRenderModules(),c.touchDependencies(this._injector,[[He],[Ke],[ze],[Fe],[$e]])}onSteady(){this._injector.get(je)}_registerRenderModules(){[[O.SheetDrawingUpdateController],[mt],[pt],[ht]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(c.UniverInstanceType.UNIVER_SHEET,r))})}},Et(O.UniverSheetsDrawingUIPlugin,"type",c.UniverInstanceType.UNIVER_SHEET),Et(O.UniverSheetsDrawingUIPlugin,"pluginName",Un),O.UniverSheetsDrawingUIPlugin=Pn([c.DependentOn(W.UniverDrawingPlugin,vt.UniverDocsDrawingPlugin,le.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),St(1,c.Inject(c.Injector)),St(2,j.IRenderManagerService),St(3,c.IConfigService)],O.UniverSheetsDrawingUIPlugin),O.ClearSheetDrawingTransformerOperation=G,O.DeleteDrawingsCommand=ot,O.EditSheetDrawingOperation=gt,O.GroupSheetDrawingCommand=st,O.InsertFloatImageCommand=Re,O.InsertSheetDrawingCommand=Me,O.MoveDrawingsCommand=fe,O.RemoveSheetDrawingCommand=me,O.SHEETS_IMAGE_MENU_ID=ft,O.SetDrawingArrangeCommand=at,O.SetSheetDrawingCommand=Te,O.SidebarSheetDrawingOperation=ut,O.UngroupSheetDrawingCommand=ct,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.8.2-nightly.202506261607",
3
+ "version": "0.8.3-nightly.202506271607",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -62,17 +62,17 @@
62
62
  "rxjs": ">=7.0.0"
63
63
  },
64
64
  "dependencies": {
65
- "@univerjs/core": "0.8.2-nightly.202506261607",
66
- "@univerjs/design": "0.8.2-nightly.202506261607",
67
- "@univerjs/docs-ui": "0.8.2-nightly.202506261607",
68
- "@univerjs/docs-drawing": "0.8.2-nightly.202506261607",
69
- "@univerjs/drawing": "0.8.2-nightly.202506261607",
70
- "@univerjs/sheets": "0.8.2-nightly.202506261607",
71
- "@univerjs/drawing-ui": "0.8.2-nightly.202506261607",
72
- "@univerjs/engine-render": "0.8.2-nightly.202506261607",
73
- "@univerjs/sheets-drawing": "0.8.2-nightly.202506261607",
74
- "@univerjs/sheets-ui": "0.8.2-nightly.202506261607",
75
- "@univerjs/ui": "0.8.2-nightly.202506261607"
65
+ "@univerjs/design": "0.8.3-nightly.202506271607",
66
+ "@univerjs/docs-ui": "0.8.3-nightly.202506271607",
67
+ "@univerjs/core": "0.8.3-nightly.202506271607",
68
+ "@univerjs/docs-drawing": "0.8.3-nightly.202506271607",
69
+ "@univerjs/drawing-ui": "0.8.3-nightly.202506271607",
70
+ "@univerjs/drawing": "0.8.3-nightly.202506271607",
71
+ "@univerjs/engine-render": "0.8.3-nightly.202506271607",
72
+ "@univerjs/sheets-drawing": "0.8.3-nightly.202506271607",
73
+ "@univerjs/sheets": "0.8.3-nightly.202506271607",
74
+ "@univerjs/ui": "0.8.3-nightly.202506271607",
75
+ "@univerjs/sheets-ui": "0.8.3-nightly.202506271607"
76
76
  },
77
77
  "devDependencies": {
78
78
  "postcss": "^8.5.6",
@@ -82,7 +82,7 @@
82
82
  "typescript": "^5.8.3",
83
83
  "vite": "^6.3.5",
84
84
  "vitest": "^3.2.4",
85
- "@univerjs-infra/shared": "0.8.2"
85
+ "@univerjs-infra/shared": "0.8.3"
86
86
  },
87
87
  "scripts": {
88
88
  "test": "vitest run",