@univerjs/sheets-drawing-ui 0.6.0-nightly.202502061605 → 0.6.0-nightly.202502071606
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +1101 -1096
- package/lib/types/services/canvas-float-dom-manager.service.d.ts +6 -1
- package/lib/umd/index.js +1 -1
- package/package.json +12 -12
|
@@ -63,6 +63,11 @@ export interface IDOMAnchor {
|
|
|
63
63
|
marginY?: number;
|
|
64
64
|
}
|
|
65
65
|
export interface ILimitBound extends IBoundRectNoAngle {
|
|
66
|
+
/**
|
|
67
|
+
* Actually, it means fixed.
|
|
68
|
+
* When left is true, dom is fixed to left of dom pos when dom width is shrinking. or dom is fixed to right of dom pos when dom width is shrinking.
|
|
69
|
+
* When top is true, dom is fixed to top of dom pos when dom height is shrinking. or dom is fixed to bottom of dom pos when dom height is shrinking.
|
|
70
|
+
*/
|
|
66
71
|
absolute: {
|
|
67
72
|
left: boolean;
|
|
68
73
|
top: boolean;
|
|
@@ -70,7 +75,7 @@ export interface ILimitBound extends IBoundRectNoAngle {
|
|
|
70
75
|
}
|
|
71
76
|
/**
|
|
72
77
|
* Adjust dom bound size when scrolling (dom bound would shrink when scrolling if over the edge of viewMain)
|
|
73
|
-
* @param posOfFloatObject
|
|
78
|
+
* @param posOfFloatObject The position of float object, relative to sheet content, scale & scrolling does not affect it.
|
|
74
79
|
* @param scene
|
|
75
80
|
* @param skeleton
|
|
76
81
|
* @param worksheet
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(E,l){typeof exports=="object"&&typeof module<"u"?l(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/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("react/jsx-runtime"),require("react"),require("@univerjs/docs-ui"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-drawing","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","react/jsx-runtime","react","@univerjs/docs-ui","@univerjs/design"],l):(E=typeof globalThis<"u"?globalThis:E||self,l(E.UniverSheetsDrawingUi={},E.UniverCore,E.UniverDocsDrawing,E.UniverDrawing,E.UniverDrawingUi,E.UniverEngineRender,E.UniverSheetsDrawing,E.UniverSheetsUi,E.UniverUi,E.rxjs,E.UniverSheets,E.React,E.React,E.UniverDocsUi,E.UniverDesign))})(this,function(E,l,Se,P,ge,N,w,R,F,W,v,X,q,Tt,ee){"use strict";var si=Object.defineProperty;var ci=(E,l,Se)=>l in E?si(E,l,{enumerable:!0,configurable:!0,writable:!0,value:Se}):E[l]=Se;var z=(E,l,Se)=>ci(E,typeof l!="symbol"?l+"":l,Se);const Ht="sheets-drawing-ui.config",bt={},H={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(r,i)=>{const n=r.get(N.IRenderManagerService);return i.forEach(e=>{var t,o;(o=(t=n.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},Ce={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{var I,M,b;const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(v.SheetInterceptorService),o=r.get(w.ISheetDrawingService);if(!i)return!1;const{drawings:a}=i,s=[];a.forEach(y=>{const{unitId:T}=y;s.push(T)});const c=o.getBatchRemoveOp(a),{unitId:m,subUnitId:u,undo:d,redo:h,objects:g}=c,p=t.onCommandExecute({id:Ce.id,params:i}),S={id:w.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:h,objects:g,type:w.DrawingApplyType.REMOVE}},f={id:w.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:d,objects:g,type:w.DrawingApplyType.INSERT}};return l.sequenceExecute([...(I=p.preRedos)!=null?I:[],S,...p.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(M=p.preUndos)!=null?M:[],f,...p.undos,{id:H.id,params:s}],redoMutations:[...(b=p.preRedos)!=null?b:[],S,...p.redos,{id:H.id,params:s}]}),!0):!1}},Rt="COMPONENT_SHEET_DRAWING_PANEL",gt={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(r,i)=>{const n=r.get(F.ISidebarService),e=r.get(l.LocaleService),t=r.get(l.IUniverInstanceService),o=r.get(l.ICommandService);if(!v.getSheetCommandTarget(t))return!1;switch(i.value){case"open":n.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Rt},onClose:()=>{o.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:n.close();break}return!0}},ht={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(r,i)=>{const n=r.get(l.ICommandService);return i==null?!1:(n.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[i]),n.executeCommand(gt.id,{value:"open"}),!0)}},Ye={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},Vt=()=>{const r=l.useDependency(P.IImageIoService),i=l.useDependency(l.LocaleService),[n,e]=q.useState(0);return q.useEffect(()=>{const t=r.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[r]),X.jsx("div",{style:{display:n>0?"block":"none"},className:Ye.uploadLoading,children:X.jsxs("div",{className:Ye.uploadLoadingBody,children:[X.jsx("div",{className:Ye.uploadLoadingBodyAnimation}),X.jsx("div",{className:Ye.uploadLoadingBodyText,children:`${i.t("uploadLoading.loading")}: ${n}`})]})})};var Xt=Object.defineProperty,xt=Object.getOwnPropertyDescriptor,Kt=(r,i,n,e)=>{for(var t=e>1?void 0:e?xt(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Xt(i,n,t),t},he=(r,i)=>(n,e)=>i(n,e,r);let Ge=class extends l.RxDisposable{constructor(i,n,e,t,o,a,s,c){super();z(this,"_initImagePopupMenu",new Set);this._injector=i,this._drawingManagerService=n,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._commandService=c,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(i=>this._create(i)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(i=>this._dispose(i)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(i=>this._create(i)),this._uiPartsService.registerComponent(F.BuiltInUIPart.CONTENT,()=>l.connectInjector(Vt,this._injector))}_dispose(i){const n=i.getUnitId();this._renderManagerService.removeRender(n)}_create(i){if(!i)return;const n=i.getUnitId();this._renderManagerService.has(n)&&!this._initImagePopupMenu.has(n)&&(this._popupMenuListener(n),this._initImagePopupMenu.add(n))}_hasCropObject(i){const n=i.getAllObjectsByOrder();for(const e of n)if(e instanceof ge.ImageCropperObject)return!0;return!1}_popupMenuListener(i){var o;const n=(o=this._renderManagerService.getRenderById(i))==null?void 0:o.scene;if(!n)return;const e=n.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(l.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(n))return;const a=e.getSelectedObjectMap();if(a.size>1){t==null||t.dispose();return}const s=a.values().next().value;if(!s)return;const c=s.oKey,m=this._drawingManagerService.getDrawingOKey(c);if(!m)return;const{unitId:u,subUnitId:d,drawingId:h,drawingType:g}=m,p=m.data;if(p&&p.disablePopup)return;t==null||t.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,d,h,g);t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:ge.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,d,h,g)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[l.FOCUSING_COMMON_DRAWINGS]===!1&&(t==null||t.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{t==null||t.dispose()}))}_getImageMenuItems(i,n,e,t){return[{label:"image-popup.edit",index:0,commandId:ht.id,commandParams:{unitId:i,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Ce.id,commandParams:{unitId:i,drawings:[{unitId:i,subUnitId:n,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ge.OpenImageCropOperation.id,commandParams:{unitId:i,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ge.ImageResetSizeOperation.id,commandParams:[{unitId:i,subUnitId:n,drawingId:e}],disable:t===l.DrawingTypeEnum.DRAWING_DOM}]}};Ge=Kt([he(0,l.Inject(l.Injector)),he(1,P.IDrawingManagerService),he(2,l.Inject(R.SheetCanvasPopManagerService)),he(3,N.IRenderManagerService),he(4,l.IUniverInstanceService),he(5,l.IContextService),he(6,l.Inject(F.IUIPartsService)),he(7,l.ICommandService)],Ge);function x(r,i,n){const{from:e,to:t,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:c=0,skewY:m=0}=r,u=n.getCurrent();if(u==null)return;const d=R.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:t},n);let{left:h,top:g,width:p,height:S}=d;const f=n.getCurrentSkeleton(),_=f.rowHeaderWidth+f.columnTotalWidth,I=f.columnHeaderHeight+f.rowTotalHeight;return h+p>_&&(h=_-p),g+S>I&&(g=I-S),{flipY:o,flipX:a,angle:s,skewX:c,skewY:m,left:h,top:g,width:p,height:S}}function V(r,i){const{left:n=0,top:e=0,width:t=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:c=0,skewX:m=0,skewY:u=0}=r,d=i.getCellWithCoordByOffset(n,e);if(d==null)return;const h={column:d.actualColumn,columnOffset:N.precisionTo(n-d.startX,1),row:d.actualRow,rowOffset:N.precisionTo(e-d.startY,1)},g=i.getCellWithCoordByOffset(n+t,e+o);if(g==null)return;const p={column:g.actualColumn,columnOffset:N.precisionTo(n+t-g.startX,1),row:g.actualRow,rowOffset:N.precisionTo(e+o-g.startY,1)};return{flipY:a,flipX:s,angle:c,skewX:m,skewY:u,from:h,to:p}}var zt=Object.defineProperty,qt=Object.getOwnPropertyDescriptor,Zt=(r,i,n,e)=>{for(var t=e>1?void 0:e?qt(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&zt(i,n,t),t},Fe=(r,i)=>(n,e)=>i(n,e,r);let mt=class extends l.Disposable{constructor(r,i,n,e,t){super(),this._context=r,this._sheetDrawingService=i,this._drawingManagerService=n,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=t,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const r=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const i in r){const n=r[i];for(const e in n.data){const t=n.data[e];t.transform=x(t.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};mt=Zt([Fe(1,w.ISheetDrawingService),Fe(2,P.IDrawingManagerService),Fe(3,l.Inject(R.ISheetSelectionRenderService)),Fe(4,l.Inject(R.SheetSkeletonManagerService))],mt);function Jt(r){const i=[];return r.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s}=e,c=N.getGroupState(0,0,t.map(d=>d.transform||{})),m=t.map(d=>{const h=d.transform||{left:0,top:0},{unitId:g,subUnitId:p,drawingId:S}=d;return{unitId:g,subUnitId:p,drawingId:S,transform:{...h,left:h.left-c.left,top:h.top-c.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:c};i.push({parent:u,children:m})}),i}function Qt(r){const i=[];return r.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s,transform:c={width:0,height:0}}=e;if(c==null)return;const m=t.map(d=>{const{transform:h}=d,{unitId:g,subUnitId:p,drawingId:S}=d,f=N.transformObjectOutOfGroup(h||{},c,c.width||0,c.height||0);return{unitId:g,subUnitId:p,drawingId:S,transform:f,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};i.push({parent:u,children:m})}),i}const pt={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService);if(!i)return!1;const o=[];i.forEach(({parent:g,children:p})=>{o.push(g.unitId),p.forEach(S=>{o.push(S.unitId)})});const a=t.getGroupDrawingOp(i),{unitId:s,subUnitId:c,undo:m,redo:u,objects:d}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:c,objects:d,type:w.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:c,objects:Qt(d),type:w.DrawingApplyType.UNGROUP}},{id:H.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:c,objects:d,type:w.DrawingApplyType.GROUP}},{id:H.id,params:o}]}),!0):!1}},Pe={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{var I,M,b;const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService),o=r.get(v.SheetInterceptorService);if(!i)return!1;const a=i.drawings,s=a.map(y=>y.unitId),c=t.getBatchAddOp(a),{unitId:m,subUnitId:u,undo:d,redo:h,objects:g}=c,p=o.onCommandExecute({id:Pe.id,params:i}),S={id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:m,subUnitId:u,objects:g,type:w.DrawingApplyType.INSERT}},f={id:w.SetDrawingApplyMutation.id,params:{op:d,unitId:m,subUnitId:u,objects:g,type:w.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(I=p.preRedos)!=null?I:[],S,...p.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(M=p.preUndos)!=null?M:[],f,...p.undos,{id:H.id,params:s}],redoMutations:[...(b=p.preRedos)!=null?b:[],S,...p.redos,{id:H.id,params:s}]}),!0):!1}},ft={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService);if(!i)return!1;const t=r.get(w.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:c}=i,m={unitId:o,subUnitId:a,drawingIds:s};let u;if(c===l.ArrangeTypeEnum.forward?u=t.getForwardDrawingsOp(m):c===l.ArrangeTypeEnum.backward?u=t.getBackwardDrawingOp(m):c===l.ArrangeTypeEnum.front?u=t.getFrontDrawingsOp(m):c===l.ArrangeTypeEnum.back&&(u=t.getBackDrawingsOp(m)),u==null)return!1;const{objects:d,redo:h,undo:g}=u;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:h,unitId:o,subUnitId:a,objects:d,type:w.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:d,type:w.DrawingApplyType.ARRANGE}}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:d,type:w.DrawingApplyType.ARRANGE}}]}),!0):!1}},Ae={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService);if(!i)return!1;const{drawings:o}=i,a=t.getBatchUpdateOp(o),{unitId:s,subUnitId:c,undo:m,redo:u,objects:d}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:s,subUnitId:c,op:u,objects:d,type:w.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:c,op:m,objects:d,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[s]}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:c,op:u,objects:d,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[s]}]}),!0):!1}},St={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService);if(!i)return!1;const o=[];i.forEach(({parent:g,children:p})=>{o.push(g.unitId),p.forEach(S=>{o.push(S.unitId)})});const a=t.getUngroupDrawingOp(i),{unitId:s,subUnitId:c,undo:m,redo:u,objects:d}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:c,objects:d,type:w.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:c,objects:Jt(d),type:w.DrawingApplyType.GROUP}},{id:H.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:c,objects:d,type:w.DrawingApplyType.UNGROUP}},{id:H.id,params:o}]}),!0):!1}};var en=Object.defineProperty,tn=Object.getOwnPropertyDescriptor,nn=(r,i,n,e)=>{for(var t=e>1?void 0:e?tn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&en(i,n,t),t},Z=(r,i)=>(n,e)=>i(n,e,r);function rn(r,i,n){const e=n*Math.PI/180,t=Math.abs(r*Math.cos(e))+Math.abs(i*Math.sin(e)),o=Math.abs(r*Math.sin(e))+Math.abs(i*Math.cos(e));return{rotatedWidth:t,rotatedHeight:o}}function Et(r,i,n,e,t){var I;const{rotatedHeight:o,rotatedWidth:a}=rn(n,e,t),c=r.get(N.IRenderManagerService).getRenderById(i.unitId);if(!c)return!1;const u=(I=c.with(R.SheetSkeletonManagerService).getSkeletonParam(i.subUnitId))==null?void 0:I.skeleton;if(u==null)return!1;const d=u.getCellByIndex(i.row,i.col),h=d.mergeInfo.endX-d.mergeInfo.startX-2,g=d.mergeInfo.endY-d.mergeInfo.startY-2,p=a/o,f=Math.ceil(Math.min(h,g*p))/a,_=!f||Number.isNaN(f)?.001:f;return{width:n*_,height:e*_}}let Ue=class extends l.Disposable{constructor(i,n,e,t,o,a,s,c,m,u,d,h,g){super();z(this,"_workbookSelections");this._context=i,this._skeletonManagerService=n,this._commandService=e,this._selectionRenderService=t,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=s,this._drawingManagerService=c,this._contextService=m,this._messageService=u,this._localeService=d,this._injector=g,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const i=await this._fileOpenerService.openFile({multiple:!0,accept:P.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),n=i.length;return n>P.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(P.DRAWING_IMAGE_COUNT_LIMIT))}),!1):n===0?!1:(i.forEach(async e=>await this.insertFloatImageByFile(e)),!0)}async insertCellImage(){const n=(await this._fileOpenerService.openFile({multiple:!1,accept:P.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}))[0];return n?(await this._insertCellImage(n),!0):!1}async insertFloatImageByFile(i){let n;try{n=await this._imageIoService.saveImage(i)}catch(I){const M=I.message;M===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):M===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):M===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:s,source:c,base64Cache:m}=n,{width:u,height:d,image:h}=await P.getImageSize(m||""),{width:g,height:p}=this._context.scene;this._imageIoService.addImageSourceCache(c,s,h);let S=1;if(u>P.DRAWING_IMAGE_WIDTH_LIMIT||d>P.DRAWING_IMAGE_HEIGHT_LIMIT){const I=P.DRAWING_IMAGE_WIDTH_LIMIT/u,M=P.DRAWING_IMAGE_HEIGHT_LIMIT/d;S=Math.max(I,M)}const f=this._getImagePosition(u*S,d*S,g,p);if(f==null)return;const _={unitId:t,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:c,transform:x(f,this._selectionRenderService,this._skeletonManagerService),sheetTransform:f};return this._commandService.executeCommand(Pe.id,{unitId:t,drawings:[_]})}async _insertCellImage(i){let n;try{n=await this._imageIoService.saveImage(i)}catch(f){const _=f.message;_===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):_===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):_===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const{imageId:e,imageSourceType:t,source:o,base64Cache:a}=n,{width:s,height:c,image:m}=await P.getImageSize(a||"");this._imageIoService.addImageSourceCache(o,t,m);const u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;const d=l.createDocumentModelWithStyle("",{}),h=Et(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},s,c,0);if(!h)return!1;const g={size:{width:h.width,height:h.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},p={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:e,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t,source:o,transform:Tt.docDrawingPositionToTransform(g),docTransform:g,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=l.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[p],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(d.apply(S),this._commandService.syncExecuteCommand(v.SetRangeValuesCommand.id,{value:{[u.primary.actualRow]:{[u.primary.actualColumn]:{p:d.getSnapshot(),t:1}}}})):!1}_getUnitInfo(){const i=this._context.unit,n=i.getActiveSheet(),e=i.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(i,n,e,t){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const s=R.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(s==null)return;let{startColumn:c,startRow:m,startX:u,startY:d}=s,h=!1;if(u+i>e&&(u=e-i,u<0&&(u=0,i=e),h=!0),d+n>t&&(d=t-n,d<0&&(d=0,n=t),h=!0),h){const f=this._selectionRenderService.getCellWithCoordByOffset(u,d);if(f==null)return;u=f.startX,d=f.startY,c=f.actualColumn,m=f.actualRow}const g={column:c,columnOffset:0,row:m,rowOffset:0},p=this._selectionRenderService.getCellWithCoordByOffset(u+i,d+n);if(p==null)return;const S={column:p.actualColumn,columnOffset:u+i-p.startX,row:p.actualRow,rowOffset:d+n-p.startY};return{from:g,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(i=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o}=i;this._commandService.executeCommand(ft.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(i=>{const n=[];i.length!==0&&(i.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a,drawingType:s,transform:c}=e;if(c==null)return;const m=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:a});if(m==null||m.unitId!==this._context.unitId)return;const u=V({...m.transform,...c},this._selectionRenderService);if(u==null)return;const d={...e,transform:{...m.transform,...c,...x(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};n.push(d)}),n.length>0&&this._commandService.executeCommand(Ae.id,{unitId:i[0].unitId,drawings:n}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(i=>{this._commandService.executeCommand(pt.id,i);const{unitId:n,subUnitId:e,drawingId:t}=i[0].parent;this._commandService.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:e,drawingId:t}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(i=>{this._commandService.executeCommand(St.id,i)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(i=>{i==null||i.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(i))}))}};Ue=nn([Z(1,l.Inject(R.SheetSkeletonManagerService)),Z(2,l.ICommandService),Z(3,R.ISheetSelectionRenderService),Z(4,P.IImageIoService),Z(5,F.ILocalFileService),Z(6,w.ISheetDrawingService),Z(7,P.IDrawingManagerService),Z(8,l.IContextService),Z(9,F.IMessageService),Z(10,l.Inject(l.LocaleService)),Z(11,l.Inject(v.SheetsSelectionsService)),Z(12,l.Inject(l.Injector))],Ue);var on=Object.defineProperty,an=Object.getOwnPropertyDescriptor,sn=(r,i,n,e)=>{for(var t=e>1?void 0:e?an(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&on(i,n,t),t},we=(r,i)=>(n,e)=>i(n,e,r);function wt(r,i,n){var e,t,o,a;if(((t=(e=n==null?void 0:n.p)==null?void 0:e.body)==null?void 0:t.dataStream.length)===3&&((a=(o=n.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const s=n.p.drawings[n.p.drawingsOrder[0]],c=Et(r,{unitId:i.unitId,subUnitId:i.subUnitId,row:i.row,col:i.col},s.docTransform.size.width,s.docTransform.size.height,s.docTransform.angle);if(c)return s.transform.width=c.width,s.transform.height=c.height,s.docTransform.size.width=c.width,s.docTransform.size.height=c.height,s.transform.left=0,s.transform.top=0,s.docTransform.positionH.posOffset=0,s.docTransform.positionV.posOffset=0,n.p.documentStyle.pageSize.width=1/0,n.p.documentStyle.pageSize.height=1/0,!0}return!1}let He=class extends l.Disposable{constructor(r,i,n,e,t,o,a){super(),this._commandService=r,this._sheetInterceptorService=i,this._univerInstanceService=n,this._injector=e,this._drawingManagerService=t,this._docDrawingController=o,this._editorBridgeService=a,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{let i,n=[];if(r.id===v.SetWorksheetRowHeightMutation.id){const e=r.params;n=e.ranges,i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===v.SetWorksheetColWidthMutation.id){const e=r.params;n=e.ranges,i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===v.SetWorksheetRowIsAutoHeightMutation.id){const e=r.params;n=e.ranges,i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===v.SetWorksheetRowAutoHeightMutation.id){const e=r.params;i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId}),n=e.rowsAutoHeightInfo.map(t=>({startRow:t.row,endRow:t.row,startColumn:0,endColumn:9999}))}else if(r.id===v.AddWorksheetMergeMutation.id){const e=r.params;n=e.ranges,i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===v.RemoveWorksheetMergeMutation.id){const e=r.params;n=e.ranges,i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}i&&n.length&&n.forEach(e=>{const t=l.Range.transformRange(e,i.worksheet);for(let o=t.startRow;o<=t.endRow;o++)for(let a=t.startColumn;a<=t.endColumn;a++)wt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:o,col:a},i.worksheet.getCellRaw(o,a))})}))}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(r=>{r.visible?r.visible&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{r.id===Tt.ReplaceSnapshotCommand.id&&r.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(v.AFTER_CELL_EDIT,{priority:9999,handler:(r,i,n)=>(wt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:i.row,col:i.col},r),n(r))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(v.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:v.InterceptCellContentPriority.CELL_IMAGE,handler:(r,i,n)=>{var e;return r!=null&&r.p&&((e=r.p.drawingsOrder)!=null&&e.length)&&(r.interceptorStyle||(r.interceptorStyle={}),r.interceptorStyle.tr={a:0}),n(r)}}))}};He=sn([we(0,l.ICommandService),we(1,l.Inject(v.SheetInterceptorService)),we(2,l.IUniverInstanceService),we(3,l.Inject(l.Injector)),we(4,P.IDrawingManagerService),we(5,l.Inject(Se.DocDrawingController)),we(6,l.Inject(R.IEditorBridgeService))],He);var cn=Object.defineProperty,dn=Object.getOwnPropertyDescriptor,ln=(r,i,n,e)=>{for(var t=e>1?void 0:e?dn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&cn(i,n,t),t},Ot=(r,i)=>(n,e)=>i(n,e,r);let Ve=class extends l.Disposable{constructor(r,i){super(),this._autoFillService=r,this._injector=i,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(r,i,n,e)=>{new l.ObjectMatrix(e).forValue((t,o,a)=>{wt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:t,col:o},a)})}}))}};Ve=ln([Ot(0,l.Inject(R.IAutoFillService)),Ot(1,l.Inject(l.Injector))],Ve);var un=Object.defineProperty,gn=Object.getOwnPropertyDescriptor,hn=(r,i,n,e)=>{for(var t=e>1?void 0:e?gn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&un(i,n,t),t},Xe=(r,i)=>(n,e)=>i(n,e,r);let xe=class extends l.Disposable{constructor(i,n,e,t){super();z(this,"_isSetCursor",!1);this._hoverManagerService=i,this._renderManagerService=n,this._selectionsService=e,this._drawingRenderService=t}_initHover(){}_initImageClick(){}};xe=hn([Xe(0,l.Inject(R.HoverManagerService)),Xe(1,l.Inject(N.IRenderManagerService)),Xe(2,l.Inject(v.SheetsSelectionsService)),Xe(3,l.Inject(ge.DrawingRenderService))],xe);const Ne={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(r,i)=>{var o,a;const e=(o=r.get(N.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:o.with(Ue);if(!e)return!1;const t=i==null?void 0:i.files;if(t){const s=t.map(c=>e.insertFloatImageByFile(c));return(await Promise.all(s)).every(c=>c)}else return(a=e.insertFloatImage())!=null?a:!1}},_t={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:r=>{var n,e;return(e=(n=r.get(N.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(Ue).insertCellImage())!=null?e:!1}};var mn=Object.defineProperty,pn=Object.getOwnPropertyDescriptor,fn=(r,i,n,e)=>{for(var t=e>1?void 0:e?pn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&mn(i,n,t),t},je=(r,i)=>(n,e)=>i(n,e,r);const Pt="image/png";function Sn(r){const i=r.split(","),n=atob(i[1]),e=n.length,t=new Uint8Array(e);for(let o=0;o<e;o++)t[o]=n.charCodeAt(o);return new Blob([t],{type:Pt})}function wn(r){const i=new ClipboardItem({[Pt]:Sn(r)});navigator.clipboard.write([i]).catch(n=>{console.error("Could not copy image using clipboard API: ",n)})}function _n(){function r(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const i=document.activeElement,n=r();return document.body.appendChild(n),n.focus(),()=>{n.blur(),document.body.removeChild(n),i instanceof HTMLElement&&i.focus()}}const At=[R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let Ke=class extends l.Disposable{constructor(i,n,e,t,o){super();z(this,"_copyInfo");this._sheetClipboardService=i,this._renderManagerService=n,this._drawingService=e,this._clipboardInterfaceService=t,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(i,n,e,t)=>{const o=this._focusedDrawings;if(o.length>0){const[a]=o;if(t===R.COPY_TYPE.CUT){const c={unitId:i,drawings:[a]};this._commandService.executeCommand(Ce.id,c)}setTimeout(()=>{const c=_n();a.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&a.imageSourceType===P.ImageSourceType.BASE64?wn(a.source):this._clipboardInterfaceService.writeText(""),c()},200);const s={unitId:a.unitId,subUnitId:a.subUnitId,drawings:[a]};this._copyInfo=s}else{const a=this._createDrawingsCopyInfoByRange(i,n,e);this._copyInfo=a}},onPasteCells:(i,n,e,t)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=R.COPY_TYPE.COPY,pasteType:a}=t,{range:s}=i||{},{range:c,unitId:m,subUnitId:u}=n;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:a,unitId:m,subUnitId:u,pasteRange:c},{copyRange:s,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:n,pasteType:a},R.COPY_TYPE.COPY)},onPastePlainText:(i,n)=>({undos:[],redos:[]}),onPasteUnrecognized:i=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:i,pasteType:R.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},R.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(i,n)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:i,pasteType:R.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},R.COPY_TYPE.COPY);{const e=n.filter(t=>t.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Ne.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(i,n,e){var h;const t=(h=this._renderManagerService.getRenderById(i))==null?void 0:h.with(R.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:s,startY:c,endY:m}=o,u=this._drawingService.getDrawingData(i,n),d=this._focusedDrawings.slice();if(Object.keys(u).forEach(g=>{const p=u[g],{transform:S}=p;if(p.anchorType!==w.SheetDrawingAnchorType.Both||!S)return;const{left:f=0,top:_=0,width:I=0,height:M=0}=S,{drawingStartX:b,drawingEndX:y,drawingStartY:T,drawingEndY:C}={drawingStartX:f,drawingEndX:f+I,drawingStartY:_,drawingEndY:_+M};a<=b&&y<=s&&c<=T&&C<=m&&d.push(p)}),d.length)return{copyRange:e,drawings:d,unitId:i,subUnitId:n}}_generateSingleDrawingPasteMutations(i,n){const{pasteType:e,pasteTo:t}=i;if(At.includes(e))return{redos:[],undos:[]};const{unitId:o,subUnitId:a,range:s}=t,c=this._renderManagerService.getRenderById(o),m=c==null?void 0:c.with(R.SheetSkeletonManagerService),u=c==null?void 0:c.with(R.ISheetSelectionRenderService),d=this._copyInfo;if(!m||!u)return{redos:[],undos:[]};const{drawings:h}=d,g=R.discreteRangeToRange(s);return this._generateMutations(h,{unitId:o,subUnitId:a,isCut:n===R.COPY_TYPE.CUT,getTransform:(p,S)=>{var I;const f=m.attachRangeWithCoord({startRow:g.startRow,endRow:g.endRow,startColumn:g.startColumn,endColumn:g.endColumn}),_={...p,left:f==null?void 0:f.startX,top:f==null?void 0:f.startY};return{transform:_,sheetTransform:(I=V(_,u))!=null?I:S}}})}_generateMutations(i,n){const{unitId:e,subUnitId:t,getTransform:o,isCut:a}=n,s=[],c=[],{_drawingService:m}=this;return i.forEach(u=>{const{transform:d,sheetTransform:h}=u;if(!d)return;const g=o(d,h),p={...u,unitId:e,subUnitId:t,drawingId:a?u.drawingId:l.Tools.generateRandomId(),transform:g.transform,sheetTransform:g.sheetTransform};if(a){const{undo:S,redo:f,objects:_}=m.getBatchUpdateOp([p]);s.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,type:w.DrawingApplyType.UPDATE,op:f,objects:_}}),c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,type:w.DrawingApplyType.UPDATE,op:S,objects:_}})}else{const{undo:S,redo:f,objects:_}=m.getBatchAddOp([p]);s.push({id:w.SetDrawingApplyMutation.id,params:{op:f,unitId:e,subUnitId:t,objects:_,type:w.DrawingApplyType.INSERT}}),c.push({id:w.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:t,objects:_,type:w.DrawingApplyType.REMOVE}})}}),{redos:s,undos:c}}_generateRangeDrawingsPasteMutations(i,n){var j;const{unitId:e,subUnitId:t,pasteType:o,pasteRange:a}=i,{copyRange:s,copyType:c}=n;if(At.includes(o))return{redos:[],undos:[]};const m=(j=this._renderManagerService.getRenderById(e))==null?void 0:j.with(R.SheetSkeletonManagerService);if(!m||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!s)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:t,range:R.discreteRangeToRange(a)},pasteType:o},c);const{ranges:[d,h],mapFunc:g}=R.virtualizeDiscreteRanges([s,a]),{row:p,col:S}=g(d.startRow,d.startColumn),{row:f,col:_}=g(h.startRow,h.startColumn),I=m.attachRangeWithCoord({startRow:p,endRow:p,startColumn:S,endColumn:S}),M=m.attachRangeWithCoord({startRow:f,endRow:f,startColumn:_,endColumn:_});if(!I||!M||!this._copyInfo)return{redos:[],undos:[]};const b=M.startX-I.startX,y=M.startY-I.startY,T=f-p,C=_-S;return this._generateMutations(u,{unitId:e,subUnitId:t,getTransform:(O,L)=>{var U,A;return{transform:{...O,left:((U=O==null?void 0:O.left)!=null?U:0)+b,top:((A=O==null?void 0:O.top)!=null?A:0)+y},sheetTransform:{...L,to:{...L.to,row:L.to.row+T,column:L.to.column+C},from:{...L.from,row:L.from.row+T,column:L.from.column+C}}}},isCut:c===R.COPY_TYPE.CUT})}};Ke=fn([je(0,R.ISheetClipboardService),je(1,N.IRenderManagerService),je(2,P.IDrawingManagerService),je(3,F.IClipboardInterfaceService),je(4,l.ICommandService)],Ke);var vn=Object.defineProperty,In=Object.getOwnPropertyDescriptor,Cn=(r,i,n,e)=>{for(var t=e>1?void 0:e?In(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&vn(i,n,t),t},We=(r,i)=>(n,e)=>i(n,e,r);let ze=class extends l.Disposable{constructor(r,i,n,e,t){super(),this._drawingManagerService=r,this._renderManagerService=i,this._permissionService=n,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{if(!i){this._drawingManagerService.setDrawingVisible(!1);return}i.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=i.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new v.WorkbookViewPermission(t).id,new v.WorksheetViewPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const s=i.getUnitId(),c=e.getSheetId(),m=this._drawingManagerService.getDrawingData(s,c),u=Object.values(m),d=this._renderManagerService.getRenderById(s),h=d==null?void 0:d.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(p=>{p.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>p.oKey.includes(S.drawingId))&&h.removeObject(p)})}})}))}_initDrawingEditable(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{if(!i){this._drawingManagerService.setDrawingEditable(!1);return}i.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=i.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new v.WorkbookEditablePermission(t).id,new v.WorksheetEditPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const s=i.getUnitId(),c=e.getSheetId(),m=this._drawingManagerService.getDrawingData(s,c),u=Object.values(m),d=this._renderManagerService.getRenderById(s),h=d==null?void 0:d.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(p=>{p.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>p.oKey.includes(S.drawingId))&&h.detachTransformerFrom(p)})}})}))}_initViewPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{i&&i.activeSheet$.subscribe(e=>{var d;if(!e)return;const t=i.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),c=s==null?void 0:s.scene;if(c==null)return;const m=c.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookViewPermission(t).id,new v.WorksheetViewPermission(t,o).id]).pipe(W.map(h=>h.every(g=>g.value)));u==null||u.pipe(W.filter(h=>h!==a),W.distinctUntilChanged()).subscribe({next:h=>{a=h,this._drawingManagerService.setDrawingVisible(h);const g=c.getAllObjectsByOrder(),p=this._drawingManagerService.getDrawingData(t,o),S=Object.values(p);h?this._drawingManagerService.addNotification(S):(g.forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(_=>f.oKey.includes(_.drawingId))&&c.removeObject(f)}),m.clearSelectedObjects())}}),(d=this._permissionService.getPermissionPoint$(new v.WorksheetViewPermission(t,o).id))==null||d.pipe(W.filter(h=>h.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const h=this._drawingManagerService.getDrawingData(t,o),g=Object.values(h);this._drawingManagerService.addNotification(g)}})})}))}_initEditPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{i&&i.activeSheet$.subscribe(e=>{var d;if(!e)return;const t=i.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),c=s==null?void 0:s.scene;if(c==null)return;const m=c.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookEditablePermission(t).id,new v.WorksheetEditPermission(t,o).id]).pipe(W.map(h=>h.every(g=>g.value)));u==null||u.pipe(W.filter(h=>h!==a),W.distinctUntilChanged()).subscribe({next:h=>{a=h,this._drawingManagerService.setDrawingEditable(h);const g=c.getAllObjectsByOrder(),p=this._drawingManagerService.getDrawingData(t,o),S=Object.values(p);h?(g.forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(_=>f.oKey.includes(_.drawingId))&&c.attachTransformerTo(f)}),this._drawingManagerService.addNotification(S)):(g.forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(_=>f.oKey.includes(_.drawingId))&&c.detachTransformerFrom(f)}),m.clearSelectedObjects())}}),(d=this._permissionService.getPermissionPoint$(new v.WorksheetEditPermission(t,o).id))==null||d.pipe(W.filter(h=>h.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const h=i.getUnitId(),g=e.getSheetId(),p=this._drawingManagerService.getDrawingData(h,g),S=Object.values(p),f=this._renderManagerService.getRenderById(h),_=f==null?void 0:f.scene;if(_==null)return;this._drawingManagerService.setDrawingEditable(!0),_.getAllObjectsByOrder().forEach(M=>{M.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(b=>M.oKey.includes(b.drawingId))&&_.detachTransformerFrom(M)})}})})}))}};ze=Cn([We(0,P.IDrawingManagerService),We(1,N.IRenderManagerService),We(2,l.IPermissionService),We(3,l.IUniverInstanceService),We(4,l.Inject(l.UserManagerService))],ze);var yn=Object.defineProperty,Dn=Object.getOwnPropertyDescriptor,Mn=(r,i,n,e)=>{for(var t=e>1?void 0:e?Dn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&yn(i,n,t),t},qe=(r,i)=>(n,e)=>i(n,e,r);let Ze=class extends l.Disposable{constructor(r,i,n,e){super(),this._sheetPrintInterceptorService=r,this._drawingRenderService=i,this._drawingManagerService=n,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(r,i,n)=>{const{unitId:e,scene:t,subUnitId:o}=i,a=this._drawingManagerService.getDrawingDataForUnit(e),s=a==null?void 0:a[o];return s&&s.order.forEach(c=>{this._drawingRenderService.renderDrawing(s.data[c],t)}),n()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(r,i,n)=>{const{unitId:e,subUnitId:t}=i,o=this._renderManagerService.getRenderById(e);if(!o)return n(r);const a=o.with(R.SheetSkeletonManagerService).getSkeletonParam(t);if(!a)return n(r);const s=this._drawingManagerService.getDrawingDataForUnit(e),c=s==null?void 0:s[i.subUnitId];if(!c)return n(r);const{scaleX:m,scaleY:u}=o.scene,d=r?{...r}:{startColumn:0,endColumn:0,endRow:0,startRow:0},h=c.order.map(g=>c.data[g]).filter(g=>g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM);return h.length?(h.forEach(g=>{if(!g.groupId&&g.transform&&l.Tools.isDefine(g.transform.left)&&l.Tools.isDefine(g.transform.top)&&l.Tools.isDefine(g.transform.width)&&l.Tools.isDefine(g.transform.height)){const p=a.skeleton.getCellIndexByOffset(g.transform.left,g.transform.top,m,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(g.transform.left+g.transform.width,g.transform.top+g.transform.height,m,u,{x:0,y:0});p.column<d.startColumn&&(d.startColumn=p.column),p.row<d.startRow&&(d.startRow=p.row),d.endRow<S.row&&(d.endRow=S.row),d.endColumn<S.column&&(d.endColumn=S.column)}}),n(d)):n(r)}}))}};Ze=Mn([qe(0,l.Inject(R.SheetPrintInterceptorService)),qe(1,l.Inject(ge.DrawingRenderService)),qe(2,P.IDrawingManagerService),qe(3,N.IRenderManagerService)],Ze);var Tn=Object.defineProperty,bn=Object.getOwnPropertyDescriptor,Rn=(r,i,n,e)=>{for(var t=e>1?void 0:e?bn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Tn(i,n,t),t},me=(r,i)=>(n,e)=>i(n,e,r);const En=[v.InsertRowCommand.id,v.InsertColCommand.id,v.RemoveRowCommand.id,v.RemoveColCommand.id,v.DeleteRangeMoveLeftCommand.id,v.DeleteRangeMoveUpCommand.id,v.InsertRangeMoveDownCommand.id,v.InsertRangeMoveRightCommand.id,v.DeltaRowHeightCommand.id,v.SetRowHeightCommand.id,v.DeltaColumnWidthCommand.id,v.SetColWidthCommand.id,v.SetRowHiddenCommand.id,v.SetSpecificRowsVisibleCommand.id,v.SetSpecificColsVisibleCommand.id,v.SetColHiddenCommand.id,v.MoveColsCommand.id,v.MoveRowsCommand.id,v.MoveRangeCommand.id],On=[v.SetRowVisibleMutation.id,v.SetRowHiddenMutation.id,v.SetColVisibleMutation.id,v.SetColHiddenMutation.id,v.SetWorksheetRowHeightMutation.id,v.SetWorksheetColWidthMutation.id];let vt=class extends l.Disposable{constructor(r,i,n,e,t,o,a,s,c){super(),this._context=r,this._renderManagerService=i,this._commandService=n,this._selectionRenderService=e,this._skeletonManagerService=t,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._univerInstanceService=c,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(!En.includes(r.id))return{redos:[],undos:[]};if(r.params==null)return{redos:[],undos:[]};const i=r.id;if(i===v.InsertRowCommand.id)return this._moveRowInterceptor(r.params,"insert");if([v.MoveColsCommand.id,v.MoveRowsCommand.id,v.MoveRangeCommand.id].includes(i))return this._moveRangeInterceptor(r.params);if(i===v.InsertColCommand.id)return this._moveColInterceptor(r.params,"insert");if(i===v.RemoveRowCommand.id)return this._moveRowInterceptor(r.params,"remove");if(i===v.RemoveColCommand.id)return this._moveColInterceptor(r.params,"remove");if(i===v.DeleteRangeMoveLeftCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,0)}else if(i===v.DeleteRangeMoveUpCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,1)}else if(i===v.InsertRangeMoveDownCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,2)}else if(i===v.InsertRangeMoveRightCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,3)}else if(i===v.SetRowHiddenCommand.id||i===v.SetSpecificRowsVisibleCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForRowVisible(e,t,o)}else if(i===v.SetSpecificColsVisibleCommand.id||i===v.SetColHiddenCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForColVisible(e,t,o)}else if(i===v.DeltaRowHeightCommand.id||i===v.SetRowHeightCommand.id||i===v.DeltaColumnWidthCommand.id||i===v.SetColWidthCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n,a=i===v.DeltaRowHeightCommand.id||i===v.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(r,i){const n=v.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const e=n.unitId,t=n.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(e,t),c=[],m=[];if(Object.keys(s).forEach(u=>{const d=s[u],{updateDrawings:h,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(r,i,d);c.push(...h),m.push(...g)}),c.length===0&&m.length===0)return{redos:[],undos:[]};if(c.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(c),{undo:d,redo:h,objects:g}=u;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:h,objects:g,type:w.DrawingApplyType.UPDATE}}),a.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:d,objects:g,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(m),d=u.undo,h=u.redo,g=u.objects;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:h,objects:g,type:w.DrawingApplyType.REMOVE}}),a.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:d,objects:g,type:w.DrawingApplyType.INSERT}})}return o.push({id:H.id,params:[e]}),a.push({id:H.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(r,i,n){const e=[],t=[],{sheetTransform:o,anchorType:a=w.SheetDrawingAnchorType.Position,transform:s,unitId:c,subUnitId:m,drawingId:u}=n,{from:d,to:h}=o,{row:g,column:p}=d,{row:S,column:f}=h;if(o==null||s==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:_,endRow:I,startColumn:M,endColumn:b}=r;let y=null,T=null;if(i===0&&g>=_&&S<=I)if(p>=M&&f<=b)t.push({unitId:c,subUnitId:m,drawingId:u});else{const C=this._shrinkCol(o,s,M,b,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}else if(i===1&&p>=M&&f<=b)if(g>=_&&S<=I)t.push({unitId:c,subUnitId:m,drawingId:u});else{const C=this._shrinkRow(o,s,_,I,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}else if(i===2){const C=this._expandRow(o,s,_,I,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}else if(i===3){const C=this._expandCol(o,s,M,b,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}if(y!=null&&T!=null){const C=x(y,this._selectionRenderService,this._skeletonManagerService);e.push({...n,sheetTransform:y,transform:C})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(r,i,n){const e=V({...r},this._selectionRenderService);e!=null&&i.push({...n,sheetTransform:e})}_getDrawingUndoForColVisible(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:h,transform:g,anchorType:p=w.SheetDrawingAnchorType.Position}=d;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,d);else{const{from:S,to:f}=h,{row:_,column:I}=S,{row:M,column:b}=f;for(let y=0;y<n.length;y++){const T=n[y],{startRow:C,endRow:j,startColumn:O,endColumn:L}=T;if(b<O)continue;if(p===w.SheetDrawingAnchorType.Position){let D=null,B=null;if(I>=O&&I<=L){const k=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:L,startRow:S.row,endRow:f.row});if(k==null)return;B={...g,left:k.startX}}if(B!=null&&(D=V(B,this._selectionRenderService),D!=null&&B!=null)){t.push({...d,sheetTransform:D,transform:B});break}this._remainDrawingSize(g,t,d);continue}if(I>=O&&b<=L)continue;let U=null,A=null;if(I>=O&&I<=L){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:L,startRow:S.row,endRow:f.row});if(D==null)return;A={...g,left:(D==null?void 0:D.startX)||0,width:((g==null?void 0:g.width)||0)-D.endX+D.startX}}else if(b>=O&&b<=L){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:b,startRow:S.row,endRow:f.row});if(D==null)return;A={...g,left:D.startX-((g==null?void 0:g.width)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:L,startRow:S.row,endRow:f.row});if(D==null)return;if(A={...g,width:((g==null?void 0:g.width)||0)-D.endX+D.startX},U=V(A,this._selectionRenderService),U!=null&&A!=null){o.push({...d,sheetTransform:U,transform:A});break}}if(A!=null&&(U=V(A,this._selectionRenderService)),A!=null&&U!=null){t.push({...d,sheetTransform:U,transform:A});break}else this._remainDrawingSize(g,t,d)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(r,i,t),c=[],m=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(r,i,o);c.push(...u),m.push(...d)}return{redos:a,undos:s,preRedos:c,preUndos:m}}_createUndoAndRedoMutation(r,i,n){const e=this._sheetDrawingService.getBatchUpdateOp(n),{undo:t,redo:o,objects:a}=e,s=[{id:w.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,op:o,objects:a,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[r]}],c=[{id:w.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,op:t,objects:a,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[r]}];return{redos:s,undos:c}}_getDrawingUndoForRowVisible(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:h,transform:g,anchorType:p=w.SheetDrawingAnchorType.Position}=d;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,d);else{const{from:S,to:f}=h,{row:_,column:I}=S,{row:M,column:b}=f;for(let y=0;y<n.length;y++){const T=n[y],{startRow:C,endRow:j,startColumn:O,endColumn:L}=T;if(M<C)continue;if(p===w.SheetDrawingAnchorType.Position){let D=null,B=null;if(_>=C&&_<=j){const k=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:_,endRow:j});if(k==null)return;B={...g,top:k.startY}}if(B!=null&&(D=V(B,this._selectionRenderService),D!=null&&B!=null)){t.push({...d,sheetTransform:D,transform:B});break}this._remainDrawingSize(g,t,d);continue}if(_>=C&&M<=j)continue;let U=null,A=null;if(_>=C&&_<=j){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:_,endRow:j});if(D==null)return;A={...g,top:(D==null?void 0:D.startY)||0,height:((g==null?void 0:g.height)||0)-D.endY+D.startY}}else if(M>=C&&M<=j){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:C,endRow:M});if(D==null)return;A={...g,top:D.startY-((g==null?void 0:g.height)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:C,endRow:j});if(D==null)return;if(A={...g,height:((g==null?void 0:g.height)||0)-D.endY+D.startY},U=V(A,this._selectionRenderService),U!=null&&A!=null){o.push({...d,sheetTransform:U,transform:A});break}}if(A!=null&&(U=V(A,this._selectionRenderService)),A!=null&&U!=null){t.push({...d,sheetTransform:U,transform:A});break}else this._remainDrawingSize(g,t,d)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(r,i,t),c=[],m=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(r,i,o);c.push(...u),m.push(...d)}return{redos:a,undos:s,preRedos:c,preUndos:m}}_getDrawingUndoForRowAndColSize(r,i,n,e){const t=this._drawingManagerService.getDrawingData(r,i),o=[];return Object.keys(t).forEach(a=>{const s=t[a],{sheetTransform:c,transform:m,anchorType:u=w.SheetDrawingAnchorType.Position}=s;if(u===w.SheetDrawingAnchorType.None)this._remainDrawingSize(m,o,s);else{const{from:d,to:h}=c,{row:g,column:p}=d,{row:S,column:f}=h;for(let _=0;_<n.length;_++){const I=n[_],{startRow:M,endRow:b,startColumn:y,endColumn:T}=I;if(S<M||f<y)continue;if(u===w.SheetDrawingAnchorType.Position&&(g<=M&&S>=b||p<=y&&f>=T)){this._remainDrawingSize(m,o,s);continue}const C=x({...c},this._selectionRenderService,this._skeletonManagerService);if(C!=null){o.push({...s,transform:C});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(r,i,o)}_getUnitIdAndSubUnitId(r,i){let n,e;if(i==="insert")n=r.unitId,e=r.subUnitId;else{const t=v.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;n=t.unitId,e=t.subUnitId}return{unitId:n,subUnitId:e}}_moveRangeInterceptor(r){var M,b;const{toRange:i,fromRange:n}=r,e=v.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,a=(b=(M=this._renderManagerService.getRenderById(t))==null?void 0:M.with(R.SheetSkeletonManagerService))==null?void 0:b.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=R.attachRangeWithCoord(a,n);if(!s)return{redos:[],undos:[]};const{startX:c,endX:m,startY:u,endY:d}=s,h=this._sheetDrawingService.getDrawingData(t,o),g=[];Object.keys(h).forEach(y=>{const T=h[y];if(T.anchorType!==w.SheetDrawingAnchorType.Both)return;const{transform:C}=T;if(!C)return;const{left:j=0,top:O=0,width:L=0,height:U=0}=C,{drawingStartX:A,drawingEndX:D,drawingStartY:B,drawingEndY:k}={drawingStartX:j,drawingEndX:j+L,drawingStartY:O,drawingEndY:O+U};c<=A&&D<=m&&u<=B&&k<=d&&g.push(T)});const p=[],S=[],f=i.startRow-n.startRow,_=i.startColumn-n.startColumn,I=g.map(y=>{const T=y.sheetTransform,C={to:{...T.to,row:T.to.row+f,column:T.to.column+_},from:{...T.from,row:T.from.row+f,column:T.from.column+_}},j=x(C,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:y.drawingId,transform:j,sheetTransform:C}});if(I.length){const y=this._sheetDrawingService.getBatchUpdateOp(I),{undo:T,redo:C,objects:j}=y;p.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:C,objects:j,type:w.DrawingApplyType.UPDATE}}),S.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:T,objects:j,type:w.DrawingApplyType.UPDATE}})}return{redos:p,undos:S}}_moveRowInterceptor(r,i){const n=this._getUnitIdAndSubUnitId(r,i);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=r,a=o.startRow,s=o.endRow,c=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),d=[],h=[];if(Object.keys(u).forEach(g=>{const p=u[g],{sheetTransform:S,transform:f,anchorType:_=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let I,M;if(i==="insert"){const y=this._expandRow(S,f,a,s,_);I=y==null?void 0:y.newSheetTransform,M=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{row:C}=y,{row:j}=T;if(_===w.SheetDrawingAnchorType.Both&&C>=a&&j<=s)h.push({unitId:e,subUnitId:t,drawingId:g});else{const O=this._shrinkRow(S,f,a,s,_);I=O==null?void 0:O.newSheetTransform,M=O==null?void 0:O.newTransform}}if(!I||!M)return;const b={unitId:e,subUnitId:t,drawingId:g,transform:M,sheetTransform:I};d.push(b)}),d.length===0&&h.length===0)return{redos:[],undos:[]};if(d.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(d),{undo:p,redo:S,objects:f}=g;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),p=g.undo,S=g.redo,f=g.objects;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return c.push({id:H.id,params:[e]}),m.push({id:H.id,params:[e]}),{redos:c,undos:m}}_moveColInterceptor(r,i){const n=this._getUnitIdAndSubUnitId(r,i);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=r,a=o.startColumn,s=o.endColumn,c=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),d=[],h=[];if(Object.keys(u).forEach(g=>{const p=u[g],{sheetTransform:S,transform:f,anchorType:_=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let I,M;if(i==="insert"){const y=this._expandCol(S,f,a,s,_);I=y==null?void 0:y.newSheetTransform,M=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{column:C}=y,{column:j}=T;if(_===w.SheetDrawingAnchorType.Both&&C>=a&&j<=s)h.push({unitId:e,subUnitId:t,drawingId:g});else{const O=this._shrinkCol(S,f,a,s,_);I=O==null?void 0:O.newSheetTransform,M=O==null?void 0:O.newTransform}}if(!I||!M)return;const b={unitId:e,subUnitId:t,drawingId:g,transform:M,sheetTransform:I};d.push(b)}),d.length===0&&h.length===0)return{redos:[],undos:[]};if(d.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(d),{undo:p,redo:S,objects:f}=g;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),p=g.undo,S=g.redo,f=g.objects;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return c.push({id:H.id,params:[e]}),m.push({id:H.id,params:[e]}),{redos:c,undos:m}}_expandCol(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{column:c}=a,{column:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,d=null;if(c>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:e,startRow:a.row,endRow:s.row});if(h==null)return;d={...i,left:(i.left||0)+h.endX-h.startX},u=V(d,this._selectionRenderService)}else if(m>=e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m+o}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkCol(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{column:c}=a,{column:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,d=null;if(c>e)u={from:{...a,column:c-o},to:{...s,column:m-o}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else{if(c>=n&&m<=e)return null;if(c<n&&m>e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m-o}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};else if(c>=n&&c<=e){if(c===n)d={...i,left:(i.left||0)-r.from.columnOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:c-1,startRow:a.row,endRow:s.row});if(h==null)return;d={...i,left:(i.left||0)-h.endX+h.startX-r.from.columnOffset}}u=V(d,this._selectionRenderService)}else if(m>=n&&m<=e&&t===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n-1,endColumn:n-1,startRow:a.row,endRow:s.row});if(h==null)return;u={from:{...a},to:{...s,column:n-1,columnOffset:h.endX-h.startX}},d=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_expandRow(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{row:c}=a,{row:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,d=null;if(c>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:e,startColumn:a.column,endColumn:s.column});if(h==null)return;d={...i,top:(i.top||0)+h.endY-h.startY},u=V(d,this._selectionRenderService)}else if(m>=e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m+o}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkRow(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{row:c}=a,{row:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,d=null;if(c>e)u={from:{...a,row:c-o},to:{...s,row:m-o}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else{if(c>=n&&m<=e)return null;if(c<n&&m>e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m-o}},d=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};else if(c>=n&&c<=e){if(c===n)d={...i,top:(i.top||0)-r.from.rowOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:c-1,startColumn:a.column,endColumn:s.column});if(h==null)return;d={...i,top:(i.top||0)-h.endY+h.startY-r.from.rowOffset}}u=V(d,this._selectionRenderService)}else if(m>=n&&m<=e&&t===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:n-1,endRow:n-1});if(h==null)return;u={from:{...a},to:{...s,row:n-1,rowOffset:h.endY-h.startY}},d=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===v.SetWorksheetActiveOperation.id){const{unitId:i,subUnitId:n}=r.params;this._updateDrawings(i,n)}})),this.disposeWithMe(this._context.activated$.subscribe(r=>{const{unit:i,unitId:n}=this._context;if(r){const e=i.getActiveSheet().getSheetId();this._updateDrawings(n,e)}else this._clearDrawings(n)}))}_clearDrawings(r){setTimeout(()=>{const i=this._drawingManagerService.drawingManagerData,n=[];Object.keys(i).forEach(e=>{const t=i[e];t!=null&&Object.keys(t).forEach(o=>{const a=t[o].data;a!=null&&Object.keys(a).forEach(s=>{e===r&&n.push(a[s])})})}),this._drawingManagerService.removeNotification(n)})}_updateDrawings(r,i){setTimeout(()=>{const n=this._drawingManagerService.drawingManagerData,e=[],t=[];Object.keys(n).forEach(o=>{const a=n[o];a!=null&&Object.keys(a).forEach(s=>{const c=a[s].data;c!=null&&Object.keys(c).forEach(m=>{if(o===r&&s===i){const u=c[m];u.transform=x(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(c[m])}else t.push(c[m])})})}),this._drawingManagerService.removeNotification(t),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{On.includes(r.id)&&requestIdleCallback(()=>{const i=r.params,{unitId:n,subUnitId:e,ranges:t}=i;this._refreshDrawingTransform(n,e,t)})}))}_refreshDrawingTransform(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:s,transform:c,anchorType:m=w.SheetDrawingAnchorType.Position}=a;if(m===w.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=s,{row:h,column:g}=u,{row:p,column:S}=d;for(let f=0;f<n.length;f++){const _=n[f],{startRow:I,endRow:M,startColumn:b,endColumn:y}=_;if(l.Rectangle.intersects({startRow:I,endRow:M,startColumn:b,endColumn:y},{startRow:h,endRow:p,startColumn:g,endColumn:S})||h>M||g>y){const T=m===w.SheetDrawingAnchorType.Position,C=x(s,this._selectionRenderService,this._skeletonManagerService);t.push({...a,transform:{...C,width:T?c==null?void 0:c.width:C==null?void 0:C.width,height:T?c==null?void 0:c.height:C==null?void 0:C.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(H.id,[r]))}};vt=Rn([me(1,N.IRenderManagerService),me(2,l.ICommandService),me(3,R.ISheetSelectionRenderService),me(4,l.Inject(R.SheetSkeletonManagerService)),me(5,l.Inject(v.SheetInterceptorService)),me(6,w.ISheetDrawingService),me(7,P.IDrawingManagerService),me(8,l.IUniverInstanceService)],vt);var J=function(){return J=Object.assign||function(r){for(var i,n=1,e=arguments.length;n<e;n++){i=arguments[n];for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&(r[t]=i[t])}return r},J.apply(this,arguments)},Pn=function(r,i){var n={};for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&i.indexOf(e)<0&&(n[e]=r[e]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(r);t<e.length;t++)i.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(r,e[t])&&(n[e[t]]=r[e[t]]);return n},Ut=q.forwardRef(function(r,i){var n=r.icon,e=r.id,t=r.className,o=r.extend,a=Pn(r,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),c=q.useRef("_".concat(Nn()));return Nt(n,"".concat(e),{defIds:n.defIds,idSuffix:c.current},J({ref:i,className:s},a),o)});function Nt(r,i,n,e,t){return q.createElement(r.tag,J(J({key:i},An(r,n,t)),e),(Un(r,n).children||[]).map(function(o,a){return Nt(o,"".concat(i,"-").concat(r.tag,"-").concat(a),n,void 0,t)}))}function An(r,i,n){var e=J({},r.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var t=i.defIds;return!t||t.length===0||(r.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+i.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(i.idSuffix,")")))})),e}function Un(r,i){var n,e=i.defIds;return!e||e.length===0?r:r.tag==="defs"&&(!((n=r.children)===null||n===void 0)&&n.length)?J(J({},r),{children:r.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?J(J({},t),{attrs:J(J({},t.attrs),{id:t.attrs.id+i.idSuffix})}):t})}):r}function Nn(){return Math.random().toString(36).substring(2,8)}Ut.displayName="UniverIcon";var jn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z"}}]},jt=q.forwardRef(function(r,i){return q.createElement(Ut,Object.assign({},r,{id:"add-image-single",ref:i,icon:jn}))});jt.displayName="AddImageSingle";const It={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:r=>{const i=r.get(l.ICommandService),e=r.get(w.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(a=>{const{unitId:s,subUnitId:c,drawingId:m,drawingType:u}=a;return{unitId:s,subUnitId:c,drawingId:m,drawingType:u}});return i.executeCommand(Ce.id,{unitId:t,drawings:o})}},ye={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(w.ISheetDrawingService),t=r.get(R.ISheetSelectionRenderService),{direction:o}=i,a=e.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,c=a.map(u=>{const{transform:d}=u;if(d==null)return null;const h={...d},{left:g=0,top:p=0}=d;return o===l.Direction.UP?h.top=p-1:o===l.Direction.DOWN?h.top=p+1:o===l.Direction.LEFT?h.left=g-1:o===l.Direction.RIGHT&&(h.left=g+1),{...u,transform:h,sheetTransform:V(h,t)}}).filter(u=>u!=null);return n.syncExecuteCommand(Ae.id,{unitId:s,drawings:c})?(n.syncExecuteCommand(H.id,[s]),!0):!1}},Wt="addition-and-subtraction-single",Ct="sheet.menu.image";function Wn(r){return{id:Ct,type:F.MenuItemType.SUBITEMS,icon:Wt,tooltip:"sheetImage.title",hidden$:F.getMenuHiddenObservable(r,l.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(r,{workbookTypes:[v.WorkbookEditablePermission],worksheetTypes:[v.WorksheetEditPermission],rangeTypes:[v.RangeProtectionPermissionEditPoint]})}}function Bn(r){return{id:Ne.id,title:"sheetImage.upload.float",type:F.MenuItemType.BUTTON,hidden$:F.getMenuHiddenObservable(r,l.UniverInstanceType.UNIVER_SHEET)}}function kn(r){return{id:_t.id,title:"sheetImage.upload.cell",type:F.MenuItemType.BUTTON}}const pe={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelSubtitle:"univer-image-common-panel-subtitle",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"};function Bt(r){var i,n,e="";if(typeof r=="string"||typeof r=="number")e+=r;else if(typeof r=="object")if(Array.isArray(r)){var t=r.length;for(i=0;i<t;i++)r[i]&&(n=Bt(r[i]))&&(e&&(e+=" "),e+=n)}else for(n in r)r[n]&&(e&&(e+=" "),e+=n);return e}function Je(){for(var r,i,n=0,e="",t=arguments.length;n<t;n++)(r=arguments[n])&&(i=Bt(r))&&(e&&(e+=" "),e+=i);return e}const Ln=r=>{var M;const i=l.useDependency(l.ICommandService),n=l.useDependency(l.LocaleService),e=l.useDependency(P.IDrawingManagerService),t=l.useDependency(N.IRenderManagerService),{drawings:o}=r,a=o[0];if(a==null)return;const{unitId:s}=a,c=t.getRenderById(s),m=c==null?void 0:c.scene;if(m==null)return;const u=m.getTransformerByCreate(),[d,h]=q.useState(!0),g=(M=a.anchorType)!=null?M:w.SheetDrawingAnchorType.Position,[p,S]=q.useState(g);function f(b,y){const T=[];return b.forEach(C=>{const{oKey:j}=C,O=y.getDrawingOKey(j);if(O==null)return T.push(null),!0;const{unitId:L,subUnitId:U,drawingId:A,drawingType:D,anchorType:B,sheetTransform:k}=O;T.push({unitId:L,subUnitId:U,drawingId:A,anchorType:B,sheetTransform:k,drawingType:D})}),T}q.useEffect(()=>{const b=u.clearControl$.subscribe(T=>{T===!0&&h(!1)}),y=u.changeStart$.subscribe(T=>{var O;const{objects:C}=T,j=f(C,e);if(j.length===0)h(!1);else if(j.length>=1){h(!0);const L=((O=j[0])==null?void 0:O.anchorType)||w.SheetDrawingAnchorType.Position;S(L)}});return()=>{y.unsubscribe(),b.unsubscribe()}},[]);function _(b){S(b);const y=e.getFocusDrawings();if(y.length===0)return;const T=y.map(C=>({unitId:C.unitId,subUnitId:C.subUnitId,drawingId:C.drawingId,anchorType:b}));i.executeCommand(Ae.id,{unitId:y[0].unitId,drawings:T})}const I=b=>b?"block":"none";return X.jsxs("div",{className:Je(pe.imageCommonPanelGrid,pe.imageCommonPanelBorder),style:{display:I(d)},children:[X.jsx("div",{className:pe.imageCommonPanelRow,children:X.jsx("div",{className:Je(pe.imageCommonPanelColumn,pe.imageCommonPanelTitle),children:X.jsx("div",{children:n.t("drawing-anchor.title")})})}),X.jsx("div",{className:Je(pe.imageCommonPanelRow),children:X.jsx("div",{className:Je(pe.imageCommonPanelColumn),children:X.jsxs(ee.RadioGroup,{value:p,onChange:_,direction:"vertical",children:[X.jsx(ee.Radio,{value:w.SheetDrawingAnchorType.Both,children:n.t("drawing-anchor.both")}),X.jsx(ee.Radio,{value:w.SheetDrawingAnchorType.Position,children:n.t("drawing-anchor.position")}),X.jsx(ee.Radio,{value:w.SheetDrawingAnchorType.None,children:n.t("drawing-anchor.none")})]})})})]})},$n=()=>{const r=l.useDependency(P.IDrawingManagerService),i=r.getFocusDrawings(),[n,e]=q.useState(i);return q.useEffect(()=>{const t=r.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(n!=null&&n.length)&&X.jsxs("div",{className:pe.imageCommonPanel,children:[X.jsx(ge.DrawingCommonPanel,{drawings:n}),X.jsx(Ln,{drawings:n})]})},Yn={[F.RibbonStartGroup.FORMULAS_INSERT]:{[Ct]:{order:3,menuItemFactory:Wn,[Ne.id]:{order:0,menuItemFactory:Bn},[_t.id]:{order:1,menuItemFactory:kn}}}};function Be(r){return!r.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!r.getContextValue(l.EDITOR_ACTIVATED)&&!r.getContextValue(l.FOCUSING_PANEL_EDITOR)&&r.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const Gn={id:ye.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_DOWN,priority:100,preconditions:Be,staticParameters:{direction:l.Direction.DOWN}},Fn={id:ye.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_UP,priority:100,preconditions:Be,staticParameters:{direction:l.Direction.UP}},Hn={id:ye.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_LEFT,priority:100,preconditions:Be,staticParameters:{direction:l.Direction.LEFT}},Vn={id:ye.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_RIGHT,priority:100,preconditions:Be,staticParameters:{direction:l.Direction.RIGHT}},Xn={id:It.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:Be,binding:F.KeyCode.DELETE,mac:F.KeyCode.BACKSPACE};var xn=Object.defineProperty,Kn=Object.getOwnPropertyDescriptor,zn=(r,i,n,e)=>{for(var t=e>1?void 0:e?Kn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&xn(i,n,t),t},De=(r,i)=>(n,e)=>i(n,e,r);let Qe=class extends l.Disposable{constructor(r,i,n,e,t,o){super(),this._componentManager=r,this._menuManagerService=i,this._commandService=n,this._shortcutService=e,this._drawingManagerService=t,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const r=this._componentManager;this.disposeWithMe(r.register(Wt,jt)),this.disposeWithMe(r.register(Rt,$n))}_initMenus(){this._menuManagerService.mergeMenu(Yn)}_initCommands(){[Ne,_t,Pe,Ce,Ae,gt,H,ht,pt,St,ye,It,ft].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_initShortcuts(){[Gn,Fn,Hn,Vn,Xn].forEach(r=>{this.disposeWithMe(this._shortcutService.registerShortcut(r))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Qe=zn([De(0,l.Inject(F.ComponentManager)),De(1,F.IMenuManagerService),De(2,l.ICommandService),De(3,F.IShortcutService),De(4,P.IDrawingManagerService),De(5,l.Inject(v.SheetsSelectionsService))],Qe);var qn=Object.defineProperty,Zn=Object.getOwnPropertyDescriptor,Jn=(r,i,n,e)=>{for(var t=e>1?void 0:e?Zn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&qn(i,n,t),t},_e=(r,i)=>(n,e)=>i(n,e,r);function Qn(r,i,n,e,t){const{scaleX:o,scaleY:a}=i.getAncestorScale(),s=i.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN),c={left:!0,top:!0};if(!s)return{...r,absolute:c};const{left:m,right:u,top:d,bottom:h}=r;let{top:g,left:p,viewportScrollX:S,viewportScrollY:f}=s;const{boundsOfViewArea:_,scrollDirectionResponse:I}=t||{};_&&(l.Tools.isDefine(_.top)&&(g=_.top),l.Tools.isDefine(_.left)&&(p=_.left)),I==="HORIZONTAL"&&(f=0),I==="VERTICAL"&&(S=0);let M,b;m<p?(c.left=!0,M=(p+(m-p))*o,b=Math.max(Math.min((p+(u-p))*o,p*o),(u-S)*o)):(c.left=!1,M=Math.max((m-S)*o,p*o),b=Math.max((u-S)*o,p*o));let y,T;return d<g?(c.top=!0,y=(g+(d-g))*a,T=Math.max(Math.min((g+(u-g))*a,g*a),(h-f)*a)):(c.top=!1,y=Math.max((d-f)*a,g*a),T=Math.max((h-f)*a,g*a)),{left:M,right:b,top:y,bottom:T,absolute:c}}const se=(r,i,n,e,t)=>{const{scene:o}=i,{left:a,top:s,width:c,height:m,angle:u}=r,d={left:a,right:a+c,top:s,bottom:s+m},h=Qn(d,o,n,e,t),{scaleX:g,scaleY:p}=o.getAncestorScale();return{startX:h.left,endX:h.right,startY:h.top,endY:h.bottom,rotate:u,width:c*g,height:m*p,absolute:h.absolute}};E.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(n,e,t,o,a,s,c){super();z(this,"_domLayerMap",new Map);z(this,"_domLayerInfoMap",new Map);z(this,"_transformChange$",new W.Subject);z(this,"transformChange$",this._transformChange$.asObservable());z(this,"_add$",new W.Subject);z(this,"add$",this._add$.asObservable());z(this,"_remove$",new W.Subject);z(this,"remove$",this._remove$.asObservable());z(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=s,this._lifecycleService=c,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(W.filter(n=>n===l.LifecycleStages.Rendered),W.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(n,e){let t=this._domLayerMap.get(n);t||(t=new Map,this._domLayerMap.set(n,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(n){return this._domLayerInfoMap.get(n)}_getSceneAndTransformerByDrawingSearch(n){if(n==null)return;const e=this._renderManagerService.getRenderById(n),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:t,transformer:o,renderUnit:e,canvas:a}}_getFloatDomProps(n){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(n)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(n=>{n.forEach(e=>{var ne,ie,K;const{unitId:t,subUnitId:o,drawingId:a}=e,s=v.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),c=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(t,l.UniverInstanceType.UNIVER_SHEET);if(!m)return;const u=m.getActiveSheet().getSheetId();if(!c||!s)return;const d=(ne=this._renderManagerService.getRenderById(t))==null?void 0:ne.with(R.SheetSkeletonManagerService).getSkeletonParam(o);if(!d)return;const{transform:h,drawingType:g,data:p}=c;if(g!==l.DrawingTypeEnum.DRAWING_DOM&&g!==l.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(t);if(S==null)return;const{scene:f,canvas:_}=S;if(h==null)return!0;if(u!==o)return;const{left:I,top:M,width:b,height:y,angle:T,flipX:C,flipY:j,skewX:O,skewY:L}=h,U=P.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),A=f.getObject(U);if(A!=null){A.transformByState({left:I,top:M,width:b,height:y,angle:T,flipX:C,flipY:j,skewX:O,skewY:L});return}const D={left:I,top:M,width:b,height:y,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},B=g===l.DrawingTypeEnum.DRAWING_CHART;if(B){const G=p?p.backgroundColor:"white";D.fill=G,D.rotateEnabled=!1,p&&p.border&&(D.stroke=p.border),D.paintFirst="stroke",D.strokeWidth=1,D.borderEnabled=!1,D.radius=8}const k=new N.Rect(U,D);B&&k.setObjectType(N.ObjectType.CHART),f.addObject(k,N.DRAWING_OBJECT_LAYER_INDEX),c.allowTransform!==!1&&f.attachTransformerTo(k);const te=this._ensureMap(t,o),oe=new l.DisposableCollection,ve=se(k,S.renderUnit,d.skeleton,s.worksheet),ae=new W.BehaviorSubject(ve),Ie={dispose:oe,rect:k,position$:ae,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:ae,id:a,componentKey:c.componentKey,onPointerDown:G=>{_.dispatchEvent(new PointerEvent(G.type,G))},onPointerMove:G=>{_.dispatchEvent(new PointerEvent(G.type,G))},onPointerUp:G=>{_.dispatchEvent(new PointerEvent(G.type,G))},onWheel:G=>{_.dispatchEvent(new WheelEvent(G.type,G))},props:(K=(ie=te.get(a))==null?void 0:ie.props)!=null?K:this._getFloatDomProps(a),data:p,unitId:t});const ce=k.onTransformChange$.subscribeEvent(()=>{const G=se(k,S.renderUnit,d.skeleton,s.worksheet);ae.next(G)});oe.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),ce&&oe.add(ce),this._domLayerInfoMap.set(a,Ie),te.set(a,{...te.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a}=e,s=P.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),c=this._getSceneAndTransformerByDrawingSearch(t);if(c==null)return;const{transformer:m,scene:u}=c,d=u.getObject(s);d!=null&&d.oKey&&m.clearControlByIds([d==null?void 0:d.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,t),s=Array.from(a.keys()),c=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),m=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(R.SheetSkeletonManagerService).getSkeletonParam(t);!o||!c||!m||s.forEach(d=>{const h=this._domLayerInfoMap.get(d);if(h){const g=se(h.rect,o.renderUnit,m.skeleton,c.worksheet,h);h.position$.next(g)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.filter(e=>!!e),W.switchMap(e=>e.activeSheet$),W.filter(e=>!!e),W.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),W.filter(e=>!!e),W.switchMap(e=>l.fromEventSubject(e.render.scene.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(W.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{n(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===R.SetZoomRatioOperation.id){const a=e.params,{unitId:s}=a;Array.from((o=(t=this._domLayerMap.get(s))==null?void 0:t.keys())!=null?o:[]).forEach(m=>{n(s,m)})}else if(e.id===v.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=e.params;n(a,s)}}))}_getPosition(n,e){var g;const{startX:t,endX:o,startY:a,endY:s}=n,c=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(R.ISheetSelectionRenderService);if(c==null)return;const m=c.getCellWithCoordByOffset(t,a);if(m==null)return;const u={column:m.actualColumn,columnOffset:t-m.startX,row:m.actualRow,rowOffset:a-m.startY},d=c.getCellWithCoordByOffset(o,s);if(d==null)return;const h={column:d.actualColumn,columnOffset:o-d.startX,row:d.actualRow,rowOffset:s-d.startY};return{from:u,to:h}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(n,e,t,o){const a=this._domLayerInfoMap.get(t),s=this._getSceneAndTransformerByDrawingSearch(n);if(a&&s){const{scene:c}=s,m=P.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),u=c.getObject(m);u&&u instanceof N.Rect&&u.setProps(o)}}addFloatDomToPosition(n,e){const t=v.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=t,{initPosition:s,componentKey:c,data:m,allowTransform:u=!0}=n,d=e!=null?e:l.generateRandomId(),h=this._getPosition(s,o);if(h==null)return;this._ensureMap(o,a).set(d,n);const p={unitId:o,subUnitId:a,drawingId:d,drawingType:n.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:c,sheetTransform:h,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:m,allowTransform:u};return this._commandService.executeCommand(Pe.id,{unitId:o,drawings:[p]}),this._add$.next({unitId:o,subUnitId:a,id:d}),{id:d,dispose:()=>{this._removeDom(d,!0)}}}_removeDom(n,e=!1){const t=this._domLayerInfoMap.get(n);if(!t)return;const{unitId:o,subUnitId:a}=t;this._domLayerInfoMap.delete(n),t.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(t.rect),e){this._ensureMap(o,a).delete(n);const m=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:n});if(!m)return;const u=this._sheetDrawingService.getBatchRemoveOp([m]),{redo:d,objects:h}=u;this._commandService.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:d,objects:h,type:w.DrawingApplyType.REMOVE})}}addHook(n){return this._hooks.push(n),{dispose:()=>{const e=this._hooks.findIndex(t=>t===n);this._hooks.splice(e,1)}}}addFloatDomToRange(n,e,t,o){var j,O,L,U,A;const a=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:c}=a,m=this._getSceneAndTransformerByDrawingSearch(s);if(!m)return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(j=this._renderManagerService.getRenderById(s))==null?void 0:j.with(R.SheetSkeletonManagerService).getWorksheetSkeleton(c);if(!d)return;const{componentKey:h,data:g,allowTransform:p=!0}=e,S=o!=null?o:l.generateRandomId(),{position:f,position$:_}=this._createRangePositionObserver(n,u,d.skeleton),I=this._getPosition(f,s);if(I==null)return;this._ensureMap(s,c).set(S,e);const b=m.scene,{scaleX:y}=b.getAncestorScale(),T=et(f,t,y),C={unitId:s,subUnitId:c,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:h,sheetTransform:I,transform:{left:T.startX,top:T.startY,width:T.width,height:T.height},data:g,allowTransform:p};{const{unitId:D,subUnitId:B,drawingId:k}=C,te=v.getSheetCommandTarget(this._univerInstanceService,{unitId:D,subUnitId:B}),oe=C,ve=this._univerInstanceService.getUnit(D,l.UniverInstanceType.UNIVER_SHEET);if(!ve)return;const ae=ve.getActiveSheet().getSheetId();if(!oe||!te)return;const Ie=(O=this._renderManagerService.getRenderById(D))==null?void 0:O.with(R.SheetSkeletonManagerService);if(!Ie)return;const ce=Ie.getWorksheetSkeleton(B);if(!ce)return;const{transform:ne,drawingType:ie,data:K}=oe;if(ie!==l.DrawingTypeEnum.DRAWING_DOM&&ie!==l.DrawingTypeEnum.DRAWING_CHART)return;const G=this._getSceneAndTransformerByDrawingSearch(D);if(G==null)return;const{scene:Me,canvas:Te}=G;if(ne==null||ae!==B)return;const{left:nt,top:it,width:rt,height:ot,angle:Dt,flipX:Mt,flipY:at,skewX:st,skewY:be}=ne,ct=P.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:B,drawingId:k}),de=Me.getObject(ct);if(de!=null){de.transformByState({left:nt,top:it,width:rt,height:ot,angle:Dt,flipX:Mt,flipY:at,skewX:st,skewY:be});return}const Q={left:nt,top:it,width:rt,height:ot,zIndex:this._drawingManagerService.getDrawingOrder(D,B).length-1},Re=ie===l.DrawingTypeEnum.DRAWING_CHART;if(Re){const $=K?K.backgroundColor:"white";Q.fill=$,Q.rotateEnabled=!1,K&&K.border&&(Q.stroke=K.border),Q.paintFirst="stroke",Q.strokeWidth=1,Q.borderEnabled=!1,Q.radius=8}const re=new N.Rect(ct,Q);Re&&re.setObjectType(N.ObjectType.CHART),Me.addObject(re,N.DRAWING_OBJECT_LAYER_INDEX),oe.allowTransform!==!1&&Me.attachTransformerTo(re);const Le=this._ensureMap(D,B),le=new l.DisposableCollection,Ee=Me.getMainViewport(),Oe={top:Ee.top,left:Ee.left,bottom:Ee.bottom,right:Ee.right},ue={dispose:le,rect:re,boundsOfViewArea:Oe,domAnchor:t,unitId:D,subUnitId:B},dt=se(re,G.renderUnit,ce.skeleton,te.worksheet,ue),fe=new W.BehaviorSubject(dt);ue.position$=fe;let Y={position$:fe,id:k,componentKey:oe.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{Te.dispatchEvent(new WheelEvent($.type,$))},props:(U=(L=Le.get(k))==null?void 0:L.props)!=null?U:this._getFloatDomProps(k),data:K,unitId:D};e.eventPassThrough&&(Y={...Y,onPointerDown:$=>{Te.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{Te.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{Te.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(Y),this.disposeWithMe(_.subscribe($=>{var $t,Yt,Gt,Ft;const ut=et({rotate:0,startX:$.startX,startY:$.startY,endX:$.endX,endY:$.endY,width:($t=t.width)!=null?$t:$.width,height:(Yt=t.height)!=null?Yt:$.height,absolute:{left:f.absolute.left,top:f.absolute.top}},t),ri=P.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:B,drawingId:k}),oi=new N.Rect(ri,{left:ut.startX,top:ut.startY,width:(Gt=t.width)!=null?Gt:$.width,height:(Ft=t.height)!=null?Ft:$.height,zIndex:this._drawingManagerService.getDrawingOrder(D,B).length-1}),ai=se(oi,G.renderUnit,ce.skeleton,te.worksheet,ue);fe.next(ai)}));const $e=(A=this._renderManagerService.getRenderById(D))==null?void 0:A.with(R.SheetSkeletonManagerService);$e==null||$e.currentSkeleton$.subscribe($=>{$&&d.sheetId!==$.sheetId&&this._removeDom(S,!0)});const lt=re.onTransformChange$.subscribeEvent(()=>{const $=se(re,G.renderUnit,ce.skeleton,te.worksheet,ue);fe.next($)});le.add(()=>{this._canvasFloatDomService.removeFloatDom(k)}),lt&&le.add(lt),this._domLayerInfoMap.set(k,ue),Le.set(k,{...Le.get(k)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(n,e,t,o){var T,C,j,O,L;const a=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:c}=a;if(!this._getSceneAndTransformerByDrawingSearch(s))return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(T=this._renderManagerService.getRenderById(s))==null?void 0:T.with(R.SheetSkeletonManagerService).getWorksheetSkeleton(c);if(!d)return;const{componentKey:h,data:g,allowTransform:p=!0}=e,S=o!=null?o:l.generateRandomId(),{position:f,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:n,endColumn:n},u,d.skeleton),I=f;I.startY=0;const M=this._getPosition(f,s);if(M==null)return;this._ensureMap(s,c).set(S,e);const y={unitId:s,subUnitId:c,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:h,sheetTransform:M,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:g,allowTransform:p};{const{unitId:U,subUnitId:A,drawingId:D}=y,B=v.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:A}),k=y,te=this._univerInstanceService.getUnit(U,l.UniverInstanceType.UNIVER_SHEET);if(!te)return;const oe=te.getActiveSheet().getSheetId();if(!k||!B)return;const ve=(C=this._renderManagerService.getRenderById(U))==null?void 0:C.with(R.SheetSkeletonManagerService);if(!ve)return;const ae=ve.getWorksheetSkeleton(A);if(!ae)return;const{transform:Ie,data:ce}=k,ne=this._getSceneAndTransformerByDrawingSearch(U);if(ne==null)return;const{scene:ie,canvas:K}=ne;if(Ie==null||oe!==A)return;const{left:G,top:Me,width:Te,height:nt,angle:it,flipX:rt,flipY:ot,skewX:Dt,skewY:Mt}=Ie,at=P.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:A,drawingId:D}),st=ie.getObject(at);if(st!=null){st.transformByState({left:G,top:Me,width:Te,height:nt,angle:it,flipX:rt,flipY:ot,skewX:Dt,skewY:Mt});return}const be=et({rotate:0,startX:I.startX,startY:0,endX:f.endX,endY:f.endY,width:t.width,height:t.height,absolute:{left:f.absolute.left,top:f.absolute.top}},t),ct={left:be.startX,top:be.startY,width:be.width,height:be.height,zIndex:this._drawingManagerService.getDrawingOrder(U,A).length-1},de=new N.Rect(at,ct);ie.addObject(de,N.DRAWING_OBJECT_LAYER_INDEX),k.allowTransform!==!1&&ie.attachTransformerTo(de);const Q=this._ensureMap(U,A),Re=new l.DisposableCollection,re=ie.getMainViewport(),Le={top:0,left:re.left,bottom:re.bottom,right:re.right},le={dispose:Re,rect:de,unitId:U,subUnitId:A,boundsOfViewArea:Le,domAnchor:t,scrollDirectionResponse:"HORIZONTAL"},Ee=se(de,ne.renderUnit,ae.skeleton,B.worksheet,le),Oe=new W.BehaviorSubject(Ee);le.position$=Oe;let ue={position$:Oe,id:D,componentKey:k.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:Y=>{K.dispatchEvent(new WheelEvent(Y.type,Y))},props:(O=(j=Q.get(D))==null?void 0:j.props)!=null?O:this._getFloatDomProps(D),data:ce,unitId:U};e.eventPassThrough&&(ue={...ue,onPointerDown:Y=>{K.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{K.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{K.dispatchEvent(new PointerEvent(Y.type,Y))}}),this._canvasFloatDomService.addFloatDom(ue);const dt=de.onTransformChange$.subscribeEvent(()=>{const Y=se(de,ne.renderUnit,ae.skeleton,B.worksheet,le);Oe.next(Y)});this.disposeWithMe(_.subscribe(Y=>{const $e=et({rotate:0,startX:Y.startX,startY:0,endX:Y.endX,endY:Y.endY,width:t.width,height:t.height,absolute:{left:f.absolute.left,top:f.absolute.top}},t),lt=P.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:A,drawingId:D}),$=new N.Rect(lt,{left:$e.startX,top:0,width:t.width,height:t.height,zIndex:this._drawingManagerService.getDrawingOrder(U,A).length-1}),ut=se($,ne.renderUnit,ae.skeleton,B.worksheet,le);Oe.next(ut)}));const fe=(L=this._renderManagerService.getRenderById(U))==null?void 0:L.with(R.SheetSkeletonManagerService);fe==null||fe.currentSkeleton$.subscribe(Y=>{Y&&d.sheetId!==Y.sheetId&&this._removeDom(S,!0)}),Re.add(()=>{this._canvasFloatDomService.removeFloatDom(D)}),dt&&Re.add(dt),this._domLayerInfoMap.set(D,le),Q.set(D,{...Q.get(D)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(n,e,t){let{startRow:o,startColumn:a}=n;const s=ke(o,a,t),c=new W.BehaviorSubject(s),m=ke(n.endRow,n.endColumn,t),u=new W.BehaviorSubject(m),d=()=>{const _=ke(o,a,t),I=ke(n.endRow,n.endColumn,t);c.next(_),u.next(I)},h=new l.DisposableCollection;h.add(e.engine.clientRect$.subscribe(()=>d())),h.add(this._commandService.onCommandExecuted(_=>{if(_.id===v.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(M=>M.row===o)>-1){d();return}(v.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===R.SetScrollOperation.id||_.id===R.SetZoomRatioOperation.id)&&d()}));const g=(_,I)=>{o=_,a=I,d()},p=()=>({rotate:0,width:m.right-s.left,height:m.bottom-s.top,absolute:{left:!0,top:!0},startX:s.left,startY:s.top,endX:m.right,endY:m.bottom}),S=c.pipe(W.map(_=>{const I=ke(n.endRow,n.endColumn,t);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}})),f=p();return{position$:S,position:f,updateRowCol:g,topLeftPos$:c,rightBottomPos$:u,disposable:h}}},E.SheetCanvasFloatDomManagerService=Jn([_e(0,l.Inject(N.IRenderManagerService)),_e(1,l.IUniverInstanceService),_e(2,l.Inject(l.ICommandService)),_e(3,P.IDrawingManagerService),_e(4,l.Inject(F.CanvasFloatDomService)),_e(5,w.ISheetDrawingService),_e(6,l.Inject(l.LifecycleService))],E.SheetCanvasFloatDomManagerService);function ke(r,i,n){const e=n.getCellWithCoordByIndex(r,i),t=e.isMergedMainCell?e.mergeInfo:e;return{left:t.startX,right:t.endX,top:t.startY,bottom:t.endY}}function et(r,i,n){var m,u;n=n!=null?n:1;const e=r.endX-r.startX,t=r.endY-r.startY,o=(m=i==null?void 0:i.width)!=null?m:e,a=(u=i==null?void 0:i.height)!=null?u:t;let s=0,c=0;if(i){if(i.horizonOffsetAlign==="right"){const d=tt(i.marginX,e*n);s=r.endX-d-o}else s=r.startX+tt(i.marginX,e);if(i.verticalOffsetAlign==="bottom"){const d=tt(i.marginY,t*n);c=r.endY-d-a}else c=r.startY+tt(i.marginY,t)}return{rotate:0,startX:s,startY:c,endX:r.endX,endY:r.endY,width:o,height:a,absolute:{left:r.absolute.left,top:r.absolute.top}}}function tt(r,i){if(r===void 0)return 0;if(typeof r=="number")return r;const n=Number.parseFloat(r);return i*n/100}var kt=Object.defineProperty,ei=Object.getOwnPropertyDescriptor,ti=(r,i,n)=>i in r?kt(r,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[i]=n,ni=(r,i,n,e)=>{for(var t=e>1?void 0:e?ei(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&kt(i,n,t),t},yt=(r,i)=>(n,e)=>i(n,e,r),Lt=(r,i,n)=>ti(r,typeof i!="symbol"?i+"":i,n);const ii="SHEET_IMAGE_UI_PLUGIN";E.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(i=bt,n,e,t){super(),this._config=i,this._injector=n,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=l.merge({},bt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Ht,a)}onStarting(){l.registerDependencies(this._injector,[[E.SheetCanvasFloatDomManagerService],[Qe],[Ge],[Ze],[ze],[Ke],[He],[xe],[Ve]]),l.touchDependencies(this._injector,[[E.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[Ke]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[ze],[Ze],[Qe],[He],[xe],[Ve]])}onSteady(){this._injector.get(Ge)}_registerRenderModules(){[[Ue],[vt],[mt]].forEach(i=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,i))})}},Lt(E.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),Lt(E.UniverSheetsDrawingUIPlugin,"pluginName",ii),E.UniverSheetsDrawingUIPlugin=ni([l.DependentOn(P.UniverDrawingPlugin,Se.UniverDocsDrawingPlugin,ge.UniverDrawingUIPlugin,w.UniverSheetsDrawingPlugin),yt(1,l.Inject(l.Injector)),yt(2,N.IRenderManagerService),yt(3,l.IConfigService)],E.UniverSheetsDrawingUIPlugin),E.ClearSheetDrawingTransformerOperation=H,E.DeleteDrawingsCommand=It,E.EditSheetDrawingOperation=ht,E.GroupSheetDrawingCommand=pt,E.InsertFloatImageCommand=Ne,E.InsertSheetDrawingCommand=Pe,E.MoveDrawingsCommand=ye,E.RemoveSheetDrawingCommand=Ce,E.SHEETS_IMAGE_MENU_ID=Ct,E.SetDrawingArrangeCommand=ft,E.SetSheetDrawingCommand=Ae,E.SidebarSheetDrawingOperation=gt,E.UngroupSheetDrawingCommand=St,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(P,l){typeof exports=="object"&&typeof module<"u"?l(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/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("react/jsx-runtime"),require("react"),require("@univerjs/docs-ui"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-drawing","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","react/jsx-runtime","react","@univerjs/docs-ui","@univerjs/design"],l):(P=typeof globalThis<"u"?globalThis:P||self,l(P.UniverSheetsDrawingUi={},P.UniverCore,P.UniverDocsDrawing,P.UniverDrawing,P.UniverDrawingUi,P.UniverEngineRender,P.UniverSheetsDrawing,P.UniverSheetsUi,P.UniverUi,P.rxjs,P.UniverSheets,P.React,P.React,P.UniverDocsUi,P.UniverDesign))})(this,function(P,l,we,U,me,W,w,E,G,k,_,x,te,bt,oe){"use strict";var di=Object.defineProperty;var li=(P,l,we)=>l in P?di(P,l,{enumerable:!0,configurable:!0,writable:!0,value:we}):P[l]=we;var Q=(P,l,we)=>li(P,typeof l!="symbol"?l+"":l,we);const Vt="sheets-drawing-ui.config",Rt={},F={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(r,i)=>{const n=r.get(W.IRenderManagerService);return i.forEach(e=>{var t,o;(o=(t=n.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},Ie={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{var I,M,b;const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(_.SheetInterceptorService),o=r.get(w.ISheetDrawingService);if(!i)return!1;const{drawings:a}=i,s=[];a.forEach(y=>{const{unitId:T}=y;s.push(T)});const d=o.getBatchRemoveOp(a),{unitId:m,subUnitId:u,undo:c,redo:h,objects:g}=d,f=t.onCommandExecute({id:Ie.id,params:i}),S={id:w.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:h,objects:g,type:w.DrawingApplyType.REMOVE}},p={id:w.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:c,objects:g,type:w.DrawingApplyType.INSERT}};return l.sequenceExecute([...(I=f.preRedos)!=null?I:[],S,...f.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(M=f.preUndos)!=null?M:[],p,...f.undos,{id:F.id,params:s}],redoMutations:[...(b=f.preRedos)!=null?b:[],S,...f.redos,{id:F.id,params:s}]}),!0):!1}},Et="COMPONENT_SHEET_DRAWING_PANEL",ht={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(r,i)=>{const n=r.get(G.ISidebarService),e=r.get(l.LocaleService),t=r.get(l.IUniverInstanceService),o=r.get(l.ICommandService);if(!_.getSheetCommandTarget(t))return!1;switch(i.value){case"open":n.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Et},onClose:()=>{o.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:n.close();break}return!0}},mt={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(r,i)=>{const n=r.get(l.ICommandService);return i==null?!1:(n.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[i]),n.executeCommand(ht.id,{value:"open"}),!0)}},Ge={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},xt=()=>{const r=l.useDependency(U.IImageIoService),i=l.useDependency(l.LocaleService),[n,e]=te.useState(0);return te.useEffect(()=>{const t=r.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[r]),x.jsx("div",{style:{display:n>0?"block":"none"},className:Ge.uploadLoading,children:x.jsxs("div",{className:Ge.uploadLoadingBody,children:[x.jsx("div",{className:Ge.uploadLoadingBodyAnimation}),x.jsx("div",{className:Ge.uploadLoadingBodyText,children:`${i.t("uploadLoading.loading")}: ${n}`})]})})};var Kt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,qt=(r,i,n,e)=>{for(var t=e>1?void 0:e?zt(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Kt(i,n,t),t},pe=(r,i)=>(n,e)=>i(n,e,r);let Fe=class extends l.RxDisposable{constructor(i,n,e,t,o,a,s,d){super();Q(this,"_initImagePopupMenu",new Set);this._injector=i,this._drawingManagerService=n,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._commandService=d,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(k.takeUntil(this.dispose$)).subscribe(i=>this._create(i)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(k.takeUntil(this.dispose$)).subscribe(i=>this._dispose(i)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(i=>this._create(i)),this._uiPartsService.registerComponent(G.BuiltInUIPart.CONTENT,()=>l.connectInjector(xt,this._injector))}_dispose(i){const n=i.getUnitId();this._renderManagerService.removeRender(n)}_create(i){if(!i)return;const n=i.getUnitId();this._renderManagerService.has(n)&&!this._initImagePopupMenu.has(n)&&(this._popupMenuListener(n),this._initImagePopupMenu.add(n))}_hasCropObject(i){const n=i.getAllObjectsByOrder();for(const e of n)if(e instanceof me.ImageCropperObject)return!0;return!1}_popupMenuListener(i){var o;const n=(o=this._renderManagerService.getRenderById(i))==null?void 0:o.scene;if(!n)return;const e=n.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(l.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(n))return;const a=e.getSelectedObjectMap();if(a.size>1){t==null||t.dispose();return}const s=a.values().next().value;if(!s)return;const d=s.oKey,m=this._drawingManagerService.getDrawingOKey(d);if(!m)return;const{unitId:u,subUnitId:c,drawingId:h,drawingType:g}=m,f=m.data;if(f&&f.disablePopup)return;t==null||t.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,c,h,g);t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:me.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,c,h,g)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[l.FOCUSING_COMMON_DRAWINGS]===!1&&(t==null||t.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{t==null||t.dispose()}))}_getImageMenuItems(i,n,e,t){return[{label:"image-popup.edit",index:0,commandId:mt.id,commandParams:{unitId:i,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Ie.id,commandParams:{unitId:i,drawings:[{unitId:i,subUnitId:n,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:me.OpenImageCropOperation.id,commandParams:{unitId:i,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:me.ImageResetSizeOperation.id,commandParams:[{unitId:i,subUnitId:n,drawingId:e}],disable:t===l.DrawingTypeEnum.DRAWING_DOM}]}};Fe=qt([pe(0,l.Inject(l.Injector)),pe(1,U.IDrawingManagerService),pe(2,l.Inject(E.SheetCanvasPopManagerService)),pe(3,W.IRenderManagerService),pe(4,l.IUniverInstanceService),pe(5,l.IContextService),pe(6,l.Inject(G.IUIPartsService)),pe(7,l.ICommandService)],Fe);function K(r,i,n){const{from:e,to:t,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:d=0,skewY:m=0}=r,u=n.getCurrent();if(u==null)return;const c=E.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:t},n);let{left:h,top:g,width:f,height:S}=c;const p=n.getCurrentSkeleton(),v=p.rowHeaderWidth+p.columnTotalWidth,I=p.columnHeaderHeight+p.rowTotalHeight;return h+f>v&&(h=v-f),g+S>I&&(g=I-S),{flipY:o,flipX:a,angle:s,skewX:d,skewY:m,left:h,top:g,width:f,height:S}}function H(r,i){const{left:n=0,top:e=0,width:t=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:d=0,skewX:m=0,skewY:u=0}=r,c=i.getCellWithCoordByOffset(n,e);if(c==null)return;const h={column:c.actualColumn,columnOffset:W.precisionTo(n-c.startX,1),row:c.actualRow,rowOffset:W.precisionTo(e-c.startY,1)},g=i.getCellWithCoordByOffset(n+t,e+o);if(g==null)return;const f={column:g.actualColumn,columnOffset:W.precisionTo(n+t-g.startX,1),row:g.actualRow,rowOffset:W.precisionTo(e+o-g.startY,1)};return{flipY:a,flipX:s,angle:d,skewX:m,skewY:u,from:h,to:f}}var Zt=Object.defineProperty,Jt=Object.getOwnPropertyDescriptor,Qt=(r,i,n,e)=>{for(var t=e>1?void 0:e?Jt(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Zt(i,n,t),t},He=(r,i)=>(n,e)=>i(n,e,r);let pt=class extends l.Disposable{constructor(r,i,n,e,t){super(),this._context=r,this._sheetDrawingService=i,this._drawingManagerService=n,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=t,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const r=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const i in r){const n=r[i];for(const e in n.data){const t=n.data[e];t.transform=K(t.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};pt=Qt([He(1,w.ISheetDrawingService),He(2,U.IDrawingManagerService),He(3,l.Inject(E.ISheetSelectionRenderService)),He(4,l.Inject(E.SheetSkeletonManagerService))],pt);function en(r){const i=[];return r.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s}=e,d=W.getGroupState(0,0,t.map(c=>c.transform||{})),m=t.map(c=>{const h=c.transform||{left:0,top:0},{unitId:g,subUnitId:f,drawingId:S}=c;return{unitId:g,subUnitId:f,drawingId:S,transform:{...h,left:h.left-d.left,top:h.top-d.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:d};i.push({parent:u,children:m})}),i}function tn(r){const i=[];return r.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s,transform:d={width:0,height:0}}=e;if(d==null)return;const m=t.map(c=>{const{transform:h}=c,{unitId:g,subUnitId:f,drawingId:S}=c,p=W.transformObjectOutOfGroup(h||{},d,d.width||0,d.height||0);return{unitId:g,subUnitId:f,drawingId:S,transform:p,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};i.push({parent:u,children:m})}),i}const ft={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService);if(!i)return!1;const o=[];i.forEach(({parent:g,children:f})=>{o.push(g.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getGroupDrawingOp(i),{unitId:s,subUnitId:d,undo:m,redo:u,objects:c}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:d,objects:c,type:w.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:d,objects:tn(c),type:w.DrawingApplyType.UNGROUP}},{id:F.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:d,objects:c,type:w.DrawingApplyType.GROUP}},{id:F.id,params:o}]}),!0):!1}},Oe={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{var I,M,b;const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService),o=r.get(_.SheetInterceptorService);if(!i)return!1;const a=i.drawings,s=a.map(y=>y.unitId),d=t.getBatchAddOp(a),{unitId:m,subUnitId:u,undo:c,redo:h,objects:g}=d,f=o.onCommandExecute({id:Oe.id,params:i}),S={id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:m,subUnitId:u,objects:g,type:w.DrawingApplyType.INSERT}},p={id:w.SetDrawingApplyMutation.id,params:{op:c,unitId:m,subUnitId:u,objects:g,type:w.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(I=f.preRedos)!=null?I:[],S,...f.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(M=f.preUndos)!=null?M:[],p,...f.undos,{id:F.id,params:s}],redoMutations:[...(b=f.preRedos)!=null?b:[],S,...f.redos,{id:F.id,params:s}]}),!0):!1}},St={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService);if(!i)return!1;const t=r.get(w.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:d}=i,m={unitId:o,subUnitId:a,drawingIds:s};let u;if(d===l.ArrangeTypeEnum.forward?u=t.getForwardDrawingsOp(m):d===l.ArrangeTypeEnum.backward?u=t.getBackwardDrawingOp(m):d===l.ArrangeTypeEnum.front?u=t.getFrontDrawingsOp(m):d===l.ArrangeTypeEnum.back&&(u=t.getBackDrawingsOp(m)),u==null)return!1;const{objects:c,redo:h,undo:g}=u;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:h,unitId:o,subUnitId:a,objects:c,type:w.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:c,type:w.DrawingApplyType.ARRANGE}}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:c,type:w.DrawingApplyType.ARRANGE}}]}),!0):!1}},Pe={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService);if(!i)return!1;const{drawings:o}=i,a=t.getBatchUpdateOp(o),{unitId:s,subUnitId:d,undo:m,redo:u,objects:c}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:s,subUnitId:d,op:u,objects:c,type:w.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:d,op:m,objects:c,type:w.DrawingApplyType.UPDATE}},{id:F.id,params:[s]}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:d,op:u,objects:c,type:w.DrawingApplyType.UPDATE}},{id:F.id,params:[s]}]}),!0):!1}},wt={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService);if(!i)return!1;const o=[];i.forEach(({parent:g,children:f})=>{o.push(g.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getUngroupDrawingOp(i),{unitId:s,subUnitId:d,undo:m,redo:u,objects:c}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:d,objects:c,type:w.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:d,objects:en(c),type:w.DrawingApplyType.GROUP}},{id:F.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:d,objects:c,type:w.DrawingApplyType.UNGROUP}},{id:F.id,params:o}]}),!0):!1}};var nn=Object.defineProperty,rn=Object.getOwnPropertyDescriptor,on=(r,i,n,e)=>{for(var t=e>1?void 0:e?rn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&nn(i,n,t),t},ne=(r,i)=>(n,e)=>i(n,e,r);function an(r,i,n){const e=n*Math.PI/180,t=Math.abs(r*Math.cos(e))+Math.abs(i*Math.sin(e)),o=Math.abs(r*Math.sin(e))+Math.abs(i*Math.cos(e));return{rotatedWidth:t,rotatedHeight:o}}function Ot(r,i,n,e,t){var I;const{rotatedHeight:o,rotatedWidth:a}=an(n,e,t),d=r.get(W.IRenderManagerService).getRenderById(i.unitId);if(!d)return!1;const u=(I=d.with(E.SheetSkeletonManagerService).getSkeletonParam(i.subUnitId))==null?void 0:I.skeleton;if(u==null)return!1;const c=u.getCellByIndex(i.row,i.col),h=c.mergeInfo.endX-c.mergeInfo.startX-2,g=c.mergeInfo.endY-c.mergeInfo.startY-2,f=a/o,p=Math.ceil(Math.min(h,g*f))/a,v=!p||Number.isNaN(p)?.001:p;return{width:n*v,height:e*v}}let Ae=class extends l.Disposable{constructor(i,n,e,t,o,a,s,d,m,u,c,h,g){super();Q(this,"_workbookSelections");this._context=i,this._skeletonManagerService=n,this._commandService=e,this._selectionRenderService=t,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=s,this._drawingManagerService=d,this._contextService=m,this._messageService=u,this._localeService=c,this._injector=g,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const i=await this._fileOpenerService.openFile({multiple:!0,accept:U.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),n=i.length;return n>U.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:oe.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(U.DRAWING_IMAGE_COUNT_LIMIT))}),!1):n===0?!1:(i.forEach(async e=>await this.insertFloatImageByFile(e)),!0)}async insertCellImage(){const n=(await this._fileOpenerService.openFile({multiple:!1,accept:U.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}))[0];return n?(await this._insertCellImage(n),!0):!1}async insertFloatImageByFile(i){let n;try{n=await this._imageIoService.saveImage(i)}catch(I){const M=I.message;M===U.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:oe.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(U.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):M===U.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:oe.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):M===U.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:oe.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:s,source:d,base64Cache:m}=n,{width:u,height:c,image:h}=await U.getImageSize(m||""),{width:g,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(d,s,h);let S=1;if(u>U.DRAWING_IMAGE_WIDTH_LIMIT||c>U.DRAWING_IMAGE_HEIGHT_LIMIT){const I=U.DRAWING_IMAGE_WIDTH_LIMIT/u,M=U.DRAWING_IMAGE_HEIGHT_LIMIT/c;S=Math.max(I,M)}const p=this._getImagePosition(u*S,c*S,g,f);if(p==null)return;const v={unitId:t,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:d,transform:K(p,this._selectionRenderService,this._skeletonManagerService),sheetTransform:p};return this._commandService.executeCommand(Oe.id,{unitId:t,drawings:[v]})}async _insertCellImage(i){let n;try{n=await this._imageIoService.saveImage(i)}catch(p){const v=p.message;v===U.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:oe.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(U.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):v===U.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:oe.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):v===U.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:oe.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const{imageId:e,imageSourceType:t,source:o,base64Cache:a}=n,{width:s,height:d,image:m}=await U.getImageSize(a||"");this._imageIoService.addImageSourceCache(o,t,m);const u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;const c=l.createDocumentModelWithStyle("",{}),h=Ot(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},s,d,0);if(!h)return!1;const g={size:{width:h.width,height:h.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},f={unitId:c.getUnitId(),subUnitId:c.getUnitId(),drawingId:e,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t,source:o,transform:bt.docDrawingPositionToTransform(g),docTransform:g,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=l.BuildTextUtils.drawing.add({documentDataModel:c,drawings:[f],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(c.apply(S),this._commandService.syncExecuteCommand(_.SetRangeValuesCommand.id,{value:{[u.primary.actualRow]:{[u.primary.actualColumn]:{p:c.getSnapshot(),t:1}}}})):!1}_getUnitInfo(){const i=this._context.unit,n=i.getActiveSheet(),e=i.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(i,n,e,t){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const s=E.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(s==null)return;let{startColumn:d,startRow:m,startX:u,startY:c}=s,h=!1;if(u+i>e&&(u=e-i,u<0&&(u=0,i=e),h=!0),c+n>t&&(c=t-n,c<0&&(c=0,n=t),h=!0),h){const p=this._selectionRenderService.getCellWithCoordByOffset(u,c);if(p==null)return;u=p.startX,c=p.startY,d=p.actualColumn,m=p.actualRow}const g={column:d,columnOffset:0,row:m,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(u+i,c+n);if(f==null)return;const S={column:f.actualColumn,columnOffset:u+i-f.startX,row:f.actualRow,rowOffset:c+n-f.startY};return{from:g,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(i=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o}=i;this._commandService.executeCommand(St.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(i=>{const n=[];i.length!==0&&(i.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a,drawingType:s,transform:d}=e;if(d==null)return;const m=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:a});if(m==null||m.unitId!==this._context.unitId)return;const u=H({...m.transform,...d},this._selectionRenderService);if(u==null)return;const c={...e,transform:{...m.transform,...d,...K(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};n.push(c)}),n.length>0&&this._commandService.executeCommand(Pe.id,{unitId:i[0].unitId,drawings:n}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(i=>{this._commandService.executeCommand(ft.id,i);const{unitId:n,subUnitId:e,drawingId:t}=i[0].parent;this._commandService.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:e,drawingId:t}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(i=>{this._commandService.executeCommand(wt.id,i)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(i=>{i==null||i.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(i))}))}};Ae=on([ne(1,l.Inject(E.SheetSkeletonManagerService)),ne(2,l.ICommandService),ne(3,E.ISheetSelectionRenderService),ne(4,U.IImageIoService),ne(5,G.ILocalFileService),ne(6,w.ISheetDrawingService),ne(7,U.IDrawingManagerService),ne(8,l.IContextService),ne(9,G.IMessageService),ne(10,l.Inject(l.LocaleService)),ne(11,l.Inject(_.SheetsSelectionsService)),ne(12,l.Inject(l.Injector))],Ae);var sn=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,dn=(r,i,n,e)=>{for(var t=e>1?void 0:e?cn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&sn(i,n,t),t},ve=(r,i)=>(n,e)=>i(n,e,r);function vt(r,i,n){var e,t,o,a;if(((t=(e=n==null?void 0:n.p)==null?void 0:e.body)==null?void 0:t.dataStream.length)===3&&((a=(o=n.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const s=n.p.drawings[n.p.drawingsOrder[0]],d=Ot(r,{unitId:i.unitId,subUnitId:i.subUnitId,row:i.row,col:i.col},s.docTransform.size.width,s.docTransform.size.height,s.docTransform.angle);if(d)return s.transform.width=d.width,s.transform.height=d.height,s.docTransform.size.width=d.width,s.docTransform.size.height=d.height,s.transform.left=0,s.transform.top=0,s.docTransform.positionH.posOffset=0,s.docTransform.positionV.posOffset=0,n.p.documentStyle.pageSize.width=1/0,n.p.documentStyle.pageSize.height=1/0,!0}return!1}let Xe=class extends l.Disposable{constructor(r,i,n,e,t,o,a){super(),this._commandService=r,this._sheetInterceptorService=i,this._univerInstanceService=n,this._injector=e,this._drawingManagerService=t,this._docDrawingController=o,this._editorBridgeService=a,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{let i,n=[];if(r.id===_.SetWorksheetRowHeightMutation.id){const e=r.params;n=e.ranges,i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===_.SetWorksheetColWidthMutation.id){const e=r.params;n=e.ranges,i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===_.SetWorksheetRowIsAutoHeightMutation.id){const e=r.params;n=e.ranges,i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===_.SetWorksheetRowAutoHeightMutation.id){const e=r.params;i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId}),n=e.rowsAutoHeightInfo.map(t=>({startRow:t.row,endRow:t.row,startColumn:0,endColumn:9999}))}else if(r.id===_.AddWorksheetMergeMutation.id){const e=r.params;n=e.ranges,i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===_.RemoveWorksheetMergeMutation.id){const e=r.params;n=e.ranges,i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}i&&n.length&&n.forEach(e=>{const t=l.Range.transformRange(e,i.worksheet);for(let o=t.startRow;o<=t.endRow;o++)for(let a=t.startColumn;a<=t.endColumn;a++)vt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:o,col:a},i.worksheet.getCellRaw(o,a))})}))}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(r=>{r.visible?r.visible&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{r.id===bt.ReplaceSnapshotCommand.id&&r.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(_.AFTER_CELL_EDIT,{priority:9999,handler:(r,i,n)=>(vt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:i.row,col:i.col},r),n(r))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:_.InterceptCellContentPriority.CELL_IMAGE,handler:(r,i,n)=>{var e;return r!=null&&r.p&&((e=r.p.drawingsOrder)!=null&&e.length)&&(r.interceptorStyle||(r.interceptorStyle={}),r.interceptorStyle.tr={a:0}),n(r)}}))}};Xe=dn([ve(0,l.ICommandService),ve(1,l.Inject(_.SheetInterceptorService)),ve(2,l.IUniverInstanceService),ve(3,l.Inject(l.Injector)),ve(4,U.IDrawingManagerService),ve(5,l.Inject(we.DocDrawingController)),ve(6,l.Inject(E.IEditorBridgeService))],Xe);var ln=Object.defineProperty,un=Object.getOwnPropertyDescriptor,gn=(r,i,n,e)=>{for(var t=e>1?void 0:e?un(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&ln(i,n,t),t},Pt=(r,i)=>(n,e)=>i(n,e,r);let Ve=class extends l.Disposable{constructor(r,i){super(),this._autoFillService=r,this._injector=i,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(r,i,n,e)=>{new l.ObjectMatrix(e).forValue((t,o,a)=>{vt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:t,col:o},a)})}}))}};Ve=gn([Pt(0,l.Inject(E.IAutoFillService)),Pt(1,l.Inject(l.Injector))],Ve);var hn=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,pn=(r,i,n,e)=>{for(var t=e>1?void 0:e?mn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&hn(i,n,t),t},xe=(r,i)=>(n,e)=>i(n,e,r);let Ke=class extends l.Disposable{constructor(i,n,e,t){super();Q(this,"_isSetCursor",!1);this._hoverManagerService=i,this._renderManagerService=n,this._selectionsService=e,this._drawingRenderService=t}_initHover(){}_initImageClick(){}};Ke=pn([xe(0,l.Inject(E.HoverManagerService)),xe(1,l.Inject(W.IRenderManagerService)),xe(2,l.Inject(_.SheetsSelectionsService)),xe(3,l.Inject(me.DrawingRenderService))],Ke);const Ue={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(r,i)=>{var o,a;const e=(o=r.get(W.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:o.with(Ae);if(!e)return!1;const t=i==null?void 0:i.files;if(t){const s=t.map(d=>e.insertFloatImageByFile(d));return(await Promise.all(s)).every(d=>d)}else return(a=e.insertFloatImage())!=null?a:!1}},_t={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:r=>{var n,e;return(e=(n=r.get(W.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(Ae).insertCellImage())!=null?e:!1}};var fn=Object.defineProperty,Sn=Object.getOwnPropertyDescriptor,wn=(r,i,n,e)=>{for(var t=e>1?void 0:e?Sn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&fn(i,n,t),t},Ne=(r,i)=>(n,e)=>i(n,e,r);const At="image/png";function vn(r){const i=r.split(","),n=atob(i[1]),e=n.length,t=new Uint8Array(e);for(let o=0;o<e;o++)t[o]=n.charCodeAt(o);return new Blob([t],{type:At})}function _n(r){const i=new ClipboardItem({[At]:vn(r)});navigator.clipboard.write([i]).catch(n=>{console.error("Could not copy image using clipboard API: ",n)})}function In(){function r(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const i=document.activeElement,n=r();return document.body.appendChild(n),n.focus(),()=>{n.blur(),document.body.removeChild(n),i instanceof HTMLElement&&i.focus()}}const Ut=[E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let ze=class extends l.Disposable{constructor(i,n,e,t,o){super();Q(this,"_copyInfo");this._sheetClipboardService=i,this._renderManagerService=n,this._drawingService=e,this._clipboardInterfaceService=t,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(i,n,e,t)=>{const o=this._focusedDrawings;if(o.length>0){const[a]=o;if(t===E.COPY_TYPE.CUT){const d={unitId:i,drawings:[a]};this._commandService.executeCommand(Ie.id,d)}setTimeout(()=>{const d=In();a.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&a.imageSourceType===U.ImageSourceType.BASE64?_n(a.source):this._clipboardInterfaceService.writeText(""),d()},200);const s={unitId:a.unitId,subUnitId:a.subUnitId,drawings:[a]};this._copyInfo=s}else{const a=this._createDrawingsCopyInfoByRange(i,n,e);this._copyInfo=a}},onPasteCells:(i,n,e,t)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=E.COPY_TYPE.COPY,pasteType:a}=t,{range:s}=i||{},{range:d,unitId:m,subUnitId:u}=n;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:a,unitId:m,subUnitId:u,pasteRange:d},{copyRange:s,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:n,pasteType:a},E.COPY_TYPE.COPY)},onPastePlainText:(i,n)=>({undos:[],redos:[]}),onPasteUnrecognized:i=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:i,pasteType:E.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},E.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(i,n)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:i,pasteType:E.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},E.COPY_TYPE.COPY);{const e=n.filter(t=>t.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Ue.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(i,n,e){var h;const t=(h=this._renderManagerService.getRenderById(i))==null?void 0:h.with(E.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:s,startY:d,endY:m}=o,u=this._drawingService.getDrawingData(i,n),c=this._focusedDrawings.slice();if(Object.keys(u).forEach(g=>{const f=u[g],{transform:S}=f;if(f.anchorType!==w.SheetDrawingAnchorType.Both||!S)return;const{left:p=0,top:v=0,width:I=0,height:M=0}=S,{drawingStartX:b,drawingEndX:y,drawingStartY:T,drawingEndY:C}={drawingStartX:p,drawingEndX:p+I,drawingStartY:v,drawingEndY:v+M};a<=b&&y<=s&&d<=T&&C<=m&&c.push(f)}),c.length)return{copyRange:e,drawings:c,unitId:i,subUnitId:n}}_generateSingleDrawingPasteMutations(i,n){const{pasteType:e,pasteTo:t}=i;if(Ut.includes(e))return{redos:[],undos:[]};const{unitId:o,subUnitId:a,range:s}=t,d=this._renderManagerService.getRenderById(o),m=d==null?void 0:d.with(E.SheetSkeletonManagerService),u=d==null?void 0:d.with(E.ISheetSelectionRenderService),c=this._copyInfo;if(!m||!u)return{redos:[],undos:[]};const{drawings:h}=c,g=E.discreteRangeToRange(s);return this._generateMutations(h,{unitId:o,subUnitId:a,isCut:n===E.COPY_TYPE.CUT,getTransform:(f,S)=>{var I;const p=m.attachRangeWithCoord({startRow:g.startRow,endRow:g.endRow,startColumn:g.startColumn,endColumn:g.endColumn}),v={...f,left:p==null?void 0:p.startX,top:p==null?void 0:p.startY};return{transform:v,sheetTransform:(I=H(v,u))!=null?I:S}}})}_generateMutations(i,n){const{unitId:e,subUnitId:t,getTransform:o,isCut:a}=n,s=[],d=[],{_drawingService:m}=this;return i.forEach(u=>{const{transform:c,sheetTransform:h}=u;if(!c)return;const g=o(c,h),f={...u,unitId:e,subUnitId:t,drawingId:a?u.drawingId:l.Tools.generateRandomId(),transform:g.transform,sheetTransform:g.sheetTransform};if(a){const{undo:S,redo:p,objects:v}=m.getBatchUpdateOp([f]);s.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,type:w.DrawingApplyType.UPDATE,op:p,objects:v}}),d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,type:w.DrawingApplyType.UPDATE,op:S,objects:v}})}else{const{undo:S,redo:p,objects:v}=m.getBatchAddOp([f]);s.push({id:w.SetDrawingApplyMutation.id,params:{op:p,unitId:e,subUnitId:t,objects:v,type:w.DrawingApplyType.INSERT}}),d.push({id:w.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:t,objects:v,type:w.DrawingApplyType.REMOVE}})}}),{redos:s,undos:d}}_generateRangeDrawingsPasteMutations(i,n){var N;const{unitId:e,subUnitId:t,pasteType:o,pasteRange:a}=i,{copyRange:s,copyType:d}=n;if(Ut.includes(o))return{redos:[],undos:[]};const m=(N=this._renderManagerService.getRenderById(e))==null?void 0:N.with(E.SheetSkeletonManagerService);if(!m||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!s)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:t,range:E.discreteRangeToRange(a)},pasteType:o},d);const{ranges:[c,h],mapFunc:g}=E.virtualizeDiscreteRanges([s,a]),{row:f,col:S}=g(c.startRow,c.startColumn),{row:p,col:v}=g(h.startRow,h.startColumn),I=m.attachRangeWithCoord({startRow:f,endRow:f,startColumn:S,endColumn:S}),M=m.attachRangeWithCoord({startRow:p,endRow:p,startColumn:v,endColumn:v});if(!I||!M||!this._copyInfo)return{redos:[],undos:[]};const b=M.startX-I.startX,y=M.startY-I.startY,T=p-f,C=v-S;return this._generateMutations(u,{unitId:e,subUnitId:t,getTransform:(R,j)=>{var A,O;return{transform:{...R,left:((A=R==null?void 0:R.left)!=null?A:0)+b,top:((O=R==null?void 0:R.top)!=null?O:0)+y},sheetTransform:{...j,to:{...j.to,row:j.to.row+T,column:j.to.column+C},from:{...j.from,row:j.from.row+T,column:j.from.column+C}}}},isCut:d===E.COPY_TYPE.CUT})}};ze=wn([Ne(0,E.ISheetClipboardService),Ne(1,W.IRenderManagerService),Ne(2,U.IDrawingManagerService),Ne(3,G.IClipboardInterfaceService),Ne(4,l.ICommandService)],ze);var Cn=Object.defineProperty,yn=Object.getOwnPropertyDescriptor,Dn=(r,i,n,e)=>{for(var t=e>1?void 0:e?yn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Cn(i,n,t),t},je=(r,i)=>(n,e)=>i(n,e,r);let qe=class extends l.Disposable{constructor(r,i,n,e,t){super(),this._drawingManagerService=r,this._renderManagerService=i,this._permissionService=n,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(k.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{if(!i){this._drawingManagerService.setDrawingVisible(!1);return}i.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=i.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const s=i.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(s,d),u=Object.values(m),c=this._renderManagerService.getRenderById(s),h=c==null?void 0:c.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(f=>{f.classType===W.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>f.oKey.includes(S.drawingId))&&h.removeObject(f)})}})}))}_initDrawingEditable(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(k.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{if(!i){this._drawingManagerService.setDrawingEditable(!1);return}i.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=i.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const s=i.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(s,d),u=Object.values(m),c=this._renderManagerService.getRenderById(s),h=c==null?void 0:c.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(f=>{f.classType===W.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>f.oKey.includes(S.drawingId))&&h.detachTransformerFrom(f)})}})}))}_initViewPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(k.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{i&&i.activeSheet$.subscribe(e=>{var c;if(!e)return;const t=i.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),d=s==null?void 0:s.scene;if(d==null)return;const m=d.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).pipe(k.map(h=>h.every(g=>g.value)));u==null||u.pipe(k.filter(h=>h!==a),k.distinctUntilChanged()).subscribe({next:h=>{a=h,this._drawingManagerService.setDrawingVisible(h);const g=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);h?this._drawingManagerService.addNotification(S):(g.forEach(p=>{p.classType===W.RENDER_CLASS_TYPE.IMAGE&&S.some(v=>p.oKey.includes(v.drawingId))&&d.removeObject(p)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(t,o).id))==null||c.pipe(k.filter(h=>h.value!==a),k.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const h=this._drawingManagerService.getDrawingData(t,o),g=Object.values(h);this._drawingManagerService.addNotification(g)}})})}))}_initEditPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(k.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{i&&i.activeSheet$.subscribe(e=>{var c;if(!e)return;const t=i.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),d=s==null?void 0:s.scene;if(d==null)return;const m=d.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).pipe(k.map(h=>h.every(g=>g.value)));u==null||u.pipe(k.filter(h=>h!==a),k.distinctUntilChanged()).subscribe({next:h=>{a=h,this._drawingManagerService.setDrawingEditable(h);const g=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);h?(g.forEach(p=>{p.classType===W.RENDER_CLASS_TYPE.IMAGE&&S.some(v=>p.oKey.includes(v.drawingId))&&d.attachTransformerTo(p)}),this._drawingManagerService.addNotification(S)):(g.forEach(p=>{p.classType===W.RENDER_CLASS_TYPE.IMAGE&&S.some(v=>p.oKey.includes(v.drawingId))&&d.detachTransformerFrom(p)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(t,o).id))==null||c.pipe(k.filter(h=>h.value!==a),k.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const h=i.getUnitId(),g=e.getSheetId(),f=this._drawingManagerService.getDrawingData(h,g),S=Object.values(f),p=this._renderManagerService.getRenderById(h),v=p==null?void 0:p.scene;if(v==null)return;this._drawingManagerService.setDrawingEditable(!0),v.getAllObjectsByOrder().forEach(M=>{M.classType===W.RENDER_CLASS_TYPE.IMAGE&&S.some(b=>M.oKey.includes(b.drawingId))&&v.detachTransformerFrom(M)})}})})}))}};qe=Dn([je(0,U.IDrawingManagerService),je(1,W.IRenderManagerService),je(2,l.IPermissionService),je(3,l.IUniverInstanceService),je(4,l.Inject(l.UserManagerService))],qe);var Mn=Object.defineProperty,Tn=Object.getOwnPropertyDescriptor,bn=(r,i,n,e)=>{for(var t=e>1?void 0:e?Tn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Mn(i,n,t),t},Ze=(r,i)=>(n,e)=>i(n,e,r);let Je=class extends l.Disposable{constructor(r,i,n,e){super(),this._sheetPrintInterceptorService=r,this._drawingRenderService=i,this._drawingManagerService=n,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(r,i,n)=>{const{unitId:e,scene:t,subUnitId:o}=i,a=this._drawingManagerService.getDrawingDataForUnit(e),s=a==null?void 0:a[o];return s&&s.order.forEach(d=>{this._drawingRenderService.renderDrawing(s.data[d],t)}),n()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(r,i,n)=>{const{unitId:e,subUnitId:t}=i,o=this._renderManagerService.getRenderById(e);if(!o)return n(r);const a=o.with(E.SheetSkeletonManagerService).getSkeletonParam(t);if(!a)return n(r);const s=this._drawingManagerService.getDrawingDataForUnit(e),d=s==null?void 0:s[i.subUnitId];if(!d)return n(r);const{scaleX:m,scaleY:u}=o.scene,c=r?{...r}:{startColumn:0,endColumn:0,endRow:0,startRow:0},h=d.order.map(g=>d.data[g]).filter(g=>g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM);return h.length?(h.forEach(g=>{if(!g.groupId&&g.transform&&l.Tools.isDefine(g.transform.left)&&l.Tools.isDefine(g.transform.top)&&l.Tools.isDefine(g.transform.width)&&l.Tools.isDefine(g.transform.height)){const f=a.skeleton.getCellIndexByOffset(g.transform.left,g.transform.top,m,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(g.transform.left+g.transform.width,g.transform.top+g.transform.height,m,u,{x:0,y:0});f.column<c.startColumn&&(c.startColumn=f.column),f.row<c.startRow&&(c.startRow=f.row),c.endRow<S.row&&(c.endRow=S.row),c.endColumn<S.column&&(c.endColumn=S.column)}}),n(c)):n(r)}}))}};Je=bn([Ze(0,l.Inject(E.SheetPrintInterceptorService)),Ze(1,l.Inject(me.DrawingRenderService)),Ze(2,U.IDrawingManagerService),Ze(3,W.IRenderManagerService)],Je);var Rn=Object.defineProperty,En=Object.getOwnPropertyDescriptor,On=(r,i,n,e)=>{for(var t=e>1?void 0:e?En(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Rn(i,n,t),t},fe=(r,i)=>(n,e)=>i(n,e,r);const Pn=[_.InsertRowCommand.id,_.InsertColCommand.id,_.RemoveRowCommand.id,_.RemoveColCommand.id,_.DeleteRangeMoveLeftCommand.id,_.DeleteRangeMoveUpCommand.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id,_.DeltaRowHeightCommand.id,_.SetRowHeightCommand.id,_.DeltaColumnWidthCommand.id,_.SetColWidthCommand.id,_.SetRowHiddenCommand.id,_.SetSpecificRowsVisibleCommand.id,_.SetSpecificColsVisibleCommand.id,_.SetColHiddenCommand.id,_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id],An=[_.SetRowVisibleMutation.id,_.SetRowHiddenMutation.id,_.SetColVisibleMutation.id,_.SetColHiddenMutation.id,_.SetWorksheetRowHeightMutation.id,_.SetWorksheetColWidthMutation.id];let It=class extends l.Disposable{constructor(r,i,n,e,t,o,a,s,d){super(),this._context=r,this._renderManagerService=i,this._commandService=n,this._selectionRenderService=e,this._skeletonManagerService=t,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(!Pn.includes(r.id))return{redos:[],undos:[]};if(r.params==null)return{redos:[],undos:[]};const i=r.id;if(i===_.InsertRowCommand.id)return this._moveRowInterceptor(r.params,"insert");if([_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id].includes(i))return this._moveRangeInterceptor(r.params);if(i===_.InsertColCommand.id)return this._moveColInterceptor(r.params,"insert");if(i===_.RemoveRowCommand.id)return this._moveRowInterceptor(r.params,"remove");if(i===_.RemoveColCommand.id)return this._moveColInterceptor(r.params,"remove");if(i===_.DeleteRangeMoveLeftCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,0)}else if(i===_.DeleteRangeMoveUpCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,1)}else if(i===_.InsertRangeMoveDownCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,2)}else if(i===_.InsertRangeMoveRightCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,3)}else if(i===_.SetRowHiddenCommand.id||i===_.SetSpecificRowsVisibleCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForRowVisible(e,t,o)}else if(i===_.SetSpecificColsVisibleCommand.id||i===_.SetColHiddenCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForColVisible(e,t,o)}else if(i===_.DeltaRowHeightCommand.id||i===_.SetRowHeightCommand.id||i===_.DeltaColumnWidthCommand.id||i===_.SetColWidthCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n,a=i===_.DeltaRowHeightCommand.id||i===_.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(r,i){const n=_.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const e=n.unitId,t=n.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(e,t),d=[],m=[];if(Object.keys(s).forEach(u=>{const c=s[u],{updateDrawings:h,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(r,i,c);d.push(...h),m.push(...g)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:h,objects:g}=u;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:h,objects:g,type:w.DrawingApplyType.UPDATE}}),a.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:c,objects:g,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(m),c=u.undo,h=u.redo,g=u.objects;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:h,objects:g,type:w.DrawingApplyType.REMOVE}}),a.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:c,objects:g,type:w.DrawingApplyType.INSERT}})}return o.push({id:F.id,params:[e]}),a.push({id:F.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(r,i,n){const e=[],t=[],{sheetTransform:o,anchorType:a=w.SheetDrawingAnchorType.Position,transform:s,unitId:d,subUnitId:m,drawingId:u}=n,{from:c,to:h}=o,{row:g,column:f}=c,{row:S,column:p}=h;if(o==null||s==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:v,endRow:I,startColumn:M,endColumn:b}=r;let y=null,T=null;if(i===0&&g>=v&&S<=I)if(f>=M&&p<=b)t.push({unitId:d,subUnitId:m,drawingId:u});else{const C=this._shrinkCol(o,s,M,b,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}else if(i===1&&f>=M&&p<=b)if(g>=v&&S<=I)t.push({unitId:d,subUnitId:m,drawingId:u});else{const C=this._shrinkRow(o,s,v,I,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}else if(i===2){const C=this._expandRow(o,s,v,I,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}else if(i===3){const C=this._expandCol(o,s,M,b,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}if(y!=null&&T!=null){const C=K(y,this._selectionRenderService,this._skeletonManagerService);e.push({...n,sheetTransform:y,transform:C})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(r,i,n){const e=H({...r},this._selectionRenderService);e!=null&&i.push({...n,sheetTransform:e})}_getDrawingUndoForColVisible(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:h,transform:g,anchorType:f=w.SheetDrawingAnchorType.Position}=c;if(f===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,c);else{const{from:S,to:p}=h,{row:v,column:I}=S,{row:M,column:b}=p;for(let y=0;y<n.length;y++){const T=n[y],{startRow:C,endRow:N,startColumn:R,endColumn:j}=T;if(b<R)continue;if(f===w.SheetDrawingAnchorType.Position){let D=null,L=null;if(I>=R&&I<=j){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:j,startRow:S.row,endRow:p.row});if(B==null)return;L={...g,left:B.startX}}if(L!=null&&(D=H(L,this._selectionRenderService),D!=null&&L!=null)){t.push({...c,sheetTransform:D,transform:L});break}this._remainDrawingSize(g,t,c);continue}if(I>=R&&b<=j)continue;let A=null,O=null;if(I>=R&&I<=j){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:j,startRow:S.row,endRow:p.row});if(D==null)return;O={...g,left:(D==null?void 0:D.startX)||0,width:((g==null?void 0:g.width)||0)-D.endX+D.startX}}else if(b>=R&&b<=j){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:R,endColumn:b,startRow:S.row,endRow:p.row});if(D==null)return;O={...g,left:D.startX-((g==null?void 0:g.width)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:R,endColumn:j,startRow:S.row,endRow:p.row});if(D==null)return;if(O={...g,width:((g==null?void 0:g.width)||0)-D.endX+D.startX},A=H(O,this._selectionRenderService),A!=null&&O!=null){o.push({...c,sheetTransform:A,transform:O});break}}if(O!=null&&(A=H(O,this._selectionRenderService)),O!=null&&A!=null){t.push({...c,sheetTransform:A,transform:O});break}else this._remainDrawingSize(g,t,c)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(r,i,t),d=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(r,i,o);d.push(...u),m.push(...c)}return{redos:a,undos:s,preRedos:d,preUndos:m}}_createUndoAndRedoMutation(r,i,n){const e=this._sheetDrawingService.getBatchUpdateOp(n),{undo:t,redo:o,objects:a}=e,s=[{id:w.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,op:o,objects:a,type:w.DrawingApplyType.UPDATE}},{id:F.id,params:[r]}],d=[{id:w.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,op:t,objects:a,type:w.DrawingApplyType.UPDATE}},{id:F.id,params:[r]}];return{redos:s,undos:d}}_getDrawingUndoForRowVisible(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:h,transform:g,anchorType:f=w.SheetDrawingAnchorType.Position}=c;if(f===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,c);else{const{from:S,to:p}=h,{row:v,column:I}=S,{row:M,column:b}=p;for(let y=0;y<n.length;y++){const T=n[y],{startRow:C,endRow:N,startColumn:R,endColumn:j}=T;if(M<C)continue;if(f===w.SheetDrawingAnchorType.Position){let D=null,L=null;if(v>=C&&v<=N){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:p.column,startRow:v,endRow:N});if(B==null)return;L={...g,top:B.startY}}if(L!=null&&(D=H(L,this._selectionRenderService),D!=null&&L!=null)){t.push({...c,sheetTransform:D,transform:L});break}this._remainDrawingSize(g,t,c);continue}if(v>=C&&M<=N)continue;let A=null,O=null;if(v>=C&&v<=N){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:p.column,startRow:v,endRow:N});if(D==null)return;O={...g,top:(D==null?void 0:D.startY)||0,height:((g==null?void 0:g.height)||0)-D.endY+D.startY}}else if(M>=C&&M<=N){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:p.column,startRow:C,endRow:M});if(D==null)return;O={...g,top:D.startY-((g==null?void 0:g.height)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:p.column,startRow:C,endRow:N});if(D==null)return;if(O={...g,height:((g==null?void 0:g.height)||0)-D.endY+D.startY},A=H(O,this._selectionRenderService),A!=null&&O!=null){o.push({...c,sheetTransform:A,transform:O});break}}if(O!=null&&(A=H(O,this._selectionRenderService)),O!=null&&A!=null){t.push({...c,sheetTransform:A,transform:O});break}else this._remainDrawingSize(g,t,c)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(r,i,t),d=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(r,i,o);d.push(...u),m.push(...c)}return{redos:a,undos:s,preRedos:d,preUndos:m}}_getDrawingUndoForRowAndColSize(r,i,n,e){const t=this._drawingManagerService.getDrawingData(r,i),o=[];return Object.keys(t).forEach(a=>{const s=t[a],{sheetTransform:d,transform:m,anchorType:u=w.SheetDrawingAnchorType.Position}=s;if(u===w.SheetDrawingAnchorType.None)this._remainDrawingSize(m,o,s);else{const{from:c,to:h}=d,{row:g,column:f}=c,{row:S,column:p}=h;for(let v=0;v<n.length;v++){const I=n[v],{startRow:M,endRow:b,startColumn:y,endColumn:T}=I;if(S<M||p<y)continue;if(u===w.SheetDrawingAnchorType.Position&&(g<=M&&S>=b||f<=y&&p>=T)){this._remainDrawingSize(m,o,s);continue}const C=K({...d},this._selectionRenderService,this._skeletonManagerService);if(C!=null){o.push({...s,transform:C});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(r,i,o)}_getUnitIdAndSubUnitId(r,i){let n,e;if(i==="insert")n=r.unitId,e=r.subUnitId;else{const t=_.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;n=t.unitId,e=t.subUnitId}return{unitId:n,subUnitId:e}}_moveRangeInterceptor(r){var M,b;const{toRange:i,fromRange:n}=r,e=_.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,a=(b=(M=this._renderManagerService.getRenderById(t))==null?void 0:M.with(E.SheetSkeletonManagerService))==null?void 0:b.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=E.attachRangeWithCoord(a,n);if(!s)return{redos:[],undos:[]};const{startX:d,endX:m,startY:u,endY:c}=s,h=this._sheetDrawingService.getDrawingData(t,o),g=[];Object.keys(h).forEach(y=>{const T=h[y];if(T.anchorType!==w.SheetDrawingAnchorType.Both)return;const{transform:C}=T;if(!C)return;const{left:N=0,top:R=0,width:j=0,height:A=0}=C,{drawingStartX:O,drawingEndX:D,drawingStartY:L,drawingEndY:B}={drawingStartX:N,drawingEndX:N+j,drawingStartY:R,drawingEndY:R+A};d<=O&&D<=m&&u<=L&&B<=c&&g.push(T)});const f=[],S=[],p=i.startRow-n.startRow,v=i.startColumn-n.startColumn,I=g.map(y=>{const T=y.sheetTransform,C={to:{...T.to,row:T.to.row+p,column:T.to.column+v},from:{...T.from,row:T.from.row+p,column:T.from.column+v}},N=K(C,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:y.drawingId,transform:N,sheetTransform:C}});if(I.length){const y=this._sheetDrawingService.getBatchUpdateOp(I),{undo:T,redo:C,objects:N}=y;f.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:C,objects:N,type:w.DrawingApplyType.UPDATE}}),S.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:T,objects:N,type:w.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(r,i){const n=this._getUnitIdAndSubUnitId(r,i);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=r,a=o.startRow,s=o.endRow,d=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),c=[],h=[];if(Object.keys(u).forEach(g=>{const f=u[g],{sheetTransform:S,transform:p,anchorType:v=w.SheetDrawingAnchorType.Position}=f;if(S==null||p==null)return;let I,M;if(i==="insert"){const y=this._expandRow(S,p,a,s,v);I=y==null?void 0:y.newSheetTransform,M=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{row:C}=y,{row:N}=T;if(v===w.SheetDrawingAnchorType.Both&&C>=a&&N<=s)h.push({unitId:e,subUnitId:t,drawingId:g});else{const R=this._shrinkRow(S,p,a,s,v);I=R==null?void 0:R.newSheetTransform,M=R==null?void 0:R.newTransform}}if(!I||!M)return;const b={unitId:e,subUnitId:t,drawingId:g,transform:M,sheetTransform:I};c.push(b)}),c.length===0&&h.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:S,objects:p}=g;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:p,type:w.DrawingApplyType.UPDATE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:p,type:w.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),f=g.undo,S=g.redo,p=g.objects;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:p,type:w.DrawingApplyType.REMOVE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:p,type:w.DrawingApplyType.INSERT}})}return d.push({id:F.id,params:[e]}),m.push({id:F.id,params:[e]}),{redos:d,undos:m}}_moveColInterceptor(r,i){const n=this._getUnitIdAndSubUnitId(r,i);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=r,a=o.startColumn,s=o.endColumn,d=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),c=[],h=[];if(Object.keys(u).forEach(g=>{const f=u[g],{sheetTransform:S,transform:p,anchorType:v=w.SheetDrawingAnchorType.Position}=f;if(S==null||p==null)return;let I,M;if(i==="insert"){const y=this._expandCol(S,p,a,s,v);I=y==null?void 0:y.newSheetTransform,M=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{column:C}=y,{column:N}=T;if(v===w.SheetDrawingAnchorType.Both&&C>=a&&N<=s)h.push({unitId:e,subUnitId:t,drawingId:g});else{const R=this._shrinkCol(S,p,a,s,v);I=R==null?void 0:R.newSheetTransform,M=R==null?void 0:R.newTransform}}if(!I||!M)return;const b={unitId:e,subUnitId:t,drawingId:g,transform:M,sheetTransform:I};c.push(b)}),c.length===0&&h.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:S,objects:p}=g;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:p,type:w.DrawingApplyType.UPDATE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:p,type:w.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),f=g.undo,S=g.redo,p=g.objects;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:p,type:w.DrawingApplyType.REMOVE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:p,type:w.DrawingApplyType.INSERT}})}return d.push({id:F.id,params:[e]}),m.push({id:F.id,params:[e]}),{redos:d,undos:m}}_expandCol(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{column:d}=a,{column:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:H({...i},this._selectionRenderService),newTransform:i};let u=null,c=null;if(d>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:e,startRow:a.row,endRow:s.row});if(h==null)return;c={...i,left:(i.left||0)+h.endX-h.startX},u=H(c,this._selectionRenderService)}else if(m>=e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m+o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...i},this._selectionRenderService),newTransform:i};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{column:d}=a,{column:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:H({...i},this._selectionRenderService),newTransform:i};let u=null,c=null;if(d>e)u={from:{...a,column:d-o},to:{...s,column:m-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=n&&m<=e)return null;if(d<n&&m>e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...i},this._selectionRenderService),newTransform:i};else if(d>=n&&d<=e){if(d===n)c={...i,left:(i.left||0)-r.from.columnOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:d-1,startRow:a.row,endRow:s.row});if(h==null)return;c={...i,left:(i.left||0)-h.endX+h.startX-r.from.columnOffset}}u=H(c,this._selectionRenderService)}else if(m>=n&&m<=e&&t===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n-1,endColumn:n-1,startRow:a.row,endRow:s.row});if(h==null)return;u={from:{...a},to:{...s,column:n-1,columnOffset:h.endX-h.startX}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{row:d}=a,{row:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:H({...i},this._selectionRenderService),newTransform:i};let u=null,c=null;if(d>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:e,startColumn:a.column,endColumn:s.column});if(h==null)return;c={...i,top:(i.top||0)+h.endY-h.startY},u=H(c,this._selectionRenderService)}else if(m>=e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m+o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...i},this._selectionRenderService),newTransform:i};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{row:d}=a,{row:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:H({...i},this._selectionRenderService),newTransform:i};let u=null,c=null;if(d>e)u={from:{...a,row:d-o},to:{...s,row:m-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=n&&m<=e)return null;if(d<n&&m>e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m-o}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...i},this._selectionRenderService),newTransform:i};else if(d>=n&&d<=e){if(d===n)c={...i,top:(i.top||0)-r.from.rowOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:d-1,startColumn:a.column,endColumn:s.column});if(h==null)return;c={...i,top:(i.top||0)-h.endY+h.startY-r.from.rowOffset}}u=H(c,this._selectionRenderService)}else if(m>=n&&m<=e&&t===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:n-1,endRow:n-1});if(h==null)return;u={from:{...a},to:{...s,row:n-1,rowOffset:h.endY-h.startY}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===_.SetWorksheetActiveOperation.id){const{unitId:i,subUnitId:n}=r.params;this._updateDrawings(i,n)}})),this.disposeWithMe(this._context.activated$.subscribe(r=>{const{unit:i,unitId:n}=this._context;if(r){const e=i.getActiveSheet().getSheetId();this._updateDrawings(n,e)}else this._clearDrawings(n)}))}_clearDrawings(r){setTimeout(()=>{const i=this._drawingManagerService.drawingManagerData,n=[];Object.keys(i).forEach(e=>{const t=i[e];t!=null&&Object.keys(t).forEach(o=>{const a=t[o].data;a!=null&&Object.keys(a).forEach(s=>{e===r&&n.push(a[s])})})}),this._drawingManagerService.removeNotification(n)})}_updateDrawings(r,i){setTimeout(()=>{const n=this._drawingManagerService.drawingManagerData,e=[],t=[];Object.keys(n).forEach(o=>{const a=n[o];a!=null&&Object.keys(a).forEach(s=>{const d=a[s].data;d!=null&&Object.keys(d).forEach(m=>{if(o===r&&s===i){const u=d[m];u.transform=K(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(d[m])}else t.push(d[m])})})}),this._drawingManagerService.removeNotification(t),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{An.includes(r.id)&&requestIdleCallback(()=>{const i=r.params,{unitId:n,subUnitId:e,ranges:t}=i;this._refreshDrawingTransform(n,e,t)})}))}_refreshDrawingTransform(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:s,transform:d,anchorType:m=w.SheetDrawingAnchorType.Position}=a;if(m===w.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=s,{row:h,column:g}=u,{row:f,column:S}=c;for(let p=0;p<n.length;p++){const v=n[p],{startRow:I,endRow:M,startColumn:b,endColumn:y}=v;if(l.Rectangle.intersects({startRow:I,endRow:M,startColumn:b,endColumn:y},{startRow:h,endRow:f,startColumn:g,endColumn:S})||h>M||g>y){const T=m===w.SheetDrawingAnchorType.Position,C=K(s,this._selectionRenderService,this._skeletonManagerService);t.push({...a,transform:{...C,width:T?d==null?void 0:d.width:C==null?void 0:C.width,height:T?d==null?void 0:d.height:C==null?void 0:C.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(F.id,[r]))}};It=On([fe(1,W.IRenderManagerService),fe(2,l.ICommandService),fe(3,E.ISheetSelectionRenderService),fe(4,l.Inject(E.SheetSkeletonManagerService)),fe(5,l.Inject(_.SheetInterceptorService)),fe(6,w.ISheetDrawingService),fe(7,U.IDrawingManagerService),fe(8,l.IUniverInstanceService)],It);var ie=function(){return ie=Object.assign||function(r){for(var i,n=1,e=arguments.length;n<e;n++){i=arguments[n];for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&(r[t]=i[t])}return r},ie.apply(this,arguments)},Un=function(r,i){var n={};for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&i.indexOf(e)<0&&(n[e]=r[e]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(r);t<e.length;t++)i.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(r,e[t])&&(n[e[t]]=r[e[t]]);return n},Nt=te.forwardRef(function(r,i){var n=r.icon,e=r.id,t=r.className,o=r.extend,a=Un(r,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),d=te.useRef("_".concat(Wn()));return jt(n,"".concat(e),{defIds:n.defIds,idSuffix:d.current},ie({ref:i,className:s},a),o)});function jt(r,i,n,e,t){return te.createElement(r.tag,ie(ie({key:i},Nn(r,n,t)),e),(jn(r,n).children||[]).map(function(o,a){return jt(o,"".concat(i,"-").concat(r.tag,"-").concat(a),n,void 0,t)}))}function Nn(r,i,n){var e=ie({},r.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var t=i.defIds;return!t||t.length===0||(r.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+i.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(i.idSuffix,")")))})),e}function jn(r,i){var n,e=i.defIds;return!e||e.length===0?r:r.tag==="defs"&&(!((n=r.children)===null||n===void 0)&&n.length)?ie(ie({},r),{children:r.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?ie(ie({},t),{attrs:ie(ie({},t.attrs),{id:t.attrs.id+i.idSuffix})}):t})}):r}function Wn(){return Math.random().toString(36).substring(2,8)}Nt.displayName="UniverIcon";var Bn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z"}}]},Wt=te.forwardRef(function(r,i){return te.createElement(Nt,Object.assign({},r,{id:"add-image-single",ref:i,icon:Bn}))});Wt.displayName="AddImageSingle";const Ct={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:r=>{const i=r.get(l.ICommandService),e=r.get(w.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(a=>{const{unitId:s,subUnitId:d,drawingId:m,drawingType:u}=a;return{unitId:s,subUnitId:d,drawingId:m,drawingType:u}});return i.executeCommand(Ie.id,{unitId:t,drawings:o})}},Ce={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(w.ISheetDrawingService),t=r.get(E.ISheetSelectionRenderService),{direction:o}=i,a=e.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,d=a.map(u=>{const{transform:c}=u;if(c==null)return null;const h={...c},{left:g=0,top:f=0}=c;return o===l.Direction.UP?h.top=f-1:o===l.Direction.DOWN?h.top=f+1:o===l.Direction.LEFT?h.left=g-1:o===l.Direction.RIGHT&&(h.left=g+1),{...u,transform:h,sheetTransform:H(h,t)}}).filter(u=>u!=null);return n.syncExecuteCommand(Pe.id,{unitId:s,drawings:d})?(n.syncExecuteCommand(F.id,[s]),!0):!1}},Bt="addition-and-subtraction-single",yt="sheet.menu.image";function Ln(r){return{id:yt,type:G.MenuItemType.SUBITEMS,icon:Bt,tooltip:"sheetImage.title",hidden$:G.getMenuHiddenObservable(r,l.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(r,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function kn(r){return{id:Ue.id,title:"sheetImage.upload.float",type:G.MenuItemType.BUTTON,hidden$:G.getMenuHiddenObservable(r,l.UniverInstanceType.UNIVER_SHEET)}}function $n(r){return{id:_t.id,title:"sheetImage.upload.cell",type:G.MenuItemType.BUTTON}}const Se={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelSubtitle:"univer-image-common-panel-subtitle",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"};function Lt(r){var i,n,e="";if(typeof r=="string"||typeof r=="number")e+=r;else if(typeof r=="object")if(Array.isArray(r)){var t=r.length;for(i=0;i<t;i++)r[i]&&(n=Lt(r[i]))&&(e&&(e+=" "),e+=n)}else for(n in r)r[n]&&(e&&(e+=" "),e+=n);return e}function Qe(){for(var r,i,n=0,e="",t=arguments.length;n<t;n++)(r=arguments[n])&&(i=Lt(r))&&(e&&(e+=" "),e+=i);return e}const Yn=r=>{var M;const i=l.useDependency(l.ICommandService),n=l.useDependency(l.LocaleService),e=l.useDependency(U.IDrawingManagerService),t=l.useDependency(W.IRenderManagerService),{drawings:o}=r,a=o[0];if(a==null)return;const{unitId:s}=a,d=t.getRenderById(s),m=d==null?void 0:d.scene;if(m==null)return;const u=m.getTransformerByCreate(),[c,h]=te.useState(!0),g=(M=a.anchorType)!=null?M:w.SheetDrawingAnchorType.Position,[f,S]=te.useState(g);function p(b,y){const T=[];return b.forEach(C=>{const{oKey:N}=C,R=y.getDrawingOKey(N);if(R==null)return T.push(null),!0;const{unitId:j,subUnitId:A,drawingId:O,drawingType:D,anchorType:L,sheetTransform:B}=R;T.push({unitId:j,subUnitId:A,drawingId:O,anchorType:L,sheetTransform:B,drawingType:D})}),T}te.useEffect(()=>{const b=u.clearControl$.subscribe(T=>{T===!0&&h(!1)}),y=u.changeStart$.subscribe(T=>{var R;const{objects:C}=T,N=p(C,e);if(N.length===0)h(!1);else if(N.length>=1){h(!0);const j=((R=N[0])==null?void 0:R.anchorType)||w.SheetDrawingAnchorType.Position;S(j)}});return()=>{y.unsubscribe(),b.unsubscribe()}},[]);function v(b){S(b);const y=e.getFocusDrawings();if(y.length===0)return;const T=y.map(C=>({unitId:C.unitId,subUnitId:C.subUnitId,drawingId:C.drawingId,anchorType:b}));i.executeCommand(Pe.id,{unitId:y[0].unitId,drawings:T})}const I=b=>b?"block":"none";return x.jsxs("div",{className:Qe(Se.imageCommonPanelGrid,Se.imageCommonPanelBorder),style:{display:I(c)},children:[x.jsx("div",{className:Se.imageCommonPanelRow,children:x.jsx("div",{className:Qe(Se.imageCommonPanelColumn,Se.imageCommonPanelTitle),children:x.jsx("div",{children:n.t("drawing-anchor.title")})})}),x.jsx("div",{className:Qe(Se.imageCommonPanelRow),children:x.jsx("div",{className:Qe(Se.imageCommonPanelColumn),children:x.jsxs(oe.RadioGroup,{value:f,onChange:v,direction:"vertical",children:[x.jsx(oe.Radio,{value:w.SheetDrawingAnchorType.Both,children:n.t("drawing-anchor.both")}),x.jsx(oe.Radio,{value:w.SheetDrawingAnchorType.Position,children:n.t("drawing-anchor.position")}),x.jsx(oe.Radio,{value:w.SheetDrawingAnchorType.None,children:n.t("drawing-anchor.none")})]})})})]})},Gn=()=>{const r=l.useDependency(U.IDrawingManagerService),i=r.getFocusDrawings(),[n,e]=te.useState(i);return te.useEffect(()=>{const t=r.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(n!=null&&n.length)&&x.jsxs("div",{className:Se.imageCommonPanel,children:[x.jsx(me.DrawingCommonPanel,{drawings:n}),x.jsx(Yn,{drawings:n})]})},Fn={[G.RibbonStartGroup.FORMULAS_INSERT]:{[yt]:{order:3,menuItemFactory:Ln,[Ue.id]:{order:0,menuItemFactory:kn},[_t.id]:{order:1,menuItemFactory:$n}}}};function We(r){return!r.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!r.getContextValue(l.EDITOR_ACTIVATED)&&!r.getContextValue(l.FOCUSING_PANEL_EDITOR)&&r.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const Hn={id:Ce.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_DOWN,priority:100,preconditions:We,staticParameters:{direction:l.Direction.DOWN}},Xn={id:Ce.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_UP,priority:100,preconditions:We,staticParameters:{direction:l.Direction.UP}},Vn={id:Ce.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_LEFT,priority:100,preconditions:We,staticParameters:{direction:l.Direction.LEFT}},xn={id:Ce.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_RIGHT,priority:100,preconditions:We,staticParameters:{direction:l.Direction.RIGHT}},Kn={id:Ct.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:We,binding:G.KeyCode.DELETE,mac:G.KeyCode.BACKSPACE};var zn=Object.defineProperty,qn=Object.getOwnPropertyDescriptor,Zn=(r,i,n,e)=>{for(var t=e>1?void 0:e?qn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&zn(i,n,t),t},ye=(r,i)=>(n,e)=>i(n,e,r);let et=class extends l.Disposable{constructor(r,i,n,e,t,o){super(),this._componentManager=r,this._menuManagerService=i,this._commandService=n,this._shortcutService=e,this._drawingManagerService=t,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const r=this._componentManager;this.disposeWithMe(r.register(Bt,Wt)),this.disposeWithMe(r.register(Et,Gn))}_initMenus(){this._menuManagerService.mergeMenu(Fn)}_initCommands(){[Ue,_t,Oe,Ie,Pe,ht,F,mt,ft,wt,Ce,Ct,St].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_initShortcuts(){[Hn,Xn,Vn,xn,Kn].forEach(r=>{this.disposeWithMe(this._shortcutService.registerShortcut(r))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};et=Zn([ye(0,l.Inject(G.ComponentManager)),ye(1,G.IMenuManagerService),ye(2,l.ICommandService),ye(3,G.IShortcutService),ye(4,U.IDrawingManagerService),ye(5,l.Inject(_.SheetsSelectionsService))],et);var Jn=Object.defineProperty,Qn=Object.getOwnPropertyDescriptor,ei=(r,i,n,e)=>{for(var t=e>1?void 0:e?Qn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Jn(i,n,t),t},_e=(r,i)=>(n,e)=>i(n,e,r);function ti(r,i,n,e,t){const{scaleX:o,scaleY:a}=i.getAncestorScale(),s=i.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN),d=e.getFreeze(),{startColumn:m,startRow:u,xSplit:c,ySplit:h}=d,g={left:!0,top:!0};if(!s)return{...r,absolute:g};const{left:f,right:S,top:p,bottom:v}=r;let{top:I,left:M,viewportScrollX:b,viewportScrollY:y}=s;const{boundsOfViewArea:T,scrollDirectionResponse:C}=t||{},{rowHeaderWidth:N,columnHeaderHeight:R}=n,j={top:R,left:N};T&&(l.Tools.isDefine(j.top)&&(j.top=T.top),l.Tools.isDefine(j.left)&&(j.left=T.left)),C==="HORIZONTAL"&&(y=0),C==="VERTICAL"&&(b=0);let A=0,O=0;const D=n.rowStartY(u-h)+R,L=n.colStartX(m-c)+N,B=n.rowStartY(u)+R,z=n.colStartX(m)+N;if(c===0)g.left=!1,A=(f-b)*o,O=(S-b)*o;else{const ee=f-(L-N),Z=S-(L-N);S<z?(A=ee*o,O=Z*o):f<=z&&S>=z?(A=ee*o,O=Math.max(M,(S-b)*o)):f>z&&(g.left=!1,A=Math.max((f-b)*o,M),O=Math.max((S-b)*o,M))}let V=0,q=0;if(h===0)g.top=!1,V=(p-y)*a,q=(v-y)*a;else{const ee=p-(D-R),Z=v-(D-R);v<B?(V=ee*a,q=Z*a):p<=B&&v>=B?(V=ee*a,q=Math.max(I,(v-y)*a)):p>B&&(g.top=!1,V=Math.max((p-y)*a,I),q=Math.max((v-y)*a,I))}return A=Math.max(A,j.left),V=Math.max(V,j.top),O=Math.max(O,j.left),q=Math.max(q,j.top),{left:A,right:O,top:V,bottom:q,absolute:g}}const le=(r,i,n,e,t)=>{const{scene:o}=i,{left:a,top:s,width:d,height:m,angle:u}=r,c={left:a,right:a+d,top:s,bottom:s+m},h=ti(c,o,n,e,t),{scaleX:g,scaleY:f}=o.getAncestorScale();return{startX:h.left,endX:h.right,startY:h.top,endY:h.bottom,rotate:u,width:d*g,height:m*f,absolute:h.absolute}};P.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(n,e,t,o,a,s,d){super();Q(this,"_domLayerMap",new Map);Q(this,"_domLayerInfoMap",new Map);Q(this,"_transformChange$",new k.Subject);Q(this,"transformChange$",this._transformChange$.asObservable());Q(this,"_add$",new k.Subject);Q(this,"add$",this._add$.asObservable());Q(this,"_remove$",new k.Subject);Q(this,"remove$",this._remove$.asObservable());Q(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=s,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(k.filter(n=>n===l.LifecycleStages.Rendered),k.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(n,e){let t=this._domLayerMap.get(n);t||(t=new Map,this._domLayerMap.set(n,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(n){return this._domLayerInfoMap.get(n)}_getSceneAndTransformerByDrawingSearch(n){if(n==null)return;const e=this._renderManagerService.getRenderById(n),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:t,transformer:o,renderUnit:e,canvas:a}}_getFloatDomProps(n){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(n)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(n=>{n.forEach(e=>{var se,ce,J;const{unitId:t,subUnitId:o,drawingId:a}=e,s=_.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(t,l.UniverInstanceType.UNIVER_SHEET);if(!m)return;const u=m.getActiveSheet().getSheetId();if(!d||!s)return;const c=(se=this._renderManagerService.getRenderById(t))==null?void 0:se.with(E.SheetSkeletonManagerService).getSkeletonParam(o);if(!c)return;const{transform:h,drawingType:g,data:f}=d;if(g!==l.DrawingTypeEnum.DRAWING_DOM&&g!==l.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(t);if(S==null)return;const{scene:p,canvas:v}=S;if(h==null)return!0;if(u!==o)return;const{left:I,top:M,width:b,height:y,angle:T,flipX:C,flipY:N,skewX:R,skewY:j}=h,A=U.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),O=p.getObject(A);if(O!=null){O.transformByState({left:I,top:M,width:b,height:y,angle:T,flipX:C,flipY:N,skewX:R,skewY:j});return}const D={left:I,top:M,width:b,height:y,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},L=g===l.DrawingTypeEnum.DRAWING_CHART;if(L){const Y=f?f.backgroundColor:"white";D.fill=Y,D.rotateEnabled=!1,f&&f.border&&(D.stroke=f.border),D.paintFirst="stroke",D.strokeWidth=1,D.borderEnabled=!1,D.radius=8}const B=new W.Rect(A,D);L&&B.setObjectType(W.ObjectType.CHART),p.addObject(B,W.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&p.attachTransformerTo(B);const z=this._ensureMap(t,o),V=new l.DisposableCollection,q=le(B,S.renderUnit,c.skeleton,s.worksheet),ae=new k.BehaviorSubject(q),ee={dispose:V,rect:B,position$:ae,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:ae,id:a,componentKey:d.componentKey,onPointerDown:Y=>{v.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{v.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{v.dispatchEvent(new PointerEvent(Y.type,Y))},onWheel:Y=>{v.dispatchEvent(new WheelEvent(Y.type,Y))},props:(J=(ce=z.get(a))==null?void 0:ce.props)!=null?J:this._getFloatDomProps(a),data:f,unitId:t});const Z=B.onTransformChange$.subscribeEvent(()=>{const Y=le(B,S.renderUnit,c.skeleton,s.worksheet);ae.next(Y)});V.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),Z&&V.add(Z),this._domLayerInfoMap.set(a,ee),z.set(a,{...z.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a}=e,s=U.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),d=this._getSceneAndTransformerByDrawingSearch(t);if(d==null)return;const{transformer:m,scene:u}=d,c=u.getObject(s);c!=null&&c.oKey&&m.clearControlByIds([c==null?void 0:c.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,t),s=Array.from(a.keys()),d=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),m=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(E.SheetSkeletonManagerService).getSkeletonParam(t);!o||!d||!m||s.forEach(c=>{const h=this._domLayerInfoMap.get(c);if(h){const g=le(h.rect,o.renderUnit,m.skeleton,d.worksheet,h);h.position$.next(g)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(k.switchMap(e=>e?e.activeSheet$:k.of(null)),k.map(e=>{if(!e)return null;const t=e.getUnitId(),o=this._renderManagerService.getRenderById(t);return o?{render:o,unitId:t,subUnitId:e.getSheetId()}:null}),k.switchMap(e=>e?l.fromEventSubject(e.render.scene.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(k.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):k.of(null))).subscribe(e=>{if(!e)return;const{unitId:t,subUnitId:o}=e;n(t,o)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===E.SetZoomRatioOperation.id){const a=e.params,{unitId:s}=a;Array.from((o=(t=this._domLayerMap.get(s))==null?void 0:t.keys())!=null?o:[]).forEach(m=>{n(s,m)})}else if(e.id===_.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=e.params;n(a,s)}}))}_getPosition(n,e){var g;const{startX:t,endX:o,startY:a,endY:s}=n,d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(E.ISheetSelectionRenderService);if(d==null)return;const m=d.getCellWithCoordByOffset(t,a);if(m==null)return;const u={column:m.actualColumn,columnOffset:t-m.startX,row:m.actualRow,rowOffset:a-m.startY},c=d.getCellWithCoordByOffset(o,s);if(c==null)return;const h={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:s-c.startY};return{from:u,to:h}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(n,e,t,o){const a=this._domLayerInfoMap.get(t),s=this._getSceneAndTransformerByDrawingSearch(n);if(a&&s){const{scene:d}=s,m=U.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),u=d.getObject(m);u&&u instanceof W.Rect&&u.setProps(o)}}addFloatDomToPosition(n,e){const t=_.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=t,{initPosition:s,componentKey:d,data:m,allowTransform:u=!0}=n,c=e!=null?e:l.generateRandomId(),h=this._getPosition(s,o);if(h==null)return;this._ensureMap(o,a).set(c,n);const f={unitId:o,subUnitId:a,drawingId:c,drawingType:n.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:h,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:m,allowTransform:u};return this._commandService.executeCommand(Oe.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:a,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(n,e=!1){const t=this._domLayerInfoMap.get(n);if(!t)return;const{unitId:o,subUnitId:a}=t;this._domLayerInfoMap.delete(n),t.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(t.rect),e){this._ensureMap(o,a).delete(n);const m=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:n});if(!m)return;const u=this._sheetDrawingService.getBatchRemoveOp([m]),{redo:c,objects:h}=u;this._commandService.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:c,objects:h,type:w.DrawingApplyType.REMOVE})}}addHook(n){return this._hooks.push(n),{dispose:()=>{const e=this._hooks.findIndex(t=>t===n);this._hooks.splice(e,1)}}}addFloatDomToRange(n,e,t,o){var N,R,j,A,O;const a=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:d}=a,m=this._getSceneAndTransformerByDrawingSearch(s);if(!m)return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const c=(N=this._renderManagerService.getRenderById(s))==null?void 0:N.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:h,data:g,allowTransform:f=!0}=e,S=o!=null?o:l.generateRandomId(),{position:p,position$:v}=this._createRangePositionObserver(n,u,c.skeleton),I=this._getPosition(p,s);if(I==null)return;this._ensureMap(s,d).set(S,e);const b=m.scene,{scaleX:y}=b.getAncestorScale(),T=tt(p,t,y),C={unitId:s,subUnitId:d,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:h,sheetTransform:I,transform:{left:T.startX,top:T.startY,width:T.width,height:T.height},data:g,allowTransform:f};{const{unitId:D,subUnitId:L,drawingId:B}=C,z=_.getSheetCommandTarget(this._univerInstanceService,{unitId:D,subUnitId:L}),V=C,q=this._univerInstanceService.getUnit(D,l.UniverInstanceType.UNIVER_SHEET);if(!q)return;const ae=q.getActiveSheet().getSheetId();if(!V||!z)return;const ee=(R=this._renderManagerService.getRenderById(D))==null?void 0:R.with(E.SheetSkeletonManagerService);if(!ee)return;const Z=ee.getWorksheetSkeleton(L);if(!Z)return;const{transform:se,drawingType:ce,data:J}=V;if(ce!==l.DrawingTypeEnum.DRAWING_DOM&&ce!==l.DrawingTypeEnum.DRAWING_CHART)return;const Y=this._getSceneAndTransformerByDrawingSearch(D);if(Y==null)return;const{scene:De,canvas:Me}=Y;if(se==null||ae!==L)return;const{left:it,top:rt,width:ot,height:at,angle:Mt,flipX:Tt,flipY:st,skewX:ct,skewY:Te}=se,dt=U.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:L,drawingId:B}),ue=De.getObject(dt);if(ue!=null){ue.transformByState({left:it,top:rt,width:ot,height:at,angle:Mt,flipX:Tt,flipY:st,skewX:ct,skewY:Te});return}const re={left:it,top:rt,width:ot,height:at,zIndex:this._drawingManagerService.getDrawingOrder(D,L).length-1},be=ce===l.DrawingTypeEnum.DRAWING_CHART;if(be){const $=J?J.backgroundColor:"white";re.fill=$,re.rotateEnabled=!1,J&&J.border&&(re.stroke=J.border),re.paintFirst="stroke",re.strokeWidth=1,re.borderEnabled=!1,re.radius=8}const de=new W.Rect(dt,re);be&&de.setObjectType(W.ObjectType.CHART),De.addObject(de,W.DRAWING_OBJECT_LAYER_INDEX),V.allowTransform!==!1&&De.attachTransformerTo(de);const Le=this._ensureMap(D,L),ge=new l.DisposableCollection,lt=De.getMainViewport(),{rowHeaderWidth:Re,columnHeaderHeight:ke}=Z.skeleton,ut={top:ke,left:Re,bottom:lt.bottom,right:lt.right},he={dispose:ge,rect:de,boundsOfViewArea:ut,domAnchor:t,unitId:D,subUnitId:L},X=le(de,Y.renderUnit,Z.skeleton,z.worksheet,he),Ee=new k.BehaviorSubject(X);he.position$=Ee;let $e={position$:Ee,id:B,componentKey:V.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{Me.dispatchEvent(new WheelEvent($.type,$))},props:(A=(j=Le.get(B))==null?void 0:j.props)!=null?A:this._getFloatDomProps(B),data:J,unitId:D};e.eventPassThrough&&($e={...$e,onPointerDown:$=>{Me.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{Me.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{Me.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom($e),this.disposeWithMe(v.subscribe($=>{var Gt,Ft,Ht,Xt;const Yt=tt({rotate:0,startX:$.startX,startY:$.startY,endX:$.endX,endY:$.endY,width:(Gt=t.width)!=null?Gt:$.width,height:(Ft=t.height)!=null?Ft:$.height,absolute:{left:p.absolute.left,top:p.absolute.top}},t),ai=U.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:L,drawingId:B}),si=new W.Rect(ai,{left:Yt.startX,top:Yt.startY,width:(Ht=t.width)!=null?Ht:$.width,height:(Xt=t.height)!=null?Xt:$.height,zIndex:this._drawingManagerService.getDrawingOrder(D,L).length-1}),ci=le(si,Y.renderUnit,Z.skeleton,z.worksheet,he);Ee.next(ci)}));const Ye=(O=this._renderManagerService.getRenderById(D))==null?void 0:O.with(E.SheetSkeletonManagerService);Ye==null||Ye.currentSkeleton$.subscribe($=>{$&&Z.sheetId!==$.sheetId&&this._removeDom(S,!0)});const gt=de.onTransformChange$.subscribeEvent(()=>{const $=le(de,Y.renderUnit,Z.skeleton,z.worksheet,he);Ee.next($)});ge.add(()=>{this._canvasFloatDomService.removeFloatDom(B)}),gt&&ge.add(gt),this._domLayerInfoMap.set(B,he),Le.set(B,{...Le.get(B)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(n,e,t,o){var T,C,N,R,j;const a=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:d}=a;if(!this._getSceneAndTransformerByDrawingSearch(s))return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const c=(T=this._renderManagerService.getRenderById(s))==null?void 0:T.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:h,data:g,allowTransform:f=!0}=e,S=o!=null?o:l.generateRandomId(),{position:p,position$:v}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:n,endColumn:n},u,c.skeleton),I=p;I.startY=0;const M=this._getPosition(p,s);if(M==null)return;this._ensureMap(s,d).set(S,e);const y={unitId:s,subUnitId:d,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:h,sheetTransform:M,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:g,allowTransform:f};{const{unitId:A,subUnitId:O,drawingId:D}=y,L=_.getSheetCommandTarget(this._univerInstanceService,{unitId:A,subUnitId:O}),B=y,z=this._univerInstanceService.getUnit(A,l.UniverInstanceType.UNIVER_SHEET);if(!z)return;const V=z.getActiveSheet().getSheetId();if(!B||!L)return;const q=(C=this._renderManagerService.getRenderById(A))==null?void 0:C.with(E.SheetSkeletonManagerService);if(!q)return;const ae=q.getWorksheetSkeleton(O);if(!ae)return;const{transform:ee,data:Z}=B,se=this._getSceneAndTransformerByDrawingSearch(A);if(se==null)return;const{scene:ce,canvas:J}=se;if(ee==null||V!==O)return;const{left:Y,top:De,width:Me,height:it,angle:rt,flipX:ot,flipY:at,skewX:Mt,skewY:Tt}=ee,st=U.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:O,drawingId:D}),ct=ce.getObject(st);if(ct!=null){ct.transformByState({left:Y,top:De,width:Me,height:it,angle:rt,flipX:ot,flipY:at,skewX:Mt,skewY:Tt});return}const Te=tt({rotate:0,startX:I.startX,startY:0,endX:p.endX,endY:p.endY,width:t.width,height:t.height,absolute:{left:p.absolute.left,top:p.absolute.top}},t),dt={left:Te.startX,top:Te.startY,width:Te.width,height:Te.height,zIndex:this._drawingManagerService.getDrawingOrder(A,O).length-1},ue=new W.Rect(st,dt);ce.addObject(ue,W.DRAWING_OBJECT_LAYER_INDEX),B.allowTransform!==!1&&ce.attachTransformerTo(ue);const re=this._ensureMap(A,O),be=new l.DisposableCollection,de=ce.getMainViewport(),Le={top:0,left:de.left,bottom:de.bottom,right:de.right},ge={dispose:be,rect:ue,unitId:A,subUnitId:O,boundsOfViewArea:Le,domAnchor:t,scrollDirectionResponse:"HORIZONTAL"},lt=le(ue,se.renderUnit,ae.skeleton,L.worksheet,ge),Re=new k.BehaviorSubject(lt);ge.position$=Re;let ke={position$:Re,id:D,componentKey:B.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:X=>{J.dispatchEvent(new WheelEvent(X.type,X))},props:(R=(N=re.get(D))==null?void 0:N.props)!=null?R:this._getFloatDomProps(D),data:Z,unitId:A};e.eventPassThrough&&(ke={...ke,onPointerDown:X=>{J.dispatchEvent(new PointerEvent(X.type,X))},onPointerMove:X=>{J.dispatchEvent(new PointerEvent(X.type,X))},onPointerUp:X=>{J.dispatchEvent(new PointerEvent(X.type,X))}}),this._canvasFloatDomService.addFloatDom(ke);const ut=ue.onTransformChange$.subscribeEvent(()=>{const X=le(ue,se.renderUnit,ae.skeleton,L.worksheet,ge);Re.next(X)});this.disposeWithMe(v.subscribe(X=>{const Ee=tt({rotate:0,startX:X.startX,startY:0,endX:X.endX,endY:X.endY,width:t.width,height:t.height,absolute:{left:p.absolute.left,top:p.absolute.top}},t),$e=U.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:O,drawingId:D}),Ye=new W.Rect($e,{left:Ee.startX,top:0,width:t.width,height:t.height,zIndex:this._drawingManagerService.getDrawingOrder(A,O).length-1}),gt=le(Ye,se.renderUnit,ae.skeleton,L.worksheet,ge);Re.next(gt)}));const he=(j=this._renderManagerService.getRenderById(A))==null?void 0:j.with(E.SheetSkeletonManagerService);he==null||he.currentSkeleton$.subscribe(X=>{X&&c.sheetId!==X.sheetId&&this._removeDom(S,!0)}),be.add(()=>{this._canvasFloatDomService.removeFloatDom(D)}),ut&&be.add(ut),this._domLayerInfoMap.set(D,ge),re.set(D,{...re.get(D)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(n,e,t){let{startRow:o,startColumn:a}=n;const s=Be(o,a,t),d=new k.BehaviorSubject(s),m=Be(n.endRow,n.endColumn,t),u=new k.BehaviorSubject(m),c=()=>{const v=Be(o,a,t),I=Be(n.endRow,n.endColumn,t);d.next(v),u.next(I)},h=new l.DisposableCollection;h.add(e.engine.clientRect$.subscribe(()=>c())),h.add(this._commandService.onCommandExecuted(v=>{if(v.id===_.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(M=>M.row===o)>-1){c();return}(_.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(v.id)>-1||v.id===E.SetScrollOperation.id||v.id===E.SetZoomRatioOperation.id)&&c()}));const g=(v,I)=>{o=v,a=I,c()},f=()=>({rotate:0,width:m.right-s.left,height:m.bottom-s.top,absolute:{left:!0,top:!0},startX:s.left,startY:s.top,endX:m.right,endY:m.bottom}),S=d.pipe(k.map(v=>{const I=Be(n.endRow,n.endColumn,t);return{rotate:0,width:I.right-v.left,height:I.bottom-v.top,absolute:{left:!0,top:!0},startX:v.left,startY:v.top,endX:I.right,endY:I.bottom}})),p=f();return{position$:S,position:p,updateRowCol:g,topLeftPos$:d,rightBottomPos$:u,disposable:h}}},P.SheetCanvasFloatDomManagerService=ei([_e(0,l.Inject(W.IRenderManagerService)),_e(1,l.IUniverInstanceService),_e(2,l.Inject(l.ICommandService)),_e(3,U.IDrawingManagerService),_e(4,l.Inject(G.CanvasFloatDomService)),_e(5,w.ISheetDrawingService),_e(6,l.Inject(l.LifecycleService))],P.SheetCanvasFloatDomManagerService);function Be(r,i,n){const e=n.getCellWithCoordByIndex(r,i),t=e.isMergedMainCell?e.mergeInfo:e;return{left:t.startX,right:t.endX,top:t.startY,bottom:t.endY}}function tt(r,i,n){var m,u;n=n!=null?n:1;const e=r.endX-r.startX,t=r.endY-r.startY,o=(m=i==null?void 0:i.width)!=null?m:e,a=(u=i==null?void 0:i.height)!=null?u:t;let s=0,d=0;if(i){if(i.horizonOffsetAlign==="right"){const c=nt(i.marginX,e*n);s=r.endX-c-o}else s=r.startX+nt(i.marginX,e);if(i.verticalOffsetAlign==="bottom"){const c=nt(i.marginY,t*n);d=r.endY-c-a}else d=r.startY+nt(i.marginY,t)}return{rotate:0,startX:s,startY:d,endX:r.endX,endY:r.endY,width:o,height:a,absolute:{left:r.absolute.left,top:r.absolute.top}}}function nt(r,i){if(r===void 0)return 0;if(typeof r=="number")return r;const n=Number.parseFloat(r);return i*n/100}var kt=Object.defineProperty,ni=Object.getOwnPropertyDescriptor,ii=(r,i,n)=>i in r?kt(r,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[i]=n,ri=(r,i,n,e)=>{for(var t=e>1?void 0:e?ni(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&kt(i,n,t),t},Dt=(r,i)=>(n,e)=>i(n,e,r),$t=(r,i,n)=>ii(r,typeof i!="symbol"?i+"":i,n);const oi="SHEET_IMAGE_UI_PLUGIN";P.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(i=Rt,n,e,t){super(),this._config=i,this._injector=n,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=l.merge({},Rt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Vt,a)}onStarting(){l.registerDependencies(this._injector,[[P.SheetCanvasFloatDomManagerService],[et],[Fe],[Je],[qe],[ze],[Xe],[Ke],[Ve]]),l.touchDependencies(this._injector,[[P.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[ze]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[qe],[Je],[et],[Xe],[Ke],[Ve]])}onSteady(){this._injector.get(Fe)}_registerRenderModules(){[[Ae],[It],[pt]].forEach(i=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,i))})}},$t(P.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),$t(P.UniverSheetsDrawingUIPlugin,"pluginName",oi),P.UniverSheetsDrawingUIPlugin=ri([l.DependentOn(U.UniverDrawingPlugin,we.UniverDocsDrawingPlugin,me.UniverDrawingUIPlugin,w.UniverSheetsDrawingPlugin),Dt(1,l.Inject(l.Injector)),Dt(2,W.IRenderManagerService),Dt(3,l.IConfigService)],P.UniverSheetsDrawingUIPlugin),P.ClearSheetDrawingTransformerOperation=F,P.DeleteDrawingsCommand=Ct,P.EditSheetDrawingOperation=mt,P.GroupSheetDrawingCommand=ft,P.InsertFloatImageCommand=Ue,P.InsertSheetDrawingCommand=Oe,P.MoveDrawingsCommand=Ce,P.RemoveSheetDrawingCommand=Ie,P.SHEETS_IMAGE_MENU_ID=yt,P.SetDrawingArrangeCommand=St,P.SetSheetDrawingCommand=Pe,P.SidebarSheetDrawingOperation=ht,P.UngroupSheetDrawingCommand=wt,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-drawing-ui",
|
|
3
|
-
"version": "0.6.0-nightly.
|
|
3
|
+
"version": "0.6.0-nightly.202502071606",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -59,17 +59,17 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@univerjs/icons": "^0.2.14",
|
|
61
61
|
"clsx": "^2.1.1",
|
|
62
|
-
"@univerjs/core": "0.6.0-nightly.
|
|
63
|
-
"@univerjs/
|
|
64
|
-
"@univerjs/
|
|
65
|
-
"@univerjs/
|
|
66
|
-
"@univerjs/docs-ui": "0.6.0-nightly.
|
|
67
|
-
"@univerjs/drawing-ui": "0.6.0-nightly.
|
|
68
|
-
"@univerjs/sheets": "0.6.0-nightly.
|
|
69
|
-
"@univerjs/
|
|
70
|
-
"@univerjs/
|
|
71
|
-
"@univerjs/sheets-ui": "0.6.0-nightly.
|
|
72
|
-
"@univerjs/ui": "0.6.0-nightly.
|
|
62
|
+
"@univerjs/core": "0.6.0-nightly.202502071606",
|
|
63
|
+
"@univerjs/docs-drawing": "0.6.0-nightly.202502071606",
|
|
64
|
+
"@univerjs/design": "0.6.0-nightly.202502071606",
|
|
65
|
+
"@univerjs/drawing": "0.6.0-nightly.202502071606",
|
|
66
|
+
"@univerjs/docs-ui": "0.6.0-nightly.202502071606",
|
|
67
|
+
"@univerjs/drawing-ui": "0.6.0-nightly.202502071606",
|
|
68
|
+
"@univerjs/sheets": "0.6.0-nightly.202502071606",
|
|
69
|
+
"@univerjs/sheets-drawing": "0.6.0-nightly.202502071606",
|
|
70
|
+
"@univerjs/engine-render": "0.6.0-nightly.202502071606",
|
|
71
|
+
"@univerjs/sheets-ui": "0.6.0-nightly.202502071606",
|
|
72
|
+
"@univerjs/ui": "0.6.0-nightly.202502071606"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"less": "^4.2.2",
|